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, enum pipe 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 case I915_FORMAT_MOD_Y_TILED_CCS:
3285 case I915_FORMAT_MOD_Yf_TILED_CCS:
3286 /* FIXME AUX plane? */
3287 case I915_FORMAT_MOD_Y_TILED:
3288 case I915_FORMAT_MOD_Yf_TILED:
3294 MISSING_CASE(fb->modifier);
3299 static int glk_max_plane_width(const struct drm_framebuffer *fb,
3301 unsigned int rotation)
3303 int cpp = fb->format->cpp[color_plane];
3305 switch (fb->modifier) {
3306 case DRM_FORMAT_MOD_LINEAR:
3307 case I915_FORMAT_MOD_X_TILED:
3312 case I915_FORMAT_MOD_Y_TILED_CCS:
3313 case I915_FORMAT_MOD_Yf_TILED_CCS:
3314 /* FIXME AUX plane? */
3315 case I915_FORMAT_MOD_Y_TILED:
3316 case I915_FORMAT_MOD_Yf_TILED:
3322 MISSING_CASE(fb->modifier);
3327 static int icl_max_plane_width(const struct drm_framebuffer *fb,
3329 unsigned int rotation)
3334 static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
3335 int main_x, int main_y, u32 main_offset)
3337 const struct drm_framebuffer *fb = plane_state->base.fb;
3338 int hsub = fb->format->hsub;
3339 int vsub = fb->format->vsub;
3340 int aux_x = plane_state->color_plane[1].x;
3341 int aux_y = plane_state->color_plane[1].y;
3342 u32 aux_offset = plane_state->color_plane[1].offset;
3343 u32 alignment = intel_surf_alignment(fb, 1);
3345 while (aux_offset >= main_offset && aux_y <= main_y) {
3348 if (aux_x == main_x && aux_y == main_y)
3351 if (aux_offset == 0)
3356 aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1,
3357 aux_offset, aux_offset - alignment);
3358 aux_x = x * hsub + aux_x % hsub;
3359 aux_y = y * vsub + aux_y % vsub;
3362 if (aux_x != main_x || aux_y != main_y)
3365 plane_state->color_plane[1].offset = aux_offset;
3366 plane_state->color_plane[1].x = aux_x;
3367 plane_state->color_plane[1].y = aux_y;
3372 static int skl_check_main_surface(struct intel_plane_state *plane_state)
3374 struct drm_i915_private *dev_priv = to_i915(plane_state->base.plane->dev);
3375 const struct drm_framebuffer *fb = plane_state->base.fb;
3376 unsigned int rotation = plane_state->base.rotation;
3377 int x = plane_state->base.src.x1 >> 16;
3378 int y = plane_state->base.src.y1 >> 16;
3379 int w = drm_rect_width(&plane_state->base.src) >> 16;
3380 int h = drm_rect_height(&plane_state->base.src) >> 16;
3382 int max_height = 4096;
3383 u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset;
3385 if (INTEL_GEN(dev_priv) >= 11)
3386 max_width = icl_max_plane_width(fb, 0, rotation);
3387 else if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
3388 max_width = glk_max_plane_width(fb, 0, rotation);
3390 max_width = skl_max_plane_width(fb, 0, rotation);
3392 if (w > max_width || h > max_height) {
3393 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
3394 w, h, max_width, max_height);
3398 intel_add_fb_offsets(&x, &y, plane_state, 0);
3399 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
3400 alignment = intel_surf_alignment(fb, 0);
3403 * AUX surface offset is specified as the distance from the
3404 * main surface offset, and it must be non-negative. Make
3405 * sure that is what we will get.
3407 if (offset > aux_offset)
3408 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3409 offset, aux_offset & ~(alignment - 1));
3412 * When using an X-tiled surface, the plane blows up
3413 * if the x offset + width exceed the stride.
3415 * TODO: linear and Y-tiled seem fine, Yf untested,
3417 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3418 int cpp = fb->format->cpp[0];
3420 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
3422 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
3426 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3427 offset, offset - alignment);
3432 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3433 * they match with the main surface x/y offsets.
3435 if (is_ccs_modifier(fb->modifier)) {
3436 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3440 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3441 offset, offset - alignment);
3444 if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) {
3445 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3450 plane_state->color_plane[0].offset = offset;
3451 plane_state->color_plane[0].x = x;
3452 plane_state->color_plane[0].y = y;
3455 * Put the final coordinates back so that the src
3456 * coordinate checks will see the right values.
3458 drm_rect_translate(&plane_state->base.src,
3459 (x << 16) - plane_state->base.src.x1,
3460 (y << 16) - plane_state->base.src.y1);
3465 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3467 const struct drm_framebuffer *fb = plane_state->base.fb;
3468 unsigned int rotation = plane_state->base.rotation;
3469 int max_width = skl_max_plane_width(fb, 1, rotation);
3470 int max_height = 4096;
3471 int x = plane_state->base.src.x1 >> 17;
3472 int y = plane_state->base.src.y1 >> 17;
3473 int w = drm_rect_width(&plane_state->base.src) >> 17;
3474 int h = drm_rect_height(&plane_state->base.src) >> 17;
3477 intel_add_fb_offsets(&x, &y, plane_state, 1);
3478 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3480 /* FIXME not quite sure how/if these apply to the chroma plane */
3481 if (w > max_width || h > max_height) {
3482 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3483 w, h, max_width, max_height);
3487 plane_state->color_plane[1].offset = offset;
3488 plane_state->color_plane[1].x = x;
3489 plane_state->color_plane[1].y = y;
3494 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3496 const struct drm_framebuffer *fb = plane_state->base.fb;
3497 int src_x = plane_state->base.src.x1 >> 16;
3498 int src_y = plane_state->base.src.y1 >> 16;
3499 int hsub = fb->format->hsub;
3500 int vsub = fb->format->vsub;
3501 int x = src_x / hsub;
3502 int y = src_y / vsub;
3505 intel_add_fb_offsets(&x, &y, plane_state, 1);
3506 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3508 plane_state->color_plane[1].offset = offset;
3509 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3510 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
3515 int skl_check_plane_surface(struct intel_plane_state *plane_state)
3517 const struct drm_framebuffer *fb = plane_state->base.fb;
3520 ret = intel_plane_compute_gtt(plane_state);
3524 if (!plane_state->base.visible)
3528 * Handle the AUX surface first since
3529 * the main surface setup depends on it.
3531 if (is_planar_yuv_format(fb->format->format)) {
3532 ret = skl_check_nv12_aux_surface(plane_state);
3535 } else if (is_ccs_modifier(fb->modifier)) {
3536 ret = skl_check_ccs_aux_surface(plane_state);
3540 plane_state->color_plane[1].offset = ~0xfff;
3541 plane_state->color_plane[1].x = 0;
3542 plane_state->color_plane[1].y = 0;
3545 ret = skl_check_main_surface(plane_state);
3553 i9xx_plane_max_stride(struct intel_plane *plane,
3554 u32 pixel_format, u64 modifier,
3555 unsigned int rotation)
3557 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3559 if (!HAS_GMCH(dev_priv)) {
3561 } else if (INTEL_GEN(dev_priv) >= 4) {
3562 if (modifier == I915_FORMAT_MOD_X_TILED)
3566 } else if (INTEL_GEN(dev_priv) >= 3) {
3567 if (modifier == I915_FORMAT_MOD_X_TILED)
3572 if (plane->i9xx_plane == PLANE_C)
3579 static u32 i9xx_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
3581 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3582 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3585 if (crtc_state->gamma_enable)
3586 dspcntr |= DISPPLANE_GAMMA_ENABLE;
3588 if (crtc_state->csc_enable)
3589 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
3591 if (INTEL_GEN(dev_priv) < 5)
3592 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
3597 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3598 const struct intel_plane_state *plane_state)
3600 struct drm_i915_private *dev_priv =
3601 to_i915(plane_state->base.plane->dev);
3602 const struct drm_framebuffer *fb = plane_state->base.fb;
3603 unsigned int rotation = plane_state->base.rotation;
3606 dspcntr = DISPLAY_PLANE_ENABLE;
3608 if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) ||
3609 IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
3610 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
3612 switch (fb->format->format) {
3614 dspcntr |= DISPPLANE_8BPP;
3616 case DRM_FORMAT_XRGB1555:
3617 dspcntr |= DISPPLANE_BGRX555;
3619 case DRM_FORMAT_RGB565:
3620 dspcntr |= DISPPLANE_BGRX565;
3622 case DRM_FORMAT_XRGB8888:
3623 dspcntr |= DISPPLANE_BGRX888;
3625 case DRM_FORMAT_XBGR8888:
3626 dspcntr |= DISPPLANE_RGBX888;
3628 case DRM_FORMAT_XRGB2101010:
3629 dspcntr |= DISPPLANE_BGRX101010;
3631 case DRM_FORMAT_XBGR2101010:
3632 dspcntr |= DISPPLANE_RGBX101010;
3635 MISSING_CASE(fb->format->format);
3639 if (INTEL_GEN(dev_priv) >= 4 &&
3640 fb->modifier == I915_FORMAT_MOD_X_TILED)
3641 dspcntr |= DISPPLANE_TILED;
3643 if (rotation & DRM_MODE_ROTATE_180)
3644 dspcntr |= DISPPLANE_ROTATE_180;
3646 if (rotation & DRM_MODE_REFLECT_X)
3647 dspcntr |= DISPPLANE_MIRROR;
3652 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
3654 struct drm_i915_private *dev_priv =
3655 to_i915(plane_state->base.plane->dev);
3660 ret = intel_plane_compute_gtt(plane_state);
3664 if (!plane_state->base.visible)
3667 src_x = plane_state->base.src.x1 >> 16;
3668 src_y = plane_state->base.src.y1 >> 16;
3670 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
3672 if (INTEL_GEN(dev_priv) >= 4)
3673 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
3679 * Put the final coordinates back so that the src
3680 * coordinate checks will see the right values.
3682 drm_rect_translate(&plane_state->base.src,
3683 (src_x << 16) - plane_state->base.src.x1,
3684 (src_y << 16) - plane_state->base.src.y1);
3686 /* HSW/BDW do this automagically in hardware */
3687 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
3688 unsigned int rotation = plane_state->base.rotation;
3689 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3690 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3692 if (rotation & DRM_MODE_ROTATE_180) {
3695 } else if (rotation & DRM_MODE_REFLECT_X) {
3700 plane_state->color_plane[0].offset = offset;
3701 plane_state->color_plane[0].x = src_x;
3702 plane_state->color_plane[0].y = src_y;
3707 static bool i9xx_plane_has_windowing(struct intel_plane *plane)
3709 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3710 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3712 if (IS_CHERRYVIEW(dev_priv))
3713 return i9xx_plane == PLANE_B;
3714 else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
3716 else if (IS_GEN(dev_priv, 4))
3717 return i9xx_plane == PLANE_C;
3719 return i9xx_plane == PLANE_B ||
3720 i9xx_plane == PLANE_C;
3724 i9xx_plane_check(struct intel_crtc_state *crtc_state,
3725 struct intel_plane_state *plane_state)
3727 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
3730 ret = chv_plane_check_rotation(plane_state);
3734 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
3736 DRM_PLANE_HELPER_NO_SCALING,
3737 DRM_PLANE_HELPER_NO_SCALING,
3738 i9xx_plane_has_windowing(plane),
3743 ret = i9xx_check_plane_surface(plane_state);
3747 if (!plane_state->base.visible)
3750 ret = intel_plane_check_src_coordinates(plane_state);
3754 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
3759 static void i9xx_update_plane(struct intel_plane *plane,
3760 const struct intel_crtc_state *crtc_state,
3761 const struct intel_plane_state *plane_state)
3763 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3764 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3766 int x = plane_state->color_plane[0].x;
3767 int y = plane_state->color_plane[0].y;
3768 int crtc_x = plane_state->base.dst.x1;
3769 int crtc_y = plane_state->base.dst.y1;
3770 int crtc_w = drm_rect_width(&plane_state->base.dst);
3771 int crtc_h = drm_rect_height(&plane_state->base.dst);
3772 unsigned long irqflags;
3776 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
3778 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
3780 if (INTEL_GEN(dev_priv) >= 4)
3781 dspaddr_offset = plane_state->color_plane[0].offset;
3783 dspaddr_offset = linear_offset;
3785 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3787 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
3789 if (INTEL_GEN(dev_priv) < 4) {
3791 * PLANE_A doesn't actually have a full window
3792 * generator but let's assume we still need to
3793 * program whatever is there.
3795 I915_WRITE_FW(DSPPOS(i9xx_plane), (crtc_y << 16) | crtc_x);
3796 I915_WRITE_FW(DSPSIZE(i9xx_plane),
3797 ((crtc_h - 1) << 16) | (crtc_w - 1));
3798 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
3799 I915_WRITE_FW(PRIMPOS(i9xx_plane), (crtc_y << 16) | crtc_x);
3800 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
3801 ((crtc_h - 1) << 16) | (crtc_w - 1));
3802 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
3805 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3806 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
3807 } else if (INTEL_GEN(dev_priv) >= 4) {
3808 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3809 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3813 * The control register self-arms if the plane was previously
3814 * disabled. Try to make the plane enable atomic by writing
3815 * the control register just before the surface register.
3817 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3818 if (INTEL_GEN(dev_priv) >= 4)
3819 I915_WRITE_FW(DSPSURF(i9xx_plane),
3820 intel_plane_ggtt_offset(plane_state) +
3823 I915_WRITE_FW(DSPADDR(i9xx_plane),
3824 intel_plane_ggtt_offset(plane_state) +
3827 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3830 static void i9xx_disable_plane(struct intel_plane *plane,
3831 const struct intel_crtc_state *crtc_state)
3833 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3834 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3835 unsigned long irqflags;
3839 * DSPCNTR pipe gamma enable on g4x+ and pipe csc
3840 * enable on ilk+ affect the pipe bottom color as
3841 * well, so we must configure them even if the plane
3844 * On pre-g4x there is no way to gamma correct the
3845 * pipe bottom color but we'll keep on doing this
3846 * anyway so that the crtc state readout works correctly.
3848 dspcntr = i9xx_plane_ctl_crtc(crtc_state);
3850 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3852 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3853 if (INTEL_GEN(dev_priv) >= 4)
3854 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
3856 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
3858 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3861 static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
3864 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3865 enum intel_display_power_domain power_domain;
3866 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3867 intel_wakeref_t wakeref;
3872 * Not 100% correct for planes that can move between pipes,
3873 * but that's only the case for gen2-4 which don't have any
3874 * display power wells.
3876 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
3877 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3881 val = I915_READ(DSPCNTR(i9xx_plane));
3883 ret = val & DISPLAY_PLANE_ENABLE;
3885 if (INTEL_GEN(dev_priv) >= 5)
3886 *pipe = plane->pipe;
3888 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
3889 DISPPLANE_SEL_PIPE_SHIFT;
3891 intel_display_power_put(dev_priv, power_domain, wakeref);
3896 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3898 struct drm_device *dev = intel_crtc->base.dev;
3899 struct drm_i915_private *dev_priv = to_i915(dev);
3901 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3902 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3903 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
3907 * This function detaches (aka. unbinds) unused scalers in hardware
3909 static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
3911 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3912 const struct intel_crtc_scaler_state *scaler_state =
3913 &crtc_state->scaler_state;
3916 /* loop through and disable scalers that aren't in use */
3917 for (i = 0; i < intel_crtc->num_scalers; i++) {
3918 if (!scaler_state->scalers[i].in_use)
3919 skl_detach_scaler(intel_crtc, i);
3923 static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
3924 int color_plane, unsigned int rotation)
3927 * The stride is either expressed as a multiple of 64 bytes chunks for
3928 * linear buffers or in number of tiles for tiled buffers.
3930 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3932 else if (drm_rotation_90_or_270(rotation))
3933 return intel_tile_height(fb, color_plane);
3935 return intel_tile_width_bytes(fb, color_plane);
3938 u32 skl_plane_stride(const struct intel_plane_state *plane_state,
3941 const struct drm_framebuffer *fb = plane_state->base.fb;
3942 unsigned int rotation = plane_state->base.rotation;
3943 u32 stride = plane_state->color_plane[color_plane].stride;
3945 if (color_plane >= fb->format->num_planes)
3948 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
3951 static u32 skl_plane_ctl_format(u32 pixel_format)
3953 switch (pixel_format) {
3955 return PLANE_CTL_FORMAT_INDEXED;
3956 case DRM_FORMAT_RGB565:
3957 return PLANE_CTL_FORMAT_RGB_565;
3958 case DRM_FORMAT_XBGR8888:
3959 case DRM_FORMAT_ABGR8888:
3960 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
3961 case DRM_FORMAT_XRGB8888:
3962 case DRM_FORMAT_ARGB8888:
3963 return PLANE_CTL_FORMAT_XRGB_8888;
3964 case DRM_FORMAT_XBGR2101010:
3965 return PLANE_CTL_FORMAT_XRGB_2101010 | PLANE_CTL_ORDER_RGBX;
3966 case DRM_FORMAT_XRGB2101010:
3967 return PLANE_CTL_FORMAT_XRGB_2101010;
3968 case DRM_FORMAT_XBGR16161616F:
3969 case DRM_FORMAT_ABGR16161616F:
3970 return PLANE_CTL_FORMAT_XRGB_16161616F | PLANE_CTL_ORDER_RGBX;
3971 case DRM_FORMAT_XRGB16161616F:
3972 case DRM_FORMAT_ARGB16161616F:
3973 return PLANE_CTL_FORMAT_XRGB_16161616F;
3974 case DRM_FORMAT_YUYV:
3975 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
3976 case DRM_FORMAT_YVYU:
3977 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
3978 case DRM_FORMAT_UYVY:
3979 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
3980 case DRM_FORMAT_VYUY:
3981 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
3982 case DRM_FORMAT_NV12:
3983 return PLANE_CTL_FORMAT_NV12;
3984 case DRM_FORMAT_P010:
3985 return PLANE_CTL_FORMAT_P010;
3986 case DRM_FORMAT_P012:
3987 return PLANE_CTL_FORMAT_P012;
3988 case DRM_FORMAT_P016:
3989 return PLANE_CTL_FORMAT_P016;
3990 case DRM_FORMAT_Y210:
3991 return PLANE_CTL_FORMAT_Y210;
3992 case DRM_FORMAT_Y212:
3993 return PLANE_CTL_FORMAT_Y212;
3994 case DRM_FORMAT_Y216:
3995 return PLANE_CTL_FORMAT_Y216;
3996 case DRM_FORMAT_XVYU2101010:
3997 return PLANE_CTL_FORMAT_Y410;
3998 case DRM_FORMAT_XVYU12_16161616:
3999 return PLANE_CTL_FORMAT_Y412;
4000 case DRM_FORMAT_XVYU16161616:
4001 return PLANE_CTL_FORMAT_Y416;
4003 MISSING_CASE(pixel_format);
4009 static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
4011 if (!plane_state->base.fb->format->has_alpha)
4012 return PLANE_CTL_ALPHA_DISABLE;
4014 switch (plane_state->base.pixel_blend_mode) {
4015 case DRM_MODE_BLEND_PIXEL_NONE:
4016 return PLANE_CTL_ALPHA_DISABLE;
4017 case DRM_MODE_BLEND_PREMULTI:
4018 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
4019 case DRM_MODE_BLEND_COVERAGE:
4020 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
4022 MISSING_CASE(plane_state->base.pixel_blend_mode);
4023 return PLANE_CTL_ALPHA_DISABLE;
4027 static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
4029 if (!plane_state->base.fb->format->has_alpha)
4030 return PLANE_COLOR_ALPHA_DISABLE;
4032 switch (plane_state->base.pixel_blend_mode) {
4033 case DRM_MODE_BLEND_PIXEL_NONE:
4034 return PLANE_COLOR_ALPHA_DISABLE;
4035 case DRM_MODE_BLEND_PREMULTI:
4036 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
4037 case DRM_MODE_BLEND_COVERAGE:
4038 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
4040 MISSING_CASE(plane_state->base.pixel_blend_mode);
4041 return PLANE_COLOR_ALPHA_DISABLE;
4045 static u32 skl_plane_ctl_tiling(u64 fb_modifier)
4047 switch (fb_modifier) {
4048 case DRM_FORMAT_MOD_LINEAR:
4050 case I915_FORMAT_MOD_X_TILED:
4051 return PLANE_CTL_TILED_X;
4052 case I915_FORMAT_MOD_Y_TILED:
4053 return PLANE_CTL_TILED_Y;
4054 case I915_FORMAT_MOD_Y_TILED_CCS:
4055 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
4056 case I915_FORMAT_MOD_Yf_TILED:
4057 return PLANE_CTL_TILED_YF;
4058 case I915_FORMAT_MOD_Yf_TILED_CCS:
4059 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
4061 MISSING_CASE(fb_modifier);
4067 static u32 skl_plane_ctl_rotate(unsigned int rotate)
4070 case DRM_MODE_ROTATE_0:
4073 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
4074 * while i915 HW rotation is clockwise, thats why this swapping.
4076 case DRM_MODE_ROTATE_90:
4077 return PLANE_CTL_ROTATE_270;
4078 case DRM_MODE_ROTATE_180:
4079 return PLANE_CTL_ROTATE_180;
4080 case DRM_MODE_ROTATE_270:
4081 return PLANE_CTL_ROTATE_90;
4083 MISSING_CASE(rotate);
4089 static u32 cnl_plane_ctl_flip(unsigned int reflect)
4094 case DRM_MODE_REFLECT_X:
4095 return PLANE_CTL_FLIP_HORIZONTAL;
4096 case DRM_MODE_REFLECT_Y:
4098 MISSING_CASE(reflect);
4104 u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
4106 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
4109 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
4112 if (crtc_state->gamma_enable)
4113 plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE;
4115 if (crtc_state->csc_enable)
4116 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
4121 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
4122 const struct intel_plane_state *plane_state)
4124 struct drm_i915_private *dev_priv =
4125 to_i915(plane_state->base.plane->dev);
4126 const struct drm_framebuffer *fb = plane_state->base.fb;
4127 unsigned int rotation = plane_state->base.rotation;
4128 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
4131 plane_ctl = PLANE_CTL_ENABLE;
4133 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
4134 plane_ctl |= skl_plane_ctl_alpha(plane_state);
4135 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
4137 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
4138 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
4140 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
4141 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
4144 plane_ctl |= skl_plane_ctl_format(fb->format->format);
4145 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
4146 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
4148 if (INTEL_GEN(dev_priv) >= 10)
4149 plane_ctl |= cnl_plane_ctl_flip(rotation &
4150 DRM_MODE_REFLECT_MASK);
4152 if (key->flags & I915_SET_COLORKEY_DESTINATION)
4153 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
4154 else if (key->flags & I915_SET_COLORKEY_SOURCE)
4155 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
4160 u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state)
4162 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
4163 u32 plane_color_ctl = 0;
4165 if (INTEL_GEN(dev_priv) >= 11)
4166 return plane_color_ctl;
4168 if (crtc_state->gamma_enable)
4169 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
4171 if (crtc_state->csc_enable)
4172 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
4174 return plane_color_ctl;
4177 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
4178 const struct intel_plane_state *plane_state)
4180 struct drm_i915_private *dev_priv =
4181 to_i915(plane_state->base.plane->dev);
4182 const struct drm_framebuffer *fb = plane_state->base.fb;
4183 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
4184 u32 plane_color_ctl = 0;
4186 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
4187 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
4189 if (fb->format->is_yuv && !icl_is_hdr_plane(dev_priv, plane->id)) {
4190 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
4191 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
4193 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
4195 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
4196 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
4197 } else if (fb->format->is_yuv) {
4198 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
4201 return plane_color_ctl;
4205 __intel_display_resume(struct drm_device *dev,
4206 struct drm_atomic_state *state,
4207 struct drm_modeset_acquire_ctx *ctx)
4209 struct drm_crtc_state *crtc_state;
4210 struct drm_crtc *crtc;
4213 intel_modeset_setup_hw_state(dev, ctx);
4214 i915_redisable_vga(to_i915(dev));
4220 * We've duplicated the state, pointers to the old state are invalid.
4222 * Don't attempt to use the old state until we commit the duplicated state.
4224 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
4226 * Force recalculation even if we restore
4227 * current state. With fast modeset this may not result
4228 * in a modeset when the state is compatible.
4230 crtc_state->mode_changed = true;
4233 /* ignore any reset values/BIOS leftovers in the WM registers */
4234 if (!HAS_GMCH(to_i915(dev)))
4235 to_intel_atomic_state(state)->skip_intermediate_wm = true;
4237 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
4239 WARN_ON(ret == -EDEADLK);
4243 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
4245 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
4246 intel_has_gpu_reset(dev_priv));
4249 void intel_prepare_reset(struct drm_i915_private *dev_priv)
4251 struct drm_device *dev = &dev_priv->drm;
4252 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
4253 struct drm_atomic_state *state;
4256 /* reset doesn't touch the display */
4257 if (!i915_modparams.force_reset_modeset_test &&
4258 !gpu_reset_clobbers_display(dev_priv))
4261 /* We have a modeset vs reset deadlock, defensively unbreak it. */
4262 set_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
4263 smp_mb__after_atomic();
4264 wake_up_bit(&dev_priv->gt.reset.flags, I915_RESET_MODESET);
4266 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
4267 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
4268 intel_gt_set_wedged(&dev_priv->gt);
4272 * Need mode_config.mutex so that we don't
4273 * trample ongoing ->detect() and whatnot.
4275 mutex_lock(&dev->mode_config.mutex);
4276 drm_modeset_acquire_init(ctx, 0);
4278 ret = drm_modeset_lock_all_ctx(dev, ctx);
4279 if (ret != -EDEADLK)
4282 drm_modeset_backoff(ctx);
4285 * Disabling the crtcs gracefully seems nicer. Also the
4286 * g33 docs say we should at least disable all the planes.
4288 state = drm_atomic_helper_duplicate_state(dev, ctx);
4289 if (IS_ERR(state)) {
4290 ret = PTR_ERR(state);
4291 DRM_ERROR("Duplicating state failed with %i\n", ret);
4295 ret = drm_atomic_helper_disable_all(dev, ctx);
4297 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
4298 drm_atomic_state_put(state);
4302 dev_priv->modeset_restore_state = state;
4303 state->acquire_ctx = ctx;
4306 void intel_finish_reset(struct drm_i915_private *dev_priv)
4308 struct drm_device *dev = &dev_priv->drm;
4309 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
4310 struct drm_atomic_state *state;
4313 /* reset doesn't touch the display */
4314 if (!test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
4317 state = fetch_and_zero(&dev_priv->modeset_restore_state);
4321 /* reset doesn't touch the display */
4322 if (!gpu_reset_clobbers_display(dev_priv)) {
4323 /* for testing only restore the display */
4324 ret = __intel_display_resume(dev, state, ctx);
4326 DRM_ERROR("Restoring old state failed with %i\n", ret);
4329 * The display has been reset as well,
4330 * so need a full re-initialization.
4332 intel_pps_unlock_regs_wa(dev_priv);
4333 intel_modeset_init_hw(dev);
4334 intel_init_clock_gating(dev_priv);
4336 spin_lock_irq(&dev_priv->irq_lock);
4337 if (dev_priv->display.hpd_irq_setup)
4338 dev_priv->display.hpd_irq_setup(dev_priv);
4339 spin_unlock_irq(&dev_priv->irq_lock);
4341 ret = __intel_display_resume(dev, state, ctx);
4343 DRM_ERROR("Restoring old state failed with %i\n", ret);
4345 intel_hpd_init(dev_priv);
4348 drm_atomic_state_put(state);
4350 drm_modeset_drop_locks(ctx);
4351 drm_modeset_acquire_fini(ctx);
4352 mutex_unlock(&dev->mode_config.mutex);
4354 clear_bit_unlock(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
4357 static void icl_set_pipe_chicken(struct intel_crtc *crtc)
4359 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4360 enum pipe pipe = crtc->pipe;
4363 tmp = I915_READ(PIPE_CHICKEN(pipe));
4366 * Display WA #1153: icl
4367 * enable hardware to bypass the alpha math
4368 * and rounding for per-pixel values 00 and 0xff
4370 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
4372 * Display WA # 1605353570: icl
4373 * Set the pixel rounding bit to 1 for allowing
4374 * passthrough of Frame buffer pixels unmodified
4377 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
4378 I915_WRITE(PIPE_CHICKEN(pipe), tmp);
4381 static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
4382 const struct intel_crtc_state *new_crtc_state)
4384 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
4385 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4387 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
4388 crtc->base.mode = new_crtc_state->base.mode;
4391 * Update pipe size and adjust fitter if needed: the reason for this is
4392 * that in compute_mode_changes we check the native mode (not the pfit
4393 * mode) to see if we can flip rather than do a full mode set. In the
4394 * fastboot case, we'll flip, but if we don't update the pipesrc and
4395 * pfit state, we'll end up with a big fb scanned out into the wrong
4399 I915_WRITE(PIPESRC(crtc->pipe),
4400 ((new_crtc_state->pipe_src_w - 1) << 16) |
4401 (new_crtc_state->pipe_src_h - 1));
4403 /* on skylake this is done by detaching scalers */
4404 if (INTEL_GEN(dev_priv) >= 9) {
4405 skl_detach_scalers(new_crtc_state);
4407 if (new_crtc_state->pch_pfit.enabled)
4408 skylake_pfit_enable(new_crtc_state);
4409 } else if (HAS_PCH_SPLIT(dev_priv)) {
4410 if (new_crtc_state->pch_pfit.enabled)
4411 ironlake_pfit_enable(new_crtc_state);
4412 else if (old_crtc_state->pch_pfit.enabled)
4413 ironlake_pfit_disable(old_crtc_state);
4416 if (INTEL_GEN(dev_priv) >= 11)
4417 icl_set_pipe_chicken(crtc);
4420 static void intel_fdi_normal_train(struct intel_crtc *crtc)
4422 struct drm_device *dev = crtc->base.dev;
4423 struct drm_i915_private *dev_priv = to_i915(dev);
4424 enum pipe pipe = crtc->pipe;
4428 /* enable normal train */
4429 reg = FDI_TX_CTL(pipe);
4430 temp = I915_READ(reg);
4431 if (IS_IVYBRIDGE(dev_priv)) {
4432 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4433 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
4435 temp &= ~FDI_LINK_TRAIN_NONE;
4436 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
4438 I915_WRITE(reg, temp);
4440 reg = FDI_RX_CTL(pipe);
4441 temp = I915_READ(reg);
4442 if (HAS_PCH_CPT(dev_priv)) {
4443 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4444 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
4446 temp &= ~FDI_LINK_TRAIN_NONE;
4447 temp |= FDI_LINK_TRAIN_NONE;
4449 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
4451 /* wait one idle pattern time */
4455 /* IVB wants error correction enabled */
4456 if (IS_IVYBRIDGE(dev_priv))
4457 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
4458 FDI_FE_ERRC_ENABLE);
4461 /* The FDI link training functions for ILK/Ibexpeak. */
4462 static void ironlake_fdi_link_train(struct intel_crtc *crtc,
4463 const struct intel_crtc_state *crtc_state)
4465 struct drm_device *dev = crtc->base.dev;
4466 struct drm_i915_private *dev_priv = to_i915(dev);
4467 enum pipe pipe = crtc->pipe;
4471 /* FDI needs bits from pipe first */
4472 assert_pipe_enabled(dev_priv, pipe);
4474 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4476 reg = FDI_RX_IMR(pipe);
4477 temp = I915_READ(reg);
4478 temp &= ~FDI_RX_SYMBOL_LOCK;
4479 temp &= ~FDI_RX_BIT_LOCK;
4480 I915_WRITE(reg, temp);
4484 /* enable CPU FDI TX and PCH FDI RX */
4485 reg = FDI_TX_CTL(pipe);
4486 temp = I915_READ(reg);
4487 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4488 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4489 temp &= ~FDI_LINK_TRAIN_NONE;
4490 temp |= FDI_LINK_TRAIN_PATTERN_1;
4491 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4493 reg = FDI_RX_CTL(pipe);
4494 temp = I915_READ(reg);
4495 temp &= ~FDI_LINK_TRAIN_NONE;
4496 temp |= FDI_LINK_TRAIN_PATTERN_1;
4497 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4502 /* Ironlake workaround, enable clock pointer after FDI enable*/
4503 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4504 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
4505 FDI_RX_PHASE_SYNC_POINTER_EN);
4507 reg = FDI_RX_IIR(pipe);
4508 for (tries = 0; tries < 5; tries++) {
4509 temp = I915_READ(reg);
4510 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4512 if ((temp & FDI_RX_BIT_LOCK)) {
4513 DRM_DEBUG_KMS("FDI train 1 done.\n");
4514 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4519 DRM_ERROR("FDI train 1 fail!\n");
4522 reg = FDI_TX_CTL(pipe);
4523 temp = I915_READ(reg);
4524 temp &= ~FDI_LINK_TRAIN_NONE;
4525 temp |= FDI_LINK_TRAIN_PATTERN_2;
4526 I915_WRITE(reg, temp);
4528 reg = FDI_RX_CTL(pipe);
4529 temp = I915_READ(reg);
4530 temp &= ~FDI_LINK_TRAIN_NONE;
4531 temp |= FDI_LINK_TRAIN_PATTERN_2;
4532 I915_WRITE(reg, temp);
4537 reg = FDI_RX_IIR(pipe);
4538 for (tries = 0; tries < 5; tries++) {
4539 temp = I915_READ(reg);
4540 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4542 if (temp & FDI_RX_SYMBOL_LOCK) {
4543 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4544 DRM_DEBUG_KMS("FDI train 2 done.\n");
4549 DRM_ERROR("FDI train 2 fail!\n");
4551 DRM_DEBUG_KMS("FDI train done\n");
4555 static const int snb_b_fdi_train_param[] = {
4556 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4557 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4558 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4559 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4562 /* The FDI link training functions for SNB/Cougarpoint. */
4563 static void gen6_fdi_link_train(struct intel_crtc *crtc,
4564 const struct intel_crtc_state *crtc_state)
4566 struct drm_device *dev = crtc->base.dev;
4567 struct drm_i915_private *dev_priv = to_i915(dev);
4568 enum pipe pipe = crtc->pipe;
4572 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4574 reg = FDI_RX_IMR(pipe);
4575 temp = I915_READ(reg);
4576 temp &= ~FDI_RX_SYMBOL_LOCK;
4577 temp &= ~FDI_RX_BIT_LOCK;
4578 I915_WRITE(reg, temp);
4583 /* enable CPU FDI TX and PCH FDI RX */
4584 reg = FDI_TX_CTL(pipe);
4585 temp = I915_READ(reg);
4586 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4587 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4588 temp &= ~FDI_LINK_TRAIN_NONE;
4589 temp |= FDI_LINK_TRAIN_PATTERN_1;
4590 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4592 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4593 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4595 I915_WRITE(FDI_RX_MISC(pipe),
4596 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4598 reg = FDI_RX_CTL(pipe);
4599 temp = I915_READ(reg);
4600 if (HAS_PCH_CPT(dev_priv)) {
4601 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4602 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4604 temp &= ~FDI_LINK_TRAIN_NONE;
4605 temp |= FDI_LINK_TRAIN_PATTERN_1;
4607 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4612 for (i = 0; i < 4; i++) {
4613 reg = FDI_TX_CTL(pipe);
4614 temp = I915_READ(reg);
4615 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4616 temp |= snb_b_fdi_train_param[i];
4617 I915_WRITE(reg, temp);
4622 for (retry = 0; retry < 5; retry++) {
4623 reg = FDI_RX_IIR(pipe);
4624 temp = I915_READ(reg);
4625 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4626 if (temp & FDI_RX_BIT_LOCK) {
4627 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4628 DRM_DEBUG_KMS("FDI train 1 done.\n");
4637 DRM_ERROR("FDI train 1 fail!\n");
4640 reg = FDI_TX_CTL(pipe);
4641 temp = I915_READ(reg);
4642 temp &= ~FDI_LINK_TRAIN_NONE;
4643 temp |= FDI_LINK_TRAIN_PATTERN_2;
4644 if (IS_GEN(dev_priv, 6)) {
4645 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4647 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4649 I915_WRITE(reg, temp);
4651 reg = FDI_RX_CTL(pipe);
4652 temp = I915_READ(reg);
4653 if (HAS_PCH_CPT(dev_priv)) {
4654 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4655 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4657 temp &= ~FDI_LINK_TRAIN_NONE;
4658 temp |= FDI_LINK_TRAIN_PATTERN_2;
4660 I915_WRITE(reg, temp);
4665 for (i = 0; i < 4; i++) {
4666 reg = FDI_TX_CTL(pipe);
4667 temp = I915_READ(reg);
4668 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4669 temp |= snb_b_fdi_train_param[i];
4670 I915_WRITE(reg, temp);
4675 for (retry = 0; retry < 5; retry++) {
4676 reg = FDI_RX_IIR(pipe);
4677 temp = I915_READ(reg);
4678 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4679 if (temp & FDI_RX_SYMBOL_LOCK) {
4680 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4681 DRM_DEBUG_KMS("FDI train 2 done.\n");
4690 DRM_ERROR("FDI train 2 fail!\n");
4692 DRM_DEBUG_KMS("FDI train done.\n");
4695 /* Manual link training for Ivy Bridge A0 parts */
4696 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4697 const struct intel_crtc_state *crtc_state)
4699 struct drm_device *dev = crtc->base.dev;
4700 struct drm_i915_private *dev_priv = to_i915(dev);
4701 enum pipe pipe = crtc->pipe;
4705 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4707 reg = FDI_RX_IMR(pipe);
4708 temp = I915_READ(reg);
4709 temp &= ~FDI_RX_SYMBOL_LOCK;
4710 temp &= ~FDI_RX_BIT_LOCK;
4711 I915_WRITE(reg, temp);
4716 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4717 I915_READ(FDI_RX_IIR(pipe)));
4719 /* Try each vswing and preemphasis setting twice before moving on */
4720 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4721 /* disable first in case we need to retry */
4722 reg = FDI_TX_CTL(pipe);
4723 temp = I915_READ(reg);
4724 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4725 temp &= ~FDI_TX_ENABLE;
4726 I915_WRITE(reg, temp);
4728 reg = FDI_RX_CTL(pipe);
4729 temp = I915_READ(reg);
4730 temp &= ~FDI_LINK_TRAIN_AUTO;
4731 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4732 temp &= ~FDI_RX_ENABLE;
4733 I915_WRITE(reg, temp);
4735 /* enable CPU FDI TX and PCH FDI RX */
4736 reg = FDI_TX_CTL(pipe);
4737 temp = I915_READ(reg);
4738 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4739 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4740 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
4741 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4742 temp |= snb_b_fdi_train_param[j/2];
4743 temp |= FDI_COMPOSITE_SYNC;
4744 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4746 I915_WRITE(FDI_RX_MISC(pipe),
4747 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4749 reg = FDI_RX_CTL(pipe);
4750 temp = I915_READ(reg);
4751 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4752 temp |= FDI_COMPOSITE_SYNC;
4753 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4756 udelay(1); /* should be 0.5us */
4758 for (i = 0; i < 4; i++) {
4759 reg = FDI_RX_IIR(pipe);
4760 temp = I915_READ(reg);
4761 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4763 if (temp & FDI_RX_BIT_LOCK ||
4764 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4765 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4766 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4770 udelay(1); /* should be 0.5us */
4773 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4778 reg = FDI_TX_CTL(pipe);
4779 temp = I915_READ(reg);
4780 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4781 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4782 I915_WRITE(reg, temp);
4784 reg = FDI_RX_CTL(pipe);
4785 temp = I915_READ(reg);
4786 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4787 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4788 I915_WRITE(reg, temp);
4791 udelay(2); /* should be 1.5us */
4793 for (i = 0; i < 4; i++) {
4794 reg = FDI_RX_IIR(pipe);
4795 temp = I915_READ(reg);
4796 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4798 if (temp & FDI_RX_SYMBOL_LOCK ||
4799 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4800 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4801 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4805 udelay(2); /* should be 1.5us */
4808 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
4812 DRM_DEBUG_KMS("FDI train done.\n");
4815 static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
4817 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4818 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4819 enum pipe pipe = intel_crtc->pipe;
4823 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4824 reg = FDI_RX_CTL(pipe);
4825 temp = I915_READ(reg);
4826 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
4827 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4828 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4829 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4834 /* Switch from Rawclk to PCDclk */
4835 temp = I915_READ(reg);
4836 I915_WRITE(reg, temp | FDI_PCDCLK);
4841 /* Enable CPU FDI TX PLL, always on for Ironlake */
4842 reg = FDI_TX_CTL(pipe);
4843 temp = I915_READ(reg);
4844 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4845 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
4852 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4854 struct drm_device *dev = intel_crtc->base.dev;
4855 struct drm_i915_private *dev_priv = to_i915(dev);
4856 enum pipe pipe = intel_crtc->pipe;
4860 /* Switch from PCDclk to Rawclk */
4861 reg = FDI_RX_CTL(pipe);
4862 temp = I915_READ(reg);
4863 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4865 /* Disable CPU FDI TX PLL */
4866 reg = FDI_TX_CTL(pipe);
4867 temp = I915_READ(reg);
4868 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4873 reg = FDI_RX_CTL(pipe);
4874 temp = I915_READ(reg);
4875 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4877 /* Wait for the clocks to turn off. */
4882 static void ironlake_fdi_disable(struct drm_crtc *crtc)
4884 struct drm_device *dev = crtc->dev;
4885 struct drm_i915_private *dev_priv = to_i915(dev);
4886 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4887 enum pipe pipe = intel_crtc->pipe;
4891 /* disable CPU FDI tx and PCH FDI rx */
4892 reg = FDI_TX_CTL(pipe);
4893 temp = I915_READ(reg);
4894 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4897 reg = FDI_RX_CTL(pipe);
4898 temp = I915_READ(reg);
4899 temp &= ~(0x7 << 16);
4900 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4901 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4906 /* Ironlake workaround, disable clock pointer after downing FDI */
4907 if (HAS_PCH_IBX(dev_priv))
4908 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4910 /* still set train pattern 1 */
4911 reg = FDI_TX_CTL(pipe);
4912 temp = I915_READ(reg);
4913 temp &= ~FDI_LINK_TRAIN_NONE;
4914 temp |= FDI_LINK_TRAIN_PATTERN_1;
4915 I915_WRITE(reg, temp);
4917 reg = FDI_RX_CTL(pipe);
4918 temp = I915_READ(reg);
4919 if (HAS_PCH_CPT(dev_priv)) {
4920 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4921 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4923 temp &= ~FDI_LINK_TRAIN_NONE;
4924 temp |= FDI_LINK_TRAIN_PATTERN_1;
4926 /* BPC in FDI rx is consistent with that in PIPECONF */
4927 temp &= ~(0x07 << 16);
4928 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4929 I915_WRITE(reg, temp);
4935 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
4937 struct drm_crtc *crtc;
4940 drm_for_each_crtc(crtc, &dev_priv->drm) {
4941 struct drm_crtc_commit *commit;
4942 spin_lock(&crtc->commit_lock);
4943 commit = list_first_entry_or_null(&crtc->commit_list,
4944 struct drm_crtc_commit, commit_entry);
4945 cleanup_done = commit ?
4946 try_wait_for_completion(&commit->cleanup_done) : true;
4947 spin_unlock(&crtc->commit_lock);
4952 drm_crtc_wait_one_vblank(crtc);
4960 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
4964 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4966 mutex_lock(&dev_priv->sb_lock);
4968 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4969 temp |= SBI_SSCCTL_DISABLE;
4970 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4972 mutex_unlock(&dev_priv->sb_lock);
4975 /* Program iCLKIP clock to the desired frequency */
4976 static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
4978 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4979 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4980 int clock = crtc_state->base.adjusted_mode.crtc_clock;
4981 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4984 lpt_disable_iclkip(dev_priv);
4986 /* The iCLK virtual clock root frequency is in MHz,
4987 * but the adjusted_mode->crtc_clock in in KHz. To get the
4988 * divisors, it is necessary to divide one by another, so we
4989 * convert the virtual clock precision to KHz here for higher
4992 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
4993 u32 iclk_virtual_root_freq = 172800 * 1000;
4994 u32 iclk_pi_range = 64;
4995 u32 desired_divisor;
4997 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4999 divsel = (desired_divisor / iclk_pi_range) - 2;
5000 phaseinc = desired_divisor % iclk_pi_range;
5003 * Near 20MHz is a corner case which is
5004 * out of range for the 7-bit divisor
5010 /* This should not happen with any sane values */
5011 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
5012 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
5013 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
5014 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
5016 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
5023 mutex_lock(&dev_priv->sb_lock);
5025 /* Program SSCDIVINTPHASE6 */
5026 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5027 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
5028 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
5029 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
5030 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
5031 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
5032 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
5033 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
5035 /* Program SSCAUXDIV */
5036 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5037 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
5038 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
5039 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
5041 /* Enable modulator and associated divider */
5042 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5043 temp &= ~SBI_SSCCTL_DISABLE;
5044 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
5046 mutex_unlock(&dev_priv->sb_lock);
5048 /* Wait for initialization time */
5051 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
5054 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
5056 u32 divsel, phaseinc, auxdiv;
5057 u32 iclk_virtual_root_freq = 172800 * 1000;
5058 u32 iclk_pi_range = 64;
5059 u32 desired_divisor;
5062 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
5065 mutex_lock(&dev_priv->sb_lock);
5067 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5068 if (temp & SBI_SSCCTL_DISABLE) {
5069 mutex_unlock(&dev_priv->sb_lock);
5073 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5074 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
5075 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
5076 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
5077 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
5079 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5080 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
5081 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
5083 mutex_unlock(&dev_priv->sb_lock);
5085 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
5087 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5088 desired_divisor << auxdiv);
5091 static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
5092 enum pipe pch_transcoder)
5094 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5095 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5096 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5098 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
5099 I915_READ(HTOTAL(cpu_transcoder)));
5100 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
5101 I915_READ(HBLANK(cpu_transcoder)));
5102 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
5103 I915_READ(HSYNC(cpu_transcoder)));
5105 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
5106 I915_READ(VTOTAL(cpu_transcoder)));
5107 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
5108 I915_READ(VBLANK(cpu_transcoder)));
5109 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
5110 I915_READ(VSYNC(cpu_transcoder)));
5111 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
5112 I915_READ(VSYNCSHIFT(cpu_transcoder)));
5115 static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
5119 temp = I915_READ(SOUTH_CHICKEN1);
5120 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
5123 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
5124 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
5126 temp &= ~FDI_BC_BIFURCATION_SELECT;
5128 temp |= FDI_BC_BIFURCATION_SELECT;
5130 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
5131 I915_WRITE(SOUTH_CHICKEN1, temp);
5132 POSTING_READ(SOUTH_CHICKEN1);
5135 static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
5137 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5138 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5140 switch (crtc->pipe) {
5144 if (crtc_state->fdi_lanes > 2)
5145 cpt_set_fdi_bc_bifurcation(dev_priv, false);
5147 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5151 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5160 * Finds the encoder associated with the given CRTC. This can only be
5161 * used when we know that the CRTC isn't feeding multiple encoders!
5163 static struct intel_encoder *
5164 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
5165 const struct intel_crtc_state *crtc_state)
5167 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5168 const struct drm_connector_state *connector_state;
5169 const struct drm_connector *connector;
5170 struct intel_encoder *encoder = NULL;
5171 int num_encoders = 0;
5174 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
5175 if (connector_state->crtc != &crtc->base)
5178 encoder = to_intel_encoder(connector_state->best_encoder);
5182 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
5183 num_encoders, pipe_name(crtc->pipe));
5189 * Enable PCH resources required for PCH ports:
5191 * - FDI training & RX/TX
5192 * - update transcoder timings
5193 * - DP transcoding bits
5196 static void ironlake_pch_enable(const struct intel_atomic_state *state,
5197 const struct intel_crtc_state *crtc_state)
5199 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5200 struct drm_device *dev = crtc->base.dev;
5201 struct drm_i915_private *dev_priv = to_i915(dev);
5202 enum pipe pipe = crtc->pipe;
5205 assert_pch_transcoder_disabled(dev_priv, pipe);
5207 if (IS_IVYBRIDGE(dev_priv))
5208 ivybridge_update_fdi_bc_bifurcation(crtc_state);
5210 /* Write the TU size bits before fdi link training, so that error
5211 * detection works. */
5212 I915_WRITE(FDI_RX_TUSIZE1(pipe),
5213 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
5215 /* For PCH output, training FDI link */
5216 dev_priv->display.fdi_link_train(crtc, crtc_state);
5218 /* We need to program the right clock selection before writing the pixel
5219 * mutliplier into the DPLL. */
5220 if (HAS_PCH_CPT(dev_priv)) {
5223 temp = I915_READ(PCH_DPLL_SEL);
5224 temp |= TRANS_DPLL_ENABLE(pipe);
5225 sel = TRANS_DPLLB_SEL(pipe);
5226 if (crtc_state->shared_dpll ==
5227 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
5231 I915_WRITE(PCH_DPLL_SEL, temp);
5234 /* XXX: pch pll's can be enabled any time before we enable the PCH
5235 * transcoder, and we actually should do this to not upset any PCH
5236 * transcoder that already use the clock when we share it.
5238 * Note that enable_shared_dpll tries to do the right thing, but
5239 * get_shared_dpll unconditionally resets the pll - we need that to have
5240 * the right LVDS enable sequence. */
5241 intel_enable_shared_dpll(crtc_state);
5243 /* set transcoder timing, panel must allow it */
5244 assert_panel_unlocked(dev_priv, pipe);
5245 ironlake_pch_transcoder_set_timings(crtc_state, pipe);
5247 intel_fdi_normal_train(crtc);
5249 /* For PCH DP, enable TRANS_DP_CTL */
5250 if (HAS_PCH_CPT(dev_priv) &&
5251 intel_crtc_has_dp_encoder(crtc_state)) {
5252 const struct drm_display_mode *adjusted_mode =
5253 &crtc_state->base.adjusted_mode;
5254 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
5255 i915_reg_t reg = TRANS_DP_CTL(pipe);
5258 temp = I915_READ(reg);
5259 temp &= ~(TRANS_DP_PORT_SEL_MASK |
5260 TRANS_DP_SYNC_MASK |
5262 temp |= TRANS_DP_OUTPUT_ENABLE;
5263 temp |= bpc << 9; /* same format but at 11:9 */
5265 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
5266 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
5267 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
5268 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
5270 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
5271 WARN_ON(port < PORT_B || port > PORT_D);
5272 temp |= TRANS_DP_PORT_SEL(port);
5274 I915_WRITE(reg, temp);
5277 ironlake_enable_pch_transcoder(crtc_state);
5280 static void lpt_pch_enable(const struct intel_atomic_state *state,
5281 const struct intel_crtc_state *crtc_state)
5283 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5284 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5285 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5287 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
5289 lpt_program_iclkip(crtc_state);
5291 /* Set transcoder timing. */
5292 ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A);
5294 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
5297 static void cpt_verify_modeset(struct drm_device *dev, enum pipe pipe)
5299 struct drm_i915_private *dev_priv = to_i915(dev);
5300 i915_reg_t dslreg = PIPEDSL(pipe);
5303 temp = I915_READ(dslreg);
5305 if (wait_for(I915_READ(dslreg) != temp, 5)) {
5306 if (wait_for(I915_READ(dslreg) != temp, 5))
5307 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
5312 * The hardware phase 0.0 refers to the center of the pixel.
5313 * We want to start from the top/left edge which is phase
5314 * -0.5. That matches how the hardware calculates the scaling
5315 * factors (from top-left of the first pixel to bottom-right
5316 * of the last pixel, as opposed to the pixel centers).
5318 * For 4:2:0 subsampled chroma planes we obviously have to
5319 * adjust that so that the chroma sample position lands in
5322 * Note that for packed YCbCr 4:2:2 formats there is no way to
5323 * control chroma siting. The hardware simply replicates the
5324 * chroma samples for both of the luma samples, and thus we don't
5325 * actually get the expected MPEG2 chroma siting convention :(
5326 * The same behaviour is observed on pre-SKL platforms as well.
5328 * Theory behind the formula (note that we ignore sub-pixel
5329 * source coordinates):
5330 * s = source sample position
5331 * d = destination sample position
5336 * | | 1.5 (initial phase)
5344 * | -0.375 (initial phase)
5351 u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
5353 int phase = -0x8000;
5357 phase += (sub - 1) * 0x8000 / sub;
5359 phase += scale / (2 * sub);
5362 * Hardware initial phase limited to [-0.5:1.5].
5363 * Since the max hardware scale factor is 3.0, we
5364 * should never actually excdeed 1.0 here.
5366 WARN_ON(phase < -0x8000 || phase > 0x18000);
5369 phase = 0x10000 + phase;
5371 trip = PS_PHASE_TRIP;
5373 return ((phase >> 2) & PS_PHASE_MASK) | trip;
5376 #define SKL_MIN_SRC_W 8
5377 #define SKL_MAX_SRC_W 4096
5378 #define SKL_MIN_SRC_H 8
5379 #define SKL_MAX_SRC_H 4096
5380 #define SKL_MIN_DST_W 8
5381 #define SKL_MAX_DST_W 4096
5382 #define SKL_MIN_DST_H 8
5383 #define SKL_MAX_DST_H 4096
5384 #define ICL_MAX_SRC_W 5120
5385 #define ICL_MAX_SRC_H 4096
5386 #define ICL_MAX_DST_W 5120
5387 #define ICL_MAX_DST_H 4096
5388 #define SKL_MIN_YUV_420_SRC_W 16
5389 #define SKL_MIN_YUV_420_SRC_H 16
5392 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
5393 unsigned int scaler_user, int *scaler_id,
5394 int src_w, int src_h, int dst_w, int dst_h,
5395 const struct drm_format_info *format, bool need_scaler)
5397 struct intel_crtc_scaler_state *scaler_state =
5398 &crtc_state->scaler_state;
5399 struct intel_crtc *intel_crtc =
5400 to_intel_crtc(crtc_state->base.crtc);
5401 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
5402 const struct drm_display_mode *adjusted_mode =
5403 &crtc_state->base.adjusted_mode;
5406 * Src coordinates are already rotated by 270 degrees for
5407 * the 90/270 degree plane rotation cases (to match the
5408 * GTT mapping), hence no need to account for rotation here.
5410 if (src_w != dst_w || src_h != dst_h)
5414 * Scaling/fitting not supported in IF-ID mode in GEN9+
5415 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
5416 * Once NV12 is enabled, handle it here while allocating scaler
5419 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
5420 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
5421 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
5426 * if plane is being disabled or scaler is no more required or force detach
5427 * - free scaler binded to this plane/crtc
5428 * - in order to do this, update crtc->scaler_usage
5430 * Here scaler state in crtc_state is set free so that
5431 * scaler can be assigned to other user. Actual register
5432 * update to free the scaler is done in plane/panel-fit programming.
5433 * For this purpose crtc/plane_state->scaler_id isn't reset here.
5435 if (force_detach || !need_scaler) {
5436 if (*scaler_id >= 0) {
5437 scaler_state->scaler_users &= ~(1 << scaler_user);
5438 scaler_state->scalers[*scaler_id].in_use = 0;
5440 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5441 "Staged freeing scaler id %d scaler_users = 0x%x\n",
5442 intel_crtc->pipe, scaler_user, *scaler_id,
5443 scaler_state->scaler_users);
5449 if (format && is_planar_yuv_format(format->format) &&
5450 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
5451 DRM_DEBUG_KMS("Planar YUV: src dimensions not met\n");
5456 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
5457 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
5458 (INTEL_GEN(dev_priv) >= 11 &&
5459 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
5460 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
5461 (INTEL_GEN(dev_priv) < 11 &&
5462 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
5463 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
5464 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
5465 "size is out of scaler range\n",
5466 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
5470 /* mark this plane as a scaler user in crtc_state */
5471 scaler_state->scaler_users |= (1 << scaler_user);
5472 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5473 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
5474 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
5475 scaler_state->scaler_users);
5481 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
5483 * @state: crtc's scaler state
5486 * 0 - scaler_usage updated successfully
5487 * error - requested scaling cannot be supported or other error condition
5489 int skl_update_scaler_crtc(struct intel_crtc_state *state)
5491 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
5492 bool need_scaler = false;
5494 if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
5497 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
5498 &state->scaler_state.scaler_id,
5499 state->pipe_src_w, state->pipe_src_h,
5500 adjusted_mode->crtc_hdisplay,
5501 adjusted_mode->crtc_vdisplay, NULL, need_scaler);
5505 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
5506 * @crtc_state: crtc's scaler state
5507 * @plane_state: atomic plane state to update
5510 * 0 - scaler_usage updated successfully
5511 * error - requested scaling cannot be supported or other error condition
5513 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
5514 struct intel_plane_state *plane_state)
5516 struct intel_plane *intel_plane =
5517 to_intel_plane(plane_state->base.plane);
5518 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
5519 struct drm_framebuffer *fb = plane_state->base.fb;
5521 bool force_detach = !fb || !plane_state->base.visible;
5522 bool need_scaler = false;
5524 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
5525 if (!icl_is_hdr_plane(dev_priv, intel_plane->id) &&
5526 fb && is_planar_yuv_format(fb->format->format))
5529 ret = skl_update_scaler(crtc_state, force_detach,
5530 drm_plane_index(&intel_plane->base),
5531 &plane_state->scaler_id,
5532 drm_rect_width(&plane_state->base.src) >> 16,
5533 drm_rect_height(&plane_state->base.src) >> 16,
5534 drm_rect_width(&plane_state->base.dst),
5535 drm_rect_height(&plane_state->base.dst),
5536 fb ? fb->format : NULL, need_scaler);
5538 if (ret || plane_state->scaler_id < 0)
5541 /* check colorkey */
5542 if (plane_state->ckey.flags) {
5543 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
5544 intel_plane->base.base.id,
5545 intel_plane->base.name);
5549 /* Check src format */
5550 switch (fb->format->format) {
5551 case DRM_FORMAT_RGB565:
5552 case DRM_FORMAT_XBGR8888:
5553 case DRM_FORMAT_XRGB8888:
5554 case DRM_FORMAT_ABGR8888:
5555 case DRM_FORMAT_ARGB8888:
5556 case DRM_FORMAT_XRGB2101010:
5557 case DRM_FORMAT_XBGR2101010:
5558 case DRM_FORMAT_XBGR16161616F:
5559 case DRM_FORMAT_ABGR16161616F:
5560 case DRM_FORMAT_XRGB16161616F:
5561 case DRM_FORMAT_ARGB16161616F:
5562 case DRM_FORMAT_YUYV:
5563 case DRM_FORMAT_YVYU:
5564 case DRM_FORMAT_UYVY:
5565 case DRM_FORMAT_VYUY:
5566 case DRM_FORMAT_NV12:
5567 case DRM_FORMAT_P010:
5568 case DRM_FORMAT_P012:
5569 case DRM_FORMAT_P016:
5570 case DRM_FORMAT_Y210:
5571 case DRM_FORMAT_Y212:
5572 case DRM_FORMAT_Y216:
5573 case DRM_FORMAT_XVYU2101010:
5574 case DRM_FORMAT_XVYU12_16161616:
5575 case DRM_FORMAT_XVYU16161616:
5578 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
5579 intel_plane->base.base.id, intel_plane->base.name,
5580 fb->base.id, fb->format->format);
5587 static void skylake_scaler_disable(struct intel_crtc *crtc)
5591 for (i = 0; i < crtc->num_scalers; i++)
5592 skl_detach_scaler(crtc, i);
5595 static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
5597 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5598 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5599 enum pipe pipe = crtc->pipe;
5600 const struct intel_crtc_scaler_state *scaler_state =
5601 &crtc_state->scaler_state;
5603 if (crtc_state->pch_pfit.enabled) {
5604 u16 uv_rgb_hphase, uv_rgb_vphase;
5605 int pfit_w, pfit_h, hscale, vscale;
5608 if (WARN_ON(crtc_state->scaler_state.scaler_id < 0))
5611 pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF;
5612 pfit_h = crtc_state->pch_pfit.size & 0xFFFF;
5614 hscale = (crtc_state->pipe_src_w << 16) / pfit_w;
5615 vscale = (crtc_state->pipe_src_h << 16) / pfit_h;
5617 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
5618 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
5620 id = scaler_state->scaler_id;
5621 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
5622 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
5623 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
5624 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5625 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
5626 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
5627 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos);
5628 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size);
5632 static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state)
5634 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5635 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5636 enum pipe pipe = crtc->pipe;
5638 if (crtc_state->pch_pfit.enabled) {
5639 /* Force use of hard-coded filter coefficients
5640 * as some pre-programmed values are broken,
5643 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
5644 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5645 PF_PIPE_SEL_IVB(pipe));
5647 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
5648 I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos);
5649 I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size);
5653 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
5655 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5656 struct drm_device *dev = crtc->base.dev;
5657 struct drm_i915_private *dev_priv = to_i915(dev);
5659 if (!crtc_state->ips_enabled)
5663 * We can only enable IPS after we enable a plane and wait for a vblank
5664 * This function is called from post_plane_update, which is run after
5667 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
5669 if (IS_BROADWELL(dev_priv)) {
5670 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5671 IPS_ENABLE | IPS_PCODE_CONTROL));
5672 /* Quoting Art Runyan: "its not safe to expect any particular
5673 * value in IPS_CTL bit 31 after enabling IPS through the
5674 * mailbox." Moreover, the mailbox may return a bogus state,
5675 * so we need to just enable it and continue on.
5678 I915_WRITE(IPS_CTL, IPS_ENABLE);
5679 /* The bit only becomes 1 in the next vblank, so this wait here
5680 * is essentially intel_wait_for_vblank. If we don't have this
5681 * and don't wait for vblanks until the end of crtc_enable, then
5682 * the HW state readout code will complain that the expected
5683 * IPS_CTL value is not the one we read. */
5684 if (intel_de_wait_for_set(dev_priv, IPS_CTL, IPS_ENABLE, 50))
5685 DRM_ERROR("Timed out waiting for IPS enable\n");
5689 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
5691 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5692 struct drm_device *dev = crtc->base.dev;
5693 struct drm_i915_private *dev_priv = to_i915(dev);
5695 if (!crtc_state->ips_enabled)
5698 if (IS_BROADWELL(dev_priv)) {
5699 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
5701 * Wait for PCODE to finish disabling IPS. The BSpec specified
5702 * 42ms timeout value leads to occasional timeouts so use 100ms
5705 if (intel_de_wait_for_clear(dev_priv, IPS_CTL, IPS_ENABLE, 100))
5706 DRM_ERROR("Timed out waiting for IPS disable\n");
5708 I915_WRITE(IPS_CTL, 0);
5709 POSTING_READ(IPS_CTL);
5712 /* We need to wait for a vblank before we can disable the plane. */
5713 intel_wait_for_vblank(dev_priv, crtc->pipe);
5716 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
5718 if (intel_crtc->overlay) {
5719 struct drm_device *dev = intel_crtc->base.dev;
5721 mutex_lock(&dev->struct_mutex);
5722 (void) intel_overlay_switch_off(intel_crtc->overlay);
5723 mutex_unlock(&dev->struct_mutex);
5726 /* Let userspace switch the overlay on again. In most cases userspace
5727 * has to recompute where to put it anyway.
5732 * intel_post_enable_primary - Perform operations after enabling primary plane
5733 * @crtc: the CRTC whose primary plane was just enabled
5734 * @new_crtc_state: the enabling state
5736 * Performs potentially sleeping operations that must be done after the primary
5737 * plane is enabled, such as updating FBC and IPS. Note that this may be
5738 * called due to an explicit primary plane update, or due to an implicit
5739 * re-enable that is caused when a sprite plane is updated to no longer
5740 * completely hide the primary plane.
5743 intel_post_enable_primary(struct drm_crtc *crtc,
5744 const struct intel_crtc_state *new_crtc_state)
5746 struct drm_device *dev = crtc->dev;
5747 struct drm_i915_private *dev_priv = to_i915(dev);
5748 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5749 enum pipe pipe = intel_crtc->pipe;
5752 * Gen2 reports pipe underruns whenever all planes are disabled.
5753 * So don't enable underrun reporting before at least some planes
5755 * FIXME: Need to fix the logic to work when we turn off all planes
5756 * but leave the pipe running.
5758 if (IS_GEN(dev_priv, 2))
5759 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5761 /* Underruns don't always raise interrupts, so check manually. */
5762 intel_check_cpu_fifo_underruns(dev_priv);
5763 intel_check_pch_fifo_underruns(dev_priv);
5766 /* FIXME get rid of this and use pre_plane_update */
5768 intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5770 struct drm_device *dev = crtc->dev;
5771 struct drm_i915_private *dev_priv = to_i915(dev);
5772 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5773 enum pipe pipe = intel_crtc->pipe;
5776 * Gen2 reports pipe underruns whenever all planes are disabled.
5777 * So disable underrun reporting before all the planes get disabled.
5779 if (IS_GEN(dev_priv, 2))
5780 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5782 hsw_disable_ips(to_intel_crtc_state(crtc->state));
5785 * Vblank time updates from the shadow to live plane control register
5786 * are blocked if the memory self-refresh mode is active at that
5787 * moment. So to make sure the plane gets truly disabled, disable
5788 * first the self-refresh mode. The self-refresh enable bit in turn
5789 * will be checked/applied by the HW only at the next frame start
5790 * event which is after the vblank start event, so we need to have a
5791 * wait-for-vblank between disabling the plane and the pipe.
5793 if (HAS_GMCH(dev_priv) &&
5794 intel_set_memory_cxsr(dev_priv, false))
5795 intel_wait_for_vblank(dev_priv, pipe);
5798 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5799 const struct intel_crtc_state *new_crtc_state)
5801 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
5802 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5804 if (!old_crtc_state->ips_enabled)
5807 if (needs_modeset(new_crtc_state))
5811 * Workaround : Do not read or write the pipe palette/gamma data while
5812 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
5814 * Disable IPS before we program the LUT.
5816 if (IS_HASWELL(dev_priv) &&
5817 (new_crtc_state->base.color_mgmt_changed ||
5818 new_crtc_state->update_pipe) &&
5819 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
5822 return !new_crtc_state->ips_enabled;
5825 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5826 const struct intel_crtc_state *new_crtc_state)
5828 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
5829 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5831 if (!new_crtc_state->ips_enabled)
5834 if (needs_modeset(new_crtc_state))
5838 * Workaround : Do not read or write the pipe palette/gamma data while
5839 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
5841 * Re-enable IPS after the LUT has been programmed.
5843 if (IS_HASWELL(dev_priv) &&
5844 (new_crtc_state->base.color_mgmt_changed ||
5845 new_crtc_state->update_pipe) &&
5846 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
5850 * We can't read out IPS on broadwell, assume the worst and
5851 * forcibly enable IPS on the first fastset.
5853 if (new_crtc_state->update_pipe &&
5854 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5857 return !old_crtc_state->ips_enabled;
5860 static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5861 const struct intel_crtc_state *crtc_state)
5863 if (!crtc_state->nv12_planes)
5866 /* WA Display #0827: Gen9:all */
5867 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv))
5873 static bool needs_scalerclk_wa(struct drm_i915_private *dev_priv,
5874 const struct intel_crtc_state *crtc_state)
5876 /* Wa_2006604312:icl */
5877 if (crtc_state->scaler_state.scaler_users > 0 && IS_ICELAKE(dev_priv))
5883 static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5885 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5886 struct drm_device *dev = crtc->base.dev;
5887 struct drm_i915_private *dev_priv = to_i915(dev);
5888 struct drm_atomic_state *state = old_crtc_state->base.state;
5889 struct intel_crtc_state *pipe_config =
5890 intel_atomic_get_new_crtc_state(to_intel_atomic_state(state),
5892 struct drm_plane *primary = crtc->base.primary;
5893 struct drm_plane_state *old_primary_state =
5894 drm_atomic_get_old_plane_state(state, primary);
5896 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
5898 if (pipe_config->update_wm_post && pipe_config->base.active)
5899 intel_update_watermarks(crtc);
5901 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5902 hsw_enable_ips(pipe_config);
5904 if (old_primary_state) {
5905 struct drm_plane_state *new_primary_state =
5906 drm_atomic_get_new_plane_state(state, primary);
5908 intel_fbc_post_update(crtc);
5910 if (new_primary_state->visible &&
5911 (needs_modeset(pipe_config) ||
5912 !old_primary_state->visible))
5913 intel_post_enable_primary(&crtc->base, pipe_config);
5916 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
5917 !needs_nv12_wa(dev_priv, pipe_config))
5918 skl_wa_827(dev_priv, crtc->pipe, false);
5920 if (needs_scalerclk_wa(dev_priv, old_crtc_state) &&
5921 !needs_scalerclk_wa(dev_priv, pipe_config))
5922 icl_wa_scalerclkgating(dev_priv, crtc->pipe, false);
5925 static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5926 struct intel_crtc_state *pipe_config)
5928 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5929 struct drm_device *dev = crtc->base.dev;
5930 struct drm_i915_private *dev_priv = to_i915(dev);
5931 struct drm_atomic_state *state = old_crtc_state->base.state;
5932 struct drm_plane *primary = crtc->base.primary;
5933 struct drm_plane_state *old_primary_state =
5934 drm_atomic_get_old_plane_state(state, primary);
5935 bool modeset = needs_modeset(pipe_config);
5936 struct intel_atomic_state *intel_state =
5937 to_intel_atomic_state(state);
5939 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5940 hsw_disable_ips(old_crtc_state);
5942 if (old_primary_state) {
5943 struct intel_plane_state *new_primary_state =
5944 intel_atomic_get_new_plane_state(intel_state,
5945 to_intel_plane(primary));
5947 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
5949 * Gen2 reports pipe underruns whenever all planes are disabled.
5950 * So disable underrun reporting before all the planes get disabled.
5952 if (IS_GEN(dev_priv, 2) && old_primary_state->visible &&
5953 (modeset || !new_primary_state->base.visible))
5954 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
5957 /* Display WA 827 */
5958 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
5959 needs_nv12_wa(dev_priv, pipe_config))
5960 skl_wa_827(dev_priv, crtc->pipe, true);
5962 /* Wa_2006604312:icl */
5963 if (!needs_scalerclk_wa(dev_priv, old_crtc_state) &&
5964 needs_scalerclk_wa(dev_priv, pipe_config))
5965 icl_wa_scalerclkgating(dev_priv, crtc->pipe, true);
5968 * Vblank time updates from the shadow to live plane control register
5969 * are blocked if the memory self-refresh mode is active at that
5970 * moment. So to make sure the plane gets truly disabled, disable
5971 * first the self-refresh mode. The self-refresh enable bit in turn
5972 * will be checked/applied by the HW only at the next frame start
5973 * event which is after the vblank start event, so we need to have a
5974 * wait-for-vblank between disabling the plane and the pipe.
5976 if (HAS_GMCH(dev_priv) && old_crtc_state->base.active &&
5977 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5978 intel_wait_for_vblank(dev_priv, crtc->pipe);
5981 * IVB workaround: must disable low power watermarks for at least
5982 * one frame before enabling scaling. LP watermarks can be re-enabled
5983 * when scaling is disabled.
5985 * WaCxSRDisabledForSpriteScaling:ivb
5987 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) &&
5988 old_crtc_state->base.active)
5989 intel_wait_for_vblank(dev_priv, crtc->pipe);
5992 * If we're doing a modeset, we're done. No need to do any pre-vblank
5993 * watermark programming here.
5995 if (needs_modeset(pipe_config))
5999 * For platforms that support atomic watermarks, program the
6000 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
6001 * will be the intermediate values that are safe for both pre- and
6002 * post- vblank; when vblank happens, the 'active' values will be set
6003 * to the final 'target' values and we'll do this again to get the
6004 * optimal watermarks. For gen9+ platforms, the values we program here
6005 * will be the final target values which will get automatically latched
6006 * at vblank time; no further programming will be necessary.
6008 * If a platform hasn't been transitioned to atomic watermarks yet,
6009 * we'll continue to update watermarks the old way, if flags tell
6012 if (dev_priv->display.initial_watermarks != NULL)
6013 dev_priv->display.initial_watermarks(intel_state,
6015 else if (pipe_config->update_wm_pre)
6016 intel_update_watermarks(crtc);
6019 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
6020 struct intel_crtc *crtc)
6022 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6023 const struct intel_crtc_state *new_crtc_state =
6024 intel_atomic_get_new_crtc_state(state, crtc);
6025 unsigned int update_mask = new_crtc_state->update_planes;
6026 const struct intel_plane_state *old_plane_state;
6027 struct intel_plane *plane;
6028 unsigned fb_bits = 0;
6031 intel_crtc_dpms_overlay_disable(crtc);
6033 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
6034 if (crtc->pipe != plane->pipe ||
6035 !(update_mask & BIT(plane->id)))
6038 intel_disable_plane(plane, new_crtc_state);
6040 if (old_plane_state->base.visible)
6041 fb_bits |= plane->frontbuffer_bit;
6044 intel_frontbuffer_flip(dev_priv, fb_bits);
6048 * intel_connector_primary_encoder - get the primary encoder for a connector
6049 * @connector: connector for which to return the encoder
6051 * Returns the primary encoder for a connector. There is a 1:1 mapping from
6052 * all connectors to their encoder, except for DP-MST connectors which have
6053 * both a virtual and a primary encoder. These DP-MST primary encoders can be
6054 * pointed to by as many DP-MST connectors as there are pipes.
6056 static struct intel_encoder *
6057 intel_connector_primary_encoder(struct intel_connector *connector)
6059 struct intel_encoder *encoder;
6061 if (connector->mst_port)
6062 return &dp_to_dig_port(connector->mst_port)->base;
6064 encoder = intel_attached_encoder(&connector->base);
6071 intel_connector_needs_modeset(struct intel_atomic_state *state,
6072 const struct drm_connector_state *old_conn_state,
6073 const struct drm_connector_state *new_conn_state)
6075 struct intel_crtc *old_crtc = old_conn_state->crtc ?
6076 to_intel_crtc(old_conn_state->crtc) : NULL;
6077 struct intel_crtc *new_crtc = new_conn_state->crtc ?
6078 to_intel_crtc(new_conn_state->crtc) : NULL;
6080 return new_crtc != old_crtc ||
6082 needs_modeset(intel_atomic_get_new_crtc_state(state, new_crtc)));
6085 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
6087 struct drm_connector_state *old_conn_state;
6088 struct drm_connector_state *new_conn_state;
6089 struct drm_connector *conn;
6092 for_each_oldnew_connector_in_state(&state->base, conn,
6093 old_conn_state, new_conn_state, i) {
6094 struct intel_encoder *encoder;
6095 struct intel_crtc *crtc;
6097 if (!intel_connector_needs_modeset(state,
6102 encoder = intel_connector_primary_encoder(to_intel_connector(conn));
6103 if (!encoder->update_prepare)
6106 crtc = new_conn_state->crtc ?
6107 to_intel_crtc(new_conn_state->crtc) : NULL;
6108 encoder->update_prepare(state, encoder, crtc);
6112 static void intel_encoders_update_complete(struct intel_atomic_state *state)
6114 struct drm_connector_state *old_conn_state;
6115 struct drm_connector_state *new_conn_state;
6116 struct drm_connector *conn;
6119 for_each_oldnew_connector_in_state(&state->base, conn,
6120 old_conn_state, new_conn_state, i) {
6121 struct intel_encoder *encoder;
6122 struct intel_crtc *crtc;
6124 if (!intel_connector_needs_modeset(state,
6129 encoder = intel_connector_primary_encoder(to_intel_connector(conn));
6130 if (!encoder->update_complete)
6133 crtc = new_conn_state->crtc ?
6134 to_intel_crtc(new_conn_state->crtc) : NULL;
6135 encoder->update_complete(state, encoder, crtc);
6139 static void intel_encoders_pre_pll_enable(struct intel_crtc *crtc,
6140 struct intel_crtc_state *crtc_state,
6141 struct intel_atomic_state *state)
6143 struct drm_connector_state *conn_state;
6144 struct drm_connector *conn;
6147 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6148 struct intel_encoder *encoder =
6149 to_intel_encoder(conn_state->best_encoder);
6151 if (conn_state->crtc != &crtc->base)
6154 if (encoder->pre_pll_enable)
6155 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
6159 static void intel_encoders_pre_enable(struct intel_crtc *crtc,
6160 struct intel_crtc_state *crtc_state,
6161 struct intel_atomic_state *state)
6163 struct drm_connector_state *conn_state;
6164 struct drm_connector *conn;
6167 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6168 struct intel_encoder *encoder =
6169 to_intel_encoder(conn_state->best_encoder);
6171 if (conn_state->crtc != &crtc->base)
6174 if (encoder->pre_enable)
6175 encoder->pre_enable(encoder, crtc_state, conn_state);
6179 static void intel_encoders_enable(struct intel_crtc *crtc,
6180 struct intel_crtc_state *crtc_state,
6181 struct intel_atomic_state *state)
6183 struct drm_connector_state *conn_state;
6184 struct drm_connector *conn;
6187 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6188 struct intel_encoder *encoder =
6189 to_intel_encoder(conn_state->best_encoder);
6191 if (conn_state->crtc != &crtc->base)
6194 if (encoder->enable)
6195 encoder->enable(encoder, crtc_state, conn_state);
6196 intel_opregion_notify_encoder(encoder, true);
6200 static void intel_encoders_disable(struct intel_crtc *crtc,
6201 struct intel_crtc_state *old_crtc_state,
6202 struct intel_atomic_state *state)
6204 struct drm_connector_state *old_conn_state;
6205 struct drm_connector *conn;
6208 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6209 struct intel_encoder *encoder =
6210 to_intel_encoder(old_conn_state->best_encoder);
6212 if (old_conn_state->crtc != &crtc->base)
6215 intel_opregion_notify_encoder(encoder, false);
6216 if (encoder->disable)
6217 encoder->disable(encoder, old_crtc_state, old_conn_state);
6221 static void intel_encoders_post_disable(struct intel_crtc *crtc,
6222 struct intel_crtc_state *old_crtc_state,
6223 struct intel_atomic_state *state)
6225 struct drm_connector_state *old_conn_state;
6226 struct drm_connector *conn;
6229 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6230 struct intel_encoder *encoder =
6231 to_intel_encoder(old_conn_state->best_encoder);
6233 if (old_conn_state->crtc != &crtc->base)
6236 if (encoder->post_disable)
6237 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
6241 static void intel_encoders_post_pll_disable(struct intel_crtc *crtc,
6242 struct intel_crtc_state *old_crtc_state,
6243 struct intel_atomic_state *state)
6245 struct drm_connector_state *old_conn_state;
6246 struct drm_connector *conn;
6249 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6250 struct intel_encoder *encoder =
6251 to_intel_encoder(old_conn_state->best_encoder);
6253 if (old_conn_state->crtc != &crtc->base)
6256 if (encoder->post_pll_disable)
6257 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
6261 static void intel_encoders_update_pipe(struct intel_crtc *crtc,
6262 struct intel_crtc_state *crtc_state,
6263 struct intel_atomic_state *state)
6265 struct drm_connector_state *conn_state;
6266 struct drm_connector *conn;
6269 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6270 struct intel_encoder *encoder =
6271 to_intel_encoder(conn_state->best_encoder);
6273 if (conn_state->crtc != &crtc->base)
6276 if (encoder->update_pipe)
6277 encoder->update_pipe(encoder, crtc_state, conn_state);
6281 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
6283 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6284 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
6286 plane->disable_plane(plane, crtc_state);
6289 static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
6290 struct intel_atomic_state *state)
6292 struct drm_crtc *crtc = pipe_config->base.crtc;
6293 struct drm_device *dev = crtc->dev;
6294 struct drm_i915_private *dev_priv = to_i915(dev);
6295 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6296 enum pipe pipe = intel_crtc->pipe;
6298 if (WARN_ON(intel_crtc->active))
6302 * Sometimes spurious CPU pipe underruns happen during FDI
6303 * training, at least with VGA+HDMI cloning. Suppress them.
6305 * On ILK we get an occasional spurious CPU pipe underruns
6306 * between eDP port A enable and vdd enable. Also PCH port
6307 * enable seems to result in the occasional CPU pipe underrun.
6309 * Spurious PCH underruns also occur during PCH enabling.
6311 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6312 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6314 if (pipe_config->has_pch_encoder)
6315 intel_prepare_shared_dpll(pipe_config);
6317 if (intel_crtc_has_dp_encoder(pipe_config))
6318 intel_dp_set_m_n(pipe_config, M1_N1);
6320 intel_set_pipe_timings(pipe_config);
6321 intel_set_pipe_src_size(pipe_config);
6323 if (pipe_config->has_pch_encoder) {
6324 intel_cpu_transcoder_set_m_n(pipe_config,
6325 &pipe_config->fdi_m_n, NULL);
6328 ironlake_set_pipeconf(pipe_config);
6330 intel_crtc->active = true;
6332 intel_encoders_pre_enable(intel_crtc, pipe_config, state);
6334 if (pipe_config->has_pch_encoder) {
6335 /* Note: FDI PLL enabling _must_ be done before we enable the
6336 * cpu pipes, hence this is separate from all the other fdi/pch
6338 ironlake_fdi_pll_enable(pipe_config);
6340 assert_fdi_tx_disabled(dev_priv, pipe);
6341 assert_fdi_rx_disabled(dev_priv, pipe);
6344 ironlake_pfit_enable(pipe_config);
6347 * On ILK+ LUT must be loaded before the pipe is running but with
6350 intel_color_load_luts(pipe_config);
6351 intel_color_commit(pipe_config);
6352 /* update DSPCNTR to configure gamma for pipe bottom color */
6353 intel_disable_primary_plane(pipe_config);
6355 if (dev_priv->display.initial_watermarks != NULL)
6356 dev_priv->display.initial_watermarks(state, pipe_config);
6357 intel_enable_pipe(pipe_config);
6359 if (pipe_config->has_pch_encoder)
6360 ironlake_pch_enable(state, pipe_config);
6362 assert_vblank_disabled(crtc);
6363 intel_crtc_vblank_on(pipe_config);
6365 intel_encoders_enable(intel_crtc, pipe_config, state);
6367 if (HAS_PCH_CPT(dev_priv))
6368 cpt_verify_modeset(dev, intel_crtc->pipe);
6371 * Must wait for vblank to avoid spurious PCH FIFO underruns.
6372 * And a second vblank wait is needed at least on ILK with
6373 * some interlaced HDMI modes. Let's do the double wait always
6374 * in case there are more corner cases we don't know about.
6376 if (pipe_config->has_pch_encoder) {
6377 intel_wait_for_vblank(dev_priv, pipe);
6378 intel_wait_for_vblank(dev_priv, pipe);
6380 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6381 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6384 /* IPS only exists on ULT machines and is tied to pipe A. */
6385 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
6387 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
6390 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
6391 enum pipe pipe, bool apply)
6393 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
6394 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
6401 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
6404 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
6406 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6407 enum pipe pipe = crtc->pipe;
6410 val = MBUS_DBOX_A_CREDIT(2);
6412 if (INTEL_GEN(dev_priv) >= 12) {
6413 val |= MBUS_DBOX_BW_CREDIT(2);
6414 val |= MBUS_DBOX_B_CREDIT(12);
6416 val |= MBUS_DBOX_BW_CREDIT(1);
6417 val |= MBUS_DBOX_B_CREDIT(8);
6420 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
6423 static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
6424 struct intel_atomic_state *state)
6426 struct drm_crtc *crtc = pipe_config->base.crtc;
6427 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6428 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6429 enum pipe pipe = intel_crtc->pipe, hsw_workaround_pipe;
6430 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
6431 bool psl_clkgate_wa;
6433 if (WARN_ON(intel_crtc->active))
6436 intel_encoders_pre_pll_enable(intel_crtc, pipe_config, state);
6438 if (pipe_config->shared_dpll)
6439 intel_enable_shared_dpll(pipe_config);
6441 intel_encoders_pre_enable(intel_crtc, pipe_config, state);
6443 if (intel_crtc_has_dp_encoder(pipe_config))
6444 intel_dp_set_m_n(pipe_config, M1_N1);
6446 if (!transcoder_is_dsi(cpu_transcoder))
6447 intel_set_pipe_timings(pipe_config);
6449 intel_set_pipe_src_size(pipe_config);
6451 if (cpu_transcoder != TRANSCODER_EDP &&
6452 !transcoder_is_dsi(cpu_transcoder)) {
6453 I915_WRITE(PIPE_MULT(cpu_transcoder),
6454 pipe_config->pixel_multiplier - 1);
6457 if (pipe_config->has_pch_encoder) {
6458 intel_cpu_transcoder_set_m_n(pipe_config,
6459 &pipe_config->fdi_m_n, NULL);
6462 if (!transcoder_is_dsi(cpu_transcoder))
6463 haswell_set_pipeconf(pipe_config);
6465 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
6466 bdw_set_pipemisc(pipe_config);
6468 intel_crtc->active = true;
6470 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
6471 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
6472 pipe_config->pch_pfit.enabled;
6474 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
6476 if (INTEL_GEN(dev_priv) >= 9)
6477 skylake_pfit_enable(pipe_config);
6479 ironlake_pfit_enable(pipe_config);
6482 * On ILK+ LUT must be loaded before the pipe is running but with
6485 intel_color_load_luts(pipe_config);
6486 intel_color_commit(pipe_config);
6487 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
6488 if (INTEL_GEN(dev_priv) < 9)
6489 intel_disable_primary_plane(pipe_config);
6491 if (INTEL_GEN(dev_priv) >= 11)
6492 icl_set_pipe_chicken(intel_crtc);
6494 intel_ddi_set_pipe_settings(pipe_config);
6495 if (!transcoder_is_dsi(cpu_transcoder))
6496 intel_ddi_enable_transcoder_func(pipe_config);
6498 if (dev_priv->display.initial_watermarks != NULL)
6499 dev_priv->display.initial_watermarks(state, pipe_config);
6501 if (INTEL_GEN(dev_priv) >= 11)
6502 icl_pipe_mbus_enable(intel_crtc);
6504 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
6505 if (!transcoder_is_dsi(cpu_transcoder))
6506 intel_enable_pipe(pipe_config);
6508 if (pipe_config->has_pch_encoder)
6509 lpt_pch_enable(state, pipe_config);
6511 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST))
6512 intel_ddi_set_vc_payload_alloc(pipe_config, true);
6514 assert_vblank_disabled(crtc);
6515 intel_crtc_vblank_on(pipe_config);
6517 intel_encoders_enable(intel_crtc, pipe_config, state);
6519 if (psl_clkgate_wa) {
6520 intel_wait_for_vblank(dev_priv, pipe);
6521 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
6524 /* If we change the relative order between pipe/planes enabling, we need
6525 * to change the workaround. */
6526 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
6527 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
6528 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6529 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6533 static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6535 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6536 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6537 enum pipe pipe = crtc->pipe;
6539 /* To avoid upsetting the power well on haswell only disable the pfit if
6540 * it's in use. The hw state code will make sure we get this right. */
6541 if (old_crtc_state->pch_pfit.enabled) {
6542 I915_WRITE(PF_CTL(pipe), 0);
6543 I915_WRITE(PF_WIN_POS(pipe), 0);
6544 I915_WRITE(PF_WIN_SZ(pipe), 0);
6548 static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
6549 struct intel_atomic_state *state)
6551 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6552 struct drm_device *dev = crtc->dev;
6553 struct drm_i915_private *dev_priv = to_i915(dev);
6554 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6555 enum pipe pipe = intel_crtc->pipe;
6558 * Sometimes spurious CPU pipe underruns happen when the
6559 * pipe is already disabled, but FDI RX/TX is still enabled.
6560 * Happens at least with VGA+HDMI cloning. Suppress them.
6562 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6563 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6565 intel_encoders_disable(intel_crtc, old_crtc_state, state);
6567 drm_crtc_vblank_off(crtc);
6568 assert_vblank_disabled(crtc);
6570 intel_disable_pipe(old_crtc_state);
6572 ironlake_pfit_disable(old_crtc_state);
6574 if (old_crtc_state->has_pch_encoder)
6575 ironlake_fdi_disable(crtc);
6577 intel_encoders_post_disable(intel_crtc, old_crtc_state, state);
6579 if (old_crtc_state->has_pch_encoder) {
6580 ironlake_disable_pch_transcoder(dev_priv, pipe);
6582 if (HAS_PCH_CPT(dev_priv)) {
6586 /* disable TRANS_DP_CTL */
6587 reg = TRANS_DP_CTL(pipe);
6588 temp = I915_READ(reg);
6589 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
6590 TRANS_DP_PORT_SEL_MASK);
6591 temp |= TRANS_DP_PORT_SEL_NONE;
6592 I915_WRITE(reg, temp);
6594 /* disable DPLL_SEL */
6595 temp = I915_READ(PCH_DPLL_SEL);
6596 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
6597 I915_WRITE(PCH_DPLL_SEL, temp);
6600 ironlake_fdi_pll_disable(intel_crtc);
6603 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6604 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6607 static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
6608 struct intel_atomic_state *state)
6610 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6611 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6612 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6613 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
6615 intel_encoders_disable(intel_crtc, old_crtc_state, state);
6617 drm_crtc_vblank_off(crtc);
6618 assert_vblank_disabled(crtc);
6620 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
6621 if (!transcoder_is_dsi(cpu_transcoder))
6622 intel_disable_pipe(old_crtc_state);
6624 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
6625 intel_ddi_set_vc_payload_alloc(old_crtc_state, false);
6627 if (!transcoder_is_dsi(cpu_transcoder))
6628 intel_ddi_disable_transcoder_func(old_crtc_state);
6630 intel_dsc_disable(old_crtc_state);
6632 if (INTEL_GEN(dev_priv) >= 9)
6633 skylake_scaler_disable(intel_crtc);
6635 ironlake_pfit_disable(old_crtc_state);
6637 intel_encoders_post_disable(intel_crtc, old_crtc_state, state);
6639 intel_encoders_post_pll_disable(intel_crtc, old_crtc_state, state);
6642 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
6644 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6645 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6647 if (!crtc_state->gmch_pfit.control)
6651 * The panel fitter should only be adjusted whilst the pipe is disabled,
6652 * according to register description and PRM.
6654 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
6655 assert_pipe_disabled(dev_priv, crtc->pipe);
6657 I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
6658 I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
6660 /* Border color in case we don't scale up to the full screen. Black by
6661 * default, change to something else for debugging. */
6662 I915_WRITE(BCLRPAT(crtc->pipe), 0);
6665 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
6667 if (phy == PHY_NONE)
6670 if (IS_ELKHARTLAKE(dev_priv))
6671 return phy <= PHY_C;
6673 if (INTEL_GEN(dev_priv) >= 11)
6674 return phy <= PHY_B;
6679 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
6681 if (INTEL_GEN(dev_priv) >= 12)
6682 return phy >= PHY_D && phy <= PHY_I;
6684 if (INTEL_GEN(dev_priv) >= 11 && !IS_ELKHARTLAKE(dev_priv))
6685 return phy >= PHY_C && phy <= PHY_F;
6690 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
6692 if (IS_ELKHARTLAKE(i915) && port == PORT_D)
6695 return (enum phy)port;
6698 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
6700 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
6701 return PORT_TC_NONE;
6703 if (INTEL_GEN(dev_priv) >= 12)
6704 return port - PORT_D;
6706 return port - PORT_C;
6709 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
6713 return POWER_DOMAIN_PORT_DDI_A_LANES;
6715 return POWER_DOMAIN_PORT_DDI_B_LANES;
6717 return POWER_DOMAIN_PORT_DDI_C_LANES;
6719 return POWER_DOMAIN_PORT_DDI_D_LANES;
6721 return POWER_DOMAIN_PORT_DDI_E_LANES;
6723 return POWER_DOMAIN_PORT_DDI_F_LANES;
6726 return POWER_DOMAIN_PORT_OTHER;
6730 enum intel_display_power_domain
6731 intel_aux_power_domain(struct intel_digital_port *dig_port)
6733 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
6734 enum phy phy = intel_port_to_phy(dev_priv, dig_port->base.port);
6736 if (intel_phy_is_tc(dev_priv, phy) &&
6737 dig_port->tc_mode == TC_PORT_TBT_ALT) {
6738 switch (dig_port->aux_ch) {
6740 return POWER_DOMAIN_AUX_C_TBT;
6742 return POWER_DOMAIN_AUX_D_TBT;
6744 return POWER_DOMAIN_AUX_E_TBT;
6746 return POWER_DOMAIN_AUX_F_TBT;
6748 MISSING_CASE(dig_port->aux_ch);
6749 return POWER_DOMAIN_AUX_C_TBT;
6753 switch (dig_port->aux_ch) {
6755 return POWER_DOMAIN_AUX_A;
6757 return POWER_DOMAIN_AUX_B;
6759 return POWER_DOMAIN_AUX_C;
6761 return POWER_DOMAIN_AUX_D;
6763 return POWER_DOMAIN_AUX_E;
6765 return POWER_DOMAIN_AUX_F;
6767 MISSING_CASE(dig_port->aux_ch);
6768 return POWER_DOMAIN_AUX_A;
6772 static u64 get_crtc_power_domains(struct intel_crtc_state *crtc_state)
6774 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6775 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6776 struct drm_encoder *encoder;
6777 enum pipe pipe = crtc->pipe;
6779 enum transcoder transcoder = crtc_state->cpu_transcoder;
6781 if (!crtc_state->base.active)
6784 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
6785 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
6786 if (crtc_state->pch_pfit.enabled ||
6787 crtc_state->pch_pfit.force_thru)
6788 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
6790 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
6791 crtc_state->base.encoder_mask) {
6792 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6794 mask |= BIT_ULL(intel_encoder->power_domain);
6797 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
6798 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
6800 if (crtc_state->shared_dpll)
6801 mask |= BIT_ULL(POWER_DOMAIN_DISPLAY_CORE);
6807 modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state)
6809 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6810 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6811 enum intel_display_power_domain domain;
6812 u64 domains, new_domains, old_domains;
6814 old_domains = crtc->enabled_power_domains;
6815 crtc->enabled_power_domains = new_domains =
6816 get_crtc_power_domains(crtc_state);
6818 domains = new_domains & ~old_domains;
6820 for_each_power_domain(domain, domains)
6821 intel_display_power_get(dev_priv, domain);
6823 return old_domains & ~new_domains;
6826 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
6829 enum intel_display_power_domain domain;
6831 for_each_power_domain(domain, domains)
6832 intel_display_power_put_unchecked(dev_priv, domain);
6835 static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
6836 struct intel_atomic_state *state)
6838 struct drm_crtc *crtc = pipe_config->base.crtc;
6839 struct drm_device *dev = crtc->dev;
6840 struct drm_i915_private *dev_priv = to_i915(dev);
6841 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6842 enum pipe pipe = intel_crtc->pipe;
6844 if (WARN_ON(intel_crtc->active))
6847 if (intel_crtc_has_dp_encoder(pipe_config))
6848 intel_dp_set_m_n(pipe_config, M1_N1);
6850 intel_set_pipe_timings(pipe_config);
6851 intel_set_pipe_src_size(pipe_config);
6853 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
6854 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6855 I915_WRITE(CHV_CANVAS(pipe), 0);
6858 i9xx_set_pipeconf(pipe_config);
6860 intel_crtc->active = true;
6862 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6864 intel_encoders_pre_pll_enable(intel_crtc, pipe_config, state);
6866 if (IS_CHERRYVIEW(dev_priv)) {
6867 chv_prepare_pll(intel_crtc, pipe_config);
6868 chv_enable_pll(intel_crtc, pipe_config);
6870 vlv_prepare_pll(intel_crtc, pipe_config);
6871 vlv_enable_pll(intel_crtc, pipe_config);
6874 intel_encoders_pre_enable(intel_crtc, pipe_config, state);
6876 i9xx_pfit_enable(pipe_config);
6878 intel_color_load_luts(pipe_config);
6879 intel_color_commit(pipe_config);
6880 /* update DSPCNTR to configure gamma for pipe bottom color */
6881 intel_disable_primary_plane(pipe_config);
6883 dev_priv->display.initial_watermarks(state, pipe_config);
6884 intel_enable_pipe(pipe_config);
6886 assert_vblank_disabled(crtc);
6887 intel_crtc_vblank_on(pipe_config);
6889 intel_encoders_enable(intel_crtc, pipe_config, state);
6892 static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
6894 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6895 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6897 I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0);
6898 I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1);
6901 static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
6902 struct intel_atomic_state *state)
6904 struct drm_crtc *crtc = pipe_config->base.crtc;
6905 struct drm_device *dev = crtc->dev;
6906 struct drm_i915_private *dev_priv = to_i915(dev);
6907 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6908 enum pipe pipe = intel_crtc->pipe;
6910 if (WARN_ON(intel_crtc->active))
6913 i9xx_set_pll_dividers(pipe_config);
6915 if (intel_crtc_has_dp_encoder(pipe_config))
6916 intel_dp_set_m_n(pipe_config, M1_N1);
6918 intel_set_pipe_timings(pipe_config);
6919 intel_set_pipe_src_size(pipe_config);
6921 i9xx_set_pipeconf(pipe_config);
6923 intel_crtc->active = true;
6925 if (!IS_GEN(dev_priv, 2))
6926 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6928 intel_encoders_pre_enable(intel_crtc, pipe_config, state);
6930 i9xx_enable_pll(intel_crtc, pipe_config);
6932 i9xx_pfit_enable(pipe_config);
6934 intel_color_load_luts(pipe_config);
6935 intel_color_commit(pipe_config);
6936 /* update DSPCNTR to configure gamma for pipe bottom color */
6937 intel_disable_primary_plane(pipe_config);
6939 if (dev_priv->display.initial_watermarks != NULL)
6940 dev_priv->display.initial_watermarks(state,
6943 intel_update_watermarks(intel_crtc);
6944 intel_enable_pipe(pipe_config);
6946 assert_vblank_disabled(crtc);
6947 intel_crtc_vblank_on(pipe_config);
6949 intel_encoders_enable(intel_crtc, pipe_config, state);
6952 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6954 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6955 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6957 if (!old_crtc_state->gmch_pfit.control)
6960 assert_pipe_disabled(dev_priv, crtc->pipe);
6962 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
6963 I915_READ(PFIT_CONTROL));
6964 I915_WRITE(PFIT_CONTROL, 0);
6967 static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6968 struct intel_atomic_state *state)
6970 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6971 struct drm_device *dev = crtc->dev;
6972 struct drm_i915_private *dev_priv = to_i915(dev);
6973 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6974 enum pipe pipe = intel_crtc->pipe;
6977 * On gen2 planes are double buffered but the pipe isn't, so we must
6978 * wait for planes to fully turn off before disabling the pipe.
6980 if (IS_GEN(dev_priv, 2))
6981 intel_wait_for_vblank(dev_priv, pipe);
6983 intel_encoders_disable(intel_crtc, old_crtc_state, state);
6985 drm_crtc_vblank_off(crtc);
6986 assert_vblank_disabled(crtc);
6988 intel_disable_pipe(old_crtc_state);
6990 i9xx_pfit_disable(old_crtc_state);
6992 intel_encoders_post_disable(intel_crtc, old_crtc_state, state);
6994 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
6995 if (IS_CHERRYVIEW(dev_priv))
6996 chv_disable_pll(dev_priv, pipe);
6997 else if (IS_VALLEYVIEW(dev_priv))
6998 vlv_disable_pll(dev_priv, pipe);
7000 i9xx_disable_pll(old_crtc_state);
7003 intel_encoders_post_pll_disable(intel_crtc, old_crtc_state, state);
7005 if (!IS_GEN(dev_priv, 2))
7006 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
7008 if (!dev_priv->display.initial_watermarks)
7009 intel_update_watermarks(intel_crtc);
7011 /* clock the pipe down to 640x480@60 to potentially save power */
7012 if (IS_I830(dev_priv))
7013 i830_enable_pipe(dev_priv, pipe);
7016 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
7017 struct drm_modeset_acquire_ctx *ctx)
7019 struct intel_encoder *encoder;
7020 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7021 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
7022 struct intel_bw_state *bw_state =
7023 to_intel_bw_state(dev_priv->bw_obj.state);
7024 enum intel_display_power_domain domain;
7025 struct intel_plane *plane;
7027 struct drm_atomic_state *state;
7028 struct intel_crtc_state *crtc_state;
7031 if (!intel_crtc->active)
7034 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
7035 const struct intel_plane_state *plane_state =
7036 to_intel_plane_state(plane->base.state);
7038 if (plane_state->base.visible)
7039 intel_plane_disable_noatomic(intel_crtc, plane);
7042 state = drm_atomic_state_alloc(crtc->dev);
7044 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
7045 crtc->base.id, crtc->name);
7049 state->acquire_ctx = ctx;
7051 /* Everything's already locked, -EDEADLK can't happen. */
7052 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
7053 ret = drm_atomic_add_affected_connectors(state, crtc);
7055 WARN_ON(IS_ERR(crtc_state) || ret);
7057 dev_priv->display.crtc_disable(crtc_state, to_intel_atomic_state(state));
7059 drm_atomic_state_put(state);
7061 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
7062 crtc->base.id, crtc->name);
7064 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
7065 crtc->state->active = false;
7066 intel_crtc->active = false;
7067 crtc->enabled = false;
7068 crtc->state->connector_mask = 0;
7069 crtc->state->encoder_mask = 0;
7071 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
7072 encoder->base.crtc = NULL;
7074 intel_fbc_disable(intel_crtc);
7075 intel_update_watermarks(intel_crtc);
7076 intel_disable_shared_dpll(to_intel_crtc_state(crtc->state));
7078 domains = intel_crtc->enabled_power_domains;
7079 for_each_power_domain(domain, domains)
7080 intel_display_power_put_unchecked(dev_priv, domain);
7081 intel_crtc->enabled_power_domains = 0;
7083 dev_priv->active_pipes &= ~BIT(intel_crtc->pipe);
7084 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
7085 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
7087 bw_state->data_rate[intel_crtc->pipe] = 0;
7088 bw_state->num_active_planes[intel_crtc->pipe] = 0;
7092 * turn all crtc's off, but do not adjust state
7093 * This has to be paired with a call to intel_modeset_setup_hw_state.
7095 int intel_display_suspend(struct drm_device *dev)
7097 struct drm_i915_private *dev_priv = to_i915(dev);
7098 struct drm_atomic_state *state;
7101 state = drm_atomic_helper_suspend(dev);
7102 ret = PTR_ERR_OR_ZERO(state);
7104 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
7106 dev_priv->modeset_restore_state = state;
7110 void intel_encoder_destroy(struct drm_encoder *encoder)
7112 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
7114 drm_encoder_cleanup(encoder);
7115 kfree(intel_encoder);
7118 /* Cross check the actual hw state with our own modeset state tracking (and it's
7119 * internal consistency). */
7120 static void intel_connector_verify_state(struct intel_crtc_state *crtc_state,
7121 struct drm_connector_state *conn_state)
7123 struct intel_connector *connector = to_intel_connector(conn_state->connector);
7125 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
7126 connector->base.base.id,
7127 connector->base.name);
7129 if (connector->get_hw_state(connector)) {
7130 struct intel_encoder *encoder = connector->encoder;
7132 I915_STATE_WARN(!crtc_state,
7133 "connector enabled without attached crtc\n");
7138 I915_STATE_WARN(!crtc_state->base.active,
7139 "connector is active, but attached crtc isn't\n");
7141 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
7144 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
7145 "atomic encoder doesn't match attached encoder\n");
7147 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
7148 "attached encoder crtc differs from connector crtc\n");
7150 I915_STATE_WARN(crtc_state && crtc_state->base.active,
7151 "attached crtc is active, but connector isn't\n");
7152 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
7153 "best encoder set without crtc!\n");
7157 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
7159 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
7160 return crtc_state->fdi_lanes;
7165 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
7166 struct intel_crtc_state *pipe_config)
7168 struct drm_i915_private *dev_priv = to_i915(dev);
7169 struct drm_atomic_state *state = pipe_config->base.state;
7170 struct intel_crtc *other_crtc;
7171 struct intel_crtc_state *other_crtc_state;
7173 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
7174 pipe_name(pipe), pipe_config->fdi_lanes);
7175 if (pipe_config->fdi_lanes > 4) {
7176 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
7177 pipe_name(pipe), pipe_config->fdi_lanes);
7181 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7182 if (pipe_config->fdi_lanes > 2) {
7183 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
7184 pipe_config->fdi_lanes);
7191 if (INTEL_INFO(dev_priv)->num_pipes == 2)
7194 /* Ivybridge 3 pipe is really complicated */
7199 if (pipe_config->fdi_lanes <= 2)
7202 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
7204 intel_atomic_get_crtc_state(state, other_crtc);
7205 if (IS_ERR(other_crtc_state))
7206 return PTR_ERR(other_crtc_state);
7208 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
7209 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
7210 pipe_name(pipe), pipe_config->fdi_lanes);
7215 if (pipe_config->fdi_lanes > 2) {
7216 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
7217 pipe_name(pipe), pipe_config->fdi_lanes);
7221 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
7223 intel_atomic_get_crtc_state(state, other_crtc);
7224 if (IS_ERR(other_crtc_state))
7225 return PTR_ERR(other_crtc_state);
7227 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
7228 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
7238 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
7239 struct intel_crtc_state *pipe_config)
7241 struct drm_device *dev = intel_crtc->base.dev;
7242 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
7243 int lane, link_bw, fdi_dotclock, ret;
7244 bool needs_recompute = false;
7247 /* FDI is a binary signal running at ~2.7GHz, encoding
7248 * each output octet as 10 bits. The actual frequency
7249 * is stored as a divider into a 100MHz clock, and the
7250 * mode pixel clock is stored in units of 1KHz.
7251 * Hence the bw of each lane in terms of the mode signal
7254 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
7256 fdi_dotclock = adjusted_mode->crtc_clock;
7258 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
7259 pipe_config->pipe_bpp);
7261 pipe_config->fdi_lanes = lane;
7263 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
7264 link_bw, &pipe_config->fdi_m_n, false);
7266 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
7267 if (ret == -EDEADLK)
7270 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
7271 pipe_config->pipe_bpp -= 2*3;
7272 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
7273 pipe_config->pipe_bpp);
7274 needs_recompute = true;
7275 pipe_config->bw_constrained = true;
7280 if (needs_recompute)
7286 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
7288 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7289 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7291 /* IPS only exists on ULT machines and is tied to pipe A. */
7292 if (!hsw_crtc_supports_ips(crtc))
7295 if (!i915_modparams.enable_ips)
7298 if (crtc_state->pipe_bpp > 24)
7302 * We compare against max which means we must take
7303 * the increased cdclk requirement into account when
7304 * calculating the new cdclk.
7306 * Should measure whether using a lower cdclk w/o IPS
7308 if (IS_BROADWELL(dev_priv) &&
7309 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
7315 static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
7317 struct drm_i915_private *dev_priv =
7318 to_i915(crtc_state->base.crtc->dev);
7319 struct intel_atomic_state *intel_state =
7320 to_intel_atomic_state(crtc_state->base.state);
7322 if (!hsw_crtc_state_ips_capable(crtc_state))
7326 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
7327 * enabled and disabled dynamically based on package C states,
7328 * user space can't make reliable use of the CRCs, so let's just
7329 * completely disable it.
7331 if (crtc_state->crc_enabled)
7334 /* IPS should be fine as long as at least one plane is enabled. */
7335 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
7338 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
7339 if (IS_BROADWELL(dev_priv) &&
7340 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
7346 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
7348 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7350 /* GDG double wide on either pipe, otherwise pipe A only */
7351 return INTEL_GEN(dev_priv) < 4 &&
7352 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
7355 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
7359 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
7362 * We only use IF-ID interlacing. If we ever use
7363 * PF-ID we'll need to adjust the pixel_rate here.
7366 if (pipe_config->pch_pfit.enabled) {
7367 u64 pipe_w, pipe_h, pfit_w, pfit_h;
7368 u32 pfit_size = pipe_config->pch_pfit.size;
7370 pipe_w = pipe_config->pipe_src_w;
7371 pipe_h = pipe_config->pipe_src_h;
7373 pfit_w = (pfit_size >> 16) & 0xFFFF;
7374 pfit_h = pfit_size & 0xFFFF;
7375 if (pipe_w < pfit_w)
7377 if (pipe_h < pfit_h)
7380 if (WARN_ON(!pfit_w || !pfit_h))
7383 pixel_rate = div_u64(mul_u32_u32(pixel_rate, pipe_w * pipe_h),
7390 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
7392 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
7394 if (HAS_GMCH(dev_priv))
7395 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
7396 crtc_state->pixel_rate =
7397 crtc_state->base.adjusted_mode.crtc_clock;
7399 crtc_state->pixel_rate =
7400 ilk_pipe_pixel_rate(crtc_state);
7403 static int intel_crtc_compute_config(struct intel_crtc *crtc,
7404 struct intel_crtc_state *pipe_config)
7406 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7407 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
7408 int clock_limit = dev_priv->max_dotclk_freq;
7410 if (INTEL_GEN(dev_priv) < 4) {
7411 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
7414 * Enable double wide mode when the dot clock
7415 * is > 90% of the (display) core speed.
7417 if (intel_crtc_supports_double_wide(crtc) &&
7418 adjusted_mode->crtc_clock > clock_limit) {
7419 clock_limit = dev_priv->max_dotclk_freq;
7420 pipe_config->double_wide = true;
7424 if (adjusted_mode->crtc_clock > clock_limit) {
7425 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
7426 adjusted_mode->crtc_clock, clock_limit,
7427 yesno(pipe_config->double_wide));
7431 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
7432 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
7433 pipe_config->base.ctm) {
7435 * There is only one pipe CSC unit per pipe, and we need that
7436 * for output conversion from RGB->YCBCR. So if CTM is already
7437 * applied we can't support YCBCR420 output.
7439 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
7444 * Pipe horizontal size must be even in:
7446 * - LVDS dual channel mode
7447 * - Double wide pipe
7449 if (pipe_config->pipe_src_w & 1) {
7450 if (pipe_config->double_wide) {
7451 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
7455 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
7456 intel_is_dual_link_lvds(dev_priv)) {
7457 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
7462 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
7463 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
7465 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
7466 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
7469 intel_crtc_compute_pixel_rate(pipe_config);
7471 if (pipe_config->has_pch_encoder)
7472 return ironlake_fdi_compute_config(crtc, pipe_config);
7478 intel_reduce_m_n_ratio(u32 *num, u32 *den)
7480 while (*num > DATA_LINK_M_N_MASK ||
7481 *den > DATA_LINK_M_N_MASK) {
7487 static void compute_m_n(unsigned int m, unsigned int n,
7488 u32 *ret_m, u32 *ret_n,
7492 * Several DP dongles in particular seem to be fussy about
7493 * too large link M/N values. Give N value as 0x8000 that
7494 * should be acceptable by specific devices. 0x8000 is the
7495 * specified fixed N value for asynchronous clock mode,
7496 * which the devices expect also in synchronous clock mode.
7501 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
7503 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
7504 intel_reduce_m_n_ratio(ret_m, ret_n);
7508 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
7509 int pixel_clock, int link_clock,
7510 struct intel_link_m_n *m_n,
7515 compute_m_n(bits_per_pixel * pixel_clock,
7516 link_clock * nlanes * 8,
7517 &m_n->gmch_m, &m_n->gmch_n,
7520 compute_m_n(pixel_clock, link_clock,
7521 &m_n->link_m, &m_n->link_n,
7525 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
7527 if (i915_modparams.panel_use_ssc >= 0)
7528 return i915_modparams.panel_use_ssc != 0;
7529 return dev_priv->vbt.lvds_use_ssc
7530 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
7533 static u32 pnv_dpll_compute_fp(struct dpll *dpll)
7535 return (1 << dpll->n) << 16 | dpll->m2;
7538 static u32 i9xx_dpll_compute_fp(struct dpll *dpll)
7540 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
7543 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
7544 struct intel_crtc_state *crtc_state,
7545 struct dpll *reduced_clock)
7547 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7550 if (IS_PINEVIEW(dev_priv)) {
7551 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
7553 fp2 = pnv_dpll_compute_fp(reduced_clock);
7555 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
7557 fp2 = i9xx_dpll_compute_fp(reduced_clock);
7560 crtc_state->dpll_hw_state.fp0 = fp;
7562 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7564 crtc_state->dpll_hw_state.fp1 = fp2;
7566 crtc_state->dpll_hw_state.fp1 = fp;
7570 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
7576 * PLLB opamp always calibrates to max value of 0x3f, force enable it
7577 * and set it to a reasonable value instead.
7579 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7580 reg_val &= 0xffffff00;
7581 reg_val |= 0x00000030;
7582 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7584 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7585 reg_val &= 0x00ffffff;
7586 reg_val |= 0x8c000000;
7587 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7589 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7590 reg_val &= 0xffffff00;
7591 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7593 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7594 reg_val &= 0x00ffffff;
7595 reg_val |= 0xb0000000;
7596 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7599 static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7600 const struct intel_link_m_n *m_n)
7602 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7603 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7604 enum pipe pipe = crtc->pipe;
7606 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7607 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
7608 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
7609 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
7612 static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
7613 enum transcoder transcoder)
7615 if (IS_HASWELL(dev_priv))
7616 return transcoder == TRANSCODER_EDP;
7619 * Strictly speaking some registers are available before
7620 * gen7, but we only support DRRS on gen7+
7622 return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv);
7625 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7626 const struct intel_link_m_n *m_n,
7627 const struct intel_link_m_n *m2_n2)
7629 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7630 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7631 enum pipe pipe = crtc->pipe;
7632 enum transcoder transcoder = crtc_state->cpu_transcoder;
7634 if (INTEL_GEN(dev_priv) >= 5) {
7635 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
7636 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
7637 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
7638 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
7640 * M2_N2 registers are set only if DRRS is supported
7641 * (to make sure the registers are not unnecessarily accessed).
7643 if (m2_n2 && crtc_state->has_drrs &&
7644 transcoder_has_m2_n2(dev_priv, transcoder)) {
7645 I915_WRITE(PIPE_DATA_M2(transcoder),
7646 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
7647 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
7648 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
7649 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
7652 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7653 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
7654 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
7655 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
7659 void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n)
7661 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
7664 dp_m_n = &crtc_state->dp_m_n;
7665 dp_m2_n2 = &crtc_state->dp_m2_n2;
7666 } else if (m_n == M2_N2) {
7669 * M2_N2 registers are not supported. Hence m2_n2 divider value
7670 * needs to be programmed into M1_N1.
7672 dp_m_n = &crtc_state->dp_m2_n2;
7674 DRM_ERROR("Unsupported divider value\n");
7678 if (crtc_state->has_pch_encoder)
7679 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
7681 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
7684 static void vlv_compute_dpll(struct intel_crtc *crtc,
7685 struct intel_crtc_state *pipe_config)
7687 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
7688 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
7689 if (crtc->pipe != PIPE_A)
7690 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7692 /* DPLL not used with DSI, but still need the rest set up */
7693 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
7694 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
7695 DPLL_EXT_BUFFER_ENABLE_VLV;
7697 pipe_config->dpll_hw_state.dpll_md =
7698 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7701 static void chv_compute_dpll(struct intel_crtc *crtc,
7702 struct intel_crtc_state *pipe_config)
7704 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
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;
7713 pipe_config->dpll_hw_state.dpll_md =
7714 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7717 static void vlv_prepare_pll(struct intel_crtc *crtc,
7718 const struct intel_crtc_state *pipe_config)
7720 struct drm_device *dev = crtc->base.dev;
7721 struct drm_i915_private *dev_priv = to_i915(dev);
7722 enum pipe pipe = crtc->pipe;
7724 u32 bestn, bestm1, bestm2, bestp1, bestp2;
7725 u32 coreclk, reg_val;
7728 I915_WRITE(DPLL(pipe),
7729 pipe_config->dpll_hw_state.dpll &
7730 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
7732 /* No need to actually set up the DPLL with DSI */
7733 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7736 vlv_dpio_get(dev_priv);
7738 bestn = pipe_config->dpll.n;
7739 bestm1 = pipe_config->dpll.m1;
7740 bestm2 = pipe_config->dpll.m2;
7741 bestp1 = pipe_config->dpll.p1;
7742 bestp2 = pipe_config->dpll.p2;
7744 /* See eDP HDMI DPIO driver vbios notes doc */
7746 /* PLL B needs special handling */
7748 vlv_pllb_recal_opamp(dev_priv, pipe);
7750 /* Set up Tx target for periodic Rcomp update */
7751 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
7753 /* Disable target IRef on PLL */
7754 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
7755 reg_val &= 0x00ffffff;
7756 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
7758 /* Disable fast lock */
7759 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
7761 /* Set idtafcrecal before PLL is enabled */
7762 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
7763 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
7764 mdiv |= ((bestn << DPIO_N_SHIFT));
7765 mdiv |= (1 << DPIO_K_SHIFT);
7768 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7769 * but we don't support that).
7770 * Note: don't use the DAC post divider as it seems unstable.
7772 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
7773 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7775 mdiv |= DPIO_ENABLE_CALIBRATION;
7776 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7778 /* Set HBR and RBR LPF coefficients */
7779 if (pipe_config->port_clock == 162000 ||
7780 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
7781 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
7782 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7785 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7788 if (intel_crtc_has_dp_encoder(pipe_config)) {
7789 /* Use SSC source */
7791 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7794 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7796 } else { /* HDMI or VGA */
7797 /* Use bend source */
7799 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7802 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7806 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
7807 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
7808 if (intel_crtc_has_dp_encoder(pipe_config))
7809 coreclk |= 0x01000000;
7810 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
7812 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
7814 vlv_dpio_put(dev_priv);
7817 static void chv_prepare_pll(struct intel_crtc *crtc,
7818 const struct intel_crtc_state *pipe_config)
7820 struct drm_device *dev = crtc->base.dev;
7821 struct drm_i915_private *dev_priv = to_i915(dev);
7822 enum pipe pipe = crtc->pipe;
7823 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7824 u32 loopfilter, tribuf_calcntr;
7825 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
7829 /* Enable Refclk and SSC */
7830 I915_WRITE(DPLL(pipe),
7831 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
7833 /* No need to actually set up the DPLL with DSI */
7834 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7837 bestn = pipe_config->dpll.n;
7838 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7839 bestm1 = pipe_config->dpll.m1;
7840 bestm2 = pipe_config->dpll.m2 >> 22;
7841 bestp1 = pipe_config->dpll.p1;
7842 bestp2 = pipe_config->dpll.p2;
7843 vco = pipe_config->dpll.vco;
7847 vlv_dpio_get(dev_priv);
7849 /* p1 and p2 divider */
7850 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7851 5 << DPIO_CHV_S1_DIV_SHIFT |
7852 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
7853 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
7854 1 << DPIO_CHV_K_DIV_SHIFT);
7856 /* Feedback post-divider - m2 */
7857 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7859 /* Feedback refclk divider - n and m1 */
7860 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7861 DPIO_CHV_M1_DIV_BY_2 |
7862 1 << DPIO_CHV_N_DIV_SHIFT);
7864 /* M2 fraction division */
7865 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
7867 /* M2 fraction division enable */
7868 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7869 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7870 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7872 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7873 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
7875 /* Program digital lock detect threshold */
7876 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7877 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7878 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7879 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7881 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7882 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7885 if (vco == 5400000) {
7886 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7887 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7888 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7889 tribuf_calcntr = 0x9;
7890 } else if (vco <= 6200000) {
7891 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7892 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7893 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7894 tribuf_calcntr = 0x9;
7895 } else if (vco <= 6480000) {
7896 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7897 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7898 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7899 tribuf_calcntr = 0x8;
7901 /* Not supported. Apply the same limits as in the max case */
7902 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7903 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7904 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7907 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7909 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
7910 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7911 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7912 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7915 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7916 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7919 vlv_dpio_put(dev_priv);
7923 * vlv_force_pll_on - forcibly enable just the PLL
7924 * @dev_priv: i915 private structure
7925 * @pipe: pipe PLL to enable
7926 * @dpll: PLL configuration
7928 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7929 * in cases where we need the PLL enabled even when @pipe is not going to
7932 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
7933 const struct dpll *dpll)
7935 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
7936 struct intel_crtc_state *pipe_config;
7938 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7942 pipe_config->base.crtc = &crtc->base;
7943 pipe_config->pixel_multiplier = 1;
7944 pipe_config->dpll = *dpll;
7946 if (IS_CHERRYVIEW(dev_priv)) {
7947 chv_compute_dpll(crtc, pipe_config);
7948 chv_prepare_pll(crtc, pipe_config);
7949 chv_enable_pll(crtc, pipe_config);
7951 vlv_compute_dpll(crtc, pipe_config);
7952 vlv_prepare_pll(crtc, pipe_config);
7953 vlv_enable_pll(crtc, pipe_config);
7962 * vlv_force_pll_off - forcibly disable just the PLL
7963 * @dev_priv: i915 private structure
7964 * @pipe: pipe PLL to disable
7966 * Disable the PLL for @pipe. To be used in cases where we need
7967 * the PLL enabled even when @pipe is not going to be enabled.
7969 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
7971 if (IS_CHERRYVIEW(dev_priv))
7972 chv_disable_pll(dev_priv, pipe);
7974 vlv_disable_pll(dev_priv, pipe);
7977 static void i9xx_compute_dpll(struct intel_crtc *crtc,
7978 struct intel_crtc_state *crtc_state,
7979 struct dpll *reduced_clock)
7981 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7983 struct dpll *clock = &crtc_state->dpll;
7985 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7987 dpll = DPLL_VGA_MODE_DIS;
7989 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
7990 dpll |= DPLLB_MODE_LVDS;
7992 dpll |= DPLLB_MODE_DAC_SERIAL;
7994 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7995 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7996 dpll |= (crtc_state->pixel_multiplier - 1)
7997 << SDVO_MULTIPLIER_SHIFT_HIRES;
8000 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8001 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8002 dpll |= DPLL_SDVO_HIGH_SPEED;
8004 if (intel_crtc_has_dp_encoder(crtc_state))
8005 dpll |= DPLL_SDVO_HIGH_SPEED;
8007 /* compute bitmask from p1 value */
8008 if (IS_PINEVIEW(dev_priv))
8009 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
8011 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8012 if (IS_G4X(dev_priv) && reduced_clock)
8013 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8015 switch (clock->p2) {
8017 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8020 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8023 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8026 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8029 if (INTEL_GEN(dev_priv) >= 4)
8030 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
8032 if (crtc_state->sdvo_tv_clock)
8033 dpll |= PLL_REF_INPUT_TVCLKINBC;
8034 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8035 intel_panel_use_ssc(dev_priv))
8036 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8038 dpll |= PLL_REF_INPUT_DREFCLK;
8040 dpll |= DPLL_VCO_ENABLE;
8041 crtc_state->dpll_hw_state.dpll = dpll;
8043 if (INTEL_GEN(dev_priv) >= 4) {
8044 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
8045 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8046 crtc_state->dpll_hw_state.dpll_md = dpll_md;
8050 static void i8xx_compute_dpll(struct intel_crtc *crtc,
8051 struct intel_crtc_state *crtc_state,
8052 struct dpll *reduced_clock)
8054 struct drm_device *dev = crtc->base.dev;
8055 struct drm_i915_private *dev_priv = to_i915(dev);
8057 struct dpll *clock = &crtc_state->dpll;
8059 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
8061 dpll = DPLL_VGA_MODE_DIS;
8063 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8064 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8067 dpll |= PLL_P1_DIVIDE_BY_TWO;
8069 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8071 dpll |= PLL_P2_DIVIDE_BY_4;
8076 * "[Almador Errata}: For the correct operation of the muxed DVO pins
8077 * (GDEVSELB/I2Cdata, GIRDBY/I2CClk) and (GFRAMEB/DVI_Data,
8078 * GTRDYB/DVI_Clk): Bit 31 (DPLL VCO Enable) and Bit 30 (2X Clock
8079 * Enable) must be set to “1” in both the DPLL A Control Register
8080 * (06014h-06017h) and DPLL B Control Register (06018h-0601Bh)."
8082 * For simplicity We simply keep both bits always enabled in
8083 * both DPLLS. The spec says we should disable the DVO 2X clock
8084 * when not needed, but this seems to work fine in practice.
8086 if (IS_I830(dev_priv) ||
8087 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
8088 dpll |= DPLL_DVO_2X_MODE;
8090 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8091 intel_panel_use_ssc(dev_priv))
8092 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8094 dpll |= PLL_REF_INPUT_DREFCLK;
8096 dpll |= DPLL_VCO_ENABLE;
8097 crtc_state->dpll_hw_state.dpll = dpll;
8100 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
8102 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8103 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8104 enum pipe pipe = crtc->pipe;
8105 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8106 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
8107 u32 crtc_vtotal, crtc_vblank_end;
8110 /* We need to be careful not to changed the adjusted mode, for otherwise
8111 * the hw state checker will get angry at the mismatch. */
8112 crtc_vtotal = adjusted_mode->crtc_vtotal;
8113 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
8115 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
8116 /* the chip adds 2 halflines automatically */
8118 crtc_vblank_end -= 1;
8120 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8121 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
8123 vsyncshift = adjusted_mode->crtc_hsync_start -
8124 adjusted_mode->crtc_htotal / 2;
8126 vsyncshift += adjusted_mode->crtc_htotal;
8129 if (INTEL_GEN(dev_priv) > 3)
8130 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
8132 I915_WRITE(HTOTAL(cpu_transcoder),
8133 (adjusted_mode->crtc_hdisplay - 1) |
8134 ((adjusted_mode->crtc_htotal - 1) << 16));
8135 I915_WRITE(HBLANK(cpu_transcoder),
8136 (adjusted_mode->crtc_hblank_start - 1) |
8137 ((adjusted_mode->crtc_hblank_end - 1) << 16));
8138 I915_WRITE(HSYNC(cpu_transcoder),
8139 (adjusted_mode->crtc_hsync_start - 1) |
8140 ((adjusted_mode->crtc_hsync_end - 1) << 16));
8142 I915_WRITE(VTOTAL(cpu_transcoder),
8143 (adjusted_mode->crtc_vdisplay - 1) |
8144 ((crtc_vtotal - 1) << 16));
8145 I915_WRITE(VBLANK(cpu_transcoder),
8146 (adjusted_mode->crtc_vblank_start - 1) |
8147 ((crtc_vblank_end - 1) << 16));
8148 I915_WRITE(VSYNC(cpu_transcoder),
8149 (adjusted_mode->crtc_vsync_start - 1) |
8150 ((adjusted_mode->crtc_vsync_end - 1) << 16));
8152 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
8153 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
8154 * documented on the DDI_FUNC_CTL register description, EDP Input Select
8156 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
8157 (pipe == PIPE_B || pipe == PIPE_C))
8158 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
8162 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
8164 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8165 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8166 enum pipe pipe = crtc->pipe;
8168 /* pipesrc controls the size that is scaled from, which should
8169 * always be the user's requested size.
8171 I915_WRITE(PIPESRC(pipe),
8172 ((crtc_state->pipe_src_w - 1) << 16) |
8173 (crtc_state->pipe_src_h - 1));
8176 static void intel_get_pipe_timings(struct intel_crtc *crtc,
8177 struct intel_crtc_state *pipe_config)
8179 struct drm_device *dev = crtc->base.dev;
8180 struct drm_i915_private *dev_priv = to_i915(dev);
8181 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
8184 tmp = I915_READ(HTOTAL(cpu_transcoder));
8185 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
8186 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
8188 if (!transcoder_is_dsi(cpu_transcoder)) {
8189 tmp = I915_READ(HBLANK(cpu_transcoder));
8190 pipe_config->base.adjusted_mode.crtc_hblank_start =
8192 pipe_config->base.adjusted_mode.crtc_hblank_end =
8193 ((tmp >> 16) & 0xffff) + 1;
8195 tmp = I915_READ(HSYNC(cpu_transcoder));
8196 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
8197 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
8199 tmp = I915_READ(VTOTAL(cpu_transcoder));
8200 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
8201 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
8203 if (!transcoder_is_dsi(cpu_transcoder)) {
8204 tmp = I915_READ(VBLANK(cpu_transcoder));
8205 pipe_config->base.adjusted_mode.crtc_vblank_start =
8207 pipe_config->base.adjusted_mode.crtc_vblank_end =
8208 ((tmp >> 16) & 0xffff) + 1;
8210 tmp = I915_READ(VSYNC(cpu_transcoder));
8211 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
8212 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
8214 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
8215 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
8216 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
8217 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
8221 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
8222 struct intel_crtc_state *pipe_config)
8224 struct drm_device *dev = crtc->base.dev;
8225 struct drm_i915_private *dev_priv = to_i915(dev);
8228 tmp = I915_READ(PIPESRC(crtc->pipe));
8229 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
8230 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
8232 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
8233 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
8236 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
8237 struct intel_crtc_state *pipe_config)
8239 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
8240 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
8241 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
8242 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
8244 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
8245 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
8246 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
8247 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
8249 mode->flags = pipe_config->base.adjusted_mode.flags;
8250 mode->type = DRM_MODE_TYPE_DRIVER;
8252 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
8254 mode->hsync = drm_mode_hsync(mode);
8255 mode->vrefresh = drm_mode_vrefresh(mode);
8256 drm_mode_set_name(mode);
8259 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
8261 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8262 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8267 /* we keep both pipes enabled on 830 */
8268 if (IS_I830(dev_priv))
8269 pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
8271 if (crtc_state->double_wide)
8272 pipeconf |= PIPECONF_DOUBLE_WIDE;
8274 /* only g4x and later have fancy bpc/dither controls */
8275 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8276 IS_CHERRYVIEW(dev_priv)) {
8277 /* Bspec claims that we can't use dithering for 30bpp pipes. */
8278 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
8279 pipeconf |= PIPECONF_DITHER_EN |
8280 PIPECONF_DITHER_TYPE_SP;
8282 switch (crtc_state->pipe_bpp) {
8284 pipeconf |= PIPECONF_6BPC;
8287 pipeconf |= PIPECONF_8BPC;
8290 pipeconf |= PIPECONF_10BPC;
8293 /* Case prevented by intel_choose_pipe_bpp_dither. */
8298 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
8299 if (INTEL_GEN(dev_priv) < 4 ||
8300 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8301 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
8303 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
8305 pipeconf |= PIPECONF_PROGRESSIVE;
8308 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
8309 crtc_state->limited_color_range)
8310 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
8312 pipeconf |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
8314 I915_WRITE(PIPECONF(crtc->pipe), pipeconf);
8315 POSTING_READ(PIPECONF(crtc->pipe));
8318 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
8319 struct intel_crtc_state *crtc_state)
8321 struct drm_device *dev = crtc->base.dev;
8322 struct drm_i915_private *dev_priv = to_i915(dev);
8323 const struct intel_limit *limit;
8326 memset(&crtc_state->dpll_hw_state, 0,
8327 sizeof(crtc_state->dpll_hw_state));
8329 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8330 if (intel_panel_use_ssc(dev_priv)) {
8331 refclk = dev_priv->vbt.lvds_ssc_freq;
8332 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8335 limit = &intel_limits_i8xx_lvds;
8336 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
8337 limit = &intel_limits_i8xx_dvo;
8339 limit = &intel_limits_i8xx_dac;
8342 if (!crtc_state->clock_set &&
8343 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8344 refclk, NULL, &crtc_state->dpll)) {
8345 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8349 i8xx_compute_dpll(crtc, crtc_state, NULL);
8354 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
8355 struct intel_crtc_state *crtc_state)
8357 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8358 const struct intel_limit *limit;
8361 memset(&crtc_state->dpll_hw_state, 0,
8362 sizeof(crtc_state->dpll_hw_state));
8364 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8365 if (intel_panel_use_ssc(dev_priv)) {
8366 refclk = dev_priv->vbt.lvds_ssc_freq;
8367 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8370 if (intel_is_dual_link_lvds(dev_priv))
8371 limit = &intel_limits_g4x_dual_channel_lvds;
8373 limit = &intel_limits_g4x_single_channel_lvds;
8374 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
8375 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
8376 limit = &intel_limits_g4x_hdmi;
8377 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
8378 limit = &intel_limits_g4x_sdvo;
8380 /* The option is for other outputs */
8381 limit = &intel_limits_i9xx_sdvo;
8384 if (!crtc_state->clock_set &&
8385 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8386 refclk, NULL, &crtc_state->dpll)) {
8387 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8391 i9xx_compute_dpll(crtc, crtc_state, NULL);
8396 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
8397 struct intel_crtc_state *crtc_state)
8399 struct drm_device *dev = crtc->base.dev;
8400 struct drm_i915_private *dev_priv = to_i915(dev);
8401 const struct intel_limit *limit;
8404 memset(&crtc_state->dpll_hw_state, 0,
8405 sizeof(crtc_state->dpll_hw_state));
8407 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8408 if (intel_panel_use_ssc(dev_priv)) {
8409 refclk = dev_priv->vbt.lvds_ssc_freq;
8410 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8413 limit = &intel_limits_pineview_lvds;
8415 limit = &intel_limits_pineview_sdvo;
8418 if (!crtc_state->clock_set &&
8419 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8420 refclk, NULL, &crtc_state->dpll)) {
8421 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8425 i9xx_compute_dpll(crtc, crtc_state, NULL);
8430 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
8431 struct intel_crtc_state *crtc_state)
8433 struct drm_device *dev = crtc->base.dev;
8434 struct drm_i915_private *dev_priv = to_i915(dev);
8435 const struct intel_limit *limit;
8438 memset(&crtc_state->dpll_hw_state, 0,
8439 sizeof(crtc_state->dpll_hw_state));
8441 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8442 if (intel_panel_use_ssc(dev_priv)) {
8443 refclk = dev_priv->vbt.lvds_ssc_freq;
8444 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8447 limit = &intel_limits_i9xx_lvds;
8449 limit = &intel_limits_i9xx_sdvo;
8452 if (!crtc_state->clock_set &&
8453 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8454 refclk, NULL, &crtc_state->dpll)) {
8455 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8459 i9xx_compute_dpll(crtc, crtc_state, NULL);
8464 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
8465 struct intel_crtc_state *crtc_state)
8467 int refclk = 100000;
8468 const struct intel_limit *limit = &intel_limits_chv;
8470 memset(&crtc_state->dpll_hw_state, 0,
8471 sizeof(crtc_state->dpll_hw_state));
8473 if (!crtc_state->clock_set &&
8474 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8475 refclk, NULL, &crtc_state->dpll)) {
8476 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8480 chv_compute_dpll(crtc, crtc_state);
8485 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
8486 struct intel_crtc_state *crtc_state)
8488 int refclk = 100000;
8489 const struct intel_limit *limit = &intel_limits_vlv;
8491 memset(&crtc_state->dpll_hw_state, 0,
8492 sizeof(crtc_state->dpll_hw_state));
8494 if (!crtc_state->clock_set &&
8495 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8496 refclk, NULL, &crtc_state->dpll)) {
8497 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8501 vlv_compute_dpll(crtc, crtc_state);
8506 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
8508 if (IS_I830(dev_priv))
8511 return INTEL_GEN(dev_priv) >= 4 ||
8512 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
8515 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
8516 struct intel_crtc_state *pipe_config)
8518 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8521 if (!i9xx_has_pfit(dev_priv))
8524 tmp = I915_READ(PFIT_CONTROL);
8525 if (!(tmp & PFIT_ENABLE))
8528 /* Check whether the pfit is attached to our pipe. */
8529 if (INTEL_GEN(dev_priv) < 4) {
8530 if (crtc->pipe != PIPE_B)
8533 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
8537 pipe_config->gmch_pfit.control = tmp;
8538 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
8541 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
8542 struct intel_crtc_state *pipe_config)
8544 struct drm_device *dev = crtc->base.dev;
8545 struct drm_i915_private *dev_priv = to_i915(dev);
8546 enum pipe pipe = crtc->pipe;
8549 int refclk = 100000;
8551 /* In case of DSI, DPLL will not be used */
8552 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8555 vlv_dpio_get(dev_priv);
8556 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
8557 vlv_dpio_put(dev_priv);
8559 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
8560 clock.m2 = mdiv & DPIO_M2DIV_MASK;
8561 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
8562 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
8563 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
8565 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
8569 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
8570 struct intel_initial_plane_config *plane_config)
8572 struct drm_device *dev = crtc->base.dev;
8573 struct drm_i915_private *dev_priv = to_i915(dev);
8574 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8575 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
8577 u32 val, base, offset;
8578 int fourcc, pixel_format;
8579 unsigned int aligned_height;
8580 struct drm_framebuffer *fb;
8581 struct intel_framebuffer *intel_fb;
8583 if (!plane->get_hw_state(plane, &pipe))
8586 WARN_ON(pipe != crtc->pipe);
8588 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8590 DRM_DEBUG_KMS("failed to alloc fb\n");
8594 fb = &intel_fb->base;
8598 val = I915_READ(DSPCNTR(i9xx_plane));
8600 if (INTEL_GEN(dev_priv) >= 4) {
8601 if (val & DISPPLANE_TILED) {
8602 plane_config->tiling = I915_TILING_X;
8603 fb->modifier = I915_FORMAT_MOD_X_TILED;
8606 if (val & DISPPLANE_ROTATE_180)
8607 plane_config->rotation = DRM_MODE_ROTATE_180;
8610 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
8611 val & DISPPLANE_MIRROR)
8612 plane_config->rotation |= DRM_MODE_REFLECT_X;
8614 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
8615 fourcc = i9xx_format_to_fourcc(pixel_format);
8616 fb->format = drm_format_info(fourcc);
8618 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
8619 offset = I915_READ(DSPOFFSET(i9xx_plane));
8620 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8621 } else if (INTEL_GEN(dev_priv) >= 4) {
8622 if (plane_config->tiling)
8623 offset = I915_READ(DSPTILEOFF(i9xx_plane));
8625 offset = I915_READ(DSPLINOFF(i9xx_plane));
8626 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8628 base = I915_READ(DSPADDR(i9xx_plane));
8630 plane_config->base = base;
8632 val = I915_READ(PIPESRC(pipe));
8633 fb->width = ((val >> 16) & 0xfff) + 1;
8634 fb->height = ((val >> 0) & 0xfff) + 1;
8636 val = I915_READ(DSPSTRIDE(i9xx_plane));
8637 fb->pitches[0] = val & 0xffffffc0;
8639 aligned_height = intel_fb_align_height(fb, 0, fb->height);
8641 plane_config->size = fb->pitches[0] * aligned_height;
8643 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8644 crtc->base.name, plane->base.name, fb->width, fb->height,
8645 fb->format->cpp[0] * 8, base, fb->pitches[0],
8646 plane_config->size);
8648 plane_config->fb = intel_fb;
8651 static void chv_crtc_clock_get(struct intel_crtc *crtc,
8652 struct intel_crtc_state *pipe_config)
8654 struct drm_device *dev = crtc->base.dev;
8655 struct drm_i915_private *dev_priv = to_i915(dev);
8656 enum pipe pipe = crtc->pipe;
8657 enum dpio_channel port = vlv_pipe_to_channel(pipe);
8659 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
8660 int refclk = 100000;
8662 /* In case of DSI, DPLL will not be used */
8663 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8666 vlv_dpio_get(dev_priv);
8667 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
8668 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
8669 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
8670 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
8671 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
8672 vlv_dpio_put(dev_priv);
8674 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
8675 clock.m2 = (pll_dw0 & 0xff) << 22;
8676 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
8677 clock.m2 |= pll_dw2 & 0x3fffff;
8678 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
8679 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
8680 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
8682 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
8685 static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc,
8686 struct intel_crtc_state *pipe_config)
8688 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8689 enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB;
8691 pipe_config->lspcon_downsampling = false;
8693 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
8694 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
8696 if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
8697 bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE;
8698 bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND;
8700 if (ycbcr420_enabled) {
8701 /* We support 4:2:0 in full blend mode only */
8703 output = INTEL_OUTPUT_FORMAT_INVALID;
8704 else if (!(IS_GEMINILAKE(dev_priv) ||
8705 INTEL_GEN(dev_priv) >= 10))
8706 output = INTEL_OUTPUT_FORMAT_INVALID;
8708 output = INTEL_OUTPUT_FORMAT_YCBCR420;
8711 * Currently there is no interface defined to
8712 * check user preference between RGB/YCBCR444
8713 * or YCBCR420. So the only possible case for
8714 * YCBCR444 usage is driving YCBCR420 output
8715 * with LSPCON, when pipe is configured for
8716 * YCBCR444 output and LSPCON takes care of
8719 pipe_config->lspcon_downsampling = true;
8720 output = INTEL_OUTPUT_FORMAT_YCBCR444;
8725 pipe_config->output_format = output;
8728 static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state)
8730 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8731 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8732 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8733 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
8736 tmp = I915_READ(DSPCNTR(i9xx_plane));
8738 if (tmp & DISPPLANE_GAMMA_ENABLE)
8739 crtc_state->gamma_enable = true;
8741 if (!HAS_GMCH(dev_priv) &&
8742 tmp & DISPPLANE_PIPE_CSC_ENABLE)
8743 crtc_state->csc_enable = true;
8746 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
8747 struct intel_crtc_state *pipe_config)
8749 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8750 enum intel_display_power_domain power_domain;
8751 intel_wakeref_t wakeref;
8755 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
8756 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
8760 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
8761 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
8762 pipe_config->shared_dpll = NULL;
8766 tmp = I915_READ(PIPECONF(crtc->pipe));
8767 if (!(tmp & PIPECONF_ENABLE))
8770 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8771 IS_CHERRYVIEW(dev_priv)) {
8772 switch (tmp & PIPECONF_BPC_MASK) {
8774 pipe_config->pipe_bpp = 18;
8777 pipe_config->pipe_bpp = 24;
8779 case PIPECONF_10BPC:
8780 pipe_config->pipe_bpp = 30;
8787 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
8788 (tmp & PIPECONF_COLOR_RANGE_SELECT))
8789 pipe_config->limited_color_range = true;
8791 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_I9XX) >>
8792 PIPECONF_GAMMA_MODE_SHIFT;
8794 if (IS_CHERRYVIEW(dev_priv))
8795 pipe_config->cgm_mode = I915_READ(CGM_PIPE_MODE(crtc->pipe));
8797 i9xx_get_pipe_color_config(pipe_config);
8798 intel_color_get_config(pipe_config);
8800 if (INTEL_GEN(dev_priv) < 4)
8801 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
8803 intel_get_pipe_timings(crtc, pipe_config);
8804 intel_get_pipe_src_size(crtc, pipe_config);
8806 i9xx_get_pfit_config(crtc, pipe_config);
8808 if (INTEL_GEN(dev_priv) >= 4) {
8809 /* No way to read it out on pipes B and C */
8810 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
8811 tmp = dev_priv->chv_dpll_md[crtc->pipe];
8813 tmp = I915_READ(DPLL_MD(crtc->pipe));
8814 pipe_config->pixel_multiplier =
8815 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
8816 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
8817 pipe_config->dpll_hw_state.dpll_md = tmp;
8818 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
8819 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
8820 tmp = I915_READ(DPLL(crtc->pipe));
8821 pipe_config->pixel_multiplier =
8822 ((tmp & SDVO_MULTIPLIER_MASK)
8823 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
8825 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8826 * port and will be fixed up in the encoder->get_config
8828 pipe_config->pixel_multiplier = 1;
8830 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
8831 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
8832 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
8833 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
8835 /* Mask out read-only status bits. */
8836 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
8837 DPLL_PORTC_READY_MASK |
8838 DPLL_PORTB_READY_MASK);
8841 if (IS_CHERRYVIEW(dev_priv))
8842 chv_crtc_clock_get(crtc, pipe_config);
8843 else if (IS_VALLEYVIEW(dev_priv))
8844 vlv_crtc_clock_get(crtc, pipe_config);
8846 i9xx_crtc_clock_get(crtc, pipe_config);
8849 * Normally the dotclock is filled in by the encoder .get_config()
8850 * but in case the pipe is enabled w/o any ports we need a sane
8853 pipe_config->base.adjusted_mode.crtc_clock =
8854 pipe_config->port_clock / pipe_config->pixel_multiplier;
8859 intel_display_power_put(dev_priv, power_domain, wakeref);
8864 static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
8866 struct intel_encoder *encoder;
8869 bool has_lvds = false;
8870 bool has_cpu_edp = false;
8871 bool has_panel = false;
8872 bool has_ck505 = false;
8873 bool can_ssc = false;
8874 bool using_ssc_source = false;
8876 /* We need to take the global config into account */
8877 for_each_intel_encoder(&dev_priv->drm, encoder) {
8878 switch (encoder->type) {
8879 case INTEL_OUTPUT_LVDS:
8883 case INTEL_OUTPUT_EDP:
8885 if (encoder->port == PORT_A)
8893 if (HAS_PCH_IBX(dev_priv)) {
8894 has_ck505 = dev_priv->vbt.display_clock_mode;
8895 can_ssc = has_ck505;
8901 /* Check if any DPLLs are using the SSC source */
8902 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
8903 u32 temp = I915_READ(PCH_DPLL(i));
8905 if (!(temp & DPLL_VCO_ENABLE))
8908 if ((temp & PLL_REF_INPUT_MASK) ==
8909 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
8910 using_ssc_source = true;
8915 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
8916 has_panel, has_lvds, has_ck505, using_ssc_source);
8918 /* Ironlake: try to setup display ref clock before DPLL
8919 * enabling. This is only under driver's control after
8920 * PCH B stepping, previous chipset stepping should be
8921 * ignoring this setting.
8923 val = I915_READ(PCH_DREF_CONTROL);
8925 /* As we must carefully and slowly disable/enable each source in turn,
8926 * compute the final state we want first and check if we need to
8927 * make any changes at all.
8930 final &= ~DREF_NONSPREAD_SOURCE_MASK;
8932 final |= DREF_NONSPREAD_CK505_ENABLE;
8934 final |= DREF_NONSPREAD_SOURCE_ENABLE;
8936 final &= ~DREF_SSC_SOURCE_MASK;
8937 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8938 final &= ~DREF_SSC1_ENABLE;
8941 final |= DREF_SSC_SOURCE_ENABLE;
8943 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8944 final |= DREF_SSC1_ENABLE;
8947 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8948 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8950 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8952 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8953 } else if (using_ssc_source) {
8954 final |= DREF_SSC_SOURCE_ENABLE;
8955 final |= DREF_SSC1_ENABLE;
8961 /* Always enable nonspread source */
8962 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8965 val |= DREF_NONSPREAD_CK505_ENABLE;
8967 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8970 val &= ~DREF_SSC_SOURCE_MASK;
8971 val |= DREF_SSC_SOURCE_ENABLE;
8973 /* SSC must be turned on before enabling the CPU output */
8974 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8975 DRM_DEBUG_KMS("Using SSC on panel\n");
8976 val |= DREF_SSC1_ENABLE;
8978 val &= ~DREF_SSC1_ENABLE;
8980 /* Get SSC going before enabling the outputs */
8981 I915_WRITE(PCH_DREF_CONTROL, val);
8982 POSTING_READ(PCH_DREF_CONTROL);
8985 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8987 /* Enable CPU source on CPU attached eDP */
8989 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8990 DRM_DEBUG_KMS("Using SSC on eDP\n");
8991 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8993 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8995 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8997 I915_WRITE(PCH_DREF_CONTROL, val);
8998 POSTING_READ(PCH_DREF_CONTROL);
9001 DRM_DEBUG_KMS("Disabling CPU source output\n");
9003 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9005 /* Turn off CPU output */
9006 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9008 I915_WRITE(PCH_DREF_CONTROL, val);
9009 POSTING_READ(PCH_DREF_CONTROL);
9012 if (!using_ssc_source) {
9013 DRM_DEBUG_KMS("Disabling SSC source\n");
9015 /* Turn off the SSC source */
9016 val &= ~DREF_SSC_SOURCE_MASK;
9017 val |= DREF_SSC_SOURCE_DISABLE;
9020 val &= ~DREF_SSC1_ENABLE;
9022 I915_WRITE(PCH_DREF_CONTROL, val);
9023 POSTING_READ(PCH_DREF_CONTROL);
9028 BUG_ON(val != final);
9031 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
9035 tmp = I915_READ(SOUTH_CHICKEN2);
9036 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
9037 I915_WRITE(SOUTH_CHICKEN2, tmp);
9039 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
9040 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
9041 DRM_ERROR("FDI mPHY reset assert timeout\n");
9043 tmp = I915_READ(SOUTH_CHICKEN2);
9044 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
9045 I915_WRITE(SOUTH_CHICKEN2, tmp);
9047 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
9048 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
9049 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
9052 /* WaMPhyProgramming:hsw */
9053 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
9057 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
9058 tmp &= ~(0xFF << 24);
9059 tmp |= (0x12 << 24);
9060 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
9062 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
9064 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
9066 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
9068 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
9070 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
9071 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9072 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
9074 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
9075 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9076 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
9078 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
9081 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
9083 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
9086 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
9088 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
9091 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
9093 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
9096 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
9098 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
9099 tmp &= ~(0xFF << 16);
9100 tmp |= (0x1C << 16);
9101 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
9103 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
9104 tmp &= ~(0xFF << 16);
9105 tmp |= (0x1C << 16);
9106 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
9108 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
9110 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
9112 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
9114 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
9116 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
9117 tmp &= ~(0xF << 28);
9119 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
9121 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
9122 tmp &= ~(0xF << 28);
9124 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
9127 /* Implements 3 different sequences from BSpec chapter "Display iCLK
9128 * Programming" based on the parameters passed:
9129 * - Sequence to enable CLKOUT_DP
9130 * - Sequence to enable CLKOUT_DP without spread
9131 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
9133 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
9134 bool with_spread, bool with_fdi)
9138 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
9140 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
9141 with_fdi, "LP PCH doesn't have FDI\n"))
9144 mutex_lock(&dev_priv->sb_lock);
9146 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9147 tmp &= ~SBI_SSCCTL_DISABLE;
9148 tmp |= SBI_SSCCTL_PATHALT;
9149 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9154 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9155 tmp &= ~SBI_SSCCTL_PATHALT;
9156 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9159 lpt_reset_fdi_mphy(dev_priv);
9160 lpt_program_fdi_mphy(dev_priv);
9164 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9165 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9166 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9167 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9169 mutex_unlock(&dev_priv->sb_lock);
9172 /* Sequence to disable CLKOUT_DP */
9173 void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
9177 mutex_lock(&dev_priv->sb_lock);
9179 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9180 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9181 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9182 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9184 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9185 if (!(tmp & SBI_SSCCTL_DISABLE)) {
9186 if (!(tmp & SBI_SSCCTL_PATHALT)) {
9187 tmp |= SBI_SSCCTL_PATHALT;
9188 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9191 tmp |= SBI_SSCCTL_DISABLE;
9192 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9195 mutex_unlock(&dev_priv->sb_lock);
9198 #define BEND_IDX(steps) ((50 + (steps)) / 5)
9200 static const u16 sscdivintphase[] = {
9201 [BEND_IDX( 50)] = 0x3B23,
9202 [BEND_IDX( 45)] = 0x3B23,
9203 [BEND_IDX( 40)] = 0x3C23,
9204 [BEND_IDX( 35)] = 0x3C23,
9205 [BEND_IDX( 30)] = 0x3D23,
9206 [BEND_IDX( 25)] = 0x3D23,
9207 [BEND_IDX( 20)] = 0x3E23,
9208 [BEND_IDX( 15)] = 0x3E23,
9209 [BEND_IDX( 10)] = 0x3F23,
9210 [BEND_IDX( 5)] = 0x3F23,
9211 [BEND_IDX( 0)] = 0x0025,
9212 [BEND_IDX( -5)] = 0x0025,
9213 [BEND_IDX(-10)] = 0x0125,
9214 [BEND_IDX(-15)] = 0x0125,
9215 [BEND_IDX(-20)] = 0x0225,
9216 [BEND_IDX(-25)] = 0x0225,
9217 [BEND_IDX(-30)] = 0x0325,
9218 [BEND_IDX(-35)] = 0x0325,
9219 [BEND_IDX(-40)] = 0x0425,
9220 [BEND_IDX(-45)] = 0x0425,
9221 [BEND_IDX(-50)] = 0x0525,
9226 * steps -50 to 50 inclusive, in steps of 5
9227 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
9228 * change in clock period = -(steps / 10) * 5.787 ps
9230 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
9233 int idx = BEND_IDX(steps);
9235 if (WARN_ON(steps % 5 != 0))
9238 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
9241 mutex_lock(&dev_priv->sb_lock);
9243 if (steps % 10 != 0)
9247 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
9249 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
9251 tmp |= sscdivintphase[idx];
9252 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
9254 mutex_unlock(&dev_priv->sb_lock);
9259 static bool spll_uses_pch_ssc(struct drm_i915_private *dev_priv)
9261 u32 fuse_strap = I915_READ(FUSE_STRAP);
9262 u32 ctl = I915_READ(SPLL_CTL);
9264 if ((ctl & SPLL_PLL_ENABLE) == 0)
9267 if ((ctl & SPLL_REF_MASK) == SPLL_REF_MUXED_SSC &&
9268 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9271 if (IS_BROADWELL(dev_priv) &&
9272 (ctl & SPLL_REF_MASK) == SPLL_REF_PCH_SSC_BDW)
9278 static bool wrpll_uses_pch_ssc(struct drm_i915_private *dev_priv,
9279 enum intel_dpll_id id)
9281 u32 fuse_strap = I915_READ(FUSE_STRAP);
9282 u32 ctl = I915_READ(WRPLL_CTL(id));
9284 if ((ctl & WRPLL_PLL_ENABLE) == 0)
9287 if ((ctl & WRPLL_REF_MASK) == WRPLL_REF_PCH_SSC)
9290 if ((IS_BROADWELL(dev_priv) || IS_HSW_ULT(dev_priv)) &&
9291 (ctl & WRPLL_REF_MASK) == WRPLL_REF_MUXED_SSC_BDW &&
9292 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9298 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
9300 struct intel_encoder *encoder;
9301 bool pch_ssc_in_use = false;
9302 bool has_fdi = false;
9304 for_each_intel_encoder(&dev_priv->drm, encoder) {
9305 switch (encoder->type) {
9306 case INTEL_OUTPUT_ANALOG:
9315 * The BIOS may have decided to use the PCH SSC
9316 * reference so we must not disable it until the
9317 * relevant PLLs have stopped relying on it. We'll
9318 * just leave the PCH SSC reference enabled in case
9319 * any active PLL is using it. It will get disabled
9320 * after runtime suspend if we don't have FDI.
9322 * TODO: Move the whole reference clock handling
9323 * to the modeset sequence proper so that we can
9324 * actually enable/disable/reconfigure these things
9325 * safely. To do that we need to introduce a real
9326 * clock hierarchy. That would also allow us to do
9327 * clock bending finally.
9329 if (spll_uses_pch_ssc(dev_priv)) {
9330 DRM_DEBUG_KMS("SPLL using PCH SSC\n");
9331 pch_ssc_in_use = true;
9334 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL1)) {
9335 DRM_DEBUG_KMS("WRPLL1 using PCH SSC\n");
9336 pch_ssc_in_use = true;
9339 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL2)) {
9340 DRM_DEBUG_KMS("WRPLL2 using PCH SSC\n");
9341 pch_ssc_in_use = true;
9348 lpt_bend_clkout_dp(dev_priv, 0);
9349 lpt_enable_clkout_dp(dev_priv, true, true);
9351 lpt_disable_clkout_dp(dev_priv);
9356 * Initialize reference clocks when the driver loads
9358 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
9360 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
9361 ironlake_init_pch_refclk(dev_priv);
9362 else if (HAS_PCH_LPT(dev_priv))
9363 lpt_init_pch_refclk(dev_priv);
9366 static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
9368 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9369 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9370 enum pipe pipe = crtc->pipe;
9375 switch (crtc_state->pipe_bpp) {
9377 val |= PIPECONF_6BPC;
9380 val |= PIPECONF_8BPC;
9383 val |= PIPECONF_10BPC;
9386 val |= PIPECONF_12BPC;
9389 /* Case prevented by intel_choose_pipe_bpp_dither. */
9393 if (crtc_state->dither)
9394 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
9396 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
9397 val |= PIPECONF_INTERLACED_ILK;
9399 val |= PIPECONF_PROGRESSIVE;
9401 if (crtc_state->limited_color_range)
9402 val |= PIPECONF_COLOR_RANGE_SELECT;
9404 val |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
9406 I915_WRITE(PIPECONF(pipe), val);
9407 POSTING_READ(PIPECONF(pipe));
9410 static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state)
9412 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9413 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9414 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
9417 if (IS_HASWELL(dev_priv) && crtc_state->dither)
9418 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
9420 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
9421 val |= PIPECONF_INTERLACED_ILK;
9423 val |= PIPECONF_PROGRESSIVE;
9425 I915_WRITE(PIPECONF(cpu_transcoder), val);
9426 POSTING_READ(PIPECONF(cpu_transcoder));
9429 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state)
9431 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9432 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9435 switch (crtc_state->pipe_bpp) {
9437 val |= PIPEMISC_DITHER_6_BPC;
9440 val |= PIPEMISC_DITHER_8_BPC;
9443 val |= PIPEMISC_DITHER_10_BPC;
9446 val |= PIPEMISC_DITHER_12_BPC;
9449 MISSING_CASE(crtc_state->pipe_bpp);
9453 if (crtc_state->dither)
9454 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
9456 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
9457 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
9458 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
9460 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
9461 val |= PIPEMISC_YUV420_ENABLE |
9462 PIPEMISC_YUV420_MODE_FULL_BLEND;
9464 if (INTEL_GEN(dev_priv) >= 11 &&
9465 (crtc_state->active_planes & ~(icl_hdr_plane_mask() |
9466 BIT(PLANE_CURSOR))) == 0)
9467 val |= PIPEMISC_HDR_MODE_PRECISION;
9469 I915_WRITE(PIPEMISC(crtc->pipe), val);
9472 int bdw_get_pipemisc_bpp(struct intel_crtc *crtc)
9474 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9477 tmp = I915_READ(PIPEMISC(crtc->pipe));
9479 switch (tmp & PIPEMISC_DITHER_BPC_MASK) {
9480 case PIPEMISC_DITHER_6_BPC:
9482 case PIPEMISC_DITHER_8_BPC:
9484 case PIPEMISC_DITHER_10_BPC:
9486 case PIPEMISC_DITHER_12_BPC:
9494 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
9497 * Account for spread spectrum to avoid
9498 * oversubscribing the link. Max center spread
9499 * is 2.5%; use 5% for safety's sake.
9501 u32 bps = target_clock * bpp * 21 / 20;
9502 return DIV_ROUND_UP(bps, link_bw * 8);
9505 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
9507 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
9510 static void ironlake_compute_dpll(struct intel_crtc *crtc,
9511 struct intel_crtc_state *crtc_state,
9512 struct dpll *reduced_clock)
9514 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9518 /* Enable autotuning of the PLL clock (if permissible) */
9520 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9521 if ((intel_panel_use_ssc(dev_priv) &&
9522 dev_priv->vbt.lvds_ssc_freq == 100000) ||
9523 (HAS_PCH_IBX(dev_priv) &&
9524 intel_is_dual_link_lvds(dev_priv)))
9526 } else if (crtc_state->sdvo_tv_clock) {
9530 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
9532 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
9535 if (reduced_clock) {
9536 fp2 = i9xx_dpll_compute_fp(reduced_clock);
9538 if (reduced_clock->m < factor * reduced_clock->n)
9546 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
9547 dpll |= DPLLB_MODE_LVDS;
9549 dpll |= DPLLB_MODE_DAC_SERIAL;
9551 dpll |= (crtc_state->pixel_multiplier - 1)
9552 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
9554 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
9555 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
9556 dpll |= DPLL_SDVO_HIGH_SPEED;
9558 if (intel_crtc_has_dp_encoder(crtc_state))
9559 dpll |= DPLL_SDVO_HIGH_SPEED;
9562 * The high speed IO clock is only really required for
9563 * SDVO/HDMI/DP, but we also enable it for CRT to make it
9564 * possible to share the DPLL between CRT and HDMI. Enabling
9565 * the clock needlessly does no real harm, except use up a
9566 * bit of power potentially.
9568 * We'll limit this to IVB with 3 pipes, since it has only two
9569 * DPLLs and so DPLL sharing is the only way to get three pipes
9570 * driving PCH ports at the same time. On SNB we could do this,
9571 * and potentially avoid enabling the second DPLL, but it's not
9572 * clear if it''s a win or loss power wise. No point in doing
9573 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
9575 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
9576 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
9577 dpll |= DPLL_SDVO_HIGH_SPEED;
9579 /* compute bitmask from p1 value */
9580 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
9582 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
9584 switch (crtc_state->dpll.p2) {
9586 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
9589 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
9592 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
9595 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
9599 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
9600 intel_panel_use_ssc(dev_priv))
9601 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
9603 dpll |= PLL_REF_INPUT_DREFCLK;
9605 dpll |= DPLL_VCO_ENABLE;
9607 crtc_state->dpll_hw_state.dpll = dpll;
9608 crtc_state->dpll_hw_state.fp0 = fp;
9609 crtc_state->dpll_hw_state.fp1 = fp2;
9612 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
9613 struct intel_crtc_state *crtc_state)
9615 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9616 struct intel_atomic_state *state =
9617 to_intel_atomic_state(crtc_state->base.state);
9618 const struct intel_limit *limit;
9619 int refclk = 120000;
9621 memset(&crtc_state->dpll_hw_state, 0,
9622 sizeof(crtc_state->dpll_hw_state));
9624 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
9625 if (!crtc_state->has_pch_encoder)
9628 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9629 if (intel_panel_use_ssc(dev_priv)) {
9630 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
9631 dev_priv->vbt.lvds_ssc_freq);
9632 refclk = dev_priv->vbt.lvds_ssc_freq;
9635 if (intel_is_dual_link_lvds(dev_priv)) {
9636 if (refclk == 100000)
9637 limit = &intel_limits_ironlake_dual_lvds_100m;
9639 limit = &intel_limits_ironlake_dual_lvds;
9641 if (refclk == 100000)
9642 limit = &intel_limits_ironlake_single_lvds_100m;
9644 limit = &intel_limits_ironlake_single_lvds;
9647 limit = &intel_limits_ironlake_dac;
9650 if (!crtc_state->clock_set &&
9651 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
9652 refclk, NULL, &crtc_state->dpll)) {
9653 DRM_ERROR("Couldn't find PLL settings for mode!\n");
9657 ironlake_compute_dpll(crtc, crtc_state, NULL);
9659 if (!intel_reserve_shared_dplls(state, crtc, NULL)) {
9660 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
9661 pipe_name(crtc->pipe));
9668 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
9669 struct intel_link_m_n *m_n)
9671 struct drm_device *dev = crtc->base.dev;
9672 struct drm_i915_private *dev_priv = to_i915(dev);
9673 enum pipe pipe = crtc->pipe;
9675 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
9676 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
9677 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
9679 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
9680 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
9681 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9684 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
9685 enum transcoder transcoder,
9686 struct intel_link_m_n *m_n,
9687 struct intel_link_m_n *m2_n2)
9689 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9690 enum pipe pipe = crtc->pipe;
9692 if (INTEL_GEN(dev_priv) >= 5) {
9693 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
9694 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
9695 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
9697 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
9698 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
9699 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9701 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
9702 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
9703 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
9704 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
9706 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
9707 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
9708 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9711 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
9712 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
9713 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
9715 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
9716 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
9717 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9721 void intel_dp_get_m_n(struct intel_crtc *crtc,
9722 struct intel_crtc_state *pipe_config)
9724 if (pipe_config->has_pch_encoder)
9725 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
9727 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
9728 &pipe_config->dp_m_n,
9729 &pipe_config->dp_m2_n2);
9732 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
9733 struct intel_crtc_state *pipe_config)
9735 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
9736 &pipe_config->fdi_m_n, NULL);
9739 static void skylake_get_pfit_config(struct intel_crtc *crtc,
9740 struct intel_crtc_state *pipe_config)
9742 struct drm_device *dev = crtc->base.dev;
9743 struct drm_i915_private *dev_priv = to_i915(dev);
9744 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
9749 /* find scaler attached to this pipe */
9750 for (i = 0; i < crtc->num_scalers; i++) {
9751 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
9752 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
9754 pipe_config->pch_pfit.enabled = true;
9755 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
9756 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
9757 scaler_state->scalers[i].in_use = true;
9762 scaler_state->scaler_id = id;
9764 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
9766 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
9771 skylake_get_initial_plane_config(struct intel_crtc *crtc,
9772 struct intel_initial_plane_config *plane_config)
9774 struct drm_device *dev = crtc->base.dev;
9775 struct drm_i915_private *dev_priv = to_i915(dev);
9776 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
9777 enum plane_id plane_id = plane->id;
9779 u32 val, base, offset, stride_mult, tiling, alpha;
9780 int fourcc, pixel_format;
9781 unsigned int aligned_height;
9782 struct drm_framebuffer *fb;
9783 struct intel_framebuffer *intel_fb;
9785 if (!plane->get_hw_state(plane, &pipe))
9788 WARN_ON(pipe != crtc->pipe);
9790 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9792 DRM_DEBUG_KMS("failed to alloc fb\n");
9796 fb = &intel_fb->base;
9800 val = I915_READ(PLANE_CTL(pipe, plane_id));
9802 if (INTEL_GEN(dev_priv) >= 11)
9803 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
9805 pixel_format = val & PLANE_CTL_FORMAT_MASK;
9807 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
9808 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
9809 alpha &= PLANE_COLOR_ALPHA_MASK;
9811 alpha = val & PLANE_CTL_ALPHA_MASK;
9814 fourcc = skl_format_to_fourcc(pixel_format,
9815 val & PLANE_CTL_ORDER_RGBX, alpha);
9816 fb->format = drm_format_info(fourcc);
9818 tiling = val & PLANE_CTL_TILED_MASK;
9820 case PLANE_CTL_TILED_LINEAR:
9821 fb->modifier = DRM_FORMAT_MOD_LINEAR;
9823 case PLANE_CTL_TILED_X:
9824 plane_config->tiling = I915_TILING_X;
9825 fb->modifier = I915_FORMAT_MOD_X_TILED;
9827 case PLANE_CTL_TILED_Y:
9828 plane_config->tiling = I915_TILING_Y;
9829 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
9830 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
9832 fb->modifier = I915_FORMAT_MOD_Y_TILED;
9834 case PLANE_CTL_TILED_YF:
9835 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
9836 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
9838 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
9841 MISSING_CASE(tiling);
9846 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
9847 * while i915 HW rotation is clockwise, thats why this swapping.
9849 switch (val & PLANE_CTL_ROTATE_MASK) {
9850 case PLANE_CTL_ROTATE_0:
9851 plane_config->rotation = DRM_MODE_ROTATE_0;
9853 case PLANE_CTL_ROTATE_90:
9854 plane_config->rotation = DRM_MODE_ROTATE_270;
9856 case PLANE_CTL_ROTATE_180:
9857 plane_config->rotation = DRM_MODE_ROTATE_180;
9859 case PLANE_CTL_ROTATE_270:
9860 plane_config->rotation = DRM_MODE_ROTATE_90;
9864 if (INTEL_GEN(dev_priv) >= 10 &&
9865 val & PLANE_CTL_FLIP_HORIZONTAL)
9866 plane_config->rotation |= DRM_MODE_REFLECT_X;
9868 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
9869 plane_config->base = base;
9871 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
9873 val = I915_READ(PLANE_SIZE(pipe, plane_id));
9874 fb->height = ((val >> 16) & 0xfff) + 1;
9875 fb->width = ((val >> 0) & 0x1fff) + 1;
9877 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
9878 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
9879 fb->pitches[0] = (val & 0x3ff) * stride_mult;
9881 aligned_height = intel_fb_align_height(fb, 0, fb->height);
9883 plane_config->size = fb->pitches[0] * aligned_height;
9885 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9886 crtc->base.name, plane->base.name, fb->width, fb->height,
9887 fb->format->cpp[0] * 8, base, fb->pitches[0],
9888 plane_config->size);
9890 plane_config->fb = intel_fb;
9897 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
9898 struct intel_crtc_state *pipe_config)
9900 struct drm_device *dev = crtc->base.dev;
9901 struct drm_i915_private *dev_priv = to_i915(dev);
9904 tmp = I915_READ(PF_CTL(crtc->pipe));
9906 if (tmp & PF_ENABLE) {
9907 pipe_config->pch_pfit.enabled = true;
9908 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
9909 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
9911 /* We currently do not free assignements of panel fitters on
9912 * ivb/hsw (since we don't use the higher upscaling modes which
9913 * differentiates them) so just WARN about this case for now. */
9914 if (IS_GEN(dev_priv, 7)) {
9915 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
9916 PF_PIPE_SEL_IVB(crtc->pipe));
9921 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
9922 struct intel_crtc_state *pipe_config)
9924 struct drm_device *dev = crtc->base.dev;
9925 struct drm_i915_private *dev_priv = to_i915(dev);
9926 enum intel_display_power_domain power_domain;
9927 intel_wakeref_t wakeref;
9931 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9932 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
9936 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
9937 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9938 pipe_config->shared_dpll = NULL;
9941 tmp = I915_READ(PIPECONF(crtc->pipe));
9942 if (!(tmp & PIPECONF_ENABLE))
9945 switch (tmp & PIPECONF_BPC_MASK) {
9947 pipe_config->pipe_bpp = 18;
9950 pipe_config->pipe_bpp = 24;
9952 case PIPECONF_10BPC:
9953 pipe_config->pipe_bpp = 30;
9955 case PIPECONF_12BPC:
9956 pipe_config->pipe_bpp = 36;
9962 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
9963 pipe_config->limited_color_range = true;
9965 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_ILK) >>
9966 PIPECONF_GAMMA_MODE_SHIFT;
9968 pipe_config->csc_mode = I915_READ(PIPE_CSC_MODE(crtc->pipe));
9970 i9xx_get_pipe_color_config(pipe_config);
9971 intel_color_get_config(pipe_config);
9973 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
9974 struct intel_shared_dpll *pll;
9975 enum intel_dpll_id pll_id;
9977 pipe_config->has_pch_encoder = true;
9979 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
9980 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9981 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9983 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9985 if (HAS_PCH_IBX(dev_priv)) {
9987 * The pipe->pch transcoder and pch transcoder->pll
9990 pll_id = (enum intel_dpll_id) crtc->pipe;
9992 tmp = I915_READ(PCH_DPLL_SEL);
9993 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
9994 pll_id = DPLL_ID_PCH_PLL_B;
9996 pll_id= DPLL_ID_PCH_PLL_A;
9999 pipe_config->shared_dpll =
10000 intel_get_shared_dpll_by_id(dev_priv, pll_id);
10001 pll = pipe_config->shared_dpll;
10003 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
10004 &pipe_config->dpll_hw_state));
10006 tmp = pipe_config->dpll_hw_state.dpll;
10007 pipe_config->pixel_multiplier =
10008 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
10009 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
10011 ironlake_pch_clock_get(crtc, pipe_config);
10013 pipe_config->pixel_multiplier = 1;
10016 intel_get_pipe_timings(crtc, pipe_config);
10017 intel_get_pipe_src_size(crtc, pipe_config);
10019 ironlake_get_pfit_config(crtc, pipe_config);
10024 intel_display_power_put(dev_priv, power_domain, wakeref);
10028 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
10029 struct intel_crtc_state *crtc_state)
10031 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10032 struct intel_atomic_state *state =
10033 to_intel_atomic_state(crtc_state->base.state);
10035 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) ||
10036 INTEL_GEN(dev_priv) >= 11) {
10037 struct intel_encoder *encoder =
10038 intel_get_crtc_new_encoder(state, crtc_state);
10040 if (!intel_reserve_shared_dplls(state, crtc, encoder)) {
10041 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
10042 pipe_name(crtc->pipe));
10050 static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
10052 struct intel_crtc_state *pipe_config)
10054 enum intel_dpll_id id;
10057 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
10058 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
10060 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
10063 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10066 static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
10068 struct intel_crtc_state *pipe_config)
10070 enum phy phy = intel_port_to_phy(dev_priv, port);
10071 enum icl_port_dpll_id port_dpll_id;
10072 enum intel_dpll_id id;
10075 if (intel_phy_is_combo(dev_priv, phy)) {
10076 temp = I915_READ(ICL_DPCLKA_CFGCR0) &
10077 ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
10078 id = temp >> ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy);
10079 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10080 } else if (intel_phy_is_tc(dev_priv, phy)) {
10081 u32 clk_sel = I915_READ(DDI_CLK_SEL(port)) & DDI_CLK_SEL_MASK;
10083 if (clk_sel == DDI_CLK_SEL_MG) {
10084 id = icl_tc_port_to_pll_id(intel_port_to_tc(dev_priv,
10086 port_dpll_id = ICL_PORT_DPLL_MG_PHY;
10088 WARN_ON(clk_sel < DDI_CLK_SEL_TBT_162);
10089 id = DPLL_ID_ICL_TBTPLL;
10090 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10093 WARN(1, "Invalid port %x\n", port);
10097 pipe_config->icl_port_dplls[port_dpll_id].pll =
10098 intel_get_shared_dpll_by_id(dev_priv, id);
10100 icl_set_active_port_dpll(pipe_config, port_dpll_id);
10103 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
10105 struct intel_crtc_state *pipe_config)
10107 enum intel_dpll_id id;
10111 id = DPLL_ID_SKL_DPLL0;
10114 id = DPLL_ID_SKL_DPLL1;
10117 id = DPLL_ID_SKL_DPLL2;
10120 DRM_ERROR("Incorrect port type\n");
10124 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10127 static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
10129 struct intel_crtc_state *pipe_config)
10131 enum intel_dpll_id id;
10134 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
10135 id = temp >> (port * 3 + 1);
10137 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
10140 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10143 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
10145 struct intel_crtc_state *pipe_config)
10147 enum intel_dpll_id id;
10148 u32 ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
10150 switch (ddi_pll_sel) {
10151 case PORT_CLK_SEL_WRPLL1:
10152 id = DPLL_ID_WRPLL1;
10154 case PORT_CLK_SEL_WRPLL2:
10155 id = DPLL_ID_WRPLL2;
10157 case PORT_CLK_SEL_SPLL:
10160 case PORT_CLK_SEL_LCPLL_810:
10161 id = DPLL_ID_LCPLL_810;
10163 case PORT_CLK_SEL_LCPLL_1350:
10164 id = DPLL_ID_LCPLL_1350;
10166 case PORT_CLK_SEL_LCPLL_2700:
10167 id = DPLL_ID_LCPLL_2700;
10170 MISSING_CASE(ddi_pll_sel);
10172 case PORT_CLK_SEL_NONE:
10176 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10179 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
10180 struct intel_crtc_state *pipe_config,
10181 u64 *power_domain_mask,
10182 intel_wakeref_t *wakerefs)
10184 struct drm_device *dev = crtc->base.dev;
10185 struct drm_i915_private *dev_priv = to_i915(dev);
10186 enum intel_display_power_domain power_domain;
10187 unsigned long panel_transcoder_mask = 0;
10188 unsigned long enabled_panel_transcoders = 0;
10189 enum transcoder panel_transcoder;
10190 intel_wakeref_t wf;
10193 if (INTEL_GEN(dev_priv) >= 11)
10194 panel_transcoder_mask |=
10195 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
10197 if (HAS_TRANSCODER_EDP(dev_priv))
10198 panel_transcoder_mask |= BIT(TRANSCODER_EDP);
10201 * The pipe->transcoder mapping is fixed with the exception of the eDP
10202 * and DSI transcoders handled below.
10204 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
10207 * XXX: Do intel_display_power_get_if_enabled before reading this (for
10208 * consistency and less surprising code; it's in always on power).
10210 for_each_set_bit(panel_transcoder,
10211 &panel_transcoder_mask,
10212 ARRAY_SIZE(INTEL_INFO(dev_priv)->trans_offsets)) {
10213 bool force_thru = false;
10214 enum pipe trans_pipe;
10216 tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder));
10217 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
10221 * Log all enabled ones, only use the first one.
10223 * FIXME: This won't work for two separate DSI displays.
10225 enabled_panel_transcoders |= BIT(panel_transcoder);
10226 if (enabled_panel_transcoders != BIT(panel_transcoder))
10229 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
10231 WARN(1, "unknown pipe linked to transcoder %s\n",
10232 transcoder_name(panel_transcoder));
10234 case TRANS_DDI_EDP_INPUT_A_ONOFF:
10237 case TRANS_DDI_EDP_INPUT_A_ON:
10238 trans_pipe = PIPE_A;
10240 case TRANS_DDI_EDP_INPUT_B_ONOFF:
10241 trans_pipe = PIPE_B;
10243 case TRANS_DDI_EDP_INPUT_C_ONOFF:
10244 trans_pipe = PIPE_C;
10248 if (trans_pipe == crtc->pipe) {
10249 pipe_config->cpu_transcoder = panel_transcoder;
10250 pipe_config->pch_pfit.force_thru = force_thru;
10255 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
10257 WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
10258 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
10260 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
10261 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
10263 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10267 wakerefs[power_domain] = wf;
10268 *power_domain_mask |= BIT_ULL(power_domain);
10270 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
10272 return tmp & PIPECONF_ENABLE;
10275 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
10276 struct intel_crtc_state *pipe_config,
10277 u64 *power_domain_mask,
10278 intel_wakeref_t *wakerefs)
10280 struct drm_device *dev = crtc->base.dev;
10281 struct drm_i915_private *dev_priv = to_i915(dev);
10282 enum intel_display_power_domain power_domain;
10283 enum transcoder cpu_transcoder;
10284 intel_wakeref_t wf;
10288 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
10289 if (port == PORT_A)
10290 cpu_transcoder = TRANSCODER_DSI_A;
10292 cpu_transcoder = TRANSCODER_DSI_C;
10294 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
10295 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
10297 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10301 wakerefs[power_domain] = wf;
10302 *power_domain_mask |= BIT_ULL(power_domain);
10305 * The PLL needs to be enabled with a valid divider
10306 * configuration, otherwise accessing DSI registers will hang
10307 * the machine. See BSpec North Display Engine
10308 * registers/MIPI[BXT]. We can break out here early, since we
10309 * need the same DSI PLL to be enabled for both DSI ports.
10311 if (!bxt_dsi_pll_is_enabled(dev_priv))
10314 /* XXX: this works for video mode only */
10315 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
10316 if (!(tmp & DPI_ENABLE))
10319 tmp = I915_READ(MIPI_CTRL(port));
10320 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
10323 pipe_config->cpu_transcoder = cpu_transcoder;
10327 return transcoder_is_dsi(pipe_config->cpu_transcoder);
10330 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
10331 struct intel_crtc_state *pipe_config)
10333 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10334 struct intel_shared_dpll *pll;
10338 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
10340 if (INTEL_GEN(dev_priv) >= 12)
10341 port = TGL_TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
10343 port = TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
10345 if (INTEL_GEN(dev_priv) >= 11)
10346 icelake_get_ddi_pll(dev_priv, port, pipe_config);
10347 else if (IS_CANNONLAKE(dev_priv))
10348 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
10349 else if (IS_GEN9_BC(dev_priv))
10350 skylake_get_ddi_pll(dev_priv, port, pipe_config);
10351 else if (IS_GEN9_LP(dev_priv))
10352 bxt_get_ddi_pll(dev_priv, port, pipe_config);
10354 haswell_get_ddi_pll(dev_priv, port, pipe_config);
10356 pll = pipe_config->shared_dpll;
10358 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
10359 &pipe_config->dpll_hw_state));
10363 * Haswell has only FDI/PCH transcoder A. It is which is connected to
10364 * DDI E. So just check whether this pipe is wired to DDI E and whether
10365 * the PCH transcoder is on.
10367 if (INTEL_GEN(dev_priv) < 9 &&
10368 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
10369 pipe_config->has_pch_encoder = true;
10371 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
10372 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
10373 FDI_DP_PORT_WIDTH_SHIFT) + 1;
10375 ironlake_get_fdi_m_n_config(crtc, pipe_config);
10379 static bool haswell_get_pipe_config(struct intel_crtc *crtc,
10380 struct intel_crtc_state *pipe_config)
10382 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10383 intel_wakeref_t wakerefs[POWER_DOMAIN_NUM], wf;
10384 enum intel_display_power_domain power_domain;
10385 u64 power_domain_mask;
10388 intel_crtc_init_scalers(crtc, pipe_config);
10390 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
10391 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10395 wakerefs[power_domain] = wf;
10396 power_domain_mask = BIT_ULL(power_domain);
10398 pipe_config->shared_dpll = NULL;
10400 active = hsw_get_transcoder_state(crtc, pipe_config,
10401 &power_domain_mask, wakerefs);
10403 if (IS_GEN9_LP(dev_priv) &&
10404 bxt_get_dsi_transcoder_state(crtc, pipe_config,
10405 &power_domain_mask, wakerefs)) {
10413 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
10414 INTEL_GEN(dev_priv) >= 11) {
10415 haswell_get_ddi_port_state(crtc, pipe_config);
10416 intel_get_pipe_timings(crtc, pipe_config);
10419 intel_get_pipe_src_size(crtc, pipe_config);
10420 intel_get_crtc_ycbcr_config(crtc, pipe_config);
10422 pipe_config->gamma_mode = I915_READ(GAMMA_MODE(crtc->pipe));
10424 pipe_config->csc_mode = I915_READ(PIPE_CSC_MODE(crtc->pipe));
10426 if (INTEL_GEN(dev_priv) >= 9) {
10427 u32 tmp = I915_READ(SKL_BOTTOM_COLOR(crtc->pipe));
10429 if (tmp & SKL_BOTTOM_COLOR_GAMMA_ENABLE)
10430 pipe_config->gamma_enable = true;
10432 if (tmp & SKL_BOTTOM_COLOR_CSC_ENABLE)
10433 pipe_config->csc_enable = true;
10435 i9xx_get_pipe_color_config(pipe_config);
10438 intel_color_get_config(pipe_config);
10440 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
10441 WARN_ON(power_domain_mask & BIT_ULL(power_domain));
10443 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10445 wakerefs[power_domain] = wf;
10446 power_domain_mask |= BIT_ULL(power_domain);
10448 if (INTEL_GEN(dev_priv) >= 9)
10449 skylake_get_pfit_config(crtc, pipe_config);
10451 ironlake_get_pfit_config(crtc, pipe_config);
10454 if (hsw_crtc_supports_ips(crtc)) {
10455 if (IS_HASWELL(dev_priv))
10456 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
10459 * We cannot readout IPS state on broadwell, set to
10460 * true so we can set it to a defined state on first
10463 pipe_config->ips_enabled = true;
10467 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
10468 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
10469 pipe_config->pixel_multiplier =
10470 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
10472 pipe_config->pixel_multiplier = 1;
10476 for_each_power_domain(power_domain, power_domain_mask)
10477 intel_display_power_put(dev_priv,
10478 power_domain, wakerefs[power_domain]);
10483 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
10485 struct drm_i915_private *dev_priv =
10486 to_i915(plane_state->base.plane->dev);
10487 const struct drm_framebuffer *fb = plane_state->base.fb;
10488 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
10491 if (INTEL_INFO(dev_priv)->display.cursor_needs_physical)
10492 base = obj->phys_handle->busaddr;
10494 base = intel_plane_ggtt_offset(plane_state);
10496 base += plane_state->color_plane[0].offset;
10498 /* ILK+ do this automagically */
10499 if (HAS_GMCH(dev_priv) &&
10500 plane_state->base.rotation & DRM_MODE_ROTATE_180)
10501 base += (plane_state->base.crtc_h *
10502 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
10507 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
10509 int x = plane_state->base.crtc_x;
10510 int y = plane_state->base.crtc_y;
10514 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
10517 pos |= x << CURSOR_X_SHIFT;
10520 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
10523 pos |= y << CURSOR_Y_SHIFT;
10528 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
10530 const struct drm_mode_config *config =
10531 &plane_state->base.plane->dev->mode_config;
10532 int width = plane_state->base.crtc_w;
10533 int height = plane_state->base.crtc_h;
10535 return width > 0 && width <= config->cursor_width &&
10536 height > 0 && height <= config->cursor_height;
10539 static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
10545 ret = intel_plane_compute_gtt(plane_state);
10549 if (!plane_state->base.visible)
10552 src_x = plane_state->base.src_x >> 16;
10553 src_y = plane_state->base.src_y >> 16;
10555 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
10556 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
10559 if (src_x != 0 || src_y != 0) {
10560 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
10564 plane_state->color_plane[0].offset = offset;
10569 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
10570 struct intel_plane_state *plane_state)
10572 const struct drm_framebuffer *fb = plane_state->base.fb;
10575 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
10576 DRM_DEBUG_KMS("cursor cannot be tiled\n");
10580 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
10582 DRM_PLANE_HELPER_NO_SCALING,
10583 DRM_PLANE_HELPER_NO_SCALING,
10588 ret = intel_cursor_check_surface(plane_state);
10592 if (!plane_state->base.visible)
10595 ret = intel_plane_check_src_coordinates(plane_state);
10602 static unsigned int
10603 i845_cursor_max_stride(struct intel_plane *plane,
10604 u32 pixel_format, u64 modifier,
10605 unsigned int rotation)
10610 static u32 i845_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
10614 if (crtc_state->gamma_enable)
10615 cntl |= CURSOR_GAMMA_ENABLE;
10620 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
10621 const struct intel_plane_state *plane_state)
10623 return CURSOR_ENABLE |
10624 CURSOR_FORMAT_ARGB |
10625 CURSOR_STRIDE(plane_state->color_plane[0].stride);
10628 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
10630 int width = plane_state->base.crtc_w;
10633 * 845g/865g are only limited by the width of their cursors,
10634 * the height is arbitrary up to the precision of the register.
10636 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
10639 static int i845_check_cursor(struct intel_crtc_state *crtc_state,
10640 struct intel_plane_state *plane_state)
10642 const struct drm_framebuffer *fb = plane_state->base.fb;
10645 ret = intel_check_cursor(crtc_state, plane_state);
10649 /* if we want to turn off the cursor ignore width and height */
10653 /* Check for which cursor types we support */
10654 if (!i845_cursor_size_ok(plane_state)) {
10655 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10656 plane_state->base.crtc_w,
10657 plane_state->base.crtc_h);
10661 WARN_ON(plane_state->base.visible &&
10662 plane_state->color_plane[0].stride != fb->pitches[0]);
10664 switch (fb->pitches[0]) {
10671 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
10676 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
10681 static void i845_update_cursor(struct intel_plane *plane,
10682 const struct intel_crtc_state *crtc_state,
10683 const struct intel_plane_state *plane_state)
10685 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10686 u32 cntl = 0, base = 0, pos = 0, size = 0;
10687 unsigned long irqflags;
10689 if (plane_state && plane_state->base.visible) {
10690 unsigned int width = plane_state->base.crtc_w;
10691 unsigned int height = plane_state->base.crtc_h;
10693 cntl = plane_state->ctl |
10694 i845_cursor_ctl_crtc(crtc_state);
10696 size = (height << 12) | width;
10698 base = intel_cursor_base(plane_state);
10699 pos = intel_cursor_position(plane_state);
10702 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10704 /* On these chipsets we can only modify the base/size/stride
10705 * whilst the cursor is disabled.
10707 if (plane->cursor.base != base ||
10708 plane->cursor.size != size ||
10709 plane->cursor.cntl != cntl) {
10710 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
10711 I915_WRITE_FW(CURBASE(PIPE_A), base);
10712 I915_WRITE_FW(CURSIZE, size);
10713 I915_WRITE_FW(CURPOS(PIPE_A), pos);
10714 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
10716 plane->cursor.base = base;
10717 plane->cursor.size = size;
10718 plane->cursor.cntl = cntl;
10720 I915_WRITE_FW(CURPOS(PIPE_A), pos);
10723 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
10726 static void i845_disable_cursor(struct intel_plane *plane,
10727 const struct intel_crtc_state *crtc_state)
10729 i845_update_cursor(plane, crtc_state, NULL);
10732 static bool i845_cursor_get_hw_state(struct intel_plane *plane,
10735 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10736 enum intel_display_power_domain power_domain;
10737 intel_wakeref_t wakeref;
10740 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
10741 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10745 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
10749 intel_display_power_put(dev_priv, power_domain, wakeref);
10754 static unsigned int
10755 i9xx_cursor_max_stride(struct intel_plane *plane,
10756 u32 pixel_format, u64 modifier,
10757 unsigned int rotation)
10759 return plane->base.dev->mode_config.cursor_width * 4;
10762 static u32 i9xx_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
10764 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
10765 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10768 if (INTEL_GEN(dev_priv) >= 11)
10771 if (crtc_state->gamma_enable)
10772 cntl = MCURSOR_GAMMA_ENABLE;
10774 if (crtc_state->csc_enable)
10775 cntl |= MCURSOR_PIPE_CSC_ENABLE;
10777 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10778 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
10783 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
10784 const struct intel_plane_state *plane_state)
10786 struct drm_i915_private *dev_priv =
10787 to_i915(plane_state->base.plane->dev);
10790 if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
10791 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
10793 switch (plane_state->base.crtc_w) {
10795 cntl |= MCURSOR_MODE_64_ARGB_AX;
10798 cntl |= MCURSOR_MODE_128_ARGB_AX;
10801 cntl |= MCURSOR_MODE_256_ARGB_AX;
10804 MISSING_CASE(plane_state->base.crtc_w);
10808 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
10809 cntl |= MCURSOR_ROTATE_180;
10814 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
10816 struct drm_i915_private *dev_priv =
10817 to_i915(plane_state->base.plane->dev);
10818 int width = plane_state->base.crtc_w;
10819 int height = plane_state->base.crtc_h;
10821 if (!intel_cursor_size_ok(plane_state))
10824 /* Cursor width is limited to a few power-of-two sizes */
10835 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
10836 * height from 8 lines up to the cursor width, when the
10837 * cursor is not rotated. Everything else requires square
10840 if (HAS_CUR_FBC(dev_priv) &&
10841 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
10842 if (height < 8 || height > width)
10845 if (height != width)
10852 static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
10853 struct intel_plane_state *plane_state)
10855 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
10856 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10857 const struct drm_framebuffer *fb = plane_state->base.fb;
10858 enum pipe pipe = plane->pipe;
10861 ret = intel_check_cursor(crtc_state, plane_state);
10865 /* if we want to turn off the cursor ignore width and height */
10869 /* Check for which cursor types we support */
10870 if (!i9xx_cursor_size_ok(plane_state)) {
10871 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10872 plane_state->base.crtc_w,
10873 plane_state->base.crtc_h);
10877 WARN_ON(plane_state->base.visible &&
10878 plane_state->color_plane[0].stride != fb->pitches[0]);
10880 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
10881 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
10882 fb->pitches[0], plane_state->base.crtc_w);
10887 * There's something wrong with the cursor on CHV pipe C.
10888 * If it straddles the left edge of the screen then
10889 * moving it away from the edge or disabling it often
10890 * results in a pipe underrun, and often that can lead to
10891 * dead pipe (constant underrun reported, and it scans
10892 * out just a solid color). To recover from that, the
10893 * display power well must be turned off and on again.
10894 * Refuse the put the cursor into that compromised position.
10896 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
10897 plane_state->base.visible && plane_state->base.crtc_x < 0) {
10898 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
10902 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
10907 static void i9xx_update_cursor(struct intel_plane *plane,
10908 const struct intel_crtc_state *crtc_state,
10909 const struct intel_plane_state *plane_state)
10911 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10912 enum pipe pipe = plane->pipe;
10913 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
10914 unsigned long irqflags;
10916 if (plane_state && plane_state->base.visible) {
10917 cntl = plane_state->ctl |
10918 i9xx_cursor_ctl_crtc(crtc_state);
10920 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
10921 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
10923 base = intel_cursor_base(plane_state);
10924 pos = intel_cursor_position(plane_state);
10927 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10930 * On some platforms writing CURCNTR first will also
10931 * cause CURPOS to be armed by the CURBASE write.
10932 * Without the CURCNTR write the CURPOS write would
10933 * arm itself. Thus we always update CURCNTR before
10936 * On other platforms CURPOS always requires the
10937 * CURBASE write to arm the update. Additonally
10938 * a write to any of the cursor register will cancel
10939 * an already armed cursor update. Thus leaving out
10940 * the CURBASE write after CURPOS could lead to a
10941 * cursor that doesn't appear to move, or even change
10942 * shape. Thus we always write CURBASE.
10944 * The other registers are armed by by the CURBASE write
10945 * except when the plane is getting enabled at which time
10946 * the CURCNTR write arms the update.
10949 if (INTEL_GEN(dev_priv) >= 9)
10950 skl_write_cursor_wm(plane, crtc_state);
10952 if (plane->cursor.base != base ||
10953 plane->cursor.size != fbc_ctl ||
10954 plane->cursor.cntl != cntl) {
10955 if (HAS_CUR_FBC(dev_priv))
10956 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
10957 I915_WRITE_FW(CURCNTR(pipe), cntl);
10958 I915_WRITE_FW(CURPOS(pipe), pos);
10959 I915_WRITE_FW(CURBASE(pipe), base);
10961 plane->cursor.base = base;
10962 plane->cursor.size = fbc_ctl;
10963 plane->cursor.cntl = cntl;
10965 I915_WRITE_FW(CURPOS(pipe), pos);
10966 I915_WRITE_FW(CURBASE(pipe), base);
10969 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
10972 static void i9xx_disable_cursor(struct intel_plane *plane,
10973 const struct intel_crtc_state *crtc_state)
10975 i9xx_update_cursor(plane, crtc_state, NULL);
10978 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
10981 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10982 enum intel_display_power_domain power_domain;
10983 intel_wakeref_t wakeref;
10988 * Not 100% correct for planes that can move between pipes,
10989 * but that's only the case for gen2-3 which don't have any
10990 * display power wells.
10992 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
10993 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10997 val = I915_READ(CURCNTR(plane->pipe));
10999 ret = val & MCURSOR_MODE;
11001 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
11002 *pipe = plane->pipe;
11004 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
11005 MCURSOR_PIPE_SELECT_SHIFT;
11007 intel_display_power_put(dev_priv, power_domain, wakeref);
11012 /* VESA 640x480x72Hz mode to set on the pipe */
11013 static const struct drm_display_mode load_detect_mode = {
11014 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
11015 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
11018 struct drm_framebuffer *
11019 intel_framebuffer_create(struct drm_i915_gem_object *obj,
11020 struct drm_mode_fb_cmd2 *mode_cmd)
11022 struct intel_framebuffer *intel_fb;
11025 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
11027 return ERR_PTR(-ENOMEM);
11029 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
11033 return &intel_fb->base;
11037 return ERR_PTR(ret);
11040 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
11041 struct drm_crtc *crtc)
11043 struct drm_plane *plane;
11044 struct drm_plane_state *plane_state;
11047 ret = drm_atomic_add_affected_planes(state, crtc);
11051 for_each_new_plane_in_state(state, plane, plane_state, i) {
11052 if (plane_state->crtc != crtc)
11055 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
11059 drm_atomic_set_fb_for_plane(plane_state, NULL);
11065 int intel_get_load_detect_pipe(struct drm_connector *connector,
11066 const struct drm_display_mode *mode,
11067 struct intel_load_detect_pipe *old,
11068 struct drm_modeset_acquire_ctx *ctx)
11070 struct intel_crtc *intel_crtc;
11071 struct intel_encoder *intel_encoder =
11072 intel_attached_encoder(connector);
11073 struct drm_crtc *possible_crtc;
11074 struct drm_encoder *encoder = &intel_encoder->base;
11075 struct drm_crtc *crtc = NULL;
11076 struct drm_device *dev = encoder->dev;
11077 struct drm_i915_private *dev_priv = to_i915(dev);
11078 struct drm_mode_config *config = &dev->mode_config;
11079 struct drm_atomic_state *state = NULL, *restore_state = NULL;
11080 struct drm_connector_state *connector_state;
11081 struct intel_crtc_state *crtc_state;
11084 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11085 connector->base.id, connector->name,
11086 encoder->base.id, encoder->name);
11088 old->restore_state = NULL;
11090 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
11093 * Algorithm gets a little messy:
11095 * - if the connector already has an assigned crtc, use it (but make
11096 * sure it's on first)
11098 * - try to find the first unused crtc that can drive this connector,
11099 * and use that if we find one
11102 /* See if we already have a CRTC for this connector */
11103 if (connector->state->crtc) {
11104 crtc = connector->state->crtc;
11106 ret = drm_modeset_lock(&crtc->mutex, ctx);
11110 /* Make sure the crtc and connector are running */
11114 /* Find an unused one (if possible) */
11115 for_each_crtc(dev, possible_crtc) {
11117 if (!(encoder->possible_crtcs & (1 << i)))
11120 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
11124 if (possible_crtc->state->enable) {
11125 drm_modeset_unlock(&possible_crtc->mutex);
11129 crtc = possible_crtc;
11134 * If we didn't find an unused CRTC, don't use any.
11137 DRM_DEBUG_KMS("no pipe available for load-detect\n");
11143 intel_crtc = to_intel_crtc(crtc);
11145 state = drm_atomic_state_alloc(dev);
11146 restore_state = drm_atomic_state_alloc(dev);
11147 if (!state || !restore_state) {
11152 state->acquire_ctx = ctx;
11153 restore_state->acquire_ctx = ctx;
11155 connector_state = drm_atomic_get_connector_state(state, connector);
11156 if (IS_ERR(connector_state)) {
11157 ret = PTR_ERR(connector_state);
11161 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
11165 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
11166 if (IS_ERR(crtc_state)) {
11167 ret = PTR_ERR(crtc_state);
11171 crtc_state->base.active = crtc_state->base.enable = true;
11174 mode = &load_detect_mode;
11176 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
11180 ret = intel_modeset_disable_planes(state, crtc);
11184 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
11186 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
11188 ret = drm_atomic_add_affected_planes(restore_state, crtc);
11190 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
11194 ret = drm_atomic_commit(state);
11196 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
11200 old->restore_state = restore_state;
11201 drm_atomic_state_put(state);
11203 /* let the connector get through one full cycle before testing */
11204 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
11209 drm_atomic_state_put(state);
11212 if (restore_state) {
11213 drm_atomic_state_put(restore_state);
11214 restore_state = NULL;
11217 if (ret == -EDEADLK)
11223 void intel_release_load_detect_pipe(struct drm_connector *connector,
11224 struct intel_load_detect_pipe *old,
11225 struct drm_modeset_acquire_ctx *ctx)
11227 struct intel_encoder *intel_encoder =
11228 intel_attached_encoder(connector);
11229 struct drm_encoder *encoder = &intel_encoder->base;
11230 struct drm_atomic_state *state = old->restore_state;
11233 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11234 connector->base.id, connector->name,
11235 encoder->base.id, encoder->name);
11240 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
11242 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
11243 drm_atomic_state_put(state);
11246 static int i9xx_pll_refclk(struct drm_device *dev,
11247 const struct intel_crtc_state *pipe_config)
11249 struct drm_i915_private *dev_priv = to_i915(dev);
11250 u32 dpll = pipe_config->dpll_hw_state.dpll;
11252 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
11253 return dev_priv->vbt.lvds_ssc_freq;
11254 else if (HAS_PCH_SPLIT(dev_priv))
11256 else if (!IS_GEN(dev_priv, 2))
11262 /* Returns the clock of the currently programmed mode of the given pipe. */
11263 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
11264 struct intel_crtc_state *pipe_config)
11266 struct drm_device *dev = crtc->base.dev;
11267 struct drm_i915_private *dev_priv = to_i915(dev);
11268 enum pipe pipe = crtc->pipe;
11269 u32 dpll = pipe_config->dpll_hw_state.dpll;
11273 int refclk = i9xx_pll_refclk(dev, pipe_config);
11275 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
11276 fp = pipe_config->dpll_hw_state.fp0;
11278 fp = pipe_config->dpll_hw_state.fp1;
11280 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
11281 if (IS_PINEVIEW(dev_priv)) {
11282 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
11283 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
11285 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
11286 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
11289 if (!IS_GEN(dev_priv, 2)) {
11290 if (IS_PINEVIEW(dev_priv))
11291 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
11292 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
11294 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
11295 DPLL_FPA01_P1_POST_DIV_SHIFT);
11297 switch (dpll & DPLL_MODE_MASK) {
11298 case DPLLB_MODE_DAC_SERIAL:
11299 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
11302 case DPLLB_MODE_LVDS:
11303 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
11307 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
11308 "mode\n", (int)(dpll & DPLL_MODE_MASK));
11312 if (IS_PINEVIEW(dev_priv))
11313 port_clock = pnv_calc_dpll_params(refclk, &clock);
11315 port_clock = i9xx_calc_dpll_params(refclk, &clock);
11317 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
11318 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
11321 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
11322 DPLL_FPA01_P1_POST_DIV_SHIFT);
11324 if (lvds & LVDS_CLKB_POWER_UP)
11329 if (dpll & PLL_P1_DIVIDE_BY_TWO)
11332 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
11333 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
11335 if (dpll & PLL_P2_DIVIDE_BY_4)
11341 port_clock = i9xx_calc_dpll_params(refclk, &clock);
11345 * This value includes pixel_multiplier. We will use
11346 * port_clock to compute adjusted_mode.crtc_clock in the
11347 * encoder's get_config() function.
11349 pipe_config->port_clock = port_clock;
11352 int intel_dotclock_calculate(int link_freq,
11353 const struct intel_link_m_n *m_n)
11356 * The calculation for the data clock is:
11357 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
11358 * But we want to avoid losing precison if possible, so:
11359 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
11361 * and the link clock is simpler:
11362 * link_clock = (m * link_clock) / n
11368 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
11371 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
11372 struct intel_crtc_state *pipe_config)
11374 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11376 /* read out port_clock from the DPLL */
11377 i9xx_crtc_clock_get(crtc, pipe_config);
11380 * In case there is an active pipe without active ports,
11381 * we may need some idea for the dotclock anyway.
11382 * Calculate one based on the FDI configuration.
11384 pipe_config->base.adjusted_mode.crtc_clock =
11385 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
11386 &pipe_config->fdi_m_n);
11389 /* Returns the currently programmed mode of the given encoder. */
11390 struct drm_display_mode *
11391 intel_encoder_current_mode(struct intel_encoder *encoder)
11393 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
11394 struct intel_crtc_state *crtc_state;
11395 struct drm_display_mode *mode;
11396 struct intel_crtc *crtc;
11399 if (!encoder->get_hw_state(encoder, &pipe))
11402 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
11404 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
11408 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
11414 crtc_state->base.crtc = &crtc->base;
11416 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
11422 encoder->get_config(encoder, crtc_state);
11424 intel_mode_from_pipe_config(mode, crtc_state);
11431 static void intel_crtc_destroy(struct drm_crtc *crtc)
11433 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11435 drm_crtc_cleanup(crtc);
11440 * intel_wm_need_update - Check whether watermarks need updating
11441 * @cur: current plane state
11442 * @new: new plane state
11444 * Check current plane state versus the new one to determine whether
11445 * watermarks need to be recalculated.
11447 * Returns true or false.
11449 static bool intel_wm_need_update(const struct intel_plane_state *cur,
11450 struct intel_plane_state *new)
11452 /* Update watermarks on tiling or size changes. */
11453 if (new->base.visible != cur->base.visible)
11456 if (!cur->base.fb || !new->base.fb)
11459 if (cur->base.fb->modifier != new->base.fb->modifier ||
11460 cur->base.rotation != new->base.rotation ||
11461 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
11462 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
11463 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
11464 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
11470 static bool needs_scaling(const struct intel_plane_state *state)
11472 int src_w = drm_rect_width(&state->base.src) >> 16;
11473 int src_h = drm_rect_height(&state->base.src) >> 16;
11474 int dst_w = drm_rect_width(&state->base.dst);
11475 int dst_h = drm_rect_height(&state->base.dst);
11477 return (src_w != dst_w || src_h != dst_h);
11480 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
11481 struct intel_crtc_state *crtc_state,
11482 const struct intel_plane_state *old_plane_state,
11483 struct intel_plane_state *plane_state)
11485 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
11486 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
11487 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11488 bool mode_changed = needs_modeset(crtc_state);
11489 bool was_crtc_enabled = old_crtc_state->base.active;
11490 bool is_crtc_enabled = crtc_state->base.active;
11491 bool turn_off, turn_on, visible, was_visible;
11492 struct drm_framebuffer *fb = plane_state->base.fb;
11495 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
11496 ret = skl_update_scaler_plane(crtc_state, plane_state);
11501 was_visible = old_plane_state->base.visible;
11502 visible = plane_state->base.visible;
11504 if (!was_crtc_enabled && WARN_ON(was_visible))
11505 was_visible = false;
11508 * Visibility is calculated as if the crtc was on, but
11509 * after scaler setup everything depends on it being off
11510 * when the crtc isn't active.
11512 * FIXME this is wrong for watermarks. Watermarks should also
11513 * be computed as if the pipe would be active. Perhaps move
11514 * per-plane wm computation to the .check_plane() hook, and
11515 * only combine the results from all planes in the current place?
11517 if (!is_crtc_enabled) {
11518 plane_state->base.visible = visible = false;
11519 crtc_state->active_planes &= ~BIT(plane->id);
11520 crtc_state->data_rate[plane->id] = 0;
11523 if (!was_visible && !visible)
11526 if (fb != old_plane_state->base.fb)
11527 crtc_state->fb_changed = true;
11529 turn_off = was_visible && (!visible || mode_changed);
11530 turn_on = visible && (!was_visible || mode_changed);
11532 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
11533 crtc->base.base.id, crtc->base.name,
11534 plane->base.base.id, plane->base.name,
11535 fb ? fb->base.id : -1);
11537 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
11538 plane->base.base.id, plane->base.name,
11539 was_visible, visible,
11540 turn_off, turn_on, mode_changed);
11543 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11544 crtc_state->update_wm_pre = true;
11546 /* must disable cxsr around plane enable/disable */
11547 if (plane->id != PLANE_CURSOR)
11548 crtc_state->disable_cxsr = true;
11549 } else if (turn_off) {
11550 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11551 crtc_state->update_wm_post = true;
11553 /* must disable cxsr around plane enable/disable */
11554 if (plane->id != PLANE_CURSOR)
11555 crtc_state->disable_cxsr = true;
11556 } else if (intel_wm_need_update(old_plane_state, plane_state)) {
11557 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
11558 /* FIXME bollocks */
11559 crtc_state->update_wm_pre = true;
11560 crtc_state->update_wm_post = true;
11564 if (visible || was_visible)
11565 crtc_state->fb_bits |= plane->frontbuffer_bit;
11568 * ILK/SNB DVSACNTR/Sprite Enable
11569 * IVB SPR_CTL/Sprite Enable
11570 * "When in Self Refresh Big FIFO mode, a write to enable the
11571 * plane will be internally buffered and delayed while Big FIFO
11572 * mode is exiting."
11574 * Which means that enabling the sprite can take an extra frame
11575 * when we start in big FIFO mode (LP1+). Thus we need to drop
11576 * down to LP0 and wait for vblank in order to make sure the
11577 * sprite gets enabled on the next vblank after the register write.
11578 * Doing otherwise would risk enabling the sprite one frame after
11579 * we've already signalled flip completion. We can resume LP1+
11580 * once the sprite has been enabled.
11583 * WaCxSRDisabledForSpriteScaling:ivb
11584 * IVB SPR_SCALE/Scaling Enable
11585 * "Low Power watermarks must be disabled for at least one
11586 * frame before enabling sprite scaling, and kept disabled
11587 * until sprite scaling is disabled."
11589 * ILK/SNB DVSASCALE/Scaling Enable
11590 * "When in Self Refresh Big FIFO mode, scaling enable will be
11591 * masked off while Big FIFO mode is exiting."
11593 * Despite the w/a only being listed for IVB we assume that
11594 * the ILK/SNB note has similar ramifications, hence we apply
11595 * the w/a on all three platforms.
11597 * With experimental results seems this is needed also for primary
11598 * plane, not only sprite plane.
11600 if (plane->id != PLANE_CURSOR &&
11601 (IS_GEN_RANGE(dev_priv, 5, 6) ||
11602 IS_IVYBRIDGE(dev_priv)) &&
11603 (turn_on || (!needs_scaling(old_plane_state) &&
11604 needs_scaling(plane_state))))
11605 crtc_state->disable_lp_wm = true;
11610 static bool encoders_cloneable(const struct intel_encoder *a,
11611 const struct intel_encoder *b)
11613 /* masks could be asymmetric, so check both ways */
11614 return a == b || (a->cloneable & (1 << b->type) &&
11615 b->cloneable & (1 << a->type));
11618 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
11619 struct intel_crtc *crtc,
11620 struct intel_encoder *encoder)
11622 struct intel_encoder *source_encoder;
11623 struct drm_connector *connector;
11624 struct drm_connector_state *connector_state;
11627 for_each_new_connector_in_state(state, connector, connector_state, i) {
11628 if (connector_state->crtc != &crtc->base)
11632 to_intel_encoder(connector_state->best_encoder);
11633 if (!encoders_cloneable(encoder, source_encoder))
11640 static int icl_add_linked_planes(struct intel_atomic_state *state)
11642 struct intel_plane *plane, *linked;
11643 struct intel_plane_state *plane_state, *linked_plane_state;
11646 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11647 linked = plane_state->linked_plane;
11652 linked_plane_state = intel_atomic_get_plane_state(state, linked);
11653 if (IS_ERR(linked_plane_state))
11654 return PTR_ERR(linked_plane_state);
11656 WARN_ON(linked_plane_state->linked_plane != plane);
11657 WARN_ON(linked_plane_state->slave == plane_state->slave);
11663 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
11665 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
11666 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11667 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state);
11668 struct intel_plane *plane, *linked;
11669 struct intel_plane_state *plane_state;
11672 if (INTEL_GEN(dev_priv) < 11)
11676 * Destroy all old plane links and make the slave plane invisible
11677 * in the crtc_state->active_planes mask.
11679 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11680 if (plane->pipe != crtc->pipe || !plane_state->linked_plane)
11683 plane_state->linked_plane = NULL;
11684 if (plane_state->slave && !plane_state->base.visible) {
11685 crtc_state->active_planes &= ~BIT(plane->id);
11686 crtc_state->update_planes |= BIT(plane->id);
11689 plane_state->slave = false;
11692 if (!crtc_state->nv12_planes)
11695 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11696 struct intel_plane_state *linked_state = NULL;
11698 if (plane->pipe != crtc->pipe ||
11699 !(crtc_state->nv12_planes & BIT(plane->id)))
11702 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
11703 if (!icl_is_nv12_y_plane(linked->id))
11706 if (crtc_state->active_planes & BIT(linked->id))
11709 linked_state = intel_atomic_get_plane_state(state, linked);
11710 if (IS_ERR(linked_state))
11711 return PTR_ERR(linked_state);
11716 if (!linked_state) {
11717 DRM_DEBUG_KMS("Need %d free Y planes for planar YUV\n",
11718 hweight8(crtc_state->nv12_planes));
11723 plane_state->linked_plane = linked;
11725 linked_state->slave = true;
11726 linked_state->linked_plane = plane;
11727 crtc_state->active_planes |= BIT(linked->id);
11728 crtc_state->update_planes |= BIT(linked->id);
11729 DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name);
11735 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
11737 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
11738 struct intel_atomic_state *state =
11739 to_intel_atomic_state(new_crtc_state->base.state);
11740 const struct intel_crtc_state *old_crtc_state =
11741 intel_atomic_get_old_crtc_state(state, crtc);
11743 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
11746 static int intel_crtc_atomic_check(struct drm_crtc *crtc,
11747 struct drm_crtc_state *crtc_state)
11749 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
11750 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11751 struct intel_crtc_state *pipe_config =
11752 to_intel_crtc_state(crtc_state);
11754 bool mode_changed = needs_modeset(pipe_config);
11756 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv) &&
11757 mode_changed && !crtc_state->active)
11758 pipe_config->update_wm_post = true;
11760 if (mode_changed && crtc_state->enable &&
11761 dev_priv->display.crtc_compute_clock &&
11762 !WARN_ON(pipe_config->shared_dpll)) {
11763 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
11770 * May need to update pipe gamma enable bits
11771 * when C8 planes are getting enabled/disabled.
11773 if (c8_planes_changed(pipe_config))
11774 crtc_state->color_mgmt_changed = true;
11776 if (mode_changed || pipe_config->update_pipe ||
11777 crtc_state->color_mgmt_changed) {
11778 ret = intel_color_check(pipe_config);
11784 if (dev_priv->display.compute_pipe_wm) {
11785 ret = dev_priv->display.compute_pipe_wm(pipe_config);
11787 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
11792 if (dev_priv->display.compute_intermediate_wm) {
11793 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
11797 * Calculate 'intermediate' watermarks that satisfy both the
11798 * old state and the new state. We can program these
11801 ret = dev_priv->display.compute_intermediate_wm(pipe_config);
11803 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
11808 if (INTEL_GEN(dev_priv) >= 9) {
11809 if (mode_changed || pipe_config->update_pipe)
11810 ret = skl_update_scaler_crtc(pipe_config);
11813 ret = icl_check_nv12_planes(pipe_config);
11815 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
11818 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
11822 if (HAS_IPS(dev_priv))
11823 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
11828 static const struct drm_crtc_helper_funcs intel_helper_funcs = {
11829 .atomic_check = intel_crtc_atomic_check,
11832 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
11834 struct intel_connector *connector;
11835 struct drm_connector_list_iter conn_iter;
11837 drm_connector_list_iter_begin(dev, &conn_iter);
11838 for_each_intel_connector_iter(connector, &conn_iter) {
11839 if (connector->base.state->crtc)
11840 drm_connector_put(&connector->base);
11842 if (connector->base.encoder) {
11843 connector->base.state->best_encoder =
11844 connector->base.encoder;
11845 connector->base.state->crtc =
11846 connector->base.encoder->crtc;
11848 drm_connector_get(&connector->base);
11850 connector->base.state->best_encoder = NULL;
11851 connector->base.state->crtc = NULL;
11854 drm_connector_list_iter_end(&conn_iter);
11858 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
11859 struct intel_crtc_state *pipe_config)
11861 struct drm_connector *connector = conn_state->connector;
11862 const struct drm_display_info *info = &connector->display_info;
11865 switch (conn_state->max_bpc) {
11882 if (bpp < pipe_config->pipe_bpp) {
11883 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
11884 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
11885 connector->base.id, connector->name,
11886 bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc,
11887 pipe_config->pipe_bpp);
11889 pipe_config->pipe_bpp = bpp;
11896 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
11897 struct intel_crtc_state *pipe_config)
11899 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11900 struct drm_atomic_state *state = pipe_config->base.state;
11901 struct drm_connector *connector;
11902 struct drm_connector_state *connector_state;
11905 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
11906 IS_CHERRYVIEW(dev_priv)))
11908 else if (INTEL_GEN(dev_priv) >= 5)
11913 pipe_config->pipe_bpp = bpp;
11915 /* Clamp display bpp to connector max bpp */
11916 for_each_new_connector_in_state(state, connector, connector_state, i) {
11919 if (connector_state->crtc != &crtc->base)
11922 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
11930 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
11932 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11933 "type: 0x%x flags: 0x%x\n",
11935 mode->crtc_hdisplay, mode->crtc_hsync_start,
11936 mode->crtc_hsync_end, mode->crtc_htotal,
11937 mode->crtc_vdisplay, mode->crtc_vsync_start,
11938 mode->crtc_vsync_end, mode->crtc_vtotal,
11939 mode->type, mode->flags);
11943 intel_dump_m_n_config(const struct intel_crtc_state *pipe_config,
11944 const char *id, unsigned int lane_count,
11945 const struct intel_link_m_n *m_n)
11947 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11949 m_n->gmch_m, m_n->gmch_n,
11950 m_n->link_m, m_n->link_n, m_n->tu);
11954 intel_dump_infoframe(struct drm_i915_private *dev_priv,
11955 const union hdmi_infoframe *frame)
11957 if ((drm_debug & DRM_UT_KMS) == 0)
11960 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, frame);
11963 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
11965 static const char * const output_type_str[] = {
11966 OUTPUT_TYPE(UNUSED),
11967 OUTPUT_TYPE(ANALOG),
11971 OUTPUT_TYPE(TVOUT),
11977 OUTPUT_TYPE(DP_MST),
11982 static void snprintf_output_types(char *buf, size_t len,
11983 unsigned int output_types)
11990 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
11993 if ((output_types & BIT(i)) == 0)
11996 r = snprintf(str, len, "%s%s",
11997 str != buf ? "," : "", output_type_str[i]);
12003 output_types &= ~BIT(i);
12006 WARN_ON_ONCE(output_types != 0);
12009 static const char * const output_format_str[] = {
12010 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
12011 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
12012 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
12013 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
12016 static const char *output_formats(enum intel_output_format format)
12018 if (format >= ARRAY_SIZE(output_format_str))
12019 format = INTEL_OUTPUT_FORMAT_INVALID;
12020 return output_format_str[format];
12023 static void intel_dump_plane_state(const struct intel_plane_state *plane_state)
12025 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
12026 const struct drm_framebuffer *fb = plane_state->base.fb;
12027 struct drm_format_name_buf format_name;
12030 DRM_DEBUG_KMS("[PLANE:%d:%s] fb: [NOFB], visible: %s\n",
12031 plane->base.base.id, plane->base.name,
12032 yesno(plane_state->base.visible));
12036 DRM_DEBUG_KMS("[PLANE:%d:%s] fb: [FB:%d] %ux%u format = %s, visible: %s\n",
12037 plane->base.base.id, plane->base.name,
12038 fb->base.id, fb->width, fb->height,
12039 drm_get_format_name(fb->format->format, &format_name),
12040 yesno(plane_state->base.visible));
12041 DRM_DEBUG_KMS("\trotation: 0x%x, scaler: %d\n",
12042 plane_state->base.rotation, plane_state->scaler_id);
12043 if (plane_state->base.visible)
12044 DRM_DEBUG_KMS("\tsrc: " DRM_RECT_FP_FMT " dst: " DRM_RECT_FMT "\n",
12045 DRM_RECT_FP_ARG(&plane_state->base.src),
12046 DRM_RECT_ARG(&plane_state->base.dst));
12049 static void intel_dump_pipe_config(const struct intel_crtc_state *pipe_config,
12050 struct intel_atomic_state *state,
12051 const char *context)
12053 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
12054 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12055 const struct intel_plane_state *plane_state;
12056 struct intel_plane *plane;
12060 DRM_DEBUG_KMS("[CRTC:%d:%s] enable: %s %s\n",
12061 crtc->base.base.id, crtc->base.name,
12062 yesno(pipe_config->base.enable), context);
12064 if (!pipe_config->base.enable)
12067 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
12068 DRM_DEBUG_KMS("active: %s, output_types: %s (0x%x), output format: %s\n",
12069 yesno(pipe_config->base.active),
12070 buf, pipe_config->output_types,
12071 output_formats(pipe_config->output_format));
12073 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
12074 transcoder_name(pipe_config->cpu_transcoder),
12075 pipe_config->pipe_bpp, pipe_config->dither);
12077 if (pipe_config->has_pch_encoder)
12078 intel_dump_m_n_config(pipe_config, "fdi",
12079 pipe_config->fdi_lanes,
12080 &pipe_config->fdi_m_n);
12082 if (intel_crtc_has_dp_encoder(pipe_config)) {
12083 intel_dump_m_n_config(pipe_config, "dp m_n",
12084 pipe_config->lane_count, &pipe_config->dp_m_n);
12085 if (pipe_config->has_drrs)
12086 intel_dump_m_n_config(pipe_config, "dp m2_n2",
12087 pipe_config->lane_count,
12088 &pipe_config->dp_m2_n2);
12091 DRM_DEBUG_KMS("audio: %i, infoframes: %i, infoframes enabled: 0x%x\n",
12092 pipe_config->has_audio, pipe_config->has_infoframe,
12093 pipe_config->infoframes.enable);
12095 if (pipe_config->infoframes.enable &
12096 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GENERAL_CONTROL))
12097 DRM_DEBUG_KMS("GCP: 0x%x\n", pipe_config->infoframes.gcp);
12098 if (pipe_config->infoframes.enable &
12099 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI))
12100 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.avi);
12101 if (pipe_config->infoframes.enable &
12102 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_SPD))
12103 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.spd);
12104 if (pipe_config->infoframes.enable &
12105 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_VENDOR))
12106 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.hdmi);
12108 DRM_DEBUG_KMS("requested mode:\n");
12109 drm_mode_debug_printmodeline(&pipe_config->base.mode);
12110 DRM_DEBUG_KMS("adjusted mode:\n");
12111 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
12112 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
12113 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
12114 pipe_config->port_clock,
12115 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
12116 pipe_config->pixel_rate);
12118 if (INTEL_GEN(dev_priv) >= 9)
12119 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
12121 pipe_config->scaler_state.scaler_users,
12122 pipe_config->scaler_state.scaler_id);
12124 if (HAS_GMCH(dev_priv))
12125 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
12126 pipe_config->gmch_pfit.control,
12127 pipe_config->gmch_pfit.pgm_ratios,
12128 pipe_config->gmch_pfit.lvds_border_bits);
12130 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s, force thru: %s\n",
12131 pipe_config->pch_pfit.pos,
12132 pipe_config->pch_pfit.size,
12133 enableddisabled(pipe_config->pch_pfit.enabled),
12134 yesno(pipe_config->pch_pfit.force_thru));
12136 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
12137 pipe_config->ips_enabled, pipe_config->double_wide);
12139 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
12145 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12146 if (plane->pipe == crtc->pipe)
12147 intel_dump_plane_state(plane_state);
12151 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
12153 struct drm_device *dev = state->base.dev;
12154 struct drm_connector *connector;
12155 struct drm_connector_list_iter conn_iter;
12156 unsigned int used_ports = 0;
12157 unsigned int used_mst_ports = 0;
12161 * Walk the connector list instead of the encoder
12162 * list to detect the problem on ddi platforms
12163 * where there's just one encoder per digital port.
12165 drm_connector_list_iter_begin(dev, &conn_iter);
12166 drm_for_each_connector_iter(connector, &conn_iter) {
12167 struct drm_connector_state *connector_state;
12168 struct intel_encoder *encoder;
12171 drm_atomic_get_new_connector_state(&state->base,
12173 if (!connector_state)
12174 connector_state = connector->state;
12176 if (!connector_state->best_encoder)
12179 encoder = to_intel_encoder(connector_state->best_encoder);
12181 WARN_ON(!connector_state->crtc);
12183 switch (encoder->type) {
12184 unsigned int port_mask;
12185 case INTEL_OUTPUT_DDI:
12186 if (WARN_ON(!HAS_DDI(to_i915(dev))))
12188 /* else, fall through */
12189 case INTEL_OUTPUT_DP:
12190 case INTEL_OUTPUT_HDMI:
12191 case INTEL_OUTPUT_EDP:
12192 port_mask = 1 << encoder->port;
12194 /* the same port mustn't appear more than once */
12195 if (used_ports & port_mask)
12198 used_ports |= port_mask;
12200 case INTEL_OUTPUT_DP_MST:
12202 1 << encoder->port;
12208 drm_connector_list_iter_end(&conn_iter);
12210 /* can't mix MST and SST/HDMI on the same port */
12211 if (used_ports & used_mst_ports)
12218 clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
12220 struct drm_i915_private *dev_priv =
12221 to_i915(crtc_state->base.crtc->dev);
12222 struct intel_crtc_state *saved_state;
12224 saved_state = kzalloc(sizeof(*saved_state), GFP_KERNEL);
12228 /* FIXME: before the switch to atomic started, a new pipe_config was
12229 * kzalloc'd. Code that depends on any field being zero should be
12230 * fixed, so that the crtc_state can be safely duplicated. For now,
12231 * only fields that are know to not cause problems are preserved. */
12233 saved_state->scaler_state = crtc_state->scaler_state;
12234 saved_state->shared_dpll = crtc_state->shared_dpll;
12235 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
12236 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
12237 sizeof(saved_state->icl_port_dplls));
12238 saved_state->crc_enabled = crtc_state->crc_enabled;
12239 if (IS_G4X(dev_priv) ||
12240 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
12241 saved_state->wm = crtc_state->wm;
12243 /* Keep base drm_crtc_state intact, only clear our extended struct */
12244 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
12245 memcpy(&crtc_state->base + 1, &saved_state->base + 1,
12246 sizeof(*crtc_state) - sizeof(crtc_state->base));
12248 kfree(saved_state);
12253 intel_modeset_pipe_config(struct intel_crtc_state *pipe_config)
12255 struct drm_crtc *crtc = pipe_config->base.crtc;
12256 struct drm_atomic_state *state = pipe_config->base.state;
12257 struct intel_encoder *encoder;
12258 struct drm_connector *connector;
12259 struct drm_connector_state *connector_state;
12264 ret = clear_intel_crtc_state(pipe_config);
12268 pipe_config->cpu_transcoder =
12269 (enum transcoder) to_intel_crtc(crtc)->pipe;
12272 * Sanitize sync polarity flags based on requested ones. If neither
12273 * positive or negative polarity is requested, treat this as meaning
12274 * negative polarity.
12276 if (!(pipe_config->base.adjusted_mode.flags &
12277 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
12278 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
12280 if (!(pipe_config->base.adjusted_mode.flags &
12281 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
12282 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
12284 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
12289 base_bpp = pipe_config->pipe_bpp;
12292 * Determine the real pipe dimensions. Note that stereo modes can
12293 * increase the actual pipe size due to the frame doubling and
12294 * insertion of additional space for blanks between the frame. This
12295 * is stored in the crtc timings. We use the requested mode to do this
12296 * computation to clearly distinguish it from the adjusted mode, which
12297 * can be changed by the connectors in the below retry loop.
12299 drm_mode_get_hv_timing(&pipe_config->base.mode,
12300 &pipe_config->pipe_src_w,
12301 &pipe_config->pipe_src_h);
12303 for_each_new_connector_in_state(state, connector, connector_state, i) {
12304 if (connector_state->crtc != crtc)
12307 encoder = to_intel_encoder(connector_state->best_encoder);
12309 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
12310 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
12315 * Determine output_types before calling the .compute_config()
12316 * hooks so that the hooks can use this information safely.
12318 if (encoder->compute_output_type)
12319 pipe_config->output_types |=
12320 BIT(encoder->compute_output_type(encoder, pipe_config,
12323 pipe_config->output_types |= BIT(encoder->type);
12327 /* Ensure the port clock defaults are reset when retrying. */
12328 pipe_config->port_clock = 0;
12329 pipe_config->pixel_multiplier = 1;
12331 /* Fill in default crtc timings, allow encoders to overwrite them. */
12332 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
12333 CRTC_STEREO_DOUBLE);
12335 /* Pass our mode to the connectors and the CRTC to give them a chance to
12336 * adjust it according to limitations or connector properties, and also
12337 * a chance to reject the mode entirely.
12339 for_each_new_connector_in_state(state, connector, connector_state, i) {
12340 if (connector_state->crtc != crtc)
12343 encoder = to_intel_encoder(connector_state->best_encoder);
12344 ret = encoder->compute_config(encoder, pipe_config,
12347 if (ret != -EDEADLK)
12348 DRM_DEBUG_KMS("Encoder config failure: %d\n",
12354 /* Set default port clock if not overwritten by the encoder. Needs to be
12355 * done afterwards in case the encoder adjusts the mode. */
12356 if (!pipe_config->port_clock)
12357 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
12358 * pipe_config->pixel_multiplier;
12360 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
12361 if (ret == -EDEADLK)
12364 DRM_DEBUG_KMS("CRTC fixup failed\n");
12368 if (ret == RETRY) {
12369 if (WARN(!retry, "loop in pipe configuration computation\n"))
12372 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
12374 goto encoder_retry;
12377 /* Dithering seems to not pass-through bits correctly when it should, so
12378 * only enable it on 6bpc panels and when its not a compliance
12379 * test requesting 6bpc video pattern.
12381 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
12382 !pipe_config->dither_force_disable;
12383 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
12384 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
12389 bool intel_fuzzy_clock_check(int clock1, int clock2)
12393 if (clock1 == clock2)
12396 if (!clock1 || !clock2)
12399 diff = abs(clock1 - clock2);
12401 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
12408 intel_compare_m_n(unsigned int m, unsigned int n,
12409 unsigned int m2, unsigned int n2,
12412 if (m == m2 && n == n2)
12415 if (exact || !m || !n || !m2 || !n2)
12418 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
12425 } else if (n < n2) {
12435 return intel_fuzzy_clock_check(m, m2);
12439 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
12440 const struct intel_link_m_n *m2_n2,
12443 return m_n->tu == m2_n2->tu &&
12444 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
12445 m2_n2->gmch_m, m2_n2->gmch_n, exact) &&
12446 intel_compare_m_n(m_n->link_m, m_n->link_n,
12447 m2_n2->link_m, m2_n2->link_n, exact);
12451 intel_compare_infoframe(const union hdmi_infoframe *a,
12452 const union hdmi_infoframe *b)
12454 return memcmp(a, b, sizeof(*a)) == 0;
12458 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
12459 bool fastset, const char *name,
12460 const union hdmi_infoframe *a,
12461 const union hdmi_infoframe *b)
12464 if ((drm_debug & DRM_UT_KMS) == 0)
12467 drm_dbg(DRM_UT_KMS, "fastset mismatch in %s infoframe", name);
12468 drm_dbg(DRM_UT_KMS, "expected:");
12469 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
12470 drm_dbg(DRM_UT_KMS, "found");
12471 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
12473 drm_err("mismatch in %s infoframe", name);
12474 drm_err("expected:");
12475 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
12477 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
12481 static void __printf(3, 4)
12482 pipe_config_mismatch(bool fastset, const char *name, const char *format, ...)
12484 struct va_format vaf;
12487 va_start(args, format);
12492 drm_dbg(DRM_UT_KMS, "fastset mismatch in %s %pV", name, &vaf);
12494 drm_err("mismatch in %s %pV", name, &vaf);
12499 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
12501 if (i915_modparams.fastboot != -1)
12502 return i915_modparams.fastboot;
12504 /* Enable fastboot by default on Skylake and newer */
12505 if (INTEL_GEN(dev_priv) >= 9)
12508 /* Enable fastboot by default on VLV and CHV */
12509 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
12512 /* Disabled by default on all others */
12517 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
12518 const struct intel_crtc_state *pipe_config,
12521 struct drm_i915_private *dev_priv = to_i915(current_config->base.crtc->dev);
12523 bool fixup_inherited = fastset &&
12524 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
12525 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
12527 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
12528 DRM_DEBUG_KMS("initial modeset and fastboot not set\n");
12532 #define PIPE_CONF_CHECK_X(name) do { \
12533 if (current_config->name != pipe_config->name) { \
12534 pipe_config_mismatch(fastset, __stringify(name), \
12535 "(expected 0x%08x, found 0x%08x)\n", \
12536 current_config->name, \
12537 pipe_config->name); \
12542 #define PIPE_CONF_CHECK_I(name) do { \
12543 if (current_config->name != pipe_config->name) { \
12544 pipe_config_mismatch(fastset, __stringify(name), \
12545 "(expected %i, found %i)\n", \
12546 current_config->name, \
12547 pipe_config->name); \
12552 #define PIPE_CONF_CHECK_BOOL(name) do { \
12553 if (current_config->name != pipe_config->name) { \
12554 pipe_config_mismatch(fastset, __stringify(name), \
12555 "(expected %s, found %s)\n", \
12556 yesno(current_config->name), \
12557 yesno(pipe_config->name)); \
12563 * Checks state where we only read out the enabling, but not the entire
12564 * state itself (like full infoframes or ELD for audio). These states
12565 * require a full modeset on bootup to fix up.
12567 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
12568 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
12569 PIPE_CONF_CHECK_BOOL(name); \
12571 pipe_config_mismatch(fastset, __stringify(name), \
12572 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
12573 yesno(current_config->name), \
12574 yesno(pipe_config->name)); \
12579 #define PIPE_CONF_CHECK_P(name) do { \
12580 if (current_config->name != pipe_config->name) { \
12581 pipe_config_mismatch(fastset, __stringify(name), \
12582 "(expected %p, found %p)\n", \
12583 current_config->name, \
12584 pipe_config->name); \
12589 #define PIPE_CONF_CHECK_M_N(name) do { \
12590 if (!intel_compare_link_m_n(¤t_config->name, \
12591 &pipe_config->name,\
12593 pipe_config_mismatch(fastset, __stringify(name), \
12594 "(expected tu %i gmch %i/%i link %i/%i, " \
12595 "found tu %i, gmch %i/%i link %i/%i)\n", \
12596 current_config->name.tu, \
12597 current_config->name.gmch_m, \
12598 current_config->name.gmch_n, \
12599 current_config->name.link_m, \
12600 current_config->name.link_n, \
12601 pipe_config->name.tu, \
12602 pipe_config->name.gmch_m, \
12603 pipe_config->name.gmch_n, \
12604 pipe_config->name.link_m, \
12605 pipe_config->name.link_n); \
12610 /* This is required for BDW+ where there is only one set of registers for
12611 * switching between high and low RR.
12612 * This macro can be used whenever a comparison has to be made between one
12613 * hw state and multiple sw state variables.
12615 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
12616 if (!intel_compare_link_m_n(¤t_config->name, \
12617 &pipe_config->name, !fastset) && \
12618 !intel_compare_link_m_n(¤t_config->alt_name, \
12619 &pipe_config->name, !fastset)) { \
12620 pipe_config_mismatch(fastset, __stringify(name), \
12621 "(expected tu %i gmch %i/%i link %i/%i, " \
12622 "or tu %i gmch %i/%i link %i/%i, " \
12623 "found tu %i, gmch %i/%i link %i/%i)\n", \
12624 current_config->name.tu, \
12625 current_config->name.gmch_m, \
12626 current_config->name.gmch_n, \
12627 current_config->name.link_m, \
12628 current_config->name.link_n, \
12629 current_config->alt_name.tu, \
12630 current_config->alt_name.gmch_m, \
12631 current_config->alt_name.gmch_n, \
12632 current_config->alt_name.link_m, \
12633 current_config->alt_name.link_n, \
12634 pipe_config->name.tu, \
12635 pipe_config->name.gmch_m, \
12636 pipe_config->name.gmch_n, \
12637 pipe_config->name.link_m, \
12638 pipe_config->name.link_n); \
12643 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
12644 if ((current_config->name ^ pipe_config->name) & (mask)) { \
12645 pipe_config_mismatch(fastset, __stringify(name), \
12646 "(%x) (expected %i, found %i)\n", \
12648 current_config->name & (mask), \
12649 pipe_config->name & (mask)); \
12654 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
12655 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
12656 pipe_config_mismatch(fastset, __stringify(name), \
12657 "(expected %i, found %i)\n", \
12658 current_config->name, \
12659 pipe_config->name); \
12664 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
12665 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
12666 &pipe_config->infoframes.name)) { \
12667 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
12668 ¤t_config->infoframes.name, \
12669 &pipe_config->infoframes.name); \
12674 #define PIPE_CONF_QUIRK(quirk) \
12675 ((current_config->quirks | pipe_config->quirks) & (quirk))
12677 PIPE_CONF_CHECK_I(cpu_transcoder);
12679 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
12680 PIPE_CONF_CHECK_I(fdi_lanes);
12681 PIPE_CONF_CHECK_M_N(fdi_m_n);
12683 PIPE_CONF_CHECK_I(lane_count);
12684 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
12686 if (INTEL_GEN(dev_priv) < 8) {
12687 PIPE_CONF_CHECK_M_N(dp_m_n);
12689 if (current_config->has_drrs)
12690 PIPE_CONF_CHECK_M_N(dp_m2_n2);
12692 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
12694 PIPE_CONF_CHECK_X(output_types);
12696 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
12697 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
12698 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
12699 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
12700 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
12701 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
12703 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
12704 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
12705 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
12706 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
12707 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
12708 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
12710 PIPE_CONF_CHECK_I(pixel_multiplier);
12711 PIPE_CONF_CHECK_I(output_format);
12712 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
12713 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
12714 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
12715 PIPE_CONF_CHECK_BOOL(limited_color_range);
12717 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
12718 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
12719 PIPE_CONF_CHECK_BOOL(has_infoframe);
12721 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
12723 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12724 DRM_MODE_FLAG_INTERLACE);
12726 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
12727 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12728 DRM_MODE_FLAG_PHSYNC);
12729 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12730 DRM_MODE_FLAG_NHSYNC);
12731 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12732 DRM_MODE_FLAG_PVSYNC);
12733 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12734 DRM_MODE_FLAG_NVSYNC);
12737 PIPE_CONF_CHECK_X(gmch_pfit.control);
12738 /* pfit ratios are autocomputed by the hw on gen4+ */
12739 if (INTEL_GEN(dev_priv) < 4)
12740 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
12741 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
12744 * Changing the EDP transcoder input mux
12745 * (A_ONOFF vs. A_ON) requires a full modeset.
12747 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
12750 PIPE_CONF_CHECK_I(pipe_src_w);
12751 PIPE_CONF_CHECK_I(pipe_src_h);
12753 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
12754 if (current_config->pch_pfit.enabled) {
12755 PIPE_CONF_CHECK_X(pch_pfit.pos);
12756 PIPE_CONF_CHECK_X(pch_pfit.size);
12759 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
12760 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
12762 PIPE_CONF_CHECK_X(gamma_mode);
12763 if (IS_CHERRYVIEW(dev_priv))
12764 PIPE_CONF_CHECK_X(cgm_mode);
12766 PIPE_CONF_CHECK_X(csc_mode);
12767 PIPE_CONF_CHECK_BOOL(gamma_enable);
12768 PIPE_CONF_CHECK_BOOL(csc_enable);
12771 PIPE_CONF_CHECK_BOOL(double_wide);
12773 PIPE_CONF_CHECK_P(shared_dpll);
12774 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
12775 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
12776 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
12777 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
12778 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
12779 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
12780 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
12781 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
12782 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
12783 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
12784 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
12785 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
12786 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
12787 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
12788 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
12789 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
12790 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
12791 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
12792 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
12793 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
12794 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
12795 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
12796 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
12797 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
12798 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
12799 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
12800 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
12801 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
12802 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
12803 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
12804 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
12806 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
12807 PIPE_CONF_CHECK_X(dsi_pll.div);
12809 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
12810 PIPE_CONF_CHECK_I(pipe_bpp);
12812 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
12813 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
12815 PIPE_CONF_CHECK_I(min_voltage_level);
12817 PIPE_CONF_CHECK_X(infoframes.enable);
12818 PIPE_CONF_CHECK_X(infoframes.gcp);
12819 PIPE_CONF_CHECK_INFOFRAME(avi);
12820 PIPE_CONF_CHECK_INFOFRAME(spd);
12821 PIPE_CONF_CHECK_INFOFRAME(hdmi);
12822 PIPE_CONF_CHECK_INFOFRAME(drm);
12824 #undef PIPE_CONF_CHECK_X
12825 #undef PIPE_CONF_CHECK_I
12826 #undef PIPE_CONF_CHECK_BOOL
12827 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
12828 #undef PIPE_CONF_CHECK_P
12829 #undef PIPE_CONF_CHECK_FLAGS
12830 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
12831 #undef PIPE_CONF_QUIRK
12836 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
12837 const struct intel_crtc_state *pipe_config)
12839 if (pipe_config->has_pch_encoder) {
12840 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
12841 &pipe_config->fdi_m_n);
12842 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
12845 * FDI already provided one idea for the dotclock.
12846 * Yell if the encoder disagrees.
12848 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
12849 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
12850 fdi_dotclock, dotclock);
12854 static void verify_wm_state(struct intel_crtc *crtc,
12855 struct intel_crtc_state *new_crtc_state)
12857 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12858 struct skl_hw_state {
12859 struct skl_ddb_entry ddb_y[I915_MAX_PLANES];
12860 struct skl_ddb_entry ddb_uv[I915_MAX_PLANES];
12861 struct skl_ddb_allocation ddb;
12862 struct skl_pipe_wm wm;
12864 struct skl_ddb_allocation *sw_ddb;
12865 struct skl_pipe_wm *sw_wm;
12866 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
12867 const enum pipe pipe = crtc->pipe;
12868 int plane, level, max_level = ilk_wm_max_level(dev_priv);
12870 if (INTEL_GEN(dev_priv) < 9 || !new_crtc_state->base.active)
12873 hw = kzalloc(sizeof(*hw), GFP_KERNEL);
12877 skl_pipe_wm_get_hw_state(crtc, &hw->wm);
12878 sw_wm = &new_crtc_state->wm.skl.optimal;
12880 skl_pipe_ddb_get_hw_state(crtc, hw->ddb_y, hw->ddb_uv);
12882 skl_ddb_get_hw_state(dev_priv, &hw->ddb);
12883 sw_ddb = &dev_priv->wm.skl_hw.ddb;
12885 if (INTEL_GEN(dev_priv) >= 11 &&
12886 hw->ddb.enabled_slices != sw_ddb->enabled_slices)
12887 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
12888 sw_ddb->enabled_slices,
12889 hw->ddb.enabled_slices);
12892 for_each_universal_plane(dev_priv, pipe, plane) {
12893 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
12895 hw_plane_wm = &hw->wm.planes[plane];
12896 sw_plane_wm = &sw_wm->planes[plane];
12899 for (level = 0; level <= max_level; level++) {
12900 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
12901 &sw_plane_wm->wm[level]))
12904 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",
12905 pipe_name(pipe), plane + 1, level,
12906 sw_plane_wm->wm[level].plane_en,
12907 sw_plane_wm->wm[level].plane_res_b,
12908 sw_plane_wm->wm[level].plane_res_l,
12909 hw_plane_wm->wm[level].plane_en,
12910 hw_plane_wm->wm[level].plane_res_b,
12911 hw_plane_wm->wm[level].plane_res_l);
12914 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12915 &sw_plane_wm->trans_wm)) {
12916 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",
12917 pipe_name(pipe), plane + 1,
12918 sw_plane_wm->trans_wm.plane_en,
12919 sw_plane_wm->trans_wm.plane_res_b,
12920 sw_plane_wm->trans_wm.plane_res_l,
12921 hw_plane_wm->trans_wm.plane_en,
12922 hw_plane_wm->trans_wm.plane_res_b,
12923 hw_plane_wm->trans_wm.plane_res_l);
12927 hw_ddb_entry = &hw->ddb_y[plane];
12928 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[plane];
12930 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
12931 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
12932 pipe_name(pipe), plane + 1,
12933 sw_ddb_entry->start, sw_ddb_entry->end,
12934 hw_ddb_entry->start, hw_ddb_entry->end);
12940 * If the cursor plane isn't active, we may not have updated it's ddb
12941 * allocation. In that case since the ddb allocation will be updated
12942 * once the plane becomes visible, we can skip this check
12945 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
12947 hw_plane_wm = &hw->wm.planes[PLANE_CURSOR];
12948 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
12951 for (level = 0; level <= max_level; level++) {
12952 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
12953 &sw_plane_wm->wm[level]))
12956 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",
12957 pipe_name(pipe), level,
12958 sw_plane_wm->wm[level].plane_en,
12959 sw_plane_wm->wm[level].plane_res_b,
12960 sw_plane_wm->wm[level].plane_res_l,
12961 hw_plane_wm->wm[level].plane_en,
12962 hw_plane_wm->wm[level].plane_res_b,
12963 hw_plane_wm->wm[level].plane_res_l);
12966 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12967 &sw_plane_wm->trans_wm)) {
12968 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
12970 sw_plane_wm->trans_wm.plane_en,
12971 sw_plane_wm->trans_wm.plane_res_b,
12972 sw_plane_wm->trans_wm.plane_res_l,
12973 hw_plane_wm->trans_wm.plane_en,
12974 hw_plane_wm->trans_wm.plane_res_b,
12975 hw_plane_wm->trans_wm.plane_res_l);
12979 hw_ddb_entry = &hw->ddb_y[PLANE_CURSOR];
12980 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR];
12982 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
12983 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
12985 sw_ddb_entry->start, sw_ddb_entry->end,
12986 hw_ddb_entry->start, hw_ddb_entry->end);
12994 verify_connector_state(struct intel_atomic_state *state,
12995 struct intel_crtc *crtc)
12997 struct drm_connector *connector;
12998 struct drm_connector_state *new_conn_state;
13001 for_each_new_connector_in_state(&state->base, connector, new_conn_state, i) {
13002 struct drm_encoder *encoder = connector->encoder;
13003 struct intel_crtc_state *crtc_state = NULL;
13005 if (new_conn_state->crtc != &crtc->base)
13009 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
13011 intel_connector_verify_state(crtc_state, new_conn_state);
13013 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
13014 "connector's atomic encoder doesn't match legacy encoder\n");
13019 verify_encoder_state(struct drm_i915_private *dev_priv, struct intel_atomic_state *state)
13021 struct intel_encoder *encoder;
13022 struct drm_connector *connector;
13023 struct drm_connector_state *old_conn_state, *new_conn_state;
13026 for_each_intel_encoder(&dev_priv->drm, encoder) {
13027 bool enabled = false, found = false;
13030 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
13031 encoder->base.base.id,
13032 encoder->base.name);
13034 for_each_oldnew_connector_in_state(&state->base, connector, old_conn_state,
13035 new_conn_state, i) {
13036 if (old_conn_state->best_encoder == &encoder->base)
13039 if (new_conn_state->best_encoder != &encoder->base)
13041 found = enabled = true;
13043 I915_STATE_WARN(new_conn_state->crtc !=
13044 encoder->base.crtc,
13045 "connector's crtc doesn't match encoder crtc\n");
13051 I915_STATE_WARN(!!encoder->base.crtc != enabled,
13052 "encoder's enabled state mismatch "
13053 "(expected %i, found %i)\n",
13054 !!encoder->base.crtc, enabled);
13056 if (!encoder->base.crtc) {
13059 active = encoder->get_hw_state(encoder, &pipe);
13060 I915_STATE_WARN(active,
13061 "encoder detached but still enabled on pipe %c.\n",
13068 verify_crtc_state(struct intel_crtc *crtc,
13069 struct intel_crtc_state *old_crtc_state,
13070 struct intel_crtc_state *new_crtc_state)
13072 struct drm_device *dev = crtc->base.dev;
13073 struct drm_i915_private *dev_priv = to_i915(dev);
13074 struct intel_encoder *encoder;
13075 struct intel_crtc_state *pipe_config;
13076 struct drm_atomic_state *state;
13079 state = old_crtc_state->base.state;
13080 __drm_atomic_helper_crtc_destroy_state(&old_crtc_state->base);
13081 pipe_config = old_crtc_state;
13082 memset(pipe_config, 0, sizeof(*pipe_config));
13083 pipe_config->base.crtc = &crtc->base;
13084 pipe_config->base.state = state;
13086 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.base.id, crtc->base.name);
13088 active = dev_priv->display.get_pipe_config(crtc, pipe_config);
13090 /* we keep both pipes enabled on 830 */
13091 if (IS_I830(dev_priv))
13092 active = new_crtc_state->base.active;
13094 I915_STATE_WARN(new_crtc_state->base.active != active,
13095 "crtc active state doesn't match with hw state "
13096 "(expected %i, found %i)\n", new_crtc_state->base.active, active);
13098 I915_STATE_WARN(crtc->active != new_crtc_state->base.active,
13099 "transitional active state does not match atomic hw state "
13100 "(expected %i, found %i)\n", new_crtc_state->base.active, crtc->active);
13102 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
13105 active = encoder->get_hw_state(encoder, &pipe);
13106 I915_STATE_WARN(active != new_crtc_state->base.active,
13107 "[ENCODER:%i] active %i with crtc active %i\n",
13108 encoder->base.base.id, active, new_crtc_state->base.active);
13110 I915_STATE_WARN(active && crtc->pipe != pipe,
13111 "Encoder connected to wrong pipe %c\n",
13115 encoder->get_config(encoder, pipe_config);
13118 intel_crtc_compute_pixel_rate(pipe_config);
13120 if (!new_crtc_state->base.active)
13123 intel_pipe_config_sanity_check(dev_priv, pipe_config);
13125 if (!intel_pipe_config_compare(new_crtc_state,
13126 pipe_config, false)) {
13127 I915_STATE_WARN(1, "pipe state doesn't match!\n");
13128 intel_dump_pipe_config(pipe_config, NULL, "[hw state]");
13129 intel_dump_pipe_config(new_crtc_state, NULL, "[sw state]");
13134 intel_verify_planes(struct intel_atomic_state *state)
13136 struct intel_plane *plane;
13137 const struct intel_plane_state *plane_state;
13140 for_each_new_intel_plane_in_state(state, plane,
13142 assert_plane(plane, plane_state->slave ||
13143 plane_state->base.visible);
13147 verify_single_dpll_state(struct drm_i915_private *dev_priv,
13148 struct intel_shared_dpll *pll,
13149 struct intel_crtc *crtc,
13150 struct intel_crtc_state *new_crtc_state)
13152 struct intel_dpll_hw_state dpll_hw_state;
13153 unsigned int crtc_mask;
13156 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
13158 DRM_DEBUG_KMS("%s\n", pll->info->name);
13160 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
13162 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
13163 I915_STATE_WARN(!pll->on && pll->active_mask,
13164 "pll in active use but not on in sw tracking\n");
13165 I915_STATE_WARN(pll->on && !pll->active_mask,
13166 "pll is on but not used by any active crtc\n");
13167 I915_STATE_WARN(pll->on != active,
13168 "pll on state mismatch (expected %i, found %i)\n",
13173 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
13174 "more active pll users than references: %x vs %x\n",
13175 pll->active_mask, pll->state.crtc_mask);
13180 crtc_mask = drm_crtc_mask(&crtc->base);
13182 if (new_crtc_state->base.active)
13183 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
13184 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
13185 pipe_name(drm_crtc_index(&crtc->base)), pll->active_mask);
13187 I915_STATE_WARN(pll->active_mask & crtc_mask,
13188 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
13189 pipe_name(drm_crtc_index(&crtc->base)), pll->active_mask);
13191 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
13192 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
13193 crtc_mask, pll->state.crtc_mask);
13195 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
13197 sizeof(dpll_hw_state)),
13198 "pll hw state mismatch\n");
13202 verify_shared_dpll_state(struct intel_crtc *crtc,
13203 struct intel_crtc_state *old_crtc_state,
13204 struct intel_crtc_state *new_crtc_state)
13206 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13208 if (new_crtc_state->shared_dpll)
13209 verify_single_dpll_state(dev_priv, new_crtc_state->shared_dpll, crtc, new_crtc_state);
13211 if (old_crtc_state->shared_dpll &&
13212 old_crtc_state->shared_dpll != new_crtc_state->shared_dpll) {
13213 unsigned int crtc_mask = drm_crtc_mask(&crtc->base);
13214 struct intel_shared_dpll *pll = old_crtc_state->shared_dpll;
13216 I915_STATE_WARN(pll->active_mask & crtc_mask,
13217 "pll active mismatch (didn't expect pipe %c in active mask)\n",
13218 pipe_name(drm_crtc_index(&crtc->base)));
13219 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
13220 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
13221 pipe_name(drm_crtc_index(&crtc->base)));
13226 intel_modeset_verify_crtc(struct intel_crtc *crtc,
13227 struct intel_atomic_state *state,
13228 struct intel_crtc_state *old_crtc_state,
13229 struct intel_crtc_state *new_crtc_state)
13231 if (!needs_modeset(new_crtc_state) && !new_crtc_state->update_pipe)
13234 verify_wm_state(crtc, new_crtc_state);
13235 verify_connector_state(state, crtc);
13236 verify_crtc_state(crtc, old_crtc_state, new_crtc_state);
13237 verify_shared_dpll_state(crtc, old_crtc_state, new_crtc_state);
13241 verify_disabled_dpll_state(struct drm_i915_private *dev_priv)
13245 for (i = 0; i < dev_priv->num_shared_dpll; i++)
13246 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
13250 intel_modeset_verify_disabled(struct drm_i915_private *dev_priv,
13251 struct intel_atomic_state *state)
13253 verify_encoder_state(dev_priv, state);
13254 verify_connector_state(state, NULL);
13255 verify_disabled_dpll_state(dev_priv);
13258 static void update_scanline_offset(const struct intel_crtc_state *crtc_state)
13260 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
13261 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13264 * The scanline counter increments at the leading edge of hsync.
13266 * On most platforms it starts counting from vtotal-1 on the
13267 * first active line. That means the scanline counter value is
13268 * always one less than what we would expect. Ie. just after
13269 * start of vblank, which also occurs at start of hsync (on the
13270 * last active line), the scanline counter will read vblank_start-1.
13272 * On gen2 the scanline counter starts counting from 1 instead
13273 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
13274 * to keep the value positive), instead of adding one.
13276 * On HSW+ the behaviour of the scanline counter depends on the output
13277 * type. For DP ports it behaves like most other platforms, but on HDMI
13278 * there's an extra 1 line difference. So we need to add two instead of
13279 * one to the value.
13281 * On VLV/CHV DSI the scanline counter would appear to increment
13282 * approx. 1/3 of a scanline before start of vblank. Unfortunately
13283 * that means we can't tell whether we're in vblank or not while
13284 * we're on that particular line. We must still set scanline_offset
13285 * to 1 so that the vblank timestamps come out correct when we query
13286 * the scanline counter from within the vblank interrupt handler.
13287 * However if queried just before the start of vblank we'll get an
13288 * answer that's slightly in the future.
13290 if (IS_GEN(dev_priv, 2)) {
13291 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
13294 vtotal = adjusted_mode->crtc_vtotal;
13295 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
13298 crtc->scanline_offset = vtotal - 1;
13299 } else if (HAS_DDI(dev_priv) &&
13300 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
13301 crtc->scanline_offset = 2;
13303 crtc->scanline_offset = 1;
13306 static void intel_modeset_clear_plls(struct intel_atomic_state *state)
13308 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13309 struct intel_crtc_state *new_crtc_state;
13310 struct intel_crtc *crtc;
13313 if (!dev_priv->display.crtc_compute_clock)
13316 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
13317 if (!needs_modeset(new_crtc_state))
13320 intel_release_shared_dplls(state, crtc);
13325 * This implements the workaround described in the "notes" section of the mode
13326 * set sequence documentation. When going from no pipes or single pipe to
13327 * multiple pipes, and planes are enabled after the pipe, we need to wait at
13328 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
13330 static int haswell_mode_set_planes_workaround(struct intel_atomic_state *state)
13332 struct intel_crtc_state *crtc_state;
13333 struct intel_crtc *crtc;
13334 struct intel_crtc_state *first_crtc_state = NULL;
13335 struct intel_crtc_state *other_crtc_state = NULL;
13336 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
13339 /* look at all crtc's that are going to be enabled in during modeset */
13340 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
13341 if (!crtc_state->base.active ||
13342 !needs_modeset(crtc_state))
13345 if (first_crtc_state) {
13346 other_crtc_state = crtc_state;
13349 first_crtc_state = crtc_state;
13350 first_pipe = crtc->pipe;
13354 /* No workaround needed? */
13355 if (!first_crtc_state)
13358 /* w/a possibly needed, check how many crtc's are already enabled. */
13359 for_each_intel_crtc(state->base.dev, crtc) {
13360 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
13361 if (IS_ERR(crtc_state))
13362 return PTR_ERR(crtc_state);
13364 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
13366 if (!crtc_state->base.active ||
13367 needs_modeset(crtc_state))
13370 /* 2 or more enabled crtcs means no need for w/a */
13371 if (enabled_pipe != INVALID_PIPE)
13374 enabled_pipe = crtc->pipe;
13377 if (enabled_pipe != INVALID_PIPE)
13378 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
13379 else if (other_crtc_state)
13380 other_crtc_state->hsw_workaround_pipe = first_pipe;
13385 static int intel_lock_all_pipes(struct intel_atomic_state *state)
13387 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13388 struct intel_crtc *crtc;
13390 /* Add all pipes to the state */
13391 for_each_intel_crtc(&dev_priv->drm, crtc) {
13392 struct intel_crtc_state *crtc_state;
13394 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
13395 if (IS_ERR(crtc_state))
13396 return PTR_ERR(crtc_state);
13402 static int intel_modeset_all_pipes(struct intel_atomic_state *state)
13404 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13405 struct intel_crtc *crtc;
13408 * Add all pipes to the state, and force
13409 * a modeset on all the active ones.
13411 for_each_intel_crtc(&dev_priv->drm, crtc) {
13412 struct intel_crtc_state *crtc_state;
13415 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
13416 if (IS_ERR(crtc_state))
13417 return PTR_ERR(crtc_state);
13419 if (!crtc_state->base.active || needs_modeset(crtc_state))
13422 crtc_state->base.mode_changed = true;
13424 ret = drm_atomic_add_affected_connectors(&state->base,
13429 ret = drm_atomic_add_affected_planes(&state->base,
13438 static int intel_modeset_checks(struct intel_atomic_state *state)
13440 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13441 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13442 struct intel_crtc *crtc;
13445 if (!check_digital_port_conflicts(state)) {
13446 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
13450 /* keep the current setting */
13451 if (!state->cdclk.force_min_cdclk_changed)
13452 state->cdclk.force_min_cdclk = dev_priv->cdclk.force_min_cdclk;
13454 state->modeset = true;
13455 state->active_pipes = dev_priv->active_pipes;
13456 state->cdclk.logical = dev_priv->cdclk.logical;
13457 state->cdclk.actual = dev_priv->cdclk.actual;
13458 state->cdclk.pipe = INVALID_PIPE;
13460 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13461 new_crtc_state, i) {
13462 if (new_crtc_state->base.active)
13463 state->active_pipes |= BIT(crtc->pipe);
13465 state->active_pipes &= ~BIT(crtc->pipe);
13467 if (old_crtc_state->base.active != new_crtc_state->base.active)
13468 state->active_pipe_changes |= BIT(crtc->pipe);
13472 * See if the config requires any additional preparation, e.g.
13473 * to adjust global state with pipes off. We need to do this
13474 * here so we can get the modeset_pipe updated config for the new
13475 * mode set on this crtc. For other crtcs we need to use the
13476 * adjusted_mode bits in the crtc directly.
13478 if (dev_priv->display.modeset_calc_cdclk) {
13481 ret = dev_priv->display.modeset_calc_cdclk(state);
13486 * Writes to dev_priv->cdclk.logical must protected by
13487 * holding all the crtc locks, even if we don't end up
13488 * touching the hardware
13490 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
13491 &state->cdclk.logical)) {
13492 ret = intel_lock_all_pipes(state);
13497 if (is_power_of_2(state->active_pipes)) {
13498 struct intel_crtc *crtc;
13499 struct intel_crtc_state *crtc_state;
13501 pipe = ilog2(state->active_pipes);
13502 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
13503 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
13504 if (crtc_state && needs_modeset(crtc_state))
13505 pipe = INVALID_PIPE;
13507 pipe = INVALID_PIPE;
13510 /* All pipes must be switched off while we change the cdclk. */
13511 if (pipe != INVALID_PIPE &&
13512 intel_cdclk_needs_cd2x_update(dev_priv,
13513 &dev_priv->cdclk.actual,
13514 &state->cdclk.actual)) {
13515 ret = intel_lock_all_pipes(state);
13519 state->cdclk.pipe = pipe;
13520 } else if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
13521 &state->cdclk.actual)) {
13522 ret = intel_modeset_all_pipes(state);
13526 state->cdclk.pipe = INVALID_PIPE;
13529 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
13530 state->cdclk.logical.cdclk,
13531 state->cdclk.actual.cdclk);
13532 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
13533 state->cdclk.logical.voltage_level,
13534 state->cdclk.actual.voltage_level);
13537 intel_modeset_clear_plls(state);
13539 if (IS_HASWELL(dev_priv))
13540 return haswell_mode_set_planes_workaround(state);
13546 * Handle calculation of various watermark data at the end of the atomic check
13547 * phase. The code here should be run after the per-crtc and per-plane 'check'
13548 * handlers to ensure that all derived state has been updated.
13550 static int calc_watermark_data(struct intel_atomic_state *state)
13552 struct drm_device *dev = state->base.dev;
13553 struct drm_i915_private *dev_priv = to_i915(dev);
13555 /* Is there platform-specific watermark information to calculate? */
13556 if (dev_priv->display.compute_global_watermarks)
13557 return dev_priv->display.compute_global_watermarks(state);
13562 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
13563 struct intel_crtc_state *new_crtc_state)
13565 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
13568 new_crtc_state->base.mode_changed = false;
13569 new_crtc_state->update_pipe = true;
13572 * If we're not doing the full modeset we want to
13573 * keep the current M/N values as they may be
13574 * sufficiently different to the computed values
13575 * to cause problems.
13577 * FIXME: should really copy more fuzzy state here
13579 new_crtc_state->fdi_m_n = old_crtc_state->fdi_m_n;
13580 new_crtc_state->dp_m_n = old_crtc_state->dp_m_n;
13581 new_crtc_state->dp_m2_n2 = old_crtc_state->dp_m2_n2;
13582 new_crtc_state->has_drrs = old_crtc_state->has_drrs;
13586 * intel_atomic_check - validate state object
13588 * @_state: state to validate
13590 static int intel_atomic_check(struct drm_device *dev,
13591 struct drm_atomic_state *_state)
13593 struct drm_i915_private *dev_priv = to_i915(dev);
13594 struct intel_atomic_state *state = to_intel_atomic_state(_state);
13595 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13596 struct intel_crtc *crtc;
13598 bool any_ms = state->cdclk.force_min_cdclk_changed;
13600 /* Catch I915_MODE_FLAG_INHERITED */
13601 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13602 new_crtc_state, i) {
13603 if (new_crtc_state->base.mode.private_flags !=
13604 old_crtc_state->base.mode.private_flags)
13605 new_crtc_state->base.mode_changed = true;
13608 ret = drm_atomic_helper_check_modeset(dev, &state->base);
13612 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13613 new_crtc_state, i) {
13614 if (!needs_modeset(new_crtc_state))
13617 if (!new_crtc_state->base.enable) {
13622 ret = intel_modeset_pipe_config(new_crtc_state);
13626 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
13628 if (needs_modeset(new_crtc_state))
13632 ret = drm_dp_mst_atomic_check(&state->base);
13637 ret = intel_modeset_checks(state);
13641 state->cdclk.logical = dev_priv->cdclk.logical;
13644 ret = icl_add_linked_planes(state);
13648 ret = drm_atomic_helper_check_planes(dev, &state->base);
13652 intel_fbc_choose_crtc(dev_priv, state);
13653 ret = calc_watermark_data(state);
13657 ret = intel_bw_atomic_check(state);
13661 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13662 new_crtc_state, i) {
13663 if (!needs_modeset(new_crtc_state) &&
13664 !new_crtc_state->update_pipe)
13667 intel_dump_pipe_config(new_crtc_state, state,
13668 needs_modeset(new_crtc_state) ?
13669 "[modeset]" : "[fastset]");
13675 if (ret == -EDEADLK)
13679 * FIXME would probably be nice to know which crtc specifically
13680 * caused the failure, in cases where we can pinpoint it.
13682 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13684 intel_dump_pipe_config(new_crtc_state, state, "[failed]");
13689 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
13691 return drm_atomic_helper_prepare_planes(state->base.dev,
13695 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
13697 struct drm_device *dev = crtc->base.dev;
13698 struct drm_vblank_crtc *vblank = &dev->vblank[drm_crtc_index(&crtc->base)];
13700 if (!vblank->max_vblank_count)
13701 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
13703 return crtc->base.funcs->get_vblank_counter(&crtc->base);
13706 static void intel_update_crtc(struct intel_crtc *crtc,
13707 struct intel_atomic_state *state,
13708 struct intel_crtc_state *old_crtc_state,
13709 struct intel_crtc_state *new_crtc_state)
13711 struct drm_device *dev = state->base.dev;
13712 struct drm_i915_private *dev_priv = to_i915(dev);
13713 bool modeset = needs_modeset(new_crtc_state);
13714 struct intel_plane_state *new_plane_state =
13715 intel_atomic_get_new_plane_state(state,
13716 to_intel_plane(crtc->base.primary));
13719 update_scanline_offset(new_crtc_state);
13720 dev_priv->display.crtc_enable(new_crtc_state, state);
13722 /* vblanks work again, re-enable pipe CRC. */
13723 intel_crtc_enable_pipe_crc(crtc);
13725 intel_pre_plane_update(old_crtc_state, new_crtc_state);
13727 if (new_crtc_state->update_pipe)
13728 intel_encoders_update_pipe(crtc, new_crtc_state, state);
13731 if (new_crtc_state->update_pipe && !new_crtc_state->enable_fbc)
13732 intel_fbc_disable(crtc);
13733 else if (new_plane_state)
13734 intel_fbc_enable(crtc, new_crtc_state, new_plane_state);
13736 intel_begin_crtc_commit(state, crtc);
13738 if (INTEL_GEN(dev_priv) >= 9)
13739 skl_update_planes_on_crtc(state, crtc);
13741 i9xx_update_planes_on_crtc(state, crtc);
13743 intel_finish_crtc_commit(state, crtc);
13746 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
13748 struct intel_crtc *crtc;
13749 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13752 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13753 if (!new_crtc_state->base.active)
13756 intel_update_crtc(crtc, state, old_crtc_state,
13761 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
13763 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13764 struct intel_crtc *crtc;
13765 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13766 unsigned int updated = 0;
13770 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
13771 u8 required_slices = state->wm_results.ddb.enabled_slices;
13772 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
13774 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
13775 /* ignore allocations for crtc's that have been turned off. */
13776 if (new_crtc_state->base.active)
13777 entries[i] = old_crtc_state->wm.skl.ddb;
13779 /* If 2nd DBuf slice required, enable it here */
13780 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
13781 icl_dbuf_slices_update(dev_priv, required_slices);
13784 * Whenever the number of active pipes changes, we need to make sure we
13785 * update the pipes in the right order so that their ddb allocations
13786 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
13787 * cause pipe underruns and other bad stuff.
13792 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13793 bool vbl_wait = false;
13794 unsigned int cmask = drm_crtc_mask(&crtc->base);
13798 if (updated & cmask || !new_crtc_state->base.active)
13801 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
13803 INTEL_INFO(dev_priv)->num_pipes, i))
13807 entries[i] = new_crtc_state->wm.skl.ddb;
13810 * If this is an already active pipe, it's DDB changed,
13811 * and this isn't the last pipe that needs updating
13812 * then we need to wait for a vblank to pass for the
13813 * new ddb allocation to take effect.
13815 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
13816 &old_crtc_state->wm.skl.ddb) &&
13817 !new_crtc_state->base.active_changed &&
13818 state->wm_results.dirty_pipes != updated)
13821 intel_update_crtc(crtc, state, old_crtc_state,
13825 intel_wait_for_vblank(dev_priv, pipe);
13829 } while (progress);
13831 /* If 2nd DBuf slice is no more required disable it */
13832 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
13833 icl_dbuf_slices_update(dev_priv, required_slices);
13836 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
13838 struct intel_atomic_state *state, *next;
13839 struct llist_node *freed;
13841 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
13842 llist_for_each_entry_safe(state, next, freed, freed)
13843 drm_atomic_state_put(&state->base);
13846 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
13848 struct drm_i915_private *dev_priv =
13849 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
13851 intel_atomic_helper_free_state(dev_priv);
13854 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
13856 struct wait_queue_entry wait_fence, wait_reset;
13857 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
13859 init_wait_entry(&wait_fence, 0);
13860 init_wait_entry(&wait_reset, 0);
13862 prepare_to_wait(&intel_state->commit_ready.wait,
13863 &wait_fence, TASK_UNINTERRUPTIBLE);
13864 prepare_to_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
13865 I915_RESET_MODESET),
13866 &wait_reset, TASK_UNINTERRUPTIBLE);
13869 if (i915_sw_fence_done(&intel_state->commit_ready) ||
13870 test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
13875 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
13876 finish_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
13877 I915_RESET_MODESET),
13881 static void intel_atomic_cleanup_work(struct work_struct *work)
13883 struct drm_atomic_state *state =
13884 container_of(work, struct drm_atomic_state, commit_work);
13885 struct drm_i915_private *i915 = to_i915(state->dev);
13887 drm_atomic_helper_cleanup_planes(&i915->drm, state);
13888 drm_atomic_helper_commit_cleanup_done(state);
13889 drm_atomic_state_put(state);
13891 intel_atomic_helper_free_state(i915);
13894 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
13896 struct drm_device *dev = state->base.dev;
13897 struct drm_i915_private *dev_priv = to_i915(dev);
13898 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
13899 struct intel_crtc *crtc;
13900 u64 put_domains[I915_MAX_PIPES] = {};
13901 intel_wakeref_t wakeref = 0;
13904 intel_atomic_commit_fence_wait(state);
13906 drm_atomic_helper_wait_for_dependencies(&state->base);
13908 if (state->modeset)
13909 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
13912 * Disable CRTC/pipes in reverse order because some features(MST in
13913 * TGL+) requires master and slave relationship between pipes, so it
13914 * should always pick the lowest pipe as master as it will be enabled
13915 * first and disable in the reverse order so the master will be the
13916 * last one to be disabled.
13918 for_each_oldnew_intel_crtc_in_state_reverse(state, crtc, old_crtc_state,
13919 new_crtc_state, i) {
13920 if (needs_modeset(new_crtc_state) ||
13921 new_crtc_state->update_pipe) {
13923 put_domains[crtc->pipe] =
13924 modeset_get_crtc_power_domains(new_crtc_state);
13927 if (!needs_modeset(new_crtc_state))
13930 intel_pre_plane_update(old_crtc_state, new_crtc_state);
13932 if (old_crtc_state->base.active) {
13933 intel_crtc_disable_planes(state, crtc);
13936 * We need to disable pipe CRC before disabling the pipe,
13937 * or we race against vblank off.
13939 intel_crtc_disable_pipe_crc(crtc);
13941 dev_priv->display.crtc_disable(old_crtc_state, state);
13942 crtc->active = false;
13943 intel_fbc_disable(crtc);
13944 intel_disable_shared_dpll(old_crtc_state);
13947 * Underruns don't always raise
13948 * interrupts, so check manually.
13950 intel_check_cpu_fifo_underruns(dev_priv);
13951 intel_check_pch_fifo_underruns(dev_priv);
13953 /* FIXME unify this for all platforms */
13954 if (!new_crtc_state->base.active &&
13955 !HAS_GMCH(dev_priv) &&
13956 dev_priv->display.initial_watermarks)
13957 dev_priv->display.initial_watermarks(state,
13962 /* FIXME: Eventually get rid of our crtc->config pointer */
13963 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
13964 crtc->config = new_crtc_state;
13966 if (state->modeset) {
13967 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
13969 intel_set_cdclk_pre_plane_update(dev_priv,
13970 &state->cdclk.actual,
13971 &dev_priv->cdclk.actual,
13972 state->cdclk.pipe);
13975 * SKL workaround: bspec recommends we disable the SAGV when we
13976 * have more then one pipe enabled
13978 if (!intel_can_enable_sagv(state))
13979 intel_disable_sagv(dev_priv);
13981 intel_modeset_verify_disabled(dev_priv, state);
13984 /* Complete the events for pipes that have now been disabled */
13985 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
13986 bool modeset = needs_modeset(new_crtc_state);
13988 /* Complete events for now disable pipes here. */
13989 if (modeset && !new_crtc_state->base.active && new_crtc_state->base.event) {
13990 spin_lock_irq(&dev->event_lock);
13991 drm_crtc_send_vblank_event(&crtc->base, new_crtc_state->base.event);
13992 spin_unlock_irq(&dev->event_lock);
13994 new_crtc_state->base.event = NULL;
13998 if (state->modeset)
13999 intel_encoders_update_prepare(state);
14001 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
14002 dev_priv->display.commit_modeset_enables(state);
14004 if (state->modeset) {
14005 intel_encoders_update_complete(state);
14007 intel_set_cdclk_post_plane_update(dev_priv,
14008 &state->cdclk.actual,
14009 &dev_priv->cdclk.actual,
14010 state->cdclk.pipe);
14013 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
14014 * already, but still need the state for the delayed optimization. To
14016 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
14017 * - schedule that vblank worker _before_ calling hw_done
14018 * - at the start of commit_tail, cancel it _synchrously
14019 * - switch over to the vblank wait helper in the core after that since
14020 * we don't need out special handling any more.
14022 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
14024 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14025 if (new_crtc_state->base.active &&
14026 !needs_modeset(new_crtc_state) &&
14027 (new_crtc_state->base.color_mgmt_changed ||
14028 new_crtc_state->update_pipe))
14029 intel_color_load_luts(new_crtc_state);
14033 * Now that the vblank has passed, we can go ahead and program the
14034 * optimal watermarks on platforms that need two-step watermark
14037 * TODO: Move this (and other cleanup) to an async worker eventually.
14039 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14040 if (dev_priv->display.optimize_watermarks)
14041 dev_priv->display.optimize_watermarks(state,
14045 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
14046 intel_post_plane_update(old_crtc_state);
14048 if (put_domains[i])
14049 modeset_put_power_domains(dev_priv, put_domains[i]);
14051 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
14054 if (state->modeset)
14055 intel_verify_planes(state);
14057 if (state->modeset && intel_can_enable_sagv(state))
14058 intel_enable_sagv(dev_priv);
14060 drm_atomic_helper_commit_hw_done(&state->base);
14062 if (state->modeset) {
14063 /* As one of the primary mmio accessors, KMS has a high
14064 * likelihood of triggering bugs in unclaimed access. After we
14065 * finish modesetting, see if an error has been flagged, and if
14066 * so enable debugging for the next modeset - and hope we catch
14069 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
14070 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
14072 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
14075 * Defer the cleanup of the old state to a separate worker to not
14076 * impede the current task (userspace for blocking modesets) that
14077 * are executed inline. For out-of-line asynchronous modesets/flips,
14078 * deferring to a new worker seems overkill, but we would place a
14079 * schedule point (cond_resched()) here anyway to keep latencies
14082 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
14083 queue_work(system_highpri_wq, &state->base.commit_work);
14086 static void intel_atomic_commit_work(struct work_struct *work)
14088 struct intel_atomic_state *state =
14089 container_of(work, struct intel_atomic_state, base.commit_work);
14091 intel_atomic_commit_tail(state);
14094 static int __i915_sw_fence_call
14095 intel_atomic_commit_ready(struct i915_sw_fence *fence,
14096 enum i915_sw_fence_notify notify)
14098 struct intel_atomic_state *state =
14099 container_of(fence, struct intel_atomic_state, commit_ready);
14102 case FENCE_COMPLETE:
14103 /* we do blocking waits in the worker, nothing to do here */
14107 struct intel_atomic_helper *helper =
14108 &to_i915(state->base.dev)->atomic_helper;
14110 if (llist_add(&state->freed, &helper->free_list))
14111 schedule_work(&helper->free_work);
14116 return NOTIFY_DONE;
14119 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
14121 struct intel_plane_state *old_plane_state, *new_plane_state;
14122 struct intel_plane *plane;
14125 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
14126 new_plane_state, i)
14127 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->base.fb),
14128 to_intel_frontbuffer(new_plane_state->base.fb),
14129 plane->frontbuffer_bit);
14132 static int intel_atomic_commit(struct drm_device *dev,
14133 struct drm_atomic_state *_state,
14136 struct intel_atomic_state *state = to_intel_atomic_state(_state);
14137 struct drm_i915_private *dev_priv = to_i915(dev);
14140 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
14142 drm_atomic_state_get(&state->base);
14143 i915_sw_fence_init(&state->commit_ready,
14144 intel_atomic_commit_ready);
14147 * The intel_legacy_cursor_update() fast path takes care
14148 * of avoiding the vblank waits for simple cursor
14149 * movement and flips. For cursor on/off and size changes,
14150 * we want to perform the vblank waits so that watermark
14151 * updates happen during the correct frames. Gen9+ have
14152 * double buffered watermarks and so shouldn't need this.
14154 * Unset state->legacy_cursor_update before the call to
14155 * drm_atomic_helper_setup_commit() because otherwise
14156 * drm_atomic_helper_wait_for_flip_done() is a noop and
14157 * we get FIFO underruns because we didn't wait
14160 * FIXME doing watermarks and fb cleanup from a vblank worker
14161 * (assuming we had any) would solve these problems.
14163 if (INTEL_GEN(dev_priv) < 9 && state->base.legacy_cursor_update) {
14164 struct intel_crtc_state *new_crtc_state;
14165 struct intel_crtc *crtc;
14168 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
14169 if (new_crtc_state->wm.need_postvbl_update ||
14170 new_crtc_state->update_wm_post)
14171 state->base.legacy_cursor_update = false;
14174 ret = intel_atomic_prepare_commit(state);
14176 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
14177 i915_sw_fence_commit(&state->commit_ready);
14178 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
14182 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
14184 ret = drm_atomic_helper_swap_state(&state->base, true);
14187 i915_sw_fence_commit(&state->commit_ready);
14189 drm_atomic_helper_cleanup_planes(dev, &state->base);
14190 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
14193 dev_priv->wm.distrust_bios_wm = false;
14194 intel_shared_dpll_swap_state(state);
14195 intel_atomic_track_fbs(state);
14197 if (state->modeset) {
14198 memcpy(dev_priv->min_cdclk, state->min_cdclk,
14199 sizeof(state->min_cdclk));
14200 memcpy(dev_priv->min_voltage_level, state->min_voltage_level,
14201 sizeof(state->min_voltage_level));
14202 dev_priv->active_pipes = state->active_pipes;
14203 dev_priv->cdclk.force_min_cdclk = state->cdclk.force_min_cdclk;
14205 intel_cdclk_swap_state(state);
14208 drm_atomic_state_get(&state->base);
14209 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
14211 i915_sw_fence_commit(&state->commit_ready);
14212 if (nonblock && state->modeset) {
14213 queue_work(dev_priv->modeset_wq, &state->base.commit_work);
14214 } else if (nonblock) {
14215 queue_work(system_unbound_wq, &state->base.commit_work);
14217 if (state->modeset)
14218 flush_workqueue(dev_priv->modeset_wq);
14219 intel_atomic_commit_tail(state);
14225 struct wait_rps_boost {
14226 struct wait_queue_entry wait;
14228 struct drm_crtc *crtc;
14229 struct i915_request *request;
14232 static int do_rps_boost(struct wait_queue_entry *_wait,
14233 unsigned mode, int sync, void *key)
14235 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
14236 struct i915_request *rq = wait->request;
14239 * If we missed the vblank, but the request is already running it
14240 * is reasonable to assume that it will complete before the next
14241 * vblank without our intervention, so leave RPS alone.
14243 if (!i915_request_started(rq))
14244 gen6_rps_boost(rq);
14245 i915_request_put(rq);
14247 drm_crtc_vblank_put(wait->crtc);
14249 list_del(&wait->wait.entry);
14254 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
14255 struct dma_fence *fence)
14257 struct wait_rps_boost *wait;
14259 if (!dma_fence_is_i915(fence))
14262 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
14265 if (drm_crtc_vblank_get(crtc))
14268 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
14270 drm_crtc_vblank_put(crtc);
14274 wait->request = to_request(dma_fence_get(fence));
14277 wait->wait.func = do_rps_boost;
14278 wait->wait.flags = 0;
14280 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
14283 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
14285 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
14286 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
14287 struct drm_framebuffer *fb = plane_state->base.fb;
14288 struct i915_vma *vma;
14290 if (plane->id == PLANE_CURSOR &&
14291 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
14292 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14293 const int align = intel_cursor_alignment(dev_priv);
14296 err = i915_gem_object_attach_phys(obj, align);
14301 vma = intel_pin_and_fence_fb_obj(fb,
14302 &plane_state->view,
14303 intel_plane_uses_fence(plane_state),
14304 &plane_state->flags);
14306 return PTR_ERR(vma);
14308 plane_state->vma = vma;
14313 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
14315 struct i915_vma *vma;
14317 vma = fetch_and_zero(&old_plane_state->vma);
14319 intel_unpin_fb_vma(vma, old_plane_state->flags);
14322 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
14324 struct i915_sched_attr attr = {
14325 .priority = I915_PRIORITY_DISPLAY,
14328 i915_gem_object_wait_priority(obj, 0, &attr);
14332 * intel_prepare_plane_fb - Prepare fb for usage on plane
14333 * @plane: drm plane to prepare for
14334 * @new_state: the plane state being prepared
14336 * Prepares a framebuffer for usage on a display plane. Generally this
14337 * involves pinning the underlying object and updating the frontbuffer tracking
14338 * bits. Some older platforms need special physical address handling for
14341 * Must be called with struct_mutex held.
14343 * Returns 0 on success, negative error code on failure.
14346 intel_prepare_plane_fb(struct drm_plane *plane,
14347 struct drm_plane_state *new_state)
14349 struct intel_atomic_state *intel_state =
14350 to_intel_atomic_state(new_state->state);
14351 struct drm_i915_private *dev_priv = to_i915(plane->dev);
14352 struct drm_framebuffer *fb = new_state->fb;
14353 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14354 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
14358 struct intel_crtc_state *crtc_state =
14359 intel_atomic_get_new_crtc_state(intel_state,
14360 to_intel_crtc(plane->state->crtc));
14362 /* Big Hammer, we also need to ensure that any pending
14363 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
14364 * current scanout is retired before unpinning the old
14365 * framebuffer. Note that we rely on userspace rendering
14366 * into the buffer attached to the pipe they are waiting
14367 * on. If not, userspace generates a GPU hang with IPEHR
14368 * point to the MI_WAIT_FOR_EVENT.
14370 * This should only fail upon a hung GPU, in which case we
14371 * can safely continue.
14373 if (needs_modeset(crtc_state)) {
14374 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
14375 old_obj->base.resv, NULL,
14383 if (new_state->fence) { /* explicit fencing */
14384 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
14386 I915_FENCE_TIMEOUT,
14395 ret = i915_gem_object_pin_pages(obj);
14399 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
14401 i915_gem_object_unpin_pages(obj);
14405 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
14407 mutex_unlock(&dev_priv->drm.struct_mutex);
14408 i915_gem_object_unpin_pages(obj);
14412 fb_obj_bump_render_priority(obj);
14413 intel_frontbuffer_flush(obj->frontbuffer, ORIGIN_DIRTYFB);
14415 if (!new_state->fence) { /* implicit fencing */
14416 struct dma_fence *fence;
14418 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
14419 obj->base.resv, NULL,
14420 false, I915_FENCE_TIMEOUT,
14425 fence = dma_resv_get_excl_rcu(obj->base.resv);
14427 add_rps_boost_after_vblank(new_state->crtc, fence);
14428 dma_fence_put(fence);
14431 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
14435 * We declare pageflips to be interactive and so merit a small bias
14436 * towards upclocking to deliver the frame on time. By only changing
14437 * the RPS thresholds to sample more regularly and aim for higher
14438 * clocks we can hopefully deliver low power workloads (like kodi)
14439 * that are not quite steady state without resorting to forcing
14440 * maximum clocks following a vblank miss (see do_rps_boost()).
14442 if (!intel_state->rps_interactive) {
14443 intel_rps_mark_interactive(dev_priv, true);
14444 intel_state->rps_interactive = true;
14451 * intel_cleanup_plane_fb - Cleans up an fb after plane use
14452 * @plane: drm plane to clean up for
14453 * @old_state: the state from the previous modeset
14455 * Cleans up a framebuffer that has just been removed from a plane.
14457 * Must be called with struct_mutex held.
14460 intel_cleanup_plane_fb(struct drm_plane *plane,
14461 struct drm_plane_state *old_state)
14463 struct intel_atomic_state *intel_state =
14464 to_intel_atomic_state(old_state->state);
14465 struct drm_i915_private *dev_priv = to_i915(plane->dev);
14467 if (intel_state->rps_interactive) {
14468 intel_rps_mark_interactive(dev_priv, false);
14469 intel_state->rps_interactive = false;
14472 /* Should only be called after a successful intel_prepare_plane_fb()! */
14473 mutex_lock(&dev_priv->drm.struct_mutex);
14474 intel_plane_unpin_fb(to_intel_plane_state(old_state));
14475 mutex_unlock(&dev_priv->drm.struct_mutex);
14479 skl_max_scale(const struct intel_crtc_state *crtc_state,
14482 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
14483 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14484 int max_scale, mult;
14485 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
14487 if (!crtc_state->base.enable)
14488 return DRM_PLANE_HELPER_NO_SCALING;
14490 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
14491 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
14493 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
14496 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
14497 return DRM_PLANE_HELPER_NO_SCALING;
14500 * skl max scale is lower of:
14501 * close to 3 but not 3, -1 is for that purpose
14505 mult = is_planar_yuv_format(pixel_format) ? 2 : 3;
14506 tmpclk1 = (1 << 16) * mult - 1;
14507 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
14508 max_scale = min(tmpclk1, tmpclk2);
14513 static void intel_begin_crtc_commit(struct intel_atomic_state *state,
14514 struct intel_crtc *crtc)
14516 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14517 struct intel_crtc_state *old_crtc_state =
14518 intel_atomic_get_old_crtc_state(state, crtc);
14519 struct intel_crtc_state *new_crtc_state =
14520 intel_atomic_get_new_crtc_state(state, crtc);
14521 bool modeset = needs_modeset(new_crtc_state);
14523 /* Perform vblank evasion around commit operation */
14524 intel_pipe_update_start(new_crtc_state);
14529 if (new_crtc_state->base.color_mgmt_changed ||
14530 new_crtc_state->update_pipe)
14531 intel_color_commit(new_crtc_state);
14533 if (new_crtc_state->update_pipe)
14534 intel_update_pipe_config(old_crtc_state, new_crtc_state);
14535 else if (INTEL_GEN(dev_priv) >= 9)
14536 skl_detach_scalers(new_crtc_state);
14538 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
14539 bdw_set_pipemisc(new_crtc_state);
14542 if (dev_priv->display.atomic_update_watermarks)
14543 dev_priv->display.atomic_update_watermarks(state,
14547 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
14548 struct intel_crtc_state *crtc_state)
14550 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14552 if (!IS_GEN(dev_priv, 2))
14553 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
14555 if (crtc_state->has_pch_encoder) {
14556 enum pipe pch_transcoder =
14557 intel_crtc_pch_transcoder(crtc);
14559 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
14563 static void intel_finish_crtc_commit(struct intel_atomic_state *state,
14564 struct intel_crtc *crtc)
14566 struct intel_crtc_state *old_crtc_state =
14567 intel_atomic_get_old_crtc_state(state, crtc);
14568 struct intel_crtc_state *new_crtc_state =
14569 intel_atomic_get_new_crtc_state(state, crtc);
14571 intel_pipe_update_end(new_crtc_state);
14573 if (new_crtc_state->update_pipe &&
14574 !needs_modeset(new_crtc_state) &&
14575 old_crtc_state->base.mode.private_flags & I915_MODE_FLAG_INHERITED)
14576 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
14580 * intel_plane_destroy - destroy a plane
14581 * @plane: plane to destroy
14583 * Common destruction function for all types of planes (primary, cursor,
14586 void intel_plane_destroy(struct drm_plane *plane)
14588 drm_plane_cleanup(plane);
14589 kfree(to_intel_plane(plane));
14592 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
14593 u32 format, u64 modifier)
14595 switch (modifier) {
14596 case DRM_FORMAT_MOD_LINEAR:
14597 case I915_FORMAT_MOD_X_TILED:
14604 case DRM_FORMAT_C8:
14605 case DRM_FORMAT_RGB565:
14606 case DRM_FORMAT_XRGB1555:
14607 case DRM_FORMAT_XRGB8888:
14608 return modifier == DRM_FORMAT_MOD_LINEAR ||
14609 modifier == I915_FORMAT_MOD_X_TILED;
14615 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
14616 u32 format, u64 modifier)
14618 switch (modifier) {
14619 case DRM_FORMAT_MOD_LINEAR:
14620 case I915_FORMAT_MOD_X_TILED:
14627 case DRM_FORMAT_C8:
14628 case DRM_FORMAT_RGB565:
14629 case DRM_FORMAT_XRGB8888:
14630 case DRM_FORMAT_XBGR8888:
14631 case DRM_FORMAT_XRGB2101010:
14632 case DRM_FORMAT_XBGR2101010:
14633 return modifier == DRM_FORMAT_MOD_LINEAR ||
14634 modifier == I915_FORMAT_MOD_X_TILED;
14640 static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
14641 u32 format, u64 modifier)
14643 return modifier == DRM_FORMAT_MOD_LINEAR &&
14644 format == DRM_FORMAT_ARGB8888;
14647 static const struct drm_plane_funcs i965_plane_funcs = {
14648 .update_plane = drm_atomic_helper_update_plane,
14649 .disable_plane = drm_atomic_helper_disable_plane,
14650 .destroy = intel_plane_destroy,
14651 .atomic_duplicate_state = intel_plane_duplicate_state,
14652 .atomic_destroy_state = intel_plane_destroy_state,
14653 .format_mod_supported = i965_plane_format_mod_supported,
14656 static const struct drm_plane_funcs i8xx_plane_funcs = {
14657 .update_plane = drm_atomic_helper_update_plane,
14658 .disable_plane = drm_atomic_helper_disable_plane,
14659 .destroy = intel_plane_destroy,
14660 .atomic_duplicate_state = intel_plane_duplicate_state,
14661 .atomic_destroy_state = intel_plane_destroy_state,
14662 .format_mod_supported = i8xx_plane_format_mod_supported,
14666 intel_legacy_cursor_update(struct drm_plane *plane,
14667 struct drm_crtc *crtc,
14668 struct drm_framebuffer *fb,
14669 int crtc_x, int crtc_y,
14670 unsigned int crtc_w, unsigned int crtc_h,
14671 u32 src_x, u32 src_y,
14672 u32 src_w, u32 src_h,
14673 struct drm_modeset_acquire_ctx *ctx)
14675 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
14676 struct drm_plane_state *old_plane_state, *new_plane_state;
14677 struct intel_plane *intel_plane = to_intel_plane(plane);
14678 struct intel_crtc_state *crtc_state =
14679 to_intel_crtc_state(crtc->state);
14680 struct intel_crtc_state *new_crtc_state;
14684 * When crtc is inactive or there is a modeset pending,
14685 * wait for it to complete in the slowpath
14687 if (!crtc_state->base.active || needs_modeset(crtc_state) ||
14688 crtc_state->update_pipe)
14691 old_plane_state = plane->state;
14693 * Don't do an async update if there is an outstanding commit modifying
14694 * the plane. This prevents our async update's changes from getting
14695 * overridden by a previous synchronous update's state.
14697 if (old_plane_state->commit &&
14698 !try_wait_for_completion(&old_plane_state->commit->hw_done))
14702 * If any parameters change that may affect watermarks,
14703 * take the slowpath. Only changing fb or position should be
14706 if (old_plane_state->crtc != crtc ||
14707 old_plane_state->src_w != src_w ||
14708 old_plane_state->src_h != src_h ||
14709 old_plane_state->crtc_w != crtc_w ||
14710 old_plane_state->crtc_h != crtc_h ||
14711 !old_plane_state->fb != !fb)
14714 new_plane_state = intel_plane_duplicate_state(plane);
14715 if (!new_plane_state)
14718 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc));
14719 if (!new_crtc_state) {
14724 drm_atomic_set_fb_for_plane(new_plane_state, fb);
14726 new_plane_state->src_x = src_x;
14727 new_plane_state->src_y = src_y;
14728 new_plane_state->src_w = src_w;
14729 new_plane_state->src_h = src_h;
14730 new_plane_state->crtc_x = crtc_x;
14731 new_plane_state->crtc_y = crtc_y;
14732 new_plane_state->crtc_w = crtc_w;
14733 new_plane_state->crtc_h = crtc_h;
14735 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
14736 to_intel_plane_state(old_plane_state),
14737 to_intel_plane_state(new_plane_state));
14741 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
14745 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
14749 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_FLIP);
14750 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->fb),
14751 to_intel_frontbuffer(fb),
14752 intel_plane->frontbuffer_bit);
14754 /* Swap plane state */
14755 plane->state = new_plane_state;
14758 * We cannot swap crtc_state as it may be in use by an atomic commit or
14759 * page flip that's running simultaneously. If we swap crtc_state and
14760 * destroy the old state, we will cause a use-after-free there.
14762 * Only update active_planes, which is needed for our internal
14763 * bookkeeping. Either value will do the right thing when updating
14764 * planes atomically. If the cursor was part of the atomic update then
14765 * we would have taken the slowpath.
14767 crtc_state->active_planes = new_crtc_state->active_planes;
14769 if (plane->state->visible)
14770 intel_update_plane(intel_plane, crtc_state,
14771 to_intel_plane_state(plane->state));
14773 intel_disable_plane(intel_plane, crtc_state);
14775 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
14778 mutex_unlock(&dev_priv->drm.struct_mutex);
14780 if (new_crtc_state)
14781 intel_crtc_destroy_state(crtc, &new_crtc_state->base);
14783 intel_plane_destroy_state(plane, new_plane_state);
14785 intel_plane_destroy_state(plane, old_plane_state);
14789 return drm_atomic_helper_update_plane(plane, crtc, fb,
14790 crtc_x, crtc_y, crtc_w, crtc_h,
14791 src_x, src_y, src_w, src_h, ctx);
14794 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
14795 .update_plane = intel_legacy_cursor_update,
14796 .disable_plane = drm_atomic_helper_disable_plane,
14797 .destroy = intel_plane_destroy,
14798 .atomic_duplicate_state = intel_plane_duplicate_state,
14799 .atomic_destroy_state = intel_plane_destroy_state,
14800 .format_mod_supported = intel_cursor_format_mod_supported,
14803 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
14804 enum i9xx_plane_id i9xx_plane)
14806 if (!HAS_FBC(dev_priv))
14809 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
14810 return i9xx_plane == PLANE_A; /* tied to pipe A */
14811 else if (IS_IVYBRIDGE(dev_priv))
14812 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
14813 i9xx_plane == PLANE_C;
14814 else if (INTEL_GEN(dev_priv) >= 4)
14815 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
14817 return i9xx_plane == PLANE_A;
14820 static struct intel_plane *
14821 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
14823 struct intel_plane *plane;
14824 const struct drm_plane_funcs *plane_funcs;
14825 unsigned int supported_rotations;
14826 unsigned int possible_crtcs;
14827 const u64 *modifiers;
14828 const u32 *formats;
14832 if (INTEL_GEN(dev_priv) >= 9)
14833 return skl_universal_plane_create(dev_priv, pipe,
14836 plane = intel_plane_alloc();
14840 plane->pipe = pipe;
14842 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
14843 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
14845 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
14846 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
14848 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
14849 plane->id = PLANE_PRIMARY;
14850 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
14852 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
14853 if (plane->has_fbc) {
14854 struct intel_fbc *fbc = &dev_priv->fbc;
14856 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
14859 if (INTEL_GEN(dev_priv) >= 4) {
14860 formats = i965_primary_formats;
14861 num_formats = ARRAY_SIZE(i965_primary_formats);
14862 modifiers = i9xx_format_modifiers;
14864 plane->max_stride = i9xx_plane_max_stride;
14865 plane->update_plane = i9xx_update_plane;
14866 plane->disable_plane = i9xx_disable_plane;
14867 plane->get_hw_state = i9xx_plane_get_hw_state;
14868 plane->check_plane = i9xx_plane_check;
14870 plane_funcs = &i965_plane_funcs;
14872 formats = i8xx_primary_formats;
14873 num_formats = ARRAY_SIZE(i8xx_primary_formats);
14874 modifiers = i9xx_format_modifiers;
14876 plane->max_stride = i9xx_plane_max_stride;
14877 plane->update_plane = i9xx_update_plane;
14878 plane->disable_plane = i9xx_disable_plane;
14879 plane->get_hw_state = i9xx_plane_get_hw_state;
14880 plane->check_plane = i9xx_plane_check;
14882 plane_funcs = &i8xx_plane_funcs;
14885 possible_crtcs = BIT(pipe);
14887 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
14888 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
14889 possible_crtcs, plane_funcs,
14890 formats, num_formats, modifiers,
14891 DRM_PLANE_TYPE_PRIMARY,
14892 "primary %c", pipe_name(pipe));
14894 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
14895 possible_crtcs, plane_funcs,
14896 formats, num_formats, modifiers,
14897 DRM_PLANE_TYPE_PRIMARY,
14899 plane_name(plane->i9xx_plane));
14903 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
14904 supported_rotations =
14905 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
14906 DRM_MODE_REFLECT_X;
14907 } else if (INTEL_GEN(dev_priv) >= 4) {
14908 supported_rotations =
14909 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
14911 supported_rotations = DRM_MODE_ROTATE_0;
14914 if (INTEL_GEN(dev_priv) >= 4)
14915 drm_plane_create_rotation_property(&plane->base,
14917 supported_rotations);
14919 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
14924 intel_plane_free(plane);
14926 return ERR_PTR(ret);
14929 static struct intel_plane *
14930 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
14933 unsigned int possible_crtcs;
14934 struct intel_plane *cursor;
14937 cursor = intel_plane_alloc();
14938 if (IS_ERR(cursor))
14941 cursor->pipe = pipe;
14942 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
14943 cursor->id = PLANE_CURSOR;
14944 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
14946 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
14947 cursor->max_stride = i845_cursor_max_stride;
14948 cursor->update_plane = i845_update_cursor;
14949 cursor->disable_plane = i845_disable_cursor;
14950 cursor->get_hw_state = i845_cursor_get_hw_state;
14951 cursor->check_plane = i845_check_cursor;
14953 cursor->max_stride = i9xx_cursor_max_stride;
14954 cursor->update_plane = i9xx_update_cursor;
14955 cursor->disable_plane = i9xx_disable_cursor;
14956 cursor->get_hw_state = i9xx_cursor_get_hw_state;
14957 cursor->check_plane = i9xx_check_cursor;
14960 cursor->cursor.base = ~0;
14961 cursor->cursor.cntl = ~0;
14963 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
14964 cursor->cursor.size = ~0;
14966 possible_crtcs = BIT(pipe);
14968 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
14969 possible_crtcs, &intel_cursor_plane_funcs,
14970 intel_cursor_formats,
14971 ARRAY_SIZE(intel_cursor_formats),
14972 cursor_format_modifiers,
14973 DRM_PLANE_TYPE_CURSOR,
14974 "cursor %c", pipe_name(pipe));
14978 if (INTEL_GEN(dev_priv) >= 4)
14979 drm_plane_create_rotation_property(&cursor->base,
14981 DRM_MODE_ROTATE_0 |
14982 DRM_MODE_ROTATE_180);
14984 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
14989 intel_plane_free(cursor);
14991 return ERR_PTR(ret);
14994 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
14995 struct intel_crtc_state *crtc_state)
14997 struct intel_crtc_scaler_state *scaler_state =
14998 &crtc_state->scaler_state;
14999 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
15002 crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[crtc->pipe];
15003 if (!crtc->num_scalers)
15006 for (i = 0; i < crtc->num_scalers; i++) {
15007 struct intel_scaler *scaler = &scaler_state->scalers[i];
15009 scaler->in_use = 0;
15013 scaler_state->scaler_id = -1;
15016 #define INTEL_CRTC_FUNCS \
15017 .gamma_set = drm_atomic_helper_legacy_gamma_set, \
15018 .set_config = drm_atomic_helper_set_config, \
15019 .destroy = intel_crtc_destroy, \
15020 .page_flip = drm_atomic_helper_page_flip, \
15021 .atomic_duplicate_state = intel_crtc_duplicate_state, \
15022 .atomic_destroy_state = intel_crtc_destroy_state, \
15023 .set_crc_source = intel_crtc_set_crc_source, \
15024 .verify_crc_source = intel_crtc_verify_crc_source, \
15025 .get_crc_sources = intel_crtc_get_crc_sources
15027 static const struct drm_crtc_funcs bdw_crtc_funcs = {
15030 .get_vblank_counter = g4x_get_vblank_counter,
15031 .enable_vblank = bdw_enable_vblank,
15032 .disable_vblank = bdw_disable_vblank,
15035 static const struct drm_crtc_funcs ilk_crtc_funcs = {
15038 .get_vblank_counter = g4x_get_vblank_counter,
15039 .enable_vblank = ilk_enable_vblank,
15040 .disable_vblank = ilk_disable_vblank,
15043 static const struct drm_crtc_funcs g4x_crtc_funcs = {
15046 .get_vblank_counter = g4x_get_vblank_counter,
15047 .enable_vblank = i965_enable_vblank,
15048 .disable_vblank = i965_disable_vblank,
15051 static const struct drm_crtc_funcs i965_crtc_funcs = {
15054 .get_vblank_counter = i915_get_vblank_counter,
15055 .enable_vblank = i965_enable_vblank,
15056 .disable_vblank = i965_disable_vblank,
15059 static const struct drm_crtc_funcs i945gm_crtc_funcs = {
15062 .get_vblank_counter = i915_get_vblank_counter,
15063 .enable_vblank = i945gm_enable_vblank,
15064 .disable_vblank = i945gm_disable_vblank,
15067 static const struct drm_crtc_funcs i915_crtc_funcs = {
15070 .get_vblank_counter = i915_get_vblank_counter,
15071 .enable_vblank = i8xx_enable_vblank,
15072 .disable_vblank = i8xx_disable_vblank,
15075 static const struct drm_crtc_funcs i8xx_crtc_funcs = {
15078 /* no hw vblank counter */
15079 .enable_vblank = i8xx_enable_vblank,
15080 .disable_vblank = i8xx_disable_vblank,
15083 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
15085 const struct drm_crtc_funcs *funcs;
15086 struct intel_crtc *intel_crtc;
15087 struct intel_crtc_state *crtc_state = NULL;
15088 struct intel_plane *primary = NULL;
15089 struct intel_plane *cursor = NULL;
15092 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
15096 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
15101 __drm_atomic_helper_crtc_reset(&intel_crtc->base, &crtc_state->base);
15102 intel_crtc->config = crtc_state;
15104 primary = intel_primary_plane_create(dev_priv, pipe);
15105 if (IS_ERR(primary)) {
15106 ret = PTR_ERR(primary);
15109 intel_crtc->plane_ids_mask |= BIT(primary->id);
15111 for_each_sprite(dev_priv, pipe, sprite) {
15112 struct intel_plane *plane;
15114 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
15115 if (IS_ERR(plane)) {
15116 ret = PTR_ERR(plane);
15119 intel_crtc->plane_ids_mask |= BIT(plane->id);
15122 cursor = intel_cursor_plane_create(dev_priv, pipe);
15123 if (IS_ERR(cursor)) {
15124 ret = PTR_ERR(cursor);
15127 intel_crtc->plane_ids_mask |= BIT(cursor->id);
15129 if (HAS_GMCH(dev_priv)) {
15130 if (IS_CHERRYVIEW(dev_priv) ||
15131 IS_VALLEYVIEW(dev_priv) || IS_G4X(dev_priv))
15132 funcs = &g4x_crtc_funcs;
15133 else if (IS_GEN(dev_priv, 4))
15134 funcs = &i965_crtc_funcs;
15135 else if (IS_I945GM(dev_priv))
15136 funcs = &i945gm_crtc_funcs;
15137 else if (IS_GEN(dev_priv, 3))
15138 funcs = &i915_crtc_funcs;
15140 funcs = &i8xx_crtc_funcs;
15142 if (INTEL_GEN(dev_priv) >= 8)
15143 funcs = &bdw_crtc_funcs;
15145 funcs = &ilk_crtc_funcs;
15148 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
15149 &primary->base, &cursor->base,
15150 funcs, "pipe %c", pipe_name(pipe));
15154 intel_crtc->pipe = pipe;
15156 /* initialize shared scalers */
15157 intel_crtc_init_scalers(intel_crtc, crtc_state);
15159 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
15160 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
15161 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
15163 if (INTEL_GEN(dev_priv) < 9) {
15164 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
15166 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
15167 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
15168 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
15171 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
15173 intel_color_init(intel_crtc);
15175 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
15181 * drm_mode_config_cleanup() will free up any
15182 * crtcs/planes already initialized.
15190 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
15191 struct drm_file *file)
15193 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
15194 struct drm_crtc *drmmode_crtc;
15195 struct intel_crtc *crtc;
15197 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
15201 crtc = to_intel_crtc(drmmode_crtc);
15202 pipe_from_crtc_id->pipe = crtc->pipe;
15207 static int intel_encoder_clones(struct intel_encoder *encoder)
15209 struct drm_device *dev = encoder->base.dev;
15210 struct intel_encoder *source_encoder;
15211 int index_mask = 0;
15214 for_each_intel_encoder(dev, source_encoder) {
15215 if (encoders_cloneable(encoder, source_encoder))
15216 index_mask |= (1 << entry);
15224 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
15226 if (!IS_MOBILE(dev_priv))
15229 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
15232 if (IS_GEN(dev_priv, 5) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
15238 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
15240 if (INTEL_GEN(dev_priv) >= 9)
15243 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
15246 if (HAS_PCH_LPT_H(dev_priv) &&
15247 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
15250 /* DDI E can't be used if DDI A requires 4 lanes */
15251 if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
15254 if (!dev_priv->vbt.int_crt_support)
15260 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
15265 if (HAS_DDI(dev_priv))
15268 * This w/a is needed at least on CPT/PPT, but to be sure apply it
15269 * everywhere where registers can be write protected.
15271 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
15276 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
15277 u32 val = I915_READ(PP_CONTROL(pps_idx));
15279 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
15280 I915_WRITE(PP_CONTROL(pps_idx), val);
15284 static void intel_pps_init(struct drm_i915_private *dev_priv)
15286 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
15287 dev_priv->pps_mmio_base = PCH_PPS_BASE;
15288 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
15289 dev_priv->pps_mmio_base = VLV_PPS_BASE;
15291 dev_priv->pps_mmio_base = PPS_BASE;
15293 intel_pps_unlock_regs_wa(dev_priv);
15296 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
15298 struct intel_encoder *encoder;
15299 bool dpd_is_edp = false;
15301 intel_pps_init(dev_priv);
15303 if (!HAS_DISPLAY(dev_priv))
15306 if (INTEL_GEN(dev_priv) >= 12) {
15307 /* TODO: initialize TC ports as well */
15308 intel_ddi_init(dev_priv, PORT_A);
15309 intel_ddi_init(dev_priv, PORT_B);
15310 icl_dsi_init(dev_priv);
15311 } else if (IS_ELKHARTLAKE(dev_priv)) {
15312 intel_ddi_init(dev_priv, PORT_A);
15313 intel_ddi_init(dev_priv, PORT_B);
15314 intel_ddi_init(dev_priv, PORT_C);
15315 intel_ddi_init(dev_priv, PORT_D);
15316 icl_dsi_init(dev_priv);
15317 } else if (IS_GEN(dev_priv, 11)) {
15318 intel_ddi_init(dev_priv, PORT_A);
15319 intel_ddi_init(dev_priv, PORT_B);
15320 intel_ddi_init(dev_priv, PORT_C);
15321 intel_ddi_init(dev_priv, PORT_D);
15322 intel_ddi_init(dev_priv, PORT_E);
15324 * On some ICL SKUs port F is not present. No strap bits for
15325 * this, so rely on VBT.
15326 * Work around broken VBTs on SKUs known to have no port F.
15328 if (IS_ICL_WITH_PORT_F(dev_priv) &&
15329 intel_bios_is_port_present(dev_priv, PORT_F))
15330 intel_ddi_init(dev_priv, PORT_F);
15332 icl_dsi_init(dev_priv);
15333 } else if (IS_GEN9_LP(dev_priv)) {
15335 * FIXME: Broxton doesn't support port detection via the
15336 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
15337 * detect the ports.
15339 intel_ddi_init(dev_priv, PORT_A);
15340 intel_ddi_init(dev_priv, PORT_B);
15341 intel_ddi_init(dev_priv, PORT_C);
15343 vlv_dsi_init(dev_priv);
15344 } else if (HAS_DDI(dev_priv)) {
15347 if (intel_ddi_crt_present(dev_priv))
15348 intel_crt_init(dev_priv);
15351 * Haswell uses DDI functions to detect digital outputs.
15352 * On SKL pre-D0 the strap isn't connected, so we assume
15355 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
15356 /* WaIgnoreDDIAStrap: skl */
15357 if (found || IS_GEN9_BC(dev_priv))
15358 intel_ddi_init(dev_priv, PORT_A);
15360 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
15362 found = I915_READ(SFUSE_STRAP);
15364 if (found & SFUSE_STRAP_DDIB_DETECTED)
15365 intel_ddi_init(dev_priv, PORT_B);
15366 if (found & SFUSE_STRAP_DDIC_DETECTED)
15367 intel_ddi_init(dev_priv, PORT_C);
15368 if (found & SFUSE_STRAP_DDID_DETECTED)
15369 intel_ddi_init(dev_priv, PORT_D);
15370 if (found & SFUSE_STRAP_DDIF_DETECTED)
15371 intel_ddi_init(dev_priv, PORT_F);
15373 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
15375 if (IS_GEN9_BC(dev_priv) &&
15376 intel_bios_is_port_present(dev_priv, PORT_E))
15377 intel_ddi_init(dev_priv, PORT_E);
15379 } else if (HAS_PCH_SPLIT(dev_priv)) {
15383 * intel_edp_init_connector() depends on this completing first,
15384 * to prevent the registration of both eDP and LVDS and the
15385 * incorrect sharing of the PPS.
15387 intel_lvds_init(dev_priv);
15388 intel_crt_init(dev_priv);
15390 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
15392 if (ilk_has_edp_a(dev_priv))
15393 intel_dp_init(dev_priv, DP_A, PORT_A);
15395 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
15396 /* PCH SDVOB multiplex with HDMIB */
15397 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
15399 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
15400 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
15401 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
15404 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
15405 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
15407 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
15408 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
15410 if (I915_READ(PCH_DP_C) & DP_DETECTED)
15411 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
15413 if (I915_READ(PCH_DP_D) & DP_DETECTED)
15414 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
15415 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
15416 bool has_edp, has_port;
15418 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
15419 intel_crt_init(dev_priv);
15422 * The DP_DETECTED bit is the latched state of the DDC
15423 * SDA pin at boot. However since eDP doesn't require DDC
15424 * (no way to plug in a DP->HDMI dongle) the DDC pins for
15425 * eDP ports may have been muxed to an alternate function.
15426 * Thus we can't rely on the DP_DETECTED bit alone to detect
15427 * eDP ports. Consult the VBT as well as DP_DETECTED to
15428 * detect eDP ports.
15430 * Sadly the straps seem to be missing sometimes even for HDMI
15431 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
15432 * and VBT for the presence of the port. Additionally we can't
15433 * trust the port type the VBT declares as we've seen at least
15434 * HDMI ports that the VBT claim are DP or eDP.
15436 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
15437 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
15438 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
15439 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
15440 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
15441 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
15443 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
15444 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
15445 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
15446 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
15447 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
15448 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
15450 if (IS_CHERRYVIEW(dev_priv)) {
15452 * eDP not supported on port D,
15453 * so no need to worry about it
15455 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
15456 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
15457 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
15458 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
15459 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
15462 vlv_dsi_init(dev_priv);
15463 } else if (IS_PINEVIEW(dev_priv)) {
15464 intel_lvds_init(dev_priv);
15465 intel_crt_init(dev_priv);
15466 } else if (IS_GEN_RANGE(dev_priv, 3, 4)) {
15467 bool found = false;
15469 if (IS_MOBILE(dev_priv))
15470 intel_lvds_init(dev_priv);
15472 intel_crt_init(dev_priv);
15474 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
15475 DRM_DEBUG_KMS("probing SDVOB\n");
15476 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
15477 if (!found && IS_G4X(dev_priv)) {
15478 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
15479 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
15482 if (!found && IS_G4X(dev_priv))
15483 intel_dp_init(dev_priv, DP_B, PORT_B);
15486 /* Before G4X SDVOC doesn't have its own detect register */
15488 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
15489 DRM_DEBUG_KMS("probing SDVOC\n");
15490 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
15493 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
15495 if (IS_G4X(dev_priv)) {
15496 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
15497 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
15499 if (IS_G4X(dev_priv))
15500 intel_dp_init(dev_priv, DP_C, PORT_C);
15503 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
15504 intel_dp_init(dev_priv, DP_D, PORT_D);
15506 if (SUPPORTS_TV(dev_priv))
15507 intel_tv_init(dev_priv);
15508 } else if (IS_GEN(dev_priv, 2)) {
15509 if (IS_I85X(dev_priv))
15510 intel_lvds_init(dev_priv);
15512 intel_crt_init(dev_priv);
15513 intel_dvo_init(dev_priv);
15516 intel_psr_init(dev_priv);
15518 for_each_intel_encoder(&dev_priv->drm, encoder) {
15519 encoder->base.possible_crtcs = encoder->crtc_mask;
15520 encoder->base.possible_clones =
15521 intel_encoder_clones(encoder);
15524 intel_init_pch_refclk(dev_priv);
15526 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
15529 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
15531 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
15533 drm_framebuffer_cleanup(fb);
15534 intel_frontbuffer_put(intel_fb->frontbuffer);
15539 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
15540 struct drm_file *file,
15541 unsigned int *handle)
15543 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
15545 if (obj->userptr.mm) {
15546 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
15550 return drm_gem_handle_create(file, &obj->base, handle);
15553 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
15554 struct drm_file *file,
15555 unsigned flags, unsigned color,
15556 struct drm_clip_rect *clips,
15557 unsigned num_clips)
15559 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
15561 i915_gem_object_flush_if_display(obj);
15562 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
15567 static const struct drm_framebuffer_funcs intel_fb_funcs = {
15568 .destroy = intel_user_framebuffer_destroy,
15569 .create_handle = intel_user_framebuffer_create_handle,
15570 .dirty = intel_user_framebuffer_dirty,
15573 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
15574 struct drm_i915_gem_object *obj,
15575 struct drm_mode_fb_cmd2 *mode_cmd)
15577 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
15578 struct drm_framebuffer *fb = &intel_fb->base;
15580 unsigned int tiling, stride;
15584 intel_fb->frontbuffer = intel_frontbuffer_get(obj);
15585 if (!intel_fb->frontbuffer)
15588 i915_gem_object_lock(obj);
15589 tiling = i915_gem_object_get_tiling(obj);
15590 stride = i915_gem_object_get_stride(obj);
15591 i915_gem_object_unlock(obj);
15593 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
15595 * If there's a fence, enforce that
15596 * the fb modifier and tiling mode match.
15598 if (tiling != I915_TILING_NONE &&
15599 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
15600 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
15604 if (tiling == I915_TILING_X) {
15605 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
15606 } else if (tiling == I915_TILING_Y) {
15607 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
15612 if (!drm_any_plane_has_format(&dev_priv->drm,
15613 mode_cmd->pixel_format,
15614 mode_cmd->modifier[0])) {
15615 struct drm_format_name_buf format_name;
15617 DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n",
15618 drm_get_format_name(mode_cmd->pixel_format,
15620 mode_cmd->modifier[0]);
15625 * gen2/3 display engine uses the fence if present,
15626 * so the tiling mode must match the fb modifier exactly.
15628 if (INTEL_GEN(dev_priv) < 4 &&
15629 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
15630 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
15634 max_stride = intel_fb_max_stride(dev_priv, mode_cmd->pixel_format,
15635 mode_cmd->modifier[0]);
15636 if (mode_cmd->pitches[0] > max_stride) {
15637 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
15638 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
15639 "tiled" : "linear",
15640 mode_cmd->pitches[0], max_stride);
15645 * If there's a fence, enforce that
15646 * the fb pitch and fence stride match.
15648 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
15649 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
15650 mode_cmd->pitches[0], stride);
15654 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
15655 if (mode_cmd->offsets[0] != 0)
15658 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
15660 for (i = 0; i < fb->format->num_planes; i++) {
15661 u32 stride_alignment;
15663 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
15664 DRM_DEBUG_KMS("bad plane %d handle\n", i);
15668 stride_alignment = intel_fb_stride_alignment(fb, i);
15671 * Display WA #0531: skl,bxt,kbl,glk
15673 * Render decompression and plane width > 3840
15674 * combined with horizontal panning requires the
15675 * plane stride to be a multiple of 4. We'll just
15676 * require the entire fb to accommodate that to avoid
15677 * potential runtime errors at plane configuration time.
15679 if (IS_GEN(dev_priv, 9) && i == 0 && fb->width > 3840 &&
15680 is_ccs_modifier(fb->modifier))
15681 stride_alignment *= 4;
15683 if (fb->pitches[i] & (stride_alignment - 1)) {
15684 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
15685 i, fb->pitches[i], stride_alignment);
15689 fb->obj[i] = &obj->base;
15692 ret = intel_fill_fb_info(dev_priv, fb);
15696 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
15698 DRM_ERROR("framebuffer init failed %d\n", ret);
15705 intel_frontbuffer_put(intel_fb->frontbuffer);
15709 static struct drm_framebuffer *
15710 intel_user_framebuffer_create(struct drm_device *dev,
15711 struct drm_file *filp,
15712 const struct drm_mode_fb_cmd2 *user_mode_cmd)
15714 struct drm_framebuffer *fb;
15715 struct drm_i915_gem_object *obj;
15716 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
15718 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
15720 return ERR_PTR(-ENOENT);
15722 fb = intel_framebuffer_create(obj, &mode_cmd);
15723 i915_gem_object_put(obj);
15728 static void intel_atomic_state_free(struct drm_atomic_state *state)
15730 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
15732 drm_atomic_state_default_release(state);
15734 i915_sw_fence_fini(&intel_state->commit_ready);
15739 static enum drm_mode_status
15740 intel_mode_valid(struct drm_device *dev,
15741 const struct drm_display_mode *mode)
15743 struct drm_i915_private *dev_priv = to_i915(dev);
15744 int hdisplay_max, htotal_max;
15745 int vdisplay_max, vtotal_max;
15748 * Can't reject DBLSCAN here because Xorg ddxen can add piles
15749 * of DBLSCAN modes to the output's mode list when they detect
15750 * the scaling mode property on the connector. And they don't
15751 * ask the kernel to validate those modes in any way until
15752 * modeset time at which point the client gets a protocol error.
15753 * So in order to not upset those clients we silently ignore the
15754 * DBLSCAN flag on such connectors. For other connectors we will
15755 * reject modes with the DBLSCAN flag in encoder->compute_config().
15756 * And we always reject DBLSCAN modes in connector->mode_valid()
15757 * as we never want such modes on the connector's mode list.
15760 if (mode->vscan > 1)
15761 return MODE_NO_VSCAN;
15763 if (mode->flags & DRM_MODE_FLAG_HSKEW)
15764 return MODE_H_ILLEGAL;
15766 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
15767 DRM_MODE_FLAG_NCSYNC |
15768 DRM_MODE_FLAG_PCSYNC))
15771 if (mode->flags & (DRM_MODE_FLAG_BCAST |
15772 DRM_MODE_FLAG_PIXMUX |
15773 DRM_MODE_FLAG_CLKDIV2))
15776 if (INTEL_GEN(dev_priv) >= 9 ||
15777 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
15778 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
15779 vdisplay_max = 4096;
15782 } else if (INTEL_GEN(dev_priv) >= 3) {
15783 hdisplay_max = 4096;
15784 vdisplay_max = 4096;
15788 hdisplay_max = 2048;
15789 vdisplay_max = 2048;
15794 if (mode->hdisplay > hdisplay_max ||
15795 mode->hsync_start > htotal_max ||
15796 mode->hsync_end > htotal_max ||
15797 mode->htotal > htotal_max)
15798 return MODE_H_ILLEGAL;
15800 if (mode->vdisplay > vdisplay_max ||
15801 mode->vsync_start > vtotal_max ||
15802 mode->vsync_end > vtotal_max ||
15803 mode->vtotal > vtotal_max)
15804 return MODE_V_ILLEGAL;
15809 static const struct drm_mode_config_funcs intel_mode_funcs = {
15810 .fb_create = intel_user_framebuffer_create,
15811 .get_format_info = intel_get_format_info,
15812 .output_poll_changed = intel_fbdev_output_poll_changed,
15813 .mode_valid = intel_mode_valid,
15814 .atomic_check = intel_atomic_check,
15815 .atomic_commit = intel_atomic_commit,
15816 .atomic_state_alloc = intel_atomic_state_alloc,
15817 .atomic_state_clear = intel_atomic_state_clear,
15818 .atomic_state_free = intel_atomic_state_free,
15822 * intel_init_display_hooks - initialize the display modesetting hooks
15823 * @dev_priv: device private
15825 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
15827 intel_init_cdclk_hooks(dev_priv);
15829 if (INTEL_GEN(dev_priv) >= 9) {
15830 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
15831 dev_priv->display.get_initial_plane_config =
15832 skylake_get_initial_plane_config;
15833 dev_priv->display.crtc_compute_clock =
15834 haswell_crtc_compute_clock;
15835 dev_priv->display.crtc_enable = haswell_crtc_enable;
15836 dev_priv->display.crtc_disable = haswell_crtc_disable;
15837 } else if (HAS_DDI(dev_priv)) {
15838 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
15839 dev_priv->display.get_initial_plane_config =
15840 i9xx_get_initial_plane_config;
15841 dev_priv->display.crtc_compute_clock =
15842 haswell_crtc_compute_clock;
15843 dev_priv->display.crtc_enable = haswell_crtc_enable;
15844 dev_priv->display.crtc_disable = haswell_crtc_disable;
15845 } else if (HAS_PCH_SPLIT(dev_priv)) {
15846 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
15847 dev_priv->display.get_initial_plane_config =
15848 i9xx_get_initial_plane_config;
15849 dev_priv->display.crtc_compute_clock =
15850 ironlake_crtc_compute_clock;
15851 dev_priv->display.crtc_enable = ironlake_crtc_enable;
15852 dev_priv->display.crtc_disable = ironlake_crtc_disable;
15853 } else if (IS_CHERRYVIEW(dev_priv)) {
15854 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15855 dev_priv->display.get_initial_plane_config =
15856 i9xx_get_initial_plane_config;
15857 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
15858 dev_priv->display.crtc_enable = valleyview_crtc_enable;
15859 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15860 } else if (IS_VALLEYVIEW(dev_priv)) {
15861 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15862 dev_priv->display.get_initial_plane_config =
15863 i9xx_get_initial_plane_config;
15864 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
15865 dev_priv->display.crtc_enable = valleyview_crtc_enable;
15866 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15867 } else if (IS_G4X(dev_priv)) {
15868 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15869 dev_priv->display.get_initial_plane_config =
15870 i9xx_get_initial_plane_config;
15871 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
15872 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15873 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15874 } else if (IS_PINEVIEW(dev_priv)) {
15875 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15876 dev_priv->display.get_initial_plane_config =
15877 i9xx_get_initial_plane_config;
15878 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
15879 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15880 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15881 } else if (!IS_GEN(dev_priv, 2)) {
15882 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15883 dev_priv->display.get_initial_plane_config =
15884 i9xx_get_initial_plane_config;
15885 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
15886 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15887 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15889 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15890 dev_priv->display.get_initial_plane_config =
15891 i9xx_get_initial_plane_config;
15892 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
15893 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15894 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15897 if (IS_GEN(dev_priv, 5)) {
15898 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
15899 } else if (IS_GEN(dev_priv, 6)) {
15900 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
15901 } else if (IS_IVYBRIDGE(dev_priv)) {
15902 /* FIXME: detect B0+ stepping and use auto training */
15903 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
15904 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
15905 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
15908 if (INTEL_GEN(dev_priv) >= 9)
15909 dev_priv->display.commit_modeset_enables = skl_commit_modeset_enables;
15911 dev_priv->display.commit_modeset_enables = intel_commit_modeset_enables;
15914 static i915_reg_t i915_vgacntrl_reg(struct drm_i915_private *dev_priv)
15916 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
15917 return VLV_VGACNTRL;
15918 else if (INTEL_GEN(dev_priv) >= 5)
15919 return CPU_VGACNTRL;
15924 /* Disable the VGA plane that we never use */
15925 static void i915_disable_vga(struct drm_i915_private *dev_priv)
15927 struct pci_dev *pdev = dev_priv->drm.pdev;
15929 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
15931 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
15932 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
15933 outb(SR01, VGA_SR_INDEX);
15934 sr1 = inb(VGA_SR_DATA);
15935 outb(sr1 | 1<<5, VGA_SR_DATA);
15936 vga_put(pdev, VGA_RSRC_LEGACY_IO);
15939 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
15940 POSTING_READ(vga_reg);
15943 void intel_modeset_init_hw(struct drm_device *dev)
15945 struct drm_i915_private *dev_priv = to_i915(dev);
15947 intel_update_cdclk(dev_priv);
15948 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
15949 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
15953 * Calculate what we think the watermarks should be for the state we've read
15954 * out of the hardware and then immediately program those watermarks so that
15955 * we ensure the hardware settings match our internal state.
15957 * We can calculate what we think WM's should be by creating a duplicate of the
15958 * current state (which was constructed during hardware readout) and running it
15959 * through the atomic check code to calculate new watermark values in the
15962 static void sanitize_watermarks(struct drm_device *dev)
15964 struct drm_i915_private *dev_priv = to_i915(dev);
15965 struct drm_atomic_state *state;
15966 struct intel_atomic_state *intel_state;
15967 struct intel_crtc *crtc;
15968 struct intel_crtc_state *crtc_state;
15969 struct drm_modeset_acquire_ctx ctx;
15973 /* Only supported on platforms that use atomic watermark design */
15974 if (!dev_priv->display.optimize_watermarks)
15978 * We need to hold connection_mutex before calling duplicate_state so
15979 * that the connector loop is protected.
15981 drm_modeset_acquire_init(&ctx, 0);
15983 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15984 if (ret == -EDEADLK) {
15985 drm_modeset_backoff(&ctx);
15987 } else if (WARN_ON(ret)) {
15991 state = drm_atomic_helper_duplicate_state(dev, &ctx);
15992 if (WARN_ON(IS_ERR(state)))
15995 intel_state = to_intel_atomic_state(state);
15998 * Hardware readout is the only time we don't want to calculate
15999 * intermediate watermarks (since we don't trust the current
16002 if (!HAS_GMCH(dev_priv))
16003 intel_state->skip_intermediate_wm = true;
16005 ret = intel_atomic_check(dev, state);
16008 * If we fail here, it means that the hardware appears to be
16009 * programmed in a way that shouldn't be possible, given our
16010 * understanding of watermark requirements. This might mean a
16011 * mistake in the hardware readout code or a mistake in the
16012 * watermark calculations for a given platform. Raise a WARN
16013 * so that this is noticeable.
16015 * If this actually happens, we'll have to just leave the
16016 * BIOS-programmed watermarks untouched and hope for the best.
16018 WARN(true, "Could not determine valid watermarks for inherited state\n");
16022 /* Write calculated watermark values back */
16023 for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) {
16024 crtc_state->wm.need_postvbl_update = true;
16025 dev_priv->display.optimize_watermarks(intel_state, crtc_state);
16027 to_intel_crtc_state(crtc->base.state)->wm = crtc_state->wm;
16031 drm_atomic_state_put(state);
16033 drm_modeset_drop_locks(&ctx);
16034 drm_modeset_acquire_fini(&ctx);
16037 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
16039 if (IS_GEN(dev_priv, 5)) {
16041 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
16043 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
16044 } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) {
16045 dev_priv->fdi_pll_freq = 270000;
16050 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
16053 static int intel_initial_commit(struct drm_device *dev)
16055 struct drm_atomic_state *state = NULL;
16056 struct drm_modeset_acquire_ctx ctx;
16057 struct drm_crtc *crtc;
16058 struct drm_crtc_state *crtc_state;
16061 state = drm_atomic_state_alloc(dev);
16065 drm_modeset_acquire_init(&ctx, 0);
16068 state->acquire_ctx = &ctx;
16070 drm_for_each_crtc(crtc, dev) {
16071 crtc_state = drm_atomic_get_crtc_state(state, crtc);
16072 if (IS_ERR(crtc_state)) {
16073 ret = PTR_ERR(crtc_state);
16077 if (crtc_state->active) {
16078 ret = drm_atomic_add_affected_planes(state, crtc);
16083 * FIXME hack to force a LUT update to avoid the
16084 * plane update forcing the pipe gamma on without
16085 * having a proper LUT loaded. Remove once we
16086 * have readout for pipe gamma enable.
16088 crtc_state->color_mgmt_changed = true;
16092 ret = drm_atomic_commit(state);
16095 if (ret == -EDEADLK) {
16096 drm_atomic_state_clear(state);
16097 drm_modeset_backoff(&ctx);
16101 drm_atomic_state_put(state);
16103 drm_modeset_drop_locks(&ctx);
16104 drm_modeset_acquire_fini(&ctx);
16109 int intel_modeset_init(struct drm_device *dev)
16111 struct drm_i915_private *dev_priv = to_i915(dev);
16113 struct intel_crtc *crtc;
16116 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
16118 drm_mode_config_init(dev);
16120 ret = intel_bw_init(dev_priv);
16124 dev->mode_config.min_width = 0;
16125 dev->mode_config.min_height = 0;
16127 dev->mode_config.preferred_depth = 24;
16128 dev->mode_config.prefer_shadow = 1;
16130 dev->mode_config.allow_fb_modifiers = true;
16132 dev->mode_config.funcs = &intel_mode_funcs;
16134 init_llist_head(&dev_priv->atomic_helper.free_list);
16135 INIT_WORK(&dev_priv->atomic_helper.free_work,
16136 intel_atomic_helper_free_state_worker);
16138 intel_init_quirks(dev_priv);
16140 intel_fbc_init(dev_priv);
16142 intel_init_pm(dev_priv);
16145 * There may be no VBT; and if the BIOS enabled SSC we can
16146 * just keep using it to avoid unnecessary flicker. Whereas if the
16147 * BIOS isn't using it, don't assume it will work even if the VBT
16148 * indicates as much.
16150 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
16151 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
16154 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
16155 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
16156 bios_lvds_use_ssc ? "en" : "dis",
16157 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
16158 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
16163 * Maximum framebuffer dimensions, chosen to match
16164 * the maximum render engine surface size on gen4+.
16166 if (INTEL_GEN(dev_priv) >= 7) {
16167 dev->mode_config.max_width = 16384;
16168 dev->mode_config.max_height = 16384;
16169 } else if (INTEL_GEN(dev_priv) >= 4) {
16170 dev->mode_config.max_width = 8192;
16171 dev->mode_config.max_height = 8192;
16172 } else if (IS_GEN(dev_priv, 3)) {
16173 dev->mode_config.max_width = 4096;
16174 dev->mode_config.max_height = 4096;
16176 dev->mode_config.max_width = 2048;
16177 dev->mode_config.max_height = 2048;
16180 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
16181 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
16182 dev->mode_config.cursor_height = 1023;
16183 } else if (IS_GEN(dev_priv, 2)) {
16184 dev->mode_config.cursor_width = 64;
16185 dev->mode_config.cursor_height = 64;
16187 dev->mode_config.cursor_width = 256;
16188 dev->mode_config.cursor_height = 256;
16191 DRM_DEBUG_KMS("%d display pipe%s available.\n",
16192 INTEL_INFO(dev_priv)->num_pipes,
16193 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
16195 for_each_pipe(dev_priv, pipe) {
16196 ret = intel_crtc_init(dev_priv, pipe);
16198 drm_mode_config_cleanup(dev);
16203 intel_shared_dpll_init(dev);
16204 intel_update_fdi_pll_freq(dev_priv);
16206 intel_update_czclk(dev_priv);
16207 intel_modeset_init_hw(dev);
16209 intel_hdcp_component_init(dev_priv);
16211 if (dev_priv->max_cdclk_freq == 0)
16212 intel_update_max_cdclk(dev_priv);
16214 /* Just disable it once at startup */
16215 i915_disable_vga(dev_priv);
16216 intel_setup_outputs(dev_priv);
16218 drm_modeset_lock_all(dev);
16219 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
16220 drm_modeset_unlock_all(dev);
16222 for_each_intel_crtc(dev, crtc) {
16223 struct intel_initial_plane_config plane_config = {};
16229 * Note that reserving the BIOS fb up front prevents us
16230 * from stuffing other stolen allocations like the ring
16231 * on top. This prevents some ugliness at boot time, and
16232 * can even allow for smooth boot transitions if the BIOS
16233 * fb is large enough for the active pipe configuration.
16235 dev_priv->display.get_initial_plane_config(crtc,
16239 * If the fb is shared between multiple heads, we'll
16240 * just get the first one.
16242 intel_find_initial_plane_obj(crtc, &plane_config);
16246 * Make sure hardware watermarks really match the state we read out.
16247 * Note that we need to do this after reconstructing the BIOS fb's
16248 * since the watermark calculation done here will use pstate->fb.
16250 if (!HAS_GMCH(dev_priv))
16251 sanitize_watermarks(dev);
16254 * Force all active planes to recompute their states. So that on
16255 * mode_setcrtc after probe, all the intel_plane_state variables
16256 * are already calculated and there is no assert_plane warnings
16259 ret = intel_initial_commit(dev);
16261 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
16266 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
16268 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
16269 /* 640x480@60Hz, ~25175 kHz */
16270 struct dpll clock = {
16280 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
16282 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
16283 pipe_name(pipe), clock.vco, clock.dot);
16285 fp = i9xx_dpll_compute_fp(&clock);
16286 dpll = DPLL_DVO_2X_MODE |
16287 DPLL_VGA_MODE_DIS |
16288 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
16289 PLL_P2_DIVIDE_BY_4 |
16290 PLL_REF_INPUT_DREFCLK |
16293 I915_WRITE(FP0(pipe), fp);
16294 I915_WRITE(FP1(pipe), fp);
16296 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
16297 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
16298 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
16299 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
16300 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
16301 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
16302 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
16305 * Apparently we need to have VGA mode enabled prior to changing
16306 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
16307 * dividers, even though the register value does change.
16309 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
16310 I915_WRITE(DPLL(pipe), dpll);
16312 /* Wait for the clocks to stabilize. */
16313 POSTING_READ(DPLL(pipe));
16316 /* The pixel multiplier can only be updated once the
16317 * DPLL is enabled and the clocks are stable.
16319 * So write it again.
16321 I915_WRITE(DPLL(pipe), dpll);
16323 /* We do this three times for luck */
16324 for (i = 0; i < 3 ; i++) {
16325 I915_WRITE(DPLL(pipe), dpll);
16326 POSTING_READ(DPLL(pipe));
16327 udelay(150); /* wait for warmup */
16330 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
16331 POSTING_READ(PIPECONF(pipe));
16333 intel_wait_for_pipe_scanline_moving(crtc);
16336 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
16338 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
16340 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
16343 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
16344 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
16345 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
16346 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
16347 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
16349 I915_WRITE(PIPECONF(pipe), 0);
16350 POSTING_READ(PIPECONF(pipe));
16352 intel_wait_for_pipe_scanline_stopped(crtc);
16354 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
16355 POSTING_READ(DPLL(pipe));
16359 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
16361 struct intel_crtc *crtc;
16363 if (INTEL_GEN(dev_priv) >= 4)
16366 for_each_intel_crtc(&dev_priv->drm, crtc) {
16367 struct intel_plane *plane =
16368 to_intel_plane(crtc->base.primary);
16369 struct intel_crtc *plane_crtc;
16372 if (!plane->get_hw_state(plane, &pipe))
16375 if (pipe == crtc->pipe)
16378 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
16379 plane->base.base.id, plane->base.name);
16381 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
16382 intel_plane_disable_noatomic(plane_crtc, plane);
16386 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
16388 struct drm_device *dev = crtc->base.dev;
16389 struct intel_encoder *encoder;
16391 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
16397 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
16399 struct drm_device *dev = encoder->base.dev;
16400 struct intel_connector *connector;
16402 for_each_connector_on_encoder(dev, &encoder->base, connector)
16408 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
16409 enum pipe pch_transcoder)
16411 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
16412 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
16415 static void intel_sanitize_crtc(struct intel_crtc *crtc,
16416 struct drm_modeset_acquire_ctx *ctx)
16418 struct drm_device *dev = crtc->base.dev;
16419 struct drm_i915_private *dev_priv = to_i915(dev);
16420 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
16421 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
16423 /* Clear any frame start delays used for debugging left by the BIOS */
16424 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
16425 i915_reg_t reg = PIPECONF(cpu_transcoder);
16428 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
16431 if (crtc_state->base.active) {
16432 struct intel_plane *plane;
16434 /* Disable everything but the primary plane */
16435 for_each_intel_plane_on_crtc(dev, crtc, plane) {
16436 const struct intel_plane_state *plane_state =
16437 to_intel_plane_state(plane->base.state);
16439 if (plane_state->base.visible &&
16440 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
16441 intel_plane_disable_noatomic(crtc, plane);
16445 * Disable any background color set by the BIOS, but enable the
16446 * gamma and CSC to match how we program our planes.
16448 if (INTEL_GEN(dev_priv) >= 9)
16449 I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe),
16450 SKL_BOTTOM_COLOR_GAMMA_ENABLE |
16451 SKL_BOTTOM_COLOR_CSC_ENABLE);
16454 /* Adjust the state of the output pipe according to whether we
16455 * have active connectors/encoders. */
16456 if (crtc_state->base.active && !intel_crtc_has_encoders(crtc))
16457 intel_crtc_disable_noatomic(&crtc->base, ctx);
16459 if (crtc_state->base.active || HAS_GMCH(dev_priv)) {
16461 * We start out with underrun reporting disabled to avoid races.
16462 * For correct bookkeeping mark this on active crtcs.
16464 * Also on gmch platforms we dont have any hardware bits to
16465 * disable the underrun reporting. Which means we need to start
16466 * out with underrun reporting disabled also on inactive pipes,
16467 * since otherwise we'll complain about the garbage we read when
16468 * e.g. coming up after runtime pm.
16470 * No protection against concurrent access is required - at
16471 * worst a fifo underrun happens which also sets this to false.
16473 crtc->cpu_fifo_underrun_disabled = true;
16475 * We track the PCH trancoder underrun reporting state
16476 * within the crtc. With crtc for pipe A housing the underrun
16477 * reporting state for PCH transcoder A, crtc for pipe B housing
16478 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
16479 * and marking underrun reporting as disabled for the non-existing
16480 * PCH transcoders B and C would prevent enabling the south
16481 * error interrupt (see cpt_can_enable_serr_int()).
16483 if (has_pch_trancoder(dev_priv, crtc->pipe))
16484 crtc->pch_fifo_underrun_disabled = true;
16488 static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state)
16490 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
16493 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
16494 * the hardware when a high res displays plugged in. DPLL P
16495 * divider is zero, and the pipe timings are bonkers. We'll
16496 * try to disable everything in that case.
16498 * FIXME would be nice to be able to sanitize this state
16499 * without several WARNs, but for now let's take the easy
16502 return IS_GEN(dev_priv, 6) &&
16503 crtc_state->base.active &&
16504 crtc_state->shared_dpll &&
16505 crtc_state->port_clock == 0;
16508 static void intel_sanitize_encoder(struct intel_encoder *encoder)
16510 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
16511 struct intel_connector *connector;
16512 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
16513 struct intel_crtc_state *crtc_state = crtc ?
16514 to_intel_crtc_state(crtc->base.state) : NULL;
16516 /* We need to check both for a crtc link (meaning that the
16517 * encoder is active and trying to read from a pipe) and the
16518 * pipe itself being active. */
16519 bool has_active_crtc = crtc_state &&
16520 crtc_state->base.active;
16522 if (crtc_state && has_bogus_dpll_config(crtc_state)) {
16523 DRM_DEBUG_KMS("BIOS has misprogrammed the hardware. Disabling pipe %c\n",
16524 pipe_name(crtc->pipe));
16525 has_active_crtc = false;
16528 connector = intel_encoder_find_connector(encoder);
16529 if (connector && !has_active_crtc) {
16530 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
16531 encoder->base.base.id,
16532 encoder->base.name);
16534 /* Connector is active, but has no active pipe. This is
16535 * fallout from our resume register restoring. Disable
16536 * the encoder manually again. */
16538 struct drm_encoder *best_encoder;
16540 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
16541 encoder->base.base.id,
16542 encoder->base.name);
16544 /* avoid oopsing in case the hooks consult best_encoder */
16545 best_encoder = connector->base.state->best_encoder;
16546 connector->base.state->best_encoder = &encoder->base;
16548 if (encoder->disable)
16549 encoder->disable(encoder, crtc_state,
16550 connector->base.state);
16551 if (encoder->post_disable)
16552 encoder->post_disable(encoder, crtc_state,
16553 connector->base.state);
16555 connector->base.state->best_encoder = best_encoder;
16557 encoder->base.crtc = NULL;
16559 /* Inconsistent output/port/pipe state happens presumably due to
16560 * a bug in one of the get_hw_state functions. Or someplace else
16561 * in our code, like the register restore mess on resume. Clamp
16562 * things to off as a safer default. */
16564 connector->base.dpms = DRM_MODE_DPMS_OFF;
16565 connector->base.encoder = NULL;
16568 /* notify opregion of the sanitized encoder state */
16569 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
16571 if (INTEL_GEN(dev_priv) >= 11)
16572 icl_sanitize_encoder_pll_mapping(encoder);
16575 void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
16577 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
16579 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
16580 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
16581 i915_disable_vga(dev_priv);
16585 void i915_redisable_vga(struct drm_i915_private *dev_priv)
16587 intel_wakeref_t wakeref;
16590 * This function can be called both from intel_modeset_setup_hw_state or
16591 * at a very early point in our resume sequence, where the power well
16592 * structures are not yet restored. Since this function is at a very
16593 * paranoid "someone might have enabled VGA while we were not looking"
16594 * level, just check if the power well is enabled instead of trying to
16595 * follow the "don't touch the power well if we don't need it" policy
16596 * the rest of the driver uses.
16598 wakeref = intel_display_power_get_if_enabled(dev_priv,
16603 i915_redisable_vga_power_on(dev_priv);
16605 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA, wakeref);
16608 /* FIXME read out full plane state for all planes */
16609 static void readout_plane_state(struct drm_i915_private *dev_priv)
16611 struct intel_plane *plane;
16612 struct intel_crtc *crtc;
16614 for_each_intel_plane(&dev_priv->drm, plane) {
16615 struct intel_plane_state *plane_state =
16616 to_intel_plane_state(plane->base.state);
16617 struct intel_crtc_state *crtc_state;
16618 enum pipe pipe = PIPE_A;
16621 visible = plane->get_hw_state(plane, &pipe);
16623 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
16624 crtc_state = to_intel_crtc_state(crtc->base.state);
16626 intel_set_plane_visible(crtc_state, plane_state, visible);
16628 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
16629 plane->base.base.id, plane->base.name,
16630 enableddisabled(visible), pipe_name(pipe));
16633 for_each_intel_crtc(&dev_priv->drm, crtc) {
16634 struct intel_crtc_state *crtc_state =
16635 to_intel_crtc_state(crtc->base.state);
16637 fixup_active_planes(crtc_state);
16641 static void intel_modeset_readout_hw_state(struct drm_device *dev)
16643 struct drm_i915_private *dev_priv = to_i915(dev);
16645 struct intel_crtc *crtc;
16646 struct intel_encoder *encoder;
16647 struct intel_connector *connector;
16648 struct drm_connector_list_iter conn_iter;
16651 dev_priv->active_pipes = 0;
16653 for_each_intel_crtc(dev, crtc) {
16654 struct intel_crtc_state *crtc_state =
16655 to_intel_crtc_state(crtc->base.state);
16657 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
16658 memset(crtc_state, 0, sizeof(*crtc_state));
16659 __drm_atomic_helper_crtc_reset(&crtc->base, &crtc_state->base);
16661 crtc_state->base.active = crtc_state->base.enable =
16662 dev_priv->display.get_pipe_config(crtc, crtc_state);
16664 crtc->base.enabled = crtc_state->base.enable;
16665 crtc->active = crtc_state->base.active;
16667 if (crtc_state->base.active)
16668 dev_priv->active_pipes |= BIT(crtc->pipe);
16670 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
16671 crtc->base.base.id, crtc->base.name,
16672 enableddisabled(crtc_state->base.active));
16675 readout_plane_state(dev_priv);
16677 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
16678 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
16680 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
16681 &pll->state.hw_state);
16683 if (IS_ELKHARTLAKE(dev_priv) && pll->on &&
16684 pll->info->id == DPLL_ID_EHL_DPLL4) {
16685 pll->wakeref = intel_display_power_get(dev_priv,
16686 POWER_DOMAIN_DPLL_DC_OFF);
16689 pll->state.crtc_mask = 0;
16690 for_each_intel_crtc(dev, crtc) {
16691 struct intel_crtc_state *crtc_state =
16692 to_intel_crtc_state(crtc->base.state);
16694 if (crtc_state->base.active &&
16695 crtc_state->shared_dpll == pll)
16696 pll->state.crtc_mask |= 1 << crtc->pipe;
16698 pll->active_mask = pll->state.crtc_mask;
16700 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
16701 pll->info->name, pll->state.crtc_mask, pll->on);
16704 for_each_intel_encoder(dev, encoder) {
16707 if (encoder->get_hw_state(encoder, &pipe)) {
16708 struct intel_crtc_state *crtc_state;
16710 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
16711 crtc_state = to_intel_crtc_state(crtc->base.state);
16713 encoder->base.crtc = &crtc->base;
16714 encoder->get_config(encoder, crtc_state);
16716 encoder->base.crtc = NULL;
16719 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
16720 encoder->base.base.id, encoder->base.name,
16721 enableddisabled(encoder->base.crtc),
16725 drm_connector_list_iter_begin(dev, &conn_iter);
16726 for_each_intel_connector_iter(connector, &conn_iter) {
16727 if (connector->get_hw_state(connector)) {
16728 connector->base.dpms = DRM_MODE_DPMS_ON;
16730 encoder = connector->encoder;
16731 connector->base.encoder = &encoder->base;
16733 if (encoder->base.crtc &&
16734 encoder->base.crtc->state->active) {
16736 * This has to be done during hardware readout
16737 * because anything calling .crtc_disable may
16738 * rely on the connector_mask being accurate.
16740 encoder->base.crtc->state->connector_mask |=
16741 drm_connector_mask(&connector->base);
16742 encoder->base.crtc->state->encoder_mask |=
16743 drm_encoder_mask(&encoder->base);
16747 connector->base.dpms = DRM_MODE_DPMS_OFF;
16748 connector->base.encoder = NULL;
16750 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
16751 connector->base.base.id, connector->base.name,
16752 enableddisabled(connector->base.encoder));
16754 drm_connector_list_iter_end(&conn_iter);
16756 for_each_intel_crtc(dev, crtc) {
16757 struct intel_bw_state *bw_state =
16758 to_intel_bw_state(dev_priv->bw_obj.state);
16759 struct intel_crtc_state *crtc_state =
16760 to_intel_crtc_state(crtc->base.state);
16761 struct intel_plane *plane;
16764 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
16765 if (crtc_state->base.active) {
16766 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
16767 crtc->base.mode.hdisplay = crtc_state->pipe_src_w;
16768 crtc->base.mode.vdisplay = crtc_state->pipe_src_h;
16769 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
16770 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
16773 * The initial mode needs to be set in order to keep
16774 * the atomic core happy. It wants a valid mode if the
16775 * crtc's enabled, so we do the above call.
16777 * But we don't set all the derived state fully, hence
16778 * set a flag to indicate that a full recalculation is
16779 * needed on the next commit.
16781 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
16783 intel_crtc_compute_pixel_rate(crtc_state);
16785 if (dev_priv->display.modeset_calc_cdclk) {
16786 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
16787 if (WARN_ON(min_cdclk < 0))
16791 drm_calc_timestamping_constants(&crtc->base,
16792 &crtc_state->base.adjusted_mode);
16793 update_scanline_offset(crtc_state);
16796 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
16797 dev_priv->min_voltage_level[crtc->pipe] =
16798 crtc_state->min_voltage_level;
16800 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
16801 const struct intel_plane_state *plane_state =
16802 to_intel_plane_state(plane->base.state);
16805 * FIXME don't have the fb yet, so can't
16806 * use intel_plane_data_rate() :(
16808 if (plane_state->base.visible)
16809 crtc_state->data_rate[plane->id] =
16810 4 * crtc_state->pixel_rate;
16813 intel_bw_crtc_update(bw_state, crtc_state);
16815 intel_pipe_config_sanity_check(dev_priv, crtc_state);
16820 get_encoder_power_domains(struct drm_i915_private *dev_priv)
16822 struct intel_encoder *encoder;
16824 for_each_intel_encoder(&dev_priv->drm, encoder) {
16825 struct intel_crtc_state *crtc_state;
16827 if (!encoder->get_power_domains)
16831 * MST-primary and inactive encoders don't have a crtc state
16832 * and neither of these require any power domain references.
16834 if (!encoder->base.crtc)
16837 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
16838 encoder->get_power_domains(encoder, crtc_state);
16842 static void intel_early_display_was(struct drm_i915_private *dev_priv)
16844 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
16845 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
16846 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
16849 if (IS_HASWELL(dev_priv)) {
16851 * WaRsPkgCStateDisplayPMReq:hsw
16852 * System hang if this isn't done before disabling all planes!
16854 I915_WRITE(CHICKEN_PAR1_1,
16855 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
16859 static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
16860 enum port port, i915_reg_t hdmi_reg)
16862 u32 val = I915_READ(hdmi_reg);
16864 if (val & SDVO_ENABLE ||
16865 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
16868 DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n",
16871 val &= ~SDVO_PIPE_SEL_MASK;
16872 val |= SDVO_PIPE_SEL(PIPE_A);
16874 I915_WRITE(hdmi_reg, val);
16877 static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
16878 enum port port, i915_reg_t dp_reg)
16880 u32 val = I915_READ(dp_reg);
16882 if (val & DP_PORT_EN ||
16883 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
16886 DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n",
16889 val &= ~DP_PIPE_SEL_MASK;
16890 val |= DP_PIPE_SEL(PIPE_A);
16892 I915_WRITE(dp_reg, val);
16895 static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
16898 * The BIOS may select transcoder B on some of the PCH
16899 * ports even it doesn't enable the port. This would trip
16900 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
16901 * Sanitize the transcoder select bits to prevent that. We
16902 * assume that the BIOS never actually enabled the port,
16903 * because if it did we'd actually have to toggle the port
16904 * on and back off to make the transcoder A select stick
16905 * (see. intel_dp_link_down(), intel_disable_hdmi(),
16906 * intel_disable_sdvo()).
16908 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
16909 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
16910 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
16912 /* PCH SDVOB multiplex with HDMIB */
16913 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
16914 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
16915 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
16918 /* Scan out the current hw modeset state,
16919 * and sanitizes it to the current state
16922 intel_modeset_setup_hw_state(struct drm_device *dev,
16923 struct drm_modeset_acquire_ctx *ctx)
16925 struct drm_i915_private *dev_priv = to_i915(dev);
16926 struct intel_crtc_state *crtc_state;
16927 struct intel_encoder *encoder;
16928 struct intel_crtc *crtc;
16929 intel_wakeref_t wakeref;
16932 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
16934 intel_early_display_was(dev_priv);
16935 intel_modeset_readout_hw_state(dev);
16937 /* HW state is read out, now we need to sanitize this mess. */
16939 /* Sanitize the TypeC port mode upfront, encoders depend on this */
16940 for_each_intel_encoder(dev, encoder) {
16941 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
16943 /* We need to sanitize only the MST primary port. */
16944 if (encoder->type != INTEL_OUTPUT_DP_MST &&
16945 intel_phy_is_tc(dev_priv, phy))
16946 intel_tc_port_sanitize(enc_to_dig_port(&encoder->base));
16949 get_encoder_power_domains(dev_priv);
16951 if (HAS_PCH_IBX(dev_priv))
16952 ibx_sanitize_pch_ports(dev_priv);
16955 * intel_sanitize_plane_mapping() may need to do vblank
16956 * waits, so we need vblank interrupts restored beforehand.
16958 for_each_intel_crtc(&dev_priv->drm, crtc) {
16959 crtc_state = to_intel_crtc_state(crtc->base.state);
16961 drm_crtc_vblank_reset(&crtc->base);
16963 if (crtc_state->base.active)
16964 intel_crtc_vblank_on(crtc_state);
16967 intel_sanitize_plane_mapping(dev_priv);
16969 for_each_intel_encoder(dev, encoder)
16970 intel_sanitize_encoder(encoder);
16972 for_each_intel_crtc(&dev_priv->drm, crtc) {
16973 crtc_state = to_intel_crtc_state(crtc->base.state);
16974 intel_sanitize_crtc(crtc, ctx);
16975 intel_dump_pipe_config(crtc_state, NULL, "[setup_hw_state]");
16978 intel_modeset_update_connector_atomic_state(dev);
16980 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
16981 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
16983 if (!pll->on || pll->active_mask)
16986 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
16989 pll->info->funcs->disable(dev_priv, pll);
16993 if (IS_G4X(dev_priv)) {
16994 g4x_wm_get_hw_state(dev_priv);
16995 g4x_wm_sanitize(dev_priv);
16996 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
16997 vlv_wm_get_hw_state(dev_priv);
16998 vlv_wm_sanitize(dev_priv);
16999 } else if (INTEL_GEN(dev_priv) >= 9) {
17000 skl_wm_get_hw_state(dev_priv);
17001 } else if (HAS_PCH_SPLIT(dev_priv)) {
17002 ilk_wm_get_hw_state(dev_priv);
17005 for_each_intel_crtc(dev, crtc) {
17008 crtc_state = to_intel_crtc_state(crtc->base.state);
17009 put_domains = modeset_get_crtc_power_domains(crtc_state);
17010 if (WARN_ON(put_domains))
17011 modeset_put_power_domains(dev_priv, put_domains);
17014 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
17016 intel_fbc_init_pipe_state(dev_priv);
17019 void intel_display_resume(struct drm_device *dev)
17021 struct drm_i915_private *dev_priv = to_i915(dev);
17022 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
17023 struct drm_modeset_acquire_ctx ctx;
17026 dev_priv->modeset_restore_state = NULL;
17028 state->acquire_ctx = &ctx;
17030 drm_modeset_acquire_init(&ctx, 0);
17033 ret = drm_modeset_lock_all_ctx(dev, &ctx);
17034 if (ret != -EDEADLK)
17037 drm_modeset_backoff(&ctx);
17041 ret = __intel_display_resume(dev, state, &ctx);
17043 intel_enable_ipc(dev_priv);
17044 drm_modeset_drop_locks(&ctx);
17045 drm_modeset_acquire_fini(&ctx);
17048 DRM_ERROR("Restoring old state failed with %i\n", ret);
17050 drm_atomic_state_put(state);
17053 static void intel_hpd_poll_fini(struct drm_device *dev)
17055 struct intel_connector *connector;
17056 struct drm_connector_list_iter conn_iter;
17058 /* Kill all the work that may have been queued by hpd. */
17059 drm_connector_list_iter_begin(dev, &conn_iter);
17060 for_each_intel_connector_iter(connector, &conn_iter) {
17061 if (connector->modeset_retry_work.func)
17062 cancel_work_sync(&connector->modeset_retry_work);
17063 if (connector->hdcp.shim) {
17064 cancel_delayed_work_sync(&connector->hdcp.check_work);
17065 cancel_work_sync(&connector->hdcp.prop_work);
17068 drm_connector_list_iter_end(&conn_iter);
17071 void intel_modeset_driver_remove(struct drm_device *dev)
17073 struct drm_i915_private *dev_priv = to_i915(dev);
17075 flush_workqueue(dev_priv->modeset_wq);
17077 flush_work(&dev_priv->atomic_helper.free_work);
17078 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
17081 * Interrupts and polling as the first thing to avoid creating havoc.
17082 * Too much stuff here (turning of connectors, ...) would
17083 * experience fancy races otherwise.
17085 intel_irq_uninstall(dev_priv);
17088 * Due to the hpd irq storm handling the hotplug work can re-arm the
17089 * poll handlers. Hence disable polling after hpd handling is shut down.
17091 intel_hpd_poll_fini(dev);
17093 /* poll work can call into fbdev, hence clean that up afterwards */
17094 intel_fbdev_fini(dev_priv);
17096 intel_unregister_dsm_handler();
17098 intel_fbc_global_disable(dev_priv);
17100 /* flush any delayed tasks or pending work */
17101 flush_scheduled_work();
17103 intel_hdcp_component_fini(dev_priv);
17105 drm_mode_config_cleanup(dev);
17107 intel_overlay_cleanup(dev_priv);
17109 intel_gmbus_teardown(dev_priv);
17111 destroy_workqueue(dev_priv->modeset_wq);
17113 intel_fbc_cleanup_cfb(dev_priv);
17117 * set vga decode state - true == enable VGA decode
17119 int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
17121 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
17124 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
17125 DRM_ERROR("failed to read control word\n");
17129 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
17133 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
17135 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
17137 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
17138 DRM_ERROR("failed to write control word\n");
17145 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
17147 struct intel_display_error_state {
17149 u32 power_well_driver;
17151 struct intel_cursor_error_state {
17156 } cursor[I915_MAX_PIPES];
17158 struct intel_pipe_error_state {
17159 bool power_domain_on;
17162 } pipe[I915_MAX_PIPES];
17164 struct intel_plane_error_state {
17172 } plane[I915_MAX_PIPES];
17174 struct intel_transcoder_error_state {
17176 bool power_domain_on;
17177 enum transcoder cpu_transcoder;
17190 struct intel_display_error_state *
17191 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
17193 struct intel_display_error_state *error;
17194 int transcoders[] = {
17203 BUILD_BUG_ON(ARRAY_SIZE(transcoders) != ARRAY_SIZE(error->transcoder));
17205 if (!HAS_DISPLAY(dev_priv))
17208 error = kzalloc(sizeof(*error), GFP_ATOMIC);
17212 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
17213 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
17215 for_each_pipe(dev_priv, i) {
17216 error->pipe[i].power_domain_on =
17217 __intel_display_power_is_enabled(dev_priv,
17218 POWER_DOMAIN_PIPE(i));
17219 if (!error->pipe[i].power_domain_on)
17222 error->cursor[i].control = I915_READ(CURCNTR(i));
17223 error->cursor[i].position = I915_READ(CURPOS(i));
17224 error->cursor[i].base = I915_READ(CURBASE(i));
17226 error->plane[i].control = I915_READ(DSPCNTR(i));
17227 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
17228 if (INTEL_GEN(dev_priv) <= 3) {
17229 error->plane[i].size = I915_READ(DSPSIZE(i));
17230 error->plane[i].pos = I915_READ(DSPPOS(i));
17232 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
17233 error->plane[i].addr = I915_READ(DSPADDR(i));
17234 if (INTEL_GEN(dev_priv) >= 4) {
17235 error->plane[i].surface = I915_READ(DSPSURF(i));
17236 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
17239 error->pipe[i].source = I915_READ(PIPESRC(i));
17241 if (HAS_GMCH(dev_priv))
17242 error->pipe[i].stat = I915_READ(PIPESTAT(i));
17245 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
17246 enum transcoder cpu_transcoder = transcoders[i];
17248 if (!INTEL_INFO(dev_priv)->trans_offsets[cpu_transcoder])
17251 error->transcoder[i].available = true;
17252 error->transcoder[i].power_domain_on =
17253 __intel_display_power_is_enabled(dev_priv,
17254 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
17255 if (!error->transcoder[i].power_domain_on)
17258 error->transcoder[i].cpu_transcoder = cpu_transcoder;
17260 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
17261 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
17262 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
17263 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
17264 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
17265 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
17266 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
17272 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
17275 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
17276 struct intel_display_error_state *error)
17278 struct drm_i915_private *dev_priv = m->i915;
17284 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
17285 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
17286 err_printf(m, "PWR_WELL_CTL2: %08x\n",
17287 error->power_well_driver);
17288 for_each_pipe(dev_priv, i) {
17289 err_printf(m, "Pipe [%d]:\n", i);
17290 err_printf(m, " Power: %s\n",
17291 onoff(error->pipe[i].power_domain_on));
17292 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
17293 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
17295 err_printf(m, "Plane [%d]:\n", i);
17296 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
17297 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
17298 if (INTEL_GEN(dev_priv) <= 3) {
17299 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
17300 err_printf(m, " POS: %08x\n", error->plane[i].pos);
17302 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
17303 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
17304 if (INTEL_GEN(dev_priv) >= 4) {
17305 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
17306 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
17309 err_printf(m, "Cursor [%d]:\n", i);
17310 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
17311 err_printf(m, " POS: %08x\n", error->cursor[i].position);
17312 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
17315 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
17316 if (!error->transcoder[i].available)
17319 err_printf(m, "CPU transcoder: %s\n",
17320 transcoder_name(error->transcoder[i].cpu_transcoder));
17321 err_printf(m, " Power: %s\n",
17322 onoff(error->transcoder[i].power_domain_on));
17323 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
17324 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
17325 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
17326 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
17327 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
17328 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
17329 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);