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 "intel_frontbuffer.h"
38 #include <drm/i915_drm.h>
40 #include "intel_dsi.h"
41 #include "i915_trace.h"
42 #include <drm/drm_atomic.h>
43 #include <drm/drm_atomic_helper.h>
44 #include <drm/drm_dp_helper.h>
45 #include <drm/drm_crtc_helper.h>
46 #include <drm/drm_plane_helper.h>
47 #include <drm/drm_rect.h>
48 #include <linux/dma_remapping.h>
49 #include <linux/reservation.h>
51 static bool is_mmio_work(struct intel_flip_work
*work
)
53 return work
->mmio_work
.func
;
56 /* Primary plane formats for gen <= 3 */
57 static const uint32_t i8xx_primary_formats
[] = {
64 /* Primary plane formats for gen >= 4 */
65 static const uint32_t i965_primary_formats
[] = {
70 DRM_FORMAT_XRGB2101010
,
71 DRM_FORMAT_XBGR2101010
,
74 static const uint32_t skl_primary_formats
[] = {
81 DRM_FORMAT_XRGB2101010
,
82 DRM_FORMAT_XBGR2101010
,
90 static const uint32_t intel_cursor_formats
[] = {
94 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
95 struct intel_crtc_state
*pipe_config
);
96 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
97 struct intel_crtc_state
*pipe_config
);
99 static int intel_framebuffer_init(struct drm_device
*dev
,
100 struct intel_framebuffer
*ifb
,
101 struct drm_mode_fb_cmd2
*mode_cmd
,
102 struct drm_i915_gem_object
*obj
);
103 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
);
104 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
);
105 static void intel_set_pipe_src_size(struct intel_crtc
*intel_crtc
);
106 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
107 struct intel_link_m_n
*m_n
,
108 struct intel_link_m_n
*m2_n2
);
109 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
);
110 static void haswell_set_pipeconf(struct drm_crtc
*crtc
);
111 static void haswell_set_pipemisc(struct drm_crtc
*crtc
);
112 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
113 const struct intel_crtc_state
*pipe_config
);
114 static void chv_prepare_pll(struct intel_crtc
*crtc
,
115 const struct intel_crtc_state
*pipe_config
);
116 static void intel_begin_crtc_commit(struct drm_crtc
*, struct drm_crtc_state
*);
117 static void intel_finish_crtc_commit(struct drm_crtc
*, struct drm_crtc_state
*);
118 static void skl_init_scalers(struct drm_device
*dev
, struct intel_crtc
*intel_crtc
,
119 struct intel_crtc_state
*crtc_state
);
120 static void skylake_pfit_enable(struct intel_crtc
*crtc
);
121 static void ironlake_pfit_disable(struct intel_crtc
*crtc
, bool force
);
122 static void ironlake_pfit_enable(struct intel_crtc
*crtc
);
123 static void intel_modeset_setup_hw_state(struct drm_device
*dev
);
124 static void intel_pre_disable_primary_noatomic(struct drm_crtc
*crtc
);
125 static int ilk_max_pixel_rate(struct drm_atomic_state
*state
);
126 static int bxt_calc_cdclk(int max_pixclk
);
131 } dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
135 int p2_slow
, p2_fast
;
139 /* returns HPLL frequency in kHz */
140 static int valleyview_get_vco(struct drm_i915_private
*dev_priv
)
142 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
144 /* Obtain SKU information */
145 mutex_lock(&dev_priv
->sb_lock
);
146 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
147 CCK_FUSE_HPLL_FREQ_MASK
;
148 mutex_unlock(&dev_priv
->sb_lock
);
150 return vco_freq
[hpll_freq
] * 1000;
153 int vlv_get_cck_clock(struct drm_i915_private
*dev_priv
,
154 const char *name
, u32 reg
, int ref_freq
)
159 mutex_lock(&dev_priv
->sb_lock
);
160 val
= vlv_cck_read(dev_priv
, reg
);
161 mutex_unlock(&dev_priv
->sb_lock
);
163 divider
= val
& CCK_FREQUENCY_VALUES
;
165 WARN((val
& CCK_FREQUENCY_STATUS
) !=
166 (divider
<< CCK_FREQUENCY_STATUS_SHIFT
),
167 "%s change in progress\n", name
);
169 return DIV_ROUND_CLOSEST(ref_freq
<< 1, divider
+ 1);
172 static int vlv_get_cck_clock_hpll(struct drm_i915_private
*dev_priv
,
173 const char *name
, u32 reg
)
175 if (dev_priv
->hpll_freq
== 0)
176 dev_priv
->hpll_freq
= valleyview_get_vco(dev_priv
);
178 return vlv_get_cck_clock(dev_priv
, name
, reg
,
179 dev_priv
->hpll_freq
);
183 intel_pch_rawclk(struct drm_i915_private
*dev_priv
)
185 return (I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
) * 1000;
189 intel_vlv_hrawclk(struct drm_i915_private
*dev_priv
)
191 /* RAWCLK_FREQ_VLV register updated from power well code */
192 return vlv_get_cck_clock_hpll(dev_priv
, "hrawclk",
193 CCK_DISPLAY_REF_CLOCK_CONTROL
);
197 intel_g4x_hrawclk(struct drm_i915_private
*dev_priv
)
201 /* hrawclock is 1/4 the FSB frequency */
202 clkcfg
= I915_READ(CLKCFG
);
203 switch (clkcfg
& CLKCFG_FSB_MASK
) {
212 case CLKCFG_FSB_1067
:
214 case CLKCFG_FSB_1333
:
216 /* these two are just a guess; one of them might be right */
217 case CLKCFG_FSB_1600
:
218 case CLKCFG_FSB_1600_ALT
:
225 void intel_update_rawclk(struct drm_i915_private
*dev_priv
)
227 if (HAS_PCH_SPLIT(dev_priv
))
228 dev_priv
->rawclk_freq
= intel_pch_rawclk(dev_priv
);
229 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
230 dev_priv
->rawclk_freq
= intel_vlv_hrawclk(dev_priv
);
231 else if (IS_G4X(dev_priv
) || IS_PINEVIEW(dev_priv
))
232 dev_priv
->rawclk_freq
= intel_g4x_hrawclk(dev_priv
);
234 return; /* no rawclk on other platforms, or no need to know it */
236 DRM_DEBUG_DRIVER("rawclk rate: %d kHz\n", dev_priv
->rawclk_freq
);
239 static void intel_update_czclk(struct drm_i915_private
*dev_priv
)
241 if (!(IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)))
244 dev_priv
->czclk_freq
= vlv_get_cck_clock_hpll(dev_priv
, "czclk",
245 CCK_CZ_CLOCK_CONTROL
);
247 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv
->czclk_freq
);
250 static inline u32
/* units of 100MHz */
251 intel_fdi_link_freq(struct drm_i915_private
*dev_priv
,
252 const struct intel_crtc_state
*pipe_config
)
254 if (HAS_DDI(dev_priv
))
255 return pipe_config
->port_clock
; /* SPLL */
256 else if (IS_GEN5(dev_priv
))
257 return ((I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2) * 10000;
262 static const struct intel_limit intel_limits_i8xx_dac
= {
263 .dot
= { .min
= 25000, .max
= 350000 },
264 .vco
= { .min
= 908000, .max
= 1512000 },
265 .n
= { .min
= 2, .max
= 16 },
266 .m
= { .min
= 96, .max
= 140 },
267 .m1
= { .min
= 18, .max
= 26 },
268 .m2
= { .min
= 6, .max
= 16 },
269 .p
= { .min
= 4, .max
= 128 },
270 .p1
= { .min
= 2, .max
= 33 },
271 .p2
= { .dot_limit
= 165000,
272 .p2_slow
= 4, .p2_fast
= 2 },
275 static const struct intel_limit intel_limits_i8xx_dvo
= {
276 .dot
= { .min
= 25000, .max
= 350000 },
277 .vco
= { .min
= 908000, .max
= 1512000 },
278 .n
= { .min
= 2, .max
= 16 },
279 .m
= { .min
= 96, .max
= 140 },
280 .m1
= { .min
= 18, .max
= 26 },
281 .m2
= { .min
= 6, .max
= 16 },
282 .p
= { .min
= 4, .max
= 128 },
283 .p1
= { .min
= 2, .max
= 33 },
284 .p2
= { .dot_limit
= 165000,
285 .p2_slow
= 4, .p2_fast
= 4 },
288 static const struct intel_limit intel_limits_i8xx_lvds
= {
289 .dot
= { .min
= 25000, .max
= 350000 },
290 .vco
= { .min
= 908000, .max
= 1512000 },
291 .n
= { .min
= 2, .max
= 16 },
292 .m
= { .min
= 96, .max
= 140 },
293 .m1
= { .min
= 18, .max
= 26 },
294 .m2
= { .min
= 6, .max
= 16 },
295 .p
= { .min
= 4, .max
= 128 },
296 .p1
= { .min
= 1, .max
= 6 },
297 .p2
= { .dot_limit
= 165000,
298 .p2_slow
= 14, .p2_fast
= 7 },
301 static const struct intel_limit intel_limits_i9xx_sdvo
= {
302 .dot
= { .min
= 20000, .max
= 400000 },
303 .vco
= { .min
= 1400000, .max
= 2800000 },
304 .n
= { .min
= 1, .max
= 6 },
305 .m
= { .min
= 70, .max
= 120 },
306 .m1
= { .min
= 8, .max
= 18 },
307 .m2
= { .min
= 3, .max
= 7 },
308 .p
= { .min
= 5, .max
= 80 },
309 .p1
= { .min
= 1, .max
= 8 },
310 .p2
= { .dot_limit
= 200000,
311 .p2_slow
= 10, .p2_fast
= 5 },
314 static const struct intel_limit intel_limits_i9xx_lvds
= {
315 .dot
= { .min
= 20000, .max
= 400000 },
316 .vco
= { .min
= 1400000, .max
= 2800000 },
317 .n
= { .min
= 1, .max
= 6 },
318 .m
= { .min
= 70, .max
= 120 },
319 .m1
= { .min
= 8, .max
= 18 },
320 .m2
= { .min
= 3, .max
= 7 },
321 .p
= { .min
= 7, .max
= 98 },
322 .p1
= { .min
= 1, .max
= 8 },
323 .p2
= { .dot_limit
= 112000,
324 .p2_slow
= 14, .p2_fast
= 7 },
328 static const struct intel_limit intel_limits_g4x_sdvo
= {
329 .dot
= { .min
= 25000, .max
= 270000 },
330 .vco
= { .min
= 1750000, .max
= 3500000},
331 .n
= { .min
= 1, .max
= 4 },
332 .m
= { .min
= 104, .max
= 138 },
333 .m1
= { .min
= 17, .max
= 23 },
334 .m2
= { .min
= 5, .max
= 11 },
335 .p
= { .min
= 10, .max
= 30 },
336 .p1
= { .min
= 1, .max
= 3},
337 .p2
= { .dot_limit
= 270000,
343 static const struct intel_limit intel_limits_g4x_hdmi
= {
344 .dot
= { .min
= 22000, .max
= 400000 },
345 .vco
= { .min
= 1750000, .max
= 3500000},
346 .n
= { .min
= 1, .max
= 4 },
347 .m
= { .min
= 104, .max
= 138 },
348 .m1
= { .min
= 16, .max
= 23 },
349 .m2
= { .min
= 5, .max
= 11 },
350 .p
= { .min
= 5, .max
= 80 },
351 .p1
= { .min
= 1, .max
= 8},
352 .p2
= { .dot_limit
= 165000,
353 .p2_slow
= 10, .p2_fast
= 5 },
356 static const struct intel_limit intel_limits_g4x_single_channel_lvds
= {
357 .dot
= { .min
= 20000, .max
= 115000 },
358 .vco
= { .min
= 1750000, .max
= 3500000 },
359 .n
= { .min
= 1, .max
= 3 },
360 .m
= { .min
= 104, .max
= 138 },
361 .m1
= { .min
= 17, .max
= 23 },
362 .m2
= { .min
= 5, .max
= 11 },
363 .p
= { .min
= 28, .max
= 112 },
364 .p1
= { .min
= 2, .max
= 8 },
365 .p2
= { .dot_limit
= 0,
366 .p2_slow
= 14, .p2_fast
= 14
370 static const struct intel_limit intel_limits_g4x_dual_channel_lvds
= {
371 .dot
= { .min
= 80000, .max
= 224000 },
372 .vco
= { .min
= 1750000, .max
= 3500000 },
373 .n
= { .min
= 1, .max
= 3 },
374 .m
= { .min
= 104, .max
= 138 },
375 .m1
= { .min
= 17, .max
= 23 },
376 .m2
= { .min
= 5, .max
= 11 },
377 .p
= { .min
= 14, .max
= 42 },
378 .p1
= { .min
= 2, .max
= 6 },
379 .p2
= { .dot_limit
= 0,
380 .p2_slow
= 7, .p2_fast
= 7
384 static const struct intel_limit intel_limits_pineview_sdvo
= {
385 .dot
= { .min
= 20000, .max
= 400000},
386 .vco
= { .min
= 1700000, .max
= 3500000 },
387 /* Pineview's Ncounter is a ring counter */
388 .n
= { .min
= 3, .max
= 6 },
389 .m
= { .min
= 2, .max
= 256 },
390 /* Pineview only has one combined m divider, which we treat as m2. */
391 .m1
= { .min
= 0, .max
= 0 },
392 .m2
= { .min
= 0, .max
= 254 },
393 .p
= { .min
= 5, .max
= 80 },
394 .p1
= { .min
= 1, .max
= 8 },
395 .p2
= { .dot_limit
= 200000,
396 .p2_slow
= 10, .p2_fast
= 5 },
399 static const struct intel_limit intel_limits_pineview_lvds
= {
400 .dot
= { .min
= 20000, .max
= 400000 },
401 .vco
= { .min
= 1700000, .max
= 3500000 },
402 .n
= { .min
= 3, .max
= 6 },
403 .m
= { .min
= 2, .max
= 256 },
404 .m1
= { .min
= 0, .max
= 0 },
405 .m2
= { .min
= 0, .max
= 254 },
406 .p
= { .min
= 7, .max
= 112 },
407 .p1
= { .min
= 1, .max
= 8 },
408 .p2
= { .dot_limit
= 112000,
409 .p2_slow
= 14, .p2_fast
= 14 },
412 /* Ironlake / Sandybridge
414 * We calculate clock using (register_value + 2) for N/M1/M2, so here
415 * the range value for them is (actual_value - 2).
417 static const struct intel_limit intel_limits_ironlake_dac
= {
418 .dot
= { .min
= 25000, .max
= 350000 },
419 .vco
= { .min
= 1760000, .max
= 3510000 },
420 .n
= { .min
= 1, .max
= 5 },
421 .m
= { .min
= 79, .max
= 127 },
422 .m1
= { .min
= 12, .max
= 22 },
423 .m2
= { .min
= 5, .max
= 9 },
424 .p
= { .min
= 5, .max
= 80 },
425 .p1
= { .min
= 1, .max
= 8 },
426 .p2
= { .dot_limit
= 225000,
427 .p2_slow
= 10, .p2_fast
= 5 },
430 static const struct intel_limit intel_limits_ironlake_single_lvds
= {
431 .dot
= { .min
= 25000, .max
= 350000 },
432 .vco
= { .min
= 1760000, .max
= 3510000 },
433 .n
= { .min
= 1, .max
= 3 },
434 .m
= { .min
= 79, .max
= 118 },
435 .m1
= { .min
= 12, .max
= 22 },
436 .m2
= { .min
= 5, .max
= 9 },
437 .p
= { .min
= 28, .max
= 112 },
438 .p1
= { .min
= 2, .max
= 8 },
439 .p2
= { .dot_limit
= 225000,
440 .p2_slow
= 14, .p2_fast
= 14 },
443 static const struct intel_limit intel_limits_ironlake_dual_lvds
= {
444 .dot
= { .min
= 25000, .max
= 350000 },
445 .vco
= { .min
= 1760000, .max
= 3510000 },
446 .n
= { .min
= 1, .max
= 3 },
447 .m
= { .min
= 79, .max
= 127 },
448 .m1
= { .min
= 12, .max
= 22 },
449 .m2
= { .min
= 5, .max
= 9 },
450 .p
= { .min
= 14, .max
= 56 },
451 .p1
= { .min
= 2, .max
= 8 },
452 .p2
= { .dot_limit
= 225000,
453 .p2_slow
= 7, .p2_fast
= 7 },
456 /* LVDS 100mhz refclk limits. */
457 static const struct intel_limit intel_limits_ironlake_single_lvds_100m
= {
458 .dot
= { .min
= 25000, .max
= 350000 },
459 .vco
= { .min
= 1760000, .max
= 3510000 },
460 .n
= { .min
= 1, .max
= 2 },
461 .m
= { .min
= 79, .max
= 126 },
462 .m1
= { .min
= 12, .max
= 22 },
463 .m2
= { .min
= 5, .max
= 9 },
464 .p
= { .min
= 28, .max
= 112 },
465 .p1
= { .min
= 2, .max
= 8 },
466 .p2
= { .dot_limit
= 225000,
467 .p2_slow
= 14, .p2_fast
= 14 },
470 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m
= {
471 .dot
= { .min
= 25000, .max
= 350000 },
472 .vco
= { .min
= 1760000, .max
= 3510000 },
473 .n
= { .min
= 1, .max
= 3 },
474 .m
= { .min
= 79, .max
= 126 },
475 .m1
= { .min
= 12, .max
= 22 },
476 .m2
= { .min
= 5, .max
= 9 },
477 .p
= { .min
= 14, .max
= 42 },
478 .p1
= { .min
= 2, .max
= 6 },
479 .p2
= { .dot_limit
= 225000,
480 .p2_slow
= 7, .p2_fast
= 7 },
483 static const struct intel_limit intel_limits_vlv
= {
485 * These are the data rate limits (measured in fast clocks)
486 * since those are the strictest limits we have. The fast
487 * clock and actual rate limits are more relaxed, so checking
488 * them would make no difference.
490 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
491 .vco
= { .min
= 4000000, .max
= 6000000 },
492 .n
= { .min
= 1, .max
= 7 },
493 .m1
= { .min
= 2, .max
= 3 },
494 .m2
= { .min
= 11, .max
= 156 },
495 .p1
= { .min
= 2, .max
= 3 },
496 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
499 static const struct intel_limit intel_limits_chv
= {
501 * These are the data rate limits (measured in fast clocks)
502 * since those are the strictest limits we have. The fast
503 * clock and actual rate limits are more relaxed, so checking
504 * them would make no difference.
506 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
507 .vco
= { .min
= 4800000, .max
= 6480000 },
508 .n
= { .min
= 1, .max
= 1 },
509 .m1
= { .min
= 2, .max
= 2 },
510 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
511 .p1
= { .min
= 2, .max
= 4 },
512 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
515 static const struct intel_limit intel_limits_bxt
= {
516 /* FIXME: find real dot limits */
517 .dot
= { .min
= 0, .max
= INT_MAX
},
518 .vco
= { .min
= 4800000, .max
= 6700000 },
519 .n
= { .min
= 1, .max
= 1 },
520 .m1
= { .min
= 2, .max
= 2 },
521 /* FIXME: find real m2 limits */
522 .m2
= { .min
= 2 << 22, .max
= 255 << 22 },
523 .p1
= { .min
= 2, .max
= 4 },
524 .p2
= { .p2_slow
= 1, .p2_fast
= 20 },
528 needs_modeset(struct drm_crtc_state
*state
)
530 return drm_atomic_crtc_needs_modeset(state
);
534 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
535 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
536 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
537 * The helpers' return value is the rate of the clock that is fed to the
538 * display engine's pipe which can be the above fast dot clock rate or a
539 * divided-down version of it.
541 /* m1 is reserved as 0 in Pineview, n is a ring counter */
542 static int pnv_calc_dpll_params(int refclk
, struct dpll
*clock
)
544 clock
->m
= clock
->m2
+ 2;
545 clock
->p
= clock
->p1
* clock
->p2
;
546 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
548 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
549 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
554 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
556 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
559 static int i9xx_calc_dpll_params(int refclk
, struct dpll
*clock
)
561 clock
->m
= i9xx_dpll_compute_m(clock
);
562 clock
->p
= clock
->p1
* clock
->p2
;
563 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
565 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
566 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
571 static int vlv_calc_dpll_params(int refclk
, struct dpll
*clock
)
573 clock
->m
= clock
->m1
* clock
->m2
;
574 clock
->p
= clock
->p1
* clock
->p2
;
575 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
577 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
578 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
580 return clock
->dot
/ 5;
583 int chv_calc_dpll_params(int refclk
, struct dpll
*clock
)
585 clock
->m
= clock
->m1
* clock
->m2
;
586 clock
->p
= clock
->p1
* clock
->p2
;
587 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
589 clock
->vco
= DIV_ROUND_CLOSEST_ULL((uint64_t)refclk
* clock
->m
,
591 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
593 return clock
->dot
/ 5;
596 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
598 * Returns whether the given set of divisors are valid for a given refclk with
599 * the given connectors.
602 static bool intel_PLL_is_valid(struct drm_i915_private
*dev_priv
,
603 const struct intel_limit
*limit
,
604 const struct dpll
*clock
)
606 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
607 INTELPllInvalid("n out of range\n");
608 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
609 INTELPllInvalid("p1 out of range\n");
610 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
611 INTELPllInvalid("m2 out of range\n");
612 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
613 INTELPllInvalid("m1 out of range\n");
615 if (!IS_PINEVIEW(dev_priv
) && !IS_VALLEYVIEW(dev_priv
) &&
616 !IS_CHERRYVIEW(dev_priv
) && !IS_BROXTON(dev_priv
))
617 if (clock
->m1
<= clock
->m2
)
618 INTELPllInvalid("m1 <= m2\n");
620 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
) &&
621 !IS_BROXTON(dev_priv
)) {
622 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
623 INTELPllInvalid("p out of range\n");
624 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
625 INTELPllInvalid("m out of range\n");
628 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
629 INTELPllInvalid("vco out of range\n");
630 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
631 * connector, etc., rather than just a single range.
633 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
634 INTELPllInvalid("dot out of range\n");
640 i9xx_select_p2_div(const struct intel_limit
*limit
,
641 const struct intel_crtc_state
*crtc_state
,
644 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
646 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
648 * For LVDS just rely on its current settings for dual-channel.
649 * We haven't figured out how to reliably set up different
650 * single/dual channel state, if we even can.
652 if (intel_is_dual_link_lvds(dev
))
653 return limit
->p2
.p2_fast
;
655 return limit
->p2
.p2_slow
;
657 if (target
< limit
->p2
.dot_limit
)
658 return limit
->p2
.p2_slow
;
660 return limit
->p2
.p2_fast
;
665 * Returns a set of divisors for the desired target clock with the given
666 * refclk, or FALSE. The returned values represent the clock equation:
667 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
669 * Target and reference clocks are specified in kHz.
671 * If match_clock is provided, then best_clock P divider must match the P
672 * divider from @match_clock used for LVDS downclocking.
675 i9xx_find_best_dpll(const struct intel_limit
*limit
,
676 struct intel_crtc_state
*crtc_state
,
677 int target
, int refclk
, struct dpll
*match_clock
,
678 struct dpll
*best_clock
)
680 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
684 memset(best_clock
, 0, sizeof(*best_clock
));
686 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
688 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
690 for (clock
.m2
= limit
->m2
.min
;
691 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
692 if (clock
.m2
>= clock
.m1
)
694 for (clock
.n
= limit
->n
.min
;
695 clock
.n
<= limit
->n
.max
; clock
.n
++) {
696 for (clock
.p1
= limit
->p1
.min
;
697 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
700 i9xx_calc_dpll_params(refclk
, &clock
);
701 if (!intel_PLL_is_valid(to_i915(dev
),
706 clock
.p
!= match_clock
->p
)
709 this_err
= abs(clock
.dot
- target
);
710 if (this_err
< err
) {
719 return (err
!= target
);
723 * Returns a set of divisors for the desired target clock with the given
724 * refclk, or FALSE. The returned values represent the clock equation:
725 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
727 * Target and reference clocks are specified in kHz.
729 * If match_clock is provided, then best_clock P divider must match the P
730 * divider from @match_clock used for LVDS downclocking.
733 pnv_find_best_dpll(const struct intel_limit
*limit
,
734 struct intel_crtc_state
*crtc_state
,
735 int target
, int refclk
, struct dpll
*match_clock
,
736 struct dpll
*best_clock
)
738 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
742 memset(best_clock
, 0, sizeof(*best_clock
));
744 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
746 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
748 for (clock
.m2
= limit
->m2
.min
;
749 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
750 for (clock
.n
= limit
->n
.min
;
751 clock
.n
<= limit
->n
.max
; clock
.n
++) {
752 for (clock
.p1
= limit
->p1
.min
;
753 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
756 pnv_calc_dpll_params(refclk
, &clock
);
757 if (!intel_PLL_is_valid(to_i915(dev
),
762 clock
.p
!= match_clock
->p
)
765 this_err
= abs(clock
.dot
- target
);
766 if (this_err
< err
) {
775 return (err
!= target
);
779 * Returns a set of divisors for the desired target clock with the given
780 * refclk, or FALSE. The returned values represent the clock equation:
781 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
783 * Target and reference clocks are specified in kHz.
785 * If match_clock is provided, then best_clock P divider must match the P
786 * divider from @match_clock used for LVDS downclocking.
789 g4x_find_best_dpll(const struct intel_limit
*limit
,
790 struct intel_crtc_state
*crtc_state
,
791 int target
, int refclk
, struct dpll
*match_clock
,
792 struct dpll
*best_clock
)
794 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
798 /* approximately equals target * 0.00585 */
799 int err_most
= (target
>> 8) + (target
>> 9);
801 memset(best_clock
, 0, sizeof(*best_clock
));
803 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
805 max_n
= limit
->n
.max
;
806 /* based on hardware requirement, prefer smaller n to precision */
807 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
808 /* based on hardware requirement, prefere larger m1,m2 */
809 for (clock
.m1
= limit
->m1
.max
;
810 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
811 for (clock
.m2
= limit
->m2
.max
;
812 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
813 for (clock
.p1
= limit
->p1
.max
;
814 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
817 i9xx_calc_dpll_params(refclk
, &clock
);
818 if (!intel_PLL_is_valid(to_i915(dev
),
823 this_err
= abs(clock
.dot
- target
);
824 if (this_err
< err_most
) {
838 * Check if the calculated PLL configuration is more optimal compared to the
839 * best configuration and error found so far. Return the calculated error.
841 static bool vlv_PLL_is_optimal(struct drm_device
*dev
, int target_freq
,
842 const struct dpll
*calculated_clock
,
843 const struct dpll
*best_clock
,
844 unsigned int best_error_ppm
,
845 unsigned int *error_ppm
)
848 * For CHV ignore the error and consider only the P value.
849 * Prefer a bigger P value based on HW requirements.
851 if (IS_CHERRYVIEW(to_i915(dev
))) {
854 return calculated_clock
->p
> best_clock
->p
;
857 if (WARN_ON_ONCE(!target_freq
))
860 *error_ppm
= div_u64(1000000ULL *
861 abs(target_freq
- calculated_clock
->dot
),
864 * Prefer a better P value over a better (smaller) error if the error
865 * is small. Ensure this preference for future configurations too by
866 * setting the error to 0.
868 if (*error_ppm
< 100 && calculated_clock
->p
> best_clock
->p
) {
874 return *error_ppm
+ 10 < best_error_ppm
;
878 * Returns a set of divisors for the desired target clock with the given
879 * refclk, or FALSE. The returned values represent the clock equation:
880 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
883 vlv_find_best_dpll(const struct intel_limit
*limit
,
884 struct intel_crtc_state
*crtc_state
,
885 int target
, int refclk
, struct dpll
*match_clock
,
886 struct dpll
*best_clock
)
888 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
889 struct drm_device
*dev
= crtc
->base
.dev
;
891 unsigned int bestppm
= 1000000;
892 /* min update 19.2 MHz */
893 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
896 target
*= 5; /* fast clock */
898 memset(best_clock
, 0, sizeof(*best_clock
));
900 /* based on hardware requirement, prefer smaller n to precision */
901 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
902 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
903 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
904 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
905 clock
.p
= clock
.p1
* clock
.p2
;
906 /* based on hardware requirement, prefer bigger m1,m2 values */
907 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
910 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
913 vlv_calc_dpll_params(refclk
, &clock
);
915 if (!intel_PLL_is_valid(to_i915(dev
),
920 if (!vlv_PLL_is_optimal(dev
, target
,
938 * Returns a set of divisors for the desired target clock with the given
939 * refclk, or FALSE. The returned values represent the clock equation:
940 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
943 chv_find_best_dpll(const struct intel_limit
*limit
,
944 struct intel_crtc_state
*crtc_state
,
945 int target
, int refclk
, struct dpll
*match_clock
,
946 struct dpll
*best_clock
)
948 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
949 struct drm_device
*dev
= crtc
->base
.dev
;
950 unsigned int best_error_ppm
;
955 memset(best_clock
, 0, sizeof(*best_clock
));
956 best_error_ppm
= 1000000;
959 * Based on hardware doc, the n always set to 1, and m1 always
960 * set to 2. If requires to support 200Mhz refclk, we need to
961 * revisit this because n may not 1 anymore.
963 clock
.n
= 1, clock
.m1
= 2;
964 target
*= 5; /* fast clock */
966 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
967 for (clock
.p2
= limit
->p2
.p2_fast
;
968 clock
.p2
>= limit
->p2
.p2_slow
;
969 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
970 unsigned int error_ppm
;
972 clock
.p
= clock
.p1
* clock
.p2
;
974 m2
= DIV_ROUND_CLOSEST_ULL(((uint64_t)target
* clock
.p
*
975 clock
.n
) << 22, refclk
* clock
.m1
);
977 if (m2
> INT_MAX
/clock
.m1
)
982 chv_calc_dpll_params(refclk
, &clock
);
984 if (!intel_PLL_is_valid(to_i915(dev
), limit
, &clock
))
987 if (!vlv_PLL_is_optimal(dev
, target
, &clock
, best_clock
,
988 best_error_ppm
, &error_ppm
))
992 best_error_ppm
= error_ppm
;
1000 bool bxt_find_best_dpll(struct intel_crtc_state
*crtc_state
, int target_clock
,
1001 struct dpll
*best_clock
)
1003 int refclk
= 100000;
1004 const struct intel_limit
*limit
= &intel_limits_bxt
;
1006 return chv_find_best_dpll(limit
, crtc_state
,
1007 target_clock
, refclk
, NULL
, best_clock
);
1010 bool intel_crtc_active(struct drm_crtc
*crtc
)
1012 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1014 /* Be paranoid as we can arrive here with only partial
1015 * state retrieved from the hardware during setup.
1017 * We can ditch the adjusted_mode.crtc_clock check as soon
1018 * as Haswell has gained clock readout/fastboot support.
1020 * We can ditch the crtc->primary->fb check as soon as we can
1021 * properly reconstruct framebuffers.
1023 * FIXME: The intel_crtc->active here should be switched to
1024 * crtc->state->active once we have proper CRTC states wired up
1027 return intel_crtc
->active
&& crtc
->primary
->state
->fb
&&
1028 intel_crtc
->config
->base
.adjusted_mode
.crtc_clock
;
1031 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
1034 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1035 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1037 return intel_crtc
->config
->cpu_transcoder
;
1040 static bool pipe_dsl_stopped(struct drm_device
*dev
, enum pipe pipe
)
1042 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1043 i915_reg_t reg
= PIPEDSL(pipe
);
1047 if (IS_GEN2(dev_priv
))
1048 line_mask
= DSL_LINEMASK_GEN2
;
1050 line_mask
= DSL_LINEMASK_GEN3
;
1052 line1
= I915_READ(reg
) & line_mask
;
1054 line2
= I915_READ(reg
) & line_mask
;
1056 return line1
== line2
;
1060 * intel_wait_for_pipe_off - wait for pipe to turn off
1061 * @crtc: crtc whose pipe to wait for
1063 * After disabling a pipe, we can't wait for vblank in the usual way,
1064 * spinning on the vblank interrupt status bit, since we won't actually
1065 * see an interrupt when the pipe is disabled.
1067 * On Gen4 and above:
1068 * wait for the pipe register state bit to turn off
1071 * wait for the display line value to settle (it usually
1072 * ends up stopping at the start of the next frame).
1075 static void intel_wait_for_pipe_off(struct intel_crtc
*crtc
)
1077 struct drm_device
*dev
= crtc
->base
.dev
;
1078 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1079 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1080 enum pipe pipe
= crtc
->pipe
;
1082 if (INTEL_INFO(dev
)->gen
>= 4) {
1083 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
1085 /* Wait for the Pipe State to go off */
1086 if (intel_wait_for_register(dev_priv
,
1087 reg
, I965_PIPECONF_ACTIVE
, 0,
1089 WARN(1, "pipe_off wait timed out\n");
1091 /* Wait for the display line to settle */
1092 if (wait_for(pipe_dsl_stopped(dev
, pipe
), 100))
1093 WARN(1, "pipe_off wait timed out\n");
1097 /* Only for pre-ILK configs */
1098 void assert_pll(struct drm_i915_private
*dev_priv
,
1099 enum pipe pipe
, bool state
)
1104 val
= I915_READ(DPLL(pipe
));
1105 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1106 I915_STATE_WARN(cur_state
!= state
,
1107 "PLL state assertion failure (expected %s, current %s)\n",
1108 onoff(state
), onoff(cur_state
));
1111 /* XXX: the dsi pll is shared between MIPI DSI ports */
1112 void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1117 mutex_lock(&dev_priv
->sb_lock
);
1118 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1119 mutex_unlock(&dev_priv
->sb_lock
);
1121 cur_state
= val
& DSI_PLL_VCO_EN
;
1122 I915_STATE_WARN(cur_state
!= state
,
1123 "DSI PLL state assertion failure (expected %s, current %s)\n",
1124 onoff(state
), onoff(cur_state
));
1127 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1128 enum pipe pipe
, bool state
)
1131 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1134 if (HAS_DDI(dev_priv
)) {
1135 /* DDI does not have a specific FDI_TX register */
1136 u32 val
= I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder
));
1137 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1139 u32 val
= I915_READ(FDI_TX_CTL(pipe
));
1140 cur_state
= !!(val
& FDI_TX_ENABLE
);
1142 I915_STATE_WARN(cur_state
!= state
,
1143 "FDI TX state assertion failure (expected %s, current %s)\n",
1144 onoff(state
), onoff(cur_state
));
1146 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1147 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1149 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1150 enum pipe pipe
, bool state
)
1155 val
= I915_READ(FDI_RX_CTL(pipe
));
1156 cur_state
= !!(val
& FDI_RX_ENABLE
);
1157 I915_STATE_WARN(cur_state
!= state
,
1158 "FDI RX state assertion failure (expected %s, current %s)\n",
1159 onoff(state
), onoff(cur_state
));
1161 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1162 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1164 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1169 /* ILK FDI PLL is always enabled */
1170 if (IS_GEN5(dev_priv
))
1173 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1174 if (HAS_DDI(dev_priv
))
1177 val
= I915_READ(FDI_TX_CTL(pipe
));
1178 I915_STATE_WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1181 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1182 enum pipe pipe
, bool state
)
1187 val
= I915_READ(FDI_RX_CTL(pipe
));
1188 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1189 I915_STATE_WARN(cur_state
!= state
,
1190 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1191 onoff(state
), onoff(cur_state
));
1194 void assert_panel_unlocked(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1198 enum pipe panel_pipe
= PIPE_A
;
1201 if (WARN_ON(HAS_DDI(dev_priv
)))
1204 if (HAS_PCH_SPLIT(dev_priv
)) {
1207 pp_reg
= PP_CONTROL(0);
1208 port_sel
= I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK
;
1210 if (port_sel
== PANEL_PORT_SELECT_LVDS
&&
1211 I915_READ(PCH_LVDS
) & LVDS_PIPEB_SELECT
)
1212 panel_pipe
= PIPE_B
;
1213 /* XXX: else fix for eDP */
1214 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
1215 /* presumably write lock depends on pipe, not port select */
1216 pp_reg
= PP_CONTROL(pipe
);
1219 pp_reg
= PP_CONTROL(0);
1220 if (I915_READ(LVDS
) & LVDS_PIPEB_SELECT
)
1221 panel_pipe
= PIPE_B
;
1224 val
= I915_READ(pp_reg
);
1225 if (!(val
& PANEL_POWER_ON
) ||
1226 ((val
& PANEL_UNLOCK_MASK
) == PANEL_UNLOCK_REGS
))
1229 I915_STATE_WARN(panel_pipe
== pipe
&& locked
,
1230 "panel assertion failure, pipe %c regs locked\n",
1234 static void assert_cursor(struct drm_i915_private
*dev_priv
,
1235 enum pipe pipe
, bool state
)
1239 if (IS_845G(dev_priv
) || IS_I865G(dev_priv
))
1240 cur_state
= I915_READ(CURCNTR(PIPE_A
)) & CURSOR_ENABLE
;
1242 cur_state
= I915_READ(CURCNTR(pipe
)) & CURSOR_MODE
;
1244 I915_STATE_WARN(cur_state
!= state
,
1245 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1246 pipe_name(pipe
), onoff(state
), onoff(cur_state
));
1248 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1249 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1251 void assert_pipe(struct drm_i915_private
*dev_priv
,
1252 enum pipe pipe
, bool state
)
1255 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1257 enum intel_display_power_domain power_domain
;
1259 /* if we need the pipe quirk it must be always on */
1260 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1261 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1264 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
1265 if (intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
1266 u32 val
= I915_READ(PIPECONF(cpu_transcoder
));
1267 cur_state
= !!(val
& PIPECONF_ENABLE
);
1269 intel_display_power_put(dev_priv
, power_domain
);
1274 I915_STATE_WARN(cur_state
!= state
,
1275 "pipe %c assertion failure (expected %s, current %s)\n",
1276 pipe_name(pipe
), onoff(state
), onoff(cur_state
));
1279 static void assert_plane(struct drm_i915_private
*dev_priv
,
1280 enum plane plane
, bool state
)
1285 val
= I915_READ(DSPCNTR(plane
));
1286 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1287 I915_STATE_WARN(cur_state
!= state
,
1288 "plane %c assertion failure (expected %s, current %s)\n",
1289 plane_name(plane
), onoff(state
), onoff(cur_state
));
1292 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1293 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1295 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1298 struct drm_device
*dev
= &dev_priv
->drm
;
1301 /* Primary planes are fixed to pipes on gen4+ */
1302 if (INTEL_INFO(dev
)->gen
>= 4) {
1303 u32 val
= I915_READ(DSPCNTR(pipe
));
1304 I915_STATE_WARN(val
& DISPLAY_PLANE_ENABLE
,
1305 "plane %c assertion failure, should be disabled but not\n",
1310 /* Need to check both planes against the pipe */
1311 for_each_pipe(dev_priv
, i
) {
1312 u32 val
= I915_READ(DSPCNTR(i
));
1313 enum pipe cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1314 DISPPLANE_SEL_PIPE_SHIFT
;
1315 I915_STATE_WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1316 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1317 plane_name(i
), pipe_name(pipe
));
1321 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1324 struct drm_device
*dev
= &dev_priv
->drm
;
1327 if (INTEL_INFO(dev
)->gen
>= 9) {
1328 for_each_sprite(dev_priv
, pipe
, sprite
) {
1329 u32 val
= I915_READ(PLANE_CTL(pipe
, sprite
));
1330 I915_STATE_WARN(val
& PLANE_CTL_ENABLE
,
1331 "plane %d assertion failure, should be off on pipe %c but is still active\n",
1332 sprite
, pipe_name(pipe
));
1334 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
1335 for_each_sprite(dev_priv
, pipe
, sprite
) {
1336 u32 val
= I915_READ(SPCNTR(pipe
, sprite
));
1337 I915_STATE_WARN(val
& SP_ENABLE
,
1338 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1339 sprite_name(pipe
, sprite
), pipe_name(pipe
));
1341 } else if (INTEL_INFO(dev
)->gen
>= 7) {
1342 u32 val
= I915_READ(SPRCTL(pipe
));
1343 I915_STATE_WARN(val
& SPRITE_ENABLE
,
1344 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1345 plane_name(pipe
), pipe_name(pipe
));
1346 } else if (INTEL_INFO(dev
)->gen
>= 5) {
1347 u32 val
= I915_READ(DVSCNTR(pipe
));
1348 I915_STATE_WARN(val
& DVS_ENABLE
,
1349 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1350 plane_name(pipe
), pipe_name(pipe
));
1354 static void assert_vblank_disabled(struct drm_crtc
*crtc
)
1356 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc
) == 0))
1357 drm_crtc_vblank_put(crtc
);
1360 void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1366 val
= I915_READ(PCH_TRANSCONF(pipe
));
1367 enabled
= !!(val
& TRANS_ENABLE
);
1368 I915_STATE_WARN(enabled
,
1369 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1373 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1374 enum pipe pipe
, u32 port_sel
, u32 val
)
1376 if ((val
& DP_PORT_EN
) == 0)
1379 if (HAS_PCH_CPT(dev_priv
)) {
1380 u32 trans_dp_ctl
= I915_READ(TRANS_DP_CTL(pipe
));
1381 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1383 } else if (IS_CHERRYVIEW(dev_priv
)) {
1384 if ((val
& DP_PIPE_MASK_CHV
) != DP_PIPE_SELECT_CHV(pipe
))
1387 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1393 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1394 enum pipe pipe
, u32 val
)
1396 if ((val
& SDVO_ENABLE
) == 0)
1399 if (HAS_PCH_CPT(dev_priv
)) {
1400 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1402 } else if (IS_CHERRYVIEW(dev_priv
)) {
1403 if ((val
& SDVO_PIPE_SEL_MASK_CHV
) != SDVO_PIPE_SEL_CHV(pipe
))
1406 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1412 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1413 enum pipe pipe
, u32 val
)
1415 if ((val
& LVDS_PORT_EN
) == 0)
1418 if (HAS_PCH_CPT(dev_priv
)) {
1419 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1422 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1428 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1429 enum pipe pipe
, u32 val
)
1431 if ((val
& ADPA_DAC_ENABLE
) == 0)
1433 if (HAS_PCH_CPT(dev_priv
)) {
1434 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1437 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1443 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1444 enum pipe pipe
, i915_reg_t reg
,
1447 u32 val
= I915_READ(reg
);
1448 I915_STATE_WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1449 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1450 i915_mmio_reg_offset(reg
), pipe_name(pipe
));
1452 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
) && (val
& DP_PORT_EN
) == 0
1453 && (val
& DP_PIPEB_SELECT
),
1454 "IBX PCH dp port still using transcoder B\n");
1457 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1458 enum pipe pipe
, i915_reg_t reg
)
1460 u32 val
= I915_READ(reg
);
1461 I915_STATE_WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1462 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1463 i915_mmio_reg_offset(reg
), pipe_name(pipe
));
1465 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
) && (val
& SDVO_ENABLE
) == 0
1466 && (val
& SDVO_PIPE_B_SELECT
),
1467 "IBX PCH hdmi port still using transcoder B\n");
1470 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1475 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1476 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1477 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1479 val
= I915_READ(PCH_ADPA
);
1480 I915_STATE_WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1481 "PCH VGA enabled on transcoder %c, should be disabled\n",
1484 val
= I915_READ(PCH_LVDS
);
1485 I915_STATE_WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1486 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1489 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1490 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1491 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1494 static void _vlv_enable_pll(struct intel_crtc
*crtc
,
1495 const struct intel_crtc_state
*pipe_config
)
1497 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1498 enum pipe pipe
= crtc
->pipe
;
1500 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1501 POSTING_READ(DPLL(pipe
));
1504 if (intel_wait_for_register(dev_priv
,
1509 DRM_ERROR("DPLL %d failed to lock\n", pipe
);
1512 static void vlv_enable_pll(struct intel_crtc
*crtc
,
1513 const struct intel_crtc_state
*pipe_config
)
1515 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1516 enum pipe pipe
= crtc
->pipe
;
1518 assert_pipe_disabled(dev_priv
, pipe
);
1520 /* PLL is protected by panel, make sure we can write it */
1521 assert_panel_unlocked(dev_priv
, pipe
);
1523 if (pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
)
1524 _vlv_enable_pll(crtc
, pipe_config
);
1526 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1527 POSTING_READ(DPLL_MD(pipe
));
1531 static void _chv_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
;
1536 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1539 mutex_lock(&dev_priv
->sb_lock
);
1541 /* Enable back the 10bit clock to display controller */
1542 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1543 tmp
|= DPIO_DCLKP_EN
;
1544 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), tmp
);
1546 mutex_unlock(&dev_priv
->sb_lock
);
1549 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1554 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1556 /* Check PLL is locked */
1557 if (intel_wait_for_register(dev_priv
,
1558 DPLL(pipe
), DPLL_LOCK_VLV
, DPLL_LOCK_VLV
,
1560 DRM_ERROR("PLL %d failed to lock\n", pipe
);
1563 static void chv_enable_pll(struct intel_crtc
*crtc
,
1564 const struct intel_crtc_state
*pipe_config
)
1566 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1567 enum pipe pipe
= crtc
->pipe
;
1569 assert_pipe_disabled(dev_priv
, pipe
);
1571 /* PLL is protected by panel, make sure we can write it */
1572 assert_panel_unlocked(dev_priv
, pipe
);
1574 if (pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
)
1575 _chv_enable_pll(crtc
, pipe_config
);
1577 if (pipe
!= PIPE_A
) {
1579 * WaPixelRepeatModeFixForC0:chv
1581 * DPLLCMD is AWOL. Use chicken bits to propagate
1582 * the value from DPLLBMD to either pipe B or C.
1584 I915_WRITE(CBR4_VLV
, pipe
== PIPE_B
? CBR_DPLLBMD_PIPE_B
: CBR_DPLLBMD_PIPE_C
);
1585 I915_WRITE(DPLL_MD(PIPE_B
), pipe_config
->dpll_hw_state
.dpll_md
);
1586 I915_WRITE(CBR4_VLV
, 0);
1587 dev_priv
->chv_dpll_md
[pipe
] = pipe_config
->dpll_hw_state
.dpll_md
;
1590 * DPLLB VGA mode also seems to cause problems.
1591 * We should always have it disabled.
1593 WARN_ON((I915_READ(DPLL(PIPE_B
)) & DPLL_VGA_MODE_DIS
) == 0);
1595 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1596 POSTING_READ(DPLL_MD(pipe
));
1600 static int intel_num_dvo_pipes(struct drm_device
*dev
)
1602 struct intel_crtc
*crtc
;
1605 for_each_intel_crtc(dev
, crtc
) {
1606 count
+= crtc
->base
.state
->active
&&
1607 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_DVO
);
1613 static void i9xx_enable_pll(struct intel_crtc
*crtc
)
1615 struct drm_device
*dev
= crtc
->base
.dev
;
1616 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1617 i915_reg_t reg
= DPLL(crtc
->pipe
);
1618 u32 dpll
= crtc
->config
->dpll_hw_state
.dpll
;
1620 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1622 /* PLL is protected by panel, make sure we can write it */
1623 if (IS_MOBILE(dev_priv
) && !IS_I830(dev_priv
))
1624 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1626 /* Enable DVO 2x clock on both PLLs if necessary */
1627 if (IS_I830(dev_priv
) && intel_num_dvo_pipes(dev
) > 0) {
1629 * It appears to be important that we don't enable this
1630 * for the current pipe before otherwise configuring the
1631 * PLL. No idea how this should be handled if multiple
1632 * DVO outputs are enabled simultaneosly.
1634 dpll
|= DPLL_DVO_2X_MODE
;
1635 I915_WRITE(DPLL(!crtc
->pipe
),
1636 I915_READ(DPLL(!crtc
->pipe
)) | DPLL_DVO_2X_MODE
);
1640 * Apparently we need to have VGA mode enabled prior to changing
1641 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1642 * dividers, even though the register value does change.
1646 I915_WRITE(reg
, dpll
);
1648 /* Wait for the clocks to stabilize. */
1652 if (INTEL_INFO(dev
)->gen
>= 4) {
1653 I915_WRITE(DPLL_MD(crtc
->pipe
),
1654 crtc
->config
->dpll_hw_state
.dpll_md
);
1656 /* The pixel multiplier can only be updated once the
1657 * DPLL is enabled and the clocks are stable.
1659 * So write it again.
1661 I915_WRITE(reg
, dpll
);
1664 /* We do this three times for luck */
1665 I915_WRITE(reg
, dpll
);
1667 udelay(150); /* wait for warmup */
1668 I915_WRITE(reg
, dpll
);
1670 udelay(150); /* wait for warmup */
1671 I915_WRITE(reg
, dpll
);
1673 udelay(150); /* wait for warmup */
1677 * i9xx_disable_pll - disable a PLL
1678 * @dev_priv: i915 private structure
1679 * @pipe: pipe PLL to disable
1681 * Disable the PLL for @pipe, making sure the pipe is off first.
1683 * Note! This is for pre-ILK only.
1685 static void i9xx_disable_pll(struct intel_crtc
*crtc
)
1687 struct drm_device
*dev
= crtc
->base
.dev
;
1688 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1689 enum pipe pipe
= crtc
->pipe
;
1691 /* Disable DVO 2x clock on both PLLs if necessary */
1692 if (IS_I830(dev_priv
) &&
1693 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_DVO
) &&
1694 !intel_num_dvo_pipes(dev
)) {
1695 I915_WRITE(DPLL(PIPE_B
),
1696 I915_READ(DPLL(PIPE_B
)) & ~DPLL_DVO_2X_MODE
);
1697 I915_WRITE(DPLL(PIPE_A
),
1698 I915_READ(DPLL(PIPE_A
)) & ~DPLL_DVO_2X_MODE
);
1701 /* Don't disable pipe or pipe PLLs if needed */
1702 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1703 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1706 /* Make sure the pipe isn't still relying on us */
1707 assert_pipe_disabled(dev_priv
, pipe
);
1709 I915_WRITE(DPLL(pipe
), DPLL_VGA_MODE_DIS
);
1710 POSTING_READ(DPLL(pipe
));
1713 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1717 /* Make sure the pipe isn't still relying on us */
1718 assert_pipe_disabled(dev_priv
, pipe
);
1720 val
= DPLL_INTEGRATED_REF_CLK_VLV
|
1721 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1723 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1725 I915_WRITE(DPLL(pipe
), val
);
1726 POSTING_READ(DPLL(pipe
));
1729 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1731 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1734 /* Make sure the pipe isn't still relying on us */
1735 assert_pipe_disabled(dev_priv
, pipe
);
1737 val
= DPLL_SSC_REF_CLK_CHV
|
1738 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1740 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1742 I915_WRITE(DPLL(pipe
), val
);
1743 POSTING_READ(DPLL(pipe
));
1745 mutex_lock(&dev_priv
->sb_lock
);
1747 /* Disable 10bit clock to display controller */
1748 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1749 val
&= ~DPIO_DCLKP_EN
;
1750 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1752 mutex_unlock(&dev_priv
->sb_lock
);
1755 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1756 struct intel_digital_port
*dport
,
1757 unsigned int expected_mask
)
1760 i915_reg_t dpll_reg
;
1762 switch (dport
->port
) {
1764 port_mask
= DPLL_PORTB_READY_MASK
;
1768 port_mask
= DPLL_PORTC_READY_MASK
;
1770 expected_mask
<<= 4;
1773 port_mask
= DPLL_PORTD_READY_MASK
;
1774 dpll_reg
= DPIO_PHY_STATUS
;
1780 if (intel_wait_for_register(dev_priv
,
1781 dpll_reg
, port_mask
, expected_mask
,
1783 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1784 port_name(dport
->port
), I915_READ(dpll_reg
) & port_mask
, expected_mask
);
1787 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1790 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1791 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1793 uint32_t val
, pipeconf_val
;
1795 /* Make sure PCH DPLL is enabled */
1796 assert_shared_dpll_enabled(dev_priv
, intel_crtc
->config
->shared_dpll
);
1798 /* FDI must be feeding us bits for PCH ports */
1799 assert_fdi_tx_enabled(dev_priv
, pipe
);
1800 assert_fdi_rx_enabled(dev_priv
, pipe
);
1802 if (HAS_PCH_CPT(dev_priv
)) {
1803 /* Workaround: Set the timing override bit before enabling the
1804 * pch transcoder. */
1805 reg
= TRANS_CHICKEN2(pipe
);
1806 val
= I915_READ(reg
);
1807 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1808 I915_WRITE(reg
, val
);
1811 reg
= PCH_TRANSCONF(pipe
);
1812 val
= I915_READ(reg
);
1813 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1815 if (HAS_PCH_IBX(dev_priv
)) {
1817 * Make the BPC in transcoder be consistent with
1818 * that in pipeconf reg. For HDMI we must use 8bpc
1819 * here for both 8bpc and 12bpc.
1821 val
&= ~PIPECONF_BPC_MASK
;
1822 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_HDMI
))
1823 val
|= PIPECONF_8BPC
;
1825 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
1828 val
&= ~TRANS_INTERLACE_MASK
;
1829 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
1830 if (HAS_PCH_IBX(dev_priv
) &&
1831 intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
1832 val
|= TRANS_LEGACY_INTERLACED_ILK
;
1834 val
|= TRANS_INTERLACED
;
1836 val
|= TRANS_PROGRESSIVE
;
1838 I915_WRITE(reg
, val
| TRANS_ENABLE
);
1839 if (intel_wait_for_register(dev_priv
,
1840 reg
, TRANS_STATE_ENABLE
, TRANS_STATE_ENABLE
,
1842 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
1845 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1846 enum transcoder cpu_transcoder
)
1848 u32 val
, pipeconf_val
;
1850 /* FDI must be feeding us bits for PCH ports */
1851 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
1852 assert_fdi_rx_enabled(dev_priv
, TRANSCODER_A
);
1854 /* Workaround: set timing override bit. */
1855 val
= I915_READ(TRANS_CHICKEN2(PIPE_A
));
1856 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1857 I915_WRITE(TRANS_CHICKEN2(PIPE_A
), val
);
1860 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
1862 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
1863 PIPECONF_INTERLACED_ILK
)
1864 val
|= TRANS_INTERLACED
;
1866 val
|= TRANS_PROGRESSIVE
;
1868 I915_WRITE(LPT_TRANSCONF
, val
);
1869 if (intel_wait_for_register(dev_priv
,
1874 DRM_ERROR("Failed to enable PCH transcoder\n");
1877 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1883 /* FDI relies on the transcoder */
1884 assert_fdi_tx_disabled(dev_priv
, pipe
);
1885 assert_fdi_rx_disabled(dev_priv
, pipe
);
1887 /* Ports must be off as well */
1888 assert_pch_ports_disabled(dev_priv
, pipe
);
1890 reg
= PCH_TRANSCONF(pipe
);
1891 val
= I915_READ(reg
);
1892 val
&= ~TRANS_ENABLE
;
1893 I915_WRITE(reg
, val
);
1894 /* wait for PCH transcoder off, transcoder state */
1895 if (intel_wait_for_register(dev_priv
,
1896 reg
, TRANS_STATE_ENABLE
, 0,
1898 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
1900 if (HAS_PCH_CPT(dev_priv
)) {
1901 /* Workaround: Clear the timing override chicken bit again. */
1902 reg
= TRANS_CHICKEN2(pipe
);
1903 val
= I915_READ(reg
);
1904 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1905 I915_WRITE(reg
, val
);
1909 void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
1913 val
= I915_READ(LPT_TRANSCONF
);
1914 val
&= ~TRANS_ENABLE
;
1915 I915_WRITE(LPT_TRANSCONF
, val
);
1916 /* wait for PCH transcoder off, transcoder state */
1917 if (intel_wait_for_register(dev_priv
,
1918 LPT_TRANSCONF
, TRANS_STATE_ENABLE
, 0,
1920 DRM_ERROR("Failed to disable PCH transcoder\n");
1922 /* Workaround: clear timing override bit. */
1923 val
= I915_READ(TRANS_CHICKEN2(PIPE_A
));
1924 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1925 I915_WRITE(TRANS_CHICKEN2(PIPE_A
), val
);
1928 enum transcoder
intel_crtc_pch_transcoder(struct intel_crtc
*crtc
)
1930 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1932 WARN_ON(!crtc
->config
->has_pch_encoder
);
1934 if (HAS_PCH_LPT(dev_priv
))
1935 return TRANSCODER_A
;
1937 return (enum transcoder
) crtc
->pipe
;
1941 * intel_enable_pipe - enable a pipe, asserting requirements
1942 * @crtc: crtc responsible for the pipe
1944 * Enable @crtc's pipe, making sure that various hardware specific requirements
1945 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
1947 static void intel_enable_pipe(struct intel_crtc
*crtc
)
1949 struct drm_device
*dev
= crtc
->base
.dev
;
1950 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1951 enum pipe pipe
= crtc
->pipe
;
1952 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1956 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe
));
1958 assert_planes_disabled(dev_priv
, pipe
);
1959 assert_cursor_disabled(dev_priv
, pipe
);
1960 assert_sprites_disabled(dev_priv
, pipe
);
1963 * A pipe without a PLL won't actually be able to drive bits from
1964 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1967 if (HAS_GMCH_DISPLAY(dev_priv
)) {
1968 if (intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_DSI
))
1969 assert_dsi_pll_enabled(dev_priv
);
1971 assert_pll_enabled(dev_priv
, pipe
);
1973 if (crtc
->config
->has_pch_encoder
) {
1974 /* if driving the PCH, we need FDI enabled */
1975 assert_fdi_rx_pll_enabled(dev_priv
,
1976 (enum pipe
) intel_crtc_pch_transcoder(crtc
));
1977 assert_fdi_tx_pll_enabled(dev_priv
,
1978 (enum pipe
) cpu_transcoder
);
1980 /* FIXME: assert CPU port conditions for SNB+ */
1983 reg
= PIPECONF(cpu_transcoder
);
1984 val
= I915_READ(reg
);
1985 if (val
& PIPECONF_ENABLE
) {
1986 WARN_ON(!((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1987 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
)));
1991 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
1995 * Until the pipe starts DSL will read as 0, which would cause
1996 * an apparent vblank timestamp jump, which messes up also the
1997 * frame count when it's derived from the timestamps. So let's
1998 * wait for the pipe to start properly before we call
1999 * drm_crtc_vblank_on()
2001 if (dev
->max_vblank_count
== 0 &&
2002 wait_for(intel_get_crtc_scanline(crtc
) != crtc
->scanline_offset
, 50))
2003 DRM_ERROR("pipe %c didn't start\n", pipe_name(pipe
));
2007 * intel_disable_pipe - disable a pipe, asserting requirements
2008 * @crtc: crtc whose pipes is to be disabled
2010 * Disable the pipe of @crtc, making sure that various hardware
2011 * specific requirements are met, if applicable, e.g. plane
2012 * disabled, panel fitter off, etc.
2014 * Will wait until the pipe has shut down before returning.
2016 static void intel_disable_pipe(struct intel_crtc
*crtc
)
2018 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
2019 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
2020 enum pipe pipe
= crtc
->pipe
;
2024 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe
));
2027 * Make sure planes won't keep trying to pump pixels to us,
2028 * or we might hang the display.
2030 assert_planes_disabled(dev_priv
, pipe
);
2031 assert_cursor_disabled(dev_priv
, pipe
);
2032 assert_sprites_disabled(dev_priv
, pipe
);
2034 reg
= PIPECONF(cpu_transcoder
);
2035 val
= I915_READ(reg
);
2036 if ((val
& PIPECONF_ENABLE
) == 0)
2040 * Double wide has implications for planes
2041 * so best keep it disabled when not needed.
2043 if (crtc
->config
->double_wide
)
2044 val
&= ~PIPECONF_DOUBLE_WIDE
;
2046 /* Don't disable pipe or pipe PLLs if needed */
2047 if (!(pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) &&
2048 !(pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
2049 val
&= ~PIPECONF_ENABLE
;
2051 I915_WRITE(reg
, val
);
2052 if ((val
& PIPECONF_ENABLE
) == 0)
2053 intel_wait_for_pipe_off(crtc
);
2056 static unsigned int intel_tile_size(const struct drm_i915_private
*dev_priv
)
2058 return IS_GEN2(dev_priv
) ? 2048 : 4096;
2061 static unsigned int intel_tile_width_bytes(const struct drm_i915_private
*dev_priv
,
2062 uint64_t fb_modifier
, unsigned int cpp
)
2064 switch (fb_modifier
) {
2065 case DRM_FORMAT_MOD_NONE
:
2067 case I915_FORMAT_MOD_X_TILED
:
2068 if (IS_GEN2(dev_priv
))
2072 case I915_FORMAT_MOD_Y_TILED
:
2073 if (IS_GEN2(dev_priv
) || HAS_128_BYTE_Y_TILING(dev_priv
))
2077 case I915_FORMAT_MOD_Yf_TILED
:
2093 MISSING_CASE(fb_modifier
);
2098 unsigned int intel_tile_height(const struct drm_i915_private
*dev_priv
,
2099 uint64_t fb_modifier
, unsigned int cpp
)
2101 if (fb_modifier
== DRM_FORMAT_MOD_NONE
)
2104 return intel_tile_size(dev_priv
) /
2105 intel_tile_width_bytes(dev_priv
, fb_modifier
, cpp
);
2108 /* Return the tile dimensions in pixel units */
2109 static void intel_tile_dims(const struct drm_i915_private
*dev_priv
,
2110 unsigned int *tile_width
,
2111 unsigned int *tile_height
,
2112 uint64_t fb_modifier
,
2115 unsigned int tile_width_bytes
=
2116 intel_tile_width_bytes(dev_priv
, fb_modifier
, cpp
);
2118 *tile_width
= tile_width_bytes
/ cpp
;
2119 *tile_height
= intel_tile_size(dev_priv
) / tile_width_bytes
;
2123 intel_fb_align_height(struct drm_device
*dev
, unsigned int height
,
2124 uint32_t pixel_format
, uint64_t fb_modifier
)
2126 unsigned int cpp
= drm_format_plane_cpp(pixel_format
, 0);
2127 unsigned int tile_height
= intel_tile_height(to_i915(dev
), fb_modifier
, cpp
);
2129 return ALIGN(height
, tile_height
);
2132 unsigned int intel_rotation_info_size(const struct intel_rotation_info
*rot_info
)
2134 unsigned int size
= 0;
2137 for (i
= 0 ; i
< ARRAY_SIZE(rot_info
->plane
); i
++)
2138 size
+= rot_info
->plane
[i
].width
* rot_info
->plane
[i
].height
;
2144 intel_fill_fb_ggtt_view(struct i915_ggtt_view
*view
,
2145 const struct drm_framebuffer
*fb
,
2146 unsigned int rotation
)
2148 if (drm_rotation_90_or_270(rotation
)) {
2149 *view
= i915_ggtt_view_rotated
;
2150 view
->params
.rotated
= to_intel_framebuffer(fb
)->rot_info
;
2152 *view
= i915_ggtt_view_normal
;
2156 static unsigned int intel_linear_alignment(const struct drm_i915_private
*dev_priv
)
2158 if (INTEL_INFO(dev_priv
)->gen
>= 9)
2160 else if (IS_BROADWATER(dev_priv
) || IS_CRESTLINE(dev_priv
) ||
2161 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
2163 else if (INTEL_INFO(dev_priv
)->gen
>= 4)
2169 static unsigned int intel_surf_alignment(const struct drm_i915_private
*dev_priv
,
2170 uint64_t fb_modifier
)
2172 switch (fb_modifier
) {
2173 case DRM_FORMAT_MOD_NONE
:
2174 return intel_linear_alignment(dev_priv
);
2175 case I915_FORMAT_MOD_X_TILED
:
2176 if (INTEL_INFO(dev_priv
)->gen
>= 9)
2179 case I915_FORMAT_MOD_Y_TILED
:
2180 case I915_FORMAT_MOD_Yf_TILED
:
2181 return 1 * 1024 * 1024;
2183 MISSING_CASE(fb_modifier
);
2189 intel_pin_and_fence_fb_obj(struct drm_framebuffer
*fb
, unsigned int rotation
)
2191 struct drm_device
*dev
= fb
->dev
;
2192 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2193 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2194 struct i915_ggtt_view view
;
2195 struct i915_vma
*vma
;
2198 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
2200 alignment
= intel_surf_alignment(dev_priv
, fb
->modifier
[0]);
2202 intel_fill_fb_ggtt_view(&view
, fb
, rotation
);
2204 /* Note that the w/a also requires 64 PTE of padding following the
2205 * bo. We currently fill all unused PTE with the shadow page and so
2206 * we should always have valid PTE following the scanout preventing
2209 if (intel_scanout_needs_vtd_wa(dev_priv
) && alignment
< 256 * 1024)
2210 alignment
= 256 * 1024;
2213 * Global gtt pte registers are special registers which actually forward
2214 * writes to a chunk of system memory. Which means that there is no risk
2215 * that the register values disappear as soon as we call
2216 * intel_runtime_pm_put(), so it is correct to wrap only the
2217 * pin/unpin/fence and not more.
2219 intel_runtime_pm_get(dev_priv
);
2221 vma
= i915_gem_object_pin_to_display_plane(obj
, alignment
, &view
);
2225 if (i915_vma_is_map_and_fenceable(vma
)) {
2226 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2227 * fence, whereas 965+ only requires a fence if using
2228 * framebuffer compression. For simplicity, we always, when
2229 * possible, install a fence as the cost is not that onerous.
2231 * If we fail to fence the tiled scanout, then either the
2232 * modeset will reject the change (which is highly unlikely as
2233 * the affected systems, all but one, do not have unmappable
2234 * space) or we will not be able to enable full powersaving
2235 * techniques (also likely not to apply due to various limits
2236 * FBC and the like impose on the size of the buffer, which
2237 * presumably we violated anyway with this unmappable buffer).
2238 * Anyway, it is presumably better to stumble onwards with
2239 * something and try to run the system in a "less than optimal"
2240 * mode that matches the user configuration.
2242 if (i915_vma_get_fence(vma
) == 0)
2243 i915_vma_pin_fence(vma
);
2247 intel_runtime_pm_put(dev_priv
);
2251 void intel_unpin_fb_obj(struct drm_framebuffer
*fb
, unsigned int rotation
)
2253 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2254 struct i915_ggtt_view view
;
2255 struct i915_vma
*vma
;
2257 WARN_ON(!mutex_is_locked(&obj
->base
.dev
->struct_mutex
));
2259 intel_fill_fb_ggtt_view(&view
, fb
, rotation
);
2260 vma
= i915_gem_object_to_ggtt(obj
, &view
);
2262 i915_vma_unpin_fence(vma
);
2263 i915_gem_object_unpin_from_display_plane(vma
);
2266 static int intel_fb_pitch(const struct drm_framebuffer
*fb
, int plane
,
2267 unsigned int rotation
)
2269 if (drm_rotation_90_or_270(rotation
))
2270 return to_intel_framebuffer(fb
)->rotated
[plane
].pitch
;
2272 return fb
->pitches
[plane
];
2276 * Convert the x/y offsets into a linear offset.
2277 * Only valid with 0/180 degree rotation, which is fine since linear
2278 * offset is only used with linear buffers on pre-hsw and tiled buffers
2279 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2281 u32
intel_fb_xy_to_linear(int x
, int y
,
2282 const struct intel_plane_state
*state
,
2285 const struct drm_framebuffer
*fb
= state
->base
.fb
;
2286 unsigned int cpp
= drm_format_plane_cpp(fb
->pixel_format
, plane
);
2287 unsigned int pitch
= fb
->pitches
[plane
];
2289 return y
* pitch
+ x
* cpp
;
2293 * Add the x/y offsets derived from fb->offsets[] to the user
2294 * specified plane src x/y offsets. The resulting x/y offsets
2295 * specify the start of scanout from the beginning of the gtt mapping.
2297 void intel_add_fb_offsets(int *x
, int *y
,
2298 const struct intel_plane_state
*state
,
2302 const struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(state
->base
.fb
);
2303 unsigned int rotation
= state
->base
.rotation
;
2305 if (drm_rotation_90_or_270(rotation
)) {
2306 *x
+= intel_fb
->rotated
[plane
].x
;
2307 *y
+= intel_fb
->rotated
[plane
].y
;
2309 *x
+= intel_fb
->normal
[plane
].x
;
2310 *y
+= intel_fb
->normal
[plane
].y
;
2315 * Input tile dimensions and pitch must already be
2316 * rotated to match x and y, and in pixel units.
2318 static u32
_intel_adjust_tile_offset(int *x
, int *y
,
2319 unsigned int tile_width
,
2320 unsigned int tile_height
,
2321 unsigned int tile_size
,
2322 unsigned int pitch_tiles
,
2326 unsigned int pitch_pixels
= pitch_tiles
* tile_width
;
2329 WARN_ON(old_offset
& (tile_size
- 1));
2330 WARN_ON(new_offset
& (tile_size
- 1));
2331 WARN_ON(new_offset
> old_offset
);
2333 tiles
= (old_offset
- new_offset
) / tile_size
;
2335 *y
+= tiles
/ pitch_tiles
* tile_height
;
2336 *x
+= tiles
% pitch_tiles
* tile_width
;
2338 /* minimize x in case it got needlessly big */
2339 *y
+= *x
/ pitch_pixels
* tile_height
;
2346 * Adjust the tile offset by moving the difference into
2349 static u32
intel_adjust_tile_offset(int *x
, int *y
,
2350 const struct intel_plane_state
*state
, int plane
,
2351 u32 old_offset
, u32 new_offset
)
2353 const struct drm_i915_private
*dev_priv
= to_i915(state
->base
.plane
->dev
);
2354 const struct drm_framebuffer
*fb
= state
->base
.fb
;
2355 unsigned int cpp
= drm_format_plane_cpp(fb
->pixel_format
, plane
);
2356 unsigned int rotation
= state
->base
.rotation
;
2357 unsigned int pitch
= intel_fb_pitch(fb
, plane
, rotation
);
2359 WARN_ON(new_offset
> old_offset
);
2361 if (fb
->modifier
[plane
] != DRM_FORMAT_MOD_NONE
) {
2362 unsigned int tile_size
, tile_width
, tile_height
;
2363 unsigned int pitch_tiles
;
2365 tile_size
= intel_tile_size(dev_priv
);
2366 intel_tile_dims(dev_priv
, &tile_width
, &tile_height
,
2367 fb
->modifier
[plane
], cpp
);
2369 if (drm_rotation_90_or_270(rotation
)) {
2370 pitch_tiles
= pitch
/ tile_height
;
2371 swap(tile_width
, tile_height
);
2373 pitch_tiles
= pitch
/ (tile_width
* cpp
);
2376 _intel_adjust_tile_offset(x
, y
, tile_width
, tile_height
,
2377 tile_size
, pitch_tiles
,
2378 old_offset
, new_offset
);
2380 old_offset
+= *y
* pitch
+ *x
* cpp
;
2382 *y
= (old_offset
- new_offset
) / pitch
;
2383 *x
= ((old_offset
- new_offset
) - *y
* pitch
) / cpp
;
2390 * Computes the linear offset to the base tile and adjusts
2391 * x, y. bytes per pixel is assumed to be a power-of-two.
2393 * In the 90/270 rotated case, x and y are assumed
2394 * to be already rotated to match the rotated GTT view, and
2395 * pitch is the tile_height aligned framebuffer height.
2397 * This function is used when computing the derived information
2398 * under intel_framebuffer, so using any of that information
2399 * here is not allowed. Anything under drm_framebuffer can be
2400 * used. This is why the user has to pass in the pitch since it
2401 * is specified in the rotated orientation.
2403 static u32
_intel_compute_tile_offset(const struct drm_i915_private
*dev_priv
,
2405 const struct drm_framebuffer
*fb
, int plane
,
2407 unsigned int rotation
,
2410 uint64_t fb_modifier
= fb
->modifier
[plane
];
2411 unsigned int cpp
= drm_format_plane_cpp(fb
->pixel_format
, plane
);
2412 u32 offset
, offset_aligned
;
2417 if (fb_modifier
!= DRM_FORMAT_MOD_NONE
) {
2418 unsigned int tile_size
, tile_width
, tile_height
;
2419 unsigned int tile_rows
, tiles
, pitch_tiles
;
2421 tile_size
= intel_tile_size(dev_priv
);
2422 intel_tile_dims(dev_priv
, &tile_width
, &tile_height
,
2425 if (drm_rotation_90_or_270(rotation
)) {
2426 pitch_tiles
= pitch
/ tile_height
;
2427 swap(tile_width
, tile_height
);
2429 pitch_tiles
= pitch
/ (tile_width
* cpp
);
2432 tile_rows
= *y
/ tile_height
;
2435 tiles
= *x
/ tile_width
;
2438 offset
= (tile_rows
* pitch_tiles
+ tiles
) * tile_size
;
2439 offset_aligned
= offset
& ~alignment
;
2441 _intel_adjust_tile_offset(x
, y
, tile_width
, tile_height
,
2442 tile_size
, pitch_tiles
,
2443 offset
, offset_aligned
);
2445 offset
= *y
* pitch
+ *x
* cpp
;
2446 offset_aligned
= offset
& ~alignment
;
2448 *y
= (offset
& alignment
) / pitch
;
2449 *x
= ((offset
& alignment
) - *y
* pitch
) / cpp
;
2452 return offset_aligned
;
2455 u32
intel_compute_tile_offset(int *x
, int *y
,
2456 const struct intel_plane_state
*state
,
2459 const struct drm_i915_private
*dev_priv
= to_i915(state
->base
.plane
->dev
);
2460 const struct drm_framebuffer
*fb
= state
->base
.fb
;
2461 unsigned int rotation
= state
->base
.rotation
;
2462 int pitch
= intel_fb_pitch(fb
, plane
, rotation
);
2465 /* AUX_DIST needs only 4K alignment */
2466 if (fb
->pixel_format
== DRM_FORMAT_NV12
&& plane
== 1)
2469 alignment
= intel_surf_alignment(dev_priv
, fb
->modifier
[plane
]);
2471 return _intel_compute_tile_offset(dev_priv
, x
, y
, fb
, plane
, pitch
,
2472 rotation
, alignment
);
2475 /* Convert the fb->offset[] linear offset into x/y offsets */
2476 static void intel_fb_offset_to_xy(int *x
, int *y
,
2477 const struct drm_framebuffer
*fb
, int plane
)
2479 unsigned int cpp
= drm_format_plane_cpp(fb
->pixel_format
, plane
);
2480 unsigned int pitch
= fb
->pitches
[plane
];
2481 u32 linear_offset
= fb
->offsets
[plane
];
2483 *y
= linear_offset
/ pitch
;
2484 *x
= linear_offset
% pitch
/ cpp
;
2487 static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier
)
2489 switch (fb_modifier
) {
2490 case I915_FORMAT_MOD_X_TILED
:
2491 return I915_TILING_X
;
2492 case I915_FORMAT_MOD_Y_TILED
:
2493 return I915_TILING_Y
;
2495 return I915_TILING_NONE
;
2500 intel_fill_fb_info(struct drm_i915_private
*dev_priv
,
2501 struct drm_framebuffer
*fb
)
2503 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
2504 struct intel_rotation_info
*rot_info
= &intel_fb
->rot_info
;
2505 u32 gtt_offset_rotated
= 0;
2506 unsigned int max_size
= 0;
2507 uint32_t format
= fb
->pixel_format
;
2508 int i
, num_planes
= drm_format_num_planes(format
);
2509 unsigned int tile_size
= intel_tile_size(dev_priv
);
2511 for (i
= 0; i
< num_planes
; i
++) {
2512 unsigned int width
, height
;
2513 unsigned int cpp
, size
;
2517 cpp
= drm_format_plane_cpp(format
, i
);
2518 width
= drm_format_plane_width(fb
->width
, format
, i
);
2519 height
= drm_format_plane_height(fb
->height
, format
, i
);
2521 intel_fb_offset_to_xy(&x
, &y
, fb
, i
);
2524 * The fence (if used) is aligned to the start of the object
2525 * so having the framebuffer wrap around across the edge of the
2526 * fenced region doesn't really work. We have no API to configure
2527 * the fence start offset within the object (nor could we probably
2528 * on gen2/3). So it's just easier if we just require that the
2529 * fb layout agrees with the fence layout. We already check that the
2530 * fb stride matches the fence stride elsewhere.
2532 if (i915_gem_object_is_tiled(intel_fb
->obj
) &&
2533 (x
+ width
) * cpp
> fb
->pitches
[i
]) {
2534 DRM_DEBUG("bad fb plane %d offset: 0x%x\n",
2540 * First pixel of the framebuffer from
2541 * the start of the normal gtt mapping.
2543 intel_fb
->normal
[i
].x
= x
;
2544 intel_fb
->normal
[i
].y
= y
;
2546 offset
= _intel_compute_tile_offset(dev_priv
, &x
, &y
,
2547 fb
, 0, fb
->pitches
[i
],
2548 DRM_ROTATE_0
, tile_size
);
2549 offset
/= tile_size
;
2551 if (fb
->modifier
[i
] != DRM_FORMAT_MOD_NONE
) {
2552 unsigned int tile_width
, tile_height
;
2553 unsigned int pitch_tiles
;
2556 intel_tile_dims(dev_priv
, &tile_width
, &tile_height
,
2557 fb
->modifier
[i
], cpp
);
2559 rot_info
->plane
[i
].offset
= offset
;
2560 rot_info
->plane
[i
].stride
= DIV_ROUND_UP(fb
->pitches
[i
], tile_width
* cpp
);
2561 rot_info
->plane
[i
].width
= DIV_ROUND_UP(x
+ width
, tile_width
);
2562 rot_info
->plane
[i
].height
= DIV_ROUND_UP(y
+ height
, tile_height
);
2564 intel_fb
->rotated
[i
].pitch
=
2565 rot_info
->plane
[i
].height
* tile_height
;
2567 /* how many tiles does this plane need */
2568 size
= rot_info
->plane
[i
].stride
* rot_info
->plane
[i
].height
;
2570 * If the plane isn't horizontally tile aligned,
2571 * we need one more tile.
2576 /* rotate the x/y offsets to match the GTT view */
2582 rot_info
->plane
[i
].width
* tile_width
,
2583 rot_info
->plane
[i
].height
* tile_height
,
2588 /* rotate the tile dimensions to match the GTT view */
2589 pitch_tiles
= intel_fb
->rotated
[i
].pitch
/ tile_height
;
2590 swap(tile_width
, tile_height
);
2593 * We only keep the x/y offsets, so push all of the
2594 * gtt offset into the x/y offsets.
2596 _intel_adjust_tile_offset(&x
, &y
, tile_size
,
2597 tile_width
, tile_height
, pitch_tiles
,
2598 gtt_offset_rotated
* tile_size
, 0);
2600 gtt_offset_rotated
+= rot_info
->plane
[i
].width
* rot_info
->plane
[i
].height
;
2603 * First pixel of the framebuffer from
2604 * the start of the rotated gtt mapping.
2606 intel_fb
->rotated
[i
].x
= x
;
2607 intel_fb
->rotated
[i
].y
= y
;
2609 size
= DIV_ROUND_UP((y
+ height
) * fb
->pitches
[i
] +
2610 x
* cpp
, tile_size
);
2613 /* how many tiles in total needed in the bo */
2614 max_size
= max(max_size
, offset
+ size
);
2617 if (max_size
* tile_size
> to_intel_framebuffer(fb
)->obj
->base
.size
) {
2618 DRM_DEBUG("fb too big for bo (need %u bytes, have %zu bytes)\n",
2619 max_size
* tile_size
, to_intel_framebuffer(fb
)->obj
->base
.size
);
2626 static int i9xx_format_to_fourcc(int format
)
2629 case DISPPLANE_8BPP
:
2630 return DRM_FORMAT_C8
;
2631 case DISPPLANE_BGRX555
:
2632 return DRM_FORMAT_XRGB1555
;
2633 case DISPPLANE_BGRX565
:
2634 return DRM_FORMAT_RGB565
;
2636 case DISPPLANE_BGRX888
:
2637 return DRM_FORMAT_XRGB8888
;
2638 case DISPPLANE_RGBX888
:
2639 return DRM_FORMAT_XBGR8888
;
2640 case DISPPLANE_BGRX101010
:
2641 return DRM_FORMAT_XRGB2101010
;
2642 case DISPPLANE_RGBX101010
:
2643 return DRM_FORMAT_XBGR2101010
;
2647 static int skl_format_to_fourcc(int format
, bool rgb_order
, bool alpha
)
2650 case PLANE_CTL_FORMAT_RGB_565
:
2651 return DRM_FORMAT_RGB565
;
2653 case PLANE_CTL_FORMAT_XRGB_8888
:
2656 return DRM_FORMAT_ABGR8888
;
2658 return DRM_FORMAT_XBGR8888
;
2661 return DRM_FORMAT_ARGB8888
;
2663 return DRM_FORMAT_XRGB8888
;
2665 case PLANE_CTL_FORMAT_XRGB_2101010
:
2667 return DRM_FORMAT_XBGR2101010
;
2669 return DRM_FORMAT_XRGB2101010
;
2674 intel_alloc_initial_plane_obj(struct intel_crtc
*crtc
,
2675 struct intel_initial_plane_config
*plane_config
)
2677 struct drm_device
*dev
= crtc
->base
.dev
;
2678 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2679 struct i915_ggtt
*ggtt
= &dev_priv
->ggtt
;
2680 struct drm_i915_gem_object
*obj
= NULL
;
2681 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2682 struct drm_framebuffer
*fb
= &plane_config
->fb
->base
;
2683 u32 base_aligned
= round_down(plane_config
->base
, PAGE_SIZE
);
2684 u32 size_aligned
= round_up(plane_config
->base
+ plane_config
->size
,
2687 size_aligned
-= base_aligned
;
2689 if (plane_config
->size
== 0)
2692 /* If the FB is too big, just don't use it since fbdev is not very
2693 * important and we should probably use that space with FBC or other
2695 if (size_aligned
* 2 > ggtt
->stolen_usable_size
)
2698 mutex_lock(&dev
->struct_mutex
);
2700 obj
= i915_gem_object_create_stolen_for_preallocated(dev
,
2705 mutex_unlock(&dev
->struct_mutex
);
2709 if (plane_config
->tiling
== I915_TILING_X
)
2710 obj
->tiling_and_stride
= fb
->pitches
[0] | I915_TILING_X
;
2712 mode_cmd
.pixel_format
= fb
->pixel_format
;
2713 mode_cmd
.width
= fb
->width
;
2714 mode_cmd
.height
= fb
->height
;
2715 mode_cmd
.pitches
[0] = fb
->pitches
[0];
2716 mode_cmd
.modifier
[0] = fb
->modifier
[0];
2717 mode_cmd
.flags
= DRM_MODE_FB_MODIFIERS
;
2719 if (intel_framebuffer_init(dev
, to_intel_framebuffer(fb
),
2721 DRM_DEBUG_KMS("intel fb init failed\n");
2725 mutex_unlock(&dev
->struct_mutex
);
2727 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj
);
2731 i915_gem_object_put(obj
);
2732 mutex_unlock(&dev
->struct_mutex
);
2736 /* Update plane->state->fb to match plane->fb after driver-internal updates */
2738 update_state_fb(struct drm_plane
*plane
)
2740 if (plane
->fb
== plane
->state
->fb
)
2743 if (plane
->state
->fb
)
2744 drm_framebuffer_unreference(plane
->state
->fb
);
2745 plane
->state
->fb
= plane
->fb
;
2746 if (plane
->state
->fb
)
2747 drm_framebuffer_reference(plane
->state
->fb
);
2751 intel_find_initial_plane_obj(struct intel_crtc
*intel_crtc
,
2752 struct intel_initial_plane_config
*plane_config
)
2754 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2755 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2757 struct intel_crtc
*i
;
2758 struct drm_i915_gem_object
*obj
;
2759 struct drm_plane
*primary
= intel_crtc
->base
.primary
;
2760 struct drm_plane_state
*plane_state
= primary
->state
;
2761 struct drm_crtc_state
*crtc_state
= intel_crtc
->base
.state
;
2762 struct intel_plane
*intel_plane
= to_intel_plane(primary
);
2763 struct intel_plane_state
*intel_state
=
2764 to_intel_plane_state(plane_state
);
2765 struct drm_framebuffer
*fb
;
2767 if (!plane_config
->fb
)
2770 if (intel_alloc_initial_plane_obj(intel_crtc
, plane_config
)) {
2771 fb
= &plane_config
->fb
->base
;
2775 kfree(plane_config
->fb
);
2778 * Failed to alloc the obj, check to see if we should share
2779 * an fb with another CRTC instead
2781 for_each_crtc(dev
, c
) {
2782 i
= to_intel_crtc(c
);
2784 if (c
== &intel_crtc
->base
)
2790 fb
= c
->primary
->fb
;
2794 obj
= intel_fb_obj(fb
);
2795 if (i915_gem_object_ggtt_offset(obj
, NULL
) == plane_config
->base
) {
2796 drm_framebuffer_reference(fb
);
2802 * We've failed to reconstruct the BIOS FB. Current display state
2803 * indicates that the primary plane is visible, but has a NULL FB,
2804 * which will lead to problems later if we don't fix it up. The
2805 * simplest solution is to just disable the primary plane now and
2806 * pretend the BIOS never had it enabled.
2808 to_intel_plane_state(plane_state
)->base
.visible
= false;
2809 crtc_state
->plane_mask
&= ~(1 << drm_plane_index(primary
));
2810 intel_pre_disable_primary_noatomic(&intel_crtc
->base
);
2811 intel_plane
->disable_plane(primary
, &intel_crtc
->base
);
2816 plane_state
->src_x
= 0;
2817 plane_state
->src_y
= 0;
2818 plane_state
->src_w
= fb
->width
<< 16;
2819 plane_state
->src_h
= fb
->height
<< 16;
2821 plane_state
->crtc_x
= 0;
2822 plane_state
->crtc_y
= 0;
2823 plane_state
->crtc_w
= fb
->width
;
2824 plane_state
->crtc_h
= fb
->height
;
2826 intel_state
->base
.src
.x1
= plane_state
->src_x
;
2827 intel_state
->base
.src
.y1
= plane_state
->src_y
;
2828 intel_state
->base
.src
.x2
= plane_state
->src_x
+ plane_state
->src_w
;
2829 intel_state
->base
.src
.y2
= plane_state
->src_y
+ plane_state
->src_h
;
2830 intel_state
->base
.dst
.x1
= plane_state
->crtc_x
;
2831 intel_state
->base
.dst
.y1
= plane_state
->crtc_y
;
2832 intel_state
->base
.dst
.x2
= plane_state
->crtc_x
+ plane_state
->crtc_w
;
2833 intel_state
->base
.dst
.y2
= plane_state
->crtc_y
+ plane_state
->crtc_h
;
2835 obj
= intel_fb_obj(fb
);
2836 if (i915_gem_object_is_tiled(obj
))
2837 dev_priv
->preserve_bios_swizzle
= true;
2839 drm_framebuffer_reference(fb
);
2840 primary
->fb
= primary
->state
->fb
= fb
;
2841 primary
->crtc
= primary
->state
->crtc
= &intel_crtc
->base
;
2842 intel_crtc
->base
.state
->plane_mask
|= (1 << drm_plane_index(primary
));
2843 atomic_or(to_intel_plane(primary
)->frontbuffer_bit
,
2844 &obj
->frontbuffer_bits
);
2847 static int skl_max_plane_width(const struct drm_framebuffer
*fb
, int plane
,
2848 unsigned int rotation
)
2850 int cpp
= drm_format_plane_cpp(fb
->pixel_format
, plane
);
2852 switch (fb
->modifier
[plane
]) {
2853 case DRM_FORMAT_MOD_NONE
:
2854 case I915_FORMAT_MOD_X_TILED
:
2867 case I915_FORMAT_MOD_Y_TILED
:
2868 case I915_FORMAT_MOD_Yf_TILED
:
2883 MISSING_CASE(fb
->modifier
[plane
]);
2889 static int skl_check_main_surface(struct intel_plane_state
*plane_state
)
2891 const struct drm_i915_private
*dev_priv
= to_i915(plane_state
->base
.plane
->dev
);
2892 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2893 unsigned int rotation
= plane_state
->base
.rotation
;
2894 int x
= plane_state
->base
.src
.x1
>> 16;
2895 int y
= plane_state
->base
.src
.y1
>> 16;
2896 int w
= drm_rect_width(&plane_state
->base
.src
) >> 16;
2897 int h
= drm_rect_height(&plane_state
->base
.src
) >> 16;
2898 int max_width
= skl_max_plane_width(fb
, 0, rotation
);
2899 int max_height
= 4096;
2900 u32 alignment
, offset
, aux_offset
= plane_state
->aux
.offset
;
2902 if (w
> max_width
|| h
> max_height
) {
2903 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
2904 w
, h
, max_width
, max_height
);
2908 intel_add_fb_offsets(&x
, &y
, plane_state
, 0);
2909 offset
= intel_compute_tile_offset(&x
, &y
, plane_state
, 0);
2911 alignment
= intel_surf_alignment(dev_priv
, fb
->modifier
[0]);
2914 * AUX surface offset is specified as the distance from the
2915 * main surface offset, and it must be non-negative. Make
2916 * sure that is what we will get.
2918 if (offset
> aux_offset
)
2919 offset
= intel_adjust_tile_offset(&x
, &y
, plane_state
, 0,
2920 offset
, aux_offset
& ~(alignment
- 1));
2923 * When using an X-tiled surface, the plane blows up
2924 * if the x offset + width exceed the stride.
2926 * TODO: linear and Y-tiled seem fine, Yf untested,
2928 if (fb
->modifier
[0] == I915_FORMAT_MOD_X_TILED
) {
2929 int cpp
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2931 while ((x
+ w
) * cpp
> fb
->pitches
[0]) {
2933 DRM_DEBUG_KMS("Unable to find suitable display surface offset\n");
2937 offset
= intel_adjust_tile_offset(&x
, &y
, plane_state
, 0,
2938 offset
, offset
- alignment
);
2942 plane_state
->main
.offset
= offset
;
2943 plane_state
->main
.x
= x
;
2944 plane_state
->main
.y
= y
;
2949 static int skl_check_nv12_aux_surface(struct intel_plane_state
*plane_state
)
2951 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2952 unsigned int rotation
= plane_state
->base
.rotation
;
2953 int max_width
= skl_max_plane_width(fb
, 1, rotation
);
2954 int max_height
= 4096;
2955 int x
= plane_state
->base
.src
.x1
>> 17;
2956 int y
= plane_state
->base
.src
.y1
>> 17;
2957 int w
= drm_rect_width(&plane_state
->base
.src
) >> 17;
2958 int h
= drm_rect_height(&plane_state
->base
.src
) >> 17;
2961 intel_add_fb_offsets(&x
, &y
, plane_state
, 1);
2962 offset
= intel_compute_tile_offset(&x
, &y
, plane_state
, 1);
2964 /* FIXME not quite sure how/if these apply to the chroma plane */
2965 if (w
> max_width
|| h
> max_height
) {
2966 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
2967 w
, h
, max_width
, max_height
);
2971 plane_state
->aux
.offset
= offset
;
2972 plane_state
->aux
.x
= x
;
2973 plane_state
->aux
.y
= y
;
2978 int skl_check_plane_surface(struct intel_plane_state
*plane_state
)
2980 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2981 unsigned int rotation
= plane_state
->base
.rotation
;
2984 /* Rotate src coordinates to match rotated GTT view */
2985 if (drm_rotation_90_or_270(rotation
))
2986 drm_rect_rotate(&plane_state
->base
.src
,
2987 fb
->width
<< 16, fb
->height
<< 16,
2991 * Handle the AUX surface first since
2992 * the main surface setup depends on it.
2994 if (fb
->pixel_format
== DRM_FORMAT_NV12
) {
2995 ret
= skl_check_nv12_aux_surface(plane_state
);
2999 plane_state
->aux
.offset
= ~0xfff;
3000 plane_state
->aux
.x
= 0;
3001 plane_state
->aux
.y
= 0;
3004 ret
= skl_check_main_surface(plane_state
);
3011 static void i9xx_update_primary_plane(struct drm_plane
*primary
,
3012 const struct intel_crtc_state
*crtc_state
,
3013 const struct intel_plane_state
*plane_state
)
3015 struct drm_device
*dev
= primary
->dev
;
3016 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3017 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
3018 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
3019 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
3020 int plane
= intel_crtc
->plane
;
3023 i915_reg_t reg
= DSPCNTR(plane
);
3024 unsigned int rotation
= plane_state
->base
.rotation
;
3025 int x
= plane_state
->base
.src
.x1
>> 16;
3026 int y
= plane_state
->base
.src
.y1
>> 16;
3028 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
3030 dspcntr
|= DISPLAY_PLANE_ENABLE
;
3032 if (INTEL_INFO(dev
)->gen
< 4) {
3033 if (intel_crtc
->pipe
== PIPE_B
)
3034 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
3036 /* pipesrc and dspsize control the size that is scaled from,
3037 * which should always be the user's requested size.
3039 I915_WRITE(DSPSIZE(plane
),
3040 ((crtc_state
->pipe_src_h
- 1) << 16) |
3041 (crtc_state
->pipe_src_w
- 1));
3042 I915_WRITE(DSPPOS(plane
), 0);
3043 } else if (IS_CHERRYVIEW(dev_priv
) && plane
== PLANE_B
) {
3044 I915_WRITE(PRIMSIZE(plane
),
3045 ((crtc_state
->pipe_src_h
- 1) << 16) |
3046 (crtc_state
->pipe_src_w
- 1));
3047 I915_WRITE(PRIMPOS(plane
), 0);
3048 I915_WRITE(PRIMCNSTALPHA(plane
), 0);
3051 switch (fb
->pixel_format
) {
3053 dspcntr
|= DISPPLANE_8BPP
;
3055 case DRM_FORMAT_XRGB1555
:
3056 dspcntr
|= DISPPLANE_BGRX555
;
3058 case DRM_FORMAT_RGB565
:
3059 dspcntr
|= DISPPLANE_BGRX565
;
3061 case DRM_FORMAT_XRGB8888
:
3062 dspcntr
|= DISPPLANE_BGRX888
;
3064 case DRM_FORMAT_XBGR8888
:
3065 dspcntr
|= DISPPLANE_RGBX888
;
3067 case DRM_FORMAT_XRGB2101010
:
3068 dspcntr
|= DISPPLANE_BGRX101010
;
3070 case DRM_FORMAT_XBGR2101010
:
3071 dspcntr
|= DISPPLANE_RGBX101010
;
3077 if (INTEL_GEN(dev_priv
) >= 4 &&
3078 fb
->modifier
[0] == I915_FORMAT_MOD_X_TILED
)
3079 dspcntr
|= DISPPLANE_TILED
;
3081 if (IS_G4X(dev_priv
))
3082 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
3084 intel_add_fb_offsets(&x
, &y
, plane_state
, 0);
3086 if (INTEL_INFO(dev
)->gen
>= 4)
3087 intel_crtc
->dspaddr_offset
=
3088 intel_compute_tile_offset(&x
, &y
, plane_state
, 0);
3090 if (rotation
== DRM_ROTATE_180
) {
3091 dspcntr
|= DISPPLANE_ROTATE_180
;
3093 x
+= (crtc_state
->pipe_src_w
- 1);
3094 y
+= (crtc_state
->pipe_src_h
- 1);
3097 linear_offset
= intel_fb_xy_to_linear(x
, y
, plane_state
, 0);
3099 if (INTEL_INFO(dev
)->gen
< 4)
3100 intel_crtc
->dspaddr_offset
= linear_offset
;
3102 intel_crtc
->adjusted_x
= x
;
3103 intel_crtc
->adjusted_y
= y
;
3105 I915_WRITE(reg
, dspcntr
);
3107 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
3108 if (INTEL_INFO(dev
)->gen
>= 4) {
3109 I915_WRITE(DSPSURF(plane
),
3110 intel_fb_gtt_offset(fb
, rotation
) +
3111 intel_crtc
->dspaddr_offset
);
3112 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
3113 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
3115 I915_WRITE(DSPADDR(plane
), i915_gem_object_ggtt_offset(obj
, NULL
) + linear_offset
);
3119 static void i9xx_disable_primary_plane(struct drm_plane
*primary
,
3120 struct drm_crtc
*crtc
)
3122 struct drm_device
*dev
= crtc
->dev
;
3123 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3124 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3125 int plane
= intel_crtc
->plane
;
3127 I915_WRITE(DSPCNTR(plane
), 0);
3128 if (INTEL_INFO(dev_priv
)->gen
>= 4)
3129 I915_WRITE(DSPSURF(plane
), 0);
3131 I915_WRITE(DSPADDR(plane
), 0);
3132 POSTING_READ(DSPCNTR(plane
));
3135 static void ironlake_update_primary_plane(struct drm_plane
*primary
,
3136 const struct intel_crtc_state
*crtc_state
,
3137 const struct intel_plane_state
*plane_state
)
3139 struct drm_device
*dev
= primary
->dev
;
3140 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3141 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
3142 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
3143 int plane
= intel_crtc
->plane
;
3146 i915_reg_t reg
= DSPCNTR(plane
);
3147 unsigned int rotation
= plane_state
->base
.rotation
;
3148 int x
= plane_state
->base
.src
.x1
>> 16;
3149 int y
= plane_state
->base
.src
.y1
>> 16;
3151 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
3152 dspcntr
|= DISPLAY_PLANE_ENABLE
;
3154 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
3155 dspcntr
|= DISPPLANE_PIPE_CSC_ENABLE
;
3157 switch (fb
->pixel_format
) {
3159 dspcntr
|= DISPPLANE_8BPP
;
3161 case DRM_FORMAT_RGB565
:
3162 dspcntr
|= DISPPLANE_BGRX565
;
3164 case DRM_FORMAT_XRGB8888
:
3165 dspcntr
|= DISPPLANE_BGRX888
;
3167 case DRM_FORMAT_XBGR8888
:
3168 dspcntr
|= DISPPLANE_RGBX888
;
3170 case DRM_FORMAT_XRGB2101010
:
3171 dspcntr
|= DISPPLANE_BGRX101010
;
3173 case DRM_FORMAT_XBGR2101010
:
3174 dspcntr
|= DISPPLANE_RGBX101010
;
3180 if (fb
->modifier
[0] == I915_FORMAT_MOD_X_TILED
)
3181 dspcntr
|= DISPPLANE_TILED
;
3183 if (!IS_HASWELL(dev_priv
) && !IS_BROADWELL(dev_priv
))
3184 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
3186 intel_add_fb_offsets(&x
, &y
, plane_state
, 0);
3188 intel_crtc
->dspaddr_offset
=
3189 intel_compute_tile_offset(&x
, &y
, plane_state
, 0);
3191 if (rotation
== DRM_ROTATE_180
) {
3192 dspcntr
|= DISPPLANE_ROTATE_180
;
3194 if (!IS_HASWELL(dev_priv
) && !IS_BROADWELL(dev_priv
)) {
3195 x
+= (crtc_state
->pipe_src_w
- 1);
3196 y
+= (crtc_state
->pipe_src_h
- 1);
3200 linear_offset
= intel_fb_xy_to_linear(x
, y
, plane_state
, 0);
3202 intel_crtc
->adjusted_x
= x
;
3203 intel_crtc
->adjusted_y
= y
;
3205 I915_WRITE(reg
, dspcntr
);
3207 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
3208 I915_WRITE(DSPSURF(plane
),
3209 intel_fb_gtt_offset(fb
, rotation
) +
3210 intel_crtc
->dspaddr_offset
);
3211 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
3212 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
3214 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
3215 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
3220 u32
intel_fb_stride_alignment(const struct drm_i915_private
*dev_priv
,
3221 uint64_t fb_modifier
, uint32_t pixel_format
)
3223 if (fb_modifier
== DRM_FORMAT_MOD_NONE
) {
3226 int cpp
= drm_format_plane_cpp(pixel_format
, 0);
3228 return intel_tile_width_bytes(dev_priv
, fb_modifier
, cpp
);
3232 u32
intel_fb_gtt_offset(struct drm_framebuffer
*fb
,
3233 unsigned int rotation
)
3235 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
3236 struct i915_ggtt_view view
;
3237 struct i915_vma
*vma
;
3239 intel_fill_fb_ggtt_view(&view
, fb
, rotation
);
3241 vma
= i915_gem_object_to_ggtt(obj
, &view
);
3242 if (WARN(!vma
, "ggtt vma for display object not found! (view=%u)\n",
3246 return i915_ggtt_offset(vma
);
3249 static void skl_detach_scaler(struct intel_crtc
*intel_crtc
, int id
)
3251 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3252 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3254 I915_WRITE(SKL_PS_CTRL(intel_crtc
->pipe
, id
), 0);
3255 I915_WRITE(SKL_PS_WIN_POS(intel_crtc
->pipe
, id
), 0);
3256 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc
->pipe
, id
), 0);
3260 * This function detaches (aka. unbinds) unused scalers in hardware
3262 static void skl_detach_scalers(struct intel_crtc
*intel_crtc
)
3264 struct intel_crtc_scaler_state
*scaler_state
;
3267 scaler_state
= &intel_crtc
->config
->scaler_state
;
3269 /* loop through and disable scalers that aren't in use */
3270 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
3271 if (!scaler_state
->scalers
[i
].in_use
)
3272 skl_detach_scaler(intel_crtc
, i
);
3276 u32
skl_plane_stride(const struct drm_framebuffer
*fb
, int plane
,
3277 unsigned int rotation
)
3279 const struct drm_i915_private
*dev_priv
= to_i915(fb
->dev
);
3280 u32 stride
= intel_fb_pitch(fb
, plane
, rotation
);
3283 * The stride is either expressed as a multiple of 64 bytes chunks for
3284 * linear buffers or in number of tiles for tiled buffers.
3286 if (drm_rotation_90_or_270(rotation
)) {
3287 int cpp
= drm_format_plane_cpp(fb
->pixel_format
, plane
);
3289 stride
/= intel_tile_height(dev_priv
, fb
->modifier
[0], cpp
);
3291 stride
/= intel_fb_stride_alignment(dev_priv
, fb
->modifier
[0],
3298 u32
skl_plane_ctl_format(uint32_t pixel_format
)
3300 switch (pixel_format
) {
3302 return PLANE_CTL_FORMAT_INDEXED
;
3303 case DRM_FORMAT_RGB565
:
3304 return PLANE_CTL_FORMAT_RGB_565
;
3305 case DRM_FORMAT_XBGR8888
:
3306 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
;
3307 case DRM_FORMAT_XRGB8888
:
3308 return PLANE_CTL_FORMAT_XRGB_8888
;
3310 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
3311 * to be already pre-multiplied. We need to add a knob (or a different
3312 * DRM_FORMAT) for user-space to configure that.
3314 case DRM_FORMAT_ABGR8888
:
3315 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
|
3316 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
3317 case DRM_FORMAT_ARGB8888
:
3318 return PLANE_CTL_FORMAT_XRGB_8888
|
3319 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
3320 case DRM_FORMAT_XRGB2101010
:
3321 return PLANE_CTL_FORMAT_XRGB_2101010
;
3322 case DRM_FORMAT_XBGR2101010
:
3323 return PLANE_CTL_ORDER_RGBX
| PLANE_CTL_FORMAT_XRGB_2101010
;
3324 case DRM_FORMAT_YUYV
:
3325 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YUYV
;
3326 case DRM_FORMAT_YVYU
:
3327 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YVYU
;
3328 case DRM_FORMAT_UYVY
:
3329 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_UYVY
;
3330 case DRM_FORMAT_VYUY
:
3331 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_VYUY
;
3333 MISSING_CASE(pixel_format
);
3339 u32
skl_plane_ctl_tiling(uint64_t fb_modifier
)
3341 switch (fb_modifier
) {
3342 case DRM_FORMAT_MOD_NONE
:
3344 case I915_FORMAT_MOD_X_TILED
:
3345 return PLANE_CTL_TILED_X
;
3346 case I915_FORMAT_MOD_Y_TILED
:
3347 return PLANE_CTL_TILED_Y
;
3348 case I915_FORMAT_MOD_Yf_TILED
:
3349 return PLANE_CTL_TILED_YF
;
3351 MISSING_CASE(fb_modifier
);
3357 u32
skl_plane_ctl_rotation(unsigned int rotation
)
3363 * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr
3364 * while i915 HW rotation is clockwise, thats why this swapping.
3367 return PLANE_CTL_ROTATE_270
;
3368 case DRM_ROTATE_180
:
3369 return PLANE_CTL_ROTATE_180
;
3370 case DRM_ROTATE_270
:
3371 return PLANE_CTL_ROTATE_90
;
3373 MISSING_CASE(rotation
);
3379 static void skylake_update_primary_plane(struct drm_plane
*plane
,
3380 const struct intel_crtc_state
*crtc_state
,
3381 const struct intel_plane_state
*plane_state
)
3383 struct drm_device
*dev
= plane
->dev
;
3384 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3385 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
3386 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
3387 const struct skl_wm_values
*wm
= &dev_priv
->wm
.skl_results
;
3388 const struct skl_plane_wm
*p_wm
=
3389 &crtc_state
->wm
.skl
.optimal
.planes
[0];
3390 int pipe
= intel_crtc
->pipe
;
3392 unsigned int rotation
= plane_state
->base
.rotation
;
3393 u32 stride
= skl_plane_stride(fb
, 0, rotation
);
3394 u32 surf_addr
= plane_state
->main
.offset
;
3395 int scaler_id
= plane_state
->scaler_id
;
3396 int src_x
= plane_state
->main
.x
;
3397 int src_y
= plane_state
->main
.y
;
3398 int src_w
= drm_rect_width(&plane_state
->base
.src
) >> 16;
3399 int src_h
= drm_rect_height(&plane_state
->base
.src
) >> 16;
3400 int dst_x
= plane_state
->base
.dst
.x1
;
3401 int dst_y
= plane_state
->base
.dst
.y1
;
3402 int dst_w
= drm_rect_width(&plane_state
->base
.dst
);
3403 int dst_h
= drm_rect_height(&plane_state
->base
.dst
);
3405 plane_ctl
= PLANE_CTL_ENABLE
|
3406 PLANE_CTL_PIPE_GAMMA_ENABLE
|
3407 PLANE_CTL_PIPE_CSC_ENABLE
;
3409 plane_ctl
|= skl_plane_ctl_format(fb
->pixel_format
);
3410 plane_ctl
|= skl_plane_ctl_tiling(fb
->modifier
[0]);
3411 plane_ctl
|= PLANE_CTL_PLANE_GAMMA_DISABLE
;
3412 plane_ctl
|= skl_plane_ctl_rotation(rotation
);
3414 /* Sizes are 0 based */
3420 intel_crtc
->dspaddr_offset
= surf_addr
;
3422 intel_crtc
->adjusted_x
= src_x
;
3423 intel_crtc
->adjusted_y
= src_y
;
3425 if (wm
->dirty_pipes
& drm_crtc_mask(&intel_crtc
->base
))
3426 skl_write_plane_wm(intel_crtc
, p_wm
, &wm
->ddb
, 0);
3428 I915_WRITE(PLANE_CTL(pipe
, 0), plane_ctl
);
3429 I915_WRITE(PLANE_OFFSET(pipe
, 0), (src_y
<< 16) | src_x
);
3430 I915_WRITE(PLANE_STRIDE(pipe
, 0), stride
);
3431 I915_WRITE(PLANE_SIZE(pipe
, 0), (src_h
<< 16) | src_w
);
3433 if (scaler_id
>= 0) {
3434 uint32_t ps_ctrl
= 0;
3436 WARN_ON(!dst_w
|| !dst_h
);
3437 ps_ctrl
= PS_SCALER_EN
| PS_PLANE_SEL(0) |
3438 crtc_state
->scaler_state
.scalers
[scaler_id
].mode
;
3439 I915_WRITE(SKL_PS_CTRL(pipe
, scaler_id
), ps_ctrl
);
3440 I915_WRITE(SKL_PS_PWR_GATE(pipe
, scaler_id
), 0);
3441 I915_WRITE(SKL_PS_WIN_POS(pipe
, scaler_id
), (dst_x
<< 16) | dst_y
);
3442 I915_WRITE(SKL_PS_WIN_SZ(pipe
, scaler_id
), (dst_w
<< 16) | dst_h
);
3443 I915_WRITE(PLANE_POS(pipe
, 0), 0);
3445 I915_WRITE(PLANE_POS(pipe
, 0), (dst_y
<< 16) | dst_x
);
3448 I915_WRITE(PLANE_SURF(pipe
, 0),
3449 intel_fb_gtt_offset(fb
, rotation
) + surf_addr
);
3451 POSTING_READ(PLANE_SURF(pipe
, 0));
3454 static void skylake_disable_primary_plane(struct drm_plane
*primary
,
3455 struct drm_crtc
*crtc
)
3457 struct drm_device
*dev
= crtc
->dev
;
3458 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3459 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3460 struct intel_crtc_state
*cstate
= to_intel_crtc_state(crtc
->state
);
3461 const struct skl_plane_wm
*p_wm
= &cstate
->wm
.skl
.optimal
.planes
[0];
3462 int pipe
= intel_crtc
->pipe
;
3465 * We only populate skl_results on watermark updates, and if the
3466 * plane's visiblity isn't actually changing neither is its watermarks.
3468 if (!crtc
->primary
->state
->visible
)
3469 skl_write_plane_wm(intel_crtc
, p_wm
,
3470 &dev_priv
->wm
.skl_results
.ddb
, 0);
3472 I915_WRITE(PLANE_CTL(pipe
, 0), 0);
3473 I915_WRITE(PLANE_SURF(pipe
, 0), 0);
3474 POSTING_READ(PLANE_SURF(pipe
, 0));
3477 /* Assume fb object is pinned & idle & fenced and just update base pointers */
3479 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
3480 int x
, int y
, enum mode_set_atomic state
)
3482 /* Support for kgdboc is disabled, this needs a major rework. */
3483 DRM_ERROR("legacy panic handler not supported any more.\n");
3488 static void intel_complete_page_flips(struct drm_i915_private
*dev_priv
)
3490 struct intel_crtc
*crtc
;
3492 for_each_intel_crtc(&dev_priv
->drm
, crtc
)
3493 intel_finish_page_flip_cs(dev_priv
, crtc
->pipe
);
3496 static void intel_update_primary_planes(struct drm_device
*dev
)
3498 struct drm_crtc
*crtc
;
3500 for_each_crtc(dev
, crtc
) {
3501 struct intel_plane
*plane
= to_intel_plane(crtc
->primary
);
3502 struct intel_plane_state
*plane_state
=
3503 to_intel_plane_state(plane
->base
.state
);
3505 if (plane_state
->base
.visible
)
3506 plane
->update_plane(&plane
->base
,
3507 to_intel_crtc_state(crtc
->state
),
3513 __intel_display_resume(struct drm_device
*dev
,
3514 struct drm_atomic_state
*state
)
3516 struct drm_crtc_state
*crtc_state
;
3517 struct drm_crtc
*crtc
;
3520 intel_modeset_setup_hw_state(dev
);
3521 i915_redisable_vga(dev
);
3526 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
3528 * Force recalculation even if we restore
3529 * current state. With fast modeset this may not result
3530 * in a modeset when the state is compatible.
3532 crtc_state
->mode_changed
= true;
3535 /* ignore any reset values/BIOS leftovers in the WM registers */
3536 to_intel_atomic_state(state
)->skip_intermediate_wm
= true;
3538 ret
= drm_atomic_commit(state
);
3540 WARN_ON(ret
== -EDEADLK
);
3544 static bool gpu_reset_clobbers_display(struct drm_i915_private
*dev_priv
)
3546 return intel_has_gpu_reset(dev_priv
) &&
3547 INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
);
3550 void intel_prepare_reset(struct drm_i915_private
*dev_priv
)
3552 struct drm_device
*dev
= &dev_priv
->drm
;
3553 struct drm_modeset_acquire_ctx
*ctx
= &dev_priv
->reset_ctx
;
3554 struct drm_atomic_state
*state
;
3558 * Need mode_config.mutex so that we don't
3559 * trample ongoing ->detect() and whatnot.
3561 mutex_lock(&dev
->mode_config
.mutex
);
3562 drm_modeset_acquire_init(ctx
, 0);
3564 ret
= drm_modeset_lock_all_ctx(dev
, ctx
);
3565 if (ret
!= -EDEADLK
)
3568 drm_modeset_backoff(ctx
);
3571 /* reset doesn't touch the display, but flips might get nuked anyway, */
3572 if (!i915
.force_reset_modeset_test
&&
3573 !gpu_reset_clobbers_display(dev_priv
))
3577 * Disabling the crtcs gracefully seems nicer. Also the
3578 * g33 docs say we should at least disable all the planes.
3580 state
= drm_atomic_helper_duplicate_state(dev
, ctx
);
3581 if (IS_ERR(state
)) {
3582 ret
= PTR_ERR(state
);
3584 DRM_ERROR("Duplicating state failed with %i\n", ret
);
3588 ret
= drm_atomic_helper_disable_all(dev
, ctx
);
3590 DRM_ERROR("Suspending crtc's failed with %i\n", ret
);
3594 dev_priv
->modeset_restore_state
= state
;
3595 state
->acquire_ctx
= ctx
;
3599 drm_atomic_state_put(state
);
3602 void intel_finish_reset(struct drm_i915_private
*dev_priv
)
3604 struct drm_device
*dev
= &dev_priv
->drm
;
3605 struct drm_modeset_acquire_ctx
*ctx
= &dev_priv
->reset_ctx
;
3606 struct drm_atomic_state
*state
= dev_priv
->modeset_restore_state
;
3610 * Flips in the rings will be nuked by the reset,
3611 * so complete all pending flips so that user space
3612 * will get its events and not get stuck.
3614 intel_complete_page_flips(dev_priv
);
3616 dev_priv
->modeset_restore_state
= NULL
;
3618 /* reset doesn't touch the display */
3619 if (!gpu_reset_clobbers_display(dev_priv
)) {
3622 * Flips in the rings have been nuked by the reset,
3623 * so update the base address of all primary
3624 * planes to the the last fb to make sure we're
3625 * showing the correct fb after a reset.
3627 * FIXME: Atomic will make this obsolete since we won't schedule
3628 * CS-based flips (which might get lost in gpu resets) any more.
3630 intel_update_primary_planes(dev
);
3632 ret
= __intel_display_resume(dev
, state
);
3634 DRM_ERROR("Restoring old state failed with %i\n", ret
);
3638 * The display has been reset as well,
3639 * so need a full re-initialization.
3641 intel_runtime_pm_disable_interrupts(dev_priv
);
3642 intel_runtime_pm_enable_interrupts(dev_priv
);
3644 intel_pps_unlock_regs_wa(dev_priv
);
3645 intel_modeset_init_hw(dev
);
3647 spin_lock_irq(&dev_priv
->irq_lock
);
3648 if (dev_priv
->display
.hpd_irq_setup
)
3649 dev_priv
->display
.hpd_irq_setup(dev_priv
);
3650 spin_unlock_irq(&dev_priv
->irq_lock
);
3652 ret
= __intel_display_resume(dev
, state
);
3654 DRM_ERROR("Restoring old state failed with %i\n", ret
);
3656 intel_hpd_init(dev_priv
);
3660 drm_atomic_state_put(state
);
3661 drm_modeset_drop_locks(ctx
);
3662 drm_modeset_acquire_fini(ctx
);
3663 mutex_unlock(&dev
->mode_config
.mutex
);
3666 static bool abort_flip_on_reset(struct intel_crtc
*crtc
)
3668 struct i915_gpu_error
*error
= &to_i915(crtc
->base
.dev
)->gpu_error
;
3670 if (i915_reset_in_progress(error
))
3673 if (crtc
->reset_count
!= i915_reset_count(error
))
3679 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
3681 struct drm_device
*dev
= crtc
->dev
;
3682 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3685 if (abort_flip_on_reset(intel_crtc
))
3688 spin_lock_irq(&dev
->event_lock
);
3689 pending
= to_intel_crtc(crtc
)->flip_work
!= NULL
;
3690 spin_unlock_irq(&dev
->event_lock
);
3695 static void intel_update_pipe_config(struct intel_crtc
*crtc
,
3696 struct intel_crtc_state
*old_crtc_state
)
3698 struct drm_device
*dev
= crtc
->base
.dev
;
3699 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3700 struct intel_crtc_state
*pipe_config
=
3701 to_intel_crtc_state(crtc
->base
.state
);
3703 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
3704 crtc
->base
.mode
= crtc
->base
.state
->mode
;
3706 DRM_DEBUG_KMS("Updating pipe size %ix%i -> %ix%i\n",
3707 old_crtc_state
->pipe_src_w
, old_crtc_state
->pipe_src_h
,
3708 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
3711 * Update pipe size and adjust fitter if needed: the reason for this is
3712 * that in compute_mode_changes we check the native mode (not the pfit
3713 * mode) to see if we can flip rather than do a full mode set. In the
3714 * fastboot case, we'll flip, but if we don't update the pipesrc and
3715 * pfit state, we'll end up with a big fb scanned out into the wrong
3719 I915_WRITE(PIPESRC(crtc
->pipe
),
3720 ((pipe_config
->pipe_src_w
- 1) << 16) |
3721 (pipe_config
->pipe_src_h
- 1));
3723 /* on skylake this is done by detaching scalers */
3724 if (INTEL_INFO(dev
)->gen
>= 9) {
3725 skl_detach_scalers(crtc
);
3727 if (pipe_config
->pch_pfit
.enabled
)
3728 skylake_pfit_enable(crtc
);
3729 } else if (HAS_PCH_SPLIT(dev_priv
)) {
3730 if (pipe_config
->pch_pfit
.enabled
)
3731 ironlake_pfit_enable(crtc
);
3732 else if (old_crtc_state
->pch_pfit
.enabled
)
3733 ironlake_pfit_disable(crtc
, true);
3737 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
3739 struct drm_device
*dev
= crtc
->dev
;
3740 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3741 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3742 int pipe
= intel_crtc
->pipe
;
3746 /* enable normal train */
3747 reg
= FDI_TX_CTL(pipe
);
3748 temp
= I915_READ(reg
);
3749 if (IS_IVYBRIDGE(dev_priv
)) {
3750 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3751 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3753 temp
&= ~FDI_LINK_TRAIN_NONE
;
3754 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3756 I915_WRITE(reg
, temp
);
3758 reg
= FDI_RX_CTL(pipe
);
3759 temp
= I915_READ(reg
);
3760 if (HAS_PCH_CPT(dev_priv
)) {
3761 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3762 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
3764 temp
&= ~FDI_LINK_TRAIN_NONE
;
3765 temp
|= FDI_LINK_TRAIN_NONE
;
3767 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
3769 /* wait one idle pattern time */
3773 /* IVB wants error correction enabled */
3774 if (IS_IVYBRIDGE(dev_priv
))
3775 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
3776 FDI_FE_ERRC_ENABLE
);
3779 /* The FDI link training functions for ILK/Ibexpeak. */
3780 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
3782 struct drm_device
*dev
= crtc
->dev
;
3783 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3784 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3785 int pipe
= intel_crtc
->pipe
;
3789 /* FDI needs bits from pipe first */
3790 assert_pipe_enabled(dev_priv
, pipe
);
3792 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3794 reg
= FDI_RX_IMR(pipe
);
3795 temp
= I915_READ(reg
);
3796 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3797 temp
&= ~FDI_RX_BIT_LOCK
;
3798 I915_WRITE(reg
, temp
);
3802 /* enable CPU FDI TX and PCH FDI RX */
3803 reg
= FDI_TX_CTL(pipe
);
3804 temp
= I915_READ(reg
);
3805 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3806 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3807 temp
&= ~FDI_LINK_TRAIN_NONE
;
3808 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3809 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3811 reg
= FDI_RX_CTL(pipe
);
3812 temp
= I915_READ(reg
);
3813 temp
&= ~FDI_LINK_TRAIN_NONE
;
3814 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3815 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3820 /* Ironlake workaround, enable clock pointer after FDI enable*/
3821 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3822 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
3823 FDI_RX_PHASE_SYNC_POINTER_EN
);
3825 reg
= FDI_RX_IIR(pipe
);
3826 for (tries
= 0; tries
< 5; tries
++) {
3827 temp
= I915_READ(reg
);
3828 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3830 if ((temp
& FDI_RX_BIT_LOCK
)) {
3831 DRM_DEBUG_KMS("FDI train 1 done.\n");
3832 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3837 DRM_ERROR("FDI train 1 fail!\n");
3840 reg
= FDI_TX_CTL(pipe
);
3841 temp
= I915_READ(reg
);
3842 temp
&= ~FDI_LINK_TRAIN_NONE
;
3843 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3844 I915_WRITE(reg
, temp
);
3846 reg
= FDI_RX_CTL(pipe
);
3847 temp
= I915_READ(reg
);
3848 temp
&= ~FDI_LINK_TRAIN_NONE
;
3849 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3850 I915_WRITE(reg
, temp
);
3855 reg
= FDI_RX_IIR(pipe
);
3856 for (tries
= 0; tries
< 5; tries
++) {
3857 temp
= I915_READ(reg
);
3858 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3860 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3861 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3862 DRM_DEBUG_KMS("FDI train 2 done.\n");
3867 DRM_ERROR("FDI train 2 fail!\n");
3869 DRM_DEBUG_KMS("FDI train done\n");
3873 static const int snb_b_fdi_train_param
[] = {
3874 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
3875 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
3876 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
3877 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
3880 /* The FDI link training functions for SNB/Cougarpoint. */
3881 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
3883 struct drm_device
*dev
= crtc
->dev
;
3884 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3885 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3886 int pipe
= intel_crtc
->pipe
;
3890 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3892 reg
= FDI_RX_IMR(pipe
);
3893 temp
= I915_READ(reg
);
3894 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3895 temp
&= ~FDI_RX_BIT_LOCK
;
3896 I915_WRITE(reg
, temp
);
3901 /* enable CPU FDI TX and PCH FDI RX */
3902 reg
= FDI_TX_CTL(pipe
);
3903 temp
= I915_READ(reg
);
3904 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3905 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3906 temp
&= ~FDI_LINK_TRAIN_NONE
;
3907 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3908 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3910 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3911 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3913 I915_WRITE(FDI_RX_MISC(pipe
),
3914 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3916 reg
= FDI_RX_CTL(pipe
);
3917 temp
= I915_READ(reg
);
3918 if (HAS_PCH_CPT(dev_priv
)) {
3919 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3920 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3922 temp
&= ~FDI_LINK_TRAIN_NONE
;
3923 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3925 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3930 for (i
= 0; i
< 4; i
++) {
3931 reg
= FDI_TX_CTL(pipe
);
3932 temp
= I915_READ(reg
);
3933 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3934 temp
|= snb_b_fdi_train_param
[i
];
3935 I915_WRITE(reg
, temp
);
3940 for (retry
= 0; retry
< 5; retry
++) {
3941 reg
= FDI_RX_IIR(pipe
);
3942 temp
= I915_READ(reg
);
3943 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3944 if (temp
& FDI_RX_BIT_LOCK
) {
3945 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3946 DRM_DEBUG_KMS("FDI train 1 done.\n");
3955 DRM_ERROR("FDI train 1 fail!\n");
3958 reg
= FDI_TX_CTL(pipe
);
3959 temp
= I915_READ(reg
);
3960 temp
&= ~FDI_LINK_TRAIN_NONE
;
3961 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3962 if (IS_GEN6(dev_priv
)) {
3963 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3965 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3967 I915_WRITE(reg
, temp
);
3969 reg
= FDI_RX_CTL(pipe
);
3970 temp
= I915_READ(reg
);
3971 if (HAS_PCH_CPT(dev_priv
)) {
3972 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3973 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3975 temp
&= ~FDI_LINK_TRAIN_NONE
;
3976 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3978 I915_WRITE(reg
, temp
);
3983 for (i
= 0; i
< 4; i
++) {
3984 reg
= FDI_TX_CTL(pipe
);
3985 temp
= I915_READ(reg
);
3986 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3987 temp
|= snb_b_fdi_train_param
[i
];
3988 I915_WRITE(reg
, temp
);
3993 for (retry
= 0; retry
< 5; retry
++) {
3994 reg
= FDI_RX_IIR(pipe
);
3995 temp
= I915_READ(reg
);
3996 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3997 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3998 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3999 DRM_DEBUG_KMS("FDI train 2 done.\n");
4008 DRM_ERROR("FDI train 2 fail!\n");
4010 DRM_DEBUG_KMS("FDI train done.\n");
4013 /* Manual link training for Ivy Bridge A0 parts */
4014 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
4016 struct drm_device
*dev
= crtc
->dev
;
4017 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4018 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4019 int pipe
= intel_crtc
->pipe
;
4023 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4025 reg
= FDI_RX_IMR(pipe
);
4026 temp
= I915_READ(reg
);
4027 temp
&= ~FDI_RX_SYMBOL_LOCK
;
4028 temp
&= ~FDI_RX_BIT_LOCK
;
4029 I915_WRITE(reg
, temp
);
4034 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4035 I915_READ(FDI_RX_IIR(pipe
)));
4037 /* Try each vswing and preemphasis setting twice before moving on */
4038 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
4039 /* disable first in case we need to retry */
4040 reg
= FDI_TX_CTL(pipe
);
4041 temp
= I915_READ(reg
);
4042 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
4043 temp
&= ~FDI_TX_ENABLE
;
4044 I915_WRITE(reg
, temp
);
4046 reg
= FDI_RX_CTL(pipe
);
4047 temp
= I915_READ(reg
);
4048 temp
&= ~FDI_LINK_TRAIN_AUTO
;
4049 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
4050 temp
&= ~FDI_RX_ENABLE
;
4051 I915_WRITE(reg
, temp
);
4053 /* enable CPU FDI TX and PCH FDI RX */
4054 reg
= FDI_TX_CTL(pipe
);
4055 temp
= I915_READ(reg
);
4056 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
4057 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
4058 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
4059 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
4060 temp
|= snb_b_fdi_train_param
[j
/2];
4061 temp
|= FDI_COMPOSITE_SYNC
;
4062 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
4064 I915_WRITE(FDI_RX_MISC(pipe
),
4065 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
4067 reg
= FDI_RX_CTL(pipe
);
4068 temp
= I915_READ(reg
);
4069 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
4070 temp
|= FDI_COMPOSITE_SYNC
;
4071 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
4074 udelay(1); /* should be 0.5us */
4076 for (i
= 0; i
< 4; i
++) {
4077 reg
= FDI_RX_IIR(pipe
);
4078 temp
= I915_READ(reg
);
4079 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
4081 if (temp
& FDI_RX_BIT_LOCK
||
4082 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
4083 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
4084 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4088 udelay(1); /* should be 0.5us */
4091 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
4096 reg
= FDI_TX_CTL(pipe
);
4097 temp
= I915_READ(reg
);
4098 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
4099 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
4100 I915_WRITE(reg
, temp
);
4102 reg
= FDI_RX_CTL(pipe
);
4103 temp
= I915_READ(reg
);
4104 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
4105 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
4106 I915_WRITE(reg
, temp
);
4109 udelay(2); /* should be 1.5us */
4111 for (i
= 0; i
< 4; i
++) {
4112 reg
= FDI_RX_IIR(pipe
);
4113 temp
= I915_READ(reg
);
4114 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
4116 if (temp
& FDI_RX_SYMBOL_LOCK
||
4117 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
4118 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
4119 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4123 udelay(2); /* should be 1.5us */
4126 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
4130 DRM_DEBUG_KMS("FDI train done.\n");
4133 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
4135 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4136 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4137 int pipe
= intel_crtc
->pipe
;
4141 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4142 reg
= FDI_RX_CTL(pipe
);
4143 temp
= I915_READ(reg
);
4144 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
4145 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
4146 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
4147 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
4152 /* Switch from Rawclk to PCDclk */
4153 temp
= I915_READ(reg
);
4154 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
4159 /* Enable CPU FDI TX PLL, always on for Ironlake */
4160 reg
= FDI_TX_CTL(pipe
);
4161 temp
= I915_READ(reg
);
4162 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
4163 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
4170 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
4172 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4173 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4174 int pipe
= intel_crtc
->pipe
;
4178 /* Switch from PCDclk to Rawclk */
4179 reg
= FDI_RX_CTL(pipe
);
4180 temp
= I915_READ(reg
);
4181 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
4183 /* Disable CPU FDI TX PLL */
4184 reg
= FDI_TX_CTL(pipe
);
4185 temp
= I915_READ(reg
);
4186 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
4191 reg
= FDI_RX_CTL(pipe
);
4192 temp
= I915_READ(reg
);
4193 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
4195 /* Wait for the clocks to turn off. */
4200 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
4202 struct drm_device
*dev
= crtc
->dev
;
4203 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4204 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4205 int pipe
= intel_crtc
->pipe
;
4209 /* disable CPU FDI tx and PCH FDI rx */
4210 reg
= FDI_TX_CTL(pipe
);
4211 temp
= I915_READ(reg
);
4212 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
4215 reg
= FDI_RX_CTL(pipe
);
4216 temp
= I915_READ(reg
);
4217 temp
&= ~(0x7 << 16);
4218 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
4219 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
4224 /* Ironlake workaround, disable clock pointer after downing FDI */
4225 if (HAS_PCH_IBX(dev_priv
))
4226 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
4228 /* still set train pattern 1 */
4229 reg
= FDI_TX_CTL(pipe
);
4230 temp
= I915_READ(reg
);
4231 temp
&= ~FDI_LINK_TRAIN_NONE
;
4232 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
4233 I915_WRITE(reg
, temp
);
4235 reg
= FDI_RX_CTL(pipe
);
4236 temp
= I915_READ(reg
);
4237 if (HAS_PCH_CPT(dev_priv
)) {
4238 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
4239 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
4241 temp
&= ~FDI_LINK_TRAIN_NONE
;
4242 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
4244 /* BPC in FDI rx is consistent with that in PIPECONF */
4245 temp
&= ~(0x07 << 16);
4246 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
4247 I915_WRITE(reg
, temp
);
4253 bool intel_has_pending_fb_unpin(struct drm_device
*dev
)
4255 struct intel_crtc
*crtc
;
4257 /* Note that we don't need to be called with mode_config.lock here
4258 * as our list of CRTC objects is static for the lifetime of the
4259 * device and so cannot disappear as we iterate. Similarly, we can
4260 * happily treat the predicates as racy, atomic checks as userspace
4261 * cannot claim and pin a new fb without at least acquring the
4262 * struct_mutex and so serialising with us.
4264 for_each_intel_crtc(dev
, crtc
) {
4265 if (atomic_read(&crtc
->unpin_work_count
) == 0)
4268 if (crtc
->flip_work
)
4269 intel_wait_for_vblank(dev
, crtc
->pipe
);
4277 static void page_flip_completed(struct intel_crtc
*intel_crtc
)
4279 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
4280 struct intel_flip_work
*work
= intel_crtc
->flip_work
;
4282 intel_crtc
->flip_work
= NULL
;
4285 drm_crtc_send_vblank_event(&intel_crtc
->base
, work
->event
);
4287 drm_crtc_vblank_put(&intel_crtc
->base
);
4289 wake_up_all(&dev_priv
->pending_flip_queue
);
4290 queue_work(dev_priv
->wq
, &work
->unpin_work
);
4292 trace_i915_flip_complete(intel_crtc
->plane
,
4293 work
->pending_flip_obj
);
4296 static int intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
4298 struct drm_device
*dev
= crtc
->dev
;
4299 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4302 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
4304 ret
= wait_event_interruptible_timeout(
4305 dev_priv
->pending_flip_queue
,
4306 !intel_crtc_has_pending_flip(crtc
),
4313 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4314 struct intel_flip_work
*work
;
4316 spin_lock_irq(&dev
->event_lock
);
4317 work
= intel_crtc
->flip_work
;
4318 if (work
&& !is_mmio_work(work
)) {
4319 WARN_ONCE(1, "Removing stuck page flip\n");
4320 page_flip_completed(intel_crtc
);
4322 spin_unlock_irq(&dev
->event_lock
);
4328 void lpt_disable_iclkip(struct drm_i915_private
*dev_priv
)
4332 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
4334 mutex_lock(&dev_priv
->sb_lock
);
4336 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4337 temp
|= SBI_SSCCTL_DISABLE
;
4338 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
4340 mutex_unlock(&dev_priv
->sb_lock
);
4343 /* Program iCLKIP clock to the desired frequency */
4344 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
4346 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
4347 int clock
= to_intel_crtc(crtc
)->config
->base
.adjusted_mode
.crtc_clock
;
4348 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
4351 lpt_disable_iclkip(dev_priv
);
4353 /* The iCLK virtual clock root frequency is in MHz,
4354 * but the adjusted_mode->crtc_clock in in KHz. To get the
4355 * divisors, it is necessary to divide one by another, so we
4356 * convert the virtual clock precision to KHz here for higher
4359 for (auxdiv
= 0; auxdiv
< 2; auxdiv
++) {
4360 u32 iclk_virtual_root_freq
= 172800 * 1000;
4361 u32 iclk_pi_range
= 64;
4362 u32 desired_divisor
;
4364 desired_divisor
= DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
4366 divsel
= (desired_divisor
/ iclk_pi_range
) - 2;
4367 phaseinc
= desired_divisor
% iclk_pi_range
;
4370 * Near 20MHz is a corner case which is
4371 * out of range for the 7-bit divisor
4377 /* This should not happen with any sane values */
4378 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
4379 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
4380 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
4381 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
4383 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4390 mutex_lock(&dev_priv
->sb_lock
);
4392 /* Program SSCDIVINTPHASE6 */
4393 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
4394 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
4395 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
4396 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
4397 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
4398 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
4399 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
4400 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
4402 /* Program SSCAUXDIV */
4403 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
4404 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4405 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
4406 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
4408 /* Enable modulator and associated divider */
4409 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4410 temp
&= ~SBI_SSCCTL_DISABLE
;
4411 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
4413 mutex_unlock(&dev_priv
->sb_lock
);
4415 /* Wait for initialization time */
4418 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
4421 int lpt_get_iclkip(struct drm_i915_private
*dev_priv
)
4423 u32 divsel
, phaseinc
, auxdiv
;
4424 u32 iclk_virtual_root_freq
= 172800 * 1000;
4425 u32 iclk_pi_range
= 64;
4426 u32 desired_divisor
;
4429 if ((I915_READ(PIXCLK_GATE
) & PIXCLK_GATE_UNGATE
) == 0)
4432 mutex_lock(&dev_priv
->sb_lock
);
4434 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4435 if (temp
& SBI_SSCCTL_DISABLE
) {
4436 mutex_unlock(&dev_priv
->sb_lock
);
4440 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
4441 divsel
= (temp
& SBI_SSCDIVINTPHASE_DIVSEL_MASK
) >>
4442 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT
;
4443 phaseinc
= (temp
& SBI_SSCDIVINTPHASE_INCVAL_MASK
) >>
4444 SBI_SSCDIVINTPHASE_INCVAL_SHIFT
;
4446 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
4447 auxdiv
= (temp
& SBI_SSCAUXDIV_FINALDIV2SEL_MASK
) >>
4448 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT
;
4450 mutex_unlock(&dev_priv
->sb_lock
);
4452 desired_divisor
= (divsel
+ 2) * iclk_pi_range
+ phaseinc
;
4454 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
4455 desired_divisor
<< auxdiv
);
4458 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
4459 enum pipe pch_transcoder
)
4461 struct drm_device
*dev
= crtc
->base
.dev
;
4462 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4463 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
4465 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
4466 I915_READ(HTOTAL(cpu_transcoder
)));
4467 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
4468 I915_READ(HBLANK(cpu_transcoder
)));
4469 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
4470 I915_READ(HSYNC(cpu_transcoder
)));
4472 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
4473 I915_READ(VTOTAL(cpu_transcoder
)));
4474 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
4475 I915_READ(VBLANK(cpu_transcoder
)));
4476 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
4477 I915_READ(VSYNC(cpu_transcoder
)));
4478 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
4479 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
4482 static void cpt_set_fdi_bc_bifurcation(struct drm_device
*dev
, bool enable
)
4484 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4487 temp
= I915_READ(SOUTH_CHICKEN1
);
4488 if (!!(temp
& FDI_BC_BIFURCATION_SELECT
) == enable
)
4491 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
4492 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
4494 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
4496 temp
|= FDI_BC_BIFURCATION_SELECT
;
4498 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable
? "en" : "dis");
4499 I915_WRITE(SOUTH_CHICKEN1
, temp
);
4500 POSTING_READ(SOUTH_CHICKEN1
);
4503 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
4505 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4507 switch (intel_crtc
->pipe
) {
4511 if (intel_crtc
->config
->fdi_lanes
> 2)
4512 cpt_set_fdi_bc_bifurcation(dev
, false);
4514 cpt_set_fdi_bc_bifurcation(dev
, true);
4518 cpt_set_fdi_bc_bifurcation(dev
, true);
4526 /* Return which DP Port should be selected for Transcoder DP control */
4528 intel_trans_dp_port_sel(struct drm_crtc
*crtc
)
4530 struct drm_device
*dev
= crtc
->dev
;
4531 struct intel_encoder
*encoder
;
4533 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4534 if (encoder
->type
== INTEL_OUTPUT_DP
||
4535 encoder
->type
== INTEL_OUTPUT_EDP
)
4536 return enc_to_dig_port(&encoder
->base
)->port
;
4543 * Enable PCH resources required for PCH ports:
4545 * - FDI training & RX/TX
4546 * - update transcoder timings
4547 * - DP transcoding bits
4550 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
4552 struct drm_device
*dev
= crtc
->dev
;
4553 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4554 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4555 int pipe
= intel_crtc
->pipe
;
4558 assert_pch_transcoder_disabled(dev_priv
, pipe
);
4560 if (IS_IVYBRIDGE(dev_priv
))
4561 ivybridge_update_fdi_bc_bifurcation(intel_crtc
);
4563 /* Write the TU size bits before fdi link training, so that error
4564 * detection works. */
4565 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
4566 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
4568 /* For PCH output, training FDI link */
4569 dev_priv
->display
.fdi_link_train(crtc
);
4571 /* We need to program the right clock selection before writing the pixel
4572 * mutliplier into the DPLL. */
4573 if (HAS_PCH_CPT(dev_priv
)) {
4576 temp
= I915_READ(PCH_DPLL_SEL
);
4577 temp
|= TRANS_DPLL_ENABLE(pipe
);
4578 sel
= TRANS_DPLLB_SEL(pipe
);
4579 if (intel_crtc
->config
->shared_dpll
==
4580 intel_get_shared_dpll_by_id(dev_priv
, DPLL_ID_PCH_PLL_B
))
4584 I915_WRITE(PCH_DPLL_SEL
, temp
);
4587 /* XXX: pch pll's can be enabled any time before we enable the PCH
4588 * transcoder, and we actually should do this to not upset any PCH
4589 * transcoder that already use the clock when we share it.
4591 * Note that enable_shared_dpll tries to do the right thing, but
4592 * get_shared_dpll unconditionally resets the pll - we need that to have
4593 * the right LVDS enable sequence. */
4594 intel_enable_shared_dpll(intel_crtc
);
4596 /* set transcoder timing, panel must allow it */
4597 assert_panel_unlocked(dev_priv
, pipe
);
4598 ironlake_pch_transcoder_set_timings(intel_crtc
, pipe
);
4600 intel_fdi_normal_train(crtc
);
4602 /* For PCH DP, enable TRANS_DP_CTL */
4603 if (HAS_PCH_CPT(dev_priv
) &&
4604 intel_crtc_has_dp_encoder(intel_crtc
->config
)) {
4605 const struct drm_display_mode
*adjusted_mode
=
4606 &intel_crtc
->config
->base
.adjusted_mode
;
4607 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
4608 i915_reg_t reg
= TRANS_DP_CTL(pipe
);
4609 temp
= I915_READ(reg
);
4610 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
4611 TRANS_DP_SYNC_MASK
|
4613 temp
|= TRANS_DP_OUTPUT_ENABLE
;
4614 temp
|= bpc
<< 9; /* same format but at 11:9 */
4616 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
4617 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
4618 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
4619 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
4621 switch (intel_trans_dp_port_sel(crtc
)) {
4623 temp
|= TRANS_DP_PORT_SEL_B
;
4626 temp
|= TRANS_DP_PORT_SEL_C
;
4629 temp
|= TRANS_DP_PORT_SEL_D
;
4635 I915_WRITE(reg
, temp
);
4638 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
4641 static void lpt_pch_enable(struct drm_crtc
*crtc
)
4643 struct drm_device
*dev
= crtc
->dev
;
4644 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4645 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4646 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
4648 assert_pch_transcoder_disabled(dev_priv
, TRANSCODER_A
);
4650 lpt_program_iclkip(crtc
);
4652 /* Set transcoder timing. */
4653 ironlake_pch_transcoder_set_timings(intel_crtc
, PIPE_A
);
4655 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
4658 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
4660 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4661 i915_reg_t dslreg
= PIPEDSL(pipe
);
4664 temp
= I915_READ(dslreg
);
4666 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
4667 if (wait_for(I915_READ(dslreg
) != temp
, 5))
4668 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
4673 skl_update_scaler(struct intel_crtc_state
*crtc_state
, bool force_detach
,
4674 unsigned scaler_user
, int *scaler_id
, unsigned int rotation
,
4675 int src_w
, int src_h
, int dst_w
, int dst_h
)
4677 struct intel_crtc_scaler_state
*scaler_state
=
4678 &crtc_state
->scaler_state
;
4679 struct intel_crtc
*intel_crtc
=
4680 to_intel_crtc(crtc_state
->base
.crtc
);
4683 need_scaling
= drm_rotation_90_or_270(rotation
) ?
4684 (src_h
!= dst_w
|| src_w
!= dst_h
):
4685 (src_w
!= dst_w
|| src_h
!= dst_h
);
4688 * if plane is being disabled or scaler is no more required or force detach
4689 * - free scaler binded to this plane/crtc
4690 * - in order to do this, update crtc->scaler_usage
4692 * Here scaler state in crtc_state is set free so that
4693 * scaler can be assigned to other user. Actual register
4694 * update to free the scaler is done in plane/panel-fit programming.
4695 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4697 if (force_detach
|| !need_scaling
) {
4698 if (*scaler_id
>= 0) {
4699 scaler_state
->scaler_users
&= ~(1 << scaler_user
);
4700 scaler_state
->scalers
[*scaler_id
].in_use
= 0;
4702 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4703 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4704 intel_crtc
->pipe
, scaler_user
, *scaler_id
,
4705 scaler_state
->scaler_users
);
4712 if (src_w
< SKL_MIN_SRC_W
|| src_h
< SKL_MIN_SRC_H
||
4713 dst_w
< SKL_MIN_DST_W
|| dst_h
< SKL_MIN_DST_H
||
4715 src_w
> SKL_MAX_SRC_W
|| src_h
> SKL_MAX_SRC_H
||
4716 dst_w
> SKL_MAX_DST_W
|| dst_h
> SKL_MAX_DST_H
) {
4717 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4718 "size is out of scaler range\n",
4719 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
);
4723 /* mark this plane as a scaler user in crtc_state */
4724 scaler_state
->scaler_users
|= (1 << scaler_user
);
4725 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4726 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4727 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
,
4728 scaler_state
->scaler_users
);
4734 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4736 * @state: crtc's scaler state
4739 * 0 - scaler_usage updated successfully
4740 * error - requested scaling cannot be supported or other error condition
4742 int skl_update_scaler_crtc(struct intel_crtc_state
*state
)
4744 struct intel_crtc
*intel_crtc
= to_intel_crtc(state
->base
.crtc
);
4745 const struct drm_display_mode
*adjusted_mode
= &state
->base
.adjusted_mode
;
4747 DRM_DEBUG_KMS("Updating scaler for [CRTC:%d:%s] scaler_user index %u.%u\n",
4748 intel_crtc
->base
.base
.id
, intel_crtc
->base
.name
,
4749 intel_crtc
->pipe
, SKL_CRTC_INDEX
);
4751 return skl_update_scaler(state
, !state
->base
.active
, SKL_CRTC_INDEX
,
4752 &state
->scaler_state
.scaler_id
, DRM_ROTATE_0
,
4753 state
->pipe_src_w
, state
->pipe_src_h
,
4754 adjusted_mode
->crtc_hdisplay
, adjusted_mode
->crtc_vdisplay
);
4758 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4760 * @state: crtc's scaler state
4761 * @plane_state: atomic plane state to update
4764 * 0 - scaler_usage updated successfully
4765 * error - requested scaling cannot be supported or other error condition
4767 static int skl_update_scaler_plane(struct intel_crtc_state
*crtc_state
,
4768 struct intel_plane_state
*plane_state
)
4771 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
4772 struct intel_plane
*intel_plane
=
4773 to_intel_plane(plane_state
->base
.plane
);
4774 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
4777 bool force_detach
= !fb
|| !plane_state
->base
.visible
;
4779 DRM_DEBUG_KMS("Updating scaler for [PLANE:%d:%s] scaler_user index %u.%u\n",
4780 intel_plane
->base
.base
.id
, intel_plane
->base
.name
,
4781 intel_crtc
->pipe
, drm_plane_index(&intel_plane
->base
));
4783 ret
= skl_update_scaler(crtc_state
, force_detach
,
4784 drm_plane_index(&intel_plane
->base
),
4785 &plane_state
->scaler_id
,
4786 plane_state
->base
.rotation
,
4787 drm_rect_width(&plane_state
->base
.src
) >> 16,
4788 drm_rect_height(&plane_state
->base
.src
) >> 16,
4789 drm_rect_width(&plane_state
->base
.dst
),
4790 drm_rect_height(&plane_state
->base
.dst
));
4792 if (ret
|| plane_state
->scaler_id
< 0)
4795 /* check colorkey */
4796 if (plane_state
->ckey
.flags
!= I915_SET_COLORKEY_NONE
) {
4797 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
4798 intel_plane
->base
.base
.id
,
4799 intel_plane
->base
.name
);
4803 /* Check src format */
4804 switch (fb
->pixel_format
) {
4805 case DRM_FORMAT_RGB565
:
4806 case DRM_FORMAT_XBGR8888
:
4807 case DRM_FORMAT_XRGB8888
:
4808 case DRM_FORMAT_ABGR8888
:
4809 case DRM_FORMAT_ARGB8888
:
4810 case DRM_FORMAT_XRGB2101010
:
4811 case DRM_FORMAT_XBGR2101010
:
4812 case DRM_FORMAT_YUYV
:
4813 case DRM_FORMAT_YVYU
:
4814 case DRM_FORMAT_UYVY
:
4815 case DRM_FORMAT_VYUY
:
4818 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
4819 intel_plane
->base
.base
.id
, intel_plane
->base
.name
,
4820 fb
->base
.id
, fb
->pixel_format
);
4827 static void skylake_scaler_disable(struct intel_crtc
*crtc
)
4831 for (i
= 0; i
< crtc
->num_scalers
; i
++)
4832 skl_detach_scaler(crtc
, i
);
4835 static void skylake_pfit_enable(struct intel_crtc
*crtc
)
4837 struct drm_device
*dev
= crtc
->base
.dev
;
4838 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4839 int pipe
= crtc
->pipe
;
4840 struct intel_crtc_scaler_state
*scaler_state
=
4841 &crtc
->config
->scaler_state
;
4843 DRM_DEBUG_KMS("for crtc_state = %p\n", crtc
->config
);
4845 if (crtc
->config
->pch_pfit
.enabled
) {
4848 if (WARN_ON(crtc
->config
->scaler_state
.scaler_id
< 0)) {
4849 DRM_ERROR("Requesting pfit without getting a scaler first\n");
4853 id
= scaler_state
->scaler_id
;
4854 I915_WRITE(SKL_PS_CTRL(pipe
, id
), PS_SCALER_EN
|
4855 PS_FILTER_MEDIUM
| scaler_state
->scalers
[id
].mode
);
4856 I915_WRITE(SKL_PS_WIN_POS(pipe
, id
), crtc
->config
->pch_pfit
.pos
);
4857 I915_WRITE(SKL_PS_WIN_SZ(pipe
, id
), crtc
->config
->pch_pfit
.size
);
4859 DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc
->config
, id
);
4863 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
4865 struct drm_device
*dev
= crtc
->base
.dev
;
4866 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4867 int pipe
= crtc
->pipe
;
4869 if (crtc
->config
->pch_pfit
.enabled
) {
4870 /* Force use of hard-coded filter coefficients
4871 * as some pre-programmed values are broken,
4874 if (IS_IVYBRIDGE(dev_priv
) || IS_HASWELL(dev_priv
))
4875 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
4876 PF_PIPE_SEL_IVB(pipe
));
4878 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
4879 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
->pch_pfit
.pos
);
4880 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
->pch_pfit
.size
);
4884 void hsw_enable_ips(struct intel_crtc
*crtc
)
4886 struct drm_device
*dev
= crtc
->base
.dev
;
4887 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4889 if (!crtc
->config
->ips_enabled
)
4893 * We can only enable IPS after we enable a plane and wait for a vblank
4894 * This function is called from post_plane_update, which is run after
4898 assert_plane_enabled(dev_priv
, crtc
->plane
);
4899 if (IS_BROADWELL(dev_priv
)) {
4900 mutex_lock(&dev_priv
->rps
.hw_lock
);
4901 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
4902 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4903 /* Quoting Art Runyan: "its not safe to expect any particular
4904 * value in IPS_CTL bit 31 after enabling IPS through the
4905 * mailbox." Moreover, the mailbox may return a bogus state,
4906 * so we need to just enable it and continue on.
4909 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
4910 /* The bit only becomes 1 in the next vblank, so this wait here
4911 * is essentially intel_wait_for_vblank. If we don't have this
4912 * and don't wait for vblanks until the end of crtc_enable, then
4913 * the HW state readout code will complain that the expected
4914 * IPS_CTL value is not the one we read. */
4915 if (intel_wait_for_register(dev_priv
,
4916 IPS_CTL
, IPS_ENABLE
, IPS_ENABLE
,
4918 DRM_ERROR("Timed out waiting for IPS enable\n");
4922 void hsw_disable_ips(struct intel_crtc
*crtc
)
4924 struct drm_device
*dev
= crtc
->base
.dev
;
4925 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4927 if (!crtc
->config
->ips_enabled
)
4930 assert_plane_enabled(dev_priv
, crtc
->plane
);
4931 if (IS_BROADWELL(dev_priv
)) {
4932 mutex_lock(&dev_priv
->rps
.hw_lock
);
4933 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
4934 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4935 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4936 if (intel_wait_for_register(dev_priv
,
4937 IPS_CTL
, IPS_ENABLE
, 0,
4939 DRM_ERROR("Timed out waiting for IPS disable\n");
4941 I915_WRITE(IPS_CTL
, 0);
4942 POSTING_READ(IPS_CTL
);
4945 /* We need to wait for a vblank before we can disable the plane. */
4946 intel_wait_for_vblank(dev
, crtc
->pipe
);
4949 static void intel_crtc_dpms_overlay_disable(struct intel_crtc
*intel_crtc
)
4951 if (intel_crtc
->overlay
) {
4952 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4953 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4955 mutex_lock(&dev
->struct_mutex
);
4956 dev_priv
->mm
.interruptible
= false;
4957 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
4958 dev_priv
->mm
.interruptible
= true;
4959 mutex_unlock(&dev
->struct_mutex
);
4962 /* Let userspace switch the overlay on again. In most cases userspace
4963 * has to recompute where to put it anyway.
4968 * intel_post_enable_primary - Perform operations after enabling primary plane
4969 * @crtc: the CRTC whose primary plane was just enabled
4971 * Performs potentially sleeping operations that must be done after the primary
4972 * plane is enabled, such as updating FBC and IPS. Note that this may be
4973 * called due to an explicit primary plane update, or due to an implicit
4974 * re-enable that is caused when a sprite plane is updated to no longer
4975 * completely hide the primary plane.
4978 intel_post_enable_primary(struct drm_crtc
*crtc
)
4980 struct drm_device
*dev
= crtc
->dev
;
4981 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4982 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4983 int pipe
= intel_crtc
->pipe
;
4986 * FIXME IPS should be fine as long as one plane is
4987 * enabled, but in practice it seems to have problems
4988 * when going from primary only to sprite only and vice
4991 hsw_enable_ips(intel_crtc
);
4994 * Gen2 reports pipe underruns whenever all planes are disabled.
4995 * So don't enable underrun reporting before at least some planes
4997 * FIXME: Need to fix the logic to work when we turn off all planes
4998 * but leave the pipe running.
5000 if (IS_GEN2(dev_priv
))
5001 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5003 /* Underruns don't always raise interrupts, so check manually. */
5004 intel_check_cpu_fifo_underruns(dev_priv
);
5005 intel_check_pch_fifo_underruns(dev_priv
);
5008 /* FIXME move all this to pre_plane_update() with proper state tracking */
5010 intel_pre_disable_primary(struct drm_crtc
*crtc
)
5012 struct drm_device
*dev
= crtc
->dev
;
5013 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5014 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5015 int pipe
= intel_crtc
->pipe
;
5018 * Gen2 reports pipe underruns whenever all planes are disabled.
5019 * So diasble underrun reporting before all the planes get disabled.
5020 * FIXME: Need to fix the logic to work when we turn off all planes
5021 * but leave the pipe running.
5023 if (IS_GEN2(dev_priv
))
5024 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5027 * FIXME IPS should be fine as long as one plane is
5028 * enabled, but in practice it seems to have problems
5029 * when going from primary only to sprite only and vice
5032 hsw_disable_ips(intel_crtc
);
5035 /* FIXME get rid of this and use pre_plane_update */
5037 intel_pre_disable_primary_noatomic(struct drm_crtc
*crtc
)
5039 struct drm_device
*dev
= crtc
->dev
;
5040 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5041 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5042 int pipe
= intel_crtc
->pipe
;
5044 intel_pre_disable_primary(crtc
);
5047 * Vblank time updates from the shadow to live plane control register
5048 * are blocked if the memory self-refresh mode is active at that
5049 * moment. So to make sure the plane gets truly disabled, disable
5050 * first the self-refresh mode. The self-refresh enable bit in turn
5051 * will be checked/applied by the HW only at the next frame start
5052 * event which is after the vblank start event, so we need to have a
5053 * wait-for-vblank between disabling the plane and the pipe.
5055 if (HAS_GMCH_DISPLAY(dev_priv
)) {
5056 intel_set_memory_cxsr(dev_priv
, false);
5057 dev_priv
->wm
.vlv
.cxsr
= false;
5058 intel_wait_for_vblank(dev
, pipe
);
5062 static void intel_post_plane_update(struct intel_crtc_state
*old_crtc_state
)
5064 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
5065 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
5066 struct intel_crtc_state
*pipe_config
=
5067 to_intel_crtc_state(crtc
->base
.state
);
5068 struct drm_plane
*primary
= crtc
->base
.primary
;
5069 struct drm_plane_state
*old_pri_state
=
5070 drm_atomic_get_existing_plane_state(old_state
, primary
);
5072 intel_frontbuffer_flip(to_i915(crtc
->base
.dev
), pipe_config
->fb_bits
);
5074 crtc
->wm
.cxsr_allowed
= true;
5076 if (pipe_config
->update_wm_post
&& pipe_config
->base
.active
)
5077 intel_update_watermarks(&crtc
->base
);
5079 if (old_pri_state
) {
5080 struct intel_plane_state
*primary_state
=
5081 to_intel_plane_state(primary
->state
);
5082 struct intel_plane_state
*old_primary_state
=
5083 to_intel_plane_state(old_pri_state
);
5085 intel_fbc_post_update(crtc
);
5087 if (primary_state
->base
.visible
&&
5088 (needs_modeset(&pipe_config
->base
) ||
5089 !old_primary_state
->base
.visible
))
5090 intel_post_enable_primary(&crtc
->base
);
5094 static void intel_pre_plane_update(struct intel_crtc_state
*old_crtc_state
)
5096 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
5097 struct drm_device
*dev
= crtc
->base
.dev
;
5098 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5099 struct intel_crtc_state
*pipe_config
=
5100 to_intel_crtc_state(crtc
->base
.state
);
5101 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
5102 struct drm_plane
*primary
= crtc
->base
.primary
;
5103 struct drm_plane_state
*old_pri_state
=
5104 drm_atomic_get_existing_plane_state(old_state
, primary
);
5105 bool modeset
= needs_modeset(&pipe_config
->base
);
5107 if (old_pri_state
) {
5108 struct intel_plane_state
*primary_state
=
5109 to_intel_plane_state(primary
->state
);
5110 struct intel_plane_state
*old_primary_state
=
5111 to_intel_plane_state(old_pri_state
);
5113 intel_fbc_pre_update(crtc
, pipe_config
, primary_state
);
5115 if (old_primary_state
->base
.visible
&&
5116 (modeset
|| !primary_state
->base
.visible
))
5117 intel_pre_disable_primary(&crtc
->base
);
5120 if (pipe_config
->disable_cxsr
&& HAS_GMCH_DISPLAY(dev_priv
)) {
5121 crtc
->wm
.cxsr_allowed
= false;
5124 * Vblank time updates from the shadow to live plane control register
5125 * are blocked if the memory self-refresh mode is active at that
5126 * moment. So to make sure the plane gets truly disabled, disable
5127 * first the self-refresh mode. The self-refresh enable bit in turn
5128 * will be checked/applied by the HW only at the next frame start
5129 * event which is after the vblank start event, so we need to have a
5130 * wait-for-vblank between disabling the plane and the pipe.
5132 if (old_crtc_state
->base
.active
) {
5133 intel_set_memory_cxsr(dev_priv
, false);
5134 dev_priv
->wm
.vlv
.cxsr
= false;
5135 intel_wait_for_vblank(dev
, crtc
->pipe
);
5140 * IVB workaround: must disable low power watermarks for at least
5141 * one frame before enabling scaling. LP watermarks can be re-enabled
5142 * when scaling is disabled.
5144 * WaCxSRDisabledForSpriteScaling:ivb
5146 if (pipe_config
->disable_lp_wm
) {
5147 ilk_disable_lp_wm(dev
);
5148 intel_wait_for_vblank(dev
, crtc
->pipe
);
5152 * If we're doing a modeset, we're done. No need to do any pre-vblank
5153 * watermark programming here.
5155 if (needs_modeset(&pipe_config
->base
))
5159 * For platforms that support atomic watermarks, program the
5160 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5161 * will be the intermediate values that are safe for both pre- and
5162 * post- vblank; when vblank happens, the 'active' values will be set
5163 * to the final 'target' values and we'll do this again to get the
5164 * optimal watermarks. For gen9+ platforms, the values we program here
5165 * will be the final target values which will get automatically latched
5166 * at vblank time; no further programming will be necessary.
5168 * If a platform hasn't been transitioned to atomic watermarks yet,
5169 * we'll continue to update watermarks the old way, if flags tell
5172 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5173 dev_priv
->display
.initial_watermarks(pipe_config
);
5174 else if (pipe_config
->update_wm_pre
)
5175 intel_update_watermarks(&crtc
->base
);
5178 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
, unsigned plane_mask
)
5180 struct drm_device
*dev
= crtc
->dev
;
5181 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5182 struct drm_plane
*p
;
5183 int pipe
= intel_crtc
->pipe
;
5185 intel_crtc_dpms_overlay_disable(intel_crtc
);
5187 drm_for_each_plane_mask(p
, dev
, plane_mask
)
5188 to_intel_plane(p
)->disable_plane(p
, crtc
);
5191 * FIXME: Once we grow proper nuclear flip support out of this we need
5192 * to compute the mask of flip planes precisely. For the time being
5193 * consider this a flip to a NULL plane.
5195 intel_frontbuffer_flip(to_i915(dev
), INTEL_FRONTBUFFER_ALL_MASK(pipe
));
5198 static void intel_encoders_pre_pll_enable(struct drm_crtc
*crtc
,
5199 struct intel_crtc_state
*crtc_state
,
5200 struct drm_atomic_state
*old_state
)
5202 struct drm_connector_state
*old_conn_state
;
5203 struct drm_connector
*conn
;
5206 for_each_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5207 struct drm_connector_state
*conn_state
= conn
->state
;
5208 struct intel_encoder
*encoder
=
5209 to_intel_encoder(conn_state
->best_encoder
);
5211 if (conn_state
->crtc
!= crtc
)
5214 if (encoder
->pre_pll_enable
)
5215 encoder
->pre_pll_enable(encoder
, crtc_state
, conn_state
);
5219 static void intel_encoders_pre_enable(struct drm_crtc
*crtc
,
5220 struct intel_crtc_state
*crtc_state
,
5221 struct drm_atomic_state
*old_state
)
5223 struct drm_connector_state
*old_conn_state
;
5224 struct drm_connector
*conn
;
5227 for_each_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5228 struct drm_connector_state
*conn_state
= conn
->state
;
5229 struct intel_encoder
*encoder
=
5230 to_intel_encoder(conn_state
->best_encoder
);
5232 if (conn_state
->crtc
!= crtc
)
5235 if (encoder
->pre_enable
)
5236 encoder
->pre_enable(encoder
, crtc_state
, conn_state
);
5240 static void intel_encoders_enable(struct drm_crtc
*crtc
,
5241 struct intel_crtc_state
*crtc_state
,
5242 struct drm_atomic_state
*old_state
)
5244 struct drm_connector_state
*old_conn_state
;
5245 struct drm_connector
*conn
;
5248 for_each_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5249 struct drm_connector_state
*conn_state
= conn
->state
;
5250 struct intel_encoder
*encoder
=
5251 to_intel_encoder(conn_state
->best_encoder
);
5253 if (conn_state
->crtc
!= crtc
)
5256 encoder
->enable(encoder
, crtc_state
, conn_state
);
5257 intel_opregion_notify_encoder(encoder
, true);
5261 static void intel_encoders_disable(struct drm_crtc
*crtc
,
5262 struct intel_crtc_state
*old_crtc_state
,
5263 struct drm_atomic_state
*old_state
)
5265 struct drm_connector_state
*old_conn_state
;
5266 struct drm_connector
*conn
;
5269 for_each_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5270 struct intel_encoder
*encoder
=
5271 to_intel_encoder(old_conn_state
->best_encoder
);
5273 if (old_conn_state
->crtc
!= crtc
)
5276 intel_opregion_notify_encoder(encoder
, false);
5277 encoder
->disable(encoder
, old_crtc_state
, old_conn_state
);
5281 static void intel_encoders_post_disable(struct drm_crtc
*crtc
,
5282 struct intel_crtc_state
*old_crtc_state
,
5283 struct drm_atomic_state
*old_state
)
5285 struct drm_connector_state
*old_conn_state
;
5286 struct drm_connector
*conn
;
5289 for_each_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5290 struct intel_encoder
*encoder
=
5291 to_intel_encoder(old_conn_state
->best_encoder
);
5293 if (old_conn_state
->crtc
!= crtc
)
5296 if (encoder
->post_disable
)
5297 encoder
->post_disable(encoder
, old_crtc_state
, old_conn_state
);
5301 static void intel_encoders_post_pll_disable(struct drm_crtc
*crtc
,
5302 struct intel_crtc_state
*old_crtc_state
,
5303 struct drm_atomic_state
*old_state
)
5305 struct drm_connector_state
*old_conn_state
;
5306 struct drm_connector
*conn
;
5309 for_each_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5310 struct intel_encoder
*encoder
=
5311 to_intel_encoder(old_conn_state
->best_encoder
);
5313 if (old_conn_state
->crtc
!= crtc
)
5316 if (encoder
->post_pll_disable
)
5317 encoder
->post_pll_disable(encoder
, old_crtc_state
, old_conn_state
);
5321 static void ironlake_crtc_enable(struct intel_crtc_state
*pipe_config
,
5322 struct drm_atomic_state
*old_state
)
5324 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5325 struct drm_device
*dev
= crtc
->dev
;
5326 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5327 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5328 int pipe
= intel_crtc
->pipe
;
5330 if (WARN_ON(intel_crtc
->active
))
5334 * Sometimes spurious CPU pipe underruns happen during FDI
5335 * training, at least with VGA+HDMI cloning. Suppress them.
5337 * On ILK we get an occasional spurious CPU pipe underruns
5338 * between eDP port A enable and vdd enable. Also PCH port
5339 * enable seems to result in the occasional CPU pipe underrun.
5341 * Spurious PCH underruns also occur during PCH enabling.
5343 if (intel_crtc
->config
->has_pch_encoder
|| IS_GEN5(dev_priv
))
5344 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5345 if (intel_crtc
->config
->has_pch_encoder
)
5346 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
5348 if (intel_crtc
->config
->has_pch_encoder
)
5349 intel_prepare_shared_dpll(intel_crtc
);
5351 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5352 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5354 intel_set_pipe_timings(intel_crtc
);
5355 intel_set_pipe_src_size(intel_crtc
);
5357 if (intel_crtc
->config
->has_pch_encoder
) {
5358 intel_cpu_transcoder_set_m_n(intel_crtc
,
5359 &intel_crtc
->config
->fdi_m_n
, NULL
);
5362 ironlake_set_pipeconf(crtc
);
5364 intel_crtc
->active
= true;
5366 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5368 if (intel_crtc
->config
->has_pch_encoder
) {
5369 /* Note: FDI PLL enabling _must_ be done before we enable the
5370 * cpu pipes, hence this is separate from all the other fdi/pch
5372 ironlake_fdi_pll_enable(intel_crtc
);
5374 assert_fdi_tx_disabled(dev_priv
, pipe
);
5375 assert_fdi_rx_disabled(dev_priv
, pipe
);
5378 ironlake_pfit_enable(intel_crtc
);
5381 * On ILK+ LUT must be loaded before the pipe is running but with
5384 intel_color_load_luts(&pipe_config
->base
);
5386 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5387 dev_priv
->display
.initial_watermarks(intel_crtc
->config
);
5388 intel_enable_pipe(intel_crtc
);
5390 if (intel_crtc
->config
->has_pch_encoder
)
5391 ironlake_pch_enable(crtc
);
5393 assert_vblank_disabled(crtc
);
5394 drm_crtc_vblank_on(crtc
);
5396 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5398 if (HAS_PCH_CPT(dev_priv
))
5399 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
5401 /* Must wait for vblank to avoid spurious PCH FIFO underruns */
5402 if (intel_crtc
->config
->has_pch_encoder
)
5403 intel_wait_for_vblank(dev
, pipe
);
5404 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5405 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
5408 /* IPS only exists on ULT machines and is tied to pipe A. */
5409 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
5411 return HAS_IPS(to_i915(crtc
->base
.dev
)) && crtc
->pipe
== PIPE_A
;
5414 static void haswell_crtc_enable(struct intel_crtc_state
*pipe_config
,
5415 struct drm_atomic_state
*old_state
)
5417 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5418 struct drm_device
*dev
= crtc
->dev
;
5419 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5420 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5421 int pipe
= intel_crtc
->pipe
, hsw_workaround_pipe
;
5422 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5424 if (WARN_ON(intel_crtc
->active
))
5427 if (intel_crtc
->config
->has_pch_encoder
)
5428 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5431 intel_encoders_pre_pll_enable(crtc
, pipe_config
, old_state
);
5433 if (intel_crtc
->config
->shared_dpll
)
5434 intel_enable_shared_dpll(intel_crtc
);
5436 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5437 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5439 if (!transcoder_is_dsi(cpu_transcoder
))
5440 intel_set_pipe_timings(intel_crtc
);
5442 intel_set_pipe_src_size(intel_crtc
);
5444 if (cpu_transcoder
!= TRANSCODER_EDP
&&
5445 !transcoder_is_dsi(cpu_transcoder
)) {
5446 I915_WRITE(PIPE_MULT(cpu_transcoder
),
5447 intel_crtc
->config
->pixel_multiplier
- 1);
5450 if (intel_crtc
->config
->has_pch_encoder
) {
5451 intel_cpu_transcoder_set_m_n(intel_crtc
,
5452 &intel_crtc
->config
->fdi_m_n
, NULL
);
5455 if (!transcoder_is_dsi(cpu_transcoder
))
5456 haswell_set_pipeconf(crtc
);
5458 haswell_set_pipemisc(crtc
);
5460 intel_color_set_csc(&pipe_config
->base
);
5462 intel_crtc
->active
= true;
5464 if (intel_crtc
->config
->has_pch_encoder
)
5465 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5467 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5469 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5471 if (intel_crtc
->config
->has_pch_encoder
)
5472 dev_priv
->display
.fdi_link_train(crtc
);
5474 if (!transcoder_is_dsi(cpu_transcoder
))
5475 intel_ddi_enable_pipe_clock(intel_crtc
);
5477 if (INTEL_INFO(dev
)->gen
>= 9)
5478 skylake_pfit_enable(intel_crtc
);
5480 ironlake_pfit_enable(intel_crtc
);
5483 * On ILK+ LUT must be loaded before the pipe is running but with
5486 intel_color_load_luts(&pipe_config
->base
);
5488 intel_ddi_set_pipe_settings(crtc
);
5489 if (!transcoder_is_dsi(cpu_transcoder
))
5490 intel_ddi_enable_transcoder_func(crtc
);
5492 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5493 dev_priv
->display
.initial_watermarks(pipe_config
);
5495 intel_update_watermarks(crtc
);
5497 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5498 if (!transcoder_is_dsi(cpu_transcoder
))
5499 intel_enable_pipe(intel_crtc
);
5501 if (intel_crtc
->config
->has_pch_encoder
)
5502 lpt_pch_enable(crtc
);
5504 if (intel_crtc
->config
->dp_encoder_is_mst
)
5505 intel_ddi_set_vc_payload_alloc(crtc
, true);
5507 assert_vblank_disabled(crtc
);
5508 drm_crtc_vblank_on(crtc
);
5510 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5512 if (intel_crtc
->config
->has_pch_encoder
) {
5513 intel_wait_for_vblank(dev
, pipe
);
5514 intel_wait_for_vblank(dev
, pipe
);
5515 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5516 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5520 /* If we change the relative order between pipe/planes enabling, we need
5521 * to change the workaround. */
5522 hsw_workaround_pipe
= pipe_config
->hsw_workaround_pipe
;
5523 if (IS_HASWELL(dev_priv
) && hsw_workaround_pipe
!= INVALID_PIPE
) {
5524 intel_wait_for_vblank(dev
, hsw_workaround_pipe
);
5525 intel_wait_for_vblank(dev
, hsw_workaround_pipe
);
5529 static void ironlake_pfit_disable(struct intel_crtc
*crtc
, bool force
)
5531 struct drm_device
*dev
= crtc
->base
.dev
;
5532 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5533 int pipe
= crtc
->pipe
;
5535 /* To avoid upsetting the power well on haswell only disable the pfit if
5536 * it's in use. The hw state code will make sure we get this right. */
5537 if (force
|| crtc
->config
->pch_pfit
.enabled
) {
5538 I915_WRITE(PF_CTL(pipe
), 0);
5539 I915_WRITE(PF_WIN_POS(pipe
), 0);
5540 I915_WRITE(PF_WIN_SZ(pipe
), 0);
5544 static void ironlake_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5545 struct drm_atomic_state
*old_state
)
5547 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5548 struct drm_device
*dev
= crtc
->dev
;
5549 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5550 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5551 int pipe
= intel_crtc
->pipe
;
5554 * Sometimes spurious CPU pipe underruns happen when the
5555 * pipe is already disabled, but FDI RX/TX is still enabled.
5556 * Happens at least with VGA+HDMI cloning. Suppress them.
5558 if (intel_crtc
->config
->has_pch_encoder
) {
5559 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5560 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
5563 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5565 drm_crtc_vblank_off(crtc
);
5566 assert_vblank_disabled(crtc
);
5568 intel_disable_pipe(intel_crtc
);
5570 ironlake_pfit_disable(intel_crtc
, false);
5572 if (intel_crtc
->config
->has_pch_encoder
)
5573 ironlake_fdi_disable(crtc
);
5575 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5577 if (intel_crtc
->config
->has_pch_encoder
) {
5578 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
5580 if (HAS_PCH_CPT(dev_priv
)) {
5584 /* disable TRANS_DP_CTL */
5585 reg
= TRANS_DP_CTL(pipe
);
5586 temp
= I915_READ(reg
);
5587 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
5588 TRANS_DP_PORT_SEL_MASK
);
5589 temp
|= TRANS_DP_PORT_SEL_NONE
;
5590 I915_WRITE(reg
, temp
);
5592 /* disable DPLL_SEL */
5593 temp
= I915_READ(PCH_DPLL_SEL
);
5594 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
5595 I915_WRITE(PCH_DPLL_SEL
, temp
);
5598 ironlake_fdi_pll_disable(intel_crtc
);
5601 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5602 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
5605 static void haswell_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5606 struct drm_atomic_state
*old_state
)
5608 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5609 struct drm_device
*dev
= crtc
->dev
;
5610 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5611 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5612 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5614 if (intel_crtc
->config
->has_pch_encoder
)
5615 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5618 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5620 drm_crtc_vblank_off(crtc
);
5621 assert_vblank_disabled(crtc
);
5623 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5624 if (!transcoder_is_dsi(cpu_transcoder
))
5625 intel_disable_pipe(intel_crtc
);
5627 if (intel_crtc
->config
->dp_encoder_is_mst
)
5628 intel_ddi_set_vc_payload_alloc(crtc
, false);
5630 if (!transcoder_is_dsi(cpu_transcoder
))
5631 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
5633 if (INTEL_INFO(dev
)->gen
>= 9)
5634 skylake_scaler_disable(intel_crtc
);
5636 ironlake_pfit_disable(intel_crtc
, false);
5638 if (!transcoder_is_dsi(cpu_transcoder
))
5639 intel_ddi_disable_pipe_clock(intel_crtc
);
5641 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5643 if (old_crtc_state
->has_pch_encoder
)
5644 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5648 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
5650 struct drm_device
*dev
= crtc
->base
.dev
;
5651 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5652 struct intel_crtc_state
*pipe_config
= crtc
->config
;
5654 if (!pipe_config
->gmch_pfit
.control
)
5658 * The panel fitter should only be adjusted whilst the pipe is disabled,
5659 * according to register description and PRM.
5661 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
5662 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5664 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
5665 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
5667 /* Border color in case we don't scale up to the full screen. Black by
5668 * default, change to something else for debugging. */
5669 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
5672 static enum intel_display_power_domain
port_to_power_domain(enum port port
)
5676 return POWER_DOMAIN_PORT_DDI_A_LANES
;
5678 return POWER_DOMAIN_PORT_DDI_B_LANES
;
5680 return POWER_DOMAIN_PORT_DDI_C_LANES
;
5682 return POWER_DOMAIN_PORT_DDI_D_LANES
;
5684 return POWER_DOMAIN_PORT_DDI_E_LANES
;
5687 return POWER_DOMAIN_PORT_OTHER
;
5691 static enum intel_display_power_domain
port_to_aux_power_domain(enum port port
)
5695 return POWER_DOMAIN_AUX_A
;
5697 return POWER_DOMAIN_AUX_B
;
5699 return POWER_DOMAIN_AUX_C
;
5701 return POWER_DOMAIN_AUX_D
;
5703 /* FIXME: Check VBT for actual wiring of PORT E */
5704 return POWER_DOMAIN_AUX_D
;
5707 return POWER_DOMAIN_AUX_A
;
5711 enum intel_display_power_domain
5712 intel_display_port_power_domain(struct intel_encoder
*intel_encoder
)
5714 struct drm_i915_private
*dev_priv
= to_i915(intel_encoder
->base
.dev
);
5715 struct intel_digital_port
*intel_dig_port
;
5717 switch (intel_encoder
->type
) {
5718 case INTEL_OUTPUT_UNKNOWN
:
5719 /* Only DDI platforms should ever use this output type */
5720 WARN_ON_ONCE(!HAS_DDI(dev_priv
));
5721 case INTEL_OUTPUT_DP
:
5722 case INTEL_OUTPUT_HDMI
:
5723 case INTEL_OUTPUT_EDP
:
5724 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
5725 return port_to_power_domain(intel_dig_port
->port
);
5726 case INTEL_OUTPUT_DP_MST
:
5727 intel_dig_port
= enc_to_mst(&intel_encoder
->base
)->primary
;
5728 return port_to_power_domain(intel_dig_port
->port
);
5729 case INTEL_OUTPUT_ANALOG
:
5730 return POWER_DOMAIN_PORT_CRT
;
5731 case INTEL_OUTPUT_DSI
:
5732 return POWER_DOMAIN_PORT_DSI
;
5734 return POWER_DOMAIN_PORT_OTHER
;
5738 enum intel_display_power_domain
5739 intel_display_port_aux_power_domain(struct intel_encoder
*intel_encoder
)
5741 struct drm_i915_private
*dev_priv
= to_i915(intel_encoder
->base
.dev
);
5742 struct intel_digital_port
*intel_dig_port
;
5744 switch (intel_encoder
->type
) {
5745 case INTEL_OUTPUT_UNKNOWN
:
5746 case INTEL_OUTPUT_HDMI
:
5748 * Only DDI platforms should ever use these output types.
5749 * We can get here after the HDMI detect code has already set
5750 * the type of the shared encoder. Since we can't be sure
5751 * what's the status of the given connectors, play safe and
5752 * run the DP detection too.
5754 WARN_ON_ONCE(!HAS_DDI(dev_priv
));
5755 case INTEL_OUTPUT_DP
:
5756 case INTEL_OUTPUT_EDP
:
5757 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
5758 return port_to_aux_power_domain(intel_dig_port
->port
);
5759 case INTEL_OUTPUT_DP_MST
:
5760 intel_dig_port
= enc_to_mst(&intel_encoder
->base
)->primary
;
5761 return port_to_aux_power_domain(intel_dig_port
->port
);
5763 MISSING_CASE(intel_encoder
->type
);
5764 return POWER_DOMAIN_AUX_A
;
5768 static unsigned long get_crtc_power_domains(struct drm_crtc
*crtc
,
5769 struct intel_crtc_state
*crtc_state
)
5771 struct drm_device
*dev
= crtc
->dev
;
5772 struct drm_encoder
*encoder
;
5773 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5774 enum pipe pipe
= intel_crtc
->pipe
;
5776 enum transcoder transcoder
= crtc_state
->cpu_transcoder
;
5778 if (!crtc_state
->base
.active
)
5781 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
5782 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
5783 if (crtc_state
->pch_pfit
.enabled
||
5784 crtc_state
->pch_pfit
.force_thru
)
5785 mask
|= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
5787 drm_for_each_encoder_mask(encoder
, dev
, crtc_state
->base
.encoder_mask
) {
5788 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5790 mask
|= BIT(intel_display_port_power_domain(intel_encoder
));
5793 if (crtc_state
->shared_dpll
)
5794 mask
|= BIT(POWER_DOMAIN_PLLS
);
5799 static unsigned long
5800 modeset_get_crtc_power_domains(struct drm_crtc
*crtc
,
5801 struct intel_crtc_state
*crtc_state
)
5803 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5804 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5805 enum intel_display_power_domain domain
;
5806 unsigned long domains
, new_domains
, old_domains
;
5808 old_domains
= intel_crtc
->enabled_power_domains
;
5809 intel_crtc
->enabled_power_domains
= new_domains
=
5810 get_crtc_power_domains(crtc
, crtc_state
);
5812 domains
= new_domains
& ~old_domains
;
5814 for_each_power_domain(domain
, domains
)
5815 intel_display_power_get(dev_priv
, domain
);
5817 return old_domains
& ~new_domains
;
5820 static void modeset_put_power_domains(struct drm_i915_private
*dev_priv
,
5821 unsigned long domains
)
5823 enum intel_display_power_domain domain
;
5825 for_each_power_domain(domain
, domains
)
5826 intel_display_power_put(dev_priv
, domain
);
5829 static int intel_compute_max_dotclk(struct drm_i915_private
*dev_priv
)
5831 int max_cdclk_freq
= dev_priv
->max_cdclk_freq
;
5833 if (INTEL_INFO(dev_priv
)->gen
>= 9 ||
5834 IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
5835 return max_cdclk_freq
;
5836 else if (IS_CHERRYVIEW(dev_priv
))
5837 return max_cdclk_freq
*95/100;
5838 else if (INTEL_INFO(dev_priv
)->gen
< 4)
5839 return 2*max_cdclk_freq
*90/100;
5841 return max_cdclk_freq
*90/100;
5844 static int skl_calc_cdclk(int max_pixclk
, int vco
);
5846 static void intel_update_max_cdclk(struct drm_device
*dev
)
5848 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5850 if (IS_SKYLAKE(dev_priv
) || IS_KABYLAKE(dev_priv
)) {
5851 u32 limit
= I915_READ(SKL_DFSM
) & SKL_DFSM_CDCLK_LIMIT_MASK
;
5854 vco
= dev_priv
->skl_preferred_vco_freq
;
5855 WARN_ON(vco
!= 8100000 && vco
!= 8640000);
5858 * Use the lower (vco 8640) cdclk values as a
5859 * first guess. skl_calc_cdclk() will correct it
5860 * if the preferred vco is 8100 instead.
5862 if (limit
== SKL_DFSM_CDCLK_LIMIT_675
)
5864 else if (limit
== SKL_DFSM_CDCLK_LIMIT_540
)
5866 else if (limit
== SKL_DFSM_CDCLK_LIMIT_450
)
5871 dev_priv
->max_cdclk_freq
= skl_calc_cdclk(max_cdclk
, vco
);
5872 } else if (IS_BROXTON(dev_priv
)) {
5873 dev_priv
->max_cdclk_freq
= 624000;
5874 } else if (IS_BROADWELL(dev_priv
)) {
5876 * FIXME with extra cooling we can allow
5877 * 540 MHz for ULX and 675 Mhz for ULT.
5878 * How can we know if extra cooling is
5879 * available? PCI ID, VTB, something else?
5881 if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
5882 dev_priv
->max_cdclk_freq
= 450000;
5883 else if (IS_BDW_ULX(dev_priv
))
5884 dev_priv
->max_cdclk_freq
= 450000;
5885 else if (IS_BDW_ULT(dev_priv
))
5886 dev_priv
->max_cdclk_freq
= 540000;
5888 dev_priv
->max_cdclk_freq
= 675000;
5889 } else if (IS_CHERRYVIEW(dev_priv
)) {
5890 dev_priv
->max_cdclk_freq
= 320000;
5891 } else if (IS_VALLEYVIEW(dev_priv
)) {
5892 dev_priv
->max_cdclk_freq
= 400000;
5894 /* otherwise assume cdclk is fixed */
5895 dev_priv
->max_cdclk_freq
= dev_priv
->cdclk_freq
;
5898 dev_priv
->max_dotclk_freq
= intel_compute_max_dotclk(dev_priv
);
5900 DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n",
5901 dev_priv
->max_cdclk_freq
);
5903 DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n",
5904 dev_priv
->max_dotclk_freq
);
5907 static void intel_update_cdclk(struct drm_device
*dev
)
5909 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5911 dev_priv
->cdclk_freq
= dev_priv
->display
.get_display_clock_speed(dev
);
5913 if (INTEL_GEN(dev_priv
) >= 9)
5914 DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz, VCO: %d kHz, ref: %d kHz\n",
5915 dev_priv
->cdclk_freq
, dev_priv
->cdclk_pll
.vco
,
5916 dev_priv
->cdclk_pll
.ref
);
5918 DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n",
5919 dev_priv
->cdclk_freq
);
5922 * 9:0 CMBUS [sic] CDCLK frequency (cdfreq):
5923 * Programmng [sic] note: bit[9:2] should be programmed to the number
5924 * of cdclk that generates 4MHz reference clock freq which is used to
5925 * generate GMBus clock. This will vary with the cdclk freq.
5927 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
5928 I915_WRITE(GMBUSFREQ_VLV
, DIV_ROUND_UP(dev_priv
->cdclk_freq
, 1000));
5931 /* convert from kHz to .1 fixpoint MHz with -1MHz offset */
5932 static int skl_cdclk_decimal(int cdclk
)
5934 return DIV_ROUND_CLOSEST(cdclk
- 1000, 500);
5937 static int bxt_de_pll_vco(struct drm_i915_private
*dev_priv
, int cdclk
)
5941 if (cdclk
== dev_priv
->cdclk_pll
.ref
)
5946 MISSING_CASE(cdclk
);
5958 return dev_priv
->cdclk_pll
.ref
* ratio
;
5961 static void bxt_de_pll_disable(struct drm_i915_private
*dev_priv
)
5963 I915_WRITE(BXT_DE_PLL_ENABLE
, 0);
5966 if (intel_wait_for_register(dev_priv
,
5967 BXT_DE_PLL_ENABLE
, BXT_DE_PLL_LOCK
, 0,
5969 DRM_ERROR("timeout waiting for DE PLL unlock\n");
5971 dev_priv
->cdclk_pll
.vco
= 0;
5974 static void bxt_de_pll_enable(struct drm_i915_private
*dev_priv
, int vco
)
5976 int ratio
= DIV_ROUND_CLOSEST(vco
, dev_priv
->cdclk_pll
.ref
);
5979 val
= I915_READ(BXT_DE_PLL_CTL
);
5980 val
&= ~BXT_DE_PLL_RATIO_MASK
;
5981 val
|= BXT_DE_PLL_RATIO(ratio
);
5982 I915_WRITE(BXT_DE_PLL_CTL
, val
);
5984 I915_WRITE(BXT_DE_PLL_ENABLE
, BXT_DE_PLL_PLL_ENABLE
);
5987 if (intel_wait_for_register(dev_priv
,
5992 DRM_ERROR("timeout waiting for DE PLL lock\n");
5994 dev_priv
->cdclk_pll
.vco
= vco
;
5997 static void bxt_set_cdclk(struct drm_i915_private
*dev_priv
, int cdclk
)
6002 vco
= bxt_de_pll_vco(dev_priv
, cdclk
);
6004 DRM_DEBUG_DRIVER("Changing CDCLK to %d kHz (VCO %d kHz)\n", cdclk
, vco
);
6006 /* cdclk = vco / 2 / div{1,1.5,2,4} */
6007 switch (DIV_ROUND_CLOSEST(vco
, cdclk
)) {
6009 divider
= BXT_CDCLK_CD2X_DIV_SEL_4
;
6012 divider
= BXT_CDCLK_CD2X_DIV_SEL_2
;
6015 divider
= BXT_CDCLK_CD2X_DIV_SEL_1_5
;
6018 divider
= BXT_CDCLK_CD2X_DIV_SEL_1
;
6021 WARN_ON(cdclk
!= dev_priv
->cdclk_pll
.ref
);
6024 divider
= BXT_CDCLK_CD2X_DIV_SEL_1
;
6028 /* Inform power controller of upcoming frequency change */
6029 mutex_lock(&dev_priv
->rps
.hw_lock
);
6030 ret
= sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
,
6032 mutex_unlock(&dev_priv
->rps
.hw_lock
);
6035 DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n",
6040 if (dev_priv
->cdclk_pll
.vco
!= 0 &&
6041 dev_priv
->cdclk_pll
.vco
!= vco
)
6042 bxt_de_pll_disable(dev_priv
);
6044 if (dev_priv
->cdclk_pll
.vco
!= vco
)
6045 bxt_de_pll_enable(dev_priv
, vco
);
6047 val
= divider
| skl_cdclk_decimal(cdclk
);
6049 * FIXME if only the cd2x divider needs changing, it could be done
6050 * without shutting off the pipe (if only one pipe is active).
6052 val
|= BXT_CDCLK_CD2X_PIPE_NONE
;
6054 * Disable SSA Precharge when CD clock frequency < 500 MHz,
6057 if (cdclk
>= 500000)
6058 val
|= BXT_CDCLK_SSA_PRECHARGE_ENABLE
;
6059 I915_WRITE(CDCLK_CTL
, val
);
6061 mutex_lock(&dev_priv
->rps
.hw_lock
);
6062 ret
= sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
,
6063 DIV_ROUND_UP(cdclk
, 25000));
6064 mutex_unlock(&dev_priv
->rps
.hw_lock
);
6067 DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n",
6072 intel_update_cdclk(&dev_priv
->drm
);
6075 static void bxt_sanitize_cdclk(struct drm_i915_private
*dev_priv
)
6077 u32 cdctl
, expected
;
6079 intel_update_cdclk(&dev_priv
->drm
);
6081 if (dev_priv
->cdclk_pll
.vco
== 0 ||
6082 dev_priv
->cdclk_freq
== dev_priv
->cdclk_pll
.ref
)
6085 /* DPLL okay; verify the cdclock
6087 * Some BIOS versions leave an incorrect decimal frequency value and
6088 * set reserved MBZ bits in CDCLK_CTL at least during exiting from S4,
6089 * so sanitize this register.
6091 cdctl
= I915_READ(CDCLK_CTL
);
6093 * Let's ignore the pipe field, since BIOS could have configured the
6094 * dividers both synching to an active pipe, or asynchronously
6097 cdctl
&= ~BXT_CDCLK_CD2X_PIPE_NONE
;
6099 expected
= (cdctl
& BXT_CDCLK_CD2X_DIV_SEL_MASK
) |
6100 skl_cdclk_decimal(dev_priv
->cdclk_freq
);
6102 * Disable SSA Precharge when CD clock frequency < 500 MHz,
6105 if (dev_priv
->cdclk_freq
>= 500000)
6106 expected
|= BXT_CDCLK_SSA_PRECHARGE_ENABLE
;
6108 if (cdctl
== expected
)
6109 /* All well; nothing to sanitize */
6113 DRM_DEBUG_KMS("Sanitizing cdclk programmed by pre-os\n");
6115 /* force cdclk programming */
6116 dev_priv
->cdclk_freq
= 0;
6118 /* force full PLL disable + enable */
6119 dev_priv
->cdclk_pll
.vco
= -1;
6122 void bxt_init_cdclk(struct drm_i915_private
*dev_priv
)
6124 bxt_sanitize_cdclk(dev_priv
);
6126 if (dev_priv
->cdclk_freq
!= 0 && dev_priv
->cdclk_pll
.vco
!= 0)
6131 * - The initial CDCLK needs to be read from VBT.
6132 * Need to make this change after VBT has changes for BXT.
6134 bxt_set_cdclk(dev_priv
, bxt_calc_cdclk(0));
6137 void bxt_uninit_cdclk(struct drm_i915_private
*dev_priv
)
6139 bxt_set_cdclk(dev_priv
, dev_priv
->cdclk_pll
.ref
);
6142 static int skl_calc_cdclk(int max_pixclk
, int vco
)
6144 if (vco
== 8640000) {
6145 if (max_pixclk
> 540000)
6147 else if (max_pixclk
> 432000)
6149 else if (max_pixclk
> 308571)
6154 if (max_pixclk
> 540000)
6156 else if (max_pixclk
> 450000)
6158 else if (max_pixclk
> 337500)
6166 skl_dpll0_update(struct drm_i915_private
*dev_priv
)
6170 dev_priv
->cdclk_pll
.ref
= 24000;
6171 dev_priv
->cdclk_pll
.vco
= 0;
6173 val
= I915_READ(LCPLL1_CTL
);
6174 if ((val
& LCPLL_PLL_ENABLE
) == 0)
6177 if (WARN_ON((val
& LCPLL_PLL_LOCK
) == 0))
6180 val
= I915_READ(DPLL_CTRL1
);
6182 if (WARN_ON((val
& (DPLL_CTRL1_HDMI_MODE(SKL_DPLL0
) |
6183 DPLL_CTRL1_SSC(SKL_DPLL0
) |
6184 DPLL_CTRL1_OVERRIDE(SKL_DPLL0
))) !=
6185 DPLL_CTRL1_OVERRIDE(SKL_DPLL0
)))
6188 switch (val
& DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
)) {
6189 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810
, SKL_DPLL0
):
6190 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1350
, SKL_DPLL0
):
6191 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1620
, SKL_DPLL0
):
6192 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2700
, SKL_DPLL0
):
6193 dev_priv
->cdclk_pll
.vco
= 8100000;
6195 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080
, SKL_DPLL0
):
6196 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2160
, SKL_DPLL0
):
6197 dev_priv
->cdclk_pll
.vco
= 8640000;
6200 MISSING_CASE(val
& DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
));
6205 void skl_set_preferred_cdclk_vco(struct drm_i915_private
*dev_priv
, int vco
)
6207 bool changed
= dev_priv
->skl_preferred_vco_freq
!= vco
;
6209 dev_priv
->skl_preferred_vco_freq
= vco
;
6212 intel_update_max_cdclk(&dev_priv
->drm
);
6216 skl_dpll0_enable(struct drm_i915_private
*dev_priv
, int vco
)
6218 int min_cdclk
= skl_calc_cdclk(0, vco
);
6221 WARN_ON(vco
!= 8100000 && vco
!= 8640000);
6223 /* select the minimum CDCLK before enabling DPLL 0 */
6224 val
= CDCLK_FREQ_337_308
| skl_cdclk_decimal(min_cdclk
);
6225 I915_WRITE(CDCLK_CTL
, val
);
6226 POSTING_READ(CDCLK_CTL
);
6229 * We always enable DPLL0 with the lowest link rate possible, but still
6230 * taking into account the VCO required to operate the eDP panel at the
6231 * desired frequency. The usual DP link rates operate with a VCO of
6232 * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640.
6233 * The modeset code is responsible for the selection of the exact link
6234 * rate later on, with the constraint of choosing a frequency that
6237 val
= I915_READ(DPLL_CTRL1
);
6239 val
&= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0
) | DPLL_CTRL1_SSC(SKL_DPLL0
) |
6240 DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
));
6241 val
|= DPLL_CTRL1_OVERRIDE(SKL_DPLL0
);
6243 val
|= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080
,
6246 val
|= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810
,
6249 I915_WRITE(DPLL_CTRL1
, val
);
6250 POSTING_READ(DPLL_CTRL1
);
6252 I915_WRITE(LCPLL1_CTL
, I915_READ(LCPLL1_CTL
) | LCPLL_PLL_ENABLE
);
6254 if (intel_wait_for_register(dev_priv
,
6255 LCPLL1_CTL
, LCPLL_PLL_LOCK
, LCPLL_PLL_LOCK
,
6257 DRM_ERROR("DPLL0 not locked\n");
6259 dev_priv
->cdclk_pll
.vco
= vco
;
6261 /* We'll want to keep using the current vco from now on. */
6262 skl_set_preferred_cdclk_vco(dev_priv
, vco
);
6266 skl_dpll0_disable(struct drm_i915_private
*dev_priv
)
6268 I915_WRITE(LCPLL1_CTL
, I915_READ(LCPLL1_CTL
) & ~LCPLL_PLL_ENABLE
);
6269 if (intel_wait_for_register(dev_priv
,
6270 LCPLL1_CTL
, LCPLL_PLL_LOCK
, 0,
6272 DRM_ERROR("Couldn't disable DPLL0\n");
6274 dev_priv
->cdclk_pll
.vco
= 0;
6277 static bool skl_cdclk_pcu_ready(struct drm_i915_private
*dev_priv
)
6282 /* inform PCU we want to change CDCLK */
6283 val
= SKL_CDCLK_PREPARE_FOR_CHANGE
;
6284 mutex_lock(&dev_priv
->rps
.hw_lock
);
6285 ret
= sandybridge_pcode_read(dev_priv
, SKL_PCODE_CDCLK_CONTROL
, &val
);
6286 mutex_unlock(&dev_priv
->rps
.hw_lock
);
6288 return ret
== 0 && (val
& SKL_CDCLK_READY_FOR_CHANGE
);
6291 static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private
*dev_priv
)
6293 return _wait_for(skl_cdclk_pcu_ready(dev_priv
), 3000, 10) == 0;
6296 static void skl_set_cdclk(struct drm_i915_private
*dev_priv
, int cdclk
, int vco
)
6298 struct drm_device
*dev
= &dev_priv
->drm
;
6299 u32 freq_select
, pcu_ack
;
6301 WARN_ON((cdclk
== 24000) != (vco
== 0));
6303 DRM_DEBUG_DRIVER("Changing CDCLK to %d kHz (VCO %d kHz)\n", cdclk
, vco
);
6305 if (!skl_cdclk_wait_for_pcu_ready(dev_priv
)) {
6306 DRM_ERROR("failed to inform PCU about cdclk change\n");
6314 freq_select
= CDCLK_FREQ_450_432
;
6318 freq_select
= CDCLK_FREQ_540
;
6324 freq_select
= CDCLK_FREQ_337_308
;
6329 freq_select
= CDCLK_FREQ_675_617
;
6334 if (dev_priv
->cdclk_pll
.vco
!= 0 &&
6335 dev_priv
->cdclk_pll
.vco
!= vco
)
6336 skl_dpll0_disable(dev_priv
);
6338 if (dev_priv
->cdclk_pll
.vco
!= vco
)
6339 skl_dpll0_enable(dev_priv
, vco
);
6341 I915_WRITE(CDCLK_CTL
, freq_select
| skl_cdclk_decimal(cdclk
));
6342 POSTING_READ(CDCLK_CTL
);
6344 /* inform PCU of the change */
6345 mutex_lock(&dev_priv
->rps
.hw_lock
);
6346 sandybridge_pcode_write(dev_priv
, SKL_PCODE_CDCLK_CONTROL
, pcu_ack
);
6347 mutex_unlock(&dev_priv
->rps
.hw_lock
);
6349 intel_update_cdclk(dev
);
6352 static void skl_sanitize_cdclk(struct drm_i915_private
*dev_priv
);
6354 void skl_uninit_cdclk(struct drm_i915_private
*dev_priv
)
6356 skl_set_cdclk(dev_priv
, dev_priv
->cdclk_pll
.ref
, 0);
6359 void skl_init_cdclk(struct drm_i915_private
*dev_priv
)
6363 skl_sanitize_cdclk(dev_priv
);
6365 if (dev_priv
->cdclk_freq
!= 0 && dev_priv
->cdclk_pll
.vco
!= 0) {
6367 * Use the current vco as our initial
6368 * guess as to what the preferred vco is.
6370 if (dev_priv
->skl_preferred_vco_freq
== 0)
6371 skl_set_preferred_cdclk_vco(dev_priv
,
6372 dev_priv
->cdclk_pll
.vco
);
6376 vco
= dev_priv
->skl_preferred_vco_freq
;
6379 cdclk
= skl_calc_cdclk(0, vco
);
6381 skl_set_cdclk(dev_priv
, cdclk
, vco
);
6384 static void skl_sanitize_cdclk(struct drm_i915_private
*dev_priv
)
6386 uint32_t cdctl
, expected
;
6389 * check if the pre-os intialized the display
6390 * There is SWF18 scratchpad register defined which is set by the
6391 * pre-os which can be used by the OS drivers to check the status
6393 if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0)
6396 intel_update_cdclk(&dev_priv
->drm
);
6397 /* Is PLL enabled and locked ? */
6398 if (dev_priv
->cdclk_pll
.vco
== 0 ||
6399 dev_priv
->cdclk_freq
== dev_priv
->cdclk_pll
.ref
)
6402 /* DPLL okay; verify the cdclock
6404 * Noticed in some instances that the freq selection is correct but
6405 * decimal part is programmed wrong from BIOS where pre-os does not
6406 * enable display. Verify the same as well.
6408 cdctl
= I915_READ(CDCLK_CTL
);
6409 expected
= (cdctl
& CDCLK_FREQ_SEL_MASK
) |
6410 skl_cdclk_decimal(dev_priv
->cdclk_freq
);
6411 if (cdctl
== expected
)
6412 /* All well; nothing to sanitize */
6416 DRM_DEBUG_KMS("Sanitizing cdclk programmed by pre-os\n");
6418 /* force cdclk programming */
6419 dev_priv
->cdclk_freq
= 0;
6420 /* force full PLL disable + enable */
6421 dev_priv
->cdclk_pll
.vco
= -1;
6424 /* Adjust CDclk dividers to allow high res or save power if possible */
6425 static void valleyview_set_cdclk(struct drm_device
*dev
, int cdclk
)
6427 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6430 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
)
6431 != dev_priv
->cdclk_freq
);
6433 if (cdclk
>= 320000) /* jump to highest voltage for 400MHz too */
6435 else if (cdclk
== 266667)
6440 mutex_lock(&dev_priv
->rps
.hw_lock
);
6441 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
6442 val
&= ~DSPFREQGUAR_MASK
;
6443 val
|= (cmd
<< DSPFREQGUAR_SHIFT
);
6444 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
6445 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
6446 DSPFREQSTAT_MASK
) == (cmd
<< DSPFREQSTAT_SHIFT
),
6448 DRM_ERROR("timed out waiting for CDclk change\n");
6450 mutex_unlock(&dev_priv
->rps
.hw_lock
);
6452 mutex_lock(&dev_priv
->sb_lock
);
6454 if (cdclk
== 400000) {
6457 divider
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
6459 /* adjust cdclk divider */
6460 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
6461 val
&= ~CCK_FREQUENCY_VALUES
;
6463 vlv_cck_write(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
, val
);
6465 if (wait_for((vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
) &
6466 CCK_FREQUENCY_STATUS
) == (divider
<< CCK_FREQUENCY_STATUS_SHIFT
),
6468 DRM_ERROR("timed out waiting for CDclk change\n");
6471 /* adjust self-refresh exit latency value */
6472 val
= vlv_bunit_read(dev_priv
, BUNIT_REG_BISOC
);
6476 * For high bandwidth configs, we set a higher latency in the bunit
6477 * so that the core display fetch happens in time to avoid underruns.
6479 if (cdclk
== 400000)
6480 val
|= 4500 / 250; /* 4.5 usec */
6482 val
|= 3000 / 250; /* 3.0 usec */
6483 vlv_bunit_write(dev_priv
, BUNIT_REG_BISOC
, val
);
6485 mutex_unlock(&dev_priv
->sb_lock
);
6487 intel_update_cdclk(dev
);
6490 static void cherryview_set_cdclk(struct drm_device
*dev
, int cdclk
)
6492 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6495 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
)
6496 != dev_priv
->cdclk_freq
);
6505 MISSING_CASE(cdclk
);
6510 * Specs are full of misinformation, but testing on actual
6511 * hardware has shown that we just need to write the desired
6512 * CCK divider into the Punit register.
6514 cmd
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
6516 mutex_lock(&dev_priv
->rps
.hw_lock
);
6517 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
6518 val
&= ~DSPFREQGUAR_MASK_CHV
;
6519 val
|= (cmd
<< DSPFREQGUAR_SHIFT_CHV
);
6520 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
6521 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
6522 DSPFREQSTAT_MASK_CHV
) == (cmd
<< DSPFREQSTAT_SHIFT_CHV
),
6524 DRM_ERROR("timed out waiting for CDclk change\n");
6526 mutex_unlock(&dev_priv
->rps
.hw_lock
);
6528 intel_update_cdclk(dev
);
6531 static int valleyview_calc_cdclk(struct drm_i915_private
*dev_priv
,
6534 int freq_320
= (dev_priv
->hpll_freq
<< 1) % 320000 != 0 ? 333333 : 320000;
6535 int limit
= IS_CHERRYVIEW(dev_priv
) ? 95 : 90;
6538 * Really only a few cases to deal with, as only 4 CDclks are supported:
6541 * 320/333MHz (depends on HPLL freq)
6543 * So we check to see whether we're above 90% (VLV) or 95% (CHV)
6544 * of the lower bin and adjust if needed.
6546 * We seem to get an unstable or solid color picture at 200MHz.
6547 * Not sure what's wrong. For now use 200MHz only when all pipes
6550 if (!IS_CHERRYVIEW(dev_priv
) &&
6551 max_pixclk
> freq_320
*limit
/100)
6553 else if (max_pixclk
> 266667*limit
/100)
6555 else if (max_pixclk
> 0)
6561 static int bxt_calc_cdclk(int max_pixclk
)
6563 if (max_pixclk
> 576000)
6565 else if (max_pixclk
> 384000)
6567 else if (max_pixclk
> 288000)
6569 else if (max_pixclk
> 144000)
6575 /* Compute the max pixel clock for new configuration. */
6576 static int intel_mode_max_pixclk(struct drm_device
*dev
,
6577 struct drm_atomic_state
*state
)
6579 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
6580 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6581 struct drm_crtc
*crtc
;
6582 struct drm_crtc_state
*crtc_state
;
6583 unsigned max_pixclk
= 0, i
;
6586 memcpy(intel_state
->min_pixclk
, dev_priv
->min_pixclk
,
6587 sizeof(intel_state
->min_pixclk
));
6589 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
6592 if (crtc_state
->enable
)
6593 pixclk
= crtc_state
->adjusted_mode
.crtc_clock
;
6595 intel_state
->min_pixclk
[i
] = pixclk
;
6598 for_each_pipe(dev_priv
, pipe
)
6599 max_pixclk
= max(intel_state
->min_pixclk
[pipe
], max_pixclk
);
6604 static int valleyview_modeset_calc_cdclk(struct drm_atomic_state
*state
)
6606 struct drm_device
*dev
= state
->dev
;
6607 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6608 int max_pixclk
= intel_mode_max_pixclk(dev
, state
);
6609 struct intel_atomic_state
*intel_state
=
6610 to_intel_atomic_state(state
);
6612 intel_state
->cdclk
= intel_state
->dev_cdclk
=
6613 valleyview_calc_cdclk(dev_priv
, max_pixclk
);
6615 if (!intel_state
->active_crtcs
)
6616 intel_state
->dev_cdclk
= valleyview_calc_cdclk(dev_priv
, 0);
6621 static int bxt_modeset_calc_cdclk(struct drm_atomic_state
*state
)
6623 int max_pixclk
= ilk_max_pixel_rate(state
);
6624 struct intel_atomic_state
*intel_state
=
6625 to_intel_atomic_state(state
);
6627 intel_state
->cdclk
= intel_state
->dev_cdclk
=
6628 bxt_calc_cdclk(max_pixclk
);
6630 if (!intel_state
->active_crtcs
)
6631 intel_state
->dev_cdclk
= bxt_calc_cdclk(0);
6636 static void vlv_program_pfi_credits(struct drm_i915_private
*dev_priv
)
6638 unsigned int credits
, default_credits
;
6640 if (IS_CHERRYVIEW(dev_priv
))
6641 default_credits
= PFI_CREDIT(12);
6643 default_credits
= PFI_CREDIT(8);
6645 if (dev_priv
->cdclk_freq
>= dev_priv
->czclk_freq
) {
6646 /* CHV suggested value is 31 or 63 */
6647 if (IS_CHERRYVIEW(dev_priv
))
6648 credits
= PFI_CREDIT_63
;
6650 credits
= PFI_CREDIT(15);
6652 credits
= default_credits
;
6656 * WA - write default credits before re-programming
6657 * FIXME: should we also set the resend bit here?
6659 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
6662 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
6663 credits
| PFI_CREDIT_RESEND
);
6666 * FIXME is this guaranteed to clear
6667 * immediately or should we poll for it?
6669 WARN_ON(I915_READ(GCI_CONTROL
) & PFI_CREDIT_RESEND
);
6672 static void valleyview_modeset_commit_cdclk(struct drm_atomic_state
*old_state
)
6674 struct drm_device
*dev
= old_state
->dev
;
6675 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6676 struct intel_atomic_state
*old_intel_state
=
6677 to_intel_atomic_state(old_state
);
6678 unsigned req_cdclk
= old_intel_state
->dev_cdclk
;
6681 * FIXME: We can end up here with all power domains off, yet
6682 * with a CDCLK frequency other than the minimum. To account
6683 * for this take the PIPE-A power domain, which covers the HW
6684 * blocks needed for the following programming. This can be
6685 * removed once it's guaranteed that we get here either with
6686 * the minimum CDCLK set, or the required power domains
6689 intel_display_power_get(dev_priv
, POWER_DOMAIN_PIPE_A
);
6691 if (IS_CHERRYVIEW(dev_priv
))
6692 cherryview_set_cdclk(dev
, req_cdclk
);
6694 valleyview_set_cdclk(dev
, req_cdclk
);
6696 vlv_program_pfi_credits(dev_priv
);
6698 intel_display_power_put(dev_priv
, POWER_DOMAIN_PIPE_A
);
6701 static void valleyview_crtc_enable(struct intel_crtc_state
*pipe_config
,
6702 struct drm_atomic_state
*old_state
)
6704 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
6705 struct drm_device
*dev
= crtc
->dev
;
6706 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6707 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6708 int pipe
= intel_crtc
->pipe
;
6710 if (WARN_ON(intel_crtc
->active
))
6713 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
6714 intel_dp_set_m_n(intel_crtc
, M1_N1
);
6716 intel_set_pipe_timings(intel_crtc
);
6717 intel_set_pipe_src_size(intel_crtc
);
6719 if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_B
) {
6720 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6722 I915_WRITE(CHV_BLEND(pipe
), CHV_BLEND_LEGACY
);
6723 I915_WRITE(CHV_CANVAS(pipe
), 0);
6726 i9xx_set_pipeconf(intel_crtc
);
6728 intel_crtc
->active
= true;
6730 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
6732 intel_encoders_pre_pll_enable(crtc
, pipe_config
, old_state
);
6734 if (IS_CHERRYVIEW(dev_priv
)) {
6735 chv_prepare_pll(intel_crtc
, intel_crtc
->config
);
6736 chv_enable_pll(intel_crtc
, intel_crtc
->config
);
6738 vlv_prepare_pll(intel_crtc
, intel_crtc
->config
);
6739 vlv_enable_pll(intel_crtc
, intel_crtc
->config
);
6742 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
6744 i9xx_pfit_enable(intel_crtc
);
6746 intel_color_load_luts(&pipe_config
->base
);
6748 intel_update_watermarks(crtc
);
6749 intel_enable_pipe(intel_crtc
);
6751 assert_vblank_disabled(crtc
);
6752 drm_crtc_vblank_on(crtc
);
6754 intel_encoders_enable(crtc
, pipe_config
, old_state
);
6757 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
6759 struct drm_device
*dev
= crtc
->base
.dev
;
6760 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6762 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp0
);
6763 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp1
);
6766 static void i9xx_crtc_enable(struct intel_crtc_state
*pipe_config
,
6767 struct drm_atomic_state
*old_state
)
6769 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
6770 struct drm_device
*dev
= crtc
->dev
;
6771 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6772 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6773 enum pipe pipe
= intel_crtc
->pipe
;
6775 if (WARN_ON(intel_crtc
->active
))
6778 i9xx_set_pll_dividers(intel_crtc
);
6780 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
6781 intel_dp_set_m_n(intel_crtc
, M1_N1
);
6783 intel_set_pipe_timings(intel_crtc
);
6784 intel_set_pipe_src_size(intel_crtc
);
6786 i9xx_set_pipeconf(intel_crtc
);
6788 intel_crtc
->active
= true;
6790 if (!IS_GEN2(dev_priv
))
6791 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
6793 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
6795 i9xx_enable_pll(intel_crtc
);
6797 i9xx_pfit_enable(intel_crtc
);
6799 intel_color_load_luts(&pipe_config
->base
);
6801 intel_update_watermarks(crtc
);
6802 intel_enable_pipe(intel_crtc
);
6804 assert_vblank_disabled(crtc
);
6805 drm_crtc_vblank_on(crtc
);
6807 intel_encoders_enable(crtc
, pipe_config
, old_state
);
6810 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
6812 struct drm_device
*dev
= crtc
->base
.dev
;
6813 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6815 if (!crtc
->config
->gmch_pfit
.control
)
6818 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
6820 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
6821 I915_READ(PFIT_CONTROL
));
6822 I915_WRITE(PFIT_CONTROL
, 0);
6825 static void i9xx_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
6826 struct drm_atomic_state
*old_state
)
6828 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
6829 struct drm_device
*dev
= crtc
->dev
;
6830 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6831 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6832 int pipe
= intel_crtc
->pipe
;
6835 * On gen2 planes are double buffered but the pipe isn't, so we must
6836 * wait for planes to fully turn off before disabling the pipe.
6838 if (IS_GEN2(dev_priv
))
6839 intel_wait_for_vblank(dev
, pipe
);
6841 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
6843 drm_crtc_vblank_off(crtc
);
6844 assert_vblank_disabled(crtc
);
6846 intel_disable_pipe(intel_crtc
);
6848 i9xx_pfit_disable(intel_crtc
);
6850 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
6852 if (!intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DSI
)) {
6853 if (IS_CHERRYVIEW(dev_priv
))
6854 chv_disable_pll(dev_priv
, pipe
);
6855 else if (IS_VALLEYVIEW(dev_priv
))
6856 vlv_disable_pll(dev_priv
, pipe
);
6858 i9xx_disable_pll(intel_crtc
);
6861 intel_encoders_post_pll_disable(crtc
, old_crtc_state
, old_state
);
6863 if (!IS_GEN2(dev_priv
))
6864 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
6867 static void intel_crtc_disable_noatomic(struct drm_crtc
*crtc
)
6869 struct intel_encoder
*encoder
;
6870 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6871 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
6872 enum intel_display_power_domain domain
;
6873 unsigned long domains
;
6874 struct drm_atomic_state
*state
;
6875 struct intel_crtc_state
*crtc_state
;
6878 if (!intel_crtc
->active
)
6881 if (to_intel_plane_state(crtc
->primary
->state
)->base
.visible
) {
6882 WARN_ON(intel_crtc
->flip_work
);
6884 intel_pre_disable_primary_noatomic(crtc
);
6886 intel_crtc_disable_planes(crtc
, 1 << drm_plane_index(crtc
->primary
));
6887 to_intel_plane_state(crtc
->primary
->state
)->base
.visible
= false;
6890 state
= drm_atomic_state_alloc(crtc
->dev
);
6891 state
->acquire_ctx
= crtc
->dev
->mode_config
.acquire_ctx
;
6893 /* Everything's already locked, -EDEADLK can't happen. */
6894 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
6895 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
6897 WARN_ON(IS_ERR(crtc_state
) || ret
);
6899 dev_priv
->display
.crtc_disable(crtc_state
, state
);
6901 drm_atomic_state_put(state
);
6903 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6904 crtc
->base
.id
, crtc
->name
);
6906 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->state
, NULL
) < 0);
6907 crtc
->state
->active
= false;
6908 intel_crtc
->active
= false;
6909 crtc
->enabled
= false;
6910 crtc
->state
->connector_mask
= 0;
6911 crtc
->state
->encoder_mask
= 0;
6913 for_each_encoder_on_crtc(crtc
->dev
, crtc
, encoder
)
6914 encoder
->base
.crtc
= NULL
;
6916 intel_fbc_disable(intel_crtc
);
6917 intel_update_watermarks(crtc
);
6918 intel_disable_shared_dpll(intel_crtc
);
6920 domains
= intel_crtc
->enabled_power_domains
;
6921 for_each_power_domain(domain
, domains
)
6922 intel_display_power_put(dev_priv
, domain
);
6923 intel_crtc
->enabled_power_domains
= 0;
6925 dev_priv
->active_crtcs
&= ~(1 << intel_crtc
->pipe
);
6926 dev_priv
->min_pixclk
[intel_crtc
->pipe
] = 0;
6930 * turn all crtc's off, but do not adjust state
6931 * This has to be paired with a call to intel_modeset_setup_hw_state.
6933 int intel_display_suspend(struct drm_device
*dev
)
6935 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6936 struct drm_atomic_state
*state
;
6939 state
= drm_atomic_helper_suspend(dev
);
6940 ret
= PTR_ERR_OR_ZERO(state
);
6942 DRM_ERROR("Suspending crtc's failed with %i\n", ret
);
6944 dev_priv
->modeset_restore_state
= state
;
6948 void intel_encoder_destroy(struct drm_encoder
*encoder
)
6950 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
6952 drm_encoder_cleanup(encoder
);
6953 kfree(intel_encoder
);
6956 /* Cross check the actual hw state with our own modeset state tracking (and it's
6957 * internal consistency). */
6958 static void intel_connector_verify_state(struct intel_connector
*connector
)
6960 struct drm_crtc
*crtc
= connector
->base
.state
->crtc
;
6962 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6963 connector
->base
.base
.id
,
6964 connector
->base
.name
);
6966 if (connector
->get_hw_state(connector
)) {
6967 struct intel_encoder
*encoder
= connector
->encoder
;
6968 struct drm_connector_state
*conn_state
= connector
->base
.state
;
6970 I915_STATE_WARN(!crtc
,
6971 "connector enabled without attached crtc\n");
6976 I915_STATE_WARN(!crtc
->state
->active
,
6977 "connector is active, but attached crtc isn't\n");
6979 if (!encoder
|| encoder
->type
== INTEL_OUTPUT_DP_MST
)
6982 I915_STATE_WARN(conn_state
->best_encoder
!= &encoder
->base
,
6983 "atomic encoder doesn't match attached encoder\n");
6985 I915_STATE_WARN(conn_state
->crtc
!= encoder
->base
.crtc
,
6986 "attached encoder crtc differs from connector crtc\n");
6988 I915_STATE_WARN(crtc
&& crtc
->state
->active
,
6989 "attached crtc is active, but connector isn't\n");
6990 I915_STATE_WARN(!crtc
&& connector
->base
.state
->best_encoder
,
6991 "best encoder set without crtc!\n");
6995 int intel_connector_init(struct intel_connector
*connector
)
6997 drm_atomic_helper_connector_reset(&connector
->base
);
6999 if (!connector
->base
.state
)
7005 struct intel_connector
*intel_connector_alloc(void)
7007 struct intel_connector
*connector
;
7009 connector
= kzalloc(sizeof *connector
, GFP_KERNEL
);
7013 if (intel_connector_init(connector
) < 0) {
7021 /* Simple connector->get_hw_state implementation for encoders that support only
7022 * one connector and no cloning and hence the encoder state determines the state
7023 * of the connector. */
7024 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
7027 struct intel_encoder
*encoder
= connector
->encoder
;
7029 return encoder
->get_hw_state(encoder
, &pipe
);
7032 static int pipe_required_fdi_lanes(struct intel_crtc_state
*crtc_state
)
7034 if (crtc_state
->base
.enable
&& crtc_state
->has_pch_encoder
)
7035 return crtc_state
->fdi_lanes
;
7040 static int ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
7041 struct intel_crtc_state
*pipe_config
)
7043 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7044 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
7045 struct intel_crtc
*other_crtc
;
7046 struct intel_crtc_state
*other_crtc_state
;
7048 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
7049 pipe_name(pipe
), pipe_config
->fdi_lanes
);
7050 if (pipe_config
->fdi_lanes
> 4) {
7051 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
7052 pipe_name(pipe
), pipe_config
->fdi_lanes
);
7056 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
7057 if (pipe_config
->fdi_lanes
> 2) {
7058 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
7059 pipe_config
->fdi_lanes
);
7066 if (INTEL_INFO(dev
)->num_pipes
== 2)
7069 /* Ivybridge 3 pipe is really complicated */
7074 if (pipe_config
->fdi_lanes
<= 2)
7077 other_crtc
= to_intel_crtc(intel_get_crtc_for_pipe(dev
, PIPE_C
));
7079 intel_atomic_get_crtc_state(state
, other_crtc
);
7080 if (IS_ERR(other_crtc_state
))
7081 return PTR_ERR(other_crtc_state
);
7083 if (pipe_required_fdi_lanes(other_crtc_state
) > 0) {
7084 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
7085 pipe_name(pipe
), pipe_config
->fdi_lanes
);
7090 if (pipe_config
->fdi_lanes
> 2) {
7091 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
7092 pipe_name(pipe
), pipe_config
->fdi_lanes
);
7096 other_crtc
= to_intel_crtc(intel_get_crtc_for_pipe(dev
, PIPE_B
));
7098 intel_atomic_get_crtc_state(state
, other_crtc
);
7099 if (IS_ERR(other_crtc_state
))
7100 return PTR_ERR(other_crtc_state
);
7102 if (pipe_required_fdi_lanes(other_crtc_state
) > 2) {
7103 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
7113 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
7114 struct intel_crtc_state
*pipe_config
)
7116 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7117 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
7118 int lane
, link_bw
, fdi_dotclock
, ret
;
7119 bool needs_recompute
= false;
7122 /* FDI is a binary signal running at ~2.7GHz, encoding
7123 * each output octet as 10 bits. The actual frequency
7124 * is stored as a divider into a 100MHz clock, and the
7125 * mode pixel clock is stored in units of 1KHz.
7126 * Hence the bw of each lane in terms of the mode signal
7129 link_bw
= intel_fdi_link_freq(to_i915(dev
), pipe_config
);
7131 fdi_dotclock
= adjusted_mode
->crtc_clock
;
7133 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
7134 pipe_config
->pipe_bpp
);
7136 pipe_config
->fdi_lanes
= lane
;
7138 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
7139 link_bw
, &pipe_config
->fdi_m_n
);
7141 ret
= ironlake_check_fdi_lanes(dev
, intel_crtc
->pipe
, pipe_config
);
7142 if (ret
== -EINVAL
&& pipe_config
->pipe_bpp
> 6*3) {
7143 pipe_config
->pipe_bpp
-= 2*3;
7144 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
7145 pipe_config
->pipe_bpp
);
7146 needs_recompute
= true;
7147 pipe_config
->bw_constrained
= true;
7152 if (needs_recompute
)
7158 static bool pipe_config_supports_ips(struct drm_i915_private
*dev_priv
,
7159 struct intel_crtc_state
*pipe_config
)
7161 if (pipe_config
->pipe_bpp
> 24)
7164 /* HSW can handle pixel rate up to cdclk? */
7165 if (IS_HASWELL(dev_priv
))
7169 * We compare against max which means we must take
7170 * the increased cdclk requirement into account when
7171 * calculating the new cdclk.
7173 * Should measure whether using a lower cdclk w/o IPS
7175 return ilk_pipe_pixel_rate(pipe_config
) <=
7176 dev_priv
->max_cdclk_freq
* 95 / 100;
7179 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
7180 struct intel_crtc_state
*pipe_config
)
7182 struct drm_device
*dev
= crtc
->base
.dev
;
7183 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7185 pipe_config
->ips_enabled
= i915
.enable_ips
&&
7186 hsw_crtc_supports_ips(crtc
) &&
7187 pipe_config_supports_ips(dev_priv
, pipe_config
);
7190 static bool intel_crtc_supports_double_wide(const struct intel_crtc
*crtc
)
7192 const struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7194 /* GDG double wide on either pipe, otherwise pipe A only */
7195 return INTEL_INFO(dev_priv
)->gen
< 4 &&
7196 (crtc
->pipe
== PIPE_A
|| IS_I915G(dev_priv
));
7199 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
7200 struct intel_crtc_state
*pipe_config
)
7202 struct drm_device
*dev
= crtc
->base
.dev
;
7203 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7204 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
7205 int clock_limit
= dev_priv
->max_dotclk_freq
;
7207 if (INTEL_INFO(dev
)->gen
< 4) {
7208 clock_limit
= dev_priv
->max_cdclk_freq
* 9 / 10;
7211 * Enable double wide mode when the dot clock
7212 * is > 90% of the (display) core speed.
7214 if (intel_crtc_supports_double_wide(crtc
) &&
7215 adjusted_mode
->crtc_clock
> clock_limit
) {
7216 clock_limit
= dev_priv
->max_dotclk_freq
;
7217 pipe_config
->double_wide
= true;
7221 if (adjusted_mode
->crtc_clock
> clock_limit
) {
7222 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
7223 adjusted_mode
->crtc_clock
, clock_limit
,
7224 yesno(pipe_config
->double_wide
));
7229 * Pipe horizontal size must be even in:
7231 * - LVDS dual channel mode
7232 * - Double wide pipe
7234 if ((intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_LVDS
) &&
7235 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
7236 pipe_config
->pipe_src_w
&= ~1;
7238 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
7239 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
7241 if ((INTEL_GEN(dev_priv
) > 4 || IS_G4X(dev_priv
)) &&
7242 adjusted_mode
->crtc_hsync_start
== adjusted_mode
->crtc_hdisplay
)
7245 if (HAS_IPS(dev_priv
))
7246 hsw_compute_ips_config(crtc
, pipe_config
);
7248 if (pipe_config
->has_pch_encoder
)
7249 return ironlake_fdi_compute_config(crtc
, pipe_config
);
7254 static int skylake_get_display_clock_speed(struct drm_device
*dev
)
7256 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7259 skl_dpll0_update(dev_priv
);
7261 if (dev_priv
->cdclk_pll
.vco
== 0)
7262 return dev_priv
->cdclk_pll
.ref
;
7264 cdctl
= I915_READ(CDCLK_CTL
);
7266 if (dev_priv
->cdclk_pll
.vco
== 8640000) {
7267 switch (cdctl
& CDCLK_FREQ_SEL_MASK
) {
7268 case CDCLK_FREQ_450_432
:
7270 case CDCLK_FREQ_337_308
:
7272 case CDCLK_FREQ_540
:
7274 case CDCLK_FREQ_675_617
:
7277 MISSING_CASE(cdctl
& CDCLK_FREQ_SEL_MASK
);
7280 switch (cdctl
& CDCLK_FREQ_SEL_MASK
) {
7281 case CDCLK_FREQ_450_432
:
7283 case CDCLK_FREQ_337_308
:
7285 case CDCLK_FREQ_540
:
7287 case CDCLK_FREQ_675_617
:
7290 MISSING_CASE(cdctl
& CDCLK_FREQ_SEL_MASK
);
7294 return dev_priv
->cdclk_pll
.ref
;
7297 static void bxt_de_pll_update(struct drm_i915_private
*dev_priv
)
7301 dev_priv
->cdclk_pll
.ref
= 19200;
7302 dev_priv
->cdclk_pll
.vco
= 0;
7304 val
= I915_READ(BXT_DE_PLL_ENABLE
);
7305 if ((val
& BXT_DE_PLL_PLL_ENABLE
) == 0)
7308 if (WARN_ON((val
& BXT_DE_PLL_LOCK
) == 0))
7311 val
= I915_READ(BXT_DE_PLL_CTL
);
7312 dev_priv
->cdclk_pll
.vco
= (val
& BXT_DE_PLL_RATIO_MASK
) *
7313 dev_priv
->cdclk_pll
.ref
;
7316 static int broxton_get_display_clock_speed(struct drm_device
*dev
)
7318 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7322 bxt_de_pll_update(dev_priv
);
7324 vco
= dev_priv
->cdclk_pll
.vco
;
7326 return dev_priv
->cdclk_pll
.ref
;
7328 divider
= I915_READ(CDCLK_CTL
) & BXT_CDCLK_CD2X_DIV_SEL_MASK
;
7331 case BXT_CDCLK_CD2X_DIV_SEL_1
:
7334 case BXT_CDCLK_CD2X_DIV_SEL_1_5
:
7337 case BXT_CDCLK_CD2X_DIV_SEL_2
:
7340 case BXT_CDCLK_CD2X_DIV_SEL_4
:
7344 MISSING_CASE(divider
);
7345 return dev_priv
->cdclk_pll
.ref
;
7348 return DIV_ROUND_CLOSEST(vco
, div
);
7351 static int broadwell_get_display_clock_speed(struct drm_device
*dev
)
7353 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7354 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
7355 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
7357 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
7359 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
7361 else if (freq
== LCPLL_CLK_FREQ_450
)
7363 else if (freq
== LCPLL_CLK_FREQ_54O_BDW
)
7365 else if (freq
== LCPLL_CLK_FREQ_337_5_BDW
)
7371 static int haswell_get_display_clock_speed(struct drm_device
*dev
)
7373 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7374 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
7375 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
7377 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
7379 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
7381 else if (freq
== LCPLL_CLK_FREQ_450
)
7383 else if (IS_HSW_ULT(dev_priv
))
7389 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
7391 return vlv_get_cck_clock_hpll(to_i915(dev
), "cdclk",
7392 CCK_DISPLAY_CLOCK_CONTROL
);
7395 static int ilk_get_display_clock_speed(struct drm_device
*dev
)
7400 static int i945_get_display_clock_speed(struct drm_device
*dev
)
7405 static int i915_get_display_clock_speed(struct drm_device
*dev
)
7410 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
7415 static int pnv_get_display_clock_speed(struct drm_device
*dev
)
7417 struct pci_dev
*pdev
= dev
->pdev
;
7420 pci_read_config_word(pdev
, GCFGC
, &gcfgc
);
7422 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
7423 case GC_DISPLAY_CLOCK_267_MHZ_PNV
:
7425 case GC_DISPLAY_CLOCK_333_MHZ_PNV
:
7427 case GC_DISPLAY_CLOCK_444_MHZ_PNV
:
7429 case GC_DISPLAY_CLOCK_200_MHZ_PNV
:
7432 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc
);
7433 case GC_DISPLAY_CLOCK_133_MHZ_PNV
:
7435 case GC_DISPLAY_CLOCK_167_MHZ_PNV
:
7440 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
7442 struct pci_dev
*pdev
= dev
->pdev
;
7445 pci_read_config_word(pdev
, GCFGC
, &gcfgc
);
7447 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
7450 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
7451 case GC_DISPLAY_CLOCK_333_MHZ
:
7454 case GC_DISPLAY_CLOCK_190_200_MHZ
:
7460 static int i865_get_display_clock_speed(struct drm_device
*dev
)
7465 static int i85x_get_display_clock_speed(struct drm_device
*dev
)
7467 struct pci_dev
*pdev
= dev
->pdev
;
7471 * 852GM/852GMV only supports 133 MHz and the HPLLCC
7472 * encoding is different :(
7473 * FIXME is this the right way to detect 852GM/852GMV?
7475 if (pdev
->revision
== 0x1)
7478 pci_bus_read_config_word(pdev
->bus
,
7479 PCI_DEVFN(0, 3), HPLLCC
, &hpllcc
);
7481 /* Assume that the hardware is in the high speed state. This
7482 * should be the default.
7484 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
7485 case GC_CLOCK_133_200
:
7486 case GC_CLOCK_133_200_2
:
7487 case GC_CLOCK_100_200
:
7489 case GC_CLOCK_166_250
:
7491 case GC_CLOCK_100_133
:
7493 case GC_CLOCK_133_266
:
7494 case GC_CLOCK_133_266_2
:
7495 case GC_CLOCK_166_266
:
7499 /* Shouldn't happen */
7503 static int i830_get_display_clock_speed(struct drm_device
*dev
)
7508 static unsigned int intel_hpll_vco(struct drm_device
*dev
)
7510 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7511 static const unsigned int blb_vco
[8] = {
7518 static const unsigned int pnv_vco
[8] = {
7525 static const unsigned int cl_vco
[8] = {
7534 static const unsigned int elk_vco
[8] = {
7540 static const unsigned int ctg_vco
[8] = {
7548 const unsigned int *vco_table
;
7552 /* FIXME other chipsets? */
7553 if (IS_GM45(dev_priv
))
7554 vco_table
= ctg_vco
;
7555 else if (IS_G4X(dev_priv
))
7556 vco_table
= elk_vco
;
7557 else if (IS_CRESTLINE(dev
))
7559 else if (IS_PINEVIEW(dev
))
7560 vco_table
= pnv_vco
;
7561 else if (IS_G33(dev
))
7562 vco_table
= blb_vco
;
7566 tmp
= I915_READ(IS_MOBILE(dev
) ? HPLLVCO_MOBILE
: HPLLVCO
);
7568 vco
= vco_table
[tmp
& 0x7];
7570 DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp
);
7572 DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco
);
7577 static int gm45_get_display_clock_speed(struct drm_device
*dev
)
7579 struct pci_dev
*pdev
= dev
->pdev
;
7580 unsigned int cdclk_sel
, vco
= intel_hpll_vco(dev
);
7583 pci_read_config_word(pdev
, GCFGC
, &tmp
);
7585 cdclk_sel
= (tmp
>> 12) & 0x1;
7591 return cdclk_sel
? 333333 : 222222;
7593 return cdclk_sel
? 320000 : 228571;
7595 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco
, tmp
);
7600 static int i965gm_get_display_clock_speed(struct drm_device
*dev
)
7602 struct pci_dev
*pdev
= dev
->pdev
;
7603 static const uint8_t div_3200
[] = { 16, 10, 8 };
7604 static const uint8_t div_4000
[] = { 20, 12, 10 };
7605 static const uint8_t div_5333
[] = { 24, 16, 14 };
7606 const uint8_t *div_table
;
7607 unsigned int cdclk_sel
, vco
= intel_hpll_vco(dev
);
7610 pci_read_config_word(pdev
, GCFGC
, &tmp
);
7612 cdclk_sel
= ((tmp
>> 8) & 0x1f) - 1;
7614 if (cdclk_sel
>= ARRAY_SIZE(div_3200
))
7619 div_table
= div_3200
;
7622 div_table
= div_4000
;
7625 div_table
= div_5333
;
7631 return DIV_ROUND_CLOSEST(vco
, div_table
[cdclk_sel
]);
7634 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco
, tmp
);
7638 static int g33_get_display_clock_speed(struct drm_device
*dev
)
7640 struct pci_dev
*pdev
= dev
->pdev
;
7641 static const uint8_t div_3200
[] = { 12, 10, 8, 7, 5, 16 };
7642 static const uint8_t div_4000
[] = { 14, 12, 10, 8, 6, 20 };
7643 static const uint8_t div_4800
[] = { 20, 14, 12, 10, 8, 24 };
7644 static const uint8_t div_5333
[] = { 20, 16, 12, 12, 8, 28 };
7645 const uint8_t *div_table
;
7646 unsigned int cdclk_sel
, vco
= intel_hpll_vco(dev
);
7649 pci_read_config_word(pdev
, GCFGC
, &tmp
);
7651 cdclk_sel
= (tmp
>> 4) & 0x7;
7653 if (cdclk_sel
>= ARRAY_SIZE(div_3200
))
7658 div_table
= div_3200
;
7661 div_table
= div_4000
;
7664 div_table
= div_4800
;
7667 div_table
= div_5333
;
7673 return DIV_ROUND_CLOSEST(vco
, div_table
[cdclk_sel
]);
7676 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco
, tmp
);
7681 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
7683 while (*num
> DATA_LINK_M_N_MASK
||
7684 *den
> DATA_LINK_M_N_MASK
) {
7690 static void compute_m_n(unsigned int m
, unsigned int n
,
7691 uint32_t *ret_m
, uint32_t *ret_n
)
7693 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
7694 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
7695 intel_reduce_m_n_ratio(ret_m
, ret_n
);
7699 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
7700 int pixel_clock
, int link_clock
,
7701 struct intel_link_m_n
*m_n
)
7705 compute_m_n(bits_per_pixel
* pixel_clock
,
7706 link_clock
* nlanes
* 8,
7707 &m_n
->gmch_m
, &m_n
->gmch_n
);
7709 compute_m_n(pixel_clock
, link_clock
,
7710 &m_n
->link_m
, &m_n
->link_n
);
7713 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
7715 if (i915
.panel_use_ssc
>= 0)
7716 return i915
.panel_use_ssc
!= 0;
7717 return dev_priv
->vbt
.lvds_use_ssc
7718 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
7721 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
7723 return (1 << dpll
->n
) << 16 | dpll
->m2
;
7726 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
7728 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
7731 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
7732 struct intel_crtc_state
*crtc_state
,
7733 struct dpll
*reduced_clock
)
7735 struct drm_device
*dev
= crtc
->base
.dev
;
7738 if (IS_PINEVIEW(dev
)) {
7739 fp
= pnv_dpll_compute_fp(&crtc_state
->dpll
);
7741 fp2
= pnv_dpll_compute_fp(reduced_clock
);
7743 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
7745 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
7748 crtc_state
->dpll_hw_state
.fp0
= fp
;
7750 crtc
->lowfreq_avail
= false;
7751 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
7753 crtc_state
->dpll_hw_state
.fp1
= fp2
;
7754 crtc
->lowfreq_avail
= true;
7756 crtc_state
->dpll_hw_state
.fp1
= fp
;
7760 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
7766 * PLLB opamp always calibrates to max value of 0x3f, force enable it
7767 * and set it to a reasonable value instead.
7769 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
7770 reg_val
&= 0xffffff00;
7771 reg_val
|= 0x00000030;
7772 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
7774 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
7775 reg_val
&= 0x8cffffff;
7776 reg_val
= 0x8c000000;
7777 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
7779 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
7780 reg_val
&= 0xffffff00;
7781 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
7783 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
7784 reg_val
&= 0x00ffffff;
7785 reg_val
|= 0xb0000000;
7786 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
7789 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
7790 struct intel_link_m_n
*m_n
)
7792 struct drm_device
*dev
= crtc
->base
.dev
;
7793 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7794 int pipe
= crtc
->pipe
;
7796 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
7797 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
7798 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
7799 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
7802 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
7803 struct intel_link_m_n
*m_n
,
7804 struct intel_link_m_n
*m2_n2
)
7806 struct drm_device
*dev
= crtc
->base
.dev
;
7807 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7808 int pipe
= crtc
->pipe
;
7809 enum transcoder transcoder
= crtc
->config
->cpu_transcoder
;
7811 if (INTEL_INFO(dev
)->gen
>= 5) {
7812 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
7813 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
7814 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
7815 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
7816 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
7817 * for gen < 8) and if DRRS is supported (to make sure the
7818 * registers are not unnecessarily accessed).
7820 if (m2_n2
&& (IS_CHERRYVIEW(dev_priv
) ||
7821 INTEL_GEN(dev_priv
) < 8) && crtc
->config
->has_drrs
) {
7822 I915_WRITE(PIPE_DATA_M2(transcoder
),
7823 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
7824 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
7825 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
7826 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
7829 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
7830 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
7831 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
7832 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
7836 void intel_dp_set_m_n(struct intel_crtc
*crtc
, enum link_m_n_set m_n
)
7838 struct intel_link_m_n
*dp_m_n
, *dp_m2_n2
= NULL
;
7841 dp_m_n
= &crtc
->config
->dp_m_n
;
7842 dp_m2_n2
= &crtc
->config
->dp_m2_n2
;
7843 } else if (m_n
== M2_N2
) {
7846 * M2_N2 registers are not supported. Hence m2_n2 divider value
7847 * needs to be programmed into M1_N1.
7849 dp_m_n
= &crtc
->config
->dp_m2_n2
;
7851 DRM_ERROR("Unsupported divider value\n");
7855 if (crtc
->config
->has_pch_encoder
)
7856 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
->dp_m_n
);
7858 intel_cpu_transcoder_set_m_n(crtc
, dp_m_n
, dp_m2_n2
);
7861 static void vlv_compute_dpll(struct intel_crtc
*crtc
,
7862 struct intel_crtc_state
*pipe_config
)
7864 pipe_config
->dpll_hw_state
.dpll
= DPLL_INTEGRATED_REF_CLK_VLV
|
7865 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
7866 if (crtc
->pipe
!= PIPE_A
)
7867 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
7869 /* DPLL not used with DSI, but still need the rest set up */
7870 if (!intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_DSI
))
7871 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
|
7872 DPLL_EXT_BUFFER_ENABLE_VLV
;
7874 pipe_config
->dpll_hw_state
.dpll_md
=
7875 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
7878 static void chv_compute_dpll(struct intel_crtc
*crtc
,
7879 struct intel_crtc_state
*pipe_config
)
7881 pipe_config
->dpll_hw_state
.dpll
= DPLL_SSC_REF_CLK_CHV
|
7882 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
7883 if (crtc
->pipe
!= PIPE_A
)
7884 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
7886 /* DPLL not used with DSI, but still need the rest set up */
7887 if (!intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_DSI
))
7888 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
;
7890 pipe_config
->dpll_hw_state
.dpll_md
=
7891 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
7894 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
7895 const struct intel_crtc_state
*pipe_config
)
7897 struct drm_device
*dev
= crtc
->base
.dev
;
7898 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7899 enum pipe pipe
= crtc
->pipe
;
7901 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
7902 u32 coreclk
, reg_val
;
7905 I915_WRITE(DPLL(pipe
),
7906 pipe_config
->dpll_hw_state
.dpll
&
7907 ~(DPLL_VCO_ENABLE
| DPLL_EXT_BUFFER_ENABLE_VLV
));
7909 /* No need to actually set up the DPLL with DSI */
7910 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7913 mutex_lock(&dev_priv
->sb_lock
);
7915 bestn
= pipe_config
->dpll
.n
;
7916 bestm1
= pipe_config
->dpll
.m1
;
7917 bestm2
= pipe_config
->dpll
.m2
;
7918 bestp1
= pipe_config
->dpll
.p1
;
7919 bestp2
= pipe_config
->dpll
.p2
;
7921 /* See eDP HDMI DPIO driver vbios notes doc */
7923 /* PLL B needs special handling */
7925 vlv_pllb_recal_opamp(dev_priv
, pipe
);
7927 /* Set up Tx target for periodic Rcomp update */
7928 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
7930 /* Disable target IRef on PLL */
7931 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
7932 reg_val
&= 0x00ffffff;
7933 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
7935 /* Disable fast lock */
7936 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
7938 /* Set idtafcrecal before PLL is enabled */
7939 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
7940 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
7941 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
7942 mdiv
|= (1 << DPIO_K_SHIFT
);
7945 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7946 * but we don't support that).
7947 * Note: don't use the DAC post divider as it seems unstable.
7949 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
7950 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
7952 mdiv
|= DPIO_ENABLE_CALIBRATION
;
7953 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
7955 /* Set HBR and RBR LPF coefficients */
7956 if (pipe_config
->port_clock
== 162000 ||
7957 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_ANALOG
) ||
7958 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_HDMI
))
7959 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
7962 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
7965 if (intel_crtc_has_dp_encoder(pipe_config
)) {
7966 /* Use SSC source */
7968 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7971 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7973 } else { /* HDMI or VGA */
7974 /* Use bend source */
7976 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7979 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7983 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
7984 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
7985 if (intel_crtc_has_dp_encoder(crtc
->config
))
7986 coreclk
|= 0x01000000;
7987 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
7989 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
7990 mutex_unlock(&dev_priv
->sb_lock
);
7993 static void chv_prepare_pll(struct intel_crtc
*crtc
,
7994 const struct intel_crtc_state
*pipe_config
)
7996 struct drm_device
*dev
= crtc
->base
.dev
;
7997 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7998 enum pipe pipe
= crtc
->pipe
;
7999 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
8000 u32 loopfilter
, tribuf_calcntr
;
8001 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
8005 /* Enable Refclk and SSC */
8006 I915_WRITE(DPLL(pipe
),
8007 pipe_config
->dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
8009 /* No need to actually set up the DPLL with DSI */
8010 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
8013 bestn
= pipe_config
->dpll
.n
;
8014 bestm2_frac
= pipe_config
->dpll
.m2
& 0x3fffff;
8015 bestm1
= pipe_config
->dpll
.m1
;
8016 bestm2
= pipe_config
->dpll
.m2
>> 22;
8017 bestp1
= pipe_config
->dpll
.p1
;
8018 bestp2
= pipe_config
->dpll
.p2
;
8019 vco
= pipe_config
->dpll
.vco
;
8023 mutex_lock(&dev_priv
->sb_lock
);
8025 /* p1 and p2 divider */
8026 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
8027 5 << DPIO_CHV_S1_DIV_SHIFT
|
8028 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
8029 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
8030 1 << DPIO_CHV_K_DIV_SHIFT
);
8032 /* Feedback post-divider - m2 */
8033 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
8035 /* Feedback refclk divider - n and m1 */
8036 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
8037 DPIO_CHV_M1_DIV_BY_2
|
8038 1 << DPIO_CHV_N_DIV_SHIFT
);
8040 /* M2 fraction division */
8041 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
8043 /* M2 fraction division enable */
8044 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
8045 dpio_val
&= ~(DPIO_CHV_FEEDFWD_GAIN_MASK
| DPIO_CHV_FRAC_DIV_EN
);
8046 dpio_val
|= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
);
8048 dpio_val
|= DPIO_CHV_FRAC_DIV_EN
;
8049 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
), dpio_val
);
8051 /* Program digital lock detect threshold */
8052 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW9(port
));
8053 dpio_val
&= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK
|
8054 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
);
8055 dpio_val
|= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT
);
8057 dpio_val
|= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
;
8058 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW9(port
), dpio_val
);
8061 if (vco
== 5400000) {
8062 loopfilter
|= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT
);
8063 loopfilter
|= (0x8 << DPIO_CHV_INT_COEFF_SHIFT
);
8064 loopfilter
|= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT
);
8065 tribuf_calcntr
= 0x9;
8066 } else if (vco
<= 6200000) {
8067 loopfilter
|= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT
);
8068 loopfilter
|= (0xB << DPIO_CHV_INT_COEFF_SHIFT
);
8069 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
8070 tribuf_calcntr
= 0x9;
8071 } else if (vco
<= 6480000) {
8072 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
8073 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
8074 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
8075 tribuf_calcntr
= 0x8;
8077 /* Not supported. Apply the same limits as in the max case */
8078 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
8079 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
8080 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
8083 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
8085 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW8(port
));
8086 dpio_val
&= ~DPIO_CHV_TDC_TARGET_CNT_MASK
;
8087 dpio_val
|= (tribuf_calcntr
<< DPIO_CHV_TDC_TARGET_CNT_SHIFT
);
8088 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW8(port
), dpio_val
);
8091 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
8092 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
8095 mutex_unlock(&dev_priv
->sb_lock
);
8099 * vlv_force_pll_on - forcibly enable just the PLL
8100 * @dev_priv: i915 private structure
8101 * @pipe: pipe PLL to enable
8102 * @dpll: PLL configuration
8104 * Enable the PLL for @pipe using the supplied @dpll config. To be used
8105 * in cases where we need the PLL enabled even when @pipe is not going to
8108 int vlv_force_pll_on(struct drm_device
*dev
, enum pipe pipe
,
8109 const struct dpll
*dpll
)
8111 struct intel_crtc
*crtc
=
8112 to_intel_crtc(intel_get_crtc_for_pipe(dev
, pipe
));
8113 struct intel_crtc_state
*pipe_config
;
8115 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
8119 pipe_config
->base
.crtc
= &crtc
->base
;
8120 pipe_config
->pixel_multiplier
= 1;
8121 pipe_config
->dpll
= *dpll
;
8123 if (IS_CHERRYVIEW(to_i915(dev
))) {
8124 chv_compute_dpll(crtc
, pipe_config
);
8125 chv_prepare_pll(crtc
, pipe_config
);
8126 chv_enable_pll(crtc
, pipe_config
);
8128 vlv_compute_dpll(crtc
, pipe_config
);
8129 vlv_prepare_pll(crtc
, pipe_config
);
8130 vlv_enable_pll(crtc
, pipe_config
);
8139 * vlv_force_pll_off - forcibly disable just the PLL
8140 * @dev_priv: i915 private structure
8141 * @pipe: pipe PLL to disable
8143 * Disable the PLL for @pipe. To be used in cases where we need
8144 * the PLL enabled even when @pipe is not going to be enabled.
8146 void vlv_force_pll_off(struct drm_device
*dev
, enum pipe pipe
)
8148 if (IS_CHERRYVIEW(to_i915(dev
)))
8149 chv_disable_pll(to_i915(dev
), pipe
);
8151 vlv_disable_pll(to_i915(dev
), pipe
);
8154 static void i9xx_compute_dpll(struct intel_crtc
*crtc
,
8155 struct intel_crtc_state
*crtc_state
,
8156 struct dpll
*reduced_clock
)
8158 struct drm_device
*dev
= crtc
->base
.dev
;
8159 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8161 struct dpll
*clock
= &crtc_state
->dpll
;
8163 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
8165 dpll
= DPLL_VGA_MODE_DIS
;
8167 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
))
8168 dpll
|= DPLLB_MODE_LVDS
;
8170 dpll
|= DPLLB_MODE_DAC_SERIAL
;
8172 if (IS_I945G(dev_priv
) || IS_I945GM(dev_priv
) || IS_G33(dev_priv
)) {
8173 dpll
|= (crtc_state
->pixel_multiplier
- 1)
8174 << SDVO_MULTIPLIER_SHIFT_HIRES
;
8177 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
8178 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
8179 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8181 if (intel_crtc_has_dp_encoder(crtc_state
))
8182 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8184 /* compute bitmask from p1 value */
8185 if (IS_PINEVIEW(dev
))
8186 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
8188 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8189 if (IS_G4X(dev_priv
) && reduced_clock
)
8190 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
8192 switch (clock
->p2
) {
8194 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
8197 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
8200 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
8203 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
8206 if (INTEL_INFO(dev
)->gen
>= 4)
8207 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
8209 if (crtc_state
->sdvo_tv_clock
)
8210 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
8211 else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
8212 intel_panel_use_ssc(dev_priv
))
8213 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
8215 dpll
|= PLL_REF_INPUT_DREFCLK
;
8217 dpll
|= DPLL_VCO_ENABLE
;
8218 crtc_state
->dpll_hw_state
.dpll
= dpll
;
8220 if (INTEL_INFO(dev
)->gen
>= 4) {
8221 u32 dpll_md
= (crtc_state
->pixel_multiplier
- 1)
8222 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
8223 crtc_state
->dpll_hw_state
.dpll_md
= dpll_md
;
8227 static void i8xx_compute_dpll(struct intel_crtc
*crtc
,
8228 struct intel_crtc_state
*crtc_state
,
8229 struct dpll
*reduced_clock
)
8231 struct drm_device
*dev
= crtc
->base
.dev
;
8232 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8234 struct dpll
*clock
= &crtc_state
->dpll
;
8236 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
8238 dpll
= DPLL_VGA_MODE_DIS
;
8240 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8241 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8244 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
8246 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8248 dpll
|= PLL_P2_DIVIDE_BY_4
;
8251 if (!IS_I830(dev_priv
) &&
8252 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DVO
))
8253 dpll
|= DPLL_DVO_2X_MODE
;
8255 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
8256 intel_panel_use_ssc(dev_priv
))
8257 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
8259 dpll
|= PLL_REF_INPUT_DREFCLK
;
8261 dpll
|= DPLL_VCO_ENABLE
;
8262 crtc_state
->dpll_hw_state
.dpll
= dpll
;
8265 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
8267 struct drm_device
*dev
= intel_crtc
->base
.dev
;
8268 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8269 enum pipe pipe
= intel_crtc
->pipe
;
8270 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
8271 const struct drm_display_mode
*adjusted_mode
= &intel_crtc
->config
->base
.adjusted_mode
;
8272 uint32_t crtc_vtotal
, crtc_vblank_end
;
8275 /* We need to be careful not to changed the adjusted mode, for otherwise
8276 * the hw state checker will get angry at the mismatch. */
8277 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
8278 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
8280 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
8281 /* the chip adds 2 halflines automatically */
8283 crtc_vblank_end
-= 1;
8285 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
8286 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
8288 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
8289 adjusted_mode
->crtc_htotal
/ 2;
8291 vsyncshift
+= adjusted_mode
->crtc_htotal
;
8294 if (INTEL_INFO(dev
)->gen
> 3)
8295 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
8297 I915_WRITE(HTOTAL(cpu_transcoder
),
8298 (adjusted_mode
->crtc_hdisplay
- 1) |
8299 ((adjusted_mode
->crtc_htotal
- 1) << 16));
8300 I915_WRITE(HBLANK(cpu_transcoder
),
8301 (adjusted_mode
->crtc_hblank_start
- 1) |
8302 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
8303 I915_WRITE(HSYNC(cpu_transcoder
),
8304 (adjusted_mode
->crtc_hsync_start
- 1) |
8305 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
8307 I915_WRITE(VTOTAL(cpu_transcoder
),
8308 (adjusted_mode
->crtc_vdisplay
- 1) |
8309 ((crtc_vtotal
- 1) << 16));
8310 I915_WRITE(VBLANK(cpu_transcoder
),
8311 (adjusted_mode
->crtc_vblank_start
- 1) |
8312 ((crtc_vblank_end
- 1) << 16));
8313 I915_WRITE(VSYNC(cpu_transcoder
),
8314 (adjusted_mode
->crtc_vsync_start
- 1) |
8315 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
8317 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
8318 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
8319 * documented on the DDI_FUNC_CTL register description, EDP Input Select
8321 if (IS_HASWELL(dev_priv
) && cpu_transcoder
== TRANSCODER_EDP
&&
8322 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
8323 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
8327 static void intel_set_pipe_src_size(struct intel_crtc
*intel_crtc
)
8329 struct drm_device
*dev
= intel_crtc
->base
.dev
;
8330 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8331 enum pipe pipe
= intel_crtc
->pipe
;
8333 /* pipesrc controls the size that is scaled from, which should
8334 * always be the user's requested size.
8336 I915_WRITE(PIPESRC(pipe
),
8337 ((intel_crtc
->config
->pipe_src_w
- 1) << 16) |
8338 (intel_crtc
->config
->pipe_src_h
- 1));
8341 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
8342 struct intel_crtc_state
*pipe_config
)
8344 struct drm_device
*dev
= crtc
->base
.dev
;
8345 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8346 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
8349 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
8350 pipe_config
->base
.adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
8351 pipe_config
->base
.adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
8352 tmp
= I915_READ(HBLANK(cpu_transcoder
));
8353 pipe_config
->base
.adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
8354 pipe_config
->base
.adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
8355 tmp
= I915_READ(HSYNC(cpu_transcoder
));
8356 pipe_config
->base
.adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
8357 pipe_config
->base
.adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
8359 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
8360 pipe_config
->base
.adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
8361 pipe_config
->base
.adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
8362 tmp
= I915_READ(VBLANK(cpu_transcoder
));
8363 pipe_config
->base
.adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
8364 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
8365 tmp
= I915_READ(VSYNC(cpu_transcoder
));
8366 pipe_config
->base
.adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
8367 pipe_config
->base
.adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
8369 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
8370 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
8371 pipe_config
->base
.adjusted_mode
.crtc_vtotal
+= 1;
8372 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
+= 1;
8376 static void intel_get_pipe_src_size(struct intel_crtc
*crtc
,
8377 struct intel_crtc_state
*pipe_config
)
8379 struct drm_device
*dev
= crtc
->base
.dev
;
8380 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8383 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
8384 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
8385 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
8387 pipe_config
->base
.mode
.vdisplay
= pipe_config
->pipe_src_h
;
8388 pipe_config
->base
.mode
.hdisplay
= pipe_config
->pipe_src_w
;
8391 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
8392 struct intel_crtc_state
*pipe_config
)
8394 mode
->hdisplay
= pipe_config
->base
.adjusted_mode
.crtc_hdisplay
;
8395 mode
->htotal
= pipe_config
->base
.adjusted_mode
.crtc_htotal
;
8396 mode
->hsync_start
= pipe_config
->base
.adjusted_mode
.crtc_hsync_start
;
8397 mode
->hsync_end
= pipe_config
->base
.adjusted_mode
.crtc_hsync_end
;
8399 mode
->vdisplay
= pipe_config
->base
.adjusted_mode
.crtc_vdisplay
;
8400 mode
->vtotal
= pipe_config
->base
.adjusted_mode
.crtc_vtotal
;
8401 mode
->vsync_start
= pipe_config
->base
.adjusted_mode
.crtc_vsync_start
;
8402 mode
->vsync_end
= pipe_config
->base
.adjusted_mode
.crtc_vsync_end
;
8404 mode
->flags
= pipe_config
->base
.adjusted_mode
.flags
;
8405 mode
->type
= DRM_MODE_TYPE_DRIVER
;
8407 mode
->clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
8408 mode
->flags
|= pipe_config
->base
.adjusted_mode
.flags
;
8410 mode
->hsync
= drm_mode_hsync(mode
);
8411 mode
->vrefresh
= drm_mode_vrefresh(mode
);
8412 drm_mode_set_name(mode
);
8415 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
8417 struct drm_device
*dev
= intel_crtc
->base
.dev
;
8418 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8423 if ((intel_crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
8424 (intel_crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
8425 pipeconf
|= I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
;
8427 if (intel_crtc
->config
->double_wide
)
8428 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
8430 /* only g4x and later have fancy bpc/dither controls */
8431 if (IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
8432 IS_CHERRYVIEW(dev_priv
)) {
8433 /* Bspec claims that we can't use dithering for 30bpp pipes. */
8434 if (intel_crtc
->config
->dither
&& intel_crtc
->config
->pipe_bpp
!= 30)
8435 pipeconf
|= PIPECONF_DITHER_EN
|
8436 PIPECONF_DITHER_TYPE_SP
;
8438 switch (intel_crtc
->config
->pipe_bpp
) {
8440 pipeconf
|= PIPECONF_6BPC
;
8443 pipeconf
|= PIPECONF_8BPC
;
8446 pipeconf
|= PIPECONF_10BPC
;
8449 /* Case prevented by intel_choose_pipe_bpp_dither. */
8454 if (HAS_PIPE_CXSR(dev
)) {
8455 if (intel_crtc
->lowfreq_avail
) {
8456 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
8457 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
8459 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
8463 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
8464 if (INTEL_INFO(dev
)->gen
< 4 ||
8465 intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
8466 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
8468 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
8470 pipeconf
|= PIPECONF_PROGRESSIVE
;
8472 if ((IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) &&
8473 intel_crtc
->config
->limited_color_range
)
8474 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
8476 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
8477 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
8480 static int i8xx_crtc_compute_clock(struct intel_crtc
*crtc
,
8481 struct intel_crtc_state
*crtc_state
)
8483 struct drm_device
*dev
= crtc
->base
.dev
;
8484 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8485 const struct intel_limit
*limit
;
8488 memset(&crtc_state
->dpll_hw_state
, 0,
8489 sizeof(crtc_state
->dpll_hw_state
));
8491 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8492 if (intel_panel_use_ssc(dev_priv
)) {
8493 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8494 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
8497 limit
= &intel_limits_i8xx_lvds
;
8498 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DVO
)) {
8499 limit
= &intel_limits_i8xx_dvo
;
8501 limit
= &intel_limits_i8xx_dac
;
8504 if (!crtc_state
->clock_set
&&
8505 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8506 refclk
, NULL
, &crtc_state
->dpll
)) {
8507 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8511 i8xx_compute_dpll(crtc
, crtc_state
, NULL
);
8516 static int g4x_crtc_compute_clock(struct intel_crtc
*crtc
,
8517 struct intel_crtc_state
*crtc_state
)
8519 struct drm_device
*dev
= crtc
->base
.dev
;
8520 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8521 const struct intel_limit
*limit
;
8524 memset(&crtc_state
->dpll_hw_state
, 0,
8525 sizeof(crtc_state
->dpll_hw_state
));
8527 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8528 if (intel_panel_use_ssc(dev_priv
)) {
8529 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8530 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
8533 if (intel_is_dual_link_lvds(dev
))
8534 limit
= &intel_limits_g4x_dual_channel_lvds
;
8536 limit
= &intel_limits_g4x_single_channel_lvds
;
8537 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
) ||
8538 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
)) {
8539 limit
= &intel_limits_g4x_hdmi
;
8540 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
)) {
8541 limit
= &intel_limits_g4x_sdvo
;
8543 /* The option is for other outputs */
8544 limit
= &intel_limits_i9xx_sdvo
;
8547 if (!crtc_state
->clock_set
&&
8548 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8549 refclk
, NULL
, &crtc_state
->dpll
)) {
8550 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8554 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
8559 static int pnv_crtc_compute_clock(struct intel_crtc
*crtc
,
8560 struct intel_crtc_state
*crtc_state
)
8562 struct drm_device
*dev
= crtc
->base
.dev
;
8563 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8564 const struct intel_limit
*limit
;
8567 memset(&crtc_state
->dpll_hw_state
, 0,
8568 sizeof(crtc_state
->dpll_hw_state
));
8570 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8571 if (intel_panel_use_ssc(dev_priv
)) {
8572 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8573 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
8576 limit
= &intel_limits_pineview_lvds
;
8578 limit
= &intel_limits_pineview_sdvo
;
8581 if (!crtc_state
->clock_set
&&
8582 !pnv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8583 refclk
, NULL
, &crtc_state
->dpll
)) {
8584 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8588 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
8593 static int i9xx_crtc_compute_clock(struct intel_crtc
*crtc
,
8594 struct intel_crtc_state
*crtc_state
)
8596 struct drm_device
*dev
= crtc
->base
.dev
;
8597 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8598 const struct intel_limit
*limit
;
8601 memset(&crtc_state
->dpll_hw_state
, 0,
8602 sizeof(crtc_state
->dpll_hw_state
));
8604 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8605 if (intel_panel_use_ssc(dev_priv
)) {
8606 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8607 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
8610 limit
= &intel_limits_i9xx_lvds
;
8612 limit
= &intel_limits_i9xx_sdvo
;
8615 if (!crtc_state
->clock_set
&&
8616 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8617 refclk
, NULL
, &crtc_state
->dpll
)) {
8618 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8622 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
8627 static int chv_crtc_compute_clock(struct intel_crtc
*crtc
,
8628 struct intel_crtc_state
*crtc_state
)
8630 int refclk
= 100000;
8631 const struct intel_limit
*limit
= &intel_limits_chv
;
8633 memset(&crtc_state
->dpll_hw_state
, 0,
8634 sizeof(crtc_state
->dpll_hw_state
));
8636 if (!crtc_state
->clock_set
&&
8637 !chv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8638 refclk
, NULL
, &crtc_state
->dpll
)) {
8639 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8643 chv_compute_dpll(crtc
, crtc_state
);
8648 static int vlv_crtc_compute_clock(struct intel_crtc
*crtc
,
8649 struct intel_crtc_state
*crtc_state
)
8651 int refclk
= 100000;
8652 const struct intel_limit
*limit
= &intel_limits_vlv
;
8654 memset(&crtc_state
->dpll_hw_state
, 0,
8655 sizeof(crtc_state
->dpll_hw_state
));
8657 if (!crtc_state
->clock_set
&&
8658 !vlv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8659 refclk
, NULL
, &crtc_state
->dpll
)) {
8660 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8664 vlv_compute_dpll(crtc
, crtc_state
);
8669 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
8670 struct intel_crtc_state
*pipe_config
)
8672 struct drm_device
*dev
= crtc
->base
.dev
;
8673 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8676 if (INTEL_GEN(dev_priv
) <= 3 &&
8677 (IS_I830(dev_priv
) || !IS_MOBILE(dev_priv
)))
8680 tmp
= I915_READ(PFIT_CONTROL
);
8681 if (!(tmp
& PFIT_ENABLE
))
8684 /* Check whether the pfit is attached to our pipe. */
8685 if (INTEL_INFO(dev
)->gen
< 4) {
8686 if (crtc
->pipe
!= PIPE_B
)
8689 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
8693 pipe_config
->gmch_pfit
.control
= tmp
;
8694 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
8697 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
8698 struct intel_crtc_state
*pipe_config
)
8700 struct drm_device
*dev
= crtc
->base
.dev
;
8701 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8702 int pipe
= pipe_config
->cpu_transcoder
;
8705 int refclk
= 100000;
8707 /* In case of DSI, DPLL will not be used */
8708 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
8711 mutex_lock(&dev_priv
->sb_lock
);
8712 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
8713 mutex_unlock(&dev_priv
->sb_lock
);
8715 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
8716 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
8717 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
8718 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
8719 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
8721 pipe_config
->port_clock
= vlv_calc_dpll_params(refclk
, &clock
);
8725 i9xx_get_initial_plane_config(struct intel_crtc
*crtc
,
8726 struct intel_initial_plane_config
*plane_config
)
8728 struct drm_device
*dev
= crtc
->base
.dev
;
8729 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8730 u32 val
, base
, offset
;
8731 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
8732 int fourcc
, pixel_format
;
8733 unsigned int aligned_height
;
8734 struct drm_framebuffer
*fb
;
8735 struct intel_framebuffer
*intel_fb
;
8737 val
= I915_READ(DSPCNTR(plane
));
8738 if (!(val
& DISPLAY_PLANE_ENABLE
))
8741 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8743 DRM_DEBUG_KMS("failed to alloc fb\n");
8747 fb
= &intel_fb
->base
;
8749 if (INTEL_INFO(dev
)->gen
>= 4) {
8750 if (val
& DISPPLANE_TILED
) {
8751 plane_config
->tiling
= I915_TILING_X
;
8752 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
8756 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
8757 fourcc
= i9xx_format_to_fourcc(pixel_format
);
8758 fb
->pixel_format
= fourcc
;
8759 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
8761 if (INTEL_INFO(dev
)->gen
>= 4) {
8762 if (plane_config
->tiling
)
8763 offset
= I915_READ(DSPTILEOFF(plane
));
8765 offset
= I915_READ(DSPLINOFF(plane
));
8766 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
8768 base
= I915_READ(DSPADDR(plane
));
8770 plane_config
->base
= base
;
8772 val
= I915_READ(PIPESRC(pipe
));
8773 fb
->width
= ((val
>> 16) & 0xfff) + 1;
8774 fb
->height
= ((val
>> 0) & 0xfff) + 1;
8776 val
= I915_READ(DSPSTRIDE(pipe
));
8777 fb
->pitches
[0] = val
& 0xffffffc0;
8779 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
8783 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8785 DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8786 pipe_name(pipe
), plane
, fb
->width
, fb
->height
,
8787 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
8788 plane_config
->size
);
8790 plane_config
->fb
= intel_fb
;
8793 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
8794 struct intel_crtc_state
*pipe_config
)
8796 struct drm_device
*dev
= crtc
->base
.dev
;
8797 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8798 int pipe
= pipe_config
->cpu_transcoder
;
8799 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
8801 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
, pll_dw3
;
8802 int refclk
= 100000;
8804 /* In case of DSI, DPLL will not be used */
8805 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
8808 mutex_lock(&dev_priv
->sb_lock
);
8809 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
8810 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
8811 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
8812 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
8813 pll_dw3
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
8814 mutex_unlock(&dev_priv
->sb_lock
);
8816 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
8817 clock
.m2
= (pll_dw0
& 0xff) << 22;
8818 if (pll_dw3
& DPIO_CHV_FRAC_DIV_EN
)
8819 clock
.m2
|= pll_dw2
& 0x3fffff;
8820 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
8821 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
8822 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
8824 pipe_config
->port_clock
= chv_calc_dpll_params(refclk
, &clock
);
8827 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
8828 struct intel_crtc_state
*pipe_config
)
8830 struct drm_device
*dev
= crtc
->base
.dev
;
8831 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8832 enum intel_display_power_domain power_domain
;
8836 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
8837 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8840 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8841 pipe_config
->shared_dpll
= NULL
;
8845 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
8846 if (!(tmp
& PIPECONF_ENABLE
))
8849 if (IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
8850 IS_CHERRYVIEW(dev_priv
)) {
8851 switch (tmp
& PIPECONF_BPC_MASK
) {
8853 pipe_config
->pipe_bpp
= 18;
8856 pipe_config
->pipe_bpp
= 24;
8858 case PIPECONF_10BPC
:
8859 pipe_config
->pipe_bpp
= 30;
8866 if ((IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) &&
8867 (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
8868 pipe_config
->limited_color_range
= true;
8870 if (INTEL_INFO(dev
)->gen
< 4)
8871 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
8873 intel_get_pipe_timings(crtc
, pipe_config
);
8874 intel_get_pipe_src_size(crtc
, pipe_config
);
8876 i9xx_get_pfit_config(crtc
, pipe_config
);
8878 if (INTEL_INFO(dev
)->gen
>= 4) {
8879 /* No way to read it out on pipes B and C */
8880 if (IS_CHERRYVIEW(dev_priv
) && crtc
->pipe
!= PIPE_A
)
8881 tmp
= dev_priv
->chv_dpll_md
[crtc
->pipe
];
8883 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
8884 pipe_config
->pixel_multiplier
=
8885 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
8886 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
8887 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
8888 } else if (IS_I945G(dev_priv
) || IS_I945GM(dev_priv
) ||
8890 tmp
= I915_READ(DPLL(crtc
->pipe
));
8891 pipe_config
->pixel_multiplier
=
8892 ((tmp
& SDVO_MULTIPLIER_MASK
)
8893 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
8895 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8896 * port and will be fixed up in the encoder->get_config
8898 pipe_config
->pixel_multiplier
= 1;
8900 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
8901 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
)) {
8903 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
8904 * on 830. Filter it out here so that we don't
8905 * report errors due to that.
8907 if (IS_I830(dev_priv
))
8908 pipe_config
->dpll_hw_state
.dpll
&= ~DPLL_DVO_2X_MODE
;
8910 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
8911 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
8913 /* Mask out read-only status bits. */
8914 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
8915 DPLL_PORTC_READY_MASK
|
8916 DPLL_PORTB_READY_MASK
);
8919 if (IS_CHERRYVIEW(dev_priv
))
8920 chv_crtc_clock_get(crtc
, pipe_config
);
8921 else if (IS_VALLEYVIEW(dev_priv
))
8922 vlv_crtc_clock_get(crtc
, pipe_config
);
8924 i9xx_crtc_clock_get(crtc
, pipe_config
);
8927 * Normally the dotclock is filled in by the encoder .get_config()
8928 * but in case the pipe is enabled w/o any ports we need a sane
8931 pipe_config
->base
.adjusted_mode
.crtc_clock
=
8932 pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
8937 intel_display_power_put(dev_priv
, power_domain
);
8942 static void ironlake_init_pch_refclk(struct drm_device
*dev
)
8944 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8945 struct intel_encoder
*encoder
;
8948 bool has_lvds
= false;
8949 bool has_cpu_edp
= false;
8950 bool has_panel
= false;
8951 bool has_ck505
= false;
8952 bool can_ssc
= false;
8953 bool using_ssc_source
= false;
8955 /* We need to take the global config into account */
8956 for_each_intel_encoder(dev
, encoder
) {
8957 switch (encoder
->type
) {
8958 case INTEL_OUTPUT_LVDS
:
8962 case INTEL_OUTPUT_EDP
:
8964 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
8972 if (HAS_PCH_IBX(dev_priv
)) {
8973 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
8974 can_ssc
= has_ck505
;
8980 /* Check if any DPLLs are using the SSC source */
8981 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
8982 u32 temp
= I915_READ(PCH_DPLL(i
));
8984 if (!(temp
& DPLL_VCO_ENABLE
))
8987 if ((temp
& PLL_REF_INPUT_MASK
) ==
8988 PLLB_REF_INPUT_SPREADSPECTRUMIN
) {
8989 using_ssc_source
= true;
8994 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
8995 has_panel
, has_lvds
, has_ck505
, using_ssc_source
);
8997 /* Ironlake: try to setup display ref clock before DPLL
8998 * enabling. This is only under driver's control after
8999 * PCH B stepping, previous chipset stepping should be
9000 * ignoring this setting.
9002 val
= I915_READ(PCH_DREF_CONTROL
);
9004 /* As we must carefully and slowly disable/enable each source in turn,
9005 * compute the final state we want first and check if we need to
9006 * make any changes at all.
9009 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
9011 final
|= DREF_NONSPREAD_CK505_ENABLE
;
9013 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
9015 final
&= ~DREF_SSC_SOURCE_MASK
;
9016 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
9017 final
&= ~DREF_SSC1_ENABLE
;
9020 final
|= DREF_SSC_SOURCE_ENABLE
;
9022 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
9023 final
|= DREF_SSC1_ENABLE
;
9026 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
9027 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
9029 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
9031 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
9032 } else if (using_ssc_source
) {
9033 final
|= DREF_SSC_SOURCE_ENABLE
;
9034 final
|= DREF_SSC1_ENABLE
;
9040 /* Always enable nonspread source */
9041 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
9044 val
|= DREF_NONSPREAD_CK505_ENABLE
;
9046 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
9049 val
&= ~DREF_SSC_SOURCE_MASK
;
9050 val
|= DREF_SSC_SOURCE_ENABLE
;
9052 /* SSC must be turned on before enabling the CPU output */
9053 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
9054 DRM_DEBUG_KMS("Using SSC on panel\n");
9055 val
|= DREF_SSC1_ENABLE
;
9057 val
&= ~DREF_SSC1_ENABLE
;
9059 /* Get SSC going before enabling the outputs */
9060 I915_WRITE(PCH_DREF_CONTROL
, val
);
9061 POSTING_READ(PCH_DREF_CONTROL
);
9064 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
9066 /* Enable CPU source on CPU attached eDP */
9068 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
9069 DRM_DEBUG_KMS("Using SSC on eDP\n");
9070 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
9072 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
9074 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
9076 I915_WRITE(PCH_DREF_CONTROL
, val
);
9077 POSTING_READ(PCH_DREF_CONTROL
);
9080 DRM_DEBUG_KMS("Disabling CPU source output\n");
9082 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
9084 /* Turn off CPU output */
9085 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
9087 I915_WRITE(PCH_DREF_CONTROL
, val
);
9088 POSTING_READ(PCH_DREF_CONTROL
);
9091 if (!using_ssc_source
) {
9092 DRM_DEBUG_KMS("Disabling SSC source\n");
9094 /* Turn off the SSC source */
9095 val
&= ~DREF_SSC_SOURCE_MASK
;
9096 val
|= DREF_SSC_SOURCE_DISABLE
;
9099 val
&= ~DREF_SSC1_ENABLE
;
9101 I915_WRITE(PCH_DREF_CONTROL
, val
);
9102 POSTING_READ(PCH_DREF_CONTROL
);
9107 BUG_ON(val
!= final
);
9110 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
9114 tmp
= I915_READ(SOUTH_CHICKEN2
);
9115 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
9116 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
9118 if (wait_for_us(I915_READ(SOUTH_CHICKEN2
) &
9119 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
9120 DRM_ERROR("FDI mPHY reset assert timeout\n");
9122 tmp
= I915_READ(SOUTH_CHICKEN2
);
9123 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
9124 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
9126 if (wait_for_us((I915_READ(SOUTH_CHICKEN2
) &
9127 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
9128 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
9131 /* WaMPhyProgramming:hsw */
9132 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
9136 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
9137 tmp
&= ~(0xFF << 24);
9138 tmp
|= (0x12 << 24);
9139 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
9141 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
9143 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
9145 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
9147 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
9149 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
9150 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
9151 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
9153 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
9154 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
9155 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
9157 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
9160 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
9162 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
9165 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
9167 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
9170 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
9172 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
9175 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
9177 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
9178 tmp
&= ~(0xFF << 16);
9179 tmp
|= (0x1C << 16);
9180 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
9182 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
9183 tmp
&= ~(0xFF << 16);
9184 tmp
|= (0x1C << 16);
9185 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
9187 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
9189 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
9191 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
9193 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
9195 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
9196 tmp
&= ~(0xF << 28);
9198 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
9200 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
9201 tmp
&= ~(0xF << 28);
9203 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
9206 /* Implements 3 different sequences from BSpec chapter "Display iCLK
9207 * Programming" based on the parameters passed:
9208 * - Sequence to enable CLKOUT_DP
9209 * - Sequence to enable CLKOUT_DP without spread
9210 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
9212 static void lpt_enable_clkout_dp(struct drm_device
*dev
, bool with_spread
,
9215 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9218 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
9220 if (WARN(HAS_PCH_LPT_LP(dev_priv
) &&
9221 with_fdi
, "LP PCH doesn't have FDI\n"))
9224 mutex_lock(&dev_priv
->sb_lock
);
9226 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
9227 tmp
&= ~SBI_SSCCTL_DISABLE
;
9228 tmp
|= SBI_SSCCTL_PATHALT
;
9229 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
9234 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
9235 tmp
&= ~SBI_SSCCTL_PATHALT
;
9236 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
9239 lpt_reset_fdi_mphy(dev_priv
);
9240 lpt_program_fdi_mphy(dev_priv
);
9244 reg
= HAS_PCH_LPT_LP(dev_priv
) ? SBI_GEN0
: SBI_DBUFF0
;
9245 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
9246 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
9247 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
9249 mutex_unlock(&dev_priv
->sb_lock
);
9252 /* Sequence to disable CLKOUT_DP */
9253 static void lpt_disable_clkout_dp(struct drm_device
*dev
)
9255 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9258 mutex_lock(&dev_priv
->sb_lock
);
9260 reg
= HAS_PCH_LPT_LP(dev_priv
) ? SBI_GEN0
: SBI_DBUFF0
;
9261 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
9262 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
9263 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
9265 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
9266 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
9267 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
9268 tmp
|= SBI_SSCCTL_PATHALT
;
9269 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
9272 tmp
|= SBI_SSCCTL_DISABLE
;
9273 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
9276 mutex_unlock(&dev_priv
->sb_lock
);
9279 #define BEND_IDX(steps) ((50 + (steps)) / 5)
9281 static const uint16_t sscdivintphase
[] = {
9282 [BEND_IDX( 50)] = 0x3B23,
9283 [BEND_IDX( 45)] = 0x3B23,
9284 [BEND_IDX( 40)] = 0x3C23,
9285 [BEND_IDX( 35)] = 0x3C23,
9286 [BEND_IDX( 30)] = 0x3D23,
9287 [BEND_IDX( 25)] = 0x3D23,
9288 [BEND_IDX( 20)] = 0x3E23,
9289 [BEND_IDX( 15)] = 0x3E23,
9290 [BEND_IDX( 10)] = 0x3F23,
9291 [BEND_IDX( 5)] = 0x3F23,
9292 [BEND_IDX( 0)] = 0x0025,
9293 [BEND_IDX( -5)] = 0x0025,
9294 [BEND_IDX(-10)] = 0x0125,
9295 [BEND_IDX(-15)] = 0x0125,
9296 [BEND_IDX(-20)] = 0x0225,
9297 [BEND_IDX(-25)] = 0x0225,
9298 [BEND_IDX(-30)] = 0x0325,
9299 [BEND_IDX(-35)] = 0x0325,
9300 [BEND_IDX(-40)] = 0x0425,
9301 [BEND_IDX(-45)] = 0x0425,
9302 [BEND_IDX(-50)] = 0x0525,
9307 * steps -50 to 50 inclusive, in steps of 5
9308 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
9309 * change in clock period = -(steps / 10) * 5.787 ps
9311 static void lpt_bend_clkout_dp(struct drm_i915_private
*dev_priv
, int steps
)
9314 int idx
= BEND_IDX(steps
);
9316 if (WARN_ON(steps
% 5 != 0))
9319 if (WARN_ON(idx
>= ARRAY_SIZE(sscdivintphase
)))
9322 mutex_lock(&dev_priv
->sb_lock
);
9324 if (steps
% 10 != 0)
9328 intel_sbi_write(dev_priv
, SBI_SSCDITHPHASE
, tmp
, SBI_ICLK
);
9330 tmp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE
, SBI_ICLK
);
9332 tmp
|= sscdivintphase
[idx
];
9333 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE
, tmp
, SBI_ICLK
);
9335 mutex_unlock(&dev_priv
->sb_lock
);
9340 static void lpt_init_pch_refclk(struct drm_device
*dev
)
9342 struct intel_encoder
*encoder
;
9343 bool has_vga
= false;
9345 for_each_intel_encoder(dev
, encoder
) {
9346 switch (encoder
->type
) {
9347 case INTEL_OUTPUT_ANALOG
:
9356 lpt_bend_clkout_dp(to_i915(dev
), 0);
9357 lpt_enable_clkout_dp(dev
, true, true);
9359 lpt_disable_clkout_dp(dev
);
9364 * Initialize reference clocks when the driver loads
9366 void intel_init_pch_refclk(struct drm_device
*dev
)
9368 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9370 if (HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
))
9371 ironlake_init_pch_refclk(dev
);
9372 else if (HAS_PCH_LPT(dev_priv
))
9373 lpt_init_pch_refclk(dev
);
9376 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
9378 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
9379 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9380 int pipe
= intel_crtc
->pipe
;
9385 switch (intel_crtc
->config
->pipe_bpp
) {
9387 val
|= PIPECONF_6BPC
;
9390 val
|= PIPECONF_8BPC
;
9393 val
|= PIPECONF_10BPC
;
9396 val
|= PIPECONF_12BPC
;
9399 /* Case prevented by intel_choose_pipe_bpp_dither. */
9403 if (intel_crtc
->config
->dither
)
9404 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
9406 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
9407 val
|= PIPECONF_INTERLACED_ILK
;
9409 val
|= PIPECONF_PROGRESSIVE
;
9411 if (intel_crtc
->config
->limited_color_range
)
9412 val
|= PIPECONF_COLOR_RANGE_SELECT
;
9414 I915_WRITE(PIPECONF(pipe
), val
);
9415 POSTING_READ(PIPECONF(pipe
));
9418 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
9420 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
9421 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9422 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
9425 if (IS_HASWELL(dev_priv
) && intel_crtc
->config
->dither
)
9426 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
9428 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
9429 val
|= PIPECONF_INTERLACED_ILK
;
9431 val
|= PIPECONF_PROGRESSIVE
;
9433 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
9434 POSTING_READ(PIPECONF(cpu_transcoder
));
9437 static void haswell_set_pipemisc(struct drm_crtc
*crtc
)
9439 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
9440 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9442 if (IS_BROADWELL(dev_priv
) || INTEL_INFO(dev_priv
)->gen
>= 9) {
9445 switch (intel_crtc
->config
->pipe_bpp
) {
9447 val
|= PIPEMISC_DITHER_6_BPC
;
9450 val
|= PIPEMISC_DITHER_8_BPC
;
9453 val
|= PIPEMISC_DITHER_10_BPC
;
9456 val
|= PIPEMISC_DITHER_12_BPC
;
9459 /* Case prevented by pipe_config_set_bpp. */
9463 if (intel_crtc
->config
->dither
)
9464 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
9466 I915_WRITE(PIPEMISC(intel_crtc
->pipe
), val
);
9470 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
9473 * Account for spread spectrum to avoid
9474 * oversubscribing the link. Max center spread
9475 * is 2.5%; use 5% for safety's sake.
9477 u32 bps
= target_clock
* bpp
* 21 / 20;
9478 return DIV_ROUND_UP(bps
, link_bw
* 8);
9481 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
9483 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
9486 static void ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
9487 struct intel_crtc_state
*crtc_state
,
9488 struct dpll
*reduced_clock
)
9490 struct drm_crtc
*crtc
= &intel_crtc
->base
;
9491 struct drm_device
*dev
= crtc
->dev
;
9492 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9496 /* Enable autotuning of the PLL clock (if permissible) */
9498 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
9499 if ((intel_panel_use_ssc(dev_priv
) &&
9500 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
9501 (HAS_PCH_IBX(dev_priv
) && intel_is_dual_link_lvds(dev
)))
9503 } else if (crtc_state
->sdvo_tv_clock
)
9506 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
9508 if (ironlake_needs_fb_cb_tune(&crtc_state
->dpll
, factor
))
9511 if (reduced_clock
) {
9512 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
9514 if (reduced_clock
->m
< factor
* reduced_clock
->n
)
9522 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
))
9523 dpll
|= DPLLB_MODE_LVDS
;
9525 dpll
|= DPLLB_MODE_DAC_SERIAL
;
9527 dpll
|= (crtc_state
->pixel_multiplier
- 1)
9528 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
9530 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
9531 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
9532 dpll
|= DPLL_SDVO_HIGH_SPEED
;
9534 if (intel_crtc_has_dp_encoder(crtc_state
))
9535 dpll
|= DPLL_SDVO_HIGH_SPEED
;
9538 * The high speed IO clock is only really required for
9539 * SDVO/HDMI/DP, but we also enable it for CRT to make it
9540 * possible to share the DPLL between CRT and HDMI. Enabling
9541 * the clock needlessly does no real harm, except use up a
9542 * bit of power potentially.
9544 * We'll limit this to IVB with 3 pipes, since it has only two
9545 * DPLLs and so DPLL sharing is the only way to get three pipes
9546 * driving PCH ports at the same time. On SNB we could do this,
9547 * and potentially avoid enabling the second DPLL, but it's not
9548 * clear if it''s a win or loss power wise. No point in doing
9549 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
9551 if (INTEL_INFO(dev_priv
)->num_pipes
== 3 &&
9552 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
))
9553 dpll
|= DPLL_SDVO_HIGH_SPEED
;
9555 /* compute bitmask from p1 value */
9556 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
9558 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
9560 switch (crtc_state
->dpll
.p2
) {
9562 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
9565 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
9568 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
9571 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
9575 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
9576 intel_panel_use_ssc(dev_priv
))
9577 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
9579 dpll
|= PLL_REF_INPUT_DREFCLK
;
9581 dpll
|= DPLL_VCO_ENABLE
;
9583 crtc_state
->dpll_hw_state
.dpll
= dpll
;
9584 crtc_state
->dpll_hw_state
.fp0
= fp
;
9585 crtc_state
->dpll_hw_state
.fp1
= fp2
;
9588 static int ironlake_crtc_compute_clock(struct intel_crtc
*crtc
,
9589 struct intel_crtc_state
*crtc_state
)
9591 struct drm_device
*dev
= crtc
->base
.dev
;
9592 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9593 struct dpll reduced_clock
;
9594 bool has_reduced_clock
= false;
9595 struct intel_shared_dpll
*pll
;
9596 const struct intel_limit
*limit
;
9597 int refclk
= 120000;
9599 memset(&crtc_state
->dpll_hw_state
, 0,
9600 sizeof(crtc_state
->dpll_hw_state
));
9602 crtc
->lowfreq_avail
= false;
9604 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
9605 if (!crtc_state
->has_pch_encoder
)
9608 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
9609 if (intel_panel_use_ssc(dev_priv
)) {
9610 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
9611 dev_priv
->vbt
.lvds_ssc_freq
);
9612 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
9615 if (intel_is_dual_link_lvds(dev
)) {
9616 if (refclk
== 100000)
9617 limit
= &intel_limits_ironlake_dual_lvds_100m
;
9619 limit
= &intel_limits_ironlake_dual_lvds
;
9621 if (refclk
== 100000)
9622 limit
= &intel_limits_ironlake_single_lvds_100m
;
9624 limit
= &intel_limits_ironlake_single_lvds
;
9627 limit
= &intel_limits_ironlake_dac
;
9630 if (!crtc_state
->clock_set
&&
9631 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
9632 refclk
, NULL
, &crtc_state
->dpll
)) {
9633 DRM_ERROR("Couldn't find PLL settings for mode!\n");
9637 ironlake_compute_dpll(crtc
, crtc_state
,
9638 has_reduced_clock
? &reduced_clock
: NULL
);
9640 pll
= intel_get_shared_dpll(crtc
, crtc_state
, NULL
);
9642 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
9643 pipe_name(crtc
->pipe
));
9647 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
9649 crtc
->lowfreq_avail
= true;
9654 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
9655 struct intel_link_m_n
*m_n
)
9657 struct drm_device
*dev
= crtc
->base
.dev
;
9658 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9659 enum pipe pipe
= crtc
->pipe
;
9661 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
9662 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
9663 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
9665 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
9666 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
9667 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
9670 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
9671 enum transcoder transcoder
,
9672 struct intel_link_m_n
*m_n
,
9673 struct intel_link_m_n
*m2_n2
)
9675 struct drm_device
*dev
= crtc
->base
.dev
;
9676 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9677 enum pipe pipe
= crtc
->pipe
;
9679 if (INTEL_INFO(dev
)->gen
>= 5) {
9680 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
9681 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
9682 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
9684 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
9685 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
9686 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
9687 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
9688 * gen < 8) and if DRRS is supported (to make sure the
9689 * registers are not unnecessarily read).
9691 if (m2_n2
&& INTEL_INFO(dev
)->gen
< 8 &&
9692 crtc
->config
->has_drrs
) {
9693 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
9694 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
9695 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
9697 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
9698 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
9699 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
9702 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
9703 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
9704 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
9706 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
9707 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
9708 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
9712 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
9713 struct intel_crtc_state
*pipe_config
)
9715 if (pipe_config
->has_pch_encoder
)
9716 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
9718 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
9719 &pipe_config
->dp_m_n
,
9720 &pipe_config
->dp_m2_n2
);
9723 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
9724 struct intel_crtc_state
*pipe_config
)
9726 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
9727 &pipe_config
->fdi_m_n
, NULL
);
9730 static void skylake_get_pfit_config(struct intel_crtc
*crtc
,
9731 struct intel_crtc_state
*pipe_config
)
9733 struct drm_device
*dev
= crtc
->base
.dev
;
9734 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9735 struct intel_crtc_scaler_state
*scaler_state
= &pipe_config
->scaler_state
;
9736 uint32_t ps_ctrl
= 0;
9740 /* find scaler attached to this pipe */
9741 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
9742 ps_ctrl
= I915_READ(SKL_PS_CTRL(crtc
->pipe
, i
));
9743 if (ps_ctrl
& PS_SCALER_EN
&& !(ps_ctrl
& PS_PLANE_SEL_MASK
)) {
9745 pipe_config
->pch_pfit
.enabled
= true;
9746 pipe_config
->pch_pfit
.pos
= I915_READ(SKL_PS_WIN_POS(crtc
->pipe
, i
));
9747 pipe_config
->pch_pfit
.size
= I915_READ(SKL_PS_WIN_SZ(crtc
->pipe
, i
));
9752 scaler_state
->scaler_id
= id
;
9754 scaler_state
->scaler_users
|= (1 << SKL_CRTC_INDEX
);
9756 scaler_state
->scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
9761 skylake_get_initial_plane_config(struct intel_crtc
*crtc
,
9762 struct intel_initial_plane_config
*plane_config
)
9764 struct drm_device
*dev
= crtc
->base
.dev
;
9765 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9766 u32 val
, base
, offset
, stride_mult
, tiling
;
9767 int pipe
= crtc
->pipe
;
9768 int fourcc
, pixel_format
;
9769 unsigned int aligned_height
;
9770 struct drm_framebuffer
*fb
;
9771 struct intel_framebuffer
*intel_fb
;
9773 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9775 DRM_DEBUG_KMS("failed to alloc fb\n");
9779 fb
= &intel_fb
->base
;
9781 val
= I915_READ(PLANE_CTL(pipe
, 0));
9782 if (!(val
& PLANE_CTL_ENABLE
))
9785 pixel_format
= val
& PLANE_CTL_FORMAT_MASK
;
9786 fourcc
= skl_format_to_fourcc(pixel_format
,
9787 val
& PLANE_CTL_ORDER_RGBX
,
9788 val
& PLANE_CTL_ALPHA_MASK
);
9789 fb
->pixel_format
= fourcc
;
9790 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
9792 tiling
= val
& PLANE_CTL_TILED_MASK
;
9794 case PLANE_CTL_TILED_LINEAR
:
9795 fb
->modifier
[0] = DRM_FORMAT_MOD_NONE
;
9797 case PLANE_CTL_TILED_X
:
9798 plane_config
->tiling
= I915_TILING_X
;
9799 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
9801 case PLANE_CTL_TILED_Y
:
9802 fb
->modifier
[0] = I915_FORMAT_MOD_Y_TILED
;
9804 case PLANE_CTL_TILED_YF
:
9805 fb
->modifier
[0] = I915_FORMAT_MOD_Yf_TILED
;
9808 MISSING_CASE(tiling
);
9812 base
= I915_READ(PLANE_SURF(pipe
, 0)) & 0xfffff000;
9813 plane_config
->base
= base
;
9815 offset
= I915_READ(PLANE_OFFSET(pipe
, 0));
9817 val
= I915_READ(PLANE_SIZE(pipe
, 0));
9818 fb
->height
= ((val
>> 16) & 0xfff) + 1;
9819 fb
->width
= ((val
>> 0) & 0x1fff) + 1;
9821 val
= I915_READ(PLANE_STRIDE(pipe
, 0));
9822 stride_mult
= intel_fb_stride_alignment(dev_priv
, fb
->modifier
[0],
9824 fb
->pitches
[0] = (val
& 0x3ff) * stride_mult
;
9826 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
9830 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
9832 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9833 pipe_name(pipe
), fb
->width
, fb
->height
,
9834 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
9835 plane_config
->size
);
9837 plane_config
->fb
= intel_fb
;
9844 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
9845 struct intel_crtc_state
*pipe_config
)
9847 struct drm_device
*dev
= crtc
->base
.dev
;
9848 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9851 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
9853 if (tmp
& PF_ENABLE
) {
9854 pipe_config
->pch_pfit
.enabled
= true;
9855 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
9856 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
9858 /* We currently do not free assignements of panel fitters on
9859 * ivb/hsw (since we don't use the higher upscaling modes which
9860 * differentiates them) so just WARN about this case for now. */
9861 if (IS_GEN7(dev_priv
)) {
9862 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
9863 PF_PIPE_SEL_IVB(crtc
->pipe
));
9869 ironlake_get_initial_plane_config(struct intel_crtc
*crtc
,
9870 struct intel_initial_plane_config
*plane_config
)
9872 struct drm_device
*dev
= crtc
->base
.dev
;
9873 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9874 u32 val
, base
, offset
;
9875 int pipe
= crtc
->pipe
;
9876 int fourcc
, pixel_format
;
9877 unsigned int aligned_height
;
9878 struct drm_framebuffer
*fb
;
9879 struct intel_framebuffer
*intel_fb
;
9881 val
= I915_READ(DSPCNTR(pipe
));
9882 if (!(val
& DISPLAY_PLANE_ENABLE
))
9885 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9887 DRM_DEBUG_KMS("failed to alloc fb\n");
9891 fb
= &intel_fb
->base
;
9893 if (INTEL_INFO(dev
)->gen
>= 4) {
9894 if (val
& DISPPLANE_TILED
) {
9895 plane_config
->tiling
= I915_TILING_X
;
9896 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
9900 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
9901 fourcc
= i9xx_format_to_fourcc(pixel_format
);
9902 fb
->pixel_format
= fourcc
;
9903 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
9905 base
= I915_READ(DSPSURF(pipe
)) & 0xfffff000;
9906 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
9907 offset
= I915_READ(DSPOFFSET(pipe
));
9909 if (plane_config
->tiling
)
9910 offset
= I915_READ(DSPTILEOFF(pipe
));
9912 offset
= I915_READ(DSPLINOFF(pipe
));
9914 plane_config
->base
= base
;
9916 val
= I915_READ(PIPESRC(pipe
));
9917 fb
->width
= ((val
>> 16) & 0xfff) + 1;
9918 fb
->height
= ((val
>> 0) & 0xfff) + 1;
9920 val
= I915_READ(DSPSTRIDE(pipe
));
9921 fb
->pitches
[0] = val
& 0xffffffc0;
9923 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
9927 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
9929 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9930 pipe_name(pipe
), fb
->width
, fb
->height
,
9931 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
9932 plane_config
->size
);
9934 plane_config
->fb
= intel_fb
;
9937 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
9938 struct intel_crtc_state
*pipe_config
)
9940 struct drm_device
*dev
= crtc
->base
.dev
;
9941 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9942 enum intel_display_power_domain power_domain
;
9946 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
9947 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9950 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
9951 pipe_config
->shared_dpll
= NULL
;
9954 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
9955 if (!(tmp
& PIPECONF_ENABLE
))
9958 switch (tmp
& PIPECONF_BPC_MASK
) {
9960 pipe_config
->pipe_bpp
= 18;
9963 pipe_config
->pipe_bpp
= 24;
9965 case PIPECONF_10BPC
:
9966 pipe_config
->pipe_bpp
= 30;
9968 case PIPECONF_12BPC
:
9969 pipe_config
->pipe_bpp
= 36;
9975 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
9976 pipe_config
->limited_color_range
= true;
9978 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
9979 struct intel_shared_dpll
*pll
;
9980 enum intel_dpll_id pll_id
;
9982 pipe_config
->has_pch_encoder
= true;
9984 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
9985 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
9986 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
9988 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
9990 if (HAS_PCH_IBX(dev_priv
)) {
9992 * The pipe->pch transcoder and pch transcoder->pll
9995 pll_id
= (enum intel_dpll_id
) crtc
->pipe
;
9997 tmp
= I915_READ(PCH_DPLL_SEL
);
9998 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
9999 pll_id
= DPLL_ID_PCH_PLL_B
;
10001 pll_id
= DPLL_ID_PCH_PLL_A
;
10004 pipe_config
->shared_dpll
=
10005 intel_get_shared_dpll_by_id(dev_priv
, pll_id
);
10006 pll
= pipe_config
->shared_dpll
;
10008 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
10009 &pipe_config
->dpll_hw_state
));
10011 tmp
= pipe_config
->dpll_hw_state
.dpll
;
10012 pipe_config
->pixel_multiplier
=
10013 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
10014 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
10016 ironlake_pch_clock_get(crtc
, pipe_config
);
10018 pipe_config
->pixel_multiplier
= 1;
10021 intel_get_pipe_timings(crtc
, pipe_config
);
10022 intel_get_pipe_src_size(crtc
, pipe_config
);
10024 ironlake_get_pfit_config(crtc
, pipe_config
);
10029 intel_display_power_put(dev_priv
, power_domain
);
10034 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
10036 struct drm_device
*dev
= &dev_priv
->drm
;
10037 struct intel_crtc
*crtc
;
10039 for_each_intel_crtc(dev
, crtc
)
10040 I915_STATE_WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
10041 pipe_name(crtc
->pipe
));
10043 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
10044 I915_STATE_WARN(I915_READ(SPLL_CTL
) & SPLL_PLL_ENABLE
, "SPLL enabled\n");
10045 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE
, "WRPLL1 enabled\n");
10046 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE
, "WRPLL2 enabled\n");
10047 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON
, "Panel power on\n");
10048 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
10049 "CPU PWM1 enabled\n");
10050 if (IS_HASWELL(dev_priv
))
10051 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
10052 "CPU PWM2 enabled\n");
10053 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
10054 "PCH PWM1 enabled\n");
10055 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
10056 "Utility pin enabled\n");
10057 I915_STATE_WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
10060 * In theory we can still leave IRQs enabled, as long as only the HPD
10061 * interrupts remain enabled. We used to check for that, but since it's
10062 * gen-specific and since we only disable LCPLL after we fully disable
10063 * the interrupts, the check below should be enough.
10065 I915_STATE_WARN(intel_irqs_enabled(dev_priv
), "IRQs enabled\n");
10068 static uint32_t hsw_read_dcomp(struct drm_i915_private
*dev_priv
)
10070 if (IS_HASWELL(dev_priv
))
10071 return I915_READ(D_COMP_HSW
);
10073 return I915_READ(D_COMP_BDW
);
10076 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
10078 if (IS_HASWELL(dev_priv
)) {
10079 mutex_lock(&dev_priv
->rps
.hw_lock
);
10080 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
10082 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
10083 mutex_unlock(&dev_priv
->rps
.hw_lock
);
10085 I915_WRITE(D_COMP_BDW
, val
);
10086 POSTING_READ(D_COMP_BDW
);
10091 * This function implements pieces of two sequences from BSpec:
10092 * - Sequence for display software to disable LCPLL
10093 * - Sequence for display software to allow package C8+
10094 * The steps implemented here are just the steps that actually touch the LCPLL
10095 * register. Callers should take care of disabling all the display engine
10096 * functions, doing the mode unset, fixing interrupts, etc.
10098 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
10099 bool switch_to_fclk
, bool allow_power_down
)
10103 assert_can_disable_lcpll(dev_priv
);
10105 val
= I915_READ(LCPLL_CTL
);
10107 if (switch_to_fclk
) {
10108 val
|= LCPLL_CD_SOURCE_FCLK
;
10109 I915_WRITE(LCPLL_CTL
, val
);
10111 if (wait_for_us(I915_READ(LCPLL_CTL
) &
10112 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
10113 DRM_ERROR("Switching to FCLK failed\n");
10115 val
= I915_READ(LCPLL_CTL
);
10118 val
|= LCPLL_PLL_DISABLE
;
10119 I915_WRITE(LCPLL_CTL
, val
);
10120 POSTING_READ(LCPLL_CTL
);
10122 if (intel_wait_for_register(dev_priv
, LCPLL_CTL
, LCPLL_PLL_LOCK
, 0, 1))
10123 DRM_ERROR("LCPLL still locked\n");
10125 val
= hsw_read_dcomp(dev_priv
);
10126 val
|= D_COMP_COMP_DISABLE
;
10127 hsw_write_dcomp(dev_priv
, val
);
10130 if (wait_for((hsw_read_dcomp(dev_priv
) & D_COMP_RCOMP_IN_PROGRESS
) == 0,
10132 DRM_ERROR("D_COMP RCOMP still in progress\n");
10134 if (allow_power_down
) {
10135 val
= I915_READ(LCPLL_CTL
);
10136 val
|= LCPLL_POWER_DOWN_ALLOW
;
10137 I915_WRITE(LCPLL_CTL
, val
);
10138 POSTING_READ(LCPLL_CTL
);
10143 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
10146 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
10150 val
= I915_READ(LCPLL_CTL
);
10152 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
10153 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
10157 * Make sure we're not on PC8 state before disabling PC8, otherwise
10158 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
10160 intel_uncore_forcewake_get(dev_priv
, FORCEWAKE_ALL
);
10162 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
10163 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
10164 I915_WRITE(LCPLL_CTL
, val
);
10165 POSTING_READ(LCPLL_CTL
);
10168 val
= hsw_read_dcomp(dev_priv
);
10169 val
|= D_COMP_COMP_FORCE
;
10170 val
&= ~D_COMP_COMP_DISABLE
;
10171 hsw_write_dcomp(dev_priv
, val
);
10173 val
= I915_READ(LCPLL_CTL
);
10174 val
&= ~LCPLL_PLL_DISABLE
;
10175 I915_WRITE(LCPLL_CTL
, val
);
10177 if (intel_wait_for_register(dev_priv
,
10178 LCPLL_CTL
, LCPLL_PLL_LOCK
, LCPLL_PLL_LOCK
,
10180 DRM_ERROR("LCPLL not locked yet\n");
10182 if (val
& LCPLL_CD_SOURCE_FCLK
) {
10183 val
= I915_READ(LCPLL_CTL
);
10184 val
&= ~LCPLL_CD_SOURCE_FCLK
;
10185 I915_WRITE(LCPLL_CTL
, val
);
10187 if (wait_for_us((I915_READ(LCPLL_CTL
) &
10188 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
10189 DRM_ERROR("Switching back to LCPLL failed\n");
10192 intel_uncore_forcewake_put(dev_priv
, FORCEWAKE_ALL
);
10193 intel_update_cdclk(&dev_priv
->drm
);
10197 * Package states C8 and deeper are really deep PC states that can only be
10198 * reached when all the devices on the system allow it, so even if the graphics
10199 * device allows PC8+, it doesn't mean the system will actually get to these
10200 * states. Our driver only allows PC8+ when going into runtime PM.
10202 * The requirements for PC8+ are that all the outputs are disabled, the power
10203 * well is disabled and most interrupts are disabled, and these are also
10204 * requirements for runtime PM. When these conditions are met, we manually do
10205 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
10206 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
10207 * hang the machine.
10209 * When we really reach PC8 or deeper states (not just when we allow it) we lose
10210 * the state of some registers, so when we come back from PC8+ we need to
10211 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
10212 * need to take care of the registers kept by RC6. Notice that this happens even
10213 * if we don't put the device in PCI D3 state (which is what currently happens
10214 * because of the runtime PM support).
10216 * For more, read "Display Sequences for Package C8" on the hardware
10219 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
10221 struct drm_device
*dev
= &dev_priv
->drm
;
10224 DRM_DEBUG_KMS("Enabling package C8+\n");
10226 if (HAS_PCH_LPT_LP(dev_priv
)) {
10227 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
10228 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
10229 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
10232 lpt_disable_clkout_dp(dev
);
10233 hsw_disable_lcpll(dev_priv
, true, true);
10236 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
10238 struct drm_device
*dev
= &dev_priv
->drm
;
10241 DRM_DEBUG_KMS("Disabling package C8+\n");
10243 hsw_restore_lcpll(dev_priv
);
10244 lpt_init_pch_refclk(dev
);
10246 if (HAS_PCH_LPT_LP(dev_priv
)) {
10247 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
10248 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
10249 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
10253 static void bxt_modeset_commit_cdclk(struct drm_atomic_state
*old_state
)
10255 struct drm_device
*dev
= old_state
->dev
;
10256 struct intel_atomic_state
*old_intel_state
=
10257 to_intel_atomic_state(old_state
);
10258 unsigned int req_cdclk
= old_intel_state
->dev_cdclk
;
10260 bxt_set_cdclk(to_i915(dev
), req_cdclk
);
10263 /* compute the max rate for new configuration */
10264 static int ilk_max_pixel_rate(struct drm_atomic_state
*state
)
10266 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
10267 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
10268 struct drm_crtc
*crtc
;
10269 struct drm_crtc_state
*cstate
;
10270 struct intel_crtc_state
*crtc_state
;
10271 unsigned max_pixel_rate
= 0, i
;
10274 memcpy(intel_state
->min_pixclk
, dev_priv
->min_pixclk
,
10275 sizeof(intel_state
->min_pixclk
));
10277 for_each_crtc_in_state(state
, crtc
, cstate
, i
) {
10280 crtc_state
= to_intel_crtc_state(cstate
);
10281 if (!crtc_state
->base
.enable
) {
10282 intel_state
->min_pixclk
[i
] = 0;
10286 pixel_rate
= ilk_pipe_pixel_rate(crtc_state
);
10288 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
10289 if (IS_BROADWELL(dev_priv
) && crtc_state
->ips_enabled
)
10290 pixel_rate
= DIV_ROUND_UP(pixel_rate
* 100, 95);
10292 intel_state
->min_pixclk
[i
] = pixel_rate
;
10295 for_each_pipe(dev_priv
, pipe
)
10296 max_pixel_rate
= max(intel_state
->min_pixclk
[pipe
], max_pixel_rate
);
10298 return max_pixel_rate
;
10301 static void broadwell_set_cdclk(struct drm_device
*dev
, int cdclk
)
10303 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10304 uint32_t val
, data
;
10307 if (WARN((I915_READ(LCPLL_CTL
) &
10308 (LCPLL_PLL_DISABLE
| LCPLL_PLL_LOCK
|
10309 LCPLL_CD_CLOCK_DISABLE
| LCPLL_ROOT_CD_CLOCK_DISABLE
|
10310 LCPLL_CD2X_CLOCK_DISABLE
| LCPLL_POWER_DOWN_ALLOW
|
10311 LCPLL_CD_SOURCE_FCLK
)) != LCPLL_PLL_LOCK
,
10312 "trying to change cdclk frequency with cdclk not enabled\n"))
10315 mutex_lock(&dev_priv
->rps
.hw_lock
);
10316 ret
= sandybridge_pcode_write(dev_priv
,
10317 BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ
, 0x0);
10318 mutex_unlock(&dev_priv
->rps
.hw_lock
);
10320 DRM_ERROR("failed to inform pcode about cdclk change\n");
10324 val
= I915_READ(LCPLL_CTL
);
10325 val
|= LCPLL_CD_SOURCE_FCLK
;
10326 I915_WRITE(LCPLL_CTL
, val
);
10328 if (wait_for_us(I915_READ(LCPLL_CTL
) &
10329 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
10330 DRM_ERROR("Switching to FCLK failed\n");
10332 val
= I915_READ(LCPLL_CTL
);
10333 val
&= ~LCPLL_CLK_FREQ_MASK
;
10337 val
|= LCPLL_CLK_FREQ_450
;
10341 val
|= LCPLL_CLK_FREQ_54O_BDW
;
10345 val
|= LCPLL_CLK_FREQ_337_5_BDW
;
10349 val
|= LCPLL_CLK_FREQ_675_BDW
;
10353 WARN(1, "invalid cdclk frequency\n");
10357 I915_WRITE(LCPLL_CTL
, val
);
10359 val
= I915_READ(LCPLL_CTL
);
10360 val
&= ~LCPLL_CD_SOURCE_FCLK
;
10361 I915_WRITE(LCPLL_CTL
, val
);
10363 if (wait_for_us((I915_READ(LCPLL_CTL
) &
10364 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
10365 DRM_ERROR("Switching back to LCPLL failed\n");
10367 mutex_lock(&dev_priv
->rps
.hw_lock
);
10368 sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
, data
);
10369 mutex_unlock(&dev_priv
->rps
.hw_lock
);
10371 I915_WRITE(CDCLK_FREQ
, DIV_ROUND_CLOSEST(cdclk
, 1000) - 1);
10373 intel_update_cdclk(dev
);
10375 WARN(cdclk
!= dev_priv
->cdclk_freq
,
10376 "cdclk requested %d kHz but got %d kHz\n",
10377 cdclk
, dev_priv
->cdclk_freq
);
10380 static int broadwell_calc_cdclk(int max_pixclk
)
10382 if (max_pixclk
> 540000)
10384 else if (max_pixclk
> 450000)
10386 else if (max_pixclk
> 337500)
10392 static int broadwell_modeset_calc_cdclk(struct drm_atomic_state
*state
)
10394 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
10395 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
10396 int max_pixclk
= ilk_max_pixel_rate(state
);
10400 * FIXME should also account for plane ratio
10401 * once 64bpp pixel formats are supported.
10403 cdclk
= broadwell_calc_cdclk(max_pixclk
);
10405 if (cdclk
> dev_priv
->max_cdclk_freq
) {
10406 DRM_DEBUG_KMS("requested cdclk (%d kHz) exceeds max (%d kHz)\n",
10407 cdclk
, dev_priv
->max_cdclk_freq
);
10411 intel_state
->cdclk
= intel_state
->dev_cdclk
= cdclk
;
10412 if (!intel_state
->active_crtcs
)
10413 intel_state
->dev_cdclk
= broadwell_calc_cdclk(0);
10418 static void broadwell_modeset_commit_cdclk(struct drm_atomic_state
*old_state
)
10420 struct drm_device
*dev
= old_state
->dev
;
10421 struct intel_atomic_state
*old_intel_state
=
10422 to_intel_atomic_state(old_state
);
10423 unsigned req_cdclk
= old_intel_state
->dev_cdclk
;
10425 broadwell_set_cdclk(dev
, req_cdclk
);
10428 static int skl_modeset_calc_cdclk(struct drm_atomic_state
*state
)
10430 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
10431 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
10432 const int max_pixclk
= ilk_max_pixel_rate(state
);
10433 int vco
= intel_state
->cdclk_pll_vco
;
10437 * FIXME should also account for plane ratio
10438 * once 64bpp pixel formats are supported.
10440 cdclk
= skl_calc_cdclk(max_pixclk
, vco
);
10443 * FIXME move the cdclk caclulation to
10444 * compute_config() so we can fail gracegully.
10446 if (cdclk
> dev_priv
->max_cdclk_freq
) {
10447 DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n",
10448 cdclk
, dev_priv
->max_cdclk_freq
);
10449 cdclk
= dev_priv
->max_cdclk_freq
;
10452 intel_state
->cdclk
= intel_state
->dev_cdclk
= cdclk
;
10453 if (!intel_state
->active_crtcs
)
10454 intel_state
->dev_cdclk
= skl_calc_cdclk(0, vco
);
10459 static void skl_modeset_commit_cdclk(struct drm_atomic_state
*old_state
)
10461 struct drm_i915_private
*dev_priv
= to_i915(old_state
->dev
);
10462 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(old_state
);
10463 unsigned int req_cdclk
= intel_state
->dev_cdclk
;
10464 unsigned int req_vco
= intel_state
->cdclk_pll_vco
;
10466 skl_set_cdclk(dev_priv
, req_cdclk
, req_vco
);
10469 static int haswell_crtc_compute_clock(struct intel_crtc
*crtc
,
10470 struct intel_crtc_state
*crtc_state
)
10472 if (!intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DSI
)) {
10473 if (!intel_ddi_pll_select(crtc
, crtc_state
))
10477 crtc
->lowfreq_avail
= false;
10482 static void bxt_get_ddi_pll(struct drm_i915_private
*dev_priv
,
10484 struct intel_crtc_state
*pipe_config
)
10486 enum intel_dpll_id id
;
10490 id
= DPLL_ID_SKL_DPLL0
;
10493 id
= DPLL_ID_SKL_DPLL1
;
10496 id
= DPLL_ID_SKL_DPLL2
;
10499 DRM_ERROR("Incorrect port type\n");
10503 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
10506 static void skylake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
10508 struct intel_crtc_state
*pipe_config
)
10510 enum intel_dpll_id id
;
10513 temp
= I915_READ(DPLL_CTRL2
) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port
);
10514 id
= temp
>> (port
* 3 + 1);
10516 if (WARN_ON(id
< SKL_DPLL0
|| id
> SKL_DPLL3
))
10519 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
10522 static void haswell_get_ddi_pll(struct drm_i915_private
*dev_priv
,
10524 struct intel_crtc_state
*pipe_config
)
10526 enum intel_dpll_id id
;
10527 uint32_t ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
10529 switch (ddi_pll_sel
) {
10530 case PORT_CLK_SEL_WRPLL1
:
10531 id
= DPLL_ID_WRPLL1
;
10533 case PORT_CLK_SEL_WRPLL2
:
10534 id
= DPLL_ID_WRPLL2
;
10536 case PORT_CLK_SEL_SPLL
:
10539 case PORT_CLK_SEL_LCPLL_810
:
10540 id
= DPLL_ID_LCPLL_810
;
10542 case PORT_CLK_SEL_LCPLL_1350
:
10543 id
= DPLL_ID_LCPLL_1350
;
10545 case PORT_CLK_SEL_LCPLL_2700
:
10546 id
= DPLL_ID_LCPLL_2700
;
10549 MISSING_CASE(ddi_pll_sel
);
10551 case PORT_CLK_SEL_NONE
:
10555 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
10558 static bool hsw_get_transcoder_state(struct intel_crtc
*crtc
,
10559 struct intel_crtc_state
*pipe_config
,
10560 unsigned long *power_domain_mask
)
10562 struct drm_device
*dev
= crtc
->base
.dev
;
10563 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10564 enum intel_display_power_domain power_domain
;
10568 * The pipe->transcoder mapping is fixed with the exception of the eDP
10569 * transcoder handled below.
10571 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
10574 * XXX: Do intel_display_power_get_if_enabled before reading this (for
10575 * consistency and less surprising code; it's in always on power).
10577 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
10578 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
10579 enum pipe trans_edp_pipe
;
10580 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
10582 WARN(1, "unknown pipe linked to edp transcoder\n");
10583 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
10584 case TRANS_DDI_EDP_INPUT_A_ON
:
10585 trans_edp_pipe
= PIPE_A
;
10587 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
10588 trans_edp_pipe
= PIPE_B
;
10590 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
10591 trans_edp_pipe
= PIPE_C
;
10595 if (trans_edp_pipe
== crtc
->pipe
)
10596 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
10599 power_domain
= POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
);
10600 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
10602 *power_domain_mask
|= BIT(power_domain
);
10604 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
10606 return tmp
& PIPECONF_ENABLE
;
10609 static bool bxt_get_dsi_transcoder_state(struct intel_crtc
*crtc
,
10610 struct intel_crtc_state
*pipe_config
,
10611 unsigned long *power_domain_mask
)
10613 struct drm_device
*dev
= crtc
->base
.dev
;
10614 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10615 enum intel_display_power_domain power_domain
;
10617 enum transcoder cpu_transcoder
;
10620 for_each_port_masked(port
, BIT(PORT_A
) | BIT(PORT_C
)) {
10621 if (port
== PORT_A
)
10622 cpu_transcoder
= TRANSCODER_DSI_A
;
10624 cpu_transcoder
= TRANSCODER_DSI_C
;
10626 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
10627 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
10629 *power_domain_mask
|= BIT(power_domain
);
10632 * The PLL needs to be enabled with a valid divider
10633 * configuration, otherwise accessing DSI registers will hang
10634 * the machine. See BSpec North Display Engine
10635 * registers/MIPI[BXT]. We can break out here early, since we
10636 * need the same DSI PLL to be enabled for both DSI ports.
10638 if (!intel_dsi_pll_is_enabled(dev_priv
))
10641 /* XXX: this works for video mode only */
10642 tmp
= I915_READ(BXT_MIPI_PORT_CTRL(port
));
10643 if (!(tmp
& DPI_ENABLE
))
10646 tmp
= I915_READ(MIPI_CTRL(port
));
10647 if ((tmp
& BXT_PIPE_SELECT_MASK
) != BXT_PIPE_SELECT(crtc
->pipe
))
10650 pipe_config
->cpu_transcoder
= cpu_transcoder
;
10654 return transcoder_is_dsi(pipe_config
->cpu_transcoder
);
10657 static void haswell_get_ddi_port_state(struct intel_crtc
*crtc
,
10658 struct intel_crtc_state
*pipe_config
)
10660 struct drm_device
*dev
= crtc
->base
.dev
;
10661 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10662 struct intel_shared_dpll
*pll
;
10666 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
10668 port
= (tmp
& TRANS_DDI_PORT_MASK
) >> TRANS_DDI_PORT_SHIFT
;
10670 if (IS_SKYLAKE(dev_priv
) || IS_KABYLAKE(dev_priv
))
10671 skylake_get_ddi_pll(dev_priv
, port
, pipe_config
);
10672 else if (IS_BROXTON(dev_priv
))
10673 bxt_get_ddi_pll(dev_priv
, port
, pipe_config
);
10675 haswell_get_ddi_pll(dev_priv
, port
, pipe_config
);
10677 pll
= pipe_config
->shared_dpll
;
10679 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
10680 &pipe_config
->dpll_hw_state
));
10684 * Haswell has only FDI/PCH transcoder A. It is which is connected to
10685 * DDI E. So just check whether this pipe is wired to DDI E and whether
10686 * the PCH transcoder is on.
10688 if (INTEL_INFO(dev
)->gen
< 9 &&
10689 (port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
10690 pipe_config
->has_pch_encoder
= true;
10692 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
10693 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
10694 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
10696 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
10700 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
10701 struct intel_crtc_state
*pipe_config
)
10703 struct drm_device
*dev
= crtc
->base
.dev
;
10704 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10705 enum intel_display_power_domain power_domain
;
10706 unsigned long power_domain_mask
;
10709 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
10710 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
10712 power_domain_mask
= BIT(power_domain
);
10714 pipe_config
->shared_dpll
= NULL
;
10716 active
= hsw_get_transcoder_state(crtc
, pipe_config
, &power_domain_mask
);
10718 if (IS_BROXTON(dev_priv
) &&
10719 bxt_get_dsi_transcoder_state(crtc
, pipe_config
, &power_domain_mask
)) {
10727 if (!transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
10728 haswell_get_ddi_port_state(crtc
, pipe_config
);
10729 intel_get_pipe_timings(crtc
, pipe_config
);
10732 intel_get_pipe_src_size(crtc
, pipe_config
);
10734 pipe_config
->gamma_mode
=
10735 I915_READ(GAMMA_MODE(crtc
->pipe
)) & GAMMA_MODE_MODE_MASK
;
10737 if (INTEL_INFO(dev
)->gen
>= 9) {
10738 skl_init_scalers(dev
, crtc
, pipe_config
);
10741 if (INTEL_INFO(dev
)->gen
>= 9) {
10742 pipe_config
->scaler_state
.scaler_id
= -1;
10743 pipe_config
->scaler_state
.scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
10746 power_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
10747 if (intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
10748 power_domain_mask
|= BIT(power_domain
);
10749 if (INTEL_INFO(dev
)->gen
>= 9)
10750 skylake_get_pfit_config(crtc
, pipe_config
);
10752 ironlake_get_pfit_config(crtc
, pipe_config
);
10755 if (IS_HASWELL(dev_priv
))
10756 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
10757 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
10759 if (pipe_config
->cpu_transcoder
!= TRANSCODER_EDP
&&
10760 !transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
10761 pipe_config
->pixel_multiplier
=
10762 I915_READ(PIPE_MULT(pipe_config
->cpu_transcoder
)) + 1;
10764 pipe_config
->pixel_multiplier
= 1;
10768 for_each_power_domain(power_domain
, power_domain_mask
)
10769 intel_display_power_put(dev_priv
, power_domain
);
10774 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
,
10775 const struct intel_plane_state
*plane_state
)
10777 struct drm_device
*dev
= crtc
->dev
;
10778 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10779 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10780 uint32_t cntl
= 0, size
= 0;
10782 if (plane_state
&& plane_state
->base
.visible
) {
10783 unsigned int width
= plane_state
->base
.crtc_w
;
10784 unsigned int height
= plane_state
->base
.crtc_h
;
10785 unsigned int stride
= roundup_pow_of_two(width
) * 4;
10789 WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
10800 cntl
|= CURSOR_ENABLE
|
10801 CURSOR_GAMMA_ENABLE
|
10802 CURSOR_FORMAT_ARGB
|
10803 CURSOR_STRIDE(stride
);
10805 size
= (height
<< 12) | width
;
10808 if (intel_crtc
->cursor_cntl
!= 0 &&
10809 (intel_crtc
->cursor_base
!= base
||
10810 intel_crtc
->cursor_size
!= size
||
10811 intel_crtc
->cursor_cntl
!= cntl
)) {
10812 /* On these chipsets we can only modify the base/size/stride
10813 * whilst the cursor is disabled.
10815 I915_WRITE(CURCNTR(PIPE_A
), 0);
10816 POSTING_READ(CURCNTR(PIPE_A
));
10817 intel_crtc
->cursor_cntl
= 0;
10820 if (intel_crtc
->cursor_base
!= base
) {
10821 I915_WRITE(CURBASE(PIPE_A
), base
);
10822 intel_crtc
->cursor_base
= base
;
10825 if (intel_crtc
->cursor_size
!= size
) {
10826 I915_WRITE(CURSIZE
, size
);
10827 intel_crtc
->cursor_size
= size
;
10830 if (intel_crtc
->cursor_cntl
!= cntl
) {
10831 I915_WRITE(CURCNTR(PIPE_A
), cntl
);
10832 POSTING_READ(CURCNTR(PIPE_A
));
10833 intel_crtc
->cursor_cntl
= cntl
;
10837 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
,
10838 const struct intel_plane_state
*plane_state
)
10840 struct drm_device
*dev
= crtc
->dev
;
10841 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10842 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10843 struct intel_crtc_state
*cstate
= to_intel_crtc_state(crtc
->state
);
10844 const struct skl_wm_values
*wm
= &dev_priv
->wm
.skl_results
;
10845 const struct skl_plane_wm
*p_wm
=
10846 &cstate
->wm
.skl
.optimal
.planes
[PLANE_CURSOR
];
10847 int pipe
= intel_crtc
->pipe
;
10850 if (INTEL_GEN(dev_priv
) >= 9 && wm
->dirty_pipes
& drm_crtc_mask(crtc
))
10851 skl_write_cursor_wm(intel_crtc
, p_wm
, &wm
->ddb
);
10853 if (plane_state
&& plane_state
->base
.visible
) {
10854 cntl
= MCURSOR_GAMMA_ENABLE
;
10855 switch (plane_state
->base
.crtc_w
) {
10857 cntl
|= CURSOR_MODE_64_ARGB_AX
;
10860 cntl
|= CURSOR_MODE_128_ARGB_AX
;
10863 cntl
|= CURSOR_MODE_256_ARGB_AX
;
10866 MISSING_CASE(plane_state
->base
.crtc_w
);
10869 cntl
|= pipe
<< 28; /* Connect to correct pipe */
10871 if (HAS_DDI(dev_priv
))
10872 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
10874 if (plane_state
->base
.rotation
== DRM_ROTATE_180
)
10875 cntl
|= CURSOR_ROTATE_180
;
10878 if (intel_crtc
->cursor_cntl
!= cntl
) {
10879 I915_WRITE(CURCNTR(pipe
), cntl
);
10880 POSTING_READ(CURCNTR(pipe
));
10881 intel_crtc
->cursor_cntl
= cntl
;
10884 /* and commit changes on next vblank */
10885 I915_WRITE(CURBASE(pipe
), base
);
10886 POSTING_READ(CURBASE(pipe
));
10888 intel_crtc
->cursor_base
= base
;
10891 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
10892 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
10893 const struct intel_plane_state
*plane_state
)
10895 struct drm_device
*dev
= crtc
->dev
;
10896 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10897 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10898 int pipe
= intel_crtc
->pipe
;
10899 u32 base
= intel_crtc
->cursor_addr
;
10903 int x
= plane_state
->base
.crtc_x
;
10904 int y
= plane_state
->base
.crtc_y
;
10907 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
10910 pos
|= x
<< CURSOR_X_SHIFT
;
10913 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
10916 pos
|= y
<< CURSOR_Y_SHIFT
;
10918 /* ILK+ do this automagically */
10919 if (HAS_GMCH_DISPLAY(dev_priv
) &&
10920 plane_state
->base
.rotation
== DRM_ROTATE_180
) {
10921 base
+= (plane_state
->base
.crtc_h
*
10922 plane_state
->base
.crtc_w
- 1) * 4;
10926 I915_WRITE(CURPOS(pipe
), pos
);
10928 if (IS_845G(dev_priv
) || IS_I865G(dev_priv
))
10929 i845_update_cursor(crtc
, base
, plane_state
);
10931 i9xx_update_cursor(crtc
, base
, plane_state
);
10934 static bool cursor_size_ok(struct drm_i915_private
*dev_priv
,
10935 uint32_t width
, uint32_t height
)
10937 if (width
== 0 || height
== 0)
10941 * 845g/865g are special in that they are only limited by
10942 * the width of their cursors, the height is arbitrary up to
10943 * the precision of the register. Everything else requires
10944 * square cursors, limited to a few power-of-two sizes.
10946 if (IS_845G(dev_priv
) || IS_I865G(dev_priv
)) {
10947 if ((width
& 63) != 0)
10950 if (width
> (IS_845G(dev_priv
) ? 64 : 512))
10956 switch (width
| height
) {
10959 if (IS_GEN2(dev_priv
))
10971 /* VESA 640x480x72Hz mode to set on the pipe */
10972 static struct drm_display_mode load_detect_mode
= {
10973 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
10974 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
10977 struct drm_framebuffer
*
10978 __intel_framebuffer_create(struct drm_device
*dev
,
10979 struct drm_mode_fb_cmd2
*mode_cmd
,
10980 struct drm_i915_gem_object
*obj
)
10982 struct intel_framebuffer
*intel_fb
;
10985 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
10987 return ERR_PTR(-ENOMEM
);
10989 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
10993 return &intel_fb
->base
;
10997 return ERR_PTR(ret
);
11000 static struct drm_framebuffer
*
11001 intel_framebuffer_create(struct drm_device
*dev
,
11002 struct drm_mode_fb_cmd2
*mode_cmd
,
11003 struct drm_i915_gem_object
*obj
)
11005 struct drm_framebuffer
*fb
;
11008 ret
= i915_mutex_lock_interruptible(dev
);
11010 return ERR_PTR(ret
);
11011 fb
= __intel_framebuffer_create(dev
, mode_cmd
, obj
);
11012 mutex_unlock(&dev
->struct_mutex
);
11018 intel_framebuffer_pitch_for_width(int width
, int bpp
)
11020 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
11021 return ALIGN(pitch
, 64);
11025 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
11027 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
11028 return PAGE_ALIGN(pitch
* mode
->vdisplay
);
11031 static struct drm_framebuffer
*
11032 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
11033 struct drm_display_mode
*mode
,
11034 int depth
, int bpp
)
11036 struct drm_framebuffer
*fb
;
11037 struct drm_i915_gem_object
*obj
;
11038 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
11040 obj
= i915_gem_object_create(dev
,
11041 intel_framebuffer_size_for_mode(mode
, bpp
));
11043 return ERR_CAST(obj
);
11045 mode_cmd
.width
= mode
->hdisplay
;
11046 mode_cmd
.height
= mode
->vdisplay
;
11047 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
11049 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
11051 fb
= intel_framebuffer_create(dev
, &mode_cmd
, obj
);
11053 i915_gem_object_put(obj
);
11058 static struct drm_framebuffer
*
11059 mode_fits_in_fbdev(struct drm_device
*dev
,
11060 struct drm_display_mode
*mode
)
11062 #ifdef CONFIG_DRM_FBDEV_EMULATION
11063 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11064 struct drm_i915_gem_object
*obj
;
11065 struct drm_framebuffer
*fb
;
11067 if (!dev_priv
->fbdev
)
11070 if (!dev_priv
->fbdev
->fb
)
11073 obj
= dev_priv
->fbdev
->fb
->obj
;
11076 fb
= &dev_priv
->fbdev
->fb
->base
;
11077 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
11078 fb
->bits_per_pixel
))
11081 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
11084 drm_framebuffer_reference(fb
);
11091 static int intel_modeset_setup_plane_state(struct drm_atomic_state
*state
,
11092 struct drm_crtc
*crtc
,
11093 struct drm_display_mode
*mode
,
11094 struct drm_framebuffer
*fb
,
11097 struct drm_plane_state
*plane_state
;
11098 int hdisplay
, vdisplay
;
11101 plane_state
= drm_atomic_get_plane_state(state
, crtc
->primary
);
11102 if (IS_ERR(plane_state
))
11103 return PTR_ERR(plane_state
);
11106 drm_crtc_get_hv_timing(mode
, &hdisplay
, &vdisplay
);
11108 hdisplay
= vdisplay
= 0;
11110 ret
= drm_atomic_set_crtc_for_plane(plane_state
, fb
? crtc
: NULL
);
11113 drm_atomic_set_fb_for_plane(plane_state
, fb
);
11114 plane_state
->crtc_x
= 0;
11115 plane_state
->crtc_y
= 0;
11116 plane_state
->crtc_w
= hdisplay
;
11117 plane_state
->crtc_h
= vdisplay
;
11118 plane_state
->src_x
= x
<< 16;
11119 plane_state
->src_y
= y
<< 16;
11120 plane_state
->src_w
= hdisplay
<< 16;
11121 plane_state
->src_h
= vdisplay
<< 16;
11126 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
11127 struct drm_display_mode
*mode
,
11128 struct intel_load_detect_pipe
*old
,
11129 struct drm_modeset_acquire_ctx
*ctx
)
11131 struct intel_crtc
*intel_crtc
;
11132 struct intel_encoder
*intel_encoder
=
11133 intel_attached_encoder(connector
);
11134 struct drm_crtc
*possible_crtc
;
11135 struct drm_encoder
*encoder
= &intel_encoder
->base
;
11136 struct drm_crtc
*crtc
= NULL
;
11137 struct drm_device
*dev
= encoder
->dev
;
11138 struct drm_framebuffer
*fb
;
11139 struct drm_mode_config
*config
= &dev
->mode_config
;
11140 struct drm_atomic_state
*state
= NULL
, *restore_state
= NULL
;
11141 struct drm_connector_state
*connector_state
;
11142 struct intel_crtc_state
*crtc_state
;
11145 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11146 connector
->base
.id
, connector
->name
,
11147 encoder
->base
.id
, encoder
->name
);
11149 old
->restore_state
= NULL
;
11152 ret
= drm_modeset_lock(&config
->connection_mutex
, ctx
);
11157 * Algorithm gets a little messy:
11159 * - if the connector already has an assigned crtc, use it (but make
11160 * sure it's on first)
11162 * - try to find the first unused crtc that can drive this connector,
11163 * and use that if we find one
11166 /* See if we already have a CRTC for this connector */
11167 if (connector
->state
->crtc
) {
11168 crtc
= connector
->state
->crtc
;
11170 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
11174 /* Make sure the crtc and connector are running */
11178 /* Find an unused one (if possible) */
11179 for_each_crtc(dev
, possible_crtc
) {
11181 if (!(encoder
->possible_crtcs
& (1 << i
)))
11184 ret
= drm_modeset_lock(&possible_crtc
->mutex
, ctx
);
11188 if (possible_crtc
->state
->enable
) {
11189 drm_modeset_unlock(&possible_crtc
->mutex
);
11193 crtc
= possible_crtc
;
11198 * If we didn't find an unused CRTC, don't use any.
11201 DRM_DEBUG_KMS("no pipe available for load-detect\n");
11206 intel_crtc
= to_intel_crtc(crtc
);
11208 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
11212 state
= drm_atomic_state_alloc(dev
);
11213 restore_state
= drm_atomic_state_alloc(dev
);
11214 if (!state
|| !restore_state
) {
11219 state
->acquire_ctx
= ctx
;
11220 restore_state
->acquire_ctx
= ctx
;
11222 connector_state
= drm_atomic_get_connector_state(state
, connector
);
11223 if (IS_ERR(connector_state
)) {
11224 ret
= PTR_ERR(connector_state
);
11228 ret
= drm_atomic_set_crtc_for_connector(connector_state
, crtc
);
11232 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
11233 if (IS_ERR(crtc_state
)) {
11234 ret
= PTR_ERR(crtc_state
);
11238 crtc_state
->base
.active
= crtc_state
->base
.enable
= true;
11241 mode
= &load_detect_mode
;
11243 /* We need a framebuffer large enough to accommodate all accesses
11244 * that the plane may generate whilst we perform load detection.
11245 * We can not rely on the fbcon either being present (we get called
11246 * during its initialisation to detect all boot displays, or it may
11247 * not even exist) or that it is large enough to satisfy the
11250 fb
= mode_fits_in_fbdev(dev
, mode
);
11252 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
11253 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
11255 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
11257 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
11261 ret
= intel_modeset_setup_plane_state(state
, crtc
, mode
, fb
, 0, 0);
11265 drm_framebuffer_unreference(fb
);
11267 ret
= drm_atomic_set_mode_for_crtc(&crtc_state
->base
, mode
);
11271 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state
, connector
));
11273 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state
, crtc
));
11275 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state
, crtc
->primary
));
11277 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret
);
11281 ret
= drm_atomic_commit(state
);
11283 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
11287 old
->restore_state
= restore_state
;
11289 /* let the connector get through one full cycle before testing */
11290 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
11295 drm_atomic_state_put(state
);
11298 if (restore_state
) {
11299 drm_atomic_state_put(restore_state
);
11300 restore_state
= NULL
;
11303 if (ret
== -EDEADLK
) {
11304 drm_modeset_backoff(ctx
);
11311 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
11312 struct intel_load_detect_pipe
*old
,
11313 struct drm_modeset_acquire_ctx
*ctx
)
11315 struct intel_encoder
*intel_encoder
=
11316 intel_attached_encoder(connector
);
11317 struct drm_encoder
*encoder
= &intel_encoder
->base
;
11318 struct drm_atomic_state
*state
= old
->restore_state
;
11321 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11322 connector
->base
.id
, connector
->name
,
11323 encoder
->base
.id
, encoder
->name
);
11328 ret
= drm_atomic_commit(state
);
11330 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret
);
11331 drm_atomic_state_put(state
);
11334 static int i9xx_pll_refclk(struct drm_device
*dev
,
11335 const struct intel_crtc_state
*pipe_config
)
11337 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11338 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
11340 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
11341 return dev_priv
->vbt
.lvds_ssc_freq
;
11342 else if (HAS_PCH_SPLIT(dev_priv
))
11344 else if (!IS_GEN2(dev_priv
))
11350 /* Returns the clock of the currently programmed mode of the given pipe. */
11351 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
11352 struct intel_crtc_state
*pipe_config
)
11354 struct drm_device
*dev
= crtc
->base
.dev
;
11355 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11356 int pipe
= pipe_config
->cpu_transcoder
;
11357 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
11361 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
11363 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
11364 fp
= pipe_config
->dpll_hw_state
.fp0
;
11366 fp
= pipe_config
->dpll_hw_state
.fp1
;
11368 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
11369 if (IS_PINEVIEW(dev
)) {
11370 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
11371 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
11373 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
11374 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
11377 if (!IS_GEN2(dev_priv
)) {
11378 if (IS_PINEVIEW(dev
))
11379 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
11380 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
11382 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
11383 DPLL_FPA01_P1_POST_DIV_SHIFT
);
11385 switch (dpll
& DPLL_MODE_MASK
) {
11386 case DPLLB_MODE_DAC_SERIAL
:
11387 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
11390 case DPLLB_MODE_LVDS
:
11391 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
11395 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
11396 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
11400 if (IS_PINEVIEW(dev
))
11401 port_clock
= pnv_calc_dpll_params(refclk
, &clock
);
11403 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
11405 u32 lvds
= IS_I830(dev_priv
) ? 0 : I915_READ(LVDS
);
11406 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
11409 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
11410 DPLL_FPA01_P1_POST_DIV_SHIFT
);
11412 if (lvds
& LVDS_CLKB_POWER_UP
)
11417 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
11420 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
11421 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
11423 if (dpll
& PLL_P2_DIVIDE_BY_4
)
11429 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
11433 * This value includes pixel_multiplier. We will use
11434 * port_clock to compute adjusted_mode.crtc_clock in the
11435 * encoder's get_config() function.
11437 pipe_config
->port_clock
= port_clock
;
11440 int intel_dotclock_calculate(int link_freq
,
11441 const struct intel_link_m_n
*m_n
)
11444 * The calculation for the data clock is:
11445 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
11446 * But we want to avoid losing precison if possible, so:
11447 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
11449 * and the link clock is simpler:
11450 * link_clock = (m * link_clock) / n
11456 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
11459 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
11460 struct intel_crtc_state
*pipe_config
)
11462 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
11464 /* read out port_clock from the DPLL */
11465 i9xx_crtc_clock_get(crtc
, pipe_config
);
11468 * In case there is an active pipe without active ports,
11469 * we may need some idea for the dotclock anyway.
11470 * Calculate one based on the FDI configuration.
11472 pipe_config
->base
.adjusted_mode
.crtc_clock
=
11473 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
11474 &pipe_config
->fdi_m_n
);
11477 /** Returns the currently programmed mode of the given pipe. */
11478 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
11479 struct drm_crtc
*crtc
)
11481 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11482 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11483 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
11484 struct drm_display_mode
*mode
;
11485 struct intel_crtc_state
*pipe_config
;
11486 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
11487 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
11488 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
11489 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
11490 enum pipe pipe
= intel_crtc
->pipe
;
11492 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
11496 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
11497 if (!pipe_config
) {
11503 * Construct a pipe_config sufficient for getting the clock info
11504 * back out of crtc_clock_get.
11506 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
11507 * to use a real value here instead.
11509 pipe_config
->cpu_transcoder
= (enum transcoder
) pipe
;
11510 pipe_config
->pixel_multiplier
= 1;
11511 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
11512 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
11513 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
11514 i9xx_crtc_clock_get(intel_crtc
, pipe_config
);
11516 mode
->clock
= pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
11517 mode
->hdisplay
= (htot
& 0xffff) + 1;
11518 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
11519 mode
->hsync_start
= (hsync
& 0xffff) + 1;
11520 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
11521 mode
->vdisplay
= (vtot
& 0xffff) + 1;
11522 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
11523 mode
->vsync_start
= (vsync
& 0xffff) + 1;
11524 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
11526 drm_mode_set_name(mode
);
11528 kfree(pipe_config
);
11533 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
11535 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11536 struct drm_device
*dev
= crtc
->dev
;
11537 struct intel_flip_work
*work
;
11539 spin_lock_irq(&dev
->event_lock
);
11540 work
= intel_crtc
->flip_work
;
11541 intel_crtc
->flip_work
= NULL
;
11542 spin_unlock_irq(&dev
->event_lock
);
11545 cancel_work_sync(&work
->mmio_work
);
11546 cancel_work_sync(&work
->unpin_work
);
11550 drm_crtc_cleanup(crtc
);
11555 static void intel_unpin_work_fn(struct work_struct
*__work
)
11557 struct intel_flip_work
*work
=
11558 container_of(__work
, struct intel_flip_work
, unpin_work
);
11559 struct intel_crtc
*crtc
= to_intel_crtc(work
->crtc
);
11560 struct drm_device
*dev
= crtc
->base
.dev
;
11561 struct drm_plane
*primary
= crtc
->base
.primary
;
11563 if (is_mmio_work(work
))
11564 flush_work(&work
->mmio_work
);
11566 mutex_lock(&dev
->struct_mutex
);
11567 intel_unpin_fb_obj(work
->old_fb
, primary
->state
->rotation
);
11568 i915_gem_object_put(work
->pending_flip_obj
);
11569 mutex_unlock(&dev
->struct_mutex
);
11571 i915_gem_request_put(work
->flip_queued_req
);
11573 intel_frontbuffer_flip_complete(to_i915(dev
),
11574 to_intel_plane(primary
)->frontbuffer_bit
);
11575 intel_fbc_post_update(crtc
);
11576 drm_framebuffer_unreference(work
->old_fb
);
11578 BUG_ON(atomic_read(&crtc
->unpin_work_count
) == 0);
11579 atomic_dec(&crtc
->unpin_work_count
);
11584 /* Is 'a' after or equal to 'b'? */
11585 static bool g4x_flip_count_after_eq(u32 a
, u32 b
)
11587 return !((a
- b
) & 0x80000000);
11590 static bool __pageflip_finished_cs(struct intel_crtc
*crtc
,
11591 struct intel_flip_work
*work
)
11593 struct drm_device
*dev
= crtc
->base
.dev
;
11594 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11596 if (abort_flip_on_reset(crtc
))
11600 * The relevant registers doen't exist on pre-ctg.
11601 * As the flip done interrupt doesn't trigger for mmio
11602 * flips on gmch platforms, a flip count check isn't
11603 * really needed there. But since ctg has the registers,
11604 * include it in the check anyway.
11606 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
))
11610 * BDW signals flip done immediately if the plane
11611 * is disabled, even if the plane enable is already
11612 * armed to occur at the next vblank :(
11616 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
11617 * used the same base address. In that case the mmio flip might
11618 * have completed, but the CS hasn't even executed the flip yet.
11620 * A flip count check isn't enough as the CS might have updated
11621 * the base address just after start of vblank, but before we
11622 * managed to process the interrupt. This means we'd complete the
11623 * CS flip too soon.
11625 * Combining both checks should get us a good enough result. It may
11626 * still happen that the CS flip has been executed, but has not
11627 * yet actually completed. But in case the base address is the same
11628 * anyway, we don't really care.
11630 return (I915_READ(DSPSURFLIVE(crtc
->plane
)) & ~0xfff) ==
11631 crtc
->flip_work
->gtt_offset
&&
11632 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc
->pipe
)),
11633 crtc
->flip_work
->flip_count
);
11637 __pageflip_finished_mmio(struct intel_crtc
*crtc
,
11638 struct intel_flip_work
*work
)
11641 * MMIO work completes when vblank is different from
11642 * flip_queued_vblank.
11644 * Reset counter value doesn't matter, this is handled by
11645 * i915_wait_request finishing early, so no need to handle
11648 return intel_crtc_get_vblank_counter(crtc
) != work
->flip_queued_vblank
;
11652 static bool pageflip_finished(struct intel_crtc
*crtc
,
11653 struct intel_flip_work
*work
)
11655 if (!atomic_read(&work
->pending
))
11660 if (is_mmio_work(work
))
11661 return __pageflip_finished_mmio(crtc
, work
);
11663 return __pageflip_finished_cs(crtc
, work
);
11666 void intel_finish_page_flip_cs(struct drm_i915_private
*dev_priv
, int pipe
)
11668 struct drm_device
*dev
= &dev_priv
->drm
;
11669 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
11670 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11671 struct intel_flip_work
*work
;
11672 unsigned long flags
;
11674 /* Ignore early vblank irqs */
11679 * This is called both by irq handlers and the reset code (to complete
11680 * lost pageflips) so needs the full irqsave spinlocks.
11682 spin_lock_irqsave(&dev
->event_lock
, flags
);
11683 work
= intel_crtc
->flip_work
;
11685 if (work
!= NULL
&&
11686 !is_mmio_work(work
) &&
11687 pageflip_finished(intel_crtc
, work
))
11688 page_flip_completed(intel_crtc
);
11690 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
11693 void intel_finish_page_flip_mmio(struct drm_i915_private
*dev_priv
, int pipe
)
11695 struct drm_device
*dev
= &dev_priv
->drm
;
11696 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
11697 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11698 struct intel_flip_work
*work
;
11699 unsigned long flags
;
11701 /* Ignore early vblank irqs */
11706 * This is called both by irq handlers and the reset code (to complete
11707 * lost pageflips) so needs the full irqsave spinlocks.
11709 spin_lock_irqsave(&dev
->event_lock
, flags
);
11710 work
= intel_crtc
->flip_work
;
11712 if (work
!= NULL
&&
11713 is_mmio_work(work
) &&
11714 pageflip_finished(intel_crtc
, work
))
11715 page_flip_completed(intel_crtc
);
11717 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
11720 static inline void intel_mark_page_flip_active(struct intel_crtc
*crtc
,
11721 struct intel_flip_work
*work
)
11723 work
->flip_queued_vblank
= intel_crtc_get_vblank_counter(crtc
);
11725 /* Ensure that the work item is consistent when activating it ... */
11726 smp_mb__before_atomic();
11727 atomic_set(&work
->pending
, 1);
11730 static int intel_gen2_queue_flip(struct drm_device
*dev
,
11731 struct drm_crtc
*crtc
,
11732 struct drm_framebuffer
*fb
,
11733 struct drm_i915_gem_object
*obj
,
11734 struct drm_i915_gem_request
*req
,
11737 struct intel_ring
*ring
= req
->ring
;
11738 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11742 ret
= intel_ring_begin(req
, 6);
11746 /* Can't queue multiple flips, so wait for the previous
11747 * one to finish before executing the next.
11749 if (intel_crtc
->plane
)
11750 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
11752 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
11753 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
11754 intel_ring_emit(ring
, MI_NOOP
);
11755 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
11756 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
11757 intel_ring_emit(ring
, fb
->pitches
[0]);
11758 intel_ring_emit(ring
, intel_crtc
->flip_work
->gtt_offset
);
11759 intel_ring_emit(ring
, 0); /* aux display base address, unused */
11764 static int intel_gen3_queue_flip(struct drm_device
*dev
,
11765 struct drm_crtc
*crtc
,
11766 struct drm_framebuffer
*fb
,
11767 struct drm_i915_gem_object
*obj
,
11768 struct drm_i915_gem_request
*req
,
11771 struct intel_ring
*ring
= req
->ring
;
11772 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11776 ret
= intel_ring_begin(req
, 6);
11780 if (intel_crtc
->plane
)
11781 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
11783 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
11784 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
11785 intel_ring_emit(ring
, MI_NOOP
);
11786 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
|
11787 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
11788 intel_ring_emit(ring
, fb
->pitches
[0]);
11789 intel_ring_emit(ring
, intel_crtc
->flip_work
->gtt_offset
);
11790 intel_ring_emit(ring
, MI_NOOP
);
11795 static int intel_gen4_queue_flip(struct drm_device
*dev
,
11796 struct drm_crtc
*crtc
,
11797 struct drm_framebuffer
*fb
,
11798 struct drm_i915_gem_object
*obj
,
11799 struct drm_i915_gem_request
*req
,
11802 struct intel_ring
*ring
= req
->ring
;
11803 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11804 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11805 uint32_t pf
, pipesrc
;
11808 ret
= intel_ring_begin(req
, 4);
11812 /* i965+ uses the linear or tiled offsets from the
11813 * Display Registers (which do not change across a page-flip)
11814 * so we need only reprogram the base address.
11816 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
11817 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
11818 intel_ring_emit(ring
, fb
->pitches
[0]);
11819 intel_ring_emit(ring
, intel_crtc
->flip_work
->gtt_offset
|
11820 intel_fb_modifier_to_tiling(fb
->modifier
[0]));
11822 /* XXX Enabling the panel-fitter across page-flip is so far
11823 * untested on non-native modes, so ignore it for now.
11824 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
11827 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
11828 intel_ring_emit(ring
, pf
| pipesrc
);
11833 static int intel_gen6_queue_flip(struct drm_device
*dev
,
11834 struct drm_crtc
*crtc
,
11835 struct drm_framebuffer
*fb
,
11836 struct drm_i915_gem_object
*obj
,
11837 struct drm_i915_gem_request
*req
,
11840 struct intel_ring
*ring
= req
->ring
;
11841 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11842 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11843 uint32_t pf
, pipesrc
;
11846 ret
= intel_ring_begin(req
, 4);
11850 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
11851 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
11852 intel_ring_emit(ring
, fb
->pitches
[0] |
11853 intel_fb_modifier_to_tiling(fb
->modifier
[0]));
11854 intel_ring_emit(ring
, intel_crtc
->flip_work
->gtt_offset
);
11856 /* Contrary to the suggestions in the documentation,
11857 * "Enable Panel Fitter" does not seem to be required when page
11858 * flipping with a non-native mode, and worse causes a normal
11860 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
11863 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
11864 intel_ring_emit(ring
, pf
| pipesrc
);
11869 static int intel_gen7_queue_flip(struct drm_device
*dev
,
11870 struct drm_crtc
*crtc
,
11871 struct drm_framebuffer
*fb
,
11872 struct drm_i915_gem_object
*obj
,
11873 struct drm_i915_gem_request
*req
,
11876 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11877 struct intel_ring
*ring
= req
->ring
;
11878 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11879 uint32_t plane_bit
= 0;
11882 switch (intel_crtc
->plane
) {
11884 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
11887 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
11890 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
11893 WARN_ONCE(1, "unknown plane in flip command\n");
11898 if (req
->engine
->id
== RCS
) {
11901 * On Gen 8, SRM is now taking an extra dword to accommodate
11902 * 48bits addresses, and we need a NOOP for the batch size to
11905 if (IS_GEN8(dev_priv
))
11910 * BSpec MI_DISPLAY_FLIP for IVB:
11911 * "The full packet must be contained within the same cache line."
11913 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
11914 * cacheline, if we ever start emitting more commands before
11915 * the MI_DISPLAY_FLIP we may need to first emit everything else,
11916 * then do the cacheline alignment, and finally emit the
11919 ret
= intel_ring_cacheline_align(req
);
11923 ret
= intel_ring_begin(req
, len
);
11927 /* Unmask the flip-done completion message. Note that the bspec says that
11928 * we should do this for both the BCS and RCS, and that we must not unmask
11929 * more than one flip event at any time (or ensure that one flip message
11930 * can be sent by waiting for flip-done prior to queueing new flips).
11931 * Experimentation says that BCS works despite DERRMR masking all
11932 * flip-done completion events and that unmasking all planes at once
11933 * for the RCS also doesn't appear to drop events. Setting the DERRMR
11934 * to zero does lead to lockups within MI_DISPLAY_FLIP.
11936 if (req
->engine
->id
== RCS
) {
11937 intel_ring_emit(ring
, MI_LOAD_REGISTER_IMM(1));
11938 intel_ring_emit_reg(ring
, DERRMR
);
11939 intel_ring_emit(ring
, ~(DERRMR_PIPEA_PRI_FLIP_DONE
|
11940 DERRMR_PIPEB_PRI_FLIP_DONE
|
11941 DERRMR_PIPEC_PRI_FLIP_DONE
));
11942 if (IS_GEN8(dev_priv
))
11943 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM_GEN8
|
11944 MI_SRM_LRM_GLOBAL_GTT
);
11946 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM
|
11947 MI_SRM_LRM_GLOBAL_GTT
);
11948 intel_ring_emit_reg(ring
, DERRMR
);
11949 intel_ring_emit(ring
,
11950 i915_ggtt_offset(req
->engine
->scratch
) + 256);
11951 if (IS_GEN8(dev_priv
)) {
11952 intel_ring_emit(ring
, 0);
11953 intel_ring_emit(ring
, MI_NOOP
);
11957 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
| plane_bit
);
11958 intel_ring_emit(ring
, fb
->pitches
[0] |
11959 intel_fb_modifier_to_tiling(fb
->modifier
[0]));
11960 intel_ring_emit(ring
, intel_crtc
->flip_work
->gtt_offset
);
11961 intel_ring_emit(ring
, (MI_NOOP
));
11966 static bool use_mmio_flip(struct intel_engine_cs
*engine
,
11967 struct drm_i915_gem_object
*obj
)
11970 * This is not being used for older platforms, because
11971 * non-availability of flip done interrupt forces us to use
11972 * CS flips. Older platforms derive flip done using some clever
11973 * tricks involving the flip_pending status bits and vblank irqs.
11974 * So using MMIO flips there would disrupt this mechanism.
11977 if (engine
== NULL
)
11980 if (INTEL_GEN(engine
->i915
) < 5)
11983 if (i915
.use_mmio_flip
< 0)
11985 else if (i915
.use_mmio_flip
> 0)
11987 else if (i915
.enable_execlists
)
11990 return engine
!= i915_gem_object_last_write_engine(obj
);
11993 static void skl_do_mmio_flip(struct intel_crtc
*intel_crtc
,
11994 unsigned int rotation
,
11995 struct intel_flip_work
*work
)
11997 struct drm_device
*dev
= intel_crtc
->base
.dev
;
11998 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11999 struct drm_framebuffer
*fb
= intel_crtc
->base
.primary
->fb
;
12000 const enum pipe pipe
= intel_crtc
->pipe
;
12001 u32 ctl
, stride
= skl_plane_stride(fb
, 0, rotation
);
12003 ctl
= I915_READ(PLANE_CTL(pipe
, 0));
12004 ctl
&= ~PLANE_CTL_TILED_MASK
;
12005 switch (fb
->modifier
[0]) {
12006 case DRM_FORMAT_MOD_NONE
:
12008 case I915_FORMAT_MOD_X_TILED
:
12009 ctl
|= PLANE_CTL_TILED_X
;
12011 case I915_FORMAT_MOD_Y_TILED
:
12012 ctl
|= PLANE_CTL_TILED_Y
;
12014 case I915_FORMAT_MOD_Yf_TILED
:
12015 ctl
|= PLANE_CTL_TILED_YF
;
12018 MISSING_CASE(fb
->modifier
[0]);
12022 * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on
12023 * PLANE_SURF updates, the update is then guaranteed to be atomic.
12025 I915_WRITE(PLANE_CTL(pipe
, 0), ctl
);
12026 I915_WRITE(PLANE_STRIDE(pipe
, 0), stride
);
12028 I915_WRITE(PLANE_SURF(pipe
, 0), work
->gtt_offset
);
12029 POSTING_READ(PLANE_SURF(pipe
, 0));
12032 static void ilk_do_mmio_flip(struct intel_crtc
*intel_crtc
,
12033 struct intel_flip_work
*work
)
12035 struct drm_device
*dev
= intel_crtc
->base
.dev
;
12036 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12037 struct drm_framebuffer
*fb
= intel_crtc
->base
.primary
->fb
;
12038 i915_reg_t reg
= DSPCNTR(intel_crtc
->plane
);
12041 dspcntr
= I915_READ(reg
);
12043 if (fb
->modifier
[0] == I915_FORMAT_MOD_X_TILED
)
12044 dspcntr
|= DISPPLANE_TILED
;
12046 dspcntr
&= ~DISPPLANE_TILED
;
12048 I915_WRITE(reg
, dspcntr
);
12050 I915_WRITE(DSPSURF(intel_crtc
->plane
), work
->gtt_offset
);
12051 POSTING_READ(DSPSURF(intel_crtc
->plane
));
12054 static void intel_mmio_flip_work_func(struct work_struct
*w
)
12056 struct intel_flip_work
*work
=
12057 container_of(w
, struct intel_flip_work
, mmio_work
);
12058 struct intel_crtc
*crtc
= to_intel_crtc(work
->crtc
);
12059 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
12060 struct intel_framebuffer
*intel_fb
=
12061 to_intel_framebuffer(crtc
->base
.primary
->fb
);
12062 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
12064 WARN_ON(i915_gem_object_wait(obj
, 0, MAX_SCHEDULE_TIMEOUT
, NULL
) < 0);
12066 intel_pipe_update_start(crtc
);
12068 if (INTEL_GEN(dev_priv
) >= 9)
12069 skl_do_mmio_flip(crtc
, work
->rotation
, work
);
12071 /* use_mmio_flip() retricts MMIO flips to ilk+ */
12072 ilk_do_mmio_flip(crtc
, work
);
12074 intel_pipe_update_end(crtc
, work
);
12077 static int intel_default_queue_flip(struct drm_device
*dev
,
12078 struct drm_crtc
*crtc
,
12079 struct drm_framebuffer
*fb
,
12080 struct drm_i915_gem_object
*obj
,
12081 struct drm_i915_gem_request
*req
,
12087 static bool __pageflip_stall_check_cs(struct drm_i915_private
*dev_priv
,
12088 struct intel_crtc
*intel_crtc
,
12089 struct intel_flip_work
*work
)
12093 if (!atomic_read(&work
->pending
))
12098 vblank
= intel_crtc_get_vblank_counter(intel_crtc
);
12099 if (work
->flip_ready_vblank
== 0) {
12100 if (work
->flip_queued_req
&&
12101 !i915_gem_request_completed(work
->flip_queued_req
))
12104 work
->flip_ready_vblank
= vblank
;
12107 if (vblank
- work
->flip_ready_vblank
< 3)
12110 /* Potential stall - if we see that the flip has happened,
12111 * assume a missed interrupt. */
12112 if (INTEL_GEN(dev_priv
) >= 4)
12113 addr
= I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc
->plane
)));
12115 addr
= I915_READ(DSPADDR(intel_crtc
->plane
));
12117 /* There is a potential issue here with a false positive after a flip
12118 * to the same address. We could address this by checking for a
12119 * non-incrementing frame counter.
12121 return addr
== work
->gtt_offset
;
12124 void intel_check_page_flip(struct drm_i915_private
*dev_priv
, int pipe
)
12126 struct drm_device
*dev
= &dev_priv
->drm
;
12127 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
12128 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12129 struct intel_flip_work
*work
;
12131 WARN_ON(!in_interrupt());
12136 spin_lock(&dev
->event_lock
);
12137 work
= intel_crtc
->flip_work
;
12139 if (work
!= NULL
&& !is_mmio_work(work
) &&
12140 __pageflip_stall_check_cs(dev_priv
, intel_crtc
, work
)) {
12142 "Kicking stuck page flip: queued at %d, now %d\n",
12143 work
->flip_queued_vblank
, intel_crtc_get_vblank_counter(intel_crtc
));
12144 page_flip_completed(intel_crtc
);
12148 if (work
!= NULL
&& !is_mmio_work(work
) &&
12149 intel_crtc_get_vblank_counter(intel_crtc
) - work
->flip_queued_vblank
> 1)
12150 intel_queue_rps_boost_for_request(work
->flip_queued_req
);
12151 spin_unlock(&dev
->event_lock
);
12154 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
12155 struct drm_framebuffer
*fb
,
12156 struct drm_pending_vblank_event
*event
,
12157 uint32_t page_flip_flags
)
12159 struct drm_device
*dev
= crtc
->dev
;
12160 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12161 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
12162 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
12163 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12164 struct drm_plane
*primary
= crtc
->primary
;
12165 enum pipe pipe
= intel_crtc
->pipe
;
12166 struct intel_flip_work
*work
;
12167 struct intel_engine_cs
*engine
;
12169 struct drm_i915_gem_request
*request
;
12170 struct i915_vma
*vma
;
12174 * drm_mode_page_flip_ioctl() should already catch this, but double
12175 * check to be safe. In the future we may enable pageflipping from
12176 * a disabled primary plane.
12178 if (WARN_ON(intel_fb_obj(old_fb
) == NULL
))
12181 /* Can't change pixel format via MI display flips. */
12182 if (fb
->pixel_format
!= crtc
->primary
->fb
->pixel_format
)
12186 * TILEOFF/LINOFF registers can't be changed via MI display flips.
12187 * Note that pitch changes could also affect these register.
12189 if (INTEL_INFO(dev
)->gen
> 3 &&
12190 (fb
->offsets
[0] != crtc
->primary
->fb
->offsets
[0] ||
12191 fb
->pitches
[0] != crtc
->primary
->fb
->pitches
[0]))
12194 if (i915_terminally_wedged(&dev_priv
->gpu_error
))
12197 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
12201 work
->event
= event
;
12203 work
->old_fb
= old_fb
;
12204 INIT_WORK(&work
->unpin_work
, intel_unpin_work_fn
);
12206 ret
= drm_crtc_vblank_get(crtc
);
12210 /* We borrow the event spin lock for protecting flip_work */
12211 spin_lock_irq(&dev
->event_lock
);
12212 if (intel_crtc
->flip_work
) {
12213 /* Before declaring the flip queue wedged, check if
12214 * the hardware completed the operation behind our backs.
12216 if (pageflip_finished(intel_crtc
, intel_crtc
->flip_work
)) {
12217 DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
12218 page_flip_completed(intel_crtc
);
12220 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
12221 spin_unlock_irq(&dev
->event_lock
);
12223 drm_crtc_vblank_put(crtc
);
12228 intel_crtc
->flip_work
= work
;
12229 spin_unlock_irq(&dev
->event_lock
);
12231 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
12232 flush_workqueue(dev_priv
->wq
);
12234 /* Reference the objects for the scheduled work. */
12235 drm_framebuffer_reference(work
->old_fb
);
12237 crtc
->primary
->fb
= fb
;
12238 update_state_fb(crtc
->primary
);
12240 work
->pending_flip_obj
= i915_gem_object_get(obj
);
12242 ret
= i915_mutex_lock_interruptible(dev
);
12246 intel_crtc
->reset_count
= i915_reset_count(&dev_priv
->gpu_error
);
12247 if (i915_reset_in_progress_or_wedged(&dev_priv
->gpu_error
)) {
12252 atomic_inc(&intel_crtc
->unpin_work_count
);
12254 if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
))
12255 work
->flip_count
= I915_READ(PIPE_FLIPCOUNT_G4X(pipe
)) + 1;
12257 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
12258 engine
= dev_priv
->engine
[BCS
];
12259 if (fb
->modifier
[0] != old_fb
->modifier
[0])
12260 /* vlv: DISPLAY_FLIP fails to change tiling */
12262 } else if (IS_IVYBRIDGE(dev_priv
) || IS_HASWELL(dev_priv
)) {
12263 engine
= dev_priv
->engine
[BCS
];
12264 } else if (INTEL_INFO(dev
)->gen
>= 7) {
12265 engine
= i915_gem_object_last_write_engine(obj
);
12266 if (engine
== NULL
|| engine
->id
!= RCS
)
12267 engine
= dev_priv
->engine
[BCS
];
12269 engine
= dev_priv
->engine
[RCS
];
12272 mmio_flip
= use_mmio_flip(engine
, obj
);
12274 vma
= intel_pin_and_fence_fb_obj(fb
, primary
->state
->rotation
);
12276 ret
= PTR_ERR(vma
);
12277 goto cleanup_pending
;
12280 work
->gtt_offset
= intel_fb_gtt_offset(fb
, primary
->state
->rotation
);
12281 work
->gtt_offset
+= intel_crtc
->dspaddr_offset
;
12282 work
->rotation
= crtc
->primary
->state
->rotation
;
12285 * There's the potential that the next frame will not be compatible with
12286 * FBC, so we want to call pre_update() before the actual page flip.
12287 * The problem is that pre_update() caches some information about the fb
12288 * object, so we want to do this only after the object is pinned. Let's
12289 * be on the safe side and do this immediately before scheduling the
12292 intel_fbc_pre_update(intel_crtc
, intel_crtc
->config
,
12293 to_intel_plane_state(primary
->state
));
12296 INIT_WORK(&work
->mmio_work
, intel_mmio_flip_work_func
);
12297 queue_work(system_unbound_wq
, &work
->mmio_work
);
12299 request
= i915_gem_request_alloc(engine
, engine
->last_context
);
12300 if (IS_ERR(request
)) {
12301 ret
= PTR_ERR(request
);
12302 goto cleanup_unpin
;
12305 ret
= i915_gem_request_await_object(request
, obj
, false);
12307 goto cleanup_request
;
12309 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
, request
,
12312 goto cleanup_request
;
12314 intel_mark_page_flip_active(intel_crtc
, work
);
12316 work
->flip_queued_req
= i915_gem_request_get(request
);
12317 i915_add_request_no_flush(request
);
12320 i915_gem_track_fb(intel_fb_obj(old_fb
), obj
,
12321 to_intel_plane(primary
)->frontbuffer_bit
);
12322 mutex_unlock(&dev
->struct_mutex
);
12324 intel_frontbuffer_flip_prepare(to_i915(dev
),
12325 to_intel_plane(primary
)->frontbuffer_bit
);
12327 trace_i915_flip_request(intel_crtc
->plane
, obj
);
12332 i915_add_request_no_flush(request
);
12334 intel_unpin_fb_obj(fb
, crtc
->primary
->state
->rotation
);
12336 atomic_dec(&intel_crtc
->unpin_work_count
);
12337 mutex_unlock(&dev
->struct_mutex
);
12339 crtc
->primary
->fb
= old_fb
;
12340 update_state_fb(crtc
->primary
);
12342 i915_gem_object_put(obj
);
12343 drm_framebuffer_unreference(work
->old_fb
);
12345 spin_lock_irq(&dev
->event_lock
);
12346 intel_crtc
->flip_work
= NULL
;
12347 spin_unlock_irq(&dev
->event_lock
);
12349 drm_crtc_vblank_put(crtc
);
12354 struct drm_atomic_state
*state
;
12355 struct drm_plane_state
*plane_state
;
12358 state
= drm_atomic_state_alloc(dev
);
12361 state
->acquire_ctx
= drm_modeset_legacy_acquire_ctx(crtc
);
12364 plane_state
= drm_atomic_get_plane_state(state
, primary
);
12365 ret
= PTR_ERR_OR_ZERO(plane_state
);
12367 drm_atomic_set_fb_for_plane(plane_state
, fb
);
12369 ret
= drm_atomic_set_crtc_for_plane(plane_state
, crtc
);
12371 ret
= drm_atomic_commit(state
);
12374 if (ret
== -EDEADLK
) {
12375 drm_modeset_backoff(state
->acquire_ctx
);
12376 drm_atomic_state_clear(state
);
12380 drm_atomic_state_put(state
);
12382 if (ret
== 0 && event
) {
12383 spin_lock_irq(&dev
->event_lock
);
12384 drm_crtc_send_vblank_event(crtc
, event
);
12385 spin_unlock_irq(&dev
->event_lock
);
12393 * intel_wm_need_update - Check whether watermarks need updating
12394 * @plane: drm plane
12395 * @state: new plane state
12397 * Check current plane state versus the new one to determine whether
12398 * watermarks need to be recalculated.
12400 * Returns true or false.
12402 static bool intel_wm_need_update(struct drm_plane
*plane
,
12403 struct drm_plane_state
*state
)
12405 struct intel_plane_state
*new = to_intel_plane_state(state
);
12406 struct intel_plane_state
*cur
= to_intel_plane_state(plane
->state
);
12408 /* Update watermarks on tiling or size changes. */
12409 if (new->base
.visible
!= cur
->base
.visible
)
12412 if (!cur
->base
.fb
|| !new->base
.fb
)
12415 if (cur
->base
.fb
->modifier
[0] != new->base
.fb
->modifier
[0] ||
12416 cur
->base
.rotation
!= new->base
.rotation
||
12417 drm_rect_width(&new->base
.src
) != drm_rect_width(&cur
->base
.src
) ||
12418 drm_rect_height(&new->base
.src
) != drm_rect_height(&cur
->base
.src
) ||
12419 drm_rect_width(&new->base
.dst
) != drm_rect_width(&cur
->base
.dst
) ||
12420 drm_rect_height(&new->base
.dst
) != drm_rect_height(&cur
->base
.dst
))
12426 static bool needs_scaling(struct intel_plane_state
*state
)
12428 int src_w
= drm_rect_width(&state
->base
.src
) >> 16;
12429 int src_h
= drm_rect_height(&state
->base
.src
) >> 16;
12430 int dst_w
= drm_rect_width(&state
->base
.dst
);
12431 int dst_h
= drm_rect_height(&state
->base
.dst
);
12433 return (src_w
!= dst_w
|| src_h
!= dst_h
);
12436 int intel_plane_atomic_calc_changes(struct drm_crtc_state
*crtc_state
,
12437 struct drm_plane_state
*plane_state
)
12439 struct intel_crtc_state
*pipe_config
= to_intel_crtc_state(crtc_state
);
12440 struct drm_crtc
*crtc
= crtc_state
->crtc
;
12441 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12442 struct drm_plane
*plane
= plane_state
->plane
;
12443 struct drm_device
*dev
= crtc
->dev
;
12444 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12445 struct intel_plane_state
*old_plane_state
=
12446 to_intel_plane_state(plane
->state
);
12447 bool mode_changed
= needs_modeset(crtc_state
);
12448 bool was_crtc_enabled
= crtc
->state
->active
;
12449 bool is_crtc_enabled
= crtc_state
->active
;
12450 bool turn_off
, turn_on
, visible
, was_visible
;
12451 struct drm_framebuffer
*fb
= plane_state
->fb
;
12454 if (INTEL_GEN(dev_priv
) >= 9 && plane
->type
!= DRM_PLANE_TYPE_CURSOR
) {
12455 ret
= skl_update_scaler_plane(
12456 to_intel_crtc_state(crtc_state
),
12457 to_intel_plane_state(plane_state
));
12462 was_visible
= old_plane_state
->base
.visible
;
12463 visible
= to_intel_plane_state(plane_state
)->base
.visible
;
12465 if (!was_crtc_enabled
&& WARN_ON(was_visible
))
12466 was_visible
= false;
12469 * Visibility is calculated as if the crtc was on, but
12470 * after scaler setup everything depends on it being off
12471 * when the crtc isn't active.
12473 * FIXME this is wrong for watermarks. Watermarks should also
12474 * be computed as if the pipe would be active. Perhaps move
12475 * per-plane wm computation to the .check_plane() hook, and
12476 * only combine the results from all planes in the current place?
12478 if (!is_crtc_enabled
)
12479 to_intel_plane_state(plane_state
)->base
.visible
= visible
= false;
12481 if (!was_visible
&& !visible
)
12484 if (fb
!= old_plane_state
->base
.fb
)
12485 pipe_config
->fb_changed
= true;
12487 turn_off
= was_visible
&& (!visible
|| mode_changed
);
12488 turn_on
= visible
&& (!was_visible
|| mode_changed
);
12490 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
12491 intel_crtc
->base
.base
.id
,
12492 intel_crtc
->base
.name
,
12493 plane
->base
.id
, plane
->name
,
12494 fb
? fb
->base
.id
: -1);
12496 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
12497 plane
->base
.id
, plane
->name
,
12498 was_visible
, visible
,
12499 turn_off
, turn_on
, mode_changed
);
12502 pipe_config
->update_wm_pre
= true;
12504 /* must disable cxsr around plane enable/disable */
12505 if (plane
->type
!= DRM_PLANE_TYPE_CURSOR
)
12506 pipe_config
->disable_cxsr
= true;
12507 } else if (turn_off
) {
12508 pipe_config
->update_wm_post
= true;
12510 /* must disable cxsr around plane enable/disable */
12511 if (plane
->type
!= DRM_PLANE_TYPE_CURSOR
)
12512 pipe_config
->disable_cxsr
= true;
12513 } else if (intel_wm_need_update(plane
, plane_state
)) {
12514 /* FIXME bollocks */
12515 pipe_config
->update_wm_pre
= true;
12516 pipe_config
->update_wm_post
= true;
12519 /* Pre-gen9 platforms need two-step watermark updates */
12520 if ((pipe_config
->update_wm_pre
|| pipe_config
->update_wm_post
) &&
12521 INTEL_INFO(dev
)->gen
< 9 && dev_priv
->display
.optimize_watermarks
)
12522 to_intel_crtc_state(crtc_state
)->wm
.need_postvbl_update
= true;
12524 if (visible
|| was_visible
)
12525 pipe_config
->fb_bits
|= to_intel_plane(plane
)->frontbuffer_bit
;
12528 * WaCxSRDisabledForSpriteScaling:ivb
12530 * cstate->update_wm was already set above, so this flag will
12531 * take effect when we commit and program watermarks.
12533 if (plane
->type
== DRM_PLANE_TYPE_OVERLAY
&& IS_IVYBRIDGE(dev_priv
) &&
12534 needs_scaling(to_intel_plane_state(plane_state
)) &&
12535 !needs_scaling(old_plane_state
))
12536 pipe_config
->disable_lp_wm
= true;
12541 static bool encoders_cloneable(const struct intel_encoder
*a
,
12542 const struct intel_encoder
*b
)
12544 /* masks could be asymmetric, so check both ways */
12545 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
12546 b
->cloneable
& (1 << a
->type
));
12549 static bool check_single_encoder_cloning(struct drm_atomic_state
*state
,
12550 struct intel_crtc
*crtc
,
12551 struct intel_encoder
*encoder
)
12553 struct intel_encoder
*source_encoder
;
12554 struct drm_connector
*connector
;
12555 struct drm_connector_state
*connector_state
;
12558 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
12559 if (connector_state
->crtc
!= &crtc
->base
)
12563 to_intel_encoder(connector_state
->best_encoder
);
12564 if (!encoders_cloneable(encoder
, source_encoder
))
12571 static int intel_crtc_atomic_check(struct drm_crtc
*crtc
,
12572 struct drm_crtc_state
*crtc_state
)
12574 struct drm_device
*dev
= crtc
->dev
;
12575 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12576 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12577 struct intel_crtc_state
*pipe_config
=
12578 to_intel_crtc_state(crtc_state
);
12579 struct drm_atomic_state
*state
= crtc_state
->state
;
12581 bool mode_changed
= needs_modeset(crtc_state
);
12583 if (mode_changed
&& !crtc_state
->active
)
12584 pipe_config
->update_wm_post
= true;
12586 if (mode_changed
&& crtc_state
->enable
&&
12587 dev_priv
->display
.crtc_compute_clock
&&
12588 !WARN_ON(pipe_config
->shared_dpll
)) {
12589 ret
= dev_priv
->display
.crtc_compute_clock(intel_crtc
,
12595 if (crtc_state
->color_mgmt_changed
) {
12596 ret
= intel_color_check(crtc
, crtc_state
);
12601 * Changing color management on Intel hardware is
12602 * handled as part of planes update.
12604 crtc_state
->planes_changed
= true;
12608 if (dev_priv
->display
.compute_pipe_wm
) {
12609 ret
= dev_priv
->display
.compute_pipe_wm(pipe_config
);
12611 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
12616 if (dev_priv
->display
.compute_intermediate_wm
&&
12617 !to_intel_atomic_state(state
)->skip_intermediate_wm
) {
12618 if (WARN_ON(!dev_priv
->display
.compute_pipe_wm
))
12622 * Calculate 'intermediate' watermarks that satisfy both the
12623 * old state and the new state. We can program these
12626 ret
= dev_priv
->display
.compute_intermediate_wm(crtc
->dev
,
12630 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
12633 } else if (dev_priv
->display
.compute_intermediate_wm
) {
12634 if (HAS_PCH_SPLIT(dev_priv
) && INTEL_GEN(dev_priv
) < 9)
12635 pipe_config
->wm
.ilk
.intermediate
= pipe_config
->wm
.ilk
.optimal
;
12638 if (INTEL_INFO(dev
)->gen
>= 9) {
12640 ret
= skl_update_scaler_crtc(pipe_config
);
12643 ret
= intel_atomic_setup_scalers(dev
, intel_crtc
,
12650 static const struct drm_crtc_helper_funcs intel_helper_funcs
= {
12651 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
12652 .atomic_begin
= intel_begin_crtc_commit
,
12653 .atomic_flush
= intel_finish_crtc_commit
,
12654 .atomic_check
= intel_crtc_atomic_check
,
12657 static void intel_modeset_update_connector_atomic_state(struct drm_device
*dev
)
12659 struct intel_connector
*connector
;
12661 for_each_intel_connector(dev
, connector
) {
12662 if (connector
->base
.state
->crtc
)
12663 drm_connector_unreference(&connector
->base
);
12665 if (connector
->base
.encoder
) {
12666 connector
->base
.state
->best_encoder
=
12667 connector
->base
.encoder
;
12668 connector
->base
.state
->crtc
=
12669 connector
->base
.encoder
->crtc
;
12671 drm_connector_reference(&connector
->base
);
12673 connector
->base
.state
->best_encoder
= NULL
;
12674 connector
->base
.state
->crtc
= NULL
;
12680 connected_sink_compute_bpp(struct intel_connector
*connector
,
12681 struct intel_crtc_state
*pipe_config
)
12683 const struct drm_display_info
*info
= &connector
->base
.display_info
;
12684 int bpp
= pipe_config
->pipe_bpp
;
12686 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
12687 connector
->base
.base
.id
,
12688 connector
->base
.name
);
12690 /* Don't use an invalid EDID bpc value */
12691 if (info
->bpc
!= 0 && info
->bpc
* 3 < bpp
) {
12692 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
12693 bpp
, info
->bpc
* 3);
12694 pipe_config
->pipe_bpp
= info
->bpc
* 3;
12697 /* Clamp bpp to 8 on screens without EDID 1.4 */
12698 if (info
->bpc
== 0 && bpp
> 24) {
12699 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
12701 pipe_config
->pipe_bpp
= 24;
12706 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
12707 struct intel_crtc_state
*pipe_config
)
12709 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
12710 struct drm_atomic_state
*state
;
12711 struct drm_connector
*connector
;
12712 struct drm_connector_state
*connector_state
;
12715 if ((IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
12716 IS_CHERRYVIEW(dev_priv
)))
12718 else if (INTEL_GEN(dev_priv
) >= 5)
12724 pipe_config
->pipe_bpp
= bpp
;
12726 state
= pipe_config
->base
.state
;
12728 /* Clamp display bpp to EDID value */
12729 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
12730 if (connector_state
->crtc
!= &crtc
->base
)
12733 connected_sink_compute_bpp(to_intel_connector(connector
),
12740 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
12742 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
12743 "type: 0x%x flags: 0x%x\n",
12745 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
12746 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
12747 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
12748 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
12751 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
12752 struct intel_crtc_state
*pipe_config
,
12753 const char *context
)
12755 struct drm_device
*dev
= crtc
->base
.dev
;
12756 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12757 struct drm_plane
*plane
;
12758 struct intel_plane
*intel_plane
;
12759 struct intel_plane_state
*state
;
12760 struct drm_framebuffer
*fb
;
12762 DRM_DEBUG_KMS("[CRTC:%d:%s]%s config %p for pipe %c\n",
12763 crtc
->base
.base
.id
, crtc
->base
.name
,
12764 context
, pipe_config
, pipe_name(crtc
->pipe
));
12766 DRM_DEBUG_KMS("cpu_transcoder: %s\n", transcoder_name(pipe_config
->cpu_transcoder
));
12767 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
12768 pipe_config
->pipe_bpp
, pipe_config
->dither
);
12769 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
12770 pipe_config
->has_pch_encoder
,
12771 pipe_config
->fdi_lanes
,
12772 pipe_config
->fdi_m_n
.gmch_m
, pipe_config
->fdi_m_n
.gmch_n
,
12773 pipe_config
->fdi_m_n
.link_m
, pipe_config
->fdi_m_n
.link_n
,
12774 pipe_config
->fdi_m_n
.tu
);
12775 DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
12776 intel_crtc_has_dp_encoder(pipe_config
),
12777 pipe_config
->lane_count
,
12778 pipe_config
->dp_m_n
.gmch_m
, pipe_config
->dp_m_n
.gmch_n
,
12779 pipe_config
->dp_m_n
.link_m
, pipe_config
->dp_m_n
.link_n
,
12780 pipe_config
->dp_m_n
.tu
);
12782 DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
12783 intel_crtc_has_dp_encoder(pipe_config
),
12784 pipe_config
->lane_count
,
12785 pipe_config
->dp_m2_n2
.gmch_m
,
12786 pipe_config
->dp_m2_n2
.gmch_n
,
12787 pipe_config
->dp_m2_n2
.link_m
,
12788 pipe_config
->dp_m2_n2
.link_n
,
12789 pipe_config
->dp_m2_n2
.tu
);
12791 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
12792 pipe_config
->has_audio
,
12793 pipe_config
->has_infoframe
);
12795 DRM_DEBUG_KMS("requested mode:\n");
12796 drm_mode_debug_printmodeline(&pipe_config
->base
.mode
);
12797 DRM_DEBUG_KMS("adjusted mode:\n");
12798 drm_mode_debug_printmodeline(&pipe_config
->base
.adjusted_mode
);
12799 intel_dump_crtc_timings(&pipe_config
->base
.adjusted_mode
);
12800 DRM_DEBUG_KMS("port clock: %d\n", pipe_config
->port_clock
);
12801 DRM_DEBUG_KMS("pipe src size: %dx%d\n",
12802 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
12803 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
12805 pipe_config
->scaler_state
.scaler_users
,
12806 pipe_config
->scaler_state
.scaler_id
);
12807 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
12808 pipe_config
->gmch_pfit
.control
,
12809 pipe_config
->gmch_pfit
.pgm_ratios
,
12810 pipe_config
->gmch_pfit
.lvds_border_bits
);
12811 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
12812 pipe_config
->pch_pfit
.pos
,
12813 pipe_config
->pch_pfit
.size
,
12814 pipe_config
->pch_pfit
.enabled
? "enabled" : "disabled");
12815 DRM_DEBUG_KMS("ips: %i\n", pipe_config
->ips_enabled
);
12816 DRM_DEBUG_KMS("double wide: %i\n", pipe_config
->double_wide
);
12818 if (IS_BROXTON(dev_priv
)) {
12819 DRM_DEBUG_KMS("dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x,"
12820 "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, "
12821 "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n",
12822 pipe_config
->dpll_hw_state
.ebb0
,
12823 pipe_config
->dpll_hw_state
.ebb4
,
12824 pipe_config
->dpll_hw_state
.pll0
,
12825 pipe_config
->dpll_hw_state
.pll1
,
12826 pipe_config
->dpll_hw_state
.pll2
,
12827 pipe_config
->dpll_hw_state
.pll3
,
12828 pipe_config
->dpll_hw_state
.pll6
,
12829 pipe_config
->dpll_hw_state
.pll8
,
12830 pipe_config
->dpll_hw_state
.pll9
,
12831 pipe_config
->dpll_hw_state
.pll10
,
12832 pipe_config
->dpll_hw_state
.pcsdw12
);
12833 } else if (IS_SKYLAKE(dev_priv
) || IS_KABYLAKE(dev_priv
)) {
12834 DRM_DEBUG_KMS("dpll_hw_state: "
12835 "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n",
12836 pipe_config
->dpll_hw_state
.ctrl1
,
12837 pipe_config
->dpll_hw_state
.cfgcr1
,
12838 pipe_config
->dpll_hw_state
.cfgcr2
);
12839 } else if (HAS_DDI(dev_priv
)) {
12840 DRM_DEBUG_KMS("dpll_hw_state: wrpll: 0x%x spll: 0x%x\n",
12841 pipe_config
->dpll_hw_state
.wrpll
,
12842 pipe_config
->dpll_hw_state
.spll
);
12844 DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, "
12845 "fp0: 0x%x, fp1: 0x%x\n",
12846 pipe_config
->dpll_hw_state
.dpll
,
12847 pipe_config
->dpll_hw_state
.dpll_md
,
12848 pipe_config
->dpll_hw_state
.fp0
,
12849 pipe_config
->dpll_hw_state
.fp1
);
12852 DRM_DEBUG_KMS("planes on this crtc\n");
12853 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
12855 intel_plane
= to_intel_plane(plane
);
12856 if (intel_plane
->pipe
!= crtc
->pipe
)
12859 state
= to_intel_plane_state(plane
->state
);
12860 fb
= state
->base
.fb
;
12862 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
12863 plane
->base
.id
, plane
->name
, state
->scaler_id
);
12867 format_name
= drm_get_format_name(fb
->pixel_format
);
12869 DRM_DEBUG_KMS("[PLANE:%d:%s] enabled",
12870 plane
->base
.id
, plane
->name
);
12871 DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = %s",
12872 fb
->base
.id
, fb
->width
, fb
->height
, format_name
);
12873 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
12875 state
->base
.src
.x1
>> 16,
12876 state
->base
.src
.y1
>> 16,
12877 drm_rect_width(&state
->base
.src
) >> 16,
12878 drm_rect_height(&state
->base
.src
) >> 16,
12879 state
->base
.dst
.x1
, state
->base
.dst
.y1
,
12880 drm_rect_width(&state
->base
.dst
),
12881 drm_rect_height(&state
->base
.dst
));
12883 kfree(format_name
);
12887 static bool check_digital_port_conflicts(struct drm_atomic_state
*state
)
12889 struct drm_device
*dev
= state
->dev
;
12890 struct drm_connector
*connector
;
12891 unsigned int used_ports
= 0;
12892 unsigned int used_mst_ports
= 0;
12895 * Walk the connector list instead of the encoder
12896 * list to detect the problem on ddi platforms
12897 * where there's just one encoder per digital port.
12899 drm_for_each_connector(connector
, dev
) {
12900 struct drm_connector_state
*connector_state
;
12901 struct intel_encoder
*encoder
;
12903 connector_state
= drm_atomic_get_existing_connector_state(state
, connector
);
12904 if (!connector_state
)
12905 connector_state
= connector
->state
;
12907 if (!connector_state
->best_encoder
)
12910 encoder
= to_intel_encoder(connector_state
->best_encoder
);
12912 WARN_ON(!connector_state
->crtc
);
12914 switch (encoder
->type
) {
12915 unsigned int port_mask
;
12916 case INTEL_OUTPUT_UNKNOWN
:
12917 if (WARN_ON(!HAS_DDI(to_i915(dev
))))
12919 case INTEL_OUTPUT_DP
:
12920 case INTEL_OUTPUT_HDMI
:
12921 case INTEL_OUTPUT_EDP
:
12922 port_mask
= 1 << enc_to_dig_port(&encoder
->base
)->port
;
12924 /* the same port mustn't appear more than once */
12925 if (used_ports
& port_mask
)
12928 used_ports
|= port_mask
;
12930 case INTEL_OUTPUT_DP_MST
:
12932 1 << enc_to_mst(&encoder
->base
)->primary
->port
;
12939 /* can't mix MST and SST/HDMI on the same port */
12940 if (used_ports
& used_mst_ports
)
12947 clear_intel_crtc_state(struct intel_crtc_state
*crtc_state
)
12949 struct drm_crtc_state tmp_state
;
12950 struct intel_crtc_scaler_state scaler_state
;
12951 struct intel_dpll_hw_state dpll_hw_state
;
12952 struct intel_shared_dpll
*shared_dpll
;
12955 /* FIXME: before the switch to atomic started, a new pipe_config was
12956 * kzalloc'd. Code that depends on any field being zero should be
12957 * fixed, so that the crtc_state can be safely duplicated. For now,
12958 * only fields that are know to not cause problems are preserved. */
12960 tmp_state
= crtc_state
->base
;
12961 scaler_state
= crtc_state
->scaler_state
;
12962 shared_dpll
= crtc_state
->shared_dpll
;
12963 dpll_hw_state
= crtc_state
->dpll_hw_state
;
12964 force_thru
= crtc_state
->pch_pfit
.force_thru
;
12966 memset(crtc_state
, 0, sizeof *crtc_state
);
12968 crtc_state
->base
= tmp_state
;
12969 crtc_state
->scaler_state
= scaler_state
;
12970 crtc_state
->shared_dpll
= shared_dpll
;
12971 crtc_state
->dpll_hw_state
= dpll_hw_state
;
12972 crtc_state
->pch_pfit
.force_thru
= force_thru
;
12976 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
12977 struct intel_crtc_state
*pipe_config
)
12979 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
12980 struct intel_encoder
*encoder
;
12981 struct drm_connector
*connector
;
12982 struct drm_connector_state
*connector_state
;
12983 int base_bpp
, ret
= -EINVAL
;
12987 clear_intel_crtc_state(pipe_config
);
12989 pipe_config
->cpu_transcoder
=
12990 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
12993 * Sanitize sync polarity flags based on requested ones. If neither
12994 * positive or negative polarity is requested, treat this as meaning
12995 * negative polarity.
12997 if (!(pipe_config
->base
.adjusted_mode
.flags
&
12998 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
12999 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
13001 if (!(pipe_config
->base
.adjusted_mode
.flags
&
13002 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
13003 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
13005 base_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
13011 * Determine the real pipe dimensions. Note that stereo modes can
13012 * increase the actual pipe size due to the frame doubling and
13013 * insertion of additional space for blanks between the frame. This
13014 * is stored in the crtc timings. We use the requested mode to do this
13015 * computation to clearly distinguish it from the adjusted mode, which
13016 * can be changed by the connectors in the below retry loop.
13018 drm_crtc_get_hv_timing(&pipe_config
->base
.mode
,
13019 &pipe_config
->pipe_src_w
,
13020 &pipe_config
->pipe_src_h
);
13022 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
13023 if (connector_state
->crtc
!= crtc
)
13026 encoder
= to_intel_encoder(connector_state
->best_encoder
);
13028 if (!check_single_encoder_cloning(state
, to_intel_crtc(crtc
), encoder
)) {
13029 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
13034 * Determine output_types before calling the .compute_config()
13035 * hooks so that the hooks can use this information safely.
13037 pipe_config
->output_types
|= 1 << encoder
->type
;
13041 /* Ensure the port clock defaults are reset when retrying. */
13042 pipe_config
->port_clock
= 0;
13043 pipe_config
->pixel_multiplier
= 1;
13045 /* Fill in default crtc timings, allow encoders to overwrite them. */
13046 drm_mode_set_crtcinfo(&pipe_config
->base
.adjusted_mode
,
13047 CRTC_STEREO_DOUBLE
);
13049 /* Pass our mode to the connectors and the CRTC to give them a chance to
13050 * adjust it according to limitations or connector properties, and also
13051 * a chance to reject the mode entirely.
13053 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
13054 if (connector_state
->crtc
!= crtc
)
13057 encoder
= to_intel_encoder(connector_state
->best_encoder
);
13059 if (!(encoder
->compute_config(encoder
, pipe_config
, connector_state
))) {
13060 DRM_DEBUG_KMS("Encoder config failure\n");
13065 /* Set default port clock if not overwritten by the encoder. Needs to be
13066 * done afterwards in case the encoder adjusts the mode. */
13067 if (!pipe_config
->port_clock
)
13068 pipe_config
->port_clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
13069 * pipe_config
->pixel_multiplier
;
13071 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
13073 DRM_DEBUG_KMS("CRTC fixup failed\n");
13077 if (ret
== RETRY
) {
13078 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
13083 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
13085 goto encoder_retry
;
13088 /* Dithering seems to not pass-through bits correctly when it should, so
13089 * only enable it on 6bpc panels. */
13090 pipe_config
->dither
= pipe_config
->pipe_bpp
== 6*3;
13091 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
13092 base_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
13099 intel_modeset_update_crtc_state(struct drm_atomic_state
*state
)
13101 struct drm_crtc
*crtc
;
13102 struct drm_crtc_state
*crtc_state
;
13105 /* Double check state. */
13106 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
13107 to_intel_crtc(crtc
)->config
= to_intel_crtc_state(crtc
->state
);
13109 /* Update hwmode for vblank functions */
13110 if (crtc
->state
->active
)
13111 crtc
->hwmode
= crtc
->state
->adjusted_mode
;
13113 crtc
->hwmode
.crtc_clock
= 0;
13116 * Update legacy state to satisfy fbc code. This can
13117 * be removed when fbc uses the atomic state.
13119 if (drm_atomic_get_existing_plane_state(state
, crtc
->primary
)) {
13120 struct drm_plane_state
*plane_state
= crtc
->primary
->state
;
13122 crtc
->primary
->fb
= plane_state
->fb
;
13123 crtc
->x
= plane_state
->src_x
>> 16;
13124 crtc
->y
= plane_state
->src_y
>> 16;
13129 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
13133 if (clock1
== clock2
)
13136 if (!clock1
|| !clock2
)
13139 diff
= abs(clock1
- clock2
);
13141 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
13148 intel_compare_m_n(unsigned int m
, unsigned int n
,
13149 unsigned int m2
, unsigned int n2
,
13152 if (m
== m2
&& n
== n2
)
13155 if (exact
|| !m
|| !n
|| !m2
|| !n2
)
13158 BUILD_BUG_ON(DATA_LINK_M_N_MASK
> INT_MAX
);
13165 } else if (n
< n2
) {
13175 return intel_fuzzy_clock_check(m
, m2
);
13179 intel_compare_link_m_n(const struct intel_link_m_n
*m_n
,
13180 struct intel_link_m_n
*m2_n2
,
13183 if (m_n
->tu
== m2_n2
->tu
&&
13184 intel_compare_m_n(m_n
->gmch_m
, m_n
->gmch_n
,
13185 m2_n2
->gmch_m
, m2_n2
->gmch_n
, !adjust
) &&
13186 intel_compare_m_n(m_n
->link_m
, m_n
->link_n
,
13187 m2_n2
->link_m
, m2_n2
->link_n
, !adjust
)) {
13198 intel_pipe_config_compare(struct drm_device
*dev
,
13199 struct intel_crtc_state
*current_config
,
13200 struct intel_crtc_state
*pipe_config
,
13203 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13206 #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \
13209 DRM_ERROR(fmt, ##__VA_ARGS__); \
13211 DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \
13214 #define PIPE_CONF_CHECK_X(name) \
13215 if (current_config->name != pipe_config->name) { \
13216 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
13217 "(expected 0x%08x, found 0x%08x)\n", \
13218 current_config->name, \
13219 pipe_config->name); \
13223 #define PIPE_CONF_CHECK_I(name) \
13224 if (current_config->name != pipe_config->name) { \
13225 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
13226 "(expected %i, found %i)\n", \
13227 current_config->name, \
13228 pipe_config->name); \
13232 #define PIPE_CONF_CHECK_P(name) \
13233 if (current_config->name != pipe_config->name) { \
13234 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
13235 "(expected %p, found %p)\n", \
13236 current_config->name, \
13237 pipe_config->name); \
13241 #define PIPE_CONF_CHECK_M_N(name) \
13242 if (!intel_compare_link_m_n(¤t_config->name, \
13243 &pipe_config->name,\
13245 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
13246 "(expected tu %i gmch %i/%i link %i/%i, " \
13247 "found tu %i, gmch %i/%i link %i/%i)\n", \
13248 current_config->name.tu, \
13249 current_config->name.gmch_m, \
13250 current_config->name.gmch_n, \
13251 current_config->name.link_m, \
13252 current_config->name.link_n, \
13253 pipe_config->name.tu, \
13254 pipe_config->name.gmch_m, \
13255 pipe_config->name.gmch_n, \
13256 pipe_config->name.link_m, \
13257 pipe_config->name.link_n); \
13261 /* This is required for BDW+ where there is only one set of registers for
13262 * switching between high and low RR.
13263 * This macro can be used whenever a comparison has to be made between one
13264 * hw state and multiple sw state variables.
13266 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \
13267 if (!intel_compare_link_m_n(¤t_config->name, \
13268 &pipe_config->name, adjust) && \
13269 !intel_compare_link_m_n(¤t_config->alt_name, \
13270 &pipe_config->name, adjust)) { \
13271 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
13272 "(expected tu %i gmch %i/%i link %i/%i, " \
13273 "or tu %i gmch %i/%i link %i/%i, " \
13274 "found tu %i, gmch %i/%i link %i/%i)\n", \
13275 current_config->name.tu, \
13276 current_config->name.gmch_m, \
13277 current_config->name.gmch_n, \
13278 current_config->name.link_m, \
13279 current_config->name.link_n, \
13280 current_config->alt_name.tu, \
13281 current_config->alt_name.gmch_m, \
13282 current_config->alt_name.gmch_n, \
13283 current_config->alt_name.link_m, \
13284 current_config->alt_name.link_n, \
13285 pipe_config->name.tu, \
13286 pipe_config->name.gmch_m, \
13287 pipe_config->name.gmch_n, \
13288 pipe_config->name.link_m, \
13289 pipe_config->name.link_n); \
13293 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
13294 if ((current_config->name ^ pipe_config->name) & (mask)) { \
13295 INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \
13296 "(expected %i, found %i)\n", \
13297 current_config->name & (mask), \
13298 pipe_config->name & (mask)); \
13302 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
13303 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
13304 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
13305 "(expected %i, found %i)\n", \
13306 current_config->name, \
13307 pipe_config->name); \
13311 #define PIPE_CONF_QUIRK(quirk) \
13312 ((current_config->quirks | pipe_config->quirks) & (quirk))
13314 PIPE_CONF_CHECK_I(cpu_transcoder
);
13316 PIPE_CONF_CHECK_I(has_pch_encoder
);
13317 PIPE_CONF_CHECK_I(fdi_lanes
);
13318 PIPE_CONF_CHECK_M_N(fdi_m_n
);
13320 PIPE_CONF_CHECK_I(lane_count
);
13321 PIPE_CONF_CHECK_X(lane_lat_optim_mask
);
13323 if (INTEL_INFO(dev
)->gen
< 8) {
13324 PIPE_CONF_CHECK_M_N(dp_m_n
);
13326 if (current_config
->has_drrs
)
13327 PIPE_CONF_CHECK_M_N(dp_m2_n2
);
13329 PIPE_CONF_CHECK_M_N_ALT(dp_m_n
, dp_m2_n2
);
13331 PIPE_CONF_CHECK_X(output_types
);
13333 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hdisplay
);
13334 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_htotal
);
13335 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_start
);
13336 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_end
);
13337 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_start
);
13338 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_end
);
13340 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vdisplay
);
13341 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vtotal
);
13342 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_start
);
13343 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_end
);
13344 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_start
);
13345 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_end
);
13347 PIPE_CONF_CHECK_I(pixel_multiplier
);
13348 PIPE_CONF_CHECK_I(has_hdmi_sink
);
13349 if ((INTEL_GEN(dev_priv
) < 8 && !IS_HASWELL(dev_priv
)) ||
13350 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
13351 PIPE_CONF_CHECK_I(limited_color_range
);
13352 PIPE_CONF_CHECK_I(has_infoframe
);
13354 PIPE_CONF_CHECK_I(has_audio
);
13356 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
13357 DRM_MODE_FLAG_INTERLACE
);
13359 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
13360 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
13361 DRM_MODE_FLAG_PHSYNC
);
13362 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
13363 DRM_MODE_FLAG_NHSYNC
);
13364 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
13365 DRM_MODE_FLAG_PVSYNC
);
13366 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
13367 DRM_MODE_FLAG_NVSYNC
);
13370 PIPE_CONF_CHECK_X(gmch_pfit
.control
);
13371 /* pfit ratios are autocomputed by the hw on gen4+ */
13372 if (INTEL_INFO(dev
)->gen
< 4)
13373 PIPE_CONF_CHECK_X(gmch_pfit
.pgm_ratios
);
13374 PIPE_CONF_CHECK_X(gmch_pfit
.lvds_border_bits
);
13377 PIPE_CONF_CHECK_I(pipe_src_w
);
13378 PIPE_CONF_CHECK_I(pipe_src_h
);
13380 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
13381 if (current_config
->pch_pfit
.enabled
) {
13382 PIPE_CONF_CHECK_X(pch_pfit
.pos
);
13383 PIPE_CONF_CHECK_X(pch_pfit
.size
);
13386 PIPE_CONF_CHECK_I(scaler_state
.scaler_id
);
13389 /* BDW+ don't expose a synchronous way to read the state */
13390 if (IS_HASWELL(dev_priv
))
13391 PIPE_CONF_CHECK_I(ips_enabled
);
13393 PIPE_CONF_CHECK_I(double_wide
);
13395 PIPE_CONF_CHECK_P(shared_dpll
);
13396 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
13397 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
13398 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
13399 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
13400 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
13401 PIPE_CONF_CHECK_X(dpll_hw_state
.spll
);
13402 PIPE_CONF_CHECK_X(dpll_hw_state
.ctrl1
);
13403 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr1
);
13404 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr2
);
13406 PIPE_CONF_CHECK_X(dsi_pll
.ctrl
);
13407 PIPE_CONF_CHECK_X(dsi_pll
.div
);
13409 if (IS_G4X(dev_priv
) || INTEL_GEN(dev_priv
) >= 5)
13410 PIPE_CONF_CHECK_I(pipe_bpp
);
13412 PIPE_CONF_CHECK_CLOCK_FUZZY(base
.adjusted_mode
.crtc_clock
);
13413 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
13415 #undef PIPE_CONF_CHECK_X
13416 #undef PIPE_CONF_CHECK_I
13417 #undef PIPE_CONF_CHECK_P
13418 #undef PIPE_CONF_CHECK_FLAGS
13419 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
13420 #undef PIPE_CONF_QUIRK
13421 #undef INTEL_ERR_OR_DBG_KMS
13426 static void intel_pipe_config_sanity_check(struct drm_i915_private
*dev_priv
,
13427 const struct intel_crtc_state
*pipe_config
)
13429 if (pipe_config
->has_pch_encoder
) {
13430 int fdi_dotclock
= intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
13431 &pipe_config
->fdi_m_n
);
13432 int dotclock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
13435 * FDI already provided one idea for the dotclock.
13436 * Yell if the encoder disagrees.
13438 WARN(!intel_fuzzy_clock_check(fdi_dotclock
, dotclock
),
13439 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
13440 fdi_dotclock
, dotclock
);
13444 static void verify_wm_state(struct drm_crtc
*crtc
,
13445 struct drm_crtc_state
*new_state
)
13447 struct drm_device
*dev
= crtc
->dev
;
13448 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13449 struct skl_ddb_allocation hw_ddb
, *sw_ddb
;
13450 struct skl_pipe_wm hw_wm
, *sw_wm
;
13451 struct skl_plane_wm
*hw_plane_wm
, *sw_plane_wm
;
13452 struct skl_ddb_entry
*hw_ddb_entry
, *sw_ddb_entry
;
13453 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13454 const enum pipe pipe
= intel_crtc
->pipe
;
13455 int plane
, level
, max_level
= ilk_wm_max_level(dev_priv
);
13457 if (INTEL_INFO(dev
)->gen
< 9 || !new_state
->active
)
13460 skl_pipe_wm_get_hw_state(crtc
, &hw_wm
);
13461 sw_wm
= &intel_crtc
->wm
.active
.skl
;
13463 skl_ddb_get_hw_state(dev_priv
, &hw_ddb
);
13464 sw_ddb
= &dev_priv
->wm
.skl_hw
.ddb
;
13467 for_each_universal_plane(dev_priv
, pipe
, plane
) {
13468 hw_plane_wm
= &hw_wm
.planes
[plane
];
13469 sw_plane_wm
= &sw_wm
->planes
[plane
];
13472 for (level
= 0; level
<= max_level
; level
++) {
13473 if (skl_wm_level_equals(&hw_plane_wm
->wm
[level
],
13474 &sw_plane_wm
->wm
[level
]))
13477 DRM_ERROR("mismatch in WM pipe %c plane %d level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13478 pipe_name(pipe
), plane
+ 1, level
,
13479 sw_plane_wm
->wm
[level
].plane_en
,
13480 sw_plane_wm
->wm
[level
].plane_res_b
,
13481 sw_plane_wm
->wm
[level
].plane_res_l
,
13482 hw_plane_wm
->wm
[level
].plane_en
,
13483 hw_plane_wm
->wm
[level
].plane_res_b
,
13484 hw_plane_wm
->wm
[level
].plane_res_l
);
13487 if (!skl_wm_level_equals(&hw_plane_wm
->trans_wm
,
13488 &sw_plane_wm
->trans_wm
)) {
13489 DRM_ERROR("mismatch in trans WM pipe %c plane %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13490 pipe_name(pipe
), plane
+ 1,
13491 sw_plane_wm
->trans_wm
.plane_en
,
13492 sw_plane_wm
->trans_wm
.plane_res_b
,
13493 sw_plane_wm
->trans_wm
.plane_res_l
,
13494 hw_plane_wm
->trans_wm
.plane_en
,
13495 hw_plane_wm
->trans_wm
.plane_res_b
,
13496 hw_plane_wm
->trans_wm
.plane_res_l
);
13500 hw_ddb_entry
= &hw_ddb
.plane
[pipe
][plane
];
13501 sw_ddb_entry
= &sw_ddb
->plane
[pipe
][plane
];
13503 if (!skl_ddb_entry_equal(hw_ddb_entry
, sw_ddb_entry
)) {
13504 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
13505 pipe_name(pipe
), plane
+ 1,
13506 sw_ddb_entry
->start
, sw_ddb_entry
->end
,
13507 hw_ddb_entry
->start
, hw_ddb_entry
->end
);
13513 * If the cursor plane isn't active, we may not have updated it's ddb
13514 * allocation. In that case since the ddb allocation will be updated
13515 * once the plane becomes visible, we can skip this check
13517 if (intel_crtc
->cursor_addr
) {
13518 hw_plane_wm
= &hw_wm
.planes
[PLANE_CURSOR
];
13519 sw_plane_wm
= &sw_wm
->planes
[PLANE_CURSOR
];
13522 for (level
= 0; level
<= max_level
; level
++) {
13523 if (skl_wm_level_equals(&hw_plane_wm
->wm
[level
],
13524 &sw_plane_wm
->wm
[level
]))
13527 DRM_ERROR("mismatch in WM pipe %c cursor level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13528 pipe_name(pipe
), level
,
13529 sw_plane_wm
->wm
[level
].plane_en
,
13530 sw_plane_wm
->wm
[level
].plane_res_b
,
13531 sw_plane_wm
->wm
[level
].plane_res_l
,
13532 hw_plane_wm
->wm
[level
].plane_en
,
13533 hw_plane_wm
->wm
[level
].plane_res_b
,
13534 hw_plane_wm
->wm
[level
].plane_res_l
);
13537 if (!skl_wm_level_equals(&hw_plane_wm
->trans_wm
,
13538 &sw_plane_wm
->trans_wm
)) {
13539 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13541 sw_plane_wm
->trans_wm
.plane_en
,
13542 sw_plane_wm
->trans_wm
.plane_res_b
,
13543 sw_plane_wm
->trans_wm
.plane_res_l
,
13544 hw_plane_wm
->trans_wm
.plane_en
,
13545 hw_plane_wm
->trans_wm
.plane_res_b
,
13546 hw_plane_wm
->trans_wm
.plane_res_l
);
13550 hw_ddb_entry
= &hw_ddb
.plane
[pipe
][PLANE_CURSOR
];
13551 sw_ddb_entry
= &sw_ddb
->plane
[pipe
][PLANE_CURSOR
];
13553 if (!skl_ddb_entry_equal(hw_ddb_entry
, sw_ddb_entry
)) {
13554 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
13556 sw_ddb_entry
->start
, sw_ddb_entry
->end
,
13557 hw_ddb_entry
->start
, hw_ddb_entry
->end
);
13563 verify_connector_state(struct drm_device
*dev
, struct drm_crtc
*crtc
)
13565 struct drm_connector
*connector
;
13567 drm_for_each_connector(connector
, dev
) {
13568 struct drm_encoder
*encoder
= connector
->encoder
;
13569 struct drm_connector_state
*state
= connector
->state
;
13571 if (state
->crtc
!= crtc
)
13574 intel_connector_verify_state(to_intel_connector(connector
));
13576 I915_STATE_WARN(state
->best_encoder
!= encoder
,
13577 "connector's atomic encoder doesn't match legacy encoder\n");
13582 verify_encoder_state(struct drm_device
*dev
)
13584 struct intel_encoder
*encoder
;
13585 struct intel_connector
*connector
;
13587 for_each_intel_encoder(dev
, encoder
) {
13588 bool enabled
= false;
13591 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
13592 encoder
->base
.base
.id
,
13593 encoder
->base
.name
);
13595 for_each_intel_connector(dev
, connector
) {
13596 if (connector
->base
.state
->best_encoder
!= &encoder
->base
)
13600 I915_STATE_WARN(connector
->base
.state
->crtc
!=
13601 encoder
->base
.crtc
,
13602 "connector's crtc doesn't match encoder crtc\n");
13605 I915_STATE_WARN(!!encoder
->base
.crtc
!= enabled
,
13606 "encoder's enabled state mismatch "
13607 "(expected %i, found %i)\n",
13608 !!encoder
->base
.crtc
, enabled
);
13610 if (!encoder
->base
.crtc
) {
13613 active
= encoder
->get_hw_state(encoder
, &pipe
);
13614 I915_STATE_WARN(active
,
13615 "encoder detached but still enabled on pipe %c.\n",
13622 verify_crtc_state(struct drm_crtc
*crtc
,
13623 struct drm_crtc_state
*old_crtc_state
,
13624 struct drm_crtc_state
*new_crtc_state
)
13626 struct drm_device
*dev
= crtc
->dev
;
13627 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13628 struct intel_encoder
*encoder
;
13629 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13630 struct intel_crtc_state
*pipe_config
, *sw_config
;
13631 struct drm_atomic_state
*old_state
;
13634 old_state
= old_crtc_state
->state
;
13635 __drm_atomic_helper_crtc_destroy_state(old_crtc_state
);
13636 pipe_config
= to_intel_crtc_state(old_crtc_state
);
13637 memset(pipe_config
, 0, sizeof(*pipe_config
));
13638 pipe_config
->base
.crtc
= crtc
;
13639 pipe_config
->base
.state
= old_state
;
13641 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc
->base
.id
, crtc
->name
);
13643 active
= dev_priv
->display
.get_pipe_config(intel_crtc
, pipe_config
);
13645 /* hw state is inconsistent with the pipe quirk */
13646 if ((intel_crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
13647 (intel_crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
13648 active
= new_crtc_state
->active
;
13650 I915_STATE_WARN(new_crtc_state
->active
!= active
,
13651 "crtc active state doesn't match with hw state "
13652 "(expected %i, found %i)\n", new_crtc_state
->active
, active
);
13654 I915_STATE_WARN(intel_crtc
->active
!= new_crtc_state
->active
,
13655 "transitional active state does not match atomic hw state "
13656 "(expected %i, found %i)\n", new_crtc_state
->active
, intel_crtc
->active
);
13658 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
13661 active
= encoder
->get_hw_state(encoder
, &pipe
);
13662 I915_STATE_WARN(active
!= new_crtc_state
->active
,
13663 "[ENCODER:%i] active %i with crtc active %i\n",
13664 encoder
->base
.base
.id
, active
, new_crtc_state
->active
);
13666 I915_STATE_WARN(active
&& intel_crtc
->pipe
!= pipe
,
13667 "Encoder connected to wrong pipe %c\n",
13671 pipe_config
->output_types
|= 1 << encoder
->type
;
13672 encoder
->get_config(encoder
, pipe_config
);
13676 if (!new_crtc_state
->active
)
13679 intel_pipe_config_sanity_check(dev_priv
, pipe_config
);
13681 sw_config
= to_intel_crtc_state(crtc
->state
);
13682 if (!intel_pipe_config_compare(dev
, sw_config
,
13683 pipe_config
, false)) {
13684 I915_STATE_WARN(1, "pipe state doesn't match!\n");
13685 intel_dump_pipe_config(intel_crtc
, pipe_config
,
13687 intel_dump_pipe_config(intel_crtc
, sw_config
,
13693 verify_single_dpll_state(struct drm_i915_private
*dev_priv
,
13694 struct intel_shared_dpll
*pll
,
13695 struct drm_crtc
*crtc
,
13696 struct drm_crtc_state
*new_state
)
13698 struct intel_dpll_hw_state dpll_hw_state
;
13699 unsigned crtc_mask
;
13702 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
13704 DRM_DEBUG_KMS("%s\n", pll
->name
);
13706 active
= pll
->funcs
.get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
13708 if (!(pll
->flags
& INTEL_DPLL_ALWAYS_ON
)) {
13709 I915_STATE_WARN(!pll
->on
&& pll
->active_mask
,
13710 "pll in active use but not on in sw tracking\n");
13711 I915_STATE_WARN(pll
->on
&& !pll
->active_mask
,
13712 "pll is on but not used by any active crtc\n");
13713 I915_STATE_WARN(pll
->on
!= active
,
13714 "pll on state mismatch (expected %i, found %i)\n",
13719 I915_STATE_WARN(pll
->active_mask
& ~pll
->config
.crtc_mask
,
13720 "more active pll users than references: %x vs %x\n",
13721 pll
->active_mask
, pll
->config
.crtc_mask
);
13726 crtc_mask
= 1 << drm_crtc_index(crtc
);
13728 if (new_state
->active
)
13729 I915_STATE_WARN(!(pll
->active_mask
& crtc_mask
),
13730 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
13731 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
13733 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
13734 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
13735 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
13737 I915_STATE_WARN(!(pll
->config
.crtc_mask
& crtc_mask
),
13738 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
13739 crtc_mask
, pll
->config
.crtc_mask
);
13741 I915_STATE_WARN(pll
->on
&& memcmp(&pll
->config
.hw_state
,
13743 sizeof(dpll_hw_state
)),
13744 "pll hw state mismatch\n");
13748 verify_shared_dpll_state(struct drm_device
*dev
, struct drm_crtc
*crtc
,
13749 struct drm_crtc_state
*old_crtc_state
,
13750 struct drm_crtc_state
*new_crtc_state
)
13752 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13753 struct intel_crtc_state
*old_state
= to_intel_crtc_state(old_crtc_state
);
13754 struct intel_crtc_state
*new_state
= to_intel_crtc_state(new_crtc_state
);
13756 if (new_state
->shared_dpll
)
13757 verify_single_dpll_state(dev_priv
, new_state
->shared_dpll
, crtc
, new_crtc_state
);
13759 if (old_state
->shared_dpll
&&
13760 old_state
->shared_dpll
!= new_state
->shared_dpll
) {
13761 unsigned crtc_mask
= 1 << drm_crtc_index(crtc
);
13762 struct intel_shared_dpll
*pll
= old_state
->shared_dpll
;
13764 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
13765 "pll active mismatch (didn't expect pipe %c in active mask)\n",
13766 pipe_name(drm_crtc_index(crtc
)));
13767 I915_STATE_WARN(pll
->config
.crtc_mask
& crtc_mask
,
13768 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
13769 pipe_name(drm_crtc_index(crtc
)));
13774 intel_modeset_verify_crtc(struct drm_crtc
*crtc
,
13775 struct drm_crtc_state
*old_state
,
13776 struct drm_crtc_state
*new_state
)
13778 if (!needs_modeset(new_state
) &&
13779 !to_intel_crtc_state(new_state
)->update_pipe
)
13782 verify_wm_state(crtc
, new_state
);
13783 verify_connector_state(crtc
->dev
, crtc
);
13784 verify_crtc_state(crtc
, old_state
, new_state
);
13785 verify_shared_dpll_state(crtc
->dev
, crtc
, old_state
, new_state
);
13789 verify_disabled_dpll_state(struct drm_device
*dev
)
13791 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13794 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++)
13795 verify_single_dpll_state(dev_priv
, &dev_priv
->shared_dplls
[i
], NULL
, NULL
);
13799 intel_modeset_verify_disabled(struct drm_device
*dev
)
13801 verify_encoder_state(dev
);
13802 verify_connector_state(dev
, NULL
);
13803 verify_disabled_dpll_state(dev
);
13806 static void update_scanline_offset(struct intel_crtc
*crtc
)
13808 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
13811 * The scanline counter increments at the leading edge of hsync.
13813 * On most platforms it starts counting from vtotal-1 on the
13814 * first active line. That means the scanline counter value is
13815 * always one less than what we would expect. Ie. just after
13816 * start of vblank, which also occurs at start of hsync (on the
13817 * last active line), the scanline counter will read vblank_start-1.
13819 * On gen2 the scanline counter starts counting from 1 instead
13820 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
13821 * to keep the value positive), instead of adding one.
13823 * On HSW+ the behaviour of the scanline counter depends on the output
13824 * type. For DP ports it behaves like most other platforms, but on HDMI
13825 * there's an extra 1 line difference. So we need to add two instead of
13826 * one to the value.
13828 if (IS_GEN2(dev_priv
)) {
13829 const struct drm_display_mode
*adjusted_mode
= &crtc
->config
->base
.adjusted_mode
;
13832 vtotal
= adjusted_mode
->crtc_vtotal
;
13833 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
13836 crtc
->scanline_offset
= vtotal
- 1;
13837 } else if (HAS_DDI(dev_priv
) &&
13838 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_HDMI
)) {
13839 crtc
->scanline_offset
= 2;
13841 crtc
->scanline_offset
= 1;
13844 static void intel_modeset_clear_plls(struct drm_atomic_state
*state
)
13846 struct drm_device
*dev
= state
->dev
;
13847 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13848 struct intel_shared_dpll_config
*shared_dpll
= NULL
;
13849 struct drm_crtc
*crtc
;
13850 struct drm_crtc_state
*crtc_state
;
13853 if (!dev_priv
->display
.crtc_compute_clock
)
13856 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
13857 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13858 struct intel_shared_dpll
*old_dpll
=
13859 to_intel_crtc_state(crtc
->state
)->shared_dpll
;
13861 if (!needs_modeset(crtc_state
))
13864 to_intel_crtc_state(crtc_state
)->shared_dpll
= NULL
;
13870 shared_dpll
= intel_atomic_get_shared_dpll_state(state
);
13872 intel_shared_dpll_config_put(shared_dpll
, old_dpll
, intel_crtc
);
13877 * This implements the workaround described in the "notes" section of the mode
13878 * set sequence documentation. When going from no pipes or single pipe to
13879 * multiple pipes, and planes are enabled after the pipe, we need to wait at
13880 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
13882 static int haswell_mode_set_planes_workaround(struct drm_atomic_state
*state
)
13884 struct drm_crtc_state
*crtc_state
;
13885 struct intel_crtc
*intel_crtc
;
13886 struct drm_crtc
*crtc
;
13887 struct intel_crtc_state
*first_crtc_state
= NULL
;
13888 struct intel_crtc_state
*other_crtc_state
= NULL
;
13889 enum pipe first_pipe
= INVALID_PIPE
, enabled_pipe
= INVALID_PIPE
;
13892 /* look at all crtc's that are going to be enabled in during modeset */
13893 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
13894 intel_crtc
= to_intel_crtc(crtc
);
13896 if (!crtc_state
->active
|| !needs_modeset(crtc_state
))
13899 if (first_crtc_state
) {
13900 other_crtc_state
= to_intel_crtc_state(crtc_state
);
13903 first_crtc_state
= to_intel_crtc_state(crtc_state
);
13904 first_pipe
= intel_crtc
->pipe
;
13908 /* No workaround needed? */
13909 if (!first_crtc_state
)
13912 /* w/a possibly needed, check how many crtc's are already enabled. */
13913 for_each_intel_crtc(state
->dev
, intel_crtc
) {
13914 struct intel_crtc_state
*pipe_config
;
13916 pipe_config
= intel_atomic_get_crtc_state(state
, intel_crtc
);
13917 if (IS_ERR(pipe_config
))
13918 return PTR_ERR(pipe_config
);
13920 pipe_config
->hsw_workaround_pipe
= INVALID_PIPE
;
13922 if (!pipe_config
->base
.active
||
13923 needs_modeset(&pipe_config
->base
))
13926 /* 2 or more enabled crtcs means no need for w/a */
13927 if (enabled_pipe
!= INVALID_PIPE
)
13930 enabled_pipe
= intel_crtc
->pipe
;
13933 if (enabled_pipe
!= INVALID_PIPE
)
13934 first_crtc_state
->hsw_workaround_pipe
= enabled_pipe
;
13935 else if (other_crtc_state
)
13936 other_crtc_state
->hsw_workaround_pipe
= first_pipe
;
13941 static int intel_modeset_all_pipes(struct drm_atomic_state
*state
)
13943 struct drm_crtc
*crtc
;
13944 struct drm_crtc_state
*crtc_state
;
13947 /* add all active pipes to the state */
13948 for_each_crtc(state
->dev
, crtc
) {
13949 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
13950 if (IS_ERR(crtc_state
))
13951 return PTR_ERR(crtc_state
);
13953 if (!crtc_state
->active
|| needs_modeset(crtc_state
))
13956 crtc_state
->mode_changed
= true;
13958 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
13962 ret
= drm_atomic_add_affected_planes(state
, crtc
);
13970 static int intel_modeset_checks(struct drm_atomic_state
*state
)
13972 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
13973 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
13974 struct drm_crtc
*crtc
;
13975 struct drm_crtc_state
*crtc_state
;
13978 if (!check_digital_port_conflicts(state
)) {
13979 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
13983 intel_state
->modeset
= true;
13984 intel_state
->active_crtcs
= dev_priv
->active_crtcs
;
13986 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
13987 if (crtc_state
->active
)
13988 intel_state
->active_crtcs
|= 1 << i
;
13990 intel_state
->active_crtcs
&= ~(1 << i
);
13992 if (crtc_state
->active
!= crtc
->state
->active
)
13993 intel_state
->active_pipe_changes
|= drm_crtc_mask(crtc
);
13997 * See if the config requires any additional preparation, e.g.
13998 * to adjust global state with pipes off. We need to do this
13999 * here so we can get the modeset_pipe updated config for the new
14000 * mode set on this crtc. For other crtcs we need to use the
14001 * adjusted_mode bits in the crtc directly.
14003 if (dev_priv
->display
.modeset_calc_cdclk
) {
14004 if (!intel_state
->cdclk_pll_vco
)
14005 intel_state
->cdclk_pll_vco
= dev_priv
->cdclk_pll
.vco
;
14006 if (!intel_state
->cdclk_pll_vco
)
14007 intel_state
->cdclk_pll_vco
= dev_priv
->skl_preferred_vco_freq
;
14009 ret
= dev_priv
->display
.modeset_calc_cdclk(state
);
14013 if (intel_state
->dev_cdclk
!= dev_priv
->cdclk_freq
||
14014 intel_state
->cdclk_pll_vco
!= dev_priv
->cdclk_pll
.vco
)
14015 ret
= intel_modeset_all_pipes(state
);
14020 DRM_DEBUG_KMS("New cdclk calculated to be atomic %u, actual %u\n",
14021 intel_state
->cdclk
, intel_state
->dev_cdclk
);
14023 to_intel_atomic_state(state
)->cdclk
= dev_priv
->atomic_cdclk_freq
;
14025 intel_modeset_clear_plls(state
);
14027 if (IS_HASWELL(dev_priv
))
14028 return haswell_mode_set_planes_workaround(state
);
14034 * Handle calculation of various watermark data at the end of the atomic check
14035 * phase. The code here should be run after the per-crtc and per-plane 'check'
14036 * handlers to ensure that all derived state has been updated.
14038 static int calc_watermark_data(struct drm_atomic_state
*state
)
14040 struct drm_device
*dev
= state
->dev
;
14041 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14043 /* Is there platform-specific watermark information to calculate? */
14044 if (dev_priv
->display
.compute_global_watermarks
)
14045 return dev_priv
->display
.compute_global_watermarks(state
);
14051 * intel_atomic_check - validate state object
14053 * @state: state to validate
14055 static int intel_atomic_check(struct drm_device
*dev
,
14056 struct drm_atomic_state
*state
)
14058 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14059 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
14060 struct drm_crtc
*crtc
;
14061 struct drm_crtc_state
*crtc_state
;
14063 bool any_ms
= false;
14065 ret
= drm_atomic_helper_check_modeset(dev
, state
);
14069 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
14070 struct intel_crtc_state
*pipe_config
=
14071 to_intel_crtc_state(crtc_state
);
14073 /* Catch I915_MODE_FLAG_INHERITED */
14074 if (crtc_state
->mode
.private_flags
!= crtc
->state
->mode
.private_flags
)
14075 crtc_state
->mode_changed
= true;
14077 if (!needs_modeset(crtc_state
))
14080 if (!crtc_state
->enable
) {
14085 /* FIXME: For only active_changed we shouldn't need to do any
14086 * state recomputation at all. */
14088 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
14092 ret
= intel_modeset_pipe_config(crtc
, pipe_config
);
14094 intel_dump_pipe_config(to_intel_crtc(crtc
),
14095 pipe_config
, "[failed]");
14099 if (i915
.fastboot
&&
14100 intel_pipe_config_compare(dev
,
14101 to_intel_crtc_state(crtc
->state
),
14102 pipe_config
, true)) {
14103 crtc_state
->mode_changed
= false;
14104 to_intel_crtc_state(crtc_state
)->update_pipe
= true;
14107 if (needs_modeset(crtc_state
))
14110 ret
= drm_atomic_add_affected_planes(state
, crtc
);
14114 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
14115 needs_modeset(crtc_state
) ?
14116 "[modeset]" : "[fastset]");
14120 ret
= intel_modeset_checks(state
);
14125 intel_state
->cdclk
= dev_priv
->cdclk_freq
;
14127 ret
= drm_atomic_helper_check_planes(dev
, state
);
14131 intel_fbc_choose_crtc(dev_priv
, state
);
14132 return calc_watermark_data(state
);
14135 static int intel_atomic_prepare_commit(struct drm_device
*dev
,
14136 struct drm_atomic_state
*state
)
14138 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14139 struct drm_crtc_state
*crtc_state
;
14140 struct drm_crtc
*crtc
;
14143 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
14144 if (state
->legacy_cursor_update
)
14147 ret
= intel_crtc_wait_for_pending_flips(crtc
);
14151 if (atomic_read(&to_intel_crtc(crtc
)->unpin_work_count
) >= 2)
14152 flush_workqueue(dev_priv
->wq
);
14155 ret
= mutex_lock_interruptible(&dev
->struct_mutex
);
14159 ret
= drm_atomic_helper_prepare_planes(dev
, state
);
14160 mutex_unlock(&dev
->struct_mutex
);
14165 u32
intel_crtc_get_vblank_counter(struct intel_crtc
*crtc
)
14167 struct drm_device
*dev
= crtc
->base
.dev
;
14169 if (!dev
->max_vblank_count
)
14170 return drm_accurate_vblank_count(&crtc
->base
);
14172 return dev
->driver
->get_vblank_counter(dev
, crtc
->pipe
);
14175 static void intel_atomic_wait_for_vblanks(struct drm_device
*dev
,
14176 struct drm_i915_private
*dev_priv
,
14177 unsigned crtc_mask
)
14179 unsigned last_vblank_count
[I915_MAX_PIPES
];
14186 for_each_pipe(dev_priv
, pipe
) {
14187 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
14189 if (!((1 << pipe
) & crtc_mask
))
14192 ret
= drm_crtc_vblank_get(crtc
);
14193 if (WARN_ON(ret
!= 0)) {
14194 crtc_mask
&= ~(1 << pipe
);
14198 last_vblank_count
[pipe
] = drm_crtc_vblank_count(crtc
);
14201 for_each_pipe(dev_priv
, pipe
) {
14202 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
14205 if (!((1 << pipe
) & crtc_mask
))
14208 lret
= wait_event_timeout(dev
->vblank
[pipe
].queue
,
14209 last_vblank_count
[pipe
] !=
14210 drm_crtc_vblank_count(crtc
),
14211 msecs_to_jiffies(50));
14213 WARN(!lret
, "pipe %c vblank wait timed out\n", pipe_name(pipe
));
14215 drm_crtc_vblank_put(crtc
);
14219 static bool needs_vblank_wait(struct intel_crtc_state
*crtc_state
)
14221 /* fb updated, need to unpin old fb */
14222 if (crtc_state
->fb_changed
)
14225 /* wm changes, need vblank before final wm's */
14226 if (crtc_state
->update_wm_post
)
14230 * cxsr is re-enabled after vblank.
14231 * This is already handled by crtc_state->update_wm_post,
14232 * but added for clarity.
14234 if (crtc_state
->disable_cxsr
)
14240 static void intel_update_crtc(struct drm_crtc
*crtc
,
14241 struct drm_atomic_state
*state
,
14242 struct drm_crtc_state
*old_crtc_state
,
14243 unsigned int *crtc_vblank_mask
)
14245 struct drm_device
*dev
= crtc
->dev
;
14246 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14247 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
14248 struct intel_crtc_state
*pipe_config
= to_intel_crtc_state(crtc
->state
);
14249 bool modeset
= needs_modeset(crtc
->state
);
14252 update_scanline_offset(intel_crtc
);
14253 dev_priv
->display
.crtc_enable(pipe_config
, state
);
14255 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
));
14258 if (drm_atomic_get_existing_plane_state(state
, crtc
->primary
)) {
14260 intel_crtc
, pipe_config
,
14261 to_intel_plane_state(crtc
->primary
->state
));
14264 drm_atomic_helper_commit_planes_on_crtc(old_crtc_state
);
14266 if (needs_vblank_wait(pipe_config
))
14267 *crtc_vblank_mask
|= drm_crtc_mask(crtc
);
14270 static void intel_update_crtcs(struct drm_atomic_state
*state
,
14271 unsigned int *crtc_vblank_mask
)
14273 struct drm_crtc
*crtc
;
14274 struct drm_crtc_state
*old_crtc_state
;
14277 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
14278 if (!crtc
->state
->active
)
14281 intel_update_crtc(crtc
, state
, old_crtc_state
,
14286 static void skl_update_crtcs(struct drm_atomic_state
*state
,
14287 unsigned int *crtc_vblank_mask
)
14289 struct drm_device
*dev
= state
->dev
;
14290 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
14291 struct drm_crtc
*crtc
;
14292 struct intel_crtc
*intel_crtc
;
14293 struct drm_crtc_state
*old_crtc_state
;
14294 struct intel_crtc_state
*cstate
;
14295 unsigned int updated
= 0;
14300 * Whenever the number of active pipes changes, we need to make sure we
14301 * update the pipes in the right order so that their ddb allocations
14302 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
14303 * cause pipe underruns and other bad stuff.
14309 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
14310 bool vbl_wait
= false;
14311 unsigned int cmask
= drm_crtc_mask(crtc
);
14313 intel_crtc
= to_intel_crtc(crtc
);
14314 cstate
= to_intel_crtc_state(crtc
->state
);
14315 pipe
= intel_crtc
->pipe
;
14317 if (updated
& cmask
|| !crtc
->state
->active
)
14319 if (skl_ddb_allocation_overlaps(state
, intel_crtc
))
14325 * If this is an already active pipe, it's DDB changed,
14326 * and this isn't the last pipe that needs updating
14327 * then we need to wait for a vblank to pass for the
14328 * new ddb allocation to take effect.
14330 if (!skl_ddb_entry_equal(&cstate
->wm
.skl
.ddb
,
14331 &intel_crtc
->hw_ddb
) &&
14332 !crtc
->state
->active_changed
&&
14333 intel_state
->wm_results
.dirty_pipes
!= updated
)
14336 intel_update_crtc(crtc
, state
, old_crtc_state
,
14340 intel_wait_for_vblank(dev
, pipe
);
14344 } while (progress
);
14347 static void intel_atomic_commit_tail(struct drm_atomic_state
*state
)
14349 struct drm_device
*dev
= state
->dev
;
14350 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
14351 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14352 struct drm_crtc_state
*old_crtc_state
;
14353 struct drm_crtc
*crtc
;
14354 struct intel_crtc_state
*intel_cstate
;
14355 bool hw_check
= intel_state
->modeset
;
14356 unsigned long put_domains
[I915_MAX_PIPES
] = {};
14357 unsigned crtc_vblank_mask
= 0;
14360 drm_atomic_helper_wait_for_dependencies(state
);
14362 if (intel_state
->modeset
) {
14363 memcpy(dev_priv
->min_pixclk
, intel_state
->min_pixclk
,
14364 sizeof(intel_state
->min_pixclk
));
14365 dev_priv
->active_crtcs
= intel_state
->active_crtcs
;
14366 dev_priv
->atomic_cdclk_freq
= intel_state
->cdclk
;
14368 intel_display_power_get(dev_priv
, POWER_DOMAIN_MODESET
);
14371 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
14372 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
14374 if (needs_modeset(crtc
->state
) ||
14375 to_intel_crtc_state(crtc
->state
)->update_pipe
) {
14378 put_domains
[to_intel_crtc(crtc
)->pipe
] =
14379 modeset_get_crtc_power_domains(crtc
,
14380 to_intel_crtc_state(crtc
->state
));
14383 if (!needs_modeset(crtc
->state
))
14386 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
));
14388 if (old_crtc_state
->active
) {
14389 intel_crtc_disable_planes(crtc
, old_crtc_state
->plane_mask
);
14390 dev_priv
->display
.crtc_disable(to_intel_crtc_state(old_crtc_state
), state
);
14391 intel_crtc
->active
= false;
14392 intel_fbc_disable(intel_crtc
);
14393 intel_disable_shared_dpll(intel_crtc
);
14396 * Underruns don't always raise
14397 * interrupts, so check manually.
14399 intel_check_cpu_fifo_underruns(dev_priv
);
14400 intel_check_pch_fifo_underruns(dev_priv
);
14402 if (!crtc
->state
->active
)
14403 intel_update_watermarks(crtc
);
14407 /* Only after disabling all output pipelines that will be changed can we
14408 * update the the output configuration. */
14409 intel_modeset_update_crtc_state(state
);
14411 if (intel_state
->modeset
) {
14412 drm_atomic_helper_update_legacy_modeset_state(state
->dev
, state
);
14414 if (dev_priv
->display
.modeset_commit_cdclk
&&
14415 (intel_state
->dev_cdclk
!= dev_priv
->cdclk_freq
||
14416 intel_state
->cdclk_pll_vco
!= dev_priv
->cdclk_pll
.vco
))
14417 dev_priv
->display
.modeset_commit_cdclk(state
);
14420 * SKL workaround: bspec recommends we disable the SAGV when we
14421 * have more then one pipe enabled
14423 if (!intel_can_enable_sagv(state
))
14424 intel_disable_sagv(dev_priv
);
14426 intel_modeset_verify_disabled(dev
);
14429 /* Complete the events for pipes that have now been disabled */
14430 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
14431 bool modeset
= needs_modeset(crtc
->state
);
14433 /* Complete events for now disable pipes here. */
14434 if (modeset
&& !crtc
->state
->active
&& crtc
->state
->event
) {
14435 spin_lock_irq(&dev
->event_lock
);
14436 drm_crtc_send_vblank_event(crtc
, crtc
->state
->event
);
14437 spin_unlock_irq(&dev
->event_lock
);
14439 crtc
->state
->event
= NULL
;
14443 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
14444 dev_priv
->display
.update_crtcs(state
, &crtc_vblank_mask
);
14446 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
14447 * already, but still need the state for the delayed optimization. To
14449 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
14450 * - schedule that vblank worker _before_ calling hw_done
14451 * - at the start of commit_tail, cancel it _synchrously
14452 * - switch over to the vblank wait helper in the core after that since
14453 * we don't need out special handling any more.
14455 if (!state
->legacy_cursor_update
)
14456 intel_atomic_wait_for_vblanks(dev
, dev_priv
, crtc_vblank_mask
);
14459 * Now that the vblank has passed, we can go ahead and program the
14460 * optimal watermarks on platforms that need two-step watermark
14463 * TODO: Move this (and other cleanup) to an async worker eventually.
14465 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
14466 intel_cstate
= to_intel_crtc_state(crtc
->state
);
14468 if (dev_priv
->display
.optimize_watermarks
)
14469 dev_priv
->display
.optimize_watermarks(intel_cstate
);
14472 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
14473 intel_post_plane_update(to_intel_crtc_state(old_crtc_state
));
14475 if (put_domains
[i
])
14476 modeset_put_power_domains(dev_priv
, put_domains
[i
]);
14478 intel_modeset_verify_crtc(crtc
, old_crtc_state
, crtc
->state
);
14481 if (intel_state
->modeset
&& intel_can_enable_sagv(state
))
14482 intel_enable_sagv(dev_priv
);
14484 drm_atomic_helper_commit_hw_done(state
);
14486 if (intel_state
->modeset
)
14487 intel_display_power_put(dev_priv
, POWER_DOMAIN_MODESET
);
14489 mutex_lock(&dev
->struct_mutex
);
14490 drm_atomic_helper_cleanup_planes(dev
, state
);
14491 mutex_unlock(&dev
->struct_mutex
);
14493 drm_atomic_helper_commit_cleanup_done(state
);
14495 drm_atomic_state_put(state
);
14497 /* As one of the primary mmio accessors, KMS has a high likelihood
14498 * of triggering bugs in unclaimed access. After we finish
14499 * modesetting, see if an error has been flagged, and if so
14500 * enable debugging for the next modeset - and hope we catch
14503 * XXX note that we assume display power is on at this point.
14504 * This might hold true now but we need to add pm helper to check
14505 * unclaimed only when the hardware is on, as atomic commits
14506 * can happen also when the device is completely off.
14508 intel_uncore_arm_unclaimed_mmio_detection(dev_priv
);
14511 static void intel_atomic_commit_work(struct work_struct
*work
)
14513 struct drm_atomic_state
*state
=
14514 container_of(work
, struct drm_atomic_state
, commit_work
);
14516 intel_atomic_commit_tail(state
);
14519 static int __i915_sw_fence_call
14520 intel_atomic_commit_ready(struct i915_sw_fence
*fence
,
14521 enum i915_sw_fence_notify notify
)
14523 struct intel_atomic_state
*state
=
14524 container_of(fence
, struct intel_atomic_state
, commit_ready
);
14527 case FENCE_COMPLETE
:
14528 if (state
->base
.commit_work
.func
)
14529 queue_work(system_unbound_wq
, &state
->base
.commit_work
);
14533 drm_atomic_state_put(&state
->base
);
14537 return NOTIFY_DONE
;
14540 static void intel_atomic_track_fbs(struct drm_atomic_state
*state
)
14542 struct drm_plane_state
*old_plane_state
;
14543 struct drm_plane
*plane
;
14546 for_each_plane_in_state(state
, plane
, old_plane_state
, i
)
14547 i915_gem_track_fb(intel_fb_obj(old_plane_state
->fb
),
14548 intel_fb_obj(plane
->state
->fb
),
14549 to_intel_plane(plane
)->frontbuffer_bit
);
14553 * intel_atomic_commit - commit validated state object
14555 * @state: the top-level driver state object
14556 * @nonblock: nonblocking commit
14558 * This function commits a top-level state object that has been validated
14559 * with drm_atomic_helper_check().
14561 * FIXME: Atomic modeset support for i915 is not yet complete. At the moment
14562 * nonblocking commits are only safe for pure plane updates. Everything else
14563 * should work though.
14566 * Zero for success or -errno.
14568 static int intel_atomic_commit(struct drm_device
*dev
,
14569 struct drm_atomic_state
*state
,
14572 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
14573 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14576 if (intel_state
->modeset
&& nonblock
) {
14577 DRM_DEBUG_KMS("nonblocking commit for modeset not yet implemented.\n");
14581 ret
= drm_atomic_helper_setup_commit(state
, nonblock
);
14585 drm_atomic_state_get(state
);
14586 i915_sw_fence_init(&intel_state
->commit_ready
,
14587 intel_atomic_commit_ready
);
14589 ret
= intel_atomic_prepare_commit(dev
, state
);
14591 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret
);
14592 i915_sw_fence_commit(&intel_state
->commit_ready
);
14596 drm_atomic_helper_swap_state(state
, true);
14597 dev_priv
->wm
.distrust_bios_wm
= false;
14598 dev_priv
->wm
.skl_results
= intel_state
->wm_results
;
14599 intel_shared_dpll_commit(state
);
14600 intel_atomic_track_fbs(state
);
14602 drm_atomic_state_get(state
);
14603 INIT_WORK(&state
->commit_work
,
14604 nonblock
? intel_atomic_commit_work
: NULL
);
14606 i915_sw_fence_commit(&intel_state
->commit_ready
);
14608 i915_sw_fence_wait(&intel_state
->commit_ready
);
14609 intel_atomic_commit_tail(state
);
14615 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
14617 struct drm_device
*dev
= crtc
->dev
;
14618 struct drm_atomic_state
*state
;
14619 struct drm_crtc_state
*crtc_state
;
14622 state
= drm_atomic_state_alloc(dev
);
14624 DRM_DEBUG_KMS("[CRTC:%d:%s] crtc restore failed, out of memory",
14625 crtc
->base
.id
, crtc
->name
);
14629 state
->acquire_ctx
= drm_modeset_legacy_acquire_ctx(crtc
);
14632 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
14633 ret
= PTR_ERR_OR_ZERO(crtc_state
);
14635 if (!crtc_state
->active
)
14638 crtc_state
->mode_changed
= true;
14639 ret
= drm_atomic_commit(state
);
14642 if (ret
== -EDEADLK
) {
14643 drm_atomic_state_clear(state
);
14644 drm_modeset_backoff(state
->acquire_ctx
);
14649 drm_atomic_state_put(state
);
14653 * FIXME: Remove this once i915 is fully DRIVER_ATOMIC by calling
14654 * drm_atomic_helper_legacy_gamma_set() directly.
14656 static int intel_atomic_legacy_gamma_set(struct drm_crtc
*crtc
,
14657 u16
*red
, u16
*green
, u16
*blue
,
14660 struct drm_device
*dev
= crtc
->dev
;
14661 struct drm_mode_config
*config
= &dev
->mode_config
;
14662 struct drm_crtc_state
*state
;
14665 ret
= drm_atomic_helper_legacy_gamma_set(crtc
, red
, green
, blue
, size
);
14670 * Make sure we update the legacy properties so this works when
14671 * atomic is not enabled.
14674 state
= crtc
->state
;
14676 drm_object_property_set_value(&crtc
->base
,
14677 config
->degamma_lut_property
,
14678 (state
->degamma_lut
) ?
14679 state
->degamma_lut
->base
.id
: 0);
14681 drm_object_property_set_value(&crtc
->base
,
14682 config
->ctm_property
,
14684 state
->ctm
->base
.id
: 0);
14686 drm_object_property_set_value(&crtc
->base
,
14687 config
->gamma_lut_property
,
14688 (state
->gamma_lut
) ?
14689 state
->gamma_lut
->base
.id
: 0);
14694 static const struct drm_crtc_funcs intel_crtc_funcs
= {
14695 .gamma_set
= intel_atomic_legacy_gamma_set
,
14696 .set_config
= drm_atomic_helper_set_config
,
14697 .set_property
= drm_atomic_helper_crtc_set_property
,
14698 .destroy
= intel_crtc_destroy
,
14699 .page_flip
= intel_crtc_page_flip
,
14700 .atomic_duplicate_state
= intel_crtc_duplicate_state
,
14701 .atomic_destroy_state
= intel_crtc_destroy_state
,
14705 * intel_prepare_plane_fb - Prepare fb for usage on plane
14706 * @plane: drm plane to prepare for
14707 * @fb: framebuffer to prepare for presentation
14709 * Prepares a framebuffer for usage on a display plane. Generally this
14710 * involves pinning the underlying object and updating the frontbuffer tracking
14711 * bits. Some older platforms need special physical address handling for
14714 * Must be called with struct_mutex held.
14716 * Returns 0 on success, negative error code on failure.
14719 intel_prepare_plane_fb(struct drm_plane
*plane
,
14720 struct drm_plane_state
*new_state
)
14722 struct intel_atomic_state
*intel_state
=
14723 to_intel_atomic_state(new_state
->state
);
14724 struct drm_device
*dev
= plane
->dev
;
14725 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14726 struct drm_framebuffer
*fb
= new_state
->fb
;
14727 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
14728 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->state
->fb
);
14731 if (!obj
&& !old_obj
)
14735 struct drm_crtc_state
*crtc_state
=
14736 drm_atomic_get_existing_crtc_state(new_state
->state
,
14737 plane
->state
->crtc
);
14739 /* Big Hammer, we also need to ensure that any pending
14740 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
14741 * current scanout is retired before unpinning the old
14742 * framebuffer. Note that we rely on userspace rendering
14743 * into the buffer attached to the pipe they are waiting
14744 * on. If not, userspace generates a GPU hang with IPEHR
14745 * point to the MI_WAIT_FOR_EVENT.
14747 * This should only fail upon a hung GPU, in which case we
14748 * can safely continue.
14750 if (needs_modeset(crtc_state
)) {
14751 ret
= i915_sw_fence_await_reservation(&intel_state
->commit_ready
,
14752 old_obj
->resv
, NULL
,
14760 if (new_state
->fence
) { /* explicit fencing */
14761 ret
= i915_sw_fence_await_dma_fence(&intel_state
->commit_ready
,
14763 I915_FENCE_TIMEOUT
,
14772 if (!new_state
->fence
) { /* implicit fencing */
14773 ret
= i915_sw_fence_await_reservation(&intel_state
->commit_ready
,
14775 false, I915_FENCE_TIMEOUT
,
14781 if (plane
->type
== DRM_PLANE_TYPE_CURSOR
&&
14782 INTEL_INFO(dev
)->cursor_needs_physical
) {
14783 int align
= IS_I830(dev_priv
) ? 16 * 1024 : 256;
14784 ret
= i915_gem_object_attach_phys(obj
, align
);
14786 DRM_DEBUG_KMS("failed to attach phys object\n");
14790 struct i915_vma
*vma
;
14792 vma
= intel_pin_and_fence_fb_obj(fb
, new_state
->rotation
);
14794 DRM_DEBUG_KMS("failed to pin object\n");
14795 return PTR_ERR(vma
);
14803 * intel_cleanup_plane_fb - Cleans up an fb after plane use
14804 * @plane: drm plane to clean up for
14805 * @fb: old framebuffer that was on plane
14807 * Cleans up a framebuffer that has just been removed from a plane.
14809 * Must be called with struct_mutex held.
14812 intel_cleanup_plane_fb(struct drm_plane
*plane
,
14813 struct drm_plane_state
*old_state
)
14815 struct drm_device
*dev
= plane
->dev
;
14816 struct intel_plane_state
*old_intel_state
;
14817 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(old_state
->fb
);
14818 struct drm_i915_gem_object
*obj
= intel_fb_obj(plane
->state
->fb
);
14820 old_intel_state
= to_intel_plane_state(old_state
);
14822 if (!obj
&& !old_obj
)
14825 if (old_obj
&& (plane
->type
!= DRM_PLANE_TYPE_CURSOR
||
14826 !INTEL_INFO(dev
)->cursor_needs_physical
))
14827 intel_unpin_fb_obj(old_state
->fb
, old_state
->rotation
);
14831 skl_max_scale(struct intel_crtc
*intel_crtc
, struct intel_crtc_state
*crtc_state
)
14834 int crtc_clock
, cdclk
;
14836 if (!intel_crtc
|| !crtc_state
->base
.enable
)
14837 return DRM_PLANE_HELPER_NO_SCALING
;
14839 crtc_clock
= crtc_state
->base
.adjusted_mode
.crtc_clock
;
14840 cdclk
= to_intel_atomic_state(crtc_state
->base
.state
)->cdclk
;
14842 if (WARN_ON_ONCE(!crtc_clock
|| cdclk
< crtc_clock
))
14843 return DRM_PLANE_HELPER_NO_SCALING
;
14846 * skl max scale is lower of:
14847 * close to 3 but not 3, -1 is for that purpose
14851 max_scale
= min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk
<< 8) / crtc_clock
));
14857 intel_check_primary_plane(struct drm_plane
*plane
,
14858 struct intel_crtc_state
*crtc_state
,
14859 struct intel_plane_state
*state
)
14861 struct drm_i915_private
*dev_priv
= to_i915(plane
->dev
);
14862 struct drm_crtc
*crtc
= state
->base
.crtc
;
14863 int min_scale
= DRM_PLANE_HELPER_NO_SCALING
;
14864 int max_scale
= DRM_PLANE_HELPER_NO_SCALING
;
14865 bool can_position
= false;
14868 if (INTEL_GEN(dev_priv
) >= 9) {
14869 /* use scaler when colorkey is not required */
14870 if (state
->ckey
.flags
== I915_SET_COLORKEY_NONE
) {
14872 max_scale
= skl_max_scale(to_intel_crtc(crtc
), crtc_state
);
14874 can_position
= true;
14877 ret
= drm_plane_helper_check_state(&state
->base
,
14879 min_scale
, max_scale
,
14880 can_position
, true);
14884 if (!state
->base
.fb
)
14887 if (INTEL_GEN(dev_priv
) >= 9) {
14888 ret
= skl_check_plane_surface(state
);
14896 static void intel_begin_crtc_commit(struct drm_crtc
*crtc
,
14897 struct drm_crtc_state
*old_crtc_state
)
14899 struct drm_device
*dev
= crtc
->dev
;
14900 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14901 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
14902 struct intel_crtc_state
*intel_cstate
=
14903 to_intel_crtc_state(crtc
->state
);
14904 struct intel_crtc_state
*old_intel_state
=
14905 to_intel_crtc_state(old_crtc_state
);
14906 bool modeset
= needs_modeset(crtc
->state
);
14907 enum pipe pipe
= intel_crtc
->pipe
;
14909 /* Perform vblank evasion around commit operation */
14910 intel_pipe_update_start(intel_crtc
);
14915 if (crtc
->state
->color_mgmt_changed
|| to_intel_crtc_state(crtc
->state
)->update_pipe
) {
14916 intel_color_set_csc(crtc
->state
);
14917 intel_color_load_luts(crtc
->state
);
14920 if (intel_cstate
->update_pipe
) {
14921 intel_update_pipe_config(intel_crtc
, old_intel_state
);
14922 } else if (INTEL_GEN(dev_priv
) >= 9) {
14923 skl_detach_scalers(intel_crtc
);
14925 I915_WRITE(PIPE_WM_LINETIME(pipe
),
14926 intel_cstate
->wm
.skl
.optimal
.linetime
);
14930 static void intel_finish_crtc_commit(struct drm_crtc
*crtc
,
14931 struct drm_crtc_state
*old_crtc_state
)
14933 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
14935 intel_pipe_update_end(intel_crtc
, NULL
);
14939 * intel_plane_destroy - destroy a plane
14940 * @plane: plane to destroy
14942 * Common destruction function for all types of planes (primary, cursor,
14945 void intel_plane_destroy(struct drm_plane
*plane
)
14950 drm_plane_cleanup(plane
);
14951 kfree(to_intel_plane(plane
));
14954 const struct drm_plane_funcs intel_plane_funcs
= {
14955 .update_plane
= drm_atomic_helper_update_plane
,
14956 .disable_plane
= drm_atomic_helper_disable_plane
,
14957 .destroy
= intel_plane_destroy
,
14958 .set_property
= drm_atomic_helper_plane_set_property
,
14959 .atomic_get_property
= intel_plane_atomic_get_property
,
14960 .atomic_set_property
= intel_plane_atomic_set_property
,
14961 .atomic_duplicate_state
= intel_plane_duplicate_state
,
14962 .atomic_destroy_state
= intel_plane_destroy_state
,
14966 static struct drm_plane
*intel_primary_plane_create(struct drm_device
*dev
,
14969 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14970 struct intel_plane
*primary
= NULL
;
14971 struct intel_plane_state
*state
= NULL
;
14972 const uint32_t *intel_primary_formats
;
14973 unsigned int supported_rotations
;
14974 unsigned int num_formats
;
14977 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
14981 state
= intel_create_plane_state(&primary
->base
);
14984 primary
->base
.state
= &state
->base
;
14986 primary
->can_scale
= false;
14987 primary
->max_downscale
= 1;
14988 if (INTEL_INFO(dev
)->gen
>= 9) {
14989 primary
->can_scale
= true;
14990 state
->scaler_id
= -1;
14992 primary
->pipe
= pipe
;
14993 primary
->plane
= pipe
;
14994 primary
->frontbuffer_bit
= INTEL_FRONTBUFFER_PRIMARY(pipe
);
14995 primary
->check_plane
= intel_check_primary_plane
;
14996 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4)
14997 primary
->plane
= !pipe
;
14999 if (INTEL_INFO(dev
)->gen
>= 9) {
15000 intel_primary_formats
= skl_primary_formats
;
15001 num_formats
= ARRAY_SIZE(skl_primary_formats
);
15003 primary
->update_plane
= skylake_update_primary_plane
;
15004 primary
->disable_plane
= skylake_disable_primary_plane
;
15005 } else if (HAS_PCH_SPLIT(dev_priv
)) {
15006 intel_primary_formats
= i965_primary_formats
;
15007 num_formats
= ARRAY_SIZE(i965_primary_formats
);
15009 primary
->update_plane
= ironlake_update_primary_plane
;
15010 primary
->disable_plane
= i9xx_disable_primary_plane
;
15011 } else if (INTEL_INFO(dev
)->gen
>= 4) {
15012 intel_primary_formats
= i965_primary_formats
;
15013 num_formats
= ARRAY_SIZE(i965_primary_formats
);
15015 primary
->update_plane
= i9xx_update_primary_plane
;
15016 primary
->disable_plane
= i9xx_disable_primary_plane
;
15018 intel_primary_formats
= i8xx_primary_formats
;
15019 num_formats
= ARRAY_SIZE(i8xx_primary_formats
);
15021 primary
->update_plane
= i9xx_update_primary_plane
;
15022 primary
->disable_plane
= i9xx_disable_primary_plane
;
15025 if (INTEL_INFO(dev
)->gen
>= 9)
15026 ret
= drm_universal_plane_init(dev
, &primary
->base
, 0,
15027 &intel_plane_funcs
,
15028 intel_primary_formats
, num_formats
,
15029 DRM_PLANE_TYPE_PRIMARY
,
15030 "plane 1%c", pipe_name(pipe
));
15031 else if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
))
15032 ret
= drm_universal_plane_init(dev
, &primary
->base
, 0,
15033 &intel_plane_funcs
,
15034 intel_primary_formats
, num_formats
,
15035 DRM_PLANE_TYPE_PRIMARY
,
15036 "primary %c", pipe_name(pipe
));
15038 ret
= drm_universal_plane_init(dev
, &primary
->base
, 0,
15039 &intel_plane_funcs
,
15040 intel_primary_formats
, num_formats
,
15041 DRM_PLANE_TYPE_PRIMARY
,
15042 "plane %c", plane_name(primary
->plane
));
15046 if (INTEL_GEN(dev_priv
) >= 9) {
15047 supported_rotations
=
15048 DRM_ROTATE_0
| DRM_ROTATE_90
|
15049 DRM_ROTATE_180
| DRM_ROTATE_270
;
15050 } else if (INTEL_GEN(dev_priv
) >= 4) {
15051 supported_rotations
=
15052 DRM_ROTATE_0
| DRM_ROTATE_180
;
15054 supported_rotations
= DRM_ROTATE_0
;
15057 if (INTEL_GEN(dev_priv
) >= 4)
15058 drm_plane_create_rotation_property(&primary
->base
,
15060 supported_rotations
);
15062 drm_plane_helper_add(&primary
->base
, &intel_plane_helper_funcs
);
15064 return &primary
->base
;
15074 intel_check_cursor_plane(struct drm_plane
*plane
,
15075 struct intel_crtc_state
*crtc_state
,
15076 struct intel_plane_state
*state
)
15078 struct drm_framebuffer
*fb
= state
->base
.fb
;
15079 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
15080 enum pipe pipe
= to_intel_plane(plane
)->pipe
;
15084 ret
= drm_plane_helper_check_state(&state
->base
,
15086 DRM_PLANE_HELPER_NO_SCALING
,
15087 DRM_PLANE_HELPER_NO_SCALING
,
15092 /* if we want to turn off the cursor ignore width and height */
15096 /* Check for which cursor types we support */
15097 if (!cursor_size_ok(to_i915(plane
->dev
), state
->base
.crtc_w
,
15098 state
->base
.crtc_h
)) {
15099 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
15100 state
->base
.crtc_w
, state
->base
.crtc_h
);
15104 stride
= roundup_pow_of_two(state
->base
.crtc_w
) * 4;
15105 if (obj
->base
.size
< stride
* state
->base
.crtc_h
) {
15106 DRM_DEBUG_KMS("buffer is too small\n");
15110 if (fb
->modifier
[0] != DRM_FORMAT_MOD_NONE
) {
15111 DRM_DEBUG_KMS("cursor cannot be tiled\n");
15116 * There's something wrong with the cursor on CHV pipe C.
15117 * If it straddles the left edge of the screen then
15118 * moving it away from the edge or disabling it often
15119 * results in a pipe underrun, and often that can lead to
15120 * dead pipe (constant underrun reported, and it scans
15121 * out just a solid color). To recover from that, the
15122 * display power well must be turned off and on again.
15123 * Refuse the put the cursor into that compromised position.
15125 if (IS_CHERRYVIEW(to_i915(plane
->dev
)) && pipe
== PIPE_C
&&
15126 state
->base
.visible
&& state
->base
.crtc_x
< 0) {
15127 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
15135 intel_disable_cursor_plane(struct drm_plane
*plane
,
15136 struct drm_crtc
*crtc
)
15138 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
15140 intel_crtc
->cursor_addr
= 0;
15141 intel_crtc_update_cursor(crtc
, NULL
);
15145 intel_update_cursor_plane(struct drm_plane
*plane
,
15146 const struct intel_crtc_state
*crtc_state
,
15147 const struct intel_plane_state
*state
)
15149 struct drm_crtc
*crtc
= crtc_state
->base
.crtc
;
15150 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
15151 struct drm_device
*dev
= plane
->dev
;
15152 struct drm_i915_gem_object
*obj
= intel_fb_obj(state
->base
.fb
);
15157 else if (!INTEL_INFO(dev
)->cursor_needs_physical
)
15158 addr
= i915_gem_object_ggtt_offset(obj
, NULL
);
15160 addr
= obj
->phys_handle
->busaddr
;
15162 intel_crtc
->cursor_addr
= addr
;
15163 intel_crtc_update_cursor(crtc
, state
);
15166 static struct drm_plane
*intel_cursor_plane_create(struct drm_device
*dev
,
15169 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15170 struct intel_plane
*cursor
= NULL
;
15171 struct intel_plane_state
*state
= NULL
;
15174 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
15178 state
= intel_create_plane_state(&cursor
->base
);
15181 cursor
->base
.state
= &state
->base
;
15183 cursor
->can_scale
= false;
15184 cursor
->max_downscale
= 1;
15185 cursor
->pipe
= pipe
;
15186 cursor
->plane
= pipe
;
15187 cursor
->frontbuffer_bit
= INTEL_FRONTBUFFER_CURSOR(pipe
);
15188 cursor
->check_plane
= intel_check_cursor_plane
;
15189 cursor
->update_plane
= intel_update_cursor_plane
;
15190 cursor
->disable_plane
= intel_disable_cursor_plane
;
15192 ret
= drm_universal_plane_init(dev
, &cursor
->base
, 0,
15193 &intel_plane_funcs
,
15194 intel_cursor_formats
,
15195 ARRAY_SIZE(intel_cursor_formats
),
15196 DRM_PLANE_TYPE_CURSOR
,
15197 "cursor %c", pipe_name(pipe
));
15201 if (INTEL_GEN(dev_priv
) >= 4)
15202 drm_plane_create_rotation_property(&cursor
->base
,
15207 if (INTEL_INFO(dev
)->gen
>=9)
15208 state
->scaler_id
= -1;
15210 drm_plane_helper_add(&cursor
->base
, &intel_plane_helper_funcs
);
15212 return &cursor
->base
;
15221 static void skl_init_scalers(struct drm_device
*dev
, struct intel_crtc
*intel_crtc
,
15222 struct intel_crtc_state
*crtc_state
)
15225 struct intel_scaler
*intel_scaler
;
15226 struct intel_crtc_scaler_state
*scaler_state
= &crtc_state
->scaler_state
;
15228 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
15229 intel_scaler
= &scaler_state
->scalers
[i
];
15230 intel_scaler
->in_use
= 0;
15231 intel_scaler
->mode
= PS_SCALER_MODE_DYN
;
15234 scaler_state
->scaler_id
= -1;
15237 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
15239 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15240 struct intel_crtc
*intel_crtc
;
15241 struct intel_crtc_state
*crtc_state
= NULL
;
15242 struct drm_plane
*primary
= NULL
;
15243 struct drm_plane
*cursor
= NULL
;
15246 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
15247 if (intel_crtc
== NULL
)
15250 crtc_state
= kzalloc(sizeof(*crtc_state
), GFP_KERNEL
);
15253 intel_crtc
->config
= crtc_state
;
15254 intel_crtc
->base
.state
= &crtc_state
->base
;
15255 crtc_state
->base
.crtc
= &intel_crtc
->base
;
15257 /* initialize shared scalers */
15258 if (INTEL_INFO(dev
)->gen
>= 9) {
15259 if (pipe
== PIPE_C
)
15260 intel_crtc
->num_scalers
= 1;
15262 intel_crtc
->num_scalers
= SKL_NUM_SCALERS
;
15264 skl_init_scalers(dev
, intel_crtc
, crtc_state
);
15267 primary
= intel_primary_plane_create(dev
, pipe
);
15271 cursor
= intel_cursor_plane_create(dev
, pipe
);
15275 ret
= drm_crtc_init_with_planes(dev
, &intel_crtc
->base
, primary
,
15276 cursor
, &intel_crtc_funcs
,
15277 "pipe %c", pipe_name(pipe
));
15282 * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
15283 * is hooked to pipe B. Hence we want plane A feeding pipe B.
15285 intel_crtc
->pipe
= pipe
;
15286 intel_crtc
->plane
= pipe
;
15287 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4) {
15288 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
15289 intel_crtc
->plane
= !pipe
;
15292 intel_crtc
->cursor_base
= ~0;
15293 intel_crtc
->cursor_cntl
= ~0;
15294 intel_crtc
->cursor_size
= ~0;
15296 intel_crtc
->wm
.cxsr_allowed
= true;
15298 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
15299 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
15300 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
15301 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
15303 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
15305 intel_color_init(&intel_crtc
->base
);
15307 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
15311 intel_plane_destroy(primary
);
15312 intel_plane_destroy(cursor
);
15317 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
15319 struct drm_encoder
*encoder
= connector
->base
.encoder
;
15320 struct drm_device
*dev
= connector
->base
.dev
;
15322 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
15324 if (!encoder
|| WARN_ON(!encoder
->crtc
))
15325 return INVALID_PIPE
;
15327 return to_intel_crtc(encoder
->crtc
)->pipe
;
15330 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
15331 struct drm_file
*file
)
15333 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
15334 struct drm_crtc
*drmmode_crtc
;
15335 struct intel_crtc
*crtc
;
15337 drmmode_crtc
= drm_crtc_find(dev
, pipe_from_crtc_id
->crtc_id
);
15341 crtc
= to_intel_crtc(drmmode_crtc
);
15342 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
15347 static int intel_encoder_clones(struct intel_encoder
*encoder
)
15349 struct drm_device
*dev
= encoder
->base
.dev
;
15350 struct intel_encoder
*source_encoder
;
15351 int index_mask
= 0;
15354 for_each_intel_encoder(dev
, source_encoder
) {
15355 if (encoders_cloneable(encoder
, source_encoder
))
15356 index_mask
|= (1 << entry
);
15364 static bool has_edp_a(struct drm_device
*dev
)
15366 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15368 if (!IS_MOBILE(dev
))
15371 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
15374 if (IS_GEN5(dev_priv
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
15380 static bool intel_crt_present(struct drm_device
*dev
)
15382 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15384 if (INTEL_INFO(dev
)->gen
>= 9)
15387 if (IS_HSW_ULT(dev_priv
) || IS_BDW_ULT(dev_priv
))
15390 if (IS_CHERRYVIEW(dev_priv
))
15393 if (HAS_PCH_LPT_H(dev_priv
) &&
15394 I915_READ(SFUSE_STRAP
) & SFUSE_STRAP_CRT_DISABLED
)
15397 /* DDI E can't be used if DDI A requires 4 lanes */
15398 if (HAS_DDI(dev_priv
) && I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_A_4_LANES
)
15401 if (!dev_priv
->vbt
.int_crt_support
)
15407 void intel_pps_unlock_regs_wa(struct drm_i915_private
*dev_priv
)
15412 if (HAS_DDI(dev_priv
))
15415 * This w/a is needed at least on CPT/PPT, but to be sure apply it
15416 * everywhere where registers can be write protected.
15418 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
15423 for (pps_idx
= 0; pps_idx
< pps_num
; pps_idx
++) {
15424 u32 val
= I915_READ(PP_CONTROL(pps_idx
));
15426 val
= (val
& ~PANEL_UNLOCK_MASK
) | PANEL_UNLOCK_REGS
;
15427 I915_WRITE(PP_CONTROL(pps_idx
), val
);
15431 static void intel_pps_init(struct drm_i915_private
*dev_priv
)
15433 if (HAS_PCH_SPLIT(dev_priv
) || IS_BROXTON(dev_priv
))
15434 dev_priv
->pps_mmio_base
= PCH_PPS_BASE
;
15435 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
15436 dev_priv
->pps_mmio_base
= VLV_PPS_BASE
;
15438 dev_priv
->pps_mmio_base
= PPS_BASE
;
15440 intel_pps_unlock_regs_wa(dev_priv
);
15443 static void intel_setup_outputs(struct drm_device
*dev
)
15445 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15446 struct intel_encoder
*encoder
;
15447 bool dpd_is_edp
= false;
15449 intel_pps_init(dev_priv
);
15452 * intel_edp_init_connector() depends on this completing first, to
15453 * prevent the registeration of both eDP and LVDS and the incorrect
15454 * sharing of the PPS.
15456 intel_lvds_init(dev
);
15458 if (intel_crt_present(dev
))
15459 intel_crt_init(dev
);
15461 if (IS_BROXTON(dev_priv
)) {
15463 * FIXME: Broxton doesn't support port detection via the
15464 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
15465 * detect the ports.
15467 intel_ddi_init(dev
, PORT_A
);
15468 intel_ddi_init(dev
, PORT_B
);
15469 intel_ddi_init(dev
, PORT_C
);
15471 intel_dsi_init(dev
);
15472 } else if (HAS_DDI(dev_priv
)) {
15476 * Haswell uses DDI functions to detect digital outputs.
15477 * On SKL pre-D0 the strap isn't connected, so we assume
15480 found
= I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_INIT_DISPLAY_DETECTED
;
15481 /* WaIgnoreDDIAStrap: skl */
15482 if (found
|| IS_SKYLAKE(dev_priv
) || IS_KABYLAKE(dev_priv
))
15483 intel_ddi_init(dev
, PORT_A
);
15485 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
15487 found
= I915_READ(SFUSE_STRAP
);
15489 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
15490 intel_ddi_init(dev
, PORT_B
);
15491 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
15492 intel_ddi_init(dev
, PORT_C
);
15493 if (found
& SFUSE_STRAP_DDID_DETECTED
)
15494 intel_ddi_init(dev
, PORT_D
);
15496 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
15498 if ((IS_SKYLAKE(dev_priv
) || IS_KABYLAKE(dev_priv
)) &&
15499 (dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dp
||
15500 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dvi
||
15501 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_hdmi
))
15502 intel_ddi_init(dev
, PORT_E
);
15504 } else if (HAS_PCH_SPLIT(dev_priv
)) {
15506 dpd_is_edp
= intel_dp_is_edp(dev
, PORT_D
);
15508 if (has_edp_a(dev
))
15509 intel_dp_init(dev
, DP_A
, PORT_A
);
15511 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
15512 /* PCH SDVOB multiplex with HDMIB */
15513 found
= intel_sdvo_init(dev
, PCH_SDVOB
, PORT_B
);
15515 intel_hdmi_init(dev
, PCH_HDMIB
, PORT_B
);
15516 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
15517 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
15520 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
15521 intel_hdmi_init(dev
, PCH_HDMIC
, PORT_C
);
15523 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
15524 intel_hdmi_init(dev
, PCH_HDMID
, PORT_D
);
15526 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
15527 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
15529 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
15530 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
15531 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
15532 bool has_edp
, has_port
;
15535 * The DP_DETECTED bit is the latched state of the DDC
15536 * SDA pin at boot. However since eDP doesn't require DDC
15537 * (no way to plug in a DP->HDMI dongle) the DDC pins for
15538 * eDP ports may have been muxed to an alternate function.
15539 * Thus we can't rely on the DP_DETECTED bit alone to detect
15540 * eDP ports. Consult the VBT as well as DP_DETECTED to
15541 * detect eDP ports.
15543 * Sadly the straps seem to be missing sometimes even for HDMI
15544 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
15545 * and VBT for the presence of the port. Additionally we can't
15546 * trust the port type the VBT declares as we've seen at least
15547 * HDMI ports that the VBT claim are DP or eDP.
15549 has_edp
= intel_dp_is_edp(dev
, PORT_B
);
15550 has_port
= intel_bios_is_port_present(dev_priv
, PORT_B
);
15551 if (I915_READ(VLV_DP_B
) & DP_DETECTED
|| has_port
)
15552 has_edp
&= intel_dp_init(dev
, VLV_DP_B
, PORT_B
);
15553 if ((I915_READ(VLV_HDMIB
) & SDVO_DETECTED
|| has_port
) && !has_edp
)
15554 intel_hdmi_init(dev
, VLV_HDMIB
, PORT_B
);
15556 has_edp
= intel_dp_is_edp(dev
, PORT_C
);
15557 has_port
= intel_bios_is_port_present(dev_priv
, PORT_C
);
15558 if (I915_READ(VLV_DP_C
) & DP_DETECTED
|| has_port
)
15559 has_edp
&= intel_dp_init(dev
, VLV_DP_C
, PORT_C
);
15560 if ((I915_READ(VLV_HDMIC
) & SDVO_DETECTED
|| has_port
) && !has_edp
)
15561 intel_hdmi_init(dev
, VLV_HDMIC
, PORT_C
);
15563 if (IS_CHERRYVIEW(dev_priv
)) {
15565 * eDP not supported on port D,
15566 * so no need to worry about it
15568 has_port
= intel_bios_is_port_present(dev_priv
, PORT_D
);
15569 if (I915_READ(CHV_DP_D
) & DP_DETECTED
|| has_port
)
15570 intel_dp_init(dev
, CHV_DP_D
, PORT_D
);
15571 if (I915_READ(CHV_HDMID
) & SDVO_DETECTED
|| has_port
)
15572 intel_hdmi_init(dev
, CHV_HDMID
, PORT_D
);
15575 intel_dsi_init(dev
);
15576 } else if (!IS_GEN2(dev_priv
) && !IS_PINEVIEW(dev_priv
)) {
15577 bool found
= false;
15579 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
15580 DRM_DEBUG_KMS("probing SDVOB\n");
15581 found
= intel_sdvo_init(dev
, GEN3_SDVOB
, PORT_B
);
15582 if (!found
&& IS_G4X(dev_priv
)) {
15583 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
15584 intel_hdmi_init(dev
, GEN4_HDMIB
, PORT_B
);
15587 if (!found
&& IS_G4X(dev_priv
))
15588 intel_dp_init(dev
, DP_B
, PORT_B
);
15591 /* Before G4X SDVOC doesn't have its own detect register */
15593 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
15594 DRM_DEBUG_KMS("probing SDVOC\n");
15595 found
= intel_sdvo_init(dev
, GEN3_SDVOC
, PORT_C
);
15598 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
15600 if (IS_G4X(dev_priv
)) {
15601 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
15602 intel_hdmi_init(dev
, GEN4_HDMIC
, PORT_C
);
15604 if (IS_G4X(dev_priv
))
15605 intel_dp_init(dev
, DP_C
, PORT_C
);
15608 if (IS_G4X(dev_priv
) && (I915_READ(DP_D
) & DP_DETECTED
))
15609 intel_dp_init(dev
, DP_D
, PORT_D
);
15610 } else if (IS_GEN2(dev_priv
))
15611 intel_dvo_init(dev
);
15613 if (SUPPORTS_TV(dev
))
15614 intel_tv_init(dev
);
15616 intel_psr_init(dev
);
15618 for_each_intel_encoder(dev
, encoder
) {
15619 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
15620 encoder
->base
.possible_clones
=
15621 intel_encoder_clones(encoder
);
15624 intel_init_pch_refclk(dev
);
15626 drm_helper_move_panel_connectors_to_head(dev
);
15629 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
15631 struct drm_device
*dev
= fb
->dev
;
15632 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
15634 drm_framebuffer_cleanup(fb
);
15635 mutex_lock(&dev
->struct_mutex
);
15636 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
15637 i915_gem_object_put(intel_fb
->obj
);
15638 mutex_unlock(&dev
->struct_mutex
);
15642 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
15643 struct drm_file
*file
,
15644 unsigned int *handle
)
15646 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
15647 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
15649 if (obj
->userptr
.mm
) {
15650 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
15654 return drm_gem_handle_create(file
, &obj
->base
, handle
);
15657 static int intel_user_framebuffer_dirty(struct drm_framebuffer
*fb
,
15658 struct drm_file
*file
,
15659 unsigned flags
, unsigned color
,
15660 struct drm_clip_rect
*clips
,
15661 unsigned num_clips
)
15663 struct drm_device
*dev
= fb
->dev
;
15664 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
15665 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
15667 mutex_lock(&dev
->struct_mutex
);
15668 intel_fb_obj_flush(obj
, false, ORIGIN_DIRTYFB
);
15669 mutex_unlock(&dev
->struct_mutex
);
15674 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
15675 .destroy
= intel_user_framebuffer_destroy
,
15676 .create_handle
= intel_user_framebuffer_create_handle
,
15677 .dirty
= intel_user_framebuffer_dirty
,
15681 u32
intel_fb_pitch_limit(struct drm_i915_private
*dev_priv
,
15682 uint64_t fb_modifier
, uint32_t pixel_format
)
15684 u32 gen
= INTEL_INFO(dev_priv
)->gen
;
15687 int cpp
= drm_format_plane_cpp(pixel_format
, 0);
15689 /* "The stride in bytes must not exceed the of the size of 8K
15690 * pixels and 32K bytes."
15692 return min(8192 * cpp
, 32768);
15693 } else if (gen
>= 5 && !IS_VALLEYVIEW(dev_priv
) &&
15694 !IS_CHERRYVIEW(dev_priv
)) {
15696 } else if (gen
>= 4) {
15697 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
15701 } else if (gen
>= 3) {
15702 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
15707 /* XXX DSPC is limited to 4k tiled */
15712 static int intel_framebuffer_init(struct drm_device
*dev
,
15713 struct intel_framebuffer
*intel_fb
,
15714 struct drm_mode_fb_cmd2
*mode_cmd
,
15715 struct drm_i915_gem_object
*obj
)
15717 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15718 unsigned int tiling
= i915_gem_object_get_tiling(obj
);
15720 u32 pitch_limit
, stride_alignment
;
15723 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
15725 if (mode_cmd
->flags
& DRM_MODE_FB_MODIFIERS
) {
15727 * If there's a fence, enforce that
15728 * the fb modifier and tiling mode match.
15730 if (tiling
!= I915_TILING_NONE
&&
15731 tiling
!= intel_fb_modifier_to_tiling(mode_cmd
->modifier
[0])) {
15732 DRM_DEBUG("tiling_mode doesn't match fb modifier\n");
15736 if (tiling
== I915_TILING_X
) {
15737 mode_cmd
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
15738 } else if (tiling
== I915_TILING_Y
) {
15739 DRM_DEBUG("No Y tiling for legacy addfb\n");
15744 /* Passed in modifier sanity checking. */
15745 switch (mode_cmd
->modifier
[0]) {
15746 case I915_FORMAT_MOD_Y_TILED
:
15747 case I915_FORMAT_MOD_Yf_TILED
:
15748 if (INTEL_INFO(dev
)->gen
< 9) {
15749 DRM_DEBUG("Unsupported tiling 0x%llx!\n",
15750 mode_cmd
->modifier
[0]);
15753 case DRM_FORMAT_MOD_NONE
:
15754 case I915_FORMAT_MOD_X_TILED
:
15757 DRM_DEBUG("Unsupported fb modifier 0x%llx!\n",
15758 mode_cmd
->modifier
[0]);
15763 * gen2/3 display engine uses the fence if present,
15764 * so the tiling mode must match the fb modifier exactly.
15766 if (INTEL_INFO(dev_priv
)->gen
< 4 &&
15767 tiling
!= intel_fb_modifier_to_tiling(mode_cmd
->modifier
[0])) {
15768 DRM_DEBUG("tiling_mode must match fb modifier exactly on gen2/3\n");
15772 stride_alignment
= intel_fb_stride_alignment(dev_priv
,
15773 mode_cmd
->modifier
[0],
15774 mode_cmd
->pixel_format
);
15775 if (mode_cmd
->pitches
[0] & (stride_alignment
- 1)) {
15776 DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n",
15777 mode_cmd
->pitches
[0], stride_alignment
);
15781 pitch_limit
= intel_fb_pitch_limit(dev_priv
, mode_cmd
->modifier
[0],
15782 mode_cmd
->pixel_format
);
15783 if (mode_cmd
->pitches
[0] > pitch_limit
) {
15784 DRM_DEBUG("%s pitch (%u) must be at less than %d\n",
15785 mode_cmd
->modifier
[0] != DRM_FORMAT_MOD_NONE
?
15786 "tiled" : "linear",
15787 mode_cmd
->pitches
[0], pitch_limit
);
15792 * If there's a fence, enforce that
15793 * the fb pitch and fence stride match.
15795 if (tiling
!= I915_TILING_NONE
&&
15796 mode_cmd
->pitches
[0] != i915_gem_object_get_stride(obj
)) {
15797 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
15798 mode_cmd
->pitches
[0],
15799 i915_gem_object_get_stride(obj
));
15803 /* Reject formats not supported by any plane early. */
15804 switch (mode_cmd
->pixel_format
) {
15805 case DRM_FORMAT_C8
:
15806 case DRM_FORMAT_RGB565
:
15807 case DRM_FORMAT_XRGB8888
:
15808 case DRM_FORMAT_ARGB8888
:
15810 case DRM_FORMAT_XRGB1555
:
15811 if (INTEL_INFO(dev
)->gen
> 3) {
15812 format_name
= drm_get_format_name(mode_cmd
->pixel_format
);
15813 DRM_DEBUG("unsupported pixel format: %s\n", format_name
);
15814 kfree(format_name
);
15818 case DRM_FORMAT_ABGR8888
:
15819 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
) &&
15820 INTEL_INFO(dev
)->gen
< 9) {
15821 format_name
= drm_get_format_name(mode_cmd
->pixel_format
);
15822 DRM_DEBUG("unsupported pixel format: %s\n", format_name
);
15823 kfree(format_name
);
15827 case DRM_FORMAT_XBGR8888
:
15828 case DRM_FORMAT_XRGB2101010
:
15829 case DRM_FORMAT_XBGR2101010
:
15830 if (INTEL_INFO(dev
)->gen
< 4) {
15831 format_name
= drm_get_format_name(mode_cmd
->pixel_format
);
15832 DRM_DEBUG("unsupported pixel format: %s\n", format_name
);
15833 kfree(format_name
);
15837 case DRM_FORMAT_ABGR2101010
:
15838 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
)) {
15839 format_name
= drm_get_format_name(mode_cmd
->pixel_format
);
15840 DRM_DEBUG("unsupported pixel format: %s\n", format_name
);
15841 kfree(format_name
);
15845 case DRM_FORMAT_YUYV
:
15846 case DRM_FORMAT_UYVY
:
15847 case DRM_FORMAT_YVYU
:
15848 case DRM_FORMAT_VYUY
:
15849 if (INTEL_INFO(dev
)->gen
< 5) {
15850 format_name
= drm_get_format_name(mode_cmd
->pixel_format
);
15851 DRM_DEBUG("unsupported pixel format: %s\n", format_name
);
15852 kfree(format_name
);
15857 format_name
= drm_get_format_name(mode_cmd
->pixel_format
);
15858 DRM_DEBUG("unsupported pixel format: %s\n", format_name
);
15859 kfree(format_name
);
15863 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
15864 if (mode_cmd
->offsets
[0] != 0)
15867 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
15868 intel_fb
->obj
= obj
;
15870 ret
= intel_fill_fb_info(dev_priv
, &intel_fb
->base
);
15874 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
15876 DRM_ERROR("framebuffer init failed %d\n", ret
);
15880 intel_fb
->obj
->framebuffer_references
++;
15885 static struct drm_framebuffer
*
15886 intel_user_framebuffer_create(struct drm_device
*dev
,
15887 struct drm_file
*filp
,
15888 const struct drm_mode_fb_cmd2
*user_mode_cmd
)
15890 struct drm_framebuffer
*fb
;
15891 struct drm_i915_gem_object
*obj
;
15892 struct drm_mode_fb_cmd2 mode_cmd
= *user_mode_cmd
;
15894 obj
= i915_gem_object_lookup(filp
, mode_cmd
.handles
[0]);
15896 return ERR_PTR(-ENOENT
);
15898 fb
= intel_framebuffer_create(dev
, &mode_cmd
, obj
);
15900 i915_gem_object_put(obj
);
15905 static const struct drm_mode_config_funcs intel_mode_funcs
= {
15906 .fb_create
= intel_user_framebuffer_create
,
15907 .output_poll_changed
= intel_fbdev_output_poll_changed
,
15908 .atomic_check
= intel_atomic_check
,
15909 .atomic_commit
= intel_atomic_commit
,
15910 .atomic_state_alloc
= intel_atomic_state_alloc
,
15911 .atomic_state_clear
= intel_atomic_state_clear
,
15915 * intel_init_display_hooks - initialize the display modesetting hooks
15916 * @dev_priv: device private
15918 void intel_init_display_hooks(struct drm_i915_private
*dev_priv
)
15920 if (INTEL_INFO(dev_priv
)->gen
>= 9) {
15921 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
15922 dev_priv
->display
.get_initial_plane_config
=
15923 skylake_get_initial_plane_config
;
15924 dev_priv
->display
.crtc_compute_clock
=
15925 haswell_crtc_compute_clock
;
15926 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
15927 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
15928 } else if (HAS_DDI(dev_priv
)) {
15929 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
15930 dev_priv
->display
.get_initial_plane_config
=
15931 ironlake_get_initial_plane_config
;
15932 dev_priv
->display
.crtc_compute_clock
=
15933 haswell_crtc_compute_clock
;
15934 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
15935 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
15936 } else if (HAS_PCH_SPLIT(dev_priv
)) {
15937 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
15938 dev_priv
->display
.get_initial_plane_config
=
15939 ironlake_get_initial_plane_config
;
15940 dev_priv
->display
.crtc_compute_clock
=
15941 ironlake_crtc_compute_clock
;
15942 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
15943 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
15944 } else if (IS_CHERRYVIEW(dev_priv
)) {
15945 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
15946 dev_priv
->display
.get_initial_plane_config
=
15947 i9xx_get_initial_plane_config
;
15948 dev_priv
->display
.crtc_compute_clock
= chv_crtc_compute_clock
;
15949 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
15950 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
15951 } else if (IS_VALLEYVIEW(dev_priv
)) {
15952 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
15953 dev_priv
->display
.get_initial_plane_config
=
15954 i9xx_get_initial_plane_config
;
15955 dev_priv
->display
.crtc_compute_clock
= vlv_crtc_compute_clock
;
15956 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
15957 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
15958 } else if (IS_G4X(dev_priv
)) {
15959 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
15960 dev_priv
->display
.get_initial_plane_config
=
15961 i9xx_get_initial_plane_config
;
15962 dev_priv
->display
.crtc_compute_clock
= g4x_crtc_compute_clock
;
15963 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
15964 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
15965 } else if (IS_PINEVIEW(dev_priv
)) {
15966 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
15967 dev_priv
->display
.get_initial_plane_config
=
15968 i9xx_get_initial_plane_config
;
15969 dev_priv
->display
.crtc_compute_clock
= pnv_crtc_compute_clock
;
15970 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
15971 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
15972 } else if (!IS_GEN2(dev_priv
)) {
15973 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
15974 dev_priv
->display
.get_initial_plane_config
=
15975 i9xx_get_initial_plane_config
;
15976 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
15977 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
15978 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
15980 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
15981 dev_priv
->display
.get_initial_plane_config
=
15982 i9xx_get_initial_plane_config
;
15983 dev_priv
->display
.crtc_compute_clock
= i8xx_crtc_compute_clock
;
15984 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
15985 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
15988 /* Returns the core display clock speed */
15989 if (IS_SKYLAKE(dev_priv
) || IS_KABYLAKE(dev_priv
))
15990 dev_priv
->display
.get_display_clock_speed
=
15991 skylake_get_display_clock_speed
;
15992 else if (IS_BROXTON(dev_priv
))
15993 dev_priv
->display
.get_display_clock_speed
=
15994 broxton_get_display_clock_speed
;
15995 else if (IS_BROADWELL(dev_priv
))
15996 dev_priv
->display
.get_display_clock_speed
=
15997 broadwell_get_display_clock_speed
;
15998 else if (IS_HASWELL(dev_priv
))
15999 dev_priv
->display
.get_display_clock_speed
=
16000 haswell_get_display_clock_speed
;
16001 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
16002 dev_priv
->display
.get_display_clock_speed
=
16003 valleyview_get_display_clock_speed
;
16004 else if (IS_GEN5(dev_priv
))
16005 dev_priv
->display
.get_display_clock_speed
=
16006 ilk_get_display_clock_speed
;
16007 else if (IS_I945G(dev_priv
) || IS_BROADWATER(dev_priv
) ||
16008 IS_GEN6(dev_priv
) || IS_IVYBRIDGE(dev_priv
))
16009 dev_priv
->display
.get_display_clock_speed
=
16010 i945_get_display_clock_speed
;
16011 else if (IS_GM45(dev_priv
))
16012 dev_priv
->display
.get_display_clock_speed
=
16013 gm45_get_display_clock_speed
;
16014 else if (IS_CRESTLINE(dev_priv
))
16015 dev_priv
->display
.get_display_clock_speed
=
16016 i965gm_get_display_clock_speed
;
16017 else if (IS_PINEVIEW(dev_priv
))
16018 dev_priv
->display
.get_display_clock_speed
=
16019 pnv_get_display_clock_speed
;
16020 else if (IS_G33(dev_priv
) || IS_G4X(dev_priv
))
16021 dev_priv
->display
.get_display_clock_speed
=
16022 g33_get_display_clock_speed
;
16023 else if (IS_I915G(dev_priv
))
16024 dev_priv
->display
.get_display_clock_speed
=
16025 i915_get_display_clock_speed
;
16026 else if (IS_I945GM(dev_priv
) || IS_845G(dev_priv
))
16027 dev_priv
->display
.get_display_clock_speed
=
16028 i9xx_misc_get_display_clock_speed
;
16029 else if (IS_I915GM(dev_priv
))
16030 dev_priv
->display
.get_display_clock_speed
=
16031 i915gm_get_display_clock_speed
;
16032 else if (IS_I865G(dev_priv
))
16033 dev_priv
->display
.get_display_clock_speed
=
16034 i865_get_display_clock_speed
;
16035 else if (IS_I85X(dev_priv
))
16036 dev_priv
->display
.get_display_clock_speed
=
16037 i85x_get_display_clock_speed
;
16039 WARN(!IS_I830(dev_priv
), "Unknown platform. Assuming 133 MHz CDCLK\n");
16040 dev_priv
->display
.get_display_clock_speed
=
16041 i830_get_display_clock_speed
;
16044 if (IS_GEN5(dev_priv
)) {
16045 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
16046 } else if (IS_GEN6(dev_priv
)) {
16047 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
16048 } else if (IS_IVYBRIDGE(dev_priv
)) {
16049 /* FIXME: detect B0+ stepping and use auto training */
16050 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
16051 } else if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
16052 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
16055 if (IS_BROADWELL(dev_priv
)) {
16056 dev_priv
->display
.modeset_commit_cdclk
=
16057 broadwell_modeset_commit_cdclk
;
16058 dev_priv
->display
.modeset_calc_cdclk
=
16059 broadwell_modeset_calc_cdclk
;
16060 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
16061 dev_priv
->display
.modeset_commit_cdclk
=
16062 valleyview_modeset_commit_cdclk
;
16063 dev_priv
->display
.modeset_calc_cdclk
=
16064 valleyview_modeset_calc_cdclk
;
16065 } else if (IS_BROXTON(dev_priv
)) {
16066 dev_priv
->display
.modeset_commit_cdclk
=
16067 bxt_modeset_commit_cdclk
;
16068 dev_priv
->display
.modeset_calc_cdclk
=
16069 bxt_modeset_calc_cdclk
;
16070 } else if (IS_SKYLAKE(dev_priv
) || IS_KABYLAKE(dev_priv
)) {
16071 dev_priv
->display
.modeset_commit_cdclk
=
16072 skl_modeset_commit_cdclk
;
16073 dev_priv
->display
.modeset_calc_cdclk
=
16074 skl_modeset_calc_cdclk
;
16077 if (dev_priv
->info
.gen
>= 9)
16078 dev_priv
->display
.update_crtcs
= skl_update_crtcs
;
16080 dev_priv
->display
.update_crtcs
= intel_update_crtcs
;
16082 switch (INTEL_INFO(dev_priv
)->gen
) {
16084 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
16088 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
16093 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
16097 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
16100 case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
16101 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
16104 /* Drop through - unsupported since execlist only. */
16106 /* Default just returns -ENODEV to indicate unsupported */
16107 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
16112 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
16113 * resume, or other times. This quirk makes sure that's the case for
16114 * affected systems.
16116 static void quirk_pipea_force(struct drm_device
*dev
)
16118 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16120 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
16121 DRM_INFO("applying pipe a force quirk\n");
16124 static void quirk_pipeb_force(struct drm_device
*dev
)
16126 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16128 dev_priv
->quirks
|= QUIRK_PIPEB_FORCE
;
16129 DRM_INFO("applying pipe b force quirk\n");
16133 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
16135 static void quirk_ssc_force_disable(struct drm_device
*dev
)
16137 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16138 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
16139 DRM_INFO("applying lvds SSC disable quirk\n");
16143 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
16146 static void quirk_invert_brightness(struct drm_device
*dev
)
16148 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16149 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
16150 DRM_INFO("applying inverted panel brightness quirk\n");
16153 /* Some VBT's incorrectly indicate no backlight is present */
16154 static void quirk_backlight_present(struct drm_device
*dev
)
16156 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16157 dev_priv
->quirks
|= QUIRK_BACKLIGHT_PRESENT
;
16158 DRM_INFO("applying backlight present quirk\n");
16161 struct intel_quirk
{
16163 int subsystem_vendor
;
16164 int subsystem_device
;
16165 void (*hook
)(struct drm_device
*dev
);
16168 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
16169 struct intel_dmi_quirk
{
16170 void (*hook
)(struct drm_device
*dev
);
16171 const struct dmi_system_id (*dmi_id_list
)[];
16174 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
16176 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
16180 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
16182 .dmi_id_list
= &(const struct dmi_system_id
[]) {
16184 .callback
= intel_dmi_reverse_brightness
,
16185 .ident
= "NCR Corporation",
16186 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
16187 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
16190 { } /* terminating entry */
16192 .hook
= quirk_invert_brightness
,
16196 static struct intel_quirk intel_quirks
[] = {
16197 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
16198 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
16200 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
16201 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
16203 /* 830 needs to leave pipe A & dpll A up */
16204 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
16206 /* 830 needs to leave pipe B & dpll B up */
16207 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipeb_force
},
16209 /* Lenovo U160 cannot use SSC on LVDS */
16210 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
16212 /* Sony Vaio Y cannot use SSC on LVDS */
16213 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
16215 /* Acer Aspire 5734Z must invert backlight brightness */
16216 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
16218 /* Acer/eMachines G725 */
16219 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
16221 /* Acer/eMachines e725 */
16222 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
16224 /* Acer/Packard Bell NCL20 */
16225 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
16227 /* Acer Aspire 4736Z */
16228 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
16230 /* Acer Aspire 5336 */
16231 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
16233 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
16234 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present
},
16236 /* Acer C720 Chromebook (Core i3 4005U) */
16237 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present
},
16239 /* Apple Macbook 2,1 (Core 2 T7400) */
16240 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present
},
16242 /* Apple Macbook 4,1 */
16243 { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present
},
16245 /* Toshiba CB35 Chromebook (Celeron 2955U) */
16246 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present
},
16248 /* HP Chromebook 14 (Celeron 2955U) */
16249 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present
},
16251 /* Dell Chromebook 11 */
16252 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present
},
16254 /* Dell Chromebook 11 (2015 version) */
16255 { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present
},
16258 static void intel_init_quirks(struct drm_device
*dev
)
16260 struct pci_dev
*d
= dev
->pdev
;
16263 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
16264 struct intel_quirk
*q
= &intel_quirks
[i
];
16266 if (d
->device
== q
->device
&&
16267 (d
->subsystem_vendor
== q
->subsystem_vendor
||
16268 q
->subsystem_vendor
== PCI_ANY_ID
) &&
16269 (d
->subsystem_device
== q
->subsystem_device
||
16270 q
->subsystem_device
== PCI_ANY_ID
))
16273 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
16274 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
16275 intel_dmi_quirks
[i
].hook(dev
);
16279 /* Disable the VGA plane that we never use */
16280 static void i915_disable_vga(struct drm_device
*dev
)
16282 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16283 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
16285 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev_priv
);
16287 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
16288 vga_get_uninterruptible(pdev
, VGA_RSRC_LEGACY_IO
);
16289 outb(SR01
, VGA_SR_INDEX
);
16290 sr1
= inb(VGA_SR_DATA
);
16291 outb(sr1
| 1<<5, VGA_SR_DATA
);
16292 vga_put(pdev
, VGA_RSRC_LEGACY_IO
);
16295 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
16296 POSTING_READ(vga_reg
);
16299 void intel_modeset_init_hw(struct drm_device
*dev
)
16301 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16303 intel_update_cdclk(dev
);
16305 dev_priv
->atomic_cdclk_freq
= dev_priv
->cdclk_freq
;
16307 intel_init_clock_gating(dev
);
16311 * Calculate what we think the watermarks should be for the state we've read
16312 * out of the hardware and then immediately program those watermarks so that
16313 * we ensure the hardware settings match our internal state.
16315 * We can calculate what we think WM's should be by creating a duplicate of the
16316 * current state (which was constructed during hardware readout) and running it
16317 * through the atomic check code to calculate new watermark values in the
16320 static void sanitize_watermarks(struct drm_device
*dev
)
16322 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16323 struct drm_atomic_state
*state
;
16324 struct drm_crtc
*crtc
;
16325 struct drm_crtc_state
*cstate
;
16326 struct drm_modeset_acquire_ctx ctx
;
16330 /* Only supported on platforms that use atomic watermark design */
16331 if (!dev_priv
->display
.optimize_watermarks
)
16335 * We need to hold connection_mutex before calling duplicate_state so
16336 * that the connector loop is protected.
16338 drm_modeset_acquire_init(&ctx
, 0);
16340 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
16341 if (ret
== -EDEADLK
) {
16342 drm_modeset_backoff(&ctx
);
16344 } else if (WARN_ON(ret
)) {
16348 state
= drm_atomic_helper_duplicate_state(dev
, &ctx
);
16349 if (WARN_ON(IS_ERR(state
)))
16353 * Hardware readout is the only time we don't want to calculate
16354 * intermediate watermarks (since we don't trust the current
16357 to_intel_atomic_state(state
)->skip_intermediate_wm
= true;
16359 ret
= intel_atomic_check(dev
, state
);
16362 * If we fail here, it means that the hardware appears to be
16363 * programmed in a way that shouldn't be possible, given our
16364 * understanding of watermark requirements. This might mean a
16365 * mistake in the hardware readout code or a mistake in the
16366 * watermark calculations for a given platform. Raise a WARN
16367 * so that this is noticeable.
16369 * If this actually happens, we'll have to just leave the
16370 * BIOS-programmed watermarks untouched and hope for the best.
16372 WARN(true, "Could not determine valid watermarks for inherited state\n");
16376 /* Write calculated watermark values back */
16377 for_each_crtc_in_state(state
, crtc
, cstate
, i
) {
16378 struct intel_crtc_state
*cs
= to_intel_crtc_state(cstate
);
16380 cs
->wm
.need_postvbl_update
= true;
16381 dev_priv
->display
.optimize_watermarks(cs
);
16385 drm_atomic_state_put(state
);
16387 drm_modeset_drop_locks(&ctx
);
16388 drm_modeset_acquire_fini(&ctx
);
16391 void intel_modeset_init(struct drm_device
*dev
)
16393 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16394 struct i915_ggtt
*ggtt
= &dev_priv
->ggtt
;
16397 struct intel_crtc
*crtc
;
16399 drm_mode_config_init(dev
);
16401 dev
->mode_config
.min_width
= 0;
16402 dev
->mode_config
.min_height
= 0;
16404 dev
->mode_config
.preferred_depth
= 24;
16405 dev
->mode_config
.prefer_shadow
= 1;
16407 dev
->mode_config
.allow_fb_modifiers
= true;
16409 dev
->mode_config
.funcs
= &intel_mode_funcs
;
16411 intel_init_quirks(dev
);
16413 intel_init_pm(dev
);
16415 if (INTEL_INFO(dev
)->num_pipes
== 0)
16419 * There may be no VBT; and if the BIOS enabled SSC we can
16420 * just keep using it to avoid unnecessary flicker. Whereas if the
16421 * BIOS isn't using it, don't assume it will work even if the VBT
16422 * indicates as much.
16424 if (HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
)) {
16425 bool bios_lvds_use_ssc
= !!(I915_READ(PCH_DREF_CONTROL
) &
16428 if (dev_priv
->vbt
.lvds_use_ssc
!= bios_lvds_use_ssc
) {
16429 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
16430 bios_lvds_use_ssc
? "en" : "dis",
16431 dev_priv
->vbt
.lvds_use_ssc
? "en" : "dis");
16432 dev_priv
->vbt
.lvds_use_ssc
= bios_lvds_use_ssc
;
16436 if (IS_GEN2(dev_priv
)) {
16437 dev
->mode_config
.max_width
= 2048;
16438 dev
->mode_config
.max_height
= 2048;
16439 } else if (IS_GEN3(dev_priv
)) {
16440 dev
->mode_config
.max_width
= 4096;
16441 dev
->mode_config
.max_height
= 4096;
16443 dev
->mode_config
.max_width
= 8192;
16444 dev
->mode_config
.max_height
= 8192;
16447 if (IS_845G(dev_priv
) || IS_I865G(dev_priv
)) {
16448 dev
->mode_config
.cursor_width
= IS_845G(dev_priv
) ? 64 : 512;
16449 dev
->mode_config
.cursor_height
= 1023;
16450 } else if (IS_GEN2(dev_priv
)) {
16451 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
16452 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
16454 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
16455 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
16458 dev
->mode_config
.fb_base
= ggtt
->mappable_base
;
16460 DRM_DEBUG_KMS("%d display pipe%s available.\n",
16461 INTEL_INFO(dev
)->num_pipes
,
16462 INTEL_INFO(dev
)->num_pipes
> 1 ? "s" : "");
16464 for_each_pipe(dev_priv
, pipe
) {
16465 intel_crtc_init(dev
, pipe
);
16466 for_each_sprite(dev_priv
, pipe
, sprite
) {
16467 ret
= intel_plane_init(dev
, pipe
, sprite
);
16469 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
16470 pipe_name(pipe
), sprite_name(pipe
, sprite
), ret
);
16474 intel_update_czclk(dev_priv
);
16475 intel_update_cdclk(dev
);
16477 intel_shared_dpll_init(dev
);
16479 if (dev_priv
->max_cdclk_freq
== 0)
16480 intel_update_max_cdclk(dev
);
16482 /* Just disable it once at startup */
16483 i915_disable_vga(dev
);
16484 intel_setup_outputs(dev
);
16486 drm_modeset_lock_all(dev
);
16487 intel_modeset_setup_hw_state(dev
);
16488 drm_modeset_unlock_all(dev
);
16490 for_each_intel_crtc(dev
, crtc
) {
16491 struct intel_initial_plane_config plane_config
= {};
16497 * Note that reserving the BIOS fb up front prevents us
16498 * from stuffing other stolen allocations like the ring
16499 * on top. This prevents some ugliness at boot time, and
16500 * can even allow for smooth boot transitions if the BIOS
16501 * fb is large enough for the active pipe configuration.
16503 dev_priv
->display
.get_initial_plane_config(crtc
,
16507 * If the fb is shared between multiple heads, we'll
16508 * just get the first one.
16510 intel_find_initial_plane_obj(crtc
, &plane_config
);
16514 * Make sure hardware watermarks really match the state we read out.
16515 * Note that we need to do this after reconstructing the BIOS fb's
16516 * since the watermark calculation done here will use pstate->fb.
16518 sanitize_watermarks(dev
);
16521 static void intel_enable_pipe_a(struct drm_device
*dev
)
16523 struct intel_connector
*connector
;
16524 struct drm_connector
*crt
= NULL
;
16525 struct intel_load_detect_pipe load_detect_temp
;
16526 struct drm_modeset_acquire_ctx
*ctx
= dev
->mode_config
.acquire_ctx
;
16528 /* We can't just switch on the pipe A, we need to set things up with a
16529 * proper mode and output configuration. As a gross hack, enable pipe A
16530 * by enabling the load detect pipe once. */
16531 for_each_intel_connector(dev
, connector
) {
16532 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
16533 crt
= &connector
->base
;
16541 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
, ctx
))
16542 intel_release_load_detect_pipe(crt
, &load_detect_temp
, ctx
);
16546 intel_check_plane_mapping(struct intel_crtc
*crtc
)
16548 struct drm_device
*dev
= crtc
->base
.dev
;
16549 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16552 if (INTEL_INFO(dev
)->num_pipes
== 1)
16555 val
= I915_READ(DSPCNTR(!crtc
->plane
));
16557 if ((val
& DISPLAY_PLANE_ENABLE
) &&
16558 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
16564 static bool intel_crtc_has_encoders(struct intel_crtc
*crtc
)
16566 struct drm_device
*dev
= crtc
->base
.dev
;
16567 struct intel_encoder
*encoder
;
16569 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
16575 static struct intel_connector
*intel_encoder_find_connector(struct intel_encoder
*encoder
)
16577 struct drm_device
*dev
= encoder
->base
.dev
;
16578 struct intel_connector
*connector
;
16580 for_each_connector_on_encoder(dev
, &encoder
->base
, connector
)
16586 static bool has_pch_trancoder(struct drm_i915_private
*dev_priv
,
16587 enum transcoder pch_transcoder
)
16589 return HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
) ||
16590 (HAS_PCH_LPT_H(dev_priv
) && pch_transcoder
== TRANSCODER_A
);
16593 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
16595 struct drm_device
*dev
= crtc
->base
.dev
;
16596 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16597 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
16599 /* Clear any frame start delays used for debugging left by the BIOS */
16600 if (!transcoder_is_dsi(cpu_transcoder
)) {
16601 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
16604 I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
16607 /* restore vblank interrupts to correct state */
16608 drm_crtc_vblank_reset(&crtc
->base
);
16609 if (crtc
->active
) {
16610 struct intel_plane
*plane
;
16612 drm_crtc_vblank_on(&crtc
->base
);
16614 /* Disable everything but the primary plane */
16615 for_each_intel_plane_on_crtc(dev
, crtc
, plane
) {
16616 if (plane
->base
.type
== DRM_PLANE_TYPE_PRIMARY
)
16619 plane
->disable_plane(&plane
->base
, &crtc
->base
);
16623 /* We need to sanitize the plane -> pipe mapping first because this will
16624 * disable the crtc (and hence change the state) if it is wrong. Note
16625 * that gen4+ has a fixed plane -> pipe mapping. */
16626 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
16629 DRM_DEBUG_KMS("[CRTC:%d:%s] wrong plane connection detected!\n",
16630 crtc
->base
.base
.id
, crtc
->base
.name
);
16632 /* Pipe has the wrong plane attached and the plane is active.
16633 * Temporarily change the plane mapping and disable everything
16635 plane
= crtc
->plane
;
16636 to_intel_plane_state(crtc
->base
.primary
->state
)->base
.visible
= true;
16637 crtc
->plane
= !plane
;
16638 intel_crtc_disable_noatomic(&crtc
->base
);
16639 crtc
->plane
= plane
;
16642 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
16643 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
16644 /* BIOS forgot to enable pipe A, this mostly happens after
16645 * resume. Force-enable the pipe to fix this, the update_dpms
16646 * call below we restore the pipe to the right state, but leave
16647 * the required bits on. */
16648 intel_enable_pipe_a(dev
);
16651 /* Adjust the state of the output pipe according to whether we
16652 * have active connectors/encoders. */
16653 if (crtc
->active
&& !intel_crtc_has_encoders(crtc
))
16654 intel_crtc_disable_noatomic(&crtc
->base
);
16656 if (crtc
->active
|| HAS_GMCH_DISPLAY(dev_priv
)) {
16658 * We start out with underrun reporting disabled to avoid races.
16659 * For correct bookkeeping mark this on active crtcs.
16661 * Also on gmch platforms we dont have any hardware bits to
16662 * disable the underrun reporting. Which means we need to start
16663 * out with underrun reporting disabled also on inactive pipes,
16664 * since otherwise we'll complain about the garbage we read when
16665 * e.g. coming up after runtime pm.
16667 * No protection against concurrent access is required - at
16668 * worst a fifo underrun happens which also sets this to false.
16670 crtc
->cpu_fifo_underrun_disabled
= true;
16672 * We track the PCH trancoder underrun reporting state
16673 * within the crtc. With crtc for pipe A housing the underrun
16674 * reporting state for PCH transcoder A, crtc for pipe B housing
16675 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
16676 * and marking underrun reporting as disabled for the non-existing
16677 * PCH transcoders B and C would prevent enabling the south
16678 * error interrupt (see cpt_can_enable_serr_int()).
16680 if (has_pch_trancoder(dev_priv
, (enum transcoder
)crtc
->pipe
))
16681 crtc
->pch_fifo_underrun_disabled
= true;
16685 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
16687 struct intel_connector
*connector
;
16689 /* We need to check both for a crtc link (meaning that the
16690 * encoder is active and trying to read from a pipe) and the
16691 * pipe itself being active. */
16692 bool has_active_crtc
= encoder
->base
.crtc
&&
16693 to_intel_crtc(encoder
->base
.crtc
)->active
;
16695 connector
= intel_encoder_find_connector(encoder
);
16696 if (connector
&& !has_active_crtc
) {
16697 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
16698 encoder
->base
.base
.id
,
16699 encoder
->base
.name
);
16701 /* Connector is active, but has no active pipe. This is
16702 * fallout from our resume register restoring. Disable
16703 * the encoder manually again. */
16704 if (encoder
->base
.crtc
) {
16705 struct drm_crtc_state
*crtc_state
= encoder
->base
.crtc
->state
;
16707 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
16708 encoder
->base
.base
.id
,
16709 encoder
->base
.name
);
16710 encoder
->disable(encoder
, to_intel_crtc_state(crtc_state
), connector
->base
.state
);
16711 if (encoder
->post_disable
)
16712 encoder
->post_disable(encoder
, to_intel_crtc_state(crtc_state
), connector
->base
.state
);
16714 encoder
->base
.crtc
= NULL
;
16716 /* Inconsistent output/port/pipe state happens presumably due to
16717 * a bug in one of the get_hw_state functions. Or someplace else
16718 * in our code, like the register restore mess on resume. Clamp
16719 * things to off as a safer default. */
16721 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
16722 connector
->base
.encoder
= NULL
;
16724 /* Enabled encoders without active connectors will be fixed in
16725 * the crtc fixup. */
16728 void i915_redisable_vga_power_on(struct drm_device
*dev
)
16730 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16731 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev_priv
);
16733 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
16734 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
16735 i915_disable_vga(dev
);
16739 void i915_redisable_vga(struct drm_device
*dev
)
16741 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16743 /* This function can be called both from intel_modeset_setup_hw_state or
16744 * at a very early point in our resume sequence, where the power well
16745 * structures are not yet restored. Since this function is at a very
16746 * paranoid "someone might have enabled VGA while we were not looking"
16747 * level, just check if the power well is enabled instead of trying to
16748 * follow the "don't touch the power well if we don't need it" policy
16749 * the rest of the driver uses. */
16750 if (!intel_display_power_get_if_enabled(dev_priv
, POWER_DOMAIN_VGA
))
16753 i915_redisable_vga_power_on(dev
);
16755 intel_display_power_put(dev_priv
, POWER_DOMAIN_VGA
);
16758 static bool primary_get_hw_state(struct intel_plane
*plane
)
16760 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
16762 return I915_READ(DSPCNTR(plane
->plane
)) & DISPLAY_PLANE_ENABLE
;
16765 /* FIXME read out full plane state for all planes */
16766 static void readout_plane_state(struct intel_crtc
*crtc
)
16768 struct drm_plane
*primary
= crtc
->base
.primary
;
16769 struct intel_plane_state
*plane_state
=
16770 to_intel_plane_state(primary
->state
);
16772 plane_state
->base
.visible
= crtc
->active
&&
16773 primary_get_hw_state(to_intel_plane(primary
));
16775 if (plane_state
->base
.visible
)
16776 crtc
->base
.state
->plane_mask
|= 1 << drm_plane_index(primary
);
16779 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
16781 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16783 struct intel_crtc
*crtc
;
16784 struct intel_encoder
*encoder
;
16785 struct intel_connector
*connector
;
16788 dev_priv
->active_crtcs
= 0;
16790 for_each_intel_crtc(dev
, crtc
) {
16791 struct intel_crtc_state
*crtc_state
= crtc
->config
;
16794 __drm_atomic_helper_crtc_destroy_state(&crtc_state
->base
);
16795 memset(crtc_state
, 0, sizeof(*crtc_state
));
16796 crtc_state
->base
.crtc
= &crtc
->base
;
16798 crtc_state
->base
.active
= crtc_state
->base
.enable
=
16799 dev_priv
->display
.get_pipe_config(crtc
, crtc_state
);
16801 crtc
->base
.enabled
= crtc_state
->base
.enable
;
16802 crtc
->active
= crtc_state
->base
.active
;
16804 if (crtc_state
->base
.active
) {
16805 dev_priv
->active_crtcs
|= 1 << crtc
->pipe
;
16807 if (INTEL_GEN(dev_priv
) >= 9 || IS_BROADWELL(dev_priv
))
16808 pixclk
= ilk_pipe_pixel_rate(crtc_state
);
16809 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
16810 pixclk
= crtc_state
->base
.adjusted_mode
.crtc_clock
;
16812 WARN_ON(dev_priv
->display
.modeset_calc_cdclk
);
16814 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
16815 if (IS_BROADWELL(dev_priv
) && crtc_state
->ips_enabled
)
16816 pixclk
= DIV_ROUND_UP(pixclk
* 100, 95);
16819 dev_priv
->min_pixclk
[crtc
->pipe
] = pixclk
;
16821 readout_plane_state(crtc
);
16823 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
16824 crtc
->base
.base
.id
, crtc
->base
.name
,
16825 crtc
->active
? "enabled" : "disabled");
16828 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
16829 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
16831 pll
->on
= pll
->funcs
.get_hw_state(dev_priv
, pll
,
16832 &pll
->config
.hw_state
);
16833 pll
->config
.crtc_mask
= 0;
16834 for_each_intel_crtc(dev
, crtc
) {
16835 if (crtc
->active
&& crtc
->config
->shared_dpll
== pll
)
16836 pll
->config
.crtc_mask
|= 1 << crtc
->pipe
;
16838 pll
->active_mask
= pll
->config
.crtc_mask
;
16840 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
16841 pll
->name
, pll
->config
.crtc_mask
, pll
->on
);
16844 for_each_intel_encoder(dev
, encoder
) {
16847 if (encoder
->get_hw_state(encoder
, &pipe
)) {
16848 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
16849 encoder
->base
.crtc
= &crtc
->base
;
16850 crtc
->config
->output_types
|= 1 << encoder
->type
;
16851 encoder
->get_config(encoder
, crtc
->config
);
16853 encoder
->base
.crtc
= NULL
;
16856 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
16857 encoder
->base
.base
.id
,
16858 encoder
->base
.name
,
16859 encoder
->base
.crtc
? "enabled" : "disabled",
16863 for_each_intel_connector(dev
, connector
) {
16864 if (connector
->get_hw_state(connector
)) {
16865 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
16867 encoder
= connector
->encoder
;
16868 connector
->base
.encoder
= &encoder
->base
;
16870 if (encoder
->base
.crtc
&&
16871 encoder
->base
.crtc
->state
->active
) {
16873 * This has to be done during hardware readout
16874 * because anything calling .crtc_disable may
16875 * rely on the connector_mask being accurate.
16877 encoder
->base
.crtc
->state
->connector_mask
|=
16878 1 << drm_connector_index(&connector
->base
);
16879 encoder
->base
.crtc
->state
->encoder_mask
|=
16880 1 << drm_encoder_index(&encoder
->base
);
16884 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
16885 connector
->base
.encoder
= NULL
;
16887 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
16888 connector
->base
.base
.id
,
16889 connector
->base
.name
,
16890 connector
->base
.encoder
? "enabled" : "disabled");
16893 for_each_intel_crtc(dev
, crtc
) {
16894 crtc
->base
.hwmode
= crtc
->config
->base
.adjusted_mode
;
16896 memset(&crtc
->base
.mode
, 0, sizeof(crtc
->base
.mode
));
16897 if (crtc
->base
.state
->active
) {
16898 intel_mode_from_pipe_config(&crtc
->base
.mode
, crtc
->config
);
16899 intel_mode_from_pipe_config(&crtc
->base
.state
->adjusted_mode
, crtc
->config
);
16900 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->base
.state
, &crtc
->base
.mode
));
16903 * The initial mode needs to be set in order to keep
16904 * the atomic core happy. It wants a valid mode if the
16905 * crtc's enabled, so we do the above call.
16907 * At this point some state updated by the connectors
16908 * in their ->detect() callback has not run yet, so
16909 * no recalculation can be done yet.
16911 * Even if we could do a recalculation and modeset
16912 * right now it would cause a double modeset if
16913 * fbdev or userspace chooses a different initial mode.
16915 * If that happens, someone indicated they wanted a
16916 * mode change, which means it's safe to do a full
16919 crtc
->base
.state
->mode
.private_flags
= I915_MODE_FLAG_INHERITED
;
16921 drm_calc_timestamping_constants(&crtc
->base
, &crtc
->base
.hwmode
);
16922 update_scanline_offset(crtc
);
16925 intel_pipe_config_sanity_check(dev_priv
, crtc
->config
);
16929 /* Scan out the current hw modeset state,
16930 * and sanitizes it to the current state
16933 intel_modeset_setup_hw_state(struct drm_device
*dev
)
16935 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16937 struct intel_crtc
*crtc
;
16938 struct intel_encoder
*encoder
;
16941 intel_modeset_readout_hw_state(dev
);
16943 /* HW state is read out, now we need to sanitize this mess. */
16944 for_each_intel_encoder(dev
, encoder
) {
16945 intel_sanitize_encoder(encoder
);
16948 for_each_pipe(dev_priv
, pipe
) {
16949 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
16950 intel_sanitize_crtc(crtc
);
16951 intel_dump_pipe_config(crtc
, crtc
->config
,
16952 "[setup_hw_state]");
16955 intel_modeset_update_connector_atomic_state(dev
);
16957 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
16958 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
16960 if (!pll
->on
|| pll
->active_mask
)
16963 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
16965 pll
->funcs
.disable(dev_priv
, pll
);
16969 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
16970 vlv_wm_get_hw_state(dev
);
16971 else if (IS_GEN9(dev_priv
))
16972 skl_wm_get_hw_state(dev
);
16973 else if (HAS_PCH_SPLIT(dev_priv
))
16974 ilk_wm_get_hw_state(dev
);
16976 for_each_intel_crtc(dev
, crtc
) {
16977 unsigned long put_domains
;
16979 put_domains
= modeset_get_crtc_power_domains(&crtc
->base
, crtc
->config
);
16980 if (WARN_ON(put_domains
))
16981 modeset_put_power_domains(dev_priv
, put_domains
);
16983 intel_display_set_init_power(dev_priv
, false);
16985 intel_fbc_init_pipe_state(dev_priv
);
16988 void intel_display_resume(struct drm_device
*dev
)
16990 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16991 struct drm_atomic_state
*state
= dev_priv
->modeset_restore_state
;
16992 struct drm_modeset_acquire_ctx ctx
;
16995 dev_priv
->modeset_restore_state
= NULL
;
16997 state
->acquire_ctx
= &ctx
;
17000 * This is a cludge because with real atomic modeset mode_config.mutex
17001 * won't be taken. Unfortunately some probed state like
17002 * audio_codec_enable is still protected by mode_config.mutex, so lock
17005 mutex_lock(&dev
->mode_config
.mutex
);
17006 drm_modeset_acquire_init(&ctx
, 0);
17009 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
17010 if (ret
!= -EDEADLK
)
17013 drm_modeset_backoff(&ctx
);
17017 ret
= __intel_display_resume(dev
, state
);
17019 drm_modeset_drop_locks(&ctx
);
17020 drm_modeset_acquire_fini(&ctx
);
17021 mutex_unlock(&dev
->mode_config
.mutex
);
17024 DRM_ERROR("Restoring old state failed with %i\n", ret
);
17025 drm_atomic_state_put(state
);
17028 void intel_modeset_gem_init(struct drm_device
*dev
)
17030 struct drm_i915_private
*dev_priv
= to_i915(dev
);
17031 struct drm_crtc
*c
;
17032 struct drm_i915_gem_object
*obj
;
17034 intel_init_gt_powersave(dev_priv
);
17036 intel_modeset_init_hw(dev
);
17038 intel_setup_overlay(dev_priv
);
17041 * Make sure any fbs we allocated at startup are properly
17042 * pinned & fenced. When we do the allocation it's too early
17045 for_each_crtc(dev
, c
) {
17046 struct i915_vma
*vma
;
17048 obj
= intel_fb_obj(c
->primary
->fb
);
17052 mutex_lock(&dev
->struct_mutex
);
17053 vma
= intel_pin_and_fence_fb_obj(c
->primary
->fb
,
17054 c
->primary
->state
->rotation
);
17055 mutex_unlock(&dev
->struct_mutex
);
17057 DRM_ERROR("failed to pin boot fb on pipe %d\n",
17058 to_intel_crtc(c
)->pipe
);
17059 drm_framebuffer_unreference(c
->primary
->fb
);
17060 c
->primary
->fb
= NULL
;
17061 c
->primary
->crtc
= c
->primary
->state
->crtc
= NULL
;
17062 update_state_fb(c
->primary
);
17063 c
->state
->plane_mask
&= ~(1 << drm_plane_index(c
->primary
));
17068 int intel_connector_register(struct drm_connector
*connector
)
17070 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
17073 ret
= intel_backlight_device_register(intel_connector
);
17083 void intel_connector_unregister(struct drm_connector
*connector
)
17085 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
17087 intel_backlight_device_unregister(intel_connector
);
17088 intel_panel_destroy_backlight(connector
);
17091 void intel_modeset_cleanup(struct drm_device
*dev
)
17093 struct drm_i915_private
*dev_priv
= to_i915(dev
);
17095 intel_disable_gt_powersave(dev_priv
);
17098 * Interrupts and polling as the first thing to avoid creating havoc.
17099 * Too much stuff here (turning of connectors, ...) would
17100 * experience fancy races otherwise.
17102 intel_irq_uninstall(dev_priv
);
17105 * Due to the hpd irq storm handling the hotplug work can re-arm the
17106 * poll handlers. Hence disable polling after hpd handling is shut down.
17108 drm_kms_helper_poll_fini(dev
);
17110 intel_unregister_dsm_handler();
17112 intel_fbc_global_disable(dev_priv
);
17114 /* flush any delayed tasks or pending work */
17115 flush_scheduled_work();
17117 drm_mode_config_cleanup(dev
);
17119 intel_cleanup_overlay(dev_priv
);
17121 intel_cleanup_gt_powersave(dev_priv
);
17123 intel_teardown_gmbus(dev
);
17126 void intel_connector_attach_encoder(struct intel_connector
*connector
,
17127 struct intel_encoder
*encoder
)
17129 connector
->encoder
= encoder
;
17130 drm_mode_connector_attach_encoder(&connector
->base
,
17135 * set vga decode state - true == enable VGA decode
17137 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
17139 struct drm_i915_private
*dev_priv
= to_i915(dev
);
17140 unsigned reg
= INTEL_INFO(dev
)->gen
>= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
17143 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
17144 DRM_ERROR("failed to read control word\n");
17148 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
17152 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
17154 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
17156 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
17157 DRM_ERROR("failed to write control word\n");
17164 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
17166 struct intel_display_error_state
{
17168 u32 power_well_driver
;
17170 int num_transcoders
;
17172 struct intel_cursor_error_state
{
17177 } cursor
[I915_MAX_PIPES
];
17179 struct intel_pipe_error_state
{
17180 bool power_domain_on
;
17183 } pipe
[I915_MAX_PIPES
];
17185 struct intel_plane_error_state
{
17193 } plane
[I915_MAX_PIPES
];
17195 struct intel_transcoder_error_state
{
17196 bool power_domain_on
;
17197 enum transcoder cpu_transcoder
;
17210 struct intel_display_error_state
*
17211 intel_display_capture_error_state(struct drm_i915_private
*dev_priv
)
17213 struct intel_display_error_state
*error
;
17214 int transcoders
[] = {
17222 if (INTEL_INFO(dev_priv
)->num_pipes
== 0)
17225 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
17229 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
17230 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
17232 for_each_pipe(dev_priv
, i
) {
17233 error
->pipe
[i
].power_domain_on
=
17234 __intel_display_power_is_enabled(dev_priv
,
17235 POWER_DOMAIN_PIPE(i
));
17236 if (!error
->pipe
[i
].power_domain_on
)
17239 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
17240 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
17241 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
17243 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
17244 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
17245 if (INTEL_GEN(dev_priv
) <= 3) {
17246 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
17247 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
17249 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
17250 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
17251 if (INTEL_GEN(dev_priv
) >= 4) {
17252 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
17253 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
17256 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
17258 if (HAS_GMCH_DISPLAY(dev_priv
))
17259 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
17262 /* Note: this does not include DSI transcoders. */
17263 error
->num_transcoders
= INTEL_INFO(dev_priv
)->num_pipes
;
17264 if (HAS_DDI(dev_priv
))
17265 error
->num_transcoders
++; /* Account for eDP. */
17267 for (i
= 0; i
< error
->num_transcoders
; i
++) {
17268 enum transcoder cpu_transcoder
= transcoders
[i
];
17270 error
->transcoder
[i
].power_domain_on
=
17271 __intel_display_power_is_enabled(dev_priv
,
17272 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
17273 if (!error
->transcoder
[i
].power_domain_on
)
17276 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
17278 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
17279 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
17280 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
17281 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
17282 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
17283 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
17284 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
17290 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
17293 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
17294 struct drm_device
*dev
,
17295 struct intel_display_error_state
*error
)
17297 struct drm_i915_private
*dev_priv
= to_i915(dev
);
17303 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev
)->num_pipes
);
17304 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
17305 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
17306 error
->power_well_driver
);
17307 for_each_pipe(dev_priv
, i
) {
17308 err_printf(m
, "Pipe [%d]:\n", i
);
17309 err_printf(m
, " Power: %s\n",
17310 onoff(error
->pipe
[i
].power_domain_on
));
17311 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
17312 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
17314 err_printf(m
, "Plane [%d]:\n", i
);
17315 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
17316 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
17317 if (INTEL_INFO(dev
)->gen
<= 3) {
17318 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
17319 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
17321 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
17322 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
17323 if (INTEL_INFO(dev
)->gen
>= 4) {
17324 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
17325 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
17328 err_printf(m
, "Cursor [%d]:\n", i
);
17329 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
17330 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
17331 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
17334 for (i
= 0; i
< error
->num_transcoders
; i
++) {
17335 err_printf(m
, "CPU transcoder: %s\n",
17336 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
17337 err_printf(m
, " Power: %s\n",
17338 onoff(error
->transcoder
[i
].power_domain_on
));
17339 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
17340 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
17341 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
17342 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
17343 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
17344 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
17345 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);