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.
27 #include <linux/i2c.h>
28 #include <linux/input.h>
29 #include <linux/intel-iommu.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/dma-resv.h>
33 #include <linux/slab.h>
35 #include <drm/drm_atomic.h>
36 #include <drm/drm_atomic_helper.h>
37 #include <drm/drm_atomic_uapi.h>
38 #include <drm/drm_dp_helper.h>
39 #include <drm/drm_edid.h>
40 #include <drm/drm_fourcc.h>
41 #include <drm/drm_plane_helper.h>
42 #include <drm/drm_probe_helper.h>
43 #include <drm/drm_rect.h>
44 #include <drm/i915_drm.h>
46 #include "display/intel_crt.h"
47 #include "display/intel_ddi.h"
48 #include "display/intel_dp.h"
49 #include "display/intel_dsi.h"
50 #include "display/intel_dvo.h"
51 #include "display/intel_gmbus.h"
52 #include "display/intel_hdmi.h"
53 #include "display/intel_lvds.h"
54 #include "display/intel_sdvo.h"
55 #include "display/intel_tv.h"
56 #include "display/intel_vdsc.h"
58 #include "gt/intel_rps.h"
61 #include "i915_trace.h"
62 #include "intel_acpi.h"
63 #include "intel_atomic.h"
64 #include "intel_atomic_plane.h"
66 #include "intel_cdclk.h"
67 #include "intel_color.h"
68 #include "intel_display_types.h"
69 #include "intel_dp_link_training.h"
70 #include "intel_fbc.h"
71 #include "intel_fbdev.h"
72 #include "intel_fifo_underrun.h"
73 #include "intel_frontbuffer.h"
74 #include "intel_hdcp.h"
75 #include "intel_hotplug.h"
76 #include "intel_overlay.h"
77 #include "intel_pipe_crc.h"
79 #include "intel_psr.h"
80 #include "intel_quirks.h"
81 #include "intel_sideband.h"
82 #include "intel_sprite.h"
84 #include "intel_vga.h"
86 /* Primary plane formats for gen <= 3 */
87 static const u32 i8xx_primary_formats[] = {
94 /* Primary plane formats for ivb (no fp16 due to hw issue) */
95 static const u32 ivb_primary_formats[] = {
100 DRM_FORMAT_XRGB2101010,
101 DRM_FORMAT_XBGR2101010,
104 /* Primary plane formats for gen >= 4, except ivb */
105 static const u32 i965_primary_formats[] = {
110 DRM_FORMAT_XRGB2101010,
111 DRM_FORMAT_XBGR2101010,
112 DRM_FORMAT_XBGR16161616F,
115 static const u64 i9xx_format_modifiers[] = {
116 I915_FORMAT_MOD_X_TILED,
117 DRM_FORMAT_MOD_LINEAR,
118 DRM_FORMAT_MOD_INVALID
122 static const u32 intel_cursor_formats[] = {
126 static const u64 cursor_format_modifiers[] = {
127 DRM_FORMAT_MOD_LINEAR,
128 DRM_FORMAT_MOD_INVALID
131 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
132 struct intel_crtc_state *pipe_config);
133 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
134 struct intel_crtc_state *pipe_config);
136 static int intel_framebuffer_init(struct intel_framebuffer *ifb,
137 struct drm_i915_gem_object *obj,
138 struct drm_mode_fb_cmd2 *mode_cmd);
139 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state);
140 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
141 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
142 const struct intel_link_m_n *m_n,
143 const struct intel_link_m_n *m2_n2);
144 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
145 static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state);
146 static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state);
147 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state);
148 static void vlv_prepare_pll(struct intel_crtc *crtc,
149 const struct intel_crtc_state *pipe_config);
150 static void chv_prepare_pll(struct intel_crtc *crtc,
151 const struct intel_crtc_state *pipe_config);
152 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
153 struct intel_crtc_state *crtc_state);
154 static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state);
155 static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state);
156 static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state);
157 static void intel_modeset_setup_hw_state(struct drm_device *dev,
158 struct drm_modeset_acquire_ctx *ctx);
159 static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc);
164 } dot, vco, n, m, m1, m2, p, p1;
168 int p2_slow, p2_fast;
172 /* returns HPLL frequency in kHz */
173 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
175 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
177 /* Obtain SKU information */
178 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
179 CCK_FUSE_HPLL_FREQ_MASK;
181 return vco_freq[hpll_freq] * 1000;
184 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
185 const char *name, u32 reg, int ref_freq)
190 val = vlv_cck_read(dev_priv, reg);
191 divider = val & CCK_FREQUENCY_VALUES;
193 WARN((val & CCK_FREQUENCY_STATUS) !=
194 (divider << CCK_FREQUENCY_STATUS_SHIFT),
195 "%s change in progress\n", name);
197 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
200 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
201 const char *name, u32 reg)
205 vlv_cck_get(dev_priv);
207 if (dev_priv->hpll_freq == 0)
208 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
210 hpll = vlv_get_cck_clock(dev_priv, name, reg, dev_priv->hpll_freq);
212 vlv_cck_put(dev_priv);
217 static void intel_update_czclk(struct drm_i915_private *dev_priv)
219 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
222 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
223 CCK_CZ_CLOCK_CONTROL);
225 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
228 static inline u32 /* units of 100MHz */
229 intel_fdi_link_freq(struct drm_i915_private *dev_priv,
230 const struct intel_crtc_state *pipe_config)
232 if (HAS_DDI(dev_priv))
233 return pipe_config->port_clock; /* SPLL */
235 return dev_priv->fdi_pll_freq;
238 static const struct intel_limit intel_limits_i8xx_dac = {
239 .dot = { .min = 25000, .max = 350000 },
240 .vco = { .min = 908000, .max = 1512000 },
241 .n = { .min = 2, .max = 16 },
242 .m = { .min = 96, .max = 140 },
243 .m1 = { .min = 18, .max = 26 },
244 .m2 = { .min = 6, .max = 16 },
245 .p = { .min = 4, .max = 128 },
246 .p1 = { .min = 2, .max = 33 },
247 .p2 = { .dot_limit = 165000,
248 .p2_slow = 4, .p2_fast = 2 },
251 static const struct intel_limit intel_limits_i8xx_dvo = {
252 .dot = { .min = 25000, .max = 350000 },
253 .vco = { .min = 908000, .max = 1512000 },
254 .n = { .min = 2, .max = 16 },
255 .m = { .min = 96, .max = 140 },
256 .m1 = { .min = 18, .max = 26 },
257 .m2 = { .min = 6, .max = 16 },
258 .p = { .min = 4, .max = 128 },
259 .p1 = { .min = 2, .max = 33 },
260 .p2 = { .dot_limit = 165000,
261 .p2_slow = 4, .p2_fast = 4 },
264 static const struct intel_limit intel_limits_i8xx_lvds = {
265 .dot = { .min = 25000, .max = 350000 },
266 .vco = { .min = 908000, .max = 1512000 },
267 .n = { .min = 2, .max = 16 },
268 .m = { .min = 96, .max = 140 },
269 .m1 = { .min = 18, .max = 26 },
270 .m2 = { .min = 6, .max = 16 },
271 .p = { .min = 4, .max = 128 },
272 .p1 = { .min = 1, .max = 6 },
273 .p2 = { .dot_limit = 165000,
274 .p2_slow = 14, .p2_fast = 7 },
277 static const struct intel_limit intel_limits_i9xx_sdvo = {
278 .dot = { .min = 20000, .max = 400000 },
279 .vco = { .min = 1400000, .max = 2800000 },
280 .n = { .min = 1, .max = 6 },
281 .m = { .min = 70, .max = 120 },
282 .m1 = { .min = 8, .max = 18 },
283 .m2 = { .min = 3, .max = 7 },
284 .p = { .min = 5, .max = 80 },
285 .p1 = { .min = 1, .max = 8 },
286 .p2 = { .dot_limit = 200000,
287 .p2_slow = 10, .p2_fast = 5 },
290 static const struct intel_limit intel_limits_i9xx_lvds = {
291 .dot = { .min = 20000, .max = 400000 },
292 .vco = { .min = 1400000, .max = 2800000 },
293 .n = { .min = 1, .max = 6 },
294 .m = { .min = 70, .max = 120 },
295 .m1 = { .min = 8, .max = 18 },
296 .m2 = { .min = 3, .max = 7 },
297 .p = { .min = 7, .max = 98 },
298 .p1 = { .min = 1, .max = 8 },
299 .p2 = { .dot_limit = 112000,
300 .p2_slow = 14, .p2_fast = 7 },
304 static const struct intel_limit intel_limits_g4x_sdvo = {
305 .dot = { .min = 25000, .max = 270000 },
306 .vco = { .min = 1750000, .max = 3500000},
307 .n = { .min = 1, .max = 4 },
308 .m = { .min = 104, .max = 138 },
309 .m1 = { .min = 17, .max = 23 },
310 .m2 = { .min = 5, .max = 11 },
311 .p = { .min = 10, .max = 30 },
312 .p1 = { .min = 1, .max = 3},
313 .p2 = { .dot_limit = 270000,
319 static const struct intel_limit intel_limits_g4x_hdmi = {
320 .dot = { .min = 22000, .max = 400000 },
321 .vco = { .min = 1750000, .max = 3500000},
322 .n = { .min = 1, .max = 4 },
323 .m = { .min = 104, .max = 138 },
324 .m1 = { .min = 16, .max = 23 },
325 .m2 = { .min = 5, .max = 11 },
326 .p = { .min = 5, .max = 80 },
327 .p1 = { .min = 1, .max = 8},
328 .p2 = { .dot_limit = 165000,
329 .p2_slow = 10, .p2_fast = 5 },
332 static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
333 .dot = { .min = 20000, .max = 115000 },
334 .vco = { .min = 1750000, .max = 3500000 },
335 .n = { .min = 1, .max = 3 },
336 .m = { .min = 104, .max = 138 },
337 .m1 = { .min = 17, .max = 23 },
338 .m2 = { .min = 5, .max = 11 },
339 .p = { .min = 28, .max = 112 },
340 .p1 = { .min = 2, .max = 8 },
341 .p2 = { .dot_limit = 0,
342 .p2_slow = 14, .p2_fast = 14
346 static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
347 .dot = { .min = 80000, .max = 224000 },
348 .vco = { .min = 1750000, .max = 3500000 },
349 .n = { .min = 1, .max = 3 },
350 .m = { .min = 104, .max = 138 },
351 .m1 = { .min = 17, .max = 23 },
352 .m2 = { .min = 5, .max = 11 },
353 .p = { .min = 14, .max = 42 },
354 .p1 = { .min = 2, .max = 6 },
355 .p2 = { .dot_limit = 0,
356 .p2_slow = 7, .p2_fast = 7
360 static const struct intel_limit intel_limits_pineview_sdvo = {
361 .dot = { .min = 20000, .max = 400000},
362 .vco = { .min = 1700000, .max = 3500000 },
363 /* Pineview's Ncounter is a ring counter */
364 .n = { .min = 3, .max = 6 },
365 .m = { .min = 2, .max = 256 },
366 /* Pineview only has one combined m divider, which we treat as m2. */
367 .m1 = { .min = 0, .max = 0 },
368 .m2 = { .min = 0, .max = 254 },
369 .p = { .min = 5, .max = 80 },
370 .p1 = { .min = 1, .max = 8 },
371 .p2 = { .dot_limit = 200000,
372 .p2_slow = 10, .p2_fast = 5 },
375 static const struct intel_limit intel_limits_pineview_lvds = {
376 .dot = { .min = 20000, .max = 400000 },
377 .vco = { .min = 1700000, .max = 3500000 },
378 .n = { .min = 3, .max = 6 },
379 .m = { .min = 2, .max = 256 },
380 .m1 = { .min = 0, .max = 0 },
381 .m2 = { .min = 0, .max = 254 },
382 .p = { .min = 7, .max = 112 },
383 .p1 = { .min = 1, .max = 8 },
384 .p2 = { .dot_limit = 112000,
385 .p2_slow = 14, .p2_fast = 14 },
388 /* Ironlake / Sandybridge
390 * We calculate clock using (register_value + 2) for N/M1/M2, so here
391 * the range value for them is (actual_value - 2).
393 static const struct intel_limit intel_limits_ironlake_dac = {
394 .dot = { .min = 25000, .max = 350000 },
395 .vco = { .min = 1760000, .max = 3510000 },
396 .n = { .min = 1, .max = 5 },
397 .m = { .min = 79, .max = 127 },
398 .m1 = { .min = 12, .max = 22 },
399 .m2 = { .min = 5, .max = 9 },
400 .p = { .min = 5, .max = 80 },
401 .p1 = { .min = 1, .max = 8 },
402 .p2 = { .dot_limit = 225000,
403 .p2_slow = 10, .p2_fast = 5 },
406 static const struct intel_limit intel_limits_ironlake_single_lvds = {
407 .dot = { .min = 25000, .max = 350000 },
408 .vco = { .min = 1760000, .max = 3510000 },
409 .n = { .min = 1, .max = 3 },
410 .m = { .min = 79, .max = 118 },
411 .m1 = { .min = 12, .max = 22 },
412 .m2 = { .min = 5, .max = 9 },
413 .p = { .min = 28, .max = 112 },
414 .p1 = { .min = 2, .max = 8 },
415 .p2 = { .dot_limit = 225000,
416 .p2_slow = 14, .p2_fast = 14 },
419 static const struct intel_limit intel_limits_ironlake_dual_lvds = {
420 .dot = { .min = 25000, .max = 350000 },
421 .vco = { .min = 1760000, .max = 3510000 },
422 .n = { .min = 1, .max = 3 },
423 .m = { .min = 79, .max = 127 },
424 .m1 = { .min = 12, .max = 22 },
425 .m2 = { .min = 5, .max = 9 },
426 .p = { .min = 14, .max = 56 },
427 .p1 = { .min = 2, .max = 8 },
428 .p2 = { .dot_limit = 225000,
429 .p2_slow = 7, .p2_fast = 7 },
432 /* LVDS 100mhz refclk limits. */
433 static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
434 .dot = { .min = 25000, .max = 350000 },
435 .vco = { .min = 1760000, .max = 3510000 },
436 .n = { .min = 1, .max = 2 },
437 .m = { .min = 79, .max = 126 },
438 .m1 = { .min = 12, .max = 22 },
439 .m2 = { .min = 5, .max = 9 },
440 .p = { .min = 28, .max = 112 },
441 .p1 = { .min = 2, .max = 8 },
442 .p2 = { .dot_limit = 225000,
443 .p2_slow = 14, .p2_fast = 14 },
446 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
447 .dot = { .min = 25000, .max = 350000 },
448 .vco = { .min = 1760000, .max = 3510000 },
449 .n = { .min = 1, .max = 3 },
450 .m = { .min = 79, .max = 126 },
451 .m1 = { .min = 12, .max = 22 },
452 .m2 = { .min = 5, .max = 9 },
453 .p = { .min = 14, .max = 42 },
454 .p1 = { .min = 2, .max = 6 },
455 .p2 = { .dot_limit = 225000,
456 .p2_slow = 7, .p2_fast = 7 },
459 static const struct intel_limit intel_limits_vlv = {
461 * These are the data rate limits (measured in fast clocks)
462 * since those are the strictest limits we have. The fast
463 * clock and actual rate limits are more relaxed, so checking
464 * them would make no difference.
466 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
467 .vco = { .min = 4000000, .max = 6000000 },
468 .n = { .min = 1, .max = 7 },
469 .m1 = { .min = 2, .max = 3 },
470 .m2 = { .min = 11, .max = 156 },
471 .p1 = { .min = 2, .max = 3 },
472 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
475 static const struct intel_limit intel_limits_chv = {
477 * These are the data rate limits (measured in fast clocks)
478 * since those are the strictest limits we have. The fast
479 * clock and actual rate limits are more relaxed, so checking
480 * them would make no difference.
482 .dot = { .min = 25000 * 5, .max = 540000 * 5},
483 .vco = { .min = 4800000, .max = 6480000 },
484 .n = { .min = 1, .max = 1 },
485 .m1 = { .min = 2, .max = 2 },
486 .m2 = { .min = 24 << 22, .max = 175 << 22 },
487 .p1 = { .min = 2, .max = 4 },
488 .p2 = { .p2_slow = 1, .p2_fast = 14 },
491 static const struct intel_limit intel_limits_bxt = {
492 /* FIXME: find real dot limits */
493 .dot = { .min = 0, .max = INT_MAX },
494 .vco = { .min = 4800000, .max = 6700000 },
495 .n = { .min = 1, .max = 1 },
496 .m1 = { .min = 2, .max = 2 },
497 /* FIXME: find real m2 limits */
498 .m2 = { .min = 2 << 22, .max = 255 << 22 },
499 .p1 = { .min = 2, .max = 4 },
500 .p2 = { .p2_slow = 1, .p2_fast = 20 },
503 /* WA Display #0827: Gen9:all */
505 skl_wa_827(struct drm_i915_private *dev_priv, enum pipe pipe, bool enable)
508 I915_WRITE(CLKGATE_DIS_PSL(pipe),
509 I915_READ(CLKGATE_DIS_PSL(pipe)) |
510 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
512 I915_WRITE(CLKGATE_DIS_PSL(pipe),
513 I915_READ(CLKGATE_DIS_PSL(pipe)) &
514 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
517 /* Wa_2006604312:icl */
519 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
523 I915_WRITE(CLKGATE_DIS_PSL(pipe),
524 I915_READ(CLKGATE_DIS_PSL(pipe)) | DPFR_GATING_DIS);
526 I915_WRITE(CLKGATE_DIS_PSL(pipe),
527 I915_READ(CLKGATE_DIS_PSL(pipe)) & ~DPFR_GATING_DIS);
531 needs_modeset(const struct intel_crtc_state *state)
533 return drm_atomic_crtc_needs_modeset(&state->base);
537 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state)
539 return (crtc_state->master_transcoder != INVALID_TRANSCODER ||
540 crtc_state->sync_mode_slaves_mask);
544 is_trans_port_sync_master(const struct intel_crtc_state *crtc_state)
546 return (crtc_state->master_transcoder == INVALID_TRANSCODER &&
547 crtc_state->sync_mode_slaves_mask);
551 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
552 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
553 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
554 * The helpers' return value is the rate of the clock that is fed to the
555 * display engine's pipe which can be the above fast dot clock rate or a
556 * divided-down version of it.
558 /* m1 is reserved as 0 in Pineview, n is a ring counter */
559 static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
561 clock->m = clock->m2 + 2;
562 clock->p = clock->p1 * clock->p2;
563 if (WARN_ON(clock->n == 0 || clock->p == 0))
565 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
566 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
571 static u32 i9xx_dpll_compute_m(struct dpll *dpll)
573 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
576 static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
578 clock->m = i9xx_dpll_compute_m(clock);
579 clock->p = clock->p1 * clock->p2;
580 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
582 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
583 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
588 static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
590 clock->m = clock->m1 * clock->m2;
591 clock->p = clock->p1 * clock->p2;
592 if (WARN_ON(clock->n == 0 || clock->p == 0))
594 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
595 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
597 return clock->dot / 5;
600 int chv_calc_dpll_params(int refclk, struct dpll *clock)
602 clock->m = clock->m1 * clock->m2;
603 clock->p = clock->p1 * clock->p2;
604 if (WARN_ON(clock->n == 0 || clock->p == 0))
606 clock->vco = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(refclk, clock->m),
608 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
610 return clock->dot / 5;
613 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
616 * Returns whether the given set of divisors are valid for a given refclk with
617 * the given connectors.
619 static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
620 const struct intel_limit *limit,
621 const struct dpll *clock)
623 if (clock->n < limit->n.min || limit->n.max < clock->n)
624 INTELPllInvalid("n out of range\n");
625 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
626 INTELPllInvalid("p1 out of range\n");
627 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
628 INTELPllInvalid("m2 out of range\n");
629 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
630 INTELPllInvalid("m1 out of range\n");
632 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
633 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
634 if (clock->m1 <= clock->m2)
635 INTELPllInvalid("m1 <= m2\n");
637 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
638 !IS_GEN9_LP(dev_priv)) {
639 if (clock->p < limit->p.min || limit->p.max < clock->p)
640 INTELPllInvalid("p out of range\n");
641 if (clock->m < limit->m.min || limit->m.max < clock->m)
642 INTELPllInvalid("m out of range\n");
645 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
646 INTELPllInvalid("vco out of range\n");
647 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
648 * connector, etc., rather than just a single range.
650 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
651 INTELPllInvalid("dot out of range\n");
657 i9xx_select_p2_div(const struct intel_limit *limit,
658 const struct intel_crtc_state *crtc_state,
661 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
663 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
665 * For LVDS just rely on its current settings for dual-channel.
666 * We haven't figured out how to reliably set up different
667 * single/dual channel state, if we even can.
669 if (intel_is_dual_link_lvds(dev_priv))
670 return limit->p2.p2_fast;
672 return limit->p2.p2_slow;
674 if (target < limit->p2.dot_limit)
675 return limit->p2.p2_slow;
677 return limit->p2.p2_fast;
682 * Returns a set of divisors for the desired target clock with the given
683 * refclk, or FALSE. The returned values represent the clock equation:
684 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
686 * Target and reference clocks are specified in kHz.
688 * If match_clock is provided, then best_clock P divider must match the P
689 * divider from @match_clock used for LVDS downclocking.
692 i9xx_find_best_dpll(const struct intel_limit *limit,
693 struct intel_crtc_state *crtc_state,
694 int target, int refclk, struct dpll *match_clock,
695 struct dpll *best_clock)
697 struct drm_device *dev = crtc_state->base.crtc->dev;
701 memset(best_clock, 0, sizeof(*best_clock));
703 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
705 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
707 for (clock.m2 = limit->m2.min;
708 clock.m2 <= limit->m2.max; clock.m2++) {
709 if (clock.m2 >= clock.m1)
711 for (clock.n = limit->n.min;
712 clock.n <= limit->n.max; clock.n++) {
713 for (clock.p1 = limit->p1.min;
714 clock.p1 <= limit->p1.max; clock.p1++) {
717 i9xx_calc_dpll_params(refclk, &clock);
718 if (!intel_PLL_is_valid(to_i915(dev),
723 clock.p != match_clock->p)
726 this_err = abs(clock.dot - target);
727 if (this_err < err) {
736 return (err != target);
740 * Returns a set of divisors for the desired target clock with the given
741 * refclk, or FALSE. The returned values represent the clock equation:
742 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
744 * Target and reference clocks are specified in kHz.
746 * If match_clock is provided, then best_clock P divider must match the P
747 * divider from @match_clock used for LVDS downclocking.
750 pnv_find_best_dpll(const struct intel_limit *limit,
751 struct intel_crtc_state *crtc_state,
752 int target, int refclk, struct dpll *match_clock,
753 struct dpll *best_clock)
755 struct drm_device *dev = crtc_state->base.crtc->dev;
759 memset(best_clock, 0, sizeof(*best_clock));
761 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
763 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
765 for (clock.m2 = limit->m2.min;
766 clock.m2 <= limit->m2.max; clock.m2++) {
767 for (clock.n = limit->n.min;
768 clock.n <= limit->n.max; clock.n++) {
769 for (clock.p1 = limit->p1.min;
770 clock.p1 <= limit->p1.max; clock.p1++) {
773 pnv_calc_dpll_params(refclk, &clock);
774 if (!intel_PLL_is_valid(to_i915(dev),
779 clock.p != match_clock->p)
782 this_err = abs(clock.dot - target);
783 if (this_err < err) {
792 return (err != target);
796 * Returns a set of divisors for the desired target clock with the given
797 * refclk, or FALSE. The returned values represent the clock equation:
798 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
800 * Target and reference clocks are specified in kHz.
802 * If match_clock is provided, then best_clock P divider must match the P
803 * divider from @match_clock used for LVDS downclocking.
806 g4x_find_best_dpll(const struct intel_limit *limit,
807 struct intel_crtc_state *crtc_state,
808 int target, int refclk, struct dpll *match_clock,
809 struct dpll *best_clock)
811 struct drm_device *dev = crtc_state->base.crtc->dev;
815 /* approximately equals target * 0.00585 */
816 int err_most = (target >> 8) + (target >> 9);
818 memset(best_clock, 0, sizeof(*best_clock));
820 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
822 max_n = limit->n.max;
823 /* based on hardware requirement, prefer smaller n to precision */
824 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
825 /* based on hardware requirement, prefere larger m1,m2 */
826 for (clock.m1 = limit->m1.max;
827 clock.m1 >= limit->m1.min; clock.m1--) {
828 for (clock.m2 = limit->m2.max;
829 clock.m2 >= limit->m2.min; clock.m2--) {
830 for (clock.p1 = limit->p1.max;
831 clock.p1 >= limit->p1.min; clock.p1--) {
834 i9xx_calc_dpll_params(refclk, &clock);
835 if (!intel_PLL_is_valid(to_i915(dev),
840 this_err = abs(clock.dot - target);
841 if (this_err < err_most) {
855 * Check if the calculated PLL configuration is more optimal compared to the
856 * best configuration and error found so far. Return the calculated error.
858 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
859 const struct dpll *calculated_clock,
860 const struct dpll *best_clock,
861 unsigned int best_error_ppm,
862 unsigned int *error_ppm)
865 * For CHV ignore the error and consider only the P value.
866 * Prefer a bigger P value based on HW requirements.
868 if (IS_CHERRYVIEW(to_i915(dev))) {
871 return calculated_clock->p > best_clock->p;
874 if (WARN_ON_ONCE(!target_freq))
877 *error_ppm = div_u64(1000000ULL *
878 abs(target_freq - calculated_clock->dot),
881 * Prefer a better P value over a better (smaller) error if the error
882 * is small. Ensure this preference for future configurations too by
883 * setting the error to 0.
885 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
891 return *error_ppm + 10 < best_error_ppm;
895 * Returns a set of divisors for the desired target clock with the given
896 * refclk, or FALSE. The returned values represent the clock equation:
897 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
900 vlv_find_best_dpll(const struct intel_limit *limit,
901 struct intel_crtc_state *crtc_state,
902 int target, int refclk, struct dpll *match_clock,
903 struct dpll *best_clock)
905 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
906 struct drm_device *dev = crtc->base.dev;
908 unsigned int bestppm = 1000000;
909 /* min update 19.2 MHz */
910 int max_n = min(limit->n.max, refclk / 19200);
913 target *= 5; /* fast clock */
915 memset(best_clock, 0, sizeof(*best_clock));
917 /* based on hardware requirement, prefer smaller n to precision */
918 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
919 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
920 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
921 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
922 clock.p = clock.p1 * clock.p2;
923 /* based on hardware requirement, prefer bigger m1,m2 values */
924 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
927 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
930 vlv_calc_dpll_params(refclk, &clock);
932 if (!intel_PLL_is_valid(to_i915(dev),
937 if (!vlv_PLL_is_optimal(dev, target,
955 * Returns a set of divisors for the desired target clock with the given
956 * refclk, or FALSE. The returned values represent the clock equation:
957 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
960 chv_find_best_dpll(const struct intel_limit *limit,
961 struct intel_crtc_state *crtc_state,
962 int target, int refclk, struct dpll *match_clock,
963 struct dpll *best_clock)
965 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
966 struct drm_device *dev = crtc->base.dev;
967 unsigned int best_error_ppm;
972 memset(best_clock, 0, sizeof(*best_clock));
973 best_error_ppm = 1000000;
976 * Based on hardware doc, the n always set to 1, and m1 always
977 * set to 2. If requires to support 200Mhz refclk, we need to
978 * revisit this because n may not 1 anymore.
980 clock.n = 1, clock.m1 = 2;
981 target *= 5; /* fast clock */
983 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
984 for (clock.p2 = limit->p2.p2_fast;
985 clock.p2 >= limit->p2.p2_slow;
986 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
987 unsigned int error_ppm;
989 clock.p = clock.p1 * clock.p2;
991 m2 = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(target, clock.p * clock.n) << 22,
994 if (m2 > INT_MAX/clock.m1)
999 chv_calc_dpll_params(refclk, &clock);
1001 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
1004 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
1005 best_error_ppm, &error_ppm))
1008 *best_clock = clock;
1009 best_error_ppm = error_ppm;
1017 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state,
1018 struct dpll *best_clock)
1020 int refclk = 100000;
1021 const struct intel_limit *limit = &intel_limits_bxt;
1023 return chv_find_best_dpll(limit, crtc_state,
1024 crtc_state->port_clock, refclk,
1028 bool intel_crtc_active(struct intel_crtc *crtc)
1030 /* Be paranoid as we can arrive here with only partial
1031 * state retrieved from the hardware during setup.
1033 * We can ditch the adjusted_mode.crtc_clock check as soon
1034 * as Haswell has gained clock readout/fastboot support.
1036 * We can ditch the crtc->primary->state->fb check as soon as we can
1037 * properly reconstruct framebuffers.
1039 * FIXME: The intel_crtc->active here should be switched to
1040 * crtc->state->active once we have proper CRTC states wired up
1043 return crtc->active && crtc->base.primary->state->fb &&
1044 crtc->config->base.adjusted_mode.crtc_clock;
1047 enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
1050 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1052 return crtc->config->cpu_transcoder;
1055 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
1058 i915_reg_t reg = PIPEDSL(pipe);
1062 if (IS_GEN(dev_priv, 2))
1063 line_mask = DSL_LINEMASK_GEN2;
1065 line_mask = DSL_LINEMASK_GEN3;
1067 line1 = I915_READ(reg) & line_mask;
1069 line2 = I915_READ(reg) & line_mask;
1071 return line1 != line2;
1074 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1076 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1077 enum pipe pipe = crtc->pipe;
1079 /* Wait for the display line to settle/start moving */
1080 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1081 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1082 pipe_name(pipe), onoff(state));
1085 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1087 wait_for_pipe_scanline_moving(crtc, false);
1090 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1092 wait_for_pipe_scanline_moving(crtc, true);
1096 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
1098 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1099 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1101 if (INTEL_GEN(dev_priv) >= 4) {
1102 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1103 i915_reg_t reg = PIPECONF(cpu_transcoder);
1105 /* Wait for the Pipe State to go off */
1106 if (intel_de_wait_for_clear(dev_priv, reg,
1107 I965_PIPECONF_ACTIVE, 100))
1108 WARN(1, "pipe_off wait timed out\n");
1110 intel_wait_for_pipe_scanline_stopped(crtc);
1114 /* Only for pre-ILK configs */
1115 void assert_pll(struct drm_i915_private *dev_priv,
1116 enum pipe pipe, bool state)
1121 val = I915_READ(DPLL(pipe));
1122 cur_state = !!(val & DPLL_VCO_ENABLE);
1123 I915_STATE_WARN(cur_state != state,
1124 "PLL state assertion failure (expected %s, current %s)\n",
1125 onoff(state), onoff(cur_state));
1128 /* XXX: the dsi pll is shared between MIPI DSI ports */
1129 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1134 vlv_cck_get(dev_priv);
1135 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1136 vlv_cck_put(dev_priv);
1138 cur_state = val & DSI_PLL_VCO_EN;
1139 I915_STATE_WARN(cur_state != state,
1140 "DSI PLL state assertion failure (expected %s, current %s)\n",
1141 onoff(state), onoff(cur_state));
1144 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1145 enum pipe pipe, bool state)
1148 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1151 if (HAS_DDI(dev_priv)) {
1152 /* DDI does not have a specific FDI_TX register */
1153 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1154 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1156 u32 val = I915_READ(FDI_TX_CTL(pipe));
1157 cur_state = !!(val & FDI_TX_ENABLE);
1159 I915_STATE_WARN(cur_state != state,
1160 "FDI TX state assertion failure (expected %s, current %s)\n",
1161 onoff(state), onoff(cur_state));
1163 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1164 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1166 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1167 enum pipe pipe, bool state)
1172 val = I915_READ(FDI_RX_CTL(pipe));
1173 cur_state = !!(val & FDI_RX_ENABLE);
1174 I915_STATE_WARN(cur_state != state,
1175 "FDI RX state assertion failure (expected %s, current %s)\n",
1176 onoff(state), onoff(cur_state));
1178 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1179 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1181 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1186 /* ILK FDI PLL is always enabled */
1187 if (IS_GEN(dev_priv, 5))
1190 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1191 if (HAS_DDI(dev_priv))
1194 val = I915_READ(FDI_TX_CTL(pipe));
1195 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1198 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1199 enum pipe pipe, bool state)
1204 val = I915_READ(FDI_RX_CTL(pipe));
1205 cur_state = !!(val & FDI_RX_PLL_ENABLE);
1206 I915_STATE_WARN(cur_state != state,
1207 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1208 onoff(state), onoff(cur_state));
1211 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
1215 enum pipe panel_pipe = INVALID_PIPE;
1218 if (WARN_ON(HAS_DDI(dev_priv)))
1221 if (HAS_PCH_SPLIT(dev_priv)) {
1224 pp_reg = PP_CONTROL(0);
1225 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1228 case PANEL_PORT_SELECT_LVDS:
1229 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
1231 case PANEL_PORT_SELECT_DPA:
1232 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1234 case PANEL_PORT_SELECT_DPC:
1235 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1237 case PANEL_PORT_SELECT_DPD:
1238 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1241 MISSING_CASE(port_sel);
1244 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1245 /* presumably write lock depends on pipe, not port select */
1246 pp_reg = PP_CONTROL(pipe);
1251 pp_reg = PP_CONTROL(0);
1252 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1254 WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS);
1255 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
1258 val = I915_READ(pp_reg);
1259 if (!(val & PANEL_POWER_ON) ||
1260 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1263 I915_STATE_WARN(panel_pipe == pipe && locked,
1264 "panel assertion failure, pipe %c regs locked\n",
1268 void assert_pipe(struct drm_i915_private *dev_priv,
1269 enum pipe pipe, bool state)
1272 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1274 enum intel_display_power_domain power_domain;
1275 intel_wakeref_t wakeref;
1277 /* we keep both pipes enabled on 830 */
1278 if (IS_I830(dev_priv))
1281 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1282 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1284 u32 val = I915_READ(PIPECONF(cpu_transcoder));
1285 cur_state = !!(val & PIPECONF_ENABLE);
1287 intel_display_power_put(dev_priv, power_domain, wakeref);
1292 I915_STATE_WARN(cur_state != state,
1293 "pipe %c assertion failure (expected %s, current %s)\n",
1294 pipe_name(pipe), onoff(state), onoff(cur_state));
1297 static void assert_plane(struct intel_plane *plane, bool state)
1302 cur_state = plane->get_hw_state(plane, &pipe);
1304 I915_STATE_WARN(cur_state != state,
1305 "%s assertion failure (expected %s, current %s)\n",
1306 plane->base.name, onoff(state), onoff(cur_state));
1309 #define assert_plane_enabled(p) assert_plane(p, true)
1310 #define assert_plane_disabled(p) assert_plane(p, false)
1312 static void assert_planes_disabled(struct intel_crtc *crtc)
1314 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1315 struct intel_plane *plane;
1317 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1318 assert_plane_disabled(plane);
1321 static void assert_vblank_disabled(struct drm_crtc *crtc)
1323 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1324 drm_crtc_vblank_put(crtc);
1327 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1333 val = I915_READ(PCH_TRANSCONF(pipe));
1334 enabled = !!(val & TRANS_ENABLE);
1335 I915_STATE_WARN(enabled,
1336 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1340 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1341 enum pipe pipe, enum port port,
1344 enum pipe port_pipe;
1347 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1349 I915_STATE_WARN(state && port_pipe == pipe,
1350 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1351 port_name(port), pipe_name(pipe));
1353 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1354 "IBX PCH DP %c still using transcoder B\n",
1358 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1359 enum pipe pipe, enum port port,
1360 i915_reg_t hdmi_reg)
1362 enum pipe port_pipe;
1365 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1367 I915_STATE_WARN(state && port_pipe == pipe,
1368 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1369 port_name(port), pipe_name(pipe));
1371 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1372 "IBX PCH HDMI %c still using transcoder B\n",
1376 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1379 enum pipe port_pipe;
1381 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1382 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1383 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
1385 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1387 "PCH VGA enabled on transcoder %c, should be disabled\n",
1390 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1392 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1395 /* PCH SDVOB multiplex with HDMIB */
1396 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1397 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1398 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
1401 static void _vlv_enable_pll(struct intel_crtc *crtc,
1402 const struct intel_crtc_state *pipe_config)
1404 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1405 enum pipe pipe = crtc->pipe;
1407 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1408 POSTING_READ(DPLL(pipe));
1411 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
1412 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1415 static void vlv_enable_pll(struct intel_crtc *crtc,
1416 const struct intel_crtc_state *pipe_config)
1418 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1419 enum pipe pipe = crtc->pipe;
1421 assert_pipe_disabled(dev_priv, pipe);
1423 /* PLL is protected by panel, make sure we can write it */
1424 assert_panel_unlocked(dev_priv, pipe);
1426 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1427 _vlv_enable_pll(crtc, pipe_config);
1429 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1430 POSTING_READ(DPLL_MD(pipe));
1434 static void _chv_enable_pll(struct intel_crtc *crtc,
1435 const struct intel_crtc_state *pipe_config)
1437 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1438 enum pipe pipe = crtc->pipe;
1439 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1442 vlv_dpio_get(dev_priv);
1444 /* Enable back the 10bit clock to display controller */
1445 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1446 tmp |= DPIO_DCLKP_EN;
1447 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1449 vlv_dpio_put(dev_priv);
1452 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1457 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1459 /* Check PLL is locked */
1460 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
1461 DRM_ERROR("PLL %d failed to lock\n", pipe);
1464 static void chv_enable_pll(struct intel_crtc *crtc,
1465 const struct intel_crtc_state *pipe_config)
1467 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1468 enum pipe pipe = crtc->pipe;
1470 assert_pipe_disabled(dev_priv, pipe);
1472 /* PLL is protected by panel, make sure we can write it */
1473 assert_panel_unlocked(dev_priv, pipe);
1475 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1476 _chv_enable_pll(crtc, pipe_config);
1478 if (pipe != PIPE_A) {
1480 * WaPixelRepeatModeFixForC0:chv
1482 * DPLLCMD is AWOL. Use chicken bits to propagate
1483 * the value from DPLLBMD to either pipe B or C.
1485 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1486 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1487 I915_WRITE(CBR4_VLV, 0);
1488 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1491 * DPLLB VGA mode also seems to cause problems.
1492 * We should always have it disabled.
1494 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1496 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1497 POSTING_READ(DPLL_MD(pipe));
1501 static bool i9xx_has_pps(struct drm_i915_private *dev_priv)
1503 if (IS_I830(dev_priv))
1506 return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
1509 static void i9xx_enable_pll(struct intel_crtc *crtc,
1510 const struct intel_crtc_state *crtc_state)
1512 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1513 i915_reg_t reg = DPLL(crtc->pipe);
1514 u32 dpll = crtc_state->dpll_hw_state.dpll;
1517 assert_pipe_disabled(dev_priv, crtc->pipe);
1519 /* PLL is protected by panel, make sure we can write it */
1520 if (i9xx_has_pps(dev_priv))
1521 assert_panel_unlocked(dev_priv, crtc->pipe);
1524 * Apparently we need to have VGA mode enabled prior to changing
1525 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1526 * dividers, even though the register value does change.
1528 I915_WRITE(reg, dpll & ~DPLL_VGA_MODE_DIS);
1529 I915_WRITE(reg, dpll);
1531 /* Wait for the clocks to stabilize. */
1535 if (INTEL_GEN(dev_priv) >= 4) {
1536 I915_WRITE(DPLL_MD(crtc->pipe),
1537 crtc_state->dpll_hw_state.dpll_md);
1539 /* The pixel multiplier can only be updated once the
1540 * DPLL is enabled and the clocks are stable.
1542 * So write it again.
1544 I915_WRITE(reg, dpll);
1547 /* We do this three times for luck */
1548 for (i = 0; i < 3; i++) {
1549 I915_WRITE(reg, dpll);
1551 udelay(150); /* wait for warmup */
1555 static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
1557 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1558 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1559 enum pipe pipe = crtc->pipe;
1561 /* Don't disable pipe or pipe PLLs if needed */
1562 if (IS_I830(dev_priv))
1565 /* Make sure the pipe isn't still relying on us */
1566 assert_pipe_disabled(dev_priv, pipe);
1568 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
1569 POSTING_READ(DPLL(pipe));
1572 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1576 /* Make sure the pipe isn't still relying on us */
1577 assert_pipe_disabled(dev_priv, pipe);
1579 val = DPLL_INTEGRATED_REF_CLK_VLV |
1580 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1582 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1584 I915_WRITE(DPLL(pipe), val);
1585 POSTING_READ(DPLL(pipe));
1588 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1590 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1593 /* Make sure the pipe isn't still relying on us */
1594 assert_pipe_disabled(dev_priv, pipe);
1596 val = DPLL_SSC_REF_CLK_CHV |
1597 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1599 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1601 I915_WRITE(DPLL(pipe), val);
1602 POSTING_READ(DPLL(pipe));
1604 vlv_dpio_get(dev_priv);
1606 /* Disable 10bit clock to display controller */
1607 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1608 val &= ~DPIO_DCLKP_EN;
1609 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1611 vlv_dpio_put(dev_priv);
1614 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1615 struct intel_digital_port *dport,
1616 unsigned int expected_mask)
1619 i915_reg_t dpll_reg;
1621 switch (dport->base.port) {
1623 port_mask = DPLL_PORTB_READY_MASK;
1627 port_mask = DPLL_PORTC_READY_MASK;
1629 expected_mask <<= 4;
1632 port_mask = DPLL_PORTD_READY_MASK;
1633 dpll_reg = DPIO_PHY_STATUS;
1639 if (intel_de_wait_for_register(dev_priv, dpll_reg,
1640 port_mask, expected_mask, 1000))
1641 WARN(1, "timed out waiting for [ENCODER:%d:%s] port ready: got 0x%x, expected 0x%x\n",
1642 dport->base.base.base.id, dport->base.base.name,
1643 I915_READ(dpll_reg) & port_mask, expected_mask);
1646 static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
1648 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1649 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1650 enum pipe pipe = crtc->pipe;
1652 u32 val, pipeconf_val;
1654 /* Make sure PCH DPLL is enabled */
1655 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
1657 /* FDI must be feeding us bits for PCH ports */
1658 assert_fdi_tx_enabled(dev_priv, pipe);
1659 assert_fdi_rx_enabled(dev_priv, pipe);
1661 if (HAS_PCH_CPT(dev_priv)) {
1662 /* Workaround: Set the timing override bit before enabling the
1663 * pch transcoder. */
1664 reg = TRANS_CHICKEN2(pipe);
1665 val = I915_READ(reg);
1666 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1667 I915_WRITE(reg, val);
1670 reg = PCH_TRANSCONF(pipe);
1671 val = I915_READ(reg);
1672 pipeconf_val = I915_READ(PIPECONF(pipe));
1674 if (HAS_PCH_IBX(dev_priv)) {
1676 * Make the BPC in transcoder be consistent with
1677 * that in pipeconf reg. For HDMI we must use 8bpc
1678 * here for both 8bpc and 12bpc.
1680 val &= ~PIPECONF_BPC_MASK;
1681 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1682 val |= PIPECONF_8BPC;
1684 val |= pipeconf_val & PIPECONF_BPC_MASK;
1687 val &= ~TRANS_INTERLACE_MASK;
1688 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) {
1689 if (HAS_PCH_IBX(dev_priv) &&
1690 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
1691 val |= TRANS_LEGACY_INTERLACED_ILK;
1693 val |= TRANS_INTERLACED;
1695 val |= TRANS_PROGRESSIVE;
1698 I915_WRITE(reg, val | TRANS_ENABLE);
1699 if (intel_de_wait_for_set(dev_priv, reg, TRANS_STATE_ENABLE, 100))
1700 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
1703 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1704 enum transcoder cpu_transcoder)
1706 u32 val, pipeconf_val;
1708 /* FDI must be feeding us bits for PCH ports */
1709 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1710 assert_fdi_rx_enabled(dev_priv, PIPE_A);
1712 /* Workaround: set timing override bit. */
1713 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1714 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1715 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1718 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
1720 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1721 PIPECONF_INTERLACED_ILK)
1722 val |= TRANS_INTERLACED;
1724 val |= TRANS_PROGRESSIVE;
1726 I915_WRITE(LPT_TRANSCONF, val);
1727 if (intel_de_wait_for_set(dev_priv, LPT_TRANSCONF,
1728 TRANS_STATE_ENABLE, 100))
1729 DRM_ERROR("Failed to enable PCH transcoder\n");
1732 static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1738 /* FDI relies on the transcoder */
1739 assert_fdi_tx_disabled(dev_priv, pipe);
1740 assert_fdi_rx_disabled(dev_priv, pipe);
1742 /* Ports must be off as well */
1743 assert_pch_ports_disabled(dev_priv, pipe);
1745 reg = PCH_TRANSCONF(pipe);
1746 val = I915_READ(reg);
1747 val &= ~TRANS_ENABLE;
1748 I915_WRITE(reg, val);
1749 /* wait for PCH transcoder off, transcoder state */
1750 if (intel_de_wait_for_clear(dev_priv, reg, TRANS_STATE_ENABLE, 50))
1751 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
1753 if (HAS_PCH_CPT(dev_priv)) {
1754 /* Workaround: Clear the timing override chicken bit again. */
1755 reg = TRANS_CHICKEN2(pipe);
1756 val = I915_READ(reg);
1757 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1758 I915_WRITE(reg, val);
1762 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1766 val = I915_READ(LPT_TRANSCONF);
1767 val &= ~TRANS_ENABLE;
1768 I915_WRITE(LPT_TRANSCONF, val);
1769 /* wait for PCH transcoder off, transcoder state */
1770 if (intel_de_wait_for_clear(dev_priv, LPT_TRANSCONF,
1771 TRANS_STATE_ENABLE, 50))
1772 DRM_ERROR("Failed to disable PCH transcoder\n");
1774 /* Workaround: clear timing override bit. */
1775 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1776 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1777 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1780 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
1782 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1784 if (HAS_PCH_LPT(dev_priv))
1790 static u32 intel_crtc_max_vblank_count(const struct intel_crtc_state *crtc_state)
1792 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
1795 * On i965gm the hardware frame counter reads
1796 * zero when the TV encoder is enabled :(
1798 if (IS_I965GM(dev_priv) &&
1799 (crtc_state->output_types & BIT(INTEL_OUTPUT_TVOUT)))
1802 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
1803 return 0xffffffff; /* full 32 bit counter */
1804 else if (INTEL_GEN(dev_priv) >= 3)
1805 return 0xffffff; /* only 24 bits of frame count */
1807 return 0; /* Gen2 doesn't have a hardware frame counter */
1810 static void intel_crtc_vblank_on(const struct intel_crtc_state *crtc_state)
1812 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1814 drm_crtc_set_max_vblank_count(&crtc->base,
1815 intel_crtc_max_vblank_count(crtc_state));
1816 drm_crtc_vblank_on(&crtc->base);
1819 static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
1821 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1822 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1823 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1824 enum pipe pipe = crtc->pipe;
1828 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1830 assert_planes_disabled(crtc);
1833 * A pipe without a PLL won't actually be able to drive bits from
1834 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1837 if (HAS_GMCH(dev_priv)) {
1838 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1839 assert_dsi_pll_enabled(dev_priv);
1841 assert_pll_enabled(dev_priv, pipe);
1843 if (new_crtc_state->has_pch_encoder) {
1844 /* if driving the PCH, we need FDI enabled */
1845 assert_fdi_rx_pll_enabled(dev_priv,
1846 intel_crtc_pch_transcoder(crtc));
1847 assert_fdi_tx_pll_enabled(dev_priv,
1848 (enum pipe) cpu_transcoder);
1850 /* FIXME: assert CPU port conditions for SNB+ */
1853 trace_intel_pipe_enable(crtc);
1855 reg = PIPECONF(cpu_transcoder);
1856 val = I915_READ(reg);
1857 if (val & PIPECONF_ENABLE) {
1858 /* we keep both pipes enabled on 830 */
1859 WARN_ON(!IS_I830(dev_priv));
1863 I915_WRITE(reg, val | PIPECONF_ENABLE);
1867 * Until the pipe starts PIPEDSL reads will return a stale value,
1868 * which causes an apparent vblank timestamp jump when PIPEDSL
1869 * resets to its proper value. That also messes up the frame count
1870 * when it's derived from the timestamps. So let's wait for the
1871 * pipe to start properly before we call drm_crtc_vblank_on()
1873 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
1874 intel_wait_for_pipe_scanline_moving(crtc);
1877 static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1879 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1880 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1881 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1882 enum pipe pipe = crtc->pipe;
1886 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1889 * Make sure planes won't keep trying to pump pixels to us,
1890 * or we might hang the display.
1892 assert_planes_disabled(crtc);
1894 trace_intel_pipe_disable(crtc);
1896 reg = PIPECONF(cpu_transcoder);
1897 val = I915_READ(reg);
1898 if ((val & PIPECONF_ENABLE) == 0)
1902 * Double wide has implications for planes
1903 * so best keep it disabled when not needed.
1905 if (old_crtc_state->double_wide)
1906 val &= ~PIPECONF_DOUBLE_WIDE;
1908 /* Don't disable pipe or pipe PLLs if needed */
1909 if (!IS_I830(dev_priv))
1910 val &= ~PIPECONF_ENABLE;
1912 I915_WRITE(reg, val);
1913 if ((val & PIPECONF_ENABLE) == 0)
1914 intel_wait_for_pipe_off(old_crtc_state);
1917 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1919 return IS_GEN(dev_priv, 2) ? 2048 : 4096;
1923 intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
1925 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1926 unsigned int cpp = fb->format->cpp[color_plane];
1928 switch (fb->modifier) {
1929 case DRM_FORMAT_MOD_LINEAR:
1930 return intel_tile_size(dev_priv);
1931 case I915_FORMAT_MOD_X_TILED:
1932 if (IS_GEN(dev_priv, 2))
1936 case I915_FORMAT_MOD_Y_TILED_CCS:
1937 if (color_plane == 1)
1940 case I915_FORMAT_MOD_Y_TILED:
1941 if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv))
1945 case I915_FORMAT_MOD_Yf_TILED_CCS:
1946 if (color_plane == 1)
1949 case I915_FORMAT_MOD_Yf_TILED:
1965 MISSING_CASE(fb->modifier);
1971 intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
1973 return intel_tile_size(to_i915(fb->dev)) /
1974 intel_tile_width_bytes(fb, color_plane);
1977 /* Return the tile dimensions in pixel units */
1978 static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
1979 unsigned int *tile_width,
1980 unsigned int *tile_height)
1982 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
1983 unsigned int cpp = fb->format->cpp[color_plane];
1985 *tile_width = tile_width_bytes / cpp;
1986 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
1990 intel_fb_align_height(const struct drm_framebuffer *fb,
1991 int color_plane, unsigned int height)
1993 unsigned int tile_height = intel_tile_height(fb, color_plane);
1995 return ALIGN(height, tile_height);
1998 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
2000 unsigned int size = 0;
2003 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
2004 size += rot_info->plane[i].width * rot_info->plane[i].height;
2009 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
2011 unsigned int size = 0;
2014 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++)
2015 size += rem_info->plane[i].width * rem_info->plane[i].height;
2021 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
2022 const struct drm_framebuffer *fb,
2023 unsigned int rotation)
2025 view->type = I915_GGTT_VIEW_NORMAL;
2026 if (drm_rotation_90_or_270(rotation)) {
2027 view->type = I915_GGTT_VIEW_ROTATED;
2028 view->rotated = to_intel_framebuffer(fb)->rot_info;
2032 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
2034 if (IS_I830(dev_priv))
2036 else if (IS_I85X(dev_priv))
2038 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
2044 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
2046 if (INTEL_GEN(dev_priv) >= 9)
2048 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
2049 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2051 else if (INTEL_GEN(dev_priv) >= 4)
2057 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
2060 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2062 /* AUX_DIST needs only 4K alignment */
2063 if (color_plane == 1)
2066 switch (fb->modifier) {
2067 case DRM_FORMAT_MOD_LINEAR:
2068 return intel_linear_alignment(dev_priv);
2069 case I915_FORMAT_MOD_X_TILED:
2070 if (INTEL_GEN(dev_priv) >= 9)
2073 case I915_FORMAT_MOD_Y_TILED_CCS:
2074 case I915_FORMAT_MOD_Yf_TILED_CCS:
2075 case I915_FORMAT_MOD_Y_TILED:
2076 case I915_FORMAT_MOD_Yf_TILED:
2077 return 1 * 1024 * 1024;
2079 MISSING_CASE(fb->modifier);
2084 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2086 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2087 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2089 return INTEL_GEN(dev_priv) < 4 ||
2091 plane_state->view.type == I915_GGTT_VIEW_NORMAL);
2095 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
2096 const struct i915_ggtt_view *view,
2098 unsigned long *out_flags)
2100 struct drm_device *dev = fb->dev;
2101 struct drm_i915_private *dev_priv = to_i915(dev);
2102 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2103 intel_wakeref_t wakeref;
2104 struct i915_vma *vma;
2105 unsigned int pinctl;
2108 if (WARN_ON(!i915_gem_object_is_framebuffer(obj)))
2109 return ERR_PTR(-EINVAL);
2111 alignment = intel_surf_alignment(fb, 0);
2113 /* Note that the w/a also requires 64 PTE of padding following the
2114 * bo. We currently fill all unused PTE with the shadow page and so
2115 * we should always have valid PTE following the scanout preventing
2118 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2119 alignment = 256 * 1024;
2122 * Global gtt pte registers are special registers which actually forward
2123 * writes to a chunk of system memory. Which means that there is no risk
2124 * that the register values disappear as soon as we call
2125 * intel_runtime_pm_put(), so it is correct to wrap only the
2126 * pin/unpin/fence and not more.
2128 wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
2129 i915_gem_object_lock(obj);
2131 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2135 /* Valleyview is definitely limited to scanning out the first
2136 * 512MiB. Lets presume this behaviour was inherited from the
2137 * g4x display engine and that all earlier gen are similarly
2138 * limited. Testing suggests that it is a little more
2139 * complicated than this. For example, Cherryview appears quite
2140 * happy to scanout from anywhere within its global aperture.
2142 if (HAS_GMCH(dev_priv))
2143 pinctl |= PIN_MAPPABLE;
2145 vma = i915_gem_object_pin_to_display_plane(obj,
2146 alignment, view, pinctl);
2150 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
2153 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2154 * fence, whereas 965+ only requires a fence if using
2155 * framebuffer compression. For simplicity, we always, when
2156 * possible, install a fence as the cost is not that onerous.
2158 * If we fail to fence the tiled scanout, then either the
2159 * modeset will reject the change (which is highly unlikely as
2160 * the affected systems, all but one, do not have unmappable
2161 * space) or we will not be able to enable full powersaving
2162 * techniques (also likely not to apply due to various limits
2163 * FBC and the like impose on the size of the buffer, which
2164 * presumably we violated anyway with this unmappable buffer).
2165 * Anyway, it is presumably better to stumble onwards with
2166 * something and try to run the system in a "less than optimal"
2167 * mode that matches the user configuration.
2169 ret = i915_vma_pin_fence(vma);
2170 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
2171 i915_gem_object_unpin_from_display_plane(vma);
2176 if (ret == 0 && vma->fence)
2177 *out_flags |= PLANE_HAS_FENCE;
2182 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2184 i915_gem_object_unlock(obj);
2185 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
2189 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
2191 i915_gem_object_lock(vma->obj);
2192 if (flags & PLANE_HAS_FENCE)
2193 i915_vma_unpin_fence(vma);
2194 i915_gem_object_unpin_from_display_plane(vma);
2195 i915_gem_object_unlock(vma->obj);
2200 static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
2201 unsigned int rotation)
2203 if (drm_rotation_90_or_270(rotation))
2204 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
2206 return fb->pitches[color_plane];
2210 * Convert the x/y offsets into a linear offset.
2211 * Only valid with 0/180 degree rotation, which is fine since linear
2212 * offset is only used with linear buffers on pre-hsw and tiled buffers
2213 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2215 u32 intel_fb_xy_to_linear(int x, int y,
2216 const struct intel_plane_state *state,
2219 const struct drm_framebuffer *fb = state->base.fb;
2220 unsigned int cpp = fb->format->cpp[color_plane];
2221 unsigned int pitch = state->color_plane[color_plane].stride;
2223 return y * pitch + x * cpp;
2227 * Add the x/y offsets derived from fb->offsets[] to the user
2228 * specified plane src x/y offsets. The resulting x/y offsets
2229 * specify the start of scanout from the beginning of the gtt mapping.
2231 void intel_add_fb_offsets(int *x, int *y,
2232 const struct intel_plane_state *state,
2236 *x += state->color_plane[color_plane].x;
2237 *y += state->color_plane[color_plane].y;
2240 static u32 intel_adjust_tile_offset(int *x, int *y,
2241 unsigned int tile_width,
2242 unsigned int tile_height,
2243 unsigned int tile_size,
2244 unsigned int pitch_tiles,
2248 unsigned int pitch_pixels = pitch_tiles * tile_width;
2251 WARN_ON(old_offset & (tile_size - 1));
2252 WARN_ON(new_offset & (tile_size - 1));
2253 WARN_ON(new_offset > old_offset);
2255 tiles = (old_offset - new_offset) / tile_size;
2257 *y += tiles / pitch_tiles * tile_height;
2258 *x += tiles % pitch_tiles * tile_width;
2260 /* minimize x in case it got needlessly big */
2261 *y += *x / pitch_pixels * tile_height;
2267 static bool is_surface_linear(u64 modifier, int color_plane)
2269 return modifier == DRM_FORMAT_MOD_LINEAR;
2272 static u32 intel_adjust_aligned_offset(int *x, int *y,
2273 const struct drm_framebuffer *fb,
2275 unsigned int rotation,
2277 u32 old_offset, u32 new_offset)
2279 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2280 unsigned int cpp = fb->format->cpp[color_plane];
2282 WARN_ON(new_offset > old_offset);
2284 if (!is_surface_linear(fb->modifier, color_plane)) {
2285 unsigned int tile_size, tile_width, tile_height;
2286 unsigned int pitch_tiles;
2288 tile_size = intel_tile_size(dev_priv);
2289 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2291 if (drm_rotation_90_or_270(rotation)) {
2292 pitch_tiles = pitch / tile_height;
2293 swap(tile_width, tile_height);
2295 pitch_tiles = pitch / (tile_width * cpp);
2298 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2299 tile_size, pitch_tiles,
2300 old_offset, new_offset);
2302 old_offset += *y * pitch + *x * cpp;
2304 *y = (old_offset - new_offset) / pitch;
2305 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2312 * Adjust the tile offset by moving the difference into
2315 static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2316 const struct intel_plane_state *state,
2318 u32 old_offset, u32 new_offset)
2320 return intel_adjust_aligned_offset(x, y, state->base.fb, color_plane,
2321 state->base.rotation,
2322 state->color_plane[color_plane].stride,
2323 old_offset, new_offset);
2327 * Computes the aligned offset to the base tile and adjusts
2328 * x, y. bytes per pixel is assumed to be a power-of-two.
2330 * In the 90/270 rotated case, x and y are assumed
2331 * to be already rotated to match the rotated GTT view, and
2332 * pitch is the tile_height aligned framebuffer height.
2334 * This function is used when computing the derived information
2335 * under intel_framebuffer, so using any of that information
2336 * here is not allowed. Anything under drm_framebuffer can be
2337 * used. This is why the user has to pass in the pitch since it
2338 * is specified in the rotated orientation.
2340 static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2342 const struct drm_framebuffer *fb,
2345 unsigned int rotation,
2348 unsigned int cpp = fb->format->cpp[color_plane];
2349 u32 offset, offset_aligned;
2354 if (!is_surface_linear(fb->modifier, color_plane)) {
2355 unsigned int tile_size, tile_width, tile_height;
2356 unsigned int tile_rows, tiles, pitch_tiles;
2358 tile_size = intel_tile_size(dev_priv);
2359 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2361 if (drm_rotation_90_or_270(rotation)) {
2362 pitch_tiles = pitch / tile_height;
2363 swap(tile_width, tile_height);
2365 pitch_tiles = pitch / (tile_width * cpp);
2368 tile_rows = *y / tile_height;
2371 tiles = *x / tile_width;
2374 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2375 offset_aligned = offset & ~alignment;
2377 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2378 tile_size, pitch_tiles,
2379 offset, offset_aligned);
2381 offset = *y * pitch + *x * cpp;
2382 offset_aligned = offset & ~alignment;
2384 *y = (offset & alignment) / pitch;
2385 *x = ((offset & alignment) - *y * pitch) / cpp;
2388 return offset_aligned;
2391 static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2392 const struct intel_plane_state *state,
2395 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2396 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2397 const struct drm_framebuffer *fb = state->base.fb;
2398 unsigned int rotation = state->base.rotation;
2399 int pitch = state->color_plane[color_plane].stride;
2402 if (intel_plane->id == PLANE_CURSOR)
2403 alignment = intel_cursor_alignment(dev_priv);
2405 alignment = intel_surf_alignment(fb, color_plane);
2407 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
2408 pitch, rotation, alignment);
2411 /* Convert the fb->offset[] into x/y offsets */
2412 static int intel_fb_offset_to_xy(int *x, int *y,
2413 const struct drm_framebuffer *fb,
2416 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2417 unsigned int height;
2419 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
2420 fb->offsets[color_plane] % intel_tile_size(dev_priv)) {
2421 DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n",
2422 fb->offsets[color_plane], color_plane);
2426 height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
2427 height = ALIGN(height, intel_tile_height(fb, color_plane));
2429 /* Catch potential overflows early */
2430 if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
2431 fb->offsets[color_plane])) {
2432 DRM_DEBUG_KMS("Bad offset 0x%08x or pitch %d for color plane %d\n",
2433 fb->offsets[color_plane], fb->pitches[color_plane],
2441 intel_adjust_aligned_offset(x, y,
2442 fb, color_plane, DRM_MODE_ROTATE_0,
2443 fb->pitches[color_plane],
2444 fb->offsets[color_plane], 0);
2449 static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier)
2451 switch (fb_modifier) {
2452 case I915_FORMAT_MOD_X_TILED:
2453 return I915_TILING_X;
2454 case I915_FORMAT_MOD_Y_TILED:
2455 case I915_FORMAT_MOD_Y_TILED_CCS:
2456 return I915_TILING_Y;
2458 return I915_TILING_NONE;
2463 * From the Sky Lake PRM:
2464 * "The Color Control Surface (CCS) contains the compression status of
2465 * the cache-line pairs. The compression state of the cache-line pair
2466 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2467 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2468 * cache-line-pairs. CCS is always Y tiled."
2470 * Since cache line pairs refers to horizontally adjacent cache lines,
2471 * each cache line in the CCS corresponds to an area of 32x16 cache
2472 * lines on the main surface. Since each pixel is 4 bytes, this gives
2473 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2476 static const struct drm_format_info ccs_formats[] = {
2477 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
2478 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2479 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
2480 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2481 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
2482 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
2483 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
2484 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
2487 static const struct drm_format_info *
2488 lookup_format_info(const struct drm_format_info formats[],
2489 int num_formats, u32 format)
2493 for (i = 0; i < num_formats; i++) {
2494 if (formats[i].format == format)
2501 static const struct drm_format_info *
2502 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2504 switch (cmd->modifier[0]) {
2505 case I915_FORMAT_MOD_Y_TILED_CCS:
2506 case I915_FORMAT_MOD_Yf_TILED_CCS:
2507 return lookup_format_info(ccs_formats,
2508 ARRAY_SIZE(ccs_formats),
2515 bool is_ccs_modifier(u64 modifier)
2517 return modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2518 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2521 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
2522 u32 pixel_format, u64 modifier)
2524 struct intel_crtc *crtc;
2525 struct intel_plane *plane;
2528 * We assume the primary plane for pipe A has
2529 * the highest stride limits of them all.
2531 crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
2535 plane = to_intel_plane(crtc->base.primary);
2537 return plane->max_stride(plane, pixel_format, modifier,
2542 u32 intel_fb_max_stride(struct drm_i915_private *dev_priv,
2543 u32 pixel_format, u64 modifier)
2546 * Arbitrary limit for gen4+ chosen to match the
2547 * render engine max stride.
2549 * The new CCS hash mode makes remapping impossible
2551 if (!is_ccs_modifier(modifier)) {
2552 if (INTEL_GEN(dev_priv) >= 7)
2554 else if (INTEL_GEN(dev_priv) >= 4)
2558 return intel_plane_fb_max_stride(dev_priv, pixel_format, modifier);
2562 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
2564 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2566 if (fb->modifier == DRM_FORMAT_MOD_LINEAR) {
2567 u32 max_stride = intel_plane_fb_max_stride(dev_priv,
2572 * To make remapping with linear generally feasible
2573 * we need the stride to be page aligned.
2575 if (fb->pitches[color_plane] > max_stride)
2576 return intel_tile_size(dev_priv);
2580 return intel_tile_width_bytes(fb, color_plane);
2584 bool intel_plane_can_remap(const struct intel_plane_state *plane_state)
2586 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2587 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2588 const struct drm_framebuffer *fb = plane_state->base.fb;
2591 /* We don't want to deal with remapping with cursors */
2592 if (plane->id == PLANE_CURSOR)
2596 * The display engine limits already match/exceed the
2597 * render engine limits, so not much point in remapping.
2598 * Would also need to deal with the fence POT alignment
2599 * and gen2 2KiB GTT tile size.
2601 if (INTEL_GEN(dev_priv) < 4)
2605 * The new CCS hash mode isn't compatible with remapping as
2606 * the virtual address of the pages affects the compressed data.
2608 if (is_ccs_modifier(fb->modifier))
2611 /* Linear needs a page aligned stride for remapping */
2612 if (fb->modifier == DRM_FORMAT_MOD_LINEAR) {
2613 unsigned int alignment = intel_tile_size(dev_priv) - 1;
2615 for (i = 0; i < fb->format->num_planes; i++) {
2616 if (fb->pitches[i] & alignment)
2624 static bool intel_plane_needs_remap(const struct intel_plane_state *plane_state)
2626 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2627 const struct drm_framebuffer *fb = plane_state->base.fb;
2628 unsigned int rotation = plane_state->base.rotation;
2629 u32 stride, max_stride;
2632 * No remapping for invisible planes since we don't have
2633 * an actual source viewport to remap.
2635 if (!plane_state->base.visible)
2638 if (!intel_plane_can_remap(plane_state))
2642 * FIXME: aux plane limits on gen9+ are
2643 * unclear in Bspec, for now no checking.
2645 stride = intel_fb_pitch(fb, 0, rotation);
2646 max_stride = plane->max_stride(plane, fb->format->format,
2647 fb->modifier, rotation);
2649 return stride > max_stride;
2653 intel_fill_fb_info(struct drm_i915_private *dev_priv,
2654 struct drm_framebuffer *fb)
2656 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2657 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2658 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2659 u32 gtt_offset_rotated = 0;
2660 unsigned int max_size = 0;
2661 int i, num_planes = fb->format->num_planes;
2662 unsigned int tile_size = intel_tile_size(dev_priv);
2664 for (i = 0; i < num_planes; i++) {
2665 unsigned int width, height;
2666 unsigned int cpp, size;
2671 cpp = fb->format->cpp[i];
2672 width = drm_framebuffer_plane_width(fb->width, fb, i);
2673 height = drm_framebuffer_plane_height(fb->height, fb, i);
2675 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2677 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2682 if (is_ccs_modifier(fb->modifier) && i == 1) {
2683 int hsub = fb->format->hsub;
2684 int vsub = fb->format->vsub;
2685 int tile_width, tile_height;
2689 intel_tile_dims(fb, i, &tile_width, &tile_height);
2691 tile_height *= vsub;
2693 ccs_x = (x * hsub) % tile_width;
2694 ccs_y = (y * vsub) % tile_height;
2695 main_x = intel_fb->normal[0].x % tile_width;
2696 main_y = intel_fb->normal[0].y % tile_height;
2699 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2700 * x/y offsets must match between CCS and the main surface.
2702 if (main_x != ccs_x || main_y != ccs_y) {
2703 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2706 intel_fb->normal[0].x,
2707 intel_fb->normal[0].y,
2714 * The fence (if used) is aligned to the start of the object
2715 * so having the framebuffer wrap around across the edge of the
2716 * fenced region doesn't really work. We have no API to configure
2717 * the fence start offset within the object (nor could we probably
2718 * on gen2/3). So it's just easier if we just require that the
2719 * fb layout agrees with the fence layout. We already check that the
2720 * fb stride matches the fence stride elsewhere.
2722 if (i == 0 && i915_gem_object_is_tiled(obj) &&
2723 (x + width) * cpp > fb->pitches[i]) {
2724 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2730 * First pixel of the framebuffer from
2731 * the start of the normal gtt mapping.
2733 intel_fb->normal[i].x = x;
2734 intel_fb->normal[i].y = y;
2736 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
2740 offset /= tile_size;
2742 if (!is_surface_linear(fb->modifier, i)) {
2743 unsigned int tile_width, tile_height;
2744 unsigned int pitch_tiles;
2747 intel_tile_dims(fb, i, &tile_width, &tile_height);
2749 rot_info->plane[i].offset = offset;
2750 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2751 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2752 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2754 intel_fb->rotated[i].pitch =
2755 rot_info->plane[i].height * tile_height;
2757 /* how many tiles does this plane need */
2758 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2760 * If the plane isn't horizontally tile aligned,
2761 * we need one more tile.
2766 /* rotate the x/y offsets to match the GTT view */
2767 drm_rect_init(&r, x, y, width, height);
2769 rot_info->plane[i].width * tile_width,
2770 rot_info->plane[i].height * tile_height,
2771 DRM_MODE_ROTATE_270);
2775 /* rotate the tile dimensions to match the GTT view */
2776 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2777 swap(tile_width, tile_height);
2780 * We only keep the x/y offsets, so push all of the
2781 * gtt offset into the x/y offsets.
2783 intel_adjust_tile_offset(&x, &y,
2784 tile_width, tile_height,
2785 tile_size, pitch_tiles,
2786 gtt_offset_rotated * tile_size, 0);
2788 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2791 * First pixel of the framebuffer from
2792 * the start of the rotated gtt mapping.
2794 intel_fb->rotated[i].x = x;
2795 intel_fb->rotated[i].y = y;
2797 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2798 x * cpp, tile_size);
2801 /* how many tiles in total needed in the bo */
2802 max_size = max(max_size, offset + size);
2805 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
2806 DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n",
2807 mul_u32_u32(max_size, tile_size), obj->base.size);
2815 intel_plane_remap_gtt(struct intel_plane_state *plane_state)
2817 struct drm_i915_private *dev_priv =
2818 to_i915(plane_state->base.plane->dev);
2819 struct drm_framebuffer *fb = plane_state->base.fb;
2820 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2821 struct intel_rotation_info *info = &plane_state->view.rotated;
2822 unsigned int rotation = plane_state->base.rotation;
2823 int i, num_planes = fb->format->num_planes;
2824 unsigned int tile_size = intel_tile_size(dev_priv);
2825 unsigned int src_x, src_y;
2826 unsigned int src_w, src_h;
2829 memset(&plane_state->view, 0, sizeof(plane_state->view));
2830 plane_state->view.type = drm_rotation_90_or_270(rotation) ?
2831 I915_GGTT_VIEW_ROTATED : I915_GGTT_VIEW_REMAPPED;
2833 src_x = plane_state->base.src.x1 >> 16;
2834 src_y = plane_state->base.src.y1 >> 16;
2835 src_w = drm_rect_width(&plane_state->base.src) >> 16;
2836 src_h = drm_rect_height(&plane_state->base.src) >> 16;
2838 WARN_ON(is_ccs_modifier(fb->modifier));
2840 /* Make src coordinates relative to the viewport */
2841 drm_rect_translate(&plane_state->base.src,
2842 -(src_x << 16), -(src_y << 16));
2844 /* Rotate src coordinates to match rotated GTT view */
2845 if (drm_rotation_90_or_270(rotation))
2846 drm_rect_rotate(&plane_state->base.src,
2847 src_w << 16, src_h << 16,
2848 DRM_MODE_ROTATE_270);
2850 for (i = 0; i < num_planes; i++) {
2851 unsigned int hsub = i ? fb->format->hsub : 1;
2852 unsigned int vsub = i ? fb->format->vsub : 1;
2853 unsigned int cpp = fb->format->cpp[i];
2854 unsigned int tile_width, tile_height;
2855 unsigned int width, height;
2856 unsigned int pitch_tiles;
2860 intel_tile_dims(fb, i, &tile_width, &tile_height);
2864 width = src_w / hsub;
2865 height = src_h / vsub;
2868 * First pixel of the src viewport from the
2869 * start of the normal gtt mapping.
2871 x += intel_fb->normal[i].x;
2872 y += intel_fb->normal[i].y;
2874 offset = intel_compute_aligned_offset(dev_priv, &x, &y,
2875 fb, i, fb->pitches[i],
2876 DRM_MODE_ROTATE_0, tile_size);
2877 offset /= tile_size;
2879 info->plane[i].offset = offset;
2880 info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i],
2882 info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2883 info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2885 if (drm_rotation_90_or_270(rotation)) {
2888 /* rotate the x/y offsets to match the GTT view */
2889 drm_rect_init(&r, x, y, width, height);
2891 info->plane[i].width * tile_width,
2892 info->plane[i].height * tile_height,
2893 DRM_MODE_ROTATE_270);
2897 pitch_tiles = info->plane[i].height;
2898 plane_state->color_plane[i].stride = pitch_tiles * tile_height;
2900 /* rotate the tile dimensions to match the GTT view */
2901 swap(tile_width, tile_height);
2903 pitch_tiles = info->plane[i].width;
2904 plane_state->color_plane[i].stride = pitch_tiles * tile_width * cpp;
2908 * We only keep the x/y offsets, so push all of the
2909 * gtt offset into the x/y offsets.
2911 intel_adjust_tile_offset(&x, &y,
2912 tile_width, tile_height,
2913 tile_size, pitch_tiles,
2914 gtt_offset * tile_size, 0);
2916 gtt_offset += info->plane[i].width * info->plane[i].height;
2918 plane_state->color_plane[i].offset = 0;
2919 plane_state->color_plane[i].x = x;
2920 plane_state->color_plane[i].y = y;
2925 intel_plane_compute_gtt(struct intel_plane_state *plane_state)
2927 const struct intel_framebuffer *fb =
2928 to_intel_framebuffer(plane_state->base.fb);
2929 unsigned int rotation = plane_state->base.rotation;
2935 num_planes = fb->base.format->num_planes;
2937 if (intel_plane_needs_remap(plane_state)) {
2938 intel_plane_remap_gtt(plane_state);
2941 * Sometimes even remapping can't overcome
2942 * the stride limitations :( Can happen with
2943 * big plane sizes and suitably misaligned
2946 return intel_plane_check_stride(plane_state);
2949 intel_fill_fb_ggtt_view(&plane_state->view, &fb->base, rotation);
2951 for (i = 0; i < num_planes; i++) {
2952 plane_state->color_plane[i].stride = intel_fb_pitch(&fb->base, i, rotation);
2953 plane_state->color_plane[i].offset = 0;
2955 if (drm_rotation_90_or_270(rotation)) {
2956 plane_state->color_plane[i].x = fb->rotated[i].x;
2957 plane_state->color_plane[i].y = fb->rotated[i].y;
2959 plane_state->color_plane[i].x = fb->normal[i].x;
2960 plane_state->color_plane[i].y = fb->normal[i].y;
2964 /* Rotate src coordinates to match rotated GTT view */
2965 if (drm_rotation_90_or_270(rotation))
2966 drm_rect_rotate(&plane_state->base.src,
2967 fb->base.width << 16, fb->base.height << 16,
2968 DRM_MODE_ROTATE_270);
2970 return intel_plane_check_stride(plane_state);
2973 static int i9xx_format_to_fourcc(int format)
2976 case DISPPLANE_8BPP:
2977 return DRM_FORMAT_C8;
2978 case DISPPLANE_BGRX555:
2979 return DRM_FORMAT_XRGB1555;
2980 case DISPPLANE_BGRX565:
2981 return DRM_FORMAT_RGB565;
2983 case DISPPLANE_BGRX888:
2984 return DRM_FORMAT_XRGB8888;
2985 case DISPPLANE_RGBX888:
2986 return DRM_FORMAT_XBGR8888;
2987 case DISPPLANE_BGRX101010:
2988 return DRM_FORMAT_XRGB2101010;
2989 case DISPPLANE_RGBX101010:
2990 return DRM_FORMAT_XBGR2101010;
2991 case DISPPLANE_RGBX161616:
2992 return DRM_FORMAT_XBGR16161616F;
2996 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
2999 case PLANE_CTL_FORMAT_RGB_565:
3000 return DRM_FORMAT_RGB565;
3001 case PLANE_CTL_FORMAT_NV12:
3002 return DRM_FORMAT_NV12;
3003 case PLANE_CTL_FORMAT_P010:
3004 return DRM_FORMAT_P010;
3005 case PLANE_CTL_FORMAT_P012:
3006 return DRM_FORMAT_P012;
3007 case PLANE_CTL_FORMAT_P016:
3008 return DRM_FORMAT_P016;
3009 case PLANE_CTL_FORMAT_Y210:
3010 return DRM_FORMAT_Y210;
3011 case PLANE_CTL_FORMAT_Y212:
3012 return DRM_FORMAT_Y212;
3013 case PLANE_CTL_FORMAT_Y216:
3014 return DRM_FORMAT_Y216;
3015 case PLANE_CTL_FORMAT_Y410:
3016 return DRM_FORMAT_XVYU2101010;
3017 case PLANE_CTL_FORMAT_Y412:
3018 return DRM_FORMAT_XVYU12_16161616;
3019 case PLANE_CTL_FORMAT_Y416:
3020 return DRM_FORMAT_XVYU16161616;
3022 case PLANE_CTL_FORMAT_XRGB_8888:
3025 return DRM_FORMAT_ABGR8888;
3027 return DRM_FORMAT_XBGR8888;
3030 return DRM_FORMAT_ARGB8888;
3032 return DRM_FORMAT_XRGB8888;
3034 case PLANE_CTL_FORMAT_XRGB_2101010:
3036 return DRM_FORMAT_XBGR2101010;
3038 return DRM_FORMAT_XRGB2101010;
3039 case PLANE_CTL_FORMAT_XRGB_16161616F:
3042 return DRM_FORMAT_ABGR16161616F;
3044 return DRM_FORMAT_XBGR16161616F;
3047 return DRM_FORMAT_ARGB16161616F;
3049 return DRM_FORMAT_XRGB16161616F;
3055 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
3056 struct intel_initial_plane_config *plane_config)
3058 struct drm_device *dev = crtc->base.dev;
3059 struct drm_i915_private *dev_priv = to_i915(dev);
3060 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
3061 struct drm_framebuffer *fb = &plane_config->fb->base;
3062 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
3063 u32 size_aligned = round_up(plane_config->base + plane_config->size,
3065 struct drm_i915_gem_object *obj;
3068 size_aligned -= base_aligned;
3070 if (plane_config->size == 0)
3073 /* If the FB is too big, just don't use it since fbdev is not very
3074 * important and we should probably use that space with FBC or other
3076 if (size_aligned * 2 > dev_priv->stolen_usable_size)
3079 switch (fb->modifier) {
3080 case DRM_FORMAT_MOD_LINEAR:
3081 case I915_FORMAT_MOD_X_TILED:
3082 case I915_FORMAT_MOD_Y_TILED:
3085 DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n",
3090 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
3097 switch (plane_config->tiling) {
3098 case I915_TILING_NONE:
3102 obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling;
3105 MISSING_CASE(plane_config->tiling);
3109 mode_cmd.pixel_format = fb->format->format;
3110 mode_cmd.width = fb->width;
3111 mode_cmd.height = fb->height;
3112 mode_cmd.pitches[0] = fb->pitches[0];
3113 mode_cmd.modifier[0] = fb->modifier;
3114 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
3116 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
3117 DRM_DEBUG_KMS("intel fb init failed\n");
3122 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
3125 i915_gem_object_put(obj);
3130 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
3131 struct intel_plane_state *plane_state,
3134 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
3136 plane_state->base.visible = visible;
3139 crtc_state->base.plane_mask |= drm_plane_mask(&plane->base);
3141 crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base);
3144 static void fixup_active_planes(struct intel_crtc_state *crtc_state)
3146 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
3147 struct drm_plane *plane;
3150 * Active_planes aliases if multiple "primary" or cursor planes
3151 * have been used on the same (or wrong) pipe. plane_mask uses
3152 * unique ids, hence we can use that to reconstruct active_planes.
3154 crtc_state->active_planes = 0;
3156 drm_for_each_plane_mask(plane, &dev_priv->drm,
3157 crtc_state->base.plane_mask)
3158 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
3161 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
3162 struct intel_plane *plane)
3164 struct intel_crtc_state *crtc_state =
3165 to_intel_crtc_state(crtc->base.state);
3166 struct intel_plane_state *plane_state =
3167 to_intel_plane_state(plane->base.state);
3169 DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
3170 plane->base.base.id, plane->base.name,
3171 crtc->base.base.id, crtc->base.name);
3173 intel_set_plane_visible(crtc_state, plane_state, false);
3174 fixup_active_planes(crtc_state);
3175 crtc_state->data_rate[plane->id] = 0;
3176 crtc_state->min_cdclk[plane->id] = 0;
3178 if (plane->id == PLANE_PRIMARY)
3179 intel_pre_disable_primary_noatomic(&crtc->base);
3181 intel_disable_plane(plane, crtc_state);
3184 static struct intel_frontbuffer *
3185 to_intel_frontbuffer(struct drm_framebuffer *fb)
3187 return fb ? to_intel_framebuffer(fb)->frontbuffer : NULL;
3191 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
3192 struct intel_initial_plane_config *plane_config)
3194 struct drm_device *dev = intel_crtc->base.dev;
3195 struct drm_i915_private *dev_priv = to_i915(dev);
3197 struct drm_plane *primary = intel_crtc->base.primary;
3198 struct drm_plane_state *plane_state = primary->state;
3199 struct intel_plane *intel_plane = to_intel_plane(primary);
3200 struct intel_plane_state *intel_state =
3201 to_intel_plane_state(plane_state);
3202 struct drm_framebuffer *fb;
3204 if (!plane_config->fb)
3207 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
3208 fb = &plane_config->fb->base;
3212 kfree(plane_config->fb);
3215 * Failed to alloc the obj, check to see if we should share
3216 * an fb with another CRTC instead
3218 for_each_crtc(dev, c) {
3219 struct intel_plane_state *state;
3221 if (c == &intel_crtc->base)
3224 if (!to_intel_crtc(c)->active)
3227 state = to_intel_plane_state(c->primary->state);
3231 if (intel_plane_ggtt_offset(state) == plane_config->base) {
3232 fb = state->base.fb;
3233 drm_framebuffer_get(fb);
3239 * We've failed to reconstruct the BIOS FB. Current display state
3240 * indicates that the primary plane is visible, but has a NULL FB,
3241 * which will lead to problems later if we don't fix it up. The
3242 * simplest solution is to just disable the primary plane now and
3243 * pretend the BIOS never had it enabled.
3245 intel_plane_disable_noatomic(intel_crtc, intel_plane);
3250 intel_state->base.rotation = plane_config->rotation;
3251 intel_fill_fb_ggtt_view(&intel_state->view, fb,
3252 intel_state->base.rotation);
3253 intel_state->color_plane[0].stride =
3254 intel_fb_pitch(fb, 0, intel_state->base.rotation);
3257 intel_pin_and_fence_fb_obj(fb,
3259 intel_plane_uses_fence(intel_state),
3260 &intel_state->flags);
3261 if (IS_ERR(intel_state->vma)) {
3262 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
3263 intel_crtc->pipe, PTR_ERR(intel_state->vma));
3265 intel_state->vma = NULL;
3266 drm_framebuffer_put(fb);
3270 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
3272 plane_state->src_x = 0;
3273 plane_state->src_y = 0;
3274 plane_state->src_w = fb->width << 16;
3275 plane_state->src_h = fb->height << 16;
3277 plane_state->crtc_x = 0;
3278 plane_state->crtc_y = 0;
3279 plane_state->crtc_w = fb->width;
3280 plane_state->crtc_h = fb->height;
3282 intel_state->base.src = drm_plane_state_src(plane_state);
3283 intel_state->base.dst = drm_plane_state_dest(plane_state);
3285 if (plane_config->tiling)
3286 dev_priv->preserve_bios_swizzle = true;
3288 plane_state->fb = fb;
3289 plane_state->crtc = &intel_crtc->base;
3291 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
3292 &to_intel_frontbuffer(fb)->bits);
3295 static int skl_max_plane_width(const struct drm_framebuffer *fb,
3297 unsigned int rotation)
3299 int cpp = fb->format->cpp[color_plane];
3301 switch (fb->modifier) {
3302 case DRM_FORMAT_MOD_LINEAR:
3303 case I915_FORMAT_MOD_X_TILED:
3305 * Validated limit is 4k, but has 5k should
3306 * work apart from the following features:
3307 * - Ytile (already limited to 4k)
3308 * - FP16 (already limited to 4k)
3309 * - render compression (already limited to 4k)
3310 * - KVMR sprite and cursor (don't care)
3311 * - horizontal panning (TODO verify this)
3312 * - pipe and plane scaling (TODO verify this)
3318 case I915_FORMAT_MOD_Y_TILED_CCS:
3319 case I915_FORMAT_MOD_Yf_TILED_CCS:
3320 /* FIXME AUX plane? */
3321 case I915_FORMAT_MOD_Y_TILED:
3322 case I915_FORMAT_MOD_Yf_TILED:
3328 MISSING_CASE(fb->modifier);
3333 static int glk_max_plane_width(const struct drm_framebuffer *fb,
3335 unsigned int rotation)
3337 int cpp = fb->format->cpp[color_plane];
3339 switch (fb->modifier) {
3340 case DRM_FORMAT_MOD_LINEAR:
3341 case I915_FORMAT_MOD_X_TILED:
3346 case I915_FORMAT_MOD_Y_TILED_CCS:
3347 case I915_FORMAT_MOD_Yf_TILED_CCS:
3348 /* FIXME AUX plane? */
3349 case I915_FORMAT_MOD_Y_TILED:
3350 case I915_FORMAT_MOD_Yf_TILED:
3356 MISSING_CASE(fb->modifier);
3361 static int icl_max_plane_width(const struct drm_framebuffer *fb,
3363 unsigned int rotation)
3368 static int skl_max_plane_height(void)
3373 static int icl_max_plane_height(void)
3378 static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
3379 int main_x, int main_y, u32 main_offset)
3381 const struct drm_framebuffer *fb = plane_state->base.fb;
3382 int hsub = fb->format->hsub;
3383 int vsub = fb->format->vsub;
3384 int aux_x = plane_state->color_plane[1].x;
3385 int aux_y = plane_state->color_plane[1].y;
3386 u32 aux_offset = plane_state->color_plane[1].offset;
3387 u32 alignment = intel_surf_alignment(fb, 1);
3389 while (aux_offset >= main_offset && aux_y <= main_y) {
3392 if (aux_x == main_x && aux_y == main_y)
3395 if (aux_offset == 0)
3400 aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1,
3401 aux_offset, aux_offset - alignment);
3402 aux_x = x * hsub + aux_x % hsub;
3403 aux_y = y * vsub + aux_y % vsub;
3406 if (aux_x != main_x || aux_y != main_y)
3409 plane_state->color_plane[1].offset = aux_offset;
3410 plane_state->color_plane[1].x = aux_x;
3411 plane_state->color_plane[1].y = aux_y;
3416 static int skl_check_main_surface(struct intel_plane_state *plane_state)
3418 struct drm_i915_private *dev_priv = to_i915(plane_state->base.plane->dev);
3419 const struct drm_framebuffer *fb = plane_state->base.fb;
3420 unsigned int rotation = plane_state->base.rotation;
3421 int x = plane_state->base.src.x1 >> 16;
3422 int y = plane_state->base.src.y1 >> 16;
3423 int w = drm_rect_width(&plane_state->base.src) >> 16;
3424 int h = drm_rect_height(&plane_state->base.src) >> 16;
3427 u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset;
3429 if (INTEL_GEN(dev_priv) >= 11)
3430 max_width = icl_max_plane_width(fb, 0, rotation);
3431 else if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
3432 max_width = glk_max_plane_width(fb, 0, rotation);
3434 max_width = skl_max_plane_width(fb, 0, rotation);
3436 if (INTEL_GEN(dev_priv) >= 11)
3437 max_height = icl_max_plane_height();
3439 max_height = skl_max_plane_height();
3441 if (w > max_width || h > max_height) {
3442 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
3443 w, h, max_width, max_height);
3447 intel_add_fb_offsets(&x, &y, plane_state, 0);
3448 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
3449 alignment = intel_surf_alignment(fb, 0);
3452 * AUX surface offset is specified as the distance from the
3453 * main surface offset, and it must be non-negative. Make
3454 * sure that is what we will get.
3456 if (offset > aux_offset)
3457 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3458 offset, aux_offset & ~(alignment - 1));
3461 * When using an X-tiled surface, the plane blows up
3462 * if the x offset + width exceed the stride.
3464 * TODO: linear and Y-tiled seem fine, Yf untested,
3466 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3467 int cpp = fb->format->cpp[0];
3469 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
3471 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
3475 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3476 offset, offset - alignment);
3481 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3482 * they match with the main surface x/y offsets.
3484 if (is_ccs_modifier(fb->modifier)) {
3485 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3489 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3490 offset, offset - alignment);
3493 if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) {
3494 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3499 plane_state->color_plane[0].offset = offset;
3500 plane_state->color_plane[0].x = x;
3501 plane_state->color_plane[0].y = y;
3504 * Put the final coordinates back so that the src
3505 * coordinate checks will see the right values.
3507 drm_rect_translate_to(&plane_state->base.src,
3513 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3515 const struct drm_framebuffer *fb = plane_state->base.fb;
3516 unsigned int rotation = plane_state->base.rotation;
3517 int max_width = skl_max_plane_width(fb, 1, rotation);
3518 int max_height = 4096;
3519 int x = plane_state->base.src.x1 >> 17;
3520 int y = plane_state->base.src.y1 >> 17;
3521 int w = drm_rect_width(&plane_state->base.src) >> 17;
3522 int h = drm_rect_height(&plane_state->base.src) >> 17;
3525 intel_add_fb_offsets(&x, &y, plane_state, 1);
3526 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3528 /* FIXME not quite sure how/if these apply to the chroma plane */
3529 if (w > max_width || h > max_height) {
3530 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3531 w, h, max_width, max_height);
3535 plane_state->color_plane[1].offset = offset;
3536 plane_state->color_plane[1].x = x;
3537 plane_state->color_plane[1].y = y;
3542 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3544 const struct drm_framebuffer *fb = plane_state->base.fb;
3545 int src_x = plane_state->base.src.x1 >> 16;
3546 int src_y = plane_state->base.src.y1 >> 16;
3547 int hsub = fb->format->hsub;
3548 int vsub = fb->format->vsub;
3549 int x = src_x / hsub;
3550 int y = src_y / vsub;
3553 intel_add_fb_offsets(&x, &y, plane_state, 1);
3554 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3556 plane_state->color_plane[1].offset = offset;
3557 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3558 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
3563 int skl_check_plane_surface(struct intel_plane_state *plane_state)
3565 const struct drm_framebuffer *fb = plane_state->base.fb;
3568 ret = intel_plane_compute_gtt(plane_state);
3572 if (!plane_state->base.visible)
3576 * Handle the AUX surface first since
3577 * the main surface setup depends on it.
3579 if (drm_format_info_is_yuv_semiplanar(fb->format)) {
3580 ret = skl_check_nv12_aux_surface(plane_state);
3583 } else if (is_ccs_modifier(fb->modifier)) {
3584 ret = skl_check_ccs_aux_surface(plane_state);
3588 plane_state->color_plane[1].offset = ~0xfff;
3589 plane_state->color_plane[1].x = 0;
3590 plane_state->color_plane[1].y = 0;
3593 ret = skl_check_main_surface(plane_state);
3600 static void i9xx_plane_ratio(const struct intel_crtc_state *crtc_state,
3601 const struct intel_plane_state *plane_state,
3602 unsigned int *num, unsigned int *den)
3604 const struct drm_framebuffer *fb = plane_state->base.fb;
3605 unsigned int cpp = fb->format->cpp[0];
3608 * g4x bspec says 64bpp pixel rate can't exceed 80%
3609 * of cdclk when the sprite plane is enabled on the
3610 * same pipe. ilk/snb bspec says 64bpp pixel rate is
3611 * never allowed to exceed 80% of cdclk. Let's just go
3612 * with the ilk/snb limit always.
3623 static int i9xx_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
3624 const struct intel_plane_state *plane_state)
3626 unsigned int pixel_rate;
3627 unsigned int num, den;
3630 * Note that crtc_state->pixel_rate accounts for both
3631 * horizontal and vertical panel fitter downscaling factors.
3632 * Pre-HSW bspec tells us to only consider the horizontal
3633 * downscaling factor here. We ignore that and just consider
3634 * both for simplicity.
3636 pixel_rate = crtc_state->pixel_rate;
3638 i9xx_plane_ratio(crtc_state, plane_state, &num, &den);
3640 /* two pixels per clock with double wide pipe */
3641 if (crtc_state->double_wide)
3644 return DIV_ROUND_UP(pixel_rate * num, den);
3648 i9xx_plane_max_stride(struct intel_plane *plane,
3649 u32 pixel_format, u64 modifier,
3650 unsigned int rotation)
3652 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3654 if (!HAS_GMCH(dev_priv)) {
3656 } else if (INTEL_GEN(dev_priv) >= 4) {
3657 if (modifier == I915_FORMAT_MOD_X_TILED)
3661 } else if (INTEL_GEN(dev_priv) >= 3) {
3662 if (modifier == I915_FORMAT_MOD_X_TILED)
3667 if (plane->i9xx_plane == PLANE_C)
3674 static u32 i9xx_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
3676 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3677 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3680 if (crtc_state->gamma_enable)
3681 dspcntr |= DISPPLANE_GAMMA_ENABLE;
3683 if (crtc_state->csc_enable)
3684 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
3686 if (INTEL_GEN(dev_priv) < 5)
3687 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
3692 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3693 const struct intel_plane_state *plane_state)
3695 struct drm_i915_private *dev_priv =
3696 to_i915(plane_state->base.plane->dev);
3697 const struct drm_framebuffer *fb = plane_state->base.fb;
3698 unsigned int rotation = plane_state->base.rotation;
3701 dspcntr = DISPLAY_PLANE_ENABLE;
3703 if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) ||
3704 IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
3705 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
3707 switch (fb->format->format) {
3709 dspcntr |= DISPPLANE_8BPP;
3711 case DRM_FORMAT_XRGB1555:
3712 dspcntr |= DISPPLANE_BGRX555;
3714 case DRM_FORMAT_RGB565:
3715 dspcntr |= DISPPLANE_BGRX565;
3717 case DRM_FORMAT_XRGB8888:
3718 dspcntr |= DISPPLANE_BGRX888;
3720 case DRM_FORMAT_XBGR8888:
3721 dspcntr |= DISPPLANE_RGBX888;
3723 case DRM_FORMAT_XRGB2101010:
3724 dspcntr |= DISPPLANE_BGRX101010;
3726 case DRM_FORMAT_XBGR2101010:
3727 dspcntr |= DISPPLANE_RGBX101010;
3729 case DRM_FORMAT_XBGR16161616F:
3730 dspcntr |= DISPPLANE_RGBX161616;
3733 MISSING_CASE(fb->format->format);
3737 if (INTEL_GEN(dev_priv) >= 4 &&
3738 fb->modifier == I915_FORMAT_MOD_X_TILED)
3739 dspcntr |= DISPPLANE_TILED;
3741 if (rotation & DRM_MODE_ROTATE_180)
3742 dspcntr |= DISPPLANE_ROTATE_180;
3744 if (rotation & DRM_MODE_REFLECT_X)
3745 dspcntr |= DISPPLANE_MIRROR;
3750 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
3752 struct drm_i915_private *dev_priv =
3753 to_i915(plane_state->base.plane->dev);
3754 const struct drm_framebuffer *fb = plane_state->base.fb;
3755 int src_x, src_y, src_w;
3759 ret = intel_plane_compute_gtt(plane_state);
3763 if (!plane_state->base.visible)
3766 src_w = drm_rect_width(&plane_state->base.src) >> 16;
3767 src_x = plane_state->base.src.x1 >> 16;
3768 src_y = plane_state->base.src.y1 >> 16;
3770 /* Undocumented hardware limit on i965/g4x/vlv/chv */
3771 if (HAS_GMCH(dev_priv) && fb->format->cpp[0] == 8 && src_w > 2048)
3774 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
3776 if (INTEL_GEN(dev_priv) >= 4)
3777 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
3783 * Put the final coordinates back so that the src
3784 * coordinate checks will see the right values.
3786 drm_rect_translate_to(&plane_state->base.src,
3787 src_x << 16, src_y << 16);
3789 /* HSW/BDW do this automagically in hardware */
3790 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
3791 unsigned int rotation = plane_state->base.rotation;
3792 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3793 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3795 if (rotation & DRM_MODE_ROTATE_180) {
3798 } else if (rotation & DRM_MODE_REFLECT_X) {
3803 plane_state->color_plane[0].offset = offset;
3804 plane_state->color_plane[0].x = src_x;
3805 plane_state->color_plane[0].y = src_y;
3810 static bool i9xx_plane_has_windowing(struct intel_plane *plane)
3812 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3813 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3815 if (IS_CHERRYVIEW(dev_priv))
3816 return i9xx_plane == PLANE_B;
3817 else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
3819 else if (IS_GEN(dev_priv, 4))
3820 return i9xx_plane == PLANE_C;
3822 return i9xx_plane == PLANE_B ||
3823 i9xx_plane == PLANE_C;
3827 i9xx_plane_check(struct intel_crtc_state *crtc_state,
3828 struct intel_plane_state *plane_state)
3830 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
3833 ret = chv_plane_check_rotation(plane_state);
3837 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
3839 DRM_PLANE_HELPER_NO_SCALING,
3840 DRM_PLANE_HELPER_NO_SCALING,
3841 i9xx_plane_has_windowing(plane),
3846 ret = i9xx_check_plane_surface(plane_state);
3850 if (!plane_state->base.visible)
3853 ret = intel_plane_check_src_coordinates(plane_state);
3857 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
3862 static void i9xx_update_plane(struct intel_plane *plane,
3863 const struct intel_crtc_state *crtc_state,
3864 const struct intel_plane_state *plane_state)
3866 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3867 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3869 int x = plane_state->color_plane[0].x;
3870 int y = plane_state->color_plane[0].y;
3871 int crtc_x = plane_state->base.dst.x1;
3872 int crtc_y = plane_state->base.dst.y1;
3873 int crtc_w = drm_rect_width(&plane_state->base.dst);
3874 int crtc_h = drm_rect_height(&plane_state->base.dst);
3875 unsigned long irqflags;
3879 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
3881 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
3883 if (INTEL_GEN(dev_priv) >= 4)
3884 dspaddr_offset = plane_state->color_plane[0].offset;
3886 dspaddr_offset = linear_offset;
3888 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3890 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
3892 if (INTEL_GEN(dev_priv) < 4) {
3894 * PLANE_A doesn't actually have a full window
3895 * generator but let's assume we still need to
3896 * program whatever is there.
3898 I915_WRITE_FW(DSPPOS(i9xx_plane), (crtc_y << 16) | crtc_x);
3899 I915_WRITE_FW(DSPSIZE(i9xx_plane),
3900 ((crtc_h - 1) << 16) | (crtc_w - 1));
3901 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
3902 I915_WRITE_FW(PRIMPOS(i9xx_plane), (crtc_y << 16) | crtc_x);
3903 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
3904 ((crtc_h - 1) << 16) | (crtc_w - 1));
3905 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
3908 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3909 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
3910 } else if (INTEL_GEN(dev_priv) >= 4) {
3911 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3912 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3916 * The control register self-arms if the plane was previously
3917 * disabled. Try to make the plane enable atomic by writing
3918 * the control register just before the surface register.
3920 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3921 if (INTEL_GEN(dev_priv) >= 4)
3922 I915_WRITE_FW(DSPSURF(i9xx_plane),
3923 intel_plane_ggtt_offset(plane_state) +
3926 I915_WRITE_FW(DSPADDR(i9xx_plane),
3927 intel_plane_ggtt_offset(plane_state) +
3930 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3933 static void i9xx_disable_plane(struct intel_plane *plane,
3934 const struct intel_crtc_state *crtc_state)
3936 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3937 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3938 unsigned long irqflags;
3942 * DSPCNTR pipe gamma enable on g4x+ and pipe csc
3943 * enable on ilk+ affect the pipe bottom color as
3944 * well, so we must configure them even if the plane
3947 * On pre-g4x there is no way to gamma correct the
3948 * pipe bottom color but we'll keep on doing this
3949 * anyway so that the crtc state readout works correctly.
3951 dspcntr = i9xx_plane_ctl_crtc(crtc_state);
3953 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3955 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3956 if (INTEL_GEN(dev_priv) >= 4)
3957 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
3959 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
3961 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3964 static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
3967 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3968 enum intel_display_power_domain power_domain;
3969 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3970 intel_wakeref_t wakeref;
3975 * Not 100% correct for planes that can move between pipes,
3976 * but that's only the case for gen2-4 which don't have any
3977 * display power wells.
3979 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
3980 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3984 val = I915_READ(DSPCNTR(i9xx_plane));
3986 ret = val & DISPLAY_PLANE_ENABLE;
3988 if (INTEL_GEN(dev_priv) >= 5)
3989 *pipe = plane->pipe;
3991 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
3992 DISPPLANE_SEL_PIPE_SHIFT;
3994 intel_display_power_put(dev_priv, power_domain, wakeref);
3999 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
4001 struct drm_device *dev = intel_crtc->base.dev;
4002 struct drm_i915_private *dev_priv = to_i915(dev);
4004 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
4005 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
4006 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
4010 * This function detaches (aka. unbinds) unused scalers in hardware
4012 static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
4014 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4015 const struct intel_crtc_scaler_state *scaler_state =
4016 &crtc_state->scaler_state;
4019 /* loop through and disable scalers that aren't in use */
4020 for (i = 0; i < intel_crtc->num_scalers; i++) {
4021 if (!scaler_state->scalers[i].in_use)
4022 skl_detach_scaler(intel_crtc, i);
4026 static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
4027 int color_plane, unsigned int rotation)
4030 * The stride is either expressed as a multiple of 64 bytes chunks for
4031 * linear buffers or in number of tiles for tiled buffers.
4033 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
4035 else if (drm_rotation_90_or_270(rotation))
4036 return intel_tile_height(fb, color_plane);
4038 return intel_tile_width_bytes(fb, color_plane);
4041 u32 skl_plane_stride(const struct intel_plane_state *plane_state,
4044 const struct drm_framebuffer *fb = plane_state->base.fb;
4045 unsigned int rotation = plane_state->base.rotation;
4046 u32 stride = plane_state->color_plane[color_plane].stride;
4048 if (color_plane >= fb->format->num_planes)
4051 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
4054 static u32 skl_plane_ctl_format(u32 pixel_format)
4056 switch (pixel_format) {
4058 return PLANE_CTL_FORMAT_INDEXED;
4059 case DRM_FORMAT_RGB565:
4060 return PLANE_CTL_FORMAT_RGB_565;
4061 case DRM_FORMAT_XBGR8888:
4062 case DRM_FORMAT_ABGR8888:
4063 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
4064 case DRM_FORMAT_XRGB8888:
4065 case DRM_FORMAT_ARGB8888:
4066 return PLANE_CTL_FORMAT_XRGB_8888;
4067 case DRM_FORMAT_XBGR2101010:
4068 return PLANE_CTL_FORMAT_XRGB_2101010 | PLANE_CTL_ORDER_RGBX;
4069 case DRM_FORMAT_XRGB2101010:
4070 return PLANE_CTL_FORMAT_XRGB_2101010;
4071 case DRM_FORMAT_XBGR16161616F:
4072 case DRM_FORMAT_ABGR16161616F:
4073 return PLANE_CTL_FORMAT_XRGB_16161616F | PLANE_CTL_ORDER_RGBX;
4074 case DRM_FORMAT_XRGB16161616F:
4075 case DRM_FORMAT_ARGB16161616F:
4076 return PLANE_CTL_FORMAT_XRGB_16161616F;
4077 case DRM_FORMAT_YUYV:
4078 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
4079 case DRM_FORMAT_YVYU:
4080 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
4081 case DRM_FORMAT_UYVY:
4082 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
4083 case DRM_FORMAT_VYUY:
4084 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
4085 case DRM_FORMAT_NV12:
4086 return PLANE_CTL_FORMAT_NV12;
4087 case DRM_FORMAT_P010:
4088 return PLANE_CTL_FORMAT_P010;
4089 case DRM_FORMAT_P012:
4090 return PLANE_CTL_FORMAT_P012;
4091 case DRM_FORMAT_P016:
4092 return PLANE_CTL_FORMAT_P016;
4093 case DRM_FORMAT_Y210:
4094 return PLANE_CTL_FORMAT_Y210;
4095 case DRM_FORMAT_Y212:
4096 return PLANE_CTL_FORMAT_Y212;
4097 case DRM_FORMAT_Y216:
4098 return PLANE_CTL_FORMAT_Y216;
4099 case DRM_FORMAT_XVYU2101010:
4100 return PLANE_CTL_FORMAT_Y410;
4101 case DRM_FORMAT_XVYU12_16161616:
4102 return PLANE_CTL_FORMAT_Y412;
4103 case DRM_FORMAT_XVYU16161616:
4104 return PLANE_CTL_FORMAT_Y416;
4106 MISSING_CASE(pixel_format);
4112 static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
4114 if (!plane_state->base.fb->format->has_alpha)
4115 return PLANE_CTL_ALPHA_DISABLE;
4117 switch (plane_state->base.pixel_blend_mode) {
4118 case DRM_MODE_BLEND_PIXEL_NONE:
4119 return PLANE_CTL_ALPHA_DISABLE;
4120 case DRM_MODE_BLEND_PREMULTI:
4121 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
4122 case DRM_MODE_BLEND_COVERAGE:
4123 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
4125 MISSING_CASE(plane_state->base.pixel_blend_mode);
4126 return PLANE_CTL_ALPHA_DISABLE;
4130 static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
4132 if (!plane_state->base.fb->format->has_alpha)
4133 return PLANE_COLOR_ALPHA_DISABLE;
4135 switch (plane_state->base.pixel_blend_mode) {
4136 case DRM_MODE_BLEND_PIXEL_NONE:
4137 return PLANE_COLOR_ALPHA_DISABLE;
4138 case DRM_MODE_BLEND_PREMULTI:
4139 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
4140 case DRM_MODE_BLEND_COVERAGE:
4141 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
4143 MISSING_CASE(plane_state->base.pixel_blend_mode);
4144 return PLANE_COLOR_ALPHA_DISABLE;
4148 static u32 skl_plane_ctl_tiling(u64 fb_modifier)
4150 switch (fb_modifier) {
4151 case DRM_FORMAT_MOD_LINEAR:
4153 case I915_FORMAT_MOD_X_TILED:
4154 return PLANE_CTL_TILED_X;
4155 case I915_FORMAT_MOD_Y_TILED:
4156 return PLANE_CTL_TILED_Y;
4157 case I915_FORMAT_MOD_Y_TILED_CCS:
4158 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
4159 case I915_FORMAT_MOD_Yf_TILED:
4160 return PLANE_CTL_TILED_YF;
4161 case I915_FORMAT_MOD_Yf_TILED_CCS:
4162 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
4164 MISSING_CASE(fb_modifier);
4170 static u32 skl_plane_ctl_rotate(unsigned int rotate)
4173 case DRM_MODE_ROTATE_0:
4176 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
4177 * while i915 HW rotation is clockwise, thats why this swapping.
4179 case DRM_MODE_ROTATE_90:
4180 return PLANE_CTL_ROTATE_270;
4181 case DRM_MODE_ROTATE_180:
4182 return PLANE_CTL_ROTATE_180;
4183 case DRM_MODE_ROTATE_270:
4184 return PLANE_CTL_ROTATE_90;
4186 MISSING_CASE(rotate);
4192 static u32 cnl_plane_ctl_flip(unsigned int reflect)
4197 case DRM_MODE_REFLECT_X:
4198 return PLANE_CTL_FLIP_HORIZONTAL;
4199 case DRM_MODE_REFLECT_Y:
4201 MISSING_CASE(reflect);
4207 u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
4209 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
4212 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
4215 if (crtc_state->gamma_enable)
4216 plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE;
4218 if (crtc_state->csc_enable)
4219 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
4224 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
4225 const struct intel_plane_state *plane_state)
4227 struct drm_i915_private *dev_priv =
4228 to_i915(plane_state->base.plane->dev);
4229 const struct drm_framebuffer *fb = plane_state->base.fb;
4230 unsigned int rotation = plane_state->base.rotation;
4231 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
4234 plane_ctl = PLANE_CTL_ENABLE;
4236 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
4237 plane_ctl |= skl_plane_ctl_alpha(plane_state);
4238 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
4240 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
4241 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
4243 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
4244 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
4247 plane_ctl |= skl_plane_ctl_format(fb->format->format);
4248 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
4249 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
4251 if (INTEL_GEN(dev_priv) >= 10)
4252 plane_ctl |= cnl_plane_ctl_flip(rotation &
4253 DRM_MODE_REFLECT_MASK);
4255 if (key->flags & I915_SET_COLORKEY_DESTINATION)
4256 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
4257 else if (key->flags & I915_SET_COLORKEY_SOURCE)
4258 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
4263 u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state)
4265 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
4266 u32 plane_color_ctl = 0;
4268 if (INTEL_GEN(dev_priv) >= 11)
4269 return plane_color_ctl;
4271 if (crtc_state->gamma_enable)
4272 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
4274 if (crtc_state->csc_enable)
4275 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
4277 return plane_color_ctl;
4280 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
4281 const struct intel_plane_state *plane_state)
4283 struct drm_i915_private *dev_priv =
4284 to_i915(plane_state->base.plane->dev);
4285 const struct drm_framebuffer *fb = plane_state->base.fb;
4286 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
4287 u32 plane_color_ctl = 0;
4289 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
4290 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
4292 if (fb->format->is_yuv && !icl_is_hdr_plane(dev_priv, plane->id)) {
4293 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
4294 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
4296 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
4298 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
4299 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
4300 } else if (fb->format->is_yuv) {
4301 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
4304 return plane_color_ctl;
4308 __intel_display_resume(struct drm_device *dev,
4309 struct drm_atomic_state *state,
4310 struct drm_modeset_acquire_ctx *ctx)
4312 struct drm_crtc_state *crtc_state;
4313 struct drm_crtc *crtc;
4316 intel_modeset_setup_hw_state(dev, ctx);
4317 intel_vga_redisable(to_i915(dev));
4323 * We've duplicated the state, pointers to the old state are invalid.
4325 * Don't attempt to use the old state until we commit the duplicated state.
4327 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
4329 * Force recalculation even if we restore
4330 * current state. With fast modeset this may not result
4331 * in a modeset when the state is compatible.
4333 crtc_state->mode_changed = true;
4336 /* ignore any reset values/BIOS leftovers in the WM registers */
4337 if (!HAS_GMCH(to_i915(dev)))
4338 to_intel_atomic_state(state)->skip_intermediate_wm = true;
4340 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
4342 WARN_ON(ret == -EDEADLK);
4346 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
4348 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
4349 intel_has_gpu_reset(&dev_priv->gt));
4352 void intel_prepare_reset(struct drm_i915_private *dev_priv)
4354 struct drm_device *dev = &dev_priv->drm;
4355 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
4356 struct drm_atomic_state *state;
4359 /* reset doesn't touch the display */
4360 if (!i915_modparams.force_reset_modeset_test &&
4361 !gpu_reset_clobbers_display(dev_priv))
4364 /* We have a modeset vs reset deadlock, defensively unbreak it. */
4365 set_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
4366 smp_mb__after_atomic();
4367 wake_up_bit(&dev_priv->gt.reset.flags, I915_RESET_MODESET);
4369 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
4370 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
4371 intel_gt_set_wedged(&dev_priv->gt);
4375 * Need mode_config.mutex so that we don't
4376 * trample ongoing ->detect() and whatnot.
4378 mutex_lock(&dev->mode_config.mutex);
4379 drm_modeset_acquire_init(ctx, 0);
4381 ret = drm_modeset_lock_all_ctx(dev, ctx);
4382 if (ret != -EDEADLK)
4385 drm_modeset_backoff(ctx);
4388 * Disabling the crtcs gracefully seems nicer. Also the
4389 * g33 docs say we should at least disable all the planes.
4391 state = drm_atomic_helper_duplicate_state(dev, ctx);
4392 if (IS_ERR(state)) {
4393 ret = PTR_ERR(state);
4394 DRM_ERROR("Duplicating state failed with %i\n", ret);
4398 ret = drm_atomic_helper_disable_all(dev, ctx);
4400 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
4401 drm_atomic_state_put(state);
4405 dev_priv->modeset_restore_state = state;
4406 state->acquire_ctx = ctx;
4409 void intel_finish_reset(struct drm_i915_private *dev_priv)
4411 struct drm_device *dev = &dev_priv->drm;
4412 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
4413 struct drm_atomic_state *state;
4416 /* reset doesn't touch the display */
4417 if (!test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
4420 state = fetch_and_zero(&dev_priv->modeset_restore_state);
4424 /* reset doesn't touch the display */
4425 if (!gpu_reset_clobbers_display(dev_priv)) {
4426 /* for testing only restore the display */
4427 ret = __intel_display_resume(dev, state, ctx);
4429 DRM_ERROR("Restoring old state failed with %i\n", ret);
4432 * The display has been reset as well,
4433 * so need a full re-initialization.
4435 intel_pps_unlock_regs_wa(dev_priv);
4436 intel_modeset_init_hw(dev_priv);
4437 intel_init_clock_gating(dev_priv);
4439 spin_lock_irq(&dev_priv->irq_lock);
4440 if (dev_priv->display.hpd_irq_setup)
4441 dev_priv->display.hpd_irq_setup(dev_priv);
4442 spin_unlock_irq(&dev_priv->irq_lock);
4444 ret = __intel_display_resume(dev, state, ctx);
4446 DRM_ERROR("Restoring old state failed with %i\n", ret);
4448 intel_hpd_init(dev_priv);
4451 drm_atomic_state_put(state);
4453 drm_modeset_drop_locks(ctx);
4454 drm_modeset_acquire_fini(ctx);
4455 mutex_unlock(&dev->mode_config.mutex);
4457 clear_bit_unlock(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
4460 static void icl_set_pipe_chicken(struct intel_crtc *crtc)
4462 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4463 enum pipe pipe = crtc->pipe;
4466 tmp = I915_READ(PIPE_CHICKEN(pipe));
4469 * Display WA #1153: icl
4470 * enable hardware to bypass the alpha math
4471 * and rounding for per-pixel values 00 and 0xff
4473 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
4475 * Display WA # 1605353570: icl
4476 * Set the pixel rounding bit to 1 for allowing
4477 * passthrough of Frame buffer pixels unmodified
4480 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
4481 I915_WRITE(PIPE_CHICKEN(pipe), tmp);
4484 static void icl_enable_trans_port_sync(const struct intel_crtc_state *crtc_state)
4486 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4487 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4488 u32 trans_ddi_func_ctl2_val;
4492 * Configure the master select and enable Transcoder Port Sync for
4493 * Slave CRTCs transcoder.
4495 if (crtc_state->master_transcoder == INVALID_TRANSCODER)
4498 if (crtc_state->master_transcoder == TRANSCODER_EDP)
4501 master_select = crtc_state->master_transcoder + 1;
4503 /* Set the master select bits for Tranascoder Port Sync */
4504 trans_ddi_func_ctl2_val = (PORT_SYNC_MODE_MASTER_SELECT(master_select) &
4505 PORT_SYNC_MODE_MASTER_SELECT_MASK) <<
4506 PORT_SYNC_MODE_MASTER_SELECT_SHIFT;
4507 /* Enable Transcoder Port Sync */
4508 trans_ddi_func_ctl2_val |= PORT_SYNC_MODE_ENABLE;
4510 I915_WRITE(TRANS_DDI_FUNC_CTL2(crtc_state->cpu_transcoder),
4511 trans_ddi_func_ctl2_val);
4514 static void icl_disable_transcoder_port_sync(const struct intel_crtc_state *old_crtc_state)
4516 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
4517 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4519 u32 trans_ddi_func_ctl2_val;
4521 if (old_crtc_state->master_transcoder == INVALID_TRANSCODER)
4524 DRM_DEBUG_KMS("Disabling Transcoder Port Sync on Slave Transcoder %s\n",
4525 transcoder_name(old_crtc_state->cpu_transcoder));
4527 reg = TRANS_DDI_FUNC_CTL2(old_crtc_state->cpu_transcoder);
4528 trans_ddi_func_ctl2_val = ~(PORT_SYNC_MODE_ENABLE |
4529 PORT_SYNC_MODE_MASTER_SELECT_MASK);
4530 I915_WRITE(reg, trans_ddi_func_ctl2_val);
4533 static void intel_fdi_normal_train(struct intel_crtc *crtc)
4535 struct drm_device *dev = crtc->base.dev;
4536 struct drm_i915_private *dev_priv = to_i915(dev);
4537 enum pipe pipe = crtc->pipe;
4541 /* enable normal train */
4542 reg = FDI_TX_CTL(pipe);
4543 temp = I915_READ(reg);
4544 if (IS_IVYBRIDGE(dev_priv)) {
4545 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4546 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
4548 temp &= ~FDI_LINK_TRAIN_NONE;
4549 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
4551 I915_WRITE(reg, temp);
4553 reg = FDI_RX_CTL(pipe);
4554 temp = I915_READ(reg);
4555 if (HAS_PCH_CPT(dev_priv)) {
4556 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4557 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
4559 temp &= ~FDI_LINK_TRAIN_NONE;
4560 temp |= FDI_LINK_TRAIN_NONE;
4562 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
4564 /* wait one idle pattern time */
4568 /* IVB wants error correction enabled */
4569 if (IS_IVYBRIDGE(dev_priv))
4570 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
4571 FDI_FE_ERRC_ENABLE);
4574 /* The FDI link training functions for ILK/Ibexpeak. */
4575 static void ironlake_fdi_link_train(struct intel_crtc *crtc,
4576 const struct intel_crtc_state *crtc_state)
4578 struct drm_device *dev = crtc->base.dev;
4579 struct drm_i915_private *dev_priv = to_i915(dev);
4580 enum pipe pipe = crtc->pipe;
4584 /* FDI needs bits from pipe first */
4585 assert_pipe_enabled(dev_priv, pipe);
4587 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4589 reg = FDI_RX_IMR(pipe);
4590 temp = I915_READ(reg);
4591 temp &= ~FDI_RX_SYMBOL_LOCK;
4592 temp &= ~FDI_RX_BIT_LOCK;
4593 I915_WRITE(reg, temp);
4597 /* enable CPU FDI TX and PCH FDI RX */
4598 reg = FDI_TX_CTL(pipe);
4599 temp = I915_READ(reg);
4600 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4601 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4602 temp &= ~FDI_LINK_TRAIN_NONE;
4603 temp |= FDI_LINK_TRAIN_PATTERN_1;
4604 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4606 reg = FDI_RX_CTL(pipe);
4607 temp = I915_READ(reg);
4608 temp &= ~FDI_LINK_TRAIN_NONE;
4609 temp |= FDI_LINK_TRAIN_PATTERN_1;
4610 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4615 /* Ironlake workaround, enable clock pointer after FDI enable*/
4616 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4617 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
4618 FDI_RX_PHASE_SYNC_POINTER_EN);
4620 reg = FDI_RX_IIR(pipe);
4621 for (tries = 0; tries < 5; tries++) {
4622 temp = I915_READ(reg);
4623 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4625 if ((temp & FDI_RX_BIT_LOCK)) {
4626 DRM_DEBUG_KMS("FDI train 1 done.\n");
4627 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4632 DRM_ERROR("FDI train 1 fail!\n");
4635 reg = FDI_TX_CTL(pipe);
4636 temp = I915_READ(reg);
4637 temp &= ~FDI_LINK_TRAIN_NONE;
4638 temp |= FDI_LINK_TRAIN_PATTERN_2;
4639 I915_WRITE(reg, temp);
4641 reg = FDI_RX_CTL(pipe);
4642 temp = I915_READ(reg);
4643 temp &= ~FDI_LINK_TRAIN_NONE;
4644 temp |= FDI_LINK_TRAIN_PATTERN_2;
4645 I915_WRITE(reg, temp);
4650 reg = FDI_RX_IIR(pipe);
4651 for (tries = 0; tries < 5; tries++) {
4652 temp = I915_READ(reg);
4653 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4655 if (temp & FDI_RX_SYMBOL_LOCK) {
4656 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4657 DRM_DEBUG_KMS("FDI train 2 done.\n");
4662 DRM_ERROR("FDI train 2 fail!\n");
4664 DRM_DEBUG_KMS("FDI train done\n");
4668 static const int snb_b_fdi_train_param[] = {
4669 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4670 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4671 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4672 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4675 /* The FDI link training functions for SNB/Cougarpoint. */
4676 static void gen6_fdi_link_train(struct intel_crtc *crtc,
4677 const struct intel_crtc_state *crtc_state)
4679 struct drm_device *dev = crtc->base.dev;
4680 struct drm_i915_private *dev_priv = to_i915(dev);
4681 enum pipe pipe = crtc->pipe;
4685 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4687 reg = FDI_RX_IMR(pipe);
4688 temp = I915_READ(reg);
4689 temp &= ~FDI_RX_SYMBOL_LOCK;
4690 temp &= ~FDI_RX_BIT_LOCK;
4691 I915_WRITE(reg, temp);
4696 /* enable CPU FDI TX and PCH FDI RX */
4697 reg = FDI_TX_CTL(pipe);
4698 temp = I915_READ(reg);
4699 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4700 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4701 temp &= ~FDI_LINK_TRAIN_NONE;
4702 temp |= FDI_LINK_TRAIN_PATTERN_1;
4703 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4705 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4706 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4708 I915_WRITE(FDI_RX_MISC(pipe),
4709 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4711 reg = FDI_RX_CTL(pipe);
4712 temp = I915_READ(reg);
4713 if (HAS_PCH_CPT(dev_priv)) {
4714 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4715 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4717 temp &= ~FDI_LINK_TRAIN_NONE;
4718 temp |= FDI_LINK_TRAIN_PATTERN_1;
4720 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4725 for (i = 0; i < 4; i++) {
4726 reg = FDI_TX_CTL(pipe);
4727 temp = I915_READ(reg);
4728 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4729 temp |= snb_b_fdi_train_param[i];
4730 I915_WRITE(reg, temp);
4735 for (retry = 0; retry < 5; retry++) {
4736 reg = FDI_RX_IIR(pipe);
4737 temp = I915_READ(reg);
4738 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4739 if (temp & FDI_RX_BIT_LOCK) {
4740 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4741 DRM_DEBUG_KMS("FDI train 1 done.\n");
4750 DRM_ERROR("FDI train 1 fail!\n");
4753 reg = FDI_TX_CTL(pipe);
4754 temp = I915_READ(reg);
4755 temp &= ~FDI_LINK_TRAIN_NONE;
4756 temp |= FDI_LINK_TRAIN_PATTERN_2;
4757 if (IS_GEN(dev_priv, 6)) {
4758 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4760 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4762 I915_WRITE(reg, temp);
4764 reg = FDI_RX_CTL(pipe);
4765 temp = I915_READ(reg);
4766 if (HAS_PCH_CPT(dev_priv)) {
4767 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4768 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4770 temp &= ~FDI_LINK_TRAIN_NONE;
4771 temp |= FDI_LINK_TRAIN_PATTERN_2;
4773 I915_WRITE(reg, temp);
4778 for (i = 0; i < 4; i++) {
4779 reg = FDI_TX_CTL(pipe);
4780 temp = I915_READ(reg);
4781 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4782 temp |= snb_b_fdi_train_param[i];
4783 I915_WRITE(reg, temp);
4788 for (retry = 0; retry < 5; retry++) {
4789 reg = FDI_RX_IIR(pipe);
4790 temp = I915_READ(reg);
4791 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4792 if (temp & FDI_RX_SYMBOL_LOCK) {
4793 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4794 DRM_DEBUG_KMS("FDI train 2 done.\n");
4803 DRM_ERROR("FDI train 2 fail!\n");
4805 DRM_DEBUG_KMS("FDI train done.\n");
4808 /* Manual link training for Ivy Bridge A0 parts */
4809 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4810 const struct intel_crtc_state *crtc_state)
4812 struct drm_device *dev = crtc->base.dev;
4813 struct drm_i915_private *dev_priv = to_i915(dev);
4814 enum pipe pipe = crtc->pipe;
4818 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4820 reg = FDI_RX_IMR(pipe);
4821 temp = I915_READ(reg);
4822 temp &= ~FDI_RX_SYMBOL_LOCK;
4823 temp &= ~FDI_RX_BIT_LOCK;
4824 I915_WRITE(reg, temp);
4829 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4830 I915_READ(FDI_RX_IIR(pipe)));
4832 /* Try each vswing and preemphasis setting twice before moving on */
4833 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4834 /* disable first in case we need to retry */
4835 reg = FDI_TX_CTL(pipe);
4836 temp = I915_READ(reg);
4837 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4838 temp &= ~FDI_TX_ENABLE;
4839 I915_WRITE(reg, temp);
4841 reg = FDI_RX_CTL(pipe);
4842 temp = I915_READ(reg);
4843 temp &= ~FDI_LINK_TRAIN_AUTO;
4844 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4845 temp &= ~FDI_RX_ENABLE;
4846 I915_WRITE(reg, temp);
4848 /* enable CPU FDI TX and PCH FDI RX */
4849 reg = FDI_TX_CTL(pipe);
4850 temp = I915_READ(reg);
4851 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4852 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4853 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
4854 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4855 temp |= snb_b_fdi_train_param[j/2];
4856 temp |= FDI_COMPOSITE_SYNC;
4857 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4859 I915_WRITE(FDI_RX_MISC(pipe),
4860 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4862 reg = FDI_RX_CTL(pipe);
4863 temp = I915_READ(reg);
4864 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4865 temp |= FDI_COMPOSITE_SYNC;
4866 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4869 udelay(1); /* should be 0.5us */
4871 for (i = 0; i < 4; i++) {
4872 reg = FDI_RX_IIR(pipe);
4873 temp = I915_READ(reg);
4874 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4876 if (temp & FDI_RX_BIT_LOCK ||
4877 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4878 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4879 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4883 udelay(1); /* should be 0.5us */
4886 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4891 reg = FDI_TX_CTL(pipe);
4892 temp = I915_READ(reg);
4893 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4894 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4895 I915_WRITE(reg, temp);
4897 reg = FDI_RX_CTL(pipe);
4898 temp = I915_READ(reg);
4899 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4900 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4901 I915_WRITE(reg, temp);
4904 udelay(2); /* should be 1.5us */
4906 for (i = 0; i < 4; i++) {
4907 reg = FDI_RX_IIR(pipe);
4908 temp = I915_READ(reg);
4909 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4911 if (temp & FDI_RX_SYMBOL_LOCK ||
4912 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4913 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4914 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4918 udelay(2); /* should be 1.5us */
4921 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
4925 DRM_DEBUG_KMS("FDI train done.\n");
4928 static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
4930 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4931 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4932 enum pipe pipe = intel_crtc->pipe;
4936 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4937 reg = FDI_RX_CTL(pipe);
4938 temp = I915_READ(reg);
4939 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
4940 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4941 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4942 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4947 /* Switch from Rawclk to PCDclk */
4948 temp = I915_READ(reg);
4949 I915_WRITE(reg, temp | FDI_PCDCLK);
4954 /* Enable CPU FDI TX PLL, always on for Ironlake */
4955 reg = FDI_TX_CTL(pipe);
4956 temp = I915_READ(reg);
4957 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4958 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
4965 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4967 struct drm_device *dev = intel_crtc->base.dev;
4968 struct drm_i915_private *dev_priv = to_i915(dev);
4969 enum pipe pipe = intel_crtc->pipe;
4973 /* Switch from PCDclk to Rawclk */
4974 reg = FDI_RX_CTL(pipe);
4975 temp = I915_READ(reg);
4976 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4978 /* Disable CPU FDI TX PLL */
4979 reg = FDI_TX_CTL(pipe);
4980 temp = I915_READ(reg);
4981 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4986 reg = FDI_RX_CTL(pipe);
4987 temp = I915_READ(reg);
4988 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4990 /* Wait for the clocks to turn off. */
4995 static void ironlake_fdi_disable(struct drm_crtc *crtc)
4997 struct drm_device *dev = crtc->dev;
4998 struct drm_i915_private *dev_priv = to_i915(dev);
4999 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5000 enum pipe pipe = intel_crtc->pipe;
5004 /* disable CPU FDI tx and PCH FDI rx */
5005 reg = FDI_TX_CTL(pipe);
5006 temp = I915_READ(reg);
5007 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
5010 reg = FDI_RX_CTL(pipe);
5011 temp = I915_READ(reg);
5012 temp &= ~(0x7 << 16);
5013 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
5014 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
5019 /* Ironlake workaround, disable clock pointer after downing FDI */
5020 if (HAS_PCH_IBX(dev_priv))
5021 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
5023 /* still set train pattern 1 */
5024 reg = FDI_TX_CTL(pipe);
5025 temp = I915_READ(reg);
5026 temp &= ~FDI_LINK_TRAIN_NONE;
5027 temp |= FDI_LINK_TRAIN_PATTERN_1;
5028 I915_WRITE(reg, temp);
5030 reg = FDI_RX_CTL(pipe);
5031 temp = I915_READ(reg);
5032 if (HAS_PCH_CPT(dev_priv)) {
5033 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5034 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
5036 temp &= ~FDI_LINK_TRAIN_NONE;
5037 temp |= FDI_LINK_TRAIN_PATTERN_1;
5039 /* BPC in FDI rx is consistent with that in PIPECONF */
5040 temp &= ~(0x07 << 16);
5041 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
5042 I915_WRITE(reg, temp);
5048 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
5050 struct drm_crtc *crtc;
5053 drm_for_each_crtc(crtc, &dev_priv->drm) {
5054 struct drm_crtc_commit *commit;
5055 spin_lock(&crtc->commit_lock);
5056 commit = list_first_entry_or_null(&crtc->commit_list,
5057 struct drm_crtc_commit, commit_entry);
5058 cleanup_done = commit ?
5059 try_wait_for_completion(&commit->cleanup_done) : true;
5060 spin_unlock(&crtc->commit_lock);
5065 drm_crtc_wait_one_vblank(crtc);
5073 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
5077 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
5079 mutex_lock(&dev_priv->sb_lock);
5081 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5082 temp |= SBI_SSCCTL_DISABLE;
5083 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
5085 mutex_unlock(&dev_priv->sb_lock);
5088 /* Program iCLKIP clock to the desired frequency */
5089 static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
5091 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5092 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5093 int clock = crtc_state->base.adjusted_mode.crtc_clock;
5094 u32 divsel, phaseinc, auxdiv, phasedir = 0;
5097 lpt_disable_iclkip(dev_priv);
5099 /* The iCLK virtual clock root frequency is in MHz,
5100 * but the adjusted_mode->crtc_clock in in KHz. To get the
5101 * divisors, it is necessary to divide one by another, so we
5102 * convert the virtual clock precision to KHz here for higher
5105 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
5106 u32 iclk_virtual_root_freq = 172800 * 1000;
5107 u32 iclk_pi_range = 64;
5108 u32 desired_divisor;
5110 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5112 divsel = (desired_divisor / iclk_pi_range) - 2;
5113 phaseinc = desired_divisor % iclk_pi_range;
5116 * Near 20MHz is a corner case which is
5117 * out of range for the 7-bit divisor
5123 /* This should not happen with any sane values */
5124 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
5125 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
5126 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
5127 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
5129 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
5136 mutex_lock(&dev_priv->sb_lock);
5138 /* Program SSCDIVINTPHASE6 */
5139 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5140 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
5141 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
5142 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
5143 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
5144 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
5145 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
5146 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
5148 /* Program SSCAUXDIV */
5149 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5150 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
5151 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
5152 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
5154 /* Enable modulator and associated divider */
5155 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5156 temp &= ~SBI_SSCCTL_DISABLE;
5157 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
5159 mutex_unlock(&dev_priv->sb_lock);
5161 /* Wait for initialization time */
5164 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
5167 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
5169 u32 divsel, phaseinc, auxdiv;
5170 u32 iclk_virtual_root_freq = 172800 * 1000;
5171 u32 iclk_pi_range = 64;
5172 u32 desired_divisor;
5175 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
5178 mutex_lock(&dev_priv->sb_lock);
5180 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5181 if (temp & SBI_SSCCTL_DISABLE) {
5182 mutex_unlock(&dev_priv->sb_lock);
5186 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5187 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
5188 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
5189 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
5190 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
5192 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5193 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
5194 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
5196 mutex_unlock(&dev_priv->sb_lock);
5198 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
5200 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5201 desired_divisor << auxdiv);
5204 static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
5205 enum pipe pch_transcoder)
5207 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5208 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5209 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5211 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
5212 I915_READ(HTOTAL(cpu_transcoder)));
5213 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
5214 I915_READ(HBLANK(cpu_transcoder)));
5215 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
5216 I915_READ(HSYNC(cpu_transcoder)));
5218 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
5219 I915_READ(VTOTAL(cpu_transcoder)));
5220 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
5221 I915_READ(VBLANK(cpu_transcoder)));
5222 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
5223 I915_READ(VSYNC(cpu_transcoder)));
5224 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
5225 I915_READ(VSYNCSHIFT(cpu_transcoder)));
5228 static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
5232 temp = I915_READ(SOUTH_CHICKEN1);
5233 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
5236 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
5237 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
5239 temp &= ~FDI_BC_BIFURCATION_SELECT;
5241 temp |= FDI_BC_BIFURCATION_SELECT;
5243 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
5244 I915_WRITE(SOUTH_CHICKEN1, temp);
5245 POSTING_READ(SOUTH_CHICKEN1);
5248 static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
5250 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5251 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5253 switch (crtc->pipe) {
5257 if (crtc_state->fdi_lanes > 2)
5258 cpt_set_fdi_bc_bifurcation(dev_priv, false);
5260 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5264 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5273 * Finds the encoder associated with the given CRTC. This can only be
5274 * used when we know that the CRTC isn't feeding multiple encoders!
5276 static struct intel_encoder *
5277 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
5278 const struct intel_crtc_state *crtc_state)
5280 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5281 const struct drm_connector_state *connector_state;
5282 const struct drm_connector *connector;
5283 struct intel_encoder *encoder = NULL;
5284 int num_encoders = 0;
5287 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
5288 if (connector_state->crtc != &crtc->base)
5291 encoder = to_intel_encoder(connector_state->best_encoder);
5295 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
5296 num_encoders, pipe_name(crtc->pipe));
5302 * Enable PCH resources required for PCH ports:
5304 * - FDI training & RX/TX
5305 * - update transcoder timings
5306 * - DP transcoding bits
5309 static void ironlake_pch_enable(const struct intel_atomic_state *state,
5310 const struct intel_crtc_state *crtc_state)
5312 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5313 struct drm_device *dev = crtc->base.dev;
5314 struct drm_i915_private *dev_priv = to_i915(dev);
5315 enum pipe pipe = crtc->pipe;
5318 assert_pch_transcoder_disabled(dev_priv, pipe);
5320 if (IS_IVYBRIDGE(dev_priv))
5321 ivybridge_update_fdi_bc_bifurcation(crtc_state);
5323 /* Write the TU size bits before fdi link training, so that error
5324 * detection works. */
5325 I915_WRITE(FDI_RX_TUSIZE1(pipe),
5326 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
5328 /* For PCH output, training FDI link */
5329 dev_priv->display.fdi_link_train(crtc, crtc_state);
5331 /* We need to program the right clock selection before writing the pixel
5332 * mutliplier into the DPLL. */
5333 if (HAS_PCH_CPT(dev_priv)) {
5336 temp = I915_READ(PCH_DPLL_SEL);
5337 temp |= TRANS_DPLL_ENABLE(pipe);
5338 sel = TRANS_DPLLB_SEL(pipe);
5339 if (crtc_state->shared_dpll ==
5340 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
5344 I915_WRITE(PCH_DPLL_SEL, temp);
5347 /* XXX: pch pll's can be enabled any time before we enable the PCH
5348 * transcoder, and we actually should do this to not upset any PCH
5349 * transcoder that already use the clock when we share it.
5351 * Note that enable_shared_dpll tries to do the right thing, but
5352 * get_shared_dpll unconditionally resets the pll - we need that to have
5353 * the right LVDS enable sequence. */
5354 intel_enable_shared_dpll(crtc_state);
5356 /* set transcoder timing, panel must allow it */
5357 assert_panel_unlocked(dev_priv, pipe);
5358 ironlake_pch_transcoder_set_timings(crtc_state, pipe);
5360 intel_fdi_normal_train(crtc);
5362 /* For PCH DP, enable TRANS_DP_CTL */
5363 if (HAS_PCH_CPT(dev_priv) &&
5364 intel_crtc_has_dp_encoder(crtc_state)) {
5365 const struct drm_display_mode *adjusted_mode =
5366 &crtc_state->base.adjusted_mode;
5367 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
5368 i915_reg_t reg = TRANS_DP_CTL(pipe);
5371 temp = I915_READ(reg);
5372 temp &= ~(TRANS_DP_PORT_SEL_MASK |
5373 TRANS_DP_SYNC_MASK |
5375 temp |= TRANS_DP_OUTPUT_ENABLE;
5376 temp |= bpc << 9; /* same format but at 11:9 */
5378 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
5379 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
5380 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
5381 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
5383 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
5384 WARN_ON(port < PORT_B || port > PORT_D);
5385 temp |= TRANS_DP_PORT_SEL(port);
5387 I915_WRITE(reg, temp);
5390 ironlake_enable_pch_transcoder(crtc_state);
5393 static void lpt_pch_enable(const struct intel_atomic_state *state,
5394 const struct intel_crtc_state *crtc_state)
5396 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5397 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5398 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5400 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
5402 lpt_program_iclkip(crtc_state);
5404 /* Set transcoder timing. */
5405 ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A);
5407 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
5410 static void cpt_verify_modeset(struct drm_device *dev, enum pipe pipe)
5412 struct drm_i915_private *dev_priv = to_i915(dev);
5413 i915_reg_t dslreg = PIPEDSL(pipe);
5416 temp = I915_READ(dslreg);
5418 if (wait_for(I915_READ(dslreg) != temp, 5)) {
5419 if (wait_for(I915_READ(dslreg) != temp, 5))
5420 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
5425 * The hardware phase 0.0 refers to the center of the pixel.
5426 * We want to start from the top/left edge which is phase
5427 * -0.5. That matches how the hardware calculates the scaling
5428 * factors (from top-left of the first pixel to bottom-right
5429 * of the last pixel, as opposed to the pixel centers).
5431 * For 4:2:0 subsampled chroma planes we obviously have to
5432 * adjust that so that the chroma sample position lands in
5435 * Note that for packed YCbCr 4:2:2 formats there is no way to
5436 * control chroma siting. The hardware simply replicates the
5437 * chroma samples for both of the luma samples, and thus we don't
5438 * actually get the expected MPEG2 chroma siting convention :(
5439 * The same behaviour is observed on pre-SKL platforms as well.
5441 * Theory behind the formula (note that we ignore sub-pixel
5442 * source coordinates):
5443 * s = source sample position
5444 * d = destination sample position
5449 * | | 1.5 (initial phase)
5457 * | -0.375 (initial phase)
5464 u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
5466 int phase = -0x8000;
5470 phase += (sub - 1) * 0x8000 / sub;
5472 phase += scale / (2 * sub);
5475 * Hardware initial phase limited to [-0.5:1.5].
5476 * Since the max hardware scale factor is 3.0, we
5477 * should never actually excdeed 1.0 here.
5479 WARN_ON(phase < -0x8000 || phase > 0x18000);
5482 phase = 0x10000 + phase;
5484 trip = PS_PHASE_TRIP;
5486 return ((phase >> 2) & PS_PHASE_MASK) | trip;
5489 #define SKL_MIN_SRC_W 8
5490 #define SKL_MAX_SRC_W 4096
5491 #define SKL_MIN_SRC_H 8
5492 #define SKL_MAX_SRC_H 4096
5493 #define SKL_MIN_DST_W 8
5494 #define SKL_MAX_DST_W 4096
5495 #define SKL_MIN_DST_H 8
5496 #define SKL_MAX_DST_H 4096
5497 #define ICL_MAX_SRC_W 5120
5498 #define ICL_MAX_SRC_H 4096
5499 #define ICL_MAX_DST_W 5120
5500 #define ICL_MAX_DST_H 4096
5501 #define SKL_MIN_YUV_420_SRC_W 16
5502 #define SKL_MIN_YUV_420_SRC_H 16
5505 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
5506 unsigned int scaler_user, int *scaler_id,
5507 int src_w, int src_h, int dst_w, int dst_h,
5508 const struct drm_format_info *format, bool need_scaler)
5510 struct intel_crtc_scaler_state *scaler_state =
5511 &crtc_state->scaler_state;
5512 struct intel_crtc *intel_crtc =
5513 to_intel_crtc(crtc_state->base.crtc);
5514 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
5515 const struct drm_display_mode *adjusted_mode =
5516 &crtc_state->base.adjusted_mode;
5519 * Src coordinates are already rotated by 270 degrees for
5520 * the 90/270 degree plane rotation cases (to match the
5521 * GTT mapping), hence no need to account for rotation here.
5523 if (src_w != dst_w || src_h != dst_h)
5527 * Scaling/fitting not supported in IF-ID mode in GEN9+
5528 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
5529 * Once NV12 is enabled, handle it here while allocating scaler
5532 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
5533 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
5534 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
5539 * if plane is being disabled or scaler is no more required or force detach
5540 * - free scaler binded to this plane/crtc
5541 * - in order to do this, update crtc->scaler_usage
5543 * Here scaler state in crtc_state is set free so that
5544 * scaler can be assigned to other user. Actual register
5545 * update to free the scaler is done in plane/panel-fit programming.
5546 * For this purpose crtc/plane_state->scaler_id isn't reset here.
5548 if (force_detach || !need_scaler) {
5549 if (*scaler_id >= 0) {
5550 scaler_state->scaler_users &= ~(1 << scaler_user);
5551 scaler_state->scalers[*scaler_id].in_use = 0;
5553 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5554 "Staged freeing scaler id %d scaler_users = 0x%x\n",
5555 intel_crtc->pipe, scaler_user, *scaler_id,
5556 scaler_state->scaler_users);
5562 if (format && drm_format_info_is_yuv_semiplanar(format) &&
5563 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
5564 DRM_DEBUG_KMS("Planar YUV: src dimensions not met\n");
5569 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
5570 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
5571 (INTEL_GEN(dev_priv) >= 11 &&
5572 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
5573 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
5574 (INTEL_GEN(dev_priv) < 11 &&
5575 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
5576 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
5577 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
5578 "size is out of scaler range\n",
5579 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
5583 /* mark this plane as a scaler user in crtc_state */
5584 scaler_state->scaler_users |= (1 << scaler_user);
5585 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5586 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
5587 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
5588 scaler_state->scaler_users);
5594 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
5596 * @state: crtc's scaler state
5599 * 0 - scaler_usage updated successfully
5600 * error - requested scaling cannot be supported or other error condition
5602 int skl_update_scaler_crtc(struct intel_crtc_state *state)
5604 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
5605 bool need_scaler = false;
5607 if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
5610 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
5611 &state->scaler_state.scaler_id,
5612 state->pipe_src_w, state->pipe_src_h,
5613 adjusted_mode->crtc_hdisplay,
5614 adjusted_mode->crtc_vdisplay, NULL, need_scaler);
5618 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
5619 * @crtc_state: crtc's scaler state
5620 * @plane_state: atomic plane state to update
5623 * 0 - scaler_usage updated successfully
5624 * error - requested scaling cannot be supported or other error condition
5626 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
5627 struct intel_plane_state *plane_state)
5629 struct intel_plane *intel_plane =
5630 to_intel_plane(plane_state->base.plane);
5631 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
5632 struct drm_framebuffer *fb = plane_state->base.fb;
5634 bool force_detach = !fb || !plane_state->base.visible;
5635 bool need_scaler = false;
5637 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
5638 if (!icl_is_hdr_plane(dev_priv, intel_plane->id) &&
5639 fb && drm_format_info_is_yuv_semiplanar(fb->format))
5642 ret = skl_update_scaler(crtc_state, force_detach,
5643 drm_plane_index(&intel_plane->base),
5644 &plane_state->scaler_id,
5645 drm_rect_width(&plane_state->base.src) >> 16,
5646 drm_rect_height(&plane_state->base.src) >> 16,
5647 drm_rect_width(&plane_state->base.dst),
5648 drm_rect_height(&plane_state->base.dst),
5649 fb ? fb->format : NULL, need_scaler);
5651 if (ret || plane_state->scaler_id < 0)
5654 /* check colorkey */
5655 if (plane_state->ckey.flags) {
5656 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
5657 intel_plane->base.base.id,
5658 intel_plane->base.name);
5662 /* Check src format */
5663 switch (fb->format->format) {
5664 case DRM_FORMAT_RGB565:
5665 case DRM_FORMAT_XBGR8888:
5666 case DRM_FORMAT_XRGB8888:
5667 case DRM_FORMAT_ABGR8888:
5668 case DRM_FORMAT_ARGB8888:
5669 case DRM_FORMAT_XRGB2101010:
5670 case DRM_FORMAT_XBGR2101010:
5671 case DRM_FORMAT_YUYV:
5672 case DRM_FORMAT_YVYU:
5673 case DRM_FORMAT_UYVY:
5674 case DRM_FORMAT_VYUY:
5675 case DRM_FORMAT_NV12:
5676 case DRM_FORMAT_P010:
5677 case DRM_FORMAT_P012:
5678 case DRM_FORMAT_P016:
5679 case DRM_FORMAT_Y210:
5680 case DRM_FORMAT_Y212:
5681 case DRM_FORMAT_Y216:
5682 case DRM_FORMAT_XVYU2101010:
5683 case DRM_FORMAT_XVYU12_16161616:
5684 case DRM_FORMAT_XVYU16161616:
5686 case DRM_FORMAT_XBGR16161616F:
5687 case DRM_FORMAT_ABGR16161616F:
5688 case DRM_FORMAT_XRGB16161616F:
5689 case DRM_FORMAT_ARGB16161616F:
5690 if (INTEL_GEN(dev_priv) >= 11)
5694 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
5695 intel_plane->base.base.id, intel_plane->base.name,
5696 fb->base.id, fb->format->format);
5703 static void skylake_scaler_disable(struct intel_crtc *crtc)
5707 for (i = 0; i < crtc->num_scalers; i++)
5708 skl_detach_scaler(crtc, i);
5711 static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
5713 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5714 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5715 enum pipe pipe = crtc->pipe;
5716 const struct intel_crtc_scaler_state *scaler_state =
5717 &crtc_state->scaler_state;
5719 if (crtc_state->pch_pfit.enabled) {
5720 u16 uv_rgb_hphase, uv_rgb_vphase;
5721 int pfit_w, pfit_h, hscale, vscale;
5724 if (WARN_ON(crtc_state->scaler_state.scaler_id < 0))
5727 pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF;
5728 pfit_h = crtc_state->pch_pfit.size & 0xFFFF;
5730 hscale = (crtc_state->pipe_src_w << 16) / pfit_w;
5731 vscale = (crtc_state->pipe_src_h << 16) / pfit_h;
5733 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
5734 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
5736 id = scaler_state->scaler_id;
5737 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
5738 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
5739 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
5740 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5741 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
5742 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
5743 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos);
5744 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size);
5748 static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state)
5750 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5751 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5752 enum pipe pipe = crtc->pipe;
5754 if (crtc_state->pch_pfit.enabled) {
5755 /* Force use of hard-coded filter coefficients
5756 * as some pre-programmed values are broken,
5759 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
5760 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5761 PF_PIPE_SEL_IVB(pipe));
5763 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
5764 I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos);
5765 I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size);
5769 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
5771 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5772 struct drm_device *dev = crtc->base.dev;
5773 struct drm_i915_private *dev_priv = to_i915(dev);
5775 if (!crtc_state->ips_enabled)
5779 * We can only enable IPS after we enable a plane and wait for a vblank
5780 * This function is called from post_plane_update, which is run after
5783 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
5785 if (IS_BROADWELL(dev_priv)) {
5786 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5787 IPS_ENABLE | IPS_PCODE_CONTROL));
5788 /* Quoting Art Runyan: "its not safe to expect any particular
5789 * value in IPS_CTL bit 31 after enabling IPS through the
5790 * mailbox." Moreover, the mailbox may return a bogus state,
5791 * so we need to just enable it and continue on.
5794 I915_WRITE(IPS_CTL, IPS_ENABLE);
5795 /* The bit only becomes 1 in the next vblank, so this wait here
5796 * is essentially intel_wait_for_vblank. If we don't have this
5797 * and don't wait for vblanks until the end of crtc_enable, then
5798 * the HW state readout code will complain that the expected
5799 * IPS_CTL value is not the one we read. */
5800 if (intel_de_wait_for_set(dev_priv, IPS_CTL, IPS_ENABLE, 50))
5801 DRM_ERROR("Timed out waiting for IPS enable\n");
5805 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
5807 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5808 struct drm_device *dev = crtc->base.dev;
5809 struct drm_i915_private *dev_priv = to_i915(dev);
5811 if (!crtc_state->ips_enabled)
5814 if (IS_BROADWELL(dev_priv)) {
5815 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
5817 * Wait for PCODE to finish disabling IPS. The BSpec specified
5818 * 42ms timeout value leads to occasional timeouts so use 100ms
5821 if (intel_de_wait_for_clear(dev_priv, IPS_CTL, IPS_ENABLE, 100))
5822 DRM_ERROR("Timed out waiting for IPS disable\n");
5824 I915_WRITE(IPS_CTL, 0);
5825 POSTING_READ(IPS_CTL);
5828 /* We need to wait for a vblank before we can disable the plane. */
5829 intel_wait_for_vblank(dev_priv, crtc->pipe);
5832 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
5834 if (intel_crtc->overlay)
5835 (void) intel_overlay_switch_off(intel_crtc->overlay);
5837 /* Let userspace switch the overlay on again. In most cases userspace
5838 * has to recompute where to put it anyway.
5843 * intel_post_enable_primary - Perform operations after enabling primary plane
5844 * @crtc: the CRTC whose primary plane was just enabled
5845 * @new_crtc_state: the enabling state
5847 * Performs potentially sleeping operations that must be done after the primary
5848 * plane is enabled, such as updating FBC and IPS. Note that this may be
5849 * called due to an explicit primary plane update, or due to an implicit
5850 * re-enable that is caused when a sprite plane is updated to no longer
5851 * completely hide the primary plane.
5854 intel_post_enable_primary(struct drm_crtc *crtc,
5855 const struct intel_crtc_state *new_crtc_state)
5857 struct drm_device *dev = crtc->dev;
5858 struct drm_i915_private *dev_priv = to_i915(dev);
5859 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5860 enum pipe pipe = intel_crtc->pipe;
5863 * Gen2 reports pipe underruns whenever all planes are disabled.
5864 * So don't enable underrun reporting before at least some planes
5866 * FIXME: Need to fix the logic to work when we turn off all planes
5867 * but leave the pipe running.
5869 if (IS_GEN(dev_priv, 2))
5870 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5872 /* Underruns don't always raise interrupts, so check manually. */
5873 intel_check_cpu_fifo_underruns(dev_priv);
5874 intel_check_pch_fifo_underruns(dev_priv);
5877 /* FIXME get rid of this and use pre_plane_update */
5879 intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5881 struct drm_device *dev = crtc->dev;
5882 struct drm_i915_private *dev_priv = to_i915(dev);
5883 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5884 enum pipe pipe = intel_crtc->pipe;
5887 * Gen2 reports pipe underruns whenever all planes are disabled.
5888 * So disable underrun reporting before all the planes get disabled.
5890 if (IS_GEN(dev_priv, 2))
5891 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5893 hsw_disable_ips(to_intel_crtc_state(crtc->state));
5896 * Vblank time updates from the shadow to live plane control register
5897 * are blocked if the memory self-refresh mode is active at that
5898 * moment. So to make sure the plane gets truly disabled, disable
5899 * first the self-refresh mode. The self-refresh enable bit in turn
5900 * will be checked/applied by the HW only at the next frame start
5901 * event which is after the vblank start event, so we need to have a
5902 * wait-for-vblank between disabling the plane and the pipe.
5904 if (HAS_GMCH(dev_priv) &&
5905 intel_set_memory_cxsr(dev_priv, false))
5906 intel_wait_for_vblank(dev_priv, pipe);
5909 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5910 const struct intel_crtc_state *new_crtc_state)
5912 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
5913 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5915 if (!old_crtc_state->ips_enabled)
5918 if (needs_modeset(new_crtc_state))
5922 * Workaround : Do not read or write the pipe palette/gamma data while
5923 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
5925 * Disable IPS before we program the LUT.
5927 if (IS_HASWELL(dev_priv) &&
5928 (new_crtc_state->base.color_mgmt_changed ||
5929 new_crtc_state->update_pipe) &&
5930 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
5933 return !new_crtc_state->ips_enabled;
5936 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5937 const struct intel_crtc_state *new_crtc_state)
5939 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
5940 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5942 if (!new_crtc_state->ips_enabled)
5945 if (needs_modeset(new_crtc_state))
5949 * Workaround : Do not read or write the pipe palette/gamma data while
5950 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
5952 * Re-enable IPS after the LUT has been programmed.
5954 if (IS_HASWELL(dev_priv) &&
5955 (new_crtc_state->base.color_mgmt_changed ||
5956 new_crtc_state->update_pipe) &&
5957 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
5961 * We can't read out IPS on broadwell, assume the worst and
5962 * forcibly enable IPS on the first fastset.
5964 if (new_crtc_state->update_pipe &&
5965 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5968 return !old_crtc_state->ips_enabled;
5971 static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5972 const struct intel_crtc_state *crtc_state)
5974 if (!crtc_state->nv12_planes)
5977 /* WA Display #0827: Gen9:all */
5978 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv))
5984 static bool needs_scalerclk_wa(struct drm_i915_private *dev_priv,
5985 const struct intel_crtc_state *crtc_state)
5987 /* Wa_2006604312:icl */
5988 if (crtc_state->scaler_state.scaler_users > 0 && IS_ICELAKE(dev_priv))
5994 static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5996 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5997 struct drm_device *dev = crtc->base.dev;
5998 struct drm_i915_private *dev_priv = to_i915(dev);
5999 struct drm_atomic_state *state = old_crtc_state->base.state;
6000 struct intel_crtc_state *pipe_config =
6001 intel_atomic_get_new_crtc_state(to_intel_atomic_state(state),
6003 struct drm_plane *primary = crtc->base.primary;
6004 struct drm_plane_state *old_primary_state =
6005 drm_atomic_get_old_plane_state(state, primary);
6007 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
6009 if (pipe_config->update_wm_post && pipe_config->base.active)
6010 intel_update_watermarks(crtc);
6012 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
6013 hsw_enable_ips(pipe_config);
6015 if (old_primary_state) {
6016 struct drm_plane_state *new_primary_state =
6017 drm_atomic_get_new_plane_state(state, primary);
6019 intel_fbc_post_update(crtc);
6021 if (new_primary_state->visible &&
6022 (needs_modeset(pipe_config) ||
6023 !old_primary_state->visible))
6024 intel_post_enable_primary(&crtc->base, pipe_config);
6027 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
6028 !needs_nv12_wa(dev_priv, pipe_config))
6029 skl_wa_827(dev_priv, crtc->pipe, false);
6031 if (needs_scalerclk_wa(dev_priv, old_crtc_state) &&
6032 !needs_scalerclk_wa(dev_priv, pipe_config))
6033 icl_wa_scalerclkgating(dev_priv, crtc->pipe, false);
6036 static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
6037 struct intel_crtc_state *pipe_config)
6039 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6040 struct drm_device *dev = crtc->base.dev;
6041 struct drm_i915_private *dev_priv = to_i915(dev);
6042 struct drm_atomic_state *state = old_crtc_state->base.state;
6043 struct drm_plane *primary = crtc->base.primary;
6044 struct drm_plane_state *old_primary_state =
6045 drm_atomic_get_old_plane_state(state, primary);
6046 bool modeset = needs_modeset(pipe_config);
6047 struct intel_atomic_state *intel_state =
6048 to_intel_atomic_state(state);
6050 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
6051 hsw_disable_ips(old_crtc_state);
6053 if (old_primary_state) {
6054 struct intel_plane_state *new_primary_state =
6055 intel_atomic_get_new_plane_state(intel_state,
6056 to_intel_plane(primary));
6058 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
6060 * Gen2 reports pipe underruns whenever all planes are disabled.
6061 * So disable underrun reporting before all the planes get disabled.
6063 if (IS_GEN(dev_priv, 2) && old_primary_state->visible &&
6064 (modeset || !new_primary_state->base.visible))
6065 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
6068 /* Display WA 827 */
6069 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
6070 needs_nv12_wa(dev_priv, pipe_config))
6071 skl_wa_827(dev_priv, crtc->pipe, true);
6073 /* Wa_2006604312:icl */
6074 if (!needs_scalerclk_wa(dev_priv, old_crtc_state) &&
6075 needs_scalerclk_wa(dev_priv, pipe_config))
6076 icl_wa_scalerclkgating(dev_priv, crtc->pipe, true);
6079 * Vblank time updates from the shadow to live plane control register
6080 * are blocked if the memory self-refresh mode is active at that
6081 * moment. So to make sure the plane gets truly disabled, disable
6082 * first the self-refresh mode. The self-refresh enable bit in turn
6083 * will be checked/applied by the HW only at the next frame start
6084 * event which is after the vblank start event, so we need to have a
6085 * wait-for-vblank between disabling the plane and the pipe.
6087 if (HAS_GMCH(dev_priv) && old_crtc_state->base.active &&
6088 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
6089 intel_wait_for_vblank(dev_priv, crtc->pipe);
6092 * IVB workaround: must disable low power watermarks for at least
6093 * one frame before enabling scaling. LP watermarks can be re-enabled
6094 * when scaling is disabled.
6096 * WaCxSRDisabledForSpriteScaling:ivb
6098 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) &&
6099 old_crtc_state->base.active)
6100 intel_wait_for_vblank(dev_priv, crtc->pipe);
6103 * If we're doing a modeset, we're done. No need to do any pre-vblank
6104 * watermark programming here.
6106 if (needs_modeset(pipe_config))
6110 * For platforms that support atomic watermarks, program the
6111 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
6112 * will be the intermediate values that are safe for both pre- and
6113 * post- vblank; when vblank happens, the 'active' values will be set
6114 * to the final 'target' values and we'll do this again to get the
6115 * optimal watermarks. For gen9+ platforms, the values we program here
6116 * will be the final target values which will get automatically latched
6117 * at vblank time; no further programming will be necessary.
6119 * If a platform hasn't been transitioned to atomic watermarks yet,
6120 * we'll continue to update watermarks the old way, if flags tell
6123 if (dev_priv->display.initial_watermarks != NULL)
6124 dev_priv->display.initial_watermarks(intel_state,
6126 else if (pipe_config->update_wm_pre)
6127 intel_update_watermarks(crtc);
6130 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
6131 struct intel_crtc *crtc)
6133 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6134 const struct intel_crtc_state *new_crtc_state =
6135 intel_atomic_get_new_crtc_state(state, crtc);
6136 unsigned int update_mask = new_crtc_state->update_planes;
6137 const struct intel_plane_state *old_plane_state;
6138 struct intel_plane *plane;
6139 unsigned fb_bits = 0;
6142 intel_crtc_dpms_overlay_disable(crtc);
6144 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
6145 if (crtc->pipe != plane->pipe ||
6146 !(update_mask & BIT(plane->id)))
6149 intel_disable_plane(plane, new_crtc_state);
6151 if (old_plane_state->base.visible)
6152 fb_bits |= plane->frontbuffer_bit;
6155 intel_frontbuffer_flip(dev_priv, fb_bits);
6159 * intel_connector_primary_encoder - get the primary encoder for a connector
6160 * @connector: connector for which to return the encoder
6162 * Returns the primary encoder for a connector. There is a 1:1 mapping from
6163 * all connectors to their encoder, except for DP-MST connectors which have
6164 * both a virtual and a primary encoder. These DP-MST primary encoders can be
6165 * pointed to by as many DP-MST connectors as there are pipes.
6167 static struct intel_encoder *
6168 intel_connector_primary_encoder(struct intel_connector *connector)
6170 struct intel_encoder *encoder;
6172 if (connector->mst_port)
6173 return &dp_to_dig_port(connector->mst_port)->base;
6175 encoder = intel_attached_encoder(&connector->base);
6182 intel_connector_needs_modeset(struct intel_atomic_state *state,
6183 const struct drm_connector_state *old_conn_state,
6184 const struct drm_connector_state *new_conn_state)
6186 struct intel_crtc *old_crtc = old_conn_state->crtc ?
6187 to_intel_crtc(old_conn_state->crtc) : NULL;
6188 struct intel_crtc *new_crtc = new_conn_state->crtc ?
6189 to_intel_crtc(new_conn_state->crtc) : NULL;
6191 return new_crtc != old_crtc ||
6193 needs_modeset(intel_atomic_get_new_crtc_state(state, new_crtc)));
6196 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
6198 struct drm_connector_state *old_conn_state;
6199 struct drm_connector_state *new_conn_state;
6200 struct drm_connector *conn;
6203 for_each_oldnew_connector_in_state(&state->base, conn,
6204 old_conn_state, new_conn_state, i) {
6205 struct intel_encoder *encoder;
6206 struct intel_crtc *crtc;
6208 if (!intel_connector_needs_modeset(state,
6213 encoder = intel_connector_primary_encoder(to_intel_connector(conn));
6214 if (!encoder->update_prepare)
6217 crtc = new_conn_state->crtc ?
6218 to_intel_crtc(new_conn_state->crtc) : NULL;
6219 encoder->update_prepare(state, encoder, crtc);
6223 static void intel_encoders_update_complete(struct intel_atomic_state *state)
6225 struct drm_connector_state *old_conn_state;
6226 struct drm_connector_state *new_conn_state;
6227 struct drm_connector *conn;
6230 for_each_oldnew_connector_in_state(&state->base, conn,
6231 old_conn_state, new_conn_state, i) {
6232 struct intel_encoder *encoder;
6233 struct intel_crtc *crtc;
6235 if (!intel_connector_needs_modeset(state,
6240 encoder = intel_connector_primary_encoder(to_intel_connector(conn));
6241 if (!encoder->update_complete)
6244 crtc = new_conn_state->crtc ?
6245 to_intel_crtc(new_conn_state->crtc) : NULL;
6246 encoder->update_complete(state, encoder, crtc);
6250 static void intel_encoders_pre_pll_enable(struct intel_crtc *crtc,
6251 struct intel_crtc_state *crtc_state,
6252 struct intel_atomic_state *state)
6254 struct drm_connector_state *conn_state;
6255 struct drm_connector *conn;
6258 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6259 struct intel_encoder *encoder =
6260 to_intel_encoder(conn_state->best_encoder);
6262 if (conn_state->crtc != &crtc->base)
6265 if (encoder->pre_pll_enable)
6266 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
6270 static void intel_encoders_pre_enable(struct intel_crtc *crtc,
6271 struct intel_crtc_state *crtc_state,
6272 struct intel_atomic_state *state)
6274 struct drm_connector_state *conn_state;
6275 struct drm_connector *conn;
6278 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6279 struct intel_encoder *encoder =
6280 to_intel_encoder(conn_state->best_encoder);
6282 if (conn_state->crtc != &crtc->base)
6285 if (encoder->pre_enable)
6286 encoder->pre_enable(encoder, crtc_state, conn_state);
6290 static void intel_encoders_enable(struct intel_crtc *crtc,
6291 struct intel_crtc_state *crtc_state,
6292 struct intel_atomic_state *state)
6294 struct drm_connector_state *conn_state;
6295 struct drm_connector *conn;
6298 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6299 struct intel_encoder *encoder =
6300 to_intel_encoder(conn_state->best_encoder);
6302 if (conn_state->crtc != &crtc->base)
6305 if (encoder->enable)
6306 encoder->enable(encoder, crtc_state, conn_state);
6307 intel_opregion_notify_encoder(encoder, true);
6311 static void intel_encoders_disable(struct intel_crtc *crtc,
6312 struct intel_crtc_state *old_crtc_state,
6313 struct intel_atomic_state *state)
6315 struct drm_connector_state *old_conn_state;
6316 struct drm_connector *conn;
6319 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6320 struct intel_encoder *encoder =
6321 to_intel_encoder(old_conn_state->best_encoder);
6323 if (old_conn_state->crtc != &crtc->base)
6326 intel_opregion_notify_encoder(encoder, false);
6327 if (encoder->disable)
6328 encoder->disable(encoder, old_crtc_state, old_conn_state);
6332 static void intel_encoders_post_disable(struct intel_crtc *crtc,
6333 struct intel_crtc_state *old_crtc_state,
6334 struct intel_atomic_state *state)
6336 struct drm_connector_state *old_conn_state;
6337 struct drm_connector *conn;
6340 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6341 struct intel_encoder *encoder =
6342 to_intel_encoder(old_conn_state->best_encoder);
6344 if (old_conn_state->crtc != &crtc->base)
6347 if (encoder->post_disable)
6348 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
6352 static void intel_encoders_post_pll_disable(struct intel_crtc *crtc,
6353 struct intel_crtc_state *old_crtc_state,
6354 struct intel_atomic_state *state)
6356 struct drm_connector_state *old_conn_state;
6357 struct drm_connector *conn;
6360 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6361 struct intel_encoder *encoder =
6362 to_intel_encoder(old_conn_state->best_encoder);
6364 if (old_conn_state->crtc != &crtc->base)
6367 if (encoder->post_pll_disable)
6368 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
6372 static void intel_encoders_update_pipe(struct intel_crtc *crtc,
6373 struct intel_crtc_state *crtc_state,
6374 struct intel_atomic_state *state)
6376 struct drm_connector_state *conn_state;
6377 struct drm_connector *conn;
6380 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6381 struct intel_encoder *encoder =
6382 to_intel_encoder(conn_state->best_encoder);
6384 if (conn_state->crtc != &crtc->base)
6387 if (encoder->update_pipe)
6388 encoder->update_pipe(encoder, crtc_state, conn_state);
6392 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
6394 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6395 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
6397 plane->disable_plane(plane, crtc_state);
6400 static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
6401 struct intel_atomic_state *state)
6403 struct drm_crtc *crtc = pipe_config->base.crtc;
6404 struct drm_device *dev = crtc->dev;
6405 struct drm_i915_private *dev_priv = to_i915(dev);
6406 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6407 enum pipe pipe = intel_crtc->pipe;
6409 if (WARN_ON(intel_crtc->active))
6413 * Sometimes spurious CPU pipe underruns happen during FDI
6414 * training, at least with VGA+HDMI cloning. Suppress them.
6416 * On ILK we get an occasional spurious CPU pipe underruns
6417 * between eDP port A enable and vdd enable. Also PCH port
6418 * enable seems to result in the occasional CPU pipe underrun.
6420 * Spurious PCH underruns also occur during PCH enabling.
6422 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6423 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6425 if (pipe_config->has_pch_encoder)
6426 intel_prepare_shared_dpll(pipe_config);
6428 if (intel_crtc_has_dp_encoder(pipe_config))
6429 intel_dp_set_m_n(pipe_config, M1_N1);
6431 intel_set_pipe_timings(pipe_config);
6432 intel_set_pipe_src_size(pipe_config);
6434 if (pipe_config->has_pch_encoder) {
6435 intel_cpu_transcoder_set_m_n(pipe_config,
6436 &pipe_config->fdi_m_n, NULL);
6439 ironlake_set_pipeconf(pipe_config);
6441 intel_crtc->active = true;
6443 intel_encoders_pre_enable(intel_crtc, pipe_config, state);
6445 if (pipe_config->has_pch_encoder) {
6446 /* Note: FDI PLL enabling _must_ be done before we enable the
6447 * cpu pipes, hence this is separate from all the other fdi/pch
6449 ironlake_fdi_pll_enable(pipe_config);
6451 assert_fdi_tx_disabled(dev_priv, pipe);
6452 assert_fdi_rx_disabled(dev_priv, pipe);
6455 ironlake_pfit_enable(pipe_config);
6458 * On ILK+ LUT must be loaded before the pipe is running but with
6461 intel_color_load_luts(pipe_config);
6462 intel_color_commit(pipe_config);
6463 /* update DSPCNTR to configure gamma for pipe bottom color */
6464 intel_disable_primary_plane(pipe_config);
6466 if (dev_priv->display.initial_watermarks != NULL)
6467 dev_priv->display.initial_watermarks(state, pipe_config);
6468 intel_enable_pipe(pipe_config);
6470 if (pipe_config->has_pch_encoder)
6471 ironlake_pch_enable(state, pipe_config);
6473 assert_vblank_disabled(crtc);
6474 intel_crtc_vblank_on(pipe_config);
6476 intel_encoders_enable(intel_crtc, pipe_config, state);
6478 if (HAS_PCH_CPT(dev_priv))
6479 cpt_verify_modeset(dev, intel_crtc->pipe);
6482 * Must wait for vblank to avoid spurious PCH FIFO underruns.
6483 * And a second vblank wait is needed at least on ILK with
6484 * some interlaced HDMI modes. Let's do the double wait always
6485 * in case there are more corner cases we don't know about.
6487 if (pipe_config->has_pch_encoder) {
6488 intel_wait_for_vblank(dev_priv, pipe);
6489 intel_wait_for_vblank(dev_priv, pipe);
6491 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6492 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6495 /* IPS only exists on ULT machines and is tied to pipe A. */
6496 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
6498 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
6501 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
6502 enum pipe pipe, bool apply)
6504 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
6505 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
6512 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
6515 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
6517 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6518 enum pipe pipe = crtc->pipe;
6521 val = MBUS_DBOX_A_CREDIT(2);
6523 if (INTEL_GEN(dev_priv) >= 12) {
6524 val |= MBUS_DBOX_BW_CREDIT(2);
6525 val |= MBUS_DBOX_B_CREDIT(12);
6527 val |= MBUS_DBOX_BW_CREDIT(1);
6528 val |= MBUS_DBOX_B_CREDIT(8);
6531 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
6534 static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
6535 struct intel_atomic_state *state)
6537 struct drm_crtc *crtc = pipe_config->base.crtc;
6538 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6539 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6540 enum pipe pipe = intel_crtc->pipe, hsw_workaround_pipe;
6541 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
6542 bool psl_clkgate_wa;
6544 if (WARN_ON(intel_crtc->active))
6547 intel_encoders_pre_pll_enable(intel_crtc, pipe_config, state);
6549 if (pipe_config->shared_dpll)
6550 intel_enable_shared_dpll(pipe_config);
6552 intel_encoders_pre_enable(intel_crtc, pipe_config, state);
6554 if (intel_crtc_has_dp_encoder(pipe_config))
6555 intel_dp_set_m_n(pipe_config, M1_N1);
6557 if (!transcoder_is_dsi(cpu_transcoder))
6558 intel_set_pipe_timings(pipe_config);
6560 if (INTEL_GEN(dev_priv) >= 11)
6561 icl_enable_trans_port_sync(pipe_config);
6563 intel_set_pipe_src_size(pipe_config);
6565 if (cpu_transcoder != TRANSCODER_EDP &&
6566 !transcoder_is_dsi(cpu_transcoder)) {
6567 I915_WRITE(PIPE_MULT(cpu_transcoder),
6568 pipe_config->pixel_multiplier - 1);
6571 if (pipe_config->has_pch_encoder) {
6572 intel_cpu_transcoder_set_m_n(pipe_config,
6573 &pipe_config->fdi_m_n, NULL);
6576 if (!transcoder_is_dsi(cpu_transcoder))
6577 haswell_set_pipeconf(pipe_config);
6579 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
6580 bdw_set_pipemisc(pipe_config);
6582 intel_crtc->active = true;
6584 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
6585 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
6586 pipe_config->pch_pfit.enabled;
6588 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
6590 if (INTEL_GEN(dev_priv) >= 9)
6591 skylake_pfit_enable(pipe_config);
6593 ironlake_pfit_enable(pipe_config);
6596 * On ILK+ LUT must be loaded before the pipe is running but with
6599 intel_color_load_luts(pipe_config);
6600 intel_color_commit(pipe_config);
6601 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
6602 if (INTEL_GEN(dev_priv) < 9)
6603 intel_disable_primary_plane(pipe_config);
6605 if (INTEL_GEN(dev_priv) >= 11)
6606 icl_set_pipe_chicken(intel_crtc);
6608 if (!transcoder_is_dsi(cpu_transcoder))
6609 intel_ddi_enable_transcoder_func(pipe_config);
6611 if (dev_priv->display.initial_watermarks != NULL)
6612 dev_priv->display.initial_watermarks(state, pipe_config);
6614 if (INTEL_GEN(dev_priv) >= 11)
6615 icl_pipe_mbus_enable(intel_crtc);
6617 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
6618 if (!transcoder_is_dsi(cpu_transcoder))
6619 intel_enable_pipe(pipe_config);
6621 if (pipe_config->has_pch_encoder)
6622 lpt_pch_enable(state, pipe_config);
6624 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST))
6625 intel_ddi_set_vc_payload_alloc(pipe_config, true);
6627 assert_vblank_disabled(crtc);
6628 intel_crtc_vblank_on(pipe_config);
6630 intel_encoders_enable(intel_crtc, pipe_config, state);
6632 if (psl_clkgate_wa) {
6633 intel_wait_for_vblank(dev_priv, pipe);
6634 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
6637 /* If we change the relative order between pipe/planes enabling, we need
6638 * to change the workaround. */
6639 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
6640 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
6641 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6642 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6646 static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6648 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6649 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6650 enum pipe pipe = crtc->pipe;
6652 /* To avoid upsetting the power well on haswell only disable the pfit if
6653 * it's in use. The hw state code will make sure we get this right. */
6654 if (old_crtc_state->pch_pfit.enabled) {
6655 I915_WRITE(PF_CTL(pipe), 0);
6656 I915_WRITE(PF_WIN_POS(pipe), 0);
6657 I915_WRITE(PF_WIN_SZ(pipe), 0);
6661 static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
6662 struct intel_atomic_state *state)
6664 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6665 struct drm_device *dev = crtc->dev;
6666 struct drm_i915_private *dev_priv = to_i915(dev);
6667 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6668 enum pipe pipe = intel_crtc->pipe;
6671 * Sometimes spurious CPU pipe underruns happen when the
6672 * pipe is already disabled, but FDI RX/TX is still enabled.
6673 * Happens at least with VGA+HDMI cloning. Suppress them.
6675 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6676 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6678 intel_encoders_disable(intel_crtc, old_crtc_state, state);
6680 drm_crtc_vblank_off(crtc);
6681 assert_vblank_disabled(crtc);
6683 intel_disable_pipe(old_crtc_state);
6685 ironlake_pfit_disable(old_crtc_state);
6687 if (old_crtc_state->has_pch_encoder)
6688 ironlake_fdi_disable(crtc);
6690 intel_encoders_post_disable(intel_crtc, old_crtc_state, state);
6692 if (old_crtc_state->has_pch_encoder) {
6693 ironlake_disable_pch_transcoder(dev_priv, pipe);
6695 if (HAS_PCH_CPT(dev_priv)) {
6699 /* disable TRANS_DP_CTL */
6700 reg = TRANS_DP_CTL(pipe);
6701 temp = I915_READ(reg);
6702 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
6703 TRANS_DP_PORT_SEL_MASK);
6704 temp |= TRANS_DP_PORT_SEL_NONE;
6705 I915_WRITE(reg, temp);
6707 /* disable DPLL_SEL */
6708 temp = I915_READ(PCH_DPLL_SEL);
6709 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
6710 I915_WRITE(PCH_DPLL_SEL, temp);
6713 ironlake_fdi_pll_disable(intel_crtc);
6716 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6717 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6720 static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
6721 struct intel_atomic_state *state)
6723 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6724 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6725 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6726 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
6728 intel_encoders_disable(intel_crtc, old_crtc_state, state);
6730 drm_crtc_vblank_off(crtc);
6731 assert_vblank_disabled(crtc);
6733 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
6734 if (!transcoder_is_dsi(cpu_transcoder))
6735 intel_disable_pipe(old_crtc_state);
6737 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
6738 intel_ddi_set_vc_payload_alloc(old_crtc_state, false);
6740 if (INTEL_GEN(dev_priv) >= 11)
6741 icl_disable_transcoder_port_sync(old_crtc_state);
6743 if (!transcoder_is_dsi(cpu_transcoder))
6744 intel_ddi_disable_transcoder_func(old_crtc_state);
6746 intel_dsc_disable(old_crtc_state);
6748 if (INTEL_GEN(dev_priv) >= 9)
6749 skylake_scaler_disable(intel_crtc);
6751 ironlake_pfit_disable(old_crtc_state);
6753 intel_encoders_post_disable(intel_crtc, old_crtc_state, state);
6755 intel_encoders_post_pll_disable(intel_crtc, old_crtc_state, state);
6758 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
6760 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6761 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6763 if (!crtc_state->gmch_pfit.control)
6767 * The panel fitter should only be adjusted whilst the pipe is disabled,
6768 * according to register description and PRM.
6770 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
6771 assert_pipe_disabled(dev_priv, crtc->pipe);
6773 I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
6774 I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
6776 /* Border color in case we don't scale up to the full screen. Black by
6777 * default, change to something else for debugging. */
6778 I915_WRITE(BCLRPAT(crtc->pipe), 0);
6781 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
6783 if (phy == PHY_NONE)
6786 if (IS_ELKHARTLAKE(dev_priv))
6787 return phy <= PHY_C;
6789 if (INTEL_GEN(dev_priv) >= 11)
6790 return phy <= PHY_B;
6795 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
6797 if (INTEL_GEN(dev_priv) >= 12)
6798 return phy >= PHY_D && phy <= PHY_I;
6800 if (INTEL_GEN(dev_priv) >= 11 && !IS_ELKHARTLAKE(dev_priv))
6801 return phy >= PHY_C && phy <= PHY_F;
6806 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
6808 if (IS_ELKHARTLAKE(i915) && port == PORT_D)
6811 return (enum phy)port;
6814 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
6816 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
6817 return PORT_TC_NONE;
6819 if (INTEL_GEN(dev_priv) >= 12)
6820 return port - PORT_D;
6822 return port - PORT_C;
6825 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
6829 return POWER_DOMAIN_PORT_DDI_A_LANES;
6831 return POWER_DOMAIN_PORT_DDI_B_LANES;
6833 return POWER_DOMAIN_PORT_DDI_C_LANES;
6835 return POWER_DOMAIN_PORT_DDI_D_LANES;
6837 return POWER_DOMAIN_PORT_DDI_E_LANES;
6839 return POWER_DOMAIN_PORT_DDI_F_LANES;
6841 return POWER_DOMAIN_PORT_DDI_G_LANES;
6844 return POWER_DOMAIN_PORT_OTHER;
6848 enum intel_display_power_domain
6849 intel_aux_power_domain(struct intel_digital_port *dig_port)
6851 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
6852 enum phy phy = intel_port_to_phy(dev_priv, dig_port->base.port);
6854 if (intel_phy_is_tc(dev_priv, phy) &&
6855 dig_port->tc_mode == TC_PORT_TBT_ALT) {
6856 switch (dig_port->aux_ch) {
6858 return POWER_DOMAIN_AUX_C_TBT;
6860 return POWER_DOMAIN_AUX_D_TBT;
6862 return POWER_DOMAIN_AUX_E_TBT;
6864 return POWER_DOMAIN_AUX_F_TBT;
6866 return POWER_DOMAIN_AUX_G_TBT;
6868 MISSING_CASE(dig_port->aux_ch);
6869 return POWER_DOMAIN_AUX_C_TBT;
6873 switch (dig_port->aux_ch) {
6875 return POWER_DOMAIN_AUX_A;
6877 return POWER_DOMAIN_AUX_B;
6879 return POWER_DOMAIN_AUX_C;
6881 return POWER_DOMAIN_AUX_D;
6883 return POWER_DOMAIN_AUX_E;
6885 return POWER_DOMAIN_AUX_F;
6887 return POWER_DOMAIN_AUX_G;
6889 MISSING_CASE(dig_port->aux_ch);
6890 return POWER_DOMAIN_AUX_A;
6894 static u64 get_crtc_power_domains(struct intel_crtc_state *crtc_state)
6896 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6897 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6898 struct drm_encoder *encoder;
6899 enum pipe pipe = crtc->pipe;
6901 enum transcoder transcoder = crtc_state->cpu_transcoder;
6903 if (!crtc_state->base.active)
6906 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
6907 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
6908 if (crtc_state->pch_pfit.enabled ||
6909 crtc_state->pch_pfit.force_thru)
6910 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
6912 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
6913 crtc_state->base.encoder_mask) {
6914 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6916 mask |= BIT_ULL(intel_encoder->power_domain);
6919 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
6920 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
6922 if (crtc_state->shared_dpll)
6923 mask |= BIT_ULL(POWER_DOMAIN_DISPLAY_CORE);
6929 modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state)
6931 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6932 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6933 enum intel_display_power_domain domain;
6934 u64 domains, new_domains, old_domains;
6936 old_domains = crtc->enabled_power_domains;
6937 crtc->enabled_power_domains = new_domains =
6938 get_crtc_power_domains(crtc_state);
6940 domains = new_domains & ~old_domains;
6942 for_each_power_domain(domain, domains)
6943 intel_display_power_get(dev_priv, domain);
6945 return old_domains & ~new_domains;
6948 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
6951 enum intel_display_power_domain domain;
6953 for_each_power_domain(domain, domains)
6954 intel_display_power_put_unchecked(dev_priv, domain);
6957 static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
6958 struct intel_atomic_state *state)
6960 struct drm_crtc *crtc = pipe_config->base.crtc;
6961 struct drm_device *dev = crtc->dev;
6962 struct drm_i915_private *dev_priv = to_i915(dev);
6963 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6964 enum pipe pipe = intel_crtc->pipe;
6966 if (WARN_ON(intel_crtc->active))
6969 if (intel_crtc_has_dp_encoder(pipe_config))
6970 intel_dp_set_m_n(pipe_config, M1_N1);
6972 intel_set_pipe_timings(pipe_config);
6973 intel_set_pipe_src_size(pipe_config);
6975 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
6976 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6977 I915_WRITE(CHV_CANVAS(pipe), 0);
6980 i9xx_set_pipeconf(pipe_config);
6982 intel_crtc->active = true;
6984 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6986 intel_encoders_pre_pll_enable(intel_crtc, pipe_config, state);
6988 if (IS_CHERRYVIEW(dev_priv)) {
6989 chv_prepare_pll(intel_crtc, pipe_config);
6990 chv_enable_pll(intel_crtc, pipe_config);
6992 vlv_prepare_pll(intel_crtc, pipe_config);
6993 vlv_enable_pll(intel_crtc, pipe_config);
6996 intel_encoders_pre_enable(intel_crtc, pipe_config, state);
6998 i9xx_pfit_enable(pipe_config);
7000 intel_color_load_luts(pipe_config);
7001 intel_color_commit(pipe_config);
7002 /* update DSPCNTR to configure gamma for pipe bottom color */
7003 intel_disable_primary_plane(pipe_config);
7005 dev_priv->display.initial_watermarks(state, pipe_config);
7006 intel_enable_pipe(pipe_config);
7008 assert_vblank_disabled(crtc);
7009 intel_crtc_vblank_on(pipe_config);
7011 intel_encoders_enable(intel_crtc, pipe_config, state);
7014 static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
7016 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7017 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7019 I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0);
7020 I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1);
7023 static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
7024 struct intel_atomic_state *state)
7026 struct drm_crtc *crtc = pipe_config->base.crtc;
7027 struct drm_device *dev = crtc->dev;
7028 struct drm_i915_private *dev_priv = to_i915(dev);
7029 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7030 enum pipe pipe = intel_crtc->pipe;
7032 if (WARN_ON(intel_crtc->active))
7035 i9xx_set_pll_dividers(pipe_config);
7037 if (intel_crtc_has_dp_encoder(pipe_config))
7038 intel_dp_set_m_n(pipe_config, M1_N1);
7040 intel_set_pipe_timings(pipe_config);
7041 intel_set_pipe_src_size(pipe_config);
7043 i9xx_set_pipeconf(pipe_config);
7045 intel_crtc->active = true;
7047 if (!IS_GEN(dev_priv, 2))
7048 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
7050 intel_encoders_pre_enable(intel_crtc, pipe_config, state);
7052 i9xx_enable_pll(intel_crtc, pipe_config);
7054 i9xx_pfit_enable(pipe_config);
7056 intel_color_load_luts(pipe_config);
7057 intel_color_commit(pipe_config);
7058 /* update DSPCNTR to configure gamma for pipe bottom color */
7059 intel_disable_primary_plane(pipe_config);
7061 if (dev_priv->display.initial_watermarks != NULL)
7062 dev_priv->display.initial_watermarks(state,
7065 intel_update_watermarks(intel_crtc);
7066 intel_enable_pipe(pipe_config);
7068 assert_vblank_disabled(crtc);
7069 intel_crtc_vblank_on(pipe_config);
7071 intel_encoders_enable(intel_crtc, pipe_config, state);
7074 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
7076 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
7077 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7079 if (!old_crtc_state->gmch_pfit.control)
7082 assert_pipe_disabled(dev_priv, crtc->pipe);
7084 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
7085 I915_READ(PFIT_CONTROL));
7086 I915_WRITE(PFIT_CONTROL, 0);
7089 static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
7090 struct intel_atomic_state *state)
7092 struct drm_crtc *crtc = old_crtc_state->base.crtc;
7093 struct drm_device *dev = crtc->dev;
7094 struct drm_i915_private *dev_priv = to_i915(dev);
7095 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7096 enum pipe pipe = intel_crtc->pipe;
7099 * On gen2 planes are double buffered but the pipe isn't, so we must
7100 * wait for planes to fully turn off before disabling the pipe.
7102 if (IS_GEN(dev_priv, 2))
7103 intel_wait_for_vblank(dev_priv, pipe);
7105 intel_encoders_disable(intel_crtc, old_crtc_state, state);
7107 drm_crtc_vblank_off(crtc);
7108 assert_vblank_disabled(crtc);
7110 intel_disable_pipe(old_crtc_state);
7112 i9xx_pfit_disable(old_crtc_state);
7114 intel_encoders_post_disable(intel_crtc, old_crtc_state, state);
7116 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
7117 if (IS_CHERRYVIEW(dev_priv))
7118 chv_disable_pll(dev_priv, pipe);
7119 else if (IS_VALLEYVIEW(dev_priv))
7120 vlv_disable_pll(dev_priv, pipe);
7122 i9xx_disable_pll(old_crtc_state);
7125 intel_encoders_post_pll_disable(intel_crtc, old_crtc_state, state);
7127 if (!IS_GEN(dev_priv, 2))
7128 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
7130 if (!dev_priv->display.initial_watermarks)
7131 intel_update_watermarks(intel_crtc);
7133 /* clock the pipe down to 640x480@60 to potentially save power */
7134 if (IS_I830(dev_priv))
7135 i830_enable_pipe(dev_priv, pipe);
7138 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
7139 struct drm_modeset_acquire_ctx *ctx)
7141 struct intel_encoder *encoder;
7142 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7143 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
7144 struct intel_bw_state *bw_state =
7145 to_intel_bw_state(dev_priv->bw_obj.state);
7146 enum intel_display_power_domain domain;
7147 struct intel_plane *plane;
7149 struct drm_atomic_state *state;
7150 struct intel_crtc_state *crtc_state;
7153 if (!intel_crtc->active)
7156 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
7157 const struct intel_plane_state *plane_state =
7158 to_intel_plane_state(plane->base.state);
7160 if (plane_state->base.visible)
7161 intel_plane_disable_noatomic(intel_crtc, plane);
7164 state = drm_atomic_state_alloc(crtc->dev);
7166 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
7167 crtc->base.id, crtc->name);
7171 state->acquire_ctx = ctx;
7173 /* Everything's already locked, -EDEADLK can't happen. */
7174 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
7175 ret = drm_atomic_add_affected_connectors(state, crtc);
7177 WARN_ON(IS_ERR(crtc_state) || ret);
7179 dev_priv->display.crtc_disable(crtc_state, to_intel_atomic_state(state));
7181 drm_atomic_state_put(state);
7183 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
7184 crtc->base.id, crtc->name);
7186 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
7187 crtc->state->active = false;
7188 intel_crtc->active = false;
7189 crtc->enabled = false;
7190 crtc->state->connector_mask = 0;
7191 crtc->state->encoder_mask = 0;
7193 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
7194 encoder->base.crtc = NULL;
7196 intel_fbc_disable(intel_crtc);
7197 intel_update_watermarks(intel_crtc);
7198 intel_disable_shared_dpll(to_intel_crtc_state(crtc->state));
7200 domains = intel_crtc->enabled_power_domains;
7201 for_each_power_domain(domain, domains)
7202 intel_display_power_put_unchecked(dev_priv, domain);
7203 intel_crtc->enabled_power_domains = 0;
7205 dev_priv->active_pipes &= ~BIT(intel_crtc->pipe);
7206 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
7207 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
7209 bw_state->data_rate[intel_crtc->pipe] = 0;
7210 bw_state->num_active_planes[intel_crtc->pipe] = 0;
7214 * turn all crtc's off, but do not adjust state
7215 * This has to be paired with a call to intel_modeset_setup_hw_state.
7217 int intel_display_suspend(struct drm_device *dev)
7219 struct drm_i915_private *dev_priv = to_i915(dev);
7220 struct drm_atomic_state *state;
7223 state = drm_atomic_helper_suspend(dev);
7224 ret = PTR_ERR_OR_ZERO(state);
7226 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
7228 dev_priv->modeset_restore_state = state;
7232 void intel_encoder_destroy(struct drm_encoder *encoder)
7234 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
7236 drm_encoder_cleanup(encoder);
7237 kfree(intel_encoder);
7240 /* Cross check the actual hw state with our own modeset state tracking (and it's
7241 * internal consistency). */
7242 static void intel_connector_verify_state(struct intel_crtc_state *crtc_state,
7243 struct drm_connector_state *conn_state)
7245 struct intel_connector *connector = to_intel_connector(conn_state->connector);
7247 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
7248 connector->base.base.id,
7249 connector->base.name);
7251 if (connector->get_hw_state(connector)) {
7252 struct intel_encoder *encoder = connector->encoder;
7254 I915_STATE_WARN(!crtc_state,
7255 "connector enabled without attached crtc\n");
7260 I915_STATE_WARN(!crtc_state->base.active,
7261 "connector is active, but attached crtc isn't\n");
7263 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
7266 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
7267 "atomic encoder doesn't match attached encoder\n");
7269 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
7270 "attached encoder crtc differs from connector crtc\n");
7272 I915_STATE_WARN(crtc_state && crtc_state->base.active,
7273 "attached crtc is active, but connector isn't\n");
7274 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
7275 "best encoder set without crtc!\n");
7279 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
7281 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
7282 return crtc_state->fdi_lanes;
7287 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
7288 struct intel_crtc_state *pipe_config)
7290 struct drm_i915_private *dev_priv = to_i915(dev);
7291 struct drm_atomic_state *state = pipe_config->base.state;
7292 struct intel_crtc *other_crtc;
7293 struct intel_crtc_state *other_crtc_state;
7295 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
7296 pipe_name(pipe), pipe_config->fdi_lanes);
7297 if (pipe_config->fdi_lanes > 4) {
7298 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
7299 pipe_name(pipe), pipe_config->fdi_lanes);
7303 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7304 if (pipe_config->fdi_lanes > 2) {
7305 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
7306 pipe_config->fdi_lanes);
7313 if (INTEL_NUM_PIPES(dev_priv) == 2)
7316 /* Ivybridge 3 pipe is really complicated */
7321 if (pipe_config->fdi_lanes <= 2)
7324 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
7326 intel_atomic_get_crtc_state(state, other_crtc);
7327 if (IS_ERR(other_crtc_state))
7328 return PTR_ERR(other_crtc_state);
7330 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
7331 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
7332 pipe_name(pipe), pipe_config->fdi_lanes);
7337 if (pipe_config->fdi_lanes > 2) {
7338 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
7339 pipe_name(pipe), pipe_config->fdi_lanes);
7343 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
7345 intel_atomic_get_crtc_state(state, other_crtc);
7346 if (IS_ERR(other_crtc_state))
7347 return PTR_ERR(other_crtc_state);
7349 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
7350 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
7360 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
7361 struct intel_crtc_state *pipe_config)
7363 struct drm_device *dev = intel_crtc->base.dev;
7364 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
7365 int lane, link_bw, fdi_dotclock, ret;
7366 bool needs_recompute = false;
7369 /* FDI is a binary signal running at ~2.7GHz, encoding
7370 * each output octet as 10 bits. The actual frequency
7371 * is stored as a divider into a 100MHz clock, and the
7372 * mode pixel clock is stored in units of 1KHz.
7373 * Hence the bw of each lane in terms of the mode signal
7376 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
7378 fdi_dotclock = adjusted_mode->crtc_clock;
7380 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
7381 pipe_config->pipe_bpp);
7383 pipe_config->fdi_lanes = lane;
7385 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
7386 link_bw, &pipe_config->fdi_m_n, false, false);
7388 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
7389 if (ret == -EDEADLK)
7392 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
7393 pipe_config->pipe_bpp -= 2*3;
7394 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
7395 pipe_config->pipe_bpp);
7396 needs_recompute = true;
7397 pipe_config->bw_constrained = true;
7402 if (needs_recompute)
7408 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
7410 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7411 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7413 /* IPS only exists on ULT machines and is tied to pipe A. */
7414 if (!hsw_crtc_supports_ips(crtc))
7417 if (!i915_modparams.enable_ips)
7420 if (crtc_state->pipe_bpp > 24)
7424 * We compare against max which means we must take
7425 * the increased cdclk requirement into account when
7426 * calculating the new cdclk.
7428 * Should measure whether using a lower cdclk w/o IPS
7430 if (IS_BROADWELL(dev_priv) &&
7431 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
7437 static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
7439 struct drm_i915_private *dev_priv =
7440 to_i915(crtc_state->base.crtc->dev);
7441 struct intel_atomic_state *intel_state =
7442 to_intel_atomic_state(crtc_state->base.state);
7444 if (!hsw_crtc_state_ips_capable(crtc_state))
7448 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
7449 * enabled and disabled dynamically based on package C states,
7450 * user space can't make reliable use of the CRCs, so let's just
7451 * completely disable it.
7453 if (crtc_state->crc_enabled)
7456 /* IPS should be fine as long as at least one plane is enabled. */
7457 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
7460 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
7461 if (IS_BROADWELL(dev_priv) &&
7462 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
7468 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
7470 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7472 /* GDG double wide on either pipe, otherwise pipe A only */
7473 return INTEL_GEN(dev_priv) < 4 &&
7474 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
7477 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
7481 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
7484 * We only use IF-ID interlacing. If we ever use
7485 * PF-ID we'll need to adjust the pixel_rate here.
7488 if (pipe_config->pch_pfit.enabled) {
7489 u64 pipe_w, pipe_h, pfit_w, pfit_h;
7490 u32 pfit_size = pipe_config->pch_pfit.size;
7492 pipe_w = pipe_config->pipe_src_w;
7493 pipe_h = pipe_config->pipe_src_h;
7495 pfit_w = (pfit_size >> 16) & 0xFFFF;
7496 pfit_h = pfit_size & 0xFFFF;
7497 if (pipe_w < pfit_w)
7499 if (pipe_h < pfit_h)
7502 if (WARN_ON(!pfit_w || !pfit_h))
7505 pixel_rate = div_u64(mul_u32_u32(pixel_rate, pipe_w * pipe_h),
7512 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
7514 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
7516 if (HAS_GMCH(dev_priv))
7517 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
7518 crtc_state->pixel_rate =
7519 crtc_state->base.adjusted_mode.crtc_clock;
7521 crtc_state->pixel_rate =
7522 ilk_pipe_pixel_rate(crtc_state);
7525 static int intel_crtc_compute_config(struct intel_crtc *crtc,
7526 struct intel_crtc_state *pipe_config)
7528 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7529 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
7530 int clock_limit = dev_priv->max_dotclk_freq;
7532 if (INTEL_GEN(dev_priv) < 4) {
7533 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
7536 * Enable double wide mode when the dot clock
7537 * is > 90% of the (display) core speed.
7539 if (intel_crtc_supports_double_wide(crtc) &&
7540 adjusted_mode->crtc_clock > clock_limit) {
7541 clock_limit = dev_priv->max_dotclk_freq;
7542 pipe_config->double_wide = true;
7546 if (adjusted_mode->crtc_clock > clock_limit) {
7547 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
7548 adjusted_mode->crtc_clock, clock_limit,
7549 yesno(pipe_config->double_wide));
7553 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
7554 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
7555 pipe_config->base.ctm) {
7557 * There is only one pipe CSC unit per pipe, and we need that
7558 * for output conversion from RGB->YCBCR. So if CTM is already
7559 * applied we can't support YCBCR420 output.
7561 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
7566 * Pipe horizontal size must be even in:
7568 * - LVDS dual channel mode
7569 * - Double wide pipe
7571 if (pipe_config->pipe_src_w & 1) {
7572 if (pipe_config->double_wide) {
7573 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
7577 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
7578 intel_is_dual_link_lvds(dev_priv)) {
7579 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
7584 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
7585 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
7587 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
7588 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
7591 intel_crtc_compute_pixel_rate(pipe_config);
7593 if (pipe_config->has_pch_encoder)
7594 return ironlake_fdi_compute_config(crtc, pipe_config);
7600 intel_reduce_m_n_ratio(u32 *num, u32 *den)
7602 while (*num > DATA_LINK_M_N_MASK ||
7603 *den > DATA_LINK_M_N_MASK) {
7609 static void compute_m_n(unsigned int m, unsigned int n,
7610 u32 *ret_m, u32 *ret_n,
7614 * Several DP dongles in particular seem to be fussy about
7615 * too large link M/N values. Give N value as 0x8000 that
7616 * should be acceptable by specific devices. 0x8000 is the
7617 * specified fixed N value for asynchronous clock mode,
7618 * which the devices expect also in synchronous clock mode.
7623 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
7625 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
7626 intel_reduce_m_n_ratio(ret_m, ret_n);
7630 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
7631 int pixel_clock, int link_clock,
7632 struct intel_link_m_n *m_n,
7633 bool constant_n, bool fec_enable)
7635 u32 data_clock = bits_per_pixel * pixel_clock;
7638 data_clock = intel_dp_mode_to_fec_clock(data_clock);
7641 compute_m_n(data_clock,
7642 link_clock * nlanes * 8,
7643 &m_n->gmch_m, &m_n->gmch_n,
7646 compute_m_n(pixel_clock, link_clock,
7647 &m_n->link_m, &m_n->link_n,
7651 static void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv)
7654 * There may be no VBT; and if the BIOS enabled SSC we can
7655 * just keep using it to avoid unnecessary flicker. Whereas if the
7656 * BIOS isn't using it, don't assume it will work even if the VBT
7657 * indicates as much.
7659 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
7660 bool bios_lvds_use_ssc = I915_READ(PCH_DREF_CONTROL) &
7663 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
7664 DRM_DEBUG_KMS("SSC %s by BIOS, overriding VBT which says %s\n",
7665 enableddisabled(bios_lvds_use_ssc),
7666 enableddisabled(dev_priv->vbt.lvds_use_ssc));
7667 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
7672 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
7674 if (i915_modparams.panel_use_ssc >= 0)
7675 return i915_modparams.panel_use_ssc != 0;
7676 return dev_priv->vbt.lvds_use_ssc
7677 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
7680 static u32 pnv_dpll_compute_fp(struct dpll *dpll)
7682 return (1 << dpll->n) << 16 | dpll->m2;
7685 static u32 i9xx_dpll_compute_fp(struct dpll *dpll)
7687 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
7690 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
7691 struct intel_crtc_state *crtc_state,
7692 struct dpll *reduced_clock)
7694 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7697 if (IS_PINEVIEW(dev_priv)) {
7698 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
7700 fp2 = pnv_dpll_compute_fp(reduced_clock);
7702 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
7704 fp2 = i9xx_dpll_compute_fp(reduced_clock);
7707 crtc_state->dpll_hw_state.fp0 = fp;
7709 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7711 crtc_state->dpll_hw_state.fp1 = fp2;
7713 crtc_state->dpll_hw_state.fp1 = fp;
7717 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
7723 * PLLB opamp always calibrates to max value of 0x3f, force enable it
7724 * and set it to a reasonable value instead.
7726 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7727 reg_val &= 0xffffff00;
7728 reg_val |= 0x00000030;
7729 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7731 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7732 reg_val &= 0x00ffffff;
7733 reg_val |= 0x8c000000;
7734 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7736 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7737 reg_val &= 0xffffff00;
7738 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7740 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7741 reg_val &= 0x00ffffff;
7742 reg_val |= 0xb0000000;
7743 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7746 static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7747 const struct intel_link_m_n *m_n)
7749 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7750 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7751 enum pipe pipe = crtc->pipe;
7753 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7754 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
7755 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
7756 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
7759 static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
7760 enum transcoder transcoder)
7762 if (IS_HASWELL(dev_priv))
7763 return transcoder == TRANSCODER_EDP;
7766 * Strictly speaking some registers are available before
7767 * gen7, but we only support DRRS on gen7+
7769 return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv);
7772 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7773 const struct intel_link_m_n *m_n,
7774 const struct intel_link_m_n *m2_n2)
7776 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7777 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7778 enum pipe pipe = crtc->pipe;
7779 enum transcoder transcoder = crtc_state->cpu_transcoder;
7781 if (INTEL_GEN(dev_priv) >= 5) {
7782 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
7783 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
7784 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
7785 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
7787 * M2_N2 registers are set only if DRRS is supported
7788 * (to make sure the registers are not unnecessarily accessed).
7790 if (m2_n2 && crtc_state->has_drrs &&
7791 transcoder_has_m2_n2(dev_priv, transcoder)) {
7792 I915_WRITE(PIPE_DATA_M2(transcoder),
7793 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
7794 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
7795 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
7796 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
7799 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7800 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
7801 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
7802 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
7806 void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n)
7808 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
7811 dp_m_n = &crtc_state->dp_m_n;
7812 dp_m2_n2 = &crtc_state->dp_m2_n2;
7813 } else if (m_n == M2_N2) {
7816 * M2_N2 registers are not supported. Hence m2_n2 divider value
7817 * needs to be programmed into M1_N1.
7819 dp_m_n = &crtc_state->dp_m2_n2;
7821 DRM_ERROR("Unsupported divider value\n");
7825 if (crtc_state->has_pch_encoder)
7826 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
7828 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
7831 static void vlv_compute_dpll(struct intel_crtc *crtc,
7832 struct intel_crtc_state *pipe_config)
7834 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
7835 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
7836 if (crtc->pipe != PIPE_A)
7837 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7839 /* DPLL not used with DSI, but still need the rest set up */
7840 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
7841 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
7842 DPLL_EXT_BUFFER_ENABLE_VLV;
7844 pipe_config->dpll_hw_state.dpll_md =
7845 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7848 static void chv_compute_dpll(struct intel_crtc *crtc,
7849 struct intel_crtc_state *pipe_config)
7851 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
7852 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
7853 if (crtc->pipe != PIPE_A)
7854 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7856 /* DPLL not used with DSI, but still need the rest set up */
7857 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
7858 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
7860 pipe_config->dpll_hw_state.dpll_md =
7861 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7864 static void vlv_prepare_pll(struct intel_crtc *crtc,
7865 const struct intel_crtc_state *pipe_config)
7867 struct drm_device *dev = crtc->base.dev;
7868 struct drm_i915_private *dev_priv = to_i915(dev);
7869 enum pipe pipe = crtc->pipe;
7871 u32 bestn, bestm1, bestm2, bestp1, bestp2;
7872 u32 coreclk, reg_val;
7875 I915_WRITE(DPLL(pipe),
7876 pipe_config->dpll_hw_state.dpll &
7877 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
7879 /* No need to actually set up the DPLL with DSI */
7880 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7883 vlv_dpio_get(dev_priv);
7885 bestn = pipe_config->dpll.n;
7886 bestm1 = pipe_config->dpll.m1;
7887 bestm2 = pipe_config->dpll.m2;
7888 bestp1 = pipe_config->dpll.p1;
7889 bestp2 = pipe_config->dpll.p2;
7891 /* See eDP HDMI DPIO driver vbios notes doc */
7893 /* PLL B needs special handling */
7895 vlv_pllb_recal_opamp(dev_priv, pipe);
7897 /* Set up Tx target for periodic Rcomp update */
7898 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
7900 /* Disable target IRef on PLL */
7901 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
7902 reg_val &= 0x00ffffff;
7903 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
7905 /* Disable fast lock */
7906 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
7908 /* Set idtafcrecal before PLL is enabled */
7909 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
7910 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
7911 mdiv |= ((bestn << DPIO_N_SHIFT));
7912 mdiv |= (1 << DPIO_K_SHIFT);
7915 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7916 * but we don't support that).
7917 * Note: don't use the DAC post divider as it seems unstable.
7919 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
7920 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7922 mdiv |= DPIO_ENABLE_CALIBRATION;
7923 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7925 /* Set HBR and RBR LPF coefficients */
7926 if (pipe_config->port_clock == 162000 ||
7927 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
7928 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
7929 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7932 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7935 if (intel_crtc_has_dp_encoder(pipe_config)) {
7936 /* Use SSC source */
7938 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7941 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7943 } else { /* HDMI or VGA */
7944 /* Use bend source */
7946 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7949 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7953 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
7954 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
7955 if (intel_crtc_has_dp_encoder(pipe_config))
7956 coreclk |= 0x01000000;
7957 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
7959 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
7961 vlv_dpio_put(dev_priv);
7964 static void chv_prepare_pll(struct intel_crtc *crtc,
7965 const struct intel_crtc_state *pipe_config)
7967 struct drm_device *dev = crtc->base.dev;
7968 struct drm_i915_private *dev_priv = to_i915(dev);
7969 enum pipe pipe = crtc->pipe;
7970 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7971 u32 loopfilter, tribuf_calcntr;
7972 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
7976 /* Enable Refclk and SSC */
7977 I915_WRITE(DPLL(pipe),
7978 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
7980 /* No need to actually set up the DPLL with DSI */
7981 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7984 bestn = pipe_config->dpll.n;
7985 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7986 bestm1 = pipe_config->dpll.m1;
7987 bestm2 = pipe_config->dpll.m2 >> 22;
7988 bestp1 = pipe_config->dpll.p1;
7989 bestp2 = pipe_config->dpll.p2;
7990 vco = pipe_config->dpll.vco;
7994 vlv_dpio_get(dev_priv);
7996 /* p1 and p2 divider */
7997 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7998 5 << DPIO_CHV_S1_DIV_SHIFT |
7999 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
8000 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
8001 1 << DPIO_CHV_K_DIV_SHIFT);
8003 /* Feedback post-divider - m2 */
8004 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
8006 /* Feedback refclk divider - n and m1 */
8007 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
8008 DPIO_CHV_M1_DIV_BY_2 |
8009 1 << DPIO_CHV_N_DIV_SHIFT);
8011 /* M2 fraction division */
8012 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
8014 /* M2 fraction division enable */
8015 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
8016 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
8017 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
8019 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
8020 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
8022 /* Program digital lock detect threshold */
8023 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
8024 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
8025 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
8026 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
8028 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
8029 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
8032 if (vco == 5400000) {
8033 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
8034 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
8035 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
8036 tribuf_calcntr = 0x9;
8037 } else if (vco <= 6200000) {
8038 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
8039 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
8040 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8041 tribuf_calcntr = 0x9;
8042 } else if (vco <= 6480000) {
8043 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
8044 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
8045 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8046 tribuf_calcntr = 0x8;
8048 /* Not supported. Apply the same limits as in the max case */
8049 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
8050 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
8051 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8054 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
8056 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
8057 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
8058 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
8059 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
8062 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
8063 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
8066 vlv_dpio_put(dev_priv);
8070 * vlv_force_pll_on - forcibly enable just the PLL
8071 * @dev_priv: i915 private structure
8072 * @pipe: pipe PLL to enable
8073 * @dpll: PLL configuration
8075 * Enable the PLL for @pipe using the supplied @dpll config. To be used
8076 * in cases where we need the PLL enabled even when @pipe is not going to
8079 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
8080 const struct dpll *dpll)
8082 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
8083 struct intel_crtc_state *pipe_config;
8085 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
8089 pipe_config->base.crtc = &crtc->base;
8090 pipe_config->pixel_multiplier = 1;
8091 pipe_config->dpll = *dpll;
8093 if (IS_CHERRYVIEW(dev_priv)) {
8094 chv_compute_dpll(crtc, pipe_config);
8095 chv_prepare_pll(crtc, pipe_config);
8096 chv_enable_pll(crtc, pipe_config);
8098 vlv_compute_dpll(crtc, pipe_config);
8099 vlv_prepare_pll(crtc, pipe_config);
8100 vlv_enable_pll(crtc, pipe_config);
8109 * vlv_force_pll_off - forcibly disable just the PLL
8110 * @dev_priv: i915 private structure
8111 * @pipe: pipe PLL to disable
8113 * Disable the PLL for @pipe. To be used in cases where we need
8114 * the PLL enabled even when @pipe is not going to be enabled.
8116 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
8118 if (IS_CHERRYVIEW(dev_priv))
8119 chv_disable_pll(dev_priv, pipe);
8121 vlv_disable_pll(dev_priv, pipe);
8124 static void i9xx_compute_dpll(struct intel_crtc *crtc,
8125 struct intel_crtc_state *crtc_state,
8126 struct dpll *reduced_clock)
8128 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8130 struct dpll *clock = &crtc_state->dpll;
8132 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
8134 dpll = DPLL_VGA_MODE_DIS;
8136 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8137 dpll |= DPLLB_MODE_LVDS;
8139 dpll |= DPLLB_MODE_DAC_SERIAL;
8141 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
8142 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
8143 dpll |= (crtc_state->pixel_multiplier - 1)
8144 << SDVO_MULTIPLIER_SHIFT_HIRES;
8147 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8148 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8149 dpll |= DPLL_SDVO_HIGH_SPEED;
8151 if (intel_crtc_has_dp_encoder(crtc_state))
8152 dpll |= DPLL_SDVO_HIGH_SPEED;
8154 /* compute bitmask from p1 value */
8155 if (IS_PINEVIEW(dev_priv))
8156 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
8158 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8159 if (IS_G4X(dev_priv) && reduced_clock)
8160 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8162 switch (clock->p2) {
8164 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8167 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8170 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8173 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8176 if (INTEL_GEN(dev_priv) >= 4)
8177 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
8179 if (crtc_state->sdvo_tv_clock)
8180 dpll |= PLL_REF_INPUT_TVCLKINBC;
8181 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8182 intel_panel_use_ssc(dev_priv))
8183 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8185 dpll |= PLL_REF_INPUT_DREFCLK;
8187 dpll |= DPLL_VCO_ENABLE;
8188 crtc_state->dpll_hw_state.dpll = dpll;
8190 if (INTEL_GEN(dev_priv) >= 4) {
8191 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
8192 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8193 crtc_state->dpll_hw_state.dpll_md = dpll_md;
8197 static void i8xx_compute_dpll(struct intel_crtc *crtc,
8198 struct intel_crtc_state *crtc_state,
8199 struct dpll *reduced_clock)
8201 struct drm_device *dev = crtc->base.dev;
8202 struct drm_i915_private *dev_priv = to_i915(dev);
8204 struct dpll *clock = &crtc_state->dpll;
8206 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
8208 dpll = DPLL_VGA_MODE_DIS;
8210 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8211 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8214 dpll |= PLL_P1_DIVIDE_BY_TWO;
8216 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8218 dpll |= PLL_P2_DIVIDE_BY_4;
8223 * "[Almador Errata}: For the correct operation of the muxed DVO pins
8224 * (GDEVSELB/I2Cdata, GIRDBY/I2CClk) and (GFRAMEB/DVI_Data,
8225 * GTRDYB/DVI_Clk): Bit 31 (DPLL VCO Enable) and Bit 30 (2X Clock
8226 * Enable) must be set to “1” in both the DPLL A Control Register
8227 * (06014h-06017h) and DPLL B Control Register (06018h-0601Bh)."
8229 * For simplicity We simply keep both bits always enabled in
8230 * both DPLLS. The spec says we should disable the DVO 2X clock
8231 * when not needed, but this seems to work fine in practice.
8233 if (IS_I830(dev_priv) ||
8234 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
8235 dpll |= DPLL_DVO_2X_MODE;
8237 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8238 intel_panel_use_ssc(dev_priv))
8239 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8241 dpll |= PLL_REF_INPUT_DREFCLK;
8243 dpll |= DPLL_VCO_ENABLE;
8244 crtc_state->dpll_hw_state.dpll = dpll;
8247 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
8249 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8250 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8251 enum pipe pipe = crtc->pipe;
8252 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8253 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
8254 u32 crtc_vtotal, crtc_vblank_end;
8257 /* We need to be careful not to changed the adjusted mode, for otherwise
8258 * the hw state checker will get angry at the mismatch. */
8259 crtc_vtotal = adjusted_mode->crtc_vtotal;
8260 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
8262 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
8263 /* the chip adds 2 halflines automatically */
8265 crtc_vblank_end -= 1;
8267 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8268 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
8270 vsyncshift = adjusted_mode->crtc_hsync_start -
8271 adjusted_mode->crtc_htotal / 2;
8273 vsyncshift += adjusted_mode->crtc_htotal;
8276 if (INTEL_GEN(dev_priv) > 3)
8277 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
8279 I915_WRITE(HTOTAL(cpu_transcoder),
8280 (adjusted_mode->crtc_hdisplay - 1) |
8281 ((adjusted_mode->crtc_htotal - 1) << 16));
8282 I915_WRITE(HBLANK(cpu_transcoder),
8283 (adjusted_mode->crtc_hblank_start - 1) |
8284 ((adjusted_mode->crtc_hblank_end - 1) << 16));
8285 I915_WRITE(HSYNC(cpu_transcoder),
8286 (adjusted_mode->crtc_hsync_start - 1) |
8287 ((adjusted_mode->crtc_hsync_end - 1) << 16));
8289 I915_WRITE(VTOTAL(cpu_transcoder),
8290 (adjusted_mode->crtc_vdisplay - 1) |
8291 ((crtc_vtotal - 1) << 16));
8292 I915_WRITE(VBLANK(cpu_transcoder),
8293 (adjusted_mode->crtc_vblank_start - 1) |
8294 ((crtc_vblank_end - 1) << 16));
8295 I915_WRITE(VSYNC(cpu_transcoder),
8296 (adjusted_mode->crtc_vsync_start - 1) |
8297 ((adjusted_mode->crtc_vsync_end - 1) << 16));
8299 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
8300 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
8301 * documented on the DDI_FUNC_CTL register description, EDP Input Select
8303 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
8304 (pipe == PIPE_B || pipe == PIPE_C))
8305 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
8309 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
8311 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8312 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8313 enum pipe pipe = crtc->pipe;
8315 /* pipesrc controls the size that is scaled from, which should
8316 * always be the user's requested size.
8318 I915_WRITE(PIPESRC(pipe),
8319 ((crtc_state->pipe_src_w - 1) << 16) |
8320 (crtc_state->pipe_src_h - 1));
8323 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
8325 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
8326 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8328 if (IS_GEN(dev_priv, 2))
8331 if (INTEL_GEN(dev_priv) >= 9 ||
8332 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
8333 return I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK_HSW;
8335 return I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK;
8338 static void intel_get_pipe_timings(struct intel_crtc *crtc,
8339 struct intel_crtc_state *pipe_config)
8341 struct drm_device *dev = crtc->base.dev;
8342 struct drm_i915_private *dev_priv = to_i915(dev);
8343 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
8346 tmp = I915_READ(HTOTAL(cpu_transcoder));
8347 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
8348 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
8350 if (!transcoder_is_dsi(cpu_transcoder)) {
8351 tmp = I915_READ(HBLANK(cpu_transcoder));
8352 pipe_config->base.adjusted_mode.crtc_hblank_start =
8354 pipe_config->base.adjusted_mode.crtc_hblank_end =
8355 ((tmp >> 16) & 0xffff) + 1;
8357 tmp = I915_READ(HSYNC(cpu_transcoder));
8358 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
8359 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
8361 tmp = I915_READ(VTOTAL(cpu_transcoder));
8362 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
8363 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
8365 if (!transcoder_is_dsi(cpu_transcoder)) {
8366 tmp = I915_READ(VBLANK(cpu_transcoder));
8367 pipe_config->base.adjusted_mode.crtc_vblank_start =
8369 pipe_config->base.adjusted_mode.crtc_vblank_end =
8370 ((tmp >> 16) & 0xffff) + 1;
8372 tmp = I915_READ(VSYNC(cpu_transcoder));
8373 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
8374 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
8376 if (intel_pipe_is_interlaced(pipe_config)) {
8377 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
8378 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
8379 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
8383 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
8384 struct intel_crtc_state *pipe_config)
8386 struct drm_device *dev = crtc->base.dev;
8387 struct drm_i915_private *dev_priv = to_i915(dev);
8390 tmp = I915_READ(PIPESRC(crtc->pipe));
8391 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
8392 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
8394 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
8395 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
8398 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
8399 struct intel_crtc_state *pipe_config)
8401 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
8402 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
8403 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
8404 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
8406 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
8407 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
8408 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
8409 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
8411 mode->flags = pipe_config->base.adjusted_mode.flags;
8412 mode->type = DRM_MODE_TYPE_DRIVER;
8414 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
8416 mode->hsync = drm_mode_hsync(mode);
8417 mode->vrefresh = drm_mode_vrefresh(mode);
8418 drm_mode_set_name(mode);
8421 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
8423 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8424 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8429 /* we keep both pipes enabled on 830 */
8430 if (IS_I830(dev_priv))
8431 pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
8433 if (crtc_state->double_wide)
8434 pipeconf |= PIPECONF_DOUBLE_WIDE;
8436 /* only g4x and later have fancy bpc/dither controls */
8437 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8438 IS_CHERRYVIEW(dev_priv)) {
8439 /* Bspec claims that we can't use dithering for 30bpp pipes. */
8440 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
8441 pipeconf |= PIPECONF_DITHER_EN |
8442 PIPECONF_DITHER_TYPE_SP;
8444 switch (crtc_state->pipe_bpp) {
8446 pipeconf |= PIPECONF_6BPC;
8449 pipeconf |= PIPECONF_8BPC;
8452 pipeconf |= PIPECONF_10BPC;
8455 /* Case prevented by intel_choose_pipe_bpp_dither. */
8460 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
8461 if (INTEL_GEN(dev_priv) < 4 ||
8462 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8463 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
8465 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
8467 pipeconf |= PIPECONF_PROGRESSIVE;
8470 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
8471 crtc_state->limited_color_range)
8472 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
8474 pipeconf |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
8476 I915_WRITE(PIPECONF(crtc->pipe), pipeconf);
8477 POSTING_READ(PIPECONF(crtc->pipe));
8480 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
8481 struct intel_crtc_state *crtc_state)
8483 struct drm_device *dev = crtc->base.dev;
8484 struct drm_i915_private *dev_priv = to_i915(dev);
8485 const struct intel_limit *limit;
8488 memset(&crtc_state->dpll_hw_state, 0,
8489 sizeof(crtc_state->dpll_hw_state));
8491 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8492 if (intel_panel_use_ssc(dev_priv)) {
8493 refclk = dev_priv->vbt.lvds_ssc_freq;
8494 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8497 limit = &intel_limits_i8xx_lvds;
8498 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
8499 limit = &intel_limits_i8xx_dvo;
8501 limit = &intel_limits_i8xx_dac;
8504 if (!crtc_state->clock_set &&
8505 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8506 refclk, NULL, &crtc_state->dpll)) {
8507 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8511 i8xx_compute_dpll(crtc, crtc_state, NULL);
8516 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
8517 struct intel_crtc_state *crtc_state)
8519 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8520 const struct intel_limit *limit;
8523 memset(&crtc_state->dpll_hw_state, 0,
8524 sizeof(crtc_state->dpll_hw_state));
8526 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8527 if (intel_panel_use_ssc(dev_priv)) {
8528 refclk = dev_priv->vbt.lvds_ssc_freq;
8529 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8532 if (intel_is_dual_link_lvds(dev_priv))
8533 limit = &intel_limits_g4x_dual_channel_lvds;
8535 limit = &intel_limits_g4x_single_channel_lvds;
8536 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
8537 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
8538 limit = &intel_limits_g4x_hdmi;
8539 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
8540 limit = &intel_limits_g4x_sdvo;
8542 /* The option is for other outputs */
8543 limit = &intel_limits_i9xx_sdvo;
8546 if (!crtc_state->clock_set &&
8547 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8548 refclk, NULL, &crtc_state->dpll)) {
8549 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8553 i9xx_compute_dpll(crtc, crtc_state, NULL);
8558 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
8559 struct intel_crtc_state *crtc_state)
8561 struct drm_device *dev = crtc->base.dev;
8562 struct drm_i915_private *dev_priv = to_i915(dev);
8563 const struct intel_limit *limit;
8566 memset(&crtc_state->dpll_hw_state, 0,
8567 sizeof(crtc_state->dpll_hw_state));
8569 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8570 if (intel_panel_use_ssc(dev_priv)) {
8571 refclk = dev_priv->vbt.lvds_ssc_freq;
8572 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8575 limit = &intel_limits_pineview_lvds;
8577 limit = &intel_limits_pineview_sdvo;
8580 if (!crtc_state->clock_set &&
8581 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8582 refclk, NULL, &crtc_state->dpll)) {
8583 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8587 i9xx_compute_dpll(crtc, crtc_state, NULL);
8592 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
8593 struct intel_crtc_state *crtc_state)
8595 struct drm_device *dev = crtc->base.dev;
8596 struct drm_i915_private *dev_priv = to_i915(dev);
8597 const struct intel_limit *limit;
8600 memset(&crtc_state->dpll_hw_state, 0,
8601 sizeof(crtc_state->dpll_hw_state));
8603 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8604 if (intel_panel_use_ssc(dev_priv)) {
8605 refclk = dev_priv->vbt.lvds_ssc_freq;
8606 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8609 limit = &intel_limits_i9xx_lvds;
8611 limit = &intel_limits_i9xx_sdvo;
8614 if (!crtc_state->clock_set &&
8615 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8616 refclk, NULL, &crtc_state->dpll)) {
8617 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8621 i9xx_compute_dpll(crtc, crtc_state, NULL);
8626 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
8627 struct intel_crtc_state *crtc_state)
8629 int refclk = 100000;
8630 const struct intel_limit *limit = &intel_limits_chv;
8632 memset(&crtc_state->dpll_hw_state, 0,
8633 sizeof(crtc_state->dpll_hw_state));
8635 if (!crtc_state->clock_set &&
8636 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8637 refclk, NULL, &crtc_state->dpll)) {
8638 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8642 chv_compute_dpll(crtc, crtc_state);
8647 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
8648 struct intel_crtc_state *crtc_state)
8650 int refclk = 100000;
8651 const struct intel_limit *limit = &intel_limits_vlv;
8653 memset(&crtc_state->dpll_hw_state, 0,
8654 sizeof(crtc_state->dpll_hw_state));
8656 if (!crtc_state->clock_set &&
8657 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8658 refclk, NULL, &crtc_state->dpll)) {
8659 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8663 vlv_compute_dpll(crtc, crtc_state);
8668 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
8670 if (IS_I830(dev_priv))
8673 return INTEL_GEN(dev_priv) >= 4 ||
8674 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
8677 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
8678 struct intel_crtc_state *pipe_config)
8680 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8683 if (!i9xx_has_pfit(dev_priv))
8686 tmp = I915_READ(PFIT_CONTROL);
8687 if (!(tmp & PFIT_ENABLE))
8690 /* Check whether the pfit is attached to our pipe. */
8691 if (INTEL_GEN(dev_priv) < 4) {
8692 if (crtc->pipe != PIPE_B)
8695 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
8699 pipe_config->gmch_pfit.control = tmp;
8700 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
8703 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
8704 struct intel_crtc_state *pipe_config)
8706 struct drm_device *dev = crtc->base.dev;
8707 struct drm_i915_private *dev_priv = to_i915(dev);
8708 enum pipe pipe = crtc->pipe;
8711 int refclk = 100000;
8713 /* In case of DSI, DPLL will not be used */
8714 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8717 vlv_dpio_get(dev_priv);
8718 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
8719 vlv_dpio_put(dev_priv);
8721 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
8722 clock.m2 = mdiv & DPIO_M2DIV_MASK;
8723 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
8724 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
8725 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
8727 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
8731 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
8732 struct intel_initial_plane_config *plane_config)
8734 struct drm_device *dev = crtc->base.dev;
8735 struct drm_i915_private *dev_priv = to_i915(dev);
8736 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8737 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
8739 u32 val, base, offset;
8740 int fourcc, pixel_format;
8741 unsigned int aligned_height;
8742 struct drm_framebuffer *fb;
8743 struct intel_framebuffer *intel_fb;
8745 if (!plane->get_hw_state(plane, &pipe))
8748 WARN_ON(pipe != crtc->pipe);
8750 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8752 DRM_DEBUG_KMS("failed to alloc fb\n");
8756 fb = &intel_fb->base;
8760 val = I915_READ(DSPCNTR(i9xx_plane));
8762 if (INTEL_GEN(dev_priv) >= 4) {
8763 if (val & DISPPLANE_TILED) {
8764 plane_config->tiling = I915_TILING_X;
8765 fb->modifier = I915_FORMAT_MOD_X_TILED;
8768 if (val & DISPPLANE_ROTATE_180)
8769 plane_config->rotation = DRM_MODE_ROTATE_180;
8772 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
8773 val & DISPPLANE_MIRROR)
8774 plane_config->rotation |= DRM_MODE_REFLECT_X;
8776 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
8777 fourcc = i9xx_format_to_fourcc(pixel_format);
8778 fb->format = drm_format_info(fourcc);
8780 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
8781 offset = I915_READ(DSPOFFSET(i9xx_plane));
8782 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8783 } else if (INTEL_GEN(dev_priv) >= 4) {
8784 if (plane_config->tiling)
8785 offset = I915_READ(DSPTILEOFF(i9xx_plane));
8787 offset = I915_READ(DSPLINOFF(i9xx_plane));
8788 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8790 base = I915_READ(DSPADDR(i9xx_plane));
8792 plane_config->base = base;
8794 val = I915_READ(PIPESRC(pipe));
8795 fb->width = ((val >> 16) & 0xfff) + 1;
8796 fb->height = ((val >> 0) & 0xfff) + 1;
8798 val = I915_READ(DSPSTRIDE(i9xx_plane));
8799 fb->pitches[0] = val & 0xffffffc0;
8801 aligned_height = intel_fb_align_height(fb, 0, fb->height);
8803 plane_config->size = fb->pitches[0] * aligned_height;
8805 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8806 crtc->base.name, plane->base.name, fb->width, fb->height,
8807 fb->format->cpp[0] * 8, base, fb->pitches[0],
8808 plane_config->size);
8810 plane_config->fb = intel_fb;
8813 static void chv_crtc_clock_get(struct intel_crtc *crtc,
8814 struct intel_crtc_state *pipe_config)
8816 struct drm_device *dev = crtc->base.dev;
8817 struct drm_i915_private *dev_priv = to_i915(dev);
8818 enum pipe pipe = crtc->pipe;
8819 enum dpio_channel port = vlv_pipe_to_channel(pipe);
8821 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
8822 int refclk = 100000;
8824 /* In case of DSI, DPLL will not be used */
8825 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8828 vlv_dpio_get(dev_priv);
8829 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
8830 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
8831 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
8832 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
8833 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
8834 vlv_dpio_put(dev_priv);
8836 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
8837 clock.m2 = (pll_dw0 & 0xff) << 22;
8838 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
8839 clock.m2 |= pll_dw2 & 0x3fffff;
8840 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
8841 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
8842 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
8844 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
8847 static enum intel_output_format
8848 bdw_get_pipemisc_output_format(struct intel_crtc *crtc)
8850 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8853 tmp = I915_READ(PIPEMISC(crtc->pipe));
8855 if (tmp & PIPEMISC_YUV420_ENABLE) {
8856 /* We support 4:2:0 in full blend mode only */
8857 WARN_ON((tmp & PIPEMISC_YUV420_MODE_FULL_BLEND) == 0);
8859 return INTEL_OUTPUT_FORMAT_YCBCR420;
8860 } else if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
8861 return INTEL_OUTPUT_FORMAT_YCBCR444;
8863 return INTEL_OUTPUT_FORMAT_RGB;
8867 static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state)
8869 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8870 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8871 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8872 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
8875 tmp = I915_READ(DSPCNTR(i9xx_plane));
8877 if (tmp & DISPPLANE_GAMMA_ENABLE)
8878 crtc_state->gamma_enable = true;
8880 if (!HAS_GMCH(dev_priv) &&
8881 tmp & DISPPLANE_PIPE_CSC_ENABLE)
8882 crtc_state->csc_enable = true;
8885 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
8886 struct intel_crtc_state *pipe_config)
8888 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8889 enum intel_display_power_domain power_domain;
8890 intel_wakeref_t wakeref;
8894 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
8895 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
8899 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
8900 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
8901 pipe_config->shared_dpll = NULL;
8902 pipe_config->master_transcoder = INVALID_TRANSCODER;
8906 tmp = I915_READ(PIPECONF(crtc->pipe));
8907 if (!(tmp & PIPECONF_ENABLE))
8910 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8911 IS_CHERRYVIEW(dev_priv)) {
8912 switch (tmp & PIPECONF_BPC_MASK) {
8914 pipe_config->pipe_bpp = 18;
8917 pipe_config->pipe_bpp = 24;
8919 case PIPECONF_10BPC:
8920 pipe_config->pipe_bpp = 30;
8927 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
8928 (tmp & PIPECONF_COLOR_RANGE_SELECT))
8929 pipe_config->limited_color_range = true;
8931 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_I9XX) >>
8932 PIPECONF_GAMMA_MODE_SHIFT;
8934 if (IS_CHERRYVIEW(dev_priv))
8935 pipe_config->cgm_mode = I915_READ(CGM_PIPE_MODE(crtc->pipe));
8937 i9xx_get_pipe_color_config(pipe_config);
8938 intel_color_get_config(pipe_config);
8940 if (INTEL_GEN(dev_priv) < 4)
8941 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
8943 intel_get_pipe_timings(crtc, pipe_config);
8944 intel_get_pipe_src_size(crtc, pipe_config);
8946 i9xx_get_pfit_config(crtc, pipe_config);
8948 if (INTEL_GEN(dev_priv) >= 4) {
8949 /* No way to read it out on pipes B and C */
8950 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
8951 tmp = dev_priv->chv_dpll_md[crtc->pipe];
8953 tmp = I915_READ(DPLL_MD(crtc->pipe));
8954 pipe_config->pixel_multiplier =
8955 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
8956 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
8957 pipe_config->dpll_hw_state.dpll_md = tmp;
8958 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
8959 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
8960 tmp = I915_READ(DPLL(crtc->pipe));
8961 pipe_config->pixel_multiplier =
8962 ((tmp & SDVO_MULTIPLIER_MASK)
8963 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
8965 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8966 * port and will be fixed up in the encoder->get_config
8968 pipe_config->pixel_multiplier = 1;
8970 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
8971 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
8972 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
8973 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
8975 /* Mask out read-only status bits. */
8976 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
8977 DPLL_PORTC_READY_MASK |
8978 DPLL_PORTB_READY_MASK);
8981 if (IS_CHERRYVIEW(dev_priv))
8982 chv_crtc_clock_get(crtc, pipe_config);
8983 else if (IS_VALLEYVIEW(dev_priv))
8984 vlv_crtc_clock_get(crtc, pipe_config);
8986 i9xx_crtc_clock_get(crtc, pipe_config);
8989 * Normally the dotclock is filled in by the encoder .get_config()
8990 * but in case the pipe is enabled w/o any ports we need a sane
8993 pipe_config->base.adjusted_mode.crtc_clock =
8994 pipe_config->port_clock / pipe_config->pixel_multiplier;
8999 intel_display_power_put(dev_priv, power_domain, wakeref);
9004 static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
9006 struct intel_encoder *encoder;
9009 bool has_lvds = false;
9010 bool has_cpu_edp = false;
9011 bool has_panel = false;
9012 bool has_ck505 = false;
9013 bool can_ssc = false;
9014 bool using_ssc_source = false;
9016 /* We need to take the global config into account */
9017 for_each_intel_encoder(&dev_priv->drm, encoder) {
9018 switch (encoder->type) {
9019 case INTEL_OUTPUT_LVDS:
9023 case INTEL_OUTPUT_EDP:
9025 if (encoder->port == PORT_A)
9033 if (HAS_PCH_IBX(dev_priv)) {
9034 has_ck505 = dev_priv->vbt.display_clock_mode;
9035 can_ssc = has_ck505;
9041 /* Check if any DPLLs are using the SSC source */
9042 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
9043 u32 temp = I915_READ(PCH_DPLL(i));
9045 if (!(temp & DPLL_VCO_ENABLE))
9048 if ((temp & PLL_REF_INPUT_MASK) ==
9049 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
9050 using_ssc_source = true;
9055 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
9056 has_panel, has_lvds, has_ck505, using_ssc_source);
9058 /* Ironlake: try to setup display ref clock before DPLL
9059 * enabling. This is only under driver's control after
9060 * PCH B stepping, previous chipset stepping should be
9061 * ignoring this setting.
9063 val = I915_READ(PCH_DREF_CONTROL);
9065 /* As we must carefully and slowly disable/enable each source in turn,
9066 * compute the final state we want first and check if we need to
9067 * make any changes at all.
9070 final &= ~DREF_NONSPREAD_SOURCE_MASK;
9072 final |= DREF_NONSPREAD_CK505_ENABLE;
9074 final |= DREF_NONSPREAD_SOURCE_ENABLE;
9076 final &= ~DREF_SSC_SOURCE_MASK;
9077 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9078 final &= ~DREF_SSC1_ENABLE;
9081 final |= DREF_SSC_SOURCE_ENABLE;
9083 if (intel_panel_use_ssc(dev_priv) && can_ssc)
9084 final |= DREF_SSC1_ENABLE;
9087 if (intel_panel_use_ssc(dev_priv) && can_ssc)
9088 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
9090 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
9092 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9093 } else if (using_ssc_source) {
9094 final |= DREF_SSC_SOURCE_ENABLE;
9095 final |= DREF_SSC1_ENABLE;
9101 /* Always enable nonspread source */
9102 val &= ~DREF_NONSPREAD_SOURCE_MASK;
9105 val |= DREF_NONSPREAD_CK505_ENABLE;
9107 val |= DREF_NONSPREAD_SOURCE_ENABLE;
9110 val &= ~DREF_SSC_SOURCE_MASK;
9111 val |= DREF_SSC_SOURCE_ENABLE;
9113 /* SSC must be turned on before enabling the CPU output */
9114 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
9115 DRM_DEBUG_KMS("Using SSC on panel\n");
9116 val |= DREF_SSC1_ENABLE;
9118 val &= ~DREF_SSC1_ENABLE;
9120 /* Get SSC going before enabling the outputs */
9121 I915_WRITE(PCH_DREF_CONTROL, val);
9122 POSTING_READ(PCH_DREF_CONTROL);
9125 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9127 /* Enable CPU source on CPU attached eDP */
9129 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
9130 DRM_DEBUG_KMS("Using SSC on eDP\n");
9131 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
9133 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
9135 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9137 I915_WRITE(PCH_DREF_CONTROL, val);
9138 POSTING_READ(PCH_DREF_CONTROL);
9141 DRM_DEBUG_KMS("Disabling CPU source output\n");
9143 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9145 /* Turn off CPU output */
9146 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9148 I915_WRITE(PCH_DREF_CONTROL, val);
9149 POSTING_READ(PCH_DREF_CONTROL);
9152 if (!using_ssc_source) {
9153 DRM_DEBUG_KMS("Disabling SSC source\n");
9155 /* Turn off the SSC source */
9156 val &= ~DREF_SSC_SOURCE_MASK;
9157 val |= DREF_SSC_SOURCE_DISABLE;
9160 val &= ~DREF_SSC1_ENABLE;
9162 I915_WRITE(PCH_DREF_CONTROL, val);
9163 POSTING_READ(PCH_DREF_CONTROL);
9168 BUG_ON(val != final);
9171 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
9175 tmp = I915_READ(SOUTH_CHICKEN2);
9176 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
9177 I915_WRITE(SOUTH_CHICKEN2, tmp);
9179 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
9180 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
9181 DRM_ERROR("FDI mPHY reset assert timeout\n");
9183 tmp = I915_READ(SOUTH_CHICKEN2);
9184 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
9185 I915_WRITE(SOUTH_CHICKEN2, tmp);
9187 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
9188 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
9189 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
9192 /* WaMPhyProgramming:hsw */
9193 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
9197 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
9198 tmp &= ~(0xFF << 24);
9199 tmp |= (0x12 << 24);
9200 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
9202 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
9204 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
9206 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
9208 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
9210 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
9211 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9212 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
9214 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
9215 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9216 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
9218 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
9221 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
9223 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
9226 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
9228 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
9231 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
9233 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
9236 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
9238 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
9239 tmp &= ~(0xFF << 16);
9240 tmp |= (0x1C << 16);
9241 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
9243 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
9244 tmp &= ~(0xFF << 16);
9245 tmp |= (0x1C << 16);
9246 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
9248 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
9250 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
9252 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
9254 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
9256 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
9257 tmp &= ~(0xF << 28);
9259 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
9261 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
9262 tmp &= ~(0xF << 28);
9264 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
9267 /* Implements 3 different sequences from BSpec chapter "Display iCLK
9268 * Programming" based on the parameters passed:
9269 * - Sequence to enable CLKOUT_DP
9270 * - Sequence to enable CLKOUT_DP without spread
9271 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
9273 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
9274 bool with_spread, bool with_fdi)
9278 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
9280 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
9281 with_fdi, "LP PCH doesn't have FDI\n"))
9284 mutex_lock(&dev_priv->sb_lock);
9286 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9287 tmp &= ~SBI_SSCCTL_DISABLE;
9288 tmp |= SBI_SSCCTL_PATHALT;
9289 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9294 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9295 tmp &= ~SBI_SSCCTL_PATHALT;
9296 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9299 lpt_reset_fdi_mphy(dev_priv);
9300 lpt_program_fdi_mphy(dev_priv);
9304 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9305 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9306 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9307 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9309 mutex_unlock(&dev_priv->sb_lock);
9312 /* Sequence to disable CLKOUT_DP */
9313 void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
9317 mutex_lock(&dev_priv->sb_lock);
9319 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9320 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9321 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9322 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9324 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9325 if (!(tmp & SBI_SSCCTL_DISABLE)) {
9326 if (!(tmp & SBI_SSCCTL_PATHALT)) {
9327 tmp |= SBI_SSCCTL_PATHALT;
9328 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9331 tmp |= SBI_SSCCTL_DISABLE;
9332 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9335 mutex_unlock(&dev_priv->sb_lock);
9338 #define BEND_IDX(steps) ((50 + (steps)) / 5)
9340 static const u16 sscdivintphase[] = {
9341 [BEND_IDX( 50)] = 0x3B23,
9342 [BEND_IDX( 45)] = 0x3B23,
9343 [BEND_IDX( 40)] = 0x3C23,
9344 [BEND_IDX( 35)] = 0x3C23,
9345 [BEND_IDX( 30)] = 0x3D23,
9346 [BEND_IDX( 25)] = 0x3D23,
9347 [BEND_IDX( 20)] = 0x3E23,
9348 [BEND_IDX( 15)] = 0x3E23,
9349 [BEND_IDX( 10)] = 0x3F23,
9350 [BEND_IDX( 5)] = 0x3F23,
9351 [BEND_IDX( 0)] = 0x0025,
9352 [BEND_IDX( -5)] = 0x0025,
9353 [BEND_IDX(-10)] = 0x0125,
9354 [BEND_IDX(-15)] = 0x0125,
9355 [BEND_IDX(-20)] = 0x0225,
9356 [BEND_IDX(-25)] = 0x0225,
9357 [BEND_IDX(-30)] = 0x0325,
9358 [BEND_IDX(-35)] = 0x0325,
9359 [BEND_IDX(-40)] = 0x0425,
9360 [BEND_IDX(-45)] = 0x0425,
9361 [BEND_IDX(-50)] = 0x0525,
9366 * steps -50 to 50 inclusive, in steps of 5
9367 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
9368 * change in clock period = -(steps / 10) * 5.787 ps
9370 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
9373 int idx = BEND_IDX(steps);
9375 if (WARN_ON(steps % 5 != 0))
9378 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
9381 mutex_lock(&dev_priv->sb_lock);
9383 if (steps % 10 != 0)
9387 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
9389 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
9391 tmp |= sscdivintphase[idx];
9392 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
9394 mutex_unlock(&dev_priv->sb_lock);
9399 static bool spll_uses_pch_ssc(struct drm_i915_private *dev_priv)
9401 u32 fuse_strap = I915_READ(FUSE_STRAP);
9402 u32 ctl = I915_READ(SPLL_CTL);
9404 if ((ctl & SPLL_PLL_ENABLE) == 0)
9407 if ((ctl & SPLL_REF_MASK) == SPLL_REF_MUXED_SSC &&
9408 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9411 if (IS_BROADWELL(dev_priv) &&
9412 (ctl & SPLL_REF_MASK) == SPLL_REF_PCH_SSC_BDW)
9418 static bool wrpll_uses_pch_ssc(struct drm_i915_private *dev_priv,
9419 enum intel_dpll_id id)
9421 u32 fuse_strap = I915_READ(FUSE_STRAP);
9422 u32 ctl = I915_READ(WRPLL_CTL(id));
9424 if ((ctl & WRPLL_PLL_ENABLE) == 0)
9427 if ((ctl & WRPLL_REF_MASK) == WRPLL_REF_PCH_SSC)
9430 if ((IS_BROADWELL(dev_priv) || IS_HSW_ULT(dev_priv)) &&
9431 (ctl & WRPLL_REF_MASK) == WRPLL_REF_MUXED_SSC_BDW &&
9432 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9438 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
9440 struct intel_encoder *encoder;
9441 bool has_fdi = false;
9443 for_each_intel_encoder(&dev_priv->drm, encoder) {
9444 switch (encoder->type) {
9445 case INTEL_OUTPUT_ANALOG:
9454 * The BIOS may have decided to use the PCH SSC
9455 * reference so we must not disable it until the
9456 * relevant PLLs have stopped relying on it. We'll
9457 * just leave the PCH SSC reference enabled in case
9458 * any active PLL is using it. It will get disabled
9459 * after runtime suspend if we don't have FDI.
9461 * TODO: Move the whole reference clock handling
9462 * to the modeset sequence proper so that we can
9463 * actually enable/disable/reconfigure these things
9464 * safely. To do that we need to introduce a real
9465 * clock hierarchy. That would also allow us to do
9466 * clock bending finally.
9468 dev_priv->pch_ssc_use = 0;
9470 if (spll_uses_pch_ssc(dev_priv)) {
9471 DRM_DEBUG_KMS("SPLL using PCH SSC\n");
9472 dev_priv->pch_ssc_use |= BIT(DPLL_ID_SPLL);
9475 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL1)) {
9476 DRM_DEBUG_KMS("WRPLL1 using PCH SSC\n");
9477 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL1);
9480 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL2)) {
9481 DRM_DEBUG_KMS("WRPLL2 using PCH SSC\n");
9482 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL2);
9485 if (dev_priv->pch_ssc_use)
9489 lpt_bend_clkout_dp(dev_priv, 0);
9490 lpt_enable_clkout_dp(dev_priv, true, true);
9492 lpt_disable_clkout_dp(dev_priv);
9497 * Initialize reference clocks when the driver loads
9499 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
9501 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
9502 ironlake_init_pch_refclk(dev_priv);
9503 else if (HAS_PCH_LPT(dev_priv))
9504 lpt_init_pch_refclk(dev_priv);
9507 static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
9509 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9510 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9511 enum pipe pipe = crtc->pipe;
9516 switch (crtc_state->pipe_bpp) {
9518 val |= PIPECONF_6BPC;
9521 val |= PIPECONF_8BPC;
9524 val |= PIPECONF_10BPC;
9527 val |= PIPECONF_12BPC;
9530 /* Case prevented by intel_choose_pipe_bpp_dither. */
9534 if (crtc_state->dither)
9535 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
9537 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
9538 val |= PIPECONF_INTERLACED_ILK;
9540 val |= PIPECONF_PROGRESSIVE;
9543 * This would end up with an odd purple hue over
9544 * the entire display. Make sure we don't do it.
9546 WARN_ON(crtc_state->limited_color_range &&
9547 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
9549 if (crtc_state->limited_color_range)
9550 val |= PIPECONF_COLOR_RANGE_SELECT;
9552 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
9553 val |= PIPECONF_OUTPUT_COLORSPACE_YUV709;
9555 val |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
9557 I915_WRITE(PIPECONF(pipe), val);
9558 POSTING_READ(PIPECONF(pipe));
9561 static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state)
9563 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9564 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9565 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
9568 if (IS_HASWELL(dev_priv) && crtc_state->dither)
9569 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
9571 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
9572 val |= PIPECONF_INTERLACED_ILK;
9574 val |= PIPECONF_PROGRESSIVE;
9576 if (IS_HASWELL(dev_priv) &&
9577 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
9578 val |= PIPECONF_OUTPUT_COLORSPACE_YUV_HSW;
9580 I915_WRITE(PIPECONF(cpu_transcoder), val);
9581 POSTING_READ(PIPECONF(cpu_transcoder));
9584 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state)
9586 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9587 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9590 switch (crtc_state->pipe_bpp) {
9592 val |= PIPEMISC_DITHER_6_BPC;
9595 val |= PIPEMISC_DITHER_8_BPC;
9598 val |= PIPEMISC_DITHER_10_BPC;
9601 val |= PIPEMISC_DITHER_12_BPC;
9604 MISSING_CASE(crtc_state->pipe_bpp);
9608 if (crtc_state->dither)
9609 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
9611 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
9612 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
9613 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
9615 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
9616 val |= PIPEMISC_YUV420_ENABLE |
9617 PIPEMISC_YUV420_MODE_FULL_BLEND;
9619 if (INTEL_GEN(dev_priv) >= 11 &&
9620 (crtc_state->active_planes & ~(icl_hdr_plane_mask() |
9621 BIT(PLANE_CURSOR))) == 0)
9622 val |= PIPEMISC_HDR_MODE_PRECISION;
9624 I915_WRITE(PIPEMISC(crtc->pipe), val);
9627 int bdw_get_pipemisc_bpp(struct intel_crtc *crtc)
9629 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9632 tmp = I915_READ(PIPEMISC(crtc->pipe));
9634 switch (tmp & PIPEMISC_DITHER_BPC_MASK) {
9635 case PIPEMISC_DITHER_6_BPC:
9637 case PIPEMISC_DITHER_8_BPC:
9639 case PIPEMISC_DITHER_10_BPC:
9641 case PIPEMISC_DITHER_12_BPC:
9649 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
9652 * Account for spread spectrum to avoid
9653 * oversubscribing the link. Max center spread
9654 * is 2.5%; use 5% for safety's sake.
9656 u32 bps = target_clock * bpp * 21 / 20;
9657 return DIV_ROUND_UP(bps, link_bw * 8);
9660 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
9662 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
9665 static void ironlake_compute_dpll(struct intel_crtc *crtc,
9666 struct intel_crtc_state *crtc_state,
9667 struct dpll *reduced_clock)
9669 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9673 /* Enable autotuning of the PLL clock (if permissible) */
9675 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9676 if ((intel_panel_use_ssc(dev_priv) &&
9677 dev_priv->vbt.lvds_ssc_freq == 100000) ||
9678 (HAS_PCH_IBX(dev_priv) &&
9679 intel_is_dual_link_lvds(dev_priv)))
9681 } else if (crtc_state->sdvo_tv_clock) {
9685 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
9687 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
9690 if (reduced_clock) {
9691 fp2 = i9xx_dpll_compute_fp(reduced_clock);
9693 if (reduced_clock->m < factor * reduced_clock->n)
9701 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
9702 dpll |= DPLLB_MODE_LVDS;
9704 dpll |= DPLLB_MODE_DAC_SERIAL;
9706 dpll |= (crtc_state->pixel_multiplier - 1)
9707 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
9709 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
9710 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
9711 dpll |= DPLL_SDVO_HIGH_SPEED;
9713 if (intel_crtc_has_dp_encoder(crtc_state))
9714 dpll |= DPLL_SDVO_HIGH_SPEED;
9717 * The high speed IO clock is only really required for
9718 * SDVO/HDMI/DP, but we also enable it for CRT to make it
9719 * possible to share the DPLL between CRT and HDMI. Enabling
9720 * the clock needlessly does no real harm, except use up a
9721 * bit of power potentially.
9723 * We'll limit this to IVB with 3 pipes, since it has only two
9724 * DPLLs and so DPLL sharing is the only way to get three pipes
9725 * driving PCH ports at the same time. On SNB we could do this,
9726 * and potentially avoid enabling the second DPLL, but it's not
9727 * clear if it''s a win or loss power wise. No point in doing
9728 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
9730 if (INTEL_NUM_PIPES(dev_priv) == 3 &&
9731 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
9732 dpll |= DPLL_SDVO_HIGH_SPEED;
9734 /* compute bitmask from p1 value */
9735 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
9737 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
9739 switch (crtc_state->dpll.p2) {
9741 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
9744 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
9747 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
9750 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
9754 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
9755 intel_panel_use_ssc(dev_priv))
9756 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
9758 dpll |= PLL_REF_INPUT_DREFCLK;
9760 dpll |= DPLL_VCO_ENABLE;
9762 crtc_state->dpll_hw_state.dpll = dpll;
9763 crtc_state->dpll_hw_state.fp0 = fp;
9764 crtc_state->dpll_hw_state.fp1 = fp2;
9767 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
9768 struct intel_crtc_state *crtc_state)
9770 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9771 struct intel_atomic_state *state =
9772 to_intel_atomic_state(crtc_state->base.state);
9773 const struct intel_limit *limit;
9774 int refclk = 120000;
9776 memset(&crtc_state->dpll_hw_state, 0,
9777 sizeof(crtc_state->dpll_hw_state));
9779 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
9780 if (!crtc_state->has_pch_encoder)
9783 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9784 if (intel_panel_use_ssc(dev_priv)) {
9785 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
9786 dev_priv->vbt.lvds_ssc_freq);
9787 refclk = dev_priv->vbt.lvds_ssc_freq;
9790 if (intel_is_dual_link_lvds(dev_priv)) {
9791 if (refclk == 100000)
9792 limit = &intel_limits_ironlake_dual_lvds_100m;
9794 limit = &intel_limits_ironlake_dual_lvds;
9796 if (refclk == 100000)
9797 limit = &intel_limits_ironlake_single_lvds_100m;
9799 limit = &intel_limits_ironlake_single_lvds;
9802 limit = &intel_limits_ironlake_dac;
9805 if (!crtc_state->clock_set &&
9806 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
9807 refclk, NULL, &crtc_state->dpll)) {
9808 DRM_ERROR("Couldn't find PLL settings for mode!\n");
9812 ironlake_compute_dpll(crtc, crtc_state, NULL);
9814 if (!intel_reserve_shared_dplls(state, crtc, NULL)) {
9815 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
9816 pipe_name(crtc->pipe));
9823 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
9824 struct intel_link_m_n *m_n)
9826 struct drm_device *dev = crtc->base.dev;
9827 struct drm_i915_private *dev_priv = to_i915(dev);
9828 enum pipe pipe = crtc->pipe;
9830 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
9831 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
9832 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
9834 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
9835 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
9836 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9839 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
9840 enum transcoder transcoder,
9841 struct intel_link_m_n *m_n,
9842 struct intel_link_m_n *m2_n2)
9844 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9845 enum pipe pipe = crtc->pipe;
9847 if (INTEL_GEN(dev_priv) >= 5) {
9848 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
9849 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
9850 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
9852 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
9853 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
9854 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9856 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
9857 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
9858 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
9859 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
9861 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
9862 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
9863 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9866 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
9867 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
9868 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
9870 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
9871 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
9872 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9876 void intel_dp_get_m_n(struct intel_crtc *crtc,
9877 struct intel_crtc_state *pipe_config)
9879 if (pipe_config->has_pch_encoder)
9880 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
9882 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
9883 &pipe_config->dp_m_n,
9884 &pipe_config->dp_m2_n2);
9887 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
9888 struct intel_crtc_state *pipe_config)
9890 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
9891 &pipe_config->fdi_m_n, NULL);
9894 static void skylake_get_pfit_config(struct intel_crtc *crtc,
9895 struct intel_crtc_state *pipe_config)
9897 struct drm_device *dev = crtc->base.dev;
9898 struct drm_i915_private *dev_priv = to_i915(dev);
9899 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
9904 /* find scaler attached to this pipe */
9905 for (i = 0; i < crtc->num_scalers; i++) {
9906 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
9907 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
9909 pipe_config->pch_pfit.enabled = true;
9910 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
9911 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
9912 scaler_state->scalers[i].in_use = true;
9917 scaler_state->scaler_id = id;
9919 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
9921 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
9926 skylake_get_initial_plane_config(struct intel_crtc *crtc,
9927 struct intel_initial_plane_config *plane_config)
9929 struct drm_device *dev = crtc->base.dev;
9930 struct drm_i915_private *dev_priv = to_i915(dev);
9931 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
9932 enum plane_id plane_id = plane->id;
9934 u32 val, base, offset, stride_mult, tiling, alpha;
9935 int fourcc, pixel_format;
9936 unsigned int aligned_height;
9937 struct drm_framebuffer *fb;
9938 struct intel_framebuffer *intel_fb;
9940 if (!plane->get_hw_state(plane, &pipe))
9943 WARN_ON(pipe != crtc->pipe);
9945 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9947 DRM_DEBUG_KMS("failed to alloc fb\n");
9951 fb = &intel_fb->base;
9955 val = I915_READ(PLANE_CTL(pipe, plane_id));
9957 if (INTEL_GEN(dev_priv) >= 11)
9958 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
9960 pixel_format = val & PLANE_CTL_FORMAT_MASK;
9962 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
9963 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
9964 alpha &= PLANE_COLOR_ALPHA_MASK;
9966 alpha = val & PLANE_CTL_ALPHA_MASK;
9969 fourcc = skl_format_to_fourcc(pixel_format,
9970 val & PLANE_CTL_ORDER_RGBX, alpha);
9971 fb->format = drm_format_info(fourcc);
9973 tiling = val & PLANE_CTL_TILED_MASK;
9975 case PLANE_CTL_TILED_LINEAR:
9976 fb->modifier = DRM_FORMAT_MOD_LINEAR;
9978 case PLANE_CTL_TILED_X:
9979 plane_config->tiling = I915_TILING_X;
9980 fb->modifier = I915_FORMAT_MOD_X_TILED;
9982 case PLANE_CTL_TILED_Y:
9983 plane_config->tiling = I915_TILING_Y;
9984 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
9985 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
9987 fb->modifier = I915_FORMAT_MOD_Y_TILED;
9989 case PLANE_CTL_TILED_YF:
9990 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
9991 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
9993 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
9996 MISSING_CASE(tiling);
10001 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
10002 * while i915 HW rotation is clockwise, thats why this swapping.
10004 switch (val & PLANE_CTL_ROTATE_MASK) {
10005 case PLANE_CTL_ROTATE_0:
10006 plane_config->rotation = DRM_MODE_ROTATE_0;
10008 case PLANE_CTL_ROTATE_90:
10009 plane_config->rotation = DRM_MODE_ROTATE_270;
10011 case PLANE_CTL_ROTATE_180:
10012 plane_config->rotation = DRM_MODE_ROTATE_180;
10014 case PLANE_CTL_ROTATE_270:
10015 plane_config->rotation = DRM_MODE_ROTATE_90;
10019 if (INTEL_GEN(dev_priv) >= 10 &&
10020 val & PLANE_CTL_FLIP_HORIZONTAL)
10021 plane_config->rotation |= DRM_MODE_REFLECT_X;
10023 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
10024 plane_config->base = base;
10026 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
10028 val = I915_READ(PLANE_SIZE(pipe, plane_id));
10029 fb->height = ((val >> 16) & 0xffff) + 1;
10030 fb->width = ((val >> 0) & 0xffff) + 1;
10032 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
10033 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
10034 fb->pitches[0] = (val & 0x3ff) * stride_mult;
10036 aligned_height = intel_fb_align_height(fb, 0, fb->height);
10038 plane_config->size = fb->pitches[0] * aligned_height;
10040 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
10041 crtc->base.name, plane->base.name, fb->width, fb->height,
10042 fb->format->cpp[0] * 8, base, fb->pitches[0],
10043 plane_config->size);
10045 plane_config->fb = intel_fb;
10052 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
10053 struct intel_crtc_state *pipe_config)
10055 struct drm_device *dev = crtc->base.dev;
10056 struct drm_i915_private *dev_priv = to_i915(dev);
10059 tmp = I915_READ(PF_CTL(crtc->pipe));
10061 if (tmp & PF_ENABLE) {
10062 pipe_config->pch_pfit.enabled = true;
10063 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
10064 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
10066 /* We currently do not free assignements of panel fitters on
10067 * ivb/hsw (since we don't use the higher upscaling modes which
10068 * differentiates them) so just WARN about this case for now. */
10069 if (IS_GEN(dev_priv, 7)) {
10070 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
10071 PF_PIPE_SEL_IVB(crtc->pipe));
10076 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
10077 struct intel_crtc_state *pipe_config)
10079 struct drm_device *dev = crtc->base.dev;
10080 struct drm_i915_private *dev_priv = to_i915(dev);
10081 enum intel_display_power_domain power_domain;
10082 intel_wakeref_t wakeref;
10086 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
10087 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10091 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
10092 pipe_config->shared_dpll = NULL;
10093 pipe_config->master_transcoder = INVALID_TRANSCODER;
10096 tmp = I915_READ(PIPECONF(crtc->pipe));
10097 if (!(tmp & PIPECONF_ENABLE))
10100 switch (tmp & PIPECONF_BPC_MASK) {
10101 case PIPECONF_6BPC:
10102 pipe_config->pipe_bpp = 18;
10104 case PIPECONF_8BPC:
10105 pipe_config->pipe_bpp = 24;
10107 case PIPECONF_10BPC:
10108 pipe_config->pipe_bpp = 30;
10110 case PIPECONF_12BPC:
10111 pipe_config->pipe_bpp = 36;
10117 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
10118 pipe_config->limited_color_range = true;
10120 switch (tmp & PIPECONF_OUTPUT_COLORSPACE_MASK) {
10121 case PIPECONF_OUTPUT_COLORSPACE_YUV601:
10122 case PIPECONF_OUTPUT_COLORSPACE_YUV709:
10123 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
10126 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
10130 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_ILK) >>
10131 PIPECONF_GAMMA_MODE_SHIFT;
10133 pipe_config->csc_mode = I915_READ(PIPE_CSC_MODE(crtc->pipe));
10135 i9xx_get_pipe_color_config(pipe_config);
10136 intel_color_get_config(pipe_config);
10138 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
10139 struct intel_shared_dpll *pll;
10140 enum intel_dpll_id pll_id;
10142 pipe_config->has_pch_encoder = true;
10144 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
10145 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
10146 FDI_DP_PORT_WIDTH_SHIFT) + 1;
10148 ironlake_get_fdi_m_n_config(crtc, pipe_config);
10150 if (HAS_PCH_IBX(dev_priv)) {
10152 * The pipe->pch transcoder and pch transcoder->pll
10153 * mapping is fixed.
10155 pll_id = (enum intel_dpll_id) crtc->pipe;
10157 tmp = I915_READ(PCH_DPLL_SEL);
10158 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
10159 pll_id = DPLL_ID_PCH_PLL_B;
10161 pll_id= DPLL_ID_PCH_PLL_A;
10164 pipe_config->shared_dpll =
10165 intel_get_shared_dpll_by_id(dev_priv, pll_id);
10166 pll = pipe_config->shared_dpll;
10168 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
10169 &pipe_config->dpll_hw_state));
10171 tmp = pipe_config->dpll_hw_state.dpll;
10172 pipe_config->pixel_multiplier =
10173 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
10174 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
10176 ironlake_pch_clock_get(crtc, pipe_config);
10178 pipe_config->pixel_multiplier = 1;
10181 intel_get_pipe_timings(crtc, pipe_config);
10182 intel_get_pipe_src_size(crtc, pipe_config);
10184 ironlake_get_pfit_config(crtc, pipe_config);
10189 intel_display_power_put(dev_priv, power_domain, wakeref);
10193 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
10194 struct intel_crtc_state *crtc_state)
10196 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10197 struct intel_atomic_state *state =
10198 to_intel_atomic_state(crtc_state->base.state);
10200 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) ||
10201 INTEL_GEN(dev_priv) >= 11) {
10202 struct intel_encoder *encoder =
10203 intel_get_crtc_new_encoder(state, crtc_state);
10205 if (!intel_reserve_shared_dplls(state, crtc, encoder)) {
10206 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
10207 pipe_name(crtc->pipe));
10215 static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
10217 struct intel_crtc_state *pipe_config)
10219 enum intel_dpll_id id;
10222 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
10223 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
10225 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
10228 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10231 static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
10233 struct intel_crtc_state *pipe_config)
10235 enum phy phy = intel_port_to_phy(dev_priv, port);
10236 enum icl_port_dpll_id port_dpll_id;
10237 enum intel_dpll_id id;
10240 if (intel_phy_is_combo(dev_priv, phy)) {
10241 temp = I915_READ(ICL_DPCLKA_CFGCR0) &
10242 ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
10243 id = temp >> ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy);
10244 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10245 } else if (intel_phy_is_tc(dev_priv, phy)) {
10246 u32 clk_sel = I915_READ(DDI_CLK_SEL(port)) & DDI_CLK_SEL_MASK;
10248 if (clk_sel == DDI_CLK_SEL_MG) {
10249 id = icl_tc_port_to_pll_id(intel_port_to_tc(dev_priv,
10251 port_dpll_id = ICL_PORT_DPLL_MG_PHY;
10253 WARN_ON(clk_sel < DDI_CLK_SEL_TBT_162);
10254 id = DPLL_ID_ICL_TBTPLL;
10255 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10258 WARN(1, "Invalid port %x\n", port);
10262 pipe_config->icl_port_dplls[port_dpll_id].pll =
10263 intel_get_shared_dpll_by_id(dev_priv, id);
10265 icl_set_active_port_dpll(pipe_config, port_dpll_id);
10268 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
10270 struct intel_crtc_state *pipe_config)
10272 enum intel_dpll_id id;
10276 id = DPLL_ID_SKL_DPLL0;
10279 id = DPLL_ID_SKL_DPLL1;
10282 id = DPLL_ID_SKL_DPLL2;
10285 DRM_ERROR("Incorrect port type\n");
10289 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10292 static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
10294 struct intel_crtc_state *pipe_config)
10296 enum intel_dpll_id id;
10299 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
10300 id = temp >> (port * 3 + 1);
10302 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
10305 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10308 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
10310 struct intel_crtc_state *pipe_config)
10312 enum intel_dpll_id id;
10313 u32 ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
10315 switch (ddi_pll_sel) {
10316 case PORT_CLK_SEL_WRPLL1:
10317 id = DPLL_ID_WRPLL1;
10319 case PORT_CLK_SEL_WRPLL2:
10320 id = DPLL_ID_WRPLL2;
10322 case PORT_CLK_SEL_SPLL:
10325 case PORT_CLK_SEL_LCPLL_810:
10326 id = DPLL_ID_LCPLL_810;
10328 case PORT_CLK_SEL_LCPLL_1350:
10329 id = DPLL_ID_LCPLL_1350;
10331 case PORT_CLK_SEL_LCPLL_2700:
10332 id = DPLL_ID_LCPLL_2700;
10335 MISSING_CASE(ddi_pll_sel);
10337 case PORT_CLK_SEL_NONE:
10341 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10344 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
10345 struct intel_crtc_state *pipe_config,
10346 u64 *power_domain_mask,
10347 intel_wakeref_t *wakerefs)
10349 struct drm_device *dev = crtc->base.dev;
10350 struct drm_i915_private *dev_priv = to_i915(dev);
10351 enum intel_display_power_domain power_domain;
10352 unsigned long panel_transcoder_mask = 0;
10353 unsigned long enabled_panel_transcoders = 0;
10354 enum transcoder panel_transcoder;
10355 intel_wakeref_t wf;
10358 if (INTEL_GEN(dev_priv) >= 11)
10359 panel_transcoder_mask |=
10360 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
10362 if (HAS_TRANSCODER_EDP(dev_priv))
10363 panel_transcoder_mask |= BIT(TRANSCODER_EDP);
10366 * The pipe->transcoder mapping is fixed with the exception of the eDP
10367 * and DSI transcoders handled below.
10369 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
10372 * XXX: Do intel_display_power_get_if_enabled before reading this (for
10373 * consistency and less surprising code; it's in always on power).
10375 for_each_set_bit(panel_transcoder,
10376 &panel_transcoder_mask,
10377 ARRAY_SIZE(INTEL_INFO(dev_priv)->trans_offsets)) {
10378 bool force_thru = false;
10379 enum pipe trans_pipe;
10381 tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder));
10382 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
10386 * Log all enabled ones, only use the first one.
10388 * FIXME: This won't work for two separate DSI displays.
10390 enabled_panel_transcoders |= BIT(panel_transcoder);
10391 if (enabled_panel_transcoders != BIT(panel_transcoder))
10394 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
10396 WARN(1, "unknown pipe linked to transcoder %s\n",
10397 transcoder_name(panel_transcoder));
10399 case TRANS_DDI_EDP_INPUT_A_ONOFF:
10402 case TRANS_DDI_EDP_INPUT_A_ON:
10403 trans_pipe = PIPE_A;
10405 case TRANS_DDI_EDP_INPUT_B_ONOFF:
10406 trans_pipe = PIPE_B;
10408 case TRANS_DDI_EDP_INPUT_C_ONOFF:
10409 trans_pipe = PIPE_C;
10413 if (trans_pipe == crtc->pipe) {
10414 pipe_config->cpu_transcoder = panel_transcoder;
10415 pipe_config->pch_pfit.force_thru = force_thru;
10420 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
10422 WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
10423 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
10425 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
10426 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
10428 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10432 wakerefs[power_domain] = wf;
10433 *power_domain_mask |= BIT_ULL(power_domain);
10435 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
10437 return tmp & PIPECONF_ENABLE;
10440 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
10441 struct intel_crtc_state *pipe_config,
10442 u64 *power_domain_mask,
10443 intel_wakeref_t *wakerefs)
10445 struct drm_device *dev = crtc->base.dev;
10446 struct drm_i915_private *dev_priv = to_i915(dev);
10447 enum intel_display_power_domain power_domain;
10448 enum transcoder cpu_transcoder;
10449 intel_wakeref_t wf;
10453 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
10454 if (port == PORT_A)
10455 cpu_transcoder = TRANSCODER_DSI_A;
10457 cpu_transcoder = TRANSCODER_DSI_C;
10459 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
10460 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
10462 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10466 wakerefs[power_domain] = wf;
10467 *power_domain_mask |= BIT_ULL(power_domain);
10470 * The PLL needs to be enabled with a valid divider
10471 * configuration, otherwise accessing DSI registers will hang
10472 * the machine. See BSpec North Display Engine
10473 * registers/MIPI[BXT]. We can break out here early, since we
10474 * need the same DSI PLL to be enabled for both DSI ports.
10476 if (!bxt_dsi_pll_is_enabled(dev_priv))
10479 /* XXX: this works for video mode only */
10480 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
10481 if (!(tmp & DPI_ENABLE))
10484 tmp = I915_READ(MIPI_CTRL(port));
10485 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
10488 pipe_config->cpu_transcoder = cpu_transcoder;
10492 return transcoder_is_dsi(pipe_config->cpu_transcoder);
10495 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
10496 struct intel_crtc_state *pipe_config)
10498 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10499 struct intel_shared_dpll *pll;
10503 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
10505 if (INTEL_GEN(dev_priv) >= 12)
10506 port = TGL_TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
10508 port = TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
10510 if (INTEL_GEN(dev_priv) >= 11)
10511 icelake_get_ddi_pll(dev_priv, port, pipe_config);
10512 else if (IS_CANNONLAKE(dev_priv))
10513 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
10514 else if (IS_GEN9_BC(dev_priv))
10515 skylake_get_ddi_pll(dev_priv, port, pipe_config);
10516 else if (IS_GEN9_LP(dev_priv))
10517 bxt_get_ddi_pll(dev_priv, port, pipe_config);
10519 haswell_get_ddi_pll(dev_priv, port, pipe_config);
10521 pll = pipe_config->shared_dpll;
10523 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
10524 &pipe_config->dpll_hw_state));
10528 * Haswell has only FDI/PCH transcoder A. It is which is connected to
10529 * DDI E. So just check whether this pipe is wired to DDI E and whether
10530 * the PCH transcoder is on.
10532 if (INTEL_GEN(dev_priv) < 9 &&
10533 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
10534 pipe_config->has_pch_encoder = true;
10536 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
10537 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
10538 FDI_DP_PORT_WIDTH_SHIFT) + 1;
10540 ironlake_get_fdi_m_n_config(crtc, pipe_config);
10544 static enum transcoder transcoder_master_readout(struct drm_i915_private *dev_priv,
10545 enum transcoder cpu_transcoder)
10547 u32 trans_port_sync, master_select;
10549 trans_port_sync = I915_READ(TRANS_DDI_FUNC_CTL2(cpu_transcoder));
10551 if ((trans_port_sync & PORT_SYNC_MODE_ENABLE) == 0)
10552 return INVALID_TRANSCODER;
10554 master_select = trans_port_sync &
10555 PORT_SYNC_MODE_MASTER_SELECT_MASK;
10556 if (master_select == 0)
10557 return TRANSCODER_EDP;
10559 return master_select - 1;
10562 static void icelake_get_trans_port_sync_config(struct intel_crtc_state *crtc_state)
10564 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
10566 enum transcoder cpu_transcoder;
10568 crtc_state->master_transcoder = transcoder_master_readout(dev_priv,
10569 crtc_state->cpu_transcoder);
10571 transcoders = BIT(TRANSCODER_A) |
10572 BIT(TRANSCODER_B) |
10573 BIT(TRANSCODER_C) |
10575 for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder, transcoders) {
10576 enum intel_display_power_domain power_domain;
10577 intel_wakeref_t trans_wakeref;
10579 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
10580 trans_wakeref = intel_display_power_get_if_enabled(dev_priv,
10583 if (!trans_wakeref)
10586 if (transcoder_master_readout(dev_priv, cpu_transcoder) ==
10587 crtc_state->cpu_transcoder)
10588 crtc_state->sync_mode_slaves_mask |= BIT(cpu_transcoder);
10590 intel_display_power_put(dev_priv, power_domain, trans_wakeref);
10593 WARN_ON(crtc_state->master_transcoder != INVALID_TRANSCODER &&
10594 crtc_state->sync_mode_slaves_mask);
10597 static bool haswell_get_pipe_config(struct intel_crtc *crtc,
10598 struct intel_crtc_state *pipe_config)
10600 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10601 intel_wakeref_t wakerefs[POWER_DOMAIN_NUM], wf;
10602 enum intel_display_power_domain power_domain;
10603 u64 power_domain_mask;
10606 intel_crtc_init_scalers(crtc, pipe_config);
10608 pipe_config->master_transcoder = INVALID_TRANSCODER;
10610 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
10611 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10615 wakerefs[power_domain] = wf;
10616 power_domain_mask = BIT_ULL(power_domain);
10618 pipe_config->shared_dpll = NULL;
10620 active = hsw_get_transcoder_state(crtc, pipe_config,
10621 &power_domain_mask, wakerefs);
10623 if (IS_GEN9_LP(dev_priv) &&
10624 bxt_get_dsi_transcoder_state(crtc, pipe_config,
10625 &power_domain_mask, wakerefs)) {
10633 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
10634 INTEL_GEN(dev_priv) >= 11) {
10635 haswell_get_ddi_port_state(crtc, pipe_config);
10636 intel_get_pipe_timings(crtc, pipe_config);
10639 intel_get_pipe_src_size(crtc, pipe_config);
10641 if (IS_HASWELL(dev_priv)) {
10642 u32 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
10644 if (tmp & PIPECONF_OUTPUT_COLORSPACE_YUV_HSW)
10645 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
10647 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
10649 pipe_config->output_format =
10650 bdw_get_pipemisc_output_format(crtc);
10653 * Currently there is no interface defined to
10654 * check user preference between RGB/YCBCR444
10655 * or YCBCR420. So the only possible case for
10656 * YCBCR444 usage is driving YCBCR420 output
10657 * with LSPCON, when pipe is configured for
10658 * YCBCR444 output and LSPCON takes care of
10661 pipe_config->lspcon_downsampling =
10662 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444;
10665 pipe_config->gamma_mode = I915_READ(GAMMA_MODE(crtc->pipe));
10667 pipe_config->csc_mode = I915_READ(PIPE_CSC_MODE(crtc->pipe));
10669 if (INTEL_GEN(dev_priv) >= 9) {
10670 u32 tmp = I915_READ(SKL_BOTTOM_COLOR(crtc->pipe));
10672 if (tmp & SKL_BOTTOM_COLOR_GAMMA_ENABLE)
10673 pipe_config->gamma_enable = true;
10675 if (tmp & SKL_BOTTOM_COLOR_CSC_ENABLE)
10676 pipe_config->csc_enable = true;
10678 i9xx_get_pipe_color_config(pipe_config);
10681 intel_color_get_config(pipe_config);
10683 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
10684 WARN_ON(power_domain_mask & BIT_ULL(power_domain));
10686 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10688 wakerefs[power_domain] = wf;
10689 power_domain_mask |= BIT_ULL(power_domain);
10691 if (INTEL_GEN(dev_priv) >= 9)
10692 skylake_get_pfit_config(crtc, pipe_config);
10694 ironlake_get_pfit_config(crtc, pipe_config);
10697 if (hsw_crtc_supports_ips(crtc)) {
10698 if (IS_HASWELL(dev_priv))
10699 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
10702 * We cannot readout IPS state on broadwell, set to
10703 * true so we can set it to a defined state on first
10706 pipe_config->ips_enabled = true;
10710 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
10711 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
10712 pipe_config->pixel_multiplier =
10713 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
10715 pipe_config->pixel_multiplier = 1;
10718 if (INTEL_GEN(dev_priv) >= 11 &&
10719 !transcoder_is_dsi(pipe_config->cpu_transcoder))
10720 icelake_get_trans_port_sync_config(pipe_config);
10723 for_each_power_domain(power_domain, power_domain_mask)
10724 intel_display_power_put(dev_priv,
10725 power_domain, wakerefs[power_domain]);
10730 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
10732 struct drm_i915_private *dev_priv =
10733 to_i915(plane_state->base.plane->dev);
10734 const struct drm_framebuffer *fb = plane_state->base.fb;
10735 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
10738 if (INTEL_INFO(dev_priv)->display.cursor_needs_physical)
10739 base = obj->phys_handle->busaddr;
10741 base = intel_plane_ggtt_offset(plane_state);
10743 return base + plane_state->color_plane[0].offset;
10746 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
10748 int x = plane_state->base.dst.x1;
10749 int y = plane_state->base.dst.y1;
10753 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
10756 pos |= x << CURSOR_X_SHIFT;
10759 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
10762 pos |= y << CURSOR_Y_SHIFT;
10767 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
10769 const struct drm_mode_config *config =
10770 &plane_state->base.plane->dev->mode_config;
10771 int width = drm_rect_width(&plane_state->base.dst);
10772 int height = drm_rect_height(&plane_state->base.dst);
10774 return width > 0 && width <= config->cursor_width &&
10775 height > 0 && height <= config->cursor_height;
10778 static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
10780 struct drm_i915_private *dev_priv =
10781 to_i915(plane_state->base.plane->dev);
10782 unsigned int rotation = plane_state->base.rotation;
10787 ret = intel_plane_compute_gtt(plane_state);
10791 if (!plane_state->base.visible)
10794 src_x = plane_state->base.src.x1 >> 16;
10795 src_y = plane_state->base.src.y1 >> 16;
10797 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
10798 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
10801 if (src_x != 0 || src_y != 0) {
10802 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
10807 * Put the final coordinates back so that the src
10808 * coordinate checks will see the right values.
10810 drm_rect_translate_to(&plane_state->base.src,
10811 src_x << 16, src_y << 16);
10813 /* ILK+ do this automagically in hardware */
10814 if (HAS_GMCH(dev_priv) && rotation & DRM_MODE_ROTATE_180) {
10815 const struct drm_framebuffer *fb = plane_state->base.fb;
10816 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
10817 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
10819 offset += (src_h * src_w - 1) * fb->format->cpp[0];
10822 plane_state->color_plane[0].offset = offset;
10823 plane_state->color_plane[0].x = src_x;
10824 plane_state->color_plane[0].y = src_y;
10829 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
10830 struct intel_plane_state *plane_state)
10832 const struct drm_framebuffer *fb = plane_state->base.fb;
10835 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
10836 DRM_DEBUG_KMS("cursor cannot be tiled\n");
10840 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
10842 DRM_PLANE_HELPER_NO_SCALING,
10843 DRM_PLANE_HELPER_NO_SCALING,
10848 /* Use the unclipped src/dst rectangles, which we program to hw */
10849 plane_state->base.src = drm_plane_state_src(&plane_state->base);
10850 plane_state->base.dst = drm_plane_state_dest(&plane_state->base);
10852 ret = intel_cursor_check_surface(plane_state);
10856 if (!plane_state->base.visible)
10859 ret = intel_plane_check_src_coordinates(plane_state);
10866 static unsigned int
10867 i845_cursor_max_stride(struct intel_plane *plane,
10868 u32 pixel_format, u64 modifier,
10869 unsigned int rotation)
10874 static u32 i845_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
10878 if (crtc_state->gamma_enable)
10879 cntl |= CURSOR_GAMMA_ENABLE;
10884 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
10885 const struct intel_plane_state *plane_state)
10887 return CURSOR_ENABLE |
10888 CURSOR_FORMAT_ARGB |
10889 CURSOR_STRIDE(plane_state->color_plane[0].stride);
10892 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
10894 int width = drm_rect_width(&plane_state->base.dst);
10897 * 845g/865g are only limited by the width of their cursors,
10898 * the height is arbitrary up to the precision of the register.
10900 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
10903 static int i845_check_cursor(struct intel_crtc_state *crtc_state,
10904 struct intel_plane_state *plane_state)
10906 const struct drm_framebuffer *fb = plane_state->base.fb;
10909 ret = intel_check_cursor(crtc_state, plane_state);
10913 /* if we want to turn off the cursor ignore width and height */
10917 /* Check for which cursor types we support */
10918 if (!i845_cursor_size_ok(plane_state)) {
10919 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10920 drm_rect_width(&plane_state->base.dst),
10921 drm_rect_height(&plane_state->base.dst));
10925 WARN_ON(plane_state->base.visible &&
10926 plane_state->color_plane[0].stride != fb->pitches[0]);
10928 switch (fb->pitches[0]) {
10935 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
10940 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
10945 static void i845_update_cursor(struct intel_plane *plane,
10946 const struct intel_crtc_state *crtc_state,
10947 const struct intel_plane_state *plane_state)
10949 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10950 u32 cntl = 0, base = 0, pos = 0, size = 0;
10951 unsigned long irqflags;
10953 if (plane_state && plane_state->base.visible) {
10954 unsigned int width = drm_rect_width(&plane_state->base.dst);
10955 unsigned int height = drm_rect_height(&plane_state->base.dst);
10957 cntl = plane_state->ctl |
10958 i845_cursor_ctl_crtc(crtc_state);
10960 size = (height << 12) | width;
10962 base = intel_cursor_base(plane_state);
10963 pos = intel_cursor_position(plane_state);
10966 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10968 /* On these chipsets we can only modify the base/size/stride
10969 * whilst the cursor is disabled.
10971 if (plane->cursor.base != base ||
10972 plane->cursor.size != size ||
10973 plane->cursor.cntl != cntl) {
10974 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
10975 I915_WRITE_FW(CURBASE(PIPE_A), base);
10976 I915_WRITE_FW(CURSIZE, size);
10977 I915_WRITE_FW(CURPOS(PIPE_A), pos);
10978 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
10980 plane->cursor.base = base;
10981 plane->cursor.size = size;
10982 plane->cursor.cntl = cntl;
10984 I915_WRITE_FW(CURPOS(PIPE_A), pos);
10987 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
10990 static void i845_disable_cursor(struct intel_plane *plane,
10991 const struct intel_crtc_state *crtc_state)
10993 i845_update_cursor(plane, crtc_state, NULL);
10996 static bool i845_cursor_get_hw_state(struct intel_plane *plane,
10999 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11000 enum intel_display_power_domain power_domain;
11001 intel_wakeref_t wakeref;
11004 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
11005 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
11009 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
11013 intel_display_power_put(dev_priv, power_domain, wakeref);
11018 static unsigned int
11019 i9xx_cursor_max_stride(struct intel_plane *plane,
11020 u32 pixel_format, u64 modifier,
11021 unsigned int rotation)
11023 return plane->base.dev->mode_config.cursor_width * 4;
11026 static u32 i9xx_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
11028 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
11029 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11032 if (INTEL_GEN(dev_priv) >= 11)
11035 if (crtc_state->gamma_enable)
11036 cntl = MCURSOR_GAMMA_ENABLE;
11038 if (crtc_state->csc_enable)
11039 cntl |= MCURSOR_PIPE_CSC_ENABLE;
11041 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11042 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
11047 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
11048 const struct intel_plane_state *plane_state)
11050 struct drm_i915_private *dev_priv =
11051 to_i915(plane_state->base.plane->dev);
11054 if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
11055 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
11057 switch (drm_rect_width(&plane_state->base.dst)) {
11059 cntl |= MCURSOR_MODE_64_ARGB_AX;
11062 cntl |= MCURSOR_MODE_128_ARGB_AX;
11065 cntl |= MCURSOR_MODE_256_ARGB_AX;
11068 MISSING_CASE(drm_rect_width(&plane_state->base.dst));
11072 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
11073 cntl |= MCURSOR_ROTATE_180;
11078 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
11080 struct drm_i915_private *dev_priv =
11081 to_i915(plane_state->base.plane->dev);
11082 int width = drm_rect_width(&plane_state->base.dst);
11083 int height = drm_rect_height(&plane_state->base.dst);
11085 if (!intel_cursor_size_ok(plane_state))
11088 /* Cursor width is limited to a few power-of-two sizes */
11099 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
11100 * height from 8 lines up to the cursor width, when the
11101 * cursor is not rotated. Everything else requires square
11104 if (HAS_CUR_FBC(dev_priv) &&
11105 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
11106 if (height < 8 || height > width)
11109 if (height != width)
11116 static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
11117 struct intel_plane_state *plane_state)
11119 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
11120 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11121 const struct drm_framebuffer *fb = plane_state->base.fb;
11122 enum pipe pipe = plane->pipe;
11125 ret = intel_check_cursor(crtc_state, plane_state);
11129 /* if we want to turn off the cursor ignore width and height */
11133 /* Check for which cursor types we support */
11134 if (!i9xx_cursor_size_ok(plane_state)) {
11135 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
11136 drm_rect_width(&plane_state->base.dst),
11137 drm_rect_height(&plane_state->base.dst));
11141 WARN_ON(plane_state->base.visible &&
11142 plane_state->color_plane[0].stride != fb->pitches[0]);
11144 if (fb->pitches[0] !=
11145 drm_rect_width(&plane_state->base.dst) * fb->format->cpp[0]) {
11146 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
11148 drm_rect_width(&plane_state->base.dst));
11153 * There's something wrong with the cursor on CHV pipe C.
11154 * If it straddles the left edge of the screen then
11155 * moving it away from the edge or disabling it often
11156 * results in a pipe underrun, and often that can lead to
11157 * dead pipe (constant underrun reported, and it scans
11158 * out just a solid color). To recover from that, the
11159 * display power well must be turned off and on again.
11160 * Refuse the put the cursor into that compromised position.
11162 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
11163 plane_state->base.visible && plane_state->base.dst.x1 < 0) {
11164 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
11168 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
11173 static void i9xx_update_cursor(struct intel_plane *plane,
11174 const struct intel_crtc_state *crtc_state,
11175 const struct intel_plane_state *plane_state)
11177 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11178 enum pipe pipe = plane->pipe;
11179 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
11180 unsigned long irqflags;
11182 if (plane_state && plane_state->base.visible) {
11183 unsigned width = drm_rect_width(&plane_state->base.dst);
11184 unsigned height = drm_rect_height(&plane_state->base.dst);
11186 cntl = plane_state->ctl |
11187 i9xx_cursor_ctl_crtc(crtc_state);
11189 if (width != height)
11190 fbc_ctl = CUR_FBC_CTL_EN | (height - 1);
11192 base = intel_cursor_base(plane_state);
11193 pos = intel_cursor_position(plane_state);
11196 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
11199 * On some platforms writing CURCNTR first will also
11200 * cause CURPOS to be armed by the CURBASE write.
11201 * Without the CURCNTR write the CURPOS write would
11202 * arm itself. Thus we always update CURCNTR before
11205 * On other platforms CURPOS always requires the
11206 * CURBASE write to arm the update. Additonally
11207 * a write to any of the cursor register will cancel
11208 * an already armed cursor update. Thus leaving out
11209 * the CURBASE write after CURPOS could lead to a
11210 * cursor that doesn't appear to move, or even change
11211 * shape. Thus we always write CURBASE.
11213 * The other registers are armed by by the CURBASE write
11214 * except when the plane is getting enabled at which time
11215 * the CURCNTR write arms the update.
11218 if (INTEL_GEN(dev_priv) >= 9)
11219 skl_write_cursor_wm(plane, crtc_state);
11221 if (plane->cursor.base != base ||
11222 plane->cursor.size != fbc_ctl ||
11223 plane->cursor.cntl != cntl) {
11224 if (HAS_CUR_FBC(dev_priv))
11225 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
11226 I915_WRITE_FW(CURCNTR(pipe), cntl);
11227 I915_WRITE_FW(CURPOS(pipe), pos);
11228 I915_WRITE_FW(CURBASE(pipe), base);
11230 plane->cursor.base = base;
11231 plane->cursor.size = fbc_ctl;
11232 plane->cursor.cntl = cntl;
11234 I915_WRITE_FW(CURPOS(pipe), pos);
11235 I915_WRITE_FW(CURBASE(pipe), base);
11238 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
11241 static void i9xx_disable_cursor(struct intel_plane *plane,
11242 const struct intel_crtc_state *crtc_state)
11244 i9xx_update_cursor(plane, crtc_state, NULL);
11247 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
11250 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11251 enum intel_display_power_domain power_domain;
11252 intel_wakeref_t wakeref;
11257 * Not 100% correct for planes that can move between pipes,
11258 * but that's only the case for gen2-3 which don't have any
11259 * display power wells.
11261 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
11262 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
11266 val = I915_READ(CURCNTR(plane->pipe));
11268 ret = val & MCURSOR_MODE;
11270 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
11271 *pipe = plane->pipe;
11273 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
11274 MCURSOR_PIPE_SELECT_SHIFT;
11276 intel_display_power_put(dev_priv, power_domain, wakeref);
11281 /* VESA 640x480x72Hz mode to set on the pipe */
11282 static const struct drm_display_mode load_detect_mode = {
11283 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
11284 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
11287 struct drm_framebuffer *
11288 intel_framebuffer_create(struct drm_i915_gem_object *obj,
11289 struct drm_mode_fb_cmd2 *mode_cmd)
11291 struct intel_framebuffer *intel_fb;
11294 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
11296 return ERR_PTR(-ENOMEM);
11298 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
11302 return &intel_fb->base;
11306 return ERR_PTR(ret);
11309 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
11310 struct drm_crtc *crtc)
11312 struct drm_plane *plane;
11313 struct drm_plane_state *plane_state;
11316 ret = drm_atomic_add_affected_planes(state, crtc);
11320 for_each_new_plane_in_state(state, plane, plane_state, i) {
11321 if (plane_state->crtc != crtc)
11324 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
11328 drm_atomic_set_fb_for_plane(plane_state, NULL);
11334 int intel_get_load_detect_pipe(struct drm_connector *connector,
11335 struct intel_load_detect_pipe *old,
11336 struct drm_modeset_acquire_ctx *ctx)
11338 struct intel_crtc *intel_crtc;
11339 struct intel_encoder *intel_encoder =
11340 intel_attached_encoder(connector);
11341 struct drm_crtc *possible_crtc;
11342 struct drm_encoder *encoder = &intel_encoder->base;
11343 struct drm_crtc *crtc = NULL;
11344 struct drm_device *dev = encoder->dev;
11345 struct drm_i915_private *dev_priv = to_i915(dev);
11346 struct drm_mode_config *config = &dev->mode_config;
11347 struct drm_atomic_state *state = NULL, *restore_state = NULL;
11348 struct drm_connector_state *connector_state;
11349 struct intel_crtc_state *crtc_state;
11352 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11353 connector->base.id, connector->name,
11354 encoder->base.id, encoder->name);
11356 old->restore_state = NULL;
11358 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
11361 * Algorithm gets a little messy:
11363 * - if the connector already has an assigned crtc, use it (but make
11364 * sure it's on first)
11366 * - try to find the first unused crtc that can drive this connector,
11367 * and use that if we find one
11370 /* See if we already have a CRTC for this connector */
11371 if (connector->state->crtc) {
11372 crtc = connector->state->crtc;
11374 ret = drm_modeset_lock(&crtc->mutex, ctx);
11378 /* Make sure the crtc and connector are running */
11382 /* Find an unused one (if possible) */
11383 for_each_crtc(dev, possible_crtc) {
11385 if (!(encoder->possible_crtcs & (1 << i)))
11388 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
11392 if (possible_crtc->state->enable) {
11393 drm_modeset_unlock(&possible_crtc->mutex);
11397 crtc = possible_crtc;
11402 * If we didn't find an unused CRTC, don't use any.
11405 DRM_DEBUG_KMS("no pipe available for load-detect\n");
11411 intel_crtc = to_intel_crtc(crtc);
11413 state = drm_atomic_state_alloc(dev);
11414 restore_state = drm_atomic_state_alloc(dev);
11415 if (!state || !restore_state) {
11420 state->acquire_ctx = ctx;
11421 restore_state->acquire_ctx = ctx;
11423 connector_state = drm_atomic_get_connector_state(state, connector);
11424 if (IS_ERR(connector_state)) {
11425 ret = PTR_ERR(connector_state);
11429 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
11433 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
11434 if (IS_ERR(crtc_state)) {
11435 ret = PTR_ERR(crtc_state);
11439 crtc_state->base.active = crtc_state->base.enable = true;
11441 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base,
11442 &load_detect_mode);
11446 ret = intel_modeset_disable_planes(state, crtc);
11450 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
11452 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
11454 ret = drm_atomic_add_affected_planes(restore_state, crtc);
11456 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
11460 ret = drm_atomic_commit(state);
11462 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
11466 old->restore_state = restore_state;
11467 drm_atomic_state_put(state);
11469 /* let the connector get through one full cycle before testing */
11470 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
11475 drm_atomic_state_put(state);
11478 if (restore_state) {
11479 drm_atomic_state_put(restore_state);
11480 restore_state = NULL;
11483 if (ret == -EDEADLK)
11489 void intel_release_load_detect_pipe(struct drm_connector *connector,
11490 struct intel_load_detect_pipe *old,
11491 struct drm_modeset_acquire_ctx *ctx)
11493 struct intel_encoder *intel_encoder =
11494 intel_attached_encoder(connector);
11495 struct drm_encoder *encoder = &intel_encoder->base;
11496 struct drm_atomic_state *state = old->restore_state;
11499 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11500 connector->base.id, connector->name,
11501 encoder->base.id, encoder->name);
11506 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
11508 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
11509 drm_atomic_state_put(state);
11512 static int i9xx_pll_refclk(struct drm_device *dev,
11513 const struct intel_crtc_state *pipe_config)
11515 struct drm_i915_private *dev_priv = to_i915(dev);
11516 u32 dpll = pipe_config->dpll_hw_state.dpll;
11518 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
11519 return dev_priv->vbt.lvds_ssc_freq;
11520 else if (HAS_PCH_SPLIT(dev_priv))
11522 else if (!IS_GEN(dev_priv, 2))
11528 /* Returns the clock of the currently programmed mode of the given pipe. */
11529 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
11530 struct intel_crtc_state *pipe_config)
11532 struct drm_device *dev = crtc->base.dev;
11533 struct drm_i915_private *dev_priv = to_i915(dev);
11534 enum pipe pipe = crtc->pipe;
11535 u32 dpll = pipe_config->dpll_hw_state.dpll;
11539 int refclk = i9xx_pll_refclk(dev, pipe_config);
11541 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
11542 fp = pipe_config->dpll_hw_state.fp0;
11544 fp = pipe_config->dpll_hw_state.fp1;
11546 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
11547 if (IS_PINEVIEW(dev_priv)) {
11548 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
11549 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
11551 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
11552 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
11555 if (!IS_GEN(dev_priv, 2)) {
11556 if (IS_PINEVIEW(dev_priv))
11557 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
11558 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
11560 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
11561 DPLL_FPA01_P1_POST_DIV_SHIFT);
11563 switch (dpll & DPLL_MODE_MASK) {
11564 case DPLLB_MODE_DAC_SERIAL:
11565 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
11568 case DPLLB_MODE_LVDS:
11569 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
11573 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
11574 "mode\n", (int)(dpll & DPLL_MODE_MASK));
11578 if (IS_PINEVIEW(dev_priv))
11579 port_clock = pnv_calc_dpll_params(refclk, &clock);
11581 port_clock = i9xx_calc_dpll_params(refclk, &clock);
11583 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
11584 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
11587 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
11588 DPLL_FPA01_P1_POST_DIV_SHIFT);
11590 if (lvds & LVDS_CLKB_POWER_UP)
11595 if (dpll & PLL_P1_DIVIDE_BY_TWO)
11598 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
11599 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
11601 if (dpll & PLL_P2_DIVIDE_BY_4)
11607 port_clock = i9xx_calc_dpll_params(refclk, &clock);
11611 * This value includes pixel_multiplier. We will use
11612 * port_clock to compute adjusted_mode.crtc_clock in the
11613 * encoder's get_config() function.
11615 pipe_config->port_clock = port_clock;
11618 int intel_dotclock_calculate(int link_freq,
11619 const struct intel_link_m_n *m_n)
11622 * The calculation for the data clock is:
11623 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
11624 * But we want to avoid losing precison if possible, so:
11625 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
11627 * and the link clock is simpler:
11628 * link_clock = (m * link_clock) / n
11634 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
11637 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
11638 struct intel_crtc_state *pipe_config)
11640 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11642 /* read out port_clock from the DPLL */
11643 i9xx_crtc_clock_get(crtc, pipe_config);
11646 * In case there is an active pipe without active ports,
11647 * we may need some idea for the dotclock anyway.
11648 * Calculate one based on the FDI configuration.
11650 pipe_config->base.adjusted_mode.crtc_clock =
11651 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
11652 &pipe_config->fdi_m_n);
11655 /* Returns the currently programmed mode of the given encoder. */
11656 struct drm_display_mode *
11657 intel_encoder_current_mode(struct intel_encoder *encoder)
11659 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
11660 struct intel_crtc_state *crtc_state;
11661 struct drm_display_mode *mode;
11662 struct intel_crtc *crtc;
11665 if (!encoder->get_hw_state(encoder, &pipe))
11668 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
11670 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
11674 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
11680 crtc_state->base.crtc = &crtc->base;
11682 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
11688 encoder->get_config(encoder, crtc_state);
11690 intel_mode_from_pipe_config(mode, crtc_state);
11697 static void intel_crtc_destroy(struct drm_crtc *crtc)
11699 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11701 drm_crtc_cleanup(crtc);
11706 * intel_wm_need_update - Check whether watermarks need updating
11707 * @cur: current plane state
11708 * @new: new plane state
11710 * Check current plane state versus the new one to determine whether
11711 * watermarks need to be recalculated.
11713 * Returns true or false.
11715 static bool intel_wm_need_update(const struct intel_plane_state *cur,
11716 struct intel_plane_state *new)
11718 /* Update watermarks on tiling or size changes. */
11719 if (new->base.visible != cur->base.visible)
11722 if (!cur->base.fb || !new->base.fb)
11725 if (cur->base.fb->modifier != new->base.fb->modifier ||
11726 cur->base.rotation != new->base.rotation ||
11727 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
11728 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
11729 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
11730 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
11736 static bool needs_scaling(const struct intel_plane_state *state)
11738 int src_w = drm_rect_width(&state->base.src) >> 16;
11739 int src_h = drm_rect_height(&state->base.src) >> 16;
11740 int dst_w = drm_rect_width(&state->base.dst);
11741 int dst_h = drm_rect_height(&state->base.dst);
11743 return (src_w != dst_w || src_h != dst_h);
11746 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
11747 struct intel_crtc_state *crtc_state,
11748 const struct intel_plane_state *old_plane_state,
11749 struct intel_plane_state *plane_state)
11751 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
11752 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
11753 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11754 bool mode_changed = needs_modeset(crtc_state);
11755 bool was_crtc_enabled = old_crtc_state->base.active;
11756 bool is_crtc_enabled = crtc_state->base.active;
11757 bool turn_off, turn_on, visible, was_visible;
11760 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
11761 ret = skl_update_scaler_plane(crtc_state, plane_state);
11766 was_visible = old_plane_state->base.visible;
11767 visible = plane_state->base.visible;
11769 if (!was_crtc_enabled && WARN_ON(was_visible))
11770 was_visible = false;
11773 * Visibility is calculated as if the crtc was on, but
11774 * after scaler setup everything depends on it being off
11775 * when the crtc isn't active.
11777 * FIXME this is wrong for watermarks. Watermarks should also
11778 * be computed as if the pipe would be active. Perhaps move
11779 * per-plane wm computation to the .check_plane() hook, and
11780 * only combine the results from all planes in the current place?
11782 if (!is_crtc_enabled) {
11783 plane_state->base.visible = visible = false;
11784 crtc_state->active_planes &= ~BIT(plane->id);
11785 crtc_state->data_rate[plane->id] = 0;
11786 crtc_state->min_cdclk[plane->id] = 0;
11789 if (!was_visible && !visible)
11792 turn_off = was_visible && (!visible || mode_changed);
11793 turn_on = visible && (!was_visible || mode_changed);
11795 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] with [PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
11796 crtc->base.base.id, crtc->base.name,
11797 plane->base.base.id, plane->base.name,
11798 was_visible, visible,
11799 turn_off, turn_on, mode_changed);
11802 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11803 crtc_state->update_wm_pre = true;
11805 /* must disable cxsr around plane enable/disable */
11806 if (plane->id != PLANE_CURSOR)
11807 crtc_state->disable_cxsr = true;
11808 } else if (turn_off) {
11809 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11810 crtc_state->update_wm_post = true;
11812 /* must disable cxsr around plane enable/disable */
11813 if (plane->id != PLANE_CURSOR)
11814 crtc_state->disable_cxsr = true;
11815 } else if (intel_wm_need_update(old_plane_state, plane_state)) {
11816 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
11817 /* FIXME bollocks */
11818 crtc_state->update_wm_pre = true;
11819 crtc_state->update_wm_post = true;
11823 if (visible || was_visible)
11824 crtc_state->fb_bits |= plane->frontbuffer_bit;
11827 * ILK/SNB DVSACNTR/Sprite Enable
11828 * IVB SPR_CTL/Sprite Enable
11829 * "When in Self Refresh Big FIFO mode, a write to enable the
11830 * plane will be internally buffered and delayed while Big FIFO
11831 * mode is exiting."
11833 * Which means that enabling the sprite can take an extra frame
11834 * when we start in big FIFO mode (LP1+). Thus we need to drop
11835 * down to LP0 and wait for vblank in order to make sure the
11836 * sprite gets enabled on the next vblank after the register write.
11837 * Doing otherwise would risk enabling the sprite one frame after
11838 * we've already signalled flip completion. We can resume LP1+
11839 * once the sprite has been enabled.
11842 * WaCxSRDisabledForSpriteScaling:ivb
11843 * IVB SPR_SCALE/Scaling Enable
11844 * "Low Power watermarks must be disabled for at least one
11845 * frame before enabling sprite scaling, and kept disabled
11846 * until sprite scaling is disabled."
11848 * ILK/SNB DVSASCALE/Scaling Enable
11849 * "When in Self Refresh Big FIFO mode, scaling enable will be
11850 * masked off while Big FIFO mode is exiting."
11852 * Despite the w/a only being listed for IVB we assume that
11853 * the ILK/SNB note has similar ramifications, hence we apply
11854 * the w/a on all three platforms.
11856 * With experimental results seems this is needed also for primary
11857 * plane, not only sprite plane.
11859 if (plane->id != PLANE_CURSOR &&
11860 (IS_GEN_RANGE(dev_priv, 5, 6) ||
11861 IS_IVYBRIDGE(dev_priv)) &&
11862 (turn_on || (!needs_scaling(old_plane_state) &&
11863 needs_scaling(plane_state))))
11864 crtc_state->disable_lp_wm = true;
11869 static bool encoders_cloneable(const struct intel_encoder *a,
11870 const struct intel_encoder *b)
11872 /* masks could be asymmetric, so check both ways */
11873 return a == b || (a->cloneable & (1 << b->type) &&
11874 b->cloneable & (1 << a->type));
11877 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
11878 struct intel_crtc *crtc,
11879 struct intel_encoder *encoder)
11881 struct intel_encoder *source_encoder;
11882 struct drm_connector *connector;
11883 struct drm_connector_state *connector_state;
11886 for_each_new_connector_in_state(state, connector, connector_state, i) {
11887 if (connector_state->crtc != &crtc->base)
11891 to_intel_encoder(connector_state->best_encoder);
11892 if (!encoders_cloneable(encoder, source_encoder))
11899 static int icl_add_linked_planes(struct intel_atomic_state *state)
11901 struct intel_plane *plane, *linked;
11902 struct intel_plane_state *plane_state, *linked_plane_state;
11905 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11906 linked = plane_state->planar_linked_plane;
11911 linked_plane_state = intel_atomic_get_plane_state(state, linked);
11912 if (IS_ERR(linked_plane_state))
11913 return PTR_ERR(linked_plane_state);
11915 WARN_ON(linked_plane_state->planar_linked_plane != plane);
11916 WARN_ON(linked_plane_state->planar_slave == plane_state->planar_slave);
11922 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
11924 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
11925 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11926 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state);
11927 struct intel_plane *plane, *linked;
11928 struct intel_plane_state *plane_state;
11931 if (INTEL_GEN(dev_priv) < 11)
11935 * Destroy all old plane links and make the slave plane invisible
11936 * in the crtc_state->active_planes mask.
11938 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11939 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane)
11942 plane_state->planar_linked_plane = NULL;
11943 if (plane_state->planar_slave && !plane_state->base.visible) {
11944 crtc_state->active_planes &= ~BIT(plane->id);
11945 crtc_state->update_planes |= BIT(plane->id);
11948 plane_state->planar_slave = false;
11951 if (!crtc_state->nv12_planes)
11954 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11955 struct intel_plane_state *linked_state = NULL;
11957 if (plane->pipe != crtc->pipe ||
11958 !(crtc_state->nv12_planes & BIT(plane->id)))
11961 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
11962 if (!icl_is_nv12_y_plane(linked->id))
11965 if (crtc_state->active_planes & BIT(linked->id))
11968 linked_state = intel_atomic_get_plane_state(state, linked);
11969 if (IS_ERR(linked_state))
11970 return PTR_ERR(linked_state);
11975 if (!linked_state) {
11976 DRM_DEBUG_KMS("Need %d free Y planes for planar YUV\n",
11977 hweight8(crtc_state->nv12_planes));
11982 plane_state->planar_linked_plane = linked;
11984 linked_state->planar_slave = true;
11985 linked_state->planar_linked_plane = plane;
11986 crtc_state->active_planes |= BIT(linked->id);
11987 crtc_state->update_planes |= BIT(linked->id);
11988 DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name);
11994 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
11996 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
11997 struct intel_atomic_state *state =
11998 to_intel_atomic_state(new_crtc_state->base.state);
11999 const struct intel_crtc_state *old_crtc_state =
12000 intel_atomic_get_old_crtc_state(state, crtc);
12002 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
12005 static int icl_add_sync_mode_crtcs(struct intel_crtc_state *crtc_state)
12007 struct drm_crtc *crtc = crtc_state->base.crtc;
12008 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state);
12009 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
12010 struct drm_connector *master_connector, *connector;
12011 struct drm_connector_state *connector_state;
12012 struct drm_connector_list_iter conn_iter;
12013 struct drm_crtc *master_crtc = NULL;
12014 struct drm_crtc_state *master_crtc_state;
12015 struct intel_crtc_state *master_pipe_config;
12016 int i, tile_group_id;
12018 if (INTEL_GEN(dev_priv) < 11)
12022 * In case of tiled displays there could be one or more slaves but there is
12023 * only one master. Lets make the CRTC used by the connector corresponding
12024 * to the last horizonal and last vertical tile a master/genlock CRTC.
12025 * All the other CRTCs corresponding to other tiles of the same Tile group
12026 * are the slave CRTCs and hold a pointer to their genlock CRTC.
12028 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
12029 if (connector_state->crtc != crtc)
12031 if (!connector->has_tile)
12033 if (crtc_state->base.mode.hdisplay != connector->tile_h_size ||
12034 crtc_state->base.mode.vdisplay != connector->tile_v_size)
12036 if (connector->tile_h_loc == connector->num_h_tile - 1 &&
12037 connector->tile_v_loc == connector->num_v_tile - 1)
12039 crtc_state->sync_mode_slaves_mask = 0;
12040 tile_group_id = connector->tile_group->id;
12041 drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
12042 drm_for_each_connector_iter(master_connector, &conn_iter) {
12043 struct drm_connector_state *master_conn_state = NULL;
12045 if (!master_connector->has_tile)
12047 if (master_connector->tile_h_loc != master_connector->num_h_tile - 1 ||
12048 master_connector->tile_v_loc != master_connector->num_v_tile - 1)
12050 if (master_connector->tile_group->id != tile_group_id)
12053 master_conn_state = drm_atomic_get_connector_state(&state->base,
12055 if (IS_ERR(master_conn_state)) {
12056 drm_connector_list_iter_end(&conn_iter);
12057 return PTR_ERR(master_conn_state);
12059 if (master_conn_state->crtc) {
12060 master_crtc = master_conn_state->crtc;
12064 drm_connector_list_iter_end(&conn_iter);
12066 if (!master_crtc) {
12067 DRM_DEBUG_KMS("Could not find Master CRTC for Slave CRTC %d\n",
12068 connector_state->crtc->base.id);
12072 master_crtc_state = drm_atomic_get_crtc_state(&state->base,
12074 if (IS_ERR(master_crtc_state))
12075 return PTR_ERR(master_crtc_state);
12077 master_pipe_config = to_intel_crtc_state(master_crtc_state);
12078 crtc_state->master_transcoder = master_pipe_config->cpu_transcoder;
12079 master_pipe_config->sync_mode_slaves_mask |=
12080 BIT(crtc_state->cpu_transcoder);
12081 DRM_DEBUG_KMS("Master Transcoder = %s added for Slave CRTC = %d, slave transcoder bitmask = %d\n",
12082 transcoder_name(crtc_state->master_transcoder),
12083 crtc_state->base.crtc->base.id,
12084 master_pipe_config->sync_mode_slaves_mask);
12090 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
12091 struct intel_crtc *crtc)
12093 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12094 struct intel_crtc_state *crtc_state =
12095 intel_atomic_get_new_crtc_state(state, crtc);
12096 bool mode_changed = needs_modeset(crtc_state);
12099 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv) &&
12100 mode_changed && !crtc_state->base.active)
12101 crtc_state->update_wm_post = true;
12103 if (mode_changed && crtc_state->base.enable &&
12104 dev_priv->display.crtc_compute_clock &&
12105 !WARN_ON(crtc_state->shared_dpll)) {
12106 ret = dev_priv->display.crtc_compute_clock(crtc, crtc_state);
12112 * May need to update pipe gamma enable bits
12113 * when C8 planes are getting enabled/disabled.
12115 if (c8_planes_changed(crtc_state))
12116 crtc_state->base.color_mgmt_changed = true;
12118 if (mode_changed || crtc_state->update_pipe ||
12119 crtc_state->base.color_mgmt_changed) {
12120 ret = intel_color_check(crtc_state);
12126 if (dev_priv->display.compute_pipe_wm) {
12127 ret = dev_priv->display.compute_pipe_wm(crtc_state);
12129 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
12134 if (dev_priv->display.compute_intermediate_wm) {
12135 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
12139 * Calculate 'intermediate' watermarks that satisfy both the
12140 * old state and the new state. We can program these
12143 ret = dev_priv->display.compute_intermediate_wm(crtc_state);
12145 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
12150 if (INTEL_GEN(dev_priv) >= 9) {
12151 if (mode_changed || crtc_state->update_pipe)
12152 ret = skl_update_scaler_crtc(crtc_state);
12154 ret = intel_atomic_setup_scalers(dev_priv, crtc,
12158 if (HAS_IPS(dev_priv))
12159 crtc_state->ips_enabled = hsw_compute_ips_config(crtc_state);
12164 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
12166 struct intel_connector *connector;
12167 struct drm_connector_list_iter conn_iter;
12169 drm_connector_list_iter_begin(dev, &conn_iter);
12170 for_each_intel_connector_iter(connector, &conn_iter) {
12171 if (connector->base.state->crtc)
12172 drm_connector_put(&connector->base);
12174 if (connector->base.encoder) {
12175 connector->base.state->best_encoder =
12176 connector->base.encoder;
12177 connector->base.state->crtc =
12178 connector->base.encoder->crtc;
12180 drm_connector_get(&connector->base);
12182 connector->base.state->best_encoder = NULL;
12183 connector->base.state->crtc = NULL;
12186 drm_connector_list_iter_end(&conn_iter);
12190 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
12191 struct intel_crtc_state *pipe_config)
12193 struct drm_connector *connector = conn_state->connector;
12194 const struct drm_display_info *info = &connector->display_info;
12197 switch (conn_state->max_bpc) {
12214 if (bpp < pipe_config->pipe_bpp) {
12215 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
12216 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
12217 connector->base.id, connector->name,
12218 bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc,
12219 pipe_config->pipe_bpp);
12221 pipe_config->pipe_bpp = bpp;
12228 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
12229 struct intel_crtc_state *pipe_config)
12231 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12232 struct drm_atomic_state *state = pipe_config->base.state;
12233 struct drm_connector *connector;
12234 struct drm_connector_state *connector_state;
12237 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
12238 IS_CHERRYVIEW(dev_priv)))
12240 else if (INTEL_GEN(dev_priv) >= 5)
12245 pipe_config->pipe_bpp = bpp;
12247 /* Clamp display bpp to connector max bpp */
12248 for_each_new_connector_in_state(state, connector, connector_state, i) {
12251 if (connector_state->crtc != &crtc->base)
12254 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
12262 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
12264 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
12265 "type: 0x%x flags: 0x%x\n",
12267 mode->crtc_hdisplay, mode->crtc_hsync_start,
12268 mode->crtc_hsync_end, mode->crtc_htotal,
12269 mode->crtc_vdisplay, mode->crtc_vsync_start,
12270 mode->crtc_vsync_end, mode->crtc_vtotal,
12271 mode->type, mode->flags);
12275 intel_dump_m_n_config(const struct intel_crtc_state *pipe_config,
12276 const char *id, unsigned int lane_count,
12277 const struct intel_link_m_n *m_n)
12279 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
12281 m_n->gmch_m, m_n->gmch_n,
12282 m_n->link_m, m_n->link_n, m_n->tu);
12286 intel_dump_infoframe(struct drm_i915_private *dev_priv,
12287 const union hdmi_infoframe *frame)
12289 if ((drm_debug & DRM_UT_KMS) == 0)
12292 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, frame);
12295 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
12297 static const char * const output_type_str[] = {
12298 OUTPUT_TYPE(UNUSED),
12299 OUTPUT_TYPE(ANALOG),
12303 OUTPUT_TYPE(TVOUT),
12309 OUTPUT_TYPE(DP_MST),
12314 static void snprintf_output_types(char *buf, size_t len,
12315 unsigned int output_types)
12322 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
12325 if ((output_types & BIT(i)) == 0)
12328 r = snprintf(str, len, "%s%s",
12329 str != buf ? "," : "", output_type_str[i]);
12335 output_types &= ~BIT(i);
12338 WARN_ON_ONCE(output_types != 0);
12341 static const char * const output_format_str[] = {
12342 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
12343 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
12344 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
12345 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
12348 static const char *output_formats(enum intel_output_format format)
12350 if (format >= ARRAY_SIZE(output_format_str))
12351 format = INTEL_OUTPUT_FORMAT_INVALID;
12352 return output_format_str[format];
12355 static void intel_dump_plane_state(const struct intel_plane_state *plane_state)
12357 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
12358 const struct drm_framebuffer *fb = plane_state->base.fb;
12359 struct drm_format_name_buf format_name;
12362 DRM_DEBUG_KMS("[PLANE:%d:%s] fb: [NOFB], visible: %s\n",
12363 plane->base.base.id, plane->base.name,
12364 yesno(plane_state->base.visible));
12368 DRM_DEBUG_KMS("[PLANE:%d:%s] fb: [FB:%d] %ux%u format = %s, visible: %s\n",
12369 plane->base.base.id, plane->base.name,
12370 fb->base.id, fb->width, fb->height,
12371 drm_get_format_name(fb->format->format, &format_name),
12372 yesno(plane_state->base.visible));
12373 DRM_DEBUG_KMS("\trotation: 0x%x, scaler: %d\n",
12374 plane_state->base.rotation, plane_state->scaler_id);
12375 if (plane_state->base.visible)
12376 DRM_DEBUG_KMS("\tsrc: " DRM_RECT_FP_FMT " dst: " DRM_RECT_FMT "\n",
12377 DRM_RECT_FP_ARG(&plane_state->base.src),
12378 DRM_RECT_ARG(&plane_state->base.dst));
12381 static void intel_dump_pipe_config(const struct intel_crtc_state *pipe_config,
12382 struct intel_atomic_state *state,
12383 const char *context)
12385 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
12386 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12387 const struct intel_plane_state *plane_state;
12388 struct intel_plane *plane;
12392 DRM_DEBUG_KMS("[CRTC:%d:%s] enable: %s %s\n",
12393 crtc->base.base.id, crtc->base.name,
12394 yesno(pipe_config->base.enable), context);
12396 if (!pipe_config->base.enable)
12399 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
12400 DRM_DEBUG_KMS("active: %s, output_types: %s (0x%x), output format: %s\n",
12401 yesno(pipe_config->base.active),
12402 buf, pipe_config->output_types,
12403 output_formats(pipe_config->output_format));
12405 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
12406 transcoder_name(pipe_config->cpu_transcoder),
12407 pipe_config->pipe_bpp, pipe_config->dither);
12409 if (pipe_config->has_pch_encoder)
12410 intel_dump_m_n_config(pipe_config, "fdi",
12411 pipe_config->fdi_lanes,
12412 &pipe_config->fdi_m_n);
12414 if (intel_crtc_has_dp_encoder(pipe_config)) {
12415 intel_dump_m_n_config(pipe_config, "dp m_n",
12416 pipe_config->lane_count, &pipe_config->dp_m_n);
12417 if (pipe_config->has_drrs)
12418 intel_dump_m_n_config(pipe_config, "dp m2_n2",
12419 pipe_config->lane_count,
12420 &pipe_config->dp_m2_n2);
12423 DRM_DEBUG_KMS("audio: %i, infoframes: %i, infoframes enabled: 0x%x\n",
12424 pipe_config->has_audio, pipe_config->has_infoframe,
12425 pipe_config->infoframes.enable);
12427 if (pipe_config->infoframes.enable &
12428 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GENERAL_CONTROL))
12429 DRM_DEBUG_KMS("GCP: 0x%x\n", pipe_config->infoframes.gcp);
12430 if (pipe_config->infoframes.enable &
12431 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI))
12432 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.avi);
12433 if (pipe_config->infoframes.enable &
12434 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_SPD))
12435 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.spd);
12436 if (pipe_config->infoframes.enable &
12437 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_VENDOR))
12438 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.hdmi);
12440 DRM_DEBUG_KMS("requested mode:\n");
12441 drm_mode_debug_printmodeline(&pipe_config->base.mode);
12442 DRM_DEBUG_KMS("adjusted mode:\n");
12443 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
12444 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
12445 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
12446 pipe_config->port_clock,
12447 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
12448 pipe_config->pixel_rate);
12450 if (INTEL_GEN(dev_priv) >= 9)
12451 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
12453 pipe_config->scaler_state.scaler_users,
12454 pipe_config->scaler_state.scaler_id);
12456 if (HAS_GMCH(dev_priv))
12457 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
12458 pipe_config->gmch_pfit.control,
12459 pipe_config->gmch_pfit.pgm_ratios,
12460 pipe_config->gmch_pfit.lvds_border_bits);
12462 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s, force thru: %s\n",
12463 pipe_config->pch_pfit.pos,
12464 pipe_config->pch_pfit.size,
12465 enableddisabled(pipe_config->pch_pfit.enabled),
12466 yesno(pipe_config->pch_pfit.force_thru));
12468 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
12469 pipe_config->ips_enabled, pipe_config->double_wide);
12471 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
12473 if (IS_CHERRYVIEW(dev_priv))
12474 DRM_DEBUG_KMS("cgm_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
12475 pipe_config->cgm_mode, pipe_config->gamma_mode,
12476 pipe_config->gamma_enable, pipe_config->csc_enable);
12478 DRM_DEBUG_KMS("csc_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
12479 pipe_config->csc_mode, pipe_config->gamma_mode,
12480 pipe_config->gamma_enable, pipe_config->csc_enable);
12486 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12487 if (plane->pipe == crtc->pipe)
12488 intel_dump_plane_state(plane_state);
12492 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
12494 struct drm_device *dev = state->base.dev;
12495 struct drm_connector *connector;
12496 struct drm_connector_list_iter conn_iter;
12497 unsigned int used_ports = 0;
12498 unsigned int used_mst_ports = 0;
12502 * We're going to peek into connector->state,
12503 * hence connection_mutex must be held.
12505 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex);
12508 * Walk the connector list instead of the encoder
12509 * list to detect the problem on ddi platforms
12510 * where there's just one encoder per digital port.
12512 drm_connector_list_iter_begin(dev, &conn_iter);
12513 drm_for_each_connector_iter(connector, &conn_iter) {
12514 struct drm_connector_state *connector_state;
12515 struct intel_encoder *encoder;
12518 drm_atomic_get_new_connector_state(&state->base,
12520 if (!connector_state)
12521 connector_state = connector->state;
12523 if (!connector_state->best_encoder)
12526 encoder = to_intel_encoder(connector_state->best_encoder);
12528 WARN_ON(!connector_state->crtc);
12530 switch (encoder->type) {
12531 unsigned int port_mask;
12532 case INTEL_OUTPUT_DDI:
12533 if (WARN_ON(!HAS_DDI(to_i915(dev))))
12535 /* else, fall through */
12536 case INTEL_OUTPUT_DP:
12537 case INTEL_OUTPUT_HDMI:
12538 case INTEL_OUTPUT_EDP:
12539 port_mask = 1 << encoder->port;
12541 /* the same port mustn't appear more than once */
12542 if (used_ports & port_mask)
12545 used_ports |= port_mask;
12547 case INTEL_OUTPUT_DP_MST:
12549 1 << encoder->port;
12555 drm_connector_list_iter_end(&conn_iter);
12557 /* can't mix MST and SST/HDMI on the same port */
12558 if (used_ports & used_mst_ports)
12565 clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
12567 struct drm_i915_private *dev_priv =
12568 to_i915(crtc_state->base.crtc->dev);
12569 struct intel_crtc_state *saved_state;
12571 saved_state = kzalloc(sizeof(*saved_state), GFP_KERNEL);
12575 /* FIXME: before the switch to atomic started, a new pipe_config was
12576 * kzalloc'd. Code that depends on any field being zero should be
12577 * fixed, so that the crtc_state can be safely duplicated. For now,
12578 * only fields that are know to not cause problems are preserved. */
12580 saved_state->scaler_state = crtc_state->scaler_state;
12581 saved_state->shared_dpll = crtc_state->shared_dpll;
12582 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
12583 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
12584 sizeof(saved_state->icl_port_dplls));
12585 saved_state->crc_enabled = crtc_state->crc_enabled;
12586 if (IS_G4X(dev_priv) ||
12587 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
12588 saved_state->wm = crtc_state->wm;
12590 * Save the slave bitmask which gets filled for master crtc state during
12591 * slave atomic check call.
12593 if (is_trans_port_sync_master(crtc_state))
12594 saved_state->sync_mode_slaves_mask =
12595 crtc_state->sync_mode_slaves_mask;
12597 /* Keep base drm_crtc_state intact, only clear our extended struct */
12598 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
12599 memcpy(&crtc_state->base + 1, &saved_state->base + 1,
12600 sizeof(*crtc_state) - sizeof(crtc_state->base));
12602 kfree(saved_state);
12607 intel_modeset_pipe_config(struct intel_crtc_state *pipe_config)
12609 struct drm_crtc *crtc = pipe_config->base.crtc;
12610 struct drm_atomic_state *state = pipe_config->base.state;
12611 struct intel_encoder *encoder;
12612 struct drm_connector *connector;
12613 struct drm_connector_state *connector_state;
12618 ret = clear_intel_crtc_state(pipe_config);
12622 pipe_config->cpu_transcoder =
12623 (enum transcoder) to_intel_crtc(crtc)->pipe;
12626 * Sanitize sync polarity flags based on requested ones. If neither
12627 * positive or negative polarity is requested, treat this as meaning
12628 * negative polarity.
12630 if (!(pipe_config->base.adjusted_mode.flags &
12631 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
12632 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
12634 if (!(pipe_config->base.adjusted_mode.flags &
12635 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
12636 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
12638 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
12643 base_bpp = pipe_config->pipe_bpp;
12646 * Determine the real pipe dimensions. Note that stereo modes can
12647 * increase the actual pipe size due to the frame doubling and
12648 * insertion of additional space for blanks between the frame. This
12649 * is stored in the crtc timings. We use the requested mode to do this
12650 * computation to clearly distinguish it from the adjusted mode, which
12651 * can be changed by the connectors in the below retry loop.
12653 drm_mode_get_hv_timing(&pipe_config->base.mode,
12654 &pipe_config->pipe_src_w,
12655 &pipe_config->pipe_src_h);
12657 for_each_new_connector_in_state(state, connector, connector_state, i) {
12658 if (connector_state->crtc != crtc)
12661 encoder = to_intel_encoder(connector_state->best_encoder);
12663 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
12664 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
12669 * Determine output_types before calling the .compute_config()
12670 * hooks so that the hooks can use this information safely.
12672 if (encoder->compute_output_type)
12673 pipe_config->output_types |=
12674 BIT(encoder->compute_output_type(encoder, pipe_config,
12677 pipe_config->output_types |= BIT(encoder->type);
12681 /* Ensure the port clock defaults are reset when retrying. */
12682 pipe_config->port_clock = 0;
12683 pipe_config->pixel_multiplier = 1;
12685 /* Fill in default crtc timings, allow encoders to overwrite them. */
12686 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
12687 CRTC_STEREO_DOUBLE);
12689 /* Set the crtc_state defaults for trans_port_sync */
12690 pipe_config->master_transcoder = INVALID_TRANSCODER;
12691 ret = icl_add_sync_mode_crtcs(pipe_config);
12693 DRM_DEBUG_KMS("Cannot assign Sync Mode CRTCs: %d\n",
12698 /* Pass our mode to the connectors and the CRTC to give them a chance to
12699 * adjust it according to limitations or connector properties, and also
12700 * a chance to reject the mode entirely.
12702 for_each_new_connector_in_state(state, connector, connector_state, i) {
12703 if (connector_state->crtc != crtc)
12706 encoder = to_intel_encoder(connector_state->best_encoder);
12707 ret = encoder->compute_config(encoder, pipe_config,
12710 if (ret != -EDEADLK)
12711 DRM_DEBUG_KMS("Encoder config failure: %d\n",
12717 /* Set default port clock if not overwritten by the encoder. Needs to be
12718 * done afterwards in case the encoder adjusts the mode. */
12719 if (!pipe_config->port_clock)
12720 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
12721 * pipe_config->pixel_multiplier;
12723 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
12724 if (ret == -EDEADLK)
12727 DRM_DEBUG_KMS("CRTC fixup failed\n");
12731 if (ret == RETRY) {
12732 if (WARN(!retry, "loop in pipe configuration computation\n"))
12735 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
12737 goto encoder_retry;
12740 /* Dithering seems to not pass-through bits correctly when it should, so
12741 * only enable it on 6bpc panels and when its not a compliance
12742 * test requesting 6bpc video pattern.
12744 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
12745 !pipe_config->dither_force_disable;
12746 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
12747 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
12752 bool intel_fuzzy_clock_check(int clock1, int clock2)
12756 if (clock1 == clock2)
12759 if (!clock1 || !clock2)
12762 diff = abs(clock1 - clock2);
12764 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
12771 intel_compare_m_n(unsigned int m, unsigned int n,
12772 unsigned int m2, unsigned int n2,
12775 if (m == m2 && n == n2)
12778 if (exact || !m || !n || !m2 || !n2)
12781 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
12788 } else if (n < n2) {
12798 return intel_fuzzy_clock_check(m, m2);
12802 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
12803 const struct intel_link_m_n *m2_n2,
12806 return m_n->tu == m2_n2->tu &&
12807 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
12808 m2_n2->gmch_m, m2_n2->gmch_n, exact) &&
12809 intel_compare_m_n(m_n->link_m, m_n->link_n,
12810 m2_n2->link_m, m2_n2->link_n, exact);
12814 intel_compare_infoframe(const union hdmi_infoframe *a,
12815 const union hdmi_infoframe *b)
12817 return memcmp(a, b, sizeof(*a)) == 0;
12821 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
12822 bool fastset, const char *name,
12823 const union hdmi_infoframe *a,
12824 const union hdmi_infoframe *b)
12827 if ((drm_debug & DRM_UT_KMS) == 0)
12830 DRM_DEBUG_KMS("fastset mismatch in %s infoframe\n", name);
12831 DRM_DEBUG_KMS("expected:\n");
12832 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
12833 DRM_DEBUG_KMS("found:\n");
12834 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
12836 DRM_ERROR("mismatch in %s infoframe\n", name);
12837 DRM_ERROR("expected:\n");
12838 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
12839 DRM_ERROR("found:\n");
12840 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
12844 static void __printf(4, 5)
12845 pipe_config_mismatch(bool fastset, const struct intel_crtc *crtc,
12846 const char *name, const char *format, ...)
12848 struct va_format vaf;
12851 va_start(args, format);
12856 DRM_DEBUG_KMS("[CRTC:%d:%s] fastset mismatch in %s %pV\n",
12857 crtc->base.base.id, crtc->base.name, name, &vaf);
12859 DRM_ERROR("[CRTC:%d:%s] mismatch in %s %pV\n",
12860 crtc->base.base.id, crtc->base.name, name, &vaf);
12865 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
12867 if (i915_modparams.fastboot != -1)
12868 return i915_modparams.fastboot;
12870 /* Enable fastboot by default on Skylake and newer */
12871 if (INTEL_GEN(dev_priv) >= 9)
12874 /* Enable fastboot by default on VLV and CHV */
12875 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
12878 /* Disabled by default on all others */
12883 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
12884 const struct intel_crtc_state *pipe_config,
12887 struct drm_i915_private *dev_priv = to_i915(current_config->base.crtc->dev);
12888 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
12891 bool fixup_inherited = fastset &&
12892 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
12893 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
12895 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
12896 DRM_DEBUG_KMS("initial modeset and fastboot not set\n");
12900 #define PIPE_CONF_CHECK_X(name) do { \
12901 if (current_config->name != pipe_config->name) { \
12902 pipe_config_mismatch(fastset, crtc, __stringify(name), \
12903 "(expected 0x%08x, found 0x%08x)", \
12904 current_config->name, \
12905 pipe_config->name); \
12910 #define PIPE_CONF_CHECK_I(name) do { \
12911 if (current_config->name != pipe_config->name) { \
12912 pipe_config_mismatch(fastset, crtc, __stringify(name), \
12913 "(expected %i, found %i)", \
12914 current_config->name, \
12915 pipe_config->name); \
12920 #define PIPE_CONF_CHECK_BOOL(name) do { \
12921 if (current_config->name != pipe_config->name) { \
12922 pipe_config_mismatch(fastset, crtc, __stringify(name), \
12923 "(expected %s, found %s)", \
12924 yesno(current_config->name), \
12925 yesno(pipe_config->name)); \
12931 * Checks state where we only read out the enabling, but not the entire
12932 * state itself (like full infoframes or ELD for audio). These states
12933 * require a full modeset on bootup to fix up.
12935 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
12936 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
12937 PIPE_CONF_CHECK_BOOL(name); \
12939 pipe_config_mismatch(fastset, crtc, __stringify(name), \
12940 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)", \
12941 yesno(current_config->name), \
12942 yesno(pipe_config->name)); \
12947 #define PIPE_CONF_CHECK_P(name) do { \
12948 if (current_config->name != pipe_config->name) { \
12949 pipe_config_mismatch(fastset, crtc, __stringify(name), \
12950 "(expected %p, found %p)", \
12951 current_config->name, \
12952 pipe_config->name); \
12957 #define PIPE_CONF_CHECK_M_N(name) do { \
12958 if (!intel_compare_link_m_n(¤t_config->name, \
12959 &pipe_config->name,\
12961 pipe_config_mismatch(fastset, crtc, __stringify(name), \
12962 "(expected tu %i gmch %i/%i link %i/%i, " \
12963 "found tu %i, gmch %i/%i link %i/%i)", \
12964 current_config->name.tu, \
12965 current_config->name.gmch_m, \
12966 current_config->name.gmch_n, \
12967 current_config->name.link_m, \
12968 current_config->name.link_n, \
12969 pipe_config->name.tu, \
12970 pipe_config->name.gmch_m, \
12971 pipe_config->name.gmch_n, \
12972 pipe_config->name.link_m, \
12973 pipe_config->name.link_n); \
12978 /* This is required for BDW+ where there is only one set of registers for
12979 * switching between high and low RR.
12980 * This macro can be used whenever a comparison has to be made between one
12981 * hw state and multiple sw state variables.
12983 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
12984 if (!intel_compare_link_m_n(¤t_config->name, \
12985 &pipe_config->name, !fastset) && \
12986 !intel_compare_link_m_n(¤t_config->alt_name, \
12987 &pipe_config->name, !fastset)) { \
12988 pipe_config_mismatch(fastset, crtc, __stringify(name), \
12989 "(expected tu %i gmch %i/%i link %i/%i, " \
12990 "or tu %i gmch %i/%i link %i/%i, " \
12991 "found tu %i, gmch %i/%i link %i/%i)", \
12992 current_config->name.tu, \
12993 current_config->name.gmch_m, \
12994 current_config->name.gmch_n, \
12995 current_config->name.link_m, \
12996 current_config->name.link_n, \
12997 current_config->alt_name.tu, \
12998 current_config->alt_name.gmch_m, \
12999 current_config->alt_name.gmch_n, \
13000 current_config->alt_name.link_m, \
13001 current_config->alt_name.link_n, \
13002 pipe_config->name.tu, \
13003 pipe_config->name.gmch_m, \
13004 pipe_config->name.gmch_n, \
13005 pipe_config->name.link_m, \
13006 pipe_config->name.link_n); \
13011 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
13012 if ((current_config->name ^ pipe_config->name) & (mask)) { \
13013 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13014 "(%x) (expected %i, found %i)", \
13016 current_config->name & (mask), \
13017 pipe_config->name & (mask)); \
13022 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
13023 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
13024 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13025 "(expected %i, found %i)", \
13026 current_config->name, \
13027 pipe_config->name); \
13032 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
13033 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
13034 &pipe_config->infoframes.name)) { \
13035 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
13036 ¤t_config->infoframes.name, \
13037 &pipe_config->infoframes.name); \
13042 #define PIPE_CONF_CHECK_COLOR_LUT(name1, name2, bit_precision) do { \
13043 if (current_config->name1 != pipe_config->name1) { \
13044 pipe_config_mismatch(fastset, crtc, __stringify(name1), \
13045 "(expected %i, found %i, won't compare lut values)", \
13046 current_config->name1, \
13047 pipe_config->name1); \
13050 if (!intel_color_lut_equal(current_config->name2, \
13051 pipe_config->name2, pipe_config->name1, \
13052 bit_precision)) { \
13053 pipe_config_mismatch(fastset, crtc, __stringify(name2), \
13054 "hw_state doesn't match sw_state"); \
13060 #define PIPE_CONF_QUIRK(quirk) \
13061 ((current_config->quirks | pipe_config->quirks) & (quirk))
13063 PIPE_CONF_CHECK_I(cpu_transcoder);
13065 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
13066 PIPE_CONF_CHECK_I(fdi_lanes);
13067 PIPE_CONF_CHECK_M_N(fdi_m_n);
13069 PIPE_CONF_CHECK_I(lane_count);
13070 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
13072 if (INTEL_GEN(dev_priv) < 8) {
13073 PIPE_CONF_CHECK_M_N(dp_m_n);
13075 if (current_config->has_drrs)
13076 PIPE_CONF_CHECK_M_N(dp_m2_n2);
13078 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
13080 PIPE_CONF_CHECK_X(output_types);
13082 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
13083 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
13084 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
13085 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
13086 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
13087 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
13089 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
13090 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
13091 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
13092 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
13093 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
13094 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
13096 PIPE_CONF_CHECK_I(pixel_multiplier);
13097 PIPE_CONF_CHECK_I(output_format);
13098 PIPE_CONF_CHECK_I(dc3co_exitline);
13099 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
13100 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
13101 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13102 PIPE_CONF_CHECK_BOOL(limited_color_range);
13104 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
13105 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
13106 PIPE_CONF_CHECK_BOOL(has_infoframe);
13107 PIPE_CONF_CHECK_BOOL(fec_enable);
13109 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
13111 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
13112 DRM_MODE_FLAG_INTERLACE);
13114 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
13115 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
13116 DRM_MODE_FLAG_PHSYNC);
13117 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
13118 DRM_MODE_FLAG_NHSYNC);
13119 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
13120 DRM_MODE_FLAG_PVSYNC);
13121 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
13122 DRM_MODE_FLAG_NVSYNC);
13125 PIPE_CONF_CHECK_X(gmch_pfit.control);
13126 /* pfit ratios are autocomputed by the hw on gen4+ */
13127 if (INTEL_GEN(dev_priv) < 4)
13128 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
13129 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
13132 * Changing the EDP transcoder input mux
13133 * (A_ONOFF vs. A_ON) requires a full modeset.
13135 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
13138 PIPE_CONF_CHECK_I(pipe_src_w);
13139 PIPE_CONF_CHECK_I(pipe_src_h);
13141 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
13142 if (current_config->pch_pfit.enabled) {
13143 PIPE_CONF_CHECK_X(pch_pfit.pos);
13144 PIPE_CONF_CHECK_X(pch_pfit.size);
13147 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
13148 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
13150 PIPE_CONF_CHECK_X(gamma_mode);
13151 if (IS_CHERRYVIEW(dev_priv))
13152 PIPE_CONF_CHECK_X(cgm_mode);
13154 PIPE_CONF_CHECK_X(csc_mode);
13155 PIPE_CONF_CHECK_BOOL(gamma_enable);
13156 PIPE_CONF_CHECK_BOOL(csc_enable);
13158 bp_gamma = intel_color_get_gamma_bit_precision(pipe_config);
13160 PIPE_CONF_CHECK_COLOR_LUT(gamma_mode, base.gamma_lut, bp_gamma);
13164 PIPE_CONF_CHECK_BOOL(double_wide);
13166 PIPE_CONF_CHECK_P(shared_dpll);
13167 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
13168 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
13169 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
13170 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
13171 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
13172 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
13173 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
13174 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
13175 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
13176 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
13177 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
13178 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
13179 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
13180 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
13181 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
13182 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
13183 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
13184 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
13185 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
13186 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
13187 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
13188 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
13189 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
13190 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
13191 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
13192 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
13193 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
13194 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
13195 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
13196 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
13197 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
13199 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
13200 PIPE_CONF_CHECK_X(dsi_pll.div);
13202 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
13203 PIPE_CONF_CHECK_I(pipe_bpp);
13205 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
13206 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
13208 PIPE_CONF_CHECK_I(min_voltage_level);
13210 PIPE_CONF_CHECK_X(infoframes.enable);
13211 PIPE_CONF_CHECK_X(infoframes.gcp);
13212 PIPE_CONF_CHECK_INFOFRAME(avi);
13213 PIPE_CONF_CHECK_INFOFRAME(spd);
13214 PIPE_CONF_CHECK_INFOFRAME(hdmi);
13215 PIPE_CONF_CHECK_INFOFRAME(drm);
13217 PIPE_CONF_CHECK_I(sync_mode_slaves_mask);
13218 PIPE_CONF_CHECK_I(master_transcoder);
13220 #undef PIPE_CONF_CHECK_X
13221 #undef PIPE_CONF_CHECK_I
13222 #undef PIPE_CONF_CHECK_BOOL
13223 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
13224 #undef PIPE_CONF_CHECK_P
13225 #undef PIPE_CONF_CHECK_FLAGS
13226 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
13227 #undef PIPE_CONF_CHECK_COLOR_LUT
13228 #undef PIPE_CONF_QUIRK
13233 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
13234 const struct intel_crtc_state *pipe_config)
13236 if (pipe_config->has_pch_encoder) {
13237 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
13238 &pipe_config->fdi_m_n);
13239 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
13242 * FDI already provided one idea for the dotclock.
13243 * Yell if the encoder disagrees.
13245 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
13246 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
13247 fdi_dotclock, dotclock);
13251 static void verify_wm_state(struct intel_crtc *crtc,
13252 struct intel_crtc_state *new_crtc_state)
13254 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13255 struct skl_hw_state {
13256 struct skl_ddb_entry ddb_y[I915_MAX_PLANES];
13257 struct skl_ddb_entry ddb_uv[I915_MAX_PLANES];
13258 struct skl_ddb_allocation ddb;
13259 struct skl_pipe_wm wm;
13261 struct skl_ddb_allocation *sw_ddb;
13262 struct skl_pipe_wm *sw_wm;
13263 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
13264 const enum pipe pipe = crtc->pipe;
13265 int plane, level, max_level = ilk_wm_max_level(dev_priv);
13267 if (INTEL_GEN(dev_priv) < 9 || !new_crtc_state->base.active)
13270 hw = kzalloc(sizeof(*hw), GFP_KERNEL);
13274 skl_pipe_wm_get_hw_state(crtc, &hw->wm);
13275 sw_wm = &new_crtc_state->wm.skl.optimal;
13277 skl_pipe_ddb_get_hw_state(crtc, hw->ddb_y, hw->ddb_uv);
13279 skl_ddb_get_hw_state(dev_priv, &hw->ddb);
13280 sw_ddb = &dev_priv->wm.skl_hw.ddb;
13282 if (INTEL_GEN(dev_priv) >= 11 &&
13283 hw->ddb.enabled_slices != sw_ddb->enabled_slices)
13284 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
13285 sw_ddb->enabled_slices,
13286 hw->ddb.enabled_slices);
13289 for_each_universal_plane(dev_priv, pipe, plane) {
13290 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
13292 hw_plane_wm = &hw->wm.planes[plane];
13293 sw_plane_wm = &sw_wm->planes[plane];
13296 for (level = 0; level <= max_level; level++) {
13297 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
13298 &sw_plane_wm->wm[level]))
13301 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",
13302 pipe_name(pipe), plane + 1, level,
13303 sw_plane_wm->wm[level].plane_en,
13304 sw_plane_wm->wm[level].plane_res_b,
13305 sw_plane_wm->wm[level].plane_res_l,
13306 hw_plane_wm->wm[level].plane_en,
13307 hw_plane_wm->wm[level].plane_res_b,
13308 hw_plane_wm->wm[level].plane_res_l);
13311 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
13312 &sw_plane_wm->trans_wm)) {
13313 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",
13314 pipe_name(pipe), plane + 1,
13315 sw_plane_wm->trans_wm.plane_en,
13316 sw_plane_wm->trans_wm.plane_res_b,
13317 sw_plane_wm->trans_wm.plane_res_l,
13318 hw_plane_wm->trans_wm.plane_en,
13319 hw_plane_wm->trans_wm.plane_res_b,
13320 hw_plane_wm->trans_wm.plane_res_l);
13324 hw_ddb_entry = &hw->ddb_y[plane];
13325 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[plane];
13327 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
13328 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
13329 pipe_name(pipe), plane + 1,
13330 sw_ddb_entry->start, sw_ddb_entry->end,
13331 hw_ddb_entry->start, hw_ddb_entry->end);
13337 * If the cursor plane isn't active, we may not have updated it's ddb
13338 * allocation. In that case since the ddb allocation will be updated
13339 * once the plane becomes visible, we can skip this check
13342 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
13344 hw_plane_wm = &hw->wm.planes[PLANE_CURSOR];
13345 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
13348 for (level = 0; level <= max_level; level++) {
13349 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
13350 &sw_plane_wm->wm[level]))
13353 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",
13354 pipe_name(pipe), level,
13355 sw_plane_wm->wm[level].plane_en,
13356 sw_plane_wm->wm[level].plane_res_b,
13357 sw_plane_wm->wm[level].plane_res_l,
13358 hw_plane_wm->wm[level].plane_en,
13359 hw_plane_wm->wm[level].plane_res_b,
13360 hw_plane_wm->wm[level].plane_res_l);
13363 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
13364 &sw_plane_wm->trans_wm)) {
13365 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13367 sw_plane_wm->trans_wm.plane_en,
13368 sw_plane_wm->trans_wm.plane_res_b,
13369 sw_plane_wm->trans_wm.plane_res_l,
13370 hw_plane_wm->trans_wm.plane_en,
13371 hw_plane_wm->trans_wm.plane_res_b,
13372 hw_plane_wm->trans_wm.plane_res_l);
13376 hw_ddb_entry = &hw->ddb_y[PLANE_CURSOR];
13377 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR];
13379 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
13380 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
13382 sw_ddb_entry->start, sw_ddb_entry->end,
13383 hw_ddb_entry->start, hw_ddb_entry->end);
13391 verify_connector_state(struct intel_atomic_state *state,
13392 struct intel_crtc *crtc)
13394 struct drm_connector *connector;
13395 struct drm_connector_state *new_conn_state;
13398 for_each_new_connector_in_state(&state->base, connector, new_conn_state, i) {
13399 struct drm_encoder *encoder = connector->encoder;
13400 struct intel_crtc_state *crtc_state = NULL;
13402 if (new_conn_state->crtc != &crtc->base)
13406 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
13408 intel_connector_verify_state(crtc_state, new_conn_state);
13410 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
13411 "connector's atomic encoder doesn't match legacy encoder\n");
13416 verify_encoder_state(struct drm_i915_private *dev_priv, struct intel_atomic_state *state)
13418 struct intel_encoder *encoder;
13419 struct drm_connector *connector;
13420 struct drm_connector_state *old_conn_state, *new_conn_state;
13423 for_each_intel_encoder(&dev_priv->drm, encoder) {
13424 bool enabled = false, found = false;
13427 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
13428 encoder->base.base.id,
13429 encoder->base.name);
13431 for_each_oldnew_connector_in_state(&state->base, connector, old_conn_state,
13432 new_conn_state, i) {
13433 if (old_conn_state->best_encoder == &encoder->base)
13436 if (new_conn_state->best_encoder != &encoder->base)
13438 found = enabled = true;
13440 I915_STATE_WARN(new_conn_state->crtc !=
13441 encoder->base.crtc,
13442 "connector's crtc doesn't match encoder crtc\n");
13448 I915_STATE_WARN(!!encoder->base.crtc != enabled,
13449 "encoder's enabled state mismatch "
13450 "(expected %i, found %i)\n",
13451 !!encoder->base.crtc, enabled);
13453 if (!encoder->base.crtc) {
13456 active = encoder->get_hw_state(encoder, &pipe);
13457 I915_STATE_WARN(active,
13458 "encoder detached but still enabled on pipe %c.\n",
13465 verify_crtc_state(struct intel_crtc *crtc,
13466 struct intel_crtc_state *old_crtc_state,
13467 struct intel_crtc_state *new_crtc_state)
13469 struct drm_device *dev = crtc->base.dev;
13470 struct drm_i915_private *dev_priv = to_i915(dev);
13471 struct intel_encoder *encoder;
13472 struct intel_crtc_state *pipe_config;
13473 struct drm_atomic_state *state;
13476 state = old_crtc_state->base.state;
13477 __drm_atomic_helper_crtc_destroy_state(&old_crtc_state->base);
13478 pipe_config = old_crtc_state;
13479 memset(pipe_config, 0, sizeof(*pipe_config));
13480 pipe_config->base.crtc = &crtc->base;
13481 pipe_config->base.state = state;
13483 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.base.id, crtc->base.name);
13485 active = dev_priv->display.get_pipe_config(crtc, pipe_config);
13487 /* we keep both pipes enabled on 830 */
13488 if (IS_I830(dev_priv))
13489 active = new_crtc_state->base.active;
13491 I915_STATE_WARN(new_crtc_state->base.active != active,
13492 "crtc active state doesn't match with hw state "
13493 "(expected %i, found %i)\n", new_crtc_state->base.active, active);
13495 I915_STATE_WARN(crtc->active != new_crtc_state->base.active,
13496 "transitional active state does not match atomic hw state "
13497 "(expected %i, found %i)\n", new_crtc_state->base.active, crtc->active);
13499 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
13502 active = encoder->get_hw_state(encoder, &pipe);
13503 I915_STATE_WARN(active != new_crtc_state->base.active,
13504 "[ENCODER:%i] active %i with crtc active %i\n",
13505 encoder->base.base.id, active, new_crtc_state->base.active);
13507 I915_STATE_WARN(active && crtc->pipe != pipe,
13508 "Encoder connected to wrong pipe %c\n",
13512 encoder->get_config(encoder, pipe_config);
13515 intel_crtc_compute_pixel_rate(pipe_config);
13517 if (!new_crtc_state->base.active)
13520 intel_pipe_config_sanity_check(dev_priv, pipe_config);
13522 if (!intel_pipe_config_compare(new_crtc_state,
13523 pipe_config, false)) {
13524 I915_STATE_WARN(1, "pipe state doesn't match!\n");
13525 intel_dump_pipe_config(pipe_config, NULL, "[hw state]");
13526 intel_dump_pipe_config(new_crtc_state, NULL, "[sw state]");
13531 intel_verify_planes(struct intel_atomic_state *state)
13533 struct intel_plane *plane;
13534 const struct intel_plane_state *plane_state;
13537 for_each_new_intel_plane_in_state(state, plane,
13539 assert_plane(plane, plane_state->planar_slave ||
13540 plane_state->base.visible);
13544 verify_single_dpll_state(struct drm_i915_private *dev_priv,
13545 struct intel_shared_dpll *pll,
13546 struct intel_crtc *crtc,
13547 struct intel_crtc_state *new_crtc_state)
13549 struct intel_dpll_hw_state dpll_hw_state;
13550 unsigned int crtc_mask;
13553 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
13555 DRM_DEBUG_KMS("%s\n", pll->info->name);
13557 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
13559 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
13560 I915_STATE_WARN(!pll->on && pll->active_mask,
13561 "pll in active use but not on in sw tracking\n");
13562 I915_STATE_WARN(pll->on && !pll->active_mask,
13563 "pll is on but not used by any active crtc\n");
13564 I915_STATE_WARN(pll->on != active,
13565 "pll on state mismatch (expected %i, found %i)\n",
13570 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
13571 "more active pll users than references: %x vs %x\n",
13572 pll->active_mask, pll->state.crtc_mask);
13577 crtc_mask = drm_crtc_mask(&crtc->base);
13579 if (new_crtc_state->base.active)
13580 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
13581 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
13582 pipe_name(drm_crtc_index(&crtc->base)), pll->active_mask);
13584 I915_STATE_WARN(pll->active_mask & crtc_mask,
13585 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
13586 pipe_name(drm_crtc_index(&crtc->base)), pll->active_mask);
13588 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
13589 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
13590 crtc_mask, pll->state.crtc_mask);
13592 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
13594 sizeof(dpll_hw_state)),
13595 "pll hw state mismatch\n");
13599 verify_shared_dpll_state(struct intel_crtc *crtc,
13600 struct intel_crtc_state *old_crtc_state,
13601 struct intel_crtc_state *new_crtc_state)
13603 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13605 if (new_crtc_state->shared_dpll)
13606 verify_single_dpll_state(dev_priv, new_crtc_state->shared_dpll, crtc, new_crtc_state);
13608 if (old_crtc_state->shared_dpll &&
13609 old_crtc_state->shared_dpll != new_crtc_state->shared_dpll) {
13610 unsigned int crtc_mask = drm_crtc_mask(&crtc->base);
13611 struct intel_shared_dpll *pll = old_crtc_state->shared_dpll;
13613 I915_STATE_WARN(pll->active_mask & crtc_mask,
13614 "pll active mismatch (didn't expect pipe %c in active mask)\n",
13615 pipe_name(drm_crtc_index(&crtc->base)));
13616 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
13617 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
13618 pipe_name(drm_crtc_index(&crtc->base)));
13623 intel_modeset_verify_crtc(struct intel_crtc *crtc,
13624 struct intel_atomic_state *state,
13625 struct intel_crtc_state *old_crtc_state,
13626 struct intel_crtc_state *new_crtc_state)
13628 if (!needs_modeset(new_crtc_state) && !new_crtc_state->update_pipe)
13631 verify_wm_state(crtc, new_crtc_state);
13632 verify_connector_state(state, crtc);
13633 verify_crtc_state(crtc, old_crtc_state, new_crtc_state);
13634 verify_shared_dpll_state(crtc, old_crtc_state, new_crtc_state);
13638 verify_disabled_dpll_state(struct drm_i915_private *dev_priv)
13642 for (i = 0; i < dev_priv->num_shared_dpll; i++)
13643 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
13647 intel_modeset_verify_disabled(struct drm_i915_private *dev_priv,
13648 struct intel_atomic_state *state)
13650 verify_encoder_state(dev_priv, state);
13651 verify_connector_state(state, NULL);
13652 verify_disabled_dpll_state(dev_priv);
13656 intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state)
13658 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
13659 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13660 const struct drm_display_mode *adjusted_mode =
13661 &crtc_state->base.adjusted_mode;
13663 drm_calc_timestamping_constants(&crtc->base, adjusted_mode);
13666 * The scanline counter increments at the leading edge of hsync.
13668 * On most platforms it starts counting from vtotal-1 on the
13669 * first active line. That means the scanline counter value is
13670 * always one less than what we would expect. Ie. just after
13671 * start of vblank, which also occurs at start of hsync (on the
13672 * last active line), the scanline counter will read vblank_start-1.
13674 * On gen2 the scanline counter starts counting from 1 instead
13675 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
13676 * to keep the value positive), instead of adding one.
13678 * On HSW+ the behaviour of the scanline counter depends on the output
13679 * type. For DP ports it behaves like most other platforms, but on HDMI
13680 * there's an extra 1 line difference. So we need to add two instead of
13681 * one to the value.
13683 * On VLV/CHV DSI the scanline counter would appear to increment
13684 * approx. 1/3 of a scanline before start of vblank. Unfortunately
13685 * that means we can't tell whether we're in vblank or not while
13686 * we're on that particular line. We must still set scanline_offset
13687 * to 1 so that the vblank timestamps come out correct when we query
13688 * the scanline counter from within the vblank interrupt handler.
13689 * However if queried just before the start of vblank we'll get an
13690 * answer that's slightly in the future.
13692 if (IS_GEN(dev_priv, 2)) {
13695 vtotal = adjusted_mode->crtc_vtotal;
13696 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
13699 crtc->scanline_offset = vtotal - 1;
13700 } else if (HAS_DDI(dev_priv) &&
13701 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
13702 crtc->scanline_offset = 2;
13704 crtc->scanline_offset = 1;
13708 static void intel_modeset_clear_plls(struct intel_atomic_state *state)
13710 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13711 struct intel_crtc_state *new_crtc_state;
13712 struct intel_crtc *crtc;
13715 if (!dev_priv->display.crtc_compute_clock)
13718 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
13719 if (!needs_modeset(new_crtc_state))
13722 intel_release_shared_dplls(state, crtc);
13727 * This implements the workaround described in the "notes" section of the mode
13728 * set sequence documentation. When going from no pipes or single pipe to
13729 * multiple pipes, and planes are enabled after the pipe, we need to wait at
13730 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
13732 static int haswell_mode_set_planes_workaround(struct intel_atomic_state *state)
13734 struct intel_crtc_state *crtc_state;
13735 struct intel_crtc *crtc;
13736 struct intel_crtc_state *first_crtc_state = NULL;
13737 struct intel_crtc_state *other_crtc_state = NULL;
13738 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
13741 /* look at all crtc's that are going to be enabled in during modeset */
13742 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
13743 if (!crtc_state->base.active ||
13744 !needs_modeset(crtc_state))
13747 if (first_crtc_state) {
13748 other_crtc_state = crtc_state;
13751 first_crtc_state = crtc_state;
13752 first_pipe = crtc->pipe;
13756 /* No workaround needed? */
13757 if (!first_crtc_state)
13760 /* w/a possibly needed, check how many crtc's are already enabled. */
13761 for_each_intel_crtc(state->base.dev, crtc) {
13762 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
13763 if (IS_ERR(crtc_state))
13764 return PTR_ERR(crtc_state);
13766 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
13768 if (!crtc_state->base.active ||
13769 needs_modeset(crtc_state))
13772 /* 2 or more enabled crtcs means no need for w/a */
13773 if (enabled_pipe != INVALID_PIPE)
13776 enabled_pipe = crtc->pipe;
13779 if (enabled_pipe != INVALID_PIPE)
13780 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
13781 else if (other_crtc_state)
13782 other_crtc_state->hsw_workaround_pipe = first_pipe;
13787 static int intel_modeset_checks(struct intel_atomic_state *state)
13789 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13790 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13791 struct intel_crtc *crtc;
13794 /* keep the current setting */
13795 if (!state->cdclk.force_min_cdclk_changed)
13796 state->cdclk.force_min_cdclk = dev_priv->cdclk.force_min_cdclk;
13798 state->modeset = true;
13799 state->active_pipes = dev_priv->active_pipes;
13800 state->cdclk.logical = dev_priv->cdclk.logical;
13801 state->cdclk.actual = dev_priv->cdclk.actual;
13803 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13804 new_crtc_state, i) {
13805 if (new_crtc_state->base.active)
13806 state->active_pipes |= BIT(crtc->pipe);
13808 state->active_pipes &= ~BIT(crtc->pipe);
13810 if (old_crtc_state->base.active != new_crtc_state->base.active)
13811 state->active_pipe_changes |= BIT(crtc->pipe);
13814 if (state->active_pipe_changes) {
13815 ret = intel_atomic_lock_global_state(state);
13820 ret = intel_modeset_calc_cdclk(state);
13824 intel_modeset_clear_plls(state);
13826 if (IS_HASWELL(dev_priv))
13827 return haswell_mode_set_planes_workaround(state);
13833 * Handle calculation of various watermark data at the end of the atomic check
13834 * phase. The code here should be run after the per-crtc and per-plane 'check'
13835 * handlers to ensure that all derived state has been updated.
13837 static int calc_watermark_data(struct intel_atomic_state *state)
13839 struct drm_device *dev = state->base.dev;
13840 struct drm_i915_private *dev_priv = to_i915(dev);
13842 /* Is there platform-specific watermark information to calculate? */
13843 if (dev_priv->display.compute_global_watermarks)
13844 return dev_priv->display.compute_global_watermarks(state);
13849 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
13850 struct intel_crtc_state *new_crtc_state)
13852 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
13855 new_crtc_state->base.mode_changed = false;
13856 new_crtc_state->update_pipe = true;
13859 * If we're not doing the full modeset we want to
13860 * keep the current M/N values as they may be
13861 * sufficiently different to the computed values
13862 * to cause problems.
13864 * FIXME: should really copy more fuzzy state here
13866 new_crtc_state->fdi_m_n = old_crtc_state->fdi_m_n;
13867 new_crtc_state->dp_m_n = old_crtc_state->dp_m_n;
13868 new_crtc_state->dp_m2_n2 = old_crtc_state->dp_m2_n2;
13869 new_crtc_state->has_drrs = old_crtc_state->has_drrs;
13872 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
13873 struct intel_crtc *crtc,
13876 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13877 struct intel_plane *plane;
13879 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
13880 struct intel_plane_state *plane_state;
13882 if ((plane_ids_mask & BIT(plane->id)) == 0)
13885 plane_state = intel_atomic_get_plane_state(state, plane);
13886 if (IS_ERR(plane_state))
13887 return PTR_ERR(plane_state);
13893 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)
13895 /* See {hsw,vlv,ivb}_plane_ratio() */
13896 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||
13897 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
13898 IS_IVYBRIDGE(dev_priv);
13901 static int intel_atomic_check_planes(struct intel_atomic_state *state,
13902 bool *need_modeset)
13904 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13905 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13906 struct intel_plane_state *plane_state;
13907 struct intel_plane *plane;
13908 struct intel_crtc *crtc;
13911 ret = icl_add_linked_planes(state);
13915 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
13916 ret = intel_plane_atomic_check(state, plane);
13918 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] atomic driver check failed\n",
13919 plane->base.base.id, plane->base.name);
13924 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13925 new_crtc_state, i) {
13926 u8 old_active_planes, new_active_planes;
13928 ret = icl_check_nv12_planes(new_crtc_state);
13933 * On some platforms the number of active planes affects
13934 * the planes' minimum cdclk calculation. Add such planes
13935 * to the state before we compute the minimum cdclk.
13937 if (!active_planes_affects_min_cdclk(dev_priv))
13940 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
13941 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
13943 if (hweight8(old_active_planes) == hweight8(new_active_planes))
13946 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
13952 * active_planes bitmask has been updated, and potentially
13953 * affected planes are part of the state. We can now
13954 * compute the minimum cdclk for each plane.
13956 for_each_new_intel_plane_in_state(state, plane, plane_state, i)
13957 *need_modeset |= intel_plane_calc_min_cdclk(state, plane);
13962 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
13964 struct intel_crtc_state *crtc_state;
13965 struct intel_crtc *crtc;
13968 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
13969 int ret = intel_crtc_atomic_check(state, crtc);
13971 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] atomic driver check failed\n",
13972 crtc->base.base.id, crtc->base.name);
13981 * intel_atomic_check - validate state object
13983 * @_state: state to validate
13985 static int intel_atomic_check(struct drm_device *dev,
13986 struct drm_atomic_state *_state)
13988 struct drm_i915_private *dev_priv = to_i915(dev);
13989 struct intel_atomic_state *state = to_intel_atomic_state(_state);
13990 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13991 struct intel_crtc *crtc;
13993 bool any_ms = false;
13995 /* Catch I915_MODE_FLAG_INHERITED */
13996 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13997 new_crtc_state, i) {
13998 if (new_crtc_state->base.mode.private_flags !=
13999 old_crtc_state->base.mode.private_flags)
14000 new_crtc_state->base.mode_changed = true;
14003 ret = drm_atomic_helper_check_modeset(dev, &state->base);
14007 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14008 new_crtc_state, i) {
14009 if (!needs_modeset(new_crtc_state))
14012 if (!new_crtc_state->base.enable) {
14017 ret = intel_modeset_pipe_config(new_crtc_state);
14021 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
14023 if (needs_modeset(new_crtc_state))
14027 if (any_ms && !check_digital_port_conflicts(state)) {
14028 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
14033 ret = drm_dp_mst_atomic_check(&state->base);
14037 any_ms |= state->cdclk.force_min_cdclk_changed;
14039 ret = intel_atomic_check_planes(state, &any_ms);
14044 ret = intel_modeset_checks(state);
14048 state->cdclk.logical = dev_priv->cdclk.logical;
14051 ret = intel_atomic_check_crtcs(state);
14055 intel_fbc_choose_crtc(dev_priv, state);
14056 ret = calc_watermark_data(state);
14060 ret = intel_bw_atomic_check(state);
14064 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14065 new_crtc_state, i) {
14066 if (!needs_modeset(new_crtc_state) &&
14067 !new_crtc_state->update_pipe)
14070 intel_dump_pipe_config(new_crtc_state, state,
14071 needs_modeset(new_crtc_state) ?
14072 "[modeset]" : "[fastset]");
14078 if (ret == -EDEADLK)
14082 * FIXME would probably be nice to know which crtc specifically
14083 * caused the failure, in cases where we can pinpoint it.
14085 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14087 intel_dump_pipe_config(new_crtc_state, state, "[failed]");
14092 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
14094 return drm_atomic_helper_prepare_planes(state->base.dev,
14098 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
14100 struct drm_device *dev = crtc->base.dev;
14101 struct drm_vblank_crtc *vblank = &dev->vblank[drm_crtc_index(&crtc->base)];
14103 if (!vblank->max_vblank_count)
14104 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
14106 return crtc->base.funcs->get_vblank_counter(&crtc->base);
14109 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
14110 struct intel_crtc_state *crtc_state)
14112 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14114 if (!IS_GEN(dev_priv, 2))
14115 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
14117 if (crtc_state->has_pch_encoder) {
14118 enum pipe pch_transcoder =
14119 intel_crtc_pch_transcoder(crtc);
14121 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
14125 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
14126 const struct intel_crtc_state *new_crtc_state)
14128 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
14129 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14132 * Update pipe size and adjust fitter if needed: the reason for this is
14133 * that in compute_mode_changes we check the native mode (not the pfit
14134 * mode) to see if we can flip rather than do a full mode set. In the
14135 * fastboot case, we'll flip, but if we don't update the pipesrc and
14136 * pfit state, we'll end up with a big fb scanned out into the wrong
14139 intel_set_pipe_src_size(new_crtc_state);
14141 /* on skylake this is done by detaching scalers */
14142 if (INTEL_GEN(dev_priv) >= 9) {
14143 skl_detach_scalers(new_crtc_state);
14145 if (new_crtc_state->pch_pfit.enabled)
14146 skylake_pfit_enable(new_crtc_state);
14147 } else if (HAS_PCH_SPLIT(dev_priv)) {
14148 if (new_crtc_state->pch_pfit.enabled)
14149 ironlake_pfit_enable(new_crtc_state);
14150 else if (old_crtc_state->pch_pfit.enabled)
14151 ironlake_pfit_disable(old_crtc_state);
14154 if (INTEL_GEN(dev_priv) >= 11)
14155 icl_set_pipe_chicken(crtc);
14158 static void commit_pipe_config(struct intel_atomic_state *state,
14159 struct intel_crtc_state *old_crtc_state,
14160 struct intel_crtc_state *new_crtc_state)
14162 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14163 bool modeset = needs_modeset(new_crtc_state);
14166 * During modesets pipe configuration was programmed as the
14167 * CRTC was enabled.
14170 if (new_crtc_state->base.color_mgmt_changed ||
14171 new_crtc_state->update_pipe)
14172 intel_color_commit(new_crtc_state);
14174 if (INTEL_GEN(dev_priv) >= 9)
14175 skl_detach_scalers(new_crtc_state);
14177 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
14178 bdw_set_pipemisc(new_crtc_state);
14180 if (new_crtc_state->update_pipe)
14181 intel_pipe_fastset(old_crtc_state, new_crtc_state);
14184 if (dev_priv->display.atomic_update_watermarks)
14185 dev_priv->display.atomic_update_watermarks(state,
14189 static void intel_update_crtc(struct intel_crtc *crtc,
14190 struct intel_atomic_state *state,
14191 struct intel_crtc_state *old_crtc_state,
14192 struct intel_crtc_state *new_crtc_state)
14194 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14195 bool modeset = needs_modeset(new_crtc_state);
14196 struct intel_plane_state *new_plane_state =
14197 intel_atomic_get_new_plane_state(state,
14198 to_intel_plane(crtc->base.primary));
14201 intel_crtc_update_active_timings(new_crtc_state);
14203 dev_priv->display.crtc_enable(new_crtc_state, state);
14205 /* vblanks work again, re-enable pipe CRC. */
14206 intel_crtc_enable_pipe_crc(crtc);
14208 if (new_crtc_state->preload_luts &&
14209 (new_crtc_state->base.color_mgmt_changed ||
14210 new_crtc_state->update_pipe))
14211 intel_color_load_luts(new_crtc_state);
14213 intel_pre_plane_update(old_crtc_state, new_crtc_state);
14215 if (new_crtc_state->update_pipe)
14216 intel_encoders_update_pipe(crtc, new_crtc_state, state);
14219 if (new_crtc_state->update_pipe && !new_crtc_state->enable_fbc)
14220 intel_fbc_disable(crtc);
14221 else if (new_plane_state)
14222 intel_fbc_enable(crtc, new_crtc_state, new_plane_state);
14224 /* Perform vblank evasion around commit operation */
14225 intel_pipe_update_start(new_crtc_state);
14227 commit_pipe_config(state, old_crtc_state, new_crtc_state);
14229 if (INTEL_GEN(dev_priv) >= 9)
14230 skl_update_planes_on_crtc(state, crtc);
14232 i9xx_update_planes_on_crtc(state, crtc);
14234 intel_pipe_update_end(new_crtc_state);
14237 * We usually enable FIFO underrun interrupts as part of the
14238 * CRTC enable sequence during modesets. But when we inherit a
14239 * valid pipe configuration from the BIOS we need to take care
14240 * of enabling them on the CRTC's first fastset.
14242 if (new_crtc_state->update_pipe && !modeset &&
14243 old_crtc_state->base.mode.private_flags & I915_MODE_FLAG_INHERITED)
14244 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
14247 static struct intel_crtc *intel_get_slave_crtc(const struct intel_crtc_state *new_crtc_state)
14249 struct drm_i915_private *dev_priv = to_i915(new_crtc_state->base.crtc->dev);
14250 enum transcoder slave_transcoder;
14252 WARN_ON(!is_power_of_2(new_crtc_state->sync_mode_slaves_mask));
14254 slave_transcoder = ffs(new_crtc_state->sync_mode_slaves_mask) - 1;
14255 return intel_get_crtc_for_pipe(dev_priv,
14256 (enum pipe)slave_transcoder);
14259 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
14260 struct intel_crtc_state *old_crtc_state,
14261 struct intel_crtc_state *new_crtc_state,
14262 struct intel_crtc *crtc)
14264 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14266 intel_crtc_disable_planes(state, crtc);
14269 * We need to disable pipe CRC before disabling the pipe,
14270 * or we race against vblank off.
14272 intel_crtc_disable_pipe_crc(crtc);
14274 dev_priv->display.crtc_disable(old_crtc_state, state);
14275 crtc->active = false;
14276 intel_fbc_disable(crtc);
14277 intel_disable_shared_dpll(old_crtc_state);
14280 * Underruns don't always raise interrupts,
14281 * so check manually.
14283 intel_check_cpu_fifo_underruns(dev_priv);
14284 intel_check_pch_fifo_underruns(dev_priv);
14286 /* FIXME unify this for all platforms */
14287 if (!new_crtc_state->base.active &&
14288 !HAS_GMCH(dev_priv) &&
14289 dev_priv->display.initial_watermarks)
14290 dev_priv->display.initial_watermarks(state,
14294 static void intel_trans_port_sync_modeset_disables(struct intel_atomic_state *state,
14295 struct intel_crtc *crtc,
14296 struct intel_crtc_state *old_crtc_state,
14297 struct intel_crtc_state *new_crtc_state)
14299 struct intel_crtc *slave_crtc = intel_get_slave_crtc(new_crtc_state);
14300 struct intel_crtc_state *new_slave_crtc_state =
14301 intel_atomic_get_new_crtc_state(state, slave_crtc);
14302 struct intel_crtc_state *old_slave_crtc_state =
14303 intel_atomic_get_old_crtc_state(state, slave_crtc);
14305 WARN_ON(!slave_crtc || !new_slave_crtc_state ||
14306 !old_slave_crtc_state);
14308 /* Disable Slave first */
14309 intel_pre_plane_update(old_slave_crtc_state, new_slave_crtc_state);
14310 if (old_slave_crtc_state->base.active)
14311 intel_old_crtc_state_disables(state,
14312 old_slave_crtc_state,
14313 new_slave_crtc_state,
14316 /* Disable Master */
14317 intel_pre_plane_update(old_crtc_state, new_crtc_state);
14318 if (old_crtc_state->base.active)
14319 intel_old_crtc_state_disables(state,
14325 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
14327 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
14328 struct intel_crtc *crtc;
14332 * Disable CRTC/pipes in reverse order because some features(MST in
14333 * TGL+) requires master and slave relationship between pipes, so it
14334 * should always pick the lowest pipe as master as it will be enabled
14335 * first and disable in the reverse order so the master will be the
14336 * last one to be disabled.
14338 for_each_oldnew_intel_crtc_in_state_reverse(state, crtc, old_crtc_state,
14339 new_crtc_state, i) {
14340 if (!needs_modeset(new_crtc_state))
14343 /* In case of Transcoder port Sync master slave CRTCs can be
14344 * assigned in any order and we need to make sure that
14345 * slave CRTCs are disabled first and then master CRTC since
14346 * Slave vblanks are masked till Master Vblanks.
14348 if (is_trans_port_sync_mode(new_crtc_state)) {
14349 if (is_trans_port_sync_master(new_crtc_state))
14350 intel_trans_port_sync_modeset_disables(state,
14357 intel_pre_plane_update(old_crtc_state, new_crtc_state);
14359 if (old_crtc_state->base.active)
14360 intel_old_crtc_state_disables(state,
14368 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
14370 struct intel_crtc *crtc;
14371 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14374 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
14375 if (!new_crtc_state->base.active)
14378 intel_update_crtc(crtc, state, old_crtc_state,
14383 static void intel_crtc_enable_trans_port_sync(struct intel_crtc *crtc,
14384 struct intel_atomic_state *state,
14385 struct intel_crtc_state *new_crtc_state)
14387 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14389 intel_crtc_update_active_timings(new_crtc_state);
14390 dev_priv->display.crtc_enable(new_crtc_state, state);
14391 intel_crtc_enable_pipe_crc(crtc);
14394 static void intel_set_dp_tp_ctl_normal(struct intel_crtc *crtc,
14395 struct intel_atomic_state *state)
14397 struct drm_connector *uninitialized_var(conn);
14398 struct drm_connector_state *conn_state;
14399 struct intel_dp *intel_dp;
14402 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
14403 if (conn_state->crtc == &crtc->base)
14406 intel_dp = enc_to_intel_dp(&intel_attached_encoder(conn)->base);
14407 intel_dp_stop_link_train(intel_dp);
14410 static void intel_post_crtc_enable_updates(struct intel_crtc *crtc,
14411 struct intel_atomic_state *state)
14413 struct intel_crtc_state *new_crtc_state =
14414 intel_atomic_get_new_crtc_state(state, crtc);
14415 struct intel_crtc_state *old_crtc_state =
14416 intel_atomic_get_old_crtc_state(state, crtc);
14417 struct intel_plane_state *new_plane_state =
14418 intel_atomic_get_new_plane_state(state,
14419 to_intel_plane(crtc->base.primary));
14420 bool modeset = needs_modeset(new_crtc_state);
14422 if (new_crtc_state->update_pipe && !new_crtc_state->enable_fbc)
14423 intel_fbc_disable(crtc);
14424 else if (new_plane_state)
14425 intel_fbc_enable(crtc, new_crtc_state, new_plane_state);
14427 /* Perform vblank evasion around commit operation */
14428 intel_pipe_update_start(new_crtc_state);
14429 commit_pipe_config(state, old_crtc_state, new_crtc_state);
14430 skl_update_planes_on_crtc(state, crtc);
14431 intel_pipe_update_end(new_crtc_state);
14434 * We usually enable FIFO underrun interrupts as part of the
14435 * CRTC enable sequence during modesets. But when we inherit a
14436 * valid pipe configuration from the BIOS we need to take care
14437 * of enabling them on the CRTC's first fastset.
14439 if (new_crtc_state->update_pipe && !modeset &&
14440 old_crtc_state->base.mode.private_flags & I915_MODE_FLAG_INHERITED)
14441 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
14444 static void intel_update_trans_port_sync_crtcs(struct intel_crtc *crtc,
14445 struct intel_atomic_state *state,
14446 struct intel_crtc_state *old_crtc_state,
14447 struct intel_crtc_state *new_crtc_state)
14449 struct intel_crtc *slave_crtc = intel_get_slave_crtc(new_crtc_state);
14450 struct intel_crtc_state *new_slave_crtc_state =
14451 intel_atomic_get_new_crtc_state(state, slave_crtc);
14452 struct intel_crtc_state *old_slave_crtc_state =
14453 intel_atomic_get_old_crtc_state(state, slave_crtc);
14455 WARN_ON(!slave_crtc || !new_slave_crtc_state ||
14456 !old_slave_crtc_state);
14458 DRM_DEBUG_KMS("Updating Transcoder Port Sync Master CRTC = %d %s and Slave CRTC %d %s\n",
14459 crtc->base.base.id, crtc->base.name, slave_crtc->base.base.id,
14460 slave_crtc->base.name);
14462 /* Enable seq for slave with with DP_TP_CTL left Idle until the
14465 intel_crtc_enable_trans_port_sync(slave_crtc,
14467 new_slave_crtc_state);
14469 /* Enable seq for master with with DP_TP_CTL left Idle */
14470 intel_crtc_enable_trans_port_sync(crtc,
14474 /* Set Slave's DP_TP_CTL to Normal */
14475 intel_set_dp_tp_ctl_normal(slave_crtc,
14478 /* Set Master's DP_TP_CTL To Normal */
14479 usleep_range(200, 400);
14480 intel_set_dp_tp_ctl_normal(crtc,
14483 /* Now do the post crtc enable for all master and slaves */
14484 intel_post_crtc_enable_updates(slave_crtc,
14486 intel_post_crtc_enable_updates(crtc,
14490 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
14492 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14493 struct intel_crtc *crtc;
14494 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14495 unsigned int updated = 0;
14498 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
14499 u8 required_slices = state->wm_results.ddb.enabled_slices;
14500 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
14502 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
14503 /* ignore allocations for crtc's that have been turned off. */
14504 if (new_crtc_state->base.active)
14505 entries[i] = old_crtc_state->wm.skl.ddb;
14507 /* If 2nd DBuf slice required, enable it here */
14508 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
14509 icl_dbuf_slices_update(dev_priv, required_slices);
14512 * Whenever the number of active pipes changes, we need to make sure we
14513 * update the pipes in the right order so that their ddb allocations
14514 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
14515 * cause pipe underruns and other bad stuff.
14520 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
14521 enum pipe pipe = crtc->pipe;
14522 bool vbl_wait = false;
14523 bool modeset = needs_modeset(new_crtc_state);
14525 if (updated & BIT(crtc->pipe) || !new_crtc_state->base.active)
14528 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
14530 INTEL_NUM_PIPES(dev_priv), i))
14533 updated |= BIT(pipe);
14534 entries[i] = new_crtc_state->wm.skl.ddb;
14537 * If this is an already active pipe, it's DDB changed,
14538 * and this isn't the last pipe that needs updating
14539 * then we need to wait for a vblank to pass for the
14540 * new ddb allocation to take effect.
14542 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
14543 &old_crtc_state->wm.skl.ddb) &&
14545 state->wm_results.dirty_pipes != updated)
14548 if (modeset && is_trans_port_sync_mode(new_crtc_state)) {
14549 if (is_trans_port_sync_master(new_crtc_state))
14550 intel_update_trans_port_sync_crtcs(crtc,
14557 intel_update_crtc(crtc, state, old_crtc_state,
14562 intel_wait_for_vblank(dev_priv, pipe);
14566 } while (progress);
14568 /* If 2nd DBuf slice is no more required disable it */
14569 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
14570 icl_dbuf_slices_update(dev_priv, required_slices);
14573 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
14575 struct intel_atomic_state *state, *next;
14576 struct llist_node *freed;
14578 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
14579 llist_for_each_entry_safe(state, next, freed, freed)
14580 drm_atomic_state_put(&state->base);
14583 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
14585 struct drm_i915_private *dev_priv =
14586 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
14588 intel_atomic_helper_free_state(dev_priv);
14591 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
14593 struct wait_queue_entry wait_fence, wait_reset;
14594 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
14596 init_wait_entry(&wait_fence, 0);
14597 init_wait_entry(&wait_reset, 0);
14599 prepare_to_wait(&intel_state->commit_ready.wait,
14600 &wait_fence, TASK_UNINTERRUPTIBLE);
14601 prepare_to_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
14602 I915_RESET_MODESET),
14603 &wait_reset, TASK_UNINTERRUPTIBLE);
14606 if (i915_sw_fence_done(&intel_state->commit_ready) ||
14607 test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
14612 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
14613 finish_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
14614 I915_RESET_MODESET),
14618 static void intel_atomic_cleanup_work(struct work_struct *work)
14620 struct drm_atomic_state *state =
14621 container_of(work, struct drm_atomic_state, commit_work);
14622 struct drm_i915_private *i915 = to_i915(state->dev);
14624 drm_atomic_helper_cleanup_planes(&i915->drm, state);
14625 drm_atomic_helper_commit_cleanup_done(state);
14626 drm_atomic_state_put(state);
14628 intel_atomic_helper_free_state(i915);
14631 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
14633 struct drm_device *dev = state->base.dev;
14634 struct drm_i915_private *dev_priv = to_i915(dev);
14635 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
14636 struct intel_crtc *crtc;
14637 u64 put_domains[I915_MAX_PIPES] = {};
14638 intel_wakeref_t wakeref = 0;
14641 intel_atomic_commit_fence_wait(state);
14643 drm_atomic_helper_wait_for_dependencies(&state->base);
14645 if (state->modeset)
14646 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
14648 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14649 new_crtc_state, i) {
14650 if (needs_modeset(new_crtc_state) ||
14651 new_crtc_state->update_pipe) {
14653 put_domains[crtc->pipe] =
14654 modeset_get_crtc_power_domains(new_crtc_state);
14658 intel_commit_modeset_disables(state);
14660 /* FIXME: Eventually get rid of our crtc->config pointer */
14661 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
14662 crtc->config = new_crtc_state;
14664 if (state->modeset) {
14665 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
14667 intel_set_cdclk_pre_plane_update(dev_priv,
14668 &state->cdclk.actual,
14669 &dev_priv->cdclk.actual,
14670 state->cdclk.pipe);
14673 * SKL workaround: bspec recommends we disable the SAGV when we
14674 * have more then one pipe enabled
14676 if (!intel_can_enable_sagv(state))
14677 intel_disable_sagv(dev_priv);
14679 intel_modeset_verify_disabled(dev_priv, state);
14682 /* Complete the events for pipes that have now been disabled */
14683 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14684 bool modeset = needs_modeset(new_crtc_state);
14686 /* Complete events for now disable pipes here. */
14687 if (modeset && !new_crtc_state->base.active && new_crtc_state->base.event) {
14688 spin_lock_irq(&dev->event_lock);
14689 drm_crtc_send_vblank_event(&crtc->base, new_crtc_state->base.event);
14690 spin_unlock_irq(&dev->event_lock);
14692 new_crtc_state->base.event = NULL;
14696 if (state->modeset)
14697 intel_encoders_update_prepare(state);
14699 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
14700 dev_priv->display.commit_modeset_enables(state);
14702 if (state->modeset) {
14703 intel_encoders_update_complete(state);
14705 intel_set_cdclk_post_plane_update(dev_priv,
14706 &state->cdclk.actual,
14707 &dev_priv->cdclk.actual,
14708 state->cdclk.pipe);
14711 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
14712 * already, but still need the state for the delayed optimization. To
14714 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
14715 * - schedule that vblank worker _before_ calling hw_done
14716 * - at the start of commit_tail, cancel it _synchrously
14717 * - switch over to the vblank wait helper in the core after that since
14718 * we don't need out special handling any more.
14720 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
14722 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14723 if (new_crtc_state->base.active &&
14724 !needs_modeset(new_crtc_state) &&
14725 !new_crtc_state->preload_luts &&
14726 (new_crtc_state->base.color_mgmt_changed ||
14727 new_crtc_state->update_pipe))
14728 intel_color_load_luts(new_crtc_state);
14732 * Now that the vblank has passed, we can go ahead and program the
14733 * optimal watermarks on platforms that need two-step watermark
14736 * TODO: Move this (and other cleanup) to an async worker eventually.
14738 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14739 if (dev_priv->display.optimize_watermarks)
14740 dev_priv->display.optimize_watermarks(state,
14744 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
14745 intel_post_plane_update(old_crtc_state);
14747 if (put_domains[i])
14748 modeset_put_power_domains(dev_priv, put_domains[i]);
14750 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
14753 if (state->modeset)
14754 intel_verify_planes(state);
14756 if (state->modeset && intel_can_enable_sagv(state))
14757 intel_enable_sagv(dev_priv);
14759 drm_atomic_helper_commit_hw_done(&state->base);
14761 if (state->modeset) {
14762 /* As one of the primary mmio accessors, KMS has a high
14763 * likelihood of triggering bugs in unclaimed access. After we
14764 * finish modesetting, see if an error has been flagged, and if
14765 * so enable debugging for the next modeset - and hope we catch
14768 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
14769 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
14771 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
14774 * Defer the cleanup of the old state to a separate worker to not
14775 * impede the current task (userspace for blocking modesets) that
14776 * are executed inline. For out-of-line asynchronous modesets/flips,
14777 * deferring to a new worker seems overkill, but we would place a
14778 * schedule point (cond_resched()) here anyway to keep latencies
14781 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
14782 queue_work(system_highpri_wq, &state->base.commit_work);
14785 static void intel_atomic_commit_work(struct work_struct *work)
14787 struct intel_atomic_state *state =
14788 container_of(work, struct intel_atomic_state, base.commit_work);
14790 intel_atomic_commit_tail(state);
14793 static int __i915_sw_fence_call
14794 intel_atomic_commit_ready(struct i915_sw_fence *fence,
14795 enum i915_sw_fence_notify notify)
14797 struct intel_atomic_state *state =
14798 container_of(fence, struct intel_atomic_state, commit_ready);
14801 case FENCE_COMPLETE:
14802 /* we do blocking waits in the worker, nothing to do here */
14806 struct intel_atomic_helper *helper =
14807 &to_i915(state->base.dev)->atomic_helper;
14809 if (llist_add(&state->freed, &helper->free_list))
14810 schedule_work(&helper->free_work);
14815 return NOTIFY_DONE;
14818 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
14820 struct intel_plane_state *old_plane_state, *new_plane_state;
14821 struct intel_plane *plane;
14824 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
14825 new_plane_state, i)
14826 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->base.fb),
14827 to_intel_frontbuffer(new_plane_state->base.fb),
14828 plane->frontbuffer_bit);
14831 static void assert_global_state_locked(struct drm_i915_private *dev_priv)
14833 struct intel_crtc *crtc;
14835 for_each_intel_crtc(&dev_priv->drm, crtc)
14836 drm_modeset_lock_assert_held(&crtc->base.mutex);
14839 static int intel_atomic_commit(struct drm_device *dev,
14840 struct drm_atomic_state *_state,
14843 struct intel_atomic_state *state = to_intel_atomic_state(_state);
14844 struct drm_i915_private *dev_priv = to_i915(dev);
14847 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
14849 drm_atomic_state_get(&state->base);
14850 i915_sw_fence_init(&state->commit_ready,
14851 intel_atomic_commit_ready);
14854 * The intel_legacy_cursor_update() fast path takes care
14855 * of avoiding the vblank waits for simple cursor
14856 * movement and flips. For cursor on/off and size changes,
14857 * we want to perform the vblank waits so that watermark
14858 * updates happen during the correct frames. Gen9+ have
14859 * double buffered watermarks and so shouldn't need this.
14861 * Unset state->legacy_cursor_update before the call to
14862 * drm_atomic_helper_setup_commit() because otherwise
14863 * drm_atomic_helper_wait_for_flip_done() is a noop and
14864 * we get FIFO underruns because we didn't wait
14867 * FIXME doing watermarks and fb cleanup from a vblank worker
14868 * (assuming we had any) would solve these problems.
14870 if (INTEL_GEN(dev_priv) < 9 && state->base.legacy_cursor_update) {
14871 struct intel_crtc_state *new_crtc_state;
14872 struct intel_crtc *crtc;
14875 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
14876 if (new_crtc_state->wm.need_postvbl_update ||
14877 new_crtc_state->update_wm_post)
14878 state->base.legacy_cursor_update = false;
14881 ret = intel_atomic_prepare_commit(state);
14883 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
14884 i915_sw_fence_commit(&state->commit_ready);
14885 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
14889 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
14891 ret = drm_atomic_helper_swap_state(&state->base, true);
14894 i915_sw_fence_commit(&state->commit_ready);
14896 drm_atomic_helper_cleanup_planes(dev, &state->base);
14897 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
14900 dev_priv->wm.distrust_bios_wm = false;
14901 intel_shared_dpll_swap_state(state);
14902 intel_atomic_track_fbs(state);
14904 if (state->global_state_changed) {
14905 assert_global_state_locked(dev_priv);
14907 memcpy(dev_priv->min_cdclk, state->min_cdclk,
14908 sizeof(state->min_cdclk));
14909 memcpy(dev_priv->min_voltage_level, state->min_voltage_level,
14910 sizeof(state->min_voltage_level));
14911 dev_priv->active_pipes = state->active_pipes;
14912 dev_priv->cdclk.force_min_cdclk = state->cdclk.force_min_cdclk;
14914 intel_cdclk_swap_state(state);
14917 drm_atomic_state_get(&state->base);
14918 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
14920 i915_sw_fence_commit(&state->commit_ready);
14921 if (nonblock && state->modeset) {
14922 queue_work(dev_priv->modeset_wq, &state->base.commit_work);
14923 } else if (nonblock) {
14924 queue_work(dev_priv->flip_wq, &state->base.commit_work);
14926 if (state->modeset)
14927 flush_workqueue(dev_priv->modeset_wq);
14928 intel_atomic_commit_tail(state);
14934 struct wait_rps_boost {
14935 struct wait_queue_entry wait;
14937 struct drm_crtc *crtc;
14938 struct i915_request *request;
14941 static int do_rps_boost(struct wait_queue_entry *_wait,
14942 unsigned mode, int sync, void *key)
14944 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
14945 struct i915_request *rq = wait->request;
14948 * If we missed the vblank, but the request is already running it
14949 * is reasonable to assume that it will complete before the next
14950 * vblank without our intervention, so leave RPS alone.
14952 if (!i915_request_started(rq))
14953 intel_rps_boost(rq);
14954 i915_request_put(rq);
14956 drm_crtc_vblank_put(wait->crtc);
14958 list_del(&wait->wait.entry);
14963 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
14964 struct dma_fence *fence)
14966 struct wait_rps_boost *wait;
14968 if (!dma_fence_is_i915(fence))
14971 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
14974 if (drm_crtc_vblank_get(crtc))
14977 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
14979 drm_crtc_vblank_put(crtc);
14983 wait->request = to_request(dma_fence_get(fence));
14986 wait->wait.func = do_rps_boost;
14987 wait->wait.flags = 0;
14989 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
14992 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
14994 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
14995 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
14996 struct drm_framebuffer *fb = plane_state->base.fb;
14997 struct i915_vma *vma;
14999 if (plane->id == PLANE_CURSOR &&
15000 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
15001 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
15002 const int align = intel_cursor_alignment(dev_priv);
15005 err = i915_gem_object_attach_phys(obj, align);
15010 vma = intel_pin_and_fence_fb_obj(fb,
15011 &plane_state->view,
15012 intel_plane_uses_fence(plane_state),
15013 &plane_state->flags);
15015 return PTR_ERR(vma);
15017 plane_state->vma = vma;
15022 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
15024 struct i915_vma *vma;
15026 vma = fetch_and_zero(&old_plane_state->vma);
15028 intel_unpin_fb_vma(vma, old_plane_state->flags);
15031 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
15033 struct i915_sched_attr attr = {
15034 .priority = I915_USER_PRIORITY(I915_PRIORITY_DISPLAY),
15037 i915_gem_object_wait_priority(obj, 0, &attr);
15041 * intel_prepare_plane_fb - Prepare fb for usage on plane
15042 * @plane: drm plane to prepare for
15043 * @_new_plane_state: the plane state being prepared
15045 * Prepares a framebuffer for usage on a display plane. Generally this
15046 * involves pinning the underlying object and updating the frontbuffer tracking
15047 * bits. Some older platforms need special physical address handling for
15050 * Returns 0 on success, negative error code on failure.
15053 intel_prepare_plane_fb(struct drm_plane *plane,
15054 struct drm_plane_state *_new_plane_state)
15056 struct intel_plane_state *new_plane_state =
15057 to_intel_plane_state(_new_plane_state);
15058 struct intel_atomic_state *intel_state =
15059 to_intel_atomic_state(new_plane_state->base.state);
15060 struct drm_i915_private *dev_priv = to_i915(plane->dev);
15061 struct drm_framebuffer *fb = new_plane_state->base.fb;
15062 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
15063 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
15067 struct intel_crtc_state *crtc_state =
15068 intel_atomic_get_new_crtc_state(intel_state,
15069 to_intel_crtc(plane->state->crtc));
15071 /* Big Hammer, we also need to ensure that any pending
15072 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
15073 * current scanout is retired before unpinning the old
15074 * framebuffer. Note that we rely on userspace rendering
15075 * into the buffer attached to the pipe they are waiting
15076 * on. If not, userspace generates a GPU hang with IPEHR
15077 * point to the MI_WAIT_FOR_EVENT.
15079 * This should only fail upon a hung GPU, in which case we
15080 * can safely continue.
15082 if (needs_modeset(crtc_state)) {
15083 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
15084 old_obj->base.resv, NULL,
15092 if (new_plane_state->base.fence) { /* explicit fencing */
15093 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
15094 new_plane_state->base.fence,
15095 I915_FENCE_TIMEOUT,
15104 ret = i915_gem_object_pin_pages(obj);
15108 ret = intel_plane_pin_fb(new_plane_state);
15110 i915_gem_object_unpin_pages(obj);
15114 fb_obj_bump_render_priority(obj);
15115 intel_frontbuffer_flush(obj->frontbuffer, ORIGIN_DIRTYFB);
15117 if (!new_plane_state->base.fence) { /* implicit fencing */
15118 struct dma_fence *fence;
15120 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
15121 obj->base.resv, NULL,
15122 false, I915_FENCE_TIMEOUT,
15127 fence = dma_resv_get_excl_rcu(obj->base.resv);
15129 add_rps_boost_after_vblank(new_plane_state->base.crtc,
15131 dma_fence_put(fence);
15134 add_rps_boost_after_vblank(new_plane_state->base.crtc,
15135 new_plane_state->base.fence);
15139 * We declare pageflips to be interactive and so merit a small bias
15140 * towards upclocking to deliver the frame on time. By only changing
15141 * the RPS thresholds to sample more regularly and aim for higher
15142 * clocks we can hopefully deliver low power workloads (like kodi)
15143 * that are not quite steady state without resorting to forcing
15144 * maximum clocks following a vblank miss (see do_rps_boost()).
15146 if (!intel_state->rps_interactive) {
15147 intel_rps_mark_interactive(&dev_priv->gt.rps, true);
15148 intel_state->rps_interactive = true;
15155 * intel_cleanup_plane_fb - Cleans up an fb after plane use
15156 * @plane: drm plane to clean up for
15157 * @_old_plane_state: the state from the previous modeset
15159 * Cleans up a framebuffer that has just been removed from a plane.
15162 intel_cleanup_plane_fb(struct drm_plane *plane,
15163 struct drm_plane_state *_old_plane_state)
15165 struct intel_plane_state *old_plane_state =
15166 to_intel_plane_state(_old_plane_state);
15167 struct intel_atomic_state *intel_state =
15168 to_intel_atomic_state(old_plane_state->base.state);
15169 struct drm_i915_private *dev_priv = to_i915(plane->dev);
15171 if (intel_state->rps_interactive) {
15172 intel_rps_mark_interactive(&dev_priv->gt.rps, false);
15173 intel_state->rps_interactive = false;
15176 /* Should only be called after a successful intel_prepare_plane_fb()! */
15177 intel_plane_unpin_fb(old_plane_state);
15181 * intel_plane_destroy - destroy a plane
15182 * @plane: plane to destroy
15184 * Common destruction function for all types of planes (primary, cursor,
15187 void intel_plane_destroy(struct drm_plane *plane)
15189 drm_plane_cleanup(plane);
15190 kfree(to_intel_plane(plane));
15193 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
15194 u32 format, u64 modifier)
15196 switch (modifier) {
15197 case DRM_FORMAT_MOD_LINEAR:
15198 case I915_FORMAT_MOD_X_TILED:
15205 case DRM_FORMAT_C8:
15206 case DRM_FORMAT_RGB565:
15207 case DRM_FORMAT_XRGB1555:
15208 case DRM_FORMAT_XRGB8888:
15209 return modifier == DRM_FORMAT_MOD_LINEAR ||
15210 modifier == I915_FORMAT_MOD_X_TILED;
15216 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
15217 u32 format, u64 modifier)
15219 switch (modifier) {
15220 case DRM_FORMAT_MOD_LINEAR:
15221 case I915_FORMAT_MOD_X_TILED:
15228 case DRM_FORMAT_C8:
15229 case DRM_FORMAT_RGB565:
15230 case DRM_FORMAT_XRGB8888:
15231 case DRM_FORMAT_XBGR8888:
15232 case DRM_FORMAT_XRGB2101010:
15233 case DRM_FORMAT_XBGR2101010:
15234 case DRM_FORMAT_XBGR16161616F:
15235 return modifier == DRM_FORMAT_MOD_LINEAR ||
15236 modifier == I915_FORMAT_MOD_X_TILED;
15242 static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
15243 u32 format, u64 modifier)
15245 return modifier == DRM_FORMAT_MOD_LINEAR &&
15246 format == DRM_FORMAT_ARGB8888;
15249 static const struct drm_plane_funcs i965_plane_funcs = {
15250 .update_plane = drm_atomic_helper_update_plane,
15251 .disable_plane = drm_atomic_helper_disable_plane,
15252 .destroy = intel_plane_destroy,
15253 .atomic_duplicate_state = intel_plane_duplicate_state,
15254 .atomic_destroy_state = intel_plane_destroy_state,
15255 .format_mod_supported = i965_plane_format_mod_supported,
15258 static const struct drm_plane_funcs i8xx_plane_funcs = {
15259 .update_plane = drm_atomic_helper_update_plane,
15260 .disable_plane = drm_atomic_helper_disable_plane,
15261 .destroy = intel_plane_destroy,
15262 .atomic_duplicate_state = intel_plane_duplicate_state,
15263 .atomic_destroy_state = intel_plane_destroy_state,
15264 .format_mod_supported = i8xx_plane_format_mod_supported,
15268 intel_legacy_cursor_update(struct drm_plane *_plane,
15269 struct drm_crtc *_crtc,
15270 struct drm_framebuffer *fb,
15271 int crtc_x, int crtc_y,
15272 unsigned int crtc_w, unsigned int crtc_h,
15273 u32 src_x, u32 src_y,
15274 u32 src_w, u32 src_h,
15275 struct drm_modeset_acquire_ctx *ctx)
15277 struct intel_plane *plane = to_intel_plane(_plane);
15278 struct intel_crtc *crtc = to_intel_crtc(_crtc);
15279 struct intel_plane_state *old_plane_state =
15280 to_intel_plane_state(plane->base.state);
15281 struct intel_plane_state *new_plane_state;
15282 struct intel_crtc_state *crtc_state =
15283 to_intel_crtc_state(crtc->base.state);
15284 struct intel_crtc_state *new_crtc_state;
15288 * When crtc is inactive or there is a modeset pending,
15289 * wait for it to complete in the slowpath
15291 if (!crtc_state->base.active || needs_modeset(crtc_state) ||
15292 crtc_state->update_pipe)
15296 * Don't do an async update if there is an outstanding commit modifying
15297 * the plane. This prevents our async update's changes from getting
15298 * overridden by a previous synchronous update's state.
15300 if (old_plane_state->base.commit &&
15301 !try_wait_for_completion(&old_plane_state->base.commit->hw_done))
15305 * If any parameters change that may affect watermarks,
15306 * take the slowpath. Only changing fb or position should be
15309 if (old_plane_state->base.crtc != &crtc->base ||
15310 old_plane_state->base.src_w != src_w ||
15311 old_plane_state->base.src_h != src_h ||
15312 old_plane_state->base.crtc_w != crtc_w ||
15313 old_plane_state->base.crtc_h != crtc_h ||
15314 !old_plane_state->base.fb != !fb)
15317 new_plane_state = to_intel_plane_state(intel_plane_duplicate_state(&plane->base));
15318 if (!new_plane_state)
15321 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(&crtc->base));
15322 if (!new_crtc_state) {
15327 drm_atomic_set_fb_for_plane(&new_plane_state->base, fb);
15329 new_plane_state->base.src_x = src_x;
15330 new_plane_state->base.src_y = src_y;
15331 new_plane_state->base.src_w = src_w;
15332 new_plane_state->base.src_h = src_h;
15333 new_plane_state->base.crtc_x = crtc_x;
15334 new_plane_state->base.crtc_y = crtc_y;
15335 new_plane_state->base.crtc_w = crtc_w;
15336 new_plane_state->base.crtc_h = crtc_h;
15338 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
15339 old_plane_state, new_plane_state);
15343 ret = intel_plane_pin_fb(new_plane_state);
15347 intel_frontbuffer_flush(to_intel_frontbuffer(new_plane_state->base.fb), ORIGIN_FLIP);
15348 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->base.fb),
15349 to_intel_frontbuffer(new_plane_state->base.fb),
15350 plane->frontbuffer_bit);
15352 /* Swap plane state */
15353 plane->base.state = &new_plane_state->base;
15356 * We cannot swap crtc_state as it may be in use by an atomic commit or
15357 * page flip that's running simultaneously. If we swap crtc_state and
15358 * destroy the old state, we will cause a use-after-free there.
15360 * Only update active_planes, which is needed for our internal
15361 * bookkeeping. Either value will do the right thing when updating
15362 * planes atomically. If the cursor was part of the atomic update then
15363 * we would have taken the slowpath.
15365 crtc_state->active_planes = new_crtc_state->active_planes;
15367 if (new_plane_state->base.visible)
15368 intel_update_plane(plane, crtc_state, new_plane_state);
15370 intel_disable_plane(plane, crtc_state);
15372 intel_plane_unpin_fb(old_plane_state);
15375 if (new_crtc_state)
15376 intel_crtc_destroy_state(&crtc->base, &new_crtc_state->base);
15378 intel_plane_destroy_state(&plane->base, &new_plane_state->base);
15380 intel_plane_destroy_state(&plane->base, &old_plane_state->base);
15384 return drm_atomic_helper_update_plane(&plane->base, &crtc->base, fb,
15385 crtc_x, crtc_y, crtc_w, crtc_h,
15386 src_x, src_y, src_w, src_h, ctx);
15389 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
15390 .update_plane = intel_legacy_cursor_update,
15391 .disable_plane = drm_atomic_helper_disable_plane,
15392 .destroy = intel_plane_destroy,
15393 .atomic_duplicate_state = intel_plane_duplicate_state,
15394 .atomic_destroy_state = intel_plane_destroy_state,
15395 .format_mod_supported = intel_cursor_format_mod_supported,
15398 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
15399 enum i9xx_plane_id i9xx_plane)
15401 if (!HAS_FBC(dev_priv))
15404 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
15405 return i9xx_plane == PLANE_A; /* tied to pipe A */
15406 else if (IS_IVYBRIDGE(dev_priv))
15407 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
15408 i9xx_plane == PLANE_C;
15409 else if (INTEL_GEN(dev_priv) >= 4)
15410 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
15412 return i9xx_plane == PLANE_A;
15415 static struct intel_plane *
15416 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
15418 struct intel_plane *plane;
15419 const struct drm_plane_funcs *plane_funcs;
15420 unsigned int supported_rotations;
15421 unsigned int possible_crtcs;
15422 const u64 *modifiers;
15423 const u32 *formats;
15427 if (INTEL_GEN(dev_priv) >= 9)
15428 return skl_universal_plane_create(dev_priv, pipe,
15431 plane = intel_plane_alloc();
15435 plane->pipe = pipe;
15437 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
15438 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
15440 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
15441 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
15443 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
15444 plane->id = PLANE_PRIMARY;
15445 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
15447 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
15448 if (plane->has_fbc) {
15449 struct intel_fbc *fbc = &dev_priv->fbc;
15451 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
15454 if (INTEL_GEN(dev_priv) >= 4) {
15456 * WaFP16GammaEnabling:ivb
15457 * "Workaround : When using the 64-bit format, the plane
15458 * output on each color channel has one quarter amplitude.
15459 * It can be brought up to full amplitude by using pipe
15460 * gamma correction or pipe color space conversion to
15461 * multiply the plane output by four."
15463 * There is no dedicated plane gamma for the primary plane,
15464 * and using the pipe gamma/csc could conflict with other
15465 * planes, so we choose not to expose fp16 on IVB primary
15466 * planes. HSW primary planes no longer have this problem.
15468 if (IS_IVYBRIDGE(dev_priv)) {
15469 formats = ivb_primary_formats;
15470 num_formats = ARRAY_SIZE(ivb_primary_formats);
15472 formats = i965_primary_formats;
15473 num_formats = ARRAY_SIZE(i965_primary_formats);
15475 modifiers = i9xx_format_modifiers;
15477 plane->max_stride = i9xx_plane_max_stride;
15478 plane->update_plane = i9xx_update_plane;
15479 plane->disable_plane = i9xx_disable_plane;
15480 plane->get_hw_state = i9xx_plane_get_hw_state;
15481 plane->check_plane = i9xx_plane_check;
15483 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
15484 plane->min_cdclk = hsw_plane_min_cdclk;
15485 else if (IS_IVYBRIDGE(dev_priv))
15486 plane->min_cdclk = ivb_plane_min_cdclk;
15487 else if (IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv))
15488 plane->min_cdclk = vlv_plane_min_cdclk;
15490 plane->min_cdclk = i9xx_plane_min_cdclk;
15492 plane_funcs = &i965_plane_funcs;
15494 formats = i8xx_primary_formats;
15495 num_formats = ARRAY_SIZE(i8xx_primary_formats);
15496 modifiers = i9xx_format_modifiers;
15498 plane->max_stride = i9xx_plane_max_stride;
15499 plane->update_plane = i9xx_update_plane;
15500 plane->disable_plane = i9xx_disable_plane;
15501 plane->get_hw_state = i9xx_plane_get_hw_state;
15502 plane->check_plane = i9xx_plane_check;
15503 plane->min_cdclk = i9xx_plane_min_cdclk;
15505 plane_funcs = &i8xx_plane_funcs;
15508 possible_crtcs = BIT(pipe);
15510 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
15511 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
15512 possible_crtcs, plane_funcs,
15513 formats, num_formats, modifiers,
15514 DRM_PLANE_TYPE_PRIMARY,
15515 "primary %c", pipe_name(pipe));
15517 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
15518 possible_crtcs, plane_funcs,
15519 formats, num_formats, modifiers,
15520 DRM_PLANE_TYPE_PRIMARY,
15522 plane_name(plane->i9xx_plane));
15526 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
15527 supported_rotations =
15528 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
15529 DRM_MODE_REFLECT_X;
15530 } else if (INTEL_GEN(dev_priv) >= 4) {
15531 supported_rotations =
15532 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
15534 supported_rotations = DRM_MODE_ROTATE_0;
15537 if (INTEL_GEN(dev_priv) >= 4)
15538 drm_plane_create_rotation_property(&plane->base,
15540 supported_rotations);
15543 drm_plane_create_zpos_immutable_property(&plane->base, zpos);
15545 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
15550 intel_plane_free(plane);
15552 return ERR_PTR(ret);
15555 static struct intel_plane *
15556 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
15559 unsigned int possible_crtcs;
15560 struct intel_plane *cursor;
15563 cursor = intel_plane_alloc();
15564 if (IS_ERR(cursor))
15567 cursor->pipe = pipe;
15568 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
15569 cursor->id = PLANE_CURSOR;
15570 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
15572 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
15573 cursor->max_stride = i845_cursor_max_stride;
15574 cursor->update_plane = i845_update_cursor;
15575 cursor->disable_plane = i845_disable_cursor;
15576 cursor->get_hw_state = i845_cursor_get_hw_state;
15577 cursor->check_plane = i845_check_cursor;
15579 cursor->max_stride = i9xx_cursor_max_stride;
15580 cursor->update_plane = i9xx_update_cursor;
15581 cursor->disable_plane = i9xx_disable_cursor;
15582 cursor->get_hw_state = i9xx_cursor_get_hw_state;
15583 cursor->check_plane = i9xx_check_cursor;
15586 cursor->cursor.base = ~0;
15587 cursor->cursor.cntl = ~0;
15589 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
15590 cursor->cursor.size = ~0;
15592 possible_crtcs = BIT(pipe);
15594 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
15595 possible_crtcs, &intel_cursor_plane_funcs,
15596 intel_cursor_formats,
15597 ARRAY_SIZE(intel_cursor_formats),
15598 cursor_format_modifiers,
15599 DRM_PLANE_TYPE_CURSOR,
15600 "cursor %c", pipe_name(pipe));
15604 if (INTEL_GEN(dev_priv) >= 4)
15605 drm_plane_create_rotation_property(&cursor->base,
15607 DRM_MODE_ROTATE_0 |
15608 DRM_MODE_ROTATE_180);
15610 zpos = RUNTIME_INFO(dev_priv)->num_sprites[pipe] + 1;
15611 drm_plane_create_zpos_immutable_property(&cursor->base, zpos);
15613 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
15618 intel_plane_free(cursor);
15620 return ERR_PTR(ret);
15623 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
15624 struct intel_crtc_state *crtc_state)
15626 struct intel_crtc_scaler_state *scaler_state =
15627 &crtc_state->scaler_state;
15628 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
15631 crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[crtc->pipe];
15632 if (!crtc->num_scalers)
15635 for (i = 0; i < crtc->num_scalers; i++) {
15636 struct intel_scaler *scaler = &scaler_state->scalers[i];
15638 scaler->in_use = 0;
15642 scaler_state->scaler_id = -1;
15645 #define INTEL_CRTC_FUNCS \
15646 .gamma_set = drm_atomic_helper_legacy_gamma_set, \
15647 .set_config = drm_atomic_helper_set_config, \
15648 .destroy = intel_crtc_destroy, \
15649 .page_flip = drm_atomic_helper_page_flip, \
15650 .atomic_duplicate_state = intel_crtc_duplicate_state, \
15651 .atomic_destroy_state = intel_crtc_destroy_state, \
15652 .set_crc_source = intel_crtc_set_crc_source, \
15653 .verify_crc_source = intel_crtc_verify_crc_source, \
15654 .get_crc_sources = intel_crtc_get_crc_sources
15656 static const struct drm_crtc_funcs bdw_crtc_funcs = {
15659 .get_vblank_counter = g4x_get_vblank_counter,
15660 .enable_vblank = bdw_enable_vblank,
15661 .disable_vblank = bdw_disable_vblank,
15664 static const struct drm_crtc_funcs ilk_crtc_funcs = {
15667 .get_vblank_counter = g4x_get_vblank_counter,
15668 .enable_vblank = ilk_enable_vblank,
15669 .disable_vblank = ilk_disable_vblank,
15672 static const struct drm_crtc_funcs g4x_crtc_funcs = {
15675 .get_vblank_counter = g4x_get_vblank_counter,
15676 .enable_vblank = i965_enable_vblank,
15677 .disable_vblank = i965_disable_vblank,
15680 static const struct drm_crtc_funcs i965_crtc_funcs = {
15683 .get_vblank_counter = i915_get_vblank_counter,
15684 .enable_vblank = i965_enable_vblank,
15685 .disable_vblank = i965_disable_vblank,
15688 static const struct drm_crtc_funcs i915gm_crtc_funcs = {
15691 .get_vblank_counter = i915_get_vblank_counter,
15692 .enable_vblank = i915gm_enable_vblank,
15693 .disable_vblank = i915gm_disable_vblank,
15696 static const struct drm_crtc_funcs i915_crtc_funcs = {
15699 .get_vblank_counter = i915_get_vblank_counter,
15700 .enable_vblank = i8xx_enable_vblank,
15701 .disable_vblank = i8xx_disable_vblank,
15704 static const struct drm_crtc_funcs i8xx_crtc_funcs = {
15707 /* no hw vblank counter */
15708 .enable_vblank = i8xx_enable_vblank,
15709 .disable_vblank = i8xx_disable_vblank,
15712 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
15714 const struct drm_crtc_funcs *funcs;
15715 struct intel_crtc *intel_crtc;
15716 struct intel_crtc_state *crtc_state = NULL;
15717 struct intel_plane *primary = NULL;
15718 struct intel_plane *cursor = NULL;
15721 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
15725 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
15730 __drm_atomic_helper_crtc_reset(&intel_crtc->base, &crtc_state->base);
15731 intel_crtc->config = crtc_state;
15733 primary = intel_primary_plane_create(dev_priv, pipe);
15734 if (IS_ERR(primary)) {
15735 ret = PTR_ERR(primary);
15738 intel_crtc->plane_ids_mask |= BIT(primary->id);
15740 for_each_sprite(dev_priv, pipe, sprite) {
15741 struct intel_plane *plane;
15743 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
15744 if (IS_ERR(plane)) {
15745 ret = PTR_ERR(plane);
15748 intel_crtc->plane_ids_mask |= BIT(plane->id);
15751 cursor = intel_cursor_plane_create(dev_priv, pipe);
15752 if (IS_ERR(cursor)) {
15753 ret = PTR_ERR(cursor);
15756 intel_crtc->plane_ids_mask |= BIT(cursor->id);
15758 if (HAS_GMCH(dev_priv)) {
15759 if (IS_CHERRYVIEW(dev_priv) ||
15760 IS_VALLEYVIEW(dev_priv) || IS_G4X(dev_priv))
15761 funcs = &g4x_crtc_funcs;
15762 else if (IS_GEN(dev_priv, 4))
15763 funcs = &i965_crtc_funcs;
15764 else if (IS_I945GM(dev_priv) || IS_I915GM(dev_priv))
15765 funcs = &i915gm_crtc_funcs;
15766 else if (IS_GEN(dev_priv, 3))
15767 funcs = &i915_crtc_funcs;
15769 funcs = &i8xx_crtc_funcs;
15771 if (INTEL_GEN(dev_priv) >= 8)
15772 funcs = &bdw_crtc_funcs;
15774 funcs = &ilk_crtc_funcs;
15777 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
15778 &primary->base, &cursor->base,
15779 funcs, "pipe %c", pipe_name(pipe));
15783 intel_crtc->pipe = pipe;
15785 /* initialize shared scalers */
15786 intel_crtc_init_scalers(intel_crtc, crtc_state);
15788 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
15789 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
15790 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
15792 if (INTEL_GEN(dev_priv) < 9) {
15793 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
15795 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
15796 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
15797 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
15800 intel_color_init(intel_crtc);
15802 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
15808 * drm_mode_config_cleanup() will free up any
15809 * crtcs/planes already initialized.
15817 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
15818 struct drm_file *file)
15820 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
15821 struct drm_crtc *drmmode_crtc;
15822 struct intel_crtc *crtc;
15824 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
15828 crtc = to_intel_crtc(drmmode_crtc);
15829 pipe_from_crtc_id->pipe = crtc->pipe;
15834 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
15836 struct drm_device *dev = encoder->base.dev;
15837 struct intel_encoder *source_encoder;
15838 u32 possible_clones = 0;
15840 for_each_intel_encoder(dev, source_encoder) {
15841 if (encoders_cloneable(encoder, source_encoder))
15842 possible_clones |= drm_encoder_mask(&source_encoder->base);
15845 return possible_clones;
15848 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
15850 struct drm_device *dev = encoder->base.dev;
15851 struct intel_crtc *crtc;
15852 u32 possible_crtcs = 0;
15854 for_each_intel_crtc(dev, crtc) {
15855 if (encoder->pipe_mask & BIT(crtc->pipe))
15856 possible_crtcs |= drm_crtc_mask(&crtc->base);
15859 return possible_crtcs;
15862 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
15864 if (!IS_MOBILE(dev_priv))
15867 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
15870 if (IS_GEN(dev_priv, 5) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
15876 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
15878 if (INTEL_GEN(dev_priv) >= 9)
15881 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
15884 if (HAS_PCH_LPT_H(dev_priv) &&
15885 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
15888 /* DDI E can't be used if DDI A requires 4 lanes */
15889 if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
15892 if (!dev_priv->vbt.int_crt_support)
15898 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
15903 if (HAS_DDI(dev_priv))
15906 * This w/a is needed at least on CPT/PPT, but to be sure apply it
15907 * everywhere where registers can be write protected.
15909 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
15914 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
15915 u32 val = I915_READ(PP_CONTROL(pps_idx));
15917 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
15918 I915_WRITE(PP_CONTROL(pps_idx), val);
15922 static void intel_pps_init(struct drm_i915_private *dev_priv)
15924 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
15925 dev_priv->pps_mmio_base = PCH_PPS_BASE;
15926 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
15927 dev_priv->pps_mmio_base = VLV_PPS_BASE;
15929 dev_priv->pps_mmio_base = PPS_BASE;
15931 intel_pps_unlock_regs_wa(dev_priv);
15934 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
15936 struct intel_encoder *encoder;
15937 bool dpd_is_edp = false;
15939 intel_pps_init(dev_priv);
15941 if (!HAS_DISPLAY(dev_priv) || !INTEL_DISPLAY_ENABLED(dev_priv))
15944 if (INTEL_GEN(dev_priv) >= 12) {
15945 intel_ddi_init(dev_priv, PORT_A);
15946 intel_ddi_init(dev_priv, PORT_B);
15947 intel_ddi_init(dev_priv, PORT_D);
15948 intel_ddi_init(dev_priv, PORT_E);
15949 intel_ddi_init(dev_priv, PORT_F);
15950 intel_ddi_init(dev_priv, PORT_G);
15951 intel_ddi_init(dev_priv, PORT_H);
15952 intel_ddi_init(dev_priv, PORT_I);
15953 icl_dsi_init(dev_priv);
15954 } else if (IS_ELKHARTLAKE(dev_priv)) {
15955 intel_ddi_init(dev_priv, PORT_A);
15956 intel_ddi_init(dev_priv, PORT_B);
15957 intel_ddi_init(dev_priv, PORT_C);
15958 intel_ddi_init(dev_priv, PORT_D);
15959 icl_dsi_init(dev_priv);
15960 } else if (IS_GEN(dev_priv, 11)) {
15961 intel_ddi_init(dev_priv, PORT_A);
15962 intel_ddi_init(dev_priv, PORT_B);
15963 intel_ddi_init(dev_priv, PORT_C);
15964 intel_ddi_init(dev_priv, PORT_D);
15965 intel_ddi_init(dev_priv, PORT_E);
15967 * On some ICL SKUs port F is not present. No strap bits for
15968 * this, so rely on VBT.
15969 * Work around broken VBTs on SKUs known to have no port F.
15971 if (IS_ICL_WITH_PORT_F(dev_priv) &&
15972 intel_bios_is_port_present(dev_priv, PORT_F))
15973 intel_ddi_init(dev_priv, PORT_F);
15975 icl_dsi_init(dev_priv);
15976 } else if (IS_GEN9_LP(dev_priv)) {
15978 * FIXME: Broxton doesn't support port detection via the
15979 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
15980 * detect the ports.
15982 intel_ddi_init(dev_priv, PORT_A);
15983 intel_ddi_init(dev_priv, PORT_B);
15984 intel_ddi_init(dev_priv, PORT_C);
15986 vlv_dsi_init(dev_priv);
15987 } else if (HAS_DDI(dev_priv)) {
15990 if (intel_ddi_crt_present(dev_priv))
15991 intel_crt_init(dev_priv);
15994 * Haswell uses DDI functions to detect digital outputs.
15995 * On SKL pre-D0 the strap isn't connected, so we assume
15998 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
15999 /* WaIgnoreDDIAStrap: skl */
16000 if (found || IS_GEN9_BC(dev_priv))
16001 intel_ddi_init(dev_priv, PORT_A);
16003 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
16005 found = I915_READ(SFUSE_STRAP);
16007 if (found & SFUSE_STRAP_DDIB_DETECTED)
16008 intel_ddi_init(dev_priv, PORT_B);
16009 if (found & SFUSE_STRAP_DDIC_DETECTED)
16010 intel_ddi_init(dev_priv, PORT_C);
16011 if (found & SFUSE_STRAP_DDID_DETECTED)
16012 intel_ddi_init(dev_priv, PORT_D);
16013 if (found & SFUSE_STRAP_DDIF_DETECTED)
16014 intel_ddi_init(dev_priv, PORT_F);
16016 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
16018 if (IS_GEN9_BC(dev_priv) &&
16019 intel_bios_is_port_present(dev_priv, PORT_E))
16020 intel_ddi_init(dev_priv, PORT_E);
16022 } else if (HAS_PCH_SPLIT(dev_priv)) {
16026 * intel_edp_init_connector() depends on this completing first,
16027 * to prevent the registration of both eDP and LVDS and the
16028 * incorrect sharing of the PPS.
16030 intel_lvds_init(dev_priv);
16031 intel_crt_init(dev_priv);
16033 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
16035 if (ilk_has_edp_a(dev_priv))
16036 intel_dp_init(dev_priv, DP_A, PORT_A);
16038 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
16039 /* PCH SDVOB multiplex with HDMIB */
16040 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
16042 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
16043 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
16044 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
16047 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
16048 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
16050 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
16051 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
16053 if (I915_READ(PCH_DP_C) & DP_DETECTED)
16054 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
16056 if (I915_READ(PCH_DP_D) & DP_DETECTED)
16057 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
16058 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
16059 bool has_edp, has_port;
16061 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
16062 intel_crt_init(dev_priv);
16065 * The DP_DETECTED bit is the latched state of the DDC
16066 * SDA pin at boot. However since eDP doesn't require DDC
16067 * (no way to plug in a DP->HDMI dongle) the DDC pins for
16068 * eDP ports may have been muxed to an alternate function.
16069 * Thus we can't rely on the DP_DETECTED bit alone to detect
16070 * eDP ports. Consult the VBT as well as DP_DETECTED to
16071 * detect eDP ports.
16073 * Sadly the straps seem to be missing sometimes even for HDMI
16074 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
16075 * and VBT for the presence of the port. Additionally we can't
16076 * trust the port type the VBT declares as we've seen at least
16077 * HDMI ports that the VBT claim are DP or eDP.
16079 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
16080 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
16081 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
16082 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
16083 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
16084 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
16086 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
16087 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
16088 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
16089 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
16090 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
16091 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
16093 if (IS_CHERRYVIEW(dev_priv)) {
16095 * eDP not supported on port D,
16096 * so no need to worry about it
16098 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
16099 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
16100 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
16101 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
16102 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
16105 vlv_dsi_init(dev_priv);
16106 } else if (IS_PINEVIEW(dev_priv)) {
16107 intel_lvds_init(dev_priv);
16108 intel_crt_init(dev_priv);
16109 } else if (IS_GEN_RANGE(dev_priv, 3, 4)) {
16110 bool found = false;
16112 if (IS_MOBILE(dev_priv))
16113 intel_lvds_init(dev_priv);
16115 intel_crt_init(dev_priv);
16117 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
16118 DRM_DEBUG_KMS("probing SDVOB\n");
16119 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
16120 if (!found && IS_G4X(dev_priv)) {
16121 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
16122 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
16125 if (!found && IS_G4X(dev_priv))
16126 intel_dp_init(dev_priv, DP_B, PORT_B);
16129 /* Before G4X SDVOC doesn't have its own detect register */
16131 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
16132 DRM_DEBUG_KMS("probing SDVOC\n");
16133 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
16136 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
16138 if (IS_G4X(dev_priv)) {
16139 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
16140 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
16142 if (IS_G4X(dev_priv))
16143 intel_dp_init(dev_priv, DP_C, PORT_C);
16146 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
16147 intel_dp_init(dev_priv, DP_D, PORT_D);
16149 if (SUPPORTS_TV(dev_priv))
16150 intel_tv_init(dev_priv);
16151 } else if (IS_GEN(dev_priv, 2)) {
16152 if (IS_I85X(dev_priv))
16153 intel_lvds_init(dev_priv);
16155 intel_crt_init(dev_priv);
16156 intel_dvo_init(dev_priv);
16159 intel_psr_init(dev_priv);
16161 for_each_intel_encoder(&dev_priv->drm, encoder) {
16162 encoder->base.possible_crtcs =
16163 intel_encoder_possible_crtcs(encoder);
16164 encoder->base.possible_clones =
16165 intel_encoder_possible_clones(encoder);
16168 intel_init_pch_refclk(dev_priv);
16170 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
16173 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
16175 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
16177 drm_framebuffer_cleanup(fb);
16178 intel_frontbuffer_put(intel_fb->frontbuffer);
16183 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
16184 struct drm_file *file,
16185 unsigned int *handle)
16187 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
16189 if (obj->userptr.mm) {
16190 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
16194 return drm_gem_handle_create(file, &obj->base, handle);
16197 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
16198 struct drm_file *file,
16199 unsigned flags, unsigned color,
16200 struct drm_clip_rect *clips,
16201 unsigned num_clips)
16203 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
16205 i915_gem_object_flush_if_display(obj);
16206 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
16211 static const struct drm_framebuffer_funcs intel_fb_funcs = {
16212 .destroy = intel_user_framebuffer_destroy,
16213 .create_handle = intel_user_framebuffer_create_handle,
16214 .dirty = intel_user_framebuffer_dirty,
16217 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
16218 struct drm_i915_gem_object *obj,
16219 struct drm_mode_fb_cmd2 *mode_cmd)
16221 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
16222 struct drm_framebuffer *fb = &intel_fb->base;
16224 unsigned int tiling, stride;
16228 intel_fb->frontbuffer = intel_frontbuffer_get(obj);
16229 if (!intel_fb->frontbuffer)
16232 i915_gem_object_lock(obj);
16233 tiling = i915_gem_object_get_tiling(obj);
16234 stride = i915_gem_object_get_stride(obj);
16235 i915_gem_object_unlock(obj);
16237 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
16239 * If there's a fence, enforce that
16240 * the fb modifier and tiling mode match.
16242 if (tiling != I915_TILING_NONE &&
16243 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
16244 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
16248 if (tiling == I915_TILING_X) {
16249 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
16250 } else if (tiling == I915_TILING_Y) {
16251 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
16256 if (!drm_any_plane_has_format(&dev_priv->drm,
16257 mode_cmd->pixel_format,
16258 mode_cmd->modifier[0])) {
16259 struct drm_format_name_buf format_name;
16261 DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n",
16262 drm_get_format_name(mode_cmd->pixel_format,
16264 mode_cmd->modifier[0]);
16269 * gen2/3 display engine uses the fence if present,
16270 * so the tiling mode must match the fb modifier exactly.
16272 if (INTEL_GEN(dev_priv) < 4 &&
16273 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
16274 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
16278 max_stride = intel_fb_max_stride(dev_priv, mode_cmd->pixel_format,
16279 mode_cmd->modifier[0]);
16280 if (mode_cmd->pitches[0] > max_stride) {
16281 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
16282 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
16283 "tiled" : "linear",
16284 mode_cmd->pitches[0], max_stride);
16289 * If there's a fence, enforce that
16290 * the fb pitch and fence stride match.
16292 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
16293 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
16294 mode_cmd->pitches[0], stride);
16298 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
16299 if (mode_cmd->offsets[0] != 0)
16302 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
16304 for (i = 0; i < fb->format->num_planes; i++) {
16305 u32 stride_alignment;
16307 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
16308 DRM_DEBUG_KMS("bad plane %d handle\n", i);
16312 stride_alignment = intel_fb_stride_alignment(fb, i);
16315 * Display WA #0531: skl,bxt,kbl,glk
16317 * Render decompression and plane width > 3840
16318 * combined with horizontal panning requires the
16319 * plane stride to be a multiple of 4. We'll just
16320 * require the entire fb to accommodate that to avoid
16321 * potential runtime errors at plane configuration time.
16323 if (IS_GEN(dev_priv, 9) && i == 0 && fb->width > 3840 &&
16324 is_ccs_modifier(fb->modifier))
16325 stride_alignment *= 4;
16327 if (fb->pitches[i] & (stride_alignment - 1)) {
16328 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
16329 i, fb->pitches[i], stride_alignment);
16333 fb->obj[i] = &obj->base;
16336 ret = intel_fill_fb_info(dev_priv, fb);
16340 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
16342 DRM_ERROR("framebuffer init failed %d\n", ret);
16349 intel_frontbuffer_put(intel_fb->frontbuffer);
16353 static struct drm_framebuffer *
16354 intel_user_framebuffer_create(struct drm_device *dev,
16355 struct drm_file *filp,
16356 const struct drm_mode_fb_cmd2 *user_mode_cmd)
16358 struct drm_framebuffer *fb;
16359 struct drm_i915_gem_object *obj;
16360 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
16362 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
16364 return ERR_PTR(-ENOENT);
16366 fb = intel_framebuffer_create(obj, &mode_cmd);
16367 i915_gem_object_put(obj);
16372 static void intel_atomic_state_free(struct drm_atomic_state *state)
16374 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
16376 drm_atomic_state_default_release(state);
16378 i915_sw_fence_fini(&intel_state->commit_ready);
16383 static enum drm_mode_status
16384 intel_mode_valid(struct drm_device *dev,
16385 const struct drm_display_mode *mode)
16387 struct drm_i915_private *dev_priv = to_i915(dev);
16388 int hdisplay_max, htotal_max;
16389 int vdisplay_max, vtotal_max;
16392 * Can't reject DBLSCAN here because Xorg ddxen can add piles
16393 * of DBLSCAN modes to the output's mode list when they detect
16394 * the scaling mode property on the connector. And they don't
16395 * ask the kernel to validate those modes in any way until
16396 * modeset time at which point the client gets a protocol error.
16397 * So in order to not upset those clients we silently ignore the
16398 * DBLSCAN flag on such connectors. For other connectors we will
16399 * reject modes with the DBLSCAN flag in encoder->compute_config().
16400 * And we always reject DBLSCAN modes in connector->mode_valid()
16401 * as we never want such modes on the connector's mode list.
16404 if (mode->vscan > 1)
16405 return MODE_NO_VSCAN;
16407 if (mode->flags & DRM_MODE_FLAG_HSKEW)
16408 return MODE_H_ILLEGAL;
16410 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
16411 DRM_MODE_FLAG_NCSYNC |
16412 DRM_MODE_FLAG_PCSYNC))
16415 if (mode->flags & (DRM_MODE_FLAG_BCAST |
16416 DRM_MODE_FLAG_PIXMUX |
16417 DRM_MODE_FLAG_CLKDIV2))
16420 /* Transcoder timing limits */
16421 if (INTEL_GEN(dev_priv) >= 11) {
16422 hdisplay_max = 16384;
16423 vdisplay_max = 8192;
16424 htotal_max = 16384;
16426 } else if (INTEL_GEN(dev_priv) >= 9 ||
16427 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
16428 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
16429 vdisplay_max = 4096;
16432 } else if (INTEL_GEN(dev_priv) >= 3) {
16433 hdisplay_max = 4096;
16434 vdisplay_max = 4096;
16438 hdisplay_max = 2048;
16439 vdisplay_max = 2048;
16444 if (mode->hdisplay > hdisplay_max ||
16445 mode->hsync_start > htotal_max ||
16446 mode->hsync_end > htotal_max ||
16447 mode->htotal > htotal_max)
16448 return MODE_H_ILLEGAL;
16450 if (mode->vdisplay > vdisplay_max ||
16451 mode->vsync_start > vtotal_max ||
16452 mode->vsync_end > vtotal_max ||
16453 mode->vtotal > vtotal_max)
16454 return MODE_V_ILLEGAL;
16456 if (INTEL_GEN(dev_priv) >= 5) {
16457 if (mode->hdisplay < 64 ||
16458 mode->htotal - mode->hdisplay < 32)
16459 return MODE_H_ILLEGAL;
16461 if (mode->vtotal - mode->vdisplay < 5)
16462 return MODE_V_ILLEGAL;
16464 if (mode->htotal - mode->hdisplay < 32)
16465 return MODE_H_ILLEGAL;
16467 if (mode->vtotal - mode->vdisplay < 3)
16468 return MODE_V_ILLEGAL;
16474 enum drm_mode_status
16475 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
16476 const struct drm_display_mode *mode)
16478 int plane_width_max, plane_height_max;
16481 * intel_mode_valid() should be
16482 * sufficient on older platforms.
16484 if (INTEL_GEN(dev_priv) < 9)
16488 * Most people will probably want a fullscreen
16489 * plane so let's not advertize modes that are
16490 * too big for that.
16492 if (INTEL_GEN(dev_priv) >= 11) {
16493 plane_width_max = 5120;
16494 plane_height_max = 4320;
16496 plane_width_max = 5120;
16497 plane_height_max = 4096;
16500 if (mode->hdisplay > plane_width_max)
16501 return MODE_H_ILLEGAL;
16503 if (mode->vdisplay > plane_height_max)
16504 return MODE_V_ILLEGAL;
16509 static const struct drm_mode_config_funcs intel_mode_funcs = {
16510 .fb_create = intel_user_framebuffer_create,
16511 .get_format_info = intel_get_format_info,
16512 .output_poll_changed = intel_fbdev_output_poll_changed,
16513 .mode_valid = intel_mode_valid,
16514 .atomic_check = intel_atomic_check,
16515 .atomic_commit = intel_atomic_commit,
16516 .atomic_state_alloc = intel_atomic_state_alloc,
16517 .atomic_state_clear = intel_atomic_state_clear,
16518 .atomic_state_free = intel_atomic_state_free,
16522 * intel_init_display_hooks - initialize the display modesetting hooks
16523 * @dev_priv: device private
16525 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
16527 intel_init_cdclk_hooks(dev_priv);
16529 if (INTEL_GEN(dev_priv) >= 9) {
16530 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
16531 dev_priv->display.get_initial_plane_config =
16532 skylake_get_initial_plane_config;
16533 dev_priv->display.crtc_compute_clock =
16534 haswell_crtc_compute_clock;
16535 dev_priv->display.crtc_enable = haswell_crtc_enable;
16536 dev_priv->display.crtc_disable = haswell_crtc_disable;
16537 } else if (HAS_DDI(dev_priv)) {
16538 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
16539 dev_priv->display.get_initial_plane_config =
16540 i9xx_get_initial_plane_config;
16541 dev_priv->display.crtc_compute_clock =
16542 haswell_crtc_compute_clock;
16543 dev_priv->display.crtc_enable = haswell_crtc_enable;
16544 dev_priv->display.crtc_disable = haswell_crtc_disable;
16545 } else if (HAS_PCH_SPLIT(dev_priv)) {
16546 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
16547 dev_priv->display.get_initial_plane_config =
16548 i9xx_get_initial_plane_config;
16549 dev_priv->display.crtc_compute_clock =
16550 ironlake_crtc_compute_clock;
16551 dev_priv->display.crtc_enable = ironlake_crtc_enable;
16552 dev_priv->display.crtc_disable = ironlake_crtc_disable;
16553 } else if (IS_CHERRYVIEW(dev_priv)) {
16554 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16555 dev_priv->display.get_initial_plane_config =
16556 i9xx_get_initial_plane_config;
16557 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
16558 dev_priv->display.crtc_enable = valleyview_crtc_enable;
16559 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16560 } else if (IS_VALLEYVIEW(dev_priv)) {
16561 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16562 dev_priv->display.get_initial_plane_config =
16563 i9xx_get_initial_plane_config;
16564 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
16565 dev_priv->display.crtc_enable = valleyview_crtc_enable;
16566 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16567 } else if (IS_G4X(dev_priv)) {
16568 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16569 dev_priv->display.get_initial_plane_config =
16570 i9xx_get_initial_plane_config;
16571 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
16572 dev_priv->display.crtc_enable = i9xx_crtc_enable;
16573 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16574 } else if (IS_PINEVIEW(dev_priv)) {
16575 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16576 dev_priv->display.get_initial_plane_config =
16577 i9xx_get_initial_plane_config;
16578 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
16579 dev_priv->display.crtc_enable = i9xx_crtc_enable;
16580 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16581 } else if (!IS_GEN(dev_priv, 2)) {
16582 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16583 dev_priv->display.get_initial_plane_config =
16584 i9xx_get_initial_plane_config;
16585 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
16586 dev_priv->display.crtc_enable = i9xx_crtc_enable;
16587 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16589 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16590 dev_priv->display.get_initial_plane_config =
16591 i9xx_get_initial_plane_config;
16592 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
16593 dev_priv->display.crtc_enable = i9xx_crtc_enable;
16594 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16597 if (IS_GEN(dev_priv, 5)) {
16598 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
16599 } else if (IS_GEN(dev_priv, 6)) {
16600 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
16601 } else if (IS_IVYBRIDGE(dev_priv)) {
16602 /* FIXME: detect B0+ stepping and use auto training */
16603 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
16604 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
16605 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
16608 if (INTEL_GEN(dev_priv) >= 9)
16609 dev_priv->display.commit_modeset_enables = skl_commit_modeset_enables;
16611 dev_priv->display.commit_modeset_enables = intel_commit_modeset_enables;
16615 void intel_modeset_init_hw(struct drm_i915_private *i915)
16617 intel_update_cdclk(i915);
16618 intel_dump_cdclk_state(&i915->cdclk.hw, "Current CDCLK");
16619 i915->cdclk.logical = i915->cdclk.actual = i915->cdclk.hw;
16623 * Calculate what we think the watermarks should be for the state we've read
16624 * out of the hardware and then immediately program those watermarks so that
16625 * we ensure the hardware settings match our internal state.
16627 * We can calculate what we think WM's should be by creating a duplicate of the
16628 * current state (which was constructed during hardware readout) and running it
16629 * through the atomic check code to calculate new watermark values in the
16632 static void sanitize_watermarks(struct drm_device *dev)
16634 struct drm_i915_private *dev_priv = to_i915(dev);
16635 struct drm_atomic_state *state;
16636 struct intel_atomic_state *intel_state;
16637 struct intel_crtc *crtc;
16638 struct intel_crtc_state *crtc_state;
16639 struct drm_modeset_acquire_ctx ctx;
16643 /* Only supported on platforms that use atomic watermark design */
16644 if (!dev_priv->display.optimize_watermarks)
16648 * We need to hold connection_mutex before calling duplicate_state so
16649 * that the connector loop is protected.
16651 drm_modeset_acquire_init(&ctx, 0);
16653 ret = drm_modeset_lock_all_ctx(dev, &ctx);
16654 if (ret == -EDEADLK) {
16655 drm_modeset_backoff(&ctx);
16657 } else if (WARN_ON(ret)) {
16661 state = drm_atomic_helper_duplicate_state(dev, &ctx);
16662 if (WARN_ON(IS_ERR(state)))
16665 intel_state = to_intel_atomic_state(state);
16668 * Hardware readout is the only time we don't want to calculate
16669 * intermediate watermarks (since we don't trust the current
16672 if (!HAS_GMCH(dev_priv))
16673 intel_state->skip_intermediate_wm = true;
16675 ret = intel_atomic_check(dev, state);
16678 * If we fail here, it means that the hardware appears to be
16679 * programmed in a way that shouldn't be possible, given our
16680 * understanding of watermark requirements. This might mean a
16681 * mistake in the hardware readout code or a mistake in the
16682 * watermark calculations for a given platform. Raise a WARN
16683 * so that this is noticeable.
16685 * If this actually happens, we'll have to just leave the
16686 * BIOS-programmed watermarks untouched and hope for the best.
16688 WARN(true, "Could not determine valid watermarks for inherited state\n");
16692 /* Write calculated watermark values back */
16693 for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) {
16694 crtc_state->wm.need_postvbl_update = true;
16695 dev_priv->display.optimize_watermarks(intel_state, crtc_state);
16697 to_intel_crtc_state(crtc->base.state)->wm = crtc_state->wm;
16701 drm_atomic_state_put(state);
16703 drm_modeset_drop_locks(&ctx);
16704 drm_modeset_acquire_fini(&ctx);
16707 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
16709 if (IS_GEN(dev_priv, 5)) {
16711 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
16713 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
16714 } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) {
16715 dev_priv->fdi_pll_freq = 270000;
16720 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
16723 static int intel_initial_commit(struct drm_device *dev)
16725 struct drm_atomic_state *state = NULL;
16726 struct drm_modeset_acquire_ctx ctx;
16727 struct drm_crtc *crtc;
16728 struct drm_crtc_state *crtc_state;
16731 state = drm_atomic_state_alloc(dev);
16735 drm_modeset_acquire_init(&ctx, 0);
16738 state->acquire_ctx = &ctx;
16740 drm_for_each_crtc(crtc, dev) {
16741 crtc_state = drm_atomic_get_crtc_state(state, crtc);
16742 if (IS_ERR(crtc_state)) {
16743 ret = PTR_ERR(crtc_state);
16747 if (crtc_state->active) {
16748 ret = drm_atomic_add_affected_planes(state, crtc);
16753 * FIXME hack to force a LUT update to avoid the
16754 * plane update forcing the pipe gamma on without
16755 * having a proper LUT loaded. Remove once we
16756 * have readout for pipe gamma enable.
16758 crtc_state->color_mgmt_changed = true;
16762 ret = drm_atomic_commit(state);
16765 if (ret == -EDEADLK) {
16766 drm_atomic_state_clear(state);
16767 drm_modeset_backoff(&ctx);
16771 drm_atomic_state_put(state);
16773 drm_modeset_drop_locks(&ctx);
16774 drm_modeset_acquire_fini(&ctx);
16779 static void intel_mode_config_init(struct drm_i915_private *i915)
16781 struct drm_mode_config *mode_config = &i915->drm.mode_config;
16783 drm_mode_config_init(&i915->drm);
16785 mode_config->min_width = 0;
16786 mode_config->min_height = 0;
16788 mode_config->preferred_depth = 24;
16789 mode_config->prefer_shadow = 1;
16791 mode_config->allow_fb_modifiers = true;
16793 mode_config->funcs = &intel_mode_funcs;
16796 * Maximum framebuffer dimensions, chosen to match
16797 * the maximum render engine surface size on gen4+.
16799 if (INTEL_GEN(i915) >= 7) {
16800 mode_config->max_width = 16384;
16801 mode_config->max_height = 16384;
16802 } else if (INTEL_GEN(i915) >= 4) {
16803 mode_config->max_width = 8192;
16804 mode_config->max_height = 8192;
16805 } else if (IS_GEN(i915, 3)) {
16806 mode_config->max_width = 4096;
16807 mode_config->max_height = 4096;
16809 mode_config->max_width = 2048;
16810 mode_config->max_height = 2048;
16813 if (IS_I845G(i915) || IS_I865G(i915)) {
16814 mode_config->cursor_width = IS_I845G(i915) ? 64 : 512;
16815 mode_config->cursor_height = 1023;
16816 } else if (IS_GEN(i915, 2)) {
16817 mode_config->cursor_width = 64;
16818 mode_config->cursor_height = 64;
16820 mode_config->cursor_width = 256;
16821 mode_config->cursor_height = 256;
16825 int intel_modeset_init(struct drm_i915_private *i915)
16827 struct drm_device *dev = &i915->drm;
16829 struct intel_crtc *crtc;
16832 i915->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
16833 i915->flip_wq = alloc_workqueue("i915_flip", WQ_HIGHPRI |
16834 WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE);
16836 intel_mode_config_init(i915);
16838 ret = intel_bw_init(i915);
16842 init_llist_head(&i915->atomic_helper.free_list);
16843 INIT_WORK(&i915->atomic_helper.free_work,
16844 intel_atomic_helper_free_state_worker);
16846 intel_init_quirks(i915);
16848 intel_fbc_init(i915);
16850 intel_init_pm(i915);
16852 intel_panel_sanitize_ssc(i915);
16854 intel_gmbus_setup(i915);
16856 DRM_DEBUG_KMS("%d display pipe%s available.\n",
16857 INTEL_NUM_PIPES(i915),
16858 INTEL_NUM_PIPES(i915) > 1 ? "s" : "");
16860 if (HAS_DISPLAY(i915) && INTEL_DISPLAY_ENABLED(i915)) {
16861 for_each_pipe(i915, pipe) {
16862 ret = intel_crtc_init(i915, pipe);
16864 drm_mode_config_cleanup(dev);
16870 intel_shared_dpll_init(dev);
16871 intel_update_fdi_pll_freq(i915);
16873 intel_update_czclk(i915);
16874 intel_modeset_init_hw(i915);
16876 intel_hdcp_component_init(i915);
16878 if (i915->max_cdclk_freq == 0)
16879 intel_update_max_cdclk(i915);
16881 /* Just disable it once at startup */
16882 intel_vga_disable(i915);
16883 intel_setup_outputs(i915);
16885 drm_modeset_lock_all(dev);
16886 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
16887 drm_modeset_unlock_all(dev);
16889 for_each_intel_crtc(dev, crtc) {
16890 struct intel_initial_plane_config plane_config = {};
16896 * Note that reserving the BIOS fb up front prevents us
16897 * from stuffing other stolen allocations like the ring
16898 * on top. This prevents some ugliness at boot time, and
16899 * can even allow for smooth boot transitions if the BIOS
16900 * fb is large enough for the active pipe configuration.
16902 i915->display.get_initial_plane_config(crtc, &plane_config);
16905 * If the fb is shared between multiple heads, we'll
16906 * just get the first one.
16908 intel_find_initial_plane_obj(crtc, &plane_config);
16912 * Make sure hardware watermarks really match the state we read out.
16913 * Note that we need to do this after reconstructing the BIOS fb's
16914 * since the watermark calculation done here will use pstate->fb.
16916 if (!HAS_GMCH(i915))
16917 sanitize_watermarks(dev);
16920 * Force all active planes to recompute their states. So that on
16921 * mode_setcrtc after probe, all the intel_plane_state variables
16922 * are already calculated and there is no assert_plane warnings
16925 ret = intel_initial_commit(dev);
16927 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
16932 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
16934 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
16935 /* 640x480@60Hz, ~25175 kHz */
16936 struct dpll clock = {
16946 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
16948 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
16949 pipe_name(pipe), clock.vco, clock.dot);
16951 fp = i9xx_dpll_compute_fp(&clock);
16952 dpll = DPLL_DVO_2X_MODE |
16953 DPLL_VGA_MODE_DIS |
16954 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
16955 PLL_P2_DIVIDE_BY_4 |
16956 PLL_REF_INPUT_DREFCLK |
16959 I915_WRITE(FP0(pipe), fp);
16960 I915_WRITE(FP1(pipe), fp);
16962 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
16963 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
16964 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
16965 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
16966 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
16967 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
16968 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
16971 * Apparently we need to have VGA mode enabled prior to changing
16972 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
16973 * dividers, even though the register value does change.
16975 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
16976 I915_WRITE(DPLL(pipe), dpll);
16978 /* Wait for the clocks to stabilize. */
16979 POSTING_READ(DPLL(pipe));
16982 /* The pixel multiplier can only be updated once the
16983 * DPLL is enabled and the clocks are stable.
16985 * So write it again.
16987 I915_WRITE(DPLL(pipe), dpll);
16989 /* We do this three times for luck */
16990 for (i = 0; i < 3 ; i++) {
16991 I915_WRITE(DPLL(pipe), dpll);
16992 POSTING_READ(DPLL(pipe));
16993 udelay(150); /* wait for warmup */
16996 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
16997 POSTING_READ(PIPECONF(pipe));
16999 intel_wait_for_pipe_scanline_moving(crtc);
17002 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
17004 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17006 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
17009 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
17010 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
17011 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
17012 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
17013 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
17015 I915_WRITE(PIPECONF(pipe), 0);
17016 POSTING_READ(PIPECONF(pipe));
17018 intel_wait_for_pipe_scanline_stopped(crtc);
17020 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
17021 POSTING_READ(DPLL(pipe));
17025 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
17027 struct intel_crtc *crtc;
17029 if (INTEL_GEN(dev_priv) >= 4)
17032 for_each_intel_crtc(&dev_priv->drm, crtc) {
17033 struct intel_plane *plane =
17034 to_intel_plane(crtc->base.primary);
17035 struct intel_crtc *plane_crtc;
17038 if (!plane->get_hw_state(plane, &pipe))
17041 if (pipe == crtc->pipe)
17044 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
17045 plane->base.base.id, plane->base.name);
17047 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17048 intel_plane_disable_noatomic(plane_crtc, plane);
17052 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
17054 struct drm_device *dev = crtc->base.dev;
17055 struct intel_encoder *encoder;
17057 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
17063 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
17065 struct drm_device *dev = encoder->base.dev;
17066 struct intel_connector *connector;
17068 for_each_connector_on_encoder(dev, &encoder->base, connector)
17074 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
17075 enum pipe pch_transcoder)
17077 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
17078 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
17081 static void intel_sanitize_crtc(struct intel_crtc *crtc,
17082 struct drm_modeset_acquire_ctx *ctx)
17084 struct drm_device *dev = crtc->base.dev;
17085 struct drm_i915_private *dev_priv = to_i915(dev);
17086 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
17087 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
17089 /* Clear any frame start delays used for debugging left by the BIOS */
17090 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
17091 i915_reg_t reg = PIPECONF(cpu_transcoder);
17094 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
17097 if (crtc_state->base.active) {
17098 struct intel_plane *plane;
17100 /* Disable everything but the primary plane */
17101 for_each_intel_plane_on_crtc(dev, crtc, plane) {
17102 const struct intel_plane_state *plane_state =
17103 to_intel_plane_state(plane->base.state);
17105 if (plane_state->base.visible &&
17106 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
17107 intel_plane_disable_noatomic(crtc, plane);
17111 * Disable any background color set by the BIOS, but enable the
17112 * gamma and CSC to match how we program our planes.
17114 if (INTEL_GEN(dev_priv) >= 9)
17115 I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe),
17116 SKL_BOTTOM_COLOR_GAMMA_ENABLE |
17117 SKL_BOTTOM_COLOR_CSC_ENABLE);
17120 /* Adjust the state of the output pipe according to whether we
17121 * have active connectors/encoders. */
17122 if (crtc_state->base.active && !intel_crtc_has_encoders(crtc))
17123 intel_crtc_disable_noatomic(&crtc->base, ctx);
17125 if (crtc_state->base.active || HAS_GMCH(dev_priv)) {
17127 * We start out with underrun reporting disabled to avoid races.
17128 * For correct bookkeeping mark this on active crtcs.
17130 * Also on gmch platforms we dont have any hardware bits to
17131 * disable the underrun reporting. Which means we need to start
17132 * out with underrun reporting disabled also on inactive pipes,
17133 * since otherwise we'll complain about the garbage we read when
17134 * e.g. coming up after runtime pm.
17136 * No protection against concurrent access is required - at
17137 * worst a fifo underrun happens which also sets this to false.
17139 crtc->cpu_fifo_underrun_disabled = true;
17141 * We track the PCH trancoder underrun reporting state
17142 * within the crtc. With crtc for pipe A housing the underrun
17143 * reporting state for PCH transcoder A, crtc for pipe B housing
17144 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
17145 * and marking underrun reporting as disabled for the non-existing
17146 * PCH transcoders B and C would prevent enabling the south
17147 * error interrupt (see cpt_can_enable_serr_int()).
17149 if (has_pch_trancoder(dev_priv, crtc->pipe))
17150 crtc->pch_fifo_underrun_disabled = true;
17154 static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state)
17156 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
17159 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
17160 * the hardware when a high res displays plugged in. DPLL P
17161 * divider is zero, and the pipe timings are bonkers. We'll
17162 * try to disable everything in that case.
17164 * FIXME would be nice to be able to sanitize this state
17165 * without several WARNs, but for now let's take the easy
17168 return IS_GEN(dev_priv, 6) &&
17169 crtc_state->base.active &&
17170 crtc_state->shared_dpll &&
17171 crtc_state->port_clock == 0;
17174 static void intel_sanitize_encoder(struct intel_encoder *encoder)
17176 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
17177 struct intel_connector *connector;
17178 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
17179 struct intel_crtc_state *crtc_state = crtc ?
17180 to_intel_crtc_state(crtc->base.state) : NULL;
17182 /* We need to check both for a crtc link (meaning that the
17183 * encoder is active and trying to read from a pipe) and the
17184 * pipe itself being active. */
17185 bool has_active_crtc = crtc_state &&
17186 crtc_state->base.active;
17188 if (crtc_state && has_bogus_dpll_config(crtc_state)) {
17189 DRM_DEBUG_KMS("BIOS has misprogrammed the hardware. Disabling pipe %c\n",
17190 pipe_name(crtc->pipe));
17191 has_active_crtc = false;
17194 connector = intel_encoder_find_connector(encoder);
17195 if (connector && !has_active_crtc) {
17196 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
17197 encoder->base.base.id,
17198 encoder->base.name);
17200 /* Connector is active, but has no active pipe. This is
17201 * fallout from our resume register restoring. Disable
17202 * the encoder manually again. */
17204 struct drm_encoder *best_encoder;
17206 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
17207 encoder->base.base.id,
17208 encoder->base.name);
17210 /* avoid oopsing in case the hooks consult best_encoder */
17211 best_encoder = connector->base.state->best_encoder;
17212 connector->base.state->best_encoder = &encoder->base;
17214 if (encoder->disable)
17215 encoder->disable(encoder, crtc_state,
17216 connector->base.state);
17217 if (encoder->post_disable)
17218 encoder->post_disable(encoder, crtc_state,
17219 connector->base.state);
17221 connector->base.state->best_encoder = best_encoder;
17223 encoder->base.crtc = NULL;
17225 /* Inconsistent output/port/pipe state happens presumably due to
17226 * a bug in one of the get_hw_state functions. Or someplace else
17227 * in our code, like the register restore mess on resume. Clamp
17228 * things to off as a safer default. */
17230 connector->base.dpms = DRM_MODE_DPMS_OFF;
17231 connector->base.encoder = NULL;
17234 /* notify opregion of the sanitized encoder state */
17235 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
17237 if (INTEL_GEN(dev_priv) >= 11)
17238 icl_sanitize_encoder_pll_mapping(encoder);
17241 /* FIXME read out full plane state for all planes */
17242 static void readout_plane_state(struct drm_i915_private *dev_priv)
17244 struct intel_plane *plane;
17245 struct intel_crtc *crtc;
17247 for_each_intel_plane(&dev_priv->drm, plane) {
17248 struct intel_plane_state *plane_state =
17249 to_intel_plane_state(plane->base.state);
17250 struct intel_crtc_state *crtc_state;
17251 enum pipe pipe = PIPE_A;
17254 visible = plane->get_hw_state(plane, &pipe);
17256 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17257 crtc_state = to_intel_crtc_state(crtc->base.state);
17259 intel_set_plane_visible(crtc_state, plane_state, visible);
17261 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
17262 plane->base.base.id, plane->base.name,
17263 enableddisabled(visible), pipe_name(pipe));
17266 for_each_intel_crtc(&dev_priv->drm, crtc) {
17267 struct intel_crtc_state *crtc_state =
17268 to_intel_crtc_state(crtc->base.state);
17270 fixup_active_planes(crtc_state);
17274 static void intel_modeset_readout_hw_state(struct drm_device *dev)
17276 struct drm_i915_private *dev_priv = to_i915(dev);
17278 struct intel_crtc *crtc;
17279 struct intel_encoder *encoder;
17280 struct intel_connector *connector;
17281 struct drm_connector_list_iter conn_iter;
17284 dev_priv->active_pipes = 0;
17286 for_each_intel_crtc(dev, crtc) {
17287 struct intel_crtc_state *crtc_state =
17288 to_intel_crtc_state(crtc->base.state);
17290 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
17291 memset(crtc_state, 0, sizeof(*crtc_state));
17292 __drm_atomic_helper_crtc_reset(&crtc->base, &crtc_state->base);
17294 crtc_state->base.active = crtc_state->base.enable =
17295 dev_priv->display.get_pipe_config(crtc, crtc_state);
17297 crtc->base.enabled = crtc_state->base.enable;
17298 crtc->active = crtc_state->base.active;
17300 if (crtc_state->base.active)
17301 dev_priv->active_pipes |= BIT(crtc->pipe);
17303 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
17304 crtc->base.base.id, crtc->base.name,
17305 enableddisabled(crtc_state->base.active));
17308 readout_plane_state(dev_priv);
17310 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
17311 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
17313 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
17314 &pll->state.hw_state);
17316 if (IS_ELKHARTLAKE(dev_priv) && pll->on &&
17317 pll->info->id == DPLL_ID_EHL_DPLL4) {
17318 pll->wakeref = intel_display_power_get(dev_priv,
17319 POWER_DOMAIN_DPLL_DC_OFF);
17322 pll->state.crtc_mask = 0;
17323 for_each_intel_crtc(dev, crtc) {
17324 struct intel_crtc_state *crtc_state =
17325 to_intel_crtc_state(crtc->base.state);
17327 if (crtc_state->base.active &&
17328 crtc_state->shared_dpll == pll)
17329 pll->state.crtc_mask |= 1 << crtc->pipe;
17331 pll->active_mask = pll->state.crtc_mask;
17333 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
17334 pll->info->name, pll->state.crtc_mask, pll->on);
17337 for_each_intel_encoder(dev, encoder) {
17340 if (encoder->get_hw_state(encoder, &pipe)) {
17341 struct intel_crtc_state *crtc_state;
17343 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17344 crtc_state = to_intel_crtc_state(crtc->base.state);
17346 encoder->base.crtc = &crtc->base;
17347 encoder->get_config(encoder, crtc_state);
17349 encoder->base.crtc = NULL;
17352 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
17353 encoder->base.base.id, encoder->base.name,
17354 enableddisabled(encoder->base.crtc),
17358 drm_connector_list_iter_begin(dev, &conn_iter);
17359 for_each_intel_connector_iter(connector, &conn_iter) {
17360 if (connector->get_hw_state(connector)) {
17361 struct intel_crtc_state *crtc_state;
17362 struct intel_crtc *crtc;
17364 connector->base.dpms = DRM_MODE_DPMS_ON;
17366 encoder = connector->encoder;
17367 connector->base.encoder = &encoder->base;
17369 crtc = to_intel_crtc(encoder->base.crtc);
17370 crtc_state = crtc ? to_intel_crtc_state(crtc->base.state) : NULL;
17372 if (crtc_state && crtc_state->base.active) {
17374 * This has to be done during hardware readout
17375 * because anything calling .crtc_disable may
17376 * rely on the connector_mask being accurate.
17378 crtc_state->base.connector_mask |=
17379 drm_connector_mask(&connector->base);
17380 crtc_state->base.encoder_mask |=
17381 drm_encoder_mask(&encoder->base);
17384 connector->base.dpms = DRM_MODE_DPMS_OFF;
17385 connector->base.encoder = NULL;
17387 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
17388 connector->base.base.id, connector->base.name,
17389 enableddisabled(connector->base.encoder));
17391 drm_connector_list_iter_end(&conn_iter);
17393 for_each_intel_crtc(dev, crtc) {
17394 struct intel_bw_state *bw_state =
17395 to_intel_bw_state(dev_priv->bw_obj.state);
17396 struct intel_crtc_state *crtc_state =
17397 to_intel_crtc_state(crtc->base.state);
17398 struct intel_plane *plane;
17401 if (crtc_state->base.active) {
17402 struct drm_display_mode mode;
17404 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode,
17407 mode = crtc_state->base.adjusted_mode;
17408 mode.hdisplay = crtc_state->pipe_src_w;
17409 mode.vdisplay = crtc_state->pipe_src_h;
17410 WARN_ON(drm_atomic_set_mode_for_crtc(&crtc_state->base, &mode));
17413 * The initial mode needs to be set in order to keep
17414 * the atomic core happy. It wants a valid mode if the
17415 * crtc's enabled, so we do the above call.
17417 * But we don't set all the derived state fully, hence
17418 * set a flag to indicate that a full recalculation is
17419 * needed on the next commit.
17421 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
17423 intel_crtc_compute_pixel_rate(crtc_state);
17425 intel_crtc_update_active_timings(crtc_state);
17428 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
17429 const struct intel_plane_state *plane_state =
17430 to_intel_plane_state(plane->base.state);
17433 * FIXME don't have the fb yet, so can't
17434 * use intel_plane_data_rate() :(
17436 if (plane_state->base.visible)
17437 crtc_state->data_rate[plane->id] =
17438 4 * crtc_state->pixel_rate;
17440 * FIXME don't have the fb yet, so can't
17441 * use plane->min_cdclk() :(
17443 if (plane_state->base.visible && plane->min_cdclk) {
17444 if (crtc_state->double_wide ||
17445 INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
17446 crtc_state->min_cdclk[plane->id] =
17447 DIV_ROUND_UP(crtc_state->pixel_rate, 2);
17449 crtc_state->min_cdclk[plane->id] =
17450 crtc_state->pixel_rate;
17452 DRM_DEBUG_KMS("[PLANE:%d:%s] min_cdclk %d kHz\n",
17453 plane->base.base.id, plane->base.name,
17454 crtc_state->min_cdclk[plane->id]);
17457 if (crtc_state->base.active) {
17458 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
17459 if (WARN_ON(min_cdclk < 0))
17463 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
17464 dev_priv->min_voltage_level[crtc->pipe] =
17465 crtc_state->min_voltage_level;
17467 intel_bw_crtc_update(bw_state, crtc_state);
17469 intel_pipe_config_sanity_check(dev_priv, crtc_state);
17474 get_encoder_power_domains(struct drm_i915_private *dev_priv)
17476 struct intel_encoder *encoder;
17478 for_each_intel_encoder(&dev_priv->drm, encoder) {
17479 struct intel_crtc_state *crtc_state;
17481 if (!encoder->get_power_domains)
17485 * MST-primary and inactive encoders don't have a crtc state
17486 * and neither of these require any power domain references.
17488 if (!encoder->base.crtc)
17491 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
17492 encoder->get_power_domains(encoder, crtc_state);
17496 static void intel_early_display_was(struct drm_i915_private *dev_priv)
17498 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
17499 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
17500 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
17503 if (IS_HASWELL(dev_priv)) {
17505 * WaRsPkgCStateDisplayPMReq:hsw
17506 * System hang if this isn't done before disabling all planes!
17508 I915_WRITE(CHICKEN_PAR1_1,
17509 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
17513 static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
17514 enum port port, i915_reg_t hdmi_reg)
17516 u32 val = I915_READ(hdmi_reg);
17518 if (val & SDVO_ENABLE ||
17519 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
17522 DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n",
17525 val &= ~SDVO_PIPE_SEL_MASK;
17526 val |= SDVO_PIPE_SEL(PIPE_A);
17528 I915_WRITE(hdmi_reg, val);
17531 static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
17532 enum port port, i915_reg_t dp_reg)
17534 u32 val = I915_READ(dp_reg);
17536 if (val & DP_PORT_EN ||
17537 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
17540 DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n",
17543 val &= ~DP_PIPE_SEL_MASK;
17544 val |= DP_PIPE_SEL(PIPE_A);
17546 I915_WRITE(dp_reg, val);
17549 static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
17552 * The BIOS may select transcoder B on some of the PCH
17553 * ports even it doesn't enable the port. This would trip
17554 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
17555 * Sanitize the transcoder select bits to prevent that. We
17556 * assume that the BIOS never actually enabled the port,
17557 * because if it did we'd actually have to toggle the port
17558 * on and back off to make the transcoder A select stick
17559 * (see. intel_dp_link_down(), intel_disable_hdmi(),
17560 * intel_disable_sdvo()).
17562 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
17563 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
17564 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
17566 /* PCH SDVOB multiplex with HDMIB */
17567 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
17568 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
17569 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
17572 /* Scan out the current hw modeset state,
17573 * and sanitizes it to the current state
17576 intel_modeset_setup_hw_state(struct drm_device *dev,
17577 struct drm_modeset_acquire_ctx *ctx)
17579 struct drm_i915_private *dev_priv = to_i915(dev);
17580 struct intel_crtc_state *crtc_state;
17581 struct intel_encoder *encoder;
17582 struct intel_crtc *crtc;
17583 intel_wakeref_t wakeref;
17586 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
17588 intel_early_display_was(dev_priv);
17589 intel_modeset_readout_hw_state(dev);
17591 /* HW state is read out, now we need to sanitize this mess. */
17593 /* Sanitize the TypeC port mode upfront, encoders depend on this */
17594 for_each_intel_encoder(dev, encoder) {
17595 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
17597 /* We need to sanitize only the MST primary port. */
17598 if (encoder->type != INTEL_OUTPUT_DP_MST &&
17599 intel_phy_is_tc(dev_priv, phy))
17600 intel_tc_port_sanitize(enc_to_dig_port(&encoder->base));
17603 get_encoder_power_domains(dev_priv);
17605 if (HAS_PCH_IBX(dev_priv))
17606 ibx_sanitize_pch_ports(dev_priv);
17609 * intel_sanitize_plane_mapping() may need to do vblank
17610 * waits, so we need vblank interrupts restored beforehand.
17612 for_each_intel_crtc(&dev_priv->drm, crtc) {
17613 crtc_state = to_intel_crtc_state(crtc->base.state);
17615 drm_crtc_vblank_reset(&crtc->base);
17617 if (crtc_state->base.active)
17618 intel_crtc_vblank_on(crtc_state);
17621 intel_sanitize_plane_mapping(dev_priv);
17623 for_each_intel_encoder(dev, encoder)
17624 intel_sanitize_encoder(encoder);
17626 for_each_intel_crtc(&dev_priv->drm, crtc) {
17627 crtc_state = to_intel_crtc_state(crtc->base.state);
17628 intel_sanitize_crtc(crtc, ctx);
17629 intel_dump_pipe_config(crtc_state, NULL, "[setup_hw_state]");
17632 intel_modeset_update_connector_atomic_state(dev);
17634 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
17635 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
17637 if (!pll->on || pll->active_mask)
17640 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
17643 pll->info->funcs->disable(dev_priv, pll);
17647 if (IS_G4X(dev_priv)) {
17648 g4x_wm_get_hw_state(dev_priv);
17649 g4x_wm_sanitize(dev_priv);
17650 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
17651 vlv_wm_get_hw_state(dev_priv);
17652 vlv_wm_sanitize(dev_priv);
17653 } else if (INTEL_GEN(dev_priv) >= 9) {
17654 skl_wm_get_hw_state(dev_priv);
17655 } else if (HAS_PCH_SPLIT(dev_priv)) {
17656 ilk_wm_get_hw_state(dev_priv);
17659 for_each_intel_crtc(dev, crtc) {
17662 crtc_state = to_intel_crtc_state(crtc->base.state);
17663 put_domains = modeset_get_crtc_power_domains(crtc_state);
17664 if (WARN_ON(put_domains))
17665 modeset_put_power_domains(dev_priv, put_domains);
17668 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
17670 intel_fbc_init_pipe_state(dev_priv);
17673 void intel_display_resume(struct drm_device *dev)
17675 struct drm_i915_private *dev_priv = to_i915(dev);
17676 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
17677 struct drm_modeset_acquire_ctx ctx;
17680 dev_priv->modeset_restore_state = NULL;
17682 state->acquire_ctx = &ctx;
17684 drm_modeset_acquire_init(&ctx, 0);
17687 ret = drm_modeset_lock_all_ctx(dev, &ctx);
17688 if (ret != -EDEADLK)
17691 drm_modeset_backoff(&ctx);
17695 ret = __intel_display_resume(dev, state, &ctx);
17697 intel_enable_ipc(dev_priv);
17698 drm_modeset_drop_locks(&ctx);
17699 drm_modeset_acquire_fini(&ctx);
17702 DRM_ERROR("Restoring old state failed with %i\n", ret);
17704 drm_atomic_state_put(state);
17707 static void intel_hpd_poll_fini(struct drm_i915_private *i915)
17709 struct intel_connector *connector;
17710 struct drm_connector_list_iter conn_iter;
17712 /* Kill all the work that may have been queued by hpd. */
17713 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
17714 for_each_intel_connector_iter(connector, &conn_iter) {
17715 if (connector->modeset_retry_work.func)
17716 cancel_work_sync(&connector->modeset_retry_work);
17717 if (connector->hdcp.shim) {
17718 cancel_delayed_work_sync(&connector->hdcp.check_work);
17719 cancel_work_sync(&connector->hdcp.prop_work);
17722 drm_connector_list_iter_end(&conn_iter);
17725 void intel_modeset_driver_remove(struct drm_i915_private *i915)
17727 flush_workqueue(i915->flip_wq);
17728 flush_workqueue(i915->modeset_wq);
17730 flush_work(&i915->atomic_helper.free_work);
17731 WARN_ON(!llist_empty(&i915->atomic_helper.free_list));
17734 * Interrupts and polling as the first thing to avoid creating havoc.
17735 * Too much stuff here (turning of connectors, ...) would
17736 * experience fancy races otherwise.
17738 intel_irq_uninstall(i915);
17741 * Due to the hpd irq storm handling the hotplug work can re-arm the
17742 * poll handlers. Hence disable polling after hpd handling is shut down.
17744 intel_hpd_poll_fini(i915);
17746 /* poll work can call into fbdev, hence clean that up afterwards */
17747 intel_fbdev_fini(i915);
17749 intel_unregister_dsm_handler();
17751 intel_fbc_global_disable(i915);
17753 /* flush any delayed tasks or pending work */
17754 flush_scheduled_work();
17756 intel_hdcp_component_fini(i915);
17758 drm_mode_config_cleanup(&i915->drm);
17760 intel_overlay_cleanup(i915);
17762 intel_gmbus_teardown(i915);
17764 destroy_workqueue(i915->flip_wq);
17765 destroy_workqueue(i915->modeset_wq);
17767 intel_fbc_cleanup_cfb(i915);
17770 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
17772 struct intel_display_error_state {
17774 u32 power_well_driver;
17776 struct intel_cursor_error_state {
17781 } cursor[I915_MAX_PIPES];
17783 struct intel_pipe_error_state {
17784 bool power_domain_on;
17787 } pipe[I915_MAX_PIPES];
17789 struct intel_plane_error_state {
17797 } plane[I915_MAX_PIPES];
17799 struct intel_transcoder_error_state {
17801 bool power_domain_on;
17802 enum transcoder cpu_transcoder;
17815 struct intel_display_error_state *
17816 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
17818 struct intel_display_error_state *error;
17819 int transcoders[] = {
17828 BUILD_BUG_ON(ARRAY_SIZE(transcoders) != ARRAY_SIZE(error->transcoder));
17830 if (!HAS_DISPLAY(dev_priv) || !INTEL_DISPLAY_ENABLED(dev_priv))
17833 error = kzalloc(sizeof(*error), GFP_ATOMIC);
17837 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
17838 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
17840 for_each_pipe(dev_priv, i) {
17841 error->pipe[i].power_domain_on =
17842 __intel_display_power_is_enabled(dev_priv,
17843 POWER_DOMAIN_PIPE(i));
17844 if (!error->pipe[i].power_domain_on)
17847 error->cursor[i].control = I915_READ(CURCNTR(i));
17848 error->cursor[i].position = I915_READ(CURPOS(i));
17849 error->cursor[i].base = I915_READ(CURBASE(i));
17851 error->plane[i].control = I915_READ(DSPCNTR(i));
17852 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
17853 if (INTEL_GEN(dev_priv) <= 3) {
17854 error->plane[i].size = I915_READ(DSPSIZE(i));
17855 error->plane[i].pos = I915_READ(DSPPOS(i));
17857 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
17858 error->plane[i].addr = I915_READ(DSPADDR(i));
17859 if (INTEL_GEN(dev_priv) >= 4) {
17860 error->plane[i].surface = I915_READ(DSPSURF(i));
17861 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
17864 error->pipe[i].source = I915_READ(PIPESRC(i));
17866 if (HAS_GMCH(dev_priv))
17867 error->pipe[i].stat = I915_READ(PIPESTAT(i));
17870 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
17871 enum transcoder cpu_transcoder = transcoders[i];
17873 if (!INTEL_INFO(dev_priv)->trans_offsets[cpu_transcoder])
17876 error->transcoder[i].available = true;
17877 error->transcoder[i].power_domain_on =
17878 __intel_display_power_is_enabled(dev_priv,
17879 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
17880 if (!error->transcoder[i].power_domain_on)
17883 error->transcoder[i].cpu_transcoder = cpu_transcoder;
17885 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
17886 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
17887 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
17888 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
17889 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
17890 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
17891 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
17897 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
17900 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
17901 struct intel_display_error_state *error)
17903 struct drm_i915_private *dev_priv = m->i915;
17909 err_printf(m, "Num Pipes: %d\n", INTEL_NUM_PIPES(dev_priv));
17910 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
17911 err_printf(m, "PWR_WELL_CTL2: %08x\n",
17912 error->power_well_driver);
17913 for_each_pipe(dev_priv, i) {
17914 err_printf(m, "Pipe [%d]:\n", i);
17915 err_printf(m, " Power: %s\n",
17916 onoff(error->pipe[i].power_domain_on));
17917 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
17918 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
17920 err_printf(m, "Plane [%d]:\n", i);
17921 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
17922 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
17923 if (INTEL_GEN(dev_priv) <= 3) {
17924 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
17925 err_printf(m, " POS: %08x\n", error->plane[i].pos);
17927 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
17928 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
17929 if (INTEL_GEN(dev_priv) >= 4) {
17930 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
17931 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
17934 err_printf(m, "Cursor [%d]:\n", i);
17935 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
17936 err_printf(m, " POS: %08x\n", error->cursor[i].position);
17937 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
17940 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
17941 if (!error->transcoder[i].available)
17944 err_printf(m, "CPU transcoder: %s\n",
17945 transcoder_name(error->transcoder[i].cpu_transcoder));
17946 err_printf(m, " Power: %s\n",
17947 onoff(error->transcoder[i].power_domain_on));
17948 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
17949 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
17950 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
17951 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
17952 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
17953 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
17954 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);