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/dma-resv.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>
47 #include "display/intel_crt.h"
48 #include "display/intel_ddi.h"
49 #include "display/intel_dp.h"
50 #include "display/intel_dsi.h"
51 #include "display/intel_dvo.h"
52 #include "display/intel_gmbus.h"
53 #include "display/intel_hdmi.h"
54 #include "display/intel_lvds.h"
55 #include "display/intel_sdvo.h"
56 #include "display/intel_tv.h"
57 #include "display/intel_vdsc.h"
60 #include "i915_trace.h"
61 #include "intel_acpi.h"
62 #include "intel_atomic.h"
63 #include "intel_atomic_plane.h"
65 #include "intel_cdclk.h"
66 #include "intel_color.h"
67 #include "intel_display_types.h"
68 #include "intel_fbc.h"
69 #include "intel_fbdev.h"
70 #include "intel_fifo_underrun.h"
71 #include "intel_frontbuffer.h"
72 #include "intel_hdcp.h"
73 #include "intel_hotplug.h"
74 #include "intel_overlay.h"
75 #include "intel_pipe_crc.h"
77 #include "intel_psr.h"
78 #include "intel_quirks.h"
79 #include "intel_sideband.h"
80 #include "intel_sprite.h"
83 /* Primary plane formats for gen <= 3 */
84 static const u32 i8xx_primary_formats[] = {
91 /* Primary plane formats for gen >= 4 */
92 static const u32 i965_primary_formats[] = {
97 DRM_FORMAT_XRGB2101010,
98 DRM_FORMAT_XBGR2101010,
101 static const u64 i9xx_format_modifiers[] = {
102 I915_FORMAT_MOD_X_TILED,
103 DRM_FORMAT_MOD_LINEAR,
104 DRM_FORMAT_MOD_INVALID
108 static const u32 intel_cursor_formats[] = {
112 static const u64 cursor_format_modifiers[] = {
113 DRM_FORMAT_MOD_LINEAR,
114 DRM_FORMAT_MOD_INVALID
117 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
118 struct intel_crtc_state *pipe_config);
119 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
120 struct intel_crtc_state *pipe_config);
122 static int intel_framebuffer_init(struct intel_framebuffer *ifb,
123 struct drm_i915_gem_object *obj,
124 struct drm_mode_fb_cmd2 *mode_cmd);
125 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state);
126 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
127 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
128 const struct intel_link_m_n *m_n,
129 const struct intel_link_m_n *m2_n2);
130 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
131 static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state);
132 static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state);
133 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state);
134 static void vlv_prepare_pll(struct intel_crtc *crtc,
135 const struct intel_crtc_state *pipe_config);
136 static void chv_prepare_pll(struct intel_crtc *crtc,
137 const struct intel_crtc_state *pipe_config);
138 static void intel_begin_crtc_commit(struct intel_atomic_state *, struct intel_crtc *);
139 static void intel_finish_crtc_commit(struct intel_atomic_state *, struct intel_crtc *);
140 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
141 struct intel_crtc_state *crtc_state);
142 static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state);
143 static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state);
144 static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state);
145 static void intel_modeset_setup_hw_state(struct drm_device *dev,
146 struct drm_modeset_acquire_ctx *ctx);
147 static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc);
152 } dot, vco, n, m, m1, m2, p, p1;
156 int p2_slow, p2_fast;
160 /* returns HPLL frequency in kHz */
161 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
163 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
165 /* Obtain SKU information */
166 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
167 CCK_FUSE_HPLL_FREQ_MASK;
169 return vco_freq[hpll_freq] * 1000;
172 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
173 const char *name, u32 reg, int ref_freq)
178 val = vlv_cck_read(dev_priv, reg);
179 divider = val & CCK_FREQUENCY_VALUES;
181 WARN((val & CCK_FREQUENCY_STATUS) !=
182 (divider << CCK_FREQUENCY_STATUS_SHIFT),
183 "%s change in progress\n", name);
185 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
188 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
189 const char *name, u32 reg)
193 vlv_cck_get(dev_priv);
195 if (dev_priv->hpll_freq == 0)
196 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
198 hpll = vlv_get_cck_clock(dev_priv, name, reg, dev_priv->hpll_freq);
200 vlv_cck_put(dev_priv);
205 static void intel_update_czclk(struct drm_i915_private *dev_priv)
207 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
210 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
211 CCK_CZ_CLOCK_CONTROL);
213 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
216 static inline u32 /* units of 100MHz */
217 intel_fdi_link_freq(struct drm_i915_private *dev_priv,
218 const struct intel_crtc_state *pipe_config)
220 if (HAS_DDI(dev_priv))
221 return pipe_config->port_clock; /* SPLL */
223 return dev_priv->fdi_pll_freq;
226 static const struct intel_limit intel_limits_i8xx_dac = {
227 .dot = { .min = 25000, .max = 350000 },
228 .vco = { .min = 908000, .max = 1512000 },
229 .n = { .min = 2, .max = 16 },
230 .m = { .min = 96, .max = 140 },
231 .m1 = { .min = 18, .max = 26 },
232 .m2 = { .min = 6, .max = 16 },
233 .p = { .min = 4, .max = 128 },
234 .p1 = { .min = 2, .max = 33 },
235 .p2 = { .dot_limit = 165000,
236 .p2_slow = 4, .p2_fast = 2 },
239 static const struct intel_limit intel_limits_i8xx_dvo = {
240 .dot = { .min = 25000, .max = 350000 },
241 .vco = { .min = 908000, .max = 1512000 },
242 .n = { .min = 2, .max = 16 },
243 .m = { .min = 96, .max = 140 },
244 .m1 = { .min = 18, .max = 26 },
245 .m2 = { .min = 6, .max = 16 },
246 .p = { .min = 4, .max = 128 },
247 .p1 = { .min = 2, .max = 33 },
248 .p2 = { .dot_limit = 165000,
249 .p2_slow = 4, .p2_fast = 4 },
252 static const struct intel_limit intel_limits_i8xx_lvds = {
253 .dot = { .min = 25000, .max = 350000 },
254 .vco = { .min = 908000, .max = 1512000 },
255 .n = { .min = 2, .max = 16 },
256 .m = { .min = 96, .max = 140 },
257 .m1 = { .min = 18, .max = 26 },
258 .m2 = { .min = 6, .max = 16 },
259 .p = { .min = 4, .max = 128 },
260 .p1 = { .min = 1, .max = 6 },
261 .p2 = { .dot_limit = 165000,
262 .p2_slow = 14, .p2_fast = 7 },
265 static const struct intel_limit intel_limits_i9xx_sdvo = {
266 .dot = { .min = 20000, .max = 400000 },
267 .vco = { .min = 1400000, .max = 2800000 },
268 .n = { .min = 1, .max = 6 },
269 .m = { .min = 70, .max = 120 },
270 .m1 = { .min = 8, .max = 18 },
271 .m2 = { .min = 3, .max = 7 },
272 .p = { .min = 5, .max = 80 },
273 .p1 = { .min = 1, .max = 8 },
274 .p2 = { .dot_limit = 200000,
275 .p2_slow = 10, .p2_fast = 5 },
278 static const struct intel_limit intel_limits_i9xx_lvds = {
279 .dot = { .min = 20000, .max = 400000 },
280 .vco = { .min = 1400000, .max = 2800000 },
281 .n = { .min = 1, .max = 6 },
282 .m = { .min = 70, .max = 120 },
283 .m1 = { .min = 8, .max = 18 },
284 .m2 = { .min = 3, .max = 7 },
285 .p = { .min = 7, .max = 98 },
286 .p1 = { .min = 1, .max = 8 },
287 .p2 = { .dot_limit = 112000,
288 .p2_slow = 14, .p2_fast = 7 },
292 static const struct intel_limit intel_limits_g4x_sdvo = {
293 .dot = { .min = 25000, .max = 270000 },
294 .vco = { .min = 1750000, .max = 3500000},
295 .n = { .min = 1, .max = 4 },
296 .m = { .min = 104, .max = 138 },
297 .m1 = { .min = 17, .max = 23 },
298 .m2 = { .min = 5, .max = 11 },
299 .p = { .min = 10, .max = 30 },
300 .p1 = { .min = 1, .max = 3},
301 .p2 = { .dot_limit = 270000,
307 static const struct intel_limit intel_limits_g4x_hdmi = {
308 .dot = { .min = 22000, .max = 400000 },
309 .vco = { .min = 1750000, .max = 3500000},
310 .n = { .min = 1, .max = 4 },
311 .m = { .min = 104, .max = 138 },
312 .m1 = { .min = 16, .max = 23 },
313 .m2 = { .min = 5, .max = 11 },
314 .p = { .min = 5, .max = 80 },
315 .p1 = { .min = 1, .max = 8},
316 .p2 = { .dot_limit = 165000,
317 .p2_slow = 10, .p2_fast = 5 },
320 static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
321 .dot = { .min = 20000, .max = 115000 },
322 .vco = { .min = 1750000, .max = 3500000 },
323 .n = { .min = 1, .max = 3 },
324 .m = { .min = 104, .max = 138 },
325 .m1 = { .min = 17, .max = 23 },
326 .m2 = { .min = 5, .max = 11 },
327 .p = { .min = 28, .max = 112 },
328 .p1 = { .min = 2, .max = 8 },
329 .p2 = { .dot_limit = 0,
330 .p2_slow = 14, .p2_fast = 14
334 static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
335 .dot = { .min = 80000, .max = 224000 },
336 .vco = { .min = 1750000, .max = 3500000 },
337 .n = { .min = 1, .max = 3 },
338 .m = { .min = 104, .max = 138 },
339 .m1 = { .min = 17, .max = 23 },
340 .m2 = { .min = 5, .max = 11 },
341 .p = { .min = 14, .max = 42 },
342 .p1 = { .min = 2, .max = 6 },
343 .p2 = { .dot_limit = 0,
344 .p2_slow = 7, .p2_fast = 7
348 static const struct intel_limit intel_limits_pineview_sdvo = {
349 .dot = { .min = 20000, .max = 400000},
350 .vco = { .min = 1700000, .max = 3500000 },
351 /* Pineview's Ncounter is a ring counter */
352 .n = { .min = 3, .max = 6 },
353 .m = { .min = 2, .max = 256 },
354 /* Pineview only has one combined m divider, which we treat as m2. */
355 .m1 = { .min = 0, .max = 0 },
356 .m2 = { .min = 0, .max = 254 },
357 .p = { .min = 5, .max = 80 },
358 .p1 = { .min = 1, .max = 8 },
359 .p2 = { .dot_limit = 200000,
360 .p2_slow = 10, .p2_fast = 5 },
363 static const struct intel_limit intel_limits_pineview_lvds = {
364 .dot = { .min = 20000, .max = 400000 },
365 .vco = { .min = 1700000, .max = 3500000 },
366 .n = { .min = 3, .max = 6 },
367 .m = { .min = 2, .max = 256 },
368 .m1 = { .min = 0, .max = 0 },
369 .m2 = { .min = 0, .max = 254 },
370 .p = { .min = 7, .max = 112 },
371 .p1 = { .min = 1, .max = 8 },
372 .p2 = { .dot_limit = 112000,
373 .p2_slow = 14, .p2_fast = 14 },
376 /* Ironlake / Sandybridge
378 * We calculate clock using (register_value + 2) for N/M1/M2, so here
379 * the range value for them is (actual_value - 2).
381 static const struct intel_limit intel_limits_ironlake_dac = {
382 .dot = { .min = 25000, .max = 350000 },
383 .vco = { .min = 1760000, .max = 3510000 },
384 .n = { .min = 1, .max = 5 },
385 .m = { .min = 79, .max = 127 },
386 .m1 = { .min = 12, .max = 22 },
387 .m2 = { .min = 5, .max = 9 },
388 .p = { .min = 5, .max = 80 },
389 .p1 = { .min = 1, .max = 8 },
390 .p2 = { .dot_limit = 225000,
391 .p2_slow = 10, .p2_fast = 5 },
394 static const struct intel_limit intel_limits_ironlake_single_lvds = {
395 .dot = { .min = 25000, .max = 350000 },
396 .vco = { .min = 1760000, .max = 3510000 },
397 .n = { .min = 1, .max = 3 },
398 .m = { .min = 79, .max = 118 },
399 .m1 = { .min = 12, .max = 22 },
400 .m2 = { .min = 5, .max = 9 },
401 .p = { .min = 28, .max = 112 },
402 .p1 = { .min = 2, .max = 8 },
403 .p2 = { .dot_limit = 225000,
404 .p2_slow = 14, .p2_fast = 14 },
407 static const struct intel_limit intel_limits_ironlake_dual_lvds = {
408 .dot = { .min = 25000, .max = 350000 },
409 .vco = { .min = 1760000, .max = 3510000 },
410 .n = { .min = 1, .max = 3 },
411 .m = { .min = 79, .max = 127 },
412 .m1 = { .min = 12, .max = 22 },
413 .m2 = { .min = 5, .max = 9 },
414 .p = { .min = 14, .max = 56 },
415 .p1 = { .min = 2, .max = 8 },
416 .p2 = { .dot_limit = 225000,
417 .p2_slow = 7, .p2_fast = 7 },
420 /* LVDS 100mhz refclk limits. */
421 static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
422 .dot = { .min = 25000, .max = 350000 },
423 .vco = { .min = 1760000, .max = 3510000 },
424 .n = { .min = 1, .max = 2 },
425 .m = { .min = 79, .max = 126 },
426 .m1 = { .min = 12, .max = 22 },
427 .m2 = { .min = 5, .max = 9 },
428 .p = { .min = 28, .max = 112 },
429 .p1 = { .min = 2, .max = 8 },
430 .p2 = { .dot_limit = 225000,
431 .p2_slow = 14, .p2_fast = 14 },
434 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
435 .dot = { .min = 25000, .max = 350000 },
436 .vco = { .min = 1760000, .max = 3510000 },
437 .n = { .min = 1, .max = 3 },
438 .m = { .min = 79, .max = 126 },
439 .m1 = { .min = 12, .max = 22 },
440 .m2 = { .min = 5, .max = 9 },
441 .p = { .min = 14, .max = 42 },
442 .p1 = { .min = 2, .max = 6 },
443 .p2 = { .dot_limit = 225000,
444 .p2_slow = 7, .p2_fast = 7 },
447 static const struct intel_limit intel_limits_vlv = {
449 * These are the data rate limits (measured in fast clocks)
450 * since those are the strictest limits we have. The fast
451 * clock and actual rate limits are more relaxed, so checking
452 * them would make no difference.
454 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
455 .vco = { .min = 4000000, .max = 6000000 },
456 .n = { .min = 1, .max = 7 },
457 .m1 = { .min = 2, .max = 3 },
458 .m2 = { .min = 11, .max = 156 },
459 .p1 = { .min = 2, .max = 3 },
460 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
463 static const struct intel_limit intel_limits_chv = {
465 * These are the data rate limits (measured in fast clocks)
466 * since those are the strictest limits we have. The fast
467 * clock and actual rate limits are more relaxed, so checking
468 * them would make no difference.
470 .dot = { .min = 25000 * 5, .max = 540000 * 5},
471 .vco = { .min = 4800000, .max = 6480000 },
472 .n = { .min = 1, .max = 1 },
473 .m1 = { .min = 2, .max = 2 },
474 .m2 = { .min = 24 << 22, .max = 175 << 22 },
475 .p1 = { .min = 2, .max = 4 },
476 .p2 = { .p2_slow = 1, .p2_fast = 14 },
479 static const struct intel_limit intel_limits_bxt = {
480 /* FIXME: find real dot limits */
481 .dot = { .min = 0, .max = INT_MAX },
482 .vco = { .min = 4800000, .max = 6700000 },
483 .n = { .min = 1, .max = 1 },
484 .m1 = { .min = 2, .max = 2 },
485 /* FIXME: find real m2 limits */
486 .m2 = { .min = 2 << 22, .max = 255 << 22 },
487 .p1 = { .min = 2, .max = 4 },
488 .p2 = { .p2_slow = 1, .p2_fast = 20 },
491 /* WA Display #0827: Gen9:all */
493 skl_wa_827(struct drm_i915_private *dev_priv, int pipe, bool enable)
496 I915_WRITE(CLKGATE_DIS_PSL(pipe),
497 I915_READ(CLKGATE_DIS_PSL(pipe)) |
498 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
500 I915_WRITE(CLKGATE_DIS_PSL(pipe),
501 I915_READ(CLKGATE_DIS_PSL(pipe)) &
502 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
505 /* Wa_2006604312:icl */
507 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
511 I915_WRITE(CLKGATE_DIS_PSL(pipe),
512 I915_READ(CLKGATE_DIS_PSL(pipe)) | DPFR_GATING_DIS);
514 I915_WRITE(CLKGATE_DIS_PSL(pipe),
515 I915_READ(CLKGATE_DIS_PSL(pipe)) & ~DPFR_GATING_DIS);
519 needs_modeset(const struct intel_crtc_state *state)
521 return drm_atomic_crtc_needs_modeset(&state->base);
525 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
526 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
527 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
528 * The helpers' return value is the rate of the clock that is fed to the
529 * display engine's pipe which can be the above fast dot clock rate or a
530 * divided-down version of it.
532 /* m1 is reserved as 0 in Pineview, n is a ring counter */
533 static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
535 clock->m = clock->m2 + 2;
536 clock->p = clock->p1 * clock->p2;
537 if (WARN_ON(clock->n == 0 || clock->p == 0))
539 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
540 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
545 static u32 i9xx_dpll_compute_m(struct dpll *dpll)
547 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
550 static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
552 clock->m = i9xx_dpll_compute_m(clock);
553 clock->p = clock->p1 * clock->p2;
554 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
556 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
557 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
562 static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
564 clock->m = clock->m1 * clock->m2;
565 clock->p = clock->p1 * clock->p2;
566 if (WARN_ON(clock->n == 0 || clock->p == 0))
568 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
569 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
571 return clock->dot / 5;
574 int chv_calc_dpll_params(int refclk, struct dpll *clock)
576 clock->m = clock->m1 * clock->m2;
577 clock->p = clock->p1 * clock->p2;
578 if (WARN_ON(clock->n == 0 || clock->p == 0))
580 clock->vco = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(refclk, clock->m),
582 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
584 return clock->dot / 5;
587 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
590 * Returns whether the given set of divisors are valid for a given refclk with
591 * the given connectors.
593 static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
594 const struct intel_limit *limit,
595 const struct dpll *clock)
597 if (clock->n < limit->n.min || limit->n.max < clock->n)
598 INTELPllInvalid("n out of range\n");
599 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
600 INTELPllInvalid("p1 out of range\n");
601 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
602 INTELPllInvalid("m2 out of range\n");
603 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
604 INTELPllInvalid("m1 out of range\n");
606 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
607 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
608 if (clock->m1 <= clock->m2)
609 INTELPllInvalid("m1 <= m2\n");
611 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
612 !IS_GEN9_LP(dev_priv)) {
613 if (clock->p < limit->p.min || limit->p.max < clock->p)
614 INTELPllInvalid("p out of range\n");
615 if (clock->m < limit->m.min || limit->m.max < clock->m)
616 INTELPllInvalid("m out of range\n");
619 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
620 INTELPllInvalid("vco out of range\n");
621 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
622 * connector, etc., rather than just a single range.
624 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
625 INTELPllInvalid("dot out of range\n");
631 i9xx_select_p2_div(const struct intel_limit *limit,
632 const struct intel_crtc_state *crtc_state,
635 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
637 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
639 * For LVDS just rely on its current settings for dual-channel.
640 * We haven't figured out how to reliably set up different
641 * single/dual channel state, if we even can.
643 if (intel_is_dual_link_lvds(dev_priv))
644 return limit->p2.p2_fast;
646 return limit->p2.p2_slow;
648 if (target < limit->p2.dot_limit)
649 return limit->p2.p2_slow;
651 return limit->p2.p2_fast;
656 * Returns a set of divisors for the desired target clock with the given
657 * refclk, or FALSE. The returned values represent the clock equation:
658 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
660 * Target and reference clocks are specified in kHz.
662 * If match_clock is provided, then best_clock P divider must match the P
663 * divider from @match_clock used for LVDS downclocking.
666 i9xx_find_best_dpll(const struct intel_limit *limit,
667 struct intel_crtc_state *crtc_state,
668 int target, int refclk, struct dpll *match_clock,
669 struct dpll *best_clock)
671 struct drm_device *dev = crtc_state->base.crtc->dev;
675 memset(best_clock, 0, sizeof(*best_clock));
677 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
679 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
681 for (clock.m2 = limit->m2.min;
682 clock.m2 <= limit->m2.max; clock.m2++) {
683 if (clock.m2 >= clock.m1)
685 for (clock.n = limit->n.min;
686 clock.n <= limit->n.max; clock.n++) {
687 for (clock.p1 = limit->p1.min;
688 clock.p1 <= limit->p1.max; clock.p1++) {
691 i9xx_calc_dpll_params(refclk, &clock);
692 if (!intel_PLL_is_valid(to_i915(dev),
697 clock.p != match_clock->p)
700 this_err = abs(clock.dot - target);
701 if (this_err < err) {
710 return (err != target);
714 * Returns a set of divisors for the desired target clock with the given
715 * refclk, or FALSE. The returned values represent the clock equation:
716 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
718 * Target and reference clocks are specified in kHz.
720 * If match_clock is provided, then best_clock P divider must match the P
721 * divider from @match_clock used for LVDS downclocking.
724 pnv_find_best_dpll(const struct intel_limit *limit,
725 struct intel_crtc_state *crtc_state,
726 int target, int refclk, struct dpll *match_clock,
727 struct dpll *best_clock)
729 struct drm_device *dev = crtc_state->base.crtc->dev;
733 memset(best_clock, 0, sizeof(*best_clock));
735 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
737 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
739 for (clock.m2 = limit->m2.min;
740 clock.m2 <= limit->m2.max; clock.m2++) {
741 for (clock.n = limit->n.min;
742 clock.n <= limit->n.max; clock.n++) {
743 for (clock.p1 = limit->p1.min;
744 clock.p1 <= limit->p1.max; clock.p1++) {
747 pnv_calc_dpll_params(refclk, &clock);
748 if (!intel_PLL_is_valid(to_i915(dev),
753 clock.p != match_clock->p)
756 this_err = abs(clock.dot - target);
757 if (this_err < err) {
766 return (err != target);
770 * Returns a set of divisors for the desired target clock with the given
771 * refclk, or FALSE. The returned values represent the clock equation:
772 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
774 * Target and reference clocks are specified in kHz.
776 * If match_clock is provided, then best_clock P divider must match the P
777 * divider from @match_clock used for LVDS downclocking.
780 g4x_find_best_dpll(const struct intel_limit *limit,
781 struct intel_crtc_state *crtc_state,
782 int target, int refclk, struct dpll *match_clock,
783 struct dpll *best_clock)
785 struct drm_device *dev = crtc_state->base.crtc->dev;
789 /* approximately equals target * 0.00585 */
790 int err_most = (target >> 8) + (target >> 9);
792 memset(best_clock, 0, sizeof(*best_clock));
794 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
796 max_n = limit->n.max;
797 /* based on hardware requirement, prefer smaller n to precision */
798 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
799 /* based on hardware requirement, prefere larger m1,m2 */
800 for (clock.m1 = limit->m1.max;
801 clock.m1 >= limit->m1.min; clock.m1--) {
802 for (clock.m2 = limit->m2.max;
803 clock.m2 >= limit->m2.min; clock.m2--) {
804 for (clock.p1 = limit->p1.max;
805 clock.p1 >= limit->p1.min; clock.p1--) {
808 i9xx_calc_dpll_params(refclk, &clock);
809 if (!intel_PLL_is_valid(to_i915(dev),
814 this_err = abs(clock.dot - target);
815 if (this_err < err_most) {
829 * Check if the calculated PLL configuration is more optimal compared to the
830 * best configuration and error found so far. Return the calculated error.
832 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
833 const struct dpll *calculated_clock,
834 const struct dpll *best_clock,
835 unsigned int best_error_ppm,
836 unsigned int *error_ppm)
839 * For CHV ignore the error and consider only the P value.
840 * Prefer a bigger P value based on HW requirements.
842 if (IS_CHERRYVIEW(to_i915(dev))) {
845 return calculated_clock->p > best_clock->p;
848 if (WARN_ON_ONCE(!target_freq))
851 *error_ppm = div_u64(1000000ULL *
852 abs(target_freq - calculated_clock->dot),
855 * Prefer a better P value over a better (smaller) error if the error
856 * is small. Ensure this preference for future configurations too by
857 * setting the error to 0.
859 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
865 return *error_ppm + 10 < best_error_ppm;
869 * Returns a set of divisors for the desired target clock with the given
870 * refclk, or FALSE. The returned values represent the clock equation:
871 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
874 vlv_find_best_dpll(const struct intel_limit *limit,
875 struct intel_crtc_state *crtc_state,
876 int target, int refclk, struct dpll *match_clock,
877 struct dpll *best_clock)
879 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
880 struct drm_device *dev = crtc->base.dev;
882 unsigned int bestppm = 1000000;
883 /* min update 19.2 MHz */
884 int max_n = min(limit->n.max, refclk / 19200);
887 target *= 5; /* fast clock */
889 memset(best_clock, 0, sizeof(*best_clock));
891 /* based on hardware requirement, prefer smaller n to precision */
892 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
893 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
894 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
895 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
896 clock.p = clock.p1 * clock.p2;
897 /* based on hardware requirement, prefer bigger m1,m2 values */
898 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
901 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
904 vlv_calc_dpll_params(refclk, &clock);
906 if (!intel_PLL_is_valid(to_i915(dev),
911 if (!vlv_PLL_is_optimal(dev, target,
929 * Returns a set of divisors for the desired target clock with the given
930 * refclk, or FALSE. The returned values represent the clock equation:
931 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
934 chv_find_best_dpll(const struct intel_limit *limit,
935 struct intel_crtc_state *crtc_state,
936 int target, int refclk, struct dpll *match_clock,
937 struct dpll *best_clock)
939 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
940 struct drm_device *dev = crtc->base.dev;
941 unsigned int best_error_ppm;
946 memset(best_clock, 0, sizeof(*best_clock));
947 best_error_ppm = 1000000;
950 * Based on hardware doc, the n always set to 1, and m1 always
951 * set to 2. If requires to support 200Mhz refclk, we need to
952 * revisit this because n may not 1 anymore.
954 clock.n = 1, clock.m1 = 2;
955 target *= 5; /* fast clock */
957 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
958 for (clock.p2 = limit->p2.p2_fast;
959 clock.p2 >= limit->p2.p2_slow;
960 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
961 unsigned int error_ppm;
963 clock.p = clock.p1 * clock.p2;
965 m2 = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(target, clock.p * clock.n) << 22,
968 if (m2 > INT_MAX/clock.m1)
973 chv_calc_dpll_params(refclk, &clock);
975 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
978 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
979 best_error_ppm, &error_ppm))
983 best_error_ppm = error_ppm;
991 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state,
992 struct dpll *best_clock)
995 const struct intel_limit *limit = &intel_limits_bxt;
997 return chv_find_best_dpll(limit, crtc_state,
998 crtc_state->port_clock, refclk,
1002 bool intel_crtc_active(struct intel_crtc *crtc)
1004 /* Be paranoid as we can arrive here with only partial
1005 * state retrieved from the hardware during setup.
1007 * We can ditch the adjusted_mode.crtc_clock check as soon
1008 * as Haswell has gained clock readout/fastboot support.
1010 * We can ditch the crtc->primary->state->fb check as soon as we can
1011 * properly reconstruct framebuffers.
1013 * FIXME: The intel_crtc->active here should be switched to
1014 * crtc->state->active once we have proper CRTC states wired up
1017 return crtc->active && crtc->base.primary->state->fb &&
1018 crtc->config->base.adjusted_mode.crtc_clock;
1021 enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
1024 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1026 return crtc->config->cpu_transcoder;
1029 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
1032 i915_reg_t reg = PIPEDSL(pipe);
1036 if (IS_GEN(dev_priv, 2))
1037 line_mask = DSL_LINEMASK_GEN2;
1039 line_mask = DSL_LINEMASK_GEN3;
1041 line1 = I915_READ(reg) & line_mask;
1043 line2 = I915_READ(reg) & line_mask;
1045 return line1 != line2;
1048 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1050 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1051 enum pipe pipe = crtc->pipe;
1053 /* Wait for the display line to settle/start moving */
1054 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1055 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1056 pipe_name(pipe), onoff(state));
1059 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1061 wait_for_pipe_scanline_moving(crtc, false);
1064 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1066 wait_for_pipe_scanline_moving(crtc, true);
1070 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
1072 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1073 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1075 if (INTEL_GEN(dev_priv) >= 4) {
1076 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1077 i915_reg_t reg = PIPECONF(cpu_transcoder);
1079 /* Wait for the Pipe State to go off */
1080 if (intel_de_wait_for_clear(dev_priv, reg,
1081 I965_PIPECONF_ACTIVE, 100))
1082 WARN(1, "pipe_off wait timed out\n");
1084 intel_wait_for_pipe_scanline_stopped(crtc);
1088 /* Only for pre-ILK configs */
1089 void assert_pll(struct drm_i915_private *dev_priv,
1090 enum pipe pipe, bool state)
1095 val = I915_READ(DPLL(pipe));
1096 cur_state = !!(val & DPLL_VCO_ENABLE);
1097 I915_STATE_WARN(cur_state != state,
1098 "PLL state assertion failure (expected %s, current %s)\n",
1099 onoff(state), onoff(cur_state));
1102 /* XXX: the dsi pll is shared between MIPI DSI ports */
1103 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1108 vlv_cck_get(dev_priv);
1109 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1110 vlv_cck_put(dev_priv);
1112 cur_state = val & DSI_PLL_VCO_EN;
1113 I915_STATE_WARN(cur_state != state,
1114 "DSI PLL state assertion failure (expected %s, current %s)\n",
1115 onoff(state), onoff(cur_state));
1118 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1119 enum pipe pipe, bool state)
1122 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1125 if (HAS_DDI(dev_priv)) {
1126 /* DDI does not have a specific FDI_TX register */
1127 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1128 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1130 u32 val = I915_READ(FDI_TX_CTL(pipe));
1131 cur_state = !!(val & FDI_TX_ENABLE);
1133 I915_STATE_WARN(cur_state != state,
1134 "FDI TX state assertion failure (expected %s, current %s)\n",
1135 onoff(state), onoff(cur_state));
1137 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1138 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1140 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1141 enum pipe pipe, bool state)
1146 val = I915_READ(FDI_RX_CTL(pipe));
1147 cur_state = !!(val & FDI_RX_ENABLE);
1148 I915_STATE_WARN(cur_state != state,
1149 "FDI RX state assertion failure (expected %s, current %s)\n",
1150 onoff(state), onoff(cur_state));
1152 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1153 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1155 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1160 /* ILK FDI PLL is always enabled */
1161 if (IS_GEN(dev_priv, 5))
1164 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1165 if (HAS_DDI(dev_priv))
1168 val = I915_READ(FDI_TX_CTL(pipe));
1169 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1172 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1173 enum pipe pipe, bool state)
1178 val = I915_READ(FDI_RX_CTL(pipe));
1179 cur_state = !!(val & FDI_RX_PLL_ENABLE);
1180 I915_STATE_WARN(cur_state != state,
1181 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1182 onoff(state), onoff(cur_state));
1185 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
1189 enum pipe panel_pipe = INVALID_PIPE;
1192 if (WARN_ON(HAS_DDI(dev_priv)))
1195 if (HAS_PCH_SPLIT(dev_priv)) {
1198 pp_reg = PP_CONTROL(0);
1199 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1202 case PANEL_PORT_SELECT_LVDS:
1203 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
1205 case PANEL_PORT_SELECT_DPA:
1206 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1208 case PANEL_PORT_SELECT_DPC:
1209 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1211 case PANEL_PORT_SELECT_DPD:
1212 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1215 MISSING_CASE(port_sel);
1218 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1219 /* presumably write lock depends on pipe, not port select */
1220 pp_reg = PP_CONTROL(pipe);
1225 pp_reg = PP_CONTROL(0);
1226 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1228 WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS);
1229 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
1232 val = I915_READ(pp_reg);
1233 if (!(val & PANEL_POWER_ON) ||
1234 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1237 I915_STATE_WARN(panel_pipe == pipe && locked,
1238 "panel assertion failure, pipe %c regs locked\n",
1242 void assert_pipe(struct drm_i915_private *dev_priv,
1243 enum pipe pipe, bool state)
1246 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1248 enum intel_display_power_domain power_domain;
1249 intel_wakeref_t wakeref;
1251 /* we keep both pipes enabled on 830 */
1252 if (IS_I830(dev_priv))
1255 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1256 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1258 u32 val = I915_READ(PIPECONF(cpu_transcoder));
1259 cur_state = !!(val & PIPECONF_ENABLE);
1261 intel_display_power_put(dev_priv, power_domain, wakeref);
1266 I915_STATE_WARN(cur_state != state,
1267 "pipe %c assertion failure (expected %s, current %s)\n",
1268 pipe_name(pipe), onoff(state), onoff(cur_state));
1271 static void assert_plane(struct intel_plane *plane, bool state)
1276 cur_state = plane->get_hw_state(plane, &pipe);
1278 I915_STATE_WARN(cur_state != state,
1279 "%s assertion failure (expected %s, current %s)\n",
1280 plane->base.name, onoff(state), onoff(cur_state));
1283 #define assert_plane_enabled(p) assert_plane(p, true)
1284 #define assert_plane_disabled(p) assert_plane(p, false)
1286 static void assert_planes_disabled(struct intel_crtc *crtc)
1288 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1289 struct intel_plane *plane;
1291 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1292 assert_plane_disabled(plane);
1295 static void assert_vblank_disabled(struct drm_crtc *crtc)
1297 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1298 drm_crtc_vblank_put(crtc);
1301 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1307 val = I915_READ(PCH_TRANSCONF(pipe));
1308 enabled = !!(val & TRANS_ENABLE);
1309 I915_STATE_WARN(enabled,
1310 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1314 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1315 enum pipe pipe, enum port port,
1318 enum pipe port_pipe;
1321 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1323 I915_STATE_WARN(state && port_pipe == pipe,
1324 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1325 port_name(port), pipe_name(pipe));
1327 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1328 "IBX PCH DP %c still using transcoder B\n",
1332 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1333 enum pipe pipe, enum port port,
1334 i915_reg_t hdmi_reg)
1336 enum pipe port_pipe;
1339 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1341 I915_STATE_WARN(state && port_pipe == pipe,
1342 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1343 port_name(port), pipe_name(pipe));
1345 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1346 "IBX PCH HDMI %c still using transcoder B\n",
1350 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1353 enum pipe port_pipe;
1355 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1356 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1357 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
1359 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1361 "PCH VGA enabled on transcoder %c, should be disabled\n",
1364 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1366 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1369 /* PCH SDVOB multiplex with HDMIB */
1370 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1371 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1372 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
1375 static void _vlv_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;
1381 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1382 POSTING_READ(DPLL(pipe));
1385 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
1386 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1389 static void vlv_enable_pll(struct intel_crtc *crtc,
1390 const struct intel_crtc_state *pipe_config)
1392 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1393 enum pipe pipe = crtc->pipe;
1395 assert_pipe_disabled(dev_priv, pipe);
1397 /* PLL is protected by panel, make sure we can write it */
1398 assert_panel_unlocked(dev_priv, pipe);
1400 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1401 _vlv_enable_pll(crtc, pipe_config);
1403 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1404 POSTING_READ(DPLL_MD(pipe));
1408 static void _chv_enable_pll(struct intel_crtc *crtc,
1409 const struct intel_crtc_state *pipe_config)
1411 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1412 enum pipe pipe = crtc->pipe;
1413 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1416 vlv_dpio_get(dev_priv);
1418 /* Enable back the 10bit clock to display controller */
1419 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1420 tmp |= DPIO_DCLKP_EN;
1421 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1423 vlv_dpio_put(dev_priv);
1426 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1431 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1433 /* Check PLL is locked */
1434 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
1435 DRM_ERROR("PLL %d failed to lock\n", pipe);
1438 static void chv_enable_pll(struct intel_crtc *crtc,
1439 const struct intel_crtc_state *pipe_config)
1441 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1442 enum pipe pipe = crtc->pipe;
1444 assert_pipe_disabled(dev_priv, pipe);
1446 /* PLL is protected by panel, make sure we can write it */
1447 assert_panel_unlocked(dev_priv, pipe);
1449 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1450 _chv_enable_pll(crtc, pipe_config);
1452 if (pipe != PIPE_A) {
1454 * WaPixelRepeatModeFixForC0:chv
1456 * DPLLCMD is AWOL. Use chicken bits to propagate
1457 * the value from DPLLBMD to either pipe B or C.
1459 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1460 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1461 I915_WRITE(CBR4_VLV, 0);
1462 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1465 * DPLLB VGA mode also seems to cause problems.
1466 * We should always have it disabled.
1468 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1470 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1471 POSTING_READ(DPLL_MD(pipe));
1475 static bool i9xx_has_pps(struct drm_i915_private *dev_priv)
1477 if (IS_I830(dev_priv))
1480 return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
1483 static void i9xx_enable_pll(struct intel_crtc *crtc,
1484 const struct intel_crtc_state *crtc_state)
1486 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1487 i915_reg_t reg = DPLL(crtc->pipe);
1488 u32 dpll = crtc_state->dpll_hw_state.dpll;
1491 assert_pipe_disabled(dev_priv, crtc->pipe);
1493 /* PLL is protected by panel, make sure we can write it */
1494 if (i9xx_has_pps(dev_priv))
1495 assert_panel_unlocked(dev_priv, crtc->pipe);
1498 * Apparently we need to have VGA mode enabled prior to changing
1499 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1500 * dividers, even though the register value does change.
1502 I915_WRITE(reg, dpll & ~DPLL_VGA_MODE_DIS);
1503 I915_WRITE(reg, dpll);
1505 /* Wait for the clocks to stabilize. */
1509 if (INTEL_GEN(dev_priv) >= 4) {
1510 I915_WRITE(DPLL_MD(crtc->pipe),
1511 crtc_state->dpll_hw_state.dpll_md);
1513 /* The pixel multiplier can only be updated once the
1514 * DPLL is enabled and the clocks are stable.
1516 * So write it again.
1518 I915_WRITE(reg, dpll);
1521 /* We do this three times for luck */
1522 for (i = 0; i < 3; i++) {
1523 I915_WRITE(reg, dpll);
1525 udelay(150); /* wait for warmup */
1529 static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
1531 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1532 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1533 enum pipe pipe = crtc->pipe;
1535 /* Don't disable pipe or pipe PLLs if needed */
1536 if (IS_I830(dev_priv))
1539 /* Make sure the pipe isn't still relying on us */
1540 assert_pipe_disabled(dev_priv, pipe);
1542 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
1543 POSTING_READ(DPLL(pipe));
1546 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1550 /* Make sure the pipe isn't still relying on us */
1551 assert_pipe_disabled(dev_priv, pipe);
1553 val = DPLL_INTEGRATED_REF_CLK_VLV |
1554 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1556 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1558 I915_WRITE(DPLL(pipe), val);
1559 POSTING_READ(DPLL(pipe));
1562 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1564 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1567 /* Make sure the pipe isn't still relying on us */
1568 assert_pipe_disabled(dev_priv, pipe);
1570 val = DPLL_SSC_REF_CLK_CHV |
1571 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1573 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1575 I915_WRITE(DPLL(pipe), val);
1576 POSTING_READ(DPLL(pipe));
1578 vlv_dpio_get(dev_priv);
1580 /* Disable 10bit clock to display controller */
1581 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1582 val &= ~DPIO_DCLKP_EN;
1583 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1585 vlv_dpio_put(dev_priv);
1588 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1589 struct intel_digital_port *dport,
1590 unsigned int expected_mask)
1593 i915_reg_t dpll_reg;
1595 switch (dport->base.port) {
1597 port_mask = DPLL_PORTB_READY_MASK;
1601 port_mask = DPLL_PORTC_READY_MASK;
1603 expected_mask <<= 4;
1606 port_mask = DPLL_PORTD_READY_MASK;
1607 dpll_reg = DPIO_PHY_STATUS;
1613 if (intel_de_wait_for_register(dev_priv, dpll_reg,
1614 port_mask, expected_mask, 1000))
1615 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1616 port_name(dport->base.port),
1617 I915_READ(dpll_reg) & port_mask, expected_mask);
1620 static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
1622 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1623 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1624 enum pipe pipe = crtc->pipe;
1626 u32 val, pipeconf_val;
1628 /* Make sure PCH DPLL is enabled */
1629 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
1631 /* FDI must be feeding us bits for PCH ports */
1632 assert_fdi_tx_enabled(dev_priv, pipe);
1633 assert_fdi_rx_enabled(dev_priv, pipe);
1635 if (HAS_PCH_CPT(dev_priv)) {
1636 /* Workaround: Set the timing override bit before enabling the
1637 * pch transcoder. */
1638 reg = TRANS_CHICKEN2(pipe);
1639 val = I915_READ(reg);
1640 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1641 I915_WRITE(reg, val);
1644 reg = PCH_TRANSCONF(pipe);
1645 val = I915_READ(reg);
1646 pipeconf_val = I915_READ(PIPECONF(pipe));
1648 if (HAS_PCH_IBX(dev_priv)) {
1650 * Make the BPC in transcoder be consistent with
1651 * that in pipeconf reg. For HDMI we must use 8bpc
1652 * here for both 8bpc and 12bpc.
1654 val &= ~PIPECONF_BPC_MASK;
1655 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1656 val |= PIPECONF_8BPC;
1658 val |= pipeconf_val & PIPECONF_BPC_MASK;
1661 val &= ~TRANS_INTERLACE_MASK;
1662 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) {
1663 if (HAS_PCH_IBX(dev_priv) &&
1664 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
1665 val |= TRANS_LEGACY_INTERLACED_ILK;
1667 val |= TRANS_INTERLACED;
1669 val |= TRANS_PROGRESSIVE;
1672 I915_WRITE(reg, val | TRANS_ENABLE);
1673 if (intel_de_wait_for_set(dev_priv, reg, TRANS_STATE_ENABLE, 100))
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_de_wait_for_set(dev_priv, LPT_TRANSCONF,
1702 TRANS_STATE_ENABLE, 100))
1703 DRM_ERROR("Failed to enable PCH transcoder\n");
1706 static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1712 /* FDI relies on the transcoder */
1713 assert_fdi_tx_disabled(dev_priv, pipe);
1714 assert_fdi_rx_disabled(dev_priv, pipe);
1716 /* Ports must be off as well */
1717 assert_pch_ports_disabled(dev_priv, pipe);
1719 reg = PCH_TRANSCONF(pipe);
1720 val = I915_READ(reg);
1721 val &= ~TRANS_ENABLE;
1722 I915_WRITE(reg, val);
1723 /* wait for PCH transcoder off, transcoder state */
1724 if (intel_de_wait_for_clear(dev_priv, reg, TRANS_STATE_ENABLE, 50))
1725 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
1727 if (HAS_PCH_CPT(dev_priv)) {
1728 /* Workaround: Clear the timing override chicken bit again. */
1729 reg = TRANS_CHICKEN2(pipe);
1730 val = I915_READ(reg);
1731 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1732 I915_WRITE(reg, val);
1736 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1740 val = I915_READ(LPT_TRANSCONF);
1741 val &= ~TRANS_ENABLE;
1742 I915_WRITE(LPT_TRANSCONF, val);
1743 /* wait for PCH transcoder off, transcoder state */
1744 if (intel_de_wait_for_clear(dev_priv, LPT_TRANSCONF,
1745 TRANS_STATE_ENABLE, 50))
1746 DRM_ERROR("Failed to disable PCH transcoder\n");
1748 /* Workaround: clear timing override bit. */
1749 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1750 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1751 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1754 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
1756 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1758 if (HAS_PCH_LPT(dev_priv))
1764 static u32 intel_crtc_max_vblank_count(const struct intel_crtc_state *crtc_state)
1766 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
1769 * On i965gm the hardware frame counter reads
1770 * zero when the TV encoder is enabled :(
1772 if (IS_I965GM(dev_priv) &&
1773 (crtc_state->output_types & BIT(INTEL_OUTPUT_TVOUT)))
1776 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
1777 return 0xffffffff; /* full 32 bit counter */
1778 else if (INTEL_GEN(dev_priv) >= 3)
1779 return 0xffffff; /* only 24 bits of frame count */
1781 return 0; /* Gen2 doesn't have a hardware frame counter */
1784 static void intel_crtc_vblank_on(const struct intel_crtc_state *crtc_state)
1786 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1788 drm_crtc_set_max_vblank_count(&crtc->base,
1789 intel_crtc_max_vblank_count(crtc_state));
1790 drm_crtc_vblank_on(&crtc->base);
1793 static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
1795 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1796 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1797 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1798 enum pipe pipe = crtc->pipe;
1802 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1804 assert_planes_disabled(crtc);
1807 * A pipe without a PLL won't actually be able to drive bits from
1808 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1811 if (HAS_GMCH(dev_priv)) {
1812 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1813 assert_dsi_pll_enabled(dev_priv);
1815 assert_pll_enabled(dev_priv, pipe);
1817 if (new_crtc_state->has_pch_encoder) {
1818 /* if driving the PCH, we need FDI enabled */
1819 assert_fdi_rx_pll_enabled(dev_priv,
1820 intel_crtc_pch_transcoder(crtc));
1821 assert_fdi_tx_pll_enabled(dev_priv,
1822 (enum pipe) cpu_transcoder);
1824 /* FIXME: assert CPU port conditions for SNB+ */
1827 trace_intel_pipe_enable(crtc);
1829 reg = PIPECONF(cpu_transcoder);
1830 val = I915_READ(reg);
1831 if (val & PIPECONF_ENABLE) {
1832 /* we keep both pipes enabled on 830 */
1833 WARN_ON(!IS_I830(dev_priv));
1837 I915_WRITE(reg, val | PIPECONF_ENABLE);
1841 * Until the pipe starts PIPEDSL reads will return a stale value,
1842 * which causes an apparent vblank timestamp jump when PIPEDSL
1843 * resets to its proper value. That also messes up the frame count
1844 * when it's derived from the timestamps. So let's wait for the
1845 * pipe to start properly before we call drm_crtc_vblank_on()
1847 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
1848 intel_wait_for_pipe_scanline_moving(crtc);
1851 static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1853 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1854 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1855 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1856 enum pipe pipe = crtc->pipe;
1860 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1863 * Make sure planes won't keep trying to pump pixels to us,
1864 * or we might hang the display.
1866 assert_planes_disabled(crtc);
1868 trace_intel_pipe_disable(crtc);
1870 reg = PIPECONF(cpu_transcoder);
1871 val = I915_READ(reg);
1872 if ((val & PIPECONF_ENABLE) == 0)
1876 * Double wide has implications for planes
1877 * so best keep it disabled when not needed.
1879 if (old_crtc_state->double_wide)
1880 val &= ~PIPECONF_DOUBLE_WIDE;
1882 /* Don't disable pipe or pipe PLLs if needed */
1883 if (!IS_I830(dev_priv))
1884 val &= ~PIPECONF_ENABLE;
1886 I915_WRITE(reg, val);
1887 if ((val & PIPECONF_ENABLE) == 0)
1888 intel_wait_for_pipe_off(old_crtc_state);
1891 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1893 return IS_GEN(dev_priv, 2) ? 2048 : 4096;
1897 intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
1899 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1900 unsigned int cpp = fb->format->cpp[color_plane];
1902 switch (fb->modifier) {
1903 case DRM_FORMAT_MOD_LINEAR:
1904 return intel_tile_size(dev_priv);
1905 case I915_FORMAT_MOD_X_TILED:
1906 if (IS_GEN(dev_priv, 2))
1910 case I915_FORMAT_MOD_Y_TILED_CCS:
1911 if (color_plane == 1)
1914 case I915_FORMAT_MOD_Y_TILED:
1915 if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv))
1919 case I915_FORMAT_MOD_Yf_TILED_CCS:
1920 if (color_plane == 1)
1923 case I915_FORMAT_MOD_Yf_TILED:
1939 MISSING_CASE(fb->modifier);
1945 intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
1947 return intel_tile_size(to_i915(fb->dev)) /
1948 intel_tile_width_bytes(fb, color_plane);
1951 /* Return the tile dimensions in pixel units */
1952 static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
1953 unsigned int *tile_width,
1954 unsigned int *tile_height)
1956 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
1957 unsigned int cpp = fb->format->cpp[color_plane];
1959 *tile_width = tile_width_bytes / cpp;
1960 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
1964 intel_fb_align_height(const struct drm_framebuffer *fb,
1965 int color_plane, unsigned int height)
1967 unsigned int tile_height = intel_tile_height(fb, color_plane);
1969 return ALIGN(height, tile_height);
1972 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
1974 unsigned int size = 0;
1977 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
1978 size += rot_info->plane[i].width * rot_info->plane[i].height;
1983 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
1985 unsigned int size = 0;
1988 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++)
1989 size += rem_info->plane[i].width * rem_info->plane[i].height;
1995 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
1996 const struct drm_framebuffer *fb,
1997 unsigned int rotation)
1999 view->type = I915_GGTT_VIEW_NORMAL;
2000 if (drm_rotation_90_or_270(rotation)) {
2001 view->type = I915_GGTT_VIEW_ROTATED;
2002 view->rotated = to_intel_framebuffer(fb)->rot_info;
2006 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
2008 if (IS_I830(dev_priv))
2010 else if (IS_I85X(dev_priv))
2012 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
2018 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
2020 if (INTEL_GEN(dev_priv) >= 9)
2022 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
2023 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2025 else if (INTEL_GEN(dev_priv) >= 4)
2031 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
2034 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2036 /* AUX_DIST needs only 4K alignment */
2037 if (color_plane == 1)
2040 switch (fb->modifier) {
2041 case DRM_FORMAT_MOD_LINEAR:
2042 return intel_linear_alignment(dev_priv);
2043 case I915_FORMAT_MOD_X_TILED:
2044 if (INTEL_GEN(dev_priv) >= 9)
2047 case I915_FORMAT_MOD_Y_TILED_CCS:
2048 case I915_FORMAT_MOD_Yf_TILED_CCS:
2049 case I915_FORMAT_MOD_Y_TILED:
2050 case I915_FORMAT_MOD_Yf_TILED:
2051 return 1 * 1024 * 1024;
2053 MISSING_CASE(fb->modifier);
2058 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2060 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2061 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2063 return INTEL_GEN(dev_priv) < 4 ||
2065 plane_state->view.type == I915_GGTT_VIEW_NORMAL);
2069 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
2070 const struct i915_ggtt_view *view,
2072 unsigned long *out_flags)
2074 struct drm_device *dev = fb->dev;
2075 struct drm_i915_private *dev_priv = to_i915(dev);
2076 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2077 intel_wakeref_t wakeref;
2078 struct i915_vma *vma;
2079 unsigned int pinctl;
2082 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2084 alignment = intel_surf_alignment(fb, 0);
2086 /* Note that the w/a also requires 64 PTE of padding following the
2087 * bo. We currently fill all unused PTE with the shadow page and so
2088 * we should always have valid PTE following the scanout preventing
2091 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2092 alignment = 256 * 1024;
2095 * Global gtt pte registers are special registers which actually forward
2096 * writes to a chunk of system memory. Which means that there is no risk
2097 * that the register values disappear as soon as we call
2098 * intel_runtime_pm_put(), so it is correct to wrap only the
2099 * pin/unpin/fence and not more.
2101 wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
2102 i915_gem_object_lock(obj);
2104 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2108 /* Valleyview is definitely limited to scanning out the first
2109 * 512MiB. Lets presume this behaviour was inherited from the
2110 * g4x display engine and that all earlier gen are similarly
2111 * limited. Testing suggests that it is a little more
2112 * complicated than this. For example, Cherryview appears quite
2113 * happy to scanout from anywhere within its global aperture.
2115 if (HAS_GMCH(dev_priv))
2116 pinctl |= PIN_MAPPABLE;
2118 vma = i915_gem_object_pin_to_display_plane(obj,
2119 alignment, view, pinctl);
2123 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
2126 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2127 * fence, whereas 965+ only requires a fence if using
2128 * framebuffer compression. For simplicity, we always, when
2129 * possible, install a fence as the cost is not that onerous.
2131 * If we fail to fence the tiled scanout, then either the
2132 * modeset will reject the change (which is highly unlikely as
2133 * the affected systems, all but one, do not have unmappable
2134 * space) or we will not be able to enable full powersaving
2135 * techniques (also likely not to apply due to various limits
2136 * FBC and the like impose on the size of the buffer, which
2137 * presumably we violated anyway with this unmappable buffer).
2138 * Anyway, it is presumably better to stumble onwards with
2139 * something and try to run the system in a "less than optimal"
2140 * mode that matches the user configuration.
2142 ret = i915_vma_pin_fence(vma);
2143 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
2144 i915_gem_object_unpin_from_display_plane(vma);
2149 if (ret == 0 && vma->fence)
2150 *out_flags |= PLANE_HAS_FENCE;
2155 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2157 i915_gem_object_unlock(obj);
2158 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
2162 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
2164 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
2166 i915_gem_object_lock(vma->obj);
2167 if (flags & PLANE_HAS_FENCE)
2168 i915_vma_unpin_fence(vma);
2169 i915_gem_object_unpin_from_display_plane(vma);
2170 i915_gem_object_unlock(vma->obj);
2175 static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
2176 unsigned int rotation)
2178 if (drm_rotation_90_or_270(rotation))
2179 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
2181 return fb->pitches[color_plane];
2185 * Convert the x/y offsets into a linear offset.
2186 * Only valid with 0/180 degree rotation, which is fine since linear
2187 * offset is only used with linear buffers on pre-hsw and tiled buffers
2188 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2190 u32 intel_fb_xy_to_linear(int x, int y,
2191 const struct intel_plane_state *state,
2194 const struct drm_framebuffer *fb = state->base.fb;
2195 unsigned int cpp = fb->format->cpp[color_plane];
2196 unsigned int pitch = state->color_plane[color_plane].stride;
2198 return y * pitch + x * cpp;
2202 * Add the x/y offsets derived from fb->offsets[] to the user
2203 * specified plane src x/y offsets. The resulting x/y offsets
2204 * specify the start of scanout from the beginning of the gtt mapping.
2206 void intel_add_fb_offsets(int *x, int *y,
2207 const struct intel_plane_state *state,
2211 *x += state->color_plane[color_plane].x;
2212 *y += state->color_plane[color_plane].y;
2215 static u32 intel_adjust_tile_offset(int *x, int *y,
2216 unsigned int tile_width,
2217 unsigned int tile_height,
2218 unsigned int tile_size,
2219 unsigned int pitch_tiles,
2223 unsigned int pitch_pixels = pitch_tiles * tile_width;
2226 WARN_ON(old_offset & (tile_size - 1));
2227 WARN_ON(new_offset & (tile_size - 1));
2228 WARN_ON(new_offset > old_offset);
2230 tiles = (old_offset - new_offset) / tile_size;
2232 *y += tiles / pitch_tiles * tile_height;
2233 *x += tiles % pitch_tiles * tile_width;
2235 /* minimize x in case it got needlessly big */
2236 *y += *x / pitch_pixels * tile_height;
2242 static bool is_surface_linear(u64 modifier, int color_plane)
2244 return modifier == DRM_FORMAT_MOD_LINEAR;
2247 static u32 intel_adjust_aligned_offset(int *x, int *y,
2248 const struct drm_framebuffer *fb,
2250 unsigned int rotation,
2252 u32 old_offset, u32 new_offset)
2254 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2255 unsigned int cpp = fb->format->cpp[color_plane];
2257 WARN_ON(new_offset > old_offset);
2259 if (!is_surface_linear(fb->modifier, color_plane)) {
2260 unsigned int tile_size, tile_width, tile_height;
2261 unsigned int pitch_tiles;
2263 tile_size = intel_tile_size(dev_priv);
2264 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2266 if (drm_rotation_90_or_270(rotation)) {
2267 pitch_tiles = pitch / tile_height;
2268 swap(tile_width, tile_height);
2270 pitch_tiles = pitch / (tile_width * cpp);
2273 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2274 tile_size, pitch_tiles,
2275 old_offset, new_offset);
2277 old_offset += *y * pitch + *x * cpp;
2279 *y = (old_offset - new_offset) / pitch;
2280 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2287 * Adjust the tile offset by moving the difference into
2290 static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2291 const struct intel_plane_state *state,
2293 u32 old_offset, u32 new_offset)
2295 return intel_adjust_aligned_offset(x, y, state->base.fb, color_plane,
2296 state->base.rotation,
2297 state->color_plane[color_plane].stride,
2298 old_offset, new_offset);
2302 * Computes the aligned offset to the base tile and adjusts
2303 * x, y. bytes per pixel is assumed to be a power-of-two.
2305 * In the 90/270 rotated case, x and y are assumed
2306 * to be already rotated to match the rotated GTT view, and
2307 * pitch is the tile_height aligned framebuffer height.
2309 * This function is used when computing the derived information
2310 * under intel_framebuffer, so using any of that information
2311 * here is not allowed. Anything under drm_framebuffer can be
2312 * used. This is why the user has to pass in the pitch since it
2313 * is specified in the rotated orientation.
2315 static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2317 const struct drm_framebuffer *fb,
2320 unsigned int rotation,
2323 unsigned int cpp = fb->format->cpp[color_plane];
2324 u32 offset, offset_aligned;
2329 if (!is_surface_linear(fb->modifier, color_plane)) {
2330 unsigned int tile_size, tile_width, tile_height;
2331 unsigned int tile_rows, tiles, pitch_tiles;
2333 tile_size = intel_tile_size(dev_priv);
2334 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2336 if (drm_rotation_90_or_270(rotation)) {
2337 pitch_tiles = pitch / tile_height;
2338 swap(tile_width, tile_height);
2340 pitch_tiles = pitch / (tile_width * cpp);
2343 tile_rows = *y / tile_height;
2346 tiles = *x / tile_width;
2349 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2350 offset_aligned = offset & ~alignment;
2352 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2353 tile_size, pitch_tiles,
2354 offset, offset_aligned);
2356 offset = *y * pitch + *x * cpp;
2357 offset_aligned = offset & ~alignment;
2359 *y = (offset & alignment) / pitch;
2360 *x = ((offset & alignment) - *y * pitch) / cpp;
2363 return offset_aligned;
2366 static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2367 const struct intel_plane_state *state,
2370 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2371 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2372 const struct drm_framebuffer *fb = state->base.fb;
2373 unsigned int rotation = state->base.rotation;
2374 int pitch = state->color_plane[color_plane].stride;
2377 if (intel_plane->id == PLANE_CURSOR)
2378 alignment = intel_cursor_alignment(dev_priv);
2380 alignment = intel_surf_alignment(fb, color_plane);
2382 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
2383 pitch, rotation, alignment);
2386 /* Convert the fb->offset[] into x/y offsets */
2387 static int intel_fb_offset_to_xy(int *x, int *y,
2388 const struct drm_framebuffer *fb,
2391 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2392 unsigned int height;
2394 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
2395 fb->offsets[color_plane] % intel_tile_size(dev_priv)) {
2396 DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n",
2397 fb->offsets[color_plane], color_plane);
2401 height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
2402 height = ALIGN(height, intel_tile_height(fb, color_plane));
2404 /* Catch potential overflows early */
2405 if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
2406 fb->offsets[color_plane])) {
2407 DRM_DEBUG_KMS("Bad offset 0x%08x or pitch %d for color plane %d\n",
2408 fb->offsets[color_plane], fb->pitches[color_plane],
2416 intel_adjust_aligned_offset(x, y,
2417 fb, color_plane, DRM_MODE_ROTATE_0,
2418 fb->pitches[color_plane],
2419 fb->offsets[color_plane], 0);
2424 static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier)
2426 switch (fb_modifier) {
2427 case I915_FORMAT_MOD_X_TILED:
2428 return I915_TILING_X;
2429 case I915_FORMAT_MOD_Y_TILED:
2430 case I915_FORMAT_MOD_Y_TILED_CCS:
2431 return I915_TILING_Y;
2433 return I915_TILING_NONE;
2438 * From the Sky Lake PRM:
2439 * "The Color Control Surface (CCS) contains the compression status of
2440 * the cache-line pairs. The compression state of the cache-line pair
2441 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2442 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2443 * cache-line-pairs. CCS is always Y tiled."
2445 * Since cache line pairs refers to horizontally adjacent cache lines,
2446 * each cache line in the CCS corresponds to an area of 32x16 cache
2447 * lines on the main surface. Since each pixel is 4 bytes, this gives
2448 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2451 static const struct drm_format_info ccs_formats[] = {
2452 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
2453 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2454 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
2455 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2456 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
2457 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
2458 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
2459 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
2462 static const struct drm_format_info *
2463 lookup_format_info(const struct drm_format_info formats[],
2464 int num_formats, u32 format)
2468 for (i = 0; i < num_formats; i++) {
2469 if (formats[i].format == format)
2476 static const struct drm_format_info *
2477 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2479 switch (cmd->modifier[0]) {
2480 case I915_FORMAT_MOD_Y_TILED_CCS:
2481 case I915_FORMAT_MOD_Yf_TILED_CCS:
2482 return lookup_format_info(ccs_formats,
2483 ARRAY_SIZE(ccs_formats),
2490 bool is_ccs_modifier(u64 modifier)
2492 return modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2493 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2496 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
2497 u32 pixel_format, u64 modifier)
2499 struct intel_crtc *crtc;
2500 struct intel_plane *plane;
2503 * We assume the primary plane for pipe A has
2504 * the highest stride limits of them all.
2506 crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
2507 plane = to_intel_plane(crtc->base.primary);
2509 return plane->max_stride(plane, pixel_format, modifier,
2514 u32 intel_fb_max_stride(struct drm_i915_private *dev_priv,
2515 u32 pixel_format, u64 modifier)
2518 * Arbitrary limit for gen4+ chosen to match the
2519 * render engine max stride.
2521 * The new CCS hash mode makes remapping impossible
2523 if (!is_ccs_modifier(modifier)) {
2524 if (INTEL_GEN(dev_priv) >= 7)
2526 else if (INTEL_GEN(dev_priv) >= 4)
2530 return intel_plane_fb_max_stride(dev_priv, pixel_format, modifier);
2534 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
2536 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2538 if (fb->modifier == DRM_FORMAT_MOD_LINEAR) {
2539 u32 max_stride = intel_plane_fb_max_stride(dev_priv,
2544 * To make remapping with linear generally feasible
2545 * we need the stride to be page aligned.
2547 if (fb->pitches[color_plane] > max_stride)
2548 return intel_tile_size(dev_priv);
2552 return intel_tile_width_bytes(fb, color_plane);
2556 bool intel_plane_can_remap(const struct intel_plane_state *plane_state)
2558 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2559 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2560 const struct drm_framebuffer *fb = plane_state->base.fb;
2563 /* We don't want to deal with remapping with cursors */
2564 if (plane->id == PLANE_CURSOR)
2568 * The display engine limits already match/exceed the
2569 * render engine limits, so not much point in remapping.
2570 * Would also need to deal with the fence POT alignment
2571 * and gen2 2KiB GTT tile size.
2573 if (INTEL_GEN(dev_priv) < 4)
2577 * The new CCS hash mode isn't compatible with remapping as
2578 * the virtual address of the pages affects the compressed data.
2580 if (is_ccs_modifier(fb->modifier))
2583 /* Linear needs a page aligned stride for remapping */
2584 if (fb->modifier == DRM_FORMAT_MOD_LINEAR) {
2585 unsigned int alignment = intel_tile_size(dev_priv) - 1;
2587 for (i = 0; i < fb->format->num_planes; i++) {
2588 if (fb->pitches[i] & alignment)
2596 static bool intel_plane_needs_remap(const struct intel_plane_state *plane_state)
2598 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2599 const struct drm_framebuffer *fb = plane_state->base.fb;
2600 unsigned int rotation = plane_state->base.rotation;
2601 u32 stride, max_stride;
2604 * No remapping for invisible planes since we don't have
2605 * an actual source viewport to remap.
2607 if (!plane_state->base.visible)
2610 if (!intel_plane_can_remap(plane_state))
2614 * FIXME: aux plane limits on gen9+ are
2615 * unclear in Bspec, for now no checking.
2617 stride = intel_fb_pitch(fb, 0, rotation);
2618 max_stride = plane->max_stride(plane, fb->format->format,
2619 fb->modifier, rotation);
2621 return stride > max_stride;
2625 intel_fill_fb_info(struct drm_i915_private *dev_priv,
2626 struct drm_framebuffer *fb)
2628 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2629 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2630 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2631 u32 gtt_offset_rotated = 0;
2632 unsigned int max_size = 0;
2633 int i, num_planes = fb->format->num_planes;
2634 unsigned int tile_size = intel_tile_size(dev_priv);
2636 for (i = 0; i < num_planes; i++) {
2637 unsigned int width, height;
2638 unsigned int cpp, size;
2643 cpp = fb->format->cpp[i];
2644 width = drm_framebuffer_plane_width(fb->width, fb, i);
2645 height = drm_framebuffer_plane_height(fb->height, fb, i);
2647 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2649 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2654 if (is_ccs_modifier(fb->modifier) && i == 1) {
2655 int hsub = fb->format->hsub;
2656 int vsub = fb->format->vsub;
2657 int tile_width, tile_height;
2661 intel_tile_dims(fb, i, &tile_width, &tile_height);
2663 tile_height *= vsub;
2665 ccs_x = (x * hsub) % tile_width;
2666 ccs_y = (y * vsub) % tile_height;
2667 main_x = intel_fb->normal[0].x % tile_width;
2668 main_y = intel_fb->normal[0].y % tile_height;
2671 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2672 * x/y offsets must match between CCS and the main surface.
2674 if (main_x != ccs_x || main_y != ccs_y) {
2675 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2678 intel_fb->normal[0].x,
2679 intel_fb->normal[0].y,
2686 * The fence (if used) is aligned to the start of the object
2687 * so having the framebuffer wrap around across the edge of the
2688 * fenced region doesn't really work. We have no API to configure
2689 * the fence start offset within the object (nor could we probably
2690 * on gen2/3). So it's just easier if we just require that the
2691 * fb layout agrees with the fence layout. We already check that the
2692 * fb stride matches the fence stride elsewhere.
2694 if (i == 0 && i915_gem_object_is_tiled(obj) &&
2695 (x + width) * cpp > fb->pitches[i]) {
2696 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2702 * First pixel of the framebuffer from
2703 * the start of the normal gtt mapping.
2705 intel_fb->normal[i].x = x;
2706 intel_fb->normal[i].y = y;
2708 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
2712 offset /= tile_size;
2714 if (!is_surface_linear(fb->modifier, i)) {
2715 unsigned int tile_width, tile_height;
2716 unsigned int pitch_tiles;
2719 intel_tile_dims(fb, i, &tile_width, &tile_height);
2721 rot_info->plane[i].offset = offset;
2722 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2723 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2724 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2726 intel_fb->rotated[i].pitch =
2727 rot_info->plane[i].height * tile_height;
2729 /* how many tiles does this plane need */
2730 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2732 * If the plane isn't horizontally tile aligned,
2733 * we need one more tile.
2738 /* rotate the x/y offsets to match the GTT view */
2744 rot_info->plane[i].width * tile_width,
2745 rot_info->plane[i].height * tile_height,
2746 DRM_MODE_ROTATE_270);
2750 /* rotate the tile dimensions to match the GTT view */
2751 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2752 swap(tile_width, tile_height);
2755 * We only keep the x/y offsets, so push all of the
2756 * gtt offset into the x/y offsets.
2758 intel_adjust_tile_offset(&x, &y,
2759 tile_width, tile_height,
2760 tile_size, pitch_tiles,
2761 gtt_offset_rotated * tile_size, 0);
2763 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2766 * First pixel of the framebuffer from
2767 * the start of the rotated gtt mapping.
2769 intel_fb->rotated[i].x = x;
2770 intel_fb->rotated[i].y = y;
2772 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2773 x * cpp, tile_size);
2776 /* how many tiles in total needed in the bo */
2777 max_size = max(max_size, offset + size);
2780 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
2781 DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n",
2782 mul_u32_u32(max_size, tile_size), obj->base.size);
2790 intel_plane_remap_gtt(struct intel_plane_state *plane_state)
2792 struct drm_i915_private *dev_priv =
2793 to_i915(plane_state->base.plane->dev);
2794 struct drm_framebuffer *fb = plane_state->base.fb;
2795 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2796 struct intel_rotation_info *info = &plane_state->view.rotated;
2797 unsigned int rotation = plane_state->base.rotation;
2798 int i, num_planes = fb->format->num_planes;
2799 unsigned int tile_size = intel_tile_size(dev_priv);
2800 unsigned int src_x, src_y;
2801 unsigned int src_w, src_h;
2804 memset(&plane_state->view, 0, sizeof(plane_state->view));
2805 plane_state->view.type = drm_rotation_90_or_270(rotation) ?
2806 I915_GGTT_VIEW_ROTATED : I915_GGTT_VIEW_REMAPPED;
2808 src_x = plane_state->base.src.x1 >> 16;
2809 src_y = plane_state->base.src.y1 >> 16;
2810 src_w = drm_rect_width(&plane_state->base.src) >> 16;
2811 src_h = drm_rect_height(&plane_state->base.src) >> 16;
2813 WARN_ON(is_ccs_modifier(fb->modifier));
2815 /* Make src coordinates relative to the viewport */
2816 drm_rect_translate(&plane_state->base.src,
2817 -(src_x << 16), -(src_y << 16));
2819 /* Rotate src coordinates to match rotated GTT view */
2820 if (drm_rotation_90_or_270(rotation))
2821 drm_rect_rotate(&plane_state->base.src,
2822 src_w << 16, src_h << 16,
2823 DRM_MODE_ROTATE_270);
2825 for (i = 0; i < num_planes; i++) {
2826 unsigned int hsub = i ? fb->format->hsub : 1;
2827 unsigned int vsub = i ? fb->format->vsub : 1;
2828 unsigned int cpp = fb->format->cpp[i];
2829 unsigned int tile_width, tile_height;
2830 unsigned int width, height;
2831 unsigned int pitch_tiles;
2835 intel_tile_dims(fb, i, &tile_width, &tile_height);
2839 width = src_w / hsub;
2840 height = src_h / vsub;
2843 * First pixel of the src viewport from the
2844 * start of the normal gtt mapping.
2846 x += intel_fb->normal[i].x;
2847 y += intel_fb->normal[i].y;
2849 offset = intel_compute_aligned_offset(dev_priv, &x, &y,
2850 fb, i, fb->pitches[i],
2851 DRM_MODE_ROTATE_0, tile_size);
2852 offset /= tile_size;
2854 info->plane[i].offset = offset;
2855 info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i],
2857 info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2858 info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2860 if (drm_rotation_90_or_270(rotation)) {
2863 /* rotate the x/y offsets to match the GTT view */
2869 info->plane[i].width * tile_width,
2870 info->plane[i].height * tile_height,
2871 DRM_MODE_ROTATE_270);
2875 pitch_tiles = info->plane[i].height;
2876 plane_state->color_plane[i].stride = pitch_tiles * tile_height;
2878 /* rotate the tile dimensions to match the GTT view */
2879 swap(tile_width, tile_height);
2881 pitch_tiles = info->plane[i].width;
2882 plane_state->color_plane[i].stride = pitch_tiles * tile_width * cpp;
2886 * We only keep the x/y offsets, so push all of the
2887 * gtt offset into the x/y offsets.
2889 intel_adjust_tile_offset(&x, &y,
2890 tile_width, tile_height,
2891 tile_size, pitch_tiles,
2892 gtt_offset * tile_size, 0);
2894 gtt_offset += info->plane[i].width * info->plane[i].height;
2896 plane_state->color_plane[i].offset = 0;
2897 plane_state->color_plane[i].x = x;
2898 plane_state->color_plane[i].y = y;
2903 intel_plane_compute_gtt(struct intel_plane_state *plane_state)
2905 const struct intel_framebuffer *fb =
2906 to_intel_framebuffer(plane_state->base.fb);
2907 unsigned int rotation = plane_state->base.rotation;
2913 num_planes = fb->base.format->num_planes;
2915 if (intel_plane_needs_remap(plane_state)) {
2916 intel_plane_remap_gtt(plane_state);
2919 * Sometimes even remapping can't overcome
2920 * the stride limitations :( Can happen with
2921 * big plane sizes and suitably misaligned
2924 return intel_plane_check_stride(plane_state);
2927 intel_fill_fb_ggtt_view(&plane_state->view, &fb->base, rotation);
2929 for (i = 0; i < num_planes; i++) {
2930 plane_state->color_plane[i].stride = intel_fb_pitch(&fb->base, i, rotation);
2931 plane_state->color_plane[i].offset = 0;
2933 if (drm_rotation_90_or_270(rotation)) {
2934 plane_state->color_plane[i].x = fb->rotated[i].x;
2935 plane_state->color_plane[i].y = fb->rotated[i].y;
2937 plane_state->color_plane[i].x = fb->normal[i].x;
2938 plane_state->color_plane[i].y = fb->normal[i].y;
2942 /* Rotate src coordinates to match rotated GTT view */
2943 if (drm_rotation_90_or_270(rotation))
2944 drm_rect_rotate(&plane_state->base.src,
2945 fb->base.width << 16, fb->base.height << 16,
2946 DRM_MODE_ROTATE_270);
2948 return intel_plane_check_stride(plane_state);
2951 static int i9xx_format_to_fourcc(int format)
2954 case DISPPLANE_8BPP:
2955 return DRM_FORMAT_C8;
2956 case DISPPLANE_BGRX555:
2957 return DRM_FORMAT_XRGB1555;
2958 case DISPPLANE_BGRX565:
2959 return DRM_FORMAT_RGB565;
2961 case DISPPLANE_BGRX888:
2962 return DRM_FORMAT_XRGB8888;
2963 case DISPPLANE_RGBX888:
2964 return DRM_FORMAT_XBGR8888;
2965 case DISPPLANE_BGRX101010:
2966 return DRM_FORMAT_XRGB2101010;
2967 case DISPPLANE_RGBX101010:
2968 return DRM_FORMAT_XBGR2101010;
2972 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
2975 case PLANE_CTL_FORMAT_RGB_565:
2976 return DRM_FORMAT_RGB565;
2977 case PLANE_CTL_FORMAT_NV12:
2978 return DRM_FORMAT_NV12;
2979 case PLANE_CTL_FORMAT_P010:
2980 return DRM_FORMAT_P010;
2981 case PLANE_CTL_FORMAT_P012:
2982 return DRM_FORMAT_P012;
2983 case PLANE_CTL_FORMAT_P016:
2984 return DRM_FORMAT_P016;
2985 case PLANE_CTL_FORMAT_Y210:
2986 return DRM_FORMAT_Y210;
2987 case PLANE_CTL_FORMAT_Y212:
2988 return DRM_FORMAT_Y212;
2989 case PLANE_CTL_FORMAT_Y216:
2990 return DRM_FORMAT_Y216;
2991 case PLANE_CTL_FORMAT_Y410:
2992 return DRM_FORMAT_XVYU2101010;
2993 case PLANE_CTL_FORMAT_Y412:
2994 return DRM_FORMAT_XVYU12_16161616;
2995 case PLANE_CTL_FORMAT_Y416:
2996 return DRM_FORMAT_XVYU16161616;
2998 case PLANE_CTL_FORMAT_XRGB_8888:
3001 return DRM_FORMAT_ABGR8888;
3003 return DRM_FORMAT_XBGR8888;
3006 return DRM_FORMAT_ARGB8888;
3008 return DRM_FORMAT_XRGB8888;
3010 case PLANE_CTL_FORMAT_XRGB_2101010:
3012 return DRM_FORMAT_XBGR2101010;
3014 return DRM_FORMAT_XRGB2101010;
3015 case PLANE_CTL_FORMAT_XRGB_16161616F:
3018 return DRM_FORMAT_ABGR16161616F;
3020 return DRM_FORMAT_XBGR16161616F;
3023 return DRM_FORMAT_ARGB16161616F;
3025 return DRM_FORMAT_XRGB16161616F;
3031 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
3032 struct intel_initial_plane_config *plane_config)
3034 struct drm_device *dev = crtc->base.dev;
3035 struct drm_i915_private *dev_priv = to_i915(dev);
3036 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
3037 struct drm_framebuffer *fb = &plane_config->fb->base;
3038 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
3039 u32 size_aligned = round_up(plane_config->base + plane_config->size,
3041 struct drm_i915_gem_object *obj;
3044 size_aligned -= base_aligned;
3046 if (plane_config->size == 0)
3049 /* If the FB is too big, just don't use it since fbdev is not very
3050 * important and we should probably use that space with FBC or other
3052 if (size_aligned * 2 > dev_priv->stolen_usable_size)
3055 switch (fb->modifier) {
3056 case DRM_FORMAT_MOD_LINEAR:
3057 case I915_FORMAT_MOD_X_TILED:
3058 case I915_FORMAT_MOD_Y_TILED:
3061 DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n",
3066 mutex_lock(&dev->struct_mutex);
3067 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
3071 mutex_unlock(&dev->struct_mutex);
3075 switch (plane_config->tiling) {
3076 case I915_TILING_NONE:
3080 obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling;
3083 MISSING_CASE(plane_config->tiling);
3087 mode_cmd.pixel_format = fb->format->format;
3088 mode_cmd.width = fb->width;
3089 mode_cmd.height = fb->height;
3090 mode_cmd.pitches[0] = fb->pitches[0];
3091 mode_cmd.modifier[0] = fb->modifier;
3092 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
3094 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
3095 DRM_DEBUG_KMS("intel fb init failed\n");
3100 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
3103 i915_gem_object_put(obj);
3108 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
3109 struct intel_plane_state *plane_state,
3112 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
3114 plane_state->base.visible = visible;
3117 crtc_state->base.plane_mask |= drm_plane_mask(&plane->base);
3119 crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base);
3122 static void fixup_active_planes(struct intel_crtc_state *crtc_state)
3124 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
3125 struct drm_plane *plane;
3128 * Active_planes aliases if multiple "primary" or cursor planes
3129 * have been used on the same (or wrong) pipe. plane_mask uses
3130 * unique ids, hence we can use that to reconstruct active_planes.
3132 crtc_state->active_planes = 0;
3134 drm_for_each_plane_mask(plane, &dev_priv->drm,
3135 crtc_state->base.plane_mask)
3136 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
3139 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
3140 struct intel_plane *plane)
3142 struct intel_crtc_state *crtc_state =
3143 to_intel_crtc_state(crtc->base.state);
3144 struct intel_plane_state *plane_state =
3145 to_intel_plane_state(plane->base.state);
3147 DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
3148 plane->base.base.id, plane->base.name,
3149 crtc->base.base.id, crtc->base.name);
3151 intel_set_plane_visible(crtc_state, plane_state, false);
3152 fixup_active_planes(crtc_state);
3153 crtc_state->data_rate[plane->id] = 0;
3155 if (plane->id == PLANE_PRIMARY)
3156 intel_pre_disable_primary_noatomic(&crtc->base);
3158 intel_disable_plane(plane, crtc_state);
3161 static struct intel_frontbuffer *
3162 to_intel_frontbuffer(struct drm_framebuffer *fb)
3164 return fb ? to_intel_framebuffer(fb)->frontbuffer : NULL;
3168 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
3169 struct intel_initial_plane_config *plane_config)
3171 struct drm_device *dev = intel_crtc->base.dev;
3172 struct drm_i915_private *dev_priv = to_i915(dev);
3174 struct drm_plane *primary = intel_crtc->base.primary;
3175 struct drm_plane_state *plane_state = primary->state;
3176 struct intel_plane *intel_plane = to_intel_plane(primary);
3177 struct intel_plane_state *intel_state =
3178 to_intel_plane_state(plane_state);
3179 struct drm_framebuffer *fb;
3181 if (!plane_config->fb)
3184 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
3185 fb = &plane_config->fb->base;
3189 kfree(plane_config->fb);
3192 * Failed to alloc the obj, check to see if we should share
3193 * an fb with another CRTC instead
3195 for_each_crtc(dev, c) {
3196 struct intel_plane_state *state;
3198 if (c == &intel_crtc->base)
3201 if (!to_intel_crtc(c)->active)
3204 state = to_intel_plane_state(c->primary->state);
3208 if (intel_plane_ggtt_offset(state) == plane_config->base) {
3209 fb = state->base.fb;
3210 drm_framebuffer_get(fb);
3216 * We've failed to reconstruct the BIOS FB. Current display state
3217 * indicates that the primary plane is visible, but has a NULL FB,
3218 * which will lead to problems later if we don't fix it up. The
3219 * simplest solution is to just disable the primary plane now and
3220 * pretend the BIOS never had it enabled.
3222 intel_plane_disable_noatomic(intel_crtc, intel_plane);
3227 intel_state->base.rotation = plane_config->rotation;
3228 intel_fill_fb_ggtt_view(&intel_state->view, fb,
3229 intel_state->base.rotation);
3230 intel_state->color_plane[0].stride =
3231 intel_fb_pitch(fb, 0, intel_state->base.rotation);
3233 mutex_lock(&dev->struct_mutex);
3235 intel_pin_and_fence_fb_obj(fb,
3237 intel_plane_uses_fence(intel_state),
3238 &intel_state->flags);
3239 mutex_unlock(&dev->struct_mutex);
3240 if (IS_ERR(intel_state->vma)) {
3241 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
3242 intel_crtc->pipe, PTR_ERR(intel_state->vma));
3244 intel_state->vma = NULL;
3245 drm_framebuffer_put(fb);
3249 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
3251 plane_state->src_x = 0;
3252 plane_state->src_y = 0;
3253 plane_state->src_w = fb->width << 16;
3254 plane_state->src_h = fb->height << 16;
3256 plane_state->crtc_x = 0;
3257 plane_state->crtc_y = 0;
3258 plane_state->crtc_w = fb->width;
3259 plane_state->crtc_h = fb->height;
3261 intel_state->base.src = drm_plane_state_src(plane_state);
3262 intel_state->base.dst = drm_plane_state_dest(plane_state);
3264 if (plane_config->tiling)
3265 dev_priv->preserve_bios_swizzle = true;
3267 plane_state->fb = fb;
3268 plane_state->crtc = &intel_crtc->base;
3270 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
3271 &to_intel_frontbuffer(fb)->bits);
3274 static int skl_max_plane_width(const struct drm_framebuffer *fb,
3276 unsigned int rotation)
3278 int cpp = fb->format->cpp[color_plane];
3280 switch (fb->modifier) {
3281 case DRM_FORMAT_MOD_LINEAR:
3282 case I915_FORMAT_MOD_X_TILED:
3284 * Validated limit is 4k, but has 5k should
3285 * work apart from the following features:
3286 * - Ytile (already limited to 4k)
3287 * - FP16 (already limited to 4k)
3288 * - render compression (already limited to 4k)
3289 * - KVMR sprite and cursor (don't care)
3290 * - horizontal panning (TODO verify this)
3291 * - pipe and plane scaling (TODO verify this)
3297 case I915_FORMAT_MOD_Y_TILED_CCS:
3298 case I915_FORMAT_MOD_Yf_TILED_CCS:
3299 /* FIXME AUX plane? */
3300 case I915_FORMAT_MOD_Y_TILED:
3301 case I915_FORMAT_MOD_Yf_TILED:
3307 MISSING_CASE(fb->modifier);
3312 static int glk_max_plane_width(const struct drm_framebuffer *fb,
3314 unsigned int rotation)
3316 int cpp = fb->format->cpp[color_plane];
3318 switch (fb->modifier) {
3319 case DRM_FORMAT_MOD_LINEAR:
3320 case I915_FORMAT_MOD_X_TILED:
3325 case I915_FORMAT_MOD_Y_TILED_CCS:
3326 case I915_FORMAT_MOD_Yf_TILED_CCS:
3327 /* FIXME AUX plane? */
3328 case I915_FORMAT_MOD_Y_TILED:
3329 case I915_FORMAT_MOD_Yf_TILED:
3335 MISSING_CASE(fb->modifier);
3340 static int icl_max_plane_width(const struct drm_framebuffer *fb,
3342 unsigned int rotation)
3347 static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
3348 int main_x, int main_y, u32 main_offset)
3350 const struct drm_framebuffer *fb = plane_state->base.fb;
3351 int hsub = fb->format->hsub;
3352 int vsub = fb->format->vsub;
3353 int aux_x = plane_state->color_plane[1].x;
3354 int aux_y = plane_state->color_plane[1].y;
3355 u32 aux_offset = plane_state->color_plane[1].offset;
3356 u32 alignment = intel_surf_alignment(fb, 1);
3358 while (aux_offset >= main_offset && aux_y <= main_y) {
3361 if (aux_x == main_x && aux_y == main_y)
3364 if (aux_offset == 0)
3369 aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1,
3370 aux_offset, aux_offset - alignment);
3371 aux_x = x * hsub + aux_x % hsub;
3372 aux_y = y * vsub + aux_y % vsub;
3375 if (aux_x != main_x || aux_y != main_y)
3378 plane_state->color_plane[1].offset = aux_offset;
3379 plane_state->color_plane[1].x = aux_x;
3380 plane_state->color_plane[1].y = aux_y;
3385 static int skl_check_main_surface(struct intel_plane_state *plane_state)
3387 struct drm_i915_private *dev_priv = to_i915(plane_state->base.plane->dev);
3388 const struct drm_framebuffer *fb = plane_state->base.fb;
3389 unsigned int rotation = plane_state->base.rotation;
3390 int x = plane_state->base.src.x1 >> 16;
3391 int y = plane_state->base.src.y1 >> 16;
3392 int w = drm_rect_width(&plane_state->base.src) >> 16;
3393 int h = drm_rect_height(&plane_state->base.src) >> 16;
3395 int max_height = 4096;
3396 u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset;
3398 if (INTEL_GEN(dev_priv) >= 11)
3399 max_width = icl_max_plane_width(fb, 0, rotation);
3400 else if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
3401 max_width = glk_max_plane_width(fb, 0, rotation);
3403 max_width = skl_max_plane_width(fb, 0, rotation);
3405 if (w > max_width || h > max_height) {
3406 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
3407 w, h, max_width, max_height);
3411 intel_add_fb_offsets(&x, &y, plane_state, 0);
3412 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
3413 alignment = intel_surf_alignment(fb, 0);
3416 * AUX surface offset is specified as the distance from the
3417 * main surface offset, and it must be non-negative. Make
3418 * sure that is what we will get.
3420 if (offset > aux_offset)
3421 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3422 offset, aux_offset & ~(alignment - 1));
3425 * When using an X-tiled surface, the plane blows up
3426 * if the x offset + width exceed the stride.
3428 * TODO: linear and Y-tiled seem fine, Yf untested,
3430 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3431 int cpp = fb->format->cpp[0];
3433 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
3435 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
3439 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3440 offset, offset - alignment);
3445 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3446 * they match with the main surface x/y offsets.
3448 if (is_ccs_modifier(fb->modifier)) {
3449 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3453 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3454 offset, offset - alignment);
3457 if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) {
3458 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3463 plane_state->color_plane[0].offset = offset;
3464 plane_state->color_plane[0].x = x;
3465 plane_state->color_plane[0].y = y;
3468 * Put the final coordinates back so that the src
3469 * coordinate checks will see the right values.
3471 drm_rect_translate(&plane_state->base.src,
3472 (x << 16) - plane_state->base.src.x1,
3473 (y << 16) - plane_state->base.src.y1);
3478 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3480 const struct drm_framebuffer *fb = plane_state->base.fb;
3481 unsigned int rotation = plane_state->base.rotation;
3482 int max_width = skl_max_plane_width(fb, 1, rotation);
3483 int max_height = 4096;
3484 int x = plane_state->base.src.x1 >> 17;
3485 int y = plane_state->base.src.y1 >> 17;
3486 int w = drm_rect_width(&plane_state->base.src) >> 17;
3487 int h = drm_rect_height(&plane_state->base.src) >> 17;
3490 intel_add_fb_offsets(&x, &y, plane_state, 1);
3491 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3493 /* FIXME not quite sure how/if these apply to the chroma plane */
3494 if (w > max_width || h > max_height) {
3495 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3496 w, h, max_width, max_height);
3500 plane_state->color_plane[1].offset = offset;
3501 plane_state->color_plane[1].x = x;
3502 plane_state->color_plane[1].y = y;
3507 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3509 const struct drm_framebuffer *fb = plane_state->base.fb;
3510 int src_x = plane_state->base.src.x1 >> 16;
3511 int src_y = plane_state->base.src.y1 >> 16;
3512 int hsub = fb->format->hsub;
3513 int vsub = fb->format->vsub;
3514 int x = src_x / hsub;
3515 int y = src_y / vsub;
3518 intel_add_fb_offsets(&x, &y, plane_state, 1);
3519 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3521 plane_state->color_plane[1].offset = offset;
3522 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3523 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
3528 int skl_check_plane_surface(struct intel_plane_state *plane_state)
3530 const struct drm_framebuffer *fb = plane_state->base.fb;
3533 ret = intel_plane_compute_gtt(plane_state);
3537 if (!plane_state->base.visible)
3541 * Handle the AUX surface first since
3542 * the main surface setup depends on it.
3544 if (is_planar_yuv_format(fb->format->format)) {
3545 ret = skl_check_nv12_aux_surface(plane_state);
3548 } else if (is_ccs_modifier(fb->modifier)) {
3549 ret = skl_check_ccs_aux_surface(plane_state);
3553 plane_state->color_plane[1].offset = ~0xfff;
3554 plane_state->color_plane[1].x = 0;
3555 plane_state->color_plane[1].y = 0;
3558 ret = skl_check_main_surface(plane_state);
3566 i9xx_plane_max_stride(struct intel_plane *plane,
3567 u32 pixel_format, u64 modifier,
3568 unsigned int rotation)
3570 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3572 if (!HAS_GMCH(dev_priv)) {
3574 } else if (INTEL_GEN(dev_priv) >= 4) {
3575 if (modifier == I915_FORMAT_MOD_X_TILED)
3579 } else if (INTEL_GEN(dev_priv) >= 3) {
3580 if (modifier == I915_FORMAT_MOD_X_TILED)
3585 if (plane->i9xx_plane == PLANE_C)
3592 static u32 i9xx_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
3594 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3595 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3598 if (crtc_state->gamma_enable)
3599 dspcntr |= DISPPLANE_GAMMA_ENABLE;
3601 if (crtc_state->csc_enable)
3602 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
3604 if (INTEL_GEN(dev_priv) < 5)
3605 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
3610 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3611 const struct intel_plane_state *plane_state)
3613 struct drm_i915_private *dev_priv =
3614 to_i915(plane_state->base.plane->dev);
3615 const struct drm_framebuffer *fb = plane_state->base.fb;
3616 unsigned int rotation = plane_state->base.rotation;
3619 dspcntr = DISPLAY_PLANE_ENABLE;
3621 if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) ||
3622 IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
3623 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
3625 switch (fb->format->format) {
3627 dspcntr |= DISPPLANE_8BPP;
3629 case DRM_FORMAT_XRGB1555:
3630 dspcntr |= DISPPLANE_BGRX555;
3632 case DRM_FORMAT_RGB565:
3633 dspcntr |= DISPPLANE_BGRX565;
3635 case DRM_FORMAT_XRGB8888:
3636 dspcntr |= DISPPLANE_BGRX888;
3638 case DRM_FORMAT_XBGR8888:
3639 dspcntr |= DISPPLANE_RGBX888;
3641 case DRM_FORMAT_XRGB2101010:
3642 dspcntr |= DISPPLANE_BGRX101010;
3644 case DRM_FORMAT_XBGR2101010:
3645 dspcntr |= DISPPLANE_RGBX101010;
3648 MISSING_CASE(fb->format->format);
3652 if (INTEL_GEN(dev_priv) >= 4 &&
3653 fb->modifier == I915_FORMAT_MOD_X_TILED)
3654 dspcntr |= DISPPLANE_TILED;
3656 if (rotation & DRM_MODE_ROTATE_180)
3657 dspcntr |= DISPPLANE_ROTATE_180;
3659 if (rotation & DRM_MODE_REFLECT_X)
3660 dspcntr |= DISPPLANE_MIRROR;
3665 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
3667 struct drm_i915_private *dev_priv =
3668 to_i915(plane_state->base.plane->dev);
3673 ret = intel_plane_compute_gtt(plane_state);
3677 if (!plane_state->base.visible)
3680 src_x = plane_state->base.src.x1 >> 16;
3681 src_y = plane_state->base.src.y1 >> 16;
3683 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
3685 if (INTEL_GEN(dev_priv) >= 4)
3686 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
3692 * Put the final coordinates back so that the src
3693 * coordinate checks will see the right values.
3695 drm_rect_translate(&plane_state->base.src,
3696 (src_x << 16) - plane_state->base.src.x1,
3697 (src_y << 16) - plane_state->base.src.y1);
3699 /* HSW/BDW do this automagically in hardware */
3700 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
3701 unsigned int rotation = plane_state->base.rotation;
3702 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3703 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3705 if (rotation & DRM_MODE_ROTATE_180) {
3708 } else if (rotation & DRM_MODE_REFLECT_X) {
3713 plane_state->color_plane[0].offset = offset;
3714 plane_state->color_plane[0].x = src_x;
3715 plane_state->color_plane[0].y = src_y;
3720 static bool i9xx_plane_has_windowing(struct intel_plane *plane)
3722 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3723 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3725 if (IS_CHERRYVIEW(dev_priv))
3726 return i9xx_plane == PLANE_B;
3727 else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
3729 else if (IS_GEN(dev_priv, 4))
3730 return i9xx_plane == PLANE_C;
3732 return i9xx_plane == PLANE_B ||
3733 i9xx_plane == PLANE_C;
3737 i9xx_plane_check(struct intel_crtc_state *crtc_state,
3738 struct intel_plane_state *plane_state)
3740 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
3743 ret = chv_plane_check_rotation(plane_state);
3747 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
3749 DRM_PLANE_HELPER_NO_SCALING,
3750 DRM_PLANE_HELPER_NO_SCALING,
3751 i9xx_plane_has_windowing(plane),
3756 ret = i9xx_check_plane_surface(plane_state);
3760 if (!plane_state->base.visible)
3763 ret = intel_plane_check_src_coordinates(plane_state);
3767 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
3772 static void i9xx_update_plane(struct intel_plane *plane,
3773 const struct intel_crtc_state *crtc_state,
3774 const struct intel_plane_state *plane_state)
3776 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3777 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3779 int x = plane_state->color_plane[0].x;
3780 int y = plane_state->color_plane[0].y;
3781 int crtc_x = plane_state->base.dst.x1;
3782 int crtc_y = plane_state->base.dst.y1;
3783 int crtc_w = drm_rect_width(&plane_state->base.dst);
3784 int crtc_h = drm_rect_height(&plane_state->base.dst);
3785 unsigned long irqflags;
3789 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
3791 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
3793 if (INTEL_GEN(dev_priv) >= 4)
3794 dspaddr_offset = plane_state->color_plane[0].offset;
3796 dspaddr_offset = linear_offset;
3798 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3800 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
3802 if (INTEL_GEN(dev_priv) < 4) {
3804 * PLANE_A doesn't actually have a full window
3805 * generator but let's assume we still need to
3806 * program whatever is there.
3808 I915_WRITE_FW(DSPPOS(i9xx_plane), (crtc_y << 16) | crtc_x);
3809 I915_WRITE_FW(DSPSIZE(i9xx_plane),
3810 ((crtc_h - 1) << 16) | (crtc_w - 1));
3811 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
3812 I915_WRITE_FW(PRIMPOS(i9xx_plane), (crtc_y << 16) | crtc_x);
3813 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
3814 ((crtc_h - 1) << 16) | (crtc_w - 1));
3815 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
3818 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3819 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
3820 } else if (INTEL_GEN(dev_priv) >= 4) {
3821 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3822 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3826 * The control register self-arms if the plane was previously
3827 * disabled. Try to make the plane enable atomic by writing
3828 * the control register just before the surface register.
3830 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3831 if (INTEL_GEN(dev_priv) >= 4)
3832 I915_WRITE_FW(DSPSURF(i9xx_plane),
3833 intel_plane_ggtt_offset(plane_state) +
3836 I915_WRITE_FW(DSPADDR(i9xx_plane),
3837 intel_plane_ggtt_offset(plane_state) +
3840 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3843 static void i9xx_disable_plane(struct intel_plane *plane,
3844 const struct intel_crtc_state *crtc_state)
3846 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3847 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3848 unsigned long irqflags;
3852 * DSPCNTR pipe gamma enable on g4x+ and pipe csc
3853 * enable on ilk+ affect the pipe bottom color as
3854 * well, so we must configure them even if the plane
3857 * On pre-g4x there is no way to gamma correct the
3858 * pipe bottom color but we'll keep on doing this
3859 * anyway so that the crtc state readout works correctly.
3861 dspcntr = i9xx_plane_ctl_crtc(crtc_state);
3863 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3865 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3866 if (INTEL_GEN(dev_priv) >= 4)
3867 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
3869 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
3871 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3874 static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
3877 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3878 enum intel_display_power_domain power_domain;
3879 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3880 intel_wakeref_t wakeref;
3885 * Not 100% correct for planes that can move between pipes,
3886 * but that's only the case for gen2-4 which don't have any
3887 * display power wells.
3889 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
3890 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3894 val = I915_READ(DSPCNTR(i9xx_plane));
3896 ret = val & DISPLAY_PLANE_ENABLE;
3898 if (INTEL_GEN(dev_priv) >= 5)
3899 *pipe = plane->pipe;
3901 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
3902 DISPPLANE_SEL_PIPE_SHIFT;
3904 intel_display_power_put(dev_priv, power_domain, wakeref);
3909 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3911 struct drm_device *dev = intel_crtc->base.dev;
3912 struct drm_i915_private *dev_priv = to_i915(dev);
3914 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3915 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3916 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
3920 * This function detaches (aka. unbinds) unused scalers in hardware
3922 static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
3924 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3925 const struct intel_crtc_scaler_state *scaler_state =
3926 &crtc_state->scaler_state;
3929 /* loop through and disable scalers that aren't in use */
3930 for (i = 0; i < intel_crtc->num_scalers; i++) {
3931 if (!scaler_state->scalers[i].in_use)
3932 skl_detach_scaler(intel_crtc, i);
3936 static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
3937 int color_plane, unsigned int rotation)
3940 * The stride is either expressed as a multiple of 64 bytes chunks for
3941 * linear buffers or in number of tiles for tiled buffers.
3943 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3945 else if (drm_rotation_90_or_270(rotation))
3946 return intel_tile_height(fb, color_plane);
3948 return intel_tile_width_bytes(fb, color_plane);
3951 u32 skl_plane_stride(const struct intel_plane_state *plane_state,
3954 const struct drm_framebuffer *fb = plane_state->base.fb;
3955 unsigned int rotation = plane_state->base.rotation;
3956 u32 stride = plane_state->color_plane[color_plane].stride;
3958 if (color_plane >= fb->format->num_planes)
3961 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
3964 static u32 skl_plane_ctl_format(u32 pixel_format)
3966 switch (pixel_format) {
3968 return PLANE_CTL_FORMAT_INDEXED;
3969 case DRM_FORMAT_RGB565:
3970 return PLANE_CTL_FORMAT_RGB_565;
3971 case DRM_FORMAT_XBGR8888:
3972 case DRM_FORMAT_ABGR8888:
3973 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
3974 case DRM_FORMAT_XRGB8888:
3975 case DRM_FORMAT_ARGB8888:
3976 return PLANE_CTL_FORMAT_XRGB_8888;
3977 case DRM_FORMAT_XBGR2101010:
3978 return PLANE_CTL_FORMAT_XRGB_2101010 | PLANE_CTL_ORDER_RGBX;
3979 case DRM_FORMAT_XRGB2101010:
3980 return PLANE_CTL_FORMAT_XRGB_2101010;
3981 case DRM_FORMAT_XBGR16161616F:
3982 case DRM_FORMAT_ABGR16161616F:
3983 return PLANE_CTL_FORMAT_XRGB_16161616F | PLANE_CTL_ORDER_RGBX;
3984 case DRM_FORMAT_XRGB16161616F:
3985 case DRM_FORMAT_ARGB16161616F:
3986 return PLANE_CTL_FORMAT_XRGB_16161616F;
3987 case DRM_FORMAT_YUYV:
3988 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
3989 case DRM_FORMAT_YVYU:
3990 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
3991 case DRM_FORMAT_UYVY:
3992 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
3993 case DRM_FORMAT_VYUY:
3994 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
3995 case DRM_FORMAT_NV12:
3996 return PLANE_CTL_FORMAT_NV12;
3997 case DRM_FORMAT_P010:
3998 return PLANE_CTL_FORMAT_P010;
3999 case DRM_FORMAT_P012:
4000 return PLANE_CTL_FORMAT_P012;
4001 case DRM_FORMAT_P016:
4002 return PLANE_CTL_FORMAT_P016;
4003 case DRM_FORMAT_Y210:
4004 return PLANE_CTL_FORMAT_Y210;
4005 case DRM_FORMAT_Y212:
4006 return PLANE_CTL_FORMAT_Y212;
4007 case DRM_FORMAT_Y216:
4008 return PLANE_CTL_FORMAT_Y216;
4009 case DRM_FORMAT_XVYU2101010:
4010 return PLANE_CTL_FORMAT_Y410;
4011 case DRM_FORMAT_XVYU12_16161616:
4012 return PLANE_CTL_FORMAT_Y412;
4013 case DRM_FORMAT_XVYU16161616:
4014 return PLANE_CTL_FORMAT_Y416;
4016 MISSING_CASE(pixel_format);
4022 static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
4024 if (!plane_state->base.fb->format->has_alpha)
4025 return PLANE_CTL_ALPHA_DISABLE;
4027 switch (plane_state->base.pixel_blend_mode) {
4028 case DRM_MODE_BLEND_PIXEL_NONE:
4029 return PLANE_CTL_ALPHA_DISABLE;
4030 case DRM_MODE_BLEND_PREMULTI:
4031 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
4032 case DRM_MODE_BLEND_COVERAGE:
4033 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
4035 MISSING_CASE(plane_state->base.pixel_blend_mode);
4036 return PLANE_CTL_ALPHA_DISABLE;
4040 static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
4042 if (!plane_state->base.fb->format->has_alpha)
4043 return PLANE_COLOR_ALPHA_DISABLE;
4045 switch (plane_state->base.pixel_blend_mode) {
4046 case DRM_MODE_BLEND_PIXEL_NONE:
4047 return PLANE_COLOR_ALPHA_DISABLE;
4048 case DRM_MODE_BLEND_PREMULTI:
4049 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
4050 case DRM_MODE_BLEND_COVERAGE:
4051 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
4053 MISSING_CASE(plane_state->base.pixel_blend_mode);
4054 return PLANE_COLOR_ALPHA_DISABLE;
4058 static u32 skl_plane_ctl_tiling(u64 fb_modifier)
4060 switch (fb_modifier) {
4061 case DRM_FORMAT_MOD_LINEAR:
4063 case I915_FORMAT_MOD_X_TILED:
4064 return PLANE_CTL_TILED_X;
4065 case I915_FORMAT_MOD_Y_TILED:
4066 return PLANE_CTL_TILED_Y;
4067 case I915_FORMAT_MOD_Y_TILED_CCS:
4068 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
4069 case I915_FORMAT_MOD_Yf_TILED:
4070 return PLANE_CTL_TILED_YF;
4071 case I915_FORMAT_MOD_Yf_TILED_CCS:
4072 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
4074 MISSING_CASE(fb_modifier);
4080 static u32 skl_plane_ctl_rotate(unsigned int rotate)
4083 case DRM_MODE_ROTATE_0:
4086 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
4087 * while i915 HW rotation is clockwise, thats why this swapping.
4089 case DRM_MODE_ROTATE_90:
4090 return PLANE_CTL_ROTATE_270;
4091 case DRM_MODE_ROTATE_180:
4092 return PLANE_CTL_ROTATE_180;
4093 case DRM_MODE_ROTATE_270:
4094 return PLANE_CTL_ROTATE_90;
4096 MISSING_CASE(rotate);
4102 static u32 cnl_plane_ctl_flip(unsigned int reflect)
4107 case DRM_MODE_REFLECT_X:
4108 return PLANE_CTL_FLIP_HORIZONTAL;
4109 case DRM_MODE_REFLECT_Y:
4111 MISSING_CASE(reflect);
4117 u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
4119 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
4122 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
4125 if (crtc_state->gamma_enable)
4126 plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE;
4128 if (crtc_state->csc_enable)
4129 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
4134 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
4135 const struct intel_plane_state *plane_state)
4137 struct drm_i915_private *dev_priv =
4138 to_i915(plane_state->base.plane->dev);
4139 const struct drm_framebuffer *fb = plane_state->base.fb;
4140 unsigned int rotation = plane_state->base.rotation;
4141 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
4144 plane_ctl = PLANE_CTL_ENABLE;
4146 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
4147 plane_ctl |= skl_plane_ctl_alpha(plane_state);
4148 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
4150 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
4151 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
4153 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
4154 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
4157 plane_ctl |= skl_plane_ctl_format(fb->format->format);
4158 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
4159 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
4161 if (INTEL_GEN(dev_priv) >= 10)
4162 plane_ctl |= cnl_plane_ctl_flip(rotation &
4163 DRM_MODE_REFLECT_MASK);
4165 if (key->flags & I915_SET_COLORKEY_DESTINATION)
4166 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
4167 else if (key->flags & I915_SET_COLORKEY_SOURCE)
4168 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
4173 u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state)
4175 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
4176 u32 plane_color_ctl = 0;
4178 if (INTEL_GEN(dev_priv) >= 11)
4179 return plane_color_ctl;
4181 if (crtc_state->gamma_enable)
4182 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
4184 if (crtc_state->csc_enable)
4185 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
4187 return plane_color_ctl;
4190 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
4191 const struct intel_plane_state *plane_state)
4193 struct drm_i915_private *dev_priv =
4194 to_i915(plane_state->base.plane->dev);
4195 const struct drm_framebuffer *fb = plane_state->base.fb;
4196 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
4197 u32 plane_color_ctl = 0;
4199 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
4200 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
4202 if (fb->format->is_yuv && !icl_is_hdr_plane(dev_priv, plane->id)) {
4203 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
4204 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
4206 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
4208 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
4209 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
4210 } else if (fb->format->is_yuv) {
4211 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
4214 return plane_color_ctl;
4218 __intel_display_resume(struct drm_device *dev,
4219 struct drm_atomic_state *state,
4220 struct drm_modeset_acquire_ctx *ctx)
4222 struct drm_crtc_state *crtc_state;
4223 struct drm_crtc *crtc;
4226 intel_modeset_setup_hw_state(dev, ctx);
4227 i915_redisable_vga(to_i915(dev));
4233 * We've duplicated the state, pointers to the old state are invalid.
4235 * Don't attempt to use the old state until we commit the duplicated state.
4237 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
4239 * Force recalculation even if we restore
4240 * current state. With fast modeset this may not result
4241 * in a modeset when the state is compatible.
4243 crtc_state->mode_changed = true;
4246 /* ignore any reset values/BIOS leftovers in the WM registers */
4247 if (!HAS_GMCH(to_i915(dev)))
4248 to_intel_atomic_state(state)->skip_intermediate_wm = true;
4250 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
4252 WARN_ON(ret == -EDEADLK);
4256 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
4258 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
4259 intel_has_gpu_reset(dev_priv));
4262 void intel_prepare_reset(struct drm_i915_private *dev_priv)
4264 struct drm_device *dev = &dev_priv->drm;
4265 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
4266 struct drm_atomic_state *state;
4269 /* reset doesn't touch the display */
4270 if (!i915_modparams.force_reset_modeset_test &&
4271 !gpu_reset_clobbers_display(dev_priv))
4274 /* We have a modeset vs reset deadlock, defensively unbreak it. */
4275 set_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
4276 smp_mb__after_atomic();
4277 wake_up_bit(&dev_priv->gt.reset.flags, I915_RESET_MODESET);
4279 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
4280 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
4281 intel_gt_set_wedged(&dev_priv->gt);
4285 * Need mode_config.mutex so that we don't
4286 * trample ongoing ->detect() and whatnot.
4288 mutex_lock(&dev->mode_config.mutex);
4289 drm_modeset_acquire_init(ctx, 0);
4291 ret = drm_modeset_lock_all_ctx(dev, ctx);
4292 if (ret != -EDEADLK)
4295 drm_modeset_backoff(ctx);
4298 * Disabling the crtcs gracefully seems nicer. Also the
4299 * g33 docs say we should at least disable all the planes.
4301 state = drm_atomic_helper_duplicate_state(dev, ctx);
4302 if (IS_ERR(state)) {
4303 ret = PTR_ERR(state);
4304 DRM_ERROR("Duplicating state failed with %i\n", ret);
4308 ret = drm_atomic_helper_disable_all(dev, ctx);
4310 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
4311 drm_atomic_state_put(state);
4315 dev_priv->modeset_restore_state = state;
4316 state->acquire_ctx = ctx;
4319 void intel_finish_reset(struct drm_i915_private *dev_priv)
4321 struct drm_device *dev = &dev_priv->drm;
4322 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
4323 struct drm_atomic_state *state;
4326 /* reset doesn't touch the display */
4327 if (!test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
4330 state = fetch_and_zero(&dev_priv->modeset_restore_state);
4334 /* reset doesn't touch the display */
4335 if (!gpu_reset_clobbers_display(dev_priv)) {
4336 /* for testing only restore the display */
4337 ret = __intel_display_resume(dev, state, ctx);
4339 DRM_ERROR("Restoring old state failed with %i\n", ret);
4342 * The display has been reset as well,
4343 * so need a full re-initialization.
4345 intel_pps_unlock_regs_wa(dev_priv);
4346 intel_modeset_init_hw(dev);
4347 intel_init_clock_gating(dev_priv);
4349 spin_lock_irq(&dev_priv->irq_lock);
4350 if (dev_priv->display.hpd_irq_setup)
4351 dev_priv->display.hpd_irq_setup(dev_priv);
4352 spin_unlock_irq(&dev_priv->irq_lock);
4354 ret = __intel_display_resume(dev, state, ctx);
4356 DRM_ERROR("Restoring old state failed with %i\n", ret);
4358 intel_hpd_init(dev_priv);
4361 drm_atomic_state_put(state);
4363 drm_modeset_drop_locks(ctx);
4364 drm_modeset_acquire_fini(ctx);
4365 mutex_unlock(&dev->mode_config.mutex);
4367 clear_bit_unlock(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
4370 static void icl_set_pipe_chicken(struct intel_crtc *crtc)
4372 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4373 enum pipe pipe = crtc->pipe;
4376 tmp = I915_READ(PIPE_CHICKEN(pipe));
4379 * Display WA #1153: icl
4380 * enable hardware to bypass the alpha math
4381 * and rounding for per-pixel values 00 and 0xff
4383 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
4385 * Display WA # 1605353570: icl
4386 * Set the pixel rounding bit to 1 for allowing
4387 * passthrough of Frame buffer pixels unmodified
4390 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
4391 I915_WRITE(PIPE_CHICKEN(pipe), tmp);
4394 static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
4395 const struct intel_crtc_state *new_crtc_state)
4397 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
4398 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4400 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
4401 crtc->base.mode = new_crtc_state->base.mode;
4404 * Update pipe size and adjust fitter if needed: the reason for this is
4405 * that in compute_mode_changes we check the native mode (not the pfit
4406 * mode) to see if we can flip rather than do a full mode set. In the
4407 * fastboot case, we'll flip, but if we don't update the pipesrc and
4408 * pfit state, we'll end up with a big fb scanned out into the wrong
4412 I915_WRITE(PIPESRC(crtc->pipe),
4413 ((new_crtc_state->pipe_src_w - 1) << 16) |
4414 (new_crtc_state->pipe_src_h - 1));
4416 /* on skylake this is done by detaching scalers */
4417 if (INTEL_GEN(dev_priv) >= 9) {
4418 skl_detach_scalers(new_crtc_state);
4420 if (new_crtc_state->pch_pfit.enabled)
4421 skylake_pfit_enable(new_crtc_state);
4422 } else if (HAS_PCH_SPLIT(dev_priv)) {
4423 if (new_crtc_state->pch_pfit.enabled)
4424 ironlake_pfit_enable(new_crtc_state);
4425 else if (old_crtc_state->pch_pfit.enabled)
4426 ironlake_pfit_disable(old_crtc_state);
4429 if (INTEL_GEN(dev_priv) >= 11)
4430 icl_set_pipe_chicken(crtc);
4433 static void intel_fdi_normal_train(struct intel_crtc *crtc)
4435 struct drm_device *dev = crtc->base.dev;
4436 struct drm_i915_private *dev_priv = to_i915(dev);
4437 int pipe = crtc->pipe;
4441 /* enable normal train */
4442 reg = FDI_TX_CTL(pipe);
4443 temp = I915_READ(reg);
4444 if (IS_IVYBRIDGE(dev_priv)) {
4445 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4446 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
4448 temp &= ~FDI_LINK_TRAIN_NONE;
4449 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
4451 I915_WRITE(reg, temp);
4453 reg = FDI_RX_CTL(pipe);
4454 temp = I915_READ(reg);
4455 if (HAS_PCH_CPT(dev_priv)) {
4456 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4457 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
4459 temp &= ~FDI_LINK_TRAIN_NONE;
4460 temp |= FDI_LINK_TRAIN_NONE;
4462 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
4464 /* wait one idle pattern time */
4468 /* IVB wants error correction enabled */
4469 if (IS_IVYBRIDGE(dev_priv))
4470 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
4471 FDI_FE_ERRC_ENABLE);
4474 /* The FDI link training functions for ILK/Ibexpeak. */
4475 static void ironlake_fdi_link_train(struct intel_crtc *crtc,
4476 const struct intel_crtc_state *crtc_state)
4478 struct drm_device *dev = crtc->base.dev;
4479 struct drm_i915_private *dev_priv = to_i915(dev);
4480 int pipe = crtc->pipe;
4484 /* FDI needs bits from pipe first */
4485 assert_pipe_enabled(dev_priv, pipe);
4487 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4489 reg = FDI_RX_IMR(pipe);
4490 temp = I915_READ(reg);
4491 temp &= ~FDI_RX_SYMBOL_LOCK;
4492 temp &= ~FDI_RX_BIT_LOCK;
4493 I915_WRITE(reg, temp);
4497 /* enable CPU FDI TX and PCH FDI RX */
4498 reg = FDI_TX_CTL(pipe);
4499 temp = I915_READ(reg);
4500 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4501 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4502 temp &= ~FDI_LINK_TRAIN_NONE;
4503 temp |= FDI_LINK_TRAIN_PATTERN_1;
4504 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4506 reg = FDI_RX_CTL(pipe);
4507 temp = I915_READ(reg);
4508 temp &= ~FDI_LINK_TRAIN_NONE;
4509 temp |= FDI_LINK_TRAIN_PATTERN_1;
4510 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4515 /* Ironlake workaround, enable clock pointer after FDI enable*/
4516 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4517 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
4518 FDI_RX_PHASE_SYNC_POINTER_EN);
4520 reg = FDI_RX_IIR(pipe);
4521 for (tries = 0; tries < 5; tries++) {
4522 temp = I915_READ(reg);
4523 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4525 if ((temp & FDI_RX_BIT_LOCK)) {
4526 DRM_DEBUG_KMS("FDI train 1 done.\n");
4527 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4532 DRM_ERROR("FDI train 1 fail!\n");
4535 reg = FDI_TX_CTL(pipe);
4536 temp = I915_READ(reg);
4537 temp &= ~FDI_LINK_TRAIN_NONE;
4538 temp |= FDI_LINK_TRAIN_PATTERN_2;
4539 I915_WRITE(reg, temp);
4541 reg = FDI_RX_CTL(pipe);
4542 temp = I915_READ(reg);
4543 temp &= ~FDI_LINK_TRAIN_NONE;
4544 temp |= FDI_LINK_TRAIN_PATTERN_2;
4545 I915_WRITE(reg, temp);
4550 reg = FDI_RX_IIR(pipe);
4551 for (tries = 0; tries < 5; tries++) {
4552 temp = I915_READ(reg);
4553 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4555 if (temp & FDI_RX_SYMBOL_LOCK) {
4556 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4557 DRM_DEBUG_KMS("FDI train 2 done.\n");
4562 DRM_ERROR("FDI train 2 fail!\n");
4564 DRM_DEBUG_KMS("FDI train done\n");
4568 static const int snb_b_fdi_train_param[] = {
4569 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4570 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4571 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4572 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4575 /* The FDI link training functions for SNB/Cougarpoint. */
4576 static void gen6_fdi_link_train(struct intel_crtc *crtc,
4577 const struct intel_crtc_state *crtc_state)
4579 struct drm_device *dev = crtc->base.dev;
4580 struct drm_i915_private *dev_priv = to_i915(dev);
4581 int pipe = crtc->pipe;
4585 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4587 reg = FDI_RX_IMR(pipe);
4588 temp = I915_READ(reg);
4589 temp &= ~FDI_RX_SYMBOL_LOCK;
4590 temp &= ~FDI_RX_BIT_LOCK;
4591 I915_WRITE(reg, temp);
4596 /* enable CPU FDI TX and PCH FDI RX */
4597 reg = FDI_TX_CTL(pipe);
4598 temp = I915_READ(reg);
4599 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4600 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4601 temp &= ~FDI_LINK_TRAIN_NONE;
4602 temp |= FDI_LINK_TRAIN_PATTERN_1;
4603 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4605 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4606 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4608 I915_WRITE(FDI_RX_MISC(pipe),
4609 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4611 reg = FDI_RX_CTL(pipe);
4612 temp = I915_READ(reg);
4613 if (HAS_PCH_CPT(dev_priv)) {
4614 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4615 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4617 temp &= ~FDI_LINK_TRAIN_NONE;
4618 temp |= FDI_LINK_TRAIN_PATTERN_1;
4620 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4625 for (i = 0; i < 4; i++) {
4626 reg = FDI_TX_CTL(pipe);
4627 temp = I915_READ(reg);
4628 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4629 temp |= snb_b_fdi_train_param[i];
4630 I915_WRITE(reg, temp);
4635 for (retry = 0; retry < 5; retry++) {
4636 reg = FDI_RX_IIR(pipe);
4637 temp = I915_READ(reg);
4638 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4639 if (temp & FDI_RX_BIT_LOCK) {
4640 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4641 DRM_DEBUG_KMS("FDI train 1 done.\n");
4650 DRM_ERROR("FDI train 1 fail!\n");
4653 reg = FDI_TX_CTL(pipe);
4654 temp = I915_READ(reg);
4655 temp &= ~FDI_LINK_TRAIN_NONE;
4656 temp |= FDI_LINK_TRAIN_PATTERN_2;
4657 if (IS_GEN(dev_priv, 6)) {
4658 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4660 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4662 I915_WRITE(reg, temp);
4664 reg = FDI_RX_CTL(pipe);
4665 temp = I915_READ(reg);
4666 if (HAS_PCH_CPT(dev_priv)) {
4667 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4668 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4670 temp &= ~FDI_LINK_TRAIN_NONE;
4671 temp |= FDI_LINK_TRAIN_PATTERN_2;
4673 I915_WRITE(reg, temp);
4678 for (i = 0; i < 4; i++) {
4679 reg = FDI_TX_CTL(pipe);
4680 temp = I915_READ(reg);
4681 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4682 temp |= snb_b_fdi_train_param[i];
4683 I915_WRITE(reg, temp);
4688 for (retry = 0; retry < 5; retry++) {
4689 reg = FDI_RX_IIR(pipe);
4690 temp = I915_READ(reg);
4691 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4692 if (temp & FDI_RX_SYMBOL_LOCK) {
4693 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4694 DRM_DEBUG_KMS("FDI train 2 done.\n");
4703 DRM_ERROR("FDI train 2 fail!\n");
4705 DRM_DEBUG_KMS("FDI train done.\n");
4708 /* Manual link training for Ivy Bridge A0 parts */
4709 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4710 const struct intel_crtc_state *crtc_state)
4712 struct drm_device *dev = crtc->base.dev;
4713 struct drm_i915_private *dev_priv = to_i915(dev);
4714 int pipe = crtc->pipe;
4718 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4720 reg = FDI_RX_IMR(pipe);
4721 temp = I915_READ(reg);
4722 temp &= ~FDI_RX_SYMBOL_LOCK;
4723 temp &= ~FDI_RX_BIT_LOCK;
4724 I915_WRITE(reg, temp);
4729 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4730 I915_READ(FDI_RX_IIR(pipe)));
4732 /* Try each vswing and preemphasis setting twice before moving on */
4733 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4734 /* disable first in case we need to retry */
4735 reg = FDI_TX_CTL(pipe);
4736 temp = I915_READ(reg);
4737 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4738 temp &= ~FDI_TX_ENABLE;
4739 I915_WRITE(reg, temp);
4741 reg = FDI_RX_CTL(pipe);
4742 temp = I915_READ(reg);
4743 temp &= ~FDI_LINK_TRAIN_AUTO;
4744 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4745 temp &= ~FDI_RX_ENABLE;
4746 I915_WRITE(reg, temp);
4748 /* enable CPU FDI TX and PCH FDI RX */
4749 reg = FDI_TX_CTL(pipe);
4750 temp = I915_READ(reg);
4751 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4752 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4753 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
4754 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4755 temp |= snb_b_fdi_train_param[j/2];
4756 temp |= FDI_COMPOSITE_SYNC;
4757 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4759 I915_WRITE(FDI_RX_MISC(pipe),
4760 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4762 reg = FDI_RX_CTL(pipe);
4763 temp = I915_READ(reg);
4764 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4765 temp |= FDI_COMPOSITE_SYNC;
4766 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4769 udelay(1); /* should be 0.5us */
4771 for (i = 0; i < 4; i++) {
4772 reg = FDI_RX_IIR(pipe);
4773 temp = I915_READ(reg);
4774 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4776 if (temp & FDI_RX_BIT_LOCK ||
4777 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4778 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4779 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4783 udelay(1); /* should be 0.5us */
4786 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4791 reg = FDI_TX_CTL(pipe);
4792 temp = I915_READ(reg);
4793 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4794 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4795 I915_WRITE(reg, temp);
4797 reg = FDI_RX_CTL(pipe);
4798 temp = I915_READ(reg);
4799 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4800 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4801 I915_WRITE(reg, temp);
4804 udelay(2); /* should be 1.5us */
4806 for (i = 0; i < 4; i++) {
4807 reg = FDI_RX_IIR(pipe);
4808 temp = I915_READ(reg);
4809 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4811 if (temp & FDI_RX_SYMBOL_LOCK ||
4812 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4813 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4814 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4818 udelay(2); /* should be 1.5us */
4821 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
4825 DRM_DEBUG_KMS("FDI train done.\n");
4828 static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
4830 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4831 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4832 int pipe = intel_crtc->pipe;
4836 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4837 reg = FDI_RX_CTL(pipe);
4838 temp = I915_READ(reg);
4839 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
4840 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4841 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4842 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4847 /* Switch from Rawclk to PCDclk */
4848 temp = I915_READ(reg);
4849 I915_WRITE(reg, temp | FDI_PCDCLK);
4854 /* Enable CPU FDI TX PLL, always on for Ironlake */
4855 reg = FDI_TX_CTL(pipe);
4856 temp = I915_READ(reg);
4857 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4858 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
4865 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4867 struct drm_device *dev = intel_crtc->base.dev;
4868 struct drm_i915_private *dev_priv = to_i915(dev);
4869 int pipe = intel_crtc->pipe;
4873 /* Switch from PCDclk to Rawclk */
4874 reg = FDI_RX_CTL(pipe);
4875 temp = I915_READ(reg);
4876 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4878 /* Disable CPU FDI TX PLL */
4879 reg = FDI_TX_CTL(pipe);
4880 temp = I915_READ(reg);
4881 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4886 reg = FDI_RX_CTL(pipe);
4887 temp = I915_READ(reg);
4888 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4890 /* Wait for the clocks to turn off. */
4895 static void ironlake_fdi_disable(struct drm_crtc *crtc)
4897 struct drm_device *dev = crtc->dev;
4898 struct drm_i915_private *dev_priv = to_i915(dev);
4899 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4900 int pipe = intel_crtc->pipe;
4904 /* disable CPU FDI tx and PCH FDI rx */
4905 reg = FDI_TX_CTL(pipe);
4906 temp = I915_READ(reg);
4907 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4910 reg = FDI_RX_CTL(pipe);
4911 temp = I915_READ(reg);
4912 temp &= ~(0x7 << 16);
4913 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4914 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4919 /* Ironlake workaround, disable clock pointer after downing FDI */
4920 if (HAS_PCH_IBX(dev_priv))
4921 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4923 /* still set train pattern 1 */
4924 reg = FDI_TX_CTL(pipe);
4925 temp = I915_READ(reg);
4926 temp &= ~FDI_LINK_TRAIN_NONE;
4927 temp |= FDI_LINK_TRAIN_PATTERN_1;
4928 I915_WRITE(reg, temp);
4930 reg = FDI_RX_CTL(pipe);
4931 temp = I915_READ(reg);
4932 if (HAS_PCH_CPT(dev_priv)) {
4933 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4934 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4936 temp &= ~FDI_LINK_TRAIN_NONE;
4937 temp |= FDI_LINK_TRAIN_PATTERN_1;
4939 /* BPC in FDI rx is consistent with that in PIPECONF */
4940 temp &= ~(0x07 << 16);
4941 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4942 I915_WRITE(reg, temp);
4948 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
4950 struct drm_crtc *crtc;
4953 drm_for_each_crtc(crtc, &dev_priv->drm) {
4954 struct drm_crtc_commit *commit;
4955 spin_lock(&crtc->commit_lock);
4956 commit = list_first_entry_or_null(&crtc->commit_list,
4957 struct drm_crtc_commit, commit_entry);
4958 cleanup_done = commit ?
4959 try_wait_for_completion(&commit->cleanup_done) : true;
4960 spin_unlock(&crtc->commit_lock);
4965 drm_crtc_wait_one_vblank(crtc);
4973 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
4977 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4979 mutex_lock(&dev_priv->sb_lock);
4981 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4982 temp |= SBI_SSCCTL_DISABLE;
4983 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4985 mutex_unlock(&dev_priv->sb_lock);
4988 /* Program iCLKIP clock to the desired frequency */
4989 static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
4991 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4992 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4993 int clock = crtc_state->base.adjusted_mode.crtc_clock;
4994 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4997 lpt_disable_iclkip(dev_priv);
4999 /* The iCLK virtual clock root frequency is in MHz,
5000 * but the adjusted_mode->crtc_clock in in KHz. To get the
5001 * divisors, it is necessary to divide one by another, so we
5002 * convert the virtual clock precision to KHz here for higher
5005 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
5006 u32 iclk_virtual_root_freq = 172800 * 1000;
5007 u32 iclk_pi_range = 64;
5008 u32 desired_divisor;
5010 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5012 divsel = (desired_divisor / iclk_pi_range) - 2;
5013 phaseinc = desired_divisor % iclk_pi_range;
5016 * Near 20MHz is a corner case which is
5017 * out of range for the 7-bit divisor
5023 /* This should not happen with any sane values */
5024 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
5025 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
5026 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
5027 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
5029 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
5036 mutex_lock(&dev_priv->sb_lock);
5038 /* Program SSCDIVINTPHASE6 */
5039 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5040 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
5041 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
5042 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
5043 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
5044 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
5045 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
5046 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
5048 /* Program SSCAUXDIV */
5049 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5050 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
5051 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
5052 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
5054 /* Enable modulator and associated divider */
5055 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5056 temp &= ~SBI_SSCCTL_DISABLE;
5057 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
5059 mutex_unlock(&dev_priv->sb_lock);
5061 /* Wait for initialization time */
5064 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
5067 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
5069 u32 divsel, phaseinc, auxdiv;
5070 u32 iclk_virtual_root_freq = 172800 * 1000;
5071 u32 iclk_pi_range = 64;
5072 u32 desired_divisor;
5075 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
5078 mutex_lock(&dev_priv->sb_lock);
5080 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5081 if (temp & SBI_SSCCTL_DISABLE) {
5082 mutex_unlock(&dev_priv->sb_lock);
5086 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5087 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
5088 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
5089 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
5090 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
5092 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5093 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
5094 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
5096 mutex_unlock(&dev_priv->sb_lock);
5098 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
5100 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5101 desired_divisor << auxdiv);
5104 static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
5105 enum pipe pch_transcoder)
5107 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5108 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5109 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5111 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
5112 I915_READ(HTOTAL(cpu_transcoder)));
5113 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
5114 I915_READ(HBLANK(cpu_transcoder)));
5115 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
5116 I915_READ(HSYNC(cpu_transcoder)));
5118 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
5119 I915_READ(VTOTAL(cpu_transcoder)));
5120 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
5121 I915_READ(VBLANK(cpu_transcoder)));
5122 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
5123 I915_READ(VSYNC(cpu_transcoder)));
5124 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
5125 I915_READ(VSYNCSHIFT(cpu_transcoder)));
5128 static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
5132 temp = I915_READ(SOUTH_CHICKEN1);
5133 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
5136 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
5137 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
5139 temp &= ~FDI_BC_BIFURCATION_SELECT;
5141 temp |= FDI_BC_BIFURCATION_SELECT;
5143 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
5144 I915_WRITE(SOUTH_CHICKEN1, temp);
5145 POSTING_READ(SOUTH_CHICKEN1);
5148 static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
5150 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5151 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5153 switch (crtc->pipe) {
5157 if (crtc_state->fdi_lanes > 2)
5158 cpt_set_fdi_bc_bifurcation(dev_priv, false);
5160 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5164 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5173 * Finds the encoder associated with the given CRTC. This can only be
5174 * used when we know that the CRTC isn't feeding multiple encoders!
5176 static struct intel_encoder *
5177 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
5178 const struct intel_crtc_state *crtc_state)
5180 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5181 const struct drm_connector_state *connector_state;
5182 const struct drm_connector *connector;
5183 struct intel_encoder *encoder = NULL;
5184 int num_encoders = 0;
5187 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
5188 if (connector_state->crtc != &crtc->base)
5191 encoder = to_intel_encoder(connector_state->best_encoder);
5195 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
5196 num_encoders, pipe_name(crtc->pipe));
5202 * Enable PCH resources required for PCH ports:
5204 * - FDI training & RX/TX
5205 * - update transcoder timings
5206 * - DP transcoding bits
5209 static void ironlake_pch_enable(const struct intel_atomic_state *state,
5210 const struct intel_crtc_state *crtc_state)
5212 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5213 struct drm_device *dev = crtc->base.dev;
5214 struct drm_i915_private *dev_priv = to_i915(dev);
5215 int pipe = crtc->pipe;
5218 assert_pch_transcoder_disabled(dev_priv, pipe);
5220 if (IS_IVYBRIDGE(dev_priv))
5221 ivybridge_update_fdi_bc_bifurcation(crtc_state);
5223 /* Write the TU size bits before fdi link training, so that error
5224 * detection works. */
5225 I915_WRITE(FDI_RX_TUSIZE1(pipe),
5226 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
5228 /* For PCH output, training FDI link */
5229 dev_priv->display.fdi_link_train(crtc, crtc_state);
5231 /* We need to program the right clock selection before writing the pixel
5232 * mutliplier into the DPLL. */
5233 if (HAS_PCH_CPT(dev_priv)) {
5236 temp = I915_READ(PCH_DPLL_SEL);
5237 temp |= TRANS_DPLL_ENABLE(pipe);
5238 sel = TRANS_DPLLB_SEL(pipe);
5239 if (crtc_state->shared_dpll ==
5240 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
5244 I915_WRITE(PCH_DPLL_SEL, temp);
5247 /* XXX: pch pll's can be enabled any time before we enable the PCH
5248 * transcoder, and we actually should do this to not upset any PCH
5249 * transcoder that already use the clock when we share it.
5251 * Note that enable_shared_dpll tries to do the right thing, but
5252 * get_shared_dpll unconditionally resets the pll - we need that to have
5253 * the right LVDS enable sequence. */
5254 intel_enable_shared_dpll(crtc_state);
5256 /* set transcoder timing, panel must allow it */
5257 assert_panel_unlocked(dev_priv, pipe);
5258 ironlake_pch_transcoder_set_timings(crtc_state, pipe);
5260 intel_fdi_normal_train(crtc);
5262 /* For PCH DP, enable TRANS_DP_CTL */
5263 if (HAS_PCH_CPT(dev_priv) &&
5264 intel_crtc_has_dp_encoder(crtc_state)) {
5265 const struct drm_display_mode *adjusted_mode =
5266 &crtc_state->base.adjusted_mode;
5267 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
5268 i915_reg_t reg = TRANS_DP_CTL(pipe);
5271 temp = I915_READ(reg);
5272 temp &= ~(TRANS_DP_PORT_SEL_MASK |
5273 TRANS_DP_SYNC_MASK |
5275 temp |= TRANS_DP_OUTPUT_ENABLE;
5276 temp |= bpc << 9; /* same format but at 11:9 */
5278 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
5279 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
5280 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
5281 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
5283 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
5284 WARN_ON(port < PORT_B || port > PORT_D);
5285 temp |= TRANS_DP_PORT_SEL(port);
5287 I915_WRITE(reg, temp);
5290 ironlake_enable_pch_transcoder(crtc_state);
5293 static void lpt_pch_enable(const struct intel_atomic_state *state,
5294 const struct intel_crtc_state *crtc_state)
5296 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5297 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5298 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5300 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
5302 lpt_program_iclkip(crtc_state);
5304 /* Set transcoder timing. */
5305 ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A);
5307 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
5310 static void cpt_verify_modeset(struct drm_device *dev, int pipe)
5312 struct drm_i915_private *dev_priv = to_i915(dev);
5313 i915_reg_t dslreg = PIPEDSL(pipe);
5316 temp = I915_READ(dslreg);
5318 if (wait_for(I915_READ(dslreg) != temp, 5)) {
5319 if (wait_for(I915_READ(dslreg) != temp, 5))
5320 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
5325 * The hardware phase 0.0 refers to the center of the pixel.
5326 * We want to start from the top/left edge which is phase
5327 * -0.5. That matches how the hardware calculates the scaling
5328 * factors (from top-left of the first pixel to bottom-right
5329 * of the last pixel, as opposed to the pixel centers).
5331 * For 4:2:0 subsampled chroma planes we obviously have to
5332 * adjust that so that the chroma sample position lands in
5335 * Note that for packed YCbCr 4:2:2 formats there is no way to
5336 * control chroma siting. The hardware simply replicates the
5337 * chroma samples for both of the luma samples, and thus we don't
5338 * actually get the expected MPEG2 chroma siting convention :(
5339 * The same behaviour is observed on pre-SKL platforms as well.
5341 * Theory behind the formula (note that we ignore sub-pixel
5342 * source coordinates):
5343 * s = source sample position
5344 * d = destination sample position
5349 * | | 1.5 (initial phase)
5357 * | -0.375 (initial phase)
5364 u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
5366 int phase = -0x8000;
5370 phase += (sub - 1) * 0x8000 / sub;
5372 phase += scale / (2 * sub);
5375 * Hardware initial phase limited to [-0.5:1.5].
5376 * Since the max hardware scale factor is 3.0, we
5377 * should never actually excdeed 1.0 here.
5379 WARN_ON(phase < -0x8000 || phase > 0x18000);
5382 phase = 0x10000 + phase;
5384 trip = PS_PHASE_TRIP;
5386 return ((phase >> 2) & PS_PHASE_MASK) | trip;
5389 #define SKL_MIN_SRC_W 8
5390 #define SKL_MAX_SRC_W 4096
5391 #define SKL_MIN_SRC_H 8
5392 #define SKL_MAX_SRC_H 4096
5393 #define SKL_MIN_DST_W 8
5394 #define SKL_MAX_DST_W 4096
5395 #define SKL_MIN_DST_H 8
5396 #define SKL_MAX_DST_H 4096
5397 #define ICL_MAX_SRC_W 5120
5398 #define ICL_MAX_SRC_H 4096
5399 #define ICL_MAX_DST_W 5120
5400 #define ICL_MAX_DST_H 4096
5401 #define SKL_MIN_YUV_420_SRC_W 16
5402 #define SKL_MIN_YUV_420_SRC_H 16
5405 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
5406 unsigned int scaler_user, int *scaler_id,
5407 int src_w, int src_h, int dst_w, int dst_h,
5408 const struct drm_format_info *format, bool need_scaler)
5410 struct intel_crtc_scaler_state *scaler_state =
5411 &crtc_state->scaler_state;
5412 struct intel_crtc *intel_crtc =
5413 to_intel_crtc(crtc_state->base.crtc);
5414 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
5415 const struct drm_display_mode *adjusted_mode =
5416 &crtc_state->base.adjusted_mode;
5419 * Src coordinates are already rotated by 270 degrees for
5420 * the 90/270 degree plane rotation cases (to match the
5421 * GTT mapping), hence no need to account for rotation here.
5423 if (src_w != dst_w || src_h != dst_h)
5427 * Scaling/fitting not supported in IF-ID mode in GEN9+
5428 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
5429 * Once NV12 is enabled, handle it here while allocating scaler
5432 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
5433 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
5434 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
5439 * if plane is being disabled or scaler is no more required or force detach
5440 * - free scaler binded to this plane/crtc
5441 * - in order to do this, update crtc->scaler_usage
5443 * Here scaler state in crtc_state is set free so that
5444 * scaler can be assigned to other user. Actual register
5445 * update to free the scaler is done in plane/panel-fit programming.
5446 * For this purpose crtc/plane_state->scaler_id isn't reset here.
5448 if (force_detach || !need_scaler) {
5449 if (*scaler_id >= 0) {
5450 scaler_state->scaler_users &= ~(1 << scaler_user);
5451 scaler_state->scalers[*scaler_id].in_use = 0;
5453 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5454 "Staged freeing scaler id %d scaler_users = 0x%x\n",
5455 intel_crtc->pipe, scaler_user, *scaler_id,
5456 scaler_state->scaler_users);
5462 if (format && is_planar_yuv_format(format->format) &&
5463 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
5464 DRM_DEBUG_KMS("Planar YUV: src dimensions not met\n");
5469 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
5470 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
5471 (INTEL_GEN(dev_priv) >= 11 &&
5472 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
5473 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
5474 (INTEL_GEN(dev_priv) < 11 &&
5475 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
5476 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
5477 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
5478 "size is out of scaler range\n",
5479 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
5483 /* mark this plane as a scaler user in crtc_state */
5484 scaler_state->scaler_users |= (1 << scaler_user);
5485 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5486 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
5487 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
5488 scaler_state->scaler_users);
5494 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
5496 * @state: crtc's scaler state
5499 * 0 - scaler_usage updated successfully
5500 * error - requested scaling cannot be supported or other error condition
5502 int skl_update_scaler_crtc(struct intel_crtc_state *state)
5504 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
5505 bool need_scaler = false;
5507 if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
5510 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
5511 &state->scaler_state.scaler_id,
5512 state->pipe_src_w, state->pipe_src_h,
5513 adjusted_mode->crtc_hdisplay,
5514 adjusted_mode->crtc_vdisplay, NULL, need_scaler);
5518 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
5519 * @crtc_state: crtc's scaler state
5520 * @plane_state: atomic plane state to update
5523 * 0 - scaler_usage updated successfully
5524 * error - requested scaling cannot be supported or other error condition
5526 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
5527 struct intel_plane_state *plane_state)
5529 struct intel_plane *intel_plane =
5530 to_intel_plane(plane_state->base.plane);
5531 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
5532 struct drm_framebuffer *fb = plane_state->base.fb;
5534 bool force_detach = !fb || !plane_state->base.visible;
5535 bool need_scaler = false;
5537 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
5538 if (!icl_is_hdr_plane(dev_priv, intel_plane->id) &&
5539 fb && is_planar_yuv_format(fb->format->format))
5542 ret = skl_update_scaler(crtc_state, force_detach,
5543 drm_plane_index(&intel_plane->base),
5544 &plane_state->scaler_id,
5545 drm_rect_width(&plane_state->base.src) >> 16,
5546 drm_rect_height(&plane_state->base.src) >> 16,
5547 drm_rect_width(&plane_state->base.dst),
5548 drm_rect_height(&plane_state->base.dst),
5549 fb ? fb->format : NULL, need_scaler);
5551 if (ret || plane_state->scaler_id < 0)
5554 /* check colorkey */
5555 if (plane_state->ckey.flags) {
5556 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
5557 intel_plane->base.base.id,
5558 intel_plane->base.name);
5562 /* Check src format */
5563 switch (fb->format->format) {
5564 case DRM_FORMAT_RGB565:
5565 case DRM_FORMAT_XBGR8888:
5566 case DRM_FORMAT_XRGB8888:
5567 case DRM_FORMAT_ABGR8888:
5568 case DRM_FORMAT_ARGB8888:
5569 case DRM_FORMAT_XRGB2101010:
5570 case DRM_FORMAT_XBGR2101010:
5571 case DRM_FORMAT_XBGR16161616F:
5572 case DRM_FORMAT_ABGR16161616F:
5573 case DRM_FORMAT_XRGB16161616F:
5574 case DRM_FORMAT_ARGB16161616F:
5575 case DRM_FORMAT_YUYV:
5576 case DRM_FORMAT_YVYU:
5577 case DRM_FORMAT_UYVY:
5578 case DRM_FORMAT_VYUY:
5579 case DRM_FORMAT_NV12:
5580 case DRM_FORMAT_P010:
5581 case DRM_FORMAT_P012:
5582 case DRM_FORMAT_P016:
5583 case DRM_FORMAT_Y210:
5584 case DRM_FORMAT_Y212:
5585 case DRM_FORMAT_Y216:
5586 case DRM_FORMAT_XVYU2101010:
5587 case DRM_FORMAT_XVYU12_16161616:
5588 case DRM_FORMAT_XVYU16161616:
5591 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
5592 intel_plane->base.base.id, intel_plane->base.name,
5593 fb->base.id, fb->format->format);
5600 static void skylake_scaler_disable(struct intel_crtc *crtc)
5604 for (i = 0; i < crtc->num_scalers; i++)
5605 skl_detach_scaler(crtc, i);
5608 static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
5610 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5611 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5612 enum pipe pipe = crtc->pipe;
5613 const struct intel_crtc_scaler_state *scaler_state =
5614 &crtc_state->scaler_state;
5616 if (crtc_state->pch_pfit.enabled) {
5617 u16 uv_rgb_hphase, uv_rgb_vphase;
5618 int pfit_w, pfit_h, hscale, vscale;
5621 if (WARN_ON(crtc_state->scaler_state.scaler_id < 0))
5624 pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF;
5625 pfit_h = crtc_state->pch_pfit.size & 0xFFFF;
5627 hscale = (crtc_state->pipe_src_w << 16) / pfit_w;
5628 vscale = (crtc_state->pipe_src_h << 16) / pfit_h;
5630 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
5631 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
5633 id = scaler_state->scaler_id;
5634 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
5635 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
5636 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
5637 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5638 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
5639 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
5640 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos);
5641 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size);
5645 static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state)
5647 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5648 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5649 int pipe = crtc->pipe;
5651 if (crtc_state->pch_pfit.enabled) {
5652 /* Force use of hard-coded filter coefficients
5653 * as some pre-programmed values are broken,
5656 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
5657 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5658 PF_PIPE_SEL_IVB(pipe));
5660 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
5661 I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos);
5662 I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size);
5666 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
5668 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5669 struct drm_device *dev = crtc->base.dev;
5670 struct drm_i915_private *dev_priv = to_i915(dev);
5672 if (!crtc_state->ips_enabled)
5676 * We can only enable IPS after we enable a plane and wait for a vblank
5677 * This function is called from post_plane_update, which is run after
5680 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
5682 if (IS_BROADWELL(dev_priv)) {
5683 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5684 IPS_ENABLE | IPS_PCODE_CONTROL));
5685 /* Quoting Art Runyan: "its not safe to expect any particular
5686 * value in IPS_CTL bit 31 after enabling IPS through the
5687 * mailbox." Moreover, the mailbox may return a bogus state,
5688 * so we need to just enable it and continue on.
5691 I915_WRITE(IPS_CTL, IPS_ENABLE);
5692 /* The bit only becomes 1 in the next vblank, so this wait here
5693 * is essentially intel_wait_for_vblank. If we don't have this
5694 * and don't wait for vblanks until the end of crtc_enable, then
5695 * the HW state readout code will complain that the expected
5696 * IPS_CTL value is not the one we read. */
5697 if (intel_de_wait_for_set(dev_priv, IPS_CTL, IPS_ENABLE, 50))
5698 DRM_ERROR("Timed out waiting for IPS enable\n");
5702 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
5704 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5705 struct drm_device *dev = crtc->base.dev;
5706 struct drm_i915_private *dev_priv = to_i915(dev);
5708 if (!crtc_state->ips_enabled)
5711 if (IS_BROADWELL(dev_priv)) {
5712 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
5714 * Wait for PCODE to finish disabling IPS. The BSpec specified
5715 * 42ms timeout value leads to occasional timeouts so use 100ms
5718 if (intel_de_wait_for_clear(dev_priv, IPS_CTL, IPS_ENABLE, 100))
5719 DRM_ERROR("Timed out waiting for IPS disable\n");
5721 I915_WRITE(IPS_CTL, 0);
5722 POSTING_READ(IPS_CTL);
5725 /* We need to wait for a vblank before we can disable the plane. */
5726 intel_wait_for_vblank(dev_priv, crtc->pipe);
5729 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
5731 if (intel_crtc->overlay) {
5732 struct drm_device *dev = intel_crtc->base.dev;
5734 mutex_lock(&dev->struct_mutex);
5735 (void) intel_overlay_switch_off(intel_crtc->overlay);
5736 mutex_unlock(&dev->struct_mutex);
5739 /* Let userspace switch the overlay on again. In most cases userspace
5740 * has to recompute where to put it anyway.
5745 * intel_post_enable_primary - Perform operations after enabling primary plane
5746 * @crtc: the CRTC whose primary plane was just enabled
5747 * @new_crtc_state: the enabling state
5749 * Performs potentially sleeping operations that must be done after the primary
5750 * plane is enabled, such as updating FBC and IPS. Note that this may be
5751 * called due to an explicit primary plane update, or due to an implicit
5752 * re-enable that is caused when a sprite plane is updated to no longer
5753 * completely hide the primary plane.
5756 intel_post_enable_primary(struct drm_crtc *crtc,
5757 const struct intel_crtc_state *new_crtc_state)
5759 struct drm_device *dev = crtc->dev;
5760 struct drm_i915_private *dev_priv = to_i915(dev);
5761 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5762 int pipe = intel_crtc->pipe;
5765 * Gen2 reports pipe underruns whenever all planes are disabled.
5766 * So don't enable underrun reporting before at least some planes
5768 * FIXME: Need to fix the logic to work when we turn off all planes
5769 * but leave the pipe running.
5771 if (IS_GEN(dev_priv, 2))
5772 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5774 /* Underruns don't always raise interrupts, so check manually. */
5775 intel_check_cpu_fifo_underruns(dev_priv);
5776 intel_check_pch_fifo_underruns(dev_priv);
5779 /* FIXME get rid of this and use pre_plane_update */
5781 intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5783 struct drm_device *dev = crtc->dev;
5784 struct drm_i915_private *dev_priv = to_i915(dev);
5785 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5786 int pipe = intel_crtc->pipe;
5789 * Gen2 reports pipe underruns whenever all planes are disabled.
5790 * So disable underrun reporting before all the planes get disabled.
5792 if (IS_GEN(dev_priv, 2))
5793 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5795 hsw_disable_ips(to_intel_crtc_state(crtc->state));
5798 * Vblank time updates from the shadow to live plane control register
5799 * are blocked if the memory self-refresh mode is active at that
5800 * moment. So to make sure the plane gets truly disabled, disable
5801 * first the self-refresh mode. The self-refresh enable bit in turn
5802 * will be checked/applied by the HW only at the next frame start
5803 * event which is after the vblank start event, so we need to have a
5804 * wait-for-vblank between disabling the plane and the pipe.
5806 if (HAS_GMCH(dev_priv) &&
5807 intel_set_memory_cxsr(dev_priv, false))
5808 intel_wait_for_vblank(dev_priv, pipe);
5811 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5812 const struct intel_crtc_state *new_crtc_state)
5814 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
5815 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5817 if (!old_crtc_state->ips_enabled)
5820 if (needs_modeset(new_crtc_state))
5824 * Workaround : Do not read or write the pipe palette/gamma data while
5825 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
5827 * Disable IPS before we program the LUT.
5829 if (IS_HASWELL(dev_priv) &&
5830 (new_crtc_state->base.color_mgmt_changed ||
5831 new_crtc_state->update_pipe) &&
5832 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
5835 return !new_crtc_state->ips_enabled;
5838 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5839 const struct intel_crtc_state *new_crtc_state)
5841 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
5842 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5844 if (!new_crtc_state->ips_enabled)
5847 if (needs_modeset(new_crtc_state))
5851 * Workaround : Do not read or write the pipe palette/gamma data while
5852 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
5854 * Re-enable IPS after the LUT has been programmed.
5856 if (IS_HASWELL(dev_priv) &&
5857 (new_crtc_state->base.color_mgmt_changed ||
5858 new_crtc_state->update_pipe) &&
5859 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
5863 * We can't read out IPS on broadwell, assume the worst and
5864 * forcibly enable IPS on the first fastset.
5866 if (new_crtc_state->update_pipe &&
5867 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5870 return !old_crtc_state->ips_enabled;
5873 static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5874 const struct intel_crtc_state *crtc_state)
5876 if (!crtc_state->nv12_planes)
5879 /* WA Display #0827: Gen9:all */
5880 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv))
5886 static bool needs_scalerclk_wa(struct drm_i915_private *dev_priv,
5887 const struct intel_crtc_state *crtc_state)
5889 /* Wa_2006604312:icl */
5890 if (crtc_state->scaler_state.scaler_users > 0 && IS_ICELAKE(dev_priv))
5896 static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5898 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5899 struct drm_device *dev = crtc->base.dev;
5900 struct drm_i915_private *dev_priv = to_i915(dev);
5901 struct drm_atomic_state *state = old_crtc_state->base.state;
5902 struct intel_crtc_state *pipe_config =
5903 intel_atomic_get_new_crtc_state(to_intel_atomic_state(state),
5905 struct drm_plane *primary = crtc->base.primary;
5906 struct drm_plane_state *old_primary_state =
5907 drm_atomic_get_old_plane_state(state, primary);
5909 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
5911 if (pipe_config->update_wm_post && pipe_config->base.active)
5912 intel_update_watermarks(crtc);
5914 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5915 hsw_enable_ips(pipe_config);
5917 if (old_primary_state) {
5918 struct drm_plane_state *new_primary_state =
5919 drm_atomic_get_new_plane_state(state, primary);
5921 intel_fbc_post_update(crtc);
5923 if (new_primary_state->visible &&
5924 (needs_modeset(pipe_config) ||
5925 !old_primary_state->visible))
5926 intel_post_enable_primary(&crtc->base, pipe_config);
5929 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
5930 !needs_nv12_wa(dev_priv, pipe_config))
5931 skl_wa_827(dev_priv, crtc->pipe, false);
5933 if (needs_scalerclk_wa(dev_priv, old_crtc_state) &&
5934 !needs_scalerclk_wa(dev_priv, pipe_config))
5935 icl_wa_scalerclkgating(dev_priv, crtc->pipe, false);
5938 static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5939 struct intel_crtc_state *pipe_config)
5941 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5942 struct drm_device *dev = crtc->base.dev;
5943 struct drm_i915_private *dev_priv = to_i915(dev);
5944 struct drm_atomic_state *state = old_crtc_state->base.state;
5945 struct drm_plane *primary = crtc->base.primary;
5946 struct drm_plane_state *old_primary_state =
5947 drm_atomic_get_old_plane_state(state, primary);
5948 bool modeset = needs_modeset(pipe_config);
5949 struct intel_atomic_state *intel_state =
5950 to_intel_atomic_state(state);
5952 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5953 hsw_disable_ips(old_crtc_state);
5955 if (old_primary_state) {
5956 struct intel_plane_state *new_primary_state =
5957 intel_atomic_get_new_plane_state(intel_state,
5958 to_intel_plane(primary));
5960 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
5962 * Gen2 reports pipe underruns whenever all planes are disabled.
5963 * So disable underrun reporting before all the planes get disabled.
5965 if (IS_GEN(dev_priv, 2) && old_primary_state->visible &&
5966 (modeset || !new_primary_state->base.visible))
5967 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
5970 /* Display WA 827 */
5971 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
5972 needs_nv12_wa(dev_priv, pipe_config))
5973 skl_wa_827(dev_priv, crtc->pipe, true);
5975 /* Wa_2006604312:icl */
5976 if (!needs_scalerclk_wa(dev_priv, old_crtc_state) &&
5977 needs_scalerclk_wa(dev_priv, pipe_config))
5978 icl_wa_scalerclkgating(dev_priv, crtc->pipe, true);
5981 * Vblank time updates from the shadow to live plane control register
5982 * are blocked if the memory self-refresh mode is active at that
5983 * moment. So to make sure the plane gets truly disabled, disable
5984 * first the self-refresh mode. The self-refresh enable bit in turn
5985 * will be checked/applied by the HW only at the next frame start
5986 * event which is after the vblank start event, so we need to have a
5987 * wait-for-vblank between disabling the plane and the pipe.
5989 if (HAS_GMCH(dev_priv) && old_crtc_state->base.active &&
5990 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5991 intel_wait_for_vblank(dev_priv, crtc->pipe);
5994 * IVB workaround: must disable low power watermarks for at least
5995 * one frame before enabling scaling. LP watermarks can be re-enabled
5996 * when scaling is disabled.
5998 * WaCxSRDisabledForSpriteScaling:ivb
6000 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) &&
6001 old_crtc_state->base.active)
6002 intel_wait_for_vblank(dev_priv, crtc->pipe);
6005 * If we're doing a modeset, we're done. No need to do any pre-vblank
6006 * watermark programming here.
6008 if (needs_modeset(pipe_config))
6012 * For platforms that support atomic watermarks, program the
6013 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
6014 * will be the intermediate values that are safe for both pre- and
6015 * post- vblank; when vblank happens, the 'active' values will be set
6016 * to the final 'target' values and we'll do this again to get the
6017 * optimal watermarks. For gen9+ platforms, the values we program here
6018 * will be the final target values which will get automatically latched
6019 * at vblank time; no further programming will be necessary.
6021 * If a platform hasn't been transitioned to atomic watermarks yet,
6022 * we'll continue to update watermarks the old way, if flags tell
6025 if (dev_priv->display.initial_watermarks != NULL)
6026 dev_priv->display.initial_watermarks(intel_state,
6028 else if (pipe_config->update_wm_pre)
6029 intel_update_watermarks(crtc);
6032 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
6033 struct intel_crtc *crtc)
6035 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6036 const struct intel_crtc_state *new_crtc_state =
6037 intel_atomic_get_new_crtc_state(state, crtc);
6038 unsigned int update_mask = new_crtc_state->update_planes;
6039 const struct intel_plane_state *old_plane_state;
6040 struct intel_plane *plane;
6041 unsigned fb_bits = 0;
6044 intel_crtc_dpms_overlay_disable(crtc);
6046 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
6047 if (crtc->pipe != plane->pipe ||
6048 !(update_mask & BIT(plane->id)))
6051 intel_disable_plane(plane, new_crtc_state);
6053 if (old_plane_state->base.visible)
6054 fb_bits |= plane->frontbuffer_bit;
6057 intel_frontbuffer_flip(dev_priv, fb_bits);
6061 * intel_connector_primary_encoder - get the primary encoder for a connector
6062 * @connector: connector for which to return the encoder
6064 * Returns the primary encoder for a connector. There is a 1:1 mapping from
6065 * all connectors to their encoder, except for DP-MST connectors which have
6066 * both a virtual and a primary encoder. These DP-MST primary encoders can be
6067 * pointed to by as many DP-MST connectors as there are pipes.
6069 static struct intel_encoder *
6070 intel_connector_primary_encoder(struct intel_connector *connector)
6072 struct intel_encoder *encoder;
6074 if (connector->mst_port)
6075 return &dp_to_dig_port(connector->mst_port)->base;
6077 encoder = intel_attached_encoder(&connector->base);
6084 intel_connector_needs_modeset(struct intel_atomic_state *state,
6085 const struct drm_connector_state *old_conn_state,
6086 const struct drm_connector_state *new_conn_state)
6088 struct intel_crtc *old_crtc = old_conn_state->crtc ?
6089 to_intel_crtc(old_conn_state->crtc) : NULL;
6090 struct intel_crtc *new_crtc = new_conn_state->crtc ?
6091 to_intel_crtc(new_conn_state->crtc) : NULL;
6093 return new_crtc != old_crtc ||
6095 needs_modeset(intel_atomic_get_new_crtc_state(state, new_crtc)));
6098 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
6100 struct drm_connector_state *old_conn_state;
6101 struct drm_connector_state *new_conn_state;
6102 struct drm_connector *conn;
6105 for_each_oldnew_connector_in_state(&state->base, conn,
6106 old_conn_state, new_conn_state, i) {
6107 struct intel_encoder *encoder;
6108 struct intel_crtc *crtc;
6110 if (!intel_connector_needs_modeset(state,
6115 encoder = intel_connector_primary_encoder(to_intel_connector(conn));
6116 if (!encoder->update_prepare)
6119 crtc = new_conn_state->crtc ?
6120 to_intel_crtc(new_conn_state->crtc) : NULL;
6121 encoder->update_prepare(state, encoder, crtc);
6125 static void intel_encoders_update_complete(struct intel_atomic_state *state)
6127 struct drm_connector_state *old_conn_state;
6128 struct drm_connector_state *new_conn_state;
6129 struct drm_connector *conn;
6132 for_each_oldnew_connector_in_state(&state->base, conn,
6133 old_conn_state, new_conn_state, i) {
6134 struct intel_encoder *encoder;
6135 struct intel_crtc *crtc;
6137 if (!intel_connector_needs_modeset(state,
6142 encoder = intel_connector_primary_encoder(to_intel_connector(conn));
6143 if (!encoder->update_complete)
6146 crtc = new_conn_state->crtc ?
6147 to_intel_crtc(new_conn_state->crtc) : NULL;
6148 encoder->update_complete(state, encoder, crtc);
6152 static void intel_encoders_pre_pll_enable(struct intel_crtc *crtc,
6153 struct intel_crtc_state *crtc_state,
6154 struct intel_atomic_state *state)
6156 struct drm_connector_state *conn_state;
6157 struct drm_connector *conn;
6160 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6161 struct intel_encoder *encoder =
6162 to_intel_encoder(conn_state->best_encoder);
6164 if (conn_state->crtc != &crtc->base)
6167 if (encoder->pre_pll_enable)
6168 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
6172 static void intel_encoders_pre_enable(struct intel_crtc *crtc,
6173 struct intel_crtc_state *crtc_state,
6174 struct intel_atomic_state *state)
6176 struct drm_connector_state *conn_state;
6177 struct drm_connector *conn;
6180 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6181 struct intel_encoder *encoder =
6182 to_intel_encoder(conn_state->best_encoder);
6184 if (conn_state->crtc != &crtc->base)
6187 if (encoder->pre_enable)
6188 encoder->pre_enable(encoder, crtc_state, conn_state);
6192 static void intel_encoders_enable(struct intel_crtc *crtc,
6193 struct intel_crtc_state *crtc_state,
6194 struct intel_atomic_state *state)
6196 struct drm_connector_state *conn_state;
6197 struct drm_connector *conn;
6200 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6201 struct intel_encoder *encoder =
6202 to_intel_encoder(conn_state->best_encoder);
6204 if (conn_state->crtc != &crtc->base)
6207 if (encoder->enable)
6208 encoder->enable(encoder, crtc_state, conn_state);
6209 intel_opregion_notify_encoder(encoder, true);
6213 static void intel_encoders_disable(struct intel_crtc *crtc,
6214 struct intel_crtc_state *old_crtc_state,
6215 struct intel_atomic_state *state)
6217 struct drm_connector_state *old_conn_state;
6218 struct drm_connector *conn;
6221 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6222 struct intel_encoder *encoder =
6223 to_intel_encoder(old_conn_state->best_encoder);
6225 if (old_conn_state->crtc != &crtc->base)
6228 intel_opregion_notify_encoder(encoder, false);
6229 if (encoder->disable)
6230 encoder->disable(encoder, old_crtc_state, old_conn_state);
6234 static void intel_encoders_post_disable(struct intel_crtc *crtc,
6235 struct intel_crtc_state *old_crtc_state,
6236 struct intel_atomic_state *state)
6238 struct drm_connector_state *old_conn_state;
6239 struct drm_connector *conn;
6242 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6243 struct intel_encoder *encoder =
6244 to_intel_encoder(old_conn_state->best_encoder);
6246 if (old_conn_state->crtc != &crtc->base)
6249 if (encoder->post_disable)
6250 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
6254 static void intel_encoders_post_pll_disable(struct intel_crtc *crtc,
6255 struct intel_crtc_state *old_crtc_state,
6256 struct intel_atomic_state *state)
6258 struct drm_connector_state *old_conn_state;
6259 struct drm_connector *conn;
6262 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6263 struct intel_encoder *encoder =
6264 to_intel_encoder(old_conn_state->best_encoder);
6266 if (old_conn_state->crtc != &crtc->base)
6269 if (encoder->post_pll_disable)
6270 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
6274 static void intel_encoders_update_pipe(struct intel_crtc *crtc,
6275 struct intel_crtc_state *crtc_state,
6276 struct intel_atomic_state *state)
6278 struct drm_connector_state *conn_state;
6279 struct drm_connector *conn;
6282 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6283 struct intel_encoder *encoder =
6284 to_intel_encoder(conn_state->best_encoder);
6286 if (conn_state->crtc != &crtc->base)
6289 if (encoder->update_pipe)
6290 encoder->update_pipe(encoder, crtc_state, conn_state);
6294 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
6296 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6297 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
6299 plane->disable_plane(plane, crtc_state);
6302 static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
6303 struct intel_atomic_state *state)
6305 struct drm_crtc *crtc = pipe_config->base.crtc;
6306 struct drm_device *dev = crtc->dev;
6307 struct drm_i915_private *dev_priv = to_i915(dev);
6308 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6309 int pipe = intel_crtc->pipe;
6311 if (WARN_ON(intel_crtc->active))
6315 * Sometimes spurious CPU pipe underruns happen during FDI
6316 * training, at least with VGA+HDMI cloning. Suppress them.
6318 * On ILK we get an occasional spurious CPU pipe underruns
6319 * between eDP port A enable and vdd enable. Also PCH port
6320 * enable seems to result in the occasional CPU pipe underrun.
6322 * Spurious PCH underruns also occur during PCH enabling.
6324 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6325 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6327 if (pipe_config->has_pch_encoder)
6328 intel_prepare_shared_dpll(pipe_config);
6330 if (intel_crtc_has_dp_encoder(pipe_config))
6331 intel_dp_set_m_n(pipe_config, M1_N1);
6333 intel_set_pipe_timings(pipe_config);
6334 intel_set_pipe_src_size(pipe_config);
6336 if (pipe_config->has_pch_encoder) {
6337 intel_cpu_transcoder_set_m_n(pipe_config,
6338 &pipe_config->fdi_m_n, NULL);
6341 ironlake_set_pipeconf(pipe_config);
6343 intel_crtc->active = true;
6345 intel_encoders_pre_enable(intel_crtc, pipe_config, state);
6347 if (pipe_config->has_pch_encoder) {
6348 /* Note: FDI PLL enabling _must_ be done before we enable the
6349 * cpu pipes, hence this is separate from all the other fdi/pch
6351 ironlake_fdi_pll_enable(pipe_config);
6353 assert_fdi_tx_disabled(dev_priv, pipe);
6354 assert_fdi_rx_disabled(dev_priv, pipe);
6357 ironlake_pfit_enable(pipe_config);
6360 * On ILK+ LUT must be loaded before the pipe is running but with
6363 intel_color_load_luts(pipe_config);
6364 intel_color_commit(pipe_config);
6365 /* update DSPCNTR to configure gamma for pipe bottom color */
6366 intel_disable_primary_plane(pipe_config);
6368 if (dev_priv->display.initial_watermarks != NULL)
6369 dev_priv->display.initial_watermarks(state, pipe_config);
6370 intel_enable_pipe(pipe_config);
6372 if (pipe_config->has_pch_encoder)
6373 ironlake_pch_enable(state, pipe_config);
6375 assert_vblank_disabled(crtc);
6376 intel_crtc_vblank_on(pipe_config);
6378 intel_encoders_enable(intel_crtc, pipe_config, state);
6380 if (HAS_PCH_CPT(dev_priv))
6381 cpt_verify_modeset(dev, intel_crtc->pipe);
6384 * Must wait for vblank to avoid spurious PCH FIFO underruns.
6385 * And a second vblank wait is needed at least on ILK with
6386 * some interlaced HDMI modes. Let's do the double wait always
6387 * in case there are more corner cases we don't know about.
6389 if (pipe_config->has_pch_encoder) {
6390 intel_wait_for_vblank(dev_priv, pipe);
6391 intel_wait_for_vblank(dev_priv, pipe);
6393 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6394 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6397 /* IPS only exists on ULT machines and is tied to pipe A. */
6398 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
6400 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
6403 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
6404 enum pipe pipe, bool apply)
6406 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
6407 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
6414 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
6417 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
6419 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6420 enum pipe pipe = crtc->pipe;
6423 val = MBUS_DBOX_A_CREDIT(2);
6425 if (INTEL_GEN(dev_priv) >= 12) {
6426 val |= MBUS_DBOX_BW_CREDIT(2);
6427 val |= MBUS_DBOX_B_CREDIT(12);
6429 val |= MBUS_DBOX_BW_CREDIT(1);
6430 val |= MBUS_DBOX_B_CREDIT(8);
6433 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
6436 static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
6437 struct intel_atomic_state *state)
6439 struct drm_crtc *crtc = pipe_config->base.crtc;
6440 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6441 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6442 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
6443 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
6444 bool psl_clkgate_wa;
6446 if (WARN_ON(intel_crtc->active))
6449 intel_encoders_pre_pll_enable(intel_crtc, pipe_config, state);
6451 if (pipe_config->shared_dpll)
6452 intel_enable_shared_dpll(pipe_config);
6454 intel_encoders_pre_enable(intel_crtc, pipe_config, state);
6456 if (intel_crtc_has_dp_encoder(pipe_config))
6457 intel_dp_set_m_n(pipe_config, M1_N1);
6459 if (!transcoder_is_dsi(cpu_transcoder))
6460 intel_set_pipe_timings(pipe_config);
6462 intel_set_pipe_src_size(pipe_config);
6464 if (cpu_transcoder != TRANSCODER_EDP &&
6465 !transcoder_is_dsi(cpu_transcoder)) {
6466 I915_WRITE(PIPE_MULT(cpu_transcoder),
6467 pipe_config->pixel_multiplier - 1);
6470 if (pipe_config->has_pch_encoder) {
6471 intel_cpu_transcoder_set_m_n(pipe_config,
6472 &pipe_config->fdi_m_n, NULL);
6475 if (!transcoder_is_dsi(cpu_transcoder))
6476 haswell_set_pipeconf(pipe_config);
6478 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
6479 bdw_set_pipemisc(pipe_config);
6481 intel_crtc->active = true;
6483 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
6484 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
6485 pipe_config->pch_pfit.enabled;
6487 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
6489 if (INTEL_GEN(dev_priv) >= 9)
6490 skylake_pfit_enable(pipe_config);
6492 ironlake_pfit_enable(pipe_config);
6495 * On ILK+ LUT must be loaded before the pipe is running but with
6498 intel_color_load_luts(pipe_config);
6499 intel_color_commit(pipe_config);
6500 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
6501 if (INTEL_GEN(dev_priv) < 9)
6502 intel_disable_primary_plane(pipe_config);
6504 if (INTEL_GEN(dev_priv) >= 11)
6505 icl_set_pipe_chicken(intel_crtc);
6507 intel_ddi_set_pipe_settings(pipe_config);
6508 if (!transcoder_is_dsi(cpu_transcoder))
6509 intel_ddi_enable_transcoder_func(pipe_config);
6511 if (dev_priv->display.initial_watermarks != NULL)
6512 dev_priv->display.initial_watermarks(state, pipe_config);
6514 if (INTEL_GEN(dev_priv) >= 11)
6515 icl_pipe_mbus_enable(intel_crtc);
6517 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
6518 if (!transcoder_is_dsi(cpu_transcoder))
6519 intel_enable_pipe(pipe_config);
6521 if (pipe_config->has_pch_encoder)
6522 lpt_pch_enable(state, pipe_config);
6524 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST))
6525 intel_ddi_set_vc_payload_alloc(pipe_config, true);
6527 assert_vblank_disabled(crtc);
6528 intel_crtc_vblank_on(pipe_config);
6530 intel_encoders_enable(intel_crtc, pipe_config, state);
6532 if (psl_clkgate_wa) {
6533 intel_wait_for_vblank(dev_priv, pipe);
6534 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
6537 /* If we change the relative order between pipe/planes enabling, we need
6538 * to change the workaround. */
6539 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
6540 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
6541 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6542 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6546 static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6548 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6549 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6550 enum pipe pipe = crtc->pipe;
6552 /* To avoid upsetting the power well on haswell only disable the pfit if
6553 * it's in use. The hw state code will make sure we get this right. */
6554 if (old_crtc_state->pch_pfit.enabled) {
6555 I915_WRITE(PF_CTL(pipe), 0);
6556 I915_WRITE(PF_WIN_POS(pipe), 0);
6557 I915_WRITE(PF_WIN_SZ(pipe), 0);
6561 static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
6562 struct intel_atomic_state *state)
6564 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6565 struct drm_device *dev = crtc->dev;
6566 struct drm_i915_private *dev_priv = to_i915(dev);
6567 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6568 int pipe = intel_crtc->pipe;
6571 * Sometimes spurious CPU pipe underruns happen when the
6572 * pipe is already disabled, but FDI RX/TX is still enabled.
6573 * Happens at least with VGA+HDMI cloning. Suppress them.
6575 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6576 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6578 intel_encoders_disable(intel_crtc, old_crtc_state, state);
6580 drm_crtc_vblank_off(crtc);
6581 assert_vblank_disabled(crtc);
6583 intel_disable_pipe(old_crtc_state);
6585 ironlake_pfit_disable(old_crtc_state);
6587 if (old_crtc_state->has_pch_encoder)
6588 ironlake_fdi_disable(crtc);
6590 intel_encoders_post_disable(intel_crtc, old_crtc_state, state);
6592 if (old_crtc_state->has_pch_encoder) {
6593 ironlake_disable_pch_transcoder(dev_priv, pipe);
6595 if (HAS_PCH_CPT(dev_priv)) {
6599 /* disable TRANS_DP_CTL */
6600 reg = TRANS_DP_CTL(pipe);
6601 temp = I915_READ(reg);
6602 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
6603 TRANS_DP_PORT_SEL_MASK);
6604 temp |= TRANS_DP_PORT_SEL_NONE;
6605 I915_WRITE(reg, temp);
6607 /* disable DPLL_SEL */
6608 temp = I915_READ(PCH_DPLL_SEL);
6609 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
6610 I915_WRITE(PCH_DPLL_SEL, temp);
6613 ironlake_fdi_pll_disable(intel_crtc);
6616 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6617 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6620 static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
6621 struct intel_atomic_state *state)
6623 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6624 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6625 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6626 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
6628 intel_encoders_disable(intel_crtc, old_crtc_state, state);
6630 drm_crtc_vblank_off(crtc);
6631 assert_vblank_disabled(crtc);
6633 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
6634 if (!transcoder_is_dsi(cpu_transcoder))
6635 intel_disable_pipe(old_crtc_state);
6637 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
6638 intel_ddi_set_vc_payload_alloc(old_crtc_state, false);
6640 if (!transcoder_is_dsi(cpu_transcoder))
6641 intel_ddi_disable_transcoder_func(old_crtc_state);
6643 intel_dsc_disable(old_crtc_state);
6645 if (INTEL_GEN(dev_priv) >= 9)
6646 skylake_scaler_disable(intel_crtc);
6648 ironlake_pfit_disable(old_crtc_state);
6650 intel_encoders_post_disable(intel_crtc, old_crtc_state, state);
6652 intel_encoders_post_pll_disable(intel_crtc, old_crtc_state, state);
6655 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
6657 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6658 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6660 if (!crtc_state->gmch_pfit.control)
6664 * The panel fitter should only be adjusted whilst the pipe is disabled,
6665 * according to register description and PRM.
6667 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
6668 assert_pipe_disabled(dev_priv, crtc->pipe);
6670 I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
6671 I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
6673 /* Border color in case we don't scale up to the full screen. Black by
6674 * default, change to something else for debugging. */
6675 I915_WRITE(BCLRPAT(crtc->pipe), 0);
6678 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
6680 if (phy == PHY_NONE)
6683 if (IS_ELKHARTLAKE(dev_priv))
6684 return phy <= PHY_C;
6686 if (INTEL_GEN(dev_priv) >= 11)
6687 return phy <= PHY_B;
6692 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
6694 if (INTEL_GEN(dev_priv) >= 12)
6695 return phy >= PHY_D && phy <= PHY_I;
6697 if (INTEL_GEN(dev_priv) >= 11 && !IS_ELKHARTLAKE(dev_priv))
6698 return phy >= PHY_C && phy <= PHY_F;
6703 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
6705 if (IS_ELKHARTLAKE(i915) && port == PORT_D)
6708 return (enum phy)port;
6711 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
6713 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
6714 return PORT_TC_NONE;
6716 if (INTEL_GEN(dev_priv) >= 12)
6717 return port - PORT_D;
6719 return port - PORT_C;
6722 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
6726 return POWER_DOMAIN_PORT_DDI_A_LANES;
6728 return POWER_DOMAIN_PORT_DDI_B_LANES;
6730 return POWER_DOMAIN_PORT_DDI_C_LANES;
6732 return POWER_DOMAIN_PORT_DDI_D_LANES;
6734 return POWER_DOMAIN_PORT_DDI_E_LANES;
6736 return POWER_DOMAIN_PORT_DDI_F_LANES;
6739 return POWER_DOMAIN_PORT_OTHER;
6743 enum intel_display_power_domain
6744 intel_aux_power_domain(struct intel_digital_port *dig_port)
6746 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
6747 enum phy phy = intel_port_to_phy(dev_priv, dig_port->base.port);
6749 if (intel_phy_is_tc(dev_priv, phy) &&
6750 dig_port->tc_mode == TC_PORT_TBT_ALT) {
6751 switch (dig_port->aux_ch) {
6753 return POWER_DOMAIN_AUX_TBT1;
6755 return POWER_DOMAIN_AUX_TBT2;
6757 return POWER_DOMAIN_AUX_TBT3;
6759 return POWER_DOMAIN_AUX_TBT4;
6761 MISSING_CASE(dig_port->aux_ch);
6762 return POWER_DOMAIN_AUX_TBT1;
6766 switch (dig_port->aux_ch) {
6768 return POWER_DOMAIN_AUX_A;
6770 return POWER_DOMAIN_AUX_B;
6772 return POWER_DOMAIN_AUX_C;
6774 return POWER_DOMAIN_AUX_D;
6776 return POWER_DOMAIN_AUX_E;
6778 return POWER_DOMAIN_AUX_F;
6780 MISSING_CASE(dig_port->aux_ch);
6781 return POWER_DOMAIN_AUX_A;
6785 static u64 get_crtc_power_domains(struct intel_crtc_state *crtc_state)
6787 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6788 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6789 struct drm_encoder *encoder;
6790 enum pipe pipe = crtc->pipe;
6792 enum transcoder transcoder = crtc_state->cpu_transcoder;
6794 if (!crtc_state->base.active)
6797 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
6798 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
6799 if (crtc_state->pch_pfit.enabled ||
6800 crtc_state->pch_pfit.force_thru)
6801 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
6803 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
6804 crtc_state->base.encoder_mask) {
6805 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6807 mask |= BIT_ULL(intel_encoder->power_domain);
6810 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
6811 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
6813 if (crtc_state->shared_dpll)
6814 mask |= BIT_ULL(POWER_DOMAIN_DISPLAY_CORE);
6820 modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state)
6822 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6823 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6824 enum intel_display_power_domain domain;
6825 u64 domains, new_domains, old_domains;
6827 old_domains = crtc->enabled_power_domains;
6828 crtc->enabled_power_domains = new_domains =
6829 get_crtc_power_domains(crtc_state);
6831 domains = new_domains & ~old_domains;
6833 for_each_power_domain(domain, domains)
6834 intel_display_power_get(dev_priv, domain);
6836 return old_domains & ~new_domains;
6839 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
6842 enum intel_display_power_domain domain;
6844 for_each_power_domain(domain, domains)
6845 intel_display_power_put_unchecked(dev_priv, domain);
6848 static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
6849 struct intel_atomic_state *state)
6851 struct drm_crtc *crtc = pipe_config->base.crtc;
6852 struct drm_device *dev = crtc->dev;
6853 struct drm_i915_private *dev_priv = to_i915(dev);
6854 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6855 int pipe = intel_crtc->pipe;
6857 if (WARN_ON(intel_crtc->active))
6860 if (intel_crtc_has_dp_encoder(pipe_config))
6861 intel_dp_set_m_n(pipe_config, M1_N1);
6863 intel_set_pipe_timings(pipe_config);
6864 intel_set_pipe_src_size(pipe_config);
6866 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
6867 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6868 I915_WRITE(CHV_CANVAS(pipe), 0);
6871 i9xx_set_pipeconf(pipe_config);
6873 intel_crtc->active = true;
6875 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6877 intel_encoders_pre_pll_enable(intel_crtc, pipe_config, state);
6879 if (IS_CHERRYVIEW(dev_priv)) {
6880 chv_prepare_pll(intel_crtc, pipe_config);
6881 chv_enable_pll(intel_crtc, pipe_config);
6883 vlv_prepare_pll(intel_crtc, pipe_config);
6884 vlv_enable_pll(intel_crtc, pipe_config);
6887 intel_encoders_pre_enable(intel_crtc, pipe_config, state);
6889 i9xx_pfit_enable(pipe_config);
6891 intel_color_load_luts(pipe_config);
6892 intel_color_commit(pipe_config);
6893 /* update DSPCNTR to configure gamma for pipe bottom color */
6894 intel_disable_primary_plane(pipe_config);
6896 dev_priv->display.initial_watermarks(state, pipe_config);
6897 intel_enable_pipe(pipe_config);
6899 assert_vblank_disabled(crtc);
6900 intel_crtc_vblank_on(pipe_config);
6902 intel_encoders_enable(intel_crtc, pipe_config, state);
6905 static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
6907 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6908 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6910 I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0);
6911 I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1);
6914 static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
6915 struct intel_atomic_state *state)
6917 struct drm_crtc *crtc = pipe_config->base.crtc;
6918 struct drm_device *dev = crtc->dev;
6919 struct drm_i915_private *dev_priv = to_i915(dev);
6920 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6921 enum pipe pipe = intel_crtc->pipe;
6923 if (WARN_ON(intel_crtc->active))
6926 i9xx_set_pll_dividers(pipe_config);
6928 if (intel_crtc_has_dp_encoder(pipe_config))
6929 intel_dp_set_m_n(pipe_config, M1_N1);
6931 intel_set_pipe_timings(pipe_config);
6932 intel_set_pipe_src_size(pipe_config);
6934 i9xx_set_pipeconf(pipe_config);
6936 intel_crtc->active = true;
6938 if (!IS_GEN(dev_priv, 2))
6939 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6941 intel_encoders_pre_enable(intel_crtc, pipe_config, state);
6943 i9xx_enable_pll(intel_crtc, pipe_config);
6945 i9xx_pfit_enable(pipe_config);
6947 intel_color_load_luts(pipe_config);
6948 intel_color_commit(pipe_config);
6949 /* update DSPCNTR to configure gamma for pipe bottom color */
6950 intel_disable_primary_plane(pipe_config);
6952 if (dev_priv->display.initial_watermarks != NULL)
6953 dev_priv->display.initial_watermarks(state,
6956 intel_update_watermarks(intel_crtc);
6957 intel_enable_pipe(pipe_config);
6959 assert_vblank_disabled(crtc);
6960 intel_crtc_vblank_on(pipe_config);
6962 intel_encoders_enable(intel_crtc, pipe_config, state);
6965 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6967 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6968 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6970 if (!old_crtc_state->gmch_pfit.control)
6973 assert_pipe_disabled(dev_priv, crtc->pipe);
6975 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
6976 I915_READ(PFIT_CONTROL));
6977 I915_WRITE(PFIT_CONTROL, 0);
6980 static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6981 struct intel_atomic_state *state)
6983 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6984 struct drm_device *dev = crtc->dev;
6985 struct drm_i915_private *dev_priv = to_i915(dev);
6986 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6987 int pipe = intel_crtc->pipe;
6990 * On gen2 planes are double buffered but the pipe isn't, so we must
6991 * wait for planes to fully turn off before disabling the pipe.
6993 if (IS_GEN(dev_priv, 2))
6994 intel_wait_for_vblank(dev_priv, pipe);
6996 intel_encoders_disable(intel_crtc, old_crtc_state, state);
6998 drm_crtc_vblank_off(crtc);
6999 assert_vblank_disabled(crtc);
7001 intel_disable_pipe(old_crtc_state);
7003 i9xx_pfit_disable(old_crtc_state);
7005 intel_encoders_post_disable(intel_crtc, old_crtc_state, state);
7007 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
7008 if (IS_CHERRYVIEW(dev_priv))
7009 chv_disable_pll(dev_priv, pipe);
7010 else if (IS_VALLEYVIEW(dev_priv))
7011 vlv_disable_pll(dev_priv, pipe);
7013 i9xx_disable_pll(old_crtc_state);
7016 intel_encoders_post_pll_disable(intel_crtc, old_crtc_state, state);
7018 if (!IS_GEN(dev_priv, 2))
7019 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
7021 if (!dev_priv->display.initial_watermarks)
7022 intel_update_watermarks(intel_crtc);
7024 /* clock the pipe down to 640x480@60 to potentially save power */
7025 if (IS_I830(dev_priv))
7026 i830_enable_pipe(dev_priv, pipe);
7029 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
7030 struct drm_modeset_acquire_ctx *ctx)
7032 struct intel_encoder *encoder;
7033 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7034 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
7035 struct intel_bw_state *bw_state =
7036 to_intel_bw_state(dev_priv->bw_obj.state);
7037 enum intel_display_power_domain domain;
7038 struct intel_plane *plane;
7040 struct drm_atomic_state *state;
7041 struct intel_crtc_state *crtc_state;
7044 if (!intel_crtc->active)
7047 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
7048 const struct intel_plane_state *plane_state =
7049 to_intel_plane_state(plane->base.state);
7051 if (plane_state->base.visible)
7052 intel_plane_disable_noatomic(intel_crtc, plane);
7055 state = drm_atomic_state_alloc(crtc->dev);
7057 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
7058 crtc->base.id, crtc->name);
7062 state->acquire_ctx = ctx;
7064 /* Everything's already locked, -EDEADLK can't happen. */
7065 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
7066 ret = drm_atomic_add_affected_connectors(state, crtc);
7068 WARN_ON(IS_ERR(crtc_state) || ret);
7070 dev_priv->display.crtc_disable(crtc_state, to_intel_atomic_state(state));
7072 drm_atomic_state_put(state);
7074 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
7075 crtc->base.id, crtc->name);
7077 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
7078 crtc->state->active = false;
7079 intel_crtc->active = false;
7080 crtc->enabled = false;
7081 crtc->state->connector_mask = 0;
7082 crtc->state->encoder_mask = 0;
7084 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
7085 encoder->base.crtc = NULL;
7087 intel_fbc_disable(intel_crtc);
7088 intel_update_watermarks(intel_crtc);
7089 intel_disable_shared_dpll(to_intel_crtc_state(crtc->state));
7091 domains = intel_crtc->enabled_power_domains;
7092 for_each_power_domain(domain, domains)
7093 intel_display_power_put_unchecked(dev_priv, domain);
7094 intel_crtc->enabled_power_domains = 0;
7096 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
7097 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
7098 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
7100 bw_state->data_rate[intel_crtc->pipe] = 0;
7101 bw_state->num_active_planes[intel_crtc->pipe] = 0;
7105 * turn all crtc's off, but do not adjust state
7106 * This has to be paired with a call to intel_modeset_setup_hw_state.
7108 int intel_display_suspend(struct drm_device *dev)
7110 struct drm_i915_private *dev_priv = to_i915(dev);
7111 struct drm_atomic_state *state;
7114 state = drm_atomic_helper_suspend(dev);
7115 ret = PTR_ERR_OR_ZERO(state);
7117 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
7119 dev_priv->modeset_restore_state = state;
7123 void intel_encoder_destroy(struct drm_encoder *encoder)
7125 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
7127 drm_encoder_cleanup(encoder);
7128 kfree(intel_encoder);
7131 /* Cross check the actual hw state with our own modeset state tracking (and it's
7132 * internal consistency). */
7133 static void intel_connector_verify_state(struct intel_crtc_state *crtc_state,
7134 struct drm_connector_state *conn_state)
7136 struct intel_connector *connector = to_intel_connector(conn_state->connector);
7138 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
7139 connector->base.base.id,
7140 connector->base.name);
7142 if (connector->get_hw_state(connector)) {
7143 struct intel_encoder *encoder = connector->encoder;
7145 I915_STATE_WARN(!crtc_state,
7146 "connector enabled without attached crtc\n");
7151 I915_STATE_WARN(!crtc_state->base.active,
7152 "connector is active, but attached crtc isn't\n");
7154 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
7157 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
7158 "atomic encoder doesn't match attached encoder\n");
7160 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
7161 "attached encoder crtc differs from connector crtc\n");
7163 I915_STATE_WARN(crtc_state && crtc_state->base.active,
7164 "attached crtc is active, but connector isn't\n");
7165 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
7166 "best encoder set without crtc!\n");
7170 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
7172 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
7173 return crtc_state->fdi_lanes;
7178 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
7179 struct intel_crtc_state *pipe_config)
7181 struct drm_i915_private *dev_priv = to_i915(dev);
7182 struct drm_atomic_state *state = pipe_config->base.state;
7183 struct intel_crtc *other_crtc;
7184 struct intel_crtc_state *other_crtc_state;
7186 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
7187 pipe_name(pipe), pipe_config->fdi_lanes);
7188 if (pipe_config->fdi_lanes > 4) {
7189 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
7190 pipe_name(pipe), pipe_config->fdi_lanes);
7194 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7195 if (pipe_config->fdi_lanes > 2) {
7196 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
7197 pipe_config->fdi_lanes);
7204 if (INTEL_INFO(dev_priv)->num_pipes == 2)
7207 /* Ivybridge 3 pipe is really complicated */
7212 if (pipe_config->fdi_lanes <= 2)
7215 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
7217 intel_atomic_get_crtc_state(state, other_crtc);
7218 if (IS_ERR(other_crtc_state))
7219 return PTR_ERR(other_crtc_state);
7221 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
7222 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
7223 pipe_name(pipe), pipe_config->fdi_lanes);
7228 if (pipe_config->fdi_lanes > 2) {
7229 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
7230 pipe_name(pipe), pipe_config->fdi_lanes);
7234 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
7236 intel_atomic_get_crtc_state(state, other_crtc);
7237 if (IS_ERR(other_crtc_state))
7238 return PTR_ERR(other_crtc_state);
7240 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
7241 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
7251 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
7252 struct intel_crtc_state *pipe_config)
7254 struct drm_device *dev = intel_crtc->base.dev;
7255 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
7256 int lane, link_bw, fdi_dotclock, ret;
7257 bool needs_recompute = false;
7260 /* FDI is a binary signal running at ~2.7GHz, encoding
7261 * each output octet as 10 bits. The actual frequency
7262 * is stored as a divider into a 100MHz clock, and the
7263 * mode pixel clock is stored in units of 1KHz.
7264 * Hence the bw of each lane in terms of the mode signal
7267 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
7269 fdi_dotclock = adjusted_mode->crtc_clock;
7271 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
7272 pipe_config->pipe_bpp);
7274 pipe_config->fdi_lanes = lane;
7276 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
7277 link_bw, &pipe_config->fdi_m_n, false, false);
7279 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
7280 if (ret == -EDEADLK)
7283 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
7284 pipe_config->pipe_bpp -= 2*3;
7285 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
7286 pipe_config->pipe_bpp);
7287 needs_recompute = true;
7288 pipe_config->bw_constrained = true;
7293 if (needs_recompute)
7299 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
7301 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7302 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7304 /* IPS only exists on ULT machines and is tied to pipe A. */
7305 if (!hsw_crtc_supports_ips(crtc))
7308 if (!i915_modparams.enable_ips)
7311 if (crtc_state->pipe_bpp > 24)
7315 * We compare against max which means we must take
7316 * the increased cdclk requirement into account when
7317 * calculating the new cdclk.
7319 * Should measure whether using a lower cdclk w/o IPS
7321 if (IS_BROADWELL(dev_priv) &&
7322 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
7328 static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
7330 struct drm_i915_private *dev_priv =
7331 to_i915(crtc_state->base.crtc->dev);
7332 struct intel_atomic_state *intel_state =
7333 to_intel_atomic_state(crtc_state->base.state);
7335 if (!hsw_crtc_state_ips_capable(crtc_state))
7339 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
7340 * enabled and disabled dynamically based on package C states,
7341 * user space can't make reliable use of the CRCs, so let's just
7342 * completely disable it.
7344 if (crtc_state->crc_enabled)
7347 /* IPS should be fine as long as at least one plane is enabled. */
7348 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
7351 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
7352 if (IS_BROADWELL(dev_priv) &&
7353 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
7359 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
7361 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7363 /* GDG double wide on either pipe, otherwise pipe A only */
7364 return INTEL_GEN(dev_priv) < 4 &&
7365 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
7368 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
7372 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
7375 * We only use IF-ID interlacing. If we ever use
7376 * PF-ID we'll need to adjust the pixel_rate here.
7379 if (pipe_config->pch_pfit.enabled) {
7380 u64 pipe_w, pipe_h, pfit_w, pfit_h;
7381 u32 pfit_size = pipe_config->pch_pfit.size;
7383 pipe_w = pipe_config->pipe_src_w;
7384 pipe_h = pipe_config->pipe_src_h;
7386 pfit_w = (pfit_size >> 16) & 0xFFFF;
7387 pfit_h = pfit_size & 0xFFFF;
7388 if (pipe_w < pfit_w)
7390 if (pipe_h < pfit_h)
7393 if (WARN_ON(!pfit_w || !pfit_h))
7396 pixel_rate = div_u64(mul_u32_u32(pixel_rate, pipe_w * pipe_h),
7403 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
7405 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
7407 if (HAS_GMCH(dev_priv))
7408 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
7409 crtc_state->pixel_rate =
7410 crtc_state->base.adjusted_mode.crtc_clock;
7412 crtc_state->pixel_rate =
7413 ilk_pipe_pixel_rate(crtc_state);
7416 static int intel_crtc_compute_config(struct intel_crtc *crtc,
7417 struct intel_crtc_state *pipe_config)
7419 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7420 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
7421 int clock_limit = dev_priv->max_dotclk_freq;
7423 if (INTEL_GEN(dev_priv) < 4) {
7424 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
7427 * Enable double wide mode when the dot clock
7428 * is > 90% of the (display) core speed.
7430 if (intel_crtc_supports_double_wide(crtc) &&
7431 adjusted_mode->crtc_clock > clock_limit) {
7432 clock_limit = dev_priv->max_dotclk_freq;
7433 pipe_config->double_wide = true;
7437 if (adjusted_mode->crtc_clock > clock_limit) {
7438 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
7439 adjusted_mode->crtc_clock, clock_limit,
7440 yesno(pipe_config->double_wide));
7444 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
7445 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
7446 pipe_config->base.ctm) {
7448 * There is only one pipe CSC unit per pipe, and we need that
7449 * for output conversion from RGB->YCBCR. So if CTM is already
7450 * applied we can't support YCBCR420 output.
7452 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
7457 * Pipe horizontal size must be even in:
7459 * - LVDS dual channel mode
7460 * - Double wide pipe
7462 if (pipe_config->pipe_src_w & 1) {
7463 if (pipe_config->double_wide) {
7464 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
7468 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
7469 intel_is_dual_link_lvds(dev_priv)) {
7470 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
7475 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
7476 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
7478 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
7479 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
7482 intel_crtc_compute_pixel_rate(pipe_config);
7484 if (pipe_config->has_pch_encoder)
7485 return ironlake_fdi_compute_config(crtc, pipe_config);
7491 intel_reduce_m_n_ratio(u32 *num, u32 *den)
7493 while (*num > DATA_LINK_M_N_MASK ||
7494 *den > DATA_LINK_M_N_MASK) {
7500 static void compute_m_n(unsigned int m, unsigned int n,
7501 u32 *ret_m, u32 *ret_n,
7505 * Several DP dongles in particular seem to be fussy about
7506 * too large link M/N values. Give N value as 0x8000 that
7507 * should be acceptable by specific devices. 0x8000 is the
7508 * specified fixed N value for asynchronous clock mode,
7509 * which the devices expect also in synchronous clock mode.
7514 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
7516 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
7517 intel_reduce_m_n_ratio(ret_m, ret_n);
7521 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
7522 int pixel_clock, int link_clock,
7523 struct intel_link_m_n *m_n,
7524 bool constant_n, bool fec_enable)
7526 u32 data_clock = bits_per_pixel * pixel_clock;
7529 data_clock = intel_dp_mode_to_fec_clock(data_clock);
7532 compute_m_n(data_clock,
7533 link_clock * nlanes * 8,
7534 &m_n->gmch_m, &m_n->gmch_n,
7537 compute_m_n(pixel_clock, link_clock,
7538 &m_n->link_m, &m_n->link_n,
7542 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
7544 if (i915_modparams.panel_use_ssc >= 0)
7545 return i915_modparams.panel_use_ssc != 0;
7546 return dev_priv->vbt.lvds_use_ssc
7547 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
7550 static u32 pnv_dpll_compute_fp(struct dpll *dpll)
7552 return (1 << dpll->n) << 16 | dpll->m2;
7555 static u32 i9xx_dpll_compute_fp(struct dpll *dpll)
7557 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
7560 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
7561 struct intel_crtc_state *crtc_state,
7562 struct dpll *reduced_clock)
7564 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7567 if (IS_PINEVIEW(dev_priv)) {
7568 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
7570 fp2 = pnv_dpll_compute_fp(reduced_clock);
7572 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
7574 fp2 = i9xx_dpll_compute_fp(reduced_clock);
7577 crtc_state->dpll_hw_state.fp0 = fp;
7579 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7581 crtc_state->dpll_hw_state.fp1 = fp2;
7583 crtc_state->dpll_hw_state.fp1 = fp;
7587 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
7593 * PLLB opamp always calibrates to max value of 0x3f, force enable it
7594 * and set it to a reasonable value instead.
7596 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7597 reg_val &= 0xffffff00;
7598 reg_val |= 0x00000030;
7599 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7601 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7602 reg_val &= 0x00ffffff;
7603 reg_val |= 0x8c000000;
7604 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7606 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7607 reg_val &= 0xffffff00;
7608 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7610 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7611 reg_val &= 0x00ffffff;
7612 reg_val |= 0xb0000000;
7613 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7616 static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7617 const struct intel_link_m_n *m_n)
7619 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7620 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7621 enum pipe pipe = crtc->pipe;
7623 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7624 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
7625 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
7626 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
7629 static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
7630 enum transcoder transcoder)
7632 if (IS_HASWELL(dev_priv))
7633 return transcoder == TRANSCODER_EDP;
7636 * Strictly speaking some registers are available before
7637 * gen7, but we only support DRRS on gen7+
7639 return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv);
7642 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7643 const struct intel_link_m_n *m_n,
7644 const struct intel_link_m_n *m2_n2)
7646 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7647 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7648 enum pipe pipe = crtc->pipe;
7649 enum transcoder transcoder = crtc_state->cpu_transcoder;
7651 if (INTEL_GEN(dev_priv) >= 5) {
7652 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
7653 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
7654 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
7655 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
7657 * M2_N2 registers are set only if DRRS is supported
7658 * (to make sure the registers are not unnecessarily accessed).
7660 if (m2_n2 && crtc_state->has_drrs &&
7661 transcoder_has_m2_n2(dev_priv, transcoder)) {
7662 I915_WRITE(PIPE_DATA_M2(transcoder),
7663 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
7664 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
7665 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
7666 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
7669 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7670 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
7671 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
7672 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
7676 void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n)
7678 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
7681 dp_m_n = &crtc_state->dp_m_n;
7682 dp_m2_n2 = &crtc_state->dp_m2_n2;
7683 } else if (m_n == M2_N2) {
7686 * M2_N2 registers are not supported. Hence m2_n2 divider value
7687 * needs to be programmed into M1_N1.
7689 dp_m_n = &crtc_state->dp_m2_n2;
7691 DRM_ERROR("Unsupported divider value\n");
7695 if (crtc_state->has_pch_encoder)
7696 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
7698 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
7701 static void vlv_compute_dpll(struct intel_crtc *crtc,
7702 struct intel_crtc_state *pipe_config)
7704 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
7705 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
7706 if (crtc->pipe != PIPE_A)
7707 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7709 /* DPLL not used with DSI, but still need the rest set up */
7710 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
7711 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
7712 DPLL_EXT_BUFFER_ENABLE_VLV;
7714 pipe_config->dpll_hw_state.dpll_md =
7715 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7718 static void chv_compute_dpll(struct intel_crtc *crtc,
7719 struct intel_crtc_state *pipe_config)
7721 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
7722 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
7723 if (crtc->pipe != PIPE_A)
7724 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7726 /* DPLL not used with DSI, but still need the rest set up */
7727 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
7728 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
7730 pipe_config->dpll_hw_state.dpll_md =
7731 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7734 static void vlv_prepare_pll(struct intel_crtc *crtc,
7735 const struct intel_crtc_state *pipe_config)
7737 struct drm_device *dev = crtc->base.dev;
7738 struct drm_i915_private *dev_priv = to_i915(dev);
7739 enum pipe pipe = crtc->pipe;
7741 u32 bestn, bestm1, bestm2, bestp1, bestp2;
7742 u32 coreclk, reg_val;
7745 I915_WRITE(DPLL(pipe),
7746 pipe_config->dpll_hw_state.dpll &
7747 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
7749 /* No need to actually set up the DPLL with DSI */
7750 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7753 vlv_dpio_get(dev_priv);
7755 bestn = pipe_config->dpll.n;
7756 bestm1 = pipe_config->dpll.m1;
7757 bestm2 = pipe_config->dpll.m2;
7758 bestp1 = pipe_config->dpll.p1;
7759 bestp2 = pipe_config->dpll.p2;
7761 /* See eDP HDMI DPIO driver vbios notes doc */
7763 /* PLL B needs special handling */
7765 vlv_pllb_recal_opamp(dev_priv, pipe);
7767 /* Set up Tx target for periodic Rcomp update */
7768 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
7770 /* Disable target IRef on PLL */
7771 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
7772 reg_val &= 0x00ffffff;
7773 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
7775 /* Disable fast lock */
7776 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
7778 /* Set idtafcrecal before PLL is enabled */
7779 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
7780 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
7781 mdiv |= ((bestn << DPIO_N_SHIFT));
7782 mdiv |= (1 << DPIO_K_SHIFT);
7785 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7786 * but we don't support that).
7787 * Note: don't use the DAC post divider as it seems unstable.
7789 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
7790 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7792 mdiv |= DPIO_ENABLE_CALIBRATION;
7793 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7795 /* Set HBR and RBR LPF coefficients */
7796 if (pipe_config->port_clock == 162000 ||
7797 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
7798 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
7799 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7802 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7805 if (intel_crtc_has_dp_encoder(pipe_config)) {
7806 /* Use SSC source */
7808 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7811 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7813 } else { /* HDMI or VGA */
7814 /* Use bend source */
7816 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7819 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7823 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
7824 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
7825 if (intel_crtc_has_dp_encoder(pipe_config))
7826 coreclk |= 0x01000000;
7827 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
7829 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
7831 vlv_dpio_put(dev_priv);
7834 static void chv_prepare_pll(struct intel_crtc *crtc,
7835 const struct intel_crtc_state *pipe_config)
7837 struct drm_device *dev = crtc->base.dev;
7838 struct drm_i915_private *dev_priv = to_i915(dev);
7839 enum pipe pipe = crtc->pipe;
7840 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7841 u32 loopfilter, tribuf_calcntr;
7842 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
7846 /* Enable Refclk and SSC */
7847 I915_WRITE(DPLL(pipe),
7848 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
7850 /* No need to actually set up the DPLL with DSI */
7851 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7854 bestn = pipe_config->dpll.n;
7855 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7856 bestm1 = pipe_config->dpll.m1;
7857 bestm2 = pipe_config->dpll.m2 >> 22;
7858 bestp1 = pipe_config->dpll.p1;
7859 bestp2 = pipe_config->dpll.p2;
7860 vco = pipe_config->dpll.vco;
7864 vlv_dpio_get(dev_priv);
7866 /* p1 and p2 divider */
7867 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7868 5 << DPIO_CHV_S1_DIV_SHIFT |
7869 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
7870 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
7871 1 << DPIO_CHV_K_DIV_SHIFT);
7873 /* Feedback post-divider - m2 */
7874 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7876 /* Feedback refclk divider - n and m1 */
7877 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7878 DPIO_CHV_M1_DIV_BY_2 |
7879 1 << DPIO_CHV_N_DIV_SHIFT);
7881 /* M2 fraction division */
7882 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
7884 /* M2 fraction division enable */
7885 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7886 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7887 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7889 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7890 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
7892 /* Program digital lock detect threshold */
7893 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7894 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7895 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7896 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7898 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7899 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7902 if (vco == 5400000) {
7903 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7904 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7905 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7906 tribuf_calcntr = 0x9;
7907 } else if (vco <= 6200000) {
7908 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7909 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7910 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7911 tribuf_calcntr = 0x9;
7912 } else if (vco <= 6480000) {
7913 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7914 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7915 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7916 tribuf_calcntr = 0x8;
7918 /* Not supported. Apply the same limits as in the max case */
7919 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7920 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7921 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7924 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7926 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
7927 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7928 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7929 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7932 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7933 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7936 vlv_dpio_put(dev_priv);
7940 * vlv_force_pll_on - forcibly enable just the PLL
7941 * @dev_priv: i915 private structure
7942 * @pipe: pipe PLL to enable
7943 * @dpll: PLL configuration
7945 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7946 * in cases where we need the PLL enabled even when @pipe is not going to
7949 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
7950 const struct dpll *dpll)
7952 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
7953 struct intel_crtc_state *pipe_config;
7955 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7959 pipe_config->base.crtc = &crtc->base;
7960 pipe_config->pixel_multiplier = 1;
7961 pipe_config->dpll = *dpll;
7963 if (IS_CHERRYVIEW(dev_priv)) {
7964 chv_compute_dpll(crtc, pipe_config);
7965 chv_prepare_pll(crtc, pipe_config);
7966 chv_enable_pll(crtc, pipe_config);
7968 vlv_compute_dpll(crtc, pipe_config);
7969 vlv_prepare_pll(crtc, pipe_config);
7970 vlv_enable_pll(crtc, pipe_config);
7979 * vlv_force_pll_off - forcibly disable just the PLL
7980 * @dev_priv: i915 private structure
7981 * @pipe: pipe PLL to disable
7983 * Disable the PLL for @pipe. To be used in cases where we need
7984 * the PLL enabled even when @pipe is not going to be enabled.
7986 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
7988 if (IS_CHERRYVIEW(dev_priv))
7989 chv_disable_pll(dev_priv, pipe);
7991 vlv_disable_pll(dev_priv, pipe);
7994 static void i9xx_compute_dpll(struct intel_crtc *crtc,
7995 struct intel_crtc_state *crtc_state,
7996 struct dpll *reduced_clock)
7998 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8000 struct dpll *clock = &crtc_state->dpll;
8002 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
8004 dpll = DPLL_VGA_MODE_DIS;
8006 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8007 dpll |= DPLLB_MODE_LVDS;
8009 dpll |= DPLLB_MODE_DAC_SERIAL;
8011 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
8012 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
8013 dpll |= (crtc_state->pixel_multiplier - 1)
8014 << SDVO_MULTIPLIER_SHIFT_HIRES;
8017 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8018 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8019 dpll |= DPLL_SDVO_HIGH_SPEED;
8021 if (intel_crtc_has_dp_encoder(crtc_state))
8022 dpll |= DPLL_SDVO_HIGH_SPEED;
8024 /* compute bitmask from p1 value */
8025 if (IS_PINEVIEW(dev_priv))
8026 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
8028 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8029 if (IS_G4X(dev_priv) && reduced_clock)
8030 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8032 switch (clock->p2) {
8034 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8037 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8040 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8043 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8046 if (INTEL_GEN(dev_priv) >= 4)
8047 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
8049 if (crtc_state->sdvo_tv_clock)
8050 dpll |= PLL_REF_INPUT_TVCLKINBC;
8051 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8052 intel_panel_use_ssc(dev_priv))
8053 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8055 dpll |= PLL_REF_INPUT_DREFCLK;
8057 dpll |= DPLL_VCO_ENABLE;
8058 crtc_state->dpll_hw_state.dpll = dpll;
8060 if (INTEL_GEN(dev_priv) >= 4) {
8061 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
8062 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8063 crtc_state->dpll_hw_state.dpll_md = dpll_md;
8067 static void i8xx_compute_dpll(struct intel_crtc *crtc,
8068 struct intel_crtc_state *crtc_state,
8069 struct dpll *reduced_clock)
8071 struct drm_device *dev = crtc->base.dev;
8072 struct drm_i915_private *dev_priv = to_i915(dev);
8074 struct dpll *clock = &crtc_state->dpll;
8076 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
8078 dpll = DPLL_VGA_MODE_DIS;
8080 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8081 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8084 dpll |= PLL_P1_DIVIDE_BY_TWO;
8086 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8088 dpll |= PLL_P2_DIVIDE_BY_4;
8093 * "[Almador Errata}: For the correct operation of the muxed DVO pins
8094 * (GDEVSELB/I2Cdata, GIRDBY/I2CClk) and (GFRAMEB/DVI_Data,
8095 * GTRDYB/DVI_Clk): Bit 31 (DPLL VCO Enable) and Bit 30 (2X Clock
8096 * Enable) must be set to “1” in both the DPLL A Control Register
8097 * (06014h-06017h) and DPLL B Control Register (06018h-0601Bh)."
8099 * For simplicity We simply keep both bits always enabled in
8100 * both DPLLS. The spec says we should disable the DVO 2X clock
8101 * when not needed, but this seems to work fine in practice.
8103 if (IS_I830(dev_priv) ||
8104 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
8105 dpll |= DPLL_DVO_2X_MODE;
8107 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8108 intel_panel_use_ssc(dev_priv))
8109 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8111 dpll |= PLL_REF_INPUT_DREFCLK;
8113 dpll |= DPLL_VCO_ENABLE;
8114 crtc_state->dpll_hw_state.dpll = dpll;
8117 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
8119 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8120 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8121 enum pipe pipe = crtc->pipe;
8122 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8123 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
8124 u32 crtc_vtotal, crtc_vblank_end;
8127 /* We need to be careful not to changed the adjusted mode, for otherwise
8128 * the hw state checker will get angry at the mismatch. */
8129 crtc_vtotal = adjusted_mode->crtc_vtotal;
8130 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
8132 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
8133 /* the chip adds 2 halflines automatically */
8135 crtc_vblank_end -= 1;
8137 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8138 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
8140 vsyncshift = adjusted_mode->crtc_hsync_start -
8141 adjusted_mode->crtc_htotal / 2;
8143 vsyncshift += adjusted_mode->crtc_htotal;
8146 if (INTEL_GEN(dev_priv) > 3)
8147 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
8149 I915_WRITE(HTOTAL(cpu_transcoder),
8150 (adjusted_mode->crtc_hdisplay - 1) |
8151 ((adjusted_mode->crtc_htotal - 1) << 16));
8152 I915_WRITE(HBLANK(cpu_transcoder),
8153 (adjusted_mode->crtc_hblank_start - 1) |
8154 ((adjusted_mode->crtc_hblank_end - 1) << 16));
8155 I915_WRITE(HSYNC(cpu_transcoder),
8156 (adjusted_mode->crtc_hsync_start - 1) |
8157 ((adjusted_mode->crtc_hsync_end - 1) << 16));
8159 I915_WRITE(VTOTAL(cpu_transcoder),
8160 (adjusted_mode->crtc_vdisplay - 1) |
8161 ((crtc_vtotal - 1) << 16));
8162 I915_WRITE(VBLANK(cpu_transcoder),
8163 (adjusted_mode->crtc_vblank_start - 1) |
8164 ((crtc_vblank_end - 1) << 16));
8165 I915_WRITE(VSYNC(cpu_transcoder),
8166 (adjusted_mode->crtc_vsync_start - 1) |
8167 ((adjusted_mode->crtc_vsync_end - 1) << 16));
8169 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
8170 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
8171 * documented on the DDI_FUNC_CTL register description, EDP Input Select
8173 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
8174 (pipe == PIPE_B || pipe == PIPE_C))
8175 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
8179 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
8181 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8182 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8183 enum pipe pipe = crtc->pipe;
8185 /* pipesrc controls the size that is scaled from, which should
8186 * always be the user's requested size.
8188 I915_WRITE(PIPESRC(pipe),
8189 ((crtc_state->pipe_src_w - 1) << 16) |
8190 (crtc_state->pipe_src_h - 1));
8193 static void intel_get_pipe_timings(struct intel_crtc *crtc,
8194 struct intel_crtc_state *pipe_config)
8196 struct drm_device *dev = crtc->base.dev;
8197 struct drm_i915_private *dev_priv = to_i915(dev);
8198 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
8201 tmp = I915_READ(HTOTAL(cpu_transcoder));
8202 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
8203 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
8205 if (!transcoder_is_dsi(cpu_transcoder)) {
8206 tmp = I915_READ(HBLANK(cpu_transcoder));
8207 pipe_config->base.adjusted_mode.crtc_hblank_start =
8209 pipe_config->base.adjusted_mode.crtc_hblank_end =
8210 ((tmp >> 16) & 0xffff) + 1;
8212 tmp = I915_READ(HSYNC(cpu_transcoder));
8213 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
8214 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
8216 tmp = I915_READ(VTOTAL(cpu_transcoder));
8217 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
8218 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
8220 if (!transcoder_is_dsi(cpu_transcoder)) {
8221 tmp = I915_READ(VBLANK(cpu_transcoder));
8222 pipe_config->base.adjusted_mode.crtc_vblank_start =
8224 pipe_config->base.adjusted_mode.crtc_vblank_end =
8225 ((tmp >> 16) & 0xffff) + 1;
8227 tmp = I915_READ(VSYNC(cpu_transcoder));
8228 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
8229 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
8231 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
8232 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
8233 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
8234 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
8238 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
8239 struct intel_crtc_state *pipe_config)
8241 struct drm_device *dev = crtc->base.dev;
8242 struct drm_i915_private *dev_priv = to_i915(dev);
8245 tmp = I915_READ(PIPESRC(crtc->pipe));
8246 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
8247 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
8249 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
8250 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
8253 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
8254 struct intel_crtc_state *pipe_config)
8256 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
8257 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
8258 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
8259 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
8261 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
8262 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
8263 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
8264 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
8266 mode->flags = pipe_config->base.adjusted_mode.flags;
8267 mode->type = DRM_MODE_TYPE_DRIVER;
8269 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
8271 mode->hsync = drm_mode_hsync(mode);
8272 mode->vrefresh = drm_mode_vrefresh(mode);
8273 drm_mode_set_name(mode);
8276 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
8278 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8279 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8284 /* we keep both pipes enabled on 830 */
8285 if (IS_I830(dev_priv))
8286 pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
8288 if (crtc_state->double_wide)
8289 pipeconf |= PIPECONF_DOUBLE_WIDE;
8291 /* only g4x and later have fancy bpc/dither controls */
8292 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8293 IS_CHERRYVIEW(dev_priv)) {
8294 /* Bspec claims that we can't use dithering for 30bpp pipes. */
8295 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
8296 pipeconf |= PIPECONF_DITHER_EN |
8297 PIPECONF_DITHER_TYPE_SP;
8299 switch (crtc_state->pipe_bpp) {
8301 pipeconf |= PIPECONF_6BPC;
8304 pipeconf |= PIPECONF_8BPC;
8307 pipeconf |= PIPECONF_10BPC;
8310 /* Case prevented by intel_choose_pipe_bpp_dither. */
8315 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
8316 if (INTEL_GEN(dev_priv) < 4 ||
8317 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8318 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
8320 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
8322 pipeconf |= PIPECONF_PROGRESSIVE;
8325 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
8326 crtc_state->limited_color_range)
8327 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
8329 pipeconf |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
8331 I915_WRITE(PIPECONF(crtc->pipe), pipeconf);
8332 POSTING_READ(PIPECONF(crtc->pipe));
8335 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
8336 struct intel_crtc_state *crtc_state)
8338 struct drm_device *dev = crtc->base.dev;
8339 struct drm_i915_private *dev_priv = to_i915(dev);
8340 const struct intel_limit *limit;
8343 memset(&crtc_state->dpll_hw_state, 0,
8344 sizeof(crtc_state->dpll_hw_state));
8346 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8347 if (intel_panel_use_ssc(dev_priv)) {
8348 refclk = dev_priv->vbt.lvds_ssc_freq;
8349 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8352 limit = &intel_limits_i8xx_lvds;
8353 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
8354 limit = &intel_limits_i8xx_dvo;
8356 limit = &intel_limits_i8xx_dac;
8359 if (!crtc_state->clock_set &&
8360 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8361 refclk, NULL, &crtc_state->dpll)) {
8362 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8366 i8xx_compute_dpll(crtc, crtc_state, NULL);
8371 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
8372 struct intel_crtc_state *crtc_state)
8374 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8375 const struct intel_limit *limit;
8378 memset(&crtc_state->dpll_hw_state, 0,
8379 sizeof(crtc_state->dpll_hw_state));
8381 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8382 if (intel_panel_use_ssc(dev_priv)) {
8383 refclk = dev_priv->vbt.lvds_ssc_freq;
8384 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8387 if (intel_is_dual_link_lvds(dev_priv))
8388 limit = &intel_limits_g4x_dual_channel_lvds;
8390 limit = &intel_limits_g4x_single_channel_lvds;
8391 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
8392 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
8393 limit = &intel_limits_g4x_hdmi;
8394 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
8395 limit = &intel_limits_g4x_sdvo;
8397 /* The option is for other outputs */
8398 limit = &intel_limits_i9xx_sdvo;
8401 if (!crtc_state->clock_set &&
8402 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8403 refclk, NULL, &crtc_state->dpll)) {
8404 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8408 i9xx_compute_dpll(crtc, crtc_state, NULL);
8413 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
8414 struct intel_crtc_state *crtc_state)
8416 struct drm_device *dev = crtc->base.dev;
8417 struct drm_i915_private *dev_priv = to_i915(dev);
8418 const struct intel_limit *limit;
8421 memset(&crtc_state->dpll_hw_state, 0,
8422 sizeof(crtc_state->dpll_hw_state));
8424 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8425 if (intel_panel_use_ssc(dev_priv)) {
8426 refclk = dev_priv->vbt.lvds_ssc_freq;
8427 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8430 limit = &intel_limits_pineview_lvds;
8432 limit = &intel_limits_pineview_sdvo;
8435 if (!crtc_state->clock_set &&
8436 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8437 refclk, NULL, &crtc_state->dpll)) {
8438 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8442 i9xx_compute_dpll(crtc, crtc_state, NULL);
8447 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
8448 struct intel_crtc_state *crtc_state)
8450 struct drm_device *dev = crtc->base.dev;
8451 struct drm_i915_private *dev_priv = to_i915(dev);
8452 const struct intel_limit *limit;
8455 memset(&crtc_state->dpll_hw_state, 0,
8456 sizeof(crtc_state->dpll_hw_state));
8458 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8459 if (intel_panel_use_ssc(dev_priv)) {
8460 refclk = dev_priv->vbt.lvds_ssc_freq;
8461 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8464 limit = &intel_limits_i9xx_lvds;
8466 limit = &intel_limits_i9xx_sdvo;
8469 if (!crtc_state->clock_set &&
8470 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8471 refclk, NULL, &crtc_state->dpll)) {
8472 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8476 i9xx_compute_dpll(crtc, crtc_state, NULL);
8481 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
8482 struct intel_crtc_state *crtc_state)
8484 int refclk = 100000;
8485 const struct intel_limit *limit = &intel_limits_chv;
8487 memset(&crtc_state->dpll_hw_state, 0,
8488 sizeof(crtc_state->dpll_hw_state));
8490 if (!crtc_state->clock_set &&
8491 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8492 refclk, NULL, &crtc_state->dpll)) {
8493 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8497 chv_compute_dpll(crtc, crtc_state);
8502 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
8503 struct intel_crtc_state *crtc_state)
8505 int refclk = 100000;
8506 const struct intel_limit *limit = &intel_limits_vlv;
8508 memset(&crtc_state->dpll_hw_state, 0,
8509 sizeof(crtc_state->dpll_hw_state));
8511 if (!crtc_state->clock_set &&
8512 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8513 refclk, NULL, &crtc_state->dpll)) {
8514 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8518 vlv_compute_dpll(crtc, crtc_state);
8523 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
8525 if (IS_I830(dev_priv))
8528 return INTEL_GEN(dev_priv) >= 4 ||
8529 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
8532 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
8533 struct intel_crtc_state *pipe_config)
8535 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8538 if (!i9xx_has_pfit(dev_priv))
8541 tmp = I915_READ(PFIT_CONTROL);
8542 if (!(tmp & PFIT_ENABLE))
8545 /* Check whether the pfit is attached to our pipe. */
8546 if (INTEL_GEN(dev_priv) < 4) {
8547 if (crtc->pipe != PIPE_B)
8550 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
8554 pipe_config->gmch_pfit.control = tmp;
8555 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
8558 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
8559 struct intel_crtc_state *pipe_config)
8561 struct drm_device *dev = crtc->base.dev;
8562 struct drm_i915_private *dev_priv = to_i915(dev);
8563 int pipe = pipe_config->cpu_transcoder;
8566 int refclk = 100000;
8568 /* In case of DSI, DPLL will not be used */
8569 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8572 vlv_dpio_get(dev_priv);
8573 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
8574 vlv_dpio_put(dev_priv);
8576 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
8577 clock.m2 = mdiv & DPIO_M2DIV_MASK;
8578 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
8579 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
8580 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
8582 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
8586 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
8587 struct intel_initial_plane_config *plane_config)
8589 struct drm_device *dev = crtc->base.dev;
8590 struct drm_i915_private *dev_priv = to_i915(dev);
8591 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8592 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
8594 u32 val, base, offset;
8595 int fourcc, pixel_format;
8596 unsigned int aligned_height;
8597 struct drm_framebuffer *fb;
8598 struct intel_framebuffer *intel_fb;
8600 if (!plane->get_hw_state(plane, &pipe))
8603 WARN_ON(pipe != crtc->pipe);
8605 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8607 DRM_DEBUG_KMS("failed to alloc fb\n");
8611 fb = &intel_fb->base;
8615 val = I915_READ(DSPCNTR(i9xx_plane));
8617 if (INTEL_GEN(dev_priv) >= 4) {
8618 if (val & DISPPLANE_TILED) {
8619 plane_config->tiling = I915_TILING_X;
8620 fb->modifier = I915_FORMAT_MOD_X_TILED;
8623 if (val & DISPPLANE_ROTATE_180)
8624 plane_config->rotation = DRM_MODE_ROTATE_180;
8627 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
8628 val & DISPPLANE_MIRROR)
8629 plane_config->rotation |= DRM_MODE_REFLECT_X;
8631 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
8632 fourcc = i9xx_format_to_fourcc(pixel_format);
8633 fb->format = drm_format_info(fourcc);
8635 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
8636 offset = I915_READ(DSPOFFSET(i9xx_plane));
8637 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8638 } else if (INTEL_GEN(dev_priv) >= 4) {
8639 if (plane_config->tiling)
8640 offset = I915_READ(DSPTILEOFF(i9xx_plane));
8642 offset = I915_READ(DSPLINOFF(i9xx_plane));
8643 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8645 base = I915_READ(DSPADDR(i9xx_plane));
8647 plane_config->base = base;
8649 val = I915_READ(PIPESRC(pipe));
8650 fb->width = ((val >> 16) & 0xfff) + 1;
8651 fb->height = ((val >> 0) & 0xfff) + 1;
8653 val = I915_READ(DSPSTRIDE(i9xx_plane));
8654 fb->pitches[0] = val & 0xffffffc0;
8656 aligned_height = intel_fb_align_height(fb, 0, fb->height);
8658 plane_config->size = fb->pitches[0] * aligned_height;
8660 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8661 crtc->base.name, plane->base.name, fb->width, fb->height,
8662 fb->format->cpp[0] * 8, base, fb->pitches[0],
8663 plane_config->size);
8665 plane_config->fb = intel_fb;
8668 static void chv_crtc_clock_get(struct intel_crtc *crtc,
8669 struct intel_crtc_state *pipe_config)
8671 struct drm_device *dev = crtc->base.dev;
8672 struct drm_i915_private *dev_priv = to_i915(dev);
8673 int pipe = pipe_config->cpu_transcoder;
8674 enum dpio_channel port = vlv_pipe_to_channel(pipe);
8676 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
8677 int refclk = 100000;
8679 /* In case of DSI, DPLL will not be used */
8680 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8683 vlv_dpio_get(dev_priv);
8684 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
8685 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
8686 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
8687 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
8688 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
8689 vlv_dpio_put(dev_priv);
8691 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
8692 clock.m2 = (pll_dw0 & 0xff) << 22;
8693 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
8694 clock.m2 |= pll_dw2 & 0x3fffff;
8695 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
8696 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
8697 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
8699 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
8702 static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc,
8703 struct intel_crtc_state *pipe_config)
8705 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8706 enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB;
8708 pipe_config->lspcon_downsampling = false;
8710 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
8711 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
8713 if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
8714 bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE;
8715 bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND;
8717 if (ycbcr420_enabled) {
8718 /* We support 4:2:0 in full blend mode only */
8720 output = INTEL_OUTPUT_FORMAT_INVALID;
8721 else if (!(IS_GEMINILAKE(dev_priv) ||
8722 INTEL_GEN(dev_priv) >= 10))
8723 output = INTEL_OUTPUT_FORMAT_INVALID;
8725 output = INTEL_OUTPUT_FORMAT_YCBCR420;
8728 * Currently there is no interface defined to
8729 * check user preference between RGB/YCBCR444
8730 * or YCBCR420. So the only possible case for
8731 * YCBCR444 usage is driving YCBCR420 output
8732 * with LSPCON, when pipe is configured for
8733 * YCBCR444 output and LSPCON takes care of
8736 pipe_config->lspcon_downsampling = true;
8737 output = INTEL_OUTPUT_FORMAT_YCBCR444;
8742 pipe_config->output_format = output;
8745 static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state)
8747 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8748 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8749 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8750 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
8753 tmp = I915_READ(DSPCNTR(i9xx_plane));
8755 if (tmp & DISPPLANE_GAMMA_ENABLE)
8756 crtc_state->gamma_enable = true;
8758 if (!HAS_GMCH(dev_priv) &&
8759 tmp & DISPPLANE_PIPE_CSC_ENABLE)
8760 crtc_state->csc_enable = true;
8763 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
8764 struct intel_crtc_state *pipe_config)
8766 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8767 enum intel_display_power_domain power_domain;
8768 intel_wakeref_t wakeref;
8772 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
8773 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
8777 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
8778 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
8779 pipe_config->shared_dpll = NULL;
8783 tmp = I915_READ(PIPECONF(crtc->pipe));
8784 if (!(tmp & PIPECONF_ENABLE))
8787 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8788 IS_CHERRYVIEW(dev_priv)) {
8789 switch (tmp & PIPECONF_BPC_MASK) {
8791 pipe_config->pipe_bpp = 18;
8794 pipe_config->pipe_bpp = 24;
8796 case PIPECONF_10BPC:
8797 pipe_config->pipe_bpp = 30;
8804 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
8805 (tmp & PIPECONF_COLOR_RANGE_SELECT))
8806 pipe_config->limited_color_range = true;
8808 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_I9XX) >>
8809 PIPECONF_GAMMA_MODE_SHIFT;
8811 if (IS_CHERRYVIEW(dev_priv))
8812 pipe_config->cgm_mode = I915_READ(CGM_PIPE_MODE(crtc->pipe));
8814 i9xx_get_pipe_color_config(pipe_config);
8815 intel_color_get_config(pipe_config);
8817 if (INTEL_GEN(dev_priv) < 4)
8818 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
8820 intel_get_pipe_timings(crtc, pipe_config);
8821 intel_get_pipe_src_size(crtc, pipe_config);
8823 i9xx_get_pfit_config(crtc, pipe_config);
8825 if (INTEL_GEN(dev_priv) >= 4) {
8826 /* No way to read it out on pipes B and C */
8827 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
8828 tmp = dev_priv->chv_dpll_md[crtc->pipe];
8830 tmp = I915_READ(DPLL_MD(crtc->pipe));
8831 pipe_config->pixel_multiplier =
8832 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
8833 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
8834 pipe_config->dpll_hw_state.dpll_md = tmp;
8835 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
8836 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
8837 tmp = I915_READ(DPLL(crtc->pipe));
8838 pipe_config->pixel_multiplier =
8839 ((tmp & SDVO_MULTIPLIER_MASK)
8840 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
8842 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8843 * port and will be fixed up in the encoder->get_config
8845 pipe_config->pixel_multiplier = 1;
8847 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
8848 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
8849 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
8850 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
8852 /* Mask out read-only status bits. */
8853 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
8854 DPLL_PORTC_READY_MASK |
8855 DPLL_PORTB_READY_MASK);
8858 if (IS_CHERRYVIEW(dev_priv))
8859 chv_crtc_clock_get(crtc, pipe_config);
8860 else if (IS_VALLEYVIEW(dev_priv))
8861 vlv_crtc_clock_get(crtc, pipe_config);
8863 i9xx_crtc_clock_get(crtc, pipe_config);
8866 * Normally the dotclock is filled in by the encoder .get_config()
8867 * but in case the pipe is enabled w/o any ports we need a sane
8870 pipe_config->base.adjusted_mode.crtc_clock =
8871 pipe_config->port_clock / pipe_config->pixel_multiplier;
8876 intel_display_power_put(dev_priv, power_domain, wakeref);
8881 static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
8883 struct intel_encoder *encoder;
8886 bool has_lvds = false;
8887 bool has_cpu_edp = false;
8888 bool has_panel = false;
8889 bool has_ck505 = false;
8890 bool can_ssc = false;
8891 bool using_ssc_source = false;
8893 /* We need to take the global config into account */
8894 for_each_intel_encoder(&dev_priv->drm, encoder) {
8895 switch (encoder->type) {
8896 case INTEL_OUTPUT_LVDS:
8900 case INTEL_OUTPUT_EDP:
8902 if (encoder->port == PORT_A)
8910 if (HAS_PCH_IBX(dev_priv)) {
8911 has_ck505 = dev_priv->vbt.display_clock_mode;
8912 can_ssc = has_ck505;
8918 /* Check if any DPLLs are using the SSC source */
8919 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
8920 u32 temp = I915_READ(PCH_DPLL(i));
8922 if (!(temp & DPLL_VCO_ENABLE))
8925 if ((temp & PLL_REF_INPUT_MASK) ==
8926 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
8927 using_ssc_source = true;
8932 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
8933 has_panel, has_lvds, has_ck505, using_ssc_source);
8935 /* Ironlake: try to setup display ref clock before DPLL
8936 * enabling. This is only under driver's control after
8937 * PCH B stepping, previous chipset stepping should be
8938 * ignoring this setting.
8940 val = I915_READ(PCH_DREF_CONTROL);
8942 /* As we must carefully and slowly disable/enable each source in turn,
8943 * compute the final state we want first and check if we need to
8944 * make any changes at all.
8947 final &= ~DREF_NONSPREAD_SOURCE_MASK;
8949 final |= DREF_NONSPREAD_CK505_ENABLE;
8951 final |= DREF_NONSPREAD_SOURCE_ENABLE;
8953 final &= ~DREF_SSC_SOURCE_MASK;
8954 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8955 final &= ~DREF_SSC1_ENABLE;
8958 final |= DREF_SSC_SOURCE_ENABLE;
8960 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8961 final |= DREF_SSC1_ENABLE;
8964 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8965 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8967 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8969 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8970 } else if (using_ssc_source) {
8971 final |= DREF_SSC_SOURCE_ENABLE;
8972 final |= DREF_SSC1_ENABLE;
8978 /* Always enable nonspread source */
8979 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8982 val |= DREF_NONSPREAD_CK505_ENABLE;
8984 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8987 val &= ~DREF_SSC_SOURCE_MASK;
8988 val |= DREF_SSC_SOURCE_ENABLE;
8990 /* SSC must be turned on before enabling the CPU output */
8991 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8992 DRM_DEBUG_KMS("Using SSC on panel\n");
8993 val |= DREF_SSC1_ENABLE;
8995 val &= ~DREF_SSC1_ENABLE;
8997 /* Get SSC going before enabling the outputs */
8998 I915_WRITE(PCH_DREF_CONTROL, val);
8999 POSTING_READ(PCH_DREF_CONTROL);
9002 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9004 /* Enable CPU source on CPU attached eDP */
9006 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
9007 DRM_DEBUG_KMS("Using SSC on eDP\n");
9008 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
9010 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
9012 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9014 I915_WRITE(PCH_DREF_CONTROL, val);
9015 POSTING_READ(PCH_DREF_CONTROL);
9018 DRM_DEBUG_KMS("Disabling CPU source output\n");
9020 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9022 /* Turn off CPU output */
9023 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9025 I915_WRITE(PCH_DREF_CONTROL, val);
9026 POSTING_READ(PCH_DREF_CONTROL);
9029 if (!using_ssc_source) {
9030 DRM_DEBUG_KMS("Disabling SSC source\n");
9032 /* Turn off the SSC source */
9033 val &= ~DREF_SSC_SOURCE_MASK;
9034 val |= DREF_SSC_SOURCE_DISABLE;
9037 val &= ~DREF_SSC1_ENABLE;
9039 I915_WRITE(PCH_DREF_CONTROL, val);
9040 POSTING_READ(PCH_DREF_CONTROL);
9045 BUG_ON(val != final);
9048 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
9052 tmp = I915_READ(SOUTH_CHICKEN2);
9053 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
9054 I915_WRITE(SOUTH_CHICKEN2, tmp);
9056 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
9057 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
9058 DRM_ERROR("FDI mPHY reset assert timeout\n");
9060 tmp = I915_READ(SOUTH_CHICKEN2);
9061 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
9062 I915_WRITE(SOUTH_CHICKEN2, tmp);
9064 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
9065 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
9066 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
9069 /* WaMPhyProgramming:hsw */
9070 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
9074 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
9075 tmp &= ~(0xFF << 24);
9076 tmp |= (0x12 << 24);
9077 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
9079 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
9081 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
9083 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
9085 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
9087 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
9088 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9089 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
9091 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
9092 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9093 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
9095 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
9098 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
9100 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
9103 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
9105 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
9108 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
9110 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
9113 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
9115 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
9116 tmp &= ~(0xFF << 16);
9117 tmp |= (0x1C << 16);
9118 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
9120 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
9121 tmp &= ~(0xFF << 16);
9122 tmp |= (0x1C << 16);
9123 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
9125 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
9127 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
9129 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
9131 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
9133 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
9134 tmp &= ~(0xF << 28);
9136 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
9138 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
9139 tmp &= ~(0xF << 28);
9141 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
9144 /* Implements 3 different sequences from BSpec chapter "Display iCLK
9145 * Programming" based on the parameters passed:
9146 * - Sequence to enable CLKOUT_DP
9147 * - Sequence to enable CLKOUT_DP without spread
9148 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
9150 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
9151 bool with_spread, bool with_fdi)
9155 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
9157 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
9158 with_fdi, "LP PCH doesn't have FDI\n"))
9161 mutex_lock(&dev_priv->sb_lock);
9163 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9164 tmp &= ~SBI_SSCCTL_DISABLE;
9165 tmp |= SBI_SSCCTL_PATHALT;
9166 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9171 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9172 tmp &= ~SBI_SSCCTL_PATHALT;
9173 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9176 lpt_reset_fdi_mphy(dev_priv);
9177 lpt_program_fdi_mphy(dev_priv);
9181 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9182 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9183 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9184 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9186 mutex_unlock(&dev_priv->sb_lock);
9189 /* Sequence to disable CLKOUT_DP */
9190 void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
9194 mutex_lock(&dev_priv->sb_lock);
9196 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9197 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9198 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9199 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9201 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9202 if (!(tmp & SBI_SSCCTL_DISABLE)) {
9203 if (!(tmp & SBI_SSCCTL_PATHALT)) {
9204 tmp |= SBI_SSCCTL_PATHALT;
9205 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9208 tmp |= SBI_SSCCTL_DISABLE;
9209 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9212 mutex_unlock(&dev_priv->sb_lock);
9215 #define BEND_IDX(steps) ((50 + (steps)) / 5)
9217 static const u16 sscdivintphase[] = {
9218 [BEND_IDX( 50)] = 0x3B23,
9219 [BEND_IDX( 45)] = 0x3B23,
9220 [BEND_IDX( 40)] = 0x3C23,
9221 [BEND_IDX( 35)] = 0x3C23,
9222 [BEND_IDX( 30)] = 0x3D23,
9223 [BEND_IDX( 25)] = 0x3D23,
9224 [BEND_IDX( 20)] = 0x3E23,
9225 [BEND_IDX( 15)] = 0x3E23,
9226 [BEND_IDX( 10)] = 0x3F23,
9227 [BEND_IDX( 5)] = 0x3F23,
9228 [BEND_IDX( 0)] = 0x0025,
9229 [BEND_IDX( -5)] = 0x0025,
9230 [BEND_IDX(-10)] = 0x0125,
9231 [BEND_IDX(-15)] = 0x0125,
9232 [BEND_IDX(-20)] = 0x0225,
9233 [BEND_IDX(-25)] = 0x0225,
9234 [BEND_IDX(-30)] = 0x0325,
9235 [BEND_IDX(-35)] = 0x0325,
9236 [BEND_IDX(-40)] = 0x0425,
9237 [BEND_IDX(-45)] = 0x0425,
9238 [BEND_IDX(-50)] = 0x0525,
9243 * steps -50 to 50 inclusive, in steps of 5
9244 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
9245 * change in clock period = -(steps / 10) * 5.787 ps
9247 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
9250 int idx = BEND_IDX(steps);
9252 if (WARN_ON(steps % 5 != 0))
9255 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
9258 mutex_lock(&dev_priv->sb_lock);
9260 if (steps % 10 != 0)
9264 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
9266 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
9268 tmp |= sscdivintphase[idx];
9269 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
9271 mutex_unlock(&dev_priv->sb_lock);
9276 static bool spll_uses_pch_ssc(struct drm_i915_private *dev_priv)
9278 u32 fuse_strap = I915_READ(FUSE_STRAP);
9279 u32 ctl = I915_READ(SPLL_CTL);
9281 if ((ctl & SPLL_PLL_ENABLE) == 0)
9284 if ((ctl & SPLL_REF_MASK) == SPLL_REF_MUXED_SSC &&
9285 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9288 if (IS_BROADWELL(dev_priv) &&
9289 (ctl & SPLL_REF_MASK) == SPLL_REF_PCH_SSC_BDW)
9295 static bool wrpll_uses_pch_ssc(struct drm_i915_private *dev_priv,
9296 enum intel_dpll_id id)
9298 u32 fuse_strap = I915_READ(FUSE_STRAP);
9299 u32 ctl = I915_READ(WRPLL_CTL(id));
9301 if ((ctl & WRPLL_PLL_ENABLE) == 0)
9304 if ((ctl & WRPLL_REF_MASK) == WRPLL_REF_PCH_SSC)
9307 if ((IS_BROADWELL(dev_priv) || IS_HSW_ULT(dev_priv)) &&
9308 (ctl & WRPLL_REF_MASK) == WRPLL_REF_MUXED_SSC_BDW &&
9309 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9315 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
9317 struct intel_encoder *encoder;
9318 bool has_fdi = false;
9320 for_each_intel_encoder(&dev_priv->drm, encoder) {
9321 switch (encoder->type) {
9322 case INTEL_OUTPUT_ANALOG:
9331 * The BIOS may have decided to use the PCH SSC
9332 * reference so we must not disable it until the
9333 * relevant PLLs have stopped relying on it. We'll
9334 * just leave the PCH SSC reference enabled in case
9335 * any active PLL is using it. It will get disabled
9336 * after runtime suspend if we don't have FDI.
9338 * TODO: Move the whole reference clock handling
9339 * to the modeset sequence proper so that we can
9340 * actually enable/disable/reconfigure these things
9341 * safely. To do that we need to introduce a real
9342 * clock hierarchy. That would also allow us to do
9343 * clock bending finally.
9345 dev_priv->pch_ssc_use = 0;
9347 if (spll_uses_pch_ssc(dev_priv)) {
9348 DRM_DEBUG_KMS("SPLL using PCH SSC\n");
9349 dev_priv->pch_ssc_use |= BIT(DPLL_ID_SPLL);
9352 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL1)) {
9353 DRM_DEBUG_KMS("WRPLL1 using PCH SSC\n");
9354 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL1);
9357 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL2)) {
9358 DRM_DEBUG_KMS("WRPLL2 using PCH SSC\n");
9359 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL2);
9362 if (dev_priv->pch_ssc_use)
9366 lpt_bend_clkout_dp(dev_priv, 0);
9367 lpt_enable_clkout_dp(dev_priv, true, true);
9369 lpt_disable_clkout_dp(dev_priv);
9374 * Initialize reference clocks when the driver loads
9376 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
9378 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
9379 ironlake_init_pch_refclk(dev_priv);
9380 else if (HAS_PCH_LPT(dev_priv))
9381 lpt_init_pch_refclk(dev_priv);
9384 static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
9386 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9387 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9388 enum pipe pipe = crtc->pipe;
9393 switch (crtc_state->pipe_bpp) {
9395 val |= PIPECONF_6BPC;
9398 val |= PIPECONF_8BPC;
9401 val |= PIPECONF_10BPC;
9404 val |= PIPECONF_12BPC;
9407 /* Case prevented by intel_choose_pipe_bpp_dither. */
9411 if (crtc_state->dither)
9412 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
9414 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
9415 val |= PIPECONF_INTERLACED_ILK;
9417 val |= PIPECONF_PROGRESSIVE;
9419 if (crtc_state->limited_color_range)
9420 val |= PIPECONF_COLOR_RANGE_SELECT;
9422 val |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
9424 I915_WRITE(PIPECONF(pipe), val);
9425 POSTING_READ(PIPECONF(pipe));
9428 static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state)
9430 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9431 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9432 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
9435 if (IS_HASWELL(dev_priv) && crtc_state->dither)
9436 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
9438 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
9439 val |= PIPECONF_INTERLACED_ILK;
9441 val |= PIPECONF_PROGRESSIVE;
9443 I915_WRITE(PIPECONF(cpu_transcoder), val);
9444 POSTING_READ(PIPECONF(cpu_transcoder));
9447 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state)
9449 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9450 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9453 switch (crtc_state->pipe_bpp) {
9455 val |= PIPEMISC_DITHER_6_BPC;
9458 val |= PIPEMISC_DITHER_8_BPC;
9461 val |= PIPEMISC_DITHER_10_BPC;
9464 val |= PIPEMISC_DITHER_12_BPC;
9467 MISSING_CASE(crtc_state->pipe_bpp);
9471 if (crtc_state->dither)
9472 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
9474 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
9475 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
9476 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
9478 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
9479 val |= PIPEMISC_YUV420_ENABLE |
9480 PIPEMISC_YUV420_MODE_FULL_BLEND;
9482 if (INTEL_GEN(dev_priv) >= 11 &&
9483 (crtc_state->active_planes & ~(icl_hdr_plane_mask() |
9484 BIT(PLANE_CURSOR))) == 0)
9485 val |= PIPEMISC_HDR_MODE_PRECISION;
9487 I915_WRITE(PIPEMISC(crtc->pipe), val);
9490 int bdw_get_pipemisc_bpp(struct intel_crtc *crtc)
9492 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9495 tmp = I915_READ(PIPEMISC(crtc->pipe));
9497 switch (tmp & PIPEMISC_DITHER_BPC_MASK) {
9498 case PIPEMISC_DITHER_6_BPC:
9500 case PIPEMISC_DITHER_8_BPC:
9502 case PIPEMISC_DITHER_10_BPC:
9504 case PIPEMISC_DITHER_12_BPC:
9512 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
9515 * Account for spread spectrum to avoid
9516 * oversubscribing the link. Max center spread
9517 * is 2.5%; use 5% for safety's sake.
9519 u32 bps = target_clock * bpp * 21 / 20;
9520 return DIV_ROUND_UP(bps, link_bw * 8);
9523 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
9525 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
9528 static void ironlake_compute_dpll(struct intel_crtc *crtc,
9529 struct intel_crtc_state *crtc_state,
9530 struct dpll *reduced_clock)
9532 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9536 /* Enable autotuning of the PLL clock (if permissible) */
9538 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9539 if ((intel_panel_use_ssc(dev_priv) &&
9540 dev_priv->vbt.lvds_ssc_freq == 100000) ||
9541 (HAS_PCH_IBX(dev_priv) &&
9542 intel_is_dual_link_lvds(dev_priv)))
9544 } else if (crtc_state->sdvo_tv_clock) {
9548 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
9550 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
9553 if (reduced_clock) {
9554 fp2 = i9xx_dpll_compute_fp(reduced_clock);
9556 if (reduced_clock->m < factor * reduced_clock->n)
9564 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
9565 dpll |= DPLLB_MODE_LVDS;
9567 dpll |= DPLLB_MODE_DAC_SERIAL;
9569 dpll |= (crtc_state->pixel_multiplier - 1)
9570 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
9572 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
9573 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
9574 dpll |= DPLL_SDVO_HIGH_SPEED;
9576 if (intel_crtc_has_dp_encoder(crtc_state))
9577 dpll |= DPLL_SDVO_HIGH_SPEED;
9580 * The high speed IO clock is only really required for
9581 * SDVO/HDMI/DP, but we also enable it for CRT to make it
9582 * possible to share the DPLL between CRT and HDMI. Enabling
9583 * the clock needlessly does no real harm, except use up a
9584 * bit of power potentially.
9586 * We'll limit this to IVB with 3 pipes, since it has only two
9587 * DPLLs and so DPLL sharing is the only way to get three pipes
9588 * driving PCH ports at the same time. On SNB we could do this,
9589 * and potentially avoid enabling the second DPLL, but it's not
9590 * clear if it''s a win or loss power wise. No point in doing
9591 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
9593 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
9594 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
9595 dpll |= DPLL_SDVO_HIGH_SPEED;
9597 /* compute bitmask from p1 value */
9598 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
9600 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
9602 switch (crtc_state->dpll.p2) {
9604 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
9607 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
9610 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
9613 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
9617 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
9618 intel_panel_use_ssc(dev_priv))
9619 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
9621 dpll |= PLL_REF_INPUT_DREFCLK;
9623 dpll |= DPLL_VCO_ENABLE;
9625 crtc_state->dpll_hw_state.dpll = dpll;
9626 crtc_state->dpll_hw_state.fp0 = fp;
9627 crtc_state->dpll_hw_state.fp1 = fp2;
9630 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
9631 struct intel_crtc_state *crtc_state)
9633 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9634 struct intel_atomic_state *state =
9635 to_intel_atomic_state(crtc_state->base.state);
9636 const struct intel_limit *limit;
9637 int refclk = 120000;
9639 memset(&crtc_state->dpll_hw_state, 0,
9640 sizeof(crtc_state->dpll_hw_state));
9642 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
9643 if (!crtc_state->has_pch_encoder)
9646 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9647 if (intel_panel_use_ssc(dev_priv)) {
9648 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
9649 dev_priv->vbt.lvds_ssc_freq);
9650 refclk = dev_priv->vbt.lvds_ssc_freq;
9653 if (intel_is_dual_link_lvds(dev_priv)) {
9654 if (refclk == 100000)
9655 limit = &intel_limits_ironlake_dual_lvds_100m;
9657 limit = &intel_limits_ironlake_dual_lvds;
9659 if (refclk == 100000)
9660 limit = &intel_limits_ironlake_single_lvds_100m;
9662 limit = &intel_limits_ironlake_single_lvds;
9665 limit = &intel_limits_ironlake_dac;
9668 if (!crtc_state->clock_set &&
9669 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
9670 refclk, NULL, &crtc_state->dpll)) {
9671 DRM_ERROR("Couldn't find PLL settings for mode!\n");
9675 ironlake_compute_dpll(crtc, crtc_state, NULL);
9677 if (!intel_reserve_shared_dplls(state, crtc, NULL)) {
9678 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
9679 pipe_name(crtc->pipe));
9686 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
9687 struct intel_link_m_n *m_n)
9689 struct drm_device *dev = crtc->base.dev;
9690 struct drm_i915_private *dev_priv = to_i915(dev);
9691 enum pipe pipe = crtc->pipe;
9693 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
9694 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
9695 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
9697 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
9698 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
9699 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9702 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
9703 enum transcoder transcoder,
9704 struct intel_link_m_n *m_n,
9705 struct intel_link_m_n *m2_n2)
9707 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9708 enum pipe pipe = crtc->pipe;
9710 if (INTEL_GEN(dev_priv) >= 5) {
9711 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
9712 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
9713 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
9715 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
9716 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
9717 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9719 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
9720 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
9721 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
9722 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
9724 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
9725 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
9726 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9729 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
9730 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
9731 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
9733 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
9734 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
9735 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9739 void intel_dp_get_m_n(struct intel_crtc *crtc,
9740 struct intel_crtc_state *pipe_config)
9742 if (pipe_config->has_pch_encoder)
9743 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
9745 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
9746 &pipe_config->dp_m_n,
9747 &pipe_config->dp_m2_n2);
9750 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
9751 struct intel_crtc_state *pipe_config)
9753 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
9754 &pipe_config->fdi_m_n, NULL);
9757 static void skylake_get_pfit_config(struct intel_crtc *crtc,
9758 struct intel_crtc_state *pipe_config)
9760 struct drm_device *dev = crtc->base.dev;
9761 struct drm_i915_private *dev_priv = to_i915(dev);
9762 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
9767 /* find scaler attached to this pipe */
9768 for (i = 0; i < crtc->num_scalers; i++) {
9769 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
9770 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
9772 pipe_config->pch_pfit.enabled = true;
9773 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
9774 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
9775 scaler_state->scalers[i].in_use = true;
9780 scaler_state->scaler_id = id;
9782 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
9784 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
9789 skylake_get_initial_plane_config(struct intel_crtc *crtc,
9790 struct intel_initial_plane_config *plane_config)
9792 struct drm_device *dev = crtc->base.dev;
9793 struct drm_i915_private *dev_priv = to_i915(dev);
9794 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
9795 enum plane_id plane_id = plane->id;
9797 u32 val, base, offset, stride_mult, tiling, alpha;
9798 int fourcc, pixel_format;
9799 unsigned int aligned_height;
9800 struct drm_framebuffer *fb;
9801 struct intel_framebuffer *intel_fb;
9803 if (!plane->get_hw_state(plane, &pipe))
9806 WARN_ON(pipe != crtc->pipe);
9808 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9810 DRM_DEBUG_KMS("failed to alloc fb\n");
9814 fb = &intel_fb->base;
9818 val = I915_READ(PLANE_CTL(pipe, plane_id));
9820 if (INTEL_GEN(dev_priv) >= 11)
9821 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
9823 pixel_format = val & PLANE_CTL_FORMAT_MASK;
9825 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
9826 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
9827 alpha &= PLANE_COLOR_ALPHA_MASK;
9829 alpha = val & PLANE_CTL_ALPHA_MASK;
9832 fourcc = skl_format_to_fourcc(pixel_format,
9833 val & PLANE_CTL_ORDER_RGBX, alpha);
9834 fb->format = drm_format_info(fourcc);
9836 tiling = val & PLANE_CTL_TILED_MASK;
9838 case PLANE_CTL_TILED_LINEAR:
9839 fb->modifier = DRM_FORMAT_MOD_LINEAR;
9841 case PLANE_CTL_TILED_X:
9842 plane_config->tiling = I915_TILING_X;
9843 fb->modifier = I915_FORMAT_MOD_X_TILED;
9845 case PLANE_CTL_TILED_Y:
9846 plane_config->tiling = I915_TILING_Y;
9847 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
9848 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
9850 fb->modifier = I915_FORMAT_MOD_Y_TILED;
9852 case PLANE_CTL_TILED_YF:
9853 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
9854 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
9856 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
9859 MISSING_CASE(tiling);
9864 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
9865 * while i915 HW rotation is clockwise, thats why this swapping.
9867 switch (val & PLANE_CTL_ROTATE_MASK) {
9868 case PLANE_CTL_ROTATE_0:
9869 plane_config->rotation = DRM_MODE_ROTATE_0;
9871 case PLANE_CTL_ROTATE_90:
9872 plane_config->rotation = DRM_MODE_ROTATE_270;
9874 case PLANE_CTL_ROTATE_180:
9875 plane_config->rotation = DRM_MODE_ROTATE_180;
9877 case PLANE_CTL_ROTATE_270:
9878 plane_config->rotation = DRM_MODE_ROTATE_90;
9882 if (INTEL_GEN(dev_priv) >= 10 &&
9883 val & PLANE_CTL_FLIP_HORIZONTAL)
9884 plane_config->rotation |= DRM_MODE_REFLECT_X;
9886 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
9887 plane_config->base = base;
9889 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
9891 val = I915_READ(PLANE_SIZE(pipe, plane_id));
9892 fb->height = ((val >> 16) & 0xfff) + 1;
9893 fb->width = ((val >> 0) & 0x1fff) + 1;
9895 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
9896 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
9897 fb->pitches[0] = (val & 0x3ff) * stride_mult;
9899 aligned_height = intel_fb_align_height(fb, 0, fb->height);
9901 plane_config->size = fb->pitches[0] * aligned_height;
9903 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9904 crtc->base.name, plane->base.name, fb->width, fb->height,
9905 fb->format->cpp[0] * 8, base, fb->pitches[0],
9906 plane_config->size);
9908 plane_config->fb = intel_fb;
9915 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
9916 struct intel_crtc_state *pipe_config)
9918 struct drm_device *dev = crtc->base.dev;
9919 struct drm_i915_private *dev_priv = to_i915(dev);
9922 tmp = I915_READ(PF_CTL(crtc->pipe));
9924 if (tmp & PF_ENABLE) {
9925 pipe_config->pch_pfit.enabled = true;
9926 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
9927 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
9929 /* We currently do not free assignements of panel fitters on
9930 * ivb/hsw (since we don't use the higher upscaling modes which
9931 * differentiates them) so just WARN about this case for now. */
9932 if (IS_GEN(dev_priv, 7)) {
9933 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
9934 PF_PIPE_SEL_IVB(crtc->pipe));
9939 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
9940 struct intel_crtc_state *pipe_config)
9942 struct drm_device *dev = crtc->base.dev;
9943 struct drm_i915_private *dev_priv = to_i915(dev);
9944 enum intel_display_power_domain power_domain;
9945 intel_wakeref_t wakeref;
9949 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9950 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
9954 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
9955 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9956 pipe_config->shared_dpll = NULL;
9959 tmp = I915_READ(PIPECONF(crtc->pipe));
9960 if (!(tmp & PIPECONF_ENABLE))
9963 switch (tmp & PIPECONF_BPC_MASK) {
9965 pipe_config->pipe_bpp = 18;
9968 pipe_config->pipe_bpp = 24;
9970 case PIPECONF_10BPC:
9971 pipe_config->pipe_bpp = 30;
9973 case PIPECONF_12BPC:
9974 pipe_config->pipe_bpp = 36;
9980 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
9981 pipe_config->limited_color_range = true;
9983 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_ILK) >>
9984 PIPECONF_GAMMA_MODE_SHIFT;
9986 pipe_config->csc_mode = I915_READ(PIPE_CSC_MODE(crtc->pipe));
9988 i9xx_get_pipe_color_config(pipe_config);
9989 intel_color_get_config(pipe_config);
9991 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
9992 struct intel_shared_dpll *pll;
9993 enum intel_dpll_id pll_id;
9995 pipe_config->has_pch_encoder = true;
9997 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
9998 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9999 FDI_DP_PORT_WIDTH_SHIFT) + 1;
10001 ironlake_get_fdi_m_n_config(crtc, pipe_config);
10003 if (HAS_PCH_IBX(dev_priv)) {
10005 * The pipe->pch transcoder and pch transcoder->pll
10006 * mapping is fixed.
10008 pll_id = (enum intel_dpll_id) crtc->pipe;
10010 tmp = I915_READ(PCH_DPLL_SEL);
10011 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
10012 pll_id = DPLL_ID_PCH_PLL_B;
10014 pll_id= DPLL_ID_PCH_PLL_A;
10017 pipe_config->shared_dpll =
10018 intel_get_shared_dpll_by_id(dev_priv, pll_id);
10019 pll = pipe_config->shared_dpll;
10021 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
10022 &pipe_config->dpll_hw_state));
10024 tmp = pipe_config->dpll_hw_state.dpll;
10025 pipe_config->pixel_multiplier =
10026 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
10027 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
10029 ironlake_pch_clock_get(crtc, pipe_config);
10031 pipe_config->pixel_multiplier = 1;
10034 intel_get_pipe_timings(crtc, pipe_config);
10035 intel_get_pipe_src_size(crtc, pipe_config);
10037 ironlake_get_pfit_config(crtc, pipe_config);
10042 intel_display_power_put(dev_priv, power_domain, wakeref);
10046 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
10047 struct intel_crtc_state *crtc_state)
10049 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10050 struct intel_atomic_state *state =
10051 to_intel_atomic_state(crtc_state->base.state);
10053 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) ||
10054 INTEL_GEN(dev_priv) >= 11) {
10055 struct intel_encoder *encoder =
10056 intel_get_crtc_new_encoder(state, crtc_state);
10058 if (!intel_reserve_shared_dplls(state, crtc, encoder)) {
10059 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
10060 pipe_name(crtc->pipe));
10068 static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
10070 struct intel_crtc_state *pipe_config)
10072 enum intel_dpll_id id;
10075 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
10076 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
10078 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
10081 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10084 static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
10086 struct intel_crtc_state *pipe_config)
10088 enum phy phy = intel_port_to_phy(dev_priv, port);
10089 enum icl_port_dpll_id port_dpll_id;
10090 enum intel_dpll_id id;
10093 if (intel_phy_is_combo(dev_priv, phy)) {
10094 temp = I915_READ(ICL_DPCLKA_CFGCR0) &
10095 ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
10096 id = temp >> ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy);
10097 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10098 } else if (intel_phy_is_tc(dev_priv, phy)) {
10099 u32 clk_sel = I915_READ(DDI_CLK_SEL(port)) & DDI_CLK_SEL_MASK;
10101 if (clk_sel == DDI_CLK_SEL_MG) {
10102 id = icl_tc_port_to_pll_id(intel_port_to_tc(dev_priv,
10104 port_dpll_id = ICL_PORT_DPLL_MG_PHY;
10106 WARN_ON(clk_sel < DDI_CLK_SEL_TBT_162);
10107 id = DPLL_ID_ICL_TBTPLL;
10108 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10111 WARN(1, "Invalid port %x\n", port);
10115 pipe_config->icl_port_dplls[port_dpll_id].pll =
10116 intel_get_shared_dpll_by_id(dev_priv, id);
10118 icl_set_active_port_dpll(pipe_config, port_dpll_id);
10121 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
10123 struct intel_crtc_state *pipe_config)
10125 enum intel_dpll_id id;
10129 id = DPLL_ID_SKL_DPLL0;
10132 id = DPLL_ID_SKL_DPLL1;
10135 id = DPLL_ID_SKL_DPLL2;
10138 DRM_ERROR("Incorrect port type\n");
10142 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10145 static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
10147 struct intel_crtc_state *pipe_config)
10149 enum intel_dpll_id id;
10152 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
10153 id = temp >> (port * 3 + 1);
10155 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
10158 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10161 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
10163 struct intel_crtc_state *pipe_config)
10165 enum intel_dpll_id id;
10166 u32 ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
10168 switch (ddi_pll_sel) {
10169 case PORT_CLK_SEL_WRPLL1:
10170 id = DPLL_ID_WRPLL1;
10172 case PORT_CLK_SEL_WRPLL2:
10173 id = DPLL_ID_WRPLL2;
10175 case PORT_CLK_SEL_SPLL:
10178 case PORT_CLK_SEL_LCPLL_810:
10179 id = DPLL_ID_LCPLL_810;
10181 case PORT_CLK_SEL_LCPLL_1350:
10182 id = DPLL_ID_LCPLL_1350;
10184 case PORT_CLK_SEL_LCPLL_2700:
10185 id = DPLL_ID_LCPLL_2700;
10188 MISSING_CASE(ddi_pll_sel);
10190 case PORT_CLK_SEL_NONE:
10194 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10197 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
10198 struct intel_crtc_state *pipe_config,
10199 u64 *power_domain_mask,
10200 intel_wakeref_t *wakerefs)
10202 struct drm_device *dev = crtc->base.dev;
10203 struct drm_i915_private *dev_priv = to_i915(dev);
10204 enum intel_display_power_domain power_domain;
10205 unsigned long panel_transcoder_mask = 0;
10206 unsigned long enabled_panel_transcoders = 0;
10207 enum transcoder panel_transcoder;
10208 intel_wakeref_t wf;
10211 if (INTEL_GEN(dev_priv) >= 11)
10212 panel_transcoder_mask |=
10213 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
10215 if (HAS_TRANSCODER_EDP(dev_priv))
10216 panel_transcoder_mask |= BIT(TRANSCODER_EDP);
10219 * The pipe->transcoder mapping is fixed with the exception of the eDP
10220 * and DSI transcoders handled below.
10222 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
10225 * XXX: Do intel_display_power_get_if_enabled before reading this (for
10226 * consistency and less surprising code; it's in always on power).
10228 for_each_set_bit(panel_transcoder,
10229 &panel_transcoder_mask,
10230 ARRAY_SIZE(INTEL_INFO(dev_priv)->trans_offsets)) {
10231 bool force_thru = false;
10232 enum pipe trans_pipe;
10234 tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder));
10235 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
10239 * Log all enabled ones, only use the first one.
10241 * FIXME: This won't work for two separate DSI displays.
10243 enabled_panel_transcoders |= BIT(panel_transcoder);
10244 if (enabled_panel_transcoders != BIT(panel_transcoder))
10247 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
10249 WARN(1, "unknown pipe linked to transcoder %s\n",
10250 transcoder_name(panel_transcoder));
10252 case TRANS_DDI_EDP_INPUT_A_ONOFF:
10255 case TRANS_DDI_EDP_INPUT_A_ON:
10256 trans_pipe = PIPE_A;
10258 case TRANS_DDI_EDP_INPUT_B_ONOFF:
10259 trans_pipe = PIPE_B;
10261 case TRANS_DDI_EDP_INPUT_C_ONOFF:
10262 trans_pipe = PIPE_C;
10266 if (trans_pipe == crtc->pipe) {
10267 pipe_config->cpu_transcoder = panel_transcoder;
10268 pipe_config->pch_pfit.force_thru = force_thru;
10273 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
10275 WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
10276 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
10278 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
10279 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
10281 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10285 wakerefs[power_domain] = wf;
10286 *power_domain_mask |= BIT_ULL(power_domain);
10288 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
10290 return tmp & PIPECONF_ENABLE;
10293 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
10294 struct intel_crtc_state *pipe_config,
10295 u64 *power_domain_mask,
10296 intel_wakeref_t *wakerefs)
10298 struct drm_device *dev = crtc->base.dev;
10299 struct drm_i915_private *dev_priv = to_i915(dev);
10300 enum intel_display_power_domain power_domain;
10301 enum transcoder cpu_transcoder;
10302 intel_wakeref_t wf;
10306 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
10307 if (port == PORT_A)
10308 cpu_transcoder = TRANSCODER_DSI_A;
10310 cpu_transcoder = TRANSCODER_DSI_C;
10312 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
10313 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
10315 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10319 wakerefs[power_domain] = wf;
10320 *power_domain_mask |= BIT_ULL(power_domain);
10323 * The PLL needs to be enabled with a valid divider
10324 * configuration, otherwise accessing DSI registers will hang
10325 * the machine. See BSpec North Display Engine
10326 * registers/MIPI[BXT]. We can break out here early, since we
10327 * need the same DSI PLL to be enabled for both DSI ports.
10329 if (!bxt_dsi_pll_is_enabled(dev_priv))
10332 /* XXX: this works for video mode only */
10333 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
10334 if (!(tmp & DPI_ENABLE))
10337 tmp = I915_READ(MIPI_CTRL(port));
10338 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
10341 pipe_config->cpu_transcoder = cpu_transcoder;
10345 return transcoder_is_dsi(pipe_config->cpu_transcoder);
10348 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
10349 struct intel_crtc_state *pipe_config)
10351 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10352 struct intel_shared_dpll *pll;
10356 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
10358 if (INTEL_GEN(dev_priv) >= 12)
10359 port = TGL_TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
10361 port = TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
10363 if (INTEL_GEN(dev_priv) >= 11)
10364 icelake_get_ddi_pll(dev_priv, port, pipe_config);
10365 else if (IS_CANNONLAKE(dev_priv))
10366 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
10367 else if (IS_GEN9_BC(dev_priv))
10368 skylake_get_ddi_pll(dev_priv, port, pipe_config);
10369 else if (IS_GEN9_LP(dev_priv))
10370 bxt_get_ddi_pll(dev_priv, port, pipe_config);
10372 haswell_get_ddi_pll(dev_priv, port, pipe_config);
10374 pll = pipe_config->shared_dpll;
10376 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
10377 &pipe_config->dpll_hw_state));
10381 * Haswell has only FDI/PCH transcoder A. It is which is connected to
10382 * DDI E. So just check whether this pipe is wired to DDI E and whether
10383 * the PCH transcoder is on.
10385 if (INTEL_GEN(dev_priv) < 9 &&
10386 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
10387 pipe_config->has_pch_encoder = true;
10389 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
10390 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
10391 FDI_DP_PORT_WIDTH_SHIFT) + 1;
10393 ironlake_get_fdi_m_n_config(crtc, pipe_config);
10397 static bool haswell_get_pipe_config(struct intel_crtc *crtc,
10398 struct intel_crtc_state *pipe_config)
10400 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10401 intel_wakeref_t wakerefs[POWER_DOMAIN_NUM], wf;
10402 enum intel_display_power_domain power_domain;
10403 u64 power_domain_mask;
10406 intel_crtc_init_scalers(crtc, pipe_config);
10408 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
10409 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10413 wakerefs[power_domain] = wf;
10414 power_domain_mask = BIT_ULL(power_domain);
10416 pipe_config->shared_dpll = NULL;
10418 active = hsw_get_transcoder_state(crtc, pipe_config,
10419 &power_domain_mask, wakerefs);
10421 if (IS_GEN9_LP(dev_priv) &&
10422 bxt_get_dsi_transcoder_state(crtc, pipe_config,
10423 &power_domain_mask, wakerefs)) {
10431 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
10432 INTEL_GEN(dev_priv) >= 11) {
10433 haswell_get_ddi_port_state(crtc, pipe_config);
10434 intel_get_pipe_timings(crtc, pipe_config);
10437 intel_get_pipe_src_size(crtc, pipe_config);
10438 intel_get_crtc_ycbcr_config(crtc, pipe_config);
10440 pipe_config->gamma_mode = I915_READ(GAMMA_MODE(crtc->pipe));
10442 pipe_config->csc_mode = I915_READ(PIPE_CSC_MODE(crtc->pipe));
10444 if (INTEL_GEN(dev_priv) >= 9) {
10445 u32 tmp = I915_READ(SKL_BOTTOM_COLOR(crtc->pipe));
10447 if (tmp & SKL_BOTTOM_COLOR_GAMMA_ENABLE)
10448 pipe_config->gamma_enable = true;
10450 if (tmp & SKL_BOTTOM_COLOR_CSC_ENABLE)
10451 pipe_config->csc_enable = true;
10453 i9xx_get_pipe_color_config(pipe_config);
10456 intel_color_get_config(pipe_config);
10458 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
10459 WARN_ON(power_domain_mask & BIT_ULL(power_domain));
10461 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10463 wakerefs[power_domain] = wf;
10464 power_domain_mask |= BIT_ULL(power_domain);
10466 if (INTEL_GEN(dev_priv) >= 9)
10467 skylake_get_pfit_config(crtc, pipe_config);
10469 ironlake_get_pfit_config(crtc, pipe_config);
10472 if (hsw_crtc_supports_ips(crtc)) {
10473 if (IS_HASWELL(dev_priv))
10474 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
10477 * We cannot readout IPS state on broadwell, set to
10478 * true so we can set it to a defined state on first
10481 pipe_config->ips_enabled = true;
10485 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
10486 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
10487 pipe_config->pixel_multiplier =
10488 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
10490 pipe_config->pixel_multiplier = 1;
10494 for_each_power_domain(power_domain, power_domain_mask)
10495 intel_display_power_put(dev_priv,
10496 power_domain, wakerefs[power_domain]);
10501 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
10503 struct drm_i915_private *dev_priv =
10504 to_i915(plane_state->base.plane->dev);
10505 const struct drm_framebuffer *fb = plane_state->base.fb;
10506 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
10509 if (INTEL_INFO(dev_priv)->display.cursor_needs_physical)
10510 base = obj->phys_handle->busaddr;
10512 base = intel_plane_ggtt_offset(plane_state);
10514 base += plane_state->color_plane[0].offset;
10516 /* ILK+ do this automagically */
10517 if (HAS_GMCH(dev_priv) &&
10518 plane_state->base.rotation & DRM_MODE_ROTATE_180)
10519 base += (plane_state->base.crtc_h *
10520 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
10525 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
10527 int x = plane_state->base.crtc_x;
10528 int y = plane_state->base.crtc_y;
10532 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
10535 pos |= x << CURSOR_X_SHIFT;
10538 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
10541 pos |= y << CURSOR_Y_SHIFT;
10546 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
10548 const struct drm_mode_config *config =
10549 &plane_state->base.plane->dev->mode_config;
10550 int width = plane_state->base.crtc_w;
10551 int height = plane_state->base.crtc_h;
10553 return width > 0 && width <= config->cursor_width &&
10554 height > 0 && height <= config->cursor_height;
10557 static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
10563 ret = intel_plane_compute_gtt(plane_state);
10567 if (!plane_state->base.visible)
10570 src_x = plane_state->base.src_x >> 16;
10571 src_y = plane_state->base.src_y >> 16;
10573 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
10574 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
10577 if (src_x != 0 || src_y != 0) {
10578 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
10582 plane_state->color_plane[0].offset = offset;
10587 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
10588 struct intel_plane_state *plane_state)
10590 const struct drm_framebuffer *fb = plane_state->base.fb;
10593 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
10594 DRM_DEBUG_KMS("cursor cannot be tiled\n");
10598 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
10600 DRM_PLANE_HELPER_NO_SCALING,
10601 DRM_PLANE_HELPER_NO_SCALING,
10606 ret = intel_cursor_check_surface(plane_state);
10610 if (!plane_state->base.visible)
10613 ret = intel_plane_check_src_coordinates(plane_state);
10620 static unsigned int
10621 i845_cursor_max_stride(struct intel_plane *plane,
10622 u32 pixel_format, u64 modifier,
10623 unsigned int rotation)
10628 static u32 i845_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
10632 if (crtc_state->gamma_enable)
10633 cntl |= CURSOR_GAMMA_ENABLE;
10638 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
10639 const struct intel_plane_state *plane_state)
10641 return CURSOR_ENABLE |
10642 CURSOR_FORMAT_ARGB |
10643 CURSOR_STRIDE(plane_state->color_plane[0].stride);
10646 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
10648 int width = plane_state->base.crtc_w;
10651 * 845g/865g are only limited by the width of their cursors,
10652 * the height is arbitrary up to the precision of the register.
10654 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
10657 static int i845_check_cursor(struct intel_crtc_state *crtc_state,
10658 struct intel_plane_state *plane_state)
10660 const struct drm_framebuffer *fb = plane_state->base.fb;
10663 ret = intel_check_cursor(crtc_state, plane_state);
10667 /* if we want to turn off the cursor ignore width and height */
10671 /* Check for which cursor types we support */
10672 if (!i845_cursor_size_ok(plane_state)) {
10673 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10674 plane_state->base.crtc_w,
10675 plane_state->base.crtc_h);
10679 WARN_ON(plane_state->base.visible &&
10680 plane_state->color_plane[0].stride != fb->pitches[0]);
10682 switch (fb->pitches[0]) {
10689 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
10694 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
10699 static void i845_update_cursor(struct intel_plane *plane,
10700 const struct intel_crtc_state *crtc_state,
10701 const struct intel_plane_state *plane_state)
10703 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10704 u32 cntl = 0, base = 0, pos = 0, size = 0;
10705 unsigned long irqflags;
10707 if (plane_state && plane_state->base.visible) {
10708 unsigned int width = plane_state->base.crtc_w;
10709 unsigned int height = plane_state->base.crtc_h;
10711 cntl = plane_state->ctl |
10712 i845_cursor_ctl_crtc(crtc_state);
10714 size = (height << 12) | width;
10716 base = intel_cursor_base(plane_state);
10717 pos = intel_cursor_position(plane_state);
10720 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10722 /* On these chipsets we can only modify the base/size/stride
10723 * whilst the cursor is disabled.
10725 if (plane->cursor.base != base ||
10726 plane->cursor.size != size ||
10727 plane->cursor.cntl != cntl) {
10728 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
10729 I915_WRITE_FW(CURBASE(PIPE_A), base);
10730 I915_WRITE_FW(CURSIZE, size);
10731 I915_WRITE_FW(CURPOS(PIPE_A), pos);
10732 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
10734 plane->cursor.base = base;
10735 plane->cursor.size = size;
10736 plane->cursor.cntl = cntl;
10738 I915_WRITE_FW(CURPOS(PIPE_A), pos);
10741 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
10744 static void i845_disable_cursor(struct intel_plane *plane,
10745 const struct intel_crtc_state *crtc_state)
10747 i845_update_cursor(plane, crtc_state, NULL);
10750 static bool i845_cursor_get_hw_state(struct intel_plane *plane,
10753 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10754 enum intel_display_power_domain power_domain;
10755 intel_wakeref_t wakeref;
10758 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
10759 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10763 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
10767 intel_display_power_put(dev_priv, power_domain, wakeref);
10772 static unsigned int
10773 i9xx_cursor_max_stride(struct intel_plane *plane,
10774 u32 pixel_format, u64 modifier,
10775 unsigned int rotation)
10777 return plane->base.dev->mode_config.cursor_width * 4;
10780 static u32 i9xx_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
10782 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
10783 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10786 if (INTEL_GEN(dev_priv) >= 11)
10789 if (crtc_state->gamma_enable)
10790 cntl = MCURSOR_GAMMA_ENABLE;
10792 if (crtc_state->csc_enable)
10793 cntl |= MCURSOR_PIPE_CSC_ENABLE;
10795 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10796 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
10801 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
10802 const struct intel_plane_state *plane_state)
10804 struct drm_i915_private *dev_priv =
10805 to_i915(plane_state->base.plane->dev);
10808 if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
10809 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
10811 switch (plane_state->base.crtc_w) {
10813 cntl |= MCURSOR_MODE_64_ARGB_AX;
10816 cntl |= MCURSOR_MODE_128_ARGB_AX;
10819 cntl |= MCURSOR_MODE_256_ARGB_AX;
10822 MISSING_CASE(plane_state->base.crtc_w);
10826 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
10827 cntl |= MCURSOR_ROTATE_180;
10832 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
10834 struct drm_i915_private *dev_priv =
10835 to_i915(plane_state->base.plane->dev);
10836 int width = plane_state->base.crtc_w;
10837 int height = plane_state->base.crtc_h;
10839 if (!intel_cursor_size_ok(plane_state))
10842 /* Cursor width is limited to a few power-of-two sizes */
10853 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
10854 * height from 8 lines up to the cursor width, when the
10855 * cursor is not rotated. Everything else requires square
10858 if (HAS_CUR_FBC(dev_priv) &&
10859 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
10860 if (height < 8 || height > width)
10863 if (height != width)
10870 static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
10871 struct intel_plane_state *plane_state)
10873 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
10874 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10875 const struct drm_framebuffer *fb = plane_state->base.fb;
10876 enum pipe pipe = plane->pipe;
10879 ret = intel_check_cursor(crtc_state, plane_state);
10883 /* if we want to turn off the cursor ignore width and height */
10887 /* Check for which cursor types we support */
10888 if (!i9xx_cursor_size_ok(plane_state)) {
10889 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10890 plane_state->base.crtc_w,
10891 plane_state->base.crtc_h);
10895 WARN_ON(plane_state->base.visible &&
10896 plane_state->color_plane[0].stride != fb->pitches[0]);
10898 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
10899 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
10900 fb->pitches[0], plane_state->base.crtc_w);
10905 * There's something wrong with the cursor on CHV pipe C.
10906 * If it straddles the left edge of the screen then
10907 * moving it away from the edge or disabling it often
10908 * results in a pipe underrun, and often that can lead to
10909 * dead pipe (constant underrun reported, and it scans
10910 * out just a solid color). To recover from that, the
10911 * display power well must be turned off and on again.
10912 * Refuse the put the cursor into that compromised position.
10914 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
10915 plane_state->base.visible && plane_state->base.crtc_x < 0) {
10916 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
10920 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
10925 static void i9xx_update_cursor(struct intel_plane *plane,
10926 const struct intel_crtc_state *crtc_state,
10927 const struct intel_plane_state *plane_state)
10929 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10930 enum pipe pipe = plane->pipe;
10931 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
10932 unsigned long irqflags;
10934 if (plane_state && plane_state->base.visible) {
10935 cntl = plane_state->ctl |
10936 i9xx_cursor_ctl_crtc(crtc_state);
10938 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
10939 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
10941 base = intel_cursor_base(plane_state);
10942 pos = intel_cursor_position(plane_state);
10945 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10948 * On some platforms writing CURCNTR first will also
10949 * cause CURPOS to be armed by the CURBASE write.
10950 * Without the CURCNTR write the CURPOS write would
10951 * arm itself. Thus we always update CURCNTR before
10954 * On other platforms CURPOS always requires the
10955 * CURBASE write to arm the update. Additonally
10956 * a write to any of the cursor register will cancel
10957 * an already armed cursor update. Thus leaving out
10958 * the CURBASE write after CURPOS could lead to a
10959 * cursor that doesn't appear to move, or even change
10960 * shape. Thus we always write CURBASE.
10962 * The other registers are armed by by the CURBASE write
10963 * except when the plane is getting enabled at which time
10964 * the CURCNTR write arms the update.
10967 if (INTEL_GEN(dev_priv) >= 9)
10968 skl_write_cursor_wm(plane, crtc_state);
10970 if (plane->cursor.base != base ||
10971 plane->cursor.size != fbc_ctl ||
10972 plane->cursor.cntl != cntl) {
10973 if (HAS_CUR_FBC(dev_priv))
10974 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
10975 I915_WRITE_FW(CURCNTR(pipe), cntl);
10976 I915_WRITE_FW(CURPOS(pipe), pos);
10977 I915_WRITE_FW(CURBASE(pipe), base);
10979 plane->cursor.base = base;
10980 plane->cursor.size = fbc_ctl;
10981 plane->cursor.cntl = cntl;
10983 I915_WRITE_FW(CURPOS(pipe), pos);
10984 I915_WRITE_FW(CURBASE(pipe), base);
10987 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
10990 static void i9xx_disable_cursor(struct intel_plane *plane,
10991 const struct intel_crtc_state *crtc_state)
10993 i9xx_update_cursor(plane, crtc_state, NULL);
10996 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
10999 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11000 enum intel_display_power_domain power_domain;
11001 intel_wakeref_t wakeref;
11006 * Not 100% correct for planes that can move between pipes,
11007 * but that's only the case for gen2-3 which don't have any
11008 * display power wells.
11010 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
11011 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
11015 val = I915_READ(CURCNTR(plane->pipe));
11017 ret = val & MCURSOR_MODE;
11019 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
11020 *pipe = plane->pipe;
11022 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
11023 MCURSOR_PIPE_SELECT_SHIFT;
11025 intel_display_power_put(dev_priv, power_domain, wakeref);
11030 /* VESA 640x480x72Hz mode to set on the pipe */
11031 static const struct drm_display_mode load_detect_mode = {
11032 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
11033 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
11036 struct drm_framebuffer *
11037 intel_framebuffer_create(struct drm_i915_gem_object *obj,
11038 struct drm_mode_fb_cmd2 *mode_cmd)
11040 struct intel_framebuffer *intel_fb;
11043 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
11045 return ERR_PTR(-ENOMEM);
11047 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
11051 return &intel_fb->base;
11055 return ERR_PTR(ret);
11058 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
11059 struct drm_crtc *crtc)
11061 struct drm_plane *plane;
11062 struct drm_plane_state *plane_state;
11065 ret = drm_atomic_add_affected_planes(state, crtc);
11069 for_each_new_plane_in_state(state, plane, plane_state, i) {
11070 if (plane_state->crtc != crtc)
11073 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
11077 drm_atomic_set_fb_for_plane(plane_state, NULL);
11083 int intel_get_load_detect_pipe(struct drm_connector *connector,
11084 const struct drm_display_mode *mode,
11085 struct intel_load_detect_pipe *old,
11086 struct drm_modeset_acquire_ctx *ctx)
11088 struct intel_crtc *intel_crtc;
11089 struct intel_encoder *intel_encoder =
11090 intel_attached_encoder(connector);
11091 struct drm_crtc *possible_crtc;
11092 struct drm_encoder *encoder = &intel_encoder->base;
11093 struct drm_crtc *crtc = NULL;
11094 struct drm_device *dev = encoder->dev;
11095 struct drm_i915_private *dev_priv = to_i915(dev);
11096 struct drm_mode_config *config = &dev->mode_config;
11097 struct drm_atomic_state *state = NULL, *restore_state = NULL;
11098 struct drm_connector_state *connector_state;
11099 struct intel_crtc_state *crtc_state;
11102 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11103 connector->base.id, connector->name,
11104 encoder->base.id, encoder->name);
11106 old->restore_state = NULL;
11108 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
11111 * Algorithm gets a little messy:
11113 * - if the connector already has an assigned crtc, use it (but make
11114 * sure it's on first)
11116 * - try to find the first unused crtc that can drive this connector,
11117 * and use that if we find one
11120 /* See if we already have a CRTC for this connector */
11121 if (connector->state->crtc) {
11122 crtc = connector->state->crtc;
11124 ret = drm_modeset_lock(&crtc->mutex, ctx);
11128 /* Make sure the crtc and connector are running */
11132 /* Find an unused one (if possible) */
11133 for_each_crtc(dev, possible_crtc) {
11135 if (!(encoder->possible_crtcs & (1 << i)))
11138 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
11142 if (possible_crtc->state->enable) {
11143 drm_modeset_unlock(&possible_crtc->mutex);
11147 crtc = possible_crtc;
11152 * If we didn't find an unused CRTC, don't use any.
11155 DRM_DEBUG_KMS("no pipe available for load-detect\n");
11161 intel_crtc = to_intel_crtc(crtc);
11163 state = drm_atomic_state_alloc(dev);
11164 restore_state = drm_atomic_state_alloc(dev);
11165 if (!state || !restore_state) {
11170 state->acquire_ctx = ctx;
11171 restore_state->acquire_ctx = ctx;
11173 connector_state = drm_atomic_get_connector_state(state, connector);
11174 if (IS_ERR(connector_state)) {
11175 ret = PTR_ERR(connector_state);
11179 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
11183 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
11184 if (IS_ERR(crtc_state)) {
11185 ret = PTR_ERR(crtc_state);
11189 crtc_state->base.active = crtc_state->base.enable = true;
11192 mode = &load_detect_mode;
11194 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
11198 ret = intel_modeset_disable_planes(state, crtc);
11202 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
11204 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
11206 ret = drm_atomic_add_affected_planes(restore_state, crtc);
11208 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
11212 ret = drm_atomic_commit(state);
11214 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
11218 old->restore_state = restore_state;
11219 drm_atomic_state_put(state);
11221 /* let the connector get through one full cycle before testing */
11222 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
11227 drm_atomic_state_put(state);
11230 if (restore_state) {
11231 drm_atomic_state_put(restore_state);
11232 restore_state = NULL;
11235 if (ret == -EDEADLK)
11241 void intel_release_load_detect_pipe(struct drm_connector *connector,
11242 struct intel_load_detect_pipe *old,
11243 struct drm_modeset_acquire_ctx *ctx)
11245 struct intel_encoder *intel_encoder =
11246 intel_attached_encoder(connector);
11247 struct drm_encoder *encoder = &intel_encoder->base;
11248 struct drm_atomic_state *state = old->restore_state;
11251 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11252 connector->base.id, connector->name,
11253 encoder->base.id, encoder->name);
11258 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
11260 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
11261 drm_atomic_state_put(state);
11264 static int i9xx_pll_refclk(struct drm_device *dev,
11265 const struct intel_crtc_state *pipe_config)
11267 struct drm_i915_private *dev_priv = to_i915(dev);
11268 u32 dpll = pipe_config->dpll_hw_state.dpll;
11270 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
11271 return dev_priv->vbt.lvds_ssc_freq;
11272 else if (HAS_PCH_SPLIT(dev_priv))
11274 else if (!IS_GEN(dev_priv, 2))
11280 /* Returns the clock of the currently programmed mode of the given pipe. */
11281 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
11282 struct intel_crtc_state *pipe_config)
11284 struct drm_device *dev = crtc->base.dev;
11285 struct drm_i915_private *dev_priv = to_i915(dev);
11286 int pipe = pipe_config->cpu_transcoder;
11287 u32 dpll = pipe_config->dpll_hw_state.dpll;
11291 int refclk = i9xx_pll_refclk(dev, pipe_config);
11293 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
11294 fp = pipe_config->dpll_hw_state.fp0;
11296 fp = pipe_config->dpll_hw_state.fp1;
11298 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
11299 if (IS_PINEVIEW(dev_priv)) {
11300 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
11301 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
11303 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
11304 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
11307 if (!IS_GEN(dev_priv, 2)) {
11308 if (IS_PINEVIEW(dev_priv))
11309 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
11310 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
11312 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
11313 DPLL_FPA01_P1_POST_DIV_SHIFT);
11315 switch (dpll & DPLL_MODE_MASK) {
11316 case DPLLB_MODE_DAC_SERIAL:
11317 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
11320 case DPLLB_MODE_LVDS:
11321 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
11325 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
11326 "mode\n", (int)(dpll & DPLL_MODE_MASK));
11330 if (IS_PINEVIEW(dev_priv))
11331 port_clock = pnv_calc_dpll_params(refclk, &clock);
11333 port_clock = i9xx_calc_dpll_params(refclk, &clock);
11335 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
11336 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
11339 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
11340 DPLL_FPA01_P1_POST_DIV_SHIFT);
11342 if (lvds & LVDS_CLKB_POWER_UP)
11347 if (dpll & PLL_P1_DIVIDE_BY_TWO)
11350 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
11351 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
11353 if (dpll & PLL_P2_DIVIDE_BY_4)
11359 port_clock = i9xx_calc_dpll_params(refclk, &clock);
11363 * This value includes pixel_multiplier. We will use
11364 * port_clock to compute adjusted_mode.crtc_clock in the
11365 * encoder's get_config() function.
11367 pipe_config->port_clock = port_clock;
11370 int intel_dotclock_calculate(int link_freq,
11371 const struct intel_link_m_n *m_n)
11374 * The calculation for the data clock is:
11375 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
11376 * But we want to avoid losing precison if possible, so:
11377 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
11379 * and the link clock is simpler:
11380 * link_clock = (m * link_clock) / n
11386 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
11389 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
11390 struct intel_crtc_state *pipe_config)
11392 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11394 /* read out port_clock from the DPLL */
11395 i9xx_crtc_clock_get(crtc, pipe_config);
11398 * In case there is an active pipe without active ports,
11399 * we may need some idea for the dotclock anyway.
11400 * Calculate one based on the FDI configuration.
11402 pipe_config->base.adjusted_mode.crtc_clock =
11403 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
11404 &pipe_config->fdi_m_n);
11407 /* Returns the currently programmed mode of the given encoder. */
11408 struct drm_display_mode *
11409 intel_encoder_current_mode(struct intel_encoder *encoder)
11411 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
11412 struct intel_crtc_state *crtc_state;
11413 struct drm_display_mode *mode;
11414 struct intel_crtc *crtc;
11417 if (!encoder->get_hw_state(encoder, &pipe))
11420 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
11422 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
11426 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
11432 crtc_state->base.crtc = &crtc->base;
11434 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
11440 encoder->get_config(encoder, crtc_state);
11442 intel_mode_from_pipe_config(mode, crtc_state);
11449 static void intel_crtc_destroy(struct drm_crtc *crtc)
11451 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11453 drm_crtc_cleanup(crtc);
11458 * intel_wm_need_update - Check whether watermarks need updating
11459 * @cur: current plane state
11460 * @new: new plane state
11462 * Check current plane state versus the new one to determine whether
11463 * watermarks need to be recalculated.
11465 * Returns true or false.
11467 static bool intel_wm_need_update(const struct intel_plane_state *cur,
11468 struct intel_plane_state *new)
11470 /* Update watermarks on tiling or size changes. */
11471 if (new->base.visible != cur->base.visible)
11474 if (!cur->base.fb || !new->base.fb)
11477 if (cur->base.fb->modifier != new->base.fb->modifier ||
11478 cur->base.rotation != new->base.rotation ||
11479 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
11480 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
11481 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
11482 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
11488 static bool needs_scaling(const struct intel_plane_state *state)
11490 int src_w = drm_rect_width(&state->base.src) >> 16;
11491 int src_h = drm_rect_height(&state->base.src) >> 16;
11492 int dst_w = drm_rect_width(&state->base.dst);
11493 int dst_h = drm_rect_height(&state->base.dst);
11495 return (src_w != dst_w || src_h != dst_h);
11498 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
11499 struct intel_crtc_state *crtc_state,
11500 const struct intel_plane_state *old_plane_state,
11501 struct intel_plane_state *plane_state)
11503 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
11504 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
11505 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11506 bool mode_changed = needs_modeset(crtc_state);
11507 bool was_crtc_enabled = old_crtc_state->base.active;
11508 bool is_crtc_enabled = crtc_state->base.active;
11509 bool turn_off, turn_on, visible, was_visible;
11510 struct drm_framebuffer *fb = plane_state->base.fb;
11513 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
11514 ret = skl_update_scaler_plane(crtc_state, plane_state);
11519 was_visible = old_plane_state->base.visible;
11520 visible = plane_state->base.visible;
11522 if (!was_crtc_enabled && WARN_ON(was_visible))
11523 was_visible = false;
11526 * Visibility is calculated as if the crtc was on, but
11527 * after scaler setup everything depends on it being off
11528 * when the crtc isn't active.
11530 * FIXME this is wrong for watermarks. Watermarks should also
11531 * be computed as if the pipe would be active. Perhaps move
11532 * per-plane wm computation to the .check_plane() hook, and
11533 * only combine the results from all planes in the current place?
11535 if (!is_crtc_enabled) {
11536 plane_state->base.visible = visible = false;
11537 crtc_state->active_planes &= ~BIT(plane->id);
11538 crtc_state->data_rate[plane->id] = 0;
11541 if (!was_visible && !visible)
11544 if (fb != old_plane_state->base.fb)
11545 crtc_state->fb_changed = true;
11547 turn_off = was_visible && (!visible || mode_changed);
11548 turn_on = visible && (!was_visible || mode_changed);
11550 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
11551 crtc->base.base.id, crtc->base.name,
11552 plane->base.base.id, plane->base.name,
11553 fb ? fb->base.id : -1);
11555 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
11556 plane->base.base.id, plane->base.name,
11557 was_visible, visible,
11558 turn_off, turn_on, mode_changed);
11561 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11562 crtc_state->update_wm_pre = true;
11564 /* must disable cxsr around plane enable/disable */
11565 if (plane->id != PLANE_CURSOR)
11566 crtc_state->disable_cxsr = true;
11567 } else if (turn_off) {
11568 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11569 crtc_state->update_wm_post = true;
11571 /* must disable cxsr around plane enable/disable */
11572 if (plane->id != PLANE_CURSOR)
11573 crtc_state->disable_cxsr = true;
11574 } else if (intel_wm_need_update(old_plane_state, plane_state)) {
11575 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
11576 /* FIXME bollocks */
11577 crtc_state->update_wm_pre = true;
11578 crtc_state->update_wm_post = true;
11582 if (visible || was_visible)
11583 crtc_state->fb_bits |= plane->frontbuffer_bit;
11586 * ILK/SNB DVSACNTR/Sprite Enable
11587 * IVB SPR_CTL/Sprite Enable
11588 * "When in Self Refresh Big FIFO mode, a write to enable the
11589 * plane will be internally buffered and delayed while Big FIFO
11590 * mode is exiting."
11592 * Which means that enabling the sprite can take an extra frame
11593 * when we start in big FIFO mode (LP1+). Thus we need to drop
11594 * down to LP0 and wait for vblank in order to make sure the
11595 * sprite gets enabled on the next vblank after the register write.
11596 * Doing otherwise would risk enabling the sprite one frame after
11597 * we've already signalled flip completion. We can resume LP1+
11598 * once the sprite has been enabled.
11601 * WaCxSRDisabledForSpriteScaling:ivb
11602 * IVB SPR_SCALE/Scaling Enable
11603 * "Low Power watermarks must be disabled for at least one
11604 * frame before enabling sprite scaling, and kept disabled
11605 * until sprite scaling is disabled."
11607 * ILK/SNB DVSASCALE/Scaling Enable
11608 * "When in Self Refresh Big FIFO mode, scaling enable will be
11609 * masked off while Big FIFO mode is exiting."
11611 * Despite the w/a only being listed for IVB we assume that
11612 * the ILK/SNB note has similar ramifications, hence we apply
11613 * the w/a on all three platforms.
11615 * With experimental results seems this is needed also for primary
11616 * plane, not only sprite plane.
11618 if (plane->id != PLANE_CURSOR &&
11619 (IS_GEN_RANGE(dev_priv, 5, 6) ||
11620 IS_IVYBRIDGE(dev_priv)) &&
11621 (turn_on || (!needs_scaling(old_plane_state) &&
11622 needs_scaling(plane_state))))
11623 crtc_state->disable_lp_wm = true;
11628 static bool encoders_cloneable(const struct intel_encoder *a,
11629 const struct intel_encoder *b)
11631 /* masks could be asymmetric, so check both ways */
11632 return a == b || (a->cloneable & (1 << b->type) &&
11633 b->cloneable & (1 << a->type));
11636 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
11637 struct intel_crtc *crtc,
11638 struct intel_encoder *encoder)
11640 struct intel_encoder *source_encoder;
11641 struct drm_connector *connector;
11642 struct drm_connector_state *connector_state;
11645 for_each_new_connector_in_state(state, connector, connector_state, i) {
11646 if (connector_state->crtc != &crtc->base)
11650 to_intel_encoder(connector_state->best_encoder);
11651 if (!encoders_cloneable(encoder, source_encoder))
11658 static int icl_add_linked_planes(struct intel_atomic_state *state)
11660 struct intel_plane *plane, *linked;
11661 struct intel_plane_state *plane_state, *linked_plane_state;
11664 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11665 linked = plane_state->linked_plane;
11670 linked_plane_state = intel_atomic_get_plane_state(state, linked);
11671 if (IS_ERR(linked_plane_state))
11672 return PTR_ERR(linked_plane_state);
11674 WARN_ON(linked_plane_state->linked_plane != plane);
11675 WARN_ON(linked_plane_state->slave == plane_state->slave);
11681 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
11683 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
11684 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11685 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state);
11686 struct intel_plane *plane, *linked;
11687 struct intel_plane_state *plane_state;
11690 if (INTEL_GEN(dev_priv) < 11)
11694 * Destroy all old plane links and make the slave plane invisible
11695 * in the crtc_state->active_planes mask.
11697 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11698 if (plane->pipe != crtc->pipe || !plane_state->linked_plane)
11701 plane_state->linked_plane = NULL;
11702 if (plane_state->slave && !plane_state->base.visible) {
11703 crtc_state->active_planes &= ~BIT(plane->id);
11704 crtc_state->update_planes |= BIT(plane->id);
11707 plane_state->slave = false;
11710 if (!crtc_state->nv12_planes)
11713 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11714 struct intel_plane_state *linked_state = NULL;
11716 if (plane->pipe != crtc->pipe ||
11717 !(crtc_state->nv12_planes & BIT(plane->id)))
11720 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
11721 if (!icl_is_nv12_y_plane(linked->id))
11724 if (crtc_state->active_planes & BIT(linked->id))
11727 linked_state = intel_atomic_get_plane_state(state, linked);
11728 if (IS_ERR(linked_state))
11729 return PTR_ERR(linked_state);
11734 if (!linked_state) {
11735 DRM_DEBUG_KMS("Need %d free Y planes for planar YUV\n",
11736 hweight8(crtc_state->nv12_planes));
11741 plane_state->linked_plane = linked;
11743 linked_state->slave = true;
11744 linked_state->linked_plane = plane;
11745 crtc_state->active_planes |= BIT(linked->id);
11746 crtc_state->update_planes |= BIT(linked->id);
11747 DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name);
11753 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
11755 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
11756 struct intel_atomic_state *state =
11757 to_intel_atomic_state(new_crtc_state->base.state);
11758 const struct intel_crtc_state *old_crtc_state =
11759 intel_atomic_get_old_crtc_state(state, crtc);
11761 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
11764 static int intel_crtc_atomic_check(struct drm_crtc *crtc,
11765 struct drm_crtc_state *crtc_state)
11767 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
11768 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11769 struct intel_crtc_state *pipe_config =
11770 to_intel_crtc_state(crtc_state);
11772 bool mode_changed = needs_modeset(pipe_config);
11774 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv) &&
11775 mode_changed && !crtc_state->active)
11776 pipe_config->update_wm_post = true;
11778 if (mode_changed && crtc_state->enable &&
11779 dev_priv->display.crtc_compute_clock &&
11780 !WARN_ON(pipe_config->shared_dpll)) {
11781 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
11788 * May need to update pipe gamma enable bits
11789 * when C8 planes are getting enabled/disabled.
11791 if (c8_planes_changed(pipe_config))
11792 crtc_state->color_mgmt_changed = true;
11794 if (mode_changed || pipe_config->update_pipe ||
11795 crtc_state->color_mgmt_changed) {
11796 ret = intel_color_check(pipe_config);
11802 if (dev_priv->display.compute_pipe_wm) {
11803 ret = dev_priv->display.compute_pipe_wm(pipe_config);
11805 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
11810 if (dev_priv->display.compute_intermediate_wm) {
11811 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
11815 * Calculate 'intermediate' watermarks that satisfy both the
11816 * old state and the new state. We can program these
11819 ret = dev_priv->display.compute_intermediate_wm(pipe_config);
11821 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
11826 if (INTEL_GEN(dev_priv) >= 9) {
11827 if (mode_changed || pipe_config->update_pipe)
11828 ret = skl_update_scaler_crtc(pipe_config);
11831 ret = icl_check_nv12_planes(pipe_config);
11833 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
11836 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
11840 if (HAS_IPS(dev_priv))
11841 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
11846 static const struct drm_crtc_helper_funcs intel_helper_funcs = {
11847 .atomic_check = intel_crtc_atomic_check,
11850 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
11852 struct intel_connector *connector;
11853 struct drm_connector_list_iter conn_iter;
11855 drm_connector_list_iter_begin(dev, &conn_iter);
11856 for_each_intel_connector_iter(connector, &conn_iter) {
11857 if (connector->base.state->crtc)
11858 drm_connector_put(&connector->base);
11860 if (connector->base.encoder) {
11861 connector->base.state->best_encoder =
11862 connector->base.encoder;
11863 connector->base.state->crtc =
11864 connector->base.encoder->crtc;
11866 drm_connector_get(&connector->base);
11868 connector->base.state->best_encoder = NULL;
11869 connector->base.state->crtc = NULL;
11872 drm_connector_list_iter_end(&conn_iter);
11876 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
11877 struct intel_crtc_state *pipe_config)
11879 struct drm_connector *connector = conn_state->connector;
11880 const struct drm_display_info *info = &connector->display_info;
11883 switch (conn_state->max_bpc) {
11900 if (bpp < pipe_config->pipe_bpp) {
11901 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
11902 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
11903 connector->base.id, connector->name,
11904 bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc,
11905 pipe_config->pipe_bpp);
11907 pipe_config->pipe_bpp = bpp;
11914 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
11915 struct intel_crtc_state *pipe_config)
11917 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11918 struct drm_atomic_state *state = pipe_config->base.state;
11919 struct drm_connector *connector;
11920 struct drm_connector_state *connector_state;
11923 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
11924 IS_CHERRYVIEW(dev_priv)))
11926 else if (INTEL_GEN(dev_priv) >= 5)
11931 pipe_config->pipe_bpp = bpp;
11933 /* Clamp display bpp to connector max bpp */
11934 for_each_new_connector_in_state(state, connector, connector_state, i) {
11937 if (connector_state->crtc != &crtc->base)
11940 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
11948 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
11950 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11951 "type: 0x%x flags: 0x%x\n",
11953 mode->crtc_hdisplay, mode->crtc_hsync_start,
11954 mode->crtc_hsync_end, mode->crtc_htotal,
11955 mode->crtc_vdisplay, mode->crtc_vsync_start,
11956 mode->crtc_vsync_end, mode->crtc_vtotal,
11957 mode->type, mode->flags);
11961 intel_dump_m_n_config(const struct intel_crtc_state *pipe_config,
11962 const char *id, unsigned int lane_count,
11963 const struct intel_link_m_n *m_n)
11965 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11967 m_n->gmch_m, m_n->gmch_n,
11968 m_n->link_m, m_n->link_n, m_n->tu);
11972 intel_dump_infoframe(struct drm_i915_private *dev_priv,
11973 const union hdmi_infoframe *frame)
11975 if ((drm_debug & DRM_UT_KMS) == 0)
11978 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, frame);
11981 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
11983 static const char * const output_type_str[] = {
11984 OUTPUT_TYPE(UNUSED),
11985 OUTPUT_TYPE(ANALOG),
11989 OUTPUT_TYPE(TVOUT),
11995 OUTPUT_TYPE(DP_MST),
12000 static void snprintf_output_types(char *buf, size_t len,
12001 unsigned int output_types)
12008 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
12011 if ((output_types & BIT(i)) == 0)
12014 r = snprintf(str, len, "%s%s",
12015 str != buf ? "," : "", output_type_str[i]);
12021 output_types &= ~BIT(i);
12024 WARN_ON_ONCE(output_types != 0);
12027 static const char * const output_format_str[] = {
12028 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
12029 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
12030 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
12031 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
12034 static const char *output_formats(enum intel_output_format format)
12036 if (format >= ARRAY_SIZE(output_format_str))
12037 format = INTEL_OUTPUT_FORMAT_INVALID;
12038 return output_format_str[format];
12041 static void intel_dump_plane_state(const struct intel_plane_state *plane_state)
12043 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
12044 const struct drm_framebuffer *fb = plane_state->base.fb;
12045 struct drm_format_name_buf format_name;
12048 DRM_DEBUG_KMS("[PLANE:%d:%s] fb: [NOFB], visible: %s\n",
12049 plane->base.base.id, plane->base.name,
12050 yesno(plane_state->base.visible));
12054 DRM_DEBUG_KMS("[PLANE:%d:%s] fb: [FB:%d] %ux%u format = %s, visible: %s\n",
12055 plane->base.base.id, plane->base.name,
12056 fb->base.id, fb->width, fb->height,
12057 drm_get_format_name(fb->format->format, &format_name),
12058 yesno(plane_state->base.visible));
12059 DRM_DEBUG_KMS("\trotation: 0x%x, scaler: %d\n",
12060 plane_state->base.rotation, plane_state->scaler_id);
12061 if (plane_state->base.visible)
12062 DRM_DEBUG_KMS("\tsrc: " DRM_RECT_FP_FMT " dst: " DRM_RECT_FMT "\n",
12063 DRM_RECT_FP_ARG(&plane_state->base.src),
12064 DRM_RECT_ARG(&plane_state->base.dst));
12067 static void intel_dump_pipe_config(const struct intel_crtc_state *pipe_config,
12068 struct intel_atomic_state *state,
12069 const char *context)
12071 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
12072 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12073 const struct intel_plane_state *plane_state;
12074 struct intel_plane *plane;
12078 DRM_DEBUG_KMS("[CRTC:%d:%s] enable: %s %s\n",
12079 crtc->base.base.id, crtc->base.name,
12080 yesno(pipe_config->base.enable), context);
12082 if (!pipe_config->base.enable)
12085 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
12086 DRM_DEBUG_KMS("active: %s, output_types: %s (0x%x), output format: %s\n",
12087 yesno(pipe_config->base.active),
12088 buf, pipe_config->output_types,
12089 output_formats(pipe_config->output_format));
12091 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
12092 transcoder_name(pipe_config->cpu_transcoder),
12093 pipe_config->pipe_bpp, pipe_config->dither);
12095 if (pipe_config->has_pch_encoder)
12096 intel_dump_m_n_config(pipe_config, "fdi",
12097 pipe_config->fdi_lanes,
12098 &pipe_config->fdi_m_n);
12100 if (intel_crtc_has_dp_encoder(pipe_config)) {
12101 intel_dump_m_n_config(pipe_config, "dp m_n",
12102 pipe_config->lane_count, &pipe_config->dp_m_n);
12103 if (pipe_config->has_drrs)
12104 intel_dump_m_n_config(pipe_config, "dp m2_n2",
12105 pipe_config->lane_count,
12106 &pipe_config->dp_m2_n2);
12109 DRM_DEBUG_KMS("audio: %i, infoframes: %i, infoframes enabled: 0x%x\n",
12110 pipe_config->has_audio, pipe_config->has_infoframe,
12111 pipe_config->infoframes.enable);
12113 if (pipe_config->infoframes.enable &
12114 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GENERAL_CONTROL))
12115 DRM_DEBUG_KMS("GCP: 0x%x\n", pipe_config->infoframes.gcp);
12116 if (pipe_config->infoframes.enable &
12117 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI))
12118 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.avi);
12119 if (pipe_config->infoframes.enable &
12120 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_SPD))
12121 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.spd);
12122 if (pipe_config->infoframes.enable &
12123 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_VENDOR))
12124 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.hdmi);
12126 DRM_DEBUG_KMS("requested mode:\n");
12127 drm_mode_debug_printmodeline(&pipe_config->base.mode);
12128 DRM_DEBUG_KMS("adjusted mode:\n");
12129 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
12130 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
12131 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
12132 pipe_config->port_clock,
12133 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
12134 pipe_config->pixel_rate);
12136 if (INTEL_GEN(dev_priv) >= 9)
12137 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
12139 pipe_config->scaler_state.scaler_users,
12140 pipe_config->scaler_state.scaler_id);
12142 if (HAS_GMCH(dev_priv))
12143 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
12144 pipe_config->gmch_pfit.control,
12145 pipe_config->gmch_pfit.pgm_ratios,
12146 pipe_config->gmch_pfit.lvds_border_bits);
12148 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s, force thru: %s\n",
12149 pipe_config->pch_pfit.pos,
12150 pipe_config->pch_pfit.size,
12151 enableddisabled(pipe_config->pch_pfit.enabled),
12152 yesno(pipe_config->pch_pfit.force_thru));
12154 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
12155 pipe_config->ips_enabled, pipe_config->double_wide);
12157 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
12163 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12164 if (plane->pipe == crtc->pipe)
12165 intel_dump_plane_state(plane_state);
12169 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
12171 struct drm_device *dev = state->base.dev;
12172 struct drm_connector *connector;
12173 struct drm_connector_list_iter conn_iter;
12174 unsigned int used_ports = 0;
12175 unsigned int used_mst_ports = 0;
12179 * Walk the connector list instead of the encoder
12180 * list to detect the problem on ddi platforms
12181 * where there's just one encoder per digital port.
12183 drm_connector_list_iter_begin(dev, &conn_iter);
12184 drm_for_each_connector_iter(connector, &conn_iter) {
12185 struct drm_connector_state *connector_state;
12186 struct intel_encoder *encoder;
12189 drm_atomic_get_new_connector_state(&state->base,
12191 if (!connector_state)
12192 connector_state = connector->state;
12194 if (!connector_state->best_encoder)
12197 encoder = to_intel_encoder(connector_state->best_encoder);
12199 WARN_ON(!connector_state->crtc);
12201 switch (encoder->type) {
12202 unsigned int port_mask;
12203 case INTEL_OUTPUT_DDI:
12204 if (WARN_ON(!HAS_DDI(to_i915(dev))))
12206 /* else, fall through */
12207 case INTEL_OUTPUT_DP:
12208 case INTEL_OUTPUT_HDMI:
12209 case INTEL_OUTPUT_EDP:
12210 port_mask = 1 << encoder->port;
12212 /* the same port mustn't appear more than once */
12213 if (used_ports & port_mask)
12216 used_ports |= port_mask;
12218 case INTEL_OUTPUT_DP_MST:
12220 1 << encoder->port;
12226 drm_connector_list_iter_end(&conn_iter);
12228 /* can't mix MST and SST/HDMI on the same port */
12229 if (used_ports & used_mst_ports)
12236 clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
12238 struct drm_i915_private *dev_priv =
12239 to_i915(crtc_state->base.crtc->dev);
12240 struct intel_crtc_state *saved_state;
12242 saved_state = kzalloc(sizeof(*saved_state), GFP_KERNEL);
12246 /* FIXME: before the switch to atomic started, a new pipe_config was
12247 * kzalloc'd. Code that depends on any field being zero should be
12248 * fixed, so that the crtc_state can be safely duplicated. For now,
12249 * only fields that are know to not cause problems are preserved. */
12251 saved_state->scaler_state = crtc_state->scaler_state;
12252 saved_state->shared_dpll = crtc_state->shared_dpll;
12253 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
12254 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
12255 sizeof(saved_state->icl_port_dplls));
12256 saved_state->crc_enabled = crtc_state->crc_enabled;
12257 if (IS_G4X(dev_priv) ||
12258 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
12259 saved_state->wm = crtc_state->wm;
12261 /* Keep base drm_crtc_state intact, only clear our extended struct */
12262 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
12263 memcpy(&crtc_state->base + 1, &saved_state->base + 1,
12264 sizeof(*crtc_state) - sizeof(crtc_state->base));
12266 kfree(saved_state);
12271 intel_modeset_pipe_config(struct intel_crtc_state *pipe_config)
12273 struct drm_crtc *crtc = pipe_config->base.crtc;
12274 struct drm_atomic_state *state = pipe_config->base.state;
12275 struct intel_encoder *encoder;
12276 struct drm_connector *connector;
12277 struct drm_connector_state *connector_state;
12282 ret = clear_intel_crtc_state(pipe_config);
12286 pipe_config->cpu_transcoder =
12287 (enum transcoder) to_intel_crtc(crtc)->pipe;
12290 * Sanitize sync polarity flags based on requested ones. If neither
12291 * positive or negative polarity is requested, treat this as meaning
12292 * negative polarity.
12294 if (!(pipe_config->base.adjusted_mode.flags &
12295 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
12296 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
12298 if (!(pipe_config->base.adjusted_mode.flags &
12299 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
12300 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
12302 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
12307 base_bpp = pipe_config->pipe_bpp;
12310 * Determine the real pipe dimensions. Note that stereo modes can
12311 * increase the actual pipe size due to the frame doubling and
12312 * insertion of additional space for blanks between the frame. This
12313 * is stored in the crtc timings. We use the requested mode to do this
12314 * computation to clearly distinguish it from the adjusted mode, which
12315 * can be changed by the connectors in the below retry loop.
12317 drm_mode_get_hv_timing(&pipe_config->base.mode,
12318 &pipe_config->pipe_src_w,
12319 &pipe_config->pipe_src_h);
12321 for_each_new_connector_in_state(state, connector, connector_state, i) {
12322 if (connector_state->crtc != crtc)
12325 encoder = to_intel_encoder(connector_state->best_encoder);
12327 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
12328 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
12333 * Determine output_types before calling the .compute_config()
12334 * hooks so that the hooks can use this information safely.
12336 if (encoder->compute_output_type)
12337 pipe_config->output_types |=
12338 BIT(encoder->compute_output_type(encoder, pipe_config,
12341 pipe_config->output_types |= BIT(encoder->type);
12345 /* Ensure the port clock defaults are reset when retrying. */
12346 pipe_config->port_clock = 0;
12347 pipe_config->pixel_multiplier = 1;
12349 /* Fill in default crtc timings, allow encoders to overwrite them. */
12350 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
12351 CRTC_STEREO_DOUBLE);
12353 /* Pass our mode to the connectors and the CRTC to give them a chance to
12354 * adjust it according to limitations or connector properties, and also
12355 * a chance to reject the mode entirely.
12357 for_each_new_connector_in_state(state, connector, connector_state, i) {
12358 if (connector_state->crtc != crtc)
12361 encoder = to_intel_encoder(connector_state->best_encoder);
12362 ret = encoder->compute_config(encoder, pipe_config,
12365 if (ret != -EDEADLK)
12366 DRM_DEBUG_KMS("Encoder config failure: %d\n",
12372 /* Set default port clock if not overwritten by the encoder. Needs to be
12373 * done afterwards in case the encoder adjusts the mode. */
12374 if (!pipe_config->port_clock)
12375 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
12376 * pipe_config->pixel_multiplier;
12378 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
12379 if (ret == -EDEADLK)
12382 DRM_DEBUG_KMS("CRTC fixup failed\n");
12386 if (ret == RETRY) {
12387 if (WARN(!retry, "loop in pipe configuration computation\n"))
12390 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
12392 goto encoder_retry;
12395 /* Dithering seems to not pass-through bits correctly when it should, so
12396 * only enable it on 6bpc panels and when its not a compliance
12397 * test requesting 6bpc video pattern.
12399 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
12400 !pipe_config->dither_force_disable;
12401 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
12402 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
12407 bool intel_fuzzy_clock_check(int clock1, int clock2)
12411 if (clock1 == clock2)
12414 if (!clock1 || !clock2)
12417 diff = abs(clock1 - clock2);
12419 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
12426 intel_compare_m_n(unsigned int m, unsigned int n,
12427 unsigned int m2, unsigned int n2,
12430 if (m == m2 && n == n2)
12433 if (exact || !m || !n || !m2 || !n2)
12436 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
12443 } else if (n < n2) {
12453 return intel_fuzzy_clock_check(m, m2);
12457 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
12458 const struct intel_link_m_n *m2_n2,
12461 return m_n->tu == m2_n2->tu &&
12462 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
12463 m2_n2->gmch_m, m2_n2->gmch_n, exact) &&
12464 intel_compare_m_n(m_n->link_m, m_n->link_n,
12465 m2_n2->link_m, m2_n2->link_n, exact);
12469 intel_compare_infoframe(const union hdmi_infoframe *a,
12470 const union hdmi_infoframe *b)
12472 return memcmp(a, b, sizeof(*a)) == 0;
12476 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
12477 bool fastset, const char *name,
12478 const union hdmi_infoframe *a,
12479 const union hdmi_infoframe *b)
12482 if ((drm_debug & DRM_UT_KMS) == 0)
12485 drm_dbg(DRM_UT_KMS, "fastset mismatch in %s infoframe", name);
12486 drm_dbg(DRM_UT_KMS, "expected:");
12487 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
12488 drm_dbg(DRM_UT_KMS, "found");
12489 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
12491 drm_err("mismatch in %s infoframe", name);
12492 drm_err("expected:");
12493 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
12495 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
12499 static void __printf(3, 4)
12500 pipe_config_mismatch(bool fastset, const char *name, const char *format, ...)
12502 struct va_format vaf;
12505 va_start(args, format);
12510 drm_dbg(DRM_UT_KMS, "fastset mismatch in %s %pV", name, &vaf);
12512 drm_err("mismatch in %s %pV", name, &vaf);
12517 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
12519 if (i915_modparams.fastboot != -1)
12520 return i915_modparams.fastboot;
12522 /* Enable fastboot by default on Skylake and newer */
12523 if (INTEL_GEN(dev_priv) >= 9)
12526 /* Enable fastboot by default on VLV and CHV */
12527 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
12530 /* Disabled by default on all others */
12535 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
12536 const struct intel_crtc_state *pipe_config,
12539 struct drm_i915_private *dev_priv = to_i915(current_config->base.crtc->dev);
12541 bool fixup_inherited = fastset &&
12542 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
12543 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
12545 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
12546 DRM_DEBUG_KMS("initial modeset and fastboot not set\n");
12550 #define PIPE_CONF_CHECK_X(name) do { \
12551 if (current_config->name != pipe_config->name) { \
12552 pipe_config_mismatch(fastset, __stringify(name), \
12553 "(expected 0x%08x, found 0x%08x)\n", \
12554 current_config->name, \
12555 pipe_config->name); \
12560 #define PIPE_CONF_CHECK_I(name) do { \
12561 if (current_config->name != pipe_config->name) { \
12562 pipe_config_mismatch(fastset, __stringify(name), \
12563 "(expected %i, found %i)\n", \
12564 current_config->name, \
12565 pipe_config->name); \
12570 #define PIPE_CONF_CHECK_BOOL(name) do { \
12571 if (current_config->name != pipe_config->name) { \
12572 pipe_config_mismatch(fastset, __stringify(name), \
12573 "(expected %s, found %s)\n", \
12574 yesno(current_config->name), \
12575 yesno(pipe_config->name)); \
12581 * Checks state where we only read out the enabling, but not the entire
12582 * state itself (like full infoframes or ELD for audio). These states
12583 * require a full modeset on bootup to fix up.
12585 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
12586 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
12587 PIPE_CONF_CHECK_BOOL(name); \
12589 pipe_config_mismatch(fastset, __stringify(name), \
12590 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
12591 yesno(current_config->name), \
12592 yesno(pipe_config->name)); \
12597 #define PIPE_CONF_CHECK_P(name) do { \
12598 if (current_config->name != pipe_config->name) { \
12599 pipe_config_mismatch(fastset, __stringify(name), \
12600 "(expected %p, found %p)\n", \
12601 current_config->name, \
12602 pipe_config->name); \
12607 #define PIPE_CONF_CHECK_M_N(name) do { \
12608 if (!intel_compare_link_m_n(¤t_config->name, \
12609 &pipe_config->name,\
12611 pipe_config_mismatch(fastset, __stringify(name), \
12612 "(expected tu %i gmch %i/%i link %i/%i, " \
12613 "found tu %i, gmch %i/%i link %i/%i)\n", \
12614 current_config->name.tu, \
12615 current_config->name.gmch_m, \
12616 current_config->name.gmch_n, \
12617 current_config->name.link_m, \
12618 current_config->name.link_n, \
12619 pipe_config->name.tu, \
12620 pipe_config->name.gmch_m, \
12621 pipe_config->name.gmch_n, \
12622 pipe_config->name.link_m, \
12623 pipe_config->name.link_n); \
12628 /* This is required for BDW+ where there is only one set of registers for
12629 * switching between high and low RR.
12630 * This macro can be used whenever a comparison has to be made between one
12631 * hw state and multiple sw state variables.
12633 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
12634 if (!intel_compare_link_m_n(¤t_config->name, \
12635 &pipe_config->name, !fastset) && \
12636 !intel_compare_link_m_n(¤t_config->alt_name, \
12637 &pipe_config->name, !fastset)) { \
12638 pipe_config_mismatch(fastset, __stringify(name), \
12639 "(expected tu %i gmch %i/%i link %i/%i, " \
12640 "or tu %i gmch %i/%i link %i/%i, " \
12641 "found tu %i, gmch %i/%i link %i/%i)\n", \
12642 current_config->name.tu, \
12643 current_config->name.gmch_m, \
12644 current_config->name.gmch_n, \
12645 current_config->name.link_m, \
12646 current_config->name.link_n, \
12647 current_config->alt_name.tu, \
12648 current_config->alt_name.gmch_m, \
12649 current_config->alt_name.gmch_n, \
12650 current_config->alt_name.link_m, \
12651 current_config->alt_name.link_n, \
12652 pipe_config->name.tu, \
12653 pipe_config->name.gmch_m, \
12654 pipe_config->name.gmch_n, \
12655 pipe_config->name.link_m, \
12656 pipe_config->name.link_n); \
12661 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
12662 if ((current_config->name ^ pipe_config->name) & (mask)) { \
12663 pipe_config_mismatch(fastset, __stringify(name), \
12664 "(%x) (expected %i, found %i)\n", \
12666 current_config->name & (mask), \
12667 pipe_config->name & (mask)); \
12672 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
12673 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
12674 pipe_config_mismatch(fastset, __stringify(name), \
12675 "(expected %i, found %i)\n", \
12676 current_config->name, \
12677 pipe_config->name); \
12682 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
12683 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
12684 &pipe_config->infoframes.name)) { \
12685 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
12686 ¤t_config->infoframes.name, \
12687 &pipe_config->infoframes.name); \
12692 #define PIPE_CONF_QUIRK(quirk) \
12693 ((current_config->quirks | pipe_config->quirks) & (quirk))
12695 PIPE_CONF_CHECK_I(cpu_transcoder);
12697 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
12698 PIPE_CONF_CHECK_I(fdi_lanes);
12699 PIPE_CONF_CHECK_M_N(fdi_m_n);
12701 PIPE_CONF_CHECK_I(lane_count);
12702 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
12704 if (INTEL_GEN(dev_priv) < 8) {
12705 PIPE_CONF_CHECK_M_N(dp_m_n);
12707 if (current_config->has_drrs)
12708 PIPE_CONF_CHECK_M_N(dp_m2_n2);
12710 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
12712 PIPE_CONF_CHECK_X(output_types);
12714 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
12715 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
12716 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
12717 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
12718 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
12719 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
12721 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
12722 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
12723 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
12724 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
12725 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
12726 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
12728 PIPE_CONF_CHECK_I(pixel_multiplier);
12729 PIPE_CONF_CHECK_I(output_format);
12730 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
12731 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
12732 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
12733 PIPE_CONF_CHECK_BOOL(limited_color_range);
12735 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
12736 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
12737 PIPE_CONF_CHECK_BOOL(has_infoframe);
12739 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
12741 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12742 DRM_MODE_FLAG_INTERLACE);
12744 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
12745 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12746 DRM_MODE_FLAG_PHSYNC);
12747 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12748 DRM_MODE_FLAG_NHSYNC);
12749 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12750 DRM_MODE_FLAG_PVSYNC);
12751 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12752 DRM_MODE_FLAG_NVSYNC);
12755 PIPE_CONF_CHECK_X(gmch_pfit.control);
12756 /* pfit ratios are autocomputed by the hw on gen4+ */
12757 if (INTEL_GEN(dev_priv) < 4)
12758 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
12759 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
12762 * Changing the EDP transcoder input mux
12763 * (A_ONOFF vs. A_ON) requires a full modeset.
12765 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
12768 PIPE_CONF_CHECK_I(pipe_src_w);
12769 PIPE_CONF_CHECK_I(pipe_src_h);
12771 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
12772 if (current_config->pch_pfit.enabled) {
12773 PIPE_CONF_CHECK_X(pch_pfit.pos);
12774 PIPE_CONF_CHECK_X(pch_pfit.size);
12777 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
12778 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
12780 PIPE_CONF_CHECK_X(gamma_mode);
12781 if (IS_CHERRYVIEW(dev_priv))
12782 PIPE_CONF_CHECK_X(cgm_mode);
12784 PIPE_CONF_CHECK_X(csc_mode);
12785 PIPE_CONF_CHECK_BOOL(gamma_enable);
12786 PIPE_CONF_CHECK_BOOL(csc_enable);
12789 PIPE_CONF_CHECK_BOOL(double_wide);
12791 PIPE_CONF_CHECK_P(shared_dpll);
12792 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
12793 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
12794 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
12795 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
12796 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
12797 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
12798 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
12799 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
12800 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
12801 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
12802 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
12803 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
12804 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
12805 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
12806 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
12807 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
12808 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
12809 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
12810 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
12811 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
12812 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
12813 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
12814 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
12815 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
12816 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
12817 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
12818 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
12819 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
12820 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
12821 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
12822 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
12824 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
12825 PIPE_CONF_CHECK_X(dsi_pll.div);
12827 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
12828 PIPE_CONF_CHECK_I(pipe_bpp);
12830 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
12831 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
12833 PIPE_CONF_CHECK_I(min_voltage_level);
12835 PIPE_CONF_CHECK_X(infoframes.enable);
12836 PIPE_CONF_CHECK_X(infoframes.gcp);
12837 PIPE_CONF_CHECK_INFOFRAME(avi);
12838 PIPE_CONF_CHECK_INFOFRAME(spd);
12839 PIPE_CONF_CHECK_INFOFRAME(hdmi);
12840 PIPE_CONF_CHECK_INFOFRAME(drm);
12842 #undef PIPE_CONF_CHECK_X
12843 #undef PIPE_CONF_CHECK_I
12844 #undef PIPE_CONF_CHECK_BOOL
12845 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
12846 #undef PIPE_CONF_CHECK_P
12847 #undef PIPE_CONF_CHECK_FLAGS
12848 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
12849 #undef PIPE_CONF_QUIRK
12854 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
12855 const struct intel_crtc_state *pipe_config)
12857 if (pipe_config->has_pch_encoder) {
12858 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
12859 &pipe_config->fdi_m_n);
12860 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
12863 * FDI already provided one idea for the dotclock.
12864 * Yell if the encoder disagrees.
12866 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
12867 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
12868 fdi_dotclock, dotclock);
12872 static void verify_wm_state(struct intel_crtc *crtc,
12873 struct intel_crtc_state *new_crtc_state)
12875 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12876 struct skl_hw_state {
12877 struct skl_ddb_entry ddb_y[I915_MAX_PLANES];
12878 struct skl_ddb_entry ddb_uv[I915_MAX_PLANES];
12879 struct skl_ddb_allocation ddb;
12880 struct skl_pipe_wm wm;
12882 struct skl_ddb_allocation *sw_ddb;
12883 struct skl_pipe_wm *sw_wm;
12884 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
12885 const enum pipe pipe = crtc->pipe;
12886 int plane, level, max_level = ilk_wm_max_level(dev_priv);
12888 if (INTEL_GEN(dev_priv) < 9 || !new_crtc_state->base.active)
12891 hw = kzalloc(sizeof(*hw), GFP_KERNEL);
12895 skl_pipe_wm_get_hw_state(crtc, &hw->wm);
12896 sw_wm = &new_crtc_state->wm.skl.optimal;
12898 skl_pipe_ddb_get_hw_state(crtc, hw->ddb_y, hw->ddb_uv);
12900 skl_ddb_get_hw_state(dev_priv, &hw->ddb);
12901 sw_ddb = &dev_priv->wm.skl_hw.ddb;
12903 if (INTEL_GEN(dev_priv) >= 11 &&
12904 hw->ddb.enabled_slices != sw_ddb->enabled_slices)
12905 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
12906 sw_ddb->enabled_slices,
12907 hw->ddb.enabled_slices);
12910 for_each_universal_plane(dev_priv, pipe, plane) {
12911 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
12913 hw_plane_wm = &hw->wm.planes[plane];
12914 sw_plane_wm = &sw_wm->planes[plane];
12917 for (level = 0; level <= max_level; level++) {
12918 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
12919 &sw_plane_wm->wm[level]))
12922 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",
12923 pipe_name(pipe), plane + 1, level,
12924 sw_plane_wm->wm[level].plane_en,
12925 sw_plane_wm->wm[level].plane_res_b,
12926 sw_plane_wm->wm[level].plane_res_l,
12927 hw_plane_wm->wm[level].plane_en,
12928 hw_plane_wm->wm[level].plane_res_b,
12929 hw_plane_wm->wm[level].plane_res_l);
12932 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12933 &sw_plane_wm->trans_wm)) {
12934 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",
12935 pipe_name(pipe), plane + 1,
12936 sw_plane_wm->trans_wm.plane_en,
12937 sw_plane_wm->trans_wm.plane_res_b,
12938 sw_plane_wm->trans_wm.plane_res_l,
12939 hw_plane_wm->trans_wm.plane_en,
12940 hw_plane_wm->trans_wm.plane_res_b,
12941 hw_plane_wm->trans_wm.plane_res_l);
12945 hw_ddb_entry = &hw->ddb_y[plane];
12946 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[plane];
12948 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
12949 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
12950 pipe_name(pipe), plane + 1,
12951 sw_ddb_entry->start, sw_ddb_entry->end,
12952 hw_ddb_entry->start, hw_ddb_entry->end);
12958 * If the cursor plane isn't active, we may not have updated it's ddb
12959 * allocation. In that case since the ddb allocation will be updated
12960 * once the plane becomes visible, we can skip this check
12963 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
12965 hw_plane_wm = &hw->wm.planes[PLANE_CURSOR];
12966 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
12969 for (level = 0; level <= max_level; level++) {
12970 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
12971 &sw_plane_wm->wm[level]))
12974 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",
12975 pipe_name(pipe), level,
12976 sw_plane_wm->wm[level].plane_en,
12977 sw_plane_wm->wm[level].plane_res_b,
12978 sw_plane_wm->wm[level].plane_res_l,
12979 hw_plane_wm->wm[level].plane_en,
12980 hw_plane_wm->wm[level].plane_res_b,
12981 hw_plane_wm->wm[level].plane_res_l);
12984 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12985 &sw_plane_wm->trans_wm)) {
12986 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
12988 sw_plane_wm->trans_wm.plane_en,
12989 sw_plane_wm->trans_wm.plane_res_b,
12990 sw_plane_wm->trans_wm.plane_res_l,
12991 hw_plane_wm->trans_wm.plane_en,
12992 hw_plane_wm->trans_wm.plane_res_b,
12993 hw_plane_wm->trans_wm.plane_res_l);
12997 hw_ddb_entry = &hw->ddb_y[PLANE_CURSOR];
12998 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR];
13000 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
13001 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
13003 sw_ddb_entry->start, sw_ddb_entry->end,
13004 hw_ddb_entry->start, hw_ddb_entry->end);
13012 verify_connector_state(struct intel_atomic_state *state,
13013 struct intel_crtc *crtc)
13015 struct drm_connector *connector;
13016 struct drm_connector_state *new_conn_state;
13019 for_each_new_connector_in_state(&state->base, connector, new_conn_state, i) {
13020 struct drm_encoder *encoder = connector->encoder;
13021 struct intel_crtc_state *crtc_state = NULL;
13023 if (new_conn_state->crtc != &crtc->base)
13027 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
13029 intel_connector_verify_state(crtc_state, new_conn_state);
13031 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
13032 "connector's atomic encoder doesn't match legacy encoder\n");
13037 verify_encoder_state(struct drm_i915_private *dev_priv, struct intel_atomic_state *state)
13039 struct intel_encoder *encoder;
13040 struct drm_connector *connector;
13041 struct drm_connector_state *old_conn_state, *new_conn_state;
13044 for_each_intel_encoder(&dev_priv->drm, encoder) {
13045 bool enabled = false, found = false;
13048 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
13049 encoder->base.base.id,
13050 encoder->base.name);
13052 for_each_oldnew_connector_in_state(&state->base, connector, old_conn_state,
13053 new_conn_state, i) {
13054 if (old_conn_state->best_encoder == &encoder->base)
13057 if (new_conn_state->best_encoder != &encoder->base)
13059 found = enabled = true;
13061 I915_STATE_WARN(new_conn_state->crtc !=
13062 encoder->base.crtc,
13063 "connector's crtc doesn't match encoder crtc\n");
13069 I915_STATE_WARN(!!encoder->base.crtc != enabled,
13070 "encoder's enabled state mismatch "
13071 "(expected %i, found %i)\n",
13072 !!encoder->base.crtc, enabled);
13074 if (!encoder->base.crtc) {
13077 active = encoder->get_hw_state(encoder, &pipe);
13078 I915_STATE_WARN(active,
13079 "encoder detached but still enabled on pipe %c.\n",
13086 verify_crtc_state(struct intel_crtc *crtc,
13087 struct intel_crtc_state *old_crtc_state,
13088 struct intel_crtc_state *new_crtc_state)
13090 struct drm_device *dev = crtc->base.dev;
13091 struct drm_i915_private *dev_priv = to_i915(dev);
13092 struct intel_encoder *encoder;
13093 struct intel_crtc_state *pipe_config;
13094 struct drm_atomic_state *state;
13097 state = old_crtc_state->base.state;
13098 __drm_atomic_helper_crtc_destroy_state(&old_crtc_state->base);
13099 pipe_config = old_crtc_state;
13100 memset(pipe_config, 0, sizeof(*pipe_config));
13101 pipe_config->base.crtc = &crtc->base;
13102 pipe_config->base.state = state;
13104 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.base.id, crtc->base.name);
13106 active = dev_priv->display.get_pipe_config(crtc, pipe_config);
13108 /* we keep both pipes enabled on 830 */
13109 if (IS_I830(dev_priv))
13110 active = new_crtc_state->base.active;
13112 I915_STATE_WARN(new_crtc_state->base.active != active,
13113 "crtc active state doesn't match with hw state "
13114 "(expected %i, found %i)\n", new_crtc_state->base.active, active);
13116 I915_STATE_WARN(crtc->active != new_crtc_state->base.active,
13117 "transitional active state does not match atomic hw state "
13118 "(expected %i, found %i)\n", new_crtc_state->base.active, crtc->active);
13120 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
13123 active = encoder->get_hw_state(encoder, &pipe);
13124 I915_STATE_WARN(active != new_crtc_state->base.active,
13125 "[ENCODER:%i] active %i with crtc active %i\n",
13126 encoder->base.base.id, active, new_crtc_state->base.active);
13128 I915_STATE_WARN(active && crtc->pipe != pipe,
13129 "Encoder connected to wrong pipe %c\n",
13133 encoder->get_config(encoder, pipe_config);
13136 intel_crtc_compute_pixel_rate(pipe_config);
13138 if (!new_crtc_state->base.active)
13141 intel_pipe_config_sanity_check(dev_priv, pipe_config);
13143 if (!intel_pipe_config_compare(new_crtc_state,
13144 pipe_config, false)) {
13145 I915_STATE_WARN(1, "pipe state doesn't match!\n");
13146 intel_dump_pipe_config(pipe_config, NULL, "[hw state]");
13147 intel_dump_pipe_config(new_crtc_state, NULL, "[sw state]");
13152 intel_verify_planes(struct intel_atomic_state *state)
13154 struct intel_plane *plane;
13155 const struct intel_plane_state *plane_state;
13158 for_each_new_intel_plane_in_state(state, plane,
13160 assert_plane(plane, plane_state->slave ||
13161 plane_state->base.visible);
13165 verify_single_dpll_state(struct drm_i915_private *dev_priv,
13166 struct intel_shared_dpll *pll,
13167 struct intel_crtc *crtc,
13168 struct intel_crtc_state *new_crtc_state)
13170 struct intel_dpll_hw_state dpll_hw_state;
13171 unsigned int crtc_mask;
13174 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
13176 DRM_DEBUG_KMS("%s\n", pll->info->name);
13178 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
13180 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
13181 I915_STATE_WARN(!pll->on && pll->active_mask,
13182 "pll in active use but not on in sw tracking\n");
13183 I915_STATE_WARN(pll->on && !pll->active_mask,
13184 "pll is on but not used by any active crtc\n");
13185 I915_STATE_WARN(pll->on != active,
13186 "pll on state mismatch (expected %i, found %i)\n",
13191 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
13192 "more active pll users than references: %x vs %x\n",
13193 pll->active_mask, pll->state.crtc_mask);
13198 crtc_mask = drm_crtc_mask(&crtc->base);
13200 if (new_crtc_state->base.active)
13201 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
13202 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
13203 pipe_name(drm_crtc_index(&crtc->base)), pll->active_mask);
13205 I915_STATE_WARN(pll->active_mask & crtc_mask,
13206 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
13207 pipe_name(drm_crtc_index(&crtc->base)), pll->active_mask);
13209 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
13210 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
13211 crtc_mask, pll->state.crtc_mask);
13213 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
13215 sizeof(dpll_hw_state)),
13216 "pll hw state mismatch\n");
13220 verify_shared_dpll_state(struct intel_crtc *crtc,
13221 struct intel_crtc_state *old_crtc_state,
13222 struct intel_crtc_state *new_crtc_state)
13224 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13226 if (new_crtc_state->shared_dpll)
13227 verify_single_dpll_state(dev_priv, new_crtc_state->shared_dpll, crtc, new_crtc_state);
13229 if (old_crtc_state->shared_dpll &&
13230 old_crtc_state->shared_dpll != new_crtc_state->shared_dpll) {
13231 unsigned int crtc_mask = drm_crtc_mask(&crtc->base);
13232 struct intel_shared_dpll *pll = old_crtc_state->shared_dpll;
13234 I915_STATE_WARN(pll->active_mask & crtc_mask,
13235 "pll active mismatch (didn't expect pipe %c in active mask)\n",
13236 pipe_name(drm_crtc_index(&crtc->base)));
13237 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
13238 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
13239 pipe_name(drm_crtc_index(&crtc->base)));
13244 intel_modeset_verify_crtc(struct intel_crtc *crtc,
13245 struct intel_atomic_state *state,
13246 struct intel_crtc_state *old_crtc_state,
13247 struct intel_crtc_state *new_crtc_state)
13249 if (!needs_modeset(new_crtc_state) && !new_crtc_state->update_pipe)
13252 verify_wm_state(crtc, new_crtc_state);
13253 verify_connector_state(state, crtc);
13254 verify_crtc_state(crtc, old_crtc_state, new_crtc_state);
13255 verify_shared_dpll_state(crtc, old_crtc_state, new_crtc_state);
13259 verify_disabled_dpll_state(struct drm_i915_private *dev_priv)
13263 for (i = 0; i < dev_priv->num_shared_dpll; i++)
13264 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
13268 intel_modeset_verify_disabled(struct drm_i915_private *dev_priv,
13269 struct intel_atomic_state *state)
13271 verify_encoder_state(dev_priv, state);
13272 verify_connector_state(state, NULL);
13273 verify_disabled_dpll_state(dev_priv);
13276 static void update_scanline_offset(const struct intel_crtc_state *crtc_state)
13278 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
13279 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13282 * The scanline counter increments at the leading edge of hsync.
13284 * On most platforms it starts counting from vtotal-1 on the
13285 * first active line. That means the scanline counter value is
13286 * always one less than what we would expect. Ie. just after
13287 * start of vblank, which also occurs at start of hsync (on the
13288 * last active line), the scanline counter will read vblank_start-1.
13290 * On gen2 the scanline counter starts counting from 1 instead
13291 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
13292 * to keep the value positive), instead of adding one.
13294 * On HSW+ the behaviour of the scanline counter depends on the output
13295 * type. For DP ports it behaves like most other platforms, but on HDMI
13296 * there's an extra 1 line difference. So we need to add two instead of
13297 * one to the value.
13299 * On VLV/CHV DSI the scanline counter would appear to increment
13300 * approx. 1/3 of a scanline before start of vblank. Unfortunately
13301 * that means we can't tell whether we're in vblank or not while
13302 * we're on that particular line. We must still set scanline_offset
13303 * to 1 so that the vblank timestamps come out correct when we query
13304 * the scanline counter from within the vblank interrupt handler.
13305 * However if queried just before the start of vblank we'll get an
13306 * answer that's slightly in the future.
13308 if (IS_GEN(dev_priv, 2)) {
13309 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
13312 vtotal = adjusted_mode->crtc_vtotal;
13313 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
13316 crtc->scanline_offset = vtotal - 1;
13317 } else if (HAS_DDI(dev_priv) &&
13318 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
13319 crtc->scanline_offset = 2;
13321 crtc->scanline_offset = 1;
13324 static void intel_modeset_clear_plls(struct intel_atomic_state *state)
13326 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13327 struct intel_crtc_state *new_crtc_state;
13328 struct intel_crtc *crtc;
13331 if (!dev_priv->display.crtc_compute_clock)
13334 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
13335 if (!needs_modeset(new_crtc_state))
13338 intel_release_shared_dplls(state, crtc);
13343 * This implements the workaround described in the "notes" section of the mode
13344 * set sequence documentation. When going from no pipes or single pipe to
13345 * multiple pipes, and planes are enabled after the pipe, we need to wait at
13346 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
13348 static int haswell_mode_set_planes_workaround(struct intel_atomic_state *state)
13350 struct intel_crtc_state *crtc_state;
13351 struct intel_crtc *crtc;
13352 struct intel_crtc_state *first_crtc_state = NULL;
13353 struct intel_crtc_state *other_crtc_state = NULL;
13354 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
13357 /* look at all crtc's that are going to be enabled in during modeset */
13358 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
13359 if (!crtc_state->base.active ||
13360 !needs_modeset(crtc_state))
13363 if (first_crtc_state) {
13364 other_crtc_state = crtc_state;
13367 first_crtc_state = crtc_state;
13368 first_pipe = crtc->pipe;
13372 /* No workaround needed? */
13373 if (!first_crtc_state)
13376 /* w/a possibly needed, check how many crtc's are already enabled. */
13377 for_each_intel_crtc(state->base.dev, crtc) {
13378 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
13379 if (IS_ERR(crtc_state))
13380 return PTR_ERR(crtc_state);
13382 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
13384 if (!crtc_state->base.active ||
13385 needs_modeset(crtc_state))
13388 /* 2 or more enabled crtcs means no need for w/a */
13389 if (enabled_pipe != INVALID_PIPE)
13392 enabled_pipe = crtc->pipe;
13395 if (enabled_pipe != INVALID_PIPE)
13396 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
13397 else if (other_crtc_state)
13398 other_crtc_state->hsw_workaround_pipe = first_pipe;
13403 static int intel_lock_all_pipes(struct intel_atomic_state *state)
13405 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13406 struct intel_crtc *crtc;
13408 /* Add all pipes to the state */
13409 for_each_intel_crtc(&dev_priv->drm, crtc) {
13410 struct intel_crtc_state *crtc_state;
13412 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
13413 if (IS_ERR(crtc_state))
13414 return PTR_ERR(crtc_state);
13420 static int intel_modeset_all_pipes(struct intel_atomic_state *state)
13422 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13423 struct intel_crtc *crtc;
13426 * Add all pipes to the state, and force
13427 * a modeset on all the active ones.
13429 for_each_intel_crtc(&dev_priv->drm, crtc) {
13430 struct intel_crtc_state *crtc_state;
13433 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
13434 if (IS_ERR(crtc_state))
13435 return PTR_ERR(crtc_state);
13437 if (!crtc_state->base.active || needs_modeset(crtc_state))
13440 crtc_state->base.mode_changed = true;
13442 ret = drm_atomic_add_affected_connectors(&state->base,
13447 ret = drm_atomic_add_affected_planes(&state->base,
13456 static int intel_modeset_checks(struct intel_atomic_state *state)
13458 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13459 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13460 struct intel_crtc *crtc;
13463 if (!check_digital_port_conflicts(state)) {
13464 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
13468 /* keep the current setting */
13469 if (!state->cdclk.force_min_cdclk_changed)
13470 state->cdclk.force_min_cdclk = dev_priv->cdclk.force_min_cdclk;
13472 state->modeset = true;
13473 state->active_crtcs = dev_priv->active_crtcs;
13474 state->cdclk.logical = dev_priv->cdclk.logical;
13475 state->cdclk.actual = dev_priv->cdclk.actual;
13476 state->cdclk.pipe = INVALID_PIPE;
13478 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13479 new_crtc_state, i) {
13480 if (new_crtc_state->base.active)
13481 state->active_crtcs |= 1 << i;
13483 state->active_crtcs &= ~(1 << i);
13485 if (old_crtc_state->base.active != new_crtc_state->base.active)
13486 state->active_pipe_changes |= drm_crtc_mask(&crtc->base);
13490 * See if the config requires any additional preparation, e.g.
13491 * to adjust global state with pipes off. We need to do this
13492 * here so we can get the modeset_pipe updated config for the new
13493 * mode set on this crtc. For other crtcs we need to use the
13494 * adjusted_mode bits in the crtc directly.
13496 if (dev_priv->display.modeset_calc_cdclk) {
13499 ret = dev_priv->display.modeset_calc_cdclk(state);
13504 * Writes to dev_priv->cdclk.logical must protected by
13505 * holding all the crtc locks, even if we don't end up
13506 * touching the hardware
13508 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
13509 &state->cdclk.logical)) {
13510 ret = intel_lock_all_pipes(state);
13515 if (is_power_of_2(state->active_crtcs)) {
13516 struct intel_crtc *crtc;
13517 struct intel_crtc_state *crtc_state;
13519 pipe = ilog2(state->active_crtcs);
13520 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
13521 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
13522 if (crtc_state && needs_modeset(crtc_state))
13523 pipe = INVALID_PIPE;
13525 pipe = INVALID_PIPE;
13528 /* All pipes must be switched off while we change the cdclk. */
13529 if (pipe != INVALID_PIPE &&
13530 intel_cdclk_needs_cd2x_update(dev_priv,
13531 &dev_priv->cdclk.actual,
13532 &state->cdclk.actual)) {
13533 ret = intel_lock_all_pipes(state);
13537 state->cdclk.pipe = pipe;
13538 } else if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
13539 &state->cdclk.actual)) {
13540 ret = intel_modeset_all_pipes(state);
13544 state->cdclk.pipe = INVALID_PIPE;
13547 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
13548 state->cdclk.logical.cdclk,
13549 state->cdclk.actual.cdclk);
13550 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
13551 state->cdclk.logical.voltage_level,
13552 state->cdclk.actual.voltage_level);
13555 intel_modeset_clear_plls(state);
13557 if (IS_HASWELL(dev_priv))
13558 return haswell_mode_set_planes_workaround(state);
13564 * Handle calculation of various watermark data at the end of the atomic check
13565 * phase. The code here should be run after the per-crtc and per-plane 'check'
13566 * handlers to ensure that all derived state has been updated.
13568 static int calc_watermark_data(struct intel_atomic_state *state)
13570 struct drm_device *dev = state->base.dev;
13571 struct drm_i915_private *dev_priv = to_i915(dev);
13573 /* Is there platform-specific watermark information to calculate? */
13574 if (dev_priv->display.compute_global_watermarks)
13575 return dev_priv->display.compute_global_watermarks(state);
13580 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
13581 struct intel_crtc_state *new_crtc_state)
13583 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
13586 new_crtc_state->base.mode_changed = false;
13587 new_crtc_state->update_pipe = true;
13590 * If we're not doing the full modeset we want to
13591 * keep the current M/N values as they may be
13592 * sufficiently different to the computed values
13593 * to cause problems.
13595 * FIXME: should really copy more fuzzy state here
13597 new_crtc_state->fdi_m_n = old_crtc_state->fdi_m_n;
13598 new_crtc_state->dp_m_n = old_crtc_state->dp_m_n;
13599 new_crtc_state->dp_m2_n2 = old_crtc_state->dp_m2_n2;
13600 new_crtc_state->has_drrs = old_crtc_state->has_drrs;
13604 * intel_atomic_check - validate state object
13606 * @_state: state to validate
13608 static int intel_atomic_check(struct drm_device *dev,
13609 struct drm_atomic_state *_state)
13611 struct drm_i915_private *dev_priv = to_i915(dev);
13612 struct intel_atomic_state *state = to_intel_atomic_state(_state);
13613 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13614 struct intel_crtc *crtc;
13616 bool any_ms = state->cdclk.force_min_cdclk_changed;
13618 /* Catch I915_MODE_FLAG_INHERITED */
13619 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13620 new_crtc_state, i) {
13621 if (new_crtc_state->base.mode.private_flags !=
13622 old_crtc_state->base.mode.private_flags)
13623 new_crtc_state->base.mode_changed = true;
13626 ret = drm_atomic_helper_check_modeset(dev, &state->base);
13630 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13631 new_crtc_state, i) {
13632 if (!needs_modeset(new_crtc_state))
13635 if (!new_crtc_state->base.enable) {
13640 ret = intel_modeset_pipe_config(new_crtc_state);
13644 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
13646 if (needs_modeset(new_crtc_state))
13650 ret = drm_dp_mst_atomic_check(&state->base);
13655 ret = intel_modeset_checks(state);
13659 state->cdclk.logical = dev_priv->cdclk.logical;
13662 ret = icl_add_linked_planes(state);
13666 ret = drm_atomic_helper_check_planes(dev, &state->base);
13670 intel_fbc_choose_crtc(dev_priv, state);
13671 ret = calc_watermark_data(state);
13675 ret = intel_bw_atomic_check(state);
13679 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13680 new_crtc_state, i) {
13681 if (!needs_modeset(new_crtc_state) &&
13682 !new_crtc_state->update_pipe)
13685 intel_dump_pipe_config(new_crtc_state, state,
13686 needs_modeset(new_crtc_state) ?
13687 "[modeset]" : "[fastset]");
13693 if (ret == -EDEADLK)
13697 * FIXME would probably be nice to know which crtc specifically
13698 * caused the failure, in cases where we can pinpoint it.
13700 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13702 intel_dump_pipe_config(new_crtc_state, state, "[failed]");
13707 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
13709 return drm_atomic_helper_prepare_planes(state->base.dev,
13713 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
13715 struct drm_device *dev = crtc->base.dev;
13716 struct drm_vblank_crtc *vblank = &dev->vblank[drm_crtc_index(&crtc->base)];
13718 if (!vblank->max_vblank_count)
13719 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
13721 return crtc->base.funcs->get_vblank_counter(&crtc->base);
13724 static void intel_update_crtc(struct intel_crtc *crtc,
13725 struct intel_atomic_state *state,
13726 struct intel_crtc_state *old_crtc_state,
13727 struct intel_crtc_state *new_crtc_state)
13729 struct drm_device *dev = state->base.dev;
13730 struct drm_i915_private *dev_priv = to_i915(dev);
13731 bool modeset = needs_modeset(new_crtc_state);
13732 struct intel_plane_state *new_plane_state =
13733 intel_atomic_get_new_plane_state(state,
13734 to_intel_plane(crtc->base.primary));
13737 update_scanline_offset(new_crtc_state);
13738 dev_priv->display.crtc_enable(new_crtc_state, state);
13740 /* vblanks work again, re-enable pipe CRC. */
13741 intel_crtc_enable_pipe_crc(crtc);
13743 intel_pre_plane_update(old_crtc_state, new_crtc_state);
13745 if (new_crtc_state->update_pipe)
13746 intel_encoders_update_pipe(crtc, new_crtc_state, state);
13749 if (new_crtc_state->update_pipe && !new_crtc_state->enable_fbc)
13750 intel_fbc_disable(crtc);
13751 else if (new_plane_state)
13752 intel_fbc_enable(crtc, new_crtc_state, new_plane_state);
13754 intel_begin_crtc_commit(state, crtc);
13756 if (INTEL_GEN(dev_priv) >= 9)
13757 skl_update_planes_on_crtc(state, crtc);
13759 i9xx_update_planes_on_crtc(state, crtc);
13761 intel_finish_crtc_commit(state, crtc);
13764 static void intel_update_crtcs(struct intel_atomic_state *state)
13766 struct intel_crtc *crtc;
13767 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13770 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13771 if (!new_crtc_state->base.active)
13774 intel_update_crtc(crtc, state, old_crtc_state,
13779 static void skl_update_crtcs(struct intel_atomic_state *state)
13781 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13782 struct intel_crtc *crtc;
13783 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13784 unsigned int updated = 0;
13788 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
13789 u8 required_slices = state->wm_results.ddb.enabled_slices;
13790 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
13792 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
13793 /* ignore allocations for crtc's that have been turned off. */
13794 if (new_crtc_state->base.active)
13795 entries[i] = old_crtc_state->wm.skl.ddb;
13797 /* If 2nd DBuf slice required, enable it here */
13798 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
13799 icl_dbuf_slices_update(dev_priv, required_slices);
13802 * Whenever the number of active pipes changes, we need to make sure we
13803 * update the pipes in the right order so that their ddb allocations
13804 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
13805 * cause pipe underruns and other bad stuff.
13810 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13811 bool vbl_wait = false;
13812 unsigned int cmask = drm_crtc_mask(&crtc->base);
13816 if (updated & cmask || !new_crtc_state->base.active)
13819 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
13821 INTEL_INFO(dev_priv)->num_pipes, i))
13825 entries[i] = new_crtc_state->wm.skl.ddb;
13828 * If this is an already active pipe, it's DDB changed,
13829 * and this isn't the last pipe that needs updating
13830 * then we need to wait for a vblank to pass for the
13831 * new ddb allocation to take effect.
13833 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
13834 &old_crtc_state->wm.skl.ddb) &&
13835 !new_crtc_state->base.active_changed &&
13836 state->wm_results.dirty_pipes != updated)
13839 intel_update_crtc(crtc, state, old_crtc_state,
13843 intel_wait_for_vblank(dev_priv, pipe);
13847 } while (progress);
13849 /* If 2nd DBuf slice is no more required disable it */
13850 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
13851 icl_dbuf_slices_update(dev_priv, required_slices);
13854 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
13856 struct intel_atomic_state *state, *next;
13857 struct llist_node *freed;
13859 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
13860 llist_for_each_entry_safe(state, next, freed, freed)
13861 drm_atomic_state_put(&state->base);
13864 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
13866 struct drm_i915_private *dev_priv =
13867 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
13869 intel_atomic_helper_free_state(dev_priv);
13872 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
13874 struct wait_queue_entry wait_fence, wait_reset;
13875 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
13877 init_wait_entry(&wait_fence, 0);
13878 init_wait_entry(&wait_reset, 0);
13880 prepare_to_wait(&intel_state->commit_ready.wait,
13881 &wait_fence, TASK_UNINTERRUPTIBLE);
13882 prepare_to_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
13883 I915_RESET_MODESET),
13884 &wait_reset, TASK_UNINTERRUPTIBLE);
13887 if (i915_sw_fence_done(&intel_state->commit_ready) ||
13888 test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
13893 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
13894 finish_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
13895 I915_RESET_MODESET),
13899 static void intel_atomic_cleanup_work(struct work_struct *work)
13901 struct drm_atomic_state *state =
13902 container_of(work, struct drm_atomic_state, commit_work);
13903 struct drm_i915_private *i915 = to_i915(state->dev);
13905 drm_atomic_helper_cleanup_planes(&i915->drm, state);
13906 drm_atomic_helper_commit_cleanup_done(state);
13907 drm_atomic_state_put(state);
13909 intel_atomic_helper_free_state(i915);
13912 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
13914 struct drm_device *dev = state->base.dev;
13915 struct drm_i915_private *dev_priv = to_i915(dev);
13916 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
13917 struct intel_crtc *crtc;
13918 u64 put_domains[I915_MAX_PIPES] = {};
13919 intel_wakeref_t wakeref = 0;
13922 intel_atomic_commit_fence_wait(state);
13924 drm_atomic_helper_wait_for_dependencies(&state->base);
13926 if (state->modeset)
13927 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
13929 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13930 if (needs_modeset(new_crtc_state) ||
13931 new_crtc_state->update_pipe) {
13933 put_domains[crtc->pipe] =
13934 modeset_get_crtc_power_domains(new_crtc_state);
13937 if (!needs_modeset(new_crtc_state))
13940 intel_pre_plane_update(old_crtc_state, new_crtc_state);
13942 if (old_crtc_state->base.active) {
13943 intel_crtc_disable_planes(state, crtc);
13946 * We need to disable pipe CRC before disabling the pipe,
13947 * or we race against vblank off.
13949 intel_crtc_disable_pipe_crc(crtc);
13951 dev_priv->display.crtc_disable(old_crtc_state, state);
13952 crtc->active = false;
13953 intel_fbc_disable(crtc);
13954 intel_disable_shared_dpll(old_crtc_state);
13957 * Underruns don't always raise
13958 * interrupts, so check manually.
13960 intel_check_cpu_fifo_underruns(dev_priv);
13961 intel_check_pch_fifo_underruns(dev_priv);
13963 /* FIXME unify this for all platforms */
13964 if (!new_crtc_state->base.active &&
13965 !HAS_GMCH(dev_priv) &&
13966 dev_priv->display.initial_watermarks)
13967 dev_priv->display.initial_watermarks(state,
13972 /* FIXME: Eventually get rid of our crtc->config pointer */
13973 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
13974 crtc->config = new_crtc_state;
13976 if (state->modeset) {
13977 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
13979 intel_set_cdclk_pre_plane_update(dev_priv,
13980 &state->cdclk.actual,
13981 &dev_priv->cdclk.actual,
13982 state->cdclk.pipe);
13985 * SKL workaround: bspec recommends we disable the SAGV when we
13986 * have more then one pipe enabled
13988 if (!intel_can_enable_sagv(state))
13989 intel_disable_sagv(dev_priv);
13991 intel_modeset_verify_disabled(dev_priv, state);
13994 /* Complete the events for pipes that have now been disabled */
13995 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
13996 bool modeset = needs_modeset(new_crtc_state);
13998 /* Complete events for now disable pipes here. */
13999 if (modeset && !new_crtc_state->base.active && new_crtc_state->base.event) {
14000 spin_lock_irq(&dev->event_lock);
14001 drm_crtc_send_vblank_event(&crtc->base, new_crtc_state->base.event);
14002 spin_unlock_irq(&dev->event_lock);
14004 new_crtc_state->base.event = NULL;
14008 if (state->modeset)
14009 intel_encoders_update_prepare(state);
14011 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
14012 dev_priv->display.update_crtcs(state);
14014 if (state->modeset) {
14015 intel_encoders_update_complete(state);
14017 intel_set_cdclk_post_plane_update(dev_priv,
14018 &state->cdclk.actual,
14019 &dev_priv->cdclk.actual,
14020 state->cdclk.pipe);
14023 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
14024 * already, but still need the state for the delayed optimization. To
14026 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
14027 * - schedule that vblank worker _before_ calling hw_done
14028 * - at the start of commit_tail, cancel it _synchrously
14029 * - switch over to the vblank wait helper in the core after that since
14030 * we don't need out special handling any more.
14032 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
14034 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14035 if (new_crtc_state->base.active &&
14036 !needs_modeset(new_crtc_state) &&
14037 (new_crtc_state->base.color_mgmt_changed ||
14038 new_crtc_state->update_pipe))
14039 intel_color_load_luts(new_crtc_state);
14043 * Now that the vblank has passed, we can go ahead and program the
14044 * optimal watermarks on platforms that need two-step watermark
14047 * TODO: Move this (and other cleanup) to an async worker eventually.
14049 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14050 if (dev_priv->display.optimize_watermarks)
14051 dev_priv->display.optimize_watermarks(state,
14055 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
14056 intel_post_plane_update(old_crtc_state);
14058 if (put_domains[i])
14059 modeset_put_power_domains(dev_priv, put_domains[i]);
14061 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
14064 if (state->modeset)
14065 intel_verify_planes(state);
14067 if (state->modeset && intel_can_enable_sagv(state))
14068 intel_enable_sagv(dev_priv);
14070 drm_atomic_helper_commit_hw_done(&state->base);
14072 if (state->modeset) {
14073 /* As one of the primary mmio accessors, KMS has a high
14074 * likelihood of triggering bugs in unclaimed access. After we
14075 * finish modesetting, see if an error has been flagged, and if
14076 * so enable debugging for the next modeset - and hope we catch
14079 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
14080 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
14082 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
14085 * Defer the cleanup of the old state to a separate worker to not
14086 * impede the current task (userspace for blocking modesets) that
14087 * are executed inline. For out-of-line asynchronous modesets/flips,
14088 * deferring to a new worker seems overkill, but we would place a
14089 * schedule point (cond_resched()) here anyway to keep latencies
14092 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
14093 queue_work(system_highpri_wq, &state->base.commit_work);
14096 static void intel_atomic_commit_work(struct work_struct *work)
14098 struct intel_atomic_state *state =
14099 container_of(work, struct intel_atomic_state, base.commit_work);
14101 intel_atomic_commit_tail(state);
14104 static int __i915_sw_fence_call
14105 intel_atomic_commit_ready(struct i915_sw_fence *fence,
14106 enum i915_sw_fence_notify notify)
14108 struct intel_atomic_state *state =
14109 container_of(fence, struct intel_atomic_state, commit_ready);
14112 case FENCE_COMPLETE:
14113 /* we do blocking waits in the worker, nothing to do here */
14117 struct intel_atomic_helper *helper =
14118 &to_i915(state->base.dev)->atomic_helper;
14120 if (llist_add(&state->freed, &helper->free_list))
14121 schedule_work(&helper->free_work);
14126 return NOTIFY_DONE;
14129 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
14131 struct intel_plane_state *old_plane_state, *new_plane_state;
14132 struct intel_plane *plane;
14135 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
14136 new_plane_state, i)
14137 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->base.fb),
14138 to_intel_frontbuffer(new_plane_state->base.fb),
14139 plane->frontbuffer_bit);
14142 static int intel_atomic_commit(struct drm_device *dev,
14143 struct drm_atomic_state *_state,
14146 struct intel_atomic_state *state = to_intel_atomic_state(_state);
14147 struct drm_i915_private *dev_priv = to_i915(dev);
14150 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
14152 drm_atomic_state_get(&state->base);
14153 i915_sw_fence_init(&state->commit_ready,
14154 intel_atomic_commit_ready);
14157 * The intel_legacy_cursor_update() fast path takes care
14158 * of avoiding the vblank waits for simple cursor
14159 * movement and flips. For cursor on/off and size changes,
14160 * we want to perform the vblank waits so that watermark
14161 * updates happen during the correct frames. Gen9+ have
14162 * double buffered watermarks and so shouldn't need this.
14164 * Unset state->legacy_cursor_update before the call to
14165 * drm_atomic_helper_setup_commit() because otherwise
14166 * drm_atomic_helper_wait_for_flip_done() is a noop and
14167 * we get FIFO underruns because we didn't wait
14170 * FIXME doing watermarks and fb cleanup from a vblank worker
14171 * (assuming we had any) would solve these problems.
14173 if (INTEL_GEN(dev_priv) < 9 && state->base.legacy_cursor_update) {
14174 struct intel_crtc_state *new_crtc_state;
14175 struct intel_crtc *crtc;
14178 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
14179 if (new_crtc_state->wm.need_postvbl_update ||
14180 new_crtc_state->update_wm_post)
14181 state->base.legacy_cursor_update = false;
14184 ret = intel_atomic_prepare_commit(state);
14186 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
14187 i915_sw_fence_commit(&state->commit_ready);
14188 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
14192 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
14194 ret = drm_atomic_helper_swap_state(&state->base, true);
14197 i915_sw_fence_commit(&state->commit_ready);
14199 drm_atomic_helper_cleanup_planes(dev, &state->base);
14200 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
14203 dev_priv->wm.distrust_bios_wm = false;
14204 intel_shared_dpll_swap_state(state);
14205 intel_atomic_track_fbs(state);
14207 if (state->modeset) {
14208 memcpy(dev_priv->min_cdclk, state->min_cdclk,
14209 sizeof(state->min_cdclk));
14210 memcpy(dev_priv->min_voltage_level, state->min_voltage_level,
14211 sizeof(state->min_voltage_level));
14212 dev_priv->active_crtcs = state->active_crtcs;
14213 dev_priv->cdclk.force_min_cdclk = state->cdclk.force_min_cdclk;
14215 intel_cdclk_swap_state(state);
14218 drm_atomic_state_get(&state->base);
14219 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
14221 i915_sw_fence_commit(&state->commit_ready);
14222 if (nonblock && state->modeset) {
14223 queue_work(dev_priv->modeset_wq, &state->base.commit_work);
14224 } else if (nonblock) {
14225 queue_work(system_unbound_wq, &state->base.commit_work);
14227 if (state->modeset)
14228 flush_workqueue(dev_priv->modeset_wq);
14229 intel_atomic_commit_tail(state);
14235 struct wait_rps_boost {
14236 struct wait_queue_entry wait;
14238 struct drm_crtc *crtc;
14239 struct i915_request *request;
14242 static int do_rps_boost(struct wait_queue_entry *_wait,
14243 unsigned mode, int sync, void *key)
14245 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
14246 struct i915_request *rq = wait->request;
14249 * If we missed the vblank, but the request is already running it
14250 * is reasonable to assume that it will complete before the next
14251 * vblank without our intervention, so leave RPS alone.
14253 if (!i915_request_started(rq))
14254 gen6_rps_boost(rq);
14255 i915_request_put(rq);
14257 drm_crtc_vblank_put(wait->crtc);
14259 list_del(&wait->wait.entry);
14264 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
14265 struct dma_fence *fence)
14267 struct wait_rps_boost *wait;
14269 if (!dma_fence_is_i915(fence))
14272 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
14275 if (drm_crtc_vblank_get(crtc))
14278 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
14280 drm_crtc_vblank_put(crtc);
14284 wait->request = to_request(dma_fence_get(fence));
14287 wait->wait.func = do_rps_boost;
14288 wait->wait.flags = 0;
14290 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
14293 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
14295 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
14296 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
14297 struct drm_framebuffer *fb = plane_state->base.fb;
14298 struct i915_vma *vma;
14300 if (plane->id == PLANE_CURSOR &&
14301 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
14302 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14303 const int align = intel_cursor_alignment(dev_priv);
14306 err = i915_gem_object_attach_phys(obj, align);
14311 vma = intel_pin_and_fence_fb_obj(fb,
14312 &plane_state->view,
14313 intel_plane_uses_fence(plane_state),
14314 &plane_state->flags);
14316 return PTR_ERR(vma);
14318 plane_state->vma = vma;
14323 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
14325 struct i915_vma *vma;
14327 vma = fetch_and_zero(&old_plane_state->vma);
14329 intel_unpin_fb_vma(vma, old_plane_state->flags);
14332 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
14334 struct i915_sched_attr attr = {
14335 .priority = I915_PRIORITY_DISPLAY,
14338 i915_gem_object_wait_priority(obj, 0, &attr);
14342 * intel_prepare_plane_fb - Prepare fb for usage on plane
14343 * @plane: drm plane to prepare for
14344 * @new_state: the plane state being prepared
14346 * Prepares a framebuffer for usage on a display plane. Generally this
14347 * involves pinning the underlying object and updating the frontbuffer tracking
14348 * bits. Some older platforms need special physical address handling for
14351 * Must be called with struct_mutex held.
14353 * Returns 0 on success, negative error code on failure.
14356 intel_prepare_plane_fb(struct drm_plane *plane,
14357 struct drm_plane_state *new_state)
14359 struct intel_atomic_state *intel_state =
14360 to_intel_atomic_state(new_state->state);
14361 struct drm_i915_private *dev_priv = to_i915(plane->dev);
14362 struct drm_framebuffer *fb = new_state->fb;
14363 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14364 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
14368 struct intel_crtc_state *crtc_state =
14369 intel_atomic_get_new_crtc_state(intel_state,
14370 to_intel_crtc(plane->state->crtc));
14372 /* Big Hammer, we also need to ensure that any pending
14373 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
14374 * current scanout is retired before unpinning the old
14375 * framebuffer. Note that we rely on userspace rendering
14376 * into the buffer attached to the pipe they are waiting
14377 * on. If not, userspace generates a GPU hang with IPEHR
14378 * point to the MI_WAIT_FOR_EVENT.
14380 * This should only fail upon a hung GPU, in which case we
14381 * can safely continue.
14383 if (needs_modeset(crtc_state)) {
14384 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
14385 old_obj->base.resv, NULL,
14393 if (new_state->fence) { /* explicit fencing */
14394 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
14396 I915_FENCE_TIMEOUT,
14405 ret = i915_gem_object_pin_pages(obj);
14409 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
14411 i915_gem_object_unpin_pages(obj);
14415 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
14417 mutex_unlock(&dev_priv->drm.struct_mutex);
14418 i915_gem_object_unpin_pages(obj);
14422 fb_obj_bump_render_priority(obj);
14423 intel_frontbuffer_flush(obj->frontbuffer, ORIGIN_DIRTYFB);
14425 if (!new_state->fence) { /* implicit fencing */
14426 struct dma_fence *fence;
14428 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
14429 obj->base.resv, NULL,
14430 false, I915_FENCE_TIMEOUT,
14435 fence = dma_resv_get_excl_rcu(obj->base.resv);
14437 add_rps_boost_after_vblank(new_state->crtc, fence);
14438 dma_fence_put(fence);
14441 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
14445 * We declare pageflips to be interactive and so merit a small bias
14446 * towards upclocking to deliver the frame on time. By only changing
14447 * the RPS thresholds to sample more regularly and aim for higher
14448 * clocks we can hopefully deliver low power workloads (like kodi)
14449 * that are not quite steady state without resorting to forcing
14450 * maximum clocks following a vblank miss (see do_rps_boost()).
14452 if (!intel_state->rps_interactive) {
14453 intel_rps_mark_interactive(dev_priv, true);
14454 intel_state->rps_interactive = true;
14461 * intel_cleanup_plane_fb - Cleans up an fb after plane use
14462 * @plane: drm plane to clean up for
14463 * @old_state: the state from the previous modeset
14465 * Cleans up a framebuffer that has just been removed from a plane.
14467 * Must be called with struct_mutex held.
14470 intel_cleanup_plane_fb(struct drm_plane *plane,
14471 struct drm_plane_state *old_state)
14473 struct intel_atomic_state *intel_state =
14474 to_intel_atomic_state(old_state->state);
14475 struct drm_i915_private *dev_priv = to_i915(plane->dev);
14477 if (intel_state->rps_interactive) {
14478 intel_rps_mark_interactive(dev_priv, false);
14479 intel_state->rps_interactive = false;
14482 /* Should only be called after a successful intel_prepare_plane_fb()! */
14483 mutex_lock(&dev_priv->drm.struct_mutex);
14484 intel_plane_unpin_fb(to_intel_plane_state(old_state));
14485 mutex_unlock(&dev_priv->drm.struct_mutex);
14489 skl_max_scale(const struct intel_crtc_state *crtc_state,
14492 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
14493 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14494 int max_scale, mult;
14495 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
14497 if (!crtc_state->base.enable)
14498 return DRM_PLANE_HELPER_NO_SCALING;
14500 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
14501 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
14503 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
14506 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
14507 return DRM_PLANE_HELPER_NO_SCALING;
14510 * skl max scale is lower of:
14511 * close to 3 but not 3, -1 is for that purpose
14515 mult = is_planar_yuv_format(pixel_format) ? 2 : 3;
14516 tmpclk1 = (1 << 16) * mult - 1;
14517 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
14518 max_scale = min(tmpclk1, tmpclk2);
14523 static void intel_begin_crtc_commit(struct intel_atomic_state *state,
14524 struct intel_crtc *crtc)
14526 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14527 struct intel_crtc_state *old_crtc_state =
14528 intel_atomic_get_old_crtc_state(state, crtc);
14529 struct intel_crtc_state *new_crtc_state =
14530 intel_atomic_get_new_crtc_state(state, crtc);
14531 bool modeset = needs_modeset(new_crtc_state);
14533 /* Perform vblank evasion around commit operation */
14534 intel_pipe_update_start(new_crtc_state);
14539 if (new_crtc_state->base.color_mgmt_changed ||
14540 new_crtc_state->update_pipe)
14541 intel_color_commit(new_crtc_state);
14543 if (new_crtc_state->update_pipe)
14544 intel_update_pipe_config(old_crtc_state, new_crtc_state);
14545 else if (INTEL_GEN(dev_priv) >= 9)
14546 skl_detach_scalers(new_crtc_state);
14548 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
14549 bdw_set_pipemisc(new_crtc_state);
14552 if (dev_priv->display.atomic_update_watermarks)
14553 dev_priv->display.atomic_update_watermarks(state,
14557 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
14558 struct intel_crtc_state *crtc_state)
14560 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14562 if (!IS_GEN(dev_priv, 2))
14563 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
14565 if (crtc_state->has_pch_encoder) {
14566 enum pipe pch_transcoder =
14567 intel_crtc_pch_transcoder(crtc);
14569 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
14573 static void intel_finish_crtc_commit(struct intel_atomic_state *state,
14574 struct intel_crtc *crtc)
14576 struct intel_crtc_state *old_crtc_state =
14577 intel_atomic_get_old_crtc_state(state, crtc);
14578 struct intel_crtc_state *new_crtc_state =
14579 intel_atomic_get_new_crtc_state(state, crtc);
14581 intel_pipe_update_end(new_crtc_state);
14583 if (new_crtc_state->update_pipe &&
14584 !needs_modeset(new_crtc_state) &&
14585 old_crtc_state->base.mode.private_flags & I915_MODE_FLAG_INHERITED)
14586 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
14590 * intel_plane_destroy - destroy a plane
14591 * @plane: plane to destroy
14593 * Common destruction function for all types of planes (primary, cursor,
14596 void intel_plane_destroy(struct drm_plane *plane)
14598 drm_plane_cleanup(plane);
14599 kfree(to_intel_plane(plane));
14602 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
14603 u32 format, u64 modifier)
14605 switch (modifier) {
14606 case DRM_FORMAT_MOD_LINEAR:
14607 case I915_FORMAT_MOD_X_TILED:
14614 case DRM_FORMAT_C8:
14615 case DRM_FORMAT_RGB565:
14616 case DRM_FORMAT_XRGB1555:
14617 case DRM_FORMAT_XRGB8888:
14618 return modifier == DRM_FORMAT_MOD_LINEAR ||
14619 modifier == I915_FORMAT_MOD_X_TILED;
14625 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
14626 u32 format, u64 modifier)
14628 switch (modifier) {
14629 case DRM_FORMAT_MOD_LINEAR:
14630 case I915_FORMAT_MOD_X_TILED:
14637 case DRM_FORMAT_C8:
14638 case DRM_FORMAT_RGB565:
14639 case DRM_FORMAT_XRGB8888:
14640 case DRM_FORMAT_XBGR8888:
14641 case DRM_FORMAT_XRGB2101010:
14642 case DRM_FORMAT_XBGR2101010:
14643 return modifier == DRM_FORMAT_MOD_LINEAR ||
14644 modifier == I915_FORMAT_MOD_X_TILED;
14650 static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
14651 u32 format, u64 modifier)
14653 return modifier == DRM_FORMAT_MOD_LINEAR &&
14654 format == DRM_FORMAT_ARGB8888;
14657 static const struct drm_plane_funcs i965_plane_funcs = {
14658 .update_plane = drm_atomic_helper_update_plane,
14659 .disable_plane = drm_atomic_helper_disable_plane,
14660 .destroy = intel_plane_destroy,
14661 .atomic_duplicate_state = intel_plane_duplicate_state,
14662 .atomic_destroy_state = intel_plane_destroy_state,
14663 .format_mod_supported = i965_plane_format_mod_supported,
14666 static const struct drm_plane_funcs i8xx_plane_funcs = {
14667 .update_plane = drm_atomic_helper_update_plane,
14668 .disable_plane = drm_atomic_helper_disable_plane,
14669 .destroy = intel_plane_destroy,
14670 .atomic_duplicate_state = intel_plane_duplicate_state,
14671 .atomic_destroy_state = intel_plane_destroy_state,
14672 .format_mod_supported = i8xx_plane_format_mod_supported,
14676 intel_legacy_cursor_update(struct drm_plane *plane,
14677 struct drm_crtc *crtc,
14678 struct drm_framebuffer *fb,
14679 int crtc_x, int crtc_y,
14680 unsigned int crtc_w, unsigned int crtc_h,
14681 u32 src_x, u32 src_y,
14682 u32 src_w, u32 src_h,
14683 struct drm_modeset_acquire_ctx *ctx)
14685 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
14686 struct drm_plane_state *old_plane_state, *new_plane_state;
14687 struct intel_plane *intel_plane = to_intel_plane(plane);
14688 struct intel_crtc_state *crtc_state =
14689 to_intel_crtc_state(crtc->state);
14690 struct intel_crtc_state *new_crtc_state;
14694 * When crtc is inactive or there is a modeset pending,
14695 * wait for it to complete in the slowpath
14697 if (!crtc_state->base.active || needs_modeset(crtc_state) ||
14698 crtc_state->update_pipe)
14701 old_plane_state = plane->state;
14703 * Don't do an async update if there is an outstanding commit modifying
14704 * the plane. This prevents our async update's changes from getting
14705 * overridden by a previous synchronous update's state.
14707 if (old_plane_state->commit &&
14708 !try_wait_for_completion(&old_plane_state->commit->hw_done))
14712 * If any parameters change that may affect watermarks,
14713 * take the slowpath. Only changing fb or position should be
14716 if (old_plane_state->crtc != crtc ||
14717 old_plane_state->src_w != src_w ||
14718 old_plane_state->src_h != src_h ||
14719 old_plane_state->crtc_w != crtc_w ||
14720 old_plane_state->crtc_h != crtc_h ||
14721 !old_plane_state->fb != !fb)
14724 new_plane_state = intel_plane_duplicate_state(plane);
14725 if (!new_plane_state)
14728 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc));
14729 if (!new_crtc_state) {
14734 drm_atomic_set_fb_for_plane(new_plane_state, fb);
14736 new_plane_state->src_x = src_x;
14737 new_plane_state->src_y = src_y;
14738 new_plane_state->src_w = src_w;
14739 new_plane_state->src_h = src_h;
14740 new_plane_state->crtc_x = crtc_x;
14741 new_plane_state->crtc_y = crtc_y;
14742 new_plane_state->crtc_w = crtc_w;
14743 new_plane_state->crtc_h = crtc_h;
14745 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
14746 to_intel_plane_state(old_plane_state),
14747 to_intel_plane_state(new_plane_state));
14751 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
14755 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
14759 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_FLIP);
14760 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->fb),
14761 to_intel_frontbuffer(fb),
14762 intel_plane->frontbuffer_bit);
14764 /* Swap plane state */
14765 plane->state = new_plane_state;
14768 * We cannot swap crtc_state as it may be in use by an atomic commit or
14769 * page flip that's running simultaneously. If we swap crtc_state and
14770 * destroy the old state, we will cause a use-after-free there.
14772 * Only update active_planes, which is needed for our internal
14773 * bookkeeping. Either value will do the right thing when updating
14774 * planes atomically. If the cursor was part of the atomic update then
14775 * we would have taken the slowpath.
14777 crtc_state->active_planes = new_crtc_state->active_planes;
14779 if (plane->state->visible)
14780 intel_update_plane(intel_plane, crtc_state,
14781 to_intel_plane_state(plane->state));
14783 intel_disable_plane(intel_plane, crtc_state);
14785 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
14788 mutex_unlock(&dev_priv->drm.struct_mutex);
14790 if (new_crtc_state)
14791 intel_crtc_destroy_state(crtc, &new_crtc_state->base);
14793 intel_plane_destroy_state(plane, new_plane_state);
14795 intel_plane_destroy_state(plane, old_plane_state);
14799 return drm_atomic_helper_update_plane(plane, crtc, fb,
14800 crtc_x, crtc_y, crtc_w, crtc_h,
14801 src_x, src_y, src_w, src_h, ctx);
14804 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
14805 .update_plane = intel_legacy_cursor_update,
14806 .disable_plane = drm_atomic_helper_disable_plane,
14807 .destroy = intel_plane_destroy,
14808 .atomic_duplicate_state = intel_plane_duplicate_state,
14809 .atomic_destroy_state = intel_plane_destroy_state,
14810 .format_mod_supported = intel_cursor_format_mod_supported,
14813 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
14814 enum i9xx_plane_id i9xx_plane)
14816 if (!HAS_FBC(dev_priv))
14819 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
14820 return i9xx_plane == PLANE_A; /* tied to pipe A */
14821 else if (IS_IVYBRIDGE(dev_priv))
14822 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
14823 i9xx_plane == PLANE_C;
14824 else if (INTEL_GEN(dev_priv) >= 4)
14825 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
14827 return i9xx_plane == PLANE_A;
14830 static struct intel_plane *
14831 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
14833 struct intel_plane *plane;
14834 const struct drm_plane_funcs *plane_funcs;
14835 unsigned int supported_rotations;
14836 unsigned int possible_crtcs;
14837 const u64 *modifiers;
14838 const u32 *formats;
14842 if (INTEL_GEN(dev_priv) >= 9)
14843 return skl_universal_plane_create(dev_priv, pipe,
14846 plane = intel_plane_alloc();
14850 plane->pipe = pipe;
14852 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
14853 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
14855 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
14856 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
14858 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
14859 plane->id = PLANE_PRIMARY;
14860 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
14862 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
14863 if (plane->has_fbc) {
14864 struct intel_fbc *fbc = &dev_priv->fbc;
14866 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
14869 if (INTEL_GEN(dev_priv) >= 4) {
14870 formats = i965_primary_formats;
14871 num_formats = ARRAY_SIZE(i965_primary_formats);
14872 modifiers = i9xx_format_modifiers;
14874 plane->max_stride = i9xx_plane_max_stride;
14875 plane->update_plane = i9xx_update_plane;
14876 plane->disable_plane = i9xx_disable_plane;
14877 plane->get_hw_state = i9xx_plane_get_hw_state;
14878 plane->check_plane = i9xx_plane_check;
14880 plane_funcs = &i965_plane_funcs;
14882 formats = i8xx_primary_formats;
14883 num_formats = ARRAY_SIZE(i8xx_primary_formats);
14884 modifiers = i9xx_format_modifiers;
14886 plane->max_stride = i9xx_plane_max_stride;
14887 plane->update_plane = i9xx_update_plane;
14888 plane->disable_plane = i9xx_disable_plane;
14889 plane->get_hw_state = i9xx_plane_get_hw_state;
14890 plane->check_plane = i9xx_plane_check;
14892 plane_funcs = &i8xx_plane_funcs;
14895 possible_crtcs = BIT(pipe);
14897 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
14898 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
14899 possible_crtcs, plane_funcs,
14900 formats, num_formats, modifiers,
14901 DRM_PLANE_TYPE_PRIMARY,
14902 "primary %c", pipe_name(pipe));
14904 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
14905 possible_crtcs, plane_funcs,
14906 formats, num_formats, modifiers,
14907 DRM_PLANE_TYPE_PRIMARY,
14909 plane_name(plane->i9xx_plane));
14913 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
14914 supported_rotations =
14915 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
14916 DRM_MODE_REFLECT_X;
14917 } else if (INTEL_GEN(dev_priv) >= 4) {
14918 supported_rotations =
14919 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
14921 supported_rotations = DRM_MODE_ROTATE_0;
14924 if (INTEL_GEN(dev_priv) >= 4)
14925 drm_plane_create_rotation_property(&plane->base,
14927 supported_rotations);
14929 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
14934 intel_plane_free(plane);
14936 return ERR_PTR(ret);
14939 static struct intel_plane *
14940 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
14943 unsigned int possible_crtcs;
14944 struct intel_plane *cursor;
14947 cursor = intel_plane_alloc();
14948 if (IS_ERR(cursor))
14951 cursor->pipe = pipe;
14952 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
14953 cursor->id = PLANE_CURSOR;
14954 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
14956 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
14957 cursor->max_stride = i845_cursor_max_stride;
14958 cursor->update_plane = i845_update_cursor;
14959 cursor->disable_plane = i845_disable_cursor;
14960 cursor->get_hw_state = i845_cursor_get_hw_state;
14961 cursor->check_plane = i845_check_cursor;
14963 cursor->max_stride = i9xx_cursor_max_stride;
14964 cursor->update_plane = i9xx_update_cursor;
14965 cursor->disable_plane = i9xx_disable_cursor;
14966 cursor->get_hw_state = i9xx_cursor_get_hw_state;
14967 cursor->check_plane = i9xx_check_cursor;
14970 cursor->cursor.base = ~0;
14971 cursor->cursor.cntl = ~0;
14973 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
14974 cursor->cursor.size = ~0;
14976 possible_crtcs = BIT(pipe);
14978 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
14979 possible_crtcs, &intel_cursor_plane_funcs,
14980 intel_cursor_formats,
14981 ARRAY_SIZE(intel_cursor_formats),
14982 cursor_format_modifiers,
14983 DRM_PLANE_TYPE_CURSOR,
14984 "cursor %c", pipe_name(pipe));
14988 if (INTEL_GEN(dev_priv) >= 4)
14989 drm_plane_create_rotation_property(&cursor->base,
14991 DRM_MODE_ROTATE_0 |
14992 DRM_MODE_ROTATE_180);
14994 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
14999 intel_plane_free(cursor);
15001 return ERR_PTR(ret);
15004 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
15005 struct intel_crtc_state *crtc_state)
15007 struct intel_crtc_scaler_state *scaler_state =
15008 &crtc_state->scaler_state;
15009 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
15012 crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[crtc->pipe];
15013 if (!crtc->num_scalers)
15016 for (i = 0; i < crtc->num_scalers; i++) {
15017 struct intel_scaler *scaler = &scaler_state->scalers[i];
15019 scaler->in_use = 0;
15023 scaler_state->scaler_id = -1;
15026 #define INTEL_CRTC_FUNCS \
15027 .gamma_set = drm_atomic_helper_legacy_gamma_set, \
15028 .set_config = drm_atomic_helper_set_config, \
15029 .destroy = intel_crtc_destroy, \
15030 .page_flip = drm_atomic_helper_page_flip, \
15031 .atomic_duplicate_state = intel_crtc_duplicate_state, \
15032 .atomic_destroy_state = intel_crtc_destroy_state, \
15033 .set_crc_source = intel_crtc_set_crc_source, \
15034 .verify_crc_source = intel_crtc_verify_crc_source, \
15035 .get_crc_sources = intel_crtc_get_crc_sources
15037 static const struct drm_crtc_funcs bdw_crtc_funcs = {
15040 .get_vblank_counter = g4x_get_vblank_counter,
15041 .enable_vblank = bdw_enable_vblank,
15042 .disable_vblank = bdw_disable_vblank,
15045 static const struct drm_crtc_funcs ilk_crtc_funcs = {
15048 .get_vblank_counter = g4x_get_vblank_counter,
15049 .enable_vblank = ilk_enable_vblank,
15050 .disable_vblank = ilk_disable_vblank,
15053 static const struct drm_crtc_funcs g4x_crtc_funcs = {
15056 .get_vblank_counter = g4x_get_vblank_counter,
15057 .enable_vblank = i965_enable_vblank,
15058 .disable_vblank = i965_disable_vblank,
15061 static const struct drm_crtc_funcs i965_crtc_funcs = {
15064 .get_vblank_counter = i915_get_vblank_counter,
15065 .enable_vblank = i965_enable_vblank,
15066 .disable_vblank = i965_disable_vblank,
15069 static const struct drm_crtc_funcs i945gm_crtc_funcs = {
15072 .get_vblank_counter = i915_get_vblank_counter,
15073 .enable_vblank = i945gm_enable_vblank,
15074 .disable_vblank = i945gm_disable_vblank,
15077 static const struct drm_crtc_funcs i915_crtc_funcs = {
15080 .get_vblank_counter = i915_get_vblank_counter,
15081 .enable_vblank = i8xx_enable_vblank,
15082 .disable_vblank = i8xx_disable_vblank,
15085 static const struct drm_crtc_funcs i8xx_crtc_funcs = {
15088 /* no hw vblank counter */
15089 .enable_vblank = i8xx_enable_vblank,
15090 .disable_vblank = i8xx_disable_vblank,
15093 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
15095 const struct drm_crtc_funcs *funcs;
15096 struct intel_crtc *intel_crtc;
15097 struct intel_crtc_state *crtc_state = NULL;
15098 struct intel_plane *primary = NULL;
15099 struct intel_plane *cursor = NULL;
15102 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
15106 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
15111 __drm_atomic_helper_crtc_reset(&intel_crtc->base, &crtc_state->base);
15112 intel_crtc->config = crtc_state;
15114 primary = intel_primary_plane_create(dev_priv, pipe);
15115 if (IS_ERR(primary)) {
15116 ret = PTR_ERR(primary);
15119 intel_crtc->plane_ids_mask |= BIT(primary->id);
15121 for_each_sprite(dev_priv, pipe, sprite) {
15122 struct intel_plane *plane;
15124 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
15125 if (IS_ERR(plane)) {
15126 ret = PTR_ERR(plane);
15129 intel_crtc->plane_ids_mask |= BIT(plane->id);
15132 cursor = intel_cursor_plane_create(dev_priv, pipe);
15133 if (IS_ERR(cursor)) {
15134 ret = PTR_ERR(cursor);
15137 intel_crtc->plane_ids_mask |= BIT(cursor->id);
15139 if (HAS_GMCH(dev_priv)) {
15140 if (IS_CHERRYVIEW(dev_priv) ||
15141 IS_VALLEYVIEW(dev_priv) || IS_G4X(dev_priv))
15142 funcs = &g4x_crtc_funcs;
15143 else if (IS_GEN(dev_priv, 4))
15144 funcs = &i965_crtc_funcs;
15145 else if (IS_I945GM(dev_priv))
15146 funcs = &i945gm_crtc_funcs;
15147 else if (IS_GEN(dev_priv, 3))
15148 funcs = &i915_crtc_funcs;
15150 funcs = &i8xx_crtc_funcs;
15152 if (INTEL_GEN(dev_priv) >= 8)
15153 funcs = &bdw_crtc_funcs;
15155 funcs = &ilk_crtc_funcs;
15158 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
15159 &primary->base, &cursor->base,
15160 funcs, "pipe %c", pipe_name(pipe));
15164 intel_crtc->pipe = pipe;
15166 /* initialize shared scalers */
15167 intel_crtc_init_scalers(intel_crtc, crtc_state);
15169 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
15170 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
15171 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
15173 if (INTEL_GEN(dev_priv) < 9) {
15174 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
15176 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
15177 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
15178 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
15181 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
15183 intel_color_init(intel_crtc);
15185 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
15191 * drm_mode_config_cleanup() will free up any
15192 * crtcs/planes already initialized.
15200 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
15201 struct drm_file *file)
15203 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
15204 struct drm_crtc *drmmode_crtc;
15205 struct intel_crtc *crtc;
15207 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
15211 crtc = to_intel_crtc(drmmode_crtc);
15212 pipe_from_crtc_id->pipe = crtc->pipe;
15217 static int intel_encoder_clones(struct intel_encoder *encoder)
15219 struct drm_device *dev = encoder->base.dev;
15220 struct intel_encoder *source_encoder;
15221 int index_mask = 0;
15224 for_each_intel_encoder(dev, source_encoder) {
15225 if (encoders_cloneable(encoder, source_encoder))
15226 index_mask |= (1 << entry);
15234 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
15236 if (!IS_MOBILE(dev_priv))
15239 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
15242 if (IS_GEN(dev_priv, 5) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
15248 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
15250 if (INTEL_GEN(dev_priv) >= 9)
15253 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
15256 if (HAS_PCH_LPT_H(dev_priv) &&
15257 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
15260 /* DDI E can't be used if DDI A requires 4 lanes */
15261 if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
15264 if (!dev_priv->vbt.int_crt_support)
15270 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
15275 if (HAS_DDI(dev_priv))
15278 * This w/a is needed at least on CPT/PPT, but to be sure apply it
15279 * everywhere where registers can be write protected.
15281 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
15286 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
15287 u32 val = I915_READ(PP_CONTROL(pps_idx));
15289 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
15290 I915_WRITE(PP_CONTROL(pps_idx), val);
15294 static void intel_pps_init(struct drm_i915_private *dev_priv)
15296 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
15297 dev_priv->pps_mmio_base = PCH_PPS_BASE;
15298 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
15299 dev_priv->pps_mmio_base = VLV_PPS_BASE;
15301 dev_priv->pps_mmio_base = PPS_BASE;
15303 intel_pps_unlock_regs_wa(dev_priv);
15306 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
15308 struct intel_encoder *encoder;
15309 bool dpd_is_edp = false;
15311 intel_pps_init(dev_priv);
15313 if (!HAS_DISPLAY(dev_priv))
15316 if (INTEL_GEN(dev_priv) >= 12) {
15317 /* TODO: initialize TC ports as well */
15318 intel_ddi_init(dev_priv, PORT_A);
15319 intel_ddi_init(dev_priv, PORT_B);
15320 icl_dsi_init(dev_priv);
15321 } else if (IS_ELKHARTLAKE(dev_priv)) {
15322 intel_ddi_init(dev_priv, PORT_A);
15323 intel_ddi_init(dev_priv, PORT_B);
15324 intel_ddi_init(dev_priv, PORT_C);
15325 intel_ddi_init(dev_priv, PORT_D);
15326 icl_dsi_init(dev_priv);
15327 } else if (IS_GEN(dev_priv, 11)) {
15328 intel_ddi_init(dev_priv, PORT_A);
15329 intel_ddi_init(dev_priv, PORT_B);
15330 intel_ddi_init(dev_priv, PORT_C);
15331 intel_ddi_init(dev_priv, PORT_D);
15332 intel_ddi_init(dev_priv, PORT_E);
15334 * On some ICL SKUs port F is not present. No strap bits for
15335 * this, so rely on VBT.
15336 * Work around broken VBTs on SKUs known to have no port F.
15338 if (IS_ICL_WITH_PORT_F(dev_priv) &&
15339 intel_bios_is_port_present(dev_priv, PORT_F))
15340 intel_ddi_init(dev_priv, PORT_F);
15342 icl_dsi_init(dev_priv);
15343 } else if (IS_GEN9_LP(dev_priv)) {
15345 * FIXME: Broxton doesn't support port detection via the
15346 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
15347 * detect the ports.
15349 intel_ddi_init(dev_priv, PORT_A);
15350 intel_ddi_init(dev_priv, PORT_B);
15351 intel_ddi_init(dev_priv, PORT_C);
15353 vlv_dsi_init(dev_priv);
15354 } else if (HAS_DDI(dev_priv)) {
15357 if (intel_ddi_crt_present(dev_priv))
15358 intel_crt_init(dev_priv);
15361 * Haswell uses DDI functions to detect digital outputs.
15362 * On SKL pre-D0 the strap isn't connected, so we assume
15365 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
15366 /* WaIgnoreDDIAStrap: skl */
15367 if (found || IS_GEN9_BC(dev_priv))
15368 intel_ddi_init(dev_priv, PORT_A);
15370 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
15372 found = I915_READ(SFUSE_STRAP);
15374 if (found & SFUSE_STRAP_DDIB_DETECTED)
15375 intel_ddi_init(dev_priv, PORT_B);
15376 if (found & SFUSE_STRAP_DDIC_DETECTED)
15377 intel_ddi_init(dev_priv, PORT_C);
15378 if (found & SFUSE_STRAP_DDID_DETECTED)
15379 intel_ddi_init(dev_priv, PORT_D);
15380 if (found & SFUSE_STRAP_DDIF_DETECTED)
15381 intel_ddi_init(dev_priv, PORT_F);
15383 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
15385 if (IS_GEN9_BC(dev_priv) &&
15386 intel_bios_is_port_present(dev_priv, PORT_E))
15387 intel_ddi_init(dev_priv, PORT_E);
15389 } else if (HAS_PCH_SPLIT(dev_priv)) {
15393 * intel_edp_init_connector() depends on this completing first,
15394 * to prevent the registration of both eDP and LVDS and the
15395 * incorrect sharing of the PPS.
15397 intel_lvds_init(dev_priv);
15398 intel_crt_init(dev_priv);
15400 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
15402 if (ilk_has_edp_a(dev_priv))
15403 intel_dp_init(dev_priv, DP_A, PORT_A);
15405 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
15406 /* PCH SDVOB multiplex with HDMIB */
15407 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
15409 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
15410 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
15411 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
15414 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
15415 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
15417 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
15418 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
15420 if (I915_READ(PCH_DP_C) & DP_DETECTED)
15421 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
15423 if (I915_READ(PCH_DP_D) & DP_DETECTED)
15424 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
15425 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
15426 bool has_edp, has_port;
15428 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
15429 intel_crt_init(dev_priv);
15432 * The DP_DETECTED bit is the latched state of the DDC
15433 * SDA pin at boot. However since eDP doesn't require DDC
15434 * (no way to plug in a DP->HDMI dongle) the DDC pins for
15435 * eDP ports may have been muxed to an alternate function.
15436 * Thus we can't rely on the DP_DETECTED bit alone to detect
15437 * eDP ports. Consult the VBT as well as DP_DETECTED to
15438 * detect eDP ports.
15440 * Sadly the straps seem to be missing sometimes even for HDMI
15441 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
15442 * and VBT for the presence of the port. Additionally we can't
15443 * trust the port type the VBT declares as we've seen at least
15444 * HDMI ports that the VBT claim are DP or eDP.
15446 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
15447 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
15448 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
15449 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
15450 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
15451 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
15453 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
15454 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
15455 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
15456 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
15457 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
15458 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
15460 if (IS_CHERRYVIEW(dev_priv)) {
15462 * eDP not supported on port D,
15463 * so no need to worry about it
15465 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
15466 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
15467 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
15468 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
15469 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
15472 vlv_dsi_init(dev_priv);
15473 } else if (IS_PINEVIEW(dev_priv)) {
15474 intel_lvds_init(dev_priv);
15475 intel_crt_init(dev_priv);
15476 } else if (IS_GEN_RANGE(dev_priv, 3, 4)) {
15477 bool found = false;
15479 if (IS_MOBILE(dev_priv))
15480 intel_lvds_init(dev_priv);
15482 intel_crt_init(dev_priv);
15484 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
15485 DRM_DEBUG_KMS("probing SDVOB\n");
15486 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
15487 if (!found && IS_G4X(dev_priv)) {
15488 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
15489 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
15492 if (!found && IS_G4X(dev_priv))
15493 intel_dp_init(dev_priv, DP_B, PORT_B);
15496 /* Before G4X SDVOC doesn't have its own detect register */
15498 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
15499 DRM_DEBUG_KMS("probing SDVOC\n");
15500 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
15503 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
15505 if (IS_G4X(dev_priv)) {
15506 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
15507 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
15509 if (IS_G4X(dev_priv))
15510 intel_dp_init(dev_priv, DP_C, PORT_C);
15513 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
15514 intel_dp_init(dev_priv, DP_D, PORT_D);
15516 if (SUPPORTS_TV(dev_priv))
15517 intel_tv_init(dev_priv);
15518 } else if (IS_GEN(dev_priv, 2)) {
15519 if (IS_I85X(dev_priv))
15520 intel_lvds_init(dev_priv);
15522 intel_crt_init(dev_priv);
15523 intel_dvo_init(dev_priv);
15526 intel_psr_init(dev_priv);
15528 for_each_intel_encoder(&dev_priv->drm, encoder) {
15529 encoder->base.possible_crtcs = encoder->crtc_mask;
15530 encoder->base.possible_clones =
15531 intel_encoder_clones(encoder);
15534 intel_init_pch_refclk(dev_priv);
15536 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
15539 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
15541 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
15543 drm_framebuffer_cleanup(fb);
15544 intel_frontbuffer_put(intel_fb->frontbuffer);
15549 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
15550 struct drm_file *file,
15551 unsigned int *handle)
15553 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
15555 if (obj->userptr.mm) {
15556 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
15560 return drm_gem_handle_create(file, &obj->base, handle);
15563 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
15564 struct drm_file *file,
15565 unsigned flags, unsigned color,
15566 struct drm_clip_rect *clips,
15567 unsigned num_clips)
15569 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
15571 i915_gem_object_flush_if_display(obj);
15572 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
15577 static const struct drm_framebuffer_funcs intel_fb_funcs = {
15578 .destroy = intel_user_framebuffer_destroy,
15579 .create_handle = intel_user_framebuffer_create_handle,
15580 .dirty = intel_user_framebuffer_dirty,
15583 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
15584 struct drm_i915_gem_object *obj,
15585 struct drm_mode_fb_cmd2 *mode_cmd)
15587 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
15588 struct drm_framebuffer *fb = &intel_fb->base;
15590 unsigned int tiling, stride;
15594 intel_fb->frontbuffer = intel_frontbuffer_get(obj);
15595 if (!intel_fb->frontbuffer)
15598 i915_gem_object_lock(obj);
15599 tiling = i915_gem_object_get_tiling(obj);
15600 stride = i915_gem_object_get_stride(obj);
15601 i915_gem_object_unlock(obj);
15603 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
15605 * If there's a fence, enforce that
15606 * the fb modifier and tiling mode match.
15608 if (tiling != I915_TILING_NONE &&
15609 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
15610 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
15614 if (tiling == I915_TILING_X) {
15615 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
15616 } else if (tiling == I915_TILING_Y) {
15617 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
15622 if (!drm_any_plane_has_format(&dev_priv->drm,
15623 mode_cmd->pixel_format,
15624 mode_cmd->modifier[0])) {
15625 struct drm_format_name_buf format_name;
15627 DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n",
15628 drm_get_format_name(mode_cmd->pixel_format,
15630 mode_cmd->modifier[0]);
15635 * gen2/3 display engine uses the fence if present,
15636 * so the tiling mode must match the fb modifier exactly.
15638 if (INTEL_GEN(dev_priv) < 4 &&
15639 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
15640 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
15644 max_stride = intel_fb_max_stride(dev_priv, mode_cmd->pixel_format,
15645 mode_cmd->modifier[0]);
15646 if (mode_cmd->pitches[0] > max_stride) {
15647 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
15648 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
15649 "tiled" : "linear",
15650 mode_cmd->pitches[0], max_stride);
15655 * If there's a fence, enforce that
15656 * the fb pitch and fence stride match.
15658 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
15659 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
15660 mode_cmd->pitches[0], stride);
15664 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
15665 if (mode_cmd->offsets[0] != 0)
15668 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
15670 for (i = 0; i < fb->format->num_planes; i++) {
15671 u32 stride_alignment;
15673 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
15674 DRM_DEBUG_KMS("bad plane %d handle\n", i);
15678 stride_alignment = intel_fb_stride_alignment(fb, i);
15681 * Display WA #0531: skl,bxt,kbl,glk
15683 * Render decompression and plane width > 3840
15684 * combined with horizontal panning requires the
15685 * plane stride to be a multiple of 4. We'll just
15686 * require the entire fb to accommodate that to avoid
15687 * potential runtime errors at plane configuration time.
15689 if (IS_GEN(dev_priv, 9) && i == 0 && fb->width > 3840 &&
15690 is_ccs_modifier(fb->modifier))
15691 stride_alignment *= 4;
15693 if (fb->pitches[i] & (stride_alignment - 1)) {
15694 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
15695 i, fb->pitches[i], stride_alignment);
15699 fb->obj[i] = &obj->base;
15702 ret = intel_fill_fb_info(dev_priv, fb);
15706 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
15708 DRM_ERROR("framebuffer init failed %d\n", ret);
15715 intel_frontbuffer_put(intel_fb->frontbuffer);
15719 static struct drm_framebuffer *
15720 intel_user_framebuffer_create(struct drm_device *dev,
15721 struct drm_file *filp,
15722 const struct drm_mode_fb_cmd2 *user_mode_cmd)
15724 struct drm_framebuffer *fb;
15725 struct drm_i915_gem_object *obj;
15726 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
15728 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
15730 return ERR_PTR(-ENOENT);
15732 fb = intel_framebuffer_create(obj, &mode_cmd);
15733 i915_gem_object_put(obj);
15738 static void intel_atomic_state_free(struct drm_atomic_state *state)
15740 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
15742 drm_atomic_state_default_release(state);
15744 i915_sw_fence_fini(&intel_state->commit_ready);
15749 static enum drm_mode_status
15750 intel_mode_valid(struct drm_device *dev,
15751 const struct drm_display_mode *mode)
15753 struct drm_i915_private *dev_priv = to_i915(dev);
15754 int hdisplay_max, htotal_max;
15755 int vdisplay_max, vtotal_max;
15758 * Can't reject DBLSCAN here because Xorg ddxen can add piles
15759 * of DBLSCAN modes to the output's mode list when they detect
15760 * the scaling mode property on the connector. And they don't
15761 * ask the kernel to validate those modes in any way until
15762 * modeset time at which point the client gets a protocol error.
15763 * So in order to not upset those clients we silently ignore the
15764 * DBLSCAN flag on such connectors. For other connectors we will
15765 * reject modes with the DBLSCAN flag in encoder->compute_config().
15766 * And we always reject DBLSCAN modes in connector->mode_valid()
15767 * as we never want such modes on the connector's mode list.
15770 if (mode->vscan > 1)
15771 return MODE_NO_VSCAN;
15773 if (mode->flags & DRM_MODE_FLAG_HSKEW)
15774 return MODE_H_ILLEGAL;
15776 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
15777 DRM_MODE_FLAG_NCSYNC |
15778 DRM_MODE_FLAG_PCSYNC))
15781 if (mode->flags & (DRM_MODE_FLAG_BCAST |
15782 DRM_MODE_FLAG_PIXMUX |
15783 DRM_MODE_FLAG_CLKDIV2))
15786 if (INTEL_GEN(dev_priv) >= 9 ||
15787 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
15788 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
15789 vdisplay_max = 4096;
15792 } else if (INTEL_GEN(dev_priv) >= 3) {
15793 hdisplay_max = 4096;
15794 vdisplay_max = 4096;
15798 hdisplay_max = 2048;
15799 vdisplay_max = 2048;
15804 if (mode->hdisplay > hdisplay_max ||
15805 mode->hsync_start > htotal_max ||
15806 mode->hsync_end > htotal_max ||
15807 mode->htotal > htotal_max)
15808 return MODE_H_ILLEGAL;
15810 if (mode->vdisplay > vdisplay_max ||
15811 mode->vsync_start > vtotal_max ||
15812 mode->vsync_end > vtotal_max ||
15813 mode->vtotal > vtotal_max)
15814 return MODE_V_ILLEGAL;
15819 static const struct drm_mode_config_funcs intel_mode_funcs = {
15820 .fb_create = intel_user_framebuffer_create,
15821 .get_format_info = intel_get_format_info,
15822 .output_poll_changed = intel_fbdev_output_poll_changed,
15823 .mode_valid = intel_mode_valid,
15824 .atomic_check = intel_atomic_check,
15825 .atomic_commit = intel_atomic_commit,
15826 .atomic_state_alloc = intel_atomic_state_alloc,
15827 .atomic_state_clear = intel_atomic_state_clear,
15828 .atomic_state_free = intel_atomic_state_free,
15832 * intel_init_display_hooks - initialize the display modesetting hooks
15833 * @dev_priv: device private
15835 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
15837 intel_init_cdclk_hooks(dev_priv);
15839 if (INTEL_GEN(dev_priv) >= 9) {
15840 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
15841 dev_priv->display.get_initial_plane_config =
15842 skylake_get_initial_plane_config;
15843 dev_priv->display.crtc_compute_clock =
15844 haswell_crtc_compute_clock;
15845 dev_priv->display.crtc_enable = haswell_crtc_enable;
15846 dev_priv->display.crtc_disable = haswell_crtc_disable;
15847 } else if (HAS_DDI(dev_priv)) {
15848 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
15849 dev_priv->display.get_initial_plane_config =
15850 i9xx_get_initial_plane_config;
15851 dev_priv->display.crtc_compute_clock =
15852 haswell_crtc_compute_clock;
15853 dev_priv->display.crtc_enable = haswell_crtc_enable;
15854 dev_priv->display.crtc_disable = haswell_crtc_disable;
15855 } else if (HAS_PCH_SPLIT(dev_priv)) {
15856 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
15857 dev_priv->display.get_initial_plane_config =
15858 i9xx_get_initial_plane_config;
15859 dev_priv->display.crtc_compute_clock =
15860 ironlake_crtc_compute_clock;
15861 dev_priv->display.crtc_enable = ironlake_crtc_enable;
15862 dev_priv->display.crtc_disable = ironlake_crtc_disable;
15863 } else if (IS_CHERRYVIEW(dev_priv)) {
15864 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15865 dev_priv->display.get_initial_plane_config =
15866 i9xx_get_initial_plane_config;
15867 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
15868 dev_priv->display.crtc_enable = valleyview_crtc_enable;
15869 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15870 } else if (IS_VALLEYVIEW(dev_priv)) {
15871 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15872 dev_priv->display.get_initial_plane_config =
15873 i9xx_get_initial_plane_config;
15874 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
15875 dev_priv->display.crtc_enable = valleyview_crtc_enable;
15876 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15877 } else if (IS_G4X(dev_priv)) {
15878 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15879 dev_priv->display.get_initial_plane_config =
15880 i9xx_get_initial_plane_config;
15881 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
15882 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15883 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15884 } else if (IS_PINEVIEW(dev_priv)) {
15885 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15886 dev_priv->display.get_initial_plane_config =
15887 i9xx_get_initial_plane_config;
15888 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
15889 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15890 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15891 } else if (!IS_GEN(dev_priv, 2)) {
15892 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15893 dev_priv->display.get_initial_plane_config =
15894 i9xx_get_initial_plane_config;
15895 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
15896 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15897 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15899 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15900 dev_priv->display.get_initial_plane_config =
15901 i9xx_get_initial_plane_config;
15902 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
15903 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15904 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15907 if (IS_GEN(dev_priv, 5)) {
15908 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
15909 } else if (IS_GEN(dev_priv, 6)) {
15910 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
15911 } else if (IS_IVYBRIDGE(dev_priv)) {
15912 /* FIXME: detect B0+ stepping and use auto training */
15913 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
15914 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
15915 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
15918 if (INTEL_GEN(dev_priv) >= 9)
15919 dev_priv->display.update_crtcs = skl_update_crtcs;
15921 dev_priv->display.update_crtcs = intel_update_crtcs;
15924 static i915_reg_t i915_vgacntrl_reg(struct drm_i915_private *dev_priv)
15926 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
15927 return VLV_VGACNTRL;
15928 else if (INTEL_GEN(dev_priv) >= 5)
15929 return CPU_VGACNTRL;
15934 /* Disable the VGA plane that we never use */
15935 static void i915_disable_vga(struct drm_i915_private *dev_priv)
15937 struct pci_dev *pdev = dev_priv->drm.pdev;
15939 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
15941 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
15942 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
15943 outb(SR01, VGA_SR_INDEX);
15944 sr1 = inb(VGA_SR_DATA);
15945 outb(sr1 | 1<<5, VGA_SR_DATA);
15946 vga_put(pdev, VGA_RSRC_LEGACY_IO);
15949 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
15950 POSTING_READ(vga_reg);
15953 void intel_modeset_init_hw(struct drm_device *dev)
15955 struct drm_i915_private *dev_priv = to_i915(dev);
15957 intel_update_cdclk(dev_priv);
15958 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
15959 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
15963 * Calculate what we think the watermarks should be for the state we've read
15964 * out of the hardware and then immediately program those watermarks so that
15965 * we ensure the hardware settings match our internal state.
15967 * We can calculate what we think WM's should be by creating a duplicate of the
15968 * current state (which was constructed during hardware readout) and running it
15969 * through the atomic check code to calculate new watermark values in the
15972 static void sanitize_watermarks(struct drm_device *dev)
15974 struct drm_i915_private *dev_priv = to_i915(dev);
15975 struct drm_atomic_state *state;
15976 struct intel_atomic_state *intel_state;
15977 struct intel_crtc *crtc;
15978 struct intel_crtc_state *crtc_state;
15979 struct drm_modeset_acquire_ctx ctx;
15983 /* Only supported on platforms that use atomic watermark design */
15984 if (!dev_priv->display.optimize_watermarks)
15988 * We need to hold connection_mutex before calling duplicate_state so
15989 * that the connector loop is protected.
15991 drm_modeset_acquire_init(&ctx, 0);
15993 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15994 if (ret == -EDEADLK) {
15995 drm_modeset_backoff(&ctx);
15997 } else if (WARN_ON(ret)) {
16001 state = drm_atomic_helper_duplicate_state(dev, &ctx);
16002 if (WARN_ON(IS_ERR(state)))
16005 intel_state = to_intel_atomic_state(state);
16008 * Hardware readout is the only time we don't want to calculate
16009 * intermediate watermarks (since we don't trust the current
16012 if (!HAS_GMCH(dev_priv))
16013 intel_state->skip_intermediate_wm = true;
16015 ret = intel_atomic_check(dev, state);
16018 * If we fail here, it means that the hardware appears to be
16019 * programmed in a way that shouldn't be possible, given our
16020 * understanding of watermark requirements. This might mean a
16021 * mistake in the hardware readout code or a mistake in the
16022 * watermark calculations for a given platform. Raise a WARN
16023 * so that this is noticeable.
16025 * If this actually happens, we'll have to just leave the
16026 * BIOS-programmed watermarks untouched and hope for the best.
16028 WARN(true, "Could not determine valid watermarks for inherited state\n");
16032 /* Write calculated watermark values back */
16033 for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) {
16034 crtc_state->wm.need_postvbl_update = true;
16035 dev_priv->display.optimize_watermarks(intel_state, crtc_state);
16037 to_intel_crtc_state(crtc->base.state)->wm = crtc_state->wm;
16041 drm_atomic_state_put(state);
16043 drm_modeset_drop_locks(&ctx);
16044 drm_modeset_acquire_fini(&ctx);
16047 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
16049 if (IS_GEN(dev_priv, 5)) {
16051 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
16053 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
16054 } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) {
16055 dev_priv->fdi_pll_freq = 270000;
16060 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
16063 static int intel_initial_commit(struct drm_device *dev)
16065 struct drm_atomic_state *state = NULL;
16066 struct drm_modeset_acquire_ctx ctx;
16067 struct drm_crtc *crtc;
16068 struct drm_crtc_state *crtc_state;
16071 state = drm_atomic_state_alloc(dev);
16075 drm_modeset_acquire_init(&ctx, 0);
16078 state->acquire_ctx = &ctx;
16080 drm_for_each_crtc(crtc, dev) {
16081 crtc_state = drm_atomic_get_crtc_state(state, crtc);
16082 if (IS_ERR(crtc_state)) {
16083 ret = PTR_ERR(crtc_state);
16087 if (crtc_state->active) {
16088 ret = drm_atomic_add_affected_planes(state, crtc);
16093 * FIXME hack to force a LUT update to avoid the
16094 * plane update forcing the pipe gamma on without
16095 * having a proper LUT loaded. Remove once we
16096 * have readout for pipe gamma enable.
16098 crtc_state->color_mgmt_changed = true;
16102 ret = drm_atomic_commit(state);
16105 if (ret == -EDEADLK) {
16106 drm_atomic_state_clear(state);
16107 drm_modeset_backoff(&ctx);
16111 drm_atomic_state_put(state);
16113 drm_modeset_drop_locks(&ctx);
16114 drm_modeset_acquire_fini(&ctx);
16119 int intel_modeset_init(struct drm_device *dev)
16121 struct drm_i915_private *dev_priv = to_i915(dev);
16123 struct intel_crtc *crtc;
16126 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
16128 drm_mode_config_init(dev);
16130 ret = intel_bw_init(dev_priv);
16134 dev->mode_config.min_width = 0;
16135 dev->mode_config.min_height = 0;
16137 dev->mode_config.preferred_depth = 24;
16138 dev->mode_config.prefer_shadow = 1;
16140 dev->mode_config.allow_fb_modifiers = true;
16142 dev->mode_config.funcs = &intel_mode_funcs;
16144 init_llist_head(&dev_priv->atomic_helper.free_list);
16145 INIT_WORK(&dev_priv->atomic_helper.free_work,
16146 intel_atomic_helper_free_state_worker);
16148 intel_init_quirks(dev_priv);
16150 intel_fbc_init(dev_priv);
16152 intel_init_pm(dev_priv);
16155 * There may be no VBT; and if the BIOS enabled SSC we can
16156 * just keep using it to avoid unnecessary flicker. Whereas if the
16157 * BIOS isn't using it, don't assume it will work even if the VBT
16158 * indicates as much.
16160 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
16161 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
16164 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
16165 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
16166 bios_lvds_use_ssc ? "en" : "dis",
16167 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
16168 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
16173 * Maximum framebuffer dimensions, chosen to match
16174 * the maximum render engine surface size on gen4+.
16176 if (INTEL_GEN(dev_priv) >= 7) {
16177 dev->mode_config.max_width = 16384;
16178 dev->mode_config.max_height = 16384;
16179 } else if (INTEL_GEN(dev_priv) >= 4) {
16180 dev->mode_config.max_width = 8192;
16181 dev->mode_config.max_height = 8192;
16182 } else if (IS_GEN(dev_priv, 3)) {
16183 dev->mode_config.max_width = 4096;
16184 dev->mode_config.max_height = 4096;
16186 dev->mode_config.max_width = 2048;
16187 dev->mode_config.max_height = 2048;
16190 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
16191 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
16192 dev->mode_config.cursor_height = 1023;
16193 } else if (IS_GEN(dev_priv, 2)) {
16194 dev->mode_config.cursor_width = 64;
16195 dev->mode_config.cursor_height = 64;
16197 dev->mode_config.cursor_width = 256;
16198 dev->mode_config.cursor_height = 256;
16201 DRM_DEBUG_KMS("%d display pipe%s available.\n",
16202 INTEL_INFO(dev_priv)->num_pipes,
16203 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
16205 for_each_pipe(dev_priv, pipe) {
16206 ret = intel_crtc_init(dev_priv, pipe);
16208 drm_mode_config_cleanup(dev);
16213 intel_shared_dpll_init(dev);
16214 intel_update_fdi_pll_freq(dev_priv);
16216 intel_update_czclk(dev_priv);
16217 intel_modeset_init_hw(dev);
16219 intel_hdcp_component_init(dev_priv);
16221 if (dev_priv->max_cdclk_freq == 0)
16222 intel_update_max_cdclk(dev_priv);
16224 /* Just disable it once at startup */
16225 i915_disable_vga(dev_priv);
16226 intel_setup_outputs(dev_priv);
16228 drm_modeset_lock_all(dev);
16229 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
16230 drm_modeset_unlock_all(dev);
16232 for_each_intel_crtc(dev, crtc) {
16233 struct intel_initial_plane_config plane_config = {};
16239 * Note that reserving the BIOS fb up front prevents us
16240 * from stuffing other stolen allocations like the ring
16241 * on top. This prevents some ugliness at boot time, and
16242 * can even allow for smooth boot transitions if the BIOS
16243 * fb is large enough for the active pipe configuration.
16245 dev_priv->display.get_initial_plane_config(crtc,
16249 * If the fb is shared between multiple heads, we'll
16250 * just get the first one.
16252 intel_find_initial_plane_obj(crtc, &plane_config);
16256 * Make sure hardware watermarks really match the state we read out.
16257 * Note that we need to do this after reconstructing the BIOS fb's
16258 * since the watermark calculation done here will use pstate->fb.
16260 if (!HAS_GMCH(dev_priv))
16261 sanitize_watermarks(dev);
16264 * Force all active planes to recompute their states. So that on
16265 * mode_setcrtc after probe, all the intel_plane_state variables
16266 * are already calculated and there is no assert_plane warnings
16269 ret = intel_initial_commit(dev);
16271 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
16276 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
16278 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
16279 /* 640x480@60Hz, ~25175 kHz */
16280 struct dpll clock = {
16290 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
16292 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
16293 pipe_name(pipe), clock.vco, clock.dot);
16295 fp = i9xx_dpll_compute_fp(&clock);
16296 dpll = DPLL_DVO_2X_MODE |
16297 DPLL_VGA_MODE_DIS |
16298 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
16299 PLL_P2_DIVIDE_BY_4 |
16300 PLL_REF_INPUT_DREFCLK |
16303 I915_WRITE(FP0(pipe), fp);
16304 I915_WRITE(FP1(pipe), fp);
16306 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
16307 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
16308 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
16309 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
16310 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
16311 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
16312 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
16315 * Apparently we need to have VGA mode enabled prior to changing
16316 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
16317 * dividers, even though the register value does change.
16319 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
16320 I915_WRITE(DPLL(pipe), dpll);
16322 /* Wait for the clocks to stabilize. */
16323 POSTING_READ(DPLL(pipe));
16326 /* The pixel multiplier can only be updated once the
16327 * DPLL is enabled and the clocks are stable.
16329 * So write it again.
16331 I915_WRITE(DPLL(pipe), dpll);
16333 /* We do this three times for luck */
16334 for (i = 0; i < 3 ; i++) {
16335 I915_WRITE(DPLL(pipe), dpll);
16336 POSTING_READ(DPLL(pipe));
16337 udelay(150); /* wait for warmup */
16340 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
16341 POSTING_READ(PIPECONF(pipe));
16343 intel_wait_for_pipe_scanline_moving(crtc);
16346 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
16348 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
16350 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
16353 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
16354 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
16355 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
16356 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
16357 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
16359 I915_WRITE(PIPECONF(pipe), 0);
16360 POSTING_READ(PIPECONF(pipe));
16362 intel_wait_for_pipe_scanline_stopped(crtc);
16364 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
16365 POSTING_READ(DPLL(pipe));
16369 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
16371 struct intel_crtc *crtc;
16373 if (INTEL_GEN(dev_priv) >= 4)
16376 for_each_intel_crtc(&dev_priv->drm, crtc) {
16377 struct intel_plane *plane =
16378 to_intel_plane(crtc->base.primary);
16379 struct intel_crtc *plane_crtc;
16382 if (!plane->get_hw_state(plane, &pipe))
16385 if (pipe == crtc->pipe)
16388 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
16389 plane->base.base.id, plane->base.name);
16391 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
16392 intel_plane_disable_noatomic(plane_crtc, plane);
16396 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
16398 struct drm_device *dev = crtc->base.dev;
16399 struct intel_encoder *encoder;
16401 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
16407 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
16409 struct drm_device *dev = encoder->base.dev;
16410 struct intel_connector *connector;
16412 for_each_connector_on_encoder(dev, &encoder->base, connector)
16418 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
16419 enum pipe pch_transcoder)
16421 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
16422 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
16425 static void intel_sanitize_crtc(struct intel_crtc *crtc,
16426 struct drm_modeset_acquire_ctx *ctx)
16428 struct drm_device *dev = crtc->base.dev;
16429 struct drm_i915_private *dev_priv = to_i915(dev);
16430 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
16431 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
16433 /* Clear any frame start delays used for debugging left by the BIOS */
16434 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
16435 i915_reg_t reg = PIPECONF(cpu_transcoder);
16438 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
16441 if (crtc_state->base.active) {
16442 struct intel_plane *plane;
16444 /* Disable everything but the primary plane */
16445 for_each_intel_plane_on_crtc(dev, crtc, plane) {
16446 const struct intel_plane_state *plane_state =
16447 to_intel_plane_state(plane->base.state);
16449 if (plane_state->base.visible &&
16450 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
16451 intel_plane_disable_noatomic(crtc, plane);
16455 * Disable any background color set by the BIOS, but enable the
16456 * gamma and CSC to match how we program our planes.
16458 if (INTEL_GEN(dev_priv) >= 9)
16459 I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe),
16460 SKL_BOTTOM_COLOR_GAMMA_ENABLE |
16461 SKL_BOTTOM_COLOR_CSC_ENABLE);
16464 /* Adjust the state of the output pipe according to whether we
16465 * have active connectors/encoders. */
16466 if (crtc_state->base.active && !intel_crtc_has_encoders(crtc))
16467 intel_crtc_disable_noatomic(&crtc->base, ctx);
16469 if (crtc_state->base.active || HAS_GMCH(dev_priv)) {
16471 * We start out with underrun reporting disabled to avoid races.
16472 * For correct bookkeeping mark this on active crtcs.
16474 * Also on gmch platforms we dont have any hardware bits to
16475 * disable the underrun reporting. Which means we need to start
16476 * out with underrun reporting disabled also on inactive pipes,
16477 * since otherwise we'll complain about the garbage we read when
16478 * e.g. coming up after runtime pm.
16480 * No protection against concurrent access is required - at
16481 * worst a fifo underrun happens which also sets this to false.
16483 crtc->cpu_fifo_underrun_disabled = true;
16485 * We track the PCH trancoder underrun reporting state
16486 * within the crtc. With crtc for pipe A housing the underrun
16487 * reporting state for PCH transcoder A, crtc for pipe B housing
16488 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
16489 * and marking underrun reporting as disabled for the non-existing
16490 * PCH transcoders B and C would prevent enabling the south
16491 * error interrupt (see cpt_can_enable_serr_int()).
16493 if (has_pch_trancoder(dev_priv, crtc->pipe))
16494 crtc->pch_fifo_underrun_disabled = true;
16498 static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state)
16500 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
16503 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
16504 * the hardware when a high res displays plugged in. DPLL P
16505 * divider is zero, and the pipe timings are bonkers. We'll
16506 * try to disable everything in that case.
16508 * FIXME would be nice to be able to sanitize this state
16509 * without several WARNs, but for now let's take the easy
16512 return IS_GEN(dev_priv, 6) &&
16513 crtc_state->base.active &&
16514 crtc_state->shared_dpll &&
16515 crtc_state->port_clock == 0;
16518 static void intel_sanitize_encoder(struct intel_encoder *encoder)
16520 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
16521 struct intel_connector *connector;
16522 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
16523 struct intel_crtc_state *crtc_state = crtc ?
16524 to_intel_crtc_state(crtc->base.state) : NULL;
16526 /* We need to check both for a crtc link (meaning that the
16527 * encoder is active and trying to read from a pipe) and the
16528 * pipe itself being active. */
16529 bool has_active_crtc = crtc_state &&
16530 crtc_state->base.active;
16532 if (crtc_state && has_bogus_dpll_config(crtc_state)) {
16533 DRM_DEBUG_KMS("BIOS has misprogrammed the hardware. Disabling pipe %c\n",
16534 pipe_name(crtc->pipe));
16535 has_active_crtc = false;
16538 connector = intel_encoder_find_connector(encoder);
16539 if (connector && !has_active_crtc) {
16540 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
16541 encoder->base.base.id,
16542 encoder->base.name);
16544 /* Connector is active, but has no active pipe. This is
16545 * fallout from our resume register restoring. Disable
16546 * the encoder manually again. */
16548 struct drm_encoder *best_encoder;
16550 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
16551 encoder->base.base.id,
16552 encoder->base.name);
16554 /* avoid oopsing in case the hooks consult best_encoder */
16555 best_encoder = connector->base.state->best_encoder;
16556 connector->base.state->best_encoder = &encoder->base;
16558 if (encoder->disable)
16559 encoder->disable(encoder, crtc_state,
16560 connector->base.state);
16561 if (encoder->post_disable)
16562 encoder->post_disable(encoder, crtc_state,
16563 connector->base.state);
16565 connector->base.state->best_encoder = best_encoder;
16567 encoder->base.crtc = NULL;
16569 /* Inconsistent output/port/pipe state happens presumably due to
16570 * a bug in one of the get_hw_state functions. Or someplace else
16571 * in our code, like the register restore mess on resume. Clamp
16572 * things to off as a safer default. */
16574 connector->base.dpms = DRM_MODE_DPMS_OFF;
16575 connector->base.encoder = NULL;
16578 /* notify opregion of the sanitized encoder state */
16579 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
16581 if (INTEL_GEN(dev_priv) >= 11)
16582 icl_sanitize_encoder_pll_mapping(encoder);
16585 void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
16587 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
16589 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
16590 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
16591 i915_disable_vga(dev_priv);
16595 void i915_redisable_vga(struct drm_i915_private *dev_priv)
16597 intel_wakeref_t wakeref;
16600 * This function can be called both from intel_modeset_setup_hw_state or
16601 * at a very early point in our resume sequence, where the power well
16602 * structures are not yet restored. Since this function is at a very
16603 * paranoid "someone might have enabled VGA while we were not looking"
16604 * level, just check if the power well is enabled instead of trying to
16605 * follow the "don't touch the power well if we don't need it" policy
16606 * the rest of the driver uses.
16608 wakeref = intel_display_power_get_if_enabled(dev_priv,
16613 i915_redisable_vga_power_on(dev_priv);
16615 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA, wakeref);
16618 /* FIXME read out full plane state for all planes */
16619 static void readout_plane_state(struct drm_i915_private *dev_priv)
16621 struct intel_plane *plane;
16622 struct intel_crtc *crtc;
16624 for_each_intel_plane(&dev_priv->drm, plane) {
16625 struct intel_plane_state *plane_state =
16626 to_intel_plane_state(plane->base.state);
16627 struct intel_crtc_state *crtc_state;
16628 enum pipe pipe = PIPE_A;
16631 visible = plane->get_hw_state(plane, &pipe);
16633 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
16634 crtc_state = to_intel_crtc_state(crtc->base.state);
16636 intel_set_plane_visible(crtc_state, plane_state, visible);
16638 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
16639 plane->base.base.id, plane->base.name,
16640 enableddisabled(visible), pipe_name(pipe));
16643 for_each_intel_crtc(&dev_priv->drm, crtc) {
16644 struct intel_crtc_state *crtc_state =
16645 to_intel_crtc_state(crtc->base.state);
16647 fixup_active_planes(crtc_state);
16651 static void intel_modeset_readout_hw_state(struct drm_device *dev)
16653 struct drm_i915_private *dev_priv = to_i915(dev);
16655 struct intel_crtc *crtc;
16656 struct intel_encoder *encoder;
16657 struct intel_connector *connector;
16658 struct drm_connector_list_iter conn_iter;
16661 dev_priv->active_crtcs = 0;
16663 for_each_intel_crtc(dev, crtc) {
16664 struct intel_crtc_state *crtc_state =
16665 to_intel_crtc_state(crtc->base.state);
16667 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
16668 memset(crtc_state, 0, sizeof(*crtc_state));
16669 __drm_atomic_helper_crtc_reset(&crtc->base, &crtc_state->base);
16671 crtc_state->base.active = crtc_state->base.enable =
16672 dev_priv->display.get_pipe_config(crtc, crtc_state);
16674 crtc->base.enabled = crtc_state->base.enable;
16675 crtc->active = crtc_state->base.active;
16677 if (crtc_state->base.active)
16678 dev_priv->active_crtcs |= 1 << crtc->pipe;
16680 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
16681 crtc->base.base.id, crtc->base.name,
16682 enableddisabled(crtc_state->base.active));
16685 readout_plane_state(dev_priv);
16687 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
16688 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
16690 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
16691 &pll->state.hw_state);
16693 if (IS_ELKHARTLAKE(dev_priv) && pll->on &&
16694 pll->info->id == DPLL_ID_EHL_DPLL4) {
16695 pll->wakeref = intel_display_power_get(dev_priv,
16696 POWER_DOMAIN_DPLL_DC_OFF);
16699 pll->state.crtc_mask = 0;
16700 for_each_intel_crtc(dev, crtc) {
16701 struct intel_crtc_state *crtc_state =
16702 to_intel_crtc_state(crtc->base.state);
16704 if (crtc_state->base.active &&
16705 crtc_state->shared_dpll == pll)
16706 pll->state.crtc_mask |= 1 << crtc->pipe;
16708 pll->active_mask = pll->state.crtc_mask;
16710 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
16711 pll->info->name, pll->state.crtc_mask, pll->on);
16714 for_each_intel_encoder(dev, encoder) {
16717 if (encoder->get_hw_state(encoder, &pipe)) {
16718 struct intel_crtc_state *crtc_state;
16720 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
16721 crtc_state = to_intel_crtc_state(crtc->base.state);
16723 encoder->base.crtc = &crtc->base;
16724 encoder->get_config(encoder, crtc_state);
16726 encoder->base.crtc = NULL;
16729 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
16730 encoder->base.base.id, encoder->base.name,
16731 enableddisabled(encoder->base.crtc),
16735 drm_connector_list_iter_begin(dev, &conn_iter);
16736 for_each_intel_connector_iter(connector, &conn_iter) {
16737 if (connector->get_hw_state(connector)) {
16738 connector->base.dpms = DRM_MODE_DPMS_ON;
16740 encoder = connector->encoder;
16741 connector->base.encoder = &encoder->base;
16743 if (encoder->base.crtc &&
16744 encoder->base.crtc->state->active) {
16746 * This has to be done during hardware readout
16747 * because anything calling .crtc_disable may
16748 * rely on the connector_mask being accurate.
16750 encoder->base.crtc->state->connector_mask |=
16751 drm_connector_mask(&connector->base);
16752 encoder->base.crtc->state->encoder_mask |=
16753 drm_encoder_mask(&encoder->base);
16757 connector->base.dpms = DRM_MODE_DPMS_OFF;
16758 connector->base.encoder = NULL;
16760 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
16761 connector->base.base.id, connector->base.name,
16762 enableddisabled(connector->base.encoder));
16764 drm_connector_list_iter_end(&conn_iter);
16766 for_each_intel_crtc(dev, crtc) {
16767 struct intel_bw_state *bw_state =
16768 to_intel_bw_state(dev_priv->bw_obj.state);
16769 struct intel_crtc_state *crtc_state =
16770 to_intel_crtc_state(crtc->base.state);
16771 struct intel_plane *plane;
16774 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
16775 if (crtc_state->base.active) {
16776 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
16777 crtc->base.mode.hdisplay = crtc_state->pipe_src_w;
16778 crtc->base.mode.vdisplay = crtc_state->pipe_src_h;
16779 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
16780 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
16783 * The initial mode needs to be set in order to keep
16784 * the atomic core happy. It wants a valid mode if the
16785 * crtc's enabled, so we do the above call.
16787 * But we don't set all the derived state fully, hence
16788 * set a flag to indicate that a full recalculation is
16789 * needed on the next commit.
16791 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
16793 intel_crtc_compute_pixel_rate(crtc_state);
16795 if (dev_priv->display.modeset_calc_cdclk) {
16796 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
16797 if (WARN_ON(min_cdclk < 0))
16801 drm_calc_timestamping_constants(&crtc->base,
16802 &crtc_state->base.adjusted_mode);
16803 update_scanline_offset(crtc_state);
16806 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
16807 dev_priv->min_voltage_level[crtc->pipe] =
16808 crtc_state->min_voltage_level;
16810 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
16811 const struct intel_plane_state *plane_state =
16812 to_intel_plane_state(plane->base.state);
16815 * FIXME don't have the fb yet, so can't
16816 * use intel_plane_data_rate() :(
16818 if (plane_state->base.visible)
16819 crtc_state->data_rate[plane->id] =
16820 4 * crtc_state->pixel_rate;
16823 intel_bw_crtc_update(bw_state, crtc_state);
16825 intel_pipe_config_sanity_check(dev_priv, crtc_state);
16830 get_encoder_power_domains(struct drm_i915_private *dev_priv)
16832 struct intel_encoder *encoder;
16834 for_each_intel_encoder(&dev_priv->drm, encoder) {
16835 struct intel_crtc_state *crtc_state;
16837 if (!encoder->get_power_domains)
16841 * MST-primary and inactive encoders don't have a crtc state
16842 * and neither of these require any power domain references.
16844 if (!encoder->base.crtc)
16847 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
16848 encoder->get_power_domains(encoder, crtc_state);
16852 static void intel_early_display_was(struct drm_i915_private *dev_priv)
16854 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
16855 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
16856 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
16859 if (IS_HASWELL(dev_priv)) {
16861 * WaRsPkgCStateDisplayPMReq:hsw
16862 * System hang if this isn't done before disabling all planes!
16864 I915_WRITE(CHICKEN_PAR1_1,
16865 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
16869 static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
16870 enum port port, i915_reg_t hdmi_reg)
16872 u32 val = I915_READ(hdmi_reg);
16874 if (val & SDVO_ENABLE ||
16875 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
16878 DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n",
16881 val &= ~SDVO_PIPE_SEL_MASK;
16882 val |= SDVO_PIPE_SEL(PIPE_A);
16884 I915_WRITE(hdmi_reg, val);
16887 static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
16888 enum port port, i915_reg_t dp_reg)
16890 u32 val = I915_READ(dp_reg);
16892 if (val & DP_PORT_EN ||
16893 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
16896 DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n",
16899 val &= ~DP_PIPE_SEL_MASK;
16900 val |= DP_PIPE_SEL(PIPE_A);
16902 I915_WRITE(dp_reg, val);
16905 static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
16908 * The BIOS may select transcoder B on some of the PCH
16909 * ports even it doesn't enable the port. This would trip
16910 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
16911 * Sanitize the transcoder select bits to prevent that. We
16912 * assume that the BIOS never actually enabled the port,
16913 * because if it did we'd actually have to toggle the port
16914 * on and back off to make the transcoder A select stick
16915 * (see. intel_dp_link_down(), intel_disable_hdmi(),
16916 * intel_disable_sdvo()).
16918 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
16919 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
16920 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
16922 /* PCH SDVOB multiplex with HDMIB */
16923 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
16924 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
16925 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
16928 /* Scan out the current hw modeset state,
16929 * and sanitizes it to the current state
16932 intel_modeset_setup_hw_state(struct drm_device *dev,
16933 struct drm_modeset_acquire_ctx *ctx)
16935 struct drm_i915_private *dev_priv = to_i915(dev);
16936 struct intel_crtc_state *crtc_state;
16937 struct intel_encoder *encoder;
16938 struct intel_crtc *crtc;
16939 intel_wakeref_t wakeref;
16942 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
16944 intel_early_display_was(dev_priv);
16945 intel_modeset_readout_hw_state(dev);
16947 /* HW state is read out, now we need to sanitize this mess. */
16949 /* Sanitize the TypeC port mode upfront, encoders depend on this */
16950 for_each_intel_encoder(dev, encoder) {
16951 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
16953 /* We need to sanitize only the MST primary port. */
16954 if (encoder->type != INTEL_OUTPUT_DP_MST &&
16955 intel_phy_is_tc(dev_priv, phy))
16956 intel_tc_port_sanitize(enc_to_dig_port(&encoder->base));
16959 get_encoder_power_domains(dev_priv);
16961 if (HAS_PCH_IBX(dev_priv))
16962 ibx_sanitize_pch_ports(dev_priv);
16965 * intel_sanitize_plane_mapping() may need to do vblank
16966 * waits, so we need vblank interrupts restored beforehand.
16968 for_each_intel_crtc(&dev_priv->drm, crtc) {
16969 crtc_state = to_intel_crtc_state(crtc->base.state);
16971 drm_crtc_vblank_reset(&crtc->base);
16973 if (crtc_state->base.active)
16974 intel_crtc_vblank_on(crtc_state);
16977 intel_sanitize_plane_mapping(dev_priv);
16979 for_each_intel_encoder(dev, encoder)
16980 intel_sanitize_encoder(encoder);
16982 for_each_intel_crtc(&dev_priv->drm, crtc) {
16983 crtc_state = to_intel_crtc_state(crtc->base.state);
16984 intel_sanitize_crtc(crtc, ctx);
16985 intel_dump_pipe_config(crtc_state, NULL, "[setup_hw_state]");
16988 intel_modeset_update_connector_atomic_state(dev);
16990 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
16991 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
16993 if (!pll->on || pll->active_mask)
16996 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
16999 pll->info->funcs->disable(dev_priv, pll);
17003 if (IS_G4X(dev_priv)) {
17004 g4x_wm_get_hw_state(dev_priv);
17005 g4x_wm_sanitize(dev_priv);
17006 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
17007 vlv_wm_get_hw_state(dev_priv);
17008 vlv_wm_sanitize(dev_priv);
17009 } else if (INTEL_GEN(dev_priv) >= 9) {
17010 skl_wm_get_hw_state(dev_priv);
17011 } else if (HAS_PCH_SPLIT(dev_priv)) {
17012 ilk_wm_get_hw_state(dev_priv);
17015 for_each_intel_crtc(dev, crtc) {
17018 crtc_state = to_intel_crtc_state(crtc->base.state);
17019 put_domains = modeset_get_crtc_power_domains(crtc_state);
17020 if (WARN_ON(put_domains))
17021 modeset_put_power_domains(dev_priv, put_domains);
17024 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
17026 intel_fbc_init_pipe_state(dev_priv);
17029 void intel_display_resume(struct drm_device *dev)
17031 struct drm_i915_private *dev_priv = to_i915(dev);
17032 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
17033 struct drm_modeset_acquire_ctx ctx;
17036 dev_priv->modeset_restore_state = NULL;
17038 state->acquire_ctx = &ctx;
17040 drm_modeset_acquire_init(&ctx, 0);
17043 ret = drm_modeset_lock_all_ctx(dev, &ctx);
17044 if (ret != -EDEADLK)
17047 drm_modeset_backoff(&ctx);
17051 ret = __intel_display_resume(dev, state, &ctx);
17053 intel_enable_ipc(dev_priv);
17054 drm_modeset_drop_locks(&ctx);
17055 drm_modeset_acquire_fini(&ctx);
17058 DRM_ERROR("Restoring old state failed with %i\n", ret);
17060 drm_atomic_state_put(state);
17063 static void intel_hpd_poll_fini(struct drm_device *dev)
17065 struct intel_connector *connector;
17066 struct drm_connector_list_iter conn_iter;
17068 /* Kill all the work that may have been queued by hpd. */
17069 drm_connector_list_iter_begin(dev, &conn_iter);
17070 for_each_intel_connector_iter(connector, &conn_iter) {
17071 if (connector->modeset_retry_work.func)
17072 cancel_work_sync(&connector->modeset_retry_work);
17073 if (connector->hdcp.shim) {
17074 cancel_delayed_work_sync(&connector->hdcp.check_work);
17075 cancel_work_sync(&connector->hdcp.prop_work);
17078 drm_connector_list_iter_end(&conn_iter);
17081 void intel_modeset_driver_remove(struct drm_device *dev)
17083 struct drm_i915_private *dev_priv = to_i915(dev);
17085 flush_workqueue(dev_priv->modeset_wq);
17087 flush_work(&dev_priv->atomic_helper.free_work);
17088 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
17091 * Interrupts and polling as the first thing to avoid creating havoc.
17092 * Too much stuff here (turning of connectors, ...) would
17093 * experience fancy races otherwise.
17095 intel_irq_uninstall(dev_priv);
17098 * Due to the hpd irq storm handling the hotplug work can re-arm the
17099 * poll handlers. Hence disable polling after hpd handling is shut down.
17101 intel_hpd_poll_fini(dev);
17103 /* poll work can call into fbdev, hence clean that up afterwards */
17104 intel_fbdev_fini(dev_priv);
17106 intel_unregister_dsm_handler();
17108 intel_fbc_global_disable(dev_priv);
17110 /* flush any delayed tasks or pending work */
17111 flush_scheduled_work();
17113 intel_hdcp_component_fini(dev_priv);
17115 drm_mode_config_cleanup(dev);
17117 intel_overlay_cleanup(dev_priv);
17119 intel_gmbus_teardown(dev_priv);
17121 destroy_workqueue(dev_priv->modeset_wq);
17123 intel_fbc_cleanup_cfb(dev_priv);
17127 * set vga decode state - true == enable VGA decode
17129 int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
17131 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
17134 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
17135 DRM_ERROR("failed to read control word\n");
17139 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
17143 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
17145 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
17147 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
17148 DRM_ERROR("failed to write control word\n");
17155 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
17157 struct intel_display_error_state {
17159 u32 power_well_driver;
17161 struct intel_cursor_error_state {
17166 } cursor[I915_MAX_PIPES];
17168 struct intel_pipe_error_state {
17169 bool power_domain_on;
17172 } pipe[I915_MAX_PIPES];
17174 struct intel_plane_error_state {
17182 } plane[I915_MAX_PIPES];
17184 struct intel_transcoder_error_state {
17186 bool power_domain_on;
17187 enum transcoder cpu_transcoder;
17200 struct intel_display_error_state *
17201 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
17203 struct intel_display_error_state *error;
17204 int transcoders[] = {
17213 BUILD_BUG_ON(ARRAY_SIZE(transcoders) != ARRAY_SIZE(error->transcoder));
17215 if (!HAS_DISPLAY(dev_priv))
17218 error = kzalloc(sizeof(*error), GFP_ATOMIC);
17222 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
17223 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
17225 for_each_pipe(dev_priv, i) {
17226 error->pipe[i].power_domain_on =
17227 __intel_display_power_is_enabled(dev_priv,
17228 POWER_DOMAIN_PIPE(i));
17229 if (!error->pipe[i].power_domain_on)
17232 error->cursor[i].control = I915_READ(CURCNTR(i));
17233 error->cursor[i].position = I915_READ(CURPOS(i));
17234 error->cursor[i].base = I915_READ(CURBASE(i));
17236 error->plane[i].control = I915_READ(DSPCNTR(i));
17237 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
17238 if (INTEL_GEN(dev_priv) <= 3) {
17239 error->plane[i].size = I915_READ(DSPSIZE(i));
17240 error->plane[i].pos = I915_READ(DSPPOS(i));
17242 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
17243 error->plane[i].addr = I915_READ(DSPADDR(i));
17244 if (INTEL_GEN(dev_priv) >= 4) {
17245 error->plane[i].surface = I915_READ(DSPSURF(i));
17246 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
17249 error->pipe[i].source = I915_READ(PIPESRC(i));
17251 if (HAS_GMCH(dev_priv))
17252 error->pipe[i].stat = I915_READ(PIPESTAT(i));
17255 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
17256 enum transcoder cpu_transcoder = transcoders[i];
17258 if (!INTEL_INFO(dev_priv)->trans_offsets[cpu_transcoder])
17261 error->transcoder[i].available = true;
17262 error->transcoder[i].power_domain_on =
17263 __intel_display_power_is_enabled(dev_priv,
17264 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
17265 if (!error->transcoder[i].power_domain_on)
17268 error->transcoder[i].cpu_transcoder = cpu_transcoder;
17270 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
17271 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
17272 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
17273 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
17274 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
17275 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
17276 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
17282 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
17285 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
17286 struct intel_display_error_state *error)
17288 struct drm_i915_private *dev_priv = m->i915;
17294 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
17295 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
17296 err_printf(m, "PWR_WELL_CTL2: %08x\n",
17297 error->power_well_driver);
17298 for_each_pipe(dev_priv, i) {
17299 err_printf(m, "Pipe [%d]:\n", i);
17300 err_printf(m, " Power: %s\n",
17301 onoff(error->pipe[i].power_domain_on));
17302 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
17303 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
17305 err_printf(m, "Plane [%d]:\n", i);
17306 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
17307 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
17308 if (INTEL_GEN(dev_priv) <= 3) {
17309 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
17310 err_printf(m, " POS: %08x\n", error->plane[i].pos);
17312 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
17313 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
17314 if (INTEL_GEN(dev_priv) >= 4) {
17315 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
17316 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
17319 err_printf(m, "Cursor [%d]:\n", i);
17320 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
17321 err_printf(m, " POS: %08x\n", error->cursor[i].position);
17322 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
17325 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
17326 if (!error->transcoder[i].available)
17329 err_printf(m, "CPU transcoder: %s\n",
17330 transcoder_name(error->transcoder[i].cpu_transcoder));
17331 err_printf(m, " Power: %s\n",
17332 onoff(error->transcoder[i].power_domain_on));
17333 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
17334 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
17335 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
17336 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
17337 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
17338 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
17339 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);