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_clflush.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 intel_framebuffer
*ifb
,
101 struct drm_i915_gem_object
*obj
,
102 struct drm_mode_fb_cmd2
*mode_cmd
);
103 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
);
104 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
);
105 static void intel_set_pipe_src_size(struct intel_crtc
*intel_crtc
);
106 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
107 struct intel_link_m_n
*m_n
,
108 struct intel_link_m_n
*m2_n2
);
109 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
);
110 static void haswell_set_pipeconf(struct drm_crtc
*crtc
);
111 static void haswell_set_pipemisc(struct drm_crtc
*crtc
);
112 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
113 const struct intel_crtc_state
*pipe_config
);
114 static void chv_prepare_pll(struct intel_crtc
*crtc
,
115 const struct intel_crtc_state
*pipe_config
);
116 static void intel_begin_crtc_commit(struct drm_crtc
*, struct drm_crtc_state
*);
117 static void intel_finish_crtc_commit(struct drm_crtc
*, struct drm_crtc_state
*);
118 static void intel_crtc_init_scalers(struct intel_crtc
*crtc
,
119 struct intel_crtc_state
*crtc_state
);
120 static void skylake_pfit_enable(struct intel_crtc
*crtc
);
121 static void ironlake_pfit_disable(struct intel_crtc
*crtc
, bool force
);
122 static void ironlake_pfit_enable(struct intel_crtc
*crtc
);
123 static void intel_modeset_setup_hw_state(struct drm_device
*dev
,
124 struct drm_modeset_acquire_ctx
*ctx
);
125 static void intel_pre_disable_primary_noatomic(struct drm_crtc
*crtc
);
130 } dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
134 int p2_slow
, p2_fast
;
138 /* returns HPLL frequency in kHz */
139 int vlv_get_hpll_vco(struct drm_i915_private
*dev_priv
)
141 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
143 /* Obtain SKU information */
144 mutex_lock(&dev_priv
->sb_lock
);
145 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
146 CCK_FUSE_HPLL_FREQ_MASK
;
147 mutex_unlock(&dev_priv
->sb_lock
);
149 return vco_freq
[hpll_freq
] * 1000;
152 int vlv_get_cck_clock(struct drm_i915_private
*dev_priv
,
153 const char *name
, u32 reg
, int ref_freq
)
158 mutex_lock(&dev_priv
->sb_lock
);
159 val
= vlv_cck_read(dev_priv
, reg
);
160 mutex_unlock(&dev_priv
->sb_lock
);
162 divider
= val
& CCK_FREQUENCY_VALUES
;
164 WARN((val
& CCK_FREQUENCY_STATUS
) !=
165 (divider
<< CCK_FREQUENCY_STATUS_SHIFT
),
166 "%s change in progress\n", name
);
168 return DIV_ROUND_CLOSEST(ref_freq
<< 1, divider
+ 1);
171 int vlv_get_cck_clock_hpll(struct drm_i915_private
*dev_priv
,
172 const char *name
, u32 reg
)
174 if (dev_priv
->hpll_freq
== 0)
175 dev_priv
->hpll_freq
= vlv_get_hpll_vco(dev_priv
);
177 return vlv_get_cck_clock(dev_priv
, name
, reg
,
178 dev_priv
->hpll_freq
);
181 static void intel_update_czclk(struct drm_i915_private
*dev_priv
)
183 if (!(IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)))
186 dev_priv
->czclk_freq
= vlv_get_cck_clock_hpll(dev_priv
, "czclk",
187 CCK_CZ_CLOCK_CONTROL
);
189 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv
->czclk_freq
);
192 static inline u32
/* units of 100MHz */
193 intel_fdi_link_freq(struct drm_i915_private
*dev_priv
,
194 const struct intel_crtc_state
*pipe_config
)
196 if (HAS_DDI(dev_priv
))
197 return pipe_config
->port_clock
; /* SPLL */
198 else if (IS_GEN5(dev_priv
))
199 return ((I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2) * 10000;
204 static const struct intel_limit intel_limits_i8xx_dac
= {
205 .dot
= { .min
= 25000, .max
= 350000 },
206 .vco
= { .min
= 908000, .max
= 1512000 },
207 .n
= { .min
= 2, .max
= 16 },
208 .m
= { .min
= 96, .max
= 140 },
209 .m1
= { .min
= 18, .max
= 26 },
210 .m2
= { .min
= 6, .max
= 16 },
211 .p
= { .min
= 4, .max
= 128 },
212 .p1
= { .min
= 2, .max
= 33 },
213 .p2
= { .dot_limit
= 165000,
214 .p2_slow
= 4, .p2_fast
= 2 },
217 static const struct intel_limit intel_limits_i8xx_dvo
= {
218 .dot
= { .min
= 25000, .max
= 350000 },
219 .vco
= { .min
= 908000, .max
= 1512000 },
220 .n
= { .min
= 2, .max
= 16 },
221 .m
= { .min
= 96, .max
= 140 },
222 .m1
= { .min
= 18, .max
= 26 },
223 .m2
= { .min
= 6, .max
= 16 },
224 .p
= { .min
= 4, .max
= 128 },
225 .p1
= { .min
= 2, .max
= 33 },
226 .p2
= { .dot_limit
= 165000,
227 .p2_slow
= 4, .p2_fast
= 4 },
230 static const struct intel_limit intel_limits_i8xx_lvds
= {
231 .dot
= { .min
= 25000, .max
= 350000 },
232 .vco
= { .min
= 908000, .max
= 1512000 },
233 .n
= { .min
= 2, .max
= 16 },
234 .m
= { .min
= 96, .max
= 140 },
235 .m1
= { .min
= 18, .max
= 26 },
236 .m2
= { .min
= 6, .max
= 16 },
237 .p
= { .min
= 4, .max
= 128 },
238 .p1
= { .min
= 1, .max
= 6 },
239 .p2
= { .dot_limit
= 165000,
240 .p2_slow
= 14, .p2_fast
= 7 },
243 static const struct intel_limit intel_limits_i9xx_sdvo
= {
244 .dot
= { .min
= 20000, .max
= 400000 },
245 .vco
= { .min
= 1400000, .max
= 2800000 },
246 .n
= { .min
= 1, .max
= 6 },
247 .m
= { .min
= 70, .max
= 120 },
248 .m1
= { .min
= 8, .max
= 18 },
249 .m2
= { .min
= 3, .max
= 7 },
250 .p
= { .min
= 5, .max
= 80 },
251 .p1
= { .min
= 1, .max
= 8 },
252 .p2
= { .dot_limit
= 200000,
253 .p2_slow
= 10, .p2_fast
= 5 },
256 static const struct intel_limit intel_limits_i9xx_lvds
= {
257 .dot
= { .min
= 20000, .max
= 400000 },
258 .vco
= { .min
= 1400000, .max
= 2800000 },
259 .n
= { .min
= 1, .max
= 6 },
260 .m
= { .min
= 70, .max
= 120 },
261 .m1
= { .min
= 8, .max
= 18 },
262 .m2
= { .min
= 3, .max
= 7 },
263 .p
= { .min
= 7, .max
= 98 },
264 .p1
= { .min
= 1, .max
= 8 },
265 .p2
= { .dot_limit
= 112000,
266 .p2_slow
= 14, .p2_fast
= 7 },
270 static const struct intel_limit intel_limits_g4x_sdvo
= {
271 .dot
= { .min
= 25000, .max
= 270000 },
272 .vco
= { .min
= 1750000, .max
= 3500000},
273 .n
= { .min
= 1, .max
= 4 },
274 .m
= { .min
= 104, .max
= 138 },
275 .m1
= { .min
= 17, .max
= 23 },
276 .m2
= { .min
= 5, .max
= 11 },
277 .p
= { .min
= 10, .max
= 30 },
278 .p1
= { .min
= 1, .max
= 3},
279 .p2
= { .dot_limit
= 270000,
285 static const struct intel_limit intel_limits_g4x_hdmi
= {
286 .dot
= { .min
= 22000, .max
= 400000 },
287 .vco
= { .min
= 1750000, .max
= 3500000},
288 .n
= { .min
= 1, .max
= 4 },
289 .m
= { .min
= 104, .max
= 138 },
290 .m1
= { .min
= 16, .max
= 23 },
291 .m2
= { .min
= 5, .max
= 11 },
292 .p
= { .min
= 5, .max
= 80 },
293 .p1
= { .min
= 1, .max
= 8},
294 .p2
= { .dot_limit
= 165000,
295 .p2_slow
= 10, .p2_fast
= 5 },
298 static const struct intel_limit intel_limits_g4x_single_channel_lvds
= {
299 .dot
= { .min
= 20000, .max
= 115000 },
300 .vco
= { .min
= 1750000, .max
= 3500000 },
301 .n
= { .min
= 1, .max
= 3 },
302 .m
= { .min
= 104, .max
= 138 },
303 .m1
= { .min
= 17, .max
= 23 },
304 .m2
= { .min
= 5, .max
= 11 },
305 .p
= { .min
= 28, .max
= 112 },
306 .p1
= { .min
= 2, .max
= 8 },
307 .p2
= { .dot_limit
= 0,
308 .p2_slow
= 14, .p2_fast
= 14
312 static const struct intel_limit intel_limits_g4x_dual_channel_lvds
= {
313 .dot
= { .min
= 80000, .max
= 224000 },
314 .vco
= { .min
= 1750000, .max
= 3500000 },
315 .n
= { .min
= 1, .max
= 3 },
316 .m
= { .min
= 104, .max
= 138 },
317 .m1
= { .min
= 17, .max
= 23 },
318 .m2
= { .min
= 5, .max
= 11 },
319 .p
= { .min
= 14, .max
= 42 },
320 .p1
= { .min
= 2, .max
= 6 },
321 .p2
= { .dot_limit
= 0,
322 .p2_slow
= 7, .p2_fast
= 7
326 static const struct intel_limit intel_limits_pineview_sdvo
= {
327 .dot
= { .min
= 20000, .max
= 400000},
328 .vco
= { .min
= 1700000, .max
= 3500000 },
329 /* Pineview's Ncounter is a ring counter */
330 .n
= { .min
= 3, .max
= 6 },
331 .m
= { .min
= 2, .max
= 256 },
332 /* Pineview only has one combined m divider, which we treat as m2. */
333 .m1
= { .min
= 0, .max
= 0 },
334 .m2
= { .min
= 0, .max
= 254 },
335 .p
= { .min
= 5, .max
= 80 },
336 .p1
= { .min
= 1, .max
= 8 },
337 .p2
= { .dot_limit
= 200000,
338 .p2_slow
= 10, .p2_fast
= 5 },
341 static const struct intel_limit intel_limits_pineview_lvds
= {
342 .dot
= { .min
= 20000, .max
= 400000 },
343 .vco
= { .min
= 1700000, .max
= 3500000 },
344 .n
= { .min
= 3, .max
= 6 },
345 .m
= { .min
= 2, .max
= 256 },
346 .m1
= { .min
= 0, .max
= 0 },
347 .m2
= { .min
= 0, .max
= 254 },
348 .p
= { .min
= 7, .max
= 112 },
349 .p1
= { .min
= 1, .max
= 8 },
350 .p2
= { .dot_limit
= 112000,
351 .p2_slow
= 14, .p2_fast
= 14 },
354 /* Ironlake / Sandybridge
356 * We calculate clock using (register_value + 2) for N/M1/M2, so here
357 * the range value for them is (actual_value - 2).
359 static const struct intel_limit intel_limits_ironlake_dac
= {
360 .dot
= { .min
= 25000, .max
= 350000 },
361 .vco
= { .min
= 1760000, .max
= 3510000 },
362 .n
= { .min
= 1, .max
= 5 },
363 .m
= { .min
= 79, .max
= 127 },
364 .m1
= { .min
= 12, .max
= 22 },
365 .m2
= { .min
= 5, .max
= 9 },
366 .p
= { .min
= 5, .max
= 80 },
367 .p1
= { .min
= 1, .max
= 8 },
368 .p2
= { .dot_limit
= 225000,
369 .p2_slow
= 10, .p2_fast
= 5 },
372 static const struct intel_limit intel_limits_ironlake_single_lvds
= {
373 .dot
= { .min
= 25000, .max
= 350000 },
374 .vco
= { .min
= 1760000, .max
= 3510000 },
375 .n
= { .min
= 1, .max
= 3 },
376 .m
= { .min
= 79, .max
= 118 },
377 .m1
= { .min
= 12, .max
= 22 },
378 .m2
= { .min
= 5, .max
= 9 },
379 .p
= { .min
= 28, .max
= 112 },
380 .p1
= { .min
= 2, .max
= 8 },
381 .p2
= { .dot_limit
= 225000,
382 .p2_slow
= 14, .p2_fast
= 14 },
385 static const struct intel_limit intel_limits_ironlake_dual_lvds
= {
386 .dot
= { .min
= 25000, .max
= 350000 },
387 .vco
= { .min
= 1760000, .max
= 3510000 },
388 .n
= { .min
= 1, .max
= 3 },
389 .m
= { .min
= 79, .max
= 127 },
390 .m1
= { .min
= 12, .max
= 22 },
391 .m2
= { .min
= 5, .max
= 9 },
392 .p
= { .min
= 14, .max
= 56 },
393 .p1
= { .min
= 2, .max
= 8 },
394 .p2
= { .dot_limit
= 225000,
395 .p2_slow
= 7, .p2_fast
= 7 },
398 /* LVDS 100mhz refclk limits. */
399 static const struct intel_limit intel_limits_ironlake_single_lvds_100m
= {
400 .dot
= { .min
= 25000, .max
= 350000 },
401 .vco
= { .min
= 1760000, .max
= 3510000 },
402 .n
= { .min
= 1, .max
= 2 },
403 .m
= { .min
= 79, .max
= 126 },
404 .m1
= { .min
= 12, .max
= 22 },
405 .m2
= { .min
= 5, .max
= 9 },
406 .p
= { .min
= 28, .max
= 112 },
407 .p1
= { .min
= 2, .max
= 8 },
408 .p2
= { .dot_limit
= 225000,
409 .p2_slow
= 14, .p2_fast
= 14 },
412 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m
= {
413 .dot
= { .min
= 25000, .max
= 350000 },
414 .vco
= { .min
= 1760000, .max
= 3510000 },
415 .n
= { .min
= 1, .max
= 3 },
416 .m
= { .min
= 79, .max
= 126 },
417 .m1
= { .min
= 12, .max
= 22 },
418 .m2
= { .min
= 5, .max
= 9 },
419 .p
= { .min
= 14, .max
= 42 },
420 .p1
= { .min
= 2, .max
= 6 },
421 .p2
= { .dot_limit
= 225000,
422 .p2_slow
= 7, .p2_fast
= 7 },
425 static const struct intel_limit intel_limits_vlv
= {
427 * These are the data rate limits (measured in fast clocks)
428 * since those are the strictest limits we have. The fast
429 * clock and actual rate limits are more relaxed, so checking
430 * them would make no difference.
432 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
433 .vco
= { .min
= 4000000, .max
= 6000000 },
434 .n
= { .min
= 1, .max
= 7 },
435 .m1
= { .min
= 2, .max
= 3 },
436 .m2
= { .min
= 11, .max
= 156 },
437 .p1
= { .min
= 2, .max
= 3 },
438 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
441 static const struct intel_limit intel_limits_chv
= {
443 * These are the data rate limits (measured in fast clocks)
444 * since those are the strictest limits we have. The fast
445 * clock and actual rate limits are more relaxed, so checking
446 * them would make no difference.
448 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
449 .vco
= { .min
= 4800000, .max
= 6480000 },
450 .n
= { .min
= 1, .max
= 1 },
451 .m1
= { .min
= 2, .max
= 2 },
452 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
453 .p1
= { .min
= 2, .max
= 4 },
454 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
457 static const struct intel_limit intel_limits_bxt
= {
458 /* FIXME: find real dot limits */
459 .dot
= { .min
= 0, .max
= INT_MAX
},
460 .vco
= { .min
= 4800000, .max
= 6700000 },
461 .n
= { .min
= 1, .max
= 1 },
462 .m1
= { .min
= 2, .max
= 2 },
463 /* FIXME: find real m2 limits */
464 .m2
= { .min
= 2 << 22, .max
= 255 << 22 },
465 .p1
= { .min
= 2, .max
= 4 },
466 .p2
= { .p2_slow
= 1, .p2_fast
= 20 },
470 needs_modeset(struct drm_crtc_state
*state
)
472 return drm_atomic_crtc_needs_modeset(state
);
476 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
477 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
478 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
479 * The helpers' return value is the rate of the clock that is fed to the
480 * display engine's pipe which can be the above fast dot clock rate or a
481 * divided-down version of it.
483 /* m1 is reserved as 0 in Pineview, n is a ring counter */
484 static int pnv_calc_dpll_params(int refclk
, struct dpll
*clock
)
486 clock
->m
= clock
->m2
+ 2;
487 clock
->p
= clock
->p1
* clock
->p2
;
488 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
490 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
491 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
496 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
498 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
501 static int i9xx_calc_dpll_params(int refclk
, struct dpll
*clock
)
503 clock
->m
= i9xx_dpll_compute_m(clock
);
504 clock
->p
= clock
->p1
* clock
->p2
;
505 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
507 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
508 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
513 static int vlv_calc_dpll_params(int refclk
, struct dpll
*clock
)
515 clock
->m
= clock
->m1
* clock
->m2
;
516 clock
->p
= clock
->p1
* clock
->p2
;
517 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
519 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
520 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
522 return clock
->dot
/ 5;
525 int chv_calc_dpll_params(int refclk
, struct dpll
*clock
)
527 clock
->m
= clock
->m1
* clock
->m2
;
528 clock
->p
= clock
->p1
* clock
->p2
;
529 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
531 clock
->vco
= DIV_ROUND_CLOSEST_ULL((uint64_t)refclk
* clock
->m
,
533 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
535 return clock
->dot
/ 5;
538 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
540 * Returns whether the given set of divisors are valid for a given refclk with
541 * the given connectors.
544 static bool intel_PLL_is_valid(struct drm_i915_private
*dev_priv
,
545 const struct intel_limit
*limit
,
546 const struct dpll
*clock
)
548 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
549 INTELPllInvalid("n out of range\n");
550 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
551 INTELPllInvalid("p1 out of range\n");
552 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
553 INTELPllInvalid("m2 out of range\n");
554 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
555 INTELPllInvalid("m1 out of range\n");
557 if (!IS_PINEVIEW(dev_priv
) && !IS_VALLEYVIEW(dev_priv
) &&
558 !IS_CHERRYVIEW(dev_priv
) && !IS_GEN9_LP(dev_priv
))
559 if (clock
->m1
<= clock
->m2
)
560 INTELPllInvalid("m1 <= m2\n");
562 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
) &&
563 !IS_GEN9_LP(dev_priv
)) {
564 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
565 INTELPllInvalid("p out of range\n");
566 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
567 INTELPllInvalid("m out of range\n");
570 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
571 INTELPllInvalid("vco out of range\n");
572 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
573 * connector, etc., rather than just a single range.
575 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
576 INTELPllInvalid("dot out of range\n");
582 i9xx_select_p2_div(const struct intel_limit
*limit
,
583 const struct intel_crtc_state
*crtc_state
,
586 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
588 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
590 * For LVDS just rely on its current settings for dual-channel.
591 * We haven't figured out how to reliably set up different
592 * single/dual channel state, if we even can.
594 if (intel_is_dual_link_lvds(dev
))
595 return limit
->p2
.p2_fast
;
597 return limit
->p2
.p2_slow
;
599 if (target
< limit
->p2
.dot_limit
)
600 return limit
->p2
.p2_slow
;
602 return limit
->p2
.p2_fast
;
607 * Returns a set of divisors for the desired target clock with the given
608 * refclk, or FALSE. The returned values represent the clock equation:
609 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
611 * Target and reference clocks are specified in kHz.
613 * If match_clock is provided, then best_clock P divider must match the P
614 * divider from @match_clock used for LVDS downclocking.
617 i9xx_find_best_dpll(const struct intel_limit
*limit
,
618 struct intel_crtc_state
*crtc_state
,
619 int target
, int refclk
, struct dpll
*match_clock
,
620 struct dpll
*best_clock
)
622 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
626 memset(best_clock
, 0, sizeof(*best_clock
));
628 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
630 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
632 for (clock
.m2
= limit
->m2
.min
;
633 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
634 if (clock
.m2
>= clock
.m1
)
636 for (clock
.n
= limit
->n
.min
;
637 clock
.n
<= limit
->n
.max
; clock
.n
++) {
638 for (clock
.p1
= limit
->p1
.min
;
639 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
642 i9xx_calc_dpll_params(refclk
, &clock
);
643 if (!intel_PLL_is_valid(to_i915(dev
),
648 clock
.p
!= match_clock
->p
)
651 this_err
= abs(clock
.dot
- target
);
652 if (this_err
< err
) {
661 return (err
!= target
);
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 pnv_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 for (clock
.n
= limit
->n
.min
;
693 clock
.n
<= limit
->n
.max
; clock
.n
++) {
694 for (clock
.p1
= limit
->p1
.min
;
695 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
698 pnv_calc_dpll_params(refclk
, &clock
);
699 if (!intel_PLL_is_valid(to_i915(dev
),
704 clock
.p
!= match_clock
->p
)
707 this_err
= abs(clock
.dot
- target
);
708 if (this_err
< err
) {
717 return (err
!= target
);
721 * Returns a set of divisors for the desired target clock with the given
722 * refclk, or FALSE. The returned values represent the clock equation:
723 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
725 * Target and reference clocks are specified in kHz.
727 * If match_clock is provided, then best_clock P divider must match the P
728 * divider from @match_clock used for LVDS downclocking.
731 g4x_find_best_dpll(const struct intel_limit
*limit
,
732 struct intel_crtc_state
*crtc_state
,
733 int target
, int refclk
, struct dpll
*match_clock
,
734 struct dpll
*best_clock
)
736 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
740 /* approximately equals target * 0.00585 */
741 int err_most
= (target
>> 8) + (target
>> 9);
743 memset(best_clock
, 0, sizeof(*best_clock
));
745 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
747 max_n
= limit
->n
.max
;
748 /* based on hardware requirement, prefer smaller n to precision */
749 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
750 /* based on hardware requirement, prefere larger m1,m2 */
751 for (clock
.m1
= limit
->m1
.max
;
752 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
753 for (clock
.m2
= limit
->m2
.max
;
754 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
755 for (clock
.p1
= limit
->p1
.max
;
756 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
759 i9xx_calc_dpll_params(refclk
, &clock
);
760 if (!intel_PLL_is_valid(to_i915(dev
),
765 this_err
= abs(clock
.dot
- target
);
766 if (this_err
< err_most
) {
780 * Check if the calculated PLL configuration is more optimal compared to the
781 * best configuration and error found so far. Return the calculated error.
783 static bool vlv_PLL_is_optimal(struct drm_device
*dev
, int target_freq
,
784 const struct dpll
*calculated_clock
,
785 const struct dpll
*best_clock
,
786 unsigned int best_error_ppm
,
787 unsigned int *error_ppm
)
790 * For CHV ignore the error and consider only the P value.
791 * Prefer a bigger P value based on HW requirements.
793 if (IS_CHERRYVIEW(to_i915(dev
))) {
796 return calculated_clock
->p
> best_clock
->p
;
799 if (WARN_ON_ONCE(!target_freq
))
802 *error_ppm
= div_u64(1000000ULL *
803 abs(target_freq
- calculated_clock
->dot
),
806 * Prefer a better P value over a better (smaller) error if the error
807 * is small. Ensure this preference for future configurations too by
808 * setting the error to 0.
810 if (*error_ppm
< 100 && calculated_clock
->p
> best_clock
->p
) {
816 return *error_ppm
+ 10 < best_error_ppm
;
820 * Returns a set of divisors for the desired target clock with the given
821 * refclk, or FALSE. The returned values represent the clock equation:
822 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
825 vlv_find_best_dpll(const struct intel_limit
*limit
,
826 struct intel_crtc_state
*crtc_state
,
827 int target
, int refclk
, struct dpll
*match_clock
,
828 struct dpll
*best_clock
)
830 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
831 struct drm_device
*dev
= crtc
->base
.dev
;
833 unsigned int bestppm
= 1000000;
834 /* min update 19.2 MHz */
835 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
838 target
*= 5; /* fast clock */
840 memset(best_clock
, 0, sizeof(*best_clock
));
842 /* based on hardware requirement, prefer smaller n to precision */
843 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
844 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
845 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
846 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
847 clock
.p
= clock
.p1
* clock
.p2
;
848 /* based on hardware requirement, prefer bigger m1,m2 values */
849 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
852 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
855 vlv_calc_dpll_params(refclk
, &clock
);
857 if (!intel_PLL_is_valid(to_i915(dev
),
862 if (!vlv_PLL_is_optimal(dev
, target
,
880 * Returns a set of divisors for the desired target clock with the given
881 * refclk, or FALSE. The returned values represent the clock equation:
882 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
885 chv_find_best_dpll(const struct intel_limit
*limit
,
886 struct intel_crtc_state
*crtc_state
,
887 int target
, int refclk
, struct dpll
*match_clock
,
888 struct dpll
*best_clock
)
890 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
891 struct drm_device
*dev
= crtc
->base
.dev
;
892 unsigned int best_error_ppm
;
897 memset(best_clock
, 0, sizeof(*best_clock
));
898 best_error_ppm
= 1000000;
901 * Based on hardware doc, the n always set to 1, and m1 always
902 * set to 2. If requires to support 200Mhz refclk, we need to
903 * revisit this because n may not 1 anymore.
905 clock
.n
= 1, clock
.m1
= 2;
906 target
*= 5; /* fast clock */
908 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
909 for (clock
.p2
= limit
->p2
.p2_fast
;
910 clock
.p2
>= limit
->p2
.p2_slow
;
911 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
912 unsigned int error_ppm
;
914 clock
.p
= clock
.p1
* clock
.p2
;
916 m2
= DIV_ROUND_CLOSEST_ULL(((uint64_t)target
* clock
.p
*
917 clock
.n
) << 22, refclk
* clock
.m1
);
919 if (m2
> INT_MAX
/clock
.m1
)
924 chv_calc_dpll_params(refclk
, &clock
);
926 if (!intel_PLL_is_valid(to_i915(dev
), limit
, &clock
))
929 if (!vlv_PLL_is_optimal(dev
, target
, &clock
, best_clock
,
930 best_error_ppm
, &error_ppm
))
934 best_error_ppm
= error_ppm
;
942 bool bxt_find_best_dpll(struct intel_crtc_state
*crtc_state
, int target_clock
,
943 struct dpll
*best_clock
)
946 const struct intel_limit
*limit
= &intel_limits_bxt
;
948 return chv_find_best_dpll(limit
, crtc_state
,
949 target_clock
, refclk
, NULL
, best_clock
);
952 bool intel_crtc_active(struct intel_crtc
*crtc
)
954 /* Be paranoid as we can arrive here with only partial
955 * state retrieved from the hardware during setup.
957 * We can ditch the adjusted_mode.crtc_clock check as soon
958 * as Haswell has gained clock readout/fastboot support.
960 * We can ditch the crtc->primary->fb check as soon as we can
961 * properly reconstruct framebuffers.
963 * FIXME: The intel_crtc->active here should be switched to
964 * crtc->state->active once we have proper CRTC states wired up
967 return crtc
->active
&& crtc
->base
.primary
->state
->fb
&&
968 crtc
->config
->base
.adjusted_mode
.crtc_clock
;
971 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
974 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
976 return crtc
->config
->cpu_transcoder
;
979 static bool pipe_dsl_stopped(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
981 i915_reg_t reg
= PIPEDSL(pipe
);
985 if (IS_GEN2(dev_priv
))
986 line_mask
= DSL_LINEMASK_GEN2
;
988 line_mask
= DSL_LINEMASK_GEN3
;
990 line1
= I915_READ(reg
) & line_mask
;
992 line2
= I915_READ(reg
) & line_mask
;
994 return line1
== line2
;
998 * intel_wait_for_pipe_off - wait for pipe to turn off
999 * @crtc: crtc whose pipe to wait for
1001 * After disabling a pipe, we can't wait for vblank in the usual way,
1002 * spinning on the vblank interrupt status bit, since we won't actually
1003 * see an interrupt when the pipe is disabled.
1005 * On Gen4 and above:
1006 * wait for the pipe register state bit to turn off
1009 * wait for the display line value to settle (it usually
1010 * ends up stopping at the start of the next frame).
1013 static void intel_wait_for_pipe_off(struct intel_crtc
*crtc
)
1015 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1016 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1017 enum pipe pipe
= crtc
->pipe
;
1019 if (INTEL_GEN(dev_priv
) >= 4) {
1020 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
1022 /* Wait for the Pipe State to go off */
1023 if (intel_wait_for_register(dev_priv
,
1024 reg
, I965_PIPECONF_ACTIVE
, 0,
1026 WARN(1, "pipe_off wait timed out\n");
1028 /* Wait for the display line to settle */
1029 if (wait_for(pipe_dsl_stopped(dev_priv
, pipe
), 100))
1030 WARN(1, "pipe_off wait timed out\n");
1034 /* Only for pre-ILK configs */
1035 void assert_pll(struct drm_i915_private
*dev_priv
,
1036 enum pipe pipe
, bool state
)
1041 val
= I915_READ(DPLL(pipe
));
1042 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1043 I915_STATE_WARN(cur_state
!= state
,
1044 "PLL state assertion failure (expected %s, current %s)\n",
1045 onoff(state
), onoff(cur_state
));
1048 /* XXX: the dsi pll is shared between MIPI DSI ports */
1049 void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1054 mutex_lock(&dev_priv
->sb_lock
);
1055 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1056 mutex_unlock(&dev_priv
->sb_lock
);
1058 cur_state
= val
& DSI_PLL_VCO_EN
;
1059 I915_STATE_WARN(cur_state
!= state
,
1060 "DSI PLL state assertion failure (expected %s, current %s)\n",
1061 onoff(state
), onoff(cur_state
));
1064 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1065 enum pipe pipe
, bool state
)
1068 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1071 if (HAS_DDI(dev_priv
)) {
1072 /* DDI does not have a specific FDI_TX register */
1073 u32 val
= I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder
));
1074 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1076 u32 val
= I915_READ(FDI_TX_CTL(pipe
));
1077 cur_state
= !!(val
& FDI_TX_ENABLE
);
1079 I915_STATE_WARN(cur_state
!= state
,
1080 "FDI TX state assertion failure (expected %s, current %s)\n",
1081 onoff(state
), onoff(cur_state
));
1083 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1084 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1086 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1087 enum pipe pipe
, bool state
)
1092 val
= I915_READ(FDI_RX_CTL(pipe
));
1093 cur_state
= !!(val
& FDI_RX_ENABLE
);
1094 I915_STATE_WARN(cur_state
!= state
,
1095 "FDI RX state assertion failure (expected %s, current %s)\n",
1096 onoff(state
), onoff(cur_state
));
1098 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1099 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1101 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1106 /* ILK FDI PLL is always enabled */
1107 if (IS_GEN5(dev_priv
))
1110 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1111 if (HAS_DDI(dev_priv
))
1114 val
= I915_READ(FDI_TX_CTL(pipe
));
1115 I915_STATE_WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1118 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1119 enum pipe pipe
, bool state
)
1124 val
= I915_READ(FDI_RX_CTL(pipe
));
1125 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1126 I915_STATE_WARN(cur_state
!= state
,
1127 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1128 onoff(state
), onoff(cur_state
));
1131 void assert_panel_unlocked(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1135 enum pipe panel_pipe
= PIPE_A
;
1138 if (WARN_ON(HAS_DDI(dev_priv
)))
1141 if (HAS_PCH_SPLIT(dev_priv
)) {
1144 pp_reg
= PP_CONTROL(0);
1145 port_sel
= I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK
;
1147 if (port_sel
== PANEL_PORT_SELECT_LVDS
&&
1148 I915_READ(PCH_LVDS
) & LVDS_PIPEB_SELECT
)
1149 panel_pipe
= PIPE_B
;
1150 /* XXX: else fix for eDP */
1151 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
1152 /* presumably write lock depends on pipe, not port select */
1153 pp_reg
= PP_CONTROL(pipe
);
1156 pp_reg
= PP_CONTROL(0);
1157 if (I915_READ(LVDS
) & LVDS_PIPEB_SELECT
)
1158 panel_pipe
= PIPE_B
;
1161 val
= I915_READ(pp_reg
);
1162 if (!(val
& PANEL_POWER_ON
) ||
1163 ((val
& PANEL_UNLOCK_MASK
) == PANEL_UNLOCK_REGS
))
1166 I915_STATE_WARN(panel_pipe
== pipe
&& locked
,
1167 "panel assertion failure, pipe %c regs locked\n",
1171 static void assert_cursor(struct drm_i915_private
*dev_priv
,
1172 enum pipe pipe
, bool state
)
1176 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
))
1177 cur_state
= I915_READ(CURCNTR(PIPE_A
)) & CURSOR_ENABLE
;
1179 cur_state
= I915_READ(CURCNTR(pipe
)) & CURSOR_MODE
;
1181 I915_STATE_WARN(cur_state
!= state
,
1182 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1183 pipe_name(pipe
), onoff(state
), onoff(cur_state
));
1185 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1186 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1188 void assert_pipe(struct drm_i915_private
*dev_priv
,
1189 enum pipe pipe
, bool state
)
1192 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1194 enum intel_display_power_domain power_domain
;
1196 /* we keep both pipes enabled on 830 */
1197 if (IS_I830(dev_priv
))
1200 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
1201 if (intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
1202 u32 val
= I915_READ(PIPECONF(cpu_transcoder
));
1203 cur_state
= !!(val
& PIPECONF_ENABLE
);
1205 intel_display_power_put(dev_priv
, power_domain
);
1210 I915_STATE_WARN(cur_state
!= state
,
1211 "pipe %c assertion failure (expected %s, current %s)\n",
1212 pipe_name(pipe
), onoff(state
), onoff(cur_state
));
1215 static void assert_plane(struct drm_i915_private
*dev_priv
,
1216 enum plane plane
, bool state
)
1221 val
= I915_READ(DSPCNTR(plane
));
1222 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1223 I915_STATE_WARN(cur_state
!= state
,
1224 "plane %c assertion failure (expected %s, current %s)\n",
1225 plane_name(plane
), onoff(state
), onoff(cur_state
));
1228 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1229 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1231 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1236 /* Primary planes are fixed to pipes on gen4+ */
1237 if (INTEL_GEN(dev_priv
) >= 4) {
1238 u32 val
= I915_READ(DSPCNTR(pipe
));
1239 I915_STATE_WARN(val
& DISPLAY_PLANE_ENABLE
,
1240 "plane %c assertion failure, should be disabled but not\n",
1245 /* Need to check both planes against the pipe */
1246 for_each_pipe(dev_priv
, i
) {
1247 u32 val
= I915_READ(DSPCNTR(i
));
1248 enum pipe cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1249 DISPPLANE_SEL_PIPE_SHIFT
;
1250 I915_STATE_WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1251 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1252 plane_name(i
), pipe_name(pipe
));
1256 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1261 if (INTEL_GEN(dev_priv
) >= 9) {
1262 for_each_sprite(dev_priv
, pipe
, sprite
) {
1263 u32 val
= I915_READ(PLANE_CTL(pipe
, sprite
));
1264 I915_STATE_WARN(val
& PLANE_CTL_ENABLE
,
1265 "plane %d assertion failure, should be off on pipe %c but is still active\n",
1266 sprite
, pipe_name(pipe
));
1268 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
1269 for_each_sprite(dev_priv
, pipe
, sprite
) {
1270 u32 val
= I915_READ(SPCNTR(pipe
, PLANE_SPRITE0
+ sprite
));
1271 I915_STATE_WARN(val
& SP_ENABLE
,
1272 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1273 sprite_name(pipe
, sprite
), pipe_name(pipe
));
1275 } else if (INTEL_GEN(dev_priv
) >= 7) {
1276 u32 val
= I915_READ(SPRCTL(pipe
));
1277 I915_STATE_WARN(val
& SPRITE_ENABLE
,
1278 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1279 plane_name(pipe
), pipe_name(pipe
));
1280 } else if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
)) {
1281 u32 val
= I915_READ(DVSCNTR(pipe
));
1282 I915_STATE_WARN(val
& DVS_ENABLE
,
1283 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1284 plane_name(pipe
), pipe_name(pipe
));
1288 static void assert_vblank_disabled(struct drm_crtc
*crtc
)
1290 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc
) == 0))
1291 drm_crtc_vblank_put(crtc
);
1294 void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1300 val
= I915_READ(PCH_TRANSCONF(pipe
));
1301 enabled
= !!(val
& TRANS_ENABLE
);
1302 I915_STATE_WARN(enabled
,
1303 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1307 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1308 enum pipe pipe
, u32 port_sel
, u32 val
)
1310 if ((val
& DP_PORT_EN
) == 0)
1313 if (HAS_PCH_CPT(dev_priv
)) {
1314 u32 trans_dp_ctl
= I915_READ(TRANS_DP_CTL(pipe
));
1315 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1317 } else if (IS_CHERRYVIEW(dev_priv
)) {
1318 if ((val
& DP_PIPE_MASK_CHV
) != DP_PIPE_SELECT_CHV(pipe
))
1321 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1327 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1328 enum pipe pipe
, u32 val
)
1330 if ((val
& SDVO_ENABLE
) == 0)
1333 if (HAS_PCH_CPT(dev_priv
)) {
1334 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1336 } else if (IS_CHERRYVIEW(dev_priv
)) {
1337 if ((val
& SDVO_PIPE_SEL_MASK_CHV
) != SDVO_PIPE_SEL_CHV(pipe
))
1340 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1346 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1347 enum pipe pipe
, u32 val
)
1349 if ((val
& LVDS_PORT_EN
) == 0)
1352 if (HAS_PCH_CPT(dev_priv
)) {
1353 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1356 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1362 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1363 enum pipe pipe
, u32 val
)
1365 if ((val
& ADPA_DAC_ENABLE
) == 0)
1367 if (HAS_PCH_CPT(dev_priv
)) {
1368 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1371 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1377 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1378 enum pipe pipe
, i915_reg_t reg
,
1381 u32 val
= I915_READ(reg
);
1382 I915_STATE_WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1383 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1384 i915_mmio_reg_offset(reg
), pipe_name(pipe
));
1386 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
) && (val
& DP_PORT_EN
) == 0
1387 && (val
& DP_PIPEB_SELECT
),
1388 "IBX PCH dp port still using transcoder B\n");
1391 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1392 enum pipe pipe
, i915_reg_t reg
)
1394 u32 val
= I915_READ(reg
);
1395 I915_STATE_WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1396 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1397 i915_mmio_reg_offset(reg
), pipe_name(pipe
));
1399 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
) && (val
& SDVO_ENABLE
) == 0
1400 && (val
& SDVO_PIPE_B_SELECT
),
1401 "IBX PCH hdmi port still using transcoder B\n");
1404 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1409 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1410 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1411 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1413 val
= I915_READ(PCH_ADPA
);
1414 I915_STATE_WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1415 "PCH VGA enabled on transcoder %c, should be disabled\n",
1418 val
= I915_READ(PCH_LVDS
);
1419 I915_STATE_WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1420 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1423 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1424 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1425 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1428 static void _vlv_enable_pll(struct intel_crtc
*crtc
,
1429 const struct intel_crtc_state
*pipe_config
)
1431 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1432 enum pipe pipe
= crtc
->pipe
;
1434 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1435 POSTING_READ(DPLL(pipe
));
1438 if (intel_wait_for_register(dev_priv
,
1443 DRM_ERROR("DPLL %d failed to lock\n", pipe
);
1446 static void vlv_enable_pll(struct intel_crtc
*crtc
,
1447 const struct intel_crtc_state
*pipe_config
)
1449 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1450 enum pipe pipe
= crtc
->pipe
;
1452 assert_pipe_disabled(dev_priv
, pipe
);
1454 /* PLL is protected by panel, make sure we can write it */
1455 assert_panel_unlocked(dev_priv
, pipe
);
1457 if (pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
)
1458 _vlv_enable_pll(crtc
, pipe_config
);
1460 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1461 POSTING_READ(DPLL_MD(pipe
));
1465 static void _chv_enable_pll(struct intel_crtc
*crtc
,
1466 const struct intel_crtc_state
*pipe_config
)
1468 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1469 enum pipe pipe
= crtc
->pipe
;
1470 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1473 mutex_lock(&dev_priv
->sb_lock
);
1475 /* Enable back the 10bit clock to display controller */
1476 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1477 tmp
|= DPIO_DCLKP_EN
;
1478 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), tmp
);
1480 mutex_unlock(&dev_priv
->sb_lock
);
1483 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1488 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1490 /* Check PLL is locked */
1491 if (intel_wait_for_register(dev_priv
,
1492 DPLL(pipe
), DPLL_LOCK_VLV
, DPLL_LOCK_VLV
,
1494 DRM_ERROR("PLL %d failed to lock\n", pipe
);
1497 static void chv_enable_pll(struct intel_crtc
*crtc
,
1498 const struct intel_crtc_state
*pipe_config
)
1500 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1501 enum pipe pipe
= crtc
->pipe
;
1503 assert_pipe_disabled(dev_priv
, pipe
);
1505 /* PLL is protected by panel, make sure we can write it */
1506 assert_panel_unlocked(dev_priv
, pipe
);
1508 if (pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
)
1509 _chv_enable_pll(crtc
, pipe_config
);
1511 if (pipe
!= PIPE_A
) {
1513 * WaPixelRepeatModeFixForC0:chv
1515 * DPLLCMD is AWOL. Use chicken bits to propagate
1516 * the value from DPLLBMD to either pipe B or C.
1518 I915_WRITE(CBR4_VLV
, pipe
== PIPE_B
? CBR_DPLLBMD_PIPE_B
: CBR_DPLLBMD_PIPE_C
);
1519 I915_WRITE(DPLL_MD(PIPE_B
), pipe_config
->dpll_hw_state
.dpll_md
);
1520 I915_WRITE(CBR4_VLV
, 0);
1521 dev_priv
->chv_dpll_md
[pipe
] = pipe_config
->dpll_hw_state
.dpll_md
;
1524 * DPLLB VGA mode also seems to cause problems.
1525 * We should always have it disabled.
1527 WARN_ON((I915_READ(DPLL(PIPE_B
)) & DPLL_VGA_MODE_DIS
) == 0);
1529 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1530 POSTING_READ(DPLL_MD(pipe
));
1534 static int intel_num_dvo_pipes(struct drm_i915_private
*dev_priv
)
1536 struct intel_crtc
*crtc
;
1539 for_each_intel_crtc(&dev_priv
->drm
, crtc
) {
1540 count
+= crtc
->base
.state
->active
&&
1541 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_DVO
);
1547 static void i9xx_enable_pll(struct intel_crtc
*crtc
)
1549 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1550 i915_reg_t reg
= DPLL(crtc
->pipe
);
1551 u32 dpll
= crtc
->config
->dpll_hw_state
.dpll
;
1554 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1556 /* PLL is protected by panel, make sure we can write it */
1557 if (IS_MOBILE(dev_priv
) && !IS_I830(dev_priv
))
1558 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1560 /* Enable DVO 2x clock on both PLLs if necessary */
1561 if (IS_I830(dev_priv
) && intel_num_dvo_pipes(dev_priv
) > 0) {
1563 * It appears to be important that we don't enable this
1564 * for the current pipe before otherwise configuring the
1565 * PLL. No idea how this should be handled if multiple
1566 * DVO outputs are enabled simultaneosly.
1568 dpll
|= DPLL_DVO_2X_MODE
;
1569 I915_WRITE(DPLL(!crtc
->pipe
),
1570 I915_READ(DPLL(!crtc
->pipe
)) | DPLL_DVO_2X_MODE
);
1574 * Apparently we need to have VGA mode enabled prior to changing
1575 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1576 * dividers, even though the register value does change.
1580 I915_WRITE(reg
, dpll
);
1582 /* Wait for the clocks to stabilize. */
1586 if (INTEL_GEN(dev_priv
) >= 4) {
1587 I915_WRITE(DPLL_MD(crtc
->pipe
),
1588 crtc
->config
->dpll_hw_state
.dpll_md
);
1590 /* The pixel multiplier can only be updated once the
1591 * DPLL is enabled and the clocks are stable.
1593 * So write it again.
1595 I915_WRITE(reg
, dpll
);
1598 /* We do this three times for luck */
1599 for (i
= 0; i
< 3; i
++) {
1600 I915_WRITE(reg
, dpll
);
1602 udelay(150); /* wait for warmup */
1607 * i9xx_disable_pll - disable a PLL
1608 * @dev_priv: i915 private structure
1609 * @pipe: pipe PLL to disable
1611 * Disable the PLL for @pipe, making sure the pipe is off first.
1613 * Note! This is for pre-ILK only.
1615 static void i9xx_disable_pll(struct intel_crtc
*crtc
)
1617 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1618 enum pipe pipe
= crtc
->pipe
;
1620 /* Disable DVO 2x clock on both PLLs if necessary */
1621 if (IS_I830(dev_priv
) &&
1622 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_DVO
) &&
1623 !intel_num_dvo_pipes(dev_priv
)) {
1624 I915_WRITE(DPLL(PIPE_B
),
1625 I915_READ(DPLL(PIPE_B
)) & ~DPLL_DVO_2X_MODE
);
1626 I915_WRITE(DPLL(PIPE_A
),
1627 I915_READ(DPLL(PIPE_A
)) & ~DPLL_DVO_2X_MODE
);
1630 /* Don't disable pipe or pipe PLLs if needed */
1631 if (IS_I830(dev_priv
))
1634 /* Make sure the pipe isn't still relying on us */
1635 assert_pipe_disabled(dev_priv
, pipe
);
1637 I915_WRITE(DPLL(pipe
), DPLL_VGA_MODE_DIS
);
1638 POSTING_READ(DPLL(pipe
));
1641 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1645 /* Make sure the pipe isn't still relying on us */
1646 assert_pipe_disabled(dev_priv
, pipe
);
1648 val
= DPLL_INTEGRATED_REF_CLK_VLV
|
1649 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1651 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1653 I915_WRITE(DPLL(pipe
), val
);
1654 POSTING_READ(DPLL(pipe
));
1657 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1659 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1662 /* Make sure the pipe isn't still relying on us */
1663 assert_pipe_disabled(dev_priv
, pipe
);
1665 val
= DPLL_SSC_REF_CLK_CHV
|
1666 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1668 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1670 I915_WRITE(DPLL(pipe
), val
);
1671 POSTING_READ(DPLL(pipe
));
1673 mutex_lock(&dev_priv
->sb_lock
);
1675 /* Disable 10bit clock to display controller */
1676 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1677 val
&= ~DPIO_DCLKP_EN
;
1678 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1680 mutex_unlock(&dev_priv
->sb_lock
);
1683 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1684 struct intel_digital_port
*dport
,
1685 unsigned int expected_mask
)
1688 i915_reg_t dpll_reg
;
1690 switch (dport
->port
) {
1692 port_mask
= DPLL_PORTB_READY_MASK
;
1696 port_mask
= DPLL_PORTC_READY_MASK
;
1698 expected_mask
<<= 4;
1701 port_mask
= DPLL_PORTD_READY_MASK
;
1702 dpll_reg
= DPIO_PHY_STATUS
;
1708 if (intel_wait_for_register(dev_priv
,
1709 dpll_reg
, port_mask
, expected_mask
,
1711 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1712 port_name(dport
->port
), I915_READ(dpll_reg
) & port_mask
, expected_mask
);
1715 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1718 struct intel_crtc
*intel_crtc
= intel_get_crtc_for_pipe(dev_priv
,
1721 uint32_t val
, pipeconf_val
;
1723 /* Make sure PCH DPLL is enabled */
1724 assert_shared_dpll_enabled(dev_priv
, intel_crtc
->config
->shared_dpll
);
1726 /* FDI must be feeding us bits for PCH ports */
1727 assert_fdi_tx_enabled(dev_priv
, pipe
);
1728 assert_fdi_rx_enabled(dev_priv
, pipe
);
1730 if (HAS_PCH_CPT(dev_priv
)) {
1731 /* Workaround: Set the timing override bit before enabling the
1732 * pch transcoder. */
1733 reg
= TRANS_CHICKEN2(pipe
);
1734 val
= I915_READ(reg
);
1735 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1736 I915_WRITE(reg
, val
);
1739 reg
= PCH_TRANSCONF(pipe
);
1740 val
= I915_READ(reg
);
1741 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1743 if (HAS_PCH_IBX(dev_priv
)) {
1745 * Make the BPC in transcoder be consistent with
1746 * that in pipeconf reg. For HDMI we must use 8bpc
1747 * here for both 8bpc and 12bpc.
1749 val
&= ~PIPECONF_BPC_MASK
;
1750 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_HDMI
))
1751 val
|= PIPECONF_8BPC
;
1753 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
1756 val
&= ~TRANS_INTERLACE_MASK
;
1757 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
1758 if (HAS_PCH_IBX(dev_priv
) &&
1759 intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
1760 val
|= TRANS_LEGACY_INTERLACED_ILK
;
1762 val
|= TRANS_INTERLACED
;
1764 val
|= TRANS_PROGRESSIVE
;
1766 I915_WRITE(reg
, val
| TRANS_ENABLE
);
1767 if (intel_wait_for_register(dev_priv
,
1768 reg
, TRANS_STATE_ENABLE
, TRANS_STATE_ENABLE
,
1770 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
1773 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1774 enum transcoder cpu_transcoder
)
1776 u32 val
, pipeconf_val
;
1778 /* FDI must be feeding us bits for PCH ports */
1779 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
1780 assert_fdi_rx_enabled(dev_priv
, PIPE_A
);
1782 /* Workaround: set timing override bit. */
1783 val
= I915_READ(TRANS_CHICKEN2(PIPE_A
));
1784 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1785 I915_WRITE(TRANS_CHICKEN2(PIPE_A
), val
);
1788 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
1790 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
1791 PIPECONF_INTERLACED_ILK
)
1792 val
|= TRANS_INTERLACED
;
1794 val
|= TRANS_PROGRESSIVE
;
1796 I915_WRITE(LPT_TRANSCONF
, val
);
1797 if (intel_wait_for_register(dev_priv
,
1802 DRM_ERROR("Failed to enable PCH transcoder\n");
1805 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1811 /* FDI relies on the transcoder */
1812 assert_fdi_tx_disabled(dev_priv
, pipe
);
1813 assert_fdi_rx_disabled(dev_priv
, pipe
);
1815 /* Ports must be off as well */
1816 assert_pch_ports_disabled(dev_priv
, pipe
);
1818 reg
= PCH_TRANSCONF(pipe
);
1819 val
= I915_READ(reg
);
1820 val
&= ~TRANS_ENABLE
;
1821 I915_WRITE(reg
, val
);
1822 /* wait for PCH transcoder off, transcoder state */
1823 if (intel_wait_for_register(dev_priv
,
1824 reg
, TRANS_STATE_ENABLE
, 0,
1826 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
1828 if (HAS_PCH_CPT(dev_priv
)) {
1829 /* Workaround: Clear the timing override chicken bit again. */
1830 reg
= TRANS_CHICKEN2(pipe
);
1831 val
= I915_READ(reg
);
1832 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1833 I915_WRITE(reg
, val
);
1837 void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
1841 val
= I915_READ(LPT_TRANSCONF
);
1842 val
&= ~TRANS_ENABLE
;
1843 I915_WRITE(LPT_TRANSCONF
, val
);
1844 /* wait for PCH transcoder off, transcoder state */
1845 if (intel_wait_for_register(dev_priv
,
1846 LPT_TRANSCONF
, TRANS_STATE_ENABLE
, 0,
1848 DRM_ERROR("Failed to disable PCH transcoder\n");
1850 /* Workaround: clear timing override bit. */
1851 val
= I915_READ(TRANS_CHICKEN2(PIPE_A
));
1852 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1853 I915_WRITE(TRANS_CHICKEN2(PIPE_A
), val
);
1856 enum pipe
intel_crtc_pch_transcoder(struct intel_crtc
*crtc
)
1858 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1860 WARN_ON(!crtc
->config
->has_pch_encoder
);
1862 if (HAS_PCH_LPT(dev_priv
))
1869 * intel_enable_pipe - enable a pipe, asserting requirements
1870 * @crtc: crtc responsible for the pipe
1872 * Enable @crtc's pipe, making sure that various hardware specific requirements
1873 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
1875 static void intel_enable_pipe(struct intel_crtc
*crtc
)
1877 struct drm_device
*dev
= crtc
->base
.dev
;
1878 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1879 enum pipe pipe
= crtc
->pipe
;
1880 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1884 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe
));
1886 assert_planes_disabled(dev_priv
, pipe
);
1887 assert_cursor_disabled(dev_priv
, pipe
);
1888 assert_sprites_disabled(dev_priv
, pipe
);
1891 * A pipe without a PLL won't actually be able to drive bits from
1892 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1895 if (HAS_GMCH_DISPLAY(dev_priv
)) {
1896 if (intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_DSI
))
1897 assert_dsi_pll_enabled(dev_priv
);
1899 assert_pll_enabled(dev_priv
, pipe
);
1901 if (crtc
->config
->has_pch_encoder
) {
1902 /* if driving the PCH, we need FDI enabled */
1903 assert_fdi_rx_pll_enabled(dev_priv
,
1904 intel_crtc_pch_transcoder(crtc
));
1905 assert_fdi_tx_pll_enabled(dev_priv
,
1906 (enum pipe
) cpu_transcoder
);
1908 /* FIXME: assert CPU port conditions for SNB+ */
1911 reg
= PIPECONF(cpu_transcoder
);
1912 val
= I915_READ(reg
);
1913 if (val
& PIPECONF_ENABLE
) {
1914 /* we keep both pipes enabled on 830 */
1915 WARN_ON(!IS_I830(dev_priv
));
1919 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
1923 * Until the pipe starts DSL will read as 0, which would cause
1924 * an apparent vblank timestamp jump, which messes up also the
1925 * frame count when it's derived from the timestamps. So let's
1926 * wait for the pipe to start properly before we call
1927 * drm_crtc_vblank_on()
1929 if (dev
->max_vblank_count
== 0 &&
1930 wait_for(intel_get_crtc_scanline(crtc
) != crtc
->scanline_offset
, 50))
1931 DRM_ERROR("pipe %c didn't start\n", pipe_name(pipe
));
1935 * intel_disable_pipe - disable a pipe, asserting requirements
1936 * @crtc: crtc whose pipes is to be disabled
1938 * Disable the pipe of @crtc, making sure that various hardware
1939 * specific requirements are met, if applicable, e.g. plane
1940 * disabled, panel fitter off, etc.
1942 * Will wait until the pipe has shut down before returning.
1944 static void intel_disable_pipe(struct intel_crtc
*crtc
)
1946 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1947 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1948 enum pipe pipe
= crtc
->pipe
;
1952 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe
));
1955 * Make sure planes won't keep trying to pump pixels to us,
1956 * or we might hang the display.
1958 assert_planes_disabled(dev_priv
, pipe
);
1959 assert_cursor_disabled(dev_priv
, pipe
);
1960 assert_sprites_disabled(dev_priv
, pipe
);
1962 reg
= PIPECONF(cpu_transcoder
);
1963 val
= I915_READ(reg
);
1964 if ((val
& PIPECONF_ENABLE
) == 0)
1968 * Double wide has implications for planes
1969 * so best keep it disabled when not needed.
1971 if (crtc
->config
->double_wide
)
1972 val
&= ~PIPECONF_DOUBLE_WIDE
;
1974 /* Don't disable pipe or pipe PLLs if needed */
1975 if (!IS_I830(dev_priv
))
1976 val
&= ~PIPECONF_ENABLE
;
1978 I915_WRITE(reg
, val
);
1979 if ((val
& PIPECONF_ENABLE
) == 0)
1980 intel_wait_for_pipe_off(crtc
);
1983 static unsigned int intel_tile_size(const struct drm_i915_private
*dev_priv
)
1985 return IS_GEN2(dev_priv
) ? 2048 : 4096;
1989 intel_tile_width_bytes(const struct drm_framebuffer
*fb
, int plane
)
1991 struct drm_i915_private
*dev_priv
= to_i915(fb
->dev
);
1992 unsigned int cpp
= fb
->format
->cpp
[plane
];
1994 switch (fb
->modifier
) {
1995 case DRM_FORMAT_MOD_LINEAR
:
1997 case I915_FORMAT_MOD_X_TILED
:
1998 if (IS_GEN2(dev_priv
))
2002 case I915_FORMAT_MOD_Y_TILED
:
2003 if (IS_GEN2(dev_priv
) || HAS_128_BYTE_Y_TILING(dev_priv
))
2007 case I915_FORMAT_MOD_Yf_TILED
:
2023 MISSING_CASE(fb
->modifier
);
2029 intel_tile_height(const struct drm_framebuffer
*fb
, int plane
)
2031 if (fb
->modifier
== DRM_FORMAT_MOD_LINEAR
)
2034 return intel_tile_size(to_i915(fb
->dev
)) /
2035 intel_tile_width_bytes(fb
, plane
);
2038 /* Return the tile dimensions in pixel units */
2039 static void intel_tile_dims(const struct drm_framebuffer
*fb
, int plane
,
2040 unsigned int *tile_width
,
2041 unsigned int *tile_height
)
2043 unsigned int tile_width_bytes
= intel_tile_width_bytes(fb
, plane
);
2044 unsigned int cpp
= fb
->format
->cpp
[plane
];
2046 *tile_width
= tile_width_bytes
/ cpp
;
2047 *tile_height
= intel_tile_size(to_i915(fb
->dev
)) / tile_width_bytes
;
2051 intel_fb_align_height(const struct drm_framebuffer
*fb
,
2052 int plane
, unsigned int height
)
2054 unsigned int tile_height
= intel_tile_height(fb
, plane
);
2056 return ALIGN(height
, tile_height
);
2059 unsigned int intel_rotation_info_size(const struct intel_rotation_info
*rot_info
)
2061 unsigned int size
= 0;
2064 for (i
= 0 ; i
< ARRAY_SIZE(rot_info
->plane
); i
++)
2065 size
+= rot_info
->plane
[i
].width
* rot_info
->plane
[i
].height
;
2071 intel_fill_fb_ggtt_view(struct i915_ggtt_view
*view
,
2072 const struct drm_framebuffer
*fb
,
2073 unsigned int rotation
)
2075 view
->type
= I915_GGTT_VIEW_NORMAL
;
2076 if (drm_rotation_90_or_270(rotation
)) {
2077 view
->type
= I915_GGTT_VIEW_ROTATED
;
2078 view
->rotated
= to_intel_framebuffer(fb
)->rot_info
;
2082 static unsigned int intel_cursor_alignment(const struct drm_i915_private
*dev_priv
)
2084 if (IS_I830(dev_priv
))
2086 else if (IS_I85X(dev_priv
))
2088 else if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
))
2094 static unsigned int intel_linear_alignment(const struct drm_i915_private
*dev_priv
)
2096 if (INTEL_INFO(dev_priv
)->gen
>= 9)
2098 else if (IS_I965G(dev_priv
) || IS_I965GM(dev_priv
) ||
2099 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
2101 else if (INTEL_INFO(dev_priv
)->gen
>= 4)
2107 static unsigned int intel_surf_alignment(const struct drm_framebuffer
*fb
,
2110 struct drm_i915_private
*dev_priv
= to_i915(fb
->dev
);
2112 /* AUX_DIST needs only 4K alignment */
2113 if (fb
->format
->format
== DRM_FORMAT_NV12
&& plane
== 1)
2116 switch (fb
->modifier
) {
2117 case DRM_FORMAT_MOD_LINEAR
:
2118 return intel_linear_alignment(dev_priv
);
2119 case I915_FORMAT_MOD_X_TILED
:
2120 if (INTEL_GEN(dev_priv
) >= 9)
2123 case I915_FORMAT_MOD_Y_TILED
:
2124 case I915_FORMAT_MOD_Yf_TILED
:
2125 return 1 * 1024 * 1024;
2127 MISSING_CASE(fb
->modifier
);
2133 intel_pin_and_fence_fb_obj(struct drm_framebuffer
*fb
, unsigned int rotation
)
2135 struct drm_device
*dev
= fb
->dev
;
2136 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2137 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2138 struct i915_ggtt_view view
;
2139 struct i915_vma
*vma
;
2142 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
2144 alignment
= intel_surf_alignment(fb
, 0);
2146 intel_fill_fb_ggtt_view(&view
, fb
, rotation
);
2148 /* Note that the w/a also requires 64 PTE of padding following the
2149 * bo. We currently fill all unused PTE with the shadow page and so
2150 * we should always have valid PTE following the scanout preventing
2153 if (intel_scanout_needs_vtd_wa(dev_priv
) && alignment
< 256 * 1024)
2154 alignment
= 256 * 1024;
2157 * Global gtt pte registers are special registers which actually forward
2158 * writes to a chunk of system memory. Which means that there is no risk
2159 * that the register values disappear as soon as we call
2160 * intel_runtime_pm_put(), so it is correct to wrap only the
2161 * pin/unpin/fence and not more.
2163 intel_runtime_pm_get(dev_priv
);
2165 vma
= i915_gem_object_pin_to_display_plane(obj
, alignment
, &view
);
2169 if (i915_vma_is_map_and_fenceable(vma
)) {
2170 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2171 * fence, whereas 965+ only requires a fence if using
2172 * framebuffer compression. For simplicity, we always, when
2173 * possible, install a fence as the cost is not that onerous.
2175 * If we fail to fence the tiled scanout, then either the
2176 * modeset will reject the change (which is highly unlikely as
2177 * the affected systems, all but one, do not have unmappable
2178 * space) or we will not be able to enable full powersaving
2179 * techniques (also likely not to apply due to various limits
2180 * FBC and the like impose on the size of the buffer, which
2181 * presumably we violated anyway with this unmappable buffer).
2182 * Anyway, it is presumably better to stumble onwards with
2183 * something and try to run the system in a "less than optimal"
2184 * mode that matches the user configuration.
2186 if (i915_vma_get_fence(vma
) == 0)
2187 i915_vma_pin_fence(vma
);
2192 intel_runtime_pm_put(dev_priv
);
2196 void intel_unpin_fb_vma(struct i915_vma
*vma
)
2198 lockdep_assert_held(&vma
->vm
->i915
->drm
.struct_mutex
);
2200 i915_vma_unpin_fence(vma
);
2201 i915_gem_object_unpin_from_display_plane(vma
);
2205 static int intel_fb_pitch(const struct drm_framebuffer
*fb
, int plane
,
2206 unsigned int rotation
)
2208 if (drm_rotation_90_or_270(rotation
))
2209 return to_intel_framebuffer(fb
)->rotated
[plane
].pitch
;
2211 return fb
->pitches
[plane
];
2215 * Convert the x/y offsets into a linear offset.
2216 * Only valid with 0/180 degree rotation, which is fine since linear
2217 * offset is only used with linear buffers on pre-hsw and tiled buffers
2218 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2220 u32
intel_fb_xy_to_linear(int x
, int y
,
2221 const struct intel_plane_state
*state
,
2224 const struct drm_framebuffer
*fb
= state
->base
.fb
;
2225 unsigned int cpp
= fb
->format
->cpp
[plane
];
2226 unsigned int pitch
= fb
->pitches
[plane
];
2228 return y
* pitch
+ x
* cpp
;
2232 * Add the x/y offsets derived from fb->offsets[] to the user
2233 * specified plane src x/y offsets. The resulting x/y offsets
2234 * specify the start of scanout from the beginning of the gtt mapping.
2236 void intel_add_fb_offsets(int *x
, int *y
,
2237 const struct intel_plane_state
*state
,
2241 const struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(state
->base
.fb
);
2242 unsigned int rotation
= state
->base
.rotation
;
2244 if (drm_rotation_90_or_270(rotation
)) {
2245 *x
+= intel_fb
->rotated
[plane
].x
;
2246 *y
+= intel_fb
->rotated
[plane
].y
;
2248 *x
+= intel_fb
->normal
[plane
].x
;
2249 *y
+= intel_fb
->normal
[plane
].y
;
2254 * Input tile dimensions and pitch must already be
2255 * rotated to match x and y, and in pixel units.
2257 static u32
_intel_adjust_tile_offset(int *x
, int *y
,
2258 unsigned int tile_width
,
2259 unsigned int tile_height
,
2260 unsigned int tile_size
,
2261 unsigned int pitch_tiles
,
2265 unsigned int pitch_pixels
= pitch_tiles
* tile_width
;
2268 WARN_ON(old_offset
& (tile_size
- 1));
2269 WARN_ON(new_offset
& (tile_size
- 1));
2270 WARN_ON(new_offset
> old_offset
);
2272 tiles
= (old_offset
- new_offset
) / tile_size
;
2274 *y
+= tiles
/ pitch_tiles
* tile_height
;
2275 *x
+= tiles
% pitch_tiles
* tile_width
;
2277 /* minimize x in case it got needlessly big */
2278 *y
+= *x
/ pitch_pixels
* tile_height
;
2285 * Adjust the tile offset by moving the difference into
2288 static u32
intel_adjust_tile_offset(int *x
, int *y
,
2289 const struct intel_plane_state
*state
, int plane
,
2290 u32 old_offset
, u32 new_offset
)
2292 const struct drm_i915_private
*dev_priv
= to_i915(state
->base
.plane
->dev
);
2293 const struct drm_framebuffer
*fb
= state
->base
.fb
;
2294 unsigned int cpp
= fb
->format
->cpp
[plane
];
2295 unsigned int rotation
= state
->base
.rotation
;
2296 unsigned int pitch
= intel_fb_pitch(fb
, plane
, rotation
);
2298 WARN_ON(new_offset
> old_offset
);
2300 if (fb
->modifier
!= DRM_FORMAT_MOD_LINEAR
) {
2301 unsigned int tile_size
, tile_width
, tile_height
;
2302 unsigned int pitch_tiles
;
2304 tile_size
= intel_tile_size(dev_priv
);
2305 intel_tile_dims(fb
, plane
, &tile_width
, &tile_height
);
2307 if (drm_rotation_90_or_270(rotation
)) {
2308 pitch_tiles
= pitch
/ tile_height
;
2309 swap(tile_width
, tile_height
);
2311 pitch_tiles
= pitch
/ (tile_width
* cpp
);
2314 _intel_adjust_tile_offset(x
, y
, tile_width
, tile_height
,
2315 tile_size
, pitch_tiles
,
2316 old_offset
, new_offset
);
2318 old_offset
+= *y
* pitch
+ *x
* cpp
;
2320 *y
= (old_offset
- new_offset
) / pitch
;
2321 *x
= ((old_offset
- new_offset
) - *y
* pitch
) / cpp
;
2328 * Computes the linear offset to the base tile and adjusts
2329 * x, y. bytes per pixel is assumed to be a power-of-two.
2331 * In the 90/270 rotated case, x and y are assumed
2332 * to be already rotated to match the rotated GTT view, and
2333 * pitch is the tile_height aligned framebuffer height.
2335 * This function is used when computing the derived information
2336 * under intel_framebuffer, so using any of that information
2337 * here is not allowed. Anything under drm_framebuffer can be
2338 * used. This is why the user has to pass in the pitch since it
2339 * is specified in the rotated orientation.
2341 static u32
_intel_compute_tile_offset(const struct drm_i915_private
*dev_priv
,
2343 const struct drm_framebuffer
*fb
, int plane
,
2345 unsigned int rotation
,
2348 uint64_t fb_modifier
= fb
->modifier
;
2349 unsigned int cpp
= fb
->format
->cpp
[plane
];
2350 u32 offset
, offset_aligned
;
2355 if (fb_modifier
!= DRM_FORMAT_MOD_LINEAR
) {
2356 unsigned int tile_size
, tile_width
, tile_height
;
2357 unsigned int tile_rows
, tiles
, pitch_tiles
;
2359 tile_size
= intel_tile_size(dev_priv
);
2360 intel_tile_dims(fb
, plane
, &tile_width
, &tile_height
);
2362 if (drm_rotation_90_or_270(rotation
)) {
2363 pitch_tiles
= pitch
/ tile_height
;
2364 swap(tile_width
, tile_height
);
2366 pitch_tiles
= pitch
/ (tile_width
* cpp
);
2369 tile_rows
= *y
/ tile_height
;
2372 tiles
= *x
/ tile_width
;
2375 offset
= (tile_rows
* pitch_tiles
+ tiles
) * tile_size
;
2376 offset_aligned
= offset
& ~alignment
;
2378 _intel_adjust_tile_offset(x
, y
, tile_width
, tile_height
,
2379 tile_size
, pitch_tiles
,
2380 offset
, offset_aligned
);
2382 offset
= *y
* pitch
+ *x
* cpp
;
2383 offset_aligned
= offset
& ~alignment
;
2385 *y
= (offset
& alignment
) / pitch
;
2386 *x
= ((offset
& alignment
) - *y
* pitch
) / cpp
;
2389 return offset_aligned
;
2392 u32
intel_compute_tile_offset(int *x
, int *y
,
2393 const struct intel_plane_state
*state
,
2396 struct intel_plane
*intel_plane
= to_intel_plane(state
->base
.plane
);
2397 struct drm_i915_private
*dev_priv
= to_i915(intel_plane
->base
.dev
);
2398 const struct drm_framebuffer
*fb
= state
->base
.fb
;
2399 unsigned int rotation
= state
->base
.rotation
;
2400 int pitch
= intel_fb_pitch(fb
, plane
, rotation
);
2403 if (intel_plane
->id
== PLANE_CURSOR
)
2404 alignment
= intel_cursor_alignment(dev_priv
);
2406 alignment
= intel_surf_alignment(fb
, plane
);
2408 return _intel_compute_tile_offset(dev_priv
, x
, y
, fb
, plane
, pitch
,
2409 rotation
, alignment
);
2412 /* Convert the fb->offset[] linear offset into x/y offsets */
2413 static void intel_fb_offset_to_xy(int *x
, int *y
,
2414 const struct drm_framebuffer
*fb
, int plane
)
2416 unsigned int cpp
= fb
->format
->cpp
[plane
];
2417 unsigned int pitch
= fb
->pitches
[plane
];
2418 u32 linear_offset
= fb
->offsets
[plane
];
2420 *y
= linear_offset
/ pitch
;
2421 *x
= linear_offset
% pitch
/ cpp
;
2424 static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier
)
2426 switch (fb_modifier
) {
2427 case I915_FORMAT_MOD_X_TILED
:
2428 return I915_TILING_X
;
2429 case I915_FORMAT_MOD_Y_TILED
:
2430 return I915_TILING_Y
;
2432 return I915_TILING_NONE
;
2437 intel_fill_fb_info(struct drm_i915_private
*dev_priv
,
2438 struct drm_framebuffer
*fb
)
2440 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
2441 struct intel_rotation_info
*rot_info
= &intel_fb
->rot_info
;
2442 u32 gtt_offset_rotated
= 0;
2443 unsigned int max_size
= 0;
2444 int i
, num_planes
= fb
->format
->num_planes
;
2445 unsigned int tile_size
= intel_tile_size(dev_priv
);
2447 for (i
= 0; i
< num_planes
; i
++) {
2448 unsigned int width
, height
;
2449 unsigned int cpp
, size
;
2453 cpp
= fb
->format
->cpp
[i
];
2454 width
= drm_framebuffer_plane_width(fb
->width
, fb
, i
);
2455 height
= drm_framebuffer_plane_height(fb
->height
, fb
, i
);
2457 intel_fb_offset_to_xy(&x
, &y
, fb
, i
);
2460 * The fence (if used) is aligned to the start of the object
2461 * so having the framebuffer wrap around across the edge of the
2462 * fenced region doesn't really work. We have no API to configure
2463 * the fence start offset within the object (nor could we probably
2464 * on gen2/3). So it's just easier if we just require that the
2465 * fb layout agrees with the fence layout. We already check that the
2466 * fb stride matches the fence stride elsewhere.
2468 if (i915_gem_object_is_tiled(intel_fb
->obj
) &&
2469 (x
+ width
) * cpp
> fb
->pitches
[i
]) {
2470 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2476 * First pixel of the framebuffer from
2477 * the start of the normal gtt mapping.
2479 intel_fb
->normal
[i
].x
= x
;
2480 intel_fb
->normal
[i
].y
= y
;
2482 offset
= _intel_compute_tile_offset(dev_priv
, &x
, &y
,
2483 fb
, i
, fb
->pitches
[i
],
2484 DRM_MODE_ROTATE_0
, tile_size
);
2485 offset
/= tile_size
;
2487 if (fb
->modifier
!= DRM_FORMAT_MOD_LINEAR
) {
2488 unsigned int tile_width
, tile_height
;
2489 unsigned int pitch_tiles
;
2492 intel_tile_dims(fb
, i
, &tile_width
, &tile_height
);
2494 rot_info
->plane
[i
].offset
= offset
;
2495 rot_info
->plane
[i
].stride
= DIV_ROUND_UP(fb
->pitches
[i
], tile_width
* cpp
);
2496 rot_info
->plane
[i
].width
= DIV_ROUND_UP(x
+ width
, tile_width
);
2497 rot_info
->plane
[i
].height
= DIV_ROUND_UP(y
+ height
, tile_height
);
2499 intel_fb
->rotated
[i
].pitch
=
2500 rot_info
->plane
[i
].height
* tile_height
;
2502 /* how many tiles does this plane need */
2503 size
= rot_info
->plane
[i
].stride
* rot_info
->plane
[i
].height
;
2505 * If the plane isn't horizontally tile aligned,
2506 * we need one more tile.
2511 /* rotate the x/y offsets to match the GTT view */
2517 rot_info
->plane
[i
].width
* tile_width
,
2518 rot_info
->plane
[i
].height
* tile_height
,
2519 DRM_MODE_ROTATE_270
);
2523 /* rotate the tile dimensions to match the GTT view */
2524 pitch_tiles
= intel_fb
->rotated
[i
].pitch
/ tile_height
;
2525 swap(tile_width
, tile_height
);
2528 * We only keep the x/y offsets, so push all of the
2529 * gtt offset into the x/y offsets.
2531 _intel_adjust_tile_offset(&x
, &y
,
2532 tile_width
, tile_height
,
2533 tile_size
, pitch_tiles
,
2534 gtt_offset_rotated
* tile_size
, 0);
2536 gtt_offset_rotated
+= rot_info
->plane
[i
].width
* rot_info
->plane
[i
].height
;
2539 * First pixel of the framebuffer from
2540 * the start of the rotated gtt mapping.
2542 intel_fb
->rotated
[i
].x
= x
;
2543 intel_fb
->rotated
[i
].y
= y
;
2545 size
= DIV_ROUND_UP((y
+ height
) * fb
->pitches
[i
] +
2546 x
* cpp
, tile_size
);
2549 /* how many tiles in total needed in the bo */
2550 max_size
= max(max_size
, offset
+ size
);
2553 if (max_size
* tile_size
> intel_fb
->obj
->base
.size
) {
2554 DRM_DEBUG_KMS("fb too big for bo (need %u bytes, have %zu bytes)\n",
2555 max_size
* tile_size
, intel_fb
->obj
->base
.size
);
2562 static int i9xx_format_to_fourcc(int format
)
2565 case DISPPLANE_8BPP
:
2566 return DRM_FORMAT_C8
;
2567 case DISPPLANE_BGRX555
:
2568 return DRM_FORMAT_XRGB1555
;
2569 case DISPPLANE_BGRX565
:
2570 return DRM_FORMAT_RGB565
;
2572 case DISPPLANE_BGRX888
:
2573 return DRM_FORMAT_XRGB8888
;
2574 case DISPPLANE_RGBX888
:
2575 return DRM_FORMAT_XBGR8888
;
2576 case DISPPLANE_BGRX101010
:
2577 return DRM_FORMAT_XRGB2101010
;
2578 case DISPPLANE_RGBX101010
:
2579 return DRM_FORMAT_XBGR2101010
;
2583 static int skl_format_to_fourcc(int format
, bool rgb_order
, bool alpha
)
2586 case PLANE_CTL_FORMAT_RGB_565
:
2587 return DRM_FORMAT_RGB565
;
2589 case PLANE_CTL_FORMAT_XRGB_8888
:
2592 return DRM_FORMAT_ABGR8888
;
2594 return DRM_FORMAT_XBGR8888
;
2597 return DRM_FORMAT_ARGB8888
;
2599 return DRM_FORMAT_XRGB8888
;
2601 case PLANE_CTL_FORMAT_XRGB_2101010
:
2603 return DRM_FORMAT_XBGR2101010
;
2605 return DRM_FORMAT_XRGB2101010
;
2610 intel_alloc_initial_plane_obj(struct intel_crtc
*crtc
,
2611 struct intel_initial_plane_config
*plane_config
)
2613 struct drm_device
*dev
= crtc
->base
.dev
;
2614 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2615 struct i915_ggtt
*ggtt
= &dev_priv
->ggtt
;
2616 struct drm_i915_gem_object
*obj
= NULL
;
2617 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2618 struct drm_framebuffer
*fb
= &plane_config
->fb
->base
;
2619 u32 base_aligned
= round_down(plane_config
->base
, PAGE_SIZE
);
2620 u32 size_aligned
= round_up(plane_config
->base
+ plane_config
->size
,
2623 size_aligned
-= base_aligned
;
2625 if (plane_config
->size
== 0)
2628 /* If the FB is too big, just don't use it since fbdev is not very
2629 * important and we should probably use that space with FBC or other
2631 if (size_aligned
* 2 > ggtt
->stolen_usable_size
)
2634 mutex_lock(&dev
->struct_mutex
);
2635 obj
= i915_gem_object_create_stolen_for_preallocated(dev_priv
,
2639 mutex_unlock(&dev
->struct_mutex
);
2643 if (plane_config
->tiling
== I915_TILING_X
)
2644 obj
->tiling_and_stride
= fb
->pitches
[0] | I915_TILING_X
;
2646 mode_cmd
.pixel_format
= fb
->format
->format
;
2647 mode_cmd
.width
= fb
->width
;
2648 mode_cmd
.height
= fb
->height
;
2649 mode_cmd
.pitches
[0] = fb
->pitches
[0];
2650 mode_cmd
.modifier
[0] = fb
->modifier
;
2651 mode_cmd
.flags
= DRM_MODE_FB_MODIFIERS
;
2653 if (intel_framebuffer_init(to_intel_framebuffer(fb
), obj
, &mode_cmd
)) {
2654 DRM_DEBUG_KMS("intel fb init failed\n");
2659 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj
);
2663 i915_gem_object_put(obj
);
2668 intel_set_plane_visible(struct intel_crtc_state
*crtc_state
,
2669 struct intel_plane_state
*plane_state
,
2672 struct intel_plane
*plane
= to_intel_plane(plane_state
->base
.plane
);
2674 plane_state
->base
.visible
= visible
;
2676 /* FIXME pre-g4x don't work like this */
2678 crtc_state
->base
.plane_mask
|= BIT(drm_plane_index(&plane
->base
));
2679 crtc_state
->active_planes
|= BIT(plane
->id
);
2681 crtc_state
->base
.plane_mask
&= ~BIT(drm_plane_index(&plane
->base
));
2682 crtc_state
->active_planes
&= ~BIT(plane
->id
);
2685 DRM_DEBUG_KMS("%s active planes 0x%x\n",
2686 crtc_state
->base
.crtc
->name
,
2687 crtc_state
->active_planes
);
2691 intel_find_initial_plane_obj(struct intel_crtc
*intel_crtc
,
2692 struct intel_initial_plane_config
*plane_config
)
2694 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2695 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2697 struct drm_i915_gem_object
*obj
;
2698 struct drm_plane
*primary
= intel_crtc
->base
.primary
;
2699 struct drm_plane_state
*plane_state
= primary
->state
;
2700 struct drm_crtc_state
*crtc_state
= intel_crtc
->base
.state
;
2701 struct intel_plane
*intel_plane
= to_intel_plane(primary
);
2702 struct intel_plane_state
*intel_state
=
2703 to_intel_plane_state(plane_state
);
2704 struct drm_framebuffer
*fb
;
2706 if (!plane_config
->fb
)
2709 if (intel_alloc_initial_plane_obj(intel_crtc
, plane_config
)) {
2710 fb
= &plane_config
->fb
->base
;
2714 kfree(plane_config
->fb
);
2717 * Failed to alloc the obj, check to see if we should share
2718 * an fb with another CRTC instead
2720 for_each_crtc(dev
, c
) {
2721 struct intel_plane_state
*state
;
2723 if (c
== &intel_crtc
->base
)
2726 if (!to_intel_crtc(c
)->active
)
2729 state
= to_intel_plane_state(c
->primary
->state
);
2733 if (intel_plane_ggtt_offset(state
) == plane_config
->base
) {
2734 fb
= c
->primary
->fb
;
2735 drm_framebuffer_reference(fb
);
2741 * We've failed to reconstruct the BIOS FB. Current display state
2742 * indicates that the primary plane is visible, but has a NULL FB,
2743 * which will lead to problems later if we don't fix it up. The
2744 * simplest solution is to just disable the primary plane now and
2745 * pretend the BIOS never had it enabled.
2747 intel_set_plane_visible(to_intel_crtc_state(crtc_state
),
2748 to_intel_plane_state(plane_state
),
2750 intel_pre_disable_primary_noatomic(&intel_crtc
->base
);
2751 trace_intel_disable_plane(primary
, intel_crtc
);
2752 intel_plane
->disable_plane(intel_plane
, intel_crtc
);
2757 mutex_lock(&dev
->struct_mutex
);
2759 intel_pin_and_fence_fb_obj(fb
, primary
->state
->rotation
);
2760 mutex_unlock(&dev
->struct_mutex
);
2761 if (IS_ERR(intel_state
->vma
)) {
2762 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2763 intel_crtc
->pipe
, PTR_ERR(intel_state
->vma
));
2765 intel_state
->vma
= NULL
;
2766 drm_framebuffer_unreference(fb
);
2770 plane_state
->src_x
= 0;
2771 plane_state
->src_y
= 0;
2772 plane_state
->src_w
= fb
->width
<< 16;
2773 plane_state
->src_h
= fb
->height
<< 16;
2775 plane_state
->crtc_x
= 0;
2776 plane_state
->crtc_y
= 0;
2777 plane_state
->crtc_w
= fb
->width
;
2778 plane_state
->crtc_h
= fb
->height
;
2780 intel_state
->base
.src
= drm_plane_state_src(plane_state
);
2781 intel_state
->base
.dst
= drm_plane_state_dest(plane_state
);
2783 obj
= intel_fb_obj(fb
);
2784 if (i915_gem_object_is_tiled(obj
))
2785 dev_priv
->preserve_bios_swizzle
= true;
2787 drm_framebuffer_reference(fb
);
2788 primary
->fb
= primary
->state
->fb
= fb
;
2789 primary
->crtc
= primary
->state
->crtc
= &intel_crtc
->base
;
2791 intel_set_plane_visible(to_intel_crtc_state(crtc_state
),
2792 to_intel_plane_state(plane_state
),
2795 atomic_or(to_intel_plane(primary
)->frontbuffer_bit
,
2796 &obj
->frontbuffer_bits
);
2799 static int skl_max_plane_width(const struct drm_framebuffer
*fb
, int plane
,
2800 unsigned int rotation
)
2802 int cpp
= fb
->format
->cpp
[plane
];
2804 switch (fb
->modifier
) {
2805 case DRM_FORMAT_MOD_LINEAR
:
2806 case I915_FORMAT_MOD_X_TILED
:
2819 case I915_FORMAT_MOD_Y_TILED
:
2820 case I915_FORMAT_MOD_Yf_TILED
:
2835 MISSING_CASE(fb
->modifier
);
2841 static int skl_check_main_surface(struct intel_plane_state
*plane_state
)
2843 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2844 unsigned int rotation
= plane_state
->base
.rotation
;
2845 int x
= plane_state
->base
.src
.x1
>> 16;
2846 int y
= plane_state
->base
.src
.y1
>> 16;
2847 int w
= drm_rect_width(&plane_state
->base
.src
) >> 16;
2848 int h
= drm_rect_height(&plane_state
->base
.src
) >> 16;
2849 int max_width
= skl_max_plane_width(fb
, 0, rotation
);
2850 int max_height
= 4096;
2851 u32 alignment
, offset
, aux_offset
= plane_state
->aux
.offset
;
2853 if (w
> max_width
|| h
> max_height
) {
2854 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
2855 w
, h
, max_width
, max_height
);
2859 intel_add_fb_offsets(&x
, &y
, plane_state
, 0);
2860 offset
= intel_compute_tile_offset(&x
, &y
, plane_state
, 0);
2861 alignment
= intel_surf_alignment(fb
, 0);
2864 * AUX surface offset is specified as the distance from the
2865 * main surface offset, and it must be non-negative. Make
2866 * sure that is what we will get.
2868 if (offset
> aux_offset
)
2869 offset
= intel_adjust_tile_offset(&x
, &y
, plane_state
, 0,
2870 offset
, aux_offset
& ~(alignment
- 1));
2873 * When using an X-tiled surface, the plane blows up
2874 * if the x offset + width exceed the stride.
2876 * TODO: linear and Y-tiled seem fine, Yf untested,
2878 if (fb
->modifier
== I915_FORMAT_MOD_X_TILED
) {
2879 int cpp
= fb
->format
->cpp
[0];
2881 while ((x
+ w
) * cpp
> fb
->pitches
[0]) {
2883 DRM_DEBUG_KMS("Unable to find suitable display surface offset\n");
2887 offset
= intel_adjust_tile_offset(&x
, &y
, plane_state
, 0,
2888 offset
, offset
- alignment
);
2892 plane_state
->main
.offset
= offset
;
2893 plane_state
->main
.x
= x
;
2894 plane_state
->main
.y
= y
;
2899 static int skl_check_nv12_aux_surface(struct intel_plane_state
*plane_state
)
2901 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2902 unsigned int rotation
= plane_state
->base
.rotation
;
2903 int max_width
= skl_max_plane_width(fb
, 1, rotation
);
2904 int max_height
= 4096;
2905 int x
= plane_state
->base
.src
.x1
>> 17;
2906 int y
= plane_state
->base
.src
.y1
>> 17;
2907 int w
= drm_rect_width(&plane_state
->base
.src
) >> 17;
2908 int h
= drm_rect_height(&plane_state
->base
.src
) >> 17;
2911 intel_add_fb_offsets(&x
, &y
, plane_state
, 1);
2912 offset
= intel_compute_tile_offset(&x
, &y
, plane_state
, 1);
2914 /* FIXME not quite sure how/if these apply to the chroma plane */
2915 if (w
> max_width
|| h
> max_height
) {
2916 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
2917 w
, h
, max_width
, max_height
);
2921 plane_state
->aux
.offset
= offset
;
2922 plane_state
->aux
.x
= x
;
2923 plane_state
->aux
.y
= y
;
2928 int skl_check_plane_surface(struct intel_plane_state
*plane_state
)
2930 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2931 unsigned int rotation
= plane_state
->base
.rotation
;
2934 if (!plane_state
->base
.visible
)
2937 /* Rotate src coordinates to match rotated GTT view */
2938 if (drm_rotation_90_or_270(rotation
))
2939 drm_rect_rotate(&plane_state
->base
.src
,
2940 fb
->width
<< 16, fb
->height
<< 16,
2941 DRM_MODE_ROTATE_270
);
2944 * Handle the AUX surface first since
2945 * the main surface setup depends on it.
2947 if (fb
->format
->format
== DRM_FORMAT_NV12
) {
2948 ret
= skl_check_nv12_aux_surface(plane_state
);
2952 plane_state
->aux
.offset
= ~0xfff;
2953 plane_state
->aux
.x
= 0;
2954 plane_state
->aux
.y
= 0;
2957 ret
= skl_check_main_surface(plane_state
);
2964 static u32
i9xx_plane_ctl(const struct intel_crtc_state
*crtc_state
,
2965 const struct intel_plane_state
*plane_state
)
2967 struct drm_i915_private
*dev_priv
=
2968 to_i915(plane_state
->base
.plane
->dev
);
2969 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
2970 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2971 unsigned int rotation
= plane_state
->base
.rotation
;
2974 dspcntr
= DISPLAY_PLANE_ENABLE
| DISPPLANE_GAMMA_ENABLE
;
2976 if (IS_G4X(dev_priv
) || IS_GEN5(dev_priv
) ||
2977 IS_GEN6(dev_priv
) || IS_IVYBRIDGE(dev_priv
))
2978 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2980 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
2981 dspcntr
|= DISPPLANE_PIPE_CSC_ENABLE
;
2983 if (INTEL_GEN(dev_priv
) < 4)
2984 dspcntr
|= DISPPLANE_SEL_PIPE(crtc
->pipe
);
2986 switch (fb
->format
->format
) {
2988 dspcntr
|= DISPPLANE_8BPP
;
2990 case DRM_FORMAT_XRGB1555
:
2991 dspcntr
|= DISPPLANE_BGRX555
;
2993 case DRM_FORMAT_RGB565
:
2994 dspcntr
|= DISPPLANE_BGRX565
;
2996 case DRM_FORMAT_XRGB8888
:
2997 dspcntr
|= DISPPLANE_BGRX888
;
2999 case DRM_FORMAT_XBGR8888
:
3000 dspcntr
|= DISPPLANE_RGBX888
;
3002 case DRM_FORMAT_XRGB2101010
:
3003 dspcntr
|= DISPPLANE_BGRX101010
;
3005 case DRM_FORMAT_XBGR2101010
:
3006 dspcntr
|= DISPPLANE_RGBX101010
;
3009 MISSING_CASE(fb
->format
->format
);
3013 if (INTEL_GEN(dev_priv
) >= 4 &&
3014 fb
->modifier
== I915_FORMAT_MOD_X_TILED
)
3015 dspcntr
|= DISPPLANE_TILED
;
3017 if (rotation
& DRM_MODE_ROTATE_180
)
3018 dspcntr
|= DISPPLANE_ROTATE_180
;
3020 if (rotation
& DRM_MODE_REFLECT_X
)
3021 dspcntr
|= DISPPLANE_MIRROR
;
3026 int i9xx_check_plane_surface(struct intel_plane_state
*plane_state
)
3028 struct drm_i915_private
*dev_priv
=
3029 to_i915(plane_state
->base
.plane
->dev
);
3030 int src_x
= plane_state
->base
.src
.x1
>> 16;
3031 int src_y
= plane_state
->base
.src
.y1
>> 16;
3034 intel_add_fb_offsets(&src_x
, &src_y
, plane_state
, 0);
3036 if (INTEL_GEN(dev_priv
) >= 4)
3037 offset
= intel_compute_tile_offset(&src_x
, &src_y
,
3042 /* HSW/BDW do this automagically in hardware */
3043 if (!IS_HASWELL(dev_priv
) && !IS_BROADWELL(dev_priv
)) {
3044 unsigned int rotation
= plane_state
->base
.rotation
;
3045 int src_w
= drm_rect_width(&plane_state
->base
.src
) >> 16;
3046 int src_h
= drm_rect_height(&plane_state
->base
.src
) >> 16;
3048 if (rotation
& DRM_MODE_ROTATE_180
) {
3051 } else if (rotation
& DRM_MODE_REFLECT_X
) {
3056 plane_state
->main
.offset
= offset
;
3057 plane_state
->main
.x
= src_x
;
3058 plane_state
->main
.y
= src_y
;
3063 static void i9xx_update_primary_plane(struct intel_plane
*primary
,
3064 const struct intel_crtc_state
*crtc_state
,
3065 const struct intel_plane_state
*plane_state
)
3067 struct drm_i915_private
*dev_priv
= to_i915(primary
->base
.dev
);
3068 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
3069 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
3070 enum plane plane
= primary
->plane
;
3072 u32 dspcntr
= plane_state
->ctl
;
3073 i915_reg_t reg
= DSPCNTR(plane
);
3074 int x
= plane_state
->main
.x
;
3075 int y
= plane_state
->main
.y
;
3076 unsigned long irqflags
;
3078 linear_offset
= intel_fb_xy_to_linear(x
, y
, plane_state
, 0);
3080 if (INTEL_GEN(dev_priv
) >= 4)
3081 crtc
->dspaddr_offset
= plane_state
->main
.offset
;
3083 crtc
->dspaddr_offset
= linear_offset
;
3085 crtc
->adjusted_x
= x
;
3086 crtc
->adjusted_y
= y
;
3088 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
3090 if (INTEL_GEN(dev_priv
) < 4) {
3091 /* pipesrc and dspsize control the size that is scaled from,
3092 * which should always be the user's requested size.
3094 I915_WRITE_FW(DSPSIZE(plane
),
3095 ((crtc_state
->pipe_src_h
- 1) << 16) |
3096 (crtc_state
->pipe_src_w
- 1));
3097 I915_WRITE_FW(DSPPOS(plane
), 0);
3098 } else if (IS_CHERRYVIEW(dev_priv
) && plane
== PLANE_B
) {
3099 I915_WRITE_FW(PRIMSIZE(plane
),
3100 ((crtc_state
->pipe_src_h
- 1) << 16) |
3101 (crtc_state
->pipe_src_w
- 1));
3102 I915_WRITE_FW(PRIMPOS(plane
), 0);
3103 I915_WRITE_FW(PRIMCNSTALPHA(plane
), 0);
3106 I915_WRITE_FW(reg
, dspcntr
);
3108 I915_WRITE_FW(DSPSTRIDE(plane
), fb
->pitches
[0]);
3109 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
3110 I915_WRITE_FW(DSPSURF(plane
),
3111 intel_plane_ggtt_offset(plane_state
) +
3112 crtc
->dspaddr_offset
);
3113 I915_WRITE_FW(DSPOFFSET(plane
), (y
<< 16) | x
);
3114 } else if (INTEL_GEN(dev_priv
) >= 4) {
3115 I915_WRITE_FW(DSPSURF(plane
),
3116 intel_plane_ggtt_offset(plane_state
) +
3117 crtc
->dspaddr_offset
);
3118 I915_WRITE_FW(DSPTILEOFF(plane
), (y
<< 16) | x
);
3119 I915_WRITE_FW(DSPLINOFF(plane
), linear_offset
);
3121 I915_WRITE_FW(DSPADDR(plane
),
3122 intel_plane_ggtt_offset(plane_state
) +
3123 crtc
->dspaddr_offset
);
3125 POSTING_READ_FW(reg
);
3127 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
3130 static void i9xx_disable_primary_plane(struct intel_plane
*primary
,
3131 struct intel_crtc
*crtc
)
3133 struct drm_i915_private
*dev_priv
= to_i915(primary
->base
.dev
);
3134 enum plane plane
= primary
->plane
;
3135 unsigned long irqflags
;
3137 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
3139 I915_WRITE_FW(DSPCNTR(plane
), 0);
3140 if (INTEL_INFO(dev_priv
)->gen
>= 4)
3141 I915_WRITE_FW(DSPSURF(plane
), 0);
3143 I915_WRITE_FW(DSPADDR(plane
), 0);
3144 POSTING_READ_FW(DSPCNTR(plane
));
3146 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
3150 intel_fb_stride_alignment(const struct drm_framebuffer
*fb
, int plane
)
3152 if (fb
->modifier
== DRM_FORMAT_MOD_LINEAR
)
3155 return intel_tile_width_bytes(fb
, plane
);
3158 static void skl_detach_scaler(struct intel_crtc
*intel_crtc
, int id
)
3160 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3161 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3163 I915_WRITE(SKL_PS_CTRL(intel_crtc
->pipe
, id
), 0);
3164 I915_WRITE(SKL_PS_WIN_POS(intel_crtc
->pipe
, id
), 0);
3165 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc
->pipe
, id
), 0);
3169 * This function detaches (aka. unbinds) unused scalers in hardware
3171 static void skl_detach_scalers(struct intel_crtc
*intel_crtc
)
3173 struct intel_crtc_scaler_state
*scaler_state
;
3176 scaler_state
= &intel_crtc
->config
->scaler_state
;
3178 /* loop through and disable scalers that aren't in use */
3179 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
3180 if (!scaler_state
->scalers
[i
].in_use
)
3181 skl_detach_scaler(intel_crtc
, i
);
3185 u32
skl_plane_stride(const struct drm_framebuffer
*fb
, int plane
,
3186 unsigned int rotation
)
3190 if (plane
>= fb
->format
->num_planes
)
3193 stride
= intel_fb_pitch(fb
, plane
, rotation
);
3196 * The stride is either expressed as a multiple of 64 bytes chunks for
3197 * linear buffers or in number of tiles for tiled buffers.
3199 if (drm_rotation_90_or_270(rotation
))
3200 stride
/= intel_tile_height(fb
, plane
);
3202 stride
/= intel_fb_stride_alignment(fb
, plane
);
3207 static u32
skl_plane_ctl_format(uint32_t pixel_format
)
3209 switch (pixel_format
) {
3211 return PLANE_CTL_FORMAT_INDEXED
;
3212 case DRM_FORMAT_RGB565
:
3213 return PLANE_CTL_FORMAT_RGB_565
;
3214 case DRM_FORMAT_XBGR8888
:
3215 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
;
3216 case DRM_FORMAT_XRGB8888
:
3217 return PLANE_CTL_FORMAT_XRGB_8888
;
3219 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
3220 * to be already pre-multiplied. We need to add a knob (or a different
3221 * DRM_FORMAT) for user-space to configure that.
3223 case DRM_FORMAT_ABGR8888
:
3224 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
|
3225 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
3226 case DRM_FORMAT_ARGB8888
:
3227 return PLANE_CTL_FORMAT_XRGB_8888
|
3228 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
3229 case DRM_FORMAT_XRGB2101010
:
3230 return PLANE_CTL_FORMAT_XRGB_2101010
;
3231 case DRM_FORMAT_XBGR2101010
:
3232 return PLANE_CTL_ORDER_RGBX
| PLANE_CTL_FORMAT_XRGB_2101010
;
3233 case DRM_FORMAT_YUYV
:
3234 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YUYV
;
3235 case DRM_FORMAT_YVYU
:
3236 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YVYU
;
3237 case DRM_FORMAT_UYVY
:
3238 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_UYVY
;
3239 case DRM_FORMAT_VYUY
:
3240 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_VYUY
;
3242 MISSING_CASE(pixel_format
);
3248 static u32
skl_plane_ctl_tiling(uint64_t fb_modifier
)
3250 switch (fb_modifier
) {
3251 case DRM_FORMAT_MOD_LINEAR
:
3253 case I915_FORMAT_MOD_X_TILED
:
3254 return PLANE_CTL_TILED_X
;
3255 case I915_FORMAT_MOD_Y_TILED
:
3256 return PLANE_CTL_TILED_Y
;
3257 case I915_FORMAT_MOD_Yf_TILED
:
3258 return PLANE_CTL_TILED_YF
;
3260 MISSING_CASE(fb_modifier
);
3266 static u32
skl_plane_ctl_rotation(unsigned int rotation
)
3269 case DRM_MODE_ROTATE_0
:
3272 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
3273 * while i915 HW rotation is clockwise, thats why this swapping.
3275 case DRM_MODE_ROTATE_90
:
3276 return PLANE_CTL_ROTATE_270
;
3277 case DRM_MODE_ROTATE_180
:
3278 return PLANE_CTL_ROTATE_180
;
3279 case DRM_MODE_ROTATE_270
:
3280 return PLANE_CTL_ROTATE_90
;
3282 MISSING_CASE(rotation
);
3288 u32
skl_plane_ctl(const struct intel_crtc_state
*crtc_state
,
3289 const struct intel_plane_state
*plane_state
)
3291 struct drm_i915_private
*dev_priv
=
3292 to_i915(plane_state
->base
.plane
->dev
);
3293 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
3294 unsigned int rotation
= plane_state
->base
.rotation
;
3295 const struct drm_intel_sprite_colorkey
*key
= &plane_state
->ckey
;
3298 plane_ctl
= PLANE_CTL_ENABLE
;
3300 if (!IS_GEMINILAKE(dev_priv
) && !IS_CANNONLAKE(dev_priv
)) {
3302 PLANE_CTL_PIPE_GAMMA_ENABLE
|
3303 PLANE_CTL_PIPE_CSC_ENABLE
|
3304 PLANE_CTL_PLANE_GAMMA_DISABLE
;
3307 plane_ctl
|= skl_plane_ctl_format(fb
->format
->format
);
3308 plane_ctl
|= skl_plane_ctl_tiling(fb
->modifier
);
3309 plane_ctl
|= skl_plane_ctl_rotation(rotation
);
3311 if (key
->flags
& I915_SET_COLORKEY_DESTINATION
)
3312 plane_ctl
|= PLANE_CTL_KEY_ENABLE_DESTINATION
;
3313 else if (key
->flags
& I915_SET_COLORKEY_SOURCE
)
3314 plane_ctl
|= PLANE_CTL_KEY_ENABLE_SOURCE
;
3319 static void skylake_update_primary_plane(struct intel_plane
*plane
,
3320 const struct intel_crtc_state
*crtc_state
,
3321 const struct intel_plane_state
*plane_state
)
3323 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
3324 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
3325 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
3326 enum plane_id plane_id
= plane
->id
;
3327 enum pipe pipe
= plane
->pipe
;
3328 u32 plane_ctl
= plane_state
->ctl
;
3329 unsigned int rotation
= plane_state
->base
.rotation
;
3330 u32 stride
= skl_plane_stride(fb
, 0, rotation
);
3331 u32 surf_addr
= plane_state
->main
.offset
;
3332 int scaler_id
= plane_state
->scaler_id
;
3333 int src_x
= plane_state
->main
.x
;
3334 int src_y
= plane_state
->main
.y
;
3335 int src_w
= drm_rect_width(&plane_state
->base
.src
) >> 16;
3336 int src_h
= drm_rect_height(&plane_state
->base
.src
) >> 16;
3337 int dst_x
= plane_state
->base
.dst
.x1
;
3338 int dst_y
= plane_state
->base
.dst
.y1
;
3339 int dst_w
= drm_rect_width(&plane_state
->base
.dst
);
3340 int dst_h
= drm_rect_height(&plane_state
->base
.dst
);
3341 unsigned long irqflags
;
3343 /* Sizes are 0 based */
3349 crtc
->dspaddr_offset
= surf_addr
;
3351 crtc
->adjusted_x
= src_x
;
3352 crtc
->adjusted_y
= src_y
;
3354 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
3356 if (IS_GEMINILAKE(dev_priv
) || IS_CANNONLAKE(dev_priv
)) {
3357 I915_WRITE_FW(PLANE_COLOR_CTL(pipe
, plane_id
),
3358 PLANE_COLOR_PIPE_GAMMA_ENABLE
|
3359 PLANE_COLOR_PIPE_CSC_ENABLE
|
3360 PLANE_COLOR_PLANE_GAMMA_DISABLE
);
3363 I915_WRITE_FW(PLANE_CTL(pipe
, plane_id
), plane_ctl
);
3364 I915_WRITE_FW(PLANE_OFFSET(pipe
, plane_id
), (src_y
<< 16) | src_x
);
3365 I915_WRITE_FW(PLANE_STRIDE(pipe
, plane_id
), stride
);
3366 I915_WRITE_FW(PLANE_SIZE(pipe
, plane_id
), (src_h
<< 16) | src_w
);
3368 if (scaler_id
>= 0) {
3369 uint32_t ps_ctrl
= 0;
3371 WARN_ON(!dst_w
|| !dst_h
);
3372 ps_ctrl
= PS_SCALER_EN
| PS_PLANE_SEL(plane_id
) |
3373 crtc_state
->scaler_state
.scalers
[scaler_id
].mode
;
3374 I915_WRITE_FW(SKL_PS_CTRL(pipe
, scaler_id
), ps_ctrl
);
3375 I915_WRITE_FW(SKL_PS_PWR_GATE(pipe
, scaler_id
), 0);
3376 I915_WRITE_FW(SKL_PS_WIN_POS(pipe
, scaler_id
), (dst_x
<< 16) | dst_y
);
3377 I915_WRITE_FW(SKL_PS_WIN_SZ(pipe
, scaler_id
), (dst_w
<< 16) | dst_h
);
3378 I915_WRITE_FW(PLANE_POS(pipe
, plane_id
), 0);
3380 I915_WRITE_FW(PLANE_POS(pipe
, plane_id
), (dst_y
<< 16) | dst_x
);
3383 I915_WRITE_FW(PLANE_SURF(pipe
, plane_id
),
3384 intel_plane_ggtt_offset(plane_state
) + surf_addr
);
3386 POSTING_READ_FW(PLANE_SURF(pipe
, plane_id
));
3388 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
3391 static void skylake_disable_primary_plane(struct intel_plane
*primary
,
3392 struct intel_crtc
*crtc
)
3394 struct drm_i915_private
*dev_priv
= to_i915(primary
->base
.dev
);
3395 enum plane_id plane_id
= primary
->id
;
3396 enum pipe pipe
= primary
->pipe
;
3397 unsigned long irqflags
;
3399 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
3401 I915_WRITE_FW(PLANE_CTL(pipe
, plane_id
), 0);
3402 I915_WRITE_FW(PLANE_SURF(pipe
, plane_id
), 0);
3403 POSTING_READ_FW(PLANE_SURF(pipe
, plane_id
));
3405 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
3408 static void intel_complete_page_flips(struct drm_i915_private
*dev_priv
)
3410 struct intel_crtc
*crtc
;
3412 for_each_intel_crtc(&dev_priv
->drm
, crtc
)
3413 intel_finish_page_flip_cs(dev_priv
, crtc
->pipe
);
3417 __intel_display_resume(struct drm_device
*dev
,
3418 struct drm_atomic_state
*state
,
3419 struct drm_modeset_acquire_ctx
*ctx
)
3421 struct drm_crtc_state
*crtc_state
;
3422 struct drm_crtc
*crtc
;
3425 intel_modeset_setup_hw_state(dev
, ctx
);
3426 i915_redisable_vga(to_i915(dev
));
3432 * We've duplicated the state, pointers to the old state are invalid.
3434 * Don't attempt to use the old state until we commit the duplicated state.
3436 for_each_new_crtc_in_state(state
, crtc
, crtc_state
, i
) {
3438 * Force recalculation even if we restore
3439 * current state. With fast modeset this may not result
3440 * in a modeset when the state is compatible.
3442 crtc_state
->mode_changed
= true;
3445 /* ignore any reset values/BIOS leftovers in the WM registers */
3446 if (!HAS_GMCH_DISPLAY(to_i915(dev
)))
3447 to_intel_atomic_state(state
)->skip_intermediate_wm
= true;
3449 ret
= drm_atomic_helper_commit_duplicated_state(state
, ctx
);
3451 WARN_ON(ret
== -EDEADLK
);
3455 static bool gpu_reset_clobbers_display(struct drm_i915_private
*dev_priv
)
3457 return intel_has_gpu_reset(dev_priv
) &&
3458 INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
);
3461 void intel_prepare_reset(struct drm_i915_private
*dev_priv
)
3463 struct drm_device
*dev
= &dev_priv
->drm
;
3464 struct drm_modeset_acquire_ctx
*ctx
= &dev_priv
->reset_ctx
;
3465 struct drm_atomic_state
*state
;
3469 /* reset doesn't touch the display */
3470 if (!i915
.force_reset_modeset_test
&&
3471 !gpu_reset_clobbers_display(dev_priv
))
3475 * Need mode_config.mutex so that we don't
3476 * trample ongoing ->detect() and whatnot.
3478 mutex_lock(&dev
->mode_config
.mutex
);
3479 drm_modeset_acquire_init(ctx
, 0);
3481 ret
= drm_modeset_lock_all_ctx(dev
, ctx
);
3482 if (ret
!= -EDEADLK
)
3485 drm_modeset_backoff(ctx
);
3488 * Disabling the crtcs gracefully seems nicer. Also the
3489 * g33 docs say we should at least disable all the planes.
3491 state
= drm_atomic_helper_duplicate_state(dev
, ctx
);
3492 if (IS_ERR(state
)) {
3493 ret
= PTR_ERR(state
);
3494 DRM_ERROR("Duplicating state failed with %i\n", ret
);
3498 ret
= drm_atomic_helper_disable_all(dev
, ctx
);
3500 DRM_ERROR("Suspending crtc's failed with %i\n", ret
);
3501 drm_atomic_state_put(state
);
3505 dev_priv
->modeset_restore_state
= state
;
3506 state
->acquire_ctx
= ctx
;
3509 void intel_finish_reset(struct drm_i915_private
*dev_priv
)
3511 struct drm_device
*dev
= &dev_priv
->drm
;
3512 struct drm_modeset_acquire_ctx
*ctx
= &dev_priv
->reset_ctx
;
3513 struct drm_atomic_state
*state
= dev_priv
->modeset_restore_state
;
3516 /* reset doesn't touch the display */
3517 if (!i915
.force_reset_modeset_test
&&
3518 !gpu_reset_clobbers_display(dev_priv
))
3525 * Flips in the rings will be nuked by the reset,
3526 * so complete all pending flips so that user space
3527 * will get its events and not get stuck.
3529 intel_complete_page_flips(dev_priv
);
3531 dev_priv
->modeset_restore_state
= NULL
;
3533 /* reset doesn't touch the display */
3534 if (!gpu_reset_clobbers_display(dev_priv
)) {
3535 /* for testing only restore the display */
3536 ret
= __intel_display_resume(dev
, state
, ctx
);
3538 DRM_ERROR("Restoring old state failed with %i\n", ret
);
3541 * The display has been reset as well,
3542 * so need a full re-initialization.
3544 intel_runtime_pm_disable_interrupts(dev_priv
);
3545 intel_runtime_pm_enable_interrupts(dev_priv
);
3547 intel_pps_unlock_regs_wa(dev_priv
);
3548 intel_modeset_init_hw(dev
);
3550 spin_lock_irq(&dev_priv
->irq_lock
);
3551 if (dev_priv
->display
.hpd_irq_setup
)
3552 dev_priv
->display
.hpd_irq_setup(dev_priv
);
3553 spin_unlock_irq(&dev_priv
->irq_lock
);
3555 ret
= __intel_display_resume(dev
, state
, ctx
);
3557 DRM_ERROR("Restoring old state failed with %i\n", ret
);
3559 intel_hpd_init(dev_priv
);
3562 drm_atomic_state_put(state
);
3564 drm_modeset_drop_locks(ctx
);
3565 drm_modeset_acquire_fini(ctx
);
3566 mutex_unlock(&dev
->mode_config
.mutex
);
3569 static bool abort_flip_on_reset(struct intel_crtc
*crtc
)
3571 struct i915_gpu_error
*error
= &to_i915(crtc
->base
.dev
)->gpu_error
;
3573 if (i915_reset_backoff(error
))
3576 if (crtc
->reset_count
!= i915_reset_count(error
))
3582 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
3584 struct drm_device
*dev
= crtc
->dev
;
3585 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3588 if (abort_flip_on_reset(intel_crtc
))
3591 spin_lock_irq(&dev
->event_lock
);
3592 pending
= to_intel_crtc(crtc
)->flip_work
!= NULL
;
3593 spin_unlock_irq(&dev
->event_lock
);
3598 static void intel_update_pipe_config(struct intel_crtc
*crtc
,
3599 struct intel_crtc_state
*old_crtc_state
)
3601 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
3602 struct intel_crtc_state
*pipe_config
=
3603 to_intel_crtc_state(crtc
->base
.state
);
3605 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
3606 crtc
->base
.mode
= crtc
->base
.state
->mode
;
3609 * Update pipe size and adjust fitter if needed: the reason for this is
3610 * that in compute_mode_changes we check the native mode (not the pfit
3611 * mode) to see if we can flip rather than do a full mode set. In the
3612 * fastboot case, we'll flip, but if we don't update the pipesrc and
3613 * pfit state, we'll end up with a big fb scanned out into the wrong
3617 I915_WRITE(PIPESRC(crtc
->pipe
),
3618 ((pipe_config
->pipe_src_w
- 1) << 16) |
3619 (pipe_config
->pipe_src_h
- 1));
3621 /* on skylake this is done by detaching scalers */
3622 if (INTEL_GEN(dev_priv
) >= 9) {
3623 skl_detach_scalers(crtc
);
3625 if (pipe_config
->pch_pfit
.enabled
)
3626 skylake_pfit_enable(crtc
);
3627 } else if (HAS_PCH_SPLIT(dev_priv
)) {
3628 if (pipe_config
->pch_pfit
.enabled
)
3629 ironlake_pfit_enable(crtc
);
3630 else if (old_crtc_state
->pch_pfit
.enabled
)
3631 ironlake_pfit_disable(crtc
, true);
3635 static void intel_fdi_normal_train(struct intel_crtc
*crtc
)
3637 struct drm_device
*dev
= crtc
->base
.dev
;
3638 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3639 int pipe
= crtc
->pipe
;
3643 /* enable normal train */
3644 reg
= FDI_TX_CTL(pipe
);
3645 temp
= I915_READ(reg
);
3646 if (IS_IVYBRIDGE(dev_priv
)) {
3647 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3648 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3650 temp
&= ~FDI_LINK_TRAIN_NONE
;
3651 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3653 I915_WRITE(reg
, temp
);
3655 reg
= FDI_RX_CTL(pipe
);
3656 temp
= I915_READ(reg
);
3657 if (HAS_PCH_CPT(dev_priv
)) {
3658 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3659 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
3661 temp
&= ~FDI_LINK_TRAIN_NONE
;
3662 temp
|= FDI_LINK_TRAIN_NONE
;
3664 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
3666 /* wait one idle pattern time */
3670 /* IVB wants error correction enabled */
3671 if (IS_IVYBRIDGE(dev_priv
))
3672 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
3673 FDI_FE_ERRC_ENABLE
);
3676 /* The FDI link training functions for ILK/Ibexpeak. */
3677 static void ironlake_fdi_link_train(struct intel_crtc
*crtc
,
3678 const struct intel_crtc_state
*crtc_state
)
3680 struct drm_device
*dev
= crtc
->base
.dev
;
3681 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3682 int pipe
= crtc
->pipe
;
3686 /* FDI needs bits from pipe first */
3687 assert_pipe_enabled(dev_priv
, pipe
);
3689 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3691 reg
= FDI_RX_IMR(pipe
);
3692 temp
= I915_READ(reg
);
3693 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3694 temp
&= ~FDI_RX_BIT_LOCK
;
3695 I915_WRITE(reg
, temp
);
3699 /* enable CPU FDI TX and PCH FDI RX */
3700 reg
= FDI_TX_CTL(pipe
);
3701 temp
= I915_READ(reg
);
3702 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3703 temp
|= FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
3704 temp
&= ~FDI_LINK_TRAIN_NONE
;
3705 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3706 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3708 reg
= FDI_RX_CTL(pipe
);
3709 temp
= I915_READ(reg
);
3710 temp
&= ~FDI_LINK_TRAIN_NONE
;
3711 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3712 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3717 /* Ironlake workaround, enable clock pointer after FDI enable*/
3718 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3719 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
3720 FDI_RX_PHASE_SYNC_POINTER_EN
);
3722 reg
= FDI_RX_IIR(pipe
);
3723 for (tries
= 0; tries
< 5; tries
++) {
3724 temp
= I915_READ(reg
);
3725 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3727 if ((temp
& FDI_RX_BIT_LOCK
)) {
3728 DRM_DEBUG_KMS("FDI train 1 done.\n");
3729 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3734 DRM_ERROR("FDI train 1 fail!\n");
3737 reg
= FDI_TX_CTL(pipe
);
3738 temp
= I915_READ(reg
);
3739 temp
&= ~FDI_LINK_TRAIN_NONE
;
3740 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3741 I915_WRITE(reg
, temp
);
3743 reg
= FDI_RX_CTL(pipe
);
3744 temp
= I915_READ(reg
);
3745 temp
&= ~FDI_LINK_TRAIN_NONE
;
3746 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3747 I915_WRITE(reg
, temp
);
3752 reg
= FDI_RX_IIR(pipe
);
3753 for (tries
= 0; tries
< 5; tries
++) {
3754 temp
= I915_READ(reg
);
3755 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3757 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3758 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3759 DRM_DEBUG_KMS("FDI train 2 done.\n");
3764 DRM_ERROR("FDI train 2 fail!\n");
3766 DRM_DEBUG_KMS("FDI train done\n");
3770 static const int snb_b_fdi_train_param
[] = {
3771 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
3772 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
3773 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
3774 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
3777 /* The FDI link training functions for SNB/Cougarpoint. */
3778 static void gen6_fdi_link_train(struct intel_crtc
*crtc
,
3779 const struct intel_crtc_state
*crtc_state
)
3781 struct drm_device
*dev
= crtc
->base
.dev
;
3782 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3783 int pipe
= crtc
->pipe
;
3787 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3789 reg
= FDI_RX_IMR(pipe
);
3790 temp
= I915_READ(reg
);
3791 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3792 temp
&= ~FDI_RX_BIT_LOCK
;
3793 I915_WRITE(reg
, temp
);
3798 /* enable CPU FDI TX and PCH FDI RX */
3799 reg
= FDI_TX_CTL(pipe
);
3800 temp
= I915_READ(reg
);
3801 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3802 temp
|= FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
3803 temp
&= ~FDI_LINK_TRAIN_NONE
;
3804 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3805 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3807 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3808 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3810 I915_WRITE(FDI_RX_MISC(pipe
),
3811 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3813 reg
= FDI_RX_CTL(pipe
);
3814 temp
= I915_READ(reg
);
3815 if (HAS_PCH_CPT(dev_priv
)) {
3816 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3817 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3819 temp
&= ~FDI_LINK_TRAIN_NONE
;
3820 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3822 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3827 for (i
= 0; i
< 4; i
++) {
3828 reg
= FDI_TX_CTL(pipe
);
3829 temp
= I915_READ(reg
);
3830 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3831 temp
|= snb_b_fdi_train_param
[i
];
3832 I915_WRITE(reg
, temp
);
3837 for (retry
= 0; retry
< 5; retry
++) {
3838 reg
= FDI_RX_IIR(pipe
);
3839 temp
= I915_READ(reg
);
3840 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3841 if (temp
& FDI_RX_BIT_LOCK
) {
3842 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3843 DRM_DEBUG_KMS("FDI train 1 done.\n");
3852 DRM_ERROR("FDI train 1 fail!\n");
3855 reg
= FDI_TX_CTL(pipe
);
3856 temp
= I915_READ(reg
);
3857 temp
&= ~FDI_LINK_TRAIN_NONE
;
3858 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3859 if (IS_GEN6(dev_priv
)) {
3860 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3862 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3864 I915_WRITE(reg
, temp
);
3866 reg
= FDI_RX_CTL(pipe
);
3867 temp
= I915_READ(reg
);
3868 if (HAS_PCH_CPT(dev_priv
)) {
3869 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3870 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3872 temp
&= ~FDI_LINK_TRAIN_NONE
;
3873 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3875 I915_WRITE(reg
, temp
);
3880 for (i
= 0; i
< 4; i
++) {
3881 reg
= FDI_TX_CTL(pipe
);
3882 temp
= I915_READ(reg
);
3883 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3884 temp
|= snb_b_fdi_train_param
[i
];
3885 I915_WRITE(reg
, temp
);
3890 for (retry
= 0; retry
< 5; retry
++) {
3891 reg
= FDI_RX_IIR(pipe
);
3892 temp
= I915_READ(reg
);
3893 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3894 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3895 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3896 DRM_DEBUG_KMS("FDI train 2 done.\n");
3905 DRM_ERROR("FDI train 2 fail!\n");
3907 DRM_DEBUG_KMS("FDI train done.\n");
3910 /* Manual link training for Ivy Bridge A0 parts */
3911 static void ivb_manual_fdi_link_train(struct intel_crtc
*crtc
,
3912 const struct intel_crtc_state
*crtc_state
)
3914 struct drm_device
*dev
= crtc
->base
.dev
;
3915 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3916 int pipe
= crtc
->pipe
;
3920 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3922 reg
= FDI_RX_IMR(pipe
);
3923 temp
= I915_READ(reg
);
3924 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3925 temp
&= ~FDI_RX_BIT_LOCK
;
3926 I915_WRITE(reg
, temp
);
3931 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3932 I915_READ(FDI_RX_IIR(pipe
)));
3934 /* Try each vswing and preemphasis setting twice before moving on */
3935 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
3936 /* disable first in case we need to retry */
3937 reg
= FDI_TX_CTL(pipe
);
3938 temp
= I915_READ(reg
);
3939 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
3940 temp
&= ~FDI_TX_ENABLE
;
3941 I915_WRITE(reg
, temp
);
3943 reg
= FDI_RX_CTL(pipe
);
3944 temp
= I915_READ(reg
);
3945 temp
&= ~FDI_LINK_TRAIN_AUTO
;
3946 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3947 temp
&= ~FDI_RX_ENABLE
;
3948 I915_WRITE(reg
, temp
);
3950 /* enable CPU FDI TX and PCH FDI RX */
3951 reg
= FDI_TX_CTL(pipe
);
3952 temp
= I915_READ(reg
);
3953 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3954 temp
|= FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
3955 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
3956 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3957 temp
|= snb_b_fdi_train_param
[j
/2];
3958 temp
|= FDI_COMPOSITE_SYNC
;
3959 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3961 I915_WRITE(FDI_RX_MISC(pipe
),
3962 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3964 reg
= FDI_RX_CTL(pipe
);
3965 temp
= I915_READ(reg
);
3966 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3967 temp
|= FDI_COMPOSITE_SYNC
;
3968 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3971 udelay(1); /* should be 0.5us */
3973 for (i
= 0; i
< 4; i
++) {
3974 reg
= FDI_RX_IIR(pipe
);
3975 temp
= I915_READ(reg
);
3976 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3978 if (temp
& FDI_RX_BIT_LOCK
||
3979 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
3980 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3981 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3985 udelay(1); /* should be 0.5us */
3988 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
3993 reg
= FDI_TX_CTL(pipe
);
3994 temp
= I915_READ(reg
);
3995 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3996 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
3997 I915_WRITE(reg
, temp
);
3999 reg
= FDI_RX_CTL(pipe
);
4000 temp
= I915_READ(reg
);
4001 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
4002 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
4003 I915_WRITE(reg
, temp
);
4006 udelay(2); /* should be 1.5us */
4008 for (i
= 0; i
< 4; i
++) {
4009 reg
= FDI_RX_IIR(pipe
);
4010 temp
= I915_READ(reg
);
4011 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
4013 if (temp
& FDI_RX_SYMBOL_LOCK
||
4014 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
4015 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
4016 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4020 udelay(2); /* should be 1.5us */
4023 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
4027 DRM_DEBUG_KMS("FDI train done.\n");
4030 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
4032 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4033 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4034 int pipe
= intel_crtc
->pipe
;
4038 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4039 reg
= FDI_RX_CTL(pipe
);
4040 temp
= I915_READ(reg
);
4041 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
4042 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
4043 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
4044 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
4049 /* Switch from Rawclk to PCDclk */
4050 temp
= I915_READ(reg
);
4051 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
4056 /* Enable CPU FDI TX PLL, always on for Ironlake */
4057 reg
= FDI_TX_CTL(pipe
);
4058 temp
= I915_READ(reg
);
4059 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
4060 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
4067 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
4069 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4070 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4071 int pipe
= intel_crtc
->pipe
;
4075 /* Switch from PCDclk to Rawclk */
4076 reg
= FDI_RX_CTL(pipe
);
4077 temp
= I915_READ(reg
);
4078 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
4080 /* Disable CPU FDI TX PLL */
4081 reg
= FDI_TX_CTL(pipe
);
4082 temp
= I915_READ(reg
);
4083 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
4088 reg
= FDI_RX_CTL(pipe
);
4089 temp
= I915_READ(reg
);
4090 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
4092 /* Wait for the clocks to turn off. */
4097 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
4099 struct drm_device
*dev
= crtc
->dev
;
4100 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4101 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4102 int pipe
= intel_crtc
->pipe
;
4106 /* disable CPU FDI tx and PCH FDI rx */
4107 reg
= FDI_TX_CTL(pipe
);
4108 temp
= I915_READ(reg
);
4109 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
4112 reg
= FDI_RX_CTL(pipe
);
4113 temp
= I915_READ(reg
);
4114 temp
&= ~(0x7 << 16);
4115 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
4116 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
4121 /* Ironlake workaround, disable clock pointer after downing FDI */
4122 if (HAS_PCH_IBX(dev_priv
))
4123 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
4125 /* still set train pattern 1 */
4126 reg
= FDI_TX_CTL(pipe
);
4127 temp
= I915_READ(reg
);
4128 temp
&= ~FDI_LINK_TRAIN_NONE
;
4129 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
4130 I915_WRITE(reg
, temp
);
4132 reg
= FDI_RX_CTL(pipe
);
4133 temp
= I915_READ(reg
);
4134 if (HAS_PCH_CPT(dev_priv
)) {
4135 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
4136 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
4138 temp
&= ~FDI_LINK_TRAIN_NONE
;
4139 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
4141 /* BPC in FDI rx is consistent with that in PIPECONF */
4142 temp
&= ~(0x07 << 16);
4143 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
4144 I915_WRITE(reg
, temp
);
4150 bool intel_has_pending_fb_unpin(struct drm_i915_private
*dev_priv
)
4152 struct intel_crtc
*crtc
;
4154 /* Note that we don't need to be called with mode_config.lock here
4155 * as our list of CRTC objects is static for the lifetime of the
4156 * device and so cannot disappear as we iterate. Similarly, we can
4157 * happily treat the predicates as racy, atomic checks as userspace
4158 * cannot claim and pin a new fb without at least acquring the
4159 * struct_mutex and so serialising with us.
4161 for_each_intel_crtc(&dev_priv
->drm
, crtc
) {
4162 if (atomic_read(&crtc
->unpin_work_count
) == 0)
4165 if (crtc
->flip_work
)
4166 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
4174 static void page_flip_completed(struct intel_crtc
*intel_crtc
)
4176 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
4177 struct intel_flip_work
*work
= intel_crtc
->flip_work
;
4179 intel_crtc
->flip_work
= NULL
;
4182 drm_crtc_send_vblank_event(&intel_crtc
->base
, work
->event
);
4184 drm_crtc_vblank_put(&intel_crtc
->base
);
4186 wake_up_all(&dev_priv
->pending_flip_queue
);
4187 trace_i915_flip_complete(intel_crtc
->plane
,
4188 work
->pending_flip_obj
);
4190 queue_work(dev_priv
->wq
, &work
->unpin_work
);
4193 static int intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
4195 struct drm_device
*dev
= crtc
->dev
;
4196 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4199 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
4201 ret
= wait_event_interruptible_timeout(
4202 dev_priv
->pending_flip_queue
,
4203 !intel_crtc_has_pending_flip(crtc
),
4210 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4211 struct intel_flip_work
*work
;
4213 spin_lock_irq(&dev
->event_lock
);
4214 work
= intel_crtc
->flip_work
;
4215 if (work
&& !is_mmio_work(work
)) {
4216 WARN_ONCE(1, "Removing stuck page flip\n");
4217 page_flip_completed(intel_crtc
);
4219 spin_unlock_irq(&dev
->event_lock
);
4225 void lpt_disable_iclkip(struct drm_i915_private
*dev_priv
)
4229 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
4231 mutex_lock(&dev_priv
->sb_lock
);
4233 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4234 temp
|= SBI_SSCCTL_DISABLE
;
4235 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
4237 mutex_unlock(&dev_priv
->sb_lock
);
4240 /* Program iCLKIP clock to the desired frequency */
4241 static void lpt_program_iclkip(struct intel_crtc
*crtc
)
4243 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
4244 int clock
= crtc
->config
->base
.adjusted_mode
.crtc_clock
;
4245 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
4248 lpt_disable_iclkip(dev_priv
);
4250 /* The iCLK virtual clock root frequency is in MHz,
4251 * but the adjusted_mode->crtc_clock in in KHz. To get the
4252 * divisors, it is necessary to divide one by another, so we
4253 * convert the virtual clock precision to KHz here for higher
4256 for (auxdiv
= 0; auxdiv
< 2; auxdiv
++) {
4257 u32 iclk_virtual_root_freq
= 172800 * 1000;
4258 u32 iclk_pi_range
= 64;
4259 u32 desired_divisor
;
4261 desired_divisor
= DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
4263 divsel
= (desired_divisor
/ iclk_pi_range
) - 2;
4264 phaseinc
= desired_divisor
% iclk_pi_range
;
4267 * Near 20MHz is a corner case which is
4268 * out of range for the 7-bit divisor
4274 /* This should not happen with any sane values */
4275 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
4276 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
4277 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
4278 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
4280 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4287 mutex_lock(&dev_priv
->sb_lock
);
4289 /* Program SSCDIVINTPHASE6 */
4290 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
4291 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
4292 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
4293 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
4294 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
4295 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
4296 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
4297 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
4299 /* Program SSCAUXDIV */
4300 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
4301 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4302 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
4303 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
4305 /* Enable modulator and associated divider */
4306 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4307 temp
&= ~SBI_SSCCTL_DISABLE
;
4308 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
4310 mutex_unlock(&dev_priv
->sb_lock
);
4312 /* Wait for initialization time */
4315 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
4318 int lpt_get_iclkip(struct drm_i915_private
*dev_priv
)
4320 u32 divsel
, phaseinc
, auxdiv
;
4321 u32 iclk_virtual_root_freq
= 172800 * 1000;
4322 u32 iclk_pi_range
= 64;
4323 u32 desired_divisor
;
4326 if ((I915_READ(PIXCLK_GATE
) & PIXCLK_GATE_UNGATE
) == 0)
4329 mutex_lock(&dev_priv
->sb_lock
);
4331 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4332 if (temp
& SBI_SSCCTL_DISABLE
) {
4333 mutex_unlock(&dev_priv
->sb_lock
);
4337 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
4338 divsel
= (temp
& SBI_SSCDIVINTPHASE_DIVSEL_MASK
) >>
4339 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT
;
4340 phaseinc
= (temp
& SBI_SSCDIVINTPHASE_INCVAL_MASK
) >>
4341 SBI_SSCDIVINTPHASE_INCVAL_SHIFT
;
4343 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
4344 auxdiv
= (temp
& SBI_SSCAUXDIV_FINALDIV2SEL_MASK
) >>
4345 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT
;
4347 mutex_unlock(&dev_priv
->sb_lock
);
4349 desired_divisor
= (divsel
+ 2) * iclk_pi_range
+ phaseinc
;
4351 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
4352 desired_divisor
<< auxdiv
);
4355 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
4356 enum pipe pch_transcoder
)
4358 struct drm_device
*dev
= crtc
->base
.dev
;
4359 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4360 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
4362 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
4363 I915_READ(HTOTAL(cpu_transcoder
)));
4364 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
4365 I915_READ(HBLANK(cpu_transcoder
)));
4366 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
4367 I915_READ(HSYNC(cpu_transcoder
)));
4369 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
4370 I915_READ(VTOTAL(cpu_transcoder
)));
4371 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
4372 I915_READ(VBLANK(cpu_transcoder
)));
4373 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
4374 I915_READ(VSYNC(cpu_transcoder
)));
4375 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
4376 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
4379 static void cpt_set_fdi_bc_bifurcation(struct drm_device
*dev
, bool enable
)
4381 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4384 temp
= I915_READ(SOUTH_CHICKEN1
);
4385 if (!!(temp
& FDI_BC_BIFURCATION_SELECT
) == enable
)
4388 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
4389 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
4391 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
4393 temp
|= FDI_BC_BIFURCATION_SELECT
;
4395 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable
? "en" : "dis");
4396 I915_WRITE(SOUTH_CHICKEN1
, temp
);
4397 POSTING_READ(SOUTH_CHICKEN1
);
4400 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
4402 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4404 switch (intel_crtc
->pipe
) {
4408 if (intel_crtc
->config
->fdi_lanes
> 2)
4409 cpt_set_fdi_bc_bifurcation(dev
, false);
4411 cpt_set_fdi_bc_bifurcation(dev
, true);
4415 cpt_set_fdi_bc_bifurcation(dev
, true);
4423 /* Return which DP Port should be selected for Transcoder DP control */
4425 intel_trans_dp_port_sel(struct intel_crtc
*crtc
)
4427 struct drm_device
*dev
= crtc
->base
.dev
;
4428 struct intel_encoder
*encoder
;
4430 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
4431 if (encoder
->type
== INTEL_OUTPUT_DP
||
4432 encoder
->type
== INTEL_OUTPUT_EDP
)
4433 return enc_to_dig_port(&encoder
->base
)->port
;
4440 * Enable PCH resources required for PCH ports:
4442 * - FDI training & RX/TX
4443 * - update transcoder timings
4444 * - DP transcoding bits
4447 static void ironlake_pch_enable(const struct intel_crtc_state
*crtc_state
)
4449 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
4450 struct drm_device
*dev
= crtc
->base
.dev
;
4451 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4452 int pipe
= crtc
->pipe
;
4455 assert_pch_transcoder_disabled(dev_priv
, pipe
);
4457 if (IS_IVYBRIDGE(dev_priv
))
4458 ivybridge_update_fdi_bc_bifurcation(crtc
);
4460 /* Write the TU size bits before fdi link training, so that error
4461 * detection works. */
4462 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
4463 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
4465 /* For PCH output, training FDI link */
4466 dev_priv
->display
.fdi_link_train(crtc
, crtc_state
);
4468 /* We need to program the right clock selection before writing the pixel
4469 * mutliplier into the DPLL. */
4470 if (HAS_PCH_CPT(dev_priv
)) {
4473 temp
= I915_READ(PCH_DPLL_SEL
);
4474 temp
|= TRANS_DPLL_ENABLE(pipe
);
4475 sel
= TRANS_DPLLB_SEL(pipe
);
4476 if (crtc_state
->shared_dpll
==
4477 intel_get_shared_dpll_by_id(dev_priv
, DPLL_ID_PCH_PLL_B
))
4481 I915_WRITE(PCH_DPLL_SEL
, temp
);
4484 /* XXX: pch pll's can be enabled any time before we enable the PCH
4485 * transcoder, and we actually should do this to not upset any PCH
4486 * transcoder that already use the clock when we share it.
4488 * Note that enable_shared_dpll tries to do the right thing, but
4489 * get_shared_dpll unconditionally resets the pll - we need that to have
4490 * the right LVDS enable sequence. */
4491 intel_enable_shared_dpll(crtc
);
4493 /* set transcoder timing, panel must allow it */
4494 assert_panel_unlocked(dev_priv
, pipe
);
4495 ironlake_pch_transcoder_set_timings(crtc
, pipe
);
4497 intel_fdi_normal_train(crtc
);
4499 /* For PCH DP, enable TRANS_DP_CTL */
4500 if (HAS_PCH_CPT(dev_priv
) &&
4501 intel_crtc_has_dp_encoder(crtc_state
)) {
4502 const struct drm_display_mode
*adjusted_mode
=
4503 &crtc_state
->base
.adjusted_mode
;
4504 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
4505 i915_reg_t reg
= TRANS_DP_CTL(pipe
);
4506 temp
= I915_READ(reg
);
4507 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
4508 TRANS_DP_SYNC_MASK
|
4510 temp
|= TRANS_DP_OUTPUT_ENABLE
;
4511 temp
|= bpc
<< 9; /* same format but at 11:9 */
4513 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
4514 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
4515 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
4516 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
4518 switch (intel_trans_dp_port_sel(crtc
)) {
4520 temp
|= TRANS_DP_PORT_SEL_B
;
4523 temp
|= TRANS_DP_PORT_SEL_C
;
4526 temp
|= TRANS_DP_PORT_SEL_D
;
4532 I915_WRITE(reg
, temp
);
4535 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
4538 static void lpt_pch_enable(const struct intel_crtc_state
*crtc_state
)
4540 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
4541 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
4542 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
4544 assert_pch_transcoder_disabled(dev_priv
, PIPE_A
);
4546 lpt_program_iclkip(crtc
);
4548 /* Set transcoder timing. */
4549 ironlake_pch_transcoder_set_timings(crtc
, PIPE_A
);
4551 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
4554 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
4556 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4557 i915_reg_t dslreg
= PIPEDSL(pipe
);
4560 temp
= I915_READ(dslreg
);
4562 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
4563 if (wait_for(I915_READ(dslreg
) != temp
, 5))
4564 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
4569 skl_update_scaler(struct intel_crtc_state
*crtc_state
, bool force_detach
,
4570 unsigned int scaler_user
, int *scaler_id
,
4571 int src_w
, int src_h
, int dst_w
, int dst_h
)
4573 struct intel_crtc_scaler_state
*scaler_state
=
4574 &crtc_state
->scaler_state
;
4575 struct intel_crtc
*intel_crtc
=
4576 to_intel_crtc(crtc_state
->base
.crtc
);
4577 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
4578 const struct drm_display_mode
*adjusted_mode
=
4579 &crtc_state
->base
.adjusted_mode
;
4583 * Src coordinates are already rotated by 270 degrees for
4584 * the 90/270 degree plane rotation cases (to match the
4585 * GTT mapping), hence no need to account for rotation here.
4587 need_scaling
= src_w
!= dst_w
|| src_h
!= dst_h
;
4590 * Scaling/fitting not supported in IF-ID mode in GEN9+
4591 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4592 * Once NV12 is enabled, handle it here while allocating scaler
4595 if (INTEL_GEN(dev_priv
) >= 9 && crtc_state
->base
.enable
&&
4596 need_scaling
&& adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
4597 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
4602 * if plane is being disabled or scaler is no more required or force detach
4603 * - free scaler binded to this plane/crtc
4604 * - in order to do this, update crtc->scaler_usage
4606 * Here scaler state in crtc_state is set free so that
4607 * scaler can be assigned to other user. Actual register
4608 * update to free the scaler is done in plane/panel-fit programming.
4609 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4611 if (force_detach
|| !need_scaling
) {
4612 if (*scaler_id
>= 0) {
4613 scaler_state
->scaler_users
&= ~(1 << scaler_user
);
4614 scaler_state
->scalers
[*scaler_id
].in_use
= 0;
4616 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4617 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4618 intel_crtc
->pipe
, scaler_user
, *scaler_id
,
4619 scaler_state
->scaler_users
);
4626 if (src_w
< SKL_MIN_SRC_W
|| src_h
< SKL_MIN_SRC_H
||
4627 dst_w
< SKL_MIN_DST_W
|| dst_h
< SKL_MIN_DST_H
||
4629 src_w
> SKL_MAX_SRC_W
|| src_h
> SKL_MAX_SRC_H
||
4630 dst_w
> SKL_MAX_DST_W
|| dst_h
> SKL_MAX_DST_H
) {
4631 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4632 "size is out of scaler range\n",
4633 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
);
4637 /* mark this plane as a scaler user in crtc_state */
4638 scaler_state
->scaler_users
|= (1 << scaler_user
);
4639 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4640 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4641 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
,
4642 scaler_state
->scaler_users
);
4648 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4650 * @state: crtc's scaler state
4653 * 0 - scaler_usage updated successfully
4654 * error - requested scaling cannot be supported or other error condition
4656 int skl_update_scaler_crtc(struct intel_crtc_state
*state
)
4658 const struct drm_display_mode
*adjusted_mode
= &state
->base
.adjusted_mode
;
4660 return skl_update_scaler(state
, !state
->base
.active
, SKL_CRTC_INDEX
,
4661 &state
->scaler_state
.scaler_id
,
4662 state
->pipe_src_w
, state
->pipe_src_h
,
4663 adjusted_mode
->crtc_hdisplay
, adjusted_mode
->crtc_vdisplay
);
4667 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4669 * @state: crtc's scaler state
4670 * @plane_state: atomic plane state to update
4673 * 0 - scaler_usage updated successfully
4674 * error - requested scaling cannot be supported or other error condition
4676 static int skl_update_scaler_plane(struct intel_crtc_state
*crtc_state
,
4677 struct intel_plane_state
*plane_state
)
4680 struct intel_plane
*intel_plane
=
4681 to_intel_plane(plane_state
->base
.plane
);
4682 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
4685 bool force_detach
= !fb
|| !plane_state
->base
.visible
;
4687 ret
= skl_update_scaler(crtc_state
, force_detach
,
4688 drm_plane_index(&intel_plane
->base
),
4689 &plane_state
->scaler_id
,
4690 drm_rect_width(&plane_state
->base
.src
) >> 16,
4691 drm_rect_height(&plane_state
->base
.src
) >> 16,
4692 drm_rect_width(&plane_state
->base
.dst
),
4693 drm_rect_height(&plane_state
->base
.dst
));
4695 if (ret
|| plane_state
->scaler_id
< 0)
4698 /* check colorkey */
4699 if (plane_state
->ckey
.flags
!= I915_SET_COLORKEY_NONE
) {
4700 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
4701 intel_plane
->base
.base
.id
,
4702 intel_plane
->base
.name
);
4706 /* Check src format */
4707 switch (fb
->format
->format
) {
4708 case DRM_FORMAT_RGB565
:
4709 case DRM_FORMAT_XBGR8888
:
4710 case DRM_FORMAT_XRGB8888
:
4711 case DRM_FORMAT_ABGR8888
:
4712 case DRM_FORMAT_ARGB8888
:
4713 case DRM_FORMAT_XRGB2101010
:
4714 case DRM_FORMAT_XBGR2101010
:
4715 case DRM_FORMAT_YUYV
:
4716 case DRM_FORMAT_YVYU
:
4717 case DRM_FORMAT_UYVY
:
4718 case DRM_FORMAT_VYUY
:
4721 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
4722 intel_plane
->base
.base
.id
, intel_plane
->base
.name
,
4723 fb
->base
.id
, fb
->format
->format
);
4730 static void skylake_scaler_disable(struct intel_crtc
*crtc
)
4734 for (i
= 0; i
< crtc
->num_scalers
; i
++)
4735 skl_detach_scaler(crtc
, i
);
4738 static void skylake_pfit_enable(struct intel_crtc
*crtc
)
4740 struct drm_device
*dev
= crtc
->base
.dev
;
4741 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4742 int pipe
= crtc
->pipe
;
4743 struct intel_crtc_scaler_state
*scaler_state
=
4744 &crtc
->config
->scaler_state
;
4746 if (crtc
->config
->pch_pfit
.enabled
) {
4749 if (WARN_ON(crtc
->config
->scaler_state
.scaler_id
< 0))
4752 id
= scaler_state
->scaler_id
;
4753 I915_WRITE(SKL_PS_CTRL(pipe
, id
), PS_SCALER_EN
|
4754 PS_FILTER_MEDIUM
| scaler_state
->scalers
[id
].mode
);
4755 I915_WRITE(SKL_PS_WIN_POS(pipe
, id
), crtc
->config
->pch_pfit
.pos
);
4756 I915_WRITE(SKL_PS_WIN_SZ(pipe
, id
), crtc
->config
->pch_pfit
.size
);
4760 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
4762 struct drm_device
*dev
= crtc
->base
.dev
;
4763 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4764 int pipe
= crtc
->pipe
;
4766 if (crtc
->config
->pch_pfit
.enabled
) {
4767 /* Force use of hard-coded filter coefficients
4768 * as some pre-programmed values are broken,
4771 if (IS_IVYBRIDGE(dev_priv
) || IS_HASWELL(dev_priv
))
4772 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
4773 PF_PIPE_SEL_IVB(pipe
));
4775 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
4776 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
->pch_pfit
.pos
);
4777 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
->pch_pfit
.size
);
4781 void hsw_enable_ips(struct intel_crtc
*crtc
)
4783 struct drm_device
*dev
= crtc
->base
.dev
;
4784 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4786 if (!crtc
->config
->ips_enabled
)
4790 * We can only enable IPS after we enable a plane and wait for a vblank
4791 * This function is called from post_plane_update, which is run after
4795 assert_plane_enabled(dev_priv
, crtc
->plane
);
4796 if (IS_BROADWELL(dev_priv
)) {
4797 mutex_lock(&dev_priv
->rps
.hw_lock
);
4798 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
4799 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4800 /* Quoting Art Runyan: "its not safe to expect any particular
4801 * value in IPS_CTL bit 31 after enabling IPS through the
4802 * mailbox." Moreover, the mailbox may return a bogus state,
4803 * so we need to just enable it and continue on.
4806 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
4807 /* The bit only becomes 1 in the next vblank, so this wait here
4808 * is essentially intel_wait_for_vblank. If we don't have this
4809 * and don't wait for vblanks until the end of crtc_enable, then
4810 * the HW state readout code will complain that the expected
4811 * IPS_CTL value is not the one we read. */
4812 if (intel_wait_for_register(dev_priv
,
4813 IPS_CTL
, IPS_ENABLE
, IPS_ENABLE
,
4815 DRM_ERROR("Timed out waiting for IPS enable\n");
4819 void hsw_disable_ips(struct intel_crtc
*crtc
)
4821 struct drm_device
*dev
= crtc
->base
.dev
;
4822 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4824 if (!crtc
->config
->ips_enabled
)
4827 assert_plane_enabled(dev_priv
, crtc
->plane
);
4828 if (IS_BROADWELL(dev_priv
)) {
4829 mutex_lock(&dev_priv
->rps
.hw_lock
);
4830 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
4831 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4832 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4833 if (intel_wait_for_register(dev_priv
,
4834 IPS_CTL
, IPS_ENABLE
, 0,
4836 DRM_ERROR("Timed out waiting for IPS disable\n");
4838 I915_WRITE(IPS_CTL
, 0);
4839 POSTING_READ(IPS_CTL
);
4842 /* We need to wait for a vblank before we can disable the plane. */
4843 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
4846 static void intel_crtc_dpms_overlay_disable(struct intel_crtc
*intel_crtc
)
4848 if (intel_crtc
->overlay
) {
4849 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4851 mutex_lock(&dev
->struct_mutex
);
4852 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
4853 mutex_unlock(&dev
->struct_mutex
);
4856 /* Let userspace switch the overlay on again. In most cases userspace
4857 * has to recompute where to put it anyway.
4862 * intel_post_enable_primary - Perform operations after enabling primary plane
4863 * @crtc: the CRTC whose primary plane was just enabled
4865 * Performs potentially sleeping operations that must be done after the primary
4866 * plane is enabled, such as updating FBC and IPS. Note that this may be
4867 * called due to an explicit primary plane update, or due to an implicit
4868 * re-enable that is caused when a sprite plane is updated to no longer
4869 * completely hide the primary plane.
4872 intel_post_enable_primary(struct drm_crtc
*crtc
)
4874 struct drm_device
*dev
= crtc
->dev
;
4875 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4876 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4877 int pipe
= intel_crtc
->pipe
;
4880 * FIXME IPS should be fine as long as one plane is
4881 * enabled, but in practice it seems to have problems
4882 * when going from primary only to sprite only and vice
4885 hsw_enable_ips(intel_crtc
);
4888 * Gen2 reports pipe underruns whenever all planes are disabled.
4889 * So don't enable underrun reporting before at least some planes
4891 * FIXME: Need to fix the logic to work when we turn off all planes
4892 * but leave the pipe running.
4894 if (IS_GEN2(dev_priv
))
4895 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4897 /* Underruns don't always raise interrupts, so check manually. */
4898 intel_check_cpu_fifo_underruns(dev_priv
);
4899 intel_check_pch_fifo_underruns(dev_priv
);
4902 /* FIXME move all this to pre_plane_update() with proper state tracking */
4904 intel_pre_disable_primary(struct drm_crtc
*crtc
)
4906 struct drm_device
*dev
= crtc
->dev
;
4907 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4908 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4909 int pipe
= intel_crtc
->pipe
;
4912 * Gen2 reports pipe underruns whenever all planes are disabled.
4913 * So diasble underrun reporting before all the planes get disabled.
4914 * FIXME: Need to fix the logic to work when we turn off all planes
4915 * but leave the pipe running.
4917 if (IS_GEN2(dev_priv
))
4918 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4921 * FIXME IPS should be fine as long as one plane is
4922 * enabled, but in practice it seems to have problems
4923 * when going from primary only to sprite only and vice
4926 hsw_disable_ips(intel_crtc
);
4929 /* FIXME get rid of this and use pre_plane_update */
4931 intel_pre_disable_primary_noatomic(struct drm_crtc
*crtc
)
4933 struct drm_device
*dev
= crtc
->dev
;
4934 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4935 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4936 int pipe
= intel_crtc
->pipe
;
4938 intel_pre_disable_primary(crtc
);
4941 * Vblank time updates from the shadow to live plane control register
4942 * are blocked if the memory self-refresh mode is active at that
4943 * moment. So to make sure the plane gets truly disabled, disable
4944 * first the self-refresh mode. The self-refresh enable bit in turn
4945 * will be checked/applied by the HW only at the next frame start
4946 * event which is after the vblank start event, so we need to have a
4947 * wait-for-vblank between disabling the plane and the pipe.
4949 if (HAS_GMCH_DISPLAY(dev_priv
) &&
4950 intel_set_memory_cxsr(dev_priv
, false))
4951 intel_wait_for_vblank(dev_priv
, pipe
);
4954 static void intel_post_plane_update(struct intel_crtc_state
*old_crtc_state
)
4956 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
4957 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
4958 struct intel_crtc_state
*pipe_config
=
4959 to_intel_crtc_state(crtc
->base
.state
);
4960 struct drm_plane
*primary
= crtc
->base
.primary
;
4961 struct drm_plane_state
*old_pri_state
=
4962 drm_atomic_get_existing_plane_state(old_state
, primary
);
4964 intel_frontbuffer_flip(to_i915(crtc
->base
.dev
), pipe_config
->fb_bits
);
4966 if (pipe_config
->update_wm_post
&& pipe_config
->base
.active
)
4967 intel_update_watermarks(crtc
);
4969 if (old_pri_state
) {
4970 struct intel_plane_state
*primary_state
=
4971 to_intel_plane_state(primary
->state
);
4972 struct intel_plane_state
*old_primary_state
=
4973 to_intel_plane_state(old_pri_state
);
4975 intel_fbc_post_update(crtc
);
4977 if (primary_state
->base
.visible
&&
4978 (needs_modeset(&pipe_config
->base
) ||
4979 !old_primary_state
->base
.visible
))
4980 intel_post_enable_primary(&crtc
->base
);
4984 static void intel_pre_plane_update(struct intel_crtc_state
*old_crtc_state
,
4985 struct intel_crtc_state
*pipe_config
)
4987 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
4988 struct drm_device
*dev
= crtc
->base
.dev
;
4989 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4990 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
4991 struct drm_plane
*primary
= crtc
->base
.primary
;
4992 struct drm_plane_state
*old_pri_state
=
4993 drm_atomic_get_existing_plane_state(old_state
, primary
);
4994 bool modeset
= needs_modeset(&pipe_config
->base
);
4995 struct intel_atomic_state
*old_intel_state
=
4996 to_intel_atomic_state(old_state
);
4998 if (old_pri_state
) {
4999 struct intel_plane_state
*primary_state
=
5000 to_intel_plane_state(primary
->state
);
5001 struct intel_plane_state
*old_primary_state
=
5002 to_intel_plane_state(old_pri_state
);
5004 intel_fbc_pre_update(crtc
, pipe_config
, primary_state
);
5006 if (old_primary_state
->base
.visible
&&
5007 (modeset
|| !primary_state
->base
.visible
))
5008 intel_pre_disable_primary(&crtc
->base
);
5012 * Vblank time updates from the shadow to live plane control register
5013 * are blocked if the memory self-refresh mode is active at that
5014 * moment. So to make sure the plane gets truly disabled, disable
5015 * first the self-refresh mode. The self-refresh enable bit in turn
5016 * will be checked/applied by the HW only at the next frame start
5017 * event which is after the vblank start event, so we need to have a
5018 * wait-for-vblank between disabling the plane and the pipe.
5020 if (HAS_GMCH_DISPLAY(dev_priv
) && old_crtc_state
->base
.active
&&
5021 pipe_config
->disable_cxsr
&& intel_set_memory_cxsr(dev_priv
, false))
5022 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
5025 * IVB workaround: must disable low power watermarks for at least
5026 * one frame before enabling scaling. LP watermarks can be re-enabled
5027 * when scaling is disabled.
5029 * WaCxSRDisabledForSpriteScaling:ivb
5031 if (pipe_config
->disable_lp_wm
&& ilk_disable_lp_wm(dev
))
5032 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
5035 * If we're doing a modeset, we're done. No need to do any pre-vblank
5036 * watermark programming here.
5038 if (needs_modeset(&pipe_config
->base
))
5042 * For platforms that support atomic watermarks, program the
5043 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5044 * will be the intermediate values that are safe for both pre- and
5045 * post- vblank; when vblank happens, the 'active' values will be set
5046 * to the final 'target' values and we'll do this again to get the
5047 * optimal watermarks. For gen9+ platforms, the values we program here
5048 * will be the final target values which will get automatically latched
5049 * at vblank time; no further programming will be necessary.
5051 * If a platform hasn't been transitioned to atomic watermarks yet,
5052 * we'll continue to update watermarks the old way, if flags tell
5055 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5056 dev_priv
->display
.initial_watermarks(old_intel_state
,
5058 else if (pipe_config
->update_wm_pre
)
5059 intel_update_watermarks(crtc
);
5062 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
, unsigned plane_mask
)
5064 struct drm_device
*dev
= crtc
->dev
;
5065 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5066 struct drm_plane
*p
;
5067 int pipe
= intel_crtc
->pipe
;
5069 intel_crtc_dpms_overlay_disable(intel_crtc
);
5071 drm_for_each_plane_mask(p
, dev
, plane_mask
)
5072 to_intel_plane(p
)->disable_plane(to_intel_plane(p
), intel_crtc
);
5075 * FIXME: Once we grow proper nuclear flip support out of this we need
5076 * to compute the mask of flip planes precisely. For the time being
5077 * consider this a flip to a NULL plane.
5079 intel_frontbuffer_flip(to_i915(dev
), INTEL_FRONTBUFFER_ALL_MASK(pipe
));
5082 static void intel_encoders_pre_pll_enable(struct drm_crtc
*crtc
,
5083 struct intel_crtc_state
*crtc_state
,
5084 struct drm_atomic_state
*old_state
)
5086 struct drm_connector_state
*conn_state
;
5087 struct drm_connector
*conn
;
5090 for_each_new_connector_in_state(old_state
, conn
, conn_state
, i
) {
5091 struct intel_encoder
*encoder
=
5092 to_intel_encoder(conn_state
->best_encoder
);
5094 if (conn_state
->crtc
!= crtc
)
5097 if (encoder
->pre_pll_enable
)
5098 encoder
->pre_pll_enable(encoder
, crtc_state
, conn_state
);
5102 static void intel_encoders_pre_enable(struct drm_crtc
*crtc
,
5103 struct intel_crtc_state
*crtc_state
,
5104 struct drm_atomic_state
*old_state
)
5106 struct drm_connector_state
*conn_state
;
5107 struct drm_connector
*conn
;
5110 for_each_new_connector_in_state(old_state
, conn
, conn_state
, i
) {
5111 struct intel_encoder
*encoder
=
5112 to_intel_encoder(conn_state
->best_encoder
);
5114 if (conn_state
->crtc
!= crtc
)
5117 if (encoder
->pre_enable
)
5118 encoder
->pre_enable(encoder
, crtc_state
, conn_state
);
5122 static void intel_encoders_enable(struct drm_crtc
*crtc
,
5123 struct intel_crtc_state
*crtc_state
,
5124 struct drm_atomic_state
*old_state
)
5126 struct drm_connector_state
*conn_state
;
5127 struct drm_connector
*conn
;
5130 for_each_new_connector_in_state(old_state
, conn
, conn_state
, i
) {
5131 struct intel_encoder
*encoder
=
5132 to_intel_encoder(conn_state
->best_encoder
);
5134 if (conn_state
->crtc
!= crtc
)
5137 encoder
->enable(encoder
, crtc_state
, conn_state
);
5138 intel_opregion_notify_encoder(encoder
, true);
5142 static void intel_encoders_disable(struct drm_crtc
*crtc
,
5143 struct intel_crtc_state
*old_crtc_state
,
5144 struct drm_atomic_state
*old_state
)
5146 struct drm_connector_state
*old_conn_state
;
5147 struct drm_connector
*conn
;
5150 for_each_old_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5151 struct intel_encoder
*encoder
=
5152 to_intel_encoder(old_conn_state
->best_encoder
);
5154 if (old_conn_state
->crtc
!= crtc
)
5157 intel_opregion_notify_encoder(encoder
, false);
5158 encoder
->disable(encoder
, old_crtc_state
, old_conn_state
);
5162 static void intel_encoders_post_disable(struct drm_crtc
*crtc
,
5163 struct intel_crtc_state
*old_crtc_state
,
5164 struct drm_atomic_state
*old_state
)
5166 struct drm_connector_state
*old_conn_state
;
5167 struct drm_connector
*conn
;
5170 for_each_old_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5171 struct intel_encoder
*encoder
=
5172 to_intel_encoder(old_conn_state
->best_encoder
);
5174 if (old_conn_state
->crtc
!= crtc
)
5177 if (encoder
->post_disable
)
5178 encoder
->post_disable(encoder
, old_crtc_state
, old_conn_state
);
5182 static void intel_encoders_post_pll_disable(struct drm_crtc
*crtc
,
5183 struct intel_crtc_state
*old_crtc_state
,
5184 struct drm_atomic_state
*old_state
)
5186 struct drm_connector_state
*old_conn_state
;
5187 struct drm_connector
*conn
;
5190 for_each_old_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5191 struct intel_encoder
*encoder
=
5192 to_intel_encoder(old_conn_state
->best_encoder
);
5194 if (old_conn_state
->crtc
!= crtc
)
5197 if (encoder
->post_pll_disable
)
5198 encoder
->post_pll_disable(encoder
, old_crtc_state
, old_conn_state
);
5202 static void ironlake_crtc_enable(struct intel_crtc_state
*pipe_config
,
5203 struct drm_atomic_state
*old_state
)
5205 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5206 struct drm_device
*dev
= crtc
->dev
;
5207 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5208 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5209 int pipe
= intel_crtc
->pipe
;
5210 struct intel_atomic_state
*old_intel_state
=
5211 to_intel_atomic_state(old_state
);
5213 if (WARN_ON(intel_crtc
->active
))
5217 * Sometimes spurious CPU pipe underruns happen during FDI
5218 * training, at least with VGA+HDMI cloning. Suppress them.
5220 * On ILK we get an occasional spurious CPU pipe underruns
5221 * between eDP port A enable and vdd enable. Also PCH port
5222 * enable seems to result in the occasional CPU pipe underrun.
5224 * Spurious PCH underruns also occur during PCH enabling.
5226 if (intel_crtc
->config
->has_pch_encoder
|| IS_GEN5(dev_priv
))
5227 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5228 if (intel_crtc
->config
->has_pch_encoder
)
5229 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
5231 if (intel_crtc
->config
->has_pch_encoder
)
5232 intel_prepare_shared_dpll(intel_crtc
);
5234 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5235 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5237 intel_set_pipe_timings(intel_crtc
);
5238 intel_set_pipe_src_size(intel_crtc
);
5240 if (intel_crtc
->config
->has_pch_encoder
) {
5241 intel_cpu_transcoder_set_m_n(intel_crtc
,
5242 &intel_crtc
->config
->fdi_m_n
, NULL
);
5245 ironlake_set_pipeconf(crtc
);
5247 intel_crtc
->active
= true;
5249 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5251 if (intel_crtc
->config
->has_pch_encoder
) {
5252 /* Note: FDI PLL enabling _must_ be done before we enable the
5253 * cpu pipes, hence this is separate from all the other fdi/pch
5255 ironlake_fdi_pll_enable(intel_crtc
);
5257 assert_fdi_tx_disabled(dev_priv
, pipe
);
5258 assert_fdi_rx_disabled(dev_priv
, pipe
);
5261 ironlake_pfit_enable(intel_crtc
);
5264 * On ILK+ LUT must be loaded before the pipe is running but with
5267 intel_color_load_luts(&pipe_config
->base
);
5269 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5270 dev_priv
->display
.initial_watermarks(old_intel_state
, intel_crtc
->config
);
5271 intel_enable_pipe(intel_crtc
);
5273 if (intel_crtc
->config
->has_pch_encoder
)
5274 ironlake_pch_enable(pipe_config
);
5276 assert_vblank_disabled(crtc
);
5277 drm_crtc_vblank_on(crtc
);
5279 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5281 if (HAS_PCH_CPT(dev_priv
))
5282 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
5284 /* Must wait for vblank to avoid spurious PCH FIFO underruns */
5285 if (intel_crtc
->config
->has_pch_encoder
)
5286 intel_wait_for_vblank(dev_priv
, pipe
);
5287 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5288 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
5291 /* IPS only exists on ULT machines and is tied to pipe A. */
5292 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
5294 return HAS_IPS(to_i915(crtc
->base
.dev
)) && crtc
->pipe
== PIPE_A
;
5297 static void haswell_crtc_enable(struct intel_crtc_state
*pipe_config
,
5298 struct drm_atomic_state
*old_state
)
5300 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5301 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5302 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5303 int pipe
= intel_crtc
->pipe
, hsw_workaround_pipe
;
5304 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5305 struct intel_atomic_state
*old_intel_state
=
5306 to_intel_atomic_state(old_state
);
5308 if (WARN_ON(intel_crtc
->active
))
5311 if (intel_crtc
->config
->has_pch_encoder
)
5312 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, false);
5314 intel_encoders_pre_pll_enable(crtc
, pipe_config
, old_state
);
5316 if (intel_crtc
->config
->shared_dpll
)
5317 intel_enable_shared_dpll(intel_crtc
);
5319 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5320 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5322 if (!transcoder_is_dsi(cpu_transcoder
))
5323 intel_set_pipe_timings(intel_crtc
);
5325 intel_set_pipe_src_size(intel_crtc
);
5327 if (cpu_transcoder
!= TRANSCODER_EDP
&&
5328 !transcoder_is_dsi(cpu_transcoder
)) {
5329 I915_WRITE(PIPE_MULT(cpu_transcoder
),
5330 intel_crtc
->config
->pixel_multiplier
- 1);
5333 if (intel_crtc
->config
->has_pch_encoder
) {
5334 intel_cpu_transcoder_set_m_n(intel_crtc
,
5335 &intel_crtc
->config
->fdi_m_n
, NULL
);
5338 if (!transcoder_is_dsi(cpu_transcoder
))
5339 haswell_set_pipeconf(crtc
);
5341 haswell_set_pipemisc(crtc
);
5343 intel_color_set_csc(&pipe_config
->base
);
5345 intel_crtc
->active
= true;
5347 if (intel_crtc
->config
->has_pch_encoder
)
5348 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5350 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5352 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5354 if (intel_crtc
->config
->has_pch_encoder
)
5355 dev_priv
->display
.fdi_link_train(intel_crtc
, pipe_config
);
5357 if (!transcoder_is_dsi(cpu_transcoder
))
5358 intel_ddi_enable_pipe_clock(pipe_config
);
5360 if (INTEL_GEN(dev_priv
) >= 9)
5361 skylake_pfit_enable(intel_crtc
);
5363 ironlake_pfit_enable(intel_crtc
);
5366 * On ILK+ LUT must be loaded before the pipe is running but with
5369 intel_color_load_luts(&pipe_config
->base
);
5371 intel_ddi_set_pipe_settings(pipe_config
);
5372 if (!transcoder_is_dsi(cpu_transcoder
))
5373 intel_ddi_enable_transcoder_func(pipe_config
);
5375 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5376 dev_priv
->display
.initial_watermarks(old_intel_state
, pipe_config
);
5378 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5379 if (!transcoder_is_dsi(cpu_transcoder
))
5380 intel_enable_pipe(intel_crtc
);
5382 if (intel_crtc
->config
->has_pch_encoder
)
5383 lpt_pch_enable(pipe_config
);
5385 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DP_MST
))
5386 intel_ddi_set_vc_payload_alloc(pipe_config
, true);
5388 assert_vblank_disabled(crtc
);
5389 drm_crtc_vblank_on(crtc
);
5391 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5393 if (intel_crtc
->config
->has_pch_encoder
) {
5394 intel_wait_for_vblank(dev_priv
, pipe
);
5395 intel_wait_for_vblank(dev_priv
, pipe
);
5396 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5397 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, true);
5400 /* If we change the relative order between pipe/planes enabling, we need
5401 * to change the workaround. */
5402 hsw_workaround_pipe
= pipe_config
->hsw_workaround_pipe
;
5403 if (IS_HASWELL(dev_priv
) && hsw_workaround_pipe
!= INVALID_PIPE
) {
5404 intel_wait_for_vblank(dev_priv
, hsw_workaround_pipe
);
5405 intel_wait_for_vblank(dev_priv
, hsw_workaround_pipe
);
5409 static void ironlake_pfit_disable(struct intel_crtc
*crtc
, bool force
)
5411 struct drm_device
*dev
= crtc
->base
.dev
;
5412 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5413 int pipe
= crtc
->pipe
;
5415 /* To avoid upsetting the power well on haswell only disable the pfit if
5416 * it's in use. The hw state code will make sure we get this right. */
5417 if (force
|| crtc
->config
->pch_pfit
.enabled
) {
5418 I915_WRITE(PF_CTL(pipe
), 0);
5419 I915_WRITE(PF_WIN_POS(pipe
), 0);
5420 I915_WRITE(PF_WIN_SZ(pipe
), 0);
5424 static void ironlake_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5425 struct drm_atomic_state
*old_state
)
5427 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5428 struct drm_device
*dev
= crtc
->dev
;
5429 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5430 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5431 int pipe
= intel_crtc
->pipe
;
5434 * Sometimes spurious CPU pipe underruns happen when the
5435 * pipe is already disabled, but FDI RX/TX is still enabled.
5436 * Happens at least with VGA+HDMI cloning. Suppress them.
5438 if (intel_crtc
->config
->has_pch_encoder
) {
5439 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5440 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
5443 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5445 drm_crtc_vblank_off(crtc
);
5446 assert_vblank_disabled(crtc
);
5448 intel_disable_pipe(intel_crtc
);
5450 ironlake_pfit_disable(intel_crtc
, false);
5452 if (intel_crtc
->config
->has_pch_encoder
)
5453 ironlake_fdi_disable(crtc
);
5455 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5457 if (intel_crtc
->config
->has_pch_encoder
) {
5458 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
5460 if (HAS_PCH_CPT(dev_priv
)) {
5464 /* disable TRANS_DP_CTL */
5465 reg
= TRANS_DP_CTL(pipe
);
5466 temp
= I915_READ(reg
);
5467 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
5468 TRANS_DP_PORT_SEL_MASK
);
5469 temp
|= TRANS_DP_PORT_SEL_NONE
;
5470 I915_WRITE(reg
, temp
);
5472 /* disable DPLL_SEL */
5473 temp
= I915_READ(PCH_DPLL_SEL
);
5474 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
5475 I915_WRITE(PCH_DPLL_SEL
, temp
);
5478 ironlake_fdi_pll_disable(intel_crtc
);
5481 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5482 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
5485 static void haswell_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5486 struct drm_atomic_state
*old_state
)
5488 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5489 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5490 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5491 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5493 if (intel_crtc
->config
->has_pch_encoder
)
5494 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, false);
5496 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5498 drm_crtc_vblank_off(crtc
);
5499 assert_vblank_disabled(crtc
);
5501 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5502 if (!transcoder_is_dsi(cpu_transcoder
))
5503 intel_disable_pipe(intel_crtc
);
5505 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DP_MST
))
5506 intel_ddi_set_vc_payload_alloc(intel_crtc
->config
, false);
5508 if (!transcoder_is_dsi(cpu_transcoder
))
5509 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
5511 if (INTEL_GEN(dev_priv
) >= 9)
5512 skylake_scaler_disable(intel_crtc
);
5514 ironlake_pfit_disable(intel_crtc
, false);
5516 if (!transcoder_is_dsi(cpu_transcoder
))
5517 intel_ddi_disable_pipe_clock(intel_crtc
->config
);
5519 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5521 if (old_crtc_state
->has_pch_encoder
)
5522 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, true);
5525 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
5527 struct drm_device
*dev
= crtc
->base
.dev
;
5528 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5529 struct intel_crtc_state
*pipe_config
= crtc
->config
;
5531 if (!pipe_config
->gmch_pfit
.control
)
5535 * The panel fitter should only be adjusted whilst the pipe is disabled,
5536 * according to register description and PRM.
5538 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
5539 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5541 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
5542 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
5544 /* Border color in case we don't scale up to the full screen. Black by
5545 * default, change to something else for debugging. */
5546 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
5549 enum intel_display_power_domain
intel_port_to_power_domain(enum port port
)
5553 return POWER_DOMAIN_PORT_DDI_A_LANES
;
5555 return POWER_DOMAIN_PORT_DDI_B_LANES
;
5557 return POWER_DOMAIN_PORT_DDI_C_LANES
;
5559 return POWER_DOMAIN_PORT_DDI_D_LANES
;
5561 return POWER_DOMAIN_PORT_DDI_E_LANES
;
5564 return POWER_DOMAIN_PORT_OTHER
;
5568 static u64
get_crtc_power_domains(struct drm_crtc
*crtc
,
5569 struct intel_crtc_state
*crtc_state
)
5571 struct drm_device
*dev
= crtc
->dev
;
5572 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5573 struct drm_encoder
*encoder
;
5574 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5575 enum pipe pipe
= intel_crtc
->pipe
;
5577 enum transcoder transcoder
= crtc_state
->cpu_transcoder
;
5579 if (!crtc_state
->base
.active
)
5582 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
5583 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
5584 if (crtc_state
->pch_pfit
.enabled
||
5585 crtc_state
->pch_pfit
.force_thru
)
5586 mask
|= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
5588 drm_for_each_encoder_mask(encoder
, dev
, crtc_state
->base
.encoder_mask
) {
5589 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5591 mask
|= BIT_ULL(intel_encoder
->power_domain
);
5594 if (HAS_DDI(dev_priv
) && crtc_state
->has_audio
)
5595 mask
|= BIT(POWER_DOMAIN_AUDIO
);
5597 if (crtc_state
->shared_dpll
)
5598 mask
|= BIT_ULL(POWER_DOMAIN_PLLS
);
5604 modeset_get_crtc_power_domains(struct drm_crtc
*crtc
,
5605 struct intel_crtc_state
*crtc_state
)
5607 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5608 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5609 enum intel_display_power_domain domain
;
5610 u64 domains
, new_domains
, old_domains
;
5612 old_domains
= intel_crtc
->enabled_power_domains
;
5613 intel_crtc
->enabled_power_domains
= new_domains
=
5614 get_crtc_power_domains(crtc
, crtc_state
);
5616 domains
= new_domains
& ~old_domains
;
5618 for_each_power_domain(domain
, domains
)
5619 intel_display_power_get(dev_priv
, domain
);
5621 return old_domains
& ~new_domains
;
5624 static void modeset_put_power_domains(struct drm_i915_private
*dev_priv
,
5627 enum intel_display_power_domain domain
;
5629 for_each_power_domain(domain
, domains
)
5630 intel_display_power_put(dev_priv
, domain
);
5633 static void valleyview_crtc_enable(struct intel_crtc_state
*pipe_config
,
5634 struct drm_atomic_state
*old_state
)
5636 struct intel_atomic_state
*old_intel_state
=
5637 to_intel_atomic_state(old_state
);
5638 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5639 struct drm_device
*dev
= crtc
->dev
;
5640 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5641 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5642 int pipe
= intel_crtc
->pipe
;
5644 if (WARN_ON(intel_crtc
->active
))
5647 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5648 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5650 intel_set_pipe_timings(intel_crtc
);
5651 intel_set_pipe_src_size(intel_crtc
);
5653 if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_B
) {
5654 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5656 I915_WRITE(CHV_BLEND(pipe
), CHV_BLEND_LEGACY
);
5657 I915_WRITE(CHV_CANVAS(pipe
), 0);
5660 i9xx_set_pipeconf(intel_crtc
);
5662 intel_crtc
->active
= true;
5664 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5666 intel_encoders_pre_pll_enable(crtc
, pipe_config
, old_state
);
5668 if (IS_CHERRYVIEW(dev_priv
)) {
5669 chv_prepare_pll(intel_crtc
, intel_crtc
->config
);
5670 chv_enable_pll(intel_crtc
, intel_crtc
->config
);
5672 vlv_prepare_pll(intel_crtc
, intel_crtc
->config
);
5673 vlv_enable_pll(intel_crtc
, intel_crtc
->config
);
5676 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5678 i9xx_pfit_enable(intel_crtc
);
5680 intel_color_load_luts(&pipe_config
->base
);
5682 dev_priv
->display
.initial_watermarks(old_intel_state
,
5684 intel_enable_pipe(intel_crtc
);
5686 assert_vblank_disabled(crtc
);
5687 drm_crtc_vblank_on(crtc
);
5689 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5692 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
5694 struct drm_device
*dev
= crtc
->base
.dev
;
5695 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5697 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp0
);
5698 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp1
);
5701 static void i9xx_crtc_enable(struct intel_crtc_state
*pipe_config
,
5702 struct drm_atomic_state
*old_state
)
5704 struct intel_atomic_state
*old_intel_state
=
5705 to_intel_atomic_state(old_state
);
5706 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5707 struct drm_device
*dev
= crtc
->dev
;
5708 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5709 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5710 enum pipe pipe
= intel_crtc
->pipe
;
5712 if (WARN_ON(intel_crtc
->active
))
5715 i9xx_set_pll_dividers(intel_crtc
);
5717 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5718 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5720 intel_set_pipe_timings(intel_crtc
);
5721 intel_set_pipe_src_size(intel_crtc
);
5723 i9xx_set_pipeconf(intel_crtc
);
5725 intel_crtc
->active
= true;
5727 if (!IS_GEN2(dev_priv
))
5728 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5730 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5732 i9xx_enable_pll(intel_crtc
);
5734 i9xx_pfit_enable(intel_crtc
);
5736 intel_color_load_luts(&pipe_config
->base
);
5738 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5739 dev_priv
->display
.initial_watermarks(old_intel_state
,
5740 intel_crtc
->config
);
5742 intel_update_watermarks(intel_crtc
);
5743 intel_enable_pipe(intel_crtc
);
5745 assert_vblank_disabled(crtc
);
5746 drm_crtc_vblank_on(crtc
);
5748 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5751 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
5753 struct drm_device
*dev
= crtc
->base
.dev
;
5754 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5756 if (!crtc
->config
->gmch_pfit
.control
)
5759 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5761 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
5762 I915_READ(PFIT_CONTROL
));
5763 I915_WRITE(PFIT_CONTROL
, 0);
5766 static void i9xx_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5767 struct drm_atomic_state
*old_state
)
5769 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5770 struct drm_device
*dev
= crtc
->dev
;
5771 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5772 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5773 int pipe
= intel_crtc
->pipe
;
5776 * On gen2 planes are double buffered but the pipe isn't, so we must
5777 * wait for planes to fully turn off before disabling the pipe.
5779 if (IS_GEN2(dev_priv
))
5780 intel_wait_for_vblank(dev_priv
, pipe
);
5782 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5784 drm_crtc_vblank_off(crtc
);
5785 assert_vblank_disabled(crtc
);
5787 intel_disable_pipe(intel_crtc
);
5789 i9xx_pfit_disable(intel_crtc
);
5791 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5793 if (!intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DSI
)) {
5794 if (IS_CHERRYVIEW(dev_priv
))
5795 chv_disable_pll(dev_priv
, pipe
);
5796 else if (IS_VALLEYVIEW(dev_priv
))
5797 vlv_disable_pll(dev_priv
, pipe
);
5799 i9xx_disable_pll(intel_crtc
);
5802 intel_encoders_post_pll_disable(crtc
, old_crtc_state
, old_state
);
5804 if (!IS_GEN2(dev_priv
))
5805 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5807 if (!dev_priv
->display
.initial_watermarks
)
5808 intel_update_watermarks(intel_crtc
);
5810 /* clock the pipe down to 640x480@60 to potentially save power */
5811 if (IS_I830(dev_priv
))
5812 i830_enable_pipe(dev_priv
, pipe
);
5815 static void intel_crtc_disable_noatomic(struct drm_crtc
*crtc
,
5816 struct drm_modeset_acquire_ctx
*ctx
)
5818 struct intel_encoder
*encoder
;
5819 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5820 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5821 enum intel_display_power_domain domain
;
5823 struct drm_atomic_state
*state
;
5824 struct intel_crtc_state
*crtc_state
;
5827 if (!intel_crtc
->active
)
5830 if (crtc
->primary
->state
->visible
) {
5831 WARN_ON(intel_crtc
->flip_work
);
5833 intel_pre_disable_primary_noatomic(crtc
);
5835 intel_crtc_disable_planes(crtc
, 1 << drm_plane_index(crtc
->primary
));
5836 crtc
->primary
->state
->visible
= false;
5839 state
= drm_atomic_state_alloc(crtc
->dev
);
5841 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
5842 crtc
->base
.id
, crtc
->name
);
5846 state
->acquire_ctx
= ctx
;
5848 /* Everything's already locked, -EDEADLK can't happen. */
5849 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
5850 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
5852 WARN_ON(IS_ERR(crtc_state
) || ret
);
5854 dev_priv
->display
.crtc_disable(crtc_state
, state
);
5856 drm_atomic_state_put(state
);
5858 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
5859 crtc
->base
.id
, crtc
->name
);
5861 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->state
, NULL
) < 0);
5862 crtc
->state
->active
= false;
5863 intel_crtc
->active
= false;
5864 crtc
->enabled
= false;
5865 crtc
->state
->connector_mask
= 0;
5866 crtc
->state
->encoder_mask
= 0;
5868 for_each_encoder_on_crtc(crtc
->dev
, crtc
, encoder
)
5869 encoder
->base
.crtc
= NULL
;
5871 intel_fbc_disable(intel_crtc
);
5872 intel_update_watermarks(intel_crtc
);
5873 intel_disable_shared_dpll(intel_crtc
);
5875 domains
= intel_crtc
->enabled_power_domains
;
5876 for_each_power_domain(domain
, domains
)
5877 intel_display_power_put(dev_priv
, domain
);
5878 intel_crtc
->enabled_power_domains
= 0;
5880 dev_priv
->active_crtcs
&= ~(1 << intel_crtc
->pipe
);
5881 dev_priv
->min_pixclk
[intel_crtc
->pipe
] = 0;
5885 * turn all crtc's off, but do not adjust state
5886 * This has to be paired with a call to intel_modeset_setup_hw_state.
5888 int intel_display_suspend(struct drm_device
*dev
)
5890 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5891 struct drm_atomic_state
*state
;
5894 state
= drm_atomic_helper_suspend(dev
);
5895 ret
= PTR_ERR_OR_ZERO(state
);
5897 DRM_ERROR("Suspending crtc's failed with %i\n", ret
);
5899 dev_priv
->modeset_restore_state
= state
;
5903 void intel_encoder_destroy(struct drm_encoder
*encoder
)
5905 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5907 drm_encoder_cleanup(encoder
);
5908 kfree(intel_encoder
);
5911 /* Cross check the actual hw state with our own modeset state tracking (and it's
5912 * internal consistency). */
5913 static void intel_connector_verify_state(struct drm_crtc_state
*crtc_state
,
5914 struct drm_connector_state
*conn_state
)
5916 struct intel_connector
*connector
= to_intel_connector(conn_state
->connector
);
5918 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
5919 connector
->base
.base
.id
,
5920 connector
->base
.name
);
5922 if (connector
->get_hw_state(connector
)) {
5923 struct intel_encoder
*encoder
= connector
->encoder
;
5925 I915_STATE_WARN(!crtc_state
,
5926 "connector enabled without attached crtc\n");
5931 I915_STATE_WARN(!crtc_state
->active
,
5932 "connector is active, but attached crtc isn't\n");
5934 if (!encoder
|| encoder
->type
== INTEL_OUTPUT_DP_MST
)
5937 I915_STATE_WARN(conn_state
->best_encoder
!= &encoder
->base
,
5938 "atomic encoder doesn't match attached encoder\n");
5940 I915_STATE_WARN(conn_state
->crtc
!= encoder
->base
.crtc
,
5941 "attached encoder crtc differs from connector crtc\n");
5943 I915_STATE_WARN(crtc_state
&& crtc_state
->active
,
5944 "attached crtc is active, but connector isn't\n");
5945 I915_STATE_WARN(!crtc_state
&& conn_state
->best_encoder
,
5946 "best encoder set without crtc!\n");
5950 int intel_connector_init(struct intel_connector
*connector
)
5952 struct intel_digital_connector_state
*conn_state
;
5955 * Allocate enough memory to hold intel_digital_connector_state,
5956 * This might be a few bytes too many, but for connectors that don't
5957 * need it we'll free the state and allocate a smaller one on the first
5958 * succesful commit anyway.
5960 conn_state
= kzalloc(sizeof(*conn_state
), GFP_KERNEL
);
5964 __drm_atomic_helper_connector_reset(&connector
->base
,
5970 struct intel_connector
*intel_connector_alloc(void)
5972 struct intel_connector
*connector
;
5974 connector
= kzalloc(sizeof *connector
, GFP_KERNEL
);
5978 if (intel_connector_init(connector
) < 0) {
5986 /* Simple connector->get_hw_state implementation for encoders that support only
5987 * one connector and no cloning and hence the encoder state determines the state
5988 * of the connector. */
5989 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
5992 struct intel_encoder
*encoder
= connector
->encoder
;
5994 return encoder
->get_hw_state(encoder
, &pipe
);
5997 static int pipe_required_fdi_lanes(struct intel_crtc_state
*crtc_state
)
5999 if (crtc_state
->base
.enable
&& crtc_state
->has_pch_encoder
)
6000 return crtc_state
->fdi_lanes
;
6005 static int ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
6006 struct intel_crtc_state
*pipe_config
)
6008 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6009 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
6010 struct intel_crtc
*other_crtc
;
6011 struct intel_crtc_state
*other_crtc_state
;
6013 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6014 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6015 if (pipe_config
->fdi_lanes
> 4) {
6016 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6017 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6021 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
6022 if (pipe_config
->fdi_lanes
> 2) {
6023 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6024 pipe_config
->fdi_lanes
);
6031 if (INTEL_INFO(dev_priv
)->num_pipes
== 2)
6034 /* Ivybridge 3 pipe is really complicated */
6039 if (pipe_config
->fdi_lanes
<= 2)
6042 other_crtc
= intel_get_crtc_for_pipe(dev_priv
, PIPE_C
);
6044 intel_atomic_get_crtc_state(state
, other_crtc
);
6045 if (IS_ERR(other_crtc_state
))
6046 return PTR_ERR(other_crtc_state
);
6048 if (pipe_required_fdi_lanes(other_crtc_state
) > 0) {
6049 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6050 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6055 if (pipe_config
->fdi_lanes
> 2) {
6056 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6057 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6061 other_crtc
= intel_get_crtc_for_pipe(dev_priv
, PIPE_B
);
6063 intel_atomic_get_crtc_state(state
, other_crtc
);
6064 if (IS_ERR(other_crtc_state
))
6065 return PTR_ERR(other_crtc_state
);
6067 if (pipe_required_fdi_lanes(other_crtc_state
) > 2) {
6068 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6078 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
6079 struct intel_crtc_state
*pipe_config
)
6081 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6082 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6083 int lane
, link_bw
, fdi_dotclock
, ret
;
6084 bool needs_recompute
= false;
6087 /* FDI is a binary signal running at ~2.7GHz, encoding
6088 * each output octet as 10 bits. The actual frequency
6089 * is stored as a divider into a 100MHz clock, and the
6090 * mode pixel clock is stored in units of 1KHz.
6091 * Hence the bw of each lane in terms of the mode signal
6094 link_bw
= intel_fdi_link_freq(to_i915(dev
), pipe_config
);
6096 fdi_dotclock
= adjusted_mode
->crtc_clock
;
6098 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
6099 pipe_config
->pipe_bpp
);
6101 pipe_config
->fdi_lanes
= lane
;
6103 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
6104 link_bw
, &pipe_config
->fdi_m_n
, false);
6106 ret
= ironlake_check_fdi_lanes(dev
, intel_crtc
->pipe
, pipe_config
);
6107 if (ret
== -EINVAL
&& pipe_config
->pipe_bpp
> 6*3) {
6108 pipe_config
->pipe_bpp
-= 2*3;
6109 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6110 pipe_config
->pipe_bpp
);
6111 needs_recompute
= true;
6112 pipe_config
->bw_constrained
= true;
6117 if (needs_recompute
)
6123 static bool pipe_config_supports_ips(struct drm_i915_private
*dev_priv
,
6124 struct intel_crtc_state
*pipe_config
)
6126 if (pipe_config
->pipe_bpp
> 24)
6129 /* HSW can handle pixel rate up to cdclk? */
6130 if (IS_HASWELL(dev_priv
))
6134 * We compare against max which means we must take
6135 * the increased cdclk requirement into account when
6136 * calculating the new cdclk.
6138 * Should measure whether using a lower cdclk w/o IPS
6140 return pipe_config
->pixel_rate
<=
6141 dev_priv
->max_cdclk_freq
* 95 / 100;
6144 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
6145 struct intel_crtc_state
*pipe_config
)
6147 struct drm_device
*dev
= crtc
->base
.dev
;
6148 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6150 pipe_config
->ips_enabled
= i915
.enable_ips
&&
6151 hsw_crtc_supports_ips(crtc
) &&
6152 pipe_config_supports_ips(dev_priv
, pipe_config
);
6155 static bool intel_crtc_supports_double_wide(const struct intel_crtc
*crtc
)
6157 const struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6159 /* GDG double wide on either pipe, otherwise pipe A only */
6160 return INTEL_INFO(dev_priv
)->gen
< 4 &&
6161 (crtc
->pipe
== PIPE_A
|| IS_I915G(dev_priv
));
6164 static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state
*pipe_config
)
6166 uint32_t pixel_rate
;
6168 pixel_rate
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
6171 * We only use IF-ID interlacing. If we ever use
6172 * PF-ID we'll need to adjust the pixel_rate here.
6175 if (pipe_config
->pch_pfit
.enabled
) {
6176 uint64_t pipe_w
, pipe_h
, pfit_w
, pfit_h
;
6177 uint32_t pfit_size
= pipe_config
->pch_pfit
.size
;
6179 pipe_w
= pipe_config
->pipe_src_w
;
6180 pipe_h
= pipe_config
->pipe_src_h
;
6182 pfit_w
= (pfit_size
>> 16) & 0xFFFF;
6183 pfit_h
= pfit_size
& 0xFFFF;
6184 if (pipe_w
< pfit_w
)
6186 if (pipe_h
< pfit_h
)
6189 if (WARN_ON(!pfit_w
|| !pfit_h
))
6192 pixel_rate
= div_u64((uint64_t) pixel_rate
* pipe_w
* pipe_h
,
6199 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state
*crtc_state
)
6201 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->base
.crtc
->dev
);
6203 if (HAS_GMCH_DISPLAY(dev_priv
))
6204 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6205 crtc_state
->pixel_rate
=
6206 crtc_state
->base
.adjusted_mode
.crtc_clock
;
6208 crtc_state
->pixel_rate
=
6209 ilk_pipe_pixel_rate(crtc_state
);
6212 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
6213 struct intel_crtc_state
*pipe_config
)
6215 struct drm_device
*dev
= crtc
->base
.dev
;
6216 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6217 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6218 int clock_limit
= dev_priv
->max_dotclk_freq
;
6220 if (INTEL_GEN(dev_priv
) < 4) {
6221 clock_limit
= dev_priv
->max_cdclk_freq
* 9 / 10;
6224 * Enable double wide mode when the dot clock
6225 * is > 90% of the (display) core speed.
6227 if (intel_crtc_supports_double_wide(crtc
) &&
6228 adjusted_mode
->crtc_clock
> clock_limit
) {
6229 clock_limit
= dev_priv
->max_dotclk_freq
;
6230 pipe_config
->double_wide
= true;
6234 if (adjusted_mode
->crtc_clock
> clock_limit
) {
6235 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6236 adjusted_mode
->crtc_clock
, clock_limit
,
6237 yesno(pipe_config
->double_wide
));
6242 * Pipe horizontal size must be even in:
6244 * - LVDS dual channel mode
6245 * - Double wide pipe
6247 if ((intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_LVDS
) &&
6248 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
6249 pipe_config
->pipe_src_w
&= ~1;
6251 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6252 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6254 if ((INTEL_GEN(dev_priv
) > 4 || IS_G4X(dev_priv
)) &&
6255 adjusted_mode
->crtc_hsync_start
== adjusted_mode
->crtc_hdisplay
)
6258 intel_crtc_compute_pixel_rate(pipe_config
);
6260 if (HAS_IPS(dev_priv
))
6261 hsw_compute_ips_config(crtc
, pipe_config
);
6263 if (pipe_config
->has_pch_encoder
)
6264 return ironlake_fdi_compute_config(crtc
, pipe_config
);
6270 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
6272 while (*num
> DATA_LINK_M_N_MASK
||
6273 *den
> DATA_LINK_M_N_MASK
) {
6279 static void compute_m_n(unsigned int m
, unsigned int n
,
6280 uint32_t *ret_m
, uint32_t *ret_n
,
6284 * Reduce M/N as much as possible without loss in precision. Several DP
6285 * dongles in particular seem to be fussy about too large *link* M/N
6286 * values. The passed in values are more likely to have the least
6287 * significant bits zero than M after rounding below, so do this first.
6290 while ((m
& 1) == 0 && (n
& 1) == 0) {
6296 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
6297 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
6298 intel_reduce_m_n_ratio(ret_m
, ret_n
);
6302 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
6303 int pixel_clock
, int link_clock
,
6304 struct intel_link_m_n
*m_n
,
6309 compute_m_n(bits_per_pixel
* pixel_clock
,
6310 link_clock
* nlanes
* 8,
6311 &m_n
->gmch_m
, &m_n
->gmch_n
,
6314 compute_m_n(pixel_clock
, link_clock
,
6315 &m_n
->link_m
, &m_n
->link_n
,
6319 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
6321 if (i915
.panel_use_ssc
>= 0)
6322 return i915
.panel_use_ssc
!= 0;
6323 return dev_priv
->vbt
.lvds_use_ssc
6324 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
6327 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
6329 return (1 << dpll
->n
) << 16 | dpll
->m2
;
6332 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
6334 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
6337 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
6338 struct intel_crtc_state
*crtc_state
,
6339 struct dpll
*reduced_clock
)
6341 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6344 if (IS_PINEVIEW(dev_priv
)) {
6345 fp
= pnv_dpll_compute_fp(&crtc_state
->dpll
);
6347 fp2
= pnv_dpll_compute_fp(reduced_clock
);
6349 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
6351 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
6354 crtc_state
->dpll_hw_state
.fp0
= fp
;
6356 crtc
->lowfreq_avail
= false;
6357 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6359 crtc_state
->dpll_hw_state
.fp1
= fp2
;
6360 crtc
->lowfreq_avail
= true;
6362 crtc_state
->dpll_hw_state
.fp1
= fp
;
6366 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
6372 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6373 * and set it to a reasonable value instead.
6375 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6376 reg_val
&= 0xffffff00;
6377 reg_val
|= 0x00000030;
6378 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6380 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6381 reg_val
&= 0x00ffffff;
6382 reg_val
|= 0x8c000000;
6383 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6385 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6386 reg_val
&= 0xffffff00;
6387 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6389 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6390 reg_val
&= 0x00ffffff;
6391 reg_val
|= 0xb0000000;
6392 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6395 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
6396 struct intel_link_m_n
*m_n
)
6398 struct drm_device
*dev
= crtc
->base
.dev
;
6399 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6400 int pipe
= crtc
->pipe
;
6402 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6403 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
6404 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
6405 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
6408 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
6409 struct intel_link_m_n
*m_n
,
6410 struct intel_link_m_n
*m2_n2
)
6412 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6413 int pipe
= crtc
->pipe
;
6414 enum transcoder transcoder
= crtc
->config
->cpu_transcoder
;
6416 if (INTEL_GEN(dev_priv
) >= 5) {
6417 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6418 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
6419 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
6420 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
6421 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
6422 * for gen < 8) and if DRRS is supported (to make sure the
6423 * registers are not unnecessarily accessed).
6425 if (m2_n2
&& (IS_CHERRYVIEW(dev_priv
) ||
6426 INTEL_GEN(dev_priv
) < 8) && crtc
->config
->has_drrs
) {
6427 I915_WRITE(PIPE_DATA_M2(transcoder
),
6428 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
6429 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
6430 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
6431 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
6434 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6435 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
6436 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
6437 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
6441 void intel_dp_set_m_n(struct intel_crtc
*crtc
, enum link_m_n_set m_n
)
6443 struct intel_link_m_n
*dp_m_n
, *dp_m2_n2
= NULL
;
6446 dp_m_n
= &crtc
->config
->dp_m_n
;
6447 dp_m2_n2
= &crtc
->config
->dp_m2_n2
;
6448 } else if (m_n
== M2_N2
) {
6451 * M2_N2 registers are not supported. Hence m2_n2 divider value
6452 * needs to be programmed into M1_N1.
6454 dp_m_n
= &crtc
->config
->dp_m2_n2
;
6456 DRM_ERROR("Unsupported divider value\n");
6460 if (crtc
->config
->has_pch_encoder
)
6461 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
->dp_m_n
);
6463 intel_cpu_transcoder_set_m_n(crtc
, dp_m_n
, dp_m2_n2
);
6466 static void vlv_compute_dpll(struct intel_crtc
*crtc
,
6467 struct intel_crtc_state
*pipe_config
)
6469 pipe_config
->dpll_hw_state
.dpll
= DPLL_INTEGRATED_REF_CLK_VLV
|
6470 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
6471 if (crtc
->pipe
!= PIPE_A
)
6472 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
6474 /* DPLL not used with DSI, but still need the rest set up */
6475 if (!intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_DSI
))
6476 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
|
6477 DPLL_EXT_BUFFER_ENABLE_VLV
;
6479 pipe_config
->dpll_hw_state
.dpll_md
=
6480 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6483 static void chv_compute_dpll(struct intel_crtc
*crtc
,
6484 struct intel_crtc_state
*pipe_config
)
6486 pipe_config
->dpll_hw_state
.dpll
= DPLL_SSC_REF_CLK_CHV
|
6487 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
6488 if (crtc
->pipe
!= PIPE_A
)
6489 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
6491 /* DPLL not used with DSI, but still need the rest set up */
6492 if (!intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_DSI
))
6493 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
;
6495 pipe_config
->dpll_hw_state
.dpll_md
=
6496 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6499 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
6500 const struct intel_crtc_state
*pipe_config
)
6502 struct drm_device
*dev
= crtc
->base
.dev
;
6503 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6504 enum pipe pipe
= crtc
->pipe
;
6506 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
6507 u32 coreclk
, reg_val
;
6510 I915_WRITE(DPLL(pipe
),
6511 pipe_config
->dpll_hw_state
.dpll
&
6512 ~(DPLL_VCO_ENABLE
| DPLL_EXT_BUFFER_ENABLE_VLV
));
6514 /* No need to actually set up the DPLL with DSI */
6515 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
6518 mutex_lock(&dev_priv
->sb_lock
);
6520 bestn
= pipe_config
->dpll
.n
;
6521 bestm1
= pipe_config
->dpll
.m1
;
6522 bestm2
= pipe_config
->dpll
.m2
;
6523 bestp1
= pipe_config
->dpll
.p1
;
6524 bestp2
= pipe_config
->dpll
.p2
;
6526 /* See eDP HDMI DPIO driver vbios notes doc */
6528 /* PLL B needs special handling */
6530 vlv_pllb_recal_opamp(dev_priv
, pipe
);
6532 /* Set up Tx target for periodic Rcomp update */
6533 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
6535 /* Disable target IRef on PLL */
6536 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
6537 reg_val
&= 0x00ffffff;
6538 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
6540 /* Disable fast lock */
6541 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
6543 /* Set idtafcrecal before PLL is enabled */
6544 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
6545 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
6546 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
6547 mdiv
|= (1 << DPIO_K_SHIFT
);
6550 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6551 * but we don't support that).
6552 * Note: don't use the DAC post divider as it seems unstable.
6554 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
6555 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
6557 mdiv
|= DPIO_ENABLE_CALIBRATION
;
6558 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
6560 /* Set HBR and RBR LPF coefficients */
6561 if (pipe_config
->port_clock
== 162000 ||
6562 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_ANALOG
) ||
6563 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_HDMI
))
6564 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
6567 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
6570 if (intel_crtc_has_dp_encoder(pipe_config
)) {
6571 /* Use SSC source */
6573 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6576 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6578 } else { /* HDMI or VGA */
6579 /* Use bend source */
6581 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6584 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6588 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
6589 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
6590 if (intel_crtc_has_dp_encoder(crtc
->config
))
6591 coreclk
|= 0x01000000;
6592 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
6594 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
6595 mutex_unlock(&dev_priv
->sb_lock
);
6598 static void chv_prepare_pll(struct intel_crtc
*crtc
,
6599 const struct intel_crtc_state
*pipe_config
)
6601 struct drm_device
*dev
= crtc
->base
.dev
;
6602 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6603 enum pipe pipe
= crtc
->pipe
;
6604 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
6605 u32 loopfilter
, tribuf_calcntr
;
6606 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
6610 /* Enable Refclk and SSC */
6611 I915_WRITE(DPLL(pipe
),
6612 pipe_config
->dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
6614 /* No need to actually set up the DPLL with DSI */
6615 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
6618 bestn
= pipe_config
->dpll
.n
;
6619 bestm2_frac
= pipe_config
->dpll
.m2
& 0x3fffff;
6620 bestm1
= pipe_config
->dpll
.m1
;
6621 bestm2
= pipe_config
->dpll
.m2
>> 22;
6622 bestp1
= pipe_config
->dpll
.p1
;
6623 bestp2
= pipe_config
->dpll
.p2
;
6624 vco
= pipe_config
->dpll
.vco
;
6628 mutex_lock(&dev_priv
->sb_lock
);
6630 /* p1 and p2 divider */
6631 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
6632 5 << DPIO_CHV_S1_DIV_SHIFT
|
6633 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
6634 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
6635 1 << DPIO_CHV_K_DIV_SHIFT
);
6637 /* Feedback post-divider - m2 */
6638 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
6640 /* Feedback refclk divider - n and m1 */
6641 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
6642 DPIO_CHV_M1_DIV_BY_2
|
6643 1 << DPIO_CHV_N_DIV_SHIFT
);
6645 /* M2 fraction division */
6646 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
6648 /* M2 fraction division enable */
6649 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
6650 dpio_val
&= ~(DPIO_CHV_FEEDFWD_GAIN_MASK
| DPIO_CHV_FRAC_DIV_EN
);
6651 dpio_val
|= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
);
6653 dpio_val
|= DPIO_CHV_FRAC_DIV_EN
;
6654 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
), dpio_val
);
6656 /* Program digital lock detect threshold */
6657 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW9(port
));
6658 dpio_val
&= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK
|
6659 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
);
6660 dpio_val
|= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT
);
6662 dpio_val
|= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
;
6663 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW9(port
), dpio_val
);
6666 if (vco
== 5400000) {
6667 loopfilter
|= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT
);
6668 loopfilter
|= (0x8 << DPIO_CHV_INT_COEFF_SHIFT
);
6669 loopfilter
|= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6670 tribuf_calcntr
= 0x9;
6671 } else if (vco
<= 6200000) {
6672 loopfilter
|= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT
);
6673 loopfilter
|= (0xB << DPIO_CHV_INT_COEFF_SHIFT
);
6674 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6675 tribuf_calcntr
= 0x9;
6676 } else if (vco
<= 6480000) {
6677 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
6678 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
6679 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6680 tribuf_calcntr
= 0x8;
6682 /* Not supported. Apply the same limits as in the max case */
6683 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
6684 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
6685 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6688 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
6690 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW8(port
));
6691 dpio_val
&= ~DPIO_CHV_TDC_TARGET_CNT_MASK
;
6692 dpio_val
|= (tribuf_calcntr
<< DPIO_CHV_TDC_TARGET_CNT_SHIFT
);
6693 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW8(port
), dpio_val
);
6696 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
6697 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
6700 mutex_unlock(&dev_priv
->sb_lock
);
6704 * vlv_force_pll_on - forcibly enable just the PLL
6705 * @dev_priv: i915 private structure
6706 * @pipe: pipe PLL to enable
6707 * @dpll: PLL configuration
6709 * Enable the PLL for @pipe using the supplied @dpll config. To be used
6710 * in cases where we need the PLL enabled even when @pipe is not going to
6713 int vlv_force_pll_on(struct drm_i915_private
*dev_priv
, enum pipe pipe
,
6714 const struct dpll
*dpll
)
6716 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
6717 struct intel_crtc_state
*pipe_config
;
6719 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
6723 pipe_config
->base
.crtc
= &crtc
->base
;
6724 pipe_config
->pixel_multiplier
= 1;
6725 pipe_config
->dpll
= *dpll
;
6727 if (IS_CHERRYVIEW(dev_priv
)) {
6728 chv_compute_dpll(crtc
, pipe_config
);
6729 chv_prepare_pll(crtc
, pipe_config
);
6730 chv_enable_pll(crtc
, pipe_config
);
6732 vlv_compute_dpll(crtc
, pipe_config
);
6733 vlv_prepare_pll(crtc
, pipe_config
);
6734 vlv_enable_pll(crtc
, pipe_config
);
6743 * vlv_force_pll_off - forcibly disable just the PLL
6744 * @dev_priv: i915 private structure
6745 * @pipe: pipe PLL to disable
6747 * Disable the PLL for @pipe. To be used in cases where we need
6748 * the PLL enabled even when @pipe is not going to be enabled.
6750 void vlv_force_pll_off(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
6752 if (IS_CHERRYVIEW(dev_priv
))
6753 chv_disable_pll(dev_priv
, pipe
);
6755 vlv_disable_pll(dev_priv
, pipe
);
6758 static void i9xx_compute_dpll(struct intel_crtc
*crtc
,
6759 struct intel_crtc_state
*crtc_state
,
6760 struct dpll
*reduced_clock
)
6762 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6764 struct dpll
*clock
= &crtc_state
->dpll
;
6766 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
6768 dpll
= DPLL_VGA_MODE_DIS
;
6770 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
))
6771 dpll
|= DPLLB_MODE_LVDS
;
6773 dpll
|= DPLLB_MODE_DAC_SERIAL
;
6775 if (IS_I945G(dev_priv
) || IS_I945GM(dev_priv
) ||
6776 IS_G33(dev_priv
) || IS_PINEVIEW(dev_priv
)) {
6777 dpll
|= (crtc_state
->pixel_multiplier
- 1)
6778 << SDVO_MULTIPLIER_SHIFT_HIRES
;
6781 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
6782 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
6783 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6785 if (intel_crtc_has_dp_encoder(crtc_state
))
6786 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6788 /* compute bitmask from p1 value */
6789 if (IS_PINEVIEW(dev_priv
))
6790 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
6792 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6793 if (IS_G4X(dev_priv
) && reduced_clock
)
6794 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
6796 switch (clock
->p2
) {
6798 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
6801 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
6804 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
6807 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
6810 if (INTEL_GEN(dev_priv
) >= 4)
6811 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
6813 if (crtc_state
->sdvo_tv_clock
)
6814 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
6815 else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6816 intel_panel_use_ssc(dev_priv
))
6817 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
6819 dpll
|= PLL_REF_INPUT_DREFCLK
;
6821 dpll
|= DPLL_VCO_ENABLE
;
6822 crtc_state
->dpll_hw_state
.dpll
= dpll
;
6824 if (INTEL_GEN(dev_priv
) >= 4) {
6825 u32 dpll_md
= (crtc_state
->pixel_multiplier
- 1)
6826 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6827 crtc_state
->dpll_hw_state
.dpll_md
= dpll_md
;
6831 static void i8xx_compute_dpll(struct intel_crtc
*crtc
,
6832 struct intel_crtc_state
*crtc_state
,
6833 struct dpll
*reduced_clock
)
6835 struct drm_device
*dev
= crtc
->base
.dev
;
6836 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6838 struct dpll
*clock
= &crtc_state
->dpll
;
6840 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
6842 dpll
= DPLL_VGA_MODE_DIS
;
6844 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
6845 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6848 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
6850 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6852 dpll
|= PLL_P2_DIVIDE_BY_4
;
6855 if (!IS_I830(dev_priv
) &&
6856 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DVO
))
6857 dpll
|= DPLL_DVO_2X_MODE
;
6859 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6860 intel_panel_use_ssc(dev_priv
))
6861 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
6863 dpll
|= PLL_REF_INPUT_DREFCLK
;
6865 dpll
|= DPLL_VCO_ENABLE
;
6866 crtc_state
->dpll_hw_state
.dpll
= dpll
;
6869 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
6871 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
6872 enum pipe pipe
= intel_crtc
->pipe
;
6873 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
6874 const struct drm_display_mode
*adjusted_mode
= &intel_crtc
->config
->base
.adjusted_mode
;
6875 uint32_t crtc_vtotal
, crtc_vblank_end
;
6878 /* We need to be careful not to changed the adjusted mode, for otherwise
6879 * the hw state checker will get angry at the mismatch. */
6880 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
6881 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
6883 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
6884 /* the chip adds 2 halflines automatically */
6886 crtc_vblank_end
-= 1;
6888 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
6889 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
6891 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
6892 adjusted_mode
->crtc_htotal
/ 2;
6894 vsyncshift
+= adjusted_mode
->crtc_htotal
;
6897 if (INTEL_GEN(dev_priv
) > 3)
6898 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
6900 I915_WRITE(HTOTAL(cpu_transcoder
),
6901 (adjusted_mode
->crtc_hdisplay
- 1) |
6902 ((adjusted_mode
->crtc_htotal
- 1) << 16));
6903 I915_WRITE(HBLANK(cpu_transcoder
),
6904 (adjusted_mode
->crtc_hblank_start
- 1) |
6905 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
6906 I915_WRITE(HSYNC(cpu_transcoder
),
6907 (adjusted_mode
->crtc_hsync_start
- 1) |
6908 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
6910 I915_WRITE(VTOTAL(cpu_transcoder
),
6911 (adjusted_mode
->crtc_vdisplay
- 1) |
6912 ((crtc_vtotal
- 1) << 16));
6913 I915_WRITE(VBLANK(cpu_transcoder
),
6914 (adjusted_mode
->crtc_vblank_start
- 1) |
6915 ((crtc_vblank_end
- 1) << 16));
6916 I915_WRITE(VSYNC(cpu_transcoder
),
6917 (adjusted_mode
->crtc_vsync_start
- 1) |
6918 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
6920 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
6921 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
6922 * documented on the DDI_FUNC_CTL register description, EDP Input Select
6924 if (IS_HASWELL(dev_priv
) && cpu_transcoder
== TRANSCODER_EDP
&&
6925 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
6926 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
6930 static void intel_set_pipe_src_size(struct intel_crtc
*intel_crtc
)
6932 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6933 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6934 enum pipe pipe
= intel_crtc
->pipe
;
6936 /* pipesrc controls the size that is scaled from, which should
6937 * always be the user's requested size.
6939 I915_WRITE(PIPESRC(pipe
),
6940 ((intel_crtc
->config
->pipe_src_w
- 1) << 16) |
6941 (intel_crtc
->config
->pipe_src_h
- 1));
6944 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
6945 struct intel_crtc_state
*pipe_config
)
6947 struct drm_device
*dev
= crtc
->base
.dev
;
6948 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6949 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
6952 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
6953 pipe_config
->base
.adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
6954 pipe_config
->base
.adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
6955 tmp
= I915_READ(HBLANK(cpu_transcoder
));
6956 pipe_config
->base
.adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
6957 pipe_config
->base
.adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
6958 tmp
= I915_READ(HSYNC(cpu_transcoder
));
6959 pipe_config
->base
.adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
6960 pipe_config
->base
.adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
6962 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
6963 pipe_config
->base
.adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
6964 pipe_config
->base
.adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
6965 tmp
= I915_READ(VBLANK(cpu_transcoder
));
6966 pipe_config
->base
.adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
6967 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
6968 tmp
= I915_READ(VSYNC(cpu_transcoder
));
6969 pipe_config
->base
.adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
6970 pipe_config
->base
.adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
6972 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
6973 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
6974 pipe_config
->base
.adjusted_mode
.crtc_vtotal
+= 1;
6975 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
+= 1;
6979 static void intel_get_pipe_src_size(struct intel_crtc
*crtc
,
6980 struct intel_crtc_state
*pipe_config
)
6982 struct drm_device
*dev
= crtc
->base
.dev
;
6983 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6986 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
6987 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
6988 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
6990 pipe_config
->base
.mode
.vdisplay
= pipe_config
->pipe_src_h
;
6991 pipe_config
->base
.mode
.hdisplay
= pipe_config
->pipe_src_w
;
6994 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
6995 struct intel_crtc_state
*pipe_config
)
6997 mode
->hdisplay
= pipe_config
->base
.adjusted_mode
.crtc_hdisplay
;
6998 mode
->htotal
= pipe_config
->base
.adjusted_mode
.crtc_htotal
;
6999 mode
->hsync_start
= pipe_config
->base
.adjusted_mode
.crtc_hsync_start
;
7000 mode
->hsync_end
= pipe_config
->base
.adjusted_mode
.crtc_hsync_end
;
7002 mode
->vdisplay
= pipe_config
->base
.adjusted_mode
.crtc_vdisplay
;
7003 mode
->vtotal
= pipe_config
->base
.adjusted_mode
.crtc_vtotal
;
7004 mode
->vsync_start
= pipe_config
->base
.adjusted_mode
.crtc_vsync_start
;
7005 mode
->vsync_end
= pipe_config
->base
.adjusted_mode
.crtc_vsync_end
;
7007 mode
->flags
= pipe_config
->base
.adjusted_mode
.flags
;
7008 mode
->type
= DRM_MODE_TYPE_DRIVER
;
7010 mode
->clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
7012 mode
->hsync
= drm_mode_hsync(mode
);
7013 mode
->vrefresh
= drm_mode_vrefresh(mode
);
7014 drm_mode_set_name(mode
);
7017 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
7019 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
7024 /* we keep both pipes enabled on 830 */
7025 if (IS_I830(dev_priv
))
7026 pipeconf
|= I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
;
7028 if (intel_crtc
->config
->double_wide
)
7029 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
7031 /* only g4x and later have fancy bpc/dither controls */
7032 if (IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
7033 IS_CHERRYVIEW(dev_priv
)) {
7034 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7035 if (intel_crtc
->config
->dither
&& intel_crtc
->config
->pipe_bpp
!= 30)
7036 pipeconf
|= PIPECONF_DITHER_EN
|
7037 PIPECONF_DITHER_TYPE_SP
;
7039 switch (intel_crtc
->config
->pipe_bpp
) {
7041 pipeconf
|= PIPECONF_6BPC
;
7044 pipeconf
|= PIPECONF_8BPC
;
7047 pipeconf
|= PIPECONF_10BPC
;
7050 /* Case prevented by intel_choose_pipe_bpp_dither. */
7055 if (HAS_PIPE_CXSR(dev_priv
)) {
7056 if (intel_crtc
->lowfreq_avail
) {
7057 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
7058 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
7060 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
7064 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
7065 if (INTEL_GEN(dev_priv
) < 4 ||
7066 intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
7067 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
7069 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
7071 pipeconf
|= PIPECONF_PROGRESSIVE
;
7073 if ((IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) &&
7074 intel_crtc
->config
->limited_color_range
)
7075 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
7077 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
7078 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
7081 static int i8xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7082 struct intel_crtc_state
*crtc_state
)
7084 struct drm_device
*dev
= crtc
->base
.dev
;
7085 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7086 const struct intel_limit
*limit
;
7089 memset(&crtc_state
->dpll_hw_state
, 0,
7090 sizeof(crtc_state
->dpll_hw_state
));
7092 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7093 if (intel_panel_use_ssc(dev_priv
)) {
7094 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7095 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7098 limit
= &intel_limits_i8xx_lvds
;
7099 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DVO
)) {
7100 limit
= &intel_limits_i8xx_dvo
;
7102 limit
= &intel_limits_i8xx_dac
;
7105 if (!crtc_state
->clock_set
&&
7106 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7107 refclk
, NULL
, &crtc_state
->dpll
)) {
7108 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7112 i8xx_compute_dpll(crtc
, crtc_state
, NULL
);
7117 static int g4x_crtc_compute_clock(struct intel_crtc
*crtc
,
7118 struct intel_crtc_state
*crtc_state
)
7120 struct drm_device
*dev
= crtc
->base
.dev
;
7121 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7122 const struct intel_limit
*limit
;
7125 memset(&crtc_state
->dpll_hw_state
, 0,
7126 sizeof(crtc_state
->dpll_hw_state
));
7128 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7129 if (intel_panel_use_ssc(dev_priv
)) {
7130 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7131 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7134 if (intel_is_dual_link_lvds(dev
))
7135 limit
= &intel_limits_g4x_dual_channel_lvds
;
7137 limit
= &intel_limits_g4x_single_channel_lvds
;
7138 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
) ||
7139 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
)) {
7140 limit
= &intel_limits_g4x_hdmi
;
7141 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
)) {
7142 limit
= &intel_limits_g4x_sdvo
;
7144 /* The option is for other outputs */
7145 limit
= &intel_limits_i9xx_sdvo
;
7148 if (!crtc_state
->clock_set
&&
7149 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7150 refclk
, NULL
, &crtc_state
->dpll
)) {
7151 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7155 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7160 static int pnv_crtc_compute_clock(struct intel_crtc
*crtc
,
7161 struct intel_crtc_state
*crtc_state
)
7163 struct drm_device
*dev
= crtc
->base
.dev
;
7164 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7165 const struct intel_limit
*limit
;
7168 memset(&crtc_state
->dpll_hw_state
, 0,
7169 sizeof(crtc_state
->dpll_hw_state
));
7171 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7172 if (intel_panel_use_ssc(dev_priv
)) {
7173 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7174 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7177 limit
= &intel_limits_pineview_lvds
;
7179 limit
= &intel_limits_pineview_sdvo
;
7182 if (!crtc_state
->clock_set
&&
7183 !pnv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7184 refclk
, NULL
, &crtc_state
->dpll
)) {
7185 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7189 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7194 static int i9xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7195 struct intel_crtc_state
*crtc_state
)
7197 struct drm_device
*dev
= crtc
->base
.dev
;
7198 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7199 const struct intel_limit
*limit
;
7202 memset(&crtc_state
->dpll_hw_state
, 0,
7203 sizeof(crtc_state
->dpll_hw_state
));
7205 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7206 if (intel_panel_use_ssc(dev_priv
)) {
7207 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7208 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7211 limit
= &intel_limits_i9xx_lvds
;
7213 limit
= &intel_limits_i9xx_sdvo
;
7216 if (!crtc_state
->clock_set
&&
7217 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7218 refclk
, NULL
, &crtc_state
->dpll
)) {
7219 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7223 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7228 static int chv_crtc_compute_clock(struct intel_crtc
*crtc
,
7229 struct intel_crtc_state
*crtc_state
)
7231 int refclk
= 100000;
7232 const struct intel_limit
*limit
= &intel_limits_chv
;
7234 memset(&crtc_state
->dpll_hw_state
, 0,
7235 sizeof(crtc_state
->dpll_hw_state
));
7237 if (!crtc_state
->clock_set
&&
7238 !chv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7239 refclk
, NULL
, &crtc_state
->dpll
)) {
7240 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7244 chv_compute_dpll(crtc
, crtc_state
);
7249 static int vlv_crtc_compute_clock(struct intel_crtc
*crtc
,
7250 struct intel_crtc_state
*crtc_state
)
7252 int refclk
= 100000;
7253 const struct intel_limit
*limit
= &intel_limits_vlv
;
7255 memset(&crtc_state
->dpll_hw_state
, 0,
7256 sizeof(crtc_state
->dpll_hw_state
));
7258 if (!crtc_state
->clock_set
&&
7259 !vlv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7260 refclk
, NULL
, &crtc_state
->dpll
)) {
7261 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7265 vlv_compute_dpll(crtc
, crtc_state
);
7270 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
7271 struct intel_crtc_state
*pipe_config
)
7273 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7276 if (INTEL_GEN(dev_priv
) <= 3 &&
7277 (IS_I830(dev_priv
) || !IS_MOBILE(dev_priv
)))
7280 tmp
= I915_READ(PFIT_CONTROL
);
7281 if (!(tmp
& PFIT_ENABLE
))
7284 /* Check whether the pfit is attached to our pipe. */
7285 if (INTEL_GEN(dev_priv
) < 4) {
7286 if (crtc
->pipe
!= PIPE_B
)
7289 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
7293 pipe_config
->gmch_pfit
.control
= tmp
;
7294 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
7297 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
7298 struct intel_crtc_state
*pipe_config
)
7300 struct drm_device
*dev
= crtc
->base
.dev
;
7301 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7302 int pipe
= pipe_config
->cpu_transcoder
;
7305 int refclk
= 100000;
7307 /* In case of DSI, DPLL will not be used */
7308 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7311 mutex_lock(&dev_priv
->sb_lock
);
7312 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
7313 mutex_unlock(&dev_priv
->sb_lock
);
7315 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
7316 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
7317 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
7318 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
7319 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
7321 pipe_config
->port_clock
= vlv_calc_dpll_params(refclk
, &clock
);
7325 i9xx_get_initial_plane_config(struct intel_crtc
*crtc
,
7326 struct intel_initial_plane_config
*plane_config
)
7328 struct drm_device
*dev
= crtc
->base
.dev
;
7329 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7330 u32 val
, base
, offset
;
7331 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
7332 int fourcc
, pixel_format
;
7333 unsigned int aligned_height
;
7334 struct drm_framebuffer
*fb
;
7335 struct intel_framebuffer
*intel_fb
;
7337 val
= I915_READ(DSPCNTR(plane
));
7338 if (!(val
& DISPLAY_PLANE_ENABLE
))
7341 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
7343 DRM_DEBUG_KMS("failed to alloc fb\n");
7347 fb
= &intel_fb
->base
;
7351 if (INTEL_GEN(dev_priv
) >= 4) {
7352 if (val
& DISPPLANE_TILED
) {
7353 plane_config
->tiling
= I915_TILING_X
;
7354 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
7358 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
7359 fourcc
= i9xx_format_to_fourcc(pixel_format
);
7360 fb
->format
= drm_format_info(fourcc
);
7362 if (INTEL_GEN(dev_priv
) >= 4) {
7363 if (plane_config
->tiling
)
7364 offset
= I915_READ(DSPTILEOFF(plane
));
7366 offset
= I915_READ(DSPLINOFF(plane
));
7367 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
7369 base
= I915_READ(DSPADDR(plane
));
7371 plane_config
->base
= base
;
7373 val
= I915_READ(PIPESRC(pipe
));
7374 fb
->width
= ((val
>> 16) & 0xfff) + 1;
7375 fb
->height
= ((val
>> 0) & 0xfff) + 1;
7377 val
= I915_READ(DSPSTRIDE(pipe
));
7378 fb
->pitches
[0] = val
& 0xffffffc0;
7380 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
7382 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
7384 DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7385 pipe_name(pipe
), plane
, fb
->width
, fb
->height
,
7386 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
7387 plane_config
->size
);
7389 plane_config
->fb
= intel_fb
;
7392 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
7393 struct intel_crtc_state
*pipe_config
)
7395 struct drm_device
*dev
= crtc
->base
.dev
;
7396 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7397 int pipe
= pipe_config
->cpu_transcoder
;
7398 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
7400 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
, pll_dw3
;
7401 int refclk
= 100000;
7403 /* In case of DSI, DPLL will not be used */
7404 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7407 mutex_lock(&dev_priv
->sb_lock
);
7408 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
7409 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
7410 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
7411 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
7412 pll_dw3
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
7413 mutex_unlock(&dev_priv
->sb_lock
);
7415 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
7416 clock
.m2
= (pll_dw0
& 0xff) << 22;
7417 if (pll_dw3
& DPIO_CHV_FRAC_DIV_EN
)
7418 clock
.m2
|= pll_dw2
& 0x3fffff;
7419 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
7420 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
7421 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
7423 pipe_config
->port_clock
= chv_calc_dpll_params(refclk
, &clock
);
7426 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
7427 struct intel_crtc_state
*pipe_config
)
7429 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7430 enum intel_display_power_domain power_domain
;
7434 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
7435 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
7438 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7439 pipe_config
->shared_dpll
= NULL
;
7443 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
7444 if (!(tmp
& PIPECONF_ENABLE
))
7447 if (IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
7448 IS_CHERRYVIEW(dev_priv
)) {
7449 switch (tmp
& PIPECONF_BPC_MASK
) {
7451 pipe_config
->pipe_bpp
= 18;
7454 pipe_config
->pipe_bpp
= 24;
7456 case PIPECONF_10BPC
:
7457 pipe_config
->pipe_bpp
= 30;
7464 if ((IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) &&
7465 (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
7466 pipe_config
->limited_color_range
= true;
7468 if (INTEL_GEN(dev_priv
) < 4)
7469 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
7471 intel_get_pipe_timings(crtc
, pipe_config
);
7472 intel_get_pipe_src_size(crtc
, pipe_config
);
7474 i9xx_get_pfit_config(crtc
, pipe_config
);
7476 if (INTEL_GEN(dev_priv
) >= 4) {
7477 /* No way to read it out on pipes B and C */
7478 if (IS_CHERRYVIEW(dev_priv
) && crtc
->pipe
!= PIPE_A
)
7479 tmp
= dev_priv
->chv_dpll_md
[crtc
->pipe
];
7481 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
7482 pipe_config
->pixel_multiplier
=
7483 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
7484 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
7485 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
7486 } else if (IS_I945G(dev_priv
) || IS_I945GM(dev_priv
) ||
7487 IS_G33(dev_priv
) || IS_PINEVIEW(dev_priv
)) {
7488 tmp
= I915_READ(DPLL(crtc
->pipe
));
7489 pipe_config
->pixel_multiplier
=
7490 ((tmp
& SDVO_MULTIPLIER_MASK
)
7491 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
7493 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7494 * port and will be fixed up in the encoder->get_config
7496 pipe_config
->pixel_multiplier
= 1;
7498 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
7499 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
)) {
7501 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
7502 * on 830. Filter it out here so that we don't
7503 * report errors due to that.
7505 if (IS_I830(dev_priv
))
7506 pipe_config
->dpll_hw_state
.dpll
&= ~DPLL_DVO_2X_MODE
;
7508 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
7509 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
7511 /* Mask out read-only status bits. */
7512 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
7513 DPLL_PORTC_READY_MASK
|
7514 DPLL_PORTB_READY_MASK
);
7517 if (IS_CHERRYVIEW(dev_priv
))
7518 chv_crtc_clock_get(crtc
, pipe_config
);
7519 else if (IS_VALLEYVIEW(dev_priv
))
7520 vlv_crtc_clock_get(crtc
, pipe_config
);
7522 i9xx_crtc_clock_get(crtc
, pipe_config
);
7525 * Normally the dotclock is filled in by the encoder .get_config()
7526 * but in case the pipe is enabled w/o any ports we need a sane
7529 pipe_config
->base
.adjusted_mode
.crtc_clock
=
7530 pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
7535 intel_display_power_put(dev_priv
, power_domain
);
7540 static void ironlake_init_pch_refclk(struct drm_i915_private
*dev_priv
)
7542 struct intel_encoder
*encoder
;
7545 bool has_lvds
= false;
7546 bool has_cpu_edp
= false;
7547 bool has_panel
= false;
7548 bool has_ck505
= false;
7549 bool can_ssc
= false;
7550 bool using_ssc_source
= false;
7552 /* We need to take the global config into account */
7553 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
7554 switch (encoder
->type
) {
7555 case INTEL_OUTPUT_LVDS
:
7559 case INTEL_OUTPUT_EDP
:
7561 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
7569 if (HAS_PCH_IBX(dev_priv
)) {
7570 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
7571 can_ssc
= has_ck505
;
7577 /* Check if any DPLLs are using the SSC source */
7578 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
7579 u32 temp
= I915_READ(PCH_DPLL(i
));
7581 if (!(temp
& DPLL_VCO_ENABLE
))
7584 if ((temp
& PLL_REF_INPUT_MASK
) ==
7585 PLLB_REF_INPUT_SPREADSPECTRUMIN
) {
7586 using_ssc_source
= true;
7591 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
7592 has_panel
, has_lvds
, has_ck505
, using_ssc_source
);
7594 /* Ironlake: try to setup display ref clock before DPLL
7595 * enabling. This is only under driver's control after
7596 * PCH B stepping, previous chipset stepping should be
7597 * ignoring this setting.
7599 val
= I915_READ(PCH_DREF_CONTROL
);
7601 /* As we must carefully and slowly disable/enable each source in turn,
7602 * compute the final state we want first and check if we need to
7603 * make any changes at all.
7606 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
7608 final
|= DREF_NONSPREAD_CK505_ENABLE
;
7610 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
7612 final
&= ~DREF_SSC_SOURCE_MASK
;
7613 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7614 final
&= ~DREF_SSC1_ENABLE
;
7617 final
|= DREF_SSC_SOURCE_ENABLE
;
7619 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
7620 final
|= DREF_SSC1_ENABLE
;
7623 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
7624 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
7626 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
7628 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7629 } else if (using_ssc_source
) {
7630 final
|= DREF_SSC_SOURCE_ENABLE
;
7631 final
|= DREF_SSC1_ENABLE
;
7637 /* Always enable nonspread source */
7638 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
7641 val
|= DREF_NONSPREAD_CK505_ENABLE
;
7643 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
7646 val
&= ~DREF_SSC_SOURCE_MASK
;
7647 val
|= DREF_SSC_SOURCE_ENABLE
;
7649 /* SSC must be turned on before enabling the CPU output */
7650 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
7651 DRM_DEBUG_KMS("Using SSC on panel\n");
7652 val
|= DREF_SSC1_ENABLE
;
7654 val
&= ~DREF_SSC1_ENABLE
;
7656 /* Get SSC going before enabling the outputs */
7657 I915_WRITE(PCH_DREF_CONTROL
, val
);
7658 POSTING_READ(PCH_DREF_CONTROL
);
7661 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7663 /* Enable CPU source on CPU attached eDP */
7665 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
7666 DRM_DEBUG_KMS("Using SSC on eDP\n");
7667 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
7669 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
7671 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7673 I915_WRITE(PCH_DREF_CONTROL
, val
);
7674 POSTING_READ(PCH_DREF_CONTROL
);
7677 DRM_DEBUG_KMS("Disabling CPU source output\n");
7679 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7681 /* Turn off CPU output */
7682 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7684 I915_WRITE(PCH_DREF_CONTROL
, val
);
7685 POSTING_READ(PCH_DREF_CONTROL
);
7688 if (!using_ssc_source
) {
7689 DRM_DEBUG_KMS("Disabling SSC source\n");
7691 /* Turn off the SSC source */
7692 val
&= ~DREF_SSC_SOURCE_MASK
;
7693 val
|= DREF_SSC_SOURCE_DISABLE
;
7696 val
&= ~DREF_SSC1_ENABLE
;
7698 I915_WRITE(PCH_DREF_CONTROL
, val
);
7699 POSTING_READ(PCH_DREF_CONTROL
);
7704 BUG_ON(val
!= final
);
7707 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
7711 tmp
= I915_READ(SOUTH_CHICKEN2
);
7712 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
7713 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
7715 if (wait_for_us(I915_READ(SOUTH_CHICKEN2
) &
7716 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
7717 DRM_ERROR("FDI mPHY reset assert timeout\n");
7719 tmp
= I915_READ(SOUTH_CHICKEN2
);
7720 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
7721 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
7723 if (wait_for_us((I915_READ(SOUTH_CHICKEN2
) &
7724 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
7725 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
7728 /* WaMPhyProgramming:hsw */
7729 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
7733 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
7734 tmp
&= ~(0xFF << 24);
7735 tmp
|= (0x12 << 24);
7736 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
7738 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
7740 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
7742 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
7744 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
7746 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
7747 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
7748 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
7750 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
7751 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
7752 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
7754 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
7757 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
7759 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
7762 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
7764 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
7767 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
7769 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
7772 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
7774 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
7775 tmp
&= ~(0xFF << 16);
7776 tmp
|= (0x1C << 16);
7777 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
7779 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
7780 tmp
&= ~(0xFF << 16);
7781 tmp
|= (0x1C << 16);
7782 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
7784 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
7786 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
7788 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
7790 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
7792 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
7793 tmp
&= ~(0xF << 28);
7795 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
7797 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
7798 tmp
&= ~(0xF << 28);
7800 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
7803 /* Implements 3 different sequences from BSpec chapter "Display iCLK
7804 * Programming" based on the parameters passed:
7805 * - Sequence to enable CLKOUT_DP
7806 * - Sequence to enable CLKOUT_DP without spread
7807 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
7809 static void lpt_enable_clkout_dp(struct drm_i915_private
*dev_priv
,
7810 bool with_spread
, bool with_fdi
)
7814 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
7816 if (WARN(HAS_PCH_LPT_LP(dev_priv
) &&
7817 with_fdi
, "LP PCH doesn't have FDI\n"))
7820 mutex_lock(&dev_priv
->sb_lock
);
7822 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7823 tmp
&= ~SBI_SSCCTL_DISABLE
;
7824 tmp
|= SBI_SSCCTL_PATHALT
;
7825 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7830 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7831 tmp
&= ~SBI_SSCCTL_PATHALT
;
7832 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7835 lpt_reset_fdi_mphy(dev_priv
);
7836 lpt_program_fdi_mphy(dev_priv
);
7840 reg
= HAS_PCH_LPT_LP(dev_priv
) ? SBI_GEN0
: SBI_DBUFF0
;
7841 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
7842 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
7843 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
7845 mutex_unlock(&dev_priv
->sb_lock
);
7848 /* Sequence to disable CLKOUT_DP */
7849 static void lpt_disable_clkout_dp(struct drm_i915_private
*dev_priv
)
7853 mutex_lock(&dev_priv
->sb_lock
);
7855 reg
= HAS_PCH_LPT_LP(dev_priv
) ? SBI_GEN0
: SBI_DBUFF0
;
7856 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
7857 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
7858 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
7860 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7861 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
7862 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
7863 tmp
|= SBI_SSCCTL_PATHALT
;
7864 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7867 tmp
|= SBI_SSCCTL_DISABLE
;
7868 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7871 mutex_unlock(&dev_priv
->sb_lock
);
7874 #define BEND_IDX(steps) ((50 + (steps)) / 5)
7876 static const uint16_t sscdivintphase
[] = {
7877 [BEND_IDX( 50)] = 0x3B23,
7878 [BEND_IDX( 45)] = 0x3B23,
7879 [BEND_IDX( 40)] = 0x3C23,
7880 [BEND_IDX( 35)] = 0x3C23,
7881 [BEND_IDX( 30)] = 0x3D23,
7882 [BEND_IDX( 25)] = 0x3D23,
7883 [BEND_IDX( 20)] = 0x3E23,
7884 [BEND_IDX( 15)] = 0x3E23,
7885 [BEND_IDX( 10)] = 0x3F23,
7886 [BEND_IDX( 5)] = 0x3F23,
7887 [BEND_IDX( 0)] = 0x0025,
7888 [BEND_IDX( -5)] = 0x0025,
7889 [BEND_IDX(-10)] = 0x0125,
7890 [BEND_IDX(-15)] = 0x0125,
7891 [BEND_IDX(-20)] = 0x0225,
7892 [BEND_IDX(-25)] = 0x0225,
7893 [BEND_IDX(-30)] = 0x0325,
7894 [BEND_IDX(-35)] = 0x0325,
7895 [BEND_IDX(-40)] = 0x0425,
7896 [BEND_IDX(-45)] = 0x0425,
7897 [BEND_IDX(-50)] = 0x0525,
7902 * steps -50 to 50 inclusive, in steps of 5
7903 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
7904 * change in clock period = -(steps / 10) * 5.787 ps
7906 static void lpt_bend_clkout_dp(struct drm_i915_private
*dev_priv
, int steps
)
7909 int idx
= BEND_IDX(steps
);
7911 if (WARN_ON(steps
% 5 != 0))
7914 if (WARN_ON(idx
>= ARRAY_SIZE(sscdivintphase
)))
7917 mutex_lock(&dev_priv
->sb_lock
);
7919 if (steps
% 10 != 0)
7923 intel_sbi_write(dev_priv
, SBI_SSCDITHPHASE
, tmp
, SBI_ICLK
);
7925 tmp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE
, SBI_ICLK
);
7927 tmp
|= sscdivintphase
[idx
];
7928 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE
, tmp
, SBI_ICLK
);
7930 mutex_unlock(&dev_priv
->sb_lock
);
7935 static void lpt_init_pch_refclk(struct drm_i915_private
*dev_priv
)
7937 struct intel_encoder
*encoder
;
7938 bool has_vga
= false;
7940 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
7941 switch (encoder
->type
) {
7942 case INTEL_OUTPUT_ANALOG
:
7951 lpt_bend_clkout_dp(dev_priv
, 0);
7952 lpt_enable_clkout_dp(dev_priv
, true, true);
7954 lpt_disable_clkout_dp(dev_priv
);
7959 * Initialize reference clocks when the driver loads
7961 void intel_init_pch_refclk(struct drm_i915_private
*dev_priv
)
7963 if (HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
))
7964 ironlake_init_pch_refclk(dev_priv
);
7965 else if (HAS_PCH_LPT(dev_priv
))
7966 lpt_init_pch_refclk(dev_priv
);
7969 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
7971 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
7972 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7973 int pipe
= intel_crtc
->pipe
;
7978 switch (intel_crtc
->config
->pipe_bpp
) {
7980 val
|= PIPECONF_6BPC
;
7983 val
|= PIPECONF_8BPC
;
7986 val
|= PIPECONF_10BPC
;
7989 val
|= PIPECONF_12BPC
;
7992 /* Case prevented by intel_choose_pipe_bpp_dither. */
7996 if (intel_crtc
->config
->dither
)
7997 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
7999 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8000 val
|= PIPECONF_INTERLACED_ILK
;
8002 val
|= PIPECONF_PROGRESSIVE
;
8004 if (intel_crtc
->config
->limited_color_range
)
8005 val
|= PIPECONF_COLOR_RANGE_SELECT
;
8007 I915_WRITE(PIPECONF(pipe
), val
);
8008 POSTING_READ(PIPECONF(pipe
));
8011 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
8013 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
8014 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8015 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
8018 if (IS_HASWELL(dev_priv
) && intel_crtc
->config
->dither
)
8019 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
8021 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8022 val
|= PIPECONF_INTERLACED_ILK
;
8024 val
|= PIPECONF_PROGRESSIVE
;
8026 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
8027 POSTING_READ(PIPECONF(cpu_transcoder
));
8030 static void haswell_set_pipemisc(struct drm_crtc
*crtc
)
8032 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
8033 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8035 if (IS_BROADWELL(dev_priv
) || INTEL_INFO(dev_priv
)->gen
>= 9) {
8038 switch (intel_crtc
->config
->pipe_bpp
) {
8040 val
|= PIPEMISC_DITHER_6_BPC
;
8043 val
|= PIPEMISC_DITHER_8_BPC
;
8046 val
|= PIPEMISC_DITHER_10_BPC
;
8049 val
|= PIPEMISC_DITHER_12_BPC
;
8052 /* Case prevented by pipe_config_set_bpp. */
8056 if (intel_crtc
->config
->dither
)
8057 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
8059 I915_WRITE(PIPEMISC(intel_crtc
->pipe
), val
);
8063 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
8066 * Account for spread spectrum to avoid
8067 * oversubscribing the link. Max center spread
8068 * is 2.5%; use 5% for safety's sake.
8070 u32 bps
= target_clock
* bpp
* 21 / 20;
8071 return DIV_ROUND_UP(bps
, link_bw
* 8);
8074 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
8076 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
8079 static void ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
8080 struct intel_crtc_state
*crtc_state
,
8081 struct dpll
*reduced_clock
)
8083 struct drm_crtc
*crtc
= &intel_crtc
->base
;
8084 struct drm_device
*dev
= crtc
->dev
;
8085 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8089 /* Enable autotuning of the PLL clock (if permissible) */
8091 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8092 if ((intel_panel_use_ssc(dev_priv
) &&
8093 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
8094 (HAS_PCH_IBX(dev_priv
) && intel_is_dual_link_lvds(dev
)))
8096 } else if (crtc_state
->sdvo_tv_clock
)
8099 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
8101 if (ironlake_needs_fb_cb_tune(&crtc_state
->dpll
, factor
))
8104 if (reduced_clock
) {
8105 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
8107 if (reduced_clock
->m
< factor
* reduced_clock
->n
)
8115 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
))
8116 dpll
|= DPLLB_MODE_LVDS
;
8118 dpll
|= DPLLB_MODE_DAC_SERIAL
;
8120 dpll
|= (crtc_state
->pixel_multiplier
- 1)
8121 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
8123 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
8124 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
8125 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8127 if (intel_crtc_has_dp_encoder(crtc_state
))
8128 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8131 * The high speed IO clock is only really required for
8132 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8133 * possible to share the DPLL between CRT and HDMI. Enabling
8134 * the clock needlessly does no real harm, except use up a
8135 * bit of power potentially.
8137 * We'll limit this to IVB with 3 pipes, since it has only two
8138 * DPLLs and so DPLL sharing is the only way to get three pipes
8139 * driving PCH ports at the same time. On SNB we could do this,
8140 * and potentially avoid enabling the second DPLL, but it's not
8141 * clear if it''s a win or loss power wise. No point in doing
8142 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8144 if (INTEL_INFO(dev_priv
)->num_pipes
== 3 &&
8145 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
))
8146 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8148 /* compute bitmask from p1 value */
8149 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8151 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
8153 switch (crtc_state
->dpll
.p2
) {
8155 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
8158 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
8161 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
8164 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
8168 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
8169 intel_panel_use_ssc(dev_priv
))
8170 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
8172 dpll
|= PLL_REF_INPUT_DREFCLK
;
8174 dpll
|= DPLL_VCO_ENABLE
;
8176 crtc_state
->dpll_hw_state
.dpll
= dpll
;
8177 crtc_state
->dpll_hw_state
.fp0
= fp
;
8178 crtc_state
->dpll_hw_state
.fp1
= fp2
;
8181 static int ironlake_crtc_compute_clock(struct intel_crtc
*crtc
,
8182 struct intel_crtc_state
*crtc_state
)
8184 struct drm_device
*dev
= crtc
->base
.dev
;
8185 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8186 const struct intel_limit
*limit
;
8187 int refclk
= 120000;
8189 memset(&crtc_state
->dpll_hw_state
, 0,
8190 sizeof(crtc_state
->dpll_hw_state
));
8192 crtc
->lowfreq_avail
= false;
8194 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8195 if (!crtc_state
->has_pch_encoder
)
8198 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8199 if (intel_panel_use_ssc(dev_priv
)) {
8200 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8201 dev_priv
->vbt
.lvds_ssc_freq
);
8202 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8205 if (intel_is_dual_link_lvds(dev
)) {
8206 if (refclk
== 100000)
8207 limit
= &intel_limits_ironlake_dual_lvds_100m
;
8209 limit
= &intel_limits_ironlake_dual_lvds
;
8211 if (refclk
== 100000)
8212 limit
= &intel_limits_ironlake_single_lvds_100m
;
8214 limit
= &intel_limits_ironlake_single_lvds
;
8217 limit
= &intel_limits_ironlake_dac
;
8220 if (!crtc_state
->clock_set
&&
8221 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8222 refclk
, NULL
, &crtc_state
->dpll
)) {
8223 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8227 ironlake_compute_dpll(crtc
, crtc_state
, NULL
);
8229 if (!intel_get_shared_dpll(crtc
, crtc_state
, NULL
)) {
8230 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8231 pipe_name(crtc
->pipe
));
8238 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
8239 struct intel_link_m_n
*m_n
)
8241 struct drm_device
*dev
= crtc
->base
.dev
;
8242 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8243 enum pipe pipe
= crtc
->pipe
;
8245 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
8246 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
8247 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
8249 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
8250 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
8251 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8254 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
8255 enum transcoder transcoder
,
8256 struct intel_link_m_n
*m_n
,
8257 struct intel_link_m_n
*m2_n2
)
8259 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
8260 enum pipe pipe
= crtc
->pipe
;
8262 if (INTEL_GEN(dev_priv
) >= 5) {
8263 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
8264 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
8265 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
8267 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
8268 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
8269 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8270 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8271 * gen < 8) and if DRRS is supported (to make sure the
8272 * registers are not unnecessarily read).
8274 if (m2_n2
&& INTEL_GEN(dev_priv
) < 8 &&
8275 crtc
->config
->has_drrs
) {
8276 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
8277 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
8278 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
8280 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
8281 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
8282 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8285 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
8286 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
8287 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
8289 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
8290 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
8291 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8295 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
8296 struct intel_crtc_state
*pipe_config
)
8298 if (pipe_config
->has_pch_encoder
)
8299 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
8301 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8302 &pipe_config
->dp_m_n
,
8303 &pipe_config
->dp_m2_n2
);
8306 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
8307 struct intel_crtc_state
*pipe_config
)
8309 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8310 &pipe_config
->fdi_m_n
, NULL
);
8313 static void skylake_get_pfit_config(struct intel_crtc
*crtc
,
8314 struct intel_crtc_state
*pipe_config
)
8316 struct drm_device
*dev
= crtc
->base
.dev
;
8317 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8318 struct intel_crtc_scaler_state
*scaler_state
= &pipe_config
->scaler_state
;
8319 uint32_t ps_ctrl
= 0;
8323 /* find scaler attached to this pipe */
8324 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
8325 ps_ctrl
= I915_READ(SKL_PS_CTRL(crtc
->pipe
, i
));
8326 if (ps_ctrl
& PS_SCALER_EN
&& !(ps_ctrl
& PS_PLANE_SEL_MASK
)) {
8328 pipe_config
->pch_pfit
.enabled
= true;
8329 pipe_config
->pch_pfit
.pos
= I915_READ(SKL_PS_WIN_POS(crtc
->pipe
, i
));
8330 pipe_config
->pch_pfit
.size
= I915_READ(SKL_PS_WIN_SZ(crtc
->pipe
, i
));
8335 scaler_state
->scaler_id
= id
;
8337 scaler_state
->scaler_users
|= (1 << SKL_CRTC_INDEX
);
8339 scaler_state
->scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
8344 skylake_get_initial_plane_config(struct intel_crtc
*crtc
,
8345 struct intel_initial_plane_config
*plane_config
)
8347 struct drm_device
*dev
= crtc
->base
.dev
;
8348 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8349 u32 val
, base
, offset
, stride_mult
, tiling
;
8350 int pipe
= crtc
->pipe
;
8351 int fourcc
, pixel_format
;
8352 unsigned int aligned_height
;
8353 struct drm_framebuffer
*fb
;
8354 struct intel_framebuffer
*intel_fb
;
8356 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8358 DRM_DEBUG_KMS("failed to alloc fb\n");
8362 fb
= &intel_fb
->base
;
8366 val
= I915_READ(PLANE_CTL(pipe
, 0));
8367 if (!(val
& PLANE_CTL_ENABLE
))
8370 pixel_format
= val
& PLANE_CTL_FORMAT_MASK
;
8371 fourcc
= skl_format_to_fourcc(pixel_format
,
8372 val
& PLANE_CTL_ORDER_RGBX
,
8373 val
& PLANE_CTL_ALPHA_MASK
);
8374 fb
->format
= drm_format_info(fourcc
);
8376 tiling
= val
& PLANE_CTL_TILED_MASK
;
8378 case PLANE_CTL_TILED_LINEAR
:
8379 fb
->modifier
= DRM_FORMAT_MOD_LINEAR
;
8381 case PLANE_CTL_TILED_X
:
8382 plane_config
->tiling
= I915_TILING_X
;
8383 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
8385 case PLANE_CTL_TILED_Y
:
8386 fb
->modifier
= I915_FORMAT_MOD_Y_TILED
;
8388 case PLANE_CTL_TILED_YF
:
8389 fb
->modifier
= I915_FORMAT_MOD_Yf_TILED
;
8392 MISSING_CASE(tiling
);
8396 base
= I915_READ(PLANE_SURF(pipe
, 0)) & 0xfffff000;
8397 plane_config
->base
= base
;
8399 offset
= I915_READ(PLANE_OFFSET(pipe
, 0));
8401 val
= I915_READ(PLANE_SIZE(pipe
, 0));
8402 fb
->height
= ((val
>> 16) & 0xfff) + 1;
8403 fb
->width
= ((val
>> 0) & 0x1fff) + 1;
8405 val
= I915_READ(PLANE_STRIDE(pipe
, 0));
8406 stride_mult
= intel_fb_stride_alignment(fb
, 0);
8407 fb
->pitches
[0] = (val
& 0x3ff) * stride_mult
;
8409 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
8411 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8413 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8414 pipe_name(pipe
), fb
->width
, fb
->height
,
8415 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
8416 plane_config
->size
);
8418 plane_config
->fb
= intel_fb
;
8425 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
8426 struct intel_crtc_state
*pipe_config
)
8428 struct drm_device
*dev
= crtc
->base
.dev
;
8429 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8432 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
8434 if (tmp
& PF_ENABLE
) {
8435 pipe_config
->pch_pfit
.enabled
= true;
8436 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
8437 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
8439 /* We currently do not free assignements of panel fitters on
8440 * ivb/hsw (since we don't use the higher upscaling modes which
8441 * differentiates them) so just WARN about this case for now. */
8442 if (IS_GEN7(dev_priv
)) {
8443 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
8444 PF_PIPE_SEL_IVB(crtc
->pipe
));
8450 ironlake_get_initial_plane_config(struct intel_crtc
*crtc
,
8451 struct intel_initial_plane_config
*plane_config
)
8453 struct drm_device
*dev
= crtc
->base
.dev
;
8454 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8455 u32 val
, base
, offset
;
8456 int pipe
= crtc
->pipe
;
8457 int fourcc
, pixel_format
;
8458 unsigned int aligned_height
;
8459 struct drm_framebuffer
*fb
;
8460 struct intel_framebuffer
*intel_fb
;
8462 val
= I915_READ(DSPCNTR(pipe
));
8463 if (!(val
& DISPLAY_PLANE_ENABLE
))
8466 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8468 DRM_DEBUG_KMS("failed to alloc fb\n");
8472 fb
= &intel_fb
->base
;
8476 if (INTEL_GEN(dev_priv
) >= 4) {
8477 if (val
& DISPPLANE_TILED
) {
8478 plane_config
->tiling
= I915_TILING_X
;
8479 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
8483 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
8484 fourcc
= i9xx_format_to_fourcc(pixel_format
);
8485 fb
->format
= drm_format_info(fourcc
);
8487 base
= I915_READ(DSPSURF(pipe
)) & 0xfffff000;
8488 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
8489 offset
= I915_READ(DSPOFFSET(pipe
));
8491 if (plane_config
->tiling
)
8492 offset
= I915_READ(DSPTILEOFF(pipe
));
8494 offset
= I915_READ(DSPLINOFF(pipe
));
8496 plane_config
->base
= base
;
8498 val
= I915_READ(PIPESRC(pipe
));
8499 fb
->width
= ((val
>> 16) & 0xfff) + 1;
8500 fb
->height
= ((val
>> 0) & 0xfff) + 1;
8502 val
= I915_READ(DSPSTRIDE(pipe
));
8503 fb
->pitches
[0] = val
& 0xffffffc0;
8505 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
8507 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8509 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8510 pipe_name(pipe
), fb
->width
, fb
->height
,
8511 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
8512 plane_config
->size
);
8514 plane_config
->fb
= intel_fb
;
8517 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
8518 struct intel_crtc_state
*pipe_config
)
8520 struct drm_device
*dev
= crtc
->base
.dev
;
8521 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8522 enum intel_display_power_domain power_domain
;
8526 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
8527 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8530 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8531 pipe_config
->shared_dpll
= NULL
;
8534 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
8535 if (!(tmp
& PIPECONF_ENABLE
))
8538 switch (tmp
& PIPECONF_BPC_MASK
) {
8540 pipe_config
->pipe_bpp
= 18;
8543 pipe_config
->pipe_bpp
= 24;
8545 case PIPECONF_10BPC
:
8546 pipe_config
->pipe_bpp
= 30;
8548 case PIPECONF_12BPC
:
8549 pipe_config
->pipe_bpp
= 36;
8555 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
8556 pipe_config
->limited_color_range
= true;
8558 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
8559 struct intel_shared_dpll
*pll
;
8560 enum intel_dpll_id pll_id
;
8562 pipe_config
->has_pch_encoder
= true;
8564 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
8565 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
8566 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
8568 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
8570 if (HAS_PCH_IBX(dev_priv
)) {
8572 * The pipe->pch transcoder and pch transcoder->pll
8575 pll_id
= (enum intel_dpll_id
) crtc
->pipe
;
8577 tmp
= I915_READ(PCH_DPLL_SEL
);
8578 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
8579 pll_id
= DPLL_ID_PCH_PLL_B
;
8581 pll_id
= DPLL_ID_PCH_PLL_A
;
8584 pipe_config
->shared_dpll
=
8585 intel_get_shared_dpll_by_id(dev_priv
, pll_id
);
8586 pll
= pipe_config
->shared_dpll
;
8588 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
8589 &pipe_config
->dpll_hw_state
));
8591 tmp
= pipe_config
->dpll_hw_state
.dpll
;
8592 pipe_config
->pixel_multiplier
=
8593 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
8594 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
8596 ironlake_pch_clock_get(crtc
, pipe_config
);
8598 pipe_config
->pixel_multiplier
= 1;
8601 intel_get_pipe_timings(crtc
, pipe_config
);
8602 intel_get_pipe_src_size(crtc
, pipe_config
);
8604 ironlake_get_pfit_config(crtc
, pipe_config
);
8609 intel_display_power_put(dev_priv
, power_domain
);
8614 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
8616 struct drm_device
*dev
= &dev_priv
->drm
;
8617 struct intel_crtc
*crtc
;
8619 for_each_intel_crtc(dev
, crtc
)
8620 I915_STATE_WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
8621 pipe_name(crtc
->pipe
));
8623 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
8624 I915_STATE_WARN(I915_READ(SPLL_CTL
) & SPLL_PLL_ENABLE
, "SPLL enabled\n");
8625 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE
, "WRPLL1 enabled\n");
8626 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE
, "WRPLL2 enabled\n");
8627 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON
, "Panel power on\n");
8628 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
8629 "CPU PWM1 enabled\n");
8630 if (IS_HASWELL(dev_priv
))
8631 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
8632 "CPU PWM2 enabled\n");
8633 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
8634 "PCH PWM1 enabled\n");
8635 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
8636 "Utility pin enabled\n");
8637 I915_STATE_WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
8640 * In theory we can still leave IRQs enabled, as long as only the HPD
8641 * interrupts remain enabled. We used to check for that, but since it's
8642 * gen-specific and since we only disable LCPLL after we fully disable
8643 * the interrupts, the check below should be enough.
8645 I915_STATE_WARN(intel_irqs_enabled(dev_priv
), "IRQs enabled\n");
8648 static uint32_t hsw_read_dcomp(struct drm_i915_private
*dev_priv
)
8650 if (IS_HASWELL(dev_priv
))
8651 return I915_READ(D_COMP_HSW
);
8653 return I915_READ(D_COMP_BDW
);
8656 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
8658 if (IS_HASWELL(dev_priv
)) {
8659 mutex_lock(&dev_priv
->rps
.hw_lock
);
8660 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
8662 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
8663 mutex_unlock(&dev_priv
->rps
.hw_lock
);
8665 I915_WRITE(D_COMP_BDW
, val
);
8666 POSTING_READ(D_COMP_BDW
);
8671 * This function implements pieces of two sequences from BSpec:
8672 * - Sequence for display software to disable LCPLL
8673 * - Sequence for display software to allow package C8+
8674 * The steps implemented here are just the steps that actually touch the LCPLL
8675 * register. Callers should take care of disabling all the display engine
8676 * functions, doing the mode unset, fixing interrupts, etc.
8678 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
8679 bool switch_to_fclk
, bool allow_power_down
)
8683 assert_can_disable_lcpll(dev_priv
);
8685 val
= I915_READ(LCPLL_CTL
);
8687 if (switch_to_fclk
) {
8688 val
|= LCPLL_CD_SOURCE_FCLK
;
8689 I915_WRITE(LCPLL_CTL
, val
);
8691 if (wait_for_us(I915_READ(LCPLL_CTL
) &
8692 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
8693 DRM_ERROR("Switching to FCLK failed\n");
8695 val
= I915_READ(LCPLL_CTL
);
8698 val
|= LCPLL_PLL_DISABLE
;
8699 I915_WRITE(LCPLL_CTL
, val
);
8700 POSTING_READ(LCPLL_CTL
);
8702 if (intel_wait_for_register(dev_priv
, LCPLL_CTL
, LCPLL_PLL_LOCK
, 0, 1))
8703 DRM_ERROR("LCPLL still locked\n");
8705 val
= hsw_read_dcomp(dev_priv
);
8706 val
|= D_COMP_COMP_DISABLE
;
8707 hsw_write_dcomp(dev_priv
, val
);
8710 if (wait_for((hsw_read_dcomp(dev_priv
) & D_COMP_RCOMP_IN_PROGRESS
) == 0,
8712 DRM_ERROR("D_COMP RCOMP still in progress\n");
8714 if (allow_power_down
) {
8715 val
= I915_READ(LCPLL_CTL
);
8716 val
|= LCPLL_POWER_DOWN_ALLOW
;
8717 I915_WRITE(LCPLL_CTL
, val
);
8718 POSTING_READ(LCPLL_CTL
);
8723 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
8726 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
8730 val
= I915_READ(LCPLL_CTL
);
8732 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
8733 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
8737 * Make sure we're not on PC8 state before disabling PC8, otherwise
8738 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
8740 intel_uncore_forcewake_get(dev_priv
, FORCEWAKE_ALL
);
8742 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
8743 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
8744 I915_WRITE(LCPLL_CTL
, val
);
8745 POSTING_READ(LCPLL_CTL
);
8748 val
= hsw_read_dcomp(dev_priv
);
8749 val
|= D_COMP_COMP_FORCE
;
8750 val
&= ~D_COMP_COMP_DISABLE
;
8751 hsw_write_dcomp(dev_priv
, val
);
8753 val
= I915_READ(LCPLL_CTL
);
8754 val
&= ~LCPLL_PLL_DISABLE
;
8755 I915_WRITE(LCPLL_CTL
, val
);
8757 if (intel_wait_for_register(dev_priv
,
8758 LCPLL_CTL
, LCPLL_PLL_LOCK
, LCPLL_PLL_LOCK
,
8760 DRM_ERROR("LCPLL not locked yet\n");
8762 if (val
& LCPLL_CD_SOURCE_FCLK
) {
8763 val
= I915_READ(LCPLL_CTL
);
8764 val
&= ~LCPLL_CD_SOURCE_FCLK
;
8765 I915_WRITE(LCPLL_CTL
, val
);
8767 if (wait_for_us((I915_READ(LCPLL_CTL
) &
8768 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
8769 DRM_ERROR("Switching back to LCPLL failed\n");
8772 intel_uncore_forcewake_put(dev_priv
, FORCEWAKE_ALL
);
8773 intel_update_cdclk(dev_priv
);
8777 * Package states C8 and deeper are really deep PC states that can only be
8778 * reached when all the devices on the system allow it, so even if the graphics
8779 * device allows PC8+, it doesn't mean the system will actually get to these
8780 * states. Our driver only allows PC8+ when going into runtime PM.
8782 * The requirements for PC8+ are that all the outputs are disabled, the power
8783 * well is disabled and most interrupts are disabled, and these are also
8784 * requirements for runtime PM. When these conditions are met, we manually do
8785 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
8786 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
8789 * When we really reach PC8 or deeper states (not just when we allow it) we lose
8790 * the state of some registers, so when we come back from PC8+ we need to
8791 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
8792 * need to take care of the registers kept by RC6. Notice that this happens even
8793 * if we don't put the device in PCI D3 state (which is what currently happens
8794 * because of the runtime PM support).
8796 * For more, read "Display Sequences for Package C8" on the hardware
8799 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
8803 DRM_DEBUG_KMS("Enabling package C8+\n");
8805 if (HAS_PCH_LPT_LP(dev_priv
)) {
8806 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
8807 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
8808 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
8811 lpt_disable_clkout_dp(dev_priv
);
8812 hsw_disable_lcpll(dev_priv
, true, true);
8815 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
8819 DRM_DEBUG_KMS("Disabling package C8+\n");
8821 hsw_restore_lcpll(dev_priv
);
8822 lpt_init_pch_refclk(dev_priv
);
8824 if (HAS_PCH_LPT_LP(dev_priv
)) {
8825 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
8826 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
8827 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
8831 static int haswell_crtc_compute_clock(struct intel_crtc
*crtc
,
8832 struct intel_crtc_state
*crtc_state
)
8834 if (!intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DSI
)) {
8835 struct intel_encoder
*encoder
=
8836 intel_ddi_get_crtc_new_encoder(crtc_state
);
8838 if (!intel_get_shared_dpll(crtc
, crtc_state
, encoder
)) {
8839 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8840 pipe_name(crtc
->pipe
));
8845 crtc
->lowfreq_avail
= false;
8850 static void cannonlake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8852 struct intel_crtc_state
*pipe_config
)
8854 enum intel_dpll_id id
;
8857 temp
= I915_READ(DPCLKA_CFGCR0
) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port
);
8858 id
= temp
>> (port
* 2);
8860 if (WARN_ON(id
< SKL_DPLL0
|| id
> SKL_DPLL2
))
8863 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8866 static void bxt_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8868 struct intel_crtc_state
*pipe_config
)
8870 enum intel_dpll_id id
;
8874 id
= DPLL_ID_SKL_DPLL0
;
8877 id
= DPLL_ID_SKL_DPLL1
;
8880 id
= DPLL_ID_SKL_DPLL2
;
8883 DRM_ERROR("Incorrect port type\n");
8887 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8890 static void skylake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8892 struct intel_crtc_state
*pipe_config
)
8894 enum intel_dpll_id id
;
8897 temp
= I915_READ(DPLL_CTRL2
) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port
);
8898 id
= temp
>> (port
* 3 + 1);
8900 if (WARN_ON(id
< SKL_DPLL0
|| id
> SKL_DPLL3
))
8903 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8906 static void haswell_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8908 struct intel_crtc_state
*pipe_config
)
8910 enum intel_dpll_id id
;
8911 uint32_t ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
8913 switch (ddi_pll_sel
) {
8914 case PORT_CLK_SEL_WRPLL1
:
8915 id
= DPLL_ID_WRPLL1
;
8917 case PORT_CLK_SEL_WRPLL2
:
8918 id
= DPLL_ID_WRPLL2
;
8920 case PORT_CLK_SEL_SPLL
:
8923 case PORT_CLK_SEL_LCPLL_810
:
8924 id
= DPLL_ID_LCPLL_810
;
8926 case PORT_CLK_SEL_LCPLL_1350
:
8927 id
= DPLL_ID_LCPLL_1350
;
8929 case PORT_CLK_SEL_LCPLL_2700
:
8930 id
= DPLL_ID_LCPLL_2700
;
8933 MISSING_CASE(ddi_pll_sel
);
8935 case PORT_CLK_SEL_NONE
:
8939 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8942 static bool hsw_get_transcoder_state(struct intel_crtc
*crtc
,
8943 struct intel_crtc_state
*pipe_config
,
8944 u64
*power_domain_mask
)
8946 struct drm_device
*dev
= crtc
->base
.dev
;
8947 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8948 enum intel_display_power_domain power_domain
;
8952 * The pipe->transcoder mapping is fixed with the exception of the eDP
8953 * transcoder handled below.
8955 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8958 * XXX: Do intel_display_power_get_if_enabled before reading this (for
8959 * consistency and less surprising code; it's in always on power).
8961 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
8962 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
8963 enum pipe trans_edp_pipe
;
8964 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
8966 WARN(1, "unknown pipe linked to edp transcoder\n");
8967 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
8968 case TRANS_DDI_EDP_INPUT_A_ON
:
8969 trans_edp_pipe
= PIPE_A
;
8971 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
8972 trans_edp_pipe
= PIPE_B
;
8974 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
8975 trans_edp_pipe
= PIPE_C
;
8979 if (trans_edp_pipe
== crtc
->pipe
)
8980 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
8983 power_domain
= POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
);
8984 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8986 *power_domain_mask
|= BIT_ULL(power_domain
);
8988 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
8990 return tmp
& PIPECONF_ENABLE
;
8993 static bool bxt_get_dsi_transcoder_state(struct intel_crtc
*crtc
,
8994 struct intel_crtc_state
*pipe_config
,
8995 u64
*power_domain_mask
)
8997 struct drm_device
*dev
= crtc
->base
.dev
;
8998 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8999 enum intel_display_power_domain power_domain
;
9001 enum transcoder cpu_transcoder
;
9004 for_each_port_masked(port
, BIT(PORT_A
) | BIT(PORT_C
)) {
9006 cpu_transcoder
= TRANSCODER_DSI_A
;
9008 cpu_transcoder
= TRANSCODER_DSI_C
;
9010 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
9011 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9013 *power_domain_mask
|= BIT_ULL(power_domain
);
9016 * The PLL needs to be enabled with a valid divider
9017 * configuration, otherwise accessing DSI registers will hang
9018 * the machine. See BSpec North Display Engine
9019 * registers/MIPI[BXT]. We can break out here early, since we
9020 * need the same DSI PLL to be enabled for both DSI ports.
9022 if (!intel_dsi_pll_is_enabled(dev_priv
))
9025 /* XXX: this works for video mode only */
9026 tmp
= I915_READ(BXT_MIPI_PORT_CTRL(port
));
9027 if (!(tmp
& DPI_ENABLE
))
9030 tmp
= I915_READ(MIPI_CTRL(port
));
9031 if ((tmp
& BXT_PIPE_SELECT_MASK
) != BXT_PIPE_SELECT(crtc
->pipe
))
9034 pipe_config
->cpu_transcoder
= cpu_transcoder
;
9038 return transcoder_is_dsi(pipe_config
->cpu_transcoder
);
9041 static void haswell_get_ddi_port_state(struct intel_crtc
*crtc
,
9042 struct intel_crtc_state
*pipe_config
)
9044 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9045 struct intel_shared_dpll
*pll
;
9049 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
9051 port
= (tmp
& TRANS_DDI_PORT_MASK
) >> TRANS_DDI_PORT_SHIFT
;
9053 if (IS_CANNONLAKE(dev_priv
))
9054 cannonlake_get_ddi_pll(dev_priv
, port
, pipe_config
);
9055 else if (IS_GEN9_BC(dev_priv
))
9056 skylake_get_ddi_pll(dev_priv
, port
, pipe_config
);
9057 else if (IS_GEN9_LP(dev_priv
))
9058 bxt_get_ddi_pll(dev_priv
, port
, pipe_config
);
9060 haswell_get_ddi_pll(dev_priv
, port
, pipe_config
);
9062 pll
= pipe_config
->shared_dpll
;
9064 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
9065 &pipe_config
->dpll_hw_state
));
9069 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9070 * DDI E. So just check whether this pipe is wired to DDI E and whether
9071 * the PCH transcoder is on.
9073 if (INTEL_GEN(dev_priv
) < 9 &&
9074 (port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
9075 pipe_config
->has_pch_encoder
= true;
9077 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
9078 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
9079 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
9081 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
9085 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
9086 struct intel_crtc_state
*pipe_config
)
9088 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9089 enum intel_display_power_domain power_domain
;
9090 u64 power_domain_mask
;
9093 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
9094 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9096 power_domain_mask
= BIT_ULL(power_domain
);
9098 pipe_config
->shared_dpll
= NULL
;
9100 active
= hsw_get_transcoder_state(crtc
, pipe_config
, &power_domain_mask
);
9102 if (IS_GEN9_LP(dev_priv
) &&
9103 bxt_get_dsi_transcoder_state(crtc
, pipe_config
, &power_domain_mask
)) {
9111 if (!transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
9112 haswell_get_ddi_port_state(crtc
, pipe_config
);
9113 intel_get_pipe_timings(crtc
, pipe_config
);
9116 intel_get_pipe_src_size(crtc
, pipe_config
);
9118 pipe_config
->gamma_mode
=
9119 I915_READ(GAMMA_MODE(crtc
->pipe
)) & GAMMA_MODE_MODE_MASK
;
9121 if (INTEL_GEN(dev_priv
) >= 9) {
9122 intel_crtc_init_scalers(crtc
, pipe_config
);
9124 pipe_config
->scaler_state
.scaler_id
= -1;
9125 pipe_config
->scaler_state
.scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
9128 power_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
9129 if (intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
9130 power_domain_mask
|= BIT_ULL(power_domain
);
9131 if (INTEL_GEN(dev_priv
) >= 9)
9132 skylake_get_pfit_config(crtc
, pipe_config
);
9134 ironlake_get_pfit_config(crtc
, pipe_config
);
9137 if (IS_HASWELL(dev_priv
))
9138 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
9139 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
9141 if (pipe_config
->cpu_transcoder
!= TRANSCODER_EDP
&&
9142 !transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
9143 pipe_config
->pixel_multiplier
=
9144 I915_READ(PIPE_MULT(pipe_config
->cpu_transcoder
)) + 1;
9146 pipe_config
->pixel_multiplier
= 1;
9150 for_each_power_domain(power_domain
, power_domain_mask
)
9151 intel_display_power_put(dev_priv
, power_domain
);
9156 static u32
intel_cursor_base(const struct intel_plane_state
*plane_state
)
9158 struct drm_i915_private
*dev_priv
=
9159 to_i915(plane_state
->base
.plane
->dev
);
9160 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9161 const struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
9164 if (INTEL_INFO(dev_priv
)->cursor_needs_physical
)
9165 base
= obj
->phys_handle
->busaddr
;
9167 base
= intel_plane_ggtt_offset(plane_state
);
9169 base
+= plane_state
->main
.offset
;
9171 /* ILK+ do this automagically */
9172 if (HAS_GMCH_DISPLAY(dev_priv
) &&
9173 plane_state
->base
.rotation
& DRM_MODE_ROTATE_180
)
9174 base
+= (plane_state
->base
.crtc_h
*
9175 plane_state
->base
.crtc_w
- 1) * fb
->format
->cpp
[0];
9180 static u32
intel_cursor_position(const struct intel_plane_state
*plane_state
)
9182 int x
= plane_state
->base
.crtc_x
;
9183 int y
= plane_state
->base
.crtc_y
;
9187 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
9190 pos
|= x
<< CURSOR_X_SHIFT
;
9193 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
9196 pos
|= y
<< CURSOR_Y_SHIFT
;
9201 static bool intel_cursor_size_ok(const struct intel_plane_state
*plane_state
)
9203 const struct drm_mode_config
*config
=
9204 &plane_state
->base
.plane
->dev
->mode_config
;
9205 int width
= plane_state
->base
.crtc_w
;
9206 int height
= plane_state
->base
.crtc_h
;
9208 return width
> 0 && width
<= config
->cursor_width
&&
9209 height
> 0 && height
<= config
->cursor_height
;
9212 static int intel_check_cursor(struct intel_crtc_state
*crtc_state
,
9213 struct intel_plane_state
*plane_state
)
9215 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9220 ret
= drm_plane_helper_check_state(&plane_state
->base
,
9222 DRM_PLANE_HELPER_NO_SCALING
,
9223 DRM_PLANE_HELPER_NO_SCALING
,
9231 if (fb
->modifier
!= DRM_FORMAT_MOD_LINEAR
) {
9232 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9236 src_x
= plane_state
->base
.src_x
>> 16;
9237 src_y
= plane_state
->base
.src_y
>> 16;
9239 intel_add_fb_offsets(&src_x
, &src_y
, plane_state
, 0);
9240 offset
= intel_compute_tile_offset(&src_x
, &src_y
, plane_state
, 0);
9242 if (src_x
!= 0 || src_y
!= 0) {
9243 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9247 plane_state
->main
.offset
= offset
;
9252 static u32
i845_cursor_ctl(const struct intel_crtc_state
*crtc_state
,
9253 const struct intel_plane_state
*plane_state
)
9255 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9257 return CURSOR_ENABLE
|
9258 CURSOR_GAMMA_ENABLE
|
9259 CURSOR_FORMAT_ARGB
|
9260 CURSOR_STRIDE(fb
->pitches
[0]);
9263 static bool i845_cursor_size_ok(const struct intel_plane_state
*plane_state
)
9265 int width
= plane_state
->base
.crtc_w
;
9268 * 845g/865g are only limited by the width of their cursors,
9269 * the height is arbitrary up to the precision of the register.
9271 return intel_cursor_size_ok(plane_state
) && IS_ALIGNED(width
, 64);
9274 static int i845_check_cursor(struct intel_plane
*plane
,
9275 struct intel_crtc_state
*crtc_state
,
9276 struct intel_plane_state
*plane_state
)
9278 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9281 ret
= intel_check_cursor(crtc_state
, plane_state
);
9285 /* if we want to turn off the cursor ignore width and height */
9289 /* Check for which cursor types we support */
9290 if (!i845_cursor_size_ok(plane_state
)) {
9291 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9292 plane_state
->base
.crtc_w
,
9293 plane_state
->base
.crtc_h
);
9297 switch (fb
->pitches
[0]) {
9304 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
9309 plane_state
->ctl
= i845_cursor_ctl(crtc_state
, plane_state
);
9314 static void i845_update_cursor(struct intel_plane
*plane
,
9315 const struct intel_crtc_state
*crtc_state
,
9316 const struct intel_plane_state
*plane_state
)
9318 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
9319 u32 cntl
= 0, base
= 0, pos
= 0, size
= 0;
9320 unsigned long irqflags
;
9322 if (plane_state
&& plane_state
->base
.visible
) {
9323 unsigned int width
= plane_state
->base
.crtc_w
;
9324 unsigned int height
= plane_state
->base
.crtc_h
;
9326 cntl
= plane_state
->ctl
;
9327 size
= (height
<< 12) | width
;
9329 base
= intel_cursor_base(plane_state
);
9330 pos
= intel_cursor_position(plane_state
);
9333 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
9335 /* On these chipsets we can only modify the base/size/stride
9336 * whilst the cursor is disabled.
9338 if (plane
->cursor
.base
!= base
||
9339 plane
->cursor
.size
!= size
||
9340 plane
->cursor
.cntl
!= cntl
) {
9341 I915_WRITE_FW(CURCNTR(PIPE_A
), 0);
9342 I915_WRITE_FW(CURBASE(PIPE_A
), base
);
9343 I915_WRITE_FW(CURSIZE
, size
);
9344 I915_WRITE_FW(CURPOS(PIPE_A
), pos
);
9345 I915_WRITE_FW(CURCNTR(PIPE_A
), cntl
);
9347 plane
->cursor
.base
= base
;
9348 plane
->cursor
.size
= size
;
9349 plane
->cursor
.cntl
= cntl
;
9351 I915_WRITE_FW(CURPOS(PIPE_A
), pos
);
9354 POSTING_READ_FW(CURCNTR(PIPE_A
));
9356 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
9359 static void i845_disable_cursor(struct intel_plane
*plane
,
9360 struct intel_crtc
*crtc
)
9362 i845_update_cursor(plane
, NULL
, NULL
);
9365 static u32
i9xx_cursor_ctl(const struct intel_crtc_state
*crtc_state
,
9366 const struct intel_plane_state
*plane_state
)
9368 struct drm_i915_private
*dev_priv
=
9369 to_i915(plane_state
->base
.plane
->dev
);
9370 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
9373 cntl
= MCURSOR_GAMMA_ENABLE
;
9375 if (HAS_DDI(dev_priv
))
9376 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
9378 cntl
|= MCURSOR_PIPE_SELECT(crtc
->pipe
);
9380 switch (plane_state
->base
.crtc_w
) {
9382 cntl
|= CURSOR_MODE_64_ARGB_AX
;
9385 cntl
|= CURSOR_MODE_128_ARGB_AX
;
9388 cntl
|= CURSOR_MODE_256_ARGB_AX
;
9391 MISSING_CASE(plane_state
->base
.crtc_w
);
9395 if (plane_state
->base
.rotation
& DRM_MODE_ROTATE_180
)
9396 cntl
|= CURSOR_ROTATE_180
;
9401 static bool i9xx_cursor_size_ok(const struct intel_plane_state
*plane_state
)
9403 struct drm_i915_private
*dev_priv
=
9404 to_i915(plane_state
->base
.plane
->dev
);
9405 int width
= plane_state
->base
.crtc_w
;
9406 int height
= plane_state
->base
.crtc_h
;
9408 if (!intel_cursor_size_ok(plane_state
))
9411 /* Cursor width is limited to a few power-of-two sizes */
9422 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
9423 * height from 8 lines up to the cursor width, when the
9424 * cursor is not rotated. Everything else requires square
9427 if (HAS_CUR_FBC(dev_priv
) &&
9428 plane_state
->base
.rotation
& DRM_MODE_ROTATE_0
) {
9429 if (height
< 8 || height
> width
)
9432 if (height
!= width
)
9439 static int i9xx_check_cursor(struct intel_plane
*plane
,
9440 struct intel_crtc_state
*crtc_state
,
9441 struct intel_plane_state
*plane_state
)
9443 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
9444 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9445 enum pipe pipe
= plane
->pipe
;
9448 ret
= intel_check_cursor(crtc_state
, plane_state
);
9452 /* if we want to turn off the cursor ignore width and height */
9456 /* Check for which cursor types we support */
9457 if (!i9xx_cursor_size_ok(plane_state
)) {
9458 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9459 plane_state
->base
.crtc_w
,
9460 plane_state
->base
.crtc_h
);
9464 if (fb
->pitches
[0] != plane_state
->base
.crtc_w
* fb
->format
->cpp
[0]) {
9465 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
9466 fb
->pitches
[0], plane_state
->base
.crtc_w
);
9471 * There's something wrong with the cursor on CHV pipe C.
9472 * If it straddles the left edge of the screen then
9473 * moving it away from the edge or disabling it often
9474 * results in a pipe underrun, and often that can lead to
9475 * dead pipe (constant underrun reported, and it scans
9476 * out just a solid color). To recover from that, the
9477 * display power well must be turned off and on again.
9478 * Refuse the put the cursor into that compromised position.
9480 if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_C
&&
9481 plane_state
->base
.visible
&& plane_state
->base
.crtc_x
< 0) {
9482 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
9486 plane_state
->ctl
= i9xx_cursor_ctl(crtc_state
, plane_state
);
9491 static void i9xx_update_cursor(struct intel_plane
*plane
,
9492 const struct intel_crtc_state
*crtc_state
,
9493 const struct intel_plane_state
*plane_state
)
9495 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
9496 enum pipe pipe
= plane
->pipe
;
9497 u32 cntl
= 0, base
= 0, pos
= 0, fbc_ctl
= 0;
9498 unsigned long irqflags
;
9500 if (plane_state
&& plane_state
->base
.visible
) {
9501 cntl
= plane_state
->ctl
;
9503 if (plane_state
->base
.crtc_h
!= plane_state
->base
.crtc_w
)
9504 fbc_ctl
= CUR_FBC_CTL_EN
| (plane_state
->base
.crtc_h
- 1);
9506 base
= intel_cursor_base(plane_state
);
9507 pos
= intel_cursor_position(plane_state
);
9510 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
9513 * On some platforms writing CURCNTR first will also
9514 * cause CURPOS to be armed by the CURBASE write.
9515 * Without the CURCNTR write the CURPOS write would
9516 * arm itself. Thus we always start the full update
9517 * with a CURCNTR write.
9519 * On other platforms CURPOS always requires the
9520 * CURBASE write to arm the update. Additonally
9521 * a write to any of the cursor register will cancel
9522 * an already armed cursor update. Thus leaving out
9523 * the CURBASE write after CURPOS could lead to a
9524 * cursor that doesn't appear to move, or even change
9525 * shape. Thus we always write CURBASE.
9527 * CURCNTR and CUR_FBC_CTL are always
9528 * armed by the CURBASE write only.
9530 if (plane
->cursor
.base
!= base
||
9531 plane
->cursor
.size
!= fbc_ctl
||
9532 plane
->cursor
.cntl
!= cntl
) {
9533 I915_WRITE_FW(CURCNTR(pipe
), cntl
);
9534 if (HAS_CUR_FBC(dev_priv
))
9535 I915_WRITE_FW(CUR_FBC_CTL(pipe
), fbc_ctl
);
9536 I915_WRITE_FW(CURPOS(pipe
), pos
);
9537 I915_WRITE_FW(CURBASE(pipe
), base
);
9539 plane
->cursor
.base
= base
;
9540 plane
->cursor
.size
= fbc_ctl
;
9541 plane
->cursor
.cntl
= cntl
;
9543 I915_WRITE_FW(CURPOS(pipe
), pos
);
9544 I915_WRITE_FW(CURBASE(pipe
), base
);
9547 POSTING_READ_FW(CURBASE(pipe
));
9549 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
9552 static void i9xx_disable_cursor(struct intel_plane
*plane
,
9553 struct intel_crtc
*crtc
)
9555 i9xx_update_cursor(plane
, NULL
, NULL
);
9559 /* VESA 640x480x72Hz mode to set on the pipe */
9560 static struct drm_display_mode load_detect_mode
= {
9561 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
9562 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
9565 struct drm_framebuffer
*
9566 intel_framebuffer_create(struct drm_i915_gem_object
*obj
,
9567 struct drm_mode_fb_cmd2
*mode_cmd
)
9569 struct intel_framebuffer
*intel_fb
;
9572 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9574 return ERR_PTR(-ENOMEM
);
9576 ret
= intel_framebuffer_init(intel_fb
, obj
, mode_cmd
);
9580 return &intel_fb
->base
;
9584 return ERR_PTR(ret
);
9588 intel_framebuffer_pitch_for_width(int width
, int bpp
)
9590 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
9591 return ALIGN(pitch
, 64);
9595 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
9597 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
9598 return PAGE_ALIGN(pitch
* mode
->vdisplay
);
9601 static struct drm_framebuffer
*
9602 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
9603 struct drm_display_mode
*mode
,
9606 struct drm_framebuffer
*fb
;
9607 struct drm_i915_gem_object
*obj
;
9608 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
9610 obj
= i915_gem_object_create(to_i915(dev
),
9611 intel_framebuffer_size_for_mode(mode
, bpp
));
9613 return ERR_CAST(obj
);
9615 mode_cmd
.width
= mode
->hdisplay
;
9616 mode_cmd
.height
= mode
->vdisplay
;
9617 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
9619 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
9621 fb
= intel_framebuffer_create(obj
, &mode_cmd
);
9623 i915_gem_object_put(obj
);
9628 static struct drm_framebuffer
*
9629 mode_fits_in_fbdev(struct drm_device
*dev
,
9630 struct drm_display_mode
*mode
)
9632 #ifdef CONFIG_DRM_FBDEV_EMULATION
9633 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9634 struct drm_i915_gem_object
*obj
;
9635 struct drm_framebuffer
*fb
;
9637 if (!dev_priv
->fbdev
)
9640 if (!dev_priv
->fbdev
->fb
)
9643 obj
= dev_priv
->fbdev
->fb
->obj
;
9646 fb
= &dev_priv
->fbdev
->fb
->base
;
9647 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
9648 fb
->format
->cpp
[0] * 8))
9651 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
9654 drm_framebuffer_reference(fb
);
9661 static int intel_modeset_setup_plane_state(struct drm_atomic_state
*state
,
9662 struct drm_crtc
*crtc
,
9663 struct drm_display_mode
*mode
,
9664 struct drm_framebuffer
*fb
,
9667 struct drm_plane_state
*plane_state
;
9668 int hdisplay
, vdisplay
;
9671 plane_state
= drm_atomic_get_plane_state(state
, crtc
->primary
);
9672 if (IS_ERR(plane_state
))
9673 return PTR_ERR(plane_state
);
9676 drm_mode_get_hv_timing(mode
, &hdisplay
, &vdisplay
);
9678 hdisplay
= vdisplay
= 0;
9680 ret
= drm_atomic_set_crtc_for_plane(plane_state
, fb
? crtc
: NULL
);
9683 drm_atomic_set_fb_for_plane(plane_state
, fb
);
9684 plane_state
->crtc_x
= 0;
9685 plane_state
->crtc_y
= 0;
9686 plane_state
->crtc_w
= hdisplay
;
9687 plane_state
->crtc_h
= vdisplay
;
9688 plane_state
->src_x
= x
<< 16;
9689 plane_state
->src_y
= y
<< 16;
9690 plane_state
->src_w
= hdisplay
<< 16;
9691 plane_state
->src_h
= vdisplay
<< 16;
9696 int intel_get_load_detect_pipe(struct drm_connector
*connector
,
9697 struct drm_display_mode
*mode
,
9698 struct intel_load_detect_pipe
*old
,
9699 struct drm_modeset_acquire_ctx
*ctx
)
9701 struct intel_crtc
*intel_crtc
;
9702 struct intel_encoder
*intel_encoder
=
9703 intel_attached_encoder(connector
);
9704 struct drm_crtc
*possible_crtc
;
9705 struct drm_encoder
*encoder
= &intel_encoder
->base
;
9706 struct drm_crtc
*crtc
= NULL
;
9707 struct drm_device
*dev
= encoder
->dev
;
9708 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9709 struct drm_framebuffer
*fb
;
9710 struct drm_mode_config
*config
= &dev
->mode_config
;
9711 struct drm_atomic_state
*state
= NULL
, *restore_state
= NULL
;
9712 struct drm_connector_state
*connector_state
;
9713 struct intel_crtc_state
*crtc_state
;
9716 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9717 connector
->base
.id
, connector
->name
,
9718 encoder
->base
.id
, encoder
->name
);
9720 old
->restore_state
= NULL
;
9722 WARN_ON(!drm_modeset_is_locked(&config
->connection_mutex
));
9725 * Algorithm gets a little messy:
9727 * - if the connector already has an assigned crtc, use it (but make
9728 * sure it's on first)
9730 * - try to find the first unused crtc that can drive this connector,
9731 * and use that if we find one
9734 /* See if we already have a CRTC for this connector */
9735 if (connector
->state
->crtc
) {
9736 crtc
= connector
->state
->crtc
;
9738 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
9742 /* Make sure the crtc and connector are running */
9746 /* Find an unused one (if possible) */
9747 for_each_crtc(dev
, possible_crtc
) {
9749 if (!(encoder
->possible_crtcs
& (1 << i
)))
9752 ret
= drm_modeset_lock(&possible_crtc
->mutex
, ctx
);
9756 if (possible_crtc
->state
->enable
) {
9757 drm_modeset_unlock(&possible_crtc
->mutex
);
9761 crtc
= possible_crtc
;
9766 * If we didn't find an unused CRTC, don't use any.
9769 DRM_DEBUG_KMS("no pipe available for load-detect\n");
9775 intel_crtc
= to_intel_crtc(crtc
);
9777 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
9781 state
= drm_atomic_state_alloc(dev
);
9782 restore_state
= drm_atomic_state_alloc(dev
);
9783 if (!state
|| !restore_state
) {
9788 state
->acquire_ctx
= ctx
;
9789 restore_state
->acquire_ctx
= ctx
;
9791 connector_state
= drm_atomic_get_connector_state(state
, connector
);
9792 if (IS_ERR(connector_state
)) {
9793 ret
= PTR_ERR(connector_state
);
9797 ret
= drm_atomic_set_crtc_for_connector(connector_state
, crtc
);
9801 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
9802 if (IS_ERR(crtc_state
)) {
9803 ret
= PTR_ERR(crtc_state
);
9807 crtc_state
->base
.active
= crtc_state
->base
.enable
= true;
9810 mode
= &load_detect_mode
;
9812 /* We need a framebuffer large enough to accommodate all accesses
9813 * that the plane may generate whilst we perform load detection.
9814 * We can not rely on the fbcon either being present (we get called
9815 * during its initialisation to detect all boot displays, or it may
9816 * not even exist) or that it is large enough to satisfy the
9819 fb
= mode_fits_in_fbdev(dev
, mode
);
9821 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
9822 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
9824 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
9826 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
9831 ret
= intel_modeset_setup_plane_state(state
, crtc
, mode
, fb
, 0, 0);
9835 drm_framebuffer_unreference(fb
);
9837 ret
= drm_atomic_set_mode_for_crtc(&crtc_state
->base
, mode
);
9841 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state
, connector
));
9843 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state
, crtc
));
9845 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state
, crtc
->primary
));
9847 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret
);
9851 ret
= drm_atomic_commit(state
);
9853 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
9857 old
->restore_state
= restore_state
;
9858 drm_atomic_state_put(state
);
9860 /* let the connector get through one full cycle before testing */
9861 intel_wait_for_vblank(dev_priv
, intel_crtc
->pipe
);
9866 drm_atomic_state_put(state
);
9869 if (restore_state
) {
9870 drm_atomic_state_put(restore_state
);
9871 restore_state
= NULL
;
9874 if (ret
== -EDEADLK
)
9880 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
9881 struct intel_load_detect_pipe
*old
,
9882 struct drm_modeset_acquire_ctx
*ctx
)
9884 struct intel_encoder
*intel_encoder
=
9885 intel_attached_encoder(connector
);
9886 struct drm_encoder
*encoder
= &intel_encoder
->base
;
9887 struct drm_atomic_state
*state
= old
->restore_state
;
9890 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9891 connector
->base
.id
, connector
->name
,
9892 encoder
->base
.id
, encoder
->name
);
9897 ret
= drm_atomic_helper_commit_duplicated_state(state
, ctx
);
9899 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret
);
9900 drm_atomic_state_put(state
);
9903 static int i9xx_pll_refclk(struct drm_device
*dev
,
9904 const struct intel_crtc_state
*pipe_config
)
9906 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9907 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
9909 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
9910 return dev_priv
->vbt
.lvds_ssc_freq
;
9911 else if (HAS_PCH_SPLIT(dev_priv
))
9913 else if (!IS_GEN2(dev_priv
))
9919 /* Returns the clock of the currently programmed mode of the given pipe. */
9920 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
9921 struct intel_crtc_state
*pipe_config
)
9923 struct drm_device
*dev
= crtc
->base
.dev
;
9924 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9925 int pipe
= pipe_config
->cpu_transcoder
;
9926 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
9930 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
9932 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
9933 fp
= pipe_config
->dpll_hw_state
.fp0
;
9935 fp
= pipe_config
->dpll_hw_state
.fp1
;
9937 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
9938 if (IS_PINEVIEW(dev_priv
)) {
9939 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
9940 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
9942 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
9943 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
9946 if (!IS_GEN2(dev_priv
)) {
9947 if (IS_PINEVIEW(dev_priv
))
9948 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
9949 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
9951 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
9952 DPLL_FPA01_P1_POST_DIV_SHIFT
);
9954 switch (dpll
& DPLL_MODE_MASK
) {
9955 case DPLLB_MODE_DAC_SERIAL
:
9956 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
9959 case DPLLB_MODE_LVDS
:
9960 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
9964 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
9965 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
9969 if (IS_PINEVIEW(dev_priv
))
9970 port_clock
= pnv_calc_dpll_params(refclk
, &clock
);
9972 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
9974 u32 lvds
= IS_I830(dev_priv
) ? 0 : I915_READ(LVDS
);
9975 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
9978 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
9979 DPLL_FPA01_P1_POST_DIV_SHIFT
);
9981 if (lvds
& LVDS_CLKB_POWER_UP
)
9986 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
9989 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
9990 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
9992 if (dpll
& PLL_P2_DIVIDE_BY_4
)
9998 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
10002 * This value includes pixel_multiplier. We will use
10003 * port_clock to compute adjusted_mode.crtc_clock in the
10004 * encoder's get_config() function.
10006 pipe_config
->port_clock
= port_clock
;
10009 int intel_dotclock_calculate(int link_freq
,
10010 const struct intel_link_m_n
*m_n
)
10013 * The calculation for the data clock is:
10014 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10015 * But we want to avoid losing precison if possible, so:
10016 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10018 * and the link clock is simpler:
10019 * link_clock = (m * link_clock) / n
10025 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
10028 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
10029 struct intel_crtc_state
*pipe_config
)
10031 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
10033 /* read out port_clock from the DPLL */
10034 i9xx_crtc_clock_get(crtc
, pipe_config
);
10037 * In case there is an active pipe without active ports,
10038 * we may need some idea for the dotclock anyway.
10039 * Calculate one based on the FDI configuration.
10041 pipe_config
->base
.adjusted_mode
.crtc_clock
=
10042 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
10043 &pipe_config
->fdi_m_n
);
10046 /** Returns the currently programmed mode of the given pipe. */
10047 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
10048 struct drm_crtc
*crtc
)
10050 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10051 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10052 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
10053 struct drm_display_mode
*mode
;
10054 struct intel_crtc_state
*pipe_config
;
10055 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
10056 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
10057 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
10058 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
10059 enum pipe pipe
= intel_crtc
->pipe
;
10061 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
10065 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
10066 if (!pipe_config
) {
10072 * Construct a pipe_config sufficient for getting the clock info
10073 * back out of crtc_clock_get.
10075 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
10076 * to use a real value here instead.
10078 pipe_config
->cpu_transcoder
= (enum transcoder
) pipe
;
10079 pipe_config
->pixel_multiplier
= 1;
10080 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
10081 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
10082 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
10083 i9xx_crtc_clock_get(intel_crtc
, pipe_config
);
10085 mode
->clock
= pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
10086 mode
->hdisplay
= (htot
& 0xffff) + 1;
10087 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
10088 mode
->hsync_start
= (hsync
& 0xffff) + 1;
10089 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
10090 mode
->vdisplay
= (vtot
& 0xffff) + 1;
10091 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
10092 mode
->vsync_start
= (vsync
& 0xffff) + 1;
10093 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
10095 drm_mode_set_name(mode
);
10097 kfree(pipe_config
);
10102 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
10104 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10105 struct drm_device
*dev
= crtc
->dev
;
10106 struct intel_flip_work
*work
;
10108 spin_lock_irq(&dev
->event_lock
);
10109 work
= intel_crtc
->flip_work
;
10110 intel_crtc
->flip_work
= NULL
;
10111 spin_unlock_irq(&dev
->event_lock
);
10114 cancel_work_sync(&work
->mmio_work
);
10115 cancel_work_sync(&work
->unpin_work
);
10119 drm_crtc_cleanup(crtc
);
10124 /* Is 'a' after or equal to 'b'? */
10125 static bool g4x_flip_count_after_eq(u32 a
, u32 b
)
10127 return !((a
- b
) & 0x80000000);
10130 static bool __pageflip_finished_cs(struct intel_crtc
*crtc
,
10131 struct intel_flip_work
*work
)
10133 struct drm_device
*dev
= crtc
->base
.dev
;
10134 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10136 if (abort_flip_on_reset(crtc
))
10140 * The relevant registers doen't exist on pre-ctg.
10141 * As the flip done interrupt doesn't trigger for mmio
10142 * flips on gmch platforms, a flip count check isn't
10143 * really needed there. But since ctg has the registers,
10144 * include it in the check anyway.
10146 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
))
10150 * BDW signals flip done immediately if the plane
10151 * is disabled, even if the plane enable is already
10152 * armed to occur at the next vblank :(
10156 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
10157 * used the same base address. In that case the mmio flip might
10158 * have completed, but the CS hasn't even executed the flip yet.
10160 * A flip count check isn't enough as the CS might have updated
10161 * the base address just after start of vblank, but before we
10162 * managed to process the interrupt. This means we'd complete the
10163 * CS flip too soon.
10165 * Combining both checks should get us a good enough result. It may
10166 * still happen that the CS flip has been executed, but has not
10167 * yet actually completed. But in case the base address is the same
10168 * anyway, we don't really care.
10170 return (I915_READ(DSPSURFLIVE(crtc
->plane
)) & ~0xfff) ==
10171 crtc
->flip_work
->gtt_offset
&&
10172 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc
->pipe
)),
10173 crtc
->flip_work
->flip_count
);
10177 __pageflip_finished_mmio(struct intel_crtc
*crtc
,
10178 struct intel_flip_work
*work
)
10181 * MMIO work completes when vblank is different from
10182 * flip_queued_vblank.
10184 * Reset counter value doesn't matter, this is handled by
10185 * i915_wait_request finishing early, so no need to handle
10188 return intel_crtc_get_vblank_counter(crtc
) != work
->flip_queued_vblank
;
10192 static bool pageflip_finished(struct intel_crtc
*crtc
,
10193 struct intel_flip_work
*work
)
10195 if (!atomic_read(&work
->pending
))
10200 if (is_mmio_work(work
))
10201 return __pageflip_finished_mmio(crtc
, work
);
10203 return __pageflip_finished_cs(crtc
, work
);
10206 void intel_finish_page_flip_cs(struct drm_i915_private
*dev_priv
, int pipe
)
10208 struct drm_device
*dev
= &dev_priv
->drm
;
10209 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
10210 struct intel_flip_work
*work
;
10211 unsigned long flags
;
10213 /* Ignore early vblank irqs */
10218 * This is called both by irq handlers and the reset code (to complete
10219 * lost pageflips) so needs the full irqsave spinlocks.
10221 spin_lock_irqsave(&dev
->event_lock
, flags
);
10222 work
= crtc
->flip_work
;
10224 if (work
!= NULL
&&
10225 !is_mmio_work(work
) &&
10226 pageflip_finished(crtc
, work
))
10227 page_flip_completed(crtc
);
10229 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
10232 void intel_finish_page_flip_mmio(struct drm_i915_private
*dev_priv
, int pipe
)
10234 struct drm_device
*dev
= &dev_priv
->drm
;
10235 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
10236 struct intel_flip_work
*work
;
10237 unsigned long flags
;
10239 /* Ignore early vblank irqs */
10244 * This is called both by irq handlers and the reset code (to complete
10245 * lost pageflips) so needs the full irqsave spinlocks.
10247 spin_lock_irqsave(&dev
->event_lock
, flags
);
10248 work
= crtc
->flip_work
;
10250 if (work
!= NULL
&&
10251 is_mmio_work(work
) &&
10252 pageflip_finished(crtc
, work
))
10253 page_flip_completed(crtc
);
10255 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
10258 static inline void intel_mark_page_flip_active(struct intel_crtc
*crtc
,
10259 struct intel_flip_work
*work
)
10261 work
->flip_queued_vblank
= intel_crtc_get_vblank_counter(crtc
);
10263 /* Ensure that the work item is consistent when activating it ... */
10264 smp_mb__before_atomic();
10265 atomic_set(&work
->pending
, 1);
10268 static bool __pageflip_stall_check_cs(struct drm_i915_private
*dev_priv
,
10269 struct intel_crtc
*intel_crtc
,
10270 struct intel_flip_work
*work
)
10274 if (!atomic_read(&work
->pending
))
10279 vblank
= intel_crtc_get_vblank_counter(intel_crtc
);
10280 if (work
->flip_ready_vblank
== 0) {
10281 if (work
->flip_queued_req
&&
10282 !i915_gem_request_completed(work
->flip_queued_req
))
10285 work
->flip_ready_vblank
= vblank
;
10288 if (vblank
- work
->flip_ready_vblank
< 3)
10291 /* Potential stall - if we see that the flip has happened,
10292 * assume a missed interrupt. */
10293 if (INTEL_GEN(dev_priv
) >= 4)
10294 addr
= I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc
->plane
)));
10296 addr
= I915_READ(DSPADDR(intel_crtc
->plane
));
10298 /* There is a potential issue here with a false positive after a flip
10299 * to the same address. We could address this by checking for a
10300 * non-incrementing frame counter.
10302 return addr
== work
->gtt_offset
;
10305 void intel_check_page_flip(struct drm_i915_private
*dev_priv
, int pipe
)
10307 struct drm_device
*dev
= &dev_priv
->drm
;
10308 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
10309 struct intel_flip_work
*work
;
10311 WARN_ON(!in_interrupt());
10316 spin_lock(&dev
->event_lock
);
10317 work
= crtc
->flip_work
;
10319 if (work
!= NULL
&& !is_mmio_work(work
) &&
10320 __pageflip_stall_check_cs(dev_priv
, crtc
, work
)) {
10322 "Kicking stuck page flip: queued at %d, now %d\n",
10323 work
->flip_queued_vblank
, intel_crtc_get_vblank_counter(crtc
));
10324 page_flip_completed(crtc
);
10328 if (work
!= NULL
&& !is_mmio_work(work
) &&
10329 intel_crtc_get_vblank_counter(crtc
) - work
->flip_queued_vblank
> 1)
10330 intel_queue_rps_boost_for_request(work
->flip_queued_req
);
10331 spin_unlock(&dev
->event_lock
);
10335 * intel_wm_need_update - Check whether watermarks need updating
10336 * @plane: drm plane
10337 * @state: new plane state
10339 * Check current plane state versus the new one to determine whether
10340 * watermarks need to be recalculated.
10342 * Returns true or false.
10344 static bool intel_wm_need_update(struct drm_plane
*plane
,
10345 struct drm_plane_state
*state
)
10347 struct intel_plane_state
*new = to_intel_plane_state(state
);
10348 struct intel_plane_state
*cur
= to_intel_plane_state(plane
->state
);
10350 /* Update watermarks on tiling or size changes. */
10351 if (new->base
.visible
!= cur
->base
.visible
)
10354 if (!cur
->base
.fb
|| !new->base
.fb
)
10357 if (cur
->base
.fb
->modifier
!= new->base
.fb
->modifier
||
10358 cur
->base
.rotation
!= new->base
.rotation
||
10359 drm_rect_width(&new->base
.src
) != drm_rect_width(&cur
->base
.src
) ||
10360 drm_rect_height(&new->base
.src
) != drm_rect_height(&cur
->base
.src
) ||
10361 drm_rect_width(&new->base
.dst
) != drm_rect_width(&cur
->base
.dst
) ||
10362 drm_rect_height(&new->base
.dst
) != drm_rect_height(&cur
->base
.dst
))
10368 static bool needs_scaling(struct intel_plane_state
*state
)
10370 int src_w
= drm_rect_width(&state
->base
.src
) >> 16;
10371 int src_h
= drm_rect_height(&state
->base
.src
) >> 16;
10372 int dst_w
= drm_rect_width(&state
->base
.dst
);
10373 int dst_h
= drm_rect_height(&state
->base
.dst
);
10375 return (src_w
!= dst_w
|| src_h
!= dst_h
);
10378 int intel_plane_atomic_calc_changes(struct drm_crtc_state
*crtc_state
,
10379 struct drm_plane_state
*plane_state
)
10381 struct intel_crtc_state
*pipe_config
= to_intel_crtc_state(crtc_state
);
10382 struct drm_crtc
*crtc
= crtc_state
->crtc
;
10383 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10384 struct intel_plane
*plane
= to_intel_plane(plane_state
->plane
);
10385 struct drm_device
*dev
= crtc
->dev
;
10386 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10387 struct intel_plane_state
*old_plane_state
=
10388 to_intel_plane_state(plane
->base
.state
);
10389 bool mode_changed
= needs_modeset(crtc_state
);
10390 bool was_crtc_enabled
= crtc
->state
->active
;
10391 bool is_crtc_enabled
= crtc_state
->active
;
10392 bool turn_off
, turn_on
, visible
, was_visible
;
10393 struct drm_framebuffer
*fb
= plane_state
->fb
;
10396 if (INTEL_GEN(dev_priv
) >= 9 && plane
->id
!= PLANE_CURSOR
) {
10397 ret
= skl_update_scaler_plane(
10398 to_intel_crtc_state(crtc_state
),
10399 to_intel_plane_state(plane_state
));
10404 was_visible
= old_plane_state
->base
.visible
;
10405 visible
= plane_state
->visible
;
10407 if (!was_crtc_enabled
&& WARN_ON(was_visible
))
10408 was_visible
= false;
10411 * Visibility is calculated as if the crtc was on, but
10412 * after scaler setup everything depends on it being off
10413 * when the crtc isn't active.
10415 * FIXME this is wrong for watermarks. Watermarks should also
10416 * be computed as if the pipe would be active. Perhaps move
10417 * per-plane wm computation to the .check_plane() hook, and
10418 * only combine the results from all planes in the current place?
10420 if (!is_crtc_enabled
) {
10421 plane_state
->visible
= visible
= false;
10422 to_intel_crtc_state(crtc_state
)->active_planes
&= ~BIT(plane
->id
);
10425 if (!was_visible
&& !visible
)
10428 if (fb
!= old_plane_state
->base
.fb
)
10429 pipe_config
->fb_changed
= true;
10431 turn_off
= was_visible
&& (!visible
|| mode_changed
);
10432 turn_on
= visible
&& (!was_visible
|| mode_changed
);
10434 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
10435 intel_crtc
->base
.base
.id
, intel_crtc
->base
.name
,
10436 plane
->base
.base
.id
, plane
->base
.name
,
10437 fb
? fb
->base
.id
: -1);
10439 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
10440 plane
->base
.base
.id
, plane
->base
.name
,
10441 was_visible
, visible
,
10442 turn_off
, turn_on
, mode_changed
);
10445 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
))
10446 pipe_config
->update_wm_pre
= true;
10448 /* must disable cxsr around plane enable/disable */
10449 if (plane
->id
!= PLANE_CURSOR
)
10450 pipe_config
->disable_cxsr
= true;
10451 } else if (turn_off
) {
10452 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
))
10453 pipe_config
->update_wm_post
= true;
10455 /* must disable cxsr around plane enable/disable */
10456 if (plane
->id
!= PLANE_CURSOR
)
10457 pipe_config
->disable_cxsr
= true;
10458 } else if (intel_wm_need_update(&plane
->base
, plane_state
)) {
10459 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
)) {
10460 /* FIXME bollocks */
10461 pipe_config
->update_wm_pre
= true;
10462 pipe_config
->update_wm_post
= true;
10466 if (visible
|| was_visible
)
10467 pipe_config
->fb_bits
|= plane
->frontbuffer_bit
;
10470 * WaCxSRDisabledForSpriteScaling:ivb
10472 * cstate->update_wm was already set above, so this flag will
10473 * take effect when we commit and program watermarks.
10475 if (plane
->id
== PLANE_SPRITE0
&& IS_IVYBRIDGE(dev_priv
) &&
10476 needs_scaling(to_intel_plane_state(plane_state
)) &&
10477 !needs_scaling(old_plane_state
))
10478 pipe_config
->disable_lp_wm
= true;
10483 static bool encoders_cloneable(const struct intel_encoder
*a
,
10484 const struct intel_encoder
*b
)
10486 /* masks could be asymmetric, so check both ways */
10487 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
10488 b
->cloneable
& (1 << a
->type
));
10491 static bool check_single_encoder_cloning(struct drm_atomic_state
*state
,
10492 struct intel_crtc
*crtc
,
10493 struct intel_encoder
*encoder
)
10495 struct intel_encoder
*source_encoder
;
10496 struct drm_connector
*connector
;
10497 struct drm_connector_state
*connector_state
;
10500 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10501 if (connector_state
->crtc
!= &crtc
->base
)
10505 to_intel_encoder(connector_state
->best_encoder
);
10506 if (!encoders_cloneable(encoder
, source_encoder
))
10513 static int intel_crtc_atomic_check(struct drm_crtc
*crtc
,
10514 struct drm_crtc_state
*crtc_state
)
10516 struct drm_device
*dev
= crtc
->dev
;
10517 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10518 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10519 struct intel_crtc_state
*pipe_config
=
10520 to_intel_crtc_state(crtc_state
);
10521 struct drm_atomic_state
*state
= crtc_state
->state
;
10523 bool mode_changed
= needs_modeset(crtc_state
);
10525 if (mode_changed
&& !crtc_state
->active
)
10526 pipe_config
->update_wm_post
= true;
10528 if (mode_changed
&& crtc_state
->enable
&&
10529 dev_priv
->display
.crtc_compute_clock
&&
10530 !WARN_ON(pipe_config
->shared_dpll
)) {
10531 ret
= dev_priv
->display
.crtc_compute_clock(intel_crtc
,
10537 if (crtc_state
->color_mgmt_changed
) {
10538 ret
= intel_color_check(crtc
, crtc_state
);
10543 * Changing color management on Intel hardware is
10544 * handled as part of planes update.
10546 crtc_state
->planes_changed
= true;
10550 if (dev_priv
->display
.compute_pipe_wm
) {
10551 ret
= dev_priv
->display
.compute_pipe_wm(pipe_config
);
10553 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
10558 if (dev_priv
->display
.compute_intermediate_wm
&&
10559 !to_intel_atomic_state(state
)->skip_intermediate_wm
) {
10560 if (WARN_ON(!dev_priv
->display
.compute_pipe_wm
))
10564 * Calculate 'intermediate' watermarks that satisfy both the
10565 * old state and the new state. We can program these
10568 ret
= dev_priv
->display
.compute_intermediate_wm(dev
,
10572 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
10575 } else if (dev_priv
->display
.compute_intermediate_wm
) {
10576 if (HAS_PCH_SPLIT(dev_priv
) && INTEL_GEN(dev_priv
) < 9)
10577 pipe_config
->wm
.ilk
.intermediate
= pipe_config
->wm
.ilk
.optimal
;
10580 if (INTEL_GEN(dev_priv
) >= 9) {
10582 ret
= skl_update_scaler_crtc(pipe_config
);
10585 ret
= skl_check_pipe_max_pixel_rate(intel_crtc
,
10588 ret
= intel_atomic_setup_scalers(dev_priv
, intel_crtc
,
10595 static const struct drm_crtc_helper_funcs intel_helper_funcs
= {
10596 .atomic_begin
= intel_begin_crtc_commit
,
10597 .atomic_flush
= intel_finish_crtc_commit
,
10598 .atomic_check
= intel_crtc_atomic_check
,
10601 static void intel_modeset_update_connector_atomic_state(struct drm_device
*dev
)
10603 struct intel_connector
*connector
;
10604 struct drm_connector_list_iter conn_iter
;
10606 drm_connector_list_iter_begin(dev
, &conn_iter
);
10607 for_each_intel_connector_iter(connector
, &conn_iter
) {
10608 if (connector
->base
.state
->crtc
)
10609 drm_connector_unreference(&connector
->base
);
10611 if (connector
->base
.encoder
) {
10612 connector
->base
.state
->best_encoder
=
10613 connector
->base
.encoder
;
10614 connector
->base
.state
->crtc
=
10615 connector
->base
.encoder
->crtc
;
10617 drm_connector_reference(&connector
->base
);
10619 connector
->base
.state
->best_encoder
= NULL
;
10620 connector
->base
.state
->crtc
= NULL
;
10623 drm_connector_list_iter_end(&conn_iter
);
10627 connected_sink_compute_bpp(struct intel_connector
*connector
,
10628 struct intel_crtc_state
*pipe_config
)
10630 const struct drm_display_info
*info
= &connector
->base
.display_info
;
10631 int bpp
= pipe_config
->pipe_bpp
;
10633 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
10634 connector
->base
.base
.id
,
10635 connector
->base
.name
);
10637 /* Don't use an invalid EDID bpc value */
10638 if (info
->bpc
!= 0 && info
->bpc
* 3 < bpp
) {
10639 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
10640 bpp
, info
->bpc
* 3);
10641 pipe_config
->pipe_bpp
= info
->bpc
* 3;
10644 /* Clamp bpp to 8 on screens without EDID 1.4 */
10645 if (info
->bpc
== 0 && bpp
> 24) {
10646 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
10648 pipe_config
->pipe_bpp
= 24;
10653 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
10654 struct intel_crtc_state
*pipe_config
)
10656 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
10657 struct drm_atomic_state
*state
;
10658 struct drm_connector
*connector
;
10659 struct drm_connector_state
*connector_state
;
10662 if ((IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
10663 IS_CHERRYVIEW(dev_priv
)))
10665 else if (INTEL_GEN(dev_priv
) >= 5)
10671 pipe_config
->pipe_bpp
= bpp
;
10673 state
= pipe_config
->base
.state
;
10675 /* Clamp display bpp to EDID value */
10676 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10677 if (connector_state
->crtc
!= &crtc
->base
)
10680 connected_sink_compute_bpp(to_intel_connector(connector
),
10687 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
10689 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
10690 "type: 0x%x flags: 0x%x\n",
10692 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
10693 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
10694 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
10695 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
10699 intel_dump_m_n_config(struct intel_crtc_state
*pipe_config
, char *id
,
10700 unsigned int lane_count
, struct intel_link_m_n
*m_n
)
10702 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10704 m_n
->gmch_m
, m_n
->gmch_n
,
10705 m_n
->link_m
, m_n
->link_n
, m_n
->tu
);
10708 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
10709 struct intel_crtc_state
*pipe_config
,
10710 const char *context
)
10712 struct drm_device
*dev
= crtc
->base
.dev
;
10713 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10714 struct drm_plane
*plane
;
10715 struct intel_plane
*intel_plane
;
10716 struct intel_plane_state
*state
;
10717 struct drm_framebuffer
*fb
;
10719 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
10720 crtc
->base
.base
.id
, crtc
->base
.name
, context
);
10722 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
10723 transcoder_name(pipe_config
->cpu_transcoder
),
10724 pipe_config
->pipe_bpp
, pipe_config
->dither
);
10726 if (pipe_config
->has_pch_encoder
)
10727 intel_dump_m_n_config(pipe_config
, "fdi",
10728 pipe_config
->fdi_lanes
,
10729 &pipe_config
->fdi_m_n
);
10731 if (intel_crtc_has_dp_encoder(pipe_config
)) {
10732 intel_dump_m_n_config(pipe_config
, "dp m_n",
10733 pipe_config
->lane_count
, &pipe_config
->dp_m_n
);
10734 if (pipe_config
->has_drrs
)
10735 intel_dump_m_n_config(pipe_config
, "dp m2_n2",
10736 pipe_config
->lane_count
,
10737 &pipe_config
->dp_m2_n2
);
10740 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
10741 pipe_config
->has_audio
, pipe_config
->has_infoframe
);
10743 DRM_DEBUG_KMS("requested mode:\n");
10744 drm_mode_debug_printmodeline(&pipe_config
->base
.mode
);
10745 DRM_DEBUG_KMS("adjusted mode:\n");
10746 drm_mode_debug_printmodeline(&pipe_config
->base
.adjusted_mode
);
10747 intel_dump_crtc_timings(&pipe_config
->base
.adjusted_mode
);
10748 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
10749 pipe_config
->port_clock
,
10750 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
,
10751 pipe_config
->pixel_rate
);
10753 if (INTEL_GEN(dev_priv
) >= 9)
10754 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
10756 pipe_config
->scaler_state
.scaler_users
,
10757 pipe_config
->scaler_state
.scaler_id
);
10759 if (HAS_GMCH_DISPLAY(dev_priv
))
10760 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
10761 pipe_config
->gmch_pfit
.control
,
10762 pipe_config
->gmch_pfit
.pgm_ratios
,
10763 pipe_config
->gmch_pfit
.lvds_border_bits
);
10765 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
10766 pipe_config
->pch_pfit
.pos
,
10767 pipe_config
->pch_pfit
.size
,
10768 enableddisabled(pipe_config
->pch_pfit
.enabled
));
10770 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
10771 pipe_config
->ips_enabled
, pipe_config
->double_wide
);
10773 intel_dpll_dump_hw_state(dev_priv
, &pipe_config
->dpll_hw_state
);
10775 DRM_DEBUG_KMS("planes on this crtc\n");
10776 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
10777 struct drm_format_name_buf format_name
;
10778 intel_plane
= to_intel_plane(plane
);
10779 if (intel_plane
->pipe
!= crtc
->pipe
)
10782 state
= to_intel_plane_state(plane
->state
);
10783 fb
= state
->base
.fb
;
10785 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
10786 plane
->base
.id
, plane
->name
, state
->scaler_id
);
10790 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
10791 plane
->base
.id
, plane
->name
,
10792 fb
->base
.id
, fb
->width
, fb
->height
,
10793 drm_get_format_name(fb
->format
->format
, &format_name
));
10794 if (INTEL_GEN(dev_priv
) >= 9)
10795 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
10797 state
->base
.src
.x1
>> 16,
10798 state
->base
.src
.y1
>> 16,
10799 drm_rect_width(&state
->base
.src
) >> 16,
10800 drm_rect_height(&state
->base
.src
) >> 16,
10801 state
->base
.dst
.x1
, state
->base
.dst
.y1
,
10802 drm_rect_width(&state
->base
.dst
),
10803 drm_rect_height(&state
->base
.dst
));
10807 static bool check_digital_port_conflicts(struct drm_atomic_state
*state
)
10809 struct drm_device
*dev
= state
->dev
;
10810 struct drm_connector
*connector
;
10811 struct drm_connector_list_iter conn_iter
;
10812 unsigned int used_ports
= 0;
10813 unsigned int used_mst_ports
= 0;
10816 * Walk the connector list instead of the encoder
10817 * list to detect the problem on ddi platforms
10818 * where there's just one encoder per digital port.
10820 drm_connector_list_iter_begin(dev
, &conn_iter
);
10821 drm_for_each_connector_iter(connector
, &conn_iter
) {
10822 struct drm_connector_state
*connector_state
;
10823 struct intel_encoder
*encoder
;
10825 connector_state
= drm_atomic_get_existing_connector_state(state
, connector
);
10826 if (!connector_state
)
10827 connector_state
= connector
->state
;
10829 if (!connector_state
->best_encoder
)
10832 encoder
= to_intel_encoder(connector_state
->best_encoder
);
10834 WARN_ON(!connector_state
->crtc
);
10836 switch (encoder
->type
) {
10837 unsigned int port_mask
;
10838 case INTEL_OUTPUT_UNKNOWN
:
10839 if (WARN_ON(!HAS_DDI(to_i915(dev
))))
10841 case INTEL_OUTPUT_DP
:
10842 case INTEL_OUTPUT_HDMI
:
10843 case INTEL_OUTPUT_EDP
:
10844 port_mask
= 1 << enc_to_dig_port(&encoder
->base
)->port
;
10846 /* the same port mustn't appear more than once */
10847 if (used_ports
& port_mask
)
10850 used_ports
|= port_mask
;
10852 case INTEL_OUTPUT_DP_MST
:
10854 1 << enc_to_mst(&encoder
->base
)->primary
->port
;
10860 drm_connector_list_iter_end(&conn_iter
);
10862 /* can't mix MST and SST/HDMI on the same port */
10863 if (used_ports
& used_mst_ports
)
10870 clear_intel_crtc_state(struct intel_crtc_state
*crtc_state
)
10872 struct drm_i915_private
*dev_priv
=
10873 to_i915(crtc_state
->base
.crtc
->dev
);
10874 struct intel_crtc_scaler_state scaler_state
;
10875 struct intel_dpll_hw_state dpll_hw_state
;
10876 struct intel_shared_dpll
*shared_dpll
;
10877 struct intel_crtc_wm_state wm_state
;
10880 /* FIXME: before the switch to atomic started, a new pipe_config was
10881 * kzalloc'd. Code that depends on any field being zero should be
10882 * fixed, so that the crtc_state can be safely duplicated. For now,
10883 * only fields that are know to not cause problems are preserved. */
10885 scaler_state
= crtc_state
->scaler_state
;
10886 shared_dpll
= crtc_state
->shared_dpll
;
10887 dpll_hw_state
= crtc_state
->dpll_hw_state
;
10888 force_thru
= crtc_state
->pch_pfit
.force_thru
;
10889 if (IS_G4X(dev_priv
) ||
10890 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
10891 wm_state
= crtc_state
->wm
;
10893 /* Keep base drm_crtc_state intact, only clear our extended struct */
10894 BUILD_BUG_ON(offsetof(struct intel_crtc_state
, base
));
10895 memset(&crtc_state
->base
+ 1, 0,
10896 sizeof(*crtc_state
) - sizeof(crtc_state
->base
));
10898 crtc_state
->scaler_state
= scaler_state
;
10899 crtc_state
->shared_dpll
= shared_dpll
;
10900 crtc_state
->dpll_hw_state
= dpll_hw_state
;
10901 crtc_state
->pch_pfit
.force_thru
= force_thru
;
10902 if (IS_G4X(dev_priv
) ||
10903 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
10904 crtc_state
->wm
= wm_state
;
10908 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
10909 struct intel_crtc_state
*pipe_config
)
10911 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
10912 struct intel_encoder
*encoder
;
10913 struct drm_connector
*connector
;
10914 struct drm_connector_state
*connector_state
;
10915 int base_bpp
, ret
= -EINVAL
;
10919 clear_intel_crtc_state(pipe_config
);
10921 pipe_config
->cpu_transcoder
=
10922 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
10925 * Sanitize sync polarity flags based on requested ones. If neither
10926 * positive or negative polarity is requested, treat this as meaning
10927 * negative polarity.
10929 if (!(pipe_config
->base
.adjusted_mode
.flags
&
10930 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
10931 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
10933 if (!(pipe_config
->base
.adjusted_mode
.flags
&
10934 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
10935 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
10937 base_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
10943 * Determine the real pipe dimensions. Note that stereo modes can
10944 * increase the actual pipe size due to the frame doubling and
10945 * insertion of additional space for blanks between the frame. This
10946 * is stored in the crtc timings. We use the requested mode to do this
10947 * computation to clearly distinguish it from the adjusted mode, which
10948 * can be changed by the connectors in the below retry loop.
10950 drm_mode_get_hv_timing(&pipe_config
->base
.mode
,
10951 &pipe_config
->pipe_src_w
,
10952 &pipe_config
->pipe_src_h
);
10954 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10955 if (connector_state
->crtc
!= crtc
)
10958 encoder
= to_intel_encoder(connector_state
->best_encoder
);
10960 if (!check_single_encoder_cloning(state
, to_intel_crtc(crtc
), encoder
)) {
10961 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
10966 * Determine output_types before calling the .compute_config()
10967 * hooks so that the hooks can use this information safely.
10969 pipe_config
->output_types
|= 1 << encoder
->type
;
10973 /* Ensure the port clock defaults are reset when retrying. */
10974 pipe_config
->port_clock
= 0;
10975 pipe_config
->pixel_multiplier
= 1;
10977 /* Fill in default crtc timings, allow encoders to overwrite them. */
10978 drm_mode_set_crtcinfo(&pipe_config
->base
.adjusted_mode
,
10979 CRTC_STEREO_DOUBLE
);
10981 /* Pass our mode to the connectors and the CRTC to give them a chance to
10982 * adjust it according to limitations or connector properties, and also
10983 * a chance to reject the mode entirely.
10985 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10986 if (connector_state
->crtc
!= crtc
)
10989 encoder
= to_intel_encoder(connector_state
->best_encoder
);
10991 if (!(encoder
->compute_config(encoder
, pipe_config
, connector_state
))) {
10992 DRM_DEBUG_KMS("Encoder config failure\n");
10997 /* Set default port clock if not overwritten by the encoder. Needs to be
10998 * done afterwards in case the encoder adjusts the mode. */
10999 if (!pipe_config
->port_clock
)
11000 pipe_config
->port_clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
11001 * pipe_config
->pixel_multiplier
;
11003 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
11005 DRM_DEBUG_KMS("CRTC fixup failed\n");
11009 if (ret
== RETRY
) {
11010 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
11015 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11017 goto encoder_retry
;
11020 /* Dithering seems to not pass-through bits correctly when it should, so
11021 * only enable it on 6bpc panels and when its not a compliance
11022 * test requesting 6bpc video pattern.
11024 pipe_config
->dither
= (pipe_config
->pipe_bpp
== 6*3) &&
11025 !pipe_config
->dither_force_disable
;
11026 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
11027 base_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
11034 intel_modeset_update_crtc_state(struct drm_atomic_state
*state
)
11036 struct drm_crtc
*crtc
;
11037 struct drm_crtc_state
*new_crtc_state
;
11040 /* Double check state. */
11041 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
11042 to_intel_crtc(crtc
)->config
= to_intel_crtc_state(new_crtc_state
);
11045 * Update legacy state to satisfy fbc code. This can
11046 * be removed when fbc uses the atomic state.
11048 if (drm_atomic_get_existing_plane_state(state
, crtc
->primary
)) {
11049 struct drm_plane_state
*plane_state
= crtc
->primary
->state
;
11051 crtc
->primary
->fb
= plane_state
->fb
;
11052 crtc
->x
= plane_state
->src_x
>> 16;
11053 crtc
->y
= plane_state
->src_y
>> 16;
11058 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
11062 if (clock1
== clock2
)
11065 if (!clock1
|| !clock2
)
11068 diff
= abs(clock1
- clock2
);
11070 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
11077 intel_compare_m_n(unsigned int m
, unsigned int n
,
11078 unsigned int m2
, unsigned int n2
,
11081 if (m
== m2
&& n
== n2
)
11084 if (exact
|| !m
|| !n
|| !m2
|| !n2
)
11087 BUILD_BUG_ON(DATA_LINK_M_N_MASK
> INT_MAX
);
11094 } else if (n
< n2
) {
11104 return intel_fuzzy_clock_check(m
, m2
);
11108 intel_compare_link_m_n(const struct intel_link_m_n
*m_n
,
11109 struct intel_link_m_n
*m2_n2
,
11112 if (m_n
->tu
== m2_n2
->tu
&&
11113 intel_compare_m_n(m_n
->gmch_m
, m_n
->gmch_n
,
11114 m2_n2
->gmch_m
, m2_n2
->gmch_n
, !adjust
) &&
11115 intel_compare_m_n(m_n
->link_m
, m_n
->link_n
,
11116 m2_n2
->link_m
, m2_n2
->link_n
, !adjust
)) {
11126 static void __printf(3, 4)
11127 pipe_config_err(bool adjust
, const char *name
, const char *format
, ...)
11130 unsigned int category
;
11131 struct va_format vaf
;
11135 level
= KERN_DEBUG
;
11136 category
= DRM_UT_KMS
;
11139 category
= DRM_UT_NONE
;
11142 va_start(args
, format
);
11146 drm_printk(level
, category
, "mismatch in %s %pV", name
, &vaf
);
11152 intel_pipe_config_compare(struct drm_i915_private
*dev_priv
,
11153 struct intel_crtc_state
*current_config
,
11154 struct intel_crtc_state
*pipe_config
,
11159 #define PIPE_CONF_CHECK_X(name) \
11160 if (current_config->name != pipe_config->name) { \
11161 pipe_config_err(adjust, __stringify(name), \
11162 "(expected 0x%08x, found 0x%08x)\n", \
11163 current_config->name, \
11164 pipe_config->name); \
11168 #define PIPE_CONF_CHECK_I(name) \
11169 if (current_config->name != pipe_config->name) { \
11170 pipe_config_err(adjust, __stringify(name), \
11171 "(expected %i, found %i)\n", \
11172 current_config->name, \
11173 pipe_config->name); \
11177 #define PIPE_CONF_CHECK_P(name) \
11178 if (current_config->name != pipe_config->name) { \
11179 pipe_config_err(adjust, __stringify(name), \
11180 "(expected %p, found %p)\n", \
11181 current_config->name, \
11182 pipe_config->name); \
11186 #define PIPE_CONF_CHECK_M_N(name) \
11187 if (!intel_compare_link_m_n(¤t_config->name, \
11188 &pipe_config->name,\
11190 pipe_config_err(adjust, __stringify(name), \
11191 "(expected tu %i gmch %i/%i link %i/%i, " \
11192 "found tu %i, gmch %i/%i link %i/%i)\n", \
11193 current_config->name.tu, \
11194 current_config->name.gmch_m, \
11195 current_config->name.gmch_n, \
11196 current_config->name.link_m, \
11197 current_config->name.link_n, \
11198 pipe_config->name.tu, \
11199 pipe_config->name.gmch_m, \
11200 pipe_config->name.gmch_n, \
11201 pipe_config->name.link_m, \
11202 pipe_config->name.link_n); \
11206 /* This is required for BDW+ where there is only one set of registers for
11207 * switching between high and low RR.
11208 * This macro can be used whenever a comparison has to be made between one
11209 * hw state and multiple sw state variables.
11211 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \
11212 if (!intel_compare_link_m_n(¤t_config->name, \
11213 &pipe_config->name, adjust) && \
11214 !intel_compare_link_m_n(¤t_config->alt_name, \
11215 &pipe_config->name, adjust)) { \
11216 pipe_config_err(adjust, __stringify(name), \
11217 "(expected tu %i gmch %i/%i link %i/%i, " \
11218 "or tu %i gmch %i/%i link %i/%i, " \
11219 "found tu %i, gmch %i/%i link %i/%i)\n", \
11220 current_config->name.tu, \
11221 current_config->name.gmch_m, \
11222 current_config->name.gmch_n, \
11223 current_config->name.link_m, \
11224 current_config->name.link_n, \
11225 current_config->alt_name.tu, \
11226 current_config->alt_name.gmch_m, \
11227 current_config->alt_name.gmch_n, \
11228 current_config->alt_name.link_m, \
11229 current_config->alt_name.link_n, \
11230 pipe_config->name.tu, \
11231 pipe_config->name.gmch_m, \
11232 pipe_config->name.gmch_n, \
11233 pipe_config->name.link_m, \
11234 pipe_config->name.link_n); \
11238 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
11239 if ((current_config->name ^ pipe_config->name) & (mask)) { \
11240 pipe_config_err(adjust, __stringify(name), \
11241 "(%x) (expected %i, found %i)\n", \
11243 current_config->name & (mask), \
11244 pipe_config->name & (mask)); \
11248 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
11249 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
11250 pipe_config_err(adjust, __stringify(name), \
11251 "(expected %i, found %i)\n", \
11252 current_config->name, \
11253 pipe_config->name); \
11257 #define PIPE_CONF_QUIRK(quirk) \
11258 ((current_config->quirks | pipe_config->quirks) & (quirk))
11260 PIPE_CONF_CHECK_I(cpu_transcoder
);
11262 PIPE_CONF_CHECK_I(has_pch_encoder
);
11263 PIPE_CONF_CHECK_I(fdi_lanes
);
11264 PIPE_CONF_CHECK_M_N(fdi_m_n
);
11266 PIPE_CONF_CHECK_I(lane_count
);
11267 PIPE_CONF_CHECK_X(lane_lat_optim_mask
);
11269 if (INTEL_GEN(dev_priv
) < 8) {
11270 PIPE_CONF_CHECK_M_N(dp_m_n
);
11272 if (current_config
->has_drrs
)
11273 PIPE_CONF_CHECK_M_N(dp_m2_n2
);
11275 PIPE_CONF_CHECK_M_N_ALT(dp_m_n
, dp_m2_n2
);
11277 PIPE_CONF_CHECK_X(output_types
);
11279 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hdisplay
);
11280 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_htotal
);
11281 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_start
);
11282 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_end
);
11283 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_start
);
11284 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_end
);
11286 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vdisplay
);
11287 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vtotal
);
11288 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_start
);
11289 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_end
);
11290 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_start
);
11291 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_end
);
11293 PIPE_CONF_CHECK_I(pixel_multiplier
);
11294 PIPE_CONF_CHECK_I(has_hdmi_sink
);
11295 if ((INTEL_GEN(dev_priv
) < 8 && !IS_HASWELL(dev_priv
)) ||
11296 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
11297 PIPE_CONF_CHECK_I(limited_color_range
);
11299 PIPE_CONF_CHECK_I(hdmi_scrambling
);
11300 PIPE_CONF_CHECK_I(hdmi_high_tmds_clock_ratio
);
11301 PIPE_CONF_CHECK_I(has_infoframe
);
11303 PIPE_CONF_CHECK_I(has_audio
);
11305 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11306 DRM_MODE_FLAG_INTERLACE
);
11308 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
11309 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11310 DRM_MODE_FLAG_PHSYNC
);
11311 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11312 DRM_MODE_FLAG_NHSYNC
);
11313 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11314 DRM_MODE_FLAG_PVSYNC
);
11315 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11316 DRM_MODE_FLAG_NVSYNC
);
11319 PIPE_CONF_CHECK_X(gmch_pfit
.control
);
11320 /* pfit ratios are autocomputed by the hw on gen4+ */
11321 if (INTEL_GEN(dev_priv
) < 4)
11322 PIPE_CONF_CHECK_X(gmch_pfit
.pgm_ratios
);
11323 PIPE_CONF_CHECK_X(gmch_pfit
.lvds_border_bits
);
11326 PIPE_CONF_CHECK_I(pipe_src_w
);
11327 PIPE_CONF_CHECK_I(pipe_src_h
);
11329 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
11330 if (current_config
->pch_pfit
.enabled
) {
11331 PIPE_CONF_CHECK_X(pch_pfit
.pos
);
11332 PIPE_CONF_CHECK_X(pch_pfit
.size
);
11335 PIPE_CONF_CHECK_I(scaler_state
.scaler_id
);
11336 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate
);
11339 /* BDW+ don't expose a synchronous way to read the state */
11340 if (IS_HASWELL(dev_priv
))
11341 PIPE_CONF_CHECK_I(ips_enabled
);
11343 PIPE_CONF_CHECK_I(double_wide
);
11345 PIPE_CONF_CHECK_P(shared_dpll
);
11346 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
11347 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
11348 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
11349 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
11350 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
11351 PIPE_CONF_CHECK_X(dpll_hw_state
.spll
);
11352 PIPE_CONF_CHECK_X(dpll_hw_state
.ctrl1
);
11353 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr1
);
11354 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr2
);
11356 PIPE_CONF_CHECK_X(dsi_pll
.ctrl
);
11357 PIPE_CONF_CHECK_X(dsi_pll
.div
);
11359 if (IS_G4X(dev_priv
) || INTEL_GEN(dev_priv
) >= 5)
11360 PIPE_CONF_CHECK_I(pipe_bpp
);
11362 PIPE_CONF_CHECK_CLOCK_FUZZY(base
.adjusted_mode
.crtc_clock
);
11363 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
11365 #undef PIPE_CONF_CHECK_X
11366 #undef PIPE_CONF_CHECK_I
11367 #undef PIPE_CONF_CHECK_P
11368 #undef PIPE_CONF_CHECK_FLAGS
11369 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
11370 #undef PIPE_CONF_QUIRK
11375 static void intel_pipe_config_sanity_check(struct drm_i915_private
*dev_priv
,
11376 const struct intel_crtc_state
*pipe_config
)
11378 if (pipe_config
->has_pch_encoder
) {
11379 int fdi_dotclock
= intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
11380 &pipe_config
->fdi_m_n
);
11381 int dotclock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
11384 * FDI already provided one idea for the dotclock.
11385 * Yell if the encoder disagrees.
11387 WARN(!intel_fuzzy_clock_check(fdi_dotclock
, dotclock
),
11388 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11389 fdi_dotclock
, dotclock
);
11393 static void verify_wm_state(struct drm_crtc
*crtc
,
11394 struct drm_crtc_state
*new_state
)
11396 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
11397 struct skl_ddb_allocation hw_ddb
, *sw_ddb
;
11398 struct skl_pipe_wm hw_wm
, *sw_wm
;
11399 struct skl_plane_wm
*hw_plane_wm
, *sw_plane_wm
;
11400 struct skl_ddb_entry
*hw_ddb_entry
, *sw_ddb_entry
;
11401 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11402 const enum pipe pipe
= intel_crtc
->pipe
;
11403 int plane
, level
, max_level
= ilk_wm_max_level(dev_priv
);
11405 if (INTEL_GEN(dev_priv
) < 9 || !new_state
->active
)
11408 skl_pipe_wm_get_hw_state(crtc
, &hw_wm
);
11409 sw_wm
= &to_intel_crtc_state(new_state
)->wm
.skl
.optimal
;
11411 skl_ddb_get_hw_state(dev_priv
, &hw_ddb
);
11412 sw_ddb
= &dev_priv
->wm
.skl_hw
.ddb
;
11415 for_each_universal_plane(dev_priv
, pipe
, plane
) {
11416 hw_plane_wm
= &hw_wm
.planes
[plane
];
11417 sw_plane_wm
= &sw_wm
->planes
[plane
];
11420 for (level
= 0; level
<= max_level
; level
++) {
11421 if (skl_wm_level_equals(&hw_plane_wm
->wm
[level
],
11422 &sw_plane_wm
->wm
[level
]))
11425 DRM_ERROR("mismatch in WM pipe %c plane %d level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11426 pipe_name(pipe
), plane
+ 1, level
,
11427 sw_plane_wm
->wm
[level
].plane_en
,
11428 sw_plane_wm
->wm
[level
].plane_res_b
,
11429 sw_plane_wm
->wm
[level
].plane_res_l
,
11430 hw_plane_wm
->wm
[level
].plane_en
,
11431 hw_plane_wm
->wm
[level
].plane_res_b
,
11432 hw_plane_wm
->wm
[level
].plane_res_l
);
11435 if (!skl_wm_level_equals(&hw_plane_wm
->trans_wm
,
11436 &sw_plane_wm
->trans_wm
)) {
11437 DRM_ERROR("mismatch in trans WM pipe %c plane %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11438 pipe_name(pipe
), plane
+ 1,
11439 sw_plane_wm
->trans_wm
.plane_en
,
11440 sw_plane_wm
->trans_wm
.plane_res_b
,
11441 sw_plane_wm
->trans_wm
.plane_res_l
,
11442 hw_plane_wm
->trans_wm
.plane_en
,
11443 hw_plane_wm
->trans_wm
.plane_res_b
,
11444 hw_plane_wm
->trans_wm
.plane_res_l
);
11448 hw_ddb_entry
= &hw_ddb
.plane
[pipe
][plane
];
11449 sw_ddb_entry
= &sw_ddb
->plane
[pipe
][plane
];
11451 if (!skl_ddb_entry_equal(hw_ddb_entry
, sw_ddb_entry
)) {
11452 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
11453 pipe_name(pipe
), plane
+ 1,
11454 sw_ddb_entry
->start
, sw_ddb_entry
->end
,
11455 hw_ddb_entry
->start
, hw_ddb_entry
->end
);
11461 * If the cursor plane isn't active, we may not have updated it's ddb
11462 * allocation. In that case since the ddb allocation will be updated
11463 * once the plane becomes visible, we can skip this check
11466 hw_plane_wm
= &hw_wm
.planes
[PLANE_CURSOR
];
11467 sw_plane_wm
= &sw_wm
->planes
[PLANE_CURSOR
];
11470 for (level
= 0; level
<= max_level
; level
++) {
11471 if (skl_wm_level_equals(&hw_plane_wm
->wm
[level
],
11472 &sw_plane_wm
->wm
[level
]))
11475 DRM_ERROR("mismatch in WM pipe %c cursor level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11476 pipe_name(pipe
), level
,
11477 sw_plane_wm
->wm
[level
].plane_en
,
11478 sw_plane_wm
->wm
[level
].plane_res_b
,
11479 sw_plane_wm
->wm
[level
].plane_res_l
,
11480 hw_plane_wm
->wm
[level
].plane_en
,
11481 hw_plane_wm
->wm
[level
].plane_res_b
,
11482 hw_plane_wm
->wm
[level
].plane_res_l
);
11485 if (!skl_wm_level_equals(&hw_plane_wm
->trans_wm
,
11486 &sw_plane_wm
->trans_wm
)) {
11487 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11489 sw_plane_wm
->trans_wm
.plane_en
,
11490 sw_plane_wm
->trans_wm
.plane_res_b
,
11491 sw_plane_wm
->trans_wm
.plane_res_l
,
11492 hw_plane_wm
->trans_wm
.plane_en
,
11493 hw_plane_wm
->trans_wm
.plane_res_b
,
11494 hw_plane_wm
->trans_wm
.plane_res_l
);
11498 hw_ddb_entry
= &hw_ddb
.plane
[pipe
][PLANE_CURSOR
];
11499 sw_ddb_entry
= &sw_ddb
->plane
[pipe
][PLANE_CURSOR
];
11501 if (!skl_ddb_entry_equal(hw_ddb_entry
, sw_ddb_entry
)) {
11502 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
11504 sw_ddb_entry
->start
, sw_ddb_entry
->end
,
11505 hw_ddb_entry
->start
, hw_ddb_entry
->end
);
11511 verify_connector_state(struct drm_device
*dev
,
11512 struct drm_atomic_state
*state
,
11513 struct drm_crtc
*crtc
)
11515 struct drm_connector
*connector
;
11516 struct drm_connector_state
*new_conn_state
;
11519 for_each_new_connector_in_state(state
, connector
, new_conn_state
, i
) {
11520 struct drm_encoder
*encoder
= connector
->encoder
;
11521 struct drm_crtc_state
*crtc_state
= NULL
;
11523 if (new_conn_state
->crtc
!= crtc
)
11527 crtc_state
= drm_atomic_get_new_crtc_state(state
, new_conn_state
->crtc
);
11529 intel_connector_verify_state(crtc_state
, new_conn_state
);
11531 I915_STATE_WARN(new_conn_state
->best_encoder
!= encoder
,
11532 "connector's atomic encoder doesn't match legacy encoder\n");
11537 verify_encoder_state(struct drm_device
*dev
, struct drm_atomic_state
*state
)
11539 struct intel_encoder
*encoder
;
11540 struct drm_connector
*connector
;
11541 struct drm_connector_state
*old_conn_state
, *new_conn_state
;
11544 for_each_intel_encoder(dev
, encoder
) {
11545 bool enabled
= false, found
= false;
11548 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
11549 encoder
->base
.base
.id
,
11550 encoder
->base
.name
);
11552 for_each_oldnew_connector_in_state(state
, connector
, old_conn_state
,
11553 new_conn_state
, i
) {
11554 if (old_conn_state
->best_encoder
== &encoder
->base
)
11557 if (new_conn_state
->best_encoder
!= &encoder
->base
)
11559 found
= enabled
= true;
11561 I915_STATE_WARN(new_conn_state
->crtc
!=
11562 encoder
->base
.crtc
,
11563 "connector's crtc doesn't match encoder crtc\n");
11569 I915_STATE_WARN(!!encoder
->base
.crtc
!= enabled
,
11570 "encoder's enabled state mismatch "
11571 "(expected %i, found %i)\n",
11572 !!encoder
->base
.crtc
, enabled
);
11574 if (!encoder
->base
.crtc
) {
11577 active
= encoder
->get_hw_state(encoder
, &pipe
);
11578 I915_STATE_WARN(active
,
11579 "encoder detached but still enabled on pipe %c.\n",
11586 verify_crtc_state(struct drm_crtc
*crtc
,
11587 struct drm_crtc_state
*old_crtc_state
,
11588 struct drm_crtc_state
*new_crtc_state
)
11590 struct drm_device
*dev
= crtc
->dev
;
11591 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11592 struct intel_encoder
*encoder
;
11593 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11594 struct intel_crtc_state
*pipe_config
, *sw_config
;
11595 struct drm_atomic_state
*old_state
;
11598 old_state
= old_crtc_state
->state
;
11599 __drm_atomic_helper_crtc_destroy_state(old_crtc_state
);
11600 pipe_config
= to_intel_crtc_state(old_crtc_state
);
11601 memset(pipe_config
, 0, sizeof(*pipe_config
));
11602 pipe_config
->base
.crtc
= crtc
;
11603 pipe_config
->base
.state
= old_state
;
11605 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc
->base
.id
, crtc
->name
);
11607 active
= dev_priv
->display
.get_pipe_config(intel_crtc
, pipe_config
);
11609 /* we keep both pipes enabled on 830 */
11610 if (IS_I830(dev_priv
))
11611 active
= new_crtc_state
->active
;
11613 I915_STATE_WARN(new_crtc_state
->active
!= active
,
11614 "crtc active state doesn't match with hw state "
11615 "(expected %i, found %i)\n", new_crtc_state
->active
, active
);
11617 I915_STATE_WARN(intel_crtc
->active
!= new_crtc_state
->active
,
11618 "transitional active state does not match atomic hw state "
11619 "(expected %i, found %i)\n", new_crtc_state
->active
, intel_crtc
->active
);
11621 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
11624 active
= encoder
->get_hw_state(encoder
, &pipe
);
11625 I915_STATE_WARN(active
!= new_crtc_state
->active
,
11626 "[ENCODER:%i] active %i with crtc active %i\n",
11627 encoder
->base
.base
.id
, active
, new_crtc_state
->active
);
11629 I915_STATE_WARN(active
&& intel_crtc
->pipe
!= pipe
,
11630 "Encoder connected to wrong pipe %c\n",
11634 pipe_config
->output_types
|= 1 << encoder
->type
;
11635 encoder
->get_config(encoder
, pipe_config
);
11639 intel_crtc_compute_pixel_rate(pipe_config
);
11641 if (!new_crtc_state
->active
)
11644 intel_pipe_config_sanity_check(dev_priv
, pipe_config
);
11646 sw_config
= to_intel_crtc_state(new_crtc_state
);
11647 if (!intel_pipe_config_compare(dev_priv
, sw_config
,
11648 pipe_config
, false)) {
11649 I915_STATE_WARN(1, "pipe state doesn't match!\n");
11650 intel_dump_pipe_config(intel_crtc
, pipe_config
,
11652 intel_dump_pipe_config(intel_crtc
, sw_config
,
11658 verify_single_dpll_state(struct drm_i915_private
*dev_priv
,
11659 struct intel_shared_dpll
*pll
,
11660 struct drm_crtc
*crtc
,
11661 struct drm_crtc_state
*new_state
)
11663 struct intel_dpll_hw_state dpll_hw_state
;
11664 unsigned crtc_mask
;
11667 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
11669 DRM_DEBUG_KMS("%s\n", pll
->name
);
11671 active
= pll
->funcs
.get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
11673 if (!(pll
->flags
& INTEL_DPLL_ALWAYS_ON
)) {
11674 I915_STATE_WARN(!pll
->on
&& pll
->active_mask
,
11675 "pll in active use but not on in sw tracking\n");
11676 I915_STATE_WARN(pll
->on
&& !pll
->active_mask
,
11677 "pll is on but not used by any active crtc\n");
11678 I915_STATE_WARN(pll
->on
!= active
,
11679 "pll on state mismatch (expected %i, found %i)\n",
11684 I915_STATE_WARN(pll
->active_mask
& ~pll
->state
.crtc_mask
,
11685 "more active pll users than references: %x vs %x\n",
11686 pll
->active_mask
, pll
->state
.crtc_mask
);
11691 crtc_mask
= 1 << drm_crtc_index(crtc
);
11693 if (new_state
->active
)
11694 I915_STATE_WARN(!(pll
->active_mask
& crtc_mask
),
11695 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
11696 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
11698 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
11699 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
11700 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
11702 I915_STATE_WARN(!(pll
->state
.crtc_mask
& crtc_mask
),
11703 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
11704 crtc_mask
, pll
->state
.crtc_mask
);
11706 I915_STATE_WARN(pll
->on
&& memcmp(&pll
->state
.hw_state
,
11708 sizeof(dpll_hw_state
)),
11709 "pll hw state mismatch\n");
11713 verify_shared_dpll_state(struct drm_device
*dev
, struct drm_crtc
*crtc
,
11714 struct drm_crtc_state
*old_crtc_state
,
11715 struct drm_crtc_state
*new_crtc_state
)
11717 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11718 struct intel_crtc_state
*old_state
= to_intel_crtc_state(old_crtc_state
);
11719 struct intel_crtc_state
*new_state
= to_intel_crtc_state(new_crtc_state
);
11721 if (new_state
->shared_dpll
)
11722 verify_single_dpll_state(dev_priv
, new_state
->shared_dpll
, crtc
, new_crtc_state
);
11724 if (old_state
->shared_dpll
&&
11725 old_state
->shared_dpll
!= new_state
->shared_dpll
) {
11726 unsigned crtc_mask
= 1 << drm_crtc_index(crtc
);
11727 struct intel_shared_dpll
*pll
= old_state
->shared_dpll
;
11729 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
11730 "pll active mismatch (didn't expect pipe %c in active mask)\n",
11731 pipe_name(drm_crtc_index(crtc
)));
11732 I915_STATE_WARN(pll
->state
.crtc_mask
& crtc_mask
,
11733 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
11734 pipe_name(drm_crtc_index(crtc
)));
11739 intel_modeset_verify_crtc(struct drm_crtc
*crtc
,
11740 struct drm_atomic_state
*state
,
11741 struct drm_crtc_state
*old_state
,
11742 struct drm_crtc_state
*new_state
)
11744 if (!needs_modeset(new_state
) &&
11745 !to_intel_crtc_state(new_state
)->update_pipe
)
11748 verify_wm_state(crtc
, new_state
);
11749 verify_connector_state(crtc
->dev
, state
, crtc
);
11750 verify_crtc_state(crtc
, old_state
, new_state
);
11751 verify_shared_dpll_state(crtc
->dev
, crtc
, old_state
, new_state
);
11755 verify_disabled_dpll_state(struct drm_device
*dev
)
11757 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11760 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++)
11761 verify_single_dpll_state(dev_priv
, &dev_priv
->shared_dplls
[i
], NULL
, NULL
);
11765 intel_modeset_verify_disabled(struct drm_device
*dev
,
11766 struct drm_atomic_state
*state
)
11768 verify_encoder_state(dev
, state
);
11769 verify_connector_state(dev
, state
, NULL
);
11770 verify_disabled_dpll_state(dev
);
11773 static void update_scanline_offset(struct intel_crtc
*crtc
)
11775 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
11778 * The scanline counter increments at the leading edge of hsync.
11780 * On most platforms it starts counting from vtotal-1 on the
11781 * first active line. That means the scanline counter value is
11782 * always one less than what we would expect. Ie. just after
11783 * start of vblank, which also occurs at start of hsync (on the
11784 * last active line), the scanline counter will read vblank_start-1.
11786 * On gen2 the scanline counter starts counting from 1 instead
11787 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
11788 * to keep the value positive), instead of adding one.
11790 * On HSW+ the behaviour of the scanline counter depends on the output
11791 * type. For DP ports it behaves like most other platforms, but on HDMI
11792 * there's an extra 1 line difference. So we need to add two instead of
11793 * one to the value.
11795 * On VLV/CHV DSI the scanline counter would appear to increment
11796 * approx. 1/3 of a scanline before start of vblank. Unfortunately
11797 * that means we can't tell whether we're in vblank or not while
11798 * we're on that particular line. We must still set scanline_offset
11799 * to 1 so that the vblank timestamps come out correct when we query
11800 * the scanline counter from within the vblank interrupt handler.
11801 * However if queried just before the start of vblank we'll get an
11802 * answer that's slightly in the future.
11804 if (IS_GEN2(dev_priv
)) {
11805 const struct drm_display_mode
*adjusted_mode
= &crtc
->config
->base
.adjusted_mode
;
11808 vtotal
= adjusted_mode
->crtc_vtotal
;
11809 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
11812 crtc
->scanline_offset
= vtotal
- 1;
11813 } else if (HAS_DDI(dev_priv
) &&
11814 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_HDMI
)) {
11815 crtc
->scanline_offset
= 2;
11817 crtc
->scanline_offset
= 1;
11820 static void intel_modeset_clear_plls(struct drm_atomic_state
*state
)
11822 struct drm_device
*dev
= state
->dev
;
11823 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11824 struct drm_crtc
*crtc
;
11825 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
11828 if (!dev_priv
->display
.crtc_compute_clock
)
11831 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
11832 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11833 struct intel_shared_dpll
*old_dpll
=
11834 to_intel_crtc_state(old_crtc_state
)->shared_dpll
;
11836 if (!needs_modeset(new_crtc_state
))
11839 to_intel_crtc_state(new_crtc_state
)->shared_dpll
= NULL
;
11844 intel_release_shared_dpll(old_dpll
, intel_crtc
, state
);
11849 * This implements the workaround described in the "notes" section of the mode
11850 * set sequence documentation. When going from no pipes or single pipe to
11851 * multiple pipes, and planes are enabled after the pipe, we need to wait at
11852 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
11854 static int haswell_mode_set_planes_workaround(struct drm_atomic_state
*state
)
11856 struct drm_crtc_state
*crtc_state
;
11857 struct intel_crtc
*intel_crtc
;
11858 struct drm_crtc
*crtc
;
11859 struct intel_crtc_state
*first_crtc_state
= NULL
;
11860 struct intel_crtc_state
*other_crtc_state
= NULL
;
11861 enum pipe first_pipe
= INVALID_PIPE
, enabled_pipe
= INVALID_PIPE
;
11864 /* look at all crtc's that are going to be enabled in during modeset */
11865 for_each_new_crtc_in_state(state
, crtc
, crtc_state
, i
) {
11866 intel_crtc
= to_intel_crtc(crtc
);
11868 if (!crtc_state
->active
|| !needs_modeset(crtc_state
))
11871 if (first_crtc_state
) {
11872 other_crtc_state
= to_intel_crtc_state(crtc_state
);
11875 first_crtc_state
= to_intel_crtc_state(crtc_state
);
11876 first_pipe
= intel_crtc
->pipe
;
11880 /* No workaround needed? */
11881 if (!first_crtc_state
)
11884 /* w/a possibly needed, check how many crtc's are already enabled. */
11885 for_each_intel_crtc(state
->dev
, intel_crtc
) {
11886 struct intel_crtc_state
*pipe_config
;
11888 pipe_config
= intel_atomic_get_crtc_state(state
, intel_crtc
);
11889 if (IS_ERR(pipe_config
))
11890 return PTR_ERR(pipe_config
);
11892 pipe_config
->hsw_workaround_pipe
= INVALID_PIPE
;
11894 if (!pipe_config
->base
.active
||
11895 needs_modeset(&pipe_config
->base
))
11898 /* 2 or more enabled crtcs means no need for w/a */
11899 if (enabled_pipe
!= INVALID_PIPE
)
11902 enabled_pipe
= intel_crtc
->pipe
;
11905 if (enabled_pipe
!= INVALID_PIPE
)
11906 first_crtc_state
->hsw_workaround_pipe
= enabled_pipe
;
11907 else if (other_crtc_state
)
11908 other_crtc_state
->hsw_workaround_pipe
= first_pipe
;
11913 static int intel_lock_all_pipes(struct drm_atomic_state
*state
)
11915 struct drm_crtc
*crtc
;
11917 /* Add all pipes to the state */
11918 for_each_crtc(state
->dev
, crtc
) {
11919 struct drm_crtc_state
*crtc_state
;
11921 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
11922 if (IS_ERR(crtc_state
))
11923 return PTR_ERR(crtc_state
);
11929 static int intel_modeset_all_pipes(struct drm_atomic_state
*state
)
11931 struct drm_crtc
*crtc
;
11934 * Add all pipes to the state, and force
11935 * a modeset on all the active ones.
11937 for_each_crtc(state
->dev
, crtc
) {
11938 struct drm_crtc_state
*crtc_state
;
11941 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
11942 if (IS_ERR(crtc_state
))
11943 return PTR_ERR(crtc_state
);
11945 if (!crtc_state
->active
|| needs_modeset(crtc_state
))
11948 crtc_state
->mode_changed
= true;
11950 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
11954 ret
= drm_atomic_add_affected_planes(state
, crtc
);
11962 static int intel_modeset_checks(struct drm_atomic_state
*state
)
11964 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
11965 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
11966 struct drm_crtc
*crtc
;
11967 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
11970 if (!check_digital_port_conflicts(state
)) {
11971 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
11975 intel_state
->modeset
= true;
11976 intel_state
->active_crtcs
= dev_priv
->active_crtcs
;
11977 intel_state
->cdclk
.logical
= dev_priv
->cdclk
.logical
;
11978 intel_state
->cdclk
.actual
= dev_priv
->cdclk
.actual
;
11980 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
11981 if (new_crtc_state
->active
)
11982 intel_state
->active_crtcs
|= 1 << i
;
11984 intel_state
->active_crtcs
&= ~(1 << i
);
11986 if (old_crtc_state
->active
!= new_crtc_state
->active
)
11987 intel_state
->active_pipe_changes
|= drm_crtc_mask(crtc
);
11991 * See if the config requires any additional preparation, e.g.
11992 * to adjust global state with pipes off. We need to do this
11993 * here so we can get the modeset_pipe updated config for the new
11994 * mode set on this crtc. For other crtcs we need to use the
11995 * adjusted_mode bits in the crtc directly.
11997 if (dev_priv
->display
.modeset_calc_cdclk
) {
11998 ret
= dev_priv
->display
.modeset_calc_cdclk(state
);
12003 * Writes to dev_priv->cdclk.logical must protected by
12004 * holding all the crtc locks, even if we don't end up
12005 * touching the hardware
12007 if (!intel_cdclk_state_compare(&dev_priv
->cdclk
.logical
,
12008 &intel_state
->cdclk
.logical
)) {
12009 ret
= intel_lock_all_pipes(state
);
12014 /* All pipes must be switched off while we change the cdclk. */
12015 if (!intel_cdclk_state_compare(&dev_priv
->cdclk
.actual
,
12016 &intel_state
->cdclk
.actual
)) {
12017 ret
= intel_modeset_all_pipes(state
);
12022 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12023 intel_state
->cdclk
.logical
.cdclk
,
12024 intel_state
->cdclk
.actual
.cdclk
);
12026 to_intel_atomic_state(state
)->cdclk
.logical
= dev_priv
->cdclk
.logical
;
12029 intel_modeset_clear_plls(state
);
12031 if (IS_HASWELL(dev_priv
))
12032 return haswell_mode_set_planes_workaround(state
);
12038 * Handle calculation of various watermark data at the end of the atomic check
12039 * phase. The code here should be run after the per-crtc and per-plane 'check'
12040 * handlers to ensure that all derived state has been updated.
12042 static int calc_watermark_data(struct drm_atomic_state
*state
)
12044 struct drm_device
*dev
= state
->dev
;
12045 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12047 /* Is there platform-specific watermark information to calculate? */
12048 if (dev_priv
->display
.compute_global_watermarks
)
12049 return dev_priv
->display
.compute_global_watermarks(state
);
12055 * intel_atomic_check - validate state object
12057 * @state: state to validate
12059 static int intel_atomic_check(struct drm_device
*dev
,
12060 struct drm_atomic_state
*state
)
12062 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12063 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12064 struct drm_crtc
*crtc
;
12065 struct drm_crtc_state
*old_crtc_state
, *crtc_state
;
12067 bool any_ms
= false;
12069 ret
= drm_atomic_helper_check_modeset(dev
, state
);
12073 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, crtc_state
, i
) {
12074 struct intel_crtc_state
*pipe_config
=
12075 to_intel_crtc_state(crtc_state
);
12077 /* Catch I915_MODE_FLAG_INHERITED */
12078 if (crtc_state
->mode
.private_flags
!= old_crtc_state
->mode
.private_flags
)
12079 crtc_state
->mode_changed
= true;
12081 if (!needs_modeset(crtc_state
))
12084 if (!crtc_state
->enable
) {
12089 /* FIXME: For only active_changed we shouldn't need to do any
12090 * state recomputation at all. */
12092 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
12096 ret
= intel_modeset_pipe_config(crtc
, pipe_config
);
12098 intel_dump_pipe_config(to_intel_crtc(crtc
),
12099 pipe_config
, "[failed]");
12103 if (i915
.fastboot
&&
12104 intel_pipe_config_compare(dev_priv
,
12105 to_intel_crtc_state(old_crtc_state
),
12106 pipe_config
, true)) {
12107 crtc_state
->mode_changed
= false;
12108 pipe_config
->update_pipe
= true;
12111 if (needs_modeset(crtc_state
))
12114 ret
= drm_atomic_add_affected_planes(state
, crtc
);
12118 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
12119 needs_modeset(crtc_state
) ?
12120 "[modeset]" : "[fastset]");
12124 ret
= intel_modeset_checks(state
);
12129 intel_state
->cdclk
.logical
= dev_priv
->cdclk
.logical
;
12132 ret
= drm_atomic_helper_check_planes(dev
, state
);
12136 intel_fbc_choose_crtc(dev_priv
, state
);
12137 return calc_watermark_data(state
);
12140 static int intel_atomic_prepare_commit(struct drm_device
*dev
,
12141 struct drm_atomic_state
*state
)
12143 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12144 struct drm_crtc_state
*crtc_state
;
12145 struct drm_crtc
*crtc
;
12148 for_each_new_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12149 if (state
->legacy_cursor_update
)
12152 ret
= intel_crtc_wait_for_pending_flips(crtc
);
12156 if (atomic_read(&to_intel_crtc(crtc
)->unpin_work_count
) >= 2)
12157 flush_workqueue(dev_priv
->wq
);
12160 ret
= mutex_lock_interruptible(&dev
->struct_mutex
);
12164 ret
= drm_atomic_helper_prepare_planes(dev
, state
);
12165 mutex_unlock(&dev
->struct_mutex
);
12170 u32
intel_crtc_get_vblank_counter(struct intel_crtc
*crtc
)
12172 struct drm_device
*dev
= crtc
->base
.dev
;
12174 if (!dev
->max_vblank_count
)
12175 return drm_accurate_vblank_count(&crtc
->base
);
12177 return dev
->driver
->get_vblank_counter(dev
, crtc
->pipe
);
12180 static void intel_atomic_wait_for_vblanks(struct drm_device
*dev
,
12181 struct drm_i915_private
*dev_priv
,
12182 unsigned crtc_mask
)
12184 unsigned last_vblank_count
[I915_MAX_PIPES
];
12191 for_each_pipe(dev_priv
, pipe
) {
12192 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
,
12195 if (!((1 << pipe
) & crtc_mask
))
12198 ret
= drm_crtc_vblank_get(&crtc
->base
);
12199 if (WARN_ON(ret
!= 0)) {
12200 crtc_mask
&= ~(1 << pipe
);
12204 last_vblank_count
[pipe
] = drm_crtc_vblank_count(&crtc
->base
);
12207 for_each_pipe(dev_priv
, pipe
) {
12208 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
,
12212 if (!((1 << pipe
) & crtc_mask
))
12215 lret
= wait_event_timeout(dev
->vblank
[pipe
].queue
,
12216 last_vblank_count
[pipe
] !=
12217 drm_crtc_vblank_count(&crtc
->base
),
12218 msecs_to_jiffies(50));
12220 WARN(!lret
, "pipe %c vblank wait timed out\n", pipe_name(pipe
));
12222 drm_crtc_vblank_put(&crtc
->base
);
12226 static bool needs_vblank_wait(struct intel_crtc_state
*crtc_state
)
12228 /* fb updated, need to unpin old fb */
12229 if (crtc_state
->fb_changed
)
12232 /* wm changes, need vblank before final wm's */
12233 if (crtc_state
->update_wm_post
)
12236 if (crtc_state
->wm
.need_postvbl_update
)
12242 static void intel_update_crtc(struct drm_crtc
*crtc
,
12243 struct drm_atomic_state
*state
,
12244 struct drm_crtc_state
*old_crtc_state
,
12245 struct drm_crtc_state
*new_crtc_state
,
12246 unsigned int *crtc_vblank_mask
)
12248 struct drm_device
*dev
= crtc
->dev
;
12249 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12250 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12251 struct intel_crtc_state
*pipe_config
= to_intel_crtc_state(new_crtc_state
);
12252 bool modeset
= needs_modeset(new_crtc_state
);
12255 update_scanline_offset(intel_crtc
);
12256 dev_priv
->display
.crtc_enable(pipe_config
, state
);
12258 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
),
12262 if (drm_atomic_get_existing_plane_state(state
, crtc
->primary
)) {
12264 intel_crtc
, pipe_config
,
12265 to_intel_plane_state(crtc
->primary
->state
));
12268 drm_atomic_helper_commit_planes_on_crtc(old_crtc_state
);
12270 if (needs_vblank_wait(pipe_config
))
12271 *crtc_vblank_mask
|= drm_crtc_mask(crtc
);
12274 static void intel_update_crtcs(struct drm_atomic_state
*state
,
12275 unsigned int *crtc_vblank_mask
)
12277 struct drm_crtc
*crtc
;
12278 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
12281 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12282 if (!new_crtc_state
->active
)
12285 intel_update_crtc(crtc
, state
, old_crtc_state
,
12286 new_crtc_state
, crtc_vblank_mask
);
12290 static void skl_update_crtcs(struct drm_atomic_state
*state
,
12291 unsigned int *crtc_vblank_mask
)
12293 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
12294 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12295 struct drm_crtc
*crtc
;
12296 struct intel_crtc
*intel_crtc
;
12297 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
12298 struct intel_crtc_state
*cstate
;
12299 unsigned int updated
= 0;
12304 const struct skl_ddb_entry
*entries
[I915_MAX_PIPES
] = {};
12306 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
)
12307 /* ignore allocations for crtc's that have been turned off. */
12308 if (new_crtc_state
->active
)
12309 entries
[i
] = &to_intel_crtc_state(old_crtc_state
)->wm
.skl
.ddb
;
12312 * Whenever the number of active pipes changes, we need to make sure we
12313 * update the pipes in the right order so that their ddb allocations
12314 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
12315 * cause pipe underruns and other bad stuff.
12320 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12321 bool vbl_wait
= false;
12322 unsigned int cmask
= drm_crtc_mask(crtc
);
12324 intel_crtc
= to_intel_crtc(crtc
);
12325 cstate
= to_intel_crtc_state(crtc
->state
);
12326 pipe
= intel_crtc
->pipe
;
12328 if (updated
& cmask
|| !cstate
->base
.active
)
12331 if (skl_ddb_allocation_overlaps(entries
, &cstate
->wm
.skl
.ddb
, i
))
12335 entries
[i
] = &cstate
->wm
.skl
.ddb
;
12338 * If this is an already active pipe, it's DDB changed,
12339 * and this isn't the last pipe that needs updating
12340 * then we need to wait for a vblank to pass for the
12341 * new ddb allocation to take effect.
12343 if (!skl_ddb_entry_equal(&cstate
->wm
.skl
.ddb
,
12344 &to_intel_crtc_state(old_crtc_state
)->wm
.skl
.ddb
) &&
12345 !new_crtc_state
->active_changed
&&
12346 intel_state
->wm_results
.dirty_pipes
!= updated
)
12349 intel_update_crtc(crtc
, state
, old_crtc_state
,
12350 new_crtc_state
, crtc_vblank_mask
);
12353 intel_wait_for_vblank(dev_priv
, pipe
);
12357 } while (progress
);
12360 static void intel_atomic_helper_free_state(struct drm_i915_private
*dev_priv
)
12362 struct intel_atomic_state
*state
, *next
;
12363 struct llist_node
*freed
;
12365 freed
= llist_del_all(&dev_priv
->atomic_helper
.free_list
);
12366 llist_for_each_entry_safe(state
, next
, freed
, freed
)
12367 drm_atomic_state_put(&state
->base
);
12370 static void intel_atomic_helper_free_state_worker(struct work_struct
*work
)
12372 struct drm_i915_private
*dev_priv
=
12373 container_of(work
, typeof(*dev_priv
), atomic_helper
.free_work
);
12375 intel_atomic_helper_free_state(dev_priv
);
12378 static void intel_atomic_commit_tail(struct drm_atomic_state
*state
)
12380 struct drm_device
*dev
= state
->dev
;
12381 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12382 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12383 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
12384 struct drm_crtc
*crtc
;
12385 struct intel_crtc_state
*intel_cstate
;
12386 bool hw_check
= intel_state
->modeset
;
12387 u64 put_domains
[I915_MAX_PIPES
] = {};
12388 unsigned crtc_vblank_mask
= 0;
12391 drm_atomic_helper_wait_for_dependencies(state
);
12393 if (intel_state
->modeset
)
12394 intel_display_power_get(dev_priv
, POWER_DOMAIN_MODESET
);
12396 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12397 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12399 if (needs_modeset(new_crtc_state
) ||
12400 to_intel_crtc_state(new_crtc_state
)->update_pipe
) {
12403 put_domains
[to_intel_crtc(crtc
)->pipe
] =
12404 modeset_get_crtc_power_domains(crtc
,
12405 to_intel_crtc_state(new_crtc_state
));
12408 if (!needs_modeset(new_crtc_state
))
12411 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
),
12412 to_intel_crtc_state(new_crtc_state
));
12414 if (old_crtc_state
->active
) {
12415 intel_crtc_disable_planes(crtc
, old_crtc_state
->plane_mask
);
12416 dev_priv
->display
.crtc_disable(to_intel_crtc_state(old_crtc_state
), state
);
12417 intel_crtc
->active
= false;
12418 intel_fbc_disable(intel_crtc
);
12419 intel_disable_shared_dpll(intel_crtc
);
12422 * Underruns don't always raise
12423 * interrupts, so check manually.
12425 intel_check_cpu_fifo_underruns(dev_priv
);
12426 intel_check_pch_fifo_underruns(dev_priv
);
12428 if (!crtc
->state
->active
) {
12430 * Make sure we don't call initial_watermarks
12431 * for ILK-style watermark updates.
12433 * No clue what this is supposed to achieve.
12435 if (INTEL_GEN(dev_priv
) >= 9)
12436 dev_priv
->display
.initial_watermarks(intel_state
,
12437 to_intel_crtc_state(crtc
->state
));
12442 /* Only after disabling all output pipelines that will be changed can we
12443 * update the the output configuration. */
12444 intel_modeset_update_crtc_state(state
);
12446 if (intel_state
->modeset
) {
12447 drm_atomic_helper_update_legacy_modeset_state(state
->dev
, state
);
12449 intel_set_cdclk(dev_priv
, &dev_priv
->cdclk
.actual
);
12452 * SKL workaround: bspec recommends we disable the SAGV when we
12453 * have more then one pipe enabled
12455 if (!intel_can_enable_sagv(state
))
12456 intel_disable_sagv(dev_priv
);
12458 intel_modeset_verify_disabled(dev
, state
);
12461 /* Complete the events for pipes that have now been disabled */
12462 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
12463 bool modeset
= needs_modeset(new_crtc_state
);
12465 /* Complete events for now disable pipes here. */
12466 if (modeset
&& !new_crtc_state
->active
&& new_crtc_state
->event
) {
12467 spin_lock_irq(&dev
->event_lock
);
12468 drm_crtc_send_vblank_event(crtc
, new_crtc_state
->event
);
12469 spin_unlock_irq(&dev
->event_lock
);
12471 new_crtc_state
->event
= NULL
;
12475 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
12476 dev_priv
->display
.update_crtcs(state
, &crtc_vblank_mask
);
12478 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
12479 * already, but still need the state for the delayed optimization. To
12481 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
12482 * - schedule that vblank worker _before_ calling hw_done
12483 * - at the start of commit_tail, cancel it _synchrously
12484 * - switch over to the vblank wait helper in the core after that since
12485 * we don't need out special handling any more.
12487 if (!state
->legacy_cursor_update
)
12488 intel_atomic_wait_for_vblanks(dev
, dev_priv
, crtc_vblank_mask
);
12491 * Now that the vblank has passed, we can go ahead and program the
12492 * optimal watermarks on platforms that need two-step watermark
12495 * TODO: Move this (and other cleanup) to an async worker eventually.
12497 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
12498 intel_cstate
= to_intel_crtc_state(new_crtc_state
);
12500 if (dev_priv
->display
.optimize_watermarks
)
12501 dev_priv
->display
.optimize_watermarks(intel_state
,
12505 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12506 intel_post_plane_update(to_intel_crtc_state(old_crtc_state
));
12508 if (put_domains
[i
])
12509 modeset_put_power_domains(dev_priv
, put_domains
[i
]);
12511 intel_modeset_verify_crtc(crtc
, state
, old_crtc_state
, new_crtc_state
);
12514 if (intel_state
->modeset
&& intel_can_enable_sagv(state
))
12515 intel_enable_sagv(dev_priv
);
12517 drm_atomic_helper_commit_hw_done(state
);
12519 if (intel_state
->modeset
) {
12520 /* As one of the primary mmio accessors, KMS has a high
12521 * likelihood of triggering bugs in unclaimed access. After we
12522 * finish modesetting, see if an error has been flagged, and if
12523 * so enable debugging for the next modeset - and hope we catch
12526 intel_uncore_arm_unclaimed_mmio_detection(dev_priv
);
12527 intel_display_power_put(dev_priv
, POWER_DOMAIN_MODESET
);
12530 mutex_lock(&dev
->struct_mutex
);
12531 drm_atomic_helper_cleanup_planes(dev
, state
);
12532 mutex_unlock(&dev
->struct_mutex
);
12534 drm_atomic_helper_commit_cleanup_done(state
);
12536 drm_atomic_state_put(state
);
12538 intel_atomic_helper_free_state(dev_priv
);
12541 static void intel_atomic_commit_work(struct work_struct
*work
)
12543 struct drm_atomic_state
*state
=
12544 container_of(work
, struct drm_atomic_state
, commit_work
);
12546 intel_atomic_commit_tail(state
);
12549 static int __i915_sw_fence_call
12550 intel_atomic_commit_ready(struct i915_sw_fence
*fence
,
12551 enum i915_sw_fence_notify notify
)
12553 struct intel_atomic_state
*state
=
12554 container_of(fence
, struct intel_atomic_state
, commit_ready
);
12557 case FENCE_COMPLETE
:
12558 if (state
->base
.commit_work
.func
)
12559 queue_work(system_unbound_wq
, &state
->base
.commit_work
);
12564 struct intel_atomic_helper
*helper
=
12565 &to_i915(state
->base
.dev
)->atomic_helper
;
12567 if (llist_add(&state
->freed
, &helper
->free_list
))
12568 schedule_work(&helper
->free_work
);
12573 return NOTIFY_DONE
;
12576 static void intel_atomic_track_fbs(struct drm_atomic_state
*state
)
12578 struct drm_plane_state
*old_plane_state
, *new_plane_state
;
12579 struct drm_plane
*plane
;
12582 for_each_oldnew_plane_in_state(state
, plane
, old_plane_state
, new_plane_state
, i
)
12583 i915_gem_track_fb(intel_fb_obj(old_plane_state
->fb
),
12584 intel_fb_obj(new_plane_state
->fb
),
12585 to_intel_plane(plane
)->frontbuffer_bit
);
12589 * intel_atomic_commit - commit validated state object
12591 * @state: the top-level driver state object
12592 * @nonblock: nonblocking commit
12594 * This function commits a top-level state object that has been validated
12595 * with drm_atomic_helper_check().
12598 * Zero for success or -errno.
12600 static int intel_atomic_commit(struct drm_device
*dev
,
12601 struct drm_atomic_state
*state
,
12604 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12605 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12608 ret
= drm_atomic_helper_setup_commit(state
, nonblock
);
12612 drm_atomic_state_get(state
);
12613 i915_sw_fence_init(&intel_state
->commit_ready
,
12614 intel_atomic_commit_ready
);
12616 ret
= intel_atomic_prepare_commit(dev
, state
);
12618 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret
);
12619 i915_sw_fence_commit(&intel_state
->commit_ready
);
12624 * The intel_legacy_cursor_update() fast path takes care
12625 * of avoiding the vblank waits for simple cursor
12626 * movement and flips. For cursor on/off and size changes,
12627 * we want to perform the vblank waits so that watermark
12628 * updates happen during the correct frames. Gen9+ have
12629 * double buffered watermarks and so shouldn't need this.
12631 * Do this after drm_atomic_helper_setup_commit() and
12632 * intel_atomic_prepare_commit() because we still want
12633 * to skip the flip and fb cleanup waits. Although that
12634 * does risk yanking the mapping from under the display
12637 * FIXME doing watermarks and fb cleanup from a vblank worker
12638 * (assuming we had any) would solve these problems.
12640 if (INTEL_GEN(dev_priv
) < 9)
12641 state
->legacy_cursor_update
= false;
12643 drm_atomic_helper_swap_state(state
, true);
12644 dev_priv
->wm
.distrust_bios_wm
= false;
12645 intel_shared_dpll_swap_state(state
);
12646 intel_atomic_track_fbs(state
);
12648 if (intel_state
->modeset
) {
12649 memcpy(dev_priv
->min_pixclk
, intel_state
->min_pixclk
,
12650 sizeof(intel_state
->min_pixclk
));
12651 dev_priv
->active_crtcs
= intel_state
->active_crtcs
;
12652 dev_priv
->cdclk
.logical
= intel_state
->cdclk
.logical
;
12653 dev_priv
->cdclk
.actual
= intel_state
->cdclk
.actual
;
12656 drm_atomic_state_get(state
);
12657 INIT_WORK(&state
->commit_work
,
12658 nonblock
? intel_atomic_commit_work
: NULL
);
12660 i915_sw_fence_commit(&intel_state
->commit_ready
);
12662 i915_sw_fence_wait(&intel_state
->commit_ready
);
12663 intel_atomic_commit_tail(state
);
12669 static const struct drm_crtc_funcs intel_crtc_funcs
= {
12670 .gamma_set
= drm_atomic_helper_legacy_gamma_set
,
12671 .set_config
= drm_atomic_helper_set_config
,
12672 .set_property
= drm_atomic_helper_crtc_set_property
,
12673 .destroy
= intel_crtc_destroy
,
12674 .page_flip
= drm_atomic_helper_page_flip
,
12675 .atomic_duplicate_state
= intel_crtc_duplicate_state
,
12676 .atomic_destroy_state
= intel_crtc_destroy_state
,
12677 .set_crc_source
= intel_crtc_set_crc_source
,
12681 * intel_prepare_plane_fb - Prepare fb for usage on plane
12682 * @plane: drm plane to prepare for
12683 * @fb: framebuffer to prepare for presentation
12685 * Prepares a framebuffer for usage on a display plane. Generally this
12686 * involves pinning the underlying object and updating the frontbuffer tracking
12687 * bits. Some older platforms need special physical address handling for
12690 * Must be called with struct_mutex held.
12692 * Returns 0 on success, negative error code on failure.
12695 intel_prepare_plane_fb(struct drm_plane
*plane
,
12696 struct drm_plane_state
*new_state
)
12698 struct intel_atomic_state
*intel_state
=
12699 to_intel_atomic_state(new_state
->state
);
12700 struct drm_i915_private
*dev_priv
= to_i915(plane
->dev
);
12701 struct drm_framebuffer
*fb
= new_state
->fb
;
12702 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
12703 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->state
->fb
);
12707 if (plane
->type
== DRM_PLANE_TYPE_CURSOR
&&
12708 INTEL_INFO(dev_priv
)->cursor_needs_physical
) {
12709 const int align
= intel_cursor_alignment(dev_priv
);
12711 ret
= i915_gem_object_attach_phys(obj
, align
);
12713 DRM_DEBUG_KMS("failed to attach phys object\n");
12717 struct i915_vma
*vma
;
12719 vma
= intel_pin_and_fence_fb_obj(fb
, new_state
->rotation
);
12721 DRM_DEBUG_KMS("failed to pin object\n");
12722 return PTR_ERR(vma
);
12725 to_intel_plane_state(new_state
)->vma
= vma
;
12729 if (!obj
&& !old_obj
)
12733 struct drm_crtc_state
*crtc_state
=
12734 drm_atomic_get_existing_crtc_state(new_state
->state
,
12735 plane
->state
->crtc
);
12737 /* Big Hammer, we also need to ensure that any pending
12738 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
12739 * current scanout is retired before unpinning the old
12740 * framebuffer. Note that we rely on userspace rendering
12741 * into the buffer attached to the pipe they are waiting
12742 * on. If not, userspace generates a GPU hang with IPEHR
12743 * point to the MI_WAIT_FOR_EVENT.
12745 * This should only fail upon a hung GPU, in which case we
12746 * can safely continue.
12748 if (needs_modeset(crtc_state
)) {
12749 ret
= i915_sw_fence_await_reservation(&intel_state
->commit_ready
,
12750 old_obj
->resv
, NULL
,
12758 if (new_state
->fence
) { /* explicit fencing */
12759 ret
= i915_sw_fence_await_dma_fence(&intel_state
->commit_ready
,
12761 I915_FENCE_TIMEOUT
,
12770 if (!new_state
->fence
) { /* implicit fencing */
12771 ret
= i915_sw_fence_await_reservation(&intel_state
->commit_ready
,
12773 false, I915_FENCE_TIMEOUT
,
12778 i915_gem_object_wait_priority(obj
, 0, I915_PRIORITY_DISPLAY
);
12785 * intel_cleanup_plane_fb - Cleans up an fb after plane use
12786 * @plane: drm plane to clean up for
12787 * @fb: old framebuffer that was on plane
12789 * Cleans up a framebuffer that has just been removed from a plane.
12791 * Must be called with struct_mutex held.
12794 intel_cleanup_plane_fb(struct drm_plane
*plane
,
12795 struct drm_plane_state
*old_state
)
12797 struct i915_vma
*vma
;
12799 /* Should only be called after a successful intel_prepare_plane_fb()! */
12800 vma
= fetch_and_zero(&to_intel_plane_state(old_state
)->vma
);
12802 intel_unpin_fb_vma(vma
);
12806 skl_max_scale(struct intel_crtc
*intel_crtc
, struct intel_crtc_state
*crtc_state
)
12808 struct drm_i915_private
*dev_priv
;
12810 int crtc_clock
, max_dotclk
;
12812 if (!intel_crtc
|| !crtc_state
->base
.enable
)
12813 return DRM_PLANE_HELPER_NO_SCALING
;
12815 dev_priv
= to_i915(intel_crtc
->base
.dev
);
12817 crtc_clock
= crtc_state
->base
.adjusted_mode
.crtc_clock
;
12818 max_dotclk
= to_intel_atomic_state(crtc_state
->base
.state
)->cdclk
.logical
.cdclk
;
12820 if (IS_GEMINILAKE(dev_priv
))
12823 if (WARN_ON_ONCE(!crtc_clock
|| max_dotclk
< crtc_clock
))
12824 return DRM_PLANE_HELPER_NO_SCALING
;
12827 * skl max scale is lower of:
12828 * close to 3 but not 3, -1 is for that purpose
12832 max_scale
= min((1 << 16) * 3 - 1,
12833 (1 << 8) * ((max_dotclk
<< 8) / crtc_clock
));
12839 intel_check_primary_plane(struct intel_plane
*plane
,
12840 struct intel_crtc_state
*crtc_state
,
12841 struct intel_plane_state
*state
)
12843 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
12844 struct drm_crtc
*crtc
= state
->base
.crtc
;
12845 int min_scale
= DRM_PLANE_HELPER_NO_SCALING
;
12846 int max_scale
= DRM_PLANE_HELPER_NO_SCALING
;
12847 bool can_position
= false;
12850 if (INTEL_GEN(dev_priv
) >= 9) {
12851 /* use scaler when colorkey is not required */
12852 if (state
->ckey
.flags
== I915_SET_COLORKEY_NONE
) {
12854 max_scale
= skl_max_scale(to_intel_crtc(crtc
), crtc_state
);
12856 can_position
= true;
12859 ret
= drm_plane_helper_check_state(&state
->base
,
12861 min_scale
, max_scale
,
12862 can_position
, true);
12866 if (!state
->base
.fb
)
12869 if (INTEL_GEN(dev_priv
) >= 9) {
12870 ret
= skl_check_plane_surface(state
);
12874 state
->ctl
= skl_plane_ctl(crtc_state
, state
);
12876 ret
= i9xx_check_plane_surface(state
);
12880 state
->ctl
= i9xx_plane_ctl(crtc_state
, state
);
12886 static void intel_begin_crtc_commit(struct drm_crtc
*crtc
,
12887 struct drm_crtc_state
*old_crtc_state
)
12889 struct drm_device
*dev
= crtc
->dev
;
12890 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12891 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12892 struct intel_crtc_state
*intel_cstate
=
12893 to_intel_crtc_state(crtc
->state
);
12894 struct intel_crtc_state
*old_intel_cstate
=
12895 to_intel_crtc_state(old_crtc_state
);
12896 struct intel_atomic_state
*old_intel_state
=
12897 to_intel_atomic_state(old_crtc_state
->state
);
12898 bool modeset
= needs_modeset(crtc
->state
);
12901 (intel_cstate
->base
.color_mgmt_changed
||
12902 intel_cstate
->update_pipe
)) {
12903 intel_color_set_csc(crtc
->state
);
12904 intel_color_load_luts(crtc
->state
);
12907 /* Perform vblank evasion around commit operation */
12908 intel_pipe_update_start(intel_crtc
);
12913 if (intel_cstate
->update_pipe
)
12914 intel_update_pipe_config(intel_crtc
, old_intel_cstate
);
12915 else if (INTEL_GEN(dev_priv
) >= 9)
12916 skl_detach_scalers(intel_crtc
);
12919 if (dev_priv
->display
.atomic_update_watermarks
)
12920 dev_priv
->display
.atomic_update_watermarks(old_intel_state
,
12924 static void intel_finish_crtc_commit(struct drm_crtc
*crtc
,
12925 struct drm_crtc_state
*old_crtc_state
)
12927 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12929 intel_pipe_update_end(intel_crtc
, NULL
);
12933 * intel_plane_destroy - destroy a plane
12934 * @plane: plane to destroy
12936 * Common destruction function for all types of planes (primary, cursor,
12939 void intel_plane_destroy(struct drm_plane
*plane
)
12941 drm_plane_cleanup(plane
);
12942 kfree(to_intel_plane(plane
));
12945 const struct drm_plane_funcs intel_plane_funcs
= {
12946 .update_plane
= drm_atomic_helper_update_plane
,
12947 .disable_plane
= drm_atomic_helper_disable_plane
,
12948 .destroy
= intel_plane_destroy
,
12949 .set_property
= drm_atomic_helper_plane_set_property
,
12950 .atomic_get_property
= intel_plane_atomic_get_property
,
12951 .atomic_set_property
= intel_plane_atomic_set_property
,
12952 .atomic_duplicate_state
= intel_plane_duplicate_state
,
12953 .atomic_destroy_state
= intel_plane_destroy_state
,
12957 intel_legacy_cursor_update(struct drm_plane
*plane
,
12958 struct drm_crtc
*crtc
,
12959 struct drm_framebuffer
*fb
,
12960 int crtc_x
, int crtc_y
,
12961 unsigned int crtc_w
, unsigned int crtc_h
,
12962 uint32_t src_x
, uint32_t src_y
,
12963 uint32_t src_w
, uint32_t src_h
,
12964 struct drm_modeset_acquire_ctx
*ctx
)
12966 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
12968 struct drm_plane_state
*old_plane_state
, *new_plane_state
;
12969 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
12970 struct drm_framebuffer
*old_fb
;
12971 struct drm_crtc_state
*crtc_state
= crtc
->state
;
12972 struct i915_vma
*old_vma
;
12975 * When crtc is inactive or there is a modeset pending,
12976 * wait for it to complete in the slowpath
12978 if (!crtc_state
->active
|| needs_modeset(crtc_state
) ||
12979 to_intel_crtc_state(crtc_state
)->update_pipe
)
12982 old_plane_state
= plane
->state
;
12985 * If any parameters change that may affect watermarks,
12986 * take the slowpath. Only changing fb or position should be
12989 if (old_plane_state
->crtc
!= crtc
||
12990 old_plane_state
->src_w
!= src_w
||
12991 old_plane_state
->src_h
!= src_h
||
12992 old_plane_state
->crtc_w
!= crtc_w
||
12993 old_plane_state
->crtc_h
!= crtc_h
||
12994 !old_plane_state
->fb
!= !fb
)
12997 new_plane_state
= intel_plane_duplicate_state(plane
);
12998 if (!new_plane_state
)
13001 drm_atomic_set_fb_for_plane(new_plane_state
, fb
);
13003 new_plane_state
->src_x
= src_x
;
13004 new_plane_state
->src_y
= src_y
;
13005 new_plane_state
->src_w
= src_w
;
13006 new_plane_state
->src_h
= src_h
;
13007 new_plane_state
->crtc_x
= crtc_x
;
13008 new_plane_state
->crtc_y
= crtc_y
;
13009 new_plane_state
->crtc_w
= crtc_w
;
13010 new_plane_state
->crtc_h
= crtc_h
;
13012 ret
= intel_plane_atomic_check_with_state(to_intel_crtc_state(crtc
->state
),
13013 to_intel_plane_state(new_plane_state
));
13017 ret
= mutex_lock_interruptible(&dev_priv
->drm
.struct_mutex
);
13021 if (INTEL_INFO(dev_priv
)->cursor_needs_physical
) {
13022 int align
= intel_cursor_alignment(dev_priv
);
13024 ret
= i915_gem_object_attach_phys(intel_fb_obj(fb
), align
);
13026 DRM_DEBUG_KMS("failed to attach phys object\n");
13030 struct i915_vma
*vma
;
13032 vma
= intel_pin_and_fence_fb_obj(fb
, new_plane_state
->rotation
);
13034 DRM_DEBUG_KMS("failed to pin object\n");
13036 ret
= PTR_ERR(vma
);
13040 to_intel_plane_state(new_plane_state
)->vma
= vma
;
13043 old_fb
= old_plane_state
->fb
;
13044 old_vma
= to_intel_plane_state(old_plane_state
)->vma
;
13046 i915_gem_track_fb(intel_fb_obj(old_fb
), intel_fb_obj(fb
),
13047 intel_plane
->frontbuffer_bit
);
13049 /* Swap plane state */
13050 new_plane_state
->fence
= old_plane_state
->fence
;
13051 *to_intel_plane_state(old_plane_state
) = *to_intel_plane_state(new_plane_state
);
13052 new_plane_state
->fence
= NULL
;
13053 new_plane_state
->fb
= old_fb
;
13054 to_intel_plane_state(new_plane_state
)->vma
= old_vma
;
13056 if (plane
->state
->visible
) {
13057 trace_intel_update_plane(plane
, to_intel_crtc(crtc
));
13058 intel_plane
->update_plane(intel_plane
,
13059 to_intel_crtc_state(crtc
->state
),
13060 to_intel_plane_state(plane
->state
));
13062 trace_intel_disable_plane(plane
, to_intel_crtc(crtc
));
13063 intel_plane
->disable_plane(intel_plane
, to_intel_crtc(crtc
));
13066 intel_cleanup_plane_fb(plane
, new_plane_state
);
13069 mutex_unlock(&dev_priv
->drm
.struct_mutex
);
13071 intel_plane_destroy_state(plane
, new_plane_state
);
13075 return drm_atomic_helper_update_plane(plane
, crtc
, fb
,
13076 crtc_x
, crtc_y
, crtc_w
, crtc_h
,
13077 src_x
, src_y
, src_w
, src_h
, ctx
);
13080 static const struct drm_plane_funcs intel_cursor_plane_funcs
= {
13081 .update_plane
= intel_legacy_cursor_update
,
13082 .disable_plane
= drm_atomic_helper_disable_plane
,
13083 .destroy
= intel_plane_destroy
,
13084 .set_property
= drm_atomic_helper_plane_set_property
,
13085 .atomic_get_property
= intel_plane_atomic_get_property
,
13086 .atomic_set_property
= intel_plane_atomic_set_property
,
13087 .atomic_duplicate_state
= intel_plane_duplicate_state
,
13088 .atomic_destroy_state
= intel_plane_destroy_state
,
13091 static struct intel_plane
*
13092 intel_primary_plane_create(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
13094 struct intel_plane
*primary
= NULL
;
13095 struct intel_plane_state
*state
= NULL
;
13096 const uint32_t *intel_primary_formats
;
13097 unsigned int supported_rotations
;
13098 unsigned int num_formats
;
13101 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
13107 state
= intel_create_plane_state(&primary
->base
);
13113 primary
->base
.state
= &state
->base
;
13115 primary
->can_scale
= false;
13116 primary
->max_downscale
= 1;
13117 if (INTEL_GEN(dev_priv
) >= 9) {
13118 primary
->can_scale
= true;
13119 state
->scaler_id
= -1;
13121 primary
->pipe
= pipe
;
13123 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
13124 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
13126 if (HAS_FBC(dev_priv
) && INTEL_GEN(dev_priv
) < 4)
13127 primary
->plane
= (enum plane
) !pipe
;
13129 primary
->plane
= (enum plane
) pipe
;
13130 primary
->id
= PLANE_PRIMARY
;
13131 primary
->frontbuffer_bit
= INTEL_FRONTBUFFER_PRIMARY(pipe
);
13132 primary
->check_plane
= intel_check_primary_plane
;
13134 if (INTEL_GEN(dev_priv
) >= 9) {
13135 intel_primary_formats
= skl_primary_formats
;
13136 num_formats
= ARRAY_SIZE(skl_primary_formats
);
13138 primary
->update_plane
= skylake_update_primary_plane
;
13139 primary
->disable_plane
= skylake_disable_primary_plane
;
13140 } else if (INTEL_GEN(dev_priv
) >= 4) {
13141 intel_primary_formats
= i965_primary_formats
;
13142 num_formats
= ARRAY_SIZE(i965_primary_formats
);
13144 primary
->update_plane
= i9xx_update_primary_plane
;
13145 primary
->disable_plane
= i9xx_disable_primary_plane
;
13147 intel_primary_formats
= i8xx_primary_formats
;
13148 num_formats
= ARRAY_SIZE(i8xx_primary_formats
);
13150 primary
->update_plane
= i9xx_update_primary_plane
;
13151 primary
->disable_plane
= i9xx_disable_primary_plane
;
13154 if (INTEL_GEN(dev_priv
) >= 9)
13155 ret
= drm_universal_plane_init(&dev_priv
->drm
, &primary
->base
,
13156 0, &intel_plane_funcs
,
13157 intel_primary_formats
, num_formats
,
13158 DRM_PLANE_TYPE_PRIMARY
,
13159 "plane 1%c", pipe_name(pipe
));
13160 else if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
))
13161 ret
= drm_universal_plane_init(&dev_priv
->drm
, &primary
->base
,
13162 0, &intel_plane_funcs
,
13163 intel_primary_formats
, num_formats
,
13164 DRM_PLANE_TYPE_PRIMARY
,
13165 "primary %c", pipe_name(pipe
));
13167 ret
= drm_universal_plane_init(&dev_priv
->drm
, &primary
->base
,
13168 0, &intel_plane_funcs
,
13169 intel_primary_formats
, num_formats
,
13170 DRM_PLANE_TYPE_PRIMARY
,
13171 "plane %c", plane_name(primary
->plane
));
13175 if (INTEL_GEN(dev_priv
) >= 9) {
13176 supported_rotations
=
13177 DRM_MODE_ROTATE_0
| DRM_MODE_ROTATE_90
|
13178 DRM_MODE_ROTATE_180
| DRM_MODE_ROTATE_270
;
13179 } else if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_B
) {
13180 supported_rotations
=
13181 DRM_MODE_ROTATE_0
| DRM_MODE_ROTATE_180
|
13182 DRM_MODE_REFLECT_X
;
13183 } else if (INTEL_GEN(dev_priv
) >= 4) {
13184 supported_rotations
=
13185 DRM_MODE_ROTATE_0
| DRM_MODE_ROTATE_180
;
13187 supported_rotations
= DRM_MODE_ROTATE_0
;
13190 if (INTEL_GEN(dev_priv
) >= 4)
13191 drm_plane_create_rotation_property(&primary
->base
,
13193 supported_rotations
);
13195 drm_plane_helper_add(&primary
->base
, &intel_plane_helper_funcs
);
13203 return ERR_PTR(ret
);
13206 static struct intel_plane
*
13207 intel_cursor_plane_create(struct drm_i915_private
*dev_priv
,
13210 struct intel_plane
*cursor
= NULL
;
13211 struct intel_plane_state
*state
= NULL
;
13214 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
13220 state
= intel_create_plane_state(&cursor
->base
);
13226 cursor
->base
.state
= &state
->base
;
13228 cursor
->can_scale
= false;
13229 cursor
->max_downscale
= 1;
13230 cursor
->pipe
= pipe
;
13231 cursor
->plane
= pipe
;
13232 cursor
->id
= PLANE_CURSOR
;
13233 cursor
->frontbuffer_bit
= INTEL_FRONTBUFFER_CURSOR(pipe
);
13235 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
)) {
13236 cursor
->update_plane
= i845_update_cursor
;
13237 cursor
->disable_plane
= i845_disable_cursor
;
13238 cursor
->check_plane
= i845_check_cursor
;
13240 cursor
->update_plane
= i9xx_update_cursor
;
13241 cursor
->disable_plane
= i9xx_disable_cursor
;
13242 cursor
->check_plane
= i9xx_check_cursor
;
13245 cursor
->cursor
.base
= ~0;
13246 cursor
->cursor
.cntl
= ~0;
13248 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
) || HAS_CUR_FBC(dev_priv
))
13249 cursor
->cursor
.size
= ~0;
13251 ret
= drm_universal_plane_init(&dev_priv
->drm
, &cursor
->base
,
13252 0, &intel_cursor_plane_funcs
,
13253 intel_cursor_formats
,
13254 ARRAY_SIZE(intel_cursor_formats
),
13255 DRM_PLANE_TYPE_CURSOR
,
13256 "cursor %c", pipe_name(pipe
));
13260 if (INTEL_GEN(dev_priv
) >= 4)
13261 drm_plane_create_rotation_property(&cursor
->base
,
13263 DRM_MODE_ROTATE_0
|
13264 DRM_MODE_ROTATE_180
);
13266 if (INTEL_GEN(dev_priv
) >= 9)
13267 state
->scaler_id
= -1;
13269 drm_plane_helper_add(&cursor
->base
, &intel_plane_helper_funcs
);
13277 return ERR_PTR(ret
);
13280 static void intel_crtc_init_scalers(struct intel_crtc
*crtc
,
13281 struct intel_crtc_state
*crtc_state
)
13283 struct intel_crtc_scaler_state
*scaler_state
=
13284 &crtc_state
->scaler_state
;
13285 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
13288 crtc
->num_scalers
= dev_priv
->info
.num_scalers
[crtc
->pipe
];
13289 if (!crtc
->num_scalers
)
13292 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
13293 struct intel_scaler
*scaler
= &scaler_state
->scalers
[i
];
13295 scaler
->in_use
= 0;
13296 scaler
->mode
= PS_SCALER_MODE_DYN
;
13299 scaler_state
->scaler_id
= -1;
13302 static int intel_crtc_init(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
13304 struct intel_crtc
*intel_crtc
;
13305 struct intel_crtc_state
*crtc_state
= NULL
;
13306 struct intel_plane
*primary
= NULL
;
13307 struct intel_plane
*cursor
= NULL
;
13310 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
13314 crtc_state
= kzalloc(sizeof(*crtc_state
), GFP_KERNEL
);
13319 intel_crtc
->config
= crtc_state
;
13320 intel_crtc
->base
.state
= &crtc_state
->base
;
13321 crtc_state
->base
.crtc
= &intel_crtc
->base
;
13323 primary
= intel_primary_plane_create(dev_priv
, pipe
);
13324 if (IS_ERR(primary
)) {
13325 ret
= PTR_ERR(primary
);
13328 intel_crtc
->plane_ids_mask
|= BIT(primary
->id
);
13330 for_each_sprite(dev_priv
, pipe
, sprite
) {
13331 struct intel_plane
*plane
;
13333 plane
= intel_sprite_plane_create(dev_priv
, pipe
, sprite
);
13334 if (IS_ERR(plane
)) {
13335 ret
= PTR_ERR(plane
);
13338 intel_crtc
->plane_ids_mask
|= BIT(plane
->id
);
13341 cursor
= intel_cursor_plane_create(dev_priv
, pipe
);
13342 if (IS_ERR(cursor
)) {
13343 ret
= PTR_ERR(cursor
);
13346 intel_crtc
->plane_ids_mask
|= BIT(cursor
->id
);
13348 ret
= drm_crtc_init_with_planes(&dev_priv
->drm
, &intel_crtc
->base
,
13349 &primary
->base
, &cursor
->base
,
13351 "pipe %c", pipe_name(pipe
));
13355 intel_crtc
->pipe
= pipe
;
13356 intel_crtc
->plane
= primary
->plane
;
13358 /* initialize shared scalers */
13359 intel_crtc_init_scalers(intel_crtc
, crtc_state
);
13361 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
13362 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
13363 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = intel_crtc
;
13364 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = intel_crtc
;
13366 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
13368 intel_color_init(&intel_crtc
->base
);
13370 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
13376 * drm_mode_config_cleanup() will free up any
13377 * crtcs/planes already initialized.
13385 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
13387 struct drm_device
*dev
= connector
->base
.dev
;
13389 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
13391 if (!connector
->base
.state
->crtc
)
13392 return INVALID_PIPE
;
13394 return to_intel_crtc(connector
->base
.state
->crtc
)->pipe
;
13397 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
13398 struct drm_file
*file
)
13400 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
13401 struct drm_crtc
*drmmode_crtc
;
13402 struct intel_crtc
*crtc
;
13404 drmmode_crtc
= drm_crtc_find(dev
, pipe_from_crtc_id
->crtc_id
);
13408 crtc
= to_intel_crtc(drmmode_crtc
);
13409 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
13414 static int intel_encoder_clones(struct intel_encoder
*encoder
)
13416 struct drm_device
*dev
= encoder
->base
.dev
;
13417 struct intel_encoder
*source_encoder
;
13418 int index_mask
= 0;
13421 for_each_intel_encoder(dev
, source_encoder
) {
13422 if (encoders_cloneable(encoder
, source_encoder
))
13423 index_mask
|= (1 << entry
);
13431 static bool has_edp_a(struct drm_i915_private
*dev_priv
)
13433 if (!IS_MOBILE(dev_priv
))
13436 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
13439 if (IS_GEN5(dev_priv
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
13445 static bool intel_crt_present(struct drm_i915_private
*dev_priv
)
13447 if (INTEL_GEN(dev_priv
) >= 9)
13450 if (IS_HSW_ULT(dev_priv
) || IS_BDW_ULT(dev_priv
))
13453 if (IS_CHERRYVIEW(dev_priv
))
13456 if (HAS_PCH_LPT_H(dev_priv
) &&
13457 I915_READ(SFUSE_STRAP
) & SFUSE_STRAP_CRT_DISABLED
)
13460 /* DDI E can't be used if DDI A requires 4 lanes */
13461 if (HAS_DDI(dev_priv
) && I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_A_4_LANES
)
13464 if (!dev_priv
->vbt
.int_crt_support
)
13470 void intel_pps_unlock_regs_wa(struct drm_i915_private
*dev_priv
)
13475 if (HAS_DDI(dev_priv
))
13478 * This w/a is needed at least on CPT/PPT, but to be sure apply it
13479 * everywhere where registers can be write protected.
13481 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
13486 for (pps_idx
= 0; pps_idx
< pps_num
; pps_idx
++) {
13487 u32 val
= I915_READ(PP_CONTROL(pps_idx
));
13489 val
= (val
& ~PANEL_UNLOCK_MASK
) | PANEL_UNLOCK_REGS
;
13490 I915_WRITE(PP_CONTROL(pps_idx
), val
);
13494 static void intel_pps_init(struct drm_i915_private
*dev_priv
)
13496 if (HAS_PCH_SPLIT(dev_priv
) || IS_GEN9_LP(dev_priv
))
13497 dev_priv
->pps_mmio_base
= PCH_PPS_BASE
;
13498 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
13499 dev_priv
->pps_mmio_base
= VLV_PPS_BASE
;
13501 dev_priv
->pps_mmio_base
= PPS_BASE
;
13503 intel_pps_unlock_regs_wa(dev_priv
);
13506 static void intel_setup_outputs(struct drm_i915_private
*dev_priv
)
13508 struct intel_encoder
*encoder
;
13509 bool dpd_is_edp
= false;
13511 intel_pps_init(dev_priv
);
13514 * intel_edp_init_connector() depends on this completing first, to
13515 * prevent the registeration of both eDP and LVDS and the incorrect
13516 * sharing of the PPS.
13518 intel_lvds_init(dev_priv
);
13520 if (intel_crt_present(dev_priv
))
13521 intel_crt_init(dev_priv
);
13523 if (IS_GEN9_LP(dev_priv
)) {
13525 * FIXME: Broxton doesn't support port detection via the
13526 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
13527 * detect the ports.
13529 intel_ddi_init(dev_priv
, PORT_A
);
13530 intel_ddi_init(dev_priv
, PORT_B
);
13531 intel_ddi_init(dev_priv
, PORT_C
);
13533 intel_dsi_init(dev_priv
);
13534 } else if (HAS_DDI(dev_priv
)) {
13538 * Haswell uses DDI functions to detect digital outputs.
13539 * On SKL pre-D0 the strap isn't connected, so we assume
13542 found
= I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_INIT_DISPLAY_DETECTED
;
13543 /* WaIgnoreDDIAStrap: skl */
13544 if (found
|| IS_GEN9_BC(dev_priv
))
13545 intel_ddi_init(dev_priv
, PORT_A
);
13547 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
13549 found
= I915_READ(SFUSE_STRAP
);
13551 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
13552 intel_ddi_init(dev_priv
, PORT_B
);
13553 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
13554 intel_ddi_init(dev_priv
, PORT_C
);
13555 if (found
& SFUSE_STRAP_DDID_DETECTED
)
13556 intel_ddi_init(dev_priv
, PORT_D
);
13558 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
13560 if (IS_GEN9_BC(dev_priv
) &&
13561 (dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dp
||
13562 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dvi
||
13563 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_hdmi
))
13564 intel_ddi_init(dev_priv
, PORT_E
);
13566 } else if (HAS_PCH_SPLIT(dev_priv
)) {
13568 dpd_is_edp
= intel_dp_is_edp(dev_priv
, PORT_D
);
13570 if (has_edp_a(dev_priv
))
13571 intel_dp_init(dev_priv
, DP_A
, PORT_A
);
13573 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
13574 /* PCH SDVOB multiplex with HDMIB */
13575 found
= intel_sdvo_init(dev_priv
, PCH_SDVOB
, PORT_B
);
13577 intel_hdmi_init(dev_priv
, PCH_HDMIB
, PORT_B
);
13578 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
13579 intel_dp_init(dev_priv
, PCH_DP_B
, PORT_B
);
13582 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
13583 intel_hdmi_init(dev_priv
, PCH_HDMIC
, PORT_C
);
13585 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
13586 intel_hdmi_init(dev_priv
, PCH_HDMID
, PORT_D
);
13588 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
13589 intel_dp_init(dev_priv
, PCH_DP_C
, PORT_C
);
13591 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
13592 intel_dp_init(dev_priv
, PCH_DP_D
, PORT_D
);
13593 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
13594 bool has_edp
, has_port
;
13597 * The DP_DETECTED bit is the latched state of the DDC
13598 * SDA pin at boot. However since eDP doesn't require DDC
13599 * (no way to plug in a DP->HDMI dongle) the DDC pins for
13600 * eDP ports may have been muxed to an alternate function.
13601 * Thus we can't rely on the DP_DETECTED bit alone to detect
13602 * eDP ports. Consult the VBT as well as DP_DETECTED to
13603 * detect eDP ports.
13605 * Sadly the straps seem to be missing sometimes even for HDMI
13606 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
13607 * and VBT for the presence of the port. Additionally we can't
13608 * trust the port type the VBT declares as we've seen at least
13609 * HDMI ports that the VBT claim are DP or eDP.
13611 has_edp
= intel_dp_is_edp(dev_priv
, PORT_B
);
13612 has_port
= intel_bios_is_port_present(dev_priv
, PORT_B
);
13613 if (I915_READ(VLV_DP_B
) & DP_DETECTED
|| has_port
)
13614 has_edp
&= intel_dp_init(dev_priv
, VLV_DP_B
, PORT_B
);
13615 if ((I915_READ(VLV_HDMIB
) & SDVO_DETECTED
|| has_port
) && !has_edp
)
13616 intel_hdmi_init(dev_priv
, VLV_HDMIB
, PORT_B
);
13618 has_edp
= intel_dp_is_edp(dev_priv
, PORT_C
);
13619 has_port
= intel_bios_is_port_present(dev_priv
, PORT_C
);
13620 if (I915_READ(VLV_DP_C
) & DP_DETECTED
|| has_port
)
13621 has_edp
&= intel_dp_init(dev_priv
, VLV_DP_C
, PORT_C
);
13622 if ((I915_READ(VLV_HDMIC
) & SDVO_DETECTED
|| has_port
) && !has_edp
)
13623 intel_hdmi_init(dev_priv
, VLV_HDMIC
, PORT_C
);
13625 if (IS_CHERRYVIEW(dev_priv
)) {
13627 * eDP not supported on port D,
13628 * so no need to worry about it
13630 has_port
= intel_bios_is_port_present(dev_priv
, PORT_D
);
13631 if (I915_READ(CHV_DP_D
) & DP_DETECTED
|| has_port
)
13632 intel_dp_init(dev_priv
, CHV_DP_D
, PORT_D
);
13633 if (I915_READ(CHV_HDMID
) & SDVO_DETECTED
|| has_port
)
13634 intel_hdmi_init(dev_priv
, CHV_HDMID
, PORT_D
);
13637 intel_dsi_init(dev_priv
);
13638 } else if (!IS_GEN2(dev_priv
) && !IS_PINEVIEW(dev_priv
)) {
13639 bool found
= false;
13641 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
13642 DRM_DEBUG_KMS("probing SDVOB\n");
13643 found
= intel_sdvo_init(dev_priv
, GEN3_SDVOB
, PORT_B
);
13644 if (!found
&& IS_G4X(dev_priv
)) {
13645 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
13646 intel_hdmi_init(dev_priv
, GEN4_HDMIB
, PORT_B
);
13649 if (!found
&& IS_G4X(dev_priv
))
13650 intel_dp_init(dev_priv
, DP_B
, PORT_B
);
13653 /* Before G4X SDVOC doesn't have its own detect register */
13655 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
13656 DRM_DEBUG_KMS("probing SDVOC\n");
13657 found
= intel_sdvo_init(dev_priv
, GEN3_SDVOC
, PORT_C
);
13660 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
13662 if (IS_G4X(dev_priv
)) {
13663 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
13664 intel_hdmi_init(dev_priv
, GEN4_HDMIC
, PORT_C
);
13666 if (IS_G4X(dev_priv
))
13667 intel_dp_init(dev_priv
, DP_C
, PORT_C
);
13670 if (IS_G4X(dev_priv
) && (I915_READ(DP_D
) & DP_DETECTED
))
13671 intel_dp_init(dev_priv
, DP_D
, PORT_D
);
13672 } else if (IS_GEN2(dev_priv
))
13673 intel_dvo_init(dev_priv
);
13675 if (SUPPORTS_TV(dev_priv
))
13676 intel_tv_init(dev_priv
);
13678 intel_psr_init(dev_priv
);
13680 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
13681 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
13682 encoder
->base
.possible_clones
=
13683 intel_encoder_clones(encoder
);
13686 intel_init_pch_refclk(dev_priv
);
13688 drm_helper_move_panel_connectors_to_head(&dev_priv
->drm
);
13691 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
13693 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
13695 drm_framebuffer_cleanup(fb
);
13697 i915_gem_object_lock(intel_fb
->obj
);
13698 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
13699 i915_gem_object_unlock(intel_fb
->obj
);
13701 i915_gem_object_put(intel_fb
->obj
);
13706 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
13707 struct drm_file
*file
,
13708 unsigned int *handle
)
13710 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
13711 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
13713 if (obj
->userptr
.mm
) {
13714 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
13718 return drm_gem_handle_create(file
, &obj
->base
, handle
);
13721 static int intel_user_framebuffer_dirty(struct drm_framebuffer
*fb
,
13722 struct drm_file
*file
,
13723 unsigned flags
, unsigned color
,
13724 struct drm_clip_rect
*clips
,
13725 unsigned num_clips
)
13727 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13729 i915_gem_object_flush_if_display(obj
);
13730 intel_fb_obj_flush(obj
, ORIGIN_DIRTYFB
);
13735 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
13736 .destroy
= intel_user_framebuffer_destroy
,
13737 .create_handle
= intel_user_framebuffer_create_handle
,
13738 .dirty
= intel_user_framebuffer_dirty
,
13742 u32
intel_fb_pitch_limit(struct drm_i915_private
*dev_priv
,
13743 uint64_t fb_modifier
, uint32_t pixel_format
)
13745 u32 gen
= INTEL_GEN(dev_priv
);
13748 int cpp
= drm_format_plane_cpp(pixel_format
, 0);
13750 /* "The stride in bytes must not exceed the of the size of 8K
13751 * pixels and 32K bytes."
13753 return min(8192 * cpp
, 32768);
13754 } else if (gen
>= 5 && !HAS_GMCH_DISPLAY(dev_priv
)) {
13756 } else if (gen
>= 4) {
13757 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
13761 } else if (gen
>= 3) {
13762 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
13767 /* XXX DSPC is limited to 4k tiled */
13772 static int intel_framebuffer_init(struct intel_framebuffer
*intel_fb
,
13773 struct drm_i915_gem_object
*obj
,
13774 struct drm_mode_fb_cmd2
*mode_cmd
)
13776 struct drm_i915_private
*dev_priv
= to_i915(obj
->base
.dev
);
13777 struct drm_format_name_buf format_name
;
13778 u32 pitch_limit
, stride_alignment
;
13779 unsigned int tiling
, stride
;
13782 i915_gem_object_lock(obj
);
13783 obj
->framebuffer_references
++;
13784 tiling
= i915_gem_object_get_tiling(obj
);
13785 stride
= i915_gem_object_get_stride(obj
);
13786 i915_gem_object_unlock(obj
);
13788 if (mode_cmd
->flags
& DRM_MODE_FB_MODIFIERS
) {
13790 * If there's a fence, enforce that
13791 * the fb modifier and tiling mode match.
13793 if (tiling
!= I915_TILING_NONE
&&
13794 tiling
!= intel_fb_modifier_to_tiling(mode_cmd
->modifier
[0])) {
13795 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
13799 if (tiling
== I915_TILING_X
) {
13800 mode_cmd
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
13801 } else if (tiling
== I915_TILING_Y
) {
13802 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
13807 /* Passed in modifier sanity checking. */
13808 switch (mode_cmd
->modifier
[0]) {
13809 case I915_FORMAT_MOD_Y_TILED
:
13810 case I915_FORMAT_MOD_Yf_TILED
:
13811 if (INTEL_GEN(dev_priv
) < 9) {
13812 DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n",
13813 mode_cmd
->modifier
[0]);
13816 case DRM_FORMAT_MOD_LINEAR
:
13817 case I915_FORMAT_MOD_X_TILED
:
13820 DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n",
13821 mode_cmd
->modifier
[0]);
13826 * gen2/3 display engine uses the fence if present,
13827 * so the tiling mode must match the fb modifier exactly.
13829 if (INTEL_INFO(dev_priv
)->gen
< 4 &&
13830 tiling
!= intel_fb_modifier_to_tiling(mode_cmd
->modifier
[0])) {
13831 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
13835 pitch_limit
= intel_fb_pitch_limit(dev_priv
, mode_cmd
->modifier
[0],
13836 mode_cmd
->pixel_format
);
13837 if (mode_cmd
->pitches
[0] > pitch_limit
) {
13838 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
13839 mode_cmd
->modifier
[0] != DRM_FORMAT_MOD_LINEAR
?
13840 "tiled" : "linear",
13841 mode_cmd
->pitches
[0], pitch_limit
);
13846 * If there's a fence, enforce that
13847 * the fb pitch and fence stride match.
13849 if (tiling
!= I915_TILING_NONE
&& mode_cmd
->pitches
[0] != stride
) {
13850 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
13851 mode_cmd
->pitches
[0], stride
);
13855 /* Reject formats not supported by any plane early. */
13856 switch (mode_cmd
->pixel_format
) {
13857 case DRM_FORMAT_C8
:
13858 case DRM_FORMAT_RGB565
:
13859 case DRM_FORMAT_XRGB8888
:
13860 case DRM_FORMAT_ARGB8888
:
13862 case DRM_FORMAT_XRGB1555
:
13863 if (INTEL_GEN(dev_priv
) > 3) {
13864 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13865 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13869 case DRM_FORMAT_ABGR8888
:
13870 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
) &&
13871 INTEL_GEN(dev_priv
) < 9) {
13872 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13873 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13877 case DRM_FORMAT_XBGR8888
:
13878 case DRM_FORMAT_XRGB2101010
:
13879 case DRM_FORMAT_XBGR2101010
:
13880 if (INTEL_GEN(dev_priv
) < 4) {
13881 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13882 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13886 case DRM_FORMAT_ABGR2101010
:
13887 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
)) {
13888 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13889 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13893 case DRM_FORMAT_YUYV
:
13894 case DRM_FORMAT_UYVY
:
13895 case DRM_FORMAT_YVYU
:
13896 case DRM_FORMAT_VYUY
:
13897 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
)) {
13898 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13899 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13904 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13905 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13909 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
13910 if (mode_cmd
->offsets
[0] != 0)
13913 drm_helper_mode_fill_fb_struct(&dev_priv
->drm
,
13914 &intel_fb
->base
, mode_cmd
);
13916 stride_alignment
= intel_fb_stride_alignment(&intel_fb
->base
, 0);
13917 if (mode_cmd
->pitches
[0] & (stride_alignment
- 1)) {
13918 DRM_DEBUG_KMS("pitch (%d) must be at least %u byte aligned\n",
13919 mode_cmd
->pitches
[0], stride_alignment
);
13923 intel_fb
->obj
= obj
;
13925 ret
= intel_fill_fb_info(dev_priv
, &intel_fb
->base
);
13929 ret
= drm_framebuffer_init(obj
->base
.dev
,
13933 DRM_ERROR("framebuffer init failed %d\n", ret
);
13940 i915_gem_object_lock(obj
);
13941 obj
->framebuffer_references
--;
13942 i915_gem_object_unlock(obj
);
13946 static struct drm_framebuffer
*
13947 intel_user_framebuffer_create(struct drm_device
*dev
,
13948 struct drm_file
*filp
,
13949 const struct drm_mode_fb_cmd2
*user_mode_cmd
)
13951 struct drm_framebuffer
*fb
;
13952 struct drm_i915_gem_object
*obj
;
13953 struct drm_mode_fb_cmd2 mode_cmd
= *user_mode_cmd
;
13955 obj
= i915_gem_object_lookup(filp
, mode_cmd
.handles
[0]);
13957 return ERR_PTR(-ENOENT
);
13959 fb
= intel_framebuffer_create(obj
, &mode_cmd
);
13961 i915_gem_object_put(obj
);
13966 static void intel_atomic_state_free(struct drm_atomic_state
*state
)
13968 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
13970 drm_atomic_state_default_release(state
);
13972 i915_sw_fence_fini(&intel_state
->commit_ready
);
13977 static const struct drm_mode_config_funcs intel_mode_funcs
= {
13978 .fb_create
= intel_user_framebuffer_create
,
13979 .output_poll_changed
= intel_fbdev_output_poll_changed
,
13980 .atomic_check
= intel_atomic_check
,
13981 .atomic_commit
= intel_atomic_commit
,
13982 .atomic_state_alloc
= intel_atomic_state_alloc
,
13983 .atomic_state_clear
= intel_atomic_state_clear
,
13984 .atomic_state_free
= intel_atomic_state_free
,
13988 * intel_init_display_hooks - initialize the display modesetting hooks
13989 * @dev_priv: device private
13991 void intel_init_display_hooks(struct drm_i915_private
*dev_priv
)
13993 intel_init_cdclk_hooks(dev_priv
);
13995 if (INTEL_INFO(dev_priv
)->gen
>= 9) {
13996 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
13997 dev_priv
->display
.get_initial_plane_config
=
13998 skylake_get_initial_plane_config
;
13999 dev_priv
->display
.crtc_compute_clock
=
14000 haswell_crtc_compute_clock
;
14001 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
14002 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
14003 } else if (HAS_DDI(dev_priv
)) {
14004 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
14005 dev_priv
->display
.get_initial_plane_config
=
14006 ironlake_get_initial_plane_config
;
14007 dev_priv
->display
.crtc_compute_clock
=
14008 haswell_crtc_compute_clock
;
14009 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
14010 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
14011 } else if (HAS_PCH_SPLIT(dev_priv
)) {
14012 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
14013 dev_priv
->display
.get_initial_plane_config
=
14014 ironlake_get_initial_plane_config
;
14015 dev_priv
->display
.crtc_compute_clock
=
14016 ironlake_crtc_compute_clock
;
14017 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
14018 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
14019 } else if (IS_CHERRYVIEW(dev_priv
)) {
14020 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14021 dev_priv
->display
.get_initial_plane_config
=
14022 i9xx_get_initial_plane_config
;
14023 dev_priv
->display
.crtc_compute_clock
= chv_crtc_compute_clock
;
14024 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
14025 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14026 } else if (IS_VALLEYVIEW(dev_priv
)) {
14027 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14028 dev_priv
->display
.get_initial_plane_config
=
14029 i9xx_get_initial_plane_config
;
14030 dev_priv
->display
.crtc_compute_clock
= vlv_crtc_compute_clock
;
14031 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
14032 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14033 } else if (IS_G4X(dev_priv
)) {
14034 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14035 dev_priv
->display
.get_initial_plane_config
=
14036 i9xx_get_initial_plane_config
;
14037 dev_priv
->display
.crtc_compute_clock
= g4x_crtc_compute_clock
;
14038 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14039 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14040 } else if (IS_PINEVIEW(dev_priv
)) {
14041 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14042 dev_priv
->display
.get_initial_plane_config
=
14043 i9xx_get_initial_plane_config
;
14044 dev_priv
->display
.crtc_compute_clock
= pnv_crtc_compute_clock
;
14045 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14046 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14047 } else if (!IS_GEN2(dev_priv
)) {
14048 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14049 dev_priv
->display
.get_initial_plane_config
=
14050 i9xx_get_initial_plane_config
;
14051 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
14052 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14053 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14055 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14056 dev_priv
->display
.get_initial_plane_config
=
14057 i9xx_get_initial_plane_config
;
14058 dev_priv
->display
.crtc_compute_clock
= i8xx_crtc_compute_clock
;
14059 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14060 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14063 if (IS_GEN5(dev_priv
)) {
14064 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
14065 } else if (IS_GEN6(dev_priv
)) {
14066 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
14067 } else if (IS_IVYBRIDGE(dev_priv
)) {
14068 /* FIXME: detect B0+ stepping and use auto training */
14069 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
14070 } else if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
14071 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
14074 if (dev_priv
->info
.gen
>= 9)
14075 dev_priv
->display
.update_crtcs
= skl_update_crtcs
;
14077 dev_priv
->display
.update_crtcs
= intel_update_crtcs
;
14081 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
14083 static void quirk_ssc_force_disable(struct drm_device
*dev
)
14085 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14086 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
14087 DRM_INFO("applying lvds SSC disable quirk\n");
14091 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
14094 static void quirk_invert_brightness(struct drm_device
*dev
)
14096 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14097 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
14098 DRM_INFO("applying inverted panel brightness quirk\n");
14101 /* Some VBT's incorrectly indicate no backlight is present */
14102 static void quirk_backlight_present(struct drm_device
*dev
)
14104 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14105 dev_priv
->quirks
|= QUIRK_BACKLIGHT_PRESENT
;
14106 DRM_INFO("applying backlight present quirk\n");
14109 /* Toshiba Satellite P50-C-18C requires T12 delay to be min 800ms
14110 * which is 300 ms greater than eDP spec T12 min.
14112 static void quirk_increase_t12_delay(struct drm_device
*dev
)
14114 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14116 dev_priv
->quirks
|= QUIRK_INCREASE_T12_DELAY
;
14117 DRM_INFO("Applying T12 delay quirk\n");
14120 struct intel_quirk
{
14122 int subsystem_vendor
;
14123 int subsystem_device
;
14124 void (*hook
)(struct drm_device
*dev
);
14127 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
14128 struct intel_dmi_quirk
{
14129 void (*hook
)(struct drm_device
*dev
);
14130 const struct dmi_system_id (*dmi_id_list
)[];
14133 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
14135 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
14139 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
14141 .dmi_id_list
= &(const struct dmi_system_id
[]) {
14143 .callback
= intel_dmi_reverse_brightness
,
14144 .ident
= "NCR Corporation",
14145 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
14146 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
14149 { } /* terminating entry */
14151 .hook
= quirk_invert_brightness
,
14155 static struct intel_quirk intel_quirks
[] = {
14156 /* Lenovo U160 cannot use SSC on LVDS */
14157 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
14159 /* Sony Vaio Y cannot use SSC on LVDS */
14160 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
14162 /* Acer Aspire 5734Z must invert backlight brightness */
14163 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
14165 /* Acer/eMachines G725 */
14166 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
14168 /* Acer/eMachines e725 */
14169 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
14171 /* Acer/Packard Bell NCL20 */
14172 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
14174 /* Acer Aspire 4736Z */
14175 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
14177 /* Acer Aspire 5336 */
14178 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
14180 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
14181 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present
},
14183 /* Acer C720 Chromebook (Core i3 4005U) */
14184 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present
},
14186 /* Apple Macbook 2,1 (Core 2 T7400) */
14187 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present
},
14189 /* Apple Macbook 4,1 */
14190 { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present
},
14192 /* Toshiba CB35 Chromebook (Celeron 2955U) */
14193 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present
},
14195 /* HP Chromebook 14 (Celeron 2955U) */
14196 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present
},
14198 /* Dell Chromebook 11 */
14199 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present
},
14201 /* Dell Chromebook 11 (2015 version) */
14202 { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present
},
14204 /* Toshiba Satellite P50-C-18C */
14205 { 0x191B, 0x1179, 0xF840, quirk_increase_t12_delay
},
14208 static void intel_init_quirks(struct drm_device
*dev
)
14210 struct pci_dev
*d
= dev
->pdev
;
14213 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
14214 struct intel_quirk
*q
= &intel_quirks
[i
];
14216 if (d
->device
== q
->device
&&
14217 (d
->subsystem_vendor
== q
->subsystem_vendor
||
14218 q
->subsystem_vendor
== PCI_ANY_ID
) &&
14219 (d
->subsystem_device
== q
->subsystem_device
||
14220 q
->subsystem_device
== PCI_ANY_ID
))
14223 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
14224 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
14225 intel_dmi_quirks
[i
].hook(dev
);
14229 /* Disable the VGA plane that we never use */
14230 static void i915_disable_vga(struct drm_i915_private
*dev_priv
)
14232 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
14234 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev_priv
);
14236 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
14237 vga_get_uninterruptible(pdev
, VGA_RSRC_LEGACY_IO
);
14238 outb(SR01
, VGA_SR_INDEX
);
14239 sr1
= inb(VGA_SR_DATA
);
14240 outb(sr1
| 1<<5, VGA_SR_DATA
);
14241 vga_put(pdev
, VGA_RSRC_LEGACY_IO
);
14244 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
14245 POSTING_READ(vga_reg
);
14248 void intel_modeset_init_hw(struct drm_device
*dev
)
14250 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14252 intel_update_cdclk(dev_priv
);
14253 dev_priv
->cdclk
.logical
= dev_priv
->cdclk
.actual
= dev_priv
->cdclk
.hw
;
14255 intel_init_clock_gating(dev_priv
);
14259 * Calculate what we think the watermarks should be for the state we've read
14260 * out of the hardware and then immediately program those watermarks so that
14261 * we ensure the hardware settings match our internal state.
14263 * We can calculate what we think WM's should be by creating a duplicate of the
14264 * current state (which was constructed during hardware readout) and running it
14265 * through the atomic check code to calculate new watermark values in the
14268 static void sanitize_watermarks(struct drm_device
*dev
)
14270 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14271 struct drm_atomic_state
*state
;
14272 struct intel_atomic_state
*intel_state
;
14273 struct drm_crtc
*crtc
;
14274 struct drm_crtc_state
*cstate
;
14275 struct drm_modeset_acquire_ctx ctx
;
14279 /* Only supported on platforms that use atomic watermark design */
14280 if (!dev_priv
->display
.optimize_watermarks
)
14284 * We need to hold connection_mutex before calling duplicate_state so
14285 * that the connector loop is protected.
14287 drm_modeset_acquire_init(&ctx
, 0);
14289 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
14290 if (ret
== -EDEADLK
) {
14291 drm_modeset_backoff(&ctx
);
14293 } else if (WARN_ON(ret
)) {
14297 state
= drm_atomic_helper_duplicate_state(dev
, &ctx
);
14298 if (WARN_ON(IS_ERR(state
)))
14301 intel_state
= to_intel_atomic_state(state
);
14304 * Hardware readout is the only time we don't want to calculate
14305 * intermediate watermarks (since we don't trust the current
14308 if (!HAS_GMCH_DISPLAY(dev_priv
))
14309 intel_state
->skip_intermediate_wm
= true;
14311 ret
= intel_atomic_check(dev
, state
);
14314 * If we fail here, it means that the hardware appears to be
14315 * programmed in a way that shouldn't be possible, given our
14316 * understanding of watermark requirements. This might mean a
14317 * mistake in the hardware readout code or a mistake in the
14318 * watermark calculations for a given platform. Raise a WARN
14319 * so that this is noticeable.
14321 * If this actually happens, we'll have to just leave the
14322 * BIOS-programmed watermarks untouched and hope for the best.
14324 WARN(true, "Could not determine valid watermarks for inherited state\n");
14328 /* Write calculated watermark values back */
14329 for_each_new_crtc_in_state(state
, crtc
, cstate
, i
) {
14330 struct intel_crtc_state
*cs
= to_intel_crtc_state(cstate
);
14332 cs
->wm
.need_postvbl_update
= true;
14333 dev_priv
->display
.optimize_watermarks(intel_state
, cs
);
14337 drm_atomic_state_put(state
);
14339 drm_modeset_drop_locks(&ctx
);
14340 drm_modeset_acquire_fini(&ctx
);
14343 int intel_modeset_init(struct drm_device
*dev
)
14345 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14346 struct i915_ggtt
*ggtt
= &dev_priv
->ggtt
;
14348 struct intel_crtc
*crtc
;
14350 drm_mode_config_init(dev
);
14352 dev
->mode_config
.min_width
= 0;
14353 dev
->mode_config
.min_height
= 0;
14355 dev
->mode_config
.preferred_depth
= 24;
14356 dev
->mode_config
.prefer_shadow
= 1;
14358 dev
->mode_config
.allow_fb_modifiers
= true;
14360 dev
->mode_config
.funcs
= &intel_mode_funcs
;
14362 init_llist_head(&dev_priv
->atomic_helper
.free_list
);
14363 INIT_WORK(&dev_priv
->atomic_helper
.free_work
,
14364 intel_atomic_helper_free_state_worker
);
14366 intel_init_quirks(dev
);
14368 intel_init_pm(dev_priv
);
14370 if (INTEL_INFO(dev_priv
)->num_pipes
== 0)
14374 * There may be no VBT; and if the BIOS enabled SSC we can
14375 * just keep using it to avoid unnecessary flicker. Whereas if the
14376 * BIOS isn't using it, don't assume it will work even if the VBT
14377 * indicates as much.
14379 if (HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
)) {
14380 bool bios_lvds_use_ssc
= !!(I915_READ(PCH_DREF_CONTROL
) &
14383 if (dev_priv
->vbt
.lvds_use_ssc
!= bios_lvds_use_ssc
) {
14384 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
14385 bios_lvds_use_ssc
? "en" : "dis",
14386 dev_priv
->vbt
.lvds_use_ssc
? "en" : "dis");
14387 dev_priv
->vbt
.lvds_use_ssc
= bios_lvds_use_ssc
;
14391 if (IS_GEN2(dev_priv
)) {
14392 dev
->mode_config
.max_width
= 2048;
14393 dev
->mode_config
.max_height
= 2048;
14394 } else if (IS_GEN3(dev_priv
)) {
14395 dev
->mode_config
.max_width
= 4096;
14396 dev
->mode_config
.max_height
= 4096;
14398 dev
->mode_config
.max_width
= 8192;
14399 dev
->mode_config
.max_height
= 8192;
14402 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
)) {
14403 dev
->mode_config
.cursor_width
= IS_I845G(dev_priv
) ? 64 : 512;
14404 dev
->mode_config
.cursor_height
= 1023;
14405 } else if (IS_GEN2(dev_priv
)) {
14406 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
14407 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
14409 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
14410 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
14413 dev
->mode_config
.fb_base
= ggtt
->mappable_base
;
14415 DRM_DEBUG_KMS("%d display pipe%s available.\n",
14416 INTEL_INFO(dev_priv
)->num_pipes
,
14417 INTEL_INFO(dev_priv
)->num_pipes
> 1 ? "s" : "");
14419 for_each_pipe(dev_priv
, pipe
) {
14422 ret
= intel_crtc_init(dev_priv
, pipe
);
14424 drm_mode_config_cleanup(dev
);
14429 intel_shared_dpll_init(dev
);
14431 intel_update_czclk(dev_priv
);
14432 intel_modeset_init_hw(dev
);
14434 if (dev_priv
->max_cdclk_freq
== 0)
14435 intel_update_max_cdclk(dev_priv
);
14437 /* Just disable it once at startup */
14438 i915_disable_vga(dev_priv
);
14439 intel_setup_outputs(dev_priv
);
14441 drm_modeset_lock_all(dev
);
14442 intel_modeset_setup_hw_state(dev
, dev
->mode_config
.acquire_ctx
);
14443 drm_modeset_unlock_all(dev
);
14445 for_each_intel_crtc(dev
, crtc
) {
14446 struct intel_initial_plane_config plane_config
= {};
14452 * Note that reserving the BIOS fb up front prevents us
14453 * from stuffing other stolen allocations like the ring
14454 * on top. This prevents some ugliness at boot time, and
14455 * can even allow for smooth boot transitions if the BIOS
14456 * fb is large enough for the active pipe configuration.
14458 dev_priv
->display
.get_initial_plane_config(crtc
,
14462 * If the fb is shared between multiple heads, we'll
14463 * just get the first one.
14465 intel_find_initial_plane_obj(crtc
, &plane_config
);
14469 * Make sure hardware watermarks really match the state we read out.
14470 * Note that we need to do this after reconstructing the BIOS fb's
14471 * since the watermark calculation done here will use pstate->fb.
14473 if (!HAS_GMCH_DISPLAY(dev_priv
))
14474 sanitize_watermarks(dev
);
14479 void i830_enable_pipe(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
14481 /* 640x480@60Hz, ~25175 kHz */
14482 struct dpll clock
= {
14492 WARN_ON(i9xx_calc_dpll_params(48000, &clock
) != 25154);
14494 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
14495 pipe_name(pipe
), clock
.vco
, clock
.dot
);
14497 fp
= i9xx_dpll_compute_fp(&clock
);
14498 dpll
= (I915_READ(DPLL(pipe
)) & DPLL_DVO_2X_MODE
) |
14499 DPLL_VGA_MODE_DIS
|
14500 ((clock
.p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
) |
14501 PLL_P2_DIVIDE_BY_4
|
14502 PLL_REF_INPUT_DREFCLK
|
14505 I915_WRITE(FP0(pipe
), fp
);
14506 I915_WRITE(FP1(pipe
), fp
);
14508 I915_WRITE(HTOTAL(pipe
), (640 - 1) | ((800 - 1) << 16));
14509 I915_WRITE(HBLANK(pipe
), (640 - 1) | ((800 - 1) << 16));
14510 I915_WRITE(HSYNC(pipe
), (656 - 1) | ((752 - 1) << 16));
14511 I915_WRITE(VTOTAL(pipe
), (480 - 1) | ((525 - 1) << 16));
14512 I915_WRITE(VBLANK(pipe
), (480 - 1) | ((525 - 1) << 16));
14513 I915_WRITE(VSYNC(pipe
), (490 - 1) | ((492 - 1) << 16));
14514 I915_WRITE(PIPESRC(pipe
), ((640 - 1) << 16) | (480 - 1));
14517 * Apparently we need to have VGA mode enabled prior to changing
14518 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
14519 * dividers, even though the register value does change.
14521 I915_WRITE(DPLL(pipe
), dpll
& ~DPLL_VGA_MODE_DIS
);
14522 I915_WRITE(DPLL(pipe
), dpll
);
14524 /* Wait for the clocks to stabilize. */
14525 POSTING_READ(DPLL(pipe
));
14528 /* The pixel multiplier can only be updated once the
14529 * DPLL is enabled and the clocks are stable.
14531 * So write it again.
14533 I915_WRITE(DPLL(pipe
), dpll
);
14535 /* We do this three times for luck */
14536 for (i
= 0; i
< 3 ; i
++) {
14537 I915_WRITE(DPLL(pipe
), dpll
);
14538 POSTING_READ(DPLL(pipe
));
14539 udelay(150); /* wait for warmup */
14542 I915_WRITE(PIPECONF(pipe
), PIPECONF_ENABLE
| PIPECONF_PROGRESSIVE
);
14543 POSTING_READ(PIPECONF(pipe
));
14546 void i830_disable_pipe(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
14548 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
14551 assert_plane_disabled(dev_priv
, PLANE_A
);
14552 assert_plane_disabled(dev_priv
, PLANE_B
);
14554 I915_WRITE(PIPECONF(pipe
), 0);
14555 POSTING_READ(PIPECONF(pipe
));
14557 if (wait_for(pipe_dsl_stopped(dev_priv
, pipe
), 100))
14558 DRM_ERROR("pipe %c off wait timed out\n", pipe_name(pipe
));
14560 I915_WRITE(DPLL(pipe
), DPLL_VGA_MODE_DIS
);
14561 POSTING_READ(DPLL(pipe
));
14565 intel_check_plane_mapping(struct intel_crtc
*crtc
)
14567 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
14570 if (INTEL_INFO(dev_priv
)->num_pipes
== 1)
14573 val
= I915_READ(DSPCNTR(!crtc
->plane
));
14575 if ((val
& DISPLAY_PLANE_ENABLE
) &&
14576 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
14582 static bool intel_crtc_has_encoders(struct intel_crtc
*crtc
)
14584 struct drm_device
*dev
= crtc
->base
.dev
;
14585 struct intel_encoder
*encoder
;
14587 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
14593 static struct intel_connector
*intel_encoder_find_connector(struct intel_encoder
*encoder
)
14595 struct drm_device
*dev
= encoder
->base
.dev
;
14596 struct intel_connector
*connector
;
14598 for_each_connector_on_encoder(dev
, &encoder
->base
, connector
)
14604 static bool has_pch_trancoder(struct drm_i915_private
*dev_priv
,
14605 enum transcoder pch_transcoder
)
14607 return HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
) ||
14608 (HAS_PCH_LPT_H(dev_priv
) && pch_transcoder
== TRANSCODER_A
);
14611 static void intel_sanitize_crtc(struct intel_crtc
*crtc
,
14612 struct drm_modeset_acquire_ctx
*ctx
)
14614 struct drm_device
*dev
= crtc
->base
.dev
;
14615 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14616 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
14618 /* Clear any frame start delays used for debugging left by the BIOS */
14619 if (!transcoder_is_dsi(cpu_transcoder
)) {
14620 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
14623 I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
14626 /* restore vblank interrupts to correct state */
14627 drm_crtc_vblank_reset(&crtc
->base
);
14628 if (crtc
->active
) {
14629 struct intel_plane
*plane
;
14631 drm_crtc_vblank_on(&crtc
->base
);
14633 /* Disable everything but the primary plane */
14634 for_each_intel_plane_on_crtc(dev
, crtc
, plane
) {
14635 if (plane
->base
.type
== DRM_PLANE_TYPE_PRIMARY
)
14638 trace_intel_disable_plane(&plane
->base
, crtc
);
14639 plane
->disable_plane(plane
, crtc
);
14643 /* We need to sanitize the plane -> pipe mapping first because this will
14644 * disable the crtc (and hence change the state) if it is wrong. Note
14645 * that gen4+ has a fixed plane -> pipe mapping. */
14646 if (INTEL_GEN(dev_priv
) < 4 && !intel_check_plane_mapping(crtc
)) {
14649 DRM_DEBUG_KMS("[CRTC:%d:%s] wrong plane connection detected!\n",
14650 crtc
->base
.base
.id
, crtc
->base
.name
);
14652 /* Pipe has the wrong plane attached and the plane is active.
14653 * Temporarily change the plane mapping and disable everything
14655 plane
= crtc
->plane
;
14656 crtc
->base
.primary
->state
->visible
= true;
14657 crtc
->plane
= !plane
;
14658 intel_crtc_disable_noatomic(&crtc
->base
, ctx
);
14659 crtc
->plane
= plane
;
14662 /* Adjust the state of the output pipe according to whether we
14663 * have active connectors/encoders. */
14664 if (crtc
->active
&& !intel_crtc_has_encoders(crtc
))
14665 intel_crtc_disable_noatomic(&crtc
->base
, ctx
);
14667 if (crtc
->active
|| HAS_GMCH_DISPLAY(dev_priv
)) {
14669 * We start out with underrun reporting disabled to avoid races.
14670 * For correct bookkeeping mark this on active crtcs.
14672 * Also on gmch platforms we dont have any hardware bits to
14673 * disable the underrun reporting. Which means we need to start
14674 * out with underrun reporting disabled also on inactive pipes,
14675 * since otherwise we'll complain about the garbage we read when
14676 * e.g. coming up after runtime pm.
14678 * No protection against concurrent access is required - at
14679 * worst a fifo underrun happens which also sets this to false.
14681 crtc
->cpu_fifo_underrun_disabled
= true;
14683 * We track the PCH trancoder underrun reporting state
14684 * within the crtc. With crtc for pipe A housing the underrun
14685 * reporting state for PCH transcoder A, crtc for pipe B housing
14686 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
14687 * and marking underrun reporting as disabled for the non-existing
14688 * PCH transcoders B and C would prevent enabling the south
14689 * error interrupt (see cpt_can_enable_serr_int()).
14691 if (has_pch_trancoder(dev_priv
, (enum transcoder
)crtc
->pipe
))
14692 crtc
->pch_fifo_underrun_disabled
= true;
14696 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
14698 struct intel_connector
*connector
;
14700 /* We need to check both for a crtc link (meaning that the
14701 * encoder is active and trying to read from a pipe) and the
14702 * pipe itself being active. */
14703 bool has_active_crtc
= encoder
->base
.crtc
&&
14704 to_intel_crtc(encoder
->base
.crtc
)->active
;
14706 connector
= intel_encoder_find_connector(encoder
);
14707 if (connector
&& !has_active_crtc
) {
14708 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
14709 encoder
->base
.base
.id
,
14710 encoder
->base
.name
);
14712 /* Connector is active, but has no active pipe. This is
14713 * fallout from our resume register restoring. Disable
14714 * the encoder manually again. */
14715 if (encoder
->base
.crtc
) {
14716 struct drm_crtc_state
*crtc_state
= encoder
->base
.crtc
->state
;
14718 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
14719 encoder
->base
.base
.id
,
14720 encoder
->base
.name
);
14721 encoder
->disable(encoder
, to_intel_crtc_state(crtc_state
), connector
->base
.state
);
14722 if (encoder
->post_disable
)
14723 encoder
->post_disable(encoder
, to_intel_crtc_state(crtc_state
), connector
->base
.state
);
14725 encoder
->base
.crtc
= NULL
;
14727 /* Inconsistent output/port/pipe state happens presumably due to
14728 * a bug in one of the get_hw_state functions. Or someplace else
14729 * in our code, like the register restore mess on resume. Clamp
14730 * things to off as a safer default. */
14732 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
14733 connector
->base
.encoder
= NULL
;
14735 /* Enabled encoders without active connectors will be fixed in
14736 * the crtc fixup. */
14739 void i915_redisable_vga_power_on(struct drm_i915_private
*dev_priv
)
14741 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev_priv
);
14743 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
14744 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
14745 i915_disable_vga(dev_priv
);
14749 void i915_redisable_vga(struct drm_i915_private
*dev_priv
)
14751 /* This function can be called both from intel_modeset_setup_hw_state or
14752 * at a very early point in our resume sequence, where the power well
14753 * structures are not yet restored. Since this function is at a very
14754 * paranoid "someone might have enabled VGA while we were not looking"
14755 * level, just check if the power well is enabled instead of trying to
14756 * follow the "don't touch the power well if we don't need it" policy
14757 * the rest of the driver uses. */
14758 if (!intel_display_power_get_if_enabled(dev_priv
, POWER_DOMAIN_VGA
))
14761 i915_redisable_vga_power_on(dev_priv
);
14763 intel_display_power_put(dev_priv
, POWER_DOMAIN_VGA
);
14766 static bool primary_get_hw_state(struct intel_plane
*plane
)
14768 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
14770 return I915_READ(DSPCNTR(plane
->plane
)) & DISPLAY_PLANE_ENABLE
;
14773 /* FIXME read out full plane state for all planes */
14774 static void readout_plane_state(struct intel_crtc
*crtc
)
14776 struct intel_plane
*primary
= to_intel_plane(crtc
->base
.primary
);
14779 visible
= crtc
->active
&& primary_get_hw_state(primary
);
14781 intel_set_plane_visible(to_intel_crtc_state(crtc
->base
.state
),
14782 to_intel_plane_state(primary
->base
.state
),
14786 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
14788 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14790 struct intel_crtc
*crtc
;
14791 struct intel_encoder
*encoder
;
14792 struct intel_connector
*connector
;
14793 struct drm_connector_list_iter conn_iter
;
14796 dev_priv
->active_crtcs
= 0;
14798 for_each_intel_crtc(dev
, crtc
) {
14799 struct intel_crtc_state
*crtc_state
=
14800 to_intel_crtc_state(crtc
->base
.state
);
14802 __drm_atomic_helper_crtc_destroy_state(&crtc_state
->base
);
14803 memset(crtc_state
, 0, sizeof(*crtc_state
));
14804 crtc_state
->base
.crtc
= &crtc
->base
;
14806 crtc_state
->base
.active
= crtc_state
->base
.enable
=
14807 dev_priv
->display
.get_pipe_config(crtc
, crtc_state
);
14809 crtc
->base
.enabled
= crtc_state
->base
.enable
;
14810 crtc
->active
= crtc_state
->base
.active
;
14812 if (crtc_state
->base
.active
)
14813 dev_priv
->active_crtcs
|= 1 << crtc
->pipe
;
14815 readout_plane_state(crtc
);
14817 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
14818 crtc
->base
.base
.id
, crtc
->base
.name
,
14819 enableddisabled(crtc_state
->base
.active
));
14822 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
14823 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
14825 pll
->on
= pll
->funcs
.get_hw_state(dev_priv
, pll
,
14826 &pll
->state
.hw_state
);
14827 pll
->state
.crtc_mask
= 0;
14828 for_each_intel_crtc(dev
, crtc
) {
14829 struct intel_crtc_state
*crtc_state
=
14830 to_intel_crtc_state(crtc
->base
.state
);
14832 if (crtc_state
->base
.active
&&
14833 crtc_state
->shared_dpll
== pll
)
14834 pll
->state
.crtc_mask
|= 1 << crtc
->pipe
;
14836 pll
->active_mask
= pll
->state
.crtc_mask
;
14838 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
14839 pll
->name
, pll
->state
.crtc_mask
, pll
->on
);
14842 for_each_intel_encoder(dev
, encoder
) {
14845 if (encoder
->get_hw_state(encoder
, &pipe
)) {
14846 struct intel_crtc_state
*crtc_state
;
14848 crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
14849 crtc_state
= to_intel_crtc_state(crtc
->base
.state
);
14851 encoder
->base
.crtc
= &crtc
->base
;
14852 crtc_state
->output_types
|= 1 << encoder
->type
;
14853 encoder
->get_config(encoder
, crtc_state
);
14855 encoder
->base
.crtc
= NULL
;
14858 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
14859 encoder
->base
.base
.id
, encoder
->base
.name
,
14860 enableddisabled(encoder
->base
.crtc
),
14864 drm_connector_list_iter_begin(dev
, &conn_iter
);
14865 for_each_intel_connector_iter(connector
, &conn_iter
) {
14866 if (connector
->get_hw_state(connector
)) {
14867 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
14869 encoder
= connector
->encoder
;
14870 connector
->base
.encoder
= &encoder
->base
;
14872 if (encoder
->base
.crtc
&&
14873 encoder
->base
.crtc
->state
->active
) {
14875 * This has to be done during hardware readout
14876 * because anything calling .crtc_disable may
14877 * rely on the connector_mask being accurate.
14879 encoder
->base
.crtc
->state
->connector_mask
|=
14880 1 << drm_connector_index(&connector
->base
);
14881 encoder
->base
.crtc
->state
->encoder_mask
|=
14882 1 << drm_encoder_index(&encoder
->base
);
14886 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
14887 connector
->base
.encoder
= NULL
;
14889 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
14890 connector
->base
.base
.id
, connector
->base
.name
,
14891 enableddisabled(connector
->base
.encoder
));
14893 drm_connector_list_iter_end(&conn_iter
);
14895 for_each_intel_crtc(dev
, crtc
) {
14896 struct intel_crtc_state
*crtc_state
=
14897 to_intel_crtc_state(crtc
->base
.state
);
14900 memset(&crtc
->base
.mode
, 0, sizeof(crtc
->base
.mode
));
14901 if (crtc_state
->base
.active
) {
14902 intel_mode_from_pipe_config(&crtc
->base
.mode
, crtc_state
);
14903 intel_mode_from_pipe_config(&crtc_state
->base
.adjusted_mode
, crtc_state
);
14904 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->base
.state
, &crtc
->base
.mode
));
14907 * The initial mode needs to be set in order to keep
14908 * the atomic core happy. It wants a valid mode if the
14909 * crtc's enabled, so we do the above call.
14911 * But we don't set all the derived state fully, hence
14912 * set a flag to indicate that a full recalculation is
14913 * needed on the next commit.
14915 crtc_state
->base
.mode
.private_flags
= I915_MODE_FLAG_INHERITED
;
14917 intel_crtc_compute_pixel_rate(crtc_state
);
14919 if (INTEL_GEN(dev_priv
) >= 9 || IS_BROADWELL(dev_priv
) ||
14920 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
14921 pixclk
= crtc_state
->pixel_rate
;
14923 WARN_ON(dev_priv
->display
.modeset_calc_cdclk
);
14925 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
14926 if (IS_BROADWELL(dev_priv
) && crtc_state
->ips_enabled
)
14927 pixclk
= DIV_ROUND_UP(pixclk
* 100, 95);
14929 drm_calc_timestamping_constants(&crtc
->base
,
14930 &crtc_state
->base
.adjusted_mode
);
14931 update_scanline_offset(crtc
);
14934 dev_priv
->min_pixclk
[crtc
->pipe
] = pixclk
;
14936 intel_pipe_config_sanity_check(dev_priv
, crtc_state
);
14941 get_encoder_power_domains(struct drm_i915_private
*dev_priv
)
14943 struct intel_encoder
*encoder
;
14945 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
14947 enum intel_display_power_domain domain
;
14949 if (!encoder
->get_power_domains
)
14952 get_domains
= encoder
->get_power_domains(encoder
);
14953 for_each_power_domain(domain
, get_domains
)
14954 intel_display_power_get(dev_priv
, domain
);
14958 /* Scan out the current hw modeset state,
14959 * and sanitizes it to the current state
14962 intel_modeset_setup_hw_state(struct drm_device
*dev
,
14963 struct drm_modeset_acquire_ctx
*ctx
)
14965 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14967 struct intel_crtc
*crtc
;
14968 struct intel_encoder
*encoder
;
14971 intel_modeset_readout_hw_state(dev
);
14973 /* HW state is read out, now we need to sanitize this mess. */
14974 get_encoder_power_domains(dev_priv
);
14976 for_each_intel_encoder(dev
, encoder
) {
14977 intel_sanitize_encoder(encoder
);
14980 for_each_pipe(dev_priv
, pipe
) {
14981 crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
14983 intel_sanitize_crtc(crtc
, ctx
);
14984 intel_dump_pipe_config(crtc
, crtc
->config
,
14985 "[setup_hw_state]");
14988 intel_modeset_update_connector_atomic_state(dev
);
14990 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
14991 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
14993 if (!pll
->on
|| pll
->active_mask
)
14996 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
14998 pll
->funcs
.disable(dev_priv
, pll
);
15002 if (IS_G4X(dev_priv
)) {
15003 g4x_wm_get_hw_state(dev
);
15004 g4x_wm_sanitize(dev_priv
);
15005 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
15006 vlv_wm_get_hw_state(dev
);
15007 vlv_wm_sanitize(dev_priv
);
15008 } else if (IS_GEN9(dev_priv
)) {
15009 skl_wm_get_hw_state(dev
);
15010 } else if (HAS_PCH_SPLIT(dev_priv
)) {
15011 ilk_wm_get_hw_state(dev
);
15014 for_each_intel_crtc(dev
, crtc
) {
15017 put_domains
= modeset_get_crtc_power_domains(&crtc
->base
, crtc
->config
);
15018 if (WARN_ON(put_domains
))
15019 modeset_put_power_domains(dev_priv
, put_domains
);
15021 intel_display_set_init_power(dev_priv
, false);
15023 intel_power_domains_verify_state(dev_priv
);
15025 intel_fbc_init_pipe_state(dev_priv
);
15028 void intel_display_resume(struct drm_device
*dev
)
15030 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15031 struct drm_atomic_state
*state
= dev_priv
->modeset_restore_state
;
15032 struct drm_modeset_acquire_ctx ctx
;
15035 dev_priv
->modeset_restore_state
= NULL
;
15037 state
->acquire_ctx
= &ctx
;
15039 drm_modeset_acquire_init(&ctx
, 0);
15042 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
15043 if (ret
!= -EDEADLK
)
15046 drm_modeset_backoff(&ctx
);
15050 ret
= __intel_display_resume(dev
, state
, &ctx
);
15052 drm_modeset_drop_locks(&ctx
);
15053 drm_modeset_acquire_fini(&ctx
);
15056 DRM_ERROR("Restoring old state failed with %i\n", ret
);
15058 drm_atomic_state_put(state
);
15061 void intel_modeset_gem_init(struct drm_device
*dev
)
15063 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15065 intel_init_gt_powersave(dev_priv
);
15067 intel_setup_overlay(dev_priv
);
15070 int intel_connector_register(struct drm_connector
*connector
)
15072 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
15075 ret
= intel_backlight_device_register(intel_connector
);
15085 void intel_connector_unregister(struct drm_connector
*connector
)
15087 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
15089 intel_backlight_device_unregister(intel_connector
);
15090 intel_panel_destroy_backlight(connector
);
15093 void intel_modeset_cleanup(struct drm_device
*dev
)
15095 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15097 flush_work(&dev_priv
->atomic_helper
.free_work
);
15098 WARN_ON(!llist_empty(&dev_priv
->atomic_helper
.free_list
));
15100 intel_disable_gt_powersave(dev_priv
);
15103 * Interrupts and polling as the first thing to avoid creating havoc.
15104 * Too much stuff here (turning of connectors, ...) would
15105 * experience fancy races otherwise.
15107 intel_irq_uninstall(dev_priv
);
15110 * Due to the hpd irq storm handling the hotplug work can re-arm the
15111 * poll handlers. Hence disable polling after hpd handling is shut down.
15113 drm_kms_helper_poll_fini(dev
);
15115 /* poll work can call into fbdev, hence clean that up afterwards */
15116 intel_fbdev_fini(dev_priv
);
15118 intel_unregister_dsm_handler();
15120 intel_fbc_global_disable(dev_priv
);
15122 /* flush any delayed tasks or pending work */
15123 flush_scheduled_work();
15125 drm_mode_config_cleanup(dev
);
15127 intel_cleanup_overlay(dev_priv
);
15129 intel_cleanup_gt_powersave(dev_priv
);
15131 intel_teardown_gmbus(dev_priv
);
15134 void intel_connector_attach_encoder(struct intel_connector
*connector
,
15135 struct intel_encoder
*encoder
)
15137 connector
->encoder
= encoder
;
15138 drm_mode_connector_attach_encoder(&connector
->base
,
15143 * set vga decode state - true == enable VGA decode
15145 int intel_modeset_vga_set_state(struct drm_i915_private
*dev_priv
, bool state
)
15147 unsigned reg
= INTEL_GEN(dev_priv
) >= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
15150 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
15151 DRM_ERROR("failed to read control word\n");
15155 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
15159 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
15161 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
15163 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
15164 DRM_ERROR("failed to write control word\n");
15171 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
15173 struct intel_display_error_state
{
15175 u32 power_well_driver
;
15177 int num_transcoders
;
15179 struct intel_cursor_error_state
{
15184 } cursor
[I915_MAX_PIPES
];
15186 struct intel_pipe_error_state
{
15187 bool power_domain_on
;
15190 } pipe
[I915_MAX_PIPES
];
15192 struct intel_plane_error_state
{
15200 } plane
[I915_MAX_PIPES
];
15202 struct intel_transcoder_error_state
{
15203 bool power_domain_on
;
15204 enum transcoder cpu_transcoder
;
15217 struct intel_display_error_state
*
15218 intel_display_capture_error_state(struct drm_i915_private
*dev_priv
)
15220 struct intel_display_error_state
*error
;
15221 int transcoders
[] = {
15229 if (INTEL_INFO(dev_priv
)->num_pipes
== 0)
15232 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
15236 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
15237 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
15239 for_each_pipe(dev_priv
, i
) {
15240 error
->pipe
[i
].power_domain_on
=
15241 __intel_display_power_is_enabled(dev_priv
,
15242 POWER_DOMAIN_PIPE(i
));
15243 if (!error
->pipe
[i
].power_domain_on
)
15246 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
15247 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
15248 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
15250 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
15251 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
15252 if (INTEL_GEN(dev_priv
) <= 3) {
15253 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
15254 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
15256 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
15257 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
15258 if (INTEL_GEN(dev_priv
) >= 4) {
15259 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
15260 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
15263 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
15265 if (HAS_GMCH_DISPLAY(dev_priv
))
15266 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
15269 /* Note: this does not include DSI transcoders. */
15270 error
->num_transcoders
= INTEL_INFO(dev_priv
)->num_pipes
;
15271 if (HAS_DDI(dev_priv
))
15272 error
->num_transcoders
++; /* Account for eDP. */
15274 for (i
= 0; i
< error
->num_transcoders
; i
++) {
15275 enum transcoder cpu_transcoder
= transcoders
[i
];
15277 error
->transcoder
[i
].power_domain_on
=
15278 __intel_display_power_is_enabled(dev_priv
,
15279 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
15280 if (!error
->transcoder
[i
].power_domain_on
)
15283 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
15285 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
15286 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
15287 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
15288 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
15289 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
15290 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
15291 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
15297 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
15300 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
15301 struct intel_display_error_state
*error
)
15303 struct drm_i915_private
*dev_priv
= m
->i915
;
15309 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev_priv
)->num_pipes
);
15310 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
15311 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
15312 error
->power_well_driver
);
15313 for_each_pipe(dev_priv
, i
) {
15314 err_printf(m
, "Pipe [%d]:\n", i
);
15315 err_printf(m
, " Power: %s\n",
15316 onoff(error
->pipe
[i
].power_domain_on
));
15317 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
15318 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
15320 err_printf(m
, "Plane [%d]:\n", i
);
15321 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
15322 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
15323 if (INTEL_GEN(dev_priv
) <= 3) {
15324 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
15325 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
15327 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
15328 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
15329 if (INTEL_GEN(dev_priv
) >= 4) {
15330 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
15331 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
15334 err_printf(m
, "Cursor [%d]:\n", i
);
15335 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
15336 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
15337 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
15340 for (i
= 0; i
< error
->num_transcoders
; i
++) {
15341 err_printf(m
, "CPU transcoder: %s\n",
15342 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
15343 err_printf(m
, " Power: %s\n",
15344 onoff(error
->transcoder
[i
].power_domain_on
));
15345 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
15346 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
15347 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
15348 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
15349 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
15350 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
15351 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);