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 "i915_gem_dmabuf.h"
41 #include "intel_dsi.h"
42 #include "i915_trace.h"
43 #include <drm/drm_atomic.h>
44 #include <drm/drm_atomic_helper.h>
45 #include <drm/drm_dp_helper.h>
46 #include <drm/drm_crtc_helper.h>
47 #include <drm/drm_plane_helper.h>
48 #include <drm/drm_rect.h>
49 #include <linux/dma_remapping.h>
50 #include <linux/reservation.h>
52 static bool is_mmio_work(struct intel_flip_work
*work
)
54 return work
->mmio_work
.func
;
57 /* Primary plane formats for gen <= 3 */
58 static const uint32_t i8xx_primary_formats
[] = {
65 /* Primary plane formats for gen >= 4 */
66 static const uint32_t i965_primary_formats
[] = {
71 DRM_FORMAT_XRGB2101010
,
72 DRM_FORMAT_XBGR2101010
,
75 static const uint32_t skl_primary_formats
[] = {
82 DRM_FORMAT_XRGB2101010
,
83 DRM_FORMAT_XBGR2101010
,
91 static const uint32_t intel_cursor_formats
[] = {
95 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
96 struct intel_crtc_state
*pipe_config
);
97 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
98 struct intel_crtc_state
*pipe_config
);
100 static int intel_framebuffer_init(struct drm_device
*dev
,
101 struct intel_framebuffer
*ifb
,
102 struct drm_mode_fb_cmd2
*mode_cmd
,
103 struct drm_i915_gem_object
*obj
);
104 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
);
105 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
);
106 static void intel_set_pipe_src_size(struct intel_crtc
*intel_crtc
);
107 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
108 struct intel_link_m_n
*m_n
,
109 struct intel_link_m_n
*m2_n2
);
110 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
);
111 static void haswell_set_pipeconf(struct drm_crtc
*crtc
);
112 static void haswell_set_pipemisc(struct drm_crtc
*crtc
);
113 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
114 const struct intel_crtc_state
*pipe_config
);
115 static void chv_prepare_pll(struct intel_crtc
*crtc
,
116 const struct intel_crtc_state
*pipe_config
);
117 static void intel_begin_crtc_commit(struct drm_crtc
*, struct drm_crtc_state
*);
118 static void intel_finish_crtc_commit(struct drm_crtc
*, struct drm_crtc_state
*);
119 static void skl_init_scalers(struct drm_device
*dev
, struct intel_crtc
*intel_crtc
,
120 struct intel_crtc_state
*crtc_state
);
121 static void skylake_pfit_enable(struct intel_crtc
*crtc
);
122 static void ironlake_pfit_disable(struct intel_crtc
*crtc
, bool force
);
123 static void ironlake_pfit_enable(struct intel_crtc
*crtc
);
124 static void intel_modeset_setup_hw_state(struct drm_device
*dev
);
125 static void intel_pre_disable_primary_noatomic(struct drm_crtc
*crtc
);
126 static int ilk_max_pixel_rate(struct drm_atomic_state
*state
);
127 static int bxt_calc_cdclk(int max_pixclk
);
132 } dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
136 int p2_slow
, p2_fast
;
140 /* returns HPLL frequency in kHz */
141 static int valleyview_get_vco(struct drm_i915_private
*dev_priv
)
143 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
145 /* Obtain SKU information */
146 mutex_lock(&dev_priv
->sb_lock
);
147 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
148 CCK_FUSE_HPLL_FREQ_MASK
;
149 mutex_unlock(&dev_priv
->sb_lock
);
151 return vco_freq
[hpll_freq
] * 1000;
154 int vlv_get_cck_clock(struct drm_i915_private
*dev_priv
,
155 const char *name
, u32 reg
, int ref_freq
)
160 mutex_lock(&dev_priv
->sb_lock
);
161 val
= vlv_cck_read(dev_priv
, reg
);
162 mutex_unlock(&dev_priv
->sb_lock
);
164 divider
= val
& CCK_FREQUENCY_VALUES
;
166 WARN((val
& CCK_FREQUENCY_STATUS
) !=
167 (divider
<< CCK_FREQUENCY_STATUS_SHIFT
),
168 "%s change in progress\n", name
);
170 return DIV_ROUND_CLOSEST(ref_freq
<< 1, divider
+ 1);
173 static int vlv_get_cck_clock_hpll(struct drm_i915_private
*dev_priv
,
174 const char *name
, u32 reg
)
176 if (dev_priv
->hpll_freq
== 0)
177 dev_priv
->hpll_freq
= valleyview_get_vco(dev_priv
);
179 return vlv_get_cck_clock(dev_priv
, name
, reg
,
180 dev_priv
->hpll_freq
);
184 intel_pch_rawclk(struct drm_i915_private
*dev_priv
)
186 return (I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
) * 1000;
190 intel_vlv_hrawclk(struct drm_i915_private
*dev_priv
)
192 /* RAWCLK_FREQ_VLV register updated from power well code */
193 return vlv_get_cck_clock_hpll(dev_priv
, "hrawclk",
194 CCK_DISPLAY_REF_CLOCK_CONTROL
);
198 intel_g4x_hrawclk(struct drm_i915_private
*dev_priv
)
202 /* hrawclock is 1/4 the FSB frequency */
203 clkcfg
= I915_READ(CLKCFG
);
204 switch (clkcfg
& CLKCFG_FSB_MASK
) {
213 case CLKCFG_FSB_1067
:
215 case CLKCFG_FSB_1333
:
217 /* these two are just a guess; one of them might be right */
218 case CLKCFG_FSB_1600
:
219 case CLKCFG_FSB_1600_ALT
:
226 void intel_update_rawclk(struct drm_i915_private
*dev_priv
)
228 if (HAS_PCH_SPLIT(dev_priv
))
229 dev_priv
->rawclk_freq
= intel_pch_rawclk(dev_priv
);
230 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
231 dev_priv
->rawclk_freq
= intel_vlv_hrawclk(dev_priv
);
232 else if (IS_G4X(dev_priv
) || IS_PINEVIEW(dev_priv
))
233 dev_priv
->rawclk_freq
= intel_g4x_hrawclk(dev_priv
);
235 return; /* no rawclk on other platforms, or no need to know it */
237 DRM_DEBUG_DRIVER("rawclk rate: %d kHz\n", dev_priv
->rawclk_freq
);
240 static void intel_update_czclk(struct drm_i915_private
*dev_priv
)
242 if (!(IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)))
245 dev_priv
->czclk_freq
= vlv_get_cck_clock_hpll(dev_priv
, "czclk",
246 CCK_CZ_CLOCK_CONTROL
);
248 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv
->czclk_freq
);
251 static inline u32
/* units of 100MHz */
252 intel_fdi_link_freq(struct drm_i915_private
*dev_priv
,
253 const struct intel_crtc_state
*pipe_config
)
255 if (HAS_DDI(dev_priv
))
256 return pipe_config
->port_clock
; /* SPLL */
257 else if (IS_GEN5(dev_priv
))
258 return ((I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2) * 10000;
263 static const struct intel_limit intel_limits_i8xx_dac
= {
264 .dot
= { .min
= 25000, .max
= 350000 },
265 .vco
= { .min
= 908000, .max
= 1512000 },
266 .n
= { .min
= 2, .max
= 16 },
267 .m
= { .min
= 96, .max
= 140 },
268 .m1
= { .min
= 18, .max
= 26 },
269 .m2
= { .min
= 6, .max
= 16 },
270 .p
= { .min
= 4, .max
= 128 },
271 .p1
= { .min
= 2, .max
= 33 },
272 .p2
= { .dot_limit
= 165000,
273 .p2_slow
= 4, .p2_fast
= 2 },
276 static const struct intel_limit intel_limits_i8xx_dvo
= {
277 .dot
= { .min
= 25000, .max
= 350000 },
278 .vco
= { .min
= 908000, .max
= 1512000 },
279 .n
= { .min
= 2, .max
= 16 },
280 .m
= { .min
= 96, .max
= 140 },
281 .m1
= { .min
= 18, .max
= 26 },
282 .m2
= { .min
= 6, .max
= 16 },
283 .p
= { .min
= 4, .max
= 128 },
284 .p1
= { .min
= 2, .max
= 33 },
285 .p2
= { .dot_limit
= 165000,
286 .p2_slow
= 4, .p2_fast
= 4 },
289 static const struct intel_limit intel_limits_i8xx_lvds
= {
290 .dot
= { .min
= 25000, .max
= 350000 },
291 .vco
= { .min
= 908000, .max
= 1512000 },
292 .n
= { .min
= 2, .max
= 16 },
293 .m
= { .min
= 96, .max
= 140 },
294 .m1
= { .min
= 18, .max
= 26 },
295 .m2
= { .min
= 6, .max
= 16 },
296 .p
= { .min
= 4, .max
= 128 },
297 .p1
= { .min
= 1, .max
= 6 },
298 .p2
= { .dot_limit
= 165000,
299 .p2_slow
= 14, .p2_fast
= 7 },
302 static const struct intel_limit intel_limits_i9xx_sdvo
= {
303 .dot
= { .min
= 20000, .max
= 400000 },
304 .vco
= { .min
= 1400000, .max
= 2800000 },
305 .n
= { .min
= 1, .max
= 6 },
306 .m
= { .min
= 70, .max
= 120 },
307 .m1
= { .min
= 8, .max
= 18 },
308 .m2
= { .min
= 3, .max
= 7 },
309 .p
= { .min
= 5, .max
= 80 },
310 .p1
= { .min
= 1, .max
= 8 },
311 .p2
= { .dot_limit
= 200000,
312 .p2_slow
= 10, .p2_fast
= 5 },
315 static const struct intel_limit intel_limits_i9xx_lvds
= {
316 .dot
= { .min
= 20000, .max
= 400000 },
317 .vco
= { .min
= 1400000, .max
= 2800000 },
318 .n
= { .min
= 1, .max
= 6 },
319 .m
= { .min
= 70, .max
= 120 },
320 .m1
= { .min
= 8, .max
= 18 },
321 .m2
= { .min
= 3, .max
= 7 },
322 .p
= { .min
= 7, .max
= 98 },
323 .p1
= { .min
= 1, .max
= 8 },
324 .p2
= { .dot_limit
= 112000,
325 .p2_slow
= 14, .p2_fast
= 7 },
329 static const struct intel_limit intel_limits_g4x_sdvo
= {
330 .dot
= { .min
= 25000, .max
= 270000 },
331 .vco
= { .min
= 1750000, .max
= 3500000},
332 .n
= { .min
= 1, .max
= 4 },
333 .m
= { .min
= 104, .max
= 138 },
334 .m1
= { .min
= 17, .max
= 23 },
335 .m2
= { .min
= 5, .max
= 11 },
336 .p
= { .min
= 10, .max
= 30 },
337 .p1
= { .min
= 1, .max
= 3},
338 .p2
= { .dot_limit
= 270000,
344 static const struct intel_limit intel_limits_g4x_hdmi
= {
345 .dot
= { .min
= 22000, .max
= 400000 },
346 .vco
= { .min
= 1750000, .max
= 3500000},
347 .n
= { .min
= 1, .max
= 4 },
348 .m
= { .min
= 104, .max
= 138 },
349 .m1
= { .min
= 16, .max
= 23 },
350 .m2
= { .min
= 5, .max
= 11 },
351 .p
= { .min
= 5, .max
= 80 },
352 .p1
= { .min
= 1, .max
= 8},
353 .p2
= { .dot_limit
= 165000,
354 .p2_slow
= 10, .p2_fast
= 5 },
357 static const struct intel_limit intel_limits_g4x_single_channel_lvds
= {
358 .dot
= { .min
= 20000, .max
= 115000 },
359 .vco
= { .min
= 1750000, .max
= 3500000 },
360 .n
= { .min
= 1, .max
= 3 },
361 .m
= { .min
= 104, .max
= 138 },
362 .m1
= { .min
= 17, .max
= 23 },
363 .m2
= { .min
= 5, .max
= 11 },
364 .p
= { .min
= 28, .max
= 112 },
365 .p1
= { .min
= 2, .max
= 8 },
366 .p2
= { .dot_limit
= 0,
367 .p2_slow
= 14, .p2_fast
= 14
371 static const struct intel_limit intel_limits_g4x_dual_channel_lvds
= {
372 .dot
= { .min
= 80000, .max
= 224000 },
373 .vco
= { .min
= 1750000, .max
= 3500000 },
374 .n
= { .min
= 1, .max
= 3 },
375 .m
= { .min
= 104, .max
= 138 },
376 .m1
= { .min
= 17, .max
= 23 },
377 .m2
= { .min
= 5, .max
= 11 },
378 .p
= { .min
= 14, .max
= 42 },
379 .p1
= { .min
= 2, .max
= 6 },
380 .p2
= { .dot_limit
= 0,
381 .p2_slow
= 7, .p2_fast
= 7
385 static const struct intel_limit intel_limits_pineview_sdvo
= {
386 .dot
= { .min
= 20000, .max
= 400000},
387 .vco
= { .min
= 1700000, .max
= 3500000 },
388 /* Pineview's Ncounter is a ring counter */
389 .n
= { .min
= 3, .max
= 6 },
390 .m
= { .min
= 2, .max
= 256 },
391 /* Pineview only has one combined m divider, which we treat as m2. */
392 .m1
= { .min
= 0, .max
= 0 },
393 .m2
= { .min
= 0, .max
= 254 },
394 .p
= { .min
= 5, .max
= 80 },
395 .p1
= { .min
= 1, .max
= 8 },
396 .p2
= { .dot_limit
= 200000,
397 .p2_slow
= 10, .p2_fast
= 5 },
400 static const struct intel_limit intel_limits_pineview_lvds
= {
401 .dot
= { .min
= 20000, .max
= 400000 },
402 .vco
= { .min
= 1700000, .max
= 3500000 },
403 .n
= { .min
= 3, .max
= 6 },
404 .m
= { .min
= 2, .max
= 256 },
405 .m1
= { .min
= 0, .max
= 0 },
406 .m2
= { .min
= 0, .max
= 254 },
407 .p
= { .min
= 7, .max
= 112 },
408 .p1
= { .min
= 1, .max
= 8 },
409 .p2
= { .dot_limit
= 112000,
410 .p2_slow
= 14, .p2_fast
= 14 },
413 /* Ironlake / Sandybridge
415 * We calculate clock using (register_value + 2) for N/M1/M2, so here
416 * the range value for them is (actual_value - 2).
418 static const struct intel_limit intel_limits_ironlake_dac
= {
419 .dot
= { .min
= 25000, .max
= 350000 },
420 .vco
= { .min
= 1760000, .max
= 3510000 },
421 .n
= { .min
= 1, .max
= 5 },
422 .m
= { .min
= 79, .max
= 127 },
423 .m1
= { .min
= 12, .max
= 22 },
424 .m2
= { .min
= 5, .max
= 9 },
425 .p
= { .min
= 5, .max
= 80 },
426 .p1
= { .min
= 1, .max
= 8 },
427 .p2
= { .dot_limit
= 225000,
428 .p2_slow
= 10, .p2_fast
= 5 },
431 static const struct intel_limit intel_limits_ironlake_single_lvds
= {
432 .dot
= { .min
= 25000, .max
= 350000 },
433 .vco
= { .min
= 1760000, .max
= 3510000 },
434 .n
= { .min
= 1, .max
= 3 },
435 .m
= { .min
= 79, .max
= 118 },
436 .m1
= { .min
= 12, .max
= 22 },
437 .m2
= { .min
= 5, .max
= 9 },
438 .p
= { .min
= 28, .max
= 112 },
439 .p1
= { .min
= 2, .max
= 8 },
440 .p2
= { .dot_limit
= 225000,
441 .p2_slow
= 14, .p2_fast
= 14 },
444 static const struct intel_limit intel_limits_ironlake_dual_lvds
= {
445 .dot
= { .min
= 25000, .max
= 350000 },
446 .vco
= { .min
= 1760000, .max
= 3510000 },
447 .n
= { .min
= 1, .max
= 3 },
448 .m
= { .min
= 79, .max
= 127 },
449 .m1
= { .min
= 12, .max
= 22 },
450 .m2
= { .min
= 5, .max
= 9 },
451 .p
= { .min
= 14, .max
= 56 },
452 .p1
= { .min
= 2, .max
= 8 },
453 .p2
= { .dot_limit
= 225000,
454 .p2_slow
= 7, .p2_fast
= 7 },
457 /* LVDS 100mhz refclk limits. */
458 static const struct intel_limit intel_limits_ironlake_single_lvds_100m
= {
459 .dot
= { .min
= 25000, .max
= 350000 },
460 .vco
= { .min
= 1760000, .max
= 3510000 },
461 .n
= { .min
= 1, .max
= 2 },
462 .m
= { .min
= 79, .max
= 126 },
463 .m1
= { .min
= 12, .max
= 22 },
464 .m2
= { .min
= 5, .max
= 9 },
465 .p
= { .min
= 28, .max
= 112 },
466 .p1
= { .min
= 2, .max
= 8 },
467 .p2
= { .dot_limit
= 225000,
468 .p2_slow
= 14, .p2_fast
= 14 },
471 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m
= {
472 .dot
= { .min
= 25000, .max
= 350000 },
473 .vco
= { .min
= 1760000, .max
= 3510000 },
474 .n
= { .min
= 1, .max
= 3 },
475 .m
= { .min
= 79, .max
= 126 },
476 .m1
= { .min
= 12, .max
= 22 },
477 .m2
= { .min
= 5, .max
= 9 },
478 .p
= { .min
= 14, .max
= 42 },
479 .p1
= { .min
= 2, .max
= 6 },
480 .p2
= { .dot_limit
= 225000,
481 .p2_slow
= 7, .p2_fast
= 7 },
484 static const struct intel_limit intel_limits_vlv
= {
486 * These are the data rate limits (measured in fast clocks)
487 * since those are the strictest limits we have. The fast
488 * clock and actual rate limits are more relaxed, so checking
489 * them would make no difference.
491 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
492 .vco
= { .min
= 4000000, .max
= 6000000 },
493 .n
= { .min
= 1, .max
= 7 },
494 .m1
= { .min
= 2, .max
= 3 },
495 .m2
= { .min
= 11, .max
= 156 },
496 .p1
= { .min
= 2, .max
= 3 },
497 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
500 static const struct intel_limit intel_limits_chv
= {
502 * These are the data rate limits (measured in fast clocks)
503 * since those are the strictest limits we have. The fast
504 * clock and actual rate limits are more relaxed, so checking
505 * them would make no difference.
507 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
508 .vco
= { .min
= 4800000, .max
= 6480000 },
509 .n
= { .min
= 1, .max
= 1 },
510 .m1
= { .min
= 2, .max
= 2 },
511 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
512 .p1
= { .min
= 2, .max
= 4 },
513 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
516 static const struct intel_limit intel_limits_bxt
= {
517 /* FIXME: find real dot limits */
518 .dot
= { .min
= 0, .max
= INT_MAX
},
519 .vco
= { .min
= 4800000, .max
= 6700000 },
520 .n
= { .min
= 1, .max
= 1 },
521 .m1
= { .min
= 2, .max
= 2 },
522 /* FIXME: find real m2 limits */
523 .m2
= { .min
= 2 << 22, .max
= 255 << 22 },
524 .p1
= { .min
= 2, .max
= 4 },
525 .p2
= { .p2_slow
= 1, .p2_fast
= 20 },
529 needs_modeset(struct drm_crtc_state
*state
)
531 return drm_atomic_crtc_needs_modeset(state
);
535 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
536 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
537 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
538 * The helpers' return value is the rate of the clock that is fed to the
539 * display engine's pipe which can be the above fast dot clock rate or a
540 * divided-down version of it.
542 /* m1 is reserved as 0 in Pineview, n is a ring counter */
543 static int pnv_calc_dpll_params(int refclk
, struct dpll
*clock
)
545 clock
->m
= clock
->m2
+ 2;
546 clock
->p
= clock
->p1
* clock
->p2
;
547 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
549 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
550 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
555 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
557 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
560 static int i9xx_calc_dpll_params(int refclk
, struct dpll
*clock
)
562 clock
->m
= i9xx_dpll_compute_m(clock
);
563 clock
->p
= clock
->p1
* clock
->p2
;
564 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
566 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
567 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
572 static int vlv_calc_dpll_params(int refclk
, struct dpll
*clock
)
574 clock
->m
= clock
->m1
* clock
->m2
;
575 clock
->p
= clock
->p1
* clock
->p2
;
576 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
578 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
579 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
581 return clock
->dot
/ 5;
584 int chv_calc_dpll_params(int refclk
, struct dpll
*clock
)
586 clock
->m
= clock
->m1
* clock
->m2
;
587 clock
->p
= clock
->p1
* clock
->p2
;
588 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
590 clock
->vco
= DIV_ROUND_CLOSEST_ULL((uint64_t)refclk
* clock
->m
,
592 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
594 return clock
->dot
/ 5;
597 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
599 * Returns whether the given set of divisors are valid for a given refclk with
600 * the given connectors.
603 static bool intel_PLL_is_valid(struct drm_device
*dev
,
604 const struct intel_limit
*limit
,
605 const struct dpll
*clock
)
607 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
608 INTELPllInvalid("n out of range\n");
609 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
610 INTELPllInvalid("p1 out of range\n");
611 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
612 INTELPllInvalid("m2 out of range\n");
613 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
614 INTELPllInvalid("m1 out of range\n");
616 if (!IS_PINEVIEW(dev
) && !IS_VALLEYVIEW(dev
) &&
617 !IS_CHERRYVIEW(dev
) && !IS_BROXTON(dev
))
618 if (clock
->m1
<= clock
->m2
)
619 INTELPllInvalid("m1 <= m2\n");
621 if (!IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
) && !IS_BROXTON(dev
)) {
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(dev
, limit
,
705 clock
.p
!= match_clock
->p
)
708 this_err
= abs(clock
.dot
- target
);
709 if (this_err
< err
) {
718 return (err
!= target
);
722 * Returns a set of divisors for the desired target clock with the given
723 * refclk, or FALSE. The returned values represent the clock equation:
724 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
726 * Target and reference clocks are specified in kHz.
728 * If match_clock is provided, then best_clock P divider must match the P
729 * divider from @match_clock used for LVDS downclocking.
732 pnv_find_best_dpll(const struct intel_limit
*limit
,
733 struct intel_crtc_state
*crtc_state
,
734 int target
, int refclk
, struct dpll
*match_clock
,
735 struct dpll
*best_clock
)
737 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
741 memset(best_clock
, 0, sizeof(*best_clock
));
743 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
745 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
747 for (clock
.m2
= limit
->m2
.min
;
748 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
749 for (clock
.n
= limit
->n
.min
;
750 clock
.n
<= limit
->n
.max
; clock
.n
++) {
751 for (clock
.p1
= limit
->p1
.min
;
752 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
755 pnv_calc_dpll_params(refclk
, &clock
);
756 if (!intel_PLL_is_valid(dev
, limit
,
760 clock
.p
!= match_clock
->p
)
763 this_err
= abs(clock
.dot
- target
);
764 if (this_err
< err
) {
773 return (err
!= target
);
777 * Returns a set of divisors for the desired target clock with the given
778 * refclk, or FALSE. The returned values represent the clock equation:
779 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
781 * Target and reference clocks are specified in kHz.
783 * If match_clock is provided, then best_clock P divider must match the P
784 * divider from @match_clock used for LVDS downclocking.
787 g4x_find_best_dpll(const struct intel_limit
*limit
,
788 struct intel_crtc_state
*crtc_state
,
789 int target
, int refclk
, struct dpll
*match_clock
,
790 struct dpll
*best_clock
)
792 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
796 /* approximately equals target * 0.00585 */
797 int err_most
= (target
>> 8) + (target
>> 9);
799 memset(best_clock
, 0, sizeof(*best_clock
));
801 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
803 max_n
= limit
->n
.max
;
804 /* based on hardware requirement, prefer smaller n to precision */
805 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
806 /* based on hardware requirement, prefere larger m1,m2 */
807 for (clock
.m1
= limit
->m1
.max
;
808 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
809 for (clock
.m2
= limit
->m2
.max
;
810 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
811 for (clock
.p1
= limit
->p1
.max
;
812 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
815 i9xx_calc_dpll_params(refclk
, &clock
);
816 if (!intel_PLL_is_valid(dev
, limit
,
820 this_err
= abs(clock
.dot
- target
);
821 if (this_err
< err_most
) {
835 * Check if the calculated PLL configuration is more optimal compared to the
836 * best configuration and error found so far. Return the calculated error.
838 static bool vlv_PLL_is_optimal(struct drm_device
*dev
, int target_freq
,
839 const struct dpll
*calculated_clock
,
840 const struct dpll
*best_clock
,
841 unsigned int best_error_ppm
,
842 unsigned int *error_ppm
)
845 * For CHV ignore the error and consider only the P value.
846 * Prefer a bigger P value based on HW requirements.
848 if (IS_CHERRYVIEW(dev
)) {
851 return calculated_clock
->p
> best_clock
->p
;
854 if (WARN_ON_ONCE(!target_freq
))
857 *error_ppm
= div_u64(1000000ULL *
858 abs(target_freq
- calculated_clock
->dot
),
861 * Prefer a better P value over a better (smaller) error if the error
862 * is small. Ensure this preference for future configurations too by
863 * setting the error to 0.
865 if (*error_ppm
< 100 && calculated_clock
->p
> best_clock
->p
) {
871 return *error_ppm
+ 10 < best_error_ppm
;
875 * Returns a set of divisors for the desired target clock with the given
876 * refclk, or FALSE. The returned values represent the clock equation:
877 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
880 vlv_find_best_dpll(const struct intel_limit
*limit
,
881 struct intel_crtc_state
*crtc_state
,
882 int target
, int refclk
, struct dpll
*match_clock
,
883 struct dpll
*best_clock
)
885 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
886 struct drm_device
*dev
= crtc
->base
.dev
;
888 unsigned int bestppm
= 1000000;
889 /* min update 19.2 MHz */
890 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
893 target
*= 5; /* fast clock */
895 memset(best_clock
, 0, sizeof(*best_clock
));
897 /* based on hardware requirement, prefer smaller n to precision */
898 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
899 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
900 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
901 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
902 clock
.p
= clock
.p1
* clock
.p2
;
903 /* based on hardware requirement, prefer bigger m1,m2 values */
904 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
907 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
910 vlv_calc_dpll_params(refclk
, &clock
);
912 if (!intel_PLL_is_valid(dev
, limit
,
916 if (!vlv_PLL_is_optimal(dev
, target
,
934 * Returns a set of divisors for the desired target clock with the given
935 * refclk, or FALSE. The returned values represent the clock equation:
936 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
939 chv_find_best_dpll(const struct intel_limit
*limit
,
940 struct intel_crtc_state
*crtc_state
,
941 int target
, int refclk
, struct dpll
*match_clock
,
942 struct dpll
*best_clock
)
944 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
945 struct drm_device
*dev
= crtc
->base
.dev
;
946 unsigned int best_error_ppm
;
951 memset(best_clock
, 0, sizeof(*best_clock
));
952 best_error_ppm
= 1000000;
955 * Based on hardware doc, the n always set to 1, and m1 always
956 * set to 2. If requires to support 200Mhz refclk, we need to
957 * revisit this because n may not 1 anymore.
959 clock
.n
= 1, clock
.m1
= 2;
960 target
*= 5; /* fast clock */
962 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
963 for (clock
.p2
= limit
->p2
.p2_fast
;
964 clock
.p2
>= limit
->p2
.p2_slow
;
965 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
966 unsigned int error_ppm
;
968 clock
.p
= clock
.p1
* clock
.p2
;
970 m2
= DIV_ROUND_CLOSEST_ULL(((uint64_t)target
* clock
.p
*
971 clock
.n
) << 22, refclk
* clock
.m1
);
973 if (m2
> INT_MAX
/clock
.m1
)
978 chv_calc_dpll_params(refclk
, &clock
);
980 if (!intel_PLL_is_valid(dev
, limit
, &clock
))
983 if (!vlv_PLL_is_optimal(dev
, target
, &clock
, best_clock
,
984 best_error_ppm
, &error_ppm
))
988 best_error_ppm
= error_ppm
;
996 bool bxt_find_best_dpll(struct intel_crtc_state
*crtc_state
, int target_clock
,
997 struct dpll
*best_clock
)
1000 const struct intel_limit
*limit
= &intel_limits_bxt
;
1002 return chv_find_best_dpll(limit
, crtc_state
,
1003 target_clock
, refclk
, NULL
, best_clock
);
1006 bool intel_crtc_active(struct drm_crtc
*crtc
)
1008 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1010 /* Be paranoid as we can arrive here with only partial
1011 * state retrieved from the hardware during setup.
1013 * We can ditch the adjusted_mode.crtc_clock check as soon
1014 * as Haswell has gained clock readout/fastboot support.
1016 * We can ditch the crtc->primary->fb check as soon as we can
1017 * properly reconstruct framebuffers.
1019 * FIXME: The intel_crtc->active here should be switched to
1020 * crtc->state->active once we have proper CRTC states wired up
1023 return intel_crtc
->active
&& crtc
->primary
->state
->fb
&&
1024 intel_crtc
->config
->base
.adjusted_mode
.crtc_clock
;
1027 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
1030 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1031 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1033 return intel_crtc
->config
->cpu_transcoder
;
1036 static bool pipe_dsl_stopped(struct drm_device
*dev
, enum pipe pipe
)
1038 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1039 i915_reg_t reg
= PIPEDSL(pipe
);
1044 line_mask
= DSL_LINEMASK_GEN2
;
1046 line_mask
= DSL_LINEMASK_GEN3
;
1048 line1
= I915_READ(reg
) & line_mask
;
1050 line2
= I915_READ(reg
) & line_mask
;
1052 return line1
== line2
;
1056 * intel_wait_for_pipe_off - wait for pipe to turn off
1057 * @crtc: crtc whose pipe to wait for
1059 * After disabling a pipe, we can't wait for vblank in the usual way,
1060 * spinning on the vblank interrupt status bit, since we won't actually
1061 * see an interrupt when the pipe is disabled.
1063 * On Gen4 and above:
1064 * wait for the pipe register state bit to turn off
1067 * wait for the display line value to settle (it usually
1068 * ends up stopping at the start of the next frame).
1071 static void intel_wait_for_pipe_off(struct intel_crtc
*crtc
)
1073 struct drm_device
*dev
= crtc
->base
.dev
;
1074 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1075 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1076 enum pipe pipe
= crtc
->pipe
;
1078 if (INTEL_INFO(dev
)->gen
>= 4) {
1079 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
1081 /* Wait for the Pipe State to go off */
1082 if (intel_wait_for_register(dev_priv
,
1083 reg
, I965_PIPECONF_ACTIVE
, 0,
1085 WARN(1, "pipe_off wait timed out\n");
1087 /* Wait for the display line to settle */
1088 if (wait_for(pipe_dsl_stopped(dev
, pipe
), 100))
1089 WARN(1, "pipe_off wait timed out\n");
1093 /* Only for pre-ILK configs */
1094 void assert_pll(struct drm_i915_private
*dev_priv
,
1095 enum pipe pipe
, bool state
)
1100 val
= I915_READ(DPLL(pipe
));
1101 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1102 I915_STATE_WARN(cur_state
!= state
,
1103 "PLL state assertion failure (expected %s, current %s)\n",
1104 onoff(state
), onoff(cur_state
));
1107 /* XXX: the dsi pll is shared between MIPI DSI ports */
1108 void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1113 mutex_lock(&dev_priv
->sb_lock
);
1114 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1115 mutex_unlock(&dev_priv
->sb_lock
);
1117 cur_state
= val
& DSI_PLL_VCO_EN
;
1118 I915_STATE_WARN(cur_state
!= state
,
1119 "DSI PLL state assertion failure (expected %s, current %s)\n",
1120 onoff(state
), onoff(cur_state
));
1123 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1124 enum pipe pipe
, bool state
)
1127 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1130 if (HAS_DDI(dev_priv
)) {
1131 /* DDI does not have a specific FDI_TX register */
1132 u32 val
= I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder
));
1133 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1135 u32 val
= I915_READ(FDI_TX_CTL(pipe
));
1136 cur_state
= !!(val
& FDI_TX_ENABLE
);
1138 I915_STATE_WARN(cur_state
!= state
,
1139 "FDI TX state assertion failure (expected %s, current %s)\n",
1140 onoff(state
), onoff(cur_state
));
1142 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1143 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1145 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1146 enum pipe pipe
, bool state
)
1151 val
= I915_READ(FDI_RX_CTL(pipe
));
1152 cur_state
= !!(val
& FDI_RX_ENABLE
);
1153 I915_STATE_WARN(cur_state
!= state
,
1154 "FDI RX state assertion failure (expected %s, current %s)\n",
1155 onoff(state
), onoff(cur_state
));
1157 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1158 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1160 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1165 /* ILK FDI PLL is always enabled */
1166 if (IS_GEN5(dev_priv
))
1169 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1170 if (HAS_DDI(dev_priv
))
1173 val
= I915_READ(FDI_TX_CTL(pipe
));
1174 I915_STATE_WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1177 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1178 enum pipe pipe
, bool state
)
1183 val
= I915_READ(FDI_RX_CTL(pipe
));
1184 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1185 I915_STATE_WARN(cur_state
!= state
,
1186 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1187 onoff(state
), onoff(cur_state
));
1190 void assert_panel_unlocked(struct drm_i915_private
*dev_priv
,
1193 struct drm_device
*dev
= &dev_priv
->drm
;
1196 enum pipe panel_pipe
= PIPE_A
;
1199 if (WARN_ON(HAS_DDI(dev
)))
1202 if (HAS_PCH_SPLIT(dev
)) {
1205 pp_reg
= PCH_PP_CONTROL
;
1206 port_sel
= I915_READ(PCH_PP_ON_DELAYS
) & PANEL_PORT_SELECT_MASK
;
1208 if (port_sel
== PANEL_PORT_SELECT_LVDS
&&
1209 I915_READ(PCH_LVDS
) & LVDS_PIPEB_SELECT
)
1210 panel_pipe
= PIPE_B
;
1211 /* XXX: else fix for eDP */
1212 } else if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
1213 /* presumably write lock depends on pipe, not port select */
1214 pp_reg
= VLV_PIPE_PP_CONTROL(pipe
);
1217 pp_reg
= PP_CONTROL
;
1218 if (I915_READ(LVDS
) & LVDS_PIPEB_SELECT
)
1219 panel_pipe
= PIPE_B
;
1222 val
= I915_READ(pp_reg
);
1223 if (!(val
& PANEL_POWER_ON
) ||
1224 ((val
& PANEL_UNLOCK_MASK
) == PANEL_UNLOCK_REGS
))
1227 I915_STATE_WARN(panel_pipe
== pipe
&& locked
,
1228 "panel assertion failure, pipe %c regs locked\n",
1232 static void assert_cursor(struct drm_i915_private
*dev_priv
,
1233 enum pipe pipe
, bool state
)
1235 struct drm_device
*dev
= &dev_priv
->drm
;
1238 if (IS_845G(dev
) || IS_I865G(dev
))
1239 cur_state
= I915_READ(CURCNTR(PIPE_A
)) & CURSOR_ENABLE
;
1241 cur_state
= I915_READ(CURCNTR(pipe
)) & CURSOR_MODE
;
1243 I915_STATE_WARN(cur_state
!= state
,
1244 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1245 pipe_name(pipe
), onoff(state
), onoff(cur_state
));
1247 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1248 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1250 void assert_pipe(struct drm_i915_private
*dev_priv
,
1251 enum pipe pipe
, bool state
)
1254 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1256 enum intel_display_power_domain power_domain
;
1258 /* if we need the pipe quirk it must be always on */
1259 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1260 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1263 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
1264 if (intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
1265 u32 val
= I915_READ(PIPECONF(cpu_transcoder
));
1266 cur_state
= !!(val
& PIPECONF_ENABLE
);
1268 intel_display_power_put(dev_priv
, power_domain
);
1273 I915_STATE_WARN(cur_state
!= state
,
1274 "pipe %c assertion failure (expected %s, current %s)\n",
1275 pipe_name(pipe
), onoff(state
), onoff(cur_state
));
1278 static void assert_plane(struct drm_i915_private
*dev_priv
,
1279 enum plane plane
, bool state
)
1284 val
= I915_READ(DSPCNTR(plane
));
1285 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1286 I915_STATE_WARN(cur_state
!= state
,
1287 "plane %c assertion failure (expected %s, current %s)\n",
1288 plane_name(plane
), onoff(state
), onoff(cur_state
));
1291 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1292 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1294 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1297 struct drm_device
*dev
= &dev_priv
->drm
;
1300 /* Primary planes are fixed to pipes on gen4+ */
1301 if (INTEL_INFO(dev
)->gen
>= 4) {
1302 u32 val
= I915_READ(DSPCNTR(pipe
));
1303 I915_STATE_WARN(val
& DISPLAY_PLANE_ENABLE
,
1304 "plane %c assertion failure, should be disabled but not\n",
1309 /* Need to check both planes against the pipe */
1310 for_each_pipe(dev_priv
, i
) {
1311 u32 val
= I915_READ(DSPCNTR(i
));
1312 enum pipe cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1313 DISPPLANE_SEL_PIPE_SHIFT
;
1314 I915_STATE_WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1315 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1316 plane_name(i
), pipe_name(pipe
));
1320 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1323 struct drm_device
*dev
= &dev_priv
->drm
;
1326 if (INTEL_INFO(dev
)->gen
>= 9) {
1327 for_each_sprite(dev_priv
, pipe
, sprite
) {
1328 u32 val
= I915_READ(PLANE_CTL(pipe
, sprite
));
1329 I915_STATE_WARN(val
& PLANE_CTL_ENABLE
,
1330 "plane %d assertion failure, should be off on pipe %c but is still active\n",
1331 sprite
, pipe_name(pipe
));
1333 } else if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
1334 for_each_sprite(dev_priv
, pipe
, sprite
) {
1335 u32 val
= I915_READ(SPCNTR(pipe
, sprite
));
1336 I915_STATE_WARN(val
& SP_ENABLE
,
1337 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1338 sprite_name(pipe
, sprite
), pipe_name(pipe
));
1340 } else if (INTEL_INFO(dev
)->gen
>= 7) {
1341 u32 val
= I915_READ(SPRCTL(pipe
));
1342 I915_STATE_WARN(val
& SPRITE_ENABLE
,
1343 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1344 plane_name(pipe
), pipe_name(pipe
));
1345 } else if (INTEL_INFO(dev
)->gen
>= 5) {
1346 u32 val
= I915_READ(DVSCNTR(pipe
));
1347 I915_STATE_WARN(val
& DVS_ENABLE
,
1348 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1349 plane_name(pipe
), pipe_name(pipe
));
1353 static void assert_vblank_disabled(struct drm_crtc
*crtc
)
1355 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc
) == 0))
1356 drm_crtc_vblank_put(crtc
);
1359 void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1365 val
= I915_READ(PCH_TRANSCONF(pipe
));
1366 enabled
= !!(val
& TRANS_ENABLE
);
1367 I915_STATE_WARN(enabled
,
1368 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1372 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1373 enum pipe pipe
, u32 port_sel
, u32 val
)
1375 if ((val
& DP_PORT_EN
) == 0)
1378 if (HAS_PCH_CPT(dev_priv
)) {
1379 u32 trans_dp_ctl
= I915_READ(TRANS_DP_CTL(pipe
));
1380 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1382 } else if (IS_CHERRYVIEW(dev_priv
)) {
1383 if ((val
& DP_PIPE_MASK_CHV
) != DP_PIPE_SELECT_CHV(pipe
))
1386 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1392 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1393 enum pipe pipe
, u32 val
)
1395 if ((val
& SDVO_ENABLE
) == 0)
1398 if (HAS_PCH_CPT(dev_priv
)) {
1399 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1401 } else if (IS_CHERRYVIEW(dev_priv
)) {
1402 if ((val
& SDVO_PIPE_SEL_MASK_CHV
) != SDVO_PIPE_SEL_CHV(pipe
))
1405 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1411 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1412 enum pipe pipe
, u32 val
)
1414 if ((val
& LVDS_PORT_EN
) == 0)
1417 if (HAS_PCH_CPT(dev_priv
)) {
1418 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1421 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1427 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1428 enum pipe pipe
, u32 val
)
1430 if ((val
& ADPA_DAC_ENABLE
) == 0)
1432 if (HAS_PCH_CPT(dev_priv
)) {
1433 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1436 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1442 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1443 enum pipe pipe
, i915_reg_t reg
,
1446 u32 val
= I915_READ(reg
);
1447 I915_STATE_WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1448 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1449 i915_mmio_reg_offset(reg
), pipe_name(pipe
));
1451 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
) && (val
& DP_PORT_EN
) == 0
1452 && (val
& DP_PIPEB_SELECT
),
1453 "IBX PCH dp port still using transcoder B\n");
1456 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1457 enum pipe pipe
, i915_reg_t reg
)
1459 u32 val
= I915_READ(reg
);
1460 I915_STATE_WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1461 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1462 i915_mmio_reg_offset(reg
), pipe_name(pipe
));
1464 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
) && (val
& SDVO_ENABLE
) == 0
1465 && (val
& SDVO_PIPE_B_SELECT
),
1466 "IBX PCH hdmi port still using transcoder B\n");
1469 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1474 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1475 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1476 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1478 val
= I915_READ(PCH_ADPA
);
1479 I915_STATE_WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1480 "PCH VGA enabled on transcoder %c, should be disabled\n",
1483 val
= I915_READ(PCH_LVDS
);
1484 I915_STATE_WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1485 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1488 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1489 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1490 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1493 static void _vlv_enable_pll(struct intel_crtc
*crtc
,
1494 const struct intel_crtc_state
*pipe_config
)
1496 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1497 enum pipe pipe
= crtc
->pipe
;
1499 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1500 POSTING_READ(DPLL(pipe
));
1503 if (intel_wait_for_register(dev_priv
,
1508 DRM_ERROR("DPLL %d failed to lock\n", pipe
);
1511 static void vlv_enable_pll(struct intel_crtc
*crtc
,
1512 const struct intel_crtc_state
*pipe_config
)
1514 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1515 enum pipe pipe
= crtc
->pipe
;
1517 assert_pipe_disabled(dev_priv
, pipe
);
1519 /* PLL is protected by panel, make sure we can write it */
1520 assert_panel_unlocked(dev_priv
, pipe
);
1522 if (pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
)
1523 _vlv_enable_pll(crtc
, pipe_config
);
1525 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1526 POSTING_READ(DPLL_MD(pipe
));
1530 static void _chv_enable_pll(struct intel_crtc
*crtc
,
1531 const struct intel_crtc_state
*pipe_config
)
1533 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1534 enum pipe pipe
= crtc
->pipe
;
1535 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1538 mutex_lock(&dev_priv
->sb_lock
);
1540 /* Enable back the 10bit clock to display controller */
1541 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1542 tmp
|= DPIO_DCLKP_EN
;
1543 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), tmp
);
1545 mutex_unlock(&dev_priv
->sb_lock
);
1548 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1553 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1555 /* Check PLL is locked */
1556 if (intel_wait_for_register(dev_priv
,
1557 DPLL(pipe
), DPLL_LOCK_VLV
, DPLL_LOCK_VLV
,
1559 DRM_ERROR("PLL %d failed to lock\n", pipe
);
1562 static void chv_enable_pll(struct intel_crtc
*crtc
,
1563 const struct intel_crtc_state
*pipe_config
)
1565 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1566 enum pipe pipe
= crtc
->pipe
;
1568 assert_pipe_disabled(dev_priv
, pipe
);
1570 /* PLL is protected by panel, make sure we can write it */
1571 assert_panel_unlocked(dev_priv
, pipe
);
1573 if (pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
)
1574 _chv_enable_pll(crtc
, pipe_config
);
1576 if (pipe
!= PIPE_A
) {
1578 * WaPixelRepeatModeFixForC0:chv
1580 * DPLLCMD is AWOL. Use chicken bits to propagate
1581 * the value from DPLLBMD to either pipe B or C.
1583 I915_WRITE(CBR4_VLV
, pipe
== PIPE_B
? CBR_DPLLBMD_PIPE_B
: CBR_DPLLBMD_PIPE_C
);
1584 I915_WRITE(DPLL_MD(PIPE_B
), pipe_config
->dpll_hw_state
.dpll_md
);
1585 I915_WRITE(CBR4_VLV
, 0);
1586 dev_priv
->chv_dpll_md
[pipe
] = pipe_config
->dpll_hw_state
.dpll_md
;
1589 * DPLLB VGA mode also seems to cause problems.
1590 * We should always have it disabled.
1592 WARN_ON((I915_READ(DPLL(PIPE_B
)) & DPLL_VGA_MODE_DIS
) == 0);
1594 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1595 POSTING_READ(DPLL_MD(pipe
));
1599 static int intel_num_dvo_pipes(struct drm_device
*dev
)
1601 struct intel_crtc
*crtc
;
1604 for_each_intel_crtc(dev
, crtc
) {
1605 count
+= crtc
->base
.state
->active
&&
1606 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_DVO
);
1612 static void i9xx_enable_pll(struct intel_crtc
*crtc
)
1614 struct drm_device
*dev
= crtc
->base
.dev
;
1615 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1616 i915_reg_t reg
= DPLL(crtc
->pipe
);
1617 u32 dpll
= crtc
->config
->dpll_hw_state
.dpll
;
1619 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1621 /* PLL is protected by panel, make sure we can write it */
1622 if (IS_MOBILE(dev
) && !IS_I830(dev
))
1623 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1625 /* Enable DVO 2x clock on both PLLs if necessary */
1626 if (IS_I830(dev
) && intel_num_dvo_pipes(dev
) > 0) {
1628 * It appears to be important that we don't enable this
1629 * for the current pipe before otherwise configuring the
1630 * PLL. No idea how this should be handled if multiple
1631 * DVO outputs are enabled simultaneosly.
1633 dpll
|= DPLL_DVO_2X_MODE
;
1634 I915_WRITE(DPLL(!crtc
->pipe
),
1635 I915_READ(DPLL(!crtc
->pipe
)) | DPLL_DVO_2X_MODE
);
1639 * Apparently we need to have VGA mode enabled prior to changing
1640 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1641 * dividers, even though the register value does change.
1645 I915_WRITE(reg
, dpll
);
1647 /* Wait for the clocks to stabilize. */
1651 if (INTEL_INFO(dev
)->gen
>= 4) {
1652 I915_WRITE(DPLL_MD(crtc
->pipe
),
1653 crtc
->config
->dpll_hw_state
.dpll_md
);
1655 /* The pixel multiplier can only be updated once the
1656 * DPLL is enabled and the clocks are stable.
1658 * So write it again.
1660 I915_WRITE(reg
, dpll
);
1663 /* We do this three times for luck */
1664 I915_WRITE(reg
, dpll
);
1666 udelay(150); /* wait for warmup */
1667 I915_WRITE(reg
, dpll
);
1669 udelay(150); /* wait for warmup */
1670 I915_WRITE(reg
, dpll
);
1672 udelay(150); /* wait for warmup */
1676 * i9xx_disable_pll - disable a PLL
1677 * @dev_priv: i915 private structure
1678 * @pipe: pipe PLL to disable
1680 * Disable the PLL for @pipe, making sure the pipe is off first.
1682 * Note! This is for pre-ILK only.
1684 static void i9xx_disable_pll(struct intel_crtc
*crtc
)
1686 struct drm_device
*dev
= crtc
->base
.dev
;
1687 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1688 enum pipe pipe
= crtc
->pipe
;
1690 /* Disable DVO 2x clock on both PLLs if necessary */
1692 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_DVO
) &&
1693 !intel_num_dvo_pipes(dev
)) {
1694 I915_WRITE(DPLL(PIPE_B
),
1695 I915_READ(DPLL(PIPE_B
)) & ~DPLL_DVO_2X_MODE
);
1696 I915_WRITE(DPLL(PIPE_A
),
1697 I915_READ(DPLL(PIPE_A
)) & ~DPLL_DVO_2X_MODE
);
1700 /* Don't disable pipe or pipe PLLs if needed */
1701 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1702 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1705 /* Make sure the pipe isn't still relying on us */
1706 assert_pipe_disabled(dev_priv
, pipe
);
1708 I915_WRITE(DPLL(pipe
), DPLL_VGA_MODE_DIS
);
1709 POSTING_READ(DPLL(pipe
));
1712 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1716 /* Make sure the pipe isn't still relying on us */
1717 assert_pipe_disabled(dev_priv
, pipe
);
1719 val
= DPLL_INTEGRATED_REF_CLK_VLV
|
1720 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1722 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1724 I915_WRITE(DPLL(pipe
), val
);
1725 POSTING_READ(DPLL(pipe
));
1728 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1730 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1733 /* Make sure the pipe isn't still relying on us */
1734 assert_pipe_disabled(dev_priv
, pipe
);
1736 val
= DPLL_SSC_REF_CLK_CHV
|
1737 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1739 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1741 I915_WRITE(DPLL(pipe
), val
);
1742 POSTING_READ(DPLL(pipe
));
1744 mutex_lock(&dev_priv
->sb_lock
);
1746 /* Disable 10bit clock to display controller */
1747 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1748 val
&= ~DPIO_DCLKP_EN
;
1749 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1751 mutex_unlock(&dev_priv
->sb_lock
);
1754 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1755 struct intel_digital_port
*dport
,
1756 unsigned int expected_mask
)
1759 i915_reg_t dpll_reg
;
1761 switch (dport
->port
) {
1763 port_mask
= DPLL_PORTB_READY_MASK
;
1767 port_mask
= DPLL_PORTC_READY_MASK
;
1769 expected_mask
<<= 4;
1772 port_mask
= DPLL_PORTD_READY_MASK
;
1773 dpll_reg
= DPIO_PHY_STATUS
;
1779 if (intel_wait_for_register(dev_priv
,
1780 dpll_reg
, port_mask
, expected_mask
,
1782 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1783 port_name(dport
->port
), I915_READ(dpll_reg
) & port_mask
, expected_mask
);
1786 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1789 struct drm_device
*dev
= &dev_priv
->drm
;
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
)) {
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
,
1880 struct drm_device
*dev
= &dev_priv
->drm
;
1884 /* FDI relies on the transcoder */
1885 assert_fdi_tx_disabled(dev_priv
, pipe
);
1886 assert_fdi_rx_disabled(dev_priv
, pipe
);
1888 /* Ports must be off as well */
1889 assert_pch_ports_disabled(dev_priv
, pipe
);
1891 reg
= PCH_TRANSCONF(pipe
);
1892 val
= I915_READ(reg
);
1893 val
&= ~TRANS_ENABLE
;
1894 I915_WRITE(reg
, val
);
1895 /* wait for PCH transcoder off, transcoder state */
1896 if (intel_wait_for_register(dev_priv
,
1897 reg
, TRANS_STATE_ENABLE
, 0,
1899 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
1901 if (HAS_PCH_CPT(dev
)) {
1902 /* Workaround: Clear the timing override chicken bit again. */
1903 reg
= TRANS_CHICKEN2(pipe
);
1904 val
= I915_READ(reg
);
1905 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1906 I915_WRITE(reg
, val
);
1910 static void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
1914 val
= I915_READ(LPT_TRANSCONF
);
1915 val
&= ~TRANS_ENABLE
;
1916 I915_WRITE(LPT_TRANSCONF
, val
);
1917 /* wait for PCH transcoder off, transcoder state */
1918 if (intel_wait_for_register(dev_priv
,
1919 LPT_TRANSCONF
, TRANS_STATE_ENABLE
, 0,
1921 DRM_ERROR("Failed to disable PCH transcoder\n");
1923 /* Workaround: clear timing override bit. */
1924 val
= I915_READ(TRANS_CHICKEN2(PIPE_A
));
1925 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1926 I915_WRITE(TRANS_CHICKEN2(PIPE_A
), val
);
1930 * intel_enable_pipe - enable a pipe, asserting requirements
1931 * @crtc: crtc responsible for the pipe
1933 * Enable @crtc's pipe, making sure that various hardware specific requirements
1934 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
1936 static void intel_enable_pipe(struct intel_crtc
*crtc
)
1938 struct drm_device
*dev
= crtc
->base
.dev
;
1939 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1940 enum pipe pipe
= crtc
->pipe
;
1941 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1942 enum pipe pch_transcoder
;
1946 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe
));
1948 assert_planes_disabled(dev_priv
, pipe
);
1949 assert_cursor_disabled(dev_priv
, pipe
);
1950 assert_sprites_disabled(dev_priv
, pipe
);
1952 if (HAS_PCH_LPT(dev_priv
))
1953 pch_transcoder
= TRANSCODER_A
;
1955 pch_transcoder
= pipe
;
1958 * A pipe without a PLL won't actually be able to drive bits from
1959 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1962 if (HAS_GMCH_DISPLAY(dev_priv
))
1963 if (intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_DSI
))
1964 assert_dsi_pll_enabled(dev_priv
);
1966 assert_pll_enabled(dev_priv
, pipe
);
1968 if (crtc
->config
->has_pch_encoder
) {
1969 /* if driving the PCH, we need FDI enabled */
1970 assert_fdi_rx_pll_enabled(dev_priv
, pch_transcoder
);
1971 assert_fdi_tx_pll_enabled(dev_priv
,
1972 (enum pipe
) cpu_transcoder
);
1974 /* FIXME: assert CPU port conditions for SNB+ */
1977 reg
= PIPECONF(cpu_transcoder
);
1978 val
= I915_READ(reg
);
1979 if (val
& PIPECONF_ENABLE
) {
1980 WARN_ON(!((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1981 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
)));
1985 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
1989 * Until the pipe starts DSL will read as 0, which would cause
1990 * an apparent vblank timestamp jump, which messes up also the
1991 * frame count when it's derived from the timestamps. So let's
1992 * wait for the pipe to start properly before we call
1993 * drm_crtc_vblank_on()
1995 if (dev
->max_vblank_count
== 0 &&
1996 wait_for(intel_get_crtc_scanline(crtc
) != crtc
->scanline_offset
, 50))
1997 DRM_ERROR("pipe %c didn't start\n", pipe_name(pipe
));
2001 * intel_disable_pipe - disable a pipe, asserting requirements
2002 * @crtc: crtc whose pipes is to be disabled
2004 * Disable the pipe of @crtc, making sure that various hardware
2005 * specific requirements are met, if applicable, e.g. plane
2006 * disabled, panel fitter off, etc.
2008 * Will wait until the pipe has shut down before returning.
2010 static void intel_disable_pipe(struct intel_crtc
*crtc
)
2012 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
2013 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
2014 enum pipe pipe
= crtc
->pipe
;
2018 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe
));
2021 * Make sure planes won't keep trying to pump pixels to us,
2022 * or we might hang the display.
2024 assert_planes_disabled(dev_priv
, pipe
);
2025 assert_cursor_disabled(dev_priv
, pipe
);
2026 assert_sprites_disabled(dev_priv
, pipe
);
2028 reg
= PIPECONF(cpu_transcoder
);
2029 val
= I915_READ(reg
);
2030 if ((val
& PIPECONF_ENABLE
) == 0)
2034 * Double wide has implications for planes
2035 * so best keep it disabled when not needed.
2037 if (crtc
->config
->double_wide
)
2038 val
&= ~PIPECONF_DOUBLE_WIDE
;
2040 /* Don't disable pipe or pipe PLLs if needed */
2041 if (!(pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) &&
2042 !(pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
2043 val
&= ~PIPECONF_ENABLE
;
2045 I915_WRITE(reg
, val
);
2046 if ((val
& PIPECONF_ENABLE
) == 0)
2047 intel_wait_for_pipe_off(crtc
);
2050 static unsigned int intel_tile_size(const struct drm_i915_private
*dev_priv
)
2052 return IS_GEN2(dev_priv
) ? 2048 : 4096;
2055 static unsigned int intel_tile_width_bytes(const struct drm_i915_private
*dev_priv
,
2056 uint64_t fb_modifier
, unsigned int cpp
)
2058 switch (fb_modifier
) {
2059 case DRM_FORMAT_MOD_NONE
:
2061 case I915_FORMAT_MOD_X_TILED
:
2062 if (IS_GEN2(dev_priv
))
2066 case I915_FORMAT_MOD_Y_TILED
:
2067 if (IS_GEN2(dev_priv
) || HAS_128_BYTE_Y_TILING(dev_priv
))
2071 case I915_FORMAT_MOD_Yf_TILED
:
2087 MISSING_CASE(fb_modifier
);
2092 unsigned int intel_tile_height(const struct drm_i915_private
*dev_priv
,
2093 uint64_t fb_modifier
, unsigned int cpp
)
2095 if (fb_modifier
== DRM_FORMAT_MOD_NONE
)
2098 return intel_tile_size(dev_priv
) /
2099 intel_tile_width_bytes(dev_priv
, fb_modifier
, cpp
);
2102 /* Return the tile dimensions in pixel units */
2103 static void intel_tile_dims(const struct drm_i915_private
*dev_priv
,
2104 unsigned int *tile_width
,
2105 unsigned int *tile_height
,
2106 uint64_t fb_modifier
,
2109 unsigned int tile_width_bytes
=
2110 intel_tile_width_bytes(dev_priv
, fb_modifier
, cpp
);
2112 *tile_width
= tile_width_bytes
/ cpp
;
2113 *tile_height
= intel_tile_size(dev_priv
) / tile_width_bytes
;
2117 intel_fb_align_height(struct drm_device
*dev
, unsigned int height
,
2118 uint32_t pixel_format
, uint64_t fb_modifier
)
2120 unsigned int cpp
= drm_format_plane_cpp(pixel_format
, 0);
2121 unsigned int tile_height
= intel_tile_height(to_i915(dev
), fb_modifier
, cpp
);
2123 return ALIGN(height
, tile_height
);
2126 unsigned int intel_rotation_info_size(const struct intel_rotation_info
*rot_info
)
2128 unsigned int size
= 0;
2131 for (i
= 0 ; i
< ARRAY_SIZE(rot_info
->plane
); i
++)
2132 size
+= rot_info
->plane
[i
].width
* rot_info
->plane
[i
].height
;
2138 intel_fill_fb_ggtt_view(struct i915_ggtt_view
*view
,
2139 const struct drm_framebuffer
*fb
,
2140 unsigned int rotation
)
2142 if (intel_rotation_90_or_270(rotation
)) {
2143 *view
= i915_ggtt_view_rotated
;
2144 view
->params
.rotated
= to_intel_framebuffer(fb
)->rot_info
;
2146 *view
= i915_ggtt_view_normal
;
2151 intel_fill_fb_info(struct drm_i915_private
*dev_priv
,
2152 struct drm_framebuffer
*fb
)
2154 struct intel_rotation_info
*info
= &to_intel_framebuffer(fb
)->rot_info
;
2155 unsigned int tile_size
, tile_width
, tile_height
, cpp
;
2157 tile_size
= intel_tile_size(dev_priv
);
2159 cpp
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2160 intel_tile_dims(dev_priv
, &tile_width
, &tile_height
,
2161 fb
->modifier
[0], cpp
);
2163 info
->plane
[0].width
= DIV_ROUND_UP(fb
->pitches
[0], tile_width
* cpp
);
2164 info
->plane
[0].height
= DIV_ROUND_UP(fb
->height
, tile_height
);
2166 if (info
->pixel_format
== DRM_FORMAT_NV12
) {
2167 cpp
= drm_format_plane_cpp(fb
->pixel_format
, 1);
2168 intel_tile_dims(dev_priv
, &tile_width
, &tile_height
,
2169 fb
->modifier
[1], cpp
);
2171 info
->uv_offset
= fb
->offsets
[1];
2172 info
->plane
[1].width
= DIV_ROUND_UP(fb
->pitches
[1], tile_width
* cpp
);
2173 info
->plane
[1].height
= DIV_ROUND_UP(fb
->height
/ 2, tile_height
);
2177 static unsigned int intel_linear_alignment(const struct drm_i915_private
*dev_priv
)
2179 if (INTEL_INFO(dev_priv
)->gen
>= 9)
2181 else if (IS_BROADWATER(dev_priv
) || IS_CRESTLINE(dev_priv
) ||
2182 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
2184 else if (INTEL_INFO(dev_priv
)->gen
>= 4)
2190 static unsigned int intel_surf_alignment(const struct drm_i915_private
*dev_priv
,
2191 uint64_t fb_modifier
)
2193 switch (fb_modifier
) {
2194 case DRM_FORMAT_MOD_NONE
:
2195 return intel_linear_alignment(dev_priv
);
2196 case I915_FORMAT_MOD_X_TILED
:
2197 if (INTEL_INFO(dev_priv
)->gen
>= 9)
2200 case I915_FORMAT_MOD_Y_TILED
:
2201 case I915_FORMAT_MOD_Yf_TILED
:
2202 return 1 * 1024 * 1024;
2204 MISSING_CASE(fb_modifier
);
2210 intel_pin_and_fence_fb_obj(struct drm_framebuffer
*fb
,
2211 unsigned int rotation
)
2213 struct drm_device
*dev
= fb
->dev
;
2214 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2215 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2216 struct i915_ggtt_view view
;
2220 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
2222 alignment
= intel_surf_alignment(dev_priv
, fb
->modifier
[0]);
2224 intel_fill_fb_ggtt_view(&view
, fb
, rotation
);
2226 /* Note that the w/a also requires 64 PTE of padding following the
2227 * bo. We currently fill all unused PTE with the shadow page and so
2228 * we should always have valid PTE following the scanout preventing
2231 if (intel_scanout_needs_vtd_wa(dev_priv
) && alignment
< 256 * 1024)
2232 alignment
= 256 * 1024;
2235 * Global gtt pte registers are special registers which actually forward
2236 * writes to a chunk of system memory. Which means that there is no risk
2237 * that the register values disappear as soon as we call
2238 * intel_runtime_pm_put(), so it is correct to wrap only the
2239 * pin/unpin/fence and not more.
2241 intel_runtime_pm_get(dev_priv
);
2243 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
,
2248 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2249 * fence, whereas 965+ only requires a fence if using
2250 * framebuffer compression. For simplicity, we always install
2251 * a fence as the cost is not that onerous.
2253 if (view
.type
== I915_GGTT_VIEW_NORMAL
) {
2254 ret
= i915_gem_object_get_fence(obj
);
2255 if (ret
== -EDEADLK
) {
2257 * -EDEADLK means there are no free fences
2260 * This is propagated to atomic, but it uses
2261 * -EDEADLK to force a locking recovery, so
2262 * change the returned error to -EBUSY.
2269 i915_gem_object_pin_fence(obj
);
2272 intel_runtime_pm_put(dev_priv
);
2276 i915_gem_object_unpin_from_display_plane(obj
, &view
);
2278 intel_runtime_pm_put(dev_priv
);
2282 void intel_unpin_fb_obj(struct drm_framebuffer
*fb
, unsigned int rotation
)
2284 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2285 struct i915_ggtt_view view
;
2287 WARN_ON(!mutex_is_locked(&obj
->base
.dev
->struct_mutex
));
2289 intel_fill_fb_ggtt_view(&view
, fb
, rotation
);
2291 if (view
.type
== I915_GGTT_VIEW_NORMAL
)
2292 i915_gem_object_unpin_fence(obj
);
2294 i915_gem_object_unpin_from_display_plane(obj
, &view
);
2298 * Adjust the tile offset by moving the difference into
2301 * Input tile dimensions and pitch must already be
2302 * rotated to match x and y, and in pixel units.
2304 static u32
intel_adjust_tile_offset(int *x
, int *y
,
2305 unsigned int tile_width
,
2306 unsigned int tile_height
,
2307 unsigned int tile_size
,
2308 unsigned int pitch_tiles
,
2314 WARN_ON(old_offset
& (tile_size
- 1));
2315 WARN_ON(new_offset
& (tile_size
- 1));
2316 WARN_ON(new_offset
> old_offset
);
2318 tiles
= (old_offset
- new_offset
) / tile_size
;
2320 *y
+= tiles
/ pitch_tiles
* tile_height
;
2321 *x
+= tiles
% pitch_tiles
* tile_width
;
2327 * Computes the linear offset to the base tile and adjusts
2328 * x, y. bytes per pixel is assumed to be a power-of-two.
2330 * In the 90/270 rotated case, x and y are assumed
2331 * to be already rotated to match the rotated GTT view, and
2332 * pitch is the tile_height aligned framebuffer height.
2334 u32
intel_compute_tile_offset(int *x
, int *y
,
2335 const struct drm_framebuffer
*fb
, int plane
,
2337 unsigned int rotation
)
2339 const struct drm_i915_private
*dev_priv
= to_i915(fb
->dev
);
2340 uint64_t fb_modifier
= fb
->modifier
[plane
];
2341 unsigned int cpp
= drm_format_plane_cpp(fb
->pixel_format
, plane
);
2342 u32 offset
, offset_aligned
, alignment
;
2344 alignment
= intel_surf_alignment(dev_priv
, fb_modifier
);
2348 if (fb_modifier
!= DRM_FORMAT_MOD_NONE
) {
2349 unsigned int tile_size
, tile_width
, tile_height
;
2350 unsigned int tile_rows
, tiles
, pitch_tiles
;
2352 tile_size
= intel_tile_size(dev_priv
);
2353 intel_tile_dims(dev_priv
, &tile_width
, &tile_height
,
2356 if (intel_rotation_90_or_270(rotation
)) {
2357 pitch_tiles
= pitch
/ tile_height
;
2358 swap(tile_width
, tile_height
);
2360 pitch_tiles
= pitch
/ (tile_width
* cpp
);
2363 tile_rows
= *y
/ tile_height
;
2366 tiles
= *x
/ tile_width
;
2369 offset
= (tile_rows
* pitch_tiles
+ tiles
) * tile_size
;
2370 offset_aligned
= offset
& ~alignment
;
2372 intel_adjust_tile_offset(x
, y
, tile_width
, tile_height
,
2373 tile_size
, pitch_tiles
,
2374 offset
, offset_aligned
);
2376 offset
= *y
* pitch
+ *x
* cpp
;
2377 offset_aligned
= offset
& ~alignment
;
2379 *y
= (offset
& alignment
) / pitch
;
2380 *x
= ((offset
& alignment
) - *y
* pitch
) / cpp
;
2383 return offset_aligned
;
2386 static int i9xx_format_to_fourcc(int format
)
2389 case DISPPLANE_8BPP
:
2390 return DRM_FORMAT_C8
;
2391 case DISPPLANE_BGRX555
:
2392 return DRM_FORMAT_XRGB1555
;
2393 case DISPPLANE_BGRX565
:
2394 return DRM_FORMAT_RGB565
;
2396 case DISPPLANE_BGRX888
:
2397 return DRM_FORMAT_XRGB8888
;
2398 case DISPPLANE_RGBX888
:
2399 return DRM_FORMAT_XBGR8888
;
2400 case DISPPLANE_BGRX101010
:
2401 return DRM_FORMAT_XRGB2101010
;
2402 case DISPPLANE_RGBX101010
:
2403 return DRM_FORMAT_XBGR2101010
;
2407 static int skl_format_to_fourcc(int format
, bool rgb_order
, bool alpha
)
2410 case PLANE_CTL_FORMAT_RGB_565
:
2411 return DRM_FORMAT_RGB565
;
2413 case PLANE_CTL_FORMAT_XRGB_8888
:
2416 return DRM_FORMAT_ABGR8888
;
2418 return DRM_FORMAT_XBGR8888
;
2421 return DRM_FORMAT_ARGB8888
;
2423 return DRM_FORMAT_XRGB8888
;
2425 case PLANE_CTL_FORMAT_XRGB_2101010
:
2427 return DRM_FORMAT_XBGR2101010
;
2429 return DRM_FORMAT_XRGB2101010
;
2434 intel_alloc_initial_plane_obj(struct intel_crtc
*crtc
,
2435 struct intel_initial_plane_config
*plane_config
)
2437 struct drm_device
*dev
= crtc
->base
.dev
;
2438 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2439 struct i915_ggtt
*ggtt
= &dev_priv
->ggtt
;
2440 struct drm_i915_gem_object
*obj
= NULL
;
2441 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2442 struct drm_framebuffer
*fb
= &plane_config
->fb
->base
;
2443 u32 base_aligned
= round_down(plane_config
->base
, PAGE_SIZE
);
2444 u32 size_aligned
= round_up(plane_config
->base
+ plane_config
->size
,
2447 size_aligned
-= base_aligned
;
2449 if (plane_config
->size
== 0)
2452 /* If the FB is too big, just don't use it since fbdev is not very
2453 * important and we should probably use that space with FBC or other
2455 if (size_aligned
* 2 > ggtt
->stolen_usable_size
)
2458 mutex_lock(&dev
->struct_mutex
);
2460 obj
= i915_gem_object_create_stolen_for_preallocated(dev
,
2465 mutex_unlock(&dev
->struct_mutex
);
2469 obj
->tiling_mode
= plane_config
->tiling
;
2470 if (obj
->tiling_mode
== I915_TILING_X
)
2471 obj
->stride
= fb
->pitches
[0];
2473 mode_cmd
.pixel_format
= fb
->pixel_format
;
2474 mode_cmd
.width
= fb
->width
;
2475 mode_cmd
.height
= fb
->height
;
2476 mode_cmd
.pitches
[0] = fb
->pitches
[0];
2477 mode_cmd
.modifier
[0] = fb
->modifier
[0];
2478 mode_cmd
.flags
= DRM_MODE_FB_MODIFIERS
;
2480 if (intel_framebuffer_init(dev
, to_intel_framebuffer(fb
),
2482 DRM_DEBUG_KMS("intel fb init failed\n");
2486 mutex_unlock(&dev
->struct_mutex
);
2488 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj
);
2492 i915_gem_object_put(obj
);
2493 mutex_unlock(&dev
->struct_mutex
);
2497 /* Update plane->state->fb to match plane->fb after driver-internal updates */
2499 update_state_fb(struct drm_plane
*plane
)
2501 if (plane
->fb
== plane
->state
->fb
)
2504 if (plane
->state
->fb
)
2505 drm_framebuffer_unreference(plane
->state
->fb
);
2506 plane
->state
->fb
= plane
->fb
;
2507 if (plane
->state
->fb
)
2508 drm_framebuffer_reference(plane
->state
->fb
);
2512 intel_find_initial_plane_obj(struct intel_crtc
*intel_crtc
,
2513 struct intel_initial_plane_config
*plane_config
)
2515 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2516 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2518 struct intel_crtc
*i
;
2519 struct drm_i915_gem_object
*obj
;
2520 struct drm_plane
*primary
= intel_crtc
->base
.primary
;
2521 struct drm_plane_state
*plane_state
= primary
->state
;
2522 struct drm_crtc_state
*crtc_state
= intel_crtc
->base
.state
;
2523 struct intel_plane
*intel_plane
= to_intel_plane(primary
);
2524 struct intel_plane_state
*intel_state
=
2525 to_intel_plane_state(plane_state
);
2526 struct drm_framebuffer
*fb
;
2528 if (!plane_config
->fb
)
2531 if (intel_alloc_initial_plane_obj(intel_crtc
, plane_config
)) {
2532 fb
= &plane_config
->fb
->base
;
2536 kfree(plane_config
->fb
);
2539 * Failed to alloc the obj, check to see if we should share
2540 * an fb with another CRTC instead
2542 for_each_crtc(dev
, c
) {
2543 i
= to_intel_crtc(c
);
2545 if (c
== &intel_crtc
->base
)
2551 fb
= c
->primary
->fb
;
2555 obj
= intel_fb_obj(fb
);
2556 if (i915_gem_obj_ggtt_offset(obj
) == plane_config
->base
) {
2557 drm_framebuffer_reference(fb
);
2563 * We've failed to reconstruct the BIOS FB. Current display state
2564 * indicates that the primary plane is visible, but has a NULL FB,
2565 * which will lead to problems later if we don't fix it up. The
2566 * simplest solution is to just disable the primary plane now and
2567 * pretend the BIOS never had it enabled.
2569 to_intel_plane_state(plane_state
)->visible
= false;
2570 crtc_state
->plane_mask
&= ~(1 << drm_plane_index(primary
));
2571 intel_pre_disable_primary_noatomic(&intel_crtc
->base
);
2572 intel_plane
->disable_plane(primary
, &intel_crtc
->base
);
2577 plane_state
->src_x
= 0;
2578 plane_state
->src_y
= 0;
2579 plane_state
->src_w
= fb
->width
<< 16;
2580 plane_state
->src_h
= fb
->height
<< 16;
2582 plane_state
->crtc_x
= 0;
2583 plane_state
->crtc_y
= 0;
2584 plane_state
->crtc_w
= fb
->width
;
2585 plane_state
->crtc_h
= fb
->height
;
2587 intel_state
->src
.x1
= plane_state
->src_x
;
2588 intel_state
->src
.y1
= plane_state
->src_y
;
2589 intel_state
->src
.x2
= plane_state
->src_x
+ plane_state
->src_w
;
2590 intel_state
->src
.y2
= plane_state
->src_y
+ plane_state
->src_h
;
2591 intel_state
->dst
.x1
= plane_state
->crtc_x
;
2592 intel_state
->dst
.y1
= plane_state
->crtc_y
;
2593 intel_state
->dst
.x2
= plane_state
->crtc_x
+ plane_state
->crtc_w
;
2594 intel_state
->dst
.y2
= plane_state
->crtc_y
+ plane_state
->crtc_h
;
2596 obj
= intel_fb_obj(fb
);
2597 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2598 dev_priv
->preserve_bios_swizzle
= true;
2600 drm_framebuffer_reference(fb
);
2601 primary
->fb
= primary
->state
->fb
= fb
;
2602 primary
->crtc
= primary
->state
->crtc
= &intel_crtc
->base
;
2603 intel_crtc
->base
.state
->plane_mask
|= (1 << drm_plane_index(primary
));
2604 obj
->frontbuffer_bits
|= to_intel_plane(primary
)->frontbuffer_bit
;
2607 static void i9xx_update_primary_plane(struct drm_plane
*primary
,
2608 const struct intel_crtc_state
*crtc_state
,
2609 const struct intel_plane_state
*plane_state
)
2611 struct drm_device
*dev
= primary
->dev
;
2612 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2613 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
2614 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2615 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2616 int plane
= intel_crtc
->plane
;
2619 i915_reg_t reg
= DSPCNTR(plane
);
2620 unsigned int rotation
= plane_state
->base
.rotation
;
2621 int cpp
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2622 int x
= plane_state
->src
.x1
>> 16;
2623 int y
= plane_state
->src
.y1
>> 16;
2625 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2627 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2629 if (INTEL_INFO(dev
)->gen
< 4) {
2630 if (intel_crtc
->pipe
== PIPE_B
)
2631 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
2633 /* pipesrc and dspsize control the size that is scaled from,
2634 * which should always be the user's requested size.
2636 I915_WRITE(DSPSIZE(plane
),
2637 ((crtc_state
->pipe_src_h
- 1) << 16) |
2638 (crtc_state
->pipe_src_w
- 1));
2639 I915_WRITE(DSPPOS(plane
), 0);
2640 } else if (IS_CHERRYVIEW(dev
) && plane
== PLANE_B
) {
2641 I915_WRITE(PRIMSIZE(plane
),
2642 ((crtc_state
->pipe_src_h
- 1) << 16) |
2643 (crtc_state
->pipe_src_w
- 1));
2644 I915_WRITE(PRIMPOS(plane
), 0);
2645 I915_WRITE(PRIMCNSTALPHA(plane
), 0);
2648 switch (fb
->pixel_format
) {
2650 dspcntr
|= DISPPLANE_8BPP
;
2652 case DRM_FORMAT_XRGB1555
:
2653 dspcntr
|= DISPPLANE_BGRX555
;
2655 case DRM_FORMAT_RGB565
:
2656 dspcntr
|= DISPPLANE_BGRX565
;
2658 case DRM_FORMAT_XRGB8888
:
2659 dspcntr
|= DISPPLANE_BGRX888
;
2661 case DRM_FORMAT_XBGR8888
:
2662 dspcntr
|= DISPPLANE_RGBX888
;
2664 case DRM_FORMAT_XRGB2101010
:
2665 dspcntr
|= DISPPLANE_BGRX101010
;
2667 case DRM_FORMAT_XBGR2101010
:
2668 dspcntr
|= DISPPLANE_RGBX101010
;
2674 if (INTEL_INFO(dev
)->gen
>= 4 &&
2675 obj
->tiling_mode
!= I915_TILING_NONE
)
2676 dspcntr
|= DISPPLANE_TILED
;
2679 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2681 linear_offset
= y
* fb
->pitches
[0] + x
* cpp
;
2683 if (INTEL_INFO(dev
)->gen
>= 4) {
2684 intel_crtc
->dspaddr_offset
=
2685 intel_compute_tile_offset(&x
, &y
, fb
, 0,
2686 fb
->pitches
[0], rotation
);
2687 linear_offset
-= intel_crtc
->dspaddr_offset
;
2689 intel_crtc
->dspaddr_offset
= linear_offset
;
2692 if (rotation
== BIT(DRM_ROTATE_180
)) {
2693 dspcntr
|= DISPPLANE_ROTATE_180
;
2695 x
+= (crtc_state
->pipe_src_w
- 1);
2696 y
+= (crtc_state
->pipe_src_h
- 1);
2698 /* Finding the last pixel of the last line of the display
2699 data and adding to linear_offset*/
2701 (crtc_state
->pipe_src_h
- 1) * fb
->pitches
[0] +
2702 (crtc_state
->pipe_src_w
- 1) * cpp
;
2705 intel_crtc
->adjusted_x
= x
;
2706 intel_crtc
->adjusted_y
= y
;
2708 I915_WRITE(reg
, dspcntr
);
2710 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2711 if (INTEL_INFO(dev
)->gen
>= 4) {
2712 I915_WRITE(DSPSURF(plane
),
2713 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2714 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2715 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2717 I915_WRITE(DSPADDR(plane
), i915_gem_obj_ggtt_offset(obj
) + linear_offset
);
2721 static void i9xx_disable_primary_plane(struct drm_plane
*primary
,
2722 struct drm_crtc
*crtc
)
2724 struct drm_device
*dev
= crtc
->dev
;
2725 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2726 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2727 int plane
= intel_crtc
->plane
;
2729 I915_WRITE(DSPCNTR(plane
), 0);
2730 if (INTEL_INFO(dev_priv
)->gen
>= 4)
2731 I915_WRITE(DSPSURF(plane
), 0);
2733 I915_WRITE(DSPADDR(plane
), 0);
2734 POSTING_READ(DSPCNTR(plane
));
2737 static void ironlake_update_primary_plane(struct drm_plane
*primary
,
2738 const struct intel_crtc_state
*crtc_state
,
2739 const struct intel_plane_state
*plane_state
)
2741 struct drm_device
*dev
= primary
->dev
;
2742 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2743 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
2744 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2745 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2746 int plane
= intel_crtc
->plane
;
2749 i915_reg_t reg
= DSPCNTR(plane
);
2750 unsigned int rotation
= plane_state
->base
.rotation
;
2751 int cpp
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2752 int x
= plane_state
->src
.x1
>> 16;
2753 int y
= plane_state
->src
.y1
>> 16;
2755 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2756 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2758 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2759 dspcntr
|= DISPPLANE_PIPE_CSC_ENABLE
;
2761 switch (fb
->pixel_format
) {
2763 dspcntr
|= DISPPLANE_8BPP
;
2765 case DRM_FORMAT_RGB565
:
2766 dspcntr
|= DISPPLANE_BGRX565
;
2768 case DRM_FORMAT_XRGB8888
:
2769 dspcntr
|= DISPPLANE_BGRX888
;
2771 case DRM_FORMAT_XBGR8888
:
2772 dspcntr
|= DISPPLANE_RGBX888
;
2774 case DRM_FORMAT_XRGB2101010
:
2775 dspcntr
|= DISPPLANE_BGRX101010
;
2777 case DRM_FORMAT_XBGR2101010
:
2778 dspcntr
|= DISPPLANE_RGBX101010
;
2784 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2785 dspcntr
|= DISPPLANE_TILED
;
2787 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
))
2788 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2790 linear_offset
= y
* fb
->pitches
[0] + x
* cpp
;
2791 intel_crtc
->dspaddr_offset
=
2792 intel_compute_tile_offset(&x
, &y
, fb
, 0,
2793 fb
->pitches
[0], rotation
);
2794 linear_offset
-= intel_crtc
->dspaddr_offset
;
2795 if (rotation
== BIT(DRM_ROTATE_180
)) {
2796 dspcntr
|= DISPPLANE_ROTATE_180
;
2798 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
)) {
2799 x
+= (crtc_state
->pipe_src_w
- 1);
2800 y
+= (crtc_state
->pipe_src_h
- 1);
2802 /* Finding the last pixel of the last line of the display
2803 data and adding to linear_offset*/
2805 (crtc_state
->pipe_src_h
- 1) * fb
->pitches
[0] +
2806 (crtc_state
->pipe_src_w
- 1) * cpp
;
2810 intel_crtc
->adjusted_x
= x
;
2811 intel_crtc
->adjusted_y
= y
;
2813 I915_WRITE(reg
, dspcntr
);
2815 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2816 I915_WRITE(DSPSURF(plane
),
2817 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2818 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2819 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
2821 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2822 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2827 u32
intel_fb_stride_alignment(const struct drm_i915_private
*dev_priv
,
2828 uint64_t fb_modifier
, uint32_t pixel_format
)
2830 if (fb_modifier
== DRM_FORMAT_MOD_NONE
) {
2833 int cpp
= drm_format_plane_cpp(pixel_format
, 0);
2835 return intel_tile_width_bytes(dev_priv
, fb_modifier
, cpp
);
2839 u32
intel_plane_obj_offset(struct intel_plane
*intel_plane
,
2840 struct drm_i915_gem_object
*obj
,
2843 struct i915_ggtt_view view
;
2844 struct i915_vma
*vma
;
2847 intel_fill_fb_ggtt_view(&view
, intel_plane
->base
.state
->fb
,
2848 intel_plane
->base
.state
->rotation
);
2850 vma
= i915_gem_obj_to_ggtt_view(obj
, &view
);
2851 if (WARN(!vma
, "ggtt vma for display object not found! (view=%u)\n",
2855 offset
= vma
->node
.start
;
2858 offset
+= vma
->ggtt_view
.params
.rotated
.uv_start_page
*
2862 WARN_ON(upper_32_bits(offset
));
2864 return lower_32_bits(offset
);
2867 static void skl_detach_scaler(struct intel_crtc
*intel_crtc
, int id
)
2869 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2870 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2872 I915_WRITE(SKL_PS_CTRL(intel_crtc
->pipe
, id
), 0);
2873 I915_WRITE(SKL_PS_WIN_POS(intel_crtc
->pipe
, id
), 0);
2874 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc
->pipe
, id
), 0);
2878 * This function detaches (aka. unbinds) unused scalers in hardware
2880 static void skl_detach_scalers(struct intel_crtc
*intel_crtc
)
2882 struct intel_crtc_scaler_state
*scaler_state
;
2885 scaler_state
= &intel_crtc
->config
->scaler_state
;
2887 /* loop through and disable scalers that aren't in use */
2888 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
2889 if (!scaler_state
->scalers
[i
].in_use
)
2890 skl_detach_scaler(intel_crtc
, i
);
2894 u32
skl_plane_ctl_format(uint32_t pixel_format
)
2896 switch (pixel_format
) {
2898 return PLANE_CTL_FORMAT_INDEXED
;
2899 case DRM_FORMAT_RGB565
:
2900 return PLANE_CTL_FORMAT_RGB_565
;
2901 case DRM_FORMAT_XBGR8888
:
2902 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
;
2903 case DRM_FORMAT_XRGB8888
:
2904 return PLANE_CTL_FORMAT_XRGB_8888
;
2906 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
2907 * to be already pre-multiplied. We need to add a knob (or a different
2908 * DRM_FORMAT) for user-space to configure that.
2910 case DRM_FORMAT_ABGR8888
:
2911 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
|
2912 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
2913 case DRM_FORMAT_ARGB8888
:
2914 return PLANE_CTL_FORMAT_XRGB_8888
|
2915 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
2916 case DRM_FORMAT_XRGB2101010
:
2917 return PLANE_CTL_FORMAT_XRGB_2101010
;
2918 case DRM_FORMAT_XBGR2101010
:
2919 return PLANE_CTL_ORDER_RGBX
| PLANE_CTL_FORMAT_XRGB_2101010
;
2920 case DRM_FORMAT_YUYV
:
2921 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YUYV
;
2922 case DRM_FORMAT_YVYU
:
2923 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YVYU
;
2924 case DRM_FORMAT_UYVY
:
2925 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_UYVY
;
2926 case DRM_FORMAT_VYUY
:
2927 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_VYUY
;
2929 MISSING_CASE(pixel_format
);
2935 u32
skl_plane_ctl_tiling(uint64_t fb_modifier
)
2937 switch (fb_modifier
) {
2938 case DRM_FORMAT_MOD_NONE
:
2940 case I915_FORMAT_MOD_X_TILED
:
2941 return PLANE_CTL_TILED_X
;
2942 case I915_FORMAT_MOD_Y_TILED
:
2943 return PLANE_CTL_TILED_Y
;
2944 case I915_FORMAT_MOD_Yf_TILED
:
2945 return PLANE_CTL_TILED_YF
;
2947 MISSING_CASE(fb_modifier
);
2953 u32
skl_plane_ctl_rotation(unsigned int rotation
)
2956 case BIT(DRM_ROTATE_0
):
2959 * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr
2960 * while i915 HW rotation is clockwise, thats why this swapping.
2962 case BIT(DRM_ROTATE_90
):
2963 return PLANE_CTL_ROTATE_270
;
2964 case BIT(DRM_ROTATE_180
):
2965 return PLANE_CTL_ROTATE_180
;
2966 case BIT(DRM_ROTATE_270
):
2967 return PLANE_CTL_ROTATE_90
;
2969 MISSING_CASE(rotation
);
2975 static void skylake_update_primary_plane(struct drm_plane
*plane
,
2976 const struct intel_crtc_state
*crtc_state
,
2977 const struct intel_plane_state
*plane_state
)
2979 struct drm_device
*dev
= plane
->dev
;
2980 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2981 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
2982 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2983 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2984 int pipe
= intel_crtc
->pipe
;
2985 u32 plane_ctl
, stride_div
, stride
;
2986 u32 tile_height
, plane_offset
, plane_size
;
2987 unsigned int rotation
= plane_state
->base
.rotation
;
2988 int x_offset
, y_offset
;
2990 int scaler_id
= plane_state
->scaler_id
;
2991 int src_x
= plane_state
->src
.x1
>> 16;
2992 int src_y
= plane_state
->src
.y1
>> 16;
2993 int src_w
= drm_rect_width(&plane_state
->src
) >> 16;
2994 int src_h
= drm_rect_height(&plane_state
->src
) >> 16;
2995 int dst_x
= plane_state
->dst
.x1
;
2996 int dst_y
= plane_state
->dst
.y1
;
2997 int dst_w
= drm_rect_width(&plane_state
->dst
);
2998 int dst_h
= drm_rect_height(&plane_state
->dst
);
3000 plane_ctl
= PLANE_CTL_ENABLE
|
3001 PLANE_CTL_PIPE_GAMMA_ENABLE
|
3002 PLANE_CTL_PIPE_CSC_ENABLE
;
3004 plane_ctl
|= skl_plane_ctl_format(fb
->pixel_format
);
3005 plane_ctl
|= skl_plane_ctl_tiling(fb
->modifier
[0]);
3006 plane_ctl
|= PLANE_CTL_PLANE_GAMMA_DISABLE
;
3007 plane_ctl
|= skl_plane_ctl_rotation(rotation
);
3009 stride_div
= intel_fb_stride_alignment(dev_priv
, fb
->modifier
[0],
3011 surf_addr
= intel_plane_obj_offset(to_intel_plane(plane
), obj
, 0);
3013 WARN_ON(drm_rect_width(&plane_state
->src
) == 0);
3015 if (intel_rotation_90_or_270(rotation
)) {
3016 int cpp
= drm_format_plane_cpp(fb
->pixel_format
, 0);
3018 /* stride = Surface height in tiles */
3019 tile_height
= intel_tile_height(dev_priv
, fb
->modifier
[0], cpp
);
3020 stride
= DIV_ROUND_UP(fb
->height
, tile_height
);
3021 x_offset
= stride
* tile_height
- src_y
- src_h
;
3023 plane_size
= (src_w
- 1) << 16 | (src_h
- 1);
3025 stride
= fb
->pitches
[0] / stride_div
;
3028 plane_size
= (src_h
- 1) << 16 | (src_w
- 1);
3030 plane_offset
= y_offset
<< 16 | x_offset
;
3032 intel_crtc
->adjusted_x
= x_offset
;
3033 intel_crtc
->adjusted_y
= y_offset
;
3035 I915_WRITE(PLANE_CTL(pipe
, 0), plane_ctl
);
3036 I915_WRITE(PLANE_OFFSET(pipe
, 0), plane_offset
);
3037 I915_WRITE(PLANE_SIZE(pipe
, 0), plane_size
);
3038 I915_WRITE(PLANE_STRIDE(pipe
, 0), stride
);
3040 if (scaler_id
>= 0) {
3041 uint32_t ps_ctrl
= 0;
3043 WARN_ON(!dst_w
|| !dst_h
);
3044 ps_ctrl
= PS_SCALER_EN
| PS_PLANE_SEL(0) |
3045 crtc_state
->scaler_state
.scalers
[scaler_id
].mode
;
3046 I915_WRITE(SKL_PS_CTRL(pipe
, scaler_id
), ps_ctrl
);
3047 I915_WRITE(SKL_PS_PWR_GATE(pipe
, scaler_id
), 0);
3048 I915_WRITE(SKL_PS_WIN_POS(pipe
, scaler_id
), (dst_x
<< 16) | dst_y
);
3049 I915_WRITE(SKL_PS_WIN_SZ(pipe
, scaler_id
), (dst_w
<< 16) | dst_h
);
3050 I915_WRITE(PLANE_POS(pipe
, 0), 0);
3052 I915_WRITE(PLANE_POS(pipe
, 0), (dst_y
<< 16) | dst_x
);
3055 I915_WRITE(PLANE_SURF(pipe
, 0), surf_addr
);
3057 POSTING_READ(PLANE_SURF(pipe
, 0));
3060 static void skylake_disable_primary_plane(struct drm_plane
*primary
,
3061 struct drm_crtc
*crtc
)
3063 struct drm_device
*dev
= crtc
->dev
;
3064 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3065 int pipe
= to_intel_crtc(crtc
)->pipe
;
3067 I915_WRITE(PLANE_CTL(pipe
, 0), 0);
3068 I915_WRITE(PLANE_SURF(pipe
, 0), 0);
3069 POSTING_READ(PLANE_SURF(pipe
, 0));
3072 /* Assume fb object is pinned & idle & fenced and just update base pointers */
3074 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
3075 int x
, int y
, enum mode_set_atomic state
)
3077 /* Support for kgdboc is disabled, this needs a major rework. */
3078 DRM_ERROR("legacy panic handler not supported any more.\n");
3083 static void intel_complete_page_flips(struct drm_i915_private
*dev_priv
)
3085 struct intel_crtc
*crtc
;
3087 for_each_intel_crtc(&dev_priv
->drm
, crtc
)
3088 intel_finish_page_flip_cs(dev_priv
, crtc
->pipe
);
3091 static void intel_update_primary_planes(struct drm_device
*dev
)
3093 struct drm_crtc
*crtc
;
3095 for_each_crtc(dev
, crtc
) {
3096 struct intel_plane
*plane
= to_intel_plane(crtc
->primary
);
3097 struct intel_plane_state
*plane_state
;
3099 drm_modeset_lock_crtc(crtc
, &plane
->base
);
3100 plane_state
= to_intel_plane_state(plane
->base
.state
);
3102 if (plane_state
->visible
)
3103 plane
->update_plane(&plane
->base
,
3104 to_intel_crtc_state(crtc
->state
),
3107 drm_modeset_unlock_crtc(crtc
);
3111 void intel_prepare_reset(struct drm_i915_private
*dev_priv
)
3113 /* no reset support for gen2 */
3114 if (IS_GEN2(dev_priv
))
3117 /* reset doesn't touch the display */
3118 if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
))
3121 drm_modeset_lock_all(&dev_priv
->drm
);
3123 * Disabling the crtcs gracefully seems nicer. Also the
3124 * g33 docs say we should at least disable all the planes.
3126 intel_display_suspend(&dev_priv
->drm
);
3129 void intel_finish_reset(struct drm_i915_private
*dev_priv
)
3132 * Flips in the rings will be nuked by the reset,
3133 * so complete all pending flips so that user space
3134 * will get its events and not get stuck.
3136 intel_complete_page_flips(dev_priv
);
3138 /* no reset support for gen2 */
3139 if (IS_GEN2(dev_priv
))
3142 /* reset doesn't touch the display */
3143 if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
)) {
3145 * Flips in the rings have been nuked by the reset,
3146 * so update the base address of all primary
3147 * planes to the the last fb to make sure we're
3148 * showing the correct fb after a reset.
3150 * FIXME: Atomic will make this obsolete since we won't schedule
3151 * CS-based flips (which might get lost in gpu resets) any more.
3153 intel_update_primary_planes(&dev_priv
->drm
);
3158 * The display has been reset as well,
3159 * so need a full re-initialization.
3161 intel_runtime_pm_disable_interrupts(dev_priv
);
3162 intel_runtime_pm_enable_interrupts(dev_priv
);
3164 intel_modeset_init_hw(&dev_priv
->drm
);
3166 spin_lock_irq(&dev_priv
->irq_lock
);
3167 if (dev_priv
->display
.hpd_irq_setup
)
3168 dev_priv
->display
.hpd_irq_setup(dev_priv
);
3169 spin_unlock_irq(&dev_priv
->irq_lock
);
3171 intel_display_resume(&dev_priv
->drm
);
3173 intel_hpd_init(dev_priv
);
3175 drm_modeset_unlock_all(&dev_priv
->drm
);
3178 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
3180 struct drm_device
*dev
= crtc
->dev
;
3181 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3182 unsigned reset_counter
;
3185 reset_counter
= i915_reset_counter(&to_i915(dev
)->gpu_error
);
3186 if (intel_crtc
->reset_counter
!= reset_counter
)
3189 spin_lock_irq(&dev
->event_lock
);
3190 pending
= to_intel_crtc(crtc
)->flip_work
!= NULL
;
3191 spin_unlock_irq(&dev
->event_lock
);
3196 static void intel_update_pipe_config(struct intel_crtc
*crtc
,
3197 struct intel_crtc_state
*old_crtc_state
)
3199 struct drm_device
*dev
= crtc
->base
.dev
;
3200 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3201 struct intel_crtc_state
*pipe_config
=
3202 to_intel_crtc_state(crtc
->base
.state
);
3204 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
3205 crtc
->base
.mode
= crtc
->base
.state
->mode
;
3207 DRM_DEBUG_KMS("Updating pipe size %ix%i -> %ix%i\n",
3208 old_crtc_state
->pipe_src_w
, old_crtc_state
->pipe_src_h
,
3209 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
3212 * Update pipe size and adjust fitter if needed: the reason for this is
3213 * that in compute_mode_changes we check the native mode (not the pfit
3214 * mode) to see if we can flip rather than do a full mode set. In the
3215 * fastboot case, we'll flip, but if we don't update the pipesrc and
3216 * pfit state, we'll end up with a big fb scanned out into the wrong
3220 I915_WRITE(PIPESRC(crtc
->pipe
),
3221 ((pipe_config
->pipe_src_w
- 1) << 16) |
3222 (pipe_config
->pipe_src_h
- 1));
3224 /* on skylake this is done by detaching scalers */
3225 if (INTEL_INFO(dev
)->gen
>= 9) {
3226 skl_detach_scalers(crtc
);
3228 if (pipe_config
->pch_pfit
.enabled
)
3229 skylake_pfit_enable(crtc
);
3230 } else if (HAS_PCH_SPLIT(dev
)) {
3231 if (pipe_config
->pch_pfit
.enabled
)
3232 ironlake_pfit_enable(crtc
);
3233 else if (old_crtc_state
->pch_pfit
.enabled
)
3234 ironlake_pfit_disable(crtc
, true);
3238 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
3240 struct drm_device
*dev
= crtc
->dev
;
3241 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3242 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3243 int pipe
= intel_crtc
->pipe
;
3247 /* enable normal train */
3248 reg
= FDI_TX_CTL(pipe
);
3249 temp
= I915_READ(reg
);
3250 if (IS_IVYBRIDGE(dev
)) {
3251 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3252 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3254 temp
&= ~FDI_LINK_TRAIN_NONE
;
3255 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3257 I915_WRITE(reg
, temp
);
3259 reg
= FDI_RX_CTL(pipe
);
3260 temp
= I915_READ(reg
);
3261 if (HAS_PCH_CPT(dev
)) {
3262 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3263 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
3265 temp
&= ~FDI_LINK_TRAIN_NONE
;
3266 temp
|= FDI_LINK_TRAIN_NONE
;
3268 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
3270 /* wait one idle pattern time */
3274 /* IVB wants error correction enabled */
3275 if (IS_IVYBRIDGE(dev
))
3276 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
3277 FDI_FE_ERRC_ENABLE
);
3280 /* The FDI link training functions for ILK/Ibexpeak. */
3281 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
3283 struct drm_device
*dev
= crtc
->dev
;
3284 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3285 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3286 int pipe
= intel_crtc
->pipe
;
3290 /* FDI needs bits from pipe first */
3291 assert_pipe_enabled(dev_priv
, pipe
);
3293 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3295 reg
= FDI_RX_IMR(pipe
);
3296 temp
= I915_READ(reg
);
3297 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3298 temp
&= ~FDI_RX_BIT_LOCK
;
3299 I915_WRITE(reg
, temp
);
3303 /* enable CPU FDI TX and PCH FDI RX */
3304 reg
= FDI_TX_CTL(pipe
);
3305 temp
= I915_READ(reg
);
3306 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3307 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3308 temp
&= ~FDI_LINK_TRAIN_NONE
;
3309 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3310 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3312 reg
= FDI_RX_CTL(pipe
);
3313 temp
= I915_READ(reg
);
3314 temp
&= ~FDI_LINK_TRAIN_NONE
;
3315 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3316 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3321 /* Ironlake workaround, enable clock pointer after FDI enable*/
3322 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3323 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
3324 FDI_RX_PHASE_SYNC_POINTER_EN
);
3326 reg
= FDI_RX_IIR(pipe
);
3327 for (tries
= 0; tries
< 5; tries
++) {
3328 temp
= I915_READ(reg
);
3329 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3331 if ((temp
& FDI_RX_BIT_LOCK
)) {
3332 DRM_DEBUG_KMS("FDI train 1 done.\n");
3333 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3338 DRM_ERROR("FDI train 1 fail!\n");
3341 reg
= FDI_TX_CTL(pipe
);
3342 temp
= I915_READ(reg
);
3343 temp
&= ~FDI_LINK_TRAIN_NONE
;
3344 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3345 I915_WRITE(reg
, temp
);
3347 reg
= FDI_RX_CTL(pipe
);
3348 temp
= I915_READ(reg
);
3349 temp
&= ~FDI_LINK_TRAIN_NONE
;
3350 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3351 I915_WRITE(reg
, temp
);
3356 reg
= FDI_RX_IIR(pipe
);
3357 for (tries
= 0; tries
< 5; tries
++) {
3358 temp
= I915_READ(reg
);
3359 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3361 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3362 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3363 DRM_DEBUG_KMS("FDI train 2 done.\n");
3368 DRM_ERROR("FDI train 2 fail!\n");
3370 DRM_DEBUG_KMS("FDI train done\n");
3374 static const int snb_b_fdi_train_param
[] = {
3375 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
3376 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
3377 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
3378 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
3381 /* The FDI link training functions for SNB/Cougarpoint. */
3382 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
3384 struct drm_device
*dev
= crtc
->dev
;
3385 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3386 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3387 int pipe
= intel_crtc
->pipe
;
3391 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3393 reg
= FDI_RX_IMR(pipe
);
3394 temp
= I915_READ(reg
);
3395 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3396 temp
&= ~FDI_RX_BIT_LOCK
;
3397 I915_WRITE(reg
, temp
);
3402 /* enable CPU FDI TX and PCH FDI RX */
3403 reg
= FDI_TX_CTL(pipe
);
3404 temp
= I915_READ(reg
);
3405 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3406 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3407 temp
&= ~FDI_LINK_TRAIN_NONE
;
3408 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3409 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3411 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3412 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3414 I915_WRITE(FDI_RX_MISC(pipe
),
3415 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3417 reg
= FDI_RX_CTL(pipe
);
3418 temp
= I915_READ(reg
);
3419 if (HAS_PCH_CPT(dev
)) {
3420 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3421 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3423 temp
&= ~FDI_LINK_TRAIN_NONE
;
3424 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3426 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3431 for (i
= 0; i
< 4; i
++) {
3432 reg
= FDI_TX_CTL(pipe
);
3433 temp
= I915_READ(reg
);
3434 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3435 temp
|= snb_b_fdi_train_param
[i
];
3436 I915_WRITE(reg
, temp
);
3441 for (retry
= 0; retry
< 5; retry
++) {
3442 reg
= FDI_RX_IIR(pipe
);
3443 temp
= I915_READ(reg
);
3444 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3445 if (temp
& FDI_RX_BIT_LOCK
) {
3446 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3447 DRM_DEBUG_KMS("FDI train 1 done.\n");
3456 DRM_ERROR("FDI train 1 fail!\n");
3459 reg
= FDI_TX_CTL(pipe
);
3460 temp
= I915_READ(reg
);
3461 temp
&= ~FDI_LINK_TRAIN_NONE
;
3462 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3464 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3466 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3468 I915_WRITE(reg
, temp
);
3470 reg
= FDI_RX_CTL(pipe
);
3471 temp
= I915_READ(reg
);
3472 if (HAS_PCH_CPT(dev
)) {
3473 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3474 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3476 temp
&= ~FDI_LINK_TRAIN_NONE
;
3477 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3479 I915_WRITE(reg
, temp
);
3484 for (i
= 0; i
< 4; i
++) {
3485 reg
= FDI_TX_CTL(pipe
);
3486 temp
= I915_READ(reg
);
3487 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3488 temp
|= snb_b_fdi_train_param
[i
];
3489 I915_WRITE(reg
, temp
);
3494 for (retry
= 0; retry
< 5; retry
++) {
3495 reg
= FDI_RX_IIR(pipe
);
3496 temp
= I915_READ(reg
);
3497 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3498 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3499 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3500 DRM_DEBUG_KMS("FDI train 2 done.\n");
3509 DRM_ERROR("FDI train 2 fail!\n");
3511 DRM_DEBUG_KMS("FDI train done.\n");
3514 /* Manual link training for Ivy Bridge A0 parts */
3515 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
3517 struct drm_device
*dev
= crtc
->dev
;
3518 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3519 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3520 int pipe
= intel_crtc
->pipe
;
3524 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3526 reg
= FDI_RX_IMR(pipe
);
3527 temp
= I915_READ(reg
);
3528 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3529 temp
&= ~FDI_RX_BIT_LOCK
;
3530 I915_WRITE(reg
, temp
);
3535 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3536 I915_READ(FDI_RX_IIR(pipe
)));
3538 /* Try each vswing and preemphasis setting twice before moving on */
3539 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
3540 /* disable first in case we need to retry */
3541 reg
= FDI_TX_CTL(pipe
);
3542 temp
= I915_READ(reg
);
3543 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
3544 temp
&= ~FDI_TX_ENABLE
;
3545 I915_WRITE(reg
, temp
);
3547 reg
= FDI_RX_CTL(pipe
);
3548 temp
= I915_READ(reg
);
3549 temp
&= ~FDI_LINK_TRAIN_AUTO
;
3550 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3551 temp
&= ~FDI_RX_ENABLE
;
3552 I915_WRITE(reg
, temp
);
3554 /* enable CPU FDI TX and PCH FDI RX */
3555 reg
= FDI_TX_CTL(pipe
);
3556 temp
= I915_READ(reg
);
3557 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3558 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3559 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
3560 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3561 temp
|= snb_b_fdi_train_param
[j
/2];
3562 temp
|= FDI_COMPOSITE_SYNC
;
3563 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3565 I915_WRITE(FDI_RX_MISC(pipe
),
3566 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3568 reg
= FDI_RX_CTL(pipe
);
3569 temp
= I915_READ(reg
);
3570 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3571 temp
|= FDI_COMPOSITE_SYNC
;
3572 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3575 udelay(1); /* should be 0.5us */
3577 for (i
= 0; i
< 4; i
++) {
3578 reg
= FDI_RX_IIR(pipe
);
3579 temp
= I915_READ(reg
);
3580 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3582 if (temp
& FDI_RX_BIT_LOCK
||
3583 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
3584 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3585 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3589 udelay(1); /* should be 0.5us */
3592 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
3597 reg
= FDI_TX_CTL(pipe
);
3598 temp
= I915_READ(reg
);
3599 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3600 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
3601 I915_WRITE(reg
, temp
);
3603 reg
= FDI_RX_CTL(pipe
);
3604 temp
= I915_READ(reg
);
3605 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3606 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3607 I915_WRITE(reg
, temp
);
3610 udelay(2); /* should be 1.5us */
3612 for (i
= 0; i
< 4; i
++) {
3613 reg
= FDI_RX_IIR(pipe
);
3614 temp
= I915_READ(reg
);
3615 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3617 if (temp
& FDI_RX_SYMBOL_LOCK
||
3618 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
3619 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3620 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
3624 udelay(2); /* should be 1.5us */
3627 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
3631 DRM_DEBUG_KMS("FDI train done.\n");
3634 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
3636 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3637 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3638 int pipe
= intel_crtc
->pipe
;
3642 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
3643 reg
= FDI_RX_CTL(pipe
);
3644 temp
= I915_READ(reg
);
3645 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
3646 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3647 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3648 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
3653 /* Switch from Rawclk to PCDclk */
3654 temp
= I915_READ(reg
);
3655 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
3660 /* Enable CPU FDI TX PLL, always on for Ironlake */
3661 reg
= FDI_TX_CTL(pipe
);
3662 temp
= I915_READ(reg
);
3663 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
3664 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
3671 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
3673 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3674 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3675 int pipe
= intel_crtc
->pipe
;
3679 /* Switch from PCDclk to Rawclk */
3680 reg
= FDI_RX_CTL(pipe
);
3681 temp
= I915_READ(reg
);
3682 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
3684 /* Disable CPU FDI TX PLL */
3685 reg
= FDI_TX_CTL(pipe
);
3686 temp
= I915_READ(reg
);
3687 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
3692 reg
= FDI_RX_CTL(pipe
);
3693 temp
= I915_READ(reg
);
3694 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
3696 /* Wait for the clocks to turn off. */
3701 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
3703 struct drm_device
*dev
= crtc
->dev
;
3704 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3705 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3706 int pipe
= intel_crtc
->pipe
;
3710 /* disable CPU FDI tx and PCH FDI rx */
3711 reg
= FDI_TX_CTL(pipe
);
3712 temp
= I915_READ(reg
);
3713 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
3716 reg
= FDI_RX_CTL(pipe
);
3717 temp
= I915_READ(reg
);
3718 temp
&= ~(0x7 << 16);
3719 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3720 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
3725 /* Ironlake workaround, disable clock pointer after downing FDI */
3726 if (HAS_PCH_IBX(dev
))
3727 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3729 /* still set train pattern 1 */
3730 reg
= FDI_TX_CTL(pipe
);
3731 temp
= I915_READ(reg
);
3732 temp
&= ~FDI_LINK_TRAIN_NONE
;
3733 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3734 I915_WRITE(reg
, temp
);
3736 reg
= FDI_RX_CTL(pipe
);
3737 temp
= I915_READ(reg
);
3738 if (HAS_PCH_CPT(dev
)) {
3739 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3740 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3742 temp
&= ~FDI_LINK_TRAIN_NONE
;
3743 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3745 /* BPC in FDI rx is consistent with that in PIPECONF */
3746 temp
&= ~(0x07 << 16);
3747 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3748 I915_WRITE(reg
, temp
);
3754 bool intel_has_pending_fb_unpin(struct drm_device
*dev
)
3756 struct intel_crtc
*crtc
;
3758 /* Note that we don't need to be called with mode_config.lock here
3759 * as our list of CRTC objects is static for the lifetime of the
3760 * device and so cannot disappear as we iterate. Similarly, we can
3761 * happily treat the predicates as racy, atomic checks as userspace
3762 * cannot claim and pin a new fb without at least acquring the
3763 * struct_mutex and so serialising with us.
3765 for_each_intel_crtc(dev
, crtc
) {
3766 if (atomic_read(&crtc
->unpin_work_count
) == 0)
3769 if (crtc
->flip_work
)
3770 intel_wait_for_vblank(dev
, crtc
->pipe
);
3778 static void page_flip_completed(struct intel_crtc
*intel_crtc
)
3780 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
3781 struct intel_flip_work
*work
= intel_crtc
->flip_work
;
3783 intel_crtc
->flip_work
= NULL
;
3786 drm_crtc_send_vblank_event(&intel_crtc
->base
, work
->event
);
3788 drm_crtc_vblank_put(&intel_crtc
->base
);
3790 wake_up_all(&dev_priv
->pending_flip_queue
);
3791 queue_work(dev_priv
->wq
, &work
->unpin_work
);
3793 trace_i915_flip_complete(intel_crtc
->plane
,
3794 work
->pending_flip_obj
);
3797 static int intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
3799 struct drm_device
*dev
= crtc
->dev
;
3800 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3803 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
3805 ret
= wait_event_interruptible_timeout(
3806 dev_priv
->pending_flip_queue
,
3807 !intel_crtc_has_pending_flip(crtc
),
3814 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3815 struct intel_flip_work
*work
;
3817 spin_lock_irq(&dev
->event_lock
);
3818 work
= intel_crtc
->flip_work
;
3819 if (work
&& !is_mmio_work(work
)) {
3820 WARN_ONCE(1, "Removing stuck page flip\n");
3821 page_flip_completed(intel_crtc
);
3823 spin_unlock_irq(&dev
->event_lock
);
3829 static void lpt_disable_iclkip(struct drm_i915_private
*dev_priv
)
3833 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
3835 mutex_lock(&dev_priv
->sb_lock
);
3837 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
3838 temp
|= SBI_SSCCTL_DISABLE
;
3839 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
3841 mutex_unlock(&dev_priv
->sb_lock
);
3844 /* Program iCLKIP clock to the desired frequency */
3845 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
3847 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
3848 int clock
= to_intel_crtc(crtc
)->config
->base
.adjusted_mode
.crtc_clock
;
3849 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
3852 lpt_disable_iclkip(dev_priv
);
3854 /* The iCLK virtual clock root frequency is in MHz,
3855 * but the adjusted_mode->crtc_clock in in KHz. To get the
3856 * divisors, it is necessary to divide one by another, so we
3857 * convert the virtual clock precision to KHz here for higher
3860 for (auxdiv
= 0; auxdiv
< 2; auxdiv
++) {
3861 u32 iclk_virtual_root_freq
= 172800 * 1000;
3862 u32 iclk_pi_range
= 64;
3863 u32 desired_divisor
;
3865 desired_divisor
= DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
3867 divsel
= (desired_divisor
/ iclk_pi_range
) - 2;
3868 phaseinc
= desired_divisor
% iclk_pi_range
;
3871 * Near 20MHz is a corner case which is
3872 * out of range for the 7-bit divisor
3878 /* This should not happen with any sane values */
3879 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
3880 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
3881 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
3882 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
3884 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3891 mutex_lock(&dev_priv
->sb_lock
);
3893 /* Program SSCDIVINTPHASE6 */
3894 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
3895 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
3896 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
3897 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
3898 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
3899 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
3900 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
3901 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
3903 /* Program SSCAUXDIV */
3904 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
3905 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3906 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
3907 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
3909 /* Enable modulator and associated divider */
3910 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
3911 temp
&= ~SBI_SSCCTL_DISABLE
;
3912 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
3914 mutex_unlock(&dev_priv
->sb_lock
);
3916 /* Wait for initialization time */
3919 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
3922 int lpt_get_iclkip(struct drm_i915_private
*dev_priv
)
3924 u32 divsel
, phaseinc
, auxdiv
;
3925 u32 iclk_virtual_root_freq
= 172800 * 1000;
3926 u32 iclk_pi_range
= 64;
3927 u32 desired_divisor
;
3930 if ((I915_READ(PIXCLK_GATE
) & PIXCLK_GATE_UNGATE
) == 0)
3933 mutex_lock(&dev_priv
->sb_lock
);
3935 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
3936 if (temp
& SBI_SSCCTL_DISABLE
) {
3937 mutex_unlock(&dev_priv
->sb_lock
);
3941 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
3942 divsel
= (temp
& SBI_SSCDIVINTPHASE_DIVSEL_MASK
) >>
3943 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT
;
3944 phaseinc
= (temp
& SBI_SSCDIVINTPHASE_INCVAL_MASK
) >>
3945 SBI_SSCDIVINTPHASE_INCVAL_SHIFT
;
3947 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
3948 auxdiv
= (temp
& SBI_SSCAUXDIV_FINALDIV2SEL_MASK
) >>
3949 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT
;
3951 mutex_unlock(&dev_priv
->sb_lock
);
3953 desired_divisor
= (divsel
+ 2) * iclk_pi_range
+ phaseinc
;
3955 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
3956 desired_divisor
<< auxdiv
);
3959 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
3960 enum pipe pch_transcoder
)
3962 struct drm_device
*dev
= crtc
->base
.dev
;
3963 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3964 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
3966 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
3967 I915_READ(HTOTAL(cpu_transcoder
)));
3968 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
3969 I915_READ(HBLANK(cpu_transcoder
)));
3970 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
3971 I915_READ(HSYNC(cpu_transcoder
)));
3973 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
3974 I915_READ(VTOTAL(cpu_transcoder
)));
3975 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
3976 I915_READ(VBLANK(cpu_transcoder
)));
3977 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
3978 I915_READ(VSYNC(cpu_transcoder
)));
3979 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
3980 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
3983 static void cpt_set_fdi_bc_bifurcation(struct drm_device
*dev
, bool enable
)
3985 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3988 temp
= I915_READ(SOUTH_CHICKEN1
);
3989 if (!!(temp
& FDI_BC_BIFURCATION_SELECT
) == enable
)
3992 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
3993 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
3995 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
3997 temp
|= FDI_BC_BIFURCATION_SELECT
;
3999 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable
? "en" : "dis");
4000 I915_WRITE(SOUTH_CHICKEN1
, temp
);
4001 POSTING_READ(SOUTH_CHICKEN1
);
4004 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
4006 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4008 switch (intel_crtc
->pipe
) {
4012 if (intel_crtc
->config
->fdi_lanes
> 2)
4013 cpt_set_fdi_bc_bifurcation(dev
, false);
4015 cpt_set_fdi_bc_bifurcation(dev
, true);
4019 cpt_set_fdi_bc_bifurcation(dev
, true);
4027 /* Return which DP Port should be selected for Transcoder DP control */
4029 intel_trans_dp_port_sel(struct drm_crtc
*crtc
)
4031 struct drm_device
*dev
= crtc
->dev
;
4032 struct intel_encoder
*encoder
;
4034 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4035 if (encoder
->type
== INTEL_OUTPUT_DP
||
4036 encoder
->type
== INTEL_OUTPUT_EDP
)
4037 return enc_to_dig_port(&encoder
->base
)->port
;
4044 * Enable PCH resources required for PCH ports:
4046 * - FDI training & RX/TX
4047 * - update transcoder timings
4048 * - DP transcoding bits
4051 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
4053 struct drm_device
*dev
= crtc
->dev
;
4054 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4055 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4056 int pipe
= intel_crtc
->pipe
;
4059 assert_pch_transcoder_disabled(dev_priv
, pipe
);
4061 if (IS_IVYBRIDGE(dev
))
4062 ivybridge_update_fdi_bc_bifurcation(intel_crtc
);
4064 /* Write the TU size bits before fdi link training, so that error
4065 * detection works. */
4066 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
4067 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
4069 /* For PCH output, training FDI link */
4070 dev_priv
->display
.fdi_link_train(crtc
);
4072 /* We need to program the right clock selection before writing the pixel
4073 * mutliplier into the DPLL. */
4074 if (HAS_PCH_CPT(dev
)) {
4077 temp
= I915_READ(PCH_DPLL_SEL
);
4078 temp
|= TRANS_DPLL_ENABLE(pipe
);
4079 sel
= TRANS_DPLLB_SEL(pipe
);
4080 if (intel_crtc
->config
->shared_dpll
==
4081 intel_get_shared_dpll_by_id(dev_priv
, DPLL_ID_PCH_PLL_B
))
4085 I915_WRITE(PCH_DPLL_SEL
, temp
);
4088 /* XXX: pch pll's can be enabled any time before we enable the PCH
4089 * transcoder, and we actually should do this to not upset any PCH
4090 * transcoder that already use the clock when we share it.
4092 * Note that enable_shared_dpll tries to do the right thing, but
4093 * get_shared_dpll unconditionally resets the pll - we need that to have
4094 * the right LVDS enable sequence. */
4095 intel_enable_shared_dpll(intel_crtc
);
4097 /* set transcoder timing, panel must allow it */
4098 assert_panel_unlocked(dev_priv
, pipe
);
4099 ironlake_pch_transcoder_set_timings(intel_crtc
, pipe
);
4101 intel_fdi_normal_train(crtc
);
4103 /* For PCH DP, enable TRANS_DP_CTL */
4104 if (HAS_PCH_CPT(dev
) && intel_crtc_has_dp_encoder(intel_crtc
->config
)) {
4105 const struct drm_display_mode
*adjusted_mode
=
4106 &intel_crtc
->config
->base
.adjusted_mode
;
4107 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
4108 i915_reg_t reg
= TRANS_DP_CTL(pipe
);
4109 temp
= I915_READ(reg
);
4110 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
4111 TRANS_DP_SYNC_MASK
|
4113 temp
|= TRANS_DP_OUTPUT_ENABLE
;
4114 temp
|= bpc
<< 9; /* same format but at 11:9 */
4116 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
4117 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
4118 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
4119 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
4121 switch (intel_trans_dp_port_sel(crtc
)) {
4123 temp
|= TRANS_DP_PORT_SEL_B
;
4126 temp
|= TRANS_DP_PORT_SEL_C
;
4129 temp
|= TRANS_DP_PORT_SEL_D
;
4135 I915_WRITE(reg
, temp
);
4138 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
4141 static void lpt_pch_enable(struct drm_crtc
*crtc
)
4143 struct drm_device
*dev
= crtc
->dev
;
4144 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4145 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4146 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
4148 assert_pch_transcoder_disabled(dev_priv
, TRANSCODER_A
);
4150 lpt_program_iclkip(crtc
);
4152 /* Set transcoder timing. */
4153 ironlake_pch_transcoder_set_timings(intel_crtc
, PIPE_A
);
4155 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
4158 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
4160 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4161 i915_reg_t dslreg
= PIPEDSL(pipe
);
4164 temp
= I915_READ(dslreg
);
4166 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
4167 if (wait_for(I915_READ(dslreg
) != temp
, 5))
4168 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
4173 skl_update_scaler(struct intel_crtc_state
*crtc_state
, bool force_detach
,
4174 unsigned scaler_user
, int *scaler_id
, unsigned int rotation
,
4175 int src_w
, int src_h
, int dst_w
, int dst_h
)
4177 struct intel_crtc_scaler_state
*scaler_state
=
4178 &crtc_state
->scaler_state
;
4179 struct intel_crtc
*intel_crtc
=
4180 to_intel_crtc(crtc_state
->base
.crtc
);
4183 need_scaling
= intel_rotation_90_or_270(rotation
) ?
4184 (src_h
!= dst_w
|| src_w
!= dst_h
):
4185 (src_w
!= dst_w
|| src_h
!= dst_h
);
4188 * if plane is being disabled or scaler is no more required or force detach
4189 * - free scaler binded to this plane/crtc
4190 * - in order to do this, update crtc->scaler_usage
4192 * Here scaler state in crtc_state is set free so that
4193 * scaler can be assigned to other user. Actual register
4194 * update to free the scaler is done in plane/panel-fit programming.
4195 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4197 if (force_detach
|| !need_scaling
) {
4198 if (*scaler_id
>= 0) {
4199 scaler_state
->scaler_users
&= ~(1 << scaler_user
);
4200 scaler_state
->scalers
[*scaler_id
].in_use
= 0;
4202 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4203 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4204 intel_crtc
->pipe
, scaler_user
, *scaler_id
,
4205 scaler_state
->scaler_users
);
4212 if (src_w
< SKL_MIN_SRC_W
|| src_h
< SKL_MIN_SRC_H
||
4213 dst_w
< SKL_MIN_DST_W
|| dst_h
< SKL_MIN_DST_H
||
4215 src_w
> SKL_MAX_SRC_W
|| src_h
> SKL_MAX_SRC_H
||
4216 dst_w
> SKL_MAX_DST_W
|| dst_h
> SKL_MAX_DST_H
) {
4217 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4218 "size is out of scaler range\n",
4219 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
);
4223 /* mark this plane as a scaler user in crtc_state */
4224 scaler_state
->scaler_users
|= (1 << scaler_user
);
4225 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4226 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4227 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
,
4228 scaler_state
->scaler_users
);
4234 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4236 * @state: crtc's scaler state
4239 * 0 - scaler_usage updated successfully
4240 * error - requested scaling cannot be supported or other error condition
4242 int skl_update_scaler_crtc(struct intel_crtc_state
*state
)
4244 struct intel_crtc
*intel_crtc
= to_intel_crtc(state
->base
.crtc
);
4245 const struct drm_display_mode
*adjusted_mode
= &state
->base
.adjusted_mode
;
4247 DRM_DEBUG_KMS("Updating scaler for [CRTC:%d:%s] scaler_user index %u.%u\n",
4248 intel_crtc
->base
.base
.id
, intel_crtc
->base
.name
,
4249 intel_crtc
->pipe
, SKL_CRTC_INDEX
);
4251 return skl_update_scaler(state
, !state
->base
.active
, SKL_CRTC_INDEX
,
4252 &state
->scaler_state
.scaler_id
, BIT(DRM_ROTATE_0
),
4253 state
->pipe_src_w
, state
->pipe_src_h
,
4254 adjusted_mode
->crtc_hdisplay
, adjusted_mode
->crtc_vdisplay
);
4258 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4260 * @state: crtc's scaler state
4261 * @plane_state: atomic plane state to update
4264 * 0 - scaler_usage updated successfully
4265 * error - requested scaling cannot be supported or other error condition
4267 static int skl_update_scaler_plane(struct intel_crtc_state
*crtc_state
,
4268 struct intel_plane_state
*plane_state
)
4271 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
4272 struct intel_plane
*intel_plane
=
4273 to_intel_plane(plane_state
->base
.plane
);
4274 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
4277 bool force_detach
= !fb
|| !plane_state
->visible
;
4279 DRM_DEBUG_KMS("Updating scaler for [PLANE:%d:%s] scaler_user index %u.%u\n",
4280 intel_plane
->base
.base
.id
, intel_plane
->base
.name
,
4281 intel_crtc
->pipe
, drm_plane_index(&intel_plane
->base
));
4283 ret
= skl_update_scaler(crtc_state
, force_detach
,
4284 drm_plane_index(&intel_plane
->base
),
4285 &plane_state
->scaler_id
,
4286 plane_state
->base
.rotation
,
4287 drm_rect_width(&plane_state
->src
) >> 16,
4288 drm_rect_height(&plane_state
->src
) >> 16,
4289 drm_rect_width(&plane_state
->dst
),
4290 drm_rect_height(&plane_state
->dst
));
4292 if (ret
|| plane_state
->scaler_id
< 0)
4295 /* check colorkey */
4296 if (plane_state
->ckey
.flags
!= I915_SET_COLORKEY_NONE
) {
4297 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
4298 intel_plane
->base
.base
.id
,
4299 intel_plane
->base
.name
);
4303 /* Check src format */
4304 switch (fb
->pixel_format
) {
4305 case DRM_FORMAT_RGB565
:
4306 case DRM_FORMAT_XBGR8888
:
4307 case DRM_FORMAT_XRGB8888
:
4308 case DRM_FORMAT_ABGR8888
:
4309 case DRM_FORMAT_ARGB8888
:
4310 case DRM_FORMAT_XRGB2101010
:
4311 case DRM_FORMAT_XBGR2101010
:
4312 case DRM_FORMAT_YUYV
:
4313 case DRM_FORMAT_YVYU
:
4314 case DRM_FORMAT_UYVY
:
4315 case DRM_FORMAT_VYUY
:
4318 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
4319 intel_plane
->base
.base
.id
, intel_plane
->base
.name
,
4320 fb
->base
.id
, fb
->pixel_format
);
4327 static void skylake_scaler_disable(struct intel_crtc
*crtc
)
4331 for (i
= 0; i
< crtc
->num_scalers
; i
++)
4332 skl_detach_scaler(crtc
, i
);
4335 static void skylake_pfit_enable(struct intel_crtc
*crtc
)
4337 struct drm_device
*dev
= crtc
->base
.dev
;
4338 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4339 int pipe
= crtc
->pipe
;
4340 struct intel_crtc_scaler_state
*scaler_state
=
4341 &crtc
->config
->scaler_state
;
4343 DRM_DEBUG_KMS("for crtc_state = %p\n", crtc
->config
);
4345 if (crtc
->config
->pch_pfit
.enabled
) {
4348 if (WARN_ON(crtc
->config
->scaler_state
.scaler_id
< 0)) {
4349 DRM_ERROR("Requesting pfit without getting a scaler first\n");
4353 id
= scaler_state
->scaler_id
;
4354 I915_WRITE(SKL_PS_CTRL(pipe
, id
), PS_SCALER_EN
|
4355 PS_FILTER_MEDIUM
| scaler_state
->scalers
[id
].mode
);
4356 I915_WRITE(SKL_PS_WIN_POS(pipe
, id
), crtc
->config
->pch_pfit
.pos
);
4357 I915_WRITE(SKL_PS_WIN_SZ(pipe
, id
), crtc
->config
->pch_pfit
.size
);
4359 DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc
->config
, id
);
4363 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
4365 struct drm_device
*dev
= crtc
->base
.dev
;
4366 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4367 int pipe
= crtc
->pipe
;
4369 if (crtc
->config
->pch_pfit
.enabled
) {
4370 /* Force use of hard-coded filter coefficients
4371 * as some pre-programmed values are broken,
4374 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
))
4375 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
4376 PF_PIPE_SEL_IVB(pipe
));
4378 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
4379 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
->pch_pfit
.pos
);
4380 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
->pch_pfit
.size
);
4384 void hsw_enable_ips(struct intel_crtc
*crtc
)
4386 struct drm_device
*dev
= crtc
->base
.dev
;
4387 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4389 if (!crtc
->config
->ips_enabled
)
4393 * We can only enable IPS after we enable a plane and wait for a vblank
4394 * This function is called from post_plane_update, which is run after
4398 assert_plane_enabled(dev_priv
, crtc
->plane
);
4399 if (IS_BROADWELL(dev
)) {
4400 mutex_lock(&dev_priv
->rps
.hw_lock
);
4401 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
4402 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4403 /* Quoting Art Runyan: "its not safe to expect any particular
4404 * value in IPS_CTL bit 31 after enabling IPS through the
4405 * mailbox." Moreover, the mailbox may return a bogus state,
4406 * so we need to just enable it and continue on.
4409 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
4410 /* The bit only becomes 1 in the next vblank, so this wait here
4411 * is essentially intel_wait_for_vblank. If we don't have this
4412 * and don't wait for vblanks until the end of crtc_enable, then
4413 * the HW state readout code will complain that the expected
4414 * IPS_CTL value is not the one we read. */
4415 if (intel_wait_for_register(dev_priv
,
4416 IPS_CTL
, IPS_ENABLE
, IPS_ENABLE
,
4418 DRM_ERROR("Timed out waiting for IPS enable\n");
4422 void hsw_disable_ips(struct intel_crtc
*crtc
)
4424 struct drm_device
*dev
= crtc
->base
.dev
;
4425 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4427 if (!crtc
->config
->ips_enabled
)
4430 assert_plane_enabled(dev_priv
, crtc
->plane
);
4431 if (IS_BROADWELL(dev
)) {
4432 mutex_lock(&dev_priv
->rps
.hw_lock
);
4433 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
4434 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4435 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4436 if (intel_wait_for_register(dev_priv
,
4437 IPS_CTL
, IPS_ENABLE
, 0,
4439 DRM_ERROR("Timed out waiting for IPS disable\n");
4441 I915_WRITE(IPS_CTL
, 0);
4442 POSTING_READ(IPS_CTL
);
4445 /* We need to wait for a vblank before we can disable the plane. */
4446 intel_wait_for_vblank(dev
, crtc
->pipe
);
4449 static void intel_crtc_dpms_overlay_disable(struct intel_crtc
*intel_crtc
)
4451 if (intel_crtc
->overlay
) {
4452 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4453 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4455 mutex_lock(&dev
->struct_mutex
);
4456 dev_priv
->mm
.interruptible
= false;
4457 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
4458 dev_priv
->mm
.interruptible
= true;
4459 mutex_unlock(&dev
->struct_mutex
);
4462 /* Let userspace switch the overlay on again. In most cases userspace
4463 * has to recompute where to put it anyway.
4468 * intel_post_enable_primary - Perform operations after enabling primary plane
4469 * @crtc: the CRTC whose primary plane was just enabled
4471 * Performs potentially sleeping operations that must be done after the primary
4472 * plane is enabled, such as updating FBC and IPS. Note that this may be
4473 * called due to an explicit primary plane update, or due to an implicit
4474 * re-enable that is caused when a sprite plane is updated to no longer
4475 * completely hide the primary plane.
4478 intel_post_enable_primary(struct drm_crtc
*crtc
)
4480 struct drm_device
*dev
= crtc
->dev
;
4481 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4482 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4483 int pipe
= intel_crtc
->pipe
;
4486 * FIXME IPS should be fine as long as one plane is
4487 * enabled, but in practice it seems to have problems
4488 * when going from primary only to sprite only and vice
4491 hsw_enable_ips(intel_crtc
);
4494 * Gen2 reports pipe underruns whenever all planes are disabled.
4495 * So don't enable underrun reporting before at least some planes
4497 * FIXME: Need to fix the logic to work when we turn off all planes
4498 * but leave the pipe running.
4501 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4503 /* Underruns don't always raise interrupts, so check manually. */
4504 intel_check_cpu_fifo_underruns(dev_priv
);
4505 intel_check_pch_fifo_underruns(dev_priv
);
4508 /* FIXME move all this to pre_plane_update() with proper state tracking */
4510 intel_pre_disable_primary(struct drm_crtc
*crtc
)
4512 struct drm_device
*dev
= crtc
->dev
;
4513 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4514 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4515 int pipe
= intel_crtc
->pipe
;
4518 * Gen2 reports pipe underruns whenever all planes are disabled.
4519 * So diasble underrun reporting before all the planes get disabled.
4520 * FIXME: Need to fix the logic to work when we turn off all planes
4521 * but leave the pipe running.
4524 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4527 * FIXME IPS should be fine as long as one plane is
4528 * enabled, but in practice it seems to have problems
4529 * when going from primary only to sprite only and vice
4532 hsw_disable_ips(intel_crtc
);
4535 /* FIXME get rid of this and use pre_plane_update */
4537 intel_pre_disable_primary_noatomic(struct drm_crtc
*crtc
)
4539 struct drm_device
*dev
= crtc
->dev
;
4540 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4541 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4542 int pipe
= intel_crtc
->pipe
;
4544 intel_pre_disable_primary(crtc
);
4547 * Vblank time updates from the shadow to live plane control register
4548 * are blocked if the memory self-refresh mode is active at that
4549 * moment. So to make sure the plane gets truly disabled, disable
4550 * first the self-refresh mode. The self-refresh enable bit in turn
4551 * will be checked/applied by the HW only at the next frame start
4552 * event which is after the vblank start event, so we need to have a
4553 * wait-for-vblank between disabling the plane and the pipe.
4555 if (HAS_GMCH_DISPLAY(dev
)) {
4556 intel_set_memory_cxsr(dev_priv
, false);
4557 dev_priv
->wm
.vlv
.cxsr
= false;
4558 intel_wait_for_vblank(dev
, pipe
);
4562 static void intel_post_plane_update(struct intel_crtc_state
*old_crtc_state
)
4564 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
4565 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
4566 struct intel_crtc_state
*pipe_config
=
4567 to_intel_crtc_state(crtc
->base
.state
);
4568 struct drm_device
*dev
= crtc
->base
.dev
;
4569 struct drm_plane
*primary
= crtc
->base
.primary
;
4570 struct drm_plane_state
*old_pri_state
=
4571 drm_atomic_get_existing_plane_state(old_state
, primary
);
4573 intel_frontbuffer_flip(dev
, pipe_config
->fb_bits
);
4575 crtc
->wm
.cxsr_allowed
= true;
4577 if (pipe_config
->update_wm_post
&& pipe_config
->base
.active
)
4578 intel_update_watermarks(&crtc
->base
);
4580 if (old_pri_state
) {
4581 struct intel_plane_state
*primary_state
=
4582 to_intel_plane_state(primary
->state
);
4583 struct intel_plane_state
*old_primary_state
=
4584 to_intel_plane_state(old_pri_state
);
4586 intel_fbc_post_update(crtc
);
4588 if (primary_state
->visible
&&
4589 (needs_modeset(&pipe_config
->base
) ||
4590 !old_primary_state
->visible
))
4591 intel_post_enable_primary(&crtc
->base
);
4595 static void intel_pre_plane_update(struct intel_crtc_state
*old_crtc_state
)
4597 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
4598 struct drm_device
*dev
= crtc
->base
.dev
;
4599 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4600 struct intel_crtc_state
*pipe_config
=
4601 to_intel_crtc_state(crtc
->base
.state
);
4602 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
4603 struct drm_plane
*primary
= crtc
->base
.primary
;
4604 struct drm_plane_state
*old_pri_state
=
4605 drm_atomic_get_existing_plane_state(old_state
, primary
);
4606 bool modeset
= needs_modeset(&pipe_config
->base
);
4608 if (old_pri_state
) {
4609 struct intel_plane_state
*primary_state
=
4610 to_intel_plane_state(primary
->state
);
4611 struct intel_plane_state
*old_primary_state
=
4612 to_intel_plane_state(old_pri_state
);
4614 intel_fbc_pre_update(crtc
, pipe_config
, primary_state
);
4616 if (old_primary_state
->visible
&&
4617 (modeset
|| !primary_state
->visible
))
4618 intel_pre_disable_primary(&crtc
->base
);
4621 if (pipe_config
->disable_cxsr
&& HAS_GMCH_DISPLAY(dev
)) {
4622 crtc
->wm
.cxsr_allowed
= false;
4625 * Vblank time updates from the shadow to live plane control register
4626 * are blocked if the memory self-refresh mode is active at that
4627 * moment. So to make sure the plane gets truly disabled, disable
4628 * first the self-refresh mode. The self-refresh enable bit in turn
4629 * will be checked/applied by the HW only at the next frame start
4630 * event which is after the vblank start event, so we need to have a
4631 * wait-for-vblank between disabling the plane and the pipe.
4633 if (old_crtc_state
->base
.active
) {
4634 intel_set_memory_cxsr(dev_priv
, false);
4635 dev_priv
->wm
.vlv
.cxsr
= false;
4636 intel_wait_for_vblank(dev
, crtc
->pipe
);
4641 * IVB workaround: must disable low power watermarks for at least
4642 * one frame before enabling scaling. LP watermarks can be re-enabled
4643 * when scaling is disabled.
4645 * WaCxSRDisabledForSpriteScaling:ivb
4647 if (pipe_config
->disable_lp_wm
) {
4648 ilk_disable_lp_wm(dev
);
4649 intel_wait_for_vblank(dev
, crtc
->pipe
);
4653 * If we're doing a modeset, we're done. No need to do any pre-vblank
4654 * watermark programming here.
4656 if (needs_modeset(&pipe_config
->base
))
4660 * For platforms that support atomic watermarks, program the
4661 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
4662 * will be the intermediate values that are safe for both pre- and
4663 * post- vblank; when vblank happens, the 'active' values will be set
4664 * to the final 'target' values and we'll do this again to get the
4665 * optimal watermarks. For gen9+ platforms, the values we program here
4666 * will be the final target values which will get automatically latched
4667 * at vblank time; no further programming will be necessary.
4669 * If a platform hasn't been transitioned to atomic watermarks yet,
4670 * we'll continue to update watermarks the old way, if flags tell
4673 if (dev_priv
->display
.initial_watermarks
!= NULL
)
4674 dev_priv
->display
.initial_watermarks(pipe_config
);
4675 else if (pipe_config
->update_wm_pre
)
4676 intel_update_watermarks(&crtc
->base
);
4679 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
, unsigned plane_mask
)
4681 struct drm_device
*dev
= crtc
->dev
;
4682 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4683 struct drm_plane
*p
;
4684 int pipe
= intel_crtc
->pipe
;
4686 intel_crtc_dpms_overlay_disable(intel_crtc
);
4688 drm_for_each_plane_mask(p
, dev
, plane_mask
)
4689 to_intel_plane(p
)->disable_plane(p
, crtc
);
4692 * FIXME: Once we grow proper nuclear flip support out of this we need
4693 * to compute the mask of flip planes precisely. For the time being
4694 * consider this a flip to a NULL plane.
4696 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_ALL_MASK(pipe
));
4699 static void ironlake_crtc_enable(struct drm_crtc
*crtc
)
4701 struct drm_device
*dev
= crtc
->dev
;
4702 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4703 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4704 struct intel_encoder
*encoder
;
4705 int pipe
= intel_crtc
->pipe
;
4706 struct intel_crtc_state
*pipe_config
=
4707 to_intel_crtc_state(crtc
->state
);
4709 if (WARN_ON(intel_crtc
->active
))
4713 * Sometimes spurious CPU pipe underruns happen during FDI
4714 * training, at least with VGA+HDMI cloning. Suppress them.
4716 * On ILK we get an occasional spurious CPU pipe underruns
4717 * between eDP port A enable and vdd enable. Also PCH port
4718 * enable seems to result in the occasional CPU pipe underrun.
4720 * Spurious PCH underruns also occur during PCH enabling.
4722 if (intel_crtc
->config
->has_pch_encoder
|| IS_GEN5(dev_priv
))
4723 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4724 if (intel_crtc
->config
->has_pch_encoder
)
4725 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
4727 if (intel_crtc
->config
->has_pch_encoder
)
4728 intel_prepare_shared_dpll(intel_crtc
);
4730 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
4731 intel_dp_set_m_n(intel_crtc
, M1_N1
);
4733 intel_set_pipe_timings(intel_crtc
);
4734 intel_set_pipe_src_size(intel_crtc
);
4736 if (intel_crtc
->config
->has_pch_encoder
) {
4737 intel_cpu_transcoder_set_m_n(intel_crtc
,
4738 &intel_crtc
->config
->fdi_m_n
, NULL
);
4741 ironlake_set_pipeconf(crtc
);
4743 intel_crtc
->active
= true;
4745 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4746 if (encoder
->pre_enable
)
4747 encoder
->pre_enable(encoder
);
4749 if (intel_crtc
->config
->has_pch_encoder
) {
4750 /* Note: FDI PLL enabling _must_ be done before we enable the
4751 * cpu pipes, hence this is separate from all the other fdi/pch
4753 ironlake_fdi_pll_enable(intel_crtc
);
4755 assert_fdi_tx_disabled(dev_priv
, pipe
);
4756 assert_fdi_rx_disabled(dev_priv
, pipe
);
4759 ironlake_pfit_enable(intel_crtc
);
4762 * On ILK+ LUT must be loaded before the pipe is running but with
4765 intel_color_load_luts(&pipe_config
->base
);
4767 if (dev_priv
->display
.initial_watermarks
!= NULL
)
4768 dev_priv
->display
.initial_watermarks(intel_crtc
->config
);
4769 intel_enable_pipe(intel_crtc
);
4771 if (intel_crtc
->config
->has_pch_encoder
)
4772 ironlake_pch_enable(crtc
);
4774 assert_vblank_disabled(crtc
);
4775 drm_crtc_vblank_on(crtc
);
4777 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4778 encoder
->enable(encoder
);
4780 if (HAS_PCH_CPT(dev
))
4781 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
4783 /* Must wait for vblank to avoid spurious PCH FIFO underruns */
4784 if (intel_crtc
->config
->has_pch_encoder
)
4785 intel_wait_for_vblank(dev
, pipe
);
4786 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4787 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
4790 /* IPS only exists on ULT machines and is tied to pipe A. */
4791 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
4793 return HAS_IPS(crtc
->base
.dev
) && crtc
->pipe
== PIPE_A
;
4796 static void haswell_crtc_enable(struct drm_crtc
*crtc
)
4798 struct drm_device
*dev
= crtc
->dev
;
4799 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4800 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4801 struct intel_encoder
*encoder
;
4802 int pipe
= intel_crtc
->pipe
, hsw_workaround_pipe
;
4803 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
4804 struct intel_crtc_state
*pipe_config
=
4805 to_intel_crtc_state(crtc
->state
);
4807 if (WARN_ON(intel_crtc
->active
))
4810 if (intel_crtc
->config
->has_pch_encoder
)
4811 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
4814 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4815 if (encoder
->pre_pll_enable
)
4816 encoder
->pre_pll_enable(encoder
);
4818 if (intel_crtc
->config
->shared_dpll
)
4819 intel_enable_shared_dpll(intel_crtc
);
4821 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
4822 intel_dp_set_m_n(intel_crtc
, M1_N1
);
4824 if (!transcoder_is_dsi(cpu_transcoder
))
4825 intel_set_pipe_timings(intel_crtc
);
4827 intel_set_pipe_src_size(intel_crtc
);
4829 if (cpu_transcoder
!= TRANSCODER_EDP
&&
4830 !transcoder_is_dsi(cpu_transcoder
)) {
4831 I915_WRITE(PIPE_MULT(cpu_transcoder
),
4832 intel_crtc
->config
->pixel_multiplier
- 1);
4835 if (intel_crtc
->config
->has_pch_encoder
) {
4836 intel_cpu_transcoder_set_m_n(intel_crtc
,
4837 &intel_crtc
->config
->fdi_m_n
, NULL
);
4840 if (!transcoder_is_dsi(cpu_transcoder
))
4841 haswell_set_pipeconf(crtc
);
4843 haswell_set_pipemisc(crtc
);
4845 intel_color_set_csc(&pipe_config
->base
);
4847 intel_crtc
->active
= true;
4849 if (intel_crtc
->config
->has_pch_encoder
)
4850 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4852 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4854 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4855 if (encoder
->pre_enable
)
4856 encoder
->pre_enable(encoder
);
4859 if (intel_crtc
->config
->has_pch_encoder
)
4860 dev_priv
->display
.fdi_link_train(crtc
);
4862 if (!transcoder_is_dsi(cpu_transcoder
))
4863 intel_ddi_enable_pipe_clock(intel_crtc
);
4865 if (INTEL_INFO(dev
)->gen
>= 9)
4866 skylake_pfit_enable(intel_crtc
);
4868 ironlake_pfit_enable(intel_crtc
);
4871 * On ILK+ LUT must be loaded before the pipe is running but with
4874 intel_color_load_luts(&pipe_config
->base
);
4876 intel_ddi_set_pipe_settings(crtc
);
4877 if (!transcoder_is_dsi(cpu_transcoder
))
4878 intel_ddi_enable_transcoder_func(crtc
);
4880 if (dev_priv
->display
.initial_watermarks
!= NULL
)
4881 dev_priv
->display
.initial_watermarks(pipe_config
);
4883 intel_update_watermarks(crtc
);
4885 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
4886 if (!transcoder_is_dsi(cpu_transcoder
))
4887 intel_enable_pipe(intel_crtc
);
4889 if (intel_crtc
->config
->has_pch_encoder
)
4890 lpt_pch_enable(crtc
);
4892 if (intel_crtc
->config
->dp_encoder_is_mst
)
4893 intel_ddi_set_vc_payload_alloc(crtc
, true);
4895 assert_vblank_disabled(crtc
);
4896 drm_crtc_vblank_on(crtc
);
4898 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4899 encoder
->enable(encoder
);
4900 intel_opregion_notify_encoder(encoder
, true);
4903 if (intel_crtc
->config
->has_pch_encoder
) {
4904 intel_wait_for_vblank(dev
, pipe
);
4905 intel_wait_for_vblank(dev
, pipe
);
4906 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4907 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
4911 /* If we change the relative order between pipe/planes enabling, we need
4912 * to change the workaround. */
4913 hsw_workaround_pipe
= pipe_config
->hsw_workaround_pipe
;
4914 if (IS_HASWELL(dev
) && hsw_workaround_pipe
!= INVALID_PIPE
) {
4915 intel_wait_for_vblank(dev
, hsw_workaround_pipe
);
4916 intel_wait_for_vblank(dev
, hsw_workaround_pipe
);
4920 static void ironlake_pfit_disable(struct intel_crtc
*crtc
, bool force
)
4922 struct drm_device
*dev
= crtc
->base
.dev
;
4923 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4924 int pipe
= crtc
->pipe
;
4926 /* To avoid upsetting the power well on haswell only disable the pfit if
4927 * it's in use. The hw state code will make sure we get this right. */
4928 if (force
|| crtc
->config
->pch_pfit
.enabled
) {
4929 I915_WRITE(PF_CTL(pipe
), 0);
4930 I915_WRITE(PF_WIN_POS(pipe
), 0);
4931 I915_WRITE(PF_WIN_SZ(pipe
), 0);
4935 static void ironlake_crtc_disable(struct drm_crtc
*crtc
)
4937 struct drm_device
*dev
= crtc
->dev
;
4938 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4939 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4940 struct intel_encoder
*encoder
;
4941 int pipe
= intel_crtc
->pipe
;
4944 * Sometimes spurious CPU pipe underruns happen when the
4945 * pipe is already disabled, but FDI RX/TX is still enabled.
4946 * Happens at least with VGA+HDMI cloning. Suppress them.
4948 if (intel_crtc
->config
->has_pch_encoder
) {
4949 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4950 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
4953 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4954 encoder
->disable(encoder
);
4956 drm_crtc_vblank_off(crtc
);
4957 assert_vblank_disabled(crtc
);
4959 intel_disable_pipe(intel_crtc
);
4961 ironlake_pfit_disable(intel_crtc
, false);
4963 if (intel_crtc
->config
->has_pch_encoder
)
4964 ironlake_fdi_disable(crtc
);
4966 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4967 if (encoder
->post_disable
)
4968 encoder
->post_disable(encoder
);
4970 if (intel_crtc
->config
->has_pch_encoder
) {
4971 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
4973 if (HAS_PCH_CPT(dev
)) {
4977 /* disable TRANS_DP_CTL */
4978 reg
= TRANS_DP_CTL(pipe
);
4979 temp
= I915_READ(reg
);
4980 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
4981 TRANS_DP_PORT_SEL_MASK
);
4982 temp
|= TRANS_DP_PORT_SEL_NONE
;
4983 I915_WRITE(reg
, temp
);
4985 /* disable DPLL_SEL */
4986 temp
= I915_READ(PCH_DPLL_SEL
);
4987 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
4988 I915_WRITE(PCH_DPLL_SEL
, temp
);
4991 ironlake_fdi_pll_disable(intel_crtc
);
4994 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4995 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
4998 static void haswell_crtc_disable(struct drm_crtc
*crtc
)
5000 struct drm_device
*dev
= crtc
->dev
;
5001 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5002 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5003 struct intel_encoder
*encoder
;
5004 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5006 if (intel_crtc
->config
->has_pch_encoder
)
5007 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5010 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5011 intel_opregion_notify_encoder(encoder
, false);
5012 encoder
->disable(encoder
);
5015 drm_crtc_vblank_off(crtc
);
5016 assert_vblank_disabled(crtc
);
5018 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5019 if (!transcoder_is_dsi(cpu_transcoder
))
5020 intel_disable_pipe(intel_crtc
);
5022 if (intel_crtc
->config
->dp_encoder_is_mst
)
5023 intel_ddi_set_vc_payload_alloc(crtc
, false);
5025 if (!transcoder_is_dsi(cpu_transcoder
))
5026 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
5028 if (INTEL_INFO(dev
)->gen
>= 9)
5029 skylake_scaler_disable(intel_crtc
);
5031 ironlake_pfit_disable(intel_crtc
, false);
5033 if (!transcoder_is_dsi(cpu_transcoder
))
5034 intel_ddi_disable_pipe_clock(intel_crtc
);
5036 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5037 if (encoder
->post_disable
)
5038 encoder
->post_disable(encoder
);
5040 if (intel_crtc
->config
->has_pch_encoder
) {
5041 lpt_disable_pch_transcoder(dev_priv
);
5042 lpt_disable_iclkip(dev_priv
);
5043 intel_ddi_fdi_disable(crtc
);
5045 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5050 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
5052 struct drm_device
*dev
= crtc
->base
.dev
;
5053 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5054 struct intel_crtc_state
*pipe_config
= crtc
->config
;
5056 if (!pipe_config
->gmch_pfit
.control
)
5060 * The panel fitter should only be adjusted whilst the pipe is disabled,
5061 * according to register description and PRM.
5063 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
5064 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5066 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
5067 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
5069 /* Border color in case we don't scale up to the full screen. Black by
5070 * default, change to something else for debugging. */
5071 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
5074 static enum intel_display_power_domain
port_to_power_domain(enum port port
)
5078 return POWER_DOMAIN_PORT_DDI_A_LANES
;
5080 return POWER_DOMAIN_PORT_DDI_B_LANES
;
5082 return POWER_DOMAIN_PORT_DDI_C_LANES
;
5084 return POWER_DOMAIN_PORT_DDI_D_LANES
;
5086 return POWER_DOMAIN_PORT_DDI_E_LANES
;
5089 return POWER_DOMAIN_PORT_OTHER
;
5093 static enum intel_display_power_domain
port_to_aux_power_domain(enum port port
)
5097 return POWER_DOMAIN_AUX_A
;
5099 return POWER_DOMAIN_AUX_B
;
5101 return POWER_DOMAIN_AUX_C
;
5103 return POWER_DOMAIN_AUX_D
;
5105 /* FIXME: Check VBT for actual wiring of PORT E */
5106 return POWER_DOMAIN_AUX_D
;
5109 return POWER_DOMAIN_AUX_A
;
5113 enum intel_display_power_domain
5114 intel_display_port_power_domain(struct intel_encoder
*intel_encoder
)
5116 struct drm_device
*dev
= intel_encoder
->base
.dev
;
5117 struct intel_digital_port
*intel_dig_port
;
5119 switch (intel_encoder
->type
) {
5120 case INTEL_OUTPUT_UNKNOWN
:
5121 /* Only DDI platforms should ever use this output type */
5122 WARN_ON_ONCE(!HAS_DDI(dev
));
5123 case INTEL_OUTPUT_DP
:
5124 case INTEL_OUTPUT_HDMI
:
5125 case INTEL_OUTPUT_EDP
:
5126 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
5127 return port_to_power_domain(intel_dig_port
->port
);
5128 case INTEL_OUTPUT_DP_MST
:
5129 intel_dig_port
= enc_to_mst(&intel_encoder
->base
)->primary
;
5130 return port_to_power_domain(intel_dig_port
->port
);
5131 case INTEL_OUTPUT_ANALOG
:
5132 return POWER_DOMAIN_PORT_CRT
;
5133 case INTEL_OUTPUT_DSI
:
5134 return POWER_DOMAIN_PORT_DSI
;
5136 return POWER_DOMAIN_PORT_OTHER
;
5140 enum intel_display_power_domain
5141 intel_display_port_aux_power_domain(struct intel_encoder
*intel_encoder
)
5143 struct drm_device
*dev
= intel_encoder
->base
.dev
;
5144 struct intel_digital_port
*intel_dig_port
;
5146 switch (intel_encoder
->type
) {
5147 case INTEL_OUTPUT_UNKNOWN
:
5148 case INTEL_OUTPUT_HDMI
:
5150 * Only DDI platforms should ever use these output types.
5151 * We can get here after the HDMI detect code has already set
5152 * the type of the shared encoder. Since we can't be sure
5153 * what's the status of the given connectors, play safe and
5154 * run the DP detection too.
5156 WARN_ON_ONCE(!HAS_DDI(dev
));
5157 case INTEL_OUTPUT_DP
:
5158 case INTEL_OUTPUT_EDP
:
5159 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
5160 return port_to_aux_power_domain(intel_dig_port
->port
);
5161 case INTEL_OUTPUT_DP_MST
:
5162 intel_dig_port
= enc_to_mst(&intel_encoder
->base
)->primary
;
5163 return port_to_aux_power_domain(intel_dig_port
->port
);
5165 MISSING_CASE(intel_encoder
->type
);
5166 return POWER_DOMAIN_AUX_A
;
5170 static unsigned long get_crtc_power_domains(struct drm_crtc
*crtc
,
5171 struct intel_crtc_state
*crtc_state
)
5173 struct drm_device
*dev
= crtc
->dev
;
5174 struct drm_encoder
*encoder
;
5175 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5176 enum pipe pipe
= intel_crtc
->pipe
;
5178 enum transcoder transcoder
= crtc_state
->cpu_transcoder
;
5180 if (!crtc_state
->base
.active
)
5183 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
5184 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
5185 if (crtc_state
->pch_pfit
.enabled
||
5186 crtc_state
->pch_pfit
.force_thru
)
5187 mask
|= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
5189 drm_for_each_encoder_mask(encoder
, dev
, crtc_state
->base
.encoder_mask
) {
5190 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5192 mask
|= BIT(intel_display_port_power_domain(intel_encoder
));
5195 if (crtc_state
->shared_dpll
)
5196 mask
|= BIT(POWER_DOMAIN_PLLS
);
5201 static unsigned long
5202 modeset_get_crtc_power_domains(struct drm_crtc
*crtc
,
5203 struct intel_crtc_state
*crtc_state
)
5205 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5206 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5207 enum intel_display_power_domain domain
;
5208 unsigned long domains
, new_domains
, old_domains
;
5210 old_domains
= intel_crtc
->enabled_power_domains
;
5211 intel_crtc
->enabled_power_domains
= new_domains
=
5212 get_crtc_power_domains(crtc
, crtc_state
);
5214 domains
= new_domains
& ~old_domains
;
5216 for_each_power_domain(domain
, domains
)
5217 intel_display_power_get(dev_priv
, domain
);
5219 return old_domains
& ~new_domains
;
5222 static void modeset_put_power_domains(struct drm_i915_private
*dev_priv
,
5223 unsigned long domains
)
5225 enum intel_display_power_domain domain
;
5227 for_each_power_domain(domain
, domains
)
5228 intel_display_power_put(dev_priv
, domain
);
5231 static int intel_compute_max_dotclk(struct drm_i915_private
*dev_priv
)
5233 int max_cdclk_freq
= dev_priv
->max_cdclk_freq
;
5235 if (INTEL_INFO(dev_priv
)->gen
>= 9 ||
5236 IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
5237 return max_cdclk_freq
;
5238 else if (IS_CHERRYVIEW(dev_priv
))
5239 return max_cdclk_freq
*95/100;
5240 else if (INTEL_INFO(dev_priv
)->gen
< 4)
5241 return 2*max_cdclk_freq
*90/100;
5243 return max_cdclk_freq
*90/100;
5246 static int skl_calc_cdclk(int max_pixclk
, int vco
);
5248 static void intel_update_max_cdclk(struct drm_device
*dev
)
5250 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5252 if (IS_SKYLAKE(dev
) || IS_KABYLAKE(dev
)) {
5253 u32 limit
= I915_READ(SKL_DFSM
) & SKL_DFSM_CDCLK_LIMIT_MASK
;
5256 vco
= dev_priv
->skl_preferred_vco_freq
;
5257 WARN_ON(vco
!= 8100000 && vco
!= 8640000);
5260 * Use the lower (vco 8640) cdclk values as a
5261 * first guess. skl_calc_cdclk() will correct it
5262 * if the preferred vco is 8100 instead.
5264 if (limit
== SKL_DFSM_CDCLK_LIMIT_675
)
5266 else if (limit
== SKL_DFSM_CDCLK_LIMIT_540
)
5268 else if (limit
== SKL_DFSM_CDCLK_LIMIT_450
)
5273 dev_priv
->max_cdclk_freq
= skl_calc_cdclk(max_cdclk
, vco
);
5274 } else if (IS_BROXTON(dev
)) {
5275 dev_priv
->max_cdclk_freq
= 624000;
5276 } else if (IS_BROADWELL(dev
)) {
5278 * FIXME with extra cooling we can allow
5279 * 540 MHz for ULX and 675 Mhz for ULT.
5280 * How can we know if extra cooling is
5281 * available? PCI ID, VTB, something else?
5283 if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
5284 dev_priv
->max_cdclk_freq
= 450000;
5285 else if (IS_BDW_ULX(dev
))
5286 dev_priv
->max_cdclk_freq
= 450000;
5287 else if (IS_BDW_ULT(dev
))
5288 dev_priv
->max_cdclk_freq
= 540000;
5290 dev_priv
->max_cdclk_freq
= 675000;
5291 } else if (IS_CHERRYVIEW(dev
)) {
5292 dev_priv
->max_cdclk_freq
= 320000;
5293 } else if (IS_VALLEYVIEW(dev
)) {
5294 dev_priv
->max_cdclk_freq
= 400000;
5296 /* otherwise assume cdclk is fixed */
5297 dev_priv
->max_cdclk_freq
= dev_priv
->cdclk_freq
;
5300 dev_priv
->max_dotclk_freq
= intel_compute_max_dotclk(dev_priv
);
5302 DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n",
5303 dev_priv
->max_cdclk_freq
);
5305 DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n",
5306 dev_priv
->max_dotclk_freq
);
5309 static void intel_update_cdclk(struct drm_device
*dev
)
5311 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5313 dev_priv
->cdclk_freq
= dev_priv
->display
.get_display_clock_speed(dev
);
5315 if (INTEL_GEN(dev_priv
) >= 9)
5316 DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz, VCO: %d kHz, ref: %d kHz\n",
5317 dev_priv
->cdclk_freq
, dev_priv
->cdclk_pll
.vco
,
5318 dev_priv
->cdclk_pll
.ref
);
5320 DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n",
5321 dev_priv
->cdclk_freq
);
5324 * 9:0 CMBUS [sic] CDCLK frequency (cdfreq):
5325 * Programmng [sic] note: bit[9:2] should be programmed to the number
5326 * of cdclk that generates 4MHz reference clock freq which is used to
5327 * generate GMBus clock. This will vary with the cdclk freq.
5329 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
5330 I915_WRITE(GMBUSFREQ_VLV
, DIV_ROUND_UP(dev_priv
->cdclk_freq
, 1000));
5333 /* convert from kHz to .1 fixpoint MHz with -1MHz offset */
5334 static int skl_cdclk_decimal(int cdclk
)
5336 return DIV_ROUND_CLOSEST(cdclk
- 1000, 500);
5339 static int bxt_de_pll_vco(struct drm_i915_private
*dev_priv
, int cdclk
)
5343 if (cdclk
== dev_priv
->cdclk_pll
.ref
)
5348 MISSING_CASE(cdclk
);
5360 return dev_priv
->cdclk_pll
.ref
* ratio
;
5363 static void bxt_de_pll_disable(struct drm_i915_private
*dev_priv
)
5365 I915_WRITE(BXT_DE_PLL_ENABLE
, 0);
5368 if (intel_wait_for_register(dev_priv
,
5369 BXT_DE_PLL_ENABLE
, BXT_DE_PLL_LOCK
, 0,
5371 DRM_ERROR("timeout waiting for DE PLL unlock\n");
5373 dev_priv
->cdclk_pll
.vco
= 0;
5376 static void bxt_de_pll_enable(struct drm_i915_private
*dev_priv
, int vco
)
5378 int ratio
= DIV_ROUND_CLOSEST(vco
, dev_priv
->cdclk_pll
.ref
);
5381 val
= I915_READ(BXT_DE_PLL_CTL
);
5382 val
&= ~BXT_DE_PLL_RATIO_MASK
;
5383 val
|= BXT_DE_PLL_RATIO(ratio
);
5384 I915_WRITE(BXT_DE_PLL_CTL
, val
);
5386 I915_WRITE(BXT_DE_PLL_ENABLE
, BXT_DE_PLL_PLL_ENABLE
);
5389 if (intel_wait_for_register(dev_priv
,
5394 DRM_ERROR("timeout waiting for DE PLL lock\n");
5396 dev_priv
->cdclk_pll
.vco
= vco
;
5399 static void bxt_set_cdclk(struct drm_i915_private
*dev_priv
, int cdclk
)
5404 vco
= bxt_de_pll_vco(dev_priv
, cdclk
);
5406 DRM_DEBUG_DRIVER("Changing CDCLK to %d kHz (VCO %d kHz)\n", cdclk
, vco
);
5408 /* cdclk = vco / 2 / div{1,1.5,2,4} */
5409 switch (DIV_ROUND_CLOSEST(vco
, cdclk
)) {
5411 divider
= BXT_CDCLK_CD2X_DIV_SEL_4
;
5414 divider
= BXT_CDCLK_CD2X_DIV_SEL_2
;
5417 divider
= BXT_CDCLK_CD2X_DIV_SEL_1_5
;
5420 divider
= BXT_CDCLK_CD2X_DIV_SEL_1
;
5423 WARN_ON(cdclk
!= dev_priv
->cdclk_pll
.ref
);
5426 divider
= BXT_CDCLK_CD2X_DIV_SEL_1
;
5430 /* Inform power controller of upcoming frequency change */
5431 mutex_lock(&dev_priv
->rps
.hw_lock
);
5432 ret
= sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
,
5434 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5437 DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n",
5442 if (dev_priv
->cdclk_pll
.vco
!= 0 &&
5443 dev_priv
->cdclk_pll
.vco
!= vco
)
5444 bxt_de_pll_disable(dev_priv
);
5446 if (dev_priv
->cdclk_pll
.vco
!= vco
)
5447 bxt_de_pll_enable(dev_priv
, vco
);
5449 val
= divider
| skl_cdclk_decimal(cdclk
);
5451 * FIXME if only the cd2x divider needs changing, it could be done
5452 * without shutting off the pipe (if only one pipe is active).
5454 val
|= BXT_CDCLK_CD2X_PIPE_NONE
;
5456 * Disable SSA Precharge when CD clock frequency < 500 MHz,
5459 if (cdclk
>= 500000)
5460 val
|= BXT_CDCLK_SSA_PRECHARGE_ENABLE
;
5461 I915_WRITE(CDCLK_CTL
, val
);
5463 mutex_lock(&dev_priv
->rps
.hw_lock
);
5464 ret
= sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
,
5465 DIV_ROUND_UP(cdclk
, 25000));
5466 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5469 DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n",
5474 intel_update_cdclk(&dev_priv
->drm
);
5477 static void bxt_sanitize_cdclk(struct drm_i915_private
*dev_priv
)
5479 u32 cdctl
, expected
;
5481 intel_update_cdclk(&dev_priv
->drm
);
5483 if (dev_priv
->cdclk_pll
.vco
== 0 ||
5484 dev_priv
->cdclk_freq
== dev_priv
->cdclk_pll
.ref
)
5487 /* DPLL okay; verify the cdclock
5489 * Some BIOS versions leave an incorrect decimal frequency value and
5490 * set reserved MBZ bits in CDCLK_CTL at least during exiting from S4,
5491 * so sanitize this register.
5493 cdctl
= I915_READ(CDCLK_CTL
);
5495 * Let's ignore the pipe field, since BIOS could have configured the
5496 * dividers both synching to an active pipe, or asynchronously
5499 cdctl
&= ~BXT_CDCLK_CD2X_PIPE_NONE
;
5501 expected
= (cdctl
& BXT_CDCLK_CD2X_DIV_SEL_MASK
) |
5502 skl_cdclk_decimal(dev_priv
->cdclk_freq
);
5504 * Disable SSA Precharge when CD clock frequency < 500 MHz,
5507 if (dev_priv
->cdclk_freq
>= 500000)
5508 expected
|= BXT_CDCLK_SSA_PRECHARGE_ENABLE
;
5510 if (cdctl
== expected
)
5511 /* All well; nothing to sanitize */
5515 DRM_DEBUG_KMS("Sanitizing cdclk programmed by pre-os\n");
5517 /* force cdclk programming */
5518 dev_priv
->cdclk_freq
= 0;
5520 /* force full PLL disable + enable */
5521 dev_priv
->cdclk_pll
.vco
= -1;
5524 void bxt_init_cdclk(struct drm_i915_private
*dev_priv
)
5526 bxt_sanitize_cdclk(dev_priv
);
5528 if (dev_priv
->cdclk_freq
!= 0 && dev_priv
->cdclk_pll
.vco
!= 0)
5533 * - The initial CDCLK needs to be read from VBT.
5534 * Need to make this change after VBT has changes for BXT.
5536 bxt_set_cdclk(dev_priv
, bxt_calc_cdclk(0));
5539 void bxt_uninit_cdclk(struct drm_i915_private
*dev_priv
)
5541 bxt_set_cdclk(dev_priv
, dev_priv
->cdclk_pll
.ref
);
5544 static int skl_calc_cdclk(int max_pixclk
, int vco
)
5546 if (vco
== 8640000) {
5547 if (max_pixclk
> 540000)
5549 else if (max_pixclk
> 432000)
5551 else if (max_pixclk
> 308571)
5556 if (max_pixclk
> 540000)
5558 else if (max_pixclk
> 450000)
5560 else if (max_pixclk
> 337500)
5568 skl_dpll0_update(struct drm_i915_private
*dev_priv
)
5572 dev_priv
->cdclk_pll
.ref
= 24000;
5573 dev_priv
->cdclk_pll
.vco
= 0;
5575 val
= I915_READ(LCPLL1_CTL
);
5576 if ((val
& LCPLL_PLL_ENABLE
) == 0)
5579 if (WARN_ON((val
& LCPLL_PLL_LOCK
) == 0))
5582 val
= I915_READ(DPLL_CTRL1
);
5584 if (WARN_ON((val
& (DPLL_CTRL1_HDMI_MODE(SKL_DPLL0
) |
5585 DPLL_CTRL1_SSC(SKL_DPLL0
) |
5586 DPLL_CTRL1_OVERRIDE(SKL_DPLL0
))) !=
5587 DPLL_CTRL1_OVERRIDE(SKL_DPLL0
)))
5590 switch (val
& DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
)) {
5591 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810
, SKL_DPLL0
):
5592 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1350
, SKL_DPLL0
):
5593 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1620
, SKL_DPLL0
):
5594 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2700
, SKL_DPLL0
):
5595 dev_priv
->cdclk_pll
.vco
= 8100000;
5597 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080
, SKL_DPLL0
):
5598 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2160
, SKL_DPLL0
):
5599 dev_priv
->cdclk_pll
.vco
= 8640000;
5602 MISSING_CASE(val
& DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
));
5607 void skl_set_preferred_cdclk_vco(struct drm_i915_private
*dev_priv
, int vco
)
5609 bool changed
= dev_priv
->skl_preferred_vco_freq
!= vco
;
5611 dev_priv
->skl_preferred_vco_freq
= vco
;
5614 intel_update_max_cdclk(&dev_priv
->drm
);
5618 skl_dpll0_enable(struct drm_i915_private
*dev_priv
, int vco
)
5620 int min_cdclk
= skl_calc_cdclk(0, vco
);
5623 WARN_ON(vco
!= 8100000 && vco
!= 8640000);
5625 /* select the minimum CDCLK before enabling DPLL 0 */
5626 val
= CDCLK_FREQ_337_308
| skl_cdclk_decimal(min_cdclk
);
5627 I915_WRITE(CDCLK_CTL
, val
);
5628 POSTING_READ(CDCLK_CTL
);
5631 * We always enable DPLL0 with the lowest link rate possible, but still
5632 * taking into account the VCO required to operate the eDP panel at the
5633 * desired frequency. The usual DP link rates operate with a VCO of
5634 * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640.
5635 * The modeset code is responsible for the selection of the exact link
5636 * rate later on, with the constraint of choosing a frequency that
5639 val
= I915_READ(DPLL_CTRL1
);
5641 val
&= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0
) | DPLL_CTRL1_SSC(SKL_DPLL0
) |
5642 DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
));
5643 val
|= DPLL_CTRL1_OVERRIDE(SKL_DPLL0
);
5645 val
|= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080
,
5648 val
|= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810
,
5651 I915_WRITE(DPLL_CTRL1
, val
);
5652 POSTING_READ(DPLL_CTRL1
);
5654 I915_WRITE(LCPLL1_CTL
, I915_READ(LCPLL1_CTL
) | LCPLL_PLL_ENABLE
);
5656 if (intel_wait_for_register(dev_priv
,
5657 LCPLL1_CTL
, LCPLL_PLL_LOCK
, LCPLL_PLL_LOCK
,
5659 DRM_ERROR("DPLL0 not locked\n");
5661 dev_priv
->cdclk_pll
.vco
= vco
;
5663 /* We'll want to keep using the current vco from now on. */
5664 skl_set_preferred_cdclk_vco(dev_priv
, vco
);
5668 skl_dpll0_disable(struct drm_i915_private
*dev_priv
)
5670 I915_WRITE(LCPLL1_CTL
, I915_READ(LCPLL1_CTL
) & ~LCPLL_PLL_ENABLE
);
5671 if (intel_wait_for_register(dev_priv
,
5672 LCPLL1_CTL
, LCPLL_PLL_LOCK
, 0,
5674 DRM_ERROR("Couldn't disable DPLL0\n");
5676 dev_priv
->cdclk_pll
.vco
= 0;
5679 static bool skl_cdclk_pcu_ready(struct drm_i915_private
*dev_priv
)
5684 /* inform PCU we want to change CDCLK */
5685 val
= SKL_CDCLK_PREPARE_FOR_CHANGE
;
5686 mutex_lock(&dev_priv
->rps
.hw_lock
);
5687 ret
= sandybridge_pcode_read(dev_priv
, SKL_PCODE_CDCLK_CONTROL
, &val
);
5688 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5690 return ret
== 0 && (val
& SKL_CDCLK_READY_FOR_CHANGE
);
5693 static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private
*dev_priv
)
5695 return _wait_for(skl_cdclk_pcu_ready(dev_priv
), 3000, 10) == 0;
5698 static void skl_set_cdclk(struct drm_i915_private
*dev_priv
, int cdclk
, int vco
)
5700 struct drm_device
*dev
= &dev_priv
->drm
;
5701 u32 freq_select
, pcu_ack
;
5703 WARN_ON((cdclk
== 24000) != (vco
== 0));
5705 DRM_DEBUG_DRIVER("Changing CDCLK to %d kHz (VCO %d kHz)\n", cdclk
, vco
);
5707 if (!skl_cdclk_wait_for_pcu_ready(dev_priv
)) {
5708 DRM_ERROR("failed to inform PCU about cdclk change\n");
5716 freq_select
= CDCLK_FREQ_450_432
;
5720 freq_select
= CDCLK_FREQ_540
;
5726 freq_select
= CDCLK_FREQ_337_308
;
5731 freq_select
= CDCLK_FREQ_675_617
;
5736 if (dev_priv
->cdclk_pll
.vco
!= 0 &&
5737 dev_priv
->cdclk_pll
.vco
!= vco
)
5738 skl_dpll0_disable(dev_priv
);
5740 if (dev_priv
->cdclk_pll
.vco
!= vco
)
5741 skl_dpll0_enable(dev_priv
, vco
);
5743 I915_WRITE(CDCLK_CTL
, freq_select
| skl_cdclk_decimal(cdclk
));
5744 POSTING_READ(CDCLK_CTL
);
5746 /* inform PCU of the change */
5747 mutex_lock(&dev_priv
->rps
.hw_lock
);
5748 sandybridge_pcode_write(dev_priv
, SKL_PCODE_CDCLK_CONTROL
, pcu_ack
);
5749 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5751 intel_update_cdclk(dev
);
5754 static void skl_sanitize_cdclk(struct drm_i915_private
*dev_priv
);
5756 void skl_uninit_cdclk(struct drm_i915_private
*dev_priv
)
5758 skl_set_cdclk(dev_priv
, dev_priv
->cdclk_pll
.ref
, 0);
5761 void skl_init_cdclk(struct drm_i915_private
*dev_priv
)
5765 skl_sanitize_cdclk(dev_priv
);
5767 if (dev_priv
->cdclk_freq
!= 0 && dev_priv
->cdclk_pll
.vco
!= 0) {
5769 * Use the current vco as our initial
5770 * guess as to what the preferred vco is.
5772 if (dev_priv
->skl_preferred_vco_freq
== 0)
5773 skl_set_preferred_cdclk_vco(dev_priv
,
5774 dev_priv
->cdclk_pll
.vco
);
5778 vco
= dev_priv
->skl_preferred_vco_freq
;
5781 cdclk
= skl_calc_cdclk(0, vco
);
5783 skl_set_cdclk(dev_priv
, cdclk
, vco
);
5786 static void skl_sanitize_cdclk(struct drm_i915_private
*dev_priv
)
5788 uint32_t cdctl
, expected
;
5791 * check if the pre-os intialized the display
5792 * There is SWF18 scratchpad register defined which is set by the
5793 * pre-os which can be used by the OS drivers to check the status
5795 if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0)
5798 intel_update_cdclk(&dev_priv
->drm
);
5799 /* Is PLL enabled and locked ? */
5800 if (dev_priv
->cdclk_pll
.vco
== 0 ||
5801 dev_priv
->cdclk_freq
== dev_priv
->cdclk_pll
.ref
)
5804 /* DPLL okay; verify the cdclock
5806 * Noticed in some instances that the freq selection is correct but
5807 * decimal part is programmed wrong from BIOS where pre-os does not
5808 * enable display. Verify the same as well.
5810 cdctl
= I915_READ(CDCLK_CTL
);
5811 expected
= (cdctl
& CDCLK_FREQ_SEL_MASK
) |
5812 skl_cdclk_decimal(dev_priv
->cdclk_freq
);
5813 if (cdctl
== expected
)
5814 /* All well; nothing to sanitize */
5818 DRM_DEBUG_KMS("Sanitizing cdclk programmed by pre-os\n");
5820 /* force cdclk programming */
5821 dev_priv
->cdclk_freq
= 0;
5822 /* force full PLL disable + enable */
5823 dev_priv
->cdclk_pll
.vco
= -1;
5826 /* Adjust CDclk dividers to allow high res or save power if possible */
5827 static void valleyview_set_cdclk(struct drm_device
*dev
, int cdclk
)
5829 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5832 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
)
5833 != dev_priv
->cdclk_freq
);
5835 if (cdclk
>= 320000) /* jump to highest voltage for 400MHz too */
5837 else if (cdclk
== 266667)
5842 mutex_lock(&dev_priv
->rps
.hw_lock
);
5843 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
5844 val
&= ~DSPFREQGUAR_MASK
;
5845 val
|= (cmd
<< DSPFREQGUAR_SHIFT
);
5846 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
5847 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
5848 DSPFREQSTAT_MASK
) == (cmd
<< DSPFREQSTAT_SHIFT
),
5850 DRM_ERROR("timed out waiting for CDclk change\n");
5852 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5854 mutex_lock(&dev_priv
->sb_lock
);
5856 if (cdclk
== 400000) {
5859 divider
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
5861 /* adjust cdclk divider */
5862 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
5863 val
&= ~CCK_FREQUENCY_VALUES
;
5865 vlv_cck_write(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
, val
);
5867 if (wait_for((vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
) &
5868 CCK_FREQUENCY_STATUS
) == (divider
<< CCK_FREQUENCY_STATUS_SHIFT
),
5870 DRM_ERROR("timed out waiting for CDclk change\n");
5873 /* adjust self-refresh exit latency value */
5874 val
= vlv_bunit_read(dev_priv
, BUNIT_REG_BISOC
);
5878 * For high bandwidth configs, we set a higher latency in the bunit
5879 * so that the core display fetch happens in time to avoid underruns.
5881 if (cdclk
== 400000)
5882 val
|= 4500 / 250; /* 4.5 usec */
5884 val
|= 3000 / 250; /* 3.0 usec */
5885 vlv_bunit_write(dev_priv
, BUNIT_REG_BISOC
, val
);
5887 mutex_unlock(&dev_priv
->sb_lock
);
5889 intel_update_cdclk(dev
);
5892 static void cherryview_set_cdclk(struct drm_device
*dev
, int cdclk
)
5894 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5897 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
)
5898 != dev_priv
->cdclk_freq
);
5907 MISSING_CASE(cdclk
);
5912 * Specs are full of misinformation, but testing on actual
5913 * hardware has shown that we just need to write the desired
5914 * CCK divider into the Punit register.
5916 cmd
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
5918 mutex_lock(&dev_priv
->rps
.hw_lock
);
5919 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
5920 val
&= ~DSPFREQGUAR_MASK_CHV
;
5921 val
|= (cmd
<< DSPFREQGUAR_SHIFT_CHV
);
5922 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
5923 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
5924 DSPFREQSTAT_MASK_CHV
) == (cmd
<< DSPFREQSTAT_SHIFT_CHV
),
5926 DRM_ERROR("timed out waiting for CDclk change\n");
5928 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5930 intel_update_cdclk(dev
);
5933 static int valleyview_calc_cdclk(struct drm_i915_private
*dev_priv
,
5936 int freq_320
= (dev_priv
->hpll_freq
<< 1) % 320000 != 0 ? 333333 : 320000;
5937 int limit
= IS_CHERRYVIEW(dev_priv
) ? 95 : 90;
5940 * Really only a few cases to deal with, as only 4 CDclks are supported:
5943 * 320/333MHz (depends on HPLL freq)
5945 * So we check to see whether we're above 90% (VLV) or 95% (CHV)
5946 * of the lower bin and adjust if needed.
5948 * We seem to get an unstable or solid color picture at 200MHz.
5949 * Not sure what's wrong. For now use 200MHz only when all pipes
5952 if (!IS_CHERRYVIEW(dev_priv
) &&
5953 max_pixclk
> freq_320
*limit
/100)
5955 else if (max_pixclk
> 266667*limit
/100)
5957 else if (max_pixclk
> 0)
5963 static int bxt_calc_cdclk(int max_pixclk
)
5965 if (max_pixclk
> 576000)
5967 else if (max_pixclk
> 384000)
5969 else if (max_pixclk
> 288000)
5971 else if (max_pixclk
> 144000)
5977 /* Compute the max pixel clock for new configuration. */
5978 static int intel_mode_max_pixclk(struct drm_device
*dev
,
5979 struct drm_atomic_state
*state
)
5981 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
5982 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5983 struct drm_crtc
*crtc
;
5984 struct drm_crtc_state
*crtc_state
;
5985 unsigned max_pixclk
= 0, i
;
5988 memcpy(intel_state
->min_pixclk
, dev_priv
->min_pixclk
,
5989 sizeof(intel_state
->min_pixclk
));
5991 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
5994 if (crtc_state
->enable
)
5995 pixclk
= crtc_state
->adjusted_mode
.crtc_clock
;
5997 intel_state
->min_pixclk
[i
] = pixclk
;
6000 for_each_pipe(dev_priv
, pipe
)
6001 max_pixclk
= max(intel_state
->min_pixclk
[pipe
], max_pixclk
);
6006 static int valleyview_modeset_calc_cdclk(struct drm_atomic_state
*state
)
6008 struct drm_device
*dev
= state
->dev
;
6009 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6010 int max_pixclk
= intel_mode_max_pixclk(dev
, state
);
6011 struct intel_atomic_state
*intel_state
=
6012 to_intel_atomic_state(state
);
6014 intel_state
->cdclk
= intel_state
->dev_cdclk
=
6015 valleyview_calc_cdclk(dev_priv
, max_pixclk
);
6017 if (!intel_state
->active_crtcs
)
6018 intel_state
->dev_cdclk
= valleyview_calc_cdclk(dev_priv
, 0);
6023 static int bxt_modeset_calc_cdclk(struct drm_atomic_state
*state
)
6025 int max_pixclk
= ilk_max_pixel_rate(state
);
6026 struct intel_atomic_state
*intel_state
=
6027 to_intel_atomic_state(state
);
6029 intel_state
->cdclk
= intel_state
->dev_cdclk
=
6030 bxt_calc_cdclk(max_pixclk
);
6032 if (!intel_state
->active_crtcs
)
6033 intel_state
->dev_cdclk
= bxt_calc_cdclk(0);
6038 static void vlv_program_pfi_credits(struct drm_i915_private
*dev_priv
)
6040 unsigned int credits
, default_credits
;
6042 if (IS_CHERRYVIEW(dev_priv
))
6043 default_credits
= PFI_CREDIT(12);
6045 default_credits
= PFI_CREDIT(8);
6047 if (dev_priv
->cdclk_freq
>= dev_priv
->czclk_freq
) {
6048 /* CHV suggested value is 31 or 63 */
6049 if (IS_CHERRYVIEW(dev_priv
))
6050 credits
= PFI_CREDIT_63
;
6052 credits
= PFI_CREDIT(15);
6054 credits
= default_credits
;
6058 * WA - write default credits before re-programming
6059 * FIXME: should we also set the resend bit here?
6061 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
6064 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
6065 credits
| PFI_CREDIT_RESEND
);
6068 * FIXME is this guaranteed to clear
6069 * immediately or should we poll for it?
6071 WARN_ON(I915_READ(GCI_CONTROL
) & PFI_CREDIT_RESEND
);
6074 static void valleyview_modeset_commit_cdclk(struct drm_atomic_state
*old_state
)
6076 struct drm_device
*dev
= old_state
->dev
;
6077 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6078 struct intel_atomic_state
*old_intel_state
=
6079 to_intel_atomic_state(old_state
);
6080 unsigned req_cdclk
= old_intel_state
->dev_cdclk
;
6083 * FIXME: We can end up here with all power domains off, yet
6084 * with a CDCLK frequency other than the minimum. To account
6085 * for this take the PIPE-A power domain, which covers the HW
6086 * blocks needed for the following programming. This can be
6087 * removed once it's guaranteed that we get here either with
6088 * the minimum CDCLK set, or the required power domains
6091 intel_display_power_get(dev_priv
, POWER_DOMAIN_PIPE_A
);
6093 if (IS_CHERRYVIEW(dev
))
6094 cherryview_set_cdclk(dev
, req_cdclk
);
6096 valleyview_set_cdclk(dev
, req_cdclk
);
6098 vlv_program_pfi_credits(dev_priv
);
6100 intel_display_power_put(dev_priv
, POWER_DOMAIN_PIPE_A
);
6103 static void valleyview_crtc_enable(struct drm_crtc
*crtc
)
6105 struct drm_device
*dev
= crtc
->dev
;
6106 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6107 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6108 struct intel_encoder
*encoder
;
6109 struct intel_crtc_state
*pipe_config
=
6110 to_intel_crtc_state(crtc
->state
);
6111 int pipe
= intel_crtc
->pipe
;
6113 if (WARN_ON(intel_crtc
->active
))
6116 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
6117 intel_dp_set_m_n(intel_crtc
, M1_N1
);
6119 intel_set_pipe_timings(intel_crtc
);
6120 intel_set_pipe_src_size(intel_crtc
);
6122 if (IS_CHERRYVIEW(dev
) && pipe
== PIPE_B
) {
6123 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6125 I915_WRITE(CHV_BLEND(pipe
), CHV_BLEND_LEGACY
);
6126 I915_WRITE(CHV_CANVAS(pipe
), 0);
6129 i9xx_set_pipeconf(intel_crtc
);
6131 intel_crtc
->active
= true;
6133 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
6135 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6136 if (encoder
->pre_pll_enable
)
6137 encoder
->pre_pll_enable(encoder
);
6139 if (IS_CHERRYVIEW(dev
)) {
6140 chv_prepare_pll(intel_crtc
, intel_crtc
->config
);
6141 chv_enable_pll(intel_crtc
, intel_crtc
->config
);
6143 vlv_prepare_pll(intel_crtc
, intel_crtc
->config
);
6144 vlv_enable_pll(intel_crtc
, intel_crtc
->config
);
6147 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6148 if (encoder
->pre_enable
)
6149 encoder
->pre_enable(encoder
);
6151 i9xx_pfit_enable(intel_crtc
);
6153 intel_color_load_luts(&pipe_config
->base
);
6155 intel_update_watermarks(crtc
);
6156 intel_enable_pipe(intel_crtc
);
6158 assert_vblank_disabled(crtc
);
6159 drm_crtc_vblank_on(crtc
);
6161 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6162 encoder
->enable(encoder
);
6165 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
6167 struct drm_device
*dev
= crtc
->base
.dev
;
6168 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6170 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp0
);
6171 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp1
);
6174 static void i9xx_crtc_enable(struct drm_crtc
*crtc
)
6176 struct drm_device
*dev
= crtc
->dev
;
6177 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6178 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6179 struct intel_encoder
*encoder
;
6180 struct intel_crtc_state
*pipe_config
=
6181 to_intel_crtc_state(crtc
->state
);
6182 enum pipe pipe
= intel_crtc
->pipe
;
6184 if (WARN_ON(intel_crtc
->active
))
6187 i9xx_set_pll_dividers(intel_crtc
);
6189 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
6190 intel_dp_set_m_n(intel_crtc
, M1_N1
);
6192 intel_set_pipe_timings(intel_crtc
);
6193 intel_set_pipe_src_size(intel_crtc
);
6195 i9xx_set_pipeconf(intel_crtc
);
6197 intel_crtc
->active
= true;
6200 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
6202 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6203 if (encoder
->pre_enable
)
6204 encoder
->pre_enable(encoder
);
6206 i9xx_enable_pll(intel_crtc
);
6208 i9xx_pfit_enable(intel_crtc
);
6210 intel_color_load_luts(&pipe_config
->base
);
6212 intel_update_watermarks(crtc
);
6213 intel_enable_pipe(intel_crtc
);
6215 assert_vblank_disabled(crtc
);
6216 drm_crtc_vblank_on(crtc
);
6218 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6219 encoder
->enable(encoder
);
6222 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
6224 struct drm_device
*dev
= crtc
->base
.dev
;
6225 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6227 if (!crtc
->config
->gmch_pfit
.control
)
6230 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
6232 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
6233 I915_READ(PFIT_CONTROL
));
6234 I915_WRITE(PFIT_CONTROL
, 0);
6237 static void i9xx_crtc_disable(struct drm_crtc
*crtc
)
6239 struct drm_device
*dev
= crtc
->dev
;
6240 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6241 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6242 struct intel_encoder
*encoder
;
6243 int pipe
= intel_crtc
->pipe
;
6246 * On gen2 planes are double buffered but the pipe isn't, so we must
6247 * wait for planes to fully turn off before disabling the pipe.
6250 intel_wait_for_vblank(dev
, pipe
);
6252 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6253 encoder
->disable(encoder
);
6255 drm_crtc_vblank_off(crtc
);
6256 assert_vblank_disabled(crtc
);
6258 intel_disable_pipe(intel_crtc
);
6260 i9xx_pfit_disable(intel_crtc
);
6262 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6263 if (encoder
->post_disable
)
6264 encoder
->post_disable(encoder
);
6266 if (!intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DSI
)) {
6267 if (IS_CHERRYVIEW(dev
))
6268 chv_disable_pll(dev_priv
, pipe
);
6269 else if (IS_VALLEYVIEW(dev
))
6270 vlv_disable_pll(dev_priv
, pipe
);
6272 i9xx_disable_pll(intel_crtc
);
6275 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6276 if (encoder
->post_pll_disable
)
6277 encoder
->post_pll_disable(encoder
);
6280 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
6283 static void intel_crtc_disable_noatomic(struct drm_crtc
*crtc
)
6285 struct intel_encoder
*encoder
;
6286 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6287 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
6288 enum intel_display_power_domain domain
;
6289 unsigned long domains
;
6291 if (!intel_crtc
->active
)
6294 if (to_intel_plane_state(crtc
->primary
->state
)->visible
) {
6295 WARN_ON(intel_crtc
->flip_work
);
6297 intel_pre_disable_primary_noatomic(crtc
);
6299 intel_crtc_disable_planes(crtc
, 1 << drm_plane_index(crtc
->primary
));
6300 to_intel_plane_state(crtc
->primary
->state
)->visible
= false;
6303 dev_priv
->display
.crtc_disable(crtc
);
6305 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6306 crtc
->base
.id
, crtc
->name
);
6308 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->state
, NULL
) < 0);
6309 crtc
->state
->active
= false;
6310 intel_crtc
->active
= false;
6311 crtc
->enabled
= false;
6312 crtc
->state
->connector_mask
= 0;
6313 crtc
->state
->encoder_mask
= 0;
6315 for_each_encoder_on_crtc(crtc
->dev
, crtc
, encoder
)
6316 encoder
->base
.crtc
= NULL
;
6318 intel_fbc_disable(intel_crtc
);
6319 intel_update_watermarks(crtc
);
6320 intel_disable_shared_dpll(intel_crtc
);
6322 domains
= intel_crtc
->enabled_power_domains
;
6323 for_each_power_domain(domain
, domains
)
6324 intel_display_power_put(dev_priv
, domain
);
6325 intel_crtc
->enabled_power_domains
= 0;
6327 dev_priv
->active_crtcs
&= ~(1 << intel_crtc
->pipe
);
6328 dev_priv
->min_pixclk
[intel_crtc
->pipe
] = 0;
6332 * turn all crtc's off, but do not adjust state
6333 * This has to be paired with a call to intel_modeset_setup_hw_state.
6335 int intel_display_suspend(struct drm_device
*dev
)
6337 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6338 struct drm_atomic_state
*state
;
6341 state
= drm_atomic_helper_suspend(dev
);
6342 ret
= PTR_ERR_OR_ZERO(state
);
6344 DRM_ERROR("Suspending crtc's failed with %i\n", ret
);
6346 dev_priv
->modeset_restore_state
= state
;
6350 void intel_encoder_destroy(struct drm_encoder
*encoder
)
6352 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
6354 drm_encoder_cleanup(encoder
);
6355 kfree(intel_encoder
);
6358 /* Cross check the actual hw state with our own modeset state tracking (and it's
6359 * internal consistency). */
6360 static void intel_connector_verify_state(struct intel_connector
*connector
)
6362 struct drm_crtc
*crtc
= connector
->base
.state
->crtc
;
6364 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6365 connector
->base
.base
.id
,
6366 connector
->base
.name
);
6368 if (connector
->get_hw_state(connector
)) {
6369 struct intel_encoder
*encoder
= connector
->encoder
;
6370 struct drm_connector_state
*conn_state
= connector
->base
.state
;
6372 I915_STATE_WARN(!crtc
,
6373 "connector enabled without attached crtc\n");
6378 I915_STATE_WARN(!crtc
->state
->active
,
6379 "connector is active, but attached crtc isn't\n");
6381 if (!encoder
|| encoder
->type
== INTEL_OUTPUT_DP_MST
)
6384 I915_STATE_WARN(conn_state
->best_encoder
!= &encoder
->base
,
6385 "atomic encoder doesn't match attached encoder\n");
6387 I915_STATE_WARN(conn_state
->crtc
!= encoder
->base
.crtc
,
6388 "attached encoder crtc differs from connector crtc\n");
6390 I915_STATE_WARN(crtc
&& crtc
->state
->active
,
6391 "attached crtc is active, but connector isn't\n");
6392 I915_STATE_WARN(!crtc
&& connector
->base
.state
->best_encoder
,
6393 "best encoder set without crtc!\n");
6397 int intel_connector_init(struct intel_connector
*connector
)
6399 drm_atomic_helper_connector_reset(&connector
->base
);
6401 if (!connector
->base
.state
)
6407 struct intel_connector
*intel_connector_alloc(void)
6409 struct intel_connector
*connector
;
6411 connector
= kzalloc(sizeof *connector
, GFP_KERNEL
);
6415 if (intel_connector_init(connector
) < 0) {
6423 /* Simple connector->get_hw_state implementation for encoders that support only
6424 * one connector and no cloning and hence the encoder state determines the state
6425 * of the connector. */
6426 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
6429 struct intel_encoder
*encoder
= connector
->encoder
;
6431 return encoder
->get_hw_state(encoder
, &pipe
);
6434 static int pipe_required_fdi_lanes(struct intel_crtc_state
*crtc_state
)
6436 if (crtc_state
->base
.enable
&& crtc_state
->has_pch_encoder
)
6437 return crtc_state
->fdi_lanes
;
6442 static int ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
6443 struct intel_crtc_state
*pipe_config
)
6445 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
6446 struct intel_crtc
*other_crtc
;
6447 struct intel_crtc_state
*other_crtc_state
;
6449 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6450 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6451 if (pipe_config
->fdi_lanes
> 4) {
6452 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6453 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6457 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
6458 if (pipe_config
->fdi_lanes
> 2) {
6459 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6460 pipe_config
->fdi_lanes
);
6467 if (INTEL_INFO(dev
)->num_pipes
== 2)
6470 /* Ivybridge 3 pipe is really complicated */
6475 if (pipe_config
->fdi_lanes
<= 2)
6478 other_crtc
= to_intel_crtc(intel_get_crtc_for_pipe(dev
, PIPE_C
));
6480 intel_atomic_get_crtc_state(state
, other_crtc
);
6481 if (IS_ERR(other_crtc_state
))
6482 return PTR_ERR(other_crtc_state
);
6484 if (pipe_required_fdi_lanes(other_crtc_state
) > 0) {
6485 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6486 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6491 if (pipe_config
->fdi_lanes
> 2) {
6492 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6493 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6497 other_crtc
= to_intel_crtc(intel_get_crtc_for_pipe(dev
, PIPE_B
));
6499 intel_atomic_get_crtc_state(state
, other_crtc
);
6500 if (IS_ERR(other_crtc_state
))
6501 return PTR_ERR(other_crtc_state
);
6503 if (pipe_required_fdi_lanes(other_crtc_state
) > 2) {
6504 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6514 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
6515 struct intel_crtc_state
*pipe_config
)
6517 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6518 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6519 int lane
, link_bw
, fdi_dotclock
, ret
;
6520 bool needs_recompute
= false;
6523 /* FDI is a binary signal running at ~2.7GHz, encoding
6524 * each output octet as 10 bits. The actual frequency
6525 * is stored as a divider into a 100MHz clock, and the
6526 * mode pixel clock is stored in units of 1KHz.
6527 * Hence the bw of each lane in terms of the mode signal
6530 link_bw
= intel_fdi_link_freq(to_i915(dev
), pipe_config
);
6532 fdi_dotclock
= adjusted_mode
->crtc_clock
;
6534 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
6535 pipe_config
->pipe_bpp
);
6537 pipe_config
->fdi_lanes
= lane
;
6539 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
6540 link_bw
, &pipe_config
->fdi_m_n
);
6542 ret
= ironlake_check_fdi_lanes(dev
, intel_crtc
->pipe
, pipe_config
);
6543 if (ret
== -EINVAL
&& pipe_config
->pipe_bpp
> 6*3) {
6544 pipe_config
->pipe_bpp
-= 2*3;
6545 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6546 pipe_config
->pipe_bpp
);
6547 needs_recompute
= true;
6548 pipe_config
->bw_constrained
= true;
6553 if (needs_recompute
)
6559 static bool pipe_config_supports_ips(struct drm_i915_private
*dev_priv
,
6560 struct intel_crtc_state
*pipe_config
)
6562 if (pipe_config
->pipe_bpp
> 24)
6565 /* HSW can handle pixel rate up to cdclk? */
6566 if (IS_HASWELL(dev_priv
))
6570 * We compare against max which means we must take
6571 * the increased cdclk requirement into account when
6572 * calculating the new cdclk.
6574 * Should measure whether using a lower cdclk w/o IPS
6576 return ilk_pipe_pixel_rate(pipe_config
) <=
6577 dev_priv
->max_cdclk_freq
* 95 / 100;
6580 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
6581 struct intel_crtc_state
*pipe_config
)
6583 struct drm_device
*dev
= crtc
->base
.dev
;
6584 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6586 pipe_config
->ips_enabled
= i915
.enable_ips
&&
6587 hsw_crtc_supports_ips(crtc
) &&
6588 pipe_config_supports_ips(dev_priv
, pipe_config
);
6591 static bool intel_crtc_supports_double_wide(const struct intel_crtc
*crtc
)
6593 const struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6595 /* GDG double wide on either pipe, otherwise pipe A only */
6596 return INTEL_INFO(dev_priv
)->gen
< 4 &&
6597 (crtc
->pipe
== PIPE_A
|| IS_I915G(dev_priv
));
6600 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
6601 struct intel_crtc_state
*pipe_config
)
6603 struct drm_device
*dev
= crtc
->base
.dev
;
6604 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6605 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6606 int clock_limit
= dev_priv
->max_dotclk_freq
;
6608 if (INTEL_INFO(dev
)->gen
< 4) {
6609 clock_limit
= dev_priv
->max_cdclk_freq
* 9 / 10;
6612 * Enable double wide mode when the dot clock
6613 * is > 90% of the (display) core speed.
6615 if (intel_crtc_supports_double_wide(crtc
) &&
6616 adjusted_mode
->crtc_clock
> clock_limit
) {
6617 clock_limit
= dev_priv
->max_dotclk_freq
;
6618 pipe_config
->double_wide
= true;
6622 if (adjusted_mode
->crtc_clock
> clock_limit
) {
6623 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6624 adjusted_mode
->crtc_clock
, clock_limit
,
6625 yesno(pipe_config
->double_wide
));
6630 * Pipe horizontal size must be even in:
6632 * - LVDS dual channel mode
6633 * - Double wide pipe
6635 if ((intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_LVDS
) &&
6636 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
6637 pipe_config
->pipe_src_w
&= ~1;
6639 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6640 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6642 if ((INTEL_INFO(dev
)->gen
> 4 || IS_G4X(dev
)) &&
6643 adjusted_mode
->crtc_hsync_start
== adjusted_mode
->crtc_hdisplay
)
6647 hsw_compute_ips_config(crtc
, pipe_config
);
6649 if (pipe_config
->has_pch_encoder
)
6650 return ironlake_fdi_compute_config(crtc
, pipe_config
);
6655 static int skylake_get_display_clock_speed(struct drm_device
*dev
)
6657 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6660 skl_dpll0_update(dev_priv
);
6662 if (dev_priv
->cdclk_pll
.vco
== 0)
6663 return dev_priv
->cdclk_pll
.ref
;
6665 cdctl
= I915_READ(CDCLK_CTL
);
6667 if (dev_priv
->cdclk_pll
.vco
== 8640000) {
6668 switch (cdctl
& CDCLK_FREQ_SEL_MASK
) {
6669 case CDCLK_FREQ_450_432
:
6671 case CDCLK_FREQ_337_308
:
6673 case CDCLK_FREQ_540
:
6675 case CDCLK_FREQ_675_617
:
6678 MISSING_CASE(cdctl
& CDCLK_FREQ_SEL_MASK
);
6681 switch (cdctl
& CDCLK_FREQ_SEL_MASK
) {
6682 case CDCLK_FREQ_450_432
:
6684 case CDCLK_FREQ_337_308
:
6686 case CDCLK_FREQ_540
:
6688 case CDCLK_FREQ_675_617
:
6691 MISSING_CASE(cdctl
& CDCLK_FREQ_SEL_MASK
);
6695 return dev_priv
->cdclk_pll
.ref
;
6698 static void bxt_de_pll_update(struct drm_i915_private
*dev_priv
)
6702 dev_priv
->cdclk_pll
.ref
= 19200;
6703 dev_priv
->cdclk_pll
.vco
= 0;
6705 val
= I915_READ(BXT_DE_PLL_ENABLE
);
6706 if ((val
& BXT_DE_PLL_PLL_ENABLE
) == 0)
6709 if (WARN_ON((val
& BXT_DE_PLL_LOCK
) == 0))
6712 val
= I915_READ(BXT_DE_PLL_CTL
);
6713 dev_priv
->cdclk_pll
.vco
= (val
& BXT_DE_PLL_RATIO_MASK
) *
6714 dev_priv
->cdclk_pll
.ref
;
6717 static int broxton_get_display_clock_speed(struct drm_device
*dev
)
6719 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6723 bxt_de_pll_update(dev_priv
);
6725 vco
= dev_priv
->cdclk_pll
.vco
;
6727 return dev_priv
->cdclk_pll
.ref
;
6729 divider
= I915_READ(CDCLK_CTL
) & BXT_CDCLK_CD2X_DIV_SEL_MASK
;
6732 case BXT_CDCLK_CD2X_DIV_SEL_1
:
6735 case BXT_CDCLK_CD2X_DIV_SEL_1_5
:
6738 case BXT_CDCLK_CD2X_DIV_SEL_2
:
6741 case BXT_CDCLK_CD2X_DIV_SEL_4
:
6745 MISSING_CASE(divider
);
6746 return dev_priv
->cdclk_pll
.ref
;
6749 return DIV_ROUND_CLOSEST(vco
, div
);
6752 static int broadwell_get_display_clock_speed(struct drm_device
*dev
)
6754 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6755 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
6756 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
6758 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
6760 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
6762 else if (freq
== LCPLL_CLK_FREQ_450
)
6764 else if (freq
== LCPLL_CLK_FREQ_54O_BDW
)
6766 else if (freq
== LCPLL_CLK_FREQ_337_5_BDW
)
6772 static int haswell_get_display_clock_speed(struct drm_device
*dev
)
6774 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6775 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
6776 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
6778 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
6780 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
6782 else if (freq
== LCPLL_CLK_FREQ_450
)
6784 else if (IS_HSW_ULT(dev
))
6790 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
6792 return vlv_get_cck_clock_hpll(to_i915(dev
), "cdclk",
6793 CCK_DISPLAY_CLOCK_CONTROL
);
6796 static int ilk_get_display_clock_speed(struct drm_device
*dev
)
6801 static int i945_get_display_clock_speed(struct drm_device
*dev
)
6806 static int i915_get_display_clock_speed(struct drm_device
*dev
)
6811 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
6816 static int pnv_get_display_clock_speed(struct drm_device
*dev
)
6820 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
6822 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
6823 case GC_DISPLAY_CLOCK_267_MHZ_PNV
:
6825 case GC_DISPLAY_CLOCK_333_MHZ_PNV
:
6827 case GC_DISPLAY_CLOCK_444_MHZ_PNV
:
6829 case GC_DISPLAY_CLOCK_200_MHZ_PNV
:
6832 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc
);
6833 case GC_DISPLAY_CLOCK_133_MHZ_PNV
:
6835 case GC_DISPLAY_CLOCK_167_MHZ_PNV
:
6840 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
6844 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
6846 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
6849 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
6850 case GC_DISPLAY_CLOCK_333_MHZ
:
6853 case GC_DISPLAY_CLOCK_190_200_MHZ
:
6859 static int i865_get_display_clock_speed(struct drm_device
*dev
)
6864 static int i85x_get_display_clock_speed(struct drm_device
*dev
)
6869 * 852GM/852GMV only supports 133 MHz and the HPLLCC
6870 * encoding is different :(
6871 * FIXME is this the right way to detect 852GM/852GMV?
6873 if (dev
->pdev
->revision
== 0x1)
6876 pci_bus_read_config_word(dev
->pdev
->bus
,
6877 PCI_DEVFN(0, 3), HPLLCC
, &hpllcc
);
6879 /* Assume that the hardware is in the high speed state. This
6880 * should be the default.
6882 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
6883 case GC_CLOCK_133_200
:
6884 case GC_CLOCK_133_200_2
:
6885 case GC_CLOCK_100_200
:
6887 case GC_CLOCK_166_250
:
6889 case GC_CLOCK_100_133
:
6891 case GC_CLOCK_133_266
:
6892 case GC_CLOCK_133_266_2
:
6893 case GC_CLOCK_166_266
:
6897 /* Shouldn't happen */
6901 static int i830_get_display_clock_speed(struct drm_device
*dev
)
6906 static unsigned int intel_hpll_vco(struct drm_device
*dev
)
6908 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6909 static const unsigned int blb_vco
[8] = {
6916 static const unsigned int pnv_vco
[8] = {
6923 static const unsigned int cl_vco
[8] = {
6932 static const unsigned int elk_vco
[8] = {
6938 static const unsigned int ctg_vco
[8] = {
6946 const unsigned int *vco_table
;
6950 /* FIXME other chipsets? */
6952 vco_table
= ctg_vco
;
6953 else if (IS_G4X(dev
))
6954 vco_table
= elk_vco
;
6955 else if (IS_CRESTLINE(dev
))
6957 else if (IS_PINEVIEW(dev
))
6958 vco_table
= pnv_vco
;
6959 else if (IS_G33(dev
))
6960 vco_table
= blb_vco
;
6964 tmp
= I915_READ(IS_MOBILE(dev
) ? HPLLVCO_MOBILE
: HPLLVCO
);
6966 vco
= vco_table
[tmp
& 0x7];
6968 DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp
);
6970 DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco
);
6975 static int gm45_get_display_clock_speed(struct drm_device
*dev
)
6977 unsigned int cdclk_sel
, vco
= intel_hpll_vco(dev
);
6980 pci_read_config_word(dev
->pdev
, GCFGC
, &tmp
);
6982 cdclk_sel
= (tmp
>> 12) & 0x1;
6988 return cdclk_sel
? 333333 : 222222;
6990 return cdclk_sel
? 320000 : 228571;
6992 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco
, tmp
);
6997 static int i965gm_get_display_clock_speed(struct drm_device
*dev
)
6999 static const uint8_t div_3200
[] = { 16, 10, 8 };
7000 static const uint8_t div_4000
[] = { 20, 12, 10 };
7001 static const uint8_t div_5333
[] = { 24, 16, 14 };
7002 const uint8_t *div_table
;
7003 unsigned int cdclk_sel
, vco
= intel_hpll_vco(dev
);
7006 pci_read_config_word(dev
->pdev
, GCFGC
, &tmp
);
7008 cdclk_sel
= ((tmp
>> 8) & 0x1f) - 1;
7010 if (cdclk_sel
>= ARRAY_SIZE(div_3200
))
7015 div_table
= div_3200
;
7018 div_table
= div_4000
;
7021 div_table
= div_5333
;
7027 return DIV_ROUND_CLOSEST(vco
, div_table
[cdclk_sel
]);
7030 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco
, tmp
);
7034 static int g33_get_display_clock_speed(struct drm_device
*dev
)
7036 static const uint8_t div_3200
[] = { 12, 10, 8, 7, 5, 16 };
7037 static const uint8_t div_4000
[] = { 14, 12, 10, 8, 6, 20 };
7038 static const uint8_t div_4800
[] = { 20, 14, 12, 10, 8, 24 };
7039 static const uint8_t div_5333
[] = { 20, 16, 12, 12, 8, 28 };
7040 const uint8_t *div_table
;
7041 unsigned int cdclk_sel
, vco
= intel_hpll_vco(dev
);
7044 pci_read_config_word(dev
->pdev
, GCFGC
, &tmp
);
7046 cdclk_sel
= (tmp
>> 4) & 0x7;
7048 if (cdclk_sel
>= ARRAY_SIZE(div_3200
))
7053 div_table
= div_3200
;
7056 div_table
= div_4000
;
7059 div_table
= div_4800
;
7062 div_table
= div_5333
;
7068 return DIV_ROUND_CLOSEST(vco
, div_table
[cdclk_sel
]);
7071 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco
, tmp
);
7076 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
7078 while (*num
> DATA_LINK_M_N_MASK
||
7079 *den
> DATA_LINK_M_N_MASK
) {
7085 static void compute_m_n(unsigned int m
, unsigned int n
,
7086 uint32_t *ret_m
, uint32_t *ret_n
)
7088 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
7089 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
7090 intel_reduce_m_n_ratio(ret_m
, ret_n
);
7094 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
7095 int pixel_clock
, int link_clock
,
7096 struct intel_link_m_n
*m_n
)
7100 compute_m_n(bits_per_pixel
* pixel_clock
,
7101 link_clock
* nlanes
* 8,
7102 &m_n
->gmch_m
, &m_n
->gmch_n
);
7104 compute_m_n(pixel_clock
, link_clock
,
7105 &m_n
->link_m
, &m_n
->link_n
);
7108 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
7110 if (i915
.panel_use_ssc
>= 0)
7111 return i915
.panel_use_ssc
!= 0;
7112 return dev_priv
->vbt
.lvds_use_ssc
7113 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
7116 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
7118 return (1 << dpll
->n
) << 16 | dpll
->m2
;
7121 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
7123 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
7126 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
7127 struct intel_crtc_state
*crtc_state
,
7128 struct dpll
*reduced_clock
)
7130 struct drm_device
*dev
= crtc
->base
.dev
;
7133 if (IS_PINEVIEW(dev
)) {
7134 fp
= pnv_dpll_compute_fp(&crtc_state
->dpll
);
7136 fp2
= pnv_dpll_compute_fp(reduced_clock
);
7138 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
7140 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
7143 crtc_state
->dpll_hw_state
.fp0
= fp
;
7145 crtc
->lowfreq_avail
= false;
7146 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
7148 crtc_state
->dpll_hw_state
.fp1
= fp2
;
7149 crtc
->lowfreq_avail
= true;
7151 crtc_state
->dpll_hw_state
.fp1
= fp
;
7155 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
7161 * PLLB opamp always calibrates to max value of 0x3f, force enable it
7162 * and set it to a reasonable value instead.
7164 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
7165 reg_val
&= 0xffffff00;
7166 reg_val
|= 0x00000030;
7167 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
7169 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
7170 reg_val
&= 0x8cffffff;
7171 reg_val
= 0x8c000000;
7172 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
7174 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
7175 reg_val
&= 0xffffff00;
7176 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
7178 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
7179 reg_val
&= 0x00ffffff;
7180 reg_val
|= 0xb0000000;
7181 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
7184 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
7185 struct intel_link_m_n
*m_n
)
7187 struct drm_device
*dev
= crtc
->base
.dev
;
7188 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7189 int pipe
= crtc
->pipe
;
7191 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
7192 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
7193 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
7194 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
7197 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
7198 struct intel_link_m_n
*m_n
,
7199 struct intel_link_m_n
*m2_n2
)
7201 struct drm_device
*dev
= crtc
->base
.dev
;
7202 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7203 int pipe
= crtc
->pipe
;
7204 enum transcoder transcoder
= crtc
->config
->cpu_transcoder
;
7206 if (INTEL_INFO(dev
)->gen
>= 5) {
7207 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
7208 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
7209 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
7210 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
7211 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
7212 * for gen < 8) and if DRRS is supported (to make sure the
7213 * registers are not unnecessarily accessed).
7215 if (m2_n2
&& (IS_CHERRYVIEW(dev
) || INTEL_INFO(dev
)->gen
< 8) &&
7216 crtc
->config
->has_drrs
) {
7217 I915_WRITE(PIPE_DATA_M2(transcoder
),
7218 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
7219 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
7220 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
7221 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
7224 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
7225 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
7226 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
7227 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
7231 void intel_dp_set_m_n(struct intel_crtc
*crtc
, enum link_m_n_set m_n
)
7233 struct intel_link_m_n
*dp_m_n
, *dp_m2_n2
= NULL
;
7236 dp_m_n
= &crtc
->config
->dp_m_n
;
7237 dp_m2_n2
= &crtc
->config
->dp_m2_n2
;
7238 } else if (m_n
== M2_N2
) {
7241 * M2_N2 registers are not supported. Hence m2_n2 divider value
7242 * needs to be programmed into M1_N1.
7244 dp_m_n
= &crtc
->config
->dp_m2_n2
;
7246 DRM_ERROR("Unsupported divider value\n");
7250 if (crtc
->config
->has_pch_encoder
)
7251 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
->dp_m_n
);
7253 intel_cpu_transcoder_set_m_n(crtc
, dp_m_n
, dp_m2_n2
);
7256 static void vlv_compute_dpll(struct intel_crtc
*crtc
,
7257 struct intel_crtc_state
*pipe_config
)
7259 pipe_config
->dpll_hw_state
.dpll
= DPLL_INTEGRATED_REF_CLK_VLV
|
7260 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
7261 if (crtc
->pipe
!= PIPE_A
)
7262 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
7264 /* DPLL not used with DSI, but still need the rest set up */
7265 if (!intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_DSI
))
7266 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
|
7267 DPLL_EXT_BUFFER_ENABLE_VLV
;
7269 pipe_config
->dpll_hw_state
.dpll_md
=
7270 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
7273 static void chv_compute_dpll(struct intel_crtc
*crtc
,
7274 struct intel_crtc_state
*pipe_config
)
7276 pipe_config
->dpll_hw_state
.dpll
= DPLL_SSC_REF_CLK_CHV
|
7277 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
7278 if (crtc
->pipe
!= PIPE_A
)
7279 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
7281 /* DPLL not used with DSI, but still need the rest set up */
7282 if (!intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_DSI
))
7283 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
;
7285 pipe_config
->dpll_hw_state
.dpll_md
=
7286 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
7289 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
7290 const struct intel_crtc_state
*pipe_config
)
7292 struct drm_device
*dev
= crtc
->base
.dev
;
7293 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7294 enum pipe pipe
= crtc
->pipe
;
7296 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
7297 u32 coreclk
, reg_val
;
7300 I915_WRITE(DPLL(pipe
),
7301 pipe_config
->dpll_hw_state
.dpll
&
7302 ~(DPLL_VCO_ENABLE
| DPLL_EXT_BUFFER_ENABLE_VLV
));
7304 /* No need to actually set up the DPLL with DSI */
7305 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7308 mutex_lock(&dev_priv
->sb_lock
);
7310 bestn
= pipe_config
->dpll
.n
;
7311 bestm1
= pipe_config
->dpll
.m1
;
7312 bestm2
= pipe_config
->dpll
.m2
;
7313 bestp1
= pipe_config
->dpll
.p1
;
7314 bestp2
= pipe_config
->dpll
.p2
;
7316 /* See eDP HDMI DPIO driver vbios notes doc */
7318 /* PLL B needs special handling */
7320 vlv_pllb_recal_opamp(dev_priv
, pipe
);
7322 /* Set up Tx target for periodic Rcomp update */
7323 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
7325 /* Disable target IRef on PLL */
7326 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
7327 reg_val
&= 0x00ffffff;
7328 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
7330 /* Disable fast lock */
7331 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
7333 /* Set idtafcrecal before PLL is enabled */
7334 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
7335 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
7336 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
7337 mdiv
|= (1 << DPIO_K_SHIFT
);
7340 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7341 * but we don't support that).
7342 * Note: don't use the DAC post divider as it seems unstable.
7344 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
7345 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
7347 mdiv
|= DPIO_ENABLE_CALIBRATION
;
7348 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
7350 /* Set HBR and RBR LPF coefficients */
7351 if (pipe_config
->port_clock
== 162000 ||
7352 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_ANALOG
) ||
7353 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_HDMI
))
7354 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
7357 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
7360 if (intel_crtc_has_dp_encoder(pipe_config
)) {
7361 /* Use SSC source */
7363 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7366 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7368 } else { /* HDMI or VGA */
7369 /* Use bend source */
7371 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7374 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7378 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
7379 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
7380 if (intel_crtc_has_dp_encoder(crtc
->config
))
7381 coreclk
|= 0x01000000;
7382 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
7384 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
7385 mutex_unlock(&dev_priv
->sb_lock
);
7388 static void chv_prepare_pll(struct intel_crtc
*crtc
,
7389 const struct intel_crtc_state
*pipe_config
)
7391 struct drm_device
*dev
= crtc
->base
.dev
;
7392 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7393 enum pipe pipe
= crtc
->pipe
;
7394 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
7395 u32 loopfilter
, tribuf_calcntr
;
7396 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
7400 /* Enable Refclk and SSC */
7401 I915_WRITE(DPLL(pipe
),
7402 pipe_config
->dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
7404 /* No need to actually set up the DPLL with DSI */
7405 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7408 bestn
= pipe_config
->dpll
.n
;
7409 bestm2_frac
= pipe_config
->dpll
.m2
& 0x3fffff;
7410 bestm1
= pipe_config
->dpll
.m1
;
7411 bestm2
= pipe_config
->dpll
.m2
>> 22;
7412 bestp1
= pipe_config
->dpll
.p1
;
7413 bestp2
= pipe_config
->dpll
.p2
;
7414 vco
= pipe_config
->dpll
.vco
;
7418 mutex_lock(&dev_priv
->sb_lock
);
7420 /* p1 and p2 divider */
7421 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
7422 5 << DPIO_CHV_S1_DIV_SHIFT
|
7423 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
7424 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
7425 1 << DPIO_CHV_K_DIV_SHIFT
);
7427 /* Feedback post-divider - m2 */
7428 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
7430 /* Feedback refclk divider - n and m1 */
7431 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
7432 DPIO_CHV_M1_DIV_BY_2
|
7433 1 << DPIO_CHV_N_DIV_SHIFT
);
7435 /* M2 fraction division */
7436 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
7438 /* M2 fraction division enable */
7439 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
7440 dpio_val
&= ~(DPIO_CHV_FEEDFWD_GAIN_MASK
| DPIO_CHV_FRAC_DIV_EN
);
7441 dpio_val
|= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
);
7443 dpio_val
|= DPIO_CHV_FRAC_DIV_EN
;
7444 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
), dpio_val
);
7446 /* Program digital lock detect threshold */
7447 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW9(port
));
7448 dpio_val
&= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK
|
7449 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
);
7450 dpio_val
|= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT
);
7452 dpio_val
|= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
;
7453 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW9(port
), dpio_val
);
7456 if (vco
== 5400000) {
7457 loopfilter
|= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT
);
7458 loopfilter
|= (0x8 << DPIO_CHV_INT_COEFF_SHIFT
);
7459 loopfilter
|= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7460 tribuf_calcntr
= 0x9;
7461 } else if (vco
<= 6200000) {
7462 loopfilter
|= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT
);
7463 loopfilter
|= (0xB << DPIO_CHV_INT_COEFF_SHIFT
);
7464 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7465 tribuf_calcntr
= 0x9;
7466 } else if (vco
<= 6480000) {
7467 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
7468 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
7469 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7470 tribuf_calcntr
= 0x8;
7472 /* Not supported. Apply the same limits as in the max case */
7473 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
7474 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
7475 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7478 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
7480 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW8(port
));
7481 dpio_val
&= ~DPIO_CHV_TDC_TARGET_CNT_MASK
;
7482 dpio_val
|= (tribuf_calcntr
<< DPIO_CHV_TDC_TARGET_CNT_SHIFT
);
7483 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW8(port
), dpio_val
);
7486 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
7487 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
7490 mutex_unlock(&dev_priv
->sb_lock
);
7494 * vlv_force_pll_on - forcibly enable just the PLL
7495 * @dev_priv: i915 private structure
7496 * @pipe: pipe PLL to enable
7497 * @dpll: PLL configuration
7499 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7500 * in cases where we need the PLL enabled even when @pipe is not going to
7503 int vlv_force_pll_on(struct drm_device
*dev
, enum pipe pipe
,
7504 const struct dpll
*dpll
)
7506 struct intel_crtc
*crtc
=
7507 to_intel_crtc(intel_get_crtc_for_pipe(dev
, pipe
));
7508 struct intel_crtc_state
*pipe_config
;
7510 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
7514 pipe_config
->base
.crtc
= &crtc
->base
;
7515 pipe_config
->pixel_multiplier
= 1;
7516 pipe_config
->dpll
= *dpll
;
7518 if (IS_CHERRYVIEW(dev
)) {
7519 chv_compute_dpll(crtc
, pipe_config
);
7520 chv_prepare_pll(crtc
, pipe_config
);
7521 chv_enable_pll(crtc
, pipe_config
);
7523 vlv_compute_dpll(crtc
, pipe_config
);
7524 vlv_prepare_pll(crtc
, pipe_config
);
7525 vlv_enable_pll(crtc
, pipe_config
);
7534 * vlv_force_pll_off - forcibly disable just the PLL
7535 * @dev_priv: i915 private structure
7536 * @pipe: pipe PLL to disable
7538 * Disable the PLL for @pipe. To be used in cases where we need
7539 * the PLL enabled even when @pipe is not going to be enabled.
7541 void vlv_force_pll_off(struct drm_device
*dev
, enum pipe pipe
)
7543 if (IS_CHERRYVIEW(dev
))
7544 chv_disable_pll(to_i915(dev
), pipe
);
7546 vlv_disable_pll(to_i915(dev
), pipe
);
7549 static void i9xx_compute_dpll(struct intel_crtc
*crtc
,
7550 struct intel_crtc_state
*crtc_state
,
7551 struct dpll
*reduced_clock
)
7553 struct drm_device
*dev
= crtc
->base
.dev
;
7554 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7556 struct dpll
*clock
= &crtc_state
->dpll
;
7558 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
7560 dpll
= DPLL_VGA_MODE_DIS
;
7562 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
))
7563 dpll
|= DPLLB_MODE_LVDS
;
7565 dpll
|= DPLLB_MODE_DAC_SERIAL
;
7567 if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
7568 dpll
|= (crtc_state
->pixel_multiplier
- 1)
7569 << SDVO_MULTIPLIER_SHIFT_HIRES
;
7572 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
7573 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
7574 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7576 if (intel_crtc_has_dp_encoder(crtc_state
))
7577 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7579 /* compute bitmask from p1 value */
7580 if (IS_PINEVIEW(dev
))
7581 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
7583 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7584 if (IS_G4X(dev
) && reduced_clock
)
7585 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
7587 switch (clock
->p2
) {
7589 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
7592 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
7595 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
7598 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
7601 if (INTEL_INFO(dev
)->gen
>= 4)
7602 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
7604 if (crtc_state
->sdvo_tv_clock
)
7605 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
7606 else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
7607 intel_panel_use_ssc(dev_priv
))
7608 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7610 dpll
|= PLL_REF_INPUT_DREFCLK
;
7612 dpll
|= DPLL_VCO_ENABLE
;
7613 crtc_state
->dpll_hw_state
.dpll
= dpll
;
7615 if (INTEL_INFO(dev
)->gen
>= 4) {
7616 u32 dpll_md
= (crtc_state
->pixel_multiplier
- 1)
7617 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
7618 crtc_state
->dpll_hw_state
.dpll_md
= dpll_md
;
7622 static void i8xx_compute_dpll(struct intel_crtc
*crtc
,
7623 struct intel_crtc_state
*crtc_state
,
7624 struct dpll
*reduced_clock
)
7626 struct drm_device
*dev
= crtc
->base
.dev
;
7627 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7629 struct dpll
*clock
= &crtc_state
->dpll
;
7631 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
7633 dpll
= DPLL_VGA_MODE_DIS
;
7635 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7636 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7639 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
7641 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7643 dpll
|= PLL_P2_DIVIDE_BY_4
;
7646 if (!IS_I830(dev
) && intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DVO
))
7647 dpll
|= DPLL_DVO_2X_MODE
;
7649 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
7650 intel_panel_use_ssc(dev_priv
))
7651 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7653 dpll
|= PLL_REF_INPUT_DREFCLK
;
7655 dpll
|= DPLL_VCO_ENABLE
;
7656 crtc_state
->dpll_hw_state
.dpll
= dpll
;
7659 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
7661 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7662 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7663 enum pipe pipe
= intel_crtc
->pipe
;
7664 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
7665 const struct drm_display_mode
*adjusted_mode
= &intel_crtc
->config
->base
.adjusted_mode
;
7666 uint32_t crtc_vtotal
, crtc_vblank_end
;
7669 /* We need to be careful not to changed the adjusted mode, for otherwise
7670 * the hw state checker will get angry at the mismatch. */
7671 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
7672 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
7674 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
7675 /* the chip adds 2 halflines automatically */
7677 crtc_vblank_end
-= 1;
7679 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
7680 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
7682 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
7683 adjusted_mode
->crtc_htotal
/ 2;
7685 vsyncshift
+= adjusted_mode
->crtc_htotal
;
7688 if (INTEL_INFO(dev
)->gen
> 3)
7689 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
7691 I915_WRITE(HTOTAL(cpu_transcoder
),
7692 (adjusted_mode
->crtc_hdisplay
- 1) |
7693 ((adjusted_mode
->crtc_htotal
- 1) << 16));
7694 I915_WRITE(HBLANK(cpu_transcoder
),
7695 (adjusted_mode
->crtc_hblank_start
- 1) |
7696 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
7697 I915_WRITE(HSYNC(cpu_transcoder
),
7698 (adjusted_mode
->crtc_hsync_start
- 1) |
7699 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
7701 I915_WRITE(VTOTAL(cpu_transcoder
),
7702 (adjusted_mode
->crtc_vdisplay
- 1) |
7703 ((crtc_vtotal
- 1) << 16));
7704 I915_WRITE(VBLANK(cpu_transcoder
),
7705 (adjusted_mode
->crtc_vblank_start
- 1) |
7706 ((crtc_vblank_end
- 1) << 16));
7707 I915_WRITE(VSYNC(cpu_transcoder
),
7708 (adjusted_mode
->crtc_vsync_start
- 1) |
7709 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
7711 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7712 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7713 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7715 if (IS_HASWELL(dev
) && cpu_transcoder
== TRANSCODER_EDP
&&
7716 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
7717 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
7721 static void intel_set_pipe_src_size(struct intel_crtc
*intel_crtc
)
7723 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7724 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7725 enum pipe pipe
= intel_crtc
->pipe
;
7727 /* pipesrc controls the size that is scaled from, which should
7728 * always be the user's requested size.
7730 I915_WRITE(PIPESRC(pipe
),
7731 ((intel_crtc
->config
->pipe_src_w
- 1) << 16) |
7732 (intel_crtc
->config
->pipe_src_h
- 1));
7735 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
7736 struct intel_crtc_state
*pipe_config
)
7738 struct drm_device
*dev
= crtc
->base
.dev
;
7739 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7740 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
7743 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
7744 pipe_config
->base
.adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
7745 pipe_config
->base
.adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
7746 tmp
= I915_READ(HBLANK(cpu_transcoder
));
7747 pipe_config
->base
.adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
7748 pipe_config
->base
.adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
7749 tmp
= I915_READ(HSYNC(cpu_transcoder
));
7750 pipe_config
->base
.adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
7751 pipe_config
->base
.adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
7753 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
7754 pipe_config
->base
.adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
7755 pipe_config
->base
.adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
7756 tmp
= I915_READ(VBLANK(cpu_transcoder
));
7757 pipe_config
->base
.adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
7758 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
7759 tmp
= I915_READ(VSYNC(cpu_transcoder
));
7760 pipe_config
->base
.adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
7761 pipe_config
->base
.adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
7763 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
7764 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
7765 pipe_config
->base
.adjusted_mode
.crtc_vtotal
+= 1;
7766 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
+= 1;
7770 static void intel_get_pipe_src_size(struct intel_crtc
*crtc
,
7771 struct intel_crtc_state
*pipe_config
)
7773 struct drm_device
*dev
= crtc
->base
.dev
;
7774 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7777 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
7778 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
7779 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
7781 pipe_config
->base
.mode
.vdisplay
= pipe_config
->pipe_src_h
;
7782 pipe_config
->base
.mode
.hdisplay
= pipe_config
->pipe_src_w
;
7785 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
7786 struct intel_crtc_state
*pipe_config
)
7788 mode
->hdisplay
= pipe_config
->base
.adjusted_mode
.crtc_hdisplay
;
7789 mode
->htotal
= pipe_config
->base
.adjusted_mode
.crtc_htotal
;
7790 mode
->hsync_start
= pipe_config
->base
.adjusted_mode
.crtc_hsync_start
;
7791 mode
->hsync_end
= pipe_config
->base
.adjusted_mode
.crtc_hsync_end
;
7793 mode
->vdisplay
= pipe_config
->base
.adjusted_mode
.crtc_vdisplay
;
7794 mode
->vtotal
= pipe_config
->base
.adjusted_mode
.crtc_vtotal
;
7795 mode
->vsync_start
= pipe_config
->base
.adjusted_mode
.crtc_vsync_start
;
7796 mode
->vsync_end
= pipe_config
->base
.adjusted_mode
.crtc_vsync_end
;
7798 mode
->flags
= pipe_config
->base
.adjusted_mode
.flags
;
7799 mode
->type
= DRM_MODE_TYPE_DRIVER
;
7801 mode
->clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
7802 mode
->flags
|= pipe_config
->base
.adjusted_mode
.flags
;
7804 mode
->hsync
= drm_mode_hsync(mode
);
7805 mode
->vrefresh
= drm_mode_vrefresh(mode
);
7806 drm_mode_set_name(mode
);
7809 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
7811 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7812 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7817 if ((intel_crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
7818 (intel_crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
7819 pipeconf
|= I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
;
7821 if (intel_crtc
->config
->double_wide
)
7822 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
7824 /* only g4x and later have fancy bpc/dither controls */
7825 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
7826 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7827 if (intel_crtc
->config
->dither
&& intel_crtc
->config
->pipe_bpp
!= 30)
7828 pipeconf
|= PIPECONF_DITHER_EN
|
7829 PIPECONF_DITHER_TYPE_SP
;
7831 switch (intel_crtc
->config
->pipe_bpp
) {
7833 pipeconf
|= PIPECONF_6BPC
;
7836 pipeconf
|= PIPECONF_8BPC
;
7839 pipeconf
|= PIPECONF_10BPC
;
7842 /* Case prevented by intel_choose_pipe_bpp_dither. */
7847 if (HAS_PIPE_CXSR(dev
)) {
7848 if (intel_crtc
->lowfreq_avail
) {
7849 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
7850 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
7852 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
7856 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
7857 if (INTEL_INFO(dev
)->gen
< 4 ||
7858 intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
7859 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
7861 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
7863 pipeconf
|= PIPECONF_PROGRESSIVE
;
7865 if ((IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) &&
7866 intel_crtc
->config
->limited_color_range
)
7867 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
7869 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
7870 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
7873 static int i8xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7874 struct intel_crtc_state
*crtc_state
)
7876 struct drm_device
*dev
= crtc
->base
.dev
;
7877 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7878 const struct intel_limit
*limit
;
7881 memset(&crtc_state
->dpll_hw_state
, 0,
7882 sizeof(crtc_state
->dpll_hw_state
));
7884 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7885 if (intel_panel_use_ssc(dev_priv
)) {
7886 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7887 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7890 limit
= &intel_limits_i8xx_lvds
;
7891 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DVO
)) {
7892 limit
= &intel_limits_i8xx_dvo
;
7894 limit
= &intel_limits_i8xx_dac
;
7897 if (!crtc_state
->clock_set
&&
7898 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7899 refclk
, NULL
, &crtc_state
->dpll
)) {
7900 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7904 i8xx_compute_dpll(crtc
, crtc_state
, NULL
);
7909 static int g4x_crtc_compute_clock(struct intel_crtc
*crtc
,
7910 struct intel_crtc_state
*crtc_state
)
7912 struct drm_device
*dev
= crtc
->base
.dev
;
7913 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7914 const struct intel_limit
*limit
;
7917 memset(&crtc_state
->dpll_hw_state
, 0,
7918 sizeof(crtc_state
->dpll_hw_state
));
7920 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7921 if (intel_panel_use_ssc(dev_priv
)) {
7922 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7923 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7926 if (intel_is_dual_link_lvds(dev
))
7927 limit
= &intel_limits_g4x_dual_channel_lvds
;
7929 limit
= &intel_limits_g4x_single_channel_lvds
;
7930 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
) ||
7931 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
)) {
7932 limit
= &intel_limits_g4x_hdmi
;
7933 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
)) {
7934 limit
= &intel_limits_g4x_sdvo
;
7936 /* The option is for other outputs */
7937 limit
= &intel_limits_i9xx_sdvo
;
7940 if (!crtc_state
->clock_set
&&
7941 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7942 refclk
, NULL
, &crtc_state
->dpll
)) {
7943 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7947 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7952 static int pnv_crtc_compute_clock(struct intel_crtc
*crtc
,
7953 struct intel_crtc_state
*crtc_state
)
7955 struct drm_device
*dev
= crtc
->base
.dev
;
7956 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7957 const struct intel_limit
*limit
;
7960 memset(&crtc_state
->dpll_hw_state
, 0,
7961 sizeof(crtc_state
->dpll_hw_state
));
7963 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7964 if (intel_panel_use_ssc(dev_priv
)) {
7965 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7966 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7969 limit
= &intel_limits_pineview_lvds
;
7971 limit
= &intel_limits_pineview_sdvo
;
7974 if (!crtc_state
->clock_set
&&
7975 !pnv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7976 refclk
, NULL
, &crtc_state
->dpll
)) {
7977 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7981 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7986 static int i9xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7987 struct intel_crtc_state
*crtc_state
)
7989 struct drm_device
*dev
= crtc
->base
.dev
;
7990 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7991 const struct intel_limit
*limit
;
7994 memset(&crtc_state
->dpll_hw_state
, 0,
7995 sizeof(crtc_state
->dpll_hw_state
));
7997 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7998 if (intel_panel_use_ssc(dev_priv
)) {
7999 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8000 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
8003 limit
= &intel_limits_i9xx_lvds
;
8005 limit
= &intel_limits_i9xx_sdvo
;
8008 if (!crtc_state
->clock_set
&&
8009 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8010 refclk
, NULL
, &crtc_state
->dpll
)) {
8011 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8015 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
8020 static int chv_crtc_compute_clock(struct intel_crtc
*crtc
,
8021 struct intel_crtc_state
*crtc_state
)
8023 int refclk
= 100000;
8024 const struct intel_limit
*limit
= &intel_limits_chv
;
8026 memset(&crtc_state
->dpll_hw_state
, 0,
8027 sizeof(crtc_state
->dpll_hw_state
));
8029 if (!crtc_state
->clock_set
&&
8030 !chv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8031 refclk
, NULL
, &crtc_state
->dpll
)) {
8032 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8036 chv_compute_dpll(crtc
, crtc_state
);
8041 static int vlv_crtc_compute_clock(struct intel_crtc
*crtc
,
8042 struct intel_crtc_state
*crtc_state
)
8044 int refclk
= 100000;
8045 const struct intel_limit
*limit
= &intel_limits_vlv
;
8047 memset(&crtc_state
->dpll_hw_state
, 0,
8048 sizeof(crtc_state
->dpll_hw_state
));
8050 if (!crtc_state
->clock_set
&&
8051 !vlv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8052 refclk
, NULL
, &crtc_state
->dpll
)) {
8053 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8057 vlv_compute_dpll(crtc
, crtc_state
);
8062 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
8063 struct intel_crtc_state
*pipe_config
)
8065 struct drm_device
*dev
= crtc
->base
.dev
;
8066 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8069 if (INTEL_INFO(dev
)->gen
<= 3 && (IS_I830(dev
) || !IS_MOBILE(dev
)))
8072 tmp
= I915_READ(PFIT_CONTROL
);
8073 if (!(tmp
& PFIT_ENABLE
))
8076 /* Check whether the pfit is attached to our pipe. */
8077 if (INTEL_INFO(dev
)->gen
< 4) {
8078 if (crtc
->pipe
!= PIPE_B
)
8081 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
8085 pipe_config
->gmch_pfit
.control
= tmp
;
8086 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
8089 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
8090 struct intel_crtc_state
*pipe_config
)
8092 struct drm_device
*dev
= crtc
->base
.dev
;
8093 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8094 int pipe
= pipe_config
->cpu_transcoder
;
8097 int refclk
= 100000;
8099 /* In case of DSI, DPLL will not be used */
8100 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
8103 mutex_lock(&dev_priv
->sb_lock
);
8104 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
8105 mutex_unlock(&dev_priv
->sb_lock
);
8107 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
8108 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
8109 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
8110 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
8111 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
8113 pipe_config
->port_clock
= vlv_calc_dpll_params(refclk
, &clock
);
8117 i9xx_get_initial_plane_config(struct intel_crtc
*crtc
,
8118 struct intel_initial_plane_config
*plane_config
)
8120 struct drm_device
*dev
= crtc
->base
.dev
;
8121 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8122 u32 val
, base
, offset
;
8123 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
8124 int fourcc
, pixel_format
;
8125 unsigned int aligned_height
;
8126 struct drm_framebuffer
*fb
;
8127 struct intel_framebuffer
*intel_fb
;
8129 val
= I915_READ(DSPCNTR(plane
));
8130 if (!(val
& DISPLAY_PLANE_ENABLE
))
8133 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8135 DRM_DEBUG_KMS("failed to alloc fb\n");
8139 fb
= &intel_fb
->base
;
8141 if (INTEL_INFO(dev
)->gen
>= 4) {
8142 if (val
& DISPPLANE_TILED
) {
8143 plane_config
->tiling
= I915_TILING_X
;
8144 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
8148 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
8149 fourcc
= i9xx_format_to_fourcc(pixel_format
);
8150 fb
->pixel_format
= fourcc
;
8151 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
8153 if (INTEL_INFO(dev
)->gen
>= 4) {
8154 if (plane_config
->tiling
)
8155 offset
= I915_READ(DSPTILEOFF(plane
));
8157 offset
= I915_READ(DSPLINOFF(plane
));
8158 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
8160 base
= I915_READ(DSPADDR(plane
));
8162 plane_config
->base
= base
;
8164 val
= I915_READ(PIPESRC(pipe
));
8165 fb
->width
= ((val
>> 16) & 0xfff) + 1;
8166 fb
->height
= ((val
>> 0) & 0xfff) + 1;
8168 val
= I915_READ(DSPSTRIDE(pipe
));
8169 fb
->pitches
[0] = val
& 0xffffffc0;
8171 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
8175 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8177 DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8178 pipe_name(pipe
), plane
, fb
->width
, fb
->height
,
8179 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
8180 plane_config
->size
);
8182 plane_config
->fb
= intel_fb
;
8185 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
8186 struct intel_crtc_state
*pipe_config
)
8188 struct drm_device
*dev
= crtc
->base
.dev
;
8189 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8190 int pipe
= pipe_config
->cpu_transcoder
;
8191 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
8193 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
, pll_dw3
;
8194 int refclk
= 100000;
8196 /* In case of DSI, DPLL will not be used */
8197 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
8200 mutex_lock(&dev_priv
->sb_lock
);
8201 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
8202 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
8203 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
8204 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
8205 pll_dw3
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
8206 mutex_unlock(&dev_priv
->sb_lock
);
8208 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
8209 clock
.m2
= (pll_dw0
& 0xff) << 22;
8210 if (pll_dw3
& DPIO_CHV_FRAC_DIV_EN
)
8211 clock
.m2
|= pll_dw2
& 0x3fffff;
8212 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
8213 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
8214 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
8216 pipe_config
->port_clock
= chv_calc_dpll_params(refclk
, &clock
);
8219 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
8220 struct intel_crtc_state
*pipe_config
)
8222 struct drm_device
*dev
= crtc
->base
.dev
;
8223 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8224 enum intel_display_power_domain power_domain
;
8228 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
8229 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8232 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8233 pipe_config
->shared_dpll
= NULL
;
8237 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
8238 if (!(tmp
& PIPECONF_ENABLE
))
8241 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
8242 switch (tmp
& PIPECONF_BPC_MASK
) {
8244 pipe_config
->pipe_bpp
= 18;
8247 pipe_config
->pipe_bpp
= 24;
8249 case PIPECONF_10BPC
:
8250 pipe_config
->pipe_bpp
= 30;
8257 if ((IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) &&
8258 (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
8259 pipe_config
->limited_color_range
= true;
8261 if (INTEL_INFO(dev
)->gen
< 4)
8262 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
8264 intel_get_pipe_timings(crtc
, pipe_config
);
8265 intel_get_pipe_src_size(crtc
, pipe_config
);
8267 i9xx_get_pfit_config(crtc
, pipe_config
);
8269 if (INTEL_INFO(dev
)->gen
>= 4) {
8270 /* No way to read it out on pipes B and C */
8271 if (IS_CHERRYVIEW(dev
) && crtc
->pipe
!= PIPE_A
)
8272 tmp
= dev_priv
->chv_dpll_md
[crtc
->pipe
];
8274 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
8275 pipe_config
->pixel_multiplier
=
8276 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
8277 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
8278 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
8279 } else if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
8280 tmp
= I915_READ(DPLL(crtc
->pipe
));
8281 pipe_config
->pixel_multiplier
=
8282 ((tmp
& SDVO_MULTIPLIER_MASK
)
8283 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
8285 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8286 * port and will be fixed up in the encoder->get_config
8288 pipe_config
->pixel_multiplier
= 1;
8290 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
8291 if (!IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
)) {
8293 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
8294 * on 830. Filter it out here so that we don't
8295 * report errors due to that.
8298 pipe_config
->dpll_hw_state
.dpll
&= ~DPLL_DVO_2X_MODE
;
8300 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
8301 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
8303 /* Mask out read-only status bits. */
8304 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
8305 DPLL_PORTC_READY_MASK
|
8306 DPLL_PORTB_READY_MASK
);
8309 if (IS_CHERRYVIEW(dev
))
8310 chv_crtc_clock_get(crtc
, pipe_config
);
8311 else if (IS_VALLEYVIEW(dev
))
8312 vlv_crtc_clock_get(crtc
, pipe_config
);
8314 i9xx_crtc_clock_get(crtc
, pipe_config
);
8317 * Normally the dotclock is filled in by the encoder .get_config()
8318 * but in case the pipe is enabled w/o any ports we need a sane
8321 pipe_config
->base
.adjusted_mode
.crtc_clock
=
8322 pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
8327 intel_display_power_put(dev_priv
, power_domain
);
8332 static void ironlake_init_pch_refclk(struct drm_device
*dev
)
8334 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8335 struct intel_encoder
*encoder
;
8338 bool has_lvds
= false;
8339 bool has_cpu_edp
= false;
8340 bool has_panel
= false;
8341 bool has_ck505
= false;
8342 bool can_ssc
= false;
8343 bool using_ssc_source
= false;
8345 /* We need to take the global config into account */
8346 for_each_intel_encoder(dev
, encoder
) {
8347 switch (encoder
->type
) {
8348 case INTEL_OUTPUT_LVDS
:
8352 case INTEL_OUTPUT_EDP
:
8354 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
8362 if (HAS_PCH_IBX(dev
)) {
8363 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
8364 can_ssc
= has_ck505
;
8370 /* Check if any DPLLs are using the SSC source */
8371 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
8372 u32 temp
= I915_READ(PCH_DPLL(i
));
8374 if (!(temp
& DPLL_VCO_ENABLE
))
8377 if ((temp
& PLL_REF_INPUT_MASK
) ==
8378 PLLB_REF_INPUT_SPREADSPECTRUMIN
) {
8379 using_ssc_source
= true;
8384 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
8385 has_panel
, has_lvds
, has_ck505
, using_ssc_source
);
8387 /* Ironlake: try to setup display ref clock before DPLL
8388 * enabling. This is only under driver's control after
8389 * PCH B stepping, previous chipset stepping should be
8390 * ignoring this setting.
8392 val
= I915_READ(PCH_DREF_CONTROL
);
8394 /* As we must carefully and slowly disable/enable each source in turn,
8395 * compute the final state we want first and check if we need to
8396 * make any changes at all.
8399 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
8401 final
|= DREF_NONSPREAD_CK505_ENABLE
;
8403 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
8405 final
&= ~DREF_SSC_SOURCE_MASK
;
8406 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
8407 final
&= ~DREF_SSC1_ENABLE
;
8410 final
|= DREF_SSC_SOURCE_ENABLE
;
8412 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
8413 final
|= DREF_SSC1_ENABLE
;
8416 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
8417 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
8419 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
8421 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
8422 } else if (using_ssc_source
) {
8423 final
|= DREF_SSC_SOURCE_ENABLE
;
8424 final
|= DREF_SSC1_ENABLE
;
8430 /* Always enable nonspread source */
8431 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
8434 val
|= DREF_NONSPREAD_CK505_ENABLE
;
8436 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
8439 val
&= ~DREF_SSC_SOURCE_MASK
;
8440 val
|= DREF_SSC_SOURCE_ENABLE
;
8442 /* SSC must be turned on before enabling the CPU output */
8443 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
8444 DRM_DEBUG_KMS("Using SSC on panel\n");
8445 val
|= DREF_SSC1_ENABLE
;
8447 val
&= ~DREF_SSC1_ENABLE
;
8449 /* Get SSC going before enabling the outputs */
8450 I915_WRITE(PCH_DREF_CONTROL
, val
);
8451 POSTING_READ(PCH_DREF_CONTROL
);
8454 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
8456 /* Enable CPU source on CPU attached eDP */
8458 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
8459 DRM_DEBUG_KMS("Using SSC on eDP\n");
8460 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
8462 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
8464 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
8466 I915_WRITE(PCH_DREF_CONTROL
, val
);
8467 POSTING_READ(PCH_DREF_CONTROL
);
8470 DRM_DEBUG_KMS("Disabling CPU source output\n");
8472 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
8474 /* Turn off CPU output */
8475 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
8477 I915_WRITE(PCH_DREF_CONTROL
, val
);
8478 POSTING_READ(PCH_DREF_CONTROL
);
8481 if (!using_ssc_source
) {
8482 DRM_DEBUG_KMS("Disabling SSC source\n");
8484 /* Turn off the SSC source */
8485 val
&= ~DREF_SSC_SOURCE_MASK
;
8486 val
|= DREF_SSC_SOURCE_DISABLE
;
8489 val
&= ~DREF_SSC1_ENABLE
;
8491 I915_WRITE(PCH_DREF_CONTROL
, val
);
8492 POSTING_READ(PCH_DREF_CONTROL
);
8497 BUG_ON(val
!= final
);
8500 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
8504 tmp
= I915_READ(SOUTH_CHICKEN2
);
8505 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
8506 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
8508 if (wait_for_us(I915_READ(SOUTH_CHICKEN2
) &
8509 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
8510 DRM_ERROR("FDI mPHY reset assert timeout\n");
8512 tmp
= I915_READ(SOUTH_CHICKEN2
);
8513 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
8514 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
8516 if (wait_for_us((I915_READ(SOUTH_CHICKEN2
) &
8517 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
8518 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
8521 /* WaMPhyProgramming:hsw */
8522 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
8526 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
8527 tmp
&= ~(0xFF << 24);
8528 tmp
|= (0x12 << 24);
8529 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
8531 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
8533 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
8535 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
8537 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
8539 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
8540 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
8541 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
8543 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
8544 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
8545 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
8547 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
8550 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
8552 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
8555 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
8557 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
8560 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
8562 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
8565 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
8567 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
8568 tmp
&= ~(0xFF << 16);
8569 tmp
|= (0x1C << 16);
8570 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
8572 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
8573 tmp
&= ~(0xFF << 16);
8574 tmp
|= (0x1C << 16);
8575 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
8577 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
8579 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
8581 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
8583 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
8585 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
8586 tmp
&= ~(0xF << 28);
8588 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
8590 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
8591 tmp
&= ~(0xF << 28);
8593 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
8596 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8597 * Programming" based on the parameters passed:
8598 * - Sequence to enable CLKOUT_DP
8599 * - Sequence to enable CLKOUT_DP without spread
8600 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8602 static void lpt_enable_clkout_dp(struct drm_device
*dev
, bool with_spread
,
8605 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8608 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
8610 if (WARN(HAS_PCH_LPT_LP(dev
) && with_fdi
, "LP PCH doesn't have FDI\n"))
8613 mutex_lock(&dev_priv
->sb_lock
);
8615 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8616 tmp
&= ~SBI_SSCCTL_DISABLE
;
8617 tmp
|= SBI_SSCCTL_PATHALT
;
8618 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8623 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8624 tmp
&= ~SBI_SSCCTL_PATHALT
;
8625 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8628 lpt_reset_fdi_mphy(dev_priv
);
8629 lpt_program_fdi_mphy(dev_priv
);
8633 reg
= HAS_PCH_LPT_LP(dev
) ? SBI_GEN0
: SBI_DBUFF0
;
8634 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
8635 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
8636 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
8638 mutex_unlock(&dev_priv
->sb_lock
);
8641 /* Sequence to disable CLKOUT_DP */
8642 static void lpt_disable_clkout_dp(struct drm_device
*dev
)
8644 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8647 mutex_lock(&dev_priv
->sb_lock
);
8649 reg
= HAS_PCH_LPT_LP(dev
) ? SBI_GEN0
: SBI_DBUFF0
;
8650 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
8651 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
8652 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
8654 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8655 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
8656 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
8657 tmp
|= SBI_SSCCTL_PATHALT
;
8658 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8661 tmp
|= SBI_SSCCTL_DISABLE
;
8662 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8665 mutex_unlock(&dev_priv
->sb_lock
);
8668 #define BEND_IDX(steps) ((50 + (steps)) / 5)
8670 static const uint16_t sscdivintphase
[] = {
8671 [BEND_IDX( 50)] = 0x3B23,
8672 [BEND_IDX( 45)] = 0x3B23,
8673 [BEND_IDX( 40)] = 0x3C23,
8674 [BEND_IDX( 35)] = 0x3C23,
8675 [BEND_IDX( 30)] = 0x3D23,
8676 [BEND_IDX( 25)] = 0x3D23,
8677 [BEND_IDX( 20)] = 0x3E23,
8678 [BEND_IDX( 15)] = 0x3E23,
8679 [BEND_IDX( 10)] = 0x3F23,
8680 [BEND_IDX( 5)] = 0x3F23,
8681 [BEND_IDX( 0)] = 0x0025,
8682 [BEND_IDX( -5)] = 0x0025,
8683 [BEND_IDX(-10)] = 0x0125,
8684 [BEND_IDX(-15)] = 0x0125,
8685 [BEND_IDX(-20)] = 0x0225,
8686 [BEND_IDX(-25)] = 0x0225,
8687 [BEND_IDX(-30)] = 0x0325,
8688 [BEND_IDX(-35)] = 0x0325,
8689 [BEND_IDX(-40)] = 0x0425,
8690 [BEND_IDX(-45)] = 0x0425,
8691 [BEND_IDX(-50)] = 0x0525,
8696 * steps -50 to 50 inclusive, in steps of 5
8697 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8698 * change in clock period = -(steps / 10) * 5.787 ps
8700 static void lpt_bend_clkout_dp(struct drm_i915_private
*dev_priv
, int steps
)
8703 int idx
= BEND_IDX(steps
);
8705 if (WARN_ON(steps
% 5 != 0))
8708 if (WARN_ON(idx
>= ARRAY_SIZE(sscdivintphase
)))
8711 mutex_lock(&dev_priv
->sb_lock
);
8713 if (steps
% 10 != 0)
8717 intel_sbi_write(dev_priv
, SBI_SSCDITHPHASE
, tmp
, SBI_ICLK
);
8719 tmp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE
, SBI_ICLK
);
8721 tmp
|= sscdivintphase
[idx
];
8722 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE
, tmp
, SBI_ICLK
);
8724 mutex_unlock(&dev_priv
->sb_lock
);
8729 static void lpt_init_pch_refclk(struct drm_device
*dev
)
8731 struct intel_encoder
*encoder
;
8732 bool has_vga
= false;
8734 for_each_intel_encoder(dev
, encoder
) {
8735 switch (encoder
->type
) {
8736 case INTEL_OUTPUT_ANALOG
:
8745 lpt_bend_clkout_dp(to_i915(dev
), 0);
8746 lpt_enable_clkout_dp(dev
, true, true);
8748 lpt_disable_clkout_dp(dev
);
8753 * Initialize reference clocks when the driver loads
8755 void intel_init_pch_refclk(struct drm_device
*dev
)
8757 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
8758 ironlake_init_pch_refclk(dev
);
8759 else if (HAS_PCH_LPT(dev
))
8760 lpt_init_pch_refclk(dev
);
8763 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
8765 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
8766 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8767 int pipe
= intel_crtc
->pipe
;
8772 switch (intel_crtc
->config
->pipe_bpp
) {
8774 val
|= PIPECONF_6BPC
;
8777 val
|= PIPECONF_8BPC
;
8780 val
|= PIPECONF_10BPC
;
8783 val
|= PIPECONF_12BPC
;
8786 /* Case prevented by intel_choose_pipe_bpp_dither. */
8790 if (intel_crtc
->config
->dither
)
8791 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
8793 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8794 val
|= PIPECONF_INTERLACED_ILK
;
8796 val
|= PIPECONF_PROGRESSIVE
;
8798 if (intel_crtc
->config
->limited_color_range
)
8799 val
|= PIPECONF_COLOR_RANGE_SELECT
;
8801 I915_WRITE(PIPECONF(pipe
), val
);
8802 POSTING_READ(PIPECONF(pipe
));
8805 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
8807 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
8808 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8809 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
8812 if (IS_HASWELL(dev_priv
) && intel_crtc
->config
->dither
)
8813 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
8815 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8816 val
|= PIPECONF_INTERLACED_ILK
;
8818 val
|= PIPECONF_PROGRESSIVE
;
8820 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
8821 POSTING_READ(PIPECONF(cpu_transcoder
));
8824 static void haswell_set_pipemisc(struct drm_crtc
*crtc
)
8826 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
8827 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8829 if (IS_BROADWELL(dev_priv
) || INTEL_INFO(dev_priv
)->gen
>= 9) {
8832 switch (intel_crtc
->config
->pipe_bpp
) {
8834 val
|= PIPEMISC_DITHER_6_BPC
;
8837 val
|= PIPEMISC_DITHER_8_BPC
;
8840 val
|= PIPEMISC_DITHER_10_BPC
;
8843 val
|= PIPEMISC_DITHER_12_BPC
;
8846 /* Case prevented by pipe_config_set_bpp. */
8850 if (intel_crtc
->config
->dither
)
8851 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
8853 I915_WRITE(PIPEMISC(intel_crtc
->pipe
), val
);
8857 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
8860 * Account for spread spectrum to avoid
8861 * oversubscribing the link. Max center spread
8862 * is 2.5%; use 5% for safety's sake.
8864 u32 bps
= target_clock
* bpp
* 21 / 20;
8865 return DIV_ROUND_UP(bps
, link_bw
* 8);
8868 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
8870 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
8873 static void ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
8874 struct intel_crtc_state
*crtc_state
,
8875 struct dpll
*reduced_clock
)
8877 struct drm_crtc
*crtc
= &intel_crtc
->base
;
8878 struct drm_device
*dev
= crtc
->dev
;
8879 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8883 /* Enable autotuning of the PLL clock (if permissible) */
8885 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8886 if ((intel_panel_use_ssc(dev_priv
) &&
8887 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
8888 (HAS_PCH_IBX(dev
) && intel_is_dual_link_lvds(dev
)))
8890 } else if (crtc_state
->sdvo_tv_clock
)
8893 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
8895 if (ironlake_needs_fb_cb_tune(&crtc_state
->dpll
, factor
))
8898 if (reduced_clock
) {
8899 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
8901 if (reduced_clock
->m
< factor
* reduced_clock
->n
)
8909 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
))
8910 dpll
|= DPLLB_MODE_LVDS
;
8912 dpll
|= DPLLB_MODE_DAC_SERIAL
;
8914 dpll
|= (crtc_state
->pixel_multiplier
- 1)
8915 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
8917 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
8918 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
8919 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8921 if (intel_crtc_has_dp_encoder(crtc_state
))
8922 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8924 /* compute bitmask from p1 value */
8925 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8927 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
8929 switch (crtc_state
->dpll
.p2
) {
8931 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
8934 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
8937 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
8940 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
8944 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
8945 intel_panel_use_ssc(dev_priv
))
8946 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
8948 dpll
|= PLL_REF_INPUT_DREFCLK
;
8950 dpll
|= DPLL_VCO_ENABLE
;
8952 crtc_state
->dpll_hw_state
.dpll
= dpll
;
8953 crtc_state
->dpll_hw_state
.fp0
= fp
;
8954 crtc_state
->dpll_hw_state
.fp1
= fp2
;
8957 static int ironlake_crtc_compute_clock(struct intel_crtc
*crtc
,
8958 struct intel_crtc_state
*crtc_state
)
8960 struct drm_device
*dev
= crtc
->base
.dev
;
8961 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8962 struct dpll reduced_clock
;
8963 bool has_reduced_clock
= false;
8964 struct intel_shared_dpll
*pll
;
8965 const struct intel_limit
*limit
;
8966 int refclk
= 120000;
8968 memset(&crtc_state
->dpll_hw_state
, 0,
8969 sizeof(crtc_state
->dpll_hw_state
));
8971 crtc
->lowfreq_avail
= false;
8973 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8974 if (!crtc_state
->has_pch_encoder
)
8977 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8978 if (intel_panel_use_ssc(dev_priv
)) {
8979 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8980 dev_priv
->vbt
.lvds_ssc_freq
);
8981 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8984 if (intel_is_dual_link_lvds(dev
)) {
8985 if (refclk
== 100000)
8986 limit
= &intel_limits_ironlake_dual_lvds_100m
;
8988 limit
= &intel_limits_ironlake_dual_lvds
;
8990 if (refclk
== 100000)
8991 limit
= &intel_limits_ironlake_single_lvds_100m
;
8993 limit
= &intel_limits_ironlake_single_lvds
;
8996 limit
= &intel_limits_ironlake_dac
;
8999 if (!crtc_state
->clock_set
&&
9000 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
9001 refclk
, NULL
, &crtc_state
->dpll
)) {
9002 DRM_ERROR("Couldn't find PLL settings for mode!\n");
9006 ironlake_compute_dpll(crtc
, crtc_state
,
9007 has_reduced_clock
? &reduced_clock
: NULL
);
9009 pll
= intel_get_shared_dpll(crtc
, crtc_state
, NULL
);
9011 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
9012 pipe_name(crtc
->pipe
));
9016 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
9018 crtc
->lowfreq_avail
= true;
9023 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
9024 struct intel_link_m_n
*m_n
)
9026 struct drm_device
*dev
= crtc
->base
.dev
;
9027 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9028 enum pipe pipe
= crtc
->pipe
;
9030 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
9031 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
9032 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
9034 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
9035 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
9036 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
9039 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
9040 enum transcoder transcoder
,
9041 struct intel_link_m_n
*m_n
,
9042 struct intel_link_m_n
*m2_n2
)
9044 struct drm_device
*dev
= crtc
->base
.dev
;
9045 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9046 enum pipe pipe
= crtc
->pipe
;
9048 if (INTEL_INFO(dev
)->gen
>= 5) {
9049 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
9050 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
9051 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
9053 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
9054 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
9055 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
9056 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
9057 * gen < 8) and if DRRS is supported (to make sure the
9058 * registers are not unnecessarily read).
9060 if (m2_n2
&& INTEL_INFO(dev
)->gen
< 8 &&
9061 crtc
->config
->has_drrs
) {
9062 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
9063 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
9064 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
9066 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
9067 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
9068 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
9071 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
9072 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
9073 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
9075 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
9076 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
9077 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
9081 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
9082 struct intel_crtc_state
*pipe_config
)
9084 if (pipe_config
->has_pch_encoder
)
9085 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
9087 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
9088 &pipe_config
->dp_m_n
,
9089 &pipe_config
->dp_m2_n2
);
9092 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
9093 struct intel_crtc_state
*pipe_config
)
9095 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
9096 &pipe_config
->fdi_m_n
, NULL
);
9099 static void skylake_get_pfit_config(struct intel_crtc
*crtc
,
9100 struct intel_crtc_state
*pipe_config
)
9102 struct drm_device
*dev
= crtc
->base
.dev
;
9103 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9104 struct intel_crtc_scaler_state
*scaler_state
= &pipe_config
->scaler_state
;
9105 uint32_t ps_ctrl
= 0;
9109 /* find scaler attached to this pipe */
9110 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
9111 ps_ctrl
= I915_READ(SKL_PS_CTRL(crtc
->pipe
, i
));
9112 if (ps_ctrl
& PS_SCALER_EN
&& !(ps_ctrl
& PS_PLANE_SEL_MASK
)) {
9114 pipe_config
->pch_pfit
.enabled
= true;
9115 pipe_config
->pch_pfit
.pos
= I915_READ(SKL_PS_WIN_POS(crtc
->pipe
, i
));
9116 pipe_config
->pch_pfit
.size
= I915_READ(SKL_PS_WIN_SZ(crtc
->pipe
, i
));
9121 scaler_state
->scaler_id
= id
;
9123 scaler_state
->scaler_users
|= (1 << SKL_CRTC_INDEX
);
9125 scaler_state
->scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
9130 skylake_get_initial_plane_config(struct intel_crtc
*crtc
,
9131 struct intel_initial_plane_config
*plane_config
)
9133 struct drm_device
*dev
= crtc
->base
.dev
;
9134 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9135 u32 val
, base
, offset
, stride_mult
, tiling
;
9136 int pipe
= crtc
->pipe
;
9137 int fourcc
, pixel_format
;
9138 unsigned int aligned_height
;
9139 struct drm_framebuffer
*fb
;
9140 struct intel_framebuffer
*intel_fb
;
9142 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9144 DRM_DEBUG_KMS("failed to alloc fb\n");
9148 fb
= &intel_fb
->base
;
9150 val
= I915_READ(PLANE_CTL(pipe
, 0));
9151 if (!(val
& PLANE_CTL_ENABLE
))
9154 pixel_format
= val
& PLANE_CTL_FORMAT_MASK
;
9155 fourcc
= skl_format_to_fourcc(pixel_format
,
9156 val
& PLANE_CTL_ORDER_RGBX
,
9157 val
& PLANE_CTL_ALPHA_MASK
);
9158 fb
->pixel_format
= fourcc
;
9159 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
9161 tiling
= val
& PLANE_CTL_TILED_MASK
;
9163 case PLANE_CTL_TILED_LINEAR
:
9164 fb
->modifier
[0] = DRM_FORMAT_MOD_NONE
;
9166 case PLANE_CTL_TILED_X
:
9167 plane_config
->tiling
= I915_TILING_X
;
9168 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
9170 case PLANE_CTL_TILED_Y
:
9171 fb
->modifier
[0] = I915_FORMAT_MOD_Y_TILED
;
9173 case PLANE_CTL_TILED_YF
:
9174 fb
->modifier
[0] = I915_FORMAT_MOD_Yf_TILED
;
9177 MISSING_CASE(tiling
);
9181 base
= I915_READ(PLANE_SURF(pipe
, 0)) & 0xfffff000;
9182 plane_config
->base
= base
;
9184 offset
= I915_READ(PLANE_OFFSET(pipe
, 0));
9186 val
= I915_READ(PLANE_SIZE(pipe
, 0));
9187 fb
->height
= ((val
>> 16) & 0xfff) + 1;
9188 fb
->width
= ((val
>> 0) & 0x1fff) + 1;
9190 val
= I915_READ(PLANE_STRIDE(pipe
, 0));
9191 stride_mult
= intel_fb_stride_alignment(dev_priv
, fb
->modifier
[0],
9193 fb
->pitches
[0] = (val
& 0x3ff) * stride_mult
;
9195 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
9199 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
9201 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9202 pipe_name(pipe
), fb
->width
, fb
->height
,
9203 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
9204 plane_config
->size
);
9206 plane_config
->fb
= intel_fb
;
9213 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
9214 struct intel_crtc_state
*pipe_config
)
9216 struct drm_device
*dev
= crtc
->base
.dev
;
9217 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9220 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
9222 if (tmp
& PF_ENABLE
) {
9223 pipe_config
->pch_pfit
.enabled
= true;
9224 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
9225 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
9227 /* We currently do not free assignements of panel fitters on
9228 * ivb/hsw (since we don't use the higher upscaling modes which
9229 * differentiates them) so just WARN about this case for now. */
9231 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
9232 PF_PIPE_SEL_IVB(crtc
->pipe
));
9238 ironlake_get_initial_plane_config(struct intel_crtc
*crtc
,
9239 struct intel_initial_plane_config
*plane_config
)
9241 struct drm_device
*dev
= crtc
->base
.dev
;
9242 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9243 u32 val
, base
, offset
;
9244 int pipe
= crtc
->pipe
;
9245 int fourcc
, pixel_format
;
9246 unsigned int aligned_height
;
9247 struct drm_framebuffer
*fb
;
9248 struct intel_framebuffer
*intel_fb
;
9250 val
= I915_READ(DSPCNTR(pipe
));
9251 if (!(val
& DISPLAY_PLANE_ENABLE
))
9254 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9256 DRM_DEBUG_KMS("failed to alloc fb\n");
9260 fb
= &intel_fb
->base
;
9262 if (INTEL_INFO(dev
)->gen
>= 4) {
9263 if (val
& DISPPLANE_TILED
) {
9264 plane_config
->tiling
= I915_TILING_X
;
9265 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
9269 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
9270 fourcc
= i9xx_format_to_fourcc(pixel_format
);
9271 fb
->pixel_format
= fourcc
;
9272 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
9274 base
= I915_READ(DSPSURF(pipe
)) & 0xfffff000;
9275 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
9276 offset
= I915_READ(DSPOFFSET(pipe
));
9278 if (plane_config
->tiling
)
9279 offset
= I915_READ(DSPTILEOFF(pipe
));
9281 offset
= I915_READ(DSPLINOFF(pipe
));
9283 plane_config
->base
= base
;
9285 val
= I915_READ(PIPESRC(pipe
));
9286 fb
->width
= ((val
>> 16) & 0xfff) + 1;
9287 fb
->height
= ((val
>> 0) & 0xfff) + 1;
9289 val
= I915_READ(DSPSTRIDE(pipe
));
9290 fb
->pitches
[0] = val
& 0xffffffc0;
9292 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
9296 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
9298 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9299 pipe_name(pipe
), fb
->width
, fb
->height
,
9300 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
9301 plane_config
->size
);
9303 plane_config
->fb
= intel_fb
;
9306 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
9307 struct intel_crtc_state
*pipe_config
)
9309 struct drm_device
*dev
= crtc
->base
.dev
;
9310 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9311 enum intel_display_power_domain power_domain
;
9315 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
9316 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9319 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
9320 pipe_config
->shared_dpll
= NULL
;
9323 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
9324 if (!(tmp
& PIPECONF_ENABLE
))
9327 switch (tmp
& PIPECONF_BPC_MASK
) {
9329 pipe_config
->pipe_bpp
= 18;
9332 pipe_config
->pipe_bpp
= 24;
9334 case PIPECONF_10BPC
:
9335 pipe_config
->pipe_bpp
= 30;
9337 case PIPECONF_12BPC
:
9338 pipe_config
->pipe_bpp
= 36;
9344 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
9345 pipe_config
->limited_color_range
= true;
9347 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
9348 struct intel_shared_dpll
*pll
;
9349 enum intel_dpll_id pll_id
;
9351 pipe_config
->has_pch_encoder
= true;
9353 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
9354 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
9355 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
9357 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
9359 if (HAS_PCH_IBX(dev_priv
)) {
9361 * The pipe->pch transcoder and pch transcoder->pll
9364 pll_id
= (enum intel_dpll_id
) crtc
->pipe
;
9366 tmp
= I915_READ(PCH_DPLL_SEL
);
9367 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
9368 pll_id
= DPLL_ID_PCH_PLL_B
;
9370 pll_id
= DPLL_ID_PCH_PLL_A
;
9373 pipe_config
->shared_dpll
=
9374 intel_get_shared_dpll_by_id(dev_priv
, pll_id
);
9375 pll
= pipe_config
->shared_dpll
;
9377 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
9378 &pipe_config
->dpll_hw_state
));
9380 tmp
= pipe_config
->dpll_hw_state
.dpll
;
9381 pipe_config
->pixel_multiplier
=
9382 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
9383 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
9385 ironlake_pch_clock_get(crtc
, pipe_config
);
9387 pipe_config
->pixel_multiplier
= 1;
9390 intel_get_pipe_timings(crtc
, pipe_config
);
9391 intel_get_pipe_src_size(crtc
, pipe_config
);
9393 ironlake_get_pfit_config(crtc
, pipe_config
);
9398 intel_display_power_put(dev_priv
, power_domain
);
9403 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
9405 struct drm_device
*dev
= &dev_priv
->drm
;
9406 struct intel_crtc
*crtc
;
9408 for_each_intel_crtc(dev
, crtc
)
9409 I915_STATE_WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
9410 pipe_name(crtc
->pipe
));
9412 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
9413 I915_STATE_WARN(I915_READ(SPLL_CTL
) & SPLL_PLL_ENABLE
, "SPLL enabled\n");
9414 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE
, "WRPLL1 enabled\n");
9415 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE
, "WRPLL2 enabled\n");
9416 I915_STATE_WARN(I915_READ(PCH_PP_STATUS
) & PP_ON
, "Panel power on\n");
9417 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
9418 "CPU PWM1 enabled\n");
9419 if (IS_HASWELL(dev
))
9420 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
9421 "CPU PWM2 enabled\n");
9422 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
9423 "PCH PWM1 enabled\n");
9424 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
9425 "Utility pin enabled\n");
9426 I915_STATE_WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
9429 * In theory we can still leave IRQs enabled, as long as only the HPD
9430 * interrupts remain enabled. We used to check for that, but since it's
9431 * gen-specific and since we only disable LCPLL after we fully disable
9432 * the interrupts, the check below should be enough.
9434 I915_STATE_WARN(intel_irqs_enabled(dev_priv
), "IRQs enabled\n");
9437 static uint32_t hsw_read_dcomp(struct drm_i915_private
*dev_priv
)
9439 struct drm_device
*dev
= &dev_priv
->drm
;
9441 if (IS_HASWELL(dev
))
9442 return I915_READ(D_COMP_HSW
);
9444 return I915_READ(D_COMP_BDW
);
9447 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
9449 struct drm_device
*dev
= &dev_priv
->drm
;
9451 if (IS_HASWELL(dev
)) {
9452 mutex_lock(&dev_priv
->rps
.hw_lock
);
9453 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
9455 DRM_ERROR("Failed to write to D_COMP\n");
9456 mutex_unlock(&dev_priv
->rps
.hw_lock
);
9458 I915_WRITE(D_COMP_BDW
, val
);
9459 POSTING_READ(D_COMP_BDW
);
9464 * This function implements pieces of two sequences from BSpec:
9465 * - Sequence for display software to disable LCPLL
9466 * - Sequence for display software to allow package C8+
9467 * The steps implemented here are just the steps that actually touch the LCPLL
9468 * register. Callers should take care of disabling all the display engine
9469 * functions, doing the mode unset, fixing interrupts, etc.
9471 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
9472 bool switch_to_fclk
, bool allow_power_down
)
9476 assert_can_disable_lcpll(dev_priv
);
9478 val
= I915_READ(LCPLL_CTL
);
9480 if (switch_to_fclk
) {
9481 val
|= LCPLL_CD_SOURCE_FCLK
;
9482 I915_WRITE(LCPLL_CTL
, val
);
9484 if (wait_for_us(I915_READ(LCPLL_CTL
) &
9485 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
9486 DRM_ERROR("Switching to FCLK failed\n");
9488 val
= I915_READ(LCPLL_CTL
);
9491 val
|= LCPLL_PLL_DISABLE
;
9492 I915_WRITE(LCPLL_CTL
, val
);
9493 POSTING_READ(LCPLL_CTL
);
9495 if (intel_wait_for_register(dev_priv
, LCPLL_CTL
, LCPLL_PLL_LOCK
, 0, 1))
9496 DRM_ERROR("LCPLL still locked\n");
9498 val
= hsw_read_dcomp(dev_priv
);
9499 val
|= D_COMP_COMP_DISABLE
;
9500 hsw_write_dcomp(dev_priv
, val
);
9503 if (wait_for((hsw_read_dcomp(dev_priv
) & D_COMP_RCOMP_IN_PROGRESS
) == 0,
9505 DRM_ERROR("D_COMP RCOMP still in progress\n");
9507 if (allow_power_down
) {
9508 val
= I915_READ(LCPLL_CTL
);
9509 val
|= LCPLL_POWER_DOWN_ALLOW
;
9510 I915_WRITE(LCPLL_CTL
, val
);
9511 POSTING_READ(LCPLL_CTL
);
9516 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9519 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
9523 val
= I915_READ(LCPLL_CTL
);
9525 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
9526 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
9530 * Make sure we're not on PC8 state before disabling PC8, otherwise
9531 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
9533 intel_uncore_forcewake_get(dev_priv
, FORCEWAKE_ALL
);
9535 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
9536 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
9537 I915_WRITE(LCPLL_CTL
, val
);
9538 POSTING_READ(LCPLL_CTL
);
9541 val
= hsw_read_dcomp(dev_priv
);
9542 val
|= D_COMP_COMP_FORCE
;
9543 val
&= ~D_COMP_COMP_DISABLE
;
9544 hsw_write_dcomp(dev_priv
, val
);
9546 val
= I915_READ(LCPLL_CTL
);
9547 val
&= ~LCPLL_PLL_DISABLE
;
9548 I915_WRITE(LCPLL_CTL
, val
);
9550 if (intel_wait_for_register(dev_priv
,
9551 LCPLL_CTL
, LCPLL_PLL_LOCK
, LCPLL_PLL_LOCK
,
9553 DRM_ERROR("LCPLL not locked yet\n");
9555 if (val
& LCPLL_CD_SOURCE_FCLK
) {
9556 val
= I915_READ(LCPLL_CTL
);
9557 val
&= ~LCPLL_CD_SOURCE_FCLK
;
9558 I915_WRITE(LCPLL_CTL
, val
);
9560 if (wait_for_us((I915_READ(LCPLL_CTL
) &
9561 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
9562 DRM_ERROR("Switching back to LCPLL failed\n");
9565 intel_uncore_forcewake_put(dev_priv
, FORCEWAKE_ALL
);
9566 intel_update_cdclk(&dev_priv
->drm
);
9570 * Package states C8 and deeper are really deep PC states that can only be
9571 * reached when all the devices on the system allow it, so even if the graphics
9572 * device allows PC8+, it doesn't mean the system will actually get to these
9573 * states. Our driver only allows PC8+ when going into runtime PM.
9575 * The requirements for PC8+ are that all the outputs are disabled, the power
9576 * well is disabled and most interrupts are disabled, and these are also
9577 * requirements for runtime PM. When these conditions are met, we manually do
9578 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9579 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9582 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9583 * the state of some registers, so when we come back from PC8+ we need to
9584 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9585 * need to take care of the registers kept by RC6. Notice that this happens even
9586 * if we don't put the device in PCI D3 state (which is what currently happens
9587 * because of the runtime PM support).
9589 * For more, read "Display Sequences for Package C8" on the hardware
9592 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
9594 struct drm_device
*dev
= &dev_priv
->drm
;
9597 DRM_DEBUG_KMS("Enabling package C8+\n");
9599 if (HAS_PCH_LPT_LP(dev
)) {
9600 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
9601 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
9602 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
9605 lpt_disable_clkout_dp(dev
);
9606 hsw_disable_lcpll(dev_priv
, true, true);
9609 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
9611 struct drm_device
*dev
= &dev_priv
->drm
;
9614 DRM_DEBUG_KMS("Disabling package C8+\n");
9616 hsw_restore_lcpll(dev_priv
);
9617 lpt_init_pch_refclk(dev
);
9619 if (HAS_PCH_LPT_LP(dev
)) {
9620 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
9621 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
9622 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
9626 static void bxt_modeset_commit_cdclk(struct drm_atomic_state
*old_state
)
9628 struct drm_device
*dev
= old_state
->dev
;
9629 struct intel_atomic_state
*old_intel_state
=
9630 to_intel_atomic_state(old_state
);
9631 unsigned int req_cdclk
= old_intel_state
->dev_cdclk
;
9633 bxt_set_cdclk(to_i915(dev
), req_cdclk
);
9636 /* compute the max rate for new configuration */
9637 static int ilk_max_pixel_rate(struct drm_atomic_state
*state
)
9639 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
9640 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
9641 struct drm_crtc
*crtc
;
9642 struct drm_crtc_state
*cstate
;
9643 struct intel_crtc_state
*crtc_state
;
9644 unsigned max_pixel_rate
= 0, i
;
9647 memcpy(intel_state
->min_pixclk
, dev_priv
->min_pixclk
,
9648 sizeof(intel_state
->min_pixclk
));
9650 for_each_crtc_in_state(state
, crtc
, cstate
, i
) {
9653 crtc_state
= to_intel_crtc_state(cstate
);
9654 if (!crtc_state
->base
.enable
) {
9655 intel_state
->min_pixclk
[i
] = 0;
9659 pixel_rate
= ilk_pipe_pixel_rate(crtc_state
);
9661 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
9662 if (IS_BROADWELL(dev_priv
) && crtc_state
->ips_enabled
)
9663 pixel_rate
= DIV_ROUND_UP(pixel_rate
* 100, 95);
9665 intel_state
->min_pixclk
[i
] = pixel_rate
;
9668 for_each_pipe(dev_priv
, pipe
)
9669 max_pixel_rate
= max(intel_state
->min_pixclk
[pipe
], max_pixel_rate
);
9671 return max_pixel_rate
;
9674 static void broadwell_set_cdclk(struct drm_device
*dev
, int cdclk
)
9676 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9680 if (WARN((I915_READ(LCPLL_CTL
) &
9681 (LCPLL_PLL_DISABLE
| LCPLL_PLL_LOCK
|
9682 LCPLL_CD_CLOCK_DISABLE
| LCPLL_ROOT_CD_CLOCK_DISABLE
|
9683 LCPLL_CD2X_CLOCK_DISABLE
| LCPLL_POWER_DOWN_ALLOW
|
9684 LCPLL_CD_SOURCE_FCLK
)) != LCPLL_PLL_LOCK
,
9685 "trying to change cdclk frequency with cdclk not enabled\n"))
9688 mutex_lock(&dev_priv
->rps
.hw_lock
);
9689 ret
= sandybridge_pcode_write(dev_priv
,
9690 BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ
, 0x0);
9691 mutex_unlock(&dev_priv
->rps
.hw_lock
);
9693 DRM_ERROR("failed to inform pcode about cdclk change\n");
9697 val
= I915_READ(LCPLL_CTL
);
9698 val
|= LCPLL_CD_SOURCE_FCLK
;
9699 I915_WRITE(LCPLL_CTL
, val
);
9701 if (wait_for_us(I915_READ(LCPLL_CTL
) &
9702 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
9703 DRM_ERROR("Switching to FCLK failed\n");
9705 val
= I915_READ(LCPLL_CTL
);
9706 val
&= ~LCPLL_CLK_FREQ_MASK
;
9710 val
|= LCPLL_CLK_FREQ_450
;
9714 val
|= LCPLL_CLK_FREQ_54O_BDW
;
9718 val
|= LCPLL_CLK_FREQ_337_5_BDW
;
9722 val
|= LCPLL_CLK_FREQ_675_BDW
;
9726 WARN(1, "invalid cdclk frequency\n");
9730 I915_WRITE(LCPLL_CTL
, val
);
9732 val
= I915_READ(LCPLL_CTL
);
9733 val
&= ~LCPLL_CD_SOURCE_FCLK
;
9734 I915_WRITE(LCPLL_CTL
, val
);
9736 if (wait_for_us((I915_READ(LCPLL_CTL
) &
9737 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
9738 DRM_ERROR("Switching back to LCPLL failed\n");
9740 mutex_lock(&dev_priv
->rps
.hw_lock
);
9741 sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
, data
);
9742 mutex_unlock(&dev_priv
->rps
.hw_lock
);
9744 I915_WRITE(CDCLK_FREQ
, DIV_ROUND_CLOSEST(cdclk
, 1000) - 1);
9746 intel_update_cdclk(dev
);
9748 WARN(cdclk
!= dev_priv
->cdclk_freq
,
9749 "cdclk requested %d kHz but got %d kHz\n",
9750 cdclk
, dev_priv
->cdclk_freq
);
9753 static int broadwell_calc_cdclk(int max_pixclk
)
9755 if (max_pixclk
> 540000)
9757 else if (max_pixclk
> 450000)
9759 else if (max_pixclk
> 337500)
9765 static int broadwell_modeset_calc_cdclk(struct drm_atomic_state
*state
)
9767 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
9768 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
9769 int max_pixclk
= ilk_max_pixel_rate(state
);
9773 * FIXME should also account for plane ratio
9774 * once 64bpp pixel formats are supported.
9776 cdclk
= broadwell_calc_cdclk(max_pixclk
);
9778 if (cdclk
> dev_priv
->max_cdclk_freq
) {
9779 DRM_DEBUG_KMS("requested cdclk (%d kHz) exceeds max (%d kHz)\n",
9780 cdclk
, dev_priv
->max_cdclk_freq
);
9784 intel_state
->cdclk
= intel_state
->dev_cdclk
= cdclk
;
9785 if (!intel_state
->active_crtcs
)
9786 intel_state
->dev_cdclk
= broadwell_calc_cdclk(0);
9791 static void broadwell_modeset_commit_cdclk(struct drm_atomic_state
*old_state
)
9793 struct drm_device
*dev
= old_state
->dev
;
9794 struct intel_atomic_state
*old_intel_state
=
9795 to_intel_atomic_state(old_state
);
9796 unsigned req_cdclk
= old_intel_state
->dev_cdclk
;
9798 broadwell_set_cdclk(dev
, req_cdclk
);
9801 static int skl_modeset_calc_cdclk(struct drm_atomic_state
*state
)
9803 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
9804 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
9805 const int max_pixclk
= ilk_max_pixel_rate(state
);
9806 int vco
= intel_state
->cdclk_pll_vco
;
9810 * FIXME should also account for plane ratio
9811 * once 64bpp pixel formats are supported.
9813 cdclk
= skl_calc_cdclk(max_pixclk
, vco
);
9816 * FIXME move the cdclk caclulation to
9817 * compute_config() so we can fail gracegully.
9819 if (cdclk
> dev_priv
->max_cdclk_freq
) {
9820 DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n",
9821 cdclk
, dev_priv
->max_cdclk_freq
);
9822 cdclk
= dev_priv
->max_cdclk_freq
;
9825 intel_state
->cdclk
= intel_state
->dev_cdclk
= cdclk
;
9826 if (!intel_state
->active_crtcs
)
9827 intel_state
->dev_cdclk
= skl_calc_cdclk(0, vco
);
9832 static void skl_modeset_commit_cdclk(struct drm_atomic_state
*old_state
)
9834 struct drm_i915_private
*dev_priv
= to_i915(old_state
->dev
);
9835 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(old_state
);
9836 unsigned int req_cdclk
= intel_state
->dev_cdclk
;
9837 unsigned int req_vco
= intel_state
->cdclk_pll_vco
;
9839 skl_set_cdclk(dev_priv
, req_cdclk
, req_vco
);
9842 static int haswell_crtc_compute_clock(struct intel_crtc
*crtc
,
9843 struct intel_crtc_state
*crtc_state
)
9845 if (!intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DSI
)) {
9846 if (!intel_ddi_pll_select(crtc
, crtc_state
))
9850 crtc
->lowfreq_avail
= false;
9855 static void bxt_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9857 struct intel_crtc_state
*pipe_config
)
9859 enum intel_dpll_id id
;
9863 pipe_config
->ddi_pll_sel
= SKL_DPLL0
;
9864 id
= DPLL_ID_SKL_DPLL0
;
9867 pipe_config
->ddi_pll_sel
= SKL_DPLL1
;
9868 id
= DPLL_ID_SKL_DPLL1
;
9871 pipe_config
->ddi_pll_sel
= SKL_DPLL2
;
9872 id
= DPLL_ID_SKL_DPLL2
;
9875 DRM_ERROR("Incorrect port type\n");
9879 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
9882 static void skylake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9884 struct intel_crtc_state
*pipe_config
)
9886 enum intel_dpll_id id
;
9889 temp
= I915_READ(DPLL_CTRL2
) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port
);
9890 pipe_config
->ddi_pll_sel
= temp
>> (port
* 3 + 1);
9892 switch (pipe_config
->ddi_pll_sel
) {
9894 id
= DPLL_ID_SKL_DPLL0
;
9897 id
= DPLL_ID_SKL_DPLL1
;
9900 id
= DPLL_ID_SKL_DPLL2
;
9903 id
= DPLL_ID_SKL_DPLL3
;
9906 MISSING_CASE(pipe_config
->ddi_pll_sel
);
9910 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
9913 static void haswell_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9915 struct intel_crtc_state
*pipe_config
)
9917 enum intel_dpll_id id
;
9919 pipe_config
->ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
9921 switch (pipe_config
->ddi_pll_sel
) {
9922 case PORT_CLK_SEL_WRPLL1
:
9923 id
= DPLL_ID_WRPLL1
;
9925 case PORT_CLK_SEL_WRPLL2
:
9926 id
= DPLL_ID_WRPLL2
;
9928 case PORT_CLK_SEL_SPLL
:
9931 case PORT_CLK_SEL_LCPLL_810
:
9932 id
= DPLL_ID_LCPLL_810
;
9934 case PORT_CLK_SEL_LCPLL_1350
:
9935 id
= DPLL_ID_LCPLL_1350
;
9937 case PORT_CLK_SEL_LCPLL_2700
:
9938 id
= DPLL_ID_LCPLL_2700
;
9941 MISSING_CASE(pipe_config
->ddi_pll_sel
);
9943 case PORT_CLK_SEL_NONE
:
9947 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
9950 static bool hsw_get_transcoder_state(struct intel_crtc
*crtc
,
9951 struct intel_crtc_state
*pipe_config
,
9952 unsigned long *power_domain_mask
)
9954 struct drm_device
*dev
= crtc
->base
.dev
;
9955 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9956 enum intel_display_power_domain power_domain
;
9960 * The pipe->transcoder mapping is fixed with the exception of the eDP
9961 * transcoder handled below.
9963 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
9966 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9967 * consistency and less surprising code; it's in always on power).
9969 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
9970 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
9971 enum pipe trans_edp_pipe
;
9972 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
9974 WARN(1, "unknown pipe linked to edp transcoder\n");
9975 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
9976 case TRANS_DDI_EDP_INPUT_A_ON
:
9977 trans_edp_pipe
= PIPE_A
;
9979 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
9980 trans_edp_pipe
= PIPE_B
;
9982 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
9983 trans_edp_pipe
= PIPE_C
;
9987 if (trans_edp_pipe
== crtc
->pipe
)
9988 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
9991 power_domain
= POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
);
9992 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9994 *power_domain_mask
|= BIT(power_domain
);
9996 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
9998 return tmp
& PIPECONF_ENABLE
;
10001 static bool bxt_get_dsi_transcoder_state(struct intel_crtc
*crtc
,
10002 struct intel_crtc_state
*pipe_config
,
10003 unsigned long *power_domain_mask
)
10005 struct drm_device
*dev
= crtc
->base
.dev
;
10006 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10007 enum intel_display_power_domain power_domain
;
10009 enum transcoder cpu_transcoder
;
10012 for_each_port_masked(port
, BIT(PORT_A
) | BIT(PORT_C
)) {
10013 if (port
== PORT_A
)
10014 cpu_transcoder
= TRANSCODER_DSI_A
;
10016 cpu_transcoder
= TRANSCODER_DSI_C
;
10018 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
10019 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
10021 *power_domain_mask
|= BIT(power_domain
);
10024 * The PLL needs to be enabled with a valid divider
10025 * configuration, otherwise accessing DSI registers will hang
10026 * the machine. See BSpec North Display Engine
10027 * registers/MIPI[BXT]. We can break out here early, since we
10028 * need the same DSI PLL to be enabled for both DSI ports.
10030 if (!intel_dsi_pll_is_enabled(dev_priv
))
10033 /* XXX: this works for video mode only */
10034 tmp
= I915_READ(BXT_MIPI_PORT_CTRL(port
));
10035 if (!(tmp
& DPI_ENABLE
))
10038 tmp
= I915_READ(MIPI_CTRL(port
));
10039 if ((tmp
& BXT_PIPE_SELECT_MASK
) != BXT_PIPE_SELECT(crtc
->pipe
))
10042 pipe_config
->cpu_transcoder
= cpu_transcoder
;
10046 return transcoder_is_dsi(pipe_config
->cpu_transcoder
);
10049 static void haswell_get_ddi_port_state(struct intel_crtc
*crtc
,
10050 struct intel_crtc_state
*pipe_config
)
10052 struct drm_device
*dev
= crtc
->base
.dev
;
10053 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10054 struct intel_shared_dpll
*pll
;
10058 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
10060 port
= (tmp
& TRANS_DDI_PORT_MASK
) >> TRANS_DDI_PORT_SHIFT
;
10062 if (IS_SKYLAKE(dev
) || IS_KABYLAKE(dev
))
10063 skylake_get_ddi_pll(dev_priv
, port
, pipe_config
);
10064 else if (IS_BROXTON(dev
))
10065 bxt_get_ddi_pll(dev_priv
, port
, pipe_config
);
10067 haswell_get_ddi_pll(dev_priv
, port
, pipe_config
);
10069 pll
= pipe_config
->shared_dpll
;
10071 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
10072 &pipe_config
->dpll_hw_state
));
10076 * Haswell has only FDI/PCH transcoder A. It is which is connected to
10077 * DDI E. So just check whether this pipe is wired to DDI E and whether
10078 * the PCH transcoder is on.
10080 if (INTEL_INFO(dev
)->gen
< 9 &&
10081 (port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
10082 pipe_config
->has_pch_encoder
= true;
10084 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
10085 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
10086 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
10088 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
10092 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
10093 struct intel_crtc_state
*pipe_config
)
10095 struct drm_device
*dev
= crtc
->base
.dev
;
10096 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10097 enum intel_display_power_domain power_domain
;
10098 unsigned long power_domain_mask
;
10101 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
10102 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
10104 power_domain_mask
= BIT(power_domain
);
10106 pipe_config
->shared_dpll
= NULL
;
10108 active
= hsw_get_transcoder_state(crtc
, pipe_config
, &power_domain_mask
);
10110 if (IS_BROXTON(dev_priv
) &&
10111 bxt_get_dsi_transcoder_state(crtc
, pipe_config
, &power_domain_mask
)) {
10119 if (!transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
10120 haswell_get_ddi_port_state(crtc
, pipe_config
);
10121 intel_get_pipe_timings(crtc
, pipe_config
);
10124 intel_get_pipe_src_size(crtc
, pipe_config
);
10126 pipe_config
->gamma_mode
=
10127 I915_READ(GAMMA_MODE(crtc
->pipe
)) & GAMMA_MODE_MODE_MASK
;
10129 if (INTEL_INFO(dev
)->gen
>= 9) {
10130 skl_init_scalers(dev
, crtc
, pipe_config
);
10133 if (INTEL_INFO(dev
)->gen
>= 9) {
10134 pipe_config
->scaler_state
.scaler_id
= -1;
10135 pipe_config
->scaler_state
.scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
10138 power_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
10139 if (intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
10140 power_domain_mask
|= BIT(power_domain
);
10141 if (INTEL_INFO(dev
)->gen
>= 9)
10142 skylake_get_pfit_config(crtc
, pipe_config
);
10144 ironlake_get_pfit_config(crtc
, pipe_config
);
10147 if (IS_HASWELL(dev
))
10148 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
10149 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
10151 if (pipe_config
->cpu_transcoder
!= TRANSCODER_EDP
&&
10152 !transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
10153 pipe_config
->pixel_multiplier
=
10154 I915_READ(PIPE_MULT(pipe_config
->cpu_transcoder
)) + 1;
10156 pipe_config
->pixel_multiplier
= 1;
10160 for_each_power_domain(power_domain
, power_domain_mask
)
10161 intel_display_power_put(dev_priv
, power_domain
);
10166 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
,
10167 const struct intel_plane_state
*plane_state
)
10169 struct drm_device
*dev
= crtc
->dev
;
10170 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10171 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10172 uint32_t cntl
= 0, size
= 0;
10174 if (plane_state
&& plane_state
->visible
) {
10175 unsigned int width
= plane_state
->base
.crtc_w
;
10176 unsigned int height
= plane_state
->base
.crtc_h
;
10177 unsigned int stride
= roundup_pow_of_two(width
) * 4;
10181 WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
10192 cntl
|= CURSOR_ENABLE
|
10193 CURSOR_GAMMA_ENABLE
|
10194 CURSOR_FORMAT_ARGB
|
10195 CURSOR_STRIDE(stride
);
10197 size
= (height
<< 12) | width
;
10200 if (intel_crtc
->cursor_cntl
!= 0 &&
10201 (intel_crtc
->cursor_base
!= base
||
10202 intel_crtc
->cursor_size
!= size
||
10203 intel_crtc
->cursor_cntl
!= cntl
)) {
10204 /* On these chipsets we can only modify the base/size/stride
10205 * whilst the cursor is disabled.
10207 I915_WRITE(CURCNTR(PIPE_A
), 0);
10208 POSTING_READ(CURCNTR(PIPE_A
));
10209 intel_crtc
->cursor_cntl
= 0;
10212 if (intel_crtc
->cursor_base
!= base
) {
10213 I915_WRITE(CURBASE(PIPE_A
), base
);
10214 intel_crtc
->cursor_base
= base
;
10217 if (intel_crtc
->cursor_size
!= size
) {
10218 I915_WRITE(CURSIZE
, size
);
10219 intel_crtc
->cursor_size
= size
;
10222 if (intel_crtc
->cursor_cntl
!= cntl
) {
10223 I915_WRITE(CURCNTR(PIPE_A
), cntl
);
10224 POSTING_READ(CURCNTR(PIPE_A
));
10225 intel_crtc
->cursor_cntl
= cntl
;
10229 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
,
10230 const struct intel_plane_state
*plane_state
)
10232 struct drm_device
*dev
= crtc
->dev
;
10233 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10234 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10235 int pipe
= intel_crtc
->pipe
;
10238 if (plane_state
&& plane_state
->visible
) {
10239 cntl
= MCURSOR_GAMMA_ENABLE
;
10240 switch (plane_state
->base
.crtc_w
) {
10242 cntl
|= CURSOR_MODE_64_ARGB_AX
;
10245 cntl
|= CURSOR_MODE_128_ARGB_AX
;
10248 cntl
|= CURSOR_MODE_256_ARGB_AX
;
10251 MISSING_CASE(plane_state
->base
.crtc_w
);
10254 cntl
|= pipe
<< 28; /* Connect to correct pipe */
10257 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
10259 if (plane_state
->base
.rotation
== BIT(DRM_ROTATE_180
))
10260 cntl
|= CURSOR_ROTATE_180
;
10263 if (intel_crtc
->cursor_cntl
!= cntl
) {
10264 I915_WRITE(CURCNTR(pipe
), cntl
);
10265 POSTING_READ(CURCNTR(pipe
));
10266 intel_crtc
->cursor_cntl
= cntl
;
10269 /* and commit changes on next vblank */
10270 I915_WRITE(CURBASE(pipe
), base
);
10271 POSTING_READ(CURBASE(pipe
));
10273 intel_crtc
->cursor_base
= base
;
10276 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
10277 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
10278 const struct intel_plane_state
*plane_state
)
10280 struct drm_device
*dev
= crtc
->dev
;
10281 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10282 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10283 int pipe
= intel_crtc
->pipe
;
10284 u32 base
= intel_crtc
->cursor_addr
;
10288 int x
= plane_state
->base
.crtc_x
;
10289 int y
= plane_state
->base
.crtc_y
;
10292 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
10295 pos
|= x
<< CURSOR_X_SHIFT
;
10298 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
10301 pos
|= y
<< CURSOR_Y_SHIFT
;
10303 /* ILK+ do this automagically */
10304 if (HAS_GMCH_DISPLAY(dev
) &&
10305 plane_state
->base
.rotation
== BIT(DRM_ROTATE_180
)) {
10306 base
+= (plane_state
->base
.crtc_h
*
10307 plane_state
->base
.crtc_w
- 1) * 4;
10311 I915_WRITE(CURPOS(pipe
), pos
);
10313 if (IS_845G(dev
) || IS_I865G(dev
))
10314 i845_update_cursor(crtc
, base
, plane_state
);
10316 i9xx_update_cursor(crtc
, base
, plane_state
);
10319 static bool cursor_size_ok(struct drm_device
*dev
,
10320 uint32_t width
, uint32_t height
)
10322 if (width
== 0 || height
== 0)
10326 * 845g/865g are special in that they are only limited by
10327 * the width of their cursors, the height is arbitrary up to
10328 * the precision of the register. Everything else requires
10329 * square cursors, limited to a few power-of-two sizes.
10331 if (IS_845G(dev
) || IS_I865G(dev
)) {
10332 if ((width
& 63) != 0)
10335 if (width
> (IS_845G(dev
) ? 64 : 512))
10341 switch (width
| height
) {
10356 /* VESA 640x480x72Hz mode to set on the pipe */
10357 static struct drm_display_mode load_detect_mode
= {
10358 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
10359 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
10362 struct drm_framebuffer
*
10363 __intel_framebuffer_create(struct drm_device
*dev
,
10364 struct drm_mode_fb_cmd2
*mode_cmd
,
10365 struct drm_i915_gem_object
*obj
)
10367 struct intel_framebuffer
*intel_fb
;
10370 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
10372 return ERR_PTR(-ENOMEM
);
10374 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
10378 return &intel_fb
->base
;
10382 return ERR_PTR(ret
);
10385 static struct drm_framebuffer
*
10386 intel_framebuffer_create(struct drm_device
*dev
,
10387 struct drm_mode_fb_cmd2
*mode_cmd
,
10388 struct drm_i915_gem_object
*obj
)
10390 struct drm_framebuffer
*fb
;
10393 ret
= i915_mutex_lock_interruptible(dev
);
10395 return ERR_PTR(ret
);
10396 fb
= __intel_framebuffer_create(dev
, mode_cmd
, obj
);
10397 mutex_unlock(&dev
->struct_mutex
);
10403 intel_framebuffer_pitch_for_width(int width
, int bpp
)
10405 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
10406 return ALIGN(pitch
, 64);
10410 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
10412 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
10413 return PAGE_ALIGN(pitch
* mode
->vdisplay
);
10416 static struct drm_framebuffer
*
10417 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
10418 struct drm_display_mode
*mode
,
10419 int depth
, int bpp
)
10421 struct drm_framebuffer
*fb
;
10422 struct drm_i915_gem_object
*obj
;
10423 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
10425 obj
= i915_gem_object_create(dev
,
10426 intel_framebuffer_size_for_mode(mode
, bpp
));
10428 return ERR_CAST(obj
);
10430 mode_cmd
.width
= mode
->hdisplay
;
10431 mode_cmd
.height
= mode
->vdisplay
;
10432 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
10434 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
10436 fb
= intel_framebuffer_create(dev
, &mode_cmd
, obj
);
10438 i915_gem_object_put_unlocked(obj
);
10443 static struct drm_framebuffer
*
10444 mode_fits_in_fbdev(struct drm_device
*dev
,
10445 struct drm_display_mode
*mode
)
10447 #ifdef CONFIG_DRM_FBDEV_EMULATION
10448 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10449 struct drm_i915_gem_object
*obj
;
10450 struct drm_framebuffer
*fb
;
10452 if (!dev_priv
->fbdev
)
10455 if (!dev_priv
->fbdev
->fb
)
10458 obj
= dev_priv
->fbdev
->fb
->obj
;
10461 fb
= &dev_priv
->fbdev
->fb
->base
;
10462 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
10463 fb
->bits_per_pixel
))
10466 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
10469 drm_framebuffer_reference(fb
);
10476 static int intel_modeset_setup_plane_state(struct drm_atomic_state
*state
,
10477 struct drm_crtc
*crtc
,
10478 struct drm_display_mode
*mode
,
10479 struct drm_framebuffer
*fb
,
10482 struct drm_plane_state
*plane_state
;
10483 int hdisplay
, vdisplay
;
10486 plane_state
= drm_atomic_get_plane_state(state
, crtc
->primary
);
10487 if (IS_ERR(plane_state
))
10488 return PTR_ERR(plane_state
);
10491 drm_crtc_get_hv_timing(mode
, &hdisplay
, &vdisplay
);
10493 hdisplay
= vdisplay
= 0;
10495 ret
= drm_atomic_set_crtc_for_plane(plane_state
, fb
? crtc
: NULL
);
10498 drm_atomic_set_fb_for_plane(plane_state
, fb
);
10499 plane_state
->crtc_x
= 0;
10500 plane_state
->crtc_y
= 0;
10501 plane_state
->crtc_w
= hdisplay
;
10502 plane_state
->crtc_h
= vdisplay
;
10503 plane_state
->src_x
= x
<< 16;
10504 plane_state
->src_y
= y
<< 16;
10505 plane_state
->src_w
= hdisplay
<< 16;
10506 plane_state
->src_h
= vdisplay
<< 16;
10511 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
10512 struct drm_display_mode
*mode
,
10513 struct intel_load_detect_pipe
*old
,
10514 struct drm_modeset_acquire_ctx
*ctx
)
10516 struct intel_crtc
*intel_crtc
;
10517 struct intel_encoder
*intel_encoder
=
10518 intel_attached_encoder(connector
);
10519 struct drm_crtc
*possible_crtc
;
10520 struct drm_encoder
*encoder
= &intel_encoder
->base
;
10521 struct drm_crtc
*crtc
= NULL
;
10522 struct drm_device
*dev
= encoder
->dev
;
10523 struct drm_framebuffer
*fb
;
10524 struct drm_mode_config
*config
= &dev
->mode_config
;
10525 struct drm_atomic_state
*state
= NULL
, *restore_state
= NULL
;
10526 struct drm_connector_state
*connector_state
;
10527 struct intel_crtc_state
*crtc_state
;
10530 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10531 connector
->base
.id
, connector
->name
,
10532 encoder
->base
.id
, encoder
->name
);
10534 old
->restore_state
= NULL
;
10537 ret
= drm_modeset_lock(&config
->connection_mutex
, ctx
);
10542 * Algorithm gets a little messy:
10544 * - if the connector already has an assigned crtc, use it (but make
10545 * sure it's on first)
10547 * - try to find the first unused crtc that can drive this connector,
10548 * and use that if we find one
10551 /* See if we already have a CRTC for this connector */
10552 if (connector
->state
->crtc
) {
10553 crtc
= connector
->state
->crtc
;
10555 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
10559 /* Make sure the crtc and connector are running */
10563 /* Find an unused one (if possible) */
10564 for_each_crtc(dev
, possible_crtc
) {
10566 if (!(encoder
->possible_crtcs
& (1 << i
)))
10569 ret
= drm_modeset_lock(&possible_crtc
->mutex
, ctx
);
10573 if (possible_crtc
->state
->enable
) {
10574 drm_modeset_unlock(&possible_crtc
->mutex
);
10578 crtc
= possible_crtc
;
10583 * If we didn't find an unused CRTC, don't use any.
10586 DRM_DEBUG_KMS("no pipe available for load-detect\n");
10591 intel_crtc
= to_intel_crtc(crtc
);
10593 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
10597 state
= drm_atomic_state_alloc(dev
);
10598 restore_state
= drm_atomic_state_alloc(dev
);
10599 if (!state
|| !restore_state
) {
10604 state
->acquire_ctx
= ctx
;
10605 restore_state
->acquire_ctx
= ctx
;
10607 connector_state
= drm_atomic_get_connector_state(state
, connector
);
10608 if (IS_ERR(connector_state
)) {
10609 ret
= PTR_ERR(connector_state
);
10613 ret
= drm_atomic_set_crtc_for_connector(connector_state
, crtc
);
10617 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
10618 if (IS_ERR(crtc_state
)) {
10619 ret
= PTR_ERR(crtc_state
);
10623 crtc_state
->base
.active
= crtc_state
->base
.enable
= true;
10626 mode
= &load_detect_mode
;
10628 /* We need a framebuffer large enough to accommodate all accesses
10629 * that the plane may generate whilst we perform load detection.
10630 * We can not rely on the fbcon either being present (we get called
10631 * during its initialisation to detect all boot displays, or it may
10632 * not even exist) or that it is large enough to satisfy the
10635 fb
= mode_fits_in_fbdev(dev
, mode
);
10637 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
10638 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
10640 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
10642 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
10646 ret
= intel_modeset_setup_plane_state(state
, crtc
, mode
, fb
, 0, 0);
10650 drm_framebuffer_unreference(fb
);
10652 ret
= drm_atomic_set_mode_for_crtc(&crtc_state
->base
, mode
);
10656 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state
, connector
));
10658 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state
, crtc
));
10660 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state
, crtc
->primary
));
10662 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret
);
10666 ret
= drm_atomic_commit(state
);
10668 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
10672 old
->restore_state
= restore_state
;
10674 /* let the connector get through one full cycle before testing */
10675 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
10679 drm_atomic_state_free(state
);
10680 drm_atomic_state_free(restore_state
);
10681 restore_state
= state
= NULL
;
10683 if (ret
== -EDEADLK
) {
10684 drm_modeset_backoff(ctx
);
10691 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
10692 struct intel_load_detect_pipe
*old
,
10693 struct drm_modeset_acquire_ctx
*ctx
)
10695 struct intel_encoder
*intel_encoder
=
10696 intel_attached_encoder(connector
);
10697 struct drm_encoder
*encoder
= &intel_encoder
->base
;
10698 struct drm_atomic_state
*state
= old
->restore_state
;
10701 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10702 connector
->base
.id
, connector
->name
,
10703 encoder
->base
.id
, encoder
->name
);
10708 ret
= drm_atomic_commit(state
);
10710 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret
);
10711 drm_atomic_state_free(state
);
10715 static int i9xx_pll_refclk(struct drm_device
*dev
,
10716 const struct intel_crtc_state
*pipe_config
)
10718 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10719 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
10721 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
10722 return dev_priv
->vbt
.lvds_ssc_freq
;
10723 else if (HAS_PCH_SPLIT(dev
))
10725 else if (!IS_GEN2(dev
))
10731 /* Returns the clock of the currently programmed mode of the given pipe. */
10732 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
10733 struct intel_crtc_state
*pipe_config
)
10735 struct drm_device
*dev
= crtc
->base
.dev
;
10736 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10737 int pipe
= pipe_config
->cpu_transcoder
;
10738 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
10742 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
10744 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
10745 fp
= pipe_config
->dpll_hw_state
.fp0
;
10747 fp
= pipe_config
->dpll_hw_state
.fp1
;
10749 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
10750 if (IS_PINEVIEW(dev
)) {
10751 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
10752 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
10754 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
10755 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
10758 if (!IS_GEN2(dev
)) {
10759 if (IS_PINEVIEW(dev
))
10760 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
10761 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
10763 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
10764 DPLL_FPA01_P1_POST_DIV_SHIFT
);
10766 switch (dpll
& DPLL_MODE_MASK
) {
10767 case DPLLB_MODE_DAC_SERIAL
:
10768 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
10771 case DPLLB_MODE_LVDS
:
10772 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
10776 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10777 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
10781 if (IS_PINEVIEW(dev
))
10782 port_clock
= pnv_calc_dpll_params(refclk
, &clock
);
10784 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
10786 u32 lvds
= IS_I830(dev
) ? 0 : I915_READ(LVDS
);
10787 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
10790 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
10791 DPLL_FPA01_P1_POST_DIV_SHIFT
);
10793 if (lvds
& LVDS_CLKB_POWER_UP
)
10798 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
10801 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
10802 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
10804 if (dpll
& PLL_P2_DIVIDE_BY_4
)
10810 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
10814 * This value includes pixel_multiplier. We will use
10815 * port_clock to compute adjusted_mode.crtc_clock in the
10816 * encoder's get_config() function.
10818 pipe_config
->port_clock
= port_clock
;
10821 int intel_dotclock_calculate(int link_freq
,
10822 const struct intel_link_m_n
*m_n
)
10825 * The calculation for the data clock is:
10826 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10827 * But we want to avoid losing precison if possible, so:
10828 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10830 * and the link clock is simpler:
10831 * link_clock = (m * link_clock) / n
10837 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
10840 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
10841 struct intel_crtc_state
*pipe_config
)
10843 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
10845 /* read out port_clock from the DPLL */
10846 i9xx_crtc_clock_get(crtc
, pipe_config
);
10849 * In case there is an active pipe without active ports,
10850 * we may need some idea for the dotclock anyway.
10851 * Calculate one based on the FDI configuration.
10853 pipe_config
->base
.adjusted_mode
.crtc_clock
=
10854 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
10855 &pipe_config
->fdi_m_n
);
10858 /** Returns the currently programmed mode of the given pipe. */
10859 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
10860 struct drm_crtc
*crtc
)
10862 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10863 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10864 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
10865 struct drm_display_mode
*mode
;
10866 struct intel_crtc_state
*pipe_config
;
10867 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
10868 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
10869 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
10870 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
10871 enum pipe pipe
= intel_crtc
->pipe
;
10873 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
10877 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
10878 if (!pipe_config
) {
10884 * Construct a pipe_config sufficient for getting the clock info
10885 * back out of crtc_clock_get.
10887 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
10888 * to use a real value here instead.
10890 pipe_config
->cpu_transcoder
= (enum transcoder
) pipe
;
10891 pipe_config
->pixel_multiplier
= 1;
10892 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
10893 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
10894 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
10895 i9xx_crtc_clock_get(intel_crtc
, pipe_config
);
10897 mode
->clock
= pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
10898 mode
->hdisplay
= (htot
& 0xffff) + 1;
10899 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
10900 mode
->hsync_start
= (hsync
& 0xffff) + 1;
10901 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
10902 mode
->vdisplay
= (vtot
& 0xffff) + 1;
10903 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
10904 mode
->vsync_start
= (vsync
& 0xffff) + 1;
10905 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
10907 drm_mode_set_name(mode
);
10909 kfree(pipe_config
);
10914 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
10916 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10917 struct drm_device
*dev
= crtc
->dev
;
10918 struct intel_flip_work
*work
;
10920 spin_lock_irq(&dev
->event_lock
);
10921 work
= intel_crtc
->flip_work
;
10922 intel_crtc
->flip_work
= NULL
;
10923 spin_unlock_irq(&dev
->event_lock
);
10926 cancel_work_sync(&work
->mmio_work
);
10927 cancel_work_sync(&work
->unpin_work
);
10931 drm_crtc_cleanup(crtc
);
10936 static void intel_unpin_work_fn(struct work_struct
*__work
)
10938 struct intel_flip_work
*work
=
10939 container_of(__work
, struct intel_flip_work
, unpin_work
);
10940 struct intel_crtc
*crtc
= to_intel_crtc(work
->crtc
);
10941 struct drm_device
*dev
= crtc
->base
.dev
;
10942 struct drm_plane
*primary
= crtc
->base
.primary
;
10944 if (is_mmio_work(work
))
10945 flush_work(&work
->mmio_work
);
10947 mutex_lock(&dev
->struct_mutex
);
10948 intel_unpin_fb_obj(work
->old_fb
, primary
->state
->rotation
);
10949 i915_gem_object_put(work
->pending_flip_obj
);
10950 mutex_unlock(&dev
->struct_mutex
);
10952 i915_gem_request_put(work
->flip_queued_req
);
10954 intel_frontbuffer_flip_complete(dev
, to_intel_plane(primary
)->frontbuffer_bit
);
10955 intel_fbc_post_update(crtc
);
10956 drm_framebuffer_unreference(work
->old_fb
);
10958 BUG_ON(atomic_read(&crtc
->unpin_work_count
) == 0);
10959 atomic_dec(&crtc
->unpin_work_count
);
10964 /* Is 'a' after or equal to 'b'? */
10965 static bool g4x_flip_count_after_eq(u32 a
, u32 b
)
10967 return !((a
- b
) & 0x80000000);
10970 static bool __pageflip_finished_cs(struct intel_crtc
*crtc
,
10971 struct intel_flip_work
*work
)
10973 struct drm_device
*dev
= crtc
->base
.dev
;
10974 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10975 unsigned reset_counter
;
10977 reset_counter
= i915_reset_counter(&dev_priv
->gpu_error
);
10978 if (crtc
->reset_counter
!= reset_counter
)
10982 * The relevant registers doen't exist on pre-ctg.
10983 * As the flip done interrupt doesn't trigger for mmio
10984 * flips on gmch platforms, a flip count check isn't
10985 * really needed there. But since ctg has the registers,
10986 * include it in the check anyway.
10988 if (INTEL_INFO(dev
)->gen
< 5 && !IS_G4X(dev
))
10992 * BDW signals flip done immediately if the plane
10993 * is disabled, even if the plane enable is already
10994 * armed to occur at the next vblank :(
10998 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
10999 * used the same base address. In that case the mmio flip might
11000 * have completed, but the CS hasn't even executed the flip yet.
11002 * A flip count check isn't enough as the CS might have updated
11003 * the base address just after start of vblank, but before we
11004 * managed to process the interrupt. This means we'd complete the
11005 * CS flip too soon.
11007 * Combining both checks should get us a good enough result. It may
11008 * still happen that the CS flip has been executed, but has not
11009 * yet actually completed. But in case the base address is the same
11010 * anyway, we don't really care.
11012 return (I915_READ(DSPSURFLIVE(crtc
->plane
)) & ~0xfff) ==
11013 crtc
->flip_work
->gtt_offset
&&
11014 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc
->pipe
)),
11015 crtc
->flip_work
->flip_count
);
11019 __pageflip_finished_mmio(struct intel_crtc
*crtc
,
11020 struct intel_flip_work
*work
)
11023 * MMIO work completes when vblank is different from
11024 * flip_queued_vblank.
11026 * Reset counter value doesn't matter, this is handled by
11027 * i915_wait_request finishing early, so no need to handle
11030 return intel_crtc_get_vblank_counter(crtc
) != work
->flip_queued_vblank
;
11034 static bool pageflip_finished(struct intel_crtc
*crtc
,
11035 struct intel_flip_work
*work
)
11037 if (!atomic_read(&work
->pending
))
11042 if (is_mmio_work(work
))
11043 return __pageflip_finished_mmio(crtc
, work
);
11045 return __pageflip_finished_cs(crtc
, work
);
11048 void intel_finish_page_flip_cs(struct drm_i915_private
*dev_priv
, int pipe
)
11050 struct drm_device
*dev
= &dev_priv
->drm
;
11051 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
11052 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11053 struct intel_flip_work
*work
;
11054 unsigned long flags
;
11056 /* Ignore early vblank irqs */
11061 * This is called both by irq handlers and the reset code (to complete
11062 * lost pageflips) so needs the full irqsave spinlocks.
11064 spin_lock_irqsave(&dev
->event_lock
, flags
);
11065 work
= intel_crtc
->flip_work
;
11067 if (work
!= NULL
&&
11068 !is_mmio_work(work
) &&
11069 pageflip_finished(intel_crtc
, work
))
11070 page_flip_completed(intel_crtc
);
11072 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
11075 void intel_finish_page_flip_mmio(struct drm_i915_private
*dev_priv
, int pipe
)
11077 struct drm_device
*dev
= &dev_priv
->drm
;
11078 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
11079 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11080 struct intel_flip_work
*work
;
11081 unsigned long flags
;
11083 /* Ignore early vblank irqs */
11088 * This is called both by irq handlers and the reset code (to complete
11089 * lost pageflips) so needs the full irqsave spinlocks.
11091 spin_lock_irqsave(&dev
->event_lock
, flags
);
11092 work
= intel_crtc
->flip_work
;
11094 if (work
!= NULL
&&
11095 is_mmio_work(work
) &&
11096 pageflip_finished(intel_crtc
, work
))
11097 page_flip_completed(intel_crtc
);
11099 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
11102 static inline void intel_mark_page_flip_active(struct intel_crtc
*crtc
,
11103 struct intel_flip_work
*work
)
11105 work
->flip_queued_vblank
= intel_crtc_get_vblank_counter(crtc
);
11107 /* Ensure that the work item is consistent when activating it ... */
11108 smp_mb__before_atomic();
11109 atomic_set(&work
->pending
, 1);
11112 static int intel_gen2_queue_flip(struct drm_device
*dev
,
11113 struct drm_crtc
*crtc
,
11114 struct drm_framebuffer
*fb
,
11115 struct drm_i915_gem_object
*obj
,
11116 struct drm_i915_gem_request
*req
,
11119 struct intel_ring
*ring
= req
->ring
;
11120 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11124 ret
= intel_ring_begin(req
, 6);
11128 /* Can't queue multiple flips, so wait for the previous
11129 * one to finish before executing the next.
11131 if (intel_crtc
->plane
)
11132 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
11134 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
11135 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
11136 intel_ring_emit(ring
, MI_NOOP
);
11137 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
11138 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
11139 intel_ring_emit(ring
, fb
->pitches
[0]);
11140 intel_ring_emit(ring
, intel_crtc
->flip_work
->gtt_offset
);
11141 intel_ring_emit(ring
, 0); /* aux display base address, unused */
11146 static int intel_gen3_queue_flip(struct drm_device
*dev
,
11147 struct drm_crtc
*crtc
,
11148 struct drm_framebuffer
*fb
,
11149 struct drm_i915_gem_object
*obj
,
11150 struct drm_i915_gem_request
*req
,
11153 struct intel_ring
*ring
= req
->ring
;
11154 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11158 ret
= intel_ring_begin(req
, 6);
11162 if (intel_crtc
->plane
)
11163 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
11165 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
11166 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
11167 intel_ring_emit(ring
, MI_NOOP
);
11168 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
|
11169 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
11170 intel_ring_emit(ring
, fb
->pitches
[0]);
11171 intel_ring_emit(ring
, intel_crtc
->flip_work
->gtt_offset
);
11172 intel_ring_emit(ring
, MI_NOOP
);
11177 static int intel_gen4_queue_flip(struct drm_device
*dev
,
11178 struct drm_crtc
*crtc
,
11179 struct drm_framebuffer
*fb
,
11180 struct drm_i915_gem_object
*obj
,
11181 struct drm_i915_gem_request
*req
,
11184 struct intel_ring
*ring
= req
->ring
;
11185 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11186 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11187 uint32_t pf
, pipesrc
;
11190 ret
= intel_ring_begin(req
, 4);
11194 /* i965+ uses the linear or tiled offsets from the
11195 * Display Registers (which do not change across a page-flip)
11196 * so we need only reprogram the base address.
11198 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
11199 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
11200 intel_ring_emit(ring
, fb
->pitches
[0]);
11201 intel_ring_emit(ring
, intel_crtc
->flip_work
->gtt_offset
|
11204 /* XXX Enabling the panel-fitter across page-flip is so far
11205 * untested on non-native modes, so ignore it for now.
11206 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
11209 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
11210 intel_ring_emit(ring
, pf
| pipesrc
);
11215 static int intel_gen6_queue_flip(struct drm_device
*dev
,
11216 struct drm_crtc
*crtc
,
11217 struct drm_framebuffer
*fb
,
11218 struct drm_i915_gem_object
*obj
,
11219 struct drm_i915_gem_request
*req
,
11222 struct intel_ring
*ring
= req
->ring
;
11223 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11224 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11225 uint32_t pf
, pipesrc
;
11228 ret
= intel_ring_begin(req
, 4);
11232 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
11233 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
11234 intel_ring_emit(ring
, fb
->pitches
[0] | obj
->tiling_mode
);
11235 intel_ring_emit(ring
, intel_crtc
->flip_work
->gtt_offset
);
11237 /* Contrary to the suggestions in the documentation,
11238 * "Enable Panel Fitter" does not seem to be required when page
11239 * flipping with a non-native mode, and worse causes a normal
11241 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
11244 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
11245 intel_ring_emit(ring
, pf
| pipesrc
);
11250 static int intel_gen7_queue_flip(struct drm_device
*dev
,
11251 struct drm_crtc
*crtc
,
11252 struct drm_framebuffer
*fb
,
11253 struct drm_i915_gem_object
*obj
,
11254 struct drm_i915_gem_request
*req
,
11257 struct intel_ring
*ring
= req
->ring
;
11258 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11259 uint32_t plane_bit
= 0;
11262 switch (intel_crtc
->plane
) {
11264 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
11267 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
11270 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
11273 WARN_ONCE(1, "unknown plane in flip command\n");
11278 if (req
->engine
->id
== RCS
) {
11281 * On Gen 8, SRM is now taking an extra dword to accommodate
11282 * 48bits addresses, and we need a NOOP for the batch size to
11290 * BSpec MI_DISPLAY_FLIP for IVB:
11291 * "The full packet must be contained within the same cache line."
11293 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
11294 * cacheline, if we ever start emitting more commands before
11295 * the MI_DISPLAY_FLIP we may need to first emit everything else,
11296 * then do the cacheline alignment, and finally emit the
11299 ret
= intel_ring_cacheline_align(req
);
11303 ret
= intel_ring_begin(req
, len
);
11307 /* Unmask the flip-done completion message. Note that the bspec says that
11308 * we should do this for both the BCS and RCS, and that we must not unmask
11309 * more than one flip event at any time (or ensure that one flip message
11310 * can be sent by waiting for flip-done prior to queueing new flips).
11311 * Experimentation says that BCS works despite DERRMR masking all
11312 * flip-done completion events and that unmasking all planes at once
11313 * for the RCS also doesn't appear to drop events. Setting the DERRMR
11314 * to zero does lead to lockups within MI_DISPLAY_FLIP.
11316 if (req
->engine
->id
== RCS
) {
11317 intel_ring_emit(ring
, MI_LOAD_REGISTER_IMM(1));
11318 intel_ring_emit_reg(ring
, DERRMR
);
11319 intel_ring_emit(ring
, ~(DERRMR_PIPEA_PRI_FLIP_DONE
|
11320 DERRMR_PIPEB_PRI_FLIP_DONE
|
11321 DERRMR_PIPEC_PRI_FLIP_DONE
));
11323 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM_GEN8
|
11324 MI_SRM_LRM_GLOBAL_GTT
);
11326 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM
|
11327 MI_SRM_LRM_GLOBAL_GTT
);
11328 intel_ring_emit_reg(ring
, DERRMR
);
11329 intel_ring_emit(ring
, req
->engine
->scratch
.gtt_offset
+ 256);
11330 if (IS_GEN8(dev
)) {
11331 intel_ring_emit(ring
, 0);
11332 intel_ring_emit(ring
, MI_NOOP
);
11336 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
| plane_bit
);
11337 intel_ring_emit(ring
, (fb
->pitches
[0] | obj
->tiling_mode
));
11338 intel_ring_emit(ring
, intel_crtc
->flip_work
->gtt_offset
);
11339 intel_ring_emit(ring
, (MI_NOOP
));
11344 static bool use_mmio_flip(struct intel_engine_cs
*engine
,
11345 struct drm_i915_gem_object
*obj
)
11347 struct reservation_object
*resv
;
11350 * This is not being used for older platforms, because
11351 * non-availability of flip done interrupt forces us to use
11352 * CS flips. Older platforms derive flip done using some clever
11353 * tricks involving the flip_pending status bits and vblank irqs.
11354 * So using MMIO flips there would disrupt this mechanism.
11357 if (engine
== NULL
)
11360 if (INTEL_GEN(engine
->i915
) < 5)
11363 if (i915
.use_mmio_flip
< 0)
11365 else if (i915
.use_mmio_flip
> 0)
11367 else if (i915
.enable_execlists
)
11370 resv
= i915_gem_object_get_dmabuf_resv(obj
);
11371 if (resv
&& !reservation_object_test_signaled_rcu(resv
, false))
11374 return engine
!= i915_gem_active_get_engine(&obj
->last_write
,
11375 &obj
->base
.dev
->struct_mutex
);
11378 static void skl_do_mmio_flip(struct intel_crtc
*intel_crtc
,
11379 unsigned int rotation
,
11380 struct intel_flip_work
*work
)
11382 struct drm_device
*dev
= intel_crtc
->base
.dev
;
11383 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11384 struct drm_framebuffer
*fb
= intel_crtc
->base
.primary
->fb
;
11385 const enum pipe pipe
= intel_crtc
->pipe
;
11386 u32 ctl
, stride
, tile_height
;
11388 ctl
= I915_READ(PLANE_CTL(pipe
, 0));
11389 ctl
&= ~PLANE_CTL_TILED_MASK
;
11390 switch (fb
->modifier
[0]) {
11391 case DRM_FORMAT_MOD_NONE
:
11393 case I915_FORMAT_MOD_X_TILED
:
11394 ctl
|= PLANE_CTL_TILED_X
;
11396 case I915_FORMAT_MOD_Y_TILED
:
11397 ctl
|= PLANE_CTL_TILED_Y
;
11399 case I915_FORMAT_MOD_Yf_TILED
:
11400 ctl
|= PLANE_CTL_TILED_YF
;
11403 MISSING_CASE(fb
->modifier
[0]);
11407 * The stride is either expressed as a multiple of 64 bytes chunks for
11408 * linear buffers or in number of tiles for tiled buffers.
11410 if (intel_rotation_90_or_270(rotation
)) {
11411 /* stride = Surface height in tiles */
11412 tile_height
= intel_tile_height(dev_priv
, fb
->modifier
[0], 0);
11413 stride
= DIV_ROUND_UP(fb
->height
, tile_height
);
11415 stride
= fb
->pitches
[0] /
11416 intel_fb_stride_alignment(dev_priv
, fb
->modifier
[0],
11421 * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on
11422 * PLANE_SURF updates, the update is then guaranteed to be atomic.
11424 I915_WRITE(PLANE_CTL(pipe
, 0), ctl
);
11425 I915_WRITE(PLANE_STRIDE(pipe
, 0), stride
);
11427 I915_WRITE(PLANE_SURF(pipe
, 0), work
->gtt_offset
);
11428 POSTING_READ(PLANE_SURF(pipe
, 0));
11431 static void ilk_do_mmio_flip(struct intel_crtc
*intel_crtc
,
11432 struct intel_flip_work
*work
)
11434 struct drm_device
*dev
= intel_crtc
->base
.dev
;
11435 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11436 struct intel_framebuffer
*intel_fb
=
11437 to_intel_framebuffer(intel_crtc
->base
.primary
->fb
);
11438 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
11439 i915_reg_t reg
= DSPCNTR(intel_crtc
->plane
);
11442 dspcntr
= I915_READ(reg
);
11444 if (obj
->tiling_mode
!= I915_TILING_NONE
)
11445 dspcntr
|= DISPPLANE_TILED
;
11447 dspcntr
&= ~DISPPLANE_TILED
;
11449 I915_WRITE(reg
, dspcntr
);
11451 I915_WRITE(DSPSURF(intel_crtc
->plane
), work
->gtt_offset
);
11452 POSTING_READ(DSPSURF(intel_crtc
->plane
));
11455 static void intel_mmio_flip_work_func(struct work_struct
*w
)
11457 struct intel_flip_work
*work
=
11458 container_of(w
, struct intel_flip_work
, mmio_work
);
11459 struct intel_crtc
*crtc
= to_intel_crtc(work
->crtc
);
11460 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
11461 struct intel_framebuffer
*intel_fb
=
11462 to_intel_framebuffer(crtc
->base
.primary
->fb
);
11463 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
11464 struct reservation_object
*resv
;
11466 if (work
->flip_queued_req
)
11467 WARN_ON(i915_wait_request(work
->flip_queued_req
,
11471 /* For framebuffer backed by dmabuf, wait for fence */
11472 resv
= i915_gem_object_get_dmabuf_resv(obj
);
11474 WARN_ON(reservation_object_wait_timeout_rcu(resv
, false, false,
11475 MAX_SCHEDULE_TIMEOUT
) < 0);
11477 intel_pipe_update_start(crtc
);
11479 if (INTEL_GEN(dev_priv
) >= 9)
11480 skl_do_mmio_flip(crtc
, work
->rotation
, work
);
11482 /* use_mmio_flip() retricts MMIO flips to ilk+ */
11483 ilk_do_mmio_flip(crtc
, work
);
11485 intel_pipe_update_end(crtc
, work
);
11488 static int intel_default_queue_flip(struct drm_device
*dev
,
11489 struct drm_crtc
*crtc
,
11490 struct drm_framebuffer
*fb
,
11491 struct drm_i915_gem_object
*obj
,
11492 struct drm_i915_gem_request
*req
,
11498 static bool __pageflip_stall_check_cs(struct drm_i915_private
*dev_priv
,
11499 struct intel_crtc
*intel_crtc
,
11500 struct intel_flip_work
*work
)
11504 if (!atomic_read(&work
->pending
))
11509 vblank
= intel_crtc_get_vblank_counter(intel_crtc
);
11510 if (work
->flip_ready_vblank
== 0) {
11511 if (work
->flip_queued_req
&&
11512 !i915_gem_request_completed(work
->flip_queued_req
))
11515 work
->flip_ready_vblank
= vblank
;
11518 if (vblank
- work
->flip_ready_vblank
< 3)
11521 /* Potential stall - if we see that the flip has happened,
11522 * assume a missed interrupt. */
11523 if (INTEL_GEN(dev_priv
) >= 4)
11524 addr
= I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc
->plane
)));
11526 addr
= I915_READ(DSPADDR(intel_crtc
->plane
));
11528 /* There is a potential issue here with a false positive after a flip
11529 * to the same address. We could address this by checking for a
11530 * non-incrementing frame counter.
11532 return addr
== work
->gtt_offset
;
11535 void intel_check_page_flip(struct drm_i915_private
*dev_priv
, int pipe
)
11537 struct drm_device
*dev
= &dev_priv
->drm
;
11538 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
11539 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11540 struct intel_flip_work
*work
;
11542 WARN_ON(!in_interrupt());
11547 spin_lock(&dev
->event_lock
);
11548 work
= intel_crtc
->flip_work
;
11550 if (work
!= NULL
&& !is_mmio_work(work
) &&
11551 __pageflip_stall_check_cs(dev_priv
, intel_crtc
, work
)) {
11553 "Kicking stuck page flip: queued at %d, now %d\n",
11554 work
->flip_queued_vblank
, intel_crtc_get_vblank_counter(intel_crtc
));
11555 page_flip_completed(intel_crtc
);
11559 if (work
!= NULL
&& !is_mmio_work(work
) &&
11560 intel_crtc_get_vblank_counter(intel_crtc
) - work
->flip_queued_vblank
> 1)
11561 intel_queue_rps_boost_for_request(work
->flip_queued_req
);
11562 spin_unlock(&dev
->event_lock
);
11565 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
11566 struct drm_framebuffer
*fb
,
11567 struct drm_pending_vblank_event
*event
,
11568 uint32_t page_flip_flags
)
11570 struct drm_device
*dev
= crtc
->dev
;
11571 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11572 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
11573 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
11574 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11575 struct drm_plane
*primary
= crtc
->primary
;
11576 enum pipe pipe
= intel_crtc
->pipe
;
11577 struct intel_flip_work
*work
;
11578 struct intel_engine_cs
*engine
;
11580 struct drm_i915_gem_request
*request
;
11584 * drm_mode_page_flip_ioctl() should already catch this, but double
11585 * check to be safe. In the future we may enable pageflipping from
11586 * a disabled primary plane.
11588 if (WARN_ON(intel_fb_obj(old_fb
) == NULL
))
11591 /* Can't change pixel format via MI display flips. */
11592 if (fb
->pixel_format
!= crtc
->primary
->fb
->pixel_format
)
11596 * TILEOFF/LINOFF registers can't be changed via MI display flips.
11597 * Note that pitch changes could also affect these register.
11599 if (INTEL_INFO(dev
)->gen
> 3 &&
11600 (fb
->offsets
[0] != crtc
->primary
->fb
->offsets
[0] ||
11601 fb
->pitches
[0] != crtc
->primary
->fb
->pitches
[0]))
11604 if (i915_terminally_wedged(&dev_priv
->gpu_error
))
11607 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
11611 work
->event
= event
;
11613 work
->old_fb
= old_fb
;
11614 INIT_WORK(&work
->unpin_work
, intel_unpin_work_fn
);
11616 ret
= drm_crtc_vblank_get(crtc
);
11620 /* We borrow the event spin lock for protecting flip_work */
11621 spin_lock_irq(&dev
->event_lock
);
11622 if (intel_crtc
->flip_work
) {
11623 /* Before declaring the flip queue wedged, check if
11624 * the hardware completed the operation behind our backs.
11626 if (pageflip_finished(intel_crtc
, intel_crtc
->flip_work
)) {
11627 DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
11628 page_flip_completed(intel_crtc
);
11630 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
11631 spin_unlock_irq(&dev
->event_lock
);
11633 drm_crtc_vblank_put(crtc
);
11638 intel_crtc
->flip_work
= work
;
11639 spin_unlock_irq(&dev
->event_lock
);
11641 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
11642 flush_workqueue(dev_priv
->wq
);
11644 /* Reference the objects for the scheduled work. */
11645 drm_framebuffer_reference(work
->old_fb
);
11647 crtc
->primary
->fb
= fb
;
11648 update_state_fb(crtc
->primary
);
11650 intel_fbc_pre_update(intel_crtc
, intel_crtc
->config
,
11651 to_intel_plane_state(primary
->state
));
11653 work
->pending_flip_obj
= i915_gem_object_get(obj
);
11655 ret
= i915_mutex_lock_interruptible(dev
);
11659 intel_crtc
->reset_counter
= i915_reset_counter(&dev_priv
->gpu_error
);
11660 if (__i915_reset_in_progress_or_wedged(intel_crtc
->reset_counter
)) {
11665 atomic_inc(&intel_crtc
->unpin_work_count
);
11667 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
11668 work
->flip_count
= I915_READ(PIPE_FLIPCOUNT_G4X(pipe
)) + 1;
11670 if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
11671 engine
= &dev_priv
->engine
[BCS
];
11672 if (obj
->tiling_mode
!= intel_fb_obj(work
->old_fb
)->tiling_mode
)
11673 /* vlv: DISPLAY_FLIP fails to change tiling */
11675 } else if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
)) {
11676 engine
= &dev_priv
->engine
[BCS
];
11677 } else if (INTEL_INFO(dev
)->gen
>= 7) {
11678 engine
= i915_gem_active_get_engine(&obj
->last_write
,
11679 &obj
->base
.dev
->struct_mutex
);
11680 if (engine
== NULL
|| engine
->id
!= RCS
)
11681 engine
= &dev_priv
->engine
[BCS
];
11683 engine
= &dev_priv
->engine
[RCS
];
11686 mmio_flip
= use_mmio_flip(engine
, obj
);
11688 ret
= intel_pin_and_fence_fb_obj(fb
, primary
->state
->rotation
);
11690 goto cleanup_pending
;
11692 work
->gtt_offset
= intel_plane_obj_offset(to_intel_plane(primary
),
11694 work
->gtt_offset
+= intel_crtc
->dspaddr_offset
;
11695 work
->rotation
= crtc
->primary
->state
->rotation
;
11698 INIT_WORK(&work
->mmio_work
, intel_mmio_flip_work_func
);
11700 work
->flip_queued_req
= i915_gem_active_get(&obj
->last_write
,
11701 &obj
->base
.dev
->struct_mutex
);
11702 schedule_work(&work
->mmio_work
);
11704 request
= i915_gem_request_alloc(engine
, engine
->last_context
);
11705 if (IS_ERR(request
)) {
11706 ret
= PTR_ERR(request
);
11707 goto cleanup_unpin
;
11710 ret
= i915_gem_object_sync(obj
, request
);
11712 goto cleanup_request
;
11714 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
, request
,
11717 goto cleanup_request
;
11719 intel_mark_page_flip_active(intel_crtc
, work
);
11721 work
->flip_queued_req
= i915_gem_request_get(request
);
11722 i915_add_request_no_flush(request
);
11725 i915_gem_track_fb(intel_fb_obj(old_fb
), obj
,
11726 to_intel_plane(primary
)->frontbuffer_bit
);
11727 mutex_unlock(&dev
->struct_mutex
);
11729 intel_frontbuffer_flip_prepare(dev
,
11730 to_intel_plane(primary
)->frontbuffer_bit
);
11732 trace_i915_flip_request(intel_crtc
->plane
, obj
);
11737 i915_add_request_no_flush(request
);
11739 intel_unpin_fb_obj(fb
, crtc
->primary
->state
->rotation
);
11741 atomic_dec(&intel_crtc
->unpin_work_count
);
11742 mutex_unlock(&dev
->struct_mutex
);
11744 crtc
->primary
->fb
= old_fb
;
11745 update_state_fb(crtc
->primary
);
11747 i915_gem_object_put_unlocked(obj
);
11748 drm_framebuffer_unreference(work
->old_fb
);
11750 spin_lock_irq(&dev
->event_lock
);
11751 intel_crtc
->flip_work
= NULL
;
11752 spin_unlock_irq(&dev
->event_lock
);
11754 drm_crtc_vblank_put(crtc
);
11759 struct drm_atomic_state
*state
;
11760 struct drm_plane_state
*plane_state
;
11763 state
= drm_atomic_state_alloc(dev
);
11766 state
->acquire_ctx
= drm_modeset_legacy_acquire_ctx(crtc
);
11769 plane_state
= drm_atomic_get_plane_state(state
, primary
);
11770 ret
= PTR_ERR_OR_ZERO(plane_state
);
11772 drm_atomic_set_fb_for_plane(plane_state
, fb
);
11774 ret
= drm_atomic_set_crtc_for_plane(plane_state
, crtc
);
11776 ret
= drm_atomic_commit(state
);
11779 if (ret
== -EDEADLK
) {
11780 drm_modeset_backoff(state
->acquire_ctx
);
11781 drm_atomic_state_clear(state
);
11786 drm_atomic_state_free(state
);
11788 if (ret
== 0 && event
) {
11789 spin_lock_irq(&dev
->event_lock
);
11790 drm_crtc_send_vblank_event(crtc
, event
);
11791 spin_unlock_irq(&dev
->event_lock
);
11799 * intel_wm_need_update - Check whether watermarks need updating
11800 * @plane: drm plane
11801 * @state: new plane state
11803 * Check current plane state versus the new one to determine whether
11804 * watermarks need to be recalculated.
11806 * Returns true or false.
11808 static bool intel_wm_need_update(struct drm_plane
*plane
,
11809 struct drm_plane_state
*state
)
11811 struct intel_plane_state
*new = to_intel_plane_state(state
);
11812 struct intel_plane_state
*cur
= to_intel_plane_state(plane
->state
);
11814 /* Update watermarks on tiling or size changes. */
11815 if (new->visible
!= cur
->visible
)
11818 if (!cur
->base
.fb
|| !new->base
.fb
)
11821 if (cur
->base
.fb
->modifier
[0] != new->base
.fb
->modifier
[0] ||
11822 cur
->base
.rotation
!= new->base
.rotation
||
11823 drm_rect_width(&new->src
) != drm_rect_width(&cur
->src
) ||
11824 drm_rect_height(&new->src
) != drm_rect_height(&cur
->src
) ||
11825 drm_rect_width(&new->dst
) != drm_rect_width(&cur
->dst
) ||
11826 drm_rect_height(&new->dst
) != drm_rect_height(&cur
->dst
))
11832 static bool needs_scaling(struct intel_plane_state
*state
)
11834 int src_w
= drm_rect_width(&state
->src
) >> 16;
11835 int src_h
= drm_rect_height(&state
->src
) >> 16;
11836 int dst_w
= drm_rect_width(&state
->dst
);
11837 int dst_h
= drm_rect_height(&state
->dst
);
11839 return (src_w
!= dst_w
|| src_h
!= dst_h
);
11842 int intel_plane_atomic_calc_changes(struct drm_crtc_state
*crtc_state
,
11843 struct drm_plane_state
*plane_state
)
11845 struct intel_crtc_state
*pipe_config
= to_intel_crtc_state(crtc_state
);
11846 struct drm_crtc
*crtc
= crtc_state
->crtc
;
11847 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11848 struct drm_plane
*plane
= plane_state
->plane
;
11849 struct drm_device
*dev
= crtc
->dev
;
11850 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11851 struct intel_plane_state
*old_plane_state
=
11852 to_intel_plane_state(plane
->state
);
11853 bool mode_changed
= needs_modeset(crtc_state
);
11854 bool was_crtc_enabled
= crtc
->state
->active
;
11855 bool is_crtc_enabled
= crtc_state
->active
;
11856 bool turn_off
, turn_on
, visible
, was_visible
;
11857 struct drm_framebuffer
*fb
= plane_state
->fb
;
11860 if (INTEL_GEN(dev
) >= 9 && plane
->type
!= DRM_PLANE_TYPE_CURSOR
) {
11861 ret
= skl_update_scaler_plane(
11862 to_intel_crtc_state(crtc_state
),
11863 to_intel_plane_state(plane_state
));
11868 was_visible
= old_plane_state
->visible
;
11869 visible
= to_intel_plane_state(plane_state
)->visible
;
11871 if (!was_crtc_enabled
&& WARN_ON(was_visible
))
11872 was_visible
= false;
11875 * Visibility is calculated as if the crtc was on, but
11876 * after scaler setup everything depends on it being off
11877 * when the crtc isn't active.
11879 * FIXME this is wrong for watermarks. Watermarks should also
11880 * be computed as if the pipe would be active. Perhaps move
11881 * per-plane wm computation to the .check_plane() hook, and
11882 * only combine the results from all planes in the current place?
11884 if (!is_crtc_enabled
)
11885 to_intel_plane_state(plane_state
)->visible
= visible
= false;
11887 if (!was_visible
&& !visible
)
11890 if (fb
!= old_plane_state
->base
.fb
)
11891 pipe_config
->fb_changed
= true;
11893 turn_off
= was_visible
&& (!visible
|| mode_changed
);
11894 turn_on
= visible
&& (!was_visible
|| mode_changed
);
11896 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
11897 intel_crtc
->base
.base
.id
,
11898 intel_crtc
->base
.name
,
11899 plane
->base
.id
, plane
->name
,
11900 fb
? fb
->base
.id
: -1);
11902 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
11903 plane
->base
.id
, plane
->name
,
11904 was_visible
, visible
,
11905 turn_off
, turn_on
, mode_changed
);
11908 pipe_config
->update_wm_pre
= true;
11910 /* must disable cxsr around plane enable/disable */
11911 if (plane
->type
!= DRM_PLANE_TYPE_CURSOR
)
11912 pipe_config
->disable_cxsr
= true;
11913 } else if (turn_off
) {
11914 pipe_config
->update_wm_post
= true;
11916 /* must disable cxsr around plane enable/disable */
11917 if (plane
->type
!= DRM_PLANE_TYPE_CURSOR
)
11918 pipe_config
->disable_cxsr
= true;
11919 } else if (intel_wm_need_update(plane
, plane_state
)) {
11920 /* FIXME bollocks */
11921 pipe_config
->update_wm_pre
= true;
11922 pipe_config
->update_wm_post
= true;
11925 /* Pre-gen9 platforms need two-step watermark updates */
11926 if ((pipe_config
->update_wm_pre
|| pipe_config
->update_wm_post
) &&
11927 INTEL_INFO(dev
)->gen
< 9 && dev_priv
->display
.optimize_watermarks
)
11928 to_intel_crtc_state(crtc_state
)->wm
.need_postvbl_update
= true;
11930 if (visible
|| was_visible
)
11931 pipe_config
->fb_bits
|= to_intel_plane(plane
)->frontbuffer_bit
;
11934 * WaCxSRDisabledForSpriteScaling:ivb
11936 * cstate->update_wm was already set above, so this flag will
11937 * take effect when we commit and program watermarks.
11939 if (plane
->type
== DRM_PLANE_TYPE_OVERLAY
&& IS_IVYBRIDGE(dev
) &&
11940 needs_scaling(to_intel_plane_state(plane_state
)) &&
11941 !needs_scaling(old_plane_state
))
11942 pipe_config
->disable_lp_wm
= true;
11947 static bool encoders_cloneable(const struct intel_encoder
*a
,
11948 const struct intel_encoder
*b
)
11950 /* masks could be asymmetric, so check both ways */
11951 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
11952 b
->cloneable
& (1 << a
->type
));
11955 static bool check_single_encoder_cloning(struct drm_atomic_state
*state
,
11956 struct intel_crtc
*crtc
,
11957 struct intel_encoder
*encoder
)
11959 struct intel_encoder
*source_encoder
;
11960 struct drm_connector
*connector
;
11961 struct drm_connector_state
*connector_state
;
11964 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11965 if (connector_state
->crtc
!= &crtc
->base
)
11969 to_intel_encoder(connector_state
->best_encoder
);
11970 if (!encoders_cloneable(encoder
, source_encoder
))
11977 static int intel_crtc_atomic_check(struct drm_crtc
*crtc
,
11978 struct drm_crtc_state
*crtc_state
)
11980 struct drm_device
*dev
= crtc
->dev
;
11981 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11982 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11983 struct intel_crtc_state
*pipe_config
=
11984 to_intel_crtc_state(crtc_state
);
11985 struct drm_atomic_state
*state
= crtc_state
->state
;
11987 bool mode_changed
= needs_modeset(crtc_state
);
11989 if (mode_changed
&& !crtc_state
->active
)
11990 pipe_config
->update_wm_post
= true;
11992 if (mode_changed
&& crtc_state
->enable
&&
11993 dev_priv
->display
.crtc_compute_clock
&&
11994 !WARN_ON(pipe_config
->shared_dpll
)) {
11995 ret
= dev_priv
->display
.crtc_compute_clock(intel_crtc
,
12001 if (crtc_state
->color_mgmt_changed
) {
12002 ret
= intel_color_check(crtc
, crtc_state
);
12007 * Changing color management on Intel hardware is
12008 * handled as part of planes update.
12010 crtc_state
->planes_changed
= true;
12014 if (dev_priv
->display
.compute_pipe_wm
) {
12015 ret
= dev_priv
->display
.compute_pipe_wm(pipe_config
);
12017 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
12022 if (dev_priv
->display
.compute_intermediate_wm
&&
12023 !to_intel_atomic_state(state
)->skip_intermediate_wm
) {
12024 if (WARN_ON(!dev_priv
->display
.compute_pipe_wm
))
12028 * Calculate 'intermediate' watermarks that satisfy both the
12029 * old state and the new state. We can program these
12032 ret
= dev_priv
->display
.compute_intermediate_wm(crtc
->dev
,
12036 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
12039 } else if (dev_priv
->display
.compute_intermediate_wm
) {
12040 if (HAS_PCH_SPLIT(dev_priv
) && INTEL_GEN(dev_priv
) < 9)
12041 pipe_config
->wm
.ilk
.intermediate
= pipe_config
->wm
.ilk
.optimal
;
12044 if (INTEL_INFO(dev
)->gen
>= 9) {
12046 ret
= skl_update_scaler_crtc(pipe_config
);
12049 ret
= intel_atomic_setup_scalers(dev
, intel_crtc
,
12056 static const struct drm_crtc_helper_funcs intel_helper_funcs
= {
12057 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
12058 .atomic_begin
= intel_begin_crtc_commit
,
12059 .atomic_flush
= intel_finish_crtc_commit
,
12060 .atomic_check
= intel_crtc_atomic_check
,
12063 static void intel_modeset_update_connector_atomic_state(struct drm_device
*dev
)
12065 struct intel_connector
*connector
;
12067 for_each_intel_connector(dev
, connector
) {
12068 if (connector
->base
.state
->crtc
)
12069 drm_connector_unreference(&connector
->base
);
12071 if (connector
->base
.encoder
) {
12072 connector
->base
.state
->best_encoder
=
12073 connector
->base
.encoder
;
12074 connector
->base
.state
->crtc
=
12075 connector
->base
.encoder
->crtc
;
12077 drm_connector_reference(&connector
->base
);
12079 connector
->base
.state
->best_encoder
= NULL
;
12080 connector
->base
.state
->crtc
= NULL
;
12086 connected_sink_compute_bpp(struct intel_connector
*connector
,
12087 struct intel_crtc_state
*pipe_config
)
12089 int bpp
= pipe_config
->pipe_bpp
;
12091 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
12092 connector
->base
.base
.id
,
12093 connector
->base
.name
);
12095 /* Don't use an invalid EDID bpc value */
12096 if (connector
->base
.display_info
.bpc
&&
12097 connector
->base
.display_info
.bpc
* 3 < bpp
) {
12098 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
12099 bpp
, connector
->base
.display_info
.bpc
*3);
12100 pipe_config
->pipe_bpp
= connector
->base
.display_info
.bpc
*3;
12103 /* Clamp bpp to default limit on screens without EDID 1.4 */
12104 if (connector
->base
.display_info
.bpc
== 0) {
12105 int type
= connector
->base
.connector_type
;
12106 int clamp_bpp
= 24;
12108 /* Fall back to 18 bpp when DP sink capability is unknown. */
12109 if (type
== DRM_MODE_CONNECTOR_DisplayPort
||
12110 type
== DRM_MODE_CONNECTOR_eDP
)
12113 if (bpp
> clamp_bpp
) {
12114 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of %d\n",
12116 pipe_config
->pipe_bpp
= clamp_bpp
;
12122 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
12123 struct intel_crtc_state
*pipe_config
)
12125 struct drm_device
*dev
= crtc
->base
.dev
;
12126 struct drm_atomic_state
*state
;
12127 struct drm_connector
*connector
;
12128 struct drm_connector_state
*connector_state
;
12131 if ((IS_G4X(dev
) || IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)))
12133 else if (INTEL_INFO(dev
)->gen
>= 5)
12139 pipe_config
->pipe_bpp
= bpp
;
12141 state
= pipe_config
->base
.state
;
12143 /* Clamp display bpp to EDID value */
12144 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
12145 if (connector_state
->crtc
!= &crtc
->base
)
12148 connected_sink_compute_bpp(to_intel_connector(connector
),
12155 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
12157 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
12158 "type: 0x%x flags: 0x%x\n",
12160 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
12161 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
12162 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
12163 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
12166 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
12167 struct intel_crtc_state
*pipe_config
,
12168 const char *context
)
12170 struct drm_device
*dev
= crtc
->base
.dev
;
12171 struct drm_plane
*plane
;
12172 struct intel_plane
*intel_plane
;
12173 struct intel_plane_state
*state
;
12174 struct drm_framebuffer
*fb
;
12176 DRM_DEBUG_KMS("[CRTC:%d:%s]%s config %p for pipe %c\n",
12177 crtc
->base
.base
.id
, crtc
->base
.name
,
12178 context
, pipe_config
, pipe_name(crtc
->pipe
));
12180 DRM_DEBUG_KMS("cpu_transcoder: %s\n", transcoder_name(pipe_config
->cpu_transcoder
));
12181 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
12182 pipe_config
->pipe_bpp
, pipe_config
->dither
);
12183 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
12184 pipe_config
->has_pch_encoder
,
12185 pipe_config
->fdi_lanes
,
12186 pipe_config
->fdi_m_n
.gmch_m
, pipe_config
->fdi_m_n
.gmch_n
,
12187 pipe_config
->fdi_m_n
.link_m
, pipe_config
->fdi_m_n
.link_n
,
12188 pipe_config
->fdi_m_n
.tu
);
12189 DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
12190 intel_crtc_has_dp_encoder(pipe_config
),
12191 pipe_config
->lane_count
,
12192 pipe_config
->dp_m_n
.gmch_m
, pipe_config
->dp_m_n
.gmch_n
,
12193 pipe_config
->dp_m_n
.link_m
, pipe_config
->dp_m_n
.link_n
,
12194 pipe_config
->dp_m_n
.tu
);
12196 DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
12197 intel_crtc_has_dp_encoder(pipe_config
),
12198 pipe_config
->lane_count
,
12199 pipe_config
->dp_m2_n2
.gmch_m
,
12200 pipe_config
->dp_m2_n2
.gmch_n
,
12201 pipe_config
->dp_m2_n2
.link_m
,
12202 pipe_config
->dp_m2_n2
.link_n
,
12203 pipe_config
->dp_m2_n2
.tu
);
12205 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
12206 pipe_config
->has_audio
,
12207 pipe_config
->has_infoframe
);
12209 DRM_DEBUG_KMS("requested mode:\n");
12210 drm_mode_debug_printmodeline(&pipe_config
->base
.mode
);
12211 DRM_DEBUG_KMS("adjusted mode:\n");
12212 drm_mode_debug_printmodeline(&pipe_config
->base
.adjusted_mode
);
12213 intel_dump_crtc_timings(&pipe_config
->base
.adjusted_mode
);
12214 DRM_DEBUG_KMS("port clock: %d\n", pipe_config
->port_clock
);
12215 DRM_DEBUG_KMS("pipe src size: %dx%d\n",
12216 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
12217 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
12219 pipe_config
->scaler_state
.scaler_users
,
12220 pipe_config
->scaler_state
.scaler_id
);
12221 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
12222 pipe_config
->gmch_pfit
.control
,
12223 pipe_config
->gmch_pfit
.pgm_ratios
,
12224 pipe_config
->gmch_pfit
.lvds_border_bits
);
12225 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
12226 pipe_config
->pch_pfit
.pos
,
12227 pipe_config
->pch_pfit
.size
,
12228 pipe_config
->pch_pfit
.enabled
? "enabled" : "disabled");
12229 DRM_DEBUG_KMS("ips: %i\n", pipe_config
->ips_enabled
);
12230 DRM_DEBUG_KMS("double wide: %i\n", pipe_config
->double_wide
);
12232 if (IS_BROXTON(dev
)) {
12233 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x,"
12234 "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, "
12235 "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n",
12236 pipe_config
->ddi_pll_sel
,
12237 pipe_config
->dpll_hw_state
.ebb0
,
12238 pipe_config
->dpll_hw_state
.ebb4
,
12239 pipe_config
->dpll_hw_state
.pll0
,
12240 pipe_config
->dpll_hw_state
.pll1
,
12241 pipe_config
->dpll_hw_state
.pll2
,
12242 pipe_config
->dpll_hw_state
.pll3
,
12243 pipe_config
->dpll_hw_state
.pll6
,
12244 pipe_config
->dpll_hw_state
.pll8
,
12245 pipe_config
->dpll_hw_state
.pll9
,
12246 pipe_config
->dpll_hw_state
.pll10
,
12247 pipe_config
->dpll_hw_state
.pcsdw12
);
12248 } else if (IS_SKYLAKE(dev
) || IS_KABYLAKE(dev
)) {
12249 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: "
12250 "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n",
12251 pipe_config
->ddi_pll_sel
,
12252 pipe_config
->dpll_hw_state
.ctrl1
,
12253 pipe_config
->dpll_hw_state
.cfgcr1
,
12254 pipe_config
->dpll_hw_state
.cfgcr2
);
12255 } else if (HAS_DDI(dev
)) {
12256 DRM_DEBUG_KMS("ddi_pll_sel: 0x%x; dpll_hw_state: wrpll: 0x%x spll: 0x%x\n",
12257 pipe_config
->ddi_pll_sel
,
12258 pipe_config
->dpll_hw_state
.wrpll
,
12259 pipe_config
->dpll_hw_state
.spll
);
12261 DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, "
12262 "fp0: 0x%x, fp1: 0x%x\n",
12263 pipe_config
->dpll_hw_state
.dpll
,
12264 pipe_config
->dpll_hw_state
.dpll_md
,
12265 pipe_config
->dpll_hw_state
.fp0
,
12266 pipe_config
->dpll_hw_state
.fp1
);
12269 DRM_DEBUG_KMS("planes on this crtc\n");
12270 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
12271 intel_plane
= to_intel_plane(plane
);
12272 if (intel_plane
->pipe
!= crtc
->pipe
)
12275 state
= to_intel_plane_state(plane
->state
);
12276 fb
= state
->base
.fb
;
12278 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
12279 plane
->base
.id
, plane
->name
, state
->scaler_id
);
12283 DRM_DEBUG_KMS("[PLANE:%d:%s] enabled",
12284 plane
->base
.id
, plane
->name
);
12285 DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = %s",
12286 fb
->base
.id
, fb
->width
, fb
->height
,
12287 drm_get_format_name(fb
->pixel_format
));
12288 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
12290 state
->src
.x1
>> 16, state
->src
.y1
>> 16,
12291 drm_rect_width(&state
->src
) >> 16,
12292 drm_rect_height(&state
->src
) >> 16,
12293 state
->dst
.x1
, state
->dst
.y1
,
12294 drm_rect_width(&state
->dst
),
12295 drm_rect_height(&state
->dst
));
12299 static bool check_digital_port_conflicts(struct drm_atomic_state
*state
)
12301 struct drm_device
*dev
= state
->dev
;
12302 struct drm_connector
*connector
;
12303 unsigned int used_ports
= 0;
12304 unsigned int used_mst_ports
= 0;
12307 * Walk the connector list instead of the encoder
12308 * list to detect the problem on ddi platforms
12309 * where there's just one encoder per digital port.
12311 drm_for_each_connector(connector
, dev
) {
12312 struct drm_connector_state
*connector_state
;
12313 struct intel_encoder
*encoder
;
12315 connector_state
= drm_atomic_get_existing_connector_state(state
, connector
);
12316 if (!connector_state
)
12317 connector_state
= connector
->state
;
12319 if (!connector_state
->best_encoder
)
12322 encoder
= to_intel_encoder(connector_state
->best_encoder
);
12324 WARN_ON(!connector_state
->crtc
);
12326 switch (encoder
->type
) {
12327 unsigned int port_mask
;
12328 case INTEL_OUTPUT_UNKNOWN
:
12329 if (WARN_ON(!HAS_DDI(dev
)))
12331 case INTEL_OUTPUT_DP
:
12332 case INTEL_OUTPUT_HDMI
:
12333 case INTEL_OUTPUT_EDP
:
12334 port_mask
= 1 << enc_to_dig_port(&encoder
->base
)->port
;
12336 /* the same port mustn't appear more than once */
12337 if (used_ports
& port_mask
)
12340 used_ports
|= port_mask
;
12342 case INTEL_OUTPUT_DP_MST
:
12344 1 << enc_to_mst(&encoder
->base
)->primary
->port
;
12351 /* can't mix MST and SST/HDMI on the same port */
12352 if (used_ports
& used_mst_ports
)
12359 clear_intel_crtc_state(struct intel_crtc_state
*crtc_state
)
12361 struct drm_crtc_state tmp_state
;
12362 struct intel_crtc_scaler_state scaler_state
;
12363 struct intel_dpll_hw_state dpll_hw_state
;
12364 struct intel_shared_dpll
*shared_dpll
;
12365 uint32_t ddi_pll_sel
;
12368 /* FIXME: before the switch to atomic started, a new pipe_config was
12369 * kzalloc'd. Code that depends on any field being zero should be
12370 * fixed, so that the crtc_state can be safely duplicated. For now,
12371 * only fields that are know to not cause problems are preserved. */
12373 tmp_state
= crtc_state
->base
;
12374 scaler_state
= crtc_state
->scaler_state
;
12375 shared_dpll
= crtc_state
->shared_dpll
;
12376 dpll_hw_state
= crtc_state
->dpll_hw_state
;
12377 ddi_pll_sel
= crtc_state
->ddi_pll_sel
;
12378 force_thru
= crtc_state
->pch_pfit
.force_thru
;
12380 memset(crtc_state
, 0, sizeof *crtc_state
);
12382 crtc_state
->base
= tmp_state
;
12383 crtc_state
->scaler_state
= scaler_state
;
12384 crtc_state
->shared_dpll
= shared_dpll
;
12385 crtc_state
->dpll_hw_state
= dpll_hw_state
;
12386 crtc_state
->ddi_pll_sel
= ddi_pll_sel
;
12387 crtc_state
->pch_pfit
.force_thru
= force_thru
;
12391 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
12392 struct intel_crtc_state
*pipe_config
)
12394 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
12395 struct intel_encoder
*encoder
;
12396 struct drm_connector
*connector
;
12397 struct drm_connector_state
*connector_state
;
12398 int base_bpp
, ret
= -EINVAL
;
12402 clear_intel_crtc_state(pipe_config
);
12404 pipe_config
->cpu_transcoder
=
12405 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
12408 * Sanitize sync polarity flags based on requested ones. If neither
12409 * positive or negative polarity is requested, treat this as meaning
12410 * negative polarity.
12412 if (!(pipe_config
->base
.adjusted_mode
.flags
&
12413 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
12414 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
12416 if (!(pipe_config
->base
.adjusted_mode
.flags
&
12417 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
12418 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
12420 base_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
12426 * Determine the real pipe dimensions. Note that stereo modes can
12427 * increase the actual pipe size due to the frame doubling and
12428 * insertion of additional space for blanks between the frame. This
12429 * is stored in the crtc timings. We use the requested mode to do this
12430 * computation to clearly distinguish it from the adjusted mode, which
12431 * can be changed by the connectors in the below retry loop.
12433 drm_crtc_get_hv_timing(&pipe_config
->base
.mode
,
12434 &pipe_config
->pipe_src_w
,
12435 &pipe_config
->pipe_src_h
);
12437 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
12438 if (connector_state
->crtc
!= crtc
)
12441 encoder
= to_intel_encoder(connector_state
->best_encoder
);
12443 if (!check_single_encoder_cloning(state
, to_intel_crtc(crtc
), encoder
)) {
12444 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
12449 * Determine output_types before calling the .compute_config()
12450 * hooks so that the hooks can use this information safely.
12452 pipe_config
->output_types
|= 1 << encoder
->type
;
12456 /* Ensure the port clock defaults are reset when retrying. */
12457 pipe_config
->port_clock
= 0;
12458 pipe_config
->pixel_multiplier
= 1;
12460 /* Fill in default crtc timings, allow encoders to overwrite them. */
12461 drm_mode_set_crtcinfo(&pipe_config
->base
.adjusted_mode
,
12462 CRTC_STEREO_DOUBLE
);
12464 /* Pass our mode to the connectors and the CRTC to give them a chance to
12465 * adjust it according to limitations or connector properties, and also
12466 * a chance to reject the mode entirely.
12468 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
12469 if (connector_state
->crtc
!= crtc
)
12472 encoder
= to_intel_encoder(connector_state
->best_encoder
);
12474 if (!(encoder
->compute_config(encoder
, pipe_config
))) {
12475 DRM_DEBUG_KMS("Encoder config failure\n");
12480 /* Set default port clock if not overwritten by the encoder. Needs to be
12481 * done afterwards in case the encoder adjusts the mode. */
12482 if (!pipe_config
->port_clock
)
12483 pipe_config
->port_clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
12484 * pipe_config
->pixel_multiplier
;
12486 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
12488 DRM_DEBUG_KMS("CRTC fixup failed\n");
12492 if (ret
== RETRY
) {
12493 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
12498 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
12500 goto encoder_retry
;
12503 /* Dithering seems to not pass-through bits correctly when it should, so
12504 * only enable it on 6bpc panels. */
12505 pipe_config
->dither
= pipe_config
->pipe_bpp
== 6*3;
12506 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
12507 base_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
12514 intel_modeset_update_crtc_state(struct drm_atomic_state
*state
)
12516 struct drm_crtc
*crtc
;
12517 struct drm_crtc_state
*crtc_state
;
12520 /* Double check state. */
12521 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12522 to_intel_crtc(crtc
)->config
= to_intel_crtc_state(crtc
->state
);
12524 /* Update hwmode for vblank functions */
12525 if (crtc
->state
->active
)
12526 crtc
->hwmode
= crtc
->state
->adjusted_mode
;
12528 crtc
->hwmode
.crtc_clock
= 0;
12531 * Update legacy state to satisfy fbc code. This can
12532 * be removed when fbc uses the atomic state.
12534 if (drm_atomic_get_existing_plane_state(state
, crtc
->primary
)) {
12535 struct drm_plane_state
*plane_state
= crtc
->primary
->state
;
12537 crtc
->primary
->fb
= plane_state
->fb
;
12538 crtc
->x
= plane_state
->src_x
>> 16;
12539 crtc
->y
= plane_state
->src_y
>> 16;
12544 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
12548 if (clock1
== clock2
)
12551 if (!clock1
|| !clock2
)
12554 diff
= abs(clock1
- clock2
);
12556 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
12562 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
12563 list_for_each_entry((intel_crtc), \
12564 &(dev)->mode_config.crtc_list, \
12566 for_each_if (mask & (1 <<(intel_crtc)->pipe))
12569 intel_compare_m_n(unsigned int m
, unsigned int n
,
12570 unsigned int m2
, unsigned int n2
,
12573 if (m
== m2
&& n
== n2
)
12576 if (exact
|| !m
|| !n
|| !m2
|| !n2
)
12579 BUILD_BUG_ON(DATA_LINK_M_N_MASK
> INT_MAX
);
12586 } else if (n
< n2
) {
12596 return intel_fuzzy_clock_check(m
, m2
);
12600 intel_compare_link_m_n(const struct intel_link_m_n
*m_n
,
12601 struct intel_link_m_n
*m2_n2
,
12604 if (m_n
->tu
== m2_n2
->tu
&&
12605 intel_compare_m_n(m_n
->gmch_m
, m_n
->gmch_n
,
12606 m2_n2
->gmch_m
, m2_n2
->gmch_n
, !adjust
) &&
12607 intel_compare_m_n(m_n
->link_m
, m_n
->link_n
,
12608 m2_n2
->link_m
, m2_n2
->link_n
, !adjust
)) {
12619 intel_pipe_config_compare(struct drm_device
*dev
,
12620 struct intel_crtc_state
*current_config
,
12621 struct intel_crtc_state
*pipe_config
,
12626 #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \
12629 DRM_ERROR(fmt, ##__VA_ARGS__); \
12631 DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \
12634 #define PIPE_CONF_CHECK_X(name) \
12635 if (current_config->name != pipe_config->name) { \
12636 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12637 "(expected 0x%08x, found 0x%08x)\n", \
12638 current_config->name, \
12639 pipe_config->name); \
12643 #define PIPE_CONF_CHECK_I(name) \
12644 if (current_config->name != pipe_config->name) { \
12645 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12646 "(expected %i, found %i)\n", \
12647 current_config->name, \
12648 pipe_config->name); \
12652 #define PIPE_CONF_CHECK_P(name) \
12653 if (current_config->name != pipe_config->name) { \
12654 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12655 "(expected %p, found %p)\n", \
12656 current_config->name, \
12657 pipe_config->name); \
12661 #define PIPE_CONF_CHECK_M_N(name) \
12662 if (!intel_compare_link_m_n(¤t_config->name, \
12663 &pipe_config->name,\
12665 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12666 "(expected tu %i gmch %i/%i link %i/%i, " \
12667 "found tu %i, gmch %i/%i link %i/%i)\n", \
12668 current_config->name.tu, \
12669 current_config->name.gmch_m, \
12670 current_config->name.gmch_n, \
12671 current_config->name.link_m, \
12672 current_config->name.link_n, \
12673 pipe_config->name.tu, \
12674 pipe_config->name.gmch_m, \
12675 pipe_config->name.gmch_n, \
12676 pipe_config->name.link_m, \
12677 pipe_config->name.link_n); \
12681 /* This is required for BDW+ where there is only one set of registers for
12682 * switching between high and low RR.
12683 * This macro can be used whenever a comparison has to be made between one
12684 * hw state and multiple sw state variables.
12686 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \
12687 if (!intel_compare_link_m_n(¤t_config->name, \
12688 &pipe_config->name, adjust) && \
12689 !intel_compare_link_m_n(¤t_config->alt_name, \
12690 &pipe_config->name, adjust)) { \
12691 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12692 "(expected tu %i gmch %i/%i link %i/%i, " \
12693 "or tu %i gmch %i/%i link %i/%i, " \
12694 "found tu %i, gmch %i/%i link %i/%i)\n", \
12695 current_config->name.tu, \
12696 current_config->name.gmch_m, \
12697 current_config->name.gmch_n, \
12698 current_config->name.link_m, \
12699 current_config->name.link_n, \
12700 current_config->alt_name.tu, \
12701 current_config->alt_name.gmch_m, \
12702 current_config->alt_name.gmch_n, \
12703 current_config->alt_name.link_m, \
12704 current_config->alt_name.link_n, \
12705 pipe_config->name.tu, \
12706 pipe_config->name.gmch_m, \
12707 pipe_config->name.gmch_n, \
12708 pipe_config->name.link_m, \
12709 pipe_config->name.link_n); \
12713 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
12714 if ((current_config->name ^ pipe_config->name) & (mask)) { \
12715 INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \
12716 "(expected %i, found %i)\n", \
12717 current_config->name & (mask), \
12718 pipe_config->name & (mask)); \
12722 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
12723 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
12724 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12725 "(expected %i, found %i)\n", \
12726 current_config->name, \
12727 pipe_config->name); \
12731 #define PIPE_CONF_QUIRK(quirk) \
12732 ((current_config->quirks | pipe_config->quirks) & (quirk))
12734 PIPE_CONF_CHECK_I(cpu_transcoder
);
12736 PIPE_CONF_CHECK_I(has_pch_encoder
);
12737 PIPE_CONF_CHECK_I(fdi_lanes
);
12738 PIPE_CONF_CHECK_M_N(fdi_m_n
);
12740 PIPE_CONF_CHECK_I(lane_count
);
12741 PIPE_CONF_CHECK_X(lane_lat_optim_mask
);
12743 if (INTEL_INFO(dev
)->gen
< 8) {
12744 PIPE_CONF_CHECK_M_N(dp_m_n
);
12746 if (current_config
->has_drrs
)
12747 PIPE_CONF_CHECK_M_N(dp_m2_n2
);
12749 PIPE_CONF_CHECK_M_N_ALT(dp_m_n
, dp_m2_n2
);
12751 PIPE_CONF_CHECK_X(output_types
);
12753 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hdisplay
);
12754 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_htotal
);
12755 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_start
);
12756 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_end
);
12757 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_start
);
12758 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_end
);
12760 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vdisplay
);
12761 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vtotal
);
12762 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_start
);
12763 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_end
);
12764 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_start
);
12765 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_end
);
12767 PIPE_CONF_CHECK_I(pixel_multiplier
);
12768 PIPE_CONF_CHECK_I(has_hdmi_sink
);
12769 if ((INTEL_INFO(dev
)->gen
< 8 && !IS_HASWELL(dev
)) ||
12770 IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
))
12771 PIPE_CONF_CHECK_I(limited_color_range
);
12772 PIPE_CONF_CHECK_I(has_infoframe
);
12774 PIPE_CONF_CHECK_I(has_audio
);
12776 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12777 DRM_MODE_FLAG_INTERLACE
);
12779 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
12780 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12781 DRM_MODE_FLAG_PHSYNC
);
12782 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12783 DRM_MODE_FLAG_NHSYNC
);
12784 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12785 DRM_MODE_FLAG_PVSYNC
);
12786 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12787 DRM_MODE_FLAG_NVSYNC
);
12790 PIPE_CONF_CHECK_X(gmch_pfit
.control
);
12791 /* pfit ratios are autocomputed by the hw on gen4+ */
12792 if (INTEL_INFO(dev
)->gen
< 4)
12793 PIPE_CONF_CHECK_X(gmch_pfit
.pgm_ratios
);
12794 PIPE_CONF_CHECK_X(gmch_pfit
.lvds_border_bits
);
12797 PIPE_CONF_CHECK_I(pipe_src_w
);
12798 PIPE_CONF_CHECK_I(pipe_src_h
);
12800 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
12801 if (current_config
->pch_pfit
.enabled
) {
12802 PIPE_CONF_CHECK_X(pch_pfit
.pos
);
12803 PIPE_CONF_CHECK_X(pch_pfit
.size
);
12806 PIPE_CONF_CHECK_I(scaler_state
.scaler_id
);
12809 /* BDW+ don't expose a synchronous way to read the state */
12810 if (IS_HASWELL(dev
))
12811 PIPE_CONF_CHECK_I(ips_enabled
);
12813 PIPE_CONF_CHECK_I(double_wide
);
12815 PIPE_CONF_CHECK_X(ddi_pll_sel
);
12817 PIPE_CONF_CHECK_P(shared_dpll
);
12818 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
12819 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
12820 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
12821 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
12822 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
12823 PIPE_CONF_CHECK_X(dpll_hw_state
.spll
);
12824 PIPE_CONF_CHECK_X(dpll_hw_state
.ctrl1
);
12825 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr1
);
12826 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr2
);
12828 PIPE_CONF_CHECK_X(dsi_pll
.ctrl
);
12829 PIPE_CONF_CHECK_X(dsi_pll
.div
);
12831 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5)
12832 PIPE_CONF_CHECK_I(pipe_bpp
);
12834 PIPE_CONF_CHECK_CLOCK_FUZZY(base
.adjusted_mode
.crtc_clock
);
12835 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
12837 #undef PIPE_CONF_CHECK_X
12838 #undef PIPE_CONF_CHECK_I
12839 #undef PIPE_CONF_CHECK_P
12840 #undef PIPE_CONF_CHECK_FLAGS
12841 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
12842 #undef PIPE_CONF_QUIRK
12843 #undef INTEL_ERR_OR_DBG_KMS
12848 static void intel_pipe_config_sanity_check(struct drm_i915_private
*dev_priv
,
12849 const struct intel_crtc_state
*pipe_config
)
12851 if (pipe_config
->has_pch_encoder
) {
12852 int fdi_dotclock
= intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
12853 &pipe_config
->fdi_m_n
);
12854 int dotclock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
12857 * FDI already provided one idea for the dotclock.
12858 * Yell if the encoder disagrees.
12860 WARN(!intel_fuzzy_clock_check(fdi_dotclock
, dotclock
),
12861 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
12862 fdi_dotclock
, dotclock
);
12866 static void verify_wm_state(struct drm_crtc
*crtc
,
12867 struct drm_crtc_state
*new_state
)
12869 struct drm_device
*dev
= crtc
->dev
;
12870 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12871 struct skl_ddb_allocation hw_ddb
, *sw_ddb
;
12872 struct skl_ddb_entry
*hw_entry
, *sw_entry
;
12873 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12874 const enum pipe pipe
= intel_crtc
->pipe
;
12877 if (INTEL_INFO(dev
)->gen
< 9 || !new_state
->active
)
12880 skl_ddb_get_hw_state(dev_priv
, &hw_ddb
);
12881 sw_ddb
= &dev_priv
->wm
.skl_hw
.ddb
;
12884 for_each_plane(dev_priv
, pipe
, plane
) {
12885 hw_entry
= &hw_ddb
.plane
[pipe
][plane
];
12886 sw_entry
= &sw_ddb
->plane
[pipe
][plane
];
12888 if (skl_ddb_entry_equal(hw_entry
, sw_entry
))
12891 DRM_ERROR("mismatch in DDB state pipe %c plane %d "
12892 "(expected (%u,%u), found (%u,%u))\n",
12893 pipe_name(pipe
), plane
+ 1,
12894 sw_entry
->start
, sw_entry
->end
,
12895 hw_entry
->start
, hw_entry
->end
);
12899 hw_entry
= &hw_ddb
.plane
[pipe
][PLANE_CURSOR
];
12900 sw_entry
= &sw_ddb
->plane
[pipe
][PLANE_CURSOR
];
12902 if (!skl_ddb_entry_equal(hw_entry
, sw_entry
)) {
12903 DRM_ERROR("mismatch in DDB state pipe %c cursor "
12904 "(expected (%u,%u), found (%u,%u))\n",
12906 sw_entry
->start
, sw_entry
->end
,
12907 hw_entry
->start
, hw_entry
->end
);
12912 verify_connector_state(struct drm_device
*dev
, struct drm_crtc
*crtc
)
12914 struct drm_connector
*connector
;
12916 drm_for_each_connector(connector
, dev
) {
12917 struct drm_encoder
*encoder
= connector
->encoder
;
12918 struct drm_connector_state
*state
= connector
->state
;
12920 if (state
->crtc
!= crtc
)
12923 intel_connector_verify_state(to_intel_connector(connector
));
12925 I915_STATE_WARN(state
->best_encoder
!= encoder
,
12926 "connector's atomic encoder doesn't match legacy encoder\n");
12931 verify_encoder_state(struct drm_device
*dev
)
12933 struct intel_encoder
*encoder
;
12934 struct intel_connector
*connector
;
12936 for_each_intel_encoder(dev
, encoder
) {
12937 bool enabled
= false;
12940 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
12941 encoder
->base
.base
.id
,
12942 encoder
->base
.name
);
12944 for_each_intel_connector(dev
, connector
) {
12945 if (connector
->base
.state
->best_encoder
!= &encoder
->base
)
12949 I915_STATE_WARN(connector
->base
.state
->crtc
!=
12950 encoder
->base
.crtc
,
12951 "connector's crtc doesn't match encoder crtc\n");
12954 I915_STATE_WARN(!!encoder
->base
.crtc
!= enabled
,
12955 "encoder's enabled state mismatch "
12956 "(expected %i, found %i)\n",
12957 !!encoder
->base
.crtc
, enabled
);
12959 if (!encoder
->base
.crtc
) {
12962 active
= encoder
->get_hw_state(encoder
, &pipe
);
12963 I915_STATE_WARN(active
,
12964 "encoder detached but still enabled on pipe %c.\n",
12971 verify_crtc_state(struct drm_crtc
*crtc
,
12972 struct drm_crtc_state
*old_crtc_state
,
12973 struct drm_crtc_state
*new_crtc_state
)
12975 struct drm_device
*dev
= crtc
->dev
;
12976 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12977 struct intel_encoder
*encoder
;
12978 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12979 struct intel_crtc_state
*pipe_config
, *sw_config
;
12980 struct drm_atomic_state
*old_state
;
12983 old_state
= old_crtc_state
->state
;
12984 __drm_atomic_helper_crtc_destroy_state(old_crtc_state
);
12985 pipe_config
= to_intel_crtc_state(old_crtc_state
);
12986 memset(pipe_config
, 0, sizeof(*pipe_config
));
12987 pipe_config
->base
.crtc
= crtc
;
12988 pipe_config
->base
.state
= old_state
;
12990 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc
->base
.id
, crtc
->name
);
12992 active
= dev_priv
->display
.get_pipe_config(intel_crtc
, pipe_config
);
12994 /* hw state is inconsistent with the pipe quirk */
12995 if ((intel_crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
12996 (intel_crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
12997 active
= new_crtc_state
->active
;
12999 I915_STATE_WARN(new_crtc_state
->active
!= active
,
13000 "crtc active state doesn't match with hw state "
13001 "(expected %i, found %i)\n", new_crtc_state
->active
, active
);
13003 I915_STATE_WARN(intel_crtc
->active
!= new_crtc_state
->active
,
13004 "transitional active state does not match atomic hw state "
13005 "(expected %i, found %i)\n", new_crtc_state
->active
, intel_crtc
->active
);
13007 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
13010 active
= encoder
->get_hw_state(encoder
, &pipe
);
13011 I915_STATE_WARN(active
!= new_crtc_state
->active
,
13012 "[ENCODER:%i] active %i with crtc active %i\n",
13013 encoder
->base
.base
.id
, active
, new_crtc_state
->active
);
13015 I915_STATE_WARN(active
&& intel_crtc
->pipe
!= pipe
,
13016 "Encoder connected to wrong pipe %c\n",
13020 pipe_config
->output_types
|= 1 << encoder
->type
;
13021 encoder
->get_config(encoder
, pipe_config
);
13025 if (!new_crtc_state
->active
)
13028 intel_pipe_config_sanity_check(dev_priv
, pipe_config
);
13030 sw_config
= to_intel_crtc_state(crtc
->state
);
13031 if (!intel_pipe_config_compare(dev
, sw_config
,
13032 pipe_config
, false)) {
13033 I915_STATE_WARN(1, "pipe state doesn't match!\n");
13034 intel_dump_pipe_config(intel_crtc
, pipe_config
,
13036 intel_dump_pipe_config(intel_crtc
, sw_config
,
13042 verify_single_dpll_state(struct drm_i915_private
*dev_priv
,
13043 struct intel_shared_dpll
*pll
,
13044 struct drm_crtc
*crtc
,
13045 struct drm_crtc_state
*new_state
)
13047 struct intel_dpll_hw_state dpll_hw_state
;
13048 unsigned crtc_mask
;
13051 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
13053 DRM_DEBUG_KMS("%s\n", pll
->name
);
13055 active
= pll
->funcs
.get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
13057 if (!(pll
->flags
& INTEL_DPLL_ALWAYS_ON
)) {
13058 I915_STATE_WARN(!pll
->on
&& pll
->active_mask
,
13059 "pll in active use but not on in sw tracking\n");
13060 I915_STATE_WARN(pll
->on
&& !pll
->active_mask
,
13061 "pll is on but not used by any active crtc\n");
13062 I915_STATE_WARN(pll
->on
!= active
,
13063 "pll on state mismatch (expected %i, found %i)\n",
13068 I915_STATE_WARN(pll
->active_mask
& ~pll
->config
.crtc_mask
,
13069 "more active pll users than references: %x vs %x\n",
13070 pll
->active_mask
, pll
->config
.crtc_mask
);
13075 crtc_mask
= 1 << drm_crtc_index(crtc
);
13077 if (new_state
->active
)
13078 I915_STATE_WARN(!(pll
->active_mask
& crtc_mask
),
13079 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
13080 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
13082 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
13083 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
13084 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
13086 I915_STATE_WARN(!(pll
->config
.crtc_mask
& crtc_mask
),
13087 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
13088 crtc_mask
, pll
->config
.crtc_mask
);
13090 I915_STATE_WARN(pll
->on
&& memcmp(&pll
->config
.hw_state
,
13092 sizeof(dpll_hw_state
)),
13093 "pll hw state mismatch\n");
13097 verify_shared_dpll_state(struct drm_device
*dev
, struct drm_crtc
*crtc
,
13098 struct drm_crtc_state
*old_crtc_state
,
13099 struct drm_crtc_state
*new_crtc_state
)
13101 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13102 struct intel_crtc_state
*old_state
= to_intel_crtc_state(old_crtc_state
);
13103 struct intel_crtc_state
*new_state
= to_intel_crtc_state(new_crtc_state
);
13105 if (new_state
->shared_dpll
)
13106 verify_single_dpll_state(dev_priv
, new_state
->shared_dpll
, crtc
, new_crtc_state
);
13108 if (old_state
->shared_dpll
&&
13109 old_state
->shared_dpll
!= new_state
->shared_dpll
) {
13110 unsigned crtc_mask
= 1 << drm_crtc_index(crtc
);
13111 struct intel_shared_dpll
*pll
= old_state
->shared_dpll
;
13113 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
13114 "pll active mismatch (didn't expect pipe %c in active mask)\n",
13115 pipe_name(drm_crtc_index(crtc
)));
13116 I915_STATE_WARN(pll
->config
.crtc_mask
& crtc_mask
,
13117 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
13118 pipe_name(drm_crtc_index(crtc
)));
13123 intel_modeset_verify_crtc(struct drm_crtc
*crtc
,
13124 struct drm_crtc_state
*old_state
,
13125 struct drm_crtc_state
*new_state
)
13127 if (!needs_modeset(new_state
) &&
13128 !to_intel_crtc_state(new_state
)->update_pipe
)
13131 verify_wm_state(crtc
, new_state
);
13132 verify_connector_state(crtc
->dev
, crtc
);
13133 verify_crtc_state(crtc
, old_state
, new_state
);
13134 verify_shared_dpll_state(crtc
->dev
, crtc
, old_state
, new_state
);
13138 verify_disabled_dpll_state(struct drm_device
*dev
)
13140 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13143 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++)
13144 verify_single_dpll_state(dev_priv
, &dev_priv
->shared_dplls
[i
], NULL
, NULL
);
13148 intel_modeset_verify_disabled(struct drm_device
*dev
)
13150 verify_encoder_state(dev
);
13151 verify_connector_state(dev
, NULL
);
13152 verify_disabled_dpll_state(dev
);
13155 static void update_scanline_offset(struct intel_crtc
*crtc
)
13157 struct drm_device
*dev
= crtc
->base
.dev
;
13160 * The scanline counter increments at the leading edge of hsync.
13162 * On most platforms it starts counting from vtotal-1 on the
13163 * first active line. That means the scanline counter value is
13164 * always one less than what we would expect. Ie. just after
13165 * start of vblank, which also occurs at start of hsync (on the
13166 * last active line), the scanline counter will read vblank_start-1.
13168 * On gen2 the scanline counter starts counting from 1 instead
13169 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
13170 * to keep the value positive), instead of adding one.
13172 * On HSW+ the behaviour of the scanline counter depends on the output
13173 * type. For DP ports it behaves like most other platforms, but on HDMI
13174 * there's an extra 1 line difference. So we need to add two instead of
13175 * one to the value.
13177 if (IS_GEN2(dev
)) {
13178 const struct drm_display_mode
*adjusted_mode
= &crtc
->config
->base
.adjusted_mode
;
13181 vtotal
= adjusted_mode
->crtc_vtotal
;
13182 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
13185 crtc
->scanline_offset
= vtotal
- 1;
13186 } else if (HAS_DDI(dev
) &&
13187 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_HDMI
)) {
13188 crtc
->scanline_offset
= 2;
13190 crtc
->scanline_offset
= 1;
13193 static void intel_modeset_clear_plls(struct drm_atomic_state
*state
)
13195 struct drm_device
*dev
= state
->dev
;
13196 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13197 struct intel_shared_dpll_config
*shared_dpll
= NULL
;
13198 struct drm_crtc
*crtc
;
13199 struct drm_crtc_state
*crtc_state
;
13202 if (!dev_priv
->display
.crtc_compute_clock
)
13205 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
13206 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13207 struct intel_shared_dpll
*old_dpll
=
13208 to_intel_crtc_state(crtc
->state
)->shared_dpll
;
13210 if (!needs_modeset(crtc_state
))
13213 to_intel_crtc_state(crtc_state
)->shared_dpll
= NULL
;
13219 shared_dpll
= intel_atomic_get_shared_dpll_state(state
);
13221 intel_shared_dpll_config_put(shared_dpll
, old_dpll
, intel_crtc
);
13226 * This implements the workaround described in the "notes" section of the mode
13227 * set sequence documentation. When going from no pipes or single pipe to
13228 * multiple pipes, and planes are enabled after the pipe, we need to wait at
13229 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
13231 static int haswell_mode_set_planes_workaround(struct drm_atomic_state
*state
)
13233 struct drm_crtc_state
*crtc_state
;
13234 struct intel_crtc
*intel_crtc
;
13235 struct drm_crtc
*crtc
;
13236 struct intel_crtc_state
*first_crtc_state
= NULL
;
13237 struct intel_crtc_state
*other_crtc_state
= NULL
;
13238 enum pipe first_pipe
= INVALID_PIPE
, enabled_pipe
= INVALID_PIPE
;
13241 /* look at all crtc's that are going to be enabled in during modeset */
13242 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
13243 intel_crtc
= to_intel_crtc(crtc
);
13245 if (!crtc_state
->active
|| !needs_modeset(crtc_state
))
13248 if (first_crtc_state
) {
13249 other_crtc_state
= to_intel_crtc_state(crtc_state
);
13252 first_crtc_state
= to_intel_crtc_state(crtc_state
);
13253 first_pipe
= intel_crtc
->pipe
;
13257 /* No workaround needed? */
13258 if (!first_crtc_state
)
13261 /* w/a possibly needed, check how many crtc's are already enabled. */
13262 for_each_intel_crtc(state
->dev
, intel_crtc
) {
13263 struct intel_crtc_state
*pipe_config
;
13265 pipe_config
= intel_atomic_get_crtc_state(state
, intel_crtc
);
13266 if (IS_ERR(pipe_config
))
13267 return PTR_ERR(pipe_config
);
13269 pipe_config
->hsw_workaround_pipe
= INVALID_PIPE
;
13271 if (!pipe_config
->base
.active
||
13272 needs_modeset(&pipe_config
->base
))
13275 /* 2 or more enabled crtcs means no need for w/a */
13276 if (enabled_pipe
!= INVALID_PIPE
)
13279 enabled_pipe
= intel_crtc
->pipe
;
13282 if (enabled_pipe
!= INVALID_PIPE
)
13283 first_crtc_state
->hsw_workaround_pipe
= enabled_pipe
;
13284 else if (other_crtc_state
)
13285 other_crtc_state
->hsw_workaround_pipe
= first_pipe
;
13290 static int intel_modeset_all_pipes(struct drm_atomic_state
*state
)
13292 struct drm_crtc
*crtc
;
13293 struct drm_crtc_state
*crtc_state
;
13296 /* add all active pipes to the state */
13297 for_each_crtc(state
->dev
, crtc
) {
13298 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
13299 if (IS_ERR(crtc_state
))
13300 return PTR_ERR(crtc_state
);
13302 if (!crtc_state
->active
|| needs_modeset(crtc_state
))
13305 crtc_state
->mode_changed
= true;
13307 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
13311 ret
= drm_atomic_add_affected_planes(state
, crtc
);
13319 static int intel_modeset_checks(struct drm_atomic_state
*state
)
13321 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
13322 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
13323 struct drm_crtc
*crtc
;
13324 struct drm_crtc_state
*crtc_state
;
13327 if (!check_digital_port_conflicts(state
)) {
13328 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
13332 intel_state
->modeset
= true;
13333 intel_state
->active_crtcs
= dev_priv
->active_crtcs
;
13335 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
13336 if (crtc_state
->active
)
13337 intel_state
->active_crtcs
|= 1 << i
;
13339 intel_state
->active_crtcs
&= ~(1 << i
);
13341 if (crtc_state
->active
!= crtc
->state
->active
)
13342 intel_state
->active_pipe_changes
|= drm_crtc_mask(crtc
);
13346 * See if the config requires any additional preparation, e.g.
13347 * to adjust global state with pipes off. We need to do this
13348 * here so we can get the modeset_pipe updated config for the new
13349 * mode set on this crtc. For other crtcs we need to use the
13350 * adjusted_mode bits in the crtc directly.
13352 if (dev_priv
->display
.modeset_calc_cdclk
) {
13353 if (!intel_state
->cdclk_pll_vco
)
13354 intel_state
->cdclk_pll_vco
= dev_priv
->cdclk_pll
.vco
;
13355 if (!intel_state
->cdclk_pll_vco
)
13356 intel_state
->cdclk_pll_vco
= dev_priv
->skl_preferred_vco_freq
;
13358 ret
= dev_priv
->display
.modeset_calc_cdclk(state
);
13362 if (intel_state
->dev_cdclk
!= dev_priv
->cdclk_freq
||
13363 intel_state
->cdclk_pll_vco
!= dev_priv
->cdclk_pll
.vco
)
13364 ret
= intel_modeset_all_pipes(state
);
13369 DRM_DEBUG_KMS("New cdclk calculated to be atomic %u, actual %u\n",
13370 intel_state
->cdclk
, intel_state
->dev_cdclk
);
13372 to_intel_atomic_state(state
)->cdclk
= dev_priv
->atomic_cdclk_freq
;
13374 intel_modeset_clear_plls(state
);
13376 if (IS_HASWELL(dev_priv
))
13377 return haswell_mode_set_planes_workaround(state
);
13383 * Handle calculation of various watermark data at the end of the atomic check
13384 * phase. The code here should be run after the per-crtc and per-plane 'check'
13385 * handlers to ensure that all derived state has been updated.
13387 static int calc_watermark_data(struct drm_atomic_state
*state
)
13389 struct drm_device
*dev
= state
->dev
;
13390 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13392 /* Is there platform-specific watermark information to calculate? */
13393 if (dev_priv
->display
.compute_global_watermarks
)
13394 return dev_priv
->display
.compute_global_watermarks(state
);
13400 * intel_atomic_check - validate state object
13402 * @state: state to validate
13404 static int intel_atomic_check(struct drm_device
*dev
,
13405 struct drm_atomic_state
*state
)
13407 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13408 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
13409 struct drm_crtc
*crtc
;
13410 struct drm_crtc_state
*crtc_state
;
13412 bool any_ms
= false;
13414 ret
= drm_atomic_helper_check_modeset(dev
, state
);
13418 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
13419 struct intel_crtc_state
*pipe_config
=
13420 to_intel_crtc_state(crtc_state
);
13422 /* Catch I915_MODE_FLAG_INHERITED */
13423 if (crtc_state
->mode
.private_flags
!= crtc
->state
->mode
.private_flags
)
13424 crtc_state
->mode_changed
= true;
13426 if (!needs_modeset(crtc_state
))
13429 if (!crtc_state
->enable
) {
13434 /* FIXME: For only active_changed we shouldn't need to do any
13435 * state recomputation at all. */
13437 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
13441 ret
= intel_modeset_pipe_config(crtc
, pipe_config
);
13443 intel_dump_pipe_config(to_intel_crtc(crtc
),
13444 pipe_config
, "[failed]");
13448 if (i915
.fastboot
&&
13449 intel_pipe_config_compare(dev
,
13450 to_intel_crtc_state(crtc
->state
),
13451 pipe_config
, true)) {
13452 crtc_state
->mode_changed
= false;
13453 to_intel_crtc_state(crtc_state
)->update_pipe
= true;
13456 if (needs_modeset(crtc_state
))
13459 ret
= drm_atomic_add_affected_planes(state
, crtc
);
13463 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
13464 needs_modeset(crtc_state
) ?
13465 "[modeset]" : "[fastset]");
13469 ret
= intel_modeset_checks(state
);
13474 intel_state
->cdclk
= dev_priv
->cdclk_freq
;
13476 ret
= drm_atomic_helper_check_planes(dev
, state
);
13480 intel_fbc_choose_crtc(dev_priv
, state
);
13481 return calc_watermark_data(state
);
13484 static int intel_atomic_prepare_commit(struct drm_device
*dev
,
13485 struct drm_atomic_state
*state
,
13488 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13489 struct drm_plane_state
*plane_state
;
13490 struct drm_crtc_state
*crtc_state
;
13491 struct drm_plane
*plane
;
13492 struct drm_crtc
*crtc
;
13495 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
13496 if (state
->legacy_cursor_update
)
13499 ret
= intel_crtc_wait_for_pending_flips(crtc
);
13503 if (atomic_read(&to_intel_crtc(crtc
)->unpin_work_count
) >= 2)
13504 flush_workqueue(dev_priv
->wq
);
13507 ret
= mutex_lock_interruptible(&dev
->struct_mutex
);
13511 ret
= drm_atomic_helper_prepare_planes(dev
, state
);
13512 mutex_unlock(&dev
->struct_mutex
);
13514 if (!ret
&& !nonblock
) {
13515 for_each_plane_in_state(state
, plane
, plane_state
, i
) {
13516 struct intel_plane_state
*intel_plane_state
=
13517 to_intel_plane_state(plane_state
);
13519 if (!intel_plane_state
->wait_req
)
13522 ret
= i915_wait_request(intel_plane_state
->wait_req
,
13525 /* Any hang should be swallowed by the wait */
13526 WARN_ON(ret
== -EIO
);
13527 mutex_lock(&dev
->struct_mutex
);
13528 drm_atomic_helper_cleanup_planes(dev
, state
);
13529 mutex_unlock(&dev
->struct_mutex
);
13538 u32
intel_crtc_get_vblank_counter(struct intel_crtc
*crtc
)
13540 struct drm_device
*dev
= crtc
->base
.dev
;
13542 if (!dev
->max_vblank_count
)
13543 return drm_accurate_vblank_count(&crtc
->base
);
13545 return dev
->driver
->get_vblank_counter(dev
, crtc
->pipe
);
13548 static void intel_atomic_wait_for_vblanks(struct drm_device
*dev
,
13549 struct drm_i915_private
*dev_priv
,
13550 unsigned crtc_mask
)
13552 unsigned last_vblank_count
[I915_MAX_PIPES
];
13559 for_each_pipe(dev_priv
, pipe
) {
13560 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
13562 if (!((1 << pipe
) & crtc_mask
))
13565 ret
= drm_crtc_vblank_get(crtc
);
13566 if (WARN_ON(ret
!= 0)) {
13567 crtc_mask
&= ~(1 << pipe
);
13571 last_vblank_count
[pipe
] = drm_crtc_vblank_count(crtc
);
13574 for_each_pipe(dev_priv
, pipe
) {
13575 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
13578 if (!((1 << pipe
) & crtc_mask
))
13581 lret
= wait_event_timeout(dev
->vblank
[pipe
].queue
,
13582 last_vblank_count
[pipe
] !=
13583 drm_crtc_vblank_count(crtc
),
13584 msecs_to_jiffies(50));
13586 WARN(!lret
, "pipe %c vblank wait timed out\n", pipe_name(pipe
));
13588 drm_crtc_vblank_put(crtc
);
13592 static bool needs_vblank_wait(struct intel_crtc_state
*crtc_state
)
13594 /* fb updated, need to unpin old fb */
13595 if (crtc_state
->fb_changed
)
13598 /* wm changes, need vblank before final wm's */
13599 if (crtc_state
->update_wm_post
)
13603 * cxsr is re-enabled after vblank.
13604 * This is already handled by crtc_state->update_wm_post,
13605 * but added for clarity.
13607 if (crtc_state
->disable_cxsr
)
13613 static void intel_atomic_commit_tail(struct drm_atomic_state
*state
)
13615 struct drm_device
*dev
= state
->dev
;
13616 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
13617 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13618 struct drm_crtc_state
*old_crtc_state
;
13619 struct drm_crtc
*crtc
;
13620 struct intel_crtc_state
*intel_cstate
;
13621 struct drm_plane
*plane
;
13622 struct drm_plane_state
*plane_state
;
13623 bool hw_check
= intel_state
->modeset
;
13624 unsigned long put_domains
[I915_MAX_PIPES
] = {};
13625 unsigned crtc_vblank_mask
= 0;
13628 for_each_plane_in_state(state
, plane
, plane_state
, i
) {
13629 struct intel_plane_state
*intel_plane_state
=
13630 to_intel_plane_state(plane_state
);
13632 if (!intel_plane_state
->wait_req
)
13635 ret
= i915_wait_request(intel_plane_state
->wait_req
,
13637 /* EIO should be eaten, and we can't get interrupted in the
13638 * worker, and blocking commits have waited already. */
13642 drm_atomic_helper_wait_for_dependencies(state
);
13644 if (intel_state
->modeset
) {
13645 memcpy(dev_priv
->min_pixclk
, intel_state
->min_pixclk
,
13646 sizeof(intel_state
->min_pixclk
));
13647 dev_priv
->active_crtcs
= intel_state
->active_crtcs
;
13648 dev_priv
->atomic_cdclk_freq
= intel_state
->cdclk
;
13650 intel_display_power_get(dev_priv
, POWER_DOMAIN_MODESET
);
13653 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
13654 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13656 if (needs_modeset(crtc
->state
) ||
13657 to_intel_crtc_state(crtc
->state
)->update_pipe
) {
13660 put_domains
[to_intel_crtc(crtc
)->pipe
] =
13661 modeset_get_crtc_power_domains(crtc
,
13662 to_intel_crtc_state(crtc
->state
));
13665 if (!needs_modeset(crtc
->state
))
13668 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
));
13670 if (old_crtc_state
->active
) {
13671 intel_crtc_disable_planes(crtc
, old_crtc_state
->plane_mask
);
13672 dev_priv
->display
.crtc_disable(crtc
);
13673 intel_crtc
->active
= false;
13674 intel_fbc_disable(intel_crtc
);
13675 intel_disable_shared_dpll(intel_crtc
);
13678 * Underruns don't always raise
13679 * interrupts, so check manually.
13681 intel_check_cpu_fifo_underruns(dev_priv
);
13682 intel_check_pch_fifo_underruns(dev_priv
);
13684 if (!crtc
->state
->active
)
13685 intel_update_watermarks(crtc
);
13689 /* Only after disabling all output pipelines that will be changed can we
13690 * update the the output configuration. */
13691 intel_modeset_update_crtc_state(state
);
13693 if (intel_state
->modeset
) {
13694 drm_atomic_helper_update_legacy_modeset_state(state
->dev
, state
);
13696 if (dev_priv
->display
.modeset_commit_cdclk
&&
13697 (intel_state
->dev_cdclk
!= dev_priv
->cdclk_freq
||
13698 intel_state
->cdclk_pll_vco
!= dev_priv
->cdclk_pll
.vco
))
13699 dev_priv
->display
.modeset_commit_cdclk(state
);
13701 intel_modeset_verify_disabled(dev
);
13704 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
13705 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
13706 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13707 bool modeset
= needs_modeset(crtc
->state
);
13708 struct intel_crtc_state
*pipe_config
=
13709 to_intel_crtc_state(crtc
->state
);
13711 if (modeset
&& crtc
->state
->active
) {
13712 update_scanline_offset(to_intel_crtc(crtc
));
13713 dev_priv
->display
.crtc_enable(crtc
);
13716 /* Complete events for now disable pipes here. */
13717 if (modeset
&& !crtc
->state
->active
&& crtc
->state
->event
) {
13718 spin_lock_irq(&dev
->event_lock
);
13719 drm_crtc_send_vblank_event(crtc
, crtc
->state
->event
);
13720 spin_unlock_irq(&dev
->event_lock
);
13722 crtc
->state
->event
= NULL
;
13726 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
));
13728 if (crtc
->state
->active
&&
13729 drm_atomic_get_existing_plane_state(state
, crtc
->primary
))
13730 intel_fbc_enable(intel_crtc
, pipe_config
, to_intel_plane_state(crtc
->primary
->state
));
13732 if (crtc
->state
->active
)
13733 drm_atomic_helper_commit_planes_on_crtc(old_crtc_state
);
13735 if (pipe_config
->base
.active
&& needs_vblank_wait(pipe_config
))
13736 crtc_vblank_mask
|= 1 << i
;
13739 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
13740 * already, but still need the state for the delayed optimization. To
13742 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
13743 * - schedule that vblank worker _before_ calling hw_done
13744 * - at the start of commit_tail, cancel it _synchrously
13745 * - switch over to the vblank wait helper in the core after that since
13746 * we don't need out special handling any more.
13748 if (!state
->legacy_cursor_update
)
13749 intel_atomic_wait_for_vblanks(dev
, dev_priv
, crtc_vblank_mask
);
13752 * Now that the vblank has passed, we can go ahead and program the
13753 * optimal watermarks on platforms that need two-step watermark
13756 * TODO: Move this (and other cleanup) to an async worker eventually.
13758 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
13759 intel_cstate
= to_intel_crtc_state(crtc
->state
);
13761 if (dev_priv
->display
.optimize_watermarks
)
13762 dev_priv
->display
.optimize_watermarks(intel_cstate
);
13765 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
13766 intel_post_plane_update(to_intel_crtc_state(old_crtc_state
));
13768 if (put_domains
[i
])
13769 modeset_put_power_domains(dev_priv
, put_domains
[i
]);
13771 intel_modeset_verify_crtc(crtc
, old_crtc_state
, crtc
->state
);
13774 drm_atomic_helper_commit_hw_done(state
);
13776 if (intel_state
->modeset
)
13777 intel_display_power_put(dev_priv
, POWER_DOMAIN_MODESET
);
13779 mutex_lock(&dev
->struct_mutex
);
13780 drm_atomic_helper_cleanup_planes(dev
, state
);
13781 mutex_unlock(&dev
->struct_mutex
);
13783 drm_atomic_helper_commit_cleanup_done(state
);
13785 drm_atomic_state_free(state
);
13787 /* As one of the primary mmio accessors, KMS has a high likelihood
13788 * of triggering bugs in unclaimed access. After we finish
13789 * modesetting, see if an error has been flagged, and if so
13790 * enable debugging for the next modeset - and hope we catch
13793 * XXX note that we assume display power is on at this point.
13794 * This might hold true now but we need to add pm helper to check
13795 * unclaimed only when the hardware is on, as atomic commits
13796 * can happen also when the device is completely off.
13798 intel_uncore_arm_unclaimed_mmio_detection(dev_priv
);
13801 static void intel_atomic_commit_work(struct work_struct
*work
)
13803 struct drm_atomic_state
*state
= container_of(work
,
13804 struct drm_atomic_state
,
13806 intel_atomic_commit_tail(state
);
13809 static void intel_atomic_track_fbs(struct drm_atomic_state
*state
)
13811 struct drm_plane_state
*old_plane_state
;
13812 struct drm_plane
*plane
;
13813 struct drm_i915_gem_object
*obj
, *old_obj
;
13814 struct intel_plane
*intel_plane
;
13817 mutex_lock(&state
->dev
->struct_mutex
);
13818 for_each_plane_in_state(state
, plane
, old_plane_state
, i
) {
13819 obj
= intel_fb_obj(plane
->state
->fb
);
13820 old_obj
= intel_fb_obj(old_plane_state
->fb
);
13821 intel_plane
= to_intel_plane(plane
);
13823 i915_gem_track_fb(old_obj
, obj
, intel_plane
->frontbuffer_bit
);
13825 mutex_unlock(&state
->dev
->struct_mutex
);
13829 * intel_atomic_commit - commit validated state object
13831 * @state: the top-level driver state object
13832 * @nonblock: nonblocking commit
13834 * This function commits a top-level state object that has been validated
13835 * with drm_atomic_helper_check().
13837 * FIXME: Atomic modeset support for i915 is not yet complete. At the moment
13838 * nonblocking commits are only safe for pure plane updates. Everything else
13839 * should work though.
13842 * Zero for success or -errno.
13844 static int intel_atomic_commit(struct drm_device
*dev
,
13845 struct drm_atomic_state
*state
,
13848 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
13849 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13852 if (intel_state
->modeset
&& nonblock
) {
13853 DRM_DEBUG_KMS("nonblocking commit for modeset not yet implemented.\n");
13857 ret
= drm_atomic_helper_setup_commit(state
, nonblock
);
13861 INIT_WORK(&state
->commit_work
, intel_atomic_commit_work
);
13863 ret
= intel_atomic_prepare_commit(dev
, state
, nonblock
);
13865 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret
);
13869 drm_atomic_helper_swap_state(state
, true);
13870 dev_priv
->wm
.distrust_bios_wm
= false;
13871 dev_priv
->wm
.skl_results
= intel_state
->wm_results
;
13872 intel_shared_dpll_commit(state
);
13873 intel_atomic_track_fbs(state
);
13876 queue_work(system_unbound_wq
, &state
->commit_work
);
13878 intel_atomic_commit_tail(state
);
13883 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
13885 struct drm_device
*dev
= crtc
->dev
;
13886 struct drm_atomic_state
*state
;
13887 struct drm_crtc_state
*crtc_state
;
13890 state
= drm_atomic_state_alloc(dev
);
13892 DRM_DEBUG_KMS("[CRTC:%d:%s] crtc restore failed, out of memory",
13893 crtc
->base
.id
, crtc
->name
);
13897 state
->acquire_ctx
= drm_modeset_legacy_acquire_ctx(crtc
);
13900 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
13901 ret
= PTR_ERR_OR_ZERO(crtc_state
);
13903 if (!crtc_state
->active
)
13906 crtc_state
->mode_changed
= true;
13907 ret
= drm_atomic_commit(state
);
13910 if (ret
== -EDEADLK
) {
13911 drm_atomic_state_clear(state
);
13912 drm_modeset_backoff(state
->acquire_ctx
);
13918 drm_atomic_state_free(state
);
13921 #undef for_each_intel_crtc_masked
13924 * FIXME: Remove this once i915 is fully DRIVER_ATOMIC by calling
13925 * drm_atomic_helper_legacy_gamma_set() directly.
13927 static int intel_atomic_legacy_gamma_set(struct drm_crtc
*crtc
,
13928 u16
*red
, u16
*green
, u16
*blue
,
13931 struct drm_device
*dev
= crtc
->dev
;
13932 struct drm_mode_config
*config
= &dev
->mode_config
;
13933 struct drm_crtc_state
*state
;
13936 ret
= drm_atomic_helper_legacy_gamma_set(crtc
, red
, green
, blue
, size
);
13941 * Make sure we update the legacy properties so this works when
13942 * atomic is not enabled.
13945 state
= crtc
->state
;
13947 drm_object_property_set_value(&crtc
->base
,
13948 config
->degamma_lut_property
,
13949 (state
->degamma_lut
) ?
13950 state
->degamma_lut
->base
.id
: 0);
13952 drm_object_property_set_value(&crtc
->base
,
13953 config
->ctm_property
,
13955 state
->ctm
->base
.id
: 0);
13957 drm_object_property_set_value(&crtc
->base
,
13958 config
->gamma_lut_property
,
13959 (state
->gamma_lut
) ?
13960 state
->gamma_lut
->base
.id
: 0);
13965 static const struct drm_crtc_funcs intel_crtc_funcs
= {
13966 .gamma_set
= intel_atomic_legacy_gamma_set
,
13967 .set_config
= drm_atomic_helper_set_config
,
13968 .set_property
= drm_atomic_helper_crtc_set_property
,
13969 .destroy
= intel_crtc_destroy
,
13970 .page_flip
= intel_crtc_page_flip
,
13971 .atomic_duplicate_state
= intel_crtc_duplicate_state
,
13972 .atomic_destroy_state
= intel_crtc_destroy_state
,
13976 * intel_prepare_plane_fb - Prepare fb for usage on plane
13977 * @plane: drm plane to prepare for
13978 * @fb: framebuffer to prepare for presentation
13980 * Prepares a framebuffer for usage on a display plane. Generally this
13981 * involves pinning the underlying object and updating the frontbuffer tracking
13982 * bits. Some older platforms need special physical address handling for
13985 * Must be called with struct_mutex held.
13987 * Returns 0 on success, negative error code on failure.
13990 intel_prepare_plane_fb(struct drm_plane
*plane
,
13991 const struct drm_plane_state
*new_state
)
13993 struct drm_device
*dev
= plane
->dev
;
13994 struct drm_framebuffer
*fb
= new_state
->fb
;
13995 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13996 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->state
->fb
);
13997 struct reservation_object
*resv
;
14000 if (!obj
&& !old_obj
)
14004 struct drm_crtc_state
*crtc_state
=
14005 drm_atomic_get_existing_crtc_state(new_state
->state
, plane
->state
->crtc
);
14007 /* Big Hammer, we also need to ensure that any pending
14008 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
14009 * current scanout is retired before unpinning the old
14010 * framebuffer. Note that we rely on userspace rendering
14011 * into the buffer attached to the pipe they are waiting
14012 * on. If not, userspace generates a GPU hang with IPEHR
14013 * point to the MI_WAIT_FOR_EVENT.
14015 * This should only fail upon a hung GPU, in which case we
14016 * can safely continue.
14018 if (needs_modeset(crtc_state
))
14019 ret
= i915_gem_object_wait_rendering(old_obj
, true);
14021 /* GPU hangs should have been swallowed by the wait */
14022 WARN_ON(ret
== -EIO
);
14030 /* For framebuffer backed by dmabuf, wait for fence */
14031 resv
= i915_gem_object_get_dmabuf_resv(obj
);
14035 lret
= reservation_object_wait_timeout_rcu(resv
, false, true,
14036 MAX_SCHEDULE_TIMEOUT
);
14037 if (lret
== -ERESTARTSYS
)
14040 WARN(lret
< 0, "waiting returns %li\n", lret
);
14043 if (plane
->type
== DRM_PLANE_TYPE_CURSOR
&&
14044 INTEL_INFO(dev
)->cursor_needs_physical
) {
14045 int align
= IS_I830(dev
) ? 16 * 1024 : 256;
14046 ret
= i915_gem_object_attach_phys(obj
, align
);
14048 DRM_DEBUG_KMS("failed to attach phys object\n");
14050 ret
= intel_pin_and_fence_fb_obj(fb
, new_state
->rotation
);
14054 to_intel_plane_state(new_state
)->wait_req
=
14055 i915_gem_active_get(&obj
->last_write
,
14056 &obj
->base
.dev
->struct_mutex
);
14063 * intel_cleanup_plane_fb - Cleans up an fb after plane use
14064 * @plane: drm plane to clean up for
14065 * @fb: old framebuffer that was on plane
14067 * Cleans up a framebuffer that has just been removed from a plane.
14069 * Must be called with struct_mutex held.
14072 intel_cleanup_plane_fb(struct drm_plane
*plane
,
14073 const struct drm_plane_state
*old_state
)
14075 struct drm_device
*dev
= plane
->dev
;
14076 struct intel_plane_state
*old_intel_state
;
14077 struct intel_plane_state
*intel_state
= to_intel_plane_state(plane
->state
);
14078 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(old_state
->fb
);
14079 struct drm_i915_gem_object
*obj
= intel_fb_obj(plane
->state
->fb
);
14081 old_intel_state
= to_intel_plane_state(old_state
);
14083 if (!obj
&& !old_obj
)
14086 if (old_obj
&& (plane
->type
!= DRM_PLANE_TYPE_CURSOR
||
14087 !INTEL_INFO(dev
)->cursor_needs_physical
))
14088 intel_unpin_fb_obj(old_state
->fb
, old_state
->rotation
);
14090 i915_gem_request_assign(&intel_state
->wait_req
, NULL
);
14091 i915_gem_request_assign(&old_intel_state
->wait_req
, NULL
);
14095 skl_max_scale(struct intel_crtc
*intel_crtc
, struct intel_crtc_state
*crtc_state
)
14098 int crtc_clock
, cdclk
;
14100 if (!intel_crtc
|| !crtc_state
->base
.enable
)
14101 return DRM_PLANE_HELPER_NO_SCALING
;
14103 crtc_clock
= crtc_state
->base
.adjusted_mode
.crtc_clock
;
14104 cdclk
= to_intel_atomic_state(crtc_state
->base
.state
)->cdclk
;
14106 if (WARN_ON_ONCE(!crtc_clock
|| cdclk
< crtc_clock
))
14107 return DRM_PLANE_HELPER_NO_SCALING
;
14110 * skl max scale is lower of:
14111 * close to 3 but not 3, -1 is for that purpose
14115 max_scale
= min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk
<< 8) / crtc_clock
));
14121 intel_check_primary_plane(struct drm_plane
*plane
,
14122 struct intel_crtc_state
*crtc_state
,
14123 struct intel_plane_state
*state
)
14125 struct drm_crtc
*crtc
= state
->base
.crtc
;
14126 struct drm_framebuffer
*fb
= state
->base
.fb
;
14127 int min_scale
= DRM_PLANE_HELPER_NO_SCALING
;
14128 int max_scale
= DRM_PLANE_HELPER_NO_SCALING
;
14129 bool can_position
= false;
14131 if (INTEL_INFO(plane
->dev
)->gen
>= 9) {
14132 /* use scaler when colorkey is not required */
14133 if (state
->ckey
.flags
== I915_SET_COLORKEY_NONE
) {
14135 max_scale
= skl_max_scale(to_intel_crtc(crtc
), crtc_state
);
14137 can_position
= true;
14140 return drm_plane_helper_check_update(plane
, crtc
, fb
, &state
->src
,
14141 &state
->dst
, &state
->clip
,
14142 state
->base
.rotation
,
14143 min_scale
, max_scale
,
14144 can_position
, true,
14148 static void intel_begin_crtc_commit(struct drm_crtc
*crtc
,
14149 struct drm_crtc_state
*old_crtc_state
)
14151 struct drm_device
*dev
= crtc
->dev
;
14152 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
14153 struct intel_crtc_state
*old_intel_state
=
14154 to_intel_crtc_state(old_crtc_state
);
14155 bool modeset
= needs_modeset(crtc
->state
);
14157 /* Perform vblank evasion around commit operation */
14158 intel_pipe_update_start(intel_crtc
);
14163 if (crtc
->state
->color_mgmt_changed
|| to_intel_crtc_state(crtc
->state
)->update_pipe
) {
14164 intel_color_set_csc(crtc
->state
);
14165 intel_color_load_luts(crtc
->state
);
14168 if (to_intel_crtc_state(crtc
->state
)->update_pipe
)
14169 intel_update_pipe_config(intel_crtc
, old_intel_state
);
14170 else if (INTEL_INFO(dev
)->gen
>= 9)
14171 skl_detach_scalers(intel_crtc
);
14174 static void intel_finish_crtc_commit(struct drm_crtc
*crtc
,
14175 struct drm_crtc_state
*old_crtc_state
)
14177 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
14179 intel_pipe_update_end(intel_crtc
, NULL
);
14183 * intel_plane_destroy - destroy a plane
14184 * @plane: plane to destroy
14186 * Common destruction function for all types of planes (primary, cursor,
14189 void intel_plane_destroy(struct drm_plane
*plane
)
14194 drm_plane_cleanup(plane
);
14195 kfree(to_intel_plane(plane
));
14198 const struct drm_plane_funcs intel_plane_funcs
= {
14199 .update_plane
= drm_atomic_helper_update_plane
,
14200 .disable_plane
= drm_atomic_helper_disable_plane
,
14201 .destroy
= intel_plane_destroy
,
14202 .set_property
= drm_atomic_helper_plane_set_property
,
14203 .atomic_get_property
= intel_plane_atomic_get_property
,
14204 .atomic_set_property
= intel_plane_atomic_set_property
,
14205 .atomic_duplicate_state
= intel_plane_duplicate_state
,
14206 .atomic_destroy_state
= intel_plane_destroy_state
,
14210 static struct drm_plane
*intel_primary_plane_create(struct drm_device
*dev
,
14213 struct intel_plane
*primary
= NULL
;
14214 struct intel_plane_state
*state
= NULL
;
14215 const uint32_t *intel_primary_formats
;
14216 unsigned int num_formats
;
14219 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
14223 state
= intel_create_plane_state(&primary
->base
);
14226 primary
->base
.state
= &state
->base
;
14228 primary
->can_scale
= false;
14229 primary
->max_downscale
= 1;
14230 if (INTEL_INFO(dev
)->gen
>= 9) {
14231 primary
->can_scale
= true;
14232 state
->scaler_id
= -1;
14234 primary
->pipe
= pipe
;
14235 primary
->plane
= pipe
;
14236 primary
->frontbuffer_bit
= INTEL_FRONTBUFFER_PRIMARY(pipe
);
14237 primary
->check_plane
= intel_check_primary_plane
;
14238 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4)
14239 primary
->plane
= !pipe
;
14241 if (INTEL_INFO(dev
)->gen
>= 9) {
14242 intel_primary_formats
= skl_primary_formats
;
14243 num_formats
= ARRAY_SIZE(skl_primary_formats
);
14245 primary
->update_plane
= skylake_update_primary_plane
;
14246 primary
->disable_plane
= skylake_disable_primary_plane
;
14247 } else if (HAS_PCH_SPLIT(dev
)) {
14248 intel_primary_formats
= i965_primary_formats
;
14249 num_formats
= ARRAY_SIZE(i965_primary_formats
);
14251 primary
->update_plane
= ironlake_update_primary_plane
;
14252 primary
->disable_plane
= i9xx_disable_primary_plane
;
14253 } else if (INTEL_INFO(dev
)->gen
>= 4) {
14254 intel_primary_formats
= i965_primary_formats
;
14255 num_formats
= ARRAY_SIZE(i965_primary_formats
);
14257 primary
->update_plane
= i9xx_update_primary_plane
;
14258 primary
->disable_plane
= i9xx_disable_primary_plane
;
14260 intel_primary_formats
= i8xx_primary_formats
;
14261 num_formats
= ARRAY_SIZE(i8xx_primary_formats
);
14263 primary
->update_plane
= i9xx_update_primary_plane
;
14264 primary
->disable_plane
= i9xx_disable_primary_plane
;
14267 if (INTEL_INFO(dev
)->gen
>= 9)
14268 ret
= drm_universal_plane_init(dev
, &primary
->base
, 0,
14269 &intel_plane_funcs
,
14270 intel_primary_formats
, num_formats
,
14271 DRM_PLANE_TYPE_PRIMARY
,
14272 "plane 1%c", pipe_name(pipe
));
14273 else if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
14274 ret
= drm_universal_plane_init(dev
, &primary
->base
, 0,
14275 &intel_plane_funcs
,
14276 intel_primary_formats
, num_formats
,
14277 DRM_PLANE_TYPE_PRIMARY
,
14278 "primary %c", pipe_name(pipe
));
14280 ret
= drm_universal_plane_init(dev
, &primary
->base
, 0,
14281 &intel_plane_funcs
,
14282 intel_primary_formats
, num_formats
,
14283 DRM_PLANE_TYPE_PRIMARY
,
14284 "plane %c", plane_name(primary
->plane
));
14288 if (INTEL_INFO(dev
)->gen
>= 4)
14289 intel_create_rotation_property(dev
, primary
);
14291 drm_plane_helper_add(&primary
->base
, &intel_plane_helper_funcs
);
14293 return &primary
->base
;
14302 void intel_create_rotation_property(struct drm_device
*dev
, struct intel_plane
*plane
)
14304 if (!dev
->mode_config
.rotation_property
) {
14305 unsigned long flags
= BIT(DRM_ROTATE_0
) |
14306 BIT(DRM_ROTATE_180
);
14308 if (INTEL_INFO(dev
)->gen
>= 9)
14309 flags
|= BIT(DRM_ROTATE_90
) | BIT(DRM_ROTATE_270
);
14311 dev
->mode_config
.rotation_property
=
14312 drm_mode_create_rotation_property(dev
, flags
);
14314 if (dev
->mode_config
.rotation_property
)
14315 drm_object_attach_property(&plane
->base
.base
,
14316 dev
->mode_config
.rotation_property
,
14317 plane
->base
.state
->rotation
);
14321 intel_check_cursor_plane(struct drm_plane
*plane
,
14322 struct intel_crtc_state
*crtc_state
,
14323 struct intel_plane_state
*state
)
14325 struct drm_crtc
*crtc
= crtc_state
->base
.crtc
;
14326 struct drm_framebuffer
*fb
= state
->base
.fb
;
14327 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
14328 enum pipe pipe
= to_intel_plane(plane
)->pipe
;
14332 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
, &state
->src
,
14333 &state
->dst
, &state
->clip
,
14334 state
->base
.rotation
,
14335 DRM_PLANE_HELPER_NO_SCALING
,
14336 DRM_PLANE_HELPER_NO_SCALING
,
14337 true, true, &state
->visible
);
14341 /* if we want to turn off the cursor ignore width and height */
14345 /* Check for which cursor types we support */
14346 if (!cursor_size_ok(plane
->dev
, state
->base
.crtc_w
, state
->base
.crtc_h
)) {
14347 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
14348 state
->base
.crtc_w
, state
->base
.crtc_h
);
14352 stride
= roundup_pow_of_two(state
->base
.crtc_w
) * 4;
14353 if (obj
->base
.size
< stride
* state
->base
.crtc_h
) {
14354 DRM_DEBUG_KMS("buffer is too small\n");
14358 if (fb
->modifier
[0] != DRM_FORMAT_MOD_NONE
) {
14359 DRM_DEBUG_KMS("cursor cannot be tiled\n");
14364 * There's something wrong with the cursor on CHV pipe C.
14365 * If it straddles the left edge of the screen then
14366 * moving it away from the edge or disabling it often
14367 * results in a pipe underrun, and often that can lead to
14368 * dead pipe (constant underrun reported, and it scans
14369 * out just a solid color). To recover from that, the
14370 * display power well must be turned off and on again.
14371 * Refuse the put the cursor into that compromised position.
14373 if (IS_CHERRYVIEW(plane
->dev
) && pipe
== PIPE_C
&&
14374 state
->visible
&& state
->base
.crtc_x
< 0) {
14375 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
14383 intel_disable_cursor_plane(struct drm_plane
*plane
,
14384 struct drm_crtc
*crtc
)
14386 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
14388 intel_crtc
->cursor_addr
= 0;
14389 intel_crtc_update_cursor(crtc
, NULL
);
14393 intel_update_cursor_plane(struct drm_plane
*plane
,
14394 const struct intel_crtc_state
*crtc_state
,
14395 const struct intel_plane_state
*state
)
14397 struct drm_crtc
*crtc
= crtc_state
->base
.crtc
;
14398 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
14399 struct drm_device
*dev
= plane
->dev
;
14400 struct drm_i915_gem_object
*obj
= intel_fb_obj(state
->base
.fb
);
14405 else if (!INTEL_INFO(dev
)->cursor_needs_physical
)
14406 addr
= i915_gem_obj_ggtt_offset(obj
);
14408 addr
= obj
->phys_handle
->busaddr
;
14410 intel_crtc
->cursor_addr
= addr
;
14411 intel_crtc_update_cursor(crtc
, state
);
14414 static struct drm_plane
*intel_cursor_plane_create(struct drm_device
*dev
,
14417 struct intel_plane
*cursor
= NULL
;
14418 struct intel_plane_state
*state
= NULL
;
14421 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
14425 state
= intel_create_plane_state(&cursor
->base
);
14428 cursor
->base
.state
= &state
->base
;
14430 cursor
->can_scale
= false;
14431 cursor
->max_downscale
= 1;
14432 cursor
->pipe
= pipe
;
14433 cursor
->plane
= pipe
;
14434 cursor
->frontbuffer_bit
= INTEL_FRONTBUFFER_CURSOR(pipe
);
14435 cursor
->check_plane
= intel_check_cursor_plane
;
14436 cursor
->update_plane
= intel_update_cursor_plane
;
14437 cursor
->disable_plane
= intel_disable_cursor_plane
;
14439 ret
= drm_universal_plane_init(dev
, &cursor
->base
, 0,
14440 &intel_plane_funcs
,
14441 intel_cursor_formats
,
14442 ARRAY_SIZE(intel_cursor_formats
),
14443 DRM_PLANE_TYPE_CURSOR
,
14444 "cursor %c", pipe_name(pipe
));
14448 if (INTEL_INFO(dev
)->gen
>= 4) {
14449 if (!dev
->mode_config
.rotation_property
)
14450 dev
->mode_config
.rotation_property
=
14451 drm_mode_create_rotation_property(dev
,
14452 BIT(DRM_ROTATE_0
) |
14453 BIT(DRM_ROTATE_180
));
14454 if (dev
->mode_config
.rotation_property
)
14455 drm_object_attach_property(&cursor
->base
.base
,
14456 dev
->mode_config
.rotation_property
,
14457 state
->base
.rotation
);
14460 if (INTEL_INFO(dev
)->gen
>=9)
14461 state
->scaler_id
= -1;
14463 drm_plane_helper_add(&cursor
->base
, &intel_plane_helper_funcs
);
14465 return &cursor
->base
;
14474 static void skl_init_scalers(struct drm_device
*dev
, struct intel_crtc
*intel_crtc
,
14475 struct intel_crtc_state
*crtc_state
)
14478 struct intel_scaler
*intel_scaler
;
14479 struct intel_crtc_scaler_state
*scaler_state
= &crtc_state
->scaler_state
;
14481 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
14482 intel_scaler
= &scaler_state
->scalers
[i
];
14483 intel_scaler
->in_use
= 0;
14484 intel_scaler
->mode
= PS_SCALER_MODE_DYN
;
14487 scaler_state
->scaler_id
= -1;
14490 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
14492 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14493 struct intel_crtc
*intel_crtc
;
14494 struct intel_crtc_state
*crtc_state
= NULL
;
14495 struct drm_plane
*primary
= NULL
;
14496 struct drm_plane
*cursor
= NULL
;
14499 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
14500 if (intel_crtc
== NULL
)
14503 crtc_state
= kzalloc(sizeof(*crtc_state
), GFP_KERNEL
);
14506 intel_crtc
->config
= crtc_state
;
14507 intel_crtc
->base
.state
= &crtc_state
->base
;
14508 crtc_state
->base
.crtc
= &intel_crtc
->base
;
14510 /* initialize shared scalers */
14511 if (INTEL_INFO(dev
)->gen
>= 9) {
14512 if (pipe
== PIPE_C
)
14513 intel_crtc
->num_scalers
= 1;
14515 intel_crtc
->num_scalers
= SKL_NUM_SCALERS
;
14517 skl_init_scalers(dev
, intel_crtc
, crtc_state
);
14520 primary
= intel_primary_plane_create(dev
, pipe
);
14524 cursor
= intel_cursor_plane_create(dev
, pipe
);
14528 ret
= drm_crtc_init_with_planes(dev
, &intel_crtc
->base
, primary
,
14529 cursor
, &intel_crtc_funcs
,
14530 "pipe %c", pipe_name(pipe
));
14535 * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
14536 * is hooked to pipe B. Hence we want plane A feeding pipe B.
14538 intel_crtc
->pipe
= pipe
;
14539 intel_crtc
->plane
= pipe
;
14540 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4) {
14541 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
14542 intel_crtc
->plane
= !pipe
;
14545 intel_crtc
->cursor_base
= ~0;
14546 intel_crtc
->cursor_cntl
= ~0;
14547 intel_crtc
->cursor_size
= ~0;
14549 intel_crtc
->wm
.cxsr_allowed
= true;
14551 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
14552 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
14553 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
14554 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
14556 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
14558 intel_color_init(&intel_crtc
->base
);
14560 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
14564 intel_plane_destroy(primary
);
14565 intel_plane_destroy(cursor
);
14570 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
14572 struct drm_encoder
*encoder
= connector
->base
.encoder
;
14573 struct drm_device
*dev
= connector
->base
.dev
;
14575 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
14577 if (!encoder
|| WARN_ON(!encoder
->crtc
))
14578 return INVALID_PIPE
;
14580 return to_intel_crtc(encoder
->crtc
)->pipe
;
14583 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
14584 struct drm_file
*file
)
14586 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
14587 struct drm_crtc
*drmmode_crtc
;
14588 struct intel_crtc
*crtc
;
14590 drmmode_crtc
= drm_crtc_find(dev
, pipe_from_crtc_id
->crtc_id
);
14594 crtc
= to_intel_crtc(drmmode_crtc
);
14595 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
14600 static int intel_encoder_clones(struct intel_encoder
*encoder
)
14602 struct drm_device
*dev
= encoder
->base
.dev
;
14603 struct intel_encoder
*source_encoder
;
14604 int index_mask
= 0;
14607 for_each_intel_encoder(dev
, source_encoder
) {
14608 if (encoders_cloneable(encoder
, source_encoder
))
14609 index_mask
|= (1 << entry
);
14617 static bool has_edp_a(struct drm_device
*dev
)
14619 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14621 if (!IS_MOBILE(dev
))
14624 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
14627 if (IS_GEN5(dev
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
14633 static bool intel_crt_present(struct drm_device
*dev
)
14635 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14637 if (INTEL_INFO(dev
)->gen
>= 9)
14640 if (IS_HSW_ULT(dev
) || IS_BDW_ULT(dev
))
14643 if (IS_CHERRYVIEW(dev
))
14646 if (HAS_PCH_LPT_H(dev
) && I915_READ(SFUSE_STRAP
) & SFUSE_STRAP_CRT_DISABLED
)
14649 /* DDI E can't be used if DDI A requires 4 lanes */
14650 if (HAS_DDI(dev
) && I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_A_4_LANES
)
14653 if (!dev_priv
->vbt
.int_crt_support
)
14659 static void intel_setup_outputs(struct drm_device
*dev
)
14661 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14662 struct intel_encoder
*encoder
;
14663 bool dpd_is_edp
= false;
14666 * intel_edp_init_connector() depends on this completing first, to
14667 * prevent the registeration of both eDP and LVDS and the incorrect
14668 * sharing of the PPS.
14670 intel_lvds_init(dev
);
14672 if (intel_crt_present(dev
))
14673 intel_crt_init(dev
);
14675 if (IS_BROXTON(dev
)) {
14677 * FIXME: Broxton doesn't support port detection via the
14678 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
14679 * detect the ports.
14681 intel_ddi_init(dev
, PORT_A
);
14682 intel_ddi_init(dev
, PORT_B
);
14683 intel_ddi_init(dev
, PORT_C
);
14685 intel_dsi_init(dev
);
14686 } else if (HAS_DDI(dev
)) {
14690 * Haswell uses DDI functions to detect digital outputs.
14691 * On SKL pre-D0 the strap isn't connected, so we assume
14694 found
= I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_INIT_DISPLAY_DETECTED
;
14695 /* WaIgnoreDDIAStrap: skl */
14696 if (found
|| IS_SKYLAKE(dev
) || IS_KABYLAKE(dev
))
14697 intel_ddi_init(dev
, PORT_A
);
14699 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
14701 found
= I915_READ(SFUSE_STRAP
);
14703 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
14704 intel_ddi_init(dev
, PORT_B
);
14705 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
14706 intel_ddi_init(dev
, PORT_C
);
14707 if (found
& SFUSE_STRAP_DDID_DETECTED
)
14708 intel_ddi_init(dev
, PORT_D
);
14710 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14712 if ((IS_SKYLAKE(dev
) || IS_KABYLAKE(dev
)) &&
14713 (dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dp
||
14714 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dvi
||
14715 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_hdmi
))
14716 intel_ddi_init(dev
, PORT_E
);
14718 } else if (HAS_PCH_SPLIT(dev
)) {
14720 dpd_is_edp
= intel_dp_is_edp(dev
, PORT_D
);
14722 if (has_edp_a(dev
))
14723 intel_dp_init(dev
, DP_A
, PORT_A
);
14725 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
14726 /* PCH SDVOB multiplex with HDMIB */
14727 found
= intel_sdvo_init(dev
, PCH_SDVOB
, PORT_B
);
14729 intel_hdmi_init(dev
, PCH_HDMIB
, PORT_B
);
14730 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
14731 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
14734 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
14735 intel_hdmi_init(dev
, PCH_HDMIC
, PORT_C
);
14737 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
14738 intel_hdmi_init(dev
, PCH_HDMID
, PORT_D
);
14740 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
14741 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
14743 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
14744 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
14745 } else if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
14746 bool has_edp
, has_port
;
14749 * The DP_DETECTED bit is the latched state of the DDC
14750 * SDA pin at boot. However since eDP doesn't require DDC
14751 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14752 * eDP ports may have been muxed to an alternate function.
14753 * Thus we can't rely on the DP_DETECTED bit alone to detect
14754 * eDP ports. Consult the VBT as well as DP_DETECTED to
14755 * detect eDP ports.
14757 * Sadly the straps seem to be missing sometimes even for HDMI
14758 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
14759 * and VBT for the presence of the port. Additionally we can't
14760 * trust the port type the VBT declares as we've seen at least
14761 * HDMI ports that the VBT claim are DP or eDP.
14763 has_edp
= intel_dp_is_edp(dev
, PORT_B
);
14764 has_port
= intel_bios_is_port_present(dev_priv
, PORT_B
);
14765 if (I915_READ(VLV_DP_B
) & DP_DETECTED
|| has_port
)
14766 has_edp
&= intel_dp_init(dev
, VLV_DP_B
, PORT_B
);
14767 if ((I915_READ(VLV_HDMIB
) & SDVO_DETECTED
|| has_port
) && !has_edp
)
14768 intel_hdmi_init(dev
, VLV_HDMIB
, PORT_B
);
14770 has_edp
= intel_dp_is_edp(dev
, PORT_C
);
14771 has_port
= intel_bios_is_port_present(dev_priv
, PORT_C
);
14772 if (I915_READ(VLV_DP_C
) & DP_DETECTED
|| has_port
)
14773 has_edp
&= intel_dp_init(dev
, VLV_DP_C
, PORT_C
);
14774 if ((I915_READ(VLV_HDMIC
) & SDVO_DETECTED
|| has_port
) && !has_edp
)
14775 intel_hdmi_init(dev
, VLV_HDMIC
, PORT_C
);
14777 if (IS_CHERRYVIEW(dev
)) {
14779 * eDP not supported on port D,
14780 * so no need to worry about it
14782 has_port
= intel_bios_is_port_present(dev_priv
, PORT_D
);
14783 if (I915_READ(CHV_DP_D
) & DP_DETECTED
|| has_port
)
14784 intel_dp_init(dev
, CHV_DP_D
, PORT_D
);
14785 if (I915_READ(CHV_HDMID
) & SDVO_DETECTED
|| has_port
)
14786 intel_hdmi_init(dev
, CHV_HDMID
, PORT_D
);
14789 intel_dsi_init(dev
);
14790 } else if (!IS_GEN2(dev
) && !IS_PINEVIEW(dev
)) {
14791 bool found
= false;
14793 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
14794 DRM_DEBUG_KMS("probing SDVOB\n");
14795 found
= intel_sdvo_init(dev
, GEN3_SDVOB
, PORT_B
);
14796 if (!found
&& IS_G4X(dev
)) {
14797 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
14798 intel_hdmi_init(dev
, GEN4_HDMIB
, PORT_B
);
14801 if (!found
&& IS_G4X(dev
))
14802 intel_dp_init(dev
, DP_B
, PORT_B
);
14805 /* Before G4X SDVOC doesn't have its own detect register */
14807 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
14808 DRM_DEBUG_KMS("probing SDVOC\n");
14809 found
= intel_sdvo_init(dev
, GEN3_SDVOC
, PORT_C
);
14812 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
14815 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
14816 intel_hdmi_init(dev
, GEN4_HDMIC
, PORT_C
);
14819 intel_dp_init(dev
, DP_C
, PORT_C
);
14823 (I915_READ(DP_D
) & DP_DETECTED
))
14824 intel_dp_init(dev
, DP_D
, PORT_D
);
14825 } else if (IS_GEN2(dev
))
14826 intel_dvo_init(dev
);
14828 if (SUPPORTS_TV(dev
))
14829 intel_tv_init(dev
);
14831 intel_psr_init(dev
);
14833 for_each_intel_encoder(dev
, encoder
) {
14834 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
14835 encoder
->base
.possible_clones
=
14836 intel_encoder_clones(encoder
);
14839 intel_init_pch_refclk(dev
);
14841 drm_helper_move_panel_connectors_to_head(dev
);
14844 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
14846 struct drm_device
*dev
= fb
->dev
;
14847 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
14849 drm_framebuffer_cleanup(fb
);
14850 mutex_lock(&dev
->struct_mutex
);
14851 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
14852 i915_gem_object_put(intel_fb
->obj
);
14853 mutex_unlock(&dev
->struct_mutex
);
14857 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
14858 struct drm_file
*file
,
14859 unsigned int *handle
)
14861 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
14862 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
14864 if (obj
->userptr
.mm
) {
14865 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14869 return drm_gem_handle_create(file
, &obj
->base
, handle
);
14872 static int intel_user_framebuffer_dirty(struct drm_framebuffer
*fb
,
14873 struct drm_file
*file
,
14874 unsigned flags
, unsigned color
,
14875 struct drm_clip_rect
*clips
,
14876 unsigned num_clips
)
14878 struct drm_device
*dev
= fb
->dev
;
14879 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
14880 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
14882 mutex_lock(&dev
->struct_mutex
);
14883 intel_fb_obj_flush(obj
, false, ORIGIN_DIRTYFB
);
14884 mutex_unlock(&dev
->struct_mutex
);
14889 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
14890 .destroy
= intel_user_framebuffer_destroy
,
14891 .create_handle
= intel_user_framebuffer_create_handle
,
14892 .dirty
= intel_user_framebuffer_dirty
,
14896 u32
intel_fb_pitch_limit(struct drm_device
*dev
, uint64_t fb_modifier
,
14897 uint32_t pixel_format
)
14899 u32 gen
= INTEL_INFO(dev
)->gen
;
14902 int cpp
= drm_format_plane_cpp(pixel_format
, 0);
14904 /* "The stride in bytes must not exceed the of the size of 8K
14905 * pixels and 32K bytes."
14907 return min(8192 * cpp
, 32768);
14908 } else if (gen
>= 5 && !IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
)) {
14910 } else if (gen
>= 4) {
14911 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
14915 } else if (gen
>= 3) {
14916 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
14921 /* XXX DSPC is limited to 4k tiled */
14926 static int intel_framebuffer_init(struct drm_device
*dev
,
14927 struct intel_framebuffer
*intel_fb
,
14928 struct drm_mode_fb_cmd2
*mode_cmd
,
14929 struct drm_i915_gem_object
*obj
)
14931 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14932 unsigned int aligned_height
;
14934 u32 pitch_limit
, stride_alignment
;
14936 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
14938 if (mode_cmd
->flags
& DRM_MODE_FB_MODIFIERS
) {
14939 /* Enforce that fb modifier and tiling mode match, but only for
14940 * X-tiled. This is needed for FBC. */
14941 if (!!(obj
->tiling_mode
== I915_TILING_X
) !=
14942 !!(mode_cmd
->modifier
[0] == I915_FORMAT_MOD_X_TILED
)) {
14943 DRM_DEBUG("tiling_mode doesn't match fb modifier\n");
14947 if (obj
->tiling_mode
== I915_TILING_X
)
14948 mode_cmd
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
14949 else if (obj
->tiling_mode
== I915_TILING_Y
) {
14950 DRM_DEBUG("No Y tiling for legacy addfb\n");
14955 /* Passed in modifier sanity checking. */
14956 switch (mode_cmd
->modifier
[0]) {
14957 case I915_FORMAT_MOD_Y_TILED
:
14958 case I915_FORMAT_MOD_Yf_TILED
:
14959 if (INTEL_INFO(dev
)->gen
< 9) {
14960 DRM_DEBUG("Unsupported tiling 0x%llx!\n",
14961 mode_cmd
->modifier
[0]);
14964 case DRM_FORMAT_MOD_NONE
:
14965 case I915_FORMAT_MOD_X_TILED
:
14968 DRM_DEBUG("Unsupported fb modifier 0x%llx!\n",
14969 mode_cmd
->modifier
[0]);
14973 stride_alignment
= intel_fb_stride_alignment(dev_priv
,
14974 mode_cmd
->modifier
[0],
14975 mode_cmd
->pixel_format
);
14976 if (mode_cmd
->pitches
[0] & (stride_alignment
- 1)) {
14977 DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n",
14978 mode_cmd
->pitches
[0], stride_alignment
);
14982 pitch_limit
= intel_fb_pitch_limit(dev
, mode_cmd
->modifier
[0],
14983 mode_cmd
->pixel_format
);
14984 if (mode_cmd
->pitches
[0] > pitch_limit
) {
14985 DRM_DEBUG("%s pitch (%u) must be at less than %d\n",
14986 mode_cmd
->modifier
[0] != DRM_FORMAT_MOD_NONE
?
14987 "tiled" : "linear",
14988 mode_cmd
->pitches
[0], pitch_limit
);
14992 if (mode_cmd
->modifier
[0] == I915_FORMAT_MOD_X_TILED
&&
14993 mode_cmd
->pitches
[0] != obj
->stride
) {
14994 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
14995 mode_cmd
->pitches
[0], obj
->stride
);
14999 /* Reject formats not supported by any plane early. */
15000 switch (mode_cmd
->pixel_format
) {
15001 case DRM_FORMAT_C8
:
15002 case DRM_FORMAT_RGB565
:
15003 case DRM_FORMAT_XRGB8888
:
15004 case DRM_FORMAT_ARGB8888
:
15006 case DRM_FORMAT_XRGB1555
:
15007 if (INTEL_INFO(dev
)->gen
> 3) {
15008 DRM_DEBUG("unsupported pixel format: %s\n",
15009 drm_get_format_name(mode_cmd
->pixel_format
));
15013 case DRM_FORMAT_ABGR8888
:
15014 if (!IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
) &&
15015 INTEL_INFO(dev
)->gen
< 9) {
15016 DRM_DEBUG("unsupported pixel format: %s\n",
15017 drm_get_format_name(mode_cmd
->pixel_format
));
15021 case DRM_FORMAT_XBGR8888
:
15022 case DRM_FORMAT_XRGB2101010
:
15023 case DRM_FORMAT_XBGR2101010
:
15024 if (INTEL_INFO(dev
)->gen
< 4) {
15025 DRM_DEBUG("unsupported pixel format: %s\n",
15026 drm_get_format_name(mode_cmd
->pixel_format
));
15030 case DRM_FORMAT_ABGR2101010
:
15031 if (!IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
)) {
15032 DRM_DEBUG("unsupported pixel format: %s\n",
15033 drm_get_format_name(mode_cmd
->pixel_format
));
15037 case DRM_FORMAT_YUYV
:
15038 case DRM_FORMAT_UYVY
:
15039 case DRM_FORMAT_YVYU
:
15040 case DRM_FORMAT_VYUY
:
15041 if (INTEL_INFO(dev
)->gen
< 5) {
15042 DRM_DEBUG("unsupported pixel format: %s\n",
15043 drm_get_format_name(mode_cmd
->pixel_format
));
15048 DRM_DEBUG("unsupported pixel format: %s\n",
15049 drm_get_format_name(mode_cmd
->pixel_format
));
15053 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
15054 if (mode_cmd
->offsets
[0] != 0)
15057 aligned_height
= intel_fb_align_height(dev
, mode_cmd
->height
,
15058 mode_cmd
->pixel_format
,
15059 mode_cmd
->modifier
[0]);
15060 /* FIXME drm helper for size checks (especially planar formats)? */
15061 if (obj
->base
.size
< aligned_height
* mode_cmd
->pitches
[0])
15064 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
15065 intel_fb
->obj
= obj
;
15067 intel_fill_fb_info(dev_priv
, &intel_fb
->base
);
15069 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
15071 DRM_ERROR("framebuffer init failed %d\n", ret
);
15075 intel_fb
->obj
->framebuffer_references
++;
15080 static struct drm_framebuffer
*
15081 intel_user_framebuffer_create(struct drm_device
*dev
,
15082 struct drm_file
*filp
,
15083 const struct drm_mode_fb_cmd2
*user_mode_cmd
)
15085 struct drm_framebuffer
*fb
;
15086 struct drm_i915_gem_object
*obj
;
15087 struct drm_mode_fb_cmd2 mode_cmd
= *user_mode_cmd
;
15089 obj
= i915_gem_object_lookup(filp
, mode_cmd
.handles
[0]);
15091 return ERR_PTR(-ENOENT
);
15093 fb
= intel_framebuffer_create(dev
, &mode_cmd
, obj
);
15095 i915_gem_object_put_unlocked(obj
);
15100 #ifndef CONFIG_DRM_FBDEV_EMULATION
15101 static inline void intel_fbdev_output_poll_changed(struct drm_device
*dev
)
15106 static const struct drm_mode_config_funcs intel_mode_funcs
= {
15107 .fb_create
= intel_user_framebuffer_create
,
15108 .output_poll_changed
= intel_fbdev_output_poll_changed
,
15109 .atomic_check
= intel_atomic_check
,
15110 .atomic_commit
= intel_atomic_commit
,
15111 .atomic_state_alloc
= intel_atomic_state_alloc
,
15112 .atomic_state_clear
= intel_atomic_state_clear
,
15116 * intel_init_display_hooks - initialize the display modesetting hooks
15117 * @dev_priv: device private
15119 void intel_init_display_hooks(struct drm_i915_private
*dev_priv
)
15121 if (INTEL_INFO(dev_priv
)->gen
>= 9) {
15122 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
15123 dev_priv
->display
.get_initial_plane_config
=
15124 skylake_get_initial_plane_config
;
15125 dev_priv
->display
.crtc_compute_clock
=
15126 haswell_crtc_compute_clock
;
15127 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
15128 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
15129 } else if (HAS_DDI(dev_priv
)) {
15130 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
15131 dev_priv
->display
.get_initial_plane_config
=
15132 ironlake_get_initial_plane_config
;
15133 dev_priv
->display
.crtc_compute_clock
=
15134 haswell_crtc_compute_clock
;
15135 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
15136 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
15137 } else if (HAS_PCH_SPLIT(dev_priv
)) {
15138 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
15139 dev_priv
->display
.get_initial_plane_config
=
15140 ironlake_get_initial_plane_config
;
15141 dev_priv
->display
.crtc_compute_clock
=
15142 ironlake_crtc_compute_clock
;
15143 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
15144 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
15145 } else if (IS_CHERRYVIEW(dev_priv
)) {
15146 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
15147 dev_priv
->display
.get_initial_plane_config
=
15148 i9xx_get_initial_plane_config
;
15149 dev_priv
->display
.crtc_compute_clock
= chv_crtc_compute_clock
;
15150 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
15151 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
15152 } else if (IS_VALLEYVIEW(dev_priv
)) {
15153 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
15154 dev_priv
->display
.get_initial_plane_config
=
15155 i9xx_get_initial_plane_config
;
15156 dev_priv
->display
.crtc_compute_clock
= vlv_crtc_compute_clock
;
15157 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
15158 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
15159 } else if (IS_G4X(dev_priv
)) {
15160 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
15161 dev_priv
->display
.get_initial_plane_config
=
15162 i9xx_get_initial_plane_config
;
15163 dev_priv
->display
.crtc_compute_clock
= g4x_crtc_compute_clock
;
15164 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
15165 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
15166 } else if (IS_PINEVIEW(dev_priv
)) {
15167 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
15168 dev_priv
->display
.get_initial_plane_config
=
15169 i9xx_get_initial_plane_config
;
15170 dev_priv
->display
.crtc_compute_clock
= pnv_crtc_compute_clock
;
15171 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
15172 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
15173 } else if (!IS_GEN2(dev_priv
)) {
15174 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
15175 dev_priv
->display
.get_initial_plane_config
=
15176 i9xx_get_initial_plane_config
;
15177 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
15178 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
15179 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
15181 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
15182 dev_priv
->display
.get_initial_plane_config
=
15183 i9xx_get_initial_plane_config
;
15184 dev_priv
->display
.crtc_compute_clock
= i8xx_crtc_compute_clock
;
15185 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
15186 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
15189 /* Returns the core display clock speed */
15190 if (IS_SKYLAKE(dev_priv
) || IS_KABYLAKE(dev_priv
))
15191 dev_priv
->display
.get_display_clock_speed
=
15192 skylake_get_display_clock_speed
;
15193 else if (IS_BROXTON(dev_priv
))
15194 dev_priv
->display
.get_display_clock_speed
=
15195 broxton_get_display_clock_speed
;
15196 else if (IS_BROADWELL(dev_priv
))
15197 dev_priv
->display
.get_display_clock_speed
=
15198 broadwell_get_display_clock_speed
;
15199 else if (IS_HASWELL(dev_priv
))
15200 dev_priv
->display
.get_display_clock_speed
=
15201 haswell_get_display_clock_speed
;
15202 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
15203 dev_priv
->display
.get_display_clock_speed
=
15204 valleyview_get_display_clock_speed
;
15205 else if (IS_GEN5(dev_priv
))
15206 dev_priv
->display
.get_display_clock_speed
=
15207 ilk_get_display_clock_speed
;
15208 else if (IS_I945G(dev_priv
) || IS_BROADWATER(dev_priv
) ||
15209 IS_GEN6(dev_priv
) || IS_IVYBRIDGE(dev_priv
))
15210 dev_priv
->display
.get_display_clock_speed
=
15211 i945_get_display_clock_speed
;
15212 else if (IS_GM45(dev_priv
))
15213 dev_priv
->display
.get_display_clock_speed
=
15214 gm45_get_display_clock_speed
;
15215 else if (IS_CRESTLINE(dev_priv
))
15216 dev_priv
->display
.get_display_clock_speed
=
15217 i965gm_get_display_clock_speed
;
15218 else if (IS_PINEVIEW(dev_priv
))
15219 dev_priv
->display
.get_display_clock_speed
=
15220 pnv_get_display_clock_speed
;
15221 else if (IS_G33(dev_priv
) || IS_G4X(dev_priv
))
15222 dev_priv
->display
.get_display_clock_speed
=
15223 g33_get_display_clock_speed
;
15224 else if (IS_I915G(dev_priv
))
15225 dev_priv
->display
.get_display_clock_speed
=
15226 i915_get_display_clock_speed
;
15227 else if (IS_I945GM(dev_priv
) || IS_845G(dev_priv
))
15228 dev_priv
->display
.get_display_clock_speed
=
15229 i9xx_misc_get_display_clock_speed
;
15230 else if (IS_I915GM(dev_priv
))
15231 dev_priv
->display
.get_display_clock_speed
=
15232 i915gm_get_display_clock_speed
;
15233 else if (IS_I865G(dev_priv
))
15234 dev_priv
->display
.get_display_clock_speed
=
15235 i865_get_display_clock_speed
;
15236 else if (IS_I85X(dev_priv
))
15237 dev_priv
->display
.get_display_clock_speed
=
15238 i85x_get_display_clock_speed
;
15240 WARN(!IS_I830(dev_priv
), "Unknown platform. Assuming 133 MHz CDCLK\n");
15241 dev_priv
->display
.get_display_clock_speed
=
15242 i830_get_display_clock_speed
;
15245 if (IS_GEN5(dev_priv
)) {
15246 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
15247 } else if (IS_GEN6(dev_priv
)) {
15248 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
15249 } else if (IS_IVYBRIDGE(dev_priv
)) {
15250 /* FIXME: detect B0+ stepping and use auto training */
15251 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
15252 } else if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
15253 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
15256 if (IS_BROADWELL(dev_priv
)) {
15257 dev_priv
->display
.modeset_commit_cdclk
=
15258 broadwell_modeset_commit_cdclk
;
15259 dev_priv
->display
.modeset_calc_cdclk
=
15260 broadwell_modeset_calc_cdclk
;
15261 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
15262 dev_priv
->display
.modeset_commit_cdclk
=
15263 valleyview_modeset_commit_cdclk
;
15264 dev_priv
->display
.modeset_calc_cdclk
=
15265 valleyview_modeset_calc_cdclk
;
15266 } else if (IS_BROXTON(dev_priv
)) {
15267 dev_priv
->display
.modeset_commit_cdclk
=
15268 bxt_modeset_commit_cdclk
;
15269 dev_priv
->display
.modeset_calc_cdclk
=
15270 bxt_modeset_calc_cdclk
;
15271 } else if (IS_SKYLAKE(dev_priv
) || IS_KABYLAKE(dev_priv
)) {
15272 dev_priv
->display
.modeset_commit_cdclk
=
15273 skl_modeset_commit_cdclk
;
15274 dev_priv
->display
.modeset_calc_cdclk
=
15275 skl_modeset_calc_cdclk
;
15278 switch (INTEL_INFO(dev_priv
)->gen
) {
15280 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
15284 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
15289 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
15293 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
15296 case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
15297 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
15300 /* Drop through - unsupported since execlist only. */
15302 /* Default just returns -ENODEV to indicate unsupported */
15303 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
15308 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
15309 * resume, or other times. This quirk makes sure that's the case for
15310 * affected systems.
15312 static void quirk_pipea_force(struct drm_device
*dev
)
15314 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15316 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
15317 DRM_INFO("applying pipe a force quirk\n");
15320 static void quirk_pipeb_force(struct drm_device
*dev
)
15322 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15324 dev_priv
->quirks
|= QUIRK_PIPEB_FORCE
;
15325 DRM_INFO("applying pipe b force quirk\n");
15329 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
15331 static void quirk_ssc_force_disable(struct drm_device
*dev
)
15333 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15334 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
15335 DRM_INFO("applying lvds SSC disable quirk\n");
15339 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
15342 static void quirk_invert_brightness(struct drm_device
*dev
)
15344 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15345 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
15346 DRM_INFO("applying inverted panel brightness quirk\n");
15349 /* Some VBT's incorrectly indicate no backlight is present */
15350 static void quirk_backlight_present(struct drm_device
*dev
)
15352 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15353 dev_priv
->quirks
|= QUIRK_BACKLIGHT_PRESENT
;
15354 DRM_INFO("applying backlight present quirk\n");
15357 struct intel_quirk
{
15359 int subsystem_vendor
;
15360 int subsystem_device
;
15361 void (*hook
)(struct drm_device
*dev
);
15364 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
15365 struct intel_dmi_quirk
{
15366 void (*hook
)(struct drm_device
*dev
);
15367 const struct dmi_system_id (*dmi_id_list
)[];
15370 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
15372 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
15376 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
15378 .dmi_id_list
= &(const struct dmi_system_id
[]) {
15380 .callback
= intel_dmi_reverse_brightness
,
15381 .ident
= "NCR Corporation",
15382 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
15383 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
15386 { } /* terminating entry */
15388 .hook
= quirk_invert_brightness
,
15392 static struct intel_quirk intel_quirks
[] = {
15393 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
15394 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
15396 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
15397 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
15399 /* 830 needs to leave pipe A & dpll A up */
15400 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
15402 /* 830 needs to leave pipe B & dpll B up */
15403 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipeb_force
},
15405 /* Lenovo U160 cannot use SSC on LVDS */
15406 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
15408 /* Sony Vaio Y cannot use SSC on LVDS */
15409 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
15411 /* Acer Aspire 5734Z must invert backlight brightness */
15412 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
15414 /* Acer/eMachines G725 */
15415 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
15417 /* Acer/eMachines e725 */
15418 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
15420 /* Acer/Packard Bell NCL20 */
15421 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
15423 /* Acer Aspire 4736Z */
15424 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
15426 /* Acer Aspire 5336 */
15427 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
15429 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
15430 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present
},
15432 /* Acer C720 Chromebook (Core i3 4005U) */
15433 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present
},
15435 /* Apple Macbook 2,1 (Core 2 T7400) */
15436 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present
},
15438 /* Apple Macbook 4,1 */
15439 { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present
},
15441 /* Toshiba CB35 Chromebook (Celeron 2955U) */
15442 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present
},
15444 /* HP Chromebook 14 (Celeron 2955U) */
15445 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present
},
15447 /* Dell Chromebook 11 */
15448 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present
},
15450 /* Dell Chromebook 11 (2015 version) */
15451 { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present
},
15454 static void intel_init_quirks(struct drm_device
*dev
)
15456 struct pci_dev
*d
= dev
->pdev
;
15459 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
15460 struct intel_quirk
*q
= &intel_quirks
[i
];
15462 if (d
->device
== q
->device
&&
15463 (d
->subsystem_vendor
== q
->subsystem_vendor
||
15464 q
->subsystem_vendor
== PCI_ANY_ID
) &&
15465 (d
->subsystem_device
== q
->subsystem_device
||
15466 q
->subsystem_device
== PCI_ANY_ID
))
15469 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
15470 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
15471 intel_dmi_quirks
[i
].hook(dev
);
15475 /* Disable the VGA plane that we never use */
15476 static void i915_disable_vga(struct drm_device
*dev
)
15478 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15480 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev
);
15482 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
15483 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
15484 outb(SR01
, VGA_SR_INDEX
);
15485 sr1
= inb(VGA_SR_DATA
);
15486 outb(sr1
| 1<<5, VGA_SR_DATA
);
15487 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
15490 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
15491 POSTING_READ(vga_reg
);
15494 void intel_modeset_init_hw(struct drm_device
*dev
)
15496 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15498 intel_update_cdclk(dev
);
15500 dev_priv
->atomic_cdclk_freq
= dev_priv
->cdclk_freq
;
15502 intel_init_clock_gating(dev
);
15506 * Calculate what we think the watermarks should be for the state we've read
15507 * out of the hardware and then immediately program those watermarks so that
15508 * we ensure the hardware settings match our internal state.
15510 * We can calculate what we think WM's should be by creating a duplicate of the
15511 * current state (which was constructed during hardware readout) and running it
15512 * through the atomic check code to calculate new watermark values in the
15515 static void sanitize_watermarks(struct drm_device
*dev
)
15517 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15518 struct drm_atomic_state
*state
;
15519 struct drm_crtc
*crtc
;
15520 struct drm_crtc_state
*cstate
;
15521 struct drm_modeset_acquire_ctx ctx
;
15525 /* Only supported on platforms that use atomic watermark design */
15526 if (!dev_priv
->display
.optimize_watermarks
)
15530 * We need to hold connection_mutex before calling duplicate_state so
15531 * that the connector loop is protected.
15533 drm_modeset_acquire_init(&ctx
, 0);
15535 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
15536 if (ret
== -EDEADLK
) {
15537 drm_modeset_backoff(&ctx
);
15539 } else if (WARN_ON(ret
)) {
15543 state
= drm_atomic_helper_duplicate_state(dev
, &ctx
);
15544 if (WARN_ON(IS_ERR(state
)))
15548 * Hardware readout is the only time we don't want to calculate
15549 * intermediate watermarks (since we don't trust the current
15552 to_intel_atomic_state(state
)->skip_intermediate_wm
= true;
15554 ret
= intel_atomic_check(dev
, state
);
15557 * If we fail here, it means that the hardware appears to be
15558 * programmed in a way that shouldn't be possible, given our
15559 * understanding of watermark requirements. This might mean a
15560 * mistake in the hardware readout code or a mistake in the
15561 * watermark calculations for a given platform. Raise a WARN
15562 * so that this is noticeable.
15564 * If this actually happens, we'll have to just leave the
15565 * BIOS-programmed watermarks untouched and hope for the best.
15567 WARN(true, "Could not determine valid watermarks for inherited state\n");
15571 /* Write calculated watermark values back */
15572 for_each_crtc_in_state(state
, crtc
, cstate
, i
) {
15573 struct intel_crtc_state
*cs
= to_intel_crtc_state(cstate
);
15575 cs
->wm
.need_postvbl_update
= true;
15576 dev_priv
->display
.optimize_watermarks(cs
);
15579 drm_atomic_state_free(state
);
15581 drm_modeset_drop_locks(&ctx
);
15582 drm_modeset_acquire_fini(&ctx
);
15585 void intel_modeset_init(struct drm_device
*dev
)
15587 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15588 struct i915_ggtt
*ggtt
= &dev_priv
->ggtt
;
15591 struct intel_crtc
*crtc
;
15593 drm_mode_config_init(dev
);
15595 dev
->mode_config
.min_width
= 0;
15596 dev
->mode_config
.min_height
= 0;
15598 dev
->mode_config
.preferred_depth
= 24;
15599 dev
->mode_config
.prefer_shadow
= 1;
15601 dev
->mode_config
.allow_fb_modifiers
= true;
15603 dev
->mode_config
.funcs
= &intel_mode_funcs
;
15605 intel_init_quirks(dev
);
15607 intel_init_pm(dev
);
15609 if (INTEL_INFO(dev
)->num_pipes
== 0)
15613 * There may be no VBT; and if the BIOS enabled SSC we can
15614 * just keep using it to avoid unnecessary flicker. Whereas if the
15615 * BIOS isn't using it, don't assume it will work even if the VBT
15616 * indicates as much.
15618 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)) {
15619 bool bios_lvds_use_ssc
= !!(I915_READ(PCH_DREF_CONTROL
) &
15622 if (dev_priv
->vbt
.lvds_use_ssc
!= bios_lvds_use_ssc
) {
15623 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
15624 bios_lvds_use_ssc
? "en" : "dis",
15625 dev_priv
->vbt
.lvds_use_ssc
? "en" : "dis");
15626 dev_priv
->vbt
.lvds_use_ssc
= bios_lvds_use_ssc
;
15630 if (IS_GEN2(dev
)) {
15631 dev
->mode_config
.max_width
= 2048;
15632 dev
->mode_config
.max_height
= 2048;
15633 } else if (IS_GEN3(dev
)) {
15634 dev
->mode_config
.max_width
= 4096;
15635 dev
->mode_config
.max_height
= 4096;
15637 dev
->mode_config
.max_width
= 8192;
15638 dev
->mode_config
.max_height
= 8192;
15641 if (IS_845G(dev
) || IS_I865G(dev
)) {
15642 dev
->mode_config
.cursor_width
= IS_845G(dev
) ? 64 : 512;
15643 dev
->mode_config
.cursor_height
= 1023;
15644 } else if (IS_GEN2(dev
)) {
15645 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
15646 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
15648 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
15649 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
15652 dev
->mode_config
.fb_base
= ggtt
->mappable_base
;
15654 DRM_DEBUG_KMS("%d display pipe%s available.\n",
15655 INTEL_INFO(dev
)->num_pipes
,
15656 INTEL_INFO(dev
)->num_pipes
> 1 ? "s" : "");
15658 for_each_pipe(dev_priv
, pipe
) {
15659 intel_crtc_init(dev
, pipe
);
15660 for_each_sprite(dev_priv
, pipe
, sprite
) {
15661 ret
= intel_plane_init(dev
, pipe
, sprite
);
15663 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
15664 pipe_name(pipe
), sprite_name(pipe
, sprite
), ret
);
15668 intel_update_czclk(dev_priv
);
15669 intel_update_cdclk(dev
);
15671 intel_shared_dpll_init(dev
);
15673 if (dev_priv
->max_cdclk_freq
== 0)
15674 intel_update_max_cdclk(dev
);
15676 /* Just disable it once at startup */
15677 i915_disable_vga(dev
);
15678 intel_setup_outputs(dev
);
15680 drm_modeset_lock_all(dev
);
15681 intel_modeset_setup_hw_state(dev
);
15682 drm_modeset_unlock_all(dev
);
15684 for_each_intel_crtc(dev
, crtc
) {
15685 struct intel_initial_plane_config plane_config
= {};
15691 * Note that reserving the BIOS fb up front prevents us
15692 * from stuffing other stolen allocations like the ring
15693 * on top. This prevents some ugliness at boot time, and
15694 * can even allow for smooth boot transitions if the BIOS
15695 * fb is large enough for the active pipe configuration.
15697 dev_priv
->display
.get_initial_plane_config(crtc
,
15701 * If the fb is shared between multiple heads, we'll
15702 * just get the first one.
15704 intel_find_initial_plane_obj(crtc
, &plane_config
);
15708 * Make sure hardware watermarks really match the state we read out.
15709 * Note that we need to do this after reconstructing the BIOS fb's
15710 * since the watermark calculation done here will use pstate->fb.
15712 sanitize_watermarks(dev
);
15715 static void intel_enable_pipe_a(struct drm_device
*dev
)
15717 struct intel_connector
*connector
;
15718 struct drm_connector
*crt
= NULL
;
15719 struct intel_load_detect_pipe load_detect_temp
;
15720 struct drm_modeset_acquire_ctx
*ctx
= dev
->mode_config
.acquire_ctx
;
15722 /* We can't just switch on the pipe A, we need to set things up with a
15723 * proper mode and output configuration. As a gross hack, enable pipe A
15724 * by enabling the load detect pipe once. */
15725 for_each_intel_connector(dev
, connector
) {
15726 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
15727 crt
= &connector
->base
;
15735 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
, ctx
))
15736 intel_release_load_detect_pipe(crt
, &load_detect_temp
, ctx
);
15740 intel_check_plane_mapping(struct intel_crtc
*crtc
)
15742 struct drm_device
*dev
= crtc
->base
.dev
;
15743 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15746 if (INTEL_INFO(dev
)->num_pipes
== 1)
15749 val
= I915_READ(DSPCNTR(!crtc
->plane
));
15751 if ((val
& DISPLAY_PLANE_ENABLE
) &&
15752 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
15758 static bool intel_crtc_has_encoders(struct intel_crtc
*crtc
)
15760 struct drm_device
*dev
= crtc
->base
.dev
;
15761 struct intel_encoder
*encoder
;
15763 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
15769 static bool intel_encoder_has_connectors(struct intel_encoder
*encoder
)
15771 struct drm_device
*dev
= encoder
->base
.dev
;
15772 struct intel_connector
*connector
;
15774 for_each_connector_on_encoder(dev
, &encoder
->base
, connector
)
15780 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
15782 struct drm_device
*dev
= crtc
->base
.dev
;
15783 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15784 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
15786 /* Clear any frame start delays used for debugging left by the BIOS */
15787 if (!transcoder_is_dsi(cpu_transcoder
)) {
15788 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
15791 I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
15794 /* restore vblank interrupts to correct state */
15795 drm_crtc_vblank_reset(&crtc
->base
);
15796 if (crtc
->active
) {
15797 struct intel_plane
*plane
;
15799 drm_crtc_vblank_on(&crtc
->base
);
15801 /* Disable everything but the primary plane */
15802 for_each_intel_plane_on_crtc(dev
, crtc
, plane
) {
15803 if (plane
->base
.type
== DRM_PLANE_TYPE_PRIMARY
)
15806 plane
->disable_plane(&plane
->base
, &crtc
->base
);
15810 /* We need to sanitize the plane -> pipe mapping first because this will
15811 * disable the crtc (and hence change the state) if it is wrong. Note
15812 * that gen4+ has a fixed plane -> pipe mapping. */
15813 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
15816 DRM_DEBUG_KMS("[CRTC:%d:%s] wrong plane connection detected!\n",
15817 crtc
->base
.base
.id
, crtc
->base
.name
);
15819 /* Pipe has the wrong plane attached and the plane is active.
15820 * Temporarily change the plane mapping and disable everything
15822 plane
= crtc
->plane
;
15823 to_intel_plane_state(crtc
->base
.primary
->state
)->visible
= true;
15824 crtc
->plane
= !plane
;
15825 intel_crtc_disable_noatomic(&crtc
->base
);
15826 crtc
->plane
= plane
;
15829 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
15830 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
15831 /* BIOS forgot to enable pipe A, this mostly happens after
15832 * resume. Force-enable the pipe to fix this, the update_dpms
15833 * call below we restore the pipe to the right state, but leave
15834 * the required bits on. */
15835 intel_enable_pipe_a(dev
);
15838 /* Adjust the state of the output pipe according to whether we
15839 * have active connectors/encoders. */
15840 if (crtc
->active
&& !intel_crtc_has_encoders(crtc
))
15841 intel_crtc_disable_noatomic(&crtc
->base
);
15843 if (crtc
->active
|| HAS_GMCH_DISPLAY(dev
)) {
15845 * We start out with underrun reporting disabled to avoid races.
15846 * For correct bookkeeping mark this on active crtcs.
15848 * Also on gmch platforms we dont have any hardware bits to
15849 * disable the underrun reporting. Which means we need to start
15850 * out with underrun reporting disabled also on inactive pipes,
15851 * since otherwise we'll complain about the garbage we read when
15852 * e.g. coming up after runtime pm.
15854 * No protection against concurrent access is required - at
15855 * worst a fifo underrun happens which also sets this to false.
15857 crtc
->cpu_fifo_underrun_disabled
= true;
15858 crtc
->pch_fifo_underrun_disabled
= true;
15862 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
15864 struct intel_connector
*connector
;
15865 struct drm_device
*dev
= encoder
->base
.dev
;
15867 /* We need to check both for a crtc link (meaning that the
15868 * encoder is active and trying to read from a pipe) and the
15869 * pipe itself being active. */
15870 bool has_active_crtc
= encoder
->base
.crtc
&&
15871 to_intel_crtc(encoder
->base
.crtc
)->active
;
15873 if (intel_encoder_has_connectors(encoder
) && !has_active_crtc
) {
15874 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15875 encoder
->base
.base
.id
,
15876 encoder
->base
.name
);
15878 /* Connector is active, but has no active pipe. This is
15879 * fallout from our resume register restoring. Disable
15880 * the encoder manually again. */
15881 if (encoder
->base
.crtc
) {
15882 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15883 encoder
->base
.base
.id
,
15884 encoder
->base
.name
);
15885 encoder
->disable(encoder
);
15886 if (encoder
->post_disable
)
15887 encoder
->post_disable(encoder
);
15889 encoder
->base
.crtc
= NULL
;
15891 /* Inconsistent output/port/pipe state happens presumably due to
15892 * a bug in one of the get_hw_state functions. Or someplace else
15893 * in our code, like the register restore mess on resume. Clamp
15894 * things to off as a safer default. */
15895 for_each_intel_connector(dev
, connector
) {
15896 if (connector
->encoder
!= encoder
)
15898 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
15899 connector
->base
.encoder
= NULL
;
15902 /* Enabled encoders without active connectors will be fixed in
15903 * the crtc fixup. */
15906 void i915_redisable_vga_power_on(struct drm_device
*dev
)
15908 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15909 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev
);
15911 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
15912 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
15913 i915_disable_vga(dev
);
15917 void i915_redisable_vga(struct drm_device
*dev
)
15919 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15921 /* This function can be called both from intel_modeset_setup_hw_state or
15922 * at a very early point in our resume sequence, where the power well
15923 * structures are not yet restored. Since this function is at a very
15924 * paranoid "someone might have enabled VGA while we were not looking"
15925 * level, just check if the power well is enabled instead of trying to
15926 * follow the "don't touch the power well if we don't need it" policy
15927 * the rest of the driver uses. */
15928 if (!intel_display_power_get_if_enabled(dev_priv
, POWER_DOMAIN_VGA
))
15931 i915_redisable_vga_power_on(dev
);
15933 intel_display_power_put(dev_priv
, POWER_DOMAIN_VGA
);
15936 static bool primary_get_hw_state(struct intel_plane
*plane
)
15938 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
15940 return I915_READ(DSPCNTR(plane
->plane
)) & DISPLAY_PLANE_ENABLE
;
15943 /* FIXME read out full plane state for all planes */
15944 static void readout_plane_state(struct intel_crtc
*crtc
)
15946 struct drm_plane
*primary
= crtc
->base
.primary
;
15947 struct intel_plane_state
*plane_state
=
15948 to_intel_plane_state(primary
->state
);
15950 plane_state
->visible
= crtc
->active
&&
15951 primary_get_hw_state(to_intel_plane(primary
));
15953 if (plane_state
->visible
)
15954 crtc
->base
.state
->plane_mask
|= 1 << drm_plane_index(primary
);
15957 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
15959 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15961 struct intel_crtc
*crtc
;
15962 struct intel_encoder
*encoder
;
15963 struct intel_connector
*connector
;
15966 dev_priv
->active_crtcs
= 0;
15968 for_each_intel_crtc(dev
, crtc
) {
15969 struct intel_crtc_state
*crtc_state
= crtc
->config
;
15972 __drm_atomic_helper_crtc_destroy_state(&crtc_state
->base
);
15973 memset(crtc_state
, 0, sizeof(*crtc_state
));
15974 crtc_state
->base
.crtc
= &crtc
->base
;
15976 crtc_state
->base
.active
= crtc_state
->base
.enable
=
15977 dev_priv
->display
.get_pipe_config(crtc
, crtc_state
);
15979 crtc
->base
.enabled
= crtc_state
->base
.enable
;
15980 crtc
->active
= crtc_state
->base
.active
;
15982 if (crtc_state
->base
.active
) {
15983 dev_priv
->active_crtcs
|= 1 << crtc
->pipe
;
15985 if (INTEL_GEN(dev_priv
) >= 9 || IS_BROADWELL(dev_priv
))
15986 pixclk
= ilk_pipe_pixel_rate(crtc_state
);
15987 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
15988 pixclk
= crtc_state
->base
.adjusted_mode
.crtc_clock
;
15990 WARN_ON(dev_priv
->display
.modeset_calc_cdclk
);
15992 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
15993 if (IS_BROADWELL(dev_priv
) && crtc_state
->ips_enabled
)
15994 pixclk
= DIV_ROUND_UP(pixclk
* 100, 95);
15997 dev_priv
->min_pixclk
[crtc
->pipe
] = pixclk
;
15999 readout_plane_state(crtc
);
16001 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
16002 crtc
->base
.base
.id
, crtc
->base
.name
,
16003 crtc
->active
? "enabled" : "disabled");
16006 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
16007 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
16009 pll
->on
= pll
->funcs
.get_hw_state(dev_priv
, pll
,
16010 &pll
->config
.hw_state
);
16011 pll
->config
.crtc_mask
= 0;
16012 for_each_intel_crtc(dev
, crtc
) {
16013 if (crtc
->active
&& crtc
->config
->shared_dpll
== pll
)
16014 pll
->config
.crtc_mask
|= 1 << crtc
->pipe
;
16016 pll
->active_mask
= pll
->config
.crtc_mask
;
16018 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
16019 pll
->name
, pll
->config
.crtc_mask
, pll
->on
);
16022 for_each_intel_encoder(dev
, encoder
) {
16025 if (encoder
->get_hw_state(encoder
, &pipe
)) {
16026 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
16027 encoder
->base
.crtc
= &crtc
->base
;
16028 crtc
->config
->output_types
|= 1 << encoder
->type
;
16029 encoder
->get_config(encoder
, crtc
->config
);
16031 encoder
->base
.crtc
= NULL
;
16034 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
16035 encoder
->base
.base
.id
,
16036 encoder
->base
.name
,
16037 encoder
->base
.crtc
? "enabled" : "disabled",
16041 for_each_intel_connector(dev
, connector
) {
16042 if (connector
->get_hw_state(connector
)) {
16043 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
16045 encoder
= connector
->encoder
;
16046 connector
->base
.encoder
= &encoder
->base
;
16048 if (encoder
->base
.crtc
&&
16049 encoder
->base
.crtc
->state
->active
) {
16051 * This has to be done during hardware readout
16052 * because anything calling .crtc_disable may
16053 * rely on the connector_mask being accurate.
16055 encoder
->base
.crtc
->state
->connector_mask
|=
16056 1 << drm_connector_index(&connector
->base
);
16057 encoder
->base
.crtc
->state
->encoder_mask
|=
16058 1 << drm_encoder_index(&encoder
->base
);
16062 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
16063 connector
->base
.encoder
= NULL
;
16065 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
16066 connector
->base
.base
.id
,
16067 connector
->base
.name
,
16068 connector
->base
.encoder
? "enabled" : "disabled");
16071 for_each_intel_crtc(dev
, crtc
) {
16072 crtc
->base
.hwmode
= crtc
->config
->base
.adjusted_mode
;
16074 memset(&crtc
->base
.mode
, 0, sizeof(crtc
->base
.mode
));
16075 if (crtc
->base
.state
->active
) {
16076 intel_mode_from_pipe_config(&crtc
->base
.mode
, crtc
->config
);
16077 intel_mode_from_pipe_config(&crtc
->base
.state
->adjusted_mode
, crtc
->config
);
16078 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->base
.state
, &crtc
->base
.mode
));
16081 * The initial mode needs to be set in order to keep
16082 * the atomic core happy. It wants a valid mode if the
16083 * crtc's enabled, so we do the above call.
16085 * At this point some state updated by the connectors
16086 * in their ->detect() callback has not run yet, so
16087 * no recalculation can be done yet.
16089 * Even if we could do a recalculation and modeset
16090 * right now it would cause a double modeset if
16091 * fbdev or userspace chooses a different initial mode.
16093 * If that happens, someone indicated they wanted a
16094 * mode change, which means it's safe to do a full
16097 crtc
->base
.state
->mode
.private_flags
= I915_MODE_FLAG_INHERITED
;
16099 drm_calc_timestamping_constants(&crtc
->base
, &crtc
->base
.hwmode
);
16100 update_scanline_offset(crtc
);
16103 intel_pipe_config_sanity_check(dev_priv
, crtc
->config
);
16107 /* Scan out the current hw modeset state,
16108 * and sanitizes it to the current state
16111 intel_modeset_setup_hw_state(struct drm_device
*dev
)
16113 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16115 struct intel_crtc
*crtc
;
16116 struct intel_encoder
*encoder
;
16119 intel_modeset_readout_hw_state(dev
);
16121 /* HW state is read out, now we need to sanitize this mess. */
16122 for_each_intel_encoder(dev
, encoder
) {
16123 intel_sanitize_encoder(encoder
);
16126 for_each_pipe(dev_priv
, pipe
) {
16127 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
16128 intel_sanitize_crtc(crtc
);
16129 intel_dump_pipe_config(crtc
, crtc
->config
,
16130 "[setup_hw_state]");
16133 intel_modeset_update_connector_atomic_state(dev
);
16135 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
16136 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
16138 if (!pll
->on
|| pll
->active_mask
)
16141 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
16143 pll
->funcs
.disable(dev_priv
, pll
);
16147 if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
))
16148 vlv_wm_get_hw_state(dev
);
16149 else if (IS_GEN9(dev
))
16150 skl_wm_get_hw_state(dev
);
16151 else if (HAS_PCH_SPLIT(dev
))
16152 ilk_wm_get_hw_state(dev
);
16154 for_each_intel_crtc(dev
, crtc
) {
16155 unsigned long put_domains
;
16157 put_domains
= modeset_get_crtc_power_domains(&crtc
->base
, crtc
->config
);
16158 if (WARN_ON(put_domains
))
16159 modeset_put_power_domains(dev_priv
, put_domains
);
16161 intel_display_set_init_power(dev_priv
, false);
16163 intel_fbc_init_pipe_state(dev_priv
);
16166 void intel_display_resume(struct drm_device
*dev
)
16168 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16169 struct drm_atomic_state
*state
= dev_priv
->modeset_restore_state
;
16170 struct drm_modeset_acquire_ctx ctx
;
16172 bool setup
= false;
16174 dev_priv
->modeset_restore_state
= NULL
;
16177 * This is a cludge because with real atomic modeset mode_config.mutex
16178 * won't be taken. Unfortunately some probed state like
16179 * audio_codec_enable is still protected by mode_config.mutex, so lock
16182 mutex_lock(&dev
->mode_config
.mutex
);
16183 drm_modeset_acquire_init(&ctx
, 0);
16186 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
16188 if (ret
== 0 && !setup
) {
16191 intel_modeset_setup_hw_state(dev
);
16192 i915_redisable_vga(dev
);
16195 if (ret
== 0 && state
) {
16196 struct drm_crtc_state
*crtc_state
;
16197 struct drm_crtc
*crtc
;
16200 state
->acquire_ctx
= &ctx
;
16202 /* ignore any reset values/BIOS leftovers in the WM registers */
16203 to_intel_atomic_state(state
)->skip_intermediate_wm
= true;
16205 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
16207 * Force recalculation even if we restore
16208 * current state. With fast modeset this may not result
16209 * in a modeset when the state is compatible.
16211 crtc_state
->mode_changed
= true;
16214 ret
= drm_atomic_commit(state
);
16217 if (ret
== -EDEADLK
) {
16218 drm_modeset_backoff(&ctx
);
16222 drm_modeset_drop_locks(&ctx
);
16223 drm_modeset_acquire_fini(&ctx
);
16224 mutex_unlock(&dev
->mode_config
.mutex
);
16227 DRM_ERROR("Restoring old state failed with %i\n", ret
);
16228 drm_atomic_state_free(state
);
16232 void intel_modeset_gem_init(struct drm_device
*dev
)
16234 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16235 struct drm_crtc
*c
;
16236 struct drm_i915_gem_object
*obj
;
16239 intel_init_gt_powersave(dev_priv
);
16241 intel_modeset_init_hw(dev
);
16243 intel_setup_overlay(dev_priv
);
16246 * Make sure any fbs we allocated at startup are properly
16247 * pinned & fenced. When we do the allocation it's too early
16250 for_each_crtc(dev
, c
) {
16251 obj
= intel_fb_obj(c
->primary
->fb
);
16255 mutex_lock(&dev
->struct_mutex
);
16256 ret
= intel_pin_and_fence_fb_obj(c
->primary
->fb
,
16257 c
->primary
->state
->rotation
);
16258 mutex_unlock(&dev
->struct_mutex
);
16260 DRM_ERROR("failed to pin boot fb on pipe %d\n",
16261 to_intel_crtc(c
)->pipe
);
16262 drm_framebuffer_unreference(c
->primary
->fb
);
16263 c
->primary
->fb
= NULL
;
16264 c
->primary
->crtc
= c
->primary
->state
->crtc
= NULL
;
16265 update_state_fb(c
->primary
);
16266 c
->state
->plane_mask
&= ~(1 << drm_plane_index(c
->primary
));
16271 int intel_connector_register(struct drm_connector
*connector
)
16273 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
16276 ret
= intel_backlight_device_register(intel_connector
);
16286 void intel_connector_unregister(struct drm_connector
*connector
)
16288 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
16290 intel_backlight_device_unregister(intel_connector
);
16291 intel_panel_destroy_backlight(connector
);
16294 void intel_modeset_cleanup(struct drm_device
*dev
)
16296 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16298 intel_disable_gt_powersave(dev_priv
);
16301 * Interrupts and polling as the first thing to avoid creating havoc.
16302 * Too much stuff here (turning of connectors, ...) would
16303 * experience fancy races otherwise.
16305 intel_irq_uninstall(dev_priv
);
16308 * Due to the hpd irq storm handling the hotplug work can re-arm the
16309 * poll handlers. Hence disable polling after hpd handling is shut down.
16311 drm_kms_helper_poll_fini(dev
);
16313 intel_unregister_dsm_handler();
16315 intel_fbc_global_disable(dev_priv
);
16317 /* flush any delayed tasks or pending work */
16318 flush_scheduled_work();
16320 drm_mode_config_cleanup(dev
);
16322 intel_cleanup_overlay(dev_priv
);
16324 intel_cleanup_gt_powersave(dev_priv
);
16326 intel_teardown_gmbus(dev
);
16329 void intel_connector_attach_encoder(struct intel_connector
*connector
,
16330 struct intel_encoder
*encoder
)
16332 connector
->encoder
= encoder
;
16333 drm_mode_connector_attach_encoder(&connector
->base
,
16338 * set vga decode state - true == enable VGA decode
16340 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
16342 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16343 unsigned reg
= INTEL_INFO(dev
)->gen
>= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
16346 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
16347 DRM_ERROR("failed to read control word\n");
16351 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
16355 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
16357 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
16359 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
16360 DRM_ERROR("failed to write control word\n");
16367 struct intel_display_error_state
{
16369 u32 power_well_driver
;
16371 int num_transcoders
;
16373 struct intel_cursor_error_state
{
16378 } cursor
[I915_MAX_PIPES
];
16380 struct intel_pipe_error_state
{
16381 bool power_domain_on
;
16384 } pipe
[I915_MAX_PIPES
];
16386 struct intel_plane_error_state
{
16394 } plane
[I915_MAX_PIPES
];
16396 struct intel_transcoder_error_state
{
16397 bool power_domain_on
;
16398 enum transcoder cpu_transcoder
;
16411 struct intel_display_error_state
*
16412 intel_display_capture_error_state(struct drm_i915_private
*dev_priv
)
16414 struct intel_display_error_state
*error
;
16415 int transcoders
[] = {
16423 if (INTEL_INFO(dev_priv
)->num_pipes
== 0)
16426 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
16430 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
16431 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
16433 for_each_pipe(dev_priv
, i
) {
16434 error
->pipe
[i
].power_domain_on
=
16435 __intel_display_power_is_enabled(dev_priv
,
16436 POWER_DOMAIN_PIPE(i
));
16437 if (!error
->pipe
[i
].power_domain_on
)
16440 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
16441 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
16442 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
16444 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
16445 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
16446 if (INTEL_GEN(dev_priv
) <= 3) {
16447 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
16448 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
16450 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
16451 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
16452 if (INTEL_GEN(dev_priv
) >= 4) {
16453 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
16454 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
16457 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
16459 if (HAS_GMCH_DISPLAY(dev_priv
))
16460 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
16463 /* Note: this does not include DSI transcoders. */
16464 error
->num_transcoders
= INTEL_INFO(dev_priv
)->num_pipes
;
16465 if (HAS_DDI(dev_priv
))
16466 error
->num_transcoders
++; /* Account for eDP. */
16468 for (i
= 0; i
< error
->num_transcoders
; i
++) {
16469 enum transcoder cpu_transcoder
= transcoders
[i
];
16471 error
->transcoder
[i
].power_domain_on
=
16472 __intel_display_power_is_enabled(dev_priv
,
16473 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
16474 if (!error
->transcoder
[i
].power_domain_on
)
16477 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
16479 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
16480 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
16481 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
16482 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
16483 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
16484 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
16485 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
16491 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
16494 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
16495 struct drm_device
*dev
,
16496 struct intel_display_error_state
*error
)
16498 struct drm_i915_private
*dev_priv
= to_i915(dev
);
16504 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev
)->num_pipes
);
16505 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
16506 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
16507 error
->power_well_driver
);
16508 for_each_pipe(dev_priv
, i
) {
16509 err_printf(m
, "Pipe [%d]:\n", i
);
16510 err_printf(m
, " Power: %s\n",
16511 onoff(error
->pipe
[i
].power_domain_on
));
16512 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
16513 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
16515 err_printf(m
, "Plane [%d]:\n", i
);
16516 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
16517 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
16518 if (INTEL_INFO(dev
)->gen
<= 3) {
16519 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
16520 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
16522 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
16523 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
16524 if (INTEL_INFO(dev
)->gen
>= 4) {
16525 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
16526 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
16529 err_printf(m
, "Cursor [%d]:\n", i
);
16530 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
16531 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
16532 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
16535 for (i
= 0; i
< error
->num_transcoders
; i
++) {
16536 err_printf(m
, "CPU transcoder: %s\n",
16537 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
16538 err_printf(m
, " Power: %s\n",
16539 onoff(error
->transcoder
[i
].power_domain_on
));
16540 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
16541 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
16542 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
16543 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
16544 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
16545 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
16546 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);