2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
27 #include <linux/i2c.h>
28 #include <linux/input.h>
29 #include <linux/intel-iommu.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/dma-resv.h>
33 #include <linux/slab.h>
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_dp_mst.h"
50 #include "display/intel_dsi.h"
51 #include "display/intel_dvo.h"
52 #include "display/intel_gmbus.h"
53 #include "display/intel_hdmi.h"
54 #include "display/intel_lvds.h"
55 #include "display/intel_sdvo.h"
56 #include "display/intel_tv.h"
57 #include "display/intel_vdsc.h"
59 #include "gt/intel_rps.h"
62 #include "i915_trace.h"
63 #include "intel_acpi.h"
64 #include "intel_atomic.h"
65 #include "intel_atomic_plane.h"
67 #include "intel_cdclk.h"
68 #include "intel_color.h"
69 #include "intel_display_types.h"
70 #include "intel_dp_link_training.h"
71 #include "intel_fbc.h"
72 #include "intel_fbdev.h"
73 #include "intel_fifo_underrun.h"
74 #include "intel_frontbuffer.h"
75 #include "intel_hdcp.h"
76 #include "intel_hotplug.h"
77 #include "intel_overlay.h"
78 #include "intel_pipe_crc.h"
80 #include "intel_psr.h"
81 #include "intel_quirks.h"
82 #include "intel_sideband.h"
83 #include "intel_sprite.h"
85 #include "intel_vga.h"
87 /* Primary plane formats for gen <= 3 */
88 static const u32 i8xx_primary_formats
[] = {
95 /* Primary plane formats for ivb (no fp16 due to hw issue) */
96 static const u32 ivb_primary_formats
[] = {
101 DRM_FORMAT_XRGB2101010
,
102 DRM_FORMAT_XBGR2101010
,
105 /* Primary plane formats for gen >= 4, except ivb */
106 static const u32 i965_primary_formats
[] = {
111 DRM_FORMAT_XRGB2101010
,
112 DRM_FORMAT_XBGR2101010
,
113 DRM_FORMAT_XBGR16161616F
,
116 /* Primary plane formats for vlv/chv */
117 static const u32 vlv_primary_formats
[] = {
124 DRM_FORMAT_XRGB2101010
,
125 DRM_FORMAT_XBGR2101010
,
126 DRM_FORMAT_ARGB2101010
,
127 DRM_FORMAT_ABGR2101010
,
128 DRM_FORMAT_XBGR16161616F
,
131 static const u64 i9xx_format_modifiers
[] = {
132 I915_FORMAT_MOD_X_TILED
,
133 DRM_FORMAT_MOD_LINEAR
,
134 DRM_FORMAT_MOD_INVALID
138 static const u32 intel_cursor_formats
[] = {
142 static const u64 cursor_format_modifiers
[] = {
143 DRM_FORMAT_MOD_LINEAR
,
144 DRM_FORMAT_MOD_INVALID
147 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
148 struct intel_crtc_state
*pipe_config
);
149 static void ilk_pch_clock_get(struct intel_crtc
*crtc
,
150 struct intel_crtc_state
*pipe_config
);
152 static int intel_framebuffer_init(struct intel_framebuffer
*ifb
,
153 struct drm_i915_gem_object
*obj
,
154 struct drm_mode_fb_cmd2
*mode_cmd
);
155 static void intel_set_pipe_timings(const struct intel_crtc_state
*crtc_state
);
156 static void intel_set_pipe_src_size(const struct intel_crtc_state
*crtc_state
);
157 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state
*crtc_state
,
158 const struct intel_link_m_n
*m_n
,
159 const struct intel_link_m_n
*m2_n2
);
160 static void i9xx_set_pipeconf(const struct intel_crtc_state
*crtc_state
);
161 static void ilk_set_pipeconf(const struct intel_crtc_state
*crtc_state
);
162 static void hsw_set_pipeconf(const struct intel_crtc_state
*crtc_state
);
163 static void bdw_set_pipemisc(const struct intel_crtc_state
*crtc_state
);
164 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
165 const struct intel_crtc_state
*pipe_config
);
166 static void chv_prepare_pll(struct intel_crtc
*crtc
,
167 const struct intel_crtc_state
*pipe_config
);
168 static void skl_pfit_enable(const struct intel_crtc_state
*crtc_state
);
169 static void ilk_pfit_enable(const struct intel_crtc_state
*crtc_state
);
170 static void intel_modeset_setup_hw_state(struct drm_device
*dev
,
171 struct drm_modeset_acquire_ctx
*ctx
);
172 static struct intel_crtc_state
*intel_crtc_state_alloc(struct intel_crtc
*crtc
);
177 } dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
181 int p2_slow
, p2_fast
;
185 /* returns HPLL frequency in kHz */
186 int vlv_get_hpll_vco(struct drm_i915_private
*dev_priv
)
188 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
190 /* Obtain SKU information */
191 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
192 CCK_FUSE_HPLL_FREQ_MASK
;
194 return vco_freq
[hpll_freq
] * 1000;
197 int vlv_get_cck_clock(struct drm_i915_private
*dev_priv
,
198 const char *name
, u32 reg
, int ref_freq
)
203 val
= vlv_cck_read(dev_priv
, reg
);
204 divider
= val
& CCK_FREQUENCY_VALUES
;
206 WARN((val
& CCK_FREQUENCY_STATUS
) !=
207 (divider
<< CCK_FREQUENCY_STATUS_SHIFT
),
208 "%s change in progress\n", name
);
210 return DIV_ROUND_CLOSEST(ref_freq
<< 1, divider
+ 1);
213 int vlv_get_cck_clock_hpll(struct drm_i915_private
*dev_priv
,
214 const char *name
, u32 reg
)
218 vlv_cck_get(dev_priv
);
220 if (dev_priv
->hpll_freq
== 0)
221 dev_priv
->hpll_freq
= vlv_get_hpll_vco(dev_priv
);
223 hpll
= vlv_get_cck_clock(dev_priv
, name
, reg
, dev_priv
->hpll_freq
);
225 vlv_cck_put(dev_priv
);
230 static void intel_update_czclk(struct drm_i915_private
*dev_priv
)
232 if (!(IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)))
235 dev_priv
->czclk_freq
= vlv_get_cck_clock_hpll(dev_priv
, "czclk",
236 CCK_CZ_CLOCK_CONTROL
);
238 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv
->czclk_freq
);
241 static inline u32
/* units of 100MHz */
242 intel_fdi_link_freq(struct drm_i915_private
*dev_priv
,
243 const struct intel_crtc_state
*pipe_config
)
245 if (HAS_DDI(dev_priv
))
246 return pipe_config
->port_clock
; /* SPLL */
248 return dev_priv
->fdi_pll_freq
;
251 static const struct intel_limit intel_limits_i8xx_dac
= {
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
= 2 },
264 static const struct intel_limit intel_limits_i8xx_dvo
= {
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
= 2, .max
= 33 },
273 .p2
= { .dot_limit
= 165000,
274 .p2_slow
= 4, .p2_fast
= 4 },
277 static const struct intel_limit intel_limits_i8xx_lvds
= {
278 .dot
= { .min
= 25000, .max
= 350000 },
279 .vco
= { .min
= 908000, .max
= 1512000 },
280 .n
= { .min
= 2, .max
= 16 },
281 .m
= { .min
= 96, .max
= 140 },
282 .m1
= { .min
= 18, .max
= 26 },
283 .m2
= { .min
= 6, .max
= 16 },
284 .p
= { .min
= 4, .max
= 128 },
285 .p1
= { .min
= 1, .max
= 6 },
286 .p2
= { .dot_limit
= 165000,
287 .p2_slow
= 14, .p2_fast
= 7 },
290 static const struct intel_limit intel_limits_i9xx_sdvo
= {
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
= 5, .max
= 80 },
298 .p1
= { .min
= 1, .max
= 8 },
299 .p2
= { .dot_limit
= 200000,
300 .p2_slow
= 10, .p2_fast
= 5 },
303 static const struct intel_limit intel_limits_i9xx_lvds
= {
304 .dot
= { .min
= 20000, .max
= 400000 },
305 .vco
= { .min
= 1400000, .max
= 2800000 },
306 .n
= { .min
= 1, .max
= 6 },
307 .m
= { .min
= 70, .max
= 120 },
308 .m1
= { .min
= 8, .max
= 18 },
309 .m2
= { .min
= 3, .max
= 7 },
310 .p
= { .min
= 7, .max
= 98 },
311 .p1
= { .min
= 1, .max
= 8 },
312 .p2
= { .dot_limit
= 112000,
313 .p2_slow
= 14, .p2_fast
= 7 },
317 static const struct intel_limit intel_limits_g4x_sdvo
= {
318 .dot
= { .min
= 25000, .max
= 270000 },
319 .vco
= { .min
= 1750000, .max
= 3500000},
320 .n
= { .min
= 1, .max
= 4 },
321 .m
= { .min
= 104, .max
= 138 },
322 .m1
= { .min
= 17, .max
= 23 },
323 .m2
= { .min
= 5, .max
= 11 },
324 .p
= { .min
= 10, .max
= 30 },
325 .p1
= { .min
= 1, .max
= 3},
326 .p2
= { .dot_limit
= 270000,
332 static const struct intel_limit intel_limits_g4x_hdmi
= {
333 .dot
= { .min
= 22000, .max
= 400000 },
334 .vco
= { .min
= 1750000, .max
= 3500000},
335 .n
= { .min
= 1, .max
= 4 },
336 .m
= { .min
= 104, .max
= 138 },
337 .m1
= { .min
= 16, .max
= 23 },
338 .m2
= { .min
= 5, .max
= 11 },
339 .p
= { .min
= 5, .max
= 80 },
340 .p1
= { .min
= 1, .max
= 8},
341 .p2
= { .dot_limit
= 165000,
342 .p2_slow
= 10, .p2_fast
= 5 },
345 static const struct intel_limit intel_limits_g4x_single_channel_lvds
= {
346 .dot
= { .min
= 20000, .max
= 115000 },
347 .vco
= { .min
= 1750000, .max
= 3500000 },
348 .n
= { .min
= 1, .max
= 3 },
349 .m
= { .min
= 104, .max
= 138 },
350 .m1
= { .min
= 17, .max
= 23 },
351 .m2
= { .min
= 5, .max
= 11 },
352 .p
= { .min
= 28, .max
= 112 },
353 .p1
= { .min
= 2, .max
= 8 },
354 .p2
= { .dot_limit
= 0,
355 .p2_slow
= 14, .p2_fast
= 14
359 static const struct intel_limit intel_limits_g4x_dual_channel_lvds
= {
360 .dot
= { .min
= 80000, .max
= 224000 },
361 .vco
= { .min
= 1750000, .max
= 3500000 },
362 .n
= { .min
= 1, .max
= 3 },
363 .m
= { .min
= 104, .max
= 138 },
364 .m1
= { .min
= 17, .max
= 23 },
365 .m2
= { .min
= 5, .max
= 11 },
366 .p
= { .min
= 14, .max
= 42 },
367 .p1
= { .min
= 2, .max
= 6 },
368 .p2
= { .dot_limit
= 0,
369 .p2_slow
= 7, .p2_fast
= 7
373 static const struct intel_limit pnv_limits_sdvo
= {
374 .dot
= { .min
= 20000, .max
= 400000},
375 .vco
= { .min
= 1700000, .max
= 3500000 },
376 /* Pineview's Ncounter is a ring counter */
377 .n
= { .min
= 3, .max
= 6 },
378 .m
= { .min
= 2, .max
= 256 },
379 /* Pineview only has one combined m divider, which we treat as m2. */
380 .m1
= { .min
= 0, .max
= 0 },
381 .m2
= { .min
= 0, .max
= 254 },
382 .p
= { .min
= 5, .max
= 80 },
383 .p1
= { .min
= 1, .max
= 8 },
384 .p2
= { .dot_limit
= 200000,
385 .p2_slow
= 10, .p2_fast
= 5 },
388 static const struct intel_limit pnv_limits_lvds
= {
389 .dot
= { .min
= 20000, .max
= 400000 },
390 .vco
= { .min
= 1700000, .max
= 3500000 },
391 .n
= { .min
= 3, .max
= 6 },
392 .m
= { .min
= 2, .max
= 256 },
393 .m1
= { .min
= 0, .max
= 0 },
394 .m2
= { .min
= 0, .max
= 254 },
395 .p
= { .min
= 7, .max
= 112 },
396 .p1
= { .min
= 1, .max
= 8 },
397 .p2
= { .dot_limit
= 112000,
398 .p2_slow
= 14, .p2_fast
= 14 },
401 /* Ironlake / Sandybridge
403 * We calculate clock using (register_value + 2) for N/M1/M2, so here
404 * the range value for them is (actual_value - 2).
406 static const struct intel_limit ilk_limits_dac
= {
407 .dot
= { .min
= 25000, .max
= 350000 },
408 .vco
= { .min
= 1760000, .max
= 3510000 },
409 .n
= { .min
= 1, .max
= 5 },
410 .m
= { .min
= 79, .max
= 127 },
411 .m1
= { .min
= 12, .max
= 22 },
412 .m2
= { .min
= 5, .max
= 9 },
413 .p
= { .min
= 5, .max
= 80 },
414 .p1
= { .min
= 1, .max
= 8 },
415 .p2
= { .dot_limit
= 225000,
416 .p2_slow
= 10, .p2_fast
= 5 },
419 static const struct intel_limit ilk_limits_single_lvds
= {
420 .dot
= { .min
= 25000, .max
= 350000 },
421 .vco
= { .min
= 1760000, .max
= 3510000 },
422 .n
= { .min
= 1, .max
= 3 },
423 .m
= { .min
= 79, .max
= 118 },
424 .m1
= { .min
= 12, .max
= 22 },
425 .m2
= { .min
= 5, .max
= 9 },
426 .p
= { .min
= 28, .max
= 112 },
427 .p1
= { .min
= 2, .max
= 8 },
428 .p2
= { .dot_limit
= 225000,
429 .p2_slow
= 14, .p2_fast
= 14 },
432 static const struct intel_limit ilk_limits_dual_lvds
= {
433 .dot
= { .min
= 25000, .max
= 350000 },
434 .vco
= { .min
= 1760000, .max
= 3510000 },
435 .n
= { .min
= 1, .max
= 3 },
436 .m
= { .min
= 79, .max
= 127 },
437 .m1
= { .min
= 12, .max
= 22 },
438 .m2
= { .min
= 5, .max
= 9 },
439 .p
= { .min
= 14, .max
= 56 },
440 .p1
= { .min
= 2, .max
= 8 },
441 .p2
= { .dot_limit
= 225000,
442 .p2_slow
= 7, .p2_fast
= 7 },
445 /* LVDS 100mhz refclk limits. */
446 static const struct intel_limit ilk_limits_single_lvds_100m
= {
447 .dot
= { .min
= 25000, .max
= 350000 },
448 .vco
= { .min
= 1760000, .max
= 3510000 },
449 .n
= { .min
= 1, .max
= 2 },
450 .m
= { .min
= 79, .max
= 126 },
451 .m1
= { .min
= 12, .max
= 22 },
452 .m2
= { .min
= 5, .max
= 9 },
453 .p
= { .min
= 28, .max
= 112 },
454 .p1
= { .min
= 2, .max
= 8 },
455 .p2
= { .dot_limit
= 225000,
456 .p2_slow
= 14, .p2_fast
= 14 },
459 static const struct intel_limit ilk_limits_dual_lvds_100m
= {
460 .dot
= { .min
= 25000, .max
= 350000 },
461 .vco
= { .min
= 1760000, .max
= 3510000 },
462 .n
= { .min
= 1, .max
= 3 },
463 .m
= { .min
= 79, .max
= 126 },
464 .m1
= { .min
= 12, .max
= 22 },
465 .m2
= { .min
= 5, .max
= 9 },
466 .p
= { .min
= 14, .max
= 42 },
467 .p1
= { .min
= 2, .max
= 6 },
468 .p2
= { .dot_limit
= 225000,
469 .p2_slow
= 7, .p2_fast
= 7 },
472 static const struct intel_limit intel_limits_vlv
= {
474 * These are the data rate limits (measured in fast clocks)
475 * since those are the strictest limits we have. The fast
476 * clock and actual rate limits are more relaxed, so checking
477 * them would make no difference.
479 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
480 .vco
= { .min
= 4000000, .max
= 6000000 },
481 .n
= { .min
= 1, .max
= 7 },
482 .m1
= { .min
= 2, .max
= 3 },
483 .m2
= { .min
= 11, .max
= 156 },
484 .p1
= { .min
= 2, .max
= 3 },
485 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
488 static const struct intel_limit intel_limits_chv
= {
490 * These are the data rate limits (measured in fast clocks)
491 * since those are the strictest limits we have. The fast
492 * clock and actual rate limits are more relaxed, so checking
493 * them would make no difference.
495 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
496 .vco
= { .min
= 4800000, .max
= 6480000 },
497 .n
= { .min
= 1, .max
= 1 },
498 .m1
= { .min
= 2, .max
= 2 },
499 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
500 .p1
= { .min
= 2, .max
= 4 },
501 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
504 static const struct intel_limit intel_limits_bxt
= {
505 /* FIXME: find real dot limits */
506 .dot
= { .min
= 0, .max
= INT_MAX
},
507 .vco
= { .min
= 4800000, .max
= 6700000 },
508 .n
= { .min
= 1, .max
= 1 },
509 .m1
= { .min
= 2, .max
= 2 },
510 /* FIXME: find real m2 limits */
511 .m2
= { .min
= 2 << 22, .max
= 255 << 22 },
512 .p1
= { .min
= 2, .max
= 4 },
513 .p2
= { .p2_slow
= 1, .p2_fast
= 20 },
516 /* WA Display #0827: Gen9:all */
518 skl_wa_827(struct drm_i915_private
*dev_priv
, enum pipe pipe
, bool enable
)
521 I915_WRITE(CLKGATE_DIS_PSL(pipe
),
522 I915_READ(CLKGATE_DIS_PSL(pipe
)) |
523 DUPS1_GATING_DIS
| DUPS2_GATING_DIS
);
525 I915_WRITE(CLKGATE_DIS_PSL(pipe
),
526 I915_READ(CLKGATE_DIS_PSL(pipe
)) &
527 ~(DUPS1_GATING_DIS
| DUPS2_GATING_DIS
));
530 /* Wa_2006604312:icl */
532 icl_wa_scalerclkgating(struct drm_i915_private
*dev_priv
, enum pipe pipe
,
536 I915_WRITE(CLKGATE_DIS_PSL(pipe
),
537 I915_READ(CLKGATE_DIS_PSL(pipe
)) | DPFR_GATING_DIS
);
539 I915_WRITE(CLKGATE_DIS_PSL(pipe
),
540 I915_READ(CLKGATE_DIS_PSL(pipe
)) & ~DPFR_GATING_DIS
);
544 needs_modeset(const struct intel_crtc_state
*state
)
546 return drm_atomic_crtc_needs_modeset(&state
->uapi
);
550 is_trans_port_sync_mode(const struct intel_crtc_state
*crtc_state
)
552 return (crtc_state
->master_transcoder
!= INVALID_TRANSCODER
||
553 crtc_state
->sync_mode_slaves_mask
);
557 is_trans_port_sync_slave(const struct intel_crtc_state
*crtc_state
)
559 return crtc_state
->master_transcoder
!= INVALID_TRANSCODER
;
563 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
564 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
565 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
566 * The helpers' return value is the rate of the clock that is fed to the
567 * display engine's pipe which can be the above fast dot clock rate or a
568 * divided-down version of it.
570 /* m1 is reserved as 0 in Pineview, n is a ring counter */
571 static int pnv_calc_dpll_params(int refclk
, struct dpll
*clock
)
573 clock
->m
= clock
->m2
+ 2;
574 clock
->p
= clock
->p1
* clock
->p2
;
575 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
577 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
578 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
583 static u32
i9xx_dpll_compute_m(struct dpll
*dpll
)
585 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
588 static int i9xx_calc_dpll_params(int refclk
, struct dpll
*clock
)
590 clock
->m
= i9xx_dpll_compute_m(clock
);
591 clock
->p
= clock
->p1
* clock
->p2
;
592 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
594 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
595 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
600 static int vlv_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(refclk
* clock
->m
, clock
->n
);
607 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
609 return clock
->dot
/ 5;
612 int chv_calc_dpll_params(int refclk
, struct dpll
*clock
)
614 clock
->m
= clock
->m1
* clock
->m2
;
615 clock
->p
= clock
->p1
* clock
->p2
;
616 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
618 clock
->vco
= DIV_ROUND_CLOSEST_ULL(mul_u32_u32(refclk
, clock
->m
),
620 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
622 return clock
->dot
/ 5;
625 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
628 * Returns whether the given set of divisors are valid for a given refclk with
629 * the given connectors.
631 static bool intel_PLL_is_valid(struct drm_i915_private
*dev_priv
,
632 const struct intel_limit
*limit
,
633 const struct dpll
*clock
)
635 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
636 INTELPllInvalid("n out of range\n");
637 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
638 INTELPllInvalid("p1 out of range\n");
639 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
640 INTELPllInvalid("m2 out of range\n");
641 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
642 INTELPllInvalid("m1 out of range\n");
644 if (!IS_PINEVIEW(dev_priv
) && !IS_VALLEYVIEW(dev_priv
) &&
645 !IS_CHERRYVIEW(dev_priv
) && !IS_GEN9_LP(dev_priv
))
646 if (clock
->m1
<= clock
->m2
)
647 INTELPllInvalid("m1 <= m2\n");
649 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
) &&
650 !IS_GEN9_LP(dev_priv
)) {
651 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
652 INTELPllInvalid("p out of range\n");
653 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
654 INTELPllInvalid("m out of range\n");
657 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
658 INTELPllInvalid("vco out of range\n");
659 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
660 * connector, etc., rather than just a single range.
662 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
663 INTELPllInvalid("dot out of range\n");
669 i9xx_select_p2_div(const struct intel_limit
*limit
,
670 const struct intel_crtc_state
*crtc_state
,
673 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->uapi
.crtc
->dev
);
675 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
677 * For LVDS just rely on its current settings for dual-channel.
678 * We haven't figured out how to reliably set up different
679 * single/dual channel state, if we even can.
681 if (intel_is_dual_link_lvds(dev_priv
))
682 return limit
->p2
.p2_fast
;
684 return limit
->p2
.p2_slow
;
686 if (target
< limit
->p2
.dot_limit
)
687 return limit
->p2
.p2_slow
;
689 return limit
->p2
.p2_fast
;
694 * Returns a set of divisors for the desired target clock with the given
695 * refclk, or FALSE. The returned values represent the clock equation:
696 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
698 * Target and reference clocks are specified in kHz.
700 * If match_clock is provided, then best_clock P divider must match the P
701 * divider from @match_clock used for LVDS downclocking.
704 i9xx_find_best_dpll(const struct intel_limit
*limit
,
705 struct intel_crtc_state
*crtc_state
,
706 int target
, int refclk
, struct dpll
*match_clock
,
707 struct dpll
*best_clock
)
709 struct drm_device
*dev
= crtc_state
->uapi
.crtc
->dev
;
713 memset(best_clock
, 0, sizeof(*best_clock
));
715 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
717 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
719 for (clock
.m2
= limit
->m2
.min
;
720 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
721 if (clock
.m2
>= clock
.m1
)
723 for (clock
.n
= limit
->n
.min
;
724 clock
.n
<= limit
->n
.max
; clock
.n
++) {
725 for (clock
.p1
= limit
->p1
.min
;
726 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
729 i9xx_calc_dpll_params(refclk
, &clock
);
730 if (!intel_PLL_is_valid(to_i915(dev
),
735 clock
.p
!= match_clock
->p
)
738 this_err
= abs(clock
.dot
- target
);
739 if (this_err
< err
) {
748 return (err
!= target
);
752 * Returns a set of divisors for the desired target clock with the given
753 * refclk, or FALSE. The returned values represent the clock equation:
754 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
756 * Target and reference clocks are specified in kHz.
758 * If match_clock is provided, then best_clock P divider must match the P
759 * divider from @match_clock used for LVDS downclocking.
762 pnv_find_best_dpll(const struct intel_limit
*limit
,
763 struct intel_crtc_state
*crtc_state
,
764 int target
, int refclk
, struct dpll
*match_clock
,
765 struct dpll
*best_clock
)
767 struct drm_device
*dev
= crtc_state
->uapi
.crtc
->dev
;
771 memset(best_clock
, 0, sizeof(*best_clock
));
773 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
775 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
777 for (clock
.m2
= limit
->m2
.min
;
778 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
779 for (clock
.n
= limit
->n
.min
;
780 clock
.n
<= limit
->n
.max
; clock
.n
++) {
781 for (clock
.p1
= limit
->p1
.min
;
782 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
785 pnv_calc_dpll_params(refclk
, &clock
);
786 if (!intel_PLL_is_valid(to_i915(dev
),
791 clock
.p
!= match_clock
->p
)
794 this_err
= abs(clock
.dot
- target
);
795 if (this_err
< err
) {
804 return (err
!= target
);
808 * Returns a set of divisors for the desired target clock with the given
809 * refclk, or FALSE. The returned values represent the clock equation:
810 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
812 * Target and reference clocks are specified in kHz.
814 * If match_clock is provided, then best_clock P divider must match the P
815 * divider from @match_clock used for LVDS downclocking.
818 g4x_find_best_dpll(const struct intel_limit
*limit
,
819 struct intel_crtc_state
*crtc_state
,
820 int target
, int refclk
, struct dpll
*match_clock
,
821 struct dpll
*best_clock
)
823 struct drm_device
*dev
= crtc_state
->uapi
.crtc
->dev
;
827 /* approximately equals target * 0.00585 */
828 int err_most
= (target
>> 8) + (target
>> 9);
830 memset(best_clock
, 0, sizeof(*best_clock
));
832 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
834 max_n
= limit
->n
.max
;
835 /* based on hardware requirement, prefer smaller n to precision */
836 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
837 /* based on hardware requirement, prefere larger m1,m2 */
838 for (clock
.m1
= limit
->m1
.max
;
839 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
840 for (clock
.m2
= limit
->m2
.max
;
841 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
842 for (clock
.p1
= limit
->p1
.max
;
843 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
846 i9xx_calc_dpll_params(refclk
, &clock
);
847 if (!intel_PLL_is_valid(to_i915(dev
),
852 this_err
= abs(clock
.dot
- target
);
853 if (this_err
< err_most
) {
867 * Check if the calculated PLL configuration is more optimal compared to the
868 * best configuration and error found so far. Return the calculated error.
870 static bool vlv_PLL_is_optimal(struct drm_device
*dev
, int target_freq
,
871 const struct dpll
*calculated_clock
,
872 const struct dpll
*best_clock
,
873 unsigned int best_error_ppm
,
874 unsigned int *error_ppm
)
877 * For CHV ignore the error and consider only the P value.
878 * Prefer a bigger P value based on HW requirements.
880 if (IS_CHERRYVIEW(to_i915(dev
))) {
883 return calculated_clock
->p
> best_clock
->p
;
886 if (WARN_ON_ONCE(!target_freq
))
889 *error_ppm
= div_u64(1000000ULL *
890 abs(target_freq
- calculated_clock
->dot
),
893 * Prefer a better P value over a better (smaller) error if the error
894 * is small. Ensure this preference for future configurations too by
895 * setting the error to 0.
897 if (*error_ppm
< 100 && calculated_clock
->p
> best_clock
->p
) {
903 return *error_ppm
+ 10 < best_error_ppm
;
907 * Returns a set of divisors for the desired target clock with the given
908 * refclk, or FALSE. The returned values represent the clock equation:
909 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
912 vlv_find_best_dpll(const struct intel_limit
*limit
,
913 struct intel_crtc_state
*crtc_state
,
914 int target
, int refclk
, struct dpll
*match_clock
,
915 struct dpll
*best_clock
)
917 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
918 struct drm_device
*dev
= crtc
->base
.dev
;
920 unsigned int bestppm
= 1000000;
921 /* min update 19.2 MHz */
922 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
925 target
*= 5; /* fast clock */
927 memset(best_clock
, 0, sizeof(*best_clock
));
929 /* based on hardware requirement, prefer smaller n to precision */
930 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
931 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
932 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
933 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
934 clock
.p
= clock
.p1
* clock
.p2
;
935 /* based on hardware requirement, prefer bigger m1,m2 values */
936 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
939 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
942 vlv_calc_dpll_params(refclk
, &clock
);
944 if (!intel_PLL_is_valid(to_i915(dev
),
949 if (!vlv_PLL_is_optimal(dev
, target
,
967 * Returns a set of divisors for the desired target clock with the given
968 * refclk, or FALSE. The returned values represent the clock equation:
969 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
972 chv_find_best_dpll(const struct intel_limit
*limit
,
973 struct intel_crtc_state
*crtc_state
,
974 int target
, int refclk
, struct dpll
*match_clock
,
975 struct dpll
*best_clock
)
977 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
978 struct drm_device
*dev
= crtc
->base
.dev
;
979 unsigned int best_error_ppm
;
984 memset(best_clock
, 0, sizeof(*best_clock
));
985 best_error_ppm
= 1000000;
988 * Based on hardware doc, the n always set to 1, and m1 always
989 * set to 2. If requires to support 200Mhz refclk, we need to
990 * revisit this because n may not 1 anymore.
992 clock
.n
= 1, clock
.m1
= 2;
993 target
*= 5; /* fast clock */
995 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
996 for (clock
.p2
= limit
->p2
.p2_fast
;
997 clock
.p2
>= limit
->p2
.p2_slow
;
998 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
999 unsigned int error_ppm
;
1001 clock
.p
= clock
.p1
* clock
.p2
;
1003 m2
= DIV_ROUND_CLOSEST_ULL(mul_u32_u32(target
, clock
.p
* clock
.n
) << 22,
1006 if (m2
> INT_MAX
/clock
.m1
)
1011 chv_calc_dpll_params(refclk
, &clock
);
1013 if (!intel_PLL_is_valid(to_i915(dev
), limit
, &clock
))
1016 if (!vlv_PLL_is_optimal(dev
, target
, &clock
, best_clock
,
1017 best_error_ppm
, &error_ppm
))
1020 *best_clock
= clock
;
1021 best_error_ppm
= error_ppm
;
1029 bool bxt_find_best_dpll(struct intel_crtc_state
*crtc_state
,
1030 struct dpll
*best_clock
)
1032 int refclk
= 100000;
1033 const struct intel_limit
*limit
= &intel_limits_bxt
;
1035 return chv_find_best_dpll(limit
, crtc_state
,
1036 crtc_state
->port_clock
, refclk
,
1040 static bool pipe_scanline_is_moving(struct drm_i915_private
*dev_priv
,
1043 i915_reg_t reg
= PIPEDSL(pipe
);
1047 if (IS_GEN(dev_priv
, 2))
1048 line_mask
= DSL_LINEMASK_GEN2
;
1050 line_mask
= DSL_LINEMASK_GEN3
;
1052 line1
= I915_READ(reg
) & line_mask
;
1054 line2
= I915_READ(reg
) & line_mask
;
1056 return line1
!= line2
;
1059 static void wait_for_pipe_scanline_moving(struct intel_crtc
*crtc
, bool state
)
1061 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1062 enum pipe pipe
= crtc
->pipe
;
1064 /* Wait for the display line to settle/start moving */
1065 if (wait_for(pipe_scanline_is_moving(dev_priv
, pipe
) == state
, 100))
1066 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1067 pipe_name(pipe
), onoff(state
));
1070 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc
*crtc
)
1072 wait_for_pipe_scanline_moving(crtc
, false);
1075 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc
*crtc
)
1077 wait_for_pipe_scanline_moving(crtc
, true);
1081 intel_wait_for_pipe_off(const struct intel_crtc_state
*old_crtc_state
)
1083 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->uapi
.crtc
);
1084 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1086 if (INTEL_GEN(dev_priv
) >= 4) {
1087 enum transcoder cpu_transcoder
= old_crtc_state
->cpu_transcoder
;
1088 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
1090 /* Wait for the Pipe State to go off */
1091 if (intel_de_wait_for_clear(dev_priv
, reg
,
1092 I965_PIPECONF_ACTIVE
, 100))
1093 WARN(1, "pipe_off wait timed out\n");
1095 intel_wait_for_pipe_scanline_stopped(crtc
);
1099 /* Only for pre-ILK configs */
1100 void assert_pll(struct drm_i915_private
*dev_priv
,
1101 enum pipe pipe
, bool state
)
1106 val
= I915_READ(DPLL(pipe
));
1107 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1108 I915_STATE_WARN(cur_state
!= state
,
1109 "PLL state assertion failure (expected %s, current %s)\n",
1110 onoff(state
), onoff(cur_state
));
1113 /* XXX: the dsi pll is shared between MIPI DSI ports */
1114 void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1119 vlv_cck_get(dev_priv
);
1120 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1121 vlv_cck_put(dev_priv
);
1123 cur_state
= val
& DSI_PLL_VCO_EN
;
1124 I915_STATE_WARN(cur_state
!= state
,
1125 "DSI PLL state assertion failure (expected %s, current %s)\n",
1126 onoff(state
), onoff(cur_state
));
1129 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1130 enum pipe pipe
, bool state
)
1134 if (HAS_DDI(dev_priv
)) {
1136 * DDI does not have a specific FDI_TX register.
1138 * FDI is never fed from EDP transcoder
1139 * so pipe->transcoder cast is fine here.
1141 enum transcoder cpu_transcoder
= (enum transcoder
)pipe
;
1142 u32 val
= I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder
));
1143 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1145 u32 val
= I915_READ(FDI_TX_CTL(pipe
));
1146 cur_state
= !!(val
& FDI_TX_ENABLE
);
1148 I915_STATE_WARN(cur_state
!= state
,
1149 "FDI TX state assertion failure (expected %s, current %s)\n",
1150 onoff(state
), onoff(cur_state
));
1152 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1153 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1155 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1156 enum pipe pipe
, bool state
)
1161 val
= I915_READ(FDI_RX_CTL(pipe
));
1162 cur_state
= !!(val
& FDI_RX_ENABLE
);
1163 I915_STATE_WARN(cur_state
!= state
,
1164 "FDI RX state assertion failure (expected %s, current %s)\n",
1165 onoff(state
), onoff(cur_state
));
1167 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1168 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1170 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1175 /* ILK FDI PLL is always enabled */
1176 if (IS_GEN(dev_priv
, 5))
1179 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1180 if (HAS_DDI(dev_priv
))
1183 val
= I915_READ(FDI_TX_CTL(pipe
));
1184 I915_STATE_WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1187 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1188 enum pipe pipe
, bool state
)
1193 val
= I915_READ(FDI_RX_CTL(pipe
));
1194 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1195 I915_STATE_WARN(cur_state
!= state
,
1196 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1197 onoff(state
), onoff(cur_state
));
1200 void assert_panel_unlocked(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1204 enum pipe panel_pipe
= INVALID_PIPE
;
1207 if (WARN_ON(HAS_DDI(dev_priv
)))
1210 if (HAS_PCH_SPLIT(dev_priv
)) {
1213 pp_reg
= PP_CONTROL(0);
1214 port_sel
= I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK
;
1217 case PANEL_PORT_SELECT_LVDS
:
1218 intel_lvds_port_enabled(dev_priv
, PCH_LVDS
, &panel_pipe
);
1220 case PANEL_PORT_SELECT_DPA
:
1221 intel_dp_port_enabled(dev_priv
, DP_A
, PORT_A
, &panel_pipe
);
1223 case PANEL_PORT_SELECT_DPC
:
1224 intel_dp_port_enabled(dev_priv
, PCH_DP_C
, PORT_C
, &panel_pipe
);
1226 case PANEL_PORT_SELECT_DPD
:
1227 intel_dp_port_enabled(dev_priv
, PCH_DP_D
, PORT_D
, &panel_pipe
);
1230 MISSING_CASE(port_sel
);
1233 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
1234 /* presumably write lock depends on pipe, not port select */
1235 pp_reg
= PP_CONTROL(pipe
);
1240 pp_reg
= PP_CONTROL(0);
1241 port_sel
= I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK
;
1243 WARN_ON(port_sel
!= PANEL_PORT_SELECT_LVDS
);
1244 intel_lvds_port_enabled(dev_priv
, LVDS
, &panel_pipe
);
1247 val
= I915_READ(pp_reg
);
1248 if (!(val
& PANEL_POWER_ON
) ||
1249 ((val
& PANEL_UNLOCK_MASK
) == PANEL_UNLOCK_REGS
))
1252 I915_STATE_WARN(panel_pipe
== pipe
&& locked
,
1253 "panel assertion failure, pipe %c regs locked\n",
1257 void assert_pipe(struct drm_i915_private
*dev_priv
,
1258 enum transcoder cpu_transcoder
, bool state
)
1261 enum intel_display_power_domain power_domain
;
1262 intel_wakeref_t wakeref
;
1264 /* we keep both pipes enabled on 830 */
1265 if (IS_I830(dev_priv
))
1268 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
1269 wakeref
= intel_display_power_get_if_enabled(dev_priv
, power_domain
);
1271 u32 val
= I915_READ(PIPECONF(cpu_transcoder
));
1272 cur_state
= !!(val
& PIPECONF_ENABLE
);
1274 intel_display_power_put(dev_priv
, power_domain
, wakeref
);
1279 I915_STATE_WARN(cur_state
!= state
,
1280 "transcoder %s assertion failure (expected %s, current %s)\n",
1281 transcoder_name(cpu_transcoder
),
1282 onoff(state
), onoff(cur_state
));
1285 static void assert_plane(struct intel_plane
*plane
, bool state
)
1290 cur_state
= plane
->get_hw_state(plane
, &pipe
);
1292 I915_STATE_WARN(cur_state
!= state
,
1293 "%s assertion failure (expected %s, current %s)\n",
1294 plane
->base
.name
, onoff(state
), onoff(cur_state
));
1297 #define assert_plane_enabled(p) assert_plane(p, true)
1298 #define assert_plane_disabled(p) assert_plane(p, false)
1300 static void assert_planes_disabled(struct intel_crtc
*crtc
)
1302 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1303 struct intel_plane
*plane
;
1305 for_each_intel_plane_on_crtc(&dev_priv
->drm
, crtc
, plane
)
1306 assert_plane_disabled(plane
);
1309 static void assert_vblank_disabled(struct drm_crtc
*crtc
)
1311 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc
) == 0))
1312 drm_crtc_vblank_put(crtc
);
1315 void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1321 val
= I915_READ(PCH_TRANSCONF(pipe
));
1322 enabled
= !!(val
& TRANS_ENABLE
);
1323 I915_STATE_WARN(enabled
,
1324 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1328 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1329 enum pipe pipe
, enum port port
,
1332 enum pipe port_pipe
;
1335 state
= intel_dp_port_enabled(dev_priv
, dp_reg
, port
, &port_pipe
);
1337 I915_STATE_WARN(state
&& port_pipe
== pipe
,
1338 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1339 port_name(port
), pipe_name(pipe
));
1341 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
) && !state
&& port_pipe
== PIPE_B
,
1342 "IBX PCH DP %c still using transcoder B\n",
1346 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1347 enum pipe pipe
, enum port port
,
1348 i915_reg_t hdmi_reg
)
1350 enum pipe port_pipe
;
1353 state
= intel_sdvo_port_enabled(dev_priv
, hdmi_reg
, &port_pipe
);
1355 I915_STATE_WARN(state
&& port_pipe
== pipe
,
1356 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1357 port_name(port
), pipe_name(pipe
));
1359 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
) && !state
&& port_pipe
== PIPE_B
,
1360 "IBX PCH HDMI %c still using transcoder B\n",
1364 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1367 enum pipe port_pipe
;
1369 assert_pch_dp_disabled(dev_priv
, pipe
, PORT_B
, PCH_DP_B
);
1370 assert_pch_dp_disabled(dev_priv
, pipe
, PORT_C
, PCH_DP_C
);
1371 assert_pch_dp_disabled(dev_priv
, pipe
, PORT_D
, PCH_DP_D
);
1373 I915_STATE_WARN(intel_crt_port_enabled(dev_priv
, PCH_ADPA
, &port_pipe
) &&
1375 "PCH VGA enabled on transcoder %c, should be disabled\n",
1378 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv
, PCH_LVDS
, &port_pipe
) &&
1380 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1383 /* PCH SDVOB multiplex with HDMIB */
1384 assert_pch_hdmi_disabled(dev_priv
, pipe
, PORT_B
, PCH_HDMIB
);
1385 assert_pch_hdmi_disabled(dev_priv
, pipe
, PORT_C
, PCH_HDMIC
);
1386 assert_pch_hdmi_disabled(dev_priv
, pipe
, PORT_D
, PCH_HDMID
);
1389 static void _vlv_enable_pll(struct intel_crtc
*crtc
,
1390 const struct intel_crtc_state
*pipe_config
)
1392 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1393 enum pipe pipe
= crtc
->pipe
;
1395 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1396 POSTING_READ(DPLL(pipe
));
1399 if (intel_de_wait_for_set(dev_priv
, DPLL(pipe
), DPLL_LOCK_VLV
, 1))
1400 DRM_ERROR("DPLL %d failed to lock\n", pipe
);
1403 static void vlv_enable_pll(struct intel_crtc
*crtc
,
1404 const struct intel_crtc_state
*pipe_config
)
1406 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1407 enum pipe pipe
= crtc
->pipe
;
1409 assert_pipe_disabled(dev_priv
, pipe_config
->cpu_transcoder
);
1411 /* PLL is protected by panel, make sure we can write it */
1412 assert_panel_unlocked(dev_priv
, pipe
);
1414 if (pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
)
1415 _vlv_enable_pll(crtc
, pipe_config
);
1417 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1418 POSTING_READ(DPLL_MD(pipe
));
1422 static void _chv_enable_pll(struct intel_crtc
*crtc
,
1423 const struct intel_crtc_state
*pipe_config
)
1425 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1426 enum pipe pipe
= crtc
->pipe
;
1427 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1430 vlv_dpio_get(dev_priv
);
1432 /* Enable back the 10bit clock to display controller */
1433 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1434 tmp
|= DPIO_DCLKP_EN
;
1435 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), tmp
);
1437 vlv_dpio_put(dev_priv
);
1440 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1445 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1447 /* Check PLL is locked */
1448 if (intel_de_wait_for_set(dev_priv
, DPLL(pipe
), DPLL_LOCK_VLV
, 1))
1449 DRM_ERROR("PLL %d failed to lock\n", pipe
);
1452 static void chv_enable_pll(struct intel_crtc
*crtc
,
1453 const struct intel_crtc_state
*pipe_config
)
1455 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1456 enum pipe pipe
= crtc
->pipe
;
1458 assert_pipe_disabled(dev_priv
, pipe_config
->cpu_transcoder
);
1460 /* PLL is protected by panel, make sure we can write it */
1461 assert_panel_unlocked(dev_priv
, pipe
);
1463 if (pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
)
1464 _chv_enable_pll(crtc
, pipe_config
);
1466 if (pipe
!= PIPE_A
) {
1468 * WaPixelRepeatModeFixForC0:chv
1470 * DPLLCMD is AWOL. Use chicken bits to propagate
1471 * the value from DPLLBMD to either pipe B or C.
1473 I915_WRITE(CBR4_VLV
, CBR_DPLLBMD_PIPE(pipe
));
1474 I915_WRITE(DPLL_MD(PIPE_B
), pipe_config
->dpll_hw_state
.dpll_md
);
1475 I915_WRITE(CBR4_VLV
, 0);
1476 dev_priv
->chv_dpll_md
[pipe
] = pipe_config
->dpll_hw_state
.dpll_md
;
1479 * DPLLB VGA mode also seems to cause problems.
1480 * We should always have it disabled.
1482 WARN_ON((I915_READ(DPLL(PIPE_B
)) & DPLL_VGA_MODE_DIS
) == 0);
1484 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1485 POSTING_READ(DPLL_MD(pipe
));
1489 static bool i9xx_has_pps(struct drm_i915_private
*dev_priv
)
1491 if (IS_I830(dev_priv
))
1494 return IS_PINEVIEW(dev_priv
) || IS_MOBILE(dev_priv
);
1497 static void i9xx_enable_pll(struct intel_crtc
*crtc
,
1498 const struct intel_crtc_state
*crtc_state
)
1500 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1501 i915_reg_t reg
= DPLL(crtc
->pipe
);
1502 u32 dpll
= crtc_state
->dpll_hw_state
.dpll
;
1505 assert_pipe_disabled(dev_priv
, crtc_state
->cpu_transcoder
);
1507 /* PLL is protected by panel, make sure we can write it */
1508 if (i9xx_has_pps(dev_priv
))
1509 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1512 * Apparently we need to have VGA mode enabled prior to changing
1513 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1514 * dividers, even though the register value does change.
1516 I915_WRITE(reg
, dpll
& ~DPLL_VGA_MODE_DIS
);
1517 I915_WRITE(reg
, dpll
);
1519 /* Wait for the clocks to stabilize. */
1523 if (INTEL_GEN(dev_priv
) >= 4) {
1524 I915_WRITE(DPLL_MD(crtc
->pipe
),
1525 crtc_state
->dpll_hw_state
.dpll_md
);
1527 /* The pixel multiplier can only be updated once the
1528 * DPLL is enabled and the clocks are stable.
1530 * So write it again.
1532 I915_WRITE(reg
, dpll
);
1535 /* We do this three times for luck */
1536 for (i
= 0; i
< 3; i
++) {
1537 I915_WRITE(reg
, dpll
);
1539 udelay(150); /* wait for warmup */
1543 static void i9xx_disable_pll(const struct intel_crtc_state
*crtc_state
)
1545 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
1546 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1547 enum pipe pipe
= crtc
->pipe
;
1549 /* Don't disable pipe or pipe PLLs if needed */
1550 if (IS_I830(dev_priv
))
1553 /* Make sure the pipe isn't still relying on us */
1554 assert_pipe_disabled(dev_priv
, crtc_state
->cpu_transcoder
);
1556 I915_WRITE(DPLL(pipe
), DPLL_VGA_MODE_DIS
);
1557 POSTING_READ(DPLL(pipe
));
1560 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1564 /* Make sure the pipe isn't still relying on us */
1565 assert_pipe_disabled(dev_priv
, (enum transcoder
)pipe
);
1567 val
= DPLL_INTEGRATED_REF_CLK_VLV
|
1568 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1570 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1572 I915_WRITE(DPLL(pipe
), val
);
1573 POSTING_READ(DPLL(pipe
));
1576 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1578 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1581 /* Make sure the pipe isn't still relying on us */
1582 assert_pipe_disabled(dev_priv
, (enum transcoder
)pipe
);
1584 val
= DPLL_SSC_REF_CLK_CHV
|
1585 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1587 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1589 I915_WRITE(DPLL(pipe
), val
);
1590 POSTING_READ(DPLL(pipe
));
1592 vlv_dpio_get(dev_priv
);
1594 /* Disable 10bit clock to display controller */
1595 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1596 val
&= ~DPIO_DCLKP_EN
;
1597 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1599 vlv_dpio_put(dev_priv
);
1602 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1603 struct intel_digital_port
*dport
,
1604 unsigned int expected_mask
)
1607 i915_reg_t dpll_reg
;
1609 switch (dport
->base
.port
) {
1611 port_mask
= DPLL_PORTB_READY_MASK
;
1615 port_mask
= DPLL_PORTC_READY_MASK
;
1617 expected_mask
<<= 4;
1620 port_mask
= DPLL_PORTD_READY_MASK
;
1621 dpll_reg
= DPIO_PHY_STATUS
;
1627 if (intel_de_wait_for_register(dev_priv
, dpll_reg
,
1628 port_mask
, expected_mask
, 1000))
1629 WARN(1, "timed out waiting for [ENCODER:%d:%s] port ready: got 0x%x, expected 0x%x\n",
1630 dport
->base
.base
.base
.id
, dport
->base
.base
.name
,
1631 I915_READ(dpll_reg
) & port_mask
, expected_mask
);
1634 static void ilk_enable_pch_transcoder(const struct intel_crtc_state
*crtc_state
)
1636 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
1637 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1638 enum pipe pipe
= crtc
->pipe
;
1640 u32 val
, pipeconf_val
;
1642 /* Make sure PCH DPLL is enabled */
1643 assert_shared_dpll_enabled(dev_priv
, crtc_state
->shared_dpll
);
1645 /* FDI must be feeding us bits for PCH ports */
1646 assert_fdi_tx_enabled(dev_priv
, pipe
);
1647 assert_fdi_rx_enabled(dev_priv
, pipe
);
1649 if (HAS_PCH_CPT(dev_priv
)) {
1650 reg
= TRANS_CHICKEN2(pipe
);
1651 val
= I915_READ(reg
);
1653 * Workaround: Set the timing override bit
1654 * before enabling the pch transcoder.
1656 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1657 /* Configure frame start delay to match the CPU */
1658 val
&= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK
;
1659 val
|= TRANS_CHICKEN2_FRAME_START_DELAY(0);
1660 I915_WRITE(reg
, val
);
1663 reg
= PCH_TRANSCONF(pipe
);
1664 val
= I915_READ(reg
);
1665 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1667 if (HAS_PCH_IBX(dev_priv
)) {
1668 /* Configure frame start delay to match the CPU */
1669 val
&= ~TRANS_FRAME_START_DELAY_MASK
;
1670 val
|= TRANS_FRAME_START_DELAY(0);
1673 * Make the BPC in transcoder be consistent with
1674 * that in pipeconf reg. For HDMI we must use 8bpc
1675 * here for both 8bpc and 12bpc.
1677 val
&= ~PIPECONF_BPC_MASK
;
1678 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
1679 val
|= PIPECONF_8BPC
;
1681 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
1684 val
&= ~TRANS_INTERLACE_MASK
;
1685 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
) {
1686 if (HAS_PCH_IBX(dev_priv
) &&
1687 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
))
1688 val
|= TRANS_LEGACY_INTERLACED_ILK
;
1690 val
|= TRANS_INTERLACED
;
1692 val
|= TRANS_PROGRESSIVE
;
1695 I915_WRITE(reg
, val
| TRANS_ENABLE
);
1696 if (intel_de_wait_for_set(dev_priv
, reg
, TRANS_STATE_ENABLE
, 100))
1697 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
1700 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1701 enum transcoder cpu_transcoder
)
1703 u32 val
, pipeconf_val
;
1705 /* FDI must be feeding us bits for PCH ports */
1706 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
1707 assert_fdi_rx_enabled(dev_priv
, PIPE_A
);
1709 val
= I915_READ(TRANS_CHICKEN2(PIPE_A
));
1710 /* Workaround: set timing override bit. */
1711 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1712 /* Configure frame start delay to match the CPU */
1713 val
&= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK
;
1714 val
|= TRANS_CHICKEN2_FRAME_START_DELAY(0);
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 ilk_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
->uapi
.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
->uapi
.crtc
);
1814 assert_vblank_disabled(&crtc
->base
);
1815 drm_crtc_set_max_vblank_count(&crtc
->base
,
1816 intel_crtc_max_vblank_count(crtc_state
));
1817 drm_crtc_vblank_on(&crtc
->base
);
1820 void intel_crtc_vblank_off(const struct intel_crtc_state
*crtc_state
)
1822 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
1824 drm_crtc_vblank_off(&crtc
->base
);
1825 assert_vblank_disabled(&crtc
->base
);
1828 static void intel_enable_pipe(const struct intel_crtc_state
*new_crtc_state
)
1830 struct intel_crtc
*crtc
= to_intel_crtc(new_crtc_state
->uapi
.crtc
);
1831 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1832 enum transcoder cpu_transcoder
= new_crtc_state
->cpu_transcoder
;
1833 enum pipe pipe
= crtc
->pipe
;
1837 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe
));
1839 assert_planes_disabled(crtc
);
1842 * A pipe without a PLL won't actually be able to drive bits from
1843 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1846 if (HAS_GMCH(dev_priv
)) {
1847 if (intel_crtc_has_type(new_crtc_state
, INTEL_OUTPUT_DSI
))
1848 assert_dsi_pll_enabled(dev_priv
);
1850 assert_pll_enabled(dev_priv
, pipe
);
1852 if (new_crtc_state
->has_pch_encoder
) {
1853 /* if driving the PCH, we need FDI enabled */
1854 assert_fdi_rx_pll_enabled(dev_priv
,
1855 intel_crtc_pch_transcoder(crtc
));
1856 assert_fdi_tx_pll_enabled(dev_priv
,
1857 (enum pipe
) cpu_transcoder
);
1859 /* FIXME: assert CPU port conditions for SNB+ */
1862 trace_intel_pipe_enable(crtc
);
1864 reg
= PIPECONF(cpu_transcoder
);
1865 val
= I915_READ(reg
);
1866 if (val
& PIPECONF_ENABLE
) {
1867 /* we keep both pipes enabled on 830 */
1868 WARN_ON(!IS_I830(dev_priv
));
1872 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
1876 * Until the pipe starts PIPEDSL reads will return a stale value,
1877 * which causes an apparent vblank timestamp jump when PIPEDSL
1878 * resets to its proper value. That also messes up the frame count
1879 * when it's derived from the timestamps. So let's wait for the
1880 * pipe to start properly before we call drm_crtc_vblank_on()
1882 if (intel_crtc_max_vblank_count(new_crtc_state
) == 0)
1883 intel_wait_for_pipe_scanline_moving(crtc
);
1886 void intel_disable_pipe(const struct intel_crtc_state
*old_crtc_state
)
1888 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->uapi
.crtc
);
1889 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1890 enum transcoder cpu_transcoder
= old_crtc_state
->cpu_transcoder
;
1891 enum pipe pipe
= crtc
->pipe
;
1895 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe
));
1898 * Make sure planes won't keep trying to pump pixels to us,
1899 * or we might hang the display.
1901 assert_planes_disabled(crtc
);
1903 trace_intel_pipe_disable(crtc
);
1905 reg
= PIPECONF(cpu_transcoder
);
1906 val
= I915_READ(reg
);
1907 if ((val
& PIPECONF_ENABLE
) == 0)
1911 * Double wide has implications for planes
1912 * so best keep it disabled when not needed.
1914 if (old_crtc_state
->double_wide
)
1915 val
&= ~PIPECONF_DOUBLE_WIDE
;
1917 /* Don't disable pipe or pipe PLLs if needed */
1918 if (!IS_I830(dev_priv
))
1919 val
&= ~PIPECONF_ENABLE
;
1921 I915_WRITE(reg
, val
);
1922 if ((val
& PIPECONF_ENABLE
) == 0)
1923 intel_wait_for_pipe_off(old_crtc_state
);
1926 static unsigned int intel_tile_size(const struct drm_i915_private
*dev_priv
)
1928 return IS_GEN(dev_priv
, 2) ? 2048 : 4096;
1931 static bool is_ccs_plane(const struct drm_framebuffer
*fb
, int plane
)
1933 if (!is_ccs_modifier(fb
->modifier
))
1936 return plane
>= fb
->format
->num_planes
/ 2;
1939 static bool is_gen12_ccs_modifier(u64 modifier
)
1941 return modifier
== I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS
||
1942 modifier
== I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS
;
1946 static bool is_gen12_ccs_plane(const struct drm_framebuffer
*fb
, int plane
)
1948 return is_gen12_ccs_modifier(fb
->modifier
) && is_ccs_plane(fb
, plane
);
1951 static bool is_aux_plane(const struct drm_framebuffer
*fb
, int plane
)
1953 if (is_ccs_modifier(fb
->modifier
))
1954 return is_ccs_plane(fb
, plane
);
1959 static int main_to_ccs_plane(const struct drm_framebuffer
*fb
, int main_plane
)
1961 WARN_ON(!is_ccs_modifier(fb
->modifier
) ||
1962 (main_plane
&& main_plane
>= fb
->format
->num_planes
/ 2));
1964 return fb
->format
->num_planes
/ 2 + main_plane
;
1967 static int ccs_to_main_plane(const struct drm_framebuffer
*fb
, int ccs_plane
)
1969 WARN_ON(!is_ccs_modifier(fb
->modifier
) ||
1970 ccs_plane
< fb
->format
->num_planes
/ 2);
1972 return ccs_plane
- fb
->format
->num_planes
/ 2;
1975 /* Return either the main plane's CCS or - if not a CCS FB - UV plane */
1976 int intel_main_to_aux_plane(const struct drm_framebuffer
*fb
, int main_plane
)
1978 if (is_ccs_modifier(fb
->modifier
))
1979 return main_to_ccs_plane(fb
, main_plane
);
1985 intel_format_info_is_yuv_semiplanar(const struct drm_format_info
*info
,
1988 return info
->is_yuv
&&
1989 info
->num_planes
== (is_ccs_modifier(modifier
) ? 4 : 2);
1992 static bool is_semiplanar_uv_plane(const struct drm_framebuffer
*fb
,
1995 return intel_format_info_is_yuv_semiplanar(fb
->format
, fb
->modifier
) &&
2000 intel_tile_width_bytes(const struct drm_framebuffer
*fb
, int color_plane
)
2002 struct drm_i915_private
*dev_priv
= to_i915(fb
->dev
);
2003 unsigned int cpp
= fb
->format
->cpp
[color_plane
];
2005 switch (fb
->modifier
) {
2006 case DRM_FORMAT_MOD_LINEAR
:
2007 return intel_tile_size(dev_priv
);
2008 case I915_FORMAT_MOD_X_TILED
:
2009 if (IS_GEN(dev_priv
, 2))
2013 case I915_FORMAT_MOD_Y_TILED_CCS
:
2014 if (is_ccs_plane(fb
, color_plane
))
2017 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS
:
2018 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS
:
2019 if (is_ccs_plane(fb
, color_plane
))
2022 case I915_FORMAT_MOD_Y_TILED
:
2023 if (IS_GEN(dev_priv
, 2) || HAS_128_BYTE_Y_TILING(dev_priv
))
2027 case I915_FORMAT_MOD_Yf_TILED_CCS
:
2028 if (is_ccs_plane(fb
, color_plane
))
2031 case I915_FORMAT_MOD_Yf_TILED
:
2047 MISSING_CASE(fb
->modifier
);
2053 intel_tile_height(const struct drm_framebuffer
*fb
, int color_plane
)
2055 if (is_gen12_ccs_plane(fb
, color_plane
))
2058 return intel_tile_size(to_i915(fb
->dev
)) /
2059 intel_tile_width_bytes(fb
, color_plane
);
2062 /* Return the tile dimensions in pixel units */
2063 static void intel_tile_dims(const struct drm_framebuffer
*fb
, int color_plane
,
2064 unsigned int *tile_width
,
2065 unsigned int *tile_height
)
2067 unsigned int tile_width_bytes
= intel_tile_width_bytes(fb
, color_plane
);
2068 unsigned int cpp
= fb
->format
->cpp
[color_plane
];
2070 *tile_width
= tile_width_bytes
/ cpp
;
2071 *tile_height
= intel_tile_height(fb
, color_plane
);
2074 static unsigned int intel_tile_row_size(const struct drm_framebuffer
*fb
,
2077 unsigned int tile_width
, tile_height
;
2079 intel_tile_dims(fb
, color_plane
, &tile_width
, &tile_height
);
2081 return fb
->pitches
[color_plane
] * tile_height
;
2085 intel_fb_align_height(const struct drm_framebuffer
*fb
,
2086 int color_plane
, unsigned int height
)
2088 unsigned int tile_height
= intel_tile_height(fb
, color_plane
);
2090 return ALIGN(height
, tile_height
);
2093 unsigned int intel_rotation_info_size(const struct intel_rotation_info
*rot_info
)
2095 unsigned int size
= 0;
2098 for (i
= 0 ; i
< ARRAY_SIZE(rot_info
->plane
); i
++)
2099 size
+= rot_info
->plane
[i
].width
* rot_info
->plane
[i
].height
;
2104 unsigned int intel_remapped_info_size(const struct intel_remapped_info
*rem_info
)
2106 unsigned int size
= 0;
2109 for (i
= 0 ; i
< ARRAY_SIZE(rem_info
->plane
); i
++)
2110 size
+= rem_info
->plane
[i
].width
* rem_info
->plane
[i
].height
;
2116 intel_fill_fb_ggtt_view(struct i915_ggtt_view
*view
,
2117 const struct drm_framebuffer
*fb
,
2118 unsigned int rotation
)
2120 view
->type
= I915_GGTT_VIEW_NORMAL
;
2121 if (drm_rotation_90_or_270(rotation
)) {
2122 view
->type
= I915_GGTT_VIEW_ROTATED
;
2123 view
->rotated
= to_intel_framebuffer(fb
)->rot_info
;
2127 static unsigned int intel_cursor_alignment(const struct drm_i915_private
*dev_priv
)
2129 if (IS_I830(dev_priv
))
2131 else if (IS_I85X(dev_priv
))
2133 else if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
))
2139 static unsigned int intel_linear_alignment(const struct drm_i915_private
*dev_priv
)
2141 if (INTEL_GEN(dev_priv
) >= 9)
2143 else if (IS_I965G(dev_priv
) || IS_I965GM(dev_priv
) ||
2144 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
2146 else if (INTEL_GEN(dev_priv
) >= 4)
2152 static unsigned int intel_surf_alignment(const struct drm_framebuffer
*fb
,
2155 struct drm_i915_private
*dev_priv
= to_i915(fb
->dev
);
2157 /* AUX_DIST needs only 4K alignment */
2158 if ((INTEL_GEN(dev_priv
) < 12 && is_aux_plane(fb
, color_plane
)) ||
2159 is_ccs_plane(fb
, color_plane
))
2162 switch (fb
->modifier
) {
2163 case DRM_FORMAT_MOD_LINEAR
:
2164 return intel_linear_alignment(dev_priv
);
2165 case I915_FORMAT_MOD_X_TILED
:
2166 if (INTEL_GEN(dev_priv
) >= 9)
2169 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS
:
2170 if (is_semiplanar_uv_plane(fb
, color_plane
))
2171 return intel_tile_row_size(fb
, color_plane
);
2173 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS
:
2175 case I915_FORMAT_MOD_Y_TILED_CCS
:
2176 case I915_FORMAT_MOD_Yf_TILED_CCS
:
2177 case I915_FORMAT_MOD_Y_TILED
:
2178 if (INTEL_GEN(dev_priv
) >= 12 &&
2179 is_semiplanar_uv_plane(fb
, color_plane
))
2180 return intel_tile_row_size(fb
, color_plane
);
2182 case I915_FORMAT_MOD_Yf_TILED
:
2183 return 1 * 1024 * 1024;
2185 MISSING_CASE(fb
->modifier
);
2190 static bool intel_plane_uses_fence(const struct intel_plane_state
*plane_state
)
2192 struct intel_plane
*plane
= to_intel_plane(plane_state
->uapi
.plane
);
2193 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
2195 return INTEL_GEN(dev_priv
) < 4 ||
2197 plane_state
->view
.type
== I915_GGTT_VIEW_NORMAL
);
2201 intel_pin_and_fence_fb_obj(struct drm_framebuffer
*fb
,
2202 const struct i915_ggtt_view
*view
,
2204 unsigned long *out_flags
)
2206 struct drm_device
*dev
= fb
->dev
;
2207 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2208 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2209 intel_wakeref_t wakeref
;
2210 struct i915_vma
*vma
;
2211 unsigned int pinctl
;
2214 if (WARN_ON(!i915_gem_object_is_framebuffer(obj
)))
2215 return ERR_PTR(-EINVAL
);
2217 alignment
= intel_surf_alignment(fb
, 0);
2218 if (WARN_ON(alignment
&& !is_power_of_2(alignment
)))
2219 return ERR_PTR(-EINVAL
);
2221 /* Note that the w/a also requires 64 PTE of padding following the
2222 * bo. We currently fill all unused PTE with the shadow page and so
2223 * we should always have valid PTE following the scanout preventing
2226 if (intel_scanout_needs_vtd_wa(dev_priv
) && alignment
< 256 * 1024)
2227 alignment
= 256 * 1024;
2230 * Global gtt pte registers are special registers which actually forward
2231 * writes to a chunk of system memory. Which means that there is no risk
2232 * that the register values disappear as soon as we call
2233 * intel_runtime_pm_put(), so it is correct to wrap only the
2234 * pin/unpin/fence and not more.
2236 wakeref
= intel_runtime_pm_get(&dev_priv
->runtime_pm
);
2238 atomic_inc(&dev_priv
->gpu_error
.pending_fb_pin
);
2241 * Valleyview is definitely limited to scanning out the first
2242 * 512MiB. Lets presume this behaviour was inherited from the
2243 * g4x display engine and that all earlier gen are similarly
2244 * limited. Testing suggests that it is a little more
2245 * complicated than this. For example, Cherryview appears quite
2246 * happy to scanout from anywhere within its global aperture.
2249 if (HAS_GMCH(dev_priv
))
2250 pinctl
|= PIN_MAPPABLE
;
2252 vma
= i915_gem_object_pin_to_display_plane(obj
,
2253 alignment
, view
, pinctl
);
2257 if (uses_fence
&& i915_vma_is_map_and_fenceable(vma
)) {
2261 * Install a fence for tiled scan-out. Pre-i965 always needs a
2262 * fence, whereas 965+ only requires a fence if using
2263 * framebuffer compression. For simplicity, we always, when
2264 * possible, install a fence as the cost is not that onerous.
2266 * If we fail to fence the tiled scanout, then either the
2267 * modeset will reject the change (which is highly unlikely as
2268 * the affected systems, all but one, do not have unmappable
2269 * space) or we will not be able to enable full powersaving
2270 * techniques (also likely not to apply due to various limits
2271 * FBC and the like impose on the size of the buffer, which
2272 * presumably we violated anyway with this unmappable buffer).
2273 * Anyway, it is presumably better to stumble onwards with
2274 * something and try to run the system in a "less than optimal"
2275 * mode that matches the user configuration.
2277 ret
= i915_vma_pin_fence(vma
);
2278 if (ret
!= 0 && INTEL_GEN(dev_priv
) < 4) {
2279 i915_gem_object_unpin_from_display_plane(vma
);
2284 if (ret
== 0 && vma
->fence
)
2285 *out_flags
|= PLANE_HAS_FENCE
;
2290 atomic_dec(&dev_priv
->gpu_error
.pending_fb_pin
);
2291 intel_runtime_pm_put(&dev_priv
->runtime_pm
, wakeref
);
2295 void intel_unpin_fb_vma(struct i915_vma
*vma
, unsigned long flags
)
2297 i915_gem_object_lock(vma
->obj
);
2298 if (flags
& PLANE_HAS_FENCE
)
2299 i915_vma_unpin_fence(vma
);
2300 i915_gem_object_unpin_from_display_plane(vma
);
2301 i915_gem_object_unlock(vma
->obj
);
2306 static int intel_fb_pitch(const struct drm_framebuffer
*fb
, int color_plane
,
2307 unsigned int rotation
)
2309 if (drm_rotation_90_or_270(rotation
))
2310 return to_intel_framebuffer(fb
)->rotated
[color_plane
].pitch
;
2312 return fb
->pitches
[color_plane
];
2316 * Convert the x/y offsets into a linear offset.
2317 * Only valid with 0/180 degree rotation, which is fine since linear
2318 * offset is only used with linear buffers on pre-hsw and tiled buffers
2319 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2321 u32
intel_fb_xy_to_linear(int x
, int y
,
2322 const struct intel_plane_state
*state
,
2325 const struct drm_framebuffer
*fb
= state
->hw
.fb
;
2326 unsigned int cpp
= fb
->format
->cpp
[color_plane
];
2327 unsigned int pitch
= state
->color_plane
[color_plane
].stride
;
2329 return y
* pitch
+ x
* cpp
;
2333 * Add the x/y offsets derived from fb->offsets[] to the user
2334 * specified plane src x/y offsets. The resulting x/y offsets
2335 * specify the start of scanout from the beginning of the gtt mapping.
2337 void intel_add_fb_offsets(int *x
, int *y
,
2338 const struct intel_plane_state
*state
,
2342 *x
+= state
->color_plane
[color_plane
].x
;
2343 *y
+= state
->color_plane
[color_plane
].y
;
2346 static u32
intel_adjust_tile_offset(int *x
, int *y
,
2347 unsigned int tile_width
,
2348 unsigned int tile_height
,
2349 unsigned int tile_size
,
2350 unsigned int pitch_tiles
,
2354 unsigned int pitch_pixels
= pitch_tiles
* tile_width
;
2357 WARN_ON(old_offset
& (tile_size
- 1));
2358 WARN_ON(new_offset
& (tile_size
- 1));
2359 WARN_ON(new_offset
> old_offset
);
2361 tiles
= (old_offset
- new_offset
) / tile_size
;
2363 *y
+= tiles
/ pitch_tiles
* tile_height
;
2364 *x
+= tiles
% pitch_tiles
* tile_width
;
2366 /* minimize x in case it got needlessly big */
2367 *y
+= *x
/ pitch_pixels
* tile_height
;
2373 static bool is_surface_linear(const struct drm_framebuffer
*fb
, int color_plane
)
2375 return fb
->modifier
== DRM_FORMAT_MOD_LINEAR
||
2376 is_gen12_ccs_plane(fb
, color_plane
);
2379 static u32
intel_adjust_aligned_offset(int *x
, int *y
,
2380 const struct drm_framebuffer
*fb
,
2382 unsigned int rotation
,
2384 u32 old_offset
, u32 new_offset
)
2386 struct drm_i915_private
*dev_priv
= to_i915(fb
->dev
);
2387 unsigned int cpp
= fb
->format
->cpp
[color_plane
];
2389 WARN_ON(new_offset
> old_offset
);
2391 if (!is_surface_linear(fb
, color_plane
)) {
2392 unsigned int tile_size
, tile_width
, tile_height
;
2393 unsigned int pitch_tiles
;
2395 tile_size
= intel_tile_size(dev_priv
);
2396 intel_tile_dims(fb
, color_plane
, &tile_width
, &tile_height
);
2398 if (drm_rotation_90_or_270(rotation
)) {
2399 pitch_tiles
= pitch
/ tile_height
;
2400 swap(tile_width
, tile_height
);
2402 pitch_tiles
= pitch
/ (tile_width
* cpp
);
2405 intel_adjust_tile_offset(x
, y
, tile_width
, tile_height
,
2406 tile_size
, pitch_tiles
,
2407 old_offset
, new_offset
);
2409 old_offset
+= *y
* pitch
+ *x
* cpp
;
2411 *y
= (old_offset
- new_offset
) / pitch
;
2412 *x
= ((old_offset
- new_offset
) - *y
* pitch
) / cpp
;
2419 * Adjust the tile offset by moving the difference into
2422 static u32
intel_plane_adjust_aligned_offset(int *x
, int *y
,
2423 const struct intel_plane_state
*state
,
2425 u32 old_offset
, u32 new_offset
)
2427 return intel_adjust_aligned_offset(x
, y
, state
->hw
.fb
, color_plane
,
2429 state
->color_plane
[color_plane
].stride
,
2430 old_offset
, new_offset
);
2434 * Computes the aligned offset to the base tile and adjusts
2435 * x, y. bytes per pixel is assumed to be a power-of-two.
2437 * In the 90/270 rotated case, x and y are assumed
2438 * to be already rotated to match the rotated GTT view, and
2439 * pitch is the tile_height aligned framebuffer height.
2441 * This function is used when computing the derived information
2442 * under intel_framebuffer, so using any of that information
2443 * here is not allowed. Anything under drm_framebuffer can be
2444 * used. This is why the user has to pass in the pitch since it
2445 * is specified in the rotated orientation.
2447 static u32
intel_compute_aligned_offset(struct drm_i915_private
*dev_priv
,
2449 const struct drm_framebuffer
*fb
,
2452 unsigned int rotation
,
2455 unsigned int cpp
= fb
->format
->cpp
[color_plane
];
2456 u32 offset
, offset_aligned
;
2458 if (!is_surface_linear(fb
, color_plane
)) {
2459 unsigned int tile_size
, tile_width
, tile_height
;
2460 unsigned int tile_rows
, tiles
, pitch_tiles
;
2462 tile_size
= intel_tile_size(dev_priv
);
2463 intel_tile_dims(fb
, color_plane
, &tile_width
, &tile_height
);
2465 if (drm_rotation_90_or_270(rotation
)) {
2466 pitch_tiles
= pitch
/ tile_height
;
2467 swap(tile_width
, tile_height
);
2469 pitch_tiles
= pitch
/ (tile_width
* cpp
);
2472 tile_rows
= *y
/ tile_height
;
2475 tiles
= *x
/ tile_width
;
2478 offset
= (tile_rows
* pitch_tiles
+ tiles
) * tile_size
;
2480 offset_aligned
= offset
;
2482 offset_aligned
= rounddown(offset_aligned
, alignment
);
2484 intel_adjust_tile_offset(x
, y
, tile_width
, tile_height
,
2485 tile_size
, pitch_tiles
,
2486 offset
, offset_aligned
);
2488 offset
= *y
* pitch
+ *x
* cpp
;
2489 offset_aligned
= offset
;
2491 offset_aligned
= rounddown(offset_aligned
, alignment
);
2492 *y
= (offset
% alignment
) / pitch
;
2493 *x
= ((offset
% alignment
) - *y
* pitch
) / cpp
;
2499 return offset_aligned
;
2502 static u32
intel_plane_compute_aligned_offset(int *x
, int *y
,
2503 const struct intel_plane_state
*state
,
2506 struct intel_plane
*intel_plane
= to_intel_plane(state
->uapi
.plane
);
2507 struct drm_i915_private
*dev_priv
= to_i915(intel_plane
->base
.dev
);
2508 const struct drm_framebuffer
*fb
= state
->hw
.fb
;
2509 unsigned int rotation
= state
->hw
.rotation
;
2510 int pitch
= state
->color_plane
[color_plane
].stride
;
2513 if (intel_plane
->id
== PLANE_CURSOR
)
2514 alignment
= intel_cursor_alignment(dev_priv
);
2516 alignment
= intel_surf_alignment(fb
, color_plane
);
2518 return intel_compute_aligned_offset(dev_priv
, x
, y
, fb
, color_plane
,
2519 pitch
, rotation
, alignment
);
2522 /* Convert the fb->offset[] into x/y offsets */
2523 static int intel_fb_offset_to_xy(int *x
, int *y
,
2524 const struct drm_framebuffer
*fb
,
2527 struct drm_i915_private
*dev_priv
= to_i915(fb
->dev
);
2528 unsigned int height
;
2531 if (INTEL_GEN(dev_priv
) >= 12 &&
2532 is_semiplanar_uv_plane(fb
, color_plane
))
2533 alignment
= intel_tile_row_size(fb
, color_plane
);
2534 else if (fb
->modifier
!= DRM_FORMAT_MOD_LINEAR
)
2535 alignment
= intel_tile_size(dev_priv
);
2539 if (alignment
!= 0 && fb
->offsets
[color_plane
] % alignment
) {
2540 DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n",
2541 fb
->offsets
[color_plane
], color_plane
);
2545 height
= drm_framebuffer_plane_height(fb
->height
, fb
, color_plane
);
2546 height
= ALIGN(height
, intel_tile_height(fb
, color_plane
));
2548 /* Catch potential overflows early */
2549 if (add_overflows_t(u32
, mul_u32_u32(height
, fb
->pitches
[color_plane
]),
2550 fb
->offsets
[color_plane
])) {
2551 DRM_DEBUG_KMS("Bad offset 0x%08x or pitch %d for color plane %d\n",
2552 fb
->offsets
[color_plane
], fb
->pitches
[color_plane
],
2560 intel_adjust_aligned_offset(x
, y
,
2561 fb
, color_plane
, DRM_MODE_ROTATE_0
,
2562 fb
->pitches
[color_plane
],
2563 fb
->offsets
[color_plane
], 0);
2568 static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier
)
2570 switch (fb_modifier
) {
2571 case I915_FORMAT_MOD_X_TILED
:
2572 return I915_TILING_X
;
2573 case I915_FORMAT_MOD_Y_TILED
:
2574 case I915_FORMAT_MOD_Y_TILED_CCS
:
2575 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS
:
2576 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS
:
2577 return I915_TILING_Y
;
2579 return I915_TILING_NONE
;
2584 * From the Sky Lake PRM:
2585 * "The Color Control Surface (CCS) contains the compression status of
2586 * the cache-line pairs. The compression state of the cache-line pair
2587 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2588 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2589 * cache-line-pairs. CCS is always Y tiled."
2591 * Since cache line pairs refers to horizontally adjacent cache lines,
2592 * each cache line in the CCS corresponds to an area of 32x16 cache
2593 * lines on the main surface. Since each pixel is 4 bytes, this gives
2594 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2597 static const struct drm_format_info skl_ccs_formats
[] = {
2598 { .format
= DRM_FORMAT_XRGB8888
, .depth
= 24, .num_planes
= 2,
2599 .cpp
= { 4, 1, }, .hsub
= 8, .vsub
= 16, },
2600 { .format
= DRM_FORMAT_XBGR8888
, .depth
= 24, .num_planes
= 2,
2601 .cpp
= { 4, 1, }, .hsub
= 8, .vsub
= 16, },
2602 { .format
= DRM_FORMAT_ARGB8888
, .depth
= 32, .num_planes
= 2,
2603 .cpp
= { 4, 1, }, .hsub
= 8, .vsub
= 16, .has_alpha
= true, },
2604 { .format
= DRM_FORMAT_ABGR8888
, .depth
= 32, .num_planes
= 2,
2605 .cpp
= { 4, 1, }, .hsub
= 8, .vsub
= 16, .has_alpha
= true, },
2609 * Gen-12 compression uses 4 bits of CCS data for each cache line pair in the
2610 * main surface. And each 64B CCS cache line represents an area of 4x1 Y-tiles
2611 * in the main surface. With 4 byte pixels and each Y-tile having dimensions of
2612 * 32x32 pixels, the ratio turns out to 1B in the CCS for every 2x32 pixels in
2615 static const struct drm_format_info gen12_ccs_formats
[] = {
2616 { .format
= DRM_FORMAT_XRGB8888
, .depth
= 24, .num_planes
= 2,
2617 .char_per_block
= { 4, 1 }, .block_w
= { 1, 2 }, .block_h
= { 1, 1 },
2618 .hsub
= 1, .vsub
= 1, },
2619 { .format
= DRM_FORMAT_XBGR8888
, .depth
= 24, .num_planes
= 2,
2620 .char_per_block
= { 4, 1 }, .block_w
= { 1, 2 }, .block_h
= { 1, 1 },
2621 .hsub
= 1, .vsub
= 1, },
2622 { .format
= DRM_FORMAT_ARGB8888
, .depth
= 32, .num_planes
= 2,
2623 .char_per_block
= { 4, 1 }, .block_w
= { 1, 2 }, .block_h
= { 1, 1 },
2624 .hsub
= 1, .vsub
= 1, .has_alpha
= true },
2625 { .format
= DRM_FORMAT_ABGR8888
, .depth
= 32, .num_planes
= 2,
2626 .char_per_block
= { 4, 1 }, .block_w
= { 1, 2 }, .block_h
= { 1, 1 },
2627 .hsub
= 1, .vsub
= 1, .has_alpha
= true },
2628 { .format
= DRM_FORMAT_YUYV
, .num_planes
= 2,
2629 .char_per_block
= { 2, 1 }, .block_w
= { 1, 2 }, .block_h
= { 1, 1 },
2630 .hsub
= 2, .vsub
= 1, .is_yuv
= true },
2631 { .format
= DRM_FORMAT_YVYU
, .num_planes
= 2,
2632 .char_per_block
= { 2, 1 }, .block_w
= { 1, 2 }, .block_h
= { 1, 1 },
2633 .hsub
= 2, .vsub
= 1, .is_yuv
= true },
2634 { .format
= DRM_FORMAT_UYVY
, .num_planes
= 2,
2635 .char_per_block
= { 2, 1 }, .block_w
= { 1, 2 }, .block_h
= { 1, 1 },
2636 .hsub
= 2, .vsub
= 1, .is_yuv
= true },
2637 { .format
= DRM_FORMAT_VYUY
, .num_planes
= 2,
2638 .char_per_block
= { 2, 1 }, .block_w
= { 1, 2 }, .block_h
= { 1, 1 },
2639 .hsub
= 2, .vsub
= 1, .is_yuv
= true },
2640 { .format
= DRM_FORMAT_NV12
, .num_planes
= 4,
2641 .char_per_block
= { 1, 2, 1, 1 }, .block_w
= { 1, 1, 4, 4 }, .block_h
= { 1, 1, 1, 1 },
2642 .hsub
= 2, .vsub
= 2, .is_yuv
= true },
2643 { .format
= DRM_FORMAT_P010
, .num_planes
= 4,
2644 .char_per_block
= { 2, 4, 1, 1 }, .block_w
= { 1, 1, 2, 2 }, .block_h
= { 1, 1, 1, 1 },
2645 .hsub
= 2, .vsub
= 2, .is_yuv
= true },
2646 { .format
= DRM_FORMAT_P012
, .num_planes
= 4,
2647 .char_per_block
= { 2, 4, 1, 1 }, .block_w
= { 1, 1, 2, 2 }, .block_h
= { 1, 1, 1, 1 },
2648 .hsub
= 2, .vsub
= 2, .is_yuv
= true },
2649 { .format
= DRM_FORMAT_P016
, .num_planes
= 4,
2650 .char_per_block
= { 2, 4, 1, 1 }, .block_w
= { 1, 1, 2, 2 }, .block_h
= { 1, 1, 1, 1 },
2651 .hsub
= 2, .vsub
= 2, .is_yuv
= true },
2654 static const struct drm_format_info
*
2655 lookup_format_info(const struct drm_format_info formats
[],
2656 int num_formats
, u32 format
)
2660 for (i
= 0; i
< num_formats
; i
++) {
2661 if (formats
[i
].format
== format
)
2668 static const struct drm_format_info
*
2669 intel_get_format_info(const struct drm_mode_fb_cmd2
*cmd
)
2671 switch (cmd
->modifier
[0]) {
2672 case I915_FORMAT_MOD_Y_TILED_CCS
:
2673 case I915_FORMAT_MOD_Yf_TILED_CCS
:
2674 return lookup_format_info(skl_ccs_formats
,
2675 ARRAY_SIZE(skl_ccs_formats
),
2677 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS
:
2678 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS
:
2679 return lookup_format_info(gen12_ccs_formats
,
2680 ARRAY_SIZE(gen12_ccs_formats
),
2687 bool is_ccs_modifier(u64 modifier
)
2689 return modifier
== I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS
||
2690 modifier
== I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS
||
2691 modifier
== I915_FORMAT_MOD_Y_TILED_CCS
||
2692 modifier
== I915_FORMAT_MOD_Yf_TILED_CCS
;
2695 static int gen12_ccs_aux_stride(struct drm_framebuffer
*fb
, int ccs_plane
)
2697 return DIV_ROUND_UP(fb
->pitches
[ccs_to_main_plane(fb
, ccs_plane
)],
2701 u32
intel_plane_fb_max_stride(struct drm_i915_private
*dev_priv
,
2702 u32 pixel_format
, u64 modifier
)
2704 struct intel_crtc
*crtc
;
2705 struct intel_plane
*plane
;
2708 * We assume the primary plane for pipe A has
2709 * the highest stride limits of them all.
2711 crtc
= intel_get_crtc_for_pipe(dev_priv
, PIPE_A
);
2715 plane
= to_intel_plane(crtc
->base
.primary
);
2717 return plane
->max_stride(plane
, pixel_format
, modifier
,
2722 u32
intel_fb_max_stride(struct drm_i915_private
*dev_priv
,
2723 u32 pixel_format
, u64 modifier
)
2726 * Arbitrary limit for gen4+ chosen to match the
2727 * render engine max stride.
2729 * The new CCS hash mode makes remapping impossible
2731 if (!is_ccs_modifier(modifier
)) {
2732 if (INTEL_GEN(dev_priv
) >= 7)
2734 else if (INTEL_GEN(dev_priv
) >= 4)
2738 return intel_plane_fb_max_stride(dev_priv
, pixel_format
, modifier
);
2742 intel_fb_stride_alignment(const struct drm_framebuffer
*fb
, int color_plane
)
2744 struct drm_i915_private
*dev_priv
= to_i915(fb
->dev
);
2747 if (is_surface_linear(fb
, color_plane
)) {
2748 u32 max_stride
= intel_plane_fb_max_stride(dev_priv
,
2753 * To make remapping with linear generally feasible
2754 * we need the stride to be page aligned.
2756 if (fb
->pitches
[color_plane
] > max_stride
&&
2757 !is_ccs_modifier(fb
->modifier
))
2758 return intel_tile_size(dev_priv
);
2763 tile_width
= intel_tile_width_bytes(fb
, color_plane
);
2764 if (is_ccs_modifier(fb
->modifier
)) {
2766 * Display WA #0531: skl,bxt,kbl,glk
2768 * Render decompression and plane width > 3840
2769 * combined with horizontal panning requires the
2770 * plane stride to be a multiple of 4. We'll just
2771 * require the entire fb to accommodate that to avoid
2772 * potential runtime errors at plane configuration time.
2774 if (IS_GEN(dev_priv
, 9) && color_plane
== 0 && fb
->width
> 3840)
2777 * The main surface pitch must be padded to a multiple of four
2780 else if (INTEL_GEN(dev_priv
) >= 12)
2786 bool intel_plane_can_remap(const struct intel_plane_state
*plane_state
)
2788 struct intel_plane
*plane
= to_intel_plane(plane_state
->uapi
.plane
);
2789 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
2790 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
2793 /* We don't want to deal with remapping with cursors */
2794 if (plane
->id
== PLANE_CURSOR
)
2798 * The display engine limits already match/exceed the
2799 * render engine limits, so not much point in remapping.
2800 * Would also need to deal with the fence POT alignment
2801 * and gen2 2KiB GTT tile size.
2803 if (INTEL_GEN(dev_priv
) < 4)
2807 * The new CCS hash mode isn't compatible with remapping as
2808 * the virtual address of the pages affects the compressed data.
2810 if (is_ccs_modifier(fb
->modifier
))
2813 /* Linear needs a page aligned stride for remapping */
2814 if (fb
->modifier
== DRM_FORMAT_MOD_LINEAR
) {
2815 unsigned int alignment
= intel_tile_size(dev_priv
) - 1;
2817 for (i
= 0; i
< fb
->format
->num_planes
; i
++) {
2818 if (fb
->pitches
[i
] & alignment
)
2826 static bool intel_plane_needs_remap(const struct intel_plane_state
*plane_state
)
2828 struct intel_plane
*plane
= to_intel_plane(plane_state
->uapi
.plane
);
2829 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
2830 unsigned int rotation
= plane_state
->hw
.rotation
;
2831 u32 stride
, max_stride
;
2834 * No remapping for invisible planes since we don't have
2835 * an actual source viewport to remap.
2837 if (!plane_state
->uapi
.visible
)
2840 if (!intel_plane_can_remap(plane_state
))
2844 * FIXME: aux plane limits on gen9+ are
2845 * unclear in Bspec, for now no checking.
2847 stride
= intel_fb_pitch(fb
, 0, rotation
);
2848 max_stride
= plane
->max_stride(plane
, fb
->format
->format
,
2849 fb
->modifier
, rotation
);
2851 return stride
> max_stride
;
2855 intel_fb_plane_get_subsampling(int *hsub
, int *vsub
,
2856 const struct drm_framebuffer
*fb
,
2861 if (color_plane
== 0) {
2869 * TODO: Deduct the subsampling from the char block for all CCS
2870 * formats and planes.
2872 if (!is_gen12_ccs_plane(fb
, color_plane
)) {
2873 *hsub
= fb
->format
->hsub
;
2874 *vsub
= fb
->format
->vsub
;
2879 main_plane
= ccs_to_main_plane(fb
, color_plane
);
2880 *hsub
= drm_format_info_block_width(fb
->format
, color_plane
) /
2881 drm_format_info_block_width(fb
->format
, main_plane
);
2884 * The min stride check in the core framebuffer_check() function
2885 * assumes that format->hsub applies to every plane except for the
2886 * first plane. That's incorrect for the CCS AUX plane of the first
2887 * plane, but for the above check to pass we must define the block
2888 * width with that subsampling applied to it. Adjust the width here
2889 * accordingly, so we can calculate the actual subsampling factor.
2891 if (main_plane
== 0)
2892 *hsub
*= fb
->format
->hsub
;
2897 intel_fb_check_ccs_xy(struct drm_framebuffer
*fb
, int ccs_plane
, int x
, int y
)
2899 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
2902 int tile_width
, tile_height
;
2906 if (!is_ccs_plane(fb
, ccs_plane
))
2909 intel_tile_dims(fb
, ccs_plane
, &tile_width
, &tile_height
);
2910 intel_fb_plane_get_subsampling(&hsub
, &vsub
, fb
, ccs_plane
);
2913 tile_height
*= vsub
;
2915 ccs_x
= (x
* hsub
) % tile_width
;
2916 ccs_y
= (y
* vsub
) % tile_height
;
2918 main_plane
= ccs_to_main_plane(fb
, ccs_plane
);
2919 main_x
= intel_fb
->normal
[main_plane
].x
% tile_width
;
2920 main_y
= intel_fb
->normal
[main_plane
].y
% tile_height
;
2923 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2924 * x/y offsets must match between CCS and the main surface.
2926 if (main_x
!= ccs_x
|| main_y
!= ccs_y
) {
2927 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2930 intel_fb
->normal
[main_plane
].x
,
2931 intel_fb
->normal
[main_plane
].y
,
2940 intel_fb_plane_dims(int *w
, int *h
, struct drm_framebuffer
*fb
, int color_plane
)
2942 int main_plane
= is_ccs_plane(fb
, color_plane
) ?
2943 ccs_to_main_plane(fb
, color_plane
) : 0;
2944 int main_hsub
, main_vsub
;
2947 intel_fb_plane_get_subsampling(&main_hsub
, &main_vsub
, fb
, main_plane
);
2948 intel_fb_plane_get_subsampling(&hsub
, &vsub
, fb
, color_plane
);
2949 *w
= fb
->width
/ main_hsub
/ hsub
;
2950 *h
= fb
->height
/ main_vsub
/ vsub
;
2954 * Setup the rotated view for an FB plane and return the size the GTT mapping
2955 * requires for this view.
2958 setup_fb_rotation(int plane
, const struct intel_remapped_plane_info
*plane_info
,
2959 u32 gtt_offset_rotated
, int x
, int y
,
2960 unsigned int width
, unsigned int height
,
2961 unsigned int tile_size
,
2962 unsigned int tile_width
, unsigned int tile_height
,
2963 struct drm_framebuffer
*fb
)
2965 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
2966 struct intel_rotation_info
*rot_info
= &intel_fb
->rot_info
;
2967 unsigned int pitch_tiles
;
2970 /* Y or Yf modifiers required for 90/270 rotation */
2971 if (fb
->modifier
!= I915_FORMAT_MOD_Y_TILED
&&
2972 fb
->modifier
!= I915_FORMAT_MOD_Yf_TILED
)
2975 if (WARN_ON(plane
>= ARRAY_SIZE(rot_info
->plane
)))
2978 rot_info
->plane
[plane
] = *plane_info
;
2980 intel_fb
->rotated
[plane
].pitch
= plane_info
->height
* tile_height
;
2982 /* rotate the x/y offsets to match the GTT view */
2983 drm_rect_init(&r
, x
, y
, width
, height
);
2985 plane_info
->width
* tile_width
,
2986 plane_info
->height
* tile_height
,
2987 DRM_MODE_ROTATE_270
);
2991 /* rotate the tile dimensions to match the GTT view */
2992 pitch_tiles
= intel_fb
->rotated
[plane
].pitch
/ tile_height
;
2993 swap(tile_width
, tile_height
);
2996 * We only keep the x/y offsets, so push all of the
2997 * gtt offset into the x/y offsets.
2999 intel_adjust_tile_offset(&x
, &y
,
3000 tile_width
, tile_height
,
3001 tile_size
, pitch_tiles
,
3002 gtt_offset_rotated
* tile_size
, 0);
3005 * First pixel of the framebuffer from
3006 * the start of the rotated gtt mapping.
3008 intel_fb
->rotated
[plane
].x
= x
;
3009 intel_fb
->rotated
[plane
].y
= y
;
3011 return plane_info
->width
* plane_info
->height
;
3015 intel_fill_fb_info(struct drm_i915_private
*dev_priv
,
3016 struct drm_framebuffer
*fb
)
3018 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
3019 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
3020 u32 gtt_offset_rotated
= 0;
3021 unsigned int max_size
= 0;
3022 int i
, num_planes
= fb
->format
->num_planes
;
3023 unsigned int tile_size
= intel_tile_size(dev_priv
);
3025 for (i
= 0; i
< num_planes
; i
++) {
3026 unsigned int width
, height
;
3027 unsigned int cpp
, size
;
3032 cpp
= fb
->format
->cpp
[i
];
3033 intel_fb_plane_dims(&width
, &height
, fb
, i
);
3035 ret
= intel_fb_offset_to_xy(&x
, &y
, fb
, i
);
3037 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
3042 ret
= intel_fb_check_ccs_xy(fb
, i
, x
, y
);
3047 * The fence (if used) is aligned to the start of the object
3048 * so having the framebuffer wrap around across the edge of the
3049 * fenced region doesn't really work. We have no API to configure
3050 * the fence start offset within the object (nor could we probably
3051 * on gen2/3). So it's just easier if we just require that the
3052 * fb layout agrees with the fence layout. We already check that the
3053 * fb stride matches the fence stride elsewhere.
3055 if (i
== 0 && i915_gem_object_is_tiled(obj
) &&
3056 (x
+ width
) * cpp
> fb
->pitches
[i
]) {
3057 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
3063 * First pixel of the framebuffer from
3064 * the start of the normal gtt mapping.
3066 intel_fb
->normal
[i
].x
= x
;
3067 intel_fb
->normal
[i
].y
= y
;
3069 offset
= intel_compute_aligned_offset(dev_priv
, &x
, &y
, fb
, i
,
3073 offset
/= tile_size
;
3075 if (!is_surface_linear(fb
, i
)) {
3076 struct intel_remapped_plane_info plane_info
;
3077 unsigned int tile_width
, tile_height
;
3079 intel_tile_dims(fb
, i
, &tile_width
, &tile_height
);
3081 plane_info
.offset
= offset
;
3082 plane_info
.stride
= DIV_ROUND_UP(fb
->pitches
[i
],
3084 plane_info
.width
= DIV_ROUND_UP(x
+ width
, tile_width
);
3085 plane_info
.height
= DIV_ROUND_UP(y
+ height
,
3088 /* how many tiles does this plane need */
3089 size
= plane_info
.stride
* plane_info
.height
;
3091 * If the plane isn't horizontally tile aligned,
3092 * we need one more tile.
3097 gtt_offset_rotated
+=
3098 setup_fb_rotation(i
, &plane_info
,
3100 x
, y
, width
, height
,
3102 tile_width
, tile_height
,
3105 size
= DIV_ROUND_UP((y
+ height
) * fb
->pitches
[i
] +
3106 x
* cpp
, tile_size
);
3109 /* how many tiles in total needed in the bo */
3110 max_size
= max(max_size
, offset
+ size
);
3113 if (mul_u32_u32(max_size
, tile_size
) > obj
->base
.size
) {
3114 DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n",
3115 mul_u32_u32(max_size
, tile_size
), obj
->base
.size
);
3123 intel_plane_remap_gtt(struct intel_plane_state
*plane_state
)
3125 struct drm_i915_private
*dev_priv
=
3126 to_i915(plane_state
->uapi
.plane
->dev
);
3127 struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
3128 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
3129 struct intel_rotation_info
*info
= &plane_state
->view
.rotated
;
3130 unsigned int rotation
= plane_state
->hw
.rotation
;
3131 int i
, num_planes
= fb
->format
->num_planes
;
3132 unsigned int tile_size
= intel_tile_size(dev_priv
);
3133 unsigned int src_x
, src_y
;
3134 unsigned int src_w
, src_h
;
3137 memset(&plane_state
->view
, 0, sizeof(plane_state
->view
));
3138 plane_state
->view
.type
= drm_rotation_90_or_270(rotation
) ?
3139 I915_GGTT_VIEW_ROTATED
: I915_GGTT_VIEW_REMAPPED
;
3141 src_x
= plane_state
->uapi
.src
.x1
>> 16;
3142 src_y
= plane_state
->uapi
.src
.y1
>> 16;
3143 src_w
= drm_rect_width(&plane_state
->uapi
.src
) >> 16;
3144 src_h
= drm_rect_height(&plane_state
->uapi
.src
) >> 16;
3146 WARN_ON(is_ccs_modifier(fb
->modifier
));
3148 /* Make src coordinates relative to the viewport */
3149 drm_rect_translate(&plane_state
->uapi
.src
,
3150 -(src_x
<< 16), -(src_y
<< 16));
3152 /* Rotate src coordinates to match rotated GTT view */
3153 if (drm_rotation_90_or_270(rotation
))
3154 drm_rect_rotate(&plane_state
->uapi
.src
,
3155 src_w
<< 16, src_h
<< 16,
3156 DRM_MODE_ROTATE_270
);
3158 for (i
= 0; i
< num_planes
; i
++) {
3159 unsigned int hsub
= i
? fb
->format
->hsub
: 1;
3160 unsigned int vsub
= i
? fb
->format
->vsub
: 1;
3161 unsigned int cpp
= fb
->format
->cpp
[i
];
3162 unsigned int tile_width
, tile_height
;
3163 unsigned int width
, height
;
3164 unsigned int pitch_tiles
;
3168 intel_tile_dims(fb
, i
, &tile_width
, &tile_height
);
3172 width
= src_w
/ hsub
;
3173 height
= src_h
/ vsub
;
3176 * First pixel of the src viewport from the
3177 * start of the normal gtt mapping.
3179 x
+= intel_fb
->normal
[i
].x
;
3180 y
+= intel_fb
->normal
[i
].y
;
3182 offset
= intel_compute_aligned_offset(dev_priv
, &x
, &y
,
3183 fb
, i
, fb
->pitches
[i
],
3184 DRM_MODE_ROTATE_0
, tile_size
);
3185 offset
/= tile_size
;
3187 WARN_ON(i
>= ARRAY_SIZE(info
->plane
));
3188 info
->plane
[i
].offset
= offset
;
3189 info
->plane
[i
].stride
= DIV_ROUND_UP(fb
->pitches
[i
],
3191 info
->plane
[i
].width
= DIV_ROUND_UP(x
+ width
, tile_width
);
3192 info
->plane
[i
].height
= DIV_ROUND_UP(y
+ height
, tile_height
);
3194 if (drm_rotation_90_or_270(rotation
)) {
3197 /* rotate the x/y offsets to match the GTT view */
3198 drm_rect_init(&r
, x
, y
, width
, height
);
3200 info
->plane
[i
].width
* tile_width
,
3201 info
->plane
[i
].height
* tile_height
,
3202 DRM_MODE_ROTATE_270
);
3206 pitch_tiles
= info
->plane
[i
].height
;
3207 plane_state
->color_plane
[i
].stride
= pitch_tiles
* tile_height
;
3209 /* rotate the tile dimensions to match the GTT view */
3210 swap(tile_width
, tile_height
);
3212 pitch_tiles
= info
->plane
[i
].width
;
3213 plane_state
->color_plane
[i
].stride
= pitch_tiles
* tile_width
* cpp
;
3217 * We only keep the x/y offsets, so push all of the
3218 * gtt offset into the x/y offsets.
3220 intel_adjust_tile_offset(&x
, &y
,
3221 tile_width
, tile_height
,
3222 tile_size
, pitch_tiles
,
3223 gtt_offset
* tile_size
, 0);
3225 gtt_offset
+= info
->plane
[i
].width
* info
->plane
[i
].height
;
3227 plane_state
->color_plane
[i
].offset
= 0;
3228 plane_state
->color_plane
[i
].x
= x
;
3229 plane_state
->color_plane
[i
].y
= y
;
3234 intel_plane_compute_gtt(struct intel_plane_state
*plane_state
)
3236 const struct intel_framebuffer
*fb
=
3237 to_intel_framebuffer(plane_state
->hw
.fb
);
3238 unsigned int rotation
= plane_state
->hw
.rotation
;
3244 num_planes
= fb
->base
.format
->num_planes
;
3246 if (intel_plane_needs_remap(plane_state
)) {
3247 intel_plane_remap_gtt(plane_state
);
3250 * Sometimes even remapping can't overcome
3251 * the stride limitations :( Can happen with
3252 * big plane sizes and suitably misaligned
3255 return intel_plane_check_stride(plane_state
);
3258 intel_fill_fb_ggtt_view(&plane_state
->view
, &fb
->base
, rotation
);
3260 for (i
= 0; i
< num_planes
; i
++) {
3261 plane_state
->color_plane
[i
].stride
= intel_fb_pitch(&fb
->base
, i
, rotation
);
3262 plane_state
->color_plane
[i
].offset
= 0;
3264 if (drm_rotation_90_or_270(rotation
)) {
3265 plane_state
->color_plane
[i
].x
= fb
->rotated
[i
].x
;
3266 plane_state
->color_plane
[i
].y
= fb
->rotated
[i
].y
;
3268 plane_state
->color_plane
[i
].x
= fb
->normal
[i
].x
;
3269 plane_state
->color_plane
[i
].y
= fb
->normal
[i
].y
;
3273 /* Rotate src coordinates to match rotated GTT view */
3274 if (drm_rotation_90_or_270(rotation
))
3275 drm_rect_rotate(&plane_state
->uapi
.src
,
3276 fb
->base
.width
<< 16, fb
->base
.height
<< 16,
3277 DRM_MODE_ROTATE_270
);
3279 return intel_plane_check_stride(plane_state
);
3282 static int i9xx_format_to_fourcc(int format
)
3285 case DISPPLANE_8BPP
:
3286 return DRM_FORMAT_C8
;
3287 case DISPPLANE_BGRA555
:
3288 return DRM_FORMAT_ARGB1555
;
3289 case DISPPLANE_BGRX555
:
3290 return DRM_FORMAT_XRGB1555
;
3291 case DISPPLANE_BGRX565
:
3292 return DRM_FORMAT_RGB565
;
3294 case DISPPLANE_BGRX888
:
3295 return DRM_FORMAT_XRGB8888
;
3296 case DISPPLANE_RGBX888
:
3297 return DRM_FORMAT_XBGR8888
;
3298 case DISPPLANE_BGRA888
:
3299 return DRM_FORMAT_ARGB8888
;
3300 case DISPPLANE_RGBA888
:
3301 return DRM_FORMAT_ABGR8888
;
3302 case DISPPLANE_BGRX101010
:
3303 return DRM_FORMAT_XRGB2101010
;
3304 case DISPPLANE_RGBX101010
:
3305 return DRM_FORMAT_XBGR2101010
;
3306 case DISPPLANE_BGRA101010
:
3307 return DRM_FORMAT_ARGB2101010
;
3308 case DISPPLANE_RGBA101010
:
3309 return DRM_FORMAT_ABGR2101010
;
3310 case DISPPLANE_RGBX161616
:
3311 return DRM_FORMAT_XBGR16161616F
;
3315 int skl_format_to_fourcc(int format
, bool rgb_order
, bool alpha
)
3318 case PLANE_CTL_FORMAT_RGB_565
:
3319 return DRM_FORMAT_RGB565
;
3320 case PLANE_CTL_FORMAT_NV12
:
3321 return DRM_FORMAT_NV12
;
3322 case PLANE_CTL_FORMAT_P010
:
3323 return DRM_FORMAT_P010
;
3324 case PLANE_CTL_FORMAT_P012
:
3325 return DRM_FORMAT_P012
;
3326 case PLANE_CTL_FORMAT_P016
:
3327 return DRM_FORMAT_P016
;
3328 case PLANE_CTL_FORMAT_Y210
:
3329 return DRM_FORMAT_Y210
;
3330 case PLANE_CTL_FORMAT_Y212
:
3331 return DRM_FORMAT_Y212
;
3332 case PLANE_CTL_FORMAT_Y216
:
3333 return DRM_FORMAT_Y216
;
3334 case PLANE_CTL_FORMAT_Y410
:
3335 return DRM_FORMAT_XVYU2101010
;
3336 case PLANE_CTL_FORMAT_Y412
:
3337 return DRM_FORMAT_XVYU12_16161616
;
3338 case PLANE_CTL_FORMAT_Y416
:
3339 return DRM_FORMAT_XVYU16161616
;
3341 case PLANE_CTL_FORMAT_XRGB_8888
:
3344 return DRM_FORMAT_ABGR8888
;
3346 return DRM_FORMAT_XBGR8888
;
3349 return DRM_FORMAT_ARGB8888
;
3351 return DRM_FORMAT_XRGB8888
;
3353 case PLANE_CTL_FORMAT_XRGB_2101010
:
3356 return DRM_FORMAT_ABGR2101010
;
3358 return DRM_FORMAT_XBGR2101010
;
3361 return DRM_FORMAT_ARGB2101010
;
3363 return DRM_FORMAT_XRGB2101010
;
3365 case PLANE_CTL_FORMAT_XRGB_16161616F
:
3368 return DRM_FORMAT_ABGR16161616F
;
3370 return DRM_FORMAT_XBGR16161616F
;
3373 return DRM_FORMAT_ARGB16161616F
;
3375 return DRM_FORMAT_XRGB16161616F
;
3381 intel_alloc_initial_plane_obj(struct intel_crtc
*crtc
,
3382 struct intel_initial_plane_config
*plane_config
)
3384 struct drm_device
*dev
= crtc
->base
.dev
;
3385 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3386 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
3387 struct drm_framebuffer
*fb
= &plane_config
->fb
->base
;
3388 u32 base_aligned
= round_down(plane_config
->base
, PAGE_SIZE
);
3389 u32 size_aligned
= round_up(plane_config
->base
+ plane_config
->size
,
3391 struct drm_i915_gem_object
*obj
;
3394 size_aligned
-= base_aligned
;
3396 if (plane_config
->size
== 0)
3399 /* If the FB is too big, just don't use it since fbdev is not very
3400 * important and we should probably use that space with FBC or other
3402 if (size_aligned
* 2 > dev_priv
->stolen_usable_size
)
3405 switch (fb
->modifier
) {
3406 case DRM_FORMAT_MOD_LINEAR
:
3407 case I915_FORMAT_MOD_X_TILED
:
3408 case I915_FORMAT_MOD_Y_TILED
:
3411 DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n",
3416 obj
= i915_gem_object_create_stolen_for_preallocated(dev_priv
,
3423 switch (plane_config
->tiling
) {
3424 case I915_TILING_NONE
:
3428 obj
->tiling_and_stride
= fb
->pitches
[0] | plane_config
->tiling
;
3431 MISSING_CASE(plane_config
->tiling
);
3435 mode_cmd
.pixel_format
= fb
->format
->format
;
3436 mode_cmd
.width
= fb
->width
;
3437 mode_cmd
.height
= fb
->height
;
3438 mode_cmd
.pitches
[0] = fb
->pitches
[0];
3439 mode_cmd
.modifier
[0] = fb
->modifier
;
3440 mode_cmd
.flags
= DRM_MODE_FB_MODIFIERS
;
3442 if (intel_framebuffer_init(to_intel_framebuffer(fb
), obj
, &mode_cmd
)) {
3443 DRM_DEBUG_KMS("intel fb init failed\n");
3448 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj
);
3451 i915_gem_object_put(obj
);
3456 intel_set_plane_visible(struct intel_crtc_state
*crtc_state
,
3457 struct intel_plane_state
*plane_state
,
3460 struct intel_plane
*plane
= to_intel_plane(plane_state
->uapi
.plane
);
3462 plane_state
->uapi
.visible
= visible
;
3465 crtc_state
->uapi
.plane_mask
|= drm_plane_mask(&plane
->base
);
3467 crtc_state
->uapi
.plane_mask
&= ~drm_plane_mask(&plane
->base
);
3470 static void fixup_active_planes(struct intel_crtc_state
*crtc_state
)
3472 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->uapi
.crtc
->dev
);
3473 struct drm_plane
*plane
;
3476 * Active_planes aliases if multiple "primary" or cursor planes
3477 * have been used on the same (or wrong) pipe. plane_mask uses
3478 * unique ids, hence we can use that to reconstruct active_planes.
3480 crtc_state
->active_planes
= 0;
3482 drm_for_each_plane_mask(plane
, &dev_priv
->drm
,
3483 crtc_state
->uapi
.plane_mask
)
3484 crtc_state
->active_planes
|= BIT(to_intel_plane(plane
)->id
);
3487 static void intel_plane_disable_noatomic(struct intel_crtc
*crtc
,
3488 struct intel_plane
*plane
)
3490 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
3491 struct intel_crtc_state
*crtc_state
=
3492 to_intel_crtc_state(crtc
->base
.state
);
3493 struct intel_plane_state
*plane_state
=
3494 to_intel_plane_state(plane
->base
.state
);
3496 DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
3497 plane
->base
.base
.id
, plane
->base
.name
,
3498 crtc
->base
.base
.id
, crtc
->base
.name
);
3500 intel_set_plane_visible(crtc_state
, plane_state
, false);
3501 fixup_active_planes(crtc_state
);
3502 crtc_state
->data_rate
[plane
->id
] = 0;
3503 crtc_state
->min_cdclk
[plane
->id
] = 0;
3505 if (plane
->id
== PLANE_PRIMARY
)
3506 hsw_disable_ips(crtc_state
);
3509 * Vblank time updates from the shadow to live plane control register
3510 * are blocked if the memory self-refresh mode is active at that
3511 * moment. So to make sure the plane gets truly disabled, disable
3512 * first the self-refresh mode. The self-refresh enable bit in turn
3513 * will be checked/applied by the HW only at the next frame start
3514 * event which is after the vblank start event, so we need to have a
3515 * wait-for-vblank between disabling the plane and the pipe.
3517 if (HAS_GMCH(dev_priv
) &&
3518 intel_set_memory_cxsr(dev_priv
, false))
3519 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
3522 * Gen2 reports pipe underruns whenever all planes are disabled.
3523 * So disable underrun reporting before all the planes get disabled.
3525 if (IS_GEN(dev_priv
, 2) && !crtc_state
->active_planes
)
3526 intel_set_cpu_fifo_underrun_reporting(dev_priv
, crtc
->pipe
, false);
3528 intel_disable_plane(plane
, crtc_state
);
3531 static struct intel_frontbuffer
*
3532 to_intel_frontbuffer(struct drm_framebuffer
*fb
)
3534 return fb
? to_intel_framebuffer(fb
)->frontbuffer
: NULL
;
3538 intel_find_initial_plane_obj(struct intel_crtc
*intel_crtc
,
3539 struct intel_initial_plane_config
*plane_config
)
3541 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3542 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3544 struct drm_plane
*primary
= intel_crtc
->base
.primary
;
3545 struct drm_plane_state
*plane_state
= primary
->state
;
3546 struct intel_plane
*intel_plane
= to_intel_plane(primary
);
3547 struct intel_plane_state
*intel_state
=
3548 to_intel_plane_state(plane_state
);
3549 struct drm_framebuffer
*fb
;
3551 if (!plane_config
->fb
)
3554 if (intel_alloc_initial_plane_obj(intel_crtc
, plane_config
)) {
3555 fb
= &plane_config
->fb
->base
;
3559 kfree(plane_config
->fb
);
3562 * Failed to alloc the obj, check to see if we should share
3563 * an fb with another CRTC instead
3565 for_each_crtc(dev
, c
) {
3566 struct intel_plane_state
*state
;
3568 if (c
== &intel_crtc
->base
)
3571 if (!to_intel_crtc(c
)->active
)
3574 state
= to_intel_plane_state(c
->primary
->state
);
3578 if (intel_plane_ggtt_offset(state
) == plane_config
->base
) {
3580 drm_framebuffer_get(fb
);
3586 * We've failed to reconstruct the BIOS FB. Current display state
3587 * indicates that the primary plane is visible, but has a NULL FB,
3588 * which will lead to problems later if we don't fix it up. The
3589 * simplest solution is to just disable the primary plane now and
3590 * pretend the BIOS never had it enabled.
3592 intel_plane_disable_noatomic(intel_crtc
, intel_plane
);
3597 intel_state
->hw
.rotation
= plane_config
->rotation
;
3598 intel_fill_fb_ggtt_view(&intel_state
->view
, fb
,
3599 intel_state
->hw
.rotation
);
3600 intel_state
->color_plane
[0].stride
=
3601 intel_fb_pitch(fb
, 0, intel_state
->hw
.rotation
);
3604 intel_pin_and_fence_fb_obj(fb
,
3606 intel_plane_uses_fence(intel_state
),
3607 &intel_state
->flags
);
3608 if (IS_ERR(intel_state
->vma
)) {
3609 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
3610 intel_crtc
->pipe
, PTR_ERR(intel_state
->vma
));
3612 intel_state
->vma
= NULL
;
3613 drm_framebuffer_put(fb
);
3617 intel_frontbuffer_flush(to_intel_frontbuffer(fb
), ORIGIN_DIRTYFB
);
3619 plane_state
->src_x
= 0;
3620 plane_state
->src_y
= 0;
3621 plane_state
->src_w
= fb
->width
<< 16;
3622 plane_state
->src_h
= fb
->height
<< 16;
3624 plane_state
->crtc_x
= 0;
3625 plane_state
->crtc_y
= 0;
3626 plane_state
->crtc_w
= fb
->width
;
3627 plane_state
->crtc_h
= fb
->height
;
3629 intel_state
->uapi
.src
= drm_plane_state_src(plane_state
);
3630 intel_state
->uapi
.dst
= drm_plane_state_dest(plane_state
);
3632 if (plane_config
->tiling
)
3633 dev_priv
->preserve_bios_swizzle
= true;
3635 plane_state
->fb
= fb
;
3636 plane_state
->crtc
= &intel_crtc
->base
;
3637 intel_plane_copy_uapi_to_hw_state(intel_state
, intel_state
);
3639 atomic_or(to_intel_plane(primary
)->frontbuffer_bit
,
3640 &to_intel_frontbuffer(fb
)->bits
);
3643 static int skl_max_plane_width(const struct drm_framebuffer
*fb
,
3645 unsigned int rotation
)
3647 int cpp
= fb
->format
->cpp
[color_plane
];
3649 switch (fb
->modifier
) {
3650 case DRM_FORMAT_MOD_LINEAR
:
3651 case I915_FORMAT_MOD_X_TILED
:
3653 * Validated limit is 4k, but has 5k should
3654 * work apart from the following features:
3655 * - Ytile (already limited to 4k)
3656 * - FP16 (already limited to 4k)
3657 * - render compression (already limited to 4k)
3658 * - KVMR sprite and cursor (don't care)
3659 * - horizontal panning (TODO verify this)
3660 * - pipe and plane scaling (TODO verify this)
3666 case I915_FORMAT_MOD_Y_TILED_CCS
:
3667 case I915_FORMAT_MOD_Yf_TILED_CCS
:
3668 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS
:
3669 /* FIXME AUX plane? */
3670 case I915_FORMAT_MOD_Y_TILED
:
3671 case I915_FORMAT_MOD_Yf_TILED
:
3677 MISSING_CASE(fb
->modifier
);
3682 static int glk_max_plane_width(const struct drm_framebuffer
*fb
,
3684 unsigned int rotation
)
3686 int cpp
= fb
->format
->cpp
[color_plane
];
3688 switch (fb
->modifier
) {
3689 case DRM_FORMAT_MOD_LINEAR
:
3690 case I915_FORMAT_MOD_X_TILED
:
3695 case I915_FORMAT_MOD_Y_TILED_CCS
:
3696 case I915_FORMAT_MOD_Yf_TILED_CCS
:
3697 /* FIXME AUX plane? */
3698 case I915_FORMAT_MOD_Y_TILED
:
3699 case I915_FORMAT_MOD_Yf_TILED
:
3705 MISSING_CASE(fb
->modifier
);
3710 static int icl_max_plane_width(const struct drm_framebuffer
*fb
,
3712 unsigned int rotation
)
3717 static int skl_max_plane_height(void)
3722 static int icl_max_plane_height(void)
3728 skl_check_main_ccs_coordinates(struct intel_plane_state
*plane_state
,
3729 int main_x
, int main_y
, u32 main_offset
,
3732 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
3733 int aux_x
= plane_state
->color_plane
[ccs_plane
].x
;
3734 int aux_y
= plane_state
->color_plane
[ccs_plane
].y
;
3735 u32 aux_offset
= plane_state
->color_plane
[ccs_plane
].offset
;
3736 u32 alignment
= intel_surf_alignment(fb
, ccs_plane
);
3740 intel_fb_plane_get_subsampling(&hsub
, &vsub
, fb
, ccs_plane
);
3741 while (aux_offset
>= main_offset
&& aux_y
<= main_y
) {
3744 if (aux_x
== main_x
&& aux_y
== main_y
)
3747 if (aux_offset
== 0)
3752 aux_offset
= intel_plane_adjust_aligned_offset(&x
, &y
,
3758 aux_x
= x
* hsub
+ aux_x
% hsub
;
3759 aux_y
= y
* vsub
+ aux_y
% vsub
;
3762 if (aux_x
!= main_x
|| aux_y
!= main_y
)
3765 plane_state
->color_plane
[ccs_plane
].offset
= aux_offset
;
3766 plane_state
->color_plane
[ccs_plane
].x
= aux_x
;
3767 plane_state
->color_plane
[ccs_plane
].y
= aux_y
;
3772 static int skl_check_main_surface(struct intel_plane_state
*plane_state
)
3774 struct drm_i915_private
*dev_priv
= to_i915(plane_state
->uapi
.plane
->dev
);
3775 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
3776 unsigned int rotation
= plane_state
->hw
.rotation
;
3777 int x
= plane_state
->uapi
.src
.x1
>> 16;
3778 int y
= plane_state
->uapi
.src
.y1
>> 16;
3779 int w
= drm_rect_width(&plane_state
->uapi
.src
) >> 16;
3780 int h
= drm_rect_height(&plane_state
->uapi
.src
) >> 16;
3785 int aux_plane
= intel_main_to_aux_plane(fb
, 0);
3786 u32 aux_offset
= plane_state
->color_plane
[aux_plane
].offset
;
3788 if (INTEL_GEN(dev_priv
) >= 11)
3789 max_width
= icl_max_plane_width(fb
, 0, rotation
);
3790 else if (INTEL_GEN(dev_priv
) >= 10 || IS_GEMINILAKE(dev_priv
))
3791 max_width
= glk_max_plane_width(fb
, 0, rotation
);
3793 max_width
= skl_max_plane_width(fb
, 0, rotation
);
3795 if (INTEL_GEN(dev_priv
) >= 11)
3796 max_height
= icl_max_plane_height();
3798 max_height
= skl_max_plane_height();
3800 if (w
> max_width
|| h
> max_height
) {
3801 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
3802 w
, h
, max_width
, max_height
);
3806 intel_add_fb_offsets(&x
, &y
, plane_state
, 0);
3807 offset
= intel_plane_compute_aligned_offset(&x
, &y
, plane_state
, 0);
3808 alignment
= intel_surf_alignment(fb
, 0);
3809 if (WARN_ON(alignment
&& !is_power_of_2(alignment
)))
3813 * AUX surface offset is specified as the distance from the
3814 * main surface offset, and it must be non-negative. Make
3815 * sure that is what we will get.
3817 if (offset
> aux_offset
)
3818 offset
= intel_plane_adjust_aligned_offset(&x
, &y
, plane_state
, 0,
3819 offset
, aux_offset
& ~(alignment
- 1));
3822 * When using an X-tiled surface, the plane blows up
3823 * if the x offset + width exceed the stride.
3825 * TODO: linear and Y-tiled seem fine, Yf untested,
3827 if (fb
->modifier
== I915_FORMAT_MOD_X_TILED
) {
3828 int cpp
= fb
->format
->cpp
[0];
3830 while ((x
+ w
) * cpp
> plane_state
->color_plane
[0].stride
) {
3832 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
3836 offset
= intel_plane_adjust_aligned_offset(&x
, &y
, plane_state
, 0,
3837 offset
, offset
- alignment
);
3842 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3843 * they match with the main surface x/y offsets.
3845 if (is_ccs_modifier(fb
->modifier
)) {
3846 while (!skl_check_main_ccs_coordinates(plane_state
, x
, y
,
3847 offset
, aux_plane
)) {
3851 offset
= intel_plane_adjust_aligned_offset(&x
, &y
, plane_state
, 0,
3852 offset
, offset
- alignment
);
3855 if (x
!= plane_state
->color_plane
[aux_plane
].x
||
3856 y
!= plane_state
->color_plane
[aux_plane
].y
) {
3857 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3862 plane_state
->color_plane
[0].offset
= offset
;
3863 plane_state
->color_plane
[0].x
= x
;
3864 plane_state
->color_plane
[0].y
= y
;
3867 * Put the final coordinates back so that the src
3868 * coordinate checks will see the right values.
3870 drm_rect_translate_to(&plane_state
->uapi
.src
,
3876 static int skl_check_nv12_aux_surface(struct intel_plane_state
*plane_state
)
3878 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
3879 unsigned int rotation
= plane_state
->hw
.rotation
;
3881 int max_width
= skl_max_plane_width(fb
, uv_plane
, rotation
);
3882 int max_height
= 4096;
3883 int x
= plane_state
->uapi
.src
.x1
>> 17;
3884 int y
= plane_state
->uapi
.src
.y1
>> 17;
3885 int w
= drm_rect_width(&plane_state
->uapi
.src
) >> 17;
3886 int h
= drm_rect_height(&plane_state
->uapi
.src
) >> 17;
3889 intel_add_fb_offsets(&x
, &y
, plane_state
, uv_plane
);
3890 offset
= intel_plane_compute_aligned_offset(&x
, &y
,
3891 plane_state
, uv_plane
);
3893 /* FIXME not quite sure how/if these apply to the chroma plane */
3894 if (w
> max_width
|| h
> max_height
) {
3895 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3896 w
, h
, max_width
, max_height
);
3900 if (is_ccs_modifier(fb
->modifier
)) {
3901 int ccs_plane
= main_to_ccs_plane(fb
, uv_plane
);
3902 int aux_offset
= plane_state
->color_plane
[ccs_plane
].offset
;
3903 int alignment
= intel_surf_alignment(fb
, uv_plane
);
3905 if (offset
> aux_offset
)
3906 offset
= intel_plane_adjust_aligned_offset(&x
, &y
,
3910 aux_offset
& ~(alignment
- 1));
3912 while (!skl_check_main_ccs_coordinates(plane_state
, x
, y
,
3913 offset
, ccs_plane
)) {
3917 offset
= intel_plane_adjust_aligned_offset(&x
, &y
,
3920 offset
, offset
- alignment
);
3923 if (x
!= plane_state
->color_plane
[ccs_plane
].x
||
3924 y
!= plane_state
->color_plane
[ccs_plane
].y
) {
3925 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3930 plane_state
->color_plane
[uv_plane
].offset
= offset
;
3931 plane_state
->color_plane
[uv_plane
].x
= x
;
3932 plane_state
->color_plane
[uv_plane
].y
= y
;
3937 static int skl_check_ccs_aux_surface(struct intel_plane_state
*plane_state
)
3939 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
3940 int src_x
= plane_state
->uapi
.src
.x1
>> 16;
3941 int src_y
= plane_state
->uapi
.src
.y1
>> 16;
3945 for (ccs_plane
= 0; ccs_plane
< fb
->format
->num_planes
; ccs_plane
++) {
3946 int main_hsub
, main_vsub
;
3950 if (!is_ccs_plane(fb
, ccs_plane
))
3953 intel_fb_plane_get_subsampling(&main_hsub
, &main_vsub
, fb
,
3954 ccs_to_main_plane(fb
, ccs_plane
));
3955 intel_fb_plane_get_subsampling(&hsub
, &vsub
, fb
, ccs_plane
);
3962 intel_add_fb_offsets(&x
, &y
, plane_state
, ccs_plane
);
3964 offset
= intel_plane_compute_aligned_offset(&x
, &y
,
3968 plane_state
->color_plane
[ccs_plane
].offset
= offset
;
3969 plane_state
->color_plane
[ccs_plane
].x
= (x
* hsub
+
3972 plane_state
->color_plane
[ccs_plane
].y
= (y
* vsub
+
3980 int skl_check_plane_surface(struct intel_plane_state
*plane_state
)
3982 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
3984 bool needs_aux
= false;
3986 ret
= intel_plane_compute_gtt(plane_state
);
3990 if (!plane_state
->uapi
.visible
)
3994 * Handle the AUX surface first since the main surface setup depends on
3997 if (is_ccs_modifier(fb
->modifier
)) {
3999 ret
= skl_check_ccs_aux_surface(plane_state
);
4004 if (intel_format_info_is_yuv_semiplanar(fb
->format
,
4007 ret
= skl_check_nv12_aux_surface(plane_state
);
4015 for (i
= 1; i
< fb
->format
->num_planes
; i
++) {
4016 plane_state
->color_plane
[i
].offset
= ~0xfff;
4017 plane_state
->color_plane
[i
].x
= 0;
4018 plane_state
->color_plane
[i
].y
= 0;
4022 ret
= skl_check_main_surface(plane_state
);
4029 static void i9xx_plane_ratio(const struct intel_crtc_state
*crtc_state
,
4030 const struct intel_plane_state
*plane_state
,
4031 unsigned int *num
, unsigned int *den
)
4033 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
4034 unsigned int cpp
= fb
->format
->cpp
[0];
4037 * g4x bspec says 64bpp pixel rate can't exceed 80%
4038 * of cdclk when the sprite plane is enabled on the
4039 * same pipe. ilk/snb bspec says 64bpp pixel rate is
4040 * never allowed to exceed 80% of cdclk. Let's just go
4041 * with the ilk/snb limit always.
4052 static int i9xx_plane_min_cdclk(const struct intel_crtc_state
*crtc_state
,
4053 const struct intel_plane_state
*plane_state
)
4055 unsigned int pixel_rate
;
4056 unsigned int num
, den
;
4059 * Note that crtc_state->pixel_rate accounts for both
4060 * horizontal and vertical panel fitter downscaling factors.
4061 * Pre-HSW bspec tells us to only consider the horizontal
4062 * downscaling factor here. We ignore that and just consider
4063 * both for simplicity.
4065 pixel_rate
= crtc_state
->pixel_rate
;
4067 i9xx_plane_ratio(crtc_state
, plane_state
, &num
, &den
);
4069 /* two pixels per clock with double wide pipe */
4070 if (crtc_state
->double_wide
)
4073 return DIV_ROUND_UP(pixel_rate
* num
, den
);
4077 i9xx_plane_max_stride(struct intel_plane
*plane
,
4078 u32 pixel_format
, u64 modifier
,
4079 unsigned int rotation
)
4081 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
4083 if (!HAS_GMCH(dev_priv
)) {
4085 } else if (INTEL_GEN(dev_priv
) >= 4) {
4086 if (modifier
== I915_FORMAT_MOD_X_TILED
)
4090 } else if (INTEL_GEN(dev_priv
) >= 3) {
4091 if (modifier
== I915_FORMAT_MOD_X_TILED
)
4096 if (plane
->i9xx_plane
== PLANE_C
)
4103 static u32
i9xx_plane_ctl_crtc(const struct intel_crtc_state
*crtc_state
)
4105 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
4106 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
4109 if (crtc_state
->gamma_enable
)
4110 dspcntr
|= DISPPLANE_GAMMA_ENABLE
;
4112 if (crtc_state
->csc_enable
)
4113 dspcntr
|= DISPPLANE_PIPE_CSC_ENABLE
;
4115 if (INTEL_GEN(dev_priv
) < 5)
4116 dspcntr
|= DISPPLANE_SEL_PIPE(crtc
->pipe
);
4121 static u32
i9xx_plane_ctl(const struct intel_crtc_state
*crtc_state
,
4122 const struct intel_plane_state
*plane_state
)
4124 struct drm_i915_private
*dev_priv
=
4125 to_i915(plane_state
->uapi
.plane
->dev
);
4126 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
4127 unsigned int rotation
= plane_state
->hw
.rotation
;
4130 dspcntr
= DISPLAY_PLANE_ENABLE
;
4132 if (IS_G4X(dev_priv
) || IS_GEN(dev_priv
, 5) ||
4133 IS_GEN(dev_priv
, 6) || IS_IVYBRIDGE(dev_priv
))
4134 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
4136 switch (fb
->format
->format
) {
4138 dspcntr
|= DISPPLANE_8BPP
;
4140 case DRM_FORMAT_XRGB1555
:
4141 dspcntr
|= DISPPLANE_BGRX555
;
4143 case DRM_FORMAT_ARGB1555
:
4144 dspcntr
|= DISPPLANE_BGRA555
;
4146 case DRM_FORMAT_RGB565
:
4147 dspcntr
|= DISPPLANE_BGRX565
;
4149 case DRM_FORMAT_XRGB8888
:
4150 dspcntr
|= DISPPLANE_BGRX888
;
4152 case DRM_FORMAT_XBGR8888
:
4153 dspcntr
|= DISPPLANE_RGBX888
;
4155 case DRM_FORMAT_ARGB8888
:
4156 dspcntr
|= DISPPLANE_BGRA888
;
4158 case DRM_FORMAT_ABGR8888
:
4159 dspcntr
|= DISPPLANE_RGBA888
;
4161 case DRM_FORMAT_XRGB2101010
:
4162 dspcntr
|= DISPPLANE_BGRX101010
;
4164 case DRM_FORMAT_XBGR2101010
:
4165 dspcntr
|= DISPPLANE_RGBX101010
;
4167 case DRM_FORMAT_ARGB2101010
:
4168 dspcntr
|= DISPPLANE_BGRA101010
;
4170 case DRM_FORMAT_ABGR2101010
:
4171 dspcntr
|= DISPPLANE_RGBA101010
;
4173 case DRM_FORMAT_XBGR16161616F
:
4174 dspcntr
|= DISPPLANE_RGBX161616
;
4177 MISSING_CASE(fb
->format
->format
);
4181 if (INTEL_GEN(dev_priv
) >= 4 &&
4182 fb
->modifier
== I915_FORMAT_MOD_X_TILED
)
4183 dspcntr
|= DISPPLANE_TILED
;
4185 if (rotation
& DRM_MODE_ROTATE_180
)
4186 dspcntr
|= DISPPLANE_ROTATE_180
;
4188 if (rotation
& DRM_MODE_REFLECT_X
)
4189 dspcntr
|= DISPPLANE_MIRROR
;
4194 int i9xx_check_plane_surface(struct intel_plane_state
*plane_state
)
4196 struct drm_i915_private
*dev_priv
=
4197 to_i915(plane_state
->uapi
.plane
->dev
);
4198 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
4199 int src_x
, src_y
, src_w
;
4203 ret
= intel_plane_compute_gtt(plane_state
);
4207 if (!plane_state
->uapi
.visible
)
4210 src_w
= drm_rect_width(&plane_state
->uapi
.src
) >> 16;
4211 src_x
= plane_state
->uapi
.src
.x1
>> 16;
4212 src_y
= plane_state
->uapi
.src
.y1
>> 16;
4214 /* Undocumented hardware limit on i965/g4x/vlv/chv */
4215 if (HAS_GMCH(dev_priv
) && fb
->format
->cpp
[0] == 8 && src_w
> 2048)
4218 intel_add_fb_offsets(&src_x
, &src_y
, plane_state
, 0);
4220 if (INTEL_GEN(dev_priv
) >= 4)
4221 offset
= intel_plane_compute_aligned_offset(&src_x
, &src_y
,
4227 * Put the final coordinates back so that the src
4228 * coordinate checks will see the right values.
4230 drm_rect_translate_to(&plane_state
->uapi
.src
,
4231 src_x
<< 16, src_y
<< 16);
4233 /* HSW/BDW do this automagically in hardware */
4234 if (!IS_HASWELL(dev_priv
) && !IS_BROADWELL(dev_priv
)) {
4235 unsigned int rotation
= plane_state
->hw
.rotation
;
4236 int src_w
= drm_rect_width(&plane_state
->uapi
.src
) >> 16;
4237 int src_h
= drm_rect_height(&plane_state
->uapi
.src
) >> 16;
4239 if (rotation
& DRM_MODE_ROTATE_180
) {
4242 } else if (rotation
& DRM_MODE_REFLECT_X
) {
4247 plane_state
->color_plane
[0].offset
= offset
;
4248 plane_state
->color_plane
[0].x
= src_x
;
4249 plane_state
->color_plane
[0].y
= src_y
;
4254 static bool i9xx_plane_has_windowing(struct intel_plane
*plane
)
4256 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
4257 enum i9xx_plane_id i9xx_plane
= plane
->i9xx_plane
;
4259 if (IS_CHERRYVIEW(dev_priv
))
4260 return i9xx_plane
== PLANE_B
;
4261 else if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
))
4263 else if (IS_GEN(dev_priv
, 4))
4264 return i9xx_plane
== PLANE_C
;
4266 return i9xx_plane
== PLANE_B
||
4267 i9xx_plane
== PLANE_C
;
4271 i9xx_plane_check(struct intel_crtc_state
*crtc_state
,
4272 struct intel_plane_state
*plane_state
)
4274 struct intel_plane
*plane
= to_intel_plane(plane_state
->uapi
.plane
);
4277 ret
= chv_plane_check_rotation(plane_state
);
4281 ret
= drm_atomic_helper_check_plane_state(&plane_state
->uapi
,
4283 DRM_PLANE_HELPER_NO_SCALING
,
4284 DRM_PLANE_HELPER_NO_SCALING
,
4285 i9xx_plane_has_windowing(plane
),
4290 ret
= i9xx_check_plane_surface(plane_state
);
4294 if (!plane_state
->uapi
.visible
)
4297 ret
= intel_plane_check_src_coordinates(plane_state
);
4301 plane_state
->ctl
= i9xx_plane_ctl(crtc_state
, plane_state
);
4306 static void i9xx_update_plane(struct intel_plane
*plane
,
4307 const struct intel_crtc_state
*crtc_state
,
4308 const struct intel_plane_state
*plane_state
)
4310 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
4311 enum i9xx_plane_id i9xx_plane
= plane
->i9xx_plane
;
4313 int x
= plane_state
->color_plane
[0].x
;
4314 int y
= plane_state
->color_plane
[0].y
;
4315 int crtc_x
= plane_state
->uapi
.dst
.x1
;
4316 int crtc_y
= plane_state
->uapi
.dst
.y1
;
4317 int crtc_w
= drm_rect_width(&plane_state
->uapi
.dst
);
4318 int crtc_h
= drm_rect_height(&plane_state
->uapi
.dst
);
4319 unsigned long irqflags
;
4323 dspcntr
= plane_state
->ctl
| i9xx_plane_ctl_crtc(crtc_state
);
4325 linear_offset
= intel_fb_xy_to_linear(x
, y
, plane_state
, 0);
4327 if (INTEL_GEN(dev_priv
) >= 4)
4328 dspaddr_offset
= plane_state
->color_plane
[0].offset
;
4330 dspaddr_offset
= linear_offset
;
4332 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
4334 I915_WRITE_FW(DSPSTRIDE(i9xx_plane
), plane_state
->color_plane
[0].stride
);
4336 if (INTEL_GEN(dev_priv
) < 4) {
4338 * PLANE_A doesn't actually have a full window
4339 * generator but let's assume we still need to
4340 * program whatever is there.
4342 I915_WRITE_FW(DSPPOS(i9xx_plane
), (crtc_y
<< 16) | crtc_x
);
4343 I915_WRITE_FW(DSPSIZE(i9xx_plane
),
4344 ((crtc_h
- 1) << 16) | (crtc_w
- 1));
4345 } else if (IS_CHERRYVIEW(dev_priv
) && i9xx_plane
== PLANE_B
) {
4346 I915_WRITE_FW(PRIMPOS(i9xx_plane
), (crtc_y
<< 16) | crtc_x
);
4347 I915_WRITE_FW(PRIMSIZE(i9xx_plane
),
4348 ((crtc_h
- 1) << 16) | (crtc_w
- 1));
4349 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane
), 0);
4352 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
4353 I915_WRITE_FW(DSPOFFSET(i9xx_plane
), (y
<< 16) | x
);
4354 } else if (INTEL_GEN(dev_priv
) >= 4) {
4355 I915_WRITE_FW(DSPLINOFF(i9xx_plane
), linear_offset
);
4356 I915_WRITE_FW(DSPTILEOFF(i9xx_plane
), (y
<< 16) | x
);
4360 * The control register self-arms if the plane was previously
4361 * disabled. Try to make the plane enable atomic by writing
4362 * the control register just before the surface register.
4364 I915_WRITE_FW(DSPCNTR(i9xx_plane
), dspcntr
);
4365 if (INTEL_GEN(dev_priv
) >= 4)
4366 I915_WRITE_FW(DSPSURF(i9xx_plane
),
4367 intel_plane_ggtt_offset(plane_state
) +
4370 I915_WRITE_FW(DSPADDR(i9xx_plane
),
4371 intel_plane_ggtt_offset(plane_state
) +
4374 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
4377 static void i9xx_disable_plane(struct intel_plane
*plane
,
4378 const struct intel_crtc_state
*crtc_state
)
4380 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
4381 enum i9xx_plane_id i9xx_plane
= plane
->i9xx_plane
;
4382 unsigned long irqflags
;
4386 * DSPCNTR pipe gamma enable on g4x+ and pipe csc
4387 * enable on ilk+ affect the pipe bottom color as
4388 * well, so we must configure them even if the plane
4391 * On pre-g4x there is no way to gamma correct the
4392 * pipe bottom color but we'll keep on doing this
4393 * anyway so that the crtc state readout works correctly.
4395 dspcntr
= i9xx_plane_ctl_crtc(crtc_state
);
4397 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
4399 I915_WRITE_FW(DSPCNTR(i9xx_plane
), dspcntr
);
4400 if (INTEL_GEN(dev_priv
) >= 4)
4401 I915_WRITE_FW(DSPSURF(i9xx_plane
), 0);
4403 I915_WRITE_FW(DSPADDR(i9xx_plane
), 0);
4405 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
4408 static bool i9xx_plane_get_hw_state(struct intel_plane
*plane
,
4411 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
4412 enum intel_display_power_domain power_domain
;
4413 enum i9xx_plane_id i9xx_plane
= plane
->i9xx_plane
;
4414 intel_wakeref_t wakeref
;
4419 * Not 100% correct for planes that can move between pipes,
4420 * but that's only the case for gen2-4 which don't have any
4421 * display power wells.
4423 power_domain
= POWER_DOMAIN_PIPE(plane
->pipe
);
4424 wakeref
= intel_display_power_get_if_enabled(dev_priv
, power_domain
);
4428 val
= I915_READ(DSPCNTR(i9xx_plane
));
4430 ret
= val
& DISPLAY_PLANE_ENABLE
;
4432 if (INTEL_GEN(dev_priv
) >= 5)
4433 *pipe
= plane
->pipe
;
4435 *pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
4436 DISPPLANE_SEL_PIPE_SHIFT
;
4438 intel_display_power_put(dev_priv
, power_domain
, wakeref
);
4443 static void skl_detach_scaler(struct intel_crtc
*intel_crtc
, int id
)
4445 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4446 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4448 I915_WRITE(SKL_PS_CTRL(intel_crtc
->pipe
, id
), 0);
4449 I915_WRITE(SKL_PS_WIN_POS(intel_crtc
->pipe
, id
), 0);
4450 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc
->pipe
, id
), 0);
4454 * This function detaches (aka. unbinds) unused scalers in hardware
4456 static void skl_detach_scalers(const struct intel_crtc_state
*crtc_state
)
4458 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
4459 const struct intel_crtc_scaler_state
*scaler_state
=
4460 &crtc_state
->scaler_state
;
4463 /* loop through and disable scalers that aren't in use */
4464 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
4465 if (!scaler_state
->scalers
[i
].in_use
)
4466 skl_detach_scaler(intel_crtc
, i
);
4470 static unsigned int skl_plane_stride_mult(const struct drm_framebuffer
*fb
,
4471 int color_plane
, unsigned int rotation
)
4474 * The stride is either expressed as a multiple of 64 bytes chunks for
4475 * linear buffers or in number of tiles for tiled buffers.
4477 if (is_surface_linear(fb
, color_plane
))
4479 else if (drm_rotation_90_or_270(rotation
))
4480 return intel_tile_height(fb
, color_plane
);
4482 return intel_tile_width_bytes(fb
, color_plane
);
4485 u32
skl_plane_stride(const struct intel_plane_state
*plane_state
,
4488 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
4489 unsigned int rotation
= plane_state
->hw
.rotation
;
4490 u32 stride
= plane_state
->color_plane
[color_plane
].stride
;
4492 if (color_plane
>= fb
->format
->num_planes
)
4495 return stride
/ skl_plane_stride_mult(fb
, color_plane
, rotation
);
4498 static u32
skl_plane_ctl_format(u32 pixel_format
)
4500 switch (pixel_format
) {
4502 return PLANE_CTL_FORMAT_INDEXED
;
4503 case DRM_FORMAT_RGB565
:
4504 return PLANE_CTL_FORMAT_RGB_565
;
4505 case DRM_FORMAT_XBGR8888
:
4506 case DRM_FORMAT_ABGR8888
:
4507 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
;
4508 case DRM_FORMAT_XRGB8888
:
4509 case DRM_FORMAT_ARGB8888
:
4510 return PLANE_CTL_FORMAT_XRGB_8888
;
4511 case DRM_FORMAT_XBGR2101010
:
4512 case DRM_FORMAT_ABGR2101010
:
4513 return PLANE_CTL_FORMAT_XRGB_2101010
| PLANE_CTL_ORDER_RGBX
;
4514 case DRM_FORMAT_XRGB2101010
:
4515 case DRM_FORMAT_ARGB2101010
:
4516 return PLANE_CTL_FORMAT_XRGB_2101010
;
4517 case DRM_FORMAT_XBGR16161616F
:
4518 case DRM_FORMAT_ABGR16161616F
:
4519 return PLANE_CTL_FORMAT_XRGB_16161616F
| PLANE_CTL_ORDER_RGBX
;
4520 case DRM_FORMAT_XRGB16161616F
:
4521 case DRM_FORMAT_ARGB16161616F
:
4522 return PLANE_CTL_FORMAT_XRGB_16161616F
;
4523 case DRM_FORMAT_YUYV
:
4524 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YUYV
;
4525 case DRM_FORMAT_YVYU
:
4526 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YVYU
;
4527 case DRM_FORMAT_UYVY
:
4528 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_UYVY
;
4529 case DRM_FORMAT_VYUY
:
4530 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_VYUY
;
4531 case DRM_FORMAT_NV12
:
4532 return PLANE_CTL_FORMAT_NV12
;
4533 case DRM_FORMAT_P010
:
4534 return PLANE_CTL_FORMAT_P010
;
4535 case DRM_FORMAT_P012
:
4536 return PLANE_CTL_FORMAT_P012
;
4537 case DRM_FORMAT_P016
:
4538 return PLANE_CTL_FORMAT_P016
;
4539 case DRM_FORMAT_Y210
:
4540 return PLANE_CTL_FORMAT_Y210
;
4541 case DRM_FORMAT_Y212
:
4542 return PLANE_CTL_FORMAT_Y212
;
4543 case DRM_FORMAT_Y216
:
4544 return PLANE_CTL_FORMAT_Y216
;
4545 case DRM_FORMAT_XVYU2101010
:
4546 return PLANE_CTL_FORMAT_Y410
;
4547 case DRM_FORMAT_XVYU12_16161616
:
4548 return PLANE_CTL_FORMAT_Y412
;
4549 case DRM_FORMAT_XVYU16161616
:
4550 return PLANE_CTL_FORMAT_Y416
;
4552 MISSING_CASE(pixel_format
);
4558 static u32
skl_plane_ctl_alpha(const struct intel_plane_state
*plane_state
)
4560 if (!plane_state
->hw
.fb
->format
->has_alpha
)
4561 return PLANE_CTL_ALPHA_DISABLE
;
4563 switch (plane_state
->hw
.pixel_blend_mode
) {
4564 case DRM_MODE_BLEND_PIXEL_NONE
:
4565 return PLANE_CTL_ALPHA_DISABLE
;
4566 case DRM_MODE_BLEND_PREMULTI
:
4567 return PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
4568 case DRM_MODE_BLEND_COVERAGE
:
4569 return PLANE_CTL_ALPHA_HW_PREMULTIPLY
;
4571 MISSING_CASE(plane_state
->hw
.pixel_blend_mode
);
4572 return PLANE_CTL_ALPHA_DISABLE
;
4576 static u32
glk_plane_color_ctl_alpha(const struct intel_plane_state
*plane_state
)
4578 if (!plane_state
->hw
.fb
->format
->has_alpha
)
4579 return PLANE_COLOR_ALPHA_DISABLE
;
4581 switch (plane_state
->hw
.pixel_blend_mode
) {
4582 case DRM_MODE_BLEND_PIXEL_NONE
:
4583 return PLANE_COLOR_ALPHA_DISABLE
;
4584 case DRM_MODE_BLEND_PREMULTI
:
4585 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY
;
4586 case DRM_MODE_BLEND_COVERAGE
:
4587 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY
;
4589 MISSING_CASE(plane_state
->hw
.pixel_blend_mode
);
4590 return PLANE_COLOR_ALPHA_DISABLE
;
4594 static u32
skl_plane_ctl_tiling(u64 fb_modifier
)
4596 switch (fb_modifier
) {
4597 case DRM_FORMAT_MOD_LINEAR
:
4599 case I915_FORMAT_MOD_X_TILED
:
4600 return PLANE_CTL_TILED_X
;
4601 case I915_FORMAT_MOD_Y_TILED
:
4602 return PLANE_CTL_TILED_Y
;
4603 case I915_FORMAT_MOD_Y_TILED_CCS
:
4604 return PLANE_CTL_TILED_Y
| PLANE_CTL_RENDER_DECOMPRESSION_ENABLE
;
4605 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS
:
4606 return PLANE_CTL_TILED_Y
|
4607 PLANE_CTL_RENDER_DECOMPRESSION_ENABLE
|
4608 PLANE_CTL_CLEAR_COLOR_DISABLE
;
4609 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS
:
4610 return PLANE_CTL_TILED_Y
| PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE
;
4611 case I915_FORMAT_MOD_Yf_TILED
:
4612 return PLANE_CTL_TILED_YF
;
4613 case I915_FORMAT_MOD_Yf_TILED_CCS
:
4614 return PLANE_CTL_TILED_YF
| PLANE_CTL_RENDER_DECOMPRESSION_ENABLE
;
4616 MISSING_CASE(fb_modifier
);
4622 static u32
skl_plane_ctl_rotate(unsigned int rotate
)
4625 case DRM_MODE_ROTATE_0
:
4628 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
4629 * while i915 HW rotation is clockwise, thats why this swapping.
4631 case DRM_MODE_ROTATE_90
:
4632 return PLANE_CTL_ROTATE_270
;
4633 case DRM_MODE_ROTATE_180
:
4634 return PLANE_CTL_ROTATE_180
;
4635 case DRM_MODE_ROTATE_270
:
4636 return PLANE_CTL_ROTATE_90
;
4638 MISSING_CASE(rotate
);
4644 static u32
cnl_plane_ctl_flip(unsigned int reflect
)
4649 case DRM_MODE_REFLECT_X
:
4650 return PLANE_CTL_FLIP_HORIZONTAL
;
4651 case DRM_MODE_REFLECT_Y
:
4653 MISSING_CASE(reflect
);
4659 u32
skl_plane_ctl_crtc(const struct intel_crtc_state
*crtc_state
)
4661 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->uapi
.crtc
->dev
);
4664 if (INTEL_GEN(dev_priv
) >= 10 || IS_GEMINILAKE(dev_priv
))
4667 if (crtc_state
->gamma_enable
)
4668 plane_ctl
|= PLANE_CTL_PIPE_GAMMA_ENABLE
;
4670 if (crtc_state
->csc_enable
)
4671 plane_ctl
|= PLANE_CTL_PIPE_CSC_ENABLE
;
4676 u32
skl_plane_ctl(const struct intel_crtc_state
*crtc_state
,
4677 const struct intel_plane_state
*plane_state
)
4679 struct drm_i915_private
*dev_priv
=
4680 to_i915(plane_state
->uapi
.plane
->dev
);
4681 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
4682 unsigned int rotation
= plane_state
->hw
.rotation
;
4683 const struct drm_intel_sprite_colorkey
*key
= &plane_state
->ckey
;
4686 plane_ctl
= PLANE_CTL_ENABLE
;
4688 if (INTEL_GEN(dev_priv
) < 10 && !IS_GEMINILAKE(dev_priv
)) {
4689 plane_ctl
|= skl_plane_ctl_alpha(plane_state
);
4690 plane_ctl
|= PLANE_CTL_PLANE_GAMMA_DISABLE
;
4692 if (plane_state
->hw
.color_encoding
== DRM_COLOR_YCBCR_BT709
)
4693 plane_ctl
|= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709
;
4695 if (plane_state
->hw
.color_range
== DRM_COLOR_YCBCR_FULL_RANGE
)
4696 plane_ctl
|= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE
;
4699 plane_ctl
|= skl_plane_ctl_format(fb
->format
->format
);
4700 plane_ctl
|= skl_plane_ctl_tiling(fb
->modifier
);
4701 plane_ctl
|= skl_plane_ctl_rotate(rotation
& DRM_MODE_ROTATE_MASK
);
4703 if (INTEL_GEN(dev_priv
) >= 10)
4704 plane_ctl
|= cnl_plane_ctl_flip(rotation
&
4705 DRM_MODE_REFLECT_MASK
);
4707 if (key
->flags
& I915_SET_COLORKEY_DESTINATION
)
4708 plane_ctl
|= PLANE_CTL_KEY_ENABLE_DESTINATION
;
4709 else if (key
->flags
& I915_SET_COLORKEY_SOURCE
)
4710 plane_ctl
|= PLANE_CTL_KEY_ENABLE_SOURCE
;
4715 u32
glk_plane_color_ctl_crtc(const struct intel_crtc_state
*crtc_state
)
4717 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->uapi
.crtc
->dev
);
4718 u32 plane_color_ctl
= 0;
4720 if (INTEL_GEN(dev_priv
) >= 11)
4721 return plane_color_ctl
;
4723 if (crtc_state
->gamma_enable
)
4724 plane_color_ctl
|= PLANE_COLOR_PIPE_GAMMA_ENABLE
;
4726 if (crtc_state
->csc_enable
)
4727 plane_color_ctl
|= PLANE_COLOR_PIPE_CSC_ENABLE
;
4729 return plane_color_ctl
;
4732 u32
glk_plane_color_ctl(const struct intel_crtc_state
*crtc_state
,
4733 const struct intel_plane_state
*plane_state
)
4735 struct drm_i915_private
*dev_priv
=
4736 to_i915(plane_state
->uapi
.plane
->dev
);
4737 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
4738 struct intel_plane
*plane
= to_intel_plane(plane_state
->uapi
.plane
);
4739 u32 plane_color_ctl
= 0;
4741 plane_color_ctl
|= PLANE_COLOR_PLANE_GAMMA_DISABLE
;
4742 plane_color_ctl
|= glk_plane_color_ctl_alpha(plane_state
);
4744 if (fb
->format
->is_yuv
&& !icl_is_hdr_plane(dev_priv
, plane
->id
)) {
4745 if (plane_state
->hw
.color_encoding
== DRM_COLOR_YCBCR_BT709
)
4746 plane_color_ctl
|= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709
;
4748 plane_color_ctl
|= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709
;
4750 if (plane_state
->hw
.color_range
== DRM_COLOR_YCBCR_FULL_RANGE
)
4751 plane_color_ctl
|= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE
;
4752 } else if (fb
->format
->is_yuv
) {
4753 plane_color_ctl
|= PLANE_COLOR_INPUT_CSC_ENABLE
;
4756 return plane_color_ctl
;
4760 __intel_display_resume(struct drm_device
*dev
,
4761 struct drm_atomic_state
*state
,
4762 struct drm_modeset_acquire_ctx
*ctx
)
4764 struct drm_crtc_state
*crtc_state
;
4765 struct drm_crtc
*crtc
;
4768 intel_modeset_setup_hw_state(dev
, ctx
);
4769 intel_vga_redisable(to_i915(dev
));
4775 * We've duplicated the state, pointers to the old state are invalid.
4777 * Don't attempt to use the old state until we commit the duplicated state.
4779 for_each_new_crtc_in_state(state
, crtc
, crtc_state
, i
) {
4781 * Force recalculation even if we restore
4782 * current state. With fast modeset this may not result
4783 * in a modeset when the state is compatible.
4785 crtc_state
->mode_changed
= true;
4788 /* ignore any reset values/BIOS leftovers in the WM registers */
4789 if (!HAS_GMCH(to_i915(dev
)))
4790 to_intel_atomic_state(state
)->skip_intermediate_wm
= true;
4792 ret
= drm_atomic_helper_commit_duplicated_state(state
, ctx
);
4794 WARN_ON(ret
== -EDEADLK
);
4798 static bool gpu_reset_clobbers_display(struct drm_i915_private
*dev_priv
)
4800 return (INTEL_INFO(dev_priv
)->gpu_reset_clobbers_display
&&
4801 intel_has_gpu_reset(&dev_priv
->gt
));
4804 void intel_prepare_reset(struct drm_i915_private
*dev_priv
)
4806 struct drm_device
*dev
= &dev_priv
->drm
;
4807 struct drm_modeset_acquire_ctx
*ctx
= &dev_priv
->reset_ctx
;
4808 struct drm_atomic_state
*state
;
4811 /* reset doesn't touch the display */
4812 if (!i915_modparams
.force_reset_modeset_test
&&
4813 !gpu_reset_clobbers_display(dev_priv
))
4816 /* We have a modeset vs reset deadlock, defensively unbreak it. */
4817 set_bit(I915_RESET_MODESET
, &dev_priv
->gt
.reset
.flags
);
4818 smp_mb__after_atomic();
4819 wake_up_bit(&dev_priv
->gt
.reset
.flags
, I915_RESET_MODESET
);
4821 if (atomic_read(&dev_priv
->gpu_error
.pending_fb_pin
)) {
4822 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
4823 intel_gt_set_wedged(&dev_priv
->gt
);
4827 * Need mode_config.mutex so that we don't
4828 * trample ongoing ->detect() and whatnot.
4830 mutex_lock(&dev
->mode_config
.mutex
);
4831 drm_modeset_acquire_init(ctx
, 0);
4833 ret
= drm_modeset_lock_all_ctx(dev
, ctx
);
4834 if (ret
!= -EDEADLK
)
4837 drm_modeset_backoff(ctx
);
4840 * Disabling the crtcs gracefully seems nicer. Also the
4841 * g33 docs say we should at least disable all the planes.
4843 state
= drm_atomic_helper_duplicate_state(dev
, ctx
);
4844 if (IS_ERR(state
)) {
4845 ret
= PTR_ERR(state
);
4846 DRM_ERROR("Duplicating state failed with %i\n", ret
);
4850 ret
= drm_atomic_helper_disable_all(dev
, ctx
);
4852 DRM_ERROR("Suspending crtc's failed with %i\n", ret
);
4853 drm_atomic_state_put(state
);
4857 dev_priv
->modeset_restore_state
= state
;
4858 state
->acquire_ctx
= ctx
;
4861 void intel_finish_reset(struct drm_i915_private
*dev_priv
)
4863 struct drm_device
*dev
= &dev_priv
->drm
;
4864 struct drm_modeset_acquire_ctx
*ctx
= &dev_priv
->reset_ctx
;
4865 struct drm_atomic_state
*state
;
4868 /* reset doesn't touch the display */
4869 if (!test_bit(I915_RESET_MODESET
, &dev_priv
->gt
.reset
.flags
))
4872 state
= fetch_and_zero(&dev_priv
->modeset_restore_state
);
4876 /* reset doesn't touch the display */
4877 if (!gpu_reset_clobbers_display(dev_priv
)) {
4878 /* for testing only restore the display */
4879 ret
= __intel_display_resume(dev
, state
, ctx
);
4881 DRM_ERROR("Restoring old state failed with %i\n", ret
);
4884 * The display has been reset as well,
4885 * so need a full re-initialization.
4887 intel_pps_unlock_regs_wa(dev_priv
);
4888 intel_modeset_init_hw(dev_priv
);
4889 intel_init_clock_gating(dev_priv
);
4891 spin_lock_irq(&dev_priv
->irq_lock
);
4892 if (dev_priv
->display
.hpd_irq_setup
)
4893 dev_priv
->display
.hpd_irq_setup(dev_priv
);
4894 spin_unlock_irq(&dev_priv
->irq_lock
);
4896 ret
= __intel_display_resume(dev
, state
, ctx
);
4898 DRM_ERROR("Restoring old state failed with %i\n", ret
);
4900 intel_hpd_init(dev_priv
);
4903 drm_atomic_state_put(state
);
4905 drm_modeset_drop_locks(ctx
);
4906 drm_modeset_acquire_fini(ctx
);
4907 mutex_unlock(&dev
->mode_config
.mutex
);
4909 clear_bit_unlock(I915_RESET_MODESET
, &dev_priv
->gt
.reset
.flags
);
4912 static void icl_set_pipe_chicken(struct intel_crtc
*crtc
)
4914 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
4915 enum pipe pipe
= crtc
->pipe
;
4918 tmp
= I915_READ(PIPE_CHICKEN(pipe
));
4921 * Display WA #1153: icl
4922 * enable hardware to bypass the alpha math
4923 * and rounding for per-pixel values 00 and 0xff
4925 tmp
|= PER_PIXEL_ALPHA_BYPASS_EN
;
4927 * Display WA # 1605353570: icl
4928 * Set the pixel rounding bit to 1 for allowing
4929 * passthrough of Frame buffer pixels unmodified
4932 tmp
|= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU
;
4933 I915_WRITE(PIPE_CHICKEN(pipe
), tmp
);
4936 static void icl_enable_trans_port_sync(const struct intel_crtc_state
*crtc_state
)
4938 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
4939 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
4940 u32 trans_ddi_func_ctl2_val
;
4944 * Configure the master select and enable Transcoder Port Sync for
4945 * Slave CRTCs transcoder.
4947 if (crtc_state
->master_transcoder
== INVALID_TRANSCODER
)
4950 if (crtc_state
->master_transcoder
== TRANSCODER_EDP
)
4953 master_select
= crtc_state
->master_transcoder
+ 1;
4955 /* Set the master select bits for Tranascoder Port Sync */
4956 trans_ddi_func_ctl2_val
= (PORT_SYNC_MODE_MASTER_SELECT(master_select
) &
4957 PORT_SYNC_MODE_MASTER_SELECT_MASK
) <<
4958 PORT_SYNC_MODE_MASTER_SELECT_SHIFT
;
4959 /* Enable Transcoder Port Sync */
4960 trans_ddi_func_ctl2_val
|= PORT_SYNC_MODE_ENABLE
;
4962 I915_WRITE(TRANS_DDI_FUNC_CTL2(crtc_state
->cpu_transcoder
),
4963 trans_ddi_func_ctl2_val
);
4966 static void intel_fdi_normal_train(struct intel_crtc
*crtc
)
4968 struct drm_device
*dev
= crtc
->base
.dev
;
4969 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4970 enum pipe pipe
= crtc
->pipe
;
4974 /* enable normal train */
4975 reg
= FDI_TX_CTL(pipe
);
4976 temp
= I915_READ(reg
);
4977 if (IS_IVYBRIDGE(dev_priv
)) {
4978 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
4979 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
4981 temp
&= ~FDI_LINK_TRAIN_NONE
;
4982 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
4984 I915_WRITE(reg
, temp
);
4986 reg
= FDI_RX_CTL(pipe
);
4987 temp
= I915_READ(reg
);
4988 if (HAS_PCH_CPT(dev_priv
)) {
4989 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
4990 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
4992 temp
&= ~FDI_LINK_TRAIN_NONE
;
4993 temp
|= FDI_LINK_TRAIN_NONE
;
4995 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
4997 /* wait one idle pattern time */
5001 /* IVB wants error correction enabled */
5002 if (IS_IVYBRIDGE(dev_priv
))
5003 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
5004 FDI_FE_ERRC_ENABLE
);
5007 /* The FDI link training functions for ILK/Ibexpeak. */
5008 static void ilk_fdi_link_train(struct intel_crtc
*crtc
,
5009 const struct intel_crtc_state
*crtc_state
)
5011 struct drm_device
*dev
= crtc
->base
.dev
;
5012 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5013 enum pipe pipe
= crtc
->pipe
;
5017 /* FDI needs bits from pipe first */
5018 assert_pipe_enabled(dev_priv
, crtc_state
->cpu_transcoder
);
5020 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
5022 reg
= FDI_RX_IMR(pipe
);
5023 temp
= I915_READ(reg
);
5024 temp
&= ~FDI_RX_SYMBOL_LOCK
;
5025 temp
&= ~FDI_RX_BIT_LOCK
;
5026 I915_WRITE(reg
, temp
);
5030 /* enable CPU FDI TX and PCH FDI RX */
5031 reg
= FDI_TX_CTL(pipe
);
5032 temp
= I915_READ(reg
);
5033 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
5034 temp
|= FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
5035 temp
&= ~FDI_LINK_TRAIN_NONE
;
5036 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
5037 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
5039 reg
= FDI_RX_CTL(pipe
);
5040 temp
= I915_READ(reg
);
5041 temp
&= ~FDI_LINK_TRAIN_NONE
;
5042 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
5043 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
5048 /* Ironlake workaround, enable clock pointer after FDI enable*/
5049 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
5050 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
5051 FDI_RX_PHASE_SYNC_POINTER_EN
);
5053 reg
= FDI_RX_IIR(pipe
);
5054 for (tries
= 0; tries
< 5; tries
++) {
5055 temp
= I915_READ(reg
);
5056 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
5058 if ((temp
& FDI_RX_BIT_LOCK
)) {
5059 DRM_DEBUG_KMS("FDI train 1 done.\n");
5060 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
5065 DRM_ERROR("FDI train 1 fail!\n");
5068 reg
= FDI_TX_CTL(pipe
);
5069 temp
= I915_READ(reg
);
5070 temp
&= ~FDI_LINK_TRAIN_NONE
;
5071 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
5072 I915_WRITE(reg
, temp
);
5074 reg
= FDI_RX_CTL(pipe
);
5075 temp
= I915_READ(reg
);
5076 temp
&= ~FDI_LINK_TRAIN_NONE
;
5077 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
5078 I915_WRITE(reg
, temp
);
5083 reg
= FDI_RX_IIR(pipe
);
5084 for (tries
= 0; tries
< 5; tries
++) {
5085 temp
= I915_READ(reg
);
5086 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
5088 if (temp
& FDI_RX_SYMBOL_LOCK
) {
5089 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
5090 DRM_DEBUG_KMS("FDI train 2 done.\n");
5095 DRM_ERROR("FDI train 2 fail!\n");
5097 DRM_DEBUG_KMS("FDI train done\n");
5101 static const int snb_b_fdi_train_param
[] = {
5102 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
5103 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
5104 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
5105 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
5108 /* The FDI link training functions for SNB/Cougarpoint. */
5109 static void gen6_fdi_link_train(struct intel_crtc
*crtc
,
5110 const struct intel_crtc_state
*crtc_state
)
5112 struct drm_device
*dev
= crtc
->base
.dev
;
5113 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5114 enum pipe pipe
= crtc
->pipe
;
5118 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
5120 reg
= FDI_RX_IMR(pipe
);
5121 temp
= I915_READ(reg
);
5122 temp
&= ~FDI_RX_SYMBOL_LOCK
;
5123 temp
&= ~FDI_RX_BIT_LOCK
;
5124 I915_WRITE(reg
, temp
);
5129 /* enable CPU FDI TX and PCH FDI RX */
5130 reg
= FDI_TX_CTL(pipe
);
5131 temp
= I915_READ(reg
);
5132 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
5133 temp
|= FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
5134 temp
&= ~FDI_LINK_TRAIN_NONE
;
5135 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
5136 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
5138 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
5139 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
5141 I915_WRITE(FDI_RX_MISC(pipe
),
5142 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
5144 reg
= FDI_RX_CTL(pipe
);
5145 temp
= I915_READ(reg
);
5146 if (HAS_PCH_CPT(dev_priv
)) {
5147 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
5148 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
5150 temp
&= ~FDI_LINK_TRAIN_NONE
;
5151 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
5153 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
5158 for (i
= 0; i
< 4; i
++) {
5159 reg
= FDI_TX_CTL(pipe
);
5160 temp
= I915_READ(reg
);
5161 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
5162 temp
|= snb_b_fdi_train_param
[i
];
5163 I915_WRITE(reg
, temp
);
5168 for (retry
= 0; retry
< 5; retry
++) {
5169 reg
= FDI_RX_IIR(pipe
);
5170 temp
= I915_READ(reg
);
5171 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
5172 if (temp
& FDI_RX_BIT_LOCK
) {
5173 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
5174 DRM_DEBUG_KMS("FDI train 1 done.\n");
5183 DRM_ERROR("FDI train 1 fail!\n");
5186 reg
= FDI_TX_CTL(pipe
);
5187 temp
= I915_READ(reg
);
5188 temp
&= ~FDI_LINK_TRAIN_NONE
;
5189 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
5190 if (IS_GEN(dev_priv
, 6)) {
5191 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
5193 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
5195 I915_WRITE(reg
, temp
);
5197 reg
= FDI_RX_CTL(pipe
);
5198 temp
= I915_READ(reg
);
5199 if (HAS_PCH_CPT(dev_priv
)) {
5200 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
5201 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
5203 temp
&= ~FDI_LINK_TRAIN_NONE
;
5204 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
5206 I915_WRITE(reg
, temp
);
5211 for (i
= 0; i
< 4; i
++) {
5212 reg
= FDI_TX_CTL(pipe
);
5213 temp
= I915_READ(reg
);
5214 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
5215 temp
|= snb_b_fdi_train_param
[i
];
5216 I915_WRITE(reg
, temp
);
5221 for (retry
= 0; retry
< 5; retry
++) {
5222 reg
= FDI_RX_IIR(pipe
);
5223 temp
= I915_READ(reg
);
5224 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
5225 if (temp
& FDI_RX_SYMBOL_LOCK
) {
5226 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
5227 DRM_DEBUG_KMS("FDI train 2 done.\n");
5236 DRM_ERROR("FDI train 2 fail!\n");
5238 DRM_DEBUG_KMS("FDI train done.\n");
5241 /* Manual link training for Ivy Bridge A0 parts */
5242 static void ivb_manual_fdi_link_train(struct intel_crtc
*crtc
,
5243 const struct intel_crtc_state
*crtc_state
)
5245 struct drm_device
*dev
= crtc
->base
.dev
;
5246 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5247 enum pipe pipe
= crtc
->pipe
;
5251 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
5253 reg
= FDI_RX_IMR(pipe
);
5254 temp
= I915_READ(reg
);
5255 temp
&= ~FDI_RX_SYMBOL_LOCK
;
5256 temp
&= ~FDI_RX_BIT_LOCK
;
5257 I915_WRITE(reg
, temp
);
5262 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
5263 I915_READ(FDI_RX_IIR(pipe
)));
5265 /* Try each vswing and preemphasis setting twice before moving on */
5266 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
5267 /* disable first in case we need to retry */
5268 reg
= FDI_TX_CTL(pipe
);
5269 temp
= I915_READ(reg
);
5270 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
5271 temp
&= ~FDI_TX_ENABLE
;
5272 I915_WRITE(reg
, temp
);
5274 reg
= FDI_RX_CTL(pipe
);
5275 temp
= I915_READ(reg
);
5276 temp
&= ~FDI_LINK_TRAIN_AUTO
;
5277 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
5278 temp
&= ~FDI_RX_ENABLE
;
5279 I915_WRITE(reg
, temp
);
5281 /* enable CPU FDI TX and PCH FDI RX */
5282 reg
= FDI_TX_CTL(pipe
);
5283 temp
= I915_READ(reg
);
5284 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
5285 temp
|= FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
5286 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
5287 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
5288 temp
|= snb_b_fdi_train_param
[j
/2];
5289 temp
|= FDI_COMPOSITE_SYNC
;
5290 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
5292 I915_WRITE(FDI_RX_MISC(pipe
),
5293 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
5295 reg
= FDI_RX_CTL(pipe
);
5296 temp
= I915_READ(reg
);
5297 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
5298 temp
|= FDI_COMPOSITE_SYNC
;
5299 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
5302 udelay(1); /* should be 0.5us */
5304 for (i
= 0; i
< 4; i
++) {
5305 reg
= FDI_RX_IIR(pipe
);
5306 temp
= I915_READ(reg
);
5307 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
5309 if (temp
& FDI_RX_BIT_LOCK
||
5310 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
5311 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
5312 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
5316 udelay(1); /* should be 0.5us */
5319 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
5324 reg
= FDI_TX_CTL(pipe
);
5325 temp
= I915_READ(reg
);
5326 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
5327 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
5328 I915_WRITE(reg
, temp
);
5330 reg
= FDI_RX_CTL(pipe
);
5331 temp
= I915_READ(reg
);
5332 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
5333 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
5334 I915_WRITE(reg
, temp
);
5337 udelay(2); /* should be 1.5us */
5339 for (i
= 0; i
< 4; i
++) {
5340 reg
= FDI_RX_IIR(pipe
);
5341 temp
= I915_READ(reg
);
5342 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
5344 if (temp
& FDI_RX_SYMBOL_LOCK
||
5345 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
5346 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
5347 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
5351 udelay(2); /* should be 1.5us */
5354 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
5358 DRM_DEBUG_KMS("FDI train done.\n");
5361 static void ilk_fdi_pll_enable(const struct intel_crtc_state
*crtc_state
)
5363 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
5364 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
5365 enum pipe pipe
= intel_crtc
->pipe
;
5369 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
5370 reg
= FDI_RX_CTL(pipe
);
5371 temp
= I915_READ(reg
);
5372 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
5373 temp
|= FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
5374 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
5375 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
5380 /* Switch from Rawclk to PCDclk */
5381 temp
= I915_READ(reg
);
5382 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
5387 /* Enable CPU FDI TX PLL, always on for Ironlake */
5388 reg
= FDI_TX_CTL(pipe
);
5389 temp
= I915_READ(reg
);
5390 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
5391 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
5398 static void ilk_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
5400 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5401 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5402 enum pipe pipe
= intel_crtc
->pipe
;
5406 /* Switch from PCDclk to Rawclk */
5407 reg
= FDI_RX_CTL(pipe
);
5408 temp
= I915_READ(reg
);
5409 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
5411 /* Disable CPU FDI TX PLL */
5412 reg
= FDI_TX_CTL(pipe
);
5413 temp
= I915_READ(reg
);
5414 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
5419 reg
= FDI_RX_CTL(pipe
);
5420 temp
= I915_READ(reg
);
5421 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
5423 /* Wait for the clocks to turn off. */
5428 static void ilk_fdi_disable(struct intel_crtc
*crtc
)
5430 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
5431 enum pipe pipe
= crtc
->pipe
;
5435 /* disable CPU FDI tx and PCH FDI rx */
5436 reg
= FDI_TX_CTL(pipe
);
5437 temp
= I915_READ(reg
);
5438 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
5441 reg
= FDI_RX_CTL(pipe
);
5442 temp
= I915_READ(reg
);
5443 temp
&= ~(0x7 << 16);
5444 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
5445 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
5450 /* Ironlake workaround, disable clock pointer after downing FDI */
5451 if (HAS_PCH_IBX(dev_priv
))
5452 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
5454 /* still set train pattern 1 */
5455 reg
= FDI_TX_CTL(pipe
);
5456 temp
= I915_READ(reg
);
5457 temp
&= ~FDI_LINK_TRAIN_NONE
;
5458 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
5459 I915_WRITE(reg
, temp
);
5461 reg
= FDI_RX_CTL(pipe
);
5462 temp
= I915_READ(reg
);
5463 if (HAS_PCH_CPT(dev_priv
)) {
5464 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
5465 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
5467 temp
&= ~FDI_LINK_TRAIN_NONE
;
5468 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
5470 /* BPC in FDI rx is consistent with that in PIPECONF */
5471 temp
&= ~(0x07 << 16);
5472 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
5473 I915_WRITE(reg
, temp
);
5479 bool intel_has_pending_fb_unpin(struct drm_i915_private
*dev_priv
)
5481 struct drm_crtc
*crtc
;
5484 drm_for_each_crtc(crtc
, &dev_priv
->drm
) {
5485 struct drm_crtc_commit
*commit
;
5486 spin_lock(&crtc
->commit_lock
);
5487 commit
= list_first_entry_or_null(&crtc
->commit_list
,
5488 struct drm_crtc_commit
, commit_entry
);
5489 cleanup_done
= commit
?
5490 try_wait_for_completion(&commit
->cleanup_done
) : true;
5491 spin_unlock(&crtc
->commit_lock
);
5496 drm_crtc_wait_one_vblank(crtc
);
5504 void lpt_disable_iclkip(struct drm_i915_private
*dev_priv
)
5508 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
5510 mutex_lock(&dev_priv
->sb_lock
);
5512 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
5513 temp
|= SBI_SSCCTL_DISABLE
;
5514 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
5516 mutex_unlock(&dev_priv
->sb_lock
);
5519 /* Program iCLKIP clock to the desired frequency */
5520 static void lpt_program_iclkip(const struct intel_crtc_state
*crtc_state
)
5522 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
5523 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
5524 int clock
= crtc_state
->hw
.adjusted_mode
.crtc_clock
;
5525 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
5528 lpt_disable_iclkip(dev_priv
);
5530 /* The iCLK virtual clock root frequency is in MHz,
5531 * but the adjusted_mode->crtc_clock in in KHz. To get the
5532 * divisors, it is necessary to divide one by another, so we
5533 * convert the virtual clock precision to KHz here for higher
5536 for (auxdiv
= 0; auxdiv
< 2; auxdiv
++) {
5537 u32 iclk_virtual_root_freq
= 172800 * 1000;
5538 u32 iclk_pi_range
= 64;
5539 u32 desired_divisor
;
5541 desired_divisor
= DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
5543 divsel
= (desired_divisor
/ iclk_pi_range
) - 2;
5544 phaseinc
= desired_divisor
% iclk_pi_range
;
5547 * Near 20MHz is a corner case which is
5548 * out of range for the 7-bit divisor
5554 /* This should not happen with any sane values */
5555 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
5556 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
5557 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
5558 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
5560 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
5567 mutex_lock(&dev_priv
->sb_lock
);
5569 /* Program SSCDIVINTPHASE6 */
5570 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
5571 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
5572 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
5573 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
5574 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
5575 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
5576 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
5577 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
5579 /* Program SSCAUXDIV */
5580 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
5581 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
5582 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
5583 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
5585 /* Enable modulator and associated divider */
5586 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
5587 temp
&= ~SBI_SSCCTL_DISABLE
;
5588 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
5590 mutex_unlock(&dev_priv
->sb_lock
);
5592 /* Wait for initialization time */
5595 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
5598 int lpt_get_iclkip(struct drm_i915_private
*dev_priv
)
5600 u32 divsel
, phaseinc
, auxdiv
;
5601 u32 iclk_virtual_root_freq
= 172800 * 1000;
5602 u32 iclk_pi_range
= 64;
5603 u32 desired_divisor
;
5606 if ((I915_READ(PIXCLK_GATE
) & PIXCLK_GATE_UNGATE
) == 0)
5609 mutex_lock(&dev_priv
->sb_lock
);
5611 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
5612 if (temp
& SBI_SSCCTL_DISABLE
) {
5613 mutex_unlock(&dev_priv
->sb_lock
);
5617 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
5618 divsel
= (temp
& SBI_SSCDIVINTPHASE_DIVSEL_MASK
) >>
5619 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT
;
5620 phaseinc
= (temp
& SBI_SSCDIVINTPHASE_INCVAL_MASK
) >>
5621 SBI_SSCDIVINTPHASE_INCVAL_SHIFT
;
5623 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
5624 auxdiv
= (temp
& SBI_SSCAUXDIV_FINALDIV2SEL_MASK
) >>
5625 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT
;
5627 mutex_unlock(&dev_priv
->sb_lock
);
5629 desired_divisor
= (divsel
+ 2) * iclk_pi_range
+ phaseinc
;
5631 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
5632 desired_divisor
<< auxdiv
);
5635 static void ilk_pch_transcoder_set_timings(const struct intel_crtc_state
*crtc_state
,
5636 enum pipe pch_transcoder
)
5638 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
5639 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
5640 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
5642 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
5643 I915_READ(HTOTAL(cpu_transcoder
)));
5644 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
5645 I915_READ(HBLANK(cpu_transcoder
)));
5646 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
5647 I915_READ(HSYNC(cpu_transcoder
)));
5649 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
5650 I915_READ(VTOTAL(cpu_transcoder
)));
5651 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
5652 I915_READ(VBLANK(cpu_transcoder
)));
5653 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
5654 I915_READ(VSYNC(cpu_transcoder
)));
5655 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
5656 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
5659 static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private
*dev_priv
, bool enable
)
5663 temp
= I915_READ(SOUTH_CHICKEN1
);
5664 if (!!(temp
& FDI_BC_BIFURCATION_SELECT
) == enable
)
5667 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
5668 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
5670 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
5672 temp
|= FDI_BC_BIFURCATION_SELECT
;
5674 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable
? "en" : "dis");
5675 I915_WRITE(SOUTH_CHICKEN1
, temp
);
5676 POSTING_READ(SOUTH_CHICKEN1
);
5679 static void ivb_update_fdi_bc_bifurcation(const struct intel_crtc_state
*crtc_state
)
5681 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
5682 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
5684 switch (crtc
->pipe
) {
5688 if (crtc_state
->fdi_lanes
> 2)
5689 cpt_set_fdi_bc_bifurcation(dev_priv
, false);
5691 cpt_set_fdi_bc_bifurcation(dev_priv
, true);
5695 cpt_set_fdi_bc_bifurcation(dev_priv
, true);
5704 * Finds the encoder associated with the given CRTC. This can only be
5705 * used when we know that the CRTC isn't feeding multiple encoders!
5707 static struct intel_encoder
*
5708 intel_get_crtc_new_encoder(const struct intel_atomic_state
*state
,
5709 const struct intel_crtc_state
*crtc_state
)
5711 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
5712 const struct drm_connector_state
*connector_state
;
5713 const struct drm_connector
*connector
;
5714 struct intel_encoder
*encoder
= NULL
;
5715 int num_encoders
= 0;
5718 for_each_new_connector_in_state(&state
->base
, connector
, connector_state
, i
) {
5719 if (connector_state
->crtc
!= &crtc
->base
)
5722 encoder
= to_intel_encoder(connector_state
->best_encoder
);
5726 WARN(num_encoders
!= 1, "%d encoders for pipe %c\n",
5727 num_encoders
, pipe_name(crtc
->pipe
));
5733 * Enable PCH resources required for PCH ports:
5735 * - FDI training & RX/TX
5736 * - update transcoder timings
5737 * - DP transcoding bits
5740 static void ilk_pch_enable(const struct intel_atomic_state
*state
,
5741 const struct intel_crtc_state
*crtc_state
)
5743 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
5744 struct drm_device
*dev
= crtc
->base
.dev
;
5745 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5746 enum pipe pipe
= crtc
->pipe
;
5749 assert_pch_transcoder_disabled(dev_priv
, pipe
);
5751 if (IS_IVYBRIDGE(dev_priv
))
5752 ivb_update_fdi_bc_bifurcation(crtc_state
);
5754 /* Write the TU size bits before fdi link training, so that error
5755 * detection works. */
5756 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
5757 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
5759 /* For PCH output, training FDI link */
5760 dev_priv
->display
.fdi_link_train(crtc
, crtc_state
);
5762 /* We need to program the right clock selection before writing the pixel
5763 * mutliplier into the DPLL. */
5764 if (HAS_PCH_CPT(dev_priv
)) {
5767 temp
= I915_READ(PCH_DPLL_SEL
);
5768 temp
|= TRANS_DPLL_ENABLE(pipe
);
5769 sel
= TRANS_DPLLB_SEL(pipe
);
5770 if (crtc_state
->shared_dpll
==
5771 intel_get_shared_dpll_by_id(dev_priv
, DPLL_ID_PCH_PLL_B
))
5775 I915_WRITE(PCH_DPLL_SEL
, temp
);
5778 /* XXX: pch pll's can be enabled any time before we enable the PCH
5779 * transcoder, and we actually should do this to not upset any PCH
5780 * transcoder that already use the clock when we share it.
5782 * Note that enable_shared_dpll tries to do the right thing, but
5783 * get_shared_dpll unconditionally resets the pll - we need that to have
5784 * the right LVDS enable sequence. */
5785 intel_enable_shared_dpll(crtc_state
);
5787 /* set transcoder timing, panel must allow it */
5788 assert_panel_unlocked(dev_priv
, pipe
);
5789 ilk_pch_transcoder_set_timings(crtc_state
, pipe
);
5791 intel_fdi_normal_train(crtc
);
5793 /* For PCH DP, enable TRANS_DP_CTL */
5794 if (HAS_PCH_CPT(dev_priv
) &&
5795 intel_crtc_has_dp_encoder(crtc_state
)) {
5796 const struct drm_display_mode
*adjusted_mode
=
5797 &crtc_state
->hw
.adjusted_mode
;
5798 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
5799 i915_reg_t reg
= TRANS_DP_CTL(pipe
);
5802 temp
= I915_READ(reg
);
5803 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
5804 TRANS_DP_SYNC_MASK
|
5806 temp
|= TRANS_DP_OUTPUT_ENABLE
;
5807 temp
|= bpc
<< 9; /* same format but at 11:9 */
5809 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
5810 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
5811 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
5812 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
5814 port
= intel_get_crtc_new_encoder(state
, crtc_state
)->port
;
5815 WARN_ON(port
< PORT_B
|| port
> PORT_D
);
5816 temp
|= TRANS_DP_PORT_SEL(port
);
5818 I915_WRITE(reg
, temp
);
5821 ilk_enable_pch_transcoder(crtc_state
);
5824 static void lpt_pch_enable(const struct intel_atomic_state
*state
,
5825 const struct intel_crtc_state
*crtc_state
)
5827 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
5828 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
5829 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
5831 assert_pch_transcoder_disabled(dev_priv
, PIPE_A
);
5833 lpt_program_iclkip(crtc_state
);
5835 /* Set transcoder timing. */
5836 ilk_pch_transcoder_set_timings(crtc_state
, PIPE_A
);
5838 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
5841 static void cpt_verify_modeset(struct drm_i915_private
*dev_priv
,
5844 i915_reg_t dslreg
= PIPEDSL(pipe
);
5847 temp
= I915_READ(dslreg
);
5849 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
5850 if (wait_for(I915_READ(dslreg
) != temp
, 5))
5851 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
5856 * The hardware phase 0.0 refers to the center of the pixel.
5857 * We want to start from the top/left edge which is phase
5858 * -0.5. That matches how the hardware calculates the scaling
5859 * factors (from top-left of the first pixel to bottom-right
5860 * of the last pixel, as opposed to the pixel centers).
5862 * For 4:2:0 subsampled chroma planes we obviously have to
5863 * adjust that so that the chroma sample position lands in
5866 * Note that for packed YCbCr 4:2:2 formats there is no way to
5867 * control chroma siting. The hardware simply replicates the
5868 * chroma samples for both of the luma samples, and thus we don't
5869 * actually get the expected MPEG2 chroma siting convention :(
5870 * The same behaviour is observed on pre-SKL platforms as well.
5872 * Theory behind the formula (note that we ignore sub-pixel
5873 * source coordinates):
5874 * s = source sample position
5875 * d = destination sample position
5880 * | | 1.5 (initial phase)
5888 * | -0.375 (initial phase)
5895 u16
skl_scaler_calc_phase(int sub
, int scale
, bool chroma_cosited
)
5897 int phase
= -0x8000;
5901 phase
+= (sub
- 1) * 0x8000 / sub
;
5903 phase
+= scale
/ (2 * sub
);
5906 * Hardware initial phase limited to [-0.5:1.5].
5907 * Since the max hardware scale factor is 3.0, we
5908 * should never actually excdeed 1.0 here.
5910 WARN_ON(phase
< -0x8000 || phase
> 0x18000);
5913 phase
= 0x10000 + phase
;
5915 trip
= PS_PHASE_TRIP
;
5917 return ((phase
>> 2) & PS_PHASE_MASK
) | trip
;
5920 #define SKL_MIN_SRC_W 8
5921 #define SKL_MAX_SRC_W 4096
5922 #define SKL_MIN_SRC_H 8
5923 #define SKL_MAX_SRC_H 4096
5924 #define SKL_MIN_DST_W 8
5925 #define SKL_MAX_DST_W 4096
5926 #define SKL_MIN_DST_H 8
5927 #define SKL_MAX_DST_H 4096
5928 #define ICL_MAX_SRC_W 5120
5929 #define ICL_MAX_SRC_H 4096
5930 #define ICL_MAX_DST_W 5120
5931 #define ICL_MAX_DST_H 4096
5932 #define SKL_MIN_YUV_420_SRC_W 16
5933 #define SKL_MIN_YUV_420_SRC_H 16
5936 skl_update_scaler(struct intel_crtc_state
*crtc_state
, bool force_detach
,
5937 unsigned int scaler_user
, int *scaler_id
,
5938 int src_w
, int src_h
, int dst_w
, int dst_h
,
5939 const struct drm_format_info
*format
,
5940 u64 modifier
, bool need_scaler
)
5942 struct intel_crtc_scaler_state
*scaler_state
=
5943 &crtc_state
->scaler_state
;
5944 struct intel_crtc
*intel_crtc
=
5945 to_intel_crtc(crtc_state
->uapi
.crtc
);
5946 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
5947 const struct drm_display_mode
*adjusted_mode
=
5948 &crtc_state
->hw
.adjusted_mode
;
5951 * Src coordinates are already rotated by 270 degrees for
5952 * the 90/270 degree plane rotation cases (to match the
5953 * GTT mapping), hence no need to account for rotation here.
5955 if (src_w
!= dst_w
|| src_h
!= dst_h
)
5959 * Scaling/fitting not supported in IF-ID mode in GEN9+
5960 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
5961 * Once NV12 is enabled, handle it here while allocating scaler
5964 if (INTEL_GEN(dev_priv
) >= 9 && crtc_state
->hw
.enable
&&
5965 need_scaler
&& adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
5966 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
5971 * if plane is being disabled or scaler is no more required or force detach
5972 * - free scaler binded to this plane/crtc
5973 * - in order to do this, update crtc->scaler_usage
5975 * Here scaler state in crtc_state is set free so that
5976 * scaler can be assigned to other user. Actual register
5977 * update to free the scaler is done in plane/panel-fit programming.
5978 * For this purpose crtc/plane_state->scaler_id isn't reset here.
5980 if (force_detach
|| !need_scaler
) {
5981 if (*scaler_id
>= 0) {
5982 scaler_state
->scaler_users
&= ~(1 << scaler_user
);
5983 scaler_state
->scalers
[*scaler_id
].in_use
= 0;
5985 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5986 "Staged freeing scaler id %d scaler_users = 0x%x\n",
5987 intel_crtc
->pipe
, scaler_user
, *scaler_id
,
5988 scaler_state
->scaler_users
);
5994 if (format
&& intel_format_info_is_yuv_semiplanar(format
, modifier
) &&
5995 (src_h
< SKL_MIN_YUV_420_SRC_H
|| src_w
< SKL_MIN_YUV_420_SRC_W
)) {
5996 DRM_DEBUG_KMS("Planar YUV: src dimensions not met\n");
6001 if (src_w
< SKL_MIN_SRC_W
|| src_h
< SKL_MIN_SRC_H
||
6002 dst_w
< SKL_MIN_DST_W
|| dst_h
< SKL_MIN_DST_H
||
6003 (INTEL_GEN(dev_priv
) >= 11 &&
6004 (src_w
> ICL_MAX_SRC_W
|| src_h
> ICL_MAX_SRC_H
||
6005 dst_w
> ICL_MAX_DST_W
|| dst_h
> ICL_MAX_DST_H
)) ||
6006 (INTEL_GEN(dev_priv
) < 11 &&
6007 (src_w
> SKL_MAX_SRC_W
|| src_h
> SKL_MAX_SRC_H
||
6008 dst_w
> SKL_MAX_DST_W
|| dst_h
> SKL_MAX_DST_H
))) {
6009 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
6010 "size is out of scaler range\n",
6011 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
);
6015 /* mark this plane as a scaler user in crtc_state */
6016 scaler_state
->scaler_users
|= (1 << scaler_user
);
6017 DRM_DEBUG_KMS("scaler_user index %u.%u: "
6018 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
6019 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
,
6020 scaler_state
->scaler_users
);
6026 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
6028 * @state: crtc's scaler state
6031 * 0 - scaler_usage updated successfully
6032 * error - requested scaling cannot be supported or other error condition
6034 int skl_update_scaler_crtc(struct intel_crtc_state
*state
)
6036 const struct drm_display_mode
*adjusted_mode
= &state
->hw
.adjusted_mode
;
6037 bool need_scaler
= false;
6039 if (state
->output_format
== INTEL_OUTPUT_FORMAT_YCBCR420
)
6042 return skl_update_scaler(state
, !state
->hw
.active
, SKL_CRTC_INDEX
,
6043 &state
->scaler_state
.scaler_id
,
6044 state
->pipe_src_w
, state
->pipe_src_h
,
6045 adjusted_mode
->crtc_hdisplay
,
6046 adjusted_mode
->crtc_vdisplay
, NULL
, 0,
6051 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
6052 * @crtc_state: crtc's scaler state
6053 * @plane_state: atomic plane state to update
6056 * 0 - scaler_usage updated successfully
6057 * error - requested scaling cannot be supported or other error condition
6059 static int skl_update_scaler_plane(struct intel_crtc_state
*crtc_state
,
6060 struct intel_plane_state
*plane_state
)
6062 struct intel_plane
*intel_plane
=
6063 to_intel_plane(plane_state
->uapi
.plane
);
6064 struct drm_i915_private
*dev_priv
= to_i915(intel_plane
->base
.dev
);
6065 struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
6067 bool force_detach
= !fb
|| !plane_state
->uapi
.visible
;
6068 bool need_scaler
= false;
6070 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
6071 if (!icl_is_hdr_plane(dev_priv
, intel_plane
->id
) &&
6072 fb
&& intel_format_info_is_yuv_semiplanar(fb
->format
, fb
->modifier
))
6075 ret
= skl_update_scaler(crtc_state
, force_detach
,
6076 drm_plane_index(&intel_plane
->base
),
6077 &plane_state
->scaler_id
,
6078 drm_rect_width(&plane_state
->uapi
.src
) >> 16,
6079 drm_rect_height(&plane_state
->uapi
.src
) >> 16,
6080 drm_rect_width(&plane_state
->uapi
.dst
),
6081 drm_rect_height(&plane_state
->uapi
.dst
),
6082 fb
? fb
->format
: NULL
,
6083 fb
? fb
->modifier
: 0,
6086 if (ret
|| plane_state
->scaler_id
< 0)
6089 /* check colorkey */
6090 if (plane_state
->ckey
.flags
) {
6091 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
6092 intel_plane
->base
.base
.id
,
6093 intel_plane
->base
.name
);
6097 /* Check src format */
6098 switch (fb
->format
->format
) {
6099 case DRM_FORMAT_RGB565
:
6100 case DRM_FORMAT_XBGR8888
:
6101 case DRM_FORMAT_XRGB8888
:
6102 case DRM_FORMAT_ABGR8888
:
6103 case DRM_FORMAT_ARGB8888
:
6104 case DRM_FORMAT_XRGB2101010
:
6105 case DRM_FORMAT_XBGR2101010
:
6106 case DRM_FORMAT_ARGB2101010
:
6107 case DRM_FORMAT_ABGR2101010
:
6108 case DRM_FORMAT_YUYV
:
6109 case DRM_FORMAT_YVYU
:
6110 case DRM_FORMAT_UYVY
:
6111 case DRM_FORMAT_VYUY
:
6112 case DRM_FORMAT_NV12
:
6113 case DRM_FORMAT_P010
:
6114 case DRM_FORMAT_P012
:
6115 case DRM_FORMAT_P016
:
6116 case DRM_FORMAT_Y210
:
6117 case DRM_FORMAT_Y212
:
6118 case DRM_FORMAT_Y216
:
6119 case DRM_FORMAT_XVYU2101010
:
6120 case DRM_FORMAT_XVYU12_16161616
:
6121 case DRM_FORMAT_XVYU16161616
:
6123 case DRM_FORMAT_XBGR16161616F
:
6124 case DRM_FORMAT_ABGR16161616F
:
6125 case DRM_FORMAT_XRGB16161616F
:
6126 case DRM_FORMAT_ARGB16161616F
:
6127 if (INTEL_GEN(dev_priv
) >= 11)
6131 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
6132 intel_plane
->base
.base
.id
, intel_plane
->base
.name
,
6133 fb
->base
.id
, fb
->format
->format
);
6140 void skl_scaler_disable(const struct intel_crtc_state
*old_crtc_state
)
6142 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->uapi
.crtc
);
6145 for (i
= 0; i
< crtc
->num_scalers
; i
++)
6146 skl_detach_scaler(crtc
, i
);
6149 static void skl_pfit_enable(const struct intel_crtc_state
*crtc_state
)
6151 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
6152 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6153 enum pipe pipe
= crtc
->pipe
;
6154 const struct intel_crtc_scaler_state
*scaler_state
=
6155 &crtc_state
->scaler_state
;
6157 if (crtc_state
->pch_pfit
.enabled
) {
6158 u16 uv_rgb_hphase
, uv_rgb_vphase
;
6159 int pfit_w
, pfit_h
, hscale
, vscale
;
6162 if (WARN_ON(crtc_state
->scaler_state
.scaler_id
< 0))
6165 pfit_w
= (crtc_state
->pch_pfit
.size
>> 16) & 0xFFFF;
6166 pfit_h
= crtc_state
->pch_pfit
.size
& 0xFFFF;
6168 hscale
= (crtc_state
->pipe_src_w
<< 16) / pfit_w
;
6169 vscale
= (crtc_state
->pipe_src_h
<< 16) / pfit_h
;
6171 uv_rgb_hphase
= skl_scaler_calc_phase(1, hscale
, false);
6172 uv_rgb_vphase
= skl_scaler_calc_phase(1, vscale
, false);
6174 id
= scaler_state
->scaler_id
;
6175 I915_WRITE(SKL_PS_CTRL(pipe
, id
), PS_SCALER_EN
|
6176 PS_FILTER_MEDIUM
| scaler_state
->scalers
[id
].mode
);
6177 I915_WRITE_FW(SKL_PS_VPHASE(pipe
, id
),
6178 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase
));
6179 I915_WRITE_FW(SKL_PS_HPHASE(pipe
, id
),
6180 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase
));
6181 I915_WRITE(SKL_PS_WIN_POS(pipe
, id
), crtc_state
->pch_pfit
.pos
);
6182 I915_WRITE(SKL_PS_WIN_SZ(pipe
, id
), crtc_state
->pch_pfit
.size
);
6186 static void ilk_pfit_enable(const struct intel_crtc_state
*crtc_state
)
6188 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
6189 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6190 enum pipe pipe
= crtc
->pipe
;
6192 if (crtc_state
->pch_pfit
.enabled
) {
6193 /* Force use of hard-coded filter coefficients
6194 * as some pre-programmed values are broken,
6197 if (IS_IVYBRIDGE(dev_priv
) || IS_HASWELL(dev_priv
))
6198 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
6199 PF_PIPE_SEL_IVB(pipe
));
6201 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
6202 I915_WRITE(PF_WIN_POS(pipe
), crtc_state
->pch_pfit
.pos
);
6203 I915_WRITE(PF_WIN_SZ(pipe
), crtc_state
->pch_pfit
.size
);
6207 void hsw_enable_ips(const struct intel_crtc_state
*crtc_state
)
6209 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
6210 struct drm_device
*dev
= crtc
->base
.dev
;
6211 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6213 if (!crtc_state
->ips_enabled
)
6217 * We can only enable IPS after we enable a plane and wait for a vblank
6218 * This function is called from post_plane_update, which is run after
6221 WARN_ON(!(crtc_state
->active_planes
& ~BIT(PLANE_CURSOR
)));
6223 if (IS_BROADWELL(dev_priv
)) {
6224 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
,
6225 IPS_ENABLE
| IPS_PCODE_CONTROL
));
6226 /* Quoting Art Runyan: "its not safe to expect any particular
6227 * value in IPS_CTL bit 31 after enabling IPS through the
6228 * mailbox." Moreover, the mailbox may return a bogus state,
6229 * so we need to just enable it and continue on.
6232 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
6233 /* The bit only becomes 1 in the next vblank, so this wait here
6234 * is essentially intel_wait_for_vblank. If we don't have this
6235 * and don't wait for vblanks until the end of crtc_enable, then
6236 * the HW state readout code will complain that the expected
6237 * IPS_CTL value is not the one we read. */
6238 if (intel_de_wait_for_set(dev_priv
, IPS_CTL
, IPS_ENABLE
, 50))
6239 DRM_ERROR("Timed out waiting for IPS enable\n");
6243 void hsw_disable_ips(const struct intel_crtc_state
*crtc_state
)
6245 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
6246 struct drm_device
*dev
= crtc
->base
.dev
;
6247 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6249 if (!crtc_state
->ips_enabled
)
6252 if (IS_BROADWELL(dev_priv
)) {
6253 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
6255 * Wait for PCODE to finish disabling IPS. The BSpec specified
6256 * 42ms timeout value leads to occasional timeouts so use 100ms
6259 if (intel_de_wait_for_clear(dev_priv
, IPS_CTL
, IPS_ENABLE
, 100))
6260 DRM_ERROR("Timed out waiting for IPS disable\n");
6262 I915_WRITE(IPS_CTL
, 0);
6263 POSTING_READ(IPS_CTL
);
6266 /* We need to wait for a vblank before we can disable the plane. */
6267 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
6270 static void intel_crtc_dpms_overlay_disable(struct intel_crtc
*intel_crtc
)
6272 if (intel_crtc
->overlay
)
6273 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
6275 /* Let userspace switch the overlay on again. In most cases userspace
6276 * has to recompute where to put it anyway.
6280 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state
*old_crtc_state
,
6281 const struct intel_crtc_state
*new_crtc_state
)
6283 struct intel_crtc
*crtc
= to_intel_crtc(new_crtc_state
->uapi
.crtc
);
6284 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6286 if (!old_crtc_state
->ips_enabled
)
6289 if (needs_modeset(new_crtc_state
))
6293 * Workaround : Do not read or write the pipe palette/gamma data while
6294 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
6296 * Disable IPS before we program the LUT.
6298 if (IS_HASWELL(dev_priv
) &&
6299 (new_crtc_state
->uapi
.color_mgmt_changed
||
6300 new_crtc_state
->update_pipe
) &&
6301 new_crtc_state
->gamma_mode
== GAMMA_MODE_MODE_SPLIT
)
6304 return !new_crtc_state
->ips_enabled
;
6307 static bool hsw_post_update_enable_ips(const struct intel_crtc_state
*old_crtc_state
,
6308 const struct intel_crtc_state
*new_crtc_state
)
6310 struct intel_crtc
*crtc
= to_intel_crtc(new_crtc_state
->uapi
.crtc
);
6311 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6313 if (!new_crtc_state
->ips_enabled
)
6316 if (needs_modeset(new_crtc_state
))
6320 * Workaround : Do not read or write the pipe palette/gamma data while
6321 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
6323 * Re-enable IPS after the LUT has been programmed.
6325 if (IS_HASWELL(dev_priv
) &&
6326 (new_crtc_state
->uapi
.color_mgmt_changed
||
6327 new_crtc_state
->update_pipe
) &&
6328 new_crtc_state
->gamma_mode
== GAMMA_MODE_MODE_SPLIT
)
6332 * We can't read out IPS on broadwell, assume the worst and
6333 * forcibly enable IPS on the first fastset.
6335 if (new_crtc_state
->update_pipe
&&
6336 old_crtc_state
->hw
.adjusted_mode
.private_flags
& I915_MODE_FLAG_INHERITED
)
6339 return !old_crtc_state
->ips_enabled
;
6342 static bool needs_nv12_wa(const struct intel_crtc_state
*crtc_state
)
6344 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->uapi
.crtc
->dev
);
6346 if (!crtc_state
->nv12_planes
)
6349 /* WA Display #0827: Gen9:all */
6350 if (IS_GEN(dev_priv
, 9) && !IS_GEMINILAKE(dev_priv
))
6356 static bool needs_scalerclk_wa(const struct intel_crtc_state
*crtc_state
)
6358 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->uapi
.crtc
->dev
);
6360 /* Wa_2006604312:icl */
6361 if (crtc_state
->scaler_state
.scaler_users
> 0 && IS_ICELAKE(dev_priv
))
6367 static bool planes_enabling(const struct intel_crtc_state
*old_crtc_state
,
6368 const struct intel_crtc_state
*new_crtc_state
)
6370 return (!old_crtc_state
->active_planes
|| needs_modeset(new_crtc_state
)) &&
6371 new_crtc_state
->active_planes
;
6374 static bool planes_disabling(const struct intel_crtc_state
*old_crtc_state
,
6375 const struct intel_crtc_state
*new_crtc_state
)
6377 return old_crtc_state
->active_planes
&&
6378 (!new_crtc_state
->active_planes
|| needs_modeset(new_crtc_state
));
6381 static void intel_post_plane_update(struct intel_atomic_state
*state
,
6382 struct intel_crtc
*crtc
)
6384 struct drm_i915_private
*dev_priv
= to_i915(state
->base
.dev
);
6385 struct intel_plane
*primary
= to_intel_plane(crtc
->base
.primary
);
6386 const struct intel_crtc_state
*old_crtc_state
=
6387 intel_atomic_get_old_crtc_state(state
, crtc
);
6388 const struct intel_crtc_state
*new_crtc_state
=
6389 intel_atomic_get_new_crtc_state(state
, crtc
);
6390 const struct intel_plane_state
*new_primary_state
=
6391 intel_atomic_get_new_plane_state(state
, primary
);
6392 enum pipe pipe
= crtc
->pipe
;
6394 intel_frontbuffer_flip(dev_priv
, new_crtc_state
->fb_bits
);
6396 if (new_crtc_state
->update_wm_post
&& new_crtc_state
->hw
.active
)
6397 intel_update_watermarks(crtc
);
6399 if (hsw_post_update_enable_ips(old_crtc_state
, new_crtc_state
))
6400 hsw_enable_ips(new_crtc_state
);
6402 if (new_primary_state
)
6403 intel_fbc_post_update(crtc
);
6405 if (needs_nv12_wa(old_crtc_state
) &&
6406 !needs_nv12_wa(new_crtc_state
))
6407 skl_wa_827(dev_priv
, pipe
, false);
6409 if (needs_scalerclk_wa(old_crtc_state
) &&
6410 !needs_scalerclk_wa(new_crtc_state
))
6411 icl_wa_scalerclkgating(dev_priv
, pipe
, false);
6414 static void intel_pre_plane_update(struct intel_atomic_state
*state
,
6415 struct intel_crtc
*crtc
)
6417 struct drm_i915_private
*dev_priv
= to_i915(state
->base
.dev
);
6418 struct intel_plane
*primary
= to_intel_plane(crtc
->base
.primary
);
6419 const struct intel_crtc_state
*old_crtc_state
=
6420 intel_atomic_get_old_crtc_state(state
, crtc
);
6421 const struct intel_crtc_state
*new_crtc_state
=
6422 intel_atomic_get_new_crtc_state(state
, crtc
);
6423 const struct intel_plane_state
*new_primary_state
=
6424 intel_atomic_get_new_plane_state(state
, primary
);
6425 enum pipe pipe
= crtc
->pipe
;
6427 if (hsw_pre_update_disable_ips(old_crtc_state
, new_crtc_state
))
6428 hsw_disable_ips(old_crtc_state
);
6430 if (new_primary_state
&&
6431 intel_fbc_pre_update(crtc
, new_crtc_state
, new_primary_state
))
6432 intel_wait_for_vblank(dev_priv
, pipe
);
6434 /* Display WA 827 */
6435 if (!needs_nv12_wa(old_crtc_state
) &&
6436 needs_nv12_wa(new_crtc_state
))
6437 skl_wa_827(dev_priv
, pipe
, true);
6439 /* Wa_2006604312:icl */
6440 if (!needs_scalerclk_wa(old_crtc_state
) &&
6441 needs_scalerclk_wa(new_crtc_state
))
6442 icl_wa_scalerclkgating(dev_priv
, pipe
, true);
6445 * Vblank time updates from the shadow to live plane control register
6446 * are blocked if the memory self-refresh mode is active at that
6447 * moment. So to make sure the plane gets truly disabled, disable
6448 * first the self-refresh mode. The self-refresh enable bit in turn
6449 * will be checked/applied by the HW only at the next frame start
6450 * event which is after the vblank start event, so we need to have a
6451 * wait-for-vblank between disabling the plane and the pipe.
6453 if (HAS_GMCH(dev_priv
) && old_crtc_state
->hw
.active
&&
6454 new_crtc_state
->disable_cxsr
&& intel_set_memory_cxsr(dev_priv
, false))
6455 intel_wait_for_vblank(dev_priv
, pipe
);
6458 * IVB workaround: must disable low power watermarks for at least
6459 * one frame before enabling scaling. LP watermarks can be re-enabled
6460 * when scaling is disabled.
6462 * WaCxSRDisabledForSpriteScaling:ivb
6464 if (old_crtc_state
->hw
.active
&&
6465 new_crtc_state
->disable_lp_wm
&& ilk_disable_lp_wm(dev_priv
))
6466 intel_wait_for_vblank(dev_priv
, pipe
);
6469 * If we're doing a modeset we don't need to do any
6470 * pre-vblank watermark programming here.
6472 if (!needs_modeset(new_crtc_state
)) {
6474 * For platforms that support atomic watermarks, program the
6475 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
6476 * will be the intermediate values that are safe for both pre- and
6477 * post- vblank; when vblank happens, the 'active' values will be set
6478 * to the final 'target' values and we'll do this again to get the
6479 * optimal watermarks. For gen9+ platforms, the values we program here
6480 * will be the final target values which will get automatically latched
6481 * at vblank time; no further programming will be necessary.
6483 * If a platform hasn't been transitioned to atomic watermarks yet,
6484 * we'll continue to update watermarks the old way, if flags tell
6487 if (dev_priv
->display
.initial_watermarks
)
6488 dev_priv
->display
.initial_watermarks(state
, crtc
);
6489 else if (new_crtc_state
->update_wm_pre
)
6490 intel_update_watermarks(crtc
);
6494 * Gen2 reports pipe underruns whenever all planes are disabled.
6495 * So disable underrun reporting before all the planes get disabled.
6497 * We do this after .initial_watermarks() so that we have a
6498 * chance of catching underruns with the intermediate watermarks
6499 * vs. the old plane configuration.
6501 if (IS_GEN(dev_priv
, 2) && planes_disabling(old_crtc_state
, new_crtc_state
))
6502 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
6505 static void intel_crtc_disable_planes(struct intel_atomic_state
*state
,
6506 struct intel_crtc
*crtc
)
6508 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6509 const struct intel_crtc_state
*new_crtc_state
=
6510 intel_atomic_get_new_crtc_state(state
, crtc
);
6511 unsigned int update_mask
= new_crtc_state
->update_planes
;
6512 const struct intel_plane_state
*old_plane_state
;
6513 struct intel_plane
*plane
;
6514 unsigned fb_bits
= 0;
6517 intel_crtc_dpms_overlay_disable(crtc
);
6519 for_each_old_intel_plane_in_state(state
, plane
, old_plane_state
, i
) {
6520 if (crtc
->pipe
!= plane
->pipe
||
6521 !(update_mask
& BIT(plane
->id
)))
6524 intel_disable_plane(plane
, new_crtc_state
);
6526 if (old_plane_state
->uapi
.visible
)
6527 fb_bits
|= plane
->frontbuffer_bit
;
6530 intel_frontbuffer_flip(dev_priv
, fb_bits
);
6534 * intel_connector_primary_encoder - get the primary encoder for a connector
6535 * @connector: connector for which to return the encoder
6537 * Returns the primary encoder for a connector. There is a 1:1 mapping from
6538 * all connectors to their encoder, except for DP-MST connectors which have
6539 * both a virtual and a primary encoder. These DP-MST primary encoders can be
6540 * pointed to by as many DP-MST connectors as there are pipes.
6542 static struct intel_encoder
*
6543 intel_connector_primary_encoder(struct intel_connector
*connector
)
6545 struct intel_encoder
*encoder
;
6547 if (connector
->mst_port
)
6548 return &dp_to_dig_port(connector
->mst_port
)->base
;
6550 encoder
= intel_attached_encoder(connector
);
6556 static void intel_encoders_update_prepare(struct intel_atomic_state
*state
)
6558 struct drm_connector_state
*new_conn_state
;
6559 struct drm_connector
*connector
;
6562 for_each_new_connector_in_state(&state
->base
, connector
, new_conn_state
,
6564 struct intel_connector
*intel_connector
;
6565 struct intel_encoder
*encoder
;
6566 struct intel_crtc
*crtc
;
6568 if (!intel_connector_needs_modeset(state
, connector
))
6571 intel_connector
= to_intel_connector(connector
);
6572 encoder
= intel_connector_primary_encoder(intel_connector
);
6573 if (!encoder
->update_prepare
)
6576 crtc
= new_conn_state
->crtc
?
6577 to_intel_crtc(new_conn_state
->crtc
) : NULL
;
6578 encoder
->update_prepare(state
, encoder
, crtc
);
6582 static void intel_encoders_update_complete(struct intel_atomic_state
*state
)
6584 struct drm_connector_state
*new_conn_state
;
6585 struct drm_connector
*connector
;
6588 for_each_new_connector_in_state(&state
->base
, connector
, new_conn_state
,
6590 struct intel_connector
*intel_connector
;
6591 struct intel_encoder
*encoder
;
6592 struct intel_crtc
*crtc
;
6594 if (!intel_connector_needs_modeset(state
, connector
))
6597 intel_connector
= to_intel_connector(connector
);
6598 encoder
= intel_connector_primary_encoder(intel_connector
);
6599 if (!encoder
->update_complete
)
6602 crtc
= new_conn_state
->crtc
?
6603 to_intel_crtc(new_conn_state
->crtc
) : NULL
;
6604 encoder
->update_complete(state
, encoder
, crtc
);
6608 static void intel_encoders_pre_pll_enable(struct intel_atomic_state
*state
,
6609 struct intel_crtc
*crtc
)
6611 const struct intel_crtc_state
*crtc_state
=
6612 intel_atomic_get_new_crtc_state(state
, crtc
);
6613 const struct drm_connector_state
*conn_state
;
6614 struct drm_connector
*conn
;
6617 for_each_new_connector_in_state(&state
->base
, conn
, conn_state
, i
) {
6618 struct intel_encoder
*encoder
=
6619 to_intel_encoder(conn_state
->best_encoder
);
6621 if (conn_state
->crtc
!= &crtc
->base
)
6624 if (encoder
->pre_pll_enable
)
6625 encoder
->pre_pll_enable(encoder
, crtc_state
, conn_state
);
6629 static void intel_encoders_pre_enable(struct intel_atomic_state
*state
,
6630 struct intel_crtc
*crtc
)
6632 const struct intel_crtc_state
*crtc_state
=
6633 intel_atomic_get_new_crtc_state(state
, crtc
);
6634 const struct drm_connector_state
*conn_state
;
6635 struct drm_connector
*conn
;
6638 for_each_new_connector_in_state(&state
->base
, conn
, conn_state
, i
) {
6639 struct intel_encoder
*encoder
=
6640 to_intel_encoder(conn_state
->best_encoder
);
6642 if (conn_state
->crtc
!= &crtc
->base
)
6645 if (encoder
->pre_enable
)
6646 encoder
->pre_enable(encoder
, crtc_state
, conn_state
);
6650 static void intel_encoders_enable(struct intel_atomic_state
*state
,
6651 struct intel_crtc
*crtc
)
6653 const struct intel_crtc_state
*crtc_state
=
6654 intel_atomic_get_new_crtc_state(state
, crtc
);
6655 const struct drm_connector_state
*conn_state
;
6656 struct drm_connector
*conn
;
6659 for_each_new_connector_in_state(&state
->base
, conn
, conn_state
, i
) {
6660 struct intel_encoder
*encoder
=
6661 to_intel_encoder(conn_state
->best_encoder
);
6663 if (conn_state
->crtc
!= &crtc
->base
)
6666 if (encoder
->enable
)
6667 encoder
->enable(encoder
, crtc_state
, conn_state
);
6668 intel_opregion_notify_encoder(encoder
, true);
6672 static void intel_encoders_disable(struct intel_atomic_state
*state
,
6673 struct intel_crtc
*crtc
)
6675 const struct intel_crtc_state
*old_crtc_state
=
6676 intel_atomic_get_old_crtc_state(state
, crtc
);
6677 const struct drm_connector_state
*old_conn_state
;
6678 struct drm_connector
*conn
;
6681 for_each_old_connector_in_state(&state
->base
, conn
, old_conn_state
, i
) {
6682 struct intel_encoder
*encoder
=
6683 to_intel_encoder(old_conn_state
->best_encoder
);
6685 if (old_conn_state
->crtc
!= &crtc
->base
)
6688 intel_opregion_notify_encoder(encoder
, false);
6689 if (encoder
->disable
)
6690 encoder
->disable(encoder
, old_crtc_state
, old_conn_state
);
6694 static void intel_encoders_post_disable(struct intel_atomic_state
*state
,
6695 struct intel_crtc
*crtc
)
6697 const struct intel_crtc_state
*old_crtc_state
=
6698 intel_atomic_get_old_crtc_state(state
, crtc
);
6699 const struct drm_connector_state
*old_conn_state
;
6700 struct drm_connector
*conn
;
6703 for_each_old_connector_in_state(&state
->base
, conn
, old_conn_state
, i
) {
6704 struct intel_encoder
*encoder
=
6705 to_intel_encoder(old_conn_state
->best_encoder
);
6707 if (old_conn_state
->crtc
!= &crtc
->base
)
6710 if (encoder
->post_disable
)
6711 encoder
->post_disable(encoder
, old_crtc_state
, old_conn_state
);
6715 static void intel_encoders_post_pll_disable(struct intel_atomic_state
*state
,
6716 struct intel_crtc
*crtc
)
6718 const struct intel_crtc_state
*old_crtc_state
=
6719 intel_atomic_get_old_crtc_state(state
, crtc
);
6720 const struct drm_connector_state
*old_conn_state
;
6721 struct drm_connector
*conn
;
6724 for_each_old_connector_in_state(&state
->base
, conn
, old_conn_state
, i
) {
6725 struct intel_encoder
*encoder
=
6726 to_intel_encoder(old_conn_state
->best_encoder
);
6728 if (old_conn_state
->crtc
!= &crtc
->base
)
6731 if (encoder
->post_pll_disable
)
6732 encoder
->post_pll_disable(encoder
, old_crtc_state
, old_conn_state
);
6736 static void intel_encoders_update_pipe(struct intel_atomic_state
*state
,
6737 struct intel_crtc
*crtc
)
6739 const struct intel_crtc_state
*crtc_state
=
6740 intel_atomic_get_new_crtc_state(state
, crtc
);
6741 const struct drm_connector_state
*conn_state
;
6742 struct drm_connector
*conn
;
6745 for_each_new_connector_in_state(&state
->base
, conn
, conn_state
, i
) {
6746 struct intel_encoder
*encoder
=
6747 to_intel_encoder(conn_state
->best_encoder
);
6749 if (conn_state
->crtc
!= &crtc
->base
)
6752 if (encoder
->update_pipe
)
6753 encoder
->update_pipe(encoder
, crtc_state
, conn_state
);
6757 static void intel_disable_primary_plane(const struct intel_crtc_state
*crtc_state
)
6759 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
6760 struct intel_plane
*plane
= to_intel_plane(crtc
->base
.primary
);
6762 plane
->disable_plane(plane
, crtc_state
);
6765 static void ilk_crtc_enable(struct intel_atomic_state
*state
,
6766 struct intel_crtc
*crtc
)
6768 const struct intel_crtc_state
*new_crtc_state
=
6769 intel_atomic_get_new_crtc_state(state
, crtc
);
6770 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6771 enum pipe pipe
= crtc
->pipe
;
6773 if (WARN_ON(crtc
->active
))
6777 * Sometimes spurious CPU pipe underruns happen during FDI
6778 * training, at least with VGA+HDMI cloning. Suppress them.
6780 * On ILK we get an occasional spurious CPU pipe underruns
6781 * between eDP port A enable and vdd enable. Also PCH port
6782 * enable seems to result in the occasional CPU pipe underrun.
6784 * Spurious PCH underruns also occur during PCH enabling.
6786 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
6787 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
6789 if (new_crtc_state
->has_pch_encoder
)
6790 intel_prepare_shared_dpll(new_crtc_state
);
6792 if (intel_crtc_has_dp_encoder(new_crtc_state
))
6793 intel_dp_set_m_n(new_crtc_state
, M1_N1
);
6795 intel_set_pipe_timings(new_crtc_state
);
6796 intel_set_pipe_src_size(new_crtc_state
);
6798 if (new_crtc_state
->has_pch_encoder
)
6799 intel_cpu_transcoder_set_m_n(new_crtc_state
,
6800 &new_crtc_state
->fdi_m_n
, NULL
);
6802 ilk_set_pipeconf(new_crtc_state
);
6804 crtc
->active
= true;
6806 intel_encoders_pre_enable(state
, crtc
);
6808 if (new_crtc_state
->has_pch_encoder
) {
6809 /* Note: FDI PLL enabling _must_ be done before we enable the
6810 * cpu pipes, hence this is separate from all the other fdi/pch
6812 ilk_fdi_pll_enable(new_crtc_state
);
6814 assert_fdi_tx_disabled(dev_priv
, pipe
);
6815 assert_fdi_rx_disabled(dev_priv
, pipe
);
6818 ilk_pfit_enable(new_crtc_state
);
6821 * On ILK+ LUT must be loaded before the pipe is running but with
6824 intel_color_load_luts(new_crtc_state
);
6825 intel_color_commit(new_crtc_state
);
6826 /* update DSPCNTR to configure gamma for pipe bottom color */
6827 intel_disable_primary_plane(new_crtc_state
);
6829 if (dev_priv
->display
.initial_watermarks
)
6830 dev_priv
->display
.initial_watermarks(state
, crtc
);
6831 intel_enable_pipe(new_crtc_state
);
6833 if (new_crtc_state
->has_pch_encoder
)
6834 ilk_pch_enable(state
, new_crtc_state
);
6836 intel_crtc_vblank_on(new_crtc_state
);
6838 intel_encoders_enable(state
, crtc
);
6840 if (HAS_PCH_CPT(dev_priv
))
6841 cpt_verify_modeset(dev_priv
, pipe
);
6844 * Must wait for vblank to avoid spurious PCH FIFO underruns.
6845 * And a second vblank wait is needed at least on ILK with
6846 * some interlaced HDMI modes. Let's do the double wait always
6847 * in case there are more corner cases we don't know about.
6849 if (new_crtc_state
->has_pch_encoder
) {
6850 intel_wait_for_vblank(dev_priv
, pipe
);
6851 intel_wait_for_vblank(dev_priv
, pipe
);
6853 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
6854 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
6857 /* IPS only exists on ULT machines and is tied to pipe A. */
6858 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
6860 return HAS_IPS(to_i915(crtc
->base
.dev
)) && crtc
->pipe
== PIPE_A
;
6863 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private
*dev_priv
,
6864 enum pipe pipe
, bool apply
)
6866 u32 val
= I915_READ(CLKGATE_DIS_PSL(pipe
));
6867 u32 mask
= DPF_GATING_DIS
| DPF_RAM_GATING_DIS
| DPFR_GATING_DIS
;
6874 I915_WRITE(CLKGATE_DIS_PSL(pipe
), val
);
6877 static void icl_pipe_mbus_enable(struct intel_crtc
*crtc
)
6879 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6880 enum pipe pipe
= crtc
->pipe
;
6883 val
= MBUS_DBOX_A_CREDIT(2);
6885 if (INTEL_GEN(dev_priv
) >= 12) {
6886 val
|= MBUS_DBOX_BW_CREDIT(2);
6887 val
|= MBUS_DBOX_B_CREDIT(12);
6889 val
|= MBUS_DBOX_BW_CREDIT(1);
6890 val
|= MBUS_DBOX_B_CREDIT(8);
6893 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe
), val
);
6896 static void hsw_set_frame_start_delay(const struct intel_crtc_state
*crtc_state
)
6898 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
6899 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6900 i915_reg_t reg
= CHICKEN_TRANS(crtc_state
->cpu_transcoder
);
6903 val
= I915_READ(reg
);
6904 val
&= ~HSW_FRAME_START_DELAY_MASK
;
6905 val
|= HSW_FRAME_START_DELAY(0);
6906 I915_WRITE(reg
, val
);
6909 static void hsw_crtc_enable(struct intel_atomic_state
*state
,
6910 struct intel_crtc
*crtc
)
6912 const struct intel_crtc_state
*new_crtc_state
=
6913 intel_atomic_get_new_crtc_state(state
, crtc
);
6914 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6915 enum pipe pipe
= crtc
->pipe
, hsw_workaround_pipe
;
6916 enum transcoder cpu_transcoder
= new_crtc_state
->cpu_transcoder
;
6917 bool psl_clkgate_wa
;
6919 if (WARN_ON(crtc
->active
))
6922 intel_encoders_pre_pll_enable(state
, crtc
);
6924 if (new_crtc_state
->shared_dpll
)
6925 intel_enable_shared_dpll(new_crtc_state
);
6927 intel_encoders_pre_enable(state
, crtc
);
6929 if (intel_crtc_has_dp_encoder(new_crtc_state
))
6930 intel_dp_set_m_n(new_crtc_state
, M1_N1
);
6932 if (!transcoder_is_dsi(cpu_transcoder
))
6933 intel_set_pipe_timings(new_crtc_state
);
6935 if (INTEL_GEN(dev_priv
) >= 11)
6936 icl_enable_trans_port_sync(new_crtc_state
);
6938 intel_set_pipe_src_size(new_crtc_state
);
6940 if (cpu_transcoder
!= TRANSCODER_EDP
&&
6941 !transcoder_is_dsi(cpu_transcoder
))
6942 I915_WRITE(PIPE_MULT(cpu_transcoder
),
6943 new_crtc_state
->pixel_multiplier
- 1);
6945 if (new_crtc_state
->has_pch_encoder
)
6946 intel_cpu_transcoder_set_m_n(new_crtc_state
,
6947 &new_crtc_state
->fdi_m_n
, NULL
);
6949 if (!transcoder_is_dsi(cpu_transcoder
)) {
6950 hsw_set_frame_start_delay(new_crtc_state
);
6951 hsw_set_pipeconf(new_crtc_state
);
6954 if (INTEL_GEN(dev_priv
) >= 9 || IS_BROADWELL(dev_priv
))
6955 bdw_set_pipemisc(new_crtc_state
);
6957 crtc
->active
= true;
6959 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
6960 psl_clkgate_wa
= (IS_GEMINILAKE(dev_priv
) || IS_CANNONLAKE(dev_priv
)) &&
6961 new_crtc_state
->pch_pfit
.enabled
;
6963 glk_pipe_scaler_clock_gating_wa(dev_priv
, pipe
, true);
6965 if (INTEL_GEN(dev_priv
) >= 9)
6966 skl_pfit_enable(new_crtc_state
);
6968 ilk_pfit_enable(new_crtc_state
);
6971 * On ILK+ LUT must be loaded before the pipe is running but with
6974 intel_color_load_luts(new_crtc_state
);
6975 intel_color_commit(new_crtc_state
);
6976 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
6977 if (INTEL_GEN(dev_priv
) < 9)
6978 intel_disable_primary_plane(new_crtc_state
);
6980 if (INTEL_GEN(dev_priv
) >= 11)
6981 icl_set_pipe_chicken(crtc
);
6983 if (!transcoder_is_dsi(cpu_transcoder
))
6984 intel_ddi_enable_transcoder_func(new_crtc_state
);
6986 if (dev_priv
->display
.initial_watermarks
)
6987 dev_priv
->display
.initial_watermarks(state
, crtc
);
6989 if (INTEL_GEN(dev_priv
) >= 11)
6990 icl_pipe_mbus_enable(crtc
);
6992 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
6993 if (!transcoder_is_dsi(cpu_transcoder
))
6994 intel_enable_pipe(new_crtc_state
);
6996 if (new_crtc_state
->has_pch_encoder
)
6997 lpt_pch_enable(state
, new_crtc_state
);
6999 intel_crtc_vblank_on(new_crtc_state
);
7001 intel_encoders_enable(state
, crtc
);
7003 if (psl_clkgate_wa
) {
7004 intel_wait_for_vblank(dev_priv
, pipe
);
7005 glk_pipe_scaler_clock_gating_wa(dev_priv
, pipe
, false);
7008 /* If we change the relative order between pipe/planes enabling, we need
7009 * to change the workaround. */
7010 hsw_workaround_pipe
= new_crtc_state
->hsw_workaround_pipe
;
7011 if (IS_HASWELL(dev_priv
) && hsw_workaround_pipe
!= INVALID_PIPE
) {
7012 intel_wait_for_vblank(dev_priv
, hsw_workaround_pipe
);
7013 intel_wait_for_vblank(dev_priv
, hsw_workaround_pipe
);
7017 void ilk_pfit_disable(const struct intel_crtc_state
*old_crtc_state
)
7019 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->uapi
.crtc
);
7020 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7021 enum pipe pipe
= crtc
->pipe
;
7023 /* To avoid upsetting the power well on haswell only disable the pfit if
7024 * it's in use. The hw state code will make sure we get this right. */
7025 if (old_crtc_state
->pch_pfit
.enabled
) {
7026 I915_WRITE(PF_CTL(pipe
), 0);
7027 I915_WRITE(PF_WIN_POS(pipe
), 0);
7028 I915_WRITE(PF_WIN_SZ(pipe
), 0);
7032 static void ilk_crtc_disable(struct intel_atomic_state
*state
,
7033 struct intel_crtc
*crtc
)
7035 const struct intel_crtc_state
*old_crtc_state
=
7036 intel_atomic_get_old_crtc_state(state
, crtc
);
7037 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7038 enum pipe pipe
= crtc
->pipe
;
7041 * Sometimes spurious CPU pipe underruns happen when the
7042 * pipe is already disabled, but FDI RX/TX is still enabled.
7043 * Happens at least with VGA+HDMI cloning. Suppress them.
7045 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
7046 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
7048 intel_encoders_disable(state
, crtc
);
7050 intel_crtc_vblank_off(old_crtc_state
);
7052 intel_disable_pipe(old_crtc_state
);
7054 ilk_pfit_disable(old_crtc_state
);
7056 if (old_crtc_state
->has_pch_encoder
)
7057 ilk_fdi_disable(crtc
);
7059 intel_encoders_post_disable(state
, crtc
);
7061 if (old_crtc_state
->has_pch_encoder
) {
7062 ilk_disable_pch_transcoder(dev_priv
, pipe
);
7064 if (HAS_PCH_CPT(dev_priv
)) {
7068 /* disable TRANS_DP_CTL */
7069 reg
= TRANS_DP_CTL(pipe
);
7070 temp
= I915_READ(reg
);
7071 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
7072 TRANS_DP_PORT_SEL_MASK
);
7073 temp
|= TRANS_DP_PORT_SEL_NONE
;
7074 I915_WRITE(reg
, temp
);
7076 /* disable DPLL_SEL */
7077 temp
= I915_READ(PCH_DPLL_SEL
);
7078 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
7079 I915_WRITE(PCH_DPLL_SEL
, temp
);
7082 ilk_fdi_pll_disable(crtc
);
7085 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
7086 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
7089 static void hsw_crtc_disable(struct intel_atomic_state
*state
,
7090 struct intel_crtc
*crtc
)
7093 * FIXME collapse everything to one hook.
7094 * Need care with mst->ddi interactions.
7096 intel_encoders_disable(state
, crtc
);
7097 intel_encoders_post_disable(state
, crtc
);
7100 static void i9xx_pfit_enable(const struct intel_crtc_state
*crtc_state
)
7102 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
7103 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7105 if (!crtc_state
->gmch_pfit
.control
)
7109 * The panel fitter should only be adjusted whilst the pipe is disabled,
7110 * according to register description and PRM.
7112 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
7113 assert_pipe_disabled(dev_priv
, crtc_state
->cpu_transcoder
);
7115 I915_WRITE(PFIT_PGM_RATIOS
, crtc_state
->gmch_pfit
.pgm_ratios
);
7116 I915_WRITE(PFIT_CONTROL
, crtc_state
->gmch_pfit
.control
);
7118 /* Border color in case we don't scale up to the full screen. Black by
7119 * default, change to something else for debugging. */
7120 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
7123 bool intel_phy_is_combo(struct drm_i915_private
*dev_priv
, enum phy phy
)
7125 if (phy
== PHY_NONE
)
7128 if (IS_ELKHARTLAKE(dev_priv
))
7129 return phy
<= PHY_C
;
7131 if (INTEL_GEN(dev_priv
) >= 11)
7132 return phy
<= PHY_B
;
7137 bool intel_phy_is_tc(struct drm_i915_private
*dev_priv
, enum phy phy
)
7139 if (INTEL_GEN(dev_priv
) >= 12)
7140 return phy
>= PHY_D
&& phy
<= PHY_I
;
7142 if (INTEL_GEN(dev_priv
) >= 11 && !IS_ELKHARTLAKE(dev_priv
))
7143 return phy
>= PHY_C
&& phy
<= PHY_F
;
7148 enum phy
intel_port_to_phy(struct drm_i915_private
*i915
, enum port port
)
7150 if (IS_ELKHARTLAKE(i915
) && port
== PORT_D
)
7153 return (enum phy
)port
;
7156 enum tc_port
intel_port_to_tc(struct drm_i915_private
*dev_priv
, enum port port
)
7158 if (!intel_phy_is_tc(dev_priv
, intel_port_to_phy(dev_priv
, port
)))
7159 return PORT_TC_NONE
;
7161 if (INTEL_GEN(dev_priv
) >= 12)
7162 return port
- PORT_D
;
7164 return port
- PORT_C
;
7167 enum intel_display_power_domain
intel_port_to_power_domain(enum port port
)
7171 return POWER_DOMAIN_PORT_DDI_A_LANES
;
7173 return POWER_DOMAIN_PORT_DDI_B_LANES
;
7175 return POWER_DOMAIN_PORT_DDI_C_LANES
;
7177 return POWER_DOMAIN_PORT_DDI_D_LANES
;
7179 return POWER_DOMAIN_PORT_DDI_E_LANES
;
7181 return POWER_DOMAIN_PORT_DDI_F_LANES
;
7183 return POWER_DOMAIN_PORT_DDI_G_LANES
;
7186 return POWER_DOMAIN_PORT_OTHER
;
7190 enum intel_display_power_domain
7191 intel_aux_power_domain(struct intel_digital_port
*dig_port
)
7193 struct drm_i915_private
*dev_priv
= to_i915(dig_port
->base
.base
.dev
);
7194 enum phy phy
= intel_port_to_phy(dev_priv
, dig_port
->base
.port
);
7196 if (intel_phy_is_tc(dev_priv
, phy
) &&
7197 dig_port
->tc_mode
== TC_PORT_TBT_ALT
) {
7198 switch (dig_port
->aux_ch
) {
7200 return POWER_DOMAIN_AUX_C_TBT
;
7202 return POWER_DOMAIN_AUX_D_TBT
;
7204 return POWER_DOMAIN_AUX_E_TBT
;
7206 return POWER_DOMAIN_AUX_F_TBT
;
7208 return POWER_DOMAIN_AUX_G_TBT
;
7210 MISSING_CASE(dig_port
->aux_ch
);
7211 return POWER_DOMAIN_AUX_C_TBT
;
7215 switch (dig_port
->aux_ch
) {
7217 return POWER_DOMAIN_AUX_A
;
7219 return POWER_DOMAIN_AUX_B
;
7221 return POWER_DOMAIN_AUX_C
;
7223 return POWER_DOMAIN_AUX_D
;
7225 return POWER_DOMAIN_AUX_E
;
7227 return POWER_DOMAIN_AUX_F
;
7229 return POWER_DOMAIN_AUX_G
;
7231 MISSING_CASE(dig_port
->aux_ch
);
7232 return POWER_DOMAIN_AUX_A
;
7236 static u64
get_crtc_power_domains(struct intel_crtc_state
*crtc_state
)
7238 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
7239 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7240 struct drm_encoder
*encoder
;
7241 enum pipe pipe
= crtc
->pipe
;
7243 enum transcoder transcoder
= crtc_state
->cpu_transcoder
;
7245 if (!crtc_state
->hw
.active
)
7248 mask
= BIT_ULL(POWER_DOMAIN_PIPE(pipe
));
7249 mask
|= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder
));
7250 if (crtc_state
->pch_pfit
.enabled
||
7251 crtc_state
->pch_pfit
.force_thru
)
7252 mask
|= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
7254 drm_for_each_encoder_mask(encoder
, &dev_priv
->drm
,
7255 crtc_state
->uapi
.encoder_mask
) {
7256 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
7258 mask
|= BIT_ULL(intel_encoder
->power_domain
);
7261 if (HAS_DDI(dev_priv
) && crtc_state
->has_audio
)
7262 mask
|= BIT_ULL(POWER_DOMAIN_AUDIO
);
7264 if (crtc_state
->shared_dpll
)
7265 mask
|= BIT_ULL(POWER_DOMAIN_DISPLAY_CORE
);
7271 modeset_get_crtc_power_domains(struct intel_crtc_state
*crtc_state
)
7273 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
7274 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7275 enum intel_display_power_domain domain
;
7276 u64 domains
, new_domains
, old_domains
;
7278 old_domains
= crtc
->enabled_power_domains
;
7279 crtc
->enabled_power_domains
= new_domains
=
7280 get_crtc_power_domains(crtc_state
);
7282 domains
= new_domains
& ~old_domains
;
7284 for_each_power_domain(domain
, domains
)
7285 intel_display_power_get(dev_priv
, domain
);
7287 return old_domains
& ~new_domains
;
7290 static void modeset_put_power_domains(struct drm_i915_private
*dev_priv
,
7293 enum intel_display_power_domain domain
;
7295 for_each_power_domain(domain
, domains
)
7296 intel_display_power_put_unchecked(dev_priv
, domain
);
7299 static void valleyview_crtc_enable(struct intel_atomic_state
*state
,
7300 struct intel_crtc
*crtc
)
7302 const struct intel_crtc_state
*new_crtc_state
=
7303 intel_atomic_get_new_crtc_state(state
, crtc
);
7304 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7305 enum pipe pipe
= crtc
->pipe
;
7307 if (WARN_ON(crtc
->active
))
7310 if (intel_crtc_has_dp_encoder(new_crtc_state
))
7311 intel_dp_set_m_n(new_crtc_state
, M1_N1
);
7313 intel_set_pipe_timings(new_crtc_state
);
7314 intel_set_pipe_src_size(new_crtc_state
);
7316 if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_B
) {
7317 I915_WRITE(CHV_BLEND(pipe
), CHV_BLEND_LEGACY
);
7318 I915_WRITE(CHV_CANVAS(pipe
), 0);
7321 i9xx_set_pipeconf(new_crtc_state
);
7323 crtc
->active
= true;
7325 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
7327 intel_encoders_pre_pll_enable(state
, crtc
);
7329 if (IS_CHERRYVIEW(dev_priv
)) {
7330 chv_prepare_pll(crtc
, new_crtc_state
);
7331 chv_enable_pll(crtc
, new_crtc_state
);
7333 vlv_prepare_pll(crtc
, new_crtc_state
);
7334 vlv_enable_pll(crtc
, new_crtc_state
);
7337 intel_encoders_pre_enable(state
, crtc
);
7339 i9xx_pfit_enable(new_crtc_state
);
7341 intel_color_load_luts(new_crtc_state
);
7342 intel_color_commit(new_crtc_state
);
7343 /* update DSPCNTR to configure gamma for pipe bottom color */
7344 intel_disable_primary_plane(new_crtc_state
);
7346 dev_priv
->display
.initial_watermarks(state
, crtc
);
7347 intel_enable_pipe(new_crtc_state
);
7349 intel_crtc_vblank_on(new_crtc_state
);
7351 intel_encoders_enable(state
, crtc
);
7354 static void i9xx_set_pll_dividers(const struct intel_crtc_state
*crtc_state
)
7356 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
7357 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7359 I915_WRITE(FP0(crtc
->pipe
), crtc_state
->dpll_hw_state
.fp0
);
7360 I915_WRITE(FP1(crtc
->pipe
), crtc_state
->dpll_hw_state
.fp1
);
7363 static void i9xx_crtc_enable(struct intel_atomic_state
*state
,
7364 struct intel_crtc
*crtc
)
7366 const struct intel_crtc_state
*new_crtc_state
=
7367 intel_atomic_get_new_crtc_state(state
, crtc
);
7368 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7369 enum pipe pipe
= crtc
->pipe
;
7371 if (WARN_ON(crtc
->active
))
7374 i9xx_set_pll_dividers(new_crtc_state
);
7376 if (intel_crtc_has_dp_encoder(new_crtc_state
))
7377 intel_dp_set_m_n(new_crtc_state
, M1_N1
);
7379 intel_set_pipe_timings(new_crtc_state
);
7380 intel_set_pipe_src_size(new_crtc_state
);
7382 i9xx_set_pipeconf(new_crtc_state
);
7384 crtc
->active
= true;
7386 if (!IS_GEN(dev_priv
, 2))
7387 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
7389 intel_encoders_pre_enable(state
, crtc
);
7391 i9xx_enable_pll(crtc
, new_crtc_state
);
7393 i9xx_pfit_enable(new_crtc_state
);
7395 intel_color_load_luts(new_crtc_state
);
7396 intel_color_commit(new_crtc_state
);
7397 /* update DSPCNTR to configure gamma for pipe bottom color */
7398 intel_disable_primary_plane(new_crtc_state
);
7400 if (dev_priv
->display
.initial_watermarks
)
7401 dev_priv
->display
.initial_watermarks(state
, crtc
);
7403 intel_update_watermarks(crtc
);
7404 intel_enable_pipe(new_crtc_state
);
7406 intel_crtc_vblank_on(new_crtc_state
);
7408 intel_encoders_enable(state
, crtc
);
7411 static void i9xx_pfit_disable(const struct intel_crtc_state
*old_crtc_state
)
7413 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->uapi
.crtc
);
7414 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7416 if (!old_crtc_state
->gmch_pfit
.control
)
7419 assert_pipe_disabled(dev_priv
, old_crtc_state
->cpu_transcoder
);
7421 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
7422 I915_READ(PFIT_CONTROL
));
7423 I915_WRITE(PFIT_CONTROL
, 0);
7426 static void i9xx_crtc_disable(struct intel_atomic_state
*state
,
7427 struct intel_crtc
*crtc
)
7429 struct intel_crtc_state
*old_crtc_state
=
7430 intel_atomic_get_old_crtc_state(state
, crtc
);
7431 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7432 enum pipe pipe
= crtc
->pipe
;
7435 * On gen2 planes are double buffered but the pipe isn't, so we must
7436 * wait for planes to fully turn off before disabling the pipe.
7438 if (IS_GEN(dev_priv
, 2))
7439 intel_wait_for_vblank(dev_priv
, pipe
);
7441 intel_encoders_disable(state
, crtc
);
7443 intel_crtc_vblank_off(old_crtc_state
);
7445 intel_disable_pipe(old_crtc_state
);
7447 i9xx_pfit_disable(old_crtc_state
);
7449 intel_encoders_post_disable(state
, crtc
);
7451 if (!intel_crtc_has_type(old_crtc_state
, INTEL_OUTPUT_DSI
)) {
7452 if (IS_CHERRYVIEW(dev_priv
))
7453 chv_disable_pll(dev_priv
, pipe
);
7454 else if (IS_VALLEYVIEW(dev_priv
))
7455 vlv_disable_pll(dev_priv
, pipe
);
7457 i9xx_disable_pll(old_crtc_state
);
7460 intel_encoders_post_pll_disable(state
, crtc
);
7462 if (!IS_GEN(dev_priv
, 2))
7463 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
7465 if (!dev_priv
->display
.initial_watermarks
)
7466 intel_update_watermarks(crtc
);
7468 /* clock the pipe down to 640x480@60 to potentially save power */
7469 if (IS_I830(dev_priv
))
7470 i830_enable_pipe(dev_priv
, pipe
);
7473 static void intel_crtc_disable_noatomic(struct intel_crtc
*crtc
,
7474 struct drm_modeset_acquire_ctx
*ctx
)
7476 struct intel_encoder
*encoder
;
7477 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7478 struct intel_bw_state
*bw_state
=
7479 to_intel_bw_state(dev_priv
->bw_obj
.state
);
7480 struct intel_crtc_state
*crtc_state
=
7481 to_intel_crtc_state(crtc
->base
.state
);
7482 enum intel_display_power_domain domain
;
7483 struct intel_plane
*plane
;
7484 struct drm_atomic_state
*state
;
7485 struct intel_crtc_state
*temp_crtc_state
;
7486 enum pipe pipe
= crtc
->pipe
;
7490 if (!crtc_state
->hw
.active
)
7493 for_each_intel_plane_on_crtc(&dev_priv
->drm
, crtc
, plane
) {
7494 const struct intel_plane_state
*plane_state
=
7495 to_intel_plane_state(plane
->base
.state
);
7497 if (plane_state
->uapi
.visible
)
7498 intel_plane_disable_noatomic(crtc
, plane
);
7501 state
= drm_atomic_state_alloc(&dev_priv
->drm
);
7503 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
7504 crtc
->base
.base
.id
, crtc
->base
.name
);
7508 state
->acquire_ctx
= ctx
;
7510 /* Everything's already locked, -EDEADLK can't happen. */
7511 temp_crtc_state
= intel_atomic_get_crtc_state(state
, crtc
);
7512 ret
= drm_atomic_add_affected_connectors(state
, &crtc
->base
);
7514 WARN_ON(IS_ERR(temp_crtc_state
) || ret
);
7516 dev_priv
->display
.crtc_disable(to_intel_atomic_state(state
), crtc
);
7518 drm_atomic_state_put(state
);
7520 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
7521 crtc
->base
.base
.id
, crtc
->base
.name
);
7523 crtc
->active
= false;
7524 crtc
->base
.enabled
= false;
7526 WARN_ON(drm_atomic_set_mode_for_crtc(&crtc_state
->uapi
, NULL
) < 0);
7527 crtc_state
->uapi
.active
= false;
7528 crtc_state
->uapi
.connector_mask
= 0;
7529 crtc_state
->uapi
.encoder_mask
= 0;
7530 intel_crtc_free_hw_state(crtc_state
);
7531 memset(&crtc_state
->hw
, 0, sizeof(crtc_state
->hw
));
7533 for_each_encoder_on_crtc(&dev_priv
->drm
, &crtc
->base
, encoder
)
7534 encoder
->base
.crtc
= NULL
;
7536 intel_fbc_disable(crtc
);
7537 intel_update_watermarks(crtc
);
7538 intel_disable_shared_dpll(crtc_state
);
7540 domains
= crtc
->enabled_power_domains
;
7541 for_each_power_domain(domain
, domains
)
7542 intel_display_power_put_unchecked(dev_priv
, domain
);
7543 crtc
->enabled_power_domains
= 0;
7545 dev_priv
->active_pipes
&= ~BIT(pipe
);
7546 dev_priv
->min_cdclk
[pipe
] = 0;
7547 dev_priv
->min_voltage_level
[pipe
] = 0;
7549 bw_state
->data_rate
[pipe
] = 0;
7550 bw_state
->num_active_planes
[pipe
] = 0;
7554 * turn all crtc's off, but do not adjust state
7555 * This has to be paired with a call to intel_modeset_setup_hw_state.
7557 int intel_display_suspend(struct drm_device
*dev
)
7559 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7560 struct drm_atomic_state
*state
;
7563 state
= drm_atomic_helper_suspend(dev
);
7564 ret
= PTR_ERR_OR_ZERO(state
);
7566 DRM_ERROR("Suspending crtc's failed with %i\n", ret
);
7568 dev_priv
->modeset_restore_state
= state
;
7572 void intel_encoder_destroy(struct drm_encoder
*encoder
)
7574 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
7576 drm_encoder_cleanup(encoder
);
7577 kfree(intel_encoder
);
7580 /* Cross check the actual hw state with our own modeset state tracking (and it's
7581 * internal consistency). */
7582 static void intel_connector_verify_state(struct intel_crtc_state
*crtc_state
,
7583 struct drm_connector_state
*conn_state
)
7585 struct intel_connector
*connector
= to_intel_connector(conn_state
->connector
);
7587 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
7588 connector
->base
.base
.id
,
7589 connector
->base
.name
);
7591 if (connector
->get_hw_state(connector
)) {
7592 struct intel_encoder
*encoder
= connector
->encoder
;
7594 I915_STATE_WARN(!crtc_state
,
7595 "connector enabled without attached crtc\n");
7600 I915_STATE_WARN(!crtc_state
->hw
.active
,
7601 "connector is active, but attached crtc isn't\n");
7603 if (!encoder
|| encoder
->type
== INTEL_OUTPUT_DP_MST
)
7606 I915_STATE_WARN(conn_state
->best_encoder
!= &encoder
->base
,
7607 "atomic encoder doesn't match attached encoder\n");
7609 I915_STATE_WARN(conn_state
->crtc
!= encoder
->base
.crtc
,
7610 "attached encoder crtc differs from connector crtc\n");
7612 I915_STATE_WARN(crtc_state
&& crtc_state
->hw
.active
,
7613 "attached crtc is active, but connector isn't\n");
7614 I915_STATE_WARN(!crtc_state
&& conn_state
->best_encoder
,
7615 "best encoder set without crtc!\n");
7619 static int pipe_required_fdi_lanes(struct intel_crtc_state
*crtc_state
)
7621 if (crtc_state
->hw
.enable
&& crtc_state
->has_pch_encoder
)
7622 return crtc_state
->fdi_lanes
;
7627 static int ilk_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
7628 struct intel_crtc_state
*pipe_config
)
7630 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7631 struct drm_atomic_state
*state
= pipe_config
->uapi
.state
;
7632 struct intel_crtc
*other_crtc
;
7633 struct intel_crtc_state
*other_crtc_state
;
7635 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
7636 pipe_name(pipe
), pipe_config
->fdi_lanes
);
7637 if (pipe_config
->fdi_lanes
> 4) {
7638 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
7639 pipe_name(pipe
), pipe_config
->fdi_lanes
);
7643 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
7644 if (pipe_config
->fdi_lanes
> 2) {
7645 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
7646 pipe_config
->fdi_lanes
);
7653 if (INTEL_NUM_PIPES(dev_priv
) == 2)
7656 /* Ivybridge 3 pipe is really complicated */
7661 if (pipe_config
->fdi_lanes
<= 2)
7664 other_crtc
= intel_get_crtc_for_pipe(dev_priv
, PIPE_C
);
7666 intel_atomic_get_crtc_state(state
, other_crtc
);
7667 if (IS_ERR(other_crtc_state
))
7668 return PTR_ERR(other_crtc_state
);
7670 if (pipe_required_fdi_lanes(other_crtc_state
) > 0) {
7671 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
7672 pipe_name(pipe
), pipe_config
->fdi_lanes
);
7677 if (pipe_config
->fdi_lanes
> 2) {
7678 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
7679 pipe_name(pipe
), pipe_config
->fdi_lanes
);
7683 other_crtc
= intel_get_crtc_for_pipe(dev_priv
, PIPE_B
);
7685 intel_atomic_get_crtc_state(state
, other_crtc
);
7686 if (IS_ERR(other_crtc_state
))
7687 return PTR_ERR(other_crtc_state
);
7689 if (pipe_required_fdi_lanes(other_crtc_state
) > 2) {
7690 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
7700 static int ilk_fdi_compute_config(struct intel_crtc
*intel_crtc
,
7701 struct intel_crtc_state
*pipe_config
)
7703 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7704 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->hw
.adjusted_mode
;
7705 int lane
, link_bw
, fdi_dotclock
, ret
;
7706 bool needs_recompute
= false;
7709 /* FDI is a binary signal running at ~2.7GHz, encoding
7710 * each output octet as 10 bits. The actual frequency
7711 * is stored as a divider into a 100MHz clock, and the
7712 * mode pixel clock is stored in units of 1KHz.
7713 * Hence the bw of each lane in terms of the mode signal
7716 link_bw
= intel_fdi_link_freq(to_i915(dev
), pipe_config
);
7718 fdi_dotclock
= adjusted_mode
->crtc_clock
;
7720 lane
= ilk_get_lanes_required(fdi_dotclock
, link_bw
,
7721 pipe_config
->pipe_bpp
);
7723 pipe_config
->fdi_lanes
= lane
;
7725 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
7726 link_bw
, &pipe_config
->fdi_m_n
, false, false);
7728 ret
= ilk_check_fdi_lanes(dev
, intel_crtc
->pipe
, pipe_config
);
7729 if (ret
== -EDEADLK
)
7732 if (ret
== -EINVAL
&& pipe_config
->pipe_bpp
> 6*3) {
7733 pipe_config
->pipe_bpp
-= 2*3;
7734 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
7735 pipe_config
->pipe_bpp
);
7736 needs_recompute
= true;
7737 pipe_config
->bw_constrained
= true;
7742 if (needs_recompute
)
7748 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state
*crtc_state
)
7750 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
7751 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7753 /* IPS only exists on ULT machines and is tied to pipe A. */
7754 if (!hsw_crtc_supports_ips(crtc
))
7757 if (!i915_modparams
.enable_ips
)
7760 if (crtc_state
->pipe_bpp
> 24)
7764 * We compare against max which means we must take
7765 * the increased cdclk requirement into account when
7766 * calculating the new cdclk.
7768 * Should measure whether using a lower cdclk w/o IPS
7770 if (IS_BROADWELL(dev_priv
) &&
7771 crtc_state
->pixel_rate
> dev_priv
->max_cdclk_freq
* 95 / 100)
7777 static bool hsw_compute_ips_config(struct intel_crtc_state
*crtc_state
)
7779 struct drm_i915_private
*dev_priv
=
7780 to_i915(crtc_state
->uapi
.crtc
->dev
);
7781 struct intel_atomic_state
*intel_state
=
7782 to_intel_atomic_state(crtc_state
->uapi
.state
);
7784 if (!hsw_crtc_state_ips_capable(crtc_state
))
7788 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
7789 * enabled and disabled dynamically based on package C states,
7790 * user space can't make reliable use of the CRCs, so let's just
7791 * completely disable it.
7793 if (crtc_state
->crc_enabled
)
7796 /* IPS should be fine as long as at least one plane is enabled. */
7797 if (!(crtc_state
->active_planes
& ~BIT(PLANE_CURSOR
)))
7800 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
7801 if (IS_BROADWELL(dev_priv
) &&
7802 crtc_state
->pixel_rate
> intel_state
->cdclk
.logical
.cdclk
* 95 / 100)
7808 static bool intel_crtc_supports_double_wide(const struct intel_crtc
*crtc
)
7810 const struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7812 /* GDG double wide on either pipe, otherwise pipe A only */
7813 return INTEL_GEN(dev_priv
) < 4 &&
7814 (crtc
->pipe
== PIPE_A
|| IS_I915G(dev_priv
));
7817 static u32
ilk_pipe_pixel_rate(const struct intel_crtc_state
*pipe_config
)
7821 pixel_rate
= pipe_config
->hw
.adjusted_mode
.crtc_clock
;
7824 * We only use IF-ID interlacing. If we ever use
7825 * PF-ID we'll need to adjust the pixel_rate here.
7828 if (pipe_config
->pch_pfit
.enabled
) {
7829 u64 pipe_w
, pipe_h
, pfit_w
, pfit_h
;
7830 u32 pfit_size
= pipe_config
->pch_pfit
.size
;
7832 pipe_w
= pipe_config
->pipe_src_w
;
7833 pipe_h
= pipe_config
->pipe_src_h
;
7835 pfit_w
= (pfit_size
>> 16) & 0xFFFF;
7836 pfit_h
= pfit_size
& 0xFFFF;
7837 if (pipe_w
< pfit_w
)
7839 if (pipe_h
< pfit_h
)
7842 if (WARN_ON(!pfit_w
|| !pfit_h
))
7845 pixel_rate
= div_u64(mul_u32_u32(pixel_rate
, pipe_w
* pipe_h
),
7852 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state
*crtc_state
)
7854 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->uapi
.crtc
->dev
);
7856 if (HAS_GMCH(dev_priv
))
7857 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
7858 crtc_state
->pixel_rate
=
7859 crtc_state
->hw
.adjusted_mode
.crtc_clock
;
7861 crtc_state
->pixel_rate
=
7862 ilk_pipe_pixel_rate(crtc_state
);
7865 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
7866 struct intel_crtc_state
*pipe_config
)
7868 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7869 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->hw
.adjusted_mode
;
7870 int clock_limit
= dev_priv
->max_dotclk_freq
;
7872 if (INTEL_GEN(dev_priv
) < 4) {
7873 clock_limit
= dev_priv
->max_cdclk_freq
* 9 / 10;
7876 * Enable double wide mode when the dot clock
7877 * is > 90% of the (display) core speed.
7879 if (intel_crtc_supports_double_wide(crtc
) &&
7880 adjusted_mode
->crtc_clock
> clock_limit
) {
7881 clock_limit
= dev_priv
->max_dotclk_freq
;
7882 pipe_config
->double_wide
= true;
7886 if (adjusted_mode
->crtc_clock
> clock_limit
) {
7887 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
7888 adjusted_mode
->crtc_clock
, clock_limit
,
7889 yesno(pipe_config
->double_wide
));
7893 if ((pipe_config
->output_format
== INTEL_OUTPUT_FORMAT_YCBCR420
||
7894 pipe_config
->output_format
== INTEL_OUTPUT_FORMAT_YCBCR444
) &&
7895 pipe_config
->hw
.ctm
) {
7897 * There is only one pipe CSC unit per pipe, and we need that
7898 * for output conversion from RGB->YCBCR. So if CTM is already
7899 * applied we can't support YCBCR420 output.
7901 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
7906 * Pipe horizontal size must be even in:
7908 * - LVDS dual channel mode
7909 * - Double wide pipe
7911 if (pipe_config
->pipe_src_w
& 1) {
7912 if (pipe_config
->double_wide
) {
7913 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
7917 if (intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_LVDS
) &&
7918 intel_is_dual_link_lvds(dev_priv
)) {
7919 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
7924 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
7925 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
7927 if ((INTEL_GEN(dev_priv
) > 4 || IS_G4X(dev_priv
)) &&
7928 adjusted_mode
->crtc_hsync_start
== adjusted_mode
->crtc_hdisplay
)
7931 intel_crtc_compute_pixel_rate(pipe_config
);
7933 if (pipe_config
->has_pch_encoder
)
7934 return ilk_fdi_compute_config(crtc
, pipe_config
);
7940 intel_reduce_m_n_ratio(u32
*num
, u32
*den
)
7942 while (*num
> DATA_LINK_M_N_MASK
||
7943 *den
> DATA_LINK_M_N_MASK
) {
7949 static void compute_m_n(unsigned int m
, unsigned int n
,
7950 u32
*ret_m
, u32
*ret_n
,
7954 * Several DP dongles in particular seem to be fussy about
7955 * too large link M/N values. Give N value as 0x8000 that
7956 * should be acceptable by specific devices. 0x8000 is the
7957 * specified fixed N value for asynchronous clock mode,
7958 * which the devices expect also in synchronous clock mode.
7963 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
7965 *ret_m
= div_u64(mul_u32_u32(m
, *ret_n
), n
);
7966 intel_reduce_m_n_ratio(ret_m
, ret_n
);
7970 intel_link_compute_m_n(u16 bits_per_pixel
, int nlanes
,
7971 int pixel_clock
, int link_clock
,
7972 struct intel_link_m_n
*m_n
,
7973 bool constant_n
, bool fec_enable
)
7975 u32 data_clock
= bits_per_pixel
* pixel_clock
;
7978 data_clock
= intel_dp_mode_to_fec_clock(data_clock
);
7981 compute_m_n(data_clock
,
7982 link_clock
* nlanes
* 8,
7983 &m_n
->gmch_m
, &m_n
->gmch_n
,
7986 compute_m_n(pixel_clock
, link_clock
,
7987 &m_n
->link_m
, &m_n
->link_n
,
7991 static void intel_panel_sanitize_ssc(struct drm_i915_private
*dev_priv
)
7994 * There may be no VBT; and if the BIOS enabled SSC we can
7995 * just keep using it to avoid unnecessary flicker. Whereas if the
7996 * BIOS isn't using it, don't assume it will work even if the VBT
7997 * indicates as much.
7999 if (HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
)) {
8000 bool bios_lvds_use_ssc
= I915_READ(PCH_DREF_CONTROL
) &
8003 if (dev_priv
->vbt
.lvds_use_ssc
!= bios_lvds_use_ssc
) {
8004 DRM_DEBUG_KMS("SSC %s by BIOS, overriding VBT which says %s\n",
8005 enableddisabled(bios_lvds_use_ssc
),
8006 enableddisabled(dev_priv
->vbt
.lvds_use_ssc
));
8007 dev_priv
->vbt
.lvds_use_ssc
= bios_lvds_use_ssc
;
8012 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
8014 if (i915_modparams
.panel_use_ssc
>= 0)
8015 return i915_modparams
.panel_use_ssc
!= 0;
8016 return dev_priv
->vbt
.lvds_use_ssc
8017 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
8020 static u32
pnv_dpll_compute_fp(struct dpll
*dpll
)
8022 return (1 << dpll
->n
) << 16 | dpll
->m2
;
8025 static u32
i9xx_dpll_compute_fp(struct dpll
*dpll
)
8027 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
8030 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
8031 struct intel_crtc_state
*crtc_state
,
8032 struct dpll
*reduced_clock
)
8034 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
8037 if (IS_PINEVIEW(dev_priv
)) {
8038 fp
= pnv_dpll_compute_fp(&crtc_state
->dpll
);
8040 fp2
= pnv_dpll_compute_fp(reduced_clock
);
8042 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
8044 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
8047 crtc_state
->dpll_hw_state
.fp0
= fp
;
8049 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
8051 crtc_state
->dpll_hw_state
.fp1
= fp2
;
8053 crtc_state
->dpll_hw_state
.fp1
= fp
;
8057 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
8063 * PLLB opamp always calibrates to max value of 0x3f, force enable it
8064 * and set it to a reasonable value instead.
8066 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
8067 reg_val
&= 0xffffff00;
8068 reg_val
|= 0x00000030;
8069 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
8071 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
8072 reg_val
&= 0x00ffffff;
8073 reg_val
|= 0x8c000000;
8074 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
8076 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
8077 reg_val
&= 0xffffff00;
8078 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
8080 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
8081 reg_val
&= 0x00ffffff;
8082 reg_val
|= 0xb0000000;
8083 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
8086 static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state
*crtc_state
,
8087 const struct intel_link_m_n
*m_n
)
8089 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
8090 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
8091 enum pipe pipe
= crtc
->pipe
;
8093 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
8094 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
8095 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
8096 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
8099 static bool transcoder_has_m2_n2(struct drm_i915_private
*dev_priv
,
8100 enum transcoder transcoder
)
8102 if (IS_HASWELL(dev_priv
))
8103 return transcoder
== TRANSCODER_EDP
;
8106 * Strictly speaking some registers are available before
8107 * gen7, but we only support DRRS on gen7+
8109 return IS_GEN(dev_priv
, 7) || IS_CHERRYVIEW(dev_priv
);
8112 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state
*crtc_state
,
8113 const struct intel_link_m_n
*m_n
,
8114 const struct intel_link_m_n
*m2_n2
)
8116 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
8117 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
8118 enum pipe pipe
= crtc
->pipe
;
8119 enum transcoder transcoder
= crtc_state
->cpu_transcoder
;
8121 if (INTEL_GEN(dev_priv
) >= 5) {
8122 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
8123 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
8124 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
8125 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
8127 * M2_N2 registers are set only if DRRS is supported
8128 * (to make sure the registers are not unnecessarily accessed).
8130 if (m2_n2
&& crtc_state
->has_drrs
&&
8131 transcoder_has_m2_n2(dev_priv
, transcoder
)) {
8132 I915_WRITE(PIPE_DATA_M2(transcoder
),
8133 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
8134 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
8135 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
8136 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
8139 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
8140 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
8141 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
8142 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
8146 void intel_dp_set_m_n(const struct intel_crtc_state
*crtc_state
, enum link_m_n_set m_n
)
8148 const struct intel_link_m_n
*dp_m_n
, *dp_m2_n2
= NULL
;
8151 dp_m_n
= &crtc_state
->dp_m_n
;
8152 dp_m2_n2
= &crtc_state
->dp_m2_n2
;
8153 } else if (m_n
== M2_N2
) {
8156 * M2_N2 registers are not supported. Hence m2_n2 divider value
8157 * needs to be programmed into M1_N1.
8159 dp_m_n
= &crtc_state
->dp_m2_n2
;
8161 DRM_ERROR("Unsupported divider value\n");
8165 if (crtc_state
->has_pch_encoder
)
8166 intel_pch_transcoder_set_m_n(crtc_state
, &crtc_state
->dp_m_n
);
8168 intel_cpu_transcoder_set_m_n(crtc_state
, dp_m_n
, dp_m2_n2
);
8171 static void vlv_compute_dpll(struct intel_crtc
*crtc
,
8172 struct intel_crtc_state
*pipe_config
)
8174 pipe_config
->dpll_hw_state
.dpll
= DPLL_INTEGRATED_REF_CLK_VLV
|
8175 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
8176 if (crtc
->pipe
!= PIPE_A
)
8177 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
8179 /* DPLL not used with DSI, but still need the rest set up */
8180 if (!intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_DSI
))
8181 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
|
8182 DPLL_EXT_BUFFER_ENABLE_VLV
;
8184 pipe_config
->dpll_hw_state
.dpll_md
=
8185 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
8188 static void chv_compute_dpll(struct intel_crtc
*crtc
,
8189 struct intel_crtc_state
*pipe_config
)
8191 pipe_config
->dpll_hw_state
.dpll
= DPLL_SSC_REF_CLK_CHV
|
8192 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
8193 if (crtc
->pipe
!= PIPE_A
)
8194 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
8196 /* DPLL not used with DSI, but still need the rest set up */
8197 if (!intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_DSI
))
8198 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
;
8200 pipe_config
->dpll_hw_state
.dpll_md
=
8201 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
8204 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
8205 const struct intel_crtc_state
*pipe_config
)
8207 struct drm_device
*dev
= crtc
->base
.dev
;
8208 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8209 enum pipe pipe
= crtc
->pipe
;
8211 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
8212 u32 coreclk
, reg_val
;
8215 I915_WRITE(DPLL(pipe
),
8216 pipe_config
->dpll_hw_state
.dpll
&
8217 ~(DPLL_VCO_ENABLE
| DPLL_EXT_BUFFER_ENABLE_VLV
));
8219 /* No need to actually set up the DPLL with DSI */
8220 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
8223 vlv_dpio_get(dev_priv
);
8225 bestn
= pipe_config
->dpll
.n
;
8226 bestm1
= pipe_config
->dpll
.m1
;
8227 bestm2
= pipe_config
->dpll
.m2
;
8228 bestp1
= pipe_config
->dpll
.p1
;
8229 bestp2
= pipe_config
->dpll
.p2
;
8231 /* See eDP HDMI DPIO driver vbios notes doc */
8233 /* PLL B needs special handling */
8235 vlv_pllb_recal_opamp(dev_priv
, pipe
);
8237 /* Set up Tx target for periodic Rcomp update */
8238 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
8240 /* Disable target IRef on PLL */
8241 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
8242 reg_val
&= 0x00ffffff;
8243 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
8245 /* Disable fast lock */
8246 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
8248 /* Set idtafcrecal before PLL is enabled */
8249 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
8250 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
8251 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
8252 mdiv
|= (1 << DPIO_K_SHIFT
);
8255 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
8256 * but we don't support that).
8257 * Note: don't use the DAC post divider as it seems unstable.
8259 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
8260 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
8262 mdiv
|= DPIO_ENABLE_CALIBRATION
;
8263 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
8265 /* Set HBR and RBR LPF coefficients */
8266 if (pipe_config
->port_clock
== 162000 ||
8267 intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_ANALOG
) ||
8268 intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_HDMI
))
8269 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
8272 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
8275 if (intel_crtc_has_dp_encoder(pipe_config
)) {
8276 /* Use SSC source */
8278 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
8281 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
8283 } else { /* HDMI or VGA */
8284 /* Use bend source */
8286 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
8289 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
8293 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
8294 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
8295 if (intel_crtc_has_dp_encoder(pipe_config
))
8296 coreclk
|= 0x01000000;
8297 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
8299 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
8301 vlv_dpio_put(dev_priv
);
8304 static void chv_prepare_pll(struct intel_crtc
*crtc
,
8305 const struct intel_crtc_state
*pipe_config
)
8307 struct drm_device
*dev
= crtc
->base
.dev
;
8308 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8309 enum pipe pipe
= crtc
->pipe
;
8310 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
8311 u32 loopfilter
, tribuf_calcntr
;
8312 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
8316 /* Enable Refclk and SSC */
8317 I915_WRITE(DPLL(pipe
),
8318 pipe_config
->dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
8320 /* No need to actually set up the DPLL with DSI */
8321 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
8324 bestn
= pipe_config
->dpll
.n
;
8325 bestm2_frac
= pipe_config
->dpll
.m2
& 0x3fffff;
8326 bestm1
= pipe_config
->dpll
.m1
;
8327 bestm2
= pipe_config
->dpll
.m2
>> 22;
8328 bestp1
= pipe_config
->dpll
.p1
;
8329 bestp2
= pipe_config
->dpll
.p2
;
8330 vco
= pipe_config
->dpll
.vco
;
8334 vlv_dpio_get(dev_priv
);
8336 /* p1 and p2 divider */
8337 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
8338 5 << DPIO_CHV_S1_DIV_SHIFT
|
8339 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
8340 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
8341 1 << DPIO_CHV_K_DIV_SHIFT
);
8343 /* Feedback post-divider - m2 */
8344 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
8346 /* Feedback refclk divider - n and m1 */
8347 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
8348 DPIO_CHV_M1_DIV_BY_2
|
8349 1 << DPIO_CHV_N_DIV_SHIFT
);
8351 /* M2 fraction division */
8352 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
8354 /* M2 fraction division enable */
8355 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
8356 dpio_val
&= ~(DPIO_CHV_FEEDFWD_GAIN_MASK
| DPIO_CHV_FRAC_DIV_EN
);
8357 dpio_val
|= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
);
8359 dpio_val
|= DPIO_CHV_FRAC_DIV_EN
;
8360 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
), dpio_val
);
8362 /* Program digital lock detect threshold */
8363 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW9(port
));
8364 dpio_val
&= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK
|
8365 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
);
8366 dpio_val
|= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT
);
8368 dpio_val
|= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
;
8369 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW9(port
), dpio_val
);
8372 if (vco
== 5400000) {
8373 loopfilter
|= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT
);
8374 loopfilter
|= (0x8 << DPIO_CHV_INT_COEFF_SHIFT
);
8375 loopfilter
|= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT
);
8376 tribuf_calcntr
= 0x9;
8377 } else if (vco
<= 6200000) {
8378 loopfilter
|= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT
);
8379 loopfilter
|= (0xB << DPIO_CHV_INT_COEFF_SHIFT
);
8380 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
8381 tribuf_calcntr
= 0x9;
8382 } else if (vco
<= 6480000) {
8383 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
8384 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
8385 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
8386 tribuf_calcntr
= 0x8;
8388 /* Not supported. Apply the same limits as in the max case */
8389 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
8390 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
8391 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
8394 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
8396 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW8(port
));
8397 dpio_val
&= ~DPIO_CHV_TDC_TARGET_CNT_MASK
;
8398 dpio_val
|= (tribuf_calcntr
<< DPIO_CHV_TDC_TARGET_CNT_SHIFT
);
8399 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW8(port
), dpio_val
);
8402 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
8403 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
8406 vlv_dpio_put(dev_priv
);
8410 * vlv_force_pll_on - forcibly enable just the PLL
8411 * @dev_priv: i915 private structure
8412 * @pipe: pipe PLL to enable
8413 * @dpll: PLL configuration
8415 * Enable the PLL for @pipe using the supplied @dpll config. To be used
8416 * in cases where we need the PLL enabled even when @pipe is not going to
8419 int vlv_force_pll_on(struct drm_i915_private
*dev_priv
, enum pipe pipe
,
8420 const struct dpll
*dpll
)
8422 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
8423 struct intel_crtc_state
*pipe_config
;
8425 pipe_config
= intel_crtc_state_alloc(crtc
);
8429 pipe_config
->cpu_transcoder
= (enum transcoder
)pipe
;
8430 pipe_config
->pixel_multiplier
= 1;
8431 pipe_config
->dpll
= *dpll
;
8433 if (IS_CHERRYVIEW(dev_priv
)) {
8434 chv_compute_dpll(crtc
, pipe_config
);
8435 chv_prepare_pll(crtc
, pipe_config
);
8436 chv_enable_pll(crtc
, pipe_config
);
8438 vlv_compute_dpll(crtc
, pipe_config
);
8439 vlv_prepare_pll(crtc
, pipe_config
);
8440 vlv_enable_pll(crtc
, pipe_config
);
8449 * vlv_force_pll_off - forcibly disable just the PLL
8450 * @dev_priv: i915 private structure
8451 * @pipe: pipe PLL to disable
8453 * Disable the PLL for @pipe. To be used in cases where we need
8454 * the PLL enabled even when @pipe is not going to be enabled.
8456 void vlv_force_pll_off(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
8458 if (IS_CHERRYVIEW(dev_priv
))
8459 chv_disable_pll(dev_priv
, pipe
);
8461 vlv_disable_pll(dev_priv
, pipe
);
8464 static void i9xx_compute_dpll(struct intel_crtc
*crtc
,
8465 struct intel_crtc_state
*crtc_state
,
8466 struct dpll
*reduced_clock
)
8468 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
8470 struct dpll
*clock
= &crtc_state
->dpll
;
8472 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
8474 dpll
= DPLL_VGA_MODE_DIS
;
8476 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
))
8477 dpll
|= DPLLB_MODE_LVDS
;
8479 dpll
|= DPLLB_MODE_DAC_SERIAL
;
8481 if (IS_I945G(dev_priv
) || IS_I945GM(dev_priv
) ||
8482 IS_G33(dev_priv
) || IS_PINEVIEW(dev_priv
)) {
8483 dpll
|= (crtc_state
->pixel_multiplier
- 1)
8484 << SDVO_MULTIPLIER_SHIFT_HIRES
;
8487 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
8488 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
8489 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8491 if (intel_crtc_has_dp_encoder(crtc_state
))
8492 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8494 /* compute bitmask from p1 value */
8495 if (IS_PINEVIEW(dev_priv
))
8496 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
8498 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8499 if (IS_G4X(dev_priv
) && reduced_clock
)
8500 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
8502 switch (clock
->p2
) {
8504 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
8507 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
8510 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
8513 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
8516 if (INTEL_GEN(dev_priv
) >= 4)
8517 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
8519 if (crtc_state
->sdvo_tv_clock
)
8520 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
8521 else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
8522 intel_panel_use_ssc(dev_priv
))
8523 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
8525 dpll
|= PLL_REF_INPUT_DREFCLK
;
8527 dpll
|= DPLL_VCO_ENABLE
;
8528 crtc_state
->dpll_hw_state
.dpll
= dpll
;
8530 if (INTEL_GEN(dev_priv
) >= 4) {
8531 u32 dpll_md
= (crtc_state
->pixel_multiplier
- 1)
8532 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
8533 crtc_state
->dpll_hw_state
.dpll_md
= dpll_md
;
8537 static void i8xx_compute_dpll(struct intel_crtc
*crtc
,
8538 struct intel_crtc_state
*crtc_state
,
8539 struct dpll
*reduced_clock
)
8541 struct drm_device
*dev
= crtc
->base
.dev
;
8542 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8544 struct dpll
*clock
= &crtc_state
->dpll
;
8546 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
8548 dpll
= DPLL_VGA_MODE_DIS
;
8550 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8551 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8554 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
8556 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8558 dpll
|= PLL_P2_DIVIDE_BY_4
;
8563 * "[Almador Errata}: For the correct operation of the muxed DVO pins
8564 * (GDEVSELB/I2Cdata, GIRDBY/I2CClk) and (GFRAMEB/DVI_Data,
8565 * GTRDYB/DVI_Clk): Bit 31 (DPLL VCO Enable) and Bit 30 (2X Clock
8566 * Enable) must be set to “1” in both the DPLL A Control Register
8567 * (06014h-06017h) and DPLL B Control Register (06018h-0601Bh)."
8569 * For simplicity We simply keep both bits always enabled in
8570 * both DPLLS. The spec says we should disable the DVO 2X clock
8571 * when not needed, but this seems to work fine in practice.
8573 if (IS_I830(dev_priv
) ||
8574 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DVO
))
8575 dpll
|= DPLL_DVO_2X_MODE
;
8577 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
8578 intel_panel_use_ssc(dev_priv
))
8579 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
8581 dpll
|= PLL_REF_INPUT_DREFCLK
;
8583 dpll
|= DPLL_VCO_ENABLE
;
8584 crtc_state
->dpll_hw_state
.dpll
= dpll
;
8587 static void intel_set_pipe_timings(const struct intel_crtc_state
*crtc_state
)
8589 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
8590 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
8591 enum pipe pipe
= crtc
->pipe
;
8592 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
8593 const struct drm_display_mode
*adjusted_mode
= &crtc_state
->hw
.adjusted_mode
;
8594 u32 crtc_vtotal
, crtc_vblank_end
;
8597 /* We need to be careful not to changed the adjusted mode, for otherwise
8598 * the hw state checker will get angry at the mismatch. */
8599 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
8600 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
8602 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
8603 /* the chip adds 2 halflines automatically */
8605 crtc_vblank_end
-= 1;
8607 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
))
8608 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
8610 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
8611 adjusted_mode
->crtc_htotal
/ 2;
8613 vsyncshift
+= adjusted_mode
->crtc_htotal
;
8616 if (INTEL_GEN(dev_priv
) > 3)
8617 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
8619 I915_WRITE(HTOTAL(cpu_transcoder
),
8620 (adjusted_mode
->crtc_hdisplay
- 1) |
8621 ((adjusted_mode
->crtc_htotal
- 1) << 16));
8622 I915_WRITE(HBLANK(cpu_transcoder
),
8623 (adjusted_mode
->crtc_hblank_start
- 1) |
8624 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
8625 I915_WRITE(HSYNC(cpu_transcoder
),
8626 (adjusted_mode
->crtc_hsync_start
- 1) |
8627 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
8629 I915_WRITE(VTOTAL(cpu_transcoder
),
8630 (adjusted_mode
->crtc_vdisplay
- 1) |
8631 ((crtc_vtotal
- 1) << 16));
8632 I915_WRITE(VBLANK(cpu_transcoder
),
8633 (adjusted_mode
->crtc_vblank_start
- 1) |
8634 ((crtc_vblank_end
- 1) << 16));
8635 I915_WRITE(VSYNC(cpu_transcoder
),
8636 (adjusted_mode
->crtc_vsync_start
- 1) |
8637 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
8639 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
8640 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
8641 * documented on the DDI_FUNC_CTL register description, EDP Input Select
8643 if (IS_HASWELL(dev_priv
) && cpu_transcoder
== TRANSCODER_EDP
&&
8644 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
8645 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
8649 static void intel_set_pipe_src_size(const struct intel_crtc_state
*crtc_state
)
8651 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
8652 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
8653 enum pipe pipe
= crtc
->pipe
;
8655 /* pipesrc controls the size that is scaled from, which should
8656 * always be the user's requested size.
8658 I915_WRITE(PIPESRC(pipe
),
8659 ((crtc_state
->pipe_src_w
- 1) << 16) |
8660 (crtc_state
->pipe_src_h
- 1));
8663 static bool intel_pipe_is_interlaced(const struct intel_crtc_state
*crtc_state
)
8665 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->uapi
.crtc
->dev
);
8666 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
8668 if (IS_GEN(dev_priv
, 2))
8671 if (INTEL_GEN(dev_priv
) >= 9 ||
8672 IS_BROADWELL(dev_priv
) || IS_HASWELL(dev_priv
))
8673 return I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK_HSW
;
8675 return I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
;
8678 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
8679 struct intel_crtc_state
*pipe_config
)
8681 struct drm_device
*dev
= crtc
->base
.dev
;
8682 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8683 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
8686 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
8687 pipe_config
->hw
.adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
8688 pipe_config
->hw
.adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
8690 if (!transcoder_is_dsi(cpu_transcoder
)) {
8691 tmp
= I915_READ(HBLANK(cpu_transcoder
));
8692 pipe_config
->hw
.adjusted_mode
.crtc_hblank_start
=
8694 pipe_config
->hw
.adjusted_mode
.crtc_hblank_end
=
8695 ((tmp
>> 16) & 0xffff) + 1;
8697 tmp
= I915_READ(HSYNC(cpu_transcoder
));
8698 pipe_config
->hw
.adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
8699 pipe_config
->hw
.adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
8701 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
8702 pipe_config
->hw
.adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
8703 pipe_config
->hw
.adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
8705 if (!transcoder_is_dsi(cpu_transcoder
)) {
8706 tmp
= I915_READ(VBLANK(cpu_transcoder
));
8707 pipe_config
->hw
.adjusted_mode
.crtc_vblank_start
=
8709 pipe_config
->hw
.adjusted_mode
.crtc_vblank_end
=
8710 ((tmp
>> 16) & 0xffff) + 1;
8712 tmp
= I915_READ(VSYNC(cpu_transcoder
));
8713 pipe_config
->hw
.adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
8714 pipe_config
->hw
.adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
8716 if (intel_pipe_is_interlaced(pipe_config
)) {
8717 pipe_config
->hw
.adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
8718 pipe_config
->hw
.adjusted_mode
.crtc_vtotal
+= 1;
8719 pipe_config
->hw
.adjusted_mode
.crtc_vblank_end
+= 1;
8723 static void intel_get_pipe_src_size(struct intel_crtc
*crtc
,
8724 struct intel_crtc_state
*pipe_config
)
8726 struct drm_device
*dev
= crtc
->base
.dev
;
8727 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8730 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
8731 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
8732 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
8734 pipe_config
->hw
.mode
.vdisplay
= pipe_config
->pipe_src_h
;
8735 pipe_config
->hw
.mode
.hdisplay
= pipe_config
->pipe_src_w
;
8738 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
8739 struct intel_crtc_state
*pipe_config
)
8741 mode
->hdisplay
= pipe_config
->hw
.adjusted_mode
.crtc_hdisplay
;
8742 mode
->htotal
= pipe_config
->hw
.adjusted_mode
.crtc_htotal
;
8743 mode
->hsync_start
= pipe_config
->hw
.adjusted_mode
.crtc_hsync_start
;
8744 mode
->hsync_end
= pipe_config
->hw
.adjusted_mode
.crtc_hsync_end
;
8746 mode
->vdisplay
= pipe_config
->hw
.adjusted_mode
.crtc_vdisplay
;
8747 mode
->vtotal
= pipe_config
->hw
.adjusted_mode
.crtc_vtotal
;
8748 mode
->vsync_start
= pipe_config
->hw
.adjusted_mode
.crtc_vsync_start
;
8749 mode
->vsync_end
= pipe_config
->hw
.adjusted_mode
.crtc_vsync_end
;
8751 mode
->flags
= pipe_config
->hw
.adjusted_mode
.flags
;
8752 mode
->type
= DRM_MODE_TYPE_DRIVER
;
8754 mode
->clock
= pipe_config
->hw
.adjusted_mode
.crtc_clock
;
8756 mode
->hsync
= drm_mode_hsync(mode
);
8757 mode
->vrefresh
= drm_mode_vrefresh(mode
);
8758 drm_mode_set_name(mode
);
8761 static void i9xx_set_pipeconf(const struct intel_crtc_state
*crtc_state
)
8763 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
8764 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
8769 /* we keep both pipes enabled on 830 */
8770 if (IS_I830(dev_priv
))
8771 pipeconf
|= I915_READ(PIPECONF(crtc
->pipe
)) & PIPECONF_ENABLE
;
8773 if (crtc_state
->double_wide
)
8774 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
8776 /* only g4x and later have fancy bpc/dither controls */
8777 if (IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
8778 IS_CHERRYVIEW(dev_priv
)) {
8779 /* Bspec claims that we can't use dithering for 30bpp pipes. */
8780 if (crtc_state
->dither
&& crtc_state
->pipe_bpp
!= 30)
8781 pipeconf
|= PIPECONF_DITHER_EN
|
8782 PIPECONF_DITHER_TYPE_SP
;
8784 switch (crtc_state
->pipe_bpp
) {
8786 pipeconf
|= PIPECONF_6BPC
;
8789 pipeconf
|= PIPECONF_8BPC
;
8792 pipeconf
|= PIPECONF_10BPC
;
8795 /* Case prevented by intel_choose_pipe_bpp_dither. */
8800 if (crtc_state
->hw
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
8801 if (INTEL_GEN(dev_priv
) < 4 ||
8802 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
))
8803 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
8805 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
8807 pipeconf
|= PIPECONF_PROGRESSIVE
;
8810 if ((IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) &&
8811 crtc_state
->limited_color_range
)
8812 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
8814 pipeconf
|= PIPECONF_GAMMA_MODE(crtc_state
->gamma_mode
);
8816 pipeconf
|= PIPECONF_FRAME_START_DELAY(0);
8818 I915_WRITE(PIPECONF(crtc
->pipe
), pipeconf
);
8819 POSTING_READ(PIPECONF(crtc
->pipe
));
8822 static int i8xx_crtc_compute_clock(struct intel_crtc
*crtc
,
8823 struct intel_crtc_state
*crtc_state
)
8825 struct drm_device
*dev
= crtc
->base
.dev
;
8826 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8827 const struct intel_limit
*limit
;
8830 memset(&crtc_state
->dpll_hw_state
, 0,
8831 sizeof(crtc_state
->dpll_hw_state
));
8833 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8834 if (intel_panel_use_ssc(dev_priv
)) {
8835 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8836 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
8839 limit
= &intel_limits_i8xx_lvds
;
8840 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DVO
)) {
8841 limit
= &intel_limits_i8xx_dvo
;
8843 limit
= &intel_limits_i8xx_dac
;
8846 if (!crtc_state
->clock_set
&&
8847 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8848 refclk
, NULL
, &crtc_state
->dpll
)) {
8849 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8853 i8xx_compute_dpll(crtc
, crtc_state
, NULL
);
8858 static int g4x_crtc_compute_clock(struct intel_crtc
*crtc
,
8859 struct intel_crtc_state
*crtc_state
)
8861 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
8862 const struct intel_limit
*limit
;
8865 memset(&crtc_state
->dpll_hw_state
, 0,
8866 sizeof(crtc_state
->dpll_hw_state
));
8868 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8869 if (intel_panel_use_ssc(dev_priv
)) {
8870 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8871 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
8874 if (intel_is_dual_link_lvds(dev_priv
))
8875 limit
= &intel_limits_g4x_dual_channel_lvds
;
8877 limit
= &intel_limits_g4x_single_channel_lvds
;
8878 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
) ||
8879 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
)) {
8880 limit
= &intel_limits_g4x_hdmi
;
8881 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
)) {
8882 limit
= &intel_limits_g4x_sdvo
;
8884 /* The option is for other outputs */
8885 limit
= &intel_limits_i9xx_sdvo
;
8888 if (!crtc_state
->clock_set
&&
8889 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8890 refclk
, NULL
, &crtc_state
->dpll
)) {
8891 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8895 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
8900 static int pnv_crtc_compute_clock(struct intel_crtc
*crtc
,
8901 struct intel_crtc_state
*crtc_state
)
8903 struct drm_device
*dev
= crtc
->base
.dev
;
8904 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8905 const struct intel_limit
*limit
;
8908 memset(&crtc_state
->dpll_hw_state
, 0,
8909 sizeof(crtc_state
->dpll_hw_state
));
8911 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8912 if (intel_panel_use_ssc(dev_priv
)) {
8913 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8914 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
8917 limit
= &pnv_limits_lvds
;
8919 limit
= &pnv_limits_sdvo
;
8922 if (!crtc_state
->clock_set
&&
8923 !pnv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8924 refclk
, NULL
, &crtc_state
->dpll
)) {
8925 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8929 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
8934 static int i9xx_crtc_compute_clock(struct intel_crtc
*crtc
,
8935 struct intel_crtc_state
*crtc_state
)
8937 struct drm_device
*dev
= crtc
->base
.dev
;
8938 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8939 const struct intel_limit
*limit
;
8942 memset(&crtc_state
->dpll_hw_state
, 0,
8943 sizeof(crtc_state
->dpll_hw_state
));
8945 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8946 if (intel_panel_use_ssc(dev_priv
)) {
8947 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8948 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
8951 limit
= &intel_limits_i9xx_lvds
;
8953 limit
= &intel_limits_i9xx_sdvo
;
8956 if (!crtc_state
->clock_set
&&
8957 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8958 refclk
, NULL
, &crtc_state
->dpll
)) {
8959 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8963 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
8968 static int chv_crtc_compute_clock(struct intel_crtc
*crtc
,
8969 struct intel_crtc_state
*crtc_state
)
8971 int refclk
= 100000;
8972 const struct intel_limit
*limit
= &intel_limits_chv
;
8974 memset(&crtc_state
->dpll_hw_state
, 0,
8975 sizeof(crtc_state
->dpll_hw_state
));
8977 if (!crtc_state
->clock_set
&&
8978 !chv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8979 refclk
, NULL
, &crtc_state
->dpll
)) {
8980 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8984 chv_compute_dpll(crtc
, crtc_state
);
8989 static int vlv_crtc_compute_clock(struct intel_crtc
*crtc
,
8990 struct intel_crtc_state
*crtc_state
)
8992 int refclk
= 100000;
8993 const struct intel_limit
*limit
= &intel_limits_vlv
;
8995 memset(&crtc_state
->dpll_hw_state
, 0,
8996 sizeof(crtc_state
->dpll_hw_state
));
8998 if (!crtc_state
->clock_set
&&
8999 !vlv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
9000 refclk
, NULL
, &crtc_state
->dpll
)) {
9001 DRM_ERROR("Couldn't find PLL settings for mode!\n");
9005 vlv_compute_dpll(crtc
, crtc_state
);
9010 static bool i9xx_has_pfit(struct drm_i915_private
*dev_priv
)
9012 if (IS_I830(dev_priv
))
9015 return INTEL_GEN(dev_priv
) >= 4 ||
9016 IS_PINEVIEW(dev_priv
) || IS_MOBILE(dev_priv
);
9019 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
9020 struct intel_crtc_state
*pipe_config
)
9022 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9025 if (!i9xx_has_pfit(dev_priv
))
9028 tmp
= I915_READ(PFIT_CONTROL
);
9029 if (!(tmp
& PFIT_ENABLE
))
9032 /* Check whether the pfit is attached to our pipe. */
9033 if (INTEL_GEN(dev_priv
) < 4) {
9034 if (crtc
->pipe
!= PIPE_B
)
9037 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
9041 pipe_config
->gmch_pfit
.control
= tmp
;
9042 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
9045 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
9046 struct intel_crtc_state
*pipe_config
)
9048 struct drm_device
*dev
= crtc
->base
.dev
;
9049 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9050 enum pipe pipe
= crtc
->pipe
;
9053 int refclk
= 100000;
9055 /* In case of DSI, DPLL will not be used */
9056 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
9059 vlv_dpio_get(dev_priv
);
9060 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
9061 vlv_dpio_put(dev_priv
);
9063 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
9064 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
9065 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
9066 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
9067 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
9069 pipe_config
->port_clock
= vlv_calc_dpll_params(refclk
, &clock
);
9073 i9xx_get_initial_plane_config(struct intel_crtc
*crtc
,
9074 struct intel_initial_plane_config
*plane_config
)
9076 struct drm_device
*dev
= crtc
->base
.dev
;
9077 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9078 struct intel_plane
*plane
= to_intel_plane(crtc
->base
.primary
);
9079 enum i9xx_plane_id i9xx_plane
= plane
->i9xx_plane
;
9081 u32 val
, base
, offset
;
9082 int fourcc
, pixel_format
;
9083 unsigned int aligned_height
;
9084 struct drm_framebuffer
*fb
;
9085 struct intel_framebuffer
*intel_fb
;
9087 if (!plane
->get_hw_state(plane
, &pipe
))
9090 WARN_ON(pipe
!= crtc
->pipe
);
9092 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9094 DRM_DEBUG_KMS("failed to alloc fb\n");
9098 fb
= &intel_fb
->base
;
9102 val
= I915_READ(DSPCNTR(i9xx_plane
));
9104 if (INTEL_GEN(dev_priv
) >= 4) {
9105 if (val
& DISPPLANE_TILED
) {
9106 plane_config
->tiling
= I915_TILING_X
;
9107 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
9110 if (val
& DISPPLANE_ROTATE_180
)
9111 plane_config
->rotation
= DRM_MODE_ROTATE_180
;
9114 if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_B
&&
9115 val
& DISPPLANE_MIRROR
)
9116 plane_config
->rotation
|= DRM_MODE_REFLECT_X
;
9118 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
9119 fourcc
= i9xx_format_to_fourcc(pixel_format
);
9120 fb
->format
= drm_format_info(fourcc
);
9122 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
9123 offset
= I915_READ(DSPOFFSET(i9xx_plane
));
9124 base
= I915_READ(DSPSURF(i9xx_plane
)) & 0xfffff000;
9125 } else if (INTEL_GEN(dev_priv
) >= 4) {
9126 if (plane_config
->tiling
)
9127 offset
= I915_READ(DSPTILEOFF(i9xx_plane
));
9129 offset
= I915_READ(DSPLINOFF(i9xx_plane
));
9130 base
= I915_READ(DSPSURF(i9xx_plane
)) & 0xfffff000;
9132 base
= I915_READ(DSPADDR(i9xx_plane
));
9134 plane_config
->base
= base
;
9136 val
= I915_READ(PIPESRC(pipe
));
9137 fb
->width
= ((val
>> 16) & 0xfff) + 1;
9138 fb
->height
= ((val
>> 0) & 0xfff) + 1;
9140 val
= I915_READ(DSPSTRIDE(i9xx_plane
));
9141 fb
->pitches
[0] = val
& 0xffffffc0;
9143 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
9145 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
9147 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9148 crtc
->base
.name
, plane
->base
.name
, fb
->width
, fb
->height
,
9149 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
9150 plane_config
->size
);
9152 plane_config
->fb
= intel_fb
;
9155 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
9156 struct intel_crtc_state
*pipe_config
)
9158 struct drm_device
*dev
= crtc
->base
.dev
;
9159 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9160 enum pipe pipe
= crtc
->pipe
;
9161 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
9163 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
, pll_dw3
;
9164 int refclk
= 100000;
9166 /* In case of DSI, DPLL will not be used */
9167 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
9170 vlv_dpio_get(dev_priv
);
9171 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
9172 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
9173 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
9174 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
9175 pll_dw3
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
9176 vlv_dpio_put(dev_priv
);
9178 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
9179 clock
.m2
= (pll_dw0
& 0xff) << 22;
9180 if (pll_dw3
& DPIO_CHV_FRAC_DIV_EN
)
9181 clock
.m2
|= pll_dw2
& 0x3fffff;
9182 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
9183 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
9184 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
9186 pipe_config
->port_clock
= chv_calc_dpll_params(refclk
, &clock
);
9189 static enum intel_output_format
9190 bdw_get_pipemisc_output_format(struct intel_crtc
*crtc
)
9192 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9195 tmp
= I915_READ(PIPEMISC(crtc
->pipe
));
9197 if (tmp
& PIPEMISC_YUV420_ENABLE
) {
9198 /* We support 4:2:0 in full blend mode only */
9199 WARN_ON((tmp
& PIPEMISC_YUV420_MODE_FULL_BLEND
) == 0);
9201 return INTEL_OUTPUT_FORMAT_YCBCR420
;
9202 } else if (tmp
& PIPEMISC_OUTPUT_COLORSPACE_YUV
) {
9203 return INTEL_OUTPUT_FORMAT_YCBCR444
;
9205 return INTEL_OUTPUT_FORMAT_RGB
;
9209 static void i9xx_get_pipe_color_config(struct intel_crtc_state
*crtc_state
)
9211 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
9212 struct intel_plane
*plane
= to_intel_plane(crtc
->base
.primary
);
9213 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9214 enum i9xx_plane_id i9xx_plane
= plane
->i9xx_plane
;
9217 tmp
= I915_READ(DSPCNTR(i9xx_plane
));
9219 if (tmp
& DISPPLANE_GAMMA_ENABLE
)
9220 crtc_state
->gamma_enable
= true;
9222 if (!HAS_GMCH(dev_priv
) &&
9223 tmp
& DISPPLANE_PIPE_CSC_ENABLE
)
9224 crtc_state
->csc_enable
= true;
9227 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
9228 struct intel_crtc_state
*pipe_config
)
9230 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9231 enum intel_display_power_domain power_domain
;
9232 intel_wakeref_t wakeref
;
9236 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
9237 wakeref
= intel_display_power_get_if_enabled(dev_priv
, power_domain
);
9241 pipe_config
->output_format
= INTEL_OUTPUT_FORMAT_RGB
;
9242 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
9243 pipe_config
->shared_dpll
= NULL
;
9244 pipe_config
->master_transcoder
= INVALID_TRANSCODER
;
9248 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
9249 if (!(tmp
& PIPECONF_ENABLE
))
9252 if (IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
9253 IS_CHERRYVIEW(dev_priv
)) {
9254 switch (tmp
& PIPECONF_BPC_MASK
) {
9256 pipe_config
->pipe_bpp
= 18;
9259 pipe_config
->pipe_bpp
= 24;
9261 case PIPECONF_10BPC
:
9262 pipe_config
->pipe_bpp
= 30;
9269 if ((IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) &&
9270 (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
9271 pipe_config
->limited_color_range
= true;
9273 pipe_config
->gamma_mode
= (tmp
& PIPECONF_GAMMA_MODE_MASK_I9XX
) >>
9274 PIPECONF_GAMMA_MODE_SHIFT
;
9276 if (IS_CHERRYVIEW(dev_priv
))
9277 pipe_config
->cgm_mode
= I915_READ(CGM_PIPE_MODE(crtc
->pipe
));
9279 i9xx_get_pipe_color_config(pipe_config
);
9280 intel_color_get_config(pipe_config
);
9282 if (INTEL_GEN(dev_priv
) < 4)
9283 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
9285 intel_get_pipe_timings(crtc
, pipe_config
);
9286 intel_get_pipe_src_size(crtc
, pipe_config
);
9288 i9xx_get_pfit_config(crtc
, pipe_config
);
9290 if (INTEL_GEN(dev_priv
) >= 4) {
9291 /* No way to read it out on pipes B and C */
9292 if (IS_CHERRYVIEW(dev_priv
) && crtc
->pipe
!= PIPE_A
)
9293 tmp
= dev_priv
->chv_dpll_md
[crtc
->pipe
];
9295 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
9296 pipe_config
->pixel_multiplier
=
9297 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
9298 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
9299 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
9300 } else if (IS_I945G(dev_priv
) || IS_I945GM(dev_priv
) ||
9301 IS_G33(dev_priv
) || IS_PINEVIEW(dev_priv
)) {
9302 tmp
= I915_READ(DPLL(crtc
->pipe
));
9303 pipe_config
->pixel_multiplier
=
9304 ((tmp
& SDVO_MULTIPLIER_MASK
)
9305 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
9307 /* Note that on i915G/GM the pixel multiplier is in the sdvo
9308 * port and will be fixed up in the encoder->get_config
9310 pipe_config
->pixel_multiplier
= 1;
9312 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
9313 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
)) {
9314 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
9315 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
9317 /* Mask out read-only status bits. */
9318 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
9319 DPLL_PORTC_READY_MASK
|
9320 DPLL_PORTB_READY_MASK
);
9323 if (IS_CHERRYVIEW(dev_priv
))
9324 chv_crtc_clock_get(crtc
, pipe_config
);
9325 else if (IS_VALLEYVIEW(dev_priv
))
9326 vlv_crtc_clock_get(crtc
, pipe_config
);
9328 i9xx_crtc_clock_get(crtc
, pipe_config
);
9331 * Normally the dotclock is filled in by the encoder .get_config()
9332 * but in case the pipe is enabled w/o any ports we need a sane
9335 pipe_config
->hw
.adjusted_mode
.crtc_clock
=
9336 pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
9341 intel_display_power_put(dev_priv
, power_domain
, wakeref
);
9346 static void ilk_init_pch_refclk(struct drm_i915_private
*dev_priv
)
9348 struct intel_encoder
*encoder
;
9351 bool has_lvds
= false;
9352 bool has_cpu_edp
= false;
9353 bool has_panel
= false;
9354 bool has_ck505
= false;
9355 bool can_ssc
= false;
9356 bool using_ssc_source
= false;
9358 /* We need to take the global config into account */
9359 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
9360 switch (encoder
->type
) {
9361 case INTEL_OUTPUT_LVDS
:
9365 case INTEL_OUTPUT_EDP
:
9367 if (encoder
->port
== PORT_A
)
9375 if (HAS_PCH_IBX(dev_priv
)) {
9376 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
9377 can_ssc
= has_ck505
;
9383 /* Check if any DPLLs are using the SSC source */
9384 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
9385 u32 temp
= I915_READ(PCH_DPLL(i
));
9387 if (!(temp
& DPLL_VCO_ENABLE
))
9390 if ((temp
& PLL_REF_INPUT_MASK
) ==
9391 PLLB_REF_INPUT_SPREADSPECTRUMIN
) {
9392 using_ssc_source
= true;
9397 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
9398 has_panel
, has_lvds
, has_ck505
, using_ssc_source
);
9400 /* Ironlake: try to setup display ref clock before DPLL
9401 * enabling. This is only under driver's control after
9402 * PCH B stepping, previous chipset stepping should be
9403 * ignoring this setting.
9405 val
= I915_READ(PCH_DREF_CONTROL
);
9407 /* As we must carefully and slowly disable/enable each source in turn,
9408 * compute the final state we want first and check if we need to
9409 * make any changes at all.
9412 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
9414 final
|= DREF_NONSPREAD_CK505_ENABLE
;
9416 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
9418 final
&= ~DREF_SSC_SOURCE_MASK
;
9419 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
9420 final
&= ~DREF_SSC1_ENABLE
;
9423 final
|= DREF_SSC_SOURCE_ENABLE
;
9425 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
9426 final
|= DREF_SSC1_ENABLE
;
9429 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
9430 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
9432 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
9434 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
9435 } else if (using_ssc_source
) {
9436 final
|= DREF_SSC_SOURCE_ENABLE
;
9437 final
|= DREF_SSC1_ENABLE
;
9443 /* Always enable nonspread source */
9444 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
9447 val
|= DREF_NONSPREAD_CK505_ENABLE
;
9449 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
9452 val
&= ~DREF_SSC_SOURCE_MASK
;
9453 val
|= DREF_SSC_SOURCE_ENABLE
;
9455 /* SSC must be turned on before enabling the CPU output */
9456 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
9457 DRM_DEBUG_KMS("Using SSC on panel\n");
9458 val
|= DREF_SSC1_ENABLE
;
9460 val
&= ~DREF_SSC1_ENABLE
;
9462 /* Get SSC going before enabling the outputs */
9463 I915_WRITE(PCH_DREF_CONTROL
, val
);
9464 POSTING_READ(PCH_DREF_CONTROL
);
9467 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
9469 /* Enable CPU source on CPU attached eDP */
9471 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
9472 DRM_DEBUG_KMS("Using SSC on eDP\n");
9473 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
9475 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
9477 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
9479 I915_WRITE(PCH_DREF_CONTROL
, val
);
9480 POSTING_READ(PCH_DREF_CONTROL
);
9483 DRM_DEBUG_KMS("Disabling CPU source output\n");
9485 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
9487 /* Turn off CPU output */
9488 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
9490 I915_WRITE(PCH_DREF_CONTROL
, val
);
9491 POSTING_READ(PCH_DREF_CONTROL
);
9494 if (!using_ssc_source
) {
9495 DRM_DEBUG_KMS("Disabling SSC source\n");
9497 /* Turn off the SSC source */
9498 val
&= ~DREF_SSC_SOURCE_MASK
;
9499 val
|= DREF_SSC_SOURCE_DISABLE
;
9502 val
&= ~DREF_SSC1_ENABLE
;
9504 I915_WRITE(PCH_DREF_CONTROL
, val
);
9505 POSTING_READ(PCH_DREF_CONTROL
);
9510 BUG_ON(val
!= final
);
9513 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
9517 tmp
= I915_READ(SOUTH_CHICKEN2
);
9518 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
9519 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
9521 if (wait_for_us(I915_READ(SOUTH_CHICKEN2
) &
9522 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
9523 DRM_ERROR("FDI mPHY reset assert timeout\n");
9525 tmp
= I915_READ(SOUTH_CHICKEN2
);
9526 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
9527 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
9529 if (wait_for_us((I915_READ(SOUTH_CHICKEN2
) &
9530 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
9531 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
9534 /* WaMPhyProgramming:hsw */
9535 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
9539 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
9540 tmp
&= ~(0xFF << 24);
9541 tmp
|= (0x12 << 24);
9542 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
9544 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
9546 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
9548 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
9550 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
9552 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
9553 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
9554 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
9556 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
9557 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
9558 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
9560 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
9563 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
9565 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
9568 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
9570 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
9573 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
9575 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
9578 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
9580 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
9581 tmp
&= ~(0xFF << 16);
9582 tmp
|= (0x1C << 16);
9583 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
9585 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
9586 tmp
&= ~(0xFF << 16);
9587 tmp
|= (0x1C << 16);
9588 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
9590 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
9592 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
9594 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
9596 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
9598 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
9599 tmp
&= ~(0xF << 28);
9601 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
9603 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
9604 tmp
&= ~(0xF << 28);
9606 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
9609 /* Implements 3 different sequences from BSpec chapter "Display iCLK
9610 * Programming" based on the parameters passed:
9611 * - Sequence to enable CLKOUT_DP
9612 * - Sequence to enable CLKOUT_DP without spread
9613 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
9615 static void lpt_enable_clkout_dp(struct drm_i915_private
*dev_priv
,
9616 bool with_spread
, bool with_fdi
)
9620 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
9622 if (WARN(HAS_PCH_LPT_LP(dev_priv
) &&
9623 with_fdi
, "LP PCH doesn't have FDI\n"))
9626 mutex_lock(&dev_priv
->sb_lock
);
9628 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
9629 tmp
&= ~SBI_SSCCTL_DISABLE
;
9630 tmp
|= SBI_SSCCTL_PATHALT
;
9631 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
9636 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
9637 tmp
&= ~SBI_SSCCTL_PATHALT
;
9638 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
9641 lpt_reset_fdi_mphy(dev_priv
);
9642 lpt_program_fdi_mphy(dev_priv
);
9646 reg
= HAS_PCH_LPT_LP(dev_priv
) ? SBI_GEN0
: SBI_DBUFF0
;
9647 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
9648 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
9649 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
9651 mutex_unlock(&dev_priv
->sb_lock
);
9654 /* Sequence to disable CLKOUT_DP */
9655 void lpt_disable_clkout_dp(struct drm_i915_private
*dev_priv
)
9659 mutex_lock(&dev_priv
->sb_lock
);
9661 reg
= HAS_PCH_LPT_LP(dev_priv
) ? SBI_GEN0
: SBI_DBUFF0
;
9662 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
9663 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
9664 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
9666 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
9667 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
9668 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
9669 tmp
|= SBI_SSCCTL_PATHALT
;
9670 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
9673 tmp
|= SBI_SSCCTL_DISABLE
;
9674 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
9677 mutex_unlock(&dev_priv
->sb_lock
);
9680 #define BEND_IDX(steps) ((50 + (steps)) / 5)
9682 static const u16 sscdivintphase
[] = {
9683 [BEND_IDX( 50)] = 0x3B23,
9684 [BEND_IDX( 45)] = 0x3B23,
9685 [BEND_IDX( 40)] = 0x3C23,
9686 [BEND_IDX( 35)] = 0x3C23,
9687 [BEND_IDX( 30)] = 0x3D23,
9688 [BEND_IDX( 25)] = 0x3D23,
9689 [BEND_IDX( 20)] = 0x3E23,
9690 [BEND_IDX( 15)] = 0x3E23,
9691 [BEND_IDX( 10)] = 0x3F23,
9692 [BEND_IDX( 5)] = 0x3F23,
9693 [BEND_IDX( 0)] = 0x0025,
9694 [BEND_IDX( -5)] = 0x0025,
9695 [BEND_IDX(-10)] = 0x0125,
9696 [BEND_IDX(-15)] = 0x0125,
9697 [BEND_IDX(-20)] = 0x0225,
9698 [BEND_IDX(-25)] = 0x0225,
9699 [BEND_IDX(-30)] = 0x0325,
9700 [BEND_IDX(-35)] = 0x0325,
9701 [BEND_IDX(-40)] = 0x0425,
9702 [BEND_IDX(-45)] = 0x0425,
9703 [BEND_IDX(-50)] = 0x0525,
9708 * steps -50 to 50 inclusive, in steps of 5
9709 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
9710 * change in clock period = -(steps / 10) * 5.787 ps
9712 static void lpt_bend_clkout_dp(struct drm_i915_private
*dev_priv
, int steps
)
9715 int idx
= BEND_IDX(steps
);
9717 if (WARN_ON(steps
% 5 != 0))
9720 if (WARN_ON(idx
>= ARRAY_SIZE(sscdivintphase
)))
9723 mutex_lock(&dev_priv
->sb_lock
);
9725 if (steps
% 10 != 0)
9729 intel_sbi_write(dev_priv
, SBI_SSCDITHPHASE
, tmp
, SBI_ICLK
);
9731 tmp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE
, SBI_ICLK
);
9733 tmp
|= sscdivintphase
[idx
];
9734 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE
, tmp
, SBI_ICLK
);
9736 mutex_unlock(&dev_priv
->sb_lock
);
9741 static bool spll_uses_pch_ssc(struct drm_i915_private
*dev_priv
)
9743 u32 fuse_strap
= I915_READ(FUSE_STRAP
);
9744 u32 ctl
= I915_READ(SPLL_CTL
);
9746 if ((ctl
& SPLL_PLL_ENABLE
) == 0)
9749 if ((ctl
& SPLL_REF_MASK
) == SPLL_REF_MUXED_SSC
&&
9750 (fuse_strap
& HSW_CPU_SSC_ENABLE
) == 0)
9753 if (IS_BROADWELL(dev_priv
) &&
9754 (ctl
& SPLL_REF_MASK
) == SPLL_REF_PCH_SSC_BDW
)
9760 static bool wrpll_uses_pch_ssc(struct drm_i915_private
*dev_priv
,
9761 enum intel_dpll_id id
)
9763 u32 fuse_strap
= I915_READ(FUSE_STRAP
);
9764 u32 ctl
= I915_READ(WRPLL_CTL(id
));
9766 if ((ctl
& WRPLL_PLL_ENABLE
) == 0)
9769 if ((ctl
& WRPLL_REF_MASK
) == WRPLL_REF_PCH_SSC
)
9772 if ((IS_BROADWELL(dev_priv
) || IS_HSW_ULT(dev_priv
)) &&
9773 (ctl
& WRPLL_REF_MASK
) == WRPLL_REF_MUXED_SSC_BDW
&&
9774 (fuse_strap
& HSW_CPU_SSC_ENABLE
) == 0)
9780 static void lpt_init_pch_refclk(struct drm_i915_private
*dev_priv
)
9782 struct intel_encoder
*encoder
;
9783 bool has_fdi
= false;
9785 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
9786 switch (encoder
->type
) {
9787 case INTEL_OUTPUT_ANALOG
:
9796 * The BIOS may have decided to use the PCH SSC
9797 * reference so we must not disable it until the
9798 * relevant PLLs have stopped relying on it. We'll
9799 * just leave the PCH SSC reference enabled in case
9800 * any active PLL is using it. It will get disabled
9801 * after runtime suspend if we don't have FDI.
9803 * TODO: Move the whole reference clock handling
9804 * to the modeset sequence proper so that we can
9805 * actually enable/disable/reconfigure these things
9806 * safely. To do that we need to introduce a real
9807 * clock hierarchy. That would also allow us to do
9808 * clock bending finally.
9810 dev_priv
->pch_ssc_use
= 0;
9812 if (spll_uses_pch_ssc(dev_priv
)) {
9813 DRM_DEBUG_KMS("SPLL using PCH SSC\n");
9814 dev_priv
->pch_ssc_use
|= BIT(DPLL_ID_SPLL
);
9817 if (wrpll_uses_pch_ssc(dev_priv
, DPLL_ID_WRPLL1
)) {
9818 DRM_DEBUG_KMS("WRPLL1 using PCH SSC\n");
9819 dev_priv
->pch_ssc_use
|= BIT(DPLL_ID_WRPLL1
);
9822 if (wrpll_uses_pch_ssc(dev_priv
, DPLL_ID_WRPLL2
)) {
9823 DRM_DEBUG_KMS("WRPLL2 using PCH SSC\n");
9824 dev_priv
->pch_ssc_use
|= BIT(DPLL_ID_WRPLL2
);
9827 if (dev_priv
->pch_ssc_use
)
9831 lpt_bend_clkout_dp(dev_priv
, 0);
9832 lpt_enable_clkout_dp(dev_priv
, true, true);
9834 lpt_disable_clkout_dp(dev_priv
);
9839 * Initialize reference clocks when the driver loads
9841 void intel_init_pch_refclk(struct drm_i915_private
*dev_priv
)
9843 if (HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
))
9844 ilk_init_pch_refclk(dev_priv
);
9845 else if (HAS_PCH_LPT(dev_priv
))
9846 lpt_init_pch_refclk(dev_priv
);
9849 static void ilk_set_pipeconf(const struct intel_crtc_state
*crtc_state
)
9851 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
9852 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9853 enum pipe pipe
= crtc
->pipe
;
9858 switch (crtc_state
->pipe_bpp
) {
9860 val
|= PIPECONF_6BPC
;
9863 val
|= PIPECONF_8BPC
;
9866 val
|= PIPECONF_10BPC
;
9869 val
|= PIPECONF_12BPC
;
9872 /* Case prevented by intel_choose_pipe_bpp_dither. */
9876 if (crtc_state
->dither
)
9877 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
9879 if (crtc_state
->hw
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
9880 val
|= PIPECONF_INTERLACED_ILK
;
9882 val
|= PIPECONF_PROGRESSIVE
;
9885 * This would end up with an odd purple hue over
9886 * the entire display. Make sure we don't do it.
9888 WARN_ON(crtc_state
->limited_color_range
&&
9889 crtc_state
->output_format
!= INTEL_OUTPUT_FORMAT_RGB
);
9891 if (crtc_state
->limited_color_range
)
9892 val
|= PIPECONF_COLOR_RANGE_SELECT
;
9894 if (crtc_state
->output_format
!= INTEL_OUTPUT_FORMAT_RGB
)
9895 val
|= PIPECONF_OUTPUT_COLORSPACE_YUV709
;
9897 val
|= PIPECONF_GAMMA_MODE(crtc_state
->gamma_mode
);
9899 val
|= PIPECONF_FRAME_START_DELAY(0);
9901 I915_WRITE(PIPECONF(pipe
), val
);
9902 POSTING_READ(PIPECONF(pipe
));
9905 static void hsw_set_pipeconf(const struct intel_crtc_state
*crtc_state
)
9907 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
9908 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9909 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
9912 if (IS_HASWELL(dev_priv
) && crtc_state
->dither
)
9913 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
9915 if (crtc_state
->hw
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
9916 val
|= PIPECONF_INTERLACED_ILK
;
9918 val
|= PIPECONF_PROGRESSIVE
;
9920 if (IS_HASWELL(dev_priv
) &&
9921 crtc_state
->output_format
!= INTEL_OUTPUT_FORMAT_RGB
)
9922 val
|= PIPECONF_OUTPUT_COLORSPACE_YUV_HSW
;
9924 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
9925 POSTING_READ(PIPECONF(cpu_transcoder
));
9928 static void bdw_set_pipemisc(const struct intel_crtc_state
*crtc_state
)
9930 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
9931 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9934 switch (crtc_state
->pipe_bpp
) {
9936 val
|= PIPEMISC_DITHER_6_BPC
;
9939 val
|= PIPEMISC_DITHER_8_BPC
;
9942 val
|= PIPEMISC_DITHER_10_BPC
;
9945 val
|= PIPEMISC_DITHER_12_BPC
;
9948 MISSING_CASE(crtc_state
->pipe_bpp
);
9952 if (crtc_state
->dither
)
9953 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
9955 if (crtc_state
->output_format
== INTEL_OUTPUT_FORMAT_YCBCR420
||
9956 crtc_state
->output_format
== INTEL_OUTPUT_FORMAT_YCBCR444
)
9957 val
|= PIPEMISC_OUTPUT_COLORSPACE_YUV
;
9959 if (crtc_state
->output_format
== INTEL_OUTPUT_FORMAT_YCBCR420
)
9960 val
|= PIPEMISC_YUV420_ENABLE
|
9961 PIPEMISC_YUV420_MODE_FULL_BLEND
;
9963 if (INTEL_GEN(dev_priv
) >= 11 &&
9964 (crtc_state
->active_planes
& ~(icl_hdr_plane_mask() |
9965 BIT(PLANE_CURSOR
))) == 0)
9966 val
|= PIPEMISC_HDR_MODE_PRECISION
;
9968 I915_WRITE(PIPEMISC(crtc
->pipe
), val
);
9971 int bdw_get_pipemisc_bpp(struct intel_crtc
*crtc
)
9973 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9976 tmp
= I915_READ(PIPEMISC(crtc
->pipe
));
9978 switch (tmp
& PIPEMISC_DITHER_BPC_MASK
) {
9979 case PIPEMISC_DITHER_6_BPC
:
9981 case PIPEMISC_DITHER_8_BPC
:
9983 case PIPEMISC_DITHER_10_BPC
:
9985 case PIPEMISC_DITHER_12_BPC
:
9993 int ilk_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
9996 * Account for spread spectrum to avoid
9997 * oversubscribing the link. Max center spread
9998 * is 2.5%; use 5% for safety's sake.
10000 u32 bps
= target_clock
* bpp
* 21 / 20;
10001 return DIV_ROUND_UP(bps
, link_bw
* 8);
10004 static bool ilk_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
10006 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
10009 static void ilk_compute_dpll(struct intel_crtc
*crtc
,
10010 struct intel_crtc_state
*crtc_state
,
10011 struct dpll
*reduced_clock
)
10013 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
10017 /* Enable autotuning of the PLL clock (if permissible) */
10019 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
10020 if ((intel_panel_use_ssc(dev_priv
) &&
10021 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
10022 (HAS_PCH_IBX(dev_priv
) &&
10023 intel_is_dual_link_lvds(dev_priv
)))
10025 } else if (crtc_state
->sdvo_tv_clock
) {
10029 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
10031 if (ilk_needs_fb_cb_tune(&crtc_state
->dpll
, factor
))
10034 if (reduced_clock
) {
10035 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
10037 if (reduced_clock
->m
< factor
* reduced_clock
->n
)
10045 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
))
10046 dpll
|= DPLLB_MODE_LVDS
;
10048 dpll
|= DPLLB_MODE_DAC_SERIAL
;
10050 dpll
|= (crtc_state
->pixel_multiplier
- 1)
10051 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
10053 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
10054 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
10055 dpll
|= DPLL_SDVO_HIGH_SPEED
;
10057 if (intel_crtc_has_dp_encoder(crtc_state
))
10058 dpll
|= DPLL_SDVO_HIGH_SPEED
;
10061 * The high speed IO clock is only really required for
10062 * SDVO/HDMI/DP, but we also enable it for CRT to make it
10063 * possible to share the DPLL between CRT and HDMI. Enabling
10064 * the clock needlessly does no real harm, except use up a
10065 * bit of power potentially.
10067 * We'll limit this to IVB with 3 pipes, since it has only two
10068 * DPLLs and so DPLL sharing is the only way to get three pipes
10069 * driving PCH ports at the same time. On SNB we could do this,
10070 * and potentially avoid enabling the second DPLL, but it's not
10071 * clear if it''s a win or loss power wise. No point in doing
10072 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
10074 if (INTEL_NUM_PIPES(dev_priv
) == 3 &&
10075 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
))
10076 dpll
|= DPLL_SDVO_HIGH_SPEED
;
10078 /* compute bitmask from p1 value */
10079 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
10081 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
10083 switch (crtc_state
->dpll
.p2
) {
10085 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
10088 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
10091 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
10094 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
10098 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
10099 intel_panel_use_ssc(dev_priv
))
10100 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
10102 dpll
|= PLL_REF_INPUT_DREFCLK
;
10104 dpll
|= DPLL_VCO_ENABLE
;
10106 crtc_state
->dpll_hw_state
.dpll
= dpll
;
10107 crtc_state
->dpll_hw_state
.fp0
= fp
;
10108 crtc_state
->dpll_hw_state
.fp1
= fp2
;
10111 static int ilk_crtc_compute_clock(struct intel_crtc
*crtc
,
10112 struct intel_crtc_state
*crtc_state
)
10114 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
10115 struct intel_atomic_state
*state
=
10116 to_intel_atomic_state(crtc_state
->uapi
.state
);
10117 const struct intel_limit
*limit
;
10118 int refclk
= 120000;
10120 memset(&crtc_state
->dpll_hw_state
, 0,
10121 sizeof(crtc_state
->dpll_hw_state
));
10123 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
10124 if (!crtc_state
->has_pch_encoder
)
10127 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
10128 if (intel_panel_use_ssc(dev_priv
)) {
10129 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
10130 dev_priv
->vbt
.lvds_ssc_freq
);
10131 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
10134 if (intel_is_dual_link_lvds(dev_priv
)) {
10135 if (refclk
== 100000)
10136 limit
= &ilk_limits_dual_lvds_100m
;
10138 limit
= &ilk_limits_dual_lvds
;
10140 if (refclk
== 100000)
10141 limit
= &ilk_limits_single_lvds_100m
;
10143 limit
= &ilk_limits_single_lvds
;
10146 limit
= &ilk_limits_dac
;
10149 if (!crtc_state
->clock_set
&&
10150 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
10151 refclk
, NULL
, &crtc_state
->dpll
)) {
10152 DRM_ERROR("Couldn't find PLL settings for mode!\n");
10156 ilk_compute_dpll(crtc
, crtc_state
, NULL
);
10158 if (!intel_reserve_shared_dplls(state
, crtc
, NULL
)) {
10159 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
10160 pipe_name(crtc
->pipe
));
10167 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
10168 struct intel_link_m_n
*m_n
)
10170 struct drm_device
*dev
= crtc
->base
.dev
;
10171 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10172 enum pipe pipe
= crtc
->pipe
;
10174 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
10175 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
10176 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
10178 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
10179 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
10180 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
10183 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
10184 enum transcoder transcoder
,
10185 struct intel_link_m_n
*m_n
,
10186 struct intel_link_m_n
*m2_n2
)
10188 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
10189 enum pipe pipe
= crtc
->pipe
;
10191 if (INTEL_GEN(dev_priv
) >= 5) {
10192 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
10193 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
10194 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
10196 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
10197 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
10198 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
10200 if (m2_n2
&& transcoder_has_m2_n2(dev_priv
, transcoder
)) {
10201 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
10202 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
10203 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
10205 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
10206 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
10207 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
10210 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
10211 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
10212 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
10214 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
10215 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
10216 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
10220 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
10221 struct intel_crtc_state
*pipe_config
)
10223 if (pipe_config
->has_pch_encoder
)
10224 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
10226 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
10227 &pipe_config
->dp_m_n
,
10228 &pipe_config
->dp_m2_n2
);
10231 static void ilk_get_fdi_m_n_config(struct intel_crtc
*crtc
,
10232 struct intel_crtc_state
*pipe_config
)
10234 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
10235 &pipe_config
->fdi_m_n
, NULL
);
10238 static void skl_get_pfit_config(struct intel_crtc
*crtc
,
10239 struct intel_crtc_state
*pipe_config
)
10241 struct drm_device
*dev
= crtc
->base
.dev
;
10242 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10243 struct intel_crtc_scaler_state
*scaler_state
= &pipe_config
->scaler_state
;
10248 /* find scaler attached to this pipe */
10249 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
10250 ps_ctrl
= I915_READ(SKL_PS_CTRL(crtc
->pipe
, i
));
10251 if (ps_ctrl
& PS_SCALER_EN
&& !(ps_ctrl
& PS_PLANE_SEL_MASK
)) {
10253 pipe_config
->pch_pfit
.enabled
= true;
10254 pipe_config
->pch_pfit
.pos
= I915_READ(SKL_PS_WIN_POS(crtc
->pipe
, i
));
10255 pipe_config
->pch_pfit
.size
= I915_READ(SKL_PS_WIN_SZ(crtc
->pipe
, i
));
10256 scaler_state
->scalers
[i
].in_use
= true;
10261 scaler_state
->scaler_id
= id
;
10263 scaler_state
->scaler_users
|= (1 << SKL_CRTC_INDEX
);
10265 scaler_state
->scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
10270 skl_get_initial_plane_config(struct intel_crtc
*crtc
,
10271 struct intel_initial_plane_config
*plane_config
)
10273 struct drm_device
*dev
= crtc
->base
.dev
;
10274 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10275 struct intel_plane
*plane
= to_intel_plane(crtc
->base
.primary
);
10276 enum plane_id plane_id
= plane
->id
;
10278 u32 val
, base
, offset
, stride_mult
, tiling
, alpha
;
10279 int fourcc
, pixel_format
;
10280 unsigned int aligned_height
;
10281 struct drm_framebuffer
*fb
;
10282 struct intel_framebuffer
*intel_fb
;
10284 if (!plane
->get_hw_state(plane
, &pipe
))
10287 WARN_ON(pipe
!= crtc
->pipe
);
10289 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
10291 DRM_DEBUG_KMS("failed to alloc fb\n");
10295 fb
= &intel_fb
->base
;
10299 val
= I915_READ(PLANE_CTL(pipe
, plane_id
));
10301 if (INTEL_GEN(dev_priv
) >= 11)
10302 pixel_format
= val
& ICL_PLANE_CTL_FORMAT_MASK
;
10304 pixel_format
= val
& PLANE_CTL_FORMAT_MASK
;
10306 if (INTEL_GEN(dev_priv
) >= 10 || IS_GEMINILAKE(dev_priv
)) {
10307 alpha
= I915_READ(PLANE_COLOR_CTL(pipe
, plane_id
));
10308 alpha
&= PLANE_COLOR_ALPHA_MASK
;
10310 alpha
= val
& PLANE_CTL_ALPHA_MASK
;
10313 fourcc
= skl_format_to_fourcc(pixel_format
,
10314 val
& PLANE_CTL_ORDER_RGBX
, alpha
);
10315 fb
->format
= drm_format_info(fourcc
);
10317 tiling
= val
& PLANE_CTL_TILED_MASK
;
10319 case PLANE_CTL_TILED_LINEAR
:
10320 fb
->modifier
= DRM_FORMAT_MOD_LINEAR
;
10322 case PLANE_CTL_TILED_X
:
10323 plane_config
->tiling
= I915_TILING_X
;
10324 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
10326 case PLANE_CTL_TILED_Y
:
10327 plane_config
->tiling
= I915_TILING_Y
;
10328 if (val
& PLANE_CTL_RENDER_DECOMPRESSION_ENABLE
)
10329 fb
->modifier
= INTEL_GEN(dev_priv
) >= 12 ?
10330 I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS
:
10331 I915_FORMAT_MOD_Y_TILED_CCS
;
10332 else if (val
& PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE
)
10333 fb
->modifier
= I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS
;
10335 fb
->modifier
= I915_FORMAT_MOD_Y_TILED
;
10337 case PLANE_CTL_TILED_YF
:
10338 if (val
& PLANE_CTL_RENDER_DECOMPRESSION_ENABLE
)
10339 fb
->modifier
= I915_FORMAT_MOD_Yf_TILED_CCS
;
10341 fb
->modifier
= I915_FORMAT_MOD_Yf_TILED
;
10344 MISSING_CASE(tiling
);
10349 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
10350 * while i915 HW rotation is clockwise, thats why this swapping.
10352 switch (val
& PLANE_CTL_ROTATE_MASK
) {
10353 case PLANE_CTL_ROTATE_0
:
10354 plane_config
->rotation
= DRM_MODE_ROTATE_0
;
10356 case PLANE_CTL_ROTATE_90
:
10357 plane_config
->rotation
= DRM_MODE_ROTATE_270
;
10359 case PLANE_CTL_ROTATE_180
:
10360 plane_config
->rotation
= DRM_MODE_ROTATE_180
;
10362 case PLANE_CTL_ROTATE_270
:
10363 plane_config
->rotation
= DRM_MODE_ROTATE_90
;
10367 if (INTEL_GEN(dev_priv
) >= 10 &&
10368 val
& PLANE_CTL_FLIP_HORIZONTAL
)
10369 plane_config
->rotation
|= DRM_MODE_REFLECT_X
;
10371 base
= I915_READ(PLANE_SURF(pipe
, plane_id
)) & 0xfffff000;
10372 plane_config
->base
= base
;
10374 offset
= I915_READ(PLANE_OFFSET(pipe
, plane_id
));
10376 val
= I915_READ(PLANE_SIZE(pipe
, plane_id
));
10377 fb
->height
= ((val
>> 16) & 0xffff) + 1;
10378 fb
->width
= ((val
>> 0) & 0xffff) + 1;
10380 val
= I915_READ(PLANE_STRIDE(pipe
, plane_id
));
10381 stride_mult
= skl_plane_stride_mult(fb
, 0, DRM_MODE_ROTATE_0
);
10382 fb
->pitches
[0] = (val
& 0x3ff) * stride_mult
;
10384 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
10386 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
10388 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
10389 crtc
->base
.name
, plane
->base
.name
, fb
->width
, fb
->height
,
10390 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
10391 plane_config
->size
);
10393 plane_config
->fb
= intel_fb
;
10400 static void ilk_get_pfit_config(struct intel_crtc
*crtc
,
10401 struct intel_crtc_state
*pipe_config
)
10403 struct drm_device
*dev
= crtc
->base
.dev
;
10404 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10407 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
10409 if (tmp
& PF_ENABLE
) {
10410 pipe_config
->pch_pfit
.enabled
= true;
10411 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
10412 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
10414 /* We currently do not free assignements of panel fitters on
10415 * ivb/hsw (since we don't use the higher upscaling modes which
10416 * differentiates them) so just WARN about this case for now. */
10417 if (IS_GEN(dev_priv
, 7)) {
10418 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
10419 PF_PIPE_SEL_IVB(crtc
->pipe
));
10424 static bool ilk_get_pipe_config(struct intel_crtc
*crtc
,
10425 struct intel_crtc_state
*pipe_config
)
10427 struct drm_device
*dev
= crtc
->base
.dev
;
10428 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10429 enum intel_display_power_domain power_domain
;
10430 intel_wakeref_t wakeref
;
10434 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
10435 wakeref
= intel_display_power_get_if_enabled(dev_priv
, power_domain
);
10439 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
10440 pipe_config
->shared_dpll
= NULL
;
10441 pipe_config
->master_transcoder
= INVALID_TRANSCODER
;
10444 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
10445 if (!(tmp
& PIPECONF_ENABLE
))
10448 switch (tmp
& PIPECONF_BPC_MASK
) {
10449 case PIPECONF_6BPC
:
10450 pipe_config
->pipe_bpp
= 18;
10452 case PIPECONF_8BPC
:
10453 pipe_config
->pipe_bpp
= 24;
10455 case PIPECONF_10BPC
:
10456 pipe_config
->pipe_bpp
= 30;
10458 case PIPECONF_12BPC
:
10459 pipe_config
->pipe_bpp
= 36;
10465 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
10466 pipe_config
->limited_color_range
= true;
10468 switch (tmp
& PIPECONF_OUTPUT_COLORSPACE_MASK
) {
10469 case PIPECONF_OUTPUT_COLORSPACE_YUV601
:
10470 case PIPECONF_OUTPUT_COLORSPACE_YUV709
:
10471 pipe_config
->output_format
= INTEL_OUTPUT_FORMAT_YCBCR444
;
10474 pipe_config
->output_format
= INTEL_OUTPUT_FORMAT_RGB
;
10478 pipe_config
->gamma_mode
= (tmp
& PIPECONF_GAMMA_MODE_MASK_ILK
) >>
10479 PIPECONF_GAMMA_MODE_SHIFT
;
10481 pipe_config
->csc_mode
= I915_READ(PIPE_CSC_MODE(crtc
->pipe
));
10483 i9xx_get_pipe_color_config(pipe_config
);
10484 intel_color_get_config(pipe_config
);
10486 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
10487 struct intel_shared_dpll
*pll
;
10488 enum intel_dpll_id pll_id
;
10490 pipe_config
->has_pch_encoder
= true;
10492 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
10493 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
10494 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
10496 ilk_get_fdi_m_n_config(crtc
, pipe_config
);
10498 if (HAS_PCH_IBX(dev_priv
)) {
10500 * The pipe->pch transcoder and pch transcoder->pll
10501 * mapping is fixed.
10503 pll_id
= (enum intel_dpll_id
) crtc
->pipe
;
10505 tmp
= I915_READ(PCH_DPLL_SEL
);
10506 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
10507 pll_id
= DPLL_ID_PCH_PLL_B
;
10509 pll_id
= DPLL_ID_PCH_PLL_A
;
10512 pipe_config
->shared_dpll
=
10513 intel_get_shared_dpll_by_id(dev_priv
, pll_id
);
10514 pll
= pipe_config
->shared_dpll
;
10516 WARN_ON(!pll
->info
->funcs
->get_hw_state(dev_priv
, pll
,
10517 &pipe_config
->dpll_hw_state
));
10519 tmp
= pipe_config
->dpll_hw_state
.dpll
;
10520 pipe_config
->pixel_multiplier
=
10521 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
10522 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
10524 ilk_pch_clock_get(crtc
, pipe_config
);
10526 pipe_config
->pixel_multiplier
= 1;
10529 intel_get_pipe_timings(crtc
, pipe_config
);
10530 intel_get_pipe_src_size(crtc
, pipe_config
);
10532 ilk_get_pfit_config(crtc
, pipe_config
);
10537 intel_display_power_put(dev_priv
, power_domain
, wakeref
);
10542 static int hsw_crtc_compute_clock(struct intel_crtc
*crtc
,
10543 struct intel_crtc_state
*crtc_state
)
10545 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
10546 struct intel_atomic_state
*state
=
10547 to_intel_atomic_state(crtc_state
->uapi
.state
);
10549 if (!intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DSI
) ||
10550 INTEL_GEN(dev_priv
) >= 11) {
10551 struct intel_encoder
*encoder
=
10552 intel_get_crtc_new_encoder(state
, crtc_state
);
10554 if (!intel_reserve_shared_dplls(state
, crtc
, encoder
)) {
10555 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
10556 pipe_name(crtc
->pipe
));
10564 static void cnl_get_ddi_pll(struct drm_i915_private
*dev_priv
, enum port port
,
10565 struct intel_crtc_state
*pipe_config
)
10567 enum intel_dpll_id id
;
10570 temp
= I915_READ(DPCLKA_CFGCR0
) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port
);
10571 id
= temp
>> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port
);
10573 if (WARN_ON(id
< SKL_DPLL0
|| id
> SKL_DPLL2
))
10576 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
10579 static void icl_get_ddi_pll(struct drm_i915_private
*dev_priv
, enum port port
,
10580 struct intel_crtc_state
*pipe_config
)
10582 enum phy phy
= intel_port_to_phy(dev_priv
, port
);
10583 enum icl_port_dpll_id port_dpll_id
;
10584 enum intel_dpll_id id
;
10587 if (intel_phy_is_combo(dev_priv
, phy
)) {
10588 temp
= I915_READ(ICL_DPCLKA_CFGCR0
) &
10589 ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy
);
10590 id
= temp
>> ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy
);
10591 port_dpll_id
= ICL_PORT_DPLL_DEFAULT
;
10592 } else if (intel_phy_is_tc(dev_priv
, phy
)) {
10593 u32 clk_sel
= I915_READ(DDI_CLK_SEL(port
)) & DDI_CLK_SEL_MASK
;
10595 if (clk_sel
== DDI_CLK_SEL_MG
) {
10596 id
= icl_tc_port_to_pll_id(intel_port_to_tc(dev_priv
,
10598 port_dpll_id
= ICL_PORT_DPLL_MG_PHY
;
10600 WARN_ON(clk_sel
< DDI_CLK_SEL_TBT_162
);
10601 id
= DPLL_ID_ICL_TBTPLL
;
10602 port_dpll_id
= ICL_PORT_DPLL_DEFAULT
;
10605 WARN(1, "Invalid port %x\n", port
);
10609 pipe_config
->icl_port_dplls
[port_dpll_id
].pll
=
10610 intel_get_shared_dpll_by_id(dev_priv
, id
);
10612 icl_set_active_port_dpll(pipe_config
, port_dpll_id
);
10615 static void bxt_get_ddi_pll(struct drm_i915_private
*dev_priv
,
10617 struct intel_crtc_state
*pipe_config
)
10619 enum intel_dpll_id id
;
10623 id
= DPLL_ID_SKL_DPLL0
;
10626 id
= DPLL_ID_SKL_DPLL1
;
10629 id
= DPLL_ID_SKL_DPLL2
;
10632 DRM_ERROR("Incorrect port type\n");
10636 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
10639 static void skl_get_ddi_pll(struct drm_i915_private
*dev_priv
, enum port port
,
10640 struct intel_crtc_state
*pipe_config
)
10642 enum intel_dpll_id id
;
10645 temp
= I915_READ(DPLL_CTRL2
) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port
);
10646 id
= temp
>> (port
* 3 + 1);
10648 if (WARN_ON(id
< SKL_DPLL0
|| id
> SKL_DPLL3
))
10651 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
10654 static void hsw_get_ddi_pll(struct drm_i915_private
*dev_priv
, enum port port
,
10655 struct intel_crtc_state
*pipe_config
)
10657 enum intel_dpll_id id
;
10658 u32 ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
10660 switch (ddi_pll_sel
) {
10661 case PORT_CLK_SEL_WRPLL1
:
10662 id
= DPLL_ID_WRPLL1
;
10664 case PORT_CLK_SEL_WRPLL2
:
10665 id
= DPLL_ID_WRPLL2
;
10667 case PORT_CLK_SEL_SPLL
:
10670 case PORT_CLK_SEL_LCPLL_810
:
10671 id
= DPLL_ID_LCPLL_810
;
10673 case PORT_CLK_SEL_LCPLL_1350
:
10674 id
= DPLL_ID_LCPLL_1350
;
10676 case PORT_CLK_SEL_LCPLL_2700
:
10677 id
= DPLL_ID_LCPLL_2700
;
10680 MISSING_CASE(ddi_pll_sel
);
10682 case PORT_CLK_SEL_NONE
:
10686 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
10689 static bool hsw_get_transcoder_state(struct intel_crtc
*crtc
,
10690 struct intel_crtc_state
*pipe_config
,
10691 u64
*power_domain_mask
,
10692 intel_wakeref_t
*wakerefs
)
10694 struct drm_device
*dev
= crtc
->base
.dev
;
10695 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10696 enum intel_display_power_domain power_domain
;
10697 unsigned long panel_transcoder_mask
= 0;
10698 unsigned long enabled_panel_transcoders
= 0;
10699 enum transcoder panel_transcoder
;
10700 intel_wakeref_t wf
;
10703 if (INTEL_GEN(dev_priv
) >= 11)
10704 panel_transcoder_mask
|=
10705 BIT(TRANSCODER_DSI_0
) | BIT(TRANSCODER_DSI_1
);
10707 if (HAS_TRANSCODER_EDP(dev_priv
))
10708 panel_transcoder_mask
|= BIT(TRANSCODER_EDP
);
10711 * The pipe->transcoder mapping is fixed with the exception of the eDP
10712 * and DSI transcoders handled below.
10714 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
10717 * XXX: Do intel_display_power_get_if_enabled before reading this (for
10718 * consistency and less surprising code; it's in always on power).
10720 for_each_set_bit(panel_transcoder
,
10721 &panel_transcoder_mask
,
10722 ARRAY_SIZE(INTEL_INFO(dev_priv
)->trans_offsets
)) {
10723 bool force_thru
= false;
10724 enum pipe trans_pipe
;
10726 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder
));
10727 if (!(tmp
& TRANS_DDI_FUNC_ENABLE
))
10731 * Log all enabled ones, only use the first one.
10733 * FIXME: This won't work for two separate DSI displays.
10735 enabled_panel_transcoders
|= BIT(panel_transcoder
);
10736 if (enabled_panel_transcoders
!= BIT(panel_transcoder
))
10739 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
10741 WARN(1, "unknown pipe linked to transcoder %s\n",
10742 transcoder_name(panel_transcoder
));
10744 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
10747 case TRANS_DDI_EDP_INPUT_A_ON
:
10748 trans_pipe
= PIPE_A
;
10750 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
10751 trans_pipe
= PIPE_B
;
10753 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
10754 trans_pipe
= PIPE_C
;
10756 case TRANS_DDI_EDP_INPUT_D_ONOFF
:
10757 trans_pipe
= PIPE_D
;
10761 if (trans_pipe
== crtc
->pipe
) {
10762 pipe_config
->cpu_transcoder
= panel_transcoder
;
10763 pipe_config
->pch_pfit
.force_thru
= force_thru
;
10768 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
10770 WARN_ON((enabled_panel_transcoders
& BIT(TRANSCODER_EDP
)) &&
10771 enabled_panel_transcoders
!= BIT(TRANSCODER_EDP
));
10773 power_domain
= POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
);
10774 WARN_ON(*power_domain_mask
& BIT_ULL(power_domain
));
10776 wf
= intel_display_power_get_if_enabled(dev_priv
, power_domain
);
10780 wakerefs
[power_domain
] = wf
;
10781 *power_domain_mask
|= BIT_ULL(power_domain
);
10783 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
10785 return tmp
& PIPECONF_ENABLE
;
10788 static bool bxt_get_dsi_transcoder_state(struct intel_crtc
*crtc
,
10789 struct intel_crtc_state
*pipe_config
,
10790 u64
*power_domain_mask
,
10791 intel_wakeref_t
*wakerefs
)
10793 struct drm_device
*dev
= crtc
->base
.dev
;
10794 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10795 enum intel_display_power_domain power_domain
;
10796 enum transcoder cpu_transcoder
;
10797 intel_wakeref_t wf
;
10801 for_each_port_masked(port
, BIT(PORT_A
) | BIT(PORT_C
)) {
10802 if (port
== PORT_A
)
10803 cpu_transcoder
= TRANSCODER_DSI_A
;
10805 cpu_transcoder
= TRANSCODER_DSI_C
;
10807 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
10808 WARN_ON(*power_domain_mask
& BIT_ULL(power_domain
));
10810 wf
= intel_display_power_get_if_enabled(dev_priv
, power_domain
);
10814 wakerefs
[power_domain
] = wf
;
10815 *power_domain_mask
|= BIT_ULL(power_domain
);
10818 * The PLL needs to be enabled with a valid divider
10819 * configuration, otherwise accessing DSI registers will hang
10820 * the machine. See BSpec North Display Engine
10821 * registers/MIPI[BXT]. We can break out here early, since we
10822 * need the same DSI PLL to be enabled for both DSI ports.
10824 if (!bxt_dsi_pll_is_enabled(dev_priv
))
10827 /* XXX: this works for video mode only */
10828 tmp
= I915_READ(BXT_MIPI_PORT_CTRL(port
));
10829 if (!(tmp
& DPI_ENABLE
))
10832 tmp
= I915_READ(MIPI_CTRL(port
));
10833 if ((tmp
& BXT_PIPE_SELECT_MASK
) != BXT_PIPE_SELECT(crtc
->pipe
))
10836 pipe_config
->cpu_transcoder
= cpu_transcoder
;
10840 return transcoder_is_dsi(pipe_config
->cpu_transcoder
);
10843 static void hsw_get_ddi_port_state(struct intel_crtc
*crtc
,
10844 struct intel_crtc_state
*pipe_config
)
10846 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
10847 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
10848 struct intel_shared_dpll
*pll
;
10852 if (transcoder_is_dsi(cpu_transcoder
)) {
10853 port
= (cpu_transcoder
== TRANSCODER_DSI_A
) ?
10856 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder
));
10857 if (INTEL_GEN(dev_priv
) >= 12)
10858 port
= TGL_TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp
);
10860 port
= TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp
);
10863 if (INTEL_GEN(dev_priv
) >= 11)
10864 icl_get_ddi_pll(dev_priv
, port
, pipe_config
);
10865 else if (IS_CANNONLAKE(dev_priv
))
10866 cnl_get_ddi_pll(dev_priv
, port
, pipe_config
);
10867 else if (IS_GEN9_BC(dev_priv
))
10868 skl_get_ddi_pll(dev_priv
, port
, pipe_config
);
10869 else if (IS_GEN9_LP(dev_priv
))
10870 bxt_get_ddi_pll(dev_priv
, port
, pipe_config
);
10872 hsw_get_ddi_pll(dev_priv
, port
, pipe_config
);
10874 pll
= pipe_config
->shared_dpll
;
10876 WARN_ON(!pll
->info
->funcs
->get_hw_state(dev_priv
, pll
,
10877 &pipe_config
->dpll_hw_state
));
10881 * Haswell has only FDI/PCH transcoder A. It is which is connected to
10882 * DDI E. So just check whether this pipe is wired to DDI E and whether
10883 * the PCH transcoder is on.
10885 if (INTEL_GEN(dev_priv
) < 9 &&
10886 (port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
10887 pipe_config
->has_pch_encoder
= true;
10889 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
10890 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
10891 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
10893 ilk_get_fdi_m_n_config(crtc
, pipe_config
);
10897 static enum transcoder
transcoder_master_readout(struct drm_i915_private
*dev_priv
,
10898 enum transcoder cpu_transcoder
)
10900 u32 trans_port_sync
, master_select
;
10902 trans_port_sync
= I915_READ(TRANS_DDI_FUNC_CTL2(cpu_transcoder
));
10904 if ((trans_port_sync
& PORT_SYNC_MODE_ENABLE
) == 0)
10905 return INVALID_TRANSCODER
;
10907 master_select
= trans_port_sync
&
10908 PORT_SYNC_MODE_MASTER_SELECT_MASK
;
10909 if (master_select
== 0)
10910 return TRANSCODER_EDP
;
10912 return master_select
- 1;
10915 static void icl_get_trans_port_sync_config(struct intel_crtc_state
*crtc_state
)
10917 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->uapi
.crtc
->dev
);
10919 enum transcoder cpu_transcoder
;
10921 crtc_state
->master_transcoder
= transcoder_master_readout(dev_priv
,
10922 crtc_state
->cpu_transcoder
);
10924 transcoders
= BIT(TRANSCODER_A
) |
10925 BIT(TRANSCODER_B
) |
10926 BIT(TRANSCODER_C
) |
10928 for_each_cpu_transcoder_masked(dev_priv
, cpu_transcoder
, transcoders
) {
10929 enum intel_display_power_domain power_domain
;
10930 intel_wakeref_t trans_wakeref
;
10932 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
10933 trans_wakeref
= intel_display_power_get_if_enabled(dev_priv
,
10936 if (!trans_wakeref
)
10939 if (transcoder_master_readout(dev_priv
, cpu_transcoder
) ==
10940 crtc_state
->cpu_transcoder
)
10941 crtc_state
->sync_mode_slaves_mask
|= BIT(cpu_transcoder
);
10943 intel_display_power_put(dev_priv
, power_domain
, trans_wakeref
);
10946 WARN_ON(crtc_state
->master_transcoder
!= INVALID_TRANSCODER
&&
10947 crtc_state
->sync_mode_slaves_mask
);
10950 static bool hsw_get_pipe_config(struct intel_crtc
*crtc
,
10951 struct intel_crtc_state
*pipe_config
)
10953 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
10954 intel_wakeref_t wakerefs
[POWER_DOMAIN_NUM
], wf
;
10955 enum intel_display_power_domain power_domain
;
10956 u64 power_domain_mask
;
10959 pipe_config
->master_transcoder
= INVALID_TRANSCODER
;
10961 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
10962 wf
= intel_display_power_get_if_enabled(dev_priv
, power_domain
);
10966 wakerefs
[power_domain
] = wf
;
10967 power_domain_mask
= BIT_ULL(power_domain
);
10969 pipe_config
->shared_dpll
= NULL
;
10971 active
= hsw_get_transcoder_state(crtc
, pipe_config
,
10972 &power_domain_mask
, wakerefs
);
10974 if (IS_GEN9_LP(dev_priv
) &&
10975 bxt_get_dsi_transcoder_state(crtc
, pipe_config
,
10976 &power_domain_mask
, wakerefs
)) {
10984 if (!transcoder_is_dsi(pipe_config
->cpu_transcoder
) ||
10985 INTEL_GEN(dev_priv
) >= 11) {
10986 hsw_get_ddi_port_state(crtc
, pipe_config
);
10987 intel_get_pipe_timings(crtc
, pipe_config
);
10990 intel_get_pipe_src_size(crtc
, pipe_config
);
10992 if (IS_HASWELL(dev_priv
)) {
10993 u32 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
10995 if (tmp
& PIPECONF_OUTPUT_COLORSPACE_YUV_HSW
)
10996 pipe_config
->output_format
= INTEL_OUTPUT_FORMAT_YCBCR444
;
10998 pipe_config
->output_format
= INTEL_OUTPUT_FORMAT_RGB
;
11000 pipe_config
->output_format
=
11001 bdw_get_pipemisc_output_format(crtc
);
11004 * Currently there is no interface defined to
11005 * check user preference between RGB/YCBCR444
11006 * or YCBCR420. So the only possible case for
11007 * YCBCR444 usage is driving YCBCR420 output
11008 * with LSPCON, when pipe is configured for
11009 * YCBCR444 output and LSPCON takes care of
11012 pipe_config
->lspcon_downsampling
=
11013 pipe_config
->output_format
== INTEL_OUTPUT_FORMAT_YCBCR444
;
11016 pipe_config
->gamma_mode
= I915_READ(GAMMA_MODE(crtc
->pipe
));
11018 pipe_config
->csc_mode
= I915_READ(PIPE_CSC_MODE(crtc
->pipe
));
11020 if (INTEL_GEN(dev_priv
) >= 9) {
11021 u32 tmp
= I915_READ(SKL_BOTTOM_COLOR(crtc
->pipe
));
11023 if (tmp
& SKL_BOTTOM_COLOR_GAMMA_ENABLE
)
11024 pipe_config
->gamma_enable
= true;
11026 if (tmp
& SKL_BOTTOM_COLOR_CSC_ENABLE
)
11027 pipe_config
->csc_enable
= true;
11029 i9xx_get_pipe_color_config(pipe_config
);
11032 intel_color_get_config(pipe_config
);
11034 power_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
11035 WARN_ON(power_domain_mask
& BIT_ULL(power_domain
));
11037 wf
= intel_display_power_get_if_enabled(dev_priv
, power_domain
);
11039 wakerefs
[power_domain
] = wf
;
11040 power_domain_mask
|= BIT_ULL(power_domain
);
11042 if (INTEL_GEN(dev_priv
) >= 9)
11043 skl_get_pfit_config(crtc
, pipe_config
);
11045 ilk_get_pfit_config(crtc
, pipe_config
);
11048 if (hsw_crtc_supports_ips(crtc
)) {
11049 if (IS_HASWELL(dev_priv
))
11050 pipe_config
->ips_enabled
= I915_READ(IPS_CTL
) & IPS_ENABLE
;
11053 * We cannot readout IPS state on broadwell, set to
11054 * true so we can set it to a defined state on first
11057 pipe_config
->ips_enabled
= true;
11061 if (pipe_config
->cpu_transcoder
!= TRANSCODER_EDP
&&
11062 !transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
11063 pipe_config
->pixel_multiplier
=
11064 I915_READ(PIPE_MULT(pipe_config
->cpu_transcoder
)) + 1;
11066 pipe_config
->pixel_multiplier
= 1;
11069 if (INTEL_GEN(dev_priv
) >= 11 &&
11070 !transcoder_is_dsi(pipe_config
->cpu_transcoder
))
11071 icl_get_trans_port_sync_config(pipe_config
);
11074 for_each_power_domain(power_domain
, power_domain_mask
)
11075 intel_display_power_put(dev_priv
,
11076 power_domain
, wakerefs
[power_domain
]);
11081 static u32
intel_cursor_base(const struct intel_plane_state
*plane_state
)
11083 struct drm_i915_private
*dev_priv
=
11084 to_i915(plane_state
->uapi
.plane
->dev
);
11085 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
11086 const struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
11089 if (INTEL_INFO(dev_priv
)->display
.cursor_needs_physical
)
11090 base
= obj
->phys_handle
->busaddr
;
11092 base
= intel_plane_ggtt_offset(plane_state
);
11094 return base
+ plane_state
->color_plane
[0].offset
;
11097 static u32
intel_cursor_position(const struct intel_plane_state
*plane_state
)
11099 int x
= plane_state
->uapi
.dst
.x1
;
11100 int y
= plane_state
->uapi
.dst
.y1
;
11104 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
11107 pos
|= x
<< CURSOR_X_SHIFT
;
11110 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
11113 pos
|= y
<< CURSOR_Y_SHIFT
;
11118 static bool intel_cursor_size_ok(const struct intel_plane_state
*plane_state
)
11120 const struct drm_mode_config
*config
=
11121 &plane_state
->uapi
.plane
->dev
->mode_config
;
11122 int width
= drm_rect_width(&plane_state
->uapi
.dst
);
11123 int height
= drm_rect_height(&plane_state
->uapi
.dst
);
11125 return width
> 0 && width
<= config
->cursor_width
&&
11126 height
> 0 && height
<= config
->cursor_height
;
11129 static int intel_cursor_check_surface(struct intel_plane_state
*plane_state
)
11131 struct drm_i915_private
*dev_priv
=
11132 to_i915(plane_state
->uapi
.plane
->dev
);
11133 unsigned int rotation
= plane_state
->hw
.rotation
;
11138 ret
= intel_plane_compute_gtt(plane_state
);
11142 if (!plane_state
->uapi
.visible
)
11145 src_x
= plane_state
->uapi
.src
.x1
>> 16;
11146 src_y
= plane_state
->uapi
.src
.y1
>> 16;
11148 intel_add_fb_offsets(&src_x
, &src_y
, plane_state
, 0);
11149 offset
= intel_plane_compute_aligned_offset(&src_x
, &src_y
,
11152 if (src_x
!= 0 || src_y
!= 0) {
11153 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
11158 * Put the final coordinates back so that the src
11159 * coordinate checks will see the right values.
11161 drm_rect_translate_to(&plane_state
->uapi
.src
,
11162 src_x
<< 16, src_y
<< 16);
11164 /* ILK+ do this automagically in hardware */
11165 if (HAS_GMCH(dev_priv
) && rotation
& DRM_MODE_ROTATE_180
) {
11166 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
11167 int src_w
= drm_rect_width(&plane_state
->uapi
.src
) >> 16;
11168 int src_h
= drm_rect_height(&plane_state
->uapi
.src
) >> 16;
11170 offset
+= (src_h
* src_w
- 1) * fb
->format
->cpp
[0];
11173 plane_state
->color_plane
[0].offset
= offset
;
11174 plane_state
->color_plane
[0].x
= src_x
;
11175 plane_state
->color_plane
[0].y
= src_y
;
11180 static int intel_check_cursor(struct intel_crtc_state
*crtc_state
,
11181 struct intel_plane_state
*plane_state
)
11183 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
11186 if (fb
&& fb
->modifier
!= DRM_FORMAT_MOD_LINEAR
) {
11187 DRM_DEBUG_KMS("cursor cannot be tiled\n");
11191 ret
= drm_atomic_helper_check_plane_state(&plane_state
->uapi
,
11193 DRM_PLANE_HELPER_NO_SCALING
,
11194 DRM_PLANE_HELPER_NO_SCALING
,
11199 /* Use the unclipped src/dst rectangles, which we program to hw */
11200 plane_state
->uapi
.src
= drm_plane_state_src(&plane_state
->uapi
);
11201 plane_state
->uapi
.dst
= drm_plane_state_dest(&plane_state
->uapi
);
11203 ret
= intel_cursor_check_surface(plane_state
);
11207 if (!plane_state
->uapi
.visible
)
11210 ret
= intel_plane_check_src_coordinates(plane_state
);
11217 static unsigned int
11218 i845_cursor_max_stride(struct intel_plane
*plane
,
11219 u32 pixel_format
, u64 modifier
,
11220 unsigned int rotation
)
11225 static u32
i845_cursor_ctl_crtc(const struct intel_crtc_state
*crtc_state
)
11229 if (crtc_state
->gamma_enable
)
11230 cntl
|= CURSOR_GAMMA_ENABLE
;
11235 static u32
i845_cursor_ctl(const struct intel_crtc_state
*crtc_state
,
11236 const struct intel_plane_state
*plane_state
)
11238 return CURSOR_ENABLE
|
11239 CURSOR_FORMAT_ARGB
|
11240 CURSOR_STRIDE(plane_state
->color_plane
[0].stride
);
11243 static bool i845_cursor_size_ok(const struct intel_plane_state
*plane_state
)
11245 int width
= drm_rect_width(&plane_state
->uapi
.dst
);
11248 * 845g/865g are only limited by the width of their cursors,
11249 * the height is arbitrary up to the precision of the register.
11251 return intel_cursor_size_ok(plane_state
) && IS_ALIGNED(width
, 64);
11254 static int i845_check_cursor(struct intel_crtc_state
*crtc_state
,
11255 struct intel_plane_state
*plane_state
)
11257 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
11260 ret
= intel_check_cursor(crtc_state
, plane_state
);
11264 /* if we want to turn off the cursor ignore width and height */
11268 /* Check for which cursor types we support */
11269 if (!i845_cursor_size_ok(plane_state
)) {
11270 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
11271 drm_rect_width(&plane_state
->uapi
.dst
),
11272 drm_rect_height(&plane_state
->uapi
.dst
));
11276 WARN_ON(plane_state
->uapi
.visible
&&
11277 plane_state
->color_plane
[0].stride
!= fb
->pitches
[0]);
11279 switch (fb
->pitches
[0]) {
11286 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
11291 plane_state
->ctl
= i845_cursor_ctl(crtc_state
, plane_state
);
11296 static void i845_update_cursor(struct intel_plane
*plane
,
11297 const struct intel_crtc_state
*crtc_state
,
11298 const struct intel_plane_state
*plane_state
)
11300 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
11301 u32 cntl
= 0, base
= 0, pos
= 0, size
= 0;
11302 unsigned long irqflags
;
11304 if (plane_state
&& plane_state
->uapi
.visible
) {
11305 unsigned int width
= drm_rect_width(&plane_state
->uapi
.dst
);
11306 unsigned int height
= drm_rect_height(&plane_state
->uapi
.dst
);
11308 cntl
= plane_state
->ctl
|
11309 i845_cursor_ctl_crtc(crtc_state
);
11311 size
= (height
<< 12) | width
;
11313 base
= intel_cursor_base(plane_state
);
11314 pos
= intel_cursor_position(plane_state
);
11317 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
11319 /* On these chipsets we can only modify the base/size/stride
11320 * whilst the cursor is disabled.
11322 if (plane
->cursor
.base
!= base
||
11323 plane
->cursor
.size
!= size
||
11324 plane
->cursor
.cntl
!= cntl
) {
11325 I915_WRITE_FW(CURCNTR(PIPE_A
), 0);
11326 I915_WRITE_FW(CURBASE(PIPE_A
), base
);
11327 I915_WRITE_FW(CURSIZE
, size
);
11328 I915_WRITE_FW(CURPOS(PIPE_A
), pos
);
11329 I915_WRITE_FW(CURCNTR(PIPE_A
), cntl
);
11331 plane
->cursor
.base
= base
;
11332 plane
->cursor
.size
= size
;
11333 plane
->cursor
.cntl
= cntl
;
11335 I915_WRITE_FW(CURPOS(PIPE_A
), pos
);
11338 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
11341 static void i845_disable_cursor(struct intel_plane
*plane
,
11342 const struct intel_crtc_state
*crtc_state
)
11344 i845_update_cursor(plane
, crtc_state
, NULL
);
11347 static bool i845_cursor_get_hw_state(struct intel_plane
*plane
,
11350 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
11351 enum intel_display_power_domain power_domain
;
11352 intel_wakeref_t wakeref
;
11355 power_domain
= POWER_DOMAIN_PIPE(PIPE_A
);
11356 wakeref
= intel_display_power_get_if_enabled(dev_priv
, power_domain
);
11360 ret
= I915_READ(CURCNTR(PIPE_A
)) & CURSOR_ENABLE
;
11364 intel_display_power_put(dev_priv
, power_domain
, wakeref
);
11369 static unsigned int
11370 i9xx_cursor_max_stride(struct intel_plane
*plane
,
11371 u32 pixel_format
, u64 modifier
,
11372 unsigned int rotation
)
11374 return plane
->base
.dev
->mode_config
.cursor_width
* 4;
11377 static u32
i9xx_cursor_ctl_crtc(const struct intel_crtc_state
*crtc_state
)
11379 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
11380 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
11383 if (INTEL_GEN(dev_priv
) >= 11)
11386 if (crtc_state
->gamma_enable
)
11387 cntl
= MCURSOR_GAMMA_ENABLE
;
11389 if (crtc_state
->csc_enable
)
11390 cntl
|= MCURSOR_PIPE_CSC_ENABLE
;
11392 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
))
11393 cntl
|= MCURSOR_PIPE_SELECT(crtc
->pipe
);
11398 static u32
i9xx_cursor_ctl(const struct intel_crtc_state
*crtc_state
,
11399 const struct intel_plane_state
*plane_state
)
11401 struct drm_i915_private
*dev_priv
=
11402 to_i915(plane_state
->uapi
.plane
->dev
);
11405 if (IS_GEN(dev_priv
, 6) || IS_IVYBRIDGE(dev_priv
))
11406 cntl
|= MCURSOR_TRICKLE_FEED_DISABLE
;
11408 switch (drm_rect_width(&plane_state
->uapi
.dst
)) {
11410 cntl
|= MCURSOR_MODE_64_ARGB_AX
;
11413 cntl
|= MCURSOR_MODE_128_ARGB_AX
;
11416 cntl
|= MCURSOR_MODE_256_ARGB_AX
;
11419 MISSING_CASE(drm_rect_width(&plane_state
->uapi
.dst
));
11423 if (plane_state
->hw
.rotation
& DRM_MODE_ROTATE_180
)
11424 cntl
|= MCURSOR_ROTATE_180
;
11429 static bool i9xx_cursor_size_ok(const struct intel_plane_state
*plane_state
)
11431 struct drm_i915_private
*dev_priv
=
11432 to_i915(plane_state
->uapi
.plane
->dev
);
11433 int width
= drm_rect_width(&plane_state
->uapi
.dst
);
11434 int height
= drm_rect_height(&plane_state
->uapi
.dst
);
11436 if (!intel_cursor_size_ok(plane_state
))
11439 /* Cursor width is limited to a few power-of-two sizes */
11450 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
11451 * height from 8 lines up to the cursor width, when the
11452 * cursor is not rotated. Everything else requires square
11455 if (HAS_CUR_FBC(dev_priv
) &&
11456 plane_state
->hw
.rotation
& DRM_MODE_ROTATE_0
) {
11457 if (height
< 8 || height
> width
)
11460 if (height
!= width
)
11467 static int i9xx_check_cursor(struct intel_crtc_state
*crtc_state
,
11468 struct intel_plane_state
*plane_state
)
11470 struct intel_plane
*plane
= to_intel_plane(plane_state
->uapi
.plane
);
11471 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
11472 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
11473 enum pipe pipe
= plane
->pipe
;
11476 ret
= intel_check_cursor(crtc_state
, plane_state
);
11480 /* if we want to turn off the cursor ignore width and height */
11484 /* Check for which cursor types we support */
11485 if (!i9xx_cursor_size_ok(plane_state
)) {
11486 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
11487 drm_rect_width(&plane_state
->uapi
.dst
),
11488 drm_rect_height(&plane_state
->uapi
.dst
));
11492 WARN_ON(plane_state
->uapi
.visible
&&
11493 plane_state
->color_plane
[0].stride
!= fb
->pitches
[0]);
11495 if (fb
->pitches
[0] !=
11496 drm_rect_width(&plane_state
->uapi
.dst
) * fb
->format
->cpp
[0]) {
11497 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
11499 drm_rect_width(&plane_state
->uapi
.dst
));
11504 * There's something wrong with the cursor on CHV pipe C.
11505 * If it straddles the left edge of the screen then
11506 * moving it away from the edge or disabling it often
11507 * results in a pipe underrun, and often that can lead to
11508 * dead pipe (constant underrun reported, and it scans
11509 * out just a solid color). To recover from that, the
11510 * display power well must be turned off and on again.
11511 * Refuse the put the cursor into that compromised position.
11513 if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_C
&&
11514 plane_state
->uapi
.visible
&& plane_state
->uapi
.dst
.x1
< 0) {
11515 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
11519 plane_state
->ctl
= i9xx_cursor_ctl(crtc_state
, plane_state
);
11524 static void i9xx_update_cursor(struct intel_plane
*plane
,
11525 const struct intel_crtc_state
*crtc_state
,
11526 const struct intel_plane_state
*plane_state
)
11528 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
11529 enum pipe pipe
= plane
->pipe
;
11530 u32 cntl
= 0, base
= 0, pos
= 0, fbc_ctl
= 0;
11531 unsigned long irqflags
;
11533 if (plane_state
&& plane_state
->uapi
.visible
) {
11534 unsigned width
= drm_rect_width(&plane_state
->uapi
.dst
);
11535 unsigned height
= drm_rect_height(&plane_state
->uapi
.dst
);
11537 cntl
= plane_state
->ctl
|
11538 i9xx_cursor_ctl_crtc(crtc_state
);
11540 if (width
!= height
)
11541 fbc_ctl
= CUR_FBC_CTL_EN
| (height
- 1);
11543 base
= intel_cursor_base(plane_state
);
11544 pos
= intel_cursor_position(plane_state
);
11547 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
11550 * On some platforms writing CURCNTR first will also
11551 * cause CURPOS to be armed by the CURBASE write.
11552 * Without the CURCNTR write the CURPOS write would
11553 * arm itself. Thus we always update CURCNTR before
11556 * On other platforms CURPOS always requires the
11557 * CURBASE write to arm the update. Additonally
11558 * a write to any of the cursor register will cancel
11559 * an already armed cursor update. Thus leaving out
11560 * the CURBASE write after CURPOS could lead to a
11561 * cursor that doesn't appear to move, or even change
11562 * shape. Thus we always write CURBASE.
11564 * The other registers are armed by by the CURBASE write
11565 * except when the plane is getting enabled at which time
11566 * the CURCNTR write arms the update.
11569 if (INTEL_GEN(dev_priv
) >= 9)
11570 skl_write_cursor_wm(plane
, crtc_state
);
11572 if (plane
->cursor
.base
!= base
||
11573 plane
->cursor
.size
!= fbc_ctl
||
11574 plane
->cursor
.cntl
!= cntl
) {
11575 if (HAS_CUR_FBC(dev_priv
))
11576 I915_WRITE_FW(CUR_FBC_CTL(pipe
), fbc_ctl
);
11577 I915_WRITE_FW(CURCNTR(pipe
), cntl
);
11578 I915_WRITE_FW(CURPOS(pipe
), pos
);
11579 I915_WRITE_FW(CURBASE(pipe
), base
);
11581 plane
->cursor
.base
= base
;
11582 plane
->cursor
.size
= fbc_ctl
;
11583 plane
->cursor
.cntl
= cntl
;
11585 I915_WRITE_FW(CURPOS(pipe
), pos
);
11586 I915_WRITE_FW(CURBASE(pipe
), base
);
11589 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
11592 static void i9xx_disable_cursor(struct intel_plane
*plane
,
11593 const struct intel_crtc_state
*crtc_state
)
11595 i9xx_update_cursor(plane
, crtc_state
, NULL
);
11598 static bool i9xx_cursor_get_hw_state(struct intel_plane
*plane
,
11601 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
11602 enum intel_display_power_domain power_domain
;
11603 intel_wakeref_t wakeref
;
11608 * Not 100% correct for planes that can move between pipes,
11609 * but that's only the case for gen2-3 which don't have any
11610 * display power wells.
11612 power_domain
= POWER_DOMAIN_PIPE(plane
->pipe
);
11613 wakeref
= intel_display_power_get_if_enabled(dev_priv
, power_domain
);
11617 val
= I915_READ(CURCNTR(plane
->pipe
));
11619 ret
= val
& MCURSOR_MODE
;
11621 if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
))
11622 *pipe
= plane
->pipe
;
11624 *pipe
= (val
& MCURSOR_PIPE_SELECT_MASK
) >>
11625 MCURSOR_PIPE_SELECT_SHIFT
;
11627 intel_display_power_put(dev_priv
, power_domain
, wakeref
);
11632 /* VESA 640x480x72Hz mode to set on the pipe */
11633 static const struct drm_display_mode load_detect_mode
= {
11634 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
11635 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
11638 struct drm_framebuffer
*
11639 intel_framebuffer_create(struct drm_i915_gem_object
*obj
,
11640 struct drm_mode_fb_cmd2
*mode_cmd
)
11642 struct intel_framebuffer
*intel_fb
;
11645 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
11647 return ERR_PTR(-ENOMEM
);
11649 ret
= intel_framebuffer_init(intel_fb
, obj
, mode_cmd
);
11653 return &intel_fb
->base
;
11657 return ERR_PTR(ret
);
11660 static int intel_modeset_disable_planes(struct drm_atomic_state
*state
,
11661 struct drm_crtc
*crtc
)
11663 struct drm_plane
*plane
;
11664 struct drm_plane_state
*plane_state
;
11667 ret
= drm_atomic_add_affected_planes(state
, crtc
);
11671 for_each_new_plane_in_state(state
, plane
, plane_state
, i
) {
11672 if (plane_state
->crtc
!= crtc
)
11675 ret
= drm_atomic_set_crtc_for_plane(plane_state
, NULL
);
11679 drm_atomic_set_fb_for_plane(plane_state
, NULL
);
11685 int intel_get_load_detect_pipe(struct drm_connector
*connector
,
11686 struct intel_load_detect_pipe
*old
,
11687 struct drm_modeset_acquire_ctx
*ctx
)
11689 struct intel_crtc
*intel_crtc
;
11690 struct intel_encoder
*intel_encoder
=
11691 intel_attached_encoder(to_intel_connector(connector
));
11692 struct drm_crtc
*possible_crtc
;
11693 struct drm_encoder
*encoder
= &intel_encoder
->base
;
11694 struct drm_crtc
*crtc
= NULL
;
11695 struct drm_device
*dev
= encoder
->dev
;
11696 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11697 struct drm_mode_config
*config
= &dev
->mode_config
;
11698 struct drm_atomic_state
*state
= NULL
, *restore_state
= NULL
;
11699 struct drm_connector_state
*connector_state
;
11700 struct intel_crtc_state
*crtc_state
;
11703 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11704 connector
->base
.id
, connector
->name
,
11705 encoder
->base
.id
, encoder
->name
);
11707 old
->restore_state
= NULL
;
11709 WARN_ON(!drm_modeset_is_locked(&config
->connection_mutex
));
11712 * Algorithm gets a little messy:
11714 * - if the connector already has an assigned crtc, use it (but make
11715 * sure it's on first)
11717 * - try to find the first unused crtc that can drive this connector,
11718 * and use that if we find one
11721 /* See if we already have a CRTC for this connector */
11722 if (connector
->state
->crtc
) {
11723 crtc
= connector
->state
->crtc
;
11725 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
11729 /* Make sure the crtc and connector are running */
11733 /* Find an unused one (if possible) */
11734 for_each_crtc(dev
, possible_crtc
) {
11736 if (!(encoder
->possible_crtcs
& (1 << i
)))
11739 ret
= drm_modeset_lock(&possible_crtc
->mutex
, ctx
);
11743 if (possible_crtc
->state
->enable
) {
11744 drm_modeset_unlock(&possible_crtc
->mutex
);
11748 crtc
= possible_crtc
;
11753 * If we didn't find an unused CRTC, don't use any.
11756 DRM_DEBUG_KMS("no pipe available for load-detect\n");
11762 intel_crtc
= to_intel_crtc(crtc
);
11764 state
= drm_atomic_state_alloc(dev
);
11765 restore_state
= drm_atomic_state_alloc(dev
);
11766 if (!state
|| !restore_state
) {
11771 state
->acquire_ctx
= ctx
;
11772 restore_state
->acquire_ctx
= ctx
;
11774 connector_state
= drm_atomic_get_connector_state(state
, connector
);
11775 if (IS_ERR(connector_state
)) {
11776 ret
= PTR_ERR(connector_state
);
11780 ret
= drm_atomic_set_crtc_for_connector(connector_state
, crtc
);
11784 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
11785 if (IS_ERR(crtc_state
)) {
11786 ret
= PTR_ERR(crtc_state
);
11790 crtc_state
->uapi
.active
= true;
11792 ret
= drm_atomic_set_mode_for_crtc(&crtc_state
->uapi
,
11793 &load_detect_mode
);
11797 ret
= intel_modeset_disable_planes(state
, crtc
);
11801 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state
, connector
));
11803 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state
, crtc
));
11805 ret
= drm_atomic_add_affected_planes(restore_state
, crtc
);
11807 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret
);
11811 ret
= drm_atomic_commit(state
);
11813 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
11817 old
->restore_state
= restore_state
;
11818 drm_atomic_state_put(state
);
11820 /* let the connector get through one full cycle before testing */
11821 intel_wait_for_vblank(dev_priv
, intel_crtc
->pipe
);
11826 drm_atomic_state_put(state
);
11829 if (restore_state
) {
11830 drm_atomic_state_put(restore_state
);
11831 restore_state
= NULL
;
11834 if (ret
== -EDEADLK
)
11840 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
11841 struct intel_load_detect_pipe
*old
,
11842 struct drm_modeset_acquire_ctx
*ctx
)
11844 struct intel_encoder
*intel_encoder
=
11845 intel_attached_encoder(to_intel_connector(connector
));
11846 struct drm_encoder
*encoder
= &intel_encoder
->base
;
11847 struct drm_atomic_state
*state
= old
->restore_state
;
11850 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11851 connector
->base
.id
, connector
->name
,
11852 encoder
->base
.id
, encoder
->name
);
11857 ret
= drm_atomic_helper_commit_duplicated_state(state
, ctx
);
11859 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret
);
11860 drm_atomic_state_put(state
);
11863 static int i9xx_pll_refclk(struct drm_device
*dev
,
11864 const struct intel_crtc_state
*pipe_config
)
11866 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11867 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
11869 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
11870 return dev_priv
->vbt
.lvds_ssc_freq
;
11871 else if (HAS_PCH_SPLIT(dev_priv
))
11873 else if (!IS_GEN(dev_priv
, 2))
11879 /* Returns the clock of the currently programmed mode of the given pipe. */
11880 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
11881 struct intel_crtc_state
*pipe_config
)
11883 struct drm_device
*dev
= crtc
->base
.dev
;
11884 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11885 enum pipe pipe
= crtc
->pipe
;
11886 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
11890 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
11892 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
11893 fp
= pipe_config
->dpll_hw_state
.fp0
;
11895 fp
= pipe_config
->dpll_hw_state
.fp1
;
11897 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
11898 if (IS_PINEVIEW(dev_priv
)) {
11899 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
11900 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
11902 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
11903 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
11906 if (!IS_GEN(dev_priv
, 2)) {
11907 if (IS_PINEVIEW(dev_priv
))
11908 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
11909 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
11911 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
11912 DPLL_FPA01_P1_POST_DIV_SHIFT
);
11914 switch (dpll
& DPLL_MODE_MASK
) {
11915 case DPLLB_MODE_DAC_SERIAL
:
11916 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
11919 case DPLLB_MODE_LVDS
:
11920 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
11924 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
11925 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
11929 if (IS_PINEVIEW(dev_priv
))
11930 port_clock
= pnv_calc_dpll_params(refclk
, &clock
);
11932 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
11934 u32 lvds
= IS_I830(dev_priv
) ? 0 : I915_READ(LVDS
);
11935 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
11938 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
11939 DPLL_FPA01_P1_POST_DIV_SHIFT
);
11941 if (lvds
& LVDS_CLKB_POWER_UP
)
11946 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
11949 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
11950 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
11952 if (dpll
& PLL_P2_DIVIDE_BY_4
)
11958 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
11962 * This value includes pixel_multiplier. We will use
11963 * port_clock to compute adjusted_mode.crtc_clock in the
11964 * encoder's get_config() function.
11966 pipe_config
->port_clock
= port_clock
;
11969 int intel_dotclock_calculate(int link_freq
,
11970 const struct intel_link_m_n
*m_n
)
11973 * The calculation for the data clock is:
11974 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
11975 * But we want to avoid losing precison if possible, so:
11976 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
11978 * and the link clock is simpler:
11979 * link_clock = (m * link_clock) / n
11985 return div_u64(mul_u32_u32(m_n
->link_m
, link_freq
), m_n
->link_n
);
11988 static void ilk_pch_clock_get(struct intel_crtc
*crtc
,
11989 struct intel_crtc_state
*pipe_config
)
11991 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
11993 /* read out port_clock from the DPLL */
11994 i9xx_crtc_clock_get(crtc
, pipe_config
);
11997 * In case there is an active pipe without active ports,
11998 * we may need some idea for the dotclock anyway.
11999 * Calculate one based on the FDI configuration.
12001 pipe_config
->hw
.adjusted_mode
.crtc_clock
=
12002 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
12003 &pipe_config
->fdi_m_n
);
12006 static void intel_crtc_state_reset(struct intel_crtc_state
*crtc_state
,
12007 struct intel_crtc
*crtc
)
12009 memset(crtc_state
, 0, sizeof(*crtc_state
));
12011 __drm_atomic_helper_crtc_state_reset(&crtc_state
->uapi
, &crtc
->base
);
12013 crtc_state
->cpu_transcoder
= INVALID_TRANSCODER
;
12014 crtc_state
->master_transcoder
= INVALID_TRANSCODER
;
12015 crtc_state
->hsw_workaround_pipe
= INVALID_PIPE
;
12016 crtc_state
->output_format
= INTEL_OUTPUT_FORMAT_INVALID
;
12017 crtc_state
->scaler_state
.scaler_id
= -1;
12018 crtc_state
->mst_master_transcoder
= INVALID_TRANSCODER
;
12021 static struct intel_crtc_state
*intel_crtc_state_alloc(struct intel_crtc
*crtc
)
12023 struct intel_crtc_state
*crtc_state
;
12025 crtc_state
= kmalloc(sizeof(*crtc_state
), GFP_KERNEL
);
12028 intel_crtc_state_reset(crtc_state
, crtc
);
12033 /* Returns the currently programmed mode of the given encoder. */
12034 struct drm_display_mode
*
12035 intel_encoder_current_mode(struct intel_encoder
*encoder
)
12037 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
12038 struct intel_crtc_state
*crtc_state
;
12039 struct drm_display_mode
*mode
;
12040 struct intel_crtc
*crtc
;
12043 if (!encoder
->get_hw_state(encoder
, &pipe
))
12046 crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
12048 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
12052 crtc_state
= intel_crtc_state_alloc(crtc
);
12058 if (!dev_priv
->display
.get_pipe_config(crtc
, crtc_state
)) {
12064 encoder
->get_config(encoder
, crtc_state
);
12066 intel_mode_from_pipe_config(mode
, crtc_state
);
12073 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
12075 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12077 drm_crtc_cleanup(crtc
);
12082 * intel_wm_need_update - Check whether watermarks need updating
12083 * @cur: current plane state
12084 * @new: new plane state
12086 * Check current plane state versus the new one to determine whether
12087 * watermarks need to be recalculated.
12089 * Returns true or false.
12091 static bool intel_wm_need_update(const struct intel_plane_state
*cur
,
12092 struct intel_plane_state
*new)
12094 /* Update watermarks on tiling or size changes. */
12095 if (new->uapi
.visible
!= cur
->uapi
.visible
)
12098 if (!cur
->hw
.fb
|| !new->hw
.fb
)
12101 if (cur
->hw
.fb
->modifier
!= new->hw
.fb
->modifier
||
12102 cur
->hw
.rotation
!= new->hw
.rotation
||
12103 drm_rect_width(&new->uapi
.src
) != drm_rect_width(&cur
->uapi
.src
) ||
12104 drm_rect_height(&new->uapi
.src
) != drm_rect_height(&cur
->uapi
.src
) ||
12105 drm_rect_width(&new->uapi
.dst
) != drm_rect_width(&cur
->uapi
.dst
) ||
12106 drm_rect_height(&new->uapi
.dst
) != drm_rect_height(&cur
->uapi
.dst
))
12112 static bool needs_scaling(const struct intel_plane_state
*state
)
12114 int src_w
= drm_rect_width(&state
->uapi
.src
) >> 16;
12115 int src_h
= drm_rect_height(&state
->uapi
.src
) >> 16;
12116 int dst_w
= drm_rect_width(&state
->uapi
.dst
);
12117 int dst_h
= drm_rect_height(&state
->uapi
.dst
);
12119 return (src_w
!= dst_w
|| src_h
!= dst_h
);
12122 int intel_plane_atomic_calc_changes(const struct intel_crtc_state
*old_crtc_state
,
12123 struct intel_crtc_state
*crtc_state
,
12124 const struct intel_plane_state
*old_plane_state
,
12125 struct intel_plane_state
*plane_state
)
12127 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
12128 struct intel_plane
*plane
= to_intel_plane(plane_state
->uapi
.plane
);
12129 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
12130 bool mode_changed
= needs_modeset(crtc_state
);
12131 bool was_crtc_enabled
= old_crtc_state
->hw
.active
;
12132 bool is_crtc_enabled
= crtc_state
->hw
.active
;
12133 bool turn_off
, turn_on
, visible
, was_visible
;
12136 if (INTEL_GEN(dev_priv
) >= 9 && plane
->id
!= PLANE_CURSOR
) {
12137 ret
= skl_update_scaler_plane(crtc_state
, plane_state
);
12142 was_visible
= old_plane_state
->uapi
.visible
;
12143 visible
= plane_state
->uapi
.visible
;
12145 if (!was_crtc_enabled
&& WARN_ON(was_visible
))
12146 was_visible
= false;
12149 * Visibility is calculated as if the crtc was on, but
12150 * after scaler setup everything depends on it being off
12151 * when the crtc isn't active.
12153 * FIXME this is wrong for watermarks. Watermarks should also
12154 * be computed as if the pipe would be active. Perhaps move
12155 * per-plane wm computation to the .check_plane() hook, and
12156 * only combine the results from all planes in the current place?
12158 if (!is_crtc_enabled
) {
12159 plane_state
->uapi
.visible
= visible
= false;
12160 crtc_state
->active_planes
&= ~BIT(plane
->id
);
12161 crtc_state
->data_rate
[plane
->id
] = 0;
12162 crtc_state
->min_cdclk
[plane
->id
] = 0;
12165 if (!was_visible
&& !visible
)
12168 turn_off
= was_visible
&& (!visible
|| mode_changed
);
12169 turn_on
= visible
&& (!was_visible
|| mode_changed
);
12171 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] with [PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
12172 crtc
->base
.base
.id
, crtc
->base
.name
,
12173 plane
->base
.base
.id
, plane
->base
.name
,
12174 was_visible
, visible
,
12175 turn_off
, turn_on
, mode_changed
);
12178 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
))
12179 crtc_state
->update_wm_pre
= true;
12181 /* must disable cxsr around plane enable/disable */
12182 if (plane
->id
!= PLANE_CURSOR
)
12183 crtc_state
->disable_cxsr
= true;
12184 } else if (turn_off
) {
12185 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
))
12186 crtc_state
->update_wm_post
= true;
12188 /* must disable cxsr around plane enable/disable */
12189 if (plane
->id
!= PLANE_CURSOR
)
12190 crtc_state
->disable_cxsr
= true;
12191 } else if (intel_wm_need_update(old_plane_state
, plane_state
)) {
12192 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
)) {
12193 /* FIXME bollocks */
12194 crtc_state
->update_wm_pre
= true;
12195 crtc_state
->update_wm_post
= true;
12199 if (visible
|| was_visible
)
12200 crtc_state
->fb_bits
|= plane
->frontbuffer_bit
;
12203 * ILK/SNB DVSACNTR/Sprite Enable
12204 * IVB SPR_CTL/Sprite Enable
12205 * "When in Self Refresh Big FIFO mode, a write to enable the
12206 * plane will be internally buffered and delayed while Big FIFO
12207 * mode is exiting."
12209 * Which means that enabling the sprite can take an extra frame
12210 * when we start in big FIFO mode (LP1+). Thus we need to drop
12211 * down to LP0 and wait for vblank in order to make sure the
12212 * sprite gets enabled on the next vblank after the register write.
12213 * Doing otherwise would risk enabling the sprite one frame after
12214 * we've already signalled flip completion. We can resume LP1+
12215 * once the sprite has been enabled.
12218 * WaCxSRDisabledForSpriteScaling:ivb
12219 * IVB SPR_SCALE/Scaling Enable
12220 * "Low Power watermarks must be disabled for at least one
12221 * frame before enabling sprite scaling, and kept disabled
12222 * until sprite scaling is disabled."
12224 * ILK/SNB DVSASCALE/Scaling Enable
12225 * "When in Self Refresh Big FIFO mode, scaling enable will be
12226 * masked off while Big FIFO mode is exiting."
12228 * Despite the w/a only being listed for IVB we assume that
12229 * the ILK/SNB note has similar ramifications, hence we apply
12230 * the w/a on all three platforms.
12232 * With experimental results seems this is needed also for primary
12233 * plane, not only sprite plane.
12235 if (plane
->id
!= PLANE_CURSOR
&&
12236 (IS_GEN_RANGE(dev_priv
, 5, 6) ||
12237 IS_IVYBRIDGE(dev_priv
)) &&
12238 (turn_on
|| (!needs_scaling(old_plane_state
) &&
12239 needs_scaling(plane_state
))))
12240 crtc_state
->disable_lp_wm
= true;
12245 static bool encoders_cloneable(const struct intel_encoder
*a
,
12246 const struct intel_encoder
*b
)
12248 /* masks could be asymmetric, so check both ways */
12249 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
12250 b
->cloneable
& (1 << a
->type
));
12253 static bool check_single_encoder_cloning(struct drm_atomic_state
*state
,
12254 struct intel_crtc
*crtc
,
12255 struct intel_encoder
*encoder
)
12257 struct intel_encoder
*source_encoder
;
12258 struct drm_connector
*connector
;
12259 struct drm_connector_state
*connector_state
;
12262 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
12263 if (connector_state
->crtc
!= &crtc
->base
)
12267 to_intel_encoder(connector_state
->best_encoder
);
12268 if (!encoders_cloneable(encoder
, source_encoder
))
12275 static int icl_add_linked_planes(struct intel_atomic_state
*state
)
12277 struct intel_plane
*plane
, *linked
;
12278 struct intel_plane_state
*plane_state
, *linked_plane_state
;
12281 for_each_new_intel_plane_in_state(state
, plane
, plane_state
, i
) {
12282 linked
= plane_state
->planar_linked_plane
;
12287 linked_plane_state
= intel_atomic_get_plane_state(state
, linked
);
12288 if (IS_ERR(linked_plane_state
))
12289 return PTR_ERR(linked_plane_state
);
12291 WARN_ON(linked_plane_state
->planar_linked_plane
!= plane
);
12292 WARN_ON(linked_plane_state
->planar_slave
== plane_state
->planar_slave
);
12298 static int icl_check_nv12_planes(struct intel_crtc_state
*crtc_state
)
12300 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
12301 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
12302 struct intel_atomic_state
*state
= to_intel_atomic_state(crtc_state
->uapi
.state
);
12303 struct intel_plane
*plane
, *linked
;
12304 struct intel_plane_state
*plane_state
;
12307 if (INTEL_GEN(dev_priv
) < 11)
12311 * Destroy all old plane links and make the slave plane invisible
12312 * in the crtc_state->active_planes mask.
12314 for_each_new_intel_plane_in_state(state
, plane
, plane_state
, i
) {
12315 if (plane
->pipe
!= crtc
->pipe
|| !plane_state
->planar_linked_plane
)
12318 plane_state
->planar_linked_plane
= NULL
;
12319 if (plane_state
->planar_slave
&& !plane_state
->uapi
.visible
) {
12320 crtc_state
->active_planes
&= ~BIT(plane
->id
);
12321 crtc_state
->update_planes
|= BIT(plane
->id
);
12324 plane_state
->planar_slave
= false;
12327 if (!crtc_state
->nv12_planes
)
12330 for_each_new_intel_plane_in_state(state
, plane
, plane_state
, i
) {
12331 struct intel_plane_state
*linked_state
= NULL
;
12333 if (plane
->pipe
!= crtc
->pipe
||
12334 !(crtc_state
->nv12_planes
& BIT(plane
->id
)))
12337 for_each_intel_plane_on_crtc(&dev_priv
->drm
, crtc
, linked
) {
12338 if (!icl_is_nv12_y_plane(linked
->id
))
12341 if (crtc_state
->active_planes
& BIT(linked
->id
))
12344 linked_state
= intel_atomic_get_plane_state(state
, linked
);
12345 if (IS_ERR(linked_state
))
12346 return PTR_ERR(linked_state
);
12351 if (!linked_state
) {
12352 DRM_DEBUG_KMS("Need %d free Y planes for planar YUV\n",
12353 hweight8(crtc_state
->nv12_planes
));
12358 plane_state
->planar_linked_plane
= linked
;
12360 linked_state
->planar_slave
= true;
12361 linked_state
->planar_linked_plane
= plane
;
12362 crtc_state
->active_planes
|= BIT(linked
->id
);
12363 crtc_state
->update_planes
|= BIT(linked
->id
);
12364 DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked
->base
.name
, plane
->base
.name
);
12366 /* Copy parameters to slave plane */
12367 linked_state
->ctl
= plane_state
->ctl
| PLANE_CTL_YUV420_Y_PLANE
;
12368 linked_state
->color_ctl
= plane_state
->color_ctl
;
12369 memcpy(linked_state
->color_plane
, plane_state
->color_plane
,
12370 sizeof(linked_state
->color_plane
));
12372 intel_plane_copy_uapi_to_hw_state(linked_state
, plane_state
);
12373 linked_state
->uapi
.src
= plane_state
->uapi
.src
;
12374 linked_state
->uapi
.dst
= plane_state
->uapi
.dst
;
12376 if (icl_is_hdr_plane(dev_priv
, plane
->id
)) {
12377 if (linked
->id
== PLANE_SPRITE5
)
12378 plane_state
->cus_ctl
|= PLANE_CUS_PLANE_7
;
12379 else if (linked
->id
== PLANE_SPRITE4
)
12380 plane_state
->cus_ctl
|= PLANE_CUS_PLANE_6
;
12382 MISSING_CASE(linked
->id
);
12389 static bool c8_planes_changed(const struct intel_crtc_state
*new_crtc_state
)
12391 struct intel_crtc
*crtc
= to_intel_crtc(new_crtc_state
->uapi
.crtc
);
12392 struct intel_atomic_state
*state
=
12393 to_intel_atomic_state(new_crtc_state
->uapi
.state
);
12394 const struct intel_crtc_state
*old_crtc_state
=
12395 intel_atomic_get_old_crtc_state(state
, crtc
);
12397 return !old_crtc_state
->c8_planes
!= !new_crtc_state
->c8_planes
;
12401 intel_atomic_is_master_connector(struct intel_crtc_state
*crtc_state
)
12403 struct drm_crtc
*crtc
= crtc_state
->uapi
.crtc
;
12404 struct drm_atomic_state
*state
= crtc_state
->uapi
.state
;
12405 struct drm_connector
*connector
;
12406 struct drm_connector_state
*connector_state
;
12409 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
12410 if (connector_state
->crtc
!= crtc
)
12412 if (connector
->has_tile
&&
12413 connector
->tile_h_loc
== connector
->num_h_tile
- 1 &&
12414 connector
->tile_v_loc
== connector
->num_v_tile
- 1)
12421 static void reset_port_sync_mode_state(struct intel_crtc_state
*crtc_state
)
12423 crtc_state
->master_transcoder
= INVALID_TRANSCODER
;
12424 crtc_state
->sync_mode_slaves_mask
= 0;
12427 static int icl_compute_port_sync_crtc_state(struct drm_connector
*connector
,
12428 struct intel_crtc_state
*crtc_state
,
12429 int num_tiled_conns
)
12431 struct drm_crtc
*crtc
= crtc_state
->uapi
.crtc
;
12432 struct intel_atomic_state
*state
= to_intel_atomic_state(crtc_state
->uapi
.state
);
12433 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->uapi
.crtc
->dev
);
12434 struct drm_connector
*master_connector
;
12435 struct drm_connector_list_iter conn_iter
;
12436 struct drm_crtc
*master_crtc
= NULL
;
12437 struct drm_crtc_state
*master_crtc_state
;
12438 struct intel_crtc_state
*master_pipe_config
;
12440 if (INTEL_GEN(dev_priv
) < 11)
12443 if (!intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DP
))
12447 * In case of tiled displays there could be one or more slaves but there is
12448 * only one master. Lets make the CRTC used by the connector corresponding
12449 * to the last horizonal and last vertical tile a master/genlock CRTC.
12450 * All the other CRTCs corresponding to other tiles of the same Tile group
12451 * are the slave CRTCs and hold a pointer to their genlock CRTC.
12452 * If all tiles not present do not make master slave assignments.
12454 if (!connector
->has_tile
||
12455 crtc_state
->hw
.mode
.hdisplay
!= connector
->tile_h_size
||
12456 crtc_state
->hw
.mode
.vdisplay
!= connector
->tile_v_size
||
12457 num_tiled_conns
< connector
->num_h_tile
* connector
->num_v_tile
) {
12458 reset_port_sync_mode_state(crtc_state
);
12461 /* Last Horizontal and last vertical tile connector is a master
12462 * Master's crtc state is already populated in slave for port sync
12464 if (connector
->tile_h_loc
== connector
->num_h_tile
- 1 &&
12465 connector
->tile_v_loc
== connector
->num_v_tile
- 1)
12468 /* Loop through all connectors and configure the Slave crtc_state
12469 * to point to the correct master.
12471 drm_connector_list_iter_begin(&dev_priv
->drm
, &conn_iter
);
12472 drm_for_each_connector_iter(master_connector
, &conn_iter
) {
12473 struct drm_connector_state
*master_conn_state
= NULL
;
12475 if (!(master_connector
->has_tile
&&
12476 master_connector
->tile_group
->id
== connector
->tile_group
->id
))
12478 if (master_connector
->tile_h_loc
!= master_connector
->num_h_tile
- 1 ||
12479 master_connector
->tile_v_loc
!= master_connector
->num_v_tile
- 1)
12482 master_conn_state
= drm_atomic_get_connector_state(&state
->base
,
12484 if (IS_ERR(master_conn_state
)) {
12485 drm_connector_list_iter_end(&conn_iter
);
12486 return PTR_ERR(master_conn_state
);
12488 if (master_conn_state
->crtc
) {
12489 master_crtc
= master_conn_state
->crtc
;
12493 drm_connector_list_iter_end(&conn_iter
);
12495 if (!master_crtc
) {
12496 DRM_DEBUG_KMS("Could not find Master CRTC for Slave CRTC %d\n",
12501 master_crtc_state
= drm_atomic_get_crtc_state(&state
->base
,
12503 if (IS_ERR(master_crtc_state
))
12504 return PTR_ERR(master_crtc_state
);
12506 master_pipe_config
= to_intel_crtc_state(master_crtc_state
);
12507 crtc_state
->master_transcoder
= master_pipe_config
->cpu_transcoder
;
12508 master_pipe_config
->sync_mode_slaves_mask
|=
12509 BIT(crtc_state
->cpu_transcoder
);
12510 DRM_DEBUG_KMS("Master Transcoder = %s added for Slave CRTC = %d, slave transcoder bitmask = %d\n",
12511 transcoder_name(crtc_state
->master_transcoder
),
12513 master_pipe_config
->sync_mode_slaves_mask
);
12518 static int intel_crtc_atomic_check(struct intel_atomic_state
*state
,
12519 struct intel_crtc
*crtc
)
12521 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
12522 struct intel_crtc_state
*crtc_state
=
12523 intel_atomic_get_new_crtc_state(state
, crtc
);
12524 bool mode_changed
= needs_modeset(crtc_state
);
12527 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
) &&
12528 mode_changed
&& !crtc_state
->hw
.active
)
12529 crtc_state
->update_wm_post
= true;
12531 if (mode_changed
&& crtc_state
->hw
.enable
&&
12532 dev_priv
->display
.crtc_compute_clock
&&
12533 !WARN_ON(crtc_state
->shared_dpll
)) {
12534 ret
= dev_priv
->display
.crtc_compute_clock(crtc
, crtc_state
);
12540 * May need to update pipe gamma enable bits
12541 * when C8 planes are getting enabled/disabled.
12543 if (c8_planes_changed(crtc_state
))
12544 crtc_state
->uapi
.color_mgmt_changed
= true;
12546 if (mode_changed
|| crtc_state
->update_pipe
||
12547 crtc_state
->uapi
.color_mgmt_changed
) {
12548 ret
= intel_color_check(crtc_state
);
12554 if (dev_priv
->display
.compute_pipe_wm
) {
12555 ret
= dev_priv
->display
.compute_pipe_wm(crtc_state
);
12557 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
12562 if (dev_priv
->display
.compute_intermediate_wm
) {
12563 if (WARN_ON(!dev_priv
->display
.compute_pipe_wm
))
12567 * Calculate 'intermediate' watermarks that satisfy both the
12568 * old state and the new state. We can program these
12571 ret
= dev_priv
->display
.compute_intermediate_wm(crtc_state
);
12573 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
12578 if (INTEL_GEN(dev_priv
) >= 9) {
12579 if (mode_changed
|| crtc_state
->update_pipe
)
12580 ret
= skl_update_scaler_crtc(crtc_state
);
12582 ret
= intel_atomic_setup_scalers(dev_priv
, crtc
,
12586 if (HAS_IPS(dev_priv
))
12587 crtc_state
->ips_enabled
= hsw_compute_ips_config(crtc_state
);
12592 static void intel_modeset_update_connector_atomic_state(struct drm_device
*dev
)
12594 struct intel_connector
*connector
;
12595 struct drm_connector_list_iter conn_iter
;
12597 drm_connector_list_iter_begin(dev
, &conn_iter
);
12598 for_each_intel_connector_iter(connector
, &conn_iter
) {
12599 if (connector
->base
.state
->crtc
)
12600 drm_connector_put(&connector
->base
);
12602 if (connector
->base
.encoder
) {
12603 connector
->base
.state
->best_encoder
=
12604 connector
->base
.encoder
;
12605 connector
->base
.state
->crtc
=
12606 connector
->base
.encoder
->crtc
;
12608 drm_connector_get(&connector
->base
);
12610 connector
->base
.state
->best_encoder
= NULL
;
12611 connector
->base
.state
->crtc
= NULL
;
12614 drm_connector_list_iter_end(&conn_iter
);
12618 compute_sink_pipe_bpp(const struct drm_connector_state
*conn_state
,
12619 struct intel_crtc_state
*pipe_config
)
12621 struct drm_connector
*connector
= conn_state
->connector
;
12622 const struct drm_display_info
*info
= &connector
->display_info
;
12625 switch (conn_state
->max_bpc
) {
12642 if (bpp
< pipe_config
->pipe_bpp
) {
12643 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
12644 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
12645 connector
->base
.id
, connector
->name
,
12646 bpp
, 3 * info
->bpc
, 3 * conn_state
->max_requested_bpc
,
12647 pipe_config
->pipe_bpp
);
12649 pipe_config
->pipe_bpp
= bpp
;
12656 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
12657 struct intel_crtc_state
*pipe_config
)
12659 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
12660 struct drm_atomic_state
*state
= pipe_config
->uapi
.state
;
12661 struct drm_connector
*connector
;
12662 struct drm_connector_state
*connector_state
;
12665 if ((IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
12666 IS_CHERRYVIEW(dev_priv
)))
12668 else if (INTEL_GEN(dev_priv
) >= 5)
12673 pipe_config
->pipe_bpp
= bpp
;
12675 /* Clamp display bpp to connector max bpp */
12676 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
12679 if (connector_state
->crtc
!= &crtc
->base
)
12682 ret
= compute_sink_pipe_bpp(connector_state
, pipe_config
);
12690 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
12692 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
12693 "type: 0x%x flags: 0x%x\n",
12695 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
12696 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
12697 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
12698 mode
->crtc_vsync_end
, mode
->crtc_vtotal
,
12699 mode
->type
, mode
->flags
);
12703 intel_dump_m_n_config(const struct intel_crtc_state
*pipe_config
,
12704 const char *id
, unsigned int lane_count
,
12705 const struct intel_link_m_n
*m_n
)
12707 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
12709 m_n
->gmch_m
, m_n
->gmch_n
,
12710 m_n
->link_m
, m_n
->link_n
, m_n
->tu
);
12714 intel_dump_infoframe(struct drm_i915_private
*dev_priv
,
12715 const union hdmi_infoframe
*frame
)
12717 if (!drm_debug_enabled(DRM_UT_KMS
))
12720 hdmi_infoframe_log(KERN_DEBUG
, dev_priv
->drm
.dev
, frame
);
12723 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
12725 static const char * const output_type_str
[] = {
12726 OUTPUT_TYPE(UNUSED
),
12727 OUTPUT_TYPE(ANALOG
),
12731 OUTPUT_TYPE(TVOUT
),
12737 OUTPUT_TYPE(DP_MST
),
12742 static void snprintf_output_types(char *buf
, size_t len
,
12743 unsigned int output_types
)
12750 for (i
= 0; i
< ARRAY_SIZE(output_type_str
); i
++) {
12753 if ((output_types
& BIT(i
)) == 0)
12756 r
= snprintf(str
, len
, "%s%s",
12757 str
!= buf
? "," : "", output_type_str
[i
]);
12763 output_types
&= ~BIT(i
);
12766 WARN_ON_ONCE(output_types
!= 0);
12769 static const char * const output_format_str
[] = {
12770 [INTEL_OUTPUT_FORMAT_INVALID
] = "Invalid",
12771 [INTEL_OUTPUT_FORMAT_RGB
] = "RGB",
12772 [INTEL_OUTPUT_FORMAT_YCBCR420
] = "YCBCR4:2:0",
12773 [INTEL_OUTPUT_FORMAT_YCBCR444
] = "YCBCR4:4:4",
12776 static const char *output_formats(enum intel_output_format format
)
12778 if (format
>= ARRAY_SIZE(output_format_str
))
12779 format
= INTEL_OUTPUT_FORMAT_INVALID
;
12780 return output_format_str
[format
];
12783 static void intel_dump_plane_state(const struct intel_plane_state
*plane_state
)
12785 struct intel_plane
*plane
= to_intel_plane(plane_state
->uapi
.plane
);
12786 const struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
12787 struct drm_format_name_buf format_name
;
12790 DRM_DEBUG_KMS("[PLANE:%d:%s] fb: [NOFB], visible: %s\n",
12791 plane
->base
.base
.id
, plane
->base
.name
,
12792 yesno(plane_state
->uapi
.visible
));
12796 DRM_DEBUG_KMS("[PLANE:%d:%s] fb: [FB:%d] %ux%u format = %s, visible: %s\n",
12797 plane
->base
.base
.id
, plane
->base
.name
,
12798 fb
->base
.id
, fb
->width
, fb
->height
,
12799 drm_get_format_name(fb
->format
->format
, &format_name
),
12800 yesno(plane_state
->uapi
.visible
));
12801 DRM_DEBUG_KMS("\trotation: 0x%x, scaler: %d\n",
12802 plane_state
->hw
.rotation
, plane_state
->scaler_id
);
12803 if (plane_state
->uapi
.visible
)
12804 DRM_DEBUG_KMS("\tsrc: " DRM_RECT_FP_FMT
" dst: " DRM_RECT_FMT
"\n",
12805 DRM_RECT_FP_ARG(&plane_state
->uapi
.src
),
12806 DRM_RECT_ARG(&plane_state
->uapi
.dst
));
12809 static void intel_dump_pipe_config(const struct intel_crtc_state
*pipe_config
,
12810 struct intel_atomic_state
*state
,
12811 const char *context
)
12813 struct intel_crtc
*crtc
= to_intel_crtc(pipe_config
->uapi
.crtc
);
12814 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
12815 const struct intel_plane_state
*plane_state
;
12816 struct intel_plane
*plane
;
12820 DRM_DEBUG_KMS("[CRTC:%d:%s] enable: %s %s\n",
12821 crtc
->base
.base
.id
, crtc
->base
.name
,
12822 yesno(pipe_config
->hw
.enable
), context
);
12824 if (!pipe_config
->hw
.enable
)
12827 snprintf_output_types(buf
, sizeof(buf
), pipe_config
->output_types
);
12828 DRM_DEBUG_KMS("active: %s, output_types: %s (0x%x), output format: %s\n",
12829 yesno(pipe_config
->hw
.active
),
12830 buf
, pipe_config
->output_types
,
12831 output_formats(pipe_config
->output_format
));
12833 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
12834 transcoder_name(pipe_config
->cpu_transcoder
),
12835 pipe_config
->pipe_bpp
, pipe_config
->dither
);
12837 if (pipe_config
->has_pch_encoder
)
12838 intel_dump_m_n_config(pipe_config
, "fdi",
12839 pipe_config
->fdi_lanes
,
12840 &pipe_config
->fdi_m_n
);
12842 if (intel_crtc_has_dp_encoder(pipe_config
)) {
12843 intel_dump_m_n_config(pipe_config
, "dp m_n",
12844 pipe_config
->lane_count
, &pipe_config
->dp_m_n
);
12845 if (pipe_config
->has_drrs
)
12846 intel_dump_m_n_config(pipe_config
, "dp m2_n2",
12847 pipe_config
->lane_count
,
12848 &pipe_config
->dp_m2_n2
);
12851 DRM_DEBUG_KMS("audio: %i, infoframes: %i, infoframes enabled: 0x%x\n",
12852 pipe_config
->has_audio
, pipe_config
->has_infoframe
,
12853 pipe_config
->infoframes
.enable
);
12855 if (pipe_config
->infoframes
.enable
&
12856 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GENERAL_CONTROL
))
12857 DRM_DEBUG_KMS("GCP: 0x%x\n", pipe_config
->infoframes
.gcp
);
12858 if (pipe_config
->infoframes
.enable
&
12859 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI
))
12860 intel_dump_infoframe(dev_priv
, &pipe_config
->infoframes
.avi
);
12861 if (pipe_config
->infoframes
.enable
&
12862 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_SPD
))
12863 intel_dump_infoframe(dev_priv
, &pipe_config
->infoframes
.spd
);
12864 if (pipe_config
->infoframes
.enable
&
12865 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_VENDOR
))
12866 intel_dump_infoframe(dev_priv
, &pipe_config
->infoframes
.hdmi
);
12868 DRM_DEBUG_KMS("requested mode:\n");
12869 drm_mode_debug_printmodeline(&pipe_config
->hw
.mode
);
12870 DRM_DEBUG_KMS("adjusted mode:\n");
12871 drm_mode_debug_printmodeline(&pipe_config
->hw
.adjusted_mode
);
12872 intel_dump_crtc_timings(&pipe_config
->hw
.adjusted_mode
);
12873 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
12874 pipe_config
->port_clock
,
12875 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
,
12876 pipe_config
->pixel_rate
);
12878 if (INTEL_GEN(dev_priv
) >= 9)
12879 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
12881 pipe_config
->scaler_state
.scaler_users
,
12882 pipe_config
->scaler_state
.scaler_id
);
12884 if (HAS_GMCH(dev_priv
))
12885 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
12886 pipe_config
->gmch_pfit
.control
,
12887 pipe_config
->gmch_pfit
.pgm_ratios
,
12888 pipe_config
->gmch_pfit
.lvds_border_bits
);
12890 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s, force thru: %s\n",
12891 pipe_config
->pch_pfit
.pos
,
12892 pipe_config
->pch_pfit
.size
,
12893 enableddisabled(pipe_config
->pch_pfit
.enabled
),
12894 yesno(pipe_config
->pch_pfit
.force_thru
));
12896 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
12897 pipe_config
->ips_enabled
, pipe_config
->double_wide
);
12899 intel_dpll_dump_hw_state(dev_priv
, &pipe_config
->dpll_hw_state
);
12901 if (IS_CHERRYVIEW(dev_priv
))
12902 DRM_DEBUG_KMS("cgm_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
12903 pipe_config
->cgm_mode
, pipe_config
->gamma_mode
,
12904 pipe_config
->gamma_enable
, pipe_config
->csc_enable
);
12906 DRM_DEBUG_KMS("csc_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
12907 pipe_config
->csc_mode
, pipe_config
->gamma_mode
,
12908 pipe_config
->gamma_enable
, pipe_config
->csc_enable
);
12910 DRM_DEBUG_KMS("MST master transcoder: %s\n",
12911 transcoder_name(pipe_config
->mst_master_transcoder
));
12917 for_each_new_intel_plane_in_state(state
, plane
, plane_state
, i
) {
12918 if (plane
->pipe
== crtc
->pipe
)
12919 intel_dump_plane_state(plane_state
);
12923 static bool check_digital_port_conflicts(struct intel_atomic_state
*state
)
12925 struct drm_device
*dev
= state
->base
.dev
;
12926 struct drm_connector
*connector
;
12927 struct drm_connector_list_iter conn_iter
;
12928 unsigned int used_ports
= 0;
12929 unsigned int used_mst_ports
= 0;
12933 * We're going to peek into connector->state,
12934 * hence connection_mutex must be held.
12936 drm_modeset_lock_assert_held(&dev
->mode_config
.connection_mutex
);
12939 * Walk the connector list instead of the encoder
12940 * list to detect the problem on ddi platforms
12941 * where there's just one encoder per digital port.
12943 drm_connector_list_iter_begin(dev
, &conn_iter
);
12944 drm_for_each_connector_iter(connector
, &conn_iter
) {
12945 struct drm_connector_state
*connector_state
;
12946 struct intel_encoder
*encoder
;
12949 drm_atomic_get_new_connector_state(&state
->base
,
12951 if (!connector_state
)
12952 connector_state
= connector
->state
;
12954 if (!connector_state
->best_encoder
)
12957 encoder
= to_intel_encoder(connector_state
->best_encoder
);
12959 WARN_ON(!connector_state
->crtc
);
12961 switch (encoder
->type
) {
12962 unsigned int port_mask
;
12963 case INTEL_OUTPUT_DDI
:
12964 if (WARN_ON(!HAS_DDI(to_i915(dev
))))
12966 /* else, fall through */
12967 case INTEL_OUTPUT_DP
:
12968 case INTEL_OUTPUT_HDMI
:
12969 case INTEL_OUTPUT_EDP
:
12970 port_mask
= 1 << encoder
->port
;
12972 /* the same port mustn't appear more than once */
12973 if (used_ports
& port_mask
)
12976 used_ports
|= port_mask
;
12978 case INTEL_OUTPUT_DP_MST
:
12980 1 << encoder
->port
;
12986 drm_connector_list_iter_end(&conn_iter
);
12988 /* can't mix MST and SST/HDMI on the same port */
12989 if (used_ports
& used_mst_ports
)
12996 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_crtc_state
*crtc_state
)
12998 intel_crtc_copy_color_blobs(crtc_state
);
13002 intel_crtc_copy_uapi_to_hw_state(struct intel_crtc_state
*crtc_state
)
13004 crtc_state
->hw
.enable
= crtc_state
->uapi
.enable
;
13005 crtc_state
->hw
.active
= crtc_state
->uapi
.active
;
13006 crtc_state
->hw
.mode
= crtc_state
->uapi
.mode
;
13007 crtc_state
->hw
.adjusted_mode
= crtc_state
->uapi
.adjusted_mode
;
13008 intel_crtc_copy_uapi_to_hw_state_nomodeset(crtc_state
);
13011 static void intel_crtc_copy_hw_to_uapi_state(struct intel_crtc_state
*crtc_state
)
13013 crtc_state
->uapi
.enable
= crtc_state
->hw
.enable
;
13014 crtc_state
->uapi
.active
= crtc_state
->hw
.active
;
13015 WARN_ON(drm_atomic_set_mode_for_crtc(&crtc_state
->uapi
, &crtc_state
->hw
.mode
) < 0);
13017 crtc_state
->uapi
.adjusted_mode
= crtc_state
->hw
.adjusted_mode
;
13019 /* copy color blobs to uapi */
13020 drm_property_replace_blob(&crtc_state
->uapi
.degamma_lut
,
13021 crtc_state
->hw
.degamma_lut
);
13022 drm_property_replace_blob(&crtc_state
->uapi
.gamma_lut
,
13023 crtc_state
->hw
.gamma_lut
);
13024 drm_property_replace_blob(&crtc_state
->uapi
.ctm
,
13025 crtc_state
->hw
.ctm
);
13029 intel_crtc_prepare_cleared_state(struct intel_crtc_state
*crtc_state
)
13031 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
13032 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
13033 struct intel_crtc_state
*saved_state
;
13035 saved_state
= intel_crtc_state_alloc(crtc
);
13039 /* free the old crtc_state->hw members */
13040 intel_crtc_free_hw_state(crtc_state
);
13042 /* FIXME: before the switch to atomic started, a new pipe_config was
13043 * kzalloc'd. Code that depends on any field being zero should be
13044 * fixed, so that the crtc_state can be safely duplicated. For now,
13045 * only fields that are know to not cause problems are preserved. */
13047 saved_state
->uapi
= crtc_state
->uapi
;
13048 saved_state
->scaler_state
= crtc_state
->scaler_state
;
13049 saved_state
->shared_dpll
= crtc_state
->shared_dpll
;
13050 saved_state
->dpll_hw_state
= crtc_state
->dpll_hw_state
;
13051 memcpy(saved_state
->icl_port_dplls
, crtc_state
->icl_port_dplls
,
13052 sizeof(saved_state
->icl_port_dplls
));
13053 saved_state
->crc_enabled
= crtc_state
->crc_enabled
;
13054 if (IS_G4X(dev_priv
) ||
13055 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
13056 saved_state
->wm
= crtc_state
->wm
;
13058 * Save the slave bitmask which gets filled for master crtc state during
13059 * slave atomic check call. For all other CRTCs reset the port sync variables
13060 * crtc_state->master_transcoder needs to be set to INVALID
13062 reset_port_sync_mode_state(saved_state
);
13063 if (intel_atomic_is_master_connector(crtc_state
))
13064 saved_state
->sync_mode_slaves_mask
=
13065 crtc_state
->sync_mode_slaves_mask
;
13067 memcpy(crtc_state
, saved_state
, sizeof(*crtc_state
));
13068 kfree(saved_state
);
13070 intel_crtc_copy_uapi_to_hw_state(crtc_state
);
13076 intel_modeset_pipe_config(struct intel_crtc_state
*pipe_config
)
13078 struct drm_crtc
*crtc
= pipe_config
->uapi
.crtc
;
13079 struct drm_atomic_state
*state
= pipe_config
->uapi
.state
;
13080 struct intel_encoder
*encoder
;
13081 struct drm_connector
*connector
;
13082 struct drm_connector_state
*connector_state
;
13084 int i
, tile_group_id
= -1, num_tiled_conns
= 0;
13087 pipe_config
->cpu_transcoder
=
13088 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
13091 * Sanitize sync polarity flags based on requested ones. If neither
13092 * positive or negative polarity is requested, treat this as meaning
13093 * negative polarity.
13095 if (!(pipe_config
->hw
.adjusted_mode
.flags
&
13096 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
13097 pipe_config
->hw
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
13099 if (!(pipe_config
->hw
.adjusted_mode
.flags
&
13100 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
13101 pipe_config
->hw
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
13103 ret
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
13108 base_bpp
= pipe_config
->pipe_bpp
;
13111 * Determine the real pipe dimensions. Note that stereo modes can
13112 * increase the actual pipe size due to the frame doubling and
13113 * insertion of additional space for blanks between the frame. This
13114 * is stored in the crtc timings. We use the requested mode to do this
13115 * computation to clearly distinguish it from the adjusted mode, which
13116 * can be changed by the connectors in the below retry loop.
13118 drm_mode_get_hv_timing(&pipe_config
->hw
.mode
,
13119 &pipe_config
->pipe_src_w
,
13120 &pipe_config
->pipe_src_h
);
13122 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
13123 if (connector_state
->crtc
!= crtc
)
13126 encoder
= to_intel_encoder(connector_state
->best_encoder
);
13128 if (!check_single_encoder_cloning(state
, to_intel_crtc(crtc
), encoder
)) {
13129 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
13134 * Determine output_types before calling the .compute_config()
13135 * hooks so that the hooks can use this information safely.
13137 if (encoder
->compute_output_type
)
13138 pipe_config
->output_types
|=
13139 BIT(encoder
->compute_output_type(encoder
, pipe_config
,
13142 pipe_config
->output_types
|= BIT(encoder
->type
);
13146 /* Ensure the port clock defaults are reset when retrying. */
13147 pipe_config
->port_clock
= 0;
13148 pipe_config
->pixel_multiplier
= 1;
13150 /* Fill in default crtc timings, allow encoders to overwrite them. */
13151 drm_mode_set_crtcinfo(&pipe_config
->hw
.adjusted_mode
,
13152 CRTC_STEREO_DOUBLE
);
13154 /* Get tile_group_id of tiled connector */
13155 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
13156 if (connector_state
->crtc
== crtc
&&
13157 connector
->has_tile
) {
13158 tile_group_id
= connector
->tile_group
->id
;
13163 /* Get total number of tiled connectors in state that belong to
13166 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
13167 if (connector
->has_tile
&&
13168 connector
->tile_group
->id
== tile_group_id
)
13172 /* Pass our mode to the connectors and the CRTC to give them a chance to
13173 * adjust it according to limitations or connector properties, and also
13174 * a chance to reject the mode entirely.
13176 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
13177 if (connector_state
->crtc
!= crtc
)
13180 ret
= icl_compute_port_sync_crtc_state(connector
, pipe_config
,
13183 DRM_DEBUG_KMS("Cannot assign Sync Mode CRTCs: %d\n",
13188 encoder
= to_intel_encoder(connector_state
->best_encoder
);
13189 ret
= encoder
->compute_config(encoder
, pipe_config
,
13192 if (ret
!= -EDEADLK
)
13193 DRM_DEBUG_KMS("Encoder config failure: %d\n",
13199 /* Set default port clock if not overwritten by the encoder. Needs to be
13200 * done afterwards in case the encoder adjusts the mode. */
13201 if (!pipe_config
->port_clock
)
13202 pipe_config
->port_clock
= pipe_config
->hw
.adjusted_mode
.crtc_clock
13203 * pipe_config
->pixel_multiplier
;
13205 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
13206 if (ret
== -EDEADLK
)
13209 DRM_DEBUG_KMS("CRTC fixup failed\n");
13213 if (ret
== RETRY
) {
13214 if (WARN(!retry
, "loop in pipe configuration computation\n"))
13217 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
13219 goto encoder_retry
;
13222 /* Dithering seems to not pass-through bits correctly when it should, so
13223 * only enable it on 6bpc panels and when its not a compliance
13224 * test requesting 6bpc video pattern.
13226 pipe_config
->dither
= (pipe_config
->pipe_bpp
== 6*3) &&
13227 !pipe_config
->dither_force_disable
;
13228 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
13229 base_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
13232 * Make drm_calc_timestamping_constants in
13233 * drm_atomic_helper_update_legacy_modeset_state() happy
13235 pipe_config
->uapi
.adjusted_mode
= pipe_config
->hw
.adjusted_mode
;
13240 bool intel_fuzzy_clock_check(int clock1
, int clock2
)
13244 if (clock1
== clock2
)
13247 if (!clock1
|| !clock2
)
13250 diff
= abs(clock1
- clock2
);
13252 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
13259 intel_compare_m_n(unsigned int m
, unsigned int n
,
13260 unsigned int m2
, unsigned int n2
,
13263 if (m
== m2
&& n
== n2
)
13266 if (exact
|| !m
|| !n
|| !m2
|| !n2
)
13269 BUILD_BUG_ON(DATA_LINK_M_N_MASK
> INT_MAX
);
13276 } else if (n
< n2
) {
13286 return intel_fuzzy_clock_check(m
, m2
);
13290 intel_compare_link_m_n(const struct intel_link_m_n
*m_n
,
13291 const struct intel_link_m_n
*m2_n2
,
13294 return m_n
->tu
== m2_n2
->tu
&&
13295 intel_compare_m_n(m_n
->gmch_m
, m_n
->gmch_n
,
13296 m2_n2
->gmch_m
, m2_n2
->gmch_n
, exact
) &&
13297 intel_compare_m_n(m_n
->link_m
, m_n
->link_n
,
13298 m2_n2
->link_m
, m2_n2
->link_n
, exact
);
13302 intel_compare_infoframe(const union hdmi_infoframe
*a
,
13303 const union hdmi_infoframe
*b
)
13305 return memcmp(a
, b
, sizeof(*a
)) == 0;
13309 pipe_config_infoframe_mismatch(struct drm_i915_private
*dev_priv
,
13310 bool fastset
, const char *name
,
13311 const union hdmi_infoframe
*a
,
13312 const union hdmi_infoframe
*b
)
13315 if (!drm_debug_enabled(DRM_UT_KMS
))
13318 DRM_DEBUG_KMS("fastset mismatch in %s infoframe\n", name
);
13319 DRM_DEBUG_KMS("expected:\n");
13320 hdmi_infoframe_log(KERN_DEBUG
, dev_priv
->drm
.dev
, a
);
13321 DRM_DEBUG_KMS("found:\n");
13322 hdmi_infoframe_log(KERN_DEBUG
, dev_priv
->drm
.dev
, b
);
13324 DRM_ERROR("mismatch in %s infoframe\n", name
);
13325 DRM_ERROR("expected:\n");
13326 hdmi_infoframe_log(KERN_ERR
, dev_priv
->drm
.dev
, a
);
13327 DRM_ERROR("found:\n");
13328 hdmi_infoframe_log(KERN_ERR
, dev_priv
->drm
.dev
, b
);
13332 static void __printf(4, 5)
13333 pipe_config_mismatch(bool fastset
, const struct intel_crtc
*crtc
,
13334 const char *name
, const char *format
, ...)
13336 struct va_format vaf
;
13339 va_start(args
, format
);
13344 DRM_DEBUG_KMS("[CRTC:%d:%s] fastset mismatch in %s %pV\n",
13345 crtc
->base
.base
.id
, crtc
->base
.name
, name
, &vaf
);
13347 DRM_ERROR("[CRTC:%d:%s] mismatch in %s %pV\n",
13348 crtc
->base
.base
.id
, crtc
->base
.name
, name
, &vaf
);
13353 static bool fastboot_enabled(struct drm_i915_private
*dev_priv
)
13355 if (i915_modparams
.fastboot
!= -1)
13356 return i915_modparams
.fastboot
;
13358 /* Enable fastboot by default on Skylake and newer */
13359 if (INTEL_GEN(dev_priv
) >= 9)
13362 /* Enable fastboot by default on VLV and CHV */
13363 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
13366 /* Disabled by default on all others */
13371 intel_pipe_config_compare(const struct intel_crtc_state
*current_config
,
13372 const struct intel_crtc_state
*pipe_config
,
13375 struct drm_i915_private
*dev_priv
= to_i915(current_config
->uapi
.crtc
->dev
);
13376 struct intel_crtc
*crtc
= to_intel_crtc(pipe_config
->uapi
.crtc
);
13379 bool fixup_inherited
= fastset
&&
13380 (current_config
->hw
.mode
.private_flags
& I915_MODE_FLAG_INHERITED
) &&
13381 !(pipe_config
->hw
.mode
.private_flags
& I915_MODE_FLAG_INHERITED
);
13383 if (fixup_inherited
&& !fastboot_enabled(dev_priv
)) {
13384 DRM_DEBUG_KMS("initial modeset and fastboot not set\n");
13388 #define PIPE_CONF_CHECK_X(name) do { \
13389 if (current_config->name != pipe_config->name) { \
13390 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13391 "(expected 0x%08x, found 0x%08x)", \
13392 current_config->name, \
13393 pipe_config->name); \
13398 #define PIPE_CONF_CHECK_I(name) do { \
13399 if (current_config->name != pipe_config->name) { \
13400 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13401 "(expected %i, found %i)", \
13402 current_config->name, \
13403 pipe_config->name); \
13408 #define PIPE_CONF_CHECK_BOOL(name) do { \
13409 if (current_config->name != pipe_config->name) { \
13410 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13411 "(expected %s, found %s)", \
13412 yesno(current_config->name), \
13413 yesno(pipe_config->name)); \
13419 * Checks state where we only read out the enabling, but not the entire
13420 * state itself (like full infoframes or ELD for audio). These states
13421 * require a full modeset on bootup to fix up.
13423 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
13424 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
13425 PIPE_CONF_CHECK_BOOL(name); \
13427 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13428 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)", \
13429 yesno(current_config->name), \
13430 yesno(pipe_config->name)); \
13435 #define PIPE_CONF_CHECK_P(name) do { \
13436 if (current_config->name != pipe_config->name) { \
13437 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13438 "(expected %p, found %p)", \
13439 current_config->name, \
13440 pipe_config->name); \
13445 #define PIPE_CONF_CHECK_M_N(name) do { \
13446 if (!intel_compare_link_m_n(¤t_config->name, \
13447 &pipe_config->name,\
13449 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13450 "(expected tu %i gmch %i/%i link %i/%i, " \
13451 "found tu %i, gmch %i/%i link %i/%i)", \
13452 current_config->name.tu, \
13453 current_config->name.gmch_m, \
13454 current_config->name.gmch_n, \
13455 current_config->name.link_m, \
13456 current_config->name.link_n, \
13457 pipe_config->name.tu, \
13458 pipe_config->name.gmch_m, \
13459 pipe_config->name.gmch_n, \
13460 pipe_config->name.link_m, \
13461 pipe_config->name.link_n); \
13466 /* This is required for BDW+ where there is only one set of registers for
13467 * switching between high and low RR.
13468 * This macro can be used whenever a comparison has to be made between one
13469 * hw state and multiple sw state variables.
13471 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
13472 if (!intel_compare_link_m_n(¤t_config->name, \
13473 &pipe_config->name, !fastset) && \
13474 !intel_compare_link_m_n(¤t_config->alt_name, \
13475 &pipe_config->name, !fastset)) { \
13476 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13477 "(expected tu %i gmch %i/%i link %i/%i, " \
13478 "or tu %i gmch %i/%i link %i/%i, " \
13479 "found tu %i, gmch %i/%i link %i/%i)", \
13480 current_config->name.tu, \
13481 current_config->name.gmch_m, \
13482 current_config->name.gmch_n, \
13483 current_config->name.link_m, \
13484 current_config->name.link_n, \
13485 current_config->alt_name.tu, \
13486 current_config->alt_name.gmch_m, \
13487 current_config->alt_name.gmch_n, \
13488 current_config->alt_name.link_m, \
13489 current_config->alt_name.link_n, \
13490 pipe_config->name.tu, \
13491 pipe_config->name.gmch_m, \
13492 pipe_config->name.gmch_n, \
13493 pipe_config->name.link_m, \
13494 pipe_config->name.link_n); \
13499 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
13500 if ((current_config->name ^ pipe_config->name) & (mask)) { \
13501 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13502 "(%x) (expected %i, found %i)", \
13504 current_config->name & (mask), \
13505 pipe_config->name & (mask)); \
13510 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
13511 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
13512 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13513 "(expected %i, found %i)", \
13514 current_config->name, \
13515 pipe_config->name); \
13520 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
13521 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
13522 &pipe_config->infoframes.name)) { \
13523 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
13524 ¤t_config->infoframes.name, \
13525 &pipe_config->infoframes.name); \
13530 #define PIPE_CONF_CHECK_COLOR_LUT(name1, name2, bit_precision) do { \
13531 if (current_config->name1 != pipe_config->name1) { \
13532 pipe_config_mismatch(fastset, crtc, __stringify(name1), \
13533 "(expected %i, found %i, won't compare lut values)", \
13534 current_config->name1, \
13535 pipe_config->name1); \
13538 if (!intel_color_lut_equal(current_config->name2, \
13539 pipe_config->name2, pipe_config->name1, \
13540 bit_precision)) { \
13541 pipe_config_mismatch(fastset, crtc, __stringify(name2), \
13542 "hw_state doesn't match sw_state"); \
13548 #define PIPE_CONF_QUIRK(quirk) \
13549 ((current_config->quirks | pipe_config->quirks) & (quirk))
13551 PIPE_CONF_CHECK_I(cpu_transcoder
);
13553 PIPE_CONF_CHECK_BOOL(has_pch_encoder
);
13554 PIPE_CONF_CHECK_I(fdi_lanes
);
13555 PIPE_CONF_CHECK_M_N(fdi_m_n
);
13557 PIPE_CONF_CHECK_I(lane_count
);
13558 PIPE_CONF_CHECK_X(lane_lat_optim_mask
);
13560 if (INTEL_GEN(dev_priv
) < 8) {
13561 PIPE_CONF_CHECK_M_N(dp_m_n
);
13563 if (current_config
->has_drrs
)
13564 PIPE_CONF_CHECK_M_N(dp_m2_n2
);
13566 PIPE_CONF_CHECK_M_N_ALT(dp_m_n
, dp_m2_n2
);
13568 PIPE_CONF_CHECK_X(output_types
);
13570 PIPE_CONF_CHECK_I(hw
.adjusted_mode
.crtc_hdisplay
);
13571 PIPE_CONF_CHECK_I(hw
.adjusted_mode
.crtc_htotal
);
13572 PIPE_CONF_CHECK_I(hw
.adjusted_mode
.crtc_hblank_start
);
13573 PIPE_CONF_CHECK_I(hw
.adjusted_mode
.crtc_hblank_end
);
13574 PIPE_CONF_CHECK_I(hw
.adjusted_mode
.crtc_hsync_start
);
13575 PIPE_CONF_CHECK_I(hw
.adjusted_mode
.crtc_hsync_end
);
13577 PIPE_CONF_CHECK_I(hw
.adjusted_mode
.crtc_vdisplay
);
13578 PIPE_CONF_CHECK_I(hw
.adjusted_mode
.crtc_vtotal
);
13579 PIPE_CONF_CHECK_I(hw
.adjusted_mode
.crtc_vblank_start
);
13580 PIPE_CONF_CHECK_I(hw
.adjusted_mode
.crtc_vblank_end
);
13581 PIPE_CONF_CHECK_I(hw
.adjusted_mode
.crtc_vsync_start
);
13582 PIPE_CONF_CHECK_I(hw
.adjusted_mode
.crtc_vsync_end
);
13584 PIPE_CONF_CHECK_I(pixel_multiplier
);
13585 PIPE_CONF_CHECK_I(output_format
);
13586 PIPE_CONF_CHECK_I(dc3co_exitline
);
13587 PIPE_CONF_CHECK_BOOL(has_hdmi_sink
);
13588 if ((INTEL_GEN(dev_priv
) < 8 && !IS_HASWELL(dev_priv
)) ||
13589 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
13590 PIPE_CONF_CHECK_BOOL(limited_color_range
);
13592 PIPE_CONF_CHECK_BOOL(hdmi_scrambling
);
13593 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio
);
13594 PIPE_CONF_CHECK_BOOL(has_infoframe
);
13595 PIPE_CONF_CHECK_BOOL(fec_enable
);
13597 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio
);
13599 PIPE_CONF_CHECK_FLAGS(hw
.adjusted_mode
.flags
,
13600 DRM_MODE_FLAG_INTERLACE
);
13602 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
13603 PIPE_CONF_CHECK_FLAGS(hw
.adjusted_mode
.flags
,
13604 DRM_MODE_FLAG_PHSYNC
);
13605 PIPE_CONF_CHECK_FLAGS(hw
.adjusted_mode
.flags
,
13606 DRM_MODE_FLAG_NHSYNC
);
13607 PIPE_CONF_CHECK_FLAGS(hw
.adjusted_mode
.flags
,
13608 DRM_MODE_FLAG_PVSYNC
);
13609 PIPE_CONF_CHECK_FLAGS(hw
.adjusted_mode
.flags
,
13610 DRM_MODE_FLAG_NVSYNC
);
13613 PIPE_CONF_CHECK_X(gmch_pfit
.control
);
13614 /* pfit ratios are autocomputed by the hw on gen4+ */
13615 if (INTEL_GEN(dev_priv
) < 4)
13616 PIPE_CONF_CHECK_X(gmch_pfit
.pgm_ratios
);
13617 PIPE_CONF_CHECK_X(gmch_pfit
.lvds_border_bits
);
13620 * Changing the EDP transcoder input mux
13621 * (A_ONOFF vs. A_ON) requires a full modeset.
13623 PIPE_CONF_CHECK_BOOL(pch_pfit
.force_thru
);
13626 PIPE_CONF_CHECK_I(pipe_src_w
);
13627 PIPE_CONF_CHECK_I(pipe_src_h
);
13629 PIPE_CONF_CHECK_BOOL(pch_pfit
.enabled
);
13630 if (current_config
->pch_pfit
.enabled
) {
13631 PIPE_CONF_CHECK_X(pch_pfit
.pos
);
13632 PIPE_CONF_CHECK_X(pch_pfit
.size
);
13635 PIPE_CONF_CHECK_I(scaler_state
.scaler_id
);
13636 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate
);
13638 PIPE_CONF_CHECK_X(gamma_mode
);
13639 if (IS_CHERRYVIEW(dev_priv
))
13640 PIPE_CONF_CHECK_X(cgm_mode
);
13642 PIPE_CONF_CHECK_X(csc_mode
);
13643 PIPE_CONF_CHECK_BOOL(gamma_enable
);
13644 PIPE_CONF_CHECK_BOOL(csc_enable
);
13646 bp_gamma
= intel_color_get_gamma_bit_precision(pipe_config
);
13648 PIPE_CONF_CHECK_COLOR_LUT(gamma_mode
, hw
.gamma_lut
, bp_gamma
);
13652 PIPE_CONF_CHECK_BOOL(double_wide
);
13654 PIPE_CONF_CHECK_P(shared_dpll
);
13655 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
13656 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
13657 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
13658 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
13659 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
13660 PIPE_CONF_CHECK_X(dpll_hw_state
.spll
);
13661 PIPE_CONF_CHECK_X(dpll_hw_state
.ctrl1
);
13662 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr1
);
13663 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr2
);
13664 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr0
);
13665 PIPE_CONF_CHECK_X(dpll_hw_state
.ebb0
);
13666 PIPE_CONF_CHECK_X(dpll_hw_state
.ebb4
);
13667 PIPE_CONF_CHECK_X(dpll_hw_state
.pll0
);
13668 PIPE_CONF_CHECK_X(dpll_hw_state
.pll1
);
13669 PIPE_CONF_CHECK_X(dpll_hw_state
.pll2
);
13670 PIPE_CONF_CHECK_X(dpll_hw_state
.pll3
);
13671 PIPE_CONF_CHECK_X(dpll_hw_state
.pll6
);
13672 PIPE_CONF_CHECK_X(dpll_hw_state
.pll8
);
13673 PIPE_CONF_CHECK_X(dpll_hw_state
.pll9
);
13674 PIPE_CONF_CHECK_X(dpll_hw_state
.pll10
);
13675 PIPE_CONF_CHECK_X(dpll_hw_state
.pcsdw12
);
13676 PIPE_CONF_CHECK_X(dpll_hw_state
.mg_refclkin_ctl
);
13677 PIPE_CONF_CHECK_X(dpll_hw_state
.mg_clktop2_coreclkctl1
);
13678 PIPE_CONF_CHECK_X(dpll_hw_state
.mg_clktop2_hsclkctl
);
13679 PIPE_CONF_CHECK_X(dpll_hw_state
.mg_pll_div0
);
13680 PIPE_CONF_CHECK_X(dpll_hw_state
.mg_pll_div1
);
13681 PIPE_CONF_CHECK_X(dpll_hw_state
.mg_pll_lf
);
13682 PIPE_CONF_CHECK_X(dpll_hw_state
.mg_pll_frac_lock
);
13683 PIPE_CONF_CHECK_X(dpll_hw_state
.mg_pll_ssc
);
13684 PIPE_CONF_CHECK_X(dpll_hw_state
.mg_pll_bias
);
13685 PIPE_CONF_CHECK_X(dpll_hw_state
.mg_pll_tdc_coldst_bias
);
13687 PIPE_CONF_CHECK_X(dsi_pll
.ctrl
);
13688 PIPE_CONF_CHECK_X(dsi_pll
.div
);
13690 if (IS_G4X(dev_priv
) || INTEL_GEN(dev_priv
) >= 5)
13691 PIPE_CONF_CHECK_I(pipe_bpp
);
13693 PIPE_CONF_CHECK_CLOCK_FUZZY(hw
.adjusted_mode
.crtc_clock
);
13694 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
13696 PIPE_CONF_CHECK_I(min_voltage_level
);
13698 PIPE_CONF_CHECK_X(infoframes
.enable
);
13699 PIPE_CONF_CHECK_X(infoframes
.gcp
);
13700 PIPE_CONF_CHECK_INFOFRAME(avi
);
13701 PIPE_CONF_CHECK_INFOFRAME(spd
);
13702 PIPE_CONF_CHECK_INFOFRAME(hdmi
);
13703 PIPE_CONF_CHECK_INFOFRAME(drm
);
13705 PIPE_CONF_CHECK_I(sync_mode_slaves_mask
);
13706 PIPE_CONF_CHECK_I(master_transcoder
);
13708 PIPE_CONF_CHECK_I(dsc
.compression_enable
);
13709 PIPE_CONF_CHECK_I(dsc
.dsc_split
);
13710 PIPE_CONF_CHECK_I(dsc
.compressed_bpp
);
13712 PIPE_CONF_CHECK_I(mst_master_transcoder
);
13714 #undef PIPE_CONF_CHECK_X
13715 #undef PIPE_CONF_CHECK_I
13716 #undef PIPE_CONF_CHECK_BOOL
13717 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
13718 #undef PIPE_CONF_CHECK_P
13719 #undef PIPE_CONF_CHECK_FLAGS
13720 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
13721 #undef PIPE_CONF_CHECK_COLOR_LUT
13722 #undef PIPE_CONF_QUIRK
13727 static void intel_pipe_config_sanity_check(struct drm_i915_private
*dev_priv
,
13728 const struct intel_crtc_state
*pipe_config
)
13730 if (pipe_config
->has_pch_encoder
) {
13731 int fdi_dotclock
= intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
13732 &pipe_config
->fdi_m_n
);
13733 int dotclock
= pipe_config
->hw
.adjusted_mode
.crtc_clock
;
13736 * FDI already provided one idea for the dotclock.
13737 * Yell if the encoder disagrees.
13739 WARN(!intel_fuzzy_clock_check(fdi_dotclock
, dotclock
),
13740 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
13741 fdi_dotclock
, dotclock
);
13745 static void verify_wm_state(struct intel_crtc
*crtc
,
13746 struct intel_crtc_state
*new_crtc_state
)
13748 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
13749 struct skl_hw_state
{
13750 struct skl_ddb_entry ddb_y
[I915_MAX_PLANES
];
13751 struct skl_ddb_entry ddb_uv
[I915_MAX_PLANES
];
13752 struct skl_ddb_allocation ddb
;
13753 struct skl_pipe_wm wm
;
13755 struct skl_ddb_allocation
*sw_ddb
;
13756 struct skl_pipe_wm
*sw_wm
;
13757 struct skl_ddb_entry
*hw_ddb_entry
, *sw_ddb_entry
;
13758 const enum pipe pipe
= crtc
->pipe
;
13759 int plane
, level
, max_level
= ilk_wm_max_level(dev_priv
);
13761 if (INTEL_GEN(dev_priv
) < 9 || !new_crtc_state
->hw
.active
)
13764 hw
= kzalloc(sizeof(*hw
), GFP_KERNEL
);
13768 skl_pipe_wm_get_hw_state(crtc
, &hw
->wm
);
13769 sw_wm
= &new_crtc_state
->wm
.skl
.optimal
;
13771 skl_pipe_ddb_get_hw_state(crtc
, hw
->ddb_y
, hw
->ddb_uv
);
13773 skl_ddb_get_hw_state(dev_priv
, &hw
->ddb
);
13774 sw_ddb
= &dev_priv
->wm
.skl_hw
.ddb
;
13776 if (INTEL_GEN(dev_priv
) >= 11 &&
13777 hw
->ddb
.enabled_slices
!= sw_ddb
->enabled_slices
)
13778 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
13779 sw_ddb
->enabled_slices
,
13780 hw
->ddb
.enabled_slices
);
13783 for_each_universal_plane(dev_priv
, pipe
, plane
) {
13784 struct skl_plane_wm
*hw_plane_wm
, *sw_plane_wm
;
13786 hw_plane_wm
= &hw
->wm
.planes
[plane
];
13787 sw_plane_wm
= &sw_wm
->planes
[plane
];
13790 for (level
= 0; level
<= max_level
; level
++) {
13791 if (skl_wm_level_equals(&hw_plane_wm
->wm
[level
],
13792 &sw_plane_wm
->wm
[level
]))
13795 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",
13796 pipe_name(pipe
), plane
+ 1, level
,
13797 sw_plane_wm
->wm
[level
].plane_en
,
13798 sw_plane_wm
->wm
[level
].plane_res_b
,
13799 sw_plane_wm
->wm
[level
].plane_res_l
,
13800 hw_plane_wm
->wm
[level
].plane_en
,
13801 hw_plane_wm
->wm
[level
].plane_res_b
,
13802 hw_plane_wm
->wm
[level
].plane_res_l
);
13805 if (!skl_wm_level_equals(&hw_plane_wm
->trans_wm
,
13806 &sw_plane_wm
->trans_wm
)) {
13807 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",
13808 pipe_name(pipe
), plane
+ 1,
13809 sw_plane_wm
->trans_wm
.plane_en
,
13810 sw_plane_wm
->trans_wm
.plane_res_b
,
13811 sw_plane_wm
->trans_wm
.plane_res_l
,
13812 hw_plane_wm
->trans_wm
.plane_en
,
13813 hw_plane_wm
->trans_wm
.plane_res_b
,
13814 hw_plane_wm
->trans_wm
.plane_res_l
);
13818 hw_ddb_entry
= &hw
->ddb_y
[plane
];
13819 sw_ddb_entry
= &new_crtc_state
->wm
.skl
.plane_ddb_y
[plane
];
13821 if (!skl_ddb_entry_equal(hw_ddb_entry
, sw_ddb_entry
)) {
13822 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
13823 pipe_name(pipe
), plane
+ 1,
13824 sw_ddb_entry
->start
, sw_ddb_entry
->end
,
13825 hw_ddb_entry
->start
, hw_ddb_entry
->end
);
13831 * If the cursor plane isn't active, we may not have updated it's ddb
13832 * allocation. In that case since the ddb allocation will be updated
13833 * once the plane becomes visible, we can skip this check
13836 struct skl_plane_wm
*hw_plane_wm
, *sw_plane_wm
;
13838 hw_plane_wm
= &hw
->wm
.planes
[PLANE_CURSOR
];
13839 sw_plane_wm
= &sw_wm
->planes
[PLANE_CURSOR
];
13842 for (level
= 0; level
<= max_level
; level
++) {
13843 if (skl_wm_level_equals(&hw_plane_wm
->wm
[level
],
13844 &sw_plane_wm
->wm
[level
]))
13847 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",
13848 pipe_name(pipe
), level
,
13849 sw_plane_wm
->wm
[level
].plane_en
,
13850 sw_plane_wm
->wm
[level
].plane_res_b
,
13851 sw_plane_wm
->wm
[level
].plane_res_l
,
13852 hw_plane_wm
->wm
[level
].plane_en
,
13853 hw_plane_wm
->wm
[level
].plane_res_b
,
13854 hw_plane_wm
->wm
[level
].plane_res_l
);
13857 if (!skl_wm_level_equals(&hw_plane_wm
->trans_wm
,
13858 &sw_plane_wm
->trans_wm
)) {
13859 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13861 sw_plane_wm
->trans_wm
.plane_en
,
13862 sw_plane_wm
->trans_wm
.plane_res_b
,
13863 sw_plane_wm
->trans_wm
.plane_res_l
,
13864 hw_plane_wm
->trans_wm
.plane_en
,
13865 hw_plane_wm
->trans_wm
.plane_res_b
,
13866 hw_plane_wm
->trans_wm
.plane_res_l
);
13870 hw_ddb_entry
= &hw
->ddb_y
[PLANE_CURSOR
];
13871 sw_ddb_entry
= &new_crtc_state
->wm
.skl
.plane_ddb_y
[PLANE_CURSOR
];
13873 if (!skl_ddb_entry_equal(hw_ddb_entry
, sw_ddb_entry
)) {
13874 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
13876 sw_ddb_entry
->start
, sw_ddb_entry
->end
,
13877 hw_ddb_entry
->start
, hw_ddb_entry
->end
);
13885 verify_connector_state(struct intel_atomic_state
*state
,
13886 struct intel_crtc
*crtc
)
13888 struct drm_connector
*connector
;
13889 struct drm_connector_state
*new_conn_state
;
13892 for_each_new_connector_in_state(&state
->base
, connector
, new_conn_state
, i
) {
13893 struct drm_encoder
*encoder
= connector
->encoder
;
13894 struct intel_crtc_state
*crtc_state
= NULL
;
13896 if (new_conn_state
->crtc
!= &crtc
->base
)
13900 crtc_state
= intel_atomic_get_new_crtc_state(state
, crtc
);
13902 intel_connector_verify_state(crtc_state
, new_conn_state
);
13904 I915_STATE_WARN(new_conn_state
->best_encoder
!= encoder
,
13905 "connector's atomic encoder doesn't match legacy encoder\n");
13910 verify_encoder_state(struct drm_i915_private
*dev_priv
, struct intel_atomic_state
*state
)
13912 struct intel_encoder
*encoder
;
13913 struct drm_connector
*connector
;
13914 struct drm_connector_state
*old_conn_state
, *new_conn_state
;
13917 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
13918 bool enabled
= false, found
= false;
13921 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
13922 encoder
->base
.base
.id
,
13923 encoder
->base
.name
);
13925 for_each_oldnew_connector_in_state(&state
->base
, connector
, old_conn_state
,
13926 new_conn_state
, i
) {
13927 if (old_conn_state
->best_encoder
== &encoder
->base
)
13930 if (new_conn_state
->best_encoder
!= &encoder
->base
)
13932 found
= enabled
= true;
13934 I915_STATE_WARN(new_conn_state
->crtc
!=
13935 encoder
->base
.crtc
,
13936 "connector's crtc doesn't match encoder crtc\n");
13942 I915_STATE_WARN(!!encoder
->base
.crtc
!= enabled
,
13943 "encoder's enabled state mismatch "
13944 "(expected %i, found %i)\n",
13945 !!encoder
->base
.crtc
, enabled
);
13947 if (!encoder
->base
.crtc
) {
13950 active
= encoder
->get_hw_state(encoder
, &pipe
);
13951 I915_STATE_WARN(active
,
13952 "encoder detached but still enabled on pipe %c.\n",
13959 verify_crtc_state(struct intel_crtc
*crtc
,
13960 struct intel_crtc_state
*old_crtc_state
,
13961 struct intel_crtc_state
*new_crtc_state
)
13963 struct drm_device
*dev
= crtc
->base
.dev
;
13964 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13965 struct intel_encoder
*encoder
;
13966 struct intel_crtc_state
*pipe_config
= old_crtc_state
;
13967 struct drm_atomic_state
*state
= old_crtc_state
->uapi
.state
;
13970 __drm_atomic_helper_crtc_destroy_state(&old_crtc_state
->uapi
);
13971 intel_crtc_free_hw_state(old_crtc_state
);
13972 intel_crtc_state_reset(old_crtc_state
, crtc
);
13973 old_crtc_state
->uapi
.state
= state
;
13975 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc
->base
.base
.id
, crtc
->base
.name
);
13977 active
= dev_priv
->display
.get_pipe_config(crtc
, pipe_config
);
13979 /* we keep both pipes enabled on 830 */
13980 if (IS_I830(dev_priv
))
13981 active
= new_crtc_state
->hw
.active
;
13983 I915_STATE_WARN(new_crtc_state
->hw
.active
!= active
,
13984 "crtc active state doesn't match with hw state "
13985 "(expected %i, found %i)\n",
13986 new_crtc_state
->hw
.active
, active
);
13988 I915_STATE_WARN(crtc
->active
!= new_crtc_state
->hw
.active
,
13989 "transitional active state does not match atomic hw state "
13990 "(expected %i, found %i)\n",
13991 new_crtc_state
->hw
.active
, crtc
->active
);
13993 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
13996 active
= encoder
->get_hw_state(encoder
, &pipe
);
13997 I915_STATE_WARN(active
!= new_crtc_state
->hw
.active
,
13998 "[ENCODER:%i] active %i with crtc active %i\n",
13999 encoder
->base
.base
.id
, active
,
14000 new_crtc_state
->hw
.active
);
14002 I915_STATE_WARN(active
&& crtc
->pipe
!= pipe
,
14003 "Encoder connected to wrong pipe %c\n",
14007 encoder
->get_config(encoder
, pipe_config
);
14010 intel_crtc_compute_pixel_rate(pipe_config
);
14012 if (!new_crtc_state
->hw
.active
)
14015 intel_pipe_config_sanity_check(dev_priv
, pipe_config
);
14017 if (!intel_pipe_config_compare(new_crtc_state
,
14018 pipe_config
, false)) {
14019 I915_STATE_WARN(1, "pipe state doesn't match!\n");
14020 intel_dump_pipe_config(pipe_config
, NULL
, "[hw state]");
14021 intel_dump_pipe_config(new_crtc_state
, NULL
, "[sw state]");
14026 intel_verify_planes(struct intel_atomic_state
*state
)
14028 struct intel_plane
*plane
;
14029 const struct intel_plane_state
*plane_state
;
14032 for_each_new_intel_plane_in_state(state
, plane
,
14034 assert_plane(plane
, plane_state
->planar_slave
||
14035 plane_state
->uapi
.visible
);
14039 verify_single_dpll_state(struct drm_i915_private
*dev_priv
,
14040 struct intel_shared_dpll
*pll
,
14041 struct intel_crtc
*crtc
,
14042 struct intel_crtc_state
*new_crtc_state
)
14044 struct intel_dpll_hw_state dpll_hw_state
;
14045 unsigned int crtc_mask
;
14048 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
14050 DRM_DEBUG_KMS("%s\n", pll
->info
->name
);
14052 active
= pll
->info
->funcs
->get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
14054 if (!(pll
->info
->flags
& INTEL_DPLL_ALWAYS_ON
)) {
14055 I915_STATE_WARN(!pll
->on
&& pll
->active_mask
,
14056 "pll in active use but not on in sw tracking\n");
14057 I915_STATE_WARN(pll
->on
&& !pll
->active_mask
,
14058 "pll is on but not used by any active crtc\n");
14059 I915_STATE_WARN(pll
->on
!= active
,
14060 "pll on state mismatch (expected %i, found %i)\n",
14065 I915_STATE_WARN(pll
->active_mask
& ~pll
->state
.crtc_mask
,
14066 "more active pll users than references: %x vs %x\n",
14067 pll
->active_mask
, pll
->state
.crtc_mask
);
14072 crtc_mask
= drm_crtc_mask(&crtc
->base
);
14074 if (new_crtc_state
->hw
.active
)
14075 I915_STATE_WARN(!(pll
->active_mask
& crtc_mask
),
14076 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
14077 pipe_name(drm_crtc_index(&crtc
->base
)), pll
->active_mask
);
14079 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
14080 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
14081 pipe_name(drm_crtc_index(&crtc
->base
)), pll
->active_mask
);
14083 I915_STATE_WARN(!(pll
->state
.crtc_mask
& crtc_mask
),
14084 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
14085 crtc_mask
, pll
->state
.crtc_mask
);
14087 I915_STATE_WARN(pll
->on
&& memcmp(&pll
->state
.hw_state
,
14089 sizeof(dpll_hw_state
)),
14090 "pll hw state mismatch\n");
14094 verify_shared_dpll_state(struct intel_crtc
*crtc
,
14095 struct intel_crtc_state
*old_crtc_state
,
14096 struct intel_crtc_state
*new_crtc_state
)
14098 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
14100 if (new_crtc_state
->shared_dpll
)
14101 verify_single_dpll_state(dev_priv
, new_crtc_state
->shared_dpll
, crtc
, new_crtc_state
);
14103 if (old_crtc_state
->shared_dpll
&&
14104 old_crtc_state
->shared_dpll
!= new_crtc_state
->shared_dpll
) {
14105 unsigned int crtc_mask
= drm_crtc_mask(&crtc
->base
);
14106 struct intel_shared_dpll
*pll
= old_crtc_state
->shared_dpll
;
14108 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
14109 "pll active mismatch (didn't expect pipe %c in active mask)\n",
14110 pipe_name(drm_crtc_index(&crtc
->base
)));
14111 I915_STATE_WARN(pll
->state
.crtc_mask
& crtc_mask
,
14112 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
14113 pipe_name(drm_crtc_index(&crtc
->base
)));
14118 intel_modeset_verify_crtc(struct intel_crtc
*crtc
,
14119 struct intel_atomic_state
*state
,
14120 struct intel_crtc_state
*old_crtc_state
,
14121 struct intel_crtc_state
*new_crtc_state
)
14123 if (!needs_modeset(new_crtc_state
) && !new_crtc_state
->update_pipe
)
14126 verify_wm_state(crtc
, new_crtc_state
);
14127 verify_connector_state(state
, crtc
);
14128 verify_crtc_state(crtc
, old_crtc_state
, new_crtc_state
);
14129 verify_shared_dpll_state(crtc
, old_crtc_state
, new_crtc_state
);
14133 verify_disabled_dpll_state(struct drm_i915_private
*dev_priv
)
14137 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++)
14138 verify_single_dpll_state(dev_priv
, &dev_priv
->shared_dplls
[i
], NULL
, NULL
);
14142 intel_modeset_verify_disabled(struct drm_i915_private
*dev_priv
,
14143 struct intel_atomic_state
*state
)
14145 verify_encoder_state(dev_priv
, state
);
14146 verify_connector_state(state
, NULL
);
14147 verify_disabled_dpll_state(dev_priv
);
14151 intel_crtc_update_active_timings(const struct intel_crtc_state
*crtc_state
)
14153 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
14154 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
14155 const struct drm_display_mode
*adjusted_mode
=
14156 &crtc_state
->hw
.adjusted_mode
;
14158 drm_calc_timestamping_constants(&crtc
->base
, adjusted_mode
);
14161 * The scanline counter increments at the leading edge of hsync.
14163 * On most platforms it starts counting from vtotal-1 on the
14164 * first active line. That means the scanline counter value is
14165 * always one less than what we would expect. Ie. just after
14166 * start of vblank, which also occurs at start of hsync (on the
14167 * last active line), the scanline counter will read vblank_start-1.
14169 * On gen2 the scanline counter starts counting from 1 instead
14170 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
14171 * to keep the value positive), instead of adding one.
14173 * On HSW+ the behaviour of the scanline counter depends on the output
14174 * type. For DP ports it behaves like most other platforms, but on HDMI
14175 * there's an extra 1 line difference. So we need to add two instead of
14176 * one to the value.
14178 * On VLV/CHV DSI the scanline counter would appear to increment
14179 * approx. 1/3 of a scanline before start of vblank. Unfortunately
14180 * that means we can't tell whether we're in vblank or not while
14181 * we're on that particular line. We must still set scanline_offset
14182 * to 1 so that the vblank timestamps come out correct when we query
14183 * the scanline counter from within the vblank interrupt handler.
14184 * However if queried just before the start of vblank we'll get an
14185 * answer that's slightly in the future.
14187 if (IS_GEN(dev_priv
, 2)) {
14190 vtotal
= adjusted_mode
->crtc_vtotal
;
14191 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
14194 crtc
->scanline_offset
= vtotal
- 1;
14195 } else if (HAS_DDI(dev_priv
) &&
14196 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
)) {
14197 crtc
->scanline_offset
= 2;
14199 crtc
->scanline_offset
= 1;
14203 static void intel_modeset_clear_plls(struct intel_atomic_state
*state
)
14205 struct drm_i915_private
*dev_priv
= to_i915(state
->base
.dev
);
14206 struct intel_crtc_state
*new_crtc_state
;
14207 struct intel_crtc
*crtc
;
14210 if (!dev_priv
->display
.crtc_compute_clock
)
14213 for_each_new_intel_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
14214 if (!needs_modeset(new_crtc_state
))
14217 intel_release_shared_dplls(state
, crtc
);
14222 * This implements the workaround described in the "notes" section of the mode
14223 * set sequence documentation. When going from no pipes or single pipe to
14224 * multiple pipes, and planes are enabled after the pipe, we need to wait at
14225 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
14227 static int hsw_mode_set_planes_workaround(struct intel_atomic_state
*state
)
14229 struct intel_crtc_state
*crtc_state
;
14230 struct intel_crtc
*crtc
;
14231 struct intel_crtc_state
*first_crtc_state
= NULL
;
14232 struct intel_crtc_state
*other_crtc_state
= NULL
;
14233 enum pipe first_pipe
= INVALID_PIPE
, enabled_pipe
= INVALID_PIPE
;
14236 /* look at all crtc's that are going to be enabled in during modeset */
14237 for_each_new_intel_crtc_in_state(state
, crtc
, crtc_state
, i
) {
14238 if (!crtc_state
->hw
.active
||
14239 !needs_modeset(crtc_state
))
14242 if (first_crtc_state
) {
14243 other_crtc_state
= crtc_state
;
14246 first_crtc_state
= crtc_state
;
14247 first_pipe
= crtc
->pipe
;
14251 /* No workaround needed? */
14252 if (!first_crtc_state
)
14255 /* w/a possibly needed, check how many crtc's are already enabled. */
14256 for_each_intel_crtc(state
->base
.dev
, crtc
) {
14257 crtc_state
= intel_atomic_get_crtc_state(&state
->base
, crtc
);
14258 if (IS_ERR(crtc_state
))
14259 return PTR_ERR(crtc_state
);
14261 crtc_state
->hsw_workaround_pipe
= INVALID_PIPE
;
14263 if (!crtc_state
->hw
.active
||
14264 needs_modeset(crtc_state
))
14267 /* 2 or more enabled crtcs means no need for w/a */
14268 if (enabled_pipe
!= INVALID_PIPE
)
14271 enabled_pipe
= crtc
->pipe
;
14274 if (enabled_pipe
!= INVALID_PIPE
)
14275 first_crtc_state
->hsw_workaround_pipe
= enabled_pipe
;
14276 else if (other_crtc_state
)
14277 other_crtc_state
->hsw_workaround_pipe
= first_pipe
;
14282 static int intel_modeset_checks(struct intel_atomic_state
*state
)
14284 struct drm_i915_private
*dev_priv
= to_i915(state
->base
.dev
);
14285 struct intel_crtc_state
*old_crtc_state
, *new_crtc_state
;
14286 struct intel_crtc
*crtc
;
14289 /* keep the current setting */
14290 if (!state
->cdclk
.force_min_cdclk_changed
)
14291 state
->cdclk
.force_min_cdclk
= dev_priv
->cdclk
.force_min_cdclk
;
14293 state
->modeset
= true;
14294 state
->active_pipes
= dev_priv
->active_pipes
;
14295 state
->cdclk
.logical
= dev_priv
->cdclk
.logical
;
14296 state
->cdclk
.actual
= dev_priv
->cdclk
.actual
;
14298 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
,
14299 new_crtc_state
, i
) {
14300 if (new_crtc_state
->hw
.active
)
14301 state
->active_pipes
|= BIT(crtc
->pipe
);
14303 state
->active_pipes
&= ~BIT(crtc
->pipe
);
14305 if (old_crtc_state
->hw
.active
!= new_crtc_state
->hw
.active
)
14306 state
->active_pipe_changes
|= BIT(crtc
->pipe
);
14309 if (state
->active_pipe_changes
) {
14310 ret
= intel_atomic_lock_global_state(state
);
14315 ret
= intel_modeset_calc_cdclk(state
);
14319 intel_modeset_clear_plls(state
);
14321 if (IS_HASWELL(dev_priv
))
14322 return hsw_mode_set_planes_workaround(state
);
14328 * Handle calculation of various watermark data at the end of the atomic check
14329 * phase. The code here should be run after the per-crtc and per-plane 'check'
14330 * handlers to ensure that all derived state has been updated.
14332 static int calc_watermark_data(struct intel_atomic_state
*state
)
14334 struct drm_device
*dev
= state
->base
.dev
;
14335 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14337 /* Is there platform-specific watermark information to calculate? */
14338 if (dev_priv
->display
.compute_global_watermarks
)
14339 return dev_priv
->display
.compute_global_watermarks(state
);
14344 static void intel_crtc_check_fastset(const struct intel_crtc_state
*old_crtc_state
,
14345 struct intel_crtc_state
*new_crtc_state
)
14347 if (!intel_pipe_config_compare(old_crtc_state
, new_crtc_state
, true))
14350 new_crtc_state
->uapi
.mode_changed
= false;
14351 new_crtc_state
->update_pipe
= true;
14354 static void intel_crtc_copy_fastset(const struct intel_crtc_state
*old_crtc_state
,
14355 struct intel_crtc_state
*new_crtc_state
)
14358 * If we're not doing the full modeset we want to
14359 * keep the current M/N values as they may be
14360 * sufficiently different to the computed values
14361 * to cause problems.
14363 * FIXME: should really copy more fuzzy state here
14365 new_crtc_state
->fdi_m_n
= old_crtc_state
->fdi_m_n
;
14366 new_crtc_state
->dp_m_n
= old_crtc_state
->dp_m_n
;
14367 new_crtc_state
->dp_m2_n2
= old_crtc_state
->dp_m2_n2
;
14368 new_crtc_state
->has_drrs
= old_crtc_state
->has_drrs
;
14371 static int intel_crtc_add_planes_to_state(struct intel_atomic_state
*state
,
14372 struct intel_crtc
*crtc
,
14375 struct drm_i915_private
*dev_priv
= to_i915(state
->base
.dev
);
14376 struct intel_plane
*plane
;
14378 for_each_intel_plane_on_crtc(&dev_priv
->drm
, crtc
, plane
) {
14379 struct intel_plane_state
*plane_state
;
14381 if ((plane_ids_mask
& BIT(plane
->id
)) == 0)
14384 plane_state
= intel_atomic_get_plane_state(state
, plane
);
14385 if (IS_ERR(plane_state
))
14386 return PTR_ERR(plane_state
);
14392 static bool active_planes_affects_min_cdclk(struct drm_i915_private
*dev_priv
)
14394 /* See {hsw,vlv,ivb}_plane_ratio() */
14395 return IS_BROADWELL(dev_priv
) || IS_HASWELL(dev_priv
) ||
14396 IS_CHERRYVIEW(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
14397 IS_IVYBRIDGE(dev_priv
);
14400 static int intel_atomic_check_planes(struct intel_atomic_state
*state
,
14401 bool *need_modeset
)
14403 struct drm_i915_private
*dev_priv
= to_i915(state
->base
.dev
);
14404 struct intel_crtc_state
*old_crtc_state
, *new_crtc_state
;
14405 struct intel_plane_state
*plane_state
;
14406 struct intel_plane
*plane
;
14407 struct intel_crtc
*crtc
;
14410 ret
= icl_add_linked_planes(state
);
14414 for_each_new_intel_plane_in_state(state
, plane
, plane_state
, i
) {
14415 ret
= intel_plane_atomic_check(state
, plane
);
14417 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] atomic driver check failed\n",
14418 plane
->base
.base
.id
, plane
->base
.name
);
14423 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
,
14424 new_crtc_state
, i
) {
14425 u8 old_active_planes
, new_active_planes
;
14427 ret
= icl_check_nv12_planes(new_crtc_state
);
14432 * On some platforms the number of active planes affects
14433 * the planes' minimum cdclk calculation. Add such planes
14434 * to the state before we compute the minimum cdclk.
14436 if (!active_planes_affects_min_cdclk(dev_priv
))
14439 old_active_planes
= old_crtc_state
->active_planes
& ~BIT(PLANE_CURSOR
);
14440 new_active_planes
= new_crtc_state
->active_planes
& ~BIT(PLANE_CURSOR
);
14442 if (hweight8(old_active_planes
) == hweight8(new_active_planes
))
14445 ret
= intel_crtc_add_planes_to_state(state
, crtc
, new_active_planes
);
14451 * active_planes bitmask has been updated, and potentially
14452 * affected planes are part of the state. We can now
14453 * compute the minimum cdclk for each plane.
14455 for_each_new_intel_plane_in_state(state
, plane
, plane_state
, i
)
14456 *need_modeset
|= intel_plane_calc_min_cdclk(state
, plane
);
14461 static int intel_atomic_check_crtcs(struct intel_atomic_state
*state
)
14463 struct intel_crtc_state
*crtc_state
;
14464 struct intel_crtc
*crtc
;
14467 for_each_new_intel_crtc_in_state(state
, crtc
, crtc_state
, i
) {
14468 int ret
= intel_crtc_atomic_check(state
, crtc
);
14470 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] atomic driver check failed\n",
14471 crtc
->base
.base
.id
, crtc
->base
.name
);
14479 static bool intel_cpu_transcoder_needs_modeset(struct intel_atomic_state
*state
,
14480 enum transcoder transcoder
)
14482 struct intel_crtc_state
*new_crtc_state
;
14483 struct intel_crtc
*crtc
;
14486 for_each_new_intel_crtc_in_state(state
, crtc
, new_crtc_state
, i
)
14487 if (new_crtc_state
->cpu_transcoder
== transcoder
)
14488 return needs_modeset(new_crtc_state
);
14494 intel_modeset_synced_crtcs(struct intel_atomic_state
*state
,
14497 struct intel_crtc_state
*new_crtc_state
;
14498 struct intel_crtc
*crtc
;
14501 for_each_new_intel_crtc_in_state(state
, crtc
,
14502 new_crtc_state
, i
) {
14503 if (transcoders
& BIT(new_crtc_state
->cpu_transcoder
)) {
14504 new_crtc_state
->uapi
.mode_changed
= true;
14505 new_crtc_state
->update_pipe
= false;
14511 intel_modeset_all_tiles(struct intel_atomic_state
*state
, int tile_grp_id
)
14513 struct drm_i915_private
*dev_priv
= to_i915(state
->base
.dev
);
14514 struct drm_connector
*connector
;
14515 struct drm_connector_list_iter conn_iter
;
14518 drm_connector_list_iter_begin(&dev_priv
->drm
, &conn_iter
);
14519 drm_for_each_connector_iter(connector
, &conn_iter
) {
14520 struct drm_connector_state
*conn_state
;
14521 struct drm_crtc_state
*crtc_state
;
14523 if (!connector
->has_tile
||
14524 connector
->tile_group
->id
!= tile_grp_id
)
14526 conn_state
= drm_atomic_get_connector_state(&state
->base
,
14528 if (IS_ERR(conn_state
)) {
14529 ret
= PTR_ERR(conn_state
);
14533 if (!conn_state
->crtc
)
14536 crtc_state
= drm_atomic_get_crtc_state(&state
->base
,
14538 if (IS_ERR(crtc_state
)) {
14539 ret
= PTR_ERR(crtc_state
);
14542 crtc_state
->mode_changed
= true;
14543 ret
= drm_atomic_add_affected_connectors(&state
->base
,
14548 drm_connector_list_iter_end(&conn_iter
);
14554 intel_atomic_check_tiled_conns(struct intel_atomic_state
*state
)
14556 struct drm_i915_private
*dev_priv
= to_i915(state
->base
.dev
);
14557 struct drm_connector
*connector
;
14558 struct drm_connector_state
*old_conn_state
, *new_conn_state
;
14561 if (INTEL_GEN(dev_priv
) < 11)
14564 /* Is tiled, mark all other tiled CRTCs as needing a modeset */
14565 for_each_oldnew_connector_in_state(&state
->base
, connector
,
14566 old_conn_state
, new_conn_state
, i
) {
14567 if (!connector
->has_tile
)
14569 if (!intel_connector_needs_modeset(state
, connector
))
14572 ret
= intel_modeset_all_tiles(state
, connector
->tile_group
->id
);
14581 * intel_atomic_check - validate state object
14583 * @_state: state to validate
14585 static int intel_atomic_check(struct drm_device
*dev
,
14586 struct drm_atomic_state
*_state
)
14588 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14589 struct intel_atomic_state
*state
= to_intel_atomic_state(_state
);
14590 struct intel_crtc_state
*old_crtc_state
, *new_crtc_state
;
14591 struct intel_crtc
*crtc
;
14593 bool any_ms
= false;
14595 /* Catch I915_MODE_FLAG_INHERITED */
14596 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
,
14597 new_crtc_state
, i
) {
14598 if (new_crtc_state
->hw
.mode
.private_flags
!=
14599 old_crtc_state
->hw
.mode
.private_flags
)
14600 new_crtc_state
->uapi
.mode_changed
= true;
14603 ret
= drm_atomic_helper_check_modeset(dev
, &state
->base
);
14608 * This check adds all the connectors in current state that belong to
14609 * the same tile group to a full modeset.
14610 * This function directly sets the mode_changed to true and we also call
14611 * drm_atomic_add_affected_connectors(). Hence we are not explicitly
14612 * calling drm_atomic_helper_check_modeset() after this.
14614 * Fixme: Handle some corner cases where one of the
14615 * tiled connectors gets disconnected and tile info is lost but since it
14616 * was previously synced to other conn, we need to add that to the modeset.
14618 ret
= intel_atomic_check_tiled_conns(state
);
14622 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
,
14623 new_crtc_state
, i
) {
14624 if (!needs_modeset(new_crtc_state
)) {
14626 intel_crtc_copy_uapi_to_hw_state_nomodeset(new_crtc_state
);
14631 if (!new_crtc_state
->uapi
.enable
) {
14632 intel_crtc_copy_uapi_to_hw_state(new_crtc_state
);
14636 ret
= intel_crtc_prepare_cleared_state(new_crtc_state
);
14640 ret
= intel_modeset_pipe_config(new_crtc_state
);
14644 intel_crtc_check_fastset(old_crtc_state
, new_crtc_state
);
14648 * Check if fastset is allowed by external dependencies like other
14649 * pipes and transcoders.
14651 * Right now it only forces a fullmodeset when the MST master
14652 * transcoder did not changed but the pipe of the master transcoder
14653 * needs a fullmodeset so all slaves also needs to do a fullmodeset or
14654 * in case of port synced crtcs, if one of the synced crtcs
14655 * needs a full modeset, all other synced crtcs should be
14656 * forced a full modeset.
14658 for_each_new_intel_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
14659 if (!new_crtc_state
->hw
.enable
|| needs_modeset(new_crtc_state
))
14662 if (intel_dp_mst_is_slave_trans(new_crtc_state
)) {
14663 enum transcoder master
= new_crtc_state
->mst_master_transcoder
;
14665 if (intel_cpu_transcoder_needs_modeset(state
, master
)) {
14666 new_crtc_state
->uapi
.mode_changed
= true;
14667 new_crtc_state
->update_pipe
= false;
14669 } else if (is_trans_port_sync_mode(new_crtc_state
)) {
14670 u8 trans
= new_crtc_state
->sync_mode_slaves_mask
|
14671 BIT(new_crtc_state
->master_transcoder
);
14673 intel_modeset_synced_crtcs(state
, trans
);
14677 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
,
14678 new_crtc_state
, i
) {
14679 if (needs_modeset(new_crtc_state
)) {
14684 if (!new_crtc_state
->update_pipe
)
14687 intel_crtc_copy_fastset(old_crtc_state
, new_crtc_state
);
14690 if (any_ms
&& !check_digital_port_conflicts(state
)) {
14691 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
14696 ret
= drm_dp_mst_atomic_check(&state
->base
);
14700 any_ms
|= state
->cdclk
.force_min_cdclk_changed
;
14702 ret
= intel_atomic_check_planes(state
, &any_ms
);
14707 ret
= intel_modeset_checks(state
);
14711 state
->cdclk
.logical
= dev_priv
->cdclk
.logical
;
14714 ret
= intel_atomic_check_crtcs(state
);
14718 intel_fbc_choose_crtc(dev_priv
, state
);
14719 ret
= calc_watermark_data(state
);
14723 ret
= intel_bw_atomic_check(state
);
14727 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
,
14728 new_crtc_state
, i
) {
14729 if (!needs_modeset(new_crtc_state
) &&
14730 !new_crtc_state
->update_pipe
)
14733 intel_dump_pipe_config(new_crtc_state
, state
,
14734 needs_modeset(new_crtc_state
) ?
14735 "[modeset]" : "[fastset]");
14741 if (ret
== -EDEADLK
)
14745 * FIXME would probably be nice to know which crtc specifically
14746 * caused the failure, in cases where we can pinpoint it.
14748 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
,
14750 intel_dump_pipe_config(new_crtc_state
, state
, "[failed]");
14755 static int intel_atomic_prepare_commit(struct intel_atomic_state
*state
)
14757 return drm_atomic_helper_prepare_planes(state
->base
.dev
,
14761 u32
intel_crtc_get_vblank_counter(struct intel_crtc
*crtc
)
14763 struct drm_device
*dev
= crtc
->base
.dev
;
14764 struct drm_vblank_crtc
*vblank
= &dev
->vblank
[drm_crtc_index(&crtc
->base
)];
14766 if (!vblank
->max_vblank_count
)
14767 return (u32
)drm_crtc_accurate_vblank_count(&crtc
->base
);
14769 return crtc
->base
.funcs
->get_vblank_counter(&crtc
->base
);
14772 void intel_crtc_arm_fifo_underrun(struct intel_crtc
*crtc
,
14773 struct intel_crtc_state
*crtc_state
)
14775 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
14777 if (!IS_GEN(dev_priv
, 2) || crtc_state
->active_planes
)
14778 intel_set_cpu_fifo_underrun_reporting(dev_priv
, crtc
->pipe
, true);
14780 if (crtc_state
->has_pch_encoder
) {
14781 enum pipe pch_transcoder
=
14782 intel_crtc_pch_transcoder(crtc
);
14784 intel_set_pch_fifo_underrun_reporting(dev_priv
, pch_transcoder
, true);
14788 static void intel_pipe_fastset(const struct intel_crtc_state
*old_crtc_state
,
14789 const struct intel_crtc_state
*new_crtc_state
)
14791 struct intel_crtc
*crtc
= to_intel_crtc(new_crtc_state
->uapi
.crtc
);
14792 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
14795 * Update pipe size and adjust fitter if needed: the reason for this is
14796 * that in compute_mode_changes we check the native mode (not the pfit
14797 * mode) to see if we can flip rather than do a full mode set. In the
14798 * fastboot case, we'll flip, but if we don't update the pipesrc and
14799 * pfit state, we'll end up with a big fb scanned out into the wrong
14802 intel_set_pipe_src_size(new_crtc_state
);
14804 /* on skylake this is done by detaching scalers */
14805 if (INTEL_GEN(dev_priv
) >= 9) {
14806 skl_detach_scalers(new_crtc_state
);
14808 if (new_crtc_state
->pch_pfit
.enabled
)
14809 skl_pfit_enable(new_crtc_state
);
14810 } else if (HAS_PCH_SPLIT(dev_priv
)) {
14811 if (new_crtc_state
->pch_pfit
.enabled
)
14812 ilk_pfit_enable(new_crtc_state
);
14813 else if (old_crtc_state
->pch_pfit
.enabled
)
14814 ilk_pfit_disable(old_crtc_state
);
14817 if (INTEL_GEN(dev_priv
) >= 11)
14818 icl_set_pipe_chicken(crtc
);
14821 static void commit_pipe_config(struct intel_atomic_state
*state
,
14822 struct intel_crtc_state
*old_crtc_state
,
14823 struct intel_crtc_state
*new_crtc_state
)
14825 struct intel_crtc
*crtc
= to_intel_crtc(new_crtc_state
->uapi
.crtc
);
14826 struct drm_i915_private
*dev_priv
= to_i915(state
->base
.dev
);
14827 bool modeset
= needs_modeset(new_crtc_state
);
14830 * During modesets pipe configuration was programmed as the
14831 * CRTC was enabled.
14834 if (new_crtc_state
->uapi
.color_mgmt_changed
||
14835 new_crtc_state
->update_pipe
)
14836 intel_color_commit(new_crtc_state
);
14838 if (INTEL_GEN(dev_priv
) >= 9)
14839 skl_detach_scalers(new_crtc_state
);
14841 if (INTEL_GEN(dev_priv
) >= 9 || IS_BROADWELL(dev_priv
))
14842 bdw_set_pipemisc(new_crtc_state
);
14844 if (new_crtc_state
->update_pipe
)
14845 intel_pipe_fastset(old_crtc_state
, new_crtc_state
);
14848 if (dev_priv
->display
.atomic_update_watermarks
)
14849 dev_priv
->display
.atomic_update_watermarks(state
, crtc
);
14852 static void intel_update_crtc(struct intel_crtc
*crtc
,
14853 struct intel_atomic_state
*state
,
14854 struct intel_crtc_state
*old_crtc_state
,
14855 struct intel_crtc_state
*new_crtc_state
)
14857 struct drm_i915_private
*dev_priv
= to_i915(state
->base
.dev
);
14858 bool modeset
= needs_modeset(new_crtc_state
);
14859 struct intel_plane_state
*new_plane_state
=
14860 intel_atomic_get_new_plane_state(state
,
14861 to_intel_plane(crtc
->base
.primary
));
14864 intel_crtc_update_active_timings(new_crtc_state
);
14866 dev_priv
->display
.crtc_enable(state
, crtc
);
14868 /* vblanks work again, re-enable pipe CRC. */
14869 intel_crtc_enable_pipe_crc(crtc
);
14871 if (new_crtc_state
->preload_luts
&&
14872 (new_crtc_state
->uapi
.color_mgmt_changed
||
14873 new_crtc_state
->update_pipe
))
14874 intel_color_load_luts(new_crtc_state
);
14876 intel_pre_plane_update(state
, crtc
);
14878 if (new_crtc_state
->update_pipe
)
14879 intel_encoders_update_pipe(state
, crtc
);
14882 if (new_crtc_state
->update_pipe
&& !new_crtc_state
->enable_fbc
)
14883 intel_fbc_disable(crtc
);
14884 else if (new_plane_state
)
14885 intel_fbc_enable(crtc
, new_crtc_state
, new_plane_state
);
14887 /* Perform vblank evasion around commit operation */
14888 intel_pipe_update_start(new_crtc_state
);
14890 commit_pipe_config(state
, old_crtc_state
, new_crtc_state
);
14892 if (INTEL_GEN(dev_priv
) >= 9)
14893 skl_update_planes_on_crtc(state
, crtc
);
14895 i9xx_update_planes_on_crtc(state
, crtc
);
14897 intel_pipe_update_end(new_crtc_state
);
14900 * We usually enable FIFO underrun interrupts as part of the
14901 * CRTC enable sequence during modesets. But when we inherit a
14902 * valid pipe configuration from the BIOS we need to take care
14903 * of enabling them on the CRTC's first fastset.
14905 if (new_crtc_state
->update_pipe
&& !modeset
&&
14906 old_crtc_state
->hw
.mode
.private_flags
& I915_MODE_FLAG_INHERITED
)
14907 intel_crtc_arm_fifo_underrun(crtc
, new_crtc_state
);
14910 static struct intel_crtc
*intel_get_slave_crtc(const struct intel_crtc_state
*new_crtc_state
)
14912 struct drm_i915_private
*dev_priv
= to_i915(new_crtc_state
->uapi
.crtc
->dev
);
14913 enum transcoder slave_transcoder
;
14915 WARN_ON(!is_power_of_2(new_crtc_state
->sync_mode_slaves_mask
));
14917 slave_transcoder
= ffs(new_crtc_state
->sync_mode_slaves_mask
) - 1;
14918 return intel_get_crtc_for_pipe(dev_priv
,
14919 (enum pipe
)slave_transcoder
);
14922 static void intel_old_crtc_state_disables(struct intel_atomic_state
*state
,
14923 struct intel_crtc_state
*old_crtc_state
,
14924 struct intel_crtc_state
*new_crtc_state
,
14925 struct intel_crtc
*crtc
)
14927 struct drm_i915_private
*dev_priv
= to_i915(state
->base
.dev
);
14929 intel_crtc_disable_planes(state
, crtc
);
14932 * We need to disable pipe CRC before disabling the pipe,
14933 * or we race against vblank off.
14935 intel_crtc_disable_pipe_crc(crtc
);
14937 dev_priv
->display
.crtc_disable(state
, crtc
);
14938 crtc
->active
= false;
14939 intel_fbc_disable(crtc
);
14940 intel_disable_shared_dpll(old_crtc_state
);
14942 /* FIXME unify this for all platforms */
14943 if (!new_crtc_state
->hw
.active
&&
14944 !HAS_GMCH(dev_priv
) &&
14945 dev_priv
->display
.initial_watermarks
)
14946 dev_priv
->display
.initial_watermarks(state
, crtc
);
14949 static void intel_commit_modeset_disables(struct intel_atomic_state
*state
)
14951 struct intel_crtc_state
*new_crtc_state
, *old_crtc_state
;
14952 struct intel_crtc
*crtc
;
14956 /* Only disable port sync and MST slaves */
14957 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
,
14958 new_crtc_state
, i
) {
14959 if (!needs_modeset(new_crtc_state
))
14962 if (!old_crtc_state
->hw
.active
)
14965 /* In case of Transcoder port Sync master slave CRTCs can be
14966 * assigned in any order and we need to make sure that
14967 * slave CRTCs are disabled first and then master CRTC since
14968 * Slave vblanks are masked till Master Vblanks.
14970 if (!is_trans_port_sync_slave(old_crtc_state
) &&
14971 !intel_dp_mst_is_slave_trans(old_crtc_state
))
14974 intel_pre_plane_update(state
, crtc
);
14975 intel_old_crtc_state_disables(state
, old_crtc_state
,
14976 new_crtc_state
, crtc
);
14977 handled
|= BIT(crtc
->pipe
);
14980 /* Disable everything else left on */
14981 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
,
14982 new_crtc_state
, i
) {
14983 if (!needs_modeset(new_crtc_state
) ||
14984 (handled
& BIT(crtc
->pipe
)))
14987 intel_pre_plane_update(state
, crtc
);
14988 if (old_crtc_state
->hw
.active
)
14989 intel_old_crtc_state_disables(state
, old_crtc_state
,
14990 new_crtc_state
, crtc
);
14994 static void intel_commit_modeset_enables(struct intel_atomic_state
*state
)
14996 struct intel_crtc
*crtc
;
14997 struct intel_crtc_state
*old_crtc_state
, *new_crtc_state
;
15000 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
15001 if (!new_crtc_state
->hw
.active
)
15004 intel_update_crtc(crtc
, state
, old_crtc_state
,
15009 static void intel_crtc_enable_trans_port_sync(struct intel_crtc
*crtc
,
15010 struct intel_atomic_state
*state
,
15011 struct intel_crtc_state
*new_crtc_state
)
15013 struct drm_i915_private
*dev_priv
= to_i915(state
->base
.dev
);
15015 intel_crtc_update_active_timings(new_crtc_state
);
15016 dev_priv
->display
.crtc_enable(state
, crtc
);
15017 intel_crtc_enable_pipe_crc(crtc
);
15020 static void intel_set_dp_tp_ctl_normal(struct intel_crtc
*crtc
,
15021 struct intel_atomic_state
*state
)
15023 struct drm_connector
*uninitialized_var(conn
);
15024 struct drm_connector_state
*conn_state
;
15025 struct intel_dp
*intel_dp
;
15028 for_each_new_connector_in_state(&state
->base
, conn
, conn_state
, i
) {
15029 if (conn_state
->crtc
== &crtc
->base
)
15032 intel_dp
= enc_to_intel_dp(intel_attached_encoder(to_intel_connector(conn
)));
15033 intel_dp_stop_link_train(intel_dp
);
15037 * TODO: This is only called from port sync and it is identical to what will be
15038 * executed again in intel_update_crtc() over port sync pipes
15040 static void intel_post_crtc_enable_updates(struct intel_crtc
*crtc
,
15041 struct intel_atomic_state
*state
)
15043 struct intel_crtc_state
*new_crtc_state
=
15044 intel_atomic_get_new_crtc_state(state
, crtc
);
15045 struct intel_crtc_state
*old_crtc_state
=
15046 intel_atomic_get_old_crtc_state(state
, crtc
);
15047 struct intel_plane_state
*new_plane_state
=
15048 intel_atomic_get_new_plane_state(state
,
15049 to_intel_plane(crtc
->base
.primary
));
15050 bool modeset
= needs_modeset(new_crtc_state
);
15052 if (new_crtc_state
->update_pipe
&& !new_crtc_state
->enable_fbc
)
15053 intel_fbc_disable(crtc
);
15054 else if (new_plane_state
)
15055 intel_fbc_enable(crtc
, new_crtc_state
, new_plane_state
);
15057 /* Perform vblank evasion around commit operation */
15058 intel_pipe_update_start(new_crtc_state
);
15059 commit_pipe_config(state
, old_crtc_state
, new_crtc_state
);
15060 skl_update_planes_on_crtc(state
, crtc
);
15061 intel_pipe_update_end(new_crtc_state
);
15064 * We usually enable FIFO underrun interrupts as part of the
15065 * CRTC enable sequence during modesets. But when we inherit a
15066 * valid pipe configuration from the BIOS we need to take care
15067 * of enabling them on the CRTC's first fastset.
15069 if (new_crtc_state
->update_pipe
&& !modeset
&&
15070 old_crtc_state
->hw
.mode
.private_flags
& I915_MODE_FLAG_INHERITED
)
15071 intel_crtc_arm_fifo_underrun(crtc
, new_crtc_state
);
15074 static void intel_update_trans_port_sync_crtcs(struct intel_crtc
*crtc
,
15075 struct intel_atomic_state
*state
,
15076 struct intel_crtc_state
*old_crtc_state
,
15077 struct intel_crtc_state
*new_crtc_state
)
15079 struct intel_crtc
*slave_crtc
= intel_get_slave_crtc(new_crtc_state
);
15080 struct intel_crtc_state
*new_slave_crtc_state
=
15081 intel_atomic_get_new_crtc_state(state
, slave_crtc
);
15082 struct intel_crtc_state
*old_slave_crtc_state
=
15083 intel_atomic_get_old_crtc_state(state
, slave_crtc
);
15085 WARN_ON(!slave_crtc
|| !new_slave_crtc_state
||
15086 !old_slave_crtc_state
);
15088 DRM_DEBUG_KMS("Updating Transcoder Port Sync Master CRTC = %d %s and Slave CRTC %d %s\n",
15089 crtc
->base
.base
.id
, crtc
->base
.name
, slave_crtc
->base
.base
.id
,
15090 slave_crtc
->base
.name
);
15092 /* Enable seq for slave with with DP_TP_CTL left Idle until the
15095 intel_crtc_enable_trans_port_sync(slave_crtc
,
15097 new_slave_crtc_state
);
15099 /* Enable seq for master with with DP_TP_CTL left Idle */
15100 intel_crtc_enable_trans_port_sync(crtc
,
15104 /* Set Slave's DP_TP_CTL to Normal */
15105 intel_set_dp_tp_ctl_normal(slave_crtc
,
15108 /* Set Master's DP_TP_CTL To Normal */
15109 usleep_range(200, 400);
15110 intel_set_dp_tp_ctl_normal(crtc
,
15113 /* Now do the post crtc enable for all master and slaves */
15114 intel_post_crtc_enable_updates(slave_crtc
,
15116 intel_post_crtc_enable_updates(crtc
,
15120 static void skl_commit_modeset_enables(struct intel_atomic_state
*state
)
15122 struct drm_i915_private
*dev_priv
= to_i915(state
->base
.dev
);
15123 struct intel_crtc
*crtc
;
15124 struct intel_crtc_state
*old_crtc_state
, *new_crtc_state
;
15125 u8 hw_enabled_slices
= dev_priv
->wm
.skl_hw
.ddb
.enabled_slices
;
15126 u8 required_slices
= state
->wm_results
.ddb
.enabled_slices
;
15127 struct skl_ddb_entry entries
[I915_MAX_PIPES
] = {};
15128 const u8 num_pipes
= INTEL_NUM_PIPES(dev_priv
);
15129 u8 update_pipes
= 0, modeset_pipes
= 0;
15132 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
15133 if (!new_crtc_state
->hw
.active
)
15136 /* ignore allocations for crtc's that have been turned off. */
15137 if (!needs_modeset(new_crtc_state
)) {
15138 entries
[i
] = old_crtc_state
->wm
.skl
.ddb
;
15139 update_pipes
|= BIT(crtc
->pipe
);
15141 modeset_pipes
|= BIT(crtc
->pipe
);
15145 /* If 2nd DBuf slice required, enable it here */
15146 if (INTEL_GEN(dev_priv
) >= 11 && required_slices
> hw_enabled_slices
)
15147 icl_dbuf_slices_update(dev_priv
, required_slices
);
15150 * Whenever the number of active pipes changes, we need to make sure we
15151 * update the pipes in the right order so that their ddb allocations
15152 * never overlap with each other between CRTC updates. Otherwise we'll
15153 * cause pipe underruns and other bad stuff.
15155 * So first lets enable all pipes that do not need a fullmodeset as
15156 * those don't have any external dependency.
15158 while (update_pipes
) {
15159 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
,
15160 new_crtc_state
, i
) {
15161 enum pipe pipe
= crtc
->pipe
;
15163 if ((update_pipes
& BIT(pipe
)) == 0)
15166 if (skl_ddb_allocation_overlaps(&new_crtc_state
->wm
.skl
.ddb
,
15167 entries
, num_pipes
, i
))
15170 entries
[i
] = new_crtc_state
->wm
.skl
.ddb
;
15171 update_pipes
&= ~BIT(pipe
);
15173 intel_update_crtc(crtc
, state
, old_crtc_state
,
15177 * If this is an already active pipe, it's DDB changed,
15178 * and this isn't the last pipe that needs updating
15179 * then we need to wait for a vblank to pass for the
15180 * new ddb allocation to take effect.
15182 if (!skl_ddb_entry_equal(&new_crtc_state
->wm
.skl
.ddb
,
15183 &old_crtc_state
->wm
.skl
.ddb
) &&
15184 (update_pipes
| modeset_pipes
))
15185 intel_wait_for_vblank(dev_priv
, pipe
);
15190 * Enable all pipes that needs a modeset and do not depends on other
15193 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
,
15194 new_crtc_state
, i
) {
15195 enum pipe pipe
= crtc
->pipe
;
15197 if ((modeset_pipes
& BIT(pipe
)) == 0)
15200 if (intel_dp_mst_is_slave_trans(new_crtc_state
) ||
15201 is_trans_port_sync_slave(new_crtc_state
))
15204 WARN_ON(skl_ddb_allocation_overlaps(&new_crtc_state
->wm
.skl
.ddb
,
15205 entries
, num_pipes
, i
));
15207 entries
[i
] = new_crtc_state
->wm
.skl
.ddb
;
15208 modeset_pipes
&= ~BIT(pipe
);
15210 if (is_trans_port_sync_mode(new_crtc_state
)) {
15211 struct intel_crtc
*slave_crtc
;
15213 intel_update_trans_port_sync_crtcs(crtc
, state
,
15217 slave_crtc
= intel_get_slave_crtc(new_crtc_state
);
15218 /* TODO: update entries[] of slave */
15219 modeset_pipes
&= ~BIT(slave_crtc
->pipe
);
15222 intel_update_crtc(crtc
, state
, old_crtc_state
,
15228 * Finally enable all pipes that needs a modeset and depends on
15229 * other pipes, right now it is only MST slaves as both port sync slave
15230 * and master are enabled together
15232 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
,
15233 new_crtc_state
, i
) {
15234 enum pipe pipe
= crtc
->pipe
;
15236 if ((modeset_pipes
& BIT(pipe
)) == 0)
15239 WARN_ON(skl_ddb_allocation_overlaps(&new_crtc_state
->wm
.skl
.ddb
,
15240 entries
, num_pipes
, i
));
15242 entries
[i
] = new_crtc_state
->wm
.skl
.ddb
;
15243 modeset_pipes
&= ~BIT(pipe
);
15245 intel_update_crtc(crtc
, state
, old_crtc_state
, new_crtc_state
);
15248 WARN_ON(modeset_pipes
);
15250 /* If 2nd DBuf slice is no more required disable it */
15251 if (INTEL_GEN(dev_priv
) >= 11 && required_slices
< hw_enabled_slices
)
15252 icl_dbuf_slices_update(dev_priv
, required_slices
);
15255 static void intel_atomic_helper_free_state(struct drm_i915_private
*dev_priv
)
15257 struct intel_atomic_state
*state
, *next
;
15258 struct llist_node
*freed
;
15260 freed
= llist_del_all(&dev_priv
->atomic_helper
.free_list
);
15261 llist_for_each_entry_safe(state
, next
, freed
, freed
)
15262 drm_atomic_state_put(&state
->base
);
15265 static void intel_atomic_helper_free_state_worker(struct work_struct
*work
)
15267 struct drm_i915_private
*dev_priv
=
15268 container_of(work
, typeof(*dev_priv
), atomic_helper
.free_work
);
15270 intel_atomic_helper_free_state(dev_priv
);
15273 static void intel_atomic_commit_fence_wait(struct intel_atomic_state
*intel_state
)
15275 struct wait_queue_entry wait_fence
, wait_reset
;
15276 struct drm_i915_private
*dev_priv
= to_i915(intel_state
->base
.dev
);
15278 init_wait_entry(&wait_fence
, 0);
15279 init_wait_entry(&wait_reset
, 0);
15281 prepare_to_wait(&intel_state
->commit_ready
.wait
,
15282 &wait_fence
, TASK_UNINTERRUPTIBLE
);
15283 prepare_to_wait(bit_waitqueue(&dev_priv
->gt
.reset
.flags
,
15284 I915_RESET_MODESET
),
15285 &wait_reset
, TASK_UNINTERRUPTIBLE
);
15288 if (i915_sw_fence_done(&intel_state
->commit_ready
) ||
15289 test_bit(I915_RESET_MODESET
, &dev_priv
->gt
.reset
.flags
))
15294 finish_wait(&intel_state
->commit_ready
.wait
, &wait_fence
);
15295 finish_wait(bit_waitqueue(&dev_priv
->gt
.reset
.flags
,
15296 I915_RESET_MODESET
),
15300 static void intel_atomic_cleanup_work(struct work_struct
*work
)
15302 struct drm_atomic_state
*state
=
15303 container_of(work
, struct drm_atomic_state
, commit_work
);
15304 struct drm_i915_private
*i915
= to_i915(state
->dev
);
15306 drm_atomic_helper_cleanup_planes(&i915
->drm
, state
);
15307 drm_atomic_helper_commit_cleanup_done(state
);
15308 drm_atomic_state_put(state
);
15310 intel_atomic_helper_free_state(i915
);
15313 static void intel_atomic_commit_tail(struct intel_atomic_state
*state
)
15315 struct drm_device
*dev
= state
->base
.dev
;
15316 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15317 struct intel_crtc_state
*new_crtc_state
, *old_crtc_state
;
15318 struct intel_crtc
*crtc
;
15319 u64 put_domains
[I915_MAX_PIPES
] = {};
15320 intel_wakeref_t wakeref
= 0;
15323 intel_atomic_commit_fence_wait(state
);
15325 drm_atomic_helper_wait_for_dependencies(&state
->base
);
15327 if (state
->modeset
)
15328 wakeref
= intel_display_power_get(dev_priv
, POWER_DOMAIN_MODESET
);
15330 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
,
15331 new_crtc_state
, i
) {
15332 if (needs_modeset(new_crtc_state
) ||
15333 new_crtc_state
->update_pipe
) {
15335 put_domains
[crtc
->pipe
] =
15336 modeset_get_crtc_power_domains(new_crtc_state
);
15340 intel_commit_modeset_disables(state
);
15342 /* FIXME: Eventually get rid of our crtc->config pointer */
15343 for_each_new_intel_crtc_in_state(state
, crtc
, new_crtc_state
, i
)
15344 crtc
->config
= new_crtc_state
;
15346 if (state
->modeset
) {
15347 drm_atomic_helper_update_legacy_modeset_state(dev
, &state
->base
);
15349 intel_set_cdclk_pre_plane_update(dev_priv
,
15350 &state
->cdclk
.actual
,
15351 &dev_priv
->cdclk
.actual
,
15352 state
->cdclk
.pipe
);
15355 * SKL workaround: bspec recommends we disable the SAGV when we
15356 * have more then one pipe enabled
15358 if (!intel_can_enable_sagv(state
))
15359 intel_disable_sagv(dev_priv
);
15361 intel_modeset_verify_disabled(dev_priv
, state
);
15364 /* Complete the events for pipes that have now been disabled */
15365 for_each_new_intel_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
15366 bool modeset
= needs_modeset(new_crtc_state
);
15368 /* Complete events for now disable pipes here. */
15369 if (modeset
&& !new_crtc_state
->hw
.active
&& new_crtc_state
->uapi
.event
) {
15370 spin_lock_irq(&dev
->event_lock
);
15371 drm_crtc_send_vblank_event(&crtc
->base
,
15372 new_crtc_state
->uapi
.event
);
15373 spin_unlock_irq(&dev
->event_lock
);
15375 new_crtc_state
->uapi
.event
= NULL
;
15379 if (state
->modeset
)
15380 intel_encoders_update_prepare(state
);
15382 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
15383 dev_priv
->display
.commit_modeset_enables(state
);
15385 if (state
->modeset
) {
15386 intel_encoders_update_complete(state
);
15388 intel_set_cdclk_post_plane_update(dev_priv
,
15389 &state
->cdclk
.actual
,
15390 &dev_priv
->cdclk
.actual
,
15391 state
->cdclk
.pipe
);
15394 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
15395 * already, but still need the state for the delayed optimization. To
15397 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
15398 * - schedule that vblank worker _before_ calling hw_done
15399 * - at the start of commit_tail, cancel it _synchrously
15400 * - switch over to the vblank wait helper in the core after that since
15401 * we don't need out special handling any more.
15403 drm_atomic_helper_wait_for_flip_done(dev
, &state
->base
);
15405 for_each_new_intel_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
15406 if (new_crtc_state
->hw
.active
&&
15407 !needs_modeset(new_crtc_state
) &&
15408 !new_crtc_state
->preload_luts
&&
15409 (new_crtc_state
->uapi
.color_mgmt_changed
||
15410 new_crtc_state
->update_pipe
))
15411 intel_color_load_luts(new_crtc_state
);
15415 * Now that the vblank has passed, we can go ahead and program the
15416 * optimal watermarks on platforms that need two-step watermark
15419 * TODO: Move this (and other cleanup) to an async worker eventually.
15421 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
,
15422 new_crtc_state
, i
) {
15424 * Gen2 reports pipe underruns whenever all planes are disabled.
15425 * So re-enable underrun reporting after some planes get enabled.
15427 * We do this before .optimize_watermarks() so that we have a
15428 * chance of catching underruns with the intermediate watermarks
15429 * vs. the new plane configuration.
15431 if (IS_GEN(dev_priv
, 2) && planes_enabling(old_crtc_state
, new_crtc_state
))
15432 intel_set_cpu_fifo_underrun_reporting(dev_priv
, crtc
->pipe
, true);
15434 if (dev_priv
->display
.optimize_watermarks
)
15435 dev_priv
->display
.optimize_watermarks(state
, crtc
);
15438 for_each_oldnew_intel_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
15439 intel_post_plane_update(state
, crtc
);
15441 if (put_domains
[i
])
15442 modeset_put_power_domains(dev_priv
, put_domains
[i
]);
15444 intel_modeset_verify_crtc(crtc
, state
, old_crtc_state
, new_crtc_state
);
15447 /* Underruns don't always raise interrupts, so check manually */
15448 intel_check_cpu_fifo_underruns(dev_priv
);
15449 intel_check_pch_fifo_underruns(dev_priv
);
15451 if (state
->modeset
)
15452 intel_verify_planes(state
);
15454 if (state
->modeset
&& intel_can_enable_sagv(state
))
15455 intel_enable_sagv(dev_priv
);
15457 drm_atomic_helper_commit_hw_done(&state
->base
);
15459 if (state
->modeset
) {
15460 /* As one of the primary mmio accessors, KMS has a high
15461 * likelihood of triggering bugs in unclaimed access. After we
15462 * finish modesetting, see if an error has been flagged, and if
15463 * so enable debugging for the next modeset - and hope we catch
15466 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv
->uncore
);
15467 intel_display_power_put(dev_priv
, POWER_DOMAIN_MODESET
, wakeref
);
15469 intel_runtime_pm_put(&dev_priv
->runtime_pm
, state
->wakeref
);
15472 * Defer the cleanup of the old state to a separate worker to not
15473 * impede the current task (userspace for blocking modesets) that
15474 * are executed inline. For out-of-line asynchronous modesets/flips,
15475 * deferring to a new worker seems overkill, but we would place a
15476 * schedule point (cond_resched()) here anyway to keep latencies
15479 INIT_WORK(&state
->base
.commit_work
, intel_atomic_cleanup_work
);
15480 queue_work(system_highpri_wq
, &state
->base
.commit_work
);
15483 static void intel_atomic_commit_work(struct work_struct
*work
)
15485 struct intel_atomic_state
*state
=
15486 container_of(work
, struct intel_atomic_state
, base
.commit_work
);
15488 intel_atomic_commit_tail(state
);
15491 static int __i915_sw_fence_call
15492 intel_atomic_commit_ready(struct i915_sw_fence
*fence
,
15493 enum i915_sw_fence_notify notify
)
15495 struct intel_atomic_state
*state
=
15496 container_of(fence
, struct intel_atomic_state
, commit_ready
);
15499 case FENCE_COMPLETE
:
15500 /* we do blocking waits in the worker, nothing to do here */
15504 struct intel_atomic_helper
*helper
=
15505 &to_i915(state
->base
.dev
)->atomic_helper
;
15507 if (llist_add(&state
->freed
, &helper
->free_list
))
15508 schedule_work(&helper
->free_work
);
15513 return NOTIFY_DONE
;
15516 static void intel_atomic_track_fbs(struct intel_atomic_state
*state
)
15518 struct intel_plane_state
*old_plane_state
, *new_plane_state
;
15519 struct intel_plane
*plane
;
15522 for_each_oldnew_intel_plane_in_state(state
, plane
, old_plane_state
,
15523 new_plane_state
, i
)
15524 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state
->hw
.fb
),
15525 to_intel_frontbuffer(new_plane_state
->hw
.fb
),
15526 plane
->frontbuffer_bit
);
15529 static void assert_global_state_locked(struct drm_i915_private
*dev_priv
)
15531 struct intel_crtc
*crtc
;
15533 for_each_intel_crtc(&dev_priv
->drm
, crtc
)
15534 drm_modeset_lock_assert_held(&crtc
->base
.mutex
);
15537 static int intel_atomic_commit(struct drm_device
*dev
,
15538 struct drm_atomic_state
*_state
,
15541 struct intel_atomic_state
*state
= to_intel_atomic_state(_state
);
15542 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15545 state
->wakeref
= intel_runtime_pm_get(&dev_priv
->runtime_pm
);
15547 drm_atomic_state_get(&state
->base
);
15548 i915_sw_fence_init(&state
->commit_ready
,
15549 intel_atomic_commit_ready
);
15552 * The intel_legacy_cursor_update() fast path takes care
15553 * of avoiding the vblank waits for simple cursor
15554 * movement and flips. For cursor on/off and size changes,
15555 * we want to perform the vblank waits so that watermark
15556 * updates happen during the correct frames. Gen9+ have
15557 * double buffered watermarks and so shouldn't need this.
15559 * Unset state->legacy_cursor_update before the call to
15560 * drm_atomic_helper_setup_commit() because otherwise
15561 * drm_atomic_helper_wait_for_flip_done() is a noop and
15562 * we get FIFO underruns because we didn't wait
15565 * FIXME doing watermarks and fb cleanup from a vblank worker
15566 * (assuming we had any) would solve these problems.
15568 if (INTEL_GEN(dev_priv
) < 9 && state
->base
.legacy_cursor_update
) {
15569 struct intel_crtc_state
*new_crtc_state
;
15570 struct intel_crtc
*crtc
;
15573 for_each_new_intel_crtc_in_state(state
, crtc
, new_crtc_state
, i
)
15574 if (new_crtc_state
->wm
.need_postvbl_update
||
15575 new_crtc_state
->update_wm_post
)
15576 state
->base
.legacy_cursor_update
= false;
15579 ret
= intel_atomic_prepare_commit(state
);
15581 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret
);
15582 i915_sw_fence_commit(&state
->commit_ready
);
15583 intel_runtime_pm_put(&dev_priv
->runtime_pm
, state
->wakeref
);
15587 ret
= drm_atomic_helper_setup_commit(&state
->base
, nonblock
);
15589 ret
= drm_atomic_helper_swap_state(&state
->base
, true);
15592 i915_sw_fence_commit(&state
->commit_ready
);
15594 drm_atomic_helper_cleanup_planes(dev
, &state
->base
);
15595 intel_runtime_pm_put(&dev_priv
->runtime_pm
, state
->wakeref
);
15598 dev_priv
->wm
.distrust_bios_wm
= false;
15599 intel_shared_dpll_swap_state(state
);
15600 intel_atomic_track_fbs(state
);
15602 if (state
->global_state_changed
) {
15603 assert_global_state_locked(dev_priv
);
15605 memcpy(dev_priv
->min_cdclk
, state
->min_cdclk
,
15606 sizeof(state
->min_cdclk
));
15607 memcpy(dev_priv
->min_voltage_level
, state
->min_voltage_level
,
15608 sizeof(state
->min_voltage_level
));
15609 dev_priv
->active_pipes
= state
->active_pipes
;
15610 dev_priv
->cdclk
.force_min_cdclk
= state
->cdclk
.force_min_cdclk
;
15612 intel_cdclk_swap_state(state
);
15615 drm_atomic_state_get(&state
->base
);
15616 INIT_WORK(&state
->base
.commit_work
, intel_atomic_commit_work
);
15618 i915_sw_fence_commit(&state
->commit_ready
);
15619 if (nonblock
&& state
->modeset
) {
15620 queue_work(dev_priv
->modeset_wq
, &state
->base
.commit_work
);
15621 } else if (nonblock
) {
15622 queue_work(dev_priv
->flip_wq
, &state
->base
.commit_work
);
15624 if (state
->modeset
)
15625 flush_workqueue(dev_priv
->modeset_wq
);
15626 intel_atomic_commit_tail(state
);
15632 struct wait_rps_boost
{
15633 struct wait_queue_entry wait
;
15635 struct drm_crtc
*crtc
;
15636 struct i915_request
*request
;
15639 static int do_rps_boost(struct wait_queue_entry
*_wait
,
15640 unsigned mode
, int sync
, void *key
)
15642 struct wait_rps_boost
*wait
= container_of(_wait
, typeof(*wait
), wait
);
15643 struct i915_request
*rq
= wait
->request
;
15646 * If we missed the vblank, but the request is already running it
15647 * is reasonable to assume that it will complete before the next
15648 * vblank without our intervention, so leave RPS alone.
15650 if (!i915_request_started(rq
))
15651 intel_rps_boost(rq
);
15652 i915_request_put(rq
);
15654 drm_crtc_vblank_put(wait
->crtc
);
15656 list_del(&wait
->wait
.entry
);
15661 static void add_rps_boost_after_vblank(struct drm_crtc
*crtc
,
15662 struct dma_fence
*fence
)
15664 struct wait_rps_boost
*wait
;
15666 if (!dma_fence_is_i915(fence
))
15669 if (INTEL_GEN(to_i915(crtc
->dev
)) < 6)
15672 if (drm_crtc_vblank_get(crtc
))
15675 wait
= kmalloc(sizeof(*wait
), GFP_KERNEL
);
15677 drm_crtc_vblank_put(crtc
);
15681 wait
->request
= to_request(dma_fence_get(fence
));
15684 wait
->wait
.func
= do_rps_boost
;
15685 wait
->wait
.flags
= 0;
15687 add_wait_queue(drm_crtc_vblank_waitqueue(crtc
), &wait
->wait
);
15690 static int intel_plane_pin_fb(struct intel_plane_state
*plane_state
)
15692 struct intel_plane
*plane
= to_intel_plane(plane_state
->uapi
.plane
);
15693 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
15694 struct drm_framebuffer
*fb
= plane_state
->hw
.fb
;
15695 struct i915_vma
*vma
;
15697 if (plane
->id
== PLANE_CURSOR
&&
15698 INTEL_INFO(dev_priv
)->display
.cursor_needs_physical
) {
15699 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
15700 const int align
= intel_cursor_alignment(dev_priv
);
15703 err
= i915_gem_object_attach_phys(obj
, align
);
15708 vma
= intel_pin_and_fence_fb_obj(fb
,
15709 &plane_state
->view
,
15710 intel_plane_uses_fence(plane_state
),
15711 &plane_state
->flags
);
15713 return PTR_ERR(vma
);
15715 plane_state
->vma
= vma
;
15720 static void intel_plane_unpin_fb(struct intel_plane_state
*old_plane_state
)
15722 struct i915_vma
*vma
;
15724 vma
= fetch_and_zero(&old_plane_state
->vma
);
15726 intel_unpin_fb_vma(vma
, old_plane_state
->flags
);
15729 static void fb_obj_bump_render_priority(struct drm_i915_gem_object
*obj
)
15731 struct i915_sched_attr attr
= {
15732 .priority
= I915_USER_PRIORITY(I915_PRIORITY_DISPLAY
),
15735 i915_gem_object_wait_priority(obj
, 0, &attr
);
15739 * intel_prepare_plane_fb - Prepare fb for usage on plane
15740 * @plane: drm plane to prepare for
15741 * @_new_plane_state: the plane state being prepared
15743 * Prepares a framebuffer for usage on a display plane. Generally this
15744 * involves pinning the underlying object and updating the frontbuffer tracking
15745 * bits. Some older platforms need special physical address handling for
15748 * Returns 0 on success, negative error code on failure.
15751 intel_prepare_plane_fb(struct drm_plane
*plane
,
15752 struct drm_plane_state
*_new_plane_state
)
15754 struct intel_plane_state
*new_plane_state
=
15755 to_intel_plane_state(_new_plane_state
);
15756 struct intel_atomic_state
*intel_state
=
15757 to_intel_atomic_state(new_plane_state
->uapi
.state
);
15758 struct drm_i915_private
*dev_priv
= to_i915(plane
->dev
);
15759 struct drm_framebuffer
*fb
= new_plane_state
->hw
.fb
;
15760 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
15761 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->state
->fb
);
15765 struct intel_crtc_state
*crtc_state
=
15766 intel_atomic_get_new_crtc_state(intel_state
,
15767 to_intel_crtc(plane
->state
->crtc
));
15769 /* Big Hammer, we also need to ensure that any pending
15770 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
15771 * current scanout is retired before unpinning the old
15772 * framebuffer. Note that we rely on userspace rendering
15773 * into the buffer attached to the pipe they are waiting
15774 * on. If not, userspace generates a GPU hang with IPEHR
15775 * point to the MI_WAIT_FOR_EVENT.
15777 * This should only fail upon a hung GPU, in which case we
15778 * can safely continue.
15780 if (needs_modeset(crtc_state
)) {
15781 ret
= i915_sw_fence_await_reservation(&intel_state
->commit_ready
,
15782 old_obj
->base
.resv
, NULL
,
15790 if (new_plane_state
->uapi
.fence
) { /* explicit fencing */
15791 ret
= i915_sw_fence_await_dma_fence(&intel_state
->commit_ready
,
15792 new_plane_state
->uapi
.fence
,
15793 I915_FENCE_TIMEOUT
,
15802 ret
= i915_gem_object_pin_pages(obj
);
15806 ret
= intel_plane_pin_fb(new_plane_state
);
15808 i915_gem_object_unpin_pages(obj
);
15812 fb_obj_bump_render_priority(obj
);
15813 i915_gem_object_flush_frontbuffer(obj
, ORIGIN_DIRTYFB
);
15815 if (!new_plane_state
->uapi
.fence
) { /* implicit fencing */
15816 struct dma_fence
*fence
;
15818 ret
= i915_sw_fence_await_reservation(&intel_state
->commit_ready
,
15819 obj
->base
.resv
, NULL
,
15820 false, I915_FENCE_TIMEOUT
,
15825 fence
= dma_resv_get_excl_rcu(obj
->base
.resv
);
15827 add_rps_boost_after_vblank(new_plane_state
->hw
.crtc
,
15829 dma_fence_put(fence
);
15832 add_rps_boost_after_vblank(new_plane_state
->hw
.crtc
,
15833 new_plane_state
->uapi
.fence
);
15837 * We declare pageflips to be interactive and so merit a small bias
15838 * towards upclocking to deliver the frame on time. By only changing
15839 * the RPS thresholds to sample more regularly and aim for higher
15840 * clocks we can hopefully deliver low power workloads (like kodi)
15841 * that are not quite steady state without resorting to forcing
15842 * maximum clocks following a vblank miss (see do_rps_boost()).
15844 if (!intel_state
->rps_interactive
) {
15845 intel_rps_mark_interactive(&dev_priv
->gt
.rps
, true);
15846 intel_state
->rps_interactive
= true;
15853 * intel_cleanup_plane_fb - Cleans up an fb after plane use
15854 * @plane: drm plane to clean up for
15855 * @_old_plane_state: the state from the previous modeset
15857 * Cleans up a framebuffer that has just been removed from a plane.
15860 intel_cleanup_plane_fb(struct drm_plane
*plane
,
15861 struct drm_plane_state
*_old_plane_state
)
15863 struct intel_plane_state
*old_plane_state
=
15864 to_intel_plane_state(_old_plane_state
);
15865 struct intel_atomic_state
*intel_state
=
15866 to_intel_atomic_state(old_plane_state
->uapi
.state
);
15867 struct drm_i915_private
*dev_priv
= to_i915(plane
->dev
);
15869 if (intel_state
->rps_interactive
) {
15870 intel_rps_mark_interactive(&dev_priv
->gt
.rps
, false);
15871 intel_state
->rps_interactive
= false;
15874 /* Should only be called after a successful intel_prepare_plane_fb()! */
15875 intel_plane_unpin_fb(old_plane_state
);
15879 * intel_plane_destroy - destroy a plane
15880 * @plane: plane to destroy
15882 * Common destruction function for all types of planes (primary, cursor,
15885 void intel_plane_destroy(struct drm_plane
*plane
)
15887 drm_plane_cleanup(plane
);
15888 kfree(to_intel_plane(plane
));
15891 static bool i8xx_plane_format_mod_supported(struct drm_plane
*_plane
,
15892 u32 format
, u64 modifier
)
15894 switch (modifier
) {
15895 case DRM_FORMAT_MOD_LINEAR
:
15896 case I915_FORMAT_MOD_X_TILED
:
15903 case DRM_FORMAT_C8
:
15904 case DRM_FORMAT_RGB565
:
15905 case DRM_FORMAT_XRGB1555
:
15906 case DRM_FORMAT_XRGB8888
:
15907 return modifier
== DRM_FORMAT_MOD_LINEAR
||
15908 modifier
== I915_FORMAT_MOD_X_TILED
;
15914 static bool i965_plane_format_mod_supported(struct drm_plane
*_plane
,
15915 u32 format
, u64 modifier
)
15917 switch (modifier
) {
15918 case DRM_FORMAT_MOD_LINEAR
:
15919 case I915_FORMAT_MOD_X_TILED
:
15926 case DRM_FORMAT_C8
:
15927 case DRM_FORMAT_RGB565
:
15928 case DRM_FORMAT_XRGB8888
:
15929 case DRM_FORMAT_XBGR8888
:
15930 case DRM_FORMAT_ARGB8888
:
15931 case DRM_FORMAT_ABGR8888
:
15932 case DRM_FORMAT_XRGB2101010
:
15933 case DRM_FORMAT_XBGR2101010
:
15934 case DRM_FORMAT_ARGB2101010
:
15935 case DRM_FORMAT_ABGR2101010
:
15936 case DRM_FORMAT_XBGR16161616F
:
15937 return modifier
== DRM_FORMAT_MOD_LINEAR
||
15938 modifier
== I915_FORMAT_MOD_X_TILED
;
15944 static bool intel_cursor_format_mod_supported(struct drm_plane
*_plane
,
15945 u32 format
, u64 modifier
)
15947 return modifier
== DRM_FORMAT_MOD_LINEAR
&&
15948 format
== DRM_FORMAT_ARGB8888
;
15951 static const struct drm_plane_funcs i965_plane_funcs
= {
15952 .update_plane
= drm_atomic_helper_update_plane
,
15953 .disable_plane
= drm_atomic_helper_disable_plane
,
15954 .destroy
= intel_plane_destroy
,
15955 .atomic_duplicate_state
= intel_plane_duplicate_state
,
15956 .atomic_destroy_state
= intel_plane_destroy_state
,
15957 .format_mod_supported
= i965_plane_format_mod_supported
,
15960 static const struct drm_plane_funcs i8xx_plane_funcs
= {
15961 .update_plane
= drm_atomic_helper_update_plane
,
15962 .disable_plane
= drm_atomic_helper_disable_plane
,
15963 .destroy
= intel_plane_destroy
,
15964 .atomic_duplicate_state
= intel_plane_duplicate_state
,
15965 .atomic_destroy_state
= intel_plane_destroy_state
,
15966 .format_mod_supported
= i8xx_plane_format_mod_supported
,
15970 intel_legacy_cursor_update(struct drm_plane
*_plane
,
15971 struct drm_crtc
*_crtc
,
15972 struct drm_framebuffer
*fb
,
15973 int crtc_x
, int crtc_y
,
15974 unsigned int crtc_w
, unsigned int crtc_h
,
15975 u32 src_x
, u32 src_y
,
15976 u32 src_w
, u32 src_h
,
15977 struct drm_modeset_acquire_ctx
*ctx
)
15979 struct intel_plane
*plane
= to_intel_plane(_plane
);
15980 struct intel_crtc
*crtc
= to_intel_crtc(_crtc
);
15981 struct intel_plane_state
*old_plane_state
=
15982 to_intel_plane_state(plane
->base
.state
);
15983 struct intel_plane_state
*new_plane_state
;
15984 struct intel_crtc_state
*crtc_state
=
15985 to_intel_crtc_state(crtc
->base
.state
);
15986 struct intel_crtc_state
*new_crtc_state
;
15990 * When crtc is inactive or there is a modeset pending,
15991 * wait for it to complete in the slowpath
15993 if (!crtc_state
->hw
.active
|| needs_modeset(crtc_state
) ||
15994 crtc_state
->update_pipe
)
15998 * Don't do an async update if there is an outstanding commit modifying
15999 * the plane. This prevents our async update's changes from getting
16000 * overridden by a previous synchronous update's state.
16002 if (old_plane_state
->uapi
.commit
&&
16003 !try_wait_for_completion(&old_plane_state
->uapi
.commit
->hw_done
))
16007 * If any parameters change that may affect watermarks,
16008 * take the slowpath. Only changing fb or position should be
16011 if (old_plane_state
->uapi
.crtc
!= &crtc
->base
||
16012 old_plane_state
->uapi
.src_w
!= src_w
||
16013 old_plane_state
->uapi
.src_h
!= src_h
||
16014 old_plane_state
->uapi
.crtc_w
!= crtc_w
||
16015 old_plane_state
->uapi
.crtc_h
!= crtc_h
||
16016 !old_plane_state
->uapi
.fb
!= !fb
)
16019 new_plane_state
= to_intel_plane_state(intel_plane_duplicate_state(&plane
->base
));
16020 if (!new_plane_state
)
16023 new_crtc_state
= to_intel_crtc_state(intel_crtc_duplicate_state(&crtc
->base
));
16024 if (!new_crtc_state
) {
16029 drm_atomic_set_fb_for_plane(&new_plane_state
->uapi
, fb
);
16031 new_plane_state
->uapi
.src_x
= src_x
;
16032 new_plane_state
->uapi
.src_y
= src_y
;
16033 new_plane_state
->uapi
.src_w
= src_w
;
16034 new_plane_state
->uapi
.src_h
= src_h
;
16035 new_plane_state
->uapi
.crtc_x
= crtc_x
;
16036 new_plane_state
->uapi
.crtc_y
= crtc_y
;
16037 new_plane_state
->uapi
.crtc_w
= crtc_w
;
16038 new_plane_state
->uapi
.crtc_h
= crtc_h
;
16040 ret
= intel_plane_atomic_check_with_state(crtc_state
, new_crtc_state
,
16041 old_plane_state
, new_plane_state
);
16045 ret
= intel_plane_pin_fb(new_plane_state
);
16049 intel_frontbuffer_flush(to_intel_frontbuffer(new_plane_state
->hw
.fb
),
16051 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state
->hw
.fb
),
16052 to_intel_frontbuffer(new_plane_state
->hw
.fb
),
16053 plane
->frontbuffer_bit
);
16055 /* Swap plane state */
16056 plane
->base
.state
= &new_plane_state
->uapi
;
16059 * We cannot swap crtc_state as it may be in use by an atomic commit or
16060 * page flip that's running simultaneously. If we swap crtc_state and
16061 * destroy the old state, we will cause a use-after-free there.
16063 * Only update active_planes, which is needed for our internal
16064 * bookkeeping. Either value will do the right thing when updating
16065 * planes atomically. If the cursor was part of the atomic update then
16066 * we would have taken the slowpath.
16068 crtc_state
->active_planes
= new_crtc_state
->active_planes
;
16070 if (new_plane_state
->uapi
.visible
)
16071 intel_update_plane(plane
, crtc_state
, new_plane_state
);
16073 intel_disable_plane(plane
, crtc_state
);
16075 intel_plane_unpin_fb(old_plane_state
);
16078 if (new_crtc_state
)
16079 intel_crtc_destroy_state(&crtc
->base
, &new_crtc_state
->uapi
);
16081 intel_plane_destroy_state(&plane
->base
, &new_plane_state
->uapi
);
16083 intel_plane_destroy_state(&plane
->base
, &old_plane_state
->uapi
);
16087 return drm_atomic_helper_update_plane(&plane
->base
, &crtc
->base
, fb
,
16088 crtc_x
, crtc_y
, crtc_w
, crtc_h
,
16089 src_x
, src_y
, src_w
, src_h
, ctx
);
16092 static const struct drm_plane_funcs intel_cursor_plane_funcs
= {
16093 .update_plane
= intel_legacy_cursor_update
,
16094 .disable_plane
= drm_atomic_helper_disable_plane
,
16095 .destroy
= intel_plane_destroy
,
16096 .atomic_duplicate_state
= intel_plane_duplicate_state
,
16097 .atomic_destroy_state
= intel_plane_destroy_state
,
16098 .format_mod_supported
= intel_cursor_format_mod_supported
,
16101 static bool i9xx_plane_has_fbc(struct drm_i915_private
*dev_priv
,
16102 enum i9xx_plane_id i9xx_plane
)
16104 if (!HAS_FBC(dev_priv
))
16107 if (IS_BROADWELL(dev_priv
) || IS_HASWELL(dev_priv
))
16108 return i9xx_plane
== PLANE_A
; /* tied to pipe A */
16109 else if (IS_IVYBRIDGE(dev_priv
))
16110 return i9xx_plane
== PLANE_A
|| i9xx_plane
== PLANE_B
||
16111 i9xx_plane
== PLANE_C
;
16112 else if (INTEL_GEN(dev_priv
) >= 4)
16113 return i9xx_plane
== PLANE_A
|| i9xx_plane
== PLANE_B
;
16115 return i9xx_plane
== PLANE_A
;
16118 static struct intel_plane
*
16119 intel_primary_plane_create(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
16121 struct intel_plane
*plane
;
16122 const struct drm_plane_funcs
*plane_funcs
;
16123 unsigned int supported_rotations
;
16124 unsigned int possible_crtcs
;
16125 const u32
*formats
;
16129 if (INTEL_GEN(dev_priv
) >= 9)
16130 return skl_universal_plane_create(dev_priv
, pipe
,
16133 plane
= intel_plane_alloc();
16137 plane
->pipe
= pipe
;
16139 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
16140 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
16142 if (HAS_FBC(dev_priv
) && INTEL_GEN(dev_priv
) < 4)
16143 plane
->i9xx_plane
= (enum i9xx_plane_id
) !pipe
;
16145 plane
->i9xx_plane
= (enum i9xx_plane_id
) pipe
;
16146 plane
->id
= PLANE_PRIMARY
;
16147 plane
->frontbuffer_bit
= INTEL_FRONTBUFFER(pipe
, plane
->id
);
16149 plane
->has_fbc
= i9xx_plane_has_fbc(dev_priv
, plane
->i9xx_plane
);
16150 if (plane
->has_fbc
) {
16151 struct intel_fbc
*fbc
= &dev_priv
->fbc
;
16153 fbc
->possible_framebuffer_bits
|= plane
->frontbuffer_bit
;
16156 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
16157 formats
= vlv_primary_formats
;
16158 num_formats
= ARRAY_SIZE(vlv_primary_formats
);
16159 } else if (INTEL_GEN(dev_priv
) >= 4) {
16161 * WaFP16GammaEnabling:ivb
16162 * "Workaround : When using the 64-bit format, the plane
16163 * output on each color channel has one quarter amplitude.
16164 * It can be brought up to full amplitude by using pipe
16165 * gamma correction or pipe color space conversion to
16166 * multiply the plane output by four."
16168 * There is no dedicated plane gamma for the primary plane,
16169 * and using the pipe gamma/csc could conflict with other
16170 * planes, so we choose not to expose fp16 on IVB primary
16171 * planes. HSW primary planes no longer have this problem.
16173 if (IS_IVYBRIDGE(dev_priv
)) {
16174 formats
= ivb_primary_formats
;
16175 num_formats
= ARRAY_SIZE(ivb_primary_formats
);
16177 formats
= i965_primary_formats
;
16178 num_formats
= ARRAY_SIZE(i965_primary_formats
);
16181 formats
= i8xx_primary_formats
;
16182 num_formats
= ARRAY_SIZE(i8xx_primary_formats
);
16185 if (INTEL_GEN(dev_priv
) >= 4)
16186 plane_funcs
= &i965_plane_funcs
;
16188 plane_funcs
= &i8xx_plane_funcs
;
16190 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
16191 plane
->min_cdclk
= vlv_plane_min_cdclk
;
16192 else if (IS_BROADWELL(dev_priv
) || IS_HASWELL(dev_priv
))
16193 plane
->min_cdclk
= hsw_plane_min_cdclk
;
16194 else if (IS_IVYBRIDGE(dev_priv
))
16195 plane
->min_cdclk
= ivb_plane_min_cdclk
;
16197 plane
->min_cdclk
= i9xx_plane_min_cdclk
;
16199 plane
->max_stride
= i9xx_plane_max_stride
;
16200 plane
->update_plane
= i9xx_update_plane
;
16201 plane
->disable_plane
= i9xx_disable_plane
;
16202 plane
->get_hw_state
= i9xx_plane_get_hw_state
;
16203 plane
->check_plane
= i9xx_plane_check
;
16205 possible_crtcs
= BIT(pipe
);
16207 if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
))
16208 ret
= drm_universal_plane_init(&dev_priv
->drm
, &plane
->base
,
16209 possible_crtcs
, plane_funcs
,
16210 formats
, num_formats
,
16211 i9xx_format_modifiers
,
16212 DRM_PLANE_TYPE_PRIMARY
,
16213 "primary %c", pipe_name(pipe
));
16215 ret
= drm_universal_plane_init(&dev_priv
->drm
, &plane
->base
,
16216 possible_crtcs
, plane_funcs
,
16217 formats
, num_formats
,
16218 i9xx_format_modifiers
,
16219 DRM_PLANE_TYPE_PRIMARY
,
16221 plane_name(plane
->i9xx_plane
));
16225 if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_B
) {
16226 supported_rotations
=
16227 DRM_MODE_ROTATE_0
| DRM_MODE_ROTATE_180
|
16228 DRM_MODE_REFLECT_X
;
16229 } else if (INTEL_GEN(dev_priv
) >= 4) {
16230 supported_rotations
=
16231 DRM_MODE_ROTATE_0
| DRM_MODE_ROTATE_180
;
16233 supported_rotations
= DRM_MODE_ROTATE_0
;
16236 if (INTEL_GEN(dev_priv
) >= 4)
16237 drm_plane_create_rotation_property(&plane
->base
,
16239 supported_rotations
);
16242 drm_plane_create_zpos_immutable_property(&plane
->base
, zpos
);
16244 drm_plane_helper_add(&plane
->base
, &intel_plane_helper_funcs
);
16249 intel_plane_free(plane
);
16251 return ERR_PTR(ret
);
16254 static struct intel_plane
*
16255 intel_cursor_plane_create(struct drm_i915_private
*dev_priv
,
16258 unsigned int possible_crtcs
;
16259 struct intel_plane
*cursor
;
16262 cursor
= intel_plane_alloc();
16263 if (IS_ERR(cursor
))
16266 cursor
->pipe
= pipe
;
16267 cursor
->i9xx_plane
= (enum i9xx_plane_id
) pipe
;
16268 cursor
->id
= PLANE_CURSOR
;
16269 cursor
->frontbuffer_bit
= INTEL_FRONTBUFFER(pipe
, cursor
->id
);
16271 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
)) {
16272 cursor
->max_stride
= i845_cursor_max_stride
;
16273 cursor
->update_plane
= i845_update_cursor
;
16274 cursor
->disable_plane
= i845_disable_cursor
;
16275 cursor
->get_hw_state
= i845_cursor_get_hw_state
;
16276 cursor
->check_plane
= i845_check_cursor
;
16278 cursor
->max_stride
= i9xx_cursor_max_stride
;
16279 cursor
->update_plane
= i9xx_update_cursor
;
16280 cursor
->disable_plane
= i9xx_disable_cursor
;
16281 cursor
->get_hw_state
= i9xx_cursor_get_hw_state
;
16282 cursor
->check_plane
= i9xx_check_cursor
;
16285 cursor
->cursor
.base
= ~0;
16286 cursor
->cursor
.cntl
= ~0;
16288 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
) || HAS_CUR_FBC(dev_priv
))
16289 cursor
->cursor
.size
= ~0;
16291 possible_crtcs
= BIT(pipe
);
16293 ret
= drm_universal_plane_init(&dev_priv
->drm
, &cursor
->base
,
16294 possible_crtcs
, &intel_cursor_plane_funcs
,
16295 intel_cursor_formats
,
16296 ARRAY_SIZE(intel_cursor_formats
),
16297 cursor_format_modifiers
,
16298 DRM_PLANE_TYPE_CURSOR
,
16299 "cursor %c", pipe_name(pipe
));
16303 if (INTEL_GEN(dev_priv
) >= 4)
16304 drm_plane_create_rotation_property(&cursor
->base
,
16306 DRM_MODE_ROTATE_0
|
16307 DRM_MODE_ROTATE_180
);
16309 zpos
= RUNTIME_INFO(dev_priv
)->num_sprites
[pipe
] + 1;
16310 drm_plane_create_zpos_immutable_property(&cursor
->base
, zpos
);
16312 drm_plane_helper_add(&cursor
->base
, &intel_plane_helper_funcs
);
16317 intel_plane_free(cursor
);
16319 return ERR_PTR(ret
);
16322 #define INTEL_CRTC_FUNCS \
16323 .gamma_set = drm_atomic_helper_legacy_gamma_set, \
16324 .set_config = drm_atomic_helper_set_config, \
16325 .destroy = intel_crtc_destroy, \
16326 .page_flip = drm_atomic_helper_page_flip, \
16327 .atomic_duplicate_state = intel_crtc_duplicate_state, \
16328 .atomic_destroy_state = intel_crtc_destroy_state, \
16329 .set_crc_source = intel_crtc_set_crc_source, \
16330 .verify_crc_source = intel_crtc_verify_crc_source, \
16331 .get_crc_sources = intel_crtc_get_crc_sources
16333 static const struct drm_crtc_funcs bdw_crtc_funcs
= {
16336 .get_vblank_counter
= g4x_get_vblank_counter
,
16337 .enable_vblank
= bdw_enable_vblank
,
16338 .disable_vblank
= bdw_disable_vblank
,
16341 static const struct drm_crtc_funcs ilk_crtc_funcs
= {
16344 .get_vblank_counter
= g4x_get_vblank_counter
,
16345 .enable_vblank
= ilk_enable_vblank
,
16346 .disable_vblank
= ilk_disable_vblank
,
16349 static const struct drm_crtc_funcs g4x_crtc_funcs
= {
16352 .get_vblank_counter
= g4x_get_vblank_counter
,
16353 .enable_vblank
= i965_enable_vblank
,
16354 .disable_vblank
= i965_disable_vblank
,
16357 static const struct drm_crtc_funcs i965_crtc_funcs
= {
16360 .get_vblank_counter
= i915_get_vblank_counter
,
16361 .enable_vblank
= i965_enable_vblank
,
16362 .disable_vblank
= i965_disable_vblank
,
16365 static const struct drm_crtc_funcs i915gm_crtc_funcs
= {
16368 .get_vblank_counter
= i915_get_vblank_counter
,
16369 .enable_vblank
= i915gm_enable_vblank
,
16370 .disable_vblank
= i915gm_disable_vblank
,
16373 static const struct drm_crtc_funcs i915_crtc_funcs
= {
16376 .get_vblank_counter
= i915_get_vblank_counter
,
16377 .enable_vblank
= i8xx_enable_vblank
,
16378 .disable_vblank
= i8xx_disable_vblank
,
16381 static const struct drm_crtc_funcs i8xx_crtc_funcs
= {
16384 /* no hw vblank counter */
16385 .enable_vblank
= i8xx_enable_vblank
,
16386 .disable_vblank
= i8xx_disable_vblank
,
16389 static struct intel_crtc
*intel_crtc_alloc(void)
16391 struct intel_crtc_state
*crtc_state
;
16392 struct intel_crtc
*crtc
;
16394 crtc
= kzalloc(sizeof(*crtc
), GFP_KERNEL
);
16396 return ERR_PTR(-ENOMEM
);
16398 crtc_state
= intel_crtc_state_alloc(crtc
);
16401 return ERR_PTR(-ENOMEM
);
16404 crtc
->base
.state
= &crtc_state
->uapi
;
16405 crtc
->config
= crtc_state
;
16410 static void intel_crtc_free(struct intel_crtc
*crtc
)
16412 intel_crtc_destroy_state(&crtc
->base
, crtc
->base
.state
);
16416 static int intel_crtc_init(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
16418 struct intel_plane
*primary
, *cursor
;
16419 const struct drm_crtc_funcs
*funcs
;
16420 struct intel_crtc
*crtc
;
16423 crtc
= intel_crtc_alloc();
16425 return PTR_ERR(crtc
);
16428 crtc
->num_scalers
= RUNTIME_INFO(dev_priv
)->num_scalers
[pipe
];
16430 primary
= intel_primary_plane_create(dev_priv
, pipe
);
16431 if (IS_ERR(primary
)) {
16432 ret
= PTR_ERR(primary
);
16435 crtc
->plane_ids_mask
|= BIT(primary
->id
);
16437 for_each_sprite(dev_priv
, pipe
, sprite
) {
16438 struct intel_plane
*plane
;
16440 plane
= intel_sprite_plane_create(dev_priv
, pipe
, sprite
);
16441 if (IS_ERR(plane
)) {
16442 ret
= PTR_ERR(plane
);
16445 crtc
->plane_ids_mask
|= BIT(plane
->id
);
16448 cursor
= intel_cursor_plane_create(dev_priv
, pipe
);
16449 if (IS_ERR(cursor
)) {
16450 ret
= PTR_ERR(cursor
);
16453 crtc
->plane_ids_mask
|= BIT(cursor
->id
);
16455 if (HAS_GMCH(dev_priv
)) {
16456 if (IS_CHERRYVIEW(dev_priv
) ||
16457 IS_VALLEYVIEW(dev_priv
) || IS_G4X(dev_priv
))
16458 funcs
= &g4x_crtc_funcs
;
16459 else if (IS_GEN(dev_priv
, 4))
16460 funcs
= &i965_crtc_funcs
;
16461 else if (IS_I945GM(dev_priv
) || IS_I915GM(dev_priv
))
16462 funcs
= &i915gm_crtc_funcs
;
16463 else if (IS_GEN(dev_priv
, 3))
16464 funcs
= &i915_crtc_funcs
;
16466 funcs
= &i8xx_crtc_funcs
;
16468 if (INTEL_GEN(dev_priv
) >= 8)
16469 funcs
= &bdw_crtc_funcs
;
16471 funcs
= &ilk_crtc_funcs
;
16474 ret
= drm_crtc_init_with_planes(&dev_priv
->drm
, &crtc
->base
,
16475 &primary
->base
, &cursor
->base
,
16476 funcs
, "pipe %c", pipe_name(pipe
));
16480 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->pipe_to_crtc_mapping
) ||
16481 dev_priv
->pipe_to_crtc_mapping
[pipe
] != NULL
);
16482 dev_priv
->pipe_to_crtc_mapping
[pipe
] = crtc
;
16484 if (INTEL_GEN(dev_priv
) < 9) {
16485 enum i9xx_plane_id i9xx_plane
= primary
->i9xx_plane
;
16487 BUG_ON(i9xx_plane
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
16488 dev_priv
->plane_to_crtc_mapping
[i9xx_plane
] != NULL
);
16489 dev_priv
->plane_to_crtc_mapping
[i9xx_plane
] = crtc
;
16492 intel_color_init(crtc
);
16494 WARN_ON(drm_crtc_index(&crtc
->base
) != crtc
->pipe
);
16499 intel_crtc_free(crtc
);
16504 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device
*dev
, void *data
,
16505 struct drm_file
*file
)
16507 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
16508 struct drm_crtc
*drmmode_crtc
;
16509 struct intel_crtc
*crtc
;
16511 drmmode_crtc
= drm_crtc_find(dev
, file
, pipe_from_crtc_id
->crtc_id
);
16515 crtc
= to_intel_crtc(drmmode_crtc
);
16516 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
16521 static u32
intel_encoder_possible_clones(struct intel_encoder
*encoder
)
16523 struct drm_device
*dev
= encoder
->base
.dev
;
16524 struct intel_encoder
*source_encoder
;
16525 u32 possible_clones
= 0;
16527 for_each_intel_encoder(dev
, source_encoder
) {
16528 if (encoders_cloneable(encoder
, source_encoder
))
16529 possible_clones
|= drm_encoder_mask(&source_encoder
->base
);
16532 return possible_clones
;
16535 static u32
intel_encoder_possible_crtcs(struct intel_encoder
*encoder
)
16537 struct drm_device
*dev
= encoder
->base
.dev
;
16538 struct intel_crtc
*crtc
;
16539 u32 possible_crtcs
= 0;
16541 for_each_intel_crtc(dev
, crtc
) {
16542 if (encoder
->pipe_mask
& BIT(crtc
->pipe
))
16543 possible_crtcs
|= drm_crtc_mask(&crtc
->base
);
16546 return possible_crtcs
;
16549 static bool ilk_has_edp_a(struct drm_i915_private
*dev_priv
)
16551 if (!IS_MOBILE(dev_priv
))
16554 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
16557 if (IS_GEN(dev_priv
, 5) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
16563 static bool intel_ddi_crt_present(struct drm_i915_private
*dev_priv
)
16565 if (INTEL_GEN(dev_priv
) >= 9)
16568 if (IS_HSW_ULT(dev_priv
) || IS_BDW_ULT(dev_priv
))
16571 if (HAS_PCH_LPT_H(dev_priv
) &&
16572 I915_READ(SFUSE_STRAP
) & SFUSE_STRAP_CRT_DISABLED
)
16575 /* DDI E can't be used if DDI A requires 4 lanes */
16576 if (I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_A_4_LANES
)
16579 if (!dev_priv
->vbt
.int_crt_support
)
16585 void intel_pps_unlock_regs_wa(struct drm_i915_private
*dev_priv
)
16590 if (HAS_DDI(dev_priv
))
16593 * This w/a is needed at least on CPT/PPT, but to be sure apply it
16594 * everywhere where registers can be write protected.
16596 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
16601 for (pps_idx
= 0; pps_idx
< pps_num
; pps_idx
++) {
16602 u32 val
= I915_READ(PP_CONTROL(pps_idx
));
16604 val
= (val
& ~PANEL_UNLOCK_MASK
) | PANEL_UNLOCK_REGS
;
16605 I915_WRITE(PP_CONTROL(pps_idx
), val
);
16609 static void intel_pps_init(struct drm_i915_private
*dev_priv
)
16611 if (HAS_PCH_SPLIT(dev_priv
) || IS_GEN9_LP(dev_priv
))
16612 dev_priv
->pps_mmio_base
= PCH_PPS_BASE
;
16613 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
16614 dev_priv
->pps_mmio_base
= VLV_PPS_BASE
;
16616 dev_priv
->pps_mmio_base
= PPS_BASE
;
16618 intel_pps_unlock_regs_wa(dev_priv
);
16621 static void intel_setup_outputs(struct drm_i915_private
*dev_priv
)
16623 struct intel_encoder
*encoder
;
16624 bool dpd_is_edp
= false;
16626 intel_pps_init(dev_priv
);
16628 if (!HAS_DISPLAY(dev_priv
) || !INTEL_DISPLAY_ENABLED(dev_priv
))
16631 if (INTEL_GEN(dev_priv
) >= 12) {
16632 intel_ddi_init(dev_priv
, PORT_A
);
16633 intel_ddi_init(dev_priv
, PORT_B
);
16634 intel_ddi_init(dev_priv
, PORT_D
);
16635 intel_ddi_init(dev_priv
, PORT_E
);
16636 intel_ddi_init(dev_priv
, PORT_F
);
16637 intel_ddi_init(dev_priv
, PORT_G
);
16638 intel_ddi_init(dev_priv
, PORT_H
);
16639 intel_ddi_init(dev_priv
, PORT_I
);
16640 icl_dsi_init(dev_priv
);
16641 } else if (IS_ELKHARTLAKE(dev_priv
)) {
16642 intel_ddi_init(dev_priv
, PORT_A
);
16643 intel_ddi_init(dev_priv
, PORT_B
);
16644 intel_ddi_init(dev_priv
, PORT_C
);
16645 intel_ddi_init(dev_priv
, PORT_D
);
16646 icl_dsi_init(dev_priv
);
16647 } else if (IS_GEN(dev_priv
, 11)) {
16648 intel_ddi_init(dev_priv
, PORT_A
);
16649 intel_ddi_init(dev_priv
, PORT_B
);
16650 intel_ddi_init(dev_priv
, PORT_C
);
16651 intel_ddi_init(dev_priv
, PORT_D
);
16652 intel_ddi_init(dev_priv
, PORT_E
);
16654 * On some ICL SKUs port F is not present. No strap bits for
16655 * this, so rely on VBT.
16656 * Work around broken VBTs on SKUs known to have no port F.
16658 if (IS_ICL_WITH_PORT_F(dev_priv
) &&
16659 intel_bios_is_port_present(dev_priv
, PORT_F
))
16660 intel_ddi_init(dev_priv
, PORT_F
);
16662 icl_dsi_init(dev_priv
);
16663 } else if (IS_GEN9_LP(dev_priv
)) {
16665 * FIXME: Broxton doesn't support port detection via the
16666 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
16667 * detect the ports.
16669 intel_ddi_init(dev_priv
, PORT_A
);
16670 intel_ddi_init(dev_priv
, PORT_B
);
16671 intel_ddi_init(dev_priv
, PORT_C
);
16673 vlv_dsi_init(dev_priv
);
16674 } else if (HAS_DDI(dev_priv
)) {
16677 if (intel_ddi_crt_present(dev_priv
))
16678 intel_crt_init(dev_priv
);
16681 * Haswell uses DDI functions to detect digital outputs.
16682 * On SKL pre-D0 the strap isn't connected, so we assume
16685 found
= I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_INIT_DISPLAY_DETECTED
;
16686 /* WaIgnoreDDIAStrap: skl */
16687 if (found
|| IS_GEN9_BC(dev_priv
))
16688 intel_ddi_init(dev_priv
, PORT_A
);
16690 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
16692 found
= I915_READ(SFUSE_STRAP
);
16694 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
16695 intel_ddi_init(dev_priv
, PORT_B
);
16696 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
16697 intel_ddi_init(dev_priv
, PORT_C
);
16698 if (found
& SFUSE_STRAP_DDID_DETECTED
)
16699 intel_ddi_init(dev_priv
, PORT_D
);
16700 if (found
& SFUSE_STRAP_DDIF_DETECTED
)
16701 intel_ddi_init(dev_priv
, PORT_F
);
16703 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
16705 if (IS_GEN9_BC(dev_priv
) &&
16706 intel_bios_is_port_present(dev_priv
, PORT_E
))
16707 intel_ddi_init(dev_priv
, PORT_E
);
16709 } else if (HAS_PCH_SPLIT(dev_priv
)) {
16713 * intel_edp_init_connector() depends on this completing first,
16714 * to prevent the registration of both eDP and LVDS and the
16715 * incorrect sharing of the PPS.
16717 intel_lvds_init(dev_priv
);
16718 intel_crt_init(dev_priv
);
16720 dpd_is_edp
= intel_dp_is_port_edp(dev_priv
, PORT_D
);
16722 if (ilk_has_edp_a(dev_priv
))
16723 intel_dp_init(dev_priv
, DP_A
, PORT_A
);
16725 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
16726 /* PCH SDVOB multiplex with HDMIB */
16727 found
= intel_sdvo_init(dev_priv
, PCH_SDVOB
, PORT_B
);
16729 intel_hdmi_init(dev_priv
, PCH_HDMIB
, PORT_B
);
16730 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
16731 intel_dp_init(dev_priv
, PCH_DP_B
, PORT_B
);
16734 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
16735 intel_hdmi_init(dev_priv
, PCH_HDMIC
, PORT_C
);
16737 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
16738 intel_hdmi_init(dev_priv
, PCH_HDMID
, PORT_D
);
16740 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
16741 intel_dp_init(dev_priv
, PCH_DP_C
, PORT_C
);
16743 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
16744 intel_dp_init(dev_priv
, PCH_DP_D
, PORT_D
);
16745 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
16746 bool has_edp
, has_port
;
16748 if (IS_VALLEYVIEW(dev_priv
) && dev_priv
->vbt
.int_crt_support
)
16749 intel_crt_init(dev_priv
);
16752 * The DP_DETECTED bit is the latched state of the DDC
16753 * SDA pin at boot. However since eDP doesn't require DDC
16754 * (no way to plug in a DP->HDMI dongle) the DDC pins for
16755 * eDP ports may have been muxed to an alternate function.
16756 * Thus we can't rely on the DP_DETECTED bit alone to detect
16757 * eDP ports. Consult the VBT as well as DP_DETECTED to
16758 * detect eDP ports.
16760 * Sadly the straps seem to be missing sometimes even for HDMI
16761 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
16762 * and VBT for the presence of the port. Additionally we can't
16763 * trust the port type the VBT declares as we've seen at least
16764 * HDMI ports that the VBT claim are DP or eDP.
16766 has_edp
= intel_dp_is_port_edp(dev_priv
, PORT_B
);
16767 has_port
= intel_bios_is_port_present(dev_priv
, PORT_B
);
16768 if (I915_READ(VLV_DP_B
) & DP_DETECTED
|| has_port
)
16769 has_edp
&= intel_dp_init(dev_priv
, VLV_DP_B
, PORT_B
);
16770 if ((I915_READ(VLV_HDMIB
) & SDVO_DETECTED
|| has_port
) && !has_edp
)
16771 intel_hdmi_init(dev_priv
, VLV_HDMIB
, PORT_B
);
16773 has_edp
= intel_dp_is_port_edp(dev_priv
, PORT_C
);
16774 has_port
= intel_bios_is_port_present(dev_priv
, PORT_C
);
16775 if (I915_READ(VLV_DP_C
) & DP_DETECTED
|| has_port
)
16776 has_edp
&= intel_dp_init(dev_priv
, VLV_DP_C
, PORT_C
);
16777 if ((I915_READ(VLV_HDMIC
) & SDVO_DETECTED
|| has_port
) && !has_edp
)
16778 intel_hdmi_init(dev_priv
, VLV_HDMIC
, PORT_C
);
16780 if (IS_CHERRYVIEW(dev_priv
)) {
16782 * eDP not supported on port D,
16783 * so no need to worry about it
16785 has_port
= intel_bios_is_port_present(dev_priv
, PORT_D
);
16786 if (I915_READ(CHV_DP_D
) & DP_DETECTED
|| has_port
)
16787 intel_dp_init(dev_priv
, CHV_DP_D
, PORT_D
);
16788 if (I915_READ(CHV_HDMID
) & SDVO_DETECTED
|| has_port
)
16789 intel_hdmi_init(dev_priv
, CHV_HDMID
, PORT_D
);
16792 vlv_dsi_init(dev_priv
);
16793 } else if (IS_PINEVIEW(dev_priv
)) {
16794 intel_lvds_init(dev_priv
);
16795 intel_crt_init(dev_priv
);
16796 } else if (IS_GEN_RANGE(dev_priv
, 3, 4)) {
16797 bool found
= false;
16799 if (IS_MOBILE(dev_priv
))
16800 intel_lvds_init(dev_priv
);
16802 intel_crt_init(dev_priv
);
16804 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
16805 DRM_DEBUG_KMS("probing SDVOB\n");
16806 found
= intel_sdvo_init(dev_priv
, GEN3_SDVOB
, PORT_B
);
16807 if (!found
&& IS_G4X(dev_priv
)) {
16808 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
16809 intel_hdmi_init(dev_priv
, GEN4_HDMIB
, PORT_B
);
16812 if (!found
&& IS_G4X(dev_priv
))
16813 intel_dp_init(dev_priv
, DP_B
, PORT_B
);
16816 /* Before G4X SDVOC doesn't have its own detect register */
16818 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
16819 DRM_DEBUG_KMS("probing SDVOC\n");
16820 found
= intel_sdvo_init(dev_priv
, GEN3_SDVOC
, PORT_C
);
16823 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
16825 if (IS_G4X(dev_priv
)) {
16826 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
16827 intel_hdmi_init(dev_priv
, GEN4_HDMIC
, PORT_C
);
16829 if (IS_G4X(dev_priv
))
16830 intel_dp_init(dev_priv
, DP_C
, PORT_C
);
16833 if (IS_G4X(dev_priv
) && (I915_READ(DP_D
) & DP_DETECTED
))
16834 intel_dp_init(dev_priv
, DP_D
, PORT_D
);
16836 if (SUPPORTS_TV(dev_priv
))
16837 intel_tv_init(dev_priv
);
16838 } else if (IS_GEN(dev_priv
, 2)) {
16839 if (IS_I85X(dev_priv
))
16840 intel_lvds_init(dev_priv
);
16842 intel_crt_init(dev_priv
);
16843 intel_dvo_init(dev_priv
);
16846 intel_psr_init(dev_priv
);
16848 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
16849 encoder
->base
.possible_crtcs
=
16850 intel_encoder_possible_crtcs(encoder
);
16851 encoder
->base
.possible_clones
=
16852 intel_encoder_possible_clones(encoder
);
16855 intel_init_pch_refclk(dev_priv
);
16857 drm_helper_move_panel_connectors_to_head(&dev_priv
->drm
);
16860 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
16862 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
16864 drm_framebuffer_cleanup(fb
);
16865 intel_frontbuffer_put(intel_fb
->frontbuffer
);
16870 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
16871 struct drm_file
*file
,
16872 unsigned int *handle
)
16874 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
16876 if (obj
->userptr
.mm
) {
16877 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
16881 return drm_gem_handle_create(file
, &obj
->base
, handle
);
16884 static int intel_user_framebuffer_dirty(struct drm_framebuffer
*fb
,
16885 struct drm_file
*file
,
16886 unsigned flags
, unsigned color
,
16887 struct drm_clip_rect
*clips
,
16888 unsigned num_clips
)
16890 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
16892 i915_gem_object_flush_if_display(obj
);
16893 intel_frontbuffer_flush(to_intel_frontbuffer(fb
), ORIGIN_DIRTYFB
);
16898 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
16899 .destroy
= intel_user_framebuffer_destroy
,
16900 .create_handle
= intel_user_framebuffer_create_handle
,
16901 .dirty
= intel_user_framebuffer_dirty
,
16904 static int intel_framebuffer_init(struct intel_framebuffer
*intel_fb
,
16905 struct drm_i915_gem_object
*obj
,
16906 struct drm_mode_fb_cmd2
*mode_cmd
)
16908 struct drm_i915_private
*dev_priv
= to_i915(obj
->base
.dev
);
16909 struct drm_framebuffer
*fb
= &intel_fb
->base
;
16911 unsigned int tiling
, stride
;
16915 intel_fb
->frontbuffer
= intel_frontbuffer_get(obj
);
16916 if (!intel_fb
->frontbuffer
)
16919 i915_gem_object_lock(obj
);
16920 tiling
= i915_gem_object_get_tiling(obj
);
16921 stride
= i915_gem_object_get_stride(obj
);
16922 i915_gem_object_unlock(obj
);
16924 if (mode_cmd
->flags
& DRM_MODE_FB_MODIFIERS
) {
16926 * If there's a fence, enforce that
16927 * the fb modifier and tiling mode match.
16929 if (tiling
!= I915_TILING_NONE
&&
16930 tiling
!= intel_fb_modifier_to_tiling(mode_cmd
->modifier
[0])) {
16931 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
16935 if (tiling
== I915_TILING_X
) {
16936 mode_cmd
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
16937 } else if (tiling
== I915_TILING_Y
) {
16938 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
16943 if (!drm_any_plane_has_format(&dev_priv
->drm
,
16944 mode_cmd
->pixel_format
,
16945 mode_cmd
->modifier
[0])) {
16946 struct drm_format_name_buf format_name
;
16948 DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n",
16949 drm_get_format_name(mode_cmd
->pixel_format
,
16951 mode_cmd
->modifier
[0]);
16956 * gen2/3 display engine uses the fence if present,
16957 * so the tiling mode must match the fb modifier exactly.
16959 if (INTEL_GEN(dev_priv
) < 4 &&
16960 tiling
!= intel_fb_modifier_to_tiling(mode_cmd
->modifier
[0])) {
16961 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
16965 max_stride
= intel_fb_max_stride(dev_priv
, mode_cmd
->pixel_format
,
16966 mode_cmd
->modifier
[0]);
16967 if (mode_cmd
->pitches
[0] > max_stride
) {
16968 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
16969 mode_cmd
->modifier
[0] != DRM_FORMAT_MOD_LINEAR
?
16970 "tiled" : "linear",
16971 mode_cmd
->pitches
[0], max_stride
);
16976 * If there's a fence, enforce that
16977 * the fb pitch and fence stride match.
16979 if (tiling
!= I915_TILING_NONE
&& mode_cmd
->pitches
[0] != stride
) {
16980 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
16981 mode_cmd
->pitches
[0], stride
);
16985 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
16986 if (mode_cmd
->offsets
[0] != 0) {
16987 DRM_DEBUG_KMS("plane 0 offset (0x%08x) must be 0\n",
16988 mode_cmd
->offsets
[0]);
16992 drm_helper_mode_fill_fb_struct(&dev_priv
->drm
, fb
, mode_cmd
);
16994 for (i
= 0; i
< fb
->format
->num_planes
; i
++) {
16995 u32 stride_alignment
;
16997 if (mode_cmd
->handles
[i
] != mode_cmd
->handles
[0]) {
16998 DRM_DEBUG_KMS("bad plane %d handle\n", i
);
17002 stride_alignment
= intel_fb_stride_alignment(fb
, i
);
17003 if (fb
->pitches
[i
] & (stride_alignment
- 1)) {
17004 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
17005 i
, fb
->pitches
[i
], stride_alignment
);
17009 if (is_gen12_ccs_plane(fb
, i
)) {
17010 int ccs_aux_stride
= gen12_ccs_aux_stride(fb
, i
);
17012 if (fb
->pitches
[i
] != ccs_aux_stride
) {
17013 DRM_DEBUG_KMS("ccs aux plane %d pitch (%d) must be %d\n",
17015 fb
->pitches
[i
], ccs_aux_stride
);
17020 fb
->obj
[i
] = &obj
->base
;
17023 ret
= intel_fill_fb_info(dev_priv
, fb
);
17027 ret
= drm_framebuffer_init(&dev_priv
->drm
, fb
, &intel_fb_funcs
);
17029 DRM_ERROR("framebuffer init failed %d\n", ret
);
17036 intel_frontbuffer_put(intel_fb
->frontbuffer
);
17040 static struct drm_framebuffer
*
17041 intel_user_framebuffer_create(struct drm_device
*dev
,
17042 struct drm_file
*filp
,
17043 const struct drm_mode_fb_cmd2
*user_mode_cmd
)
17045 struct drm_framebuffer
*fb
;
17046 struct drm_i915_gem_object
*obj
;
17047 struct drm_mode_fb_cmd2 mode_cmd
= *user_mode_cmd
;
17049 obj
= i915_gem_object_lookup(filp
, mode_cmd
.handles
[0]);
17051 return ERR_PTR(-ENOENT
);
17053 fb
= intel_framebuffer_create(obj
, &mode_cmd
);
17054 i915_gem_object_put(obj
);
17059 static void intel_atomic_state_free(struct drm_atomic_state
*state
)
17061 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
17063 drm_atomic_state_default_release(state
);
17065 i915_sw_fence_fini(&intel_state
->commit_ready
);
17070 static enum drm_mode_status
17071 intel_mode_valid(struct drm_device
*dev
,
17072 const struct drm_display_mode
*mode
)
17074 struct drm_i915_private
*dev_priv
= to_i915(dev
);
17075 int hdisplay_max
, htotal_max
;
17076 int vdisplay_max
, vtotal_max
;
17079 * Can't reject DBLSCAN here because Xorg ddxen can add piles
17080 * of DBLSCAN modes to the output's mode list when they detect
17081 * the scaling mode property on the connector. And they don't
17082 * ask the kernel to validate those modes in any way until
17083 * modeset time at which point the client gets a protocol error.
17084 * So in order to not upset those clients we silently ignore the
17085 * DBLSCAN flag on such connectors. For other connectors we will
17086 * reject modes with the DBLSCAN flag in encoder->compute_config().
17087 * And we always reject DBLSCAN modes in connector->mode_valid()
17088 * as we never want such modes on the connector's mode list.
17091 if (mode
->vscan
> 1)
17092 return MODE_NO_VSCAN
;
17094 if (mode
->flags
& DRM_MODE_FLAG_HSKEW
)
17095 return MODE_H_ILLEGAL
;
17097 if (mode
->flags
& (DRM_MODE_FLAG_CSYNC
|
17098 DRM_MODE_FLAG_NCSYNC
|
17099 DRM_MODE_FLAG_PCSYNC
))
17102 if (mode
->flags
& (DRM_MODE_FLAG_BCAST
|
17103 DRM_MODE_FLAG_PIXMUX
|
17104 DRM_MODE_FLAG_CLKDIV2
))
17107 /* Transcoder timing limits */
17108 if (INTEL_GEN(dev_priv
) >= 11) {
17109 hdisplay_max
= 16384;
17110 vdisplay_max
= 8192;
17111 htotal_max
= 16384;
17113 } else if (INTEL_GEN(dev_priv
) >= 9 ||
17114 IS_BROADWELL(dev_priv
) || IS_HASWELL(dev_priv
)) {
17115 hdisplay_max
= 8192; /* FDI max 4096 handled elsewhere */
17116 vdisplay_max
= 4096;
17119 } else if (INTEL_GEN(dev_priv
) >= 3) {
17120 hdisplay_max
= 4096;
17121 vdisplay_max
= 4096;
17125 hdisplay_max
= 2048;
17126 vdisplay_max
= 2048;
17131 if (mode
->hdisplay
> hdisplay_max
||
17132 mode
->hsync_start
> htotal_max
||
17133 mode
->hsync_end
> htotal_max
||
17134 mode
->htotal
> htotal_max
)
17135 return MODE_H_ILLEGAL
;
17137 if (mode
->vdisplay
> vdisplay_max
||
17138 mode
->vsync_start
> vtotal_max
||
17139 mode
->vsync_end
> vtotal_max
||
17140 mode
->vtotal
> vtotal_max
)
17141 return MODE_V_ILLEGAL
;
17143 if (INTEL_GEN(dev_priv
) >= 5) {
17144 if (mode
->hdisplay
< 64 ||
17145 mode
->htotal
- mode
->hdisplay
< 32)
17146 return MODE_H_ILLEGAL
;
17148 if (mode
->vtotal
- mode
->vdisplay
< 5)
17149 return MODE_V_ILLEGAL
;
17151 if (mode
->htotal
- mode
->hdisplay
< 32)
17152 return MODE_H_ILLEGAL
;
17154 if (mode
->vtotal
- mode
->vdisplay
< 3)
17155 return MODE_V_ILLEGAL
;
17161 enum drm_mode_status
17162 intel_mode_valid_max_plane_size(struct drm_i915_private
*dev_priv
,
17163 const struct drm_display_mode
*mode
)
17165 int plane_width_max
, plane_height_max
;
17168 * intel_mode_valid() should be
17169 * sufficient on older platforms.
17171 if (INTEL_GEN(dev_priv
) < 9)
17175 * Most people will probably want a fullscreen
17176 * plane so let's not advertize modes that are
17177 * too big for that.
17179 if (INTEL_GEN(dev_priv
) >= 11) {
17180 plane_width_max
= 5120;
17181 plane_height_max
= 4320;
17183 plane_width_max
= 5120;
17184 plane_height_max
= 4096;
17187 if (mode
->hdisplay
> plane_width_max
)
17188 return MODE_H_ILLEGAL
;
17190 if (mode
->vdisplay
> plane_height_max
)
17191 return MODE_V_ILLEGAL
;
17196 static const struct drm_mode_config_funcs intel_mode_funcs
= {
17197 .fb_create
= intel_user_framebuffer_create
,
17198 .get_format_info
= intel_get_format_info
,
17199 .output_poll_changed
= intel_fbdev_output_poll_changed
,
17200 .mode_valid
= intel_mode_valid
,
17201 .atomic_check
= intel_atomic_check
,
17202 .atomic_commit
= intel_atomic_commit
,
17203 .atomic_state_alloc
= intel_atomic_state_alloc
,
17204 .atomic_state_clear
= intel_atomic_state_clear
,
17205 .atomic_state_free
= intel_atomic_state_free
,
17209 * intel_init_display_hooks - initialize the display modesetting hooks
17210 * @dev_priv: device private
17212 void intel_init_display_hooks(struct drm_i915_private
*dev_priv
)
17214 intel_init_cdclk_hooks(dev_priv
);
17216 if (INTEL_GEN(dev_priv
) >= 9) {
17217 dev_priv
->display
.get_pipe_config
= hsw_get_pipe_config
;
17218 dev_priv
->display
.get_initial_plane_config
=
17219 skl_get_initial_plane_config
;
17220 dev_priv
->display
.crtc_compute_clock
= hsw_crtc_compute_clock
;
17221 dev_priv
->display
.crtc_enable
= hsw_crtc_enable
;
17222 dev_priv
->display
.crtc_disable
= hsw_crtc_disable
;
17223 } else if (HAS_DDI(dev_priv
)) {
17224 dev_priv
->display
.get_pipe_config
= hsw_get_pipe_config
;
17225 dev_priv
->display
.get_initial_plane_config
=
17226 i9xx_get_initial_plane_config
;
17227 dev_priv
->display
.crtc_compute_clock
=
17228 hsw_crtc_compute_clock
;
17229 dev_priv
->display
.crtc_enable
= hsw_crtc_enable
;
17230 dev_priv
->display
.crtc_disable
= hsw_crtc_disable
;
17231 } else if (HAS_PCH_SPLIT(dev_priv
)) {
17232 dev_priv
->display
.get_pipe_config
= ilk_get_pipe_config
;
17233 dev_priv
->display
.get_initial_plane_config
=
17234 i9xx_get_initial_plane_config
;
17235 dev_priv
->display
.crtc_compute_clock
=
17236 ilk_crtc_compute_clock
;
17237 dev_priv
->display
.crtc_enable
= ilk_crtc_enable
;
17238 dev_priv
->display
.crtc_disable
= ilk_crtc_disable
;
17239 } else if (IS_CHERRYVIEW(dev_priv
)) {
17240 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
17241 dev_priv
->display
.get_initial_plane_config
=
17242 i9xx_get_initial_plane_config
;
17243 dev_priv
->display
.crtc_compute_clock
= chv_crtc_compute_clock
;
17244 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
17245 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
17246 } else if (IS_VALLEYVIEW(dev_priv
)) {
17247 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
17248 dev_priv
->display
.get_initial_plane_config
=
17249 i9xx_get_initial_plane_config
;
17250 dev_priv
->display
.crtc_compute_clock
= vlv_crtc_compute_clock
;
17251 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
17252 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
17253 } else if (IS_G4X(dev_priv
)) {
17254 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
17255 dev_priv
->display
.get_initial_plane_config
=
17256 i9xx_get_initial_plane_config
;
17257 dev_priv
->display
.crtc_compute_clock
= g4x_crtc_compute_clock
;
17258 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
17259 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
17260 } else if (IS_PINEVIEW(dev_priv
)) {
17261 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
17262 dev_priv
->display
.get_initial_plane_config
=
17263 i9xx_get_initial_plane_config
;
17264 dev_priv
->display
.crtc_compute_clock
= pnv_crtc_compute_clock
;
17265 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
17266 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
17267 } else if (!IS_GEN(dev_priv
, 2)) {
17268 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
17269 dev_priv
->display
.get_initial_plane_config
=
17270 i9xx_get_initial_plane_config
;
17271 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
17272 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
17273 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
17275 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
17276 dev_priv
->display
.get_initial_plane_config
=
17277 i9xx_get_initial_plane_config
;
17278 dev_priv
->display
.crtc_compute_clock
= i8xx_crtc_compute_clock
;
17279 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
17280 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
17283 if (IS_GEN(dev_priv
, 5)) {
17284 dev_priv
->display
.fdi_link_train
= ilk_fdi_link_train
;
17285 } else if (IS_GEN(dev_priv
, 6)) {
17286 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
17287 } else if (IS_IVYBRIDGE(dev_priv
)) {
17288 /* FIXME: detect B0+ stepping and use auto training */
17289 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
17292 if (INTEL_GEN(dev_priv
) >= 9)
17293 dev_priv
->display
.commit_modeset_enables
= skl_commit_modeset_enables
;
17295 dev_priv
->display
.commit_modeset_enables
= intel_commit_modeset_enables
;
17299 void intel_modeset_init_hw(struct drm_i915_private
*i915
)
17301 intel_update_cdclk(i915
);
17302 intel_dump_cdclk_state(&i915
->cdclk
.hw
, "Current CDCLK");
17303 i915
->cdclk
.logical
= i915
->cdclk
.actual
= i915
->cdclk
.hw
;
17307 * Calculate what we think the watermarks should be for the state we've read
17308 * out of the hardware and then immediately program those watermarks so that
17309 * we ensure the hardware settings match our internal state.
17311 * We can calculate what we think WM's should be by creating a duplicate of the
17312 * current state (which was constructed during hardware readout) and running it
17313 * through the atomic check code to calculate new watermark values in the
17316 static void sanitize_watermarks(struct drm_device
*dev
)
17318 struct drm_i915_private
*dev_priv
= to_i915(dev
);
17319 struct drm_atomic_state
*state
;
17320 struct intel_atomic_state
*intel_state
;
17321 struct intel_crtc
*crtc
;
17322 struct intel_crtc_state
*crtc_state
;
17323 struct drm_modeset_acquire_ctx ctx
;
17327 /* Only supported on platforms that use atomic watermark design */
17328 if (!dev_priv
->display
.optimize_watermarks
)
17332 * We need to hold connection_mutex before calling duplicate_state so
17333 * that the connector loop is protected.
17335 drm_modeset_acquire_init(&ctx
, 0);
17337 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
17338 if (ret
== -EDEADLK
) {
17339 drm_modeset_backoff(&ctx
);
17341 } else if (WARN_ON(ret
)) {
17345 state
= drm_atomic_helper_duplicate_state(dev
, &ctx
);
17346 if (WARN_ON(IS_ERR(state
)))
17349 intel_state
= to_intel_atomic_state(state
);
17352 * Hardware readout is the only time we don't want to calculate
17353 * intermediate watermarks (since we don't trust the current
17356 if (!HAS_GMCH(dev_priv
))
17357 intel_state
->skip_intermediate_wm
= true;
17359 ret
= intel_atomic_check(dev
, state
);
17362 * If we fail here, it means that the hardware appears to be
17363 * programmed in a way that shouldn't be possible, given our
17364 * understanding of watermark requirements. This might mean a
17365 * mistake in the hardware readout code or a mistake in the
17366 * watermark calculations for a given platform. Raise a WARN
17367 * so that this is noticeable.
17369 * If this actually happens, we'll have to just leave the
17370 * BIOS-programmed watermarks untouched and hope for the best.
17372 WARN(true, "Could not determine valid watermarks for inherited state\n");
17376 /* Write calculated watermark values back */
17377 for_each_new_intel_crtc_in_state(intel_state
, crtc
, crtc_state
, i
) {
17378 crtc_state
->wm
.need_postvbl_update
= true;
17379 dev_priv
->display
.optimize_watermarks(intel_state
, crtc
);
17381 to_intel_crtc_state(crtc
->base
.state
)->wm
= crtc_state
->wm
;
17385 drm_atomic_state_put(state
);
17387 drm_modeset_drop_locks(&ctx
);
17388 drm_modeset_acquire_fini(&ctx
);
17391 static void intel_update_fdi_pll_freq(struct drm_i915_private
*dev_priv
)
17393 if (IS_GEN(dev_priv
, 5)) {
17395 I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
;
17397 dev_priv
->fdi_pll_freq
= (fdi_pll_clk
+ 2) * 10000;
17398 } else if (IS_GEN(dev_priv
, 6) || IS_IVYBRIDGE(dev_priv
)) {
17399 dev_priv
->fdi_pll_freq
= 270000;
17404 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv
->fdi_pll_freq
);
17407 static int intel_initial_commit(struct drm_device
*dev
)
17409 struct drm_atomic_state
*state
= NULL
;
17410 struct drm_modeset_acquire_ctx ctx
;
17411 struct intel_crtc
*crtc
;
17414 state
= drm_atomic_state_alloc(dev
);
17418 drm_modeset_acquire_init(&ctx
, 0);
17421 state
->acquire_ctx
= &ctx
;
17423 for_each_intel_crtc(dev
, crtc
) {
17424 struct intel_crtc_state
*crtc_state
=
17425 intel_atomic_get_crtc_state(state
, crtc
);
17427 if (IS_ERR(crtc_state
)) {
17428 ret
= PTR_ERR(crtc_state
);
17432 if (crtc_state
->hw
.active
) {
17433 ret
= drm_atomic_add_affected_planes(state
, &crtc
->base
);
17438 * FIXME hack to force a LUT update to avoid the
17439 * plane update forcing the pipe gamma on without
17440 * having a proper LUT loaded. Remove once we
17441 * have readout for pipe gamma enable.
17443 crtc_state
->uapi
.color_mgmt_changed
= true;
17447 ret
= drm_atomic_commit(state
);
17450 if (ret
== -EDEADLK
) {
17451 drm_atomic_state_clear(state
);
17452 drm_modeset_backoff(&ctx
);
17456 drm_atomic_state_put(state
);
17458 drm_modeset_drop_locks(&ctx
);
17459 drm_modeset_acquire_fini(&ctx
);
17464 static void intel_mode_config_init(struct drm_i915_private
*i915
)
17466 struct drm_mode_config
*mode_config
= &i915
->drm
.mode_config
;
17468 drm_mode_config_init(&i915
->drm
);
17470 mode_config
->min_width
= 0;
17471 mode_config
->min_height
= 0;
17473 mode_config
->preferred_depth
= 24;
17474 mode_config
->prefer_shadow
= 1;
17476 mode_config
->allow_fb_modifiers
= true;
17478 mode_config
->funcs
= &intel_mode_funcs
;
17481 * Maximum framebuffer dimensions, chosen to match
17482 * the maximum render engine surface size on gen4+.
17484 if (INTEL_GEN(i915
) >= 7) {
17485 mode_config
->max_width
= 16384;
17486 mode_config
->max_height
= 16384;
17487 } else if (INTEL_GEN(i915
) >= 4) {
17488 mode_config
->max_width
= 8192;
17489 mode_config
->max_height
= 8192;
17490 } else if (IS_GEN(i915
, 3)) {
17491 mode_config
->max_width
= 4096;
17492 mode_config
->max_height
= 4096;
17494 mode_config
->max_width
= 2048;
17495 mode_config
->max_height
= 2048;
17498 if (IS_I845G(i915
) || IS_I865G(i915
)) {
17499 mode_config
->cursor_width
= IS_I845G(i915
) ? 64 : 512;
17500 mode_config
->cursor_height
= 1023;
17501 } else if (IS_GEN(i915
, 2)) {
17502 mode_config
->cursor_width
= 64;
17503 mode_config
->cursor_height
= 64;
17505 mode_config
->cursor_width
= 256;
17506 mode_config
->cursor_height
= 256;
17510 int intel_modeset_init(struct drm_i915_private
*i915
)
17512 struct drm_device
*dev
= &i915
->drm
;
17514 struct intel_crtc
*crtc
;
17517 i915
->modeset_wq
= alloc_ordered_workqueue("i915_modeset", 0);
17518 i915
->flip_wq
= alloc_workqueue("i915_flip", WQ_HIGHPRI
|
17519 WQ_UNBOUND
, WQ_UNBOUND_MAX_ACTIVE
);
17521 intel_mode_config_init(i915
);
17523 ret
= intel_bw_init(i915
);
17527 init_llist_head(&i915
->atomic_helper
.free_list
);
17528 INIT_WORK(&i915
->atomic_helper
.free_work
,
17529 intel_atomic_helper_free_state_worker
);
17531 intel_init_quirks(i915
);
17533 intel_fbc_init(i915
);
17535 intel_init_pm(i915
);
17537 intel_panel_sanitize_ssc(i915
);
17539 intel_gmbus_setup(i915
);
17541 DRM_DEBUG_KMS("%d display pipe%s available.\n",
17542 INTEL_NUM_PIPES(i915
),
17543 INTEL_NUM_PIPES(i915
) > 1 ? "s" : "");
17545 if (HAS_DISPLAY(i915
) && INTEL_DISPLAY_ENABLED(i915
)) {
17546 for_each_pipe(i915
, pipe
) {
17547 ret
= intel_crtc_init(i915
, pipe
);
17549 drm_mode_config_cleanup(dev
);
17555 intel_shared_dpll_init(dev
);
17556 intel_update_fdi_pll_freq(i915
);
17558 intel_update_czclk(i915
);
17559 intel_modeset_init_hw(i915
);
17561 intel_hdcp_component_init(i915
);
17563 if (i915
->max_cdclk_freq
== 0)
17564 intel_update_max_cdclk(i915
);
17566 /* Just disable it once at startup */
17567 intel_vga_disable(i915
);
17568 intel_setup_outputs(i915
);
17570 drm_modeset_lock_all(dev
);
17571 intel_modeset_setup_hw_state(dev
, dev
->mode_config
.acquire_ctx
);
17572 drm_modeset_unlock_all(dev
);
17574 for_each_intel_crtc(dev
, crtc
) {
17575 struct intel_initial_plane_config plane_config
= {};
17581 * Note that reserving the BIOS fb up front prevents us
17582 * from stuffing other stolen allocations like the ring
17583 * on top. This prevents some ugliness at boot time, and
17584 * can even allow for smooth boot transitions if the BIOS
17585 * fb is large enough for the active pipe configuration.
17587 i915
->display
.get_initial_plane_config(crtc
, &plane_config
);
17590 * If the fb is shared between multiple heads, we'll
17591 * just get the first one.
17593 intel_find_initial_plane_obj(crtc
, &plane_config
);
17597 * Make sure hardware watermarks really match the state we read out.
17598 * Note that we need to do this after reconstructing the BIOS fb's
17599 * since the watermark calculation done here will use pstate->fb.
17601 if (!HAS_GMCH(i915
))
17602 sanitize_watermarks(dev
);
17605 * Force all active planes to recompute their states. So that on
17606 * mode_setcrtc after probe, all the intel_plane_state variables
17607 * are already calculated and there is no assert_plane warnings
17610 ret
= intel_initial_commit(dev
);
17612 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
17617 void i830_enable_pipe(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
17619 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
17620 /* 640x480@60Hz, ~25175 kHz */
17621 struct dpll clock
= {
17631 WARN_ON(i9xx_calc_dpll_params(48000, &clock
) != 25154);
17633 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
17634 pipe_name(pipe
), clock
.vco
, clock
.dot
);
17636 fp
= i9xx_dpll_compute_fp(&clock
);
17637 dpll
= DPLL_DVO_2X_MODE
|
17638 DPLL_VGA_MODE_DIS
|
17639 ((clock
.p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
) |
17640 PLL_P2_DIVIDE_BY_4
|
17641 PLL_REF_INPUT_DREFCLK
|
17644 I915_WRITE(FP0(pipe
), fp
);
17645 I915_WRITE(FP1(pipe
), fp
);
17647 I915_WRITE(HTOTAL(pipe
), (640 - 1) | ((800 - 1) << 16));
17648 I915_WRITE(HBLANK(pipe
), (640 - 1) | ((800 - 1) << 16));
17649 I915_WRITE(HSYNC(pipe
), (656 - 1) | ((752 - 1) << 16));
17650 I915_WRITE(VTOTAL(pipe
), (480 - 1) | ((525 - 1) << 16));
17651 I915_WRITE(VBLANK(pipe
), (480 - 1) | ((525 - 1) << 16));
17652 I915_WRITE(VSYNC(pipe
), (490 - 1) | ((492 - 1) << 16));
17653 I915_WRITE(PIPESRC(pipe
), ((640 - 1) << 16) | (480 - 1));
17656 * Apparently we need to have VGA mode enabled prior to changing
17657 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
17658 * dividers, even though the register value does change.
17660 I915_WRITE(DPLL(pipe
), dpll
& ~DPLL_VGA_MODE_DIS
);
17661 I915_WRITE(DPLL(pipe
), dpll
);
17663 /* Wait for the clocks to stabilize. */
17664 POSTING_READ(DPLL(pipe
));
17667 /* The pixel multiplier can only be updated once the
17668 * DPLL is enabled and the clocks are stable.
17670 * So write it again.
17672 I915_WRITE(DPLL(pipe
), dpll
);
17674 /* We do this three times for luck */
17675 for (i
= 0; i
< 3 ; i
++) {
17676 I915_WRITE(DPLL(pipe
), dpll
);
17677 POSTING_READ(DPLL(pipe
));
17678 udelay(150); /* wait for warmup */
17681 I915_WRITE(PIPECONF(pipe
), PIPECONF_ENABLE
| PIPECONF_PROGRESSIVE
);
17682 POSTING_READ(PIPECONF(pipe
));
17684 intel_wait_for_pipe_scanline_moving(crtc
);
17687 void i830_disable_pipe(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
17689 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
17691 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
17694 WARN_ON(I915_READ(DSPCNTR(PLANE_A
)) & DISPLAY_PLANE_ENABLE
);
17695 WARN_ON(I915_READ(DSPCNTR(PLANE_B
)) & DISPLAY_PLANE_ENABLE
);
17696 WARN_ON(I915_READ(DSPCNTR(PLANE_C
)) & DISPLAY_PLANE_ENABLE
);
17697 WARN_ON(I915_READ(CURCNTR(PIPE_A
)) & MCURSOR_MODE
);
17698 WARN_ON(I915_READ(CURCNTR(PIPE_B
)) & MCURSOR_MODE
);
17700 I915_WRITE(PIPECONF(pipe
), 0);
17701 POSTING_READ(PIPECONF(pipe
));
17703 intel_wait_for_pipe_scanline_stopped(crtc
);
17705 I915_WRITE(DPLL(pipe
), DPLL_VGA_MODE_DIS
);
17706 POSTING_READ(DPLL(pipe
));
17710 intel_sanitize_plane_mapping(struct drm_i915_private
*dev_priv
)
17712 struct intel_crtc
*crtc
;
17714 if (INTEL_GEN(dev_priv
) >= 4)
17717 for_each_intel_crtc(&dev_priv
->drm
, crtc
) {
17718 struct intel_plane
*plane
=
17719 to_intel_plane(crtc
->base
.primary
);
17720 struct intel_crtc
*plane_crtc
;
17723 if (!plane
->get_hw_state(plane
, &pipe
))
17726 if (pipe
== crtc
->pipe
)
17729 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
17730 plane
->base
.base
.id
, plane
->base
.name
);
17732 plane_crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
17733 intel_plane_disable_noatomic(plane_crtc
, plane
);
17737 static bool intel_crtc_has_encoders(struct intel_crtc
*crtc
)
17739 struct drm_device
*dev
= crtc
->base
.dev
;
17740 struct intel_encoder
*encoder
;
17742 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
17748 static struct intel_connector
*intel_encoder_find_connector(struct intel_encoder
*encoder
)
17750 struct drm_device
*dev
= encoder
->base
.dev
;
17751 struct intel_connector
*connector
;
17753 for_each_connector_on_encoder(dev
, &encoder
->base
, connector
)
17759 static bool has_pch_trancoder(struct drm_i915_private
*dev_priv
,
17760 enum pipe pch_transcoder
)
17762 return HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
) ||
17763 (HAS_PCH_LPT_H(dev_priv
) && pch_transcoder
== PIPE_A
);
17766 static void intel_sanitize_frame_start_delay(const struct intel_crtc_state
*crtc_state
)
17768 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
17769 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
17770 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
17772 if (INTEL_GEN(dev_priv
) >= 9 ||
17773 IS_BROADWELL(dev_priv
) || IS_HASWELL(dev_priv
)) {
17774 i915_reg_t reg
= CHICKEN_TRANS(cpu_transcoder
);
17777 if (transcoder_is_dsi(cpu_transcoder
))
17780 val
= I915_READ(reg
);
17781 val
&= ~HSW_FRAME_START_DELAY_MASK
;
17782 val
|= HSW_FRAME_START_DELAY(0);
17783 I915_WRITE(reg
, val
);
17785 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
17788 val
= I915_READ(reg
);
17789 val
&= ~PIPECONF_FRAME_START_DELAY_MASK
;
17790 val
|= PIPECONF_FRAME_START_DELAY(0);
17791 I915_WRITE(reg
, val
);
17794 if (!crtc_state
->has_pch_encoder
)
17797 if (HAS_PCH_IBX(dev_priv
)) {
17798 i915_reg_t reg
= PCH_TRANSCONF(crtc
->pipe
);
17801 val
= I915_READ(reg
);
17802 val
&= ~TRANS_FRAME_START_DELAY_MASK
;
17803 val
|= TRANS_FRAME_START_DELAY(0);
17804 I915_WRITE(reg
, val
);
17806 enum pipe pch_transcoder
= intel_crtc_pch_transcoder(crtc
);
17807 i915_reg_t reg
= TRANS_CHICKEN2(pch_transcoder
);
17810 val
= I915_READ(reg
);
17811 val
&= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK
;
17812 val
|= TRANS_CHICKEN2_FRAME_START_DELAY(0);
17813 I915_WRITE(reg
, val
);
17817 static void intel_sanitize_crtc(struct intel_crtc
*crtc
,
17818 struct drm_modeset_acquire_ctx
*ctx
)
17820 struct drm_device
*dev
= crtc
->base
.dev
;
17821 struct drm_i915_private
*dev_priv
= to_i915(dev
);
17822 struct intel_crtc_state
*crtc_state
= to_intel_crtc_state(crtc
->base
.state
);
17824 if (crtc_state
->hw
.active
) {
17825 struct intel_plane
*plane
;
17827 /* Clear any frame start delays used for debugging left by the BIOS */
17828 intel_sanitize_frame_start_delay(crtc_state
);
17830 /* Disable everything but the primary plane */
17831 for_each_intel_plane_on_crtc(dev
, crtc
, plane
) {
17832 const struct intel_plane_state
*plane_state
=
17833 to_intel_plane_state(plane
->base
.state
);
17835 if (plane_state
->uapi
.visible
&&
17836 plane
->base
.type
!= DRM_PLANE_TYPE_PRIMARY
)
17837 intel_plane_disable_noatomic(crtc
, plane
);
17841 * Disable any background color set by the BIOS, but enable the
17842 * gamma and CSC to match how we program our planes.
17844 if (INTEL_GEN(dev_priv
) >= 9)
17845 I915_WRITE(SKL_BOTTOM_COLOR(crtc
->pipe
),
17846 SKL_BOTTOM_COLOR_GAMMA_ENABLE
|
17847 SKL_BOTTOM_COLOR_CSC_ENABLE
);
17850 /* Adjust the state of the output pipe according to whether we
17851 * have active connectors/encoders. */
17852 if (crtc_state
->hw
.active
&& !intel_crtc_has_encoders(crtc
))
17853 intel_crtc_disable_noatomic(crtc
, ctx
);
17855 if (crtc_state
->hw
.active
|| HAS_GMCH(dev_priv
)) {
17857 * We start out with underrun reporting disabled to avoid races.
17858 * For correct bookkeeping mark this on active crtcs.
17860 * Also on gmch platforms we dont have any hardware bits to
17861 * disable the underrun reporting. Which means we need to start
17862 * out with underrun reporting disabled also on inactive pipes,
17863 * since otherwise we'll complain about the garbage we read when
17864 * e.g. coming up after runtime pm.
17866 * No protection against concurrent access is required - at
17867 * worst a fifo underrun happens which also sets this to false.
17869 crtc
->cpu_fifo_underrun_disabled
= true;
17871 * We track the PCH trancoder underrun reporting state
17872 * within the crtc. With crtc for pipe A housing the underrun
17873 * reporting state for PCH transcoder A, crtc for pipe B housing
17874 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
17875 * and marking underrun reporting as disabled for the non-existing
17876 * PCH transcoders B and C would prevent enabling the south
17877 * error interrupt (see cpt_can_enable_serr_int()).
17879 if (has_pch_trancoder(dev_priv
, crtc
->pipe
))
17880 crtc
->pch_fifo_underrun_disabled
= true;
17884 static bool has_bogus_dpll_config(const struct intel_crtc_state
*crtc_state
)
17886 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->uapi
.crtc
->dev
);
17889 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
17890 * the hardware when a high res displays plugged in. DPLL P
17891 * divider is zero, and the pipe timings are bonkers. We'll
17892 * try to disable everything in that case.
17894 * FIXME would be nice to be able to sanitize this state
17895 * without several WARNs, but for now let's take the easy
17898 return IS_GEN(dev_priv
, 6) &&
17899 crtc_state
->hw
.active
&&
17900 crtc_state
->shared_dpll
&&
17901 crtc_state
->port_clock
== 0;
17904 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
17906 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
17907 struct intel_connector
*connector
;
17908 struct intel_crtc
*crtc
= to_intel_crtc(encoder
->base
.crtc
);
17909 struct intel_crtc_state
*crtc_state
= crtc
?
17910 to_intel_crtc_state(crtc
->base
.state
) : NULL
;
17912 /* We need to check both for a crtc link (meaning that the
17913 * encoder is active and trying to read from a pipe) and the
17914 * pipe itself being active. */
17915 bool has_active_crtc
= crtc_state
&&
17916 crtc_state
->hw
.active
;
17918 if (crtc_state
&& has_bogus_dpll_config(crtc_state
)) {
17919 DRM_DEBUG_KMS("BIOS has misprogrammed the hardware. Disabling pipe %c\n",
17920 pipe_name(crtc
->pipe
));
17921 has_active_crtc
= false;
17924 connector
= intel_encoder_find_connector(encoder
);
17925 if (connector
&& !has_active_crtc
) {
17926 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
17927 encoder
->base
.base
.id
,
17928 encoder
->base
.name
);
17930 /* Connector is active, but has no active pipe. This is
17931 * fallout from our resume register restoring. Disable
17932 * the encoder manually again. */
17934 struct drm_encoder
*best_encoder
;
17936 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
17937 encoder
->base
.base
.id
,
17938 encoder
->base
.name
);
17940 /* avoid oopsing in case the hooks consult best_encoder */
17941 best_encoder
= connector
->base
.state
->best_encoder
;
17942 connector
->base
.state
->best_encoder
= &encoder
->base
;
17944 if (encoder
->disable
)
17945 encoder
->disable(encoder
, crtc_state
,
17946 connector
->base
.state
);
17947 if (encoder
->post_disable
)
17948 encoder
->post_disable(encoder
, crtc_state
,
17949 connector
->base
.state
);
17951 connector
->base
.state
->best_encoder
= best_encoder
;
17953 encoder
->base
.crtc
= NULL
;
17955 /* Inconsistent output/port/pipe state happens presumably due to
17956 * a bug in one of the get_hw_state functions. Or someplace else
17957 * in our code, like the register restore mess on resume. Clamp
17958 * things to off as a safer default. */
17960 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
17961 connector
->base
.encoder
= NULL
;
17964 /* notify opregion of the sanitized encoder state */
17965 intel_opregion_notify_encoder(encoder
, connector
&& has_active_crtc
);
17967 if (INTEL_GEN(dev_priv
) >= 11)
17968 icl_sanitize_encoder_pll_mapping(encoder
);
17971 /* FIXME read out full plane state for all planes */
17972 static void readout_plane_state(struct drm_i915_private
*dev_priv
)
17974 struct intel_plane
*plane
;
17975 struct intel_crtc
*crtc
;
17977 for_each_intel_plane(&dev_priv
->drm
, plane
) {
17978 struct intel_plane_state
*plane_state
=
17979 to_intel_plane_state(plane
->base
.state
);
17980 struct intel_crtc_state
*crtc_state
;
17981 enum pipe pipe
= PIPE_A
;
17984 visible
= plane
->get_hw_state(plane
, &pipe
);
17986 crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
17987 crtc_state
= to_intel_crtc_state(crtc
->base
.state
);
17989 intel_set_plane_visible(crtc_state
, plane_state
, visible
);
17991 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
17992 plane
->base
.base
.id
, plane
->base
.name
,
17993 enableddisabled(visible
), pipe_name(pipe
));
17996 for_each_intel_crtc(&dev_priv
->drm
, crtc
) {
17997 struct intel_crtc_state
*crtc_state
=
17998 to_intel_crtc_state(crtc
->base
.state
);
18000 fixup_active_planes(crtc_state
);
18004 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
18006 struct drm_i915_private
*dev_priv
= to_i915(dev
);
18008 struct intel_crtc
*crtc
;
18009 struct intel_encoder
*encoder
;
18010 struct intel_connector
*connector
;
18011 struct drm_connector_list_iter conn_iter
;
18014 dev_priv
->active_pipes
= 0;
18016 for_each_intel_crtc(dev
, crtc
) {
18017 struct intel_crtc_state
*crtc_state
=
18018 to_intel_crtc_state(crtc
->base
.state
);
18020 __drm_atomic_helper_crtc_destroy_state(&crtc_state
->uapi
);
18021 intel_crtc_free_hw_state(crtc_state
);
18022 intel_crtc_state_reset(crtc_state
, crtc
);
18024 crtc_state
->hw
.active
= crtc_state
->hw
.enable
=
18025 dev_priv
->display
.get_pipe_config(crtc
, crtc_state
);
18027 crtc
->base
.enabled
= crtc_state
->hw
.enable
;
18028 crtc
->active
= crtc_state
->hw
.active
;
18030 if (crtc_state
->hw
.active
)
18031 dev_priv
->active_pipes
|= BIT(crtc
->pipe
);
18033 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
18034 crtc
->base
.base
.id
, crtc
->base
.name
,
18035 enableddisabled(crtc_state
->hw
.active
));
18038 readout_plane_state(dev_priv
);
18040 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
18041 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
18043 pll
->on
= pll
->info
->funcs
->get_hw_state(dev_priv
, pll
,
18044 &pll
->state
.hw_state
);
18046 if (IS_ELKHARTLAKE(dev_priv
) && pll
->on
&&
18047 pll
->info
->id
== DPLL_ID_EHL_DPLL4
) {
18048 pll
->wakeref
= intel_display_power_get(dev_priv
,
18049 POWER_DOMAIN_DPLL_DC_OFF
);
18052 pll
->state
.crtc_mask
= 0;
18053 for_each_intel_crtc(dev
, crtc
) {
18054 struct intel_crtc_state
*crtc_state
=
18055 to_intel_crtc_state(crtc
->base
.state
);
18057 if (crtc_state
->hw
.active
&&
18058 crtc_state
->shared_dpll
== pll
)
18059 pll
->state
.crtc_mask
|= 1 << crtc
->pipe
;
18061 pll
->active_mask
= pll
->state
.crtc_mask
;
18063 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
18064 pll
->info
->name
, pll
->state
.crtc_mask
, pll
->on
);
18067 for_each_intel_encoder(dev
, encoder
) {
18070 if (encoder
->get_hw_state(encoder
, &pipe
)) {
18071 struct intel_crtc_state
*crtc_state
;
18073 crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
18074 crtc_state
= to_intel_crtc_state(crtc
->base
.state
);
18076 encoder
->base
.crtc
= &crtc
->base
;
18077 encoder
->get_config(encoder
, crtc_state
);
18079 encoder
->base
.crtc
= NULL
;
18082 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
18083 encoder
->base
.base
.id
, encoder
->base
.name
,
18084 enableddisabled(encoder
->base
.crtc
),
18088 drm_connector_list_iter_begin(dev
, &conn_iter
);
18089 for_each_intel_connector_iter(connector
, &conn_iter
) {
18090 if (connector
->get_hw_state(connector
)) {
18091 struct intel_crtc_state
*crtc_state
;
18092 struct intel_crtc
*crtc
;
18094 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
18096 encoder
= connector
->encoder
;
18097 connector
->base
.encoder
= &encoder
->base
;
18099 crtc
= to_intel_crtc(encoder
->base
.crtc
);
18100 crtc_state
= crtc
? to_intel_crtc_state(crtc
->base
.state
) : NULL
;
18102 if (crtc_state
&& crtc_state
->hw
.active
) {
18104 * This has to be done during hardware readout
18105 * because anything calling .crtc_disable may
18106 * rely on the connector_mask being accurate.
18108 crtc_state
->uapi
.connector_mask
|=
18109 drm_connector_mask(&connector
->base
);
18110 crtc_state
->uapi
.encoder_mask
|=
18111 drm_encoder_mask(&encoder
->base
);
18114 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
18115 connector
->base
.encoder
= NULL
;
18117 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
18118 connector
->base
.base
.id
, connector
->base
.name
,
18119 enableddisabled(connector
->base
.encoder
));
18121 drm_connector_list_iter_end(&conn_iter
);
18123 for_each_intel_crtc(dev
, crtc
) {
18124 struct intel_bw_state
*bw_state
=
18125 to_intel_bw_state(dev_priv
->bw_obj
.state
);
18126 struct intel_crtc_state
*crtc_state
=
18127 to_intel_crtc_state(crtc
->base
.state
);
18128 struct intel_plane
*plane
;
18131 if (crtc_state
->hw
.active
) {
18132 struct drm_display_mode
*mode
= &crtc_state
->hw
.mode
;
18134 intel_mode_from_pipe_config(&crtc_state
->hw
.adjusted_mode
,
18137 *mode
= crtc_state
->hw
.adjusted_mode
;
18138 mode
->hdisplay
= crtc_state
->pipe_src_w
;
18139 mode
->vdisplay
= crtc_state
->pipe_src_h
;
18142 * The initial mode needs to be set in order to keep
18143 * the atomic core happy. It wants a valid mode if the
18144 * crtc's enabled, so we do the above call.
18146 * But we don't set all the derived state fully, hence
18147 * set a flag to indicate that a full recalculation is
18148 * needed on the next commit.
18150 mode
->private_flags
= I915_MODE_FLAG_INHERITED
;
18152 intel_crtc_compute_pixel_rate(crtc_state
);
18154 intel_crtc_update_active_timings(crtc_state
);
18156 intel_crtc_copy_hw_to_uapi_state(crtc_state
);
18159 for_each_intel_plane_on_crtc(&dev_priv
->drm
, crtc
, plane
) {
18160 const struct intel_plane_state
*plane_state
=
18161 to_intel_plane_state(plane
->base
.state
);
18164 * FIXME don't have the fb yet, so can't
18165 * use intel_plane_data_rate() :(
18167 if (plane_state
->uapi
.visible
)
18168 crtc_state
->data_rate
[plane
->id
] =
18169 4 * crtc_state
->pixel_rate
;
18171 * FIXME don't have the fb yet, so can't
18172 * use plane->min_cdclk() :(
18174 if (plane_state
->uapi
.visible
&& plane
->min_cdclk
) {
18175 if (crtc_state
->double_wide
||
18176 INTEL_GEN(dev_priv
) >= 10 || IS_GEMINILAKE(dev_priv
))
18177 crtc_state
->min_cdclk
[plane
->id
] =
18178 DIV_ROUND_UP(crtc_state
->pixel_rate
, 2);
18180 crtc_state
->min_cdclk
[plane
->id
] =
18181 crtc_state
->pixel_rate
;
18183 DRM_DEBUG_KMS("[PLANE:%d:%s] min_cdclk %d kHz\n",
18184 plane
->base
.base
.id
, plane
->base
.name
,
18185 crtc_state
->min_cdclk
[plane
->id
]);
18188 if (crtc_state
->hw
.active
) {
18189 min_cdclk
= intel_crtc_compute_min_cdclk(crtc_state
);
18190 if (WARN_ON(min_cdclk
< 0))
18194 dev_priv
->min_cdclk
[crtc
->pipe
] = min_cdclk
;
18195 dev_priv
->min_voltage_level
[crtc
->pipe
] =
18196 crtc_state
->min_voltage_level
;
18198 intel_bw_crtc_update(bw_state
, crtc_state
);
18200 intel_pipe_config_sanity_check(dev_priv
, crtc_state
);
18205 get_encoder_power_domains(struct drm_i915_private
*dev_priv
)
18207 struct intel_encoder
*encoder
;
18209 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
18210 struct intel_crtc_state
*crtc_state
;
18212 if (!encoder
->get_power_domains
)
18216 * MST-primary and inactive encoders don't have a crtc state
18217 * and neither of these require any power domain references.
18219 if (!encoder
->base
.crtc
)
18222 crtc_state
= to_intel_crtc_state(encoder
->base
.crtc
->state
);
18223 encoder
->get_power_domains(encoder
, crtc_state
);
18227 static void intel_early_display_was(struct drm_i915_private
*dev_priv
)
18230 * Display WA #1185 WaDisableDARBFClkGating:cnl,glk,icl,ehl,tgl
18231 * Also known as Wa_14010480278.
18233 if (IS_GEN_RANGE(dev_priv
, 10, 12) || IS_GEMINILAKE(dev_priv
))
18234 I915_WRITE(GEN9_CLKGATE_DIS_0
, I915_READ(GEN9_CLKGATE_DIS_0
) |
18237 if (IS_HASWELL(dev_priv
)) {
18239 * WaRsPkgCStateDisplayPMReq:hsw
18240 * System hang if this isn't done before disabling all planes!
18242 I915_WRITE(CHICKEN_PAR1_1
,
18243 I915_READ(CHICKEN_PAR1_1
) | FORCE_ARB_IDLE_PLANES
);
18247 static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private
*dev_priv
,
18248 enum port port
, i915_reg_t hdmi_reg
)
18250 u32 val
= I915_READ(hdmi_reg
);
18252 if (val
& SDVO_ENABLE
||
18253 (val
& SDVO_PIPE_SEL_MASK
) == SDVO_PIPE_SEL(PIPE_A
))
18256 DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n",
18259 val
&= ~SDVO_PIPE_SEL_MASK
;
18260 val
|= SDVO_PIPE_SEL(PIPE_A
);
18262 I915_WRITE(hdmi_reg
, val
);
18265 static void ibx_sanitize_pch_dp_port(struct drm_i915_private
*dev_priv
,
18266 enum port port
, i915_reg_t dp_reg
)
18268 u32 val
= I915_READ(dp_reg
);
18270 if (val
& DP_PORT_EN
||
18271 (val
& DP_PIPE_SEL_MASK
) == DP_PIPE_SEL(PIPE_A
))
18274 DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n",
18277 val
&= ~DP_PIPE_SEL_MASK
;
18278 val
|= DP_PIPE_SEL(PIPE_A
);
18280 I915_WRITE(dp_reg
, val
);
18283 static void ibx_sanitize_pch_ports(struct drm_i915_private
*dev_priv
)
18286 * The BIOS may select transcoder B on some of the PCH
18287 * ports even it doesn't enable the port. This would trip
18288 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
18289 * Sanitize the transcoder select bits to prevent that. We
18290 * assume that the BIOS never actually enabled the port,
18291 * because if it did we'd actually have to toggle the port
18292 * on and back off to make the transcoder A select stick
18293 * (see. intel_dp_link_down(), intel_disable_hdmi(),
18294 * intel_disable_sdvo()).
18296 ibx_sanitize_pch_dp_port(dev_priv
, PORT_B
, PCH_DP_B
);
18297 ibx_sanitize_pch_dp_port(dev_priv
, PORT_C
, PCH_DP_C
);
18298 ibx_sanitize_pch_dp_port(dev_priv
, PORT_D
, PCH_DP_D
);
18300 /* PCH SDVOB multiplex with HDMIB */
18301 ibx_sanitize_pch_hdmi_port(dev_priv
, PORT_B
, PCH_HDMIB
);
18302 ibx_sanitize_pch_hdmi_port(dev_priv
, PORT_C
, PCH_HDMIC
);
18303 ibx_sanitize_pch_hdmi_port(dev_priv
, PORT_D
, PCH_HDMID
);
18306 /* Scan out the current hw modeset state,
18307 * and sanitizes it to the current state
18310 intel_modeset_setup_hw_state(struct drm_device
*dev
,
18311 struct drm_modeset_acquire_ctx
*ctx
)
18313 struct drm_i915_private
*dev_priv
= to_i915(dev
);
18314 struct intel_encoder
*encoder
;
18315 struct intel_crtc
*crtc
;
18316 intel_wakeref_t wakeref
;
18319 wakeref
= intel_display_power_get(dev_priv
, POWER_DOMAIN_INIT
);
18321 intel_early_display_was(dev_priv
);
18322 intel_modeset_readout_hw_state(dev
);
18324 /* HW state is read out, now we need to sanitize this mess. */
18326 /* Sanitize the TypeC port mode upfront, encoders depend on this */
18327 for_each_intel_encoder(dev
, encoder
) {
18328 enum phy phy
= intel_port_to_phy(dev_priv
, encoder
->port
);
18330 /* We need to sanitize only the MST primary port. */
18331 if (encoder
->type
!= INTEL_OUTPUT_DP_MST
&&
18332 intel_phy_is_tc(dev_priv
, phy
))
18333 intel_tc_port_sanitize(enc_to_dig_port(encoder
));
18336 get_encoder_power_domains(dev_priv
);
18338 if (HAS_PCH_IBX(dev_priv
))
18339 ibx_sanitize_pch_ports(dev_priv
);
18342 * intel_sanitize_plane_mapping() may need to do vblank
18343 * waits, so we need vblank interrupts restored beforehand.
18345 for_each_intel_crtc(&dev_priv
->drm
, crtc
) {
18346 struct intel_crtc_state
*crtc_state
=
18347 to_intel_crtc_state(crtc
->base
.state
);
18349 drm_crtc_vblank_reset(&crtc
->base
);
18351 if (crtc_state
->hw
.active
)
18352 intel_crtc_vblank_on(crtc_state
);
18355 intel_sanitize_plane_mapping(dev_priv
);
18357 for_each_intel_encoder(dev
, encoder
)
18358 intel_sanitize_encoder(encoder
);
18360 for_each_intel_crtc(&dev_priv
->drm
, crtc
) {
18361 struct intel_crtc_state
*crtc_state
=
18362 to_intel_crtc_state(crtc
->base
.state
);
18364 intel_sanitize_crtc(crtc
, ctx
);
18365 intel_dump_pipe_config(crtc_state
, NULL
, "[setup_hw_state]");
18368 intel_modeset_update_connector_atomic_state(dev
);
18370 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
18371 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
18373 if (!pll
->on
|| pll
->active_mask
)
18376 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
18379 pll
->info
->funcs
->disable(dev_priv
, pll
);
18383 if (IS_G4X(dev_priv
)) {
18384 g4x_wm_get_hw_state(dev_priv
);
18385 g4x_wm_sanitize(dev_priv
);
18386 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
18387 vlv_wm_get_hw_state(dev_priv
);
18388 vlv_wm_sanitize(dev_priv
);
18389 } else if (INTEL_GEN(dev_priv
) >= 9) {
18390 skl_wm_get_hw_state(dev_priv
);
18391 } else if (HAS_PCH_SPLIT(dev_priv
)) {
18392 ilk_wm_get_hw_state(dev_priv
);
18395 for_each_intel_crtc(dev
, crtc
) {
18396 struct intel_crtc_state
*crtc_state
=
18397 to_intel_crtc_state(crtc
->base
.state
);
18400 put_domains
= modeset_get_crtc_power_domains(crtc_state
);
18401 if (WARN_ON(put_domains
))
18402 modeset_put_power_domains(dev_priv
, put_domains
);
18405 intel_display_power_put(dev_priv
, POWER_DOMAIN_INIT
, wakeref
);
18408 void intel_display_resume(struct drm_device
*dev
)
18410 struct drm_i915_private
*dev_priv
= to_i915(dev
);
18411 struct drm_atomic_state
*state
= dev_priv
->modeset_restore_state
;
18412 struct drm_modeset_acquire_ctx ctx
;
18415 dev_priv
->modeset_restore_state
= NULL
;
18417 state
->acquire_ctx
= &ctx
;
18419 drm_modeset_acquire_init(&ctx
, 0);
18422 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
18423 if (ret
!= -EDEADLK
)
18426 drm_modeset_backoff(&ctx
);
18430 ret
= __intel_display_resume(dev
, state
, &ctx
);
18432 intel_enable_ipc(dev_priv
);
18433 drm_modeset_drop_locks(&ctx
);
18434 drm_modeset_acquire_fini(&ctx
);
18437 DRM_ERROR("Restoring old state failed with %i\n", ret
);
18439 drm_atomic_state_put(state
);
18442 static void intel_hpd_poll_fini(struct drm_i915_private
*i915
)
18444 struct intel_connector
*connector
;
18445 struct drm_connector_list_iter conn_iter
;
18447 /* Kill all the work that may have been queued by hpd. */
18448 drm_connector_list_iter_begin(&i915
->drm
, &conn_iter
);
18449 for_each_intel_connector_iter(connector
, &conn_iter
) {
18450 if (connector
->modeset_retry_work
.func
)
18451 cancel_work_sync(&connector
->modeset_retry_work
);
18452 if (connector
->hdcp
.shim
) {
18453 cancel_delayed_work_sync(&connector
->hdcp
.check_work
);
18454 cancel_work_sync(&connector
->hdcp
.prop_work
);
18457 drm_connector_list_iter_end(&conn_iter
);
18460 void intel_modeset_driver_remove(struct drm_i915_private
*i915
)
18462 flush_workqueue(i915
->flip_wq
);
18463 flush_workqueue(i915
->modeset_wq
);
18465 flush_work(&i915
->atomic_helper
.free_work
);
18466 WARN_ON(!llist_empty(&i915
->atomic_helper
.free_list
));
18469 * Interrupts and polling as the first thing to avoid creating havoc.
18470 * Too much stuff here (turning of connectors, ...) would
18471 * experience fancy races otherwise.
18473 intel_irq_uninstall(i915
);
18476 * Due to the hpd irq storm handling the hotplug work can re-arm the
18477 * poll handlers. Hence disable polling after hpd handling is shut down.
18479 intel_hpd_poll_fini(i915
);
18482 * MST topology needs to be suspended so we don't have any calls to
18483 * fbdev after it's finalized. MST will be destroyed later as part of
18484 * drm_mode_config_cleanup()
18486 intel_dp_mst_suspend(i915
);
18488 /* poll work can call into fbdev, hence clean that up afterwards */
18489 intel_fbdev_fini(i915
);
18491 intel_unregister_dsm_handler();
18493 intel_fbc_global_disable(i915
);
18495 /* flush any delayed tasks or pending work */
18496 flush_scheduled_work();
18498 intel_hdcp_component_fini(i915
);
18500 drm_mode_config_cleanup(&i915
->drm
);
18502 intel_overlay_cleanup(i915
);
18504 intel_gmbus_teardown(i915
);
18506 intel_bw_cleanup(i915
);
18508 destroy_workqueue(i915
->flip_wq
);
18509 destroy_workqueue(i915
->modeset_wq
);
18511 intel_fbc_cleanup_cfb(i915
);
18514 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
18516 struct intel_display_error_state
{
18518 u32 power_well_driver
;
18520 struct intel_cursor_error_state
{
18525 } cursor
[I915_MAX_PIPES
];
18527 struct intel_pipe_error_state
{
18528 bool power_domain_on
;
18531 } pipe
[I915_MAX_PIPES
];
18533 struct intel_plane_error_state
{
18541 } plane
[I915_MAX_PIPES
];
18543 struct intel_transcoder_error_state
{
18545 bool power_domain_on
;
18546 enum transcoder cpu_transcoder
;
18559 struct intel_display_error_state
*
18560 intel_display_capture_error_state(struct drm_i915_private
*dev_priv
)
18562 struct intel_display_error_state
*error
;
18563 int transcoders
[] = {
18572 BUILD_BUG_ON(ARRAY_SIZE(transcoders
) != ARRAY_SIZE(error
->transcoder
));
18574 if (!HAS_DISPLAY(dev_priv
) || !INTEL_DISPLAY_ENABLED(dev_priv
))
18577 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
18581 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
18582 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_CTL2
);
18584 for_each_pipe(dev_priv
, i
) {
18585 error
->pipe
[i
].power_domain_on
=
18586 __intel_display_power_is_enabled(dev_priv
,
18587 POWER_DOMAIN_PIPE(i
));
18588 if (!error
->pipe
[i
].power_domain_on
)
18591 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
18592 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
18593 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
18595 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
18596 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
18597 if (INTEL_GEN(dev_priv
) <= 3) {
18598 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
18599 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
18601 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
18602 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
18603 if (INTEL_GEN(dev_priv
) >= 4) {
18604 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
18605 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
18608 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
18610 if (HAS_GMCH(dev_priv
))
18611 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
18614 for (i
= 0; i
< ARRAY_SIZE(error
->transcoder
); i
++) {
18615 enum transcoder cpu_transcoder
= transcoders
[i
];
18617 if (!INTEL_INFO(dev_priv
)->trans_offsets
[cpu_transcoder
])
18620 error
->transcoder
[i
].available
= true;
18621 error
->transcoder
[i
].power_domain_on
=
18622 __intel_display_power_is_enabled(dev_priv
,
18623 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
18624 if (!error
->transcoder
[i
].power_domain_on
)
18627 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
18629 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
18630 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
18631 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
18632 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
18633 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
18634 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
18635 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
18641 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
18644 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
18645 struct intel_display_error_state
*error
)
18647 struct drm_i915_private
*dev_priv
= m
->i915
;
18653 err_printf(m
, "Num Pipes: %d\n", INTEL_NUM_PIPES(dev_priv
));
18654 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
18655 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
18656 error
->power_well_driver
);
18657 for_each_pipe(dev_priv
, i
) {
18658 err_printf(m
, "Pipe [%d]:\n", i
);
18659 err_printf(m
, " Power: %s\n",
18660 onoff(error
->pipe
[i
].power_domain_on
));
18661 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
18662 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
18664 err_printf(m
, "Plane [%d]:\n", i
);
18665 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
18666 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
18667 if (INTEL_GEN(dev_priv
) <= 3) {
18668 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
18669 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
18671 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
18672 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
18673 if (INTEL_GEN(dev_priv
) >= 4) {
18674 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
18675 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
18678 err_printf(m
, "Cursor [%d]:\n", i
);
18679 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
18680 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
18681 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
18684 for (i
= 0; i
< ARRAY_SIZE(error
->transcoder
); i
++) {
18685 if (!error
->transcoder
[i
].available
)
18688 err_printf(m
, "CPU transcoder: %s\n",
18689 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
18690 err_printf(m
, " Power: %s\n",
18691 onoff(error
->transcoder
[i
].power_domain_on
));
18692 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
18693 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
18694 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
18695 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
18696 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
18697 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
18698 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);