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 intel_begin_crtc_commit(struct drm_crtc
*, struct drm_crtc_state
*);
112 static void intel_finish_crtc_commit(struct drm_crtc
*, struct drm_crtc_state
*);
113 static void skl_init_scalers(struct drm_device
*dev
, struct intel_crtc
*intel_crtc
,
114 struct intel_crtc_state
*crtc_state
);
115 static void skylake_pfit_enable(struct intel_crtc
*crtc
);
116 static void ironlake_pfit_disable(struct intel_crtc
*crtc
, bool force
);
117 static void ironlake_pfit_enable(struct intel_crtc
*crtc
);
118 static void intel_modeset_setup_hw_state(struct drm_device
*dev
);
119 static void intel_pre_disable_primary_noatomic(struct drm_crtc
*crtc
);
120 static int ilk_max_pixel_rate(struct drm_atomic_state
*state
);
125 } dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
129 int p2_slow
, p2_fast
;
133 /* returns HPLL frequency in kHz */
134 static int valleyview_get_vco(struct drm_i915_private
*dev_priv
)
136 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
138 /* Obtain SKU information */
139 mutex_lock(&dev_priv
->sb_lock
);
140 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
141 CCK_FUSE_HPLL_FREQ_MASK
;
142 mutex_unlock(&dev_priv
->sb_lock
);
144 return vco_freq
[hpll_freq
] * 1000;
147 int vlv_get_cck_clock(struct drm_i915_private
*dev_priv
,
148 const char *name
, u32 reg
, int ref_freq
)
153 mutex_lock(&dev_priv
->sb_lock
);
154 val
= vlv_cck_read(dev_priv
, reg
);
155 mutex_unlock(&dev_priv
->sb_lock
);
157 divider
= val
& CCK_FREQUENCY_VALUES
;
159 WARN((val
& CCK_FREQUENCY_STATUS
) !=
160 (divider
<< CCK_FREQUENCY_STATUS_SHIFT
),
161 "%s change in progress\n", name
);
163 return DIV_ROUND_CLOSEST(ref_freq
<< 1, divider
+ 1);
166 static int vlv_get_cck_clock_hpll(struct drm_i915_private
*dev_priv
,
167 const char *name
, u32 reg
)
169 if (dev_priv
->hpll_freq
== 0)
170 dev_priv
->hpll_freq
= valleyview_get_vco(dev_priv
);
172 return vlv_get_cck_clock(dev_priv
, name
, reg
,
173 dev_priv
->hpll_freq
);
177 intel_pch_rawclk(struct drm_i915_private
*dev_priv
)
179 return (I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
) * 1000;
183 intel_vlv_hrawclk(struct drm_i915_private
*dev_priv
)
185 /* RAWCLK_FREQ_VLV register updated from power well code */
186 return vlv_get_cck_clock_hpll(dev_priv
, "hrawclk",
187 CCK_DISPLAY_REF_CLOCK_CONTROL
);
191 intel_g4x_hrawclk(struct drm_i915_private
*dev_priv
)
195 /* hrawclock is 1/4 the FSB frequency */
196 clkcfg
= I915_READ(CLKCFG
);
197 switch (clkcfg
& CLKCFG_FSB_MASK
) {
206 case CLKCFG_FSB_1067
:
208 case CLKCFG_FSB_1333
:
210 /* these two are just a guess; one of them might be right */
211 case CLKCFG_FSB_1600
:
212 case CLKCFG_FSB_1600_ALT
:
219 void intel_update_rawclk(struct drm_i915_private
*dev_priv
)
221 if (HAS_PCH_SPLIT(dev_priv
))
222 dev_priv
->rawclk_freq
= intel_pch_rawclk(dev_priv
);
223 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
224 dev_priv
->rawclk_freq
= intel_vlv_hrawclk(dev_priv
);
225 else if (IS_G4X(dev_priv
) || IS_PINEVIEW(dev_priv
))
226 dev_priv
->rawclk_freq
= intel_g4x_hrawclk(dev_priv
);
228 return; /* no rawclk on other platforms, or no need to know it */
230 DRM_DEBUG_DRIVER("rawclk rate: %d kHz\n", dev_priv
->rawclk_freq
);
233 static void intel_update_czclk(struct drm_i915_private
*dev_priv
)
235 if (!(IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)))
238 dev_priv
->czclk_freq
= vlv_get_cck_clock_hpll(dev_priv
, "czclk",
239 CCK_CZ_CLOCK_CONTROL
);
241 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv
->czclk_freq
);
244 static inline u32
/* units of 100MHz */
245 intel_fdi_link_freq(struct drm_i915_private
*dev_priv
,
246 const struct intel_crtc_state
*pipe_config
)
248 if (HAS_DDI(dev_priv
))
249 return pipe_config
->port_clock
; /* SPLL */
250 else if (IS_GEN5(dev_priv
))
251 return ((I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2) * 10000;
256 static const struct intel_limit intel_limits_i8xx_dac
= {
257 .dot
= { .min
= 25000, .max
= 350000 },
258 .vco
= { .min
= 908000, .max
= 1512000 },
259 .n
= { .min
= 2, .max
= 16 },
260 .m
= { .min
= 96, .max
= 140 },
261 .m1
= { .min
= 18, .max
= 26 },
262 .m2
= { .min
= 6, .max
= 16 },
263 .p
= { .min
= 4, .max
= 128 },
264 .p1
= { .min
= 2, .max
= 33 },
265 .p2
= { .dot_limit
= 165000,
266 .p2_slow
= 4, .p2_fast
= 2 },
269 static const struct intel_limit intel_limits_i8xx_dvo
= {
270 .dot
= { .min
= 25000, .max
= 350000 },
271 .vco
= { .min
= 908000, .max
= 1512000 },
272 .n
= { .min
= 2, .max
= 16 },
273 .m
= { .min
= 96, .max
= 140 },
274 .m1
= { .min
= 18, .max
= 26 },
275 .m2
= { .min
= 6, .max
= 16 },
276 .p
= { .min
= 4, .max
= 128 },
277 .p1
= { .min
= 2, .max
= 33 },
278 .p2
= { .dot_limit
= 165000,
279 .p2_slow
= 4, .p2_fast
= 4 },
282 static const struct intel_limit intel_limits_i8xx_lvds
= {
283 .dot
= { .min
= 25000, .max
= 350000 },
284 .vco
= { .min
= 908000, .max
= 1512000 },
285 .n
= { .min
= 2, .max
= 16 },
286 .m
= { .min
= 96, .max
= 140 },
287 .m1
= { .min
= 18, .max
= 26 },
288 .m2
= { .min
= 6, .max
= 16 },
289 .p
= { .min
= 4, .max
= 128 },
290 .p1
= { .min
= 1, .max
= 6 },
291 .p2
= { .dot_limit
= 165000,
292 .p2_slow
= 14, .p2_fast
= 7 },
295 static const struct intel_limit intel_limits_i9xx_sdvo
= {
296 .dot
= { .min
= 20000, .max
= 400000 },
297 .vco
= { .min
= 1400000, .max
= 2800000 },
298 .n
= { .min
= 1, .max
= 6 },
299 .m
= { .min
= 70, .max
= 120 },
300 .m1
= { .min
= 8, .max
= 18 },
301 .m2
= { .min
= 3, .max
= 7 },
302 .p
= { .min
= 5, .max
= 80 },
303 .p1
= { .min
= 1, .max
= 8 },
304 .p2
= { .dot_limit
= 200000,
305 .p2_slow
= 10, .p2_fast
= 5 },
308 static const struct intel_limit intel_limits_i9xx_lvds
= {
309 .dot
= { .min
= 20000, .max
= 400000 },
310 .vco
= { .min
= 1400000, .max
= 2800000 },
311 .n
= { .min
= 1, .max
= 6 },
312 .m
= { .min
= 70, .max
= 120 },
313 .m1
= { .min
= 8, .max
= 18 },
314 .m2
= { .min
= 3, .max
= 7 },
315 .p
= { .min
= 7, .max
= 98 },
316 .p1
= { .min
= 1, .max
= 8 },
317 .p2
= { .dot_limit
= 112000,
318 .p2_slow
= 14, .p2_fast
= 7 },
322 static const struct intel_limit intel_limits_g4x_sdvo
= {
323 .dot
= { .min
= 25000, .max
= 270000 },
324 .vco
= { .min
= 1750000, .max
= 3500000},
325 .n
= { .min
= 1, .max
= 4 },
326 .m
= { .min
= 104, .max
= 138 },
327 .m1
= { .min
= 17, .max
= 23 },
328 .m2
= { .min
= 5, .max
= 11 },
329 .p
= { .min
= 10, .max
= 30 },
330 .p1
= { .min
= 1, .max
= 3},
331 .p2
= { .dot_limit
= 270000,
337 static const struct intel_limit intel_limits_g4x_hdmi
= {
338 .dot
= { .min
= 22000, .max
= 400000 },
339 .vco
= { .min
= 1750000, .max
= 3500000},
340 .n
= { .min
= 1, .max
= 4 },
341 .m
= { .min
= 104, .max
= 138 },
342 .m1
= { .min
= 16, .max
= 23 },
343 .m2
= { .min
= 5, .max
= 11 },
344 .p
= { .min
= 5, .max
= 80 },
345 .p1
= { .min
= 1, .max
= 8},
346 .p2
= { .dot_limit
= 165000,
347 .p2_slow
= 10, .p2_fast
= 5 },
350 static const struct intel_limit intel_limits_g4x_single_channel_lvds
= {
351 .dot
= { .min
= 20000, .max
= 115000 },
352 .vco
= { .min
= 1750000, .max
= 3500000 },
353 .n
= { .min
= 1, .max
= 3 },
354 .m
= { .min
= 104, .max
= 138 },
355 .m1
= { .min
= 17, .max
= 23 },
356 .m2
= { .min
= 5, .max
= 11 },
357 .p
= { .min
= 28, .max
= 112 },
358 .p1
= { .min
= 2, .max
= 8 },
359 .p2
= { .dot_limit
= 0,
360 .p2_slow
= 14, .p2_fast
= 14
364 static const struct intel_limit intel_limits_g4x_dual_channel_lvds
= {
365 .dot
= { .min
= 80000, .max
= 224000 },
366 .vco
= { .min
= 1750000, .max
= 3500000 },
367 .n
= { .min
= 1, .max
= 3 },
368 .m
= { .min
= 104, .max
= 138 },
369 .m1
= { .min
= 17, .max
= 23 },
370 .m2
= { .min
= 5, .max
= 11 },
371 .p
= { .min
= 14, .max
= 42 },
372 .p1
= { .min
= 2, .max
= 6 },
373 .p2
= { .dot_limit
= 0,
374 .p2_slow
= 7, .p2_fast
= 7
378 static const struct intel_limit intel_limits_pineview_sdvo
= {
379 .dot
= { .min
= 20000, .max
= 400000},
380 .vco
= { .min
= 1700000, .max
= 3500000 },
381 /* Pineview's Ncounter is a ring counter */
382 .n
= { .min
= 3, .max
= 6 },
383 .m
= { .min
= 2, .max
= 256 },
384 /* Pineview only has one combined m divider, which we treat as m2. */
385 .m1
= { .min
= 0, .max
= 0 },
386 .m2
= { .min
= 0, .max
= 254 },
387 .p
= { .min
= 5, .max
= 80 },
388 .p1
= { .min
= 1, .max
= 8 },
389 .p2
= { .dot_limit
= 200000,
390 .p2_slow
= 10, .p2_fast
= 5 },
393 static const struct intel_limit intel_limits_pineview_lvds
= {
394 .dot
= { .min
= 20000, .max
= 400000 },
395 .vco
= { .min
= 1700000, .max
= 3500000 },
396 .n
= { .min
= 3, .max
= 6 },
397 .m
= { .min
= 2, .max
= 256 },
398 .m1
= { .min
= 0, .max
= 0 },
399 .m2
= { .min
= 0, .max
= 254 },
400 .p
= { .min
= 7, .max
= 112 },
401 .p1
= { .min
= 1, .max
= 8 },
402 .p2
= { .dot_limit
= 112000,
403 .p2_slow
= 14, .p2_fast
= 14 },
406 /* Ironlake / Sandybridge
408 * We calculate clock using (register_value + 2) for N/M1/M2, so here
409 * the range value for them is (actual_value - 2).
411 static const struct intel_limit intel_limits_ironlake_dac
= {
412 .dot
= { .min
= 25000, .max
= 350000 },
413 .vco
= { .min
= 1760000, .max
= 3510000 },
414 .n
= { .min
= 1, .max
= 5 },
415 .m
= { .min
= 79, .max
= 127 },
416 .m1
= { .min
= 12, .max
= 22 },
417 .m2
= { .min
= 5, .max
= 9 },
418 .p
= { .min
= 5, .max
= 80 },
419 .p1
= { .min
= 1, .max
= 8 },
420 .p2
= { .dot_limit
= 225000,
421 .p2_slow
= 10, .p2_fast
= 5 },
424 static const struct intel_limit intel_limits_ironlake_single_lvds
= {
425 .dot
= { .min
= 25000, .max
= 350000 },
426 .vco
= { .min
= 1760000, .max
= 3510000 },
427 .n
= { .min
= 1, .max
= 3 },
428 .m
= { .min
= 79, .max
= 118 },
429 .m1
= { .min
= 12, .max
= 22 },
430 .m2
= { .min
= 5, .max
= 9 },
431 .p
= { .min
= 28, .max
= 112 },
432 .p1
= { .min
= 2, .max
= 8 },
433 .p2
= { .dot_limit
= 225000,
434 .p2_slow
= 14, .p2_fast
= 14 },
437 static const struct intel_limit intel_limits_ironlake_dual_lvds
= {
438 .dot
= { .min
= 25000, .max
= 350000 },
439 .vco
= { .min
= 1760000, .max
= 3510000 },
440 .n
= { .min
= 1, .max
= 3 },
441 .m
= { .min
= 79, .max
= 127 },
442 .m1
= { .min
= 12, .max
= 22 },
443 .m2
= { .min
= 5, .max
= 9 },
444 .p
= { .min
= 14, .max
= 56 },
445 .p1
= { .min
= 2, .max
= 8 },
446 .p2
= { .dot_limit
= 225000,
447 .p2_slow
= 7, .p2_fast
= 7 },
450 /* LVDS 100mhz refclk limits. */
451 static const struct intel_limit intel_limits_ironlake_single_lvds_100m
= {
452 .dot
= { .min
= 25000, .max
= 350000 },
453 .vco
= { .min
= 1760000, .max
= 3510000 },
454 .n
= { .min
= 1, .max
= 2 },
455 .m
= { .min
= 79, .max
= 126 },
456 .m1
= { .min
= 12, .max
= 22 },
457 .m2
= { .min
= 5, .max
= 9 },
458 .p
= { .min
= 28, .max
= 112 },
459 .p1
= { .min
= 2, .max
= 8 },
460 .p2
= { .dot_limit
= 225000,
461 .p2_slow
= 14, .p2_fast
= 14 },
464 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m
= {
465 .dot
= { .min
= 25000, .max
= 350000 },
466 .vco
= { .min
= 1760000, .max
= 3510000 },
467 .n
= { .min
= 1, .max
= 3 },
468 .m
= { .min
= 79, .max
= 126 },
469 .m1
= { .min
= 12, .max
= 22 },
470 .m2
= { .min
= 5, .max
= 9 },
471 .p
= { .min
= 14, .max
= 42 },
472 .p1
= { .min
= 2, .max
= 6 },
473 .p2
= { .dot_limit
= 225000,
474 .p2_slow
= 7, .p2_fast
= 7 },
477 static const struct intel_limit intel_limits_vlv
= {
479 * These are the data rate limits (measured in fast clocks)
480 * since those are the strictest limits we have. The fast
481 * clock and actual rate limits are more relaxed, so checking
482 * them would make no difference.
484 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
485 .vco
= { .min
= 4000000, .max
= 6000000 },
486 .n
= { .min
= 1, .max
= 7 },
487 .m1
= { .min
= 2, .max
= 3 },
488 .m2
= { .min
= 11, .max
= 156 },
489 .p1
= { .min
= 2, .max
= 3 },
490 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
493 static const struct intel_limit intel_limits_chv
= {
495 * These are the data rate limits (measured in fast clocks)
496 * since those are the strictest limits we have. The fast
497 * clock and actual rate limits are more relaxed, so checking
498 * them would make no difference.
500 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
501 .vco
= { .min
= 4800000, .max
= 6480000 },
502 .n
= { .min
= 1, .max
= 1 },
503 .m1
= { .min
= 2, .max
= 2 },
504 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
505 .p1
= { .min
= 2, .max
= 4 },
506 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
509 static const struct intel_limit intel_limits_bxt
= {
510 /* FIXME: find real dot limits */
511 .dot
= { .min
= 0, .max
= INT_MAX
},
512 .vco
= { .min
= 4800000, .max
= 6700000 },
513 .n
= { .min
= 1, .max
= 1 },
514 .m1
= { .min
= 2, .max
= 2 },
515 /* FIXME: find real m2 limits */
516 .m2
= { .min
= 2 << 22, .max
= 255 << 22 },
517 .p1
= { .min
= 2, .max
= 4 },
518 .p2
= { .p2_slow
= 1, .p2_fast
= 20 },
522 needs_modeset(struct drm_crtc_state
*state
)
524 return drm_atomic_crtc_needs_modeset(state
);
528 * Returns whether any output on the specified pipe is of the specified type
530 bool intel_pipe_has_type(struct intel_crtc
*crtc
, enum intel_output_type type
)
532 struct drm_device
*dev
= crtc
->base
.dev
;
533 struct intel_encoder
*encoder
;
535 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
536 if (encoder
->type
== type
)
543 * Returns whether any output on the specified pipe will have the specified
544 * type after a staged modeset is complete, i.e., the same as
545 * intel_pipe_has_type() but looking at encoder->new_crtc instead of
548 static bool intel_pipe_will_have_type(const struct intel_crtc_state
*crtc_state
,
551 struct drm_atomic_state
*state
= crtc_state
->base
.state
;
552 struct drm_connector
*connector
;
553 struct drm_connector_state
*connector_state
;
554 struct intel_encoder
*encoder
;
555 int i
, num_connectors
= 0;
557 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
558 if (connector_state
->crtc
!= crtc_state
->base
.crtc
)
563 encoder
= to_intel_encoder(connector_state
->best_encoder
);
564 if (encoder
->type
== type
)
568 WARN_ON(num_connectors
== 0);
574 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
575 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
576 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
577 * The helpers' return value is the rate of the clock that is fed to the
578 * display engine's pipe which can be the above fast dot clock rate or a
579 * divided-down version of it.
581 /* m1 is reserved as 0 in Pineview, n is a ring counter */
582 static int pnv_calc_dpll_params(int refclk
, struct dpll
*clock
)
584 clock
->m
= clock
->m2
+ 2;
585 clock
->p
= clock
->p1
* clock
->p2
;
586 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
588 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
589 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
594 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
596 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
599 static int i9xx_calc_dpll_params(int refclk
, struct dpll
*clock
)
601 clock
->m
= i9xx_dpll_compute_m(clock
);
602 clock
->p
= clock
->p1
* clock
->p2
;
603 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
605 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
606 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
611 static int vlv_calc_dpll_params(int refclk
, struct dpll
*clock
)
613 clock
->m
= clock
->m1
* clock
->m2
;
614 clock
->p
= clock
->p1
* clock
->p2
;
615 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
617 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
618 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
620 return clock
->dot
/ 5;
623 int chv_calc_dpll_params(int refclk
, struct dpll
*clock
)
625 clock
->m
= clock
->m1
* clock
->m2
;
626 clock
->p
= clock
->p1
* clock
->p2
;
627 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
629 clock
->vco
= DIV_ROUND_CLOSEST_ULL((uint64_t)refclk
* clock
->m
,
631 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
633 return clock
->dot
/ 5;
636 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
638 * Returns whether the given set of divisors are valid for a given refclk with
639 * the given connectors.
642 static bool intel_PLL_is_valid(struct drm_device
*dev
,
643 const struct intel_limit
*limit
,
644 const struct dpll
*clock
)
646 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
647 INTELPllInvalid("n out of range\n");
648 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
649 INTELPllInvalid("p1 out of range\n");
650 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
651 INTELPllInvalid("m2 out of range\n");
652 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
653 INTELPllInvalid("m1 out of range\n");
655 if (!IS_PINEVIEW(dev
) && !IS_VALLEYVIEW(dev
) &&
656 !IS_CHERRYVIEW(dev
) && !IS_BROXTON(dev
))
657 if (clock
->m1
<= clock
->m2
)
658 INTELPllInvalid("m1 <= m2\n");
660 if (!IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
) && !IS_BROXTON(dev
)) {
661 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
662 INTELPllInvalid("p out of range\n");
663 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
664 INTELPllInvalid("m out of range\n");
667 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
668 INTELPllInvalid("vco out of range\n");
669 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
670 * connector, etc., rather than just a single range.
672 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
673 INTELPllInvalid("dot out of range\n");
679 i9xx_select_p2_div(const struct intel_limit
*limit
,
680 const struct intel_crtc_state
*crtc_state
,
683 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
685 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
687 * For LVDS just rely on its current settings for dual-channel.
688 * We haven't figured out how to reliably set up different
689 * single/dual channel state, if we even can.
691 if (intel_is_dual_link_lvds(dev
))
692 return limit
->p2
.p2_fast
;
694 return limit
->p2
.p2_slow
;
696 if (target
< limit
->p2
.dot_limit
)
697 return limit
->p2
.p2_slow
;
699 return limit
->p2
.p2_fast
;
704 * Returns a set of divisors for the desired target clock with the given
705 * refclk, or FALSE. The returned values represent the clock equation:
706 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
708 * Target and reference clocks are specified in kHz.
710 * If match_clock is provided, then best_clock P divider must match the P
711 * divider from @match_clock used for LVDS downclocking.
714 i9xx_find_best_dpll(const struct intel_limit
*limit
,
715 struct intel_crtc_state
*crtc_state
,
716 int target
, int refclk
, struct dpll
*match_clock
,
717 struct dpll
*best_clock
)
719 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
723 memset(best_clock
, 0, sizeof(*best_clock
));
725 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
727 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
729 for (clock
.m2
= limit
->m2
.min
;
730 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
731 if (clock
.m2
>= clock
.m1
)
733 for (clock
.n
= limit
->n
.min
;
734 clock
.n
<= limit
->n
.max
; clock
.n
++) {
735 for (clock
.p1
= limit
->p1
.min
;
736 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
739 i9xx_calc_dpll_params(refclk
, &clock
);
740 if (!intel_PLL_is_valid(dev
, limit
,
744 clock
.p
!= match_clock
->p
)
747 this_err
= abs(clock
.dot
- target
);
748 if (this_err
< err
) {
757 return (err
!= target
);
761 * Returns a set of divisors for the desired target clock with the given
762 * refclk, or FALSE. The returned values represent the clock equation:
763 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
765 * Target and reference clocks are specified in kHz.
767 * If match_clock is provided, then best_clock P divider must match the P
768 * divider from @match_clock used for LVDS downclocking.
771 pnv_find_best_dpll(const struct intel_limit
*limit
,
772 struct intel_crtc_state
*crtc_state
,
773 int target
, int refclk
, struct dpll
*match_clock
,
774 struct dpll
*best_clock
)
776 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
780 memset(best_clock
, 0, sizeof(*best_clock
));
782 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
784 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
786 for (clock
.m2
= limit
->m2
.min
;
787 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
788 for (clock
.n
= limit
->n
.min
;
789 clock
.n
<= limit
->n
.max
; clock
.n
++) {
790 for (clock
.p1
= limit
->p1
.min
;
791 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
794 pnv_calc_dpll_params(refclk
, &clock
);
795 if (!intel_PLL_is_valid(dev
, limit
,
799 clock
.p
!= match_clock
->p
)
802 this_err
= abs(clock
.dot
- target
);
803 if (this_err
< err
) {
812 return (err
!= target
);
816 * Returns a set of divisors for the desired target clock with the given
817 * refclk, or FALSE. The returned values represent the clock equation:
818 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
820 * Target and reference clocks are specified in kHz.
822 * If match_clock is provided, then best_clock P divider must match the P
823 * divider from @match_clock used for LVDS downclocking.
826 g4x_find_best_dpll(const struct intel_limit
*limit
,
827 struct intel_crtc_state
*crtc_state
,
828 int target
, int refclk
, struct dpll
*match_clock
,
829 struct dpll
*best_clock
)
831 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
835 /* approximately equals target * 0.00585 */
836 int err_most
= (target
>> 8) + (target
>> 9);
838 memset(best_clock
, 0, sizeof(*best_clock
));
840 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
842 max_n
= limit
->n
.max
;
843 /* based on hardware requirement, prefer smaller n to precision */
844 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
845 /* based on hardware requirement, prefere larger m1,m2 */
846 for (clock
.m1
= limit
->m1
.max
;
847 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
848 for (clock
.m2
= limit
->m2
.max
;
849 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
850 for (clock
.p1
= limit
->p1
.max
;
851 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
854 i9xx_calc_dpll_params(refclk
, &clock
);
855 if (!intel_PLL_is_valid(dev
, limit
,
859 this_err
= abs(clock
.dot
- target
);
860 if (this_err
< err_most
) {
874 * Check if the calculated PLL configuration is more optimal compared to the
875 * best configuration and error found so far. Return the calculated error.
877 static bool vlv_PLL_is_optimal(struct drm_device
*dev
, int target_freq
,
878 const struct dpll
*calculated_clock
,
879 const struct dpll
*best_clock
,
880 unsigned int best_error_ppm
,
881 unsigned int *error_ppm
)
884 * For CHV ignore the error and consider only the P value.
885 * Prefer a bigger P value based on HW requirements.
887 if (IS_CHERRYVIEW(dev
)) {
890 return calculated_clock
->p
> best_clock
->p
;
893 if (WARN_ON_ONCE(!target_freq
))
896 *error_ppm
= div_u64(1000000ULL *
897 abs(target_freq
- calculated_clock
->dot
),
900 * Prefer a better P value over a better (smaller) error if the error
901 * is small. Ensure this preference for future configurations too by
902 * setting the error to 0.
904 if (*error_ppm
< 100 && calculated_clock
->p
> best_clock
->p
) {
910 return *error_ppm
+ 10 < best_error_ppm
;
914 * Returns a set of divisors for the desired target clock with the given
915 * refclk, or FALSE. The returned values represent the clock equation:
916 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
919 vlv_find_best_dpll(const struct intel_limit
*limit
,
920 struct intel_crtc_state
*crtc_state
,
921 int target
, int refclk
, struct dpll
*match_clock
,
922 struct dpll
*best_clock
)
924 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
925 struct drm_device
*dev
= crtc
->base
.dev
;
927 unsigned int bestppm
= 1000000;
928 /* min update 19.2 MHz */
929 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
932 target
*= 5; /* fast clock */
934 memset(best_clock
, 0, sizeof(*best_clock
));
936 /* based on hardware requirement, prefer smaller n to precision */
937 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
938 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
939 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
940 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
941 clock
.p
= clock
.p1
* clock
.p2
;
942 /* based on hardware requirement, prefer bigger m1,m2 values */
943 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
946 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
949 vlv_calc_dpll_params(refclk
, &clock
);
951 if (!intel_PLL_is_valid(dev
, limit
,
955 if (!vlv_PLL_is_optimal(dev
, target
,
973 * Returns a set of divisors for the desired target clock with the given
974 * refclk, or FALSE. The returned values represent the clock equation:
975 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
978 chv_find_best_dpll(const struct intel_limit
*limit
,
979 struct intel_crtc_state
*crtc_state
,
980 int target
, int refclk
, struct dpll
*match_clock
,
981 struct dpll
*best_clock
)
983 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
984 struct drm_device
*dev
= crtc
->base
.dev
;
985 unsigned int best_error_ppm
;
990 memset(best_clock
, 0, sizeof(*best_clock
));
991 best_error_ppm
= 1000000;
994 * Based on hardware doc, the n always set to 1, and m1 always
995 * set to 2. If requires to support 200Mhz refclk, we need to
996 * revisit this because n may not 1 anymore.
998 clock
.n
= 1, clock
.m1
= 2;
999 target
*= 5; /* fast clock */
1001 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
1002 for (clock
.p2
= limit
->p2
.p2_fast
;
1003 clock
.p2
>= limit
->p2
.p2_slow
;
1004 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
1005 unsigned int error_ppm
;
1007 clock
.p
= clock
.p1
* clock
.p2
;
1009 m2
= DIV_ROUND_CLOSEST_ULL(((uint64_t)target
* clock
.p
*
1010 clock
.n
) << 22, refclk
* clock
.m1
);
1012 if (m2
> INT_MAX
/clock
.m1
)
1017 chv_calc_dpll_params(refclk
, &clock
);
1019 if (!intel_PLL_is_valid(dev
, limit
, &clock
))
1022 if (!vlv_PLL_is_optimal(dev
, target
, &clock
, best_clock
,
1023 best_error_ppm
, &error_ppm
))
1026 *best_clock
= clock
;
1027 best_error_ppm
= error_ppm
;
1035 bool bxt_find_best_dpll(struct intel_crtc_state
*crtc_state
, int target_clock
,
1036 struct dpll
*best_clock
)
1038 int refclk
= 100000;
1039 const struct intel_limit
*limit
= &intel_limits_bxt
;
1041 return chv_find_best_dpll(limit
, crtc_state
,
1042 target_clock
, refclk
, NULL
, best_clock
);
1045 bool intel_crtc_active(struct drm_crtc
*crtc
)
1047 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1049 /* Be paranoid as we can arrive here with only partial
1050 * state retrieved from the hardware during setup.
1052 * We can ditch the adjusted_mode.crtc_clock check as soon
1053 * as Haswell has gained clock readout/fastboot support.
1055 * We can ditch the crtc->primary->fb check as soon as we can
1056 * properly reconstruct framebuffers.
1058 * FIXME: The intel_crtc->active here should be switched to
1059 * crtc->state->active once we have proper CRTC states wired up
1062 return intel_crtc
->active
&& crtc
->primary
->state
->fb
&&
1063 intel_crtc
->config
->base
.adjusted_mode
.crtc_clock
;
1066 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
1069 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1070 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1072 return intel_crtc
->config
->cpu_transcoder
;
1075 static bool pipe_dsl_stopped(struct drm_device
*dev
, enum pipe pipe
)
1077 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1078 i915_reg_t reg
= PIPEDSL(pipe
);
1083 line_mask
= DSL_LINEMASK_GEN2
;
1085 line_mask
= DSL_LINEMASK_GEN3
;
1087 line1
= I915_READ(reg
) & line_mask
;
1089 line2
= I915_READ(reg
) & line_mask
;
1091 return line1
== line2
;
1095 * intel_wait_for_pipe_off - wait for pipe to turn off
1096 * @crtc: crtc whose pipe to wait for
1098 * After disabling a pipe, we can't wait for vblank in the usual way,
1099 * spinning on the vblank interrupt status bit, since we won't actually
1100 * see an interrupt when the pipe is disabled.
1102 * On Gen4 and above:
1103 * wait for the pipe register state bit to turn off
1106 * wait for the display line value to settle (it usually
1107 * ends up stopping at the start of the next frame).
1110 static void intel_wait_for_pipe_off(struct intel_crtc
*crtc
)
1112 struct drm_device
*dev
= crtc
->base
.dev
;
1113 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1114 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1115 enum pipe pipe
= crtc
->pipe
;
1117 if (INTEL_INFO(dev
)->gen
>= 4) {
1118 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
1120 /* Wait for the Pipe State to go off */
1121 if (wait_for((I915_READ(reg
) & I965_PIPECONF_ACTIVE
) == 0,
1123 WARN(1, "pipe_off wait timed out\n");
1125 /* Wait for the display line to settle */
1126 if (wait_for(pipe_dsl_stopped(dev
, pipe
), 100))
1127 WARN(1, "pipe_off wait timed out\n");
1131 /* Only for pre-ILK configs */
1132 void assert_pll(struct drm_i915_private
*dev_priv
,
1133 enum pipe pipe
, bool state
)
1138 val
= I915_READ(DPLL(pipe
));
1139 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1140 I915_STATE_WARN(cur_state
!= state
,
1141 "PLL state assertion failure (expected %s, current %s)\n",
1142 onoff(state
), onoff(cur_state
));
1145 /* XXX: the dsi pll is shared between MIPI DSI ports */
1146 void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1151 mutex_lock(&dev_priv
->sb_lock
);
1152 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1153 mutex_unlock(&dev_priv
->sb_lock
);
1155 cur_state
= val
& DSI_PLL_VCO_EN
;
1156 I915_STATE_WARN(cur_state
!= state
,
1157 "DSI PLL state assertion failure (expected %s, current %s)\n",
1158 onoff(state
), onoff(cur_state
));
1161 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1162 enum pipe pipe
, bool state
)
1165 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1168 if (HAS_DDI(dev_priv
)) {
1169 /* DDI does not have a specific FDI_TX register */
1170 u32 val
= I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder
));
1171 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1173 u32 val
= I915_READ(FDI_TX_CTL(pipe
));
1174 cur_state
= !!(val
& FDI_TX_ENABLE
);
1176 I915_STATE_WARN(cur_state
!= state
,
1177 "FDI TX state assertion failure (expected %s, current %s)\n",
1178 onoff(state
), onoff(cur_state
));
1180 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1181 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1183 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1184 enum pipe pipe
, bool state
)
1189 val
= I915_READ(FDI_RX_CTL(pipe
));
1190 cur_state
= !!(val
& FDI_RX_ENABLE
);
1191 I915_STATE_WARN(cur_state
!= state
,
1192 "FDI RX state assertion failure (expected %s, current %s)\n",
1193 onoff(state
), onoff(cur_state
));
1195 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1196 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1198 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1203 /* ILK FDI PLL is always enabled */
1204 if (IS_GEN5(dev_priv
))
1207 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1208 if (HAS_DDI(dev_priv
))
1211 val
= I915_READ(FDI_TX_CTL(pipe
));
1212 I915_STATE_WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1215 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1216 enum pipe pipe
, bool state
)
1221 val
= I915_READ(FDI_RX_CTL(pipe
));
1222 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1223 I915_STATE_WARN(cur_state
!= state
,
1224 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1225 onoff(state
), onoff(cur_state
));
1228 void assert_panel_unlocked(struct drm_i915_private
*dev_priv
,
1231 struct drm_device
*dev
= dev_priv
->dev
;
1234 enum pipe panel_pipe
= PIPE_A
;
1237 if (WARN_ON(HAS_DDI(dev
)))
1240 if (HAS_PCH_SPLIT(dev
)) {
1243 pp_reg
= PCH_PP_CONTROL
;
1244 port_sel
= I915_READ(PCH_PP_ON_DELAYS
) & PANEL_PORT_SELECT_MASK
;
1246 if (port_sel
== PANEL_PORT_SELECT_LVDS
&&
1247 I915_READ(PCH_LVDS
) & LVDS_PIPEB_SELECT
)
1248 panel_pipe
= PIPE_B
;
1249 /* XXX: else fix for eDP */
1250 } else if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
1251 /* presumably write lock depends on pipe, not port select */
1252 pp_reg
= VLV_PIPE_PP_CONTROL(pipe
);
1255 pp_reg
= PP_CONTROL
;
1256 if (I915_READ(LVDS
) & LVDS_PIPEB_SELECT
)
1257 panel_pipe
= PIPE_B
;
1260 val
= I915_READ(pp_reg
);
1261 if (!(val
& PANEL_POWER_ON
) ||
1262 ((val
& PANEL_UNLOCK_MASK
) == PANEL_UNLOCK_REGS
))
1265 I915_STATE_WARN(panel_pipe
== pipe
&& locked
,
1266 "panel assertion failure, pipe %c regs locked\n",
1270 static void assert_cursor(struct drm_i915_private
*dev_priv
,
1271 enum pipe pipe
, bool state
)
1273 struct drm_device
*dev
= dev_priv
->dev
;
1276 if (IS_845G(dev
) || IS_I865G(dev
))
1277 cur_state
= I915_READ(CURCNTR(PIPE_A
)) & CURSOR_ENABLE
;
1279 cur_state
= I915_READ(CURCNTR(pipe
)) & CURSOR_MODE
;
1281 I915_STATE_WARN(cur_state
!= state
,
1282 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1283 pipe_name(pipe
), onoff(state
), onoff(cur_state
));
1285 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1286 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1288 void assert_pipe(struct drm_i915_private
*dev_priv
,
1289 enum pipe pipe
, bool state
)
1292 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1294 enum intel_display_power_domain power_domain
;
1296 /* if we need the pipe quirk it must be always on */
1297 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1298 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1301 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
1302 if (intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
1303 u32 val
= I915_READ(PIPECONF(cpu_transcoder
));
1304 cur_state
= !!(val
& PIPECONF_ENABLE
);
1306 intel_display_power_put(dev_priv
, power_domain
);
1311 I915_STATE_WARN(cur_state
!= state
,
1312 "pipe %c assertion failure (expected %s, current %s)\n",
1313 pipe_name(pipe
), onoff(state
), onoff(cur_state
));
1316 static void assert_plane(struct drm_i915_private
*dev_priv
,
1317 enum plane plane
, bool state
)
1322 val
= I915_READ(DSPCNTR(plane
));
1323 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1324 I915_STATE_WARN(cur_state
!= state
,
1325 "plane %c assertion failure (expected %s, current %s)\n",
1326 plane_name(plane
), onoff(state
), onoff(cur_state
));
1329 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1330 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1332 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1335 struct drm_device
*dev
= dev_priv
->dev
;
1338 /* Primary planes are fixed to pipes on gen4+ */
1339 if (INTEL_INFO(dev
)->gen
>= 4) {
1340 u32 val
= I915_READ(DSPCNTR(pipe
));
1341 I915_STATE_WARN(val
& DISPLAY_PLANE_ENABLE
,
1342 "plane %c assertion failure, should be disabled but not\n",
1347 /* Need to check both planes against the pipe */
1348 for_each_pipe(dev_priv
, i
) {
1349 u32 val
= I915_READ(DSPCNTR(i
));
1350 enum pipe cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1351 DISPPLANE_SEL_PIPE_SHIFT
;
1352 I915_STATE_WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1353 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1354 plane_name(i
), pipe_name(pipe
));
1358 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1361 struct drm_device
*dev
= dev_priv
->dev
;
1364 if (INTEL_INFO(dev
)->gen
>= 9) {
1365 for_each_sprite(dev_priv
, pipe
, sprite
) {
1366 u32 val
= I915_READ(PLANE_CTL(pipe
, sprite
));
1367 I915_STATE_WARN(val
& PLANE_CTL_ENABLE
,
1368 "plane %d assertion failure, should be off on pipe %c but is still active\n",
1369 sprite
, pipe_name(pipe
));
1371 } else if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
1372 for_each_sprite(dev_priv
, pipe
, sprite
) {
1373 u32 val
= I915_READ(SPCNTR(pipe
, sprite
));
1374 I915_STATE_WARN(val
& SP_ENABLE
,
1375 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1376 sprite_name(pipe
, sprite
), pipe_name(pipe
));
1378 } else if (INTEL_INFO(dev
)->gen
>= 7) {
1379 u32 val
= I915_READ(SPRCTL(pipe
));
1380 I915_STATE_WARN(val
& SPRITE_ENABLE
,
1381 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1382 plane_name(pipe
), pipe_name(pipe
));
1383 } else if (INTEL_INFO(dev
)->gen
>= 5) {
1384 u32 val
= I915_READ(DVSCNTR(pipe
));
1385 I915_STATE_WARN(val
& DVS_ENABLE
,
1386 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1387 plane_name(pipe
), pipe_name(pipe
));
1391 static void assert_vblank_disabled(struct drm_crtc
*crtc
)
1393 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc
) == 0))
1394 drm_crtc_vblank_put(crtc
);
1397 void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1403 val
= I915_READ(PCH_TRANSCONF(pipe
));
1404 enabled
= !!(val
& TRANS_ENABLE
);
1405 I915_STATE_WARN(enabled
,
1406 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1410 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1411 enum pipe pipe
, u32 port_sel
, u32 val
)
1413 if ((val
& DP_PORT_EN
) == 0)
1416 if (HAS_PCH_CPT(dev_priv
)) {
1417 u32 trans_dp_ctl
= I915_READ(TRANS_DP_CTL(pipe
));
1418 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1420 } else if (IS_CHERRYVIEW(dev_priv
)) {
1421 if ((val
& DP_PIPE_MASK_CHV
) != DP_PIPE_SELECT_CHV(pipe
))
1424 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1430 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1431 enum pipe pipe
, u32 val
)
1433 if ((val
& SDVO_ENABLE
) == 0)
1436 if (HAS_PCH_CPT(dev_priv
)) {
1437 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1439 } else if (IS_CHERRYVIEW(dev_priv
)) {
1440 if ((val
& SDVO_PIPE_SEL_MASK_CHV
) != SDVO_PIPE_SEL_CHV(pipe
))
1443 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1449 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1450 enum pipe pipe
, u32 val
)
1452 if ((val
& LVDS_PORT_EN
) == 0)
1455 if (HAS_PCH_CPT(dev_priv
)) {
1456 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1459 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1465 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1466 enum pipe pipe
, u32 val
)
1468 if ((val
& ADPA_DAC_ENABLE
) == 0)
1470 if (HAS_PCH_CPT(dev_priv
)) {
1471 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1474 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1480 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1481 enum pipe pipe
, i915_reg_t reg
,
1484 u32 val
= I915_READ(reg
);
1485 I915_STATE_WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1486 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1487 i915_mmio_reg_offset(reg
), pipe_name(pipe
));
1489 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
) && (val
& DP_PORT_EN
) == 0
1490 && (val
& DP_PIPEB_SELECT
),
1491 "IBX PCH dp port still using transcoder B\n");
1494 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1495 enum pipe pipe
, i915_reg_t reg
)
1497 u32 val
= I915_READ(reg
);
1498 I915_STATE_WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1499 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1500 i915_mmio_reg_offset(reg
), pipe_name(pipe
));
1502 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
) && (val
& SDVO_ENABLE
) == 0
1503 && (val
& SDVO_PIPE_B_SELECT
),
1504 "IBX PCH hdmi port still using transcoder B\n");
1507 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1512 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1513 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1514 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1516 val
= I915_READ(PCH_ADPA
);
1517 I915_STATE_WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1518 "PCH VGA enabled on transcoder %c, should be disabled\n",
1521 val
= I915_READ(PCH_LVDS
);
1522 I915_STATE_WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1523 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1526 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1527 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1528 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1531 static void _vlv_enable_pll(struct intel_crtc
*crtc
,
1532 const struct intel_crtc_state
*pipe_config
)
1534 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1535 enum pipe pipe
= crtc
->pipe
;
1537 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1538 POSTING_READ(DPLL(pipe
));
1541 if (wait_for(((I915_READ(DPLL(pipe
)) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1542 DRM_ERROR("DPLL %d failed to lock\n", pipe
);
1545 static void vlv_enable_pll(struct intel_crtc
*crtc
,
1546 const struct intel_crtc_state
*pipe_config
)
1548 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1549 enum pipe pipe
= crtc
->pipe
;
1551 assert_pipe_disabled(dev_priv
, pipe
);
1553 /* PLL is protected by panel, make sure we can write it */
1554 assert_panel_unlocked(dev_priv
, pipe
);
1556 if (pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
)
1557 _vlv_enable_pll(crtc
, pipe_config
);
1559 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1560 POSTING_READ(DPLL_MD(pipe
));
1564 static void _chv_enable_pll(struct intel_crtc
*crtc
,
1565 const struct intel_crtc_state
*pipe_config
)
1567 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1568 enum pipe pipe
= crtc
->pipe
;
1569 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1572 mutex_lock(&dev_priv
->sb_lock
);
1574 /* Enable back the 10bit clock to display controller */
1575 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1576 tmp
|= DPIO_DCLKP_EN
;
1577 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), tmp
);
1579 mutex_unlock(&dev_priv
->sb_lock
);
1582 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1587 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1589 /* Check PLL is locked */
1590 if (wait_for(((I915_READ(DPLL(pipe
)) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1591 DRM_ERROR("PLL %d failed to lock\n", pipe
);
1594 static void chv_enable_pll(struct intel_crtc
*crtc
,
1595 const struct intel_crtc_state
*pipe_config
)
1597 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1598 enum pipe pipe
= crtc
->pipe
;
1600 assert_pipe_disabled(dev_priv
, pipe
);
1602 /* PLL is protected by panel, make sure we can write it */
1603 assert_panel_unlocked(dev_priv
, pipe
);
1605 if (pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
)
1606 _chv_enable_pll(crtc
, pipe_config
);
1608 if (pipe
!= PIPE_A
) {
1610 * WaPixelRepeatModeFixForC0:chv
1612 * DPLLCMD is AWOL. Use chicken bits to propagate
1613 * the value from DPLLBMD to either pipe B or C.
1615 I915_WRITE(CBR4_VLV
, pipe
== PIPE_B
? CBR_DPLLBMD_PIPE_B
: CBR_DPLLBMD_PIPE_C
);
1616 I915_WRITE(DPLL_MD(PIPE_B
), pipe_config
->dpll_hw_state
.dpll_md
);
1617 I915_WRITE(CBR4_VLV
, 0);
1618 dev_priv
->chv_dpll_md
[pipe
] = pipe_config
->dpll_hw_state
.dpll_md
;
1621 * DPLLB VGA mode also seems to cause problems.
1622 * We should always have it disabled.
1624 WARN_ON((I915_READ(DPLL(PIPE_B
)) & DPLL_VGA_MODE_DIS
) == 0);
1626 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1627 POSTING_READ(DPLL_MD(pipe
));
1631 static int intel_num_dvo_pipes(struct drm_device
*dev
)
1633 struct intel_crtc
*crtc
;
1636 for_each_intel_crtc(dev
, crtc
)
1637 count
+= crtc
->base
.state
->active
&&
1638 intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
);
1643 static void i9xx_enable_pll(struct intel_crtc
*crtc
)
1645 struct drm_device
*dev
= crtc
->base
.dev
;
1646 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1647 i915_reg_t reg
= DPLL(crtc
->pipe
);
1648 u32 dpll
= crtc
->config
->dpll_hw_state
.dpll
;
1650 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1652 /* PLL is protected by panel, make sure we can write it */
1653 if (IS_MOBILE(dev
) && !IS_I830(dev
))
1654 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1656 /* Enable DVO 2x clock on both PLLs if necessary */
1657 if (IS_I830(dev
) && intel_num_dvo_pipes(dev
) > 0) {
1659 * It appears to be important that we don't enable this
1660 * for the current pipe before otherwise configuring the
1661 * PLL. No idea how this should be handled if multiple
1662 * DVO outputs are enabled simultaneosly.
1664 dpll
|= DPLL_DVO_2X_MODE
;
1665 I915_WRITE(DPLL(!crtc
->pipe
),
1666 I915_READ(DPLL(!crtc
->pipe
)) | DPLL_DVO_2X_MODE
);
1670 * Apparently we need to have VGA mode enabled prior to changing
1671 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1672 * dividers, even though the register value does change.
1676 I915_WRITE(reg
, dpll
);
1678 /* Wait for the clocks to stabilize. */
1682 if (INTEL_INFO(dev
)->gen
>= 4) {
1683 I915_WRITE(DPLL_MD(crtc
->pipe
),
1684 crtc
->config
->dpll_hw_state
.dpll_md
);
1686 /* The pixel multiplier can only be updated once the
1687 * DPLL is enabled and the clocks are stable.
1689 * So write it again.
1691 I915_WRITE(reg
, dpll
);
1694 /* We do this three times for luck */
1695 I915_WRITE(reg
, dpll
);
1697 udelay(150); /* wait for warmup */
1698 I915_WRITE(reg
, dpll
);
1700 udelay(150); /* wait for warmup */
1701 I915_WRITE(reg
, dpll
);
1703 udelay(150); /* wait for warmup */
1707 * i9xx_disable_pll - disable a PLL
1708 * @dev_priv: i915 private structure
1709 * @pipe: pipe PLL to disable
1711 * Disable the PLL for @pipe, making sure the pipe is off first.
1713 * Note! This is for pre-ILK only.
1715 static void i9xx_disable_pll(struct intel_crtc
*crtc
)
1717 struct drm_device
*dev
= crtc
->base
.dev
;
1718 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1719 enum pipe pipe
= crtc
->pipe
;
1721 /* Disable DVO 2x clock on both PLLs if necessary */
1723 intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
) &&
1724 !intel_num_dvo_pipes(dev
)) {
1725 I915_WRITE(DPLL(PIPE_B
),
1726 I915_READ(DPLL(PIPE_B
)) & ~DPLL_DVO_2X_MODE
);
1727 I915_WRITE(DPLL(PIPE_A
),
1728 I915_READ(DPLL(PIPE_A
)) & ~DPLL_DVO_2X_MODE
);
1731 /* Don't disable pipe or pipe PLLs if needed */
1732 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1733 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1736 /* Make sure the pipe isn't still relying on us */
1737 assert_pipe_disabled(dev_priv
, pipe
);
1739 I915_WRITE(DPLL(pipe
), DPLL_VGA_MODE_DIS
);
1740 POSTING_READ(DPLL(pipe
));
1743 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1747 /* Make sure the pipe isn't still relying on us */
1748 assert_pipe_disabled(dev_priv
, pipe
);
1750 val
= DPLL_INTEGRATED_REF_CLK_VLV
|
1751 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1753 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1755 I915_WRITE(DPLL(pipe
), val
);
1756 POSTING_READ(DPLL(pipe
));
1759 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1761 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1764 /* Make sure the pipe isn't still relying on us */
1765 assert_pipe_disabled(dev_priv
, pipe
);
1767 val
= DPLL_SSC_REF_CLK_CHV
|
1768 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1770 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1772 I915_WRITE(DPLL(pipe
), val
);
1773 POSTING_READ(DPLL(pipe
));
1775 mutex_lock(&dev_priv
->sb_lock
);
1777 /* Disable 10bit clock to display controller */
1778 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1779 val
&= ~DPIO_DCLKP_EN
;
1780 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1782 mutex_unlock(&dev_priv
->sb_lock
);
1785 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1786 struct intel_digital_port
*dport
,
1787 unsigned int expected_mask
)
1790 i915_reg_t dpll_reg
;
1792 switch (dport
->port
) {
1794 port_mask
= DPLL_PORTB_READY_MASK
;
1798 port_mask
= DPLL_PORTC_READY_MASK
;
1800 expected_mask
<<= 4;
1803 port_mask
= DPLL_PORTD_READY_MASK
;
1804 dpll_reg
= DPIO_PHY_STATUS
;
1810 if (wait_for((I915_READ(dpll_reg
) & port_mask
) == expected_mask
, 1000))
1811 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1812 port_name(dport
->port
), I915_READ(dpll_reg
) & port_mask
, expected_mask
);
1815 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1818 struct drm_device
*dev
= dev_priv
->dev
;
1819 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1820 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1822 uint32_t val
, pipeconf_val
;
1824 /* Make sure PCH DPLL is enabled */
1825 assert_shared_dpll_enabled(dev_priv
, intel_crtc
->config
->shared_dpll
);
1827 /* FDI must be feeding us bits for PCH ports */
1828 assert_fdi_tx_enabled(dev_priv
, pipe
);
1829 assert_fdi_rx_enabled(dev_priv
, pipe
);
1831 if (HAS_PCH_CPT(dev
)) {
1832 /* Workaround: Set the timing override bit before enabling the
1833 * pch transcoder. */
1834 reg
= TRANS_CHICKEN2(pipe
);
1835 val
= I915_READ(reg
);
1836 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1837 I915_WRITE(reg
, val
);
1840 reg
= PCH_TRANSCONF(pipe
);
1841 val
= I915_READ(reg
);
1842 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1844 if (HAS_PCH_IBX(dev_priv
)) {
1846 * Make the BPC in transcoder be consistent with
1847 * that in pipeconf reg. For HDMI we must use 8bpc
1848 * here for both 8bpc and 12bpc.
1850 val
&= ~PIPECONF_BPC_MASK
;
1851 if (intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_HDMI
))
1852 val
|= PIPECONF_8BPC
;
1854 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
1857 val
&= ~TRANS_INTERLACE_MASK
;
1858 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
1859 if (HAS_PCH_IBX(dev_priv
) &&
1860 intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
1861 val
|= TRANS_LEGACY_INTERLACED_ILK
;
1863 val
|= TRANS_INTERLACED
;
1865 val
|= TRANS_PROGRESSIVE
;
1867 I915_WRITE(reg
, val
| TRANS_ENABLE
);
1868 if (wait_for(I915_READ(reg
) & TRANS_STATE_ENABLE
, 100))
1869 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
1872 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1873 enum transcoder cpu_transcoder
)
1875 u32 val
, pipeconf_val
;
1877 /* FDI must be feeding us bits for PCH ports */
1878 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
1879 assert_fdi_rx_enabled(dev_priv
, TRANSCODER_A
);
1881 /* Workaround: set timing override bit. */
1882 val
= I915_READ(TRANS_CHICKEN2(PIPE_A
));
1883 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1884 I915_WRITE(TRANS_CHICKEN2(PIPE_A
), val
);
1887 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
1889 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
1890 PIPECONF_INTERLACED_ILK
)
1891 val
|= TRANS_INTERLACED
;
1893 val
|= TRANS_PROGRESSIVE
;
1895 I915_WRITE(LPT_TRANSCONF
, val
);
1896 if (wait_for(I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
, 100))
1897 DRM_ERROR("Failed to enable PCH transcoder\n");
1900 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1903 struct drm_device
*dev
= dev_priv
->dev
;
1907 /* FDI relies on the transcoder */
1908 assert_fdi_tx_disabled(dev_priv
, pipe
);
1909 assert_fdi_rx_disabled(dev_priv
, pipe
);
1911 /* Ports must be off as well */
1912 assert_pch_ports_disabled(dev_priv
, pipe
);
1914 reg
= PCH_TRANSCONF(pipe
);
1915 val
= I915_READ(reg
);
1916 val
&= ~TRANS_ENABLE
;
1917 I915_WRITE(reg
, val
);
1918 /* wait for PCH transcoder off, transcoder state */
1919 if (wait_for((I915_READ(reg
) & TRANS_STATE_ENABLE
) == 0, 50))
1920 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
1922 if (HAS_PCH_CPT(dev
)) {
1923 /* Workaround: Clear the timing override chicken bit again. */
1924 reg
= TRANS_CHICKEN2(pipe
);
1925 val
= I915_READ(reg
);
1926 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1927 I915_WRITE(reg
, val
);
1931 static void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
1935 val
= I915_READ(LPT_TRANSCONF
);
1936 val
&= ~TRANS_ENABLE
;
1937 I915_WRITE(LPT_TRANSCONF
, val
);
1938 /* wait for PCH transcoder off, transcoder state */
1939 if (wait_for((I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
) == 0, 50))
1940 DRM_ERROR("Failed to disable PCH transcoder\n");
1942 /* Workaround: clear timing override bit. */
1943 val
= I915_READ(TRANS_CHICKEN2(PIPE_A
));
1944 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1945 I915_WRITE(TRANS_CHICKEN2(PIPE_A
), val
);
1949 * intel_enable_pipe - enable a pipe, asserting requirements
1950 * @crtc: crtc responsible for the pipe
1952 * Enable @crtc's pipe, making sure that various hardware specific requirements
1953 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
1955 static void intel_enable_pipe(struct intel_crtc
*crtc
)
1957 struct drm_device
*dev
= crtc
->base
.dev
;
1958 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1959 enum pipe pipe
= crtc
->pipe
;
1960 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1961 enum pipe pch_transcoder
;
1965 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe
));
1967 assert_planes_disabled(dev_priv
, pipe
);
1968 assert_cursor_disabled(dev_priv
, pipe
);
1969 assert_sprites_disabled(dev_priv
, pipe
);
1971 if (HAS_PCH_LPT(dev_priv
))
1972 pch_transcoder
= TRANSCODER_A
;
1974 pch_transcoder
= pipe
;
1977 * A pipe without a PLL won't actually be able to drive bits from
1978 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1981 if (HAS_GMCH_DISPLAY(dev_priv
))
1982 if (crtc
->config
->has_dsi_encoder
)
1983 assert_dsi_pll_enabled(dev_priv
);
1985 assert_pll_enabled(dev_priv
, pipe
);
1987 if (crtc
->config
->has_pch_encoder
) {
1988 /* if driving the PCH, we need FDI enabled */
1989 assert_fdi_rx_pll_enabled(dev_priv
, pch_transcoder
);
1990 assert_fdi_tx_pll_enabled(dev_priv
,
1991 (enum pipe
) cpu_transcoder
);
1993 /* FIXME: assert CPU port conditions for SNB+ */
1996 reg
= PIPECONF(cpu_transcoder
);
1997 val
= I915_READ(reg
);
1998 if (val
& PIPECONF_ENABLE
) {
1999 WARN_ON(!((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
2000 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
)));
2004 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
2008 * Until the pipe starts DSL will read as 0, which would cause
2009 * an apparent vblank timestamp jump, which messes up also the
2010 * frame count when it's derived from the timestamps. So let's
2011 * wait for the pipe to start properly before we call
2012 * drm_crtc_vblank_on()
2014 if (dev
->max_vblank_count
== 0 &&
2015 wait_for(intel_get_crtc_scanline(crtc
) != crtc
->scanline_offset
, 50))
2016 DRM_ERROR("pipe %c didn't start\n", pipe_name(pipe
));
2020 * intel_disable_pipe - disable a pipe, asserting requirements
2021 * @crtc: crtc whose pipes is to be disabled
2023 * Disable the pipe of @crtc, making sure that various hardware
2024 * specific requirements are met, if applicable, e.g. plane
2025 * disabled, panel fitter off, etc.
2027 * Will wait until the pipe has shut down before returning.
2029 static void intel_disable_pipe(struct intel_crtc
*crtc
)
2031 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
2032 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
2033 enum pipe pipe
= crtc
->pipe
;
2037 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe
));
2040 * Make sure planes won't keep trying to pump pixels to us,
2041 * or we might hang the display.
2043 assert_planes_disabled(dev_priv
, pipe
);
2044 assert_cursor_disabled(dev_priv
, pipe
);
2045 assert_sprites_disabled(dev_priv
, pipe
);
2047 reg
= PIPECONF(cpu_transcoder
);
2048 val
= I915_READ(reg
);
2049 if ((val
& PIPECONF_ENABLE
) == 0)
2053 * Double wide has implications for planes
2054 * so best keep it disabled when not needed.
2056 if (crtc
->config
->double_wide
)
2057 val
&= ~PIPECONF_DOUBLE_WIDE
;
2059 /* Don't disable pipe or pipe PLLs if needed */
2060 if (!(pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) &&
2061 !(pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
2062 val
&= ~PIPECONF_ENABLE
;
2064 I915_WRITE(reg
, val
);
2065 if ((val
& PIPECONF_ENABLE
) == 0)
2066 intel_wait_for_pipe_off(crtc
);
2069 static bool need_vtd_wa(struct drm_device
*dev
)
2071 #ifdef CONFIG_INTEL_IOMMU
2072 if (INTEL_INFO(dev
)->gen
>= 6 && intel_iommu_gfx_mapped
)
2078 static unsigned int intel_tile_size(const struct drm_i915_private
*dev_priv
)
2080 return IS_GEN2(dev_priv
) ? 2048 : 4096;
2083 static unsigned int intel_tile_width_bytes(const struct drm_i915_private
*dev_priv
,
2084 uint64_t fb_modifier
, unsigned int cpp
)
2086 switch (fb_modifier
) {
2087 case DRM_FORMAT_MOD_NONE
:
2089 case I915_FORMAT_MOD_X_TILED
:
2090 if (IS_GEN2(dev_priv
))
2094 case I915_FORMAT_MOD_Y_TILED
:
2095 if (IS_GEN2(dev_priv
) || HAS_128_BYTE_Y_TILING(dev_priv
))
2099 case I915_FORMAT_MOD_Yf_TILED
:
2115 MISSING_CASE(fb_modifier
);
2120 unsigned int intel_tile_height(const struct drm_i915_private
*dev_priv
,
2121 uint64_t fb_modifier
, unsigned int cpp
)
2123 if (fb_modifier
== DRM_FORMAT_MOD_NONE
)
2126 return intel_tile_size(dev_priv
) /
2127 intel_tile_width_bytes(dev_priv
, fb_modifier
, cpp
);
2130 /* Return the tile dimensions in pixel units */
2131 static void intel_tile_dims(const struct drm_i915_private
*dev_priv
,
2132 unsigned int *tile_width
,
2133 unsigned int *tile_height
,
2134 uint64_t fb_modifier
,
2137 unsigned int tile_width_bytes
=
2138 intel_tile_width_bytes(dev_priv
, fb_modifier
, cpp
);
2140 *tile_width
= tile_width_bytes
/ cpp
;
2141 *tile_height
= intel_tile_size(dev_priv
) / tile_width_bytes
;
2145 intel_fb_align_height(struct drm_device
*dev
, unsigned int height
,
2146 uint32_t pixel_format
, uint64_t fb_modifier
)
2148 unsigned int cpp
= drm_format_plane_cpp(pixel_format
, 0);
2149 unsigned int tile_height
= intel_tile_height(to_i915(dev
), fb_modifier
, cpp
);
2151 return ALIGN(height
, tile_height
);
2154 unsigned int intel_rotation_info_size(const struct intel_rotation_info
*rot_info
)
2156 unsigned int size
= 0;
2159 for (i
= 0 ; i
< ARRAY_SIZE(rot_info
->plane
); i
++)
2160 size
+= rot_info
->plane
[i
].width
* rot_info
->plane
[i
].height
;
2166 intel_fill_fb_ggtt_view(struct i915_ggtt_view
*view
,
2167 const struct drm_framebuffer
*fb
,
2168 unsigned int rotation
)
2170 if (intel_rotation_90_or_270(rotation
)) {
2171 *view
= i915_ggtt_view_rotated
;
2172 view
->params
.rotated
= to_intel_framebuffer(fb
)->rot_info
;
2174 *view
= i915_ggtt_view_normal
;
2179 intel_fill_fb_info(struct drm_i915_private
*dev_priv
,
2180 struct drm_framebuffer
*fb
)
2182 struct intel_rotation_info
*info
= &to_intel_framebuffer(fb
)->rot_info
;
2183 unsigned int tile_size
, tile_width
, tile_height
, cpp
;
2185 tile_size
= intel_tile_size(dev_priv
);
2187 cpp
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2188 intel_tile_dims(dev_priv
, &tile_width
, &tile_height
,
2189 fb
->modifier
[0], cpp
);
2191 info
->plane
[0].width
= DIV_ROUND_UP(fb
->pitches
[0], tile_width
* cpp
);
2192 info
->plane
[0].height
= DIV_ROUND_UP(fb
->height
, tile_height
);
2194 if (info
->pixel_format
== DRM_FORMAT_NV12
) {
2195 cpp
= drm_format_plane_cpp(fb
->pixel_format
, 1);
2196 intel_tile_dims(dev_priv
, &tile_width
, &tile_height
,
2197 fb
->modifier
[1], cpp
);
2199 info
->uv_offset
= fb
->offsets
[1];
2200 info
->plane
[1].width
= DIV_ROUND_UP(fb
->pitches
[1], tile_width
* cpp
);
2201 info
->plane
[1].height
= DIV_ROUND_UP(fb
->height
/ 2, tile_height
);
2205 static unsigned int intel_linear_alignment(const struct drm_i915_private
*dev_priv
)
2207 if (INTEL_INFO(dev_priv
)->gen
>= 9)
2209 else if (IS_BROADWATER(dev_priv
) || IS_CRESTLINE(dev_priv
) ||
2210 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
2212 else if (INTEL_INFO(dev_priv
)->gen
>= 4)
2218 static unsigned int intel_surf_alignment(const struct drm_i915_private
*dev_priv
,
2219 uint64_t fb_modifier
)
2221 switch (fb_modifier
) {
2222 case DRM_FORMAT_MOD_NONE
:
2223 return intel_linear_alignment(dev_priv
);
2224 case I915_FORMAT_MOD_X_TILED
:
2225 if (INTEL_INFO(dev_priv
)->gen
>= 9)
2228 case I915_FORMAT_MOD_Y_TILED
:
2229 case I915_FORMAT_MOD_Yf_TILED
:
2230 return 1 * 1024 * 1024;
2232 MISSING_CASE(fb_modifier
);
2238 intel_pin_and_fence_fb_obj(struct drm_framebuffer
*fb
,
2239 unsigned int rotation
)
2241 struct drm_device
*dev
= fb
->dev
;
2242 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2243 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2244 struct i915_ggtt_view view
;
2248 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
2250 alignment
= intel_surf_alignment(dev_priv
, fb
->modifier
[0]);
2252 intel_fill_fb_ggtt_view(&view
, fb
, rotation
);
2254 /* Note that the w/a also requires 64 PTE of padding following the
2255 * bo. We currently fill all unused PTE with the shadow page and so
2256 * we should always have valid PTE following the scanout preventing
2259 if (need_vtd_wa(dev
) && alignment
< 256 * 1024)
2260 alignment
= 256 * 1024;
2263 * Global gtt pte registers are special registers which actually forward
2264 * writes to a chunk of system memory. Which means that there is no risk
2265 * that the register values disappear as soon as we call
2266 * intel_runtime_pm_put(), so it is correct to wrap only the
2267 * pin/unpin/fence and not more.
2269 intel_runtime_pm_get(dev_priv
);
2271 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
,
2276 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2277 * fence, whereas 965+ only requires a fence if using
2278 * framebuffer compression. For simplicity, we always install
2279 * a fence as the cost is not that onerous.
2281 if (view
.type
== I915_GGTT_VIEW_NORMAL
) {
2282 ret
= i915_gem_object_get_fence(obj
);
2283 if (ret
== -EDEADLK
) {
2285 * -EDEADLK means there are no free fences
2288 * This is propagated to atomic, but it uses
2289 * -EDEADLK to force a locking recovery, so
2290 * change the returned error to -EBUSY.
2297 i915_gem_object_pin_fence(obj
);
2300 intel_runtime_pm_put(dev_priv
);
2304 i915_gem_object_unpin_from_display_plane(obj
, &view
);
2306 intel_runtime_pm_put(dev_priv
);
2310 void intel_unpin_fb_obj(struct drm_framebuffer
*fb
, unsigned int rotation
)
2312 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2313 struct i915_ggtt_view view
;
2315 WARN_ON(!mutex_is_locked(&obj
->base
.dev
->struct_mutex
));
2317 intel_fill_fb_ggtt_view(&view
, fb
, rotation
);
2319 if (view
.type
== I915_GGTT_VIEW_NORMAL
)
2320 i915_gem_object_unpin_fence(obj
);
2322 i915_gem_object_unpin_from_display_plane(obj
, &view
);
2326 * Adjust the tile offset by moving the difference into
2329 * Input tile dimensions and pitch must already be
2330 * rotated to match x and y, and in pixel units.
2332 static u32
intel_adjust_tile_offset(int *x
, int *y
,
2333 unsigned int tile_width
,
2334 unsigned int tile_height
,
2335 unsigned int tile_size
,
2336 unsigned int pitch_tiles
,
2342 WARN_ON(old_offset
& (tile_size
- 1));
2343 WARN_ON(new_offset
& (tile_size
- 1));
2344 WARN_ON(new_offset
> old_offset
);
2346 tiles
= (old_offset
- new_offset
) / tile_size
;
2348 *y
+= tiles
/ pitch_tiles
* tile_height
;
2349 *x
+= tiles
% pitch_tiles
* tile_width
;
2355 * Computes the linear offset to the base tile and adjusts
2356 * x, y. bytes per pixel is assumed to be a power-of-two.
2358 * In the 90/270 rotated case, x and y are assumed
2359 * to be already rotated to match the rotated GTT view, and
2360 * pitch is the tile_height aligned framebuffer height.
2362 u32
intel_compute_tile_offset(int *x
, int *y
,
2363 const struct drm_framebuffer
*fb
, int plane
,
2365 unsigned int rotation
)
2367 const struct drm_i915_private
*dev_priv
= to_i915(fb
->dev
);
2368 uint64_t fb_modifier
= fb
->modifier
[plane
];
2369 unsigned int cpp
= drm_format_plane_cpp(fb
->pixel_format
, plane
);
2370 u32 offset
, offset_aligned
, alignment
;
2372 alignment
= intel_surf_alignment(dev_priv
, fb_modifier
);
2376 if (fb_modifier
!= DRM_FORMAT_MOD_NONE
) {
2377 unsigned int tile_size
, tile_width
, tile_height
;
2378 unsigned int tile_rows
, tiles
, pitch_tiles
;
2380 tile_size
= intel_tile_size(dev_priv
);
2381 intel_tile_dims(dev_priv
, &tile_width
, &tile_height
,
2384 if (intel_rotation_90_or_270(rotation
)) {
2385 pitch_tiles
= pitch
/ tile_height
;
2386 swap(tile_width
, tile_height
);
2388 pitch_tiles
= pitch
/ (tile_width
* cpp
);
2391 tile_rows
= *y
/ tile_height
;
2394 tiles
= *x
/ tile_width
;
2397 offset
= (tile_rows
* pitch_tiles
+ tiles
) * tile_size
;
2398 offset_aligned
= offset
& ~alignment
;
2400 intel_adjust_tile_offset(x
, y
, tile_width
, tile_height
,
2401 tile_size
, pitch_tiles
,
2402 offset
, offset_aligned
);
2404 offset
= *y
* pitch
+ *x
* cpp
;
2405 offset_aligned
= offset
& ~alignment
;
2407 *y
= (offset
& alignment
) / pitch
;
2408 *x
= ((offset
& alignment
) - *y
* pitch
) / cpp
;
2411 return offset_aligned
;
2414 static int i9xx_format_to_fourcc(int format
)
2417 case DISPPLANE_8BPP
:
2418 return DRM_FORMAT_C8
;
2419 case DISPPLANE_BGRX555
:
2420 return DRM_FORMAT_XRGB1555
;
2421 case DISPPLANE_BGRX565
:
2422 return DRM_FORMAT_RGB565
;
2424 case DISPPLANE_BGRX888
:
2425 return DRM_FORMAT_XRGB8888
;
2426 case DISPPLANE_RGBX888
:
2427 return DRM_FORMAT_XBGR8888
;
2428 case DISPPLANE_BGRX101010
:
2429 return DRM_FORMAT_XRGB2101010
;
2430 case DISPPLANE_RGBX101010
:
2431 return DRM_FORMAT_XBGR2101010
;
2435 static int skl_format_to_fourcc(int format
, bool rgb_order
, bool alpha
)
2438 case PLANE_CTL_FORMAT_RGB_565
:
2439 return DRM_FORMAT_RGB565
;
2441 case PLANE_CTL_FORMAT_XRGB_8888
:
2444 return DRM_FORMAT_ABGR8888
;
2446 return DRM_FORMAT_XBGR8888
;
2449 return DRM_FORMAT_ARGB8888
;
2451 return DRM_FORMAT_XRGB8888
;
2453 case PLANE_CTL_FORMAT_XRGB_2101010
:
2455 return DRM_FORMAT_XBGR2101010
;
2457 return DRM_FORMAT_XRGB2101010
;
2462 intel_alloc_initial_plane_obj(struct intel_crtc
*crtc
,
2463 struct intel_initial_plane_config
*plane_config
)
2465 struct drm_device
*dev
= crtc
->base
.dev
;
2466 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2467 struct i915_ggtt
*ggtt
= &dev_priv
->ggtt
;
2468 struct drm_i915_gem_object
*obj
= NULL
;
2469 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2470 struct drm_framebuffer
*fb
= &plane_config
->fb
->base
;
2471 u32 base_aligned
= round_down(plane_config
->base
, PAGE_SIZE
);
2472 u32 size_aligned
= round_up(plane_config
->base
+ plane_config
->size
,
2475 size_aligned
-= base_aligned
;
2477 if (plane_config
->size
== 0)
2480 /* If the FB is too big, just don't use it since fbdev is not very
2481 * important and we should probably use that space with FBC or other
2483 if (size_aligned
* 2 > ggtt
->stolen_usable_size
)
2486 mutex_lock(&dev
->struct_mutex
);
2488 obj
= i915_gem_object_create_stolen_for_preallocated(dev
,
2493 mutex_unlock(&dev
->struct_mutex
);
2497 obj
->tiling_mode
= plane_config
->tiling
;
2498 if (obj
->tiling_mode
== I915_TILING_X
)
2499 obj
->stride
= fb
->pitches
[0];
2501 mode_cmd
.pixel_format
= fb
->pixel_format
;
2502 mode_cmd
.width
= fb
->width
;
2503 mode_cmd
.height
= fb
->height
;
2504 mode_cmd
.pitches
[0] = fb
->pitches
[0];
2505 mode_cmd
.modifier
[0] = fb
->modifier
[0];
2506 mode_cmd
.flags
= DRM_MODE_FB_MODIFIERS
;
2508 if (intel_framebuffer_init(dev
, to_intel_framebuffer(fb
),
2510 DRM_DEBUG_KMS("intel fb init failed\n");
2514 mutex_unlock(&dev
->struct_mutex
);
2516 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj
);
2520 drm_gem_object_unreference(&obj
->base
);
2521 mutex_unlock(&dev
->struct_mutex
);
2525 /* Update plane->state->fb to match plane->fb after driver-internal updates */
2527 update_state_fb(struct drm_plane
*plane
)
2529 if (plane
->fb
== plane
->state
->fb
)
2532 if (plane
->state
->fb
)
2533 drm_framebuffer_unreference(plane
->state
->fb
);
2534 plane
->state
->fb
= plane
->fb
;
2535 if (plane
->state
->fb
)
2536 drm_framebuffer_reference(plane
->state
->fb
);
2540 intel_find_initial_plane_obj(struct intel_crtc
*intel_crtc
,
2541 struct intel_initial_plane_config
*plane_config
)
2543 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2544 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2546 struct intel_crtc
*i
;
2547 struct drm_i915_gem_object
*obj
;
2548 struct drm_plane
*primary
= intel_crtc
->base
.primary
;
2549 struct drm_plane_state
*plane_state
= primary
->state
;
2550 struct drm_crtc_state
*crtc_state
= intel_crtc
->base
.state
;
2551 struct intel_plane
*intel_plane
= to_intel_plane(primary
);
2552 struct intel_plane_state
*intel_state
=
2553 to_intel_plane_state(plane_state
);
2554 struct drm_framebuffer
*fb
;
2556 if (!plane_config
->fb
)
2559 if (intel_alloc_initial_plane_obj(intel_crtc
, plane_config
)) {
2560 fb
= &plane_config
->fb
->base
;
2564 kfree(plane_config
->fb
);
2567 * Failed to alloc the obj, check to see if we should share
2568 * an fb with another CRTC instead
2570 for_each_crtc(dev
, c
) {
2571 i
= to_intel_crtc(c
);
2573 if (c
== &intel_crtc
->base
)
2579 fb
= c
->primary
->fb
;
2583 obj
= intel_fb_obj(fb
);
2584 if (i915_gem_obj_ggtt_offset(obj
) == plane_config
->base
) {
2585 drm_framebuffer_reference(fb
);
2591 * We've failed to reconstruct the BIOS FB. Current display state
2592 * indicates that the primary plane is visible, but has a NULL FB,
2593 * which will lead to problems later if we don't fix it up. The
2594 * simplest solution is to just disable the primary plane now and
2595 * pretend the BIOS never had it enabled.
2597 to_intel_plane_state(plane_state
)->visible
= false;
2598 crtc_state
->plane_mask
&= ~(1 << drm_plane_index(primary
));
2599 intel_pre_disable_primary_noatomic(&intel_crtc
->base
);
2600 intel_plane
->disable_plane(primary
, &intel_crtc
->base
);
2605 plane_state
->src_x
= 0;
2606 plane_state
->src_y
= 0;
2607 plane_state
->src_w
= fb
->width
<< 16;
2608 plane_state
->src_h
= fb
->height
<< 16;
2610 plane_state
->crtc_x
= 0;
2611 plane_state
->crtc_y
= 0;
2612 plane_state
->crtc_w
= fb
->width
;
2613 plane_state
->crtc_h
= fb
->height
;
2615 intel_state
->src
.x1
= plane_state
->src_x
;
2616 intel_state
->src
.y1
= plane_state
->src_y
;
2617 intel_state
->src
.x2
= plane_state
->src_x
+ plane_state
->src_w
;
2618 intel_state
->src
.y2
= plane_state
->src_y
+ plane_state
->src_h
;
2619 intel_state
->dst
.x1
= plane_state
->crtc_x
;
2620 intel_state
->dst
.y1
= plane_state
->crtc_y
;
2621 intel_state
->dst
.x2
= plane_state
->crtc_x
+ plane_state
->crtc_w
;
2622 intel_state
->dst
.y2
= plane_state
->crtc_y
+ plane_state
->crtc_h
;
2624 obj
= intel_fb_obj(fb
);
2625 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2626 dev_priv
->preserve_bios_swizzle
= true;
2628 drm_framebuffer_reference(fb
);
2629 primary
->fb
= primary
->state
->fb
= fb
;
2630 primary
->crtc
= primary
->state
->crtc
= &intel_crtc
->base
;
2631 intel_crtc
->base
.state
->plane_mask
|= (1 << drm_plane_index(primary
));
2632 obj
->frontbuffer_bits
|= to_intel_plane(primary
)->frontbuffer_bit
;
2635 static void i9xx_update_primary_plane(struct drm_plane
*primary
,
2636 const struct intel_crtc_state
*crtc_state
,
2637 const struct intel_plane_state
*plane_state
)
2639 struct drm_device
*dev
= primary
->dev
;
2640 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2641 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
2642 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2643 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2644 int plane
= intel_crtc
->plane
;
2647 i915_reg_t reg
= DSPCNTR(plane
);
2648 unsigned int rotation
= plane_state
->base
.rotation
;
2649 int cpp
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2650 int x
= plane_state
->src
.x1
>> 16;
2651 int y
= plane_state
->src
.y1
>> 16;
2653 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2655 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2657 if (INTEL_INFO(dev
)->gen
< 4) {
2658 if (intel_crtc
->pipe
== PIPE_B
)
2659 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
2661 /* pipesrc and dspsize control the size that is scaled from,
2662 * which should always be the user's requested size.
2664 I915_WRITE(DSPSIZE(plane
),
2665 ((crtc_state
->pipe_src_h
- 1) << 16) |
2666 (crtc_state
->pipe_src_w
- 1));
2667 I915_WRITE(DSPPOS(plane
), 0);
2668 } else if (IS_CHERRYVIEW(dev
) && plane
== PLANE_B
) {
2669 I915_WRITE(PRIMSIZE(plane
),
2670 ((crtc_state
->pipe_src_h
- 1) << 16) |
2671 (crtc_state
->pipe_src_w
- 1));
2672 I915_WRITE(PRIMPOS(plane
), 0);
2673 I915_WRITE(PRIMCNSTALPHA(plane
), 0);
2676 switch (fb
->pixel_format
) {
2678 dspcntr
|= DISPPLANE_8BPP
;
2680 case DRM_FORMAT_XRGB1555
:
2681 dspcntr
|= DISPPLANE_BGRX555
;
2683 case DRM_FORMAT_RGB565
:
2684 dspcntr
|= DISPPLANE_BGRX565
;
2686 case DRM_FORMAT_XRGB8888
:
2687 dspcntr
|= DISPPLANE_BGRX888
;
2689 case DRM_FORMAT_XBGR8888
:
2690 dspcntr
|= DISPPLANE_RGBX888
;
2692 case DRM_FORMAT_XRGB2101010
:
2693 dspcntr
|= DISPPLANE_BGRX101010
;
2695 case DRM_FORMAT_XBGR2101010
:
2696 dspcntr
|= DISPPLANE_RGBX101010
;
2702 if (INTEL_INFO(dev
)->gen
>= 4 &&
2703 obj
->tiling_mode
!= I915_TILING_NONE
)
2704 dspcntr
|= DISPPLANE_TILED
;
2707 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2709 linear_offset
= y
* fb
->pitches
[0] + x
* cpp
;
2711 if (INTEL_INFO(dev
)->gen
>= 4) {
2712 intel_crtc
->dspaddr_offset
=
2713 intel_compute_tile_offset(&x
, &y
, fb
, 0,
2714 fb
->pitches
[0], rotation
);
2715 linear_offset
-= intel_crtc
->dspaddr_offset
;
2717 intel_crtc
->dspaddr_offset
= linear_offset
;
2720 if (rotation
== BIT(DRM_ROTATE_180
)) {
2721 dspcntr
|= DISPPLANE_ROTATE_180
;
2723 x
+= (crtc_state
->pipe_src_w
- 1);
2724 y
+= (crtc_state
->pipe_src_h
- 1);
2726 /* Finding the last pixel of the last line of the display
2727 data and adding to linear_offset*/
2729 (crtc_state
->pipe_src_h
- 1) * fb
->pitches
[0] +
2730 (crtc_state
->pipe_src_w
- 1) * cpp
;
2733 intel_crtc
->adjusted_x
= x
;
2734 intel_crtc
->adjusted_y
= y
;
2736 I915_WRITE(reg
, dspcntr
);
2738 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2739 if (INTEL_INFO(dev
)->gen
>= 4) {
2740 I915_WRITE(DSPSURF(plane
),
2741 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2742 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2743 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2745 I915_WRITE(DSPADDR(plane
), i915_gem_obj_ggtt_offset(obj
) + linear_offset
);
2749 static void i9xx_disable_primary_plane(struct drm_plane
*primary
,
2750 struct drm_crtc
*crtc
)
2752 struct drm_device
*dev
= crtc
->dev
;
2753 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2754 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2755 int plane
= intel_crtc
->plane
;
2757 I915_WRITE(DSPCNTR(plane
), 0);
2758 if (INTEL_INFO(dev_priv
)->gen
>= 4)
2759 I915_WRITE(DSPSURF(plane
), 0);
2761 I915_WRITE(DSPADDR(plane
), 0);
2762 POSTING_READ(DSPCNTR(plane
));
2765 static void ironlake_update_primary_plane(struct drm_plane
*primary
,
2766 const struct intel_crtc_state
*crtc_state
,
2767 const struct intel_plane_state
*plane_state
)
2769 struct drm_device
*dev
= primary
->dev
;
2770 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2771 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
2772 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2773 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2774 int plane
= intel_crtc
->plane
;
2777 i915_reg_t reg
= DSPCNTR(plane
);
2778 unsigned int rotation
= plane_state
->base
.rotation
;
2779 int cpp
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2780 int x
= plane_state
->src
.x1
>> 16;
2781 int y
= plane_state
->src
.y1
>> 16;
2783 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2784 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2786 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2787 dspcntr
|= DISPPLANE_PIPE_CSC_ENABLE
;
2789 switch (fb
->pixel_format
) {
2791 dspcntr
|= DISPPLANE_8BPP
;
2793 case DRM_FORMAT_RGB565
:
2794 dspcntr
|= DISPPLANE_BGRX565
;
2796 case DRM_FORMAT_XRGB8888
:
2797 dspcntr
|= DISPPLANE_BGRX888
;
2799 case DRM_FORMAT_XBGR8888
:
2800 dspcntr
|= DISPPLANE_RGBX888
;
2802 case DRM_FORMAT_XRGB2101010
:
2803 dspcntr
|= DISPPLANE_BGRX101010
;
2805 case DRM_FORMAT_XBGR2101010
:
2806 dspcntr
|= DISPPLANE_RGBX101010
;
2812 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2813 dspcntr
|= DISPPLANE_TILED
;
2815 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
))
2816 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2818 linear_offset
= y
* fb
->pitches
[0] + x
* cpp
;
2819 intel_crtc
->dspaddr_offset
=
2820 intel_compute_tile_offset(&x
, &y
, fb
, 0,
2821 fb
->pitches
[0], rotation
);
2822 linear_offset
-= intel_crtc
->dspaddr_offset
;
2823 if (rotation
== BIT(DRM_ROTATE_180
)) {
2824 dspcntr
|= DISPPLANE_ROTATE_180
;
2826 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
)) {
2827 x
+= (crtc_state
->pipe_src_w
- 1);
2828 y
+= (crtc_state
->pipe_src_h
- 1);
2830 /* Finding the last pixel of the last line of the display
2831 data and adding to linear_offset*/
2833 (crtc_state
->pipe_src_h
- 1) * fb
->pitches
[0] +
2834 (crtc_state
->pipe_src_w
- 1) * cpp
;
2838 intel_crtc
->adjusted_x
= x
;
2839 intel_crtc
->adjusted_y
= y
;
2841 I915_WRITE(reg
, dspcntr
);
2843 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2844 I915_WRITE(DSPSURF(plane
),
2845 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2846 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2847 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
2849 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2850 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2855 u32
intel_fb_stride_alignment(const struct drm_i915_private
*dev_priv
,
2856 uint64_t fb_modifier
, uint32_t pixel_format
)
2858 if (fb_modifier
== DRM_FORMAT_MOD_NONE
) {
2861 int cpp
= drm_format_plane_cpp(pixel_format
, 0);
2863 return intel_tile_width_bytes(dev_priv
, fb_modifier
, cpp
);
2867 u32
intel_plane_obj_offset(struct intel_plane
*intel_plane
,
2868 struct drm_i915_gem_object
*obj
,
2871 struct i915_ggtt_view view
;
2872 struct i915_vma
*vma
;
2875 intel_fill_fb_ggtt_view(&view
, intel_plane
->base
.state
->fb
,
2876 intel_plane
->base
.state
->rotation
);
2878 vma
= i915_gem_obj_to_ggtt_view(obj
, &view
);
2879 if (WARN(!vma
, "ggtt vma for display object not found! (view=%u)\n",
2883 offset
= vma
->node
.start
;
2886 offset
+= vma
->ggtt_view
.params
.rotated
.uv_start_page
*
2890 WARN_ON(upper_32_bits(offset
));
2892 return lower_32_bits(offset
);
2895 static void skl_detach_scaler(struct intel_crtc
*intel_crtc
, int id
)
2897 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2898 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2900 I915_WRITE(SKL_PS_CTRL(intel_crtc
->pipe
, id
), 0);
2901 I915_WRITE(SKL_PS_WIN_POS(intel_crtc
->pipe
, id
), 0);
2902 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc
->pipe
, id
), 0);
2906 * This function detaches (aka. unbinds) unused scalers in hardware
2908 static void skl_detach_scalers(struct intel_crtc
*intel_crtc
)
2910 struct intel_crtc_scaler_state
*scaler_state
;
2913 scaler_state
= &intel_crtc
->config
->scaler_state
;
2915 /* loop through and disable scalers that aren't in use */
2916 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
2917 if (!scaler_state
->scalers
[i
].in_use
)
2918 skl_detach_scaler(intel_crtc
, i
);
2922 u32
skl_plane_ctl_format(uint32_t pixel_format
)
2924 switch (pixel_format
) {
2926 return PLANE_CTL_FORMAT_INDEXED
;
2927 case DRM_FORMAT_RGB565
:
2928 return PLANE_CTL_FORMAT_RGB_565
;
2929 case DRM_FORMAT_XBGR8888
:
2930 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
;
2931 case DRM_FORMAT_XRGB8888
:
2932 return PLANE_CTL_FORMAT_XRGB_8888
;
2934 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
2935 * to be already pre-multiplied. We need to add a knob (or a different
2936 * DRM_FORMAT) for user-space to configure that.
2938 case DRM_FORMAT_ABGR8888
:
2939 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
|
2940 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
2941 case DRM_FORMAT_ARGB8888
:
2942 return PLANE_CTL_FORMAT_XRGB_8888
|
2943 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
2944 case DRM_FORMAT_XRGB2101010
:
2945 return PLANE_CTL_FORMAT_XRGB_2101010
;
2946 case DRM_FORMAT_XBGR2101010
:
2947 return PLANE_CTL_ORDER_RGBX
| PLANE_CTL_FORMAT_XRGB_2101010
;
2948 case DRM_FORMAT_YUYV
:
2949 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YUYV
;
2950 case DRM_FORMAT_YVYU
:
2951 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YVYU
;
2952 case DRM_FORMAT_UYVY
:
2953 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_UYVY
;
2954 case DRM_FORMAT_VYUY
:
2955 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_VYUY
;
2957 MISSING_CASE(pixel_format
);
2963 u32
skl_plane_ctl_tiling(uint64_t fb_modifier
)
2965 switch (fb_modifier
) {
2966 case DRM_FORMAT_MOD_NONE
:
2968 case I915_FORMAT_MOD_X_TILED
:
2969 return PLANE_CTL_TILED_X
;
2970 case I915_FORMAT_MOD_Y_TILED
:
2971 return PLANE_CTL_TILED_Y
;
2972 case I915_FORMAT_MOD_Yf_TILED
:
2973 return PLANE_CTL_TILED_YF
;
2975 MISSING_CASE(fb_modifier
);
2981 u32
skl_plane_ctl_rotation(unsigned int rotation
)
2984 case BIT(DRM_ROTATE_0
):
2987 * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr
2988 * while i915 HW rotation is clockwise, thats why this swapping.
2990 case BIT(DRM_ROTATE_90
):
2991 return PLANE_CTL_ROTATE_270
;
2992 case BIT(DRM_ROTATE_180
):
2993 return PLANE_CTL_ROTATE_180
;
2994 case BIT(DRM_ROTATE_270
):
2995 return PLANE_CTL_ROTATE_90
;
2997 MISSING_CASE(rotation
);
3003 static void skylake_update_primary_plane(struct drm_plane
*plane
,
3004 const struct intel_crtc_state
*crtc_state
,
3005 const struct intel_plane_state
*plane_state
)
3007 struct drm_device
*dev
= plane
->dev
;
3008 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3009 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
3010 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
3011 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
3012 int pipe
= intel_crtc
->pipe
;
3013 u32 plane_ctl
, stride_div
, stride
;
3014 u32 tile_height
, plane_offset
, plane_size
;
3015 unsigned int rotation
= plane_state
->base
.rotation
;
3016 int x_offset
, y_offset
;
3018 int scaler_id
= plane_state
->scaler_id
;
3019 int src_x
= plane_state
->src
.x1
>> 16;
3020 int src_y
= plane_state
->src
.y1
>> 16;
3021 int src_w
= drm_rect_width(&plane_state
->src
) >> 16;
3022 int src_h
= drm_rect_height(&plane_state
->src
) >> 16;
3023 int dst_x
= plane_state
->dst
.x1
;
3024 int dst_y
= plane_state
->dst
.y1
;
3025 int dst_w
= drm_rect_width(&plane_state
->dst
);
3026 int dst_h
= drm_rect_height(&plane_state
->dst
);
3028 plane_ctl
= PLANE_CTL_ENABLE
|
3029 PLANE_CTL_PIPE_GAMMA_ENABLE
|
3030 PLANE_CTL_PIPE_CSC_ENABLE
;
3032 plane_ctl
|= skl_plane_ctl_format(fb
->pixel_format
);
3033 plane_ctl
|= skl_plane_ctl_tiling(fb
->modifier
[0]);
3034 plane_ctl
|= PLANE_CTL_PLANE_GAMMA_DISABLE
;
3035 plane_ctl
|= skl_plane_ctl_rotation(rotation
);
3037 stride_div
= intel_fb_stride_alignment(dev_priv
, fb
->modifier
[0],
3039 surf_addr
= intel_plane_obj_offset(to_intel_plane(plane
), obj
, 0);
3041 WARN_ON(drm_rect_width(&plane_state
->src
) == 0);
3043 if (intel_rotation_90_or_270(rotation
)) {
3044 int cpp
= drm_format_plane_cpp(fb
->pixel_format
, 0);
3046 /* stride = Surface height in tiles */
3047 tile_height
= intel_tile_height(dev_priv
, fb
->modifier
[0], cpp
);
3048 stride
= DIV_ROUND_UP(fb
->height
, tile_height
);
3049 x_offset
= stride
* tile_height
- src_y
- src_h
;
3051 plane_size
= (src_w
- 1) << 16 | (src_h
- 1);
3053 stride
= fb
->pitches
[0] / stride_div
;
3056 plane_size
= (src_h
- 1) << 16 | (src_w
- 1);
3058 plane_offset
= y_offset
<< 16 | x_offset
;
3060 intel_crtc
->adjusted_x
= x_offset
;
3061 intel_crtc
->adjusted_y
= y_offset
;
3063 I915_WRITE(PLANE_CTL(pipe
, 0), plane_ctl
);
3064 I915_WRITE(PLANE_OFFSET(pipe
, 0), plane_offset
);
3065 I915_WRITE(PLANE_SIZE(pipe
, 0), plane_size
);
3066 I915_WRITE(PLANE_STRIDE(pipe
, 0), stride
);
3068 if (scaler_id
>= 0) {
3069 uint32_t ps_ctrl
= 0;
3071 WARN_ON(!dst_w
|| !dst_h
);
3072 ps_ctrl
= PS_SCALER_EN
| PS_PLANE_SEL(0) |
3073 crtc_state
->scaler_state
.scalers
[scaler_id
].mode
;
3074 I915_WRITE(SKL_PS_CTRL(pipe
, scaler_id
), ps_ctrl
);
3075 I915_WRITE(SKL_PS_PWR_GATE(pipe
, scaler_id
), 0);
3076 I915_WRITE(SKL_PS_WIN_POS(pipe
, scaler_id
), (dst_x
<< 16) | dst_y
);
3077 I915_WRITE(SKL_PS_WIN_SZ(pipe
, scaler_id
), (dst_w
<< 16) | dst_h
);
3078 I915_WRITE(PLANE_POS(pipe
, 0), 0);
3080 I915_WRITE(PLANE_POS(pipe
, 0), (dst_y
<< 16) | dst_x
);
3083 I915_WRITE(PLANE_SURF(pipe
, 0), surf_addr
);
3085 POSTING_READ(PLANE_SURF(pipe
, 0));
3088 static void skylake_disable_primary_plane(struct drm_plane
*primary
,
3089 struct drm_crtc
*crtc
)
3091 struct drm_device
*dev
= crtc
->dev
;
3092 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3093 int pipe
= to_intel_crtc(crtc
)->pipe
;
3095 I915_WRITE(PLANE_CTL(pipe
, 0), 0);
3096 I915_WRITE(PLANE_SURF(pipe
, 0), 0);
3097 POSTING_READ(PLANE_SURF(pipe
, 0));
3100 /* Assume fb object is pinned & idle & fenced and just update base pointers */
3102 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
3103 int x
, int y
, enum mode_set_atomic state
)
3105 /* Support for kgdboc is disabled, this needs a major rework. */
3106 DRM_ERROR("legacy panic handler not supported any more.\n");
3111 static void intel_complete_page_flips(struct drm_i915_private
*dev_priv
)
3113 struct intel_crtc
*crtc
;
3115 for_each_intel_crtc(dev_priv
->dev
, crtc
)
3116 intel_finish_page_flip(dev_priv
, crtc
->pipe
);
3119 static void intel_update_primary_planes(struct drm_device
*dev
)
3121 struct drm_crtc
*crtc
;
3123 for_each_crtc(dev
, crtc
) {
3124 struct intel_plane
*plane
= to_intel_plane(crtc
->primary
);
3125 struct intel_plane_state
*plane_state
;
3127 drm_modeset_lock_crtc(crtc
, &plane
->base
);
3128 plane_state
= to_intel_plane_state(plane
->base
.state
);
3130 if (plane_state
->visible
)
3131 plane
->update_plane(&plane
->base
,
3132 to_intel_crtc_state(crtc
->state
),
3135 drm_modeset_unlock_crtc(crtc
);
3139 void intel_prepare_reset(struct drm_i915_private
*dev_priv
)
3141 /* no reset support for gen2 */
3142 if (IS_GEN2(dev_priv
))
3145 /* reset doesn't touch the display */
3146 if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
))
3149 drm_modeset_lock_all(dev_priv
->dev
);
3151 * Disabling the crtcs gracefully seems nicer. Also the
3152 * g33 docs say we should at least disable all the planes.
3154 intel_display_suspend(dev_priv
->dev
);
3157 void intel_finish_reset(struct drm_i915_private
*dev_priv
)
3160 * Flips in the rings will be nuked by the reset,
3161 * so complete all pending flips so that user space
3162 * will get its events and not get stuck.
3164 intel_complete_page_flips(dev_priv
);
3166 /* no reset support for gen2 */
3167 if (IS_GEN2(dev_priv
))
3170 /* reset doesn't touch the display */
3171 if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
)) {
3173 * Flips in the rings have been nuked by the reset,
3174 * so update the base address of all primary
3175 * planes to the the last fb to make sure we're
3176 * showing the correct fb after a reset.
3178 * FIXME: Atomic will make this obsolete since we won't schedule
3179 * CS-based flips (which might get lost in gpu resets) any more.
3181 intel_update_primary_planes(dev_priv
->dev
);
3186 * The display has been reset as well,
3187 * so need a full re-initialization.
3189 intel_runtime_pm_disable_interrupts(dev_priv
);
3190 intel_runtime_pm_enable_interrupts(dev_priv
);
3192 intel_modeset_init_hw(dev_priv
->dev
);
3194 spin_lock_irq(&dev_priv
->irq_lock
);
3195 if (dev_priv
->display
.hpd_irq_setup
)
3196 dev_priv
->display
.hpd_irq_setup(dev_priv
);
3197 spin_unlock_irq(&dev_priv
->irq_lock
);
3199 intel_display_resume(dev_priv
->dev
);
3201 intel_hpd_init(dev_priv
);
3203 drm_modeset_unlock_all(dev_priv
->dev
);
3206 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
3208 struct drm_device
*dev
= crtc
->dev
;
3209 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3210 unsigned reset_counter
;
3213 reset_counter
= i915_reset_counter(&to_i915(dev
)->gpu_error
);
3214 if (intel_crtc
->reset_counter
!= reset_counter
)
3217 spin_lock_irq(&dev
->event_lock
);
3218 pending
= to_intel_crtc(crtc
)->unpin_work
!= NULL
;
3219 spin_unlock_irq(&dev
->event_lock
);
3224 static void intel_update_pipe_config(struct intel_crtc
*crtc
,
3225 struct intel_crtc_state
*old_crtc_state
)
3227 struct drm_device
*dev
= crtc
->base
.dev
;
3228 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3229 struct intel_crtc_state
*pipe_config
=
3230 to_intel_crtc_state(crtc
->base
.state
);
3232 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
3233 crtc
->base
.mode
= crtc
->base
.state
->mode
;
3235 DRM_DEBUG_KMS("Updating pipe size %ix%i -> %ix%i\n",
3236 old_crtc_state
->pipe_src_w
, old_crtc_state
->pipe_src_h
,
3237 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
3240 * Update pipe size and adjust fitter if needed: the reason for this is
3241 * that in compute_mode_changes we check the native mode (not the pfit
3242 * mode) to see if we can flip rather than do a full mode set. In the
3243 * fastboot case, we'll flip, but if we don't update the pipesrc and
3244 * pfit state, we'll end up with a big fb scanned out into the wrong
3248 I915_WRITE(PIPESRC(crtc
->pipe
),
3249 ((pipe_config
->pipe_src_w
- 1) << 16) |
3250 (pipe_config
->pipe_src_h
- 1));
3252 /* on skylake this is done by detaching scalers */
3253 if (INTEL_INFO(dev
)->gen
>= 9) {
3254 skl_detach_scalers(crtc
);
3256 if (pipe_config
->pch_pfit
.enabled
)
3257 skylake_pfit_enable(crtc
);
3258 } else if (HAS_PCH_SPLIT(dev
)) {
3259 if (pipe_config
->pch_pfit
.enabled
)
3260 ironlake_pfit_enable(crtc
);
3261 else if (old_crtc_state
->pch_pfit
.enabled
)
3262 ironlake_pfit_disable(crtc
, true);
3266 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
3268 struct drm_device
*dev
= crtc
->dev
;
3269 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3270 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3271 int pipe
= intel_crtc
->pipe
;
3275 /* enable normal train */
3276 reg
= FDI_TX_CTL(pipe
);
3277 temp
= I915_READ(reg
);
3278 if (IS_IVYBRIDGE(dev
)) {
3279 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3280 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3282 temp
&= ~FDI_LINK_TRAIN_NONE
;
3283 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3285 I915_WRITE(reg
, temp
);
3287 reg
= FDI_RX_CTL(pipe
);
3288 temp
= I915_READ(reg
);
3289 if (HAS_PCH_CPT(dev
)) {
3290 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3291 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
3293 temp
&= ~FDI_LINK_TRAIN_NONE
;
3294 temp
|= FDI_LINK_TRAIN_NONE
;
3296 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
3298 /* wait one idle pattern time */
3302 /* IVB wants error correction enabled */
3303 if (IS_IVYBRIDGE(dev
))
3304 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
3305 FDI_FE_ERRC_ENABLE
);
3308 /* The FDI link training functions for ILK/Ibexpeak. */
3309 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
3311 struct drm_device
*dev
= crtc
->dev
;
3312 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3313 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3314 int pipe
= intel_crtc
->pipe
;
3318 /* FDI needs bits from pipe first */
3319 assert_pipe_enabled(dev_priv
, pipe
);
3321 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3323 reg
= FDI_RX_IMR(pipe
);
3324 temp
= I915_READ(reg
);
3325 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3326 temp
&= ~FDI_RX_BIT_LOCK
;
3327 I915_WRITE(reg
, temp
);
3331 /* enable CPU FDI TX and PCH FDI RX */
3332 reg
= FDI_TX_CTL(pipe
);
3333 temp
= I915_READ(reg
);
3334 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3335 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3336 temp
&= ~FDI_LINK_TRAIN_NONE
;
3337 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3338 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3340 reg
= FDI_RX_CTL(pipe
);
3341 temp
= I915_READ(reg
);
3342 temp
&= ~FDI_LINK_TRAIN_NONE
;
3343 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3344 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3349 /* Ironlake workaround, enable clock pointer after FDI enable*/
3350 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3351 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
3352 FDI_RX_PHASE_SYNC_POINTER_EN
);
3354 reg
= FDI_RX_IIR(pipe
);
3355 for (tries
= 0; tries
< 5; tries
++) {
3356 temp
= I915_READ(reg
);
3357 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3359 if ((temp
& FDI_RX_BIT_LOCK
)) {
3360 DRM_DEBUG_KMS("FDI train 1 done.\n");
3361 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3366 DRM_ERROR("FDI train 1 fail!\n");
3369 reg
= FDI_TX_CTL(pipe
);
3370 temp
= I915_READ(reg
);
3371 temp
&= ~FDI_LINK_TRAIN_NONE
;
3372 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3373 I915_WRITE(reg
, temp
);
3375 reg
= FDI_RX_CTL(pipe
);
3376 temp
= I915_READ(reg
);
3377 temp
&= ~FDI_LINK_TRAIN_NONE
;
3378 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3379 I915_WRITE(reg
, temp
);
3384 reg
= FDI_RX_IIR(pipe
);
3385 for (tries
= 0; tries
< 5; tries
++) {
3386 temp
= I915_READ(reg
);
3387 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3389 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3390 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3391 DRM_DEBUG_KMS("FDI train 2 done.\n");
3396 DRM_ERROR("FDI train 2 fail!\n");
3398 DRM_DEBUG_KMS("FDI train done\n");
3402 static const int snb_b_fdi_train_param
[] = {
3403 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
3404 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
3405 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
3406 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
3409 /* The FDI link training functions for SNB/Cougarpoint. */
3410 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
3412 struct drm_device
*dev
= crtc
->dev
;
3413 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3414 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3415 int pipe
= intel_crtc
->pipe
;
3419 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3421 reg
= FDI_RX_IMR(pipe
);
3422 temp
= I915_READ(reg
);
3423 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3424 temp
&= ~FDI_RX_BIT_LOCK
;
3425 I915_WRITE(reg
, temp
);
3430 /* enable CPU FDI TX and PCH FDI RX */
3431 reg
= FDI_TX_CTL(pipe
);
3432 temp
= I915_READ(reg
);
3433 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3434 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3435 temp
&= ~FDI_LINK_TRAIN_NONE
;
3436 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3437 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3439 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3440 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3442 I915_WRITE(FDI_RX_MISC(pipe
),
3443 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3445 reg
= FDI_RX_CTL(pipe
);
3446 temp
= I915_READ(reg
);
3447 if (HAS_PCH_CPT(dev
)) {
3448 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3449 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3451 temp
&= ~FDI_LINK_TRAIN_NONE
;
3452 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3454 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3459 for (i
= 0; i
< 4; i
++) {
3460 reg
= FDI_TX_CTL(pipe
);
3461 temp
= I915_READ(reg
);
3462 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3463 temp
|= snb_b_fdi_train_param
[i
];
3464 I915_WRITE(reg
, temp
);
3469 for (retry
= 0; retry
< 5; retry
++) {
3470 reg
= FDI_RX_IIR(pipe
);
3471 temp
= I915_READ(reg
);
3472 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3473 if (temp
& FDI_RX_BIT_LOCK
) {
3474 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3475 DRM_DEBUG_KMS("FDI train 1 done.\n");
3484 DRM_ERROR("FDI train 1 fail!\n");
3487 reg
= FDI_TX_CTL(pipe
);
3488 temp
= I915_READ(reg
);
3489 temp
&= ~FDI_LINK_TRAIN_NONE
;
3490 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3492 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3494 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3496 I915_WRITE(reg
, temp
);
3498 reg
= FDI_RX_CTL(pipe
);
3499 temp
= I915_READ(reg
);
3500 if (HAS_PCH_CPT(dev
)) {
3501 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3502 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3504 temp
&= ~FDI_LINK_TRAIN_NONE
;
3505 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3507 I915_WRITE(reg
, temp
);
3512 for (i
= 0; i
< 4; i
++) {
3513 reg
= FDI_TX_CTL(pipe
);
3514 temp
= I915_READ(reg
);
3515 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3516 temp
|= snb_b_fdi_train_param
[i
];
3517 I915_WRITE(reg
, temp
);
3522 for (retry
= 0; retry
< 5; retry
++) {
3523 reg
= FDI_RX_IIR(pipe
);
3524 temp
= I915_READ(reg
);
3525 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3526 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3527 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3528 DRM_DEBUG_KMS("FDI train 2 done.\n");
3537 DRM_ERROR("FDI train 2 fail!\n");
3539 DRM_DEBUG_KMS("FDI train done.\n");
3542 /* Manual link training for Ivy Bridge A0 parts */
3543 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
3545 struct drm_device
*dev
= crtc
->dev
;
3546 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3547 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3548 int pipe
= intel_crtc
->pipe
;
3552 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3554 reg
= FDI_RX_IMR(pipe
);
3555 temp
= I915_READ(reg
);
3556 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3557 temp
&= ~FDI_RX_BIT_LOCK
;
3558 I915_WRITE(reg
, temp
);
3563 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3564 I915_READ(FDI_RX_IIR(pipe
)));
3566 /* Try each vswing and preemphasis setting twice before moving on */
3567 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
3568 /* disable first in case we need to retry */
3569 reg
= FDI_TX_CTL(pipe
);
3570 temp
= I915_READ(reg
);
3571 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
3572 temp
&= ~FDI_TX_ENABLE
;
3573 I915_WRITE(reg
, temp
);
3575 reg
= FDI_RX_CTL(pipe
);
3576 temp
= I915_READ(reg
);
3577 temp
&= ~FDI_LINK_TRAIN_AUTO
;
3578 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3579 temp
&= ~FDI_RX_ENABLE
;
3580 I915_WRITE(reg
, temp
);
3582 /* enable CPU FDI TX and PCH FDI RX */
3583 reg
= FDI_TX_CTL(pipe
);
3584 temp
= I915_READ(reg
);
3585 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3586 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3587 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
3588 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3589 temp
|= snb_b_fdi_train_param
[j
/2];
3590 temp
|= FDI_COMPOSITE_SYNC
;
3591 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3593 I915_WRITE(FDI_RX_MISC(pipe
),
3594 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3596 reg
= FDI_RX_CTL(pipe
);
3597 temp
= I915_READ(reg
);
3598 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3599 temp
|= FDI_COMPOSITE_SYNC
;
3600 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3603 udelay(1); /* should be 0.5us */
3605 for (i
= 0; i
< 4; i
++) {
3606 reg
= FDI_RX_IIR(pipe
);
3607 temp
= I915_READ(reg
);
3608 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3610 if (temp
& FDI_RX_BIT_LOCK
||
3611 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
3612 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3613 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3617 udelay(1); /* should be 0.5us */
3620 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
3625 reg
= FDI_TX_CTL(pipe
);
3626 temp
= I915_READ(reg
);
3627 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3628 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
3629 I915_WRITE(reg
, temp
);
3631 reg
= FDI_RX_CTL(pipe
);
3632 temp
= I915_READ(reg
);
3633 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3634 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3635 I915_WRITE(reg
, temp
);
3638 udelay(2); /* should be 1.5us */
3640 for (i
= 0; i
< 4; i
++) {
3641 reg
= FDI_RX_IIR(pipe
);
3642 temp
= I915_READ(reg
);
3643 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3645 if (temp
& FDI_RX_SYMBOL_LOCK
||
3646 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
3647 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3648 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
3652 udelay(2); /* should be 1.5us */
3655 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
3659 DRM_DEBUG_KMS("FDI train done.\n");
3662 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
3664 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3665 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3666 int pipe
= intel_crtc
->pipe
;
3670 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
3671 reg
= FDI_RX_CTL(pipe
);
3672 temp
= I915_READ(reg
);
3673 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
3674 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3675 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3676 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
3681 /* Switch from Rawclk to PCDclk */
3682 temp
= I915_READ(reg
);
3683 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
3688 /* Enable CPU FDI TX PLL, always on for Ironlake */
3689 reg
= FDI_TX_CTL(pipe
);
3690 temp
= I915_READ(reg
);
3691 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
3692 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
3699 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
3701 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3702 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3703 int pipe
= intel_crtc
->pipe
;
3707 /* Switch from PCDclk to Rawclk */
3708 reg
= FDI_RX_CTL(pipe
);
3709 temp
= I915_READ(reg
);
3710 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
3712 /* Disable CPU FDI TX PLL */
3713 reg
= FDI_TX_CTL(pipe
);
3714 temp
= I915_READ(reg
);
3715 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
3720 reg
= FDI_RX_CTL(pipe
);
3721 temp
= I915_READ(reg
);
3722 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
3724 /* Wait for the clocks to turn off. */
3729 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
3731 struct drm_device
*dev
= crtc
->dev
;
3732 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3733 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3734 int pipe
= intel_crtc
->pipe
;
3738 /* disable CPU FDI tx and PCH FDI rx */
3739 reg
= FDI_TX_CTL(pipe
);
3740 temp
= I915_READ(reg
);
3741 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
3744 reg
= FDI_RX_CTL(pipe
);
3745 temp
= I915_READ(reg
);
3746 temp
&= ~(0x7 << 16);
3747 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3748 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
3753 /* Ironlake workaround, disable clock pointer after downing FDI */
3754 if (HAS_PCH_IBX(dev
))
3755 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3757 /* still set train pattern 1 */
3758 reg
= FDI_TX_CTL(pipe
);
3759 temp
= I915_READ(reg
);
3760 temp
&= ~FDI_LINK_TRAIN_NONE
;
3761 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3762 I915_WRITE(reg
, temp
);
3764 reg
= FDI_RX_CTL(pipe
);
3765 temp
= I915_READ(reg
);
3766 if (HAS_PCH_CPT(dev
)) {
3767 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3768 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3770 temp
&= ~FDI_LINK_TRAIN_NONE
;
3771 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3773 /* BPC in FDI rx is consistent with that in PIPECONF */
3774 temp
&= ~(0x07 << 16);
3775 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3776 I915_WRITE(reg
, temp
);
3782 bool intel_has_pending_fb_unpin(struct drm_device
*dev
)
3784 struct intel_crtc
*crtc
;
3786 /* Note that we don't need to be called with mode_config.lock here
3787 * as our list of CRTC objects is static for the lifetime of the
3788 * device and so cannot disappear as we iterate. Similarly, we can
3789 * happily treat the predicates as racy, atomic checks as userspace
3790 * cannot claim and pin a new fb without at least acquring the
3791 * struct_mutex and so serialising with us.
3793 for_each_intel_crtc(dev
, crtc
) {
3794 if (atomic_read(&crtc
->unpin_work_count
) == 0)
3797 if (crtc
->unpin_work
)
3798 intel_wait_for_vblank(dev
, crtc
->pipe
);
3806 static void page_flip_completed(struct intel_crtc
*intel_crtc
)
3808 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
3809 struct intel_unpin_work
*work
= intel_crtc
->unpin_work
;
3811 intel_crtc
->unpin_work
= NULL
;
3814 drm_crtc_send_vblank_event(&intel_crtc
->base
, work
->event
);
3816 drm_crtc_vblank_put(&intel_crtc
->base
);
3818 wake_up_all(&dev_priv
->pending_flip_queue
);
3819 queue_work(dev_priv
->wq
, &work
->work
);
3821 trace_i915_flip_complete(intel_crtc
->plane
,
3822 work
->pending_flip_obj
);
3825 static int intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
3827 struct drm_device
*dev
= crtc
->dev
;
3828 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3831 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
3833 ret
= wait_event_interruptible_timeout(
3834 dev_priv
->pending_flip_queue
,
3835 !intel_crtc_has_pending_flip(crtc
),
3842 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3844 spin_lock_irq(&dev
->event_lock
);
3845 if (intel_crtc
->unpin_work
) {
3846 WARN_ONCE(1, "Removing stuck page flip\n");
3847 page_flip_completed(intel_crtc
);
3849 spin_unlock_irq(&dev
->event_lock
);
3855 static void lpt_disable_iclkip(struct drm_i915_private
*dev_priv
)
3859 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
3861 mutex_lock(&dev_priv
->sb_lock
);
3863 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
3864 temp
|= SBI_SSCCTL_DISABLE
;
3865 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
3867 mutex_unlock(&dev_priv
->sb_lock
);
3870 /* Program iCLKIP clock to the desired frequency */
3871 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
3873 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
3874 int clock
= to_intel_crtc(crtc
)->config
->base
.adjusted_mode
.crtc_clock
;
3875 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
3878 lpt_disable_iclkip(dev_priv
);
3880 /* The iCLK virtual clock root frequency is in MHz,
3881 * but the adjusted_mode->crtc_clock in in KHz. To get the
3882 * divisors, it is necessary to divide one by another, so we
3883 * convert the virtual clock precision to KHz here for higher
3886 for (auxdiv
= 0; auxdiv
< 2; auxdiv
++) {
3887 u32 iclk_virtual_root_freq
= 172800 * 1000;
3888 u32 iclk_pi_range
= 64;
3889 u32 desired_divisor
;
3891 desired_divisor
= DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
3893 divsel
= (desired_divisor
/ iclk_pi_range
) - 2;
3894 phaseinc
= desired_divisor
% iclk_pi_range
;
3897 * Near 20MHz is a corner case which is
3898 * out of range for the 7-bit divisor
3904 /* This should not happen with any sane values */
3905 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
3906 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
3907 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
3908 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
3910 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3917 mutex_lock(&dev_priv
->sb_lock
);
3919 /* Program SSCDIVINTPHASE6 */
3920 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
3921 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
3922 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
3923 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
3924 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
3925 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
3926 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
3927 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
3929 /* Program SSCAUXDIV */
3930 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
3931 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3932 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
3933 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
3935 /* Enable modulator and associated divider */
3936 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
3937 temp
&= ~SBI_SSCCTL_DISABLE
;
3938 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
3940 mutex_unlock(&dev_priv
->sb_lock
);
3942 /* Wait for initialization time */
3945 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
3948 int lpt_get_iclkip(struct drm_i915_private
*dev_priv
)
3950 u32 divsel
, phaseinc
, auxdiv
;
3951 u32 iclk_virtual_root_freq
= 172800 * 1000;
3952 u32 iclk_pi_range
= 64;
3953 u32 desired_divisor
;
3956 if ((I915_READ(PIXCLK_GATE
) & PIXCLK_GATE_UNGATE
) == 0)
3959 mutex_lock(&dev_priv
->sb_lock
);
3961 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
3962 if (temp
& SBI_SSCCTL_DISABLE
) {
3963 mutex_unlock(&dev_priv
->sb_lock
);
3967 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
3968 divsel
= (temp
& SBI_SSCDIVINTPHASE_DIVSEL_MASK
) >>
3969 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT
;
3970 phaseinc
= (temp
& SBI_SSCDIVINTPHASE_INCVAL_MASK
) >>
3971 SBI_SSCDIVINTPHASE_INCVAL_SHIFT
;
3973 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
3974 auxdiv
= (temp
& SBI_SSCAUXDIV_FINALDIV2SEL_MASK
) >>
3975 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT
;
3977 mutex_unlock(&dev_priv
->sb_lock
);
3979 desired_divisor
= (divsel
+ 2) * iclk_pi_range
+ phaseinc
;
3981 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
3982 desired_divisor
<< auxdiv
);
3985 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
3986 enum pipe pch_transcoder
)
3988 struct drm_device
*dev
= crtc
->base
.dev
;
3989 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3990 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
3992 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
3993 I915_READ(HTOTAL(cpu_transcoder
)));
3994 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
3995 I915_READ(HBLANK(cpu_transcoder
)));
3996 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
3997 I915_READ(HSYNC(cpu_transcoder
)));
3999 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
4000 I915_READ(VTOTAL(cpu_transcoder
)));
4001 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
4002 I915_READ(VBLANK(cpu_transcoder
)));
4003 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
4004 I915_READ(VSYNC(cpu_transcoder
)));
4005 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
4006 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
4009 static void cpt_set_fdi_bc_bifurcation(struct drm_device
*dev
, bool enable
)
4011 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4014 temp
= I915_READ(SOUTH_CHICKEN1
);
4015 if (!!(temp
& FDI_BC_BIFURCATION_SELECT
) == enable
)
4018 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
4019 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
4021 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
4023 temp
|= FDI_BC_BIFURCATION_SELECT
;
4025 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable
? "en" : "dis");
4026 I915_WRITE(SOUTH_CHICKEN1
, temp
);
4027 POSTING_READ(SOUTH_CHICKEN1
);
4030 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
4032 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4034 switch (intel_crtc
->pipe
) {
4038 if (intel_crtc
->config
->fdi_lanes
> 2)
4039 cpt_set_fdi_bc_bifurcation(dev
, false);
4041 cpt_set_fdi_bc_bifurcation(dev
, true);
4045 cpt_set_fdi_bc_bifurcation(dev
, true);
4053 /* Return which DP Port should be selected for Transcoder DP control */
4055 intel_trans_dp_port_sel(struct drm_crtc
*crtc
)
4057 struct drm_device
*dev
= crtc
->dev
;
4058 struct intel_encoder
*encoder
;
4060 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4061 if (encoder
->type
== INTEL_OUTPUT_DISPLAYPORT
||
4062 encoder
->type
== INTEL_OUTPUT_EDP
)
4063 return enc_to_dig_port(&encoder
->base
)->port
;
4070 * Enable PCH resources required for PCH ports:
4072 * - FDI training & RX/TX
4073 * - update transcoder timings
4074 * - DP transcoding bits
4077 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
4079 struct drm_device
*dev
= crtc
->dev
;
4080 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4081 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4082 int pipe
= intel_crtc
->pipe
;
4085 assert_pch_transcoder_disabled(dev_priv
, pipe
);
4087 if (IS_IVYBRIDGE(dev
))
4088 ivybridge_update_fdi_bc_bifurcation(intel_crtc
);
4090 /* Write the TU size bits before fdi link training, so that error
4091 * detection works. */
4092 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
4093 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
4095 /* For PCH output, training FDI link */
4096 dev_priv
->display
.fdi_link_train(crtc
);
4098 /* We need to program the right clock selection before writing the pixel
4099 * mutliplier into the DPLL. */
4100 if (HAS_PCH_CPT(dev
)) {
4103 temp
= I915_READ(PCH_DPLL_SEL
);
4104 temp
|= TRANS_DPLL_ENABLE(pipe
);
4105 sel
= TRANS_DPLLB_SEL(pipe
);
4106 if (intel_crtc
->config
->shared_dpll
==
4107 intel_get_shared_dpll_by_id(dev_priv
, DPLL_ID_PCH_PLL_B
))
4111 I915_WRITE(PCH_DPLL_SEL
, temp
);
4114 /* XXX: pch pll's can be enabled any time before we enable the PCH
4115 * transcoder, and we actually should do this to not upset any PCH
4116 * transcoder that already use the clock when we share it.
4118 * Note that enable_shared_dpll tries to do the right thing, but
4119 * get_shared_dpll unconditionally resets the pll - we need that to have
4120 * the right LVDS enable sequence. */
4121 intel_enable_shared_dpll(intel_crtc
);
4123 /* set transcoder timing, panel must allow it */
4124 assert_panel_unlocked(dev_priv
, pipe
);
4125 ironlake_pch_transcoder_set_timings(intel_crtc
, pipe
);
4127 intel_fdi_normal_train(crtc
);
4129 /* For PCH DP, enable TRANS_DP_CTL */
4130 if (HAS_PCH_CPT(dev
) && intel_crtc
->config
->has_dp_encoder
) {
4131 const struct drm_display_mode
*adjusted_mode
=
4132 &intel_crtc
->config
->base
.adjusted_mode
;
4133 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
4134 i915_reg_t reg
= TRANS_DP_CTL(pipe
);
4135 temp
= I915_READ(reg
);
4136 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
4137 TRANS_DP_SYNC_MASK
|
4139 temp
|= TRANS_DP_OUTPUT_ENABLE
;
4140 temp
|= bpc
<< 9; /* same format but at 11:9 */
4142 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
4143 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
4144 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
4145 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
4147 switch (intel_trans_dp_port_sel(crtc
)) {
4149 temp
|= TRANS_DP_PORT_SEL_B
;
4152 temp
|= TRANS_DP_PORT_SEL_C
;
4155 temp
|= TRANS_DP_PORT_SEL_D
;
4161 I915_WRITE(reg
, temp
);
4164 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
4167 static void lpt_pch_enable(struct drm_crtc
*crtc
)
4169 struct drm_device
*dev
= crtc
->dev
;
4170 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4171 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4172 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
4174 assert_pch_transcoder_disabled(dev_priv
, TRANSCODER_A
);
4176 lpt_program_iclkip(crtc
);
4178 /* Set transcoder timing. */
4179 ironlake_pch_transcoder_set_timings(intel_crtc
, PIPE_A
);
4181 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
4184 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
4186 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4187 i915_reg_t dslreg
= PIPEDSL(pipe
);
4190 temp
= I915_READ(dslreg
);
4192 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
4193 if (wait_for(I915_READ(dslreg
) != temp
, 5))
4194 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
4199 skl_update_scaler(struct intel_crtc_state
*crtc_state
, bool force_detach
,
4200 unsigned scaler_user
, int *scaler_id
, unsigned int rotation
,
4201 int src_w
, int src_h
, int dst_w
, int dst_h
)
4203 struct intel_crtc_scaler_state
*scaler_state
=
4204 &crtc_state
->scaler_state
;
4205 struct intel_crtc
*intel_crtc
=
4206 to_intel_crtc(crtc_state
->base
.crtc
);
4209 need_scaling
= intel_rotation_90_or_270(rotation
) ?
4210 (src_h
!= dst_w
|| src_w
!= dst_h
):
4211 (src_w
!= dst_w
|| src_h
!= dst_h
);
4214 * if plane is being disabled or scaler is no more required or force detach
4215 * - free scaler binded to this plane/crtc
4216 * - in order to do this, update crtc->scaler_usage
4218 * Here scaler state in crtc_state is set free so that
4219 * scaler can be assigned to other user. Actual register
4220 * update to free the scaler is done in plane/panel-fit programming.
4221 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4223 if (force_detach
|| !need_scaling
) {
4224 if (*scaler_id
>= 0) {
4225 scaler_state
->scaler_users
&= ~(1 << scaler_user
);
4226 scaler_state
->scalers
[*scaler_id
].in_use
= 0;
4228 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4229 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4230 intel_crtc
->pipe
, scaler_user
, *scaler_id
,
4231 scaler_state
->scaler_users
);
4238 if (src_w
< SKL_MIN_SRC_W
|| src_h
< SKL_MIN_SRC_H
||
4239 dst_w
< SKL_MIN_DST_W
|| dst_h
< SKL_MIN_DST_H
||
4241 src_w
> SKL_MAX_SRC_W
|| src_h
> SKL_MAX_SRC_H
||
4242 dst_w
> SKL_MAX_DST_W
|| dst_h
> SKL_MAX_DST_H
) {
4243 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4244 "size is out of scaler range\n",
4245 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
);
4249 /* mark this plane as a scaler user in crtc_state */
4250 scaler_state
->scaler_users
|= (1 << scaler_user
);
4251 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4252 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4253 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
,
4254 scaler_state
->scaler_users
);
4260 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4262 * @state: crtc's scaler state
4265 * 0 - scaler_usage updated successfully
4266 * error - requested scaling cannot be supported or other error condition
4268 int skl_update_scaler_crtc(struct intel_crtc_state
*state
)
4270 struct intel_crtc
*intel_crtc
= to_intel_crtc(state
->base
.crtc
);
4271 const struct drm_display_mode
*adjusted_mode
= &state
->base
.adjusted_mode
;
4273 DRM_DEBUG_KMS("Updating scaler for [CRTC:%i] scaler_user index %u.%u\n",
4274 intel_crtc
->base
.base
.id
, intel_crtc
->pipe
, SKL_CRTC_INDEX
);
4276 return skl_update_scaler(state
, !state
->base
.active
, SKL_CRTC_INDEX
,
4277 &state
->scaler_state
.scaler_id
, BIT(DRM_ROTATE_0
),
4278 state
->pipe_src_w
, state
->pipe_src_h
,
4279 adjusted_mode
->crtc_hdisplay
, adjusted_mode
->crtc_vdisplay
);
4283 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4285 * @state: crtc's scaler state
4286 * @plane_state: atomic plane state to update
4289 * 0 - scaler_usage updated successfully
4290 * error - requested scaling cannot be supported or other error condition
4292 static int skl_update_scaler_plane(struct intel_crtc_state
*crtc_state
,
4293 struct intel_plane_state
*plane_state
)
4296 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
4297 struct intel_plane
*intel_plane
=
4298 to_intel_plane(plane_state
->base
.plane
);
4299 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
4302 bool force_detach
= !fb
|| !plane_state
->visible
;
4304 DRM_DEBUG_KMS("Updating scaler for [PLANE:%d] scaler_user index %u.%u\n",
4305 intel_plane
->base
.base
.id
, intel_crtc
->pipe
,
4306 drm_plane_index(&intel_plane
->base
));
4308 ret
= skl_update_scaler(crtc_state
, force_detach
,
4309 drm_plane_index(&intel_plane
->base
),
4310 &plane_state
->scaler_id
,
4311 plane_state
->base
.rotation
,
4312 drm_rect_width(&plane_state
->src
) >> 16,
4313 drm_rect_height(&plane_state
->src
) >> 16,
4314 drm_rect_width(&plane_state
->dst
),
4315 drm_rect_height(&plane_state
->dst
));
4317 if (ret
|| plane_state
->scaler_id
< 0)
4320 /* check colorkey */
4321 if (plane_state
->ckey
.flags
!= I915_SET_COLORKEY_NONE
) {
4322 DRM_DEBUG_KMS("[PLANE:%d] scaling with color key not allowed",
4323 intel_plane
->base
.base
.id
);
4327 /* Check src format */
4328 switch (fb
->pixel_format
) {
4329 case DRM_FORMAT_RGB565
:
4330 case DRM_FORMAT_XBGR8888
:
4331 case DRM_FORMAT_XRGB8888
:
4332 case DRM_FORMAT_ABGR8888
:
4333 case DRM_FORMAT_ARGB8888
:
4334 case DRM_FORMAT_XRGB2101010
:
4335 case DRM_FORMAT_XBGR2101010
:
4336 case DRM_FORMAT_YUYV
:
4337 case DRM_FORMAT_YVYU
:
4338 case DRM_FORMAT_UYVY
:
4339 case DRM_FORMAT_VYUY
:
4342 DRM_DEBUG_KMS("[PLANE:%d] FB:%d unsupported scaling format 0x%x\n",
4343 intel_plane
->base
.base
.id
, fb
->base
.id
, fb
->pixel_format
);
4350 static void skylake_scaler_disable(struct intel_crtc
*crtc
)
4354 for (i
= 0; i
< crtc
->num_scalers
; i
++)
4355 skl_detach_scaler(crtc
, i
);
4358 static void skylake_pfit_enable(struct intel_crtc
*crtc
)
4360 struct drm_device
*dev
= crtc
->base
.dev
;
4361 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4362 int pipe
= crtc
->pipe
;
4363 struct intel_crtc_scaler_state
*scaler_state
=
4364 &crtc
->config
->scaler_state
;
4366 DRM_DEBUG_KMS("for crtc_state = %p\n", crtc
->config
);
4368 if (crtc
->config
->pch_pfit
.enabled
) {
4371 if (WARN_ON(crtc
->config
->scaler_state
.scaler_id
< 0)) {
4372 DRM_ERROR("Requesting pfit without getting a scaler first\n");
4376 id
= scaler_state
->scaler_id
;
4377 I915_WRITE(SKL_PS_CTRL(pipe
, id
), PS_SCALER_EN
|
4378 PS_FILTER_MEDIUM
| scaler_state
->scalers
[id
].mode
);
4379 I915_WRITE(SKL_PS_WIN_POS(pipe
, id
), crtc
->config
->pch_pfit
.pos
);
4380 I915_WRITE(SKL_PS_WIN_SZ(pipe
, id
), crtc
->config
->pch_pfit
.size
);
4382 DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc
->config
, id
);
4386 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
4388 struct drm_device
*dev
= crtc
->base
.dev
;
4389 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4390 int pipe
= crtc
->pipe
;
4392 if (crtc
->config
->pch_pfit
.enabled
) {
4393 /* Force use of hard-coded filter coefficients
4394 * as some pre-programmed values are broken,
4397 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
))
4398 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
4399 PF_PIPE_SEL_IVB(pipe
));
4401 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
4402 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
->pch_pfit
.pos
);
4403 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
->pch_pfit
.size
);
4407 void hsw_enable_ips(struct intel_crtc
*crtc
)
4409 struct drm_device
*dev
= crtc
->base
.dev
;
4410 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4412 if (!crtc
->config
->ips_enabled
)
4416 * We can only enable IPS after we enable a plane and wait for a vblank
4417 * This function is called from post_plane_update, which is run after
4421 assert_plane_enabled(dev_priv
, crtc
->plane
);
4422 if (IS_BROADWELL(dev
)) {
4423 mutex_lock(&dev_priv
->rps
.hw_lock
);
4424 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
4425 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4426 /* Quoting Art Runyan: "its not safe to expect any particular
4427 * value in IPS_CTL bit 31 after enabling IPS through the
4428 * mailbox." Moreover, the mailbox may return a bogus state,
4429 * so we need to just enable it and continue on.
4432 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
4433 /* The bit only becomes 1 in the next vblank, so this wait here
4434 * is essentially intel_wait_for_vblank. If we don't have this
4435 * and don't wait for vblanks until the end of crtc_enable, then
4436 * the HW state readout code will complain that the expected
4437 * IPS_CTL value is not the one we read. */
4438 if (wait_for(I915_READ_NOTRACE(IPS_CTL
) & IPS_ENABLE
, 50))
4439 DRM_ERROR("Timed out waiting for IPS enable\n");
4443 void hsw_disable_ips(struct intel_crtc
*crtc
)
4445 struct drm_device
*dev
= crtc
->base
.dev
;
4446 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4448 if (!crtc
->config
->ips_enabled
)
4451 assert_plane_enabled(dev_priv
, crtc
->plane
);
4452 if (IS_BROADWELL(dev
)) {
4453 mutex_lock(&dev_priv
->rps
.hw_lock
);
4454 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
4455 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4456 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4457 if (wait_for((I915_READ(IPS_CTL
) & IPS_ENABLE
) == 0, 42))
4458 DRM_ERROR("Timed out waiting for IPS disable\n");
4460 I915_WRITE(IPS_CTL
, 0);
4461 POSTING_READ(IPS_CTL
);
4464 /* We need to wait for a vblank before we can disable the plane. */
4465 intel_wait_for_vblank(dev
, crtc
->pipe
);
4468 static void intel_crtc_dpms_overlay_disable(struct intel_crtc
*intel_crtc
)
4470 if (intel_crtc
->overlay
) {
4471 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4472 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4474 mutex_lock(&dev
->struct_mutex
);
4475 dev_priv
->mm
.interruptible
= false;
4476 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
4477 dev_priv
->mm
.interruptible
= true;
4478 mutex_unlock(&dev
->struct_mutex
);
4481 /* Let userspace switch the overlay on again. In most cases userspace
4482 * has to recompute where to put it anyway.
4487 * intel_post_enable_primary - Perform operations after enabling primary plane
4488 * @crtc: the CRTC whose primary plane was just enabled
4490 * Performs potentially sleeping operations that must be done after the primary
4491 * plane is enabled, such as updating FBC and IPS. Note that this may be
4492 * called due to an explicit primary plane update, or due to an implicit
4493 * re-enable that is caused when a sprite plane is updated to no longer
4494 * completely hide the primary plane.
4497 intel_post_enable_primary(struct drm_crtc
*crtc
)
4499 struct drm_device
*dev
= crtc
->dev
;
4500 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4501 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4502 int pipe
= intel_crtc
->pipe
;
4505 * FIXME IPS should be fine as long as one plane is
4506 * enabled, but in practice it seems to have problems
4507 * when going from primary only to sprite only and vice
4510 hsw_enable_ips(intel_crtc
);
4513 * Gen2 reports pipe underruns whenever all planes are disabled.
4514 * So don't enable underrun reporting before at least some planes
4516 * FIXME: Need to fix the logic to work when we turn off all planes
4517 * but leave the pipe running.
4520 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4522 /* Underruns don't always raise interrupts, so check manually. */
4523 intel_check_cpu_fifo_underruns(dev_priv
);
4524 intel_check_pch_fifo_underruns(dev_priv
);
4527 /* FIXME move all this to pre_plane_update() with proper state tracking */
4529 intel_pre_disable_primary(struct drm_crtc
*crtc
)
4531 struct drm_device
*dev
= crtc
->dev
;
4532 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4533 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4534 int pipe
= intel_crtc
->pipe
;
4537 * Gen2 reports pipe underruns whenever all planes are disabled.
4538 * So diasble underrun reporting before all the planes get disabled.
4539 * FIXME: Need to fix the logic to work when we turn off all planes
4540 * but leave the pipe running.
4543 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4546 * FIXME IPS should be fine as long as one plane is
4547 * enabled, but in practice it seems to have problems
4548 * when going from primary only to sprite only and vice
4551 hsw_disable_ips(intel_crtc
);
4554 /* FIXME get rid of this and use pre_plane_update */
4556 intel_pre_disable_primary_noatomic(struct drm_crtc
*crtc
)
4558 struct drm_device
*dev
= crtc
->dev
;
4559 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4560 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4561 int pipe
= intel_crtc
->pipe
;
4563 intel_pre_disable_primary(crtc
);
4566 * Vblank time updates from the shadow to live plane control register
4567 * are blocked if the memory self-refresh mode is active at that
4568 * moment. So to make sure the plane gets truly disabled, disable
4569 * first the self-refresh mode. The self-refresh enable bit in turn
4570 * will be checked/applied by the HW only at the next frame start
4571 * event which is after the vblank start event, so we need to have a
4572 * wait-for-vblank between disabling the plane and the pipe.
4574 if (HAS_GMCH_DISPLAY(dev
)) {
4575 intel_set_memory_cxsr(dev_priv
, false);
4576 dev_priv
->wm
.vlv
.cxsr
= false;
4577 intel_wait_for_vblank(dev
, pipe
);
4581 static void intel_post_plane_update(struct intel_crtc_state
*old_crtc_state
)
4583 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
4584 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
4585 struct intel_crtc_state
*pipe_config
=
4586 to_intel_crtc_state(crtc
->base
.state
);
4587 struct drm_device
*dev
= crtc
->base
.dev
;
4588 struct drm_plane
*primary
= crtc
->base
.primary
;
4589 struct drm_plane_state
*old_pri_state
=
4590 drm_atomic_get_existing_plane_state(old_state
, primary
);
4592 intel_frontbuffer_flip(dev
, pipe_config
->fb_bits
);
4594 crtc
->wm
.cxsr_allowed
= true;
4596 if (pipe_config
->update_wm_post
&& pipe_config
->base
.active
)
4597 intel_update_watermarks(&crtc
->base
);
4599 if (old_pri_state
) {
4600 struct intel_plane_state
*primary_state
=
4601 to_intel_plane_state(primary
->state
);
4602 struct intel_plane_state
*old_primary_state
=
4603 to_intel_plane_state(old_pri_state
);
4605 intel_fbc_post_update(crtc
);
4607 if (primary_state
->visible
&&
4608 (needs_modeset(&pipe_config
->base
) ||
4609 !old_primary_state
->visible
))
4610 intel_post_enable_primary(&crtc
->base
);
4614 static void intel_pre_plane_update(struct intel_crtc_state
*old_crtc_state
)
4616 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
4617 struct drm_device
*dev
= crtc
->base
.dev
;
4618 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4619 struct intel_crtc_state
*pipe_config
=
4620 to_intel_crtc_state(crtc
->base
.state
);
4621 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
4622 struct drm_plane
*primary
= crtc
->base
.primary
;
4623 struct drm_plane_state
*old_pri_state
=
4624 drm_atomic_get_existing_plane_state(old_state
, primary
);
4625 bool modeset
= needs_modeset(&pipe_config
->base
);
4627 if (old_pri_state
) {
4628 struct intel_plane_state
*primary_state
=
4629 to_intel_plane_state(primary
->state
);
4630 struct intel_plane_state
*old_primary_state
=
4631 to_intel_plane_state(old_pri_state
);
4633 intel_fbc_pre_update(crtc
);
4635 if (old_primary_state
->visible
&&
4636 (modeset
|| !primary_state
->visible
))
4637 intel_pre_disable_primary(&crtc
->base
);
4640 if (pipe_config
->disable_cxsr
) {
4641 crtc
->wm
.cxsr_allowed
= false;
4644 * Vblank time updates from the shadow to live plane control register
4645 * are blocked if the memory self-refresh mode is active at that
4646 * moment. So to make sure the plane gets truly disabled, disable
4647 * first the self-refresh mode. The self-refresh enable bit in turn
4648 * will be checked/applied by the HW only at the next frame start
4649 * event which is after the vblank start event, so we need to have a
4650 * wait-for-vblank between disabling the plane and the pipe.
4652 if (old_crtc_state
->base
.active
) {
4653 intel_set_memory_cxsr(dev_priv
, false);
4654 dev_priv
->wm
.vlv
.cxsr
= false;
4655 intel_wait_for_vblank(dev
, crtc
->pipe
);
4660 * IVB workaround: must disable low power watermarks for at least
4661 * one frame before enabling scaling. LP watermarks can be re-enabled
4662 * when scaling is disabled.
4664 * WaCxSRDisabledForSpriteScaling:ivb
4666 if (pipe_config
->disable_lp_wm
) {
4667 ilk_disable_lp_wm(dev
);
4668 intel_wait_for_vblank(dev
, crtc
->pipe
);
4672 * If we're doing a modeset, we're done. No need to do any pre-vblank
4673 * watermark programming here.
4675 if (needs_modeset(&pipe_config
->base
))
4679 * For platforms that support atomic watermarks, program the
4680 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
4681 * will be the intermediate values that are safe for both pre- and
4682 * post- vblank; when vblank happens, the 'active' values will be set
4683 * to the final 'target' values and we'll do this again to get the
4684 * optimal watermarks. For gen9+ platforms, the values we program here
4685 * will be the final target values which will get automatically latched
4686 * at vblank time; no further programming will be necessary.
4688 * If a platform hasn't been transitioned to atomic watermarks yet,
4689 * we'll continue to update watermarks the old way, if flags tell
4692 if (dev_priv
->display
.initial_watermarks
!= NULL
)
4693 dev_priv
->display
.initial_watermarks(pipe_config
);
4694 else if (pipe_config
->update_wm_pre
)
4695 intel_update_watermarks(&crtc
->base
);
4698 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
, unsigned plane_mask
)
4700 struct drm_device
*dev
= crtc
->dev
;
4701 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4702 struct drm_plane
*p
;
4703 int pipe
= intel_crtc
->pipe
;
4705 intel_crtc_dpms_overlay_disable(intel_crtc
);
4707 drm_for_each_plane_mask(p
, dev
, plane_mask
)
4708 to_intel_plane(p
)->disable_plane(p
, crtc
);
4711 * FIXME: Once we grow proper nuclear flip support out of this we need
4712 * to compute the mask of flip planes precisely. For the time being
4713 * consider this a flip to a NULL plane.
4715 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_ALL_MASK(pipe
));
4718 static void ironlake_crtc_enable(struct drm_crtc
*crtc
)
4720 struct drm_device
*dev
= crtc
->dev
;
4721 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4722 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4723 struct intel_encoder
*encoder
;
4724 int pipe
= intel_crtc
->pipe
;
4725 struct intel_crtc_state
*pipe_config
=
4726 to_intel_crtc_state(crtc
->state
);
4728 if (WARN_ON(intel_crtc
->active
))
4732 * Sometimes spurious CPU pipe underruns happen during FDI
4733 * training, at least with VGA+HDMI cloning. Suppress them.
4735 * On ILK we get an occasional spurious CPU pipe underruns
4736 * between eDP port A enable and vdd enable. Also PCH port
4737 * enable seems to result in the occasional CPU pipe underrun.
4739 * Spurious PCH underruns also occur during PCH enabling.
4741 if (intel_crtc
->config
->has_pch_encoder
|| IS_GEN5(dev_priv
))
4742 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4743 if (intel_crtc
->config
->has_pch_encoder
)
4744 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
4746 if (intel_crtc
->config
->has_pch_encoder
)
4747 intel_prepare_shared_dpll(intel_crtc
);
4749 if (intel_crtc
->config
->has_dp_encoder
)
4750 intel_dp_set_m_n(intel_crtc
, M1_N1
);
4752 intel_set_pipe_timings(intel_crtc
);
4753 intel_set_pipe_src_size(intel_crtc
);
4755 if (intel_crtc
->config
->has_pch_encoder
) {
4756 intel_cpu_transcoder_set_m_n(intel_crtc
,
4757 &intel_crtc
->config
->fdi_m_n
, NULL
);
4760 ironlake_set_pipeconf(crtc
);
4762 intel_crtc
->active
= true;
4764 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4765 if (encoder
->pre_enable
)
4766 encoder
->pre_enable(encoder
);
4768 if (intel_crtc
->config
->has_pch_encoder
) {
4769 /* Note: FDI PLL enabling _must_ be done before we enable the
4770 * cpu pipes, hence this is separate from all the other fdi/pch
4772 ironlake_fdi_pll_enable(intel_crtc
);
4774 assert_fdi_tx_disabled(dev_priv
, pipe
);
4775 assert_fdi_rx_disabled(dev_priv
, pipe
);
4778 ironlake_pfit_enable(intel_crtc
);
4781 * On ILK+ LUT must be loaded before the pipe is running but with
4784 intel_color_load_luts(&pipe_config
->base
);
4786 if (dev_priv
->display
.initial_watermarks
!= NULL
)
4787 dev_priv
->display
.initial_watermarks(intel_crtc
->config
);
4788 intel_enable_pipe(intel_crtc
);
4790 if (intel_crtc
->config
->has_pch_encoder
)
4791 ironlake_pch_enable(crtc
);
4793 assert_vblank_disabled(crtc
);
4794 drm_crtc_vblank_on(crtc
);
4796 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4797 encoder
->enable(encoder
);
4799 if (HAS_PCH_CPT(dev
))
4800 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
4802 /* Must wait for vblank to avoid spurious PCH FIFO underruns */
4803 if (intel_crtc
->config
->has_pch_encoder
)
4804 intel_wait_for_vblank(dev
, pipe
);
4805 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4806 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
4809 /* IPS only exists on ULT machines and is tied to pipe A. */
4810 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
4812 return HAS_IPS(crtc
->base
.dev
) && crtc
->pipe
== PIPE_A
;
4815 static void haswell_crtc_enable(struct drm_crtc
*crtc
)
4817 struct drm_device
*dev
= crtc
->dev
;
4818 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4819 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4820 struct intel_encoder
*encoder
;
4821 int pipe
= intel_crtc
->pipe
, hsw_workaround_pipe
;
4822 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
4823 struct intel_crtc_state
*pipe_config
=
4824 to_intel_crtc_state(crtc
->state
);
4826 if (WARN_ON(intel_crtc
->active
))
4829 if (intel_crtc
->config
->has_pch_encoder
)
4830 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
4833 if (intel_crtc
->config
->shared_dpll
)
4834 intel_enable_shared_dpll(intel_crtc
);
4836 if (intel_crtc
->config
->has_dp_encoder
)
4837 intel_dp_set_m_n(intel_crtc
, M1_N1
);
4839 if (!intel_crtc
->config
->has_dsi_encoder
)
4840 intel_set_pipe_timings(intel_crtc
);
4842 intel_set_pipe_src_size(intel_crtc
);
4844 if (cpu_transcoder
!= TRANSCODER_EDP
&&
4845 !transcoder_is_dsi(cpu_transcoder
)) {
4846 I915_WRITE(PIPE_MULT(cpu_transcoder
),
4847 intel_crtc
->config
->pixel_multiplier
- 1);
4850 if (intel_crtc
->config
->has_pch_encoder
) {
4851 intel_cpu_transcoder_set_m_n(intel_crtc
,
4852 &intel_crtc
->config
->fdi_m_n
, NULL
);
4855 if (!intel_crtc
->config
->has_dsi_encoder
)
4856 haswell_set_pipeconf(crtc
);
4858 haswell_set_pipemisc(crtc
);
4860 intel_color_set_csc(&pipe_config
->base
);
4862 intel_crtc
->active
= true;
4864 if (intel_crtc
->config
->has_pch_encoder
)
4865 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4867 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4869 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4870 if (encoder
->pre_enable
)
4871 encoder
->pre_enable(encoder
);
4874 if (intel_crtc
->config
->has_pch_encoder
)
4875 dev_priv
->display
.fdi_link_train(crtc
);
4877 if (!intel_crtc
->config
->has_dsi_encoder
)
4878 intel_ddi_enable_pipe_clock(intel_crtc
);
4880 if (INTEL_INFO(dev
)->gen
>= 9)
4881 skylake_pfit_enable(intel_crtc
);
4883 ironlake_pfit_enable(intel_crtc
);
4886 * On ILK+ LUT must be loaded before the pipe is running but with
4889 intel_color_load_luts(&pipe_config
->base
);
4891 intel_ddi_set_pipe_settings(crtc
);
4892 if (!intel_crtc
->config
->has_dsi_encoder
)
4893 intel_ddi_enable_transcoder_func(crtc
);
4895 if (dev_priv
->display
.initial_watermarks
!= NULL
)
4896 dev_priv
->display
.initial_watermarks(pipe_config
);
4898 intel_update_watermarks(crtc
);
4900 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
4901 if (!intel_crtc
->config
->has_dsi_encoder
)
4902 intel_enable_pipe(intel_crtc
);
4904 if (intel_crtc
->config
->has_pch_encoder
)
4905 lpt_pch_enable(crtc
);
4907 if (intel_crtc
->config
->dp_encoder_is_mst
)
4908 intel_ddi_set_vc_payload_alloc(crtc
, true);
4910 assert_vblank_disabled(crtc
);
4911 drm_crtc_vblank_on(crtc
);
4913 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4914 encoder
->enable(encoder
);
4915 intel_opregion_notify_encoder(encoder
, true);
4918 if (intel_crtc
->config
->has_pch_encoder
) {
4919 intel_wait_for_vblank(dev
, pipe
);
4920 intel_wait_for_vblank(dev
, pipe
);
4921 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4922 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
4926 /* If we change the relative order between pipe/planes enabling, we need
4927 * to change the workaround. */
4928 hsw_workaround_pipe
= pipe_config
->hsw_workaround_pipe
;
4929 if (IS_HASWELL(dev
) && hsw_workaround_pipe
!= INVALID_PIPE
) {
4930 intel_wait_for_vblank(dev
, hsw_workaround_pipe
);
4931 intel_wait_for_vblank(dev
, hsw_workaround_pipe
);
4935 static void ironlake_pfit_disable(struct intel_crtc
*crtc
, bool force
)
4937 struct drm_device
*dev
= crtc
->base
.dev
;
4938 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4939 int pipe
= crtc
->pipe
;
4941 /* To avoid upsetting the power well on haswell only disable the pfit if
4942 * it's in use. The hw state code will make sure we get this right. */
4943 if (force
|| crtc
->config
->pch_pfit
.enabled
) {
4944 I915_WRITE(PF_CTL(pipe
), 0);
4945 I915_WRITE(PF_WIN_POS(pipe
), 0);
4946 I915_WRITE(PF_WIN_SZ(pipe
), 0);
4950 static void ironlake_crtc_disable(struct drm_crtc
*crtc
)
4952 struct drm_device
*dev
= crtc
->dev
;
4953 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4954 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4955 struct intel_encoder
*encoder
;
4956 int pipe
= intel_crtc
->pipe
;
4959 * Sometimes spurious CPU pipe underruns happen when the
4960 * pipe is already disabled, but FDI RX/TX is still enabled.
4961 * Happens at least with VGA+HDMI cloning. Suppress them.
4963 if (intel_crtc
->config
->has_pch_encoder
) {
4964 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4965 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
4968 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4969 encoder
->disable(encoder
);
4971 drm_crtc_vblank_off(crtc
);
4972 assert_vblank_disabled(crtc
);
4974 intel_disable_pipe(intel_crtc
);
4976 ironlake_pfit_disable(intel_crtc
, false);
4978 if (intel_crtc
->config
->has_pch_encoder
)
4979 ironlake_fdi_disable(crtc
);
4981 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4982 if (encoder
->post_disable
)
4983 encoder
->post_disable(encoder
);
4985 if (intel_crtc
->config
->has_pch_encoder
) {
4986 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
4988 if (HAS_PCH_CPT(dev
)) {
4992 /* disable TRANS_DP_CTL */
4993 reg
= TRANS_DP_CTL(pipe
);
4994 temp
= I915_READ(reg
);
4995 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
4996 TRANS_DP_PORT_SEL_MASK
);
4997 temp
|= TRANS_DP_PORT_SEL_NONE
;
4998 I915_WRITE(reg
, temp
);
5000 /* disable DPLL_SEL */
5001 temp
= I915_READ(PCH_DPLL_SEL
);
5002 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
5003 I915_WRITE(PCH_DPLL_SEL
, temp
);
5006 ironlake_fdi_pll_disable(intel_crtc
);
5009 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5010 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
5013 static void haswell_crtc_disable(struct drm_crtc
*crtc
)
5015 struct drm_device
*dev
= crtc
->dev
;
5016 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5017 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5018 struct intel_encoder
*encoder
;
5019 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5021 if (intel_crtc
->config
->has_pch_encoder
)
5022 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5025 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5026 intel_opregion_notify_encoder(encoder
, false);
5027 encoder
->disable(encoder
);
5030 drm_crtc_vblank_off(crtc
);
5031 assert_vblank_disabled(crtc
);
5033 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5034 if (!intel_crtc
->config
->has_dsi_encoder
)
5035 intel_disable_pipe(intel_crtc
);
5037 if (intel_crtc
->config
->dp_encoder_is_mst
)
5038 intel_ddi_set_vc_payload_alloc(crtc
, false);
5040 if (!intel_crtc
->config
->has_dsi_encoder
)
5041 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
5043 if (INTEL_INFO(dev
)->gen
>= 9)
5044 skylake_scaler_disable(intel_crtc
);
5046 ironlake_pfit_disable(intel_crtc
, false);
5048 if (!intel_crtc
->config
->has_dsi_encoder
)
5049 intel_ddi_disable_pipe_clock(intel_crtc
);
5051 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5052 if (encoder
->post_disable
)
5053 encoder
->post_disable(encoder
);
5055 if (intel_crtc
->config
->has_pch_encoder
) {
5056 lpt_disable_pch_transcoder(dev_priv
);
5057 lpt_disable_iclkip(dev_priv
);
5058 intel_ddi_fdi_disable(crtc
);
5060 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5065 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
5067 struct drm_device
*dev
= crtc
->base
.dev
;
5068 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5069 struct intel_crtc_state
*pipe_config
= crtc
->config
;
5071 if (!pipe_config
->gmch_pfit
.control
)
5075 * The panel fitter should only be adjusted whilst the pipe is disabled,
5076 * according to register description and PRM.
5078 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
5079 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5081 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
5082 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
5084 /* Border color in case we don't scale up to the full screen. Black by
5085 * default, change to something else for debugging. */
5086 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
5089 static enum intel_display_power_domain
port_to_power_domain(enum port port
)
5093 return POWER_DOMAIN_PORT_DDI_A_LANES
;
5095 return POWER_DOMAIN_PORT_DDI_B_LANES
;
5097 return POWER_DOMAIN_PORT_DDI_C_LANES
;
5099 return POWER_DOMAIN_PORT_DDI_D_LANES
;
5101 return POWER_DOMAIN_PORT_DDI_E_LANES
;
5104 return POWER_DOMAIN_PORT_OTHER
;
5108 static enum intel_display_power_domain
port_to_aux_power_domain(enum port port
)
5112 return POWER_DOMAIN_AUX_A
;
5114 return POWER_DOMAIN_AUX_B
;
5116 return POWER_DOMAIN_AUX_C
;
5118 return POWER_DOMAIN_AUX_D
;
5120 /* FIXME: Check VBT for actual wiring of PORT E */
5121 return POWER_DOMAIN_AUX_D
;
5124 return POWER_DOMAIN_AUX_A
;
5128 enum intel_display_power_domain
5129 intel_display_port_power_domain(struct intel_encoder
*intel_encoder
)
5131 struct drm_device
*dev
= intel_encoder
->base
.dev
;
5132 struct intel_digital_port
*intel_dig_port
;
5134 switch (intel_encoder
->type
) {
5135 case INTEL_OUTPUT_UNKNOWN
:
5136 /* Only DDI platforms should ever use this output type */
5137 WARN_ON_ONCE(!HAS_DDI(dev
));
5138 case INTEL_OUTPUT_DISPLAYPORT
:
5139 case INTEL_OUTPUT_HDMI
:
5140 case INTEL_OUTPUT_EDP
:
5141 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
5142 return port_to_power_domain(intel_dig_port
->port
);
5143 case INTEL_OUTPUT_DP_MST
:
5144 intel_dig_port
= enc_to_mst(&intel_encoder
->base
)->primary
;
5145 return port_to_power_domain(intel_dig_port
->port
);
5146 case INTEL_OUTPUT_ANALOG
:
5147 return POWER_DOMAIN_PORT_CRT
;
5148 case INTEL_OUTPUT_DSI
:
5149 return POWER_DOMAIN_PORT_DSI
;
5151 return POWER_DOMAIN_PORT_OTHER
;
5155 enum intel_display_power_domain
5156 intel_display_port_aux_power_domain(struct intel_encoder
*intel_encoder
)
5158 struct drm_device
*dev
= intel_encoder
->base
.dev
;
5159 struct intel_digital_port
*intel_dig_port
;
5161 switch (intel_encoder
->type
) {
5162 case INTEL_OUTPUT_UNKNOWN
:
5163 case INTEL_OUTPUT_HDMI
:
5165 * Only DDI platforms should ever use these output types.
5166 * We can get here after the HDMI detect code has already set
5167 * the type of the shared encoder. Since we can't be sure
5168 * what's the status of the given connectors, play safe and
5169 * run the DP detection too.
5171 WARN_ON_ONCE(!HAS_DDI(dev
));
5172 case INTEL_OUTPUT_DISPLAYPORT
:
5173 case INTEL_OUTPUT_EDP
:
5174 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
5175 return port_to_aux_power_domain(intel_dig_port
->port
);
5176 case INTEL_OUTPUT_DP_MST
:
5177 intel_dig_port
= enc_to_mst(&intel_encoder
->base
)->primary
;
5178 return port_to_aux_power_domain(intel_dig_port
->port
);
5180 MISSING_CASE(intel_encoder
->type
);
5181 return POWER_DOMAIN_AUX_A
;
5185 static unsigned long get_crtc_power_domains(struct drm_crtc
*crtc
,
5186 struct intel_crtc_state
*crtc_state
)
5188 struct drm_device
*dev
= crtc
->dev
;
5189 struct drm_encoder
*encoder
;
5190 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5191 enum pipe pipe
= intel_crtc
->pipe
;
5193 enum transcoder transcoder
= crtc_state
->cpu_transcoder
;
5195 if (!crtc_state
->base
.active
)
5198 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
5199 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
5200 if (crtc_state
->pch_pfit
.enabled
||
5201 crtc_state
->pch_pfit
.force_thru
)
5202 mask
|= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
5204 drm_for_each_encoder_mask(encoder
, dev
, crtc_state
->base
.encoder_mask
) {
5205 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5207 mask
|= BIT(intel_display_port_power_domain(intel_encoder
));
5210 if (crtc_state
->shared_dpll
)
5211 mask
|= BIT(POWER_DOMAIN_PLLS
);
5216 static unsigned long
5217 modeset_get_crtc_power_domains(struct drm_crtc
*crtc
,
5218 struct intel_crtc_state
*crtc_state
)
5220 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
5221 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5222 enum intel_display_power_domain domain
;
5223 unsigned long domains
, new_domains
, old_domains
;
5225 old_domains
= intel_crtc
->enabled_power_domains
;
5226 intel_crtc
->enabled_power_domains
= new_domains
=
5227 get_crtc_power_domains(crtc
, crtc_state
);
5229 domains
= new_domains
& ~old_domains
;
5231 for_each_power_domain(domain
, domains
)
5232 intel_display_power_get(dev_priv
, domain
);
5234 return old_domains
& ~new_domains
;
5237 static void modeset_put_power_domains(struct drm_i915_private
*dev_priv
,
5238 unsigned long domains
)
5240 enum intel_display_power_domain domain
;
5242 for_each_power_domain(domain
, domains
)
5243 intel_display_power_put(dev_priv
, domain
);
5246 static int intel_compute_max_dotclk(struct drm_i915_private
*dev_priv
)
5248 int max_cdclk_freq
= dev_priv
->max_cdclk_freq
;
5250 if (INTEL_INFO(dev_priv
)->gen
>= 9 ||
5251 IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
5252 return max_cdclk_freq
;
5253 else if (IS_CHERRYVIEW(dev_priv
))
5254 return max_cdclk_freq
*95/100;
5255 else if (INTEL_INFO(dev_priv
)->gen
< 4)
5256 return 2*max_cdclk_freq
*90/100;
5258 return max_cdclk_freq
*90/100;
5261 static void intel_update_max_cdclk(struct drm_device
*dev
)
5263 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5265 if (IS_SKYLAKE(dev
) || IS_KABYLAKE(dev
)) {
5266 u32 limit
= I915_READ(SKL_DFSM
) & SKL_DFSM_CDCLK_LIMIT_MASK
;
5268 if (limit
== SKL_DFSM_CDCLK_LIMIT_675
)
5269 dev_priv
->max_cdclk_freq
= 675000;
5270 else if (limit
== SKL_DFSM_CDCLK_LIMIT_540
)
5271 dev_priv
->max_cdclk_freq
= 540000;
5272 else if (limit
== SKL_DFSM_CDCLK_LIMIT_450
)
5273 dev_priv
->max_cdclk_freq
= 450000;
5275 dev_priv
->max_cdclk_freq
= 337500;
5276 } else if (IS_BROXTON(dev
)) {
5277 dev_priv
->max_cdclk_freq
= 624000;
5278 } else if (IS_BROADWELL(dev
)) {
5280 * FIXME with extra cooling we can allow
5281 * 540 MHz for ULX and 675 Mhz for ULT.
5282 * How can we know if extra cooling is
5283 * available? PCI ID, VTB, something else?
5285 if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
5286 dev_priv
->max_cdclk_freq
= 450000;
5287 else if (IS_BDW_ULX(dev
))
5288 dev_priv
->max_cdclk_freq
= 450000;
5289 else if (IS_BDW_ULT(dev
))
5290 dev_priv
->max_cdclk_freq
= 540000;
5292 dev_priv
->max_cdclk_freq
= 675000;
5293 } else if (IS_CHERRYVIEW(dev
)) {
5294 dev_priv
->max_cdclk_freq
= 320000;
5295 } else if (IS_VALLEYVIEW(dev
)) {
5296 dev_priv
->max_cdclk_freq
= 400000;
5298 /* otherwise assume cdclk is fixed */
5299 dev_priv
->max_cdclk_freq
= dev_priv
->cdclk_freq
;
5302 dev_priv
->max_dotclk_freq
= intel_compute_max_dotclk(dev_priv
);
5304 DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n",
5305 dev_priv
->max_cdclk_freq
);
5307 DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n",
5308 dev_priv
->max_dotclk_freq
);
5311 static void intel_update_cdclk(struct drm_device
*dev
)
5313 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5315 dev_priv
->cdclk_freq
= dev_priv
->display
.get_display_clock_speed(dev
);
5316 DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n",
5317 dev_priv
->cdclk_freq
);
5320 * 9:0 CMBUS [sic] CDCLK frequency (cdfreq):
5321 * Programmng [sic] note: bit[9:2] should be programmed to the number
5322 * of cdclk that generates 4MHz reference clock freq which is used to
5323 * generate GMBus clock. This will vary with the cdclk freq.
5325 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
5326 I915_WRITE(GMBUSFREQ_VLV
, DIV_ROUND_UP(dev_priv
->cdclk_freq
, 1000));
5328 if (dev_priv
->max_cdclk_freq
== 0)
5329 intel_update_max_cdclk(dev
);
5332 /* convert from kHz to .1 fixpoint MHz with -1MHz offset */
5333 static int skl_cdclk_decimal(int cdclk
)
5335 return DIV_ROUND_CLOSEST(cdclk
- 1000, 500);
5338 static void broxton_set_cdclk(struct drm_i915_private
*dev_priv
, int cdclk
)
5342 uint32_t current_cdclk
;
5345 /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */
5348 divider
= BXT_CDCLK_CD2X_DIV_SEL_4
;
5349 ratio
= BXT_DE_PLL_RATIO(60);
5352 divider
= BXT_CDCLK_CD2X_DIV_SEL_2
;
5353 ratio
= BXT_DE_PLL_RATIO(60);
5356 divider
= BXT_CDCLK_CD2X_DIV_SEL_1_5
;
5357 ratio
= BXT_DE_PLL_RATIO(60);
5360 divider
= BXT_CDCLK_CD2X_DIV_SEL_1
;
5361 ratio
= BXT_DE_PLL_RATIO(60);
5364 divider
= BXT_CDCLK_CD2X_DIV_SEL_1
;
5365 ratio
= BXT_DE_PLL_RATIO(65);
5369 * Bypass frequency with DE PLL disabled. Init ratio, divider
5370 * to suppress GCC warning.
5376 DRM_ERROR("unsupported CDCLK freq %d", cdclk
);
5381 mutex_lock(&dev_priv
->rps
.hw_lock
);
5382 /* Inform power controller of upcoming frequency change */
5383 ret
= sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
,
5385 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5388 DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n",
5393 current_cdclk
= I915_READ(CDCLK_CTL
) & CDCLK_FREQ_DECIMAL_MASK
;
5394 /* convert from .1 fixpoint MHz with -1MHz offset to kHz */
5395 current_cdclk
= current_cdclk
* 500 + 1000;
5398 * DE PLL has to be disabled when
5399 * - setting to 19.2MHz (bypass, PLL isn't used)
5400 * - before setting to 624MHz (PLL needs toggling)
5401 * - before setting to any frequency from 624MHz (PLL needs toggling)
5403 if (cdclk
== 19200 || cdclk
== 624000 ||
5404 current_cdclk
== 624000) {
5405 I915_WRITE(BXT_DE_PLL_ENABLE
, ~BXT_DE_PLL_PLL_ENABLE
);
5407 if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_LOCK
),
5409 DRM_ERROR("timout waiting for DE PLL unlock\n");
5412 if (cdclk
!= 19200) {
5415 val
= I915_READ(BXT_DE_PLL_CTL
);
5416 val
&= ~BXT_DE_PLL_RATIO_MASK
;
5418 I915_WRITE(BXT_DE_PLL_CTL
, val
);
5420 I915_WRITE(BXT_DE_PLL_ENABLE
, BXT_DE_PLL_PLL_ENABLE
);
5422 if (wait_for(I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_LOCK
, 1))
5423 DRM_ERROR("timeout waiting for DE PLL lock\n");
5425 val
= divider
| skl_cdclk_decimal(cdclk
);
5427 * FIXME if only the cd2x divider needs changing, it could be done
5428 * without shutting off the pipe (if only one pipe is active).
5430 val
|= BXT_CDCLK_CD2X_PIPE_NONE
;
5432 * Disable SSA Precharge when CD clock frequency < 500 MHz,
5435 if (cdclk
>= 500000)
5436 val
|= BXT_CDCLK_SSA_PRECHARGE_ENABLE
;
5437 I915_WRITE(CDCLK_CTL
, val
);
5440 mutex_lock(&dev_priv
->rps
.hw_lock
);
5441 ret
= sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
,
5442 DIV_ROUND_UP(cdclk
, 25000));
5443 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5446 DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n",
5451 intel_update_cdclk(dev_priv
->dev
);
5454 static bool broxton_cdclk_is_enabled(struct drm_i915_private
*dev_priv
)
5456 if (!(I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_PLL_ENABLE
))
5459 /* TODO: Check for a valid CDCLK rate */
5461 if (!(I915_READ(DBUF_CTL
) & DBUF_POWER_REQUEST
)) {
5462 DRM_DEBUG_DRIVER("CDCLK enabled, but DBUF power not requested\n");
5467 if (!(I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
)) {
5468 DRM_DEBUG_DRIVER("CDCLK enabled, but DBUF power hasn't settled\n");
5476 bool broxton_cdclk_verify_state(struct drm_i915_private
*dev_priv
)
5478 return broxton_cdclk_is_enabled(dev_priv
);
5481 void broxton_init_cdclk(struct drm_i915_private
*dev_priv
)
5483 /* check if cd clock is enabled */
5484 if (broxton_cdclk_is_enabled(dev_priv
)) {
5485 DRM_DEBUG_KMS("CDCLK already enabled, won't reprogram it\n");
5489 DRM_DEBUG_KMS("CDCLK not enabled, enabling it\n");
5493 * - The initial CDCLK needs to be read from VBT.
5494 * Need to make this change after VBT has changes for BXT.
5495 * - check if setting the max (or any) cdclk freq is really necessary
5496 * here, it belongs to modeset time
5498 broxton_set_cdclk(dev_priv
, 624000);
5500 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) | DBUF_POWER_REQUEST
);
5501 POSTING_READ(DBUF_CTL
);
5505 if (!(I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
))
5506 DRM_ERROR("DBuf power enable timeout!\n");
5509 void broxton_uninit_cdclk(struct drm_i915_private
*dev_priv
)
5511 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) & ~DBUF_POWER_REQUEST
);
5512 POSTING_READ(DBUF_CTL
);
5516 if (I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
)
5517 DRM_ERROR("DBuf power disable timeout!\n");
5519 /* Set minimum (bypass) frequency, in effect turning off the DE PLL */
5520 broxton_set_cdclk(dev_priv
, 19200);
5523 static const struct skl_cdclk_entry
{
5526 } skl_cdclk_frequencies
[] = {
5527 { .freq
= 308570, .vco
= 8640 },
5528 { .freq
= 337500, .vco
= 8100 },
5529 { .freq
= 432000, .vco
= 8640 },
5530 { .freq
= 450000, .vco
= 8100 },
5531 { .freq
= 540000, .vco
= 8100 },
5532 { .freq
= 617140, .vco
= 8640 },
5533 { .freq
= 675000, .vco
= 8100 },
5536 static unsigned int skl_cdclk_get_vco(unsigned int freq
)
5540 for (i
= 0; i
< ARRAY_SIZE(skl_cdclk_frequencies
); i
++) {
5541 const struct skl_cdclk_entry
*e
= &skl_cdclk_frequencies
[i
];
5543 if (e
->freq
== freq
)
5551 skl_dpll0_enable(struct drm_i915_private
*dev_priv
, int vco
)
5556 /* select the minimum CDCLK before enabling DPLL 0 */
5562 val
= CDCLK_FREQ_337_308
| skl_cdclk_decimal(min_cdclk
);
5563 I915_WRITE(CDCLK_CTL
, val
);
5564 POSTING_READ(CDCLK_CTL
);
5567 * We always enable DPLL0 with the lowest link rate possible, but still
5568 * taking into account the VCO required to operate the eDP panel at the
5569 * desired frequency. The usual DP link rates operate with a VCO of
5570 * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640.
5571 * The modeset code is responsible for the selection of the exact link
5572 * rate later on, with the constraint of choosing a frequency that
5573 * works with required_vco.
5575 val
= I915_READ(DPLL_CTRL1
);
5577 val
&= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0
) | DPLL_CTRL1_SSC(SKL_DPLL0
) |
5578 DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
));
5579 val
|= DPLL_CTRL1_OVERRIDE(SKL_DPLL0
);
5581 val
|= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080
,
5584 val
|= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810
,
5587 I915_WRITE(DPLL_CTRL1
, val
);
5588 POSTING_READ(DPLL_CTRL1
);
5590 I915_WRITE(LCPLL1_CTL
, I915_READ(LCPLL1_CTL
) | LCPLL_PLL_ENABLE
);
5592 if (wait_for(I915_READ(LCPLL1_CTL
) & LCPLL_PLL_LOCK
, 5))
5593 DRM_ERROR("DPLL0 not locked\n");
5597 skl_dpll0_disable(struct drm_i915_private
*dev_priv
)
5599 I915_WRITE(LCPLL1_CTL
, I915_READ(LCPLL1_CTL
) & ~LCPLL_PLL_ENABLE
);
5600 if (wait_for(!(I915_READ(LCPLL1_CTL
) & LCPLL_PLL_LOCK
), 1))
5601 DRM_ERROR("Couldn't disable DPLL0\n");
5604 static bool skl_cdclk_pcu_ready(struct drm_i915_private
*dev_priv
)
5609 /* inform PCU we want to change CDCLK */
5610 val
= SKL_CDCLK_PREPARE_FOR_CHANGE
;
5611 mutex_lock(&dev_priv
->rps
.hw_lock
);
5612 ret
= sandybridge_pcode_read(dev_priv
, SKL_PCODE_CDCLK_CONTROL
, &val
);
5613 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5615 return ret
== 0 && (val
& SKL_CDCLK_READY_FOR_CHANGE
);
5618 static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private
*dev_priv
)
5622 for (i
= 0; i
< 15; i
++) {
5623 if (skl_cdclk_pcu_ready(dev_priv
))
5631 static void skl_set_cdclk(struct drm_i915_private
*dev_priv
, int cdclk
)
5633 struct drm_device
*dev
= dev_priv
->dev
;
5634 u32 freq_select
, pcu_ack
;
5636 DRM_DEBUG_DRIVER("Changing CDCLK to %dKHz\n", cdclk
);
5638 if (!skl_cdclk_wait_for_pcu_ready(dev_priv
)) {
5639 DRM_ERROR("failed to inform PCU about cdclk change\n");
5647 freq_select
= CDCLK_FREQ_450_432
;
5651 freq_select
= CDCLK_FREQ_540
;
5657 freq_select
= CDCLK_FREQ_337_308
;
5662 freq_select
= CDCLK_FREQ_675_617
;
5667 I915_WRITE(CDCLK_CTL
, freq_select
| skl_cdclk_decimal(cdclk
));
5668 POSTING_READ(CDCLK_CTL
);
5670 /* inform PCU of the change */
5671 mutex_lock(&dev_priv
->rps
.hw_lock
);
5672 sandybridge_pcode_write(dev_priv
, SKL_PCODE_CDCLK_CONTROL
, pcu_ack
);
5673 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5675 intel_update_cdclk(dev
);
5678 void skl_uninit_cdclk(struct drm_i915_private
*dev_priv
)
5680 /* disable DBUF power */
5681 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) & ~DBUF_POWER_REQUEST
);
5682 POSTING_READ(DBUF_CTL
);
5686 if (I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
)
5687 DRM_ERROR("DBuf power disable timeout\n");
5689 skl_dpll0_disable(dev_priv
);
5692 void skl_init_cdclk(struct drm_i915_private
*dev_priv
)
5696 /* DPLL0 not enabled (happens on early BIOS versions) */
5697 if (!(I915_READ(LCPLL1_CTL
) & LCPLL_PLL_ENABLE
)) {
5699 vco
= skl_cdclk_get_vco(dev_priv
->skl_boot_cdclk
);
5700 skl_dpll0_enable(dev_priv
, vco
);
5703 /* set CDCLK to the frequency the BIOS chose */
5704 skl_set_cdclk(dev_priv
, dev_priv
->skl_boot_cdclk
);
5706 /* enable DBUF power */
5707 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) | DBUF_POWER_REQUEST
);
5708 POSTING_READ(DBUF_CTL
);
5712 if (!(I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
))
5713 DRM_ERROR("DBuf power enable timeout\n");
5716 int skl_sanitize_cdclk(struct drm_i915_private
*dev_priv
)
5718 uint32_t lcpll1
= I915_READ(LCPLL1_CTL
);
5719 uint32_t cdctl
= I915_READ(CDCLK_CTL
);
5720 int freq
= dev_priv
->skl_boot_cdclk
;
5723 * check if the pre-os intialized the display
5724 * There is SWF18 scratchpad register defined which is set by the
5725 * pre-os which can be used by the OS drivers to check the status
5727 if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0)
5730 /* Is PLL enabled and locked ? */
5731 if (!((lcpll1
& LCPLL_PLL_ENABLE
) && (lcpll1
& LCPLL_PLL_LOCK
)))
5734 /* DPLL okay; verify the cdclock
5736 * Noticed in some instances that the freq selection is correct but
5737 * decimal part is programmed wrong from BIOS where pre-os does not
5738 * enable display. Verify the same as well.
5740 if (cdctl
== ((cdctl
& CDCLK_FREQ_SEL_MASK
) | skl_cdclk_decimal(freq
)))
5741 /* All well; nothing to sanitize */
5745 * As of now initialize with max cdclk till
5746 * we get dynamic cdclk support
5748 dev_priv
->skl_boot_cdclk
= dev_priv
->max_cdclk_freq
;
5749 skl_init_cdclk(dev_priv
);
5751 /* we did have to sanitize */
5755 /* Adjust CDclk dividers to allow high res or save power if possible */
5756 static void valleyview_set_cdclk(struct drm_device
*dev
, int cdclk
)
5758 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5761 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
)
5762 != dev_priv
->cdclk_freq
);
5764 if (cdclk
>= 320000) /* jump to highest voltage for 400MHz too */
5766 else if (cdclk
== 266667)
5771 mutex_lock(&dev_priv
->rps
.hw_lock
);
5772 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
5773 val
&= ~DSPFREQGUAR_MASK
;
5774 val
|= (cmd
<< DSPFREQGUAR_SHIFT
);
5775 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
5776 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
5777 DSPFREQSTAT_MASK
) == (cmd
<< DSPFREQSTAT_SHIFT
),
5779 DRM_ERROR("timed out waiting for CDclk change\n");
5781 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5783 mutex_lock(&dev_priv
->sb_lock
);
5785 if (cdclk
== 400000) {
5788 divider
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
5790 /* adjust cdclk divider */
5791 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
5792 val
&= ~CCK_FREQUENCY_VALUES
;
5794 vlv_cck_write(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
, val
);
5796 if (wait_for((vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
) &
5797 CCK_FREQUENCY_STATUS
) == (divider
<< CCK_FREQUENCY_STATUS_SHIFT
),
5799 DRM_ERROR("timed out waiting for CDclk change\n");
5802 /* adjust self-refresh exit latency value */
5803 val
= vlv_bunit_read(dev_priv
, BUNIT_REG_BISOC
);
5807 * For high bandwidth configs, we set a higher latency in the bunit
5808 * so that the core display fetch happens in time to avoid underruns.
5810 if (cdclk
== 400000)
5811 val
|= 4500 / 250; /* 4.5 usec */
5813 val
|= 3000 / 250; /* 3.0 usec */
5814 vlv_bunit_write(dev_priv
, BUNIT_REG_BISOC
, val
);
5816 mutex_unlock(&dev_priv
->sb_lock
);
5818 intel_update_cdclk(dev
);
5821 static void cherryview_set_cdclk(struct drm_device
*dev
, int cdclk
)
5823 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5826 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
)
5827 != dev_priv
->cdclk_freq
);
5836 MISSING_CASE(cdclk
);
5841 * Specs are full of misinformation, but testing on actual
5842 * hardware has shown that we just need to write the desired
5843 * CCK divider into the Punit register.
5845 cmd
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
5847 mutex_lock(&dev_priv
->rps
.hw_lock
);
5848 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
5849 val
&= ~DSPFREQGUAR_MASK_CHV
;
5850 val
|= (cmd
<< DSPFREQGUAR_SHIFT_CHV
);
5851 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
5852 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
5853 DSPFREQSTAT_MASK_CHV
) == (cmd
<< DSPFREQSTAT_SHIFT_CHV
),
5855 DRM_ERROR("timed out waiting for CDclk change\n");
5857 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5859 intel_update_cdclk(dev
);
5862 static int valleyview_calc_cdclk(struct drm_i915_private
*dev_priv
,
5865 int freq_320
= (dev_priv
->hpll_freq
<< 1) % 320000 != 0 ? 333333 : 320000;
5866 int limit
= IS_CHERRYVIEW(dev_priv
) ? 95 : 90;
5869 * Really only a few cases to deal with, as only 4 CDclks are supported:
5872 * 320/333MHz (depends on HPLL freq)
5874 * So we check to see whether we're above 90% (VLV) or 95% (CHV)
5875 * of the lower bin and adjust if needed.
5877 * We seem to get an unstable or solid color picture at 200MHz.
5878 * Not sure what's wrong. For now use 200MHz only when all pipes
5881 if (!IS_CHERRYVIEW(dev_priv
) &&
5882 max_pixclk
> freq_320
*limit
/100)
5884 else if (max_pixclk
> 266667*limit
/100)
5886 else if (max_pixclk
> 0)
5892 static int broxton_calc_cdclk(int max_pixclk
)
5896 * - set 19.2MHz bypass frequency if there are no active pipes
5898 if (max_pixclk
> 576000)
5900 else if (max_pixclk
> 384000)
5902 else if (max_pixclk
> 288000)
5904 else if (max_pixclk
> 144000)
5910 /* Compute the max pixel clock for new configuration. */
5911 static int intel_mode_max_pixclk(struct drm_device
*dev
,
5912 struct drm_atomic_state
*state
)
5914 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
5915 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5916 struct drm_crtc
*crtc
;
5917 struct drm_crtc_state
*crtc_state
;
5918 unsigned max_pixclk
= 0, i
;
5921 memcpy(intel_state
->min_pixclk
, dev_priv
->min_pixclk
,
5922 sizeof(intel_state
->min_pixclk
));
5924 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
5927 if (crtc_state
->enable
)
5928 pixclk
= crtc_state
->adjusted_mode
.crtc_clock
;
5930 intel_state
->min_pixclk
[i
] = pixclk
;
5933 for_each_pipe(dev_priv
, pipe
)
5934 max_pixclk
= max(intel_state
->min_pixclk
[pipe
], max_pixclk
);
5939 static int valleyview_modeset_calc_cdclk(struct drm_atomic_state
*state
)
5941 struct drm_device
*dev
= state
->dev
;
5942 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5943 int max_pixclk
= intel_mode_max_pixclk(dev
, state
);
5944 struct intel_atomic_state
*intel_state
=
5945 to_intel_atomic_state(state
);
5947 intel_state
->cdclk
= intel_state
->dev_cdclk
=
5948 valleyview_calc_cdclk(dev_priv
, max_pixclk
);
5950 if (!intel_state
->active_crtcs
)
5951 intel_state
->dev_cdclk
= valleyview_calc_cdclk(dev_priv
, 0);
5956 static int broxton_modeset_calc_cdclk(struct drm_atomic_state
*state
)
5958 int max_pixclk
= ilk_max_pixel_rate(state
);
5959 struct intel_atomic_state
*intel_state
=
5960 to_intel_atomic_state(state
);
5962 intel_state
->cdclk
= intel_state
->dev_cdclk
=
5963 broxton_calc_cdclk(max_pixclk
);
5965 if (!intel_state
->active_crtcs
)
5966 intel_state
->dev_cdclk
= broxton_calc_cdclk(0);
5971 static void vlv_program_pfi_credits(struct drm_i915_private
*dev_priv
)
5973 unsigned int credits
, default_credits
;
5975 if (IS_CHERRYVIEW(dev_priv
))
5976 default_credits
= PFI_CREDIT(12);
5978 default_credits
= PFI_CREDIT(8);
5980 if (dev_priv
->cdclk_freq
>= dev_priv
->czclk_freq
) {
5981 /* CHV suggested value is 31 or 63 */
5982 if (IS_CHERRYVIEW(dev_priv
))
5983 credits
= PFI_CREDIT_63
;
5985 credits
= PFI_CREDIT(15);
5987 credits
= default_credits
;
5991 * WA - write default credits before re-programming
5992 * FIXME: should we also set the resend bit here?
5994 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
5997 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
5998 credits
| PFI_CREDIT_RESEND
);
6001 * FIXME is this guaranteed to clear
6002 * immediately or should we poll for it?
6004 WARN_ON(I915_READ(GCI_CONTROL
) & PFI_CREDIT_RESEND
);
6007 static void valleyview_modeset_commit_cdclk(struct drm_atomic_state
*old_state
)
6009 struct drm_device
*dev
= old_state
->dev
;
6010 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6011 struct intel_atomic_state
*old_intel_state
=
6012 to_intel_atomic_state(old_state
);
6013 unsigned req_cdclk
= old_intel_state
->dev_cdclk
;
6016 * FIXME: We can end up here with all power domains off, yet
6017 * with a CDCLK frequency other than the minimum. To account
6018 * for this take the PIPE-A power domain, which covers the HW
6019 * blocks needed for the following programming. This can be
6020 * removed once it's guaranteed that we get here either with
6021 * the minimum CDCLK set, or the required power domains
6024 intel_display_power_get(dev_priv
, POWER_DOMAIN_PIPE_A
);
6026 if (IS_CHERRYVIEW(dev
))
6027 cherryview_set_cdclk(dev
, req_cdclk
);
6029 valleyview_set_cdclk(dev
, req_cdclk
);
6031 vlv_program_pfi_credits(dev_priv
);
6033 intel_display_power_put(dev_priv
, POWER_DOMAIN_PIPE_A
);
6036 static void valleyview_crtc_enable(struct drm_crtc
*crtc
)
6038 struct drm_device
*dev
= crtc
->dev
;
6039 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6040 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6041 struct intel_encoder
*encoder
;
6042 struct intel_crtc_state
*pipe_config
=
6043 to_intel_crtc_state(crtc
->state
);
6044 int pipe
= intel_crtc
->pipe
;
6046 if (WARN_ON(intel_crtc
->active
))
6049 if (intel_crtc
->config
->has_dp_encoder
)
6050 intel_dp_set_m_n(intel_crtc
, M1_N1
);
6052 intel_set_pipe_timings(intel_crtc
);
6053 intel_set_pipe_src_size(intel_crtc
);
6055 if (IS_CHERRYVIEW(dev
) && pipe
== PIPE_B
) {
6056 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6058 I915_WRITE(CHV_BLEND(pipe
), CHV_BLEND_LEGACY
);
6059 I915_WRITE(CHV_CANVAS(pipe
), 0);
6062 i9xx_set_pipeconf(intel_crtc
);
6064 intel_crtc
->active
= true;
6066 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
6068 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6069 if (encoder
->pre_pll_enable
)
6070 encoder
->pre_pll_enable(encoder
);
6072 if (IS_CHERRYVIEW(dev
)) {
6073 chv_prepare_pll(intel_crtc
, intel_crtc
->config
);
6074 chv_enable_pll(intel_crtc
, intel_crtc
->config
);
6076 vlv_prepare_pll(intel_crtc
, intel_crtc
->config
);
6077 vlv_enable_pll(intel_crtc
, intel_crtc
->config
);
6080 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6081 if (encoder
->pre_enable
)
6082 encoder
->pre_enable(encoder
);
6084 i9xx_pfit_enable(intel_crtc
);
6086 intel_color_load_luts(&pipe_config
->base
);
6088 intel_update_watermarks(crtc
);
6089 intel_enable_pipe(intel_crtc
);
6091 assert_vblank_disabled(crtc
);
6092 drm_crtc_vblank_on(crtc
);
6094 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6095 encoder
->enable(encoder
);
6098 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
6100 struct drm_device
*dev
= crtc
->base
.dev
;
6101 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6103 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp0
);
6104 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp1
);
6107 static void i9xx_crtc_enable(struct drm_crtc
*crtc
)
6109 struct drm_device
*dev
= crtc
->dev
;
6110 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6111 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6112 struct intel_encoder
*encoder
;
6113 struct intel_crtc_state
*pipe_config
=
6114 to_intel_crtc_state(crtc
->state
);
6115 enum pipe pipe
= intel_crtc
->pipe
;
6117 if (WARN_ON(intel_crtc
->active
))
6120 i9xx_set_pll_dividers(intel_crtc
);
6122 if (intel_crtc
->config
->has_dp_encoder
)
6123 intel_dp_set_m_n(intel_crtc
, M1_N1
);
6125 intel_set_pipe_timings(intel_crtc
);
6126 intel_set_pipe_src_size(intel_crtc
);
6128 i9xx_set_pipeconf(intel_crtc
);
6130 intel_crtc
->active
= true;
6133 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
6135 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6136 if (encoder
->pre_enable
)
6137 encoder
->pre_enable(encoder
);
6139 i9xx_enable_pll(intel_crtc
);
6141 i9xx_pfit_enable(intel_crtc
);
6143 intel_color_load_luts(&pipe_config
->base
);
6145 intel_update_watermarks(crtc
);
6146 intel_enable_pipe(intel_crtc
);
6148 assert_vblank_disabled(crtc
);
6149 drm_crtc_vblank_on(crtc
);
6151 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6152 encoder
->enable(encoder
);
6155 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
6157 struct drm_device
*dev
= crtc
->base
.dev
;
6158 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6160 if (!crtc
->config
->gmch_pfit
.control
)
6163 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
6165 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
6166 I915_READ(PFIT_CONTROL
));
6167 I915_WRITE(PFIT_CONTROL
, 0);
6170 static void i9xx_crtc_disable(struct drm_crtc
*crtc
)
6172 struct drm_device
*dev
= crtc
->dev
;
6173 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6174 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6175 struct intel_encoder
*encoder
;
6176 int pipe
= intel_crtc
->pipe
;
6179 * On gen2 planes are double buffered but the pipe isn't, so we must
6180 * wait for planes to fully turn off before disabling the pipe.
6183 intel_wait_for_vblank(dev
, pipe
);
6185 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6186 encoder
->disable(encoder
);
6188 drm_crtc_vblank_off(crtc
);
6189 assert_vblank_disabled(crtc
);
6191 intel_disable_pipe(intel_crtc
);
6193 i9xx_pfit_disable(intel_crtc
);
6195 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6196 if (encoder
->post_disable
)
6197 encoder
->post_disable(encoder
);
6199 if (!intel_crtc
->config
->has_dsi_encoder
) {
6200 if (IS_CHERRYVIEW(dev
))
6201 chv_disable_pll(dev_priv
, pipe
);
6202 else if (IS_VALLEYVIEW(dev
))
6203 vlv_disable_pll(dev_priv
, pipe
);
6205 i9xx_disable_pll(intel_crtc
);
6208 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6209 if (encoder
->post_pll_disable
)
6210 encoder
->post_pll_disable(encoder
);
6213 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
6216 static void intel_crtc_disable_noatomic(struct drm_crtc
*crtc
)
6218 struct intel_encoder
*encoder
;
6219 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6220 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
6221 enum intel_display_power_domain domain
;
6222 unsigned long domains
;
6224 if (!intel_crtc
->active
)
6227 if (to_intel_plane_state(crtc
->primary
->state
)->visible
) {
6228 WARN_ON(intel_crtc
->unpin_work
);
6230 intel_pre_disable_primary_noatomic(crtc
);
6232 intel_crtc_disable_planes(crtc
, 1 << drm_plane_index(crtc
->primary
));
6233 to_intel_plane_state(crtc
->primary
->state
)->visible
= false;
6236 dev_priv
->display
.crtc_disable(crtc
);
6238 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was enabled, now disabled\n",
6241 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->state
, NULL
) < 0);
6242 crtc
->state
->active
= false;
6243 intel_crtc
->active
= false;
6244 crtc
->enabled
= false;
6245 crtc
->state
->connector_mask
= 0;
6246 crtc
->state
->encoder_mask
= 0;
6248 for_each_encoder_on_crtc(crtc
->dev
, crtc
, encoder
)
6249 encoder
->base
.crtc
= NULL
;
6251 intel_fbc_disable(intel_crtc
);
6252 intel_update_watermarks(crtc
);
6253 intel_disable_shared_dpll(intel_crtc
);
6255 domains
= intel_crtc
->enabled_power_domains
;
6256 for_each_power_domain(domain
, domains
)
6257 intel_display_power_put(dev_priv
, domain
);
6258 intel_crtc
->enabled_power_domains
= 0;
6260 dev_priv
->active_crtcs
&= ~(1 << intel_crtc
->pipe
);
6261 dev_priv
->min_pixclk
[intel_crtc
->pipe
] = 0;
6265 * turn all crtc's off, but do not adjust state
6266 * This has to be paired with a call to intel_modeset_setup_hw_state.
6268 int intel_display_suspend(struct drm_device
*dev
)
6270 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6271 struct drm_atomic_state
*state
;
6274 state
= drm_atomic_helper_suspend(dev
);
6275 ret
= PTR_ERR_OR_ZERO(state
);
6277 DRM_ERROR("Suspending crtc's failed with %i\n", ret
);
6279 dev_priv
->modeset_restore_state
= state
;
6283 void intel_encoder_destroy(struct drm_encoder
*encoder
)
6285 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
6287 drm_encoder_cleanup(encoder
);
6288 kfree(intel_encoder
);
6291 /* Cross check the actual hw state with our own modeset state tracking (and it's
6292 * internal consistency). */
6293 static void intel_connector_verify_state(struct intel_connector
*connector
)
6295 struct drm_crtc
*crtc
= connector
->base
.state
->crtc
;
6297 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6298 connector
->base
.base
.id
,
6299 connector
->base
.name
);
6301 if (connector
->get_hw_state(connector
)) {
6302 struct intel_encoder
*encoder
= connector
->encoder
;
6303 struct drm_connector_state
*conn_state
= connector
->base
.state
;
6305 I915_STATE_WARN(!crtc
,
6306 "connector enabled without attached crtc\n");
6311 I915_STATE_WARN(!crtc
->state
->active
,
6312 "connector is active, but attached crtc isn't\n");
6314 if (!encoder
|| encoder
->type
== INTEL_OUTPUT_DP_MST
)
6317 I915_STATE_WARN(conn_state
->best_encoder
!= &encoder
->base
,
6318 "atomic encoder doesn't match attached encoder\n");
6320 I915_STATE_WARN(conn_state
->crtc
!= encoder
->base
.crtc
,
6321 "attached encoder crtc differs from connector crtc\n");
6323 I915_STATE_WARN(crtc
&& crtc
->state
->active
,
6324 "attached crtc is active, but connector isn't\n");
6325 I915_STATE_WARN(!crtc
&& connector
->base
.state
->best_encoder
,
6326 "best encoder set without crtc!\n");
6330 int intel_connector_init(struct intel_connector
*connector
)
6332 drm_atomic_helper_connector_reset(&connector
->base
);
6334 if (!connector
->base
.state
)
6340 struct intel_connector
*intel_connector_alloc(void)
6342 struct intel_connector
*connector
;
6344 connector
= kzalloc(sizeof *connector
, GFP_KERNEL
);
6348 if (intel_connector_init(connector
) < 0) {
6356 /* Simple connector->get_hw_state implementation for encoders that support only
6357 * one connector and no cloning and hence the encoder state determines the state
6358 * of the connector. */
6359 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
6362 struct intel_encoder
*encoder
= connector
->encoder
;
6364 return encoder
->get_hw_state(encoder
, &pipe
);
6367 static int pipe_required_fdi_lanes(struct intel_crtc_state
*crtc_state
)
6369 if (crtc_state
->base
.enable
&& crtc_state
->has_pch_encoder
)
6370 return crtc_state
->fdi_lanes
;
6375 static int ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
6376 struct intel_crtc_state
*pipe_config
)
6378 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
6379 struct intel_crtc
*other_crtc
;
6380 struct intel_crtc_state
*other_crtc_state
;
6382 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6383 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6384 if (pipe_config
->fdi_lanes
> 4) {
6385 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6386 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6390 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
6391 if (pipe_config
->fdi_lanes
> 2) {
6392 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6393 pipe_config
->fdi_lanes
);
6400 if (INTEL_INFO(dev
)->num_pipes
== 2)
6403 /* Ivybridge 3 pipe is really complicated */
6408 if (pipe_config
->fdi_lanes
<= 2)
6411 other_crtc
= to_intel_crtc(intel_get_crtc_for_pipe(dev
, PIPE_C
));
6413 intel_atomic_get_crtc_state(state
, other_crtc
);
6414 if (IS_ERR(other_crtc_state
))
6415 return PTR_ERR(other_crtc_state
);
6417 if (pipe_required_fdi_lanes(other_crtc_state
) > 0) {
6418 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6419 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6424 if (pipe_config
->fdi_lanes
> 2) {
6425 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6426 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6430 other_crtc
= to_intel_crtc(intel_get_crtc_for_pipe(dev
, PIPE_B
));
6432 intel_atomic_get_crtc_state(state
, other_crtc
);
6433 if (IS_ERR(other_crtc_state
))
6434 return PTR_ERR(other_crtc_state
);
6436 if (pipe_required_fdi_lanes(other_crtc_state
) > 2) {
6437 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6447 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
6448 struct intel_crtc_state
*pipe_config
)
6450 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6451 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6452 int lane
, link_bw
, fdi_dotclock
, ret
;
6453 bool needs_recompute
= false;
6456 /* FDI is a binary signal running at ~2.7GHz, encoding
6457 * each output octet as 10 bits. The actual frequency
6458 * is stored as a divider into a 100MHz clock, and the
6459 * mode pixel clock is stored in units of 1KHz.
6460 * Hence the bw of each lane in terms of the mode signal
6463 link_bw
= intel_fdi_link_freq(to_i915(dev
), pipe_config
);
6465 fdi_dotclock
= adjusted_mode
->crtc_clock
;
6467 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
6468 pipe_config
->pipe_bpp
);
6470 pipe_config
->fdi_lanes
= lane
;
6472 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
6473 link_bw
, &pipe_config
->fdi_m_n
);
6475 ret
= ironlake_check_fdi_lanes(dev
, intel_crtc
->pipe
, pipe_config
);
6476 if (ret
== -EINVAL
&& pipe_config
->pipe_bpp
> 6*3) {
6477 pipe_config
->pipe_bpp
-= 2*3;
6478 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6479 pipe_config
->pipe_bpp
);
6480 needs_recompute
= true;
6481 pipe_config
->bw_constrained
= true;
6486 if (needs_recompute
)
6492 static bool pipe_config_supports_ips(struct drm_i915_private
*dev_priv
,
6493 struct intel_crtc_state
*pipe_config
)
6495 if (pipe_config
->pipe_bpp
> 24)
6498 /* HSW can handle pixel rate up to cdclk? */
6499 if (IS_HASWELL(dev_priv
))
6503 * We compare against max which means we must take
6504 * the increased cdclk requirement into account when
6505 * calculating the new cdclk.
6507 * Should measure whether using a lower cdclk w/o IPS
6509 return ilk_pipe_pixel_rate(pipe_config
) <=
6510 dev_priv
->max_cdclk_freq
* 95 / 100;
6513 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
6514 struct intel_crtc_state
*pipe_config
)
6516 struct drm_device
*dev
= crtc
->base
.dev
;
6517 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6519 pipe_config
->ips_enabled
= i915
.enable_ips
&&
6520 hsw_crtc_supports_ips(crtc
) &&
6521 pipe_config_supports_ips(dev_priv
, pipe_config
);
6524 static bool intel_crtc_supports_double_wide(const struct intel_crtc
*crtc
)
6526 const struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6528 /* GDG double wide on either pipe, otherwise pipe A only */
6529 return INTEL_INFO(dev_priv
)->gen
< 4 &&
6530 (crtc
->pipe
== PIPE_A
|| IS_I915G(dev_priv
));
6533 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
6534 struct intel_crtc_state
*pipe_config
)
6536 struct drm_device
*dev
= crtc
->base
.dev
;
6537 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6538 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6540 /* FIXME should check pixel clock limits on all platforms */
6541 if (INTEL_INFO(dev
)->gen
< 4) {
6542 int clock_limit
= dev_priv
->max_cdclk_freq
* 9 / 10;
6545 * Enable double wide mode when the dot clock
6546 * is > 90% of the (display) core speed.
6548 if (intel_crtc_supports_double_wide(crtc
) &&
6549 adjusted_mode
->crtc_clock
> clock_limit
) {
6551 pipe_config
->double_wide
= true;
6554 if (adjusted_mode
->crtc_clock
> clock_limit
) {
6555 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6556 adjusted_mode
->crtc_clock
, clock_limit
,
6557 yesno(pipe_config
->double_wide
));
6563 * Pipe horizontal size must be even in:
6565 * - LVDS dual channel mode
6566 * - Double wide pipe
6568 if ((intel_pipe_will_have_type(pipe_config
, INTEL_OUTPUT_LVDS
) &&
6569 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
6570 pipe_config
->pipe_src_w
&= ~1;
6572 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6573 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6575 if ((INTEL_INFO(dev
)->gen
> 4 || IS_G4X(dev
)) &&
6576 adjusted_mode
->crtc_hsync_start
== adjusted_mode
->crtc_hdisplay
)
6580 hsw_compute_ips_config(crtc
, pipe_config
);
6582 if (pipe_config
->has_pch_encoder
)
6583 return ironlake_fdi_compute_config(crtc
, pipe_config
);
6588 static int skylake_get_display_clock_speed(struct drm_device
*dev
)
6590 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6591 uint32_t lcpll1
= I915_READ(LCPLL1_CTL
);
6592 uint32_t cdctl
= I915_READ(CDCLK_CTL
);
6595 if (!(lcpll1
& LCPLL_PLL_ENABLE
))
6596 return 24000; /* 24MHz is the cd freq with NSSC ref */
6598 if ((cdctl
& CDCLK_FREQ_SEL_MASK
) == CDCLK_FREQ_540
)
6601 linkrate
= (I915_READ(DPLL_CTRL1
) &
6602 DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
)) >> 1;
6604 if (linkrate
== DPLL_CTRL1_LINK_RATE_2160
||
6605 linkrate
== DPLL_CTRL1_LINK_RATE_1080
) {
6607 switch (cdctl
& CDCLK_FREQ_SEL_MASK
) {
6608 case CDCLK_FREQ_450_432
:
6610 case CDCLK_FREQ_337_308
:
6612 case CDCLK_FREQ_675_617
:
6615 WARN(1, "Unknown cd freq selection\n");
6619 switch (cdctl
& CDCLK_FREQ_SEL_MASK
) {
6620 case CDCLK_FREQ_450_432
:
6622 case CDCLK_FREQ_337_308
:
6624 case CDCLK_FREQ_675_617
:
6627 WARN(1, "Unknown cd freq selection\n");
6631 /* error case, do as if DPLL0 isn't enabled */
6635 static int broxton_get_display_clock_speed(struct drm_device
*dev
)
6637 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6638 uint32_t cdctl
= I915_READ(CDCLK_CTL
);
6639 uint32_t pll_ratio
= I915_READ(BXT_DE_PLL_CTL
) & BXT_DE_PLL_RATIO_MASK
;
6640 uint32_t pll_enab
= I915_READ(BXT_DE_PLL_ENABLE
);
6643 if (!(pll_enab
& BXT_DE_PLL_PLL_ENABLE
))
6646 cdclk
= 19200 * pll_ratio
/ 2;
6648 switch (cdctl
& BXT_CDCLK_CD2X_DIV_SEL_MASK
) {
6649 case BXT_CDCLK_CD2X_DIV_SEL_1
:
6650 return cdclk
; /* 576MHz or 624MHz */
6651 case BXT_CDCLK_CD2X_DIV_SEL_1_5
:
6652 return cdclk
* 2 / 3; /* 384MHz */
6653 case BXT_CDCLK_CD2X_DIV_SEL_2
:
6654 return cdclk
/ 2; /* 288MHz */
6655 case BXT_CDCLK_CD2X_DIV_SEL_4
:
6656 return cdclk
/ 4; /* 144MHz */
6659 /* error case, do as if DE PLL isn't enabled */
6663 static int broadwell_get_display_clock_speed(struct drm_device
*dev
)
6665 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6666 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
6667 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
6669 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
6671 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
6673 else if (freq
== LCPLL_CLK_FREQ_450
)
6675 else if (freq
== LCPLL_CLK_FREQ_54O_BDW
)
6677 else if (freq
== LCPLL_CLK_FREQ_337_5_BDW
)
6683 static int haswell_get_display_clock_speed(struct drm_device
*dev
)
6685 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6686 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
6687 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
6689 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
6691 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
6693 else if (freq
== LCPLL_CLK_FREQ_450
)
6695 else if (IS_HSW_ULT(dev
))
6701 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
6703 return vlv_get_cck_clock_hpll(to_i915(dev
), "cdclk",
6704 CCK_DISPLAY_CLOCK_CONTROL
);
6707 static int ilk_get_display_clock_speed(struct drm_device
*dev
)
6712 static int i945_get_display_clock_speed(struct drm_device
*dev
)
6717 static int i915_get_display_clock_speed(struct drm_device
*dev
)
6722 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
6727 static int pnv_get_display_clock_speed(struct drm_device
*dev
)
6731 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
6733 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
6734 case GC_DISPLAY_CLOCK_267_MHZ_PNV
:
6736 case GC_DISPLAY_CLOCK_333_MHZ_PNV
:
6738 case GC_DISPLAY_CLOCK_444_MHZ_PNV
:
6740 case GC_DISPLAY_CLOCK_200_MHZ_PNV
:
6743 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc
);
6744 case GC_DISPLAY_CLOCK_133_MHZ_PNV
:
6746 case GC_DISPLAY_CLOCK_167_MHZ_PNV
:
6751 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
6755 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
6757 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
6760 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
6761 case GC_DISPLAY_CLOCK_333_MHZ
:
6764 case GC_DISPLAY_CLOCK_190_200_MHZ
:
6770 static int i865_get_display_clock_speed(struct drm_device
*dev
)
6775 static int i85x_get_display_clock_speed(struct drm_device
*dev
)
6780 * 852GM/852GMV only supports 133 MHz and the HPLLCC
6781 * encoding is different :(
6782 * FIXME is this the right way to detect 852GM/852GMV?
6784 if (dev
->pdev
->revision
== 0x1)
6787 pci_bus_read_config_word(dev
->pdev
->bus
,
6788 PCI_DEVFN(0, 3), HPLLCC
, &hpllcc
);
6790 /* Assume that the hardware is in the high speed state. This
6791 * should be the default.
6793 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
6794 case GC_CLOCK_133_200
:
6795 case GC_CLOCK_133_200_2
:
6796 case GC_CLOCK_100_200
:
6798 case GC_CLOCK_166_250
:
6800 case GC_CLOCK_100_133
:
6802 case GC_CLOCK_133_266
:
6803 case GC_CLOCK_133_266_2
:
6804 case GC_CLOCK_166_266
:
6808 /* Shouldn't happen */
6812 static int i830_get_display_clock_speed(struct drm_device
*dev
)
6817 static unsigned int intel_hpll_vco(struct drm_device
*dev
)
6819 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6820 static const unsigned int blb_vco
[8] = {
6827 static const unsigned int pnv_vco
[8] = {
6834 static const unsigned int cl_vco
[8] = {
6843 static const unsigned int elk_vco
[8] = {
6849 static const unsigned int ctg_vco
[8] = {
6857 const unsigned int *vco_table
;
6861 /* FIXME other chipsets? */
6863 vco_table
= ctg_vco
;
6864 else if (IS_G4X(dev
))
6865 vco_table
= elk_vco
;
6866 else if (IS_CRESTLINE(dev
))
6868 else if (IS_PINEVIEW(dev
))
6869 vco_table
= pnv_vco
;
6870 else if (IS_G33(dev
))
6871 vco_table
= blb_vco
;
6875 tmp
= I915_READ(IS_MOBILE(dev
) ? HPLLVCO_MOBILE
: HPLLVCO
);
6877 vco
= vco_table
[tmp
& 0x7];
6879 DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp
);
6881 DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco
);
6886 static int gm45_get_display_clock_speed(struct drm_device
*dev
)
6888 unsigned int cdclk_sel
, vco
= intel_hpll_vco(dev
);
6891 pci_read_config_word(dev
->pdev
, GCFGC
, &tmp
);
6893 cdclk_sel
= (tmp
>> 12) & 0x1;
6899 return cdclk_sel
? 333333 : 222222;
6901 return cdclk_sel
? 320000 : 228571;
6903 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco
, tmp
);
6908 static int i965gm_get_display_clock_speed(struct drm_device
*dev
)
6910 static const uint8_t div_3200
[] = { 16, 10, 8 };
6911 static const uint8_t div_4000
[] = { 20, 12, 10 };
6912 static const uint8_t div_5333
[] = { 24, 16, 14 };
6913 const uint8_t *div_table
;
6914 unsigned int cdclk_sel
, vco
= intel_hpll_vco(dev
);
6917 pci_read_config_word(dev
->pdev
, GCFGC
, &tmp
);
6919 cdclk_sel
= ((tmp
>> 8) & 0x1f) - 1;
6921 if (cdclk_sel
>= ARRAY_SIZE(div_3200
))
6926 div_table
= div_3200
;
6929 div_table
= div_4000
;
6932 div_table
= div_5333
;
6938 return DIV_ROUND_CLOSEST(vco
, div_table
[cdclk_sel
]);
6941 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco
, tmp
);
6945 static int g33_get_display_clock_speed(struct drm_device
*dev
)
6947 static const uint8_t div_3200
[] = { 12, 10, 8, 7, 5, 16 };
6948 static const uint8_t div_4000
[] = { 14, 12, 10, 8, 6, 20 };
6949 static const uint8_t div_4800
[] = { 20, 14, 12, 10, 8, 24 };
6950 static const uint8_t div_5333
[] = { 20, 16, 12, 12, 8, 28 };
6951 const uint8_t *div_table
;
6952 unsigned int cdclk_sel
, vco
= intel_hpll_vco(dev
);
6955 pci_read_config_word(dev
->pdev
, GCFGC
, &tmp
);
6957 cdclk_sel
= (tmp
>> 4) & 0x7;
6959 if (cdclk_sel
>= ARRAY_SIZE(div_3200
))
6964 div_table
= div_3200
;
6967 div_table
= div_4000
;
6970 div_table
= div_4800
;
6973 div_table
= div_5333
;
6979 return DIV_ROUND_CLOSEST(vco
, div_table
[cdclk_sel
]);
6982 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco
, tmp
);
6987 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
6989 while (*num
> DATA_LINK_M_N_MASK
||
6990 *den
> DATA_LINK_M_N_MASK
) {
6996 static void compute_m_n(unsigned int m
, unsigned int n
,
6997 uint32_t *ret_m
, uint32_t *ret_n
)
6999 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
7000 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
7001 intel_reduce_m_n_ratio(ret_m
, ret_n
);
7005 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
7006 int pixel_clock
, int link_clock
,
7007 struct intel_link_m_n
*m_n
)
7011 compute_m_n(bits_per_pixel
* pixel_clock
,
7012 link_clock
* nlanes
* 8,
7013 &m_n
->gmch_m
, &m_n
->gmch_n
);
7015 compute_m_n(pixel_clock
, link_clock
,
7016 &m_n
->link_m
, &m_n
->link_n
);
7019 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
7021 if (i915
.panel_use_ssc
>= 0)
7022 return i915
.panel_use_ssc
!= 0;
7023 return dev_priv
->vbt
.lvds_use_ssc
7024 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
7027 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
7029 return (1 << dpll
->n
) << 16 | dpll
->m2
;
7032 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
7034 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
7037 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
7038 struct intel_crtc_state
*crtc_state
,
7039 struct dpll
*reduced_clock
)
7041 struct drm_device
*dev
= crtc
->base
.dev
;
7044 if (IS_PINEVIEW(dev
)) {
7045 fp
= pnv_dpll_compute_fp(&crtc_state
->dpll
);
7047 fp2
= pnv_dpll_compute_fp(reduced_clock
);
7049 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
7051 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
7054 crtc_state
->dpll_hw_state
.fp0
= fp
;
7056 crtc
->lowfreq_avail
= false;
7057 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
7059 crtc_state
->dpll_hw_state
.fp1
= fp2
;
7060 crtc
->lowfreq_avail
= true;
7062 crtc_state
->dpll_hw_state
.fp1
= fp
;
7066 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
7072 * PLLB opamp always calibrates to max value of 0x3f, force enable it
7073 * and set it to a reasonable value instead.
7075 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
7076 reg_val
&= 0xffffff00;
7077 reg_val
|= 0x00000030;
7078 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
7080 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
7081 reg_val
&= 0x8cffffff;
7082 reg_val
= 0x8c000000;
7083 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
7085 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
7086 reg_val
&= 0xffffff00;
7087 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
7089 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
7090 reg_val
&= 0x00ffffff;
7091 reg_val
|= 0xb0000000;
7092 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
7095 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
7096 struct intel_link_m_n
*m_n
)
7098 struct drm_device
*dev
= crtc
->base
.dev
;
7099 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7100 int pipe
= crtc
->pipe
;
7102 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
7103 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
7104 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
7105 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
7108 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
7109 struct intel_link_m_n
*m_n
,
7110 struct intel_link_m_n
*m2_n2
)
7112 struct drm_device
*dev
= crtc
->base
.dev
;
7113 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7114 int pipe
= crtc
->pipe
;
7115 enum transcoder transcoder
= crtc
->config
->cpu_transcoder
;
7117 if (INTEL_INFO(dev
)->gen
>= 5) {
7118 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
7119 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
7120 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
7121 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
7122 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
7123 * for gen < 8) and if DRRS is supported (to make sure the
7124 * registers are not unnecessarily accessed).
7126 if (m2_n2
&& (IS_CHERRYVIEW(dev
) || INTEL_INFO(dev
)->gen
< 8) &&
7127 crtc
->config
->has_drrs
) {
7128 I915_WRITE(PIPE_DATA_M2(transcoder
),
7129 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
7130 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
7131 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
7132 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
7135 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
7136 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
7137 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
7138 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
7142 void intel_dp_set_m_n(struct intel_crtc
*crtc
, enum link_m_n_set m_n
)
7144 struct intel_link_m_n
*dp_m_n
, *dp_m2_n2
= NULL
;
7147 dp_m_n
= &crtc
->config
->dp_m_n
;
7148 dp_m2_n2
= &crtc
->config
->dp_m2_n2
;
7149 } else if (m_n
== M2_N2
) {
7152 * M2_N2 registers are not supported. Hence m2_n2 divider value
7153 * needs to be programmed into M1_N1.
7155 dp_m_n
= &crtc
->config
->dp_m2_n2
;
7157 DRM_ERROR("Unsupported divider value\n");
7161 if (crtc
->config
->has_pch_encoder
)
7162 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
->dp_m_n
);
7164 intel_cpu_transcoder_set_m_n(crtc
, dp_m_n
, dp_m2_n2
);
7167 static void vlv_compute_dpll(struct intel_crtc
*crtc
,
7168 struct intel_crtc_state
*pipe_config
)
7170 pipe_config
->dpll_hw_state
.dpll
= DPLL_INTEGRATED_REF_CLK_VLV
|
7171 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
7172 if (crtc
->pipe
!= PIPE_A
)
7173 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
7175 /* DPLL not used with DSI, but still need the rest set up */
7176 if (!pipe_config
->has_dsi_encoder
)
7177 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
|
7178 DPLL_EXT_BUFFER_ENABLE_VLV
;
7180 pipe_config
->dpll_hw_state
.dpll_md
=
7181 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
7184 static void chv_compute_dpll(struct intel_crtc
*crtc
,
7185 struct intel_crtc_state
*pipe_config
)
7187 pipe_config
->dpll_hw_state
.dpll
= DPLL_SSC_REF_CLK_CHV
|
7188 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
7189 if (crtc
->pipe
!= PIPE_A
)
7190 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
7192 /* DPLL not used with DSI, but still need the rest set up */
7193 if (!pipe_config
->has_dsi_encoder
)
7194 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
;
7196 pipe_config
->dpll_hw_state
.dpll_md
=
7197 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
7200 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
7201 const struct intel_crtc_state
*pipe_config
)
7203 struct drm_device
*dev
= crtc
->base
.dev
;
7204 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7205 enum pipe pipe
= crtc
->pipe
;
7207 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
7208 u32 coreclk
, reg_val
;
7211 I915_WRITE(DPLL(pipe
),
7212 pipe_config
->dpll_hw_state
.dpll
&
7213 ~(DPLL_VCO_ENABLE
| DPLL_EXT_BUFFER_ENABLE_VLV
));
7215 /* No need to actually set up the DPLL with DSI */
7216 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7219 mutex_lock(&dev_priv
->sb_lock
);
7221 bestn
= pipe_config
->dpll
.n
;
7222 bestm1
= pipe_config
->dpll
.m1
;
7223 bestm2
= pipe_config
->dpll
.m2
;
7224 bestp1
= pipe_config
->dpll
.p1
;
7225 bestp2
= pipe_config
->dpll
.p2
;
7227 /* See eDP HDMI DPIO driver vbios notes doc */
7229 /* PLL B needs special handling */
7231 vlv_pllb_recal_opamp(dev_priv
, pipe
);
7233 /* Set up Tx target for periodic Rcomp update */
7234 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
7236 /* Disable target IRef on PLL */
7237 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
7238 reg_val
&= 0x00ffffff;
7239 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
7241 /* Disable fast lock */
7242 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
7244 /* Set idtafcrecal before PLL is enabled */
7245 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
7246 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
7247 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
7248 mdiv
|= (1 << DPIO_K_SHIFT
);
7251 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7252 * but we don't support that).
7253 * Note: don't use the DAC post divider as it seems unstable.
7255 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
7256 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
7258 mdiv
|= DPIO_ENABLE_CALIBRATION
;
7259 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
7261 /* Set HBR and RBR LPF coefficients */
7262 if (pipe_config
->port_clock
== 162000 ||
7263 intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
) ||
7264 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
))
7265 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
7268 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
7271 if (pipe_config
->has_dp_encoder
) {
7272 /* Use SSC source */
7274 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7277 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7279 } else { /* HDMI or VGA */
7280 /* Use bend source */
7282 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7285 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7289 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
7290 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
7291 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
7292 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))
7293 coreclk
|= 0x01000000;
7294 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
7296 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
7297 mutex_unlock(&dev_priv
->sb_lock
);
7300 static void chv_prepare_pll(struct intel_crtc
*crtc
,
7301 const struct intel_crtc_state
*pipe_config
)
7303 struct drm_device
*dev
= crtc
->base
.dev
;
7304 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7305 enum pipe pipe
= crtc
->pipe
;
7306 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
7307 u32 loopfilter
, tribuf_calcntr
;
7308 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
7312 /* Enable Refclk and SSC */
7313 I915_WRITE(DPLL(pipe
),
7314 pipe_config
->dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
7316 /* No need to actually set up the DPLL with DSI */
7317 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7320 bestn
= pipe_config
->dpll
.n
;
7321 bestm2_frac
= pipe_config
->dpll
.m2
& 0x3fffff;
7322 bestm1
= pipe_config
->dpll
.m1
;
7323 bestm2
= pipe_config
->dpll
.m2
>> 22;
7324 bestp1
= pipe_config
->dpll
.p1
;
7325 bestp2
= pipe_config
->dpll
.p2
;
7326 vco
= pipe_config
->dpll
.vco
;
7330 mutex_lock(&dev_priv
->sb_lock
);
7332 /* p1 and p2 divider */
7333 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
7334 5 << DPIO_CHV_S1_DIV_SHIFT
|
7335 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
7336 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
7337 1 << DPIO_CHV_K_DIV_SHIFT
);
7339 /* Feedback post-divider - m2 */
7340 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
7342 /* Feedback refclk divider - n and m1 */
7343 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
7344 DPIO_CHV_M1_DIV_BY_2
|
7345 1 << DPIO_CHV_N_DIV_SHIFT
);
7347 /* M2 fraction division */
7348 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
7350 /* M2 fraction division enable */
7351 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
7352 dpio_val
&= ~(DPIO_CHV_FEEDFWD_GAIN_MASK
| DPIO_CHV_FRAC_DIV_EN
);
7353 dpio_val
|= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
);
7355 dpio_val
|= DPIO_CHV_FRAC_DIV_EN
;
7356 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
), dpio_val
);
7358 /* Program digital lock detect threshold */
7359 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW9(port
));
7360 dpio_val
&= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK
|
7361 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
);
7362 dpio_val
|= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT
);
7364 dpio_val
|= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
;
7365 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW9(port
), dpio_val
);
7368 if (vco
== 5400000) {
7369 loopfilter
|= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT
);
7370 loopfilter
|= (0x8 << DPIO_CHV_INT_COEFF_SHIFT
);
7371 loopfilter
|= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7372 tribuf_calcntr
= 0x9;
7373 } else if (vco
<= 6200000) {
7374 loopfilter
|= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT
);
7375 loopfilter
|= (0xB << DPIO_CHV_INT_COEFF_SHIFT
);
7376 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7377 tribuf_calcntr
= 0x9;
7378 } else if (vco
<= 6480000) {
7379 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
7380 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
7381 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7382 tribuf_calcntr
= 0x8;
7384 /* Not supported. Apply the same limits as in the max case */
7385 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
7386 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
7387 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7390 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
7392 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW8(port
));
7393 dpio_val
&= ~DPIO_CHV_TDC_TARGET_CNT_MASK
;
7394 dpio_val
|= (tribuf_calcntr
<< DPIO_CHV_TDC_TARGET_CNT_SHIFT
);
7395 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW8(port
), dpio_val
);
7398 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
7399 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
7402 mutex_unlock(&dev_priv
->sb_lock
);
7406 * vlv_force_pll_on - forcibly enable just the PLL
7407 * @dev_priv: i915 private structure
7408 * @pipe: pipe PLL to enable
7409 * @dpll: PLL configuration
7411 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7412 * in cases where we need the PLL enabled even when @pipe is not going to
7415 int vlv_force_pll_on(struct drm_device
*dev
, enum pipe pipe
,
7416 const struct dpll
*dpll
)
7418 struct intel_crtc
*crtc
=
7419 to_intel_crtc(intel_get_crtc_for_pipe(dev
, pipe
));
7420 struct intel_crtc_state
*pipe_config
;
7422 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
7426 pipe_config
->base
.crtc
= &crtc
->base
;
7427 pipe_config
->pixel_multiplier
= 1;
7428 pipe_config
->dpll
= *dpll
;
7430 if (IS_CHERRYVIEW(dev
)) {
7431 chv_compute_dpll(crtc
, pipe_config
);
7432 chv_prepare_pll(crtc
, pipe_config
);
7433 chv_enable_pll(crtc
, pipe_config
);
7435 vlv_compute_dpll(crtc
, pipe_config
);
7436 vlv_prepare_pll(crtc
, pipe_config
);
7437 vlv_enable_pll(crtc
, pipe_config
);
7446 * vlv_force_pll_off - forcibly disable just the PLL
7447 * @dev_priv: i915 private structure
7448 * @pipe: pipe PLL to disable
7450 * Disable the PLL for @pipe. To be used in cases where we need
7451 * the PLL enabled even when @pipe is not going to be enabled.
7453 void vlv_force_pll_off(struct drm_device
*dev
, enum pipe pipe
)
7455 if (IS_CHERRYVIEW(dev
))
7456 chv_disable_pll(to_i915(dev
), pipe
);
7458 vlv_disable_pll(to_i915(dev
), pipe
);
7461 static void i9xx_compute_dpll(struct intel_crtc
*crtc
,
7462 struct intel_crtc_state
*crtc_state
,
7463 struct dpll
*reduced_clock
)
7465 struct drm_device
*dev
= crtc
->base
.dev
;
7466 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7469 struct dpll
*clock
= &crtc_state
->dpll
;
7471 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
7473 is_sdvo
= intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
7474 intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_HDMI
);
7476 dpll
= DPLL_VGA_MODE_DIS
;
7478 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
))
7479 dpll
|= DPLLB_MODE_LVDS
;
7481 dpll
|= DPLLB_MODE_DAC_SERIAL
;
7483 if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
7484 dpll
|= (crtc_state
->pixel_multiplier
- 1)
7485 << SDVO_MULTIPLIER_SHIFT_HIRES
;
7489 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7491 if (crtc_state
->has_dp_encoder
)
7492 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7494 /* compute bitmask from p1 value */
7495 if (IS_PINEVIEW(dev
))
7496 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
7498 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7499 if (IS_G4X(dev
) && reduced_clock
)
7500 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
7502 switch (clock
->p2
) {
7504 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
7507 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
7510 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
7513 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
7516 if (INTEL_INFO(dev
)->gen
>= 4)
7517 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
7519 if (crtc_state
->sdvo_tv_clock
)
7520 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
7521 else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
7522 intel_panel_use_ssc(dev_priv
))
7523 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7525 dpll
|= PLL_REF_INPUT_DREFCLK
;
7527 dpll
|= DPLL_VCO_ENABLE
;
7528 crtc_state
->dpll_hw_state
.dpll
= dpll
;
7530 if (INTEL_INFO(dev
)->gen
>= 4) {
7531 u32 dpll_md
= (crtc_state
->pixel_multiplier
- 1)
7532 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
7533 crtc_state
->dpll_hw_state
.dpll_md
= dpll_md
;
7537 static void i8xx_compute_dpll(struct intel_crtc
*crtc
,
7538 struct intel_crtc_state
*crtc_state
,
7539 struct dpll
*reduced_clock
)
7541 struct drm_device
*dev
= crtc
->base
.dev
;
7542 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7544 struct dpll
*clock
= &crtc_state
->dpll
;
7546 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
7548 dpll
= DPLL_VGA_MODE_DIS
;
7550 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7551 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7554 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
7556 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7558 dpll
|= PLL_P2_DIVIDE_BY_4
;
7561 if (!IS_I830(dev
) && intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_DVO
))
7562 dpll
|= DPLL_DVO_2X_MODE
;
7564 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
7565 intel_panel_use_ssc(dev_priv
))
7566 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7568 dpll
|= PLL_REF_INPUT_DREFCLK
;
7570 dpll
|= DPLL_VCO_ENABLE
;
7571 crtc_state
->dpll_hw_state
.dpll
= dpll
;
7574 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
7576 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7577 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7578 enum pipe pipe
= intel_crtc
->pipe
;
7579 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
7580 const struct drm_display_mode
*adjusted_mode
= &intel_crtc
->config
->base
.adjusted_mode
;
7581 uint32_t crtc_vtotal
, crtc_vblank_end
;
7584 /* We need to be careful not to changed the adjusted mode, for otherwise
7585 * the hw state checker will get angry at the mismatch. */
7586 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
7587 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
7589 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
7590 /* the chip adds 2 halflines automatically */
7592 crtc_vblank_end
-= 1;
7594 if (intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
7595 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
7597 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
7598 adjusted_mode
->crtc_htotal
/ 2;
7600 vsyncshift
+= adjusted_mode
->crtc_htotal
;
7603 if (INTEL_INFO(dev
)->gen
> 3)
7604 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
7606 I915_WRITE(HTOTAL(cpu_transcoder
),
7607 (adjusted_mode
->crtc_hdisplay
- 1) |
7608 ((adjusted_mode
->crtc_htotal
- 1) << 16));
7609 I915_WRITE(HBLANK(cpu_transcoder
),
7610 (adjusted_mode
->crtc_hblank_start
- 1) |
7611 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
7612 I915_WRITE(HSYNC(cpu_transcoder
),
7613 (adjusted_mode
->crtc_hsync_start
- 1) |
7614 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
7616 I915_WRITE(VTOTAL(cpu_transcoder
),
7617 (adjusted_mode
->crtc_vdisplay
- 1) |
7618 ((crtc_vtotal
- 1) << 16));
7619 I915_WRITE(VBLANK(cpu_transcoder
),
7620 (adjusted_mode
->crtc_vblank_start
- 1) |
7621 ((crtc_vblank_end
- 1) << 16));
7622 I915_WRITE(VSYNC(cpu_transcoder
),
7623 (adjusted_mode
->crtc_vsync_start
- 1) |
7624 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
7626 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7627 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7628 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7630 if (IS_HASWELL(dev
) && cpu_transcoder
== TRANSCODER_EDP
&&
7631 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
7632 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
7636 static void intel_set_pipe_src_size(struct intel_crtc
*intel_crtc
)
7638 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7639 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7640 enum pipe pipe
= intel_crtc
->pipe
;
7642 /* pipesrc controls the size that is scaled from, which should
7643 * always be the user's requested size.
7645 I915_WRITE(PIPESRC(pipe
),
7646 ((intel_crtc
->config
->pipe_src_w
- 1) << 16) |
7647 (intel_crtc
->config
->pipe_src_h
- 1));
7650 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
7651 struct intel_crtc_state
*pipe_config
)
7653 struct drm_device
*dev
= crtc
->base
.dev
;
7654 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7655 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
7658 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
7659 pipe_config
->base
.adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
7660 pipe_config
->base
.adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
7661 tmp
= I915_READ(HBLANK(cpu_transcoder
));
7662 pipe_config
->base
.adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
7663 pipe_config
->base
.adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
7664 tmp
= I915_READ(HSYNC(cpu_transcoder
));
7665 pipe_config
->base
.adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
7666 pipe_config
->base
.adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
7668 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
7669 pipe_config
->base
.adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
7670 pipe_config
->base
.adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
7671 tmp
= I915_READ(VBLANK(cpu_transcoder
));
7672 pipe_config
->base
.adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
7673 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
7674 tmp
= I915_READ(VSYNC(cpu_transcoder
));
7675 pipe_config
->base
.adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
7676 pipe_config
->base
.adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
7678 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
7679 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
7680 pipe_config
->base
.adjusted_mode
.crtc_vtotal
+= 1;
7681 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
+= 1;
7685 static void intel_get_pipe_src_size(struct intel_crtc
*crtc
,
7686 struct intel_crtc_state
*pipe_config
)
7688 struct drm_device
*dev
= crtc
->base
.dev
;
7689 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7692 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
7693 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
7694 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
7696 pipe_config
->base
.mode
.vdisplay
= pipe_config
->pipe_src_h
;
7697 pipe_config
->base
.mode
.hdisplay
= pipe_config
->pipe_src_w
;
7700 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
7701 struct intel_crtc_state
*pipe_config
)
7703 mode
->hdisplay
= pipe_config
->base
.adjusted_mode
.crtc_hdisplay
;
7704 mode
->htotal
= pipe_config
->base
.adjusted_mode
.crtc_htotal
;
7705 mode
->hsync_start
= pipe_config
->base
.adjusted_mode
.crtc_hsync_start
;
7706 mode
->hsync_end
= pipe_config
->base
.adjusted_mode
.crtc_hsync_end
;
7708 mode
->vdisplay
= pipe_config
->base
.adjusted_mode
.crtc_vdisplay
;
7709 mode
->vtotal
= pipe_config
->base
.adjusted_mode
.crtc_vtotal
;
7710 mode
->vsync_start
= pipe_config
->base
.adjusted_mode
.crtc_vsync_start
;
7711 mode
->vsync_end
= pipe_config
->base
.adjusted_mode
.crtc_vsync_end
;
7713 mode
->flags
= pipe_config
->base
.adjusted_mode
.flags
;
7714 mode
->type
= DRM_MODE_TYPE_DRIVER
;
7716 mode
->clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
7717 mode
->flags
|= pipe_config
->base
.adjusted_mode
.flags
;
7719 mode
->hsync
= drm_mode_hsync(mode
);
7720 mode
->vrefresh
= drm_mode_vrefresh(mode
);
7721 drm_mode_set_name(mode
);
7724 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
7726 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7727 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7732 if ((intel_crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
7733 (intel_crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
7734 pipeconf
|= I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
;
7736 if (intel_crtc
->config
->double_wide
)
7737 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
7739 /* only g4x and later have fancy bpc/dither controls */
7740 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
7741 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7742 if (intel_crtc
->config
->dither
&& intel_crtc
->config
->pipe_bpp
!= 30)
7743 pipeconf
|= PIPECONF_DITHER_EN
|
7744 PIPECONF_DITHER_TYPE_SP
;
7746 switch (intel_crtc
->config
->pipe_bpp
) {
7748 pipeconf
|= PIPECONF_6BPC
;
7751 pipeconf
|= PIPECONF_8BPC
;
7754 pipeconf
|= PIPECONF_10BPC
;
7757 /* Case prevented by intel_choose_pipe_bpp_dither. */
7762 if (HAS_PIPE_CXSR(dev
)) {
7763 if (intel_crtc
->lowfreq_avail
) {
7764 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
7765 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
7767 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
7771 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
7772 if (INTEL_INFO(dev
)->gen
< 4 ||
7773 intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
7774 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
7776 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
7778 pipeconf
|= PIPECONF_PROGRESSIVE
;
7780 if ((IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) &&
7781 intel_crtc
->config
->limited_color_range
)
7782 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
7784 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
7785 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
7788 static int i8xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7789 struct intel_crtc_state
*crtc_state
)
7791 struct drm_device
*dev
= crtc
->base
.dev
;
7792 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7793 const struct intel_limit
*limit
;
7796 memset(&crtc_state
->dpll_hw_state
, 0,
7797 sizeof(crtc_state
->dpll_hw_state
));
7799 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7800 if (intel_panel_use_ssc(dev_priv
)) {
7801 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7802 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7805 limit
= &intel_limits_i8xx_lvds
;
7806 } else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_DVO
)) {
7807 limit
= &intel_limits_i8xx_dvo
;
7809 limit
= &intel_limits_i8xx_dac
;
7812 if (!crtc_state
->clock_set
&&
7813 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7814 refclk
, NULL
, &crtc_state
->dpll
)) {
7815 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7819 i8xx_compute_dpll(crtc
, crtc_state
, NULL
);
7824 static int g4x_crtc_compute_clock(struct intel_crtc
*crtc
,
7825 struct intel_crtc_state
*crtc_state
)
7827 struct drm_device
*dev
= crtc
->base
.dev
;
7828 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7829 const struct intel_limit
*limit
;
7832 memset(&crtc_state
->dpll_hw_state
, 0,
7833 sizeof(crtc_state
->dpll_hw_state
));
7835 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7836 if (intel_panel_use_ssc(dev_priv
)) {
7837 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7838 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7841 if (intel_is_dual_link_lvds(dev
))
7842 limit
= &intel_limits_g4x_dual_channel_lvds
;
7844 limit
= &intel_limits_g4x_single_channel_lvds
;
7845 } else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_HDMI
) ||
7846 intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_ANALOG
)) {
7847 limit
= &intel_limits_g4x_hdmi
;
7848 } else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_SDVO
)) {
7849 limit
= &intel_limits_g4x_sdvo
;
7851 /* The option is for other outputs */
7852 limit
= &intel_limits_i9xx_sdvo
;
7855 if (!crtc_state
->clock_set
&&
7856 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7857 refclk
, NULL
, &crtc_state
->dpll
)) {
7858 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7862 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7867 static int pnv_crtc_compute_clock(struct intel_crtc
*crtc
,
7868 struct intel_crtc_state
*crtc_state
)
7870 struct drm_device
*dev
= crtc
->base
.dev
;
7871 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7872 const struct intel_limit
*limit
;
7875 memset(&crtc_state
->dpll_hw_state
, 0,
7876 sizeof(crtc_state
->dpll_hw_state
));
7878 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7879 if (intel_panel_use_ssc(dev_priv
)) {
7880 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7881 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7884 limit
= &intel_limits_pineview_lvds
;
7886 limit
= &intel_limits_pineview_sdvo
;
7889 if (!crtc_state
->clock_set
&&
7890 !pnv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7891 refclk
, NULL
, &crtc_state
->dpll
)) {
7892 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7896 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7901 static int i9xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7902 struct intel_crtc_state
*crtc_state
)
7904 struct drm_device
*dev
= crtc
->base
.dev
;
7905 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7906 const struct intel_limit
*limit
;
7909 memset(&crtc_state
->dpll_hw_state
, 0,
7910 sizeof(crtc_state
->dpll_hw_state
));
7912 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7913 if (intel_panel_use_ssc(dev_priv
)) {
7914 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7915 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7918 limit
= &intel_limits_i9xx_lvds
;
7920 limit
= &intel_limits_i9xx_sdvo
;
7923 if (!crtc_state
->clock_set
&&
7924 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7925 refclk
, NULL
, &crtc_state
->dpll
)) {
7926 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7930 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7935 static int chv_crtc_compute_clock(struct intel_crtc
*crtc
,
7936 struct intel_crtc_state
*crtc_state
)
7938 int refclk
= 100000;
7939 const struct intel_limit
*limit
= &intel_limits_chv
;
7941 memset(&crtc_state
->dpll_hw_state
, 0,
7942 sizeof(crtc_state
->dpll_hw_state
));
7944 if (!crtc_state
->clock_set
&&
7945 !chv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7946 refclk
, NULL
, &crtc_state
->dpll
)) {
7947 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7951 chv_compute_dpll(crtc
, crtc_state
);
7956 static int vlv_crtc_compute_clock(struct intel_crtc
*crtc
,
7957 struct intel_crtc_state
*crtc_state
)
7959 int refclk
= 100000;
7960 const struct intel_limit
*limit
= &intel_limits_vlv
;
7962 memset(&crtc_state
->dpll_hw_state
, 0,
7963 sizeof(crtc_state
->dpll_hw_state
));
7965 if (!crtc_state
->clock_set
&&
7966 !vlv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7967 refclk
, NULL
, &crtc_state
->dpll
)) {
7968 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7972 vlv_compute_dpll(crtc
, crtc_state
);
7977 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
7978 struct intel_crtc_state
*pipe_config
)
7980 struct drm_device
*dev
= crtc
->base
.dev
;
7981 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7984 if (INTEL_INFO(dev
)->gen
<= 3 && (IS_I830(dev
) || !IS_MOBILE(dev
)))
7987 tmp
= I915_READ(PFIT_CONTROL
);
7988 if (!(tmp
& PFIT_ENABLE
))
7991 /* Check whether the pfit is attached to our pipe. */
7992 if (INTEL_INFO(dev
)->gen
< 4) {
7993 if (crtc
->pipe
!= PIPE_B
)
7996 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
8000 pipe_config
->gmch_pfit
.control
= tmp
;
8001 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
8004 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
8005 struct intel_crtc_state
*pipe_config
)
8007 struct drm_device
*dev
= crtc
->base
.dev
;
8008 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8009 int pipe
= pipe_config
->cpu_transcoder
;
8012 int refclk
= 100000;
8014 /* In case of DSI, DPLL will not be used */
8015 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
8018 mutex_lock(&dev_priv
->sb_lock
);
8019 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
8020 mutex_unlock(&dev_priv
->sb_lock
);
8022 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
8023 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
8024 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
8025 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
8026 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
8028 pipe_config
->port_clock
= vlv_calc_dpll_params(refclk
, &clock
);
8032 i9xx_get_initial_plane_config(struct intel_crtc
*crtc
,
8033 struct intel_initial_plane_config
*plane_config
)
8035 struct drm_device
*dev
= crtc
->base
.dev
;
8036 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8037 u32 val
, base
, offset
;
8038 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
8039 int fourcc
, pixel_format
;
8040 unsigned int aligned_height
;
8041 struct drm_framebuffer
*fb
;
8042 struct intel_framebuffer
*intel_fb
;
8044 val
= I915_READ(DSPCNTR(plane
));
8045 if (!(val
& DISPLAY_PLANE_ENABLE
))
8048 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8050 DRM_DEBUG_KMS("failed to alloc fb\n");
8054 fb
= &intel_fb
->base
;
8056 if (INTEL_INFO(dev
)->gen
>= 4) {
8057 if (val
& DISPPLANE_TILED
) {
8058 plane_config
->tiling
= I915_TILING_X
;
8059 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
8063 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
8064 fourcc
= i9xx_format_to_fourcc(pixel_format
);
8065 fb
->pixel_format
= fourcc
;
8066 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
8068 if (INTEL_INFO(dev
)->gen
>= 4) {
8069 if (plane_config
->tiling
)
8070 offset
= I915_READ(DSPTILEOFF(plane
));
8072 offset
= I915_READ(DSPLINOFF(plane
));
8073 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
8075 base
= I915_READ(DSPADDR(plane
));
8077 plane_config
->base
= base
;
8079 val
= I915_READ(PIPESRC(pipe
));
8080 fb
->width
= ((val
>> 16) & 0xfff) + 1;
8081 fb
->height
= ((val
>> 0) & 0xfff) + 1;
8083 val
= I915_READ(DSPSTRIDE(pipe
));
8084 fb
->pitches
[0] = val
& 0xffffffc0;
8086 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
8090 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8092 DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8093 pipe_name(pipe
), plane
, fb
->width
, fb
->height
,
8094 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
8095 plane_config
->size
);
8097 plane_config
->fb
= intel_fb
;
8100 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
8101 struct intel_crtc_state
*pipe_config
)
8103 struct drm_device
*dev
= crtc
->base
.dev
;
8104 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8105 int pipe
= pipe_config
->cpu_transcoder
;
8106 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
8108 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
, pll_dw3
;
8109 int refclk
= 100000;
8111 /* In case of DSI, DPLL will not be used */
8112 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
8115 mutex_lock(&dev_priv
->sb_lock
);
8116 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
8117 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
8118 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
8119 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
8120 pll_dw3
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
8121 mutex_unlock(&dev_priv
->sb_lock
);
8123 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
8124 clock
.m2
= (pll_dw0
& 0xff) << 22;
8125 if (pll_dw3
& DPIO_CHV_FRAC_DIV_EN
)
8126 clock
.m2
|= pll_dw2
& 0x3fffff;
8127 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
8128 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
8129 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
8131 pipe_config
->port_clock
= chv_calc_dpll_params(refclk
, &clock
);
8134 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
8135 struct intel_crtc_state
*pipe_config
)
8137 struct drm_device
*dev
= crtc
->base
.dev
;
8138 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8139 enum intel_display_power_domain power_domain
;
8143 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
8144 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8147 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8148 pipe_config
->shared_dpll
= NULL
;
8152 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
8153 if (!(tmp
& PIPECONF_ENABLE
))
8156 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
8157 switch (tmp
& PIPECONF_BPC_MASK
) {
8159 pipe_config
->pipe_bpp
= 18;
8162 pipe_config
->pipe_bpp
= 24;
8164 case PIPECONF_10BPC
:
8165 pipe_config
->pipe_bpp
= 30;
8172 if ((IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) &&
8173 (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
8174 pipe_config
->limited_color_range
= true;
8176 if (INTEL_INFO(dev
)->gen
< 4)
8177 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
8179 intel_get_pipe_timings(crtc
, pipe_config
);
8180 intel_get_pipe_src_size(crtc
, pipe_config
);
8182 i9xx_get_pfit_config(crtc
, pipe_config
);
8184 if (INTEL_INFO(dev
)->gen
>= 4) {
8185 /* No way to read it out on pipes B and C */
8186 if (IS_CHERRYVIEW(dev
) && crtc
->pipe
!= PIPE_A
)
8187 tmp
= dev_priv
->chv_dpll_md
[crtc
->pipe
];
8189 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
8190 pipe_config
->pixel_multiplier
=
8191 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
8192 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
8193 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
8194 } else if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
8195 tmp
= I915_READ(DPLL(crtc
->pipe
));
8196 pipe_config
->pixel_multiplier
=
8197 ((tmp
& SDVO_MULTIPLIER_MASK
)
8198 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
8200 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8201 * port and will be fixed up in the encoder->get_config
8203 pipe_config
->pixel_multiplier
= 1;
8205 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
8206 if (!IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
)) {
8208 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
8209 * on 830. Filter it out here so that we don't
8210 * report errors due to that.
8213 pipe_config
->dpll_hw_state
.dpll
&= ~DPLL_DVO_2X_MODE
;
8215 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
8216 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
8218 /* Mask out read-only status bits. */
8219 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
8220 DPLL_PORTC_READY_MASK
|
8221 DPLL_PORTB_READY_MASK
);
8224 if (IS_CHERRYVIEW(dev
))
8225 chv_crtc_clock_get(crtc
, pipe_config
);
8226 else if (IS_VALLEYVIEW(dev
))
8227 vlv_crtc_clock_get(crtc
, pipe_config
);
8229 i9xx_crtc_clock_get(crtc
, pipe_config
);
8232 * Normally the dotclock is filled in by the encoder .get_config()
8233 * but in case the pipe is enabled w/o any ports we need a sane
8236 pipe_config
->base
.adjusted_mode
.crtc_clock
=
8237 pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
8242 intel_display_power_put(dev_priv
, power_domain
);
8247 static void ironlake_init_pch_refclk(struct drm_device
*dev
)
8249 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8250 struct intel_encoder
*encoder
;
8252 bool has_lvds
= false;
8253 bool has_cpu_edp
= false;
8254 bool has_panel
= false;
8255 bool has_ck505
= false;
8256 bool can_ssc
= false;
8258 /* We need to take the global config into account */
8259 for_each_intel_encoder(dev
, encoder
) {
8260 switch (encoder
->type
) {
8261 case INTEL_OUTPUT_LVDS
:
8265 case INTEL_OUTPUT_EDP
:
8267 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
8275 if (HAS_PCH_IBX(dev
)) {
8276 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
8277 can_ssc
= has_ck505
;
8283 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
8284 has_panel
, has_lvds
, has_ck505
);
8286 /* Ironlake: try to setup display ref clock before DPLL
8287 * enabling. This is only under driver's control after
8288 * PCH B stepping, previous chipset stepping should be
8289 * ignoring this setting.
8291 val
= I915_READ(PCH_DREF_CONTROL
);
8293 /* As we must carefully and slowly disable/enable each source in turn,
8294 * compute the final state we want first and check if we need to
8295 * make any changes at all.
8298 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
8300 final
|= DREF_NONSPREAD_CK505_ENABLE
;
8302 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
8304 final
&= ~DREF_SSC_SOURCE_MASK
;
8305 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
8306 final
&= ~DREF_SSC1_ENABLE
;
8309 final
|= DREF_SSC_SOURCE_ENABLE
;
8311 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
8312 final
|= DREF_SSC1_ENABLE
;
8315 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
8316 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
8318 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
8320 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
8322 final
|= DREF_SSC_SOURCE_DISABLE
;
8323 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
8329 /* Always enable nonspread source */
8330 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
8333 val
|= DREF_NONSPREAD_CK505_ENABLE
;
8335 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
8338 val
&= ~DREF_SSC_SOURCE_MASK
;
8339 val
|= DREF_SSC_SOURCE_ENABLE
;
8341 /* SSC must be turned on before enabling the CPU output */
8342 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
8343 DRM_DEBUG_KMS("Using SSC on panel\n");
8344 val
|= DREF_SSC1_ENABLE
;
8346 val
&= ~DREF_SSC1_ENABLE
;
8348 /* Get SSC going before enabling the outputs */
8349 I915_WRITE(PCH_DREF_CONTROL
, val
);
8350 POSTING_READ(PCH_DREF_CONTROL
);
8353 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
8355 /* Enable CPU source on CPU attached eDP */
8357 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
8358 DRM_DEBUG_KMS("Using SSC on eDP\n");
8359 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
8361 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
8363 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
8365 I915_WRITE(PCH_DREF_CONTROL
, val
);
8366 POSTING_READ(PCH_DREF_CONTROL
);
8369 DRM_DEBUG_KMS("Disabling SSC entirely\n");
8371 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
8373 /* Turn off CPU output */
8374 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
8376 I915_WRITE(PCH_DREF_CONTROL
, val
);
8377 POSTING_READ(PCH_DREF_CONTROL
);
8380 /* Turn off the SSC source */
8381 val
&= ~DREF_SSC_SOURCE_MASK
;
8382 val
|= DREF_SSC_SOURCE_DISABLE
;
8385 val
&= ~DREF_SSC1_ENABLE
;
8387 I915_WRITE(PCH_DREF_CONTROL
, val
);
8388 POSTING_READ(PCH_DREF_CONTROL
);
8392 BUG_ON(val
!= final
);
8395 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
8399 tmp
= I915_READ(SOUTH_CHICKEN2
);
8400 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
8401 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
8403 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2
) &
8404 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
8405 DRM_ERROR("FDI mPHY reset assert timeout\n");
8407 tmp
= I915_READ(SOUTH_CHICKEN2
);
8408 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
8409 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
8411 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2
) &
8412 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
8413 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
8416 /* WaMPhyProgramming:hsw */
8417 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
8421 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
8422 tmp
&= ~(0xFF << 24);
8423 tmp
|= (0x12 << 24);
8424 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
8426 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
8428 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
8430 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
8432 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
8434 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
8435 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
8436 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
8438 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
8439 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
8440 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
8442 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
8445 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
8447 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
8450 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
8452 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
8455 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
8457 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
8460 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
8462 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
8463 tmp
&= ~(0xFF << 16);
8464 tmp
|= (0x1C << 16);
8465 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
8467 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
8468 tmp
&= ~(0xFF << 16);
8469 tmp
|= (0x1C << 16);
8470 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
8472 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
8474 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
8476 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
8478 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
8480 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
8481 tmp
&= ~(0xF << 28);
8483 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
8485 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
8486 tmp
&= ~(0xF << 28);
8488 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
8491 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8492 * Programming" based on the parameters passed:
8493 * - Sequence to enable CLKOUT_DP
8494 * - Sequence to enable CLKOUT_DP without spread
8495 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8497 static void lpt_enable_clkout_dp(struct drm_device
*dev
, bool with_spread
,
8500 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8503 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
8505 if (WARN(HAS_PCH_LPT_LP(dev
) && with_fdi
, "LP PCH doesn't have FDI\n"))
8508 mutex_lock(&dev_priv
->sb_lock
);
8510 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8511 tmp
&= ~SBI_SSCCTL_DISABLE
;
8512 tmp
|= SBI_SSCCTL_PATHALT
;
8513 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8518 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8519 tmp
&= ~SBI_SSCCTL_PATHALT
;
8520 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8523 lpt_reset_fdi_mphy(dev_priv
);
8524 lpt_program_fdi_mphy(dev_priv
);
8528 reg
= HAS_PCH_LPT_LP(dev
) ? SBI_GEN0
: SBI_DBUFF0
;
8529 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
8530 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
8531 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
8533 mutex_unlock(&dev_priv
->sb_lock
);
8536 /* Sequence to disable CLKOUT_DP */
8537 static void lpt_disable_clkout_dp(struct drm_device
*dev
)
8539 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8542 mutex_lock(&dev_priv
->sb_lock
);
8544 reg
= HAS_PCH_LPT_LP(dev
) ? SBI_GEN0
: SBI_DBUFF0
;
8545 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
8546 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
8547 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
8549 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8550 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
8551 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
8552 tmp
|= SBI_SSCCTL_PATHALT
;
8553 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8556 tmp
|= SBI_SSCCTL_DISABLE
;
8557 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8560 mutex_unlock(&dev_priv
->sb_lock
);
8563 #define BEND_IDX(steps) ((50 + (steps)) / 5)
8565 static const uint16_t sscdivintphase
[] = {
8566 [BEND_IDX( 50)] = 0x3B23,
8567 [BEND_IDX( 45)] = 0x3B23,
8568 [BEND_IDX( 40)] = 0x3C23,
8569 [BEND_IDX( 35)] = 0x3C23,
8570 [BEND_IDX( 30)] = 0x3D23,
8571 [BEND_IDX( 25)] = 0x3D23,
8572 [BEND_IDX( 20)] = 0x3E23,
8573 [BEND_IDX( 15)] = 0x3E23,
8574 [BEND_IDX( 10)] = 0x3F23,
8575 [BEND_IDX( 5)] = 0x3F23,
8576 [BEND_IDX( 0)] = 0x0025,
8577 [BEND_IDX( -5)] = 0x0025,
8578 [BEND_IDX(-10)] = 0x0125,
8579 [BEND_IDX(-15)] = 0x0125,
8580 [BEND_IDX(-20)] = 0x0225,
8581 [BEND_IDX(-25)] = 0x0225,
8582 [BEND_IDX(-30)] = 0x0325,
8583 [BEND_IDX(-35)] = 0x0325,
8584 [BEND_IDX(-40)] = 0x0425,
8585 [BEND_IDX(-45)] = 0x0425,
8586 [BEND_IDX(-50)] = 0x0525,
8591 * steps -50 to 50 inclusive, in steps of 5
8592 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8593 * change in clock period = -(steps / 10) * 5.787 ps
8595 static void lpt_bend_clkout_dp(struct drm_i915_private
*dev_priv
, int steps
)
8598 int idx
= BEND_IDX(steps
);
8600 if (WARN_ON(steps
% 5 != 0))
8603 if (WARN_ON(idx
>= ARRAY_SIZE(sscdivintphase
)))
8606 mutex_lock(&dev_priv
->sb_lock
);
8608 if (steps
% 10 != 0)
8612 intel_sbi_write(dev_priv
, SBI_SSCDITHPHASE
, tmp
, SBI_ICLK
);
8614 tmp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE
, SBI_ICLK
);
8616 tmp
|= sscdivintphase
[idx
];
8617 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE
, tmp
, SBI_ICLK
);
8619 mutex_unlock(&dev_priv
->sb_lock
);
8624 static void lpt_init_pch_refclk(struct drm_device
*dev
)
8626 struct intel_encoder
*encoder
;
8627 bool has_vga
= false;
8629 for_each_intel_encoder(dev
, encoder
) {
8630 switch (encoder
->type
) {
8631 case INTEL_OUTPUT_ANALOG
:
8640 lpt_bend_clkout_dp(to_i915(dev
), 0);
8641 lpt_enable_clkout_dp(dev
, true, true);
8643 lpt_disable_clkout_dp(dev
);
8648 * Initialize reference clocks when the driver loads
8650 void intel_init_pch_refclk(struct drm_device
*dev
)
8652 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
8653 ironlake_init_pch_refclk(dev
);
8654 else if (HAS_PCH_LPT(dev
))
8655 lpt_init_pch_refclk(dev
);
8658 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
8660 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
8661 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8662 int pipe
= intel_crtc
->pipe
;
8667 switch (intel_crtc
->config
->pipe_bpp
) {
8669 val
|= PIPECONF_6BPC
;
8672 val
|= PIPECONF_8BPC
;
8675 val
|= PIPECONF_10BPC
;
8678 val
|= PIPECONF_12BPC
;
8681 /* Case prevented by intel_choose_pipe_bpp_dither. */
8685 if (intel_crtc
->config
->dither
)
8686 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
8688 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8689 val
|= PIPECONF_INTERLACED_ILK
;
8691 val
|= PIPECONF_PROGRESSIVE
;
8693 if (intel_crtc
->config
->limited_color_range
)
8694 val
|= PIPECONF_COLOR_RANGE_SELECT
;
8696 I915_WRITE(PIPECONF(pipe
), val
);
8697 POSTING_READ(PIPECONF(pipe
));
8700 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
8702 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
8703 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8704 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
8707 if (IS_HASWELL(dev_priv
) && intel_crtc
->config
->dither
)
8708 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
8710 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8711 val
|= PIPECONF_INTERLACED_ILK
;
8713 val
|= PIPECONF_PROGRESSIVE
;
8715 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
8716 POSTING_READ(PIPECONF(cpu_transcoder
));
8719 static void haswell_set_pipemisc(struct drm_crtc
*crtc
)
8721 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
8722 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8724 if (IS_BROADWELL(dev_priv
) || INTEL_INFO(dev_priv
)->gen
>= 9) {
8727 switch (intel_crtc
->config
->pipe_bpp
) {
8729 val
|= PIPEMISC_DITHER_6_BPC
;
8732 val
|= PIPEMISC_DITHER_8_BPC
;
8735 val
|= PIPEMISC_DITHER_10_BPC
;
8738 val
|= PIPEMISC_DITHER_12_BPC
;
8741 /* Case prevented by pipe_config_set_bpp. */
8745 if (intel_crtc
->config
->dither
)
8746 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
8748 I915_WRITE(PIPEMISC(intel_crtc
->pipe
), val
);
8752 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
8755 * Account for spread spectrum to avoid
8756 * oversubscribing the link. Max center spread
8757 * is 2.5%; use 5% for safety's sake.
8759 u32 bps
= target_clock
* bpp
* 21 / 20;
8760 return DIV_ROUND_UP(bps
, link_bw
* 8);
8763 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
8765 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
8768 static void ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
8769 struct intel_crtc_state
*crtc_state
,
8770 struct dpll
*reduced_clock
)
8772 struct drm_crtc
*crtc
= &intel_crtc
->base
;
8773 struct drm_device
*dev
= crtc
->dev
;
8774 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8775 struct drm_atomic_state
*state
= crtc_state
->base
.state
;
8776 struct drm_connector
*connector
;
8777 struct drm_connector_state
*connector_state
;
8778 struct intel_encoder
*encoder
;
8781 bool is_lvds
= false, is_sdvo
= false;
8783 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
8784 if (connector_state
->crtc
!= crtc_state
->base
.crtc
)
8787 encoder
= to_intel_encoder(connector_state
->best_encoder
);
8789 switch (encoder
->type
) {
8790 case INTEL_OUTPUT_LVDS
:
8793 case INTEL_OUTPUT_SDVO
:
8794 case INTEL_OUTPUT_HDMI
:
8802 /* Enable autotuning of the PLL clock (if permissible) */
8805 if ((intel_panel_use_ssc(dev_priv
) &&
8806 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
8807 (HAS_PCH_IBX(dev
) && intel_is_dual_link_lvds(dev
)))
8809 } else if (crtc_state
->sdvo_tv_clock
)
8812 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
8814 if (ironlake_needs_fb_cb_tune(&crtc_state
->dpll
, factor
))
8817 if (reduced_clock
) {
8818 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
8820 if (reduced_clock
->m
< factor
* reduced_clock
->n
)
8829 dpll
|= DPLLB_MODE_LVDS
;
8831 dpll
|= DPLLB_MODE_DAC_SERIAL
;
8833 dpll
|= (crtc_state
->pixel_multiplier
- 1)
8834 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
8837 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8838 if (crtc_state
->has_dp_encoder
)
8839 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8841 /* compute bitmask from p1 value */
8842 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8844 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
8846 switch (crtc_state
->dpll
.p2
) {
8848 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
8851 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
8854 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
8857 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
8861 if (is_lvds
&& intel_panel_use_ssc(dev_priv
))
8862 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
8864 dpll
|= PLL_REF_INPUT_DREFCLK
;
8866 dpll
|= DPLL_VCO_ENABLE
;
8868 crtc_state
->dpll_hw_state
.dpll
= dpll
;
8869 crtc_state
->dpll_hw_state
.fp0
= fp
;
8870 crtc_state
->dpll_hw_state
.fp1
= fp2
;
8873 static int ironlake_crtc_compute_clock(struct intel_crtc
*crtc
,
8874 struct intel_crtc_state
*crtc_state
)
8876 struct drm_device
*dev
= crtc
->base
.dev
;
8877 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8878 struct dpll reduced_clock
;
8879 bool has_reduced_clock
= false;
8880 struct intel_shared_dpll
*pll
;
8881 const struct intel_limit
*limit
;
8882 int refclk
= 120000;
8884 memset(&crtc_state
->dpll_hw_state
, 0,
8885 sizeof(crtc_state
->dpll_hw_state
));
8887 crtc
->lowfreq_avail
= false;
8889 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8890 if (!crtc_state
->has_pch_encoder
)
8893 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8894 if (intel_panel_use_ssc(dev_priv
)) {
8895 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8896 dev_priv
->vbt
.lvds_ssc_freq
);
8897 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8900 if (intel_is_dual_link_lvds(dev
)) {
8901 if (refclk
== 100000)
8902 limit
= &intel_limits_ironlake_dual_lvds_100m
;
8904 limit
= &intel_limits_ironlake_dual_lvds
;
8906 if (refclk
== 100000)
8907 limit
= &intel_limits_ironlake_single_lvds_100m
;
8909 limit
= &intel_limits_ironlake_single_lvds
;
8912 limit
= &intel_limits_ironlake_dac
;
8915 if (!crtc_state
->clock_set
&&
8916 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8917 refclk
, NULL
, &crtc_state
->dpll
)) {
8918 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8922 ironlake_compute_dpll(crtc
, crtc_state
,
8923 has_reduced_clock
? &reduced_clock
: NULL
);
8925 pll
= intel_get_shared_dpll(crtc
, crtc_state
, NULL
);
8927 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8928 pipe_name(crtc
->pipe
));
8932 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
8934 crtc
->lowfreq_avail
= true;
8939 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
8940 struct intel_link_m_n
*m_n
)
8942 struct drm_device
*dev
= crtc
->base
.dev
;
8943 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8944 enum pipe pipe
= crtc
->pipe
;
8946 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
8947 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
8948 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
8950 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
8951 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
8952 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8955 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
8956 enum transcoder transcoder
,
8957 struct intel_link_m_n
*m_n
,
8958 struct intel_link_m_n
*m2_n2
)
8960 struct drm_device
*dev
= crtc
->base
.dev
;
8961 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8962 enum pipe pipe
= crtc
->pipe
;
8964 if (INTEL_INFO(dev
)->gen
>= 5) {
8965 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
8966 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
8967 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
8969 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
8970 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
8971 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8972 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8973 * gen < 8) and if DRRS is supported (to make sure the
8974 * registers are not unnecessarily read).
8976 if (m2_n2
&& INTEL_INFO(dev
)->gen
< 8 &&
8977 crtc
->config
->has_drrs
) {
8978 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
8979 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
8980 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
8982 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
8983 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
8984 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8987 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
8988 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
8989 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
8991 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
8992 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
8993 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8997 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
8998 struct intel_crtc_state
*pipe_config
)
9000 if (pipe_config
->has_pch_encoder
)
9001 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
9003 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
9004 &pipe_config
->dp_m_n
,
9005 &pipe_config
->dp_m2_n2
);
9008 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
9009 struct intel_crtc_state
*pipe_config
)
9011 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
9012 &pipe_config
->fdi_m_n
, NULL
);
9015 static void skylake_get_pfit_config(struct intel_crtc
*crtc
,
9016 struct intel_crtc_state
*pipe_config
)
9018 struct drm_device
*dev
= crtc
->base
.dev
;
9019 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9020 struct intel_crtc_scaler_state
*scaler_state
= &pipe_config
->scaler_state
;
9021 uint32_t ps_ctrl
= 0;
9025 /* find scaler attached to this pipe */
9026 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
9027 ps_ctrl
= I915_READ(SKL_PS_CTRL(crtc
->pipe
, i
));
9028 if (ps_ctrl
& PS_SCALER_EN
&& !(ps_ctrl
& PS_PLANE_SEL_MASK
)) {
9030 pipe_config
->pch_pfit
.enabled
= true;
9031 pipe_config
->pch_pfit
.pos
= I915_READ(SKL_PS_WIN_POS(crtc
->pipe
, i
));
9032 pipe_config
->pch_pfit
.size
= I915_READ(SKL_PS_WIN_SZ(crtc
->pipe
, i
));
9037 scaler_state
->scaler_id
= id
;
9039 scaler_state
->scaler_users
|= (1 << SKL_CRTC_INDEX
);
9041 scaler_state
->scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
9046 skylake_get_initial_plane_config(struct intel_crtc
*crtc
,
9047 struct intel_initial_plane_config
*plane_config
)
9049 struct drm_device
*dev
= crtc
->base
.dev
;
9050 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9051 u32 val
, base
, offset
, stride_mult
, tiling
;
9052 int pipe
= crtc
->pipe
;
9053 int fourcc
, pixel_format
;
9054 unsigned int aligned_height
;
9055 struct drm_framebuffer
*fb
;
9056 struct intel_framebuffer
*intel_fb
;
9058 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9060 DRM_DEBUG_KMS("failed to alloc fb\n");
9064 fb
= &intel_fb
->base
;
9066 val
= I915_READ(PLANE_CTL(pipe
, 0));
9067 if (!(val
& PLANE_CTL_ENABLE
))
9070 pixel_format
= val
& PLANE_CTL_FORMAT_MASK
;
9071 fourcc
= skl_format_to_fourcc(pixel_format
,
9072 val
& PLANE_CTL_ORDER_RGBX
,
9073 val
& PLANE_CTL_ALPHA_MASK
);
9074 fb
->pixel_format
= fourcc
;
9075 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
9077 tiling
= val
& PLANE_CTL_TILED_MASK
;
9079 case PLANE_CTL_TILED_LINEAR
:
9080 fb
->modifier
[0] = DRM_FORMAT_MOD_NONE
;
9082 case PLANE_CTL_TILED_X
:
9083 plane_config
->tiling
= I915_TILING_X
;
9084 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
9086 case PLANE_CTL_TILED_Y
:
9087 fb
->modifier
[0] = I915_FORMAT_MOD_Y_TILED
;
9089 case PLANE_CTL_TILED_YF
:
9090 fb
->modifier
[0] = I915_FORMAT_MOD_Yf_TILED
;
9093 MISSING_CASE(tiling
);
9097 base
= I915_READ(PLANE_SURF(pipe
, 0)) & 0xfffff000;
9098 plane_config
->base
= base
;
9100 offset
= I915_READ(PLANE_OFFSET(pipe
, 0));
9102 val
= I915_READ(PLANE_SIZE(pipe
, 0));
9103 fb
->height
= ((val
>> 16) & 0xfff) + 1;
9104 fb
->width
= ((val
>> 0) & 0x1fff) + 1;
9106 val
= I915_READ(PLANE_STRIDE(pipe
, 0));
9107 stride_mult
= intel_fb_stride_alignment(dev_priv
, fb
->modifier
[0],
9109 fb
->pitches
[0] = (val
& 0x3ff) * stride_mult
;
9111 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
9115 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
9117 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9118 pipe_name(pipe
), fb
->width
, fb
->height
,
9119 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
9120 plane_config
->size
);
9122 plane_config
->fb
= intel_fb
;
9129 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
9130 struct intel_crtc_state
*pipe_config
)
9132 struct drm_device
*dev
= crtc
->base
.dev
;
9133 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9136 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
9138 if (tmp
& PF_ENABLE
) {
9139 pipe_config
->pch_pfit
.enabled
= true;
9140 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
9141 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
9143 /* We currently do not free assignements of panel fitters on
9144 * ivb/hsw (since we don't use the higher upscaling modes which
9145 * differentiates them) so just WARN about this case for now. */
9147 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
9148 PF_PIPE_SEL_IVB(crtc
->pipe
));
9154 ironlake_get_initial_plane_config(struct intel_crtc
*crtc
,
9155 struct intel_initial_plane_config
*plane_config
)
9157 struct drm_device
*dev
= crtc
->base
.dev
;
9158 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9159 u32 val
, base
, offset
;
9160 int pipe
= crtc
->pipe
;
9161 int fourcc
, pixel_format
;
9162 unsigned int aligned_height
;
9163 struct drm_framebuffer
*fb
;
9164 struct intel_framebuffer
*intel_fb
;
9166 val
= I915_READ(DSPCNTR(pipe
));
9167 if (!(val
& DISPLAY_PLANE_ENABLE
))
9170 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9172 DRM_DEBUG_KMS("failed to alloc fb\n");
9176 fb
= &intel_fb
->base
;
9178 if (INTEL_INFO(dev
)->gen
>= 4) {
9179 if (val
& DISPPLANE_TILED
) {
9180 plane_config
->tiling
= I915_TILING_X
;
9181 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
9185 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
9186 fourcc
= i9xx_format_to_fourcc(pixel_format
);
9187 fb
->pixel_format
= fourcc
;
9188 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
9190 base
= I915_READ(DSPSURF(pipe
)) & 0xfffff000;
9191 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
9192 offset
= I915_READ(DSPOFFSET(pipe
));
9194 if (plane_config
->tiling
)
9195 offset
= I915_READ(DSPTILEOFF(pipe
));
9197 offset
= I915_READ(DSPLINOFF(pipe
));
9199 plane_config
->base
= base
;
9201 val
= I915_READ(PIPESRC(pipe
));
9202 fb
->width
= ((val
>> 16) & 0xfff) + 1;
9203 fb
->height
= ((val
>> 0) & 0xfff) + 1;
9205 val
= I915_READ(DSPSTRIDE(pipe
));
9206 fb
->pitches
[0] = val
& 0xffffffc0;
9208 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
9212 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
9214 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9215 pipe_name(pipe
), fb
->width
, fb
->height
,
9216 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
9217 plane_config
->size
);
9219 plane_config
->fb
= intel_fb
;
9222 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
9223 struct intel_crtc_state
*pipe_config
)
9225 struct drm_device
*dev
= crtc
->base
.dev
;
9226 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9227 enum intel_display_power_domain power_domain
;
9231 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
9232 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9235 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
9236 pipe_config
->shared_dpll
= NULL
;
9239 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
9240 if (!(tmp
& PIPECONF_ENABLE
))
9243 switch (tmp
& PIPECONF_BPC_MASK
) {
9245 pipe_config
->pipe_bpp
= 18;
9248 pipe_config
->pipe_bpp
= 24;
9250 case PIPECONF_10BPC
:
9251 pipe_config
->pipe_bpp
= 30;
9253 case PIPECONF_12BPC
:
9254 pipe_config
->pipe_bpp
= 36;
9260 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
9261 pipe_config
->limited_color_range
= true;
9263 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
9264 struct intel_shared_dpll
*pll
;
9265 enum intel_dpll_id pll_id
;
9267 pipe_config
->has_pch_encoder
= true;
9269 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
9270 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
9271 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
9273 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
9275 if (HAS_PCH_IBX(dev_priv
)) {
9277 * The pipe->pch transcoder and pch transcoder->pll
9280 pll_id
= (enum intel_dpll_id
) crtc
->pipe
;
9282 tmp
= I915_READ(PCH_DPLL_SEL
);
9283 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
9284 pll_id
= DPLL_ID_PCH_PLL_B
;
9286 pll_id
= DPLL_ID_PCH_PLL_A
;
9289 pipe_config
->shared_dpll
=
9290 intel_get_shared_dpll_by_id(dev_priv
, pll_id
);
9291 pll
= pipe_config
->shared_dpll
;
9293 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
9294 &pipe_config
->dpll_hw_state
));
9296 tmp
= pipe_config
->dpll_hw_state
.dpll
;
9297 pipe_config
->pixel_multiplier
=
9298 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
9299 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
9301 ironlake_pch_clock_get(crtc
, pipe_config
);
9303 pipe_config
->pixel_multiplier
= 1;
9306 intel_get_pipe_timings(crtc
, pipe_config
);
9307 intel_get_pipe_src_size(crtc
, pipe_config
);
9309 ironlake_get_pfit_config(crtc
, pipe_config
);
9314 intel_display_power_put(dev_priv
, power_domain
);
9319 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
9321 struct drm_device
*dev
= dev_priv
->dev
;
9322 struct intel_crtc
*crtc
;
9324 for_each_intel_crtc(dev
, crtc
)
9325 I915_STATE_WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
9326 pipe_name(crtc
->pipe
));
9328 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
9329 I915_STATE_WARN(I915_READ(SPLL_CTL
) & SPLL_PLL_ENABLE
, "SPLL enabled\n");
9330 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE
, "WRPLL1 enabled\n");
9331 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE
, "WRPLL2 enabled\n");
9332 I915_STATE_WARN(I915_READ(PCH_PP_STATUS
) & PP_ON
, "Panel power on\n");
9333 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
9334 "CPU PWM1 enabled\n");
9335 if (IS_HASWELL(dev
))
9336 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
9337 "CPU PWM2 enabled\n");
9338 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
9339 "PCH PWM1 enabled\n");
9340 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
9341 "Utility pin enabled\n");
9342 I915_STATE_WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
9345 * In theory we can still leave IRQs enabled, as long as only the HPD
9346 * interrupts remain enabled. We used to check for that, but since it's
9347 * gen-specific and since we only disable LCPLL after we fully disable
9348 * the interrupts, the check below should be enough.
9350 I915_STATE_WARN(intel_irqs_enabled(dev_priv
), "IRQs enabled\n");
9353 static uint32_t hsw_read_dcomp(struct drm_i915_private
*dev_priv
)
9355 struct drm_device
*dev
= dev_priv
->dev
;
9357 if (IS_HASWELL(dev
))
9358 return I915_READ(D_COMP_HSW
);
9360 return I915_READ(D_COMP_BDW
);
9363 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
9365 struct drm_device
*dev
= dev_priv
->dev
;
9367 if (IS_HASWELL(dev
)) {
9368 mutex_lock(&dev_priv
->rps
.hw_lock
);
9369 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
9371 DRM_ERROR("Failed to write to D_COMP\n");
9372 mutex_unlock(&dev_priv
->rps
.hw_lock
);
9374 I915_WRITE(D_COMP_BDW
, val
);
9375 POSTING_READ(D_COMP_BDW
);
9380 * This function implements pieces of two sequences from BSpec:
9381 * - Sequence for display software to disable LCPLL
9382 * - Sequence for display software to allow package C8+
9383 * The steps implemented here are just the steps that actually touch the LCPLL
9384 * register. Callers should take care of disabling all the display engine
9385 * functions, doing the mode unset, fixing interrupts, etc.
9387 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
9388 bool switch_to_fclk
, bool allow_power_down
)
9392 assert_can_disable_lcpll(dev_priv
);
9394 val
= I915_READ(LCPLL_CTL
);
9396 if (switch_to_fclk
) {
9397 val
|= LCPLL_CD_SOURCE_FCLK
;
9398 I915_WRITE(LCPLL_CTL
, val
);
9400 if (wait_for_atomic_us(I915_READ(LCPLL_CTL
) &
9401 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
9402 DRM_ERROR("Switching to FCLK failed\n");
9404 val
= I915_READ(LCPLL_CTL
);
9407 val
|= LCPLL_PLL_DISABLE
;
9408 I915_WRITE(LCPLL_CTL
, val
);
9409 POSTING_READ(LCPLL_CTL
);
9411 if (wait_for((I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
) == 0, 1))
9412 DRM_ERROR("LCPLL still locked\n");
9414 val
= hsw_read_dcomp(dev_priv
);
9415 val
|= D_COMP_COMP_DISABLE
;
9416 hsw_write_dcomp(dev_priv
, val
);
9419 if (wait_for((hsw_read_dcomp(dev_priv
) & D_COMP_RCOMP_IN_PROGRESS
) == 0,
9421 DRM_ERROR("D_COMP RCOMP still in progress\n");
9423 if (allow_power_down
) {
9424 val
= I915_READ(LCPLL_CTL
);
9425 val
|= LCPLL_POWER_DOWN_ALLOW
;
9426 I915_WRITE(LCPLL_CTL
, val
);
9427 POSTING_READ(LCPLL_CTL
);
9432 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9435 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
9439 val
= I915_READ(LCPLL_CTL
);
9441 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
9442 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
9446 * Make sure we're not on PC8 state before disabling PC8, otherwise
9447 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
9449 intel_uncore_forcewake_get(dev_priv
, FORCEWAKE_ALL
);
9451 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
9452 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
9453 I915_WRITE(LCPLL_CTL
, val
);
9454 POSTING_READ(LCPLL_CTL
);
9457 val
= hsw_read_dcomp(dev_priv
);
9458 val
|= D_COMP_COMP_FORCE
;
9459 val
&= ~D_COMP_COMP_DISABLE
;
9460 hsw_write_dcomp(dev_priv
, val
);
9462 val
= I915_READ(LCPLL_CTL
);
9463 val
&= ~LCPLL_PLL_DISABLE
;
9464 I915_WRITE(LCPLL_CTL
, val
);
9466 if (wait_for(I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
, 5))
9467 DRM_ERROR("LCPLL not locked yet\n");
9469 if (val
& LCPLL_CD_SOURCE_FCLK
) {
9470 val
= I915_READ(LCPLL_CTL
);
9471 val
&= ~LCPLL_CD_SOURCE_FCLK
;
9472 I915_WRITE(LCPLL_CTL
, val
);
9474 if (wait_for_atomic_us((I915_READ(LCPLL_CTL
) &
9475 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
9476 DRM_ERROR("Switching back to LCPLL failed\n");
9479 intel_uncore_forcewake_put(dev_priv
, FORCEWAKE_ALL
);
9480 intel_update_cdclk(dev_priv
->dev
);
9484 * Package states C8 and deeper are really deep PC states that can only be
9485 * reached when all the devices on the system allow it, so even if the graphics
9486 * device allows PC8+, it doesn't mean the system will actually get to these
9487 * states. Our driver only allows PC8+ when going into runtime PM.
9489 * The requirements for PC8+ are that all the outputs are disabled, the power
9490 * well is disabled and most interrupts are disabled, and these are also
9491 * requirements for runtime PM. When these conditions are met, we manually do
9492 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9493 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9496 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9497 * the state of some registers, so when we come back from PC8+ we need to
9498 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9499 * need to take care of the registers kept by RC6. Notice that this happens even
9500 * if we don't put the device in PCI D3 state (which is what currently happens
9501 * because of the runtime PM support).
9503 * For more, read "Display Sequences for Package C8" on the hardware
9506 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
9508 struct drm_device
*dev
= dev_priv
->dev
;
9511 DRM_DEBUG_KMS("Enabling package C8+\n");
9513 if (HAS_PCH_LPT_LP(dev
)) {
9514 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
9515 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
9516 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
9519 lpt_disable_clkout_dp(dev
);
9520 hsw_disable_lcpll(dev_priv
, true, true);
9523 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
9525 struct drm_device
*dev
= dev_priv
->dev
;
9528 DRM_DEBUG_KMS("Disabling package C8+\n");
9530 hsw_restore_lcpll(dev_priv
);
9531 lpt_init_pch_refclk(dev
);
9533 if (HAS_PCH_LPT_LP(dev
)) {
9534 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
9535 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
9536 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
9540 static void broxton_modeset_commit_cdclk(struct drm_atomic_state
*old_state
)
9542 struct drm_device
*dev
= old_state
->dev
;
9543 struct intel_atomic_state
*old_intel_state
=
9544 to_intel_atomic_state(old_state
);
9545 unsigned int req_cdclk
= old_intel_state
->dev_cdclk
;
9547 broxton_set_cdclk(to_i915(dev
), req_cdclk
);
9550 /* compute the max rate for new configuration */
9551 static int ilk_max_pixel_rate(struct drm_atomic_state
*state
)
9553 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
9554 struct drm_i915_private
*dev_priv
= state
->dev
->dev_private
;
9555 struct drm_crtc
*crtc
;
9556 struct drm_crtc_state
*cstate
;
9557 struct intel_crtc_state
*crtc_state
;
9558 unsigned max_pixel_rate
= 0, i
;
9561 memcpy(intel_state
->min_pixclk
, dev_priv
->min_pixclk
,
9562 sizeof(intel_state
->min_pixclk
));
9564 for_each_crtc_in_state(state
, crtc
, cstate
, i
) {
9567 crtc_state
= to_intel_crtc_state(cstate
);
9568 if (!crtc_state
->base
.enable
) {
9569 intel_state
->min_pixclk
[i
] = 0;
9573 pixel_rate
= ilk_pipe_pixel_rate(crtc_state
);
9575 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
9576 if (IS_BROADWELL(dev_priv
) && crtc_state
->ips_enabled
)
9577 pixel_rate
= DIV_ROUND_UP(pixel_rate
* 100, 95);
9579 intel_state
->min_pixclk
[i
] = pixel_rate
;
9582 for_each_pipe(dev_priv
, pipe
)
9583 max_pixel_rate
= max(intel_state
->min_pixclk
[pipe
], max_pixel_rate
);
9585 return max_pixel_rate
;
9588 static void broadwell_set_cdclk(struct drm_device
*dev
, int cdclk
)
9590 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9594 if (WARN((I915_READ(LCPLL_CTL
) &
9595 (LCPLL_PLL_DISABLE
| LCPLL_PLL_LOCK
|
9596 LCPLL_CD_CLOCK_DISABLE
| LCPLL_ROOT_CD_CLOCK_DISABLE
|
9597 LCPLL_CD2X_CLOCK_DISABLE
| LCPLL_POWER_DOWN_ALLOW
|
9598 LCPLL_CD_SOURCE_FCLK
)) != LCPLL_PLL_LOCK
,
9599 "trying to change cdclk frequency with cdclk not enabled\n"))
9602 mutex_lock(&dev_priv
->rps
.hw_lock
);
9603 ret
= sandybridge_pcode_write(dev_priv
,
9604 BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ
, 0x0);
9605 mutex_unlock(&dev_priv
->rps
.hw_lock
);
9607 DRM_ERROR("failed to inform pcode about cdclk change\n");
9611 val
= I915_READ(LCPLL_CTL
);
9612 val
|= LCPLL_CD_SOURCE_FCLK
;
9613 I915_WRITE(LCPLL_CTL
, val
);
9615 if (wait_for_us(I915_READ(LCPLL_CTL
) &
9616 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
9617 DRM_ERROR("Switching to FCLK failed\n");
9619 val
= I915_READ(LCPLL_CTL
);
9620 val
&= ~LCPLL_CLK_FREQ_MASK
;
9624 val
|= LCPLL_CLK_FREQ_450
;
9628 val
|= LCPLL_CLK_FREQ_54O_BDW
;
9632 val
|= LCPLL_CLK_FREQ_337_5_BDW
;
9636 val
|= LCPLL_CLK_FREQ_675_BDW
;
9640 WARN(1, "invalid cdclk frequency\n");
9644 I915_WRITE(LCPLL_CTL
, val
);
9646 val
= I915_READ(LCPLL_CTL
);
9647 val
&= ~LCPLL_CD_SOURCE_FCLK
;
9648 I915_WRITE(LCPLL_CTL
, val
);
9650 if (wait_for_us((I915_READ(LCPLL_CTL
) &
9651 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
9652 DRM_ERROR("Switching back to LCPLL failed\n");
9654 mutex_lock(&dev_priv
->rps
.hw_lock
);
9655 sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
, data
);
9656 mutex_unlock(&dev_priv
->rps
.hw_lock
);
9658 I915_WRITE(CDCLK_FREQ
, DIV_ROUND_CLOSEST(cdclk
, 1000) - 1);
9660 intel_update_cdclk(dev
);
9662 WARN(cdclk
!= dev_priv
->cdclk_freq
,
9663 "cdclk requested %d kHz but got %d kHz\n",
9664 cdclk
, dev_priv
->cdclk_freq
);
9667 static int broadwell_calc_cdclk(int max_pixclk
)
9669 if (max_pixclk
> 540000)
9671 else if (max_pixclk
> 450000)
9673 else if (max_pixclk
> 337500)
9679 static int broadwell_modeset_calc_cdclk(struct drm_atomic_state
*state
)
9681 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
9682 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
9683 int max_pixclk
= ilk_max_pixel_rate(state
);
9687 * FIXME should also account for plane ratio
9688 * once 64bpp pixel formats are supported.
9690 cdclk
= broadwell_calc_cdclk(max_pixclk
);
9692 if (cdclk
> dev_priv
->max_cdclk_freq
) {
9693 DRM_DEBUG_KMS("requested cdclk (%d kHz) exceeds max (%d kHz)\n",
9694 cdclk
, dev_priv
->max_cdclk_freq
);
9698 intel_state
->cdclk
= intel_state
->dev_cdclk
= cdclk
;
9699 if (!intel_state
->active_crtcs
)
9700 intel_state
->dev_cdclk
= broadwell_calc_cdclk(0);
9705 static void broadwell_modeset_commit_cdclk(struct drm_atomic_state
*old_state
)
9707 struct drm_device
*dev
= old_state
->dev
;
9708 struct intel_atomic_state
*old_intel_state
=
9709 to_intel_atomic_state(old_state
);
9710 unsigned req_cdclk
= old_intel_state
->dev_cdclk
;
9712 broadwell_set_cdclk(dev
, req_cdclk
);
9715 static int haswell_crtc_compute_clock(struct intel_crtc
*crtc
,
9716 struct intel_crtc_state
*crtc_state
)
9718 struct intel_encoder
*intel_encoder
=
9719 intel_ddi_get_crtc_new_encoder(crtc_state
);
9721 if (intel_encoder
->type
!= INTEL_OUTPUT_DSI
) {
9722 if (!intel_ddi_pll_select(crtc
, crtc_state
))
9726 crtc
->lowfreq_avail
= false;
9731 static void bxt_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9733 struct intel_crtc_state
*pipe_config
)
9735 enum intel_dpll_id id
;
9739 pipe_config
->ddi_pll_sel
= SKL_DPLL0
;
9740 id
= DPLL_ID_SKL_DPLL0
;
9743 pipe_config
->ddi_pll_sel
= SKL_DPLL1
;
9744 id
= DPLL_ID_SKL_DPLL1
;
9747 pipe_config
->ddi_pll_sel
= SKL_DPLL2
;
9748 id
= DPLL_ID_SKL_DPLL2
;
9751 DRM_ERROR("Incorrect port type\n");
9755 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
9758 static void skylake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9760 struct intel_crtc_state
*pipe_config
)
9762 enum intel_dpll_id id
;
9765 temp
= I915_READ(DPLL_CTRL2
) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port
);
9766 pipe_config
->ddi_pll_sel
= temp
>> (port
* 3 + 1);
9768 switch (pipe_config
->ddi_pll_sel
) {
9770 id
= DPLL_ID_SKL_DPLL0
;
9773 id
= DPLL_ID_SKL_DPLL1
;
9776 id
= DPLL_ID_SKL_DPLL2
;
9779 id
= DPLL_ID_SKL_DPLL3
;
9782 MISSING_CASE(pipe_config
->ddi_pll_sel
);
9786 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
9789 static void haswell_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9791 struct intel_crtc_state
*pipe_config
)
9793 enum intel_dpll_id id
;
9795 pipe_config
->ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
9797 switch (pipe_config
->ddi_pll_sel
) {
9798 case PORT_CLK_SEL_WRPLL1
:
9799 id
= DPLL_ID_WRPLL1
;
9801 case PORT_CLK_SEL_WRPLL2
:
9802 id
= DPLL_ID_WRPLL2
;
9804 case PORT_CLK_SEL_SPLL
:
9807 case PORT_CLK_SEL_LCPLL_810
:
9808 id
= DPLL_ID_LCPLL_810
;
9810 case PORT_CLK_SEL_LCPLL_1350
:
9811 id
= DPLL_ID_LCPLL_1350
;
9813 case PORT_CLK_SEL_LCPLL_2700
:
9814 id
= DPLL_ID_LCPLL_2700
;
9817 MISSING_CASE(pipe_config
->ddi_pll_sel
);
9819 case PORT_CLK_SEL_NONE
:
9823 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
9826 static bool hsw_get_transcoder_state(struct intel_crtc
*crtc
,
9827 struct intel_crtc_state
*pipe_config
,
9828 unsigned long *power_domain_mask
)
9830 struct drm_device
*dev
= crtc
->base
.dev
;
9831 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9832 enum intel_display_power_domain power_domain
;
9836 * The pipe->transcoder mapping is fixed with the exception of the eDP
9837 * transcoder handled below.
9839 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
9842 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9843 * consistency and less surprising code; it's in always on power).
9845 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
9846 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
9847 enum pipe trans_edp_pipe
;
9848 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
9850 WARN(1, "unknown pipe linked to edp transcoder\n");
9851 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
9852 case TRANS_DDI_EDP_INPUT_A_ON
:
9853 trans_edp_pipe
= PIPE_A
;
9855 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
9856 trans_edp_pipe
= PIPE_B
;
9858 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
9859 trans_edp_pipe
= PIPE_C
;
9863 if (trans_edp_pipe
== crtc
->pipe
)
9864 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
9867 power_domain
= POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
);
9868 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9870 *power_domain_mask
|= BIT(power_domain
);
9872 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
9874 return tmp
& PIPECONF_ENABLE
;
9877 static bool bxt_get_dsi_transcoder_state(struct intel_crtc
*crtc
,
9878 struct intel_crtc_state
*pipe_config
,
9879 unsigned long *power_domain_mask
)
9881 struct drm_device
*dev
= crtc
->base
.dev
;
9882 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9883 enum intel_display_power_domain power_domain
;
9885 enum transcoder cpu_transcoder
;
9888 pipe_config
->has_dsi_encoder
= false;
9890 for_each_port_masked(port
, BIT(PORT_A
) | BIT(PORT_C
)) {
9892 cpu_transcoder
= TRANSCODER_DSI_A
;
9894 cpu_transcoder
= TRANSCODER_DSI_C
;
9896 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
9897 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9899 *power_domain_mask
|= BIT(power_domain
);
9902 * The PLL needs to be enabled with a valid divider
9903 * configuration, otherwise accessing DSI registers will hang
9904 * the machine. See BSpec North Display Engine
9905 * registers/MIPI[BXT]. We can break out here early, since we
9906 * need the same DSI PLL to be enabled for both DSI ports.
9908 if (!intel_dsi_pll_is_enabled(dev_priv
))
9911 /* XXX: this works for video mode only */
9912 tmp
= I915_READ(BXT_MIPI_PORT_CTRL(port
));
9913 if (!(tmp
& DPI_ENABLE
))
9916 tmp
= I915_READ(MIPI_CTRL(port
));
9917 if ((tmp
& BXT_PIPE_SELECT_MASK
) != BXT_PIPE_SELECT(crtc
->pipe
))
9920 pipe_config
->cpu_transcoder
= cpu_transcoder
;
9921 pipe_config
->has_dsi_encoder
= true;
9925 return pipe_config
->has_dsi_encoder
;
9928 static void haswell_get_ddi_port_state(struct intel_crtc
*crtc
,
9929 struct intel_crtc_state
*pipe_config
)
9931 struct drm_device
*dev
= crtc
->base
.dev
;
9932 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9933 struct intel_shared_dpll
*pll
;
9937 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
9939 port
= (tmp
& TRANS_DDI_PORT_MASK
) >> TRANS_DDI_PORT_SHIFT
;
9941 if (IS_SKYLAKE(dev
) || IS_KABYLAKE(dev
))
9942 skylake_get_ddi_pll(dev_priv
, port
, pipe_config
);
9943 else if (IS_BROXTON(dev
))
9944 bxt_get_ddi_pll(dev_priv
, port
, pipe_config
);
9946 haswell_get_ddi_pll(dev_priv
, port
, pipe_config
);
9948 pll
= pipe_config
->shared_dpll
;
9950 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
9951 &pipe_config
->dpll_hw_state
));
9955 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9956 * DDI E. So just check whether this pipe is wired to DDI E and whether
9957 * the PCH transcoder is on.
9959 if (INTEL_INFO(dev
)->gen
< 9 &&
9960 (port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
9961 pipe_config
->has_pch_encoder
= true;
9963 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
9964 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
9965 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
9967 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
9971 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
9972 struct intel_crtc_state
*pipe_config
)
9974 struct drm_device
*dev
= crtc
->base
.dev
;
9975 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9976 enum intel_display_power_domain power_domain
;
9977 unsigned long power_domain_mask
;
9980 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
9981 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9983 power_domain_mask
= BIT(power_domain
);
9985 pipe_config
->shared_dpll
= NULL
;
9987 active
= hsw_get_transcoder_state(crtc
, pipe_config
, &power_domain_mask
);
9989 if (IS_BROXTON(dev_priv
)) {
9990 bxt_get_dsi_transcoder_state(crtc
, pipe_config
,
9991 &power_domain_mask
);
9992 WARN_ON(active
&& pipe_config
->has_dsi_encoder
);
9993 if (pipe_config
->has_dsi_encoder
)
10000 if (!pipe_config
->has_dsi_encoder
) {
10001 haswell_get_ddi_port_state(crtc
, pipe_config
);
10002 intel_get_pipe_timings(crtc
, pipe_config
);
10005 intel_get_pipe_src_size(crtc
, pipe_config
);
10007 pipe_config
->gamma_mode
=
10008 I915_READ(GAMMA_MODE(crtc
->pipe
)) & GAMMA_MODE_MODE_MASK
;
10010 if (INTEL_INFO(dev
)->gen
>= 9) {
10011 skl_init_scalers(dev
, crtc
, pipe_config
);
10014 if (INTEL_INFO(dev
)->gen
>= 9) {
10015 pipe_config
->scaler_state
.scaler_id
= -1;
10016 pipe_config
->scaler_state
.scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
10019 power_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
10020 if (intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
10021 power_domain_mask
|= BIT(power_domain
);
10022 if (INTEL_INFO(dev
)->gen
>= 9)
10023 skylake_get_pfit_config(crtc
, pipe_config
);
10025 ironlake_get_pfit_config(crtc
, pipe_config
);
10028 if (IS_HASWELL(dev
))
10029 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
10030 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
10032 if (pipe_config
->cpu_transcoder
!= TRANSCODER_EDP
&&
10033 !transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
10034 pipe_config
->pixel_multiplier
=
10035 I915_READ(PIPE_MULT(pipe_config
->cpu_transcoder
)) + 1;
10037 pipe_config
->pixel_multiplier
= 1;
10041 for_each_power_domain(power_domain
, power_domain_mask
)
10042 intel_display_power_put(dev_priv
, power_domain
);
10047 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
,
10048 const struct intel_plane_state
*plane_state
)
10050 struct drm_device
*dev
= crtc
->dev
;
10051 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10052 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10053 uint32_t cntl
= 0, size
= 0;
10055 if (plane_state
&& plane_state
->visible
) {
10056 unsigned int width
= plane_state
->base
.crtc_w
;
10057 unsigned int height
= plane_state
->base
.crtc_h
;
10058 unsigned int stride
= roundup_pow_of_two(width
) * 4;
10062 WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
10073 cntl
|= CURSOR_ENABLE
|
10074 CURSOR_GAMMA_ENABLE
|
10075 CURSOR_FORMAT_ARGB
|
10076 CURSOR_STRIDE(stride
);
10078 size
= (height
<< 12) | width
;
10081 if (intel_crtc
->cursor_cntl
!= 0 &&
10082 (intel_crtc
->cursor_base
!= base
||
10083 intel_crtc
->cursor_size
!= size
||
10084 intel_crtc
->cursor_cntl
!= cntl
)) {
10085 /* On these chipsets we can only modify the base/size/stride
10086 * whilst the cursor is disabled.
10088 I915_WRITE(CURCNTR(PIPE_A
), 0);
10089 POSTING_READ(CURCNTR(PIPE_A
));
10090 intel_crtc
->cursor_cntl
= 0;
10093 if (intel_crtc
->cursor_base
!= base
) {
10094 I915_WRITE(CURBASE(PIPE_A
), base
);
10095 intel_crtc
->cursor_base
= base
;
10098 if (intel_crtc
->cursor_size
!= size
) {
10099 I915_WRITE(CURSIZE
, size
);
10100 intel_crtc
->cursor_size
= size
;
10103 if (intel_crtc
->cursor_cntl
!= cntl
) {
10104 I915_WRITE(CURCNTR(PIPE_A
), cntl
);
10105 POSTING_READ(CURCNTR(PIPE_A
));
10106 intel_crtc
->cursor_cntl
= cntl
;
10110 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
,
10111 const struct intel_plane_state
*plane_state
)
10113 struct drm_device
*dev
= crtc
->dev
;
10114 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10115 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10116 int pipe
= intel_crtc
->pipe
;
10119 if (plane_state
&& plane_state
->visible
) {
10120 cntl
= MCURSOR_GAMMA_ENABLE
;
10121 switch (plane_state
->base
.crtc_w
) {
10123 cntl
|= CURSOR_MODE_64_ARGB_AX
;
10126 cntl
|= CURSOR_MODE_128_ARGB_AX
;
10129 cntl
|= CURSOR_MODE_256_ARGB_AX
;
10132 MISSING_CASE(plane_state
->base
.crtc_w
);
10135 cntl
|= pipe
<< 28; /* Connect to correct pipe */
10138 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
10140 if (plane_state
->base
.rotation
== BIT(DRM_ROTATE_180
))
10141 cntl
|= CURSOR_ROTATE_180
;
10144 if (intel_crtc
->cursor_cntl
!= cntl
) {
10145 I915_WRITE(CURCNTR(pipe
), cntl
);
10146 POSTING_READ(CURCNTR(pipe
));
10147 intel_crtc
->cursor_cntl
= cntl
;
10150 /* and commit changes on next vblank */
10151 I915_WRITE(CURBASE(pipe
), base
);
10152 POSTING_READ(CURBASE(pipe
));
10154 intel_crtc
->cursor_base
= base
;
10157 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
10158 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
10159 const struct intel_plane_state
*plane_state
)
10161 struct drm_device
*dev
= crtc
->dev
;
10162 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10163 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10164 int pipe
= intel_crtc
->pipe
;
10165 u32 base
= intel_crtc
->cursor_addr
;
10169 int x
= plane_state
->base
.crtc_x
;
10170 int y
= plane_state
->base
.crtc_y
;
10173 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
10176 pos
|= x
<< CURSOR_X_SHIFT
;
10179 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
10182 pos
|= y
<< CURSOR_Y_SHIFT
;
10184 /* ILK+ do this automagically */
10185 if (HAS_GMCH_DISPLAY(dev
) &&
10186 plane_state
->base
.rotation
== BIT(DRM_ROTATE_180
)) {
10187 base
+= (plane_state
->base
.crtc_h
*
10188 plane_state
->base
.crtc_w
- 1) * 4;
10192 I915_WRITE(CURPOS(pipe
), pos
);
10194 if (IS_845G(dev
) || IS_I865G(dev
))
10195 i845_update_cursor(crtc
, base
, plane_state
);
10197 i9xx_update_cursor(crtc
, base
, plane_state
);
10200 static bool cursor_size_ok(struct drm_device
*dev
,
10201 uint32_t width
, uint32_t height
)
10203 if (width
== 0 || height
== 0)
10207 * 845g/865g are special in that they are only limited by
10208 * the width of their cursors, the height is arbitrary up to
10209 * the precision of the register. Everything else requires
10210 * square cursors, limited to a few power-of-two sizes.
10212 if (IS_845G(dev
) || IS_I865G(dev
)) {
10213 if ((width
& 63) != 0)
10216 if (width
> (IS_845G(dev
) ? 64 : 512))
10222 switch (width
| height
) {
10237 /* VESA 640x480x72Hz mode to set on the pipe */
10238 static struct drm_display_mode load_detect_mode
= {
10239 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
10240 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
10243 struct drm_framebuffer
*
10244 __intel_framebuffer_create(struct drm_device
*dev
,
10245 struct drm_mode_fb_cmd2
*mode_cmd
,
10246 struct drm_i915_gem_object
*obj
)
10248 struct intel_framebuffer
*intel_fb
;
10251 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
10253 return ERR_PTR(-ENOMEM
);
10255 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
10259 return &intel_fb
->base
;
10263 return ERR_PTR(ret
);
10266 static struct drm_framebuffer
*
10267 intel_framebuffer_create(struct drm_device
*dev
,
10268 struct drm_mode_fb_cmd2
*mode_cmd
,
10269 struct drm_i915_gem_object
*obj
)
10271 struct drm_framebuffer
*fb
;
10274 ret
= i915_mutex_lock_interruptible(dev
);
10276 return ERR_PTR(ret
);
10277 fb
= __intel_framebuffer_create(dev
, mode_cmd
, obj
);
10278 mutex_unlock(&dev
->struct_mutex
);
10284 intel_framebuffer_pitch_for_width(int width
, int bpp
)
10286 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
10287 return ALIGN(pitch
, 64);
10291 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
10293 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
10294 return PAGE_ALIGN(pitch
* mode
->vdisplay
);
10297 static struct drm_framebuffer
*
10298 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
10299 struct drm_display_mode
*mode
,
10300 int depth
, int bpp
)
10302 struct drm_framebuffer
*fb
;
10303 struct drm_i915_gem_object
*obj
;
10304 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
10306 obj
= i915_gem_object_create(dev
,
10307 intel_framebuffer_size_for_mode(mode
, bpp
));
10309 return ERR_CAST(obj
);
10311 mode_cmd
.width
= mode
->hdisplay
;
10312 mode_cmd
.height
= mode
->vdisplay
;
10313 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
10315 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
10317 fb
= intel_framebuffer_create(dev
, &mode_cmd
, obj
);
10319 drm_gem_object_unreference_unlocked(&obj
->base
);
10324 static struct drm_framebuffer
*
10325 mode_fits_in_fbdev(struct drm_device
*dev
,
10326 struct drm_display_mode
*mode
)
10328 #ifdef CONFIG_DRM_FBDEV_EMULATION
10329 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10330 struct drm_i915_gem_object
*obj
;
10331 struct drm_framebuffer
*fb
;
10333 if (!dev_priv
->fbdev
)
10336 if (!dev_priv
->fbdev
->fb
)
10339 obj
= dev_priv
->fbdev
->fb
->obj
;
10342 fb
= &dev_priv
->fbdev
->fb
->base
;
10343 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
10344 fb
->bits_per_pixel
))
10347 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
10350 drm_framebuffer_reference(fb
);
10357 static int intel_modeset_setup_plane_state(struct drm_atomic_state
*state
,
10358 struct drm_crtc
*crtc
,
10359 struct drm_display_mode
*mode
,
10360 struct drm_framebuffer
*fb
,
10363 struct drm_plane_state
*plane_state
;
10364 int hdisplay
, vdisplay
;
10367 plane_state
= drm_atomic_get_plane_state(state
, crtc
->primary
);
10368 if (IS_ERR(plane_state
))
10369 return PTR_ERR(plane_state
);
10372 drm_crtc_get_hv_timing(mode
, &hdisplay
, &vdisplay
);
10374 hdisplay
= vdisplay
= 0;
10376 ret
= drm_atomic_set_crtc_for_plane(plane_state
, fb
? crtc
: NULL
);
10379 drm_atomic_set_fb_for_plane(plane_state
, fb
);
10380 plane_state
->crtc_x
= 0;
10381 plane_state
->crtc_y
= 0;
10382 plane_state
->crtc_w
= hdisplay
;
10383 plane_state
->crtc_h
= vdisplay
;
10384 plane_state
->src_x
= x
<< 16;
10385 plane_state
->src_y
= y
<< 16;
10386 plane_state
->src_w
= hdisplay
<< 16;
10387 plane_state
->src_h
= vdisplay
<< 16;
10392 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
10393 struct drm_display_mode
*mode
,
10394 struct intel_load_detect_pipe
*old
,
10395 struct drm_modeset_acquire_ctx
*ctx
)
10397 struct intel_crtc
*intel_crtc
;
10398 struct intel_encoder
*intel_encoder
=
10399 intel_attached_encoder(connector
);
10400 struct drm_crtc
*possible_crtc
;
10401 struct drm_encoder
*encoder
= &intel_encoder
->base
;
10402 struct drm_crtc
*crtc
= NULL
;
10403 struct drm_device
*dev
= encoder
->dev
;
10404 struct drm_framebuffer
*fb
;
10405 struct drm_mode_config
*config
= &dev
->mode_config
;
10406 struct drm_atomic_state
*state
= NULL
, *restore_state
= NULL
;
10407 struct drm_connector_state
*connector_state
;
10408 struct intel_crtc_state
*crtc_state
;
10411 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10412 connector
->base
.id
, connector
->name
,
10413 encoder
->base
.id
, encoder
->name
);
10415 old
->restore_state
= NULL
;
10418 ret
= drm_modeset_lock(&config
->connection_mutex
, ctx
);
10423 * Algorithm gets a little messy:
10425 * - if the connector already has an assigned crtc, use it (but make
10426 * sure it's on first)
10428 * - try to find the first unused crtc that can drive this connector,
10429 * and use that if we find one
10432 /* See if we already have a CRTC for this connector */
10433 if (connector
->state
->crtc
) {
10434 crtc
= connector
->state
->crtc
;
10436 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
10440 /* Make sure the crtc and connector are running */
10444 /* Find an unused one (if possible) */
10445 for_each_crtc(dev
, possible_crtc
) {
10447 if (!(encoder
->possible_crtcs
& (1 << i
)))
10450 ret
= drm_modeset_lock(&possible_crtc
->mutex
, ctx
);
10454 if (possible_crtc
->state
->enable
) {
10455 drm_modeset_unlock(&possible_crtc
->mutex
);
10459 crtc
= possible_crtc
;
10464 * If we didn't find an unused CRTC, don't use any.
10467 DRM_DEBUG_KMS("no pipe available for load-detect\n");
10472 intel_crtc
= to_intel_crtc(crtc
);
10474 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
10478 state
= drm_atomic_state_alloc(dev
);
10479 restore_state
= drm_atomic_state_alloc(dev
);
10480 if (!state
|| !restore_state
) {
10485 state
->acquire_ctx
= ctx
;
10486 restore_state
->acquire_ctx
= ctx
;
10488 connector_state
= drm_atomic_get_connector_state(state
, connector
);
10489 if (IS_ERR(connector_state
)) {
10490 ret
= PTR_ERR(connector_state
);
10494 ret
= drm_atomic_set_crtc_for_connector(connector_state
, crtc
);
10498 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
10499 if (IS_ERR(crtc_state
)) {
10500 ret
= PTR_ERR(crtc_state
);
10504 crtc_state
->base
.active
= crtc_state
->base
.enable
= true;
10507 mode
= &load_detect_mode
;
10509 /* We need a framebuffer large enough to accommodate all accesses
10510 * that the plane may generate whilst we perform load detection.
10511 * We can not rely on the fbcon either being present (we get called
10512 * during its initialisation to detect all boot displays, or it may
10513 * not even exist) or that it is large enough to satisfy the
10516 fb
= mode_fits_in_fbdev(dev
, mode
);
10518 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
10519 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
10521 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
10523 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
10527 ret
= intel_modeset_setup_plane_state(state
, crtc
, mode
, fb
, 0, 0);
10531 drm_framebuffer_unreference(fb
);
10533 ret
= drm_atomic_set_mode_for_crtc(&crtc_state
->base
, mode
);
10537 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state
, connector
));
10539 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state
, crtc
));
10541 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state
, crtc
->primary
));
10543 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret
);
10547 ret
= drm_atomic_commit(state
);
10549 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
10553 old
->restore_state
= restore_state
;
10555 /* let the connector get through one full cycle before testing */
10556 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
10560 drm_atomic_state_free(state
);
10561 drm_atomic_state_free(restore_state
);
10562 restore_state
= state
= NULL
;
10564 if (ret
== -EDEADLK
) {
10565 drm_modeset_backoff(ctx
);
10572 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
10573 struct intel_load_detect_pipe
*old
,
10574 struct drm_modeset_acquire_ctx
*ctx
)
10576 struct intel_encoder
*intel_encoder
=
10577 intel_attached_encoder(connector
);
10578 struct drm_encoder
*encoder
= &intel_encoder
->base
;
10579 struct drm_atomic_state
*state
= old
->restore_state
;
10582 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10583 connector
->base
.id
, connector
->name
,
10584 encoder
->base
.id
, encoder
->name
);
10589 ret
= drm_atomic_commit(state
);
10591 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret
);
10592 drm_atomic_state_free(state
);
10596 static int i9xx_pll_refclk(struct drm_device
*dev
,
10597 const struct intel_crtc_state
*pipe_config
)
10599 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10600 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
10602 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
10603 return dev_priv
->vbt
.lvds_ssc_freq
;
10604 else if (HAS_PCH_SPLIT(dev
))
10606 else if (!IS_GEN2(dev
))
10612 /* Returns the clock of the currently programmed mode of the given pipe. */
10613 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
10614 struct intel_crtc_state
*pipe_config
)
10616 struct drm_device
*dev
= crtc
->base
.dev
;
10617 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10618 int pipe
= pipe_config
->cpu_transcoder
;
10619 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
10623 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
10625 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
10626 fp
= pipe_config
->dpll_hw_state
.fp0
;
10628 fp
= pipe_config
->dpll_hw_state
.fp1
;
10630 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
10631 if (IS_PINEVIEW(dev
)) {
10632 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
10633 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
10635 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
10636 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
10639 if (!IS_GEN2(dev
)) {
10640 if (IS_PINEVIEW(dev
))
10641 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
10642 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
10644 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
10645 DPLL_FPA01_P1_POST_DIV_SHIFT
);
10647 switch (dpll
& DPLL_MODE_MASK
) {
10648 case DPLLB_MODE_DAC_SERIAL
:
10649 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
10652 case DPLLB_MODE_LVDS
:
10653 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
10657 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10658 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
10662 if (IS_PINEVIEW(dev
))
10663 port_clock
= pnv_calc_dpll_params(refclk
, &clock
);
10665 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
10667 u32 lvds
= IS_I830(dev
) ? 0 : I915_READ(LVDS
);
10668 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
10671 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
10672 DPLL_FPA01_P1_POST_DIV_SHIFT
);
10674 if (lvds
& LVDS_CLKB_POWER_UP
)
10679 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
10682 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
10683 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
10685 if (dpll
& PLL_P2_DIVIDE_BY_4
)
10691 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
10695 * This value includes pixel_multiplier. We will use
10696 * port_clock to compute adjusted_mode.crtc_clock in the
10697 * encoder's get_config() function.
10699 pipe_config
->port_clock
= port_clock
;
10702 int intel_dotclock_calculate(int link_freq
,
10703 const struct intel_link_m_n
*m_n
)
10706 * The calculation for the data clock is:
10707 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10708 * But we want to avoid losing precison if possible, so:
10709 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10711 * and the link clock is simpler:
10712 * link_clock = (m * link_clock) / n
10718 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
10721 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
10722 struct intel_crtc_state
*pipe_config
)
10724 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
10726 /* read out port_clock from the DPLL */
10727 i9xx_crtc_clock_get(crtc
, pipe_config
);
10730 * In case there is an active pipe without active ports,
10731 * we may need some idea for the dotclock anyway.
10732 * Calculate one based on the FDI configuration.
10734 pipe_config
->base
.adjusted_mode
.crtc_clock
=
10735 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
10736 &pipe_config
->fdi_m_n
);
10739 /** Returns the currently programmed mode of the given pipe. */
10740 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
10741 struct drm_crtc
*crtc
)
10743 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10744 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10745 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
10746 struct drm_display_mode
*mode
;
10747 struct intel_crtc_state
*pipe_config
;
10748 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
10749 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
10750 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
10751 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
10752 enum pipe pipe
= intel_crtc
->pipe
;
10754 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
10758 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
10759 if (!pipe_config
) {
10765 * Construct a pipe_config sufficient for getting the clock info
10766 * back out of crtc_clock_get.
10768 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
10769 * to use a real value here instead.
10771 pipe_config
->cpu_transcoder
= (enum transcoder
) pipe
;
10772 pipe_config
->pixel_multiplier
= 1;
10773 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
10774 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
10775 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
10776 i9xx_crtc_clock_get(intel_crtc
, pipe_config
);
10778 mode
->clock
= pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
10779 mode
->hdisplay
= (htot
& 0xffff) + 1;
10780 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
10781 mode
->hsync_start
= (hsync
& 0xffff) + 1;
10782 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
10783 mode
->vdisplay
= (vtot
& 0xffff) + 1;
10784 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
10785 mode
->vsync_start
= (vsync
& 0xffff) + 1;
10786 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
10788 drm_mode_set_name(mode
);
10790 kfree(pipe_config
);
10795 void intel_mark_busy(struct drm_i915_private
*dev_priv
)
10797 if (dev_priv
->mm
.busy
)
10800 intel_runtime_pm_get(dev_priv
);
10801 i915_update_gfx_val(dev_priv
);
10802 if (INTEL_GEN(dev_priv
) >= 6)
10803 gen6_rps_busy(dev_priv
);
10804 dev_priv
->mm
.busy
= true;
10807 void intel_mark_idle(struct drm_i915_private
*dev_priv
)
10809 if (!dev_priv
->mm
.busy
)
10812 dev_priv
->mm
.busy
= false;
10814 if (INTEL_GEN(dev_priv
) >= 6)
10815 gen6_rps_idle(dev_priv
);
10817 intel_runtime_pm_put(dev_priv
);
10820 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
10822 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10823 struct drm_device
*dev
= crtc
->dev
;
10824 struct intel_unpin_work
*work
;
10826 spin_lock_irq(&dev
->event_lock
);
10827 work
= intel_crtc
->unpin_work
;
10828 intel_crtc
->unpin_work
= NULL
;
10829 spin_unlock_irq(&dev
->event_lock
);
10832 cancel_work_sync(&work
->work
);
10836 drm_crtc_cleanup(crtc
);
10841 static void intel_unpin_work_fn(struct work_struct
*__work
)
10843 struct intel_unpin_work
*work
=
10844 container_of(__work
, struct intel_unpin_work
, work
);
10845 struct intel_crtc
*crtc
= to_intel_crtc(work
->crtc
);
10846 struct drm_device
*dev
= crtc
->base
.dev
;
10847 struct drm_plane
*primary
= crtc
->base
.primary
;
10849 mutex_lock(&dev
->struct_mutex
);
10850 intel_unpin_fb_obj(work
->old_fb
, primary
->state
->rotation
);
10851 drm_gem_object_unreference(&work
->pending_flip_obj
->base
);
10853 if (work
->flip_queued_req
)
10854 i915_gem_request_assign(&work
->flip_queued_req
, NULL
);
10855 mutex_unlock(&dev
->struct_mutex
);
10857 intel_frontbuffer_flip_complete(dev
, to_intel_plane(primary
)->frontbuffer_bit
);
10858 intel_fbc_post_update(crtc
);
10859 drm_framebuffer_unreference(work
->old_fb
);
10861 BUG_ON(atomic_read(&crtc
->unpin_work_count
) == 0);
10862 atomic_dec(&crtc
->unpin_work_count
);
10867 /* Is 'a' after or equal to 'b'? */
10868 static bool g4x_flip_count_after_eq(u32 a
, u32 b
)
10870 return !((a
- b
) & 0x80000000);
10873 static bool page_flip_finished(struct intel_crtc
*crtc
)
10875 struct drm_device
*dev
= crtc
->base
.dev
;
10876 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10877 unsigned reset_counter
;
10879 /* ensure that the unpin work is consistent wrt ->pending. */
10882 reset_counter
= i915_reset_counter(&dev_priv
->gpu_error
);
10883 if (crtc
->reset_counter
!= reset_counter
)
10887 * The relevant registers doen't exist on pre-ctg.
10888 * As the flip done interrupt doesn't trigger for mmio
10889 * flips on gmch platforms, a flip count check isn't
10890 * really needed there. But since ctg has the registers,
10891 * include it in the check anyway.
10893 if (INTEL_INFO(dev
)->gen
< 5 && !IS_G4X(dev
))
10897 * BDW signals flip done immediately if the plane
10898 * is disabled, even if the plane enable is already
10899 * armed to occur at the next vblank :(
10903 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
10904 * used the same base address. In that case the mmio flip might
10905 * have completed, but the CS hasn't even executed the flip yet.
10907 * A flip count check isn't enough as the CS might have updated
10908 * the base address just after start of vblank, but before we
10909 * managed to process the interrupt. This means we'd complete the
10910 * CS flip too soon.
10912 * Combining both checks should get us a good enough result. It may
10913 * still happen that the CS flip has been executed, but has not
10914 * yet actually completed. But in case the base address is the same
10915 * anyway, we don't really care.
10917 return (I915_READ(DSPSURFLIVE(crtc
->plane
)) & ~0xfff) ==
10918 crtc
->unpin_work
->gtt_offset
&&
10919 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc
->pipe
)),
10920 crtc
->unpin_work
->flip_count
);
10923 void intel_finish_page_flip(struct drm_i915_private
*dev_priv
, int pipe
)
10925 struct drm_device
*dev
= dev_priv
->dev
;
10926 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
10927 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10928 struct intel_unpin_work
*work
;
10929 unsigned long flags
;
10931 /* Ignore early vblank irqs */
10936 * This is called both by irq handlers and the reset code (to complete
10937 * lost pageflips) so needs the full irqsave spinlocks.
10939 spin_lock_irqsave(&dev
->event_lock
, flags
);
10940 work
= intel_crtc
->unpin_work
;
10942 if (work
!= NULL
&&
10943 atomic_read(&work
->pending
) &&
10944 page_flip_finished(intel_crtc
))
10945 page_flip_completed(intel_crtc
);
10947 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
10950 static inline void intel_mark_page_flip_active(struct intel_unpin_work
*work
)
10952 /* Ensure that the work item is consistent when activating it ... */
10953 smp_mb__before_atomic();
10954 atomic_set(&work
->pending
, 1);
10957 static int intel_gen2_queue_flip(struct drm_device
*dev
,
10958 struct drm_crtc
*crtc
,
10959 struct drm_framebuffer
*fb
,
10960 struct drm_i915_gem_object
*obj
,
10961 struct drm_i915_gem_request
*req
,
10964 struct intel_engine_cs
*engine
= req
->engine
;
10965 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10969 ret
= intel_ring_begin(req
, 6);
10973 /* Can't queue multiple flips, so wait for the previous
10974 * one to finish before executing the next.
10976 if (intel_crtc
->plane
)
10977 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
10979 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
10980 intel_ring_emit(engine
, MI_WAIT_FOR_EVENT
| flip_mask
);
10981 intel_ring_emit(engine
, MI_NOOP
);
10982 intel_ring_emit(engine
, MI_DISPLAY_FLIP
|
10983 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
10984 intel_ring_emit(engine
, fb
->pitches
[0]);
10985 intel_ring_emit(engine
, intel_crtc
->unpin_work
->gtt_offset
);
10986 intel_ring_emit(engine
, 0); /* aux display base address, unused */
10991 static int intel_gen3_queue_flip(struct drm_device
*dev
,
10992 struct drm_crtc
*crtc
,
10993 struct drm_framebuffer
*fb
,
10994 struct drm_i915_gem_object
*obj
,
10995 struct drm_i915_gem_request
*req
,
10998 struct intel_engine_cs
*engine
= req
->engine
;
10999 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11003 ret
= intel_ring_begin(req
, 6);
11007 if (intel_crtc
->plane
)
11008 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
11010 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
11011 intel_ring_emit(engine
, MI_WAIT_FOR_EVENT
| flip_mask
);
11012 intel_ring_emit(engine
, MI_NOOP
);
11013 intel_ring_emit(engine
, MI_DISPLAY_FLIP_I915
|
11014 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
11015 intel_ring_emit(engine
, fb
->pitches
[0]);
11016 intel_ring_emit(engine
, intel_crtc
->unpin_work
->gtt_offset
);
11017 intel_ring_emit(engine
, MI_NOOP
);
11022 static int intel_gen4_queue_flip(struct drm_device
*dev
,
11023 struct drm_crtc
*crtc
,
11024 struct drm_framebuffer
*fb
,
11025 struct drm_i915_gem_object
*obj
,
11026 struct drm_i915_gem_request
*req
,
11029 struct intel_engine_cs
*engine
= req
->engine
;
11030 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11031 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11032 uint32_t pf
, pipesrc
;
11035 ret
= intel_ring_begin(req
, 4);
11039 /* i965+ uses the linear or tiled offsets from the
11040 * Display Registers (which do not change across a page-flip)
11041 * so we need only reprogram the base address.
11043 intel_ring_emit(engine
, MI_DISPLAY_FLIP
|
11044 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
11045 intel_ring_emit(engine
, fb
->pitches
[0]);
11046 intel_ring_emit(engine
, intel_crtc
->unpin_work
->gtt_offset
|
11049 /* XXX Enabling the panel-fitter across page-flip is so far
11050 * untested on non-native modes, so ignore it for now.
11051 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
11054 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
11055 intel_ring_emit(engine
, pf
| pipesrc
);
11060 static int intel_gen6_queue_flip(struct drm_device
*dev
,
11061 struct drm_crtc
*crtc
,
11062 struct drm_framebuffer
*fb
,
11063 struct drm_i915_gem_object
*obj
,
11064 struct drm_i915_gem_request
*req
,
11067 struct intel_engine_cs
*engine
= req
->engine
;
11068 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11069 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11070 uint32_t pf
, pipesrc
;
11073 ret
= intel_ring_begin(req
, 4);
11077 intel_ring_emit(engine
, MI_DISPLAY_FLIP
|
11078 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
11079 intel_ring_emit(engine
, fb
->pitches
[0] | obj
->tiling_mode
);
11080 intel_ring_emit(engine
, intel_crtc
->unpin_work
->gtt_offset
);
11082 /* Contrary to the suggestions in the documentation,
11083 * "Enable Panel Fitter" does not seem to be required when page
11084 * flipping with a non-native mode, and worse causes a normal
11086 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
11089 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
11090 intel_ring_emit(engine
, pf
| pipesrc
);
11095 static int intel_gen7_queue_flip(struct drm_device
*dev
,
11096 struct drm_crtc
*crtc
,
11097 struct drm_framebuffer
*fb
,
11098 struct drm_i915_gem_object
*obj
,
11099 struct drm_i915_gem_request
*req
,
11102 struct intel_engine_cs
*engine
= req
->engine
;
11103 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11104 uint32_t plane_bit
= 0;
11107 switch (intel_crtc
->plane
) {
11109 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
11112 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
11115 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
11118 WARN_ONCE(1, "unknown plane in flip command\n");
11123 if (engine
->id
== RCS
) {
11126 * On Gen 8, SRM is now taking an extra dword to accommodate
11127 * 48bits addresses, and we need a NOOP for the batch size to
11135 * BSpec MI_DISPLAY_FLIP for IVB:
11136 * "The full packet must be contained within the same cache line."
11138 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
11139 * cacheline, if we ever start emitting more commands before
11140 * the MI_DISPLAY_FLIP we may need to first emit everything else,
11141 * then do the cacheline alignment, and finally emit the
11144 ret
= intel_ring_cacheline_align(req
);
11148 ret
= intel_ring_begin(req
, len
);
11152 /* Unmask the flip-done completion message. Note that the bspec says that
11153 * we should do this for both the BCS and RCS, and that we must not unmask
11154 * more than one flip event at any time (or ensure that one flip message
11155 * can be sent by waiting for flip-done prior to queueing new flips).
11156 * Experimentation says that BCS works despite DERRMR masking all
11157 * flip-done completion events and that unmasking all planes at once
11158 * for the RCS also doesn't appear to drop events. Setting the DERRMR
11159 * to zero does lead to lockups within MI_DISPLAY_FLIP.
11161 if (engine
->id
== RCS
) {
11162 intel_ring_emit(engine
, MI_LOAD_REGISTER_IMM(1));
11163 intel_ring_emit_reg(engine
, DERRMR
);
11164 intel_ring_emit(engine
, ~(DERRMR_PIPEA_PRI_FLIP_DONE
|
11165 DERRMR_PIPEB_PRI_FLIP_DONE
|
11166 DERRMR_PIPEC_PRI_FLIP_DONE
));
11168 intel_ring_emit(engine
, MI_STORE_REGISTER_MEM_GEN8
|
11169 MI_SRM_LRM_GLOBAL_GTT
);
11171 intel_ring_emit(engine
, MI_STORE_REGISTER_MEM
|
11172 MI_SRM_LRM_GLOBAL_GTT
);
11173 intel_ring_emit_reg(engine
, DERRMR
);
11174 intel_ring_emit(engine
, engine
->scratch
.gtt_offset
+ 256);
11175 if (IS_GEN8(dev
)) {
11176 intel_ring_emit(engine
, 0);
11177 intel_ring_emit(engine
, MI_NOOP
);
11181 intel_ring_emit(engine
, MI_DISPLAY_FLIP_I915
| plane_bit
);
11182 intel_ring_emit(engine
, (fb
->pitches
[0] | obj
->tiling_mode
));
11183 intel_ring_emit(engine
, intel_crtc
->unpin_work
->gtt_offset
);
11184 intel_ring_emit(engine
, (MI_NOOP
));
11189 static bool use_mmio_flip(struct intel_engine_cs
*engine
,
11190 struct drm_i915_gem_object
*obj
)
11193 * This is not being used for older platforms, because
11194 * non-availability of flip done interrupt forces us to use
11195 * CS flips. Older platforms derive flip done using some clever
11196 * tricks involving the flip_pending status bits and vblank irqs.
11197 * So using MMIO flips there would disrupt this mechanism.
11200 if (engine
== NULL
)
11203 if (INTEL_GEN(engine
->i915
) < 5)
11206 if (i915
.use_mmio_flip
< 0)
11208 else if (i915
.use_mmio_flip
> 0)
11210 else if (i915
.enable_execlists
)
11212 else if (obj
->base
.dma_buf
&&
11213 !reservation_object_test_signaled_rcu(obj
->base
.dma_buf
->resv
,
11217 return engine
!= i915_gem_request_get_engine(obj
->last_write_req
);
11220 static void skl_do_mmio_flip(struct intel_crtc
*intel_crtc
,
11221 unsigned int rotation
,
11222 struct intel_unpin_work
*work
)
11224 struct drm_device
*dev
= intel_crtc
->base
.dev
;
11225 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11226 struct drm_framebuffer
*fb
= intel_crtc
->base
.primary
->fb
;
11227 const enum pipe pipe
= intel_crtc
->pipe
;
11228 u32 ctl
, stride
, tile_height
;
11230 ctl
= I915_READ(PLANE_CTL(pipe
, 0));
11231 ctl
&= ~PLANE_CTL_TILED_MASK
;
11232 switch (fb
->modifier
[0]) {
11233 case DRM_FORMAT_MOD_NONE
:
11235 case I915_FORMAT_MOD_X_TILED
:
11236 ctl
|= PLANE_CTL_TILED_X
;
11238 case I915_FORMAT_MOD_Y_TILED
:
11239 ctl
|= PLANE_CTL_TILED_Y
;
11241 case I915_FORMAT_MOD_Yf_TILED
:
11242 ctl
|= PLANE_CTL_TILED_YF
;
11245 MISSING_CASE(fb
->modifier
[0]);
11249 * The stride is either expressed as a multiple of 64 bytes chunks for
11250 * linear buffers or in number of tiles for tiled buffers.
11252 if (intel_rotation_90_or_270(rotation
)) {
11253 /* stride = Surface height in tiles */
11254 tile_height
= intel_tile_height(dev_priv
, fb
->modifier
[0], 0);
11255 stride
= DIV_ROUND_UP(fb
->height
, tile_height
);
11257 stride
= fb
->pitches
[0] /
11258 intel_fb_stride_alignment(dev_priv
, fb
->modifier
[0],
11263 * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on
11264 * PLANE_SURF updates, the update is then guaranteed to be atomic.
11266 I915_WRITE(PLANE_CTL(pipe
, 0), ctl
);
11267 I915_WRITE(PLANE_STRIDE(pipe
, 0), stride
);
11269 I915_WRITE(PLANE_SURF(pipe
, 0), work
->gtt_offset
);
11270 POSTING_READ(PLANE_SURF(pipe
, 0));
11273 static void ilk_do_mmio_flip(struct intel_crtc
*intel_crtc
,
11274 struct intel_unpin_work
*work
)
11276 struct drm_device
*dev
= intel_crtc
->base
.dev
;
11277 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11278 struct intel_framebuffer
*intel_fb
=
11279 to_intel_framebuffer(intel_crtc
->base
.primary
->fb
);
11280 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
11281 i915_reg_t reg
= DSPCNTR(intel_crtc
->plane
);
11284 dspcntr
= I915_READ(reg
);
11286 if (obj
->tiling_mode
!= I915_TILING_NONE
)
11287 dspcntr
|= DISPPLANE_TILED
;
11289 dspcntr
&= ~DISPPLANE_TILED
;
11291 I915_WRITE(reg
, dspcntr
);
11293 I915_WRITE(DSPSURF(intel_crtc
->plane
), work
->gtt_offset
);
11294 POSTING_READ(DSPSURF(intel_crtc
->plane
));
11298 * XXX: This is the temporary way to update the plane registers until we get
11299 * around to using the usual plane update functions for MMIO flips
11301 static void intel_do_mmio_flip(struct intel_mmio_flip
*mmio_flip
)
11303 struct intel_crtc
*crtc
= mmio_flip
->crtc
;
11304 struct intel_unpin_work
*work
;
11306 spin_lock_irq(&crtc
->base
.dev
->event_lock
);
11307 work
= crtc
->unpin_work
;
11308 spin_unlock_irq(&crtc
->base
.dev
->event_lock
);
11312 intel_pipe_update_start(crtc
);
11314 if (INTEL_INFO(mmio_flip
->i915
)->gen
>= 9)
11315 skl_do_mmio_flip(crtc
, mmio_flip
->rotation
, work
);
11317 /* use_mmio_flip() retricts MMIO flips to ilk+ */
11318 ilk_do_mmio_flip(crtc
, work
);
11320 intel_pipe_update_end(crtc
);
11322 intel_mark_page_flip_active(work
);
11325 static void intel_mmio_flip_work_func(struct work_struct
*work
)
11327 struct intel_mmio_flip
*mmio_flip
=
11328 container_of(work
, struct intel_mmio_flip
, work
);
11329 struct intel_framebuffer
*intel_fb
=
11330 to_intel_framebuffer(mmio_flip
->crtc
->base
.primary
->fb
);
11331 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
11333 if (mmio_flip
->req
) {
11334 WARN_ON(__i915_wait_request(mmio_flip
->req
,
11336 &mmio_flip
->i915
->rps
.mmioflips
));
11337 i915_gem_request_unreference(mmio_flip
->req
);
11340 /* For framebuffer backed by dmabuf, wait for fence */
11341 if (obj
->base
.dma_buf
)
11342 WARN_ON(reservation_object_wait_timeout_rcu(obj
->base
.dma_buf
->resv
,
11344 MAX_SCHEDULE_TIMEOUT
) < 0);
11346 intel_do_mmio_flip(mmio_flip
);
11350 static int intel_queue_mmio_flip(struct drm_device
*dev
,
11351 struct drm_crtc
*crtc
,
11352 struct drm_i915_gem_object
*obj
)
11354 struct intel_mmio_flip
*mmio_flip
;
11356 mmio_flip
= kmalloc(sizeof(*mmio_flip
), GFP_KERNEL
);
11357 if (mmio_flip
== NULL
)
11360 mmio_flip
->i915
= to_i915(dev
);
11361 mmio_flip
->req
= i915_gem_request_reference(obj
->last_write_req
);
11362 mmio_flip
->crtc
= to_intel_crtc(crtc
);
11363 mmio_flip
->rotation
= crtc
->primary
->state
->rotation
;
11365 INIT_WORK(&mmio_flip
->work
, intel_mmio_flip_work_func
);
11366 schedule_work(&mmio_flip
->work
);
11371 static int intel_default_queue_flip(struct drm_device
*dev
,
11372 struct drm_crtc
*crtc
,
11373 struct drm_framebuffer
*fb
,
11374 struct drm_i915_gem_object
*obj
,
11375 struct drm_i915_gem_request
*req
,
11381 static bool __intel_pageflip_stall_check(struct drm_device
*dev
,
11382 struct drm_crtc
*crtc
)
11384 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11385 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11386 struct intel_unpin_work
*work
= intel_crtc
->unpin_work
;
11390 pending
= atomic_read(&work
->pending
);
11391 /* ensure that the unpin work is consistent wrt ->pending. */
11397 if (work
->flip_ready_vblank
== 0) {
11398 if (work
->flip_queued_req
&&
11399 !i915_gem_request_completed(work
->flip_queued_req
, true))
11402 work
->flip_ready_vblank
= drm_crtc_vblank_count(crtc
);
11405 if (drm_crtc_vblank_count(crtc
) - work
->flip_ready_vblank
< 3)
11408 /* Potential stall - if we see that the flip has happened,
11409 * assume a missed interrupt. */
11410 if (INTEL_INFO(dev
)->gen
>= 4)
11411 addr
= I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc
->plane
)));
11413 addr
= I915_READ(DSPADDR(intel_crtc
->plane
));
11415 /* There is a potential issue here with a false positive after a flip
11416 * to the same address. We could address this by checking for a
11417 * non-incrementing frame counter.
11419 return addr
== work
->gtt_offset
;
11422 void intel_check_page_flip(struct drm_i915_private
*dev_priv
, int pipe
)
11424 struct drm_device
*dev
= dev_priv
->dev
;
11425 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
11426 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11427 struct intel_unpin_work
*work
;
11429 WARN_ON(!in_interrupt());
11434 spin_lock(&dev
->event_lock
);
11435 work
= intel_crtc
->unpin_work
;
11436 if (work
!= NULL
&& __intel_pageflip_stall_check(dev
, crtc
)) {
11437 WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n",
11438 work
->flip_queued_vblank
, drm_vblank_count(dev
, pipe
));
11439 page_flip_completed(intel_crtc
);
11442 if (work
!= NULL
&&
11443 drm_vblank_count(dev
, pipe
) - work
->flip_queued_vblank
> 1)
11444 intel_queue_rps_boost_for_request(work
->flip_queued_req
);
11445 spin_unlock(&dev
->event_lock
);
11448 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
11449 struct drm_framebuffer
*fb
,
11450 struct drm_pending_vblank_event
*event
,
11451 uint32_t page_flip_flags
)
11453 struct drm_device
*dev
= crtc
->dev
;
11454 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11455 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
11456 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
11457 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11458 struct drm_plane
*primary
= crtc
->primary
;
11459 enum pipe pipe
= intel_crtc
->pipe
;
11460 struct intel_unpin_work
*work
;
11461 struct intel_engine_cs
*engine
;
11463 struct drm_i915_gem_request
*request
= NULL
;
11467 * drm_mode_page_flip_ioctl() should already catch this, but double
11468 * check to be safe. In the future we may enable pageflipping from
11469 * a disabled primary plane.
11471 if (WARN_ON(intel_fb_obj(old_fb
) == NULL
))
11474 /* Can't change pixel format via MI display flips. */
11475 if (fb
->pixel_format
!= crtc
->primary
->fb
->pixel_format
)
11479 * TILEOFF/LINOFF registers can't be changed via MI display flips.
11480 * Note that pitch changes could also affect these register.
11482 if (INTEL_INFO(dev
)->gen
> 3 &&
11483 (fb
->offsets
[0] != crtc
->primary
->fb
->offsets
[0] ||
11484 fb
->pitches
[0] != crtc
->primary
->fb
->pitches
[0]))
11487 if (i915_terminally_wedged(&dev_priv
->gpu_error
))
11490 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
11494 work
->event
= event
;
11496 work
->old_fb
= old_fb
;
11497 INIT_WORK(&work
->work
, intel_unpin_work_fn
);
11499 ret
= drm_crtc_vblank_get(crtc
);
11503 /* We borrow the event spin lock for protecting unpin_work */
11504 spin_lock_irq(&dev
->event_lock
);
11505 if (intel_crtc
->unpin_work
) {
11506 /* Before declaring the flip queue wedged, check if
11507 * the hardware completed the operation behind our backs.
11509 if (__intel_pageflip_stall_check(dev
, crtc
)) {
11510 DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
11511 page_flip_completed(intel_crtc
);
11513 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
11514 spin_unlock_irq(&dev
->event_lock
);
11516 drm_crtc_vblank_put(crtc
);
11521 intel_crtc
->unpin_work
= work
;
11522 spin_unlock_irq(&dev
->event_lock
);
11524 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
11525 flush_workqueue(dev_priv
->wq
);
11527 /* Reference the objects for the scheduled work. */
11528 drm_framebuffer_reference(work
->old_fb
);
11529 drm_gem_object_reference(&obj
->base
);
11531 crtc
->primary
->fb
= fb
;
11532 update_state_fb(crtc
->primary
);
11533 intel_fbc_pre_update(intel_crtc
);
11535 work
->pending_flip_obj
= obj
;
11537 ret
= i915_mutex_lock_interruptible(dev
);
11541 intel_crtc
->reset_counter
= i915_reset_counter(&dev_priv
->gpu_error
);
11542 if (__i915_reset_in_progress_or_wedged(intel_crtc
->reset_counter
)) {
11547 atomic_inc(&intel_crtc
->unpin_work_count
);
11549 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
11550 work
->flip_count
= I915_READ(PIPE_FLIPCOUNT_G4X(pipe
)) + 1;
11552 if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
11553 engine
= &dev_priv
->engine
[BCS
];
11554 if (obj
->tiling_mode
!= intel_fb_obj(work
->old_fb
)->tiling_mode
)
11555 /* vlv: DISPLAY_FLIP fails to change tiling */
11557 } else if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
)) {
11558 engine
= &dev_priv
->engine
[BCS
];
11559 } else if (INTEL_INFO(dev
)->gen
>= 7) {
11560 engine
= i915_gem_request_get_engine(obj
->last_write_req
);
11561 if (engine
== NULL
|| engine
->id
!= RCS
)
11562 engine
= &dev_priv
->engine
[BCS
];
11564 engine
= &dev_priv
->engine
[RCS
];
11567 mmio_flip
= use_mmio_flip(engine
, obj
);
11569 /* When using CS flips, we want to emit semaphores between rings.
11570 * However, when using mmio flips we will create a task to do the
11571 * synchronisation, so all we want here is to pin the framebuffer
11572 * into the display plane and skip any waits.
11575 ret
= i915_gem_object_sync(obj
, engine
, &request
);
11576 if (!ret
&& !request
) {
11577 request
= i915_gem_request_alloc(engine
, NULL
);
11578 ret
= PTR_ERR_OR_ZERO(request
);
11582 goto cleanup_pending
;
11585 ret
= intel_pin_and_fence_fb_obj(fb
, primary
->state
->rotation
);
11587 goto cleanup_pending
;
11589 work
->gtt_offset
= intel_plane_obj_offset(to_intel_plane(primary
),
11591 work
->gtt_offset
+= intel_crtc
->dspaddr_offset
;
11594 work
->flip_queued_vblank
= drm_crtc_vblank_count(crtc
);
11596 i915_gem_request_assign(&work
->flip_queued_req
,
11597 obj
->last_write_req
);
11599 ret
= intel_queue_mmio_flip(dev
, crtc
, obj
);
11601 goto cleanup_unpin
;
11603 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
, request
,
11606 goto cleanup_unpin
;
11608 i915_gem_request_assign(&work
->flip_queued_req
, request
);
11610 work
->flip_queued_vblank
= drm_crtc_vblank_count(crtc
);
11611 intel_mark_page_flip_active(work
);
11613 i915_add_request_no_flush(request
);
11616 i915_gem_track_fb(intel_fb_obj(old_fb
), obj
,
11617 to_intel_plane(primary
)->frontbuffer_bit
);
11618 mutex_unlock(&dev
->struct_mutex
);
11620 intel_frontbuffer_flip_prepare(dev
,
11621 to_intel_plane(primary
)->frontbuffer_bit
);
11623 trace_i915_flip_request(intel_crtc
->plane
, obj
);
11628 intel_unpin_fb_obj(fb
, crtc
->primary
->state
->rotation
);
11630 if (!IS_ERR_OR_NULL(request
))
11631 i915_add_request_no_flush(request
);
11632 atomic_dec(&intel_crtc
->unpin_work_count
);
11633 mutex_unlock(&dev
->struct_mutex
);
11635 crtc
->primary
->fb
= old_fb
;
11636 update_state_fb(crtc
->primary
);
11638 drm_gem_object_unreference_unlocked(&obj
->base
);
11639 drm_framebuffer_unreference(work
->old_fb
);
11641 spin_lock_irq(&dev
->event_lock
);
11642 intel_crtc
->unpin_work
= NULL
;
11643 spin_unlock_irq(&dev
->event_lock
);
11645 drm_crtc_vblank_put(crtc
);
11650 struct drm_atomic_state
*state
;
11651 struct drm_plane_state
*plane_state
;
11654 state
= drm_atomic_state_alloc(dev
);
11657 state
->acquire_ctx
= drm_modeset_legacy_acquire_ctx(crtc
);
11660 plane_state
= drm_atomic_get_plane_state(state
, primary
);
11661 ret
= PTR_ERR_OR_ZERO(plane_state
);
11663 drm_atomic_set_fb_for_plane(plane_state
, fb
);
11665 ret
= drm_atomic_set_crtc_for_plane(plane_state
, crtc
);
11667 ret
= drm_atomic_commit(state
);
11670 if (ret
== -EDEADLK
) {
11671 drm_modeset_backoff(state
->acquire_ctx
);
11672 drm_atomic_state_clear(state
);
11677 drm_atomic_state_free(state
);
11679 if (ret
== 0 && event
) {
11680 spin_lock_irq(&dev
->event_lock
);
11681 drm_crtc_send_vblank_event(crtc
, event
);
11682 spin_unlock_irq(&dev
->event_lock
);
11690 * intel_wm_need_update - Check whether watermarks need updating
11691 * @plane: drm plane
11692 * @state: new plane state
11694 * Check current plane state versus the new one to determine whether
11695 * watermarks need to be recalculated.
11697 * Returns true or false.
11699 static bool intel_wm_need_update(struct drm_plane
*plane
,
11700 struct drm_plane_state
*state
)
11702 struct intel_plane_state
*new = to_intel_plane_state(state
);
11703 struct intel_plane_state
*cur
= to_intel_plane_state(plane
->state
);
11705 /* Update watermarks on tiling or size changes. */
11706 if (new->visible
!= cur
->visible
)
11709 if (!cur
->base
.fb
|| !new->base
.fb
)
11712 if (cur
->base
.fb
->modifier
[0] != new->base
.fb
->modifier
[0] ||
11713 cur
->base
.rotation
!= new->base
.rotation
||
11714 drm_rect_width(&new->src
) != drm_rect_width(&cur
->src
) ||
11715 drm_rect_height(&new->src
) != drm_rect_height(&cur
->src
) ||
11716 drm_rect_width(&new->dst
) != drm_rect_width(&cur
->dst
) ||
11717 drm_rect_height(&new->dst
) != drm_rect_height(&cur
->dst
))
11723 static bool needs_scaling(struct intel_plane_state
*state
)
11725 int src_w
= drm_rect_width(&state
->src
) >> 16;
11726 int src_h
= drm_rect_height(&state
->src
) >> 16;
11727 int dst_w
= drm_rect_width(&state
->dst
);
11728 int dst_h
= drm_rect_height(&state
->dst
);
11730 return (src_w
!= dst_w
|| src_h
!= dst_h
);
11733 int intel_plane_atomic_calc_changes(struct drm_crtc_state
*crtc_state
,
11734 struct drm_plane_state
*plane_state
)
11736 struct intel_crtc_state
*pipe_config
= to_intel_crtc_state(crtc_state
);
11737 struct drm_crtc
*crtc
= crtc_state
->crtc
;
11738 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11739 struct drm_plane
*plane
= plane_state
->plane
;
11740 struct drm_device
*dev
= crtc
->dev
;
11741 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11742 struct intel_plane_state
*old_plane_state
=
11743 to_intel_plane_state(plane
->state
);
11744 int idx
= intel_crtc
->base
.base
.id
, ret
;
11745 bool mode_changed
= needs_modeset(crtc_state
);
11746 bool was_crtc_enabled
= crtc
->state
->active
;
11747 bool is_crtc_enabled
= crtc_state
->active
;
11748 bool turn_off
, turn_on
, visible
, was_visible
;
11749 struct drm_framebuffer
*fb
= plane_state
->fb
;
11751 if (crtc_state
&& INTEL_INFO(dev
)->gen
>= 9 &&
11752 plane
->type
!= DRM_PLANE_TYPE_CURSOR
) {
11753 ret
= skl_update_scaler_plane(
11754 to_intel_crtc_state(crtc_state
),
11755 to_intel_plane_state(plane_state
));
11760 was_visible
= old_plane_state
->visible
;
11761 visible
= to_intel_plane_state(plane_state
)->visible
;
11763 if (!was_crtc_enabled
&& WARN_ON(was_visible
))
11764 was_visible
= false;
11767 * Visibility is calculated as if the crtc was on, but
11768 * after scaler setup everything depends on it being off
11769 * when the crtc isn't active.
11771 * FIXME this is wrong for watermarks. Watermarks should also
11772 * be computed as if the pipe would be active. Perhaps move
11773 * per-plane wm computation to the .check_plane() hook, and
11774 * only combine the results from all planes in the current place?
11776 if (!is_crtc_enabled
)
11777 to_intel_plane_state(plane_state
)->visible
= visible
= false;
11779 if (!was_visible
&& !visible
)
11782 if (fb
!= old_plane_state
->base
.fb
)
11783 pipe_config
->fb_changed
= true;
11785 turn_off
= was_visible
&& (!visible
|| mode_changed
);
11786 turn_on
= visible
&& (!was_visible
|| mode_changed
);
11788 DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx
,
11789 plane
->base
.id
, fb
? fb
->base
.id
: -1);
11791 DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n",
11792 plane
->base
.id
, was_visible
, visible
,
11793 turn_off
, turn_on
, mode_changed
);
11796 pipe_config
->update_wm_pre
= true;
11798 /* must disable cxsr around plane enable/disable */
11799 if (plane
->type
!= DRM_PLANE_TYPE_CURSOR
)
11800 pipe_config
->disable_cxsr
= true;
11801 } else if (turn_off
) {
11802 pipe_config
->update_wm_post
= true;
11804 /* must disable cxsr around plane enable/disable */
11805 if (plane
->type
!= DRM_PLANE_TYPE_CURSOR
)
11806 pipe_config
->disable_cxsr
= true;
11807 } else if (intel_wm_need_update(plane
, plane_state
)) {
11808 /* FIXME bollocks */
11809 pipe_config
->update_wm_pre
= true;
11810 pipe_config
->update_wm_post
= true;
11813 /* Pre-gen9 platforms need two-step watermark updates */
11814 if ((pipe_config
->update_wm_pre
|| pipe_config
->update_wm_post
) &&
11815 INTEL_INFO(dev
)->gen
< 9 && dev_priv
->display
.optimize_watermarks
)
11816 to_intel_crtc_state(crtc_state
)->wm
.need_postvbl_update
= true;
11818 if (visible
|| was_visible
)
11819 pipe_config
->fb_bits
|= to_intel_plane(plane
)->frontbuffer_bit
;
11822 * WaCxSRDisabledForSpriteScaling:ivb
11824 * cstate->update_wm was already set above, so this flag will
11825 * take effect when we commit and program watermarks.
11827 if (plane
->type
== DRM_PLANE_TYPE_OVERLAY
&& IS_IVYBRIDGE(dev
) &&
11828 needs_scaling(to_intel_plane_state(plane_state
)) &&
11829 !needs_scaling(old_plane_state
))
11830 pipe_config
->disable_lp_wm
= true;
11835 static bool encoders_cloneable(const struct intel_encoder
*a
,
11836 const struct intel_encoder
*b
)
11838 /* masks could be asymmetric, so check both ways */
11839 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
11840 b
->cloneable
& (1 << a
->type
));
11843 static bool check_single_encoder_cloning(struct drm_atomic_state
*state
,
11844 struct intel_crtc
*crtc
,
11845 struct intel_encoder
*encoder
)
11847 struct intel_encoder
*source_encoder
;
11848 struct drm_connector
*connector
;
11849 struct drm_connector_state
*connector_state
;
11852 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11853 if (connector_state
->crtc
!= &crtc
->base
)
11857 to_intel_encoder(connector_state
->best_encoder
);
11858 if (!encoders_cloneable(encoder
, source_encoder
))
11865 static bool check_encoder_cloning(struct drm_atomic_state
*state
,
11866 struct intel_crtc
*crtc
)
11868 struct intel_encoder
*encoder
;
11869 struct drm_connector
*connector
;
11870 struct drm_connector_state
*connector_state
;
11873 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11874 if (connector_state
->crtc
!= &crtc
->base
)
11877 encoder
= to_intel_encoder(connector_state
->best_encoder
);
11878 if (!check_single_encoder_cloning(state
, crtc
, encoder
))
11885 static int intel_crtc_atomic_check(struct drm_crtc
*crtc
,
11886 struct drm_crtc_state
*crtc_state
)
11888 struct drm_device
*dev
= crtc
->dev
;
11889 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11890 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11891 struct intel_crtc_state
*pipe_config
=
11892 to_intel_crtc_state(crtc_state
);
11893 struct drm_atomic_state
*state
= crtc_state
->state
;
11895 bool mode_changed
= needs_modeset(crtc_state
);
11897 if (mode_changed
&& !check_encoder_cloning(state
, intel_crtc
)) {
11898 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
11902 if (mode_changed
&& !crtc_state
->active
)
11903 pipe_config
->update_wm_post
= true;
11905 if (mode_changed
&& crtc_state
->enable
&&
11906 dev_priv
->display
.crtc_compute_clock
&&
11907 !WARN_ON(pipe_config
->shared_dpll
)) {
11908 ret
= dev_priv
->display
.crtc_compute_clock(intel_crtc
,
11914 if (crtc_state
->color_mgmt_changed
) {
11915 ret
= intel_color_check(crtc
, crtc_state
);
11921 if (dev_priv
->display
.compute_pipe_wm
) {
11922 ret
= dev_priv
->display
.compute_pipe_wm(pipe_config
);
11924 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
11929 if (dev_priv
->display
.compute_intermediate_wm
&&
11930 !to_intel_atomic_state(state
)->skip_intermediate_wm
) {
11931 if (WARN_ON(!dev_priv
->display
.compute_pipe_wm
))
11935 * Calculate 'intermediate' watermarks that satisfy both the
11936 * old state and the new state. We can program these
11939 ret
= dev_priv
->display
.compute_intermediate_wm(crtc
->dev
,
11943 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
11946 } else if (dev_priv
->display
.compute_intermediate_wm
) {
11947 if (HAS_PCH_SPLIT(dev_priv
) && INTEL_GEN(dev_priv
) < 9)
11948 pipe_config
->wm
.ilk
.intermediate
= pipe_config
->wm
.ilk
.optimal
;
11951 if (INTEL_INFO(dev
)->gen
>= 9) {
11953 ret
= skl_update_scaler_crtc(pipe_config
);
11956 ret
= intel_atomic_setup_scalers(dev
, intel_crtc
,
11963 static const struct drm_crtc_helper_funcs intel_helper_funcs
= {
11964 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
11965 .atomic_begin
= intel_begin_crtc_commit
,
11966 .atomic_flush
= intel_finish_crtc_commit
,
11967 .atomic_check
= intel_crtc_atomic_check
,
11970 static void intel_modeset_update_connector_atomic_state(struct drm_device
*dev
)
11972 struct intel_connector
*connector
;
11974 for_each_intel_connector(dev
, connector
) {
11975 if (connector
->base
.state
->crtc
)
11976 drm_connector_unreference(&connector
->base
);
11978 if (connector
->base
.encoder
) {
11979 connector
->base
.state
->best_encoder
=
11980 connector
->base
.encoder
;
11981 connector
->base
.state
->crtc
=
11982 connector
->base
.encoder
->crtc
;
11984 drm_connector_reference(&connector
->base
);
11986 connector
->base
.state
->best_encoder
= NULL
;
11987 connector
->base
.state
->crtc
= NULL
;
11993 connected_sink_compute_bpp(struct intel_connector
*connector
,
11994 struct intel_crtc_state
*pipe_config
)
11996 int bpp
= pipe_config
->pipe_bpp
;
11998 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
11999 connector
->base
.base
.id
,
12000 connector
->base
.name
);
12002 /* Don't use an invalid EDID bpc value */
12003 if (connector
->base
.display_info
.bpc
&&
12004 connector
->base
.display_info
.bpc
* 3 < bpp
) {
12005 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
12006 bpp
, connector
->base
.display_info
.bpc
*3);
12007 pipe_config
->pipe_bpp
= connector
->base
.display_info
.bpc
*3;
12010 /* Clamp bpp to default limit on screens without EDID 1.4 */
12011 if (connector
->base
.display_info
.bpc
== 0) {
12012 int type
= connector
->base
.connector_type
;
12013 int clamp_bpp
= 24;
12015 /* Fall back to 18 bpp when DP sink capability is unknown. */
12016 if (type
== DRM_MODE_CONNECTOR_DisplayPort
||
12017 type
== DRM_MODE_CONNECTOR_eDP
)
12020 if (bpp
> clamp_bpp
) {
12021 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of %d\n",
12023 pipe_config
->pipe_bpp
= clamp_bpp
;
12029 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
12030 struct intel_crtc_state
*pipe_config
)
12032 struct drm_device
*dev
= crtc
->base
.dev
;
12033 struct drm_atomic_state
*state
;
12034 struct drm_connector
*connector
;
12035 struct drm_connector_state
*connector_state
;
12038 if ((IS_G4X(dev
) || IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)))
12040 else if (INTEL_INFO(dev
)->gen
>= 5)
12046 pipe_config
->pipe_bpp
= bpp
;
12048 state
= pipe_config
->base
.state
;
12050 /* Clamp display bpp to EDID value */
12051 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
12052 if (connector_state
->crtc
!= &crtc
->base
)
12055 connected_sink_compute_bpp(to_intel_connector(connector
),
12062 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
12064 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
12065 "type: 0x%x flags: 0x%x\n",
12067 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
12068 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
12069 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
12070 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
12073 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
12074 struct intel_crtc_state
*pipe_config
,
12075 const char *context
)
12077 struct drm_device
*dev
= crtc
->base
.dev
;
12078 struct drm_plane
*plane
;
12079 struct intel_plane
*intel_plane
;
12080 struct intel_plane_state
*state
;
12081 struct drm_framebuffer
*fb
;
12083 DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc
->base
.base
.id
,
12084 context
, pipe_config
, pipe_name(crtc
->pipe
));
12086 DRM_DEBUG_KMS("cpu_transcoder: %s\n", transcoder_name(pipe_config
->cpu_transcoder
));
12087 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
12088 pipe_config
->pipe_bpp
, pipe_config
->dither
);
12089 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
12090 pipe_config
->has_pch_encoder
,
12091 pipe_config
->fdi_lanes
,
12092 pipe_config
->fdi_m_n
.gmch_m
, pipe_config
->fdi_m_n
.gmch_n
,
12093 pipe_config
->fdi_m_n
.link_m
, pipe_config
->fdi_m_n
.link_n
,
12094 pipe_config
->fdi_m_n
.tu
);
12095 DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
12096 pipe_config
->has_dp_encoder
,
12097 pipe_config
->lane_count
,
12098 pipe_config
->dp_m_n
.gmch_m
, pipe_config
->dp_m_n
.gmch_n
,
12099 pipe_config
->dp_m_n
.link_m
, pipe_config
->dp_m_n
.link_n
,
12100 pipe_config
->dp_m_n
.tu
);
12102 DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
12103 pipe_config
->has_dp_encoder
,
12104 pipe_config
->lane_count
,
12105 pipe_config
->dp_m2_n2
.gmch_m
,
12106 pipe_config
->dp_m2_n2
.gmch_n
,
12107 pipe_config
->dp_m2_n2
.link_m
,
12108 pipe_config
->dp_m2_n2
.link_n
,
12109 pipe_config
->dp_m2_n2
.tu
);
12111 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
12112 pipe_config
->has_audio
,
12113 pipe_config
->has_infoframe
);
12115 DRM_DEBUG_KMS("requested mode:\n");
12116 drm_mode_debug_printmodeline(&pipe_config
->base
.mode
);
12117 DRM_DEBUG_KMS("adjusted mode:\n");
12118 drm_mode_debug_printmodeline(&pipe_config
->base
.adjusted_mode
);
12119 intel_dump_crtc_timings(&pipe_config
->base
.adjusted_mode
);
12120 DRM_DEBUG_KMS("port clock: %d\n", pipe_config
->port_clock
);
12121 DRM_DEBUG_KMS("pipe src size: %dx%d\n",
12122 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
12123 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
12125 pipe_config
->scaler_state
.scaler_users
,
12126 pipe_config
->scaler_state
.scaler_id
);
12127 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
12128 pipe_config
->gmch_pfit
.control
,
12129 pipe_config
->gmch_pfit
.pgm_ratios
,
12130 pipe_config
->gmch_pfit
.lvds_border_bits
);
12131 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
12132 pipe_config
->pch_pfit
.pos
,
12133 pipe_config
->pch_pfit
.size
,
12134 pipe_config
->pch_pfit
.enabled
? "enabled" : "disabled");
12135 DRM_DEBUG_KMS("ips: %i\n", pipe_config
->ips_enabled
);
12136 DRM_DEBUG_KMS("double wide: %i\n", pipe_config
->double_wide
);
12138 if (IS_BROXTON(dev
)) {
12139 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x,"
12140 "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, "
12141 "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n",
12142 pipe_config
->ddi_pll_sel
,
12143 pipe_config
->dpll_hw_state
.ebb0
,
12144 pipe_config
->dpll_hw_state
.ebb4
,
12145 pipe_config
->dpll_hw_state
.pll0
,
12146 pipe_config
->dpll_hw_state
.pll1
,
12147 pipe_config
->dpll_hw_state
.pll2
,
12148 pipe_config
->dpll_hw_state
.pll3
,
12149 pipe_config
->dpll_hw_state
.pll6
,
12150 pipe_config
->dpll_hw_state
.pll8
,
12151 pipe_config
->dpll_hw_state
.pll9
,
12152 pipe_config
->dpll_hw_state
.pll10
,
12153 pipe_config
->dpll_hw_state
.pcsdw12
);
12154 } else if (IS_SKYLAKE(dev
) || IS_KABYLAKE(dev
)) {
12155 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: "
12156 "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n",
12157 pipe_config
->ddi_pll_sel
,
12158 pipe_config
->dpll_hw_state
.ctrl1
,
12159 pipe_config
->dpll_hw_state
.cfgcr1
,
12160 pipe_config
->dpll_hw_state
.cfgcr2
);
12161 } else if (HAS_DDI(dev
)) {
12162 DRM_DEBUG_KMS("ddi_pll_sel: 0x%x; dpll_hw_state: wrpll: 0x%x spll: 0x%x\n",
12163 pipe_config
->ddi_pll_sel
,
12164 pipe_config
->dpll_hw_state
.wrpll
,
12165 pipe_config
->dpll_hw_state
.spll
);
12167 DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, "
12168 "fp0: 0x%x, fp1: 0x%x\n",
12169 pipe_config
->dpll_hw_state
.dpll
,
12170 pipe_config
->dpll_hw_state
.dpll_md
,
12171 pipe_config
->dpll_hw_state
.fp0
,
12172 pipe_config
->dpll_hw_state
.fp1
);
12175 DRM_DEBUG_KMS("planes on this crtc\n");
12176 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
12177 intel_plane
= to_intel_plane(plane
);
12178 if (intel_plane
->pipe
!= crtc
->pipe
)
12181 state
= to_intel_plane_state(plane
->state
);
12182 fb
= state
->base
.fb
;
12184 DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d "
12185 "disabled, scaler_id = %d\n",
12186 plane
->type
== DRM_PLANE_TYPE_CURSOR
? "CURSOR" : "STANDARD",
12187 plane
->base
.id
, intel_plane
->pipe
,
12188 (crtc
->base
.primary
== plane
) ? 0 : intel_plane
->plane
+ 1,
12189 drm_plane_index(plane
), state
->scaler_id
);
12193 DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled",
12194 plane
->type
== DRM_PLANE_TYPE_CURSOR
? "CURSOR" : "STANDARD",
12195 plane
->base
.id
, intel_plane
->pipe
,
12196 crtc
->base
.primary
== plane
? 0 : intel_plane
->plane
+ 1,
12197 drm_plane_index(plane
));
12198 DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x",
12199 fb
->base
.id
, fb
->width
, fb
->height
, fb
->pixel_format
);
12200 DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n",
12202 state
->src
.x1
>> 16, state
->src
.y1
>> 16,
12203 drm_rect_width(&state
->src
) >> 16,
12204 drm_rect_height(&state
->src
) >> 16,
12205 state
->dst
.x1
, state
->dst
.y1
,
12206 drm_rect_width(&state
->dst
), drm_rect_height(&state
->dst
));
12210 static bool check_digital_port_conflicts(struct drm_atomic_state
*state
)
12212 struct drm_device
*dev
= state
->dev
;
12213 struct drm_connector
*connector
;
12214 unsigned int used_ports
= 0;
12217 * Walk the connector list instead of the encoder
12218 * list to detect the problem on ddi platforms
12219 * where there's just one encoder per digital port.
12221 drm_for_each_connector(connector
, dev
) {
12222 struct drm_connector_state
*connector_state
;
12223 struct intel_encoder
*encoder
;
12225 connector_state
= drm_atomic_get_existing_connector_state(state
, connector
);
12226 if (!connector_state
)
12227 connector_state
= connector
->state
;
12229 if (!connector_state
->best_encoder
)
12232 encoder
= to_intel_encoder(connector_state
->best_encoder
);
12234 WARN_ON(!connector_state
->crtc
);
12236 switch (encoder
->type
) {
12237 unsigned int port_mask
;
12238 case INTEL_OUTPUT_UNKNOWN
:
12239 if (WARN_ON(!HAS_DDI(dev
)))
12241 case INTEL_OUTPUT_DISPLAYPORT
:
12242 case INTEL_OUTPUT_HDMI
:
12243 case INTEL_OUTPUT_EDP
:
12244 port_mask
= 1 << enc_to_dig_port(&encoder
->base
)->port
;
12246 /* the same port mustn't appear more than once */
12247 if (used_ports
& port_mask
)
12250 used_ports
|= port_mask
;
12260 clear_intel_crtc_state(struct intel_crtc_state
*crtc_state
)
12262 struct drm_crtc_state tmp_state
;
12263 struct intel_crtc_scaler_state scaler_state
;
12264 struct intel_dpll_hw_state dpll_hw_state
;
12265 struct intel_shared_dpll
*shared_dpll
;
12266 uint32_t ddi_pll_sel
;
12269 /* FIXME: before the switch to atomic started, a new pipe_config was
12270 * kzalloc'd. Code that depends on any field being zero should be
12271 * fixed, so that the crtc_state can be safely duplicated. For now,
12272 * only fields that are know to not cause problems are preserved. */
12274 tmp_state
= crtc_state
->base
;
12275 scaler_state
= crtc_state
->scaler_state
;
12276 shared_dpll
= crtc_state
->shared_dpll
;
12277 dpll_hw_state
= crtc_state
->dpll_hw_state
;
12278 ddi_pll_sel
= crtc_state
->ddi_pll_sel
;
12279 force_thru
= crtc_state
->pch_pfit
.force_thru
;
12281 memset(crtc_state
, 0, sizeof *crtc_state
);
12283 crtc_state
->base
= tmp_state
;
12284 crtc_state
->scaler_state
= scaler_state
;
12285 crtc_state
->shared_dpll
= shared_dpll
;
12286 crtc_state
->dpll_hw_state
= dpll_hw_state
;
12287 crtc_state
->ddi_pll_sel
= ddi_pll_sel
;
12288 crtc_state
->pch_pfit
.force_thru
= force_thru
;
12292 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
12293 struct intel_crtc_state
*pipe_config
)
12295 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
12296 struct intel_encoder
*encoder
;
12297 struct drm_connector
*connector
;
12298 struct drm_connector_state
*connector_state
;
12299 int base_bpp
, ret
= -EINVAL
;
12303 clear_intel_crtc_state(pipe_config
);
12305 pipe_config
->cpu_transcoder
=
12306 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
12309 * Sanitize sync polarity flags based on requested ones. If neither
12310 * positive or negative polarity is requested, treat this as meaning
12311 * negative polarity.
12313 if (!(pipe_config
->base
.adjusted_mode
.flags
&
12314 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
12315 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
12317 if (!(pipe_config
->base
.adjusted_mode
.flags
&
12318 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
12319 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
12321 base_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
12327 * Determine the real pipe dimensions. Note that stereo modes can
12328 * increase the actual pipe size due to the frame doubling and
12329 * insertion of additional space for blanks between the frame. This
12330 * is stored in the crtc timings. We use the requested mode to do this
12331 * computation to clearly distinguish it from the adjusted mode, which
12332 * can be changed by the connectors in the below retry loop.
12334 drm_crtc_get_hv_timing(&pipe_config
->base
.mode
,
12335 &pipe_config
->pipe_src_w
,
12336 &pipe_config
->pipe_src_h
);
12339 /* Ensure the port clock defaults are reset when retrying. */
12340 pipe_config
->port_clock
= 0;
12341 pipe_config
->pixel_multiplier
= 1;
12343 /* Fill in default crtc timings, allow encoders to overwrite them. */
12344 drm_mode_set_crtcinfo(&pipe_config
->base
.adjusted_mode
,
12345 CRTC_STEREO_DOUBLE
);
12347 /* Pass our mode to the connectors and the CRTC to give them a chance to
12348 * adjust it according to limitations or connector properties, and also
12349 * a chance to reject the mode entirely.
12351 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
12352 if (connector_state
->crtc
!= crtc
)
12355 encoder
= to_intel_encoder(connector_state
->best_encoder
);
12357 if (!(encoder
->compute_config(encoder
, pipe_config
))) {
12358 DRM_DEBUG_KMS("Encoder config failure\n");
12363 /* Set default port clock if not overwritten by the encoder. Needs to be
12364 * done afterwards in case the encoder adjusts the mode. */
12365 if (!pipe_config
->port_clock
)
12366 pipe_config
->port_clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
12367 * pipe_config
->pixel_multiplier
;
12369 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
12371 DRM_DEBUG_KMS("CRTC fixup failed\n");
12375 if (ret
== RETRY
) {
12376 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
12381 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
12383 goto encoder_retry
;
12386 /* Dithering seems to not pass-through bits correctly when it should, so
12387 * only enable it on 6bpc panels. */
12388 pipe_config
->dither
= pipe_config
->pipe_bpp
== 6*3;
12389 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
12390 base_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
12397 intel_modeset_update_crtc_state(struct drm_atomic_state
*state
)
12399 struct drm_crtc
*crtc
;
12400 struct drm_crtc_state
*crtc_state
;
12403 /* Double check state. */
12404 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12405 to_intel_crtc(crtc
)->config
= to_intel_crtc_state(crtc
->state
);
12407 /* Update hwmode for vblank functions */
12408 if (crtc
->state
->active
)
12409 crtc
->hwmode
= crtc
->state
->adjusted_mode
;
12411 crtc
->hwmode
.crtc_clock
= 0;
12414 * Update legacy state to satisfy fbc code. This can
12415 * be removed when fbc uses the atomic state.
12417 if (drm_atomic_get_existing_plane_state(state
, crtc
->primary
)) {
12418 struct drm_plane_state
*plane_state
= crtc
->primary
->state
;
12420 crtc
->primary
->fb
= plane_state
->fb
;
12421 crtc
->x
= plane_state
->src_x
>> 16;
12422 crtc
->y
= plane_state
->src_y
>> 16;
12427 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
12431 if (clock1
== clock2
)
12434 if (!clock1
|| !clock2
)
12437 diff
= abs(clock1
- clock2
);
12439 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
12445 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
12446 list_for_each_entry((intel_crtc), \
12447 &(dev)->mode_config.crtc_list, \
12449 for_each_if (mask & (1 <<(intel_crtc)->pipe))
12452 intel_compare_m_n(unsigned int m
, unsigned int n
,
12453 unsigned int m2
, unsigned int n2
,
12456 if (m
== m2
&& n
== n2
)
12459 if (exact
|| !m
|| !n
|| !m2
|| !n2
)
12462 BUILD_BUG_ON(DATA_LINK_M_N_MASK
> INT_MAX
);
12469 } else if (n
< n2
) {
12479 return intel_fuzzy_clock_check(m
, m2
);
12483 intel_compare_link_m_n(const struct intel_link_m_n
*m_n
,
12484 struct intel_link_m_n
*m2_n2
,
12487 if (m_n
->tu
== m2_n2
->tu
&&
12488 intel_compare_m_n(m_n
->gmch_m
, m_n
->gmch_n
,
12489 m2_n2
->gmch_m
, m2_n2
->gmch_n
, !adjust
) &&
12490 intel_compare_m_n(m_n
->link_m
, m_n
->link_n
,
12491 m2_n2
->link_m
, m2_n2
->link_n
, !adjust
)) {
12502 intel_pipe_config_compare(struct drm_device
*dev
,
12503 struct intel_crtc_state
*current_config
,
12504 struct intel_crtc_state
*pipe_config
,
12509 #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \
12512 DRM_ERROR(fmt, ##__VA_ARGS__); \
12514 DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \
12517 #define PIPE_CONF_CHECK_X(name) \
12518 if (current_config->name != pipe_config->name) { \
12519 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12520 "(expected 0x%08x, found 0x%08x)\n", \
12521 current_config->name, \
12522 pipe_config->name); \
12526 #define PIPE_CONF_CHECK_I(name) \
12527 if (current_config->name != pipe_config->name) { \
12528 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12529 "(expected %i, found %i)\n", \
12530 current_config->name, \
12531 pipe_config->name); \
12535 #define PIPE_CONF_CHECK_P(name) \
12536 if (current_config->name != pipe_config->name) { \
12537 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12538 "(expected %p, found %p)\n", \
12539 current_config->name, \
12540 pipe_config->name); \
12544 #define PIPE_CONF_CHECK_M_N(name) \
12545 if (!intel_compare_link_m_n(¤t_config->name, \
12546 &pipe_config->name,\
12548 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12549 "(expected tu %i gmch %i/%i link %i/%i, " \
12550 "found tu %i, gmch %i/%i link %i/%i)\n", \
12551 current_config->name.tu, \
12552 current_config->name.gmch_m, \
12553 current_config->name.gmch_n, \
12554 current_config->name.link_m, \
12555 current_config->name.link_n, \
12556 pipe_config->name.tu, \
12557 pipe_config->name.gmch_m, \
12558 pipe_config->name.gmch_n, \
12559 pipe_config->name.link_m, \
12560 pipe_config->name.link_n); \
12564 /* This is required for BDW+ where there is only one set of registers for
12565 * switching between high and low RR.
12566 * This macro can be used whenever a comparison has to be made between one
12567 * hw state and multiple sw state variables.
12569 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \
12570 if (!intel_compare_link_m_n(¤t_config->name, \
12571 &pipe_config->name, adjust) && \
12572 !intel_compare_link_m_n(¤t_config->alt_name, \
12573 &pipe_config->name, adjust)) { \
12574 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12575 "(expected tu %i gmch %i/%i link %i/%i, " \
12576 "or tu %i gmch %i/%i link %i/%i, " \
12577 "found tu %i, gmch %i/%i link %i/%i)\n", \
12578 current_config->name.tu, \
12579 current_config->name.gmch_m, \
12580 current_config->name.gmch_n, \
12581 current_config->name.link_m, \
12582 current_config->name.link_n, \
12583 current_config->alt_name.tu, \
12584 current_config->alt_name.gmch_m, \
12585 current_config->alt_name.gmch_n, \
12586 current_config->alt_name.link_m, \
12587 current_config->alt_name.link_n, \
12588 pipe_config->name.tu, \
12589 pipe_config->name.gmch_m, \
12590 pipe_config->name.gmch_n, \
12591 pipe_config->name.link_m, \
12592 pipe_config->name.link_n); \
12596 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
12597 if ((current_config->name ^ pipe_config->name) & (mask)) { \
12598 INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \
12599 "(expected %i, found %i)\n", \
12600 current_config->name & (mask), \
12601 pipe_config->name & (mask)); \
12605 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
12606 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
12607 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12608 "(expected %i, found %i)\n", \
12609 current_config->name, \
12610 pipe_config->name); \
12614 #define PIPE_CONF_QUIRK(quirk) \
12615 ((current_config->quirks | pipe_config->quirks) & (quirk))
12617 PIPE_CONF_CHECK_I(cpu_transcoder
);
12619 PIPE_CONF_CHECK_I(has_pch_encoder
);
12620 PIPE_CONF_CHECK_I(fdi_lanes
);
12621 PIPE_CONF_CHECK_M_N(fdi_m_n
);
12623 PIPE_CONF_CHECK_I(has_dp_encoder
);
12624 PIPE_CONF_CHECK_I(lane_count
);
12626 if (INTEL_INFO(dev
)->gen
< 8) {
12627 PIPE_CONF_CHECK_M_N(dp_m_n
);
12629 if (current_config
->has_drrs
)
12630 PIPE_CONF_CHECK_M_N(dp_m2_n2
);
12632 PIPE_CONF_CHECK_M_N_ALT(dp_m_n
, dp_m2_n2
);
12634 PIPE_CONF_CHECK_I(has_dsi_encoder
);
12636 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hdisplay
);
12637 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_htotal
);
12638 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_start
);
12639 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_end
);
12640 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_start
);
12641 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_end
);
12643 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vdisplay
);
12644 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vtotal
);
12645 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_start
);
12646 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_end
);
12647 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_start
);
12648 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_end
);
12650 PIPE_CONF_CHECK_I(pixel_multiplier
);
12651 PIPE_CONF_CHECK_I(has_hdmi_sink
);
12652 if ((INTEL_INFO(dev
)->gen
< 8 && !IS_HASWELL(dev
)) ||
12653 IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
))
12654 PIPE_CONF_CHECK_I(limited_color_range
);
12655 PIPE_CONF_CHECK_I(has_infoframe
);
12657 PIPE_CONF_CHECK_I(has_audio
);
12659 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12660 DRM_MODE_FLAG_INTERLACE
);
12662 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
12663 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12664 DRM_MODE_FLAG_PHSYNC
);
12665 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12666 DRM_MODE_FLAG_NHSYNC
);
12667 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12668 DRM_MODE_FLAG_PVSYNC
);
12669 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12670 DRM_MODE_FLAG_NVSYNC
);
12673 PIPE_CONF_CHECK_X(gmch_pfit
.control
);
12674 /* pfit ratios are autocomputed by the hw on gen4+ */
12675 if (INTEL_INFO(dev
)->gen
< 4)
12676 PIPE_CONF_CHECK_X(gmch_pfit
.pgm_ratios
);
12677 PIPE_CONF_CHECK_X(gmch_pfit
.lvds_border_bits
);
12680 PIPE_CONF_CHECK_I(pipe_src_w
);
12681 PIPE_CONF_CHECK_I(pipe_src_h
);
12683 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
12684 if (current_config
->pch_pfit
.enabled
) {
12685 PIPE_CONF_CHECK_X(pch_pfit
.pos
);
12686 PIPE_CONF_CHECK_X(pch_pfit
.size
);
12689 PIPE_CONF_CHECK_I(scaler_state
.scaler_id
);
12692 /* BDW+ don't expose a synchronous way to read the state */
12693 if (IS_HASWELL(dev
))
12694 PIPE_CONF_CHECK_I(ips_enabled
);
12696 PIPE_CONF_CHECK_I(double_wide
);
12698 PIPE_CONF_CHECK_X(ddi_pll_sel
);
12700 PIPE_CONF_CHECK_P(shared_dpll
);
12701 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
12702 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
12703 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
12704 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
12705 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
12706 PIPE_CONF_CHECK_X(dpll_hw_state
.spll
);
12707 PIPE_CONF_CHECK_X(dpll_hw_state
.ctrl1
);
12708 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr1
);
12709 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr2
);
12711 PIPE_CONF_CHECK_X(dsi_pll
.ctrl
);
12712 PIPE_CONF_CHECK_X(dsi_pll
.div
);
12714 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5)
12715 PIPE_CONF_CHECK_I(pipe_bpp
);
12717 PIPE_CONF_CHECK_CLOCK_FUZZY(base
.adjusted_mode
.crtc_clock
);
12718 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
12720 #undef PIPE_CONF_CHECK_X
12721 #undef PIPE_CONF_CHECK_I
12722 #undef PIPE_CONF_CHECK_P
12723 #undef PIPE_CONF_CHECK_FLAGS
12724 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
12725 #undef PIPE_CONF_QUIRK
12726 #undef INTEL_ERR_OR_DBG_KMS
12731 static void intel_pipe_config_sanity_check(struct drm_i915_private
*dev_priv
,
12732 const struct intel_crtc_state
*pipe_config
)
12734 if (pipe_config
->has_pch_encoder
) {
12735 int fdi_dotclock
= intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
12736 &pipe_config
->fdi_m_n
);
12737 int dotclock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
12740 * FDI already provided one idea for the dotclock.
12741 * Yell if the encoder disagrees.
12743 WARN(!intel_fuzzy_clock_check(fdi_dotclock
, dotclock
),
12744 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
12745 fdi_dotclock
, dotclock
);
12749 static void verify_wm_state(struct drm_crtc
*crtc
,
12750 struct drm_crtc_state
*new_state
)
12752 struct drm_device
*dev
= crtc
->dev
;
12753 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12754 struct skl_ddb_allocation hw_ddb
, *sw_ddb
;
12755 struct skl_ddb_entry
*hw_entry
, *sw_entry
;
12756 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12757 const enum pipe pipe
= intel_crtc
->pipe
;
12760 if (INTEL_INFO(dev
)->gen
< 9 || !new_state
->active
)
12763 skl_ddb_get_hw_state(dev_priv
, &hw_ddb
);
12764 sw_ddb
= &dev_priv
->wm
.skl_hw
.ddb
;
12767 for_each_plane(dev_priv
, pipe
, plane
) {
12768 hw_entry
= &hw_ddb
.plane
[pipe
][plane
];
12769 sw_entry
= &sw_ddb
->plane
[pipe
][plane
];
12771 if (skl_ddb_entry_equal(hw_entry
, sw_entry
))
12774 DRM_ERROR("mismatch in DDB state pipe %c plane %d "
12775 "(expected (%u,%u), found (%u,%u))\n",
12776 pipe_name(pipe
), plane
+ 1,
12777 sw_entry
->start
, sw_entry
->end
,
12778 hw_entry
->start
, hw_entry
->end
);
12782 hw_entry
= &hw_ddb
.plane
[pipe
][PLANE_CURSOR
];
12783 sw_entry
= &sw_ddb
->plane
[pipe
][PLANE_CURSOR
];
12785 if (!skl_ddb_entry_equal(hw_entry
, sw_entry
)) {
12786 DRM_ERROR("mismatch in DDB state pipe %c cursor "
12787 "(expected (%u,%u), found (%u,%u))\n",
12789 sw_entry
->start
, sw_entry
->end
,
12790 hw_entry
->start
, hw_entry
->end
);
12795 verify_connector_state(struct drm_device
*dev
, struct drm_crtc
*crtc
)
12797 struct drm_connector
*connector
;
12799 drm_for_each_connector(connector
, dev
) {
12800 struct drm_encoder
*encoder
= connector
->encoder
;
12801 struct drm_connector_state
*state
= connector
->state
;
12803 if (state
->crtc
!= crtc
)
12806 intel_connector_verify_state(to_intel_connector(connector
));
12808 I915_STATE_WARN(state
->best_encoder
!= encoder
,
12809 "connector's atomic encoder doesn't match legacy encoder\n");
12814 verify_encoder_state(struct drm_device
*dev
)
12816 struct intel_encoder
*encoder
;
12817 struct intel_connector
*connector
;
12819 for_each_intel_encoder(dev
, encoder
) {
12820 bool enabled
= false;
12823 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
12824 encoder
->base
.base
.id
,
12825 encoder
->base
.name
);
12827 for_each_intel_connector(dev
, connector
) {
12828 if (connector
->base
.state
->best_encoder
!= &encoder
->base
)
12832 I915_STATE_WARN(connector
->base
.state
->crtc
!=
12833 encoder
->base
.crtc
,
12834 "connector's crtc doesn't match encoder crtc\n");
12837 I915_STATE_WARN(!!encoder
->base
.crtc
!= enabled
,
12838 "encoder's enabled state mismatch "
12839 "(expected %i, found %i)\n",
12840 !!encoder
->base
.crtc
, enabled
);
12842 if (!encoder
->base
.crtc
) {
12845 active
= encoder
->get_hw_state(encoder
, &pipe
);
12846 I915_STATE_WARN(active
,
12847 "encoder detached but still enabled on pipe %c.\n",
12854 verify_crtc_state(struct drm_crtc
*crtc
,
12855 struct drm_crtc_state
*old_crtc_state
,
12856 struct drm_crtc_state
*new_crtc_state
)
12858 struct drm_device
*dev
= crtc
->dev
;
12859 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12860 struct intel_encoder
*encoder
;
12861 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12862 struct intel_crtc_state
*pipe_config
, *sw_config
;
12863 struct drm_atomic_state
*old_state
;
12866 old_state
= old_crtc_state
->state
;
12867 __drm_atomic_helper_crtc_destroy_state(crtc
, old_crtc_state
);
12868 pipe_config
= to_intel_crtc_state(old_crtc_state
);
12869 memset(pipe_config
, 0, sizeof(*pipe_config
));
12870 pipe_config
->base
.crtc
= crtc
;
12871 pipe_config
->base
.state
= old_state
;
12873 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
12875 active
= dev_priv
->display
.get_pipe_config(intel_crtc
, pipe_config
);
12877 /* hw state is inconsistent with the pipe quirk */
12878 if ((intel_crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
12879 (intel_crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
12880 active
= new_crtc_state
->active
;
12882 I915_STATE_WARN(new_crtc_state
->active
!= active
,
12883 "crtc active state doesn't match with hw state "
12884 "(expected %i, found %i)\n", new_crtc_state
->active
, active
);
12886 I915_STATE_WARN(intel_crtc
->active
!= new_crtc_state
->active
,
12887 "transitional active state does not match atomic hw state "
12888 "(expected %i, found %i)\n", new_crtc_state
->active
, intel_crtc
->active
);
12890 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
12893 active
= encoder
->get_hw_state(encoder
, &pipe
);
12894 I915_STATE_WARN(active
!= new_crtc_state
->active
,
12895 "[ENCODER:%i] active %i with crtc active %i\n",
12896 encoder
->base
.base
.id
, active
, new_crtc_state
->active
);
12898 I915_STATE_WARN(active
&& intel_crtc
->pipe
!= pipe
,
12899 "Encoder connected to wrong pipe %c\n",
12903 encoder
->get_config(encoder
, pipe_config
);
12906 if (!new_crtc_state
->active
)
12909 intel_pipe_config_sanity_check(dev_priv
, pipe_config
);
12911 sw_config
= to_intel_crtc_state(crtc
->state
);
12912 if (!intel_pipe_config_compare(dev
, sw_config
,
12913 pipe_config
, false)) {
12914 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12915 intel_dump_pipe_config(intel_crtc
, pipe_config
,
12917 intel_dump_pipe_config(intel_crtc
, sw_config
,
12923 verify_single_dpll_state(struct drm_i915_private
*dev_priv
,
12924 struct intel_shared_dpll
*pll
,
12925 struct drm_crtc
*crtc
,
12926 struct drm_crtc_state
*new_state
)
12928 struct intel_dpll_hw_state dpll_hw_state
;
12929 unsigned crtc_mask
;
12932 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
12934 DRM_DEBUG_KMS("%s\n", pll
->name
);
12936 active
= pll
->funcs
.get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
12938 if (!(pll
->flags
& INTEL_DPLL_ALWAYS_ON
)) {
12939 I915_STATE_WARN(!pll
->on
&& pll
->active_mask
,
12940 "pll in active use but not on in sw tracking\n");
12941 I915_STATE_WARN(pll
->on
&& !pll
->active_mask
,
12942 "pll is on but not used by any active crtc\n");
12943 I915_STATE_WARN(pll
->on
!= active
,
12944 "pll on state mismatch (expected %i, found %i)\n",
12949 I915_STATE_WARN(pll
->active_mask
& ~pll
->config
.crtc_mask
,
12950 "more active pll users than references: %x vs %x\n",
12951 pll
->active_mask
, pll
->config
.crtc_mask
);
12956 crtc_mask
= 1 << drm_crtc_index(crtc
);
12958 if (new_state
->active
)
12959 I915_STATE_WARN(!(pll
->active_mask
& crtc_mask
),
12960 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
12961 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
12963 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
12964 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
12965 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
12967 I915_STATE_WARN(!(pll
->config
.crtc_mask
& crtc_mask
),
12968 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
12969 crtc_mask
, pll
->config
.crtc_mask
);
12971 I915_STATE_WARN(pll
->on
&& memcmp(&pll
->config
.hw_state
,
12973 sizeof(dpll_hw_state
)),
12974 "pll hw state mismatch\n");
12978 verify_shared_dpll_state(struct drm_device
*dev
, struct drm_crtc
*crtc
,
12979 struct drm_crtc_state
*old_crtc_state
,
12980 struct drm_crtc_state
*new_crtc_state
)
12982 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12983 struct intel_crtc_state
*old_state
= to_intel_crtc_state(old_crtc_state
);
12984 struct intel_crtc_state
*new_state
= to_intel_crtc_state(new_crtc_state
);
12986 if (new_state
->shared_dpll
)
12987 verify_single_dpll_state(dev_priv
, new_state
->shared_dpll
, crtc
, new_crtc_state
);
12989 if (old_state
->shared_dpll
&&
12990 old_state
->shared_dpll
!= new_state
->shared_dpll
) {
12991 unsigned crtc_mask
= 1 << drm_crtc_index(crtc
);
12992 struct intel_shared_dpll
*pll
= old_state
->shared_dpll
;
12994 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
12995 "pll active mismatch (didn't expect pipe %c in active mask)\n",
12996 pipe_name(drm_crtc_index(crtc
)));
12997 I915_STATE_WARN(pll
->config
.crtc_mask
& crtc_mask
,
12998 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
12999 pipe_name(drm_crtc_index(crtc
)));
13004 intel_modeset_verify_crtc(struct drm_crtc
*crtc
,
13005 struct drm_crtc_state
*old_state
,
13006 struct drm_crtc_state
*new_state
)
13008 if (!needs_modeset(new_state
) &&
13009 !to_intel_crtc_state(new_state
)->update_pipe
)
13012 verify_wm_state(crtc
, new_state
);
13013 verify_connector_state(crtc
->dev
, crtc
);
13014 verify_crtc_state(crtc
, old_state
, new_state
);
13015 verify_shared_dpll_state(crtc
->dev
, crtc
, old_state
, new_state
);
13019 verify_disabled_dpll_state(struct drm_device
*dev
)
13021 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13024 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++)
13025 verify_single_dpll_state(dev_priv
, &dev_priv
->shared_dplls
[i
], NULL
, NULL
);
13029 intel_modeset_verify_disabled(struct drm_device
*dev
)
13031 verify_encoder_state(dev
);
13032 verify_connector_state(dev
, NULL
);
13033 verify_disabled_dpll_state(dev
);
13036 static void update_scanline_offset(struct intel_crtc
*crtc
)
13038 struct drm_device
*dev
= crtc
->base
.dev
;
13041 * The scanline counter increments at the leading edge of hsync.
13043 * On most platforms it starts counting from vtotal-1 on the
13044 * first active line. That means the scanline counter value is
13045 * always one less than what we would expect. Ie. just after
13046 * start of vblank, which also occurs at start of hsync (on the
13047 * last active line), the scanline counter will read vblank_start-1.
13049 * On gen2 the scanline counter starts counting from 1 instead
13050 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
13051 * to keep the value positive), instead of adding one.
13053 * On HSW+ the behaviour of the scanline counter depends on the output
13054 * type. For DP ports it behaves like most other platforms, but on HDMI
13055 * there's an extra 1 line difference. So we need to add two instead of
13056 * one to the value.
13058 if (IS_GEN2(dev
)) {
13059 const struct drm_display_mode
*adjusted_mode
= &crtc
->config
->base
.adjusted_mode
;
13062 vtotal
= adjusted_mode
->crtc_vtotal
;
13063 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
13066 crtc
->scanline_offset
= vtotal
- 1;
13067 } else if (HAS_DDI(dev
) &&
13068 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
)) {
13069 crtc
->scanline_offset
= 2;
13071 crtc
->scanline_offset
= 1;
13074 static void intel_modeset_clear_plls(struct drm_atomic_state
*state
)
13076 struct drm_device
*dev
= state
->dev
;
13077 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13078 struct intel_shared_dpll_config
*shared_dpll
= NULL
;
13079 struct drm_crtc
*crtc
;
13080 struct drm_crtc_state
*crtc_state
;
13083 if (!dev_priv
->display
.crtc_compute_clock
)
13086 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
13087 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13088 struct intel_shared_dpll
*old_dpll
=
13089 to_intel_crtc_state(crtc
->state
)->shared_dpll
;
13091 if (!needs_modeset(crtc_state
))
13094 to_intel_crtc_state(crtc_state
)->shared_dpll
= NULL
;
13100 shared_dpll
= intel_atomic_get_shared_dpll_state(state
);
13102 intel_shared_dpll_config_put(shared_dpll
, old_dpll
, intel_crtc
);
13107 * This implements the workaround described in the "notes" section of the mode
13108 * set sequence documentation. When going from no pipes or single pipe to
13109 * multiple pipes, and planes are enabled after the pipe, we need to wait at
13110 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
13112 static int haswell_mode_set_planes_workaround(struct drm_atomic_state
*state
)
13114 struct drm_crtc_state
*crtc_state
;
13115 struct intel_crtc
*intel_crtc
;
13116 struct drm_crtc
*crtc
;
13117 struct intel_crtc_state
*first_crtc_state
= NULL
;
13118 struct intel_crtc_state
*other_crtc_state
= NULL
;
13119 enum pipe first_pipe
= INVALID_PIPE
, enabled_pipe
= INVALID_PIPE
;
13122 /* look at all crtc's that are going to be enabled in during modeset */
13123 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
13124 intel_crtc
= to_intel_crtc(crtc
);
13126 if (!crtc_state
->active
|| !needs_modeset(crtc_state
))
13129 if (first_crtc_state
) {
13130 other_crtc_state
= to_intel_crtc_state(crtc_state
);
13133 first_crtc_state
= to_intel_crtc_state(crtc_state
);
13134 first_pipe
= intel_crtc
->pipe
;
13138 /* No workaround needed? */
13139 if (!first_crtc_state
)
13142 /* w/a possibly needed, check how many crtc's are already enabled. */
13143 for_each_intel_crtc(state
->dev
, intel_crtc
) {
13144 struct intel_crtc_state
*pipe_config
;
13146 pipe_config
= intel_atomic_get_crtc_state(state
, intel_crtc
);
13147 if (IS_ERR(pipe_config
))
13148 return PTR_ERR(pipe_config
);
13150 pipe_config
->hsw_workaround_pipe
= INVALID_PIPE
;
13152 if (!pipe_config
->base
.active
||
13153 needs_modeset(&pipe_config
->base
))
13156 /* 2 or more enabled crtcs means no need for w/a */
13157 if (enabled_pipe
!= INVALID_PIPE
)
13160 enabled_pipe
= intel_crtc
->pipe
;
13163 if (enabled_pipe
!= INVALID_PIPE
)
13164 first_crtc_state
->hsw_workaround_pipe
= enabled_pipe
;
13165 else if (other_crtc_state
)
13166 other_crtc_state
->hsw_workaround_pipe
= first_pipe
;
13171 static int intel_modeset_all_pipes(struct drm_atomic_state
*state
)
13173 struct drm_crtc
*crtc
;
13174 struct drm_crtc_state
*crtc_state
;
13177 /* add all active pipes to the state */
13178 for_each_crtc(state
->dev
, crtc
) {
13179 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
13180 if (IS_ERR(crtc_state
))
13181 return PTR_ERR(crtc_state
);
13183 if (!crtc_state
->active
|| needs_modeset(crtc_state
))
13186 crtc_state
->mode_changed
= true;
13188 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
13192 ret
= drm_atomic_add_affected_planes(state
, crtc
);
13200 static int intel_modeset_checks(struct drm_atomic_state
*state
)
13202 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
13203 struct drm_i915_private
*dev_priv
= state
->dev
->dev_private
;
13204 struct drm_crtc
*crtc
;
13205 struct drm_crtc_state
*crtc_state
;
13208 if (!check_digital_port_conflicts(state
)) {
13209 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
13213 intel_state
->modeset
= true;
13214 intel_state
->active_crtcs
= dev_priv
->active_crtcs
;
13216 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
13217 if (crtc_state
->active
)
13218 intel_state
->active_crtcs
|= 1 << i
;
13220 intel_state
->active_crtcs
&= ~(1 << i
);
13222 if (crtc_state
->active
!= crtc
->state
->active
)
13223 intel_state
->active_pipe_changes
|= drm_crtc_mask(crtc
);
13227 * See if the config requires any additional preparation, e.g.
13228 * to adjust global state with pipes off. We need to do this
13229 * here so we can get the modeset_pipe updated config for the new
13230 * mode set on this crtc. For other crtcs we need to use the
13231 * adjusted_mode bits in the crtc directly.
13233 if (dev_priv
->display
.modeset_calc_cdclk
) {
13234 ret
= dev_priv
->display
.modeset_calc_cdclk(state
);
13236 if (!ret
&& intel_state
->dev_cdclk
!= dev_priv
->cdclk_freq
)
13237 ret
= intel_modeset_all_pipes(state
);
13242 DRM_DEBUG_KMS("New cdclk calculated to be atomic %u, actual %u\n",
13243 intel_state
->cdclk
, intel_state
->dev_cdclk
);
13245 to_intel_atomic_state(state
)->cdclk
= dev_priv
->atomic_cdclk_freq
;
13247 intel_modeset_clear_plls(state
);
13249 if (IS_HASWELL(dev_priv
))
13250 return haswell_mode_set_planes_workaround(state
);
13256 * Handle calculation of various watermark data at the end of the atomic check
13257 * phase. The code here should be run after the per-crtc and per-plane 'check'
13258 * handlers to ensure that all derived state has been updated.
13260 static int calc_watermark_data(struct drm_atomic_state
*state
)
13262 struct drm_device
*dev
= state
->dev
;
13263 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13265 /* Is there platform-specific watermark information to calculate? */
13266 if (dev_priv
->display
.compute_global_watermarks
)
13267 return dev_priv
->display
.compute_global_watermarks(state
);
13273 * intel_atomic_check - validate state object
13275 * @state: state to validate
13277 static int intel_atomic_check(struct drm_device
*dev
,
13278 struct drm_atomic_state
*state
)
13280 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13281 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
13282 struct drm_crtc
*crtc
;
13283 struct drm_crtc_state
*crtc_state
;
13285 bool any_ms
= false;
13287 ret
= drm_atomic_helper_check_modeset(dev
, state
);
13291 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
13292 struct intel_crtc_state
*pipe_config
=
13293 to_intel_crtc_state(crtc_state
);
13295 /* Catch I915_MODE_FLAG_INHERITED */
13296 if (crtc_state
->mode
.private_flags
!= crtc
->state
->mode
.private_flags
)
13297 crtc_state
->mode_changed
= true;
13299 if (!needs_modeset(crtc_state
))
13302 if (!crtc_state
->enable
) {
13307 /* FIXME: For only active_changed we shouldn't need to do any
13308 * state recomputation at all. */
13310 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
13314 ret
= intel_modeset_pipe_config(crtc
, pipe_config
);
13316 intel_dump_pipe_config(to_intel_crtc(crtc
),
13317 pipe_config
, "[failed]");
13321 if (i915
.fastboot
&&
13322 intel_pipe_config_compare(dev
,
13323 to_intel_crtc_state(crtc
->state
),
13324 pipe_config
, true)) {
13325 crtc_state
->mode_changed
= false;
13326 to_intel_crtc_state(crtc_state
)->update_pipe
= true;
13329 if (needs_modeset(crtc_state
))
13332 ret
= drm_atomic_add_affected_planes(state
, crtc
);
13336 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
13337 needs_modeset(crtc_state
) ?
13338 "[modeset]" : "[fastset]");
13342 ret
= intel_modeset_checks(state
);
13347 intel_state
->cdclk
= dev_priv
->cdclk_freq
;
13349 ret
= drm_atomic_helper_check_planes(dev
, state
);
13353 intel_fbc_choose_crtc(dev_priv
, state
);
13354 return calc_watermark_data(state
);
13357 static int intel_atomic_prepare_commit(struct drm_device
*dev
,
13358 struct drm_atomic_state
*state
,
13361 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13362 struct drm_plane_state
*plane_state
;
13363 struct drm_crtc_state
*crtc_state
;
13364 struct drm_plane
*plane
;
13365 struct drm_crtc
*crtc
;
13369 DRM_DEBUG_KMS("i915 does not yet support nonblocking commit\n");
13373 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
13374 if (state
->legacy_cursor_update
)
13377 ret
= intel_crtc_wait_for_pending_flips(crtc
);
13381 if (atomic_read(&to_intel_crtc(crtc
)->unpin_work_count
) >= 2)
13382 flush_workqueue(dev_priv
->wq
);
13385 ret
= mutex_lock_interruptible(&dev
->struct_mutex
);
13389 ret
= drm_atomic_helper_prepare_planes(dev
, state
);
13390 mutex_unlock(&dev
->struct_mutex
);
13392 if (!ret
&& !nonblock
) {
13393 for_each_plane_in_state(state
, plane
, plane_state
, i
) {
13394 struct intel_plane_state
*intel_plane_state
=
13395 to_intel_plane_state(plane_state
);
13397 if (!intel_plane_state
->wait_req
)
13400 ret
= __i915_wait_request(intel_plane_state
->wait_req
,
13403 /* Any hang should be swallowed by the wait */
13404 WARN_ON(ret
== -EIO
);
13405 mutex_lock(&dev
->struct_mutex
);
13406 drm_atomic_helper_cleanup_planes(dev
, state
);
13407 mutex_unlock(&dev
->struct_mutex
);
13416 static void intel_atomic_wait_for_vblanks(struct drm_device
*dev
,
13417 struct drm_i915_private
*dev_priv
,
13418 unsigned crtc_mask
)
13420 unsigned last_vblank_count
[I915_MAX_PIPES
];
13427 for_each_pipe(dev_priv
, pipe
) {
13428 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
13430 if (!((1 << pipe
) & crtc_mask
))
13433 ret
= drm_crtc_vblank_get(crtc
);
13434 if (WARN_ON(ret
!= 0)) {
13435 crtc_mask
&= ~(1 << pipe
);
13439 last_vblank_count
[pipe
] = drm_crtc_vblank_count(crtc
);
13442 for_each_pipe(dev_priv
, pipe
) {
13443 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
13446 if (!((1 << pipe
) & crtc_mask
))
13449 lret
= wait_event_timeout(dev
->vblank
[pipe
].queue
,
13450 last_vblank_count
[pipe
] !=
13451 drm_crtc_vblank_count(crtc
),
13452 msecs_to_jiffies(50));
13454 WARN(!lret
, "pipe %c vblank wait timed out\n", pipe_name(pipe
));
13456 drm_crtc_vblank_put(crtc
);
13460 static bool needs_vblank_wait(struct intel_crtc_state
*crtc_state
)
13462 /* fb updated, need to unpin old fb */
13463 if (crtc_state
->fb_changed
)
13466 /* wm changes, need vblank before final wm's */
13467 if (crtc_state
->update_wm_post
)
13471 * cxsr is re-enabled after vblank.
13472 * This is already handled by crtc_state->update_wm_post,
13473 * but added for clarity.
13475 if (crtc_state
->disable_cxsr
)
13482 * intel_atomic_commit - commit validated state object
13484 * @state: the top-level driver state object
13485 * @nonblock: nonblocking commit
13487 * This function commits a top-level state object that has been validated
13488 * with drm_atomic_helper_check().
13490 * FIXME: Atomic modeset support for i915 is not yet complete. At the moment
13491 * we can only handle plane-related operations and do not yet support
13492 * nonblocking commit.
13495 * Zero for success or -errno.
13497 static int intel_atomic_commit(struct drm_device
*dev
,
13498 struct drm_atomic_state
*state
,
13501 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
13502 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13503 struct drm_crtc_state
*old_crtc_state
;
13504 struct drm_crtc
*crtc
;
13505 struct intel_crtc_state
*intel_cstate
;
13507 bool hw_check
= intel_state
->modeset
;
13508 unsigned long put_domains
[I915_MAX_PIPES
] = {};
13509 unsigned crtc_vblank_mask
= 0;
13511 ret
= intel_atomic_prepare_commit(dev
, state
, nonblock
);
13513 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret
);
13517 drm_atomic_helper_swap_state(dev
, state
);
13518 dev_priv
->wm
.distrust_bios_wm
= false;
13519 dev_priv
->wm
.skl_results
= intel_state
->wm_results
;
13520 intel_shared_dpll_commit(state
);
13522 if (intel_state
->modeset
) {
13523 memcpy(dev_priv
->min_pixclk
, intel_state
->min_pixclk
,
13524 sizeof(intel_state
->min_pixclk
));
13525 dev_priv
->active_crtcs
= intel_state
->active_crtcs
;
13526 dev_priv
->atomic_cdclk_freq
= intel_state
->cdclk
;
13528 intel_display_power_get(dev_priv
, POWER_DOMAIN_MODESET
);
13531 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
13532 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13534 if (needs_modeset(crtc
->state
) ||
13535 to_intel_crtc_state(crtc
->state
)->update_pipe
) {
13538 put_domains
[to_intel_crtc(crtc
)->pipe
] =
13539 modeset_get_crtc_power_domains(crtc
,
13540 to_intel_crtc_state(crtc
->state
));
13543 if (!needs_modeset(crtc
->state
))
13546 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
));
13548 if (old_crtc_state
->active
) {
13549 intel_crtc_disable_planes(crtc
, old_crtc_state
->plane_mask
);
13550 dev_priv
->display
.crtc_disable(crtc
);
13551 intel_crtc
->active
= false;
13552 intel_fbc_disable(intel_crtc
);
13553 intel_disable_shared_dpll(intel_crtc
);
13556 * Underruns don't always raise
13557 * interrupts, so check manually.
13559 intel_check_cpu_fifo_underruns(dev_priv
);
13560 intel_check_pch_fifo_underruns(dev_priv
);
13562 if (!crtc
->state
->active
)
13563 intel_update_watermarks(crtc
);
13567 /* Only after disabling all output pipelines that will be changed can we
13568 * update the the output configuration. */
13569 intel_modeset_update_crtc_state(state
);
13571 if (intel_state
->modeset
) {
13572 drm_atomic_helper_update_legacy_modeset_state(state
->dev
, state
);
13574 if (dev_priv
->display
.modeset_commit_cdclk
&&
13575 intel_state
->dev_cdclk
!= dev_priv
->cdclk_freq
)
13576 dev_priv
->display
.modeset_commit_cdclk(state
);
13578 intel_modeset_verify_disabled(dev
);
13581 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
13582 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
13583 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13584 bool modeset
= needs_modeset(crtc
->state
);
13585 struct intel_crtc_state
*pipe_config
=
13586 to_intel_crtc_state(crtc
->state
);
13587 bool update_pipe
= !modeset
&& pipe_config
->update_pipe
;
13589 if (modeset
&& crtc
->state
->active
) {
13590 update_scanline_offset(to_intel_crtc(crtc
));
13591 dev_priv
->display
.crtc_enable(crtc
);
13595 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
));
13597 if (crtc
->state
->active
&&
13598 drm_atomic_get_existing_plane_state(state
, crtc
->primary
))
13599 intel_fbc_enable(intel_crtc
);
13601 if (crtc
->state
->active
&&
13602 (crtc
->state
->planes_changed
|| update_pipe
))
13603 drm_atomic_helper_commit_planes_on_crtc(old_crtc_state
);
13605 if (pipe_config
->base
.active
&& needs_vblank_wait(pipe_config
))
13606 crtc_vblank_mask
|= 1 << i
;
13609 /* FIXME: add subpixel order */
13611 if (!state
->legacy_cursor_update
)
13612 intel_atomic_wait_for_vblanks(dev
, dev_priv
, crtc_vblank_mask
);
13615 * Now that the vblank has passed, we can go ahead and program the
13616 * optimal watermarks on platforms that need two-step watermark
13619 * TODO: Move this (and other cleanup) to an async worker eventually.
13621 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
13622 intel_cstate
= to_intel_crtc_state(crtc
->state
);
13624 if (dev_priv
->display
.optimize_watermarks
)
13625 dev_priv
->display
.optimize_watermarks(intel_cstate
);
13628 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
13629 intel_post_plane_update(to_intel_crtc_state(old_crtc_state
));
13631 if (put_domains
[i
])
13632 modeset_put_power_domains(dev_priv
, put_domains
[i
]);
13634 intel_modeset_verify_crtc(crtc
, old_crtc_state
, crtc
->state
);
13637 if (intel_state
->modeset
)
13638 intel_display_power_put(dev_priv
, POWER_DOMAIN_MODESET
);
13640 mutex_lock(&dev
->struct_mutex
);
13641 drm_atomic_helper_cleanup_planes(dev
, state
);
13642 mutex_unlock(&dev
->struct_mutex
);
13644 drm_atomic_state_free(state
);
13646 /* As one of the primary mmio accessors, KMS has a high likelihood
13647 * of triggering bugs in unclaimed access. After we finish
13648 * modesetting, see if an error has been flagged, and if so
13649 * enable debugging for the next modeset - and hope we catch
13652 * XXX note that we assume display power is on at this point.
13653 * This might hold true now but we need to add pm helper to check
13654 * unclaimed only when the hardware is on, as atomic commits
13655 * can happen also when the device is completely off.
13657 intel_uncore_arm_unclaimed_mmio_detection(dev_priv
);
13662 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
13664 struct drm_device
*dev
= crtc
->dev
;
13665 struct drm_atomic_state
*state
;
13666 struct drm_crtc_state
*crtc_state
;
13669 state
= drm_atomic_state_alloc(dev
);
13671 DRM_DEBUG_KMS("[CRTC:%d] crtc restore failed, out of memory",
13676 state
->acquire_ctx
= drm_modeset_legacy_acquire_ctx(crtc
);
13679 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
13680 ret
= PTR_ERR_OR_ZERO(crtc_state
);
13682 if (!crtc_state
->active
)
13685 crtc_state
->mode_changed
= true;
13686 ret
= drm_atomic_commit(state
);
13689 if (ret
== -EDEADLK
) {
13690 drm_atomic_state_clear(state
);
13691 drm_modeset_backoff(state
->acquire_ctx
);
13697 drm_atomic_state_free(state
);
13700 #undef for_each_intel_crtc_masked
13702 static const struct drm_crtc_funcs intel_crtc_funcs
= {
13703 .gamma_set
= drm_atomic_helper_legacy_gamma_set
,
13704 .set_config
= drm_atomic_helper_set_config
,
13705 .set_property
= drm_atomic_helper_crtc_set_property
,
13706 .destroy
= intel_crtc_destroy
,
13707 .page_flip
= intel_crtc_page_flip
,
13708 .atomic_duplicate_state
= intel_crtc_duplicate_state
,
13709 .atomic_destroy_state
= intel_crtc_destroy_state
,
13713 * intel_prepare_plane_fb - Prepare fb for usage on plane
13714 * @plane: drm plane to prepare for
13715 * @fb: framebuffer to prepare for presentation
13717 * Prepares a framebuffer for usage on a display plane. Generally this
13718 * involves pinning the underlying object and updating the frontbuffer tracking
13719 * bits. Some older platforms need special physical address handling for
13722 * Must be called with struct_mutex held.
13724 * Returns 0 on success, negative error code on failure.
13727 intel_prepare_plane_fb(struct drm_plane
*plane
,
13728 const struct drm_plane_state
*new_state
)
13730 struct drm_device
*dev
= plane
->dev
;
13731 struct drm_framebuffer
*fb
= new_state
->fb
;
13732 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
13733 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13734 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->state
->fb
);
13737 if (!obj
&& !old_obj
)
13741 struct drm_crtc_state
*crtc_state
=
13742 drm_atomic_get_existing_crtc_state(new_state
->state
, plane
->state
->crtc
);
13744 /* Big Hammer, we also need to ensure that any pending
13745 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
13746 * current scanout is retired before unpinning the old
13747 * framebuffer. Note that we rely on userspace rendering
13748 * into the buffer attached to the pipe they are waiting
13749 * on. If not, userspace generates a GPU hang with IPEHR
13750 * point to the MI_WAIT_FOR_EVENT.
13752 * This should only fail upon a hung GPU, in which case we
13753 * can safely continue.
13755 if (needs_modeset(crtc_state
))
13756 ret
= i915_gem_object_wait_rendering(old_obj
, true);
13758 /* GPU hangs should have been swallowed by the wait */
13759 WARN_ON(ret
== -EIO
);
13764 /* For framebuffer backed by dmabuf, wait for fence */
13765 if (obj
&& obj
->base
.dma_buf
) {
13768 lret
= reservation_object_wait_timeout_rcu(obj
->base
.dma_buf
->resv
,
13770 MAX_SCHEDULE_TIMEOUT
);
13771 if (lret
== -ERESTARTSYS
)
13774 WARN(lret
< 0, "waiting returns %li\n", lret
);
13779 } else if (plane
->type
== DRM_PLANE_TYPE_CURSOR
&&
13780 INTEL_INFO(dev
)->cursor_needs_physical
) {
13781 int align
= IS_I830(dev
) ? 16 * 1024 : 256;
13782 ret
= i915_gem_object_attach_phys(obj
, align
);
13784 DRM_DEBUG_KMS("failed to attach phys object\n");
13786 ret
= intel_pin_and_fence_fb_obj(fb
, new_state
->rotation
);
13791 struct intel_plane_state
*plane_state
=
13792 to_intel_plane_state(new_state
);
13794 i915_gem_request_assign(&plane_state
->wait_req
,
13795 obj
->last_write_req
);
13798 i915_gem_track_fb(old_obj
, obj
, intel_plane
->frontbuffer_bit
);
13805 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13806 * @plane: drm plane to clean up for
13807 * @fb: old framebuffer that was on plane
13809 * Cleans up a framebuffer that has just been removed from a plane.
13811 * Must be called with struct_mutex held.
13814 intel_cleanup_plane_fb(struct drm_plane
*plane
,
13815 const struct drm_plane_state
*old_state
)
13817 struct drm_device
*dev
= plane
->dev
;
13818 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
13819 struct intel_plane_state
*old_intel_state
;
13820 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(old_state
->fb
);
13821 struct drm_i915_gem_object
*obj
= intel_fb_obj(plane
->state
->fb
);
13823 old_intel_state
= to_intel_plane_state(old_state
);
13825 if (!obj
&& !old_obj
)
13828 if (old_obj
&& (plane
->type
!= DRM_PLANE_TYPE_CURSOR
||
13829 !INTEL_INFO(dev
)->cursor_needs_physical
))
13830 intel_unpin_fb_obj(old_state
->fb
, old_state
->rotation
);
13832 /* prepare_fb aborted? */
13833 if ((old_obj
&& (old_obj
->frontbuffer_bits
& intel_plane
->frontbuffer_bit
)) ||
13834 (obj
&& !(obj
->frontbuffer_bits
& intel_plane
->frontbuffer_bit
)))
13835 i915_gem_track_fb(old_obj
, obj
, intel_plane
->frontbuffer_bit
);
13837 i915_gem_request_assign(&old_intel_state
->wait_req
, NULL
);
13841 skl_max_scale(struct intel_crtc
*intel_crtc
, struct intel_crtc_state
*crtc_state
)
13844 struct drm_device
*dev
;
13845 struct drm_i915_private
*dev_priv
;
13846 int crtc_clock
, cdclk
;
13848 if (!intel_crtc
|| !crtc_state
->base
.enable
)
13849 return DRM_PLANE_HELPER_NO_SCALING
;
13851 dev
= intel_crtc
->base
.dev
;
13852 dev_priv
= dev
->dev_private
;
13853 crtc_clock
= crtc_state
->base
.adjusted_mode
.crtc_clock
;
13854 cdclk
= to_intel_atomic_state(crtc_state
->base
.state
)->cdclk
;
13856 if (WARN_ON_ONCE(!crtc_clock
|| cdclk
< crtc_clock
))
13857 return DRM_PLANE_HELPER_NO_SCALING
;
13860 * skl max scale is lower of:
13861 * close to 3 but not 3, -1 is for that purpose
13865 max_scale
= min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk
<< 8) / crtc_clock
));
13871 intel_check_primary_plane(struct drm_plane
*plane
,
13872 struct intel_crtc_state
*crtc_state
,
13873 struct intel_plane_state
*state
)
13875 struct drm_crtc
*crtc
= state
->base
.crtc
;
13876 struct drm_framebuffer
*fb
= state
->base
.fb
;
13877 int min_scale
= DRM_PLANE_HELPER_NO_SCALING
;
13878 int max_scale
= DRM_PLANE_HELPER_NO_SCALING
;
13879 bool can_position
= false;
13881 if (INTEL_INFO(plane
->dev
)->gen
>= 9) {
13882 /* use scaler when colorkey is not required */
13883 if (state
->ckey
.flags
== I915_SET_COLORKEY_NONE
) {
13885 max_scale
= skl_max_scale(to_intel_crtc(crtc
), crtc_state
);
13887 can_position
= true;
13890 return drm_plane_helper_check_update(plane
, crtc
, fb
, &state
->src
,
13891 &state
->dst
, &state
->clip
,
13892 min_scale
, max_scale
,
13893 can_position
, true,
13897 static void intel_begin_crtc_commit(struct drm_crtc
*crtc
,
13898 struct drm_crtc_state
*old_crtc_state
)
13900 struct drm_device
*dev
= crtc
->dev
;
13901 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13902 struct intel_crtc_state
*old_intel_state
=
13903 to_intel_crtc_state(old_crtc_state
);
13904 bool modeset
= needs_modeset(crtc
->state
);
13906 /* Perform vblank evasion around commit operation */
13907 intel_pipe_update_start(intel_crtc
);
13912 if (crtc
->state
->color_mgmt_changed
|| to_intel_crtc_state(crtc
->state
)->update_pipe
) {
13913 intel_color_set_csc(crtc
->state
);
13914 intel_color_load_luts(crtc
->state
);
13917 if (to_intel_crtc_state(crtc
->state
)->update_pipe
)
13918 intel_update_pipe_config(intel_crtc
, old_intel_state
);
13919 else if (INTEL_INFO(dev
)->gen
>= 9)
13920 skl_detach_scalers(intel_crtc
);
13923 static void intel_finish_crtc_commit(struct drm_crtc
*crtc
,
13924 struct drm_crtc_state
*old_crtc_state
)
13926 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13928 intel_pipe_update_end(intel_crtc
);
13932 * intel_plane_destroy - destroy a plane
13933 * @plane: plane to destroy
13935 * Common destruction function for all types of planes (primary, cursor,
13938 void intel_plane_destroy(struct drm_plane
*plane
)
13940 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
13941 drm_plane_cleanup(plane
);
13942 kfree(intel_plane
);
13945 const struct drm_plane_funcs intel_plane_funcs
= {
13946 .update_plane
= drm_atomic_helper_update_plane
,
13947 .disable_plane
= drm_atomic_helper_disable_plane
,
13948 .destroy
= intel_plane_destroy
,
13949 .set_property
= drm_atomic_helper_plane_set_property
,
13950 .atomic_get_property
= intel_plane_atomic_get_property
,
13951 .atomic_set_property
= intel_plane_atomic_set_property
,
13952 .atomic_duplicate_state
= intel_plane_duplicate_state
,
13953 .atomic_destroy_state
= intel_plane_destroy_state
,
13957 static struct drm_plane
*intel_primary_plane_create(struct drm_device
*dev
,
13960 struct intel_plane
*primary
= NULL
;
13961 struct intel_plane_state
*state
= NULL
;
13962 const uint32_t *intel_primary_formats
;
13963 unsigned int num_formats
;
13966 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
13970 state
= intel_create_plane_state(&primary
->base
);
13973 primary
->base
.state
= &state
->base
;
13975 primary
->can_scale
= false;
13976 primary
->max_downscale
= 1;
13977 if (INTEL_INFO(dev
)->gen
>= 9) {
13978 primary
->can_scale
= true;
13979 state
->scaler_id
= -1;
13981 primary
->pipe
= pipe
;
13982 primary
->plane
= pipe
;
13983 primary
->frontbuffer_bit
= INTEL_FRONTBUFFER_PRIMARY(pipe
);
13984 primary
->check_plane
= intel_check_primary_plane
;
13985 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4)
13986 primary
->plane
= !pipe
;
13988 if (INTEL_INFO(dev
)->gen
>= 9) {
13989 intel_primary_formats
= skl_primary_formats
;
13990 num_formats
= ARRAY_SIZE(skl_primary_formats
);
13992 primary
->update_plane
= skylake_update_primary_plane
;
13993 primary
->disable_plane
= skylake_disable_primary_plane
;
13994 } else if (HAS_PCH_SPLIT(dev
)) {
13995 intel_primary_formats
= i965_primary_formats
;
13996 num_formats
= ARRAY_SIZE(i965_primary_formats
);
13998 primary
->update_plane
= ironlake_update_primary_plane
;
13999 primary
->disable_plane
= i9xx_disable_primary_plane
;
14000 } else if (INTEL_INFO(dev
)->gen
>= 4) {
14001 intel_primary_formats
= i965_primary_formats
;
14002 num_formats
= ARRAY_SIZE(i965_primary_formats
);
14004 primary
->update_plane
= i9xx_update_primary_plane
;
14005 primary
->disable_plane
= i9xx_disable_primary_plane
;
14007 intel_primary_formats
= i8xx_primary_formats
;
14008 num_formats
= ARRAY_SIZE(i8xx_primary_formats
);
14010 primary
->update_plane
= i9xx_update_primary_plane
;
14011 primary
->disable_plane
= i9xx_disable_primary_plane
;
14014 ret
= drm_universal_plane_init(dev
, &primary
->base
, 0,
14015 &intel_plane_funcs
,
14016 intel_primary_formats
, num_formats
,
14017 DRM_PLANE_TYPE_PRIMARY
, NULL
);
14021 if (INTEL_INFO(dev
)->gen
>= 4)
14022 intel_create_rotation_property(dev
, primary
);
14024 drm_plane_helper_add(&primary
->base
, &intel_plane_helper_funcs
);
14026 return &primary
->base
;
14035 void intel_create_rotation_property(struct drm_device
*dev
, struct intel_plane
*plane
)
14037 if (!dev
->mode_config
.rotation_property
) {
14038 unsigned long flags
= BIT(DRM_ROTATE_0
) |
14039 BIT(DRM_ROTATE_180
);
14041 if (INTEL_INFO(dev
)->gen
>= 9)
14042 flags
|= BIT(DRM_ROTATE_90
) | BIT(DRM_ROTATE_270
);
14044 dev
->mode_config
.rotation_property
=
14045 drm_mode_create_rotation_property(dev
, flags
);
14047 if (dev
->mode_config
.rotation_property
)
14048 drm_object_attach_property(&plane
->base
.base
,
14049 dev
->mode_config
.rotation_property
,
14050 plane
->base
.state
->rotation
);
14054 intel_check_cursor_plane(struct drm_plane
*plane
,
14055 struct intel_crtc_state
*crtc_state
,
14056 struct intel_plane_state
*state
)
14058 struct drm_crtc
*crtc
= crtc_state
->base
.crtc
;
14059 struct drm_framebuffer
*fb
= state
->base
.fb
;
14060 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
14061 enum pipe pipe
= to_intel_plane(plane
)->pipe
;
14065 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
, &state
->src
,
14066 &state
->dst
, &state
->clip
,
14067 DRM_PLANE_HELPER_NO_SCALING
,
14068 DRM_PLANE_HELPER_NO_SCALING
,
14069 true, true, &state
->visible
);
14073 /* if we want to turn off the cursor ignore width and height */
14077 /* Check for which cursor types we support */
14078 if (!cursor_size_ok(plane
->dev
, state
->base
.crtc_w
, state
->base
.crtc_h
)) {
14079 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
14080 state
->base
.crtc_w
, state
->base
.crtc_h
);
14084 stride
= roundup_pow_of_two(state
->base
.crtc_w
) * 4;
14085 if (obj
->base
.size
< stride
* state
->base
.crtc_h
) {
14086 DRM_DEBUG_KMS("buffer is too small\n");
14090 if (fb
->modifier
[0] != DRM_FORMAT_MOD_NONE
) {
14091 DRM_DEBUG_KMS("cursor cannot be tiled\n");
14096 * There's something wrong with the cursor on CHV pipe C.
14097 * If it straddles the left edge of the screen then
14098 * moving it away from the edge or disabling it often
14099 * results in a pipe underrun, and often that can lead to
14100 * dead pipe (constant underrun reported, and it scans
14101 * out just a solid color). To recover from that, the
14102 * display power well must be turned off and on again.
14103 * Refuse the put the cursor into that compromised position.
14105 if (IS_CHERRYVIEW(plane
->dev
) && pipe
== PIPE_C
&&
14106 state
->visible
&& state
->base
.crtc_x
< 0) {
14107 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
14115 intel_disable_cursor_plane(struct drm_plane
*plane
,
14116 struct drm_crtc
*crtc
)
14118 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
14120 intel_crtc
->cursor_addr
= 0;
14121 intel_crtc_update_cursor(crtc
, NULL
);
14125 intel_update_cursor_plane(struct drm_plane
*plane
,
14126 const struct intel_crtc_state
*crtc_state
,
14127 const struct intel_plane_state
*state
)
14129 struct drm_crtc
*crtc
= crtc_state
->base
.crtc
;
14130 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
14131 struct drm_device
*dev
= plane
->dev
;
14132 struct drm_i915_gem_object
*obj
= intel_fb_obj(state
->base
.fb
);
14137 else if (!INTEL_INFO(dev
)->cursor_needs_physical
)
14138 addr
= i915_gem_obj_ggtt_offset(obj
);
14140 addr
= obj
->phys_handle
->busaddr
;
14142 intel_crtc
->cursor_addr
= addr
;
14143 intel_crtc_update_cursor(crtc
, state
);
14146 static struct drm_plane
*intel_cursor_plane_create(struct drm_device
*dev
,
14149 struct intel_plane
*cursor
= NULL
;
14150 struct intel_plane_state
*state
= NULL
;
14153 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
14157 state
= intel_create_plane_state(&cursor
->base
);
14160 cursor
->base
.state
= &state
->base
;
14162 cursor
->can_scale
= false;
14163 cursor
->max_downscale
= 1;
14164 cursor
->pipe
= pipe
;
14165 cursor
->plane
= pipe
;
14166 cursor
->frontbuffer_bit
= INTEL_FRONTBUFFER_CURSOR(pipe
);
14167 cursor
->check_plane
= intel_check_cursor_plane
;
14168 cursor
->update_plane
= intel_update_cursor_plane
;
14169 cursor
->disable_plane
= intel_disable_cursor_plane
;
14171 ret
= drm_universal_plane_init(dev
, &cursor
->base
, 0,
14172 &intel_plane_funcs
,
14173 intel_cursor_formats
,
14174 ARRAY_SIZE(intel_cursor_formats
),
14175 DRM_PLANE_TYPE_CURSOR
, NULL
);
14179 if (INTEL_INFO(dev
)->gen
>= 4) {
14180 if (!dev
->mode_config
.rotation_property
)
14181 dev
->mode_config
.rotation_property
=
14182 drm_mode_create_rotation_property(dev
,
14183 BIT(DRM_ROTATE_0
) |
14184 BIT(DRM_ROTATE_180
));
14185 if (dev
->mode_config
.rotation_property
)
14186 drm_object_attach_property(&cursor
->base
.base
,
14187 dev
->mode_config
.rotation_property
,
14188 state
->base
.rotation
);
14191 if (INTEL_INFO(dev
)->gen
>=9)
14192 state
->scaler_id
= -1;
14194 drm_plane_helper_add(&cursor
->base
, &intel_plane_helper_funcs
);
14196 return &cursor
->base
;
14205 static void skl_init_scalers(struct drm_device
*dev
, struct intel_crtc
*intel_crtc
,
14206 struct intel_crtc_state
*crtc_state
)
14209 struct intel_scaler
*intel_scaler
;
14210 struct intel_crtc_scaler_state
*scaler_state
= &crtc_state
->scaler_state
;
14212 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
14213 intel_scaler
= &scaler_state
->scalers
[i
];
14214 intel_scaler
->in_use
= 0;
14215 intel_scaler
->mode
= PS_SCALER_MODE_DYN
;
14218 scaler_state
->scaler_id
= -1;
14221 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
14223 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14224 struct intel_crtc
*intel_crtc
;
14225 struct intel_crtc_state
*crtc_state
= NULL
;
14226 struct drm_plane
*primary
= NULL
;
14227 struct drm_plane
*cursor
= NULL
;
14230 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
14231 if (intel_crtc
== NULL
)
14234 crtc_state
= kzalloc(sizeof(*crtc_state
), GFP_KERNEL
);
14237 intel_crtc
->config
= crtc_state
;
14238 intel_crtc
->base
.state
= &crtc_state
->base
;
14239 crtc_state
->base
.crtc
= &intel_crtc
->base
;
14241 /* initialize shared scalers */
14242 if (INTEL_INFO(dev
)->gen
>= 9) {
14243 if (pipe
== PIPE_C
)
14244 intel_crtc
->num_scalers
= 1;
14246 intel_crtc
->num_scalers
= SKL_NUM_SCALERS
;
14248 skl_init_scalers(dev
, intel_crtc
, crtc_state
);
14251 primary
= intel_primary_plane_create(dev
, pipe
);
14255 cursor
= intel_cursor_plane_create(dev
, pipe
);
14259 ret
= drm_crtc_init_with_planes(dev
, &intel_crtc
->base
, primary
,
14260 cursor
, &intel_crtc_funcs
, NULL
);
14265 * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
14266 * is hooked to pipe B. Hence we want plane A feeding pipe B.
14268 intel_crtc
->pipe
= pipe
;
14269 intel_crtc
->plane
= pipe
;
14270 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4) {
14271 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
14272 intel_crtc
->plane
= !pipe
;
14275 intel_crtc
->cursor_base
= ~0;
14276 intel_crtc
->cursor_cntl
= ~0;
14277 intel_crtc
->cursor_size
= ~0;
14279 intel_crtc
->wm
.cxsr_allowed
= true;
14281 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
14282 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
14283 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
14284 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
14286 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
14288 intel_color_init(&intel_crtc
->base
);
14290 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
14295 drm_plane_cleanup(primary
);
14297 drm_plane_cleanup(cursor
);
14302 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
14304 struct drm_encoder
*encoder
= connector
->base
.encoder
;
14305 struct drm_device
*dev
= connector
->base
.dev
;
14307 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
14309 if (!encoder
|| WARN_ON(!encoder
->crtc
))
14310 return INVALID_PIPE
;
14312 return to_intel_crtc(encoder
->crtc
)->pipe
;
14315 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
14316 struct drm_file
*file
)
14318 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
14319 struct drm_crtc
*drmmode_crtc
;
14320 struct intel_crtc
*crtc
;
14322 drmmode_crtc
= drm_crtc_find(dev
, pipe_from_crtc_id
->crtc_id
);
14324 if (!drmmode_crtc
) {
14325 DRM_ERROR("no such CRTC id\n");
14329 crtc
= to_intel_crtc(drmmode_crtc
);
14330 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
14335 static int intel_encoder_clones(struct intel_encoder
*encoder
)
14337 struct drm_device
*dev
= encoder
->base
.dev
;
14338 struct intel_encoder
*source_encoder
;
14339 int index_mask
= 0;
14342 for_each_intel_encoder(dev
, source_encoder
) {
14343 if (encoders_cloneable(encoder
, source_encoder
))
14344 index_mask
|= (1 << entry
);
14352 static bool has_edp_a(struct drm_device
*dev
)
14354 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14356 if (!IS_MOBILE(dev
))
14359 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
14362 if (IS_GEN5(dev
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
14368 static bool intel_crt_present(struct drm_device
*dev
)
14370 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14372 if (INTEL_INFO(dev
)->gen
>= 9)
14375 if (IS_HSW_ULT(dev
) || IS_BDW_ULT(dev
))
14378 if (IS_CHERRYVIEW(dev
))
14381 if (HAS_PCH_LPT_H(dev
) && I915_READ(SFUSE_STRAP
) & SFUSE_STRAP_CRT_DISABLED
)
14384 /* DDI E can't be used if DDI A requires 4 lanes */
14385 if (HAS_DDI(dev
) && I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_A_4_LANES
)
14388 if (!dev_priv
->vbt
.int_crt_support
)
14394 static void intel_setup_outputs(struct drm_device
*dev
)
14396 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14397 struct intel_encoder
*encoder
;
14398 bool dpd_is_edp
= false;
14400 intel_lvds_init(dev
);
14402 if (intel_crt_present(dev
))
14403 intel_crt_init(dev
);
14405 if (IS_BROXTON(dev
)) {
14407 * FIXME: Broxton doesn't support port detection via the
14408 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
14409 * detect the ports.
14411 intel_ddi_init(dev
, PORT_A
);
14412 intel_ddi_init(dev
, PORT_B
);
14413 intel_ddi_init(dev
, PORT_C
);
14415 intel_dsi_init(dev
);
14416 } else if (HAS_DDI(dev
)) {
14420 * Haswell uses DDI functions to detect digital outputs.
14421 * On SKL pre-D0 the strap isn't connected, so we assume
14424 found
= I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_INIT_DISPLAY_DETECTED
;
14425 /* WaIgnoreDDIAStrap: skl */
14426 if (found
|| IS_SKYLAKE(dev
) || IS_KABYLAKE(dev
))
14427 intel_ddi_init(dev
, PORT_A
);
14429 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
14431 found
= I915_READ(SFUSE_STRAP
);
14433 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
14434 intel_ddi_init(dev
, PORT_B
);
14435 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
14436 intel_ddi_init(dev
, PORT_C
);
14437 if (found
& SFUSE_STRAP_DDID_DETECTED
)
14438 intel_ddi_init(dev
, PORT_D
);
14440 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14442 if ((IS_SKYLAKE(dev
) || IS_KABYLAKE(dev
)) &&
14443 (dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dp
||
14444 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dvi
||
14445 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_hdmi
))
14446 intel_ddi_init(dev
, PORT_E
);
14448 } else if (HAS_PCH_SPLIT(dev
)) {
14450 dpd_is_edp
= intel_dp_is_edp(dev
, PORT_D
);
14452 if (has_edp_a(dev
))
14453 intel_dp_init(dev
, DP_A
, PORT_A
);
14455 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
14456 /* PCH SDVOB multiplex with HDMIB */
14457 found
= intel_sdvo_init(dev
, PCH_SDVOB
, PORT_B
);
14459 intel_hdmi_init(dev
, PCH_HDMIB
, PORT_B
);
14460 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
14461 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
14464 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
14465 intel_hdmi_init(dev
, PCH_HDMIC
, PORT_C
);
14467 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
14468 intel_hdmi_init(dev
, PCH_HDMID
, PORT_D
);
14470 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
14471 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
14473 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
14474 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
14475 } else if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
14477 * The DP_DETECTED bit is the latched state of the DDC
14478 * SDA pin at boot. However since eDP doesn't require DDC
14479 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14480 * eDP ports may have been muxed to an alternate function.
14481 * Thus we can't rely on the DP_DETECTED bit alone to detect
14482 * eDP ports. Consult the VBT as well as DP_DETECTED to
14483 * detect eDP ports.
14485 if (I915_READ(VLV_HDMIB
) & SDVO_DETECTED
&&
14486 !intel_dp_is_edp(dev
, PORT_B
))
14487 intel_hdmi_init(dev
, VLV_HDMIB
, PORT_B
);
14488 if (I915_READ(VLV_DP_B
) & DP_DETECTED
||
14489 intel_dp_is_edp(dev
, PORT_B
))
14490 intel_dp_init(dev
, VLV_DP_B
, PORT_B
);
14492 if (I915_READ(VLV_HDMIC
) & SDVO_DETECTED
&&
14493 !intel_dp_is_edp(dev
, PORT_C
))
14494 intel_hdmi_init(dev
, VLV_HDMIC
, PORT_C
);
14495 if (I915_READ(VLV_DP_C
) & DP_DETECTED
||
14496 intel_dp_is_edp(dev
, PORT_C
))
14497 intel_dp_init(dev
, VLV_DP_C
, PORT_C
);
14499 if (IS_CHERRYVIEW(dev
)) {
14500 /* eDP not supported on port D, so don't check VBT */
14501 if (I915_READ(CHV_HDMID
) & SDVO_DETECTED
)
14502 intel_hdmi_init(dev
, CHV_HDMID
, PORT_D
);
14503 if (I915_READ(CHV_DP_D
) & DP_DETECTED
)
14504 intel_dp_init(dev
, CHV_DP_D
, PORT_D
);
14507 intel_dsi_init(dev
);
14508 } else if (!IS_GEN2(dev
) && !IS_PINEVIEW(dev
)) {
14509 bool found
= false;
14511 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
14512 DRM_DEBUG_KMS("probing SDVOB\n");
14513 found
= intel_sdvo_init(dev
, GEN3_SDVOB
, PORT_B
);
14514 if (!found
&& IS_G4X(dev
)) {
14515 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
14516 intel_hdmi_init(dev
, GEN4_HDMIB
, PORT_B
);
14519 if (!found
&& IS_G4X(dev
))
14520 intel_dp_init(dev
, DP_B
, PORT_B
);
14523 /* Before G4X SDVOC doesn't have its own detect register */
14525 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
14526 DRM_DEBUG_KMS("probing SDVOC\n");
14527 found
= intel_sdvo_init(dev
, GEN3_SDVOC
, PORT_C
);
14530 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
14533 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
14534 intel_hdmi_init(dev
, GEN4_HDMIC
, PORT_C
);
14537 intel_dp_init(dev
, DP_C
, PORT_C
);
14541 (I915_READ(DP_D
) & DP_DETECTED
))
14542 intel_dp_init(dev
, DP_D
, PORT_D
);
14543 } else if (IS_GEN2(dev
))
14544 intel_dvo_init(dev
);
14546 if (SUPPORTS_TV(dev
))
14547 intel_tv_init(dev
);
14549 intel_psr_init(dev
);
14551 for_each_intel_encoder(dev
, encoder
) {
14552 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
14553 encoder
->base
.possible_clones
=
14554 intel_encoder_clones(encoder
);
14557 intel_init_pch_refclk(dev
);
14559 drm_helper_move_panel_connectors_to_head(dev
);
14562 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
14564 struct drm_device
*dev
= fb
->dev
;
14565 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
14567 drm_framebuffer_cleanup(fb
);
14568 mutex_lock(&dev
->struct_mutex
);
14569 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
14570 drm_gem_object_unreference(&intel_fb
->obj
->base
);
14571 mutex_unlock(&dev
->struct_mutex
);
14575 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
14576 struct drm_file
*file
,
14577 unsigned int *handle
)
14579 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
14580 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
14582 if (obj
->userptr
.mm
) {
14583 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14587 return drm_gem_handle_create(file
, &obj
->base
, handle
);
14590 static int intel_user_framebuffer_dirty(struct drm_framebuffer
*fb
,
14591 struct drm_file
*file
,
14592 unsigned flags
, unsigned color
,
14593 struct drm_clip_rect
*clips
,
14594 unsigned num_clips
)
14596 struct drm_device
*dev
= fb
->dev
;
14597 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
14598 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
14600 mutex_lock(&dev
->struct_mutex
);
14601 intel_fb_obj_flush(obj
, false, ORIGIN_DIRTYFB
);
14602 mutex_unlock(&dev
->struct_mutex
);
14607 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
14608 .destroy
= intel_user_framebuffer_destroy
,
14609 .create_handle
= intel_user_framebuffer_create_handle
,
14610 .dirty
= intel_user_framebuffer_dirty
,
14614 u32
intel_fb_pitch_limit(struct drm_device
*dev
, uint64_t fb_modifier
,
14615 uint32_t pixel_format
)
14617 u32 gen
= INTEL_INFO(dev
)->gen
;
14620 int cpp
= drm_format_plane_cpp(pixel_format
, 0);
14622 /* "The stride in bytes must not exceed the of the size of 8K
14623 * pixels and 32K bytes."
14625 return min(8192 * cpp
, 32768);
14626 } else if (gen
>= 5 && !IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
)) {
14628 } else if (gen
>= 4) {
14629 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
14633 } else if (gen
>= 3) {
14634 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
14639 /* XXX DSPC is limited to 4k tiled */
14644 static int intel_framebuffer_init(struct drm_device
*dev
,
14645 struct intel_framebuffer
*intel_fb
,
14646 struct drm_mode_fb_cmd2
*mode_cmd
,
14647 struct drm_i915_gem_object
*obj
)
14649 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14650 unsigned int aligned_height
;
14652 u32 pitch_limit
, stride_alignment
;
14654 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
14656 if (mode_cmd
->flags
& DRM_MODE_FB_MODIFIERS
) {
14657 /* Enforce that fb modifier and tiling mode match, but only for
14658 * X-tiled. This is needed for FBC. */
14659 if (!!(obj
->tiling_mode
== I915_TILING_X
) !=
14660 !!(mode_cmd
->modifier
[0] == I915_FORMAT_MOD_X_TILED
)) {
14661 DRM_DEBUG("tiling_mode doesn't match fb modifier\n");
14665 if (obj
->tiling_mode
== I915_TILING_X
)
14666 mode_cmd
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
14667 else if (obj
->tiling_mode
== I915_TILING_Y
) {
14668 DRM_DEBUG("No Y tiling for legacy addfb\n");
14673 /* Passed in modifier sanity checking. */
14674 switch (mode_cmd
->modifier
[0]) {
14675 case I915_FORMAT_MOD_Y_TILED
:
14676 case I915_FORMAT_MOD_Yf_TILED
:
14677 if (INTEL_INFO(dev
)->gen
< 9) {
14678 DRM_DEBUG("Unsupported tiling 0x%llx!\n",
14679 mode_cmd
->modifier
[0]);
14682 case DRM_FORMAT_MOD_NONE
:
14683 case I915_FORMAT_MOD_X_TILED
:
14686 DRM_DEBUG("Unsupported fb modifier 0x%llx!\n",
14687 mode_cmd
->modifier
[0]);
14691 stride_alignment
= intel_fb_stride_alignment(dev_priv
,
14692 mode_cmd
->modifier
[0],
14693 mode_cmd
->pixel_format
);
14694 if (mode_cmd
->pitches
[0] & (stride_alignment
- 1)) {
14695 DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n",
14696 mode_cmd
->pitches
[0], stride_alignment
);
14700 pitch_limit
= intel_fb_pitch_limit(dev
, mode_cmd
->modifier
[0],
14701 mode_cmd
->pixel_format
);
14702 if (mode_cmd
->pitches
[0] > pitch_limit
) {
14703 DRM_DEBUG("%s pitch (%u) must be at less than %d\n",
14704 mode_cmd
->modifier
[0] != DRM_FORMAT_MOD_NONE
?
14705 "tiled" : "linear",
14706 mode_cmd
->pitches
[0], pitch_limit
);
14710 if (mode_cmd
->modifier
[0] == I915_FORMAT_MOD_X_TILED
&&
14711 mode_cmd
->pitches
[0] != obj
->stride
) {
14712 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
14713 mode_cmd
->pitches
[0], obj
->stride
);
14717 /* Reject formats not supported by any plane early. */
14718 switch (mode_cmd
->pixel_format
) {
14719 case DRM_FORMAT_C8
:
14720 case DRM_FORMAT_RGB565
:
14721 case DRM_FORMAT_XRGB8888
:
14722 case DRM_FORMAT_ARGB8888
:
14724 case DRM_FORMAT_XRGB1555
:
14725 if (INTEL_INFO(dev
)->gen
> 3) {
14726 DRM_DEBUG("unsupported pixel format: %s\n",
14727 drm_get_format_name(mode_cmd
->pixel_format
));
14731 case DRM_FORMAT_ABGR8888
:
14732 if (!IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
) &&
14733 INTEL_INFO(dev
)->gen
< 9) {
14734 DRM_DEBUG("unsupported pixel format: %s\n",
14735 drm_get_format_name(mode_cmd
->pixel_format
));
14739 case DRM_FORMAT_XBGR8888
:
14740 case DRM_FORMAT_XRGB2101010
:
14741 case DRM_FORMAT_XBGR2101010
:
14742 if (INTEL_INFO(dev
)->gen
< 4) {
14743 DRM_DEBUG("unsupported pixel format: %s\n",
14744 drm_get_format_name(mode_cmd
->pixel_format
));
14748 case DRM_FORMAT_ABGR2101010
:
14749 if (!IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
)) {
14750 DRM_DEBUG("unsupported pixel format: %s\n",
14751 drm_get_format_name(mode_cmd
->pixel_format
));
14755 case DRM_FORMAT_YUYV
:
14756 case DRM_FORMAT_UYVY
:
14757 case DRM_FORMAT_YVYU
:
14758 case DRM_FORMAT_VYUY
:
14759 if (INTEL_INFO(dev
)->gen
< 5) {
14760 DRM_DEBUG("unsupported pixel format: %s\n",
14761 drm_get_format_name(mode_cmd
->pixel_format
));
14766 DRM_DEBUG("unsupported pixel format: %s\n",
14767 drm_get_format_name(mode_cmd
->pixel_format
));
14771 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14772 if (mode_cmd
->offsets
[0] != 0)
14775 aligned_height
= intel_fb_align_height(dev
, mode_cmd
->height
,
14776 mode_cmd
->pixel_format
,
14777 mode_cmd
->modifier
[0]);
14778 /* FIXME drm helper for size checks (especially planar formats)? */
14779 if (obj
->base
.size
< aligned_height
* mode_cmd
->pitches
[0])
14782 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
14783 intel_fb
->obj
= obj
;
14785 intel_fill_fb_info(dev_priv
, &intel_fb
->base
);
14787 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
14789 DRM_ERROR("framebuffer init failed %d\n", ret
);
14793 intel_fb
->obj
->framebuffer_references
++;
14798 static struct drm_framebuffer
*
14799 intel_user_framebuffer_create(struct drm_device
*dev
,
14800 struct drm_file
*filp
,
14801 const struct drm_mode_fb_cmd2
*user_mode_cmd
)
14803 struct drm_framebuffer
*fb
;
14804 struct drm_i915_gem_object
*obj
;
14805 struct drm_mode_fb_cmd2 mode_cmd
= *user_mode_cmd
;
14807 obj
= to_intel_bo(drm_gem_object_lookup(dev
, filp
,
14808 mode_cmd
.handles
[0]));
14809 if (&obj
->base
== NULL
)
14810 return ERR_PTR(-ENOENT
);
14812 fb
= intel_framebuffer_create(dev
, &mode_cmd
, obj
);
14814 drm_gem_object_unreference_unlocked(&obj
->base
);
14819 #ifndef CONFIG_DRM_FBDEV_EMULATION
14820 static inline void intel_fbdev_output_poll_changed(struct drm_device
*dev
)
14825 static const struct drm_mode_config_funcs intel_mode_funcs
= {
14826 .fb_create
= intel_user_framebuffer_create
,
14827 .output_poll_changed
= intel_fbdev_output_poll_changed
,
14828 .atomic_check
= intel_atomic_check
,
14829 .atomic_commit
= intel_atomic_commit
,
14830 .atomic_state_alloc
= intel_atomic_state_alloc
,
14831 .atomic_state_clear
= intel_atomic_state_clear
,
14835 * intel_init_display_hooks - initialize the display modesetting hooks
14836 * @dev_priv: device private
14838 void intel_init_display_hooks(struct drm_i915_private
*dev_priv
)
14840 if (INTEL_INFO(dev_priv
)->gen
>= 9) {
14841 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
14842 dev_priv
->display
.get_initial_plane_config
=
14843 skylake_get_initial_plane_config
;
14844 dev_priv
->display
.crtc_compute_clock
=
14845 haswell_crtc_compute_clock
;
14846 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
14847 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
14848 } else if (HAS_DDI(dev_priv
)) {
14849 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
14850 dev_priv
->display
.get_initial_plane_config
=
14851 ironlake_get_initial_plane_config
;
14852 dev_priv
->display
.crtc_compute_clock
=
14853 haswell_crtc_compute_clock
;
14854 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
14855 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
14856 } else if (HAS_PCH_SPLIT(dev_priv
)) {
14857 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
14858 dev_priv
->display
.get_initial_plane_config
=
14859 ironlake_get_initial_plane_config
;
14860 dev_priv
->display
.crtc_compute_clock
=
14861 ironlake_crtc_compute_clock
;
14862 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
14863 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
14864 } else if (IS_CHERRYVIEW(dev_priv
)) {
14865 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14866 dev_priv
->display
.get_initial_plane_config
=
14867 i9xx_get_initial_plane_config
;
14868 dev_priv
->display
.crtc_compute_clock
= chv_crtc_compute_clock
;
14869 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
14870 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14871 } else if (IS_VALLEYVIEW(dev_priv
)) {
14872 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14873 dev_priv
->display
.get_initial_plane_config
=
14874 i9xx_get_initial_plane_config
;
14875 dev_priv
->display
.crtc_compute_clock
= vlv_crtc_compute_clock
;
14876 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
14877 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14878 } else if (IS_G4X(dev_priv
)) {
14879 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14880 dev_priv
->display
.get_initial_plane_config
=
14881 i9xx_get_initial_plane_config
;
14882 dev_priv
->display
.crtc_compute_clock
= g4x_crtc_compute_clock
;
14883 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14884 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14885 } else if (IS_PINEVIEW(dev_priv
)) {
14886 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14887 dev_priv
->display
.get_initial_plane_config
=
14888 i9xx_get_initial_plane_config
;
14889 dev_priv
->display
.crtc_compute_clock
= pnv_crtc_compute_clock
;
14890 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14891 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14892 } else if (!IS_GEN2(dev_priv
)) {
14893 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14894 dev_priv
->display
.get_initial_plane_config
=
14895 i9xx_get_initial_plane_config
;
14896 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
14897 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14898 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14900 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14901 dev_priv
->display
.get_initial_plane_config
=
14902 i9xx_get_initial_plane_config
;
14903 dev_priv
->display
.crtc_compute_clock
= i8xx_crtc_compute_clock
;
14904 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14905 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14908 /* Returns the core display clock speed */
14909 if (IS_SKYLAKE(dev_priv
) || IS_KABYLAKE(dev_priv
))
14910 dev_priv
->display
.get_display_clock_speed
=
14911 skylake_get_display_clock_speed
;
14912 else if (IS_BROXTON(dev_priv
))
14913 dev_priv
->display
.get_display_clock_speed
=
14914 broxton_get_display_clock_speed
;
14915 else if (IS_BROADWELL(dev_priv
))
14916 dev_priv
->display
.get_display_clock_speed
=
14917 broadwell_get_display_clock_speed
;
14918 else if (IS_HASWELL(dev_priv
))
14919 dev_priv
->display
.get_display_clock_speed
=
14920 haswell_get_display_clock_speed
;
14921 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
14922 dev_priv
->display
.get_display_clock_speed
=
14923 valleyview_get_display_clock_speed
;
14924 else if (IS_GEN5(dev_priv
))
14925 dev_priv
->display
.get_display_clock_speed
=
14926 ilk_get_display_clock_speed
;
14927 else if (IS_I945G(dev_priv
) || IS_BROADWATER(dev_priv
) ||
14928 IS_GEN6(dev_priv
) || IS_IVYBRIDGE(dev_priv
))
14929 dev_priv
->display
.get_display_clock_speed
=
14930 i945_get_display_clock_speed
;
14931 else if (IS_GM45(dev_priv
))
14932 dev_priv
->display
.get_display_clock_speed
=
14933 gm45_get_display_clock_speed
;
14934 else if (IS_CRESTLINE(dev_priv
))
14935 dev_priv
->display
.get_display_clock_speed
=
14936 i965gm_get_display_clock_speed
;
14937 else if (IS_PINEVIEW(dev_priv
))
14938 dev_priv
->display
.get_display_clock_speed
=
14939 pnv_get_display_clock_speed
;
14940 else if (IS_G33(dev_priv
) || IS_G4X(dev_priv
))
14941 dev_priv
->display
.get_display_clock_speed
=
14942 g33_get_display_clock_speed
;
14943 else if (IS_I915G(dev_priv
))
14944 dev_priv
->display
.get_display_clock_speed
=
14945 i915_get_display_clock_speed
;
14946 else if (IS_I945GM(dev_priv
) || IS_845G(dev_priv
))
14947 dev_priv
->display
.get_display_clock_speed
=
14948 i9xx_misc_get_display_clock_speed
;
14949 else if (IS_I915GM(dev_priv
))
14950 dev_priv
->display
.get_display_clock_speed
=
14951 i915gm_get_display_clock_speed
;
14952 else if (IS_I865G(dev_priv
))
14953 dev_priv
->display
.get_display_clock_speed
=
14954 i865_get_display_clock_speed
;
14955 else if (IS_I85X(dev_priv
))
14956 dev_priv
->display
.get_display_clock_speed
=
14957 i85x_get_display_clock_speed
;
14959 WARN(!IS_I830(dev_priv
), "Unknown platform. Assuming 133 MHz CDCLK\n");
14960 dev_priv
->display
.get_display_clock_speed
=
14961 i830_get_display_clock_speed
;
14964 if (IS_GEN5(dev_priv
)) {
14965 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
14966 } else if (IS_GEN6(dev_priv
)) {
14967 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
14968 } else if (IS_IVYBRIDGE(dev_priv
)) {
14969 /* FIXME: detect B0+ stepping and use auto training */
14970 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
14971 } else if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
14972 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
14975 if (IS_BROADWELL(dev_priv
)) {
14976 dev_priv
->display
.modeset_commit_cdclk
=
14977 broadwell_modeset_commit_cdclk
;
14978 dev_priv
->display
.modeset_calc_cdclk
=
14979 broadwell_modeset_calc_cdclk
;
14980 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
14981 dev_priv
->display
.modeset_commit_cdclk
=
14982 valleyview_modeset_commit_cdclk
;
14983 dev_priv
->display
.modeset_calc_cdclk
=
14984 valleyview_modeset_calc_cdclk
;
14985 } else if (IS_BROXTON(dev_priv
)) {
14986 dev_priv
->display
.modeset_commit_cdclk
=
14987 broxton_modeset_commit_cdclk
;
14988 dev_priv
->display
.modeset_calc_cdclk
=
14989 broxton_modeset_calc_cdclk
;
14992 switch (INTEL_INFO(dev_priv
)->gen
) {
14994 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
14998 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
15003 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
15007 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
15010 case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
15011 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
15014 /* Drop through - unsupported since execlist only. */
15016 /* Default just returns -ENODEV to indicate unsupported */
15017 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
15022 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
15023 * resume, or other times. This quirk makes sure that's the case for
15024 * affected systems.
15026 static void quirk_pipea_force(struct drm_device
*dev
)
15028 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15030 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
15031 DRM_INFO("applying pipe a force quirk\n");
15034 static void quirk_pipeb_force(struct drm_device
*dev
)
15036 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15038 dev_priv
->quirks
|= QUIRK_PIPEB_FORCE
;
15039 DRM_INFO("applying pipe b force quirk\n");
15043 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
15045 static void quirk_ssc_force_disable(struct drm_device
*dev
)
15047 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15048 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
15049 DRM_INFO("applying lvds SSC disable quirk\n");
15053 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
15056 static void quirk_invert_brightness(struct drm_device
*dev
)
15058 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15059 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
15060 DRM_INFO("applying inverted panel brightness quirk\n");
15063 /* Some VBT's incorrectly indicate no backlight is present */
15064 static void quirk_backlight_present(struct drm_device
*dev
)
15066 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15067 dev_priv
->quirks
|= QUIRK_BACKLIGHT_PRESENT
;
15068 DRM_INFO("applying backlight present quirk\n");
15071 struct intel_quirk
{
15073 int subsystem_vendor
;
15074 int subsystem_device
;
15075 void (*hook
)(struct drm_device
*dev
);
15078 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
15079 struct intel_dmi_quirk
{
15080 void (*hook
)(struct drm_device
*dev
);
15081 const struct dmi_system_id (*dmi_id_list
)[];
15084 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
15086 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
15090 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
15092 .dmi_id_list
= &(const struct dmi_system_id
[]) {
15094 .callback
= intel_dmi_reverse_brightness
,
15095 .ident
= "NCR Corporation",
15096 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
15097 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
15100 { } /* terminating entry */
15102 .hook
= quirk_invert_brightness
,
15106 static struct intel_quirk intel_quirks
[] = {
15107 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
15108 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
15110 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
15111 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
15113 /* 830 needs to leave pipe A & dpll A up */
15114 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
15116 /* 830 needs to leave pipe B & dpll B up */
15117 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipeb_force
},
15119 /* Lenovo U160 cannot use SSC on LVDS */
15120 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
15122 /* Sony Vaio Y cannot use SSC on LVDS */
15123 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
15125 /* Acer Aspire 5734Z must invert backlight brightness */
15126 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
15128 /* Acer/eMachines G725 */
15129 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
15131 /* Acer/eMachines e725 */
15132 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
15134 /* Acer/Packard Bell NCL20 */
15135 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
15137 /* Acer Aspire 4736Z */
15138 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
15140 /* Acer Aspire 5336 */
15141 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
15143 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
15144 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present
},
15146 /* Acer C720 Chromebook (Core i3 4005U) */
15147 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present
},
15149 /* Apple Macbook 2,1 (Core 2 T7400) */
15150 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present
},
15152 /* Apple Macbook 4,1 */
15153 { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present
},
15155 /* Toshiba CB35 Chromebook (Celeron 2955U) */
15156 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present
},
15158 /* HP Chromebook 14 (Celeron 2955U) */
15159 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present
},
15161 /* Dell Chromebook 11 */
15162 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present
},
15164 /* Dell Chromebook 11 (2015 version) */
15165 { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present
},
15168 static void intel_init_quirks(struct drm_device
*dev
)
15170 struct pci_dev
*d
= dev
->pdev
;
15173 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
15174 struct intel_quirk
*q
= &intel_quirks
[i
];
15176 if (d
->device
== q
->device
&&
15177 (d
->subsystem_vendor
== q
->subsystem_vendor
||
15178 q
->subsystem_vendor
== PCI_ANY_ID
) &&
15179 (d
->subsystem_device
== q
->subsystem_device
||
15180 q
->subsystem_device
== PCI_ANY_ID
))
15183 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
15184 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
15185 intel_dmi_quirks
[i
].hook(dev
);
15189 /* Disable the VGA plane that we never use */
15190 static void i915_disable_vga(struct drm_device
*dev
)
15192 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15194 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev
);
15196 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
15197 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
15198 outb(SR01
, VGA_SR_INDEX
);
15199 sr1
= inb(VGA_SR_DATA
);
15200 outb(sr1
| 1<<5, VGA_SR_DATA
);
15201 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
15204 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
15205 POSTING_READ(vga_reg
);
15208 void intel_modeset_init_hw(struct drm_device
*dev
)
15210 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15212 intel_update_cdclk(dev
);
15214 dev_priv
->atomic_cdclk_freq
= dev_priv
->cdclk_freq
;
15216 intel_init_clock_gating(dev
);
15217 intel_enable_gt_powersave(dev_priv
);
15221 * Calculate what we think the watermarks should be for the state we've read
15222 * out of the hardware and then immediately program those watermarks so that
15223 * we ensure the hardware settings match our internal state.
15225 * We can calculate what we think WM's should be by creating a duplicate of the
15226 * current state (which was constructed during hardware readout) and running it
15227 * through the atomic check code to calculate new watermark values in the
15230 static void sanitize_watermarks(struct drm_device
*dev
)
15232 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15233 struct drm_atomic_state
*state
;
15234 struct drm_crtc
*crtc
;
15235 struct drm_crtc_state
*cstate
;
15236 struct drm_modeset_acquire_ctx ctx
;
15240 /* Only supported on platforms that use atomic watermark design */
15241 if (!dev_priv
->display
.optimize_watermarks
)
15245 * We need to hold connection_mutex before calling duplicate_state so
15246 * that the connector loop is protected.
15248 drm_modeset_acquire_init(&ctx
, 0);
15250 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
15251 if (ret
== -EDEADLK
) {
15252 drm_modeset_backoff(&ctx
);
15254 } else if (WARN_ON(ret
)) {
15258 state
= drm_atomic_helper_duplicate_state(dev
, &ctx
);
15259 if (WARN_ON(IS_ERR(state
)))
15263 * Hardware readout is the only time we don't want to calculate
15264 * intermediate watermarks (since we don't trust the current
15267 to_intel_atomic_state(state
)->skip_intermediate_wm
= true;
15269 ret
= intel_atomic_check(dev
, state
);
15272 * If we fail here, it means that the hardware appears to be
15273 * programmed in a way that shouldn't be possible, given our
15274 * understanding of watermark requirements. This might mean a
15275 * mistake in the hardware readout code or a mistake in the
15276 * watermark calculations for a given platform. Raise a WARN
15277 * so that this is noticeable.
15279 * If this actually happens, we'll have to just leave the
15280 * BIOS-programmed watermarks untouched and hope for the best.
15282 WARN(true, "Could not determine valid watermarks for inherited state\n");
15286 /* Write calculated watermark values back */
15287 for_each_crtc_in_state(state
, crtc
, cstate
, i
) {
15288 struct intel_crtc_state
*cs
= to_intel_crtc_state(cstate
);
15290 cs
->wm
.need_postvbl_update
= true;
15291 dev_priv
->display
.optimize_watermarks(cs
);
15294 drm_atomic_state_free(state
);
15296 drm_modeset_drop_locks(&ctx
);
15297 drm_modeset_acquire_fini(&ctx
);
15300 void intel_modeset_init(struct drm_device
*dev
)
15302 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15303 struct i915_ggtt
*ggtt
= &dev_priv
->ggtt
;
15306 struct intel_crtc
*crtc
;
15308 drm_mode_config_init(dev
);
15310 dev
->mode_config
.min_width
= 0;
15311 dev
->mode_config
.min_height
= 0;
15313 dev
->mode_config
.preferred_depth
= 24;
15314 dev
->mode_config
.prefer_shadow
= 1;
15316 dev
->mode_config
.allow_fb_modifiers
= true;
15318 dev
->mode_config
.funcs
= &intel_mode_funcs
;
15320 intel_init_quirks(dev
);
15322 intel_init_pm(dev
);
15324 if (INTEL_INFO(dev
)->num_pipes
== 0)
15328 * There may be no VBT; and if the BIOS enabled SSC we can
15329 * just keep using it to avoid unnecessary flicker. Whereas if the
15330 * BIOS isn't using it, don't assume it will work even if the VBT
15331 * indicates as much.
15333 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)) {
15334 bool bios_lvds_use_ssc
= !!(I915_READ(PCH_DREF_CONTROL
) &
15337 if (dev_priv
->vbt
.lvds_use_ssc
!= bios_lvds_use_ssc
) {
15338 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
15339 bios_lvds_use_ssc
? "en" : "dis",
15340 dev_priv
->vbt
.lvds_use_ssc
? "en" : "dis");
15341 dev_priv
->vbt
.lvds_use_ssc
= bios_lvds_use_ssc
;
15345 if (IS_GEN2(dev
)) {
15346 dev
->mode_config
.max_width
= 2048;
15347 dev
->mode_config
.max_height
= 2048;
15348 } else if (IS_GEN3(dev
)) {
15349 dev
->mode_config
.max_width
= 4096;
15350 dev
->mode_config
.max_height
= 4096;
15352 dev
->mode_config
.max_width
= 8192;
15353 dev
->mode_config
.max_height
= 8192;
15356 if (IS_845G(dev
) || IS_I865G(dev
)) {
15357 dev
->mode_config
.cursor_width
= IS_845G(dev
) ? 64 : 512;
15358 dev
->mode_config
.cursor_height
= 1023;
15359 } else if (IS_GEN2(dev
)) {
15360 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
15361 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
15363 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
15364 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
15367 dev
->mode_config
.fb_base
= ggtt
->mappable_base
;
15369 DRM_DEBUG_KMS("%d display pipe%s available.\n",
15370 INTEL_INFO(dev
)->num_pipes
,
15371 INTEL_INFO(dev
)->num_pipes
> 1 ? "s" : "");
15373 for_each_pipe(dev_priv
, pipe
) {
15374 intel_crtc_init(dev
, pipe
);
15375 for_each_sprite(dev_priv
, pipe
, sprite
) {
15376 ret
= intel_plane_init(dev
, pipe
, sprite
);
15378 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
15379 pipe_name(pipe
), sprite_name(pipe
, sprite
), ret
);
15383 intel_update_czclk(dev_priv
);
15384 intel_update_cdclk(dev
);
15386 intel_shared_dpll_init(dev
);
15388 /* Just disable it once at startup */
15389 i915_disable_vga(dev
);
15390 intel_setup_outputs(dev
);
15392 drm_modeset_lock_all(dev
);
15393 intel_modeset_setup_hw_state(dev
);
15394 drm_modeset_unlock_all(dev
);
15396 for_each_intel_crtc(dev
, crtc
) {
15397 struct intel_initial_plane_config plane_config
= {};
15403 * Note that reserving the BIOS fb up front prevents us
15404 * from stuffing other stolen allocations like the ring
15405 * on top. This prevents some ugliness at boot time, and
15406 * can even allow for smooth boot transitions if the BIOS
15407 * fb is large enough for the active pipe configuration.
15409 dev_priv
->display
.get_initial_plane_config(crtc
,
15413 * If the fb is shared between multiple heads, we'll
15414 * just get the first one.
15416 intel_find_initial_plane_obj(crtc
, &plane_config
);
15420 * Make sure hardware watermarks really match the state we read out.
15421 * Note that we need to do this after reconstructing the BIOS fb's
15422 * since the watermark calculation done here will use pstate->fb.
15424 sanitize_watermarks(dev
);
15427 static void intel_enable_pipe_a(struct drm_device
*dev
)
15429 struct intel_connector
*connector
;
15430 struct drm_connector
*crt
= NULL
;
15431 struct intel_load_detect_pipe load_detect_temp
;
15432 struct drm_modeset_acquire_ctx
*ctx
= dev
->mode_config
.acquire_ctx
;
15434 /* We can't just switch on the pipe A, we need to set things up with a
15435 * proper mode and output configuration. As a gross hack, enable pipe A
15436 * by enabling the load detect pipe once. */
15437 for_each_intel_connector(dev
, connector
) {
15438 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
15439 crt
= &connector
->base
;
15447 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
, ctx
))
15448 intel_release_load_detect_pipe(crt
, &load_detect_temp
, ctx
);
15452 intel_check_plane_mapping(struct intel_crtc
*crtc
)
15454 struct drm_device
*dev
= crtc
->base
.dev
;
15455 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15458 if (INTEL_INFO(dev
)->num_pipes
== 1)
15461 val
= I915_READ(DSPCNTR(!crtc
->plane
));
15463 if ((val
& DISPLAY_PLANE_ENABLE
) &&
15464 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
15470 static bool intel_crtc_has_encoders(struct intel_crtc
*crtc
)
15472 struct drm_device
*dev
= crtc
->base
.dev
;
15473 struct intel_encoder
*encoder
;
15475 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
15481 static bool intel_encoder_has_connectors(struct intel_encoder
*encoder
)
15483 struct drm_device
*dev
= encoder
->base
.dev
;
15484 struct intel_connector
*connector
;
15486 for_each_connector_on_encoder(dev
, &encoder
->base
, connector
)
15492 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
15494 struct drm_device
*dev
= crtc
->base
.dev
;
15495 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15496 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
15498 /* Clear any frame start delays used for debugging left by the BIOS */
15499 if (!transcoder_is_dsi(cpu_transcoder
)) {
15500 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
15503 I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
15506 /* restore vblank interrupts to correct state */
15507 drm_crtc_vblank_reset(&crtc
->base
);
15508 if (crtc
->active
) {
15509 struct intel_plane
*plane
;
15511 drm_crtc_vblank_on(&crtc
->base
);
15513 /* Disable everything but the primary plane */
15514 for_each_intel_plane_on_crtc(dev
, crtc
, plane
) {
15515 if (plane
->base
.type
== DRM_PLANE_TYPE_PRIMARY
)
15518 plane
->disable_plane(&plane
->base
, &crtc
->base
);
15522 /* We need to sanitize the plane -> pipe mapping first because this will
15523 * disable the crtc (and hence change the state) if it is wrong. Note
15524 * that gen4+ has a fixed plane -> pipe mapping. */
15525 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
15528 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
15529 crtc
->base
.base
.id
);
15531 /* Pipe has the wrong plane attached and the plane is active.
15532 * Temporarily change the plane mapping and disable everything
15534 plane
= crtc
->plane
;
15535 to_intel_plane_state(crtc
->base
.primary
->state
)->visible
= true;
15536 crtc
->plane
= !plane
;
15537 intel_crtc_disable_noatomic(&crtc
->base
);
15538 crtc
->plane
= plane
;
15541 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
15542 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
15543 /* BIOS forgot to enable pipe A, this mostly happens after
15544 * resume. Force-enable the pipe to fix this, the update_dpms
15545 * call below we restore the pipe to the right state, but leave
15546 * the required bits on. */
15547 intel_enable_pipe_a(dev
);
15550 /* Adjust the state of the output pipe according to whether we
15551 * have active connectors/encoders. */
15552 if (crtc
->active
&& !intel_crtc_has_encoders(crtc
))
15553 intel_crtc_disable_noatomic(&crtc
->base
);
15555 if (crtc
->active
|| HAS_GMCH_DISPLAY(dev
)) {
15557 * We start out with underrun reporting disabled to avoid races.
15558 * For correct bookkeeping mark this on active crtcs.
15560 * Also on gmch platforms we dont have any hardware bits to
15561 * disable the underrun reporting. Which means we need to start
15562 * out with underrun reporting disabled also on inactive pipes,
15563 * since otherwise we'll complain about the garbage we read when
15564 * e.g. coming up after runtime pm.
15566 * No protection against concurrent access is required - at
15567 * worst a fifo underrun happens which also sets this to false.
15569 crtc
->cpu_fifo_underrun_disabled
= true;
15570 crtc
->pch_fifo_underrun_disabled
= true;
15574 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
15576 struct intel_connector
*connector
;
15577 struct drm_device
*dev
= encoder
->base
.dev
;
15579 /* We need to check both for a crtc link (meaning that the
15580 * encoder is active and trying to read from a pipe) and the
15581 * pipe itself being active. */
15582 bool has_active_crtc
= encoder
->base
.crtc
&&
15583 to_intel_crtc(encoder
->base
.crtc
)->active
;
15585 if (intel_encoder_has_connectors(encoder
) && !has_active_crtc
) {
15586 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15587 encoder
->base
.base
.id
,
15588 encoder
->base
.name
);
15590 /* Connector is active, but has no active pipe. This is
15591 * fallout from our resume register restoring. Disable
15592 * the encoder manually again. */
15593 if (encoder
->base
.crtc
) {
15594 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15595 encoder
->base
.base
.id
,
15596 encoder
->base
.name
);
15597 encoder
->disable(encoder
);
15598 if (encoder
->post_disable
)
15599 encoder
->post_disable(encoder
);
15601 encoder
->base
.crtc
= NULL
;
15603 /* Inconsistent output/port/pipe state happens presumably due to
15604 * a bug in one of the get_hw_state functions. Or someplace else
15605 * in our code, like the register restore mess on resume. Clamp
15606 * things to off as a safer default. */
15607 for_each_intel_connector(dev
, connector
) {
15608 if (connector
->encoder
!= encoder
)
15610 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
15611 connector
->base
.encoder
= NULL
;
15614 /* Enabled encoders without active connectors will be fixed in
15615 * the crtc fixup. */
15618 void i915_redisable_vga_power_on(struct drm_device
*dev
)
15620 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15621 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev
);
15623 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
15624 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
15625 i915_disable_vga(dev
);
15629 void i915_redisable_vga(struct drm_device
*dev
)
15631 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15633 /* This function can be called both from intel_modeset_setup_hw_state or
15634 * at a very early point in our resume sequence, where the power well
15635 * structures are not yet restored. Since this function is at a very
15636 * paranoid "someone might have enabled VGA while we were not looking"
15637 * level, just check if the power well is enabled instead of trying to
15638 * follow the "don't touch the power well if we don't need it" policy
15639 * the rest of the driver uses. */
15640 if (!intel_display_power_get_if_enabled(dev_priv
, POWER_DOMAIN_VGA
))
15643 i915_redisable_vga_power_on(dev
);
15645 intel_display_power_put(dev_priv
, POWER_DOMAIN_VGA
);
15648 static bool primary_get_hw_state(struct intel_plane
*plane
)
15650 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
15652 return I915_READ(DSPCNTR(plane
->plane
)) & DISPLAY_PLANE_ENABLE
;
15655 /* FIXME read out full plane state for all planes */
15656 static void readout_plane_state(struct intel_crtc
*crtc
)
15658 struct drm_plane
*primary
= crtc
->base
.primary
;
15659 struct intel_plane_state
*plane_state
=
15660 to_intel_plane_state(primary
->state
);
15662 plane_state
->visible
= crtc
->active
&&
15663 primary_get_hw_state(to_intel_plane(primary
));
15665 if (plane_state
->visible
)
15666 crtc
->base
.state
->plane_mask
|= 1 << drm_plane_index(primary
);
15669 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
15671 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15673 struct intel_crtc
*crtc
;
15674 struct intel_encoder
*encoder
;
15675 struct intel_connector
*connector
;
15678 dev_priv
->active_crtcs
= 0;
15680 for_each_intel_crtc(dev
, crtc
) {
15681 struct intel_crtc_state
*crtc_state
= crtc
->config
;
15684 __drm_atomic_helper_crtc_destroy_state(&crtc
->base
, &crtc_state
->base
);
15685 memset(crtc_state
, 0, sizeof(*crtc_state
));
15686 crtc_state
->base
.crtc
= &crtc
->base
;
15688 crtc_state
->base
.active
= crtc_state
->base
.enable
=
15689 dev_priv
->display
.get_pipe_config(crtc
, crtc_state
);
15691 crtc
->base
.enabled
= crtc_state
->base
.enable
;
15692 crtc
->active
= crtc_state
->base
.active
;
15694 if (crtc_state
->base
.active
) {
15695 dev_priv
->active_crtcs
|= 1 << crtc
->pipe
;
15697 if (IS_BROADWELL(dev_priv
)) {
15698 pixclk
= ilk_pipe_pixel_rate(crtc_state
);
15700 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
15701 if (crtc_state
->ips_enabled
)
15702 pixclk
= DIV_ROUND_UP(pixclk
* 100, 95);
15703 } else if (IS_VALLEYVIEW(dev_priv
) ||
15704 IS_CHERRYVIEW(dev_priv
) ||
15705 IS_BROXTON(dev_priv
))
15706 pixclk
= crtc_state
->base
.adjusted_mode
.crtc_clock
;
15708 WARN_ON(dev_priv
->display
.modeset_calc_cdclk
);
15711 dev_priv
->min_pixclk
[crtc
->pipe
] = pixclk
;
15713 readout_plane_state(crtc
);
15715 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
15716 crtc
->base
.base
.id
,
15717 crtc
->active
? "enabled" : "disabled");
15720 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
15721 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
15723 pll
->on
= pll
->funcs
.get_hw_state(dev_priv
, pll
,
15724 &pll
->config
.hw_state
);
15725 pll
->config
.crtc_mask
= 0;
15726 for_each_intel_crtc(dev
, crtc
) {
15727 if (crtc
->active
&& crtc
->config
->shared_dpll
== pll
)
15728 pll
->config
.crtc_mask
|= 1 << crtc
->pipe
;
15730 pll
->active_mask
= pll
->config
.crtc_mask
;
15732 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15733 pll
->name
, pll
->config
.crtc_mask
, pll
->on
);
15736 for_each_intel_encoder(dev
, encoder
) {
15739 if (encoder
->get_hw_state(encoder
, &pipe
)) {
15740 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
15741 encoder
->base
.crtc
= &crtc
->base
;
15742 encoder
->get_config(encoder
, crtc
->config
);
15744 encoder
->base
.crtc
= NULL
;
15747 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15748 encoder
->base
.base
.id
,
15749 encoder
->base
.name
,
15750 encoder
->base
.crtc
? "enabled" : "disabled",
15754 for_each_intel_connector(dev
, connector
) {
15755 if (connector
->get_hw_state(connector
)) {
15756 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
15758 encoder
= connector
->encoder
;
15759 connector
->base
.encoder
= &encoder
->base
;
15761 if (encoder
->base
.crtc
&&
15762 encoder
->base
.crtc
->state
->active
) {
15764 * This has to be done during hardware readout
15765 * because anything calling .crtc_disable may
15766 * rely on the connector_mask being accurate.
15768 encoder
->base
.crtc
->state
->connector_mask
|=
15769 1 << drm_connector_index(&connector
->base
);
15770 encoder
->base
.crtc
->state
->encoder_mask
|=
15771 1 << drm_encoder_index(&encoder
->base
);
15775 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
15776 connector
->base
.encoder
= NULL
;
15778 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
15779 connector
->base
.base
.id
,
15780 connector
->base
.name
,
15781 connector
->base
.encoder
? "enabled" : "disabled");
15784 for_each_intel_crtc(dev
, crtc
) {
15785 crtc
->base
.hwmode
= crtc
->config
->base
.adjusted_mode
;
15787 memset(&crtc
->base
.mode
, 0, sizeof(crtc
->base
.mode
));
15788 if (crtc
->base
.state
->active
) {
15789 intel_mode_from_pipe_config(&crtc
->base
.mode
, crtc
->config
);
15790 intel_mode_from_pipe_config(&crtc
->base
.state
->adjusted_mode
, crtc
->config
);
15791 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->base
.state
, &crtc
->base
.mode
));
15794 * The initial mode needs to be set in order to keep
15795 * the atomic core happy. It wants a valid mode if the
15796 * crtc's enabled, so we do the above call.
15798 * At this point some state updated by the connectors
15799 * in their ->detect() callback has not run yet, so
15800 * no recalculation can be done yet.
15802 * Even if we could do a recalculation and modeset
15803 * right now it would cause a double modeset if
15804 * fbdev or userspace chooses a different initial mode.
15806 * If that happens, someone indicated they wanted a
15807 * mode change, which means it's safe to do a full
15810 crtc
->base
.state
->mode
.private_flags
= I915_MODE_FLAG_INHERITED
;
15812 drm_calc_timestamping_constants(&crtc
->base
, &crtc
->base
.hwmode
);
15813 update_scanline_offset(crtc
);
15816 intel_pipe_config_sanity_check(dev_priv
, crtc
->config
);
15820 /* Scan out the current hw modeset state,
15821 * and sanitizes it to the current state
15824 intel_modeset_setup_hw_state(struct drm_device
*dev
)
15826 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15828 struct intel_crtc
*crtc
;
15829 struct intel_encoder
*encoder
;
15832 intel_modeset_readout_hw_state(dev
);
15834 /* HW state is read out, now we need to sanitize this mess. */
15835 for_each_intel_encoder(dev
, encoder
) {
15836 intel_sanitize_encoder(encoder
);
15839 for_each_pipe(dev_priv
, pipe
) {
15840 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
15841 intel_sanitize_crtc(crtc
);
15842 intel_dump_pipe_config(crtc
, crtc
->config
,
15843 "[setup_hw_state]");
15846 intel_modeset_update_connector_atomic_state(dev
);
15848 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
15849 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
15851 if (!pll
->on
|| pll
->active_mask
)
15854 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
15856 pll
->funcs
.disable(dev_priv
, pll
);
15860 if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
))
15861 vlv_wm_get_hw_state(dev
);
15862 else if (IS_GEN9(dev
))
15863 skl_wm_get_hw_state(dev
);
15864 else if (HAS_PCH_SPLIT(dev
))
15865 ilk_wm_get_hw_state(dev
);
15867 for_each_intel_crtc(dev
, crtc
) {
15868 unsigned long put_domains
;
15870 put_domains
= modeset_get_crtc_power_domains(&crtc
->base
, crtc
->config
);
15871 if (WARN_ON(put_domains
))
15872 modeset_put_power_domains(dev_priv
, put_domains
);
15874 intel_display_set_init_power(dev_priv
, false);
15876 intel_fbc_init_pipe_state(dev_priv
);
15879 void intel_display_resume(struct drm_device
*dev
)
15881 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15882 struct drm_atomic_state
*state
= dev_priv
->modeset_restore_state
;
15883 struct drm_modeset_acquire_ctx ctx
;
15885 bool setup
= false;
15887 dev_priv
->modeset_restore_state
= NULL
;
15890 * This is a cludge because with real atomic modeset mode_config.mutex
15891 * won't be taken. Unfortunately some probed state like
15892 * audio_codec_enable is still protected by mode_config.mutex, so lock
15895 mutex_lock(&dev
->mode_config
.mutex
);
15896 drm_modeset_acquire_init(&ctx
, 0);
15899 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
15901 if (ret
== 0 && !setup
) {
15904 intel_modeset_setup_hw_state(dev
);
15905 i915_redisable_vga(dev
);
15908 if (ret
== 0 && state
) {
15909 struct drm_crtc_state
*crtc_state
;
15910 struct drm_crtc
*crtc
;
15913 state
->acquire_ctx
= &ctx
;
15915 /* ignore any reset values/BIOS leftovers in the WM registers */
15916 to_intel_atomic_state(state
)->skip_intermediate_wm
= true;
15918 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
15920 * Force recalculation even if we restore
15921 * current state. With fast modeset this may not result
15922 * in a modeset when the state is compatible.
15924 crtc_state
->mode_changed
= true;
15927 ret
= drm_atomic_commit(state
);
15930 if (ret
== -EDEADLK
) {
15931 drm_modeset_backoff(&ctx
);
15935 drm_modeset_drop_locks(&ctx
);
15936 drm_modeset_acquire_fini(&ctx
);
15937 mutex_unlock(&dev
->mode_config
.mutex
);
15940 DRM_ERROR("Restoring old state failed with %i\n", ret
);
15941 drm_atomic_state_free(state
);
15945 void intel_modeset_gem_init(struct drm_device
*dev
)
15947 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15948 struct drm_crtc
*c
;
15949 struct drm_i915_gem_object
*obj
;
15952 intel_init_gt_powersave(dev_priv
);
15954 intel_modeset_init_hw(dev
);
15956 intel_setup_overlay(dev_priv
);
15959 * Make sure any fbs we allocated at startup are properly
15960 * pinned & fenced. When we do the allocation it's too early
15963 for_each_crtc(dev
, c
) {
15964 obj
= intel_fb_obj(c
->primary
->fb
);
15968 mutex_lock(&dev
->struct_mutex
);
15969 ret
= intel_pin_and_fence_fb_obj(c
->primary
->fb
,
15970 c
->primary
->state
->rotation
);
15971 mutex_unlock(&dev
->struct_mutex
);
15973 DRM_ERROR("failed to pin boot fb on pipe %d\n",
15974 to_intel_crtc(c
)->pipe
);
15975 drm_framebuffer_unreference(c
->primary
->fb
);
15976 c
->primary
->fb
= NULL
;
15977 c
->primary
->crtc
= c
->primary
->state
->crtc
= NULL
;
15978 update_state_fb(c
->primary
);
15979 c
->state
->plane_mask
&= ~(1 << drm_plane_index(c
->primary
));
15983 intel_backlight_register(dev
);
15986 void intel_connector_unregister(struct intel_connector
*intel_connector
)
15988 struct drm_connector
*connector
= &intel_connector
->base
;
15990 intel_panel_destroy_backlight(connector
);
15991 drm_connector_unregister(connector
);
15994 void intel_modeset_cleanup(struct drm_device
*dev
)
15996 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15997 struct intel_connector
*connector
;
15999 intel_disable_gt_powersave(dev_priv
);
16001 intel_backlight_unregister(dev
);
16004 * Interrupts and polling as the first thing to avoid creating havoc.
16005 * Too much stuff here (turning of connectors, ...) would
16006 * experience fancy races otherwise.
16008 intel_irq_uninstall(dev_priv
);
16011 * Due to the hpd irq storm handling the hotplug work can re-arm the
16012 * poll handlers. Hence disable polling after hpd handling is shut down.
16014 drm_kms_helper_poll_fini(dev
);
16016 intel_unregister_dsm_handler();
16018 intel_fbc_global_disable(dev_priv
);
16020 /* flush any delayed tasks or pending work */
16021 flush_scheduled_work();
16023 /* destroy the backlight and sysfs files before encoders/connectors */
16024 for_each_intel_connector(dev
, connector
)
16025 connector
->unregister(connector
);
16027 drm_mode_config_cleanup(dev
);
16029 intel_cleanup_overlay(dev_priv
);
16031 intel_cleanup_gt_powersave(dev_priv
);
16033 intel_teardown_gmbus(dev
);
16037 * Return which encoder is currently attached for connector.
16039 struct drm_encoder
*intel_best_encoder(struct drm_connector
*connector
)
16041 return &intel_attached_encoder(connector
)->base
;
16044 void intel_connector_attach_encoder(struct intel_connector
*connector
,
16045 struct intel_encoder
*encoder
)
16047 connector
->encoder
= encoder
;
16048 drm_mode_connector_attach_encoder(&connector
->base
,
16053 * set vga decode state - true == enable VGA decode
16055 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
16057 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
16058 unsigned reg
= INTEL_INFO(dev
)->gen
>= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
16061 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
16062 DRM_ERROR("failed to read control word\n");
16066 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
16070 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
16072 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
16074 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
16075 DRM_ERROR("failed to write control word\n");
16082 struct intel_display_error_state
{
16084 u32 power_well_driver
;
16086 int num_transcoders
;
16088 struct intel_cursor_error_state
{
16093 } cursor
[I915_MAX_PIPES
];
16095 struct intel_pipe_error_state
{
16096 bool power_domain_on
;
16099 } pipe
[I915_MAX_PIPES
];
16101 struct intel_plane_error_state
{
16109 } plane
[I915_MAX_PIPES
];
16111 struct intel_transcoder_error_state
{
16112 bool power_domain_on
;
16113 enum transcoder cpu_transcoder
;
16126 struct intel_display_error_state
*
16127 intel_display_capture_error_state(struct drm_i915_private
*dev_priv
)
16129 struct intel_display_error_state
*error
;
16130 int transcoders
[] = {
16138 if (INTEL_INFO(dev_priv
)->num_pipes
== 0)
16141 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
16145 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
16146 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
16148 for_each_pipe(dev_priv
, i
) {
16149 error
->pipe
[i
].power_domain_on
=
16150 __intel_display_power_is_enabled(dev_priv
,
16151 POWER_DOMAIN_PIPE(i
));
16152 if (!error
->pipe
[i
].power_domain_on
)
16155 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
16156 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
16157 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
16159 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
16160 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
16161 if (INTEL_GEN(dev_priv
) <= 3) {
16162 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
16163 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
16165 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
16166 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
16167 if (INTEL_GEN(dev_priv
) >= 4) {
16168 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
16169 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
16172 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
16174 if (HAS_GMCH_DISPLAY(dev_priv
))
16175 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
16178 /* Note: this does not include DSI transcoders. */
16179 error
->num_transcoders
= INTEL_INFO(dev_priv
)->num_pipes
;
16180 if (HAS_DDI(dev_priv
))
16181 error
->num_transcoders
++; /* Account for eDP. */
16183 for (i
= 0; i
< error
->num_transcoders
; i
++) {
16184 enum transcoder cpu_transcoder
= transcoders
[i
];
16186 error
->transcoder
[i
].power_domain_on
=
16187 __intel_display_power_is_enabled(dev_priv
,
16188 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
16189 if (!error
->transcoder
[i
].power_domain_on
)
16192 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
16194 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
16195 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
16196 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
16197 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
16198 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
16199 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
16200 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
16206 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
16209 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
16210 struct drm_device
*dev
,
16211 struct intel_display_error_state
*error
)
16213 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
16219 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev
)->num_pipes
);
16220 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
16221 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
16222 error
->power_well_driver
);
16223 for_each_pipe(dev_priv
, i
) {
16224 err_printf(m
, "Pipe [%d]:\n", i
);
16225 err_printf(m
, " Power: %s\n",
16226 onoff(error
->pipe
[i
].power_domain_on
));
16227 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
16228 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
16230 err_printf(m
, "Plane [%d]:\n", i
);
16231 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
16232 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
16233 if (INTEL_INFO(dev
)->gen
<= 3) {
16234 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
16235 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
16237 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
16238 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
16239 if (INTEL_INFO(dev
)->gen
>= 4) {
16240 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
16241 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
16244 err_printf(m
, "Cursor [%d]:\n", i
);
16245 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
16246 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
16247 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
16250 for (i
= 0; i
< error
->num_transcoders
; i
++) {
16251 err_printf(m
, "CPU transcoder: %s\n",
16252 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
16253 err_printf(m
, " Power: %s\n",
16254 onoff(error
->transcoder
[i
].power_domain_on
));
16255 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
16256 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
16257 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
16258 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
16259 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
16260 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
16261 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);