2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
27 #include <linux/i2c.h>
28 #include <linux/input.h>
29 #include <linux/intel-iommu.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/reservation.h>
33 #include <linux/slab.h>
34 #include <linux/vgaarb.h>
36 #include <drm/drm_atomic.h>
37 #include <drm/drm_atomic_helper.h>
38 #include <drm/drm_atomic_uapi.h>
39 #include <drm/drm_dp_helper.h>
40 #include <drm/drm_edid.h>
41 #include <drm/drm_fourcc.h>
42 #include <drm/drm_plane_helper.h>
43 #include <drm/drm_probe_helper.h>
44 #include <drm/drm_rect.h>
45 #include <drm/i915_drm.h>
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_color.h"
66 #include "intel_cdclk.h"
67 #include "intel_drv.h"
68 #include "intel_fbc.h"
69 #include "intel_fbdev.h"
70 #include "intel_fifo_underrun.h"
71 #include "intel_frontbuffer.h"
72 #include "intel_hdcp.h"
73 #include "intel_hotplug.h"
74 #include "intel_overlay.h"
75 #include "intel_pipe_crc.h"
77 #include "intel_psr.h"
78 #include "intel_quirks.h"
79 #include "intel_sideband.h"
80 #include "intel_sprite.h"
83 /* Primary plane formats for gen <= 3 */
84 static const u32 i8xx_primary_formats[] = {
91 /* Primary plane formats for gen >= 4 */
92 static const u32 i965_primary_formats[] = {
97 DRM_FORMAT_XRGB2101010,
98 DRM_FORMAT_XBGR2101010,
101 static const u64 i9xx_format_modifiers[] = {
102 I915_FORMAT_MOD_X_TILED,
103 DRM_FORMAT_MOD_LINEAR,
104 DRM_FORMAT_MOD_INVALID
108 static const u32 intel_cursor_formats[] = {
112 static const u64 cursor_format_modifiers[] = {
113 DRM_FORMAT_MOD_LINEAR,
114 DRM_FORMAT_MOD_INVALID
117 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
118 struct intel_crtc_state *pipe_config);
119 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
120 struct intel_crtc_state *pipe_config);
122 static int intel_framebuffer_init(struct intel_framebuffer *ifb,
123 struct drm_i915_gem_object *obj,
124 struct drm_mode_fb_cmd2 *mode_cmd);
125 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state);
126 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
127 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
128 const struct intel_link_m_n *m_n,
129 const struct intel_link_m_n *m2_n2);
130 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
131 static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state);
132 static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state);
133 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state);
134 static void vlv_prepare_pll(struct intel_crtc *crtc,
135 const struct intel_crtc_state *pipe_config);
136 static void chv_prepare_pll(struct intel_crtc *crtc,
137 const struct intel_crtc_state *pipe_config);
138 static void intel_begin_crtc_commit(struct intel_atomic_state *, struct intel_crtc *);
139 static void intel_finish_crtc_commit(struct intel_atomic_state *, struct intel_crtc *);
140 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
141 struct intel_crtc_state *crtc_state);
142 static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state);
143 static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state);
144 static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state);
145 static void intel_modeset_setup_hw_state(struct drm_device *dev,
146 struct drm_modeset_acquire_ctx *ctx);
147 static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc);
152 } dot, vco, n, m, m1, m2, p, p1;
156 int p2_slow, p2_fast;
160 /* returns HPLL frequency in kHz */
161 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
163 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
165 /* Obtain SKU information */
166 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
167 CCK_FUSE_HPLL_FREQ_MASK;
169 return vco_freq[hpll_freq] * 1000;
172 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
173 const char *name, u32 reg, int ref_freq)
178 val = vlv_cck_read(dev_priv, reg);
179 divider = val & CCK_FREQUENCY_VALUES;
181 WARN((val & CCK_FREQUENCY_STATUS) !=
182 (divider << CCK_FREQUENCY_STATUS_SHIFT),
183 "%s change in progress\n", name);
185 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
188 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
189 const char *name, u32 reg)
193 vlv_cck_get(dev_priv);
195 if (dev_priv->hpll_freq == 0)
196 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
198 hpll = vlv_get_cck_clock(dev_priv, name, reg, dev_priv->hpll_freq);
200 vlv_cck_put(dev_priv);
205 static void intel_update_czclk(struct drm_i915_private *dev_priv)
207 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
210 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
211 CCK_CZ_CLOCK_CONTROL);
213 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
216 static inline u32 /* units of 100MHz */
217 intel_fdi_link_freq(struct drm_i915_private *dev_priv,
218 const struct intel_crtc_state *pipe_config)
220 if (HAS_DDI(dev_priv))
221 return pipe_config->port_clock; /* SPLL */
223 return dev_priv->fdi_pll_freq;
226 static const struct intel_limit intel_limits_i8xx_dac = {
227 .dot = { .min = 25000, .max = 350000 },
228 .vco = { .min = 908000, .max = 1512000 },
229 .n = { .min = 2, .max = 16 },
230 .m = { .min = 96, .max = 140 },
231 .m1 = { .min = 18, .max = 26 },
232 .m2 = { .min = 6, .max = 16 },
233 .p = { .min = 4, .max = 128 },
234 .p1 = { .min = 2, .max = 33 },
235 .p2 = { .dot_limit = 165000,
236 .p2_slow = 4, .p2_fast = 2 },
239 static const struct intel_limit intel_limits_i8xx_dvo = {
240 .dot = { .min = 25000, .max = 350000 },
241 .vco = { .min = 908000, .max = 1512000 },
242 .n = { .min = 2, .max = 16 },
243 .m = { .min = 96, .max = 140 },
244 .m1 = { .min = 18, .max = 26 },
245 .m2 = { .min = 6, .max = 16 },
246 .p = { .min = 4, .max = 128 },
247 .p1 = { .min = 2, .max = 33 },
248 .p2 = { .dot_limit = 165000,
249 .p2_slow = 4, .p2_fast = 4 },
252 static const struct intel_limit intel_limits_i8xx_lvds = {
253 .dot = { .min = 25000, .max = 350000 },
254 .vco = { .min = 908000, .max = 1512000 },
255 .n = { .min = 2, .max = 16 },
256 .m = { .min = 96, .max = 140 },
257 .m1 = { .min = 18, .max = 26 },
258 .m2 = { .min = 6, .max = 16 },
259 .p = { .min = 4, .max = 128 },
260 .p1 = { .min = 1, .max = 6 },
261 .p2 = { .dot_limit = 165000,
262 .p2_slow = 14, .p2_fast = 7 },
265 static const struct intel_limit intel_limits_i9xx_sdvo = {
266 .dot = { .min = 20000, .max = 400000 },
267 .vco = { .min = 1400000, .max = 2800000 },
268 .n = { .min = 1, .max = 6 },
269 .m = { .min = 70, .max = 120 },
270 .m1 = { .min = 8, .max = 18 },
271 .m2 = { .min = 3, .max = 7 },
272 .p = { .min = 5, .max = 80 },
273 .p1 = { .min = 1, .max = 8 },
274 .p2 = { .dot_limit = 200000,
275 .p2_slow = 10, .p2_fast = 5 },
278 static const struct intel_limit intel_limits_i9xx_lvds = {
279 .dot = { .min = 20000, .max = 400000 },
280 .vco = { .min = 1400000, .max = 2800000 },
281 .n = { .min = 1, .max = 6 },
282 .m = { .min = 70, .max = 120 },
283 .m1 = { .min = 8, .max = 18 },
284 .m2 = { .min = 3, .max = 7 },
285 .p = { .min = 7, .max = 98 },
286 .p1 = { .min = 1, .max = 8 },
287 .p2 = { .dot_limit = 112000,
288 .p2_slow = 14, .p2_fast = 7 },
292 static const struct intel_limit intel_limits_g4x_sdvo = {
293 .dot = { .min = 25000, .max = 270000 },
294 .vco = { .min = 1750000, .max = 3500000},
295 .n = { .min = 1, .max = 4 },
296 .m = { .min = 104, .max = 138 },
297 .m1 = { .min = 17, .max = 23 },
298 .m2 = { .min = 5, .max = 11 },
299 .p = { .min = 10, .max = 30 },
300 .p1 = { .min = 1, .max = 3},
301 .p2 = { .dot_limit = 270000,
307 static const struct intel_limit intel_limits_g4x_hdmi = {
308 .dot = { .min = 22000, .max = 400000 },
309 .vco = { .min = 1750000, .max = 3500000},
310 .n = { .min = 1, .max = 4 },
311 .m = { .min = 104, .max = 138 },
312 .m1 = { .min = 16, .max = 23 },
313 .m2 = { .min = 5, .max = 11 },
314 .p = { .min = 5, .max = 80 },
315 .p1 = { .min = 1, .max = 8},
316 .p2 = { .dot_limit = 165000,
317 .p2_slow = 10, .p2_fast = 5 },
320 static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
321 .dot = { .min = 20000, .max = 115000 },
322 .vco = { .min = 1750000, .max = 3500000 },
323 .n = { .min = 1, .max = 3 },
324 .m = { .min = 104, .max = 138 },
325 .m1 = { .min = 17, .max = 23 },
326 .m2 = { .min = 5, .max = 11 },
327 .p = { .min = 28, .max = 112 },
328 .p1 = { .min = 2, .max = 8 },
329 .p2 = { .dot_limit = 0,
330 .p2_slow = 14, .p2_fast = 14
334 static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
335 .dot = { .min = 80000, .max = 224000 },
336 .vco = { .min = 1750000, .max = 3500000 },
337 .n = { .min = 1, .max = 3 },
338 .m = { .min = 104, .max = 138 },
339 .m1 = { .min = 17, .max = 23 },
340 .m2 = { .min = 5, .max = 11 },
341 .p = { .min = 14, .max = 42 },
342 .p1 = { .min = 2, .max = 6 },
343 .p2 = { .dot_limit = 0,
344 .p2_slow = 7, .p2_fast = 7
348 static const struct intel_limit intel_limits_pineview_sdvo = {
349 .dot = { .min = 20000, .max = 400000},
350 .vco = { .min = 1700000, .max = 3500000 },
351 /* Pineview's Ncounter is a ring counter */
352 .n = { .min = 3, .max = 6 },
353 .m = { .min = 2, .max = 256 },
354 /* Pineview only has one combined m divider, which we treat as m2. */
355 .m1 = { .min = 0, .max = 0 },
356 .m2 = { .min = 0, .max = 254 },
357 .p = { .min = 5, .max = 80 },
358 .p1 = { .min = 1, .max = 8 },
359 .p2 = { .dot_limit = 200000,
360 .p2_slow = 10, .p2_fast = 5 },
363 static const struct intel_limit intel_limits_pineview_lvds = {
364 .dot = { .min = 20000, .max = 400000 },
365 .vco = { .min = 1700000, .max = 3500000 },
366 .n = { .min = 3, .max = 6 },
367 .m = { .min = 2, .max = 256 },
368 .m1 = { .min = 0, .max = 0 },
369 .m2 = { .min = 0, .max = 254 },
370 .p = { .min = 7, .max = 112 },
371 .p1 = { .min = 1, .max = 8 },
372 .p2 = { .dot_limit = 112000,
373 .p2_slow = 14, .p2_fast = 14 },
376 /* Ironlake / Sandybridge
378 * We calculate clock using (register_value + 2) for N/M1/M2, so here
379 * the range value for them is (actual_value - 2).
381 static const struct intel_limit intel_limits_ironlake_dac = {
382 .dot = { .min = 25000, .max = 350000 },
383 .vco = { .min = 1760000, .max = 3510000 },
384 .n = { .min = 1, .max = 5 },
385 .m = { .min = 79, .max = 127 },
386 .m1 = { .min = 12, .max = 22 },
387 .m2 = { .min = 5, .max = 9 },
388 .p = { .min = 5, .max = 80 },
389 .p1 = { .min = 1, .max = 8 },
390 .p2 = { .dot_limit = 225000,
391 .p2_slow = 10, .p2_fast = 5 },
394 static const struct intel_limit intel_limits_ironlake_single_lvds = {
395 .dot = { .min = 25000, .max = 350000 },
396 .vco = { .min = 1760000, .max = 3510000 },
397 .n = { .min = 1, .max = 3 },
398 .m = { .min = 79, .max = 118 },
399 .m1 = { .min = 12, .max = 22 },
400 .m2 = { .min = 5, .max = 9 },
401 .p = { .min = 28, .max = 112 },
402 .p1 = { .min = 2, .max = 8 },
403 .p2 = { .dot_limit = 225000,
404 .p2_slow = 14, .p2_fast = 14 },
407 static const struct intel_limit intel_limits_ironlake_dual_lvds = {
408 .dot = { .min = 25000, .max = 350000 },
409 .vco = { .min = 1760000, .max = 3510000 },
410 .n = { .min = 1, .max = 3 },
411 .m = { .min = 79, .max = 127 },
412 .m1 = { .min = 12, .max = 22 },
413 .m2 = { .min = 5, .max = 9 },
414 .p = { .min = 14, .max = 56 },
415 .p1 = { .min = 2, .max = 8 },
416 .p2 = { .dot_limit = 225000,
417 .p2_slow = 7, .p2_fast = 7 },
420 /* LVDS 100mhz refclk limits. */
421 static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
422 .dot = { .min = 25000, .max = 350000 },
423 .vco = { .min = 1760000, .max = 3510000 },
424 .n = { .min = 1, .max = 2 },
425 .m = { .min = 79, .max = 126 },
426 .m1 = { .min = 12, .max = 22 },
427 .m2 = { .min = 5, .max = 9 },
428 .p = { .min = 28, .max = 112 },
429 .p1 = { .min = 2, .max = 8 },
430 .p2 = { .dot_limit = 225000,
431 .p2_slow = 14, .p2_fast = 14 },
434 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
435 .dot = { .min = 25000, .max = 350000 },
436 .vco = { .min = 1760000, .max = 3510000 },
437 .n = { .min = 1, .max = 3 },
438 .m = { .min = 79, .max = 126 },
439 .m1 = { .min = 12, .max = 22 },
440 .m2 = { .min = 5, .max = 9 },
441 .p = { .min = 14, .max = 42 },
442 .p1 = { .min = 2, .max = 6 },
443 .p2 = { .dot_limit = 225000,
444 .p2_slow = 7, .p2_fast = 7 },
447 static const struct intel_limit intel_limits_vlv = {
449 * These are the data rate limits (measured in fast clocks)
450 * since those are the strictest limits we have. The fast
451 * clock and actual rate limits are more relaxed, so checking
452 * them would make no difference.
454 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
455 .vco = { .min = 4000000, .max = 6000000 },
456 .n = { .min = 1, .max = 7 },
457 .m1 = { .min = 2, .max = 3 },
458 .m2 = { .min = 11, .max = 156 },
459 .p1 = { .min = 2, .max = 3 },
460 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
463 static const struct intel_limit intel_limits_chv = {
465 * These are the data rate limits (measured in fast clocks)
466 * since those are the strictest limits we have. The fast
467 * clock and actual rate limits are more relaxed, so checking
468 * them would make no difference.
470 .dot = { .min = 25000 * 5, .max = 540000 * 5},
471 .vco = { .min = 4800000, .max = 6480000 },
472 .n = { .min = 1, .max = 1 },
473 .m1 = { .min = 2, .max = 2 },
474 .m2 = { .min = 24 << 22, .max = 175 << 22 },
475 .p1 = { .min = 2, .max = 4 },
476 .p2 = { .p2_slow = 1, .p2_fast = 14 },
479 static const struct intel_limit intel_limits_bxt = {
480 /* FIXME: find real dot limits */
481 .dot = { .min = 0, .max = INT_MAX },
482 .vco = { .min = 4800000, .max = 6700000 },
483 .n = { .min = 1, .max = 1 },
484 .m1 = { .min = 2, .max = 2 },
485 /* FIXME: find real m2 limits */
486 .m2 = { .min = 2 << 22, .max = 255 << 22 },
487 .p1 = { .min = 2, .max = 4 },
488 .p2 = { .p2_slow = 1, .p2_fast = 20 },
491 /* WA Display #0827: Gen9:all */
493 skl_wa_827(struct drm_i915_private *dev_priv, int pipe, bool enable)
496 I915_WRITE(CLKGATE_DIS_PSL(pipe),
497 I915_READ(CLKGATE_DIS_PSL(pipe)) |
498 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
500 I915_WRITE(CLKGATE_DIS_PSL(pipe),
501 I915_READ(CLKGATE_DIS_PSL(pipe)) &
502 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
505 /* Wa_2006604312:icl */
507 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
511 I915_WRITE(CLKGATE_DIS_PSL(pipe),
512 I915_READ(CLKGATE_DIS_PSL(pipe)) | DPFR_GATING_DIS);
514 I915_WRITE(CLKGATE_DIS_PSL(pipe),
515 I915_READ(CLKGATE_DIS_PSL(pipe)) & ~DPFR_GATING_DIS);
519 needs_modeset(const struct intel_crtc_state *state)
521 return drm_atomic_crtc_needs_modeset(&state->base);
525 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
526 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
527 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
528 * The helpers' return value is the rate of the clock that is fed to the
529 * display engine's pipe which can be the above fast dot clock rate or a
530 * divided-down version of it.
532 /* m1 is reserved as 0 in Pineview, n is a ring counter */
533 static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
535 clock->m = clock->m2 + 2;
536 clock->p = clock->p1 * clock->p2;
537 if (WARN_ON(clock->n == 0 || clock->p == 0))
539 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
540 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
545 static u32 i9xx_dpll_compute_m(struct dpll *dpll)
547 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
550 static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
552 clock->m = i9xx_dpll_compute_m(clock);
553 clock->p = clock->p1 * clock->p2;
554 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
556 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
557 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
562 static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
564 clock->m = clock->m1 * clock->m2;
565 clock->p = clock->p1 * clock->p2;
566 if (WARN_ON(clock->n == 0 || clock->p == 0))
568 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
569 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
571 return clock->dot / 5;
574 int chv_calc_dpll_params(int refclk, struct dpll *clock)
576 clock->m = clock->m1 * clock->m2;
577 clock->p = clock->p1 * clock->p2;
578 if (WARN_ON(clock->n == 0 || clock->p == 0))
580 clock->vco = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(refclk, clock->m),
582 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
584 return clock->dot / 5;
587 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
590 * Returns whether the given set of divisors are valid for a given refclk with
591 * the given connectors.
593 static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
594 const struct intel_limit *limit,
595 const struct dpll *clock)
597 if (clock->n < limit->n.min || limit->n.max < clock->n)
598 INTELPllInvalid("n out of range\n");
599 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
600 INTELPllInvalid("p1 out of range\n");
601 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
602 INTELPllInvalid("m2 out of range\n");
603 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
604 INTELPllInvalid("m1 out of range\n");
606 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
607 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
608 if (clock->m1 <= clock->m2)
609 INTELPllInvalid("m1 <= m2\n");
611 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
612 !IS_GEN9_LP(dev_priv)) {
613 if (clock->p < limit->p.min || limit->p.max < clock->p)
614 INTELPllInvalid("p out of range\n");
615 if (clock->m < limit->m.min || limit->m.max < clock->m)
616 INTELPllInvalid("m out of range\n");
619 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
620 INTELPllInvalid("vco out of range\n");
621 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
622 * connector, etc., rather than just a single range.
624 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
625 INTELPllInvalid("dot out of range\n");
631 i9xx_select_p2_div(const struct intel_limit *limit,
632 const struct intel_crtc_state *crtc_state,
635 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
637 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
639 * For LVDS just rely on its current settings for dual-channel.
640 * We haven't figured out how to reliably set up different
641 * single/dual channel state, if we even can.
643 if (intel_is_dual_link_lvds(dev_priv))
644 return limit->p2.p2_fast;
646 return limit->p2.p2_slow;
648 if (target < limit->p2.dot_limit)
649 return limit->p2.p2_slow;
651 return limit->p2.p2_fast;
656 * Returns a set of divisors for the desired target clock with the given
657 * refclk, or FALSE. The returned values represent the clock equation:
658 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
660 * Target and reference clocks are specified in kHz.
662 * If match_clock is provided, then best_clock P divider must match the P
663 * divider from @match_clock used for LVDS downclocking.
666 i9xx_find_best_dpll(const struct intel_limit *limit,
667 struct intel_crtc_state *crtc_state,
668 int target, int refclk, struct dpll *match_clock,
669 struct dpll *best_clock)
671 struct drm_device *dev = crtc_state->base.crtc->dev;
675 memset(best_clock, 0, sizeof(*best_clock));
677 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
679 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
681 for (clock.m2 = limit->m2.min;
682 clock.m2 <= limit->m2.max; clock.m2++) {
683 if (clock.m2 >= clock.m1)
685 for (clock.n = limit->n.min;
686 clock.n <= limit->n.max; clock.n++) {
687 for (clock.p1 = limit->p1.min;
688 clock.p1 <= limit->p1.max; clock.p1++) {
691 i9xx_calc_dpll_params(refclk, &clock);
692 if (!intel_PLL_is_valid(to_i915(dev),
697 clock.p != match_clock->p)
700 this_err = abs(clock.dot - target);
701 if (this_err < err) {
710 return (err != target);
714 * Returns a set of divisors for the desired target clock with the given
715 * refclk, or FALSE. The returned values represent the clock equation:
716 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
718 * Target and reference clocks are specified in kHz.
720 * If match_clock is provided, then best_clock P divider must match the P
721 * divider from @match_clock used for LVDS downclocking.
724 pnv_find_best_dpll(const struct intel_limit *limit,
725 struct intel_crtc_state *crtc_state,
726 int target, int refclk, struct dpll *match_clock,
727 struct dpll *best_clock)
729 struct drm_device *dev = crtc_state->base.crtc->dev;
733 memset(best_clock, 0, sizeof(*best_clock));
735 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
737 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
739 for (clock.m2 = limit->m2.min;
740 clock.m2 <= limit->m2.max; clock.m2++) {
741 for (clock.n = limit->n.min;
742 clock.n <= limit->n.max; clock.n++) {
743 for (clock.p1 = limit->p1.min;
744 clock.p1 <= limit->p1.max; clock.p1++) {
747 pnv_calc_dpll_params(refclk, &clock);
748 if (!intel_PLL_is_valid(to_i915(dev),
753 clock.p != match_clock->p)
756 this_err = abs(clock.dot - target);
757 if (this_err < err) {
766 return (err != target);
770 * Returns a set of divisors for the desired target clock with the given
771 * refclk, or FALSE. The returned values represent the clock equation:
772 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
774 * Target and reference clocks are specified in kHz.
776 * If match_clock is provided, then best_clock P divider must match the P
777 * divider from @match_clock used for LVDS downclocking.
780 g4x_find_best_dpll(const struct intel_limit *limit,
781 struct intel_crtc_state *crtc_state,
782 int target, int refclk, struct dpll *match_clock,
783 struct dpll *best_clock)
785 struct drm_device *dev = crtc_state->base.crtc->dev;
789 /* approximately equals target * 0.00585 */
790 int err_most = (target >> 8) + (target >> 9);
792 memset(best_clock, 0, sizeof(*best_clock));
794 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
796 max_n = limit->n.max;
797 /* based on hardware requirement, prefer smaller n to precision */
798 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
799 /* based on hardware requirement, prefere larger m1,m2 */
800 for (clock.m1 = limit->m1.max;
801 clock.m1 >= limit->m1.min; clock.m1--) {
802 for (clock.m2 = limit->m2.max;
803 clock.m2 >= limit->m2.min; clock.m2--) {
804 for (clock.p1 = limit->p1.max;
805 clock.p1 >= limit->p1.min; clock.p1--) {
808 i9xx_calc_dpll_params(refclk, &clock);
809 if (!intel_PLL_is_valid(to_i915(dev),
814 this_err = abs(clock.dot - target);
815 if (this_err < err_most) {
829 * Check if the calculated PLL configuration is more optimal compared to the
830 * best configuration and error found so far. Return the calculated error.
832 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
833 const struct dpll *calculated_clock,
834 const struct dpll *best_clock,
835 unsigned int best_error_ppm,
836 unsigned int *error_ppm)
839 * For CHV ignore the error and consider only the P value.
840 * Prefer a bigger P value based on HW requirements.
842 if (IS_CHERRYVIEW(to_i915(dev))) {
845 return calculated_clock->p > best_clock->p;
848 if (WARN_ON_ONCE(!target_freq))
851 *error_ppm = div_u64(1000000ULL *
852 abs(target_freq - calculated_clock->dot),
855 * Prefer a better P value over a better (smaller) error if the error
856 * is small. Ensure this preference for future configurations too by
857 * setting the error to 0.
859 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
865 return *error_ppm + 10 < best_error_ppm;
869 * Returns a set of divisors for the desired target clock with the given
870 * refclk, or FALSE. The returned values represent the clock equation:
871 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
874 vlv_find_best_dpll(const struct intel_limit *limit,
875 struct intel_crtc_state *crtc_state,
876 int target, int refclk, struct dpll *match_clock,
877 struct dpll *best_clock)
879 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
880 struct drm_device *dev = crtc->base.dev;
882 unsigned int bestppm = 1000000;
883 /* min update 19.2 MHz */
884 int max_n = min(limit->n.max, refclk / 19200);
887 target *= 5; /* fast clock */
889 memset(best_clock, 0, sizeof(*best_clock));
891 /* based on hardware requirement, prefer smaller n to precision */
892 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
893 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
894 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
895 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
896 clock.p = clock.p1 * clock.p2;
897 /* based on hardware requirement, prefer bigger m1,m2 values */
898 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
901 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
904 vlv_calc_dpll_params(refclk, &clock);
906 if (!intel_PLL_is_valid(to_i915(dev),
911 if (!vlv_PLL_is_optimal(dev, target,
929 * Returns a set of divisors for the desired target clock with the given
930 * refclk, or FALSE. The returned values represent the clock equation:
931 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
934 chv_find_best_dpll(const struct intel_limit *limit,
935 struct intel_crtc_state *crtc_state,
936 int target, int refclk, struct dpll *match_clock,
937 struct dpll *best_clock)
939 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
940 struct drm_device *dev = crtc->base.dev;
941 unsigned int best_error_ppm;
946 memset(best_clock, 0, sizeof(*best_clock));
947 best_error_ppm = 1000000;
950 * Based on hardware doc, the n always set to 1, and m1 always
951 * set to 2. If requires to support 200Mhz refclk, we need to
952 * revisit this because n may not 1 anymore.
954 clock.n = 1, clock.m1 = 2;
955 target *= 5; /* fast clock */
957 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
958 for (clock.p2 = limit->p2.p2_fast;
959 clock.p2 >= limit->p2.p2_slow;
960 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
961 unsigned int error_ppm;
963 clock.p = clock.p1 * clock.p2;
965 m2 = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(target, clock.p * clock.n) << 22,
968 if (m2 > INT_MAX/clock.m1)
973 chv_calc_dpll_params(refclk, &clock);
975 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
978 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
979 best_error_ppm, &error_ppm))
983 best_error_ppm = error_ppm;
991 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state,
992 struct dpll *best_clock)
995 const struct intel_limit *limit = &intel_limits_bxt;
997 return chv_find_best_dpll(limit, crtc_state,
998 crtc_state->port_clock, refclk,
1002 bool intel_crtc_active(struct intel_crtc *crtc)
1004 /* Be paranoid as we can arrive here with only partial
1005 * state retrieved from the hardware during setup.
1007 * We can ditch the adjusted_mode.crtc_clock check as soon
1008 * as Haswell has gained clock readout/fastboot support.
1010 * We can ditch the crtc->primary->state->fb check as soon as we can
1011 * properly reconstruct framebuffers.
1013 * FIXME: The intel_crtc->active here should be switched to
1014 * crtc->state->active once we have proper CRTC states wired up
1017 return crtc->active && crtc->base.primary->state->fb &&
1018 crtc->config->base.adjusted_mode.crtc_clock;
1021 enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
1024 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1026 return crtc->config->cpu_transcoder;
1029 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
1032 i915_reg_t reg = PIPEDSL(pipe);
1036 if (IS_GEN(dev_priv, 2))
1037 line_mask = DSL_LINEMASK_GEN2;
1039 line_mask = DSL_LINEMASK_GEN3;
1041 line1 = I915_READ(reg) & line_mask;
1043 line2 = I915_READ(reg) & line_mask;
1045 return line1 != line2;
1048 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1050 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1051 enum pipe pipe = crtc->pipe;
1053 /* Wait for the display line to settle/start moving */
1054 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1055 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1056 pipe_name(pipe), onoff(state));
1059 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1061 wait_for_pipe_scanline_moving(crtc, false);
1064 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1066 wait_for_pipe_scanline_moving(crtc, true);
1070 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
1072 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1073 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1075 if (INTEL_GEN(dev_priv) >= 4) {
1076 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1077 i915_reg_t reg = PIPECONF(cpu_transcoder);
1079 /* Wait for the Pipe State to go off */
1080 if (intel_wait_for_register(&dev_priv->uncore,
1081 reg, I965_PIPECONF_ACTIVE, 0,
1083 WARN(1, "pipe_off wait timed out\n");
1085 intel_wait_for_pipe_scanline_stopped(crtc);
1089 /* Only for pre-ILK configs */
1090 void assert_pll(struct drm_i915_private *dev_priv,
1091 enum pipe pipe, bool state)
1096 val = I915_READ(DPLL(pipe));
1097 cur_state = !!(val & DPLL_VCO_ENABLE);
1098 I915_STATE_WARN(cur_state != state,
1099 "PLL state assertion failure (expected %s, current %s)\n",
1100 onoff(state), onoff(cur_state));
1103 /* XXX: the dsi pll is shared between MIPI DSI ports */
1104 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1109 vlv_cck_get(dev_priv);
1110 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1111 vlv_cck_put(dev_priv);
1113 cur_state = val & DSI_PLL_VCO_EN;
1114 I915_STATE_WARN(cur_state != state,
1115 "DSI PLL state assertion failure (expected %s, current %s)\n",
1116 onoff(state), onoff(cur_state));
1119 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1120 enum pipe pipe, bool state)
1123 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1126 if (HAS_DDI(dev_priv)) {
1127 /* DDI does not have a specific FDI_TX register */
1128 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1129 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1131 u32 val = I915_READ(FDI_TX_CTL(pipe));
1132 cur_state = !!(val & FDI_TX_ENABLE);
1134 I915_STATE_WARN(cur_state != state,
1135 "FDI TX state assertion failure (expected %s, current %s)\n",
1136 onoff(state), onoff(cur_state));
1138 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1139 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1141 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1142 enum pipe pipe, bool state)
1147 val = I915_READ(FDI_RX_CTL(pipe));
1148 cur_state = !!(val & FDI_RX_ENABLE);
1149 I915_STATE_WARN(cur_state != state,
1150 "FDI RX state assertion failure (expected %s, current %s)\n",
1151 onoff(state), onoff(cur_state));
1153 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1154 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1156 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1161 /* ILK FDI PLL is always enabled */
1162 if (IS_GEN(dev_priv, 5))
1165 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1166 if (HAS_DDI(dev_priv))
1169 val = I915_READ(FDI_TX_CTL(pipe));
1170 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1173 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1174 enum pipe pipe, bool state)
1179 val = I915_READ(FDI_RX_CTL(pipe));
1180 cur_state = !!(val & FDI_RX_PLL_ENABLE);
1181 I915_STATE_WARN(cur_state != state,
1182 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1183 onoff(state), onoff(cur_state));
1186 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
1190 enum pipe panel_pipe = INVALID_PIPE;
1193 if (WARN_ON(HAS_DDI(dev_priv)))
1196 if (HAS_PCH_SPLIT(dev_priv)) {
1199 pp_reg = PP_CONTROL(0);
1200 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1203 case PANEL_PORT_SELECT_LVDS:
1204 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
1206 case PANEL_PORT_SELECT_DPA:
1207 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1209 case PANEL_PORT_SELECT_DPC:
1210 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1212 case PANEL_PORT_SELECT_DPD:
1213 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1216 MISSING_CASE(port_sel);
1219 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1220 /* presumably write lock depends on pipe, not port select */
1221 pp_reg = PP_CONTROL(pipe);
1226 pp_reg = PP_CONTROL(0);
1227 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1229 WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS);
1230 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
1233 val = I915_READ(pp_reg);
1234 if (!(val & PANEL_POWER_ON) ||
1235 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1238 I915_STATE_WARN(panel_pipe == pipe && locked,
1239 "panel assertion failure, pipe %c regs locked\n",
1243 void assert_pipe(struct drm_i915_private *dev_priv,
1244 enum pipe pipe, bool state)
1247 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1249 enum intel_display_power_domain power_domain;
1250 intel_wakeref_t wakeref;
1252 /* we keep both pipes enabled on 830 */
1253 if (IS_I830(dev_priv))
1256 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1257 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1259 u32 val = I915_READ(PIPECONF(cpu_transcoder));
1260 cur_state = !!(val & PIPECONF_ENABLE);
1262 intel_display_power_put(dev_priv, power_domain, wakeref);
1267 I915_STATE_WARN(cur_state != state,
1268 "pipe %c assertion failure (expected %s, current %s)\n",
1269 pipe_name(pipe), onoff(state), onoff(cur_state));
1272 static void assert_plane(struct intel_plane *plane, bool state)
1277 cur_state = plane->get_hw_state(plane, &pipe);
1279 I915_STATE_WARN(cur_state != state,
1280 "%s assertion failure (expected %s, current %s)\n",
1281 plane->base.name, onoff(state), onoff(cur_state));
1284 #define assert_plane_enabled(p) assert_plane(p, true)
1285 #define assert_plane_disabled(p) assert_plane(p, false)
1287 static void assert_planes_disabled(struct intel_crtc *crtc)
1289 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1290 struct intel_plane *plane;
1292 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1293 assert_plane_disabled(plane);
1296 static void assert_vblank_disabled(struct drm_crtc *crtc)
1298 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1299 drm_crtc_vblank_put(crtc);
1302 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1308 val = I915_READ(PCH_TRANSCONF(pipe));
1309 enabled = !!(val & TRANS_ENABLE);
1310 I915_STATE_WARN(enabled,
1311 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1315 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1316 enum pipe pipe, enum port port,
1319 enum pipe port_pipe;
1322 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1324 I915_STATE_WARN(state && port_pipe == pipe,
1325 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1326 port_name(port), pipe_name(pipe));
1328 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1329 "IBX PCH DP %c still using transcoder B\n",
1333 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1334 enum pipe pipe, enum port port,
1335 i915_reg_t hdmi_reg)
1337 enum pipe port_pipe;
1340 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1342 I915_STATE_WARN(state && port_pipe == pipe,
1343 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1344 port_name(port), pipe_name(pipe));
1346 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1347 "IBX PCH HDMI %c still using transcoder B\n",
1351 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1354 enum pipe port_pipe;
1356 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1357 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1358 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
1360 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1362 "PCH VGA enabled on transcoder %c, should be disabled\n",
1365 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1367 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1370 /* PCH SDVOB multiplex with HDMIB */
1371 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1372 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1373 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
1376 static void _vlv_enable_pll(struct intel_crtc *crtc,
1377 const struct intel_crtc_state *pipe_config)
1379 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1380 enum pipe pipe = crtc->pipe;
1382 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1383 POSTING_READ(DPLL(pipe));
1386 if (intel_wait_for_register(&dev_priv->uncore,
1391 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1394 static void vlv_enable_pll(struct intel_crtc *crtc,
1395 const struct intel_crtc_state *pipe_config)
1397 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1398 enum pipe pipe = crtc->pipe;
1400 assert_pipe_disabled(dev_priv, pipe);
1402 /* PLL is protected by panel, make sure we can write it */
1403 assert_panel_unlocked(dev_priv, pipe);
1405 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1406 _vlv_enable_pll(crtc, pipe_config);
1408 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1409 POSTING_READ(DPLL_MD(pipe));
1413 static void _chv_enable_pll(struct intel_crtc *crtc,
1414 const struct intel_crtc_state *pipe_config)
1416 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1417 enum pipe pipe = crtc->pipe;
1418 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1421 vlv_dpio_get(dev_priv);
1423 /* Enable back the 10bit clock to display controller */
1424 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1425 tmp |= DPIO_DCLKP_EN;
1426 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1428 vlv_dpio_put(dev_priv);
1431 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1436 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1438 /* Check PLL is locked */
1439 if (intel_wait_for_register(&dev_priv->uncore,
1440 DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV,
1442 DRM_ERROR("PLL %d failed to lock\n", pipe);
1445 static void chv_enable_pll(struct intel_crtc *crtc,
1446 const struct intel_crtc_state *pipe_config)
1448 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1449 enum pipe pipe = crtc->pipe;
1451 assert_pipe_disabled(dev_priv, pipe);
1453 /* PLL is protected by panel, make sure we can write it */
1454 assert_panel_unlocked(dev_priv, pipe);
1456 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1457 _chv_enable_pll(crtc, pipe_config);
1459 if (pipe != PIPE_A) {
1461 * WaPixelRepeatModeFixForC0:chv
1463 * DPLLCMD is AWOL. Use chicken bits to propagate
1464 * the value from DPLLBMD to either pipe B or C.
1466 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1467 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1468 I915_WRITE(CBR4_VLV, 0);
1469 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1472 * DPLLB VGA mode also seems to cause problems.
1473 * We should always have it disabled.
1475 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1477 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1478 POSTING_READ(DPLL_MD(pipe));
1482 static bool i9xx_has_pps(struct drm_i915_private *dev_priv)
1484 if (IS_I830(dev_priv))
1487 return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
1490 static void i9xx_enable_pll(struct intel_crtc *crtc,
1491 const struct intel_crtc_state *crtc_state)
1493 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1494 i915_reg_t reg = DPLL(crtc->pipe);
1495 u32 dpll = crtc_state->dpll_hw_state.dpll;
1498 assert_pipe_disabled(dev_priv, crtc->pipe);
1500 /* PLL is protected by panel, make sure we can write it */
1501 if (i9xx_has_pps(dev_priv))
1502 assert_panel_unlocked(dev_priv, crtc->pipe);
1505 * Apparently we need to have VGA mode enabled prior to changing
1506 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1507 * dividers, even though the register value does change.
1509 I915_WRITE(reg, dpll & ~DPLL_VGA_MODE_DIS);
1510 I915_WRITE(reg, dpll);
1512 /* Wait for the clocks to stabilize. */
1516 if (INTEL_GEN(dev_priv) >= 4) {
1517 I915_WRITE(DPLL_MD(crtc->pipe),
1518 crtc_state->dpll_hw_state.dpll_md);
1520 /* The pixel multiplier can only be updated once the
1521 * DPLL is enabled and the clocks are stable.
1523 * So write it again.
1525 I915_WRITE(reg, dpll);
1528 /* We do this three times for luck */
1529 for (i = 0; i < 3; i++) {
1530 I915_WRITE(reg, dpll);
1532 udelay(150); /* wait for warmup */
1536 static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
1538 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1539 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1540 enum pipe pipe = crtc->pipe;
1542 /* Don't disable pipe or pipe PLLs if needed */
1543 if (IS_I830(dev_priv))
1546 /* Make sure the pipe isn't still relying on us */
1547 assert_pipe_disabled(dev_priv, pipe);
1549 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
1550 POSTING_READ(DPLL(pipe));
1553 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1557 /* Make sure the pipe isn't still relying on us */
1558 assert_pipe_disabled(dev_priv, pipe);
1560 val = DPLL_INTEGRATED_REF_CLK_VLV |
1561 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1563 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1565 I915_WRITE(DPLL(pipe), val);
1566 POSTING_READ(DPLL(pipe));
1569 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1571 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1574 /* Make sure the pipe isn't still relying on us */
1575 assert_pipe_disabled(dev_priv, pipe);
1577 val = DPLL_SSC_REF_CLK_CHV |
1578 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1580 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1582 I915_WRITE(DPLL(pipe), val);
1583 POSTING_READ(DPLL(pipe));
1585 vlv_dpio_get(dev_priv);
1587 /* Disable 10bit clock to display controller */
1588 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1589 val &= ~DPIO_DCLKP_EN;
1590 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1592 vlv_dpio_put(dev_priv);
1595 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1596 struct intel_digital_port *dport,
1597 unsigned int expected_mask)
1600 i915_reg_t dpll_reg;
1602 switch (dport->base.port) {
1604 port_mask = DPLL_PORTB_READY_MASK;
1608 port_mask = DPLL_PORTC_READY_MASK;
1610 expected_mask <<= 4;
1613 port_mask = DPLL_PORTD_READY_MASK;
1614 dpll_reg = DPIO_PHY_STATUS;
1620 if (intel_wait_for_register(&dev_priv->uncore,
1621 dpll_reg, port_mask, expected_mask,
1623 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1624 port_name(dport->base.port),
1625 I915_READ(dpll_reg) & port_mask, expected_mask);
1628 static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
1630 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1631 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1632 enum pipe pipe = crtc->pipe;
1634 u32 val, pipeconf_val;
1636 /* Make sure PCH DPLL is enabled */
1637 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
1639 /* FDI must be feeding us bits for PCH ports */
1640 assert_fdi_tx_enabled(dev_priv, pipe);
1641 assert_fdi_rx_enabled(dev_priv, pipe);
1643 if (HAS_PCH_CPT(dev_priv)) {
1644 /* Workaround: Set the timing override bit before enabling the
1645 * pch transcoder. */
1646 reg = TRANS_CHICKEN2(pipe);
1647 val = I915_READ(reg);
1648 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1649 I915_WRITE(reg, val);
1652 reg = PCH_TRANSCONF(pipe);
1653 val = I915_READ(reg);
1654 pipeconf_val = I915_READ(PIPECONF(pipe));
1656 if (HAS_PCH_IBX(dev_priv)) {
1658 * Make the BPC in transcoder be consistent with
1659 * that in pipeconf reg. For HDMI we must use 8bpc
1660 * here for both 8bpc and 12bpc.
1662 val &= ~PIPECONF_BPC_MASK;
1663 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1664 val |= PIPECONF_8BPC;
1666 val |= pipeconf_val & PIPECONF_BPC_MASK;
1669 val &= ~TRANS_INTERLACE_MASK;
1670 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) {
1671 if (HAS_PCH_IBX(dev_priv) &&
1672 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
1673 val |= TRANS_LEGACY_INTERLACED_ILK;
1675 val |= TRANS_INTERLACED;
1677 val |= TRANS_PROGRESSIVE;
1680 I915_WRITE(reg, val | TRANS_ENABLE);
1681 if (intel_wait_for_register(&dev_priv->uncore,
1682 reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE,
1684 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
1687 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1688 enum transcoder cpu_transcoder)
1690 u32 val, pipeconf_val;
1692 /* FDI must be feeding us bits for PCH ports */
1693 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1694 assert_fdi_rx_enabled(dev_priv, PIPE_A);
1696 /* Workaround: set timing override bit. */
1697 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1698 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1699 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1702 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
1704 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1705 PIPECONF_INTERLACED_ILK)
1706 val |= TRANS_INTERLACED;
1708 val |= TRANS_PROGRESSIVE;
1710 I915_WRITE(LPT_TRANSCONF, val);
1711 if (intel_wait_for_register(&dev_priv->uncore,
1716 DRM_ERROR("Failed to enable PCH transcoder\n");
1719 static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1725 /* FDI relies on the transcoder */
1726 assert_fdi_tx_disabled(dev_priv, pipe);
1727 assert_fdi_rx_disabled(dev_priv, pipe);
1729 /* Ports must be off as well */
1730 assert_pch_ports_disabled(dev_priv, pipe);
1732 reg = PCH_TRANSCONF(pipe);
1733 val = I915_READ(reg);
1734 val &= ~TRANS_ENABLE;
1735 I915_WRITE(reg, val);
1736 /* wait for PCH transcoder off, transcoder state */
1737 if (intel_wait_for_register(&dev_priv->uncore,
1738 reg, TRANS_STATE_ENABLE, 0,
1740 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
1742 if (HAS_PCH_CPT(dev_priv)) {
1743 /* Workaround: Clear the timing override chicken bit again. */
1744 reg = TRANS_CHICKEN2(pipe);
1745 val = I915_READ(reg);
1746 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1747 I915_WRITE(reg, val);
1751 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1755 val = I915_READ(LPT_TRANSCONF);
1756 val &= ~TRANS_ENABLE;
1757 I915_WRITE(LPT_TRANSCONF, val);
1758 /* wait for PCH transcoder off, transcoder state */
1759 if (intel_wait_for_register(&dev_priv->uncore,
1760 LPT_TRANSCONF, TRANS_STATE_ENABLE, 0,
1762 DRM_ERROR("Failed to disable PCH transcoder\n");
1764 /* Workaround: clear timing override bit. */
1765 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1766 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1767 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1770 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
1772 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1774 if (HAS_PCH_LPT(dev_priv))
1780 static u32 intel_crtc_max_vblank_count(const struct intel_crtc_state *crtc_state)
1782 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
1785 * On i965gm the hardware frame counter reads
1786 * zero when the TV encoder is enabled :(
1788 if (IS_I965GM(dev_priv) &&
1789 (crtc_state->output_types & BIT(INTEL_OUTPUT_TVOUT)))
1792 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
1793 return 0xffffffff; /* full 32 bit counter */
1794 else if (INTEL_GEN(dev_priv) >= 3)
1795 return 0xffffff; /* only 24 bits of frame count */
1797 return 0; /* Gen2 doesn't have a hardware frame counter */
1800 static void intel_crtc_vblank_on(const struct intel_crtc_state *crtc_state)
1802 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1804 drm_crtc_set_max_vblank_count(&crtc->base,
1805 intel_crtc_max_vblank_count(crtc_state));
1806 drm_crtc_vblank_on(&crtc->base);
1809 static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
1811 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1812 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1813 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1814 enum pipe pipe = crtc->pipe;
1818 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1820 assert_planes_disabled(crtc);
1823 * A pipe without a PLL won't actually be able to drive bits from
1824 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1827 if (HAS_GMCH(dev_priv)) {
1828 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1829 assert_dsi_pll_enabled(dev_priv);
1831 assert_pll_enabled(dev_priv, pipe);
1833 if (new_crtc_state->has_pch_encoder) {
1834 /* if driving the PCH, we need FDI enabled */
1835 assert_fdi_rx_pll_enabled(dev_priv,
1836 intel_crtc_pch_transcoder(crtc));
1837 assert_fdi_tx_pll_enabled(dev_priv,
1838 (enum pipe) cpu_transcoder);
1840 /* FIXME: assert CPU port conditions for SNB+ */
1843 trace_intel_pipe_enable(crtc);
1845 reg = PIPECONF(cpu_transcoder);
1846 val = I915_READ(reg);
1847 if (val & PIPECONF_ENABLE) {
1848 /* we keep both pipes enabled on 830 */
1849 WARN_ON(!IS_I830(dev_priv));
1853 I915_WRITE(reg, val | PIPECONF_ENABLE);
1857 * Until the pipe starts PIPEDSL reads will return a stale value,
1858 * which causes an apparent vblank timestamp jump when PIPEDSL
1859 * resets to its proper value. That also messes up the frame count
1860 * when it's derived from the timestamps. So let's wait for the
1861 * pipe to start properly before we call drm_crtc_vblank_on()
1863 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
1864 intel_wait_for_pipe_scanline_moving(crtc);
1867 static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1869 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1870 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1871 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1872 enum pipe pipe = crtc->pipe;
1876 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1879 * Make sure planes won't keep trying to pump pixels to us,
1880 * or we might hang the display.
1882 assert_planes_disabled(crtc);
1884 trace_intel_pipe_disable(crtc);
1886 reg = PIPECONF(cpu_transcoder);
1887 val = I915_READ(reg);
1888 if ((val & PIPECONF_ENABLE) == 0)
1892 * Double wide has implications for planes
1893 * so best keep it disabled when not needed.
1895 if (old_crtc_state->double_wide)
1896 val &= ~PIPECONF_DOUBLE_WIDE;
1898 /* Don't disable pipe or pipe PLLs if needed */
1899 if (!IS_I830(dev_priv))
1900 val &= ~PIPECONF_ENABLE;
1902 I915_WRITE(reg, val);
1903 if ((val & PIPECONF_ENABLE) == 0)
1904 intel_wait_for_pipe_off(old_crtc_state);
1907 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1909 return IS_GEN(dev_priv, 2) ? 2048 : 4096;
1913 intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
1915 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1916 unsigned int cpp = fb->format->cpp[color_plane];
1918 switch (fb->modifier) {
1919 case DRM_FORMAT_MOD_LINEAR:
1920 return intel_tile_size(dev_priv);
1921 case I915_FORMAT_MOD_X_TILED:
1922 if (IS_GEN(dev_priv, 2))
1926 case I915_FORMAT_MOD_Y_TILED_CCS:
1927 if (color_plane == 1)
1930 case I915_FORMAT_MOD_Y_TILED:
1931 if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv))
1935 case I915_FORMAT_MOD_Yf_TILED_CCS:
1936 if (color_plane == 1)
1939 case I915_FORMAT_MOD_Yf_TILED:
1955 MISSING_CASE(fb->modifier);
1961 intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
1963 return intel_tile_size(to_i915(fb->dev)) /
1964 intel_tile_width_bytes(fb, color_plane);
1967 /* Return the tile dimensions in pixel units */
1968 static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
1969 unsigned int *tile_width,
1970 unsigned int *tile_height)
1972 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
1973 unsigned int cpp = fb->format->cpp[color_plane];
1975 *tile_width = tile_width_bytes / cpp;
1976 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
1980 intel_fb_align_height(const struct drm_framebuffer *fb,
1981 int color_plane, unsigned int height)
1983 unsigned int tile_height = intel_tile_height(fb, color_plane);
1985 return ALIGN(height, tile_height);
1988 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
1990 unsigned int size = 0;
1993 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
1994 size += rot_info->plane[i].width * rot_info->plane[i].height;
1999 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
2001 unsigned int size = 0;
2004 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++)
2005 size += rem_info->plane[i].width * rem_info->plane[i].height;
2011 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
2012 const struct drm_framebuffer *fb,
2013 unsigned int rotation)
2015 view->type = I915_GGTT_VIEW_NORMAL;
2016 if (drm_rotation_90_or_270(rotation)) {
2017 view->type = I915_GGTT_VIEW_ROTATED;
2018 view->rotated = to_intel_framebuffer(fb)->rot_info;
2022 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
2024 if (IS_I830(dev_priv))
2026 else if (IS_I85X(dev_priv))
2028 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
2034 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
2036 if (INTEL_GEN(dev_priv) >= 9)
2038 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
2039 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2041 else if (INTEL_GEN(dev_priv) >= 4)
2047 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
2050 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2052 /* AUX_DIST needs only 4K alignment */
2053 if (color_plane == 1)
2056 switch (fb->modifier) {
2057 case DRM_FORMAT_MOD_LINEAR:
2058 return intel_linear_alignment(dev_priv);
2059 case I915_FORMAT_MOD_X_TILED:
2060 if (INTEL_GEN(dev_priv) >= 9)
2063 case I915_FORMAT_MOD_Y_TILED_CCS:
2064 case I915_FORMAT_MOD_Yf_TILED_CCS:
2065 case I915_FORMAT_MOD_Y_TILED:
2066 case I915_FORMAT_MOD_Yf_TILED:
2067 return 1 * 1024 * 1024;
2069 MISSING_CASE(fb->modifier);
2074 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2076 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2077 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2079 return INTEL_GEN(dev_priv) < 4 ||
2081 plane_state->view.type == I915_GGTT_VIEW_NORMAL);
2085 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
2086 const struct i915_ggtt_view *view,
2088 unsigned long *out_flags)
2090 struct drm_device *dev = fb->dev;
2091 struct drm_i915_private *dev_priv = to_i915(dev);
2092 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2093 intel_wakeref_t wakeref;
2094 struct i915_vma *vma;
2095 unsigned int pinctl;
2098 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2100 alignment = intel_surf_alignment(fb, 0);
2102 /* Note that the w/a also requires 64 PTE of padding following the
2103 * bo. We currently fill all unused PTE with the shadow page and so
2104 * we should always have valid PTE following the scanout preventing
2107 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2108 alignment = 256 * 1024;
2111 * Global gtt pte registers are special registers which actually forward
2112 * writes to a chunk of system memory. Which means that there is no risk
2113 * that the register values disappear as soon as we call
2114 * intel_runtime_pm_put(), so it is correct to wrap only the
2115 * pin/unpin/fence and not more.
2117 wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
2118 i915_gem_object_lock(obj);
2120 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2124 /* Valleyview is definitely limited to scanning out the first
2125 * 512MiB. Lets presume this behaviour was inherited from the
2126 * g4x display engine and that all earlier gen are similarly
2127 * limited. Testing suggests that it is a little more
2128 * complicated than this. For example, Cherryview appears quite
2129 * happy to scanout from anywhere within its global aperture.
2131 if (HAS_GMCH(dev_priv))
2132 pinctl |= PIN_MAPPABLE;
2134 vma = i915_gem_object_pin_to_display_plane(obj,
2135 alignment, view, pinctl);
2139 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
2142 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2143 * fence, whereas 965+ only requires a fence if using
2144 * framebuffer compression. For simplicity, we always, when
2145 * possible, install a fence as the cost is not that onerous.
2147 * If we fail to fence the tiled scanout, then either the
2148 * modeset will reject the change (which is highly unlikely as
2149 * the affected systems, all but one, do not have unmappable
2150 * space) or we will not be able to enable full powersaving
2151 * techniques (also likely not to apply due to various limits
2152 * FBC and the like impose on the size of the buffer, which
2153 * presumably we violated anyway with this unmappable buffer).
2154 * Anyway, it is presumably better to stumble onwards with
2155 * something and try to run the system in a "less than optimal"
2156 * mode that matches the user configuration.
2158 ret = i915_vma_pin_fence(vma);
2159 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
2160 i915_gem_object_unpin_from_display_plane(vma);
2165 if (ret == 0 && vma->fence)
2166 *out_flags |= PLANE_HAS_FENCE;
2171 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2173 i915_gem_object_unlock(obj);
2174 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
2178 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
2180 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
2182 i915_gem_object_lock(vma->obj);
2183 if (flags & PLANE_HAS_FENCE)
2184 i915_vma_unpin_fence(vma);
2185 i915_gem_object_unpin_from_display_plane(vma);
2186 i915_gem_object_unlock(vma->obj);
2191 static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
2192 unsigned int rotation)
2194 if (drm_rotation_90_or_270(rotation))
2195 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
2197 return fb->pitches[color_plane];
2201 * Convert the x/y offsets into a linear offset.
2202 * Only valid with 0/180 degree rotation, which is fine since linear
2203 * offset is only used with linear buffers on pre-hsw and tiled buffers
2204 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2206 u32 intel_fb_xy_to_linear(int x, int y,
2207 const struct intel_plane_state *state,
2210 const struct drm_framebuffer *fb = state->base.fb;
2211 unsigned int cpp = fb->format->cpp[color_plane];
2212 unsigned int pitch = state->color_plane[color_plane].stride;
2214 return y * pitch + x * cpp;
2218 * Add the x/y offsets derived from fb->offsets[] to the user
2219 * specified plane src x/y offsets. The resulting x/y offsets
2220 * specify the start of scanout from the beginning of the gtt mapping.
2222 void intel_add_fb_offsets(int *x, int *y,
2223 const struct intel_plane_state *state,
2227 *x += state->color_plane[color_plane].x;
2228 *y += state->color_plane[color_plane].y;
2231 static u32 intel_adjust_tile_offset(int *x, int *y,
2232 unsigned int tile_width,
2233 unsigned int tile_height,
2234 unsigned int tile_size,
2235 unsigned int pitch_tiles,
2239 unsigned int pitch_pixels = pitch_tiles * tile_width;
2242 WARN_ON(old_offset & (tile_size - 1));
2243 WARN_ON(new_offset & (tile_size - 1));
2244 WARN_ON(new_offset > old_offset);
2246 tiles = (old_offset - new_offset) / tile_size;
2248 *y += tiles / pitch_tiles * tile_height;
2249 *x += tiles % pitch_tiles * tile_width;
2251 /* minimize x in case it got needlessly big */
2252 *y += *x / pitch_pixels * tile_height;
2258 static bool is_surface_linear(u64 modifier, int color_plane)
2260 return modifier == DRM_FORMAT_MOD_LINEAR;
2263 static u32 intel_adjust_aligned_offset(int *x, int *y,
2264 const struct drm_framebuffer *fb,
2266 unsigned int rotation,
2268 u32 old_offset, u32 new_offset)
2270 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2271 unsigned int cpp = fb->format->cpp[color_plane];
2273 WARN_ON(new_offset > old_offset);
2275 if (!is_surface_linear(fb->modifier, color_plane)) {
2276 unsigned int tile_size, tile_width, tile_height;
2277 unsigned int pitch_tiles;
2279 tile_size = intel_tile_size(dev_priv);
2280 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2282 if (drm_rotation_90_or_270(rotation)) {
2283 pitch_tiles = pitch / tile_height;
2284 swap(tile_width, tile_height);
2286 pitch_tiles = pitch / (tile_width * cpp);
2289 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2290 tile_size, pitch_tiles,
2291 old_offset, new_offset);
2293 old_offset += *y * pitch + *x * cpp;
2295 *y = (old_offset - new_offset) / pitch;
2296 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2303 * Adjust the tile offset by moving the difference into
2306 static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2307 const struct intel_plane_state *state,
2309 u32 old_offset, u32 new_offset)
2311 return intel_adjust_aligned_offset(x, y, state->base.fb, color_plane,
2312 state->base.rotation,
2313 state->color_plane[color_plane].stride,
2314 old_offset, new_offset);
2318 * Computes the aligned offset to the base tile and adjusts
2319 * x, y. bytes per pixel is assumed to be a power-of-two.
2321 * In the 90/270 rotated case, x and y are assumed
2322 * to be already rotated to match the rotated GTT view, and
2323 * pitch is the tile_height aligned framebuffer height.
2325 * This function is used when computing the derived information
2326 * under intel_framebuffer, so using any of that information
2327 * here is not allowed. Anything under drm_framebuffer can be
2328 * used. This is why the user has to pass in the pitch since it
2329 * is specified in the rotated orientation.
2331 static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2333 const struct drm_framebuffer *fb,
2336 unsigned int rotation,
2339 unsigned int cpp = fb->format->cpp[color_plane];
2340 u32 offset, offset_aligned;
2345 if (!is_surface_linear(fb->modifier, color_plane)) {
2346 unsigned int tile_size, tile_width, tile_height;
2347 unsigned int tile_rows, tiles, pitch_tiles;
2349 tile_size = intel_tile_size(dev_priv);
2350 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2352 if (drm_rotation_90_or_270(rotation)) {
2353 pitch_tiles = pitch / tile_height;
2354 swap(tile_width, tile_height);
2356 pitch_tiles = pitch / (tile_width * cpp);
2359 tile_rows = *y / tile_height;
2362 tiles = *x / tile_width;
2365 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2366 offset_aligned = offset & ~alignment;
2368 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2369 tile_size, pitch_tiles,
2370 offset, offset_aligned);
2372 offset = *y * pitch + *x * cpp;
2373 offset_aligned = offset & ~alignment;
2375 *y = (offset & alignment) / pitch;
2376 *x = ((offset & alignment) - *y * pitch) / cpp;
2379 return offset_aligned;
2382 static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2383 const struct intel_plane_state *state,
2386 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2387 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2388 const struct drm_framebuffer *fb = state->base.fb;
2389 unsigned int rotation = state->base.rotation;
2390 int pitch = state->color_plane[color_plane].stride;
2393 if (intel_plane->id == PLANE_CURSOR)
2394 alignment = intel_cursor_alignment(dev_priv);
2396 alignment = intel_surf_alignment(fb, color_plane);
2398 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
2399 pitch, rotation, alignment);
2402 /* Convert the fb->offset[] into x/y offsets */
2403 static int intel_fb_offset_to_xy(int *x, int *y,
2404 const struct drm_framebuffer *fb,
2407 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2408 unsigned int height;
2410 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
2411 fb->offsets[color_plane] % intel_tile_size(dev_priv)) {
2412 DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n",
2413 fb->offsets[color_plane], color_plane);
2417 height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
2418 height = ALIGN(height, intel_tile_height(fb, color_plane));
2420 /* Catch potential overflows early */
2421 if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
2422 fb->offsets[color_plane])) {
2423 DRM_DEBUG_KMS("Bad offset 0x%08x or pitch %d for color plane %d\n",
2424 fb->offsets[color_plane], fb->pitches[color_plane],
2432 intel_adjust_aligned_offset(x, y,
2433 fb, color_plane, DRM_MODE_ROTATE_0,
2434 fb->pitches[color_plane],
2435 fb->offsets[color_plane], 0);
2440 static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier)
2442 switch (fb_modifier) {
2443 case I915_FORMAT_MOD_X_TILED:
2444 return I915_TILING_X;
2445 case I915_FORMAT_MOD_Y_TILED:
2446 case I915_FORMAT_MOD_Y_TILED_CCS:
2447 return I915_TILING_Y;
2449 return I915_TILING_NONE;
2454 * From the Sky Lake PRM:
2455 * "The Color Control Surface (CCS) contains the compression status of
2456 * the cache-line pairs. The compression state of the cache-line pair
2457 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2458 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2459 * cache-line-pairs. CCS is always Y tiled."
2461 * Since cache line pairs refers to horizontally adjacent cache lines,
2462 * each cache line in the CCS corresponds to an area of 32x16 cache
2463 * lines on the main surface. Since each pixel is 4 bytes, this gives
2464 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2467 static const struct drm_format_info ccs_formats[] = {
2468 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
2469 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2470 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
2471 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2472 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
2473 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
2474 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
2475 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
2478 static const struct drm_format_info *
2479 lookup_format_info(const struct drm_format_info formats[],
2480 int num_formats, u32 format)
2484 for (i = 0; i < num_formats; i++) {
2485 if (formats[i].format == format)
2492 static const struct drm_format_info *
2493 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2495 switch (cmd->modifier[0]) {
2496 case I915_FORMAT_MOD_Y_TILED_CCS:
2497 case I915_FORMAT_MOD_Yf_TILED_CCS:
2498 return lookup_format_info(ccs_formats,
2499 ARRAY_SIZE(ccs_formats),
2506 bool is_ccs_modifier(u64 modifier)
2508 return modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2509 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2512 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
2513 u32 pixel_format, u64 modifier)
2515 struct intel_crtc *crtc;
2516 struct intel_plane *plane;
2519 * We assume the primary plane for pipe A has
2520 * the highest stride limits of them all.
2522 crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
2523 plane = to_intel_plane(crtc->base.primary);
2525 return plane->max_stride(plane, pixel_format, modifier,
2530 u32 intel_fb_max_stride(struct drm_i915_private *dev_priv,
2531 u32 pixel_format, u64 modifier)
2534 * Arbitrary limit for gen4+ chosen to match the
2535 * render engine max stride.
2537 * The new CCS hash mode makes remapping impossible
2539 if (!is_ccs_modifier(modifier)) {
2540 if (INTEL_GEN(dev_priv) >= 7)
2542 else if (INTEL_GEN(dev_priv) >= 4)
2546 return intel_plane_fb_max_stride(dev_priv, pixel_format, modifier);
2550 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
2552 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2554 if (fb->modifier == DRM_FORMAT_MOD_LINEAR) {
2555 u32 max_stride = intel_plane_fb_max_stride(dev_priv,
2560 * To make remapping with linear generally feasible
2561 * we need the stride to be page aligned.
2563 if (fb->pitches[color_plane] > max_stride)
2564 return intel_tile_size(dev_priv);
2568 return intel_tile_width_bytes(fb, color_plane);
2572 bool intel_plane_can_remap(const struct intel_plane_state *plane_state)
2574 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2575 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2576 const struct drm_framebuffer *fb = plane_state->base.fb;
2579 /* We don't want to deal with remapping with cursors */
2580 if (plane->id == PLANE_CURSOR)
2584 * The display engine limits already match/exceed the
2585 * render engine limits, so not much point in remapping.
2586 * Would also need to deal with the fence POT alignment
2587 * and gen2 2KiB GTT tile size.
2589 if (INTEL_GEN(dev_priv) < 4)
2593 * The new CCS hash mode isn't compatible with remapping as
2594 * the virtual address of the pages affects the compressed data.
2596 if (is_ccs_modifier(fb->modifier))
2599 /* Linear needs a page aligned stride for remapping */
2600 if (fb->modifier == DRM_FORMAT_MOD_LINEAR) {
2601 unsigned int alignment = intel_tile_size(dev_priv) - 1;
2603 for (i = 0; i < fb->format->num_planes; i++) {
2604 if (fb->pitches[i] & alignment)
2612 static bool intel_plane_needs_remap(const struct intel_plane_state *plane_state)
2614 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2615 const struct drm_framebuffer *fb = plane_state->base.fb;
2616 unsigned int rotation = plane_state->base.rotation;
2617 u32 stride, max_stride;
2620 * No remapping for invisible planes since we don't have
2621 * an actual source viewport to remap.
2623 if (!plane_state->base.visible)
2626 if (!intel_plane_can_remap(plane_state))
2630 * FIXME: aux plane limits on gen9+ are
2631 * unclear in Bspec, for now no checking.
2633 stride = intel_fb_pitch(fb, 0, rotation);
2634 max_stride = plane->max_stride(plane, fb->format->format,
2635 fb->modifier, rotation);
2637 return stride > max_stride;
2641 intel_fill_fb_info(struct drm_i915_private *dev_priv,
2642 struct drm_framebuffer *fb)
2644 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2645 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2646 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2647 u32 gtt_offset_rotated = 0;
2648 unsigned int max_size = 0;
2649 int i, num_planes = fb->format->num_planes;
2650 unsigned int tile_size = intel_tile_size(dev_priv);
2652 for (i = 0; i < num_planes; i++) {
2653 unsigned int width, height;
2654 unsigned int cpp, size;
2659 cpp = fb->format->cpp[i];
2660 width = drm_framebuffer_plane_width(fb->width, fb, i);
2661 height = drm_framebuffer_plane_height(fb->height, fb, i);
2663 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2665 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2670 if (is_ccs_modifier(fb->modifier) && i == 1) {
2671 int hsub = fb->format->hsub;
2672 int vsub = fb->format->vsub;
2673 int tile_width, tile_height;
2677 intel_tile_dims(fb, i, &tile_width, &tile_height);
2679 tile_height *= vsub;
2681 ccs_x = (x * hsub) % tile_width;
2682 ccs_y = (y * vsub) % tile_height;
2683 main_x = intel_fb->normal[0].x % tile_width;
2684 main_y = intel_fb->normal[0].y % tile_height;
2687 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2688 * x/y offsets must match between CCS and the main surface.
2690 if (main_x != ccs_x || main_y != ccs_y) {
2691 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2694 intel_fb->normal[0].x,
2695 intel_fb->normal[0].y,
2702 * The fence (if used) is aligned to the start of the object
2703 * so having the framebuffer wrap around across the edge of the
2704 * fenced region doesn't really work. We have no API to configure
2705 * the fence start offset within the object (nor could we probably
2706 * on gen2/3). So it's just easier if we just require that the
2707 * fb layout agrees with the fence layout. We already check that the
2708 * fb stride matches the fence stride elsewhere.
2710 if (i == 0 && i915_gem_object_is_tiled(obj) &&
2711 (x + width) * cpp > fb->pitches[i]) {
2712 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2718 * First pixel of the framebuffer from
2719 * the start of the normal gtt mapping.
2721 intel_fb->normal[i].x = x;
2722 intel_fb->normal[i].y = y;
2724 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
2728 offset /= tile_size;
2730 if (!is_surface_linear(fb->modifier, i)) {
2731 unsigned int tile_width, tile_height;
2732 unsigned int pitch_tiles;
2735 intel_tile_dims(fb, i, &tile_width, &tile_height);
2737 rot_info->plane[i].offset = offset;
2738 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2739 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2740 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2742 intel_fb->rotated[i].pitch =
2743 rot_info->plane[i].height * tile_height;
2745 /* how many tiles does this plane need */
2746 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2748 * If the plane isn't horizontally tile aligned,
2749 * we need one more tile.
2754 /* rotate the x/y offsets to match the GTT view */
2760 rot_info->plane[i].width * tile_width,
2761 rot_info->plane[i].height * tile_height,
2762 DRM_MODE_ROTATE_270);
2766 /* rotate the tile dimensions to match the GTT view */
2767 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2768 swap(tile_width, tile_height);
2771 * We only keep the x/y offsets, so push all of the
2772 * gtt offset into the x/y offsets.
2774 intel_adjust_tile_offset(&x, &y,
2775 tile_width, tile_height,
2776 tile_size, pitch_tiles,
2777 gtt_offset_rotated * tile_size, 0);
2779 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2782 * First pixel of the framebuffer from
2783 * the start of the rotated gtt mapping.
2785 intel_fb->rotated[i].x = x;
2786 intel_fb->rotated[i].y = y;
2788 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2789 x * cpp, tile_size);
2792 /* how many tiles in total needed in the bo */
2793 max_size = max(max_size, offset + size);
2796 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
2797 DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n",
2798 mul_u32_u32(max_size, tile_size), obj->base.size);
2806 intel_plane_remap_gtt(struct intel_plane_state *plane_state)
2808 struct drm_i915_private *dev_priv =
2809 to_i915(plane_state->base.plane->dev);
2810 struct drm_framebuffer *fb = plane_state->base.fb;
2811 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2812 struct intel_rotation_info *info = &plane_state->view.rotated;
2813 unsigned int rotation = plane_state->base.rotation;
2814 int i, num_planes = fb->format->num_planes;
2815 unsigned int tile_size = intel_tile_size(dev_priv);
2816 unsigned int src_x, src_y;
2817 unsigned int src_w, src_h;
2820 memset(&plane_state->view, 0, sizeof(plane_state->view));
2821 plane_state->view.type = drm_rotation_90_or_270(rotation) ?
2822 I915_GGTT_VIEW_ROTATED : I915_GGTT_VIEW_REMAPPED;
2824 src_x = plane_state->base.src.x1 >> 16;
2825 src_y = plane_state->base.src.y1 >> 16;
2826 src_w = drm_rect_width(&plane_state->base.src) >> 16;
2827 src_h = drm_rect_height(&plane_state->base.src) >> 16;
2829 WARN_ON(is_ccs_modifier(fb->modifier));
2831 /* Make src coordinates relative to the viewport */
2832 drm_rect_translate(&plane_state->base.src,
2833 -(src_x << 16), -(src_y << 16));
2835 /* Rotate src coordinates to match rotated GTT view */
2836 if (drm_rotation_90_or_270(rotation))
2837 drm_rect_rotate(&plane_state->base.src,
2838 src_w << 16, src_h << 16,
2839 DRM_MODE_ROTATE_270);
2841 for (i = 0; i < num_planes; i++) {
2842 unsigned int hsub = i ? fb->format->hsub : 1;
2843 unsigned int vsub = i ? fb->format->vsub : 1;
2844 unsigned int cpp = fb->format->cpp[i];
2845 unsigned int tile_width, tile_height;
2846 unsigned int width, height;
2847 unsigned int pitch_tiles;
2851 intel_tile_dims(fb, i, &tile_width, &tile_height);
2855 width = src_w / hsub;
2856 height = src_h / vsub;
2859 * First pixel of the src viewport from the
2860 * start of the normal gtt mapping.
2862 x += intel_fb->normal[i].x;
2863 y += intel_fb->normal[i].y;
2865 offset = intel_compute_aligned_offset(dev_priv, &x, &y,
2866 fb, i, fb->pitches[i],
2867 DRM_MODE_ROTATE_0, tile_size);
2868 offset /= tile_size;
2870 info->plane[i].offset = offset;
2871 info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i],
2873 info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2874 info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2876 if (drm_rotation_90_or_270(rotation)) {
2879 /* rotate the x/y offsets to match the GTT view */
2885 info->plane[i].width * tile_width,
2886 info->plane[i].height * tile_height,
2887 DRM_MODE_ROTATE_270);
2891 pitch_tiles = info->plane[i].height;
2892 plane_state->color_plane[i].stride = pitch_tiles * tile_height;
2894 /* rotate the tile dimensions to match the GTT view */
2895 swap(tile_width, tile_height);
2897 pitch_tiles = info->plane[i].width;
2898 plane_state->color_plane[i].stride = pitch_tiles * tile_width * cpp;
2902 * We only keep the x/y offsets, so push all of the
2903 * gtt offset into the x/y offsets.
2905 intel_adjust_tile_offset(&x, &y,
2906 tile_width, tile_height,
2907 tile_size, pitch_tiles,
2908 gtt_offset * tile_size, 0);
2910 gtt_offset += info->plane[i].width * info->plane[i].height;
2912 plane_state->color_plane[i].offset = 0;
2913 plane_state->color_plane[i].x = x;
2914 plane_state->color_plane[i].y = y;
2919 intel_plane_compute_gtt(struct intel_plane_state *plane_state)
2921 const struct intel_framebuffer *fb =
2922 to_intel_framebuffer(plane_state->base.fb);
2923 unsigned int rotation = plane_state->base.rotation;
2929 num_planes = fb->base.format->num_planes;
2931 if (intel_plane_needs_remap(plane_state)) {
2932 intel_plane_remap_gtt(plane_state);
2935 * Sometimes even remapping can't overcome
2936 * the stride limitations :( Can happen with
2937 * big plane sizes and suitably misaligned
2940 return intel_plane_check_stride(plane_state);
2943 intel_fill_fb_ggtt_view(&plane_state->view, &fb->base, rotation);
2945 for (i = 0; i < num_planes; i++) {
2946 plane_state->color_plane[i].stride = intel_fb_pitch(&fb->base, i, rotation);
2947 plane_state->color_plane[i].offset = 0;
2949 if (drm_rotation_90_or_270(rotation)) {
2950 plane_state->color_plane[i].x = fb->rotated[i].x;
2951 plane_state->color_plane[i].y = fb->rotated[i].y;
2953 plane_state->color_plane[i].x = fb->normal[i].x;
2954 plane_state->color_plane[i].y = fb->normal[i].y;
2958 /* Rotate src coordinates to match rotated GTT view */
2959 if (drm_rotation_90_or_270(rotation))
2960 drm_rect_rotate(&plane_state->base.src,
2961 fb->base.width << 16, fb->base.height << 16,
2962 DRM_MODE_ROTATE_270);
2964 return intel_plane_check_stride(plane_state);
2967 static int i9xx_format_to_fourcc(int format)
2970 case DISPPLANE_8BPP:
2971 return DRM_FORMAT_C8;
2972 case DISPPLANE_BGRX555:
2973 return DRM_FORMAT_XRGB1555;
2974 case DISPPLANE_BGRX565:
2975 return DRM_FORMAT_RGB565;
2977 case DISPPLANE_BGRX888:
2978 return DRM_FORMAT_XRGB8888;
2979 case DISPPLANE_RGBX888:
2980 return DRM_FORMAT_XBGR8888;
2981 case DISPPLANE_BGRX101010:
2982 return DRM_FORMAT_XRGB2101010;
2983 case DISPPLANE_RGBX101010:
2984 return DRM_FORMAT_XBGR2101010;
2988 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
2991 case PLANE_CTL_FORMAT_RGB_565:
2992 return DRM_FORMAT_RGB565;
2993 case PLANE_CTL_FORMAT_NV12:
2994 return DRM_FORMAT_NV12;
2995 case PLANE_CTL_FORMAT_P010:
2996 return DRM_FORMAT_P010;
2997 case PLANE_CTL_FORMAT_P012:
2998 return DRM_FORMAT_P012;
2999 case PLANE_CTL_FORMAT_P016:
3000 return DRM_FORMAT_P016;
3001 case PLANE_CTL_FORMAT_Y210:
3002 return DRM_FORMAT_Y210;
3003 case PLANE_CTL_FORMAT_Y212:
3004 return DRM_FORMAT_Y212;
3005 case PLANE_CTL_FORMAT_Y216:
3006 return DRM_FORMAT_Y216;
3007 case PLANE_CTL_FORMAT_Y410:
3008 return DRM_FORMAT_XVYU2101010;
3009 case PLANE_CTL_FORMAT_Y412:
3010 return DRM_FORMAT_XVYU12_16161616;
3011 case PLANE_CTL_FORMAT_Y416:
3012 return DRM_FORMAT_XVYU16161616;
3014 case PLANE_CTL_FORMAT_XRGB_8888:
3017 return DRM_FORMAT_ABGR8888;
3019 return DRM_FORMAT_XBGR8888;
3022 return DRM_FORMAT_ARGB8888;
3024 return DRM_FORMAT_XRGB8888;
3026 case PLANE_CTL_FORMAT_XRGB_2101010:
3028 return DRM_FORMAT_XBGR2101010;
3030 return DRM_FORMAT_XRGB2101010;
3031 case PLANE_CTL_FORMAT_XRGB_16161616F:
3034 return DRM_FORMAT_ABGR16161616F;
3036 return DRM_FORMAT_XBGR16161616F;
3039 return DRM_FORMAT_ARGB16161616F;
3041 return DRM_FORMAT_XRGB16161616F;
3047 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
3048 struct intel_initial_plane_config *plane_config)
3050 struct drm_device *dev = crtc->base.dev;
3051 struct drm_i915_private *dev_priv = to_i915(dev);
3052 struct drm_i915_gem_object *obj = NULL;
3053 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
3054 struct drm_framebuffer *fb = &plane_config->fb->base;
3055 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
3056 u32 size_aligned = round_up(plane_config->base + plane_config->size,
3059 size_aligned -= base_aligned;
3061 if (plane_config->size == 0)
3064 /* If the FB is too big, just don't use it since fbdev is not very
3065 * important and we should probably use that space with FBC or other
3067 if (size_aligned * 2 > dev_priv->stolen_usable_size)
3070 switch (fb->modifier) {
3071 case DRM_FORMAT_MOD_LINEAR:
3072 case I915_FORMAT_MOD_X_TILED:
3073 case I915_FORMAT_MOD_Y_TILED:
3076 DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n",
3081 mutex_lock(&dev->struct_mutex);
3082 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
3086 mutex_unlock(&dev->struct_mutex);
3090 switch (plane_config->tiling) {
3091 case I915_TILING_NONE:
3095 obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling;
3098 MISSING_CASE(plane_config->tiling);
3102 mode_cmd.pixel_format = fb->format->format;
3103 mode_cmd.width = fb->width;
3104 mode_cmd.height = fb->height;
3105 mode_cmd.pitches[0] = fb->pitches[0];
3106 mode_cmd.modifier[0] = fb->modifier;
3107 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
3109 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
3110 DRM_DEBUG_KMS("intel fb init failed\n");
3115 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
3119 i915_gem_object_put(obj);
3124 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
3125 struct intel_plane_state *plane_state,
3128 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
3130 plane_state->base.visible = visible;
3133 crtc_state->base.plane_mask |= drm_plane_mask(&plane->base);
3135 crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base);
3138 static void fixup_active_planes(struct intel_crtc_state *crtc_state)
3140 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
3141 struct drm_plane *plane;
3144 * Active_planes aliases if multiple "primary" or cursor planes
3145 * have been used on the same (or wrong) pipe. plane_mask uses
3146 * unique ids, hence we can use that to reconstruct active_planes.
3148 crtc_state->active_planes = 0;
3150 drm_for_each_plane_mask(plane, &dev_priv->drm,
3151 crtc_state->base.plane_mask)
3152 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
3155 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
3156 struct intel_plane *plane)
3158 struct intel_crtc_state *crtc_state =
3159 to_intel_crtc_state(crtc->base.state);
3160 struct intel_plane_state *plane_state =
3161 to_intel_plane_state(plane->base.state);
3163 DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
3164 plane->base.base.id, plane->base.name,
3165 crtc->base.base.id, crtc->base.name);
3167 intel_set_plane_visible(crtc_state, plane_state, false);
3168 fixup_active_planes(crtc_state);
3169 crtc_state->data_rate[plane->id] = 0;
3171 if (plane->id == PLANE_PRIMARY)
3172 intel_pre_disable_primary_noatomic(&crtc->base);
3174 intel_disable_plane(plane, crtc_state);
3178 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
3179 struct intel_initial_plane_config *plane_config)
3181 struct drm_device *dev = intel_crtc->base.dev;
3182 struct drm_i915_private *dev_priv = to_i915(dev);
3184 struct drm_i915_gem_object *obj;
3185 struct drm_plane *primary = intel_crtc->base.primary;
3186 struct drm_plane_state *plane_state = primary->state;
3187 struct intel_plane *intel_plane = to_intel_plane(primary);
3188 struct intel_plane_state *intel_state =
3189 to_intel_plane_state(plane_state);
3190 struct drm_framebuffer *fb;
3192 if (!plane_config->fb)
3195 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
3196 fb = &plane_config->fb->base;
3200 kfree(plane_config->fb);
3203 * Failed to alloc the obj, check to see if we should share
3204 * an fb with another CRTC instead
3206 for_each_crtc(dev, c) {
3207 struct intel_plane_state *state;
3209 if (c == &intel_crtc->base)
3212 if (!to_intel_crtc(c)->active)
3215 state = to_intel_plane_state(c->primary->state);
3219 if (intel_plane_ggtt_offset(state) == plane_config->base) {
3220 fb = state->base.fb;
3221 drm_framebuffer_get(fb);
3227 * We've failed to reconstruct the BIOS FB. Current display state
3228 * indicates that the primary plane is visible, but has a NULL FB,
3229 * which will lead to problems later if we don't fix it up. The
3230 * simplest solution is to just disable the primary plane now and
3231 * pretend the BIOS never had it enabled.
3233 intel_plane_disable_noatomic(intel_crtc, intel_plane);
3238 intel_state->base.rotation = plane_config->rotation;
3239 intel_fill_fb_ggtt_view(&intel_state->view, fb,
3240 intel_state->base.rotation);
3241 intel_state->color_plane[0].stride =
3242 intel_fb_pitch(fb, 0, intel_state->base.rotation);
3244 mutex_lock(&dev->struct_mutex);
3246 intel_pin_and_fence_fb_obj(fb,
3248 intel_plane_uses_fence(intel_state),
3249 &intel_state->flags);
3250 mutex_unlock(&dev->struct_mutex);
3251 if (IS_ERR(intel_state->vma)) {
3252 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
3253 intel_crtc->pipe, PTR_ERR(intel_state->vma));
3255 intel_state->vma = NULL;
3256 drm_framebuffer_put(fb);
3260 obj = intel_fb_obj(fb);
3261 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
3263 plane_state->src_x = 0;
3264 plane_state->src_y = 0;
3265 plane_state->src_w = fb->width << 16;
3266 plane_state->src_h = fb->height << 16;
3268 plane_state->crtc_x = 0;
3269 plane_state->crtc_y = 0;
3270 plane_state->crtc_w = fb->width;
3271 plane_state->crtc_h = fb->height;
3273 intel_state->base.src = drm_plane_state_src(plane_state);
3274 intel_state->base.dst = drm_plane_state_dest(plane_state);
3276 if (i915_gem_object_is_tiled(obj))
3277 dev_priv->preserve_bios_swizzle = true;
3279 plane_state->fb = fb;
3280 plane_state->crtc = &intel_crtc->base;
3282 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
3283 &obj->frontbuffer_bits);
3286 static int skl_max_plane_width(const struct drm_framebuffer *fb,
3288 unsigned int rotation)
3290 int cpp = fb->format->cpp[color_plane];
3292 switch (fb->modifier) {
3293 case DRM_FORMAT_MOD_LINEAR:
3294 case I915_FORMAT_MOD_X_TILED:
3296 case I915_FORMAT_MOD_Y_TILED_CCS:
3297 case I915_FORMAT_MOD_Yf_TILED_CCS:
3298 /* FIXME AUX plane? */
3299 case I915_FORMAT_MOD_Y_TILED:
3300 case I915_FORMAT_MOD_Yf_TILED:
3306 MISSING_CASE(fb->modifier);
3311 static int glk_max_plane_width(const struct drm_framebuffer *fb,
3313 unsigned int rotation)
3315 int cpp = fb->format->cpp[color_plane];
3317 switch (fb->modifier) {
3318 case DRM_FORMAT_MOD_LINEAR:
3319 case I915_FORMAT_MOD_X_TILED:
3324 case I915_FORMAT_MOD_Y_TILED_CCS:
3325 case I915_FORMAT_MOD_Yf_TILED_CCS:
3326 /* FIXME AUX plane? */
3327 case I915_FORMAT_MOD_Y_TILED:
3328 case I915_FORMAT_MOD_Yf_TILED:
3334 MISSING_CASE(fb->modifier);
3339 static int icl_max_plane_width(const struct drm_framebuffer *fb,
3341 unsigned int rotation)
3346 static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
3347 int main_x, int main_y, u32 main_offset)
3349 const struct drm_framebuffer *fb = plane_state->base.fb;
3350 int hsub = fb->format->hsub;
3351 int vsub = fb->format->vsub;
3352 int aux_x = plane_state->color_plane[1].x;
3353 int aux_y = plane_state->color_plane[1].y;
3354 u32 aux_offset = plane_state->color_plane[1].offset;
3355 u32 alignment = intel_surf_alignment(fb, 1);
3357 while (aux_offset >= main_offset && aux_y <= main_y) {
3360 if (aux_x == main_x && aux_y == main_y)
3363 if (aux_offset == 0)
3368 aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1,
3369 aux_offset, aux_offset - alignment);
3370 aux_x = x * hsub + aux_x % hsub;
3371 aux_y = y * vsub + aux_y % vsub;
3374 if (aux_x != main_x || aux_y != main_y)
3377 plane_state->color_plane[1].offset = aux_offset;
3378 plane_state->color_plane[1].x = aux_x;
3379 plane_state->color_plane[1].y = aux_y;
3384 static int skl_check_main_surface(struct intel_plane_state *plane_state)
3386 struct drm_i915_private *dev_priv = to_i915(plane_state->base.plane->dev);
3387 const struct drm_framebuffer *fb = plane_state->base.fb;
3388 unsigned int rotation = plane_state->base.rotation;
3389 int x = plane_state->base.src.x1 >> 16;
3390 int y = plane_state->base.src.y1 >> 16;
3391 int w = drm_rect_width(&plane_state->base.src) >> 16;
3392 int h = drm_rect_height(&plane_state->base.src) >> 16;
3394 int max_height = 4096;
3395 u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset;
3397 if (INTEL_GEN(dev_priv) >= 11)
3398 max_width = icl_max_plane_width(fb, 0, rotation);
3399 else if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
3400 max_width = glk_max_plane_width(fb, 0, rotation);
3402 max_width = skl_max_plane_width(fb, 0, rotation);
3404 if (w > max_width || h > max_height) {
3405 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
3406 w, h, max_width, max_height);
3410 intel_add_fb_offsets(&x, &y, plane_state, 0);
3411 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
3412 alignment = intel_surf_alignment(fb, 0);
3415 * AUX surface offset is specified as the distance from the
3416 * main surface offset, and it must be non-negative. Make
3417 * sure that is what we will get.
3419 if (offset > aux_offset)
3420 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3421 offset, aux_offset & ~(alignment - 1));
3424 * When using an X-tiled surface, the plane blows up
3425 * if the x offset + width exceed the stride.
3427 * TODO: linear and Y-tiled seem fine, Yf untested,
3429 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3430 int cpp = fb->format->cpp[0];
3432 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
3434 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
3438 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3439 offset, offset - alignment);
3444 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3445 * they match with the main surface x/y offsets.
3447 if (is_ccs_modifier(fb->modifier)) {
3448 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3452 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3453 offset, offset - alignment);
3456 if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) {
3457 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3462 plane_state->color_plane[0].offset = offset;
3463 plane_state->color_plane[0].x = x;
3464 plane_state->color_plane[0].y = y;
3467 * Put the final coordinates back so that the src
3468 * coordinate checks will see the right values.
3470 drm_rect_translate(&plane_state->base.src,
3471 (x << 16) - plane_state->base.src.x1,
3472 (y << 16) - plane_state->base.src.y1);
3477 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3479 const struct drm_framebuffer *fb = plane_state->base.fb;
3480 unsigned int rotation = plane_state->base.rotation;
3481 int max_width = skl_max_plane_width(fb, 1, rotation);
3482 int max_height = 4096;
3483 int x = plane_state->base.src.x1 >> 17;
3484 int y = plane_state->base.src.y1 >> 17;
3485 int w = drm_rect_width(&plane_state->base.src) >> 17;
3486 int h = drm_rect_height(&plane_state->base.src) >> 17;
3489 intel_add_fb_offsets(&x, &y, plane_state, 1);
3490 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3492 /* FIXME not quite sure how/if these apply to the chroma plane */
3493 if (w > max_width || h > max_height) {
3494 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3495 w, h, max_width, max_height);
3499 plane_state->color_plane[1].offset = offset;
3500 plane_state->color_plane[1].x = x;
3501 plane_state->color_plane[1].y = y;
3506 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3508 const struct drm_framebuffer *fb = plane_state->base.fb;
3509 int src_x = plane_state->base.src.x1 >> 16;
3510 int src_y = plane_state->base.src.y1 >> 16;
3511 int hsub = fb->format->hsub;
3512 int vsub = fb->format->vsub;
3513 int x = src_x / hsub;
3514 int y = src_y / vsub;
3517 intel_add_fb_offsets(&x, &y, plane_state, 1);
3518 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3520 plane_state->color_plane[1].offset = offset;
3521 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3522 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
3527 int skl_check_plane_surface(struct intel_plane_state *plane_state)
3529 const struct drm_framebuffer *fb = plane_state->base.fb;
3532 ret = intel_plane_compute_gtt(plane_state);
3536 if (!plane_state->base.visible)
3540 * Handle the AUX surface first since
3541 * the main surface setup depends on it.
3543 if (is_planar_yuv_format(fb->format->format)) {
3544 ret = skl_check_nv12_aux_surface(plane_state);
3547 } else if (is_ccs_modifier(fb->modifier)) {
3548 ret = skl_check_ccs_aux_surface(plane_state);
3552 plane_state->color_plane[1].offset = ~0xfff;
3553 plane_state->color_plane[1].x = 0;
3554 plane_state->color_plane[1].y = 0;
3557 ret = skl_check_main_surface(plane_state);
3565 i9xx_plane_max_stride(struct intel_plane *plane,
3566 u32 pixel_format, u64 modifier,
3567 unsigned int rotation)
3569 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3571 if (!HAS_GMCH(dev_priv)) {
3573 } else if (INTEL_GEN(dev_priv) >= 4) {
3574 if (modifier == I915_FORMAT_MOD_X_TILED)
3578 } else if (INTEL_GEN(dev_priv) >= 3) {
3579 if (modifier == I915_FORMAT_MOD_X_TILED)
3584 if (plane->i9xx_plane == PLANE_C)
3591 static u32 i9xx_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
3593 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3594 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3597 if (crtc_state->gamma_enable)
3598 dspcntr |= DISPPLANE_GAMMA_ENABLE;
3600 if (crtc_state->csc_enable)
3601 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
3603 if (INTEL_GEN(dev_priv) < 5)
3604 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
3609 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3610 const struct intel_plane_state *plane_state)
3612 struct drm_i915_private *dev_priv =
3613 to_i915(plane_state->base.plane->dev);
3614 const struct drm_framebuffer *fb = plane_state->base.fb;
3615 unsigned int rotation = plane_state->base.rotation;
3618 dspcntr = DISPLAY_PLANE_ENABLE;
3620 if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) ||
3621 IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
3622 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
3624 switch (fb->format->format) {
3626 dspcntr |= DISPPLANE_8BPP;
3628 case DRM_FORMAT_XRGB1555:
3629 dspcntr |= DISPPLANE_BGRX555;
3631 case DRM_FORMAT_RGB565:
3632 dspcntr |= DISPPLANE_BGRX565;
3634 case DRM_FORMAT_XRGB8888:
3635 dspcntr |= DISPPLANE_BGRX888;
3637 case DRM_FORMAT_XBGR8888:
3638 dspcntr |= DISPPLANE_RGBX888;
3640 case DRM_FORMAT_XRGB2101010:
3641 dspcntr |= DISPPLANE_BGRX101010;
3643 case DRM_FORMAT_XBGR2101010:
3644 dspcntr |= DISPPLANE_RGBX101010;
3647 MISSING_CASE(fb->format->format);
3651 if (INTEL_GEN(dev_priv) >= 4 &&
3652 fb->modifier == I915_FORMAT_MOD_X_TILED)
3653 dspcntr |= DISPPLANE_TILED;
3655 if (rotation & DRM_MODE_ROTATE_180)
3656 dspcntr |= DISPPLANE_ROTATE_180;
3658 if (rotation & DRM_MODE_REFLECT_X)
3659 dspcntr |= DISPPLANE_MIRROR;
3664 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
3666 struct drm_i915_private *dev_priv =
3667 to_i915(plane_state->base.plane->dev);
3672 ret = intel_plane_compute_gtt(plane_state);
3676 if (!plane_state->base.visible)
3679 src_x = plane_state->base.src.x1 >> 16;
3680 src_y = plane_state->base.src.y1 >> 16;
3682 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
3684 if (INTEL_GEN(dev_priv) >= 4)
3685 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
3691 * Put the final coordinates back so that the src
3692 * coordinate checks will see the right values.
3694 drm_rect_translate(&plane_state->base.src,
3695 (src_x << 16) - plane_state->base.src.x1,
3696 (src_y << 16) - plane_state->base.src.y1);
3698 /* HSW/BDW do this automagically in hardware */
3699 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
3700 unsigned int rotation = plane_state->base.rotation;
3701 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3702 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3704 if (rotation & DRM_MODE_ROTATE_180) {
3707 } else if (rotation & DRM_MODE_REFLECT_X) {
3712 plane_state->color_plane[0].offset = offset;
3713 plane_state->color_plane[0].x = src_x;
3714 plane_state->color_plane[0].y = src_y;
3719 static bool i9xx_plane_has_windowing(struct intel_plane *plane)
3721 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3722 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3724 if (IS_CHERRYVIEW(dev_priv))
3725 return i9xx_plane == PLANE_B;
3726 else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
3728 else if (IS_GEN(dev_priv, 4))
3729 return i9xx_plane == PLANE_C;
3731 return i9xx_plane == PLANE_B ||
3732 i9xx_plane == PLANE_C;
3736 i9xx_plane_check(struct intel_crtc_state *crtc_state,
3737 struct intel_plane_state *plane_state)
3739 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
3742 ret = chv_plane_check_rotation(plane_state);
3746 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
3748 DRM_PLANE_HELPER_NO_SCALING,
3749 DRM_PLANE_HELPER_NO_SCALING,
3750 i9xx_plane_has_windowing(plane),
3755 ret = i9xx_check_plane_surface(plane_state);
3759 if (!plane_state->base.visible)
3762 ret = intel_plane_check_src_coordinates(plane_state);
3766 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
3771 static void i9xx_update_plane(struct intel_plane *plane,
3772 const struct intel_crtc_state *crtc_state,
3773 const struct intel_plane_state *plane_state)
3775 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3776 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3778 int x = plane_state->color_plane[0].x;
3779 int y = plane_state->color_plane[0].y;
3780 int crtc_x = plane_state->base.dst.x1;
3781 int crtc_y = plane_state->base.dst.y1;
3782 int crtc_w = drm_rect_width(&plane_state->base.dst);
3783 int crtc_h = drm_rect_height(&plane_state->base.dst);
3784 unsigned long irqflags;
3788 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
3790 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
3792 if (INTEL_GEN(dev_priv) >= 4)
3793 dspaddr_offset = plane_state->color_plane[0].offset;
3795 dspaddr_offset = linear_offset;
3797 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3799 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
3801 if (INTEL_GEN(dev_priv) < 4) {
3803 * PLANE_A doesn't actually have a full window
3804 * generator but let's assume we still need to
3805 * program whatever is there.
3807 I915_WRITE_FW(DSPPOS(i9xx_plane), (crtc_y << 16) | crtc_x);
3808 I915_WRITE_FW(DSPSIZE(i9xx_plane),
3809 ((crtc_h - 1) << 16) | (crtc_w - 1));
3810 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
3811 I915_WRITE_FW(PRIMPOS(i9xx_plane), (crtc_y << 16) | crtc_x);
3812 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
3813 ((crtc_h - 1) << 16) | (crtc_w - 1));
3814 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
3817 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3818 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
3819 } else if (INTEL_GEN(dev_priv) >= 4) {
3820 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3821 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3825 * The control register self-arms if the plane was previously
3826 * disabled. Try to make the plane enable atomic by writing
3827 * the control register just before the surface register.
3829 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3830 if (INTEL_GEN(dev_priv) >= 4)
3831 I915_WRITE_FW(DSPSURF(i9xx_plane),
3832 intel_plane_ggtt_offset(plane_state) +
3835 I915_WRITE_FW(DSPADDR(i9xx_plane),
3836 intel_plane_ggtt_offset(plane_state) +
3839 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3842 static void i9xx_disable_plane(struct intel_plane *plane,
3843 const struct intel_crtc_state *crtc_state)
3845 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3846 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3847 unsigned long irqflags;
3851 * DSPCNTR pipe gamma enable on g4x+ and pipe csc
3852 * enable on ilk+ affect the pipe bottom color as
3853 * well, so we must configure them even if the plane
3856 * On pre-g4x there is no way to gamma correct the
3857 * pipe bottom color but we'll keep on doing this
3858 * anyway so that the crtc state readout works correctly.
3860 dspcntr = i9xx_plane_ctl_crtc(crtc_state);
3862 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3864 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3865 if (INTEL_GEN(dev_priv) >= 4)
3866 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
3868 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
3870 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3873 static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
3876 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3877 enum intel_display_power_domain power_domain;
3878 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3879 intel_wakeref_t wakeref;
3884 * Not 100% correct for planes that can move between pipes,
3885 * but that's only the case for gen2-4 which don't have any
3886 * display power wells.
3888 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
3889 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3893 val = I915_READ(DSPCNTR(i9xx_plane));
3895 ret = val & DISPLAY_PLANE_ENABLE;
3897 if (INTEL_GEN(dev_priv) >= 5)
3898 *pipe = plane->pipe;
3900 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
3901 DISPPLANE_SEL_PIPE_SHIFT;
3903 intel_display_power_put(dev_priv, power_domain, wakeref);
3908 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3910 struct drm_device *dev = intel_crtc->base.dev;
3911 struct drm_i915_private *dev_priv = to_i915(dev);
3913 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3914 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3915 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
3919 * This function detaches (aka. unbinds) unused scalers in hardware
3921 static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
3923 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3924 const struct intel_crtc_scaler_state *scaler_state =
3925 &crtc_state->scaler_state;
3928 /* loop through and disable scalers that aren't in use */
3929 for (i = 0; i < intel_crtc->num_scalers; i++) {
3930 if (!scaler_state->scalers[i].in_use)
3931 skl_detach_scaler(intel_crtc, i);
3935 static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
3936 int color_plane, unsigned int rotation)
3939 * The stride is either expressed as a multiple of 64 bytes chunks for
3940 * linear buffers or in number of tiles for tiled buffers.
3942 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3944 else if (drm_rotation_90_or_270(rotation))
3945 return intel_tile_height(fb, color_plane);
3947 return intel_tile_width_bytes(fb, color_plane);
3950 u32 skl_plane_stride(const struct intel_plane_state *plane_state,
3953 const struct drm_framebuffer *fb = plane_state->base.fb;
3954 unsigned int rotation = plane_state->base.rotation;
3955 u32 stride = plane_state->color_plane[color_plane].stride;
3957 if (color_plane >= fb->format->num_planes)
3960 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
3963 static u32 skl_plane_ctl_format(u32 pixel_format)
3965 switch (pixel_format) {
3967 return PLANE_CTL_FORMAT_INDEXED;
3968 case DRM_FORMAT_RGB565:
3969 return PLANE_CTL_FORMAT_RGB_565;
3970 case DRM_FORMAT_XBGR8888:
3971 case DRM_FORMAT_ABGR8888:
3972 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
3973 case DRM_FORMAT_XRGB8888:
3974 case DRM_FORMAT_ARGB8888:
3975 return PLANE_CTL_FORMAT_XRGB_8888;
3976 case DRM_FORMAT_XBGR2101010:
3977 return PLANE_CTL_FORMAT_XRGB_2101010 | PLANE_CTL_ORDER_RGBX;
3978 case DRM_FORMAT_XRGB2101010:
3979 return PLANE_CTL_FORMAT_XRGB_2101010;
3980 case DRM_FORMAT_XBGR16161616F:
3981 case DRM_FORMAT_ABGR16161616F:
3982 return PLANE_CTL_FORMAT_XRGB_16161616F | PLANE_CTL_ORDER_RGBX;
3983 case DRM_FORMAT_XRGB16161616F:
3984 case DRM_FORMAT_ARGB16161616F:
3985 return PLANE_CTL_FORMAT_XRGB_16161616F;
3986 case DRM_FORMAT_YUYV:
3987 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
3988 case DRM_FORMAT_YVYU:
3989 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
3990 case DRM_FORMAT_UYVY:
3991 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
3992 case DRM_FORMAT_VYUY:
3993 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
3994 case DRM_FORMAT_NV12:
3995 return PLANE_CTL_FORMAT_NV12;
3996 case DRM_FORMAT_P010:
3997 return PLANE_CTL_FORMAT_P010;
3998 case DRM_FORMAT_P012:
3999 return PLANE_CTL_FORMAT_P012;
4000 case DRM_FORMAT_P016:
4001 return PLANE_CTL_FORMAT_P016;
4002 case DRM_FORMAT_Y210:
4003 return PLANE_CTL_FORMAT_Y210;
4004 case DRM_FORMAT_Y212:
4005 return PLANE_CTL_FORMAT_Y212;
4006 case DRM_FORMAT_Y216:
4007 return PLANE_CTL_FORMAT_Y216;
4008 case DRM_FORMAT_XVYU2101010:
4009 return PLANE_CTL_FORMAT_Y410;
4010 case DRM_FORMAT_XVYU12_16161616:
4011 return PLANE_CTL_FORMAT_Y412;
4012 case DRM_FORMAT_XVYU16161616:
4013 return PLANE_CTL_FORMAT_Y416;
4015 MISSING_CASE(pixel_format);
4021 static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
4023 if (!plane_state->base.fb->format->has_alpha)
4024 return PLANE_CTL_ALPHA_DISABLE;
4026 switch (plane_state->base.pixel_blend_mode) {
4027 case DRM_MODE_BLEND_PIXEL_NONE:
4028 return PLANE_CTL_ALPHA_DISABLE;
4029 case DRM_MODE_BLEND_PREMULTI:
4030 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
4031 case DRM_MODE_BLEND_COVERAGE:
4032 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
4034 MISSING_CASE(plane_state->base.pixel_blend_mode);
4035 return PLANE_CTL_ALPHA_DISABLE;
4039 static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
4041 if (!plane_state->base.fb->format->has_alpha)
4042 return PLANE_COLOR_ALPHA_DISABLE;
4044 switch (plane_state->base.pixel_blend_mode) {
4045 case DRM_MODE_BLEND_PIXEL_NONE:
4046 return PLANE_COLOR_ALPHA_DISABLE;
4047 case DRM_MODE_BLEND_PREMULTI:
4048 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
4049 case DRM_MODE_BLEND_COVERAGE:
4050 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
4052 MISSING_CASE(plane_state->base.pixel_blend_mode);
4053 return PLANE_COLOR_ALPHA_DISABLE;
4057 static u32 skl_plane_ctl_tiling(u64 fb_modifier)
4059 switch (fb_modifier) {
4060 case DRM_FORMAT_MOD_LINEAR:
4062 case I915_FORMAT_MOD_X_TILED:
4063 return PLANE_CTL_TILED_X;
4064 case I915_FORMAT_MOD_Y_TILED:
4065 return PLANE_CTL_TILED_Y;
4066 case I915_FORMAT_MOD_Y_TILED_CCS:
4067 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
4068 case I915_FORMAT_MOD_Yf_TILED:
4069 return PLANE_CTL_TILED_YF;
4070 case I915_FORMAT_MOD_Yf_TILED_CCS:
4071 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
4073 MISSING_CASE(fb_modifier);
4079 static u32 skl_plane_ctl_rotate(unsigned int rotate)
4082 case DRM_MODE_ROTATE_0:
4085 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
4086 * while i915 HW rotation is clockwise, thats why this swapping.
4088 case DRM_MODE_ROTATE_90:
4089 return PLANE_CTL_ROTATE_270;
4090 case DRM_MODE_ROTATE_180:
4091 return PLANE_CTL_ROTATE_180;
4092 case DRM_MODE_ROTATE_270:
4093 return PLANE_CTL_ROTATE_90;
4095 MISSING_CASE(rotate);
4101 static u32 cnl_plane_ctl_flip(unsigned int reflect)
4106 case DRM_MODE_REFLECT_X:
4107 return PLANE_CTL_FLIP_HORIZONTAL;
4108 case DRM_MODE_REFLECT_Y:
4110 MISSING_CASE(reflect);
4116 u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
4118 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
4121 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
4124 if (crtc_state->gamma_enable)
4125 plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE;
4127 if (crtc_state->csc_enable)
4128 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
4133 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
4134 const struct intel_plane_state *plane_state)
4136 struct drm_i915_private *dev_priv =
4137 to_i915(plane_state->base.plane->dev);
4138 const struct drm_framebuffer *fb = plane_state->base.fb;
4139 unsigned int rotation = plane_state->base.rotation;
4140 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
4143 plane_ctl = PLANE_CTL_ENABLE;
4145 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
4146 plane_ctl |= skl_plane_ctl_alpha(plane_state);
4147 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
4149 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
4150 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
4152 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
4153 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
4156 plane_ctl |= skl_plane_ctl_format(fb->format->format);
4157 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
4158 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
4160 if (INTEL_GEN(dev_priv) >= 10)
4161 plane_ctl |= cnl_plane_ctl_flip(rotation &
4162 DRM_MODE_REFLECT_MASK);
4164 if (key->flags & I915_SET_COLORKEY_DESTINATION)
4165 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
4166 else if (key->flags & I915_SET_COLORKEY_SOURCE)
4167 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
4172 u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state)
4174 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
4175 u32 plane_color_ctl = 0;
4177 if (INTEL_GEN(dev_priv) >= 11)
4178 return plane_color_ctl;
4180 if (crtc_state->gamma_enable)
4181 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
4183 if (crtc_state->csc_enable)
4184 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
4186 return plane_color_ctl;
4189 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
4190 const struct intel_plane_state *plane_state)
4192 struct drm_i915_private *dev_priv =
4193 to_i915(plane_state->base.plane->dev);
4194 const struct drm_framebuffer *fb = plane_state->base.fb;
4195 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
4196 u32 plane_color_ctl = 0;
4198 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
4199 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
4201 if (fb->format->is_yuv && !icl_is_hdr_plane(dev_priv, plane->id)) {
4202 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
4203 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
4205 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
4207 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
4208 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
4209 } else if (fb->format->is_yuv) {
4210 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
4213 return plane_color_ctl;
4217 __intel_display_resume(struct drm_device *dev,
4218 struct drm_atomic_state *state,
4219 struct drm_modeset_acquire_ctx *ctx)
4221 struct drm_crtc_state *crtc_state;
4222 struct drm_crtc *crtc;
4225 intel_modeset_setup_hw_state(dev, ctx);
4226 i915_redisable_vga(to_i915(dev));
4232 * We've duplicated the state, pointers to the old state are invalid.
4234 * Don't attempt to use the old state until we commit the duplicated state.
4236 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
4238 * Force recalculation even if we restore
4239 * current state. With fast modeset this may not result
4240 * in a modeset when the state is compatible.
4242 crtc_state->mode_changed = true;
4245 /* ignore any reset values/BIOS leftovers in the WM registers */
4246 if (!HAS_GMCH(to_i915(dev)))
4247 to_intel_atomic_state(state)->skip_intermediate_wm = true;
4249 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
4251 WARN_ON(ret == -EDEADLK);
4255 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
4257 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
4258 intel_has_gpu_reset(dev_priv));
4261 void intel_prepare_reset(struct drm_i915_private *dev_priv)
4263 struct drm_device *dev = &dev_priv->drm;
4264 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
4265 struct drm_atomic_state *state;
4268 /* reset doesn't touch the display */
4269 if (!i915_modparams.force_reset_modeset_test &&
4270 !gpu_reset_clobbers_display(dev_priv))
4273 /* We have a modeset vs reset deadlock, defensively unbreak it. */
4274 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
4275 wake_up_all(&dev_priv->gpu_error.wait_queue);
4277 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
4278 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
4279 i915_gem_set_wedged(dev_priv);
4283 * Need mode_config.mutex so that we don't
4284 * trample ongoing ->detect() and whatnot.
4286 mutex_lock(&dev->mode_config.mutex);
4287 drm_modeset_acquire_init(ctx, 0);
4289 ret = drm_modeset_lock_all_ctx(dev, ctx);
4290 if (ret != -EDEADLK)
4293 drm_modeset_backoff(ctx);
4296 * Disabling the crtcs gracefully seems nicer. Also the
4297 * g33 docs say we should at least disable all the planes.
4299 state = drm_atomic_helper_duplicate_state(dev, ctx);
4300 if (IS_ERR(state)) {
4301 ret = PTR_ERR(state);
4302 DRM_ERROR("Duplicating state failed with %i\n", ret);
4306 ret = drm_atomic_helper_disable_all(dev, ctx);
4308 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
4309 drm_atomic_state_put(state);
4313 dev_priv->modeset_restore_state = state;
4314 state->acquire_ctx = ctx;
4317 void intel_finish_reset(struct drm_i915_private *dev_priv)
4319 struct drm_device *dev = &dev_priv->drm;
4320 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
4321 struct drm_atomic_state *state;
4324 /* reset doesn't touch the display */
4325 if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
4328 state = fetch_and_zero(&dev_priv->modeset_restore_state);
4332 /* reset doesn't touch the display */
4333 if (!gpu_reset_clobbers_display(dev_priv)) {
4334 /* for testing only restore the display */
4335 ret = __intel_display_resume(dev, state, ctx);
4337 DRM_ERROR("Restoring old state failed with %i\n", ret);
4340 * The display has been reset as well,
4341 * so need a full re-initialization.
4343 intel_pps_unlock_regs_wa(dev_priv);
4344 intel_modeset_init_hw(dev);
4345 intel_init_clock_gating(dev_priv);
4347 spin_lock_irq(&dev_priv->irq_lock);
4348 if (dev_priv->display.hpd_irq_setup)
4349 dev_priv->display.hpd_irq_setup(dev_priv);
4350 spin_unlock_irq(&dev_priv->irq_lock);
4352 ret = __intel_display_resume(dev, state, ctx);
4354 DRM_ERROR("Restoring old state failed with %i\n", ret);
4356 intel_hpd_init(dev_priv);
4359 drm_atomic_state_put(state);
4361 drm_modeset_drop_locks(ctx);
4362 drm_modeset_acquire_fini(ctx);
4363 mutex_unlock(&dev->mode_config.mutex);
4365 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
4368 static void icl_set_pipe_chicken(struct intel_crtc *crtc)
4370 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4371 enum pipe pipe = crtc->pipe;
4374 tmp = I915_READ(PIPE_CHICKEN(pipe));
4377 * Display WA #1153: icl
4378 * enable hardware to bypass the alpha math
4379 * and rounding for per-pixel values 00 and 0xff
4381 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
4383 * Display WA # 1605353570: icl
4384 * Set the pixel rounding bit to 1 for allowing
4385 * passthrough of Frame buffer pixels unmodified
4388 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
4389 I915_WRITE(PIPE_CHICKEN(pipe), tmp);
4392 static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
4393 const struct intel_crtc_state *new_crtc_state)
4395 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
4396 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4398 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
4399 crtc->base.mode = new_crtc_state->base.mode;
4402 * Update pipe size and adjust fitter if needed: the reason for this is
4403 * that in compute_mode_changes we check the native mode (not the pfit
4404 * mode) to see if we can flip rather than do a full mode set. In the
4405 * fastboot case, we'll flip, but if we don't update the pipesrc and
4406 * pfit state, we'll end up with a big fb scanned out into the wrong
4410 I915_WRITE(PIPESRC(crtc->pipe),
4411 ((new_crtc_state->pipe_src_w - 1) << 16) |
4412 (new_crtc_state->pipe_src_h - 1));
4414 /* on skylake this is done by detaching scalers */
4415 if (INTEL_GEN(dev_priv) >= 9) {
4416 skl_detach_scalers(new_crtc_state);
4418 if (new_crtc_state->pch_pfit.enabled)
4419 skylake_pfit_enable(new_crtc_state);
4420 } else if (HAS_PCH_SPLIT(dev_priv)) {
4421 if (new_crtc_state->pch_pfit.enabled)
4422 ironlake_pfit_enable(new_crtc_state);
4423 else if (old_crtc_state->pch_pfit.enabled)
4424 ironlake_pfit_disable(old_crtc_state);
4427 if (INTEL_GEN(dev_priv) >= 11)
4428 icl_set_pipe_chicken(crtc);
4431 static void intel_fdi_normal_train(struct intel_crtc *crtc)
4433 struct drm_device *dev = crtc->base.dev;
4434 struct drm_i915_private *dev_priv = to_i915(dev);
4435 int pipe = crtc->pipe;
4439 /* enable normal train */
4440 reg = FDI_TX_CTL(pipe);
4441 temp = I915_READ(reg);
4442 if (IS_IVYBRIDGE(dev_priv)) {
4443 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4444 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
4446 temp &= ~FDI_LINK_TRAIN_NONE;
4447 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
4449 I915_WRITE(reg, temp);
4451 reg = FDI_RX_CTL(pipe);
4452 temp = I915_READ(reg);
4453 if (HAS_PCH_CPT(dev_priv)) {
4454 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4455 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
4457 temp &= ~FDI_LINK_TRAIN_NONE;
4458 temp |= FDI_LINK_TRAIN_NONE;
4460 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
4462 /* wait one idle pattern time */
4466 /* IVB wants error correction enabled */
4467 if (IS_IVYBRIDGE(dev_priv))
4468 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
4469 FDI_FE_ERRC_ENABLE);
4472 /* The FDI link training functions for ILK/Ibexpeak. */
4473 static void ironlake_fdi_link_train(struct intel_crtc *crtc,
4474 const struct intel_crtc_state *crtc_state)
4476 struct drm_device *dev = crtc->base.dev;
4477 struct drm_i915_private *dev_priv = to_i915(dev);
4478 int pipe = crtc->pipe;
4482 /* FDI needs bits from pipe first */
4483 assert_pipe_enabled(dev_priv, pipe);
4485 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4487 reg = FDI_RX_IMR(pipe);
4488 temp = I915_READ(reg);
4489 temp &= ~FDI_RX_SYMBOL_LOCK;
4490 temp &= ~FDI_RX_BIT_LOCK;
4491 I915_WRITE(reg, temp);
4495 /* enable CPU FDI TX and PCH FDI RX */
4496 reg = FDI_TX_CTL(pipe);
4497 temp = I915_READ(reg);
4498 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4499 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4500 temp &= ~FDI_LINK_TRAIN_NONE;
4501 temp |= FDI_LINK_TRAIN_PATTERN_1;
4502 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4504 reg = FDI_RX_CTL(pipe);
4505 temp = I915_READ(reg);
4506 temp &= ~FDI_LINK_TRAIN_NONE;
4507 temp |= FDI_LINK_TRAIN_PATTERN_1;
4508 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4513 /* Ironlake workaround, enable clock pointer after FDI enable*/
4514 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4515 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
4516 FDI_RX_PHASE_SYNC_POINTER_EN);
4518 reg = FDI_RX_IIR(pipe);
4519 for (tries = 0; tries < 5; tries++) {
4520 temp = I915_READ(reg);
4521 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4523 if ((temp & FDI_RX_BIT_LOCK)) {
4524 DRM_DEBUG_KMS("FDI train 1 done.\n");
4525 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4530 DRM_ERROR("FDI train 1 fail!\n");
4533 reg = FDI_TX_CTL(pipe);
4534 temp = I915_READ(reg);
4535 temp &= ~FDI_LINK_TRAIN_NONE;
4536 temp |= FDI_LINK_TRAIN_PATTERN_2;
4537 I915_WRITE(reg, temp);
4539 reg = FDI_RX_CTL(pipe);
4540 temp = I915_READ(reg);
4541 temp &= ~FDI_LINK_TRAIN_NONE;
4542 temp |= FDI_LINK_TRAIN_PATTERN_2;
4543 I915_WRITE(reg, temp);
4548 reg = FDI_RX_IIR(pipe);
4549 for (tries = 0; tries < 5; tries++) {
4550 temp = I915_READ(reg);
4551 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4553 if (temp & FDI_RX_SYMBOL_LOCK) {
4554 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4555 DRM_DEBUG_KMS("FDI train 2 done.\n");
4560 DRM_ERROR("FDI train 2 fail!\n");
4562 DRM_DEBUG_KMS("FDI train done\n");
4566 static const int snb_b_fdi_train_param[] = {
4567 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4568 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4569 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4570 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4573 /* The FDI link training functions for SNB/Cougarpoint. */
4574 static void gen6_fdi_link_train(struct intel_crtc *crtc,
4575 const struct intel_crtc_state *crtc_state)
4577 struct drm_device *dev = crtc->base.dev;
4578 struct drm_i915_private *dev_priv = to_i915(dev);
4579 int pipe = crtc->pipe;
4583 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4585 reg = FDI_RX_IMR(pipe);
4586 temp = I915_READ(reg);
4587 temp &= ~FDI_RX_SYMBOL_LOCK;
4588 temp &= ~FDI_RX_BIT_LOCK;
4589 I915_WRITE(reg, temp);
4594 /* enable CPU FDI TX and PCH FDI RX */
4595 reg = FDI_TX_CTL(pipe);
4596 temp = I915_READ(reg);
4597 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4598 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4599 temp &= ~FDI_LINK_TRAIN_NONE;
4600 temp |= FDI_LINK_TRAIN_PATTERN_1;
4601 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4603 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4604 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4606 I915_WRITE(FDI_RX_MISC(pipe),
4607 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4609 reg = FDI_RX_CTL(pipe);
4610 temp = I915_READ(reg);
4611 if (HAS_PCH_CPT(dev_priv)) {
4612 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4613 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4615 temp &= ~FDI_LINK_TRAIN_NONE;
4616 temp |= FDI_LINK_TRAIN_PATTERN_1;
4618 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4623 for (i = 0; i < 4; i++) {
4624 reg = FDI_TX_CTL(pipe);
4625 temp = I915_READ(reg);
4626 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4627 temp |= snb_b_fdi_train_param[i];
4628 I915_WRITE(reg, temp);
4633 for (retry = 0; retry < 5; retry++) {
4634 reg = FDI_RX_IIR(pipe);
4635 temp = I915_READ(reg);
4636 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4637 if (temp & FDI_RX_BIT_LOCK) {
4638 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4639 DRM_DEBUG_KMS("FDI train 1 done.\n");
4648 DRM_ERROR("FDI train 1 fail!\n");
4651 reg = FDI_TX_CTL(pipe);
4652 temp = I915_READ(reg);
4653 temp &= ~FDI_LINK_TRAIN_NONE;
4654 temp |= FDI_LINK_TRAIN_PATTERN_2;
4655 if (IS_GEN(dev_priv, 6)) {
4656 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4658 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4660 I915_WRITE(reg, temp);
4662 reg = FDI_RX_CTL(pipe);
4663 temp = I915_READ(reg);
4664 if (HAS_PCH_CPT(dev_priv)) {
4665 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4666 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4668 temp &= ~FDI_LINK_TRAIN_NONE;
4669 temp |= FDI_LINK_TRAIN_PATTERN_2;
4671 I915_WRITE(reg, temp);
4676 for (i = 0; i < 4; i++) {
4677 reg = FDI_TX_CTL(pipe);
4678 temp = I915_READ(reg);
4679 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4680 temp |= snb_b_fdi_train_param[i];
4681 I915_WRITE(reg, temp);
4686 for (retry = 0; retry < 5; retry++) {
4687 reg = FDI_RX_IIR(pipe);
4688 temp = I915_READ(reg);
4689 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4690 if (temp & FDI_RX_SYMBOL_LOCK) {
4691 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4692 DRM_DEBUG_KMS("FDI train 2 done.\n");
4701 DRM_ERROR("FDI train 2 fail!\n");
4703 DRM_DEBUG_KMS("FDI train done.\n");
4706 /* Manual link training for Ivy Bridge A0 parts */
4707 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4708 const struct intel_crtc_state *crtc_state)
4710 struct drm_device *dev = crtc->base.dev;
4711 struct drm_i915_private *dev_priv = to_i915(dev);
4712 int pipe = crtc->pipe;
4716 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4718 reg = FDI_RX_IMR(pipe);
4719 temp = I915_READ(reg);
4720 temp &= ~FDI_RX_SYMBOL_LOCK;
4721 temp &= ~FDI_RX_BIT_LOCK;
4722 I915_WRITE(reg, temp);
4727 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4728 I915_READ(FDI_RX_IIR(pipe)));
4730 /* Try each vswing and preemphasis setting twice before moving on */
4731 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4732 /* disable first in case we need to retry */
4733 reg = FDI_TX_CTL(pipe);
4734 temp = I915_READ(reg);
4735 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4736 temp &= ~FDI_TX_ENABLE;
4737 I915_WRITE(reg, temp);
4739 reg = FDI_RX_CTL(pipe);
4740 temp = I915_READ(reg);
4741 temp &= ~FDI_LINK_TRAIN_AUTO;
4742 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4743 temp &= ~FDI_RX_ENABLE;
4744 I915_WRITE(reg, temp);
4746 /* enable CPU FDI TX and PCH FDI RX */
4747 reg = FDI_TX_CTL(pipe);
4748 temp = I915_READ(reg);
4749 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4750 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4751 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
4752 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4753 temp |= snb_b_fdi_train_param[j/2];
4754 temp |= FDI_COMPOSITE_SYNC;
4755 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4757 I915_WRITE(FDI_RX_MISC(pipe),
4758 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4760 reg = FDI_RX_CTL(pipe);
4761 temp = I915_READ(reg);
4762 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4763 temp |= FDI_COMPOSITE_SYNC;
4764 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4767 udelay(1); /* should be 0.5us */
4769 for (i = 0; i < 4; i++) {
4770 reg = FDI_RX_IIR(pipe);
4771 temp = I915_READ(reg);
4772 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4774 if (temp & FDI_RX_BIT_LOCK ||
4775 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4776 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4777 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4781 udelay(1); /* should be 0.5us */
4784 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4789 reg = FDI_TX_CTL(pipe);
4790 temp = I915_READ(reg);
4791 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4792 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4793 I915_WRITE(reg, temp);
4795 reg = FDI_RX_CTL(pipe);
4796 temp = I915_READ(reg);
4797 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4798 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4799 I915_WRITE(reg, temp);
4802 udelay(2); /* should be 1.5us */
4804 for (i = 0; i < 4; i++) {
4805 reg = FDI_RX_IIR(pipe);
4806 temp = I915_READ(reg);
4807 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4809 if (temp & FDI_RX_SYMBOL_LOCK ||
4810 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4811 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4812 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4816 udelay(2); /* should be 1.5us */
4819 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
4823 DRM_DEBUG_KMS("FDI train done.\n");
4826 static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
4828 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4829 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4830 int pipe = intel_crtc->pipe;
4834 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4835 reg = FDI_RX_CTL(pipe);
4836 temp = I915_READ(reg);
4837 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
4838 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4839 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4840 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4845 /* Switch from Rawclk to PCDclk */
4846 temp = I915_READ(reg);
4847 I915_WRITE(reg, temp | FDI_PCDCLK);
4852 /* Enable CPU FDI TX PLL, always on for Ironlake */
4853 reg = FDI_TX_CTL(pipe);
4854 temp = I915_READ(reg);
4855 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4856 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
4863 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4865 struct drm_device *dev = intel_crtc->base.dev;
4866 struct drm_i915_private *dev_priv = to_i915(dev);
4867 int pipe = intel_crtc->pipe;
4871 /* Switch from PCDclk to Rawclk */
4872 reg = FDI_RX_CTL(pipe);
4873 temp = I915_READ(reg);
4874 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4876 /* Disable CPU FDI TX PLL */
4877 reg = FDI_TX_CTL(pipe);
4878 temp = I915_READ(reg);
4879 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4884 reg = FDI_RX_CTL(pipe);
4885 temp = I915_READ(reg);
4886 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4888 /* Wait for the clocks to turn off. */
4893 static void ironlake_fdi_disable(struct drm_crtc *crtc)
4895 struct drm_device *dev = crtc->dev;
4896 struct drm_i915_private *dev_priv = to_i915(dev);
4897 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4898 int pipe = intel_crtc->pipe;
4902 /* disable CPU FDI tx and PCH FDI rx */
4903 reg = FDI_TX_CTL(pipe);
4904 temp = I915_READ(reg);
4905 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4908 reg = FDI_RX_CTL(pipe);
4909 temp = I915_READ(reg);
4910 temp &= ~(0x7 << 16);
4911 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4912 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4917 /* Ironlake workaround, disable clock pointer after downing FDI */
4918 if (HAS_PCH_IBX(dev_priv))
4919 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4921 /* still set train pattern 1 */
4922 reg = FDI_TX_CTL(pipe);
4923 temp = I915_READ(reg);
4924 temp &= ~FDI_LINK_TRAIN_NONE;
4925 temp |= FDI_LINK_TRAIN_PATTERN_1;
4926 I915_WRITE(reg, temp);
4928 reg = FDI_RX_CTL(pipe);
4929 temp = I915_READ(reg);
4930 if (HAS_PCH_CPT(dev_priv)) {
4931 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4932 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4934 temp &= ~FDI_LINK_TRAIN_NONE;
4935 temp |= FDI_LINK_TRAIN_PATTERN_1;
4937 /* BPC in FDI rx is consistent with that in PIPECONF */
4938 temp &= ~(0x07 << 16);
4939 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4940 I915_WRITE(reg, temp);
4946 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
4948 struct drm_crtc *crtc;
4951 drm_for_each_crtc(crtc, &dev_priv->drm) {
4952 struct drm_crtc_commit *commit;
4953 spin_lock(&crtc->commit_lock);
4954 commit = list_first_entry_or_null(&crtc->commit_list,
4955 struct drm_crtc_commit, commit_entry);
4956 cleanup_done = commit ?
4957 try_wait_for_completion(&commit->cleanup_done) : true;
4958 spin_unlock(&crtc->commit_lock);
4963 drm_crtc_wait_one_vblank(crtc);
4971 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
4975 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4977 mutex_lock(&dev_priv->sb_lock);
4979 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4980 temp |= SBI_SSCCTL_DISABLE;
4981 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4983 mutex_unlock(&dev_priv->sb_lock);
4986 /* Program iCLKIP clock to the desired frequency */
4987 static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
4989 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4990 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4991 int clock = crtc_state->base.adjusted_mode.crtc_clock;
4992 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4995 lpt_disable_iclkip(dev_priv);
4997 /* The iCLK virtual clock root frequency is in MHz,
4998 * but the adjusted_mode->crtc_clock in in KHz. To get the
4999 * divisors, it is necessary to divide one by another, so we
5000 * convert the virtual clock precision to KHz here for higher
5003 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
5004 u32 iclk_virtual_root_freq = 172800 * 1000;
5005 u32 iclk_pi_range = 64;
5006 u32 desired_divisor;
5008 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5010 divsel = (desired_divisor / iclk_pi_range) - 2;
5011 phaseinc = desired_divisor % iclk_pi_range;
5014 * Near 20MHz is a corner case which is
5015 * out of range for the 7-bit divisor
5021 /* This should not happen with any sane values */
5022 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
5023 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
5024 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
5025 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
5027 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
5034 mutex_lock(&dev_priv->sb_lock);
5036 /* Program SSCDIVINTPHASE6 */
5037 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5038 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
5039 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
5040 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
5041 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
5042 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
5043 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
5044 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
5046 /* Program SSCAUXDIV */
5047 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5048 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
5049 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
5050 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
5052 /* Enable modulator and associated divider */
5053 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5054 temp &= ~SBI_SSCCTL_DISABLE;
5055 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
5057 mutex_unlock(&dev_priv->sb_lock);
5059 /* Wait for initialization time */
5062 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
5065 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
5067 u32 divsel, phaseinc, auxdiv;
5068 u32 iclk_virtual_root_freq = 172800 * 1000;
5069 u32 iclk_pi_range = 64;
5070 u32 desired_divisor;
5073 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
5076 mutex_lock(&dev_priv->sb_lock);
5078 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5079 if (temp & SBI_SSCCTL_DISABLE) {
5080 mutex_unlock(&dev_priv->sb_lock);
5084 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5085 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
5086 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
5087 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
5088 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
5090 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5091 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
5092 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
5094 mutex_unlock(&dev_priv->sb_lock);
5096 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
5098 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5099 desired_divisor << auxdiv);
5102 static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
5103 enum pipe pch_transcoder)
5105 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5106 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5107 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5109 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
5110 I915_READ(HTOTAL(cpu_transcoder)));
5111 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
5112 I915_READ(HBLANK(cpu_transcoder)));
5113 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
5114 I915_READ(HSYNC(cpu_transcoder)));
5116 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
5117 I915_READ(VTOTAL(cpu_transcoder)));
5118 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
5119 I915_READ(VBLANK(cpu_transcoder)));
5120 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
5121 I915_READ(VSYNC(cpu_transcoder)));
5122 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
5123 I915_READ(VSYNCSHIFT(cpu_transcoder)));
5126 static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
5130 temp = I915_READ(SOUTH_CHICKEN1);
5131 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
5134 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
5135 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
5137 temp &= ~FDI_BC_BIFURCATION_SELECT;
5139 temp |= FDI_BC_BIFURCATION_SELECT;
5141 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
5142 I915_WRITE(SOUTH_CHICKEN1, temp);
5143 POSTING_READ(SOUTH_CHICKEN1);
5146 static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
5148 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5149 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5151 switch (crtc->pipe) {
5155 if (crtc_state->fdi_lanes > 2)
5156 cpt_set_fdi_bc_bifurcation(dev_priv, false);
5158 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5162 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5171 * Finds the encoder associated with the given CRTC. This can only be
5172 * used when we know that the CRTC isn't feeding multiple encoders!
5174 static struct intel_encoder *
5175 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
5176 const struct intel_crtc_state *crtc_state)
5178 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5179 const struct drm_connector_state *connector_state;
5180 const struct drm_connector *connector;
5181 struct intel_encoder *encoder = NULL;
5182 int num_encoders = 0;
5185 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
5186 if (connector_state->crtc != &crtc->base)
5189 encoder = to_intel_encoder(connector_state->best_encoder);
5193 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
5194 num_encoders, pipe_name(crtc->pipe));
5200 * Enable PCH resources required for PCH ports:
5202 * - FDI training & RX/TX
5203 * - update transcoder timings
5204 * - DP transcoding bits
5207 static void ironlake_pch_enable(const struct intel_atomic_state *state,
5208 const struct intel_crtc_state *crtc_state)
5210 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5211 struct drm_device *dev = crtc->base.dev;
5212 struct drm_i915_private *dev_priv = to_i915(dev);
5213 int pipe = crtc->pipe;
5216 assert_pch_transcoder_disabled(dev_priv, pipe);
5218 if (IS_IVYBRIDGE(dev_priv))
5219 ivybridge_update_fdi_bc_bifurcation(crtc_state);
5221 /* Write the TU size bits before fdi link training, so that error
5222 * detection works. */
5223 I915_WRITE(FDI_RX_TUSIZE1(pipe),
5224 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
5226 /* For PCH output, training FDI link */
5227 dev_priv->display.fdi_link_train(crtc, crtc_state);
5229 /* We need to program the right clock selection before writing the pixel
5230 * mutliplier into the DPLL. */
5231 if (HAS_PCH_CPT(dev_priv)) {
5234 temp = I915_READ(PCH_DPLL_SEL);
5235 temp |= TRANS_DPLL_ENABLE(pipe);
5236 sel = TRANS_DPLLB_SEL(pipe);
5237 if (crtc_state->shared_dpll ==
5238 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
5242 I915_WRITE(PCH_DPLL_SEL, temp);
5245 /* XXX: pch pll's can be enabled any time before we enable the PCH
5246 * transcoder, and we actually should do this to not upset any PCH
5247 * transcoder that already use the clock when we share it.
5249 * Note that enable_shared_dpll tries to do the right thing, but
5250 * get_shared_dpll unconditionally resets the pll - we need that to have
5251 * the right LVDS enable sequence. */
5252 intel_enable_shared_dpll(crtc_state);
5254 /* set transcoder timing, panel must allow it */
5255 assert_panel_unlocked(dev_priv, pipe);
5256 ironlake_pch_transcoder_set_timings(crtc_state, pipe);
5258 intel_fdi_normal_train(crtc);
5260 /* For PCH DP, enable TRANS_DP_CTL */
5261 if (HAS_PCH_CPT(dev_priv) &&
5262 intel_crtc_has_dp_encoder(crtc_state)) {
5263 const struct drm_display_mode *adjusted_mode =
5264 &crtc_state->base.adjusted_mode;
5265 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
5266 i915_reg_t reg = TRANS_DP_CTL(pipe);
5269 temp = I915_READ(reg);
5270 temp &= ~(TRANS_DP_PORT_SEL_MASK |
5271 TRANS_DP_SYNC_MASK |
5273 temp |= TRANS_DP_OUTPUT_ENABLE;
5274 temp |= bpc << 9; /* same format but at 11:9 */
5276 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
5277 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
5278 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
5279 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
5281 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
5282 WARN_ON(port < PORT_B || port > PORT_D);
5283 temp |= TRANS_DP_PORT_SEL(port);
5285 I915_WRITE(reg, temp);
5288 ironlake_enable_pch_transcoder(crtc_state);
5291 static void lpt_pch_enable(const struct intel_atomic_state *state,
5292 const struct intel_crtc_state *crtc_state)
5294 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5295 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5296 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5298 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
5300 lpt_program_iclkip(crtc_state);
5302 /* Set transcoder timing. */
5303 ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A);
5305 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
5308 static void cpt_verify_modeset(struct drm_device *dev, int pipe)
5310 struct drm_i915_private *dev_priv = to_i915(dev);
5311 i915_reg_t dslreg = PIPEDSL(pipe);
5314 temp = I915_READ(dslreg);
5316 if (wait_for(I915_READ(dslreg) != temp, 5)) {
5317 if (wait_for(I915_READ(dslreg) != temp, 5))
5318 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
5323 * The hardware phase 0.0 refers to the center of the pixel.
5324 * We want to start from the top/left edge which is phase
5325 * -0.5. That matches how the hardware calculates the scaling
5326 * factors (from top-left of the first pixel to bottom-right
5327 * of the last pixel, as opposed to the pixel centers).
5329 * For 4:2:0 subsampled chroma planes we obviously have to
5330 * adjust that so that the chroma sample position lands in
5333 * Note that for packed YCbCr 4:2:2 formats there is no way to
5334 * control chroma siting. The hardware simply replicates the
5335 * chroma samples for both of the luma samples, and thus we don't
5336 * actually get the expected MPEG2 chroma siting convention :(
5337 * The same behaviour is observed on pre-SKL platforms as well.
5339 * Theory behind the formula (note that we ignore sub-pixel
5340 * source coordinates):
5341 * s = source sample position
5342 * d = destination sample position
5347 * | | 1.5 (initial phase)
5355 * | -0.375 (initial phase)
5362 u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
5364 int phase = -0x8000;
5368 phase += (sub - 1) * 0x8000 / sub;
5370 phase += scale / (2 * sub);
5373 * Hardware initial phase limited to [-0.5:1.5].
5374 * Since the max hardware scale factor is 3.0, we
5375 * should never actually excdeed 1.0 here.
5377 WARN_ON(phase < -0x8000 || phase > 0x18000);
5380 phase = 0x10000 + phase;
5382 trip = PS_PHASE_TRIP;
5384 return ((phase >> 2) & PS_PHASE_MASK) | trip;
5387 #define SKL_MIN_SRC_W 8
5388 #define SKL_MAX_SRC_W 4096
5389 #define SKL_MIN_SRC_H 8
5390 #define SKL_MAX_SRC_H 4096
5391 #define SKL_MIN_DST_W 8
5392 #define SKL_MAX_DST_W 4096
5393 #define SKL_MIN_DST_H 8
5394 #define SKL_MAX_DST_H 4096
5395 #define ICL_MAX_SRC_W 5120
5396 #define ICL_MAX_SRC_H 4096
5397 #define ICL_MAX_DST_W 5120
5398 #define ICL_MAX_DST_H 4096
5399 #define SKL_MIN_YUV_420_SRC_W 16
5400 #define SKL_MIN_YUV_420_SRC_H 16
5403 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
5404 unsigned int scaler_user, int *scaler_id,
5405 int src_w, int src_h, int dst_w, int dst_h,
5406 const struct drm_format_info *format, bool need_scaler)
5408 struct intel_crtc_scaler_state *scaler_state =
5409 &crtc_state->scaler_state;
5410 struct intel_crtc *intel_crtc =
5411 to_intel_crtc(crtc_state->base.crtc);
5412 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
5413 const struct drm_display_mode *adjusted_mode =
5414 &crtc_state->base.adjusted_mode;
5417 * Src coordinates are already rotated by 270 degrees for
5418 * the 90/270 degree plane rotation cases (to match the
5419 * GTT mapping), hence no need to account for rotation here.
5421 if (src_w != dst_w || src_h != dst_h)
5425 * Scaling/fitting not supported in IF-ID mode in GEN9+
5426 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
5427 * Once NV12 is enabled, handle it here while allocating scaler
5430 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
5431 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
5432 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
5437 * if plane is being disabled or scaler is no more required or force detach
5438 * - free scaler binded to this plane/crtc
5439 * - in order to do this, update crtc->scaler_usage
5441 * Here scaler state in crtc_state is set free so that
5442 * scaler can be assigned to other user. Actual register
5443 * update to free the scaler is done in plane/panel-fit programming.
5444 * For this purpose crtc/plane_state->scaler_id isn't reset here.
5446 if (force_detach || !need_scaler) {
5447 if (*scaler_id >= 0) {
5448 scaler_state->scaler_users &= ~(1 << scaler_user);
5449 scaler_state->scalers[*scaler_id].in_use = 0;
5451 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5452 "Staged freeing scaler id %d scaler_users = 0x%x\n",
5453 intel_crtc->pipe, scaler_user, *scaler_id,
5454 scaler_state->scaler_users);
5460 if (format && is_planar_yuv_format(format->format) &&
5461 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
5462 DRM_DEBUG_KMS("Planar YUV: src dimensions not met\n");
5467 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
5468 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
5469 (INTEL_GEN(dev_priv) >= 11 &&
5470 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
5471 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
5472 (INTEL_GEN(dev_priv) < 11 &&
5473 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
5474 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
5475 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
5476 "size is out of scaler range\n",
5477 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
5481 /* mark this plane as a scaler user in crtc_state */
5482 scaler_state->scaler_users |= (1 << scaler_user);
5483 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5484 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
5485 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
5486 scaler_state->scaler_users);
5492 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
5494 * @state: crtc's scaler state
5497 * 0 - scaler_usage updated successfully
5498 * error - requested scaling cannot be supported or other error condition
5500 int skl_update_scaler_crtc(struct intel_crtc_state *state)
5502 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
5503 bool need_scaler = false;
5505 if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
5508 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
5509 &state->scaler_state.scaler_id,
5510 state->pipe_src_w, state->pipe_src_h,
5511 adjusted_mode->crtc_hdisplay,
5512 adjusted_mode->crtc_vdisplay, NULL, need_scaler);
5516 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
5517 * @crtc_state: crtc's scaler state
5518 * @plane_state: atomic plane state to update
5521 * 0 - scaler_usage updated successfully
5522 * error - requested scaling cannot be supported or other error condition
5524 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
5525 struct intel_plane_state *plane_state)
5527 struct intel_plane *intel_plane =
5528 to_intel_plane(plane_state->base.plane);
5529 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
5530 struct drm_framebuffer *fb = plane_state->base.fb;
5532 bool force_detach = !fb || !plane_state->base.visible;
5533 bool need_scaler = false;
5535 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
5536 if (!icl_is_hdr_plane(dev_priv, intel_plane->id) &&
5537 fb && is_planar_yuv_format(fb->format->format))
5540 ret = skl_update_scaler(crtc_state, force_detach,
5541 drm_plane_index(&intel_plane->base),
5542 &plane_state->scaler_id,
5543 drm_rect_width(&plane_state->base.src) >> 16,
5544 drm_rect_height(&plane_state->base.src) >> 16,
5545 drm_rect_width(&plane_state->base.dst),
5546 drm_rect_height(&plane_state->base.dst),
5547 fb ? fb->format : NULL, need_scaler);
5549 if (ret || plane_state->scaler_id < 0)
5552 /* check colorkey */
5553 if (plane_state->ckey.flags) {
5554 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
5555 intel_plane->base.base.id,
5556 intel_plane->base.name);
5560 /* Check src format */
5561 switch (fb->format->format) {
5562 case DRM_FORMAT_RGB565:
5563 case DRM_FORMAT_XBGR8888:
5564 case DRM_FORMAT_XRGB8888:
5565 case DRM_FORMAT_ABGR8888:
5566 case DRM_FORMAT_ARGB8888:
5567 case DRM_FORMAT_XRGB2101010:
5568 case DRM_FORMAT_XBGR2101010:
5569 case DRM_FORMAT_XBGR16161616F:
5570 case DRM_FORMAT_ABGR16161616F:
5571 case DRM_FORMAT_XRGB16161616F:
5572 case DRM_FORMAT_ARGB16161616F:
5573 case DRM_FORMAT_YUYV:
5574 case DRM_FORMAT_YVYU:
5575 case DRM_FORMAT_UYVY:
5576 case DRM_FORMAT_VYUY:
5577 case DRM_FORMAT_NV12:
5578 case DRM_FORMAT_P010:
5579 case DRM_FORMAT_P012:
5580 case DRM_FORMAT_P016:
5581 case DRM_FORMAT_Y210:
5582 case DRM_FORMAT_Y212:
5583 case DRM_FORMAT_Y216:
5584 case DRM_FORMAT_XVYU2101010:
5585 case DRM_FORMAT_XVYU12_16161616:
5586 case DRM_FORMAT_XVYU16161616:
5589 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
5590 intel_plane->base.base.id, intel_plane->base.name,
5591 fb->base.id, fb->format->format);
5598 static void skylake_scaler_disable(struct intel_crtc *crtc)
5602 for (i = 0; i < crtc->num_scalers; i++)
5603 skl_detach_scaler(crtc, i);
5606 static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
5608 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5609 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5610 enum pipe pipe = crtc->pipe;
5611 const struct intel_crtc_scaler_state *scaler_state =
5612 &crtc_state->scaler_state;
5614 if (crtc_state->pch_pfit.enabled) {
5615 u16 uv_rgb_hphase, uv_rgb_vphase;
5616 int pfit_w, pfit_h, hscale, vscale;
5619 if (WARN_ON(crtc_state->scaler_state.scaler_id < 0))
5622 pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF;
5623 pfit_h = crtc_state->pch_pfit.size & 0xFFFF;
5625 hscale = (crtc_state->pipe_src_w << 16) / pfit_w;
5626 vscale = (crtc_state->pipe_src_h << 16) / pfit_h;
5628 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
5629 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
5631 id = scaler_state->scaler_id;
5632 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
5633 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
5634 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
5635 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5636 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
5637 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
5638 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos);
5639 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size);
5643 static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state)
5645 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5646 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5647 int pipe = crtc->pipe;
5649 if (crtc_state->pch_pfit.enabled) {
5650 /* Force use of hard-coded filter coefficients
5651 * as some pre-programmed values are broken,
5654 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
5655 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5656 PF_PIPE_SEL_IVB(pipe));
5658 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
5659 I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos);
5660 I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size);
5664 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
5666 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5667 struct drm_device *dev = crtc->base.dev;
5668 struct drm_i915_private *dev_priv = to_i915(dev);
5670 if (!crtc_state->ips_enabled)
5674 * We can only enable IPS after we enable a plane and wait for a vblank
5675 * This function is called from post_plane_update, which is run after
5678 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
5680 if (IS_BROADWELL(dev_priv)) {
5681 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5682 IPS_ENABLE | IPS_PCODE_CONTROL));
5683 /* Quoting Art Runyan: "its not safe to expect any particular
5684 * value in IPS_CTL bit 31 after enabling IPS through the
5685 * mailbox." Moreover, the mailbox may return a bogus state,
5686 * so we need to just enable it and continue on.
5689 I915_WRITE(IPS_CTL, IPS_ENABLE);
5690 /* The bit only becomes 1 in the next vblank, so this wait here
5691 * is essentially intel_wait_for_vblank. If we don't have this
5692 * and don't wait for vblanks until the end of crtc_enable, then
5693 * the HW state readout code will complain that the expected
5694 * IPS_CTL value is not the one we read. */
5695 if (intel_wait_for_register(&dev_priv->uncore,
5696 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
5698 DRM_ERROR("Timed out waiting for IPS enable\n");
5702 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
5704 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5705 struct drm_device *dev = crtc->base.dev;
5706 struct drm_i915_private *dev_priv = to_i915(dev);
5708 if (!crtc_state->ips_enabled)
5711 if (IS_BROADWELL(dev_priv)) {
5712 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
5714 * Wait for PCODE to finish disabling IPS. The BSpec specified
5715 * 42ms timeout value leads to occasional timeouts so use 100ms
5718 if (intel_wait_for_register(&dev_priv->uncore,
5719 IPS_CTL, IPS_ENABLE, 0,
5721 DRM_ERROR("Timed out waiting for IPS disable\n");
5723 I915_WRITE(IPS_CTL, 0);
5724 POSTING_READ(IPS_CTL);
5727 /* We need to wait for a vblank before we can disable the plane. */
5728 intel_wait_for_vblank(dev_priv, crtc->pipe);
5731 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
5733 if (intel_crtc->overlay) {
5734 struct drm_device *dev = intel_crtc->base.dev;
5736 mutex_lock(&dev->struct_mutex);
5737 (void) intel_overlay_switch_off(intel_crtc->overlay);
5738 mutex_unlock(&dev->struct_mutex);
5741 /* Let userspace switch the overlay on again. In most cases userspace
5742 * has to recompute where to put it anyway.
5747 * intel_post_enable_primary - Perform operations after enabling primary plane
5748 * @crtc: the CRTC whose primary plane was just enabled
5749 * @new_crtc_state: the enabling state
5751 * Performs potentially sleeping operations that must be done after the primary
5752 * plane is enabled, such as updating FBC and IPS. Note that this may be
5753 * called due to an explicit primary plane update, or due to an implicit
5754 * re-enable that is caused when a sprite plane is updated to no longer
5755 * completely hide the primary plane.
5758 intel_post_enable_primary(struct drm_crtc *crtc,
5759 const struct intel_crtc_state *new_crtc_state)
5761 struct drm_device *dev = crtc->dev;
5762 struct drm_i915_private *dev_priv = to_i915(dev);
5763 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5764 int pipe = intel_crtc->pipe;
5767 * Gen2 reports pipe underruns whenever all planes are disabled.
5768 * So don't enable underrun reporting before at least some planes
5770 * FIXME: Need to fix the logic to work when we turn off all planes
5771 * but leave the pipe running.
5773 if (IS_GEN(dev_priv, 2))
5774 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5776 /* Underruns don't always raise interrupts, so check manually. */
5777 intel_check_cpu_fifo_underruns(dev_priv);
5778 intel_check_pch_fifo_underruns(dev_priv);
5781 /* FIXME get rid of this and use pre_plane_update */
5783 intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5785 struct drm_device *dev = crtc->dev;
5786 struct drm_i915_private *dev_priv = to_i915(dev);
5787 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5788 int pipe = intel_crtc->pipe;
5791 * Gen2 reports pipe underruns whenever all planes are disabled.
5792 * So disable underrun reporting before all the planes get disabled.
5794 if (IS_GEN(dev_priv, 2))
5795 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5797 hsw_disable_ips(to_intel_crtc_state(crtc->state));
5800 * Vblank time updates from the shadow to live plane control register
5801 * are blocked if the memory self-refresh mode is active at that
5802 * moment. So to make sure the plane gets truly disabled, disable
5803 * first the self-refresh mode. The self-refresh enable bit in turn
5804 * will be checked/applied by the HW only at the next frame start
5805 * event which is after the vblank start event, so we need to have a
5806 * wait-for-vblank between disabling the plane and the pipe.
5808 if (HAS_GMCH(dev_priv) &&
5809 intel_set_memory_cxsr(dev_priv, false))
5810 intel_wait_for_vblank(dev_priv, pipe);
5813 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5814 const struct intel_crtc_state *new_crtc_state)
5816 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
5817 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5819 if (!old_crtc_state->ips_enabled)
5822 if (needs_modeset(new_crtc_state))
5826 * Workaround : Do not read or write the pipe palette/gamma data while
5827 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
5829 * Disable IPS before we program the LUT.
5831 if (IS_HASWELL(dev_priv) &&
5832 (new_crtc_state->base.color_mgmt_changed ||
5833 new_crtc_state->update_pipe) &&
5834 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
5837 return !new_crtc_state->ips_enabled;
5840 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5841 const struct intel_crtc_state *new_crtc_state)
5843 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
5844 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5846 if (!new_crtc_state->ips_enabled)
5849 if (needs_modeset(new_crtc_state))
5853 * Workaround : Do not read or write the pipe palette/gamma data while
5854 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
5856 * Re-enable IPS after the LUT has been programmed.
5858 if (IS_HASWELL(dev_priv) &&
5859 (new_crtc_state->base.color_mgmt_changed ||
5860 new_crtc_state->update_pipe) &&
5861 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
5865 * We can't read out IPS on broadwell, assume the worst and
5866 * forcibly enable IPS on the first fastset.
5868 if (new_crtc_state->update_pipe &&
5869 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5872 return !old_crtc_state->ips_enabled;
5875 static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5876 const struct intel_crtc_state *crtc_state)
5878 if (!crtc_state->nv12_planes)
5881 /* WA Display #0827: Gen9:all */
5882 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv))
5888 static bool needs_scalerclk_wa(struct drm_i915_private *dev_priv,
5889 const struct intel_crtc_state *crtc_state)
5891 /* Wa_2006604312:icl */
5892 if (crtc_state->scaler_state.scaler_users > 0 && IS_ICELAKE(dev_priv))
5898 static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5900 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5901 struct drm_device *dev = crtc->base.dev;
5902 struct drm_i915_private *dev_priv = to_i915(dev);
5903 struct drm_atomic_state *state = old_crtc_state->base.state;
5904 struct intel_crtc_state *pipe_config =
5905 intel_atomic_get_new_crtc_state(to_intel_atomic_state(state),
5907 struct drm_plane *primary = crtc->base.primary;
5908 struct drm_plane_state *old_primary_state =
5909 drm_atomic_get_old_plane_state(state, primary);
5911 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
5913 if (pipe_config->update_wm_post && pipe_config->base.active)
5914 intel_update_watermarks(crtc);
5916 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5917 hsw_enable_ips(pipe_config);
5919 if (old_primary_state) {
5920 struct drm_plane_state *new_primary_state =
5921 drm_atomic_get_new_plane_state(state, primary);
5923 intel_fbc_post_update(crtc);
5925 if (new_primary_state->visible &&
5926 (needs_modeset(pipe_config) ||
5927 !old_primary_state->visible))
5928 intel_post_enable_primary(&crtc->base, pipe_config);
5931 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
5932 !needs_nv12_wa(dev_priv, pipe_config))
5933 skl_wa_827(dev_priv, crtc->pipe, false);
5935 if (needs_scalerclk_wa(dev_priv, old_crtc_state) &&
5936 !needs_scalerclk_wa(dev_priv, pipe_config))
5937 icl_wa_scalerclkgating(dev_priv, crtc->pipe, false);
5940 static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5941 struct intel_crtc_state *pipe_config)
5943 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5944 struct drm_device *dev = crtc->base.dev;
5945 struct drm_i915_private *dev_priv = to_i915(dev);
5946 struct drm_atomic_state *state = old_crtc_state->base.state;
5947 struct drm_plane *primary = crtc->base.primary;
5948 struct drm_plane_state *old_primary_state =
5949 drm_atomic_get_old_plane_state(state, primary);
5950 bool modeset = needs_modeset(pipe_config);
5951 struct intel_atomic_state *intel_state =
5952 to_intel_atomic_state(state);
5954 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5955 hsw_disable_ips(old_crtc_state);
5957 if (old_primary_state) {
5958 struct intel_plane_state *new_primary_state =
5959 intel_atomic_get_new_plane_state(intel_state,
5960 to_intel_plane(primary));
5962 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
5964 * Gen2 reports pipe underruns whenever all planes are disabled.
5965 * So disable underrun reporting before all the planes get disabled.
5967 if (IS_GEN(dev_priv, 2) && old_primary_state->visible &&
5968 (modeset || !new_primary_state->base.visible))
5969 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
5972 /* Display WA 827 */
5973 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
5974 needs_nv12_wa(dev_priv, pipe_config))
5975 skl_wa_827(dev_priv, crtc->pipe, true);
5977 /* Wa_2006604312:icl */
5978 if (!needs_scalerclk_wa(dev_priv, old_crtc_state) &&
5979 needs_scalerclk_wa(dev_priv, pipe_config))
5980 icl_wa_scalerclkgating(dev_priv, crtc->pipe, true);
5983 * Vblank time updates from the shadow to live plane control register
5984 * are blocked if the memory self-refresh mode is active at that
5985 * moment. So to make sure the plane gets truly disabled, disable
5986 * first the self-refresh mode. The self-refresh enable bit in turn
5987 * will be checked/applied by the HW only at the next frame start
5988 * event which is after the vblank start event, so we need to have a
5989 * wait-for-vblank between disabling the plane and the pipe.
5991 if (HAS_GMCH(dev_priv) && old_crtc_state->base.active &&
5992 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5993 intel_wait_for_vblank(dev_priv, crtc->pipe);
5996 * IVB workaround: must disable low power watermarks for at least
5997 * one frame before enabling scaling. LP watermarks can be re-enabled
5998 * when scaling is disabled.
6000 * WaCxSRDisabledForSpriteScaling:ivb
6002 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) &&
6003 old_crtc_state->base.active)
6004 intel_wait_for_vblank(dev_priv, crtc->pipe);
6007 * If we're doing a modeset, we're done. No need to do any pre-vblank
6008 * watermark programming here.
6010 if (needs_modeset(pipe_config))
6014 * For platforms that support atomic watermarks, program the
6015 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
6016 * will be the intermediate values that are safe for both pre- and
6017 * post- vblank; when vblank happens, the 'active' values will be set
6018 * to the final 'target' values and we'll do this again to get the
6019 * optimal watermarks. For gen9+ platforms, the values we program here
6020 * will be the final target values which will get automatically latched
6021 * at vblank time; no further programming will be necessary.
6023 * If a platform hasn't been transitioned to atomic watermarks yet,
6024 * we'll continue to update watermarks the old way, if flags tell
6027 if (dev_priv->display.initial_watermarks != NULL)
6028 dev_priv->display.initial_watermarks(intel_state,
6030 else if (pipe_config->update_wm_pre)
6031 intel_update_watermarks(crtc);
6034 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
6035 struct intel_crtc *crtc)
6037 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6038 const struct intel_crtc_state *new_crtc_state =
6039 intel_atomic_get_new_crtc_state(state, crtc);
6040 unsigned int update_mask = new_crtc_state->update_planes;
6041 const struct intel_plane_state *old_plane_state;
6042 struct intel_plane *plane;
6043 unsigned fb_bits = 0;
6046 intel_crtc_dpms_overlay_disable(crtc);
6048 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
6049 if (crtc->pipe != plane->pipe ||
6050 !(update_mask & BIT(plane->id)))
6053 intel_disable_plane(plane, new_crtc_state);
6055 if (old_plane_state->base.visible)
6056 fb_bits |= plane->frontbuffer_bit;
6059 intel_frontbuffer_flip(dev_priv, fb_bits);
6063 * intel_connector_primary_encoder - get the primary encoder for a connector
6064 * @connector: connector for which to return the encoder
6066 * Returns the primary encoder for a connector. There is a 1:1 mapping from
6067 * all connectors to their encoder, except for DP-MST connectors which have
6068 * both a virtual and a primary encoder. These DP-MST primary encoders can be
6069 * pointed to by as many DP-MST connectors as there are pipes.
6071 static struct intel_encoder *
6072 intel_connector_primary_encoder(struct intel_connector *connector)
6074 struct intel_encoder *encoder;
6076 if (connector->mst_port)
6077 return &dp_to_dig_port(connector->mst_port)->base;
6079 encoder = intel_attached_encoder(&connector->base);
6086 intel_connector_needs_modeset(struct intel_atomic_state *state,
6087 const struct drm_connector_state *old_conn_state,
6088 const struct drm_connector_state *new_conn_state)
6090 struct intel_crtc *old_crtc = old_conn_state->crtc ?
6091 to_intel_crtc(old_conn_state->crtc) : NULL;
6092 struct intel_crtc *new_crtc = new_conn_state->crtc ?
6093 to_intel_crtc(new_conn_state->crtc) : NULL;
6095 return new_crtc != old_crtc ||
6097 needs_modeset(intel_atomic_get_new_crtc_state(state, new_crtc)));
6100 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
6102 struct drm_connector_state *old_conn_state;
6103 struct drm_connector_state *new_conn_state;
6104 struct drm_connector *conn;
6107 for_each_oldnew_connector_in_state(&state->base, conn,
6108 old_conn_state, new_conn_state, i) {
6109 struct intel_encoder *encoder;
6110 struct intel_crtc *crtc;
6112 if (!intel_connector_needs_modeset(state,
6117 encoder = intel_connector_primary_encoder(to_intel_connector(conn));
6118 if (!encoder->update_prepare)
6121 crtc = new_conn_state->crtc ?
6122 to_intel_crtc(new_conn_state->crtc) : NULL;
6123 encoder->update_prepare(state, encoder, crtc);
6127 static void intel_encoders_update_complete(struct intel_atomic_state *state)
6129 struct drm_connector_state *old_conn_state;
6130 struct drm_connector_state *new_conn_state;
6131 struct drm_connector *conn;
6134 for_each_oldnew_connector_in_state(&state->base, conn,
6135 old_conn_state, new_conn_state, i) {
6136 struct intel_encoder *encoder;
6137 struct intel_crtc *crtc;
6139 if (!intel_connector_needs_modeset(state,
6144 encoder = intel_connector_primary_encoder(to_intel_connector(conn));
6145 if (!encoder->update_complete)
6148 crtc = new_conn_state->crtc ?
6149 to_intel_crtc(new_conn_state->crtc) : NULL;
6150 encoder->update_complete(state, encoder, crtc);
6154 static void intel_encoders_pre_pll_enable(struct intel_crtc *crtc,
6155 struct intel_crtc_state *crtc_state,
6156 struct intel_atomic_state *state)
6158 struct drm_connector_state *conn_state;
6159 struct drm_connector *conn;
6162 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6163 struct intel_encoder *encoder =
6164 to_intel_encoder(conn_state->best_encoder);
6166 if (conn_state->crtc != &crtc->base)
6169 if (encoder->pre_pll_enable)
6170 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
6174 static void intel_encoders_pre_enable(struct intel_crtc *crtc,
6175 struct intel_crtc_state *crtc_state,
6176 struct intel_atomic_state *state)
6178 struct drm_connector_state *conn_state;
6179 struct drm_connector *conn;
6182 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6183 struct intel_encoder *encoder =
6184 to_intel_encoder(conn_state->best_encoder);
6186 if (conn_state->crtc != &crtc->base)
6189 if (encoder->pre_enable)
6190 encoder->pre_enable(encoder, crtc_state, conn_state);
6194 static void intel_encoders_enable(struct intel_crtc *crtc,
6195 struct intel_crtc_state *crtc_state,
6196 struct intel_atomic_state *state)
6198 struct drm_connector_state *conn_state;
6199 struct drm_connector *conn;
6202 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6203 struct intel_encoder *encoder =
6204 to_intel_encoder(conn_state->best_encoder);
6206 if (conn_state->crtc != &crtc->base)
6209 if (encoder->enable)
6210 encoder->enable(encoder, crtc_state, conn_state);
6211 intel_opregion_notify_encoder(encoder, true);
6215 static void intel_encoders_disable(struct intel_crtc *crtc,
6216 struct intel_crtc_state *old_crtc_state,
6217 struct intel_atomic_state *state)
6219 struct drm_connector_state *old_conn_state;
6220 struct drm_connector *conn;
6223 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6224 struct intel_encoder *encoder =
6225 to_intel_encoder(old_conn_state->best_encoder);
6227 if (old_conn_state->crtc != &crtc->base)
6230 intel_opregion_notify_encoder(encoder, false);
6231 if (encoder->disable)
6232 encoder->disable(encoder, old_crtc_state, old_conn_state);
6236 static void intel_encoders_post_disable(struct intel_crtc *crtc,
6237 struct intel_crtc_state *old_crtc_state,
6238 struct intel_atomic_state *state)
6240 struct drm_connector_state *old_conn_state;
6241 struct drm_connector *conn;
6244 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6245 struct intel_encoder *encoder =
6246 to_intel_encoder(old_conn_state->best_encoder);
6248 if (old_conn_state->crtc != &crtc->base)
6251 if (encoder->post_disable)
6252 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
6256 static void intel_encoders_post_pll_disable(struct intel_crtc *crtc,
6257 struct intel_crtc_state *old_crtc_state,
6258 struct intel_atomic_state *state)
6260 struct drm_connector_state *old_conn_state;
6261 struct drm_connector *conn;
6264 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6265 struct intel_encoder *encoder =
6266 to_intel_encoder(old_conn_state->best_encoder);
6268 if (old_conn_state->crtc != &crtc->base)
6271 if (encoder->post_pll_disable)
6272 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
6276 static void intel_encoders_update_pipe(struct intel_crtc *crtc,
6277 struct intel_crtc_state *crtc_state,
6278 struct intel_atomic_state *state)
6280 struct drm_connector_state *conn_state;
6281 struct drm_connector *conn;
6284 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6285 struct intel_encoder *encoder =
6286 to_intel_encoder(conn_state->best_encoder);
6288 if (conn_state->crtc != &crtc->base)
6291 if (encoder->update_pipe)
6292 encoder->update_pipe(encoder, crtc_state, conn_state);
6296 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
6298 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6299 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
6301 plane->disable_plane(plane, crtc_state);
6304 static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
6305 struct intel_atomic_state *state)
6307 struct drm_crtc *crtc = pipe_config->base.crtc;
6308 struct drm_device *dev = crtc->dev;
6309 struct drm_i915_private *dev_priv = to_i915(dev);
6310 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6311 int pipe = intel_crtc->pipe;
6313 if (WARN_ON(intel_crtc->active))
6317 * Sometimes spurious CPU pipe underruns happen during FDI
6318 * training, at least with VGA+HDMI cloning. Suppress them.
6320 * On ILK we get an occasional spurious CPU pipe underruns
6321 * between eDP port A enable and vdd enable. Also PCH port
6322 * enable seems to result in the occasional CPU pipe underrun.
6324 * Spurious PCH underruns also occur during PCH enabling.
6326 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6327 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6329 if (pipe_config->has_pch_encoder)
6330 intel_prepare_shared_dpll(pipe_config);
6332 if (intel_crtc_has_dp_encoder(pipe_config))
6333 intel_dp_set_m_n(pipe_config, M1_N1);
6335 intel_set_pipe_timings(pipe_config);
6336 intel_set_pipe_src_size(pipe_config);
6338 if (pipe_config->has_pch_encoder) {
6339 intel_cpu_transcoder_set_m_n(pipe_config,
6340 &pipe_config->fdi_m_n, NULL);
6343 ironlake_set_pipeconf(pipe_config);
6345 intel_crtc->active = true;
6347 intel_encoders_pre_enable(intel_crtc, pipe_config, state);
6349 if (pipe_config->has_pch_encoder) {
6350 /* Note: FDI PLL enabling _must_ be done before we enable the
6351 * cpu pipes, hence this is separate from all the other fdi/pch
6353 ironlake_fdi_pll_enable(pipe_config);
6355 assert_fdi_tx_disabled(dev_priv, pipe);
6356 assert_fdi_rx_disabled(dev_priv, pipe);
6359 ironlake_pfit_enable(pipe_config);
6362 * On ILK+ LUT must be loaded before the pipe is running but with
6365 intel_color_load_luts(pipe_config);
6366 intel_color_commit(pipe_config);
6367 /* update DSPCNTR to configure gamma for pipe bottom color */
6368 intel_disable_primary_plane(pipe_config);
6370 if (dev_priv->display.initial_watermarks != NULL)
6371 dev_priv->display.initial_watermarks(state, pipe_config);
6372 intel_enable_pipe(pipe_config);
6374 if (pipe_config->has_pch_encoder)
6375 ironlake_pch_enable(state, pipe_config);
6377 assert_vblank_disabled(crtc);
6378 intel_crtc_vblank_on(pipe_config);
6380 intel_encoders_enable(intel_crtc, pipe_config, state);
6382 if (HAS_PCH_CPT(dev_priv))
6383 cpt_verify_modeset(dev, intel_crtc->pipe);
6386 * Must wait for vblank to avoid spurious PCH FIFO underruns.
6387 * And a second vblank wait is needed at least on ILK with
6388 * some interlaced HDMI modes. Let's do the double wait always
6389 * in case there are more corner cases we don't know about.
6391 if (pipe_config->has_pch_encoder) {
6392 intel_wait_for_vblank(dev_priv, pipe);
6393 intel_wait_for_vblank(dev_priv, pipe);
6395 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6396 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6399 /* IPS only exists on ULT machines and is tied to pipe A. */
6400 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
6402 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
6405 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
6406 enum pipe pipe, bool apply)
6408 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
6409 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
6416 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
6419 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
6421 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6422 enum pipe pipe = crtc->pipe;
6425 val = MBUS_DBOX_A_CREDIT(2);
6426 val |= MBUS_DBOX_BW_CREDIT(1);
6427 val |= MBUS_DBOX_B_CREDIT(8);
6429 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
6432 static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
6433 struct intel_atomic_state *state)
6435 struct drm_crtc *crtc = pipe_config->base.crtc;
6436 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6437 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6438 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
6439 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
6440 bool psl_clkgate_wa;
6442 if (WARN_ON(intel_crtc->active))
6445 intel_encoders_pre_pll_enable(intel_crtc, pipe_config, state);
6447 if (pipe_config->shared_dpll)
6448 intel_enable_shared_dpll(pipe_config);
6450 intel_encoders_pre_enable(intel_crtc, pipe_config, state);
6452 if (intel_crtc_has_dp_encoder(pipe_config))
6453 intel_dp_set_m_n(pipe_config, M1_N1);
6455 if (!transcoder_is_dsi(cpu_transcoder))
6456 intel_set_pipe_timings(pipe_config);
6458 intel_set_pipe_src_size(pipe_config);
6460 if (cpu_transcoder != TRANSCODER_EDP &&
6461 !transcoder_is_dsi(cpu_transcoder)) {
6462 I915_WRITE(PIPE_MULT(cpu_transcoder),
6463 pipe_config->pixel_multiplier - 1);
6466 if (pipe_config->has_pch_encoder) {
6467 intel_cpu_transcoder_set_m_n(pipe_config,
6468 &pipe_config->fdi_m_n, NULL);
6471 if (!transcoder_is_dsi(cpu_transcoder))
6472 haswell_set_pipeconf(pipe_config);
6474 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
6475 bdw_set_pipemisc(pipe_config);
6477 intel_crtc->active = true;
6479 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
6480 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
6481 pipe_config->pch_pfit.enabled;
6483 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
6485 if (INTEL_GEN(dev_priv) >= 9)
6486 skylake_pfit_enable(pipe_config);
6488 ironlake_pfit_enable(pipe_config);
6491 * On ILK+ LUT must be loaded before the pipe is running but with
6494 intel_color_load_luts(pipe_config);
6495 intel_color_commit(pipe_config);
6496 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
6497 if (INTEL_GEN(dev_priv) < 9)
6498 intel_disable_primary_plane(pipe_config);
6500 if (INTEL_GEN(dev_priv) >= 11)
6501 icl_set_pipe_chicken(intel_crtc);
6503 intel_ddi_set_pipe_settings(pipe_config);
6504 if (!transcoder_is_dsi(cpu_transcoder))
6505 intel_ddi_enable_transcoder_func(pipe_config);
6507 if (dev_priv->display.initial_watermarks != NULL)
6508 dev_priv->display.initial_watermarks(state, pipe_config);
6510 if (INTEL_GEN(dev_priv) >= 11)
6511 icl_pipe_mbus_enable(intel_crtc);
6513 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
6514 if (!transcoder_is_dsi(cpu_transcoder))
6515 intel_enable_pipe(pipe_config);
6517 if (pipe_config->has_pch_encoder)
6518 lpt_pch_enable(state, pipe_config);
6520 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST))
6521 intel_ddi_set_vc_payload_alloc(pipe_config, true);
6523 assert_vblank_disabled(crtc);
6524 intel_crtc_vblank_on(pipe_config);
6526 intel_encoders_enable(intel_crtc, pipe_config, state);
6528 if (psl_clkgate_wa) {
6529 intel_wait_for_vblank(dev_priv, pipe);
6530 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
6533 /* If we change the relative order between pipe/planes enabling, we need
6534 * to change the workaround. */
6535 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
6536 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
6537 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6538 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6542 static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6544 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6545 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6546 enum pipe pipe = crtc->pipe;
6548 /* To avoid upsetting the power well on haswell only disable the pfit if
6549 * it's in use. The hw state code will make sure we get this right. */
6550 if (old_crtc_state->pch_pfit.enabled) {
6551 I915_WRITE(PF_CTL(pipe), 0);
6552 I915_WRITE(PF_WIN_POS(pipe), 0);
6553 I915_WRITE(PF_WIN_SZ(pipe), 0);
6557 static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
6558 struct intel_atomic_state *state)
6560 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6561 struct drm_device *dev = crtc->dev;
6562 struct drm_i915_private *dev_priv = to_i915(dev);
6563 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6564 int pipe = intel_crtc->pipe;
6567 * Sometimes spurious CPU pipe underruns happen when the
6568 * pipe is already disabled, but FDI RX/TX is still enabled.
6569 * Happens at least with VGA+HDMI cloning. Suppress them.
6571 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6572 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6574 intel_encoders_disable(intel_crtc, old_crtc_state, state);
6576 drm_crtc_vblank_off(crtc);
6577 assert_vblank_disabled(crtc);
6579 intel_disable_pipe(old_crtc_state);
6581 ironlake_pfit_disable(old_crtc_state);
6583 if (old_crtc_state->has_pch_encoder)
6584 ironlake_fdi_disable(crtc);
6586 intel_encoders_post_disable(intel_crtc, old_crtc_state, state);
6588 if (old_crtc_state->has_pch_encoder) {
6589 ironlake_disable_pch_transcoder(dev_priv, pipe);
6591 if (HAS_PCH_CPT(dev_priv)) {
6595 /* disable TRANS_DP_CTL */
6596 reg = TRANS_DP_CTL(pipe);
6597 temp = I915_READ(reg);
6598 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
6599 TRANS_DP_PORT_SEL_MASK);
6600 temp |= TRANS_DP_PORT_SEL_NONE;
6601 I915_WRITE(reg, temp);
6603 /* disable DPLL_SEL */
6604 temp = I915_READ(PCH_DPLL_SEL);
6605 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
6606 I915_WRITE(PCH_DPLL_SEL, temp);
6609 ironlake_fdi_pll_disable(intel_crtc);
6612 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6613 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6616 static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
6617 struct intel_atomic_state *state)
6619 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6620 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6621 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6622 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
6624 intel_encoders_disable(intel_crtc, old_crtc_state, state);
6626 drm_crtc_vblank_off(crtc);
6627 assert_vblank_disabled(crtc);
6629 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
6630 if (!transcoder_is_dsi(cpu_transcoder))
6631 intel_disable_pipe(old_crtc_state);
6633 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
6634 intel_ddi_set_vc_payload_alloc(old_crtc_state, false);
6636 if (!transcoder_is_dsi(cpu_transcoder))
6637 intel_ddi_disable_transcoder_func(old_crtc_state);
6639 intel_dsc_disable(old_crtc_state);
6641 if (INTEL_GEN(dev_priv) >= 9)
6642 skylake_scaler_disable(intel_crtc);
6644 ironlake_pfit_disable(old_crtc_state);
6646 intel_encoders_post_disable(intel_crtc, old_crtc_state, state);
6648 intel_encoders_post_pll_disable(intel_crtc, old_crtc_state, state);
6651 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
6653 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6654 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6656 if (!crtc_state->gmch_pfit.control)
6660 * The panel fitter should only be adjusted whilst the pipe is disabled,
6661 * according to register description and PRM.
6663 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
6664 assert_pipe_disabled(dev_priv, crtc->pipe);
6666 I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
6667 I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
6669 /* Border color in case we don't scale up to the full screen. Black by
6670 * default, change to something else for debugging. */
6671 I915_WRITE(BCLRPAT(crtc->pipe), 0);
6674 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
6676 if (phy == PHY_NONE)
6679 if (IS_ELKHARTLAKE(dev_priv))
6680 return phy <= PHY_C;
6682 if (INTEL_GEN(dev_priv) >= 11)
6683 return phy <= PHY_B;
6688 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
6690 if (INTEL_GEN(dev_priv) >= 11 && !IS_ELKHARTLAKE(dev_priv))
6691 return phy >= PHY_C && phy <= PHY_F;
6696 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
6698 if (IS_ELKHARTLAKE(i915) && port == PORT_D)
6701 return (enum phy)port;
6704 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
6706 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
6707 return PORT_TC_NONE;
6709 return port - PORT_C;
6712 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
6716 return POWER_DOMAIN_PORT_DDI_A_LANES;
6718 return POWER_DOMAIN_PORT_DDI_B_LANES;
6720 return POWER_DOMAIN_PORT_DDI_C_LANES;
6722 return POWER_DOMAIN_PORT_DDI_D_LANES;
6724 return POWER_DOMAIN_PORT_DDI_E_LANES;
6726 return POWER_DOMAIN_PORT_DDI_F_LANES;
6729 return POWER_DOMAIN_PORT_OTHER;
6733 enum intel_display_power_domain
6734 intel_aux_power_domain(struct intel_digital_port *dig_port)
6736 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
6737 enum phy phy = intel_port_to_phy(dev_priv, dig_port->base.port);
6739 if (intel_phy_is_tc(dev_priv, phy) &&
6740 dig_port->tc_mode == TC_PORT_TBT_ALT) {
6741 switch (dig_port->aux_ch) {
6743 return POWER_DOMAIN_AUX_TBT1;
6745 return POWER_DOMAIN_AUX_TBT2;
6747 return POWER_DOMAIN_AUX_TBT3;
6749 return POWER_DOMAIN_AUX_TBT4;
6751 MISSING_CASE(dig_port->aux_ch);
6752 return POWER_DOMAIN_AUX_TBT1;
6756 switch (dig_port->aux_ch) {
6758 return POWER_DOMAIN_AUX_A;
6760 return POWER_DOMAIN_AUX_B;
6762 return POWER_DOMAIN_AUX_C;
6764 return POWER_DOMAIN_AUX_D;
6766 return POWER_DOMAIN_AUX_E;
6768 return POWER_DOMAIN_AUX_F;
6770 MISSING_CASE(dig_port->aux_ch);
6771 return POWER_DOMAIN_AUX_A;
6775 static u64 get_crtc_power_domains(struct intel_crtc_state *crtc_state)
6777 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6778 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6779 struct drm_encoder *encoder;
6780 enum pipe pipe = crtc->pipe;
6782 enum transcoder transcoder = crtc_state->cpu_transcoder;
6784 if (!crtc_state->base.active)
6787 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
6788 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
6789 if (crtc_state->pch_pfit.enabled ||
6790 crtc_state->pch_pfit.force_thru)
6791 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
6793 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
6794 crtc_state->base.encoder_mask) {
6795 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6797 mask |= BIT_ULL(intel_encoder->power_domain);
6800 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
6801 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
6803 if (crtc_state->shared_dpll)
6804 mask |= BIT_ULL(POWER_DOMAIN_DISPLAY_CORE);
6810 modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state)
6812 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6813 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6814 enum intel_display_power_domain domain;
6815 u64 domains, new_domains, old_domains;
6817 old_domains = crtc->enabled_power_domains;
6818 crtc->enabled_power_domains = new_domains =
6819 get_crtc_power_domains(crtc_state);
6821 domains = new_domains & ~old_domains;
6823 for_each_power_domain(domain, domains)
6824 intel_display_power_get(dev_priv, domain);
6826 return old_domains & ~new_domains;
6829 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
6832 enum intel_display_power_domain domain;
6834 for_each_power_domain(domain, domains)
6835 intel_display_power_put_unchecked(dev_priv, domain);
6838 static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
6839 struct intel_atomic_state *state)
6841 struct drm_crtc *crtc = pipe_config->base.crtc;
6842 struct drm_device *dev = crtc->dev;
6843 struct drm_i915_private *dev_priv = to_i915(dev);
6844 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6845 int pipe = intel_crtc->pipe;
6847 if (WARN_ON(intel_crtc->active))
6850 if (intel_crtc_has_dp_encoder(pipe_config))
6851 intel_dp_set_m_n(pipe_config, M1_N1);
6853 intel_set_pipe_timings(pipe_config);
6854 intel_set_pipe_src_size(pipe_config);
6856 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
6857 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6858 I915_WRITE(CHV_CANVAS(pipe), 0);
6861 i9xx_set_pipeconf(pipe_config);
6863 intel_crtc->active = true;
6865 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6867 intel_encoders_pre_pll_enable(intel_crtc, pipe_config, state);
6869 if (IS_CHERRYVIEW(dev_priv)) {
6870 chv_prepare_pll(intel_crtc, pipe_config);
6871 chv_enable_pll(intel_crtc, pipe_config);
6873 vlv_prepare_pll(intel_crtc, pipe_config);
6874 vlv_enable_pll(intel_crtc, pipe_config);
6877 intel_encoders_pre_enable(intel_crtc, pipe_config, state);
6879 i9xx_pfit_enable(pipe_config);
6881 intel_color_load_luts(pipe_config);
6882 intel_color_commit(pipe_config);
6883 /* update DSPCNTR to configure gamma for pipe bottom color */
6884 intel_disable_primary_plane(pipe_config);
6886 dev_priv->display.initial_watermarks(state, pipe_config);
6887 intel_enable_pipe(pipe_config);
6889 assert_vblank_disabled(crtc);
6890 intel_crtc_vblank_on(pipe_config);
6892 intel_encoders_enable(intel_crtc, pipe_config, state);
6895 static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
6897 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6898 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6900 I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0);
6901 I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1);
6904 static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
6905 struct intel_atomic_state *state)
6907 struct drm_crtc *crtc = pipe_config->base.crtc;
6908 struct drm_device *dev = crtc->dev;
6909 struct drm_i915_private *dev_priv = to_i915(dev);
6910 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6911 enum pipe pipe = intel_crtc->pipe;
6913 if (WARN_ON(intel_crtc->active))
6916 i9xx_set_pll_dividers(pipe_config);
6918 if (intel_crtc_has_dp_encoder(pipe_config))
6919 intel_dp_set_m_n(pipe_config, M1_N1);
6921 intel_set_pipe_timings(pipe_config);
6922 intel_set_pipe_src_size(pipe_config);
6924 i9xx_set_pipeconf(pipe_config);
6926 intel_crtc->active = true;
6928 if (!IS_GEN(dev_priv, 2))
6929 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6931 intel_encoders_pre_enable(intel_crtc, pipe_config, state);
6933 i9xx_enable_pll(intel_crtc, pipe_config);
6935 i9xx_pfit_enable(pipe_config);
6937 intel_color_load_luts(pipe_config);
6938 intel_color_commit(pipe_config);
6939 /* update DSPCNTR to configure gamma for pipe bottom color */
6940 intel_disable_primary_plane(pipe_config);
6942 if (dev_priv->display.initial_watermarks != NULL)
6943 dev_priv->display.initial_watermarks(state,
6946 intel_update_watermarks(intel_crtc);
6947 intel_enable_pipe(pipe_config);
6949 assert_vblank_disabled(crtc);
6950 intel_crtc_vblank_on(pipe_config);
6952 intel_encoders_enable(intel_crtc, pipe_config, state);
6955 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6957 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6958 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6960 if (!old_crtc_state->gmch_pfit.control)
6963 assert_pipe_disabled(dev_priv, crtc->pipe);
6965 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
6966 I915_READ(PFIT_CONTROL));
6967 I915_WRITE(PFIT_CONTROL, 0);
6970 static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6971 struct intel_atomic_state *state)
6973 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6974 struct drm_device *dev = crtc->dev;
6975 struct drm_i915_private *dev_priv = to_i915(dev);
6976 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6977 int pipe = intel_crtc->pipe;
6980 * On gen2 planes are double buffered but the pipe isn't, so we must
6981 * wait for planes to fully turn off before disabling the pipe.
6983 if (IS_GEN(dev_priv, 2))
6984 intel_wait_for_vblank(dev_priv, pipe);
6986 intel_encoders_disable(intel_crtc, old_crtc_state, state);
6988 drm_crtc_vblank_off(crtc);
6989 assert_vblank_disabled(crtc);
6991 intel_disable_pipe(old_crtc_state);
6993 i9xx_pfit_disable(old_crtc_state);
6995 intel_encoders_post_disable(intel_crtc, old_crtc_state, state);
6997 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
6998 if (IS_CHERRYVIEW(dev_priv))
6999 chv_disable_pll(dev_priv, pipe);
7000 else if (IS_VALLEYVIEW(dev_priv))
7001 vlv_disable_pll(dev_priv, pipe);
7003 i9xx_disable_pll(old_crtc_state);
7006 intel_encoders_post_pll_disable(intel_crtc, old_crtc_state, state);
7008 if (!IS_GEN(dev_priv, 2))
7009 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
7011 if (!dev_priv->display.initial_watermarks)
7012 intel_update_watermarks(intel_crtc);
7014 /* clock the pipe down to 640x480@60 to potentially save power */
7015 if (IS_I830(dev_priv))
7016 i830_enable_pipe(dev_priv, pipe);
7019 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
7020 struct drm_modeset_acquire_ctx *ctx)
7022 struct intel_encoder *encoder;
7023 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7024 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
7025 struct intel_bw_state *bw_state =
7026 to_intel_bw_state(dev_priv->bw_obj.state);
7027 enum intel_display_power_domain domain;
7028 struct intel_plane *plane;
7030 struct drm_atomic_state *state;
7031 struct intel_crtc_state *crtc_state;
7034 if (!intel_crtc->active)
7037 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
7038 const struct intel_plane_state *plane_state =
7039 to_intel_plane_state(plane->base.state);
7041 if (plane_state->base.visible)
7042 intel_plane_disable_noatomic(intel_crtc, plane);
7045 state = drm_atomic_state_alloc(crtc->dev);
7047 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
7048 crtc->base.id, crtc->name);
7052 state->acquire_ctx = ctx;
7054 /* Everything's already locked, -EDEADLK can't happen. */
7055 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
7056 ret = drm_atomic_add_affected_connectors(state, crtc);
7058 WARN_ON(IS_ERR(crtc_state) || ret);
7060 dev_priv->display.crtc_disable(crtc_state, to_intel_atomic_state(state));
7062 drm_atomic_state_put(state);
7064 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
7065 crtc->base.id, crtc->name);
7067 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
7068 crtc->state->active = false;
7069 intel_crtc->active = false;
7070 crtc->enabled = false;
7071 crtc->state->connector_mask = 0;
7072 crtc->state->encoder_mask = 0;
7074 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
7075 encoder->base.crtc = NULL;
7077 intel_fbc_disable(intel_crtc);
7078 intel_update_watermarks(intel_crtc);
7079 intel_disable_shared_dpll(to_intel_crtc_state(crtc->state));
7081 domains = intel_crtc->enabled_power_domains;
7082 for_each_power_domain(domain, domains)
7083 intel_display_power_put_unchecked(dev_priv, domain);
7084 intel_crtc->enabled_power_domains = 0;
7086 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
7087 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
7088 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
7090 bw_state->data_rate[intel_crtc->pipe] = 0;
7091 bw_state->num_active_planes[intel_crtc->pipe] = 0;
7095 * turn all crtc's off, but do not adjust state
7096 * This has to be paired with a call to intel_modeset_setup_hw_state.
7098 int intel_display_suspend(struct drm_device *dev)
7100 struct drm_i915_private *dev_priv = to_i915(dev);
7101 struct drm_atomic_state *state;
7104 state = drm_atomic_helper_suspend(dev);
7105 ret = PTR_ERR_OR_ZERO(state);
7107 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
7109 dev_priv->modeset_restore_state = state;
7113 void intel_encoder_destroy(struct drm_encoder *encoder)
7115 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
7117 drm_encoder_cleanup(encoder);
7118 kfree(intel_encoder);
7121 /* Cross check the actual hw state with our own modeset state tracking (and it's
7122 * internal consistency). */
7123 static void intel_connector_verify_state(struct intel_crtc_state *crtc_state,
7124 struct drm_connector_state *conn_state)
7126 struct intel_connector *connector = to_intel_connector(conn_state->connector);
7128 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
7129 connector->base.base.id,
7130 connector->base.name);
7132 if (connector->get_hw_state(connector)) {
7133 struct intel_encoder *encoder = connector->encoder;
7135 I915_STATE_WARN(!crtc_state,
7136 "connector enabled without attached crtc\n");
7141 I915_STATE_WARN(!crtc_state->base.active,
7142 "connector is active, but attached crtc isn't\n");
7144 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
7147 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
7148 "atomic encoder doesn't match attached encoder\n");
7150 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
7151 "attached encoder crtc differs from connector crtc\n");
7153 I915_STATE_WARN(crtc_state && crtc_state->base.active,
7154 "attached crtc is active, but connector isn't\n");
7155 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
7156 "best encoder set without crtc!\n");
7160 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
7162 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
7163 return crtc_state->fdi_lanes;
7168 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
7169 struct intel_crtc_state *pipe_config)
7171 struct drm_i915_private *dev_priv = to_i915(dev);
7172 struct drm_atomic_state *state = pipe_config->base.state;
7173 struct intel_crtc *other_crtc;
7174 struct intel_crtc_state *other_crtc_state;
7176 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
7177 pipe_name(pipe), pipe_config->fdi_lanes);
7178 if (pipe_config->fdi_lanes > 4) {
7179 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
7180 pipe_name(pipe), pipe_config->fdi_lanes);
7184 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7185 if (pipe_config->fdi_lanes > 2) {
7186 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
7187 pipe_config->fdi_lanes);
7194 if (INTEL_INFO(dev_priv)->num_pipes == 2)
7197 /* Ivybridge 3 pipe is really complicated */
7202 if (pipe_config->fdi_lanes <= 2)
7205 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
7207 intel_atomic_get_crtc_state(state, other_crtc);
7208 if (IS_ERR(other_crtc_state))
7209 return PTR_ERR(other_crtc_state);
7211 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
7212 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
7213 pipe_name(pipe), pipe_config->fdi_lanes);
7218 if (pipe_config->fdi_lanes > 2) {
7219 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
7220 pipe_name(pipe), pipe_config->fdi_lanes);
7224 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
7226 intel_atomic_get_crtc_state(state, other_crtc);
7227 if (IS_ERR(other_crtc_state))
7228 return PTR_ERR(other_crtc_state);
7230 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
7231 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
7241 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
7242 struct intel_crtc_state *pipe_config)
7244 struct drm_device *dev = intel_crtc->base.dev;
7245 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
7246 int lane, link_bw, fdi_dotclock, ret;
7247 bool needs_recompute = false;
7250 /* FDI is a binary signal running at ~2.7GHz, encoding
7251 * each output octet as 10 bits. The actual frequency
7252 * is stored as a divider into a 100MHz clock, and the
7253 * mode pixel clock is stored in units of 1KHz.
7254 * Hence the bw of each lane in terms of the mode signal
7257 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
7259 fdi_dotclock = adjusted_mode->crtc_clock;
7261 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
7262 pipe_config->pipe_bpp);
7264 pipe_config->fdi_lanes = lane;
7266 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
7267 link_bw, &pipe_config->fdi_m_n, false);
7269 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
7270 if (ret == -EDEADLK)
7273 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
7274 pipe_config->pipe_bpp -= 2*3;
7275 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
7276 pipe_config->pipe_bpp);
7277 needs_recompute = true;
7278 pipe_config->bw_constrained = true;
7283 if (needs_recompute)
7289 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
7291 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7292 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7294 /* IPS only exists on ULT machines and is tied to pipe A. */
7295 if (!hsw_crtc_supports_ips(crtc))
7298 if (!i915_modparams.enable_ips)
7301 if (crtc_state->pipe_bpp > 24)
7305 * We compare against max which means we must take
7306 * the increased cdclk requirement into account when
7307 * calculating the new cdclk.
7309 * Should measure whether using a lower cdclk w/o IPS
7311 if (IS_BROADWELL(dev_priv) &&
7312 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
7318 static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
7320 struct drm_i915_private *dev_priv =
7321 to_i915(crtc_state->base.crtc->dev);
7322 struct intel_atomic_state *intel_state =
7323 to_intel_atomic_state(crtc_state->base.state);
7325 if (!hsw_crtc_state_ips_capable(crtc_state))
7329 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
7330 * enabled and disabled dynamically based on package C states,
7331 * user space can't make reliable use of the CRCs, so let's just
7332 * completely disable it.
7334 if (crtc_state->crc_enabled)
7337 /* IPS should be fine as long as at least one plane is enabled. */
7338 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
7341 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
7342 if (IS_BROADWELL(dev_priv) &&
7343 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
7349 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
7351 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7353 /* GDG double wide on either pipe, otherwise pipe A only */
7354 return INTEL_GEN(dev_priv) < 4 &&
7355 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
7358 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
7362 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
7365 * We only use IF-ID interlacing. If we ever use
7366 * PF-ID we'll need to adjust the pixel_rate here.
7369 if (pipe_config->pch_pfit.enabled) {
7370 u64 pipe_w, pipe_h, pfit_w, pfit_h;
7371 u32 pfit_size = pipe_config->pch_pfit.size;
7373 pipe_w = pipe_config->pipe_src_w;
7374 pipe_h = pipe_config->pipe_src_h;
7376 pfit_w = (pfit_size >> 16) & 0xFFFF;
7377 pfit_h = pfit_size & 0xFFFF;
7378 if (pipe_w < pfit_w)
7380 if (pipe_h < pfit_h)
7383 if (WARN_ON(!pfit_w || !pfit_h))
7386 pixel_rate = div_u64(mul_u32_u32(pixel_rate, pipe_w * pipe_h),
7393 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
7395 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
7397 if (HAS_GMCH(dev_priv))
7398 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
7399 crtc_state->pixel_rate =
7400 crtc_state->base.adjusted_mode.crtc_clock;
7402 crtc_state->pixel_rate =
7403 ilk_pipe_pixel_rate(crtc_state);
7406 static int intel_crtc_compute_config(struct intel_crtc *crtc,
7407 struct intel_crtc_state *pipe_config)
7409 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7410 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
7411 int clock_limit = dev_priv->max_dotclk_freq;
7413 if (INTEL_GEN(dev_priv) < 4) {
7414 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
7417 * Enable double wide mode when the dot clock
7418 * is > 90% of the (display) core speed.
7420 if (intel_crtc_supports_double_wide(crtc) &&
7421 adjusted_mode->crtc_clock > clock_limit) {
7422 clock_limit = dev_priv->max_dotclk_freq;
7423 pipe_config->double_wide = true;
7427 if (adjusted_mode->crtc_clock > clock_limit) {
7428 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
7429 adjusted_mode->crtc_clock, clock_limit,
7430 yesno(pipe_config->double_wide));
7434 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
7435 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
7436 pipe_config->base.ctm) {
7438 * There is only one pipe CSC unit per pipe, and we need that
7439 * for output conversion from RGB->YCBCR. So if CTM is already
7440 * applied we can't support YCBCR420 output.
7442 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
7447 * Pipe horizontal size must be even in:
7449 * - LVDS dual channel mode
7450 * - Double wide pipe
7452 if (pipe_config->pipe_src_w & 1) {
7453 if (pipe_config->double_wide) {
7454 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
7458 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
7459 intel_is_dual_link_lvds(dev_priv)) {
7460 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
7465 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
7466 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
7468 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
7469 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
7472 intel_crtc_compute_pixel_rate(pipe_config);
7474 if (pipe_config->has_pch_encoder)
7475 return ironlake_fdi_compute_config(crtc, pipe_config);
7481 intel_reduce_m_n_ratio(u32 *num, u32 *den)
7483 while (*num > DATA_LINK_M_N_MASK ||
7484 *den > DATA_LINK_M_N_MASK) {
7490 static void compute_m_n(unsigned int m, unsigned int n,
7491 u32 *ret_m, u32 *ret_n,
7495 * Several DP dongles in particular seem to be fussy about
7496 * too large link M/N values. Give N value as 0x8000 that
7497 * should be acceptable by specific devices. 0x8000 is the
7498 * specified fixed N value for asynchronous clock mode,
7499 * which the devices expect also in synchronous clock mode.
7504 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
7506 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
7507 intel_reduce_m_n_ratio(ret_m, ret_n);
7511 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
7512 int pixel_clock, int link_clock,
7513 struct intel_link_m_n *m_n,
7518 compute_m_n(bits_per_pixel * pixel_clock,
7519 link_clock * nlanes * 8,
7520 &m_n->gmch_m, &m_n->gmch_n,
7523 compute_m_n(pixel_clock, link_clock,
7524 &m_n->link_m, &m_n->link_n,
7528 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
7530 if (i915_modparams.panel_use_ssc >= 0)
7531 return i915_modparams.panel_use_ssc != 0;
7532 return dev_priv->vbt.lvds_use_ssc
7533 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
7536 static u32 pnv_dpll_compute_fp(struct dpll *dpll)
7538 return (1 << dpll->n) << 16 | dpll->m2;
7541 static u32 i9xx_dpll_compute_fp(struct dpll *dpll)
7543 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
7546 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
7547 struct intel_crtc_state *crtc_state,
7548 struct dpll *reduced_clock)
7550 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7553 if (IS_PINEVIEW(dev_priv)) {
7554 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
7556 fp2 = pnv_dpll_compute_fp(reduced_clock);
7558 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
7560 fp2 = i9xx_dpll_compute_fp(reduced_clock);
7563 crtc_state->dpll_hw_state.fp0 = fp;
7565 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7567 crtc_state->dpll_hw_state.fp1 = fp2;
7569 crtc_state->dpll_hw_state.fp1 = fp;
7573 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
7579 * PLLB opamp always calibrates to max value of 0x3f, force enable it
7580 * and set it to a reasonable value instead.
7582 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7583 reg_val &= 0xffffff00;
7584 reg_val |= 0x00000030;
7585 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7587 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7588 reg_val &= 0x00ffffff;
7589 reg_val |= 0x8c000000;
7590 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7592 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7593 reg_val &= 0xffffff00;
7594 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7596 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7597 reg_val &= 0x00ffffff;
7598 reg_val |= 0xb0000000;
7599 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7602 static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7603 const struct intel_link_m_n *m_n)
7605 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7606 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7607 enum pipe pipe = crtc->pipe;
7609 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7610 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
7611 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
7612 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
7615 static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
7616 enum transcoder transcoder)
7618 if (IS_HASWELL(dev_priv))
7619 return transcoder == TRANSCODER_EDP;
7622 * Strictly speaking some registers are available before
7623 * gen7, but we only support DRRS on gen7+
7625 return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv);
7628 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7629 const struct intel_link_m_n *m_n,
7630 const struct intel_link_m_n *m2_n2)
7632 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7633 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7634 enum pipe pipe = crtc->pipe;
7635 enum transcoder transcoder = crtc_state->cpu_transcoder;
7637 if (INTEL_GEN(dev_priv) >= 5) {
7638 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
7639 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
7640 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
7641 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
7643 * M2_N2 registers are set only if DRRS is supported
7644 * (to make sure the registers are not unnecessarily accessed).
7646 if (m2_n2 && crtc_state->has_drrs &&
7647 transcoder_has_m2_n2(dev_priv, transcoder)) {
7648 I915_WRITE(PIPE_DATA_M2(transcoder),
7649 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
7650 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
7651 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
7652 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
7655 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7656 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
7657 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
7658 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
7662 void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n)
7664 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
7667 dp_m_n = &crtc_state->dp_m_n;
7668 dp_m2_n2 = &crtc_state->dp_m2_n2;
7669 } else if (m_n == M2_N2) {
7672 * M2_N2 registers are not supported. Hence m2_n2 divider value
7673 * needs to be programmed into M1_N1.
7675 dp_m_n = &crtc_state->dp_m2_n2;
7677 DRM_ERROR("Unsupported divider value\n");
7681 if (crtc_state->has_pch_encoder)
7682 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
7684 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
7687 static void vlv_compute_dpll(struct intel_crtc *crtc,
7688 struct intel_crtc_state *pipe_config)
7690 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
7691 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
7692 if (crtc->pipe != PIPE_A)
7693 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7695 /* DPLL not used with DSI, but still need the rest set up */
7696 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
7697 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
7698 DPLL_EXT_BUFFER_ENABLE_VLV;
7700 pipe_config->dpll_hw_state.dpll_md =
7701 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7704 static void chv_compute_dpll(struct intel_crtc *crtc,
7705 struct intel_crtc_state *pipe_config)
7707 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
7708 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
7709 if (crtc->pipe != PIPE_A)
7710 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7712 /* DPLL not used with DSI, but still need the rest set up */
7713 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
7714 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
7716 pipe_config->dpll_hw_state.dpll_md =
7717 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7720 static void vlv_prepare_pll(struct intel_crtc *crtc,
7721 const struct intel_crtc_state *pipe_config)
7723 struct drm_device *dev = crtc->base.dev;
7724 struct drm_i915_private *dev_priv = to_i915(dev);
7725 enum pipe pipe = crtc->pipe;
7727 u32 bestn, bestm1, bestm2, bestp1, bestp2;
7728 u32 coreclk, reg_val;
7731 I915_WRITE(DPLL(pipe),
7732 pipe_config->dpll_hw_state.dpll &
7733 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
7735 /* No need to actually set up the DPLL with DSI */
7736 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7739 vlv_dpio_get(dev_priv);
7741 bestn = pipe_config->dpll.n;
7742 bestm1 = pipe_config->dpll.m1;
7743 bestm2 = pipe_config->dpll.m2;
7744 bestp1 = pipe_config->dpll.p1;
7745 bestp2 = pipe_config->dpll.p2;
7747 /* See eDP HDMI DPIO driver vbios notes doc */
7749 /* PLL B needs special handling */
7751 vlv_pllb_recal_opamp(dev_priv, pipe);
7753 /* Set up Tx target for periodic Rcomp update */
7754 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
7756 /* Disable target IRef on PLL */
7757 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
7758 reg_val &= 0x00ffffff;
7759 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
7761 /* Disable fast lock */
7762 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
7764 /* Set idtafcrecal before PLL is enabled */
7765 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
7766 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
7767 mdiv |= ((bestn << DPIO_N_SHIFT));
7768 mdiv |= (1 << DPIO_K_SHIFT);
7771 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7772 * but we don't support that).
7773 * Note: don't use the DAC post divider as it seems unstable.
7775 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
7776 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7778 mdiv |= DPIO_ENABLE_CALIBRATION;
7779 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7781 /* Set HBR and RBR LPF coefficients */
7782 if (pipe_config->port_clock == 162000 ||
7783 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
7784 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
7785 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7788 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7791 if (intel_crtc_has_dp_encoder(pipe_config)) {
7792 /* Use SSC source */
7794 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7797 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7799 } else { /* HDMI or VGA */
7800 /* Use bend source */
7802 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7805 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7809 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
7810 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
7811 if (intel_crtc_has_dp_encoder(pipe_config))
7812 coreclk |= 0x01000000;
7813 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
7815 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
7817 vlv_dpio_put(dev_priv);
7820 static void chv_prepare_pll(struct intel_crtc *crtc,
7821 const struct intel_crtc_state *pipe_config)
7823 struct drm_device *dev = crtc->base.dev;
7824 struct drm_i915_private *dev_priv = to_i915(dev);
7825 enum pipe pipe = crtc->pipe;
7826 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7827 u32 loopfilter, tribuf_calcntr;
7828 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
7832 /* Enable Refclk and SSC */
7833 I915_WRITE(DPLL(pipe),
7834 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
7836 /* No need to actually set up the DPLL with DSI */
7837 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7840 bestn = pipe_config->dpll.n;
7841 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7842 bestm1 = pipe_config->dpll.m1;
7843 bestm2 = pipe_config->dpll.m2 >> 22;
7844 bestp1 = pipe_config->dpll.p1;
7845 bestp2 = pipe_config->dpll.p2;
7846 vco = pipe_config->dpll.vco;
7850 vlv_dpio_get(dev_priv);
7852 /* p1 and p2 divider */
7853 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7854 5 << DPIO_CHV_S1_DIV_SHIFT |
7855 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
7856 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
7857 1 << DPIO_CHV_K_DIV_SHIFT);
7859 /* Feedback post-divider - m2 */
7860 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7862 /* Feedback refclk divider - n and m1 */
7863 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7864 DPIO_CHV_M1_DIV_BY_2 |
7865 1 << DPIO_CHV_N_DIV_SHIFT);
7867 /* M2 fraction division */
7868 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
7870 /* M2 fraction division enable */
7871 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7872 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7873 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7875 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7876 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
7878 /* Program digital lock detect threshold */
7879 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7880 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7881 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7882 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7884 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7885 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7888 if (vco == 5400000) {
7889 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7890 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7891 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7892 tribuf_calcntr = 0x9;
7893 } else if (vco <= 6200000) {
7894 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7895 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7896 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7897 tribuf_calcntr = 0x9;
7898 } else if (vco <= 6480000) {
7899 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7900 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7901 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7902 tribuf_calcntr = 0x8;
7904 /* Not supported. Apply the same limits as in the max case */
7905 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7906 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7907 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7910 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7912 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
7913 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7914 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7915 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7918 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7919 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7922 vlv_dpio_put(dev_priv);
7926 * vlv_force_pll_on - forcibly enable just the PLL
7927 * @dev_priv: i915 private structure
7928 * @pipe: pipe PLL to enable
7929 * @dpll: PLL configuration
7931 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7932 * in cases where we need the PLL enabled even when @pipe is not going to
7935 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
7936 const struct dpll *dpll)
7938 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
7939 struct intel_crtc_state *pipe_config;
7941 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7945 pipe_config->base.crtc = &crtc->base;
7946 pipe_config->pixel_multiplier = 1;
7947 pipe_config->dpll = *dpll;
7949 if (IS_CHERRYVIEW(dev_priv)) {
7950 chv_compute_dpll(crtc, pipe_config);
7951 chv_prepare_pll(crtc, pipe_config);
7952 chv_enable_pll(crtc, pipe_config);
7954 vlv_compute_dpll(crtc, pipe_config);
7955 vlv_prepare_pll(crtc, pipe_config);
7956 vlv_enable_pll(crtc, pipe_config);
7965 * vlv_force_pll_off - forcibly disable just the PLL
7966 * @dev_priv: i915 private structure
7967 * @pipe: pipe PLL to disable
7969 * Disable the PLL for @pipe. To be used in cases where we need
7970 * the PLL enabled even when @pipe is not going to be enabled.
7972 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
7974 if (IS_CHERRYVIEW(dev_priv))
7975 chv_disable_pll(dev_priv, pipe);
7977 vlv_disable_pll(dev_priv, pipe);
7980 static void i9xx_compute_dpll(struct intel_crtc *crtc,
7981 struct intel_crtc_state *crtc_state,
7982 struct dpll *reduced_clock)
7984 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7986 struct dpll *clock = &crtc_state->dpll;
7988 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7990 dpll = DPLL_VGA_MODE_DIS;
7992 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
7993 dpll |= DPLLB_MODE_LVDS;
7995 dpll |= DPLLB_MODE_DAC_SERIAL;
7997 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7998 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7999 dpll |= (crtc_state->pixel_multiplier - 1)
8000 << SDVO_MULTIPLIER_SHIFT_HIRES;
8003 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8004 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8005 dpll |= DPLL_SDVO_HIGH_SPEED;
8007 if (intel_crtc_has_dp_encoder(crtc_state))
8008 dpll |= DPLL_SDVO_HIGH_SPEED;
8010 /* compute bitmask from p1 value */
8011 if (IS_PINEVIEW(dev_priv))
8012 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
8014 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8015 if (IS_G4X(dev_priv) && reduced_clock)
8016 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8018 switch (clock->p2) {
8020 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8023 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8026 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8029 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8032 if (INTEL_GEN(dev_priv) >= 4)
8033 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
8035 if (crtc_state->sdvo_tv_clock)
8036 dpll |= PLL_REF_INPUT_TVCLKINBC;
8037 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8038 intel_panel_use_ssc(dev_priv))
8039 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8041 dpll |= PLL_REF_INPUT_DREFCLK;
8043 dpll |= DPLL_VCO_ENABLE;
8044 crtc_state->dpll_hw_state.dpll = dpll;
8046 if (INTEL_GEN(dev_priv) >= 4) {
8047 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
8048 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8049 crtc_state->dpll_hw_state.dpll_md = dpll_md;
8053 static void i8xx_compute_dpll(struct intel_crtc *crtc,
8054 struct intel_crtc_state *crtc_state,
8055 struct dpll *reduced_clock)
8057 struct drm_device *dev = crtc->base.dev;
8058 struct drm_i915_private *dev_priv = to_i915(dev);
8060 struct dpll *clock = &crtc_state->dpll;
8062 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
8064 dpll = DPLL_VGA_MODE_DIS;
8066 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8067 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8070 dpll |= PLL_P1_DIVIDE_BY_TWO;
8072 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8074 dpll |= PLL_P2_DIVIDE_BY_4;
8079 * "[Almador Errata}: For the correct operation of the muxed DVO pins
8080 * (GDEVSELB/I2Cdata, GIRDBY/I2CClk) and (GFRAMEB/DVI_Data,
8081 * GTRDYB/DVI_Clk): Bit 31 (DPLL VCO Enable) and Bit 30 (2X Clock
8082 * Enable) must be set to “1” in both the DPLL A Control Register
8083 * (06014h-06017h) and DPLL B Control Register (06018h-0601Bh)."
8085 * For simplicity We simply keep both bits always enabled in
8086 * both DPLLS. The spec says we should disable the DVO 2X clock
8087 * when not needed, but this seems to work fine in practice.
8089 if (IS_I830(dev_priv) ||
8090 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
8091 dpll |= DPLL_DVO_2X_MODE;
8093 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8094 intel_panel_use_ssc(dev_priv))
8095 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8097 dpll |= PLL_REF_INPUT_DREFCLK;
8099 dpll |= DPLL_VCO_ENABLE;
8100 crtc_state->dpll_hw_state.dpll = dpll;
8103 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
8105 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8106 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8107 enum pipe pipe = crtc->pipe;
8108 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8109 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
8110 u32 crtc_vtotal, crtc_vblank_end;
8113 /* We need to be careful not to changed the adjusted mode, for otherwise
8114 * the hw state checker will get angry at the mismatch. */
8115 crtc_vtotal = adjusted_mode->crtc_vtotal;
8116 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
8118 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
8119 /* the chip adds 2 halflines automatically */
8121 crtc_vblank_end -= 1;
8123 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8124 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
8126 vsyncshift = adjusted_mode->crtc_hsync_start -
8127 adjusted_mode->crtc_htotal / 2;
8129 vsyncshift += adjusted_mode->crtc_htotal;
8132 if (INTEL_GEN(dev_priv) > 3)
8133 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
8135 I915_WRITE(HTOTAL(cpu_transcoder),
8136 (adjusted_mode->crtc_hdisplay - 1) |
8137 ((adjusted_mode->crtc_htotal - 1) << 16));
8138 I915_WRITE(HBLANK(cpu_transcoder),
8139 (adjusted_mode->crtc_hblank_start - 1) |
8140 ((adjusted_mode->crtc_hblank_end - 1) << 16));
8141 I915_WRITE(HSYNC(cpu_transcoder),
8142 (adjusted_mode->crtc_hsync_start - 1) |
8143 ((adjusted_mode->crtc_hsync_end - 1) << 16));
8145 I915_WRITE(VTOTAL(cpu_transcoder),
8146 (adjusted_mode->crtc_vdisplay - 1) |
8147 ((crtc_vtotal - 1) << 16));
8148 I915_WRITE(VBLANK(cpu_transcoder),
8149 (adjusted_mode->crtc_vblank_start - 1) |
8150 ((crtc_vblank_end - 1) << 16));
8151 I915_WRITE(VSYNC(cpu_transcoder),
8152 (adjusted_mode->crtc_vsync_start - 1) |
8153 ((adjusted_mode->crtc_vsync_end - 1) << 16));
8155 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
8156 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
8157 * documented on the DDI_FUNC_CTL register description, EDP Input Select
8159 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
8160 (pipe == PIPE_B || pipe == PIPE_C))
8161 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
8165 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
8167 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8168 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8169 enum pipe pipe = crtc->pipe;
8171 /* pipesrc controls the size that is scaled from, which should
8172 * always be the user's requested size.
8174 I915_WRITE(PIPESRC(pipe),
8175 ((crtc_state->pipe_src_w - 1) << 16) |
8176 (crtc_state->pipe_src_h - 1));
8179 static void intel_get_pipe_timings(struct intel_crtc *crtc,
8180 struct intel_crtc_state *pipe_config)
8182 struct drm_device *dev = crtc->base.dev;
8183 struct drm_i915_private *dev_priv = to_i915(dev);
8184 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
8187 tmp = I915_READ(HTOTAL(cpu_transcoder));
8188 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
8189 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
8191 if (!transcoder_is_dsi(cpu_transcoder)) {
8192 tmp = I915_READ(HBLANK(cpu_transcoder));
8193 pipe_config->base.adjusted_mode.crtc_hblank_start =
8195 pipe_config->base.adjusted_mode.crtc_hblank_end =
8196 ((tmp >> 16) & 0xffff) + 1;
8198 tmp = I915_READ(HSYNC(cpu_transcoder));
8199 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
8200 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
8202 tmp = I915_READ(VTOTAL(cpu_transcoder));
8203 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
8204 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
8206 if (!transcoder_is_dsi(cpu_transcoder)) {
8207 tmp = I915_READ(VBLANK(cpu_transcoder));
8208 pipe_config->base.adjusted_mode.crtc_vblank_start =
8210 pipe_config->base.adjusted_mode.crtc_vblank_end =
8211 ((tmp >> 16) & 0xffff) + 1;
8213 tmp = I915_READ(VSYNC(cpu_transcoder));
8214 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
8215 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
8217 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
8218 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
8219 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
8220 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
8224 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
8225 struct intel_crtc_state *pipe_config)
8227 struct drm_device *dev = crtc->base.dev;
8228 struct drm_i915_private *dev_priv = to_i915(dev);
8231 tmp = I915_READ(PIPESRC(crtc->pipe));
8232 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
8233 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
8235 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
8236 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
8239 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
8240 struct intel_crtc_state *pipe_config)
8242 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
8243 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
8244 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
8245 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
8247 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
8248 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
8249 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
8250 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
8252 mode->flags = pipe_config->base.adjusted_mode.flags;
8253 mode->type = DRM_MODE_TYPE_DRIVER;
8255 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
8257 mode->hsync = drm_mode_hsync(mode);
8258 mode->vrefresh = drm_mode_vrefresh(mode);
8259 drm_mode_set_name(mode);
8262 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
8264 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8265 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8270 /* we keep both pipes enabled on 830 */
8271 if (IS_I830(dev_priv))
8272 pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
8274 if (crtc_state->double_wide)
8275 pipeconf |= PIPECONF_DOUBLE_WIDE;
8277 /* only g4x and later have fancy bpc/dither controls */
8278 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8279 IS_CHERRYVIEW(dev_priv)) {
8280 /* Bspec claims that we can't use dithering for 30bpp pipes. */
8281 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
8282 pipeconf |= PIPECONF_DITHER_EN |
8283 PIPECONF_DITHER_TYPE_SP;
8285 switch (crtc_state->pipe_bpp) {
8287 pipeconf |= PIPECONF_6BPC;
8290 pipeconf |= PIPECONF_8BPC;
8293 pipeconf |= PIPECONF_10BPC;
8296 /* Case prevented by intel_choose_pipe_bpp_dither. */
8301 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
8302 if (INTEL_GEN(dev_priv) < 4 ||
8303 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8304 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
8306 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
8308 pipeconf |= PIPECONF_PROGRESSIVE;
8311 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
8312 crtc_state->limited_color_range)
8313 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
8315 pipeconf |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
8317 I915_WRITE(PIPECONF(crtc->pipe), pipeconf);
8318 POSTING_READ(PIPECONF(crtc->pipe));
8321 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
8322 struct intel_crtc_state *crtc_state)
8324 struct drm_device *dev = crtc->base.dev;
8325 struct drm_i915_private *dev_priv = to_i915(dev);
8326 const struct intel_limit *limit;
8329 memset(&crtc_state->dpll_hw_state, 0,
8330 sizeof(crtc_state->dpll_hw_state));
8332 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8333 if (intel_panel_use_ssc(dev_priv)) {
8334 refclk = dev_priv->vbt.lvds_ssc_freq;
8335 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8338 limit = &intel_limits_i8xx_lvds;
8339 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
8340 limit = &intel_limits_i8xx_dvo;
8342 limit = &intel_limits_i8xx_dac;
8345 if (!crtc_state->clock_set &&
8346 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8347 refclk, NULL, &crtc_state->dpll)) {
8348 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8352 i8xx_compute_dpll(crtc, crtc_state, NULL);
8357 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
8358 struct intel_crtc_state *crtc_state)
8360 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8361 const struct intel_limit *limit;
8364 memset(&crtc_state->dpll_hw_state, 0,
8365 sizeof(crtc_state->dpll_hw_state));
8367 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8368 if (intel_panel_use_ssc(dev_priv)) {
8369 refclk = dev_priv->vbt.lvds_ssc_freq;
8370 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8373 if (intel_is_dual_link_lvds(dev_priv))
8374 limit = &intel_limits_g4x_dual_channel_lvds;
8376 limit = &intel_limits_g4x_single_channel_lvds;
8377 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
8378 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
8379 limit = &intel_limits_g4x_hdmi;
8380 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
8381 limit = &intel_limits_g4x_sdvo;
8383 /* The option is for other outputs */
8384 limit = &intel_limits_i9xx_sdvo;
8387 if (!crtc_state->clock_set &&
8388 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8389 refclk, NULL, &crtc_state->dpll)) {
8390 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8394 i9xx_compute_dpll(crtc, crtc_state, NULL);
8399 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
8400 struct intel_crtc_state *crtc_state)
8402 struct drm_device *dev = crtc->base.dev;
8403 struct drm_i915_private *dev_priv = to_i915(dev);
8404 const struct intel_limit *limit;
8407 memset(&crtc_state->dpll_hw_state, 0,
8408 sizeof(crtc_state->dpll_hw_state));
8410 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8411 if (intel_panel_use_ssc(dev_priv)) {
8412 refclk = dev_priv->vbt.lvds_ssc_freq;
8413 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8416 limit = &intel_limits_pineview_lvds;
8418 limit = &intel_limits_pineview_sdvo;
8421 if (!crtc_state->clock_set &&
8422 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8423 refclk, NULL, &crtc_state->dpll)) {
8424 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8428 i9xx_compute_dpll(crtc, crtc_state, NULL);
8433 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
8434 struct intel_crtc_state *crtc_state)
8436 struct drm_device *dev = crtc->base.dev;
8437 struct drm_i915_private *dev_priv = to_i915(dev);
8438 const struct intel_limit *limit;
8441 memset(&crtc_state->dpll_hw_state, 0,
8442 sizeof(crtc_state->dpll_hw_state));
8444 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8445 if (intel_panel_use_ssc(dev_priv)) {
8446 refclk = dev_priv->vbt.lvds_ssc_freq;
8447 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8450 limit = &intel_limits_i9xx_lvds;
8452 limit = &intel_limits_i9xx_sdvo;
8455 if (!crtc_state->clock_set &&
8456 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8457 refclk, NULL, &crtc_state->dpll)) {
8458 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8462 i9xx_compute_dpll(crtc, crtc_state, NULL);
8467 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
8468 struct intel_crtc_state *crtc_state)
8470 int refclk = 100000;
8471 const struct intel_limit *limit = &intel_limits_chv;
8473 memset(&crtc_state->dpll_hw_state, 0,
8474 sizeof(crtc_state->dpll_hw_state));
8476 if (!crtc_state->clock_set &&
8477 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8478 refclk, NULL, &crtc_state->dpll)) {
8479 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8483 chv_compute_dpll(crtc, crtc_state);
8488 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
8489 struct intel_crtc_state *crtc_state)
8491 int refclk = 100000;
8492 const struct intel_limit *limit = &intel_limits_vlv;
8494 memset(&crtc_state->dpll_hw_state, 0,
8495 sizeof(crtc_state->dpll_hw_state));
8497 if (!crtc_state->clock_set &&
8498 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8499 refclk, NULL, &crtc_state->dpll)) {
8500 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8504 vlv_compute_dpll(crtc, crtc_state);
8509 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
8511 if (IS_I830(dev_priv))
8514 return INTEL_GEN(dev_priv) >= 4 ||
8515 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
8518 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
8519 struct intel_crtc_state *pipe_config)
8521 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8524 if (!i9xx_has_pfit(dev_priv))
8527 tmp = I915_READ(PFIT_CONTROL);
8528 if (!(tmp & PFIT_ENABLE))
8531 /* Check whether the pfit is attached to our pipe. */
8532 if (INTEL_GEN(dev_priv) < 4) {
8533 if (crtc->pipe != PIPE_B)
8536 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
8540 pipe_config->gmch_pfit.control = tmp;
8541 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
8544 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
8545 struct intel_crtc_state *pipe_config)
8547 struct drm_device *dev = crtc->base.dev;
8548 struct drm_i915_private *dev_priv = to_i915(dev);
8549 int pipe = pipe_config->cpu_transcoder;
8552 int refclk = 100000;
8554 /* In case of DSI, DPLL will not be used */
8555 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8558 vlv_dpio_get(dev_priv);
8559 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
8560 vlv_dpio_put(dev_priv);
8562 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
8563 clock.m2 = mdiv & DPIO_M2DIV_MASK;
8564 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
8565 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
8566 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
8568 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
8572 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
8573 struct intel_initial_plane_config *plane_config)
8575 struct drm_device *dev = crtc->base.dev;
8576 struct drm_i915_private *dev_priv = to_i915(dev);
8577 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8578 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
8580 u32 val, base, offset;
8581 int fourcc, pixel_format;
8582 unsigned int aligned_height;
8583 struct drm_framebuffer *fb;
8584 struct intel_framebuffer *intel_fb;
8586 if (!plane->get_hw_state(plane, &pipe))
8589 WARN_ON(pipe != crtc->pipe);
8591 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8593 DRM_DEBUG_KMS("failed to alloc fb\n");
8597 fb = &intel_fb->base;
8601 val = I915_READ(DSPCNTR(i9xx_plane));
8603 if (INTEL_GEN(dev_priv) >= 4) {
8604 if (val & DISPPLANE_TILED) {
8605 plane_config->tiling = I915_TILING_X;
8606 fb->modifier = I915_FORMAT_MOD_X_TILED;
8609 if (val & DISPPLANE_ROTATE_180)
8610 plane_config->rotation = DRM_MODE_ROTATE_180;
8613 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
8614 val & DISPPLANE_MIRROR)
8615 plane_config->rotation |= DRM_MODE_REFLECT_X;
8617 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
8618 fourcc = i9xx_format_to_fourcc(pixel_format);
8619 fb->format = drm_format_info(fourcc);
8621 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
8622 offset = I915_READ(DSPOFFSET(i9xx_plane));
8623 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8624 } else if (INTEL_GEN(dev_priv) >= 4) {
8625 if (plane_config->tiling)
8626 offset = I915_READ(DSPTILEOFF(i9xx_plane));
8628 offset = I915_READ(DSPLINOFF(i9xx_plane));
8629 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8631 base = I915_READ(DSPADDR(i9xx_plane));
8633 plane_config->base = base;
8635 val = I915_READ(PIPESRC(pipe));
8636 fb->width = ((val >> 16) & 0xfff) + 1;
8637 fb->height = ((val >> 0) & 0xfff) + 1;
8639 val = I915_READ(DSPSTRIDE(i9xx_plane));
8640 fb->pitches[0] = val & 0xffffffc0;
8642 aligned_height = intel_fb_align_height(fb, 0, fb->height);
8644 plane_config->size = fb->pitches[0] * aligned_height;
8646 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8647 crtc->base.name, plane->base.name, fb->width, fb->height,
8648 fb->format->cpp[0] * 8, base, fb->pitches[0],
8649 plane_config->size);
8651 plane_config->fb = intel_fb;
8654 static void chv_crtc_clock_get(struct intel_crtc *crtc,
8655 struct intel_crtc_state *pipe_config)
8657 struct drm_device *dev = crtc->base.dev;
8658 struct drm_i915_private *dev_priv = to_i915(dev);
8659 int pipe = pipe_config->cpu_transcoder;
8660 enum dpio_channel port = vlv_pipe_to_channel(pipe);
8662 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
8663 int refclk = 100000;
8665 /* In case of DSI, DPLL will not be used */
8666 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8669 vlv_dpio_get(dev_priv);
8670 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
8671 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
8672 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
8673 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
8674 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
8675 vlv_dpio_put(dev_priv);
8677 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
8678 clock.m2 = (pll_dw0 & 0xff) << 22;
8679 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
8680 clock.m2 |= pll_dw2 & 0x3fffff;
8681 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
8682 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
8683 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
8685 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
8688 static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc,
8689 struct intel_crtc_state *pipe_config)
8691 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8692 enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB;
8694 pipe_config->lspcon_downsampling = false;
8696 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
8697 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
8699 if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
8700 bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE;
8701 bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND;
8703 if (ycbcr420_enabled) {
8704 /* We support 4:2:0 in full blend mode only */
8706 output = INTEL_OUTPUT_FORMAT_INVALID;
8707 else if (!(IS_GEMINILAKE(dev_priv) ||
8708 INTEL_GEN(dev_priv) >= 10))
8709 output = INTEL_OUTPUT_FORMAT_INVALID;
8711 output = INTEL_OUTPUT_FORMAT_YCBCR420;
8714 * Currently there is no interface defined to
8715 * check user preference between RGB/YCBCR444
8716 * or YCBCR420. So the only possible case for
8717 * YCBCR444 usage is driving YCBCR420 output
8718 * with LSPCON, when pipe is configured for
8719 * YCBCR444 output and LSPCON takes care of
8722 pipe_config->lspcon_downsampling = true;
8723 output = INTEL_OUTPUT_FORMAT_YCBCR444;
8728 pipe_config->output_format = output;
8731 static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state)
8733 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8734 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8735 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8736 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
8739 tmp = I915_READ(DSPCNTR(i9xx_plane));
8741 if (tmp & DISPPLANE_GAMMA_ENABLE)
8742 crtc_state->gamma_enable = true;
8744 if (!HAS_GMCH(dev_priv) &&
8745 tmp & DISPPLANE_PIPE_CSC_ENABLE)
8746 crtc_state->csc_enable = true;
8749 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
8750 struct intel_crtc_state *pipe_config)
8752 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8753 enum intel_display_power_domain power_domain;
8754 intel_wakeref_t wakeref;
8758 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
8759 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
8763 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
8764 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
8765 pipe_config->shared_dpll = NULL;
8769 tmp = I915_READ(PIPECONF(crtc->pipe));
8770 if (!(tmp & PIPECONF_ENABLE))
8773 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8774 IS_CHERRYVIEW(dev_priv)) {
8775 switch (tmp & PIPECONF_BPC_MASK) {
8777 pipe_config->pipe_bpp = 18;
8780 pipe_config->pipe_bpp = 24;
8782 case PIPECONF_10BPC:
8783 pipe_config->pipe_bpp = 30;
8790 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
8791 (tmp & PIPECONF_COLOR_RANGE_SELECT))
8792 pipe_config->limited_color_range = true;
8794 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_I9XX) >>
8795 PIPECONF_GAMMA_MODE_SHIFT;
8797 if (IS_CHERRYVIEW(dev_priv))
8798 pipe_config->cgm_mode = I915_READ(CGM_PIPE_MODE(crtc->pipe));
8800 i9xx_get_pipe_color_config(pipe_config);
8801 intel_color_get_config(pipe_config);
8803 if (INTEL_GEN(dev_priv) < 4)
8804 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
8806 intel_get_pipe_timings(crtc, pipe_config);
8807 intel_get_pipe_src_size(crtc, pipe_config);
8809 i9xx_get_pfit_config(crtc, pipe_config);
8811 if (INTEL_GEN(dev_priv) >= 4) {
8812 /* No way to read it out on pipes B and C */
8813 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
8814 tmp = dev_priv->chv_dpll_md[crtc->pipe];
8816 tmp = I915_READ(DPLL_MD(crtc->pipe));
8817 pipe_config->pixel_multiplier =
8818 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
8819 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
8820 pipe_config->dpll_hw_state.dpll_md = tmp;
8821 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
8822 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
8823 tmp = I915_READ(DPLL(crtc->pipe));
8824 pipe_config->pixel_multiplier =
8825 ((tmp & SDVO_MULTIPLIER_MASK)
8826 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
8828 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8829 * port and will be fixed up in the encoder->get_config
8831 pipe_config->pixel_multiplier = 1;
8833 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
8834 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
8835 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
8836 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
8838 /* Mask out read-only status bits. */
8839 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
8840 DPLL_PORTC_READY_MASK |
8841 DPLL_PORTB_READY_MASK);
8844 if (IS_CHERRYVIEW(dev_priv))
8845 chv_crtc_clock_get(crtc, pipe_config);
8846 else if (IS_VALLEYVIEW(dev_priv))
8847 vlv_crtc_clock_get(crtc, pipe_config);
8849 i9xx_crtc_clock_get(crtc, pipe_config);
8852 * Normally the dotclock is filled in by the encoder .get_config()
8853 * but in case the pipe is enabled w/o any ports we need a sane
8856 pipe_config->base.adjusted_mode.crtc_clock =
8857 pipe_config->port_clock / pipe_config->pixel_multiplier;
8862 intel_display_power_put(dev_priv, power_domain, wakeref);
8867 static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
8869 struct intel_encoder *encoder;
8872 bool has_lvds = false;
8873 bool has_cpu_edp = false;
8874 bool has_panel = false;
8875 bool has_ck505 = false;
8876 bool can_ssc = false;
8877 bool using_ssc_source = false;
8879 /* We need to take the global config into account */
8880 for_each_intel_encoder(&dev_priv->drm, encoder) {
8881 switch (encoder->type) {
8882 case INTEL_OUTPUT_LVDS:
8886 case INTEL_OUTPUT_EDP:
8888 if (encoder->port == PORT_A)
8896 if (HAS_PCH_IBX(dev_priv)) {
8897 has_ck505 = dev_priv->vbt.display_clock_mode;
8898 can_ssc = has_ck505;
8904 /* Check if any DPLLs are using the SSC source */
8905 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
8906 u32 temp = I915_READ(PCH_DPLL(i));
8908 if (!(temp & DPLL_VCO_ENABLE))
8911 if ((temp & PLL_REF_INPUT_MASK) ==
8912 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
8913 using_ssc_source = true;
8918 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
8919 has_panel, has_lvds, has_ck505, using_ssc_source);
8921 /* Ironlake: try to setup display ref clock before DPLL
8922 * enabling. This is only under driver's control after
8923 * PCH B stepping, previous chipset stepping should be
8924 * ignoring this setting.
8926 val = I915_READ(PCH_DREF_CONTROL);
8928 /* As we must carefully and slowly disable/enable each source in turn,
8929 * compute the final state we want first and check if we need to
8930 * make any changes at all.
8933 final &= ~DREF_NONSPREAD_SOURCE_MASK;
8935 final |= DREF_NONSPREAD_CK505_ENABLE;
8937 final |= DREF_NONSPREAD_SOURCE_ENABLE;
8939 final &= ~DREF_SSC_SOURCE_MASK;
8940 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8941 final &= ~DREF_SSC1_ENABLE;
8944 final |= DREF_SSC_SOURCE_ENABLE;
8946 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8947 final |= DREF_SSC1_ENABLE;
8950 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8951 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8953 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8955 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8956 } else if (using_ssc_source) {
8957 final |= DREF_SSC_SOURCE_ENABLE;
8958 final |= DREF_SSC1_ENABLE;
8964 /* Always enable nonspread source */
8965 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8968 val |= DREF_NONSPREAD_CK505_ENABLE;
8970 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8973 val &= ~DREF_SSC_SOURCE_MASK;
8974 val |= DREF_SSC_SOURCE_ENABLE;
8976 /* SSC must be turned on before enabling the CPU output */
8977 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8978 DRM_DEBUG_KMS("Using SSC on panel\n");
8979 val |= DREF_SSC1_ENABLE;
8981 val &= ~DREF_SSC1_ENABLE;
8983 /* Get SSC going before enabling the outputs */
8984 I915_WRITE(PCH_DREF_CONTROL, val);
8985 POSTING_READ(PCH_DREF_CONTROL);
8988 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8990 /* Enable CPU source on CPU attached eDP */
8992 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8993 DRM_DEBUG_KMS("Using SSC on eDP\n");
8994 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8996 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8998 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9000 I915_WRITE(PCH_DREF_CONTROL, val);
9001 POSTING_READ(PCH_DREF_CONTROL);
9004 DRM_DEBUG_KMS("Disabling CPU source output\n");
9006 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9008 /* Turn off CPU output */
9009 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9011 I915_WRITE(PCH_DREF_CONTROL, val);
9012 POSTING_READ(PCH_DREF_CONTROL);
9015 if (!using_ssc_source) {
9016 DRM_DEBUG_KMS("Disabling SSC source\n");
9018 /* Turn off the SSC source */
9019 val &= ~DREF_SSC_SOURCE_MASK;
9020 val |= DREF_SSC_SOURCE_DISABLE;
9023 val &= ~DREF_SSC1_ENABLE;
9025 I915_WRITE(PCH_DREF_CONTROL, val);
9026 POSTING_READ(PCH_DREF_CONTROL);
9031 BUG_ON(val != final);
9034 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
9038 tmp = I915_READ(SOUTH_CHICKEN2);
9039 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
9040 I915_WRITE(SOUTH_CHICKEN2, tmp);
9042 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
9043 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
9044 DRM_ERROR("FDI mPHY reset assert timeout\n");
9046 tmp = I915_READ(SOUTH_CHICKEN2);
9047 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
9048 I915_WRITE(SOUTH_CHICKEN2, tmp);
9050 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
9051 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
9052 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
9055 /* WaMPhyProgramming:hsw */
9056 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
9060 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
9061 tmp &= ~(0xFF << 24);
9062 tmp |= (0x12 << 24);
9063 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
9065 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
9067 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
9069 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
9071 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
9073 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
9074 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9075 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
9077 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
9078 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9079 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
9081 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
9084 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
9086 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
9089 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
9091 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
9094 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
9096 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
9099 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
9101 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
9102 tmp &= ~(0xFF << 16);
9103 tmp |= (0x1C << 16);
9104 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
9106 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
9107 tmp &= ~(0xFF << 16);
9108 tmp |= (0x1C << 16);
9109 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
9111 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
9113 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
9115 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
9117 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
9119 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
9120 tmp &= ~(0xF << 28);
9122 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
9124 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
9125 tmp &= ~(0xF << 28);
9127 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
9130 /* Implements 3 different sequences from BSpec chapter "Display iCLK
9131 * Programming" based on the parameters passed:
9132 * - Sequence to enable CLKOUT_DP
9133 * - Sequence to enable CLKOUT_DP without spread
9134 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
9136 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
9137 bool with_spread, bool with_fdi)
9141 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
9143 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
9144 with_fdi, "LP PCH doesn't have FDI\n"))
9147 mutex_lock(&dev_priv->sb_lock);
9149 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9150 tmp &= ~SBI_SSCCTL_DISABLE;
9151 tmp |= SBI_SSCCTL_PATHALT;
9152 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9157 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9158 tmp &= ~SBI_SSCCTL_PATHALT;
9159 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9162 lpt_reset_fdi_mphy(dev_priv);
9163 lpt_program_fdi_mphy(dev_priv);
9167 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9168 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9169 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9170 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9172 mutex_unlock(&dev_priv->sb_lock);
9175 /* Sequence to disable CLKOUT_DP */
9176 void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
9180 mutex_lock(&dev_priv->sb_lock);
9182 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9183 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9184 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9185 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9187 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9188 if (!(tmp & SBI_SSCCTL_DISABLE)) {
9189 if (!(tmp & SBI_SSCCTL_PATHALT)) {
9190 tmp |= SBI_SSCCTL_PATHALT;
9191 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9194 tmp |= SBI_SSCCTL_DISABLE;
9195 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9198 mutex_unlock(&dev_priv->sb_lock);
9201 #define BEND_IDX(steps) ((50 + (steps)) / 5)
9203 static const u16 sscdivintphase[] = {
9204 [BEND_IDX( 50)] = 0x3B23,
9205 [BEND_IDX( 45)] = 0x3B23,
9206 [BEND_IDX( 40)] = 0x3C23,
9207 [BEND_IDX( 35)] = 0x3C23,
9208 [BEND_IDX( 30)] = 0x3D23,
9209 [BEND_IDX( 25)] = 0x3D23,
9210 [BEND_IDX( 20)] = 0x3E23,
9211 [BEND_IDX( 15)] = 0x3E23,
9212 [BEND_IDX( 10)] = 0x3F23,
9213 [BEND_IDX( 5)] = 0x3F23,
9214 [BEND_IDX( 0)] = 0x0025,
9215 [BEND_IDX( -5)] = 0x0025,
9216 [BEND_IDX(-10)] = 0x0125,
9217 [BEND_IDX(-15)] = 0x0125,
9218 [BEND_IDX(-20)] = 0x0225,
9219 [BEND_IDX(-25)] = 0x0225,
9220 [BEND_IDX(-30)] = 0x0325,
9221 [BEND_IDX(-35)] = 0x0325,
9222 [BEND_IDX(-40)] = 0x0425,
9223 [BEND_IDX(-45)] = 0x0425,
9224 [BEND_IDX(-50)] = 0x0525,
9229 * steps -50 to 50 inclusive, in steps of 5
9230 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
9231 * change in clock period = -(steps / 10) * 5.787 ps
9233 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
9236 int idx = BEND_IDX(steps);
9238 if (WARN_ON(steps % 5 != 0))
9241 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
9244 mutex_lock(&dev_priv->sb_lock);
9246 if (steps % 10 != 0)
9250 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
9252 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
9254 tmp |= sscdivintphase[idx];
9255 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
9257 mutex_unlock(&dev_priv->sb_lock);
9262 static bool spll_uses_pch_ssc(struct drm_i915_private *dev_priv)
9264 u32 fuse_strap = I915_READ(FUSE_STRAP);
9265 u32 ctl = I915_READ(SPLL_CTL);
9267 if ((ctl & SPLL_PLL_ENABLE) == 0)
9270 if ((ctl & SPLL_REF_MASK) == SPLL_REF_MUXED_SSC &&
9271 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9274 if (IS_BROADWELL(dev_priv) &&
9275 (ctl & SPLL_REF_MASK) == SPLL_REF_PCH_SSC_BDW)
9281 static bool wrpll_uses_pch_ssc(struct drm_i915_private *dev_priv,
9282 enum intel_dpll_id id)
9284 u32 fuse_strap = I915_READ(FUSE_STRAP);
9285 u32 ctl = I915_READ(WRPLL_CTL(id));
9287 if ((ctl & WRPLL_PLL_ENABLE) == 0)
9290 if ((ctl & WRPLL_REF_MASK) == WRPLL_REF_PCH_SSC)
9293 if ((IS_BROADWELL(dev_priv) || IS_HSW_ULT(dev_priv)) &&
9294 (ctl & WRPLL_REF_MASK) == WRPLL_REF_MUXED_SSC_BDW &&
9295 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9301 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
9303 struct intel_encoder *encoder;
9304 bool pch_ssc_in_use = false;
9305 bool has_fdi = false;
9307 for_each_intel_encoder(&dev_priv->drm, encoder) {
9308 switch (encoder->type) {
9309 case INTEL_OUTPUT_ANALOG:
9318 * The BIOS may have decided to use the PCH SSC
9319 * reference so we must not disable it until the
9320 * relevant PLLs have stopped relying on it. We'll
9321 * just leave the PCH SSC reference enabled in case
9322 * any active PLL is using it. It will get disabled
9323 * after runtime suspend if we don't have FDI.
9325 * TODO: Move the whole reference clock handling
9326 * to the modeset sequence proper so that we can
9327 * actually enable/disable/reconfigure these things
9328 * safely. To do that we need to introduce a real
9329 * clock hierarchy. That would also allow us to do
9330 * clock bending finally.
9332 if (spll_uses_pch_ssc(dev_priv)) {
9333 DRM_DEBUG_KMS("SPLL using PCH SSC\n");
9334 pch_ssc_in_use = true;
9337 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL1)) {
9338 DRM_DEBUG_KMS("WRPLL1 using PCH SSC\n");
9339 pch_ssc_in_use = true;
9342 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL2)) {
9343 DRM_DEBUG_KMS("WRPLL2 using PCH SSC\n");
9344 pch_ssc_in_use = true;
9351 lpt_bend_clkout_dp(dev_priv, 0);
9352 lpt_enable_clkout_dp(dev_priv, true, true);
9354 lpt_disable_clkout_dp(dev_priv);
9359 * Initialize reference clocks when the driver loads
9361 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
9363 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
9364 ironlake_init_pch_refclk(dev_priv);
9365 else if (HAS_PCH_LPT(dev_priv))
9366 lpt_init_pch_refclk(dev_priv);
9369 static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
9371 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9372 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9373 enum pipe pipe = crtc->pipe;
9378 switch (crtc_state->pipe_bpp) {
9380 val |= PIPECONF_6BPC;
9383 val |= PIPECONF_8BPC;
9386 val |= PIPECONF_10BPC;
9389 val |= PIPECONF_12BPC;
9392 /* Case prevented by intel_choose_pipe_bpp_dither. */
9396 if (crtc_state->dither)
9397 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
9399 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
9400 val |= PIPECONF_INTERLACED_ILK;
9402 val |= PIPECONF_PROGRESSIVE;
9404 if (crtc_state->limited_color_range)
9405 val |= PIPECONF_COLOR_RANGE_SELECT;
9407 val |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
9409 I915_WRITE(PIPECONF(pipe), val);
9410 POSTING_READ(PIPECONF(pipe));
9413 static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state)
9415 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9416 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9417 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
9420 if (IS_HASWELL(dev_priv) && crtc_state->dither)
9421 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
9423 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
9424 val |= PIPECONF_INTERLACED_ILK;
9426 val |= PIPECONF_PROGRESSIVE;
9428 I915_WRITE(PIPECONF(cpu_transcoder), val);
9429 POSTING_READ(PIPECONF(cpu_transcoder));
9432 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state)
9434 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9435 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9438 switch (crtc_state->pipe_bpp) {
9440 val |= PIPEMISC_DITHER_6_BPC;
9443 val |= PIPEMISC_DITHER_8_BPC;
9446 val |= PIPEMISC_DITHER_10_BPC;
9449 val |= PIPEMISC_DITHER_12_BPC;
9452 MISSING_CASE(crtc_state->pipe_bpp);
9456 if (crtc_state->dither)
9457 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
9459 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
9460 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
9461 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
9463 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
9464 val |= PIPEMISC_YUV420_ENABLE |
9465 PIPEMISC_YUV420_MODE_FULL_BLEND;
9467 if (INTEL_GEN(dev_priv) >= 11 &&
9468 (crtc_state->active_planes & ~(icl_hdr_plane_mask() |
9469 BIT(PLANE_CURSOR))) == 0)
9470 val |= PIPEMISC_HDR_MODE_PRECISION;
9472 I915_WRITE(PIPEMISC(crtc->pipe), val);
9475 int bdw_get_pipemisc_bpp(struct intel_crtc *crtc)
9477 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9480 tmp = I915_READ(PIPEMISC(crtc->pipe));
9482 switch (tmp & PIPEMISC_DITHER_BPC_MASK) {
9483 case PIPEMISC_DITHER_6_BPC:
9485 case PIPEMISC_DITHER_8_BPC:
9487 case PIPEMISC_DITHER_10_BPC:
9489 case PIPEMISC_DITHER_12_BPC:
9497 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
9500 * Account for spread spectrum to avoid
9501 * oversubscribing the link. Max center spread
9502 * is 2.5%; use 5% for safety's sake.
9504 u32 bps = target_clock * bpp * 21 / 20;
9505 return DIV_ROUND_UP(bps, link_bw * 8);
9508 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
9510 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
9513 static void ironlake_compute_dpll(struct intel_crtc *crtc,
9514 struct intel_crtc_state *crtc_state,
9515 struct dpll *reduced_clock)
9517 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9521 /* Enable autotuning of the PLL clock (if permissible) */
9523 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9524 if ((intel_panel_use_ssc(dev_priv) &&
9525 dev_priv->vbt.lvds_ssc_freq == 100000) ||
9526 (HAS_PCH_IBX(dev_priv) &&
9527 intel_is_dual_link_lvds(dev_priv)))
9529 } else if (crtc_state->sdvo_tv_clock) {
9533 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
9535 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
9538 if (reduced_clock) {
9539 fp2 = i9xx_dpll_compute_fp(reduced_clock);
9541 if (reduced_clock->m < factor * reduced_clock->n)
9549 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
9550 dpll |= DPLLB_MODE_LVDS;
9552 dpll |= DPLLB_MODE_DAC_SERIAL;
9554 dpll |= (crtc_state->pixel_multiplier - 1)
9555 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
9557 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
9558 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
9559 dpll |= DPLL_SDVO_HIGH_SPEED;
9561 if (intel_crtc_has_dp_encoder(crtc_state))
9562 dpll |= DPLL_SDVO_HIGH_SPEED;
9565 * The high speed IO clock is only really required for
9566 * SDVO/HDMI/DP, but we also enable it for CRT to make it
9567 * possible to share the DPLL between CRT and HDMI. Enabling
9568 * the clock needlessly does no real harm, except use up a
9569 * bit of power potentially.
9571 * We'll limit this to IVB with 3 pipes, since it has only two
9572 * DPLLs and so DPLL sharing is the only way to get three pipes
9573 * driving PCH ports at the same time. On SNB we could do this,
9574 * and potentially avoid enabling the second DPLL, but it's not
9575 * clear if it''s a win or loss power wise. No point in doing
9576 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
9578 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
9579 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
9580 dpll |= DPLL_SDVO_HIGH_SPEED;
9582 /* compute bitmask from p1 value */
9583 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
9585 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
9587 switch (crtc_state->dpll.p2) {
9589 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
9592 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
9595 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
9598 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
9602 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
9603 intel_panel_use_ssc(dev_priv))
9604 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
9606 dpll |= PLL_REF_INPUT_DREFCLK;
9608 dpll |= DPLL_VCO_ENABLE;
9610 crtc_state->dpll_hw_state.dpll = dpll;
9611 crtc_state->dpll_hw_state.fp0 = fp;
9612 crtc_state->dpll_hw_state.fp1 = fp2;
9615 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
9616 struct intel_crtc_state *crtc_state)
9618 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9619 struct intel_atomic_state *state =
9620 to_intel_atomic_state(crtc_state->base.state);
9621 const struct intel_limit *limit;
9622 int refclk = 120000;
9624 memset(&crtc_state->dpll_hw_state, 0,
9625 sizeof(crtc_state->dpll_hw_state));
9627 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
9628 if (!crtc_state->has_pch_encoder)
9631 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9632 if (intel_panel_use_ssc(dev_priv)) {
9633 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
9634 dev_priv->vbt.lvds_ssc_freq);
9635 refclk = dev_priv->vbt.lvds_ssc_freq;
9638 if (intel_is_dual_link_lvds(dev_priv)) {
9639 if (refclk == 100000)
9640 limit = &intel_limits_ironlake_dual_lvds_100m;
9642 limit = &intel_limits_ironlake_dual_lvds;
9644 if (refclk == 100000)
9645 limit = &intel_limits_ironlake_single_lvds_100m;
9647 limit = &intel_limits_ironlake_single_lvds;
9650 limit = &intel_limits_ironlake_dac;
9653 if (!crtc_state->clock_set &&
9654 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
9655 refclk, NULL, &crtc_state->dpll)) {
9656 DRM_ERROR("Couldn't find PLL settings for mode!\n");
9660 ironlake_compute_dpll(crtc, crtc_state, NULL);
9662 if (!intel_reserve_shared_dplls(state, crtc, NULL)) {
9663 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
9664 pipe_name(crtc->pipe));
9671 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
9672 struct intel_link_m_n *m_n)
9674 struct drm_device *dev = crtc->base.dev;
9675 struct drm_i915_private *dev_priv = to_i915(dev);
9676 enum pipe pipe = crtc->pipe;
9678 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
9679 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
9680 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
9682 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
9683 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
9684 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9687 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
9688 enum transcoder transcoder,
9689 struct intel_link_m_n *m_n,
9690 struct intel_link_m_n *m2_n2)
9692 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9693 enum pipe pipe = crtc->pipe;
9695 if (INTEL_GEN(dev_priv) >= 5) {
9696 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
9697 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
9698 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
9700 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
9701 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
9702 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9704 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
9705 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
9706 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
9707 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
9709 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
9710 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
9711 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9714 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
9715 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
9716 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
9718 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
9719 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
9720 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9724 void intel_dp_get_m_n(struct intel_crtc *crtc,
9725 struct intel_crtc_state *pipe_config)
9727 if (pipe_config->has_pch_encoder)
9728 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
9730 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
9731 &pipe_config->dp_m_n,
9732 &pipe_config->dp_m2_n2);
9735 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
9736 struct intel_crtc_state *pipe_config)
9738 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
9739 &pipe_config->fdi_m_n, NULL);
9742 static void skylake_get_pfit_config(struct intel_crtc *crtc,
9743 struct intel_crtc_state *pipe_config)
9745 struct drm_device *dev = crtc->base.dev;
9746 struct drm_i915_private *dev_priv = to_i915(dev);
9747 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
9752 /* find scaler attached to this pipe */
9753 for (i = 0; i < crtc->num_scalers; i++) {
9754 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
9755 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
9757 pipe_config->pch_pfit.enabled = true;
9758 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
9759 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
9760 scaler_state->scalers[i].in_use = true;
9765 scaler_state->scaler_id = id;
9767 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
9769 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
9774 skylake_get_initial_plane_config(struct intel_crtc *crtc,
9775 struct intel_initial_plane_config *plane_config)
9777 struct drm_device *dev = crtc->base.dev;
9778 struct drm_i915_private *dev_priv = to_i915(dev);
9779 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
9780 enum plane_id plane_id = plane->id;
9782 u32 val, base, offset, stride_mult, tiling, alpha;
9783 int fourcc, pixel_format;
9784 unsigned int aligned_height;
9785 struct drm_framebuffer *fb;
9786 struct intel_framebuffer *intel_fb;
9788 if (!plane->get_hw_state(plane, &pipe))
9791 WARN_ON(pipe != crtc->pipe);
9793 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9795 DRM_DEBUG_KMS("failed to alloc fb\n");
9799 fb = &intel_fb->base;
9803 val = I915_READ(PLANE_CTL(pipe, plane_id));
9805 if (INTEL_GEN(dev_priv) >= 11)
9806 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
9808 pixel_format = val & PLANE_CTL_FORMAT_MASK;
9810 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
9811 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
9812 alpha &= PLANE_COLOR_ALPHA_MASK;
9814 alpha = val & PLANE_CTL_ALPHA_MASK;
9817 fourcc = skl_format_to_fourcc(pixel_format,
9818 val & PLANE_CTL_ORDER_RGBX, alpha);
9819 fb->format = drm_format_info(fourcc);
9821 tiling = val & PLANE_CTL_TILED_MASK;
9823 case PLANE_CTL_TILED_LINEAR:
9824 fb->modifier = DRM_FORMAT_MOD_LINEAR;
9826 case PLANE_CTL_TILED_X:
9827 plane_config->tiling = I915_TILING_X;
9828 fb->modifier = I915_FORMAT_MOD_X_TILED;
9830 case PLANE_CTL_TILED_Y:
9831 plane_config->tiling = I915_TILING_Y;
9832 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
9833 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
9835 fb->modifier = I915_FORMAT_MOD_Y_TILED;
9837 case PLANE_CTL_TILED_YF:
9838 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
9839 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
9841 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
9844 MISSING_CASE(tiling);
9849 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
9850 * while i915 HW rotation is clockwise, thats why this swapping.
9852 switch (val & PLANE_CTL_ROTATE_MASK) {
9853 case PLANE_CTL_ROTATE_0:
9854 plane_config->rotation = DRM_MODE_ROTATE_0;
9856 case PLANE_CTL_ROTATE_90:
9857 plane_config->rotation = DRM_MODE_ROTATE_270;
9859 case PLANE_CTL_ROTATE_180:
9860 plane_config->rotation = DRM_MODE_ROTATE_180;
9862 case PLANE_CTL_ROTATE_270:
9863 plane_config->rotation = DRM_MODE_ROTATE_90;
9867 if (INTEL_GEN(dev_priv) >= 10 &&
9868 val & PLANE_CTL_FLIP_HORIZONTAL)
9869 plane_config->rotation |= DRM_MODE_REFLECT_X;
9871 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
9872 plane_config->base = base;
9874 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
9876 val = I915_READ(PLANE_SIZE(pipe, plane_id));
9877 fb->height = ((val >> 16) & 0xfff) + 1;
9878 fb->width = ((val >> 0) & 0x1fff) + 1;
9880 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
9881 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
9882 fb->pitches[0] = (val & 0x3ff) * stride_mult;
9884 aligned_height = intel_fb_align_height(fb, 0, fb->height);
9886 plane_config->size = fb->pitches[0] * aligned_height;
9888 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9889 crtc->base.name, plane->base.name, fb->width, fb->height,
9890 fb->format->cpp[0] * 8, base, fb->pitches[0],
9891 plane_config->size);
9893 plane_config->fb = intel_fb;
9900 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
9901 struct intel_crtc_state *pipe_config)
9903 struct drm_device *dev = crtc->base.dev;
9904 struct drm_i915_private *dev_priv = to_i915(dev);
9907 tmp = I915_READ(PF_CTL(crtc->pipe));
9909 if (tmp & PF_ENABLE) {
9910 pipe_config->pch_pfit.enabled = true;
9911 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
9912 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
9914 /* We currently do not free assignements of panel fitters on
9915 * ivb/hsw (since we don't use the higher upscaling modes which
9916 * differentiates them) so just WARN about this case for now. */
9917 if (IS_GEN(dev_priv, 7)) {
9918 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
9919 PF_PIPE_SEL_IVB(crtc->pipe));
9924 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
9925 struct intel_crtc_state *pipe_config)
9927 struct drm_device *dev = crtc->base.dev;
9928 struct drm_i915_private *dev_priv = to_i915(dev);
9929 enum intel_display_power_domain power_domain;
9930 intel_wakeref_t wakeref;
9934 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9935 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
9939 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
9940 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9941 pipe_config->shared_dpll = NULL;
9944 tmp = I915_READ(PIPECONF(crtc->pipe));
9945 if (!(tmp & PIPECONF_ENABLE))
9948 switch (tmp & PIPECONF_BPC_MASK) {
9950 pipe_config->pipe_bpp = 18;
9953 pipe_config->pipe_bpp = 24;
9955 case PIPECONF_10BPC:
9956 pipe_config->pipe_bpp = 30;
9958 case PIPECONF_12BPC:
9959 pipe_config->pipe_bpp = 36;
9965 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
9966 pipe_config->limited_color_range = true;
9968 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_ILK) >>
9969 PIPECONF_GAMMA_MODE_SHIFT;
9971 pipe_config->csc_mode = I915_READ(PIPE_CSC_MODE(crtc->pipe));
9973 i9xx_get_pipe_color_config(pipe_config);
9974 intel_color_get_config(pipe_config);
9976 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
9977 struct intel_shared_dpll *pll;
9978 enum intel_dpll_id pll_id;
9980 pipe_config->has_pch_encoder = true;
9982 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
9983 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9984 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9986 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9988 if (HAS_PCH_IBX(dev_priv)) {
9990 * The pipe->pch transcoder and pch transcoder->pll
9993 pll_id = (enum intel_dpll_id) crtc->pipe;
9995 tmp = I915_READ(PCH_DPLL_SEL);
9996 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
9997 pll_id = DPLL_ID_PCH_PLL_B;
9999 pll_id= DPLL_ID_PCH_PLL_A;
10002 pipe_config->shared_dpll =
10003 intel_get_shared_dpll_by_id(dev_priv, pll_id);
10004 pll = pipe_config->shared_dpll;
10006 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
10007 &pipe_config->dpll_hw_state));
10009 tmp = pipe_config->dpll_hw_state.dpll;
10010 pipe_config->pixel_multiplier =
10011 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
10012 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
10014 ironlake_pch_clock_get(crtc, pipe_config);
10016 pipe_config->pixel_multiplier = 1;
10019 intel_get_pipe_timings(crtc, pipe_config);
10020 intel_get_pipe_src_size(crtc, pipe_config);
10022 ironlake_get_pfit_config(crtc, pipe_config);
10027 intel_display_power_put(dev_priv, power_domain, wakeref);
10031 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
10032 struct intel_crtc_state *crtc_state)
10034 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10035 struct intel_atomic_state *state =
10036 to_intel_atomic_state(crtc_state->base.state);
10038 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) ||
10039 INTEL_GEN(dev_priv) >= 11) {
10040 struct intel_encoder *encoder =
10041 intel_get_crtc_new_encoder(state, crtc_state);
10043 if (!intel_reserve_shared_dplls(state, crtc, encoder)) {
10044 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
10045 pipe_name(crtc->pipe));
10053 static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
10055 struct intel_crtc_state *pipe_config)
10057 enum intel_dpll_id id;
10060 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
10061 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
10063 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
10066 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10069 static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
10071 struct intel_crtc_state *pipe_config)
10073 enum phy phy = intel_port_to_phy(dev_priv, port);
10074 enum icl_port_dpll_id port_dpll_id;
10075 enum intel_dpll_id id;
10078 if (intel_phy_is_combo(dev_priv, phy)) {
10079 temp = I915_READ(ICL_DPCLKA_CFGCR0) &
10080 ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
10081 id = temp >> ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy);
10082 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10083 } else if (intel_phy_is_tc(dev_priv, phy)) {
10084 u32 clk_sel = I915_READ(DDI_CLK_SEL(port)) & DDI_CLK_SEL_MASK;
10086 if (clk_sel == DDI_CLK_SEL_MG) {
10087 id = icl_tc_port_to_pll_id(intel_port_to_tc(dev_priv,
10089 port_dpll_id = ICL_PORT_DPLL_MG_PHY;
10091 WARN_ON(clk_sel < DDI_CLK_SEL_TBT_162);
10092 id = DPLL_ID_ICL_TBTPLL;
10093 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10096 WARN(1, "Invalid port %x\n", port);
10100 pipe_config->icl_port_dplls[port_dpll_id].pll =
10101 intel_get_shared_dpll_by_id(dev_priv, id);
10103 icl_set_active_port_dpll(pipe_config, port_dpll_id);
10106 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
10108 struct intel_crtc_state *pipe_config)
10110 enum intel_dpll_id id;
10114 id = DPLL_ID_SKL_DPLL0;
10117 id = DPLL_ID_SKL_DPLL1;
10120 id = DPLL_ID_SKL_DPLL2;
10123 DRM_ERROR("Incorrect port type\n");
10127 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10130 static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
10132 struct intel_crtc_state *pipe_config)
10134 enum intel_dpll_id id;
10137 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
10138 id = temp >> (port * 3 + 1);
10140 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
10143 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10146 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
10148 struct intel_crtc_state *pipe_config)
10150 enum intel_dpll_id id;
10151 u32 ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
10153 switch (ddi_pll_sel) {
10154 case PORT_CLK_SEL_WRPLL1:
10155 id = DPLL_ID_WRPLL1;
10157 case PORT_CLK_SEL_WRPLL2:
10158 id = DPLL_ID_WRPLL2;
10160 case PORT_CLK_SEL_SPLL:
10163 case PORT_CLK_SEL_LCPLL_810:
10164 id = DPLL_ID_LCPLL_810;
10166 case PORT_CLK_SEL_LCPLL_1350:
10167 id = DPLL_ID_LCPLL_1350;
10169 case PORT_CLK_SEL_LCPLL_2700:
10170 id = DPLL_ID_LCPLL_2700;
10173 MISSING_CASE(ddi_pll_sel);
10175 case PORT_CLK_SEL_NONE:
10179 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10182 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
10183 struct intel_crtc_state *pipe_config,
10184 u64 *power_domain_mask,
10185 intel_wakeref_t *wakerefs)
10187 struct drm_device *dev = crtc->base.dev;
10188 struct drm_i915_private *dev_priv = to_i915(dev);
10189 enum intel_display_power_domain power_domain;
10190 unsigned long panel_transcoder_mask = 0;
10191 unsigned long enabled_panel_transcoders = 0;
10192 enum transcoder panel_transcoder;
10193 intel_wakeref_t wf;
10196 if (INTEL_GEN(dev_priv) >= 11)
10197 panel_transcoder_mask |=
10198 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
10200 if (HAS_TRANSCODER_EDP(dev_priv))
10201 panel_transcoder_mask |= BIT(TRANSCODER_EDP);
10204 * The pipe->transcoder mapping is fixed with the exception of the eDP
10205 * and DSI transcoders handled below.
10207 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
10210 * XXX: Do intel_display_power_get_if_enabled before reading this (for
10211 * consistency and less surprising code; it's in always on power).
10213 for_each_set_bit(panel_transcoder,
10214 &panel_transcoder_mask,
10215 ARRAY_SIZE(INTEL_INFO(dev_priv)->trans_offsets)) {
10216 bool force_thru = false;
10217 enum pipe trans_pipe;
10219 tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder));
10220 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
10224 * Log all enabled ones, only use the first one.
10226 * FIXME: This won't work for two separate DSI displays.
10228 enabled_panel_transcoders |= BIT(panel_transcoder);
10229 if (enabled_panel_transcoders != BIT(panel_transcoder))
10232 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
10234 WARN(1, "unknown pipe linked to transcoder %s\n",
10235 transcoder_name(panel_transcoder));
10237 case TRANS_DDI_EDP_INPUT_A_ONOFF:
10240 case TRANS_DDI_EDP_INPUT_A_ON:
10241 trans_pipe = PIPE_A;
10243 case TRANS_DDI_EDP_INPUT_B_ONOFF:
10244 trans_pipe = PIPE_B;
10246 case TRANS_DDI_EDP_INPUT_C_ONOFF:
10247 trans_pipe = PIPE_C;
10251 if (trans_pipe == crtc->pipe) {
10252 pipe_config->cpu_transcoder = panel_transcoder;
10253 pipe_config->pch_pfit.force_thru = force_thru;
10258 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
10260 WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
10261 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
10263 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
10264 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
10266 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10270 wakerefs[power_domain] = wf;
10271 *power_domain_mask |= BIT_ULL(power_domain);
10273 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
10275 return tmp & PIPECONF_ENABLE;
10278 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
10279 struct intel_crtc_state *pipe_config,
10280 u64 *power_domain_mask,
10281 intel_wakeref_t *wakerefs)
10283 struct drm_device *dev = crtc->base.dev;
10284 struct drm_i915_private *dev_priv = to_i915(dev);
10285 enum intel_display_power_domain power_domain;
10286 enum transcoder cpu_transcoder;
10287 intel_wakeref_t wf;
10291 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
10292 if (port == PORT_A)
10293 cpu_transcoder = TRANSCODER_DSI_A;
10295 cpu_transcoder = TRANSCODER_DSI_C;
10297 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
10298 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
10300 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10304 wakerefs[power_domain] = wf;
10305 *power_domain_mask |= BIT_ULL(power_domain);
10308 * The PLL needs to be enabled with a valid divider
10309 * configuration, otherwise accessing DSI registers will hang
10310 * the machine. See BSpec North Display Engine
10311 * registers/MIPI[BXT]. We can break out here early, since we
10312 * need the same DSI PLL to be enabled for both DSI ports.
10314 if (!bxt_dsi_pll_is_enabled(dev_priv))
10317 /* XXX: this works for video mode only */
10318 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
10319 if (!(tmp & DPI_ENABLE))
10322 tmp = I915_READ(MIPI_CTRL(port));
10323 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
10326 pipe_config->cpu_transcoder = cpu_transcoder;
10330 return transcoder_is_dsi(pipe_config->cpu_transcoder);
10333 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
10334 struct intel_crtc_state *pipe_config)
10336 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10337 struct intel_shared_dpll *pll;
10341 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
10343 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
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 int pipe = pipe_config->cpu_transcoder;
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 drm_atomic_state *state)
13387 struct drm_crtc *crtc;
13389 /* Add all pipes to the state */
13390 for_each_crtc(state->dev, crtc) {
13391 struct drm_crtc_state *crtc_state;
13393 crtc_state = drm_atomic_get_crtc_state(state, crtc);
13394 if (IS_ERR(crtc_state))
13395 return PTR_ERR(crtc_state);
13401 static int intel_modeset_all_pipes(struct drm_atomic_state *state)
13403 struct drm_crtc *crtc;
13406 * Add all pipes to the state, and force
13407 * a modeset on all the active ones.
13409 for_each_crtc(state->dev, crtc) {
13410 struct drm_crtc_state *crtc_state;
13413 crtc_state = drm_atomic_get_crtc_state(state, crtc);
13414 if (IS_ERR(crtc_state))
13415 return PTR_ERR(crtc_state);
13417 if (!crtc_state->active || needs_modeset(to_intel_crtc_state(crtc_state)))
13420 crtc_state->mode_changed = true;
13422 ret = drm_atomic_add_affected_connectors(state, crtc);
13426 ret = drm_atomic_add_affected_planes(state, crtc);
13434 static int intel_modeset_checks(struct intel_atomic_state *state)
13436 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13437 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13438 struct intel_crtc *crtc;
13441 if (!check_digital_port_conflicts(state)) {
13442 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
13446 /* keep the current setting */
13447 if (!state->cdclk.force_min_cdclk_changed)
13448 state->cdclk.force_min_cdclk = dev_priv->cdclk.force_min_cdclk;
13450 state->modeset = true;
13451 state->active_crtcs = dev_priv->active_crtcs;
13452 state->cdclk.logical = dev_priv->cdclk.logical;
13453 state->cdclk.actual = dev_priv->cdclk.actual;
13454 state->cdclk.pipe = INVALID_PIPE;
13456 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13457 new_crtc_state, i) {
13458 if (new_crtc_state->base.active)
13459 state->active_crtcs |= 1 << i;
13461 state->active_crtcs &= ~(1 << i);
13463 if (old_crtc_state->base.active != new_crtc_state->base.active)
13464 state->active_pipe_changes |= drm_crtc_mask(&crtc->base);
13468 * See if the config requires any additional preparation, e.g.
13469 * to adjust global state with pipes off. We need to do this
13470 * here so we can get the modeset_pipe updated config for the new
13471 * mode set on this crtc. For other crtcs we need to use the
13472 * adjusted_mode bits in the crtc directly.
13474 if (dev_priv->display.modeset_calc_cdclk) {
13477 ret = dev_priv->display.modeset_calc_cdclk(state);
13482 * Writes to dev_priv->cdclk.logical must protected by
13483 * holding all the crtc locks, even if we don't end up
13484 * touching the hardware
13486 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
13487 &state->cdclk.logical)) {
13488 ret = intel_lock_all_pipes(&state->base);
13493 if (is_power_of_2(state->active_crtcs)) {
13494 struct intel_crtc *crtc;
13495 struct intel_crtc_state *crtc_state;
13497 pipe = ilog2(state->active_crtcs);
13498 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
13499 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
13500 if (crtc_state && needs_modeset(crtc_state))
13501 pipe = INVALID_PIPE;
13503 pipe = INVALID_PIPE;
13506 /* All pipes must be switched off while we change the cdclk. */
13507 if (pipe != INVALID_PIPE &&
13508 intel_cdclk_needs_cd2x_update(dev_priv,
13509 &dev_priv->cdclk.actual,
13510 &state->cdclk.actual)) {
13511 ret = intel_lock_all_pipes(&state->base);
13515 state->cdclk.pipe = pipe;
13516 } else if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
13517 &state->cdclk.actual)) {
13518 ret = intel_modeset_all_pipes(&state->base);
13522 state->cdclk.pipe = INVALID_PIPE;
13525 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
13526 state->cdclk.logical.cdclk,
13527 state->cdclk.actual.cdclk);
13528 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
13529 state->cdclk.logical.voltage_level,
13530 state->cdclk.actual.voltage_level);
13533 intel_modeset_clear_plls(state);
13535 if (IS_HASWELL(dev_priv))
13536 return haswell_mode_set_planes_workaround(state);
13542 * Handle calculation of various watermark data at the end of the atomic check
13543 * phase. The code here should be run after the per-crtc and per-plane 'check'
13544 * handlers to ensure that all derived state has been updated.
13546 static int calc_watermark_data(struct intel_atomic_state *state)
13548 struct drm_device *dev = state->base.dev;
13549 struct drm_i915_private *dev_priv = to_i915(dev);
13551 /* Is there platform-specific watermark information to calculate? */
13552 if (dev_priv->display.compute_global_watermarks)
13553 return dev_priv->display.compute_global_watermarks(state);
13558 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
13559 struct intel_crtc_state *new_crtc_state)
13561 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
13564 new_crtc_state->base.mode_changed = false;
13565 new_crtc_state->update_pipe = true;
13568 * If we're not doing the full modeset we want to
13569 * keep the current M/N values as they may be
13570 * sufficiently different to the computed values
13571 * to cause problems.
13573 * FIXME: should really copy more fuzzy state here
13575 new_crtc_state->fdi_m_n = old_crtc_state->fdi_m_n;
13576 new_crtc_state->dp_m_n = old_crtc_state->dp_m_n;
13577 new_crtc_state->dp_m2_n2 = old_crtc_state->dp_m2_n2;
13578 new_crtc_state->has_drrs = old_crtc_state->has_drrs;
13582 * intel_atomic_check - validate state object
13584 * @_state: state to validate
13586 static int intel_atomic_check(struct drm_device *dev,
13587 struct drm_atomic_state *_state)
13589 struct drm_i915_private *dev_priv = to_i915(dev);
13590 struct intel_atomic_state *state = to_intel_atomic_state(_state);
13591 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13592 struct intel_crtc *crtc;
13594 bool any_ms = state->cdclk.force_min_cdclk_changed;
13596 /* Catch I915_MODE_FLAG_INHERITED */
13597 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13598 new_crtc_state, i) {
13599 if (new_crtc_state->base.mode.private_flags !=
13600 old_crtc_state->base.mode.private_flags)
13601 new_crtc_state->base.mode_changed = true;
13604 ret = drm_atomic_helper_check_modeset(dev, &state->base);
13608 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13609 new_crtc_state, i) {
13610 if (!needs_modeset(new_crtc_state))
13613 if (!new_crtc_state->base.enable) {
13618 ret = intel_modeset_pipe_config(new_crtc_state);
13622 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
13624 if (needs_modeset(new_crtc_state))
13628 ret = drm_dp_mst_atomic_check(&state->base);
13633 ret = intel_modeset_checks(state);
13637 state->cdclk.logical = dev_priv->cdclk.logical;
13640 ret = icl_add_linked_planes(state);
13644 ret = drm_atomic_helper_check_planes(dev, &state->base);
13648 intel_fbc_choose_crtc(dev_priv, state);
13649 ret = calc_watermark_data(state);
13653 ret = intel_bw_atomic_check(state);
13657 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13658 new_crtc_state, i) {
13659 if (!needs_modeset(new_crtc_state) &&
13660 !new_crtc_state->update_pipe)
13663 intel_dump_pipe_config(new_crtc_state, state,
13664 needs_modeset(new_crtc_state) ?
13665 "[modeset]" : "[fastset]");
13671 if (ret == -EDEADLK)
13675 * FIXME would probably be nice to know which crtc specifically
13676 * caused the failure, in cases where we can pinpoint it.
13678 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13680 intel_dump_pipe_config(new_crtc_state, state, "[failed]");
13685 static int intel_atomic_prepare_commit(struct drm_device *dev,
13686 struct drm_atomic_state *state)
13688 return drm_atomic_helper_prepare_planes(dev, state);
13691 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
13693 struct drm_device *dev = crtc->base.dev;
13694 struct drm_vblank_crtc *vblank = &dev->vblank[drm_crtc_index(&crtc->base)];
13696 if (!vblank->max_vblank_count)
13697 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
13699 return crtc->base.funcs->get_vblank_counter(&crtc->base);
13702 static void intel_update_crtc(struct intel_crtc *crtc,
13703 struct intel_atomic_state *state,
13704 struct intel_crtc_state *old_crtc_state,
13705 struct intel_crtc_state *new_crtc_state)
13707 struct drm_device *dev = state->base.dev;
13708 struct drm_i915_private *dev_priv = to_i915(dev);
13709 bool modeset = needs_modeset(new_crtc_state);
13710 struct intel_plane_state *new_plane_state =
13711 intel_atomic_get_new_plane_state(state,
13712 to_intel_plane(crtc->base.primary));
13715 update_scanline_offset(new_crtc_state);
13716 dev_priv->display.crtc_enable(new_crtc_state, state);
13718 /* vblanks work again, re-enable pipe CRC. */
13719 intel_crtc_enable_pipe_crc(crtc);
13721 intel_pre_plane_update(old_crtc_state, new_crtc_state);
13723 if (new_crtc_state->update_pipe)
13724 intel_encoders_update_pipe(crtc, new_crtc_state, state);
13727 if (new_crtc_state->update_pipe && !new_crtc_state->enable_fbc)
13728 intel_fbc_disable(crtc);
13729 else if (new_plane_state)
13730 intel_fbc_enable(crtc, new_crtc_state, new_plane_state);
13732 intel_begin_crtc_commit(state, crtc);
13734 if (INTEL_GEN(dev_priv) >= 9)
13735 skl_update_planes_on_crtc(state, crtc);
13737 i9xx_update_planes_on_crtc(state, crtc);
13739 intel_finish_crtc_commit(state, crtc);
13742 static void intel_update_crtcs(struct intel_atomic_state *state)
13744 struct intel_crtc *crtc;
13745 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13748 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13749 if (!new_crtc_state->base.active)
13752 intel_update_crtc(crtc, state, old_crtc_state,
13757 static void skl_update_crtcs(struct intel_atomic_state *state)
13759 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13760 struct intel_crtc *crtc;
13761 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13762 unsigned int updated = 0;
13766 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
13767 u8 required_slices = state->wm_results.ddb.enabled_slices;
13768 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
13770 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
13771 /* ignore allocations for crtc's that have been turned off. */
13772 if (new_crtc_state->base.active)
13773 entries[i] = old_crtc_state->wm.skl.ddb;
13775 /* If 2nd DBuf slice required, enable it here */
13776 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
13777 icl_dbuf_slices_update(dev_priv, required_slices);
13780 * Whenever the number of active pipes changes, we need to make sure we
13781 * update the pipes in the right order so that their ddb allocations
13782 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
13783 * cause pipe underruns and other bad stuff.
13788 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13789 bool vbl_wait = false;
13790 unsigned int cmask = drm_crtc_mask(&crtc->base);
13794 if (updated & cmask || !new_crtc_state->base.active)
13797 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
13799 INTEL_INFO(dev_priv)->num_pipes, i))
13803 entries[i] = new_crtc_state->wm.skl.ddb;
13806 * If this is an already active pipe, it's DDB changed,
13807 * and this isn't the last pipe that needs updating
13808 * then we need to wait for a vblank to pass for the
13809 * new ddb allocation to take effect.
13811 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
13812 &old_crtc_state->wm.skl.ddb) &&
13813 !new_crtc_state->base.active_changed &&
13814 state->wm_results.dirty_pipes != updated)
13817 intel_update_crtc(crtc, state, old_crtc_state,
13821 intel_wait_for_vblank(dev_priv, pipe);
13825 } while (progress);
13827 /* If 2nd DBuf slice is no more required disable it */
13828 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
13829 icl_dbuf_slices_update(dev_priv, required_slices);
13832 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
13834 struct intel_atomic_state *state, *next;
13835 struct llist_node *freed;
13837 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
13838 llist_for_each_entry_safe(state, next, freed, freed)
13839 drm_atomic_state_put(&state->base);
13842 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
13844 struct drm_i915_private *dev_priv =
13845 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
13847 intel_atomic_helper_free_state(dev_priv);
13850 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
13852 struct wait_queue_entry wait_fence, wait_reset;
13853 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
13855 init_wait_entry(&wait_fence, 0);
13856 init_wait_entry(&wait_reset, 0);
13858 prepare_to_wait(&intel_state->commit_ready.wait,
13859 &wait_fence, TASK_UNINTERRUPTIBLE);
13860 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
13861 &wait_reset, TASK_UNINTERRUPTIBLE);
13864 if (i915_sw_fence_done(&intel_state->commit_ready)
13865 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
13870 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
13871 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
13874 static void intel_atomic_cleanup_work(struct work_struct *work)
13876 struct drm_atomic_state *state =
13877 container_of(work, struct drm_atomic_state, commit_work);
13878 struct drm_i915_private *i915 = to_i915(state->dev);
13880 drm_atomic_helper_cleanup_planes(&i915->drm, state);
13881 drm_atomic_helper_commit_cleanup_done(state);
13882 drm_atomic_state_put(state);
13884 intel_atomic_helper_free_state(i915);
13887 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
13889 struct drm_device *dev = state->base.dev;
13890 struct drm_i915_private *dev_priv = to_i915(dev);
13891 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
13892 struct intel_crtc *crtc;
13893 u64 put_domains[I915_MAX_PIPES] = {};
13894 intel_wakeref_t wakeref = 0;
13897 intel_atomic_commit_fence_wait(state);
13899 drm_atomic_helper_wait_for_dependencies(&state->base);
13901 if (state->modeset)
13902 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
13904 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13905 if (needs_modeset(new_crtc_state) ||
13906 new_crtc_state->update_pipe) {
13908 put_domains[crtc->pipe] =
13909 modeset_get_crtc_power_domains(new_crtc_state);
13912 if (!needs_modeset(new_crtc_state))
13915 intel_pre_plane_update(old_crtc_state, new_crtc_state);
13917 if (old_crtc_state->base.active) {
13918 intel_crtc_disable_planes(state, crtc);
13921 * We need to disable pipe CRC before disabling the pipe,
13922 * or we race against vblank off.
13924 intel_crtc_disable_pipe_crc(crtc);
13926 dev_priv->display.crtc_disable(old_crtc_state, state);
13927 crtc->active = false;
13928 intel_fbc_disable(crtc);
13929 intel_disable_shared_dpll(old_crtc_state);
13932 * Underruns don't always raise
13933 * interrupts, so check manually.
13935 intel_check_cpu_fifo_underruns(dev_priv);
13936 intel_check_pch_fifo_underruns(dev_priv);
13938 /* FIXME unify this for all platforms */
13939 if (!new_crtc_state->base.active &&
13940 !HAS_GMCH(dev_priv) &&
13941 dev_priv->display.initial_watermarks)
13942 dev_priv->display.initial_watermarks(state,
13947 /* FIXME: Eventually get rid of our crtc->config pointer */
13948 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
13949 crtc->config = new_crtc_state;
13951 if (state->modeset) {
13952 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
13954 intel_set_cdclk_pre_plane_update(dev_priv,
13955 &state->cdclk.actual,
13956 &dev_priv->cdclk.actual,
13957 state->cdclk.pipe);
13960 * SKL workaround: bspec recommends we disable the SAGV when we
13961 * have more then one pipe enabled
13963 if (!intel_can_enable_sagv(state))
13964 intel_disable_sagv(dev_priv);
13966 intel_modeset_verify_disabled(dev_priv, state);
13969 /* Complete the events for pipes that have now been disabled */
13970 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
13971 bool modeset = needs_modeset(new_crtc_state);
13973 /* Complete events for now disable pipes here. */
13974 if (modeset && !new_crtc_state->base.active && new_crtc_state->base.event) {
13975 spin_lock_irq(&dev->event_lock);
13976 drm_crtc_send_vblank_event(&crtc->base, new_crtc_state->base.event);
13977 spin_unlock_irq(&dev->event_lock);
13979 new_crtc_state->base.event = NULL;
13983 if (state->modeset)
13984 intel_encoders_update_prepare(state);
13986 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
13987 dev_priv->display.update_crtcs(state);
13989 if (state->modeset) {
13990 intel_encoders_update_complete(state);
13992 intel_set_cdclk_post_plane_update(dev_priv,
13993 &state->cdclk.actual,
13994 &dev_priv->cdclk.actual,
13995 state->cdclk.pipe);
13998 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
13999 * already, but still need the state for the delayed optimization. To
14001 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
14002 * - schedule that vblank worker _before_ calling hw_done
14003 * - at the start of commit_tail, cancel it _synchrously
14004 * - switch over to the vblank wait helper in the core after that since
14005 * we don't need out special handling any more.
14007 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
14009 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14010 if (new_crtc_state->base.active &&
14011 !needs_modeset(new_crtc_state) &&
14012 (new_crtc_state->base.color_mgmt_changed ||
14013 new_crtc_state->update_pipe))
14014 intel_color_load_luts(new_crtc_state);
14018 * Now that the vblank has passed, we can go ahead and program the
14019 * optimal watermarks on platforms that need two-step watermark
14022 * TODO: Move this (and other cleanup) to an async worker eventually.
14024 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14025 if (dev_priv->display.optimize_watermarks)
14026 dev_priv->display.optimize_watermarks(state,
14030 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
14031 intel_post_plane_update(old_crtc_state);
14033 if (put_domains[i])
14034 modeset_put_power_domains(dev_priv, put_domains[i]);
14036 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
14039 if (state->modeset)
14040 intel_verify_planes(state);
14042 if (state->modeset && intel_can_enable_sagv(state))
14043 intel_enable_sagv(dev_priv);
14045 drm_atomic_helper_commit_hw_done(&state->base);
14047 if (state->modeset) {
14048 /* As one of the primary mmio accessors, KMS has a high
14049 * likelihood of triggering bugs in unclaimed access. After we
14050 * finish modesetting, see if an error has been flagged, and if
14051 * so enable debugging for the next modeset - and hope we catch
14054 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
14055 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
14057 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
14060 * Defer the cleanup of the old state to a separate worker to not
14061 * impede the current task (userspace for blocking modesets) that
14062 * are executed inline. For out-of-line asynchronous modesets/flips,
14063 * deferring to a new worker seems overkill, but we would place a
14064 * schedule point (cond_resched()) here anyway to keep latencies
14067 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
14068 queue_work(system_highpri_wq, &state->base.commit_work);
14071 static void intel_atomic_commit_work(struct work_struct *work)
14073 struct intel_atomic_state *state =
14074 container_of(work, struct intel_atomic_state, base.commit_work);
14076 intel_atomic_commit_tail(state);
14079 static int __i915_sw_fence_call
14080 intel_atomic_commit_ready(struct i915_sw_fence *fence,
14081 enum i915_sw_fence_notify notify)
14083 struct intel_atomic_state *state =
14084 container_of(fence, struct intel_atomic_state, commit_ready);
14087 case FENCE_COMPLETE:
14088 /* we do blocking waits in the worker, nothing to do here */
14092 struct intel_atomic_helper *helper =
14093 &to_i915(state->base.dev)->atomic_helper;
14095 if (llist_add(&state->freed, &helper->free_list))
14096 schedule_work(&helper->free_work);
14101 return NOTIFY_DONE;
14104 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
14106 struct intel_plane_state *old_plane_state, *new_plane_state;
14107 struct intel_plane *plane;
14110 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
14111 new_plane_state, i)
14112 i915_gem_track_fb(intel_fb_obj(old_plane_state->base.fb),
14113 intel_fb_obj(new_plane_state->base.fb),
14114 plane->frontbuffer_bit);
14118 * intel_atomic_commit - commit validated state object
14120 * @state: the top-level driver state object
14121 * @nonblock: nonblocking commit
14123 * This function commits a top-level state object that has been validated
14124 * with drm_atomic_helper_check().
14127 * Zero for success or -errno.
14129 static int intel_atomic_commit(struct drm_device *dev,
14130 struct drm_atomic_state *state,
14133 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
14134 struct drm_i915_private *dev_priv = to_i915(dev);
14137 intel_state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
14139 drm_atomic_state_get(state);
14140 i915_sw_fence_init(&intel_state->commit_ready,
14141 intel_atomic_commit_ready);
14144 * The intel_legacy_cursor_update() fast path takes care
14145 * of avoiding the vblank waits for simple cursor
14146 * movement and flips. For cursor on/off and size changes,
14147 * we want to perform the vblank waits so that watermark
14148 * updates happen during the correct frames. Gen9+ have
14149 * double buffered watermarks and so shouldn't need this.
14151 * Unset state->legacy_cursor_update before the call to
14152 * drm_atomic_helper_setup_commit() because otherwise
14153 * drm_atomic_helper_wait_for_flip_done() is a noop and
14154 * we get FIFO underruns because we didn't wait
14157 * FIXME doing watermarks and fb cleanup from a vblank worker
14158 * (assuming we had any) would solve these problems.
14160 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
14161 struct intel_crtc_state *new_crtc_state;
14162 struct intel_crtc *crtc;
14165 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
14166 if (new_crtc_state->wm.need_postvbl_update ||
14167 new_crtc_state->update_wm_post)
14168 state->legacy_cursor_update = false;
14171 ret = intel_atomic_prepare_commit(dev, state);
14173 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
14174 i915_sw_fence_commit(&intel_state->commit_ready);
14175 intel_runtime_pm_put(&dev_priv->runtime_pm, intel_state->wakeref);
14179 ret = drm_atomic_helper_setup_commit(state, nonblock);
14181 ret = drm_atomic_helper_swap_state(state, true);
14184 i915_sw_fence_commit(&intel_state->commit_ready);
14186 drm_atomic_helper_cleanup_planes(dev, state);
14187 intel_runtime_pm_put(&dev_priv->runtime_pm, intel_state->wakeref);
14190 dev_priv->wm.distrust_bios_wm = false;
14191 intel_shared_dpll_swap_state(intel_state);
14192 intel_atomic_track_fbs(intel_state);
14194 if (intel_state->modeset) {
14195 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
14196 sizeof(intel_state->min_cdclk));
14197 memcpy(dev_priv->min_voltage_level,
14198 intel_state->min_voltage_level,
14199 sizeof(intel_state->min_voltage_level));
14200 dev_priv->active_crtcs = intel_state->active_crtcs;
14201 dev_priv->cdclk.force_min_cdclk =
14202 intel_state->cdclk.force_min_cdclk;
14204 intel_cdclk_swap_state(intel_state);
14207 drm_atomic_state_get(state);
14208 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
14210 i915_sw_fence_commit(&intel_state->commit_ready);
14211 if (nonblock && intel_state->modeset) {
14212 queue_work(dev_priv->modeset_wq, &state->commit_work);
14213 } else if (nonblock) {
14214 queue_work(system_unbound_wq, &state->commit_work);
14216 if (intel_state->modeset)
14217 flush_workqueue(dev_priv->modeset_wq);
14218 intel_atomic_commit_tail(intel_state);
14224 struct wait_rps_boost {
14225 struct wait_queue_entry wait;
14227 struct drm_crtc *crtc;
14228 struct i915_request *request;
14231 static int do_rps_boost(struct wait_queue_entry *_wait,
14232 unsigned mode, int sync, void *key)
14234 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
14235 struct i915_request *rq = wait->request;
14238 * If we missed the vblank, but the request is already running it
14239 * is reasonable to assume that it will complete before the next
14240 * vblank without our intervention, so leave RPS alone.
14242 if (!i915_request_started(rq))
14243 gen6_rps_boost(rq);
14244 i915_request_put(rq);
14246 drm_crtc_vblank_put(wait->crtc);
14248 list_del(&wait->wait.entry);
14253 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
14254 struct dma_fence *fence)
14256 struct wait_rps_boost *wait;
14258 if (!dma_fence_is_i915(fence))
14261 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
14264 if (drm_crtc_vblank_get(crtc))
14267 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
14269 drm_crtc_vblank_put(crtc);
14273 wait->request = to_request(dma_fence_get(fence));
14276 wait->wait.func = do_rps_boost;
14277 wait->wait.flags = 0;
14279 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
14282 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
14284 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
14285 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
14286 struct drm_framebuffer *fb = plane_state->base.fb;
14287 struct i915_vma *vma;
14289 if (plane->id == PLANE_CURSOR &&
14290 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
14291 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14292 const int align = intel_cursor_alignment(dev_priv);
14295 err = i915_gem_object_attach_phys(obj, align);
14300 vma = intel_pin_and_fence_fb_obj(fb,
14301 &plane_state->view,
14302 intel_plane_uses_fence(plane_state),
14303 &plane_state->flags);
14305 return PTR_ERR(vma);
14307 plane_state->vma = vma;
14312 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
14314 struct i915_vma *vma;
14316 vma = fetch_and_zero(&old_plane_state->vma);
14318 intel_unpin_fb_vma(vma, old_plane_state->flags);
14321 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
14323 struct i915_sched_attr attr = {
14324 .priority = I915_PRIORITY_DISPLAY,
14327 i915_gem_object_wait_priority(obj, 0, &attr);
14331 * intel_prepare_plane_fb - Prepare fb for usage on plane
14332 * @plane: drm plane to prepare for
14333 * @new_state: the plane state being prepared
14335 * Prepares a framebuffer for usage on a display plane. Generally this
14336 * involves pinning the underlying object and updating the frontbuffer tracking
14337 * bits. Some older platforms need special physical address handling for
14340 * Must be called with struct_mutex held.
14342 * Returns 0 on success, negative error code on failure.
14345 intel_prepare_plane_fb(struct drm_plane *plane,
14346 struct drm_plane_state *new_state)
14348 struct intel_atomic_state *intel_state =
14349 to_intel_atomic_state(new_state->state);
14350 struct drm_i915_private *dev_priv = to_i915(plane->dev);
14351 struct drm_framebuffer *fb = new_state->fb;
14352 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14353 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
14357 struct intel_crtc_state *crtc_state =
14358 intel_atomic_get_new_crtc_state(intel_state,
14359 to_intel_crtc(plane->state->crtc));
14361 /* Big Hammer, we also need to ensure that any pending
14362 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
14363 * current scanout is retired before unpinning the old
14364 * framebuffer. Note that we rely on userspace rendering
14365 * into the buffer attached to the pipe they are waiting
14366 * on. If not, userspace generates a GPU hang with IPEHR
14367 * point to the MI_WAIT_FOR_EVENT.
14369 * This should only fail upon a hung GPU, in which case we
14370 * can safely continue.
14372 if (needs_modeset(crtc_state)) {
14373 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
14374 old_obj->base.resv, NULL,
14382 if (new_state->fence) { /* explicit fencing */
14383 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
14385 I915_FENCE_TIMEOUT,
14394 ret = i915_gem_object_pin_pages(obj);
14398 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
14400 i915_gem_object_unpin_pages(obj);
14404 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
14406 mutex_unlock(&dev_priv->drm.struct_mutex);
14407 i915_gem_object_unpin_pages(obj);
14411 fb_obj_bump_render_priority(obj);
14412 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
14414 if (!new_state->fence) { /* implicit fencing */
14415 struct dma_fence *fence;
14417 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
14418 obj->base.resv, NULL,
14419 false, I915_FENCE_TIMEOUT,
14424 fence = reservation_object_get_excl_rcu(obj->base.resv);
14426 add_rps_boost_after_vblank(new_state->crtc, fence);
14427 dma_fence_put(fence);
14430 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
14434 * We declare pageflips to be interactive and so merit a small bias
14435 * towards upclocking to deliver the frame on time. By only changing
14436 * the RPS thresholds to sample more regularly and aim for higher
14437 * clocks we can hopefully deliver low power workloads (like kodi)
14438 * that are not quite steady state without resorting to forcing
14439 * maximum clocks following a vblank miss (see do_rps_boost()).
14441 if (!intel_state->rps_interactive) {
14442 intel_rps_mark_interactive(dev_priv, true);
14443 intel_state->rps_interactive = true;
14450 * intel_cleanup_plane_fb - Cleans up an fb after plane use
14451 * @plane: drm plane to clean up for
14452 * @old_state: the state from the previous modeset
14454 * Cleans up a framebuffer that has just been removed from a plane.
14456 * Must be called with struct_mutex held.
14459 intel_cleanup_plane_fb(struct drm_plane *plane,
14460 struct drm_plane_state *old_state)
14462 struct intel_atomic_state *intel_state =
14463 to_intel_atomic_state(old_state->state);
14464 struct drm_i915_private *dev_priv = to_i915(plane->dev);
14466 if (intel_state->rps_interactive) {
14467 intel_rps_mark_interactive(dev_priv, false);
14468 intel_state->rps_interactive = false;
14471 /* Should only be called after a successful intel_prepare_plane_fb()! */
14472 mutex_lock(&dev_priv->drm.struct_mutex);
14473 intel_plane_unpin_fb(to_intel_plane_state(old_state));
14474 mutex_unlock(&dev_priv->drm.struct_mutex);
14478 skl_max_scale(const struct intel_crtc_state *crtc_state,
14481 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
14482 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14483 int max_scale, mult;
14484 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
14486 if (!crtc_state->base.enable)
14487 return DRM_PLANE_HELPER_NO_SCALING;
14489 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
14490 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
14492 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
14495 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
14496 return DRM_PLANE_HELPER_NO_SCALING;
14499 * skl max scale is lower of:
14500 * close to 3 but not 3, -1 is for that purpose
14504 mult = is_planar_yuv_format(pixel_format) ? 2 : 3;
14505 tmpclk1 = (1 << 16) * mult - 1;
14506 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
14507 max_scale = min(tmpclk1, tmpclk2);
14512 static void intel_begin_crtc_commit(struct intel_atomic_state *state,
14513 struct intel_crtc *crtc)
14515 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14516 struct intel_crtc_state *old_crtc_state =
14517 intel_atomic_get_old_crtc_state(state, crtc);
14518 struct intel_crtc_state *new_crtc_state =
14519 intel_atomic_get_new_crtc_state(state, crtc);
14520 bool modeset = needs_modeset(new_crtc_state);
14522 /* Perform vblank evasion around commit operation */
14523 intel_pipe_update_start(new_crtc_state);
14528 if (new_crtc_state->base.color_mgmt_changed ||
14529 new_crtc_state->update_pipe)
14530 intel_color_commit(new_crtc_state);
14532 if (new_crtc_state->update_pipe)
14533 intel_update_pipe_config(old_crtc_state, new_crtc_state);
14534 else if (INTEL_GEN(dev_priv) >= 9)
14535 skl_detach_scalers(new_crtc_state);
14537 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
14538 bdw_set_pipemisc(new_crtc_state);
14541 if (dev_priv->display.atomic_update_watermarks)
14542 dev_priv->display.atomic_update_watermarks(state,
14546 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
14547 struct intel_crtc_state *crtc_state)
14549 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14551 if (!IS_GEN(dev_priv, 2))
14552 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
14554 if (crtc_state->has_pch_encoder) {
14555 enum pipe pch_transcoder =
14556 intel_crtc_pch_transcoder(crtc);
14558 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
14562 static void intel_finish_crtc_commit(struct intel_atomic_state *state,
14563 struct intel_crtc *crtc)
14565 struct intel_crtc_state *old_crtc_state =
14566 intel_atomic_get_old_crtc_state(state, crtc);
14567 struct intel_crtc_state *new_crtc_state =
14568 intel_atomic_get_new_crtc_state(state, crtc);
14570 intel_pipe_update_end(new_crtc_state);
14572 if (new_crtc_state->update_pipe &&
14573 !needs_modeset(new_crtc_state) &&
14574 old_crtc_state->base.mode.private_flags & I915_MODE_FLAG_INHERITED)
14575 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
14579 * intel_plane_destroy - destroy a plane
14580 * @plane: plane to destroy
14582 * Common destruction function for all types of planes (primary, cursor,
14585 void intel_plane_destroy(struct drm_plane *plane)
14587 drm_plane_cleanup(plane);
14588 kfree(to_intel_plane(plane));
14591 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
14592 u32 format, u64 modifier)
14594 switch (modifier) {
14595 case DRM_FORMAT_MOD_LINEAR:
14596 case I915_FORMAT_MOD_X_TILED:
14603 case DRM_FORMAT_C8:
14604 case DRM_FORMAT_RGB565:
14605 case DRM_FORMAT_XRGB1555:
14606 case DRM_FORMAT_XRGB8888:
14607 return modifier == DRM_FORMAT_MOD_LINEAR ||
14608 modifier == I915_FORMAT_MOD_X_TILED;
14614 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
14615 u32 format, u64 modifier)
14617 switch (modifier) {
14618 case DRM_FORMAT_MOD_LINEAR:
14619 case I915_FORMAT_MOD_X_TILED:
14626 case DRM_FORMAT_C8:
14627 case DRM_FORMAT_RGB565:
14628 case DRM_FORMAT_XRGB8888:
14629 case DRM_FORMAT_XBGR8888:
14630 case DRM_FORMAT_XRGB2101010:
14631 case DRM_FORMAT_XBGR2101010:
14632 return modifier == DRM_FORMAT_MOD_LINEAR ||
14633 modifier == I915_FORMAT_MOD_X_TILED;
14639 static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
14640 u32 format, u64 modifier)
14642 return modifier == DRM_FORMAT_MOD_LINEAR &&
14643 format == DRM_FORMAT_ARGB8888;
14646 static const struct drm_plane_funcs i965_plane_funcs = {
14647 .update_plane = drm_atomic_helper_update_plane,
14648 .disable_plane = drm_atomic_helper_disable_plane,
14649 .destroy = intel_plane_destroy,
14650 .atomic_duplicate_state = intel_plane_duplicate_state,
14651 .atomic_destroy_state = intel_plane_destroy_state,
14652 .format_mod_supported = i965_plane_format_mod_supported,
14655 static const struct drm_plane_funcs i8xx_plane_funcs = {
14656 .update_plane = drm_atomic_helper_update_plane,
14657 .disable_plane = drm_atomic_helper_disable_plane,
14658 .destroy = intel_plane_destroy,
14659 .atomic_duplicate_state = intel_plane_duplicate_state,
14660 .atomic_destroy_state = intel_plane_destroy_state,
14661 .format_mod_supported = i8xx_plane_format_mod_supported,
14665 intel_legacy_cursor_update(struct drm_plane *plane,
14666 struct drm_crtc *crtc,
14667 struct drm_framebuffer *fb,
14668 int crtc_x, int crtc_y,
14669 unsigned int crtc_w, unsigned int crtc_h,
14670 u32 src_x, u32 src_y,
14671 u32 src_w, u32 src_h,
14672 struct drm_modeset_acquire_ctx *ctx)
14674 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 drm_framebuffer *old_fb;
14679 struct intel_crtc_state *crtc_state =
14680 to_intel_crtc_state(crtc->state);
14681 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_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
14751 old_fb = old_plane_state->fb;
14752 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
14753 intel_plane->frontbuffer_bit);
14755 /* Swap plane state */
14756 plane->state = new_plane_state;
14759 * We cannot swap crtc_state as it may be in use by an atomic commit or
14760 * page flip that's running simultaneously. If we swap crtc_state and
14761 * destroy the old state, we will cause a use-after-free there.
14763 * Only update active_planes, which is needed for our internal
14764 * bookkeeping. Either value will do the right thing when updating
14765 * planes atomically. If the cursor was part of the atomic update then
14766 * we would have taken the slowpath.
14768 crtc_state->active_planes = new_crtc_state->active_planes;
14770 if (plane->state->visible)
14771 intel_update_plane(intel_plane, crtc_state,
14772 to_intel_plane_state(plane->state));
14774 intel_disable_plane(intel_plane, crtc_state);
14776 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
14779 mutex_unlock(&dev_priv->drm.struct_mutex);
14781 if (new_crtc_state)
14782 intel_crtc_destroy_state(crtc, &new_crtc_state->base);
14784 intel_plane_destroy_state(plane, new_plane_state);
14786 intel_plane_destroy_state(plane, old_plane_state);
14790 return drm_atomic_helper_update_plane(plane, crtc, fb,
14791 crtc_x, crtc_y, crtc_w, crtc_h,
14792 src_x, src_y, src_w, src_h, ctx);
14795 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
14796 .update_plane = intel_legacy_cursor_update,
14797 .disable_plane = drm_atomic_helper_disable_plane,
14798 .destroy = intel_plane_destroy,
14799 .atomic_duplicate_state = intel_plane_duplicate_state,
14800 .atomic_destroy_state = intel_plane_destroy_state,
14801 .format_mod_supported = intel_cursor_format_mod_supported,
14804 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
14805 enum i9xx_plane_id i9xx_plane)
14807 if (!HAS_FBC(dev_priv))
14810 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
14811 return i9xx_plane == PLANE_A; /* tied to pipe A */
14812 else if (IS_IVYBRIDGE(dev_priv))
14813 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
14814 i9xx_plane == PLANE_C;
14815 else if (INTEL_GEN(dev_priv) >= 4)
14816 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
14818 return i9xx_plane == PLANE_A;
14821 static struct intel_plane *
14822 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
14824 struct intel_plane *plane;
14825 const struct drm_plane_funcs *plane_funcs;
14826 unsigned int supported_rotations;
14827 unsigned int possible_crtcs;
14828 const u64 *modifiers;
14829 const u32 *formats;
14833 if (INTEL_GEN(dev_priv) >= 9)
14834 return skl_universal_plane_create(dev_priv, pipe,
14837 plane = intel_plane_alloc();
14841 plane->pipe = pipe;
14843 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
14844 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
14846 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
14847 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
14849 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
14850 plane->id = PLANE_PRIMARY;
14851 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
14853 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
14854 if (plane->has_fbc) {
14855 struct intel_fbc *fbc = &dev_priv->fbc;
14857 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
14860 if (INTEL_GEN(dev_priv) >= 4) {
14861 formats = i965_primary_formats;
14862 num_formats = ARRAY_SIZE(i965_primary_formats);
14863 modifiers = i9xx_format_modifiers;
14865 plane->max_stride = i9xx_plane_max_stride;
14866 plane->update_plane = i9xx_update_plane;
14867 plane->disable_plane = i9xx_disable_plane;
14868 plane->get_hw_state = i9xx_plane_get_hw_state;
14869 plane->check_plane = i9xx_plane_check;
14871 plane_funcs = &i965_plane_funcs;
14873 formats = i8xx_primary_formats;
14874 num_formats = ARRAY_SIZE(i8xx_primary_formats);
14875 modifiers = i9xx_format_modifiers;
14877 plane->max_stride = i9xx_plane_max_stride;
14878 plane->update_plane = i9xx_update_plane;
14879 plane->disable_plane = i9xx_disable_plane;
14880 plane->get_hw_state = i9xx_plane_get_hw_state;
14881 plane->check_plane = i9xx_plane_check;
14883 plane_funcs = &i8xx_plane_funcs;
14886 possible_crtcs = BIT(pipe);
14888 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
14889 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
14890 possible_crtcs, plane_funcs,
14891 formats, num_formats, modifiers,
14892 DRM_PLANE_TYPE_PRIMARY,
14893 "primary %c", pipe_name(pipe));
14895 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
14896 possible_crtcs, plane_funcs,
14897 formats, num_formats, modifiers,
14898 DRM_PLANE_TYPE_PRIMARY,
14900 plane_name(plane->i9xx_plane));
14904 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
14905 supported_rotations =
14906 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
14907 DRM_MODE_REFLECT_X;
14908 } else if (INTEL_GEN(dev_priv) >= 4) {
14909 supported_rotations =
14910 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
14912 supported_rotations = DRM_MODE_ROTATE_0;
14915 if (INTEL_GEN(dev_priv) >= 4)
14916 drm_plane_create_rotation_property(&plane->base,
14918 supported_rotations);
14920 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
14925 intel_plane_free(plane);
14927 return ERR_PTR(ret);
14930 static struct intel_plane *
14931 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
14934 unsigned int possible_crtcs;
14935 struct intel_plane *cursor;
14938 cursor = intel_plane_alloc();
14939 if (IS_ERR(cursor))
14942 cursor->pipe = pipe;
14943 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
14944 cursor->id = PLANE_CURSOR;
14945 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
14947 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
14948 cursor->max_stride = i845_cursor_max_stride;
14949 cursor->update_plane = i845_update_cursor;
14950 cursor->disable_plane = i845_disable_cursor;
14951 cursor->get_hw_state = i845_cursor_get_hw_state;
14952 cursor->check_plane = i845_check_cursor;
14954 cursor->max_stride = i9xx_cursor_max_stride;
14955 cursor->update_plane = i9xx_update_cursor;
14956 cursor->disable_plane = i9xx_disable_cursor;
14957 cursor->get_hw_state = i9xx_cursor_get_hw_state;
14958 cursor->check_plane = i9xx_check_cursor;
14961 cursor->cursor.base = ~0;
14962 cursor->cursor.cntl = ~0;
14964 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
14965 cursor->cursor.size = ~0;
14967 possible_crtcs = BIT(pipe);
14969 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
14970 possible_crtcs, &intel_cursor_plane_funcs,
14971 intel_cursor_formats,
14972 ARRAY_SIZE(intel_cursor_formats),
14973 cursor_format_modifiers,
14974 DRM_PLANE_TYPE_CURSOR,
14975 "cursor %c", pipe_name(pipe));
14979 if (INTEL_GEN(dev_priv) >= 4)
14980 drm_plane_create_rotation_property(&cursor->base,
14982 DRM_MODE_ROTATE_0 |
14983 DRM_MODE_ROTATE_180);
14985 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
14990 intel_plane_free(cursor);
14992 return ERR_PTR(ret);
14995 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
14996 struct intel_crtc_state *crtc_state)
14998 struct intel_crtc_scaler_state *scaler_state =
14999 &crtc_state->scaler_state;
15000 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
15003 crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[crtc->pipe];
15004 if (!crtc->num_scalers)
15007 for (i = 0; i < crtc->num_scalers; i++) {
15008 struct intel_scaler *scaler = &scaler_state->scalers[i];
15010 scaler->in_use = 0;
15014 scaler_state->scaler_id = -1;
15017 #define INTEL_CRTC_FUNCS \
15018 .gamma_set = drm_atomic_helper_legacy_gamma_set, \
15019 .set_config = drm_atomic_helper_set_config, \
15020 .destroy = intel_crtc_destroy, \
15021 .page_flip = drm_atomic_helper_page_flip, \
15022 .atomic_duplicate_state = intel_crtc_duplicate_state, \
15023 .atomic_destroy_state = intel_crtc_destroy_state, \
15024 .set_crc_source = intel_crtc_set_crc_source, \
15025 .verify_crc_source = intel_crtc_verify_crc_source, \
15026 .get_crc_sources = intel_crtc_get_crc_sources
15028 static const struct drm_crtc_funcs bdw_crtc_funcs = {
15031 .get_vblank_counter = g4x_get_vblank_counter,
15032 .enable_vblank = bdw_enable_vblank,
15033 .disable_vblank = bdw_disable_vblank,
15036 static const struct drm_crtc_funcs ilk_crtc_funcs = {
15039 .get_vblank_counter = g4x_get_vblank_counter,
15040 .enable_vblank = ilk_enable_vblank,
15041 .disable_vblank = ilk_disable_vblank,
15044 static const struct drm_crtc_funcs g4x_crtc_funcs = {
15047 .get_vblank_counter = g4x_get_vblank_counter,
15048 .enable_vblank = i965_enable_vblank,
15049 .disable_vblank = i965_disable_vblank,
15052 static const struct drm_crtc_funcs i965_crtc_funcs = {
15055 .get_vblank_counter = i915_get_vblank_counter,
15056 .enable_vblank = i965_enable_vblank,
15057 .disable_vblank = i965_disable_vblank,
15060 static const struct drm_crtc_funcs i945gm_crtc_funcs = {
15063 .get_vblank_counter = i915_get_vblank_counter,
15064 .enable_vblank = i945gm_enable_vblank,
15065 .disable_vblank = i945gm_disable_vblank,
15068 static const struct drm_crtc_funcs i915_crtc_funcs = {
15071 .get_vblank_counter = i915_get_vblank_counter,
15072 .enable_vblank = i8xx_enable_vblank,
15073 .disable_vblank = i8xx_disable_vblank,
15076 static const struct drm_crtc_funcs i8xx_crtc_funcs = {
15079 /* no hw vblank counter */
15080 .enable_vblank = i8xx_enable_vblank,
15081 .disable_vblank = i8xx_disable_vblank,
15084 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
15086 const struct drm_crtc_funcs *funcs;
15087 struct intel_crtc *intel_crtc;
15088 struct intel_crtc_state *crtc_state = NULL;
15089 struct intel_plane *primary = NULL;
15090 struct intel_plane *cursor = NULL;
15093 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
15097 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
15102 __drm_atomic_helper_crtc_reset(&intel_crtc->base, &crtc_state->base);
15103 intel_crtc->config = crtc_state;
15105 primary = intel_primary_plane_create(dev_priv, pipe);
15106 if (IS_ERR(primary)) {
15107 ret = PTR_ERR(primary);
15110 intel_crtc->plane_ids_mask |= BIT(primary->id);
15112 for_each_sprite(dev_priv, pipe, sprite) {
15113 struct intel_plane *plane;
15115 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
15116 if (IS_ERR(plane)) {
15117 ret = PTR_ERR(plane);
15120 intel_crtc->plane_ids_mask |= BIT(plane->id);
15123 cursor = intel_cursor_plane_create(dev_priv, pipe);
15124 if (IS_ERR(cursor)) {
15125 ret = PTR_ERR(cursor);
15128 intel_crtc->plane_ids_mask |= BIT(cursor->id);
15130 if (HAS_GMCH(dev_priv)) {
15131 if (IS_CHERRYVIEW(dev_priv) ||
15132 IS_VALLEYVIEW(dev_priv) || IS_G4X(dev_priv))
15133 funcs = &g4x_crtc_funcs;
15134 else if (IS_GEN(dev_priv, 4))
15135 funcs = &i965_crtc_funcs;
15136 else if (IS_I945GM(dev_priv))
15137 funcs = &i945gm_crtc_funcs;
15138 else if (IS_GEN(dev_priv, 3))
15139 funcs = &i915_crtc_funcs;
15141 funcs = &i8xx_crtc_funcs;
15143 if (INTEL_GEN(dev_priv) >= 8)
15144 funcs = &bdw_crtc_funcs;
15146 funcs = &ilk_crtc_funcs;
15149 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
15150 &primary->base, &cursor->base,
15151 funcs, "pipe %c", pipe_name(pipe));
15155 intel_crtc->pipe = pipe;
15157 /* initialize shared scalers */
15158 intel_crtc_init_scalers(intel_crtc, crtc_state);
15160 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
15161 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
15162 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
15164 if (INTEL_GEN(dev_priv) < 9) {
15165 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
15167 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
15168 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
15169 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
15172 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
15174 intel_color_init(intel_crtc);
15176 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
15182 * drm_mode_config_cleanup() will free up any
15183 * crtcs/planes already initialized.
15191 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
15192 struct drm_file *file)
15194 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
15195 struct drm_crtc *drmmode_crtc;
15196 struct intel_crtc *crtc;
15198 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
15202 crtc = to_intel_crtc(drmmode_crtc);
15203 pipe_from_crtc_id->pipe = crtc->pipe;
15208 static int intel_encoder_clones(struct intel_encoder *encoder)
15210 struct drm_device *dev = encoder->base.dev;
15211 struct intel_encoder *source_encoder;
15212 int index_mask = 0;
15215 for_each_intel_encoder(dev, source_encoder) {
15216 if (encoders_cloneable(encoder, source_encoder))
15217 index_mask |= (1 << entry);
15225 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
15227 if (!IS_MOBILE(dev_priv))
15230 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
15233 if (IS_GEN(dev_priv, 5) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
15239 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
15241 if (INTEL_GEN(dev_priv) >= 9)
15244 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
15247 if (HAS_PCH_LPT_H(dev_priv) &&
15248 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
15251 /* DDI E can't be used if DDI A requires 4 lanes */
15252 if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
15255 if (!dev_priv->vbt.int_crt_support)
15261 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
15266 if (HAS_DDI(dev_priv))
15269 * This w/a is needed at least on CPT/PPT, but to be sure apply it
15270 * everywhere where registers can be write protected.
15272 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
15277 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
15278 u32 val = I915_READ(PP_CONTROL(pps_idx));
15280 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
15281 I915_WRITE(PP_CONTROL(pps_idx), val);
15285 static void intel_pps_init(struct drm_i915_private *dev_priv)
15287 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
15288 dev_priv->pps_mmio_base = PCH_PPS_BASE;
15289 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
15290 dev_priv->pps_mmio_base = VLV_PPS_BASE;
15292 dev_priv->pps_mmio_base = PPS_BASE;
15294 intel_pps_unlock_regs_wa(dev_priv);
15297 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
15299 struct intel_encoder *encoder;
15300 bool dpd_is_edp = false;
15302 intel_pps_init(dev_priv);
15304 if (!HAS_DISPLAY(dev_priv))
15307 if (IS_ELKHARTLAKE(dev_priv)) {
15308 intel_ddi_init(dev_priv, PORT_A);
15309 intel_ddi_init(dev_priv, PORT_B);
15310 intel_ddi_init(dev_priv, PORT_C);
15311 intel_ddi_init(dev_priv, PORT_D);
15312 icl_dsi_init(dev_priv);
15313 } else if (INTEL_GEN(dev_priv) >= 11) {
15314 intel_ddi_init(dev_priv, PORT_A);
15315 intel_ddi_init(dev_priv, PORT_B);
15316 intel_ddi_init(dev_priv, PORT_C);
15317 intel_ddi_init(dev_priv, PORT_D);
15318 intel_ddi_init(dev_priv, PORT_E);
15320 * On some ICL SKUs port F is not present. No strap bits for
15321 * this, so rely on VBT.
15322 * Work around broken VBTs on SKUs known to have no port F.
15324 if (IS_ICL_WITH_PORT_F(dev_priv) &&
15325 intel_bios_is_port_present(dev_priv, PORT_F))
15326 intel_ddi_init(dev_priv, PORT_F);
15328 icl_dsi_init(dev_priv);
15329 } else if (IS_GEN9_LP(dev_priv)) {
15331 * FIXME: Broxton doesn't support port detection via the
15332 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
15333 * detect the ports.
15335 intel_ddi_init(dev_priv, PORT_A);
15336 intel_ddi_init(dev_priv, PORT_B);
15337 intel_ddi_init(dev_priv, PORT_C);
15339 vlv_dsi_init(dev_priv);
15340 } else if (HAS_DDI(dev_priv)) {
15343 if (intel_ddi_crt_present(dev_priv))
15344 intel_crt_init(dev_priv);
15347 * Haswell uses DDI functions to detect digital outputs.
15348 * On SKL pre-D0 the strap isn't connected, so we assume
15351 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
15352 /* WaIgnoreDDIAStrap: skl */
15353 if (found || IS_GEN9_BC(dev_priv))
15354 intel_ddi_init(dev_priv, PORT_A);
15356 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
15358 found = I915_READ(SFUSE_STRAP);
15360 if (found & SFUSE_STRAP_DDIB_DETECTED)
15361 intel_ddi_init(dev_priv, PORT_B);
15362 if (found & SFUSE_STRAP_DDIC_DETECTED)
15363 intel_ddi_init(dev_priv, PORT_C);
15364 if (found & SFUSE_STRAP_DDID_DETECTED)
15365 intel_ddi_init(dev_priv, PORT_D);
15366 if (found & SFUSE_STRAP_DDIF_DETECTED)
15367 intel_ddi_init(dev_priv, PORT_F);
15369 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
15371 if (IS_GEN9_BC(dev_priv) &&
15372 intel_bios_is_port_present(dev_priv, PORT_E))
15373 intel_ddi_init(dev_priv, PORT_E);
15375 } else if (HAS_PCH_SPLIT(dev_priv)) {
15379 * intel_edp_init_connector() depends on this completing first,
15380 * to prevent the registration of both eDP and LVDS and the
15381 * incorrect sharing of the PPS.
15383 intel_lvds_init(dev_priv);
15384 intel_crt_init(dev_priv);
15386 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
15388 if (ilk_has_edp_a(dev_priv))
15389 intel_dp_init(dev_priv, DP_A, PORT_A);
15391 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
15392 /* PCH SDVOB multiplex with HDMIB */
15393 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
15395 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
15396 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
15397 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
15400 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
15401 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
15403 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
15404 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
15406 if (I915_READ(PCH_DP_C) & DP_DETECTED)
15407 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
15409 if (I915_READ(PCH_DP_D) & DP_DETECTED)
15410 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
15411 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
15412 bool has_edp, has_port;
15414 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
15415 intel_crt_init(dev_priv);
15418 * The DP_DETECTED bit is the latched state of the DDC
15419 * SDA pin at boot. However since eDP doesn't require DDC
15420 * (no way to plug in a DP->HDMI dongle) the DDC pins for
15421 * eDP ports may have been muxed to an alternate function.
15422 * Thus we can't rely on the DP_DETECTED bit alone to detect
15423 * eDP ports. Consult the VBT as well as DP_DETECTED to
15424 * detect eDP ports.
15426 * Sadly the straps seem to be missing sometimes even for HDMI
15427 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
15428 * and VBT for the presence of the port. Additionally we can't
15429 * trust the port type the VBT declares as we've seen at least
15430 * HDMI ports that the VBT claim are DP or eDP.
15432 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
15433 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
15434 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
15435 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
15436 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
15437 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
15439 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
15440 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
15441 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
15442 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
15443 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
15444 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
15446 if (IS_CHERRYVIEW(dev_priv)) {
15448 * eDP not supported on port D,
15449 * so no need to worry about it
15451 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
15452 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
15453 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
15454 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
15455 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
15458 vlv_dsi_init(dev_priv);
15459 } else if (IS_PINEVIEW(dev_priv)) {
15460 intel_lvds_init(dev_priv);
15461 intel_crt_init(dev_priv);
15462 } else if (IS_GEN_RANGE(dev_priv, 3, 4)) {
15463 bool found = false;
15465 if (IS_MOBILE(dev_priv))
15466 intel_lvds_init(dev_priv);
15468 intel_crt_init(dev_priv);
15470 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
15471 DRM_DEBUG_KMS("probing SDVOB\n");
15472 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
15473 if (!found && IS_G4X(dev_priv)) {
15474 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
15475 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
15478 if (!found && IS_G4X(dev_priv))
15479 intel_dp_init(dev_priv, DP_B, PORT_B);
15482 /* Before G4X SDVOC doesn't have its own detect register */
15484 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
15485 DRM_DEBUG_KMS("probing SDVOC\n");
15486 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
15489 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
15491 if (IS_G4X(dev_priv)) {
15492 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
15493 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
15495 if (IS_G4X(dev_priv))
15496 intel_dp_init(dev_priv, DP_C, PORT_C);
15499 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
15500 intel_dp_init(dev_priv, DP_D, PORT_D);
15502 if (SUPPORTS_TV(dev_priv))
15503 intel_tv_init(dev_priv);
15504 } else if (IS_GEN(dev_priv, 2)) {
15505 if (IS_I85X(dev_priv))
15506 intel_lvds_init(dev_priv);
15508 intel_crt_init(dev_priv);
15509 intel_dvo_init(dev_priv);
15512 intel_psr_init(dev_priv);
15514 for_each_intel_encoder(&dev_priv->drm, encoder) {
15515 encoder->base.possible_crtcs = encoder->crtc_mask;
15516 encoder->base.possible_clones =
15517 intel_encoder_clones(encoder);
15520 intel_init_pch_refclk(dev_priv);
15522 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
15525 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
15527 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
15528 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
15530 drm_framebuffer_cleanup(fb);
15532 i915_gem_object_lock(obj);
15533 WARN_ON(!obj->framebuffer_references--);
15534 i915_gem_object_unlock(obj);
15536 i915_gem_object_put(obj);
15541 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
15542 struct drm_file *file,
15543 unsigned int *handle)
15545 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
15547 if (obj->userptr.mm) {
15548 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
15552 return drm_gem_handle_create(file, &obj->base, handle);
15555 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
15556 struct drm_file *file,
15557 unsigned flags, unsigned color,
15558 struct drm_clip_rect *clips,
15559 unsigned num_clips)
15561 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
15563 i915_gem_object_flush_if_display(obj);
15564 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
15569 static const struct drm_framebuffer_funcs intel_fb_funcs = {
15570 .destroy = intel_user_framebuffer_destroy,
15571 .create_handle = intel_user_framebuffer_create_handle,
15572 .dirty = intel_user_framebuffer_dirty,
15575 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
15576 struct drm_i915_gem_object *obj,
15577 struct drm_mode_fb_cmd2 *mode_cmd)
15579 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
15580 struct drm_framebuffer *fb = &intel_fb->base;
15582 unsigned int tiling, stride;
15586 i915_gem_object_lock(obj);
15587 obj->framebuffer_references++;
15588 tiling = i915_gem_object_get_tiling(obj);
15589 stride = i915_gem_object_get_stride(obj);
15590 i915_gem_object_unlock(obj);
15592 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
15594 * If there's a fence, enforce that
15595 * the fb modifier and tiling mode match.
15597 if (tiling != I915_TILING_NONE &&
15598 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
15599 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
15603 if (tiling == I915_TILING_X) {
15604 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
15605 } else if (tiling == I915_TILING_Y) {
15606 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
15611 if (!drm_any_plane_has_format(&dev_priv->drm,
15612 mode_cmd->pixel_format,
15613 mode_cmd->modifier[0])) {
15614 struct drm_format_name_buf format_name;
15616 DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n",
15617 drm_get_format_name(mode_cmd->pixel_format,
15619 mode_cmd->modifier[0]);
15624 * gen2/3 display engine uses the fence if present,
15625 * so the tiling mode must match the fb modifier exactly.
15627 if (INTEL_GEN(dev_priv) < 4 &&
15628 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
15629 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
15633 max_stride = intel_fb_max_stride(dev_priv, mode_cmd->pixel_format,
15634 mode_cmd->modifier[0]);
15635 if (mode_cmd->pitches[0] > max_stride) {
15636 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
15637 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
15638 "tiled" : "linear",
15639 mode_cmd->pitches[0], max_stride);
15644 * If there's a fence, enforce that
15645 * the fb pitch and fence stride match.
15647 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
15648 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
15649 mode_cmd->pitches[0], stride);
15653 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
15654 if (mode_cmd->offsets[0] != 0)
15657 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
15659 for (i = 0; i < fb->format->num_planes; i++) {
15660 u32 stride_alignment;
15662 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
15663 DRM_DEBUG_KMS("bad plane %d handle\n", i);
15667 stride_alignment = intel_fb_stride_alignment(fb, i);
15670 * Display WA #0531: skl,bxt,kbl,glk
15672 * Render decompression and plane width > 3840
15673 * combined with horizontal panning requires the
15674 * plane stride to be a multiple of 4. We'll just
15675 * require the entire fb to accommodate that to avoid
15676 * potential runtime errors at plane configuration time.
15678 if (IS_GEN(dev_priv, 9) && i == 0 && fb->width > 3840 &&
15679 is_ccs_modifier(fb->modifier))
15680 stride_alignment *= 4;
15682 if (fb->pitches[i] & (stride_alignment - 1)) {
15683 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
15684 i, fb->pitches[i], stride_alignment);
15688 fb->obj[i] = &obj->base;
15691 ret = intel_fill_fb_info(dev_priv, fb);
15695 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
15697 DRM_ERROR("framebuffer init failed %d\n", ret);
15704 i915_gem_object_lock(obj);
15705 obj->framebuffer_references--;
15706 i915_gem_object_unlock(obj);
15710 static struct drm_framebuffer *
15711 intel_user_framebuffer_create(struct drm_device *dev,
15712 struct drm_file *filp,
15713 const struct drm_mode_fb_cmd2 *user_mode_cmd)
15715 struct drm_framebuffer *fb;
15716 struct drm_i915_gem_object *obj;
15717 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
15719 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
15721 return ERR_PTR(-ENOENT);
15723 fb = intel_framebuffer_create(obj, &mode_cmd);
15725 i915_gem_object_put(obj);
15730 static void intel_atomic_state_free(struct drm_atomic_state *state)
15732 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
15734 drm_atomic_state_default_release(state);
15736 i915_sw_fence_fini(&intel_state->commit_ready);
15741 static enum drm_mode_status
15742 intel_mode_valid(struct drm_device *dev,
15743 const struct drm_display_mode *mode)
15745 struct drm_i915_private *dev_priv = to_i915(dev);
15746 int hdisplay_max, htotal_max;
15747 int vdisplay_max, vtotal_max;
15750 * Can't reject DBLSCAN here because Xorg ddxen can add piles
15751 * of DBLSCAN modes to the output's mode list when they detect
15752 * the scaling mode property on the connector. And they don't
15753 * ask the kernel to validate those modes in any way until
15754 * modeset time at which point the client gets a protocol error.
15755 * So in order to not upset those clients we silently ignore the
15756 * DBLSCAN flag on such connectors. For other connectors we will
15757 * reject modes with the DBLSCAN flag in encoder->compute_config().
15758 * And we always reject DBLSCAN modes in connector->mode_valid()
15759 * as we never want such modes on the connector's mode list.
15762 if (mode->vscan > 1)
15763 return MODE_NO_VSCAN;
15765 if (mode->flags & DRM_MODE_FLAG_HSKEW)
15766 return MODE_H_ILLEGAL;
15768 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
15769 DRM_MODE_FLAG_NCSYNC |
15770 DRM_MODE_FLAG_PCSYNC))
15773 if (mode->flags & (DRM_MODE_FLAG_BCAST |
15774 DRM_MODE_FLAG_PIXMUX |
15775 DRM_MODE_FLAG_CLKDIV2))
15778 if (INTEL_GEN(dev_priv) >= 9 ||
15779 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
15780 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
15781 vdisplay_max = 4096;
15784 } else if (INTEL_GEN(dev_priv) >= 3) {
15785 hdisplay_max = 4096;
15786 vdisplay_max = 4096;
15790 hdisplay_max = 2048;
15791 vdisplay_max = 2048;
15796 if (mode->hdisplay > hdisplay_max ||
15797 mode->hsync_start > htotal_max ||
15798 mode->hsync_end > htotal_max ||
15799 mode->htotal > htotal_max)
15800 return MODE_H_ILLEGAL;
15802 if (mode->vdisplay > vdisplay_max ||
15803 mode->vsync_start > vtotal_max ||
15804 mode->vsync_end > vtotal_max ||
15805 mode->vtotal > vtotal_max)
15806 return MODE_V_ILLEGAL;
15811 static const struct drm_mode_config_funcs intel_mode_funcs = {
15812 .fb_create = intel_user_framebuffer_create,
15813 .get_format_info = intel_get_format_info,
15814 .output_poll_changed = intel_fbdev_output_poll_changed,
15815 .mode_valid = intel_mode_valid,
15816 .atomic_check = intel_atomic_check,
15817 .atomic_commit = intel_atomic_commit,
15818 .atomic_state_alloc = intel_atomic_state_alloc,
15819 .atomic_state_clear = intel_atomic_state_clear,
15820 .atomic_state_free = intel_atomic_state_free,
15824 * intel_init_display_hooks - initialize the display modesetting hooks
15825 * @dev_priv: device private
15827 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
15829 intel_init_cdclk_hooks(dev_priv);
15831 if (INTEL_GEN(dev_priv) >= 9) {
15832 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
15833 dev_priv->display.get_initial_plane_config =
15834 skylake_get_initial_plane_config;
15835 dev_priv->display.crtc_compute_clock =
15836 haswell_crtc_compute_clock;
15837 dev_priv->display.crtc_enable = haswell_crtc_enable;
15838 dev_priv->display.crtc_disable = haswell_crtc_disable;
15839 } else if (HAS_DDI(dev_priv)) {
15840 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
15841 dev_priv->display.get_initial_plane_config =
15842 i9xx_get_initial_plane_config;
15843 dev_priv->display.crtc_compute_clock =
15844 haswell_crtc_compute_clock;
15845 dev_priv->display.crtc_enable = haswell_crtc_enable;
15846 dev_priv->display.crtc_disable = haswell_crtc_disable;
15847 } else if (HAS_PCH_SPLIT(dev_priv)) {
15848 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
15849 dev_priv->display.get_initial_plane_config =
15850 i9xx_get_initial_plane_config;
15851 dev_priv->display.crtc_compute_clock =
15852 ironlake_crtc_compute_clock;
15853 dev_priv->display.crtc_enable = ironlake_crtc_enable;
15854 dev_priv->display.crtc_disable = ironlake_crtc_disable;
15855 } else if (IS_CHERRYVIEW(dev_priv)) {
15856 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15857 dev_priv->display.get_initial_plane_config =
15858 i9xx_get_initial_plane_config;
15859 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
15860 dev_priv->display.crtc_enable = valleyview_crtc_enable;
15861 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15862 } else if (IS_VALLEYVIEW(dev_priv)) {
15863 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15864 dev_priv->display.get_initial_plane_config =
15865 i9xx_get_initial_plane_config;
15866 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
15867 dev_priv->display.crtc_enable = valleyview_crtc_enable;
15868 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15869 } else if (IS_G4X(dev_priv)) {
15870 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15871 dev_priv->display.get_initial_plane_config =
15872 i9xx_get_initial_plane_config;
15873 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
15874 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15875 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15876 } else if (IS_PINEVIEW(dev_priv)) {
15877 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15878 dev_priv->display.get_initial_plane_config =
15879 i9xx_get_initial_plane_config;
15880 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
15881 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15882 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15883 } else if (!IS_GEN(dev_priv, 2)) {
15884 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15885 dev_priv->display.get_initial_plane_config =
15886 i9xx_get_initial_plane_config;
15887 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
15888 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15889 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15891 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15892 dev_priv->display.get_initial_plane_config =
15893 i9xx_get_initial_plane_config;
15894 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
15895 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15896 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15899 if (IS_GEN(dev_priv, 5)) {
15900 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
15901 } else if (IS_GEN(dev_priv, 6)) {
15902 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
15903 } else if (IS_IVYBRIDGE(dev_priv)) {
15904 /* FIXME: detect B0+ stepping and use auto training */
15905 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
15906 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
15907 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
15910 if (INTEL_GEN(dev_priv) >= 9)
15911 dev_priv->display.update_crtcs = skl_update_crtcs;
15913 dev_priv->display.update_crtcs = intel_update_crtcs;
15916 static i915_reg_t i915_vgacntrl_reg(struct drm_i915_private *dev_priv)
15918 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
15919 return VLV_VGACNTRL;
15920 else if (INTEL_GEN(dev_priv) >= 5)
15921 return CPU_VGACNTRL;
15926 /* Disable the VGA plane that we never use */
15927 static void i915_disable_vga(struct drm_i915_private *dev_priv)
15929 struct pci_dev *pdev = dev_priv->drm.pdev;
15931 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
15933 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
15934 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
15935 outb(SR01, VGA_SR_INDEX);
15936 sr1 = inb(VGA_SR_DATA);
15937 outb(sr1 | 1<<5, VGA_SR_DATA);
15938 vga_put(pdev, VGA_RSRC_LEGACY_IO);
15941 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
15942 POSTING_READ(vga_reg);
15945 void intel_modeset_init_hw(struct drm_device *dev)
15947 struct drm_i915_private *dev_priv = to_i915(dev);
15949 intel_update_cdclk(dev_priv);
15950 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
15951 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
15955 * Calculate what we think the watermarks should be for the state we've read
15956 * out of the hardware and then immediately program those watermarks so that
15957 * we ensure the hardware settings match our internal state.
15959 * We can calculate what we think WM's should be by creating a duplicate of the
15960 * current state (which was constructed during hardware readout) and running it
15961 * through the atomic check code to calculate new watermark values in the
15964 static void sanitize_watermarks(struct drm_device *dev)
15966 struct drm_i915_private *dev_priv = to_i915(dev);
15967 struct drm_atomic_state *state;
15968 struct intel_atomic_state *intel_state;
15969 struct intel_crtc *crtc;
15970 struct intel_crtc_state *crtc_state;
15971 struct drm_modeset_acquire_ctx ctx;
15975 /* Only supported on platforms that use atomic watermark design */
15976 if (!dev_priv->display.optimize_watermarks)
15980 * We need to hold connection_mutex before calling duplicate_state so
15981 * that the connector loop is protected.
15983 drm_modeset_acquire_init(&ctx, 0);
15985 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15986 if (ret == -EDEADLK) {
15987 drm_modeset_backoff(&ctx);
15989 } else if (WARN_ON(ret)) {
15993 state = drm_atomic_helper_duplicate_state(dev, &ctx);
15994 if (WARN_ON(IS_ERR(state)))
15997 intel_state = to_intel_atomic_state(state);
16000 * Hardware readout is the only time we don't want to calculate
16001 * intermediate watermarks (since we don't trust the current
16004 if (!HAS_GMCH(dev_priv))
16005 intel_state->skip_intermediate_wm = true;
16007 ret = intel_atomic_check(dev, state);
16010 * If we fail here, it means that the hardware appears to be
16011 * programmed in a way that shouldn't be possible, given our
16012 * understanding of watermark requirements. This might mean a
16013 * mistake in the hardware readout code or a mistake in the
16014 * watermark calculations for a given platform. Raise a WARN
16015 * so that this is noticeable.
16017 * If this actually happens, we'll have to just leave the
16018 * BIOS-programmed watermarks untouched and hope for the best.
16020 WARN(true, "Could not determine valid watermarks for inherited state\n");
16024 /* Write calculated watermark values back */
16025 for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) {
16026 crtc_state->wm.need_postvbl_update = true;
16027 dev_priv->display.optimize_watermarks(intel_state, crtc_state);
16029 to_intel_crtc_state(crtc->base.state)->wm = crtc_state->wm;
16033 drm_atomic_state_put(state);
16035 drm_modeset_drop_locks(&ctx);
16036 drm_modeset_acquire_fini(&ctx);
16039 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
16041 if (IS_GEN(dev_priv, 5)) {
16043 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
16045 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
16046 } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) {
16047 dev_priv->fdi_pll_freq = 270000;
16052 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
16055 static int intel_initial_commit(struct drm_device *dev)
16057 struct drm_atomic_state *state = NULL;
16058 struct drm_modeset_acquire_ctx ctx;
16059 struct drm_crtc *crtc;
16060 struct drm_crtc_state *crtc_state;
16063 state = drm_atomic_state_alloc(dev);
16067 drm_modeset_acquire_init(&ctx, 0);
16070 state->acquire_ctx = &ctx;
16072 drm_for_each_crtc(crtc, dev) {
16073 crtc_state = drm_atomic_get_crtc_state(state, crtc);
16074 if (IS_ERR(crtc_state)) {
16075 ret = PTR_ERR(crtc_state);
16079 if (crtc_state->active) {
16080 ret = drm_atomic_add_affected_planes(state, crtc);
16085 * FIXME hack to force a LUT update to avoid the
16086 * plane update forcing the pipe gamma on without
16087 * having a proper LUT loaded. Remove once we
16088 * have readout for pipe gamma enable.
16090 crtc_state->color_mgmt_changed = true;
16094 ret = drm_atomic_commit(state);
16097 if (ret == -EDEADLK) {
16098 drm_atomic_state_clear(state);
16099 drm_modeset_backoff(&ctx);
16103 drm_atomic_state_put(state);
16105 drm_modeset_drop_locks(&ctx);
16106 drm_modeset_acquire_fini(&ctx);
16111 int intel_modeset_init(struct drm_device *dev)
16113 struct drm_i915_private *dev_priv = to_i915(dev);
16114 struct i915_ggtt *ggtt = &dev_priv->ggtt;
16116 struct intel_crtc *crtc;
16119 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
16121 drm_mode_config_init(dev);
16123 ret = intel_bw_init(dev_priv);
16127 dev->mode_config.min_width = 0;
16128 dev->mode_config.min_height = 0;
16130 dev->mode_config.preferred_depth = 24;
16131 dev->mode_config.prefer_shadow = 1;
16133 dev->mode_config.allow_fb_modifiers = true;
16135 dev->mode_config.funcs = &intel_mode_funcs;
16137 init_llist_head(&dev_priv->atomic_helper.free_list);
16138 INIT_WORK(&dev_priv->atomic_helper.free_work,
16139 intel_atomic_helper_free_state_worker);
16141 intel_init_quirks(dev_priv);
16143 intel_fbc_init(dev_priv);
16145 intel_init_pm(dev_priv);
16148 * There may be no VBT; and if the BIOS enabled SSC we can
16149 * just keep using it to avoid unnecessary flicker. Whereas if the
16150 * BIOS isn't using it, don't assume it will work even if the VBT
16151 * indicates as much.
16153 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
16154 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
16157 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
16158 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
16159 bios_lvds_use_ssc ? "en" : "dis",
16160 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
16161 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
16166 * Maximum framebuffer dimensions, chosen to match
16167 * the maximum render engine surface size on gen4+.
16169 if (INTEL_GEN(dev_priv) >= 7) {
16170 dev->mode_config.max_width = 16384;
16171 dev->mode_config.max_height = 16384;
16172 } else if (INTEL_GEN(dev_priv) >= 4) {
16173 dev->mode_config.max_width = 8192;
16174 dev->mode_config.max_height = 8192;
16175 } else if (IS_GEN(dev_priv, 3)) {
16176 dev->mode_config.max_width = 4096;
16177 dev->mode_config.max_height = 4096;
16179 dev->mode_config.max_width = 2048;
16180 dev->mode_config.max_height = 2048;
16183 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
16184 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
16185 dev->mode_config.cursor_height = 1023;
16186 } else if (IS_GEN(dev_priv, 2)) {
16187 dev->mode_config.cursor_width = 64;
16188 dev->mode_config.cursor_height = 64;
16190 dev->mode_config.cursor_width = 256;
16191 dev->mode_config.cursor_height = 256;
16194 dev->mode_config.fb_base = ggtt->gmadr.start;
16196 DRM_DEBUG_KMS("%d display pipe%s available.\n",
16197 INTEL_INFO(dev_priv)->num_pipes,
16198 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
16200 for_each_pipe(dev_priv, pipe) {
16201 ret = intel_crtc_init(dev_priv, pipe);
16203 drm_mode_config_cleanup(dev);
16208 intel_shared_dpll_init(dev);
16209 intel_update_fdi_pll_freq(dev_priv);
16211 intel_update_czclk(dev_priv);
16212 intel_modeset_init_hw(dev);
16214 intel_hdcp_component_init(dev_priv);
16216 if (dev_priv->max_cdclk_freq == 0)
16217 intel_update_max_cdclk(dev_priv);
16219 /* Just disable it once at startup */
16220 i915_disable_vga(dev_priv);
16221 intel_setup_outputs(dev_priv);
16223 drm_modeset_lock_all(dev);
16224 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
16225 drm_modeset_unlock_all(dev);
16227 for_each_intel_crtc(dev, crtc) {
16228 struct intel_initial_plane_config plane_config = {};
16234 * Note that reserving the BIOS fb up front prevents us
16235 * from stuffing other stolen allocations like the ring
16236 * on top. This prevents some ugliness at boot time, and
16237 * can even allow for smooth boot transitions if the BIOS
16238 * fb is large enough for the active pipe configuration.
16240 dev_priv->display.get_initial_plane_config(crtc,
16244 * If the fb is shared between multiple heads, we'll
16245 * just get the first one.
16247 intel_find_initial_plane_obj(crtc, &plane_config);
16251 * Make sure hardware watermarks really match the state we read out.
16252 * Note that we need to do this after reconstructing the BIOS fb's
16253 * since the watermark calculation done here will use pstate->fb.
16255 if (!HAS_GMCH(dev_priv))
16256 sanitize_watermarks(dev);
16259 * Force all active planes to recompute their states. So that on
16260 * mode_setcrtc after probe, all the intel_plane_state variables
16261 * are already calculated and there is no assert_plane warnings
16264 ret = intel_initial_commit(dev);
16266 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
16271 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
16273 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
16274 /* 640x480@60Hz, ~25175 kHz */
16275 struct dpll clock = {
16285 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
16287 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
16288 pipe_name(pipe), clock.vco, clock.dot);
16290 fp = i9xx_dpll_compute_fp(&clock);
16291 dpll = DPLL_DVO_2X_MODE |
16292 DPLL_VGA_MODE_DIS |
16293 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
16294 PLL_P2_DIVIDE_BY_4 |
16295 PLL_REF_INPUT_DREFCLK |
16298 I915_WRITE(FP0(pipe), fp);
16299 I915_WRITE(FP1(pipe), fp);
16301 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
16302 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
16303 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
16304 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
16305 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
16306 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
16307 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
16310 * Apparently we need to have VGA mode enabled prior to changing
16311 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
16312 * dividers, even though the register value does change.
16314 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
16315 I915_WRITE(DPLL(pipe), dpll);
16317 /* Wait for the clocks to stabilize. */
16318 POSTING_READ(DPLL(pipe));
16321 /* The pixel multiplier can only be updated once the
16322 * DPLL is enabled and the clocks are stable.
16324 * So write it again.
16326 I915_WRITE(DPLL(pipe), dpll);
16328 /* We do this three times for luck */
16329 for (i = 0; i < 3 ; i++) {
16330 I915_WRITE(DPLL(pipe), dpll);
16331 POSTING_READ(DPLL(pipe));
16332 udelay(150); /* wait for warmup */
16335 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
16336 POSTING_READ(PIPECONF(pipe));
16338 intel_wait_for_pipe_scanline_moving(crtc);
16341 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
16343 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
16345 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
16348 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
16349 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
16350 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
16351 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
16352 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
16354 I915_WRITE(PIPECONF(pipe), 0);
16355 POSTING_READ(PIPECONF(pipe));
16357 intel_wait_for_pipe_scanline_stopped(crtc);
16359 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
16360 POSTING_READ(DPLL(pipe));
16364 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
16366 struct intel_crtc *crtc;
16368 if (INTEL_GEN(dev_priv) >= 4)
16371 for_each_intel_crtc(&dev_priv->drm, crtc) {
16372 struct intel_plane *plane =
16373 to_intel_plane(crtc->base.primary);
16374 struct intel_crtc *plane_crtc;
16377 if (!plane->get_hw_state(plane, &pipe))
16380 if (pipe == crtc->pipe)
16383 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
16384 plane->base.base.id, plane->base.name);
16386 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
16387 intel_plane_disable_noatomic(plane_crtc, plane);
16391 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
16393 struct drm_device *dev = crtc->base.dev;
16394 struct intel_encoder *encoder;
16396 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
16402 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
16404 struct drm_device *dev = encoder->base.dev;
16405 struct intel_connector *connector;
16407 for_each_connector_on_encoder(dev, &encoder->base, connector)
16413 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
16414 enum pipe pch_transcoder)
16416 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
16417 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
16420 static void intel_sanitize_crtc(struct intel_crtc *crtc,
16421 struct drm_modeset_acquire_ctx *ctx)
16423 struct drm_device *dev = crtc->base.dev;
16424 struct drm_i915_private *dev_priv = to_i915(dev);
16425 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
16426 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
16428 /* Clear any frame start delays used for debugging left by the BIOS */
16429 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
16430 i915_reg_t reg = PIPECONF(cpu_transcoder);
16433 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
16436 if (crtc_state->base.active) {
16437 struct intel_plane *plane;
16439 /* Disable everything but the primary plane */
16440 for_each_intel_plane_on_crtc(dev, crtc, plane) {
16441 const struct intel_plane_state *plane_state =
16442 to_intel_plane_state(plane->base.state);
16444 if (plane_state->base.visible &&
16445 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
16446 intel_plane_disable_noatomic(crtc, plane);
16450 * Disable any background color set by the BIOS, but enable the
16451 * gamma and CSC to match how we program our planes.
16453 if (INTEL_GEN(dev_priv) >= 9)
16454 I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe),
16455 SKL_BOTTOM_COLOR_GAMMA_ENABLE |
16456 SKL_BOTTOM_COLOR_CSC_ENABLE);
16459 /* Adjust the state of the output pipe according to whether we
16460 * have active connectors/encoders. */
16461 if (crtc_state->base.active && !intel_crtc_has_encoders(crtc))
16462 intel_crtc_disable_noatomic(&crtc->base, ctx);
16464 if (crtc_state->base.active || HAS_GMCH(dev_priv)) {
16466 * We start out with underrun reporting disabled to avoid races.
16467 * For correct bookkeeping mark this on active crtcs.
16469 * Also on gmch platforms we dont have any hardware bits to
16470 * disable the underrun reporting. Which means we need to start
16471 * out with underrun reporting disabled also on inactive pipes,
16472 * since otherwise we'll complain about the garbage we read when
16473 * e.g. coming up after runtime pm.
16475 * No protection against concurrent access is required - at
16476 * worst a fifo underrun happens which also sets this to false.
16478 crtc->cpu_fifo_underrun_disabled = true;
16480 * We track the PCH trancoder underrun reporting state
16481 * within the crtc. With crtc for pipe A housing the underrun
16482 * reporting state for PCH transcoder A, crtc for pipe B housing
16483 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
16484 * and marking underrun reporting as disabled for the non-existing
16485 * PCH transcoders B and C would prevent enabling the south
16486 * error interrupt (see cpt_can_enable_serr_int()).
16488 if (has_pch_trancoder(dev_priv, crtc->pipe))
16489 crtc->pch_fifo_underrun_disabled = true;
16493 static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state)
16495 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
16498 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
16499 * the hardware when a high res displays plugged in. DPLL P
16500 * divider is zero, and the pipe timings are bonkers. We'll
16501 * try to disable everything in that case.
16503 * FIXME would be nice to be able to sanitize this state
16504 * without several WARNs, but for now let's take the easy
16507 return IS_GEN(dev_priv, 6) &&
16508 crtc_state->base.active &&
16509 crtc_state->shared_dpll &&
16510 crtc_state->port_clock == 0;
16513 static void intel_sanitize_encoder(struct intel_encoder *encoder)
16515 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
16516 struct intel_connector *connector;
16517 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
16518 struct intel_crtc_state *crtc_state = crtc ?
16519 to_intel_crtc_state(crtc->base.state) : NULL;
16521 /* We need to check both for a crtc link (meaning that the
16522 * encoder is active and trying to read from a pipe) and the
16523 * pipe itself being active. */
16524 bool has_active_crtc = crtc_state &&
16525 crtc_state->base.active;
16527 if (crtc_state && has_bogus_dpll_config(crtc_state)) {
16528 DRM_DEBUG_KMS("BIOS has misprogrammed the hardware. Disabling pipe %c\n",
16529 pipe_name(crtc->pipe));
16530 has_active_crtc = false;
16533 connector = intel_encoder_find_connector(encoder);
16534 if (connector && !has_active_crtc) {
16535 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
16536 encoder->base.base.id,
16537 encoder->base.name);
16539 /* Connector is active, but has no active pipe. This is
16540 * fallout from our resume register restoring. Disable
16541 * the encoder manually again. */
16543 struct drm_encoder *best_encoder;
16545 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
16546 encoder->base.base.id,
16547 encoder->base.name);
16549 /* avoid oopsing in case the hooks consult best_encoder */
16550 best_encoder = connector->base.state->best_encoder;
16551 connector->base.state->best_encoder = &encoder->base;
16553 if (encoder->disable)
16554 encoder->disable(encoder, crtc_state,
16555 connector->base.state);
16556 if (encoder->post_disable)
16557 encoder->post_disable(encoder, crtc_state,
16558 connector->base.state);
16560 connector->base.state->best_encoder = best_encoder;
16562 encoder->base.crtc = NULL;
16564 /* Inconsistent output/port/pipe state happens presumably due to
16565 * a bug in one of the get_hw_state functions. Or someplace else
16566 * in our code, like the register restore mess on resume. Clamp
16567 * things to off as a safer default. */
16569 connector->base.dpms = DRM_MODE_DPMS_OFF;
16570 connector->base.encoder = NULL;
16573 /* notify opregion of the sanitized encoder state */
16574 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
16576 if (INTEL_GEN(dev_priv) >= 11)
16577 icl_sanitize_encoder_pll_mapping(encoder);
16580 void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
16582 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
16584 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
16585 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
16586 i915_disable_vga(dev_priv);
16590 void i915_redisable_vga(struct drm_i915_private *dev_priv)
16592 intel_wakeref_t wakeref;
16595 * This function can be called both from intel_modeset_setup_hw_state or
16596 * at a very early point in our resume sequence, where the power well
16597 * structures are not yet restored. Since this function is at a very
16598 * paranoid "someone might have enabled VGA while we were not looking"
16599 * level, just check if the power well is enabled instead of trying to
16600 * follow the "don't touch the power well if we don't need it" policy
16601 * the rest of the driver uses.
16603 wakeref = intel_display_power_get_if_enabled(dev_priv,
16608 i915_redisable_vga_power_on(dev_priv);
16610 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA, wakeref);
16613 /* FIXME read out full plane state for all planes */
16614 static void readout_plane_state(struct drm_i915_private *dev_priv)
16616 struct intel_plane *plane;
16617 struct intel_crtc *crtc;
16619 for_each_intel_plane(&dev_priv->drm, plane) {
16620 struct intel_plane_state *plane_state =
16621 to_intel_plane_state(plane->base.state);
16622 struct intel_crtc_state *crtc_state;
16623 enum pipe pipe = PIPE_A;
16626 visible = plane->get_hw_state(plane, &pipe);
16628 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
16629 crtc_state = to_intel_crtc_state(crtc->base.state);
16631 intel_set_plane_visible(crtc_state, plane_state, visible);
16633 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
16634 plane->base.base.id, plane->base.name,
16635 enableddisabled(visible), pipe_name(pipe));
16638 for_each_intel_crtc(&dev_priv->drm, crtc) {
16639 struct intel_crtc_state *crtc_state =
16640 to_intel_crtc_state(crtc->base.state);
16642 fixup_active_planes(crtc_state);
16646 static void intel_modeset_readout_hw_state(struct drm_device *dev)
16648 struct drm_i915_private *dev_priv = to_i915(dev);
16650 struct intel_crtc *crtc;
16651 struct intel_encoder *encoder;
16652 struct intel_connector *connector;
16653 struct drm_connector_list_iter conn_iter;
16656 dev_priv->active_crtcs = 0;
16658 for_each_intel_crtc(dev, crtc) {
16659 struct intel_crtc_state *crtc_state =
16660 to_intel_crtc_state(crtc->base.state);
16662 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
16663 memset(crtc_state, 0, sizeof(*crtc_state));
16664 __drm_atomic_helper_crtc_reset(&crtc->base, &crtc_state->base);
16666 crtc_state->base.active = crtc_state->base.enable =
16667 dev_priv->display.get_pipe_config(crtc, crtc_state);
16669 crtc->base.enabled = crtc_state->base.enable;
16670 crtc->active = crtc_state->base.active;
16672 if (crtc_state->base.active)
16673 dev_priv->active_crtcs |= 1 << crtc->pipe;
16675 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
16676 crtc->base.base.id, crtc->base.name,
16677 enableddisabled(crtc_state->base.active));
16680 readout_plane_state(dev_priv);
16682 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
16683 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
16685 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
16686 &pll->state.hw_state);
16688 if (IS_ELKHARTLAKE(dev_priv) && pll->on &&
16689 pll->info->id == DPLL_ID_EHL_DPLL4) {
16690 pll->wakeref = intel_display_power_get(dev_priv,
16691 POWER_DOMAIN_DPLL_DC_OFF);
16694 pll->state.crtc_mask = 0;
16695 for_each_intel_crtc(dev, crtc) {
16696 struct intel_crtc_state *crtc_state =
16697 to_intel_crtc_state(crtc->base.state);
16699 if (crtc_state->base.active &&
16700 crtc_state->shared_dpll == pll)
16701 pll->state.crtc_mask |= 1 << crtc->pipe;
16703 pll->active_mask = pll->state.crtc_mask;
16705 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
16706 pll->info->name, pll->state.crtc_mask, pll->on);
16709 for_each_intel_encoder(dev, encoder) {
16712 if (encoder->get_hw_state(encoder, &pipe)) {
16713 struct intel_crtc_state *crtc_state;
16715 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
16716 crtc_state = to_intel_crtc_state(crtc->base.state);
16718 encoder->base.crtc = &crtc->base;
16719 encoder->get_config(encoder, crtc_state);
16721 encoder->base.crtc = NULL;
16724 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
16725 encoder->base.base.id, encoder->base.name,
16726 enableddisabled(encoder->base.crtc),
16730 drm_connector_list_iter_begin(dev, &conn_iter);
16731 for_each_intel_connector_iter(connector, &conn_iter) {
16732 if (connector->get_hw_state(connector)) {
16733 connector->base.dpms = DRM_MODE_DPMS_ON;
16735 encoder = connector->encoder;
16736 connector->base.encoder = &encoder->base;
16738 if (encoder->base.crtc &&
16739 encoder->base.crtc->state->active) {
16741 * This has to be done during hardware readout
16742 * because anything calling .crtc_disable may
16743 * rely on the connector_mask being accurate.
16745 encoder->base.crtc->state->connector_mask |=
16746 drm_connector_mask(&connector->base);
16747 encoder->base.crtc->state->encoder_mask |=
16748 drm_encoder_mask(&encoder->base);
16752 connector->base.dpms = DRM_MODE_DPMS_OFF;
16753 connector->base.encoder = NULL;
16755 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
16756 connector->base.base.id, connector->base.name,
16757 enableddisabled(connector->base.encoder));
16759 drm_connector_list_iter_end(&conn_iter);
16761 for_each_intel_crtc(dev, crtc) {
16762 struct intel_bw_state *bw_state =
16763 to_intel_bw_state(dev_priv->bw_obj.state);
16764 struct intel_crtc_state *crtc_state =
16765 to_intel_crtc_state(crtc->base.state);
16766 struct intel_plane *plane;
16769 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
16770 if (crtc_state->base.active) {
16771 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
16772 crtc->base.mode.hdisplay = crtc_state->pipe_src_w;
16773 crtc->base.mode.vdisplay = crtc_state->pipe_src_h;
16774 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
16775 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
16778 * The initial mode needs to be set in order to keep
16779 * the atomic core happy. It wants a valid mode if the
16780 * crtc's enabled, so we do the above call.
16782 * But we don't set all the derived state fully, hence
16783 * set a flag to indicate that a full recalculation is
16784 * needed on the next commit.
16786 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
16788 intel_crtc_compute_pixel_rate(crtc_state);
16790 if (dev_priv->display.modeset_calc_cdclk) {
16791 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
16792 if (WARN_ON(min_cdclk < 0))
16796 drm_calc_timestamping_constants(&crtc->base,
16797 &crtc_state->base.adjusted_mode);
16798 update_scanline_offset(crtc_state);
16801 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
16802 dev_priv->min_voltage_level[crtc->pipe] =
16803 crtc_state->min_voltage_level;
16805 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
16806 const struct intel_plane_state *plane_state =
16807 to_intel_plane_state(plane->base.state);
16810 * FIXME don't have the fb yet, so can't
16811 * use intel_plane_data_rate() :(
16813 if (plane_state->base.visible)
16814 crtc_state->data_rate[plane->id] =
16815 4 * crtc_state->pixel_rate;
16818 intel_bw_crtc_update(bw_state, crtc_state);
16820 intel_pipe_config_sanity_check(dev_priv, crtc_state);
16825 get_encoder_power_domains(struct drm_i915_private *dev_priv)
16827 struct intel_encoder *encoder;
16829 for_each_intel_encoder(&dev_priv->drm, encoder) {
16830 struct intel_crtc_state *crtc_state;
16832 if (!encoder->get_power_domains)
16836 * MST-primary and inactive encoders don't have a crtc state
16837 * and neither of these require any power domain references.
16839 if (!encoder->base.crtc)
16842 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
16843 encoder->get_power_domains(encoder, crtc_state);
16847 static void intel_early_display_was(struct drm_i915_private *dev_priv)
16849 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
16850 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
16851 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
16854 if (IS_HASWELL(dev_priv)) {
16856 * WaRsPkgCStateDisplayPMReq:hsw
16857 * System hang if this isn't done before disabling all planes!
16859 I915_WRITE(CHICKEN_PAR1_1,
16860 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
16864 static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
16865 enum port port, i915_reg_t hdmi_reg)
16867 u32 val = I915_READ(hdmi_reg);
16869 if (val & SDVO_ENABLE ||
16870 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
16873 DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n",
16876 val &= ~SDVO_PIPE_SEL_MASK;
16877 val |= SDVO_PIPE_SEL(PIPE_A);
16879 I915_WRITE(hdmi_reg, val);
16882 static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
16883 enum port port, i915_reg_t dp_reg)
16885 u32 val = I915_READ(dp_reg);
16887 if (val & DP_PORT_EN ||
16888 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
16891 DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n",
16894 val &= ~DP_PIPE_SEL_MASK;
16895 val |= DP_PIPE_SEL(PIPE_A);
16897 I915_WRITE(dp_reg, val);
16900 static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
16903 * The BIOS may select transcoder B on some of the PCH
16904 * ports even it doesn't enable the port. This would trip
16905 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
16906 * Sanitize the transcoder select bits to prevent that. We
16907 * assume that the BIOS never actually enabled the port,
16908 * because if it did we'd actually have to toggle the port
16909 * on and back off to make the transcoder A select stick
16910 * (see. intel_dp_link_down(), intel_disable_hdmi(),
16911 * intel_disable_sdvo()).
16913 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
16914 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
16915 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
16917 /* PCH SDVOB multiplex with HDMIB */
16918 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
16919 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
16920 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
16923 /* Scan out the current hw modeset state,
16924 * and sanitizes it to the current state
16927 intel_modeset_setup_hw_state(struct drm_device *dev,
16928 struct drm_modeset_acquire_ctx *ctx)
16930 struct drm_i915_private *dev_priv = to_i915(dev);
16931 struct intel_crtc_state *crtc_state;
16932 struct intel_encoder *encoder;
16933 struct intel_crtc *crtc;
16934 intel_wakeref_t wakeref;
16937 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
16939 intel_early_display_was(dev_priv);
16940 intel_modeset_readout_hw_state(dev);
16942 /* HW state is read out, now we need to sanitize this mess. */
16944 /* Sanitize the TypeC port mode upfront, encoders depend on this */
16945 for_each_intel_encoder(dev, encoder) {
16946 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
16948 /* We need to sanitize only the MST primary port. */
16949 if (encoder->type != INTEL_OUTPUT_DP_MST &&
16950 intel_phy_is_tc(dev_priv, phy))
16951 intel_tc_port_sanitize(enc_to_dig_port(&encoder->base));
16954 get_encoder_power_domains(dev_priv);
16956 if (HAS_PCH_IBX(dev_priv))
16957 ibx_sanitize_pch_ports(dev_priv);
16960 * intel_sanitize_plane_mapping() may need to do vblank
16961 * waits, so we need vblank interrupts restored beforehand.
16963 for_each_intel_crtc(&dev_priv->drm, crtc) {
16964 crtc_state = to_intel_crtc_state(crtc->base.state);
16966 drm_crtc_vblank_reset(&crtc->base);
16968 if (crtc_state->base.active)
16969 intel_crtc_vblank_on(crtc_state);
16972 intel_sanitize_plane_mapping(dev_priv);
16974 for_each_intel_encoder(dev, encoder)
16975 intel_sanitize_encoder(encoder);
16977 for_each_intel_crtc(&dev_priv->drm, crtc) {
16978 crtc_state = to_intel_crtc_state(crtc->base.state);
16979 intel_sanitize_crtc(crtc, ctx);
16980 intel_dump_pipe_config(crtc_state, NULL, "[setup_hw_state]");
16983 intel_modeset_update_connector_atomic_state(dev);
16985 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
16986 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
16988 if (!pll->on || pll->active_mask)
16991 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
16994 pll->info->funcs->disable(dev_priv, pll);
16998 if (IS_G4X(dev_priv)) {
16999 g4x_wm_get_hw_state(dev_priv);
17000 g4x_wm_sanitize(dev_priv);
17001 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
17002 vlv_wm_get_hw_state(dev_priv);
17003 vlv_wm_sanitize(dev_priv);
17004 } else if (INTEL_GEN(dev_priv) >= 9) {
17005 skl_wm_get_hw_state(dev_priv);
17006 } else if (HAS_PCH_SPLIT(dev_priv)) {
17007 ilk_wm_get_hw_state(dev_priv);
17010 for_each_intel_crtc(dev, crtc) {
17013 crtc_state = to_intel_crtc_state(crtc->base.state);
17014 put_domains = modeset_get_crtc_power_domains(crtc_state);
17015 if (WARN_ON(put_domains))
17016 modeset_put_power_domains(dev_priv, put_domains);
17019 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
17021 intel_fbc_init_pipe_state(dev_priv);
17024 void intel_display_resume(struct drm_device *dev)
17026 struct drm_i915_private *dev_priv = to_i915(dev);
17027 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
17028 struct drm_modeset_acquire_ctx ctx;
17031 dev_priv->modeset_restore_state = NULL;
17033 state->acquire_ctx = &ctx;
17035 drm_modeset_acquire_init(&ctx, 0);
17038 ret = drm_modeset_lock_all_ctx(dev, &ctx);
17039 if (ret != -EDEADLK)
17042 drm_modeset_backoff(&ctx);
17046 ret = __intel_display_resume(dev, state, &ctx);
17048 intel_enable_ipc(dev_priv);
17049 drm_modeset_drop_locks(&ctx);
17050 drm_modeset_acquire_fini(&ctx);
17053 DRM_ERROR("Restoring old state failed with %i\n", ret);
17055 drm_atomic_state_put(state);
17058 static void intel_hpd_poll_fini(struct drm_device *dev)
17060 struct intel_connector *connector;
17061 struct drm_connector_list_iter conn_iter;
17063 /* Kill all the work that may have been queued by hpd. */
17064 drm_connector_list_iter_begin(dev, &conn_iter);
17065 for_each_intel_connector_iter(connector, &conn_iter) {
17066 if (connector->modeset_retry_work.func)
17067 cancel_work_sync(&connector->modeset_retry_work);
17068 if (connector->hdcp.shim) {
17069 cancel_delayed_work_sync(&connector->hdcp.check_work);
17070 cancel_work_sync(&connector->hdcp.prop_work);
17073 drm_connector_list_iter_end(&conn_iter);
17076 void intel_modeset_cleanup(struct drm_device *dev)
17078 struct drm_i915_private *dev_priv = to_i915(dev);
17080 flush_workqueue(dev_priv->modeset_wq);
17082 flush_work(&dev_priv->atomic_helper.free_work);
17083 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
17086 * Interrupts and polling as the first thing to avoid creating havoc.
17087 * Too much stuff here (turning of connectors, ...) would
17088 * experience fancy races otherwise.
17090 intel_irq_uninstall(dev_priv);
17093 * Due to the hpd irq storm handling the hotplug work can re-arm the
17094 * poll handlers. Hence disable polling after hpd handling is shut down.
17096 intel_hpd_poll_fini(dev);
17098 /* poll work can call into fbdev, hence clean that up afterwards */
17099 intel_fbdev_fini(dev_priv);
17101 intel_unregister_dsm_handler();
17103 intel_fbc_global_disable(dev_priv);
17105 /* flush any delayed tasks or pending work */
17106 flush_scheduled_work();
17108 intel_hdcp_component_fini(dev_priv);
17110 drm_mode_config_cleanup(dev);
17112 intel_overlay_cleanup(dev_priv);
17114 intel_gmbus_teardown(dev_priv);
17116 destroy_workqueue(dev_priv->modeset_wq);
17118 intel_fbc_cleanup_cfb(dev_priv);
17122 * set vga decode state - true == enable VGA decode
17124 int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
17126 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
17129 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
17130 DRM_ERROR("failed to read control word\n");
17134 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
17138 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
17140 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
17142 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
17143 DRM_ERROR("failed to write control word\n");
17150 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
17152 struct intel_display_error_state {
17154 u32 power_well_driver;
17156 struct intel_cursor_error_state {
17161 } cursor[I915_MAX_PIPES];
17163 struct intel_pipe_error_state {
17164 bool power_domain_on;
17167 } pipe[I915_MAX_PIPES];
17169 struct intel_plane_error_state {
17177 } plane[I915_MAX_PIPES];
17179 struct intel_transcoder_error_state {
17181 bool power_domain_on;
17182 enum transcoder cpu_transcoder;
17195 struct intel_display_error_state *
17196 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
17198 struct intel_display_error_state *error;
17199 int transcoders[] = {
17207 BUILD_BUG_ON(ARRAY_SIZE(transcoders) != ARRAY_SIZE(error->transcoder));
17209 if (!HAS_DISPLAY(dev_priv))
17212 error = kzalloc(sizeof(*error), GFP_ATOMIC);
17216 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
17217 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
17219 for_each_pipe(dev_priv, i) {
17220 error->pipe[i].power_domain_on =
17221 __intel_display_power_is_enabled(dev_priv,
17222 POWER_DOMAIN_PIPE(i));
17223 if (!error->pipe[i].power_domain_on)
17226 error->cursor[i].control = I915_READ(CURCNTR(i));
17227 error->cursor[i].position = I915_READ(CURPOS(i));
17228 error->cursor[i].base = I915_READ(CURBASE(i));
17230 error->plane[i].control = I915_READ(DSPCNTR(i));
17231 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
17232 if (INTEL_GEN(dev_priv) <= 3) {
17233 error->plane[i].size = I915_READ(DSPSIZE(i));
17234 error->plane[i].pos = I915_READ(DSPPOS(i));
17236 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
17237 error->plane[i].addr = I915_READ(DSPADDR(i));
17238 if (INTEL_GEN(dev_priv) >= 4) {
17239 error->plane[i].surface = I915_READ(DSPSURF(i));
17240 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
17243 error->pipe[i].source = I915_READ(PIPESRC(i));
17245 if (HAS_GMCH(dev_priv))
17246 error->pipe[i].stat = I915_READ(PIPESTAT(i));
17249 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
17250 enum transcoder cpu_transcoder = transcoders[i];
17252 if (!INTEL_INFO(dev_priv)->trans_offsets[cpu_transcoder])
17255 error->transcoder[i].available = true;
17256 error->transcoder[i].power_domain_on =
17257 __intel_display_power_is_enabled(dev_priv,
17258 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
17259 if (!error->transcoder[i].power_domain_on)
17262 error->transcoder[i].cpu_transcoder = cpu_transcoder;
17264 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
17265 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
17266 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
17267 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
17268 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
17269 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
17270 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
17276 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
17279 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
17280 struct intel_display_error_state *error)
17282 struct drm_i915_private *dev_priv = m->i915;
17288 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
17289 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
17290 err_printf(m, "PWR_WELL_CTL2: %08x\n",
17291 error->power_well_driver);
17292 for_each_pipe(dev_priv, i) {
17293 err_printf(m, "Pipe [%d]:\n", i);
17294 err_printf(m, " Power: %s\n",
17295 onoff(error->pipe[i].power_domain_on));
17296 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
17297 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
17299 err_printf(m, "Plane [%d]:\n", i);
17300 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
17301 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
17302 if (INTEL_GEN(dev_priv) <= 3) {
17303 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
17304 err_printf(m, " POS: %08x\n", error->plane[i].pos);
17306 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
17307 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
17308 if (INTEL_GEN(dev_priv) >= 4) {
17309 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
17310 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
17313 err_printf(m, "Cursor [%d]:\n", i);
17314 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
17315 err_printf(m, " POS: %08x\n", error->cursor[i].position);
17316 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
17319 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
17320 if (!error->transcoder[i].available)
17323 err_printf(m, "CPU transcoder: %s\n",
17324 transcoder_name(error->transcoder[i].cpu_transcoder));
17325 err_printf(m, " Power: %s\n",
17326 onoff(error->transcoder[i].power_domain_on));
17327 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
17328 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
17329 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
17330 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
17331 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
17332 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
17333 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);