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/dmi.h>
28 #include <linux/module.h>
29 #include <linux/input.h>
30 #include <linux/i2c.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/vgaarb.h>
34 #include <drm/drm_edid.h>
36 #include "intel_drv.h"
37 #include <drm/i915_drm.h>
39 #include "intel_dsi.h"
40 #include "i915_trace.h"
41 #include <drm/drm_atomic.h>
42 #include <drm/drm_atomic_helper.h>
43 #include <drm/drm_dp_helper.h>
44 #include <drm/drm_crtc_helper.h>
45 #include <drm/drm_plane_helper.h>
46 #include <drm/drm_rect.h>
47 #include <linux/dma_remapping.h>
48 #include <linux/reservation.h>
49 #include <linux/dma-buf.h>
51 /* Primary plane formats for gen <= 3 */
52 static const uint32_t i8xx_primary_formats
[] = {
59 /* Primary plane formats for gen >= 4 */
60 static const uint32_t i965_primary_formats
[] = {
65 DRM_FORMAT_XRGB2101010
,
66 DRM_FORMAT_XBGR2101010
,
69 static const uint32_t skl_primary_formats
[] = {
76 DRM_FORMAT_XRGB2101010
,
77 DRM_FORMAT_XBGR2101010
,
85 static const uint32_t intel_cursor_formats
[] = {
89 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
90 struct intel_crtc_state
*pipe_config
);
91 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
92 struct intel_crtc_state
*pipe_config
);
94 static int intel_framebuffer_init(struct drm_device
*dev
,
95 struct intel_framebuffer
*ifb
,
96 struct drm_mode_fb_cmd2
*mode_cmd
,
97 struct drm_i915_gem_object
*obj
);
98 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
);
99 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
);
100 static void intel_set_pipe_src_size(struct intel_crtc
*intel_crtc
);
101 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
102 struct intel_link_m_n
*m_n
,
103 struct intel_link_m_n
*m2_n2
);
104 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
);
105 static void haswell_set_pipeconf(struct drm_crtc
*crtc
);
106 static void haswell_set_pipemisc(struct drm_crtc
*crtc
);
107 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
108 const struct intel_crtc_state
*pipe_config
);
109 static void chv_prepare_pll(struct intel_crtc
*crtc
,
110 const struct intel_crtc_state
*pipe_config
);
111 static void skl_init_scalers(struct drm_device
*dev
, struct intel_crtc
*intel_crtc
,
112 struct intel_crtc_state
*crtc_state
);
113 static void skylake_pfit_enable(struct intel_crtc
*crtc
);
114 static void ironlake_pfit_disable(struct intel_crtc
*crtc
, bool force
);
115 static void ironlake_pfit_enable(struct intel_crtc
*crtc
);
116 static void intel_modeset_setup_hw_state(struct drm_device
*dev
);
117 static void intel_pre_disable_primary_noatomic(struct drm_crtc
*crtc
);
118 static int ilk_max_pixel_rate(struct drm_atomic_state
*state
);
119 static void intel_modeset_verify_crtc(struct drm_crtc
*crtc
,
120 struct drm_crtc_state
*old_state
,
121 struct drm_crtc_state
*new_state
);
126 } dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
130 int p2_slow
, p2_fast
;
134 /* returns HPLL frequency in kHz */
135 static int valleyview_get_vco(struct drm_i915_private
*dev_priv
)
137 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
139 /* Obtain SKU information */
140 mutex_lock(&dev_priv
->sb_lock
);
141 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
142 CCK_FUSE_HPLL_FREQ_MASK
;
143 mutex_unlock(&dev_priv
->sb_lock
);
145 return vco_freq
[hpll_freq
] * 1000;
148 int vlv_get_cck_clock(struct drm_i915_private
*dev_priv
,
149 const char *name
, u32 reg
, int ref_freq
)
154 mutex_lock(&dev_priv
->sb_lock
);
155 val
= vlv_cck_read(dev_priv
, reg
);
156 mutex_unlock(&dev_priv
->sb_lock
);
158 divider
= val
& CCK_FREQUENCY_VALUES
;
160 WARN((val
& CCK_FREQUENCY_STATUS
) !=
161 (divider
<< CCK_FREQUENCY_STATUS_SHIFT
),
162 "%s change in progress\n", name
);
164 return DIV_ROUND_CLOSEST(ref_freq
<< 1, divider
+ 1);
167 static int vlv_get_cck_clock_hpll(struct drm_i915_private
*dev_priv
,
168 const char *name
, u32 reg
)
170 if (dev_priv
->hpll_freq
== 0)
171 dev_priv
->hpll_freq
= valleyview_get_vco(dev_priv
);
173 return vlv_get_cck_clock(dev_priv
, name
, reg
,
174 dev_priv
->hpll_freq
);
178 intel_pch_rawclk(struct drm_i915_private
*dev_priv
)
180 return (I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
) * 1000;
184 intel_vlv_hrawclk(struct drm_i915_private
*dev_priv
)
186 /* RAWCLK_FREQ_VLV register updated from power well code */
187 return vlv_get_cck_clock_hpll(dev_priv
, "hrawclk",
188 CCK_DISPLAY_REF_CLOCK_CONTROL
);
192 intel_g4x_hrawclk(struct drm_i915_private
*dev_priv
)
196 /* hrawclock is 1/4 the FSB frequency */
197 clkcfg
= I915_READ(CLKCFG
);
198 switch (clkcfg
& CLKCFG_FSB_MASK
) {
207 case CLKCFG_FSB_1067
:
209 case CLKCFG_FSB_1333
:
211 /* these two are just a guess; one of them might be right */
212 case CLKCFG_FSB_1600
:
213 case CLKCFG_FSB_1600_ALT
:
220 void intel_update_rawclk(struct drm_i915_private
*dev_priv
)
222 if (HAS_PCH_SPLIT(dev_priv
))
223 dev_priv
->rawclk_freq
= intel_pch_rawclk(dev_priv
);
224 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
225 dev_priv
->rawclk_freq
= intel_vlv_hrawclk(dev_priv
);
226 else if (IS_G4X(dev_priv
) || IS_PINEVIEW(dev_priv
))
227 dev_priv
->rawclk_freq
= intel_g4x_hrawclk(dev_priv
);
229 return; /* no rawclk on other platforms, or no need to know it */
231 DRM_DEBUG_DRIVER("rawclk rate: %d kHz\n", dev_priv
->rawclk_freq
);
234 static void intel_update_czclk(struct drm_i915_private
*dev_priv
)
236 if (!(IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)))
239 dev_priv
->czclk_freq
= vlv_get_cck_clock_hpll(dev_priv
, "czclk",
240 CCK_CZ_CLOCK_CONTROL
);
242 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv
->czclk_freq
);
245 static inline u32
/* units of 100MHz */
246 intel_fdi_link_freq(struct drm_i915_private
*dev_priv
,
247 const struct intel_crtc_state
*pipe_config
)
249 if (HAS_DDI(dev_priv
))
250 return pipe_config
->port_clock
; /* SPLL */
251 else if (IS_GEN5(dev_priv
))
252 return ((I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2) * 10000;
257 static const struct intel_limit intel_limits_i8xx_dac
= {
258 .dot
= { .min
= 25000, .max
= 350000 },
259 .vco
= { .min
= 908000, .max
= 1512000 },
260 .n
= { .min
= 2, .max
= 16 },
261 .m
= { .min
= 96, .max
= 140 },
262 .m1
= { .min
= 18, .max
= 26 },
263 .m2
= { .min
= 6, .max
= 16 },
264 .p
= { .min
= 4, .max
= 128 },
265 .p1
= { .min
= 2, .max
= 33 },
266 .p2
= { .dot_limit
= 165000,
267 .p2_slow
= 4, .p2_fast
= 2 },
270 static const struct intel_limit intel_limits_i8xx_dvo
= {
271 .dot
= { .min
= 25000, .max
= 350000 },
272 .vco
= { .min
= 908000, .max
= 1512000 },
273 .n
= { .min
= 2, .max
= 16 },
274 .m
= { .min
= 96, .max
= 140 },
275 .m1
= { .min
= 18, .max
= 26 },
276 .m2
= { .min
= 6, .max
= 16 },
277 .p
= { .min
= 4, .max
= 128 },
278 .p1
= { .min
= 2, .max
= 33 },
279 .p2
= { .dot_limit
= 165000,
280 .p2_slow
= 4, .p2_fast
= 4 },
283 static const struct intel_limit intel_limits_i8xx_lvds
= {
284 .dot
= { .min
= 25000, .max
= 350000 },
285 .vco
= { .min
= 908000, .max
= 1512000 },
286 .n
= { .min
= 2, .max
= 16 },
287 .m
= { .min
= 96, .max
= 140 },
288 .m1
= { .min
= 18, .max
= 26 },
289 .m2
= { .min
= 6, .max
= 16 },
290 .p
= { .min
= 4, .max
= 128 },
291 .p1
= { .min
= 1, .max
= 6 },
292 .p2
= { .dot_limit
= 165000,
293 .p2_slow
= 14, .p2_fast
= 7 },
296 static const struct intel_limit intel_limits_i9xx_sdvo
= {
297 .dot
= { .min
= 20000, .max
= 400000 },
298 .vco
= { .min
= 1400000, .max
= 2800000 },
299 .n
= { .min
= 1, .max
= 6 },
300 .m
= { .min
= 70, .max
= 120 },
301 .m1
= { .min
= 8, .max
= 18 },
302 .m2
= { .min
= 3, .max
= 7 },
303 .p
= { .min
= 5, .max
= 80 },
304 .p1
= { .min
= 1, .max
= 8 },
305 .p2
= { .dot_limit
= 200000,
306 .p2_slow
= 10, .p2_fast
= 5 },
309 static const struct intel_limit intel_limits_i9xx_lvds
= {
310 .dot
= { .min
= 20000, .max
= 400000 },
311 .vco
= { .min
= 1400000, .max
= 2800000 },
312 .n
= { .min
= 1, .max
= 6 },
313 .m
= { .min
= 70, .max
= 120 },
314 .m1
= { .min
= 8, .max
= 18 },
315 .m2
= { .min
= 3, .max
= 7 },
316 .p
= { .min
= 7, .max
= 98 },
317 .p1
= { .min
= 1, .max
= 8 },
318 .p2
= { .dot_limit
= 112000,
319 .p2_slow
= 14, .p2_fast
= 7 },
323 static const struct intel_limit intel_limits_g4x_sdvo
= {
324 .dot
= { .min
= 25000, .max
= 270000 },
325 .vco
= { .min
= 1750000, .max
= 3500000},
326 .n
= { .min
= 1, .max
= 4 },
327 .m
= { .min
= 104, .max
= 138 },
328 .m1
= { .min
= 17, .max
= 23 },
329 .m2
= { .min
= 5, .max
= 11 },
330 .p
= { .min
= 10, .max
= 30 },
331 .p1
= { .min
= 1, .max
= 3},
332 .p2
= { .dot_limit
= 270000,
338 static const struct intel_limit intel_limits_g4x_hdmi
= {
339 .dot
= { .min
= 22000, .max
= 400000 },
340 .vco
= { .min
= 1750000, .max
= 3500000},
341 .n
= { .min
= 1, .max
= 4 },
342 .m
= { .min
= 104, .max
= 138 },
343 .m1
= { .min
= 16, .max
= 23 },
344 .m2
= { .min
= 5, .max
= 11 },
345 .p
= { .min
= 5, .max
= 80 },
346 .p1
= { .min
= 1, .max
= 8},
347 .p2
= { .dot_limit
= 165000,
348 .p2_slow
= 10, .p2_fast
= 5 },
351 static const struct intel_limit intel_limits_g4x_single_channel_lvds
= {
352 .dot
= { .min
= 20000, .max
= 115000 },
353 .vco
= { .min
= 1750000, .max
= 3500000 },
354 .n
= { .min
= 1, .max
= 3 },
355 .m
= { .min
= 104, .max
= 138 },
356 .m1
= { .min
= 17, .max
= 23 },
357 .m2
= { .min
= 5, .max
= 11 },
358 .p
= { .min
= 28, .max
= 112 },
359 .p1
= { .min
= 2, .max
= 8 },
360 .p2
= { .dot_limit
= 0,
361 .p2_slow
= 14, .p2_fast
= 14
365 static const struct intel_limit intel_limits_g4x_dual_channel_lvds
= {
366 .dot
= { .min
= 80000, .max
= 224000 },
367 .vco
= { .min
= 1750000, .max
= 3500000 },
368 .n
= { .min
= 1, .max
= 3 },
369 .m
= { .min
= 104, .max
= 138 },
370 .m1
= { .min
= 17, .max
= 23 },
371 .m2
= { .min
= 5, .max
= 11 },
372 .p
= { .min
= 14, .max
= 42 },
373 .p1
= { .min
= 2, .max
= 6 },
374 .p2
= { .dot_limit
= 0,
375 .p2_slow
= 7, .p2_fast
= 7
379 static const struct intel_limit intel_limits_pineview_sdvo
= {
380 .dot
= { .min
= 20000, .max
= 400000},
381 .vco
= { .min
= 1700000, .max
= 3500000 },
382 /* Pineview's Ncounter is a ring counter */
383 .n
= { .min
= 3, .max
= 6 },
384 .m
= { .min
= 2, .max
= 256 },
385 /* Pineview only has one combined m divider, which we treat as m2. */
386 .m1
= { .min
= 0, .max
= 0 },
387 .m2
= { .min
= 0, .max
= 254 },
388 .p
= { .min
= 5, .max
= 80 },
389 .p1
= { .min
= 1, .max
= 8 },
390 .p2
= { .dot_limit
= 200000,
391 .p2_slow
= 10, .p2_fast
= 5 },
394 static const struct intel_limit intel_limits_pineview_lvds
= {
395 .dot
= { .min
= 20000, .max
= 400000 },
396 .vco
= { .min
= 1700000, .max
= 3500000 },
397 .n
= { .min
= 3, .max
= 6 },
398 .m
= { .min
= 2, .max
= 256 },
399 .m1
= { .min
= 0, .max
= 0 },
400 .m2
= { .min
= 0, .max
= 254 },
401 .p
= { .min
= 7, .max
= 112 },
402 .p1
= { .min
= 1, .max
= 8 },
403 .p2
= { .dot_limit
= 112000,
404 .p2_slow
= 14, .p2_fast
= 14 },
407 /* Ironlake / Sandybridge
409 * We calculate clock using (register_value + 2) for N/M1/M2, so here
410 * the range value for them is (actual_value - 2).
412 static const struct intel_limit intel_limits_ironlake_dac
= {
413 .dot
= { .min
= 25000, .max
= 350000 },
414 .vco
= { .min
= 1760000, .max
= 3510000 },
415 .n
= { .min
= 1, .max
= 5 },
416 .m
= { .min
= 79, .max
= 127 },
417 .m1
= { .min
= 12, .max
= 22 },
418 .m2
= { .min
= 5, .max
= 9 },
419 .p
= { .min
= 5, .max
= 80 },
420 .p1
= { .min
= 1, .max
= 8 },
421 .p2
= { .dot_limit
= 225000,
422 .p2_slow
= 10, .p2_fast
= 5 },
425 static const struct intel_limit intel_limits_ironlake_single_lvds
= {
426 .dot
= { .min
= 25000, .max
= 350000 },
427 .vco
= { .min
= 1760000, .max
= 3510000 },
428 .n
= { .min
= 1, .max
= 3 },
429 .m
= { .min
= 79, .max
= 118 },
430 .m1
= { .min
= 12, .max
= 22 },
431 .m2
= { .min
= 5, .max
= 9 },
432 .p
= { .min
= 28, .max
= 112 },
433 .p1
= { .min
= 2, .max
= 8 },
434 .p2
= { .dot_limit
= 225000,
435 .p2_slow
= 14, .p2_fast
= 14 },
438 static const struct intel_limit intel_limits_ironlake_dual_lvds
= {
439 .dot
= { .min
= 25000, .max
= 350000 },
440 .vco
= { .min
= 1760000, .max
= 3510000 },
441 .n
= { .min
= 1, .max
= 3 },
442 .m
= { .min
= 79, .max
= 127 },
443 .m1
= { .min
= 12, .max
= 22 },
444 .m2
= { .min
= 5, .max
= 9 },
445 .p
= { .min
= 14, .max
= 56 },
446 .p1
= { .min
= 2, .max
= 8 },
447 .p2
= { .dot_limit
= 225000,
448 .p2_slow
= 7, .p2_fast
= 7 },
451 /* LVDS 100mhz refclk limits. */
452 static const struct intel_limit intel_limits_ironlake_single_lvds_100m
= {
453 .dot
= { .min
= 25000, .max
= 350000 },
454 .vco
= { .min
= 1760000, .max
= 3510000 },
455 .n
= { .min
= 1, .max
= 2 },
456 .m
= { .min
= 79, .max
= 126 },
457 .m1
= { .min
= 12, .max
= 22 },
458 .m2
= { .min
= 5, .max
= 9 },
459 .p
= { .min
= 28, .max
= 112 },
460 .p1
= { .min
= 2, .max
= 8 },
461 .p2
= { .dot_limit
= 225000,
462 .p2_slow
= 14, .p2_fast
= 14 },
465 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m
= {
466 .dot
= { .min
= 25000, .max
= 350000 },
467 .vco
= { .min
= 1760000, .max
= 3510000 },
468 .n
= { .min
= 1, .max
= 3 },
469 .m
= { .min
= 79, .max
= 126 },
470 .m1
= { .min
= 12, .max
= 22 },
471 .m2
= { .min
= 5, .max
= 9 },
472 .p
= { .min
= 14, .max
= 42 },
473 .p1
= { .min
= 2, .max
= 6 },
474 .p2
= { .dot_limit
= 225000,
475 .p2_slow
= 7, .p2_fast
= 7 },
478 static const struct intel_limit intel_limits_vlv
= {
480 * These are the data rate limits (measured in fast clocks)
481 * since those are the strictest limits we have. The fast
482 * clock and actual rate limits are more relaxed, so checking
483 * them would make no difference.
485 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
486 .vco
= { .min
= 4000000, .max
= 6000000 },
487 .n
= { .min
= 1, .max
= 7 },
488 .m1
= { .min
= 2, .max
= 3 },
489 .m2
= { .min
= 11, .max
= 156 },
490 .p1
= { .min
= 2, .max
= 3 },
491 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
494 static const struct intel_limit intel_limits_chv
= {
496 * These are the data rate limits (measured in fast clocks)
497 * since those are the strictest limits we have. The fast
498 * clock and actual rate limits are more relaxed, so checking
499 * them would make no difference.
501 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
502 .vco
= { .min
= 4800000, .max
= 6480000 },
503 .n
= { .min
= 1, .max
= 1 },
504 .m1
= { .min
= 2, .max
= 2 },
505 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
506 .p1
= { .min
= 2, .max
= 4 },
507 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
510 static const struct intel_limit intel_limits_bxt
= {
511 /* FIXME: find real dot limits */
512 .dot
= { .min
= 0, .max
= INT_MAX
},
513 .vco
= { .min
= 4800000, .max
= 6700000 },
514 .n
= { .min
= 1, .max
= 1 },
515 .m1
= { .min
= 2, .max
= 2 },
516 /* FIXME: find real m2 limits */
517 .m2
= { .min
= 2 << 22, .max
= 255 << 22 },
518 .p1
= { .min
= 2, .max
= 4 },
519 .p2
= { .p2_slow
= 1, .p2_fast
= 20 },
523 needs_modeset(struct drm_crtc_state
*state
)
525 return drm_atomic_crtc_needs_modeset(state
);
529 * Returns whether any output on the specified pipe is of the specified type
531 bool intel_pipe_has_type(struct intel_crtc
*crtc
, enum intel_output_type type
)
533 struct drm_device
*dev
= crtc
->base
.dev
;
534 struct intel_encoder
*encoder
;
536 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
537 if (encoder
->type
== type
)
544 * Returns whether any output on the specified pipe will have the specified
545 * type after a staged modeset is complete, i.e., the same as
546 * intel_pipe_has_type() but looking at encoder->new_crtc instead of
549 static bool intel_pipe_will_have_type(const struct intel_crtc_state
*crtc_state
,
552 struct drm_atomic_state
*state
= crtc_state
->base
.state
;
553 struct drm_connector
*connector
;
554 struct drm_connector_state
*connector_state
;
555 struct intel_encoder
*encoder
;
556 int i
, num_connectors
= 0;
558 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
559 if (connector_state
->crtc
!= crtc_state
->base
.crtc
)
564 encoder
= to_intel_encoder(connector_state
->best_encoder
);
565 if (encoder
->type
== type
)
569 WARN_ON(num_connectors
== 0);
575 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
576 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
577 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
578 * The helpers' return value is the rate of the clock that is fed to the
579 * display engine's pipe which can be the above fast dot clock rate or a
580 * divided-down version of it.
582 /* m1 is reserved as 0 in Pineview, n is a ring counter */
583 static int pnv_calc_dpll_params(int refclk
, struct dpll
*clock
)
585 clock
->m
= clock
->m2
+ 2;
586 clock
->p
= clock
->p1
* clock
->p2
;
587 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
589 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
590 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
595 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
597 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
600 static int i9xx_calc_dpll_params(int refclk
, struct dpll
*clock
)
602 clock
->m
= i9xx_dpll_compute_m(clock
);
603 clock
->p
= clock
->p1
* clock
->p2
;
604 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
606 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
607 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
612 static int vlv_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(refclk
* clock
->m
, clock
->n
);
619 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
621 return clock
->dot
/ 5;
624 int chv_calc_dpll_params(int refclk
, struct dpll
*clock
)
626 clock
->m
= clock
->m1
* clock
->m2
;
627 clock
->p
= clock
->p1
* clock
->p2
;
628 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
630 clock
->vco
= DIV_ROUND_CLOSEST_ULL((uint64_t)refclk
* clock
->m
,
632 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
634 return clock
->dot
/ 5;
637 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
639 * Returns whether the given set of divisors are valid for a given refclk with
640 * the given connectors.
643 static bool intel_PLL_is_valid(struct drm_device
*dev
,
644 const struct intel_limit
*limit
,
645 const struct dpll
*clock
)
647 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
648 INTELPllInvalid("n out of range\n");
649 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
650 INTELPllInvalid("p1 out of range\n");
651 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
652 INTELPllInvalid("m2 out of range\n");
653 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
654 INTELPllInvalid("m1 out of range\n");
656 if (!IS_PINEVIEW(dev
) && !IS_VALLEYVIEW(dev
) &&
657 !IS_CHERRYVIEW(dev
) && !IS_BROXTON(dev
))
658 if (clock
->m1
<= clock
->m2
)
659 INTELPllInvalid("m1 <= m2\n");
661 if (!IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
) && !IS_BROXTON(dev
)) {
662 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
663 INTELPllInvalid("p out of range\n");
664 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
665 INTELPllInvalid("m out of range\n");
668 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
669 INTELPllInvalid("vco out of range\n");
670 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
671 * connector, etc., rather than just a single range.
673 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
674 INTELPllInvalid("dot out of range\n");
680 i9xx_select_p2_div(const struct intel_limit
*limit
,
681 const struct intel_crtc_state
*crtc_state
,
684 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
686 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
688 * For LVDS just rely on its current settings for dual-channel.
689 * We haven't figured out how to reliably set up different
690 * single/dual channel state, if we even can.
692 if (intel_is_dual_link_lvds(dev
))
693 return limit
->p2
.p2_fast
;
695 return limit
->p2
.p2_slow
;
697 if (target
< limit
->p2
.dot_limit
)
698 return limit
->p2
.p2_slow
;
700 return limit
->p2
.p2_fast
;
705 * Returns a set of divisors for the desired target clock with the given
706 * refclk, or FALSE. The returned values represent the clock equation:
707 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
709 * Target and reference clocks are specified in kHz.
711 * If match_clock is provided, then best_clock P divider must match the P
712 * divider from @match_clock used for LVDS downclocking.
715 i9xx_find_best_dpll(const struct intel_limit
*limit
,
716 struct intel_crtc_state
*crtc_state
,
717 int target
, int refclk
, struct dpll
*match_clock
,
718 struct dpll
*best_clock
)
720 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
724 memset(best_clock
, 0, sizeof(*best_clock
));
726 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
728 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
730 for (clock
.m2
= limit
->m2
.min
;
731 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
732 if (clock
.m2
>= clock
.m1
)
734 for (clock
.n
= limit
->n
.min
;
735 clock
.n
<= limit
->n
.max
; clock
.n
++) {
736 for (clock
.p1
= limit
->p1
.min
;
737 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
740 i9xx_calc_dpll_params(refclk
, &clock
);
741 if (!intel_PLL_is_valid(dev
, limit
,
745 clock
.p
!= match_clock
->p
)
748 this_err
= abs(clock
.dot
- target
);
749 if (this_err
< err
) {
758 return (err
!= target
);
762 * Returns a set of divisors for the desired target clock with the given
763 * refclk, or FALSE. The returned values represent the clock equation:
764 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
766 * Target and reference clocks are specified in kHz.
768 * If match_clock is provided, then best_clock P divider must match the P
769 * divider from @match_clock used for LVDS downclocking.
772 pnv_find_best_dpll(const struct intel_limit
*limit
,
773 struct intel_crtc_state
*crtc_state
,
774 int target
, int refclk
, struct dpll
*match_clock
,
775 struct dpll
*best_clock
)
777 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
781 memset(best_clock
, 0, sizeof(*best_clock
));
783 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
785 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
787 for (clock
.m2
= limit
->m2
.min
;
788 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
789 for (clock
.n
= limit
->n
.min
;
790 clock
.n
<= limit
->n
.max
; clock
.n
++) {
791 for (clock
.p1
= limit
->p1
.min
;
792 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
795 pnv_calc_dpll_params(refclk
, &clock
);
796 if (!intel_PLL_is_valid(dev
, limit
,
800 clock
.p
!= match_clock
->p
)
803 this_err
= abs(clock
.dot
- target
);
804 if (this_err
< err
) {
813 return (err
!= target
);
817 * Returns a set of divisors for the desired target clock with the given
818 * refclk, or FALSE. The returned values represent the clock equation:
819 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
821 * Target and reference clocks are specified in kHz.
823 * If match_clock is provided, then best_clock P divider must match the P
824 * divider from @match_clock used for LVDS downclocking.
827 g4x_find_best_dpll(const struct intel_limit
*limit
,
828 struct intel_crtc_state
*crtc_state
,
829 int target
, int refclk
, struct dpll
*match_clock
,
830 struct dpll
*best_clock
)
832 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
836 /* approximately equals target * 0.00585 */
837 int err_most
= (target
>> 8) + (target
>> 9);
839 memset(best_clock
, 0, sizeof(*best_clock
));
841 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
843 max_n
= limit
->n
.max
;
844 /* based on hardware requirement, prefer smaller n to precision */
845 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
846 /* based on hardware requirement, prefere larger m1,m2 */
847 for (clock
.m1
= limit
->m1
.max
;
848 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
849 for (clock
.m2
= limit
->m2
.max
;
850 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
851 for (clock
.p1
= limit
->p1
.max
;
852 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
855 i9xx_calc_dpll_params(refclk
, &clock
);
856 if (!intel_PLL_is_valid(dev
, limit
,
860 this_err
= abs(clock
.dot
- target
);
861 if (this_err
< err_most
) {
875 * Check if the calculated PLL configuration is more optimal compared to the
876 * best configuration and error found so far. Return the calculated error.
878 static bool vlv_PLL_is_optimal(struct drm_device
*dev
, int target_freq
,
879 const struct dpll
*calculated_clock
,
880 const struct dpll
*best_clock
,
881 unsigned int best_error_ppm
,
882 unsigned int *error_ppm
)
885 * For CHV ignore the error and consider only the P value.
886 * Prefer a bigger P value based on HW requirements.
888 if (IS_CHERRYVIEW(dev
)) {
891 return calculated_clock
->p
> best_clock
->p
;
894 if (WARN_ON_ONCE(!target_freq
))
897 *error_ppm
= div_u64(1000000ULL *
898 abs(target_freq
- calculated_clock
->dot
),
901 * Prefer a better P value over a better (smaller) error if the error
902 * is small. Ensure this preference for future configurations too by
903 * setting the error to 0.
905 if (*error_ppm
< 100 && calculated_clock
->p
> best_clock
->p
) {
911 return *error_ppm
+ 10 < best_error_ppm
;
915 * Returns a set of divisors for the desired target clock with the given
916 * refclk, or FALSE. The returned values represent the clock equation:
917 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
920 vlv_find_best_dpll(const struct intel_limit
*limit
,
921 struct intel_crtc_state
*crtc_state
,
922 int target
, int refclk
, struct dpll
*match_clock
,
923 struct dpll
*best_clock
)
925 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
926 struct drm_device
*dev
= crtc
->base
.dev
;
928 unsigned int bestppm
= 1000000;
929 /* min update 19.2 MHz */
930 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
933 target
*= 5; /* fast clock */
935 memset(best_clock
, 0, sizeof(*best_clock
));
937 /* based on hardware requirement, prefer smaller n to precision */
938 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
939 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
940 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
941 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
942 clock
.p
= clock
.p1
* clock
.p2
;
943 /* based on hardware requirement, prefer bigger m1,m2 values */
944 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
947 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
950 vlv_calc_dpll_params(refclk
, &clock
);
952 if (!intel_PLL_is_valid(dev
, limit
,
956 if (!vlv_PLL_is_optimal(dev
, target
,
974 * Returns a set of divisors for the desired target clock with the given
975 * refclk, or FALSE. The returned values represent the clock equation:
976 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
979 chv_find_best_dpll(const struct intel_limit
*limit
,
980 struct intel_crtc_state
*crtc_state
,
981 int target
, int refclk
, struct dpll
*match_clock
,
982 struct dpll
*best_clock
)
984 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
985 struct drm_device
*dev
= crtc
->base
.dev
;
986 unsigned int best_error_ppm
;
991 memset(best_clock
, 0, sizeof(*best_clock
));
992 best_error_ppm
= 1000000;
995 * Based on hardware doc, the n always set to 1, and m1 always
996 * set to 2. If requires to support 200Mhz refclk, we need to
997 * revisit this because n may not 1 anymore.
999 clock
.n
= 1, clock
.m1
= 2;
1000 target
*= 5; /* fast clock */
1002 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
1003 for (clock
.p2
= limit
->p2
.p2_fast
;
1004 clock
.p2
>= limit
->p2
.p2_slow
;
1005 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
1006 unsigned int error_ppm
;
1008 clock
.p
= clock
.p1
* clock
.p2
;
1010 m2
= DIV_ROUND_CLOSEST_ULL(((uint64_t)target
* clock
.p
*
1011 clock
.n
) << 22, refclk
* clock
.m1
);
1013 if (m2
> INT_MAX
/clock
.m1
)
1018 chv_calc_dpll_params(refclk
, &clock
);
1020 if (!intel_PLL_is_valid(dev
, limit
, &clock
))
1023 if (!vlv_PLL_is_optimal(dev
, target
, &clock
, best_clock
,
1024 best_error_ppm
, &error_ppm
))
1027 *best_clock
= clock
;
1028 best_error_ppm
= error_ppm
;
1036 bool bxt_find_best_dpll(struct intel_crtc_state
*crtc_state
, int target_clock
,
1037 struct dpll
*best_clock
)
1039 int refclk
= 100000;
1040 const struct intel_limit
*limit
= &intel_limits_bxt
;
1042 return chv_find_best_dpll(limit
, crtc_state
,
1043 target_clock
, refclk
, NULL
, best_clock
);
1046 bool intel_crtc_active(struct drm_crtc
*crtc
)
1048 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1050 /* Be paranoid as we can arrive here with only partial
1051 * state retrieved from the hardware during setup.
1053 * We can ditch the adjusted_mode.crtc_clock check as soon
1054 * as Haswell has gained clock readout/fastboot support.
1056 * We can ditch the crtc->primary->fb check as soon as we can
1057 * properly reconstruct framebuffers.
1059 * FIXME: The intel_crtc->active here should be switched to
1060 * crtc->state->active once we have proper CRTC states wired up
1063 return intel_crtc
->active
&& crtc
->primary
->state
->fb
&&
1064 intel_crtc
->config
->base
.adjusted_mode
.crtc_clock
;
1067 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
1070 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1071 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1073 return intel_crtc
->config
->cpu_transcoder
;
1076 static bool pipe_dsl_stopped(struct drm_device
*dev
, enum pipe pipe
)
1078 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1079 i915_reg_t reg
= PIPEDSL(pipe
);
1084 line_mask
= DSL_LINEMASK_GEN2
;
1086 line_mask
= DSL_LINEMASK_GEN3
;
1088 line1
= I915_READ(reg
) & line_mask
;
1090 line2
= I915_READ(reg
) & line_mask
;
1092 return line1
== line2
;
1096 * intel_wait_for_pipe_off - wait for pipe to turn off
1097 * @crtc: crtc whose pipe to wait for
1099 * After disabling a pipe, we can't wait for vblank in the usual way,
1100 * spinning on the vblank interrupt status bit, since we won't actually
1101 * see an interrupt when the pipe is disabled.
1103 * On Gen4 and above:
1104 * wait for the pipe register state bit to turn off
1107 * wait for the display line value to settle (it usually
1108 * ends up stopping at the start of the next frame).
1111 static void intel_wait_for_pipe_off(struct intel_crtc
*crtc
)
1113 struct drm_device
*dev
= crtc
->base
.dev
;
1114 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1115 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1116 enum pipe pipe
= crtc
->pipe
;
1118 if (INTEL_INFO(dev
)->gen
>= 4) {
1119 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
1121 /* Wait for the Pipe State to go off */
1122 if (wait_for((I915_READ(reg
) & I965_PIPECONF_ACTIVE
) == 0,
1124 WARN(1, "pipe_off wait timed out\n");
1126 /* Wait for the display line to settle */
1127 if (wait_for(pipe_dsl_stopped(dev
, pipe
), 100))
1128 WARN(1, "pipe_off wait timed out\n");
1132 /* Only for pre-ILK configs */
1133 void assert_pll(struct drm_i915_private
*dev_priv
,
1134 enum pipe pipe
, bool state
)
1139 val
= I915_READ(DPLL(pipe
));
1140 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1141 I915_STATE_WARN(cur_state
!= state
,
1142 "PLL state assertion failure (expected %s, current %s)\n",
1143 onoff(state
), onoff(cur_state
));
1146 /* XXX: the dsi pll is shared between MIPI DSI ports */
1147 void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1152 mutex_lock(&dev_priv
->sb_lock
);
1153 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1154 mutex_unlock(&dev_priv
->sb_lock
);
1156 cur_state
= val
& DSI_PLL_VCO_EN
;
1157 I915_STATE_WARN(cur_state
!= state
,
1158 "DSI PLL state assertion failure (expected %s, current %s)\n",
1159 onoff(state
), onoff(cur_state
));
1162 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1163 enum pipe pipe
, bool state
)
1166 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1169 if (HAS_DDI(dev_priv
)) {
1170 /* DDI does not have a specific FDI_TX register */
1171 u32 val
= I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder
));
1172 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1174 u32 val
= I915_READ(FDI_TX_CTL(pipe
));
1175 cur_state
= !!(val
& FDI_TX_ENABLE
);
1177 I915_STATE_WARN(cur_state
!= state
,
1178 "FDI TX state assertion failure (expected %s, current %s)\n",
1179 onoff(state
), onoff(cur_state
));
1181 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1182 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1184 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1185 enum pipe pipe
, bool state
)
1190 val
= I915_READ(FDI_RX_CTL(pipe
));
1191 cur_state
= !!(val
& FDI_RX_ENABLE
);
1192 I915_STATE_WARN(cur_state
!= state
,
1193 "FDI RX state assertion failure (expected %s, current %s)\n",
1194 onoff(state
), onoff(cur_state
));
1196 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1197 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1199 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1204 /* ILK FDI PLL is always enabled */
1205 if (IS_GEN5(dev_priv
))
1208 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1209 if (HAS_DDI(dev_priv
))
1212 val
= I915_READ(FDI_TX_CTL(pipe
));
1213 I915_STATE_WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1216 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1217 enum pipe pipe
, bool state
)
1222 val
= I915_READ(FDI_RX_CTL(pipe
));
1223 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1224 I915_STATE_WARN(cur_state
!= state
,
1225 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1226 onoff(state
), onoff(cur_state
));
1229 void assert_panel_unlocked(struct drm_i915_private
*dev_priv
,
1232 struct drm_device
*dev
= dev_priv
->dev
;
1235 enum pipe panel_pipe
= PIPE_A
;
1238 if (WARN_ON(HAS_DDI(dev
)))
1241 if (HAS_PCH_SPLIT(dev
)) {
1244 pp_reg
= PCH_PP_CONTROL
;
1245 port_sel
= I915_READ(PCH_PP_ON_DELAYS
) & PANEL_PORT_SELECT_MASK
;
1247 if (port_sel
== PANEL_PORT_SELECT_LVDS
&&
1248 I915_READ(PCH_LVDS
) & LVDS_PIPEB_SELECT
)
1249 panel_pipe
= PIPE_B
;
1250 /* XXX: else fix for eDP */
1251 } else if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
1252 /* presumably write lock depends on pipe, not port select */
1253 pp_reg
= VLV_PIPE_PP_CONTROL(pipe
);
1256 pp_reg
= PP_CONTROL
;
1257 if (I915_READ(LVDS
) & LVDS_PIPEB_SELECT
)
1258 panel_pipe
= PIPE_B
;
1261 val
= I915_READ(pp_reg
);
1262 if (!(val
& PANEL_POWER_ON
) ||
1263 ((val
& PANEL_UNLOCK_MASK
) == PANEL_UNLOCK_REGS
))
1266 I915_STATE_WARN(panel_pipe
== pipe
&& locked
,
1267 "panel assertion failure, pipe %c regs locked\n",
1271 static void assert_cursor(struct drm_i915_private
*dev_priv
,
1272 enum pipe pipe
, bool state
)
1274 struct drm_device
*dev
= dev_priv
->dev
;
1277 if (IS_845G(dev
) || IS_I865G(dev
))
1278 cur_state
= I915_READ(CURCNTR(PIPE_A
)) & CURSOR_ENABLE
;
1280 cur_state
= I915_READ(CURCNTR(pipe
)) & CURSOR_MODE
;
1282 I915_STATE_WARN(cur_state
!= state
,
1283 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1284 pipe_name(pipe
), onoff(state
), onoff(cur_state
));
1286 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1287 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1289 void assert_pipe(struct drm_i915_private
*dev_priv
,
1290 enum pipe pipe
, bool state
)
1293 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1295 enum intel_display_power_domain power_domain
;
1297 /* if we need the pipe quirk it must be always on */
1298 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1299 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1302 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
1303 if (intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
1304 u32 val
= I915_READ(PIPECONF(cpu_transcoder
));
1305 cur_state
= !!(val
& PIPECONF_ENABLE
);
1307 intel_display_power_put(dev_priv
, power_domain
);
1312 I915_STATE_WARN(cur_state
!= state
,
1313 "pipe %c assertion failure (expected %s, current %s)\n",
1314 pipe_name(pipe
), onoff(state
), onoff(cur_state
));
1317 static void assert_plane(struct drm_i915_private
*dev_priv
,
1318 enum plane plane
, bool state
)
1323 val
= I915_READ(DSPCNTR(plane
));
1324 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1325 I915_STATE_WARN(cur_state
!= state
,
1326 "plane %c assertion failure (expected %s, current %s)\n",
1327 plane_name(plane
), onoff(state
), onoff(cur_state
));
1330 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1331 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1333 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1336 struct drm_device
*dev
= dev_priv
->dev
;
1339 /* Primary planes are fixed to pipes on gen4+ */
1340 if (INTEL_INFO(dev
)->gen
>= 4) {
1341 u32 val
= I915_READ(DSPCNTR(pipe
));
1342 I915_STATE_WARN(val
& DISPLAY_PLANE_ENABLE
,
1343 "plane %c assertion failure, should be disabled but not\n",
1348 /* Need to check both planes against the pipe */
1349 for_each_pipe(dev_priv
, i
) {
1350 u32 val
= I915_READ(DSPCNTR(i
));
1351 enum pipe cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1352 DISPPLANE_SEL_PIPE_SHIFT
;
1353 I915_STATE_WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1354 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1355 plane_name(i
), pipe_name(pipe
));
1359 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1362 struct drm_device
*dev
= dev_priv
->dev
;
1365 if (INTEL_INFO(dev
)->gen
>= 9) {
1366 for_each_sprite(dev_priv
, pipe
, sprite
) {
1367 u32 val
= I915_READ(PLANE_CTL(pipe
, sprite
));
1368 I915_STATE_WARN(val
& PLANE_CTL_ENABLE
,
1369 "plane %d assertion failure, should be off on pipe %c but is still active\n",
1370 sprite
, pipe_name(pipe
));
1372 } else if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
1373 for_each_sprite(dev_priv
, pipe
, sprite
) {
1374 u32 val
= I915_READ(SPCNTR(pipe
, sprite
));
1375 I915_STATE_WARN(val
& SP_ENABLE
,
1376 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1377 sprite_name(pipe
, sprite
), pipe_name(pipe
));
1379 } else if (INTEL_INFO(dev
)->gen
>= 7) {
1380 u32 val
= I915_READ(SPRCTL(pipe
));
1381 I915_STATE_WARN(val
& SPRITE_ENABLE
,
1382 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1383 plane_name(pipe
), pipe_name(pipe
));
1384 } else if (INTEL_INFO(dev
)->gen
>= 5) {
1385 u32 val
= I915_READ(DVSCNTR(pipe
));
1386 I915_STATE_WARN(val
& DVS_ENABLE
,
1387 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1388 plane_name(pipe
), pipe_name(pipe
));
1392 static void assert_vblank_disabled(struct drm_crtc
*crtc
)
1394 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc
) == 0))
1395 drm_crtc_vblank_put(crtc
);
1398 void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1404 val
= I915_READ(PCH_TRANSCONF(pipe
));
1405 enabled
= !!(val
& TRANS_ENABLE
);
1406 I915_STATE_WARN(enabled
,
1407 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1411 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1412 enum pipe pipe
, u32 port_sel
, u32 val
)
1414 if ((val
& DP_PORT_EN
) == 0)
1417 if (HAS_PCH_CPT(dev_priv
)) {
1418 u32 trans_dp_ctl
= I915_READ(TRANS_DP_CTL(pipe
));
1419 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1421 } else if (IS_CHERRYVIEW(dev_priv
)) {
1422 if ((val
& DP_PIPE_MASK_CHV
) != DP_PIPE_SELECT_CHV(pipe
))
1425 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1431 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1432 enum pipe pipe
, u32 val
)
1434 if ((val
& SDVO_ENABLE
) == 0)
1437 if (HAS_PCH_CPT(dev_priv
)) {
1438 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1440 } else if (IS_CHERRYVIEW(dev_priv
)) {
1441 if ((val
& SDVO_PIPE_SEL_MASK_CHV
) != SDVO_PIPE_SEL_CHV(pipe
))
1444 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1450 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1451 enum pipe pipe
, u32 val
)
1453 if ((val
& LVDS_PORT_EN
) == 0)
1456 if (HAS_PCH_CPT(dev_priv
)) {
1457 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1460 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1466 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1467 enum pipe pipe
, u32 val
)
1469 if ((val
& ADPA_DAC_ENABLE
) == 0)
1471 if (HAS_PCH_CPT(dev_priv
)) {
1472 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1475 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1481 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1482 enum pipe pipe
, i915_reg_t reg
,
1485 u32 val
= I915_READ(reg
);
1486 I915_STATE_WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1487 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1488 i915_mmio_reg_offset(reg
), pipe_name(pipe
));
1490 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
) && (val
& DP_PORT_EN
) == 0
1491 && (val
& DP_PIPEB_SELECT
),
1492 "IBX PCH dp port still using transcoder B\n");
1495 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1496 enum pipe pipe
, i915_reg_t reg
)
1498 u32 val
= I915_READ(reg
);
1499 I915_STATE_WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1500 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1501 i915_mmio_reg_offset(reg
), pipe_name(pipe
));
1503 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
) && (val
& SDVO_ENABLE
) == 0
1504 && (val
& SDVO_PIPE_B_SELECT
),
1505 "IBX PCH hdmi port still using transcoder B\n");
1508 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1513 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1514 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1515 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1517 val
= I915_READ(PCH_ADPA
);
1518 I915_STATE_WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1519 "PCH VGA enabled on transcoder %c, should be disabled\n",
1522 val
= I915_READ(PCH_LVDS
);
1523 I915_STATE_WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1524 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1527 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1528 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1529 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1532 static void _vlv_enable_pll(struct intel_crtc
*crtc
,
1533 const struct intel_crtc_state
*pipe_config
)
1535 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1536 enum pipe pipe
= crtc
->pipe
;
1538 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1539 POSTING_READ(DPLL(pipe
));
1542 if (wait_for(((I915_READ(DPLL(pipe
)) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1543 DRM_ERROR("DPLL %d failed to lock\n", pipe
);
1546 static void vlv_enable_pll(struct intel_crtc
*crtc
,
1547 const struct intel_crtc_state
*pipe_config
)
1549 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1550 enum pipe pipe
= crtc
->pipe
;
1552 assert_pipe_disabled(dev_priv
, pipe
);
1554 /* PLL is protected by panel, make sure we can write it */
1555 assert_panel_unlocked(dev_priv
, pipe
);
1557 if (pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
)
1558 _vlv_enable_pll(crtc
, pipe_config
);
1560 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1561 POSTING_READ(DPLL_MD(pipe
));
1565 static void _chv_enable_pll(struct intel_crtc
*crtc
,
1566 const struct intel_crtc_state
*pipe_config
)
1568 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1569 enum pipe pipe
= crtc
->pipe
;
1570 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1573 mutex_lock(&dev_priv
->sb_lock
);
1575 /* Enable back the 10bit clock to display controller */
1576 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1577 tmp
|= DPIO_DCLKP_EN
;
1578 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), tmp
);
1580 mutex_unlock(&dev_priv
->sb_lock
);
1583 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1588 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1590 /* Check PLL is locked */
1591 if (wait_for(((I915_READ(DPLL(pipe
)) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1592 DRM_ERROR("PLL %d failed to lock\n", pipe
);
1595 static void chv_enable_pll(struct intel_crtc
*crtc
,
1596 const struct intel_crtc_state
*pipe_config
)
1598 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1599 enum pipe pipe
= crtc
->pipe
;
1601 assert_pipe_disabled(dev_priv
, pipe
);
1603 /* PLL is protected by panel, make sure we can write it */
1604 assert_panel_unlocked(dev_priv
, pipe
);
1606 if (pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
)
1607 _chv_enable_pll(crtc
, pipe_config
);
1609 if (pipe
!= PIPE_A
) {
1611 * WaPixelRepeatModeFixForC0:chv
1613 * DPLLCMD is AWOL. Use chicken bits to propagate
1614 * the value from DPLLBMD to either pipe B or C.
1616 I915_WRITE(CBR4_VLV
, pipe
== PIPE_B
? CBR_DPLLBMD_PIPE_B
: CBR_DPLLBMD_PIPE_C
);
1617 I915_WRITE(DPLL_MD(PIPE_B
), pipe_config
->dpll_hw_state
.dpll_md
);
1618 I915_WRITE(CBR4_VLV
, 0);
1619 dev_priv
->chv_dpll_md
[pipe
] = pipe_config
->dpll_hw_state
.dpll_md
;
1622 * DPLLB VGA mode also seems to cause problems.
1623 * We should always have it disabled.
1625 WARN_ON((I915_READ(DPLL(PIPE_B
)) & DPLL_VGA_MODE_DIS
) == 0);
1627 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1628 POSTING_READ(DPLL_MD(pipe
));
1632 static int intel_num_dvo_pipes(struct drm_device
*dev
)
1634 struct intel_crtc
*crtc
;
1637 for_each_intel_crtc(dev
, crtc
)
1638 count
+= crtc
->base
.state
->active
&&
1639 intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
);
1644 static void i9xx_enable_pll(struct intel_crtc
*crtc
)
1646 struct drm_device
*dev
= crtc
->base
.dev
;
1647 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1648 i915_reg_t reg
= DPLL(crtc
->pipe
);
1649 u32 dpll
= crtc
->config
->dpll_hw_state
.dpll
;
1651 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1653 /* PLL is protected by panel, make sure we can write it */
1654 if (IS_MOBILE(dev
) && !IS_I830(dev
))
1655 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1657 /* Enable DVO 2x clock on both PLLs if necessary */
1658 if (IS_I830(dev
) && intel_num_dvo_pipes(dev
) > 0) {
1660 * It appears to be important that we don't enable this
1661 * for the current pipe before otherwise configuring the
1662 * PLL. No idea how this should be handled if multiple
1663 * DVO outputs are enabled simultaneosly.
1665 dpll
|= DPLL_DVO_2X_MODE
;
1666 I915_WRITE(DPLL(!crtc
->pipe
),
1667 I915_READ(DPLL(!crtc
->pipe
)) | DPLL_DVO_2X_MODE
);
1671 * Apparently we need to have VGA mode enabled prior to changing
1672 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1673 * dividers, even though the register value does change.
1677 I915_WRITE(reg
, dpll
);
1679 /* Wait for the clocks to stabilize. */
1683 if (INTEL_INFO(dev
)->gen
>= 4) {
1684 I915_WRITE(DPLL_MD(crtc
->pipe
),
1685 crtc
->config
->dpll_hw_state
.dpll_md
);
1687 /* The pixel multiplier can only be updated once the
1688 * DPLL is enabled and the clocks are stable.
1690 * So write it again.
1692 I915_WRITE(reg
, dpll
);
1695 /* We do this three times for luck */
1696 I915_WRITE(reg
, dpll
);
1698 udelay(150); /* wait for warmup */
1699 I915_WRITE(reg
, dpll
);
1701 udelay(150); /* wait for warmup */
1702 I915_WRITE(reg
, dpll
);
1704 udelay(150); /* wait for warmup */
1708 * i9xx_disable_pll - disable a PLL
1709 * @dev_priv: i915 private structure
1710 * @pipe: pipe PLL to disable
1712 * Disable the PLL for @pipe, making sure the pipe is off first.
1714 * Note! This is for pre-ILK only.
1716 static void i9xx_disable_pll(struct intel_crtc
*crtc
)
1718 struct drm_device
*dev
= crtc
->base
.dev
;
1719 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1720 enum pipe pipe
= crtc
->pipe
;
1722 /* Disable DVO 2x clock on both PLLs if necessary */
1724 intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
) &&
1725 !intel_num_dvo_pipes(dev
)) {
1726 I915_WRITE(DPLL(PIPE_B
),
1727 I915_READ(DPLL(PIPE_B
)) & ~DPLL_DVO_2X_MODE
);
1728 I915_WRITE(DPLL(PIPE_A
),
1729 I915_READ(DPLL(PIPE_A
)) & ~DPLL_DVO_2X_MODE
);
1732 /* Don't disable pipe or pipe PLLs if needed */
1733 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1734 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1737 /* Make sure the pipe isn't still relying on us */
1738 assert_pipe_disabled(dev_priv
, pipe
);
1740 I915_WRITE(DPLL(pipe
), DPLL_VGA_MODE_DIS
);
1741 POSTING_READ(DPLL(pipe
));
1744 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1748 /* Make sure the pipe isn't still relying on us */
1749 assert_pipe_disabled(dev_priv
, pipe
);
1751 val
= DPLL_INTEGRATED_REF_CLK_VLV
|
1752 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1754 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1756 I915_WRITE(DPLL(pipe
), val
);
1757 POSTING_READ(DPLL(pipe
));
1760 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1762 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1765 /* Make sure the pipe isn't still relying on us */
1766 assert_pipe_disabled(dev_priv
, pipe
);
1768 val
= DPLL_SSC_REF_CLK_CHV
|
1769 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1771 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1773 I915_WRITE(DPLL(pipe
), val
);
1774 POSTING_READ(DPLL(pipe
));
1776 mutex_lock(&dev_priv
->sb_lock
);
1778 /* Disable 10bit clock to display controller */
1779 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1780 val
&= ~DPIO_DCLKP_EN
;
1781 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1783 mutex_unlock(&dev_priv
->sb_lock
);
1786 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1787 struct intel_digital_port
*dport
,
1788 unsigned int expected_mask
)
1791 i915_reg_t dpll_reg
;
1793 switch (dport
->port
) {
1795 port_mask
= DPLL_PORTB_READY_MASK
;
1799 port_mask
= DPLL_PORTC_READY_MASK
;
1801 expected_mask
<<= 4;
1804 port_mask
= DPLL_PORTD_READY_MASK
;
1805 dpll_reg
= DPIO_PHY_STATUS
;
1811 if (wait_for((I915_READ(dpll_reg
) & port_mask
) == expected_mask
, 1000))
1812 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1813 port_name(dport
->port
), I915_READ(dpll_reg
) & port_mask
, expected_mask
);
1816 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1819 struct drm_device
*dev
= dev_priv
->dev
;
1820 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1821 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1823 uint32_t val
, pipeconf_val
;
1825 /* Make sure PCH DPLL is enabled */
1826 assert_shared_dpll_enabled(dev_priv
, intel_crtc
->config
->shared_dpll
);
1828 /* FDI must be feeding us bits for PCH ports */
1829 assert_fdi_tx_enabled(dev_priv
, pipe
);
1830 assert_fdi_rx_enabled(dev_priv
, pipe
);
1832 if (HAS_PCH_CPT(dev
)) {
1833 /* Workaround: Set the timing override bit before enabling the
1834 * pch transcoder. */
1835 reg
= TRANS_CHICKEN2(pipe
);
1836 val
= I915_READ(reg
);
1837 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1838 I915_WRITE(reg
, val
);
1841 reg
= PCH_TRANSCONF(pipe
);
1842 val
= I915_READ(reg
);
1843 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1845 if (HAS_PCH_IBX(dev_priv
)) {
1847 * Make the BPC in transcoder be consistent with
1848 * that in pipeconf reg. For HDMI we must use 8bpc
1849 * here for both 8bpc and 12bpc.
1851 val
&= ~PIPECONF_BPC_MASK
;
1852 if (intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_HDMI
))
1853 val
|= PIPECONF_8BPC
;
1855 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
1858 val
&= ~TRANS_INTERLACE_MASK
;
1859 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
1860 if (HAS_PCH_IBX(dev_priv
) &&
1861 intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
1862 val
|= TRANS_LEGACY_INTERLACED_ILK
;
1864 val
|= TRANS_INTERLACED
;
1866 val
|= TRANS_PROGRESSIVE
;
1868 I915_WRITE(reg
, val
| TRANS_ENABLE
);
1869 if (wait_for(I915_READ(reg
) & TRANS_STATE_ENABLE
, 100))
1870 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
1873 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1874 enum transcoder cpu_transcoder
)
1876 u32 val
, pipeconf_val
;
1878 /* FDI must be feeding us bits for PCH ports */
1879 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
1880 assert_fdi_rx_enabled(dev_priv
, TRANSCODER_A
);
1882 /* Workaround: set timing override bit. */
1883 val
= I915_READ(TRANS_CHICKEN2(PIPE_A
));
1884 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1885 I915_WRITE(TRANS_CHICKEN2(PIPE_A
), val
);
1888 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
1890 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
1891 PIPECONF_INTERLACED_ILK
)
1892 val
|= TRANS_INTERLACED
;
1894 val
|= TRANS_PROGRESSIVE
;
1896 I915_WRITE(LPT_TRANSCONF
, val
);
1897 if (wait_for(I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
, 100))
1898 DRM_ERROR("Failed to enable PCH transcoder\n");
1901 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1904 struct drm_device
*dev
= dev_priv
->dev
;
1908 /* FDI relies on the transcoder */
1909 assert_fdi_tx_disabled(dev_priv
, pipe
);
1910 assert_fdi_rx_disabled(dev_priv
, pipe
);
1912 /* Ports must be off as well */
1913 assert_pch_ports_disabled(dev_priv
, pipe
);
1915 reg
= PCH_TRANSCONF(pipe
);
1916 val
= I915_READ(reg
);
1917 val
&= ~TRANS_ENABLE
;
1918 I915_WRITE(reg
, val
);
1919 /* wait for PCH transcoder off, transcoder state */
1920 if (wait_for((I915_READ(reg
) & TRANS_STATE_ENABLE
) == 0, 50))
1921 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
1923 if (HAS_PCH_CPT(dev
)) {
1924 /* Workaround: Clear the timing override chicken bit again. */
1925 reg
= TRANS_CHICKEN2(pipe
);
1926 val
= I915_READ(reg
);
1927 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1928 I915_WRITE(reg
, val
);
1932 static void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
1936 val
= I915_READ(LPT_TRANSCONF
);
1937 val
&= ~TRANS_ENABLE
;
1938 I915_WRITE(LPT_TRANSCONF
, val
);
1939 /* wait for PCH transcoder off, transcoder state */
1940 if (wait_for((I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
) == 0, 50))
1941 DRM_ERROR("Failed to disable PCH transcoder\n");
1943 /* Workaround: clear timing override bit. */
1944 val
= I915_READ(TRANS_CHICKEN2(PIPE_A
));
1945 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1946 I915_WRITE(TRANS_CHICKEN2(PIPE_A
), val
);
1950 * intel_enable_pipe - enable a pipe, asserting requirements
1951 * @crtc: crtc responsible for the pipe
1953 * Enable @crtc's pipe, making sure that various hardware specific requirements
1954 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
1956 static void intel_enable_pipe(struct intel_crtc
*crtc
)
1958 struct drm_device
*dev
= crtc
->base
.dev
;
1959 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1960 enum pipe pipe
= crtc
->pipe
;
1961 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1962 enum pipe pch_transcoder
;
1966 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe
));
1968 assert_planes_disabled(dev_priv
, pipe
);
1969 assert_cursor_disabled(dev_priv
, pipe
);
1970 assert_sprites_disabled(dev_priv
, pipe
);
1972 if (HAS_PCH_LPT(dev_priv
))
1973 pch_transcoder
= TRANSCODER_A
;
1975 pch_transcoder
= pipe
;
1978 * A pipe without a PLL won't actually be able to drive bits from
1979 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1982 if (HAS_GMCH_DISPLAY(dev_priv
))
1983 if (crtc
->config
->has_dsi_encoder
)
1984 assert_dsi_pll_enabled(dev_priv
);
1986 assert_pll_enabled(dev_priv
, pipe
);
1988 if (crtc
->config
->has_pch_encoder
) {
1989 /* if driving the PCH, we need FDI enabled */
1990 assert_fdi_rx_pll_enabled(dev_priv
, pch_transcoder
);
1991 assert_fdi_tx_pll_enabled(dev_priv
,
1992 (enum pipe
) cpu_transcoder
);
1994 /* FIXME: assert CPU port conditions for SNB+ */
1997 reg
= PIPECONF(cpu_transcoder
);
1998 val
= I915_READ(reg
);
1999 if (val
& PIPECONF_ENABLE
) {
2000 WARN_ON(!((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
2001 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
)));
2005 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
2009 * Until the pipe starts DSL will read as 0, which would cause
2010 * an apparent vblank timestamp jump, which messes up also the
2011 * frame count when it's derived from the timestamps. So let's
2012 * wait for the pipe to start properly before we call
2013 * drm_crtc_vblank_on()
2015 if (dev
->max_vblank_count
== 0 &&
2016 wait_for(intel_get_crtc_scanline(crtc
) != crtc
->scanline_offset
, 50))
2017 DRM_ERROR("pipe %c didn't start\n", pipe_name(pipe
));
2021 * intel_disable_pipe - disable a pipe, asserting requirements
2022 * @crtc: crtc whose pipes is to be disabled
2024 * Disable the pipe of @crtc, making sure that various hardware
2025 * specific requirements are met, if applicable, e.g. plane
2026 * disabled, panel fitter off, etc.
2028 * Will wait until the pipe has shut down before returning.
2030 static void intel_disable_pipe(struct intel_crtc
*crtc
)
2032 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
2033 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
2034 enum pipe pipe
= crtc
->pipe
;
2038 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe
));
2041 * Make sure planes won't keep trying to pump pixels to us,
2042 * or we might hang the display.
2044 assert_planes_disabled(dev_priv
, pipe
);
2045 assert_cursor_disabled(dev_priv
, pipe
);
2046 assert_sprites_disabled(dev_priv
, pipe
);
2048 reg
= PIPECONF(cpu_transcoder
);
2049 val
= I915_READ(reg
);
2050 if ((val
& PIPECONF_ENABLE
) == 0)
2054 * Double wide has implications for planes
2055 * so best keep it disabled when not needed.
2057 if (crtc
->config
->double_wide
)
2058 val
&= ~PIPECONF_DOUBLE_WIDE
;
2060 /* Don't disable pipe or pipe PLLs if needed */
2061 if (!(pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) &&
2062 !(pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
2063 val
&= ~PIPECONF_ENABLE
;
2065 I915_WRITE(reg
, val
);
2066 if ((val
& PIPECONF_ENABLE
) == 0)
2067 intel_wait_for_pipe_off(crtc
);
2070 static bool need_vtd_wa(struct drm_device
*dev
)
2072 #ifdef CONFIG_INTEL_IOMMU
2073 if (INTEL_INFO(dev
)->gen
>= 6 && intel_iommu_gfx_mapped
)
2079 static unsigned int intel_tile_size(const struct drm_i915_private
*dev_priv
)
2081 return IS_GEN2(dev_priv
) ? 2048 : 4096;
2084 static unsigned int intel_tile_width_bytes(const struct drm_i915_private
*dev_priv
,
2085 uint64_t fb_modifier
, unsigned int cpp
)
2087 switch (fb_modifier
) {
2088 case DRM_FORMAT_MOD_NONE
:
2090 case I915_FORMAT_MOD_X_TILED
:
2091 if (IS_GEN2(dev_priv
))
2095 case I915_FORMAT_MOD_Y_TILED
:
2096 if (IS_GEN2(dev_priv
) || HAS_128_BYTE_Y_TILING(dev_priv
))
2100 case I915_FORMAT_MOD_Yf_TILED
:
2116 MISSING_CASE(fb_modifier
);
2121 unsigned int intel_tile_height(const struct drm_i915_private
*dev_priv
,
2122 uint64_t fb_modifier
, unsigned int cpp
)
2124 if (fb_modifier
== DRM_FORMAT_MOD_NONE
)
2127 return intel_tile_size(dev_priv
) /
2128 intel_tile_width_bytes(dev_priv
, fb_modifier
, cpp
);
2131 /* Return the tile dimensions in pixel units */
2132 static void intel_tile_dims(const struct drm_i915_private
*dev_priv
,
2133 unsigned int *tile_width
,
2134 unsigned int *tile_height
,
2135 uint64_t fb_modifier
,
2138 unsigned int tile_width_bytes
=
2139 intel_tile_width_bytes(dev_priv
, fb_modifier
, cpp
);
2141 *tile_width
= tile_width_bytes
/ cpp
;
2142 *tile_height
= intel_tile_size(dev_priv
) / tile_width_bytes
;
2146 intel_fb_align_height(struct drm_device
*dev
, unsigned int height
,
2147 uint32_t pixel_format
, uint64_t fb_modifier
)
2149 unsigned int cpp
= drm_format_plane_cpp(pixel_format
, 0);
2150 unsigned int tile_height
= intel_tile_height(to_i915(dev
), fb_modifier
, cpp
);
2152 return ALIGN(height
, tile_height
);
2155 unsigned int intel_rotation_info_size(const struct intel_rotation_info
*rot_info
)
2157 unsigned int size
= 0;
2160 for (i
= 0 ; i
< ARRAY_SIZE(rot_info
->plane
); i
++)
2161 size
+= rot_info
->plane
[i
].width
* rot_info
->plane
[i
].height
;
2167 intel_fill_fb_ggtt_view(struct i915_ggtt_view
*view
,
2168 const struct drm_framebuffer
*fb
,
2169 unsigned int rotation
)
2171 if (intel_rotation_90_or_270(rotation
)) {
2172 *view
= i915_ggtt_view_rotated
;
2173 view
->params
.rotated
= to_intel_framebuffer(fb
)->rot_info
;
2175 *view
= i915_ggtt_view_normal
;
2180 intel_fill_fb_info(struct drm_i915_private
*dev_priv
,
2181 struct drm_framebuffer
*fb
)
2183 struct intel_rotation_info
*info
= &to_intel_framebuffer(fb
)->rot_info
;
2184 unsigned int tile_size
, tile_width
, tile_height
, cpp
;
2186 tile_size
= intel_tile_size(dev_priv
);
2188 cpp
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2189 intel_tile_dims(dev_priv
, &tile_width
, &tile_height
,
2190 fb
->modifier
[0], cpp
);
2192 info
->plane
[0].width
= DIV_ROUND_UP(fb
->pitches
[0], tile_width
* cpp
);
2193 info
->plane
[0].height
= DIV_ROUND_UP(fb
->height
, tile_height
);
2195 if (info
->pixel_format
== DRM_FORMAT_NV12
) {
2196 cpp
= drm_format_plane_cpp(fb
->pixel_format
, 1);
2197 intel_tile_dims(dev_priv
, &tile_width
, &tile_height
,
2198 fb
->modifier
[1], cpp
);
2200 info
->uv_offset
= fb
->offsets
[1];
2201 info
->plane
[1].width
= DIV_ROUND_UP(fb
->pitches
[1], tile_width
* cpp
);
2202 info
->plane
[1].height
= DIV_ROUND_UP(fb
->height
/ 2, tile_height
);
2206 static unsigned int intel_linear_alignment(const struct drm_i915_private
*dev_priv
)
2208 if (INTEL_INFO(dev_priv
)->gen
>= 9)
2210 else if (IS_BROADWATER(dev_priv
) || IS_CRESTLINE(dev_priv
) ||
2211 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
2213 else if (INTEL_INFO(dev_priv
)->gen
>= 4)
2219 static unsigned int intel_surf_alignment(const struct drm_i915_private
*dev_priv
,
2220 uint64_t fb_modifier
)
2222 switch (fb_modifier
) {
2223 case DRM_FORMAT_MOD_NONE
:
2224 return intel_linear_alignment(dev_priv
);
2225 case I915_FORMAT_MOD_X_TILED
:
2226 if (INTEL_INFO(dev_priv
)->gen
>= 9)
2229 case I915_FORMAT_MOD_Y_TILED
:
2230 case I915_FORMAT_MOD_Yf_TILED
:
2231 return 1 * 1024 * 1024;
2233 MISSING_CASE(fb_modifier
);
2239 intel_pin_and_fence_fb_obj(struct drm_framebuffer
*fb
,
2240 unsigned int rotation
)
2242 struct drm_device
*dev
= fb
->dev
;
2243 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2244 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2245 struct i915_ggtt_view view
;
2249 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
2251 alignment
= intel_surf_alignment(dev_priv
, fb
->modifier
[0]);
2253 intel_fill_fb_ggtt_view(&view
, fb
, rotation
);
2255 /* Note that the w/a also requires 64 PTE of padding following the
2256 * bo. We currently fill all unused PTE with the shadow page and so
2257 * we should always have valid PTE following the scanout preventing
2260 if (need_vtd_wa(dev
) && alignment
< 256 * 1024)
2261 alignment
= 256 * 1024;
2264 * Global gtt pte registers are special registers which actually forward
2265 * writes to a chunk of system memory. Which means that there is no risk
2266 * that the register values disappear as soon as we call
2267 * intel_runtime_pm_put(), so it is correct to wrap only the
2268 * pin/unpin/fence and not more.
2270 intel_runtime_pm_get(dev_priv
);
2272 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
,
2277 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2278 * fence, whereas 965+ only requires a fence if using
2279 * framebuffer compression. For simplicity, we always install
2280 * a fence as the cost is not that onerous.
2282 if (view
.type
== I915_GGTT_VIEW_NORMAL
) {
2283 ret
= i915_gem_object_get_fence(obj
);
2284 if (ret
== -EDEADLK
) {
2286 * -EDEADLK means there are no free fences
2289 * This is propagated to atomic, but it uses
2290 * -EDEADLK to force a locking recovery, so
2291 * change the returned error to -EBUSY.
2298 i915_gem_object_pin_fence(obj
);
2301 intel_runtime_pm_put(dev_priv
);
2305 i915_gem_object_unpin_from_display_plane(obj
, &view
);
2307 intel_runtime_pm_put(dev_priv
);
2311 void intel_unpin_fb_obj(struct drm_framebuffer
*fb
, unsigned int rotation
)
2313 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2314 struct i915_ggtt_view view
;
2316 WARN_ON(!mutex_is_locked(&obj
->base
.dev
->struct_mutex
));
2318 intel_fill_fb_ggtt_view(&view
, fb
, rotation
);
2320 if (view
.type
== I915_GGTT_VIEW_NORMAL
)
2321 i915_gem_object_unpin_fence(obj
);
2323 i915_gem_object_unpin_from_display_plane(obj
, &view
);
2327 * Adjust the tile offset by moving the difference into
2330 * Input tile dimensions and pitch must already be
2331 * rotated to match x and y, and in pixel units.
2333 static u32
intel_adjust_tile_offset(int *x
, int *y
,
2334 unsigned int tile_width
,
2335 unsigned int tile_height
,
2336 unsigned int tile_size
,
2337 unsigned int pitch_tiles
,
2343 WARN_ON(old_offset
& (tile_size
- 1));
2344 WARN_ON(new_offset
& (tile_size
- 1));
2345 WARN_ON(new_offset
> old_offset
);
2347 tiles
= (old_offset
- new_offset
) / tile_size
;
2349 *y
+= tiles
/ pitch_tiles
* tile_height
;
2350 *x
+= tiles
% pitch_tiles
* tile_width
;
2356 * Computes the linear offset to the base tile and adjusts
2357 * x, y. bytes per pixel is assumed to be a power-of-two.
2359 * In the 90/270 rotated case, x and y are assumed
2360 * to be already rotated to match the rotated GTT view, and
2361 * pitch is the tile_height aligned framebuffer height.
2363 u32
intel_compute_tile_offset(int *x
, int *y
,
2364 const struct drm_framebuffer
*fb
, int plane
,
2366 unsigned int rotation
)
2368 const struct drm_i915_private
*dev_priv
= to_i915(fb
->dev
);
2369 uint64_t fb_modifier
= fb
->modifier
[plane
];
2370 unsigned int cpp
= drm_format_plane_cpp(fb
->pixel_format
, plane
);
2371 u32 offset
, offset_aligned
, alignment
;
2373 alignment
= intel_surf_alignment(dev_priv
, fb_modifier
);
2377 if (fb_modifier
!= DRM_FORMAT_MOD_NONE
) {
2378 unsigned int tile_size
, tile_width
, tile_height
;
2379 unsigned int tile_rows
, tiles
, pitch_tiles
;
2381 tile_size
= intel_tile_size(dev_priv
);
2382 intel_tile_dims(dev_priv
, &tile_width
, &tile_height
,
2385 if (intel_rotation_90_or_270(rotation
)) {
2386 pitch_tiles
= pitch
/ tile_height
;
2387 swap(tile_width
, tile_height
);
2389 pitch_tiles
= pitch
/ (tile_width
* cpp
);
2392 tile_rows
= *y
/ tile_height
;
2395 tiles
= *x
/ tile_width
;
2398 offset
= (tile_rows
* pitch_tiles
+ tiles
) * tile_size
;
2399 offset_aligned
= offset
& ~alignment
;
2401 intel_adjust_tile_offset(x
, y
, tile_width
, tile_height
,
2402 tile_size
, pitch_tiles
,
2403 offset
, offset_aligned
);
2405 offset
= *y
* pitch
+ *x
* cpp
;
2406 offset_aligned
= offset
& ~alignment
;
2408 *y
= (offset
& alignment
) / pitch
;
2409 *x
= ((offset
& alignment
) - *y
* pitch
) / cpp
;
2412 return offset_aligned
;
2415 static int i9xx_format_to_fourcc(int format
)
2418 case DISPPLANE_8BPP
:
2419 return DRM_FORMAT_C8
;
2420 case DISPPLANE_BGRX555
:
2421 return DRM_FORMAT_XRGB1555
;
2422 case DISPPLANE_BGRX565
:
2423 return DRM_FORMAT_RGB565
;
2425 case DISPPLANE_BGRX888
:
2426 return DRM_FORMAT_XRGB8888
;
2427 case DISPPLANE_RGBX888
:
2428 return DRM_FORMAT_XBGR8888
;
2429 case DISPPLANE_BGRX101010
:
2430 return DRM_FORMAT_XRGB2101010
;
2431 case DISPPLANE_RGBX101010
:
2432 return DRM_FORMAT_XBGR2101010
;
2436 static int skl_format_to_fourcc(int format
, bool rgb_order
, bool alpha
)
2439 case PLANE_CTL_FORMAT_RGB_565
:
2440 return DRM_FORMAT_RGB565
;
2442 case PLANE_CTL_FORMAT_XRGB_8888
:
2445 return DRM_FORMAT_ABGR8888
;
2447 return DRM_FORMAT_XBGR8888
;
2450 return DRM_FORMAT_ARGB8888
;
2452 return DRM_FORMAT_XRGB8888
;
2454 case PLANE_CTL_FORMAT_XRGB_2101010
:
2456 return DRM_FORMAT_XBGR2101010
;
2458 return DRM_FORMAT_XRGB2101010
;
2463 intel_alloc_initial_plane_obj(struct intel_crtc
*crtc
,
2464 struct intel_initial_plane_config
*plane_config
)
2466 struct drm_device
*dev
= crtc
->base
.dev
;
2467 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2468 struct i915_ggtt
*ggtt
= &dev_priv
->ggtt
;
2469 struct drm_i915_gem_object
*obj
= NULL
;
2470 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2471 struct drm_framebuffer
*fb
= &plane_config
->fb
->base
;
2472 u32 base_aligned
= round_down(plane_config
->base
, PAGE_SIZE
);
2473 u32 size_aligned
= round_up(plane_config
->base
+ plane_config
->size
,
2476 size_aligned
-= base_aligned
;
2478 if (plane_config
->size
== 0)
2481 /* If the FB is too big, just don't use it since fbdev is not very
2482 * important and we should probably use that space with FBC or other
2484 if (size_aligned
* 2 > ggtt
->stolen_usable_size
)
2487 mutex_lock(&dev
->struct_mutex
);
2489 obj
= i915_gem_object_create_stolen_for_preallocated(dev
,
2494 mutex_unlock(&dev
->struct_mutex
);
2498 obj
->tiling_mode
= plane_config
->tiling
;
2499 if (obj
->tiling_mode
== I915_TILING_X
)
2500 obj
->stride
= fb
->pitches
[0];
2502 mode_cmd
.pixel_format
= fb
->pixel_format
;
2503 mode_cmd
.width
= fb
->width
;
2504 mode_cmd
.height
= fb
->height
;
2505 mode_cmd
.pitches
[0] = fb
->pitches
[0];
2506 mode_cmd
.modifier
[0] = fb
->modifier
[0];
2507 mode_cmd
.flags
= DRM_MODE_FB_MODIFIERS
;
2509 if (intel_framebuffer_init(dev
, to_intel_framebuffer(fb
),
2511 DRM_DEBUG_KMS("intel fb init failed\n");
2515 mutex_unlock(&dev
->struct_mutex
);
2517 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj
);
2521 drm_gem_object_unreference(&obj
->base
);
2522 mutex_unlock(&dev
->struct_mutex
);
2527 intel_find_initial_plane_obj(struct intel_crtc
*intel_crtc
,
2528 struct intel_initial_plane_config
*plane_config
)
2530 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2531 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2533 struct intel_crtc
*i
;
2534 struct drm_i915_gem_object
*obj
;
2535 struct drm_plane
*primary
= intel_crtc
->base
.primary
;
2536 struct drm_plane_state
*plane_state
= primary
->state
;
2537 struct drm_crtc_state
*crtc_state
= intel_crtc
->base
.state
;
2538 struct intel_plane
*intel_plane
= to_intel_plane(primary
);
2539 struct intel_plane_state
*intel_state
=
2540 to_intel_plane_state(plane_state
);
2541 struct drm_framebuffer
*fb
;
2543 if (!plane_config
->fb
)
2546 if (intel_alloc_initial_plane_obj(intel_crtc
, plane_config
)) {
2547 fb
= &plane_config
->fb
->base
;
2551 kfree(plane_config
->fb
);
2554 * Failed to alloc the obj, check to see if we should share
2555 * an fb with another CRTC instead
2557 for_each_crtc(dev
, c
) {
2558 i
= to_intel_crtc(c
);
2560 if (c
== &intel_crtc
->base
)
2566 fb
= c
->primary
->fb
;
2570 obj
= intel_fb_obj(fb
);
2571 if (i915_gem_obj_ggtt_offset(obj
) == plane_config
->base
) {
2572 drm_framebuffer_reference(fb
);
2578 * We've failed to reconstruct the BIOS FB. Current display state
2579 * indicates that the primary plane is visible, but has a NULL FB,
2580 * which will lead to problems later if we don't fix it up. The
2581 * simplest solution is to just disable the primary plane now and
2582 * pretend the BIOS never had it enabled.
2584 to_intel_plane_state(plane_state
)->visible
= false;
2585 crtc_state
->plane_mask
&= ~(1 << drm_plane_index(primary
));
2586 intel_pre_disable_primary_noatomic(&intel_crtc
->base
);
2587 intel_plane
->disable_plane(primary
, &intel_crtc
->base
);
2592 plane_state
->src_x
= 0;
2593 plane_state
->src_y
= 0;
2594 plane_state
->src_w
= fb
->width
<< 16;
2595 plane_state
->src_h
= fb
->height
<< 16;
2597 plane_state
->crtc_x
= 0;
2598 plane_state
->crtc_y
= 0;
2599 plane_state
->crtc_w
= fb
->width
;
2600 plane_state
->crtc_h
= fb
->height
;
2602 intel_state
->src
.x1
= plane_state
->src_x
;
2603 intel_state
->src
.y1
= plane_state
->src_y
;
2604 intel_state
->src
.x2
= plane_state
->src_x
+ plane_state
->src_w
;
2605 intel_state
->src
.y2
= plane_state
->src_y
+ plane_state
->src_h
;
2606 intel_state
->dst
.x1
= plane_state
->crtc_x
;
2607 intel_state
->dst
.y1
= plane_state
->crtc_y
;
2608 intel_state
->dst
.x2
= plane_state
->crtc_x
+ plane_state
->crtc_w
;
2609 intel_state
->dst
.y2
= plane_state
->crtc_y
+ plane_state
->crtc_h
;
2611 obj
= intel_fb_obj(fb
);
2612 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2613 dev_priv
->preserve_bios_swizzle
= true;
2615 drm_framebuffer_reference(fb
);
2616 primary
->fb
= primary
->state
->fb
= fb
;
2617 primary
->crtc
= primary
->state
->crtc
= &intel_crtc
->base
;
2618 intel_crtc
->base
.state
->plane_mask
|= (1 << drm_plane_index(primary
));
2619 obj
->frontbuffer_bits
|= to_intel_plane(primary
)->frontbuffer_bit
;
2622 static void i9xx_update_primary_plane(struct drm_plane
*primary
,
2623 const struct intel_crtc_state
*crtc_state
,
2624 const struct intel_plane_state
*plane_state
)
2626 struct drm_device
*dev
= primary
->dev
;
2627 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2628 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
2629 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2630 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2631 int plane
= intel_crtc
->plane
;
2634 i915_reg_t reg
= DSPCNTR(plane
);
2635 unsigned int rotation
= plane_state
->base
.rotation
;
2636 int cpp
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2637 int x
= plane_state
->src
.x1
>> 16;
2638 int y
= plane_state
->src
.y1
>> 16;
2640 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2642 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2644 if (INTEL_INFO(dev
)->gen
< 4) {
2645 if (intel_crtc
->pipe
== PIPE_B
)
2646 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
2648 /* pipesrc and dspsize control the size that is scaled from,
2649 * which should always be the user's requested size.
2651 I915_WRITE(DSPSIZE(plane
),
2652 ((crtc_state
->pipe_src_h
- 1) << 16) |
2653 (crtc_state
->pipe_src_w
- 1));
2654 I915_WRITE(DSPPOS(plane
), 0);
2655 } else if (IS_CHERRYVIEW(dev
) && plane
== PLANE_B
) {
2656 I915_WRITE(PRIMSIZE(plane
),
2657 ((crtc_state
->pipe_src_h
- 1) << 16) |
2658 (crtc_state
->pipe_src_w
- 1));
2659 I915_WRITE(PRIMPOS(plane
), 0);
2660 I915_WRITE(PRIMCNSTALPHA(plane
), 0);
2663 switch (fb
->pixel_format
) {
2665 dspcntr
|= DISPPLANE_8BPP
;
2667 case DRM_FORMAT_XRGB1555
:
2668 dspcntr
|= DISPPLANE_BGRX555
;
2670 case DRM_FORMAT_RGB565
:
2671 dspcntr
|= DISPPLANE_BGRX565
;
2673 case DRM_FORMAT_XRGB8888
:
2674 dspcntr
|= DISPPLANE_BGRX888
;
2676 case DRM_FORMAT_XBGR8888
:
2677 dspcntr
|= DISPPLANE_RGBX888
;
2679 case DRM_FORMAT_XRGB2101010
:
2680 dspcntr
|= DISPPLANE_BGRX101010
;
2682 case DRM_FORMAT_XBGR2101010
:
2683 dspcntr
|= DISPPLANE_RGBX101010
;
2689 if (INTEL_INFO(dev
)->gen
>= 4 &&
2690 obj
->tiling_mode
!= I915_TILING_NONE
)
2691 dspcntr
|= DISPPLANE_TILED
;
2694 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2696 linear_offset
= y
* fb
->pitches
[0] + x
* cpp
;
2698 if (INTEL_INFO(dev
)->gen
>= 4) {
2699 intel_crtc
->dspaddr_offset
=
2700 intel_compute_tile_offset(&x
, &y
, fb
, 0,
2701 fb
->pitches
[0], rotation
);
2702 linear_offset
-= intel_crtc
->dspaddr_offset
;
2704 intel_crtc
->dspaddr_offset
= linear_offset
;
2707 if (rotation
== BIT(DRM_ROTATE_180
)) {
2708 dspcntr
|= DISPPLANE_ROTATE_180
;
2710 x
+= (crtc_state
->pipe_src_w
- 1);
2711 y
+= (crtc_state
->pipe_src_h
- 1);
2713 /* Finding the last pixel of the last line of the display
2714 data and adding to linear_offset*/
2716 (crtc_state
->pipe_src_h
- 1) * fb
->pitches
[0] +
2717 (crtc_state
->pipe_src_w
- 1) * cpp
;
2720 intel_crtc
->adjusted_x
= x
;
2721 intel_crtc
->adjusted_y
= y
;
2723 I915_WRITE(reg
, dspcntr
);
2725 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2726 if (INTEL_INFO(dev
)->gen
>= 4) {
2727 I915_WRITE(DSPSURF(plane
),
2728 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2729 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2730 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2732 I915_WRITE(DSPADDR(plane
), i915_gem_obj_ggtt_offset(obj
) + linear_offset
);
2736 static void i9xx_disable_primary_plane(struct drm_plane
*primary
,
2737 struct drm_crtc
*crtc
)
2739 struct drm_device
*dev
= crtc
->dev
;
2740 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2741 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2742 int plane
= intel_crtc
->plane
;
2744 I915_WRITE(DSPCNTR(plane
), 0);
2745 if (INTEL_INFO(dev_priv
)->gen
>= 4)
2746 I915_WRITE(DSPSURF(plane
), 0);
2748 I915_WRITE(DSPADDR(plane
), 0);
2749 POSTING_READ(DSPCNTR(plane
));
2752 static void ironlake_update_primary_plane(struct drm_plane
*primary
,
2753 const struct intel_crtc_state
*crtc_state
,
2754 const struct intel_plane_state
*plane_state
)
2756 struct drm_device
*dev
= primary
->dev
;
2757 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2758 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
2759 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2760 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2761 int plane
= intel_crtc
->plane
;
2764 i915_reg_t reg
= DSPCNTR(plane
);
2765 unsigned int rotation
= plane_state
->base
.rotation
;
2766 int cpp
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2767 int x
= plane_state
->src
.x1
>> 16;
2768 int y
= plane_state
->src
.y1
>> 16;
2770 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2771 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2773 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2774 dspcntr
|= DISPPLANE_PIPE_CSC_ENABLE
;
2776 switch (fb
->pixel_format
) {
2778 dspcntr
|= DISPPLANE_8BPP
;
2780 case DRM_FORMAT_RGB565
:
2781 dspcntr
|= DISPPLANE_BGRX565
;
2783 case DRM_FORMAT_XRGB8888
:
2784 dspcntr
|= DISPPLANE_BGRX888
;
2786 case DRM_FORMAT_XBGR8888
:
2787 dspcntr
|= DISPPLANE_RGBX888
;
2789 case DRM_FORMAT_XRGB2101010
:
2790 dspcntr
|= DISPPLANE_BGRX101010
;
2792 case DRM_FORMAT_XBGR2101010
:
2793 dspcntr
|= DISPPLANE_RGBX101010
;
2799 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2800 dspcntr
|= DISPPLANE_TILED
;
2802 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
))
2803 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2805 linear_offset
= y
* fb
->pitches
[0] + x
* cpp
;
2806 intel_crtc
->dspaddr_offset
=
2807 intel_compute_tile_offset(&x
, &y
, fb
, 0,
2808 fb
->pitches
[0], rotation
);
2809 linear_offset
-= intel_crtc
->dspaddr_offset
;
2810 if (rotation
== BIT(DRM_ROTATE_180
)) {
2811 dspcntr
|= DISPPLANE_ROTATE_180
;
2813 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
)) {
2814 x
+= (crtc_state
->pipe_src_w
- 1);
2815 y
+= (crtc_state
->pipe_src_h
- 1);
2817 /* Finding the last pixel of the last line of the display
2818 data and adding to linear_offset*/
2820 (crtc_state
->pipe_src_h
- 1) * fb
->pitches
[0] +
2821 (crtc_state
->pipe_src_w
- 1) * cpp
;
2825 intel_crtc
->adjusted_x
= x
;
2826 intel_crtc
->adjusted_y
= y
;
2828 I915_WRITE(reg
, dspcntr
);
2830 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2831 I915_WRITE(DSPSURF(plane
),
2832 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2833 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2834 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
2836 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2837 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2842 u32
intel_fb_stride_alignment(const struct drm_i915_private
*dev_priv
,
2843 uint64_t fb_modifier
, uint32_t pixel_format
)
2845 if (fb_modifier
== DRM_FORMAT_MOD_NONE
) {
2848 int cpp
= drm_format_plane_cpp(pixel_format
, 0);
2850 return intel_tile_width_bytes(dev_priv
, fb_modifier
, cpp
);
2854 u32
intel_plane_obj_offset(struct intel_plane
*intel_plane
,
2855 struct drm_i915_gem_object
*obj
,
2858 struct i915_ggtt_view view
;
2859 struct i915_vma
*vma
;
2862 intel_fill_fb_ggtt_view(&view
, intel_plane
->base
.state
->fb
,
2863 intel_plane
->base
.state
->rotation
);
2865 vma
= i915_gem_obj_to_ggtt_view(obj
, &view
);
2866 if (WARN(!vma
, "ggtt vma for display object not found! (view=%u)\n",
2870 offset
= vma
->node
.start
;
2873 offset
+= vma
->ggtt_view
.params
.rotated
.uv_start_page
*
2877 WARN_ON(upper_32_bits(offset
));
2879 return lower_32_bits(offset
);
2882 static void skl_detach_scaler(struct intel_crtc
*intel_crtc
, int id
)
2884 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2885 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2887 I915_WRITE(SKL_PS_CTRL(intel_crtc
->pipe
, id
), 0);
2888 I915_WRITE(SKL_PS_WIN_POS(intel_crtc
->pipe
, id
), 0);
2889 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc
->pipe
, id
), 0);
2893 * This function detaches (aka. unbinds) unused scalers in hardware
2895 static void skl_detach_scalers(struct intel_crtc
*intel_crtc
)
2897 struct intel_crtc_scaler_state
*scaler_state
;
2900 scaler_state
= &intel_crtc
->config
->scaler_state
;
2902 /* loop through and disable scalers that aren't in use */
2903 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
2904 if (!scaler_state
->scalers
[i
].in_use
)
2905 skl_detach_scaler(intel_crtc
, i
);
2909 u32
skl_plane_ctl_format(uint32_t pixel_format
)
2911 switch (pixel_format
) {
2913 return PLANE_CTL_FORMAT_INDEXED
;
2914 case DRM_FORMAT_RGB565
:
2915 return PLANE_CTL_FORMAT_RGB_565
;
2916 case DRM_FORMAT_XBGR8888
:
2917 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
;
2918 case DRM_FORMAT_XRGB8888
:
2919 return PLANE_CTL_FORMAT_XRGB_8888
;
2921 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
2922 * to be already pre-multiplied. We need to add a knob (or a different
2923 * DRM_FORMAT) for user-space to configure that.
2925 case DRM_FORMAT_ABGR8888
:
2926 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
|
2927 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
2928 case DRM_FORMAT_ARGB8888
:
2929 return PLANE_CTL_FORMAT_XRGB_8888
|
2930 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
2931 case DRM_FORMAT_XRGB2101010
:
2932 return PLANE_CTL_FORMAT_XRGB_2101010
;
2933 case DRM_FORMAT_XBGR2101010
:
2934 return PLANE_CTL_ORDER_RGBX
| PLANE_CTL_FORMAT_XRGB_2101010
;
2935 case DRM_FORMAT_YUYV
:
2936 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YUYV
;
2937 case DRM_FORMAT_YVYU
:
2938 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YVYU
;
2939 case DRM_FORMAT_UYVY
:
2940 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_UYVY
;
2941 case DRM_FORMAT_VYUY
:
2942 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_VYUY
;
2944 MISSING_CASE(pixel_format
);
2950 u32
skl_plane_ctl_tiling(uint64_t fb_modifier
)
2952 switch (fb_modifier
) {
2953 case DRM_FORMAT_MOD_NONE
:
2955 case I915_FORMAT_MOD_X_TILED
:
2956 return PLANE_CTL_TILED_X
;
2957 case I915_FORMAT_MOD_Y_TILED
:
2958 return PLANE_CTL_TILED_Y
;
2959 case I915_FORMAT_MOD_Yf_TILED
:
2960 return PLANE_CTL_TILED_YF
;
2962 MISSING_CASE(fb_modifier
);
2968 u32
skl_plane_ctl_rotation(unsigned int rotation
)
2971 case BIT(DRM_ROTATE_0
):
2974 * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr
2975 * while i915 HW rotation is clockwise, thats why this swapping.
2977 case BIT(DRM_ROTATE_90
):
2978 return PLANE_CTL_ROTATE_270
;
2979 case BIT(DRM_ROTATE_180
):
2980 return PLANE_CTL_ROTATE_180
;
2981 case BIT(DRM_ROTATE_270
):
2982 return PLANE_CTL_ROTATE_90
;
2984 MISSING_CASE(rotation
);
2990 static void skylake_update_primary_plane(struct drm_plane
*plane
,
2991 const struct intel_crtc_state
*crtc_state
,
2992 const struct intel_plane_state
*plane_state
)
2994 struct drm_device
*dev
= plane
->dev
;
2995 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2996 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
2997 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2998 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2999 int pipe
= intel_crtc
->pipe
;
3000 u32 plane_ctl
, stride_div
, stride
;
3001 u32 tile_height
, plane_offset
, plane_size
;
3002 unsigned int rotation
= plane_state
->base
.rotation
;
3003 int x_offset
, y_offset
;
3005 int scaler_id
= plane_state
->scaler_id
;
3006 int src_x
= plane_state
->src
.x1
>> 16;
3007 int src_y
= plane_state
->src
.y1
>> 16;
3008 int src_w
= drm_rect_width(&plane_state
->src
) >> 16;
3009 int src_h
= drm_rect_height(&plane_state
->src
) >> 16;
3010 int dst_x
= plane_state
->dst
.x1
;
3011 int dst_y
= plane_state
->dst
.y1
;
3012 int dst_w
= drm_rect_width(&plane_state
->dst
);
3013 int dst_h
= drm_rect_height(&plane_state
->dst
);
3015 plane_ctl
= PLANE_CTL_ENABLE
|
3016 PLANE_CTL_PIPE_GAMMA_ENABLE
|
3017 PLANE_CTL_PIPE_CSC_ENABLE
;
3019 plane_ctl
|= skl_plane_ctl_format(fb
->pixel_format
);
3020 plane_ctl
|= skl_plane_ctl_tiling(fb
->modifier
[0]);
3021 plane_ctl
|= PLANE_CTL_PLANE_GAMMA_DISABLE
;
3022 plane_ctl
|= skl_plane_ctl_rotation(rotation
);
3024 stride_div
= intel_fb_stride_alignment(dev_priv
, fb
->modifier
[0],
3026 surf_addr
= intel_plane_obj_offset(to_intel_plane(plane
), obj
, 0);
3028 WARN_ON(drm_rect_width(&plane_state
->src
) == 0);
3030 if (intel_rotation_90_or_270(rotation
)) {
3031 int cpp
= drm_format_plane_cpp(fb
->pixel_format
, 0);
3033 /* stride = Surface height in tiles */
3034 tile_height
= intel_tile_height(dev_priv
, fb
->modifier
[0], cpp
);
3035 stride
= DIV_ROUND_UP(fb
->height
, tile_height
);
3036 x_offset
= stride
* tile_height
- src_y
- src_h
;
3038 plane_size
= (src_w
- 1) << 16 | (src_h
- 1);
3040 stride
= fb
->pitches
[0] / stride_div
;
3043 plane_size
= (src_h
- 1) << 16 | (src_w
- 1);
3045 plane_offset
= y_offset
<< 16 | x_offset
;
3047 intel_crtc
->adjusted_x
= x_offset
;
3048 intel_crtc
->adjusted_y
= y_offset
;
3050 I915_WRITE(PLANE_CTL(pipe
, 0), plane_ctl
);
3051 I915_WRITE(PLANE_OFFSET(pipe
, 0), plane_offset
);
3052 I915_WRITE(PLANE_SIZE(pipe
, 0), plane_size
);
3053 I915_WRITE(PLANE_STRIDE(pipe
, 0), stride
);
3055 if (scaler_id
>= 0) {
3056 uint32_t ps_ctrl
= 0;
3058 WARN_ON(!dst_w
|| !dst_h
);
3059 ps_ctrl
= PS_SCALER_EN
| PS_PLANE_SEL(0) |
3060 crtc_state
->scaler_state
.scalers
[scaler_id
].mode
;
3061 I915_WRITE(SKL_PS_CTRL(pipe
, scaler_id
), ps_ctrl
);
3062 I915_WRITE(SKL_PS_PWR_GATE(pipe
, scaler_id
), 0);
3063 I915_WRITE(SKL_PS_WIN_POS(pipe
, scaler_id
), (dst_x
<< 16) | dst_y
);
3064 I915_WRITE(SKL_PS_WIN_SZ(pipe
, scaler_id
), (dst_w
<< 16) | dst_h
);
3065 I915_WRITE(PLANE_POS(pipe
, 0), 0);
3067 I915_WRITE(PLANE_POS(pipe
, 0), (dst_y
<< 16) | dst_x
);
3070 I915_WRITE(PLANE_SURF(pipe
, 0), surf_addr
);
3072 POSTING_READ(PLANE_SURF(pipe
, 0));
3075 static void skylake_disable_primary_plane(struct drm_plane
*primary
,
3076 struct drm_crtc
*crtc
)
3078 struct drm_device
*dev
= crtc
->dev
;
3079 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3080 int pipe
= to_intel_crtc(crtc
)->pipe
;
3082 I915_WRITE(PLANE_CTL(pipe
, 0), 0);
3083 I915_WRITE(PLANE_SURF(pipe
, 0), 0);
3084 POSTING_READ(PLANE_SURF(pipe
, 0));
3087 /* Assume fb object is pinned & idle & fenced and just update base pointers */
3089 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
3090 int x
, int y
, enum mode_set_atomic state
)
3092 /* Support for kgdboc is disabled, this needs a major rework. */
3093 DRM_ERROR("legacy panic handler not supported any more.\n");
3098 static void intel_update_primary_planes(struct drm_device
*dev
)
3100 struct drm_crtc
*crtc
;
3102 for_each_crtc(dev
, crtc
) {
3103 struct intel_plane
*plane
= to_intel_plane(crtc
->primary
);
3104 struct intel_plane_state
*plane_state
;
3106 drm_modeset_lock_crtc(crtc
, &plane
->base
);
3107 plane_state
= to_intel_plane_state(plane
->base
.state
);
3109 if (plane_state
->visible
)
3110 plane
->update_plane(&plane
->base
,
3111 to_intel_crtc_state(crtc
->state
),
3114 drm_modeset_unlock_crtc(crtc
);
3118 void intel_prepare_reset(struct drm_i915_private
*dev_priv
)
3120 /* no reset support for gen2 */
3121 if (IS_GEN2(dev_priv
))
3124 /* reset doesn't touch the display */
3125 if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
))
3128 drm_modeset_lock_all(dev_priv
->dev
);
3130 * Disabling the crtcs gracefully seems nicer. Also the
3131 * g33 docs say we should at least disable all the planes.
3133 intel_display_suspend(dev_priv
->dev
);
3136 void intel_finish_reset(struct drm_i915_private
*dev_priv
)
3138 /* no reset support for gen2 */
3139 if (IS_GEN2(dev_priv
))
3142 /* reset doesn't touch the display */
3143 if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
)) {
3145 * Flips in the rings have been nuked by the reset,
3146 * so update the base address of all primary
3147 * planes to the the last fb to make sure we're
3148 * showing the correct fb after a reset.
3150 * FIXME: Atomic will make this obsolete since we won't schedule
3151 * CS-based flips (which might get lost in gpu resets) any more.
3153 intel_update_primary_planes(dev_priv
->dev
);
3158 * The display has been reset as well,
3159 * so need a full re-initialization.
3161 intel_runtime_pm_disable_interrupts(dev_priv
);
3162 intel_runtime_pm_enable_interrupts(dev_priv
);
3164 intel_modeset_init_hw(dev_priv
->dev
);
3166 spin_lock_irq(&dev_priv
->irq_lock
);
3167 if (dev_priv
->display
.hpd_irq_setup
)
3168 dev_priv
->display
.hpd_irq_setup(dev_priv
);
3169 spin_unlock_irq(&dev_priv
->irq_lock
);
3171 intel_display_resume(dev_priv
->dev
);
3173 intel_hpd_init(dev_priv
);
3175 drm_modeset_unlock_all(dev_priv
->dev
);
3178 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
3180 return !list_empty_careful(&to_intel_crtc(crtc
)->flip_work
);
3183 static void intel_update_pipe_config(struct intel_crtc
*crtc
,
3184 struct intel_crtc_state
*old_crtc_state
)
3186 struct drm_device
*dev
= crtc
->base
.dev
;
3187 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3188 struct intel_crtc_state
*pipe_config
=
3189 to_intel_crtc_state(crtc
->base
.state
);
3191 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
3192 crtc
->base
.mode
= crtc
->base
.state
->mode
;
3194 DRM_DEBUG_KMS("Updating pipe size %ix%i -> %ix%i\n",
3195 old_crtc_state
->pipe_src_w
, old_crtc_state
->pipe_src_h
,
3196 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
3199 * Update pipe size and adjust fitter if needed: the reason for this is
3200 * that in compute_mode_changes we check the native mode (not the pfit
3201 * mode) to see if we can flip rather than do a full mode set. In the
3202 * fastboot case, we'll flip, but if we don't update the pipesrc and
3203 * pfit state, we'll end up with a big fb scanned out into the wrong
3207 I915_WRITE(PIPESRC(crtc
->pipe
),
3208 ((pipe_config
->pipe_src_w
- 1) << 16) |
3209 (pipe_config
->pipe_src_h
- 1));
3211 /* on skylake this is done by detaching scalers */
3212 if (INTEL_INFO(dev
)->gen
>= 9) {
3213 skl_detach_scalers(crtc
);
3215 if (pipe_config
->pch_pfit
.enabled
)
3216 skylake_pfit_enable(crtc
);
3217 } else if (HAS_PCH_SPLIT(dev
)) {
3218 if (pipe_config
->pch_pfit
.enabled
)
3219 ironlake_pfit_enable(crtc
);
3220 else if (old_crtc_state
->pch_pfit
.enabled
)
3221 ironlake_pfit_disable(crtc
, true);
3225 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
3227 struct drm_device
*dev
= crtc
->dev
;
3228 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3229 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3230 int pipe
= intel_crtc
->pipe
;
3234 /* enable normal train */
3235 reg
= FDI_TX_CTL(pipe
);
3236 temp
= I915_READ(reg
);
3237 if (IS_IVYBRIDGE(dev
)) {
3238 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3239 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3241 temp
&= ~FDI_LINK_TRAIN_NONE
;
3242 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3244 I915_WRITE(reg
, temp
);
3246 reg
= FDI_RX_CTL(pipe
);
3247 temp
= I915_READ(reg
);
3248 if (HAS_PCH_CPT(dev
)) {
3249 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3250 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
3252 temp
&= ~FDI_LINK_TRAIN_NONE
;
3253 temp
|= FDI_LINK_TRAIN_NONE
;
3255 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
3257 /* wait one idle pattern time */
3261 /* IVB wants error correction enabled */
3262 if (IS_IVYBRIDGE(dev
))
3263 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
3264 FDI_FE_ERRC_ENABLE
);
3267 /* The FDI link training functions for ILK/Ibexpeak. */
3268 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
3270 struct drm_device
*dev
= crtc
->dev
;
3271 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3272 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3273 int pipe
= intel_crtc
->pipe
;
3277 /* FDI needs bits from pipe first */
3278 assert_pipe_enabled(dev_priv
, pipe
);
3280 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3282 reg
= FDI_RX_IMR(pipe
);
3283 temp
= I915_READ(reg
);
3284 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3285 temp
&= ~FDI_RX_BIT_LOCK
;
3286 I915_WRITE(reg
, temp
);
3290 /* enable CPU FDI TX and PCH FDI RX */
3291 reg
= FDI_TX_CTL(pipe
);
3292 temp
= I915_READ(reg
);
3293 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3294 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3295 temp
&= ~FDI_LINK_TRAIN_NONE
;
3296 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3297 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3299 reg
= FDI_RX_CTL(pipe
);
3300 temp
= I915_READ(reg
);
3301 temp
&= ~FDI_LINK_TRAIN_NONE
;
3302 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3303 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3308 /* Ironlake workaround, enable clock pointer after FDI enable*/
3309 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3310 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
3311 FDI_RX_PHASE_SYNC_POINTER_EN
);
3313 reg
= FDI_RX_IIR(pipe
);
3314 for (tries
= 0; tries
< 5; tries
++) {
3315 temp
= I915_READ(reg
);
3316 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3318 if ((temp
& FDI_RX_BIT_LOCK
)) {
3319 DRM_DEBUG_KMS("FDI train 1 done.\n");
3320 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3325 DRM_ERROR("FDI train 1 fail!\n");
3328 reg
= FDI_TX_CTL(pipe
);
3329 temp
= I915_READ(reg
);
3330 temp
&= ~FDI_LINK_TRAIN_NONE
;
3331 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3332 I915_WRITE(reg
, temp
);
3334 reg
= FDI_RX_CTL(pipe
);
3335 temp
= I915_READ(reg
);
3336 temp
&= ~FDI_LINK_TRAIN_NONE
;
3337 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3338 I915_WRITE(reg
, temp
);
3343 reg
= FDI_RX_IIR(pipe
);
3344 for (tries
= 0; tries
< 5; tries
++) {
3345 temp
= I915_READ(reg
);
3346 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3348 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3349 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3350 DRM_DEBUG_KMS("FDI train 2 done.\n");
3355 DRM_ERROR("FDI train 2 fail!\n");
3357 DRM_DEBUG_KMS("FDI train done\n");
3361 static const int snb_b_fdi_train_param
[] = {
3362 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
3363 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
3364 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
3365 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
3368 /* The FDI link training functions for SNB/Cougarpoint. */
3369 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
3371 struct drm_device
*dev
= crtc
->dev
;
3372 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3373 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3374 int pipe
= intel_crtc
->pipe
;
3378 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3380 reg
= FDI_RX_IMR(pipe
);
3381 temp
= I915_READ(reg
);
3382 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3383 temp
&= ~FDI_RX_BIT_LOCK
;
3384 I915_WRITE(reg
, temp
);
3389 /* enable CPU FDI TX and PCH FDI RX */
3390 reg
= FDI_TX_CTL(pipe
);
3391 temp
= I915_READ(reg
);
3392 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3393 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3394 temp
&= ~FDI_LINK_TRAIN_NONE
;
3395 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3396 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3398 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3399 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3401 I915_WRITE(FDI_RX_MISC(pipe
),
3402 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3404 reg
= FDI_RX_CTL(pipe
);
3405 temp
= I915_READ(reg
);
3406 if (HAS_PCH_CPT(dev
)) {
3407 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3408 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3410 temp
&= ~FDI_LINK_TRAIN_NONE
;
3411 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3413 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3418 for (i
= 0; i
< 4; i
++) {
3419 reg
= FDI_TX_CTL(pipe
);
3420 temp
= I915_READ(reg
);
3421 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3422 temp
|= snb_b_fdi_train_param
[i
];
3423 I915_WRITE(reg
, temp
);
3428 for (retry
= 0; retry
< 5; retry
++) {
3429 reg
= FDI_RX_IIR(pipe
);
3430 temp
= I915_READ(reg
);
3431 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3432 if (temp
& FDI_RX_BIT_LOCK
) {
3433 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3434 DRM_DEBUG_KMS("FDI train 1 done.\n");
3443 DRM_ERROR("FDI train 1 fail!\n");
3446 reg
= FDI_TX_CTL(pipe
);
3447 temp
= I915_READ(reg
);
3448 temp
&= ~FDI_LINK_TRAIN_NONE
;
3449 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3451 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3453 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3455 I915_WRITE(reg
, temp
);
3457 reg
= FDI_RX_CTL(pipe
);
3458 temp
= I915_READ(reg
);
3459 if (HAS_PCH_CPT(dev
)) {
3460 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3461 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3463 temp
&= ~FDI_LINK_TRAIN_NONE
;
3464 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3466 I915_WRITE(reg
, temp
);
3471 for (i
= 0; i
< 4; i
++) {
3472 reg
= FDI_TX_CTL(pipe
);
3473 temp
= I915_READ(reg
);
3474 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3475 temp
|= snb_b_fdi_train_param
[i
];
3476 I915_WRITE(reg
, temp
);
3481 for (retry
= 0; retry
< 5; retry
++) {
3482 reg
= FDI_RX_IIR(pipe
);
3483 temp
= I915_READ(reg
);
3484 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3485 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3486 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3487 DRM_DEBUG_KMS("FDI train 2 done.\n");
3496 DRM_ERROR("FDI train 2 fail!\n");
3498 DRM_DEBUG_KMS("FDI train done.\n");
3501 /* Manual link training for Ivy Bridge A0 parts */
3502 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
3504 struct drm_device
*dev
= crtc
->dev
;
3505 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3506 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3507 int pipe
= intel_crtc
->pipe
;
3511 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3513 reg
= FDI_RX_IMR(pipe
);
3514 temp
= I915_READ(reg
);
3515 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3516 temp
&= ~FDI_RX_BIT_LOCK
;
3517 I915_WRITE(reg
, temp
);
3522 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3523 I915_READ(FDI_RX_IIR(pipe
)));
3525 /* Try each vswing and preemphasis setting twice before moving on */
3526 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
3527 /* disable first in case we need to retry */
3528 reg
= FDI_TX_CTL(pipe
);
3529 temp
= I915_READ(reg
);
3530 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
3531 temp
&= ~FDI_TX_ENABLE
;
3532 I915_WRITE(reg
, temp
);
3534 reg
= FDI_RX_CTL(pipe
);
3535 temp
= I915_READ(reg
);
3536 temp
&= ~FDI_LINK_TRAIN_AUTO
;
3537 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3538 temp
&= ~FDI_RX_ENABLE
;
3539 I915_WRITE(reg
, temp
);
3541 /* enable CPU FDI TX and PCH FDI RX */
3542 reg
= FDI_TX_CTL(pipe
);
3543 temp
= I915_READ(reg
);
3544 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3545 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3546 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
3547 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3548 temp
|= snb_b_fdi_train_param
[j
/2];
3549 temp
|= FDI_COMPOSITE_SYNC
;
3550 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3552 I915_WRITE(FDI_RX_MISC(pipe
),
3553 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3555 reg
= FDI_RX_CTL(pipe
);
3556 temp
= I915_READ(reg
);
3557 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3558 temp
|= FDI_COMPOSITE_SYNC
;
3559 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3562 udelay(1); /* should be 0.5us */
3564 for (i
= 0; i
< 4; i
++) {
3565 reg
= FDI_RX_IIR(pipe
);
3566 temp
= I915_READ(reg
);
3567 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3569 if (temp
& FDI_RX_BIT_LOCK
||
3570 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
3571 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3572 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3576 udelay(1); /* should be 0.5us */
3579 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
3584 reg
= FDI_TX_CTL(pipe
);
3585 temp
= I915_READ(reg
);
3586 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3587 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
3588 I915_WRITE(reg
, temp
);
3590 reg
= FDI_RX_CTL(pipe
);
3591 temp
= I915_READ(reg
);
3592 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3593 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3594 I915_WRITE(reg
, temp
);
3597 udelay(2); /* should be 1.5us */
3599 for (i
= 0; i
< 4; i
++) {
3600 reg
= FDI_RX_IIR(pipe
);
3601 temp
= I915_READ(reg
);
3602 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3604 if (temp
& FDI_RX_SYMBOL_LOCK
||
3605 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
3606 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3607 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
3611 udelay(2); /* should be 1.5us */
3614 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
3618 DRM_DEBUG_KMS("FDI train done.\n");
3621 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
3623 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3624 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3625 int pipe
= intel_crtc
->pipe
;
3629 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
3630 reg
= FDI_RX_CTL(pipe
);
3631 temp
= I915_READ(reg
);
3632 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
3633 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3634 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3635 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
3640 /* Switch from Rawclk to PCDclk */
3641 temp
= I915_READ(reg
);
3642 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
3647 /* Enable CPU FDI TX PLL, always on for Ironlake */
3648 reg
= FDI_TX_CTL(pipe
);
3649 temp
= I915_READ(reg
);
3650 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
3651 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
3658 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
3660 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3661 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3662 int pipe
= intel_crtc
->pipe
;
3666 /* Switch from PCDclk to Rawclk */
3667 reg
= FDI_RX_CTL(pipe
);
3668 temp
= I915_READ(reg
);
3669 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
3671 /* Disable CPU FDI TX PLL */
3672 reg
= FDI_TX_CTL(pipe
);
3673 temp
= I915_READ(reg
);
3674 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
3679 reg
= FDI_RX_CTL(pipe
);
3680 temp
= I915_READ(reg
);
3681 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
3683 /* Wait for the clocks to turn off. */
3688 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
3690 struct drm_device
*dev
= crtc
->dev
;
3691 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3692 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3693 int pipe
= intel_crtc
->pipe
;
3697 /* disable CPU FDI tx and PCH FDI rx */
3698 reg
= FDI_TX_CTL(pipe
);
3699 temp
= I915_READ(reg
);
3700 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
3703 reg
= FDI_RX_CTL(pipe
);
3704 temp
= I915_READ(reg
);
3705 temp
&= ~(0x7 << 16);
3706 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3707 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
3712 /* Ironlake workaround, disable clock pointer after downing FDI */
3713 if (HAS_PCH_IBX(dev
))
3714 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3716 /* still set train pattern 1 */
3717 reg
= FDI_TX_CTL(pipe
);
3718 temp
= I915_READ(reg
);
3719 temp
&= ~FDI_LINK_TRAIN_NONE
;
3720 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3721 I915_WRITE(reg
, temp
);
3723 reg
= FDI_RX_CTL(pipe
);
3724 temp
= I915_READ(reg
);
3725 if (HAS_PCH_CPT(dev
)) {
3726 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3727 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3729 temp
&= ~FDI_LINK_TRAIN_NONE
;
3730 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3732 /* BPC in FDI rx is consistent with that in PIPECONF */
3733 temp
&= ~(0x07 << 16);
3734 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3735 I915_WRITE(reg
, temp
);
3741 bool intel_has_pending_fb_unpin(struct drm_device
*dev
)
3743 struct intel_crtc
*crtc
;
3745 /* Note that we don't need to be called with mode_config.lock here
3746 * as our list of CRTC objects is static for the lifetime of the
3747 * device and so cannot disappear as we iterate. Similarly, we can
3748 * happily treat the predicates as racy, atomic checks as userspace
3749 * cannot claim and pin a new fb without at least acquring the
3750 * struct_mutex and so serialising with us.
3752 for_each_intel_crtc(dev
, crtc
) {
3753 if (atomic_read(&crtc
->unpin_work_count
) == 0)
3756 if (!list_empty_careful(&crtc
->flip_work
))
3757 intel_wait_for_vblank(dev
, crtc
->pipe
);
3765 static void page_flip_completed(struct intel_crtc
*intel_crtc
, struct intel_flip_work
*work
)
3767 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
3768 struct drm_plane_state
*new_plane_state
;
3769 struct drm_plane
*primary
= intel_crtc
->base
.primary
;
3772 drm_crtc_send_vblank_event(&intel_crtc
->base
, work
->event
);
3774 drm_crtc_vblank_put(&intel_crtc
->base
);
3776 new_plane_state
= &work
->old_plane_state
[0]->base
;
3777 if (work
->num_planes
>= 1 &&
3778 new_plane_state
->plane
== primary
&&
3779 new_plane_state
->fb
)
3780 trace_i915_flip_complete(intel_crtc
->plane
,
3781 intel_fb_obj(new_plane_state
->fb
));
3783 if (work
->can_async_unpin
) {
3784 list_del_init(&work
->head
);
3785 wake_up_all(&dev_priv
->pending_flip_queue
);
3788 queue_work(dev_priv
->wq
, &work
->unpin_work
);
3791 static int intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
3793 struct drm_device
*dev
= crtc
->dev
;
3794 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3797 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
3799 ret
= wait_event_interruptible_timeout(
3800 dev_priv
->pending_flip_queue
,
3801 !intel_crtc_has_pending_flip(crtc
),
3807 WARN(ret
== 0, "Stuck page flip\n");
3812 static void lpt_disable_iclkip(struct drm_i915_private
*dev_priv
)
3816 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
3818 mutex_lock(&dev_priv
->sb_lock
);
3820 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
3821 temp
|= SBI_SSCCTL_DISABLE
;
3822 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
3824 mutex_unlock(&dev_priv
->sb_lock
);
3827 /* Program iCLKIP clock to the desired frequency */
3828 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
3830 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
3831 int clock
= to_intel_crtc(crtc
)->config
->base
.adjusted_mode
.crtc_clock
;
3832 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
3835 lpt_disable_iclkip(dev_priv
);
3837 /* The iCLK virtual clock root frequency is in MHz,
3838 * but the adjusted_mode->crtc_clock in in KHz. To get the
3839 * divisors, it is necessary to divide one by another, so we
3840 * convert the virtual clock precision to KHz here for higher
3843 for (auxdiv
= 0; auxdiv
< 2; auxdiv
++) {
3844 u32 iclk_virtual_root_freq
= 172800 * 1000;
3845 u32 iclk_pi_range
= 64;
3846 u32 desired_divisor
;
3848 desired_divisor
= DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
3850 divsel
= (desired_divisor
/ iclk_pi_range
) - 2;
3851 phaseinc
= desired_divisor
% iclk_pi_range
;
3854 * Near 20MHz is a corner case which is
3855 * out of range for the 7-bit divisor
3861 /* This should not happen with any sane values */
3862 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
3863 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
3864 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
3865 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
3867 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3874 mutex_lock(&dev_priv
->sb_lock
);
3876 /* Program SSCDIVINTPHASE6 */
3877 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
3878 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
3879 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
3880 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
3881 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
3882 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
3883 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
3884 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
3886 /* Program SSCAUXDIV */
3887 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
3888 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3889 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
3890 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
3892 /* Enable modulator and associated divider */
3893 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
3894 temp
&= ~SBI_SSCCTL_DISABLE
;
3895 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
3897 mutex_unlock(&dev_priv
->sb_lock
);
3899 /* Wait for initialization time */
3902 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
3905 int lpt_get_iclkip(struct drm_i915_private
*dev_priv
)
3907 u32 divsel
, phaseinc
, auxdiv
;
3908 u32 iclk_virtual_root_freq
= 172800 * 1000;
3909 u32 iclk_pi_range
= 64;
3910 u32 desired_divisor
;
3913 if ((I915_READ(PIXCLK_GATE
) & PIXCLK_GATE_UNGATE
) == 0)
3916 mutex_lock(&dev_priv
->sb_lock
);
3918 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
3919 if (temp
& SBI_SSCCTL_DISABLE
) {
3920 mutex_unlock(&dev_priv
->sb_lock
);
3924 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
3925 divsel
= (temp
& SBI_SSCDIVINTPHASE_DIVSEL_MASK
) >>
3926 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT
;
3927 phaseinc
= (temp
& SBI_SSCDIVINTPHASE_INCVAL_MASK
) >>
3928 SBI_SSCDIVINTPHASE_INCVAL_SHIFT
;
3930 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
3931 auxdiv
= (temp
& SBI_SSCAUXDIV_FINALDIV2SEL_MASK
) >>
3932 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT
;
3934 mutex_unlock(&dev_priv
->sb_lock
);
3936 desired_divisor
= (divsel
+ 2) * iclk_pi_range
+ phaseinc
;
3938 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
3939 desired_divisor
<< auxdiv
);
3942 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
3943 enum pipe pch_transcoder
)
3945 struct drm_device
*dev
= crtc
->base
.dev
;
3946 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3947 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
3949 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
3950 I915_READ(HTOTAL(cpu_transcoder
)));
3951 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
3952 I915_READ(HBLANK(cpu_transcoder
)));
3953 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
3954 I915_READ(HSYNC(cpu_transcoder
)));
3956 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
3957 I915_READ(VTOTAL(cpu_transcoder
)));
3958 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
3959 I915_READ(VBLANK(cpu_transcoder
)));
3960 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
3961 I915_READ(VSYNC(cpu_transcoder
)));
3962 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
3963 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
3966 static void cpt_set_fdi_bc_bifurcation(struct drm_device
*dev
, bool enable
)
3968 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3971 temp
= I915_READ(SOUTH_CHICKEN1
);
3972 if (!!(temp
& FDI_BC_BIFURCATION_SELECT
) == enable
)
3975 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
3976 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
3978 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
3980 temp
|= FDI_BC_BIFURCATION_SELECT
;
3982 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable
? "en" : "dis");
3983 I915_WRITE(SOUTH_CHICKEN1
, temp
);
3984 POSTING_READ(SOUTH_CHICKEN1
);
3987 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
3989 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3991 switch (intel_crtc
->pipe
) {
3995 if (intel_crtc
->config
->fdi_lanes
> 2)
3996 cpt_set_fdi_bc_bifurcation(dev
, false);
3998 cpt_set_fdi_bc_bifurcation(dev
, true);
4002 cpt_set_fdi_bc_bifurcation(dev
, true);
4010 /* Return which DP Port should be selected for Transcoder DP control */
4012 intel_trans_dp_port_sel(struct drm_crtc
*crtc
)
4014 struct drm_device
*dev
= crtc
->dev
;
4015 struct intel_encoder
*encoder
;
4017 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4018 if (encoder
->type
== INTEL_OUTPUT_DISPLAYPORT
||
4019 encoder
->type
== INTEL_OUTPUT_EDP
)
4020 return enc_to_dig_port(&encoder
->base
)->port
;
4027 * Enable PCH resources required for PCH ports:
4029 * - FDI training & RX/TX
4030 * - update transcoder timings
4031 * - DP transcoding bits
4034 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
4036 struct drm_device
*dev
= crtc
->dev
;
4037 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4038 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4039 int pipe
= intel_crtc
->pipe
;
4042 assert_pch_transcoder_disabled(dev_priv
, pipe
);
4044 if (IS_IVYBRIDGE(dev
))
4045 ivybridge_update_fdi_bc_bifurcation(intel_crtc
);
4047 /* Write the TU size bits before fdi link training, so that error
4048 * detection works. */
4049 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
4050 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
4052 /* For PCH output, training FDI link */
4053 dev_priv
->display
.fdi_link_train(crtc
);
4055 /* We need to program the right clock selection before writing the pixel
4056 * mutliplier into the DPLL. */
4057 if (HAS_PCH_CPT(dev
)) {
4060 temp
= I915_READ(PCH_DPLL_SEL
);
4061 temp
|= TRANS_DPLL_ENABLE(pipe
);
4062 sel
= TRANS_DPLLB_SEL(pipe
);
4063 if (intel_crtc
->config
->shared_dpll
==
4064 intel_get_shared_dpll_by_id(dev_priv
, DPLL_ID_PCH_PLL_B
))
4068 I915_WRITE(PCH_DPLL_SEL
, temp
);
4071 /* XXX: pch pll's can be enabled any time before we enable the PCH
4072 * transcoder, and we actually should do this to not upset any PCH
4073 * transcoder that already use the clock when we share it.
4075 * Note that enable_shared_dpll tries to do the right thing, but
4076 * get_shared_dpll unconditionally resets the pll - we need that to have
4077 * the right LVDS enable sequence. */
4078 intel_enable_shared_dpll(intel_crtc
);
4080 /* set transcoder timing, panel must allow it */
4081 assert_panel_unlocked(dev_priv
, pipe
);
4082 ironlake_pch_transcoder_set_timings(intel_crtc
, pipe
);
4084 intel_fdi_normal_train(crtc
);
4086 /* For PCH DP, enable TRANS_DP_CTL */
4087 if (HAS_PCH_CPT(dev
) && intel_crtc
->config
->has_dp_encoder
) {
4088 const struct drm_display_mode
*adjusted_mode
=
4089 &intel_crtc
->config
->base
.adjusted_mode
;
4090 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
4091 i915_reg_t reg
= TRANS_DP_CTL(pipe
);
4092 temp
= I915_READ(reg
);
4093 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
4094 TRANS_DP_SYNC_MASK
|
4096 temp
|= TRANS_DP_OUTPUT_ENABLE
;
4097 temp
|= bpc
<< 9; /* same format but at 11:9 */
4099 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
4100 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
4101 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
4102 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
4104 switch (intel_trans_dp_port_sel(crtc
)) {
4106 temp
|= TRANS_DP_PORT_SEL_B
;
4109 temp
|= TRANS_DP_PORT_SEL_C
;
4112 temp
|= TRANS_DP_PORT_SEL_D
;
4118 I915_WRITE(reg
, temp
);
4121 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
4124 static void lpt_pch_enable(struct drm_crtc
*crtc
)
4126 struct drm_device
*dev
= crtc
->dev
;
4127 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4128 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4129 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
4131 assert_pch_transcoder_disabled(dev_priv
, TRANSCODER_A
);
4133 lpt_program_iclkip(crtc
);
4135 /* Set transcoder timing. */
4136 ironlake_pch_transcoder_set_timings(intel_crtc
, PIPE_A
);
4138 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
4141 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
4143 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4144 i915_reg_t dslreg
= PIPEDSL(pipe
);
4147 temp
= I915_READ(dslreg
);
4149 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
4150 if (wait_for(I915_READ(dslreg
) != temp
, 5))
4151 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
4156 skl_update_scaler(struct intel_crtc_state
*crtc_state
, bool force_detach
,
4157 unsigned scaler_user
, int *scaler_id
, unsigned int rotation
,
4158 int src_w
, int src_h
, int dst_w
, int dst_h
)
4160 struct intel_crtc_scaler_state
*scaler_state
=
4161 &crtc_state
->scaler_state
;
4162 struct intel_crtc
*intel_crtc
=
4163 to_intel_crtc(crtc_state
->base
.crtc
);
4166 need_scaling
= intel_rotation_90_or_270(rotation
) ?
4167 (src_h
!= dst_w
|| src_w
!= dst_h
):
4168 (src_w
!= dst_w
|| src_h
!= dst_h
);
4171 * if plane is being disabled or scaler is no more required or force detach
4172 * - free scaler binded to this plane/crtc
4173 * - in order to do this, update crtc->scaler_usage
4175 * Here scaler state in crtc_state is set free so that
4176 * scaler can be assigned to other user. Actual register
4177 * update to free the scaler is done in plane/panel-fit programming.
4178 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4180 if (force_detach
|| !need_scaling
) {
4181 if (*scaler_id
>= 0) {
4182 scaler_state
->scaler_users
&= ~(1 << scaler_user
);
4183 scaler_state
->scalers
[*scaler_id
].in_use
= 0;
4185 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4186 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4187 intel_crtc
->pipe
, scaler_user
, *scaler_id
,
4188 scaler_state
->scaler_users
);
4195 if (src_w
< SKL_MIN_SRC_W
|| src_h
< SKL_MIN_SRC_H
||
4196 dst_w
< SKL_MIN_DST_W
|| dst_h
< SKL_MIN_DST_H
||
4198 src_w
> SKL_MAX_SRC_W
|| src_h
> SKL_MAX_SRC_H
||
4199 dst_w
> SKL_MAX_DST_W
|| dst_h
> SKL_MAX_DST_H
) {
4200 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4201 "size is out of scaler range\n",
4202 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
);
4206 /* mark this plane as a scaler user in crtc_state */
4207 scaler_state
->scaler_users
|= (1 << scaler_user
);
4208 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4209 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4210 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
,
4211 scaler_state
->scaler_users
);
4217 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4219 * @state: crtc's scaler state
4222 * 0 - scaler_usage updated successfully
4223 * error - requested scaling cannot be supported or other error condition
4225 int skl_update_scaler_crtc(struct intel_crtc_state
*state
)
4227 struct intel_crtc
*intel_crtc
= to_intel_crtc(state
->base
.crtc
);
4228 const struct drm_display_mode
*adjusted_mode
= &state
->base
.adjusted_mode
;
4230 DRM_DEBUG_KMS("Updating scaler for [CRTC:%i] scaler_user index %u.%u\n",
4231 intel_crtc
->base
.base
.id
, intel_crtc
->pipe
, SKL_CRTC_INDEX
);
4233 return skl_update_scaler(state
, !state
->base
.active
, SKL_CRTC_INDEX
,
4234 &state
->scaler_state
.scaler_id
, BIT(DRM_ROTATE_0
),
4235 state
->pipe_src_w
, state
->pipe_src_h
,
4236 adjusted_mode
->crtc_hdisplay
, adjusted_mode
->crtc_vdisplay
);
4240 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4242 * @state: crtc's scaler state
4243 * @plane_state: atomic plane state to update
4246 * 0 - scaler_usage updated successfully
4247 * error - requested scaling cannot be supported or other error condition
4249 static int skl_update_scaler_plane(struct intel_crtc_state
*crtc_state
,
4250 struct intel_plane_state
*plane_state
)
4253 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
4254 struct intel_plane
*intel_plane
=
4255 to_intel_plane(plane_state
->base
.plane
);
4256 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
4259 bool force_detach
= !fb
|| !plane_state
->visible
;
4261 DRM_DEBUG_KMS("Updating scaler for [PLANE:%d] scaler_user index %u.%u\n",
4262 intel_plane
->base
.base
.id
, intel_crtc
->pipe
,
4263 drm_plane_index(&intel_plane
->base
));
4265 ret
= skl_update_scaler(crtc_state
, force_detach
,
4266 drm_plane_index(&intel_plane
->base
),
4267 &plane_state
->scaler_id
,
4268 plane_state
->base
.rotation
,
4269 drm_rect_width(&plane_state
->src
) >> 16,
4270 drm_rect_height(&plane_state
->src
) >> 16,
4271 drm_rect_width(&plane_state
->dst
),
4272 drm_rect_height(&plane_state
->dst
));
4274 if (ret
|| plane_state
->scaler_id
< 0)
4277 /* check colorkey */
4278 if (plane_state
->ckey
.flags
!= I915_SET_COLORKEY_NONE
) {
4279 DRM_DEBUG_KMS("[PLANE:%d] scaling with color key not allowed",
4280 intel_plane
->base
.base
.id
);
4284 /* Check src format */
4285 switch (fb
->pixel_format
) {
4286 case DRM_FORMAT_RGB565
:
4287 case DRM_FORMAT_XBGR8888
:
4288 case DRM_FORMAT_XRGB8888
:
4289 case DRM_FORMAT_ABGR8888
:
4290 case DRM_FORMAT_ARGB8888
:
4291 case DRM_FORMAT_XRGB2101010
:
4292 case DRM_FORMAT_XBGR2101010
:
4293 case DRM_FORMAT_YUYV
:
4294 case DRM_FORMAT_YVYU
:
4295 case DRM_FORMAT_UYVY
:
4296 case DRM_FORMAT_VYUY
:
4299 DRM_DEBUG_KMS("[PLANE:%d] FB:%d unsupported scaling format 0x%x\n",
4300 intel_plane
->base
.base
.id
, fb
->base
.id
, fb
->pixel_format
);
4307 static void skylake_scaler_disable(struct intel_crtc
*crtc
)
4311 for (i
= 0; i
< crtc
->num_scalers
; i
++)
4312 skl_detach_scaler(crtc
, i
);
4315 static void skylake_pfit_enable(struct intel_crtc
*crtc
)
4317 struct drm_device
*dev
= crtc
->base
.dev
;
4318 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4319 int pipe
= crtc
->pipe
;
4320 struct intel_crtc_scaler_state
*scaler_state
=
4321 &crtc
->config
->scaler_state
;
4323 DRM_DEBUG_KMS("for crtc_state = %p\n", crtc
->config
);
4325 if (crtc
->config
->pch_pfit
.enabled
) {
4328 if (WARN_ON(crtc
->config
->scaler_state
.scaler_id
< 0)) {
4329 DRM_ERROR("Requesting pfit without getting a scaler first\n");
4333 id
= scaler_state
->scaler_id
;
4334 I915_WRITE(SKL_PS_CTRL(pipe
, id
), PS_SCALER_EN
|
4335 PS_FILTER_MEDIUM
| scaler_state
->scalers
[id
].mode
);
4336 I915_WRITE(SKL_PS_WIN_POS(pipe
, id
), crtc
->config
->pch_pfit
.pos
);
4337 I915_WRITE(SKL_PS_WIN_SZ(pipe
, id
), crtc
->config
->pch_pfit
.size
);
4339 DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc
->config
, id
);
4343 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
4345 struct drm_device
*dev
= crtc
->base
.dev
;
4346 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4347 int pipe
= crtc
->pipe
;
4349 if (crtc
->config
->pch_pfit
.enabled
) {
4350 /* Force use of hard-coded filter coefficients
4351 * as some pre-programmed values are broken,
4354 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
))
4355 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
4356 PF_PIPE_SEL_IVB(pipe
));
4358 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
4359 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
->pch_pfit
.pos
);
4360 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
->pch_pfit
.size
);
4364 void hsw_enable_ips(struct intel_crtc
*crtc
)
4366 struct drm_device
*dev
= crtc
->base
.dev
;
4367 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4369 if (!crtc
->config
->ips_enabled
)
4373 * We can only enable IPS after we enable a plane and wait for a vblank
4374 * This function is called from post_plane_update, which is run after
4378 assert_plane_enabled(dev_priv
, crtc
->plane
);
4379 if (IS_BROADWELL(dev
)) {
4380 mutex_lock(&dev_priv
->rps
.hw_lock
);
4381 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
4382 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4383 /* Quoting Art Runyan: "its not safe to expect any particular
4384 * value in IPS_CTL bit 31 after enabling IPS through the
4385 * mailbox." Moreover, the mailbox may return a bogus state,
4386 * so we need to just enable it and continue on.
4389 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
4390 /* The bit only becomes 1 in the next vblank, so this wait here
4391 * is essentially intel_wait_for_vblank. If we don't have this
4392 * and don't wait for vblanks until the end of crtc_enable, then
4393 * the HW state readout code will complain that the expected
4394 * IPS_CTL value is not the one we read. */
4395 if (wait_for(I915_READ_NOTRACE(IPS_CTL
) & IPS_ENABLE
, 50))
4396 DRM_ERROR("Timed out waiting for IPS enable\n");
4400 void hsw_disable_ips(struct intel_crtc
*crtc
)
4402 struct drm_device
*dev
= crtc
->base
.dev
;
4403 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4405 if (!crtc
->config
->ips_enabled
)
4408 assert_plane_enabled(dev_priv
, crtc
->plane
);
4409 if (IS_BROADWELL(dev
)) {
4410 mutex_lock(&dev_priv
->rps
.hw_lock
);
4411 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
4412 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4413 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4414 if (wait_for((I915_READ(IPS_CTL
) & IPS_ENABLE
) == 0, 42))
4415 DRM_ERROR("Timed out waiting for IPS disable\n");
4417 I915_WRITE(IPS_CTL
, 0);
4418 POSTING_READ(IPS_CTL
);
4421 /* We need to wait for a vblank before we can disable the plane. */
4422 intel_wait_for_vblank(dev
, crtc
->pipe
);
4425 static void intel_crtc_dpms_overlay_disable(struct intel_crtc
*intel_crtc
)
4427 if (intel_crtc
->overlay
) {
4428 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4429 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4431 mutex_lock(&dev
->struct_mutex
);
4432 dev_priv
->mm
.interruptible
= false;
4433 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
4434 dev_priv
->mm
.interruptible
= true;
4435 mutex_unlock(&dev
->struct_mutex
);
4438 /* Let userspace switch the overlay on again. In most cases userspace
4439 * has to recompute where to put it anyway.
4444 * intel_post_enable_primary - Perform operations after enabling primary plane
4445 * @crtc: the CRTC whose primary plane was just enabled
4447 * Performs potentially sleeping operations that must be done after the primary
4448 * plane is enabled, such as updating FBC and IPS. Note that this may be
4449 * called due to an explicit primary plane update, or due to an implicit
4450 * re-enable that is caused when a sprite plane is updated to no longer
4451 * completely hide the primary plane.
4454 intel_post_enable_primary(struct drm_crtc
*crtc
)
4456 struct drm_device
*dev
= crtc
->dev
;
4457 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4458 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4459 int pipe
= intel_crtc
->pipe
;
4462 * FIXME IPS should be fine as long as one plane is
4463 * enabled, but in practice it seems to have problems
4464 * when going from primary only to sprite only and vice
4467 hsw_enable_ips(intel_crtc
);
4470 * Gen2 reports pipe underruns whenever all planes are disabled.
4471 * So don't enable underrun reporting before at least some planes
4473 * FIXME: Need to fix the logic to work when we turn off all planes
4474 * but leave the pipe running.
4477 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4479 /* Underruns don't always raise interrupts, so check manually. */
4480 intel_check_cpu_fifo_underruns(dev_priv
);
4481 intel_check_pch_fifo_underruns(dev_priv
);
4484 /* FIXME move all this to pre_plane_update() with proper state tracking */
4486 intel_pre_disable_primary(struct drm_crtc
*crtc
)
4488 struct drm_device
*dev
= crtc
->dev
;
4489 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4490 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4491 int pipe
= intel_crtc
->pipe
;
4494 * Gen2 reports pipe underruns whenever all planes are disabled.
4495 * So diasble underrun reporting before all the planes get disabled.
4496 * FIXME: Need to fix the logic to work when we turn off all planes
4497 * but leave the pipe running.
4500 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4503 * FIXME IPS should be fine as long as one plane is
4504 * enabled, but in practice it seems to have problems
4505 * when going from primary only to sprite only and vice
4508 hsw_disable_ips(intel_crtc
);
4511 /* FIXME get rid of this and use pre_plane_update */
4513 intel_pre_disable_primary_noatomic(struct drm_crtc
*crtc
)
4515 struct drm_device
*dev
= crtc
->dev
;
4516 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4517 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4518 int pipe
= intel_crtc
->pipe
;
4520 intel_pre_disable_primary(crtc
);
4523 * Vblank time updates from the shadow to live plane control register
4524 * are blocked if the memory self-refresh mode is active at that
4525 * moment. So to make sure the plane gets truly disabled, disable
4526 * first the self-refresh mode. The self-refresh enable bit in turn
4527 * will be checked/applied by the HW only at the next frame start
4528 * event which is after the vblank start event, so we need to have a
4529 * wait-for-vblank between disabling the plane and the pipe.
4531 if (HAS_GMCH_DISPLAY(dev
)) {
4532 intel_set_memory_cxsr(dev_priv
, false);
4533 dev_priv
->wm
.vlv
.cxsr
= false;
4534 intel_wait_for_vblank(dev
, pipe
);
4538 static void intel_pre_plane_update(struct intel_crtc_state
*old_crtc_state
)
4540 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
4541 struct drm_device
*dev
= crtc
->base
.dev
;
4542 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4543 struct intel_crtc_state
*pipe_config
=
4544 to_intel_crtc_state(crtc
->base
.state
);
4545 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
4546 struct drm_plane
*primary
= crtc
->base
.primary
;
4547 struct drm_plane_state
*old_pri_state
=
4548 drm_atomic_get_existing_plane_state(old_state
, primary
);
4549 bool modeset
= needs_modeset(&pipe_config
->base
);
4551 if (old_pri_state
) {
4552 struct intel_plane_state
*primary_state
=
4553 to_intel_plane_state(primary
->state
);
4554 struct intel_plane_state
*old_primary_state
=
4555 to_intel_plane_state(old_pri_state
);
4557 intel_fbc_pre_update(crtc
, pipe_config
, primary_state
);
4559 if (old_primary_state
->visible
&&
4560 (modeset
|| !primary_state
->visible
))
4561 intel_pre_disable_primary(&crtc
->base
);
4564 if (pipe_config
->disable_cxsr
) {
4565 crtc
->wm
.cxsr_allowed
= false;
4568 * Vblank time updates from the shadow to live plane control register
4569 * are blocked if the memory self-refresh mode is active at that
4570 * moment. So to make sure the plane gets truly disabled, disable
4571 * first the self-refresh mode. The self-refresh enable bit in turn
4572 * will be checked/applied by the HW only at the next frame start
4573 * event which is after the vblank start event, so we need to have a
4574 * wait-for-vblank between disabling the plane and the pipe.
4576 if (old_crtc_state
->base
.active
) {
4577 intel_set_memory_cxsr(dev_priv
, false);
4578 dev_priv
->wm
.vlv
.cxsr
= false;
4579 intel_wait_for_vblank(dev
, crtc
->pipe
);
4584 * IVB workaround: must disable low power watermarks for at least
4585 * one frame before enabling scaling. LP watermarks can be re-enabled
4586 * when scaling is disabled.
4588 * WaCxSRDisabledForSpriteScaling:ivb
4590 if (pipe_config
->disable_lp_wm
) {
4591 ilk_disable_lp_wm(dev
);
4592 intel_wait_for_vblank(dev
, crtc
->pipe
);
4596 * If we're doing a modeset, we're done. No need to do any pre-vblank
4597 * watermark programming here.
4599 if (needs_modeset(&pipe_config
->base
))
4603 * For platforms that support atomic watermarks, program the
4604 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
4605 * will be the intermediate values that are safe for both pre- and
4606 * post- vblank; when vblank happens, the 'active' values will be set
4607 * to the final 'target' values and we'll do this again to get the
4608 * optimal watermarks. For gen9+ platforms, the values we program here
4609 * will be the final target values which will get automatically latched
4610 * at vblank time; no further programming will be necessary.
4612 * If a platform hasn't been transitioned to atomic watermarks yet,
4613 * we'll continue to update watermarks the old way, if flags tell
4616 if (dev_priv
->display
.initial_watermarks
!= NULL
)
4617 dev_priv
->display
.initial_watermarks(pipe_config
);
4618 else if (pipe_config
->update_wm_pre
)
4619 intel_update_watermarks(&crtc
->base
);
4622 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
, unsigned plane_mask
)
4624 struct drm_device
*dev
= crtc
->dev
;
4625 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4626 struct drm_plane
*p
;
4627 int pipe
= intel_crtc
->pipe
;
4629 intel_crtc_dpms_overlay_disable(intel_crtc
);
4631 drm_for_each_plane_mask(p
, dev
, plane_mask
)
4632 to_intel_plane(p
)->disable_plane(p
, crtc
);
4635 * FIXME: Once we grow proper nuclear flip support out of this we need
4636 * to compute the mask of flip planes precisely. For the time being
4637 * consider this a flip to a NULL plane.
4639 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_ALL_MASK(pipe
));
4642 static void ironlake_crtc_enable(struct drm_crtc
*crtc
)
4644 struct drm_device
*dev
= crtc
->dev
;
4645 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4646 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4647 struct intel_encoder
*encoder
;
4648 int pipe
= intel_crtc
->pipe
;
4649 struct intel_crtc_state
*pipe_config
=
4650 to_intel_crtc_state(crtc
->state
);
4652 if (WARN_ON(intel_crtc
->active
))
4656 * Sometimes spurious CPU pipe underruns happen during FDI
4657 * training, at least with VGA+HDMI cloning. Suppress them.
4659 * On ILK we get an occasional spurious CPU pipe underruns
4660 * between eDP port A enable and vdd enable. Also PCH port
4661 * enable seems to result in the occasional CPU pipe underrun.
4663 * Spurious PCH underruns also occur during PCH enabling.
4665 if (intel_crtc
->config
->has_pch_encoder
|| IS_GEN5(dev_priv
))
4666 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4667 if (intel_crtc
->config
->has_pch_encoder
)
4668 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
4670 if (intel_crtc
->config
->has_pch_encoder
)
4671 intel_prepare_shared_dpll(intel_crtc
);
4673 if (intel_crtc
->config
->has_dp_encoder
)
4674 intel_dp_set_m_n(intel_crtc
, M1_N1
);
4676 intel_set_pipe_timings(intel_crtc
);
4677 intel_set_pipe_src_size(intel_crtc
);
4679 if (intel_crtc
->config
->has_pch_encoder
) {
4680 intel_cpu_transcoder_set_m_n(intel_crtc
,
4681 &intel_crtc
->config
->fdi_m_n
, NULL
);
4684 ironlake_set_pipeconf(crtc
);
4686 intel_crtc
->active
= true;
4688 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4689 if (encoder
->pre_enable
)
4690 encoder
->pre_enable(encoder
);
4692 if (intel_crtc
->config
->has_pch_encoder
) {
4693 /* Note: FDI PLL enabling _must_ be done before we enable the
4694 * cpu pipes, hence this is separate from all the other fdi/pch
4696 ironlake_fdi_pll_enable(intel_crtc
);
4698 assert_fdi_tx_disabled(dev_priv
, pipe
);
4699 assert_fdi_rx_disabled(dev_priv
, pipe
);
4702 ironlake_pfit_enable(intel_crtc
);
4705 * On ILK+ LUT must be loaded before the pipe is running but with
4708 intel_color_load_luts(&pipe_config
->base
);
4710 if (dev_priv
->display
.initial_watermarks
!= NULL
)
4711 dev_priv
->display
.initial_watermarks(intel_crtc
->config
);
4712 intel_enable_pipe(intel_crtc
);
4714 if (intel_crtc
->config
->has_pch_encoder
)
4715 ironlake_pch_enable(crtc
);
4717 assert_vblank_disabled(crtc
);
4718 drm_crtc_vblank_on(crtc
);
4720 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4721 encoder
->enable(encoder
);
4723 if (HAS_PCH_CPT(dev
))
4724 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
4726 /* Must wait for vblank to avoid spurious PCH FIFO underruns */
4727 if (intel_crtc
->config
->has_pch_encoder
)
4728 intel_wait_for_vblank(dev
, pipe
);
4729 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4730 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
4733 /* IPS only exists on ULT machines and is tied to pipe A. */
4734 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
4736 return HAS_IPS(crtc
->base
.dev
) && crtc
->pipe
== PIPE_A
;
4739 static void haswell_crtc_enable(struct drm_crtc
*crtc
)
4741 struct drm_device
*dev
= crtc
->dev
;
4742 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4743 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4744 struct intel_encoder
*encoder
;
4745 int pipe
= intel_crtc
->pipe
, hsw_workaround_pipe
;
4746 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
4747 struct intel_crtc_state
*pipe_config
=
4748 to_intel_crtc_state(crtc
->state
);
4750 if (WARN_ON(intel_crtc
->active
))
4753 if (intel_crtc
->config
->has_pch_encoder
)
4754 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
4757 if (intel_crtc
->config
->shared_dpll
)
4758 intel_enable_shared_dpll(intel_crtc
);
4760 if (intel_crtc
->config
->has_dp_encoder
)
4761 intel_dp_set_m_n(intel_crtc
, M1_N1
);
4763 if (!intel_crtc
->config
->has_dsi_encoder
)
4764 intel_set_pipe_timings(intel_crtc
);
4766 intel_set_pipe_src_size(intel_crtc
);
4768 if (cpu_transcoder
!= TRANSCODER_EDP
&&
4769 !transcoder_is_dsi(cpu_transcoder
)) {
4770 I915_WRITE(PIPE_MULT(cpu_transcoder
),
4771 intel_crtc
->config
->pixel_multiplier
- 1);
4774 if (intel_crtc
->config
->has_pch_encoder
) {
4775 intel_cpu_transcoder_set_m_n(intel_crtc
,
4776 &intel_crtc
->config
->fdi_m_n
, NULL
);
4779 if (!intel_crtc
->config
->has_dsi_encoder
)
4780 haswell_set_pipeconf(crtc
);
4782 haswell_set_pipemisc(crtc
);
4784 intel_color_set_csc(&pipe_config
->base
);
4786 intel_crtc
->active
= true;
4788 if (intel_crtc
->config
->has_pch_encoder
)
4789 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4791 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4793 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4794 if (encoder
->pre_enable
)
4795 encoder
->pre_enable(encoder
);
4798 if (intel_crtc
->config
->has_pch_encoder
)
4799 dev_priv
->display
.fdi_link_train(crtc
);
4801 if (!intel_crtc
->config
->has_dsi_encoder
)
4802 intel_ddi_enable_pipe_clock(intel_crtc
);
4804 if (INTEL_INFO(dev
)->gen
>= 9)
4805 skylake_pfit_enable(intel_crtc
);
4807 ironlake_pfit_enable(intel_crtc
);
4810 * On ILK+ LUT must be loaded before the pipe is running but with
4813 intel_color_load_luts(&pipe_config
->base
);
4815 intel_ddi_set_pipe_settings(crtc
);
4816 if (!intel_crtc
->config
->has_dsi_encoder
)
4817 intel_ddi_enable_transcoder_func(crtc
);
4819 if (dev_priv
->display
.initial_watermarks
!= NULL
)
4820 dev_priv
->display
.initial_watermarks(pipe_config
);
4822 intel_update_watermarks(crtc
);
4824 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
4825 if (!intel_crtc
->config
->has_dsi_encoder
)
4826 intel_enable_pipe(intel_crtc
);
4828 if (intel_crtc
->config
->has_pch_encoder
)
4829 lpt_pch_enable(crtc
);
4831 if (intel_crtc
->config
->dp_encoder_is_mst
)
4832 intel_ddi_set_vc_payload_alloc(crtc
, true);
4834 assert_vblank_disabled(crtc
);
4835 drm_crtc_vblank_on(crtc
);
4837 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4838 encoder
->enable(encoder
);
4839 intel_opregion_notify_encoder(encoder
, true);
4842 if (intel_crtc
->config
->has_pch_encoder
) {
4843 intel_wait_for_vblank(dev
, pipe
);
4844 intel_wait_for_vblank(dev
, pipe
);
4845 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4846 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
4850 /* If we change the relative order between pipe/planes enabling, we need
4851 * to change the workaround. */
4852 hsw_workaround_pipe
= pipe_config
->hsw_workaround_pipe
;
4853 if (IS_HASWELL(dev
) && hsw_workaround_pipe
!= INVALID_PIPE
) {
4854 intel_wait_for_vblank(dev
, hsw_workaround_pipe
);
4855 intel_wait_for_vblank(dev
, hsw_workaround_pipe
);
4859 static void ironlake_pfit_disable(struct intel_crtc
*crtc
, bool force
)
4861 struct drm_device
*dev
= crtc
->base
.dev
;
4862 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4863 int pipe
= crtc
->pipe
;
4865 /* To avoid upsetting the power well on haswell only disable the pfit if
4866 * it's in use. The hw state code will make sure we get this right. */
4867 if (force
|| crtc
->config
->pch_pfit
.enabled
) {
4868 I915_WRITE(PF_CTL(pipe
), 0);
4869 I915_WRITE(PF_WIN_POS(pipe
), 0);
4870 I915_WRITE(PF_WIN_SZ(pipe
), 0);
4874 static void ironlake_crtc_disable(struct drm_crtc
*crtc
)
4876 struct drm_device
*dev
= crtc
->dev
;
4877 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4878 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4879 struct intel_encoder
*encoder
;
4880 int pipe
= intel_crtc
->pipe
;
4883 * Sometimes spurious CPU pipe underruns happen when the
4884 * pipe is already disabled, but FDI RX/TX is still enabled.
4885 * Happens at least with VGA+HDMI cloning. Suppress them.
4887 if (intel_crtc
->config
->has_pch_encoder
) {
4888 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4889 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
4892 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4893 encoder
->disable(encoder
);
4895 drm_crtc_vblank_off(crtc
);
4896 assert_vblank_disabled(crtc
);
4898 intel_disable_pipe(intel_crtc
);
4900 ironlake_pfit_disable(intel_crtc
, false);
4902 if (intel_crtc
->config
->has_pch_encoder
)
4903 ironlake_fdi_disable(crtc
);
4905 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4906 if (encoder
->post_disable
)
4907 encoder
->post_disable(encoder
);
4909 if (intel_crtc
->config
->has_pch_encoder
) {
4910 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
4912 if (HAS_PCH_CPT(dev
)) {
4916 /* disable TRANS_DP_CTL */
4917 reg
= TRANS_DP_CTL(pipe
);
4918 temp
= I915_READ(reg
);
4919 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
4920 TRANS_DP_PORT_SEL_MASK
);
4921 temp
|= TRANS_DP_PORT_SEL_NONE
;
4922 I915_WRITE(reg
, temp
);
4924 /* disable DPLL_SEL */
4925 temp
= I915_READ(PCH_DPLL_SEL
);
4926 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
4927 I915_WRITE(PCH_DPLL_SEL
, temp
);
4930 ironlake_fdi_pll_disable(intel_crtc
);
4933 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4934 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
4937 static void haswell_crtc_disable(struct drm_crtc
*crtc
)
4939 struct drm_device
*dev
= crtc
->dev
;
4940 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4941 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4942 struct intel_encoder
*encoder
;
4943 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
4945 if (intel_crtc
->config
->has_pch_encoder
)
4946 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
4949 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4950 intel_opregion_notify_encoder(encoder
, false);
4951 encoder
->disable(encoder
);
4954 drm_crtc_vblank_off(crtc
);
4955 assert_vblank_disabled(crtc
);
4957 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
4958 if (!intel_crtc
->config
->has_dsi_encoder
)
4959 intel_disable_pipe(intel_crtc
);
4961 if (intel_crtc
->config
->dp_encoder_is_mst
)
4962 intel_ddi_set_vc_payload_alloc(crtc
, false);
4964 if (!intel_crtc
->config
->has_dsi_encoder
)
4965 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
4967 if (INTEL_INFO(dev
)->gen
>= 9)
4968 skylake_scaler_disable(intel_crtc
);
4970 ironlake_pfit_disable(intel_crtc
, false);
4972 if (!intel_crtc
->config
->has_dsi_encoder
)
4973 intel_ddi_disable_pipe_clock(intel_crtc
);
4975 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4976 if (encoder
->post_disable
)
4977 encoder
->post_disable(encoder
);
4979 if (intel_crtc
->config
->has_pch_encoder
) {
4980 lpt_disable_pch_transcoder(dev_priv
);
4981 lpt_disable_iclkip(dev_priv
);
4982 intel_ddi_fdi_disable(crtc
);
4984 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
4989 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
4991 struct drm_device
*dev
= crtc
->base
.dev
;
4992 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4993 struct intel_crtc_state
*pipe_config
= crtc
->config
;
4995 if (!pipe_config
->gmch_pfit
.control
)
4999 * The panel fitter should only be adjusted whilst the pipe is disabled,
5000 * according to register description and PRM.
5002 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
5003 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5005 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
5006 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
5008 /* Border color in case we don't scale up to the full screen. Black by
5009 * default, change to something else for debugging. */
5010 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
5013 static enum intel_display_power_domain
port_to_power_domain(enum port port
)
5017 return POWER_DOMAIN_PORT_DDI_A_LANES
;
5019 return POWER_DOMAIN_PORT_DDI_B_LANES
;
5021 return POWER_DOMAIN_PORT_DDI_C_LANES
;
5023 return POWER_DOMAIN_PORT_DDI_D_LANES
;
5025 return POWER_DOMAIN_PORT_DDI_E_LANES
;
5028 return POWER_DOMAIN_PORT_OTHER
;
5032 static enum intel_display_power_domain
port_to_aux_power_domain(enum port port
)
5036 return POWER_DOMAIN_AUX_A
;
5038 return POWER_DOMAIN_AUX_B
;
5040 return POWER_DOMAIN_AUX_C
;
5042 return POWER_DOMAIN_AUX_D
;
5044 /* FIXME: Check VBT for actual wiring of PORT E */
5045 return POWER_DOMAIN_AUX_D
;
5048 return POWER_DOMAIN_AUX_A
;
5052 enum intel_display_power_domain
5053 intel_display_port_power_domain(struct intel_encoder
*intel_encoder
)
5055 struct drm_device
*dev
= intel_encoder
->base
.dev
;
5056 struct intel_digital_port
*intel_dig_port
;
5058 switch (intel_encoder
->type
) {
5059 case INTEL_OUTPUT_UNKNOWN
:
5060 /* Only DDI platforms should ever use this output type */
5061 WARN_ON_ONCE(!HAS_DDI(dev
));
5062 case INTEL_OUTPUT_DISPLAYPORT
:
5063 case INTEL_OUTPUT_HDMI
:
5064 case INTEL_OUTPUT_EDP
:
5065 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
5066 return port_to_power_domain(intel_dig_port
->port
);
5067 case INTEL_OUTPUT_DP_MST
:
5068 intel_dig_port
= enc_to_mst(&intel_encoder
->base
)->primary
;
5069 return port_to_power_domain(intel_dig_port
->port
);
5070 case INTEL_OUTPUT_ANALOG
:
5071 return POWER_DOMAIN_PORT_CRT
;
5072 case INTEL_OUTPUT_DSI
:
5073 return POWER_DOMAIN_PORT_DSI
;
5075 return POWER_DOMAIN_PORT_OTHER
;
5079 enum intel_display_power_domain
5080 intel_display_port_aux_power_domain(struct intel_encoder
*intel_encoder
)
5082 struct drm_device
*dev
= intel_encoder
->base
.dev
;
5083 struct intel_digital_port
*intel_dig_port
;
5085 switch (intel_encoder
->type
) {
5086 case INTEL_OUTPUT_UNKNOWN
:
5087 case INTEL_OUTPUT_HDMI
:
5089 * Only DDI platforms should ever use these output types.
5090 * We can get here after the HDMI detect code has already set
5091 * the type of the shared encoder. Since we can't be sure
5092 * what's the status of the given connectors, play safe and
5093 * run the DP detection too.
5095 WARN_ON_ONCE(!HAS_DDI(dev
));
5096 case INTEL_OUTPUT_DISPLAYPORT
:
5097 case INTEL_OUTPUT_EDP
:
5098 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
5099 return port_to_aux_power_domain(intel_dig_port
->port
);
5100 case INTEL_OUTPUT_DP_MST
:
5101 intel_dig_port
= enc_to_mst(&intel_encoder
->base
)->primary
;
5102 return port_to_aux_power_domain(intel_dig_port
->port
);
5104 MISSING_CASE(intel_encoder
->type
);
5105 return POWER_DOMAIN_AUX_A
;
5109 static unsigned long get_crtc_power_domains(struct drm_crtc
*crtc
,
5110 struct intel_crtc_state
*crtc_state
)
5112 struct drm_device
*dev
= crtc
->dev
;
5113 struct drm_encoder
*encoder
;
5114 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5115 enum pipe pipe
= intel_crtc
->pipe
;
5117 enum transcoder transcoder
= crtc_state
->cpu_transcoder
;
5119 if (!crtc_state
->base
.active
)
5122 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
5123 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
5124 if (crtc_state
->pch_pfit
.enabled
||
5125 crtc_state
->pch_pfit
.force_thru
)
5126 mask
|= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
5128 drm_for_each_encoder_mask(encoder
, dev
, crtc_state
->base
.encoder_mask
) {
5129 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5131 mask
|= BIT(intel_display_port_power_domain(intel_encoder
));
5134 if (crtc_state
->shared_dpll
)
5135 mask
|= BIT(POWER_DOMAIN_PLLS
);
5140 static unsigned long
5141 modeset_get_crtc_power_domains(struct drm_crtc
*crtc
,
5142 struct intel_crtc_state
*crtc_state
)
5144 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
5145 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5146 enum intel_display_power_domain domain
;
5147 unsigned long domains
, new_domains
, old_domains
, ms_domain
= 0;
5149 old_domains
= intel_crtc
->enabled_power_domains
;
5150 intel_crtc
->enabled_power_domains
= new_domains
=
5151 get_crtc_power_domains(crtc
, crtc_state
);
5153 if (needs_modeset(&crtc_state
->base
))
5154 ms_domain
= BIT(POWER_DOMAIN_MODESET
);
5156 domains
= (new_domains
& ~old_domains
) | ms_domain
;
5158 for_each_power_domain(domain
, domains
)
5159 intel_display_power_get(dev_priv
, domain
);
5161 return (old_domains
& ~new_domains
) | ms_domain
;
5164 static void modeset_put_power_domains(struct drm_i915_private
*dev_priv
,
5165 unsigned long domains
)
5167 enum intel_display_power_domain domain
;
5169 for_each_power_domain(domain
, domains
)
5170 intel_display_power_put(dev_priv
, domain
);
5173 static int intel_compute_max_dotclk(struct drm_i915_private
*dev_priv
)
5175 int max_cdclk_freq
= dev_priv
->max_cdclk_freq
;
5177 if (INTEL_INFO(dev_priv
)->gen
>= 9 ||
5178 IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
5179 return max_cdclk_freq
;
5180 else if (IS_CHERRYVIEW(dev_priv
))
5181 return max_cdclk_freq
*95/100;
5182 else if (INTEL_INFO(dev_priv
)->gen
< 4)
5183 return 2*max_cdclk_freq
*90/100;
5185 return max_cdclk_freq
*90/100;
5188 static int skl_calc_cdclk(int max_pixclk
, int vco
);
5190 static void intel_update_max_cdclk(struct drm_device
*dev
)
5192 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5194 if (IS_SKYLAKE(dev
) || IS_KABYLAKE(dev
)) {
5195 u32 limit
= I915_READ(SKL_DFSM
) & SKL_DFSM_CDCLK_LIMIT_MASK
;
5198 vco
= dev_priv
->skl_preferred_vco_freq
;
5199 WARN_ON(vco
!= 8100 && vco
!= 8640);
5202 * Use the lower (vco 8640) cdclk values as a
5203 * first guess. skl_calc_cdclk() will correct it
5204 * if the preferred vco is 8100 instead.
5206 if (limit
== SKL_DFSM_CDCLK_LIMIT_675
)
5208 else if (limit
== SKL_DFSM_CDCLK_LIMIT_540
)
5210 else if (limit
== SKL_DFSM_CDCLK_LIMIT_450
)
5215 dev_priv
->max_cdclk_freq
= skl_calc_cdclk(max_cdclk
, vco
);
5216 } else if (IS_BROXTON(dev
)) {
5217 dev_priv
->max_cdclk_freq
= 624000;
5218 } else if (IS_BROADWELL(dev
)) {
5220 * FIXME with extra cooling we can allow
5221 * 540 MHz for ULX and 675 Mhz for ULT.
5222 * How can we know if extra cooling is
5223 * available? PCI ID, VTB, something else?
5225 if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
5226 dev_priv
->max_cdclk_freq
= 450000;
5227 else if (IS_BDW_ULX(dev
))
5228 dev_priv
->max_cdclk_freq
= 450000;
5229 else if (IS_BDW_ULT(dev
))
5230 dev_priv
->max_cdclk_freq
= 540000;
5232 dev_priv
->max_cdclk_freq
= 675000;
5233 } else if (IS_CHERRYVIEW(dev
)) {
5234 dev_priv
->max_cdclk_freq
= 320000;
5235 } else if (IS_VALLEYVIEW(dev
)) {
5236 dev_priv
->max_cdclk_freq
= 400000;
5238 /* otherwise assume cdclk is fixed */
5239 dev_priv
->max_cdclk_freq
= dev_priv
->cdclk_freq
;
5242 dev_priv
->max_dotclk_freq
= intel_compute_max_dotclk(dev_priv
);
5244 DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n",
5245 dev_priv
->max_cdclk_freq
);
5247 DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n",
5248 dev_priv
->max_dotclk_freq
);
5251 static void intel_update_cdclk(struct drm_device
*dev
)
5253 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5255 dev_priv
->cdclk_freq
= dev_priv
->display
.get_display_clock_speed(dev
);
5257 if (IS_SKYLAKE(dev_priv
) || IS_KABYLAKE(dev_priv
))
5258 DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz, VCO: %d MHz\n",
5259 dev_priv
->cdclk_freq
, dev_priv
->skl_vco_freq
);
5261 DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n",
5262 dev_priv
->cdclk_freq
);
5265 * 9:0 CMBUS [sic] CDCLK frequency (cdfreq):
5266 * Programmng [sic] note: bit[9:2] should be programmed to the number
5267 * of cdclk that generates 4MHz reference clock freq which is used to
5268 * generate GMBus clock. This will vary with the cdclk freq.
5270 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
5271 I915_WRITE(GMBUSFREQ_VLV
, DIV_ROUND_UP(dev_priv
->cdclk_freq
, 1000));
5274 /* convert from kHz to .1 fixpoint MHz with -1MHz offset */
5275 static int skl_cdclk_decimal(int cdclk
)
5277 return DIV_ROUND_CLOSEST(cdclk
- 1000, 500);
5280 static void broxton_set_cdclk(struct drm_i915_private
*dev_priv
, int cdclk
)
5284 uint32_t current_cdclk
;
5287 /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */
5290 divider
= BXT_CDCLK_CD2X_DIV_SEL_4
;
5291 ratio
= BXT_DE_PLL_RATIO(60);
5294 divider
= BXT_CDCLK_CD2X_DIV_SEL_2
;
5295 ratio
= BXT_DE_PLL_RATIO(60);
5298 divider
= BXT_CDCLK_CD2X_DIV_SEL_1_5
;
5299 ratio
= BXT_DE_PLL_RATIO(60);
5302 divider
= BXT_CDCLK_CD2X_DIV_SEL_1
;
5303 ratio
= BXT_DE_PLL_RATIO(60);
5306 divider
= BXT_CDCLK_CD2X_DIV_SEL_1
;
5307 ratio
= BXT_DE_PLL_RATIO(65);
5311 * Bypass frequency with DE PLL disabled. Init ratio, divider
5312 * to suppress GCC warning.
5318 DRM_ERROR("unsupported CDCLK freq %d", cdclk
);
5323 mutex_lock(&dev_priv
->rps
.hw_lock
);
5324 /* Inform power controller of upcoming frequency change */
5325 ret
= sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
,
5327 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5330 DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n",
5335 current_cdclk
= I915_READ(CDCLK_CTL
) & CDCLK_FREQ_DECIMAL_MASK
;
5336 /* convert from .1 fixpoint MHz with -1MHz offset to kHz */
5337 current_cdclk
= current_cdclk
* 500 + 1000;
5340 * DE PLL has to be disabled when
5341 * - setting to 19.2MHz (bypass, PLL isn't used)
5342 * - before setting to 624MHz (PLL needs toggling)
5343 * - before setting to any frequency from 624MHz (PLL needs toggling)
5345 if (cdclk
== 19200 || cdclk
== 624000 ||
5346 current_cdclk
== 624000) {
5347 I915_WRITE(BXT_DE_PLL_ENABLE
, ~BXT_DE_PLL_PLL_ENABLE
);
5349 if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_LOCK
),
5351 DRM_ERROR("timout waiting for DE PLL unlock\n");
5354 if (cdclk
!= 19200) {
5357 val
= I915_READ(BXT_DE_PLL_CTL
);
5358 val
&= ~BXT_DE_PLL_RATIO_MASK
;
5360 I915_WRITE(BXT_DE_PLL_CTL
, val
);
5362 I915_WRITE(BXT_DE_PLL_ENABLE
, BXT_DE_PLL_PLL_ENABLE
);
5364 if (wait_for(I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_LOCK
, 1))
5365 DRM_ERROR("timeout waiting for DE PLL lock\n");
5367 val
= divider
| skl_cdclk_decimal(cdclk
);
5369 * FIXME if only the cd2x divider needs changing, it could be done
5370 * without shutting off the pipe (if only one pipe is active).
5372 val
|= BXT_CDCLK_CD2X_PIPE_NONE
;
5374 * Disable SSA Precharge when CD clock frequency < 500 MHz,
5377 if (cdclk
>= 500000)
5378 val
|= BXT_CDCLK_SSA_PRECHARGE_ENABLE
;
5379 I915_WRITE(CDCLK_CTL
, val
);
5382 mutex_lock(&dev_priv
->rps
.hw_lock
);
5383 ret
= sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
,
5384 DIV_ROUND_UP(cdclk
, 25000));
5385 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5388 DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n",
5393 intel_update_cdclk(dev_priv
->dev
);
5396 static bool broxton_cdclk_is_enabled(struct drm_i915_private
*dev_priv
)
5398 if (!(I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_PLL_ENABLE
))
5401 /* TODO: Check for a valid CDCLK rate */
5403 if (!(I915_READ(DBUF_CTL
) & DBUF_POWER_REQUEST
)) {
5404 DRM_DEBUG_DRIVER("CDCLK enabled, but DBUF power not requested\n");
5409 if (!(I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
)) {
5410 DRM_DEBUG_DRIVER("CDCLK enabled, but DBUF power hasn't settled\n");
5418 bool broxton_cdclk_verify_state(struct drm_i915_private
*dev_priv
)
5420 return broxton_cdclk_is_enabled(dev_priv
);
5423 void broxton_init_cdclk(struct drm_i915_private
*dev_priv
)
5425 /* check if cd clock is enabled */
5426 if (broxton_cdclk_is_enabled(dev_priv
)) {
5427 DRM_DEBUG_KMS("CDCLK already enabled, won't reprogram it\n");
5431 DRM_DEBUG_KMS("CDCLK not enabled, enabling it\n");
5435 * - The initial CDCLK needs to be read from VBT.
5436 * Need to make this change after VBT has changes for BXT.
5437 * - check if setting the max (or any) cdclk freq is really necessary
5438 * here, it belongs to modeset time
5440 broxton_set_cdclk(dev_priv
, 624000);
5442 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) | DBUF_POWER_REQUEST
);
5443 POSTING_READ(DBUF_CTL
);
5447 if (!(I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
))
5448 DRM_ERROR("DBuf power enable timeout!\n");
5451 void broxton_uninit_cdclk(struct drm_i915_private
*dev_priv
)
5453 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) & ~DBUF_POWER_REQUEST
);
5454 POSTING_READ(DBUF_CTL
);
5458 if (I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
)
5459 DRM_ERROR("DBuf power disable timeout!\n");
5461 /* Set minimum (bypass) frequency, in effect turning off the DE PLL */
5462 broxton_set_cdclk(dev_priv
, 19200);
5465 static int skl_calc_cdclk(int max_pixclk
, int vco
)
5468 if (max_pixclk
> 540000)
5470 else if (max_pixclk
> 432000)
5472 else if (max_pixclk
> 308570)
5478 if (max_pixclk
> 540000)
5480 else if (max_pixclk
> 450000)
5482 else if (max_pixclk
> 337500)
5490 skl_dpll0_update(struct drm_i915_private
*dev_priv
)
5494 val
= I915_READ(LCPLL1_CTL
);
5495 if ((val
& LCPLL_PLL_ENABLE
) == 0) {
5496 dev_priv
->skl_vco_freq
= 0;
5500 val
= I915_READ(DPLL_CTRL1
);
5502 switch (val
& DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
)) {
5503 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810
, SKL_DPLL0
):
5504 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1350
, SKL_DPLL0
):
5505 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1620
, SKL_DPLL0
):
5506 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2700
, SKL_DPLL0
):
5507 dev_priv
->skl_vco_freq
= 8100;
5509 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080
, SKL_DPLL0
):
5510 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2160
, SKL_DPLL0
):
5511 dev_priv
->skl_vco_freq
= 8640;
5514 MISSING_CASE(val
& DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
));
5515 dev_priv
->skl_vco_freq
= 0;
5520 void skl_set_preferred_cdclk_vco(struct drm_i915_private
*dev_priv
, int vco
)
5522 bool changed
= dev_priv
->skl_preferred_vco_freq
!= vco
;
5524 dev_priv
->skl_preferred_vco_freq
= vco
;
5527 intel_update_max_cdclk(dev_priv
->dev
);
5531 skl_dpll0_enable(struct drm_i915_private
*dev_priv
, int vco
)
5533 int min_cdclk
= skl_calc_cdclk(0, vco
);
5536 WARN_ON(vco
!= 8100 && vco
!= 8640);
5538 /* select the minimum CDCLK before enabling DPLL 0 */
5539 val
= CDCLK_FREQ_337_308
| skl_cdclk_decimal(min_cdclk
);
5540 I915_WRITE(CDCLK_CTL
, val
);
5541 POSTING_READ(CDCLK_CTL
);
5544 * We always enable DPLL0 with the lowest link rate possible, but still
5545 * taking into account the VCO required to operate the eDP panel at the
5546 * desired frequency. The usual DP link rates operate with a VCO of
5547 * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640.
5548 * The modeset code is responsible for the selection of the exact link
5549 * rate later on, with the constraint of choosing a frequency that
5552 val
= I915_READ(DPLL_CTRL1
);
5554 val
&= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0
) | DPLL_CTRL1_SSC(SKL_DPLL0
) |
5555 DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
));
5556 val
|= DPLL_CTRL1_OVERRIDE(SKL_DPLL0
);
5558 val
|= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080
,
5561 val
|= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810
,
5564 I915_WRITE(DPLL_CTRL1
, val
);
5565 POSTING_READ(DPLL_CTRL1
);
5567 I915_WRITE(LCPLL1_CTL
, I915_READ(LCPLL1_CTL
) | LCPLL_PLL_ENABLE
);
5569 if (wait_for(I915_READ(LCPLL1_CTL
) & LCPLL_PLL_LOCK
, 5))
5570 DRM_ERROR("DPLL0 not locked\n");
5572 dev_priv
->skl_vco_freq
= vco
;
5574 /* We'll want to keep using the current vco from now on. */
5575 skl_set_preferred_cdclk_vco(dev_priv
, vco
);
5579 skl_dpll0_disable(struct drm_i915_private
*dev_priv
)
5581 I915_WRITE(LCPLL1_CTL
, I915_READ(LCPLL1_CTL
) & ~LCPLL_PLL_ENABLE
);
5582 if (wait_for(!(I915_READ(LCPLL1_CTL
) & LCPLL_PLL_LOCK
), 1))
5583 DRM_ERROR("Couldn't disable DPLL0\n");
5585 dev_priv
->skl_vco_freq
= 0;
5588 static bool skl_cdclk_pcu_ready(struct drm_i915_private
*dev_priv
)
5593 /* inform PCU we want to change CDCLK */
5594 val
= SKL_CDCLK_PREPARE_FOR_CHANGE
;
5595 mutex_lock(&dev_priv
->rps
.hw_lock
);
5596 ret
= sandybridge_pcode_read(dev_priv
, SKL_PCODE_CDCLK_CONTROL
, &val
);
5597 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5599 return ret
== 0 && (val
& SKL_CDCLK_READY_FOR_CHANGE
);
5602 static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private
*dev_priv
)
5606 for (i
= 0; i
< 15; i
++) {
5607 if (skl_cdclk_pcu_ready(dev_priv
))
5615 static void skl_set_cdclk(struct drm_i915_private
*dev_priv
, int cdclk
, int vco
)
5617 struct drm_device
*dev
= dev_priv
->dev
;
5618 u32 freq_select
, pcu_ack
;
5620 WARN_ON((cdclk
== 24000) != (vco
== 0));
5622 DRM_DEBUG_DRIVER("Changing CDCLK to %d kHz (VCO %d MHz)\n", cdclk
, vco
);
5624 if (!skl_cdclk_wait_for_pcu_ready(dev_priv
)) {
5625 DRM_ERROR("failed to inform PCU about cdclk change\n");
5633 freq_select
= CDCLK_FREQ_450_432
;
5637 freq_select
= CDCLK_FREQ_540
;
5643 freq_select
= CDCLK_FREQ_337_308
;
5648 freq_select
= CDCLK_FREQ_675_617
;
5653 if (dev_priv
->skl_vco_freq
!= 0 &&
5654 dev_priv
->skl_vco_freq
!= vco
)
5655 skl_dpll0_disable(dev_priv
);
5657 if (dev_priv
->skl_vco_freq
!= vco
)
5658 skl_dpll0_enable(dev_priv
, vco
);
5660 I915_WRITE(CDCLK_CTL
, freq_select
| skl_cdclk_decimal(cdclk
));
5661 POSTING_READ(CDCLK_CTL
);
5663 /* inform PCU of the change */
5664 mutex_lock(&dev_priv
->rps
.hw_lock
);
5665 sandybridge_pcode_write(dev_priv
, SKL_PCODE_CDCLK_CONTROL
, pcu_ack
);
5666 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5668 intel_update_cdclk(dev
);
5671 void skl_uninit_cdclk(struct drm_i915_private
*dev_priv
)
5673 /* disable DBUF power */
5674 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) & ~DBUF_POWER_REQUEST
);
5675 POSTING_READ(DBUF_CTL
);
5679 if (I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
)
5680 DRM_ERROR("DBuf power disable timeout\n");
5682 skl_set_cdclk(dev_priv
, 24000, 0);
5685 void skl_init_cdclk(struct drm_i915_private
*dev_priv
)
5687 /* DPLL0 not enabled (happens on early BIOS versions) */
5688 if (dev_priv
->skl_vco_freq
== 0) {
5691 /* set CDCLK to the lowest frequency, Modeset follows */
5692 vco
= dev_priv
->skl_preferred_vco_freq
;
5695 cdclk
= skl_calc_cdclk(0, vco
);
5697 skl_set_cdclk(dev_priv
, cdclk
, vco
);
5700 /* enable DBUF power */
5701 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) | DBUF_POWER_REQUEST
);
5702 POSTING_READ(DBUF_CTL
);
5706 if (!(I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
))
5707 DRM_ERROR("DBuf power enable timeout\n");
5710 int skl_sanitize_cdclk(struct drm_i915_private
*dev_priv
)
5712 uint32_t lcpll1
= I915_READ(LCPLL1_CTL
);
5713 uint32_t cdctl
= I915_READ(CDCLK_CTL
);
5714 int freq
= dev_priv
->cdclk_freq
;
5717 * check if the pre-os intialized the display
5718 * There is SWF18 scratchpad register defined which is set by the
5719 * pre-os which can be used by the OS drivers to check the status
5721 if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0)
5724 /* Is PLL enabled and locked ? */
5725 if (!((lcpll1
& LCPLL_PLL_ENABLE
) && (lcpll1
& LCPLL_PLL_LOCK
)))
5728 /* DPLL okay; verify the cdclock
5730 * Noticed in some instances that the freq selection is correct but
5731 * decimal part is programmed wrong from BIOS where pre-os does not
5732 * enable display. Verify the same as well.
5734 if (cdctl
== ((cdctl
& CDCLK_FREQ_SEL_MASK
) | skl_cdclk_decimal(freq
)))
5735 /* All well; nothing to sanitize */
5739 skl_init_cdclk(dev_priv
);
5741 /* we did have to sanitize */
5745 /* Adjust CDclk dividers to allow high res or save power if possible */
5746 static void valleyview_set_cdclk(struct drm_device
*dev
, int cdclk
)
5748 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5751 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
)
5752 != dev_priv
->cdclk_freq
);
5754 if (cdclk
>= 320000) /* jump to highest voltage for 400MHz too */
5756 else if (cdclk
== 266667)
5761 mutex_lock(&dev_priv
->rps
.hw_lock
);
5762 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
5763 val
&= ~DSPFREQGUAR_MASK
;
5764 val
|= (cmd
<< DSPFREQGUAR_SHIFT
);
5765 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
5766 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
5767 DSPFREQSTAT_MASK
) == (cmd
<< DSPFREQSTAT_SHIFT
),
5769 DRM_ERROR("timed out waiting for CDclk change\n");
5771 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5773 mutex_lock(&dev_priv
->sb_lock
);
5775 if (cdclk
== 400000) {
5778 divider
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
5780 /* adjust cdclk divider */
5781 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
5782 val
&= ~CCK_FREQUENCY_VALUES
;
5784 vlv_cck_write(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
, val
);
5786 if (wait_for((vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
) &
5787 CCK_FREQUENCY_STATUS
) == (divider
<< CCK_FREQUENCY_STATUS_SHIFT
),
5789 DRM_ERROR("timed out waiting for CDclk change\n");
5792 /* adjust self-refresh exit latency value */
5793 val
= vlv_bunit_read(dev_priv
, BUNIT_REG_BISOC
);
5797 * For high bandwidth configs, we set a higher latency in the bunit
5798 * so that the core display fetch happens in time to avoid underruns.
5800 if (cdclk
== 400000)
5801 val
|= 4500 / 250; /* 4.5 usec */
5803 val
|= 3000 / 250; /* 3.0 usec */
5804 vlv_bunit_write(dev_priv
, BUNIT_REG_BISOC
, val
);
5806 mutex_unlock(&dev_priv
->sb_lock
);
5808 intel_update_cdclk(dev
);
5811 static void cherryview_set_cdclk(struct drm_device
*dev
, int cdclk
)
5813 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5816 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
)
5817 != dev_priv
->cdclk_freq
);
5826 MISSING_CASE(cdclk
);
5831 * Specs are full of misinformation, but testing on actual
5832 * hardware has shown that we just need to write the desired
5833 * CCK divider into the Punit register.
5835 cmd
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
5837 mutex_lock(&dev_priv
->rps
.hw_lock
);
5838 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
5839 val
&= ~DSPFREQGUAR_MASK_CHV
;
5840 val
|= (cmd
<< DSPFREQGUAR_SHIFT_CHV
);
5841 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
5842 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
5843 DSPFREQSTAT_MASK_CHV
) == (cmd
<< DSPFREQSTAT_SHIFT_CHV
),
5845 DRM_ERROR("timed out waiting for CDclk change\n");
5847 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5849 intel_update_cdclk(dev
);
5852 static int valleyview_calc_cdclk(struct drm_i915_private
*dev_priv
,
5855 int freq_320
= (dev_priv
->hpll_freq
<< 1) % 320000 != 0 ? 333333 : 320000;
5856 int limit
= IS_CHERRYVIEW(dev_priv
) ? 95 : 90;
5859 * Really only a few cases to deal with, as only 4 CDclks are supported:
5862 * 320/333MHz (depends on HPLL freq)
5864 * So we check to see whether we're above 90% (VLV) or 95% (CHV)
5865 * of the lower bin and adjust if needed.
5867 * We seem to get an unstable or solid color picture at 200MHz.
5868 * Not sure what's wrong. For now use 200MHz only when all pipes
5871 if (!IS_CHERRYVIEW(dev_priv
) &&
5872 max_pixclk
> freq_320
*limit
/100)
5874 else if (max_pixclk
> 266667*limit
/100)
5876 else if (max_pixclk
> 0)
5882 static int broxton_calc_cdclk(int max_pixclk
)
5886 * - set 19.2MHz bypass frequency if there are no active pipes
5888 if (max_pixclk
> 576000)
5890 else if (max_pixclk
> 384000)
5892 else if (max_pixclk
> 288000)
5894 else if (max_pixclk
> 144000)
5900 /* Compute the max pixel clock for new configuration. */
5901 static int intel_mode_max_pixclk(struct drm_device
*dev
,
5902 struct drm_atomic_state
*state
)
5904 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
5905 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5906 struct drm_crtc
*crtc
;
5907 struct drm_crtc_state
*crtc_state
;
5908 unsigned max_pixclk
= 0, i
;
5911 memcpy(intel_state
->min_pixclk
, dev_priv
->min_pixclk
,
5912 sizeof(intel_state
->min_pixclk
));
5914 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
5917 if (crtc_state
->enable
)
5918 pixclk
= crtc_state
->adjusted_mode
.crtc_clock
;
5920 intel_state
->min_pixclk
[i
] = pixclk
;
5923 for_each_pipe(dev_priv
, pipe
)
5924 max_pixclk
= max(intel_state
->min_pixclk
[pipe
], max_pixclk
);
5929 static int valleyview_modeset_calc_cdclk(struct drm_atomic_state
*state
)
5931 struct drm_device
*dev
= state
->dev
;
5932 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5933 int max_pixclk
= intel_mode_max_pixclk(dev
, state
);
5934 struct intel_atomic_state
*intel_state
=
5935 to_intel_atomic_state(state
);
5937 intel_state
->cdclk
= intel_state
->dev_cdclk
=
5938 valleyview_calc_cdclk(dev_priv
, max_pixclk
);
5940 if (!intel_state
->active_crtcs
)
5941 intel_state
->dev_cdclk
= valleyview_calc_cdclk(dev_priv
, 0);
5946 static int broxton_modeset_calc_cdclk(struct drm_atomic_state
*state
)
5948 int max_pixclk
= ilk_max_pixel_rate(state
);
5949 struct intel_atomic_state
*intel_state
=
5950 to_intel_atomic_state(state
);
5952 intel_state
->cdclk
= intel_state
->dev_cdclk
=
5953 broxton_calc_cdclk(max_pixclk
);
5955 if (!intel_state
->active_crtcs
)
5956 intel_state
->dev_cdclk
= broxton_calc_cdclk(0);
5961 static void vlv_program_pfi_credits(struct drm_i915_private
*dev_priv
)
5963 unsigned int credits
, default_credits
;
5965 if (IS_CHERRYVIEW(dev_priv
))
5966 default_credits
= PFI_CREDIT(12);
5968 default_credits
= PFI_CREDIT(8);
5970 if (dev_priv
->cdclk_freq
>= dev_priv
->czclk_freq
) {
5971 /* CHV suggested value is 31 or 63 */
5972 if (IS_CHERRYVIEW(dev_priv
))
5973 credits
= PFI_CREDIT_63
;
5975 credits
= PFI_CREDIT(15);
5977 credits
= default_credits
;
5981 * WA - write default credits before re-programming
5982 * FIXME: should we also set the resend bit here?
5984 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
5987 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
5988 credits
| PFI_CREDIT_RESEND
);
5991 * FIXME is this guaranteed to clear
5992 * immediately or should we poll for it?
5994 WARN_ON(I915_READ(GCI_CONTROL
) & PFI_CREDIT_RESEND
);
5997 static void valleyview_modeset_commit_cdclk(struct drm_atomic_state
*old_state
)
5999 struct drm_device
*dev
= old_state
->dev
;
6000 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6001 struct intel_atomic_state
*old_intel_state
=
6002 to_intel_atomic_state(old_state
);
6003 unsigned req_cdclk
= old_intel_state
->dev_cdclk
;
6006 * FIXME: We can end up here with all power domains off, yet
6007 * with a CDCLK frequency other than the minimum. To account
6008 * for this take the PIPE-A power domain, which covers the HW
6009 * blocks needed for the following programming. This can be
6010 * removed once it's guaranteed that we get here either with
6011 * the minimum CDCLK set, or the required power domains
6014 intel_display_power_get(dev_priv
, POWER_DOMAIN_PIPE_A
);
6016 if (IS_CHERRYVIEW(dev
))
6017 cherryview_set_cdclk(dev
, req_cdclk
);
6019 valleyview_set_cdclk(dev
, req_cdclk
);
6021 vlv_program_pfi_credits(dev_priv
);
6023 intel_display_power_put(dev_priv
, POWER_DOMAIN_PIPE_A
);
6026 static void valleyview_crtc_enable(struct drm_crtc
*crtc
)
6028 struct drm_device
*dev
= crtc
->dev
;
6029 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6030 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6031 struct intel_encoder
*encoder
;
6032 struct intel_crtc_state
*pipe_config
=
6033 to_intel_crtc_state(crtc
->state
);
6034 int pipe
= intel_crtc
->pipe
;
6036 if (WARN_ON(intel_crtc
->active
))
6039 if (intel_crtc
->config
->has_dp_encoder
)
6040 intel_dp_set_m_n(intel_crtc
, M1_N1
);
6042 intel_set_pipe_timings(intel_crtc
);
6043 intel_set_pipe_src_size(intel_crtc
);
6045 if (IS_CHERRYVIEW(dev
) && pipe
== PIPE_B
) {
6046 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6048 I915_WRITE(CHV_BLEND(pipe
), CHV_BLEND_LEGACY
);
6049 I915_WRITE(CHV_CANVAS(pipe
), 0);
6052 i9xx_set_pipeconf(intel_crtc
);
6054 intel_crtc
->active
= true;
6056 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
6058 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6059 if (encoder
->pre_pll_enable
)
6060 encoder
->pre_pll_enable(encoder
);
6062 if (IS_CHERRYVIEW(dev
)) {
6063 chv_prepare_pll(intel_crtc
, intel_crtc
->config
);
6064 chv_enable_pll(intel_crtc
, intel_crtc
->config
);
6066 vlv_prepare_pll(intel_crtc
, intel_crtc
->config
);
6067 vlv_enable_pll(intel_crtc
, intel_crtc
->config
);
6070 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6071 if (encoder
->pre_enable
)
6072 encoder
->pre_enable(encoder
);
6074 i9xx_pfit_enable(intel_crtc
);
6076 intel_color_load_luts(&pipe_config
->base
);
6078 intel_update_watermarks(crtc
);
6079 intel_enable_pipe(intel_crtc
);
6081 assert_vblank_disabled(crtc
);
6082 drm_crtc_vblank_on(crtc
);
6084 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6085 encoder
->enable(encoder
);
6088 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
6090 struct drm_device
*dev
= crtc
->base
.dev
;
6091 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6093 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp0
);
6094 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp1
);
6097 static void i9xx_crtc_enable(struct drm_crtc
*crtc
)
6099 struct drm_device
*dev
= crtc
->dev
;
6100 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6101 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6102 struct intel_encoder
*encoder
;
6103 struct intel_crtc_state
*pipe_config
=
6104 to_intel_crtc_state(crtc
->state
);
6105 enum pipe pipe
= intel_crtc
->pipe
;
6107 if (WARN_ON(intel_crtc
->active
))
6110 i9xx_set_pll_dividers(intel_crtc
);
6112 if (intel_crtc
->config
->has_dp_encoder
)
6113 intel_dp_set_m_n(intel_crtc
, M1_N1
);
6115 intel_set_pipe_timings(intel_crtc
);
6116 intel_set_pipe_src_size(intel_crtc
);
6118 i9xx_set_pipeconf(intel_crtc
);
6120 intel_crtc
->active
= true;
6123 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
6125 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6126 if (encoder
->pre_enable
)
6127 encoder
->pre_enable(encoder
);
6129 i9xx_enable_pll(intel_crtc
);
6131 i9xx_pfit_enable(intel_crtc
);
6133 intel_color_load_luts(&pipe_config
->base
);
6135 intel_update_watermarks(crtc
);
6136 intel_enable_pipe(intel_crtc
);
6138 assert_vblank_disabled(crtc
);
6139 drm_crtc_vblank_on(crtc
);
6141 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6142 encoder
->enable(encoder
);
6145 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
6147 struct drm_device
*dev
= crtc
->base
.dev
;
6148 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6150 if (!crtc
->config
->gmch_pfit
.control
)
6153 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
6155 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
6156 I915_READ(PFIT_CONTROL
));
6157 I915_WRITE(PFIT_CONTROL
, 0);
6160 static void i9xx_crtc_disable(struct drm_crtc
*crtc
)
6162 struct drm_device
*dev
= crtc
->dev
;
6163 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6164 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6165 struct intel_encoder
*encoder
;
6166 int pipe
= intel_crtc
->pipe
;
6169 * On gen2 planes are double buffered but the pipe isn't, so we must
6170 * wait for planes to fully turn off before disabling the pipe.
6173 intel_wait_for_vblank(dev
, pipe
);
6175 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6176 encoder
->disable(encoder
);
6178 drm_crtc_vblank_off(crtc
);
6179 assert_vblank_disabled(crtc
);
6181 intel_disable_pipe(intel_crtc
);
6183 i9xx_pfit_disable(intel_crtc
);
6185 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6186 if (encoder
->post_disable
)
6187 encoder
->post_disable(encoder
);
6189 if (!intel_crtc
->config
->has_dsi_encoder
) {
6190 if (IS_CHERRYVIEW(dev
))
6191 chv_disable_pll(dev_priv
, pipe
);
6192 else if (IS_VALLEYVIEW(dev
))
6193 vlv_disable_pll(dev_priv
, pipe
);
6195 i9xx_disable_pll(intel_crtc
);
6198 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6199 if (encoder
->post_pll_disable
)
6200 encoder
->post_pll_disable(encoder
);
6203 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
6206 static void intel_crtc_disable_noatomic(struct drm_crtc
*crtc
)
6208 struct intel_encoder
*encoder
;
6209 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6210 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
6211 enum intel_display_power_domain domain
;
6212 unsigned long domains
;
6214 if (!intel_crtc
->active
)
6217 if (to_intel_plane_state(crtc
->primary
->state
)->visible
) {
6218 WARN_ON(list_empty(&intel_crtc
->flip_work
));
6220 intel_pre_disable_primary_noatomic(crtc
);
6222 intel_crtc_disable_planes(crtc
, 1 << drm_plane_index(crtc
->primary
));
6223 to_intel_plane_state(crtc
->primary
->state
)->visible
= false;
6226 dev_priv
->display
.crtc_disable(crtc
);
6228 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was enabled, now disabled\n",
6231 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->state
, NULL
) < 0);
6232 crtc
->state
->active
= false;
6233 intel_crtc
->active
= false;
6234 crtc
->enabled
= false;
6235 crtc
->state
->connector_mask
= 0;
6236 crtc
->state
->encoder_mask
= 0;
6238 for_each_encoder_on_crtc(crtc
->dev
, crtc
, encoder
)
6239 encoder
->base
.crtc
= NULL
;
6241 intel_fbc_disable(intel_crtc
);
6242 intel_update_watermarks(crtc
);
6243 intel_disable_shared_dpll(intel_crtc
);
6245 domains
= intel_crtc
->enabled_power_domains
;
6246 for_each_power_domain(domain
, domains
)
6247 intel_display_power_put(dev_priv
, domain
);
6248 intel_crtc
->enabled_power_domains
= 0;
6250 dev_priv
->active_crtcs
&= ~(1 << intel_crtc
->pipe
);
6251 dev_priv
->min_pixclk
[intel_crtc
->pipe
] = 0;
6255 * turn all crtc's off, but do not adjust state
6256 * This has to be paired with a call to intel_modeset_setup_hw_state.
6258 int intel_display_suspend(struct drm_device
*dev
)
6260 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6261 struct drm_atomic_state
*state
;
6264 state
= drm_atomic_helper_suspend(dev
);
6265 ret
= PTR_ERR_OR_ZERO(state
);
6267 DRM_ERROR("Suspending crtc's failed with %i\n", ret
);
6269 dev_priv
->modeset_restore_state
= state
;
6272 * Make sure all unpin_work completes before returning.
6274 flush_workqueue(dev_priv
->wq
);
6279 void intel_encoder_destroy(struct drm_encoder
*encoder
)
6281 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
6283 drm_encoder_cleanup(encoder
);
6284 kfree(intel_encoder
);
6287 /* Cross check the actual hw state with our own modeset state tracking (and it's
6288 * internal consistency). */
6289 static void intel_connector_verify_state(struct intel_connector
*connector
,
6290 struct drm_connector_state
*conn_state
)
6292 struct drm_crtc
*crtc
= conn_state
->crtc
;
6294 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6295 connector
->base
.base
.id
,
6296 connector
->base
.name
);
6298 if (connector
->get_hw_state(connector
)) {
6299 struct intel_encoder
*encoder
= connector
->encoder
;
6301 I915_STATE_WARN(!crtc
,
6302 "connector enabled without attached crtc\n");
6307 I915_STATE_WARN(!crtc
->state
->active
,
6308 "connector is active, but attached crtc isn't\n");
6310 if (!encoder
|| encoder
->type
== INTEL_OUTPUT_DP_MST
)
6313 I915_STATE_WARN(conn_state
->best_encoder
!= &encoder
->base
,
6314 "atomic encoder doesn't match attached encoder\n");
6316 I915_STATE_WARN(conn_state
->crtc
!= encoder
->base
.crtc
,
6317 "attached encoder crtc differs from connector crtc\n");
6319 I915_STATE_WARN(crtc
&& crtc
->state
->active
,
6320 "attached crtc is active, but connector isn't\n");
6321 I915_STATE_WARN(!crtc
&& conn_state
->best_encoder
,
6322 "best encoder set without crtc!\n");
6326 int intel_connector_init(struct intel_connector
*connector
)
6328 drm_atomic_helper_connector_reset(&connector
->base
);
6330 if (!connector
->base
.state
)
6336 struct intel_connector
*intel_connector_alloc(void)
6338 struct intel_connector
*connector
;
6340 connector
= kzalloc(sizeof *connector
, GFP_KERNEL
);
6344 if (intel_connector_init(connector
) < 0) {
6352 /* Simple connector->get_hw_state implementation for encoders that support only
6353 * one connector and no cloning and hence the encoder state determines the state
6354 * of the connector. */
6355 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
6358 struct intel_encoder
*encoder
= connector
->encoder
;
6360 return encoder
->get_hw_state(encoder
, &pipe
);
6363 static int pipe_required_fdi_lanes(struct intel_crtc_state
*crtc_state
)
6365 if (crtc_state
->base
.enable
&& crtc_state
->has_pch_encoder
)
6366 return crtc_state
->fdi_lanes
;
6371 static int ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
6372 struct intel_crtc_state
*pipe_config
)
6374 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
6375 struct intel_crtc
*other_crtc
;
6376 struct intel_crtc_state
*other_crtc_state
;
6378 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6379 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6380 if (pipe_config
->fdi_lanes
> 4) {
6381 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6382 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6386 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
6387 if (pipe_config
->fdi_lanes
> 2) {
6388 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6389 pipe_config
->fdi_lanes
);
6396 if (INTEL_INFO(dev
)->num_pipes
== 2)
6399 /* Ivybridge 3 pipe is really complicated */
6404 if (pipe_config
->fdi_lanes
<= 2)
6407 other_crtc
= to_intel_crtc(intel_get_crtc_for_pipe(dev
, PIPE_C
));
6409 intel_atomic_get_crtc_state(state
, other_crtc
);
6410 if (IS_ERR(other_crtc_state
))
6411 return PTR_ERR(other_crtc_state
);
6413 if (pipe_required_fdi_lanes(other_crtc_state
) > 0) {
6414 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6415 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6420 if (pipe_config
->fdi_lanes
> 2) {
6421 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6422 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6426 other_crtc
= to_intel_crtc(intel_get_crtc_for_pipe(dev
, PIPE_B
));
6428 intel_atomic_get_crtc_state(state
, other_crtc
);
6429 if (IS_ERR(other_crtc_state
))
6430 return PTR_ERR(other_crtc_state
);
6432 if (pipe_required_fdi_lanes(other_crtc_state
) > 2) {
6433 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6443 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
6444 struct intel_crtc_state
*pipe_config
)
6446 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6447 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6448 int lane
, link_bw
, fdi_dotclock
, ret
;
6449 bool needs_recompute
= false;
6452 /* FDI is a binary signal running at ~2.7GHz, encoding
6453 * each output octet as 10 bits. The actual frequency
6454 * is stored as a divider into a 100MHz clock, and the
6455 * mode pixel clock is stored in units of 1KHz.
6456 * Hence the bw of each lane in terms of the mode signal
6459 link_bw
= intel_fdi_link_freq(to_i915(dev
), pipe_config
);
6461 fdi_dotclock
= adjusted_mode
->crtc_clock
;
6463 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
6464 pipe_config
->pipe_bpp
);
6466 pipe_config
->fdi_lanes
= lane
;
6468 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
6469 link_bw
, &pipe_config
->fdi_m_n
);
6471 ret
= ironlake_check_fdi_lanes(dev
, intel_crtc
->pipe
, pipe_config
);
6472 if (ret
== -EINVAL
&& pipe_config
->pipe_bpp
> 6*3) {
6473 pipe_config
->pipe_bpp
-= 2*3;
6474 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6475 pipe_config
->pipe_bpp
);
6476 needs_recompute
= true;
6477 pipe_config
->bw_constrained
= true;
6482 if (needs_recompute
)
6488 static bool pipe_config_supports_ips(struct drm_i915_private
*dev_priv
,
6489 struct intel_crtc_state
*pipe_config
)
6491 if (pipe_config
->pipe_bpp
> 24)
6494 /* HSW can handle pixel rate up to cdclk? */
6495 if (IS_HASWELL(dev_priv
))
6499 * We compare against max which means we must take
6500 * the increased cdclk requirement into account when
6501 * calculating the new cdclk.
6503 * Should measure whether using a lower cdclk w/o IPS
6505 return ilk_pipe_pixel_rate(pipe_config
) <=
6506 dev_priv
->max_cdclk_freq
* 95 / 100;
6509 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
6510 struct intel_crtc_state
*pipe_config
)
6512 struct drm_device
*dev
= crtc
->base
.dev
;
6513 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6515 pipe_config
->ips_enabled
= i915
.enable_ips
&&
6516 hsw_crtc_supports_ips(crtc
) &&
6517 pipe_config_supports_ips(dev_priv
, pipe_config
);
6520 static bool intel_crtc_supports_double_wide(const struct intel_crtc
*crtc
)
6522 const struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6524 /* GDG double wide on either pipe, otherwise pipe A only */
6525 return INTEL_INFO(dev_priv
)->gen
< 4 &&
6526 (crtc
->pipe
== PIPE_A
|| IS_I915G(dev_priv
));
6529 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
6530 struct intel_crtc_state
*pipe_config
)
6532 struct drm_device
*dev
= crtc
->base
.dev
;
6533 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6534 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6536 /* FIXME should check pixel clock limits on all platforms */
6537 if (INTEL_INFO(dev
)->gen
< 4) {
6538 int clock_limit
= dev_priv
->max_cdclk_freq
* 9 / 10;
6541 * Enable double wide mode when the dot clock
6542 * is > 90% of the (display) core speed.
6544 if (intel_crtc_supports_double_wide(crtc
) &&
6545 adjusted_mode
->crtc_clock
> clock_limit
) {
6547 pipe_config
->double_wide
= true;
6550 if (adjusted_mode
->crtc_clock
> clock_limit
) {
6551 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6552 adjusted_mode
->crtc_clock
, clock_limit
,
6553 yesno(pipe_config
->double_wide
));
6559 * Pipe horizontal size must be even in:
6561 * - LVDS dual channel mode
6562 * - Double wide pipe
6564 if ((intel_pipe_will_have_type(pipe_config
, INTEL_OUTPUT_LVDS
) &&
6565 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
6566 pipe_config
->pipe_src_w
&= ~1;
6568 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6569 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6571 if ((INTEL_INFO(dev
)->gen
> 4 || IS_G4X(dev
)) &&
6572 adjusted_mode
->crtc_hsync_start
== adjusted_mode
->crtc_hdisplay
)
6576 hsw_compute_ips_config(crtc
, pipe_config
);
6578 if (pipe_config
->has_pch_encoder
)
6579 return ironlake_fdi_compute_config(crtc
, pipe_config
);
6584 static int skylake_get_display_clock_speed(struct drm_device
*dev
)
6586 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6589 skl_dpll0_update(dev_priv
);
6591 if (dev_priv
->skl_vco_freq
== 0)
6592 return 24000; /* 24MHz is the cd freq with NSSC ref */
6594 cdctl
= I915_READ(CDCLK_CTL
);
6596 if (dev_priv
->skl_vco_freq
== 8640) {
6597 switch (cdctl
& CDCLK_FREQ_SEL_MASK
) {
6598 case CDCLK_FREQ_450_432
:
6600 case CDCLK_FREQ_337_308
:
6602 case CDCLK_FREQ_540
:
6604 case CDCLK_FREQ_675_617
:
6607 MISSING_CASE(cdctl
& CDCLK_FREQ_SEL_MASK
);
6610 switch (cdctl
& CDCLK_FREQ_SEL_MASK
) {
6611 case CDCLK_FREQ_450_432
:
6613 case CDCLK_FREQ_337_308
:
6615 case CDCLK_FREQ_540
:
6617 case CDCLK_FREQ_675_617
:
6620 MISSING_CASE(cdctl
& CDCLK_FREQ_SEL_MASK
);
6624 /* error case, do as if DPLL0 isn't enabled */
6628 static int broxton_get_display_clock_speed(struct drm_device
*dev
)
6630 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6631 uint32_t cdctl
= I915_READ(CDCLK_CTL
);
6632 uint32_t pll_ratio
= I915_READ(BXT_DE_PLL_CTL
) & BXT_DE_PLL_RATIO_MASK
;
6633 uint32_t pll_enab
= I915_READ(BXT_DE_PLL_ENABLE
);
6636 if (!(pll_enab
& BXT_DE_PLL_PLL_ENABLE
))
6639 cdclk
= 19200 * pll_ratio
/ 2;
6641 switch (cdctl
& BXT_CDCLK_CD2X_DIV_SEL_MASK
) {
6642 case BXT_CDCLK_CD2X_DIV_SEL_1
:
6643 return cdclk
; /* 576MHz or 624MHz */
6644 case BXT_CDCLK_CD2X_DIV_SEL_1_5
:
6645 return cdclk
* 2 / 3; /* 384MHz */
6646 case BXT_CDCLK_CD2X_DIV_SEL_2
:
6647 return cdclk
/ 2; /* 288MHz */
6648 case BXT_CDCLK_CD2X_DIV_SEL_4
:
6649 return cdclk
/ 4; /* 144MHz */
6652 /* error case, do as if DE PLL isn't enabled */
6656 static int broadwell_get_display_clock_speed(struct drm_device
*dev
)
6658 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6659 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
6660 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
6662 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
6664 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
6666 else if (freq
== LCPLL_CLK_FREQ_450
)
6668 else if (freq
== LCPLL_CLK_FREQ_54O_BDW
)
6670 else if (freq
== LCPLL_CLK_FREQ_337_5_BDW
)
6676 static int haswell_get_display_clock_speed(struct drm_device
*dev
)
6678 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6679 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
6680 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
6682 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
6684 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
6686 else if (freq
== LCPLL_CLK_FREQ_450
)
6688 else if (IS_HSW_ULT(dev
))
6694 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
6696 return vlv_get_cck_clock_hpll(to_i915(dev
), "cdclk",
6697 CCK_DISPLAY_CLOCK_CONTROL
);
6700 static int ilk_get_display_clock_speed(struct drm_device
*dev
)
6705 static int i945_get_display_clock_speed(struct drm_device
*dev
)
6710 static int i915_get_display_clock_speed(struct drm_device
*dev
)
6715 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
6720 static int pnv_get_display_clock_speed(struct drm_device
*dev
)
6724 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
6726 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
6727 case GC_DISPLAY_CLOCK_267_MHZ_PNV
:
6729 case GC_DISPLAY_CLOCK_333_MHZ_PNV
:
6731 case GC_DISPLAY_CLOCK_444_MHZ_PNV
:
6733 case GC_DISPLAY_CLOCK_200_MHZ_PNV
:
6736 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc
);
6737 case GC_DISPLAY_CLOCK_133_MHZ_PNV
:
6739 case GC_DISPLAY_CLOCK_167_MHZ_PNV
:
6744 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
6748 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
6750 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
6753 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
6754 case GC_DISPLAY_CLOCK_333_MHZ
:
6757 case GC_DISPLAY_CLOCK_190_200_MHZ
:
6763 static int i865_get_display_clock_speed(struct drm_device
*dev
)
6768 static int i85x_get_display_clock_speed(struct drm_device
*dev
)
6773 * 852GM/852GMV only supports 133 MHz and the HPLLCC
6774 * encoding is different :(
6775 * FIXME is this the right way to detect 852GM/852GMV?
6777 if (dev
->pdev
->revision
== 0x1)
6780 pci_bus_read_config_word(dev
->pdev
->bus
,
6781 PCI_DEVFN(0, 3), HPLLCC
, &hpllcc
);
6783 /* Assume that the hardware is in the high speed state. This
6784 * should be the default.
6786 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
6787 case GC_CLOCK_133_200
:
6788 case GC_CLOCK_133_200_2
:
6789 case GC_CLOCK_100_200
:
6791 case GC_CLOCK_166_250
:
6793 case GC_CLOCK_100_133
:
6795 case GC_CLOCK_133_266
:
6796 case GC_CLOCK_133_266_2
:
6797 case GC_CLOCK_166_266
:
6801 /* Shouldn't happen */
6805 static int i830_get_display_clock_speed(struct drm_device
*dev
)
6810 static unsigned int intel_hpll_vco(struct drm_device
*dev
)
6812 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6813 static const unsigned int blb_vco
[8] = {
6820 static const unsigned int pnv_vco
[8] = {
6827 static const unsigned int cl_vco
[8] = {
6836 static const unsigned int elk_vco
[8] = {
6842 static const unsigned int ctg_vco
[8] = {
6850 const unsigned int *vco_table
;
6854 /* FIXME other chipsets? */
6856 vco_table
= ctg_vco
;
6857 else if (IS_G4X(dev
))
6858 vco_table
= elk_vco
;
6859 else if (IS_CRESTLINE(dev
))
6861 else if (IS_PINEVIEW(dev
))
6862 vco_table
= pnv_vco
;
6863 else if (IS_G33(dev
))
6864 vco_table
= blb_vco
;
6868 tmp
= I915_READ(IS_MOBILE(dev
) ? HPLLVCO_MOBILE
: HPLLVCO
);
6870 vco
= vco_table
[tmp
& 0x7];
6872 DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp
);
6874 DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco
);
6879 static int gm45_get_display_clock_speed(struct drm_device
*dev
)
6881 unsigned int cdclk_sel
, vco
= intel_hpll_vco(dev
);
6884 pci_read_config_word(dev
->pdev
, GCFGC
, &tmp
);
6886 cdclk_sel
= (tmp
>> 12) & 0x1;
6892 return cdclk_sel
? 333333 : 222222;
6894 return cdclk_sel
? 320000 : 228571;
6896 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco
, tmp
);
6901 static int i965gm_get_display_clock_speed(struct drm_device
*dev
)
6903 static const uint8_t div_3200
[] = { 16, 10, 8 };
6904 static const uint8_t div_4000
[] = { 20, 12, 10 };
6905 static const uint8_t div_5333
[] = { 24, 16, 14 };
6906 const uint8_t *div_table
;
6907 unsigned int cdclk_sel
, vco
= intel_hpll_vco(dev
);
6910 pci_read_config_word(dev
->pdev
, GCFGC
, &tmp
);
6912 cdclk_sel
= ((tmp
>> 8) & 0x1f) - 1;
6914 if (cdclk_sel
>= ARRAY_SIZE(div_3200
))
6919 div_table
= div_3200
;
6922 div_table
= div_4000
;
6925 div_table
= div_5333
;
6931 return DIV_ROUND_CLOSEST(vco
, div_table
[cdclk_sel
]);
6934 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco
, tmp
);
6938 static int g33_get_display_clock_speed(struct drm_device
*dev
)
6940 static const uint8_t div_3200
[] = { 12, 10, 8, 7, 5, 16 };
6941 static const uint8_t div_4000
[] = { 14, 12, 10, 8, 6, 20 };
6942 static const uint8_t div_4800
[] = { 20, 14, 12, 10, 8, 24 };
6943 static const uint8_t div_5333
[] = { 20, 16, 12, 12, 8, 28 };
6944 const uint8_t *div_table
;
6945 unsigned int cdclk_sel
, vco
= intel_hpll_vco(dev
);
6948 pci_read_config_word(dev
->pdev
, GCFGC
, &tmp
);
6950 cdclk_sel
= (tmp
>> 4) & 0x7;
6952 if (cdclk_sel
>= ARRAY_SIZE(div_3200
))
6957 div_table
= div_3200
;
6960 div_table
= div_4000
;
6963 div_table
= div_4800
;
6966 div_table
= div_5333
;
6972 return DIV_ROUND_CLOSEST(vco
, div_table
[cdclk_sel
]);
6975 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco
, tmp
);
6980 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
6982 while (*num
> DATA_LINK_M_N_MASK
||
6983 *den
> DATA_LINK_M_N_MASK
) {
6989 static void compute_m_n(unsigned int m
, unsigned int n
,
6990 uint32_t *ret_m
, uint32_t *ret_n
)
6992 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
6993 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
6994 intel_reduce_m_n_ratio(ret_m
, ret_n
);
6998 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
6999 int pixel_clock
, int link_clock
,
7000 struct intel_link_m_n
*m_n
)
7004 compute_m_n(bits_per_pixel
* pixel_clock
,
7005 link_clock
* nlanes
* 8,
7006 &m_n
->gmch_m
, &m_n
->gmch_n
);
7008 compute_m_n(pixel_clock
, link_clock
,
7009 &m_n
->link_m
, &m_n
->link_n
);
7012 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
7014 if (i915
.panel_use_ssc
>= 0)
7015 return i915
.panel_use_ssc
!= 0;
7016 return dev_priv
->vbt
.lvds_use_ssc
7017 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
7020 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
7022 return (1 << dpll
->n
) << 16 | dpll
->m2
;
7025 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
7027 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
7030 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
7031 struct intel_crtc_state
*crtc_state
,
7032 struct dpll
*reduced_clock
)
7034 struct drm_device
*dev
= crtc
->base
.dev
;
7037 if (IS_PINEVIEW(dev
)) {
7038 fp
= pnv_dpll_compute_fp(&crtc_state
->dpll
);
7040 fp2
= pnv_dpll_compute_fp(reduced_clock
);
7042 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
7044 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
7047 crtc_state
->dpll_hw_state
.fp0
= fp
;
7049 crtc
->lowfreq_avail
= false;
7050 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
7052 crtc_state
->dpll_hw_state
.fp1
= fp2
;
7053 crtc
->lowfreq_avail
= true;
7055 crtc_state
->dpll_hw_state
.fp1
= fp
;
7059 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
7065 * PLLB opamp always calibrates to max value of 0x3f, force enable it
7066 * and set it to a reasonable value instead.
7068 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
7069 reg_val
&= 0xffffff00;
7070 reg_val
|= 0x00000030;
7071 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
7073 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
7074 reg_val
&= 0x8cffffff;
7075 reg_val
= 0x8c000000;
7076 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
7078 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
7079 reg_val
&= 0xffffff00;
7080 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
7082 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
7083 reg_val
&= 0x00ffffff;
7084 reg_val
|= 0xb0000000;
7085 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
7088 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
7089 struct intel_link_m_n
*m_n
)
7091 struct drm_device
*dev
= crtc
->base
.dev
;
7092 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7093 int pipe
= crtc
->pipe
;
7095 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
7096 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
7097 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
7098 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
7101 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
7102 struct intel_link_m_n
*m_n
,
7103 struct intel_link_m_n
*m2_n2
)
7105 struct drm_device
*dev
= crtc
->base
.dev
;
7106 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7107 int pipe
= crtc
->pipe
;
7108 enum transcoder transcoder
= crtc
->config
->cpu_transcoder
;
7110 if (INTEL_INFO(dev
)->gen
>= 5) {
7111 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
7112 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
7113 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
7114 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
7115 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
7116 * for gen < 8) and if DRRS is supported (to make sure the
7117 * registers are not unnecessarily accessed).
7119 if (m2_n2
&& (IS_CHERRYVIEW(dev
) || INTEL_INFO(dev
)->gen
< 8) &&
7120 crtc
->config
->has_drrs
) {
7121 I915_WRITE(PIPE_DATA_M2(transcoder
),
7122 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
7123 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
7124 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
7125 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
7128 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
7129 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
7130 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
7131 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
7135 void intel_dp_set_m_n(struct intel_crtc
*crtc
, enum link_m_n_set m_n
)
7137 struct intel_link_m_n
*dp_m_n
, *dp_m2_n2
= NULL
;
7140 dp_m_n
= &crtc
->config
->dp_m_n
;
7141 dp_m2_n2
= &crtc
->config
->dp_m2_n2
;
7142 } else if (m_n
== M2_N2
) {
7145 * M2_N2 registers are not supported. Hence m2_n2 divider value
7146 * needs to be programmed into M1_N1.
7148 dp_m_n
= &crtc
->config
->dp_m2_n2
;
7150 DRM_ERROR("Unsupported divider value\n");
7154 if (crtc
->config
->has_pch_encoder
)
7155 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
->dp_m_n
);
7157 intel_cpu_transcoder_set_m_n(crtc
, dp_m_n
, dp_m2_n2
);
7160 static void vlv_compute_dpll(struct intel_crtc
*crtc
,
7161 struct intel_crtc_state
*pipe_config
)
7163 pipe_config
->dpll_hw_state
.dpll
= DPLL_INTEGRATED_REF_CLK_VLV
|
7164 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
7165 if (crtc
->pipe
!= PIPE_A
)
7166 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
7168 /* DPLL not used with DSI, but still need the rest set up */
7169 if (!pipe_config
->has_dsi_encoder
)
7170 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
|
7171 DPLL_EXT_BUFFER_ENABLE_VLV
;
7173 pipe_config
->dpll_hw_state
.dpll_md
=
7174 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
7177 static void chv_compute_dpll(struct intel_crtc
*crtc
,
7178 struct intel_crtc_state
*pipe_config
)
7180 pipe_config
->dpll_hw_state
.dpll
= DPLL_SSC_REF_CLK_CHV
|
7181 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
7182 if (crtc
->pipe
!= PIPE_A
)
7183 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
7185 /* DPLL not used with DSI, but still need the rest set up */
7186 if (!pipe_config
->has_dsi_encoder
)
7187 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
;
7189 pipe_config
->dpll_hw_state
.dpll_md
=
7190 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
7193 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
7194 const struct intel_crtc_state
*pipe_config
)
7196 struct drm_device
*dev
= crtc
->base
.dev
;
7197 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7198 enum pipe pipe
= crtc
->pipe
;
7200 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
7201 u32 coreclk
, reg_val
;
7204 I915_WRITE(DPLL(pipe
),
7205 pipe_config
->dpll_hw_state
.dpll
&
7206 ~(DPLL_VCO_ENABLE
| DPLL_EXT_BUFFER_ENABLE_VLV
));
7208 /* No need to actually set up the DPLL with DSI */
7209 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7212 mutex_lock(&dev_priv
->sb_lock
);
7214 bestn
= pipe_config
->dpll
.n
;
7215 bestm1
= pipe_config
->dpll
.m1
;
7216 bestm2
= pipe_config
->dpll
.m2
;
7217 bestp1
= pipe_config
->dpll
.p1
;
7218 bestp2
= pipe_config
->dpll
.p2
;
7220 /* See eDP HDMI DPIO driver vbios notes doc */
7222 /* PLL B needs special handling */
7224 vlv_pllb_recal_opamp(dev_priv
, pipe
);
7226 /* Set up Tx target for periodic Rcomp update */
7227 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
7229 /* Disable target IRef on PLL */
7230 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
7231 reg_val
&= 0x00ffffff;
7232 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
7234 /* Disable fast lock */
7235 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
7237 /* Set idtafcrecal before PLL is enabled */
7238 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
7239 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
7240 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
7241 mdiv
|= (1 << DPIO_K_SHIFT
);
7244 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7245 * but we don't support that).
7246 * Note: don't use the DAC post divider as it seems unstable.
7248 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
7249 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
7251 mdiv
|= DPIO_ENABLE_CALIBRATION
;
7252 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
7254 /* Set HBR and RBR LPF coefficients */
7255 if (pipe_config
->port_clock
== 162000 ||
7256 intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
) ||
7257 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
))
7258 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
7261 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
7264 if (pipe_config
->has_dp_encoder
) {
7265 /* Use SSC source */
7267 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7270 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7272 } else { /* HDMI or VGA */
7273 /* Use bend source */
7275 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7278 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7282 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
7283 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
7284 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
7285 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))
7286 coreclk
|= 0x01000000;
7287 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
7289 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
7290 mutex_unlock(&dev_priv
->sb_lock
);
7293 static void chv_prepare_pll(struct intel_crtc
*crtc
,
7294 const struct intel_crtc_state
*pipe_config
)
7296 struct drm_device
*dev
= crtc
->base
.dev
;
7297 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7298 enum pipe pipe
= crtc
->pipe
;
7299 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
7300 u32 loopfilter
, tribuf_calcntr
;
7301 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
7305 /* Enable Refclk and SSC */
7306 I915_WRITE(DPLL(pipe
),
7307 pipe_config
->dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
7309 /* No need to actually set up the DPLL with DSI */
7310 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7313 bestn
= pipe_config
->dpll
.n
;
7314 bestm2_frac
= pipe_config
->dpll
.m2
& 0x3fffff;
7315 bestm1
= pipe_config
->dpll
.m1
;
7316 bestm2
= pipe_config
->dpll
.m2
>> 22;
7317 bestp1
= pipe_config
->dpll
.p1
;
7318 bestp2
= pipe_config
->dpll
.p2
;
7319 vco
= pipe_config
->dpll
.vco
;
7323 mutex_lock(&dev_priv
->sb_lock
);
7325 /* p1 and p2 divider */
7326 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
7327 5 << DPIO_CHV_S1_DIV_SHIFT
|
7328 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
7329 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
7330 1 << DPIO_CHV_K_DIV_SHIFT
);
7332 /* Feedback post-divider - m2 */
7333 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
7335 /* Feedback refclk divider - n and m1 */
7336 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
7337 DPIO_CHV_M1_DIV_BY_2
|
7338 1 << DPIO_CHV_N_DIV_SHIFT
);
7340 /* M2 fraction division */
7341 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
7343 /* M2 fraction division enable */
7344 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
7345 dpio_val
&= ~(DPIO_CHV_FEEDFWD_GAIN_MASK
| DPIO_CHV_FRAC_DIV_EN
);
7346 dpio_val
|= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
);
7348 dpio_val
|= DPIO_CHV_FRAC_DIV_EN
;
7349 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
), dpio_val
);
7351 /* Program digital lock detect threshold */
7352 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW9(port
));
7353 dpio_val
&= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK
|
7354 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
);
7355 dpio_val
|= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT
);
7357 dpio_val
|= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
;
7358 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW9(port
), dpio_val
);
7361 if (vco
== 5400000) {
7362 loopfilter
|= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT
);
7363 loopfilter
|= (0x8 << DPIO_CHV_INT_COEFF_SHIFT
);
7364 loopfilter
|= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7365 tribuf_calcntr
= 0x9;
7366 } else if (vco
<= 6200000) {
7367 loopfilter
|= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT
);
7368 loopfilter
|= (0xB << DPIO_CHV_INT_COEFF_SHIFT
);
7369 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7370 tribuf_calcntr
= 0x9;
7371 } else if (vco
<= 6480000) {
7372 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
7373 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
7374 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7375 tribuf_calcntr
= 0x8;
7377 /* Not supported. Apply the same limits as in the max case */
7378 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
7379 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
7380 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7383 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
7385 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW8(port
));
7386 dpio_val
&= ~DPIO_CHV_TDC_TARGET_CNT_MASK
;
7387 dpio_val
|= (tribuf_calcntr
<< DPIO_CHV_TDC_TARGET_CNT_SHIFT
);
7388 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW8(port
), dpio_val
);
7391 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
7392 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
7395 mutex_unlock(&dev_priv
->sb_lock
);
7399 * vlv_force_pll_on - forcibly enable just the PLL
7400 * @dev_priv: i915 private structure
7401 * @pipe: pipe PLL to enable
7402 * @dpll: PLL configuration
7404 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7405 * in cases where we need the PLL enabled even when @pipe is not going to
7408 int vlv_force_pll_on(struct drm_device
*dev
, enum pipe pipe
,
7409 const struct dpll
*dpll
)
7411 struct intel_crtc
*crtc
=
7412 to_intel_crtc(intel_get_crtc_for_pipe(dev
, pipe
));
7413 struct intel_crtc_state
*pipe_config
;
7415 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
7419 pipe_config
->base
.crtc
= &crtc
->base
;
7420 pipe_config
->pixel_multiplier
= 1;
7421 pipe_config
->dpll
= *dpll
;
7423 if (IS_CHERRYVIEW(dev
)) {
7424 chv_compute_dpll(crtc
, pipe_config
);
7425 chv_prepare_pll(crtc
, pipe_config
);
7426 chv_enable_pll(crtc
, pipe_config
);
7428 vlv_compute_dpll(crtc
, pipe_config
);
7429 vlv_prepare_pll(crtc
, pipe_config
);
7430 vlv_enable_pll(crtc
, pipe_config
);
7439 * vlv_force_pll_off - forcibly disable just the PLL
7440 * @dev_priv: i915 private structure
7441 * @pipe: pipe PLL to disable
7443 * Disable the PLL for @pipe. To be used in cases where we need
7444 * the PLL enabled even when @pipe is not going to be enabled.
7446 void vlv_force_pll_off(struct drm_device
*dev
, enum pipe pipe
)
7448 if (IS_CHERRYVIEW(dev
))
7449 chv_disable_pll(to_i915(dev
), pipe
);
7451 vlv_disable_pll(to_i915(dev
), pipe
);
7454 static void i9xx_compute_dpll(struct intel_crtc
*crtc
,
7455 struct intel_crtc_state
*crtc_state
,
7456 struct dpll
*reduced_clock
)
7458 struct drm_device
*dev
= crtc
->base
.dev
;
7459 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7462 struct dpll
*clock
= &crtc_state
->dpll
;
7464 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
7466 is_sdvo
= intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
7467 intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_HDMI
);
7469 dpll
= DPLL_VGA_MODE_DIS
;
7471 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
))
7472 dpll
|= DPLLB_MODE_LVDS
;
7474 dpll
|= DPLLB_MODE_DAC_SERIAL
;
7476 if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
7477 dpll
|= (crtc_state
->pixel_multiplier
- 1)
7478 << SDVO_MULTIPLIER_SHIFT_HIRES
;
7482 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7484 if (crtc_state
->has_dp_encoder
)
7485 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7487 /* compute bitmask from p1 value */
7488 if (IS_PINEVIEW(dev
))
7489 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
7491 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7492 if (IS_G4X(dev
) && reduced_clock
)
7493 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
7495 switch (clock
->p2
) {
7497 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
7500 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
7503 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
7506 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
7509 if (INTEL_INFO(dev
)->gen
>= 4)
7510 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
7512 if (crtc_state
->sdvo_tv_clock
)
7513 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
7514 else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
7515 intel_panel_use_ssc(dev_priv
))
7516 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7518 dpll
|= PLL_REF_INPUT_DREFCLK
;
7520 dpll
|= DPLL_VCO_ENABLE
;
7521 crtc_state
->dpll_hw_state
.dpll
= dpll
;
7523 if (INTEL_INFO(dev
)->gen
>= 4) {
7524 u32 dpll_md
= (crtc_state
->pixel_multiplier
- 1)
7525 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
7526 crtc_state
->dpll_hw_state
.dpll_md
= dpll_md
;
7530 static void i8xx_compute_dpll(struct intel_crtc
*crtc
,
7531 struct intel_crtc_state
*crtc_state
,
7532 struct dpll
*reduced_clock
)
7534 struct drm_device
*dev
= crtc
->base
.dev
;
7535 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7537 struct dpll
*clock
= &crtc_state
->dpll
;
7539 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
7541 dpll
= DPLL_VGA_MODE_DIS
;
7543 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7544 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7547 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
7549 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7551 dpll
|= PLL_P2_DIVIDE_BY_4
;
7554 if (!IS_I830(dev
) && intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_DVO
))
7555 dpll
|= DPLL_DVO_2X_MODE
;
7557 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
7558 intel_panel_use_ssc(dev_priv
))
7559 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7561 dpll
|= PLL_REF_INPUT_DREFCLK
;
7563 dpll
|= DPLL_VCO_ENABLE
;
7564 crtc_state
->dpll_hw_state
.dpll
= dpll
;
7567 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
7569 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7570 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7571 enum pipe pipe
= intel_crtc
->pipe
;
7572 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
7573 const struct drm_display_mode
*adjusted_mode
= &intel_crtc
->config
->base
.adjusted_mode
;
7574 uint32_t crtc_vtotal
, crtc_vblank_end
;
7577 /* We need to be careful not to changed the adjusted mode, for otherwise
7578 * the hw state checker will get angry at the mismatch. */
7579 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
7580 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
7582 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
7583 /* the chip adds 2 halflines automatically */
7585 crtc_vblank_end
-= 1;
7587 if (intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
7588 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
7590 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
7591 adjusted_mode
->crtc_htotal
/ 2;
7593 vsyncshift
+= adjusted_mode
->crtc_htotal
;
7596 if (INTEL_INFO(dev
)->gen
> 3)
7597 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
7599 I915_WRITE(HTOTAL(cpu_transcoder
),
7600 (adjusted_mode
->crtc_hdisplay
- 1) |
7601 ((adjusted_mode
->crtc_htotal
- 1) << 16));
7602 I915_WRITE(HBLANK(cpu_transcoder
),
7603 (adjusted_mode
->crtc_hblank_start
- 1) |
7604 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
7605 I915_WRITE(HSYNC(cpu_transcoder
),
7606 (adjusted_mode
->crtc_hsync_start
- 1) |
7607 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
7609 I915_WRITE(VTOTAL(cpu_transcoder
),
7610 (adjusted_mode
->crtc_vdisplay
- 1) |
7611 ((crtc_vtotal
- 1) << 16));
7612 I915_WRITE(VBLANK(cpu_transcoder
),
7613 (adjusted_mode
->crtc_vblank_start
- 1) |
7614 ((crtc_vblank_end
- 1) << 16));
7615 I915_WRITE(VSYNC(cpu_transcoder
),
7616 (adjusted_mode
->crtc_vsync_start
- 1) |
7617 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
7619 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7620 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7621 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7623 if (IS_HASWELL(dev
) && cpu_transcoder
== TRANSCODER_EDP
&&
7624 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
7625 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
7629 static void intel_set_pipe_src_size(struct intel_crtc
*intel_crtc
)
7631 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7632 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7633 enum pipe pipe
= intel_crtc
->pipe
;
7635 /* pipesrc controls the size that is scaled from, which should
7636 * always be the user's requested size.
7638 I915_WRITE(PIPESRC(pipe
),
7639 ((intel_crtc
->config
->pipe_src_w
- 1) << 16) |
7640 (intel_crtc
->config
->pipe_src_h
- 1));
7643 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
7644 struct intel_crtc_state
*pipe_config
)
7646 struct drm_device
*dev
= crtc
->base
.dev
;
7647 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7648 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
7651 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
7652 pipe_config
->base
.adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
7653 pipe_config
->base
.adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
7654 tmp
= I915_READ(HBLANK(cpu_transcoder
));
7655 pipe_config
->base
.adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
7656 pipe_config
->base
.adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
7657 tmp
= I915_READ(HSYNC(cpu_transcoder
));
7658 pipe_config
->base
.adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
7659 pipe_config
->base
.adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
7661 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
7662 pipe_config
->base
.adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
7663 pipe_config
->base
.adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
7664 tmp
= I915_READ(VBLANK(cpu_transcoder
));
7665 pipe_config
->base
.adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
7666 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
7667 tmp
= I915_READ(VSYNC(cpu_transcoder
));
7668 pipe_config
->base
.adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
7669 pipe_config
->base
.adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
7671 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
7672 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
7673 pipe_config
->base
.adjusted_mode
.crtc_vtotal
+= 1;
7674 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
+= 1;
7678 static void intel_get_pipe_src_size(struct intel_crtc
*crtc
,
7679 struct intel_crtc_state
*pipe_config
)
7681 struct drm_device
*dev
= crtc
->base
.dev
;
7682 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7685 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
7686 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
7687 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
7689 pipe_config
->base
.mode
.vdisplay
= pipe_config
->pipe_src_h
;
7690 pipe_config
->base
.mode
.hdisplay
= pipe_config
->pipe_src_w
;
7693 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
7694 struct intel_crtc_state
*pipe_config
)
7696 mode
->hdisplay
= pipe_config
->base
.adjusted_mode
.crtc_hdisplay
;
7697 mode
->htotal
= pipe_config
->base
.adjusted_mode
.crtc_htotal
;
7698 mode
->hsync_start
= pipe_config
->base
.adjusted_mode
.crtc_hsync_start
;
7699 mode
->hsync_end
= pipe_config
->base
.adjusted_mode
.crtc_hsync_end
;
7701 mode
->vdisplay
= pipe_config
->base
.adjusted_mode
.crtc_vdisplay
;
7702 mode
->vtotal
= pipe_config
->base
.adjusted_mode
.crtc_vtotal
;
7703 mode
->vsync_start
= pipe_config
->base
.adjusted_mode
.crtc_vsync_start
;
7704 mode
->vsync_end
= pipe_config
->base
.adjusted_mode
.crtc_vsync_end
;
7706 mode
->flags
= pipe_config
->base
.adjusted_mode
.flags
;
7707 mode
->type
= DRM_MODE_TYPE_DRIVER
;
7709 mode
->clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
7710 mode
->flags
|= pipe_config
->base
.adjusted_mode
.flags
;
7712 mode
->hsync
= drm_mode_hsync(mode
);
7713 mode
->vrefresh
= drm_mode_vrefresh(mode
);
7714 drm_mode_set_name(mode
);
7717 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
7719 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7720 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7725 if ((intel_crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
7726 (intel_crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
7727 pipeconf
|= I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
;
7729 if (intel_crtc
->config
->double_wide
)
7730 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
7732 /* only g4x and later have fancy bpc/dither controls */
7733 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
7734 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7735 if (intel_crtc
->config
->dither
&& intel_crtc
->config
->pipe_bpp
!= 30)
7736 pipeconf
|= PIPECONF_DITHER_EN
|
7737 PIPECONF_DITHER_TYPE_SP
;
7739 switch (intel_crtc
->config
->pipe_bpp
) {
7741 pipeconf
|= PIPECONF_6BPC
;
7744 pipeconf
|= PIPECONF_8BPC
;
7747 pipeconf
|= PIPECONF_10BPC
;
7750 /* Case prevented by intel_choose_pipe_bpp_dither. */
7755 if (HAS_PIPE_CXSR(dev
)) {
7756 if (intel_crtc
->lowfreq_avail
) {
7757 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
7758 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
7760 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
7764 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
7765 if (INTEL_INFO(dev
)->gen
< 4 ||
7766 intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
7767 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
7769 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
7771 pipeconf
|= PIPECONF_PROGRESSIVE
;
7773 if ((IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) &&
7774 intel_crtc
->config
->limited_color_range
)
7775 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
7777 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
7778 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
7781 static int i8xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7782 struct intel_crtc_state
*crtc_state
)
7784 struct drm_device
*dev
= crtc
->base
.dev
;
7785 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7786 const struct intel_limit
*limit
;
7789 memset(&crtc_state
->dpll_hw_state
, 0,
7790 sizeof(crtc_state
->dpll_hw_state
));
7792 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7793 if (intel_panel_use_ssc(dev_priv
)) {
7794 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7795 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7798 limit
= &intel_limits_i8xx_lvds
;
7799 } else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_DVO
)) {
7800 limit
= &intel_limits_i8xx_dvo
;
7802 limit
= &intel_limits_i8xx_dac
;
7805 if (!crtc_state
->clock_set
&&
7806 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7807 refclk
, NULL
, &crtc_state
->dpll
)) {
7808 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7812 i8xx_compute_dpll(crtc
, crtc_state
, NULL
);
7817 static int g4x_crtc_compute_clock(struct intel_crtc
*crtc
,
7818 struct intel_crtc_state
*crtc_state
)
7820 struct drm_device
*dev
= crtc
->base
.dev
;
7821 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7822 const struct intel_limit
*limit
;
7825 memset(&crtc_state
->dpll_hw_state
, 0,
7826 sizeof(crtc_state
->dpll_hw_state
));
7828 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7829 if (intel_panel_use_ssc(dev_priv
)) {
7830 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7831 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7834 if (intel_is_dual_link_lvds(dev
))
7835 limit
= &intel_limits_g4x_dual_channel_lvds
;
7837 limit
= &intel_limits_g4x_single_channel_lvds
;
7838 } else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_HDMI
) ||
7839 intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_ANALOG
)) {
7840 limit
= &intel_limits_g4x_hdmi
;
7841 } else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_SDVO
)) {
7842 limit
= &intel_limits_g4x_sdvo
;
7844 /* The option is for other outputs */
7845 limit
= &intel_limits_i9xx_sdvo
;
7848 if (!crtc_state
->clock_set
&&
7849 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7850 refclk
, NULL
, &crtc_state
->dpll
)) {
7851 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7855 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7860 static int pnv_crtc_compute_clock(struct intel_crtc
*crtc
,
7861 struct intel_crtc_state
*crtc_state
)
7863 struct drm_device
*dev
= crtc
->base
.dev
;
7864 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7865 const struct intel_limit
*limit
;
7868 memset(&crtc_state
->dpll_hw_state
, 0,
7869 sizeof(crtc_state
->dpll_hw_state
));
7871 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7872 if (intel_panel_use_ssc(dev_priv
)) {
7873 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7874 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7877 limit
= &intel_limits_pineview_lvds
;
7879 limit
= &intel_limits_pineview_sdvo
;
7882 if (!crtc_state
->clock_set
&&
7883 !pnv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7884 refclk
, NULL
, &crtc_state
->dpll
)) {
7885 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7889 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7894 static int i9xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7895 struct intel_crtc_state
*crtc_state
)
7897 struct drm_device
*dev
= crtc
->base
.dev
;
7898 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7899 const struct intel_limit
*limit
;
7902 memset(&crtc_state
->dpll_hw_state
, 0,
7903 sizeof(crtc_state
->dpll_hw_state
));
7905 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7906 if (intel_panel_use_ssc(dev_priv
)) {
7907 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7908 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7911 limit
= &intel_limits_i9xx_lvds
;
7913 limit
= &intel_limits_i9xx_sdvo
;
7916 if (!crtc_state
->clock_set
&&
7917 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7918 refclk
, NULL
, &crtc_state
->dpll
)) {
7919 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7923 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7928 static int chv_crtc_compute_clock(struct intel_crtc
*crtc
,
7929 struct intel_crtc_state
*crtc_state
)
7931 int refclk
= 100000;
7932 const struct intel_limit
*limit
= &intel_limits_chv
;
7934 memset(&crtc_state
->dpll_hw_state
, 0,
7935 sizeof(crtc_state
->dpll_hw_state
));
7937 if (!crtc_state
->clock_set
&&
7938 !chv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7939 refclk
, NULL
, &crtc_state
->dpll
)) {
7940 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7944 chv_compute_dpll(crtc
, crtc_state
);
7949 static int vlv_crtc_compute_clock(struct intel_crtc
*crtc
,
7950 struct intel_crtc_state
*crtc_state
)
7952 int refclk
= 100000;
7953 const struct intel_limit
*limit
= &intel_limits_vlv
;
7955 memset(&crtc_state
->dpll_hw_state
, 0,
7956 sizeof(crtc_state
->dpll_hw_state
));
7958 if (!crtc_state
->clock_set
&&
7959 !vlv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7960 refclk
, NULL
, &crtc_state
->dpll
)) {
7961 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7965 vlv_compute_dpll(crtc
, crtc_state
);
7970 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
7971 struct intel_crtc_state
*pipe_config
)
7973 struct drm_device
*dev
= crtc
->base
.dev
;
7974 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7977 if (INTEL_INFO(dev
)->gen
<= 3 && (IS_I830(dev
) || !IS_MOBILE(dev
)))
7980 tmp
= I915_READ(PFIT_CONTROL
);
7981 if (!(tmp
& PFIT_ENABLE
))
7984 /* Check whether the pfit is attached to our pipe. */
7985 if (INTEL_INFO(dev
)->gen
< 4) {
7986 if (crtc
->pipe
!= PIPE_B
)
7989 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
7993 pipe_config
->gmch_pfit
.control
= tmp
;
7994 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
7997 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
7998 struct intel_crtc_state
*pipe_config
)
8000 struct drm_device
*dev
= crtc
->base
.dev
;
8001 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8002 int pipe
= pipe_config
->cpu_transcoder
;
8005 int refclk
= 100000;
8007 /* In case of DSI, DPLL will not be used */
8008 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
8011 mutex_lock(&dev_priv
->sb_lock
);
8012 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
8013 mutex_unlock(&dev_priv
->sb_lock
);
8015 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
8016 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
8017 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
8018 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
8019 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
8021 pipe_config
->port_clock
= vlv_calc_dpll_params(refclk
, &clock
);
8025 i9xx_get_initial_plane_config(struct intel_crtc
*crtc
,
8026 struct intel_initial_plane_config
*plane_config
)
8028 struct drm_device
*dev
= crtc
->base
.dev
;
8029 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8030 u32 val
, base
, offset
;
8031 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
8032 int fourcc
, pixel_format
;
8033 unsigned int aligned_height
;
8034 struct drm_framebuffer
*fb
;
8035 struct intel_framebuffer
*intel_fb
;
8037 val
= I915_READ(DSPCNTR(plane
));
8038 if (!(val
& DISPLAY_PLANE_ENABLE
))
8041 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8043 DRM_DEBUG_KMS("failed to alloc fb\n");
8047 fb
= &intel_fb
->base
;
8049 if (INTEL_INFO(dev
)->gen
>= 4) {
8050 if (val
& DISPPLANE_TILED
) {
8051 plane_config
->tiling
= I915_TILING_X
;
8052 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
8056 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
8057 fourcc
= i9xx_format_to_fourcc(pixel_format
);
8058 fb
->pixel_format
= fourcc
;
8059 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
8061 if (INTEL_INFO(dev
)->gen
>= 4) {
8062 if (plane_config
->tiling
)
8063 offset
= I915_READ(DSPTILEOFF(plane
));
8065 offset
= I915_READ(DSPLINOFF(plane
));
8066 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
8068 base
= I915_READ(DSPADDR(plane
));
8070 plane_config
->base
= base
;
8072 val
= I915_READ(PIPESRC(pipe
));
8073 fb
->width
= ((val
>> 16) & 0xfff) + 1;
8074 fb
->height
= ((val
>> 0) & 0xfff) + 1;
8076 val
= I915_READ(DSPSTRIDE(pipe
));
8077 fb
->pitches
[0] = val
& 0xffffffc0;
8079 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
8083 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8085 DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8086 pipe_name(pipe
), plane
, fb
->width
, fb
->height
,
8087 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
8088 plane_config
->size
);
8090 plane_config
->fb
= intel_fb
;
8093 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
8094 struct intel_crtc_state
*pipe_config
)
8096 struct drm_device
*dev
= crtc
->base
.dev
;
8097 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8098 int pipe
= pipe_config
->cpu_transcoder
;
8099 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
8101 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
, pll_dw3
;
8102 int refclk
= 100000;
8104 /* In case of DSI, DPLL will not be used */
8105 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
8108 mutex_lock(&dev_priv
->sb_lock
);
8109 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
8110 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
8111 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
8112 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
8113 pll_dw3
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
8114 mutex_unlock(&dev_priv
->sb_lock
);
8116 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
8117 clock
.m2
= (pll_dw0
& 0xff) << 22;
8118 if (pll_dw3
& DPIO_CHV_FRAC_DIV_EN
)
8119 clock
.m2
|= pll_dw2
& 0x3fffff;
8120 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
8121 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
8122 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
8124 pipe_config
->port_clock
= chv_calc_dpll_params(refclk
, &clock
);
8127 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
8128 struct intel_crtc_state
*pipe_config
)
8130 struct drm_device
*dev
= crtc
->base
.dev
;
8131 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8132 enum intel_display_power_domain power_domain
;
8136 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
8137 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8140 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8141 pipe_config
->shared_dpll
= NULL
;
8145 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
8146 if (!(tmp
& PIPECONF_ENABLE
))
8149 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
8150 switch (tmp
& PIPECONF_BPC_MASK
) {
8152 pipe_config
->pipe_bpp
= 18;
8155 pipe_config
->pipe_bpp
= 24;
8157 case PIPECONF_10BPC
:
8158 pipe_config
->pipe_bpp
= 30;
8165 if ((IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) &&
8166 (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
8167 pipe_config
->limited_color_range
= true;
8169 if (INTEL_INFO(dev
)->gen
< 4)
8170 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
8172 intel_get_pipe_timings(crtc
, pipe_config
);
8173 intel_get_pipe_src_size(crtc
, pipe_config
);
8175 i9xx_get_pfit_config(crtc
, pipe_config
);
8177 if (INTEL_INFO(dev
)->gen
>= 4) {
8178 /* No way to read it out on pipes B and C */
8179 if (IS_CHERRYVIEW(dev
) && crtc
->pipe
!= PIPE_A
)
8180 tmp
= dev_priv
->chv_dpll_md
[crtc
->pipe
];
8182 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
8183 pipe_config
->pixel_multiplier
=
8184 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
8185 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
8186 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
8187 } else if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
8188 tmp
= I915_READ(DPLL(crtc
->pipe
));
8189 pipe_config
->pixel_multiplier
=
8190 ((tmp
& SDVO_MULTIPLIER_MASK
)
8191 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
8193 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8194 * port and will be fixed up in the encoder->get_config
8196 pipe_config
->pixel_multiplier
= 1;
8198 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
8199 if (!IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
)) {
8201 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
8202 * on 830. Filter it out here so that we don't
8203 * report errors due to that.
8206 pipe_config
->dpll_hw_state
.dpll
&= ~DPLL_DVO_2X_MODE
;
8208 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
8209 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
8211 /* Mask out read-only status bits. */
8212 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
8213 DPLL_PORTC_READY_MASK
|
8214 DPLL_PORTB_READY_MASK
);
8217 if (IS_CHERRYVIEW(dev
))
8218 chv_crtc_clock_get(crtc
, pipe_config
);
8219 else if (IS_VALLEYVIEW(dev
))
8220 vlv_crtc_clock_get(crtc
, pipe_config
);
8222 i9xx_crtc_clock_get(crtc
, pipe_config
);
8225 * Normally the dotclock is filled in by the encoder .get_config()
8226 * but in case the pipe is enabled w/o any ports we need a sane
8229 pipe_config
->base
.adjusted_mode
.crtc_clock
=
8230 pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
8235 intel_display_power_put(dev_priv
, power_domain
);
8240 static void ironlake_init_pch_refclk(struct drm_device
*dev
)
8242 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8243 struct intel_encoder
*encoder
;
8245 bool has_lvds
= false;
8246 bool has_cpu_edp
= false;
8247 bool has_panel
= false;
8248 bool has_ck505
= false;
8249 bool can_ssc
= false;
8251 /* We need to take the global config into account */
8252 for_each_intel_encoder(dev
, encoder
) {
8253 switch (encoder
->type
) {
8254 case INTEL_OUTPUT_LVDS
:
8258 case INTEL_OUTPUT_EDP
:
8260 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
8268 if (HAS_PCH_IBX(dev
)) {
8269 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
8270 can_ssc
= has_ck505
;
8276 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
8277 has_panel
, has_lvds
, has_ck505
);
8279 /* Ironlake: try to setup display ref clock before DPLL
8280 * enabling. This is only under driver's control after
8281 * PCH B stepping, previous chipset stepping should be
8282 * ignoring this setting.
8284 val
= I915_READ(PCH_DREF_CONTROL
);
8286 /* As we must carefully and slowly disable/enable each source in turn,
8287 * compute the final state we want first and check if we need to
8288 * make any changes at all.
8291 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
8293 final
|= DREF_NONSPREAD_CK505_ENABLE
;
8295 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
8297 final
&= ~DREF_SSC_SOURCE_MASK
;
8298 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
8299 final
&= ~DREF_SSC1_ENABLE
;
8302 final
|= DREF_SSC_SOURCE_ENABLE
;
8304 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
8305 final
|= DREF_SSC1_ENABLE
;
8308 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
8309 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
8311 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
8313 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
8315 final
|= DREF_SSC_SOURCE_DISABLE
;
8316 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
8322 /* Always enable nonspread source */
8323 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
8326 val
|= DREF_NONSPREAD_CK505_ENABLE
;
8328 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
8331 val
&= ~DREF_SSC_SOURCE_MASK
;
8332 val
|= DREF_SSC_SOURCE_ENABLE
;
8334 /* SSC must be turned on before enabling the CPU output */
8335 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
8336 DRM_DEBUG_KMS("Using SSC on panel\n");
8337 val
|= DREF_SSC1_ENABLE
;
8339 val
&= ~DREF_SSC1_ENABLE
;
8341 /* Get SSC going before enabling the outputs */
8342 I915_WRITE(PCH_DREF_CONTROL
, val
);
8343 POSTING_READ(PCH_DREF_CONTROL
);
8346 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
8348 /* Enable CPU source on CPU attached eDP */
8350 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
8351 DRM_DEBUG_KMS("Using SSC on eDP\n");
8352 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
8354 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
8356 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
8358 I915_WRITE(PCH_DREF_CONTROL
, val
);
8359 POSTING_READ(PCH_DREF_CONTROL
);
8362 DRM_DEBUG_KMS("Disabling SSC entirely\n");
8364 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
8366 /* Turn off CPU output */
8367 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
8369 I915_WRITE(PCH_DREF_CONTROL
, val
);
8370 POSTING_READ(PCH_DREF_CONTROL
);
8373 /* Turn off the SSC source */
8374 val
&= ~DREF_SSC_SOURCE_MASK
;
8375 val
|= DREF_SSC_SOURCE_DISABLE
;
8378 val
&= ~DREF_SSC1_ENABLE
;
8380 I915_WRITE(PCH_DREF_CONTROL
, val
);
8381 POSTING_READ(PCH_DREF_CONTROL
);
8385 BUG_ON(val
!= final
);
8388 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
8392 tmp
= I915_READ(SOUTH_CHICKEN2
);
8393 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
8394 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
8396 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2
) &
8397 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
8398 DRM_ERROR("FDI mPHY reset assert timeout\n");
8400 tmp
= I915_READ(SOUTH_CHICKEN2
);
8401 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
8402 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
8404 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2
) &
8405 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
8406 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
8409 /* WaMPhyProgramming:hsw */
8410 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
8414 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
8415 tmp
&= ~(0xFF << 24);
8416 tmp
|= (0x12 << 24);
8417 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
8419 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
8421 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
8423 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
8425 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
8427 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
8428 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
8429 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
8431 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
8432 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
8433 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
8435 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
8438 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
8440 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
8443 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
8445 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
8448 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
8450 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
8453 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
8455 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
8456 tmp
&= ~(0xFF << 16);
8457 tmp
|= (0x1C << 16);
8458 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
8460 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
8461 tmp
&= ~(0xFF << 16);
8462 tmp
|= (0x1C << 16);
8463 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
8465 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
8467 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
8469 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
8471 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
8473 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
8474 tmp
&= ~(0xF << 28);
8476 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
8478 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
8479 tmp
&= ~(0xF << 28);
8481 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
8484 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8485 * Programming" based on the parameters passed:
8486 * - Sequence to enable CLKOUT_DP
8487 * - Sequence to enable CLKOUT_DP without spread
8488 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8490 static void lpt_enable_clkout_dp(struct drm_device
*dev
, bool with_spread
,
8493 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8496 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
8498 if (WARN(HAS_PCH_LPT_LP(dev
) && with_fdi
, "LP PCH doesn't have FDI\n"))
8501 mutex_lock(&dev_priv
->sb_lock
);
8503 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8504 tmp
&= ~SBI_SSCCTL_DISABLE
;
8505 tmp
|= SBI_SSCCTL_PATHALT
;
8506 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8511 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8512 tmp
&= ~SBI_SSCCTL_PATHALT
;
8513 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8516 lpt_reset_fdi_mphy(dev_priv
);
8517 lpt_program_fdi_mphy(dev_priv
);
8521 reg
= HAS_PCH_LPT_LP(dev
) ? SBI_GEN0
: SBI_DBUFF0
;
8522 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
8523 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
8524 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
8526 mutex_unlock(&dev_priv
->sb_lock
);
8529 /* Sequence to disable CLKOUT_DP */
8530 static void lpt_disable_clkout_dp(struct drm_device
*dev
)
8532 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8535 mutex_lock(&dev_priv
->sb_lock
);
8537 reg
= HAS_PCH_LPT_LP(dev
) ? SBI_GEN0
: SBI_DBUFF0
;
8538 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
8539 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
8540 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
8542 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8543 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
8544 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
8545 tmp
|= SBI_SSCCTL_PATHALT
;
8546 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8549 tmp
|= SBI_SSCCTL_DISABLE
;
8550 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8553 mutex_unlock(&dev_priv
->sb_lock
);
8556 #define BEND_IDX(steps) ((50 + (steps)) / 5)
8558 static const uint16_t sscdivintphase
[] = {
8559 [BEND_IDX( 50)] = 0x3B23,
8560 [BEND_IDX( 45)] = 0x3B23,
8561 [BEND_IDX( 40)] = 0x3C23,
8562 [BEND_IDX( 35)] = 0x3C23,
8563 [BEND_IDX( 30)] = 0x3D23,
8564 [BEND_IDX( 25)] = 0x3D23,
8565 [BEND_IDX( 20)] = 0x3E23,
8566 [BEND_IDX( 15)] = 0x3E23,
8567 [BEND_IDX( 10)] = 0x3F23,
8568 [BEND_IDX( 5)] = 0x3F23,
8569 [BEND_IDX( 0)] = 0x0025,
8570 [BEND_IDX( -5)] = 0x0025,
8571 [BEND_IDX(-10)] = 0x0125,
8572 [BEND_IDX(-15)] = 0x0125,
8573 [BEND_IDX(-20)] = 0x0225,
8574 [BEND_IDX(-25)] = 0x0225,
8575 [BEND_IDX(-30)] = 0x0325,
8576 [BEND_IDX(-35)] = 0x0325,
8577 [BEND_IDX(-40)] = 0x0425,
8578 [BEND_IDX(-45)] = 0x0425,
8579 [BEND_IDX(-50)] = 0x0525,
8584 * steps -50 to 50 inclusive, in steps of 5
8585 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8586 * change in clock period = -(steps / 10) * 5.787 ps
8588 static void lpt_bend_clkout_dp(struct drm_i915_private
*dev_priv
, int steps
)
8591 int idx
= BEND_IDX(steps
);
8593 if (WARN_ON(steps
% 5 != 0))
8596 if (WARN_ON(idx
>= ARRAY_SIZE(sscdivintphase
)))
8599 mutex_lock(&dev_priv
->sb_lock
);
8601 if (steps
% 10 != 0)
8605 intel_sbi_write(dev_priv
, SBI_SSCDITHPHASE
, tmp
, SBI_ICLK
);
8607 tmp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE
, SBI_ICLK
);
8609 tmp
|= sscdivintphase
[idx
];
8610 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE
, tmp
, SBI_ICLK
);
8612 mutex_unlock(&dev_priv
->sb_lock
);
8617 static void lpt_init_pch_refclk(struct drm_device
*dev
)
8619 struct intel_encoder
*encoder
;
8620 bool has_vga
= false;
8622 for_each_intel_encoder(dev
, encoder
) {
8623 switch (encoder
->type
) {
8624 case INTEL_OUTPUT_ANALOG
:
8633 lpt_bend_clkout_dp(to_i915(dev
), 0);
8634 lpt_enable_clkout_dp(dev
, true, true);
8636 lpt_disable_clkout_dp(dev
);
8641 * Initialize reference clocks when the driver loads
8643 void intel_init_pch_refclk(struct drm_device
*dev
)
8645 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
8646 ironlake_init_pch_refclk(dev
);
8647 else if (HAS_PCH_LPT(dev
))
8648 lpt_init_pch_refclk(dev
);
8651 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
8653 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
8654 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8655 int pipe
= intel_crtc
->pipe
;
8660 switch (intel_crtc
->config
->pipe_bpp
) {
8662 val
|= PIPECONF_6BPC
;
8665 val
|= PIPECONF_8BPC
;
8668 val
|= PIPECONF_10BPC
;
8671 val
|= PIPECONF_12BPC
;
8674 /* Case prevented by intel_choose_pipe_bpp_dither. */
8678 if (intel_crtc
->config
->dither
)
8679 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
8681 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8682 val
|= PIPECONF_INTERLACED_ILK
;
8684 val
|= PIPECONF_PROGRESSIVE
;
8686 if (intel_crtc
->config
->limited_color_range
)
8687 val
|= PIPECONF_COLOR_RANGE_SELECT
;
8689 I915_WRITE(PIPECONF(pipe
), val
);
8690 POSTING_READ(PIPECONF(pipe
));
8693 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
8695 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
8696 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8697 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
8700 if (IS_HASWELL(dev_priv
) && intel_crtc
->config
->dither
)
8701 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
8703 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8704 val
|= PIPECONF_INTERLACED_ILK
;
8706 val
|= PIPECONF_PROGRESSIVE
;
8708 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
8709 POSTING_READ(PIPECONF(cpu_transcoder
));
8712 static void haswell_set_pipemisc(struct drm_crtc
*crtc
)
8714 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
8715 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8717 if (IS_BROADWELL(dev_priv
) || INTEL_INFO(dev_priv
)->gen
>= 9) {
8720 switch (intel_crtc
->config
->pipe_bpp
) {
8722 val
|= PIPEMISC_DITHER_6_BPC
;
8725 val
|= PIPEMISC_DITHER_8_BPC
;
8728 val
|= PIPEMISC_DITHER_10_BPC
;
8731 val
|= PIPEMISC_DITHER_12_BPC
;
8734 /* Case prevented by pipe_config_set_bpp. */
8738 if (intel_crtc
->config
->dither
)
8739 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
8741 I915_WRITE(PIPEMISC(intel_crtc
->pipe
), val
);
8745 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
8748 * Account for spread spectrum to avoid
8749 * oversubscribing the link. Max center spread
8750 * is 2.5%; use 5% for safety's sake.
8752 u32 bps
= target_clock
* bpp
* 21 / 20;
8753 return DIV_ROUND_UP(bps
, link_bw
* 8);
8756 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
8758 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
8761 static void ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
8762 struct intel_crtc_state
*crtc_state
,
8763 struct dpll
*reduced_clock
)
8765 struct drm_crtc
*crtc
= &intel_crtc
->base
;
8766 struct drm_device
*dev
= crtc
->dev
;
8767 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8768 struct drm_atomic_state
*state
= crtc_state
->base
.state
;
8769 struct drm_connector
*connector
;
8770 struct drm_connector_state
*connector_state
;
8771 struct intel_encoder
*encoder
;
8774 bool is_lvds
= false, is_sdvo
= false;
8776 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
8777 if (connector_state
->crtc
!= crtc_state
->base
.crtc
)
8780 encoder
= to_intel_encoder(connector_state
->best_encoder
);
8782 switch (encoder
->type
) {
8783 case INTEL_OUTPUT_LVDS
:
8786 case INTEL_OUTPUT_SDVO
:
8787 case INTEL_OUTPUT_HDMI
:
8795 /* Enable autotuning of the PLL clock (if permissible) */
8798 if ((intel_panel_use_ssc(dev_priv
) &&
8799 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
8800 (HAS_PCH_IBX(dev
) && intel_is_dual_link_lvds(dev
)))
8802 } else if (crtc_state
->sdvo_tv_clock
)
8805 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
8807 if (ironlake_needs_fb_cb_tune(&crtc_state
->dpll
, factor
))
8810 if (reduced_clock
) {
8811 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
8813 if (reduced_clock
->m
< factor
* reduced_clock
->n
)
8822 dpll
|= DPLLB_MODE_LVDS
;
8824 dpll
|= DPLLB_MODE_DAC_SERIAL
;
8826 dpll
|= (crtc_state
->pixel_multiplier
- 1)
8827 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
8830 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8831 if (crtc_state
->has_dp_encoder
)
8832 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8834 /* compute bitmask from p1 value */
8835 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8837 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
8839 switch (crtc_state
->dpll
.p2
) {
8841 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
8844 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
8847 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
8850 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
8854 if (is_lvds
&& intel_panel_use_ssc(dev_priv
))
8855 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
8857 dpll
|= PLL_REF_INPUT_DREFCLK
;
8859 dpll
|= DPLL_VCO_ENABLE
;
8861 crtc_state
->dpll_hw_state
.dpll
= dpll
;
8862 crtc_state
->dpll_hw_state
.fp0
= fp
;
8863 crtc_state
->dpll_hw_state
.fp1
= fp2
;
8866 static int ironlake_crtc_compute_clock(struct intel_crtc
*crtc
,
8867 struct intel_crtc_state
*crtc_state
)
8869 struct drm_device
*dev
= crtc
->base
.dev
;
8870 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8871 struct dpll reduced_clock
;
8872 bool has_reduced_clock
= false;
8873 struct intel_shared_dpll
*pll
;
8874 const struct intel_limit
*limit
;
8875 int refclk
= 120000;
8877 memset(&crtc_state
->dpll_hw_state
, 0,
8878 sizeof(crtc_state
->dpll_hw_state
));
8880 crtc
->lowfreq_avail
= false;
8882 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8883 if (!crtc_state
->has_pch_encoder
)
8886 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8887 if (intel_panel_use_ssc(dev_priv
)) {
8888 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8889 dev_priv
->vbt
.lvds_ssc_freq
);
8890 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8893 if (intel_is_dual_link_lvds(dev
)) {
8894 if (refclk
== 100000)
8895 limit
= &intel_limits_ironlake_dual_lvds_100m
;
8897 limit
= &intel_limits_ironlake_dual_lvds
;
8899 if (refclk
== 100000)
8900 limit
= &intel_limits_ironlake_single_lvds_100m
;
8902 limit
= &intel_limits_ironlake_single_lvds
;
8905 limit
= &intel_limits_ironlake_dac
;
8908 if (!crtc_state
->clock_set
&&
8909 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8910 refclk
, NULL
, &crtc_state
->dpll
)) {
8911 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8915 ironlake_compute_dpll(crtc
, crtc_state
,
8916 has_reduced_clock
? &reduced_clock
: NULL
);
8918 pll
= intel_get_shared_dpll(crtc
, crtc_state
, NULL
);
8920 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8921 pipe_name(crtc
->pipe
));
8925 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
8927 crtc
->lowfreq_avail
= true;
8932 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
8933 struct intel_link_m_n
*m_n
)
8935 struct drm_device
*dev
= crtc
->base
.dev
;
8936 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8937 enum pipe pipe
= crtc
->pipe
;
8939 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
8940 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
8941 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
8943 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
8944 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
8945 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8948 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
8949 enum transcoder transcoder
,
8950 struct intel_link_m_n
*m_n
,
8951 struct intel_link_m_n
*m2_n2
)
8953 struct drm_device
*dev
= crtc
->base
.dev
;
8954 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8955 enum pipe pipe
= crtc
->pipe
;
8957 if (INTEL_INFO(dev
)->gen
>= 5) {
8958 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
8959 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
8960 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
8962 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
8963 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
8964 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8965 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8966 * gen < 8) and if DRRS is supported (to make sure the
8967 * registers are not unnecessarily read).
8969 if (m2_n2
&& INTEL_INFO(dev
)->gen
< 8 &&
8970 crtc
->config
->has_drrs
) {
8971 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
8972 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
8973 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
8975 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
8976 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
8977 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8980 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
8981 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
8982 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
8984 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
8985 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
8986 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8990 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
8991 struct intel_crtc_state
*pipe_config
)
8993 if (pipe_config
->has_pch_encoder
)
8994 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
8996 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8997 &pipe_config
->dp_m_n
,
8998 &pipe_config
->dp_m2_n2
);
9001 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
9002 struct intel_crtc_state
*pipe_config
)
9004 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
9005 &pipe_config
->fdi_m_n
, NULL
);
9008 static void skylake_get_pfit_config(struct intel_crtc
*crtc
,
9009 struct intel_crtc_state
*pipe_config
)
9011 struct drm_device
*dev
= crtc
->base
.dev
;
9012 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9013 struct intel_crtc_scaler_state
*scaler_state
= &pipe_config
->scaler_state
;
9014 uint32_t ps_ctrl
= 0;
9018 /* find scaler attached to this pipe */
9019 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
9020 ps_ctrl
= I915_READ(SKL_PS_CTRL(crtc
->pipe
, i
));
9021 if (ps_ctrl
& PS_SCALER_EN
&& !(ps_ctrl
& PS_PLANE_SEL_MASK
)) {
9023 pipe_config
->pch_pfit
.enabled
= true;
9024 pipe_config
->pch_pfit
.pos
= I915_READ(SKL_PS_WIN_POS(crtc
->pipe
, i
));
9025 pipe_config
->pch_pfit
.size
= I915_READ(SKL_PS_WIN_SZ(crtc
->pipe
, i
));
9030 scaler_state
->scaler_id
= id
;
9032 scaler_state
->scaler_users
|= (1 << SKL_CRTC_INDEX
);
9034 scaler_state
->scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
9039 skylake_get_initial_plane_config(struct intel_crtc
*crtc
,
9040 struct intel_initial_plane_config
*plane_config
)
9042 struct drm_device
*dev
= crtc
->base
.dev
;
9043 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9044 u32 val
, base
, offset
, stride_mult
, tiling
;
9045 int pipe
= crtc
->pipe
;
9046 int fourcc
, pixel_format
;
9047 unsigned int aligned_height
;
9048 struct drm_framebuffer
*fb
;
9049 struct intel_framebuffer
*intel_fb
;
9051 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9053 DRM_DEBUG_KMS("failed to alloc fb\n");
9057 fb
= &intel_fb
->base
;
9059 val
= I915_READ(PLANE_CTL(pipe
, 0));
9060 if (!(val
& PLANE_CTL_ENABLE
))
9063 pixel_format
= val
& PLANE_CTL_FORMAT_MASK
;
9064 fourcc
= skl_format_to_fourcc(pixel_format
,
9065 val
& PLANE_CTL_ORDER_RGBX
,
9066 val
& PLANE_CTL_ALPHA_MASK
);
9067 fb
->pixel_format
= fourcc
;
9068 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
9070 tiling
= val
& PLANE_CTL_TILED_MASK
;
9072 case PLANE_CTL_TILED_LINEAR
:
9073 fb
->modifier
[0] = DRM_FORMAT_MOD_NONE
;
9075 case PLANE_CTL_TILED_X
:
9076 plane_config
->tiling
= I915_TILING_X
;
9077 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
9079 case PLANE_CTL_TILED_Y
:
9080 fb
->modifier
[0] = I915_FORMAT_MOD_Y_TILED
;
9082 case PLANE_CTL_TILED_YF
:
9083 fb
->modifier
[0] = I915_FORMAT_MOD_Yf_TILED
;
9086 MISSING_CASE(tiling
);
9090 base
= I915_READ(PLANE_SURF(pipe
, 0)) & 0xfffff000;
9091 plane_config
->base
= base
;
9093 offset
= I915_READ(PLANE_OFFSET(pipe
, 0));
9095 val
= I915_READ(PLANE_SIZE(pipe
, 0));
9096 fb
->height
= ((val
>> 16) & 0xfff) + 1;
9097 fb
->width
= ((val
>> 0) & 0x1fff) + 1;
9099 val
= I915_READ(PLANE_STRIDE(pipe
, 0));
9100 stride_mult
= intel_fb_stride_alignment(dev_priv
, fb
->modifier
[0],
9102 fb
->pitches
[0] = (val
& 0x3ff) * stride_mult
;
9104 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
9108 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
9110 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9111 pipe_name(pipe
), fb
->width
, fb
->height
,
9112 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
9113 plane_config
->size
);
9115 plane_config
->fb
= intel_fb
;
9122 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
9123 struct intel_crtc_state
*pipe_config
)
9125 struct drm_device
*dev
= crtc
->base
.dev
;
9126 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9129 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
9131 if (tmp
& PF_ENABLE
) {
9132 pipe_config
->pch_pfit
.enabled
= true;
9133 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
9134 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
9136 /* We currently do not free assignements of panel fitters on
9137 * ivb/hsw (since we don't use the higher upscaling modes which
9138 * differentiates them) so just WARN about this case for now. */
9140 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
9141 PF_PIPE_SEL_IVB(crtc
->pipe
));
9147 ironlake_get_initial_plane_config(struct intel_crtc
*crtc
,
9148 struct intel_initial_plane_config
*plane_config
)
9150 struct drm_device
*dev
= crtc
->base
.dev
;
9151 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9152 u32 val
, base
, offset
;
9153 int pipe
= crtc
->pipe
;
9154 int fourcc
, pixel_format
;
9155 unsigned int aligned_height
;
9156 struct drm_framebuffer
*fb
;
9157 struct intel_framebuffer
*intel_fb
;
9159 val
= I915_READ(DSPCNTR(pipe
));
9160 if (!(val
& DISPLAY_PLANE_ENABLE
))
9163 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9165 DRM_DEBUG_KMS("failed to alloc fb\n");
9169 fb
= &intel_fb
->base
;
9171 if (INTEL_INFO(dev
)->gen
>= 4) {
9172 if (val
& DISPPLANE_TILED
) {
9173 plane_config
->tiling
= I915_TILING_X
;
9174 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
9178 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
9179 fourcc
= i9xx_format_to_fourcc(pixel_format
);
9180 fb
->pixel_format
= fourcc
;
9181 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
9183 base
= I915_READ(DSPSURF(pipe
)) & 0xfffff000;
9184 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
9185 offset
= I915_READ(DSPOFFSET(pipe
));
9187 if (plane_config
->tiling
)
9188 offset
= I915_READ(DSPTILEOFF(pipe
));
9190 offset
= I915_READ(DSPLINOFF(pipe
));
9192 plane_config
->base
= base
;
9194 val
= I915_READ(PIPESRC(pipe
));
9195 fb
->width
= ((val
>> 16) & 0xfff) + 1;
9196 fb
->height
= ((val
>> 0) & 0xfff) + 1;
9198 val
= I915_READ(DSPSTRIDE(pipe
));
9199 fb
->pitches
[0] = val
& 0xffffffc0;
9201 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
9205 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
9207 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9208 pipe_name(pipe
), fb
->width
, fb
->height
,
9209 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
9210 plane_config
->size
);
9212 plane_config
->fb
= intel_fb
;
9215 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
9216 struct intel_crtc_state
*pipe_config
)
9218 struct drm_device
*dev
= crtc
->base
.dev
;
9219 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9220 enum intel_display_power_domain power_domain
;
9224 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
9225 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9228 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
9229 pipe_config
->shared_dpll
= NULL
;
9232 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
9233 if (!(tmp
& PIPECONF_ENABLE
))
9236 switch (tmp
& PIPECONF_BPC_MASK
) {
9238 pipe_config
->pipe_bpp
= 18;
9241 pipe_config
->pipe_bpp
= 24;
9243 case PIPECONF_10BPC
:
9244 pipe_config
->pipe_bpp
= 30;
9246 case PIPECONF_12BPC
:
9247 pipe_config
->pipe_bpp
= 36;
9253 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
9254 pipe_config
->limited_color_range
= true;
9256 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
9257 struct intel_shared_dpll
*pll
;
9258 enum intel_dpll_id pll_id
;
9260 pipe_config
->has_pch_encoder
= true;
9262 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
9263 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
9264 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
9266 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
9268 if (HAS_PCH_IBX(dev_priv
)) {
9270 * The pipe->pch transcoder and pch transcoder->pll
9273 pll_id
= (enum intel_dpll_id
) crtc
->pipe
;
9275 tmp
= I915_READ(PCH_DPLL_SEL
);
9276 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
9277 pll_id
= DPLL_ID_PCH_PLL_B
;
9279 pll_id
= DPLL_ID_PCH_PLL_A
;
9282 pipe_config
->shared_dpll
=
9283 intel_get_shared_dpll_by_id(dev_priv
, pll_id
);
9284 pll
= pipe_config
->shared_dpll
;
9286 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
9287 &pipe_config
->dpll_hw_state
));
9289 tmp
= pipe_config
->dpll_hw_state
.dpll
;
9290 pipe_config
->pixel_multiplier
=
9291 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
9292 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
9294 ironlake_pch_clock_get(crtc
, pipe_config
);
9296 pipe_config
->pixel_multiplier
= 1;
9299 intel_get_pipe_timings(crtc
, pipe_config
);
9300 intel_get_pipe_src_size(crtc
, pipe_config
);
9302 ironlake_get_pfit_config(crtc
, pipe_config
);
9307 intel_display_power_put(dev_priv
, power_domain
);
9312 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
9314 struct drm_device
*dev
= dev_priv
->dev
;
9315 struct intel_crtc
*crtc
;
9317 for_each_intel_crtc(dev
, crtc
)
9318 I915_STATE_WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
9319 pipe_name(crtc
->pipe
));
9321 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
9322 I915_STATE_WARN(I915_READ(SPLL_CTL
) & SPLL_PLL_ENABLE
, "SPLL enabled\n");
9323 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE
, "WRPLL1 enabled\n");
9324 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE
, "WRPLL2 enabled\n");
9325 I915_STATE_WARN(I915_READ(PCH_PP_STATUS
) & PP_ON
, "Panel power on\n");
9326 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
9327 "CPU PWM1 enabled\n");
9328 if (IS_HASWELL(dev
))
9329 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
9330 "CPU PWM2 enabled\n");
9331 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
9332 "PCH PWM1 enabled\n");
9333 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
9334 "Utility pin enabled\n");
9335 I915_STATE_WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
9338 * In theory we can still leave IRQs enabled, as long as only the HPD
9339 * interrupts remain enabled. We used to check for that, but since it's
9340 * gen-specific and since we only disable LCPLL after we fully disable
9341 * the interrupts, the check below should be enough.
9343 I915_STATE_WARN(intel_irqs_enabled(dev_priv
), "IRQs enabled\n");
9346 static uint32_t hsw_read_dcomp(struct drm_i915_private
*dev_priv
)
9348 struct drm_device
*dev
= dev_priv
->dev
;
9350 if (IS_HASWELL(dev
))
9351 return I915_READ(D_COMP_HSW
);
9353 return I915_READ(D_COMP_BDW
);
9356 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
9358 struct drm_device
*dev
= dev_priv
->dev
;
9360 if (IS_HASWELL(dev
)) {
9361 mutex_lock(&dev_priv
->rps
.hw_lock
);
9362 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
9364 DRM_ERROR("Failed to write to D_COMP\n");
9365 mutex_unlock(&dev_priv
->rps
.hw_lock
);
9367 I915_WRITE(D_COMP_BDW
, val
);
9368 POSTING_READ(D_COMP_BDW
);
9373 * This function implements pieces of two sequences from BSpec:
9374 * - Sequence for display software to disable LCPLL
9375 * - Sequence for display software to allow package C8+
9376 * The steps implemented here are just the steps that actually touch the LCPLL
9377 * register. Callers should take care of disabling all the display engine
9378 * functions, doing the mode unset, fixing interrupts, etc.
9380 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
9381 bool switch_to_fclk
, bool allow_power_down
)
9385 assert_can_disable_lcpll(dev_priv
);
9387 val
= I915_READ(LCPLL_CTL
);
9389 if (switch_to_fclk
) {
9390 val
|= LCPLL_CD_SOURCE_FCLK
;
9391 I915_WRITE(LCPLL_CTL
, val
);
9393 if (wait_for_atomic_us(I915_READ(LCPLL_CTL
) &
9394 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
9395 DRM_ERROR("Switching to FCLK failed\n");
9397 val
= I915_READ(LCPLL_CTL
);
9400 val
|= LCPLL_PLL_DISABLE
;
9401 I915_WRITE(LCPLL_CTL
, val
);
9402 POSTING_READ(LCPLL_CTL
);
9404 if (wait_for((I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
) == 0, 1))
9405 DRM_ERROR("LCPLL still locked\n");
9407 val
= hsw_read_dcomp(dev_priv
);
9408 val
|= D_COMP_COMP_DISABLE
;
9409 hsw_write_dcomp(dev_priv
, val
);
9412 if (wait_for((hsw_read_dcomp(dev_priv
) & D_COMP_RCOMP_IN_PROGRESS
) == 0,
9414 DRM_ERROR("D_COMP RCOMP still in progress\n");
9416 if (allow_power_down
) {
9417 val
= I915_READ(LCPLL_CTL
);
9418 val
|= LCPLL_POWER_DOWN_ALLOW
;
9419 I915_WRITE(LCPLL_CTL
, val
);
9420 POSTING_READ(LCPLL_CTL
);
9425 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9428 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
9432 val
= I915_READ(LCPLL_CTL
);
9434 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
9435 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
9439 * Make sure we're not on PC8 state before disabling PC8, otherwise
9440 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
9442 intel_uncore_forcewake_get(dev_priv
, FORCEWAKE_ALL
);
9444 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
9445 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
9446 I915_WRITE(LCPLL_CTL
, val
);
9447 POSTING_READ(LCPLL_CTL
);
9450 val
= hsw_read_dcomp(dev_priv
);
9451 val
|= D_COMP_COMP_FORCE
;
9452 val
&= ~D_COMP_COMP_DISABLE
;
9453 hsw_write_dcomp(dev_priv
, val
);
9455 val
= I915_READ(LCPLL_CTL
);
9456 val
&= ~LCPLL_PLL_DISABLE
;
9457 I915_WRITE(LCPLL_CTL
, val
);
9459 if (wait_for(I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
, 5))
9460 DRM_ERROR("LCPLL not locked yet\n");
9462 if (val
& LCPLL_CD_SOURCE_FCLK
) {
9463 val
= I915_READ(LCPLL_CTL
);
9464 val
&= ~LCPLL_CD_SOURCE_FCLK
;
9465 I915_WRITE(LCPLL_CTL
, val
);
9467 if (wait_for_atomic_us((I915_READ(LCPLL_CTL
) &
9468 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
9469 DRM_ERROR("Switching back to LCPLL failed\n");
9472 intel_uncore_forcewake_put(dev_priv
, FORCEWAKE_ALL
);
9473 intel_update_cdclk(dev_priv
->dev
);
9477 * Package states C8 and deeper are really deep PC states that can only be
9478 * reached when all the devices on the system allow it, so even if the graphics
9479 * device allows PC8+, it doesn't mean the system will actually get to these
9480 * states. Our driver only allows PC8+ when going into runtime PM.
9482 * The requirements for PC8+ are that all the outputs are disabled, the power
9483 * well is disabled and most interrupts are disabled, and these are also
9484 * requirements for runtime PM. When these conditions are met, we manually do
9485 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9486 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9489 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9490 * the state of some registers, so when we come back from PC8+ we need to
9491 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9492 * need to take care of the registers kept by RC6. Notice that this happens even
9493 * if we don't put the device in PCI D3 state (which is what currently happens
9494 * because of the runtime PM support).
9496 * For more, read "Display Sequences for Package C8" on the hardware
9499 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
9501 struct drm_device
*dev
= dev_priv
->dev
;
9504 DRM_DEBUG_KMS("Enabling package C8+\n");
9506 if (HAS_PCH_LPT_LP(dev
)) {
9507 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
9508 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
9509 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
9512 lpt_disable_clkout_dp(dev
);
9513 hsw_disable_lcpll(dev_priv
, true, true);
9516 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
9518 struct drm_device
*dev
= dev_priv
->dev
;
9521 DRM_DEBUG_KMS("Disabling package C8+\n");
9523 hsw_restore_lcpll(dev_priv
);
9524 lpt_init_pch_refclk(dev
);
9526 if (HAS_PCH_LPT_LP(dev
)) {
9527 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
9528 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
9529 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
9533 static void broxton_modeset_commit_cdclk(struct drm_atomic_state
*old_state
)
9535 struct drm_device
*dev
= old_state
->dev
;
9536 struct intel_atomic_state
*old_intel_state
=
9537 to_intel_atomic_state(old_state
);
9538 unsigned int req_cdclk
= old_intel_state
->dev_cdclk
;
9540 broxton_set_cdclk(to_i915(dev
), req_cdclk
);
9543 /* compute the max rate for new configuration */
9544 static int ilk_max_pixel_rate(struct drm_atomic_state
*state
)
9546 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
9547 struct drm_i915_private
*dev_priv
= state
->dev
->dev_private
;
9548 struct drm_crtc
*crtc
;
9549 struct drm_crtc_state
*cstate
;
9550 struct intel_crtc_state
*crtc_state
;
9551 unsigned max_pixel_rate
= 0, i
;
9554 memcpy(intel_state
->min_pixclk
, dev_priv
->min_pixclk
,
9555 sizeof(intel_state
->min_pixclk
));
9557 for_each_crtc_in_state(state
, crtc
, cstate
, i
) {
9560 crtc_state
= to_intel_crtc_state(cstate
);
9561 if (!crtc_state
->base
.enable
) {
9562 intel_state
->min_pixclk
[i
] = 0;
9566 pixel_rate
= ilk_pipe_pixel_rate(crtc_state
);
9568 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
9569 if (IS_BROADWELL(dev_priv
) && crtc_state
->ips_enabled
)
9570 pixel_rate
= DIV_ROUND_UP(pixel_rate
* 100, 95);
9572 intel_state
->min_pixclk
[i
] = pixel_rate
;
9575 for_each_pipe(dev_priv
, pipe
)
9576 max_pixel_rate
= max(intel_state
->min_pixclk
[pipe
], max_pixel_rate
);
9578 return max_pixel_rate
;
9581 static void broadwell_set_cdclk(struct drm_device
*dev
, int cdclk
)
9583 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9587 if (WARN((I915_READ(LCPLL_CTL
) &
9588 (LCPLL_PLL_DISABLE
| LCPLL_PLL_LOCK
|
9589 LCPLL_CD_CLOCK_DISABLE
| LCPLL_ROOT_CD_CLOCK_DISABLE
|
9590 LCPLL_CD2X_CLOCK_DISABLE
| LCPLL_POWER_DOWN_ALLOW
|
9591 LCPLL_CD_SOURCE_FCLK
)) != LCPLL_PLL_LOCK
,
9592 "trying to change cdclk frequency with cdclk not enabled\n"))
9595 mutex_lock(&dev_priv
->rps
.hw_lock
);
9596 ret
= sandybridge_pcode_write(dev_priv
,
9597 BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ
, 0x0);
9598 mutex_unlock(&dev_priv
->rps
.hw_lock
);
9600 DRM_ERROR("failed to inform pcode about cdclk change\n");
9604 val
= I915_READ(LCPLL_CTL
);
9605 val
|= LCPLL_CD_SOURCE_FCLK
;
9606 I915_WRITE(LCPLL_CTL
, val
);
9608 if (wait_for_us(I915_READ(LCPLL_CTL
) &
9609 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
9610 DRM_ERROR("Switching to FCLK failed\n");
9612 val
= I915_READ(LCPLL_CTL
);
9613 val
&= ~LCPLL_CLK_FREQ_MASK
;
9617 val
|= LCPLL_CLK_FREQ_450
;
9621 val
|= LCPLL_CLK_FREQ_54O_BDW
;
9625 val
|= LCPLL_CLK_FREQ_337_5_BDW
;
9629 val
|= LCPLL_CLK_FREQ_675_BDW
;
9633 WARN(1, "invalid cdclk frequency\n");
9637 I915_WRITE(LCPLL_CTL
, val
);
9639 val
= I915_READ(LCPLL_CTL
);
9640 val
&= ~LCPLL_CD_SOURCE_FCLK
;
9641 I915_WRITE(LCPLL_CTL
, val
);
9643 if (wait_for_us((I915_READ(LCPLL_CTL
) &
9644 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
9645 DRM_ERROR("Switching back to LCPLL failed\n");
9647 mutex_lock(&dev_priv
->rps
.hw_lock
);
9648 sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
, data
);
9649 mutex_unlock(&dev_priv
->rps
.hw_lock
);
9651 I915_WRITE(CDCLK_FREQ
, DIV_ROUND_CLOSEST(cdclk
, 1000) - 1);
9653 intel_update_cdclk(dev
);
9655 WARN(cdclk
!= dev_priv
->cdclk_freq
,
9656 "cdclk requested %d kHz but got %d kHz\n",
9657 cdclk
, dev_priv
->cdclk_freq
);
9660 static int broadwell_calc_cdclk(int max_pixclk
)
9662 if (max_pixclk
> 540000)
9664 else if (max_pixclk
> 450000)
9666 else if (max_pixclk
> 337500)
9672 static int broadwell_modeset_calc_cdclk(struct drm_atomic_state
*state
)
9674 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
9675 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
9676 int max_pixclk
= ilk_max_pixel_rate(state
);
9680 * FIXME should also account for plane ratio
9681 * once 64bpp pixel formats are supported.
9683 cdclk
= broadwell_calc_cdclk(max_pixclk
);
9685 if (cdclk
> dev_priv
->max_cdclk_freq
) {
9686 DRM_DEBUG_KMS("requested cdclk (%d kHz) exceeds max (%d kHz)\n",
9687 cdclk
, dev_priv
->max_cdclk_freq
);
9691 intel_state
->cdclk
= intel_state
->dev_cdclk
= cdclk
;
9692 if (!intel_state
->active_crtcs
)
9693 intel_state
->dev_cdclk
= broadwell_calc_cdclk(0);
9698 static void broadwell_modeset_commit_cdclk(struct drm_atomic_state
*old_state
)
9700 struct drm_device
*dev
= old_state
->dev
;
9701 struct intel_atomic_state
*old_intel_state
=
9702 to_intel_atomic_state(old_state
);
9703 unsigned req_cdclk
= old_intel_state
->dev_cdclk
;
9705 broadwell_set_cdclk(dev
, req_cdclk
);
9708 static int skl_modeset_calc_cdclk(struct drm_atomic_state
*state
)
9710 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
9711 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
9712 const int max_pixclk
= ilk_max_pixel_rate(state
);
9713 int vco
= intel_state
->cdclk_pll_vco
;
9717 * FIXME should also account for plane ratio
9718 * once 64bpp pixel formats are supported.
9720 cdclk
= skl_calc_cdclk(max_pixclk
, vco
);
9723 * FIXME move the cdclk caclulation to
9724 * compute_config() so we can fail gracegully.
9726 if (cdclk
> dev_priv
->max_cdclk_freq
) {
9727 DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n",
9728 cdclk
, dev_priv
->max_cdclk_freq
);
9729 cdclk
= dev_priv
->max_cdclk_freq
;
9732 intel_state
->cdclk
= intel_state
->dev_cdclk
= cdclk
;
9733 if (!intel_state
->active_crtcs
)
9734 intel_state
->dev_cdclk
= skl_calc_cdclk(0, vco
);
9739 static void skl_modeset_commit_cdclk(struct drm_atomic_state
*old_state
)
9741 struct drm_i915_private
*dev_priv
= to_i915(old_state
->dev
);
9742 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(old_state
);
9743 unsigned int req_cdclk
= intel_state
->dev_cdclk
;
9744 unsigned int req_vco
= intel_state
->cdclk_pll_vco
;
9746 skl_set_cdclk(dev_priv
, req_cdclk
, req_vco
);
9749 static int haswell_crtc_compute_clock(struct intel_crtc
*crtc
,
9750 struct intel_crtc_state
*crtc_state
)
9752 struct intel_encoder
*intel_encoder
=
9753 intel_ddi_get_crtc_new_encoder(crtc_state
);
9755 if (intel_encoder
->type
!= INTEL_OUTPUT_DSI
) {
9756 if (!intel_ddi_pll_select(crtc
, crtc_state
))
9760 crtc
->lowfreq_avail
= false;
9765 static void bxt_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9767 struct intel_crtc_state
*pipe_config
)
9769 enum intel_dpll_id id
;
9773 pipe_config
->ddi_pll_sel
= SKL_DPLL0
;
9774 id
= DPLL_ID_SKL_DPLL0
;
9777 pipe_config
->ddi_pll_sel
= SKL_DPLL1
;
9778 id
= DPLL_ID_SKL_DPLL1
;
9781 pipe_config
->ddi_pll_sel
= SKL_DPLL2
;
9782 id
= DPLL_ID_SKL_DPLL2
;
9785 DRM_ERROR("Incorrect port type\n");
9789 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
9792 static void skylake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9794 struct intel_crtc_state
*pipe_config
)
9796 enum intel_dpll_id id
;
9799 temp
= I915_READ(DPLL_CTRL2
) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port
);
9800 pipe_config
->ddi_pll_sel
= temp
>> (port
* 3 + 1);
9802 switch (pipe_config
->ddi_pll_sel
) {
9804 id
= DPLL_ID_SKL_DPLL0
;
9807 id
= DPLL_ID_SKL_DPLL1
;
9810 id
= DPLL_ID_SKL_DPLL2
;
9813 id
= DPLL_ID_SKL_DPLL3
;
9816 MISSING_CASE(pipe_config
->ddi_pll_sel
);
9820 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
9823 static void haswell_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9825 struct intel_crtc_state
*pipe_config
)
9827 enum intel_dpll_id id
;
9829 pipe_config
->ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
9831 switch (pipe_config
->ddi_pll_sel
) {
9832 case PORT_CLK_SEL_WRPLL1
:
9833 id
= DPLL_ID_WRPLL1
;
9835 case PORT_CLK_SEL_WRPLL2
:
9836 id
= DPLL_ID_WRPLL2
;
9838 case PORT_CLK_SEL_SPLL
:
9841 case PORT_CLK_SEL_LCPLL_810
:
9842 id
= DPLL_ID_LCPLL_810
;
9844 case PORT_CLK_SEL_LCPLL_1350
:
9845 id
= DPLL_ID_LCPLL_1350
;
9847 case PORT_CLK_SEL_LCPLL_2700
:
9848 id
= DPLL_ID_LCPLL_2700
;
9851 MISSING_CASE(pipe_config
->ddi_pll_sel
);
9853 case PORT_CLK_SEL_NONE
:
9857 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
9860 static bool hsw_get_transcoder_state(struct intel_crtc
*crtc
,
9861 struct intel_crtc_state
*pipe_config
,
9862 unsigned long *power_domain_mask
)
9864 struct drm_device
*dev
= crtc
->base
.dev
;
9865 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9866 enum intel_display_power_domain power_domain
;
9870 * The pipe->transcoder mapping is fixed with the exception of the eDP
9871 * transcoder handled below.
9873 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
9876 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9877 * consistency and less surprising code; it's in always on power).
9879 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
9880 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
9881 enum pipe trans_edp_pipe
;
9882 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
9884 WARN(1, "unknown pipe linked to edp transcoder\n");
9885 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
9886 case TRANS_DDI_EDP_INPUT_A_ON
:
9887 trans_edp_pipe
= PIPE_A
;
9889 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
9890 trans_edp_pipe
= PIPE_B
;
9892 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
9893 trans_edp_pipe
= PIPE_C
;
9897 if (trans_edp_pipe
== crtc
->pipe
)
9898 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
9901 power_domain
= POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
);
9902 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9904 *power_domain_mask
|= BIT(power_domain
);
9906 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
9908 return tmp
& PIPECONF_ENABLE
;
9911 static bool bxt_get_dsi_transcoder_state(struct intel_crtc
*crtc
,
9912 struct intel_crtc_state
*pipe_config
,
9913 unsigned long *power_domain_mask
)
9915 struct drm_device
*dev
= crtc
->base
.dev
;
9916 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9917 enum intel_display_power_domain power_domain
;
9919 enum transcoder cpu_transcoder
;
9922 pipe_config
->has_dsi_encoder
= false;
9924 for_each_port_masked(port
, BIT(PORT_A
) | BIT(PORT_C
)) {
9926 cpu_transcoder
= TRANSCODER_DSI_A
;
9928 cpu_transcoder
= TRANSCODER_DSI_C
;
9930 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
9931 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9933 *power_domain_mask
|= BIT(power_domain
);
9936 * The PLL needs to be enabled with a valid divider
9937 * configuration, otherwise accessing DSI registers will hang
9938 * the machine. See BSpec North Display Engine
9939 * registers/MIPI[BXT]. We can break out here early, since we
9940 * need the same DSI PLL to be enabled for both DSI ports.
9942 if (!intel_dsi_pll_is_enabled(dev_priv
))
9945 /* XXX: this works for video mode only */
9946 tmp
= I915_READ(BXT_MIPI_PORT_CTRL(port
));
9947 if (!(tmp
& DPI_ENABLE
))
9950 tmp
= I915_READ(MIPI_CTRL(port
));
9951 if ((tmp
& BXT_PIPE_SELECT_MASK
) != BXT_PIPE_SELECT(crtc
->pipe
))
9954 pipe_config
->cpu_transcoder
= cpu_transcoder
;
9955 pipe_config
->has_dsi_encoder
= true;
9959 return pipe_config
->has_dsi_encoder
;
9962 static void haswell_get_ddi_port_state(struct intel_crtc
*crtc
,
9963 struct intel_crtc_state
*pipe_config
)
9965 struct drm_device
*dev
= crtc
->base
.dev
;
9966 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9967 struct intel_shared_dpll
*pll
;
9971 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
9973 port
= (tmp
& TRANS_DDI_PORT_MASK
) >> TRANS_DDI_PORT_SHIFT
;
9975 if (IS_SKYLAKE(dev
) || IS_KABYLAKE(dev
))
9976 skylake_get_ddi_pll(dev_priv
, port
, pipe_config
);
9977 else if (IS_BROXTON(dev
))
9978 bxt_get_ddi_pll(dev_priv
, port
, pipe_config
);
9980 haswell_get_ddi_pll(dev_priv
, port
, pipe_config
);
9982 pll
= pipe_config
->shared_dpll
;
9984 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
9985 &pipe_config
->dpll_hw_state
));
9989 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9990 * DDI E. So just check whether this pipe is wired to DDI E and whether
9991 * the PCH transcoder is on.
9993 if (INTEL_INFO(dev
)->gen
< 9 &&
9994 (port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
9995 pipe_config
->has_pch_encoder
= true;
9997 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
9998 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
9999 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
10001 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
10005 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
10006 struct intel_crtc_state
*pipe_config
)
10008 struct drm_device
*dev
= crtc
->base
.dev
;
10009 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10010 enum intel_display_power_domain power_domain
;
10011 unsigned long power_domain_mask
;
10014 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
10015 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
10017 power_domain_mask
= BIT(power_domain
);
10019 pipe_config
->shared_dpll
= NULL
;
10021 active
= hsw_get_transcoder_state(crtc
, pipe_config
, &power_domain_mask
);
10023 if (IS_BROXTON(dev_priv
)) {
10024 bxt_get_dsi_transcoder_state(crtc
, pipe_config
,
10025 &power_domain_mask
);
10026 WARN_ON(active
&& pipe_config
->has_dsi_encoder
);
10027 if (pipe_config
->has_dsi_encoder
)
10034 if (!pipe_config
->has_dsi_encoder
) {
10035 haswell_get_ddi_port_state(crtc
, pipe_config
);
10036 intel_get_pipe_timings(crtc
, pipe_config
);
10039 intel_get_pipe_src_size(crtc
, pipe_config
);
10041 pipe_config
->gamma_mode
=
10042 I915_READ(GAMMA_MODE(crtc
->pipe
)) & GAMMA_MODE_MODE_MASK
;
10044 if (INTEL_INFO(dev
)->gen
>= 9) {
10045 skl_init_scalers(dev
, crtc
, pipe_config
);
10048 if (INTEL_INFO(dev
)->gen
>= 9) {
10049 pipe_config
->scaler_state
.scaler_id
= -1;
10050 pipe_config
->scaler_state
.scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
10053 power_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
10054 if (intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
10055 power_domain_mask
|= BIT(power_domain
);
10056 if (INTEL_INFO(dev
)->gen
>= 9)
10057 skylake_get_pfit_config(crtc
, pipe_config
);
10059 ironlake_get_pfit_config(crtc
, pipe_config
);
10062 if (IS_HASWELL(dev
))
10063 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
10064 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
10066 if (pipe_config
->cpu_transcoder
!= TRANSCODER_EDP
&&
10067 !transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
10068 pipe_config
->pixel_multiplier
=
10069 I915_READ(PIPE_MULT(pipe_config
->cpu_transcoder
)) + 1;
10071 pipe_config
->pixel_multiplier
= 1;
10075 for_each_power_domain(power_domain
, power_domain_mask
)
10076 intel_display_power_put(dev_priv
, power_domain
);
10081 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
,
10082 const struct intel_plane_state
*plane_state
)
10084 struct drm_device
*dev
= crtc
->dev
;
10085 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10086 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10087 uint32_t cntl
= 0, size
= 0;
10089 if (plane_state
&& plane_state
->visible
) {
10090 unsigned int width
= plane_state
->base
.crtc_w
;
10091 unsigned int height
= plane_state
->base
.crtc_h
;
10092 unsigned int stride
= roundup_pow_of_two(width
) * 4;
10096 WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
10107 cntl
|= CURSOR_ENABLE
|
10108 CURSOR_GAMMA_ENABLE
|
10109 CURSOR_FORMAT_ARGB
|
10110 CURSOR_STRIDE(stride
);
10112 size
= (height
<< 12) | width
;
10115 if (intel_crtc
->cursor_cntl
!= 0 &&
10116 (intel_crtc
->cursor_base
!= base
||
10117 intel_crtc
->cursor_size
!= size
||
10118 intel_crtc
->cursor_cntl
!= cntl
)) {
10119 /* On these chipsets we can only modify the base/size/stride
10120 * whilst the cursor is disabled.
10122 I915_WRITE(CURCNTR(PIPE_A
), 0);
10123 POSTING_READ(CURCNTR(PIPE_A
));
10124 intel_crtc
->cursor_cntl
= 0;
10127 if (intel_crtc
->cursor_base
!= base
) {
10128 I915_WRITE(CURBASE(PIPE_A
), base
);
10129 intel_crtc
->cursor_base
= base
;
10132 if (intel_crtc
->cursor_size
!= size
) {
10133 I915_WRITE(CURSIZE
, size
);
10134 intel_crtc
->cursor_size
= size
;
10137 if (intel_crtc
->cursor_cntl
!= cntl
) {
10138 I915_WRITE(CURCNTR(PIPE_A
), cntl
);
10139 POSTING_READ(CURCNTR(PIPE_A
));
10140 intel_crtc
->cursor_cntl
= cntl
;
10144 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
,
10145 const struct intel_plane_state
*plane_state
)
10147 struct drm_device
*dev
= crtc
->dev
;
10148 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10149 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10150 int pipe
= intel_crtc
->pipe
;
10153 if (plane_state
&& plane_state
->visible
) {
10154 cntl
= MCURSOR_GAMMA_ENABLE
;
10155 switch (plane_state
->base
.crtc_w
) {
10157 cntl
|= CURSOR_MODE_64_ARGB_AX
;
10160 cntl
|= CURSOR_MODE_128_ARGB_AX
;
10163 cntl
|= CURSOR_MODE_256_ARGB_AX
;
10166 MISSING_CASE(plane_state
->base
.crtc_w
);
10169 cntl
|= pipe
<< 28; /* Connect to correct pipe */
10172 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
10174 if (plane_state
->base
.rotation
== BIT(DRM_ROTATE_180
))
10175 cntl
|= CURSOR_ROTATE_180
;
10178 if (intel_crtc
->cursor_cntl
!= cntl
) {
10179 I915_WRITE(CURCNTR(pipe
), cntl
);
10180 POSTING_READ(CURCNTR(pipe
));
10181 intel_crtc
->cursor_cntl
= cntl
;
10184 /* and commit changes on next vblank */
10185 I915_WRITE(CURBASE(pipe
), base
);
10186 POSTING_READ(CURBASE(pipe
));
10188 intel_crtc
->cursor_base
= base
;
10191 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
10192 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
10193 const struct intel_plane_state
*plane_state
)
10195 struct drm_device
*dev
= crtc
->dev
;
10196 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10197 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10198 int pipe
= intel_crtc
->pipe
;
10199 u32 base
= intel_crtc
->cursor_addr
;
10203 int x
= plane_state
->base
.crtc_x
;
10204 int y
= plane_state
->base
.crtc_y
;
10207 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
10210 pos
|= x
<< CURSOR_X_SHIFT
;
10213 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
10216 pos
|= y
<< CURSOR_Y_SHIFT
;
10218 /* ILK+ do this automagically */
10219 if (HAS_GMCH_DISPLAY(dev
) &&
10220 plane_state
->base
.rotation
== BIT(DRM_ROTATE_180
)) {
10221 base
+= (plane_state
->base
.crtc_h
*
10222 plane_state
->base
.crtc_w
- 1) * 4;
10226 I915_WRITE(CURPOS(pipe
), pos
);
10228 if (IS_845G(dev
) || IS_I865G(dev
))
10229 i845_update_cursor(crtc
, base
, plane_state
);
10231 i9xx_update_cursor(crtc
, base
, plane_state
);
10234 static bool cursor_size_ok(struct drm_device
*dev
,
10235 uint32_t width
, uint32_t height
)
10237 if (width
== 0 || height
== 0)
10241 * 845g/865g are special in that they are only limited by
10242 * the width of their cursors, the height is arbitrary up to
10243 * the precision of the register. Everything else requires
10244 * square cursors, limited to a few power-of-two sizes.
10246 if (IS_845G(dev
) || IS_I865G(dev
)) {
10247 if ((width
& 63) != 0)
10250 if (width
> (IS_845G(dev
) ? 64 : 512))
10256 switch (width
| height
) {
10271 /* VESA 640x480x72Hz mode to set on the pipe */
10272 static struct drm_display_mode load_detect_mode
= {
10273 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
10274 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
10277 struct drm_framebuffer
*
10278 __intel_framebuffer_create(struct drm_device
*dev
,
10279 struct drm_mode_fb_cmd2
*mode_cmd
,
10280 struct drm_i915_gem_object
*obj
)
10282 struct intel_framebuffer
*intel_fb
;
10285 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
10287 return ERR_PTR(-ENOMEM
);
10289 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
10293 return &intel_fb
->base
;
10297 return ERR_PTR(ret
);
10300 static struct drm_framebuffer
*
10301 intel_framebuffer_create(struct drm_device
*dev
,
10302 struct drm_mode_fb_cmd2
*mode_cmd
,
10303 struct drm_i915_gem_object
*obj
)
10305 struct drm_framebuffer
*fb
;
10308 ret
= i915_mutex_lock_interruptible(dev
);
10310 return ERR_PTR(ret
);
10311 fb
= __intel_framebuffer_create(dev
, mode_cmd
, obj
);
10312 mutex_unlock(&dev
->struct_mutex
);
10318 intel_framebuffer_pitch_for_width(int width
, int bpp
)
10320 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
10321 return ALIGN(pitch
, 64);
10325 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
10327 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
10328 return PAGE_ALIGN(pitch
* mode
->vdisplay
);
10331 static struct drm_framebuffer
*
10332 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
10333 struct drm_display_mode
*mode
,
10334 int depth
, int bpp
)
10336 struct drm_framebuffer
*fb
;
10337 struct drm_i915_gem_object
*obj
;
10338 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
10340 obj
= i915_gem_object_create(dev
,
10341 intel_framebuffer_size_for_mode(mode
, bpp
));
10343 return ERR_CAST(obj
);
10345 mode_cmd
.width
= mode
->hdisplay
;
10346 mode_cmd
.height
= mode
->vdisplay
;
10347 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
10349 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
10351 fb
= intel_framebuffer_create(dev
, &mode_cmd
, obj
);
10353 drm_gem_object_unreference_unlocked(&obj
->base
);
10358 static struct drm_framebuffer
*
10359 mode_fits_in_fbdev(struct drm_device
*dev
,
10360 struct drm_display_mode
*mode
)
10362 #ifdef CONFIG_DRM_FBDEV_EMULATION
10363 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10364 struct drm_i915_gem_object
*obj
;
10365 struct drm_framebuffer
*fb
;
10367 if (!dev_priv
->fbdev
)
10370 if (!dev_priv
->fbdev
->fb
)
10373 obj
= dev_priv
->fbdev
->fb
->obj
;
10376 fb
= &dev_priv
->fbdev
->fb
->base
;
10377 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
10378 fb
->bits_per_pixel
))
10381 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
10384 drm_framebuffer_reference(fb
);
10391 static int intel_modeset_setup_plane_state(struct drm_atomic_state
*state
,
10392 struct drm_crtc
*crtc
,
10393 struct drm_display_mode
*mode
,
10394 struct drm_framebuffer
*fb
,
10397 struct drm_plane_state
*plane_state
;
10398 int hdisplay
, vdisplay
;
10401 plane_state
= drm_atomic_get_plane_state(state
, crtc
->primary
);
10402 if (IS_ERR(plane_state
))
10403 return PTR_ERR(plane_state
);
10406 drm_crtc_get_hv_timing(mode
, &hdisplay
, &vdisplay
);
10408 hdisplay
= vdisplay
= 0;
10410 ret
= drm_atomic_set_crtc_for_plane(plane_state
, fb
? crtc
: NULL
);
10413 drm_atomic_set_fb_for_plane(plane_state
, fb
);
10414 plane_state
->crtc_x
= 0;
10415 plane_state
->crtc_y
= 0;
10416 plane_state
->crtc_w
= hdisplay
;
10417 plane_state
->crtc_h
= vdisplay
;
10418 plane_state
->src_x
= x
<< 16;
10419 plane_state
->src_y
= y
<< 16;
10420 plane_state
->src_w
= hdisplay
<< 16;
10421 plane_state
->src_h
= vdisplay
<< 16;
10426 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
10427 struct drm_display_mode
*mode
,
10428 struct intel_load_detect_pipe
*old
,
10429 struct drm_modeset_acquire_ctx
*ctx
)
10431 struct intel_crtc
*intel_crtc
;
10432 struct intel_encoder
*intel_encoder
=
10433 intel_attached_encoder(connector
);
10434 struct drm_crtc
*possible_crtc
;
10435 struct drm_encoder
*encoder
= &intel_encoder
->base
;
10436 struct drm_crtc
*crtc
= NULL
;
10437 struct drm_device
*dev
= encoder
->dev
;
10438 struct drm_framebuffer
*fb
;
10439 struct drm_mode_config
*config
= &dev
->mode_config
;
10440 struct drm_atomic_state
*state
= NULL
, *restore_state
= NULL
;
10441 struct drm_connector_state
*connector_state
;
10442 struct intel_crtc_state
*crtc_state
;
10445 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10446 connector
->base
.id
, connector
->name
,
10447 encoder
->base
.id
, encoder
->name
);
10449 old
->restore_state
= NULL
;
10452 ret
= drm_modeset_lock(&config
->connection_mutex
, ctx
);
10457 * Algorithm gets a little messy:
10459 * - if the connector already has an assigned crtc, use it (but make
10460 * sure it's on first)
10462 * - try to find the first unused crtc that can drive this connector,
10463 * and use that if we find one
10466 /* See if we already have a CRTC for this connector */
10467 if (connector
->state
->crtc
) {
10468 crtc
= connector
->state
->crtc
;
10470 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
10474 /* Make sure the crtc and connector are running */
10478 /* Find an unused one (if possible) */
10479 for_each_crtc(dev
, possible_crtc
) {
10481 if (!(encoder
->possible_crtcs
& (1 << i
)))
10484 ret
= drm_modeset_lock(&possible_crtc
->mutex
, ctx
);
10488 if (possible_crtc
->state
->enable
) {
10489 drm_modeset_unlock(&possible_crtc
->mutex
);
10493 crtc
= possible_crtc
;
10498 * If we didn't find an unused CRTC, don't use any.
10501 DRM_DEBUG_KMS("no pipe available for load-detect\n");
10506 intel_crtc
= to_intel_crtc(crtc
);
10508 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
10512 state
= drm_atomic_state_alloc(dev
);
10513 restore_state
= drm_atomic_state_alloc(dev
);
10514 if (!state
|| !restore_state
) {
10519 state
->acquire_ctx
= ctx
;
10520 restore_state
->acquire_ctx
= ctx
;
10522 connector_state
= drm_atomic_get_connector_state(state
, connector
);
10523 if (IS_ERR(connector_state
)) {
10524 ret
= PTR_ERR(connector_state
);
10528 ret
= drm_atomic_set_crtc_for_connector(connector_state
, crtc
);
10532 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
10533 if (IS_ERR(crtc_state
)) {
10534 ret
= PTR_ERR(crtc_state
);
10538 crtc_state
->base
.active
= crtc_state
->base
.enable
= true;
10541 mode
= &load_detect_mode
;
10543 /* We need a framebuffer large enough to accommodate all accesses
10544 * that the plane may generate whilst we perform load detection.
10545 * We can not rely on the fbcon either being present (we get called
10546 * during its initialisation to detect all boot displays, or it may
10547 * not even exist) or that it is large enough to satisfy the
10550 fb
= mode_fits_in_fbdev(dev
, mode
);
10552 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
10553 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
10555 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
10557 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
10561 ret
= intel_modeset_setup_plane_state(state
, crtc
, mode
, fb
, 0, 0);
10565 drm_framebuffer_unreference(fb
);
10567 ret
= drm_atomic_set_mode_for_crtc(&crtc_state
->base
, mode
);
10571 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state
, connector
));
10573 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state
, crtc
));
10575 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state
, crtc
->primary
));
10577 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret
);
10581 ret
= drm_atomic_commit(state
);
10583 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
10587 old
->restore_state
= restore_state
;
10589 /* let the connector get through one full cycle before testing */
10590 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
10594 drm_atomic_state_free(state
);
10595 drm_atomic_state_free(restore_state
);
10596 restore_state
= state
= NULL
;
10598 if (ret
== -EDEADLK
) {
10599 drm_modeset_backoff(ctx
);
10606 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
10607 struct intel_load_detect_pipe
*old
,
10608 struct drm_modeset_acquire_ctx
*ctx
)
10610 struct intel_encoder
*intel_encoder
=
10611 intel_attached_encoder(connector
);
10612 struct drm_encoder
*encoder
= &intel_encoder
->base
;
10613 struct drm_atomic_state
*state
= old
->restore_state
;
10616 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10617 connector
->base
.id
, connector
->name
,
10618 encoder
->base
.id
, encoder
->name
);
10623 ret
= drm_atomic_commit(state
);
10625 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret
);
10626 drm_atomic_state_free(state
);
10630 static int i9xx_pll_refclk(struct drm_device
*dev
,
10631 const struct intel_crtc_state
*pipe_config
)
10633 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10634 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
10636 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
10637 return dev_priv
->vbt
.lvds_ssc_freq
;
10638 else if (HAS_PCH_SPLIT(dev
))
10640 else if (!IS_GEN2(dev
))
10646 /* Returns the clock of the currently programmed mode of the given pipe. */
10647 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
10648 struct intel_crtc_state
*pipe_config
)
10650 struct drm_device
*dev
= crtc
->base
.dev
;
10651 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10652 int pipe
= pipe_config
->cpu_transcoder
;
10653 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
10657 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
10659 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
10660 fp
= pipe_config
->dpll_hw_state
.fp0
;
10662 fp
= pipe_config
->dpll_hw_state
.fp1
;
10664 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
10665 if (IS_PINEVIEW(dev
)) {
10666 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
10667 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
10669 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
10670 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
10673 if (!IS_GEN2(dev
)) {
10674 if (IS_PINEVIEW(dev
))
10675 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
10676 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
10678 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
10679 DPLL_FPA01_P1_POST_DIV_SHIFT
);
10681 switch (dpll
& DPLL_MODE_MASK
) {
10682 case DPLLB_MODE_DAC_SERIAL
:
10683 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
10686 case DPLLB_MODE_LVDS
:
10687 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
10691 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10692 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
10696 if (IS_PINEVIEW(dev
))
10697 port_clock
= pnv_calc_dpll_params(refclk
, &clock
);
10699 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
10701 u32 lvds
= IS_I830(dev
) ? 0 : I915_READ(LVDS
);
10702 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
10705 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
10706 DPLL_FPA01_P1_POST_DIV_SHIFT
);
10708 if (lvds
& LVDS_CLKB_POWER_UP
)
10713 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
10716 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
10717 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
10719 if (dpll
& PLL_P2_DIVIDE_BY_4
)
10725 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
10729 * This value includes pixel_multiplier. We will use
10730 * port_clock to compute adjusted_mode.crtc_clock in the
10731 * encoder's get_config() function.
10733 pipe_config
->port_clock
= port_clock
;
10736 int intel_dotclock_calculate(int link_freq
,
10737 const struct intel_link_m_n
*m_n
)
10740 * The calculation for the data clock is:
10741 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10742 * But we want to avoid losing precison if possible, so:
10743 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10745 * and the link clock is simpler:
10746 * link_clock = (m * link_clock) / n
10752 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
10755 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
10756 struct intel_crtc_state
*pipe_config
)
10758 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
10760 /* read out port_clock from the DPLL */
10761 i9xx_crtc_clock_get(crtc
, pipe_config
);
10764 * In case there is an active pipe without active ports,
10765 * we may need some idea for the dotclock anyway.
10766 * Calculate one based on the FDI configuration.
10768 pipe_config
->base
.adjusted_mode
.crtc_clock
=
10769 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
10770 &pipe_config
->fdi_m_n
);
10773 /** Returns the currently programmed mode of the given pipe. */
10774 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
10775 struct drm_crtc
*crtc
)
10777 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10778 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10779 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
10780 struct drm_display_mode
*mode
;
10781 struct intel_crtc_state
*pipe_config
;
10782 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
10783 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
10784 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
10785 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
10786 enum pipe pipe
= intel_crtc
->pipe
;
10788 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
10792 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
10793 if (!pipe_config
) {
10799 * Construct a pipe_config sufficient for getting the clock info
10800 * back out of crtc_clock_get.
10802 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
10803 * to use a real value here instead.
10805 pipe_config
->cpu_transcoder
= (enum transcoder
) pipe
;
10806 pipe_config
->pixel_multiplier
= 1;
10807 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
10808 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
10809 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
10810 i9xx_crtc_clock_get(intel_crtc
, pipe_config
);
10812 mode
->clock
= pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
10813 mode
->hdisplay
= (htot
& 0xffff) + 1;
10814 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
10815 mode
->hsync_start
= (hsync
& 0xffff) + 1;
10816 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
10817 mode
->vdisplay
= (vtot
& 0xffff) + 1;
10818 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
10819 mode
->vsync_start
= (vsync
& 0xffff) + 1;
10820 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
10822 drm_mode_set_name(mode
);
10824 kfree(pipe_config
);
10829 void intel_mark_busy(struct drm_i915_private
*dev_priv
)
10831 if (dev_priv
->mm
.busy
)
10834 intel_runtime_pm_get(dev_priv
);
10835 i915_update_gfx_val(dev_priv
);
10836 if (INTEL_GEN(dev_priv
) >= 6)
10837 gen6_rps_busy(dev_priv
);
10838 dev_priv
->mm
.busy
= true;
10841 void intel_mark_idle(struct drm_i915_private
*dev_priv
)
10843 if (!dev_priv
->mm
.busy
)
10846 dev_priv
->mm
.busy
= false;
10848 if (INTEL_GEN(dev_priv
) >= 6)
10849 gen6_rps_idle(dev_priv
);
10851 intel_runtime_pm_put(dev_priv
);
10854 void intel_free_flip_work(struct intel_flip_work
*work
)
10856 kfree(work
->old_connector_state
);
10857 kfree(work
->new_connector_state
);
10861 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
10863 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10864 struct drm_device
*dev
= crtc
->dev
;
10865 struct intel_flip_work
*work
;
10867 spin_lock_irq(&dev
->event_lock
);
10868 while (!list_empty(&intel_crtc
->flip_work
)) {
10869 work
= list_first_entry(&intel_crtc
->flip_work
,
10870 struct intel_flip_work
, head
);
10871 list_del_init(&work
->head
);
10872 spin_unlock_irq(&dev
->event_lock
);
10874 cancel_work_sync(&work
->mmio_work
);
10875 cancel_work_sync(&work
->unpin_work
);
10876 intel_free_flip_work(work
);
10878 spin_lock_irq(&dev
->event_lock
);
10880 spin_unlock_irq(&dev
->event_lock
);
10882 drm_crtc_cleanup(crtc
);
10887 static void intel_crtc_post_flip_update(struct intel_flip_work
*work
,
10888 struct drm_crtc
*crtc
)
10890 struct intel_crtc_state
*crtc_state
= work
->new_crtc_state
;
10891 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10893 if (crtc_state
->disable_cxsr
)
10894 intel_crtc
->wm
.cxsr_allowed
= true;
10896 if (crtc_state
->update_wm_post
&& crtc_state
->base
.active
)
10897 intel_update_watermarks(crtc
);
10899 if (work
->num_planes
> 0 &&
10900 work
->old_plane_state
[0]->base
.plane
== crtc
->primary
) {
10901 struct intel_plane_state
*plane_state
=
10902 work
->new_plane_state
[0];
10904 if (plane_state
->visible
&&
10905 (needs_modeset(&crtc_state
->base
) ||
10906 !work
->old_plane_state
[0]->visible
))
10907 intel_post_enable_primary(crtc
);
10911 static void intel_unpin_work_fn(struct work_struct
*__work
)
10913 struct intel_flip_work
*work
=
10914 container_of(__work
, struct intel_flip_work
, unpin_work
);
10915 struct drm_crtc
*crtc
= work
->old_crtc_state
->base
.crtc
;
10916 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10917 struct drm_device
*dev
= crtc
->dev
;
10918 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10922 intel_frontbuffer_flip_complete(dev
, work
->fb_bits
);
10925 * Unless work->can_async_unpin is false, there's no way to ensure
10926 * that work->new_crtc_state contains valid memory during unpin
10927 * because intel_atomic_commit may free it before this runs.
10929 if (!work
->can_async_unpin
) {
10930 intel_crtc_post_flip_update(work
, crtc
);
10932 if (dev_priv
->display
.optimize_watermarks
)
10933 dev_priv
->display
.optimize_watermarks(work
->new_crtc_state
);
10936 if (work
->fb_bits
& to_intel_plane(crtc
->primary
)->frontbuffer_bit
)
10937 intel_fbc_post_update(intel_crtc
);
10939 if (work
->put_power_domains
)
10940 modeset_put_power_domains(dev_priv
, work
->put_power_domains
);
10942 /* Make sure mmio work is completely finished before freeing all state here. */
10943 flush_work(&work
->mmio_work
);
10945 if (!work
->can_async_unpin
&&
10946 (work
->new_crtc_state
->update_pipe
||
10947 needs_modeset(&work
->new_crtc_state
->base
))) {
10948 /* This must be called before work is unpinned for serialization. */
10949 intel_modeset_verify_crtc(crtc
, &work
->old_crtc_state
->base
,
10950 &work
->new_crtc_state
->base
);
10952 for (i
= 0; i
< work
->num_new_connectors
; i
++) {
10953 struct drm_connector_state
*conn_state
=
10954 work
->new_connector_state
[i
];
10955 struct drm_connector
*con
= conn_state
->connector
;
10959 intel_connector_verify_state(to_intel_connector(con
),
10964 for (i
= 0; i
< work
->num_old_connectors
; i
++) {
10965 struct drm_connector_state
*old_con_state
=
10966 work
->old_connector_state
[i
];
10967 struct drm_connector
*con
=
10968 old_con_state
->connector
;
10970 con
->funcs
->atomic_destroy_state(con
, old_con_state
);
10973 if (!work
->can_async_unpin
|| !list_empty(&work
->head
)) {
10974 spin_lock_irq(&dev
->event_lock
);
10975 WARN(list_empty(&work
->head
) != work
->can_async_unpin
,
10976 "[CRTC:%i] Pin work %p async %i with %i planes, active %i -> %i ms %i\n",
10977 crtc
->base
.id
, work
, work
->can_async_unpin
, work
->num_planes
,
10978 work
->old_crtc_state
->base
.active
, work
->new_crtc_state
->base
.active
,
10979 needs_modeset(&work
->new_crtc_state
->base
));
10981 if (!list_empty(&work
->head
))
10982 list_del(&work
->head
);
10984 wake_up_all(&dev_priv
->pending_flip_queue
);
10985 spin_unlock_irq(&dev
->event_lock
);
10988 /* New crtc_state freed? */
10989 if (work
->free_new_crtc_state
)
10990 intel_crtc_destroy_state(crtc
, &work
->new_crtc_state
->base
);
10992 intel_crtc_destroy_state(crtc
, &work
->old_crtc_state
->base
);
10994 for (i
= 0; i
< work
->num_planes
; i
++) {
10995 struct intel_plane_state
*old_plane_state
=
10996 work
->old_plane_state
[i
];
10997 struct drm_framebuffer
*old_fb
= old_plane_state
->base
.fb
;
10998 struct drm_plane
*plane
= old_plane_state
->base
.plane
;
10999 struct drm_i915_gem_request
*req
;
11001 req
= old_plane_state
->wait_req
;
11002 old_plane_state
->wait_req
= NULL
;
11004 i915_gem_request_unreference(req
);
11006 fence_put(old_plane_state
->base
.fence
);
11007 old_plane_state
->base
.fence
= NULL
;
11010 (plane
->type
!= DRM_PLANE_TYPE_CURSOR
||
11011 !INTEL_INFO(dev_priv
)->cursor_needs_physical
)) {
11012 mutex_lock(&dev
->struct_mutex
);
11013 intel_unpin_fb_obj(old_fb
, old_plane_state
->base
.rotation
);
11014 mutex_unlock(&dev
->struct_mutex
);
11017 intel_plane_destroy_state(plane
, &old_plane_state
->base
);
11020 if (!WARN_ON(atomic_read(&intel_crtc
->unpin_work_count
) == 0))
11021 atomic_dec(&intel_crtc
->unpin_work_count
);
11023 intel_free_flip_work(work
);
11027 static bool pageflip_finished(struct intel_crtc
*crtc
,
11028 struct intel_flip_work
*work
)
11030 if (!atomic_read(&work
->pending
))
11036 * MMIO work completes when vblank is different from
11037 * flip_queued_vblank.
11039 return intel_crtc_get_vblank_counter(crtc
) != work
->flip_queued_vblank
;
11042 void intel_finish_page_flip_mmio(struct drm_i915_private
*dev_priv
, int pipe
)
11044 struct drm_device
*dev
= dev_priv
->dev
;
11045 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
11046 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11047 struct intel_flip_work
*work
;
11048 unsigned long flags
;
11050 /* Ignore early vblank irqs */
11055 * This is called both by irq handlers and the reset code (to complete
11056 * lost pageflips) so needs the full irqsave spinlocks.
11058 spin_lock_irqsave(&dev
->event_lock
, flags
);
11059 while (!list_empty(&intel_crtc
->flip_work
)) {
11060 work
= list_first_entry(&intel_crtc
->flip_work
,
11061 struct intel_flip_work
,
11064 if (!pageflip_finished(intel_crtc
, work
) ||
11065 work_busy(&work
->unpin_work
))
11068 page_flip_completed(intel_crtc
, work
);
11070 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
11073 static void intel_mmio_flip_work_func(struct work_struct
*w
)
11075 struct intel_flip_work
*work
=
11076 container_of(w
, struct intel_flip_work
, mmio_work
);
11077 struct drm_crtc
*crtc
= work
->old_crtc_state
->base
.crtc
;
11078 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11079 struct intel_crtc_state
*crtc_state
= work
->new_crtc_state
;
11080 struct drm_device
*dev
= crtc
->dev
;
11081 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11082 struct drm_i915_gem_request
*req
;
11085 if (!needs_modeset(&crtc_state
->base
) && crtc_state
->update_pipe
) {
11086 work
->put_power_domains
=
11087 modeset_get_crtc_power_domains(crtc
, crtc_state
);
11090 for (i
= 0; i
< work
->num_planes
; i
++) {
11091 struct intel_plane_state
*old_plane_state
= work
->old_plane_state
[i
];
11093 /* For framebuffer backed by dmabuf, wait for fence */
11094 if (old_plane_state
->base
.fence
)
11095 WARN_ON(fence_wait(old_plane_state
->base
.fence
, false) < 0);
11097 req
= old_plane_state
->wait_req
;
11101 WARN_ON(__i915_wait_request(req
, false, NULL
,
11102 &dev_priv
->rps
.mmioflips
));
11105 ret
= drm_crtc_vblank_get(crtc
);
11106 I915_STATE_WARN(ret
< 0, "enabling vblank failed with %i\n", ret
);
11108 if (work
->num_planes
&&
11109 work
->old_plane_state
[0]->base
.plane
== crtc
->primary
)
11110 intel_fbc_enable(intel_crtc
, work
->new_crtc_state
, work
->new_plane_state
[0]);
11112 intel_frontbuffer_flip_prepare(dev
, work
->fb_bits
);
11114 intel_pipe_update_start(intel_crtc
);
11115 if (!needs_modeset(&crtc_state
->base
)) {
11116 if (crtc_state
->base
.color_mgmt_changed
|| crtc_state
->update_pipe
) {
11117 intel_color_set_csc(&crtc_state
->base
);
11118 intel_color_load_luts(&crtc_state
->base
);
11121 if (crtc_state
->update_pipe
)
11122 intel_update_pipe_config(intel_crtc
, work
->old_crtc_state
);
11123 else if (INTEL_INFO(dev
)->gen
>= 9)
11124 skl_detach_scalers(intel_crtc
);
11127 for (i
= 0; i
< work
->num_planes
; i
++) {
11128 struct intel_plane_state
*new_plane_state
= work
->new_plane_state
[i
];
11129 struct intel_plane
*plane
= to_intel_plane(new_plane_state
->base
.plane
);
11131 if (new_plane_state
->visible
)
11132 plane
->update_plane(&plane
->base
, crtc_state
, new_plane_state
);
11134 plane
->disable_plane(&plane
->base
, crtc
);
11137 intel_pipe_update_end(intel_crtc
, work
);
11141 * intel_wm_need_update - Check whether watermarks need updating
11142 * @plane: drm plane
11143 * @state: new plane state
11145 * Check current plane state versus the new one to determine whether
11146 * watermarks need to be recalculated.
11148 * Returns true or false.
11150 static bool intel_wm_need_update(struct drm_plane
*plane
,
11151 struct drm_plane_state
*state
)
11153 struct intel_plane_state
*new = to_intel_plane_state(state
);
11154 struct intel_plane_state
*cur
= to_intel_plane_state(plane
->state
);
11156 /* Update watermarks on tiling or size changes. */
11157 if (new->visible
!= cur
->visible
)
11160 if (!cur
->base
.fb
|| !new->base
.fb
)
11163 if (cur
->base
.fb
->modifier
[0] != new->base
.fb
->modifier
[0] ||
11164 cur
->base
.rotation
!= new->base
.rotation
||
11165 drm_rect_width(&new->src
) != drm_rect_width(&cur
->src
) ||
11166 drm_rect_height(&new->src
) != drm_rect_height(&cur
->src
) ||
11167 drm_rect_width(&new->dst
) != drm_rect_width(&cur
->dst
) ||
11168 drm_rect_height(&new->dst
) != drm_rect_height(&cur
->dst
))
11174 static bool needs_scaling(struct intel_plane_state
*state
)
11176 int src_w
= drm_rect_width(&state
->src
) >> 16;
11177 int src_h
= drm_rect_height(&state
->src
) >> 16;
11178 int dst_w
= drm_rect_width(&state
->dst
);
11179 int dst_h
= drm_rect_height(&state
->dst
);
11181 return (src_w
!= dst_w
|| src_h
!= dst_h
);
11184 int intel_plane_atomic_calc_changes(struct drm_crtc_state
*crtc_state
,
11185 struct drm_plane_state
*plane_state
)
11187 struct intel_crtc_state
*pipe_config
= to_intel_crtc_state(crtc_state
);
11188 struct drm_crtc
*crtc
= crtc_state
->crtc
;
11189 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11190 struct drm_plane
*plane
= plane_state
->plane
;
11191 struct drm_device
*dev
= crtc
->dev
;
11192 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11193 struct intel_plane_state
*old_plane_state
=
11194 to_intel_plane_state(plane
->state
);
11195 int idx
= intel_crtc
->base
.base
.id
, ret
;
11196 bool mode_changed
= needs_modeset(crtc_state
);
11197 bool was_crtc_enabled
= crtc
->state
->active
;
11198 bool is_crtc_enabled
= crtc_state
->active
;
11199 bool turn_off
, turn_on
, visible
, was_visible
;
11200 struct drm_framebuffer
*fb
= plane_state
->fb
;
11202 if (crtc_state
&& INTEL_INFO(dev
)->gen
>= 9 &&
11203 plane
->type
!= DRM_PLANE_TYPE_CURSOR
) {
11204 ret
= skl_update_scaler_plane(
11205 to_intel_crtc_state(crtc_state
),
11206 to_intel_plane_state(plane_state
));
11211 was_visible
= old_plane_state
->visible
;
11212 visible
= to_intel_plane_state(plane_state
)->visible
;
11214 if (!was_crtc_enabled
&& WARN_ON(was_visible
))
11215 was_visible
= false;
11218 * Visibility is calculated as if the crtc was on, but
11219 * after scaler setup everything depends on it being off
11220 * when the crtc isn't active.
11222 * FIXME this is wrong for watermarks. Watermarks should also
11223 * be computed as if the pipe would be active. Perhaps move
11224 * per-plane wm computation to the .check_plane() hook, and
11225 * only combine the results from all planes in the current place?
11227 if (!is_crtc_enabled
)
11228 to_intel_plane_state(plane_state
)->visible
= visible
= false;
11230 if (!was_visible
&& !visible
)
11233 if (fb
!= old_plane_state
->base
.fb
)
11234 pipe_config
->fb_changed
= true;
11236 turn_off
= was_visible
&& (!visible
|| mode_changed
);
11237 turn_on
= visible
&& (!was_visible
|| mode_changed
);
11239 DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx
,
11240 plane
->base
.id
, fb
? fb
->base
.id
: -1);
11242 DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n",
11243 plane
->base
.id
, was_visible
, visible
,
11244 turn_off
, turn_on
, mode_changed
);
11247 pipe_config
->update_wm_pre
= true;
11249 /* must disable cxsr around plane enable/disable */
11250 if (plane
->type
!= DRM_PLANE_TYPE_CURSOR
)
11251 pipe_config
->disable_cxsr
= true;
11252 } else if (turn_off
) {
11253 pipe_config
->update_wm_post
= true;
11255 /* must disable cxsr around plane enable/disable */
11256 if (plane
->type
!= DRM_PLANE_TYPE_CURSOR
)
11257 pipe_config
->disable_cxsr
= true;
11258 } else if (intel_wm_need_update(plane
, plane_state
)) {
11259 /* FIXME bollocks */
11260 pipe_config
->update_wm_pre
= true;
11261 pipe_config
->update_wm_post
= true;
11264 /* Pre-gen9 platforms need two-step watermark updates */
11265 if ((pipe_config
->update_wm_pre
|| pipe_config
->update_wm_post
) &&
11266 INTEL_INFO(dev
)->gen
< 9 && dev_priv
->display
.optimize_watermarks
)
11267 to_intel_crtc_state(crtc_state
)->wm
.need_postvbl_update
= true;
11269 if (visible
|| was_visible
)
11270 pipe_config
->fb_bits
|= to_intel_plane(plane
)->frontbuffer_bit
;
11273 * WaCxSRDisabledForSpriteScaling:ivb
11275 * cstate->update_wm was already set above, so this flag will
11276 * take effect when we commit and program watermarks.
11278 if (plane
->type
== DRM_PLANE_TYPE_OVERLAY
&& IS_IVYBRIDGE(dev
) &&
11279 needs_scaling(to_intel_plane_state(plane_state
)) &&
11280 !needs_scaling(old_plane_state
))
11281 pipe_config
->disable_lp_wm
= true;
11286 static bool encoders_cloneable(const struct intel_encoder
*a
,
11287 const struct intel_encoder
*b
)
11289 /* masks could be asymmetric, so check both ways */
11290 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
11291 b
->cloneable
& (1 << a
->type
));
11294 static bool check_single_encoder_cloning(struct drm_atomic_state
*state
,
11295 struct intel_crtc
*crtc
,
11296 struct intel_encoder
*encoder
)
11298 struct intel_encoder
*source_encoder
;
11299 struct drm_connector
*connector
;
11300 struct drm_connector_state
*connector_state
;
11303 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11304 if (connector_state
->crtc
!= &crtc
->base
)
11308 to_intel_encoder(connector_state
->best_encoder
);
11309 if (!encoders_cloneable(encoder
, source_encoder
))
11316 static bool check_encoder_cloning(struct drm_atomic_state
*state
,
11317 struct intel_crtc
*crtc
)
11319 struct intel_encoder
*encoder
;
11320 struct drm_connector
*connector
;
11321 struct drm_connector_state
*connector_state
;
11324 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11325 if (connector_state
->crtc
!= &crtc
->base
)
11328 encoder
= to_intel_encoder(connector_state
->best_encoder
);
11329 if (!check_single_encoder_cloning(state
, crtc
, encoder
))
11336 static int intel_crtc_atomic_check(struct drm_crtc
*crtc
,
11337 struct drm_crtc_state
*crtc_state
)
11339 struct drm_device
*dev
= crtc
->dev
;
11340 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11341 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11342 struct intel_crtc_state
*pipe_config
=
11343 to_intel_crtc_state(crtc_state
);
11344 struct drm_atomic_state
*state
= crtc_state
->state
;
11346 bool mode_changed
= needs_modeset(crtc_state
);
11348 if (mode_changed
&& !check_encoder_cloning(state
, intel_crtc
)) {
11349 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
11353 if (mode_changed
&& !crtc_state
->active
)
11354 pipe_config
->update_wm_post
= true;
11356 if (mode_changed
&& crtc_state
->enable
&&
11357 dev_priv
->display
.crtc_compute_clock
&&
11358 !WARN_ON(pipe_config
->shared_dpll
)) {
11359 ret
= dev_priv
->display
.crtc_compute_clock(intel_crtc
,
11365 if (crtc_state
->color_mgmt_changed
) {
11366 ret
= intel_color_check(crtc
, crtc_state
);
11372 if (dev_priv
->display
.compute_pipe_wm
) {
11373 ret
= dev_priv
->display
.compute_pipe_wm(pipe_config
);
11375 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
11380 if (dev_priv
->display
.compute_intermediate_wm
&&
11381 !to_intel_atomic_state(state
)->skip_intermediate_wm
) {
11382 if (WARN_ON(!dev_priv
->display
.compute_pipe_wm
))
11386 * Calculate 'intermediate' watermarks that satisfy both the
11387 * old state and the new state. We can program these
11390 ret
= dev_priv
->display
.compute_intermediate_wm(crtc
->dev
,
11394 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
11397 } else if (dev_priv
->display
.compute_intermediate_wm
) {
11398 if (HAS_PCH_SPLIT(dev_priv
) && INTEL_GEN(dev_priv
) < 9)
11399 pipe_config
->wm
.ilk
.intermediate
= pipe_config
->wm
.ilk
.optimal
;
11402 if (INTEL_INFO(dev
)->gen
>= 9) {
11404 ret
= skl_update_scaler_crtc(pipe_config
);
11407 ret
= intel_atomic_setup_scalers(dev
, intel_crtc
,
11414 static const struct drm_crtc_helper_funcs intel_helper_funcs
= {
11415 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
11416 .atomic_check
= intel_crtc_atomic_check
,
11419 static void intel_modeset_update_connector_atomic_state(struct drm_device
*dev
)
11421 struct intel_connector
*connector
;
11423 for_each_intel_connector(dev
, connector
) {
11424 if (connector
->base
.state
->crtc
)
11425 drm_connector_unreference(&connector
->base
);
11427 if (connector
->base
.encoder
) {
11428 connector
->base
.state
->best_encoder
=
11429 connector
->base
.encoder
;
11430 connector
->base
.state
->crtc
=
11431 connector
->base
.encoder
->crtc
;
11433 drm_connector_reference(&connector
->base
);
11435 connector
->base
.state
->best_encoder
= NULL
;
11436 connector
->base
.state
->crtc
= NULL
;
11442 connected_sink_compute_bpp(struct intel_connector
*connector
,
11443 struct intel_crtc_state
*pipe_config
)
11445 int bpp
= pipe_config
->pipe_bpp
;
11447 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
11448 connector
->base
.base
.id
,
11449 connector
->base
.name
);
11451 /* Don't use an invalid EDID bpc value */
11452 if (connector
->base
.display_info
.bpc
&&
11453 connector
->base
.display_info
.bpc
* 3 < bpp
) {
11454 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
11455 bpp
, connector
->base
.display_info
.bpc
*3);
11456 pipe_config
->pipe_bpp
= connector
->base
.display_info
.bpc
*3;
11459 /* Clamp bpp to default limit on screens without EDID 1.4 */
11460 if (connector
->base
.display_info
.bpc
== 0) {
11461 int type
= connector
->base
.connector_type
;
11462 int clamp_bpp
= 24;
11464 /* Fall back to 18 bpp when DP sink capability is unknown. */
11465 if (type
== DRM_MODE_CONNECTOR_DisplayPort
||
11466 type
== DRM_MODE_CONNECTOR_eDP
)
11469 if (bpp
> clamp_bpp
) {
11470 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of %d\n",
11472 pipe_config
->pipe_bpp
= clamp_bpp
;
11478 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
11479 struct intel_crtc_state
*pipe_config
)
11481 struct drm_device
*dev
= crtc
->base
.dev
;
11482 struct drm_atomic_state
*state
;
11483 struct drm_connector
*connector
;
11484 struct drm_connector_state
*connector_state
;
11487 if ((IS_G4X(dev
) || IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)))
11489 else if (INTEL_INFO(dev
)->gen
>= 5)
11495 pipe_config
->pipe_bpp
= bpp
;
11497 state
= pipe_config
->base
.state
;
11499 /* Clamp display bpp to EDID value */
11500 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11501 if (connector_state
->crtc
!= &crtc
->base
)
11504 connected_sink_compute_bpp(to_intel_connector(connector
),
11511 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
11513 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11514 "type: 0x%x flags: 0x%x\n",
11516 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
11517 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
11518 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
11519 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
11522 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
11523 struct intel_crtc_state
*pipe_config
,
11524 const char *context
)
11526 struct drm_device
*dev
= crtc
->base
.dev
;
11527 struct drm_plane
*plane
;
11528 struct intel_plane
*intel_plane
;
11529 struct intel_plane_state
*state
;
11530 struct drm_framebuffer
*fb
;
11532 DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc
->base
.base
.id
,
11533 context
, pipe_config
, pipe_name(crtc
->pipe
));
11535 DRM_DEBUG_KMS("cpu_transcoder: %s\n", transcoder_name(pipe_config
->cpu_transcoder
));
11536 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
11537 pipe_config
->pipe_bpp
, pipe_config
->dither
);
11538 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11539 pipe_config
->has_pch_encoder
,
11540 pipe_config
->fdi_lanes
,
11541 pipe_config
->fdi_m_n
.gmch_m
, pipe_config
->fdi_m_n
.gmch_n
,
11542 pipe_config
->fdi_m_n
.link_m
, pipe_config
->fdi_m_n
.link_n
,
11543 pipe_config
->fdi_m_n
.tu
);
11544 DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11545 pipe_config
->has_dp_encoder
,
11546 pipe_config
->lane_count
,
11547 pipe_config
->dp_m_n
.gmch_m
, pipe_config
->dp_m_n
.gmch_n
,
11548 pipe_config
->dp_m_n
.link_m
, pipe_config
->dp_m_n
.link_n
,
11549 pipe_config
->dp_m_n
.tu
);
11551 DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
11552 pipe_config
->has_dp_encoder
,
11553 pipe_config
->lane_count
,
11554 pipe_config
->dp_m2_n2
.gmch_m
,
11555 pipe_config
->dp_m2_n2
.gmch_n
,
11556 pipe_config
->dp_m2_n2
.link_m
,
11557 pipe_config
->dp_m2_n2
.link_n
,
11558 pipe_config
->dp_m2_n2
.tu
);
11560 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
11561 pipe_config
->has_audio
,
11562 pipe_config
->has_infoframe
);
11564 DRM_DEBUG_KMS("requested mode:\n");
11565 drm_mode_debug_printmodeline(&pipe_config
->base
.mode
);
11566 DRM_DEBUG_KMS("adjusted mode:\n");
11567 drm_mode_debug_printmodeline(&pipe_config
->base
.adjusted_mode
);
11568 intel_dump_crtc_timings(&pipe_config
->base
.adjusted_mode
);
11569 DRM_DEBUG_KMS("port clock: %d\n", pipe_config
->port_clock
);
11570 DRM_DEBUG_KMS("pipe src size: %dx%d\n",
11571 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
11572 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
11574 pipe_config
->scaler_state
.scaler_users
,
11575 pipe_config
->scaler_state
.scaler_id
);
11576 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
11577 pipe_config
->gmch_pfit
.control
,
11578 pipe_config
->gmch_pfit
.pgm_ratios
,
11579 pipe_config
->gmch_pfit
.lvds_border_bits
);
11580 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
11581 pipe_config
->pch_pfit
.pos
,
11582 pipe_config
->pch_pfit
.size
,
11583 pipe_config
->pch_pfit
.enabled
? "enabled" : "disabled");
11584 DRM_DEBUG_KMS("ips: %i\n", pipe_config
->ips_enabled
);
11585 DRM_DEBUG_KMS("double wide: %i\n", pipe_config
->double_wide
);
11587 if (IS_BROXTON(dev
)) {
11588 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x,"
11589 "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, "
11590 "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n",
11591 pipe_config
->ddi_pll_sel
,
11592 pipe_config
->dpll_hw_state
.ebb0
,
11593 pipe_config
->dpll_hw_state
.ebb4
,
11594 pipe_config
->dpll_hw_state
.pll0
,
11595 pipe_config
->dpll_hw_state
.pll1
,
11596 pipe_config
->dpll_hw_state
.pll2
,
11597 pipe_config
->dpll_hw_state
.pll3
,
11598 pipe_config
->dpll_hw_state
.pll6
,
11599 pipe_config
->dpll_hw_state
.pll8
,
11600 pipe_config
->dpll_hw_state
.pll9
,
11601 pipe_config
->dpll_hw_state
.pll10
,
11602 pipe_config
->dpll_hw_state
.pcsdw12
);
11603 } else if (IS_SKYLAKE(dev
) || IS_KABYLAKE(dev
)) {
11604 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: "
11605 "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n",
11606 pipe_config
->ddi_pll_sel
,
11607 pipe_config
->dpll_hw_state
.ctrl1
,
11608 pipe_config
->dpll_hw_state
.cfgcr1
,
11609 pipe_config
->dpll_hw_state
.cfgcr2
);
11610 } else if (HAS_DDI(dev
)) {
11611 DRM_DEBUG_KMS("ddi_pll_sel: 0x%x; dpll_hw_state: wrpll: 0x%x spll: 0x%x\n",
11612 pipe_config
->ddi_pll_sel
,
11613 pipe_config
->dpll_hw_state
.wrpll
,
11614 pipe_config
->dpll_hw_state
.spll
);
11616 DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, "
11617 "fp0: 0x%x, fp1: 0x%x\n",
11618 pipe_config
->dpll_hw_state
.dpll
,
11619 pipe_config
->dpll_hw_state
.dpll_md
,
11620 pipe_config
->dpll_hw_state
.fp0
,
11621 pipe_config
->dpll_hw_state
.fp1
);
11624 DRM_DEBUG_KMS("planes on this crtc\n");
11625 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
11626 intel_plane
= to_intel_plane(plane
);
11627 if (intel_plane
->pipe
!= crtc
->pipe
)
11630 state
= to_intel_plane_state(plane
->state
);
11631 fb
= state
->base
.fb
;
11633 DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d "
11634 "disabled, scaler_id = %d\n",
11635 plane
->type
== DRM_PLANE_TYPE_CURSOR
? "CURSOR" : "STANDARD",
11636 plane
->base
.id
, intel_plane
->pipe
,
11637 (crtc
->base
.primary
== plane
) ? 0 : intel_plane
->plane
+ 1,
11638 drm_plane_index(plane
), state
->scaler_id
);
11642 DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled",
11643 plane
->type
== DRM_PLANE_TYPE_CURSOR
? "CURSOR" : "STANDARD",
11644 plane
->base
.id
, intel_plane
->pipe
,
11645 crtc
->base
.primary
== plane
? 0 : intel_plane
->plane
+ 1,
11646 drm_plane_index(plane
));
11647 DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x",
11648 fb
->base
.id
, fb
->width
, fb
->height
, fb
->pixel_format
);
11649 DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n",
11651 state
->src
.x1
>> 16, state
->src
.y1
>> 16,
11652 drm_rect_width(&state
->src
) >> 16,
11653 drm_rect_height(&state
->src
) >> 16,
11654 state
->dst
.x1
, state
->dst
.y1
,
11655 drm_rect_width(&state
->dst
), drm_rect_height(&state
->dst
));
11659 static bool check_digital_port_conflicts(struct drm_atomic_state
*state
)
11661 struct drm_device
*dev
= state
->dev
;
11662 struct drm_connector
*connector
;
11663 unsigned int used_ports
= 0;
11666 * Walk the connector list instead of the encoder
11667 * list to detect the problem on ddi platforms
11668 * where there's just one encoder per digital port.
11670 drm_for_each_connector(connector
, dev
) {
11671 struct drm_connector_state
*connector_state
;
11672 struct intel_encoder
*encoder
;
11674 connector_state
= drm_atomic_get_existing_connector_state(state
, connector
);
11675 if (!connector_state
)
11676 connector_state
= connector
->state
;
11678 if (!connector_state
->best_encoder
)
11681 encoder
= to_intel_encoder(connector_state
->best_encoder
);
11683 WARN_ON(!connector_state
->crtc
);
11685 switch (encoder
->type
) {
11686 unsigned int port_mask
;
11687 case INTEL_OUTPUT_UNKNOWN
:
11688 if (WARN_ON(!HAS_DDI(dev
)))
11690 case INTEL_OUTPUT_DISPLAYPORT
:
11691 case INTEL_OUTPUT_HDMI
:
11692 case INTEL_OUTPUT_EDP
:
11693 port_mask
= 1 << enc_to_dig_port(&encoder
->base
)->port
;
11695 /* the same port mustn't appear more than once */
11696 if (used_ports
& port_mask
)
11699 used_ports
|= port_mask
;
11709 clear_intel_crtc_state(struct intel_crtc_state
*crtc_state
)
11711 struct drm_crtc_state tmp_state
;
11712 struct intel_crtc_scaler_state scaler_state
;
11713 struct intel_dpll_hw_state dpll_hw_state
;
11714 struct intel_shared_dpll
*shared_dpll
;
11715 uint32_t ddi_pll_sel
;
11718 /* FIXME: before the switch to atomic started, a new pipe_config was
11719 * kzalloc'd. Code that depends on any field being zero should be
11720 * fixed, so that the crtc_state can be safely duplicated. For now,
11721 * only fields that are know to not cause problems are preserved. */
11723 tmp_state
= crtc_state
->base
;
11724 scaler_state
= crtc_state
->scaler_state
;
11725 shared_dpll
= crtc_state
->shared_dpll
;
11726 dpll_hw_state
= crtc_state
->dpll_hw_state
;
11727 ddi_pll_sel
= crtc_state
->ddi_pll_sel
;
11728 force_thru
= crtc_state
->pch_pfit
.force_thru
;
11730 memset(crtc_state
, 0, sizeof *crtc_state
);
11732 crtc_state
->base
= tmp_state
;
11733 crtc_state
->scaler_state
= scaler_state
;
11734 crtc_state
->shared_dpll
= shared_dpll
;
11735 crtc_state
->dpll_hw_state
= dpll_hw_state
;
11736 crtc_state
->ddi_pll_sel
= ddi_pll_sel
;
11737 crtc_state
->pch_pfit
.force_thru
= force_thru
;
11741 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
11742 struct intel_crtc_state
*pipe_config
)
11744 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
11745 struct intel_encoder
*encoder
;
11746 struct drm_connector
*connector
;
11747 struct drm_connector_state
*connector_state
;
11748 int base_bpp
, ret
= -EINVAL
;
11752 clear_intel_crtc_state(pipe_config
);
11754 pipe_config
->cpu_transcoder
=
11755 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
11758 * Sanitize sync polarity flags based on requested ones. If neither
11759 * positive or negative polarity is requested, treat this as meaning
11760 * negative polarity.
11762 if (!(pipe_config
->base
.adjusted_mode
.flags
&
11763 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
11764 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
11766 if (!(pipe_config
->base
.adjusted_mode
.flags
&
11767 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
11768 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
11770 base_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
11776 * Determine the real pipe dimensions. Note that stereo modes can
11777 * increase the actual pipe size due to the frame doubling and
11778 * insertion of additional space for blanks between the frame. This
11779 * is stored in the crtc timings. We use the requested mode to do this
11780 * computation to clearly distinguish it from the adjusted mode, which
11781 * can be changed by the connectors in the below retry loop.
11783 drm_crtc_get_hv_timing(&pipe_config
->base
.mode
,
11784 &pipe_config
->pipe_src_w
,
11785 &pipe_config
->pipe_src_h
);
11788 /* Ensure the port clock defaults are reset when retrying. */
11789 pipe_config
->port_clock
= 0;
11790 pipe_config
->pixel_multiplier
= 1;
11792 /* Fill in default crtc timings, allow encoders to overwrite them. */
11793 drm_mode_set_crtcinfo(&pipe_config
->base
.adjusted_mode
,
11794 CRTC_STEREO_DOUBLE
);
11796 /* Pass our mode to the connectors and the CRTC to give them a chance to
11797 * adjust it according to limitations or connector properties, and also
11798 * a chance to reject the mode entirely.
11800 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11801 if (connector_state
->crtc
!= crtc
)
11804 encoder
= to_intel_encoder(connector_state
->best_encoder
);
11806 if (!(encoder
->compute_config(encoder
, pipe_config
))) {
11807 DRM_DEBUG_KMS("Encoder config failure\n");
11812 /* Set default port clock if not overwritten by the encoder. Needs to be
11813 * done afterwards in case the encoder adjusts the mode. */
11814 if (!pipe_config
->port_clock
)
11815 pipe_config
->port_clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
11816 * pipe_config
->pixel_multiplier
;
11818 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
11820 DRM_DEBUG_KMS("CRTC fixup failed\n");
11824 if (ret
== RETRY
) {
11825 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
11830 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11832 goto encoder_retry
;
11835 /* Dithering seems to not pass-through bits correctly when it should, so
11836 * only enable it on 6bpc panels. */
11837 pipe_config
->dither
= pipe_config
->pipe_bpp
== 6*3;
11838 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
11839 base_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
11846 intel_modeset_update_crtc_state(struct drm_atomic_state
*state
)
11848 struct drm_crtc
*crtc
;
11849 struct drm_crtc_state
*crtc_state
;
11852 /* Double check state. */
11853 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
11854 to_intel_crtc(crtc
)->config
= to_intel_crtc_state(crtc
->state
);
11856 /* Update hwmode for vblank functions */
11857 if (crtc
->state
->active
)
11858 crtc
->hwmode
= crtc
->state
->adjusted_mode
;
11860 crtc
->hwmode
.crtc_clock
= 0;
11863 * Update legacy state to satisfy fbc code. This can
11864 * be removed when fbc uses the atomic state.
11866 if (drm_atomic_get_existing_plane_state(state
, crtc
->primary
)) {
11867 struct drm_plane_state
*plane_state
= crtc
->primary
->state
;
11869 crtc
->primary
->fb
= plane_state
->fb
;
11870 crtc
->x
= plane_state
->src_x
>> 16;
11871 crtc
->y
= plane_state
->src_y
>> 16;
11876 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
11880 if (clock1
== clock2
)
11883 if (!clock1
|| !clock2
)
11886 diff
= abs(clock1
- clock2
);
11888 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
11894 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
11895 list_for_each_entry((intel_crtc), \
11896 &(dev)->mode_config.crtc_list, \
11898 for_each_if (mask & (1 <<(intel_crtc)->pipe))
11901 intel_compare_m_n(unsigned int m
, unsigned int n
,
11902 unsigned int m2
, unsigned int n2
,
11905 if (m
== m2
&& n
== n2
)
11908 if (exact
|| !m
|| !n
|| !m2
|| !n2
)
11911 BUILD_BUG_ON(DATA_LINK_M_N_MASK
> INT_MAX
);
11918 } else if (n
< n2
) {
11928 return intel_fuzzy_clock_check(m
, m2
);
11932 intel_compare_link_m_n(const struct intel_link_m_n
*m_n
,
11933 struct intel_link_m_n
*m2_n2
,
11936 if (m_n
->tu
== m2_n2
->tu
&&
11937 intel_compare_m_n(m_n
->gmch_m
, m_n
->gmch_n
,
11938 m2_n2
->gmch_m
, m2_n2
->gmch_n
, !adjust
) &&
11939 intel_compare_m_n(m_n
->link_m
, m_n
->link_n
,
11940 m2_n2
->link_m
, m2_n2
->link_n
, !adjust
)) {
11951 intel_pipe_config_compare(struct drm_device
*dev
,
11952 struct intel_crtc_state
*current_config
,
11953 struct intel_crtc_state
*pipe_config
,
11958 #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \
11961 DRM_ERROR(fmt, ##__VA_ARGS__); \
11963 DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \
11966 #define PIPE_CONF_CHECK_X(name) \
11967 if (current_config->name != pipe_config->name) { \
11968 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
11969 "(expected 0x%08x, found 0x%08x)\n", \
11970 current_config->name, \
11971 pipe_config->name); \
11975 #define PIPE_CONF_CHECK_I(name) \
11976 if (current_config->name != pipe_config->name) { \
11977 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
11978 "(expected %i, found %i)\n", \
11979 current_config->name, \
11980 pipe_config->name); \
11984 #define PIPE_CONF_CHECK_P(name) \
11985 if (current_config->name != pipe_config->name) { \
11986 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
11987 "(expected %p, found %p)\n", \
11988 current_config->name, \
11989 pipe_config->name); \
11993 #define PIPE_CONF_CHECK_M_N(name) \
11994 if (!intel_compare_link_m_n(¤t_config->name, \
11995 &pipe_config->name,\
11997 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
11998 "(expected tu %i gmch %i/%i link %i/%i, " \
11999 "found tu %i, gmch %i/%i link %i/%i)\n", \
12000 current_config->name.tu, \
12001 current_config->name.gmch_m, \
12002 current_config->name.gmch_n, \
12003 current_config->name.link_m, \
12004 current_config->name.link_n, \
12005 pipe_config->name.tu, \
12006 pipe_config->name.gmch_m, \
12007 pipe_config->name.gmch_n, \
12008 pipe_config->name.link_m, \
12009 pipe_config->name.link_n); \
12013 /* This is required for BDW+ where there is only one set of registers for
12014 * switching between high and low RR.
12015 * This macro can be used whenever a comparison has to be made between one
12016 * hw state and multiple sw state variables.
12018 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \
12019 if (!intel_compare_link_m_n(¤t_config->name, \
12020 &pipe_config->name, adjust) && \
12021 !intel_compare_link_m_n(¤t_config->alt_name, \
12022 &pipe_config->name, adjust)) { \
12023 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12024 "(expected tu %i gmch %i/%i link %i/%i, " \
12025 "or tu %i gmch %i/%i link %i/%i, " \
12026 "found tu %i, gmch %i/%i link %i/%i)\n", \
12027 current_config->name.tu, \
12028 current_config->name.gmch_m, \
12029 current_config->name.gmch_n, \
12030 current_config->name.link_m, \
12031 current_config->name.link_n, \
12032 current_config->alt_name.tu, \
12033 current_config->alt_name.gmch_m, \
12034 current_config->alt_name.gmch_n, \
12035 current_config->alt_name.link_m, \
12036 current_config->alt_name.link_n, \
12037 pipe_config->name.tu, \
12038 pipe_config->name.gmch_m, \
12039 pipe_config->name.gmch_n, \
12040 pipe_config->name.link_m, \
12041 pipe_config->name.link_n); \
12045 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
12046 if ((current_config->name ^ pipe_config->name) & (mask)) { \
12047 INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \
12048 "(expected %i, found %i)\n", \
12049 current_config->name & (mask), \
12050 pipe_config->name & (mask)); \
12054 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
12055 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
12056 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12057 "(expected %i, found %i)\n", \
12058 current_config->name, \
12059 pipe_config->name); \
12063 #define PIPE_CONF_QUIRK(quirk) \
12064 ((current_config->quirks | pipe_config->quirks) & (quirk))
12066 PIPE_CONF_CHECK_I(cpu_transcoder
);
12068 PIPE_CONF_CHECK_I(has_pch_encoder
);
12069 PIPE_CONF_CHECK_I(fdi_lanes
);
12070 PIPE_CONF_CHECK_M_N(fdi_m_n
);
12072 PIPE_CONF_CHECK_I(has_dp_encoder
);
12073 PIPE_CONF_CHECK_I(lane_count
);
12075 if (INTEL_INFO(dev
)->gen
< 8) {
12076 PIPE_CONF_CHECK_M_N(dp_m_n
);
12078 if (current_config
->has_drrs
)
12079 PIPE_CONF_CHECK_M_N(dp_m2_n2
);
12081 PIPE_CONF_CHECK_M_N_ALT(dp_m_n
, dp_m2_n2
);
12083 PIPE_CONF_CHECK_I(has_dsi_encoder
);
12085 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hdisplay
);
12086 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_htotal
);
12087 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_start
);
12088 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_end
);
12089 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_start
);
12090 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_end
);
12092 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vdisplay
);
12093 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vtotal
);
12094 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_start
);
12095 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_end
);
12096 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_start
);
12097 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_end
);
12099 PIPE_CONF_CHECK_I(pixel_multiplier
);
12100 PIPE_CONF_CHECK_I(has_hdmi_sink
);
12101 if ((INTEL_INFO(dev
)->gen
< 8 && !IS_HASWELL(dev
)) ||
12102 IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
))
12103 PIPE_CONF_CHECK_I(limited_color_range
);
12104 PIPE_CONF_CHECK_I(has_infoframe
);
12106 PIPE_CONF_CHECK_I(has_audio
);
12108 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12109 DRM_MODE_FLAG_INTERLACE
);
12111 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
12112 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12113 DRM_MODE_FLAG_PHSYNC
);
12114 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12115 DRM_MODE_FLAG_NHSYNC
);
12116 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12117 DRM_MODE_FLAG_PVSYNC
);
12118 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12119 DRM_MODE_FLAG_NVSYNC
);
12122 PIPE_CONF_CHECK_X(gmch_pfit
.control
);
12123 /* pfit ratios are autocomputed by the hw on gen4+ */
12124 if (INTEL_INFO(dev
)->gen
< 4)
12125 PIPE_CONF_CHECK_X(gmch_pfit
.pgm_ratios
);
12126 PIPE_CONF_CHECK_X(gmch_pfit
.lvds_border_bits
);
12129 PIPE_CONF_CHECK_I(pipe_src_w
);
12130 PIPE_CONF_CHECK_I(pipe_src_h
);
12132 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
12133 if (current_config
->pch_pfit
.enabled
) {
12134 PIPE_CONF_CHECK_X(pch_pfit
.pos
);
12135 PIPE_CONF_CHECK_X(pch_pfit
.size
);
12138 PIPE_CONF_CHECK_I(scaler_state
.scaler_id
);
12141 /* BDW+ don't expose a synchronous way to read the state */
12142 if (IS_HASWELL(dev
))
12143 PIPE_CONF_CHECK_I(ips_enabled
);
12145 PIPE_CONF_CHECK_I(double_wide
);
12147 PIPE_CONF_CHECK_X(ddi_pll_sel
);
12149 PIPE_CONF_CHECK_P(shared_dpll
);
12150 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
12151 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
12152 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
12153 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
12154 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
12155 PIPE_CONF_CHECK_X(dpll_hw_state
.spll
);
12156 PIPE_CONF_CHECK_X(dpll_hw_state
.ctrl1
);
12157 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr1
);
12158 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr2
);
12160 PIPE_CONF_CHECK_X(dsi_pll
.ctrl
);
12161 PIPE_CONF_CHECK_X(dsi_pll
.div
);
12163 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5)
12164 PIPE_CONF_CHECK_I(pipe_bpp
);
12166 PIPE_CONF_CHECK_CLOCK_FUZZY(base
.adjusted_mode
.crtc_clock
);
12167 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
12169 #undef PIPE_CONF_CHECK_X
12170 #undef PIPE_CONF_CHECK_I
12171 #undef PIPE_CONF_CHECK_P
12172 #undef PIPE_CONF_CHECK_FLAGS
12173 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
12174 #undef PIPE_CONF_QUIRK
12175 #undef INTEL_ERR_OR_DBG_KMS
12180 static void intel_pipe_config_sanity_check(struct drm_i915_private
*dev_priv
,
12181 const struct intel_crtc_state
*pipe_config
)
12183 if (pipe_config
->has_pch_encoder
) {
12184 int fdi_dotclock
= intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
12185 &pipe_config
->fdi_m_n
);
12186 int dotclock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
12189 * FDI already provided one idea for the dotclock.
12190 * Yell if the encoder disagrees.
12192 WARN(!intel_fuzzy_clock_check(fdi_dotclock
, dotclock
),
12193 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
12194 fdi_dotclock
, dotclock
);
12198 static void verify_wm_state(struct drm_crtc
*crtc
,
12199 struct drm_crtc_state
*new_state
)
12201 struct drm_device
*dev
= crtc
->dev
;
12202 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12203 struct skl_ddb_allocation hw_ddb
, *sw_ddb
;
12204 struct skl_ddb_entry
*hw_entry
, *sw_entry
;
12205 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12206 const enum pipe pipe
= intel_crtc
->pipe
;
12209 if (INTEL_INFO(dev
)->gen
< 9 || !new_state
->active
)
12212 skl_ddb_get_hw_state(dev_priv
, &hw_ddb
);
12213 sw_ddb
= &dev_priv
->wm
.skl_hw
.ddb
;
12216 for_each_plane(dev_priv
, pipe
, plane
) {
12217 hw_entry
= &hw_ddb
.plane
[pipe
][plane
];
12218 sw_entry
= &sw_ddb
->plane
[pipe
][plane
];
12220 if (skl_ddb_entry_equal(hw_entry
, sw_entry
))
12223 DRM_ERROR("mismatch in DDB state pipe %c plane %d "
12224 "(expected (%u,%u), found (%u,%u))\n",
12225 pipe_name(pipe
), plane
+ 1,
12226 sw_entry
->start
, sw_entry
->end
,
12227 hw_entry
->start
, hw_entry
->end
);
12231 hw_entry
= &hw_ddb
.plane
[pipe
][PLANE_CURSOR
];
12232 sw_entry
= &sw_ddb
->plane
[pipe
][PLANE_CURSOR
];
12234 if (!skl_ddb_entry_equal(hw_entry
, sw_entry
)) {
12235 DRM_ERROR("mismatch in DDB state pipe %c cursor "
12236 "(expected (%u,%u), found (%u,%u))\n",
12238 sw_entry
->start
, sw_entry
->end
,
12239 hw_entry
->start
, hw_entry
->end
);
12244 verify_connector_state(struct drm_device
*dev
, struct drm_crtc
*crtc
)
12246 struct drm_connector
*connector
;
12248 drm_for_each_connector(connector
, dev
) {
12249 struct drm_encoder
*encoder
= connector
->encoder
;
12250 struct drm_connector_state
*state
= connector
->state
;
12252 if (state
->crtc
!= crtc
)
12255 intel_connector_verify_state(to_intel_connector(connector
),
12258 I915_STATE_WARN(state
->best_encoder
!= encoder
,
12259 "connector's atomic encoder doesn't match legacy encoder\n");
12264 verify_encoder_state(struct drm_device
*dev
)
12266 struct intel_encoder
*encoder
;
12267 struct intel_connector
*connector
;
12269 for_each_intel_encoder(dev
, encoder
) {
12270 bool enabled
= false;
12273 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
12274 encoder
->base
.base
.id
,
12275 encoder
->base
.name
);
12277 for_each_intel_connector(dev
, connector
) {
12278 if (connector
->base
.state
->best_encoder
!= &encoder
->base
)
12282 I915_STATE_WARN(connector
->base
.state
->crtc
!=
12283 encoder
->base
.crtc
,
12284 "connector's crtc doesn't match encoder crtc\n");
12287 I915_STATE_WARN(!!encoder
->base
.crtc
!= enabled
,
12288 "encoder's enabled state mismatch "
12289 "(expected %i, found %i)\n",
12290 !!encoder
->base
.crtc
, enabled
);
12292 if (!encoder
->base
.crtc
) {
12295 active
= encoder
->get_hw_state(encoder
, &pipe
);
12296 I915_STATE_WARN(active
,
12297 "encoder detached but still enabled on pipe %c.\n",
12304 verify_crtc_state(struct drm_crtc
*crtc
,
12305 struct drm_crtc_state
*old_crtc_state
,
12306 struct drm_crtc_state
*new_crtc_state
)
12308 struct drm_device
*dev
= crtc
->dev
;
12309 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12310 struct intel_encoder
*encoder
;
12311 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12312 struct intel_crtc_state
*pipe_config
, *sw_config
;
12313 struct drm_atomic_state
*old_state
;
12316 old_state
= old_crtc_state
->state
;
12317 __drm_atomic_helper_crtc_destroy_state(crtc
, old_crtc_state
);
12318 pipe_config
= to_intel_crtc_state(old_crtc_state
);
12319 memset(pipe_config
, 0, sizeof(*pipe_config
));
12320 pipe_config
->base
.crtc
= crtc
;
12321 pipe_config
->base
.state
= old_state
;
12323 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
12325 active
= dev_priv
->display
.get_pipe_config(intel_crtc
, pipe_config
);
12327 /* hw state is inconsistent with the pipe quirk */
12328 if ((intel_crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
12329 (intel_crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
12330 active
= new_crtc_state
->active
;
12332 I915_STATE_WARN(new_crtc_state
->active
!= active
,
12333 "crtc active state doesn't match with hw state "
12334 "(expected %i, found %i)\n", new_crtc_state
->active
, active
);
12336 I915_STATE_WARN(intel_crtc
->active
!= new_crtc_state
->active
,
12337 "transitional active state does not match atomic hw state "
12338 "(expected %i, found %i)\n", new_crtc_state
->active
, intel_crtc
->active
);
12340 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
12343 active
= encoder
->get_hw_state(encoder
, &pipe
);
12344 I915_STATE_WARN(active
!= new_crtc_state
->active
,
12345 "[ENCODER:%i] active %i with crtc active %i\n",
12346 encoder
->base
.base
.id
, active
, new_crtc_state
->active
);
12348 I915_STATE_WARN(active
&& intel_crtc
->pipe
!= pipe
,
12349 "Encoder connected to wrong pipe %c\n",
12353 encoder
->get_config(encoder
, pipe_config
);
12356 if (!new_crtc_state
->active
)
12359 intel_pipe_config_sanity_check(dev_priv
, pipe_config
);
12361 sw_config
= to_intel_crtc_state(crtc
->state
);
12362 if (!intel_pipe_config_compare(dev
, sw_config
,
12363 pipe_config
, false)) {
12364 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12365 intel_dump_pipe_config(intel_crtc
, pipe_config
,
12367 intel_dump_pipe_config(intel_crtc
, sw_config
,
12373 verify_single_dpll_state(struct drm_i915_private
*dev_priv
,
12374 struct intel_shared_dpll
*pll
,
12375 struct drm_crtc
*crtc
,
12376 struct drm_crtc_state
*new_state
)
12378 struct intel_dpll_hw_state dpll_hw_state
;
12379 unsigned crtc_mask
;
12382 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
12384 DRM_DEBUG_KMS("%s\n", pll
->name
);
12386 active
= pll
->funcs
.get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
12388 if (!(pll
->flags
& INTEL_DPLL_ALWAYS_ON
)) {
12389 I915_STATE_WARN(!pll
->on
&& pll
->active_mask
,
12390 "pll in active use but not on in sw tracking\n");
12391 I915_STATE_WARN(pll
->on
&& !pll
->active_mask
,
12392 "pll is on but not used by any active crtc\n");
12393 I915_STATE_WARN(pll
->on
!= active
,
12394 "pll on state mismatch (expected %i, found %i)\n",
12399 I915_STATE_WARN(pll
->active_mask
& ~pll
->config
.crtc_mask
,
12400 "more active pll users than references: %x vs %x\n",
12401 pll
->active_mask
, pll
->config
.crtc_mask
);
12406 crtc_mask
= 1 << drm_crtc_index(crtc
);
12408 if (new_state
->active
)
12409 I915_STATE_WARN(!(pll
->active_mask
& crtc_mask
),
12410 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
12411 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
12413 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
12414 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
12415 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
12417 I915_STATE_WARN(!(pll
->config
.crtc_mask
& crtc_mask
),
12418 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
12419 crtc_mask
, pll
->config
.crtc_mask
);
12421 I915_STATE_WARN(pll
->on
&& memcmp(&pll
->config
.hw_state
,
12423 sizeof(dpll_hw_state
)),
12424 "pll hw state mismatch\n");
12428 verify_shared_dpll_state(struct drm_device
*dev
, struct drm_crtc
*crtc
,
12429 struct drm_crtc_state
*old_crtc_state
,
12430 struct drm_crtc_state
*new_crtc_state
)
12432 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12433 struct intel_crtc_state
*old_state
= to_intel_crtc_state(old_crtc_state
);
12434 struct intel_crtc_state
*new_state
= to_intel_crtc_state(new_crtc_state
);
12436 if (new_state
->shared_dpll
)
12437 verify_single_dpll_state(dev_priv
, new_state
->shared_dpll
, crtc
, new_crtc_state
);
12439 if (old_state
->shared_dpll
&&
12440 old_state
->shared_dpll
!= new_state
->shared_dpll
) {
12441 unsigned crtc_mask
= 1 << drm_crtc_index(crtc
);
12442 struct intel_shared_dpll
*pll
= old_state
->shared_dpll
;
12444 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
12445 "pll active mismatch (didn't expect pipe %c in active mask)\n",
12446 pipe_name(drm_crtc_index(crtc
)));
12447 I915_STATE_WARN(pll
->config
.crtc_mask
& crtc_mask
,
12448 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
12449 pipe_name(drm_crtc_index(crtc
)));
12454 intel_modeset_verify_crtc(struct drm_crtc
*crtc
,
12455 struct drm_crtc_state
*old_state
,
12456 struct drm_crtc_state
*new_state
)
12458 verify_wm_state(crtc
, new_state
);
12459 verify_crtc_state(crtc
, old_state
, new_state
);
12460 verify_shared_dpll_state(crtc
->dev
, crtc
, old_state
, new_state
);
12464 verify_disabled_dpll_state(struct drm_device
*dev
)
12466 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12469 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++)
12470 verify_single_dpll_state(dev_priv
, &dev_priv
->shared_dplls
[i
], NULL
, NULL
);
12474 intel_modeset_verify_disabled(struct drm_device
*dev
)
12476 verify_encoder_state(dev
);
12477 verify_connector_state(dev
, NULL
);
12478 verify_disabled_dpll_state(dev
);
12481 static void update_scanline_offset(struct intel_crtc
*crtc
)
12483 struct drm_device
*dev
= crtc
->base
.dev
;
12486 * The scanline counter increments at the leading edge of hsync.
12488 * On most platforms it starts counting from vtotal-1 on the
12489 * first active line. That means the scanline counter value is
12490 * always one less than what we would expect. Ie. just after
12491 * start of vblank, which also occurs at start of hsync (on the
12492 * last active line), the scanline counter will read vblank_start-1.
12494 * On gen2 the scanline counter starts counting from 1 instead
12495 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12496 * to keep the value positive), instead of adding one.
12498 * On HSW+ the behaviour of the scanline counter depends on the output
12499 * type. For DP ports it behaves like most other platforms, but on HDMI
12500 * there's an extra 1 line difference. So we need to add two instead of
12501 * one to the value.
12503 if (IS_GEN2(dev
)) {
12504 const struct drm_display_mode
*adjusted_mode
= &crtc
->config
->base
.adjusted_mode
;
12507 vtotal
= adjusted_mode
->crtc_vtotal
;
12508 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
12511 crtc
->scanline_offset
= vtotal
- 1;
12512 } else if (HAS_DDI(dev
) &&
12513 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
)) {
12514 crtc
->scanline_offset
= 2;
12516 crtc
->scanline_offset
= 1;
12519 static void intel_modeset_clear_plls(struct drm_atomic_state
*state
)
12521 struct drm_device
*dev
= state
->dev
;
12522 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12523 struct intel_shared_dpll_config
*shared_dpll
= NULL
;
12524 struct drm_crtc
*crtc
;
12525 struct drm_crtc_state
*crtc_state
;
12528 if (!dev_priv
->display
.crtc_compute_clock
)
12531 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12532 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12533 struct intel_shared_dpll
*old_dpll
=
12534 to_intel_crtc_state(crtc
->state
)->shared_dpll
;
12536 if (!needs_modeset(crtc_state
))
12539 to_intel_crtc_state(crtc_state
)->shared_dpll
= NULL
;
12545 shared_dpll
= intel_atomic_get_shared_dpll_state(state
);
12547 intel_shared_dpll_config_put(shared_dpll
, old_dpll
, intel_crtc
);
12552 * This implements the workaround described in the "notes" section of the mode
12553 * set sequence documentation. When going from no pipes or single pipe to
12554 * multiple pipes, and planes are enabled after the pipe, we need to wait at
12555 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
12557 static int haswell_mode_set_planes_workaround(struct drm_atomic_state
*state
)
12559 struct drm_crtc_state
*crtc_state
;
12560 struct intel_crtc
*intel_crtc
;
12561 struct drm_crtc
*crtc
;
12562 struct intel_crtc_state
*first_crtc_state
= NULL
;
12563 struct intel_crtc_state
*other_crtc_state
= NULL
;
12564 enum pipe first_pipe
= INVALID_PIPE
, enabled_pipe
= INVALID_PIPE
;
12567 /* look at all crtc's that are going to be enabled in during modeset */
12568 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12569 intel_crtc
= to_intel_crtc(crtc
);
12571 if (!crtc_state
->active
|| !needs_modeset(crtc_state
))
12574 if (first_crtc_state
) {
12575 other_crtc_state
= to_intel_crtc_state(crtc_state
);
12578 first_crtc_state
= to_intel_crtc_state(crtc_state
);
12579 first_pipe
= intel_crtc
->pipe
;
12583 /* No workaround needed? */
12584 if (!first_crtc_state
)
12587 /* w/a possibly needed, check how many crtc's are already enabled. */
12588 for_each_intel_crtc(state
->dev
, intel_crtc
) {
12589 struct intel_crtc_state
*pipe_config
;
12591 pipe_config
= intel_atomic_get_crtc_state(state
, intel_crtc
);
12592 if (IS_ERR(pipe_config
))
12593 return PTR_ERR(pipe_config
);
12595 pipe_config
->hsw_workaround_pipe
= INVALID_PIPE
;
12597 if (!pipe_config
->base
.active
||
12598 needs_modeset(&pipe_config
->base
))
12601 /* 2 or more enabled crtcs means no need for w/a */
12602 if (enabled_pipe
!= INVALID_PIPE
)
12605 enabled_pipe
= intel_crtc
->pipe
;
12608 if (enabled_pipe
!= INVALID_PIPE
)
12609 first_crtc_state
->hsw_workaround_pipe
= enabled_pipe
;
12610 else if (other_crtc_state
)
12611 other_crtc_state
->hsw_workaround_pipe
= first_pipe
;
12616 static int intel_modeset_all_pipes(struct drm_atomic_state
*state
)
12618 struct drm_crtc
*crtc
;
12619 struct drm_crtc_state
*crtc_state
;
12622 /* add all active pipes to the state */
12623 for_each_crtc(state
->dev
, crtc
) {
12624 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
12625 if (IS_ERR(crtc_state
))
12626 return PTR_ERR(crtc_state
);
12628 if (!crtc_state
->active
|| needs_modeset(crtc_state
))
12631 crtc_state
->mode_changed
= true;
12633 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
12637 ret
= drm_atomic_add_affected_planes(state
, crtc
);
12645 static int intel_modeset_checks(struct drm_atomic_state
*state
)
12647 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12648 struct drm_i915_private
*dev_priv
= state
->dev
->dev_private
;
12649 struct drm_crtc
*crtc
;
12650 struct drm_crtc_state
*crtc_state
;
12653 if (!check_digital_port_conflicts(state
)) {
12654 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12658 intel_state
->modeset
= true;
12659 intel_state
->active_crtcs
= dev_priv
->active_crtcs
;
12661 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12662 if (crtc_state
->active
)
12663 intel_state
->active_crtcs
|= 1 << i
;
12665 intel_state
->active_crtcs
&= ~(1 << i
);
12667 if (crtc_state
->active
!= crtc
->state
->active
)
12668 intel_state
->active_pipe_changes
|= drm_crtc_mask(crtc
);
12672 * See if the config requires any additional preparation, e.g.
12673 * to adjust global state with pipes off. We need to do this
12674 * here so we can get the modeset_pipe updated config for the new
12675 * mode set on this crtc. For other crtcs we need to use the
12676 * adjusted_mode bits in the crtc directly.
12678 if (dev_priv
->display
.modeset_calc_cdclk
) {
12679 if (!intel_state
->cdclk_pll_vco
)
12680 intel_state
->cdclk_pll_vco
= dev_priv
->skl_vco_freq
;
12681 if (!intel_state
->cdclk_pll_vco
)
12682 intel_state
->cdclk_pll_vco
= dev_priv
->skl_preferred_vco_freq
;
12684 ret
= dev_priv
->display
.modeset_calc_cdclk(state
);
12688 if (intel_state
->dev_cdclk
!= dev_priv
->cdclk_freq
||
12689 intel_state
->cdclk_pll_vco
!= dev_priv
->skl_vco_freq
)
12690 ret
= intel_modeset_all_pipes(state
);
12695 DRM_DEBUG_KMS("New cdclk calculated to be atomic %u, actual %u\n",
12696 intel_state
->cdclk
, intel_state
->dev_cdclk
);
12698 to_intel_atomic_state(state
)->cdclk
= dev_priv
->atomic_cdclk_freq
;
12700 intel_modeset_clear_plls(state
);
12702 if (IS_HASWELL(dev_priv
))
12703 return haswell_mode_set_planes_workaround(state
);
12709 * Handle calculation of various watermark data at the end of the atomic check
12710 * phase. The code here should be run after the per-crtc and per-plane 'check'
12711 * handlers to ensure that all derived state has been updated.
12713 static int calc_watermark_data(struct drm_atomic_state
*state
)
12715 struct drm_device
*dev
= state
->dev
;
12716 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12718 /* Is there platform-specific watermark information to calculate? */
12719 if (dev_priv
->display
.compute_global_watermarks
)
12720 return dev_priv
->display
.compute_global_watermarks(state
);
12726 * intel_atomic_check - validate state object
12728 * @state: state to validate
12730 static int intel_atomic_check(struct drm_device
*dev
,
12731 struct drm_atomic_state
*state
)
12733 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12734 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12735 struct drm_crtc
*crtc
;
12736 struct drm_crtc_state
*crtc_state
;
12738 bool any_ms
= false;
12740 ret
= drm_atomic_helper_check_modeset(dev
, state
);
12744 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12745 struct intel_crtc_state
*pipe_config
=
12746 to_intel_crtc_state(crtc_state
);
12748 /* Catch I915_MODE_FLAG_INHERITED */
12749 if (crtc_state
->mode
.private_flags
!= crtc
->state
->mode
.private_flags
)
12750 crtc_state
->mode_changed
= true;
12752 if (!needs_modeset(crtc_state
))
12755 if (!crtc_state
->enable
) {
12760 /* FIXME: For only active_changed we shouldn't need to do any
12761 * state recomputation at all. */
12763 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
12767 ret
= intel_modeset_pipe_config(crtc
, pipe_config
);
12769 intel_dump_pipe_config(to_intel_crtc(crtc
),
12770 pipe_config
, "[failed]");
12774 if (i915
.fastboot
&&
12775 intel_pipe_config_compare(dev
,
12776 to_intel_crtc_state(crtc
->state
),
12777 pipe_config
, true)) {
12778 crtc_state
->mode_changed
= false;
12779 to_intel_crtc_state(crtc_state
)->update_pipe
= true;
12782 if (needs_modeset(crtc_state
))
12785 ret
= drm_atomic_add_affected_planes(state
, crtc
);
12789 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
12790 needs_modeset(crtc_state
) ?
12791 "[modeset]" : "[fastset]");
12795 ret
= intel_modeset_checks(state
);
12800 intel_state
->cdclk
= dev_priv
->cdclk_freq
;
12802 ret
= drm_atomic_helper_check_planes(dev
, state
);
12806 intel_fbc_choose_crtc(dev_priv
, state
);
12807 return calc_watermark_data(state
);
12810 static bool needs_work(struct drm_crtc_state
*crtc_state
)
12812 /* hw state checker needs to run */
12813 if (needs_modeset(crtc_state
))
12816 /* unpin old fb's, possibly vblank update */
12817 if (crtc_state
->planes_changed
)
12820 /* pipe parameters need to be updated, and hw state checker */
12821 if (to_intel_crtc_state(crtc_state
)->update_pipe
)
12824 /* vblank event requested? */
12825 if (crtc_state
->event
)
12831 static int intel_atomic_prepare_commit(struct drm_device
*dev
,
12832 struct drm_atomic_state
*state
,
12835 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12836 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12837 struct drm_plane_state
*plane_state
;
12838 struct drm_crtc_state
*crtc_state
;
12839 struct drm_plane
*plane
;
12840 struct drm_crtc
*crtc
;
12843 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12844 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12845 struct intel_flip_work
*work
;
12847 if (!state
->legacy_cursor_update
) {
12848 ret
= intel_crtc_wait_for_pending_flips(crtc
);
12852 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
12853 flush_workqueue(dev_priv
->wq
);
12856 /* test if we need to update something */
12857 if (!needs_work(crtc_state
))
12860 intel_state
->work
[i
] = work
=
12861 kzalloc(sizeof(**intel_state
->work
), GFP_KERNEL
);
12866 if (needs_modeset(crtc_state
) ||
12867 to_intel_crtc_state(crtc_state
)->update_pipe
) {
12868 work
->num_old_connectors
= hweight32(crtc
->state
->connector_mask
);
12870 work
->old_connector_state
= kcalloc(work
->num_old_connectors
,
12871 sizeof(*work
->old_connector_state
),
12874 work
->num_new_connectors
= hweight32(crtc_state
->connector_mask
);
12875 work
->new_connector_state
= kcalloc(work
->num_new_connectors
,
12876 sizeof(*work
->new_connector_state
),
12879 if (!work
->old_connector_state
|| !work
->new_connector_state
)
12884 if (intel_state
->modeset
&& nonblock
) {
12885 DRM_DEBUG_ATOMIC("Nonblock modesets are not yet supported!\n");
12889 ret
= mutex_lock_interruptible(&dev
->struct_mutex
);
12893 ret
= drm_atomic_helper_prepare_planes(dev
, state
);
12894 mutex_unlock(&dev
->struct_mutex
);
12896 if (!ret
&& !nonblock
) {
12897 for_each_plane_in_state(state
, plane
, plane_state
, i
) {
12898 struct intel_plane_state
*intel_plane_state
=
12899 to_intel_plane_state(plane_state
);
12901 if (plane_state
->fence
) {
12902 long lret
= fence_wait(plane_state
->fence
, true);
12910 if (!intel_plane_state
->wait_req
)
12913 ret
= __i915_wait_request(intel_plane_state
->wait_req
,
12916 /* Any hang should be swallowed by the wait */
12917 WARN_ON(ret
== -EIO
);
12918 mutex_lock(&dev
->struct_mutex
);
12919 drm_atomic_helper_cleanup_planes(dev
, state
);
12920 mutex_unlock(&dev
->struct_mutex
);
12929 u32
intel_crtc_get_vblank_counter(struct intel_crtc
*crtc
)
12931 struct drm_device
*dev
= crtc
->base
.dev
;
12933 if (!dev
->max_vblank_count
)
12934 return drm_accurate_vblank_count(&crtc
->base
);
12936 return dev
->driver
->get_vblank_counter(dev
, crtc
->pipe
);
12939 static void intel_prepare_work(struct drm_crtc
*crtc
,
12940 struct intel_flip_work
*work
,
12941 struct drm_atomic_state
*state
,
12942 struct drm_crtc_state
*old_crtc_state
)
12944 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12945 struct drm_plane_state
*old_plane_state
;
12946 struct drm_plane
*plane
;
12949 INIT_WORK(&work
->unpin_work
, intel_unpin_work_fn
);
12950 INIT_WORK(&work
->mmio_work
, intel_mmio_flip_work_func
);
12951 atomic_inc(&intel_crtc
->unpin_work_count
);
12953 for_each_plane_in_state(state
, plane
, old_plane_state
, i
) {
12954 struct intel_plane_state
*old_state
= to_intel_plane_state(old_plane_state
);
12955 struct intel_plane_state
*new_state
= to_intel_plane_state(plane
->state
);
12957 if (old_state
->base
.crtc
!= crtc
&&
12958 new_state
->base
.crtc
!= crtc
)
12961 if (plane
->type
== DRM_PLANE_TYPE_PRIMARY
) {
12962 plane
->fb
= new_state
->base
.fb
;
12963 crtc
->x
= new_state
->base
.src_x
>> 16;
12964 crtc
->y
= new_state
->base
.src_y
>> 16;
12967 old_state
->wait_req
= new_state
->wait_req
;
12968 new_state
->wait_req
= NULL
;
12970 old_state
->base
.fence
= new_state
->base
.fence
;
12971 new_state
->base
.fence
= NULL
;
12973 /* remove plane state from the atomic state and move it to work */
12974 old_plane_state
->state
= NULL
;
12975 state
->planes
[i
] = NULL
;
12976 state
->plane_states
[i
] = NULL
;
12978 work
->old_plane_state
[j
] = old_state
;
12979 work
->new_plane_state
[j
++] = new_state
;
12982 old_crtc_state
->state
= NULL
;
12983 state
->crtcs
[drm_crtc_index(crtc
)] = NULL
;
12984 state
->crtc_states
[drm_crtc_index(crtc
)] = NULL
;
12986 work
->old_crtc_state
= to_intel_crtc_state(old_crtc_state
);
12987 work
->new_crtc_state
= to_intel_crtc_state(crtc
->state
);
12988 work
->num_planes
= j
;
12990 work
->event
= crtc
->state
->event
;
12991 crtc
->state
->event
= NULL
;
12993 if (needs_modeset(crtc
->state
) || work
->new_crtc_state
->update_pipe
) {
12994 struct drm_connector
*conn
;
12995 struct drm_connector_state
*old_conn_state
;
13001 * intel_unpin_work_fn cannot depend on the connector list
13002 * because it may be freed from underneath it, so add
13003 * them all to the work struct while we're holding locks.
13005 for_each_connector_in_state(state
, conn
, old_conn_state
, i
) {
13006 if (old_conn_state
->crtc
== crtc
) {
13007 work
->old_connector_state
[j
++] = old_conn_state
;
13009 state
->connectors
[i
] = NULL
;
13010 state
->connector_states
[i
] = NULL
;
13014 /* If another crtc has stolen the connector from state,
13015 * then for_each_connector_in_state is no longer reliable,
13016 * so use drm_for_each_connector here.
13018 drm_for_each_connector(conn
, state
->dev
)
13019 if (conn
->state
->crtc
== crtc
)
13020 work
->new_connector_state
[k
++] = conn
->state
;
13022 WARN(j
!= work
->num_old_connectors
, "j = %i, expected %i\n", j
, work
->num_old_connectors
);
13023 WARN(k
!= work
->num_new_connectors
, "k = %i, expected %i\n", k
, work
->num_new_connectors
);
13024 } else if (!work
->new_crtc_state
->update_wm_post
)
13025 work
->can_async_unpin
= true;
13027 work
->fb_bits
= work
->new_crtc_state
->fb_bits
;
13030 static void intel_schedule_unpin(struct drm_crtc
*crtc
,
13031 struct intel_atomic_state
*state
,
13032 struct intel_flip_work
*work
)
13034 struct drm_device
*dev
= crtc
->dev
;
13035 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13037 to_intel_crtc(crtc
)->config
= work
->new_crtc_state
;
13039 queue_work(dev_priv
->wq
, &work
->unpin_work
);
13042 static void intel_schedule_flip(struct drm_crtc
*crtc
,
13043 struct intel_atomic_state
*state
,
13044 struct intel_flip_work
*work
,
13047 struct intel_crtc_state
*crtc_state
= work
->new_crtc_state
;
13049 if (crtc_state
->base
.planes_changed
||
13050 needs_modeset(&crtc_state
->base
) ||
13051 crtc_state
->update_pipe
) {
13053 schedule_work(&work
->mmio_work
);
13055 intel_mmio_flip_work_func(&work
->mmio_work
);
13059 ret
= drm_crtc_vblank_get(crtc
);
13060 I915_STATE_WARN(ret
< 0, "enabling vblank failed with %i\n", ret
);
13062 work
->flip_queued_vblank
= intel_crtc_get_vblank_counter(to_intel_crtc(crtc
));
13063 smp_mb__before_atomic();
13064 atomic_set(&work
->pending
, 1);
13068 static void intel_schedule_update(struct drm_crtc
*crtc
,
13069 struct intel_atomic_state
*state
,
13070 struct intel_flip_work
*work
,
13073 struct drm_device
*dev
= crtc
->dev
;
13074 struct intel_crtc_state
*pipe_config
= work
->new_crtc_state
;
13076 if (!pipe_config
->base
.active
&& work
->can_async_unpin
) {
13077 INIT_LIST_HEAD(&work
->head
);
13078 intel_schedule_unpin(crtc
, state
, work
);
13082 spin_lock_irq(&dev
->event_lock
);
13083 list_add_tail(&work
->head
, &to_intel_crtc(crtc
)->flip_work
);
13084 spin_unlock_irq(&dev
->event_lock
);
13086 if (!pipe_config
->base
.active
)
13087 intel_schedule_unpin(crtc
, state
, work
);
13089 intel_schedule_flip(crtc
, state
, work
, nonblock
);
13093 * intel_atomic_commit - commit validated state object
13095 * @state: the top-level driver state object
13096 * @nonblock: nonblocking commit
13098 * This function commits a top-level state object that has been validated
13099 * with drm_atomic_helper_check().
13101 * FIXME: Atomic modeset support for i915 is not yet complete. At the moment
13102 * we can only handle plane-related operations and do not yet support
13103 * nonblocking commit.
13106 * Zero for success or -errno.
13108 static int intel_atomic_commit(struct drm_device
*dev
,
13109 struct drm_atomic_state
*state
,
13112 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
13113 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13114 struct drm_crtc_state
*old_crtc_state
;
13115 struct drm_crtc
*crtc
;
13118 ret
= intel_atomic_prepare_commit(dev
, state
, nonblock
);
13120 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret
);
13124 drm_atomic_helper_swap_state(dev
, state
);
13125 dev_priv
->wm
.distrust_bios_wm
= false;
13126 dev_priv
->wm
.skl_results
= intel_state
->wm_results
;
13127 intel_shared_dpll_commit(state
);
13129 if (intel_state
->modeset
) {
13130 memcpy(dev_priv
->min_pixclk
, intel_state
->min_pixclk
,
13131 sizeof(intel_state
->min_pixclk
));
13132 dev_priv
->active_crtcs
= intel_state
->active_crtcs
;
13133 dev_priv
->atomic_cdclk_freq
= intel_state
->cdclk
;
13136 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
13137 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13139 if (!needs_modeset(crtc
->state
))
13142 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
));
13144 intel_state
->work
[i
]->put_power_domains
=
13145 modeset_get_crtc_power_domains(crtc
,
13146 to_intel_crtc_state(crtc
->state
));
13148 if (old_crtc_state
->active
) {
13149 intel_crtc_disable_planes(crtc
, old_crtc_state
->plane_mask
);
13150 dev_priv
->display
.crtc_disable(crtc
);
13151 intel_crtc
->active
= false;
13152 intel_fbc_disable(intel_crtc
);
13153 intel_disable_shared_dpll(intel_crtc
);
13156 * Underruns don't always raise
13157 * interrupts, so check manually.
13159 intel_check_cpu_fifo_underruns(dev_priv
);
13160 intel_check_pch_fifo_underruns(dev_priv
);
13162 if (!crtc
->state
->active
)
13163 intel_update_watermarks(crtc
);
13167 /* Only after disabling all output pipelines that will be changed can we
13168 * update the the output configuration. */
13169 intel_modeset_update_crtc_state(state
);
13171 if (intel_state
->modeset
) {
13172 drm_atomic_helper_update_legacy_modeset_state(state
->dev
, state
);
13174 if (dev_priv
->display
.modeset_commit_cdclk
&&
13175 (intel_state
->dev_cdclk
!= dev_priv
->cdclk_freq
||
13176 intel_state
->cdclk_pll_vco
!= dev_priv
->skl_vco_freq
))
13177 dev_priv
->display
.modeset_commit_cdclk(state
);
13179 intel_modeset_verify_disabled(dev
);
13182 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
13183 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
13184 struct intel_flip_work
*work
= intel_state
->work
[i
];
13185 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13186 bool modeset
= needs_modeset(crtc
->state
);
13188 if (modeset
&& crtc
->state
->active
) {
13189 update_scanline_offset(to_intel_crtc(crtc
));
13190 dev_priv
->display
.crtc_enable(crtc
);
13194 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
));
13197 if (!list_empty_careful(&intel_crtc
->flip_work
)) {
13198 spin_lock_irq(&dev
->event_lock
);
13199 if (!list_empty(&intel_crtc
->flip_work
))
13200 work
= list_last_entry(&intel_crtc
->flip_work
,
13201 struct intel_flip_work
, head
);
13203 if (work
&& work
->new_crtc_state
== to_intel_crtc_state(old_crtc_state
)) {
13204 work
->free_new_crtc_state
= true;
13205 state
->crtc_states
[i
] = NULL
;
13206 state
->crtcs
[i
] = NULL
;
13208 spin_unlock_irq(&dev
->event_lock
);
13213 intel_state
->work
[i
] = NULL
;
13214 intel_prepare_work(crtc
, work
, state
, old_crtc_state
);
13215 intel_schedule_update(crtc
, intel_state
, work
, nonblock
);
13218 /* FIXME: add subpixel order */
13220 drm_atomic_state_free(state
);
13222 /* As one of the primary mmio accessors, KMS has a high likelihood
13223 * of triggering bugs in unclaimed access. After we finish
13224 * modesetting, see if an error has been flagged, and if so
13225 * enable debugging for the next modeset - and hope we catch
13228 * XXX note that we assume display power is on at this point.
13229 * This might hold true now but we need to add pm helper to check
13230 * unclaimed only when the hardware is on, as atomic commits
13231 * can happen also when the device is completely off.
13233 intel_uncore_arm_unclaimed_mmio_detection(dev_priv
);
13238 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
13240 struct drm_device
*dev
= crtc
->dev
;
13241 struct drm_atomic_state
*state
;
13242 struct drm_crtc_state
*crtc_state
;
13245 state
= drm_atomic_state_alloc(dev
);
13247 DRM_DEBUG_KMS("[CRTC:%d] crtc restore failed, out of memory",
13252 state
->acquire_ctx
= drm_modeset_legacy_acquire_ctx(crtc
);
13255 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
13256 ret
= PTR_ERR_OR_ZERO(crtc_state
);
13258 if (!crtc_state
->active
)
13261 crtc_state
->mode_changed
= true;
13262 ret
= drm_atomic_commit(state
);
13265 if (ret
== -EDEADLK
) {
13266 drm_atomic_state_clear(state
);
13267 drm_modeset_backoff(state
->acquire_ctx
);
13273 drm_atomic_state_free(state
);
13276 #undef for_each_intel_crtc_masked
13278 static const struct drm_crtc_funcs intel_crtc_funcs
= {
13279 .gamma_set
= drm_atomic_helper_legacy_gamma_set
,
13280 .set_config
= drm_atomic_helper_set_config
,
13281 .set_property
= drm_atomic_helper_crtc_set_property
,
13282 .destroy
= intel_crtc_destroy
,
13283 .page_flip
= drm_atomic_helper_page_flip
,
13284 .atomic_duplicate_state
= intel_crtc_duplicate_state
,
13285 .atomic_destroy_state
= intel_crtc_destroy_state
,
13288 static struct fence
*intel_get_excl_fence(struct drm_i915_gem_object
*obj
)
13290 struct reservation_object
*resv
;
13293 if (!obj
->base
.dma_buf
)
13296 resv
= obj
->base
.dma_buf
->resv
;
13298 /* For framebuffer backed by dmabuf, wait for fence */
13300 struct fence
*fence_excl
, *ret
= NULL
;
13304 fence_excl
= rcu_dereference(resv
->fence_excl
);
13306 ret
= fence_get_rcu(fence_excl
);
13310 if (ret
== fence_excl
)
13316 * intel_prepare_plane_fb - Prepare fb for usage on plane
13317 * @plane: drm plane to prepare for
13318 * @fb: framebuffer to prepare for presentation
13320 * Prepares a framebuffer for usage on a display plane. Generally this
13321 * involves pinning the underlying object and updating the frontbuffer tracking
13322 * bits. Some older platforms need special physical address handling for
13325 * Must be called with struct_mutex held.
13327 * Returns 0 on success, negative error code on failure.
13330 intel_prepare_plane_fb(struct drm_plane
*plane
,
13331 const struct drm_plane_state
*new_state
)
13333 struct drm_device
*dev
= plane
->dev
;
13334 struct drm_framebuffer
*fb
= new_state
->fb
;
13335 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
13336 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13337 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->state
->fb
);
13338 struct drm_crtc
*crtc
= new_state
->crtc
?: plane
->state
->crtc
;
13341 if (!obj
&& !old_obj
)
13344 if (WARN_ON(!new_state
->state
) || WARN_ON(!crtc
) ||
13345 WARN_ON(!to_intel_atomic_state(new_state
->state
)->work
[to_intel_crtc(crtc
)->pipe
])) {
13346 if (WARN_ON(old_obj
!= obj
))
13353 struct drm_crtc_state
*crtc_state
=
13354 drm_atomic_get_existing_crtc_state(new_state
->state
, plane
->state
->crtc
);
13356 /* Big Hammer, we also need to ensure that any pending
13357 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
13358 * current scanout is retired before unpinning the old
13359 * framebuffer. Note that we rely on userspace rendering
13360 * into the buffer attached to the pipe they are waiting
13361 * on. If not, userspace generates a GPU hang with IPEHR
13362 * point to the MI_WAIT_FOR_EVENT.
13364 * This should only fail upon a hung GPU, in which case we
13365 * can safely continue.
13367 if (needs_modeset(crtc_state
))
13368 ret
= i915_gem_object_wait_rendering(old_obj
, true);
13370 /* GPU hangs should have been swallowed by the wait */
13371 WARN_ON(ret
== -EIO
);
13378 } else if (plane
->type
== DRM_PLANE_TYPE_CURSOR
&&
13379 INTEL_INFO(dev
)->cursor_needs_physical
) {
13380 int align
= IS_I830(dev
) ? 16 * 1024 : 256;
13381 ret
= i915_gem_object_attach_phys(obj
, align
);
13383 DRM_DEBUG_KMS("failed to attach phys object\n");
13385 ret
= intel_pin_and_fence_fb_obj(fb
, new_state
->rotation
);
13390 struct intel_plane_state
*plane_state
=
13391 to_intel_plane_state(new_state
);
13393 i915_gem_request_assign(&plane_state
->wait_req
,
13394 obj
->last_write_req
);
13396 plane_state
->base
.fence
= intel_get_excl_fence(obj
);
13399 i915_gem_track_fb(old_obj
, obj
, intel_plane
->frontbuffer_bit
);
13406 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13407 * @plane: drm plane to clean up for
13408 * @fb: old framebuffer that was on plane
13410 * Cleans up a framebuffer that has just been removed from a plane.
13412 * Must be called with struct_mutex held.
13415 intel_cleanup_plane_fb(struct drm_plane
*plane
,
13416 const struct drm_plane_state
*old_state
)
13418 struct drm_device
*dev
= plane
->dev
;
13419 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
13420 struct intel_plane_state
*old_intel_state
;
13421 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(old_state
->fb
);
13422 struct drm_i915_gem_object
*obj
= intel_fb_obj(plane
->state
->fb
);
13424 old_intel_state
= to_intel_plane_state(old_state
);
13426 if (!obj
&& !old_obj
)
13429 if (old_obj
&& (plane
->type
!= DRM_PLANE_TYPE_CURSOR
||
13430 !INTEL_INFO(dev
)->cursor_needs_physical
))
13431 intel_unpin_fb_obj(old_state
->fb
, old_state
->rotation
);
13433 /* prepare_fb aborted? */
13434 if ((old_obj
&& (old_obj
->frontbuffer_bits
& intel_plane
->frontbuffer_bit
)) ||
13435 (obj
&& !(obj
->frontbuffer_bits
& intel_plane
->frontbuffer_bit
)))
13436 i915_gem_track_fb(old_obj
, obj
, intel_plane
->frontbuffer_bit
);
13438 i915_gem_request_assign(&old_intel_state
->wait_req
, NULL
);
13440 fence_put(old_intel_state
->base
.fence
);
13441 old_intel_state
->base
.fence
= NULL
;
13445 skl_max_scale(struct intel_crtc
*intel_crtc
, struct intel_crtc_state
*crtc_state
)
13448 struct drm_device
*dev
;
13449 struct drm_i915_private
*dev_priv
;
13450 int crtc_clock
, cdclk
;
13452 if (!intel_crtc
|| !crtc_state
->base
.enable
)
13453 return DRM_PLANE_HELPER_NO_SCALING
;
13455 dev
= intel_crtc
->base
.dev
;
13456 dev_priv
= dev
->dev_private
;
13457 crtc_clock
= crtc_state
->base
.adjusted_mode
.crtc_clock
;
13458 cdclk
= to_intel_atomic_state(crtc_state
->base
.state
)->cdclk
;
13460 if (WARN_ON_ONCE(!crtc_clock
|| cdclk
< crtc_clock
))
13461 return DRM_PLANE_HELPER_NO_SCALING
;
13464 * skl max scale is lower of:
13465 * close to 3 but not 3, -1 is for that purpose
13469 max_scale
= min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk
<< 8) / crtc_clock
));
13475 intel_check_primary_plane(struct drm_plane
*plane
,
13476 struct intel_crtc_state
*crtc_state
,
13477 struct intel_plane_state
*state
)
13479 struct drm_crtc
*crtc
= state
->base
.crtc
;
13480 struct drm_framebuffer
*fb
= state
->base
.fb
;
13481 int min_scale
= DRM_PLANE_HELPER_NO_SCALING
;
13482 int max_scale
= DRM_PLANE_HELPER_NO_SCALING
;
13483 bool can_position
= false;
13485 if (INTEL_INFO(plane
->dev
)->gen
>= 9) {
13486 /* use scaler when colorkey is not required */
13487 if (state
->ckey
.flags
== I915_SET_COLORKEY_NONE
) {
13489 max_scale
= skl_max_scale(to_intel_crtc(crtc
), crtc_state
);
13491 can_position
= true;
13494 return drm_plane_helper_check_update(plane
, crtc
, fb
, &state
->src
,
13495 &state
->dst
, &state
->clip
,
13496 min_scale
, max_scale
,
13497 can_position
, true,
13502 * intel_plane_destroy - destroy a plane
13503 * @plane: plane to destroy
13505 * Common destruction function for all types of planes (primary, cursor,
13508 void intel_plane_destroy(struct drm_plane
*plane
)
13510 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
13511 drm_plane_cleanup(plane
);
13512 kfree(intel_plane
);
13515 const struct drm_plane_funcs intel_plane_funcs
= {
13516 .update_plane
= drm_atomic_helper_update_plane
,
13517 .disable_plane
= drm_atomic_helper_disable_plane
,
13518 .destroy
= intel_plane_destroy
,
13519 .set_property
= drm_atomic_helper_plane_set_property
,
13520 .atomic_get_property
= intel_plane_atomic_get_property
,
13521 .atomic_set_property
= intel_plane_atomic_set_property
,
13522 .atomic_duplicate_state
= intel_plane_duplicate_state
,
13523 .atomic_destroy_state
= intel_plane_destroy_state
,
13527 static struct drm_plane
*intel_primary_plane_create(struct drm_device
*dev
,
13530 struct intel_plane
*primary
= NULL
;
13531 struct intel_plane_state
*state
= NULL
;
13532 const uint32_t *intel_primary_formats
;
13533 unsigned int num_formats
;
13536 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
13540 state
= intel_create_plane_state(&primary
->base
);
13543 primary
->base
.state
= &state
->base
;
13545 primary
->can_scale
= false;
13546 primary
->max_downscale
= 1;
13547 if (INTEL_INFO(dev
)->gen
>= 9) {
13548 primary
->can_scale
= true;
13549 state
->scaler_id
= -1;
13551 primary
->pipe
= pipe
;
13552 primary
->plane
= pipe
;
13553 primary
->frontbuffer_bit
= INTEL_FRONTBUFFER_PRIMARY(pipe
);
13554 primary
->check_plane
= intel_check_primary_plane
;
13555 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4)
13556 primary
->plane
= !pipe
;
13558 if (INTEL_INFO(dev
)->gen
>= 9) {
13559 intel_primary_formats
= skl_primary_formats
;
13560 num_formats
= ARRAY_SIZE(skl_primary_formats
);
13562 primary
->update_plane
= skylake_update_primary_plane
;
13563 primary
->disable_plane
= skylake_disable_primary_plane
;
13564 } else if (HAS_PCH_SPLIT(dev
)) {
13565 intel_primary_formats
= i965_primary_formats
;
13566 num_formats
= ARRAY_SIZE(i965_primary_formats
);
13568 primary
->update_plane
= ironlake_update_primary_plane
;
13569 primary
->disable_plane
= i9xx_disable_primary_plane
;
13570 } else if (INTEL_INFO(dev
)->gen
>= 4) {
13571 intel_primary_formats
= i965_primary_formats
;
13572 num_formats
= ARRAY_SIZE(i965_primary_formats
);
13574 primary
->update_plane
= i9xx_update_primary_plane
;
13575 primary
->disable_plane
= i9xx_disable_primary_plane
;
13577 intel_primary_formats
= i8xx_primary_formats
;
13578 num_formats
= ARRAY_SIZE(i8xx_primary_formats
);
13580 primary
->update_plane
= i9xx_update_primary_plane
;
13581 primary
->disable_plane
= i9xx_disable_primary_plane
;
13584 ret
= drm_universal_plane_init(dev
, &primary
->base
, 0,
13585 &intel_plane_funcs
,
13586 intel_primary_formats
, num_formats
,
13587 DRM_PLANE_TYPE_PRIMARY
, NULL
);
13591 if (INTEL_INFO(dev
)->gen
>= 4)
13592 intel_create_rotation_property(dev
, primary
);
13594 drm_plane_helper_add(&primary
->base
, &intel_plane_helper_funcs
);
13596 return &primary
->base
;
13605 void intel_create_rotation_property(struct drm_device
*dev
, struct intel_plane
*plane
)
13607 if (!dev
->mode_config
.rotation_property
) {
13608 unsigned long flags
= BIT(DRM_ROTATE_0
) |
13609 BIT(DRM_ROTATE_180
);
13611 if (INTEL_INFO(dev
)->gen
>= 9)
13612 flags
|= BIT(DRM_ROTATE_90
) | BIT(DRM_ROTATE_270
);
13614 dev
->mode_config
.rotation_property
=
13615 drm_mode_create_rotation_property(dev
, flags
);
13617 if (dev
->mode_config
.rotation_property
)
13618 drm_object_attach_property(&plane
->base
.base
,
13619 dev
->mode_config
.rotation_property
,
13620 plane
->base
.state
->rotation
);
13624 intel_check_cursor_plane(struct drm_plane
*plane
,
13625 struct intel_crtc_state
*crtc_state
,
13626 struct intel_plane_state
*state
)
13628 struct drm_crtc
*crtc
= crtc_state
->base
.crtc
;
13629 struct drm_framebuffer
*fb
= state
->base
.fb
;
13630 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13631 enum pipe pipe
= to_intel_plane(plane
)->pipe
;
13635 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
, &state
->src
,
13636 &state
->dst
, &state
->clip
,
13637 DRM_PLANE_HELPER_NO_SCALING
,
13638 DRM_PLANE_HELPER_NO_SCALING
,
13639 true, true, &state
->visible
);
13643 /* if we want to turn off the cursor ignore width and height */
13647 /* Check for which cursor types we support */
13648 if (!cursor_size_ok(plane
->dev
, state
->base
.crtc_w
, state
->base
.crtc_h
)) {
13649 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
13650 state
->base
.crtc_w
, state
->base
.crtc_h
);
13654 stride
= roundup_pow_of_two(state
->base
.crtc_w
) * 4;
13655 if (obj
->base
.size
< stride
* state
->base
.crtc_h
) {
13656 DRM_DEBUG_KMS("buffer is too small\n");
13660 if (fb
->modifier
[0] != DRM_FORMAT_MOD_NONE
) {
13661 DRM_DEBUG_KMS("cursor cannot be tiled\n");
13666 * There's something wrong with the cursor on CHV pipe C.
13667 * If it straddles the left edge of the screen then
13668 * moving it away from the edge or disabling it often
13669 * results in a pipe underrun, and often that can lead to
13670 * dead pipe (constant underrun reported, and it scans
13671 * out just a solid color). To recover from that, the
13672 * display power well must be turned off and on again.
13673 * Refuse the put the cursor into that compromised position.
13675 if (IS_CHERRYVIEW(plane
->dev
) && pipe
== PIPE_C
&&
13676 state
->visible
&& state
->base
.crtc_x
< 0) {
13677 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
13685 intel_disable_cursor_plane(struct drm_plane
*plane
,
13686 struct drm_crtc
*crtc
)
13688 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13690 intel_crtc
->cursor_addr
= 0;
13691 intel_crtc_update_cursor(crtc
, NULL
);
13695 intel_update_cursor_plane(struct drm_plane
*plane
,
13696 const struct intel_crtc_state
*crtc_state
,
13697 const struct intel_plane_state
*state
)
13699 struct drm_crtc
*crtc
= crtc_state
->base
.crtc
;
13700 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13701 struct drm_device
*dev
= plane
->dev
;
13702 struct drm_i915_gem_object
*obj
= intel_fb_obj(state
->base
.fb
);
13707 else if (!INTEL_INFO(dev
)->cursor_needs_physical
)
13708 addr
= i915_gem_obj_ggtt_offset(obj
);
13710 addr
= obj
->phys_handle
->busaddr
;
13712 intel_crtc
->cursor_addr
= addr
;
13713 intel_crtc_update_cursor(crtc
, state
);
13716 static struct drm_plane
*intel_cursor_plane_create(struct drm_device
*dev
,
13719 struct intel_plane
*cursor
= NULL
;
13720 struct intel_plane_state
*state
= NULL
;
13723 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
13727 state
= intel_create_plane_state(&cursor
->base
);
13730 cursor
->base
.state
= &state
->base
;
13732 cursor
->can_scale
= false;
13733 cursor
->max_downscale
= 1;
13734 cursor
->pipe
= pipe
;
13735 cursor
->plane
= pipe
;
13736 cursor
->frontbuffer_bit
= INTEL_FRONTBUFFER_CURSOR(pipe
);
13737 cursor
->check_plane
= intel_check_cursor_plane
;
13738 cursor
->update_plane
= intel_update_cursor_plane
;
13739 cursor
->disable_plane
= intel_disable_cursor_plane
;
13741 ret
= drm_universal_plane_init(dev
, &cursor
->base
, 0,
13742 &intel_plane_funcs
,
13743 intel_cursor_formats
,
13744 ARRAY_SIZE(intel_cursor_formats
),
13745 DRM_PLANE_TYPE_CURSOR
, NULL
);
13749 if (INTEL_INFO(dev
)->gen
>= 4) {
13750 if (!dev
->mode_config
.rotation_property
)
13751 dev
->mode_config
.rotation_property
=
13752 drm_mode_create_rotation_property(dev
,
13753 BIT(DRM_ROTATE_0
) |
13754 BIT(DRM_ROTATE_180
));
13755 if (dev
->mode_config
.rotation_property
)
13756 drm_object_attach_property(&cursor
->base
.base
,
13757 dev
->mode_config
.rotation_property
,
13758 state
->base
.rotation
);
13761 if (INTEL_INFO(dev
)->gen
>=9)
13762 state
->scaler_id
= -1;
13764 drm_plane_helper_add(&cursor
->base
, &intel_plane_helper_funcs
);
13766 return &cursor
->base
;
13775 static void skl_init_scalers(struct drm_device
*dev
, struct intel_crtc
*intel_crtc
,
13776 struct intel_crtc_state
*crtc_state
)
13779 struct intel_scaler
*intel_scaler
;
13780 struct intel_crtc_scaler_state
*scaler_state
= &crtc_state
->scaler_state
;
13782 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
13783 intel_scaler
= &scaler_state
->scalers
[i
];
13784 intel_scaler
->in_use
= 0;
13785 intel_scaler
->mode
= PS_SCALER_MODE_DYN
;
13788 scaler_state
->scaler_id
= -1;
13791 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
13793 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13794 struct intel_crtc
*intel_crtc
;
13795 struct intel_crtc_state
*crtc_state
= NULL
;
13796 struct drm_plane
*primary
= NULL
;
13797 struct drm_plane
*cursor
= NULL
;
13800 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
13801 if (intel_crtc
== NULL
)
13804 crtc_state
= kzalloc(sizeof(*crtc_state
), GFP_KERNEL
);
13807 intel_crtc
->config
= crtc_state
;
13808 intel_crtc
->base
.state
= &crtc_state
->base
;
13809 crtc_state
->base
.crtc
= &intel_crtc
->base
;
13811 INIT_LIST_HEAD(&intel_crtc
->flip_work
);
13813 /* initialize shared scalers */
13814 if (INTEL_INFO(dev
)->gen
>= 9) {
13815 if (pipe
== PIPE_C
)
13816 intel_crtc
->num_scalers
= 1;
13818 intel_crtc
->num_scalers
= SKL_NUM_SCALERS
;
13820 skl_init_scalers(dev
, intel_crtc
, crtc_state
);
13823 primary
= intel_primary_plane_create(dev
, pipe
);
13827 cursor
= intel_cursor_plane_create(dev
, pipe
);
13831 ret
= drm_crtc_init_with_planes(dev
, &intel_crtc
->base
, primary
,
13832 cursor
, &intel_crtc_funcs
, NULL
);
13837 * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
13838 * is hooked to pipe B. Hence we want plane A feeding pipe B.
13840 intel_crtc
->pipe
= pipe
;
13841 intel_crtc
->plane
= pipe
;
13842 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4) {
13843 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
13844 intel_crtc
->plane
= !pipe
;
13847 intel_crtc
->cursor_base
= ~0;
13848 intel_crtc
->cursor_cntl
= ~0;
13849 intel_crtc
->cursor_size
= ~0;
13851 intel_crtc
->wm
.cxsr_allowed
= true;
13853 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
13854 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
13855 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
13856 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
13858 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
13860 intel_color_init(&intel_crtc
->base
);
13862 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
13867 drm_plane_cleanup(primary
);
13869 drm_plane_cleanup(cursor
);
13874 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
13876 struct drm_encoder
*encoder
= connector
->base
.encoder
;
13877 struct drm_device
*dev
= connector
->base
.dev
;
13879 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
13881 if (!encoder
|| WARN_ON(!encoder
->crtc
))
13882 return INVALID_PIPE
;
13884 return to_intel_crtc(encoder
->crtc
)->pipe
;
13887 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
13888 struct drm_file
*file
)
13890 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
13891 struct drm_crtc
*drmmode_crtc
;
13892 struct intel_crtc
*crtc
;
13894 drmmode_crtc
= drm_crtc_find(dev
, pipe_from_crtc_id
->crtc_id
);
13896 if (!drmmode_crtc
) {
13897 DRM_ERROR("no such CRTC id\n");
13901 crtc
= to_intel_crtc(drmmode_crtc
);
13902 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
13907 static int intel_encoder_clones(struct intel_encoder
*encoder
)
13909 struct drm_device
*dev
= encoder
->base
.dev
;
13910 struct intel_encoder
*source_encoder
;
13911 int index_mask
= 0;
13914 for_each_intel_encoder(dev
, source_encoder
) {
13915 if (encoders_cloneable(encoder
, source_encoder
))
13916 index_mask
|= (1 << entry
);
13924 static bool has_edp_a(struct drm_device
*dev
)
13926 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13928 if (!IS_MOBILE(dev
))
13931 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
13934 if (IS_GEN5(dev
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
13940 static bool intel_crt_present(struct drm_device
*dev
)
13942 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13944 if (INTEL_INFO(dev
)->gen
>= 9)
13947 if (IS_HSW_ULT(dev
) || IS_BDW_ULT(dev
))
13950 if (IS_CHERRYVIEW(dev
))
13953 if (HAS_PCH_LPT_H(dev
) && I915_READ(SFUSE_STRAP
) & SFUSE_STRAP_CRT_DISABLED
)
13956 /* DDI E can't be used if DDI A requires 4 lanes */
13957 if (HAS_DDI(dev
) && I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_A_4_LANES
)
13960 if (!dev_priv
->vbt
.int_crt_support
)
13966 static void intel_setup_outputs(struct drm_device
*dev
)
13968 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13969 struct intel_encoder
*encoder
;
13970 bool dpd_is_edp
= false;
13972 intel_lvds_init(dev
);
13974 if (intel_crt_present(dev
))
13975 intel_crt_init(dev
);
13977 if (IS_BROXTON(dev
)) {
13979 * FIXME: Broxton doesn't support port detection via the
13980 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
13981 * detect the ports.
13983 intel_ddi_init(dev
, PORT_A
);
13984 intel_ddi_init(dev
, PORT_B
);
13985 intel_ddi_init(dev
, PORT_C
);
13987 intel_dsi_init(dev
);
13988 } else if (HAS_DDI(dev
)) {
13992 * Haswell uses DDI functions to detect digital outputs.
13993 * On SKL pre-D0 the strap isn't connected, so we assume
13996 found
= I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_INIT_DISPLAY_DETECTED
;
13997 /* WaIgnoreDDIAStrap: skl */
13998 if (found
|| IS_SKYLAKE(dev
) || IS_KABYLAKE(dev
))
13999 intel_ddi_init(dev
, PORT_A
);
14001 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
14003 found
= I915_READ(SFUSE_STRAP
);
14005 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
14006 intel_ddi_init(dev
, PORT_B
);
14007 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
14008 intel_ddi_init(dev
, PORT_C
);
14009 if (found
& SFUSE_STRAP_DDID_DETECTED
)
14010 intel_ddi_init(dev
, PORT_D
);
14012 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14014 if ((IS_SKYLAKE(dev
) || IS_KABYLAKE(dev
)) &&
14015 (dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dp
||
14016 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dvi
||
14017 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_hdmi
))
14018 intel_ddi_init(dev
, PORT_E
);
14020 } else if (HAS_PCH_SPLIT(dev
)) {
14022 dpd_is_edp
= intel_dp_is_edp(dev
, PORT_D
);
14024 if (has_edp_a(dev
))
14025 intel_dp_init(dev
, DP_A
, PORT_A
);
14027 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
14028 /* PCH SDVOB multiplex with HDMIB */
14029 found
= intel_sdvo_init(dev
, PCH_SDVOB
, PORT_B
);
14031 intel_hdmi_init(dev
, PCH_HDMIB
, PORT_B
);
14032 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
14033 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
14036 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
14037 intel_hdmi_init(dev
, PCH_HDMIC
, PORT_C
);
14039 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
14040 intel_hdmi_init(dev
, PCH_HDMID
, PORT_D
);
14042 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
14043 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
14045 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
14046 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
14047 } else if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
14049 * The DP_DETECTED bit is the latched state of the DDC
14050 * SDA pin at boot. However since eDP doesn't require DDC
14051 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14052 * eDP ports may have been muxed to an alternate function.
14053 * Thus we can't rely on the DP_DETECTED bit alone to detect
14054 * eDP ports. Consult the VBT as well as DP_DETECTED to
14055 * detect eDP ports.
14057 if (I915_READ(VLV_HDMIB
) & SDVO_DETECTED
&&
14058 !intel_dp_is_edp(dev
, PORT_B
))
14059 intel_hdmi_init(dev
, VLV_HDMIB
, PORT_B
);
14060 if (I915_READ(VLV_DP_B
) & DP_DETECTED
||
14061 intel_dp_is_edp(dev
, PORT_B
))
14062 intel_dp_init(dev
, VLV_DP_B
, PORT_B
);
14064 if (I915_READ(VLV_HDMIC
) & SDVO_DETECTED
&&
14065 !intel_dp_is_edp(dev
, PORT_C
))
14066 intel_hdmi_init(dev
, VLV_HDMIC
, PORT_C
);
14067 if (I915_READ(VLV_DP_C
) & DP_DETECTED
||
14068 intel_dp_is_edp(dev
, PORT_C
))
14069 intel_dp_init(dev
, VLV_DP_C
, PORT_C
);
14071 if (IS_CHERRYVIEW(dev
)) {
14072 /* eDP not supported on port D, so don't check VBT */
14073 if (I915_READ(CHV_HDMID
) & SDVO_DETECTED
)
14074 intel_hdmi_init(dev
, CHV_HDMID
, PORT_D
);
14075 if (I915_READ(CHV_DP_D
) & DP_DETECTED
)
14076 intel_dp_init(dev
, CHV_DP_D
, PORT_D
);
14079 intel_dsi_init(dev
);
14080 } else if (!IS_GEN2(dev
) && !IS_PINEVIEW(dev
)) {
14081 bool found
= false;
14083 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
14084 DRM_DEBUG_KMS("probing SDVOB\n");
14085 found
= intel_sdvo_init(dev
, GEN3_SDVOB
, PORT_B
);
14086 if (!found
&& IS_G4X(dev
)) {
14087 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
14088 intel_hdmi_init(dev
, GEN4_HDMIB
, PORT_B
);
14091 if (!found
&& IS_G4X(dev
))
14092 intel_dp_init(dev
, DP_B
, PORT_B
);
14095 /* Before G4X SDVOC doesn't have its own detect register */
14097 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
14098 DRM_DEBUG_KMS("probing SDVOC\n");
14099 found
= intel_sdvo_init(dev
, GEN3_SDVOC
, PORT_C
);
14102 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
14105 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
14106 intel_hdmi_init(dev
, GEN4_HDMIC
, PORT_C
);
14109 intel_dp_init(dev
, DP_C
, PORT_C
);
14113 (I915_READ(DP_D
) & DP_DETECTED
))
14114 intel_dp_init(dev
, DP_D
, PORT_D
);
14115 } else if (IS_GEN2(dev
))
14116 intel_dvo_init(dev
);
14118 if (SUPPORTS_TV(dev
))
14119 intel_tv_init(dev
);
14121 intel_psr_init(dev
);
14123 for_each_intel_encoder(dev
, encoder
) {
14124 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
14125 encoder
->base
.possible_clones
=
14126 intel_encoder_clones(encoder
);
14129 intel_init_pch_refclk(dev
);
14131 drm_helper_move_panel_connectors_to_head(dev
);
14134 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
14136 struct drm_device
*dev
= fb
->dev
;
14137 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
14139 drm_framebuffer_cleanup(fb
);
14140 mutex_lock(&dev
->struct_mutex
);
14141 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
14142 drm_gem_object_unreference(&intel_fb
->obj
->base
);
14143 mutex_unlock(&dev
->struct_mutex
);
14147 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
14148 struct drm_file
*file
,
14149 unsigned int *handle
)
14151 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
14152 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
14154 if (obj
->userptr
.mm
) {
14155 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14159 return drm_gem_handle_create(file
, &obj
->base
, handle
);
14162 static int intel_user_framebuffer_dirty(struct drm_framebuffer
*fb
,
14163 struct drm_file
*file
,
14164 unsigned flags
, unsigned color
,
14165 struct drm_clip_rect
*clips
,
14166 unsigned num_clips
)
14168 struct drm_device
*dev
= fb
->dev
;
14169 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
14170 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
14172 mutex_lock(&dev
->struct_mutex
);
14173 intel_fb_obj_flush(obj
, false, ORIGIN_DIRTYFB
);
14174 mutex_unlock(&dev
->struct_mutex
);
14179 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
14180 .destroy
= intel_user_framebuffer_destroy
,
14181 .create_handle
= intel_user_framebuffer_create_handle
,
14182 .dirty
= intel_user_framebuffer_dirty
,
14186 u32
intel_fb_pitch_limit(struct drm_device
*dev
, uint64_t fb_modifier
,
14187 uint32_t pixel_format
)
14189 u32 gen
= INTEL_INFO(dev
)->gen
;
14192 int cpp
= drm_format_plane_cpp(pixel_format
, 0);
14194 /* "The stride in bytes must not exceed the of the size of 8K
14195 * pixels and 32K bytes."
14197 return min(8192 * cpp
, 32768);
14198 } else if (gen
>= 5 && !IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
)) {
14200 } else if (gen
>= 4) {
14201 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
14205 } else if (gen
>= 3) {
14206 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
14211 /* XXX DSPC is limited to 4k tiled */
14216 static int intel_framebuffer_init(struct drm_device
*dev
,
14217 struct intel_framebuffer
*intel_fb
,
14218 struct drm_mode_fb_cmd2
*mode_cmd
,
14219 struct drm_i915_gem_object
*obj
)
14221 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14222 unsigned int aligned_height
;
14224 u32 pitch_limit
, stride_alignment
;
14226 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
14228 if (mode_cmd
->flags
& DRM_MODE_FB_MODIFIERS
) {
14229 /* Enforce that fb modifier and tiling mode match, but only for
14230 * X-tiled. This is needed for FBC. */
14231 if (!!(obj
->tiling_mode
== I915_TILING_X
) !=
14232 !!(mode_cmd
->modifier
[0] == I915_FORMAT_MOD_X_TILED
)) {
14233 DRM_DEBUG("tiling_mode doesn't match fb modifier\n");
14237 if (obj
->tiling_mode
== I915_TILING_X
)
14238 mode_cmd
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
14239 else if (obj
->tiling_mode
== I915_TILING_Y
) {
14240 DRM_DEBUG("No Y tiling for legacy addfb\n");
14245 /* Passed in modifier sanity checking. */
14246 switch (mode_cmd
->modifier
[0]) {
14247 case I915_FORMAT_MOD_Y_TILED
:
14248 case I915_FORMAT_MOD_Yf_TILED
:
14249 if (INTEL_INFO(dev
)->gen
< 9) {
14250 DRM_DEBUG("Unsupported tiling 0x%llx!\n",
14251 mode_cmd
->modifier
[0]);
14254 case DRM_FORMAT_MOD_NONE
:
14255 case I915_FORMAT_MOD_X_TILED
:
14258 DRM_DEBUG("Unsupported fb modifier 0x%llx!\n",
14259 mode_cmd
->modifier
[0]);
14263 stride_alignment
= intel_fb_stride_alignment(dev_priv
,
14264 mode_cmd
->modifier
[0],
14265 mode_cmd
->pixel_format
);
14266 if (mode_cmd
->pitches
[0] & (stride_alignment
- 1)) {
14267 DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n",
14268 mode_cmd
->pitches
[0], stride_alignment
);
14272 pitch_limit
= intel_fb_pitch_limit(dev
, mode_cmd
->modifier
[0],
14273 mode_cmd
->pixel_format
);
14274 if (mode_cmd
->pitches
[0] > pitch_limit
) {
14275 DRM_DEBUG("%s pitch (%u) must be at less than %d\n",
14276 mode_cmd
->modifier
[0] != DRM_FORMAT_MOD_NONE
?
14277 "tiled" : "linear",
14278 mode_cmd
->pitches
[0], pitch_limit
);
14282 if (mode_cmd
->modifier
[0] == I915_FORMAT_MOD_X_TILED
&&
14283 mode_cmd
->pitches
[0] != obj
->stride
) {
14284 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
14285 mode_cmd
->pitches
[0], obj
->stride
);
14289 /* Reject formats not supported by any plane early. */
14290 switch (mode_cmd
->pixel_format
) {
14291 case DRM_FORMAT_C8
:
14292 case DRM_FORMAT_RGB565
:
14293 case DRM_FORMAT_XRGB8888
:
14294 case DRM_FORMAT_ARGB8888
:
14296 case DRM_FORMAT_XRGB1555
:
14297 if (INTEL_INFO(dev
)->gen
> 3) {
14298 DRM_DEBUG("unsupported pixel format: %s\n",
14299 drm_get_format_name(mode_cmd
->pixel_format
));
14303 case DRM_FORMAT_ABGR8888
:
14304 if (!IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
) &&
14305 INTEL_INFO(dev
)->gen
< 9) {
14306 DRM_DEBUG("unsupported pixel format: %s\n",
14307 drm_get_format_name(mode_cmd
->pixel_format
));
14311 case DRM_FORMAT_XBGR8888
:
14312 case DRM_FORMAT_XRGB2101010
:
14313 case DRM_FORMAT_XBGR2101010
:
14314 if (INTEL_INFO(dev
)->gen
< 4) {
14315 DRM_DEBUG("unsupported pixel format: %s\n",
14316 drm_get_format_name(mode_cmd
->pixel_format
));
14320 case DRM_FORMAT_ABGR2101010
:
14321 if (!IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
)) {
14322 DRM_DEBUG("unsupported pixel format: %s\n",
14323 drm_get_format_name(mode_cmd
->pixel_format
));
14327 case DRM_FORMAT_YUYV
:
14328 case DRM_FORMAT_UYVY
:
14329 case DRM_FORMAT_YVYU
:
14330 case DRM_FORMAT_VYUY
:
14331 if (INTEL_INFO(dev
)->gen
< 5) {
14332 DRM_DEBUG("unsupported pixel format: %s\n",
14333 drm_get_format_name(mode_cmd
->pixel_format
));
14338 DRM_DEBUG("unsupported pixel format: %s\n",
14339 drm_get_format_name(mode_cmd
->pixel_format
));
14343 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14344 if (mode_cmd
->offsets
[0] != 0)
14347 aligned_height
= intel_fb_align_height(dev
, mode_cmd
->height
,
14348 mode_cmd
->pixel_format
,
14349 mode_cmd
->modifier
[0]);
14350 /* FIXME drm helper for size checks (especially planar formats)? */
14351 if (obj
->base
.size
< aligned_height
* mode_cmd
->pitches
[0])
14354 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
14355 intel_fb
->obj
= obj
;
14357 intel_fill_fb_info(dev_priv
, &intel_fb
->base
);
14359 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
14361 DRM_ERROR("framebuffer init failed %d\n", ret
);
14365 intel_fb
->obj
->framebuffer_references
++;
14370 static struct drm_framebuffer
*
14371 intel_user_framebuffer_create(struct drm_device
*dev
,
14372 struct drm_file
*filp
,
14373 const struct drm_mode_fb_cmd2
*user_mode_cmd
)
14375 struct drm_framebuffer
*fb
;
14376 struct drm_i915_gem_object
*obj
;
14377 struct drm_mode_fb_cmd2 mode_cmd
= *user_mode_cmd
;
14379 obj
= to_intel_bo(drm_gem_object_lookup(dev
, filp
,
14380 mode_cmd
.handles
[0]));
14381 if (&obj
->base
== NULL
)
14382 return ERR_PTR(-ENOENT
);
14384 fb
= intel_framebuffer_create(dev
, &mode_cmd
, obj
);
14386 drm_gem_object_unreference_unlocked(&obj
->base
);
14391 #ifndef CONFIG_DRM_FBDEV_EMULATION
14392 static inline void intel_fbdev_output_poll_changed(struct drm_device
*dev
)
14397 static const struct drm_mode_config_funcs intel_mode_funcs
= {
14398 .fb_create
= intel_user_framebuffer_create
,
14399 .output_poll_changed
= intel_fbdev_output_poll_changed
,
14400 .atomic_check
= intel_atomic_check
,
14401 .atomic_commit
= intel_atomic_commit
,
14402 .atomic_state_alloc
= intel_atomic_state_alloc
,
14403 .atomic_state_clear
= intel_atomic_state_clear
,
14407 * intel_init_display_hooks - initialize the display modesetting hooks
14408 * @dev_priv: device private
14410 void intel_init_display_hooks(struct drm_i915_private
*dev_priv
)
14412 if (INTEL_INFO(dev_priv
)->gen
>= 9) {
14413 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
14414 dev_priv
->display
.get_initial_plane_config
=
14415 skylake_get_initial_plane_config
;
14416 dev_priv
->display
.crtc_compute_clock
=
14417 haswell_crtc_compute_clock
;
14418 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
14419 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
14420 } else if (HAS_DDI(dev_priv
)) {
14421 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
14422 dev_priv
->display
.get_initial_plane_config
=
14423 ironlake_get_initial_plane_config
;
14424 dev_priv
->display
.crtc_compute_clock
=
14425 haswell_crtc_compute_clock
;
14426 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
14427 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
14428 } else if (HAS_PCH_SPLIT(dev_priv
)) {
14429 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
14430 dev_priv
->display
.get_initial_plane_config
=
14431 ironlake_get_initial_plane_config
;
14432 dev_priv
->display
.crtc_compute_clock
=
14433 ironlake_crtc_compute_clock
;
14434 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
14435 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
14436 } else if (IS_CHERRYVIEW(dev_priv
)) {
14437 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14438 dev_priv
->display
.get_initial_plane_config
=
14439 i9xx_get_initial_plane_config
;
14440 dev_priv
->display
.crtc_compute_clock
= chv_crtc_compute_clock
;
14441 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
14442 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14443 } else if (IS_VALLEYVIEW(dev_priv
)) {
14444 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14445 dev_priv
->display
.get_initial_plane_config
=
14446 i9xx_get_initial_plane_config
;
14447 dev_priv
->display
.crtc_compute_clock
= vlv_crtc_compute_clock
;
14448 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
14449 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14450 } else if (IS_G4X(dev_priv
)) {
14451 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14452 dev_priv
->display
.get_initial_plane_config
=
14453 i9xx_get_initial_plane_config
;
14454 dev_priv
->display
.crtc_compute_clock
= g4x_crtc_compute_clock
;
14455 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14456 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14457 } else if (IS_PINEVIEW(dev_priv
)) {
14458 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14459 dev_priv
->display
.get_initial_plane_config
=
14460 i9xx_get_initial_plane_config
;
14461 dev_priv
->display
.crtc_compute_clock
= pnv_crtc_compute_clock
;
14462 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14463 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14464 } else if (!IS_GEN2(dev_priv
)) {
14465 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14466 dev_priv
->display
.get_initial_plane_config
=
14467 i9xx_get_initial_plane_config
;
14468 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
14469 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14470 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14472 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14473 dev_priv
->display
.get_initial_plane_config
=
14474 i9xx_get_initial_plane_config
;
14475 dev_priv
->display
.crtc_compute_clock
= i8xx_crtc_compute_clock
;
14476 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14477 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14480 /* Returns the core display clock speed */
14481 if (IS_SKYLAKE(dev_priv
) || IS_KABYLAKE(dev_priv
))
14482 dev_priv
->display
.get_display_clock_speed
=
14483 skylake_get_display_clock_speed
;
14484 else if (IS_BROXTON(dev_priv
))
14485 dev_priv
->display
.get_display_clock_speed
=
14486 broxton_get_display_clock_speed
;
14487 else if (IS_BROADWELL(dev_priv
))
14488 dev_priv
->display
.get_display_clock_speed
=
14489 broadwell_get_display_clock_speed
;
14490 else if (IS_HASWELL(dev_priv
))
14491 dev_priv
->display
.get_display_clock_speed
=
14492 haswell_get_display_clock_speed
;
14493 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
14494 dev_priv
->display
.get_display_clock_speed
=
14495 valleyview_get_display_clock_speed
;
14496 else if (IS_GEN5(dev_priv
))
14497 dev_priv
->display
.get_display_clock_speed
=
14498 ilk_get_display_clock_speed
;
14499 else if (IS_I945G(dev_priv
) || IS_BROADWATER(dev_priv
) ||
14500 IS_GEN6(dev_priv
) || IS_IVYBRIDGE(dev_priv
))
14501 dev_priv
->display
.get_display_clock_speed
=
14502 i945_get_display_clock_speed
;
14503 else if (IS_GM45(dev_priv
))
14504 dev_priv
->display
.get_display_clock_speed
=
14505 gm45_get_display_clock_speed
;
14506 else if (IS_CRESTLINE(dev_priv
))
14507 dev_priv
->display
.get_display_clock_speed
=
14508 i965gm_get_display_clock_speed
;
14509 else if (IS_PINEVIEW(dev_priv
))
14510 dev_priv
->display
.get_display_clock_speed
=
14511 pnv_get_display_clock_speed
;
14512 else if (IS_G33(dev_priv
) || IS_G4X(dev_priv
))
14513 dev_priv
->display
.get_display_clock_speed
=
14514 g33_get_display_clock_speed
;
14515 else if (IS_I915G(dev_priv
))
14516 dev_priv
->display
.get_display_clock_speed
=
14517 i915_get_display_clock_speed
;
14518 else if (IS_I945GM(dev_priv
) || IS_845G(dev_priv
))
14519 dev_priv
->display
.get_display_clock_speed
=
14520 i9xx_misc_get_display_clock_speed
;
14521 else if (IS_I915GM(dev_priv
))
14522 dev_priv
->display
.get_display_clock_speed
=
14523 i915gm_get_display_clock_speed
;
14524 else if (IS_I865G(dev_priv
))
14525 dev_priv
->display
.get_display_clock_speed
=
14526 i865_get_display_clock_speed
;
14527 else if (IS_I85X(dev_priv
))
14528 dev_priv
->display
.get_display_clock_speed
=
14529 i85x_get_display_clock_speed
;
14531 WARN(!IS_I830(dev_priv
), "Unknown platform. Assuming 133 MHz CDCLK\n");
14532 dev_priv
->display
.get_display_clock_speed
=
14533 i830_get_display_clock_speed
;
14536 if (IS_GEN5(dev_priv
)) {
14537 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
14538 } else if (IS_GEN6(dev_priv
)) {
14539 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
14540 } else if (IS_IVYBRIDGE(dev_priv
)) {
14541 /* FIXME: detect B0+ stepping and use auto training */
14542 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
14543 } else if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
14544 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
14547 if (IS_BROADWELL(dev_priv
)) {
14548 dev_priv
->display
.modeset_commit_cdclk
=
14549 broadwell_modeset_commit_cdclk
;
14550 dev_priv
->display
.modeset_calc_cdclk
=
14551 broadwell_modeset_calc_cdclk
;
14552 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
14553 dev_priv
->display
.modeset_commit_cdclk
=
14554 valleyview_modeset_commit_cdclk
;
14555 dev_priv
->display
.modeset_calc_cdclk
=
14556 valleyview_modeset_calc_cdclk
;
14557 } else if (IS_BROXTON(dev_priv
)) {
14558 dev_priv
->display
.modeset_commit_cdclk
=
14559 broxton_modeset_commit_cdclk
;
14560 dev_priv
->display
.modeset_calc_cdclk
=
14561 broxton_modeset_calc_cdclk
;
14562 } else if (IS_SKYLAKE(dev_priv
) || IS_KABYLAKE(dev_priv
)) {
14563 dev_priv
->display
.modeset_commit_cdclk
=
14564 skl_modeset_commit_cdclk
;
14565 dev_priv
->display
.modeset_calc_cdclk
=
14566 skl_modeset_calc_cdclk
;
14571 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
14572 * resume, or other times. This quirk makes sure that's the case for
14573 * affected systems.
14575 static void quirk_pipea_force(struct drm_device
*dev
)
14577 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14579 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
14580 DRM_INFO("applying pipe a force quirk\n");
14583 static void quirk_pipeb_force(struct drm_device
*dev
)
14585 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14587 dev_priv
->quirks
|= QUIRK_PIPEB_FORCE
;
14588 DRM_INFO("applying pipe b force quirk\n");
14592 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
14594 static void quirk_ssc_force_disable(struct drm_device
*dev
)
14596 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14597 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
14598 DRM_INFO("applying lvds SSC disable quirk\n");
14602 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
14605 static void quirk_invert_brightness(struct drm_device
*dev
)
14607 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14608 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
14609 DRM_INFO("applying inverted panel brightness quirk\n");
14612 /* Some VBT's incorrectly indicate no backlight is present */
14613 static void quirk_backlight_present(struct drm_device
*dev
)
14615 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14616 dev_priv
->quirks
|= QUIRK_BACKLIGHT_PRESENT
;
14617 DRM_INFO("applying backlight present quirk\n");
14620 struct intel_quirk
{
14622 int subsystem_vendor
;
14623 int subsystem_device
;
14624 void (*hook
)(struct drm_device
*dev
);
14627 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
14628 struct intel_dmi_quirk
{
14629 void (*hook
)(struct drm_device
*dev
);
14630 const struct dmi_system_id (*dmi_id_list
)[];
14633 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
14635 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
14639 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
14641 .dmi_id_list
= &(const struct dmi_system_id
[]) {
14643 .callback
= intel_dmi_reverse_brightness
,
14644 .ident
= "NCR Corporation",
14645 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
14646 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
14649 { } /* terminating entry */
14651 .hook
= quirk_invert_brightness
,
14655 static struct intel_quirk intel_quirks
[] = {
14656 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
14657 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
14659 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
14660 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
14662 /* 830 needs to leave pipe A & dpll A up */
14663 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
14665 /* 830 needs to leave pipe B & dpll B up */
14666 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipeb_force
},
14668 /* Lenovo U160 cannot use SSC on LVDS */
14669 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
14671 /* Sony Vaio Y cannot use SSC on LVDS */
14672 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
14674 /* Acer Aspire 5734Z must invert backlight brightness */
14675 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
14677 /* Acer/eMachines G725 */
14678 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
14680 /* Acer/eMachines e725 */
14681 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
14683 /* Acer/Packard Bell NCL20 */
14684 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
14686 /* Acer Aspire 4736Z */
14687 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
14689 /* Acer Aspire 5336 */
14690 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
14692 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
14693 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present
},
14695 /* Acer C720 Chromebook (Core i3 4005U) */
14696 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present
},
14698 /* Apple Macbook 2,1 (Core 2 T7400) */
14699 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present
},
14701 /* Apple Macbook 4,1 */
14702 { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present
},
14704 /* Toshiba CB35 Chromebook (Celeron 2955U) */
14705 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present
},
14707 /* HP Chromebook 14 (Celeron 2955U) */
14708 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present
},
14710 /* Dell Chromebook 11 */
14711 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present
},
14713 /* Dell Chromebook 11 (2015 version) */
14714 { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present
},
14717 static void intel_init_quirks(struct drm_device
*dev
)
14719 struct pci_dev
*d
= dev
->pdev
;
14722 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
14723 struct intel_quirk
*q
= &intel_quirks
[i
];
14725 if (d
->device
== q
->device
&&
14726 (d
->subsystem_vendor
== q
->subsystem_vendor
||
14727 q
->subsystem_vendor
== PCI_ANY_ID
) &&
14728 (d
->subsystem_device
== q
->subsystem_device
||
14729 q
->subsystem_device
== PCI_ANY_ID
))
14732 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
14733 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
14734 intel_dmi_quirks
[i
].hook(dev
);
14738 /* Disable the VGA plane that we never use */
14739 static void i915_disable_vga(struct drm_device
*dev
)
14741 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14743 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev
);
14745 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
14746 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
14747 outb(SR01
, VGA_SR_INDEX
);
14748 sr1
= inb(VGA_SR_DATA
);
14749 outb(sr1
| 1<<5, VGA_SR_DATA
);
14750 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
14753 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
14754 POSTING_READ(vga_reg
);
14757 void intel_modeset_init_hw(struct drm_device
*dev
)
14759 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14761 intel_update_cdclk(dev
);
14763 dev_priv
->atomic_cdclk_freq
= dev_priv
->cdclk_freq
;
14765 intel_init_clock_gating(dev
);
14766 intel_enable_gt_powersave(dev_priv
);
14770 * Calculate what we think the watermarks should be for the state we've read
14771 * out of the hardware and then immediately program those watermarks so that
14772 * we ensure the hardware settings match our internal state.
14774 * We can calculate what we think WM's should be by creating a duplicate of the
14775 * current state (which was constructed during hardware readout) and running it
14776 * through the atomic check code to calculate new watermark values in the
14779 static void sanitize_watermarks(struct drm_device
*dev
)
14781 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14782 struct drm_atomic_state
*state
;
14783 struct drm_crtc
*crtc
;
14784 struct drm_crtc_state
*cstate
;
14785 struct drm_modeset_acquire_ctx ctx
;
14789 /* Only supported on platforms that use atomic watermark design */
14790 if (!dev_priv
->display
.optimize_watermarks
)
14794 * We need to hold connection_mutex before calling duplicate_state so
14795 * that the connector loop is protected.
14797 drm_modeset_acquire_init(&ctx
, 0);
14799 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
14800 if (ret
== -EDEADLK
) {
14801 drm_modeset_backoff(&ctx
);
14803 } else if (WARN_ON(ret
)) {
14807 state
= drm_atomic_helper_duplicate_state(dev
, &ctx
);
14808 if (WARN_ON(IS_ERR(state
)))
14812 * Hardware readout is the only time we don't want to calculate
14813 * intermediate watermarks (since we don't trust the current
14816 to_intel_atomic_state(state
)->skip_intermediate_wm
= true;
14818 ret
= intel_atomic_check(dev
, state
);
14821 * If we fail here, it means that the hardware appears to be
14822 * programmed in a way that shouldn't be possible, given our
14823 * understanding of watermark requirements. This might mean a
14824 * mistake in the hardware readout code or a mistake in the
14825 * watermark calculations for a given platform. Raise a WARN
14826 * so that this is noticeable.
14828 * If this actually happens, we'll have to just leave the
14829 * BIOS-programmed watermarks untouched and hope for the best.
14831 WARN(true, "Could not determine valid watermarks for inherited state\n");
14835 /* Write calculated watermark values back */
14836 for_each_crtc_in_state(state
, crtc
, cstate
, i
) {
14837 struct intel_crtc_state
*cs
= to_intel_crtc_state(cstate
);
14839 cs
->wm
.need_postvbl_update
= true;
14840 dev_priv
->display
.optimize_watermarks(cs
);
14843 drm_atomic_state_free(state
);
14845 drm_modeset_drop_locks(&ctx
);
14846 drm_modeset_acquire_fini(&ctx
);
14849 void intel_modeset_init(struct drm_device
*dev
)
14851 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14852 struct i915_ggtt
*ggtt
= &dev_priv
->ggtt
;
14855 struct intel_crtc
*crtc
;
14857 drm_mode_config_init(dev
);
14859 dev
->mode_config
.min_width
= 0;
14860 dev
->mode_config
.min_height
= 0;
14862 dev
->mode_config
.preferred_depth
= 24;
14863 dev
->mode_config
.prefer_shadow
= 1;
14865 dev
->mode_config
.allow_fb_modifiers
= true;
14867 dev
->mode_config
.funcs
= &intel_mode_funcs
;
14869 intel_init_quirks(dev
);
14871 intel_init_pm(dev
);
14873 if (INTEL_INFO(dev
)->num_pipes
== 0)
14877 * There may be no VBT; and if the BIOS enabled SSC we can
14878 * just keep using it to avoid unnecessary flicker. Whereas if the
14879 * BIOS isn't using it, don't assume it will work even if the VBT
14880 * indicates as much.
14882 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)) {
14883 bool bios_lvds_use_ssc
= !!(I915_READ(PCH_DREF_CONTROL
) &
14886 if (dev_priv
->vbt
.lvds_use_ssc
!= bios_lvds_use_ssc
) {
14887 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
14888 bios_lvds_use_ssc
? "en" : "dis",
14889 dev_priv
->vbt
.lvds_use_ssc
? "en" : "dis");
14890 dev_priv
->vbt
.lvds_use_ssc
= bios_lvds_use_ssc
;
14894 if (IS_GEN2(dev
)) {
14895 dev
->mode_config
.max_width
= 2048;
14896 dev
->mode_config
.max_height
= 2048;
14897 } else if (IS_GEN3(dev
)) {
14898 dev
->mode_config
.max_width
= 4096;
14899 dev
->mode_config
.max_height
= 4096;
14901 dev
->mode_config
.max_width
= 8192;
14902 dev
->mode_config
.max_height
= 8192;
14905 if (IS_845G(dev
) || IS_I865G(dev
)) {
14906 dev
->mode_config
.cursor_width
= IS_845G(dev
) ? 64 : 512;
14907 dev
->mode_config
.cursor_height
= 1023;
14908 } else if (IS_GEN2(dev
)) {
14909 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
14910 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
14912 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
14913 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
14916 dev
->mode_config
.fb_base
= ggtt
->mappable_base
;
14918 DRM_DEBUG_KMS("%d display pipe%s available.\n",
14919 INTEL_INFO(dev
)->num_pipes
,
14920 INTEL_INFO(dev
)->num_pipes
> 1 ? "s" : "");
14922 for_each_pipe(dev_priv
, pipe
) {
14923 intel_crtc_init(dev
, pipe
);
14924 for_each_sprite(dev_priv
, pipe
, sprite
) {
14925 ret
= intel_plane_init(dev
, pipe
, sprite
);
14927 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
14928 pipe_name(pipe
), sprite_name(pipe
, sprite
), ret
);
14932 intel_update_czclk(dev_priv
);
14933 intel_update_cdclk(dev
);
14935 intel_shared_dpll_init(dev
);
14937 if (dev_priv
->max_cdclk_freq
== 0)
14938 intel_update_max_cdclk(dev
);
14940 /* Just disable it once at startup */
14941 i915_disable_vga(dev
);
14942 intel_setup_outputs(dev
);
14944 drm_modeset_lock_all(dev
);
14945 intel_modeset_setup_hw_state(dev
);
14946 drm_modeset_unlock_all(dev
);
14948 for_each_intel_crtc(dev
, crtc
) {
14949 struct intel_initial_plane_config plane_config
= {};
14955 * Note that reserving the BIOS fb up front prevents us
14956 * from stuffing other stolen allocations like the ring
14957 * on top. This prevents some ugliness at boot time, and
14958 * can even allow for smooth boot transitions if the BIOS
14959 * fb is large enough for the active pipe configuration.
14961 dev_priv
->display
.get_initial_plane_config(crtc
,
14965 * If the fb is shared between multiple heads, we'll
14966 * just get the first one.
14968 intel_find_initial_plane_obj(crtc
, &plane_config
);
14972 * Make sure hardware watermarks really match the state we read out.
14973 * Note that we need to do this after reconstructing the BIOS fb's
14974 * since the watermark calculation done here will use pstate->fb.
14976 sanitize_watermarks(dev
);
14979 static void intel_enable_pipe_a(struct drm_device
*dev
)
14981 struct intel_connector
*connector
;
14982 struct drm_connector
*crt
= NULL
;
14983 struct intel_load_detect_pipe load_detect_temp
;
14984 struct drm_modeset_acquire_ctx
*ctx
= dev
->mode_config
.acquire_ctx
;
14986 /* We can't just switch on the pipe A, we need to set things up with a
14987 * proper mode and output configuration. As a gross hack, enable pipe A
14988 * by enabling the load detect pipe once. */
14989 for_each_intel_connector(dev
, connector
) {
14990 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
14991 crt
= &connector
->base
;
14999 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
, ctx
))
15000 intel_release_load_detect_pipe(crt
, &load_detect_temp
, ctx
);
15004 intel_check_plane_mapping(struct intel_crtc
*crtc
)
15006 struct drm_device
*dev
= crtc
->base
.dev
;
15007 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15010 if (INTEL_INFO(dev
)->num_pipes
== 1)
15013 val
= I915_READ(DSPCNTR(!crtc
->plane
));
15015 if ((val
& DISPLAY_PLANE_ENABLE
) &&
15016 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
15022 static bool intel_crtc_has_encoders(struct intel_crtc
*crtc
)
15024 struct drm_device
*dev
= crtc
->base
.dev
;
15025 struct intel_encoder
*encoder
;
15027 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
15033 static bool intel_encoder_has_connectors(struct intel_encoder
*encoder
)
15035 struct drm_device
*dev
= encoder
->base
.dev
;
15036 struct intel_connector
*connector
;
15038 for_each_connector_on_encoder(dev
, &encoder
->base
, connector
)
15044 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
15046 struct drm_device
*dev
= crtc
->base
.dev
;
15047 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15048 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
15050 /* Clear any frame start delays used for debugging left by the BIOS */
15051 if (!transcoder_is_dsi(cpu_transcoder
)) {
15052 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
15055 I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
15058 /* restore vblank interrupts to correct state */
15059 drm_crtc_vblank_reset(&crtc
->base
);
15060 if (crtc
->active
) {
15061 struct intel_plane
*plane
;
15063 drm_crtc_vblank_on(&crtc
->base
);
15065 /* Disable everything but the primary plane */
15066 for_each_intel_plane_on_crtc(dev
, crtc
, plane
) {
15067 if (plane
->base
.type
== DRM_PLANE_TYPE_PRIMARY
)
15070 plane
->disable_plane(&plane
->base
, &crtc
->base
);
15074 /* We need to sanitize the plane -> pipe mapping first because this will
15075 * disable the crtc (and hence change the state) if it is wrong. Note
15076 * that gen4+ has a fixed plane -> pipe mapping. */
15077 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
15080 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
15081 crtc
->base
.base
.id
);
15083 /* Pipe has the wrong plane attached and the plane is active.
15084 * Temporarily change the plane mapping and disable everything
15086 plane
= crtc
->plane
;
15087 to_intel_plane_state(crtc
->base
.primary
->state
)->visible
= true;
15088 crtc
->plane
= !plane
;
15089 intel_crtc_disable_noatomic(&crtc
->base
);
15090 crtc
->plane
= plane
;
15093 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
15094 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
15095 /* BIOS forgot to enable pipe A, this mostly happens after
15096 * resume. Force-enable the pipe to fix this, the update_dpms
15097 * call below we restore the pipe to the right state, but leave
15098 * the required bits on. */
15099 intel_enable_pipe_a(dev
);
15102 /* Adjust the state of the output pipe according to whether we
15103 * have active connectors/encoders. */
15104 if (crtc
->active
&& !intel_crtc_has_encoders(crtc
))
15105 intel_crtc_disable_noatomic(&crtc
->base
);
15107 if (crtc
->active
|| HAS_GMCH_DISPLAY(dev
)) {
15109 * We start out with underrun reporting disabled to avoid races.
15110 * For correct bookkeeping mark this on active crtcs.
15112 * Also on gmch platforms we dont have any hardware bits to
15113 * disable the underrun reporting. Which means we need to start
15114 * out with underrun reporting disabled also on inactive pipes,
15115 * since otherwise we'll complain about the garbage we read when
15116 * e.g. coming up after runtime pm.
15118 * No protection against concurrent access is required - at
15119 * worst a fifo underrun happens which also sets this to false.
15121 crtc
->cpu_fifo_underrun_disabled
= true;
15122 crtc
->pch_fifo_underrun_disabled
= true;
15126 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
15128 struct intel_connector
*connector
;
15129 struct drm_device
*dev
= encoder
->base
.dev
;
15131 /* We need to check both for a crtc link (meaning that the
15132 * encoder is active and trying to read from a pipe) and the
15133 * pipe itself being active. */
15134 bool has_active_crtc
= encoder
->base
.crtc
&&
15135 to_intel_crtc(encoder
->base
.crtc
)->active
;
15137 if (intel_encoder_has_connectors(encoder
) && !has_active_crtc
) {
15138 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15139 encoder
->base
.base
.id
,
15140 encoder
->base
.name
);
15142 /* Connector is active, but has no active pipe. This is
15143 * fallout from our resume register restoring. Disable
15144 * the encoder manually again. */
15145 if (encoder
->base
.crtc
) {
15146 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15147 encoder
->base
.base
.id
,
15148 encoder
->base
.name
);
15149 encoder
->disable(encoder
);
15150 if (encoder
->post_disable
)
15151 encoder
->post_disable(encoder
);
15153 encoder
->base
.crtc
= NULL
;
15155 /* Inconsistent output/port/pipe state happens presumably due to
15156 * a bug in one of the get_hw_state functions. Or someplace else
15157 * in our code, like the register restore mess on resume. Clamp
15158 * things to off as a safer default. */
15159 for_each_intel_connector(dev
, connector
) {
15160 if (connector
->encoder
!= encoder
)
15162 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
15163 connector
->base
.encoder
= NULL
;
15166 /* Enabled encoders without active connectors will be fixed in
15167 * the crtc fixup. */
15170 void i915_redisable_vga_power_on(struct drm_device
*dev
)
15172 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15173 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev
);
15175 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
15176 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
15177 i915_disable_vga(dev
);
15181 void i915_redisable_vga(struct drm_device
*dev
)
15183 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15185 /* This function can be called both from intel_modeset_setup_hw_state or
15186 * at a very early point in our resume sequence, where the power well
15187 * structures are not yet restored. Since this function is at a very
15188 * paranoid "someone might have enabled VGA while we were not looking"
15189 * level, just check if the power well is enabled instead of trying to
15190 * follow the "don't touch the power well if we don't need it" policy
15191 * the rest of the driver uses. */
15192 if (!intel_display_power_get_if_enabled(dev_priv
, POWER_DOMAIN_VGA
))
15195 i915_redisable_vga_power_on(dev
);
15197 intel_display_power_put(dev_priv
, POWER_DOMAIN_VGA
);
15200 static bool primary_get_hw_state(struct intel_plane
*plane
)
15202 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
15204 return I915_READ(DSPCNTR(plane
->plane
)) & DISPLAY_PLANE_ENABLE
;
15207 /* FIXME read out full plane state for all planes */
15208 static void readout_plane_state(struct intel_crtc
*crtc
)
15210 struct drm_plane
*primary
= crtc
->base
.primary
;
15211 struct intel_plane_state
*plane_state
=
15212 to_intel_plane_state(primary
->state
);
15214 plane_state
->visible
= crtc
->active
&&
15215 primary_get_hw_state(to_intel_plane(primary
));
15217 if (plane_state
->visible
)
15218 crtc
->base
.state
->plane_mask
|= 1 << drm_plane_index(primary
);
15221 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
15223 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15225 struct intel_crtc
*crtc
;
15226 struct intel_encoder
*encoder
;
15227 struct intel_connector
*connector
;
15230 dev_priv
->active_crtcs
= 0;
15232 for_each_intel_crtc(dev
, crtc
) {
15233 struct intel_crtc_state
*crtc_state
= crtc
->config
;
15236 __drm_atomic_helper_crtc_destroy_state(&crtc
->base
, &crtc_state
->base
);
15237 memset(crtc_state
, 0, sizeof(*crtc_state
));
15238 crtc_state
->base
.crtc
= &crtc
->base
;
15240 crtc_state
->base
.active
= crtc_state
->base
.enable
=
15241 dev_priv
->display
.get_pipe_config(crtc
, crtc_state
);
15243 crtc
->base
.enabled
= crtc_state
->base
.enable
;
15244 crtc
->active
= crtc_state
->base
.active
;
15246 if (crtc_state
->base
.active
) {
15247 dev_priv
->active_crtcs
|= 1 << crtc
->pipe
;
15249 if (INTEL_GEN(dev_priv
) >= 9 || IS_BROADWELL(dev_priv
))
15250 pixclk
= ilk_pipe_pixel_rate(crtc_state
);
15251 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
15252 pixclk
= crtc_state
->base
.adjusted_mode
.crtc_clock
;
15254 WARN_ON(dev_priv
->display
.modeset_calc_cdclk
);
15256 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
15257 if (IS_BROADWELL(dev_priv
) && crtc_state
->ips_enabled
)
15258 pixclk
= DIV_ROUND_UP(pixclk
* 100, 95);
15261 dev_priv
->min_pixclk
[crtc
->pipe
] = pixclk
;
15263 readout_plane_state(crtc
);
15265 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
15266 crtc
->base
.base
.id
,
15267 crtc
->active
? "enabled" : "disabled");
15270 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
15271 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
15273 pll
->on
= pll
->funcs
.get_hw_state(dev_priv
, pll
,
15274 &pll
->config
.hw_state
);
15275 pll
->config
.crtc_mask
= 0;
15276 for_each_intel_crtc(dev
, crtc
) {
15277 if (crtc
->active
&& crtc
->config
->shared_dpll
== pll
)
15278 pll
->config
.crtc_mask
|= 1 << crtc
->pipe
;
15280 pll
->active_mask
= pll
->config
.crtc_mask
;
15282 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15283 pll
->name
, pll
->config
.crtc_mask
, pll
->on
);
15286 for_each_intel_encoder(dev
, encoder
) {
15289 if (encoder
->get_hw_state(encoder
, &pipe
)) {
15290 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
15291 encoder
->base
.crtc
= &crtc
->base
;
15292 encoder
->get_config(encoder
, crtc
->config
);
15294 encoder
->base
.crtc
= NULL
;
15297 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15298 encoder
->base
.base
.id
,
15299 encoder
->base
.name
,
15300 encoder
->base
.crtc
? "enabled" : "disabled",
15304 for_each_intel_connector(dev
, connector
) {
15305 if (connector
->get_hw_state(connector
)) {
15306 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
15308 encoder
= connector
->encoder
;
15309 connector
->base
.encoder
= &encoder
->base
;
15311 if (encoder
->base
.crtc
&&
15312 encoder
->base
.crtc
->state
->active
) {
15314 * This has to be done during hardware readout
15315 * because anything calling .crtc_disable may
15316 * rely on the connector_mask being accurate.
15318 encoder
->base
.crtc
->state
->connector_mask
|=
15319 1 << drm_connector_index(&connector
->base
);
15320 encoder
->base
.crtc
->state
->encoder_mask
|=
15321 1 << drm_encoder_index(&encoder
->base
);
15325 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
15326 connector
->base
.encoder
= NULL
;
15328 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
15329 connector
->base
.base
.id
,
15330 connector
->base
.name
,
15331 connector
->base
.encoder
? "enabled" : "disabled");
15334 for_each_intel_crtc(dev
, crtc
) {
15335 crtc
->base
.hwmode
= crtc
->config
->base
.adjusted_mode
;
15337 memset(&crtc
->base
.mode
, 0, sizeof(crtc
->base
.mode
));
15338 if (crtc
->base
.state
->active
) {
15339 intel_mode_from_pipe_config(&crtc
->base
.mode
, crtc
->config
);
15340 intel_mode_from_pipe_config(&crtc
->base
.state
->adjusted_mode
, crtc
->config
);
15341 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->base
.state
, &crtc
->base
.mode
));
15344 * The initial mode needs to be set in order to keep
15345 * the atomic core happy. It wants a valid mode if the
15346 * crtc's enabled, so we do the above call.
15348 * At this point some state updated by the connectors
15349 * in their ->detect() callback has not run yet, so
15350 * no recalculation can be done yet.
15352 * Even if we could do a recalculation and modeset
15353 * right now it would cause a double modeset if
15354 * fbdev or userspace chooses a different initial mode.
15356 * If that happens, someone indicated they wanted a
15357 * mode change, which means it's safe to do a full
15360 crtc
->base
.state
->mode
.private_flags
= I915_MODE_FLAG_INHERITED
;
15362 drm_calc_timestamping_constants(&crtc
->base
, &crtc
->base
.hwmode
);
15363 update_scanline_offset(crtc
);
15366 intel_pipe_config_sanity_check(dev_priv
, crtc
->config
);
15370 /* Scan out the current hw modeset state,
15371 * and sanitizes it to the current state
15374 intel_modeset_setup_hw_state(struct drm_device
*dev
)
15376 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15378 struct intel_crtc
*crtc
;
15379 struct intel_encoder
*encoder
;
15382 intel_modeset_readout_hw_state(dev
);
15384 /* HW state is read out, now we need to sanitize this mess. */
15385 for_each_intel_encoder(dev
, encoder
) {
15386 intel_sanitize_encoder(encoder
);
15389 for_each_pipe(dev_priv
, pipe
) {
15390 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
15391 intel_sanitize_crtc(crtc
);
15392 intel_dump_pipe_config(crtc
, crtc
->config
,
15393 "[setup_hw_state]");
15396 intel_modeset_update_connector_atomic_state(dev
);
15398 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
15399 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
15401 if (!pll
->on
|| pll
->active_mask
)
15404 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
15406 pll
->funcs
.disable(dev_priv
, pll
);
15410 if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
))
15411 vlv_wm_get_hw_state(dev
);
15412 else if (IS_GEN9(dev
))
15413 skl_wm_get_hw_state(dev
);
15414 else if (HAS_PCH_SPLIT(dev
))
15415 ilk_wm_get_hw_state(dev
);
15417 for_each_intel_crtc(dev
, crtc
) {
15418 unsigned long put_domains
;
15420 put_domains
= modeset_get_crtc_power_domains(&crtc
->base
, crtc
->config
);
15421 if (WARN_ON(put_domains
))
15422 modeset_put_power_domains(dev_priv
, put_domains
);
15424 intel_display_set_init_power(dev_priv
, false);
15426 intel_fbc_init_pipe_state(dev_priv
);
15429 void intel_display_resume(struct drm_device
*dev
)
15431 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15432 struct drm_atomic_state
*state
= dev_priv
->modeset_restore_state
;
15433 struct drm_modeset_acquire_ctx ctx
;
15435 bool setup
= false;
15437 dev_priv
->modeset_restore_state
= NULL
;
15440 * This is a cludge because with real atomic modeset mode_config.mutex
15441 * won't be taken. Unfortunately some probed state like
15442 * audio_codec_enable is still protected by mode_config.mutex, so lock
15445 mutex_lock(&dev
->mode_config
.mutex
);
15446 drm_modeset_acquire_init(&ctx
, 0);
15449 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
15451 if (ret
== 0 && !setup
) {
15454 intel_modeset_setup_hw_state(dev
);
15455 i915_redisable_vga(dev
);
15458 if (ret
== 0 && state
) {
15459 struct drm_crtc_state
*crtc_state
;
15460 struct drm_crtc
*crtc
;
15463 state
->acquire_ctx
= &ctx
;
15465 /* ignore any reset values/BIOS leftovers in the WM registers */
15466 to_intel_atomic_state(state
)->skip_intermediate_wm
= true;
15468 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
15470 * Force recalculation even if we restore
15471 * current state. With fast modeset this may not result
15472 * in a modeset when the state is compatible.
15474 crtc_state
->mode_changed
= true;
15477 ret
= drm_atomic_commit(state
);
15480 if (ret
== -EDEADLK
) {
15481 drm_modeset_backoff(&ctx
);
15485 drm_modeset_drop_locks(&ctx
);
15486 drm_modeset_acquire_fini(&ctx
);
15487 mutex_unlock(&dev
->mode_config
.mutex
);
15490 DRM_ERROR("Restoring old state failed with %i\n", ret
);
15491 drm_atomic_state_free(state
);
15495 void intel_modeset_gem_init(struct drm_device
*dev
)
15497 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15498 struct drm_crtc
*c
;
15499 struct drm_i915_gem_object
*obj
;
15502 intel_init_gt_powersave(dev_priv
);
15504 intel_modeset_init_hw(dev
);
15506 intel_setup_overlay(dev_priv
);
15509 * Make sure any fbs we allocated at startup are properly
15510 * pinned & fenced. When we do the allocation it's too early
15513 for_each_crtc(dev
, c
) {
15514 obj
= intel_fb_obj(c
->primary
->fb
);
15518 mutex_lock(&dev
->struct_mutex
);
15519 ret
= intel_pin_and_fence_fb_obj(c
->primary
->fb
,
15520 c
->primary
->state
->rotation
);
15521 mutex_unlock(&dev
->struct_mutex
);
15523 DRM_ERROR("failed to pin boot fb on pipe %d\n",
15524 to_intel_crtc(c
)->pipe
);
15525 drm_framebuffer_unreference(c
->primary
->fb
);
15526 drm_framebuffer_unreference(c
->primary
->state
->fb
);
15527 c
->primary
->fb
= c
->primary
->state
->fb
= NULL
;
15528 c
->primary
->crtc
= c
->primary
->state
->crtc
= NULL
;
15529 c
->state
->plane_mask
&= ~(1 << drm_plane_index(c
->primary
));
15533 intel_backlight_register(dev
);
15536 void intel_connector_unregister(struct intel_connector
*intel_connector
)
15538 struct drm_connector
*connector
= &intel_connector
->base
;
15540 intel_panel_destroy_backlight(connector
);
15541 drm_connector_unregister(connector
);
15544 void intel_modeset_cleanup(struct drm_device
*dev
)
15546 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15547 struct intel_connector
*connector
;
15549 intel_disable_gt_powersave(dev_priv
);
15551 intel_backlight_unregister(dev
);
15554 * Interrupts and polling as the first thing to avoid creating havoc.
15555 * Too much stuff here (turning of connectors, ...) would
15556 * experience fancy races otherwise.
15558 intel_irq_uninstall(dev_priv
);
15561 * Due to the hpd irq storm handling the hotplug work can re-arm the
15562 * poll handlers. Hence disable polling after hpd handling is shut down.
15564 drm_kms_helper_poll_fini(dev
);
15566 intel_unregister_dsm_handler();
15568 intel_fbc_global_disable(dev_priv
);
15570 /* flush any delayed tasks or pending work */
15571 flush_scheduled_work();
15573 /* destroy the backlight and sysfs files before encoders/connectors */
15574 for_each_intel_connector(dev
, connector
)
15575 connector
->unregister(connector
);
15577 drm_mode_config_cleanup(dev
);
15579 intel_cleanup_overlay(dev_priv
);
15581 intel_cleanup_gt_powersave(dev_priv
);
15583 intel_teardown_gmbus(dev
);
15587 * Return which encoder is currently attached for connector.
15589 struct drm_encoder
*intel_best_encoder(struct drm_connector
*connector
)
15591 return &intel_attached_encoder(connector
)->base
;
15594 void intel_connector_attach_encoder(struct intel_connector
*connector
,
15595 struct intel_encoder
*encoder
)
15597 connector
->encoder
= encoder
;
15598 drm_mode_connector_attach_encoder(&connector
->base
,
15603 * set vga decode state - true == enable VGA decode
15605 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
15607 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15608 unsigned reg
= INTEL_INFO(dev
)->gen
>= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
15611 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
15612 DRM_ERROR("failed to read control word\n");
15616 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
15620 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
15622 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
15624 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
15625 DRM_ERROR("failed to write control word\n");
15632 struct intel_display_error_state
{
15634 u32 power_well_driver
;
15636 int num_transcoders
;
15638 struct intel_cursor_error_state
{
15643 } cursor
[I915_MAX_PIPES
];
15645 struct intel_pipe_error_state
{
15646 bool power_domain_on
;
15649 } pipe
[I915_MAX_PIPES
];
15651 struct intel_plane_error_state
{
15659 } plane
[I915_MAX_PIPES
];
15661 struct intel_transcoder_error_state
{
15662 bool power_domain_on
;
15663 enum transcoder cpu_transcoder
;
15676 struct intel_display_error_state
*
15677 intel_display_capture_error_state(struct drm_i915_private
*dev_priv
)
15679 struct intel_display_error_state
*error
;
15680 int transcoders
[] = {
15688 if (INTEL_INFO(dev_priv
)->num_pipes
== 0)
15691 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
15695 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
15696 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
15698 for_each_pipe(dev_priv
, i
) {
15699 error
->pipe
[i
].power_domain_on
=
15700 __intel_display_power_is_enabled(dev_priv
,
15701 POWER_DOMAIN_PIPE(i
));
15702 if (!error
->pipe
[i
].power_domain_on
)
15705 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
15706 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
15707 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
15709 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
15710 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
15711 if (INTEL_GEN(dev_priv
) <= 3) {
15712 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
15713 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
15715 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
15716 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
15717 if (INTEL_GEN(dev_priv
) >= 4) {
15718 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
15719 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
15722 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
15724 if (HAS_GMCH_DISPLAY(dev_priv
))
15725 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
15728 /* Note: this does not include DSI transcoders. */
15729 error
->num_transcoders
= INTEL_INFO(dev_priv
)->num_pipes
;
15730 if (HAS_DDI(dev_priv
))
15731 error
->num_transcoders
++; /* Account for eDP. */
15733 for (i
= 0; i
< error
->num_transcoders
; i
++) {
15734 enum transcoder cpu_transcoder
= transcoders
[i
];
15736 error
->transcoder
[i
].power_domain_on
=
15737 __intel_display_power_is_enabled(dev_priv
,
15738 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
15739 if (!error
->transcoder
[i
].power_domain_on
)
15742 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
15744 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
15745 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
15746 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
15747 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
15748 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
15749 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
15750 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
15756 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
15759 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
15760 struct drm_device
*dev
,
15761 struct intel_display_error_state
*error
)
15763 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15769 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev
)->num_pipes
);
15770 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
15771 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
15772 error
->power_well_driver
);
15773 for_each_pipe(dev_priv
, i
) {
15774 err_printf(m
, "Pipe [%d]:\n", i
);
15775 err_printf(m
, " Power: %s\n",
15776 onoff(error
->pipe
[i
].power_domain_on
));
15777 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
15778 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
15780 err_printf(m
, "Plane [%d]:\n", i
);
15781 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
15782 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
15783 if (INTEL_INFO(dev
)->gen
<= 3) {
15784 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
15785 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
15787 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
15788 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
15789 if (INTEL_INFO(dev
)->gen
>= 4) {
15790 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
15791 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
15794 err_printf(m
, "Cursor [%d]:\n", i
);
15795 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
15796 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
15797 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
15800 for (i
= 0; i
< error
->num_transcoders
; i
++) {
15801 err_printf(m
, "CPU transcoder: %s\n",
15802 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
15803 err_printf(m
, " Power: %s\n",
15804 onoff(error
->transcoder
[i
].power_domain_on
));
15805 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
15806 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
15807 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
15808 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
15809 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
15810 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
15811 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);