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
);
3409 __intel_display_resume(struct drm_device
*dev
,
3410 struct drm_atomic_state
*state
,
3411 struct drm_modeset_acquire_ctx
*ctx
)
3413 struct drm_crtc_state
*crtc_state
;
3414 struct drm_crtc
*crtc
;
3417 intel_modeset_setup_hw_state(dev
, ctx
);
3418 i915_redisable_vga(to_i915(dev
));
3424 * We've duplicated the state, pointers to the old state are invalid.
3426 * Don't attempt to use the old state until we commit the duplicated state.
3428 for_each_new_crtc_in_state(state
, crtc
, crtc_state
, i
) {
3430 * Force recalculation even if we restore
3431 * current state. With fast modeset this may not result
3432 * in a modeset when the state is compatible.
3434 crtc_state
->mode_changed
= true;
3437 /* ignore any reset values/BIOS leftovers in the WM registers */
3438 if (!HAS_GMCH_DISPLAY(to_i915(dev
)))
3439 to_intel_atomic_state(state
)->skip_intermediate_wm
= true;
3441 ret
= drm_atomic_helper_commit_duplicated_state(state
, ctx
);
3443 WARN_ON(ret
== -EDEADLK
);
3447 static bool gpu_reset_clobbers_display(struct drm_i915_private
*dev_priv
)
3449 return intel_has_gpu_reset(dev_priv
) &&
3450 INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
);
3453 void intel_prepare_reset(struct drm_i915_private
*dev_priv
)
3455 struct drm_device
*dev
= &dev_priv
->drm
;
3456 struct drm_modeset_acquire_ctx
*ctx
= &dev_priv
->reset_ctx
;
3457 struct drm_atomic_state
*state
;
3461 /* reset doesn't touch the display */
3462 if (!i915
.force_reset_modeset_test
&&
3463 !gpu_reset_clobbers_display(dev_priv
))
3467 * Need mode_config.mutex so that we don't
3468 * trample ongoing ->detect() and whatnot.
3470 mutex_lock(&dev
->mode_config
.mutex
);
3471 drm_modeset_acquire_init(ctx
, 0);
3473 ret
= drm_modeset_lock_all_ctx(dev
, ctx
);
3474 if (ret
!= -EDEADLK
)
3477 drm_modeset_backoff(ctx
);
3480 * Disabling the crtcs gracefully seems nicer. Also the
3481 * g33 docs say we should at least disable all the planes.
3483 state
= drm_atomic_helper_duplicate_state(dev
, ctx
);
3484 if (IS_ERR(state
)) {
3485 ret
= PTR_ERR(state
);
3486 DRM_ERROR("Duplicating state failed with %i\n", ret
);
3490 ret
= drm_atomic_helper_disable_all(dev
, ctx
);
3492 DRM_ERROR("Suspending crtc's failed with %i\n", ret
);
3493 drm_atomic_state_put(state
);
3497 dev_priv
->modeset_restore_state
= state
;
3498 state
->acquire_ctx
= ctx
;
3501 void intel_finish_reset(struct drm_i915_private
*dev_priv
)
3503 struct drm_device
*dev
= &dev_priv
->drm
;
3504 struct drm_modeset_acquire_ctx
*ctx
= &dev_priv
->reset_ctx
;
3505 struct drm_atomic_state
*state
= dev_priv
->modeset_restore_state
;
3508 /* reset doesn't touch the display */
3509 if (!i915
.force_reset_modeset_test
&&
3510 !gpu_reset_clobbers_display(dev_priv
))
3516 dev_priv
->modeset_restore_state
= NULL
;
3518 /* reset doesn't touch the display */
3519 if (!gpu_reset_clobbers_display(dev_priv
)) {
3520 /* for testing only restore the display */
3521 ret
= __intel_display_resume(dev
, state
, ctx
);
3523 DRM_ERROR("Restoring old state failed with %i\n", ret
);
3526 * The display has been reset as well,
3527 * so need a full re-initialization.
3529 intel_runtime_pm_disable_interrupts(dev_priv
);
3530 intel_runtime_pm_enable_interrupts(dev_priv
);
3532 intel_pps_unlock_regs_wa(dev_priv
);
3533 intel_modeset_init_hw(dev
);
3535 spin_lock_irq(&dev_priv
->irq_lock
);
3536 if (dev_priv
->display
.hpd_irq_setup
)
3537 dev_priv
->display
.hpd_irq_setup(dev_priv
);
3538 spin_unlock_irq(&dev_priv
->irq_lock
);
3540 ret
= __intel_display_resume(dev
, state
, ctx
);
3542 DRM_ERROR("Restoring old state failed with %i\n", ret
);
3544 intel_hpd_init(dev_priv
);
3547 drm_atomic_state_put(state
);
3549 drm_modeset_drop_locks(ctx
);
3550 drm_modeset_acquire_fini(ctx
);
3551 mutex_unlock(&dev
->mode_config
.mutex
);
3554 static bool abort_flip_on_reset(struct intel_crtc
*crtc
)
3556 struct i915_gpu_error
*error
= &to_i915(crtc
->base
.dev
)->gpu_error
;
3558 if (i915_reset_backoff(error
))
3561 if (crtc
->reset_count
!= i915_reset_count(error
))
3567 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
3569 struct drm_device
*dev
= crtc
->dev
;
3570 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3573 if (abort_flip_on_reset(intel_crtc
))
3576 spin_lock_irq(&dev
->event_lock
);
3577 pending
= to_intel_crtc(crtc
)->flip_work
!= NULL
;
3578 spin_unlock_irq(&dev
->event_lock
);
3583 static void intel_update_pipe_config(struct intel_crtc
*crtc
,
3584 struct intel_crtc_state
*old_crtc_state
)
3586 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
3587 struct intel_crtc_state
*pipe_config
=
3588 to_intel_crtc_state(crtc
->base
.state
);
3590 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
3591 crtc
->base
.mode
= crtc
->base
.state
->mode
;
3594 * Update pipe size and adjust fitter if needed: the reason for this is
3595 * that in compute_mode_changes we check the native mode (not the pfit
3596 * mode) to see if we can flip rather than do a full mode set. In the
3597 * fastboot case, we'll flip, but if we don't update the pipesrc and
3598 * pfit state, we'll end up with a big fb scanned out into the wrong
3602 I915_WRITE(PIPESRC(crtc
->pipe
),
3603 ((pipe_config
->pipe_src_w
- 1) << 16) |
3604 (pipe_config
->pipe_src_h
- 1));
3606 /* on skylake this is done by detaching scalers */
3607 if (INTEL_GEN(dev_priv
) >= 9) {
3608 skl_detach_scalers(crtc
);
3610 if (pipe_config
->pch_pfit
.enabled
)
3611 skylake_pfit_enable(crtc
);
3612 } else if (HAS_PCH_SPLIT(dev_priv
)) {
3613 if (pipe_config
->pch_pfit
.enabled
)
3614 ironlake_pfit_enable(crtc
);
3615 else if (old_crtc_state
->pch_pfit
.enabled
)
3616 ironlake_pfit_disable(crtc
, true);
3620 static void intel_fdi_normal_train(struct intel_crtc
*crtc
)
3622 struct drm_device
*dev
= crtc
->base
.dev
;
3623 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3624 int pipe
= crtc
->pipe
;
3628 /* enable normal train */
3629 reg
= FDI_TX_CTL(pipe
);
3630 temp
= I915_READ(reg
);
3631 if (IS_IVYBRIDGE(dev_priv
)) {
3632 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3633 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3635 temp
&= ~FDI_LINK_TRAIN_NONE
;
3636 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3638 I915_WRITE(reg
, temp
);
3640 reg
= FDI_RX_CTL(pipe
);
3641 temp
= I915_READ(reg
);
3642 if (HAS_PCH_CPT(dev_priv
)) {
3643 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3644 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
3646 temp
&= ~FDI_LINK_TRAIN_NONE
;
3647 temp
|= FDI_LINK_TRAIN_NONE
;
3649 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
3651 /* wait one idle pattern time */
3655 /* IVB wants error correction enabled */
3656 if (IS_IVYBRIDGE(dev_priv
))
3657 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
3658 FDI_FE_ERRC_ENABLE
);
3661 /* The FDI link training functions for ILK/Ibexpeak. */
3662 static void ironlake_fdi_link_train(struct intel_crtc
*crtc
,
3663 const struct intel_crtc_state
*crtc_state
)
3665 struct drm_device
*dev
= crtc
->base
.dev
;
3666 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3667 int pipe
= crtc
->pipe
;
3671 /* FDI needs bits from pipe first */
3672 assert_pipe_enabled(dev_priv
, pipe
);
3674 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3676 reg
= FDI_RX_IMR(pipe
);
3677 temp
= I915_READ(reg
);
3678 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3679 temp
&= ~FDI_RX_BIT_LOCK
;
3680 I915_WRITE(reg
, temp
);
3684 /* enable CPU FDI TX and PCH FDI RX */
3685 reg
= FDI_TX_CTL(pipe
);
3686 temp
= I915_READ(reg
);
3687 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3688 temp
|= FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
3689 temp
&= ~FDI_LINK_TRAIN_NONE
;
3690 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3691 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3693 reg
= FDI_RX_CTL(pipe
);
3694 temp
= I915_READ(reg
);
3695 temp
&= ~FDI_LINK_TRAIN_NONE
;
3696 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3697 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3702 /* Ironlake workaround, enable clock pointer after FDI enable*/
3703 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3704 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
3705 FDI_RX_PHASE_SYNC_POINTER_EN
);
3707 reg
= FDI_RX_IIR(pipe
);
3708 for (tries
= 0; tries
< 5; tries
++) {
3709 temp
= I915_READ(reg
);
3710 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3712 if ((temp
& FDI_RX_BIT_LOCK
)) {
3713 DRM_DEBUG_KMS("FDI train 1 done.\n");
3714 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3719 DRM_ERROR("FDI train 1 fail!\n");
3722 reg
= FDI_TX_CTL(pipe
);
3723 temp
= I915_READ(reg
);
3724 temp
&= ~FDI_LINK_TRAIN_NONE
;
3725 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3726 I915_WRITE(reg
, temp
);
3728 reg
= FDI_RX_CTL(pipe
);
3729 temp
= I915_READ(reg
);
3730 temp
&= ~FDI_LINK_TRAIN_NONE
;
3731 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3732 I915_WRITE(reg
, temp
);
3737 reg
= FDI_RX_IIR(pipe
);
3738 for (tries
= 0; tries
< 5; tries
++) {
3739 temp
= I915_READ(reg
);
3740 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3742 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3743 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3744 DRM_DEBUG_KMS("FDI train 2 done.\n");
3749 DRM_ERROR("FDI train 2 fail!\n");
3751 DRM_DEBUG_KMS("FDI train done\n");
3755 static const int snb_b_fdi_train_param
[] = {
3756 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
3757 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
3758 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
3759 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
3762 /* The FDI link training functions for SNB/Cougarpoint. */
3763 static void gen6_fdi_link_train(struct intel_crtc
*crtc
,
3764 const struct intel_crtc_state
*crtc_state
)
3766 struct drm_device
*dev
= crtc
->base
.dev
;
3767 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3768 int pipe
= crtc
->pipe
;
3772 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3774 reg
= FDI_RX_IMR(pipe
);
3775 temp
= I915_READ(reg
);
3776 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3777 temp
&= ~FDI_RX_BIT_LOCK
;
3778 I915_WRITE(reg
, temp
);
3783 /* enable CPU FDI TX and PCH FDI RX */
3784 reg
= FDI_TX_CTL(pipe
);
3785 temp
= I915_READ(reg
);
3786 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3787 temp
|= FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
3788 temp
&= ~FDI_LINK_TRAIN_NONE
;
3789 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3790 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3792 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3793 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3795 I915_WRITE(FDI_RX_MISC(pipe
),
3796 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3798 reg
= FDI_RX_CTL(pipe
);
3799 temp
= I915_READ(reg
);
3800 if (HAS_PCH_CPT(dev_priv
)) {
3801 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3802 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3804 temp
&= ~FDI_LINK_TRAIN_NONE
;
3805 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3807 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3812 for (i
= 0; i
< 4; i
++) {
3813 reg
= FDI_TX_CTL(pipe
);
3814 temp
= I915_READ(reg
);
3815 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3816 temp
|= snb_b_fdi_train_param
[i
];
3817 I915_WRITE(reg
, temp
);
3822 for (retry
= 0; retry
< 5; retry
++) {
3823 reg
= FDI_RX_IIR(pipe
);
3824 temp
= I915_READ(reg
);
3825 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3826 if (temp
& FDI_RX_BIT_LOCK
) {
3827 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3828 DRM_DEBUG_KMS("FDI train 1 done.\n");
3837 DRM_ERROR("FDI train 1 fail!\n");
3840 reg
= FDI_TX_CTL(pipe
);
3841 temp
= I915_READ(reg
);
3842 temp
&= ~FDI_LINK_TRAIN_NONE
;
3843 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3844 if (IS_GEN6(dev_priv
)) {
3845 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3847 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3849 I915_WRITE(reg
, temp
);
3851 reg
= FDI_RX_CTL(pipe
);
3852 temp
= I915_READ(reg
);
3853 if (HAS_PCH_CPT(dev_priv
)) {
3854 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3855 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3857 temp
&= ~FDI_LINK_TRAIN_NONE
;
3858 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3860 I915_WRITE(reg
, temp
);
3865 for (i
= 0; i
< 4; i
++) {
3866 reg
= FDI_TX_CTL(pipe
);
3867 temp
= I915_READ(reg
);
3868 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3869 temp
|= snb_b_fdi_train_param
[i
];
3870 I915_WRITE(reg
, temp
);
3875 for (retry
= 0; retry
< 5; retry
++) {
3876 reg
= FDI_RX_IIR(pipe
);
3877 temp
= I915_READ(reg
);
3878 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3879 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3880 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3881 DRM_DEBUG_KMS("FDI train 2 done.\n");
3890 DRM_ERROR("FDI train 2 fail!\n");
3892 DRM_DEBUG_KMS("FDI train done.\n");
3895 /* Manual link training for Ivy Bridge A0 parts */
3896 static void ivb_manual_fdi_link_train(struct intel_crtc
*crtc
,
3897 const struct intel_crtc_state
*crtc_state
)
3899 struct drm_device
*dev
= crtc
->base
.dev
;
3900 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3901 int pipe
= crtc
->pipe
;
3905 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3907 reg
= FDI_RX_IMR(pipe
);
3908 temp
= I915_READ(reg
);
3909 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3910 temp
&= ~FDI_RX_BIT_LOCK
;
3911 I915_WRITE(reg
, temp
);
3916 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3917 I915_READ(FDI_RX_IIR(pipe
)));
3919 /* Try each vswing and preemphasis setting twice before moving on */
3920 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
3921 /* disable first in case we need to retry */
3922 reg
= FDI_TX_CTL(pipe
);
3923 temp
= I915_READ(reg
);
3924 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
3925 temp
&= ~FDI_TX_ENABLE
;
3926 I915_WRITE(reg
, temp
);
3928 reg
= FDI_RX_CTL(pipe
);
3929 temp
= I915_READ(reg
);
3930 temp
&= ~FDI_LINK_TRAIN_AUTO
;
3931 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3932 temp
&= ~FDI_RX_ENABLE
;
3933 I915_WRITE(reg
, temp
);
3935 /* enable CPU FDI TX and PCH FDI RX */
3936 reg
= FDI_TX_CTL(pipe
);
3937 temp
= I915_READ(reg
);
3938 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3939 temp
|= FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
3940 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
3941 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3942 temp
|= snb_b_fdi_train_param
[j
/2];
3943 temp
|= FDI_COMPOSITE_SYNC
;
3944 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3946 I915_WRITE(FDI_RX_MISC(pipe
),
3947 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3949 reg
= FDI_RX_CTL(pipe
);
3950 temp
= I915_READ(reg
);
3951 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3952 temp
|= FDI_COMPOSITE_SYNC
;
3953 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3956 udelay(1); /* should be 0.5us */
3958 for (i
= 0; i
< 4; i
++) {
3959 reg
= FDI_RX_IIR(pipe
);
3960 temp
= I915_READ(reg
);
3961 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3963 if (temp
& FDI_RX_BIT_LOCK
||
3964 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
3965 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3966 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3970 udelay(1); /* should be 0.5us */
3973 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
3978 reg
= FDI_TX_CTL(pipe
);
3979 temp
= I915_READ(reg
);
3980 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3981 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
3982 I915_WRITE(reg
, temp
);
3984 reg
= FDI_RX_CTL(pipe
);
3985 temp
= I915_READ(reg
);
3986 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3987 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3988 I915_WRITE(reg
, temp
);
3991 udelay(2); /* should be 1.5us */
3993 for (i
= 0; i
< 4; i
++) {
3994 reg
= FDI_RX_IIR(pipe
);
3995 temp
= I915_READ(reg
);
3996 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3998 if (temp
& FDI_RX_SYMBOL_LOCK
||
3999 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
4000 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
4001 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4005 udelay(2); /* should be 1.5us */
4008 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
4012 DRM_DEBUG_KMS("FDI train done.\n");
4015 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
4017 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4018 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4019 int pipe
= intel_crtc
->pipe
;
4023 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4024 reg
= FDI_RX_CTL(pipe
);
4025 temp
= I915_READ(reg
);
4026 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
4027 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
4028 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
4029 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
4034 /* Switch from Rawclk to PCDclk */
4035 temp
= I915_READ(reg
);
4036 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
4041 /* Enable CPU FDI TX PLL, always on for Ironlake */
4042 reg
= FDI_TX_CTL(pipe
);
4043 temp
= I915_READ(reg
);
4044 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
4045 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
4052 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
4054 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4055 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4056 int pipe
= intel_crtc
->pipe
;
4060 /* Switch from PCDclk to Rawclk */
4061 reg
= FDI_RX_CTL(pipe
);
4062 temp
= I915_READ(reg
);
4063 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
4065 /* Disable CPU FDI TX PLL */
4066 reg
= FDI_TX_CTL(pipe
);
4067 temp
= I915_READ(reg
);
4068 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
4073 reg
= FDI_RX_CTL(pipe
);
4074 temp
= I915_READ(reg
);
4075 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
4077 /* Wait for the clocks to turn off. */
4082 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
4084 struct drm_device
*dev
= crtc
->dev
;
4085 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4086 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4087 int pipe
= intel_crtc
->pipe
;
4091 /* disable CPU FDI tx and PCH FDI rx */
4092 reg
= FDI_TX_CTL(pipe
);
4093 temp
= I915_READ(reg
);
4094 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
4097 reg
= FDI_RX_CTL(pipe
);
4098 temp
= I915_READ(reg
);
4099 temp
&= ~(0x7 << 16);
4100 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
4101 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
4106 /* Ironlake workaround, disable clock pointer after downing FDI */
4107 if (HAS_PCH_IBX(dev_priv
))
4108 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
4110 /* still set train pattern 1 */
4111 reg
= FDI_TX_CTL(pipe
);
4112 temp
= I915_READ(reg
);
4113 temp
&= ~FDI_LINK_TRAIN_NONE
;
4114 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
4115 I915_WRITE(reg
, temp
);
4117 reg
= FDI_RX_CTL(pipe
);
4118 temp
= I915_READ(reg
);
4119 if (HAS_PCH_CPT(dev_priv
)) {
4120 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
4121 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
4123 temp
&= ~FDI_LINK_TRAIN_NONE
;
4124 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
4126 /* BPC in FDI rx is consistent with that in PIPECONF */
4127 temp
&= ~(0x07 << 16);
4128 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
4129 I915_WRITE(reg
, temp
);
4135 bool intel_has_pending_fb_unpin(struct drm_i915_private
*dev_priv
)
4137 struct intel_crtc
*crtc
;
4139 /* Note that we don't need to be called with mode_config.lock here
4140 * as our list of CRTC objects is static for the lifetime of the
4141 * device and so cannot disappear as we iterate. Similarly, we can
4142 * happily treat the predicates as racy, atomic checks as userspace
4143 * cannot claim and pin a new fb without at least acquring the
4144 * struct_mutex and so serialising with us.
4146 for_each_intel_crtc(&dev_priv
->drm
, crtc
) {
4147 if (atomic_read(&crtc
->unpin_work_count
) == 0)
4150 if (crtc
->flip_work
)
4151 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
4159 static void page_flip_completed(struct intel_crtc
*intel_crtc
)
4161 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
4162 struct intel_flip_work
*work
= intel_crtc
->flip_work
;
4164 intel_crtc
->flip_work
= NULL
;
4167 drm_crtc_send_vblank_event(&intel_crtc
->base
, work
->event
);
4169 drm_crtc_vblank_put(&intel_crtc
->base
);
4171 wake_up_all(&dev_priv
->pending_flip_queue
);
4172 trace_i915_flip_complete(intel_crtc
->plane
,
4173 work
->pending_flip_obj
);
4175 queue_work(dev_priv
->wq
, &work
->unpin_work
);
4178 static int intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
4180 struct drm_device
*dev
= crtc
->dev
;
4181 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4184 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
4186 ret
= wait_event_interruptible_timeout(
4187 dev_priv
->pending_flip_queue
,
4188 !intel_crtc_has_pending_flip(crtc
),
4195 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4196 struct intel_flip_work
*work
;
4198 spin_lock_irq(&dev
->event_lock
);
4199 work
= intel_crtc
->flip_work
;
4200 if (work
&& !is_mmio_work(work
)) {
4201 WARN_ONCE(1, "Removing stuck page flip\n");
4202 page_flip_completed(intel_crtc
);
4204 spin_unlock_irq(&dev
->event_lock
);
4210 void lpt_disable_iclkip(struct drm_i915_private
*dev_priv
)
4214 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
4216 mutex_lock(&dev_priv
->sb_lock
);
4218 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4219 temp
|= SBI_SSCCTL_DISABLE
;
4220 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
4222 mutex_unlock(&dev_priv
->sb_lock
);
4225 /* Program iCLKIP clock to the desired frequency */
4226 static void lpt_program_iclkip(struct intel_crtc
*crtc
)
4228 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
4229 int clock
= crtc
->config
->base
.adjusted_mode
.crtc_clock
;
4230 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
4233 lpt_disable_iclkip(dev_priv
);
4235 /* The iCLK virtual clock root frequency is in MHz,
4236 * but the adjusted_mode->crtc_clock in in KHz. To get the
4237 * divisors, it is necessary to divide one by another, so we
4238 * convert the virtual clock precision to KHz here for higher
4241 for (auxdiv
= 0; auxdiv
< 2; auxdiv
++) {
4242 u32 iclk_virtual_root_freq
= 172800 * 1000;
4243 u32 iclk_pi_range
= 64;
4244 u32 desired_divisor
;
4246 desired_divisor
= DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
4248 divsel
= (desired_divisor
/ iclk_pi_range
) - 2;
4249 phaseinc
= desired_divisor
% iclk_pi_range
;
4252 * Near 20MHz is a corner case which is
4253 * out of range for the 7-bit divisor
4259 /* This should not happen with any sane values */
4260 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
4261 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
4262 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
4263 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
4265 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4272 mutex_lock(&dev_priv
->sb_lock
);
4274 /* Program SSCDIVINTPHASE6 */
4275 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
4276 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
4277 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
4278 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
4279 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
4280 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
4281 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
4282 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
4284 /* Program SSCAUXDIV */
4285 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
4286 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4287 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
4288 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
4290 /* Enable modulator and associated divider */
4291 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4292 temp
&= ~SBI_SSCCTL_DISABLE
;
4293 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
4295 mutex_unlock(&dev_priv
->sb_lock
);
4297 /* Wait for initialization time */
4300 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
4303 int lpt_get_iclkip(struct drm_i915_private
*dev_priv
)
4305 u32 divsel
, phaseinc
, auxdiv
;
4306 u32 iclk_virtual_root_freq
= 172800 * 1000;
4307 u32 iclk_pi_range
= 64;
4308 u32 desired_divisor
;
4311 if ((I915_READ(PIXCLK_GATE
) & PIXCLK_GATE_UNGATE
) == 0)
4314 mutex_lock(&dev_priv
->sb_lock
);
4316 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4317 if (temp
& SBI_SSCCTL_DISABLE
) {
4318 mutex_unlock(&dev_priv
->sb_lock
);
4322 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
4323 divsel
= (temp
& SBI_SSCDIVINTPHASE_DIVSEL_MASK
) >>
4324 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT
;
4325 phaseinc
= (temp
& SBI_SSCDIVINTPHASE_INCVAL_MASK
) >>
4326 SBI_SSCDIVINTPHASE_INCVAL_SHIFT
;
4328 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
4329 auxdiv
= (temp
& SBI_SSCAUXDIV_FINALDIV2SEL_MASK
) >>
4330 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT
;
4332 mutex_unlock(&dev_priv
->sb_lock
);
4334 desired_divisor
= (divsel
+ 2) * iclk_pi_range
+ phaseinc
;
4336 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
4337 desired_divisor
<< auxdiv
);
4340 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
4341 enum pipe pch_transcoder
)
4343 struct drm_device
*dev
= crtc
->base
.dev
;
4344 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4345 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
4347 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
4348 I915_READ(HTOTAL(cpu_transcoder
)));
4349 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
4350 I915_READ(HBLANK(cpu_transcoder
)));
4351 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
4352 I915_READ(HSYNC(cpu_transcoder
)));
4354 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
4355 I915_READ(VTOTAL(cpu_transcoder
)));
4356 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
4357 I915_READ(VBLANK(cpu_transcoder
)));
4358 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
4359 I915_READ(VSYNC(cpu_transcoder
)));
4360 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
4361 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
4364 static void cpt_set_fdi_bc_bifurcation(struct drm_device
*dev
, bool enable
)
4366 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4369 temp
= I915_READ(SOUTH_CHICKEN1
);
4370 if (!!(temp
& FDI_BC_BIFURCATION_SELECT
) == enable
)
4373 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
4374 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
4376 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
4378 temp
|= FDI_BC_BIFURCATION_SELECT
;
4380 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable
? "en" : "dis");
4381 I915_WRITE(SOUTH_CHICKEN1
, temp
);
4382 POSTING_READ(SOUTH_CHICKEN1
);
4385 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
4387 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4389 switch (intel_crtc
->pipe
) {
4393 if (intel_crtc
->config
->fdi_lanes
> 2)
4394 cpt_set_fdi_bc_bifurcation(dev
, false);
4396 cpt_set_fdi_bc_bifurcation(dev
, true);
4400 cpt_set_fdi_bc_bifurcation(dev
, true);
4408 /* Return which DP Port should be selected for Transcoder DP control */
4410 intel_trans_dp_port_sel(struct intel_crtc
*crtc
)
4412 struct drm_device
*dev
= crtc
->base
.dev
;
4413 struct intel_encoder
*encoder
;
4415 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
4416 if (encoder
->type
== INTEL_OUTPUT_DP
||
4417 encoder
->type
== INTEL_OUTPUT_EDP
)
4418 return enc_to_dig_port(&encoder
->base
)->port
;
4425 * Enable PCH resources required for PCH ports:
4427 * - FDI training & RX/TX
4428 * - update transcoder timings
4429 * - DP transcoding bits
4432 static void ironlake_pch_enable(const struct intel_crtc_state
*crtc_state
)
4434 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
4435 struct drm_device
*dev
= crtc
->base
.dev
;
4436 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4437 int pipe
= crtc
->pipe
;
4440 assert_pch_transcoder_disabled(dev_priv
, pipe
);
4442 if (IS_IVYBRIDGE(dev_priv
))
4443 ivybridge_update_fdi_bc_bifurcation(crtc
);
4445 /* Write the TU size bits before fdi link training, so that error
4446 * detection works. */
4447 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
4448 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
4450 /* For PCH output, training FDI link */
4451 dev_priv
->display
.fdi_link_train(crtc
, crtc_state
);
4453 /* We need to program the right clock selection before writing the pixel
4454 * mutliplier into the DPLL. */
4455 if (HAS_PCH_CPT(dev_priv
)) {
4458 temp
= I915_READ(PCH_DPLL_SEL
);
4459 temp
|= TRANS_DPLL_ENABLE(pipe
);
4460 sel
= TRANS_DPLLB_SEL(pipe
);
4461 if (crtc_state
->shared_dpll
==
4462 intel_get_shared_dpll_by_id(dev_priv
, DPLL_ID_PCH_PLL_B
))
4466 I915_WRITE(PCH_DPLL_SEL
, temp
);
4469 /* XXX: pch pll's can be enabled any time before we enable the PCH
4470 * transcoder, and we actually should do this to not upset any PCH
4471 * transcoder that already use the clock when we share it.
4473 * Note that enable_shared_dpll tries to do the right thing, but
4474 * get_shared_dpll unconditionally resets the pll - we need that to have
4475 * the right LVDS enable sequence. */
4476 intel_enable_shared_dpll(crtc
);
4478 /* set transcoder timing, panel must allow it */
4479 assert_panel_unlocked(dev_priv
, pipe
);
4480 ironlake_pch_transcoder_set_timings(crtc
, pipe
);
4482 intel_fdi_normal_train(crtc
);
4484 /* For PCH DP, enable TRANS_DP_CTL */
4485 if (HAS_PCH_CPT(dev_priv
) &&
4486 intel_crtc_has_dp_encoder(crtc_state
)) {
4487 const struct drm_display_mode
*adjusted_mode
=
4488 &crtc_state
->base
.adjusted_mode
;
4489 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
4490 i915_reg_t reg
= TRANS_DP_CTL(pipe
);
4491 temp
= I915_READ(reg
);
4492 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
4493 TRANS_DP_SYNC_MASK
|
4495 temp
|= TRANS_DP_OUTPUT_ENABLE
;
4496 temp
|= bpc
<< 9; /* same format but at 11:9 */
4498 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
4499 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
4500 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
4501 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
4503 switch (intel_trans_dp_port_sel(crtc
)) {
4505 temp
|= TRANS_DP_PORT_SEL_B
;
4508 temp
|= TRANS_DP_PORT_SEL_C
;
4511 temp
|= TRANS_DP_PORT_SEL_D
;
4517 I915_WRITE(reg
, temp
);
4520 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
4523 static void lpt_pch_enable(const struct intel_crtc_state
*crtc_state
)
4525 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
4526 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
4527 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
4529 assert_pch_transcoder_disabled(dev_priv
, PIPE_A
);
4531 lpt_program_iclkip(crtc
);
4533 /* Set transcoder timing. */
4534 ironlake_pch_transcoder_set_timings(crtc
, PIPE_A
);
4536 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
4539 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
4541 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4542 i915_reg_t dslreg
= PIPEDSL(pipe
);
4545 temp
= I915_READ(dslreg
);
4547 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
4548 if (wait_for(I915_READ(dslreg
) != temp
, 5))
4549 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
4554 skl_update_scaler(struct intel_crtc_state
*crtc_state
, bool force_detach
,
4555 unsigned int scaler_user
, int *scaler_id
,
4556 int src_w
, int src_h
, int dst_w
, int dst_h
)
4558 struct intel_crtc_scaler_state
*scaler_state
=
4559 &crtc_state
->scaler_state
;
4560 struct intel_crtc
*intel_crtc
=
4561 to_intel_crtc(crtc_state
->base
.crtc
);
4562 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
4563 const struct drm_display_mode
*adjusted_mode
=
4564 &crtc_state
->base
.adjusted_mode
;
4568 * Src coordinates are already rotated by 270 degrees for
4569 * the 90/270 degree plane rotation cases (to match the
4570 * GTT mapping), hence no need to account for rotation here.
4572 need_scaling
= src_w
!= dst_w
|| src_h
!= dst_h
;
4575 * Scaling/fitting not supported in IF-ID mode in GEN9+
4576 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4577 * Once NV12 is enabled, handle it here while allocating scaler
4580 if (INTEL_GEN(dev_priv
) >= 9 && crtc_state
->base
.enable
&&
4581 need_scaling
&& adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
4582 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
4587 * if plane is being disabled or scaler is no more required or force detach
4588 * - free scaler binded to this plane/crtc
4589 * - in order to do this, update crtc->scaler_usage
4591 * Here scaler state in crtc_state is set free so that
4592 * scaler can be assigned to other user. Actual register
4593 * update to free the scaler is done in plane/panel-fit programming.
4594 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4596 if (force_detach
|| !need_scaling
) {
4597 if (*scaler_id
>= 0) {
4598 scaler_state
->scaler_users
&= ~(1 << scaler_user
);
4599 scaler_state
->scalers
[*scaler_id
].in_use
= 0;
4601 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4602 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4603 intel_crtc
->pipe
, scaler_user
, *scaler_id
,
4604 scaler_state
->scaler_users
);
4611 if (src_w
< SKL_MIN_SRC_W
|| src_h
< SKL_MIN_SRC_H
||
4612 dst_w
< SKL_MIN_DST_W
|| dst_h
< SKL_MIN_DST_H
||
4614 src_w
> SKL_MAX_SRC_W
|| src_h
> SKL_MAX_SRC_H
||
4615 dst_w
> SKL_MAX_DST_W
|| dst_h
> SKL_MAX_DST_H
) {
4616 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4617 "size is out of scaler range\n",
4618 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
);
4622 /* mark this plane as a scaler user in crtc_state */
4623 scaler_state
->scaler_users
|= (1 << scaler_user
);
4624 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4625 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4626 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
,
4627 scaler_state
->scaler_users
);
4633 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4635 * @state: crtc's scaler state
4638 * 0 - scaler_usage updated successfully
4639 * error - requested scaling cannot be supported or other error condition
4641 int skl_update_scaler_crtc(struct intel_crtc_state
*state
)
4643 const struct drm_display_mode
*adjusted_mode
= &state
->base
.adjusted_mode
;
4645 return skl_update_scaler(state
, !state
->base
.active
, SKL_CRTC_INDEX
,
4646 &state
->scaler_state
.scaler_id
,
4647 state
->pipe_src_w
, state
->pipe_src_h
,
4648 adjusted_mode
->crtc_hdisplay
, adjusted_mode
->crtc_vdisplay
);
4652 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4654 * @state: crtc's scaler state
4655 * @plane_state: atomic plane state to update
4658 * 0 - scaler_usage updated successfully
4659 * error - requested scaling cannot be supported or other error condition
4661 static int skl_update_scaler_plane(struct intel_crtc_state
*crtc_state
,
4662 struct intel_plane_state
*plane_state
)
4665 struct intel_plane
*intel_plane
=
4666 to_intel_plane(plane_state
->base
.plane
);
4667 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
4670 bool force_detach
= !fb
|| !plane_state
->base
.visible
;
4672 ret
= skl_update_scaler(crtc_state
, force_detach
,
4673 drm_plane_index(&intel_plane
->base
),
4674 &plane_state
->scaler_id
,
4675 drm_rect_width(&plane_state
->base
.src
) >> 16,
4676 drm_rect_height(&plane_state
->base
.src
) >> 16,
4677 drm_rect_width(&plane_state
->base
.dst
),
4678 drm_rect_height(&plane_state
->base
.dst
));
4680 if (ret
|| plane_state
->scaler_id
< 0)
4683 /* check colorkey */
4684 if (plane_state
->ckey
.flags
!= I915_SET_COLORKEY_NONE
) {
4685 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
4686 intel_plane
->base
.base
.id
,
4687 intel_plane
->base
.name
);
4691 /* Check src format */
4692 switch (fb
->format
->format
) {
4693 case DRM_FORMAT_RGB565
:
4694 case DRM_FORMAT_XBGR8888
:
4695 case DRM_FORMAT_XRGB8888
:
4696 case DRM_FORMAT_ABGR8888
:
4697 case DRM_FORMAT_ARGB8888
:
4698 case DRM_FORMAT_XRGB2101010
:
4699 case DRM_FORMAT_XBGR2101010
:
4700 case DRM_FORMAT_YUYV
:
4701 case DRM_FORMAT_YVYU
:
4702 case DRM_FORMAT_UYVY
:
4703 case DRM_FORMAT_VYUY
:
4706 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
4707 intel_plane
->base
.base
.id
, intel_plane
->base
.name
,
4708 fb
->base
.id
, fb
->format
->format
);
4715 static void skylake_scaler_disable(struct intel_crtc
*crtc
)
4719 for (i
= 0; i
< crtc
->num_scalers
; i
++)
4720 skl_detach_scaler(crtc
, i
);
4723 static void skylake_pfit_enable(struct intel_crtc
*crtc
)
4725 struct drm_device
*dev
= crtc
->base
.dev
;
4726 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4727 int pipe
= crtc
->pipe
;
4728 struct intel_crtc_scaler_state
*scaler_state
=
4729 &crtc
->config
->scaler_state
;
4731 if (crtc
->config
->pch_pfit
.enabled
) {
4734 if (WARN_ON(crtc
->config
->scaler_state
.scaler_id
< 0))
4737 id
= scaler_state
->scaler_id
;
4738 I915_WRITE(SKL_PS_CTRL(pipe
, id
), PS_SCALER_EN
|
4739 PS_FILTER_MEDIUM
| scaler_state
->scalers
[id
].mode
);
4740 I915_WRITE(SKL_PS_WIN_POS(pipe
, id
), crtc
->config
->pch_pfit
.pos
);
4741 I915_WRITE(SKL_PS_WIN_SZ(pipe
, id
), crtc
->config
->pch_pfit
.size
);
4745 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
4747 struct drm_device
*dev
= crtc
->base
.dev
;
4748 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4749 int pipe
= crtc
->pipe
;
4751 if (crtc
->config
->pch_pfit
.enabled
) {
4752 /* Force use of hard-coded filter coefficients
4753 * as some pre-programmed values are broken,
4756 if (IS_IVYBRIDGE(dev_priv
) || IS_HASWELL(dev_priv
))
4757 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
4758 PF_PIPE_SEL_IVB(pipe
));
4760 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
4761 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
->pch_pfit
.pos
);
4762 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
->pch_pfit
.size
);
4766 void hsw_enable_ips(struct intel_crtc
*crtc
)
4768 struct drm_device
*dev
= crtc
->base
.dev
;
4769 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4771 if (!crtc
->config
->ips_enabled
)
4775 * We can only enable IPS after we enable a plane and wait for a vblank
4776 * This function is called from post_plane_update, which is run after
4780 assert_plane_enabled(dev_priv
, crtc
->plane
);
4781 if (IS_BROADWELL(dev_priv
)) {
4782 mutex_lock(&dev_priv
->rps
.hw_lock
);
4783 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
4784 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4785 /* Quoting Art Runyan: "its not safe to expect any particular
4786 * value in IPS_CTL bit 31 after enabling IPS through the
4787 * mailbox." Moreover, the mailbox may return a bogus state,
4788 * so we need to just enable it and continue on.
4791 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
4792 /* The bit only becomes 1 in the next vblank, so this wait here
4793 * is essentially intel_wait_for_vblank. If we don't have this
4794 * and don't wait for vblanks until the end of crtc_enable, then
4795 * the HW state readout code will complain that the expected
4796 * IPS_CTL value is not the one we read. */
4797 if (intel_wait_for_register(dev_priv
,
4798 IPS_CTL
, IPS_ENABLE
, IPS_ENABLE
,
4800 DRM_ERROR("Timed out waiting for IPS enable\n");
4804 void hsw_disable_ips(struct intel_crtc
*crtc
)
4806 struct drm_device
*dev
= crtc
->base
.dev
;
4807 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4809 if (!crtc
->config
->ips_enabled
)
4812 assert_plane_enabled(dev_priv
, crtc
->plane
);
4813 if (IS_BROADWELL(dev_priv
)) {
4814 mutex_lock(&dev_priv
->rps
.hw_lock
);
4815 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
4816 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4817 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4818 if (intel_wait_for_register(dev_priv
,
4819 IPS_CTL
, IPS_ENABLE
, 0,
4821 DRM_ERROR("Timed out waiting for IPS disable\n");
4823 I915_WRITE(IPS_CTL
, 0);
4824 POSTING_READ(IPS_CTL
);
4827 /* We need to wait for a vblank before we can disable the plane. */
4828 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
4831 static void intel_crtc_dpms_overlay_disable(struct intel_crtc
*intel_crtc
)
4833 if (intel_crtc
->overlay
) {
4834 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4836 mutex_lock(&dev
->struct_mutex
);
4837 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
4838 mutex_unlock(&dev
->struct_mutex
);
4841 /* Let userspace switch the overlay on again. In most cases userspace
4842 * has to recompute where to put it anyway.
4847 * intel_post_enable_primary - Perform operations after enabling primary plane
4848 * @crtc: the CRTC whose primary plane was just enabled
4850 * Performs potentially sleeping operations that must be done after the primary
4851 * plane is enabled, such as updating FBC and IPS. Note that this may be
4852 * called due to an explicit primary plane update, or due to an implicit
4853 * re-enable that is caused when a sprite plane is updated to no longer
4854 * completely hide the primary plane.
4857 intel_post_enable_primary(struct drm_crtc
*crtc
)
4859 struct drm_device
*dev
= crtc
->dev
;
4860 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4861 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4862 int pipe
= intel_crtc
->pipe
;
4865 * FIXME IPS should be fine as long as one plane is
4866 * enabled, but in practice it seems to have problems
4867 * when going from primary only to sprite only and vice
4870 hsw_enable_ips(intel_crtc
);
4873 * Gen2 reports pipe underruns whenever all planes are disabled.
4874 * So don't enable underrun reporting before at least some planes
4876 * FIXME: Need to fix the logic to work when we turn off all planes
4877 * but leave the pipe running.
4879 if (IS_GEN2(dev_priv
))
4880 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4882 /* Underruns don't always raise interrupts, so check manually. */
4883 intel_check_cpu_fifo_underruns(dev_priv
);
4884 intel_check_pch_fifo_underruns(dev_priv
);
4887 /* FIXME move all this to pre_plane_update() with proper state tracking */
4889 intel_pre_disable_primary(struct drm_crtc
*crtc
)
4891 struct drm_device
*dev
= crtc
->dev
;
4892 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4893 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4894 int pipe
= intel_crtc
->pipe
;
4897 * Gen2 reports pipe underruns whenever all planes are disabled.
4898 * So diasble underrun reporting before all the planes get disabled.
4899 * FIXME: Need to fix the logic to work when we turn off all planes
4900 * but leave the pipe running.
4902 if (IS_GEN2(dev_priv
))
4903 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4906 * FIXME IPS should be fine as long as one plane is
4907 * enabled, but in practice it seems to have problems
4908 * when going from primary only to sprite only and vice
4911 hsw_disable_ips(intel_crtc
);
4914 /* FIXME get rid of this and use pre_plane_update */
4916 intel_pre_disable_primary_noatomic(struct drm_crtc
*crtc
)
4918 struct drm_device
*dev
= crtc
->dev
;
4919 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4920 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4921 int pipe
= intel_crtc
->pipe
;
4923 intel_pre_disable_primary(crtc
);
4926 * Vblank time updates from the shadow to live plane control register
4927 * are blocked if the memory self-refresh mode is active at that
4928 * moment. So to make sure the plane gets truly disabled, disable
4929 * first the self-refresh mode. The self-refresh enable bit in turn
4930 * will be checked/applied by the HW only at the next frame start
4931 * event which is after the vblank start event, so we need to have a
4932 * wait-for-vblank between disabling the plane and the pipe.
4934 if (HAS_GMCH_DISPLAY(dev_priv
) &&
4935 intel_set_memory_cxsr(dev_priv
, false))
4936 intel_wait_for_vblank(dev_priv
, pipe
);
4939 static void intel_post_plane_update(struct intel_crtc_state
*old_crtc_state
)
4941 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
4942 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
4943 struct intel_crtc_state
*pipe_config
=
4944 to_intel_crtc_state(crtc
->base
.state
);
4945 struct drm_plane
*primary
= crtc
->base
.primary
;
4946 struct drm_plane_state
*old_pri_state
=
4947 drm_atomic_get_existing_plane_state(old_state
, primary
);
4949 intel_frontbuffer_flip(to_i915(crtc
->base
.dev
), pipe_config
->fb_bits
);
4951 if (pipe_config
->update_wm_post
&& pipe_config
->base
.active
)
4952 intel_update_watermarks(crtc
);
4954 if (old_pri_state
) {
4955 struct intel_plane_state
*primary_state
=
4956 to_intel_plane_state(primary
->state
);
4957 struct intel_plane_state
*old_primary_state
=
4958 to_intel_plane_state(old_pri_state
);
4960 intel_fbc_post_update(crtc
);
4962 if (primary_state
->base
.visible
&&
4963 (needs_modeset(&pipe_config
->base
) ||
4964 !old_primary_state
->base
.visible
))
4965 intel_post_enable_primary(&crtc
->base
);
4969 static void intel_pre_plane_update(struct intel_crtc_state
*old_crtc_state
,
4970 struct intel_crtc_state
*pipe_config
)
4972 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
4973 struct drm_device
*dev
= crtc
->base
.dev
;
4974 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4975 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
4976 struct drm_plane
*primary
= crtc
->base
.primary
;
4977 struct drm_plane_state
*old_pri_state
=
4978 drm_atomic_get_existing_plane_state(old_state
, primary
);
4979 bool modeset
= needs_modeset(&pipe_config
->base
);
4980 struct intel_atomic_state
*old_intel_state
=
4981 to_intel_atomic_state(old_state
);
4983 if (old_pri_state
) {
4984 struct intel_plane_state
*primary_state
=
4985 to_intel_plane_state(primary
->state
);
4986 struct intel_plane_state
*old_primary_state
=
4987 to_intel_plane_state(old_pri_state
);
4989 intel_fbc_pre_update(crtc
, pipe_config
, primary_state
);
4991 if (old_primary_state
->base
.visible
&&
4992 (modeset
|| !primary_state
->base
.visible
))
4993 intel_pre_disable_primary(&crtc
->base
);
4997 * Vblank time updates from the shadow to live plane control register
4998 * are blocked if the memory self-refresh mode is active at that
4999 * moment. So to make sure the plane gets truly disabled, disable
5000 * first the self-refresh mode. The self-refresh enable bit in turn
5001 * will be checked/applied by the HW only at the next frame start
5002 * event which is after the vblank start event, so we need to have a
5003 * wait-for-vblank between disabling the plane and the pipe.
5005 if (HAS_GMCH_DISPLAY(dev_priv
) && old_crtc_state
->base
.active
&&
5006 pipe_config
->disable_cxsr
&& intel_set_memory_cxsr(dev_priv
, false))
5007 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
5010 * IVB workaround: must disable low power watermarks for at least
5011 * one frame before enabling scaling. LP watermarks can be re-enabled
5012 * when scaling is disabled.
5014 * WaCxSRDisabledForSpriteScaling:ivb
5016 if (pipe_config
->disable_lp_wm
&& ilk_disable_lp_wm(dev
))
5017 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
5020 * If we're doing a modeset, we're done. No need to do any pre-vblank
5021 * watermark programming here.
5023 if (needs_modeset(&pipe_config
->base
))
5027 * For platforms that support atomic watermarks, program the
5028 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5029 * will be the intermediate values that are safe for both pre- and
5030 * post- vblank; when vblank happens, the 'active' values will be set
5031 * to the final 'target' values and we'll do this again to get the
5032 * optimal watermarks. For gen9+ platforms, the values we program here
5033 * will be the final target values which will get automatically latched
5034 * at vblank time; no further programming will be necessary.
5036 * If a platform hasn't been transitioned to atomic watermarks yet,
5037 * we'll continue to update watermarks the old way, if flags tell
5040 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5041 dev_priv
->display
.initial_watermarks(old_intel_state
,
5043 else if (pipe_config
->update_wm_pre
)
5044 intel_update_watermarks(crtc
);
5047 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
, unsigned plane_mask
)
5049 struct drm_device
*dev
= crtc
->dev
;
5050 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5051 struct drm_plane
*p
;
5052 int pipe
= intel_crtc
->pipe
;
5054 intel_crtc_dpms_overlay_disable(intel_crtc
);
5056 drm_for_each_plane_mask(p
, dev
, plane_mask
)
5057 to_intel_plane(p
)->disable_plane(to_intel_plane(p
), intel_crtc
);
5060 * FIXME: Once we grow proper nuclear flip support out of this we need
5061 * to compute the mask of flip planes precisely. For the time being
5062 * consider this a flip to a NULL plane.
5064 intel_frontbuffer_flip(to_i915(dev
), INTEL_FRONTBUFFER_ALL_MASK(pipe
));
5067 static void intel_encoders_pre_pll_enable(struct drm_crtc
*crtc
,
5068 struct intel_crtc_state
*crtc_state
,
5069 struct drm_atomic_state
*old_state
)
5071 struct drm_connector_state
*conn_state
;
5072 struct drm_connector
*conn
;
5075 for_each_new_connector_in_state(old_state
, conn
, conn_state
, i
) {
5076 struct intel_encoder
*encoder
=
5077 to_intel_encoder(conn_state
->best_encoder
);
5079 if (conn_state
->crtc
!= crtc
)
5082 if (encoder
->pre_pll_enable
)
5083 encoder
->pre_pll_enable(encoder
, crtc_state
, conn_state
);
5087 static void intel_encoders_pre_enable(struct drm_crtc
*crtc
,
5088 struct intel_crtc_state
*crtc_state
,
5089 struct drm_atomic_state
*old_state
)
5091 struct drm_connector_state
*conn_state
;
5092 struct drm_connector
*conn
;
5095 for_each_new_connector_in_state(old_state
, conn
, conn_state
, i
) {
5096 struct intel_encoder
*encoder
=
5097 to_intel_encoder(conn_state
->best_encoder
);
5099 if (conn_state
->crtc
!= crtc
)
5102 if (encoder
->pre_enable
)
5103 encoder
->pre_enable(encoder
, crtc_state
, conn_state
);
5107 static void intel_encoders_enable(struct drm_crtc
*crtc
,
5108 struct intel_crtc_state
*crtc_state
,
5109 struct drm_atomic_state
*old_state
)
5111 struct drm_connector_state
*conn_state
;
5112 struct drm_connector
*conn
;
5115 for_each_new_connector_in_state(old_state
, conn
, conn_state
, i
) {
5116 struct intel_encoder
*encoder
=
5117 to_intel_encoder(conn_state
->best_encoder
);
5119 if (conn_state
->crtc
!= crtc
)
5122 encoder
->enable(encoder
, crtc_state
, conn_state
);
5123 intel_opregion_notify_encoder(encoder
, true);
5127 static void intel_encoders_disable(struct drm_crtc
*crtc
,
5128 struct intel_crtc_state
*old_crtc_state
,
5129 struct drm_atomic_state
*old_state
)
5131 struct drm_connector_state
*old_conn_state
;
5132 struct drm_connector
*conn
;
5135 for_each_old_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5136 struct intel_encoder
*encoder
=
5137 to_intel_encoder(old_conn_state
->best_encoder
);
5139 if (old_conn_state
->crtc
!= crtc
)
5142 intel_opregion_notify_encoder(encoder
, false);
5143 encoder
->disable(encoder
, old_crtc_state
, old_conn_state
);
5147 static void intel_encoders_post_disable(struct drm_crtc
*crtc
,
5148 struct intel_crtc_state
*old_crtc_state
,
5149 struct drm_atomic_state
*old_state
)
5151 struct drm_connector_state
*old_conn_state
;
5152 struct drm_connector
*conn
;
5155 for_each_old_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5156 struct intel_encoder
*encoder
=
5157 to_intel_encoder(old_conn_state
->best_encoder
);
5159 if (old_conn_state
->crtc
!= crtc
)
5162 if (encoder
->post_disable
)
5163 encoder
->post_disable(encoder
, old_crtc_state
, old_conn_state
);
5167 static void intel_encoders_post_pll_disable(struct drm_crtc
*crtc
,
5168 struct intel_crtc_state
*old_crtc_state
,
5169 struct drm_atomic_state
*old_state
)
5171 struct drm_connector_state
*old_conn_state
;
5172 struct drm_connector
*conn
;
5175 for_each_old_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5176 struct intel_encoder
*encoder
=
5177 to_intel_encoder(old_conn_state
->best_encoder
);
5179 if (old_conn_state
->crtc
!= crtc
)
5182 if (encoder
->post_pll_disable
)
5183 encoder
->post_pll_disable(encoder
, old_crtc_state
, old_conn_state
);
5187 static void ironlake_crtc_enable(struct intel_crtc_state
*pipe_config
,
5188 struct drm_atomic_state
*old_state
)
5190 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5191 struct drm_device
*dev
= crtc
->dev
;
5192 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5193 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5194 int pipe
= intel_crtc
->pipe
;
5195 struct intel_atomic_state
*old_intel_state
=
5196 to_intel_atomic_state(old_state
);
5198 if (WARN_ON(intel_crtc
->active
))
5202 * Sometimes spurious CPU pipe underruns happen during FDI
5203 * training, at least with VGA+HDMI cloning. Suppress them.
5205 * On ILK we get an occasional spurious CPU pipe underruns
5206 * between eDP port A enable and vdd enable. Also PCH port
5207 * enable seems to result in the occasional CPU pipe underrun.
5209 * Spurious PCH underruns also occur during PCH enabling.
5211 if (intel_crtc
->config
->has_pch_encoder
|| IS_GEN5(dev_priv
))
5212 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5213 if (intel_crtc
->config
->has_pch_encoder
)
5214 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
5216 if (intel_crtc
->config
->has_pch_encoder
)
5217 intel_prepare_shared_dpll(intel_crtc
);
5219 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5220 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5222 intel_set_pipe_timings(intel_crtc
);
5223 intel_set_pipe_src_size(intel_crtc
);
5225 if (intel_crtc
->config
->has_pch_encoder
) {
5226 intel_cpu_transcoder_set_m_n(intel_crtc
,
5227 &intel_crtc
->config
->fdi_m_n
, NULL
);
5230 ironlake_set_pipeconf(crtc
);
5232 intel_crtc
->active
= true;
5234 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5236 if (intel_crtc
->config
->has_pch_encoder
) {
5237 /* Note: FDI PLL enabling _must_ be done before we enable the
5238 * cpu pipes, hence this is separate from all the other fdi/pch
5240 ironlake_fdi_pll_enable(intel_crtc
);
5242 assert_fdi_tx_disabled(dev_priv
, pipe
);
5243 assert_fdi_rx_disabled(dev_priv
, pipe
);
5246 ironlake_pfit_enable(intel_crtc
);
5249 * On ILK+ LUT must be loaded before the pipe is running but with
5252 intel_color_load_luts(&pipe_config
->base
);
5254 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5255 dev_priv
->display
.initial_watermarks(old_intel_state
, intel_crtc
->config
);
5256 intel_enable_pipe(intel_crtc
);
5258 if (intel_crtc
->config
->has_pch_encoder
)
5259 ironlake_pch_enable(pipe_config
);
5261 assert_vblank_disabled(crtc
);
5262 drm_crtc_vblank_on(crtc
);
5264 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5266 if (HAS_PCH_CPT(dev_priv
))
5267 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
5269 /* Must wait for vblank to avoid spurious PCH FIFO underruns */
5270 if (intel_crtc
->config
->has_pch_encoder
)
5271 intel_wait_for_vblank(dev_priv
, pipe
);
5272 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5273 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
5276 /* IPS only exists on ULT machines and is tied to pipe A. */
5277 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
5279 return HAS_IPS(to_i915(crtc
->base
.dev
)) && crtc
->pipe
== PIPE_A
;
5282 static void haswell_crtc_enable(struct intel_crtc_state
*pipe_config
,
5283 struct drm_atomic_state
*old_state
)
5285 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5286 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5287 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5288 int pipe
= intel_crtc
->pipe
, hsw_workaround_pipe
;
5289 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5290 struct intel_atomic_state
*old_intel_state
=
5291 to_intel_atomic_state(old_state
);
5293 if (WARN_ON(intel_crtc
->active
))
5296 if (intel_crtc
->config
->has_pch_encoder
)
5297 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, false);
5299 intel_encoders_pre_pll_enable(crtc
, pipe_config
, old_state
);
5301 if (intel_crtc
->config
->shared_dpll
)
5302 intel_enable_shared_dpll(intel_crtc
);
5304 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5305 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5307 if (!transcoder_is_dsi(cpu_transcoder
))
5308 intel_set_pipe_timings(intel_crtc
);
5310 intel_set_pipe_src_size(intel_crtc
);
5312 if (cpu_transcoder
!= TRANSCODER_EDP
&&
5313 !transcoder_is_dsi(cpu_transcoder
)) {
5314 I915_WRITE(PIPE_MULT(cpu_transcoder
),
5315 intel_crtc
->config
->pixel_multiplier
- 1);
5318 if (intel_crtc
->config
->has_pch_encoder
) {
5319 intel_cpu_transcoder_set_m_n(intel_crtc
,
5320 &intel_crtc
->config
->fdi_m_n
, NULL
);
5323 if (!transcoder_is_dsi(cpu_transcoder
))
5324 haswell_set_pipeconf(crtc
);
5326 haswell_set_pipemisc(crtc
);
5328 intel_color_set_csc(&pipe_config
->base
);
5330 intel_crtc
->active
= true;
5332 if (intel_crtc
->config
->has_pch_encoder
)
5333 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5335 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5337 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5339 if (intel_crtc
->config
->has_pch_encoder
)
5340 dev_priv
->display
.fdi_link_train(intel_crtc
, pipe_config
);
5342 if (!transcoder_is_dsi(cpu_transcoder
))
5343 intel_ddi_enable_pipe_clock(pipe_config
);
5345 if (INTEL_GEN(dev_priv
) >= 9)
5346 skylake_pfit_enable(intel_crtc
);
5348 ironlake_pfit_enable(intel_crtc
);
5351 * On ILK+ LUT must be loaded before the pipe is running but with
5354 intel_color_load_luts(&pipe_config
->base
);
5356 intel_ddi_set_pipe_settings(pipe_config
);
5357 if (!transcoder_is_dsi(cpu_transcoder
))
5358 intel_ddi_enable_transcoder_func(pipe_config
);
5360 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5361 dev_priv
->display
.initial_watermarks(old_intel_state
, pipe_config
);
5363 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5364 if (!transcoder_is_dsi(cpu_transcoder
))
5365 intel_enable_pipe(intel_crtc
);
5367 if (intel_crtc
->config
->has_pch_encoder
)
5368 lpt_pch_enable(pipe_config
);
5370 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DP_MST
))
5371 intel_ddi_set_vc_payload_alloc(pipe_config
, true);
5373 assert_vblank_disabled(crtc
);
5374 drm_crtc_vblank_on(crtc
);
5376 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5378 if (intel_crtc
->config
->has_pch_encoder
) {
5379 intel_wait_for_vblank(dev_priv
, pipe
);
5380 intel_wait_for_vblank(dev_priv
, pipe
);
5381 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5382 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, true);
5385 /* If we change the relative order between pipe/planes enabling, we need
5386 * to change the workaround. */
5387 hsw_workaround_pipe
= pipe_config
->hsw_workaround_pipe
;
5388 if (IS_HASWELL(dev_priv
) && hsw_workaround_pipe
!= INVALID_PIPE
) {
5389 intel_wait_for_vblank(dev_priv
, hsw_workaround_pipe
);
5390 intel_wait_for_vblank(dev_priv
, hsw_workaround_pipe
);
5394 static void ironlake_pfit_disable(struct intel_crtc
*crtc
, bool force
)
5396 struct drm_device
*dev
= crtc
->base
.dev
;
5397 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5398 int pipe
= crtc
->pipe
;
5400 /* To avoid upsetting the power well on haswell only disable the pfit if
5401 * it's in use. The hw state code will make sure we get this right. */
5402 if (force
|| crtc
->config
->pch_pfit
.enabled
) {
5403 I915_WRITE(PF_CTL(pipe
), 0);
5404 I915_WRITE(PF_WIN_POS(pipe
), 0);
5405 I915_WRITE(PF_WIN_SZ(pipe
), 0);
5409 static void ironlake_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5410 struct drm_atomic_state
*old_state
)
5412 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5413 struct drm_device
*dev
= crtc
->dev
;
5414 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5415 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5416 int pipe
= intel_crtc
->pipe
;
5419 * Sometimes spurious CPU pipe underruns happen when the
5420 * pipe is already disabled, but FDI RX/TX is still enabled.
5421 * Happens at least with VGA+HDMI cloning. Suppress them.
5423 if (intel_crtc
->config
->has_pch_encoder
) {
5424 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5425 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
5428 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5430 drm_crtc_vblank_off(crtc
);
5431 assert_vblank_disabled(crtc
);
5433 intel_disable_pipe(intel_crtc
);
5435 ironlake_pfit_disable(intel_crtc
, false);
5437 if (intel_crtc
->config
->has_pch_encoder
)
5438 ironlake_fdi_disable(crtc
);
5440 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5442 if (intel_crtc
->config
->has_pch_encoder
) {
5443 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
5445 if (HAS_PCH_CPT(dev_priv
)) {
5449 /* disable TRANS_DP_CTL */
5450 reg
= TRANS_DP_CTL(pipe
);
5451 temp
= I915_READ(reg
);
5452 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
5453 TRANS_DP_PORT_SEL_MASK
);
5454 temp
|= TRANS_DP_PORT_SEL_NONE
;
5455 I915_WRITE(reg
, temp
);
5457 /* disable DPLL_SEL */
5458 temp
= I915_READ(PCH_DPLL_SEL
);
5459 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
5460 I915_WRITE(PCH_DPLL_SEL
, temp
);
5463 ironlake_fdi_pll_disable(intel_crtc
);
5466 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5467 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
5470 static void haswell_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5471 struct drm_atomic_state
*old_state
)
5473 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5474 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5475 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5476 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5478 if (intel_crtc
->config
->has_pch_encoder
)
5479 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, false);
5481 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5483 drm_crtc_vblank_off(crtc
);
5484 assert_vblank_disabled(crtc
);
5486 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5487 if (!transcoder_is_dsi(cpu_transcoder
))
5488 intel_disable_pipe(intel_crtc
);
5490 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DP_MST
))
5491 intel_ddi_set_vc_payload_alloc(intel_crtc
->config
, false);
5493 if (!transcoder_is_dsi(cpu_transcoder
))
5494 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
5496 if (INTEL_GEN(dev_priv
) >= 9)
5497 skylake_scaler_disable(intel_crtc
);
5499 ironlake_pfit_disable(intel_crtc
, false);
5501 if (!transcoder_is_dsi(cpu_transcoder
))
5502 intel_ddi_disable_pipe_clock(intel_crtc
->config
);
5504 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5506 if (old_crtc_state
->has_pch_encoder
)
5507 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, true);
5510 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
5512 struct drm_device
*dev
= crtc
->base
.dev
;
5513 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5514 struct intel_crtc_state
*pipe_config
= crtc
->config
;
5516 if (!pipe_config
->gmch_pfit
.control
)
5520 * The panel fitter should only be adjusted whilst the pipe is disabled,
5521 * according to register description and PRM.
5523 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
5524 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5526 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
5527 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
5529 /* Border color in case we don't scale up to the full screen. Black by
5530 * default, change to something else for debugging. */
5531 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
5534 enum intel_display_power_domain
intel_port_to_power_domain(enum port port
)
5538 return POWER_DOMAIN_PORT_DDI_A_LANES
;
5540 return POWER_DOMAIN_PORT_DDI_B_LANES
;
5542 return POWER_DOMAIN_PORT_DDI_C_LANES
;
5544 return POWER_DOMAIN_PORT_DDI_D_LANES
;
5546 return POWER_DOMAIN_PORT_DDI_E_LANES
;
5549 return POWER_DOMAIN_PORT_OTHER
;
5553 static u64
get_crtc_power_domains(struct drm_crtc
*crtc
,
5554 struct intel_crtc_state
*crtc_state
)
5556 struct drm_device
*dev
= crtc
->dev
;
5557 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5558 struct drm_encoder
*encoder
;
5559 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5560 enum pipe pipe
= intel_crtc
->pipe
;
5562 enum transcoder transcoder
= crtc_state
->cpu_transcoder
;
5564 if (!crtc_state
->base
.active
)
5567 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
5568 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
5569 if (crtc_state
->pch_pfit
.enabled
||
5570 crtc_state
->pch_pfit
.force_thru
)
5571 mask
|= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
5573 drm_for_each_encoder_mask(encoder
, dev
, crtc_state
->base
.encoder_mask
) {
5574 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5576 mask
|= BIT_ULL(intel_encoder
->power_domain
);
5579 if (HAS_DDI(dev_priv
) && crtc_state
->has_audio
)
5580 mask
|= BIT(POWER_DOMAIN_AUDIO
);
5582 if (crtc_state
->shared_dpll
)
5583 mask
|= BIT_ULL(POWER_DOMAIN_PLLS
);
5589 modeset_get_crtc_power_domains(struct drm_crtc
*crtc
,
5590 struct intel_crtc_state
*crtc_state
)
5592 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5593 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5594 enum intel_display_power_domain domain
;
5595 u64 domains
, new_domains
, old_domains
;
5597 old_domains
= intel_crtc
->enabled_power_domains
;
5598 intel_crtc
->enabled_power_domains
= new_domains
=
5599 get_crtc_power_domains(crtc
, crtc_state
);
5601 domains
= new_domains
& ~old_domains
;
5603 for_each_power_domain(domain
, domains
)
5604 intel_display_power_get(dev_priv
, domain
);
5606 return old_domains
& ~new_domains
;
5609 static void modeset_put_power_domains(struct drm_i915_private
*dev_priv
,
5612 enum intel_display_power_domain domain
;
5614 for_each_power_domain(domain
, domains
)
5615 intel_display_power_put(dev_priv
, domain
);
5618 static void valleyview_crtc_enable(struct intel_crtc_state
*pipe_config
,
5619 struct drm_atomic_state
*old_state
)
5621 struct intel_atomic_state
*old_intel_state
=
5622 to_intel_atomic_state(old_state
);
5623 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5624 struct drm_device
*dev
= crtc
->dev
;
5625 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5626 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5627 int pipe
= intel_crtc
->pipe
;
5629 if (WARN_ON(intel_crtc
->active
))
5632 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5633 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5635 intel_set_pipe_timings(intel_crtc
);
5636 intel_set_pipe_src_size(intel_crtc
);
5638 if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_B
) {
5639 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5641 I915_WRITE(CHV_BLEND(pipe
), CHV_BLEND_LEGACY
);
5642 I915_WRITE(CHV_CANVAS(pipe
), 0);
5645 i9xx_set_pipeconf(intel_crtc
);
5647 intel_crtc
->active
= true;
5649 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5651 intel_encoders_pre_pll_enable(crtc
, pipe_config
, old_state
);
5653 if (IS_CHERRYVIEW(dev_priv
)) {
5654 chv_prepare_pll(intel_crtc
, intel_crtc
->config
);
5655 chv_enable_pll(intel_crtc
, intel_crtc
->config
);
5657 vlv_prepare_pll(intel_crtc
, intel_crtc
->config
);
5658 vlv_enable_pll(intel_crtc
, intel_crtc
->config
);
5661 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5663 i9xx_pfit_enable(intel_crtc
);
5665 intel_color_load_luts(&pipe_config
->base
);
5667 dev_priv
->display
.initial_watermarks(old_intel_state
,
5669 intel_enable_pipe(intel_crtc
);
5671 assert_vblank_disabled(crtc
);
5672 drm_crtc_vblank_on(crtc
);
5674 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5677 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
5679 struct drm_device
*dev
= crtc
->base
.dev
;
5680 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5682 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp0
);
5683 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp1
);
5686 static void i9xx_crtc_enable(struct intel_crtc_state
*pipe_config
,
5687 struct drm_atomic_state
*old_state
)
5689 struct intel_atomic_state
*old_intel_state
=
5690 to_intel_atomic_state(old_state
);
5691 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5692 struct drm_device
*dev
= crtc
->dev
;
5693 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5694 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5695 enum pipe pipe
= intel_crtc
->pipe
;
5697 if (WARN_ON(intel_crtc
->active
))
5700 i9xx_set_pll_dividers(intel_crtc
);
5702 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5703 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5705 intel_set_pipe_timings(intel_crtc
);
5706 intel_set_pipe_src_size(intel_crtc
);
5708 i9xx_set_pipeconf(intel_crtc
);
5710 intel_crtc
->active
= true;
5712 if (!IS_GEN2(dev_priv
))
5713 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5715 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5717 i9xx_enable_pll(intel_crtc
);
5719 i9xx_pfit_enable(intel_crtc
);
5721 intel_color_load_luts(&pipe_config
->base
);
5723 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5724 dev_priv
->display
.initial_watermarks(old_intel_state
,
5725 intel_crtc
->config
);
5727 intel_update_watermarks(intel_crtc
);
5728 intel_enable_pipe(intel_crtc
);
5730 assert_vblank_disabled(crtc
);
5731 drm_crtc_vblank_on(crtc
);
5733 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5736 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
5738 struct drm_device
*dev
= crtc
->base
.dev
;
5739 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5741 if (!crtc
->config
->gmch_pfit
.control
)
5744 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5746 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
5747 I915_READ(PFIT_CONTROL
));
5748 I915_WRITE(PFIT_CONTROL
, 0);
5751 static void i9xx_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5752 struct drm_atomic_state
*old_state
)
5754 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5755 struct drm_device
*dev
= crtc
->dev
;
5756 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5757 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5758 int pipe
= intel_crtc
->pipe
;
5761 * On gen2 planes are double buffered but the pipe isn't, so we must
5762 * wait for planes to fully turn off before disabling the pipe.
5764 if (IS_GEN2(dev_priv
))
5765 intel_wait_for_vblank(dev_priv
, pipe
);
5767 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5769 drm_crtc_vblank_off(crtc
);
5770 assert_vblank_disabled(crtc
);
5772 intel_disable_pipe(intel_crtc
);
5774 i9xx_pfit_disable(intel_crtc
);
5776 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5778 if (!intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DSI
)) {
5779 if (IS_CHERRYVIEW(dev_priv
))
5780 chv_disable_pll(dev_priv
, pipe
);
5781 else if (IS_VALLEYVIEW(dev_priv
))
5782 vlv_disable_pll(dev_priv
, pipe
);
5784 i9xx_disable_pll(intel_crtc
);
5787 intel_encoders_post_pll_disable(crtc
, old_crtc_state
, old_state
);
5789 if (!IS_GEN2(dev_priv
))
5790 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5792 if (!dev_priv
->display
.initial_watermarks
)
5793 intel_update_watermarks(intel_crtc
);
5795 /* clock the pipe down to 640x480@60 to potentially save power */
5796 if (IS_I830(dev_priv
))
5797 i830_enable_pipe(dev_priv
, pipe
);
5800 static void intel_crtc_disable_noatomic(struct drm_crtc
*crtc
,
5801 struct drm_modeset_acquire_ctx
*ctx
)
5803 struct intel_encoder
*encoder
;
5804 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5805 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5806 enum intel_display_power_domain domain
;
5808 struct drm_atomic_state
*state
;
5809 struct intel_crtc_state
*crtc_state
;
5812 if (!intel_crtc
->active
)
5815 if (crtc
->primary
->state
->visible
) {
5816 WARN_ON(intel_crtc
->flip_work
);
5818 intel_pre_disable_primary_noatomic(crtc
);
5820 intel_crtc_disable_planes(crtc
, 1 << drm_plane_index(crtc
->primary
));
5821 crtc
->primary
->state
->visible
= false;
5824 state
= drm_atomic_state_alloc(crtc
->dev
);
5826 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
5827 crtc
->base
.id
, crtc
->name
);
5831 state
->acquire_ctx
= ctx
;
5833 /* Everything's already locked, -EDEADLK can't happen. */
5834 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
5835 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
5837 WARN_ON(IS_ERR(crtc_state
) || ret
);
5839 dev_priv
->display
.crtc_disable(crtc_state
, state
);
5841 drm_atomic_state_put(state
);
5843 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
5844 crtc
->base
.id
, crtc
->name
);
5846 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->state
, NULL
) < 0);
5847 crtc
->state
->active
= false;
5848 intel_crtc
->active
= false;
5849 crtc
->enabled
= false;
5850 crtc
->state
->connector_mask
= 0;
5851 crtc
->state
->encoder_mask
= 0;
5853 for_each_encoder_on_crtc(crtc
->dev
, crtc
, encoder
)
5854 encoder
->base
.crtc
= NULL
;
5856 intel_fbc_disable(intel_crtc
);
5857 intel_update_watermarks(intel_crtc
);
5858 intel_disable_shared_dpll(intel_crtc
);
5860 domains
= intel_crtc
->enabled_power_domains
;
5861 for_each_power_domain(domain
, domains
)
5862 intel_display_power_put(dev_priv
, domain
);
5863 intel_crtc
->enabled_power_domains
= 0;
5865 dev_priv
->active_crtcs
&= ~(1 << intel_crtc
->pipe
);
5866 dev_priv
->min_pixclk
[intel_crtc
->pipe
] = 0;
5870 * turn all crtc's off, but do not adjust state
5871 * This has to be paired with a call to intel_modeset_setup_hw_state.
5873 int intel_display_suspend(struct drm_device
*dev
)
5875 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5876 struct drm_atomic_state
*state
;
5879 state
= drm_atomic_helper_suspend(dev
);
5880 ret
= PTR_ERR_OR_ZERO(state
);
5882 DRM_ERROR("Suspending crtc's failed with %i\n", ret
);
5884 dev_priv
->modeset_restore_state
= state
;
5888 void intel_encoder_destroy(struct drm_encoder
*encoder
)
5890 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5892 drm_encoder_cleanup(encoder
);
5893 kfree(intel_encoder
);
5896 /* Cross check the actual hw state with our own modeset state tracking (and it's
5897 * internal consistency). */
5898 static void intel_connector_verify_state(struct drm_crtc_state
*crtc_state
,
5899 struct drm_connector_state
*conn_state
)
5901 struct intel_connector
*connector
= to_intel_connector(conn_state
->connector
);
5903 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
5904 connector
->base
.base
.id
,
5905 connector
->base
.name
);
5907 if (connector
->get_hw_state(connector
)) {
5908 struct intel_encoder
*encoder
= connector
->encoder
;
5910 I915_STATE_WARN(!crtc_state
,
5911 "connector enabled without attached crtc\n");
5916 I915_STATE_WARN(!crtc_state
->active
,
5917 "connector is active, but attached crtc isn't\n");
5919 if (!encoder
|| encoder
->type
== INTEL_OUTPUT_DP_MST
)
5922 I915_STATE_WARN(conn_state
->best_encoder
!= &encoder
->base
,
5923 "atomic encoder doesn't match attached encoder\n");
5925 I915_STATE_WARN(conn_state
->crtc
!= encoder
->base
.crtc
,
5926 "attached encoder crtc differs from connector crtc\n");
5928 I915_STATE_WARN(crtc_state
&& crtc_state
->active
,
5929 "attached crtc is active, but connector isn't\n");
5930 I915_STATE_WARN(!crtc_state
&& conn_state
->best_encoder
,
5931 "best encoder set without crtc!\n");
5935 int intel_connector_init(struct intel_connector
*connector
)
5937 struct intel_digital_connector_state
*conn_state
;
5940 * Allocate enough memory to hold intel_digital_connector_state,
5941 * This might be a few bytes too many, but for connectors that don't
5942 * need it we'll free the state and allocate a smaller one on the first
5943 * succesful commit anyway.
5945 conn_state
= kzalloc(sizeof(*conn_state
), GFP_KERNEL
);
5949 __drm_atomic_helper_connector_reset(&connector
->base
,
5955 struct intel_connector
*intel_connector_alloc(void)
5957 struct intel_connector
*connector
;
5959 connector
= kzalloc(sizeof *connector
, GFP_KERNEL
);
5963 if (intel_connector_init(connector
) < 0) {
5971 /* Simple connector->get_hw_state implementation for encoders that support only
5972 * one connector and no cloning and hence the encoder state determines the state
5973 * of the connector. */
5974 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
5977 struct intel_encoder
*encoder
= connector
->encoder
;
5979 return encoder
->get_hw_state(encoder
, &pipe
);
5982 static int pipe_required_fdi_lanes(struct intel_crtc_state
*crtc_state
)
5984 if (crtc_state
->base
.enable
&& crtc_state
->has_pch_encoder
)
5985 return crtc_state
->fdi_lanes
;
5990 static int ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
5991 struct intel_crtc_state
*pipe_config
)
5993 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5994 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
5995 struct intel_crtc
*other_crtc
;
5996 struct intel_crtc_state
*other_crtc_state
;
5998 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
5999 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6000 if (pipe_config
->fdi_lanes
> 4) {
6001 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6002 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6006 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
6007 if (pipe_config
->fdi_lanes
> 2) {
6008 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6009 pipe_config
->fdi_lanes
);
6016 if (INTEL_INFO(dev_priv
)->num_pipes
== 2)
6019 /* Ivybridge 3 pipe is really complicated */
6024 if (pipe_config
->fdi_lanes
<= 2)
6027 other_crtc
= intel_get_crtc_for_pipe(dev_priv
, PIPE_C
);
6029 intel_atomic_get_crtc_state(state
, other_crtc
);
6030 if (IS_ERR(other_crtc_state
))
6031 return PTR_ERR(other_crtc_state
);
6033 if (pipe_required_fdi_lanes(other_crtc_state
) > 0) {
6034 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6035 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6040 if (pipe_config
->fdi_lanes
> 2) {
6041 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6042 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6046 other_crtc
= intel_get_crtc_for_pipe(dev_priv
, PIPE_B
);
6048 intel_atomic_get_crtc_state(state
, other_crtc
);
6049 if (IS_ERR(other_crtc_state
))
6050 return PTR_ERR(other_crtc_state
);
6052 if (pipe_required_fdi_lanes(other_crtc_state
) > 2) {
6053 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6063 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
6064 struct intel_crtc_state
*pipe_config
)
6066 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6067 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6068 int lane
, link_bw
, fdi_dotclock
, ret
;
6069 bool needs_recompute
= false;
6072 /* FDI is a binary signal running at ~2.7GHz, encoding
6073 * each output octet as 10 bits. The actual frequency
6074 * is stored as a divider into a 100MHz clock, and the
6075 * mode pixel clock is stored in units of 1KHz.
6076 * Hence the bw of each lane in terms of the mode signal
6079 link_bw
= intel_fdi_link_freq(to_i915(dev
), pipe_config
);
6081 fdi_dotclock
= adjusted_mode
->crtc_clock
;
6083 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
6084 pipe_config
->pipe_bpp
);
6086 pipe_config
->fdi_lanes
= lane
;
6088 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
6089 link_bw
, &pipe_config
->fdi_m_n
, false);
6091 ret
= ironlake_check_fdi_lanes(dev
, intel_crtc
->pipe
, pipe_config
);
6092 if (ret
== -EINVAL
&& pipe_config
->pipe_bpp
> 6*3) {
6093 pipe_config
->pipe_bpp
-= 2*3;
6094 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6095 pipe_config
->pipe_bpp
);
6096 needs_recompute
= true;
6097 pipe_config
->bw_constrained
= true;
6102 if (needs_recompute
)
6108 static bool pipe_config_supports_ips(struct drm_i915_private
*dev_priv
,
6109 struct intel_crtc_state
*pipe_config
)
6111 if (pipe_config
->pipe_bpp
> 24)
6114 /* HSW can handle pixel rate up to cdclk? */
6115 if (IS_HASWELL(dev_priv
))
6119 * We compare against max which means we must take
6120 * the increased cdclk requirement into account when
6121 * calculating the new cdclk.
6123 * Should measure whether using a lower cdclk w/o IPS
6125 return pipe_config
->pixel_rate
<=
6126 dev_priv
->max_cdclk_freq
* 95 / 100;
6129 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
6130 struct intel_crtc_state
*pipe_config
)
6132 struct drm_device
*dev
= crtc
->base
.dev
;
6133 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6135 pipe_config
->ips_enabled
= i915
.enable_ips
&&
6136 hsw_crtc_supports_ips(crtc
) &&
6137 pipe_config_supports_ips(dev_priv
, pipe_config
);
6140 static bool intel_crtc_supports_double_wide(const struct intel_crtc
*crtc
)
6142 const struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6144 /* GDG double wide on either pipe, otherwise pipe A only */
6145 return INTEL_INFO(dev_priv
)->gen
< 4 &&
6146 (crtc
->pipe
== PIPE_A
|| IS_I915G(dev_priv
));
6149 static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state
*pipe_config
)
6151 uint32_t pixel_rate
;
6153 pixel_rate
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
6156 * We only use IF-ID interlacing. If we ever use
6157 * PF-ID we'll need to adjust the pixel_rate here.
6160 if (pipe_config
->pch_pfit
.enabled
) {
6161 uint64_t pipe_w
, pipe_h
, pfit_w
, pfit_h
;
6162 uint32_t pfit_size
= pipe_config
->pch_pfit
.size
;
6164 pipe_w
= pipe_config
->pipe_src_w
;
6165 pipe_h
= pipe_config
->pipe_src_h
;
6167 pfit_w
= (pfit_size
>> 16) & 0xFFFF;
6168 pfit_h
= pfit_size
& 0xFFFF;
6169 if (pipe_w
< pfit_w
)
6171 if (pipe_h
< pfit_h
)
6174 if (WARN_ON(!pfit_w
|| !pfit_h
))
6177 pixel_rate
= div_u64((uint64_t) pixel_rate
* pipe_w
* pipe_h
,
6184 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state
*crtc_state
)
6186 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->base
.crtc
->dev
);
6188 if (HAS_GMCH_DISPLAY(dev_priv
))
6189 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6190 crtc_state
->pixel_rate
=
6191 crtc_state
->base
.adjusted_mode
.crtc_clock
;
6193 crtc_state
->pixel_rate
=
6194 ilk_pipe_pixel_rate(crtc_state
);
6197 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
6198 struct intel_crtc_state
*pipe_config
)
6200 struct drm_device
*dev
= crtc
->base
.dev
;
6201 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6202 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6203 int clock_limit
= dev_priv
->max_dotclk_freq
;
6205 if (INTEL_GEN(dev_priv
) < 4) {
6206 clock_limit
= dev_priv
->max_cdclk_freq
* 9 / 10;
6209 * Enable double wide mode when the dot clock
6210 * is > 90% of the (display) core speed.
6212 if (intel_crtc_supports_double_wide(crtc
) &&
6213 adjusted_mode
->crtc_clock
> clock_limit
) {
6214 clock_limit
= dev_priv
->max_dotclk_freq
;
6215 pipe_config
->double_wide
= true;
6219 if (adjusted_mode
->crtc_clock
> clock_limit
) {
6220 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6221 adjusted_mode
->crtc_clock
, clock_limit
,
6222 yesno(pipe_config
->double_wide
));
6227 * Pipe horizontal size must be even in:
6229 * - LVDS dual channel mode
6230 * - Double wide pipe
6232 if ((intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_LVDS
) &&
6233 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
6234 pipe_config
->pipe_src_w
&= ~1;
6236 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6237 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6239 if ((INTEL_GEN(dev_priv
) > 4 || IS_G4X(dev_priv
)) &&
6240 adjusted_mode
->crtc_hsync_start
== adjusted_mode
->crtc_hdisplay
)
6243 intel_crtc_compute_pixel_rate(pipe_config
);
6245 if (HAS_IPS(dev_priv
))
6246 hsw_compute_ips_config(crtc
, pipe_config
);
6248 if (pipe_config
->has_pch_encoder
)
6249 return ironlake_fdi_compute_config(crtc
, pipe_config
);
6255 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
6257 while (*num
> DATA_LINK_M_N_MASK
||
6258 *den
> DATA_LINK_M_N_MASK
) {
6264 static void compute_m_n(unsigned int m
, unsigned int n
,
6265 uint32_t *ret_m
, uint32_t *ret_n
,
6269 * Reduce M/N as much as possible without loss in precision. Several DP
6270 * dongles in particular seem to be fussy about too large *link* M/N
6271 * values. The passed in values are more likely to have the least
6272 * significant bits zero than M after rounding below, so do this first.
6275 while ((m
& 1) == 0 && (n
& 1) == 0) {
6281 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
6282 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
6283 intel_reduce_m_n_ratio(ret_m
, ret_n
);
6287 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
6288 int pixel_clock
, int link_clock
,
6289 struct intel_link_m_n
*m_n
,
6294 compute_m_n(bits_per_pixel
* pixel_clock
,
6295 link_clock
* nlanes
* 8,
6296 &m_n
->gmch_m
, &m_n
->gmch_n
,
6299 compute_m_n(pixel_clock
, link_clock
,
6300 &m_n
->link_m
, &m_n
->link_n
,
6304 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
6306 if (i915
.panel_use_ssc
>= 0)
6307 return i915
.panel_use_ssc
!= 0;
6308 return dev_priv
->vbt
.lvds_use_ssc
6309 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
6312 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
6314 return (1 << dpll
->n
) << 16 | dpll
->m2
;
6317 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
6319 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
6322 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
6323 struct intel_crtc_state
*crtc_state
,
6324 struct dpll
*reduced_clock
)
6326 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6329 if (IS_PINEVIEW(dev_priv
)) {
6330 fp
= pnv_dpll_compute_fp(&crtc_state
->dpll
);
6332 fp2
= pnv_dpll_compute_fp(reduced_clock
);
6334 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
6336 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
6339 crtc_state
->dpll_hw_state
.fp0
= fp
;
6341 crtc
->lowfreq_avail
= false;
6342 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6344 crtc_state
->dpll_hw_state
.fp1
= fp2
;
6345 crtc
->lowfreq_avail
= true;
6347 crtc_state
->dpll_hw_state
.fp1
= fp
;
6351 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
6357 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6358 * and set it to a reasonable value instead.
6360 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6361 reg_val
&= 0xffffff00;
6362 reg_val
|= 0x00000030;
6363 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6365 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6366 reg_val
&= 0x00ffffff;
6367 reg_val
|= 0x8c000000;
6368 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6370 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6371 reg_val
&= 0xffffff00;
6372 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6374 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6375 reg_val
&= 0x00ffffff;
6376 reg_val
|= 0xb0000000;
6377 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6380 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
6381 struct intel_link_m_n
*m_n
)
6383 struct drm_device
*dev
= crtc
->base
.dev
;
6384 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6385 int pipe
= crtc
->pipe
;
6387 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6388 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
6389 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
6390 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
6393 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
6394 struct intel_link_m_n
*m_n
,
6395 struct intel_link_m_n
*m2_n2
)
6397 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6398 int pipe
= crtc
->pipe
;
6399 enum transcoder transcoder
= crtc
->config
->cpu_transcoder
;
6401 if (INTEL_GEN(dev_priv
) >= 5) {
6402 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6403 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
6404 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
6405 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
6406 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
6407 * for gen < 8) and if DRRS is supported (to make sure the
6408 * registers are not unnecessarily accessed).
6410 if (m2_n2
&& (IS_CHERRYVIEW(dev_priv
) ||
6411 INTEL_GEN(dev_priv
) < 8) && crtc
->config
->has_drrs
) {
6412 I915_WRITE(PIPE_DATA_M2(transcoder
),
6413 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
6414 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
6415 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
6416 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
6419 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6420 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
6421 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
6422 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
6426 void intel_dp_set_m_n(struct intel_crtc
*crtc
, enum link_m_n_set m_n
)
6428 struct intel_link_m_n
*dp_m_n
, *dp_m2_n2
= NULL
;
6431 dp_m_n
= &crtc
->config
->dp_m_n
;
6432 dp_m2_n2
= &crtc
->config
->dp_m2_n2
;
6433 } else if (m_n
== M2_N2
) {
6436 * M2_N2 registers are not supported. Hence m2_n2 divider value
6437 * needs to be programmed into M1_N1.
6439 dp_m_n
= &crtc
->config
->dp_m2_n2
;
6441 DRM_ERROR("Unsupported divider value\n");
6445 if (crtc
->config
->has_pch_encoder
)
6446 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
->dp_m_n
);
6448 intel_cpu_transcoder_set_m_n(crtc
, dp_m_n
, dp_m2_n2
);
6451 static void vlv_compute_dpll(struct intel_crtc
*crtc
,
6452 struct intel_crtc_state
*pipe_config
)
6454 pipe_config
->dpll_hw_state
.dpll
= DPLL_INTEGRATED_REF_CLK_VLV
|
6455 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
6456 if (crtc
->pipe
!= PIPE_A
)
6457 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
6459 /* DPLL not used with DSI, but still need the rest set up */
6460 if (!intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_DSI
))
6461 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
|
6462 DPLL_EXT_BUFFER_ENABLE_VLV
;
6464 pipe_config
->dpll_hw_state
.dpll_md
=
6465 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6468 static void chv_compute_dpll(struct intel_crtc
*crtc
,
6469 struct intel_crtc_state
*pipe_config
)
6471 pipe_config
->dpll_hw_state
.dpll
= DPLL_SSC_REF_CLK_CHV
|
6472 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
6473 if (crtc
->pipe
!= PIPE_A
)
6474 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
6476 /* DPLL not used with DSI, but still need the rest set up */
6477 if (!intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_DSI
))
6478 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
;
6480 pipe_config
->dpll_hw_state
.dpll_md
=
6481 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6484 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
6485 const struct intel_crtc_state
*pipe_config
)
6487 struct drm_device
*dev
= crtc
->base
.dev
;
6488 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6489 enum pipe pipe
= crtc
->pipe
;
6491 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
6492 u32 coreclk
, reg_val
;
6495 I915_WRITE(DPLL(pipe
),
6496 pipe_config
->dpll_hw_state
.dpll
&
6497 ~(DPLL_VCO_ENABLE
| DPLL_EXT_BUFFER_ENABLE_VLV
));
6499 /* No need to actually set up the DPLL with DSI */
6500 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
6503 mutex_lock(&dev_priv
->sb_lock
);
6505 bestn
= pipe_config
->dpll
.n
;
6506 bestm1
= pipe_config
->dpll
.m1
;
6507 bestm2
= pipe_config
->dpll
.m2
;
6508 bestp1
= pipe_config
->dpll
.p1
;
6509 bestp2
= pipe_config
->dpll
.p2
;
6511 /* See eDP HDMI DPIO driver vbios notes doc */
6513 /* PLL B needs special handling */
6515 vlv_pllb_recal_opamp(dev_priv
, pipe
);
6517 /* Set up Tx target for periodic Rcomp update */
6518 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
6520 /* Disable target IRef on PLL */
6521 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
6522 reg_val
&= 0x00ffffff;
6523 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
6525 /* Disable fast lock */
6526 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
6528 /* Set idtafcrecal before PLL is enabled */
6529 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
6530 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
6531 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
6532 mdiv
|= (1 << DPIO_K_SHIFT
);
6535 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6536 * but we don't support that).
6537 * Note: don't use the DAC post divider as it seems unstable.
6539 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
6540 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
6542 mdiv
|= DPIO_ENABLE_CALIBRATION
;
6543 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
6545 /* Set HBR and RBR LPF coefficients */
6546 if (pipe_config
->port_clock
== 162000 ||
6547 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_ANALOG
) ||
6548 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_HDMI
))
6549 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
6552 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
6555 if (intel_crtc_has_dp_encoder(pipe_config
)) {
6556 /* Use SSC source */
6558 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6561 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6563 } else { /* HDMI or VGA */
6564 /* Use bend source */
6566 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6569 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6573 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
6574 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
6575 if (intel_crtc_has_dp_encoder(crtc
->config
))
6576 coreclk
|= 0x01000000;
6577 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
6579 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
6580 mutex_unlock(&dev_priv
->sb_lock
);
6583 static void chv_prepare_pll(struct intel_crtc
*crtc
,
6584 const struct intel_crtc_state
*pipe_config
)
6586 struct drm_device
*dev
= crtc
->base
.dev
;
6587 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6588 enum pipe pipe
= crtc
->pipe
;
6589 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
6590 u32 loopfilter
, tribuf_calcntr
;
6591 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
6595 /* Enable Refclk and SSC */
6596 I915_WRITE(DPLL(pipe
),
6597 pipe_config
->dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
6599 /* No need to actually set up the DPLL with DSI */
6600 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
6603 bestn
= pipe_config
->dpll
.n
;
6604 bestm2_frac
= pipe_config
->dpll
.m2
& 0x3fffff;
6605 bestm1
= pipe_config
->dpll
.m1
;
6606 bestm2
= pipe_config
->dpll
.m2
>> 22;
6607 bestp1
= pipe_config
->dpll
.p1
;
6608 bestp2
= pipe_config
->dpll
.p2
;
6609 vco
= pipe_config
->dpll
.vco
;
6613 mutex_lock(&dev_priv
->sb_lock
);
6615 /* p1 and p2 divider */
6616 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
6617 5 << DPIO_CHV_S1_DIV_SHIFT
|
6618 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
6619 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
6620 1 << DPIO_CHV_K_DIV_SHIFT
);
6622 /* Feedback post-divider - m2 */
6623 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
6625 /* Feedback refclk divider - n and m1 */
6626 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
6627 DPIO_CHV_M1_DIV_BY_2
|
6628 1 << DPIO_CHV_N_DIV_SHIFT
);
6630 /* M2 fraction division */
6631 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
6633 /* M2 fraction division enable */
6634 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
6635 dpio_val
&= ~(DPIO_CHV_FEEDFWD_GAIN_MASK
| DPIO_CHV_FRAC_DIV_EN
);
6636 dpio_val
|= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
);
6638 dpio_val
|= DPIO_CHV_FRAC_DIV_EN
;
6639 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
), dpio_val
);
6641 /* Program digital lock detect threshold */
6642 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW9(port
));
6643 dpio_val
&= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK
|
6644 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
);
6645 dpio_val
|= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT
);
6647 dpio_val
|= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
;
6648 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW9(port
), dpio_val
);
6651 if (vco
== 5400000) {
6652 loopfilter
|= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT
);
6653 loopfilter
|= (0x8 << DPIO_CHV_INT_COEFF_SHIFT
);
6654 loopfilter
|= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6655 tribuf_calcntr
= 0x9;
6656 } else if (vco
<= 6200000) {
6657 loopfilter
|= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT
);
6658 loopfilter
|= (0xB << DPIO_CHV_INT_COEFF_SHIFT
);
6659 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6660 tribuf_calcntr
= 0x9;
6661 } else if (vco
<= 6480000) {
6662 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
6663 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
6664 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6665 tribuf_calcntr
= 0x8;
6667 /* Not supported. Apply the same limits as in the max case */
6668 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
6669 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
6670 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6673 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
6675 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW8(port
));
6676 dpio_val
&= ~DPIO_CHV_TDC_TARGET_CNT_MASK
;
6677 dpio_val
|= (tribuf_calcntr
<< DPIO_CHV_TDC_TARGET_CNT_SHIFT
);
6678 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW8(port
), dpio_val
);
6681 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
6682 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
6685 mutex_unlock(&dev_priv
->sb_lock
);
6689 * vlv_force_pll_on - forcibly enable just the PLL
6690 * @dev_priv: i915 private structure
6691 * @pipe: pipe PLL to enable
6692 * @dpll: PLL configuration
6694 * Enable the PLL for @pipe using the supplied @dpll config. To be used
6695 * in cases where we need the PLL enabled even when @pipe is not going to
6698 int vlv_force_pll_on(struct drm_i915_private
*dev_priv
, enum pipe pipe
,
6699 const struct dpll
*dpll
)
6701 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
6702 struct intel_crtc_state
*pipe_config
;
6704 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
6708 pipe_config
->base
.crtc
= &crtc
->base
;
6709 pipe_config
->pixel_multiplier
= 1;
6710 pipe_config
->dpll
= *dpll
;
6712 if (IS_CHERRYVIEW(dev_priv
)) {
6713 chv_compute_dpll(crtc
, pipe_config
);
6714 chv_prepare_pll(crtc
, pipe_config
);
6715 chv_enable_pll(crtc
, pipe_config
);
6717 vlv_compute_dpll(crtc
, pipe_config
);
6718 vlv_prepare_pll(crtc
, pipe_config
);
6719 vlv_enable_pll(crtc
, pipe_config
);
6728 * vlv_force_pll_off - forcibly disable just the PLL
6729 * @dev_priv: i915 private structure
6730 * @pipe: pipe PLL to disable
6732 * Disable the PLL for @pipe. To be used in cases where we need
6733 * the PLL enabled even when @pipe is not going to be enabled.
6735 void vlv_force_pll_off(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
6737 if (IS_CHERRYVIEW(dev_priv
))
6738 chv_disable_pll(dev_priv
, pipe
);
6740 vlv_disable_pll(dev_priv
, pipe
);
6743 static void i9xx_compute_dpll(struct intel_crtc
*crtc
,
6744 struct intel_crtc_state
*crtc_state
,
6745 struct dpll
*reduced_clock
)
6747 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6749 struct dpll
*clock
= &crtc_state
->dpll
;
6751 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
6753 dpll
= DPLL_VGA_MODE_DIS
;
6755 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
))
6756 dpll
|= DPLLB_MODE_LVDS
;
6758 dpll
|= DPLLB_MODE_DAC_SERIAL
;
6760 if (IS_I945G(dev_priv
) || IS_I945GM(dev_priv
) ||
6761 IS_G33(dev_priv
) || IS_PINEVIEW(dev_priv
)) {
6762 dpll
|= (crtc_state
->pixel_multiplier
- 1)
6763 << SDVO_MULTIPLIER_SHIFT_HIRES
;
6766 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
6767 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
6768 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6770 if (intel_crtc_has_dp_encoder(crtc_state
))
6771 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6773 /* compute bitmask from p1 value */
6774 if (IS_PINEVIEW(dev_priv
))
6775 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
6777 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6778 if (IS_G4X(dev_priv
) && reduced_clock
)
6779 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
6781 switch (clock
->p2
) {
6783 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
6786 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
6789 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
6792 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
6795 if (INTEL_GEN(dev_priv
) >= 4)
6796 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
6798 if (crtc_state
->sdvo_tv_clock
)
6799 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
6800 else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6801 intel_panel_use_ssc(dev_priv
))
6802 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
6804 dpll
|= PLL_REF_INPUT_DREFCLK
;
6806 dpll
|= DPLL_VCO_ENABLE
;
6807 crtc_state
->dpll_hw_state
.dpll
= dpll
;
6809 if (INTEL_GEN(dev_priv
) >= 4) {
6810 u32 dpll_md
= (crtc_state
->pixel_multiplier
- 1)
6811 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6812 crtc_state
->dpll_hw_state
.dpll_md
= dpll_md
;
6816 static void i8xx_compute_dpll(struct intel_crtc
*crtc
,
6817 struct intel_crtc_state
*crtc_state
,
6818 struct dpll
*reduced_clock
)
6820 struct drm_device
*dev
= crtc
->base
.dev
;
6821 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6823 struct dpll
*clock
= &crtc_state
->dpll
;
6825 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
6827 dpll
= DPLL_VGA_MODE_DIS
;
6829 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
6830 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6833 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
6835 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6837 dpll
|= PLL_P2_DIVIDE_BY_4
;
6840 if (!IS_I830(dev_priv
) &&
6841 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DVO
))
6842 dpll
|= DPLL_DVO_2X_MODE
;
6844 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6845 intel_panel_use_ssc(dev_priv
))
6846 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
6848 dpll
|= PLL_REF_INPUT_DREFCLK
;
6850 dpll
|= DPLL_VCO_ENABLE
;
6851 crtc_state
->dpll_hw_state
.dpll
= dpll
;
6854 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
6856 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
6857 enum pipe pipe
= intel_crtc
->pipe
;
6858 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
6859 const struct drm_display_mode
*adjusted_mode
= &intel_crtc
->config
->base
.adjusted_mode
;
6860 uint32_t crtc_vtotal
, crtc_vblank_end
;
6863 /* We need to be careful not to changed the adjusted mode, for otherwise
6864 * the hw state checker will get angry at the mismatch. */
6865 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
6866 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
6868 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
6869 /* the chip adds 2 halflines automatically */
6871 crtc_vblank_end
-= 1;
6873 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
6874 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
6876 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
6877 adjusted_mode
->crtc_htotal
/ 2;
6879 vsyncshift
+= adjusted_mode
->crtc_htotal
;
6882 if (INTEL_GEN(dev_priv
) > 3)
6883 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
6885 I915_WRITE(HTOTAL(cpu_transcoder
),
6886 (adjusted_mode
->crtc_hdisplay
- 1) |
6887 ((adjusted_mode
->crtc_htotal
- 1) << 16));
6888 I915_WRITE(HBLANK(cpu_transcoder
),
6889 (adjusted_mode
->crtc_hblank_start
- 1) |
6890 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
6891 I915_WRITE(HSYNC(cpu_transcoder
),
6892 (adjusted_mode
->crtc_hsync_start
- 1) |
6893 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
6895 I915_WRITE(VTOTAL(cpu_transcoder
),
6896 (adjusted_mode
->crtc_vdisplay
- 1) |
6897 ((crtc_vtotal
- 1) << 16));
6898 I915_WRITE(VBLANK(cpu_transcoder
),
6899 (adjusted_mode
->crtc_vblank_start
- 1) |
6900 ((crtc_vblank_end
- 1) << 16));
6901 I915_WRITE(VSYNC(cpu_transcoder
),
6902 (adjusted_mode
->crtc_vsync_start
- 1) |
6903 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
6905 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
6906 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
6907 * documented on the DDI_FUNC_CTL register description, EDP Input Select
6909 if (IS_HASWELL(dev_priv
) && cpu_transcoder
== TRANSCODER_EDP
&&
6910 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
6911 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
6915 static void intel_set_pipe_src_size(struct intel_crtc
*intel_crtc
)
6917 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6918 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6919 enum pipe pipe
= intel_crtc
->pipe
;
6921 /* pipesrc controls the size that is scaled from, which should
6922 * always be the user's requested size.
6924 I915_WRITE(PIPESRC(pipe
),
6925 ((intel_crtc
->config
->pipe_src_w
- 1) << 16) |
6926 (intel_crtc
->config
->pipe_src_h
- 1));
6929 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
6930 struct intel_crtc_state
*pipe_config
)
6932 struct drm_device
*dev
= crtc
->base
.dev
;
6933 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6934 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
6937 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
6938 pipe_config
->base
.adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
6939 pipe_config
->base
.adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
6940 tmp
= I915_READ(HBLANK(cpu_transcoder
));
6941 pipe_config
->base
.adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
6942 pipe_config
->base
.adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
6943 tmp
= I915_READ(HSYNC(cpu_transcoder
));
6944 pipe_config
->base
.adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
6945 pipe_config
->base
.adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
6947 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
6948 pipe_config
->base
.adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
6949 pipe_config
->base
.adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
6950 tmp
= I915_READ(VBLANK(cpu_transcoder
));
6951 pipe_config
->base
.adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
6952 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
6953 tmp
= I915_READ(VSYNC(cpu_transcoder
));
6954 pipe_config
->base
.adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
6955 pipe_config
->base
.adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
6957 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
6958 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
6959 pipe_config
->base
.adjusted_mode
.crtc_vtotal
+= 1;
6960 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
+= 1;
6964 static void intel_get_pipe_src_size(struct intel_crtc
*crtc
,
6965 struct intel_crtc_state
*pipe_config
)
6967 struct drm_device
*dev
= crtc
->base
.dev
;
6968 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6971 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
6972 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
6973 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
6975 pipe_config
->base
.mode
.vdisplay
= pipe_config
->pipe_src_h
;
6976 pipe_config
->base
.mode
.hdisplay
= pipe_config
->pipe_src_w
;
6979 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
6980 struct intel_crtc_state
*pipe_config
)
6982 mode
->hdisplay
= pipe_config
->base
.adjusted_mode
.crtc_hdisplay
;
6983 mode
->htotal
= pipe_config
->base
.adjusted_mode
.crtc_htotal
;
6984 mode
->hsync_start
= pipe_config
->base
.adjusted_mode
.crtc_hsync_start
;
6985 mode
->hsync_end
= pipe_config
->base
.adjusted_mode
.crtc_hsync_end
;
6987 mode
->vdisplay
= pipe_config
->base
.adjusted_mode
.crtc_vdisplay
;
6988 mode
->vtotal
= pipe_config
->base
.adjusted_mode
.crtc_vtotal
;
6989 mode
->vsync_start
= pipe_config
->base
.adjusted_mode
.crtc_vsync_start
;
6990 mode
->vsync_end
= pipe_config
->base
.adjusted_mode
.crtc_vsync_end
;
6992 mode
->flags
= pipe_config
->base
.adjusted_mode
.flags
;
6993 mode
->type
= DRM_MODE_TYPE_DRIVER
;
6995 mode
->clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
6997 mode
->hsync
= drm_mode_hsync(mode
);
6998 mode
->vrefresh
= drm_mode_vrefresh(mode
);
6999 drm_mode_set_name(mode
);
7002 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
7004 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
7009 /* we keep both pipes enabled on 830 */
7010 if (IS_I830(dev_priv
))
7011 pipeconf
|= I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
;
7013 if (intel_crtc
->config
->double_wide
)
7014 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
7016 /* only g4x and later have fancy bpc/dither controls */
7017 if (IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
7018 IS_CHERRYVIEW(dev_priv
)) {
7019 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7020 if (intel_crtc
->config
->dither
&& intel_crtc
->config
->pipe_bpp
!= 30)
7021 pipeconf
|= PIPECONF_DITHER_EN
|
7022 PIPECONF_DITHER_TYPE_SP
;
7024 switch (intel_crtc
->config
->pipe_bpp
) {
7026 pipeconf
|= PIPECONF_6BPC
;
7029 pipeconf
|= PIPECONF_8BPC
;
7032 pipeconf
|= PIPECONF_10BPC
;
7035 /* Case prevented by intel_choose_pipe_bpp_dither. */
7040 if (HAS_PIPE_CXSR(dev_priv
)) {
7041 if (intel_crtc
->lowfreq_avail
) {
7042 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
7043 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
7045 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
7049 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
7050 if (INTEL_GEN(dev_priv
) < 4 ||
7051 intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
7052 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
7054 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
7056 pipeconf
|= PIPECONF_PROGRESSIVE
;
7058 if ((IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) &&
7059 intel_crtc
->config
->limited_color_range
)
7060 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
7062 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
7063 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
7066 static int i8xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7067 struct intel_crtc_state
*crtc_state
)
7069 struct drm_device
*dev
= crtc
->base
.dev
;
7070 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7071 const struct intel_limit
*limit
;
7074 memset(&crtc_state
->dpll_hw_state
, 0,
7075 sizeof(crtc_state
->dpll_hw_state
));
7077 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7078 if (intel_panel_use_ssc(dev_priv
)) {
7079 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7080 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7083 limit
= &intel_limits_i8xx_lvds
;
7084 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DVO
)) {
7085 limit
= &intel_limits_i8xx_dvo
;
7087 limit
= &intel_limits_i8xx_dac
;
7090 if (!crtc_state
->clock_set
&&
7091 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7092 refclk
, NULL
, &crtc_state
->dpll
)) {
7093 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7097 i8xx_compute_dpll(crtc
, crtc_state
, NULL
);
7102 static int g4x_crtc_compute_clock(struct intel_crtc
*crtc
,
7103 struct intel_crtc_state
*crtc_state
)
7105 struct drm_device
*dev
= crtc
->base
.dev
;
7106 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7107 const struct intel_limit
*limit
;
7110 memset(&crtc_state
->dpll_hw_state
, 0,
7111 sizeof(crtc_state
->dpll_hw_state
));
7113 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7114 if (intel_panel_use_ssc(dev_priv
)) {
7115 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7116 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7119 if (intel_is_dual_link_lvds(dev
))
7120 limit
= &intel_limits_g4x_dual_channel_lvds
;
7122 limit
= &intel_limits_g4x_single_channel_lvds
;
7123 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
) ||
7124 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
)) {
7125 limit
= &intel_limits_g4x_hdmi
;
7126 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
)) {
7127 limit
= &intel_limits_g4x_sdvo
;
7129 /* The option is for other outputs */
7130 limit
= &intel_limits_i9xx_sdvo
;
7133 if (!crtc_state
->clock_set
&&
7134 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7135 refclk
, NULL
, &crtc_state
->dpll
)) {
7136 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7140 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7145 static int pnv_crtc_compute_clock(struct intel_crtc
*crtc
,
7146 struct intel_crtc_state
*crtc_state
)
7148 struct drm_device
*dev
= crtc
->base
.dev
;
7149 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7150 const struct intel_limit
*limit
;
7153 memset(&crtc_state
->dpll_hw_state
, 0,
7154 sizeof(crtc_state
->dpll_hw_state
));
7156 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7157 if (intel_panel_use_ssc(dev_priv
)) {
7158 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7159 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7162 limit
= &intel_limits_pineview_lvds
;
7164 limit
= &intel_limits_pineview_sdvo
;
7167 if (!crtc_state
->clock_set
&&
7168 !pnv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7169 refclk
, NULL
, &crtc_state
->dpll
)) {
7170 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7174 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7179 static int i9xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7180 struct intel_crtc_state
*crtc_state
)
7182 struct drm_device
*dev
= crtc
->base
.dev
;
7183 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7184 const struct intel_limit
*limit
;
7187 memset(&crtc_state
->dpll_hw_state
, 0,
7188 sizeof(crtc_state
->dpll_hw_state
));
7190 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7191 if (intel_panel_use_ssc(dev_priv
)) {
7192 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7193 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7196 limit
= &intel_limits_i9xx_lvds
;
7198 limit
= &intel_limits_i9xx_sdvo
;
7201 if (!crtc_state
->clock_set
&&
7202 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7203 refclk
, NULL
, &crtc_state
->dpll
)) {
7204 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7208 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7213 static int chv_crtc_compute_clock(struct intel_crtc
*crtc
,
7214 struct intel_crtc_state
*crtc_state
)
7216 int refclk
= 100000;
7217 const struct intel_limit
*limit
= &intel_limits_chv
;
7219 memset(&crtc_state
->dpll_hw_state
, 0,
7220 sizeof(crtc_state
->dpll_hw_state
));
7222 if (!crtc_state
->clock_set
&&
7223 !chv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7224 refclk
, NULL
, &crtc_state
->dpll
)) {
7225 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7229 chv_compute_dpll(crtc
, crtc_state
);
7234 static int vlv_crtc_compute_clock(struct intel_crtc
*crtc
,
7235 struct intel_crtc_state
*crtc_state
)
7237 int refclk
= 100000;
7238 const struct intel_limit
*limit
= &intel_limits_vlv
;
7240 memset(&crtc_state
->dpll_hw_state
, 0,
7241 sizeof(crtc_state
->dpll_hw_state
));
7243 if (!crtc_state
->clock_set
&&
7244 !vlv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7245 refclk
, NULL
, &crtc_state
->dpll
)) {
7246 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7250 vlv_compute_dpll(crtc
, crtc_state
);
7255 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
7256 struct intel_crtc_state
*pipe_config
)
7258 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7261 if (INTEL_GEN(dev_priv
) <= 3 &&
7262 (IS_I830(dev_priv
) || !IS_MOBILE(dev_priv
)))
7265 tmp
= I915_READ(PFIT_CONTROL
);
7266 if (!(tmp
& PFIT_ENABLE
))
7269 /* Check whether the pfit is attached to our pipe. */
7270 if (INTEL_GEN(dev_priv
) < 4) {
7271 if (crtc
->pipe
!= PIPE_B
)
7274 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
7278 pipe_config
->gmch_pfit
.control
= tmp
;
7279 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
7282 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
7283 struct intel_crtc_state
*pipe_config
)
7285 struct drm_device
*dev
= crtc
->base
.dev
;
7286 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7287 int pipe
= pipe_config
->cpu_transcoder
;
7290 int refclk
= 100000;
7292 /* In case of DSI, DPLL will not be used */
7293 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7296 mutex_lock(&dev_priv
->sb_lock
);
7297 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
7298 mutex_unlock(&dev_priv
->sb_lock
);
7300 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
7301 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
7302 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
7303 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
7304 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
7306 pipe_config
->port_clock
= vlv_calc_dpll_params(refclk
, &clock
);
7310 i9xx_get_initial_plane_config(struct intel_crtc
*crtc
,
7311 struct intel_initial_plane_config
*plane_config
)
7313 struct drm_device
*dev
= crtc
->base
.dev
;
7314 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7315 u32 val
, base
, offset
;
7316 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
7317 int fourcc
, pixel_format
;
7318 unsigned int aligned_height
;
7319 struct drm_framebuffer
*fb
;
7320 struct intel_framebuffer
*intel_fb
;
7322 val
= I915_READ(DSPCNTR(plane
));
7323 if (!(val
& DISPLAY_PLANE_ENABLE
))
7326 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
7328 DRM_DEBUG_KMS("failed to alloc fb\n");
7332 fb
= &intel_fb
->base
;
7336 if (INTEL_GEN(dev_priv
) >= 4) {
7337 if (val
& DISPPLANE_TILED
) {
7338 plane_config
->tiling
= I915_TILING_X
;
7339 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
7343 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
7344 fourcc
= i9xx_format_to_fourcc(pixel_format
);
7345 fb
->format
= drm_format_info(fourcc
);
7347 if (INTEL_GEN(dev_priv
) >= 4) {
7348 if (plane_config
->tiling
)
7349 offset
= I915_READ(DSPTILEOFF(plane
));
7351 offset
= I915_READ(DSPLINOFF(plane
));
7352 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
7354 base
= I915_READ(DSPADDR(plane
));
7356 plane_config
->base
= base
;
7358 val
= I915_READ(PIPESRC(pipe
));
7359 fb
->width
= ((val
>> 16) & 0xfff) + 1;
7360 fb
->height
= ((val
>> 0) & 0xfff) + 1;
7362 val
= I915_READ(DSPSTRIDE(pipe
));
7363 fb
->pitches
[0] = val
& 0xffffffc0;
7365 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
7367 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
7369 DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7370 pipe_name(pipe
), plane
, fb
->width
, fb
->height
,
7371 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
7372 plane_config
->size
);
7374 plane_config
->fb
= intel_fb
;
7377 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
7378 struct intel_crtc_state
*pipe_config
)
7380 struct drm_device
*dev
= crtc
->base
.dev
;
7381 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7382 int pipe
= pipe_config
->cpu_transcoder
;
7383 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
7385 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
, pll_dw3
;
7386 int refclk
= 100000;
7388 /* In case of DSI, DPLL will not be used */
7389 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7392 mutex_lock(&dev_priv
->sb_lock
);
7393 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
7394 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
7395 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
7396 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
7397 pll_dw3
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
7398 mutex_unlock(&dev_priv
->sb_lock
);
7400 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
7401 clock
.m2
= (pll_dw0
& 0xff) << 22;
7402 if (pll_dw3
& DPIO_CHV_FRAC_DIV_EN
)
7403 clock
.m2
|= pll_dw2
& 0x3fffff;
7404 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
7405 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
7406 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
7408 pipe_config
->port_clock
= chv_calc_dpll_params(refclk
, &clock
);
7411 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
7412 struct intel_crtc_state
*pipe_config
)
7414 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7415 enum intel_display_power_domain power_domain
;
7419 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
7420 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
7423 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7424 pipe_config
->shared_dpll
= NULL
;
7428 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
7429 if (!(tmp
& PIPECONF_ENABLE
))
7432 if (IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
7433 IS_CHERRYVIEW(dev_priv
)) {
7434 switch (tmp
& PIPECONF_BPC_MASK
) {
7436 pipe_config
->pipe_bpp
= 18;
7439 pipe_config
->pipe_bpp
= 24;
7441 case PIPECONF_10BPC
:
7442 pipe_config
->pipe_bpp
= 30;
7449 if ((IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) &&
7450 (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
7451 pipe_config
->limited_color_range
= true;
7453 if (INTEL_GEN(dev_priv
) < 4)
7454 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
7456 intel_get_pipe_timings(crtc
, pipe_config
);
7457 intel_get_pipe_src_size(crtc
, pipe_config
);
7459 i9xx_get_pfit_config(crtc
, pipe_config
);
7461 if (INTEL_GEN(dev_priv
) >= 4) {
7462 /* No way to read it out on pipes B and C */
7463 if (IS_CHERRYVIEW(dev_priv
) && crtc
->pipe
!= PIPE_A
)
7464 tmp
= dev_priv
->chv_dpll_md
[crtc
->pipe
];
7466 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
7467 pipe_config
->pixel_multiplier
=
7468 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
7469 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
7470 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
7471 } else if (IS_I945G(dev_priv
) || IS_I945GM(dev_priv
) ||
7472 IS_G33(dev_priv
) || IS_PINEVIEW(dev_priv
)) {
7473 tmp
= I915_READ(DPLL(crtc
->pipe
));
7474 pipe_config
->pixel_multiplier
=
7475 ((tmp
& SDVO_MULTIPLIER_MASK
)
7476 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
7478 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7479 * port and will be fixed up in the encoder->get_config
7481 pipe_config
->pixel_multiplier
= 1;
7483 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
7484 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
)) {
7486 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
7487 * on 830. Filter it out here so that we don't
7488 * report errors due to that.
7490 if (IS_I830(dev_priv
))
7491 pipe_config
->dpll_hw_state
.dpll
&= ~DPLL_DVO_2X_MODE
;
7493 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
7494 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
7496 /* Mask out read-only status bits. */
7497 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
7498 DPLL_PORTC_READY_MASK
|
7499 DPLL_PORTB_READY_MASK
);
7502 if (IS_CHERRYVIEW(dev_priv
))
7503 chv_crtc_clock_get(crtc
, pipe_config
);
7504 else if (IS_VALLEYVIEW(dev_priv
))
7505 vlv_crtc_clock_get(crtc
, pipe_config
);
7507 i9xx_crtc_clock_get(crtc
, pipe_config
);
7510 * Normally the dotclock is filled in by the encoder .get_config()
7511 * but in case the pipe is enabled w/o any ports we need a sane
7514 pipe_config
->base
.adjusted_mode
.crtc_clock
=
7515 pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
7520 intel_display_power_put(dev_priv
, power_domain
);
7525 static void ironlake_init_pch_refclk(struct drm_i915_private
*dev_priv
)
7527 struct intel_encoder
*encoder
;
7530 bool has_lvds
= false;
7531 bool has_cpu_edp
= false;
7532 bool has_panel
= false;
7533 bool has_ck505
= false;
7534 bool can_ssc
= false;
7535 bool using_ssc_source
= false;
7537 /* We need to take the global config into account */
7538 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
7539 switch (encoder
->type
) {
7540 case INTEL_OUTPUT_LVDS
:
7544 case INTEL_OUTPUT_EDP
:
7546 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
7554 if (HAS_PCH_IBX(dev_priv
)) {
7555 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
7556 can_ssc
= has_ck505
;
7562 /* Check if any DPLLs are using the SSC source */
7563 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
7564 u32 temp
= I915_READ(PCH_DPLL(i
));
7566 if (!(temp
& DPLL_VCO_ENABLE
))
7569 if ((temp
& PLL_REF_INPUT_MASK
) ==
7570 PLLB_REF_INPUT_SPREADSPECTRUMIN
) {
7571 using_ssc_source
= true;
7576 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
7577 has_panel
, has_lvds
, has_ck505
, using_ssc_source
);
7579 /* Ironlake: try to setup display ref clock before DPLL
7580 * enabling. This is only under driver's control after
7581 * PCH B stepping, previous chipset stepping should be
7582 * ignoring this setting.
7584 val
= I915_READ(PCH_DREF_CONTROL
);
7586 /* As we must carefully and slowly disable/enable each source in turn,
7587 * compute the final state we want first and check if we need to
7588 * make any changes at all.
7591 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
7593 final
|= DREF_NONSPREAD_CK505_ENABLE
;
7595 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
7597 final
&= ~DREF_SSC_SOURCE_MASK
;
7598 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7599 final
&= ~DREF_SSC1_ENABLE
;
7602 final
|= DREF_SSC_SOURCE_ENABLE
;
7604 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
7605 final
|= DREF_SSC1_ENABLE
;
7608 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
7609 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
7611 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
7613 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7614 } else if (using_ssc_source
) {
7615 final
|= DREF_SSC_SOURCE_ENABLE
;
7616 final
|= DREF_SSC1_ENABLE
;
7622 /* Always enable nonspread source */
7623 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
7626 val
|= DREF_NONSPREAD_CK505_ENABLE
;
7628 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
7631 val
&= ~DREF_SSC_SOURCE_MASK
;
7632 val
|= DREF_SSC_SOURCE_ENABLE
;
7634 /* SSC must be turned on before enabling the CPU output */
7635 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
7636 DRM_DEBUG_KMS("Using SSC on panel\n");
7637 val
|= DREF_SSC1_ENABLE
;
7639 val
&= ~DREF_SSC1_ENABLE
;
7641 /* Get SSC going before enabling the outputs */
7642 I915_WRITE(PCH_DREF_CONTROL
, val
);
7643 POSTING_READ(PCH_DREF_CONTROL
);
7646 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7648 /* Enable CPU source on CPU attached eDP */
7650 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
7651 DRM_DEBUG_KMS("Using SSC on eDP\n");
7652 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
7654 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
7656 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7658 I915_WRITE(PCH_DREF_CONTROL
, val
);
7659 POSTING_READ(PCH_DREF_CONTROL
);
7662 DRM_DEBUG_KMS("Disabling CPU source output\n");
7664 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7666 /* Turn off CPU output */
7667 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7669 I915_WRITE(PCH_DREF_CONTROL
, val
);
7670 POSTING_READ(PCH_DREF_CONTROL
);
7673 if (!using_ssc_source
) {
7674 DRM_DEBUG_KMS("Disabling SSC source\n");
7676 /* Turn off the SSC source */
7677 val
&= ~DREF_SSC_SOURCE_MASK
;
7678 val
|= DREF_SSC_SOURCE_DISABLE
;
7681 val
&= ~DREF_SSC1_ENABLE
;
7683 I915_WRITE(PCH_DREF_CONTROL
, val
);
7684 POSTING_READ(PCH_DREF_CONTROL
);
7689 BUG_ON(val
!= final
);
7692 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
7696 tmp
= I915_READ(SOUTH_CHICKEN2
);
7697 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
7698 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
7700 if (wait_for_us(I915_READ(SOUTH_CHICKEN2
) &
7701 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
7702 DRM_ERROR("FDI mPHY reset assert timeout\n");
7704 tmp
= I915_READ(SOUTH_CHICKEN2
);
7705 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
7706 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
7708 if (wait_for_us((I915_READ(SOUTH_CHICKEN2
) &
7709 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
7710 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
7713 /* WaMPhyProgramming:hsw */
7714 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
7718 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
7719 tmp
&= ~(0xFF << 24);
7720 tmp
|= (0x12 << 24);
7721 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
7723 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
7725 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
7727 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
7729 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
7731 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
7732 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
7733 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
7735 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
7736 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
7737 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
7739 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
7742 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
7744 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
7747 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
7749 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
7752 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
7754 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
7757 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
7759 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
7760 tmp
&= ~(0xFF << 16);
7761 tmp
|= (0x1C << 16);
7762 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
7764 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
7765 tmp
&= ~(0xFF << 16);
7766 tmp
|= (0x1C << 16);
7767 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
7769 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
7771 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
7773 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
7775 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
7777 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
7778 tmp
&= ~(0xF << 28);
7780 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
7782 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
7783 tmp
&= ~(0xF << 28);
7785 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
7788 /* Implements 3 different sequences from BSpec chapter "Display iCLK
7789 * Programming" based on the parameters passed:
7790 * - Sequence to enable CLKOUT_DP
7791 * - Sequence to enable CLKOUT_DP without spread
7792 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
7794 static void lpt_enable_clkout_dp(struct drm_i915_private
*dev_priv
,
7795 bool with_spread
, bool with_fdi
)
7799 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
7801 if (WARN(HAS_PCH_LPT_LP(dev_priv
) &&
7802 with_fdi
, "LP PCH doesn't have FDI\n"))
7805 mutex_lock(&dev_priv
->sb_lock
);
7807 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7808 tmp
&= ~SBI_SSCCTL_DISABLE
;
7809 tmp
|= SBI_SSCCTL_PATHALT
;
7810 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7815 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7816 tmp
&= ~SBI_SSCCTL_PATHALT
;
7817 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7820 lpt_reset_fdi_mphy(dev_priv
);
7821 lpt_program_fdi_mphy(dev_priv
);
7825 reg
= HAS_PCH_LPT_LP(dev_priv
) ? SBI_GEN0
: SBI_DBUFF0
;
7826 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
7827 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
7828 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
7830 mutex_unlock(&dev_priv
->sb_lock
);
7833 /* Sequence to disable CLKOUT_DP */
7834 static void lpt_disable_clkout_dp(struct drm_i915_private
*dev_priv
)
7838 mutex_lock(&dev_priv
->sb_lock
);
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 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7846 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
7847 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
7848 tmp
|= SBI_SSCCTL_PATHALT
;
7849 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7852 tmp
|= SBI_SSCCTL_DISABLE
;
7853 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7856 mutex_unlock(&dev_priv
->sb_lock
);
7859 #define BEND_IDX(steps) ((50 + (steps)) / 5)
7861 static const uint16_t sscdivintphase
[] = {
7862 [BEND_IDX( 50)] = 0x3B23,
7863 [BEND_IDX( 45)] = 0x3B23,
7864 [BEND_IDX( 40)] = 0x3C23,
7865 [BEND_IDX( 35)] = 0x3C23,
7866 [BEND_IDX( 30)] = 0x3D23,
7867 [BEND_IDX( 25)] = 0x3D23,
7868 [BEND_IDX( 20)] = 0x3E23,
7869 [BEND_IDX( 15)] = 0x3E23,
7870 [BEND_IDX( 10)] = 0x3F23,
7871 [BEND_IDX( 5)] = 0x3F23,
7872 [BEND_IDX( 0)] = 0x0025,
7873 [BEND_IDX( -5)] = 0x0025,
7874 [BEND_IDX(-10)] = 0x0125,
7875 [BEND_IDX(-15)] = 0x0125,
7876 [BEND_IDX(-20)] = 0x0225,
7877 [BEND_IDX(-25)] = 0x0225,
7878 [BEND_IDX(-30)] = 0x0325,
7879 [BEND_IDX(-35)] = 0x0325,
7880 [BEND_IDX(-40)] = 0x0425,
7881 [BEND_IDX(-45)] = 0x0425,
7882 [BEND_IDX(-50)] = 0x0525,
7887 * steps -50 to 50 inclusive, in steps of 5
7888 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
7889 * change in clock period = -(steps / 10) * 5.787 ps
7891 static void lpt_bend_clkout_dp(struct drm_i915_private
*dev_priv
, int steps
)
7894 int idx
= BEND_IDX(steps
);
7896 if (WARN_ON(steps
% 5 != 0))
7899 if (WARN_ON(idx
>= ARRAY_SIZE(sscdivintphase
)))
7902 mutex_lock(&dev_priv
->sb_lock
);
7904 if (steps
% 10 != 0)
7908 intel_sbi_write(dev_priv
, SBI_SSCDITHPHASE
, tmp
, SBI_ICLK
);
7910 tmp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE
, SBI_ICLK
);
7912 tmp
|= sscdivintphase
[idx
];
7913 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE
, tmp
, SBI_ICLK
);
7915 mutex_unlock(&dev_priv
->sb_lock
);
7920 static void lpt_init_pch_refclk(struct drm_i915_private
*dev_priv
)
7922 struct intel_encoder
*encoder
;
7923 bool has_vga
= false;
7925 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
7926 switch (encoder
->type
) {
7927 case INTEL_OUTPUT_ANALOG
:
7936 lpt_bend_clkout_dp(dev_priv
, 0);
7937 lpt_enable_clkout_dp(dev_priv
, true, true);
7939 lpt_disable_clkout_dp(dev_priv
);
7944 * Initialize reference clocks when the driver loads
7946 void intel_init_pch_refclk(struct drm_i915_private
*dev_priv
)
7948 if (HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
))
7949 ironlake_init_pch_refclk(dev_priv
);
7950 else if (HAS_PCH_LPT(dev_priv
))
7951 lpt_init_pch_refclk(dev_priv
);
7954 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
7956 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
7957 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7958 int pipe
= intel_crtc
->pipe
;
7963 switch (intel_crtc
->config
->pipe_bpp
) {
7965 val
|= PIPECONF_6BPC
;
7968 val
|= PIPECONF_8BPC
;
7971 val
|= PIPECONF_10BPC
;
7974 val
|= PIPECONF_12BPC
;
7977 /* Case prevented by intel_choose_pipe_bpp_dither. */
7981 if (intel_crtc
->config
->dither
)
7982 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
7984 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
7985 val
|= PIPECONF_INTERLACED_ILK
;
7987 val
|= PIPECONF_PROGRESSIVE
;
7989 if (intel_crtc
->config
->limited_color_range
)
7990 val
|= PIPECONF_COLOR_RANGE_SELECT
;
7992 I915_WRITE(PIPECONF(pipe
), val
);
7993 POSTING_READ(PIPECONF(pipe
));
7996 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
7998 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
7999 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8000 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
8003 if (IS_HASWELL(dev_priv
) && intel_crtc
->config
->dither
)
8004 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
8006 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8007 val
|= PIPECONF_INTERLACED_ILK
;
8009 val
|= PIPECONF_PROGRESSIVE
;
8011 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
8012 POSTING_READ(PIPECONF(cpu_transcoder
));
8015 static void haswell_set_pipemisc(struct drm_crtc
*crtc
)
8017 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
8018 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8020 if (IS_BROADWELL(dev_priv
) || INTEL_INFO(dev_priv
)->gen
>= 9) {
8023 switch (intel_crtc
->config
->pipe_bpp
) {
8025 val
|= PIPEMISC_DITHER_6_BPC
;
8028 val
|= PIPEMISC_DITHER_8_BPC
;
8031 val
|= PIPEMISC_DITHER_10_BPC
;
8034 val
|= PIPEMISC_DITHER_12_BPC
;
8037 /* Case prevented by pipe_config_set_bpp. */
8041 if (intel_crtc
->config
->dither
)
8042 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
8044 I915_WRITE(PIPEMISC(intel_crtc
->pipe
), val
);
8048 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
8051 * Account for spread spectrum to avoid
8052 * oversubscribing the link. Max center spread
8053 * is 2.5%; use 5% for safety's sake.
8055 u32 bps
= target_clock
* bpp
* 21 / 20;
8056 return DIV_ROUND_UP(bps
, link_bw
* 8);
8059 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
8061 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
8064 static void ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
8065 struct intel_crtc_state
*crtc_state
,
8066 struct dpll
*reduced_clock
)
8068 struct drm_crtc
*crtc
= &intel_crtc
->base
;
8069 struct drm_device
*dev
= crtc
->dev
;
8070 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8074 /* Enable autotuning of the PLL clock (if permissible) */
8076 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8077 if ((intel_panel_use_ssc(dev_priv
) &&
8078 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
8079 (HAS_PCH_IBX(dev_priv
) && intel_is_dual_link_lvds(dev
)))
8081 } else if (crtc_state
->sdvo_tv_clock
)
8084 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
8086 if (ironlake_needs_fb_cb_tune(&crtc_state
->dpll
, factor
))
8089 if (reduced_clock
) {
8090 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
8092 if (reduced_clock
->m
< factor
* reduced_clock
->n
)
8100 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
))
8101 dpll
|= DPLLB_MODE_LVDS
;
8103 dpll
|= DPLLB_MODE_DAC_SERIAL
;
8105 dpll
|= (crtc_state
->pixel_multiplier
- 1)
8106 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
8108 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
8109 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
8110 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8112 if (intel_crtc_has_dp_encoder(crtc_state
))
8113 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8116 * The high speed IO clock is only really required for
8117 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8118 * possible to share the DPLL between CRT and HDMI. Enabling
8119 * the clock needlessly does no real harm, except use up a
8120 * bit of power potentially.
8122 * We'll limit this to IVB with 3 pipes, since it has only two
8123 * DPLLs and so DPLL sharing is the only way to get three pipes
8124 * driving PCH ports at the same time. On SNB we could do this,
8125 * and potentially avoid enabling the second DPLL, but it's not
8126 * clear if it''s a win or loss power wise. No point in doing
8127 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8129 if (INTEL_INFO(dev_priv
)->num_pipes
== 3 &&
8130 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
))
8131 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8133 /* compute bitmask from p1 value */
8134 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8136 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
8138 switch (crtc_state
->dpll
.p2
) {
8140 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
8143 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
8146 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
8149 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
8153 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
8154 intel_panel_use_ssc(dev_priv
))
8155 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
8157 dpll
|= PLL_REF_INPUT_DREFCLK
;
8159 dpll
|= DPLL_VCO_ENABLE
;
8161 crtc_state
->dpll_hw_state
.dpll
= dpll
;
8162 crtc_state
->dpll_hw_state
.fp0
= fp
;
8163 crtc_state
->dpll_hw_state
.fp1
= fp2
;
8166 static int ironlake_crtc_compute_clock(struct intel_crtc
*crtc
,
8167 struct intel_crtc_state
*crtc_state
)
8169 struct drm_device
*dev
= crtc
->base
.dev
;
8170 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8171 const struct intel_limit
*limit
;
8172 int refclk
= 120000;
8174 memset(&crtc_state
->dpll_hw_state
, 0,
8175 sizeof(crtc_state
->dpll_hw_state
));
8177 crtc
->lowfreq_avail
= false;
8179 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8180 if (!crtc_state
->has_pch_encoder
)
8183 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8184 if (intel_panel_use_ssc(dev_priv
)) {
8185 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8186 dev_priv
->vbt
.lvds_ssc_freq
);
8187 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8190 if (intel_is_dual_link_lvds(dev
)) {
8191 if (refclk
== 100000)
8192 limit
= &intel_limits_ironlake_dual_lvds_100m
;
8194 limit
= &intel_limits_ironlake_dual_lvds
;
8196 if (refclk
== 100000)
8197 limit
= &intel_limits_ironlake_single_lvds_100m
;
8199 limit
= &intel_limits_ironlake_single_lvds
;
8202 limit
= &intel_limits_ironlake_dac
;
8205 if (!crtc_state
->clock_set
&&
8206 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8207 refclk
, NULL
, &crtc_state
->dpll
)) {
8208 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8212 ironlake_compute_dpll(crtc
, crtc_state
, NULL
);
8214 if (!intel_get_shared_dpll(crtc
, crtc_state
, NULL
)) {
8215 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8216 pipe_name(crtc
->pipe
));
8223 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
8224 struct intel_link_m_n
*m_n
)
8226 struct drm_device
*dev
= crtc
->base
.dev
;
8227 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8228 enum pipe pipe
= crtc
->pipe
;
8230 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
8231 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
8232 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
8234 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
8235 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
8236 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8239 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
8240 enum transcoder transcoder
,
8241 struct intel_link_m_n
*m_n
,
8242 struct intel_link_m_n
*m2_n2
)
8244 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
8245 enum pipe pipe
= crtc
->pipe
;
8247 if (INTEL_GEN(dev_priv
) >= 5) {
8248 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
8249 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
8250 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
8252 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
8253 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
8254 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8255 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8256 * gen < 8) and if DRRS is supported (to make sure the
8257 * registers are not unnecessarily read).
8259 if (m2_n2
&& INTEL_GEN(dev_priv
) < 8 &&
8260 crtc
->config
->has_drrs
) {
8261 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
8262 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
8263 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
8265 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
8266 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
8267 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8270 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
8271 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
8272 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
8274 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
8275 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
8276 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8280 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
8281 struct intel_crtc_state
*pipe_config
)
8283 if (pipe_config
->has_pch_encoder
)
8284 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
8286 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8287 &pipe_config
->dp_m_n
,
8288 &pipe_config
->dp_m2_n2
);
8291 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
8292 struct intel_crtc_state
*pipe_config
)
8294 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8295 &pipe_config
->fdi_m_n
, NULL
);
8298 static void skylake_get_pfit_config(struct intel_crtc
*crtc
,
8299 struct intel_crtc_state
*pipe_config
)
8301 struct drm_device
*dev
= crtc
->base
.dev
;
8302 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8303 struct intel_crtc_scaler_state
*scaler_state
= &pipe_config
->scaler_state
;
8304 uint32_t ps_ctrl
= 0;
8308 /* find scaler attached to this pipe */
8309 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
8310 ps_ctrl
= I915_READ(SKL_PS_CTRL(crtc
->pipe
, i
));
8311 if (ps_ctrl
& PS_SCALER_EN
&& !(ps_ctrl
& PS_PLANE_SEL_MASK
)) {
8313 pipe_config
->pch_pfit
.enabled
= true;
8314 pipe_config
->pch_pfit
.pos
= I915_READ(SKL_PS_WIN_POS(crtc
->pipe
, i
));
8315 pipe_config
->pch_pfit
.size
= I915_READ(SKL_PS_WIN_SZ(crtc
->pipe
, i
));
8320 scaler_state
->scaler_id
= id
;
8322 scaler_state
->scaler_users
|= (1 << SKL_CRTC_INDEX
);
8324 scaler_state
->scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
8329 skylake_get_initial_plane_config(struct intel_crtc
*crtc
,
8330 struct intel_initial_plane_config
*plane_config
)
8332 struct drm_device
*dev
= crtc
->base
.dev
;
8333 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8334 u32 val
, base
, offset
, stride_mult
, tiling
;
8335 int pipe
= crtc
->pipe
;
8336 int fourcc
, pixel_format
;
8337 unsigned int aligned_height
;
8338 struct drm_framebuffer
*fb
;
8339 struct intel_framebuffer
*intel_fb
;
8341 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8343 DRM_DEBUG_KMS("failed to alloc fb\n");
8347 fb
= &intel_fb
->base
;
8351 val
= I915_READ(PLANE_CTL(pipe
, 0));
8352 if (!(val
& PLANE_CTL_ENABLE
))
8355 pixel_format
= val
& PLANE_CTL_FORMAT_MASK
;
8356 fourcc
= skl_format_to_fourcc(pixel_format
,
8357 val
& PLANE_CTL_ORDER_RGBX
,
8358 val
& PLANE_CTL_ALPHA_MASK
);
8359 fb
->format
= drm_format_info(fourcc
);
8361 tiling
= val
& PLANE_CTL_TILED_MASK
;
8363 case PLANE_CTL_TILED_LINEAR
:
8364 fb
->modifier
= DRM_FORMAT_MOD_LINEAR
;
8366 case PLANE_CTL_TILED_X
:
8367 plane_config
->tiling
= I915_TILING_X
;
8368 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
8370 case PLANE_CTL_TILED_Y
:
8371 fb
->modifier
= I915_FORMAT_MOD_Y_TILED
;
8373 case PLANE_CTL_TILED_YF
:
8374 fb
->modifier
= I915_FORMAT_MOD_Yf_TILED
;
8377 MISSING_CASE(tiling
);
8381 base
= I915_READ(PLANE_SURF(pipe
, 0)) & 0xfffff000;
8382 plane_config
->base
= base
;
8384 offset
= I915_READ(PLANE_OFFSET(pipe
, 0));
8386 val
= I915_READ(PLANE_SIZE(pipe
, 0));
8387 fb
->height
= ((val
>> 16) & 0xfff) + 1;
8388 fb
->width
= ((val
>> 0) & 0x1fff) + 1;
8390 val
= I915_READ(PLANE_STRIDE(pipe
, 0));
8391 stride_mult
= intel_fb_stride_alignment(fb
, 0);
8392 fb
->pitches
[0] = (val
& 0x3ff) * stride_mult
;
8394 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
8396 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8398 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8399 pipe_name(pipe
), fb
->width
, fb
->height
,
8400 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
8401 plane_config
->size
);
8403 plane_config
->fb
= intel_fb
;
8410 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
8411 struct intel_crtc_state
*pipe_config
)
8413 struct drm_device
*dev
= crtc
->base
.dev
;
8414 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8417 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
8419 if (tmp
& PF_ENABLE
) {
8420 pipe_config
->pch_pfit
.enabled
= true;
8421 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
8422 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
8424 /* We currently do not free assignements of panel fitters on
8425 * ivb/hsw (since we don't use the higher upscaling modes which
8426 * differentiates them) so just WARN about this case for now. */
8427 if (IS_GEN7(dev_priv
)) {
8428 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
8429 PF_PIPE_SEL_IVB(crtc
->pipe
));
8435 ironlake_get_initial_plane_config(struct intel_crtc
*crtc
,
8436 struct intel_initial_plane_config
*plane_config
)
8438 struct drm_device
*dev
= crtc
->base
.dev
;
8439 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8440 u32 val
, base
, offset
;
8441 int pipe
= crtc
->pipe
;
8442 int fourcc
, pixel_format
;
8443 unsigned int aligned_height
;
8444 struct drm_framebuffer
*fb
;
8445 struct intel_framebuffer
*intel_fb
;
8447 val
= I915_READ(DSPCNTR(pipe
));
8448 if (!(val
& DISPLAY_PLANE_ENABLE
))
8451 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8453 DRM_DEBUG_KMS("failed to alloc fb\n");
8457 fb
= &intel_fb
->base
;
8461 if (INTEL_GEN(dev_priv
) >= 4) {
8462 if (val
& DISPPLANE_TILED
) {
8463 plane_config
->tiling
= I915_TILING_X
;
8464 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
8468 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
8469 fourcc
= i9xx_format_to_fourcc(pixel_format
);
8470 fb
->format
= drm_format_info(fourcc
);
8472 base
= I915_READ(DSPSURF(pipe
)) & 0xfffff000;
8473 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
8474 offset
= I915_READ(DSPOFFSET(pipe
));
8476 if (plane_config
->tiling
)
8477 offset
= I915_READ(DSPTILEOFF(pipe
));
8479 offset
= I915_READ(DSPLINOFF(pipe
));
8481 plane_config
->base
= base
;
8483 val
= I915_READ(PIPESRC(pipe
));
8484 fb
->width
= ((val
>> 16) & 0xfff) + 1;
8485 fb
->height
= ((val
>> 0) & 0xfff) + 1;
8487 val
= I915_READ(DSPSTRIDE(pipe
));
8488 fb
->pitches
[0] = val
& 0xffffffc0;
8490 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
8492 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8494 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8495 pipe_name(pipe
), fb
->width
, fb
->height
,
8496 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
8497 plane_config
->size
);
8499 plane_config
->fb
= intel_fb
;
8502 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
8503 struct intel_crtc_state
*pipe_config
)
8505 struct drm_device
*dev
= crtc
->base
.dev
;
8506 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8507 enum intel_display_power_domain power_domain
;
8511 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
8512 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8515 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8516 pipe_config
->shared_dpll
= NULL
;
8519 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
8520 if (!(tmp
& PIPECONF_ENABLE
))
8523 switch (tmp
& PIPECONF_BPC_MASK
) {
8525 pipe_config
->pipe_bpp
= 18;
8528 pipe_config
->pipe_bpp
= 24;
8530 case PIPECONF_10BPC
:
8531 pipe_config
->pipe_bpp
= 30;
8533 case PIPECONF_12BPC
:
8534 pipe_config
->pipe_bpp
= 36;
8540 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
8541 pipe_config
->limited_color_range
= true;
8543 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
8544 struct intel_shared_dpll
*pll
;
8545 enum intel_dpll_id pll_id
;
8547 pipe_config
->has_pch_encoder
= true;
8549 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
8550 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
8551 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
8553 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
8555 if (HAS_PCH_IBX(dev_priv
)) {
8557 * The pipe->pch transcoder and pch transcoder->pll
8560 pll_id
= (enum intel_dpll_id
) crtc
->pipe
;
8562 tmp
= I915_READ(PCH_DPLL_SEL
);
8563 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
8564 pll_id
= DPLL_ID_PCH_PLL_B
;
8566 pll_id
= DPLL_ID_PCH_PLL_A
;
8569 pipe_config
->shared_dpll
=
8570 intel_get_shared_dpll_by_id(dev_priv
, pll_id
);
8571 pll
= pipe_config
->shared_dpll
;
8573 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
8574 &pipe_config
->dpll_hw_state
));
8576 tmp
= pipe_config
->dpll_hw_state
.dpll
;
8577 pipe_config
->pixel_multiplier
=
8578 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
8579 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
8581 ironlake_pch_clock_get(crtc
, pipe_config
);
8583 pipe_config
->pixel_multiplier
= 1;
8586 intel_get_pipe_timings(crtc
, pipe_config
);
8587 intel_get_pipe_src_size(crtc
, pipe_config
);
8589 ironlake_get_pfit_config(crtc
, pipe_config
);
8594 intel_display_power_put(dev_priv
, power_domain
);
8599 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
8601 struct drm_device
*dev
= &dev_priv
->drm
;
8602 struct intel_crtc
*crtc
;
8604 for_each_intel_crtc(dev
, crtc
)
8605 I915_STATE_WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
8606 pipe_name(crtc
->pipe
));
8608 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
8609 I915_STATE_WARN(I915_READ(SPLL_CTL
) & SPLL_PLL_ENABLE
, "SPLL enabled\n");
8610 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE
, "WRPLL1 enabled\n");
8611 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE
, "WRPLL2 enabled\n");
8612 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON
, "Panel power on\n");
8613 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
8614 "CPU PWM1 enabled\n");
8615 if (IS_HASWELL(dev_priv
))
8616 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
8617 "CPU PWM2 enabled\n");
8618 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
8619 "PCH PWM1 enabled\n");
8620 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
8621 "Utility pin enabled\n");
8622 I915_STATE_WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
8625 * In theory we can still leave IRQs enabled, as long as only the HPD
8626 * interrupts remain enabled. We used to check for that, but since it's
8627 * gen-specific and since we only disable LCPLL after we fully disable
8628 * the interrupts, the check below should be enough.
8630 I915_STATE_WARN(intel_irqs_enabled(dev_priv
), "IRQs enabled\n");
8633 static uint32_t hsw_read_dcomp(struct drm_i915_private
*dev_priv
)
8635 if (IS_HASWELL(dev_priv
))
8636 return I915_READ(D_COMP_HSW
);
8638 return I915_READ(D_COMP_BDW
);
8641 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
8643 if (IS_HASWELL(dev_priv
)) {
8644 mutex_lock(&dev_priv
->rps
.hw_lock
);
8645 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
8647 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
8648 mutex_unlock(&dev_priv
->rps
.hw_lock
);
8650 I915_WRITE(D_COMP_BDW
, val
);
8651 POSTING_READ(D_COMP_BDW
);
8656 * This function implements pieces of two sequences from BSpec:
8657 * - Sequence for display software to disable LCPLL
8658 * - Sequence for display software to allow package C8+
8659 * The steps implemented here are just the steps that actually touch the LCPLL
8660 * register. Callers should take care of disabling all the display engine
8661 * functions, doing the mode unset, fixing interrupts, etc.
8663 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
8664 bool switch_to_fclk
, bool allow_power_down
)
8668 assert_can_disable_lcpll(dev_priv
);
8670 val
= I915_READ(LCPLL_CTL
);
8672 if (switch_to_fclk
) {
8673 val
|= LCPLL_CD_SOURCE_FCLK
;
8674 I915_WRITE(LCPLL_CTL
, val
);
8676 if (wait_for_us(I915_READ(LCPLL_CTL
) &
8677 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
8678 DRM_ERROR("Switching to FCLK failed\n");
8680 val
= I915_READ(LCPLL_CTL
);
8683 val
|= LCPLL_PLL_DISABLE
;
8684 I915_WRITE(LCPLL_CTL
, val
);
8685 POSTING_READ(LCPLL_CTL
);
8687 if (intel_wait_for_register(dev_priv
, LCPLL_CTL
, LCPLL_PLL_LOCK
, 0, 1))
8688 DRM_ERROR("LCPLL still locked\n");
8690 val
= hsw_read_dcomp(dev_priv
);
8691 val
|= D_COMP_COMP_DISABLE
;
8692 hsw_write_dcomp(dev_priv
, val
);
8695 if (wait_for((hsw_read_dcomp(dev_priv
) & D_COMP_RCOMP_IN_PROGRESS
) == 0,
8697 DRM_ERROR("D_COMP RCOMP still in progress\n");
8699 if (allow_power_down
) {
8700 val
= I915_READ(LCPLL_CTL
);
8701 val
|= LCPLL_POWER_DOWN_ALLOW
;
8702 I915_WRITE(LCPLL_CTL
, val
);
8703 POSTING_READ(LCPLL_CTL
);
8708 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
8711 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
8715 val
= I915_READ(LCPLL_CTL
);
8717 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
8718 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
8722 * Make sure we're not on PC8 state before disabling PC8, otherwise
8723 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
8725 intel_uncore_forcewake_get(dev_priv
, FORCEWAKE_ALL
);
8727 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
8728 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
8729 I915_WRITE(LCPLL_CTL
, val
);
8730 POSTING_READ(LCPLL_CTL
);
8733 val
= hsw_read_dcomp(dev_priv
);
8734 val
|= D_COMP_COMP_FORCE
;
8735 val
&= ~D_COMP_COMP_DISABLE
;
8736 hsw_write_dcomp(dev_priv
, val
);
8738 val
= I915_READ(LCPLL_CTL
);
8739 val
&= ~LCPLL_PLL_DISABLE
;
8740 I915_WRITE(LCPLL_CTL
, val
);
8742 if (intel_wait_for_register(dev_priv
,
8743 LCPLL_CTL
, LCPLL_PLL_LOCK
, LCPLL_PLL_LOCK
,
8745 DRM_ERROR("LCPLL not locked yet\n");
8747 if (val
& LCPLL_CD_SOURCE_FCLK
) {
8748 val
= I915_READ(LCPLL_CTL
);
8749 val
&= ~LCPLL_CD_SOURCE_FCLK
;
8750 I915_WRITE(LCPLL_CTL
, val
);
8752 if (wait_for_us((I915_READ(LCPLL_CTL
) &
8753 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
8754 DRM_ERROR("Switching back to LCPLL failed\n");
8757 intel_uncore_forcewake_put(dev_priv
, FORCEWAKE_ALL
);
8758 intel_update_cdclk(dev_priv
);
8762 * Package states C8 and deeper are really deep PC states that can only be
8763 * reached when all the devices on the system allow it, so even if the graphics
8764 * device allows PC8+, it doesn't mean the system will actually get to these
8765 * states. Our driver only allows PC8+ when going into runtime PM.
8767 * The requirements for PC8+ are that all the outputs are disabled, the power
8768 * well is disabled and most interrupts are disabled, and these are also
8769 * requirements for runtime PM. When these conditions are met, we manually do
8770 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
8771 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
8774 * When we really reach PC8 or deeper states (not just when we allow it) we lose
8775 * the state of some registers, so when we come back from PC8+ we need to
8776 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
8777 * need to take care of the registers kept by RC6. Notice that this happens even
8778 * if we don't put the device in PCI D3 state (which is what currently happens
8779 * because of the runtime PM support).
8781 * For more, read "Display Sequences for Package C8" on the hardware
8784 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
8788 DRM_DEBUG_KMS("Enabling package C8+\n");
8790 if (HAS_PCH_LPT_LP(dev_priv
)) {
8791 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
8792 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
8793 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
8796 lpt_disable_clkout_dp(dev_priv
);
8797 hsw_disable_lcpll(dev_priv
, true, true);
8800 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
8804 DRM_DEBUG_KMS("Disabling package C8+\n");
8806 hsw_restore_lcpll(dev_priv
);
8807 lpt_init_pch_refclk(dev_priv
);
8809 if (HAS_PCH_LPT_LP(dev_priv
)) {
8810 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
8811 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
8812 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
8816 static int haswell_crtc_compute_clock(struct intel_crtc
*crtc
,
8817 struct intel_crtc_state
*crtc_state
)
8819 if (!intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DSI
)) {
8820 struct intel_encoder
*encoder
=
8821 intel_ddi_get_crtc_new_encoder(crtc_state
);
8823 if (!intel_get_shared_dpll(crtc
, crtc_state
, encoder
)) {
8824 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8825 pipe_name(crtc
->pipe
));
8830 crtc
->lowfreq_avail
= false;
8835 static void cannonlake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8837 struct intel_crtc_state
*pipe_config
)
8839 enum intel_dpll_id id
;
8842 temp
= I915_READ(DPCLKA_CFGCR0
) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port
);
8843 id
= temp
>> (port
* 2);
8845 if (WARN_ON(id
< SKL_DPLL0
|| id
> SKL_DPLL2
))
8848 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8851 static void bxt_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8853 struct intel_crtc_state
*pipe_config
)
8855 enum intel_dpll_id id
;
8859 id
= DPLL_ID_SKL_DPLL0
;
8862 id
= DPLL_ID_SKL_DPLL1
;
8865 id
= DPLL_ID_SKL_DPLL2
;
8868 DRM_ERROR("Incorrect port type\n");
8872 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8875 static void skylake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8877 struct intel_crtc_state
*pipe_config
)
8879 enum intel_dpll_id id
;
8882 temp
= I915_READ(DPLL_CTRL2
) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port
);
8883 id
= temp
>> (port
* 3 + 1);
8885 if (WARN_ON(id
< SKL_DPLL0
|| id
> SKL_DPLL3
))
8888 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8891 static void haswell_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8893 struct intel_crtc_state
*pipe_config
)
8895 enum intel_dpll_id id
;
8896 uint32_t ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
8898 switch (ddi_pll_sel
) {
8899 case PORT_CLK_SEL_WRPLL1
:
8900 id
= DPLL_ID_WRPLL1
;
8902 case PORT_CLK_SEL_WRPLL2
:
8903 id
= DPLL_ID_WRPLL2
;
8905 case PORT_CLK_SEL_SPLL
:
8908 case PORT_CLK_SEL_LCPLL_810
:
8909 id
= DPLL_ID_LCPLL_810
;
8911 case PORT_CLK_SEL_LCPLL_1350
:
8912 id
= DPLL_ID_LCPLL_1350
;
8914 case PORT_CLK_SEL_LCPLL_2700
:
8915 id
= DPLL_ID_LCPLL_2700
;
8918 MISSING_CASE(ddi_pll_sel
);
8920 case PORT_CLK_SEL_NONE
:
8924 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8927 static bool hsw_get_transcoder_state(struct intel_crtc
*crtc
,
8928 struct intel_crtc_state
*pipe_config
,
8929 u64
*power_domain_mask
)
8931 struct drm_device
*dev
= crtc
->base
.dev
;
8932 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8933 enum intel_display_power_domain power_domain
;
8937 * The pipe->transcoder mapping is fixed with the exception of the eDP
8938 * transcoder handled below.
8940 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8943 * XXX: Do intel_display_power_get_if_enabled before reading this (for
8944 * consistency and less surprising code; it's in always on power).
8946 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
8947 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
8948 enum pipe trans_edp_pipe
;
8949 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
8951 WARN(1, "unknown pipe linked to edp transcoder\n");
8952 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
8953 case TRANS_DDI_EDP_INPUT_A_ON
:
8954 trans_edp_pipe
= PIPE_A
;
8956 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
8957 trans_edp_pipe
= PIPE_B
;
8959 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
8960 trans_edp_pipe
= PIPE_C
;
8964 if (trans_edp_pipe
== crtc
->pipe
)
8965 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
8968 power_domain
= POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
);
8969 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8971 *power_domain_mask
|= BIT_ULL(power_domain
);
8973 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
8975 return tmp
& PIPECONF_ENABLE
;
8978 static bool bxt_get_dsi_transcoder_state(struct intel_crtc
*crtc
,
8979 struct intel_crtc_state
*pipe_config
,
8980 u64
*power_domain_mask
)
8982 struct drm_device
*dev
= crtc
->base
.dev
;
8983 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8984 enum intel_display_power_domain power_domain
;
8986 enum transcoder cpu_transcoder
;
8989 for_each_port_masked(port
, BIT(PORT_A
) | BIT(PORT_C
)) {
8991 cpu_transcoder
= TRANSCODER_DSI_A
;
8993 cpu_transcoder
= TRANSCODER_DSI_C
;
8995 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
8996 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8998 *power_domain_mask
|= BIT_ULL(power_domain
);
9001 * The PLL needs to be enabled with a valid divider
9002 * configuration, otherwise accessing DSI registers will hang
9003 * the machine. See BSpec North Display Engine
9004 * registers/MIPI[BXT]. We can break out here early, since we
9005 * need the same DSI PLL to be enabled for both DSI ports.
9007 if (!intel_dsi_pll_is_enabled(dev_priv
))
9010 /* XXX: this works for video mode only */
9011 tmp
= I915_READ(BXT_MIPI_PORT_CTRL(port
));
9012 if (!(tmp
& DPI_ENABLE
))
9015 tmp
= I915_READ(MIPI_CTRL(port
));
9016 if ((tmp
& BXT_PIPE_SELECT_MASK
) != BXT_PIPE_SELECT(crtc
->pipe
))
9019 pipe_config
->cpu_transcoder
= cpu_transcoder
;
9023 return transcoder_is_dsi(pipe_config
->cpu_transcoder
);
9026 static void haswell_get_ddi_port_state(struct intel_crtc
*crtc
,
9027 struct intel_crtc_state
*pipe_config
)
9029 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9030 struct intel_shared_dpll
*pll
;
9034 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
9036 port
= (tmp
& TRANS_DDI_PORT_MASK
) >> TRANS_DDI_PORT_SHIFT
;
9038 if (IS_CANNONLAKE(dev_priv
))
9039 cannonlake_get_ddi_pll(dev_priv
, port
, pipe_config
);
9040 else if (IS_GEN9_BC(dev_priv
))
9041 skylake_get_ddi_pll(dev_priv
, port
, pipe_config
);
9042 else if (IS_GEN9_LP(dev_priv
))
9043 bxt_get_ddi_pll(dev_priv
, port
, pipe_config
);
9045 haswell_get_ddi_pll(dev_priv
, port
, pipe_config
);
9047 pll
= pipe_config
->shared_dpll
;
9049 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
9050 &pipe_config
->dpll_hw_state
));
9054 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9055 * DDI E. So just check whether this pipe is wired to DDI E and whether
9056 * the PCH transcoder is on.
9058 if (INTEL_GEN(dev_priv
) < 9 &&
9059 (port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
9060 pipe_config
->has_pch_encoder
= true;
9062 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
9063 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
9064 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
9066 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
9070 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
9071 struct intel_crtc_state
*pipe_config
)
9073 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9074 enum intel_display_power_domain power_domain
;
9075 u64 power_domain_mask
;
9078 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
9079 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9081 power_domain_mask
= BIT_ULL(power_domain
);
9083 pipe_config
->shared_dpll
= NULL
;
9085 active
= hsw_get_transcoder_state(crtc
, pipe_config
, &power_domain_mask
);
9087 if (IS_GEN9_LP(dev_priv
) &&
9088 bxt_get_dsi_transcoder_state(crtc
, pipe_config
, &power_domain_mask
)) {
9096 if (!transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
9097 haswell_get_ddi_port_state(crtc
, pipe_config
);
9098 intel_get_pipe_timings(crtc
, pipe_config
);
9101 intel_get_pipe_src_size(crtc
, pipe_config
);
9103 pipe_config
->gamma_mode
=
9104 I915_READ(GAMMA_MODE(crtc
->pipe
)) & GAMMA_MODE_MODE_MASK
;
9106 if (INTEL_GEN(dev_priv
) >= 9) {
9107 intel_crtc_init_scalers(crtc
, pipe_config
);
9109 pipe_config
->scaler_state
.scaler_id
= -1;
9110 pipe_config
->scaler_state
.scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
9113 power_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
9114 if (intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
9115 power_domain_mask
|= BIT_ULL(power_domain
);
9116 if (INTEL_GEN(dev_priv
) >= 9)
9117 skylake_get_pfit_config(crtc
, pipe_config
);
9119 ironlake_get_pfit_config(crtc
, pipe_config
);
9122 if (IS_HASWELL(dev_priv
))
9123 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
9124 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
9126 if (pipe_config
->cpu_transcoder
!= TRANSCODER_EDP
&&
9127 !transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
9128 pipe_config
->pixel_multiplier
=
9129 I915_READ(PIPE_MULT(pipe_config
->cpu_transcoder
)) + 1;
9131 pipe_config
->pixel_multiplier
= 1;
9135 for_each_power_domain(power_domain
, power_domain_mask
)
9136 intel_display_power_put(dev_priv
, power_domain
);
9141 static u32
intel_cursor_base(const struct intel_plane_state
*plane_state
)
9143 struct drm_i915_private
*dev_priv
=
9144 to_i915(plane_state
->base
.plane
->dev
);
9145 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9146 const struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
9149 if (INTEL_INFO(dev_priv
)->cursor_needs_physical
)
9150 base
= obj
->phys_handle
->busaddr
;
9152 base
= intel_plane_ggtt_offset(plane_state
);
9154 base
+= plane_state
->main
.offset
;
9156 /* ILK+ do this automagically */
9157 if (HAS_GMCH_DISPLAY(dev_priv
) &&
9158 plane_state
->base
.rotation
& DRM_MODE_ROTATE_180
)
9159 base
+= (plane_state
->base
.crtc_h
*
9160 plane_state
->base
.crtc_w
- 1) * fb
->format
->cpp
[0];
9165 static u32
intel_cursor_position(const struct intel_plane_state
*plane_state
)
9167 int x
= plane_state
->base
.crtc_x
;
9168 int y
= plane_state
->base
.crtc_y
;
9172 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
9175 pos
|= x
<< CURSOR_X_SHIFT
;
9178 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
9181 pos
|= y
<< CURSOR_Y_SHIFT
;
9186 static bool intel_cursor_size_ok(const struct intel_plane_state
*plane_state
)
9188 const struct drm_mode_config
*config
=
9189 &plane_state
->base
.plane
->dev
->mode_config
;
9190 int width
= plane_state
->base
.crtc_w
;
9191 int height
= plane_state
->base
.crtc_h
;
9193 return width
> 0 && width
<= config
->cursor_width
&&
9194 height
> 0 && height
<= config
->cursor_height
;
9197 static int intel_check_cursor(struct intel_crtc_state
*crtc_state
,
9198 struct intel_plane_state
*plane_state
)
9200 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9205 ret
= drm_plane_helper_check_state(&plane_state
->base
,
9207 DRM_PLANE_HELPER_NO_SCALING
,
9208 DRM_PLANE_HELPER_NO_SCALING
,
9216 if (fb
->modifier
!= DRM_FORMAT_MOD_LINEAR
) {
9217 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9221 src_x
= plane_state
->base
.src_x
>> 16;
9222 src_y
= plane_state
->base
.src_y
>> 16;
9224 intel_add_fb_offsets(&src_x
, &src_y
, plane_state
, 0);
9225 offset
= intel_compute_tile_offset(&src_x
, &src_y
, plane_state
, 0);
9227 if (src_x
!= 0 || src_y
!= 0) {
9228 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9232 plane_state
->main
.offset
= offset
;
9237 static u32
i845_cursor_ctl(const struct intel_crtc_state
*crtc_state
,
9238 const struct intel_plane_state
*plane_state
)
9240 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9242 return CURSOR_ENABLE
|
9243 CURSOR_GAMMA_ENABLE
|
9244 CURSOR_FORMAT_ARGB
|
9245 CURSOR_STRIDE(fb
->pitches
[0]);
9248 static bool i845_cursor_size_ok(const struct intel_plane_state
*plane_state
)
9250 int width
= plane_state
->base
.crtc_w
;
9253 * 845g/865g are only limited by the width of their cursors,
9254 * the height is arbitrary up to the precision of the register.
9256 return intel_cursor_size_ok(plane_state
) && IS_ALIGNED(width
, 64);
9259 static int i845_check_cursor(struct intel_plane
*plane
,
9260 struct intel_crtc_state
*crtc_state
,
9261 struct intel_plane_state
*plane_state
)
9263 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9266 ret
= intel_check_cursor(crtc_state
, plane_state
);
9270 /* if we want to turn off the cursor ignore width and height */
9274 /* Check for which cursor types we support */
9275 if (!i845_cursor_size_ok(plane_state
)) {
9276 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9277 plane_state
->base
.crtc_w
,
9278 plane_state
->base
.crtc_h
);
9282 switch (fb
->pitches
[0]) {
9289 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
9294 plane_state
->ctl
= i845_cursor_ctl(crtc_state
, plane_state
);
9299 static void i845_update_cursor(struct intel_plane
*plane
,
9300 const struct intel_crtc_state
*crtc_state
,
9301 const struct intel_plane_state
*plane_state
)
9303 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
9304 u32 cntl
= 0, base
= 0, pos
= 0, size
= 0;
9305 unsigned long irqflags
;
9307 if (plane_state
&& plane_state
->base
.visible
) {
9308 unsigned int width
= plane_state
->base
.crtc_w
;
9309 unsigned int height
= plane_state
->base
.crtc_h
;
9311 cntl
= plane_state
->ctl
;
9312 size
= (height
<< 12) | width
;
9314 base
= intel_cursor_base(plane_state
);
9315 pos
= intel_cursor_position(plane_state
);
9318 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
9320 /* On these chipsets we can only modify the base/size/stride
9321 * whilst the cursor is disabled.
9323 if (plane
->cursor
.base
!= base
||
9324 plane
->cursor
.size
!= size
||
9325 plane
->cursor
.cntl
!= cntl
) {
9326 I915_WRITE_FW(CURCNTR(PIPE_A
), 0);
9327 I915_WRITE_FW(CURBASE(PIPE_A
), base
);
9328 I915_WRITE_FW(CURSIZE
, size
);
9329 I915_WRITE_FW(CURPOS(PIPE_A
), pos
);
9330 I915_WRITE_FW(CURCNTR(PIPE_A
), cntl
);
9332 plane
->cursor
.base
= base
;
9333 plane
->cursor
.size
= size
;
9334 plane
->cursor
.cntl
= cntl
;
9336 I915_WRITE_FW(CURPOS(PIPE_A
), pos
);
9339 POSTING_READ_FW(CURCNTR(PIPE_A
));
9341 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
9344 static void i845_disable_cursor(struct intel_plane
*plane
,
9345 struct intel_crtc
*crtc
)
9347 i845_update_cursor(plane
, NULL
, NULL
);
9350 static u32
i9xx_cursor_ctl(const struct intel_crtc_state
*crtc_state
,
9351 const struct intel_plane_state
*plane_state
)
9353 struct drm_i915_private
*dev_priv
=
9354 to_i915(plane_state
->base
.plane
->dev
);
9355 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
9358 cntl
= MCURSOR_GAMMA_ENABLE
;
9360 if (HAS_DDI(dev_priv
))
9361 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
9363 cntl
|= MCURSOR_PIPE_SELECT(crtc
->pipe
);
9365 switch (plane_state
->base
.crtc_w
) {
9367 cntl
|= CURSOR_MODE_64_ARGB_AX
;
9370 cntl
|= CURSOR_MODE_128_ARGB_AX
;
9373 cntl
|= CURSOR_MODE_256_ARGB_AX
;
9376 MISSING_CASE(plane_state
->base
.crtc_w
);
9380 if (plane_state
->base
.rotation
& DRM_MODE_ROTATE_180
)
9381 cntl
|= CURSOR_ROTATE_180
;
9386 static bool i9xx_cursor_size_ok(const struct intel_plane_state
*plane_state
)
9388 struct drm_i915_private
*dev_priv
=
9389 to_i915(plane_state
->base
.plane
->dev
);
9390 int width
= plane_state
->base
.crtc_w
;
9391 int height
= plane_state
->base
.crtc_h
;
9393 if (!intel_cursor_size_ok(plane_state
))
9396 /* Cursor width is limited to a few power-of-two sizes */
9407 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
9408 * height from 8 lines up to the cursor width, when the
9409 * cursor is not rotated. Everything else requires square
9412 if (HAS_CUR_FBC(dev_priv
) &&
9413 plane_state
->base
.rotation
& DRM_MODE_ROTATE_0
) {
9414 if (height
< 8 || height
> width
)
9417 if (height
!= width
)
9424 static int i9xx_check_cursor(struct intel_plane
*plane
,
9425 struct intel_crtc_state
*crtc_state
,
9426 struct intel_plane_state
*plane_state
)
9428 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
9429 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9430 enum pipe pipe
= plane
->pipe
;
9433 ret
= intel_check_cursor(crtc_state
, plane_state
);
9437 /* if we want to turn off the cursor ignore width and height */
9441 /* Check for which cursor types we support */
9442 if (!i9xx_cursor_size_ok(plane_state
)) {
9443 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9444 plane_state
->base
.crtc_w
,
9445 plane_state
->base
.crtc_h
);
9449 if (fb
->pitches
[0] != plane_state
->base
.crtc_w
* fb
->format
->cpp
[0]) {
9450 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
9451 fb
->pitches
[0], plane_state
->base
.crtc_w
);
9456 * There's something wrong with the cursor on CHV pipe C.
9457 * If it straddles the left edge of the screen then
9458 * moving it away from the edge or disabling it often
9459 * results in a pipe underrun, and often that can lead to
9460 * dead pipe (constant underrun reported, and it scans
9461 * out just a solid color). To recover from that, the
9462 * display power well must be turned off and on again.
9463 * Refuse the put the cursor into that compromised position.
9465 if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_C
&&
9466 plane_state
->base
.visible
&& plane_state
->base
.crtc_x
< 0) {
9467 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
9471 plane_state
->ctl
= i9xx_cursor_ctl(crtc_state
, plane_state
);
9476 static void i9xx_update_cursor(struct intel_plane
*plane
,
9477 const struct intel_crtc_state
*crtc_state
,
9478 const struct intel_plane_state
*plane_state
)
9480 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
9481 enum pipe pipe
= plane
->pipe
;
9482 u32 cntl
= 0, base
= 0, pos
= 0, fbc_ctl
= 0;
9483 unsigned long irqflags
;
9485 if (plane_state
&& plane_state
->base
.visible
) {
9486 cntl
= plane_state
->ctl
;
9488 if (plane_state
->base
.crtc_h
!= plane_state
->base
.crtc_w
)
9489 fbc_ctl
= CUR_FBC_CTL_EN
| (plane_state
->base
.crtc_h
- 1);
9491 base
= intel_cursor_base(plane_state
);
9492 pos
= intel_cursor_position(plane_state
);
9495 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
9498 * On some platforms writing CURCNTR first will also
9499 * cause CURPOS to be armed by the CURBASE write.
9500 * Without the CURCNTR write the CURPOS write would
9501 * arm itself. Thus we always start the full update
9502 * with a CURCNTR write.
9504 * On other platforms CURPOS always requires the
9505 * CURBASE write to arm the update. Additonally
9506 * a write to any of the cursor register will cancel
9507 * an already armed cursor update. Thus leaving out
9508 * the CURBASE write after CURPOS could lead to a
9509 * cursor that doesn't appear to move, or even change
9510 * shape. Thus we always write CURBASE.
9512 * CURCNTR and CUR_FBC_CTL are always
9513 * armed by the CURBASE write only.
9515 if (plane
->cursor
.base
!= base
||
9516 plane
->cursor
.size
!= fbc_ctl
||
9517 plane
->cursor
.cntl
!= cntl
) {
9518 I915_WRITE_FW(CURCNTR(pipe
), cntl
);
9519 if (HAS_CUR_FBC(dev_priv
))
9520 I915_WRITE_FW(CUR_FBC_CTL(pipe
), fbc_ctl
);
9521 I915_WRITE_FW(CURPOS(pipe
), pos
);
9522 I915_WRITE_FW(CURBASE(pipe
), base
);
9524 plane
->cursor
.base
= base
;
9525 plane
->cursor
.size
= fbc_ctl
;
9526 plane
->cursor
.cntl
= cntl
;
9528 I915_WRITE_FW(CURPOS(pipe
), pos
);
9529 I915_WRITE_FW(CURBASE(pipe
), base
);
9532 POSTING_READ_FW(CURBASE(pipe
));
9534 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
9537 static void i9xx_disable_cursor(struct intel_plane
*plane
,
9538 struct intel_crtc
*crtc
)
9540 i9xx_update_cursor(plane
, NULL
, NULL
);
9544 /* VESA 640x480x72Hz mode to set on the pipe */
9545 static struct drm_display_mode load_detect_mode
= {
9546 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
9547 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
9550 struct drm_framebuffer
*
9551 intel_framebuffer_create(struct drm_i915_gem_object
*obj
,
9552 struct drm_mode_fb_cmd2
*mode_cmd
)
9554 struct intel_framebuffer
*intel_fb
;
9557 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9559 return ERR_PTR(-ENOMEM
);
9561 ret
= intel_framebuffer_init(intel_fb
, obj
, mode_cmd
);
9565 return &intel_fb
->base
;
9569 return ERR_PTR(ret
);
9573 intel_framebuffer_pitch_for_width(int width
, int bpp
)
9575 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
9576 return ALIGN(pitch
, 64);
9580 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
9582 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
9583 return PAGE_ALIGN(pitch
* mode
->vdisplay
);
9586 static struct drm_framebuffer
*
9587 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
9588 struct drm_display_mode
*mode
,
9591 struct drm_framebuffer
*fb
;
9592 struct drm_i915_gem_object
*obj
;
9593 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
9595 obj
= i915_gem_object_create(to_i915(dev
),
9596 intel_framebuffer_size_for_mode(mode
, bpp
));
9598 return ERR_CAST(obj
);
9600 mode_cmd
.width
= mode
->hdisplay
;
9601 mode_cmd
.height
= mode
->vdisplay
;
9602 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
9604 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
9606 fb
= intel_framebuffer_create(obj
, &mode_cmd
);
9608 i915_gem_object_put(obj
);
9613 static struct drm_framebuffer
*
9614 mode_fits_in_fbdev(struct drm_device
*dev
,
9615 struct drm_display_mode
*mode
)
9617 #ifdef CONFIG_DRM_FBDEV_EMULATION
9618 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9619 struct drm_i915_gem_object
*obj
;
9620 struct drm_framebuffer
*fb
;
9622 if (!dev_priv
->fbdev
)
9625 if (!dev_priv
->fbdev
->fb
)
9628 obj
= dev_priv
->fbdev
->fb
->obj
;
9631 fb
= &dev_priv
->fbdev
->fb
->base
;
9632 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
9633 fb
->format
->cpp
[0] * 8))
9636 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
9639 drm_framebuffer_reference(fb
);
9646 static int intel_modeset_setup_plane_state(struct drm_atomic_state
*state
,
9647 struct drm_crtc
*crtc
,
9648 struct drm_display_mode
*mode
,
9649 struct drm_framebuffer
*fb
,
9652 struct drm_plane_state
*plane_state
;
9653 int hdisplay
, vdisplay
;
9656 plane_state
= drm_atomic_get_plane_state(state
, crtc
->primary
);
9657 if (IS_ERR(plane_state
))
9658 return PTR_ERR(plane_state
);
9661 drm_mode_get_hv_timing(mode
, &hdisplay
, &vdisplay
);
9663 hdisplay
= vdisplay
= 0;
9665 ret
= drm_atomic_set_crtc_for_plane(plane_state
, fb
? crtc
: NULL
);
9668 drm_atomic_set_fb_for_plane(plane_state
, fb
);
9669 plane_state
->crtc_x
= 0;
9670 plane_state
->crtc_y
= 0;
9671 plane_state
->crtc_w
= hdisplay
;
9672 plane_state
->crtc_h
= vdisplay
;
9673 plane_state
->src_x
= x
<< 16;
9674 plane_state
->src_y
= y
<< 16;
9675 plane_state
->src_w
= hdisplay
<< 16;
9676 plane_state
->src_h
= vdisplay
<< 16;
9681 int intel_get_load_detect_pipe(struct drm_connector
*connector
,
9682 struct drm_display_mode
*mode
,
9683 struct intel_load_detect_pipe
*old
,
9684 struct drm_modeset_acquire_ctx
*ctx
)
9686 struct intel_crtc
*intel_crtc
;
9687 struct intel_encoder
*intel_encoder
=
9688 intel_attached_encoder(connector
);
9689 struct drm_crtc
*possible_crtc
;
9690 struct drm_encoder
*encoder
= &intel_encoder
->base
;
9691 struct drm_crtc
*crtc
= NULL
;
9692 struct drm_device
*dev
= encoder
->dev
;
9693 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9694 struct drm_framebuffer
*fb
;
9695 struct drm_mode_config
*config
= &dev
->mode_config
;
9696 struct drm_atomic_state
*state
= NULL
, *restore_state
= NULL
;
9697 struct drm_connector_state
*connector_state
;
9698 struct intel_crtc_state
*crtc_state
;
9701 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9702 connector
->base
.id
, connector
->name
,
9703 encoder
->base
.id
, encoder
->name
);
9705 old
->restore_state
= NULL
;
9707 WARN_ON(!drm_modeset_is_locked(&config
->connection_mutex
));
9710 * Algorithm gets a little messy:
9712 * - if the connector already has an assigned crtc, use it (but make
9713 * sure it's on first)
9715 * - try to find the first unused crtc that can drive this connector,
9716 * and use that if we find one
9719 /* See if we already have a CRTC for this connector */
9720 if (connector
->state
->crtc
) {
9721 crtc
= connector
->state
->crtc
;
9723 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
9727 /* Make sure the crtc and connector are running */
9731 /* Find an unused one (if possible) */
9732 for_each_crtc(dev
, possible_crtc
) {
9734 if (!(encoder
->possible_crtcs
& (1 << i
)))
9737 ret
= drm_modeset_lock(&possible_crtc
->mutex
, ctx
);
9741 if (possible_crtc
->state
->enable
) {
9742 drm_modeset_unlock(&possible_crtc
->mutex
);
9746 crtc
= possible_crtc
;
9751 * If we didn't find an unused CRTC, don't use any.
9754 DRM_DEBUG_KMS("no pipe available for load-detect\n");
9760 intel_crtc
= to_intel_crtc(crtc
);
9762 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
9766 state
= drm_atomic_state_alloc(dev
);
9767 restore_state
= drm_atomic_state_alloc(dev
);
9768 if (!state
|| !restore_state
) {
9773 state
->acquire_ctx
= ctx
;
9774 restore_state
->acquire_ctx
= ctx
;
9776 connector_state
= drm_atomic_get_connector_state(state
, connector
);
9777 if (IS_ERR(connector_state
)) {
9778 ret
= PTR_ERR(connector_state
);
9782 ret
= drm_atomic_set_crtc_for_connector(connector_state
, crtc
);
9786 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
9787 if (IS_ERR(crtc_state
)) {
9788 ret
= PTR_ERR(crtc_state
);
9792 crtc_state
->base
.active
= crtc_state
->base
.enable
= true;
9795 mode
= &load_detect_mode
;
9797 /* We need a framebuffer large enough to accommodate all accesses
9798 * that the plane may generate whilst we perform load detection.
9799 * We can not rely on the fbcon either being present (we get called
9800 * during its initialisation to detect all boot displays, or it may
9801 * not even exist) or that it is large enough to satisfy the
9804 fb
= mode_fits_in_fbdev(dev
, mode
);
9806 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
9807 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
9809 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
9811 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
9816 ret
= intel_modeset_setup_plane_state(state
, crtc
, mode
, fb
, 0, 0);
9820 drm_framebuffer_unreference(fb
);
9822 ret
= drm_atomic_set_mode_for_crtc(&crtc_state
->base
, mode
);
9826 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state
, connector
));
9828 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state
, crtc
));
9830 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state
, crtc
->primary
));
9832 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret
);
9836 ret
= drm_atomic_commit(state
);
9838 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
9842 old
->restore_state
= restore_state
;
9843 drm_atomic_state_put(state
);
9845 /* let the connector get through one full cycle before testing */
9846 intel_wait_for_vblank(dev_priv
, intel_crtc
->pipe
);
9851 drm_atomic_state_put(state
);
9854 if (restore_state
) {
9855 drm_atomic_state_put(restore_state
);
9856 restore_state
= NULL
;
9859 if (ret
== -EDEADLK
)
9865 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
9866 struct intel_load_detect_pipe
*old
,
9867 struct drm_modeset_acquire_ctx
*ctx
)
9869 struct intel_encoder
*intel_encoder
=
9870 intel_attached_encoder(connector
);
9871 struct drm_encoder
*encoder
= &intel_encoder
->base
;
9872 struct drm_atomic_state
*state
= old
->restore_state
;
9875 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9876 connector
->base
.id
, connector
->name
,
9877 encoder
->base
.id
, encoder
->name
);
9882 ret
= drm_atomic_helper_commit_duplicated_state(state
, ctx
);
9884 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret
);
9885 drm_atomic_state_put(state
);
9888 static int i9xx_pll_refclk(struct drm_device
*dev
,
9889 const struct intel_crtc_state
*pipe_config
)
9891 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9892 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
9894 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
9895 return dev_priv
->vbt
.lvds_ssc_freq
;
9896 else if (HAS_PCH_SPLIT(dev_priv
))
9898 else if (!IS_GEN2(dev_priv
))
9904 /* Returns the clock of the currently programmed mode of the given pipe. */
9905 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
9906 struct intel_crtc_state
*pipe_config
)
9908 struct drm_device
*dev
= crtc
->base
.dev
;
9909 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9910 int pipe
= pipe_config
->cpu_transcoder
;
9911 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
9915 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
9917 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
9918 fp
= pipe_config
->dpll_hw_state
.fp0
;
9920 fp
= pipe_config
->dpll_hw_state
.fp1
;
9922 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
9923 if (IS_PINEVIEW(dev_priv
)) {
9924 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
9925 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
9927 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
9928 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
9931 if (!IS_GEN2(dev_priv
)) {
9932 if (IS_PINEVIEW(dev_priv
))
9933 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
9934 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
9936 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
9937 DPLL_FPA01_P1_POST_DIV_SHIFT
);
9939 switch (dpll
& DPLL_MODE_MASK
) {
9940 case DPLLB_MODE_DAC_SERIAL
:
9941 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
9944 case DPLLB_MODE_LVDS
:
9945 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
9949 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
9950 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
9954 if (IS_PINEVIEW(dev_priv
))
9955 port_clock
= pnv_calc_dpll_params(refclk
, &clock
);
9957 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
9959 u32 lvds
= IS_I830(dev_priv
) ? 0 : I915_READ(LVDS
);
9960 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
9963 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
9964 DPLL_FPA01_P1_POST_DIV_SHIFT
);
9966 if (lvds
& LVDS_CLKB_POWER_UP
)
9971 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
9974 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
9975 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
9977 if (dpll
& PLL_P2_DIVIDE_BY_4
)
9983 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
9987 * This value includes pixel_multiplier. We will use
9988 * port_clock to compute adjusted_mode.crtc_clock in the
9989 * encoder's get_config() function.
9991 pipe_config
->port_clock
= port_clock
;
9994 int intel_dotclock_calculate(int link_freq
,
9995 const struct intel_link_m_n
*m_n
)
9998 * The calculation for the data clock is:
9999 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10000 * But we want to avoid losing precison if possible, so:
10001 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10003 * and the link clock is simpler:
10004 * link_clock = (m * link_clock) / n
10010 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
10013 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
10014 struct intel_crtc_state
*pipe_config
)
10016 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
10018 /* read out port_clock from the DPLL */
10019 i9xx_crtc_clock_get(crtc
, pipe_config
);
10022 * In case there is an active pipe without active ports,
10023 * we may need some idea for the dotclock anyway.
10024 * Calculate one based on the FDI configuration.
10026 pipe_config
->base
.adjusted_mode
.crtc_clock
=
10027 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
10028 &pipe_config
->fdi_m_n
);
10031 /** Returns the currently programmed mode of the given pipe. */
10032 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
10033 struct drm_crtc
*crtc
)
10035 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10036 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10037 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
10038 struct drm_display_mode
*mode
;
10039 struct intel_crtc_state
*pipe_config
;
10040 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
10041 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
10042 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
10043 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
10044 enum pipe pipe
= intel_crtc
->pipe
;
10046 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
10050 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
10051 if (!pipe_config
) {
10057 * Construct a pipe_config sufficient for getting the clock info
10058 * back out of crtc_clock_get.
10060 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
10061 * to use a real value here instead.
10063 pipe_config
->cpu_transcoder
= (enum transcoder
) pipe
;
10064 pipe_config
->pixel_multiplier
= 1;
10065 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
10066 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
10067 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
10068 i9xx_crtc_clock_get(intel_crtc
, pipe_config
);
10070 mode
->clock
= pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
10071 mode
->hdisplay
= (htot
& 0xffff) + 1;
10072 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
10073 mode
->hsync_start
= (hsync
& 0xffff) + 1;
10074 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
10075 mode
->vdisplay
= (vtot
& 0xffff) + 1;
10076 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
10077 mode
->vsync_start
= (vsync
& 0xffff) + 1;
10078 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
10080 drm_mode_set_name(mode
);
10082 kfree(pipe_config
);
10087 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
10089 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10090 struct drm_device
*dev
= crtc
->dev
;
10091 struct intel_flip_work
*work
;
10093 spin_lock_irq(&dev
->event_lock
);
10094 work
= intel_crtc
->flip_work
;
10095 intel_crtc
->flip_work
= NULL
;
10096 spin_unlock_irq(&dev
->event_lock
);
10099 cancel_work_sync(&work
->mmio_work
);
10100 cancel_work_sync(&work
->unpin_work
);
10104 drm_crtc_cleanup(crtc
);
10109 static inline void intel_mark_page_flip_active(struct intel_crtc
*crtc
,
10110 struct intel_flip_work
*work
)
10112 work
->flip_queued_vblank
= intel_crtc_get_vblank_counter(crtc
);
10114 /* Ensure that the work item is consistent when activating it ... */
10115 smp_mb__before_atomic();
10116 atomic_set(&work
->pending
, 1);
10120 * intel_wm_need_update - Check whether watermarks need updating
10121 * @plane: drm plane
10122 * @state: new plane state
10124 * Check current plane state versus the new one to determine whether
10125 * watermarks need to be recalculated.
10127 * Returns true or false.
10129 static bool intel_wm_need_update(struct drm_plane
*plane
,
10130 struct drm_plane_state
*state
)
10132 struct intel_plane_state
*new = to_intel_plane_state(state
);
10133 struct intel_plane_state
*cur
= to_intel_plane_state(plane
->state
);
10135 /* Update watermarks on tiling or size changes. */
10136 if (new->base
.visible
!= cur
->base
.visible
)
10139 if (!cur
->base
.fb
|| !new->base
.fb
)
10142 if (cur
->base
.fb
->modifier
!= new->base
.fb
->modifier
||
10143 cur
->base
.rotation
!= new->base
.rotation
||
10144 drm_rect_width(&new->base
.src
) != drm_rect_width(&cur
->base
.src
) ||
10145 drm_rect_height(&new->base
.src
) != drm_rect_height(&cur
->base
.src
) ||
10146 drm_rect_width(&new->base
.dst
) != drm_rect_width(&cur
->base
.dst
) ||
10147 drm_rect_height(&new->base
.dst
) != drm_rect_height(&cur
->base
.dst
))
10153 static bool needs_scaling(struct intel_plane_state
*state
)
10155 int src_w
= drm_rect_width(&state
->base
.src
) >> 16;
10156 int src_h
= drm_rect_height(&state
->base
.src
) >> 16;
10157 int dst_w
= drm_rect_width(&state
->base
.dst
);
10158 int dst_h
= drm_rect_height(&state
->base
.dst
);
10160 return (src_w
!= dst_w
|| src_h
!= dst_h
);
10163 int intel_plane_atomic_calc_changes(struct drm_crtc_state
*crtc_state
,
10164 struct drm_plane_state
*plane_state
)
10166 struct intel_crtc_state
*pipe_config
= to_intel_crtc_state(crtc_state
);
10167 struct drm_crtc
*crtc
= crtc_state
->crtc
;
10168 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10169 struct intel_plane
*plane
= to_intel_plane(plane_state
->plane
);
10170 struct drm_device
*dev
= crtc
->dev
;
10171 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10172 struct intel_plane_state
*old_plane_state
=
10173 to_intel_plane_state(plane
->base
.state
);
10174 bool mode_changed
= needs_modeset(crtc_state
);
10175 bool was_crtc_enabled
= crtc
->state
->active
;
10176 bool is_crtc_enabled
= crtc_state
->active
;
10177 bool turn_off
, turn_on
, visible
, was_visible
;
10178 struct drm_framebuffer
*fb
= plane_state
->fb
;
10181 if (INTEL_GEN(dev_priv
) >= 9 && plane
->id
!= PLANE_CURSOR
) {
10182 ret
= skl_update_scaler_plane(
10183 to_intel_crtc_state(crtc_state
),
10184 to_intel_plane_state(plane_state
));
10189 was_visible
= old_plane_state
->base
.visible
;
10190 visible
= plane_state
->visible
;
10192 if (!was_crtc_enabled
&& WARN_ON(was_visible
))
10193 was_visible
= false;
10196 * Visibility is calculated as if the crtc was on, but
10197 * after scaler setup everything depends on it being off
10198 * when the crtc isn't active.
10200 * FIXME this is wrong for watermarks. Watermarks should also
10201 * be computed as if the pipe would be active. Perhaps move
10202 * per-plane wm computation to the .check_plane() hook, and
10203 * only combine the results from all planes in the current place?
10205 if (!is_crtc_enabled
) {
10206 plane_state
->visible
= visible
= false;
10207 to_intel_crtc_state(crtc_state
)->active_planes
&= ~BIT(plane
->id
);
10210 if (!was_visible
&& !visible
)
10213 if (fb
!= old_plane_state
->base
.fb
)
10214 pipe_config
->fb_changed
= true;
10216 turn_off
= was_visible
&& (!visible
|| mode_changed
);
10217 turn_on
= visible
&& (!was_visible
|| mode_changed
);
10219 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
10220 intel_crtc
->base
.base
.id
, intel_crtc
->base
.name
,
10221 plane
->base
.base
.id
, plane
->base
.name
,
10222 fb
? fb
->base
.id
: -1);
10224 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
10225 plane
->base
.base
.id
, plane
->base
.name
,
10226 was_visible
, visible
,
10227 turn_off
, turn_on
, mode_changed
);
10230 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
))
10231 pipe_config
->update_wm_pre
= true;
10233 /* must disable cxsr around plane enable/disable */
10234 if (plane
->id
!= PLANE_CURSOR
)
10235 pipe_config
->disable_cxsr
= true;
10236 } else if (turn_off
) {
10237 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
))
10238 pipe_config
->update_wm_post
= true;
10240 /* must disable cxsr around plane enable/disable */
10241 if (plane
->id
!= PLANE_CURSOR
)
10242 pipe_config
->disable_cxsr
= true;
10243 } else if (intel_wm_need_update(&plane
->base
, plane_state
)) {
10244 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
)) {
10245 /* FIXME bollocks */
10246 pipe_config
->update_wm_pre
= true;
10247 pipe_config
->update_wm_post
= true;
10251 if (visible
|| was_visible
)
10252 pipe_config
->fb_bits
|= plane
->frontbuffer_bit
;
10255 * WaCxSRDisabledForSpriteScaling:ivb
10257 * cstate->update_wm was already set above, so this flag will
10258 * take effect when we commit and program watermarks.
10260 if (plane
->id
== PLANE_SPRITE0
&& IS_IVYBRIDGE(dev_priv
) &&
10261 needs_scaling(to_intel_plane_state(plane_state
)) &&
10262 !needs_scaling(old_plane_state
))
10263 pipe_config
->disable_lp_wm
= true;
10268 static bool encoders_cloneable(const struct intel_encoder
*a
,
10269 const struct intel_encoder
*b
)
10271 /* masks could be asymmetric, so check both ways */
10272 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
10273 b
->cloneable
& (1 << a
->type
));
10276 static bool check_single_encoder_cloning(struct drm_atomic_state
*state
,
10277 struct intel_crtc
*crtc
,
10278 struct intel_encoder
*encoder
)
10280 struct intel_encoder
*source_encoder
;
10281 struct drm_connector
*connector
;
10282 struct drm_connector_state
*connector_state
;
10285 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10286 if (connector_state
->crtc
!= &crtc
->base
)
10290 to_intel_encoder(connector_state
->best_encoder
);
10291 if (!encoders_cloneable(encoder
, source_encoder
))
10298 static int intel_crtc_atomic_check(struct drm_crtc
*crtc
,
10299 struct drm_crtc_state
*crtc_state
)
10301 struct drm_device
*dev
= crtc
->dev
;
10302 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10303 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10304 struct intel_crtc_state
*pipe_config
=
10305 to_intel_crtc_state(crtc_state
);
10306 struct drm_atomic_state
*state
= crtc_state
->state
;
10308 bool mode_changed
= needs_modeset(crtc_state
);
10310 if (mode_changed
&& !crtc_state
->active
)
10311 pipe_config
->update_wm_post
= true;
10313 if (mode_changed
&& crtc_state
->enable
&&
10314 dev_priv
->display
.crtc_compute_clock
&&
10315 !WARN_ON(pipe_config
->shared_dpll
)) {
10316 ret
= dev_priv
->display
.crtc_compute_clock(intel_crtc
,
10322 if (crtc_state
->color_mgmt_changed
) {
10323 ret
= intel_color_check(crtc
, crtc_state
);
10328 * Changing color management on Intel hardware is
10329 * handled as part of planes update.
10331 crtc_state
->planes_changed
= true;
10335 if (dev_priv
->display
.compute_pipe_wm
) {
10336 ret
= dev_priv
->display
.compute_pipe_wm(pipe_config
);
10338 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
10343 if (dev_priv
->display
.compute_intermediate_wm
&&
10344 !to_intel_atomic_state(state
)->skip_intermediate_wm
) {
10345 if (WARN_ON(!dev_priv
->display
.compute_pipe_wm
))
10349 * Calculate 'intermediate' watermarks that satisfy both the
10350 * old state and the new state. We can program these
10353 ret
= dev_priv
->display
.compute_intermediate_wm(dev
,
10357 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
10360 } else if (dev_priv
->display
.compute_intermediate_wm
) {
10361 if (HAS_PCH_SPLIT(dev_priv
) && INTEL_GEN(dev_priv
) < 9)
10362 pipe_config
->wm
.ilk
.intermediate
= pipe_config
->wm
.ilk
.optimal
;
10365 if (INTEL_GEN(dev_priv
) >= 9) {
10367 ret
= skl_update_scaler_crtc(pipe_config
);
10370 ret
= skl_check_pipe_max_pixel_rate(intel_crtc
,
10373 ret
= intel_atomic_setup_scalers(dev_priv
, intel_crtc
,
10380 static const struct drm_crtc_helper_funcs intel_helper_funcs
= {
10381 .atomic_begin
= intel_begin_crtc_commit
,
10382 .atomic_flush
= intel_finish_crtc_commit
,
10383 .atomic_check
= intel_crtc_atomic_check
,
10386 static void intel_modeset_update_connector_atomic_state(struct drm_device
*dev
)
10388 struct intel_connector
*connector
;
10389 struct drm_connector_list_iter conn_iter
;
10391 drm_connector_list_iter_begin(dev
, &conn_iter
);
10392 for_each_intel_connector_iter(connector
, &conn_iter
) {
10393 if (connector
->base
.state
->crtc
)
10394 drm_connector_unreference(&connector
->base
);
10396 if (connector
->base
.encoder
) {
10397 connector
->base
.state
->best_encoder
=
10398 connector
->base
.encoder
;
10399 connector
->base
.state
->crtc
=
10400 connector
->base
.encoder
->crtc
;
10402 drm_connector_reference(&connector
->base
);
10404 connector
->base
.state
->best_encoder
= NULL
;
10405 connector
->base
.state
->crtc
= NULL
;
10408 drm_connector_list_iter_end(&conn_iter
);
10412 connected_sink_compute_bpp(struct intel_connector
*connector
,
10413 struct intel_crtc_state
*pipe_config
)
10415 const struct drm_display_info
*info
= &connector
->base
.display_info
;
10416 int bpp
= pipe_config
->pipe_bpp
;
10418 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
10419 connector
->base
.base
.id
,
10420 connector
->base
.name
);
10422 /* Don't use an invalid EDID bpc value */
10423 if (info
->bpc
!= 0 && info
->bpc
* 3 < bpp
) {
10424 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
10425 bpp
, info
->bpc
* 3);
10426 pipe_config
->pipe_bpp
= info
->bpc
* 3;
10429 /* Clamp bpp to 8 on screens without EDID 1.4 */
10430 if (info
->bpc
== 0 && bpp
> 24) {
10431 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
10433 pipe_config
->pipe_bpp
= 24;
10438 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
10439 struct intel_crtc_state
*pipe_config
)
10441 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
10442 struct drm_atomic_state
*state
;
10443 struct drm_connector
*connector
;
10444 struct drm_connector_state
*connector_state
;
10447 if ((IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
10448 IS_CHERRYVIEW(dev_priv
)))
10450 else if (INTEL_GEN(dev_priv
) >= 5)
10456 pipe_config
->pipe_bpp
= bpp
;
10458 state
= pipe_config
->base
.state
;
10460 /* Clamp display bpp to EDID value */
10461 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10462 if (connector_state
->crtc
!= &crtc
->base
)
10465 connected_sink_compute_bpp(to_intel_connector(connector
),
10472 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
10474 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
10475 "type: 0x%x flags: 0x%x\n",
10477 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
10478 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
10479 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
10480 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
10484 intel_dump_m_n_config(struct intel_crtc_state
*pipe_config
, char *id
,
10485 unsigned int lane_count
, struct intel_link_m_n
*m_n
)
10487 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10489 m_n
->gmch_m
, m_n
->gmch_n
,
10490 m_n
->link_m
, m_n
->link_n
, m_n
->tu
);
10493 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
10494 struct intel_crtc_state
*pipe_config
,
10495 const char *context
)
10497 struct drm_device
*dev
= crtc
->base
.dev
;
10498 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10499 struct drm_plane
*plane
;
10500 struct intel_plane
*intel_plane
;
10501 struct intel_plane_state
*state
;
10502 struct drm_framebuffer
*fb
;
10504 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
10505 crtc
->base
.base
.id
, crtc
->base
.name
, context
);
10507 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
10508 transcoder_name(pipe_config
->cpu_transcoder
),
10509 pipe_config
->pipe_bpp
, pipe_config
->dither
);
10511 if (pipe_config
->has_pch_encoder
)
10512 intel_dump_m_n_config(pipe_config
, "fdi",
10513 pipe_config
->fdi_lanes
,
10514 &pipe_config
->fdi_m_n
);
10516 if (intel_crtc_has_dp_encoder(pipe_config
)) {
10517 intel_dump_m_n_config(pipe_config
, "dp m_n",
10518 pipe_config
->lane_count
, &pipe_config
->dp_m_n
);
10519 if (pipe_config
->has_drrs
)
10520 intel_dump_m_n_config(pipe_config
, "dp m2_n2",
10521 pipe_config
->lane_count
,
10522 &pipe_config
->dp_m2_n2
);
10525 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
10526 pipe_config
->has_audio
, pipe_config
->has_infoframe
);
10528 DRM_DEBUG_KMS("requested mode:\n");
10529 drm_mode_debug_printmodeline(&pipe_config
->base
.mode
);
10530 DRM_DEBUG_KMS("adjusted mode:\n");
10531 drm_mode_debug_printmodeline(&pipe_config
->base
.adjusted_mode
);
10532 intel_dump_crtc_timings(&pipe_config
->base
.adjusted_mode
);
10533 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
10534 pipe_config
->port_clock
,
10535 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
,
10536 pipe_config
->pixel_rate
);
10538 if (INTEL_GEN(dev_priv
) >= 9)
10539 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
10541 pipe_config
->scaler_state
.scaler_users
,
10542 pipe_config
->scaler_state
.scaler_id
);
10544 if (HAS_GMCH_DISPLAY(dev_priv
))
10545 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
10546 pipe_config
->gmch_pfit
.control
,
10547 pipe_config
->gmch_pfit
.pgm_ratios
,
10548 pipe_config
->gmch_pfit
.lvds_border_bits
);
10550 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
10551 pipe_config
->pch_pfit
.pos
,
10552 pipe_config
->pch_pfit
.size
,
10553 enableddisabled(pipe_config
->pch_pfit
.enabled
));
10555 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
10556 pipe_config
->ips_enabled
, pipe_config
->double_wide
);
10558 intel_dpll_dump_hw_state(dev_priv
, &pipe_config
->dpll_hw_state
);
10560 DRM_DEBUG_KMS("planes on this crtc\n");
10561 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
10562 struct drm_format_name_buf format_name
;
10563 intel_plane
= to_intel_plane(plane
);
10564 if (intel_plane
->pipe
!= crtc
->pipe
)
10567 state
= to_intel_plane_state(plane
->state
);
10568 fb
= state
->base
.fb
;
10570 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
10571 plane
->base
.id
, plane
->name
, state
->scaler_id
);
10575 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
10576 plane
->base
.id
, plane
->name
,
10577 fb
->base
.id
, fb
->width
, fb
->height
,
10578 drm_get_format_name(fb
->format
->format
, &format_name
));
10579 if (INTEL_GEN(dev_priv
) >= 9)
10580 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
10582 state
->base
.src
.x1
>> 16,
10583 state
->base
.src
.y1
>> 16,
10584 drm_rect_width(&state
->base
.src
) >> 16,
10585 drm_rect_height(&state
->base
.src
) >> 16,
10586 state
->base
.dst
.x1
, state
->base
.dst
.y1
,
10587 drm_rect_width(&state
->base
.dst
),
10588 drm_rect_height(&state
->base
.dst
));
10592 static bool check_digital_port_conflicts(struct drm_atomic_state
*state
)
10594 struct drm_device
*dev
= state
->dev
;
10595 struct drm_connector
*connector
;
10596 struct drm_connector_list_iter conn_iter
;
10597 unsigned int used_ports
= 0;
10598 unsigned int used_mst_ports
= 0;
10601 * Walk the connector list instead of the encoder
10602 * list to detect the problem on ddi platforms
10603 * where there's just one encoder per digital port.
10605 drm_connector_list_iter_begin(dev
, &conn_iter
);
10606 drm_for_each_connector_iter(connector
, &conn_iter
) {
10607 struct drm_connector_state
*connector_state
;
10608 struct intel_encoder
*encoder
;
10610 connector_state
= drm_atomic_get_existing_connector_state(state
, connector
);
10611 if (!connector_state
)
10612 connector_state
= connector
->state
;
10614 if (!connector_state
->best_encoder
)
10617 encoder
= to_intel_encoder(connector_state
->best_encoder
);
10619 WARN_ON(!connector_state
->crtc
);
10621 switch (encoder
->type
) {
10622 unsigned int port_mask
;
10623 case INTEL_OUTPUT_UNKNOWN
:
10624 if (WARN_ON(!HAS_DDI(to_i915(dev
))))
10626 case INTEL_OUTPUT_DP
:
10627 case INTEL_OUTPUT_HDMI
:
10628 case INTEL_OUTPUT_EDP
:
10629 port_mask
= 1 << enc_to_dig_port(&encoder
->base
)->port
;
10631 /* the same port mustn't appear more than once */
10632 if (used_ports
& port_mask
)
10635 used_ports
|= port_mask
;
10637 case INTEL_OUTPUT_DP_MST
:
10639 1 << enc_to_mst(&encoder
->base
)->primary
->port
;
10645 drm_connector_list_iter_end(&conn_iter
);
10647 /* can't mix MST and SST/HDMI on the same port */
10648 if (used_ports
& used_mst_ports
)
10655 clear_intel_crtc_state(struct intel_crtc_state
*crtc_state
)
10657 struct drm_i915_private
*dev_priv
=
10658 to_i915(crtc_state
->base
.crtc
->dev
);
10659 struct intel_crtc_scaler_state scaler_state
;
10660 struct intel_dpll_hw_state dpll_hw_state
;
10661 struct intel_shared_dpll
*shared_dpll
;
10662 struct intel_crtc_wm_state wm_state
;
10665 /* FIXME: before the switch to atomic started, a new pipe_config was
10666 * kzalloc'd. Code that depends on any field being zero should be
10667 * fixed, so that the crtc_state can be safely duplicated. For now,
10668 * only fields that are know to not cause problems are preserved. */
10670 scaler_state
= crtc_state
->scaler_state
;
10671 shared_dpll
= crtc_state
->shared_dpll
;
10672 dpll_hw_state
= crtc_state
->dpll_hw_state
;
10673 force_thru
= crtc_state
->pch_pfit
.force_thru
;
10674 if (IS_G4X(dev_priv
) ||
10675 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
10676 wm_state
= crtc_state
->wm
;
10678 /* Keep base drm_crtc_state intact, only clear our extended struct */
10679 BUILD_BUG_ON(offsetof(struct intel_crtc_state
, base
));
10680 memset(&crtc_state
->base
+ 1, 0,
10681 sizeof(*crtc_state
) - sizeof(crtc_state
->base
));
10683 crtc_state
->scaler_state
= scaler_state
;
10684 crtc_state
->shared_dpll
= shared_dpll
;
10685 crtc_state
->dpll_hw_state
= dpll_hw_state
;
10686 crtc_state
->pch_pfit
.force_thru
= force_thru
;
10687 if (IS_G4X(dev_priv
) ||
10688 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
10689 crtc_state
->wm
= wm_state
;
10693 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
10694 struct intel_crtc_state
*pipe_config
)
10696 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
10697 struct intel_encoder
*encoder
;
10698 struct drm_connector
*connector
;
10699 struct drm_connector_state
*connector_state
;
10700 int base_bpp
, ret
= -EINVAL
;
10704 clear_intel_crtc_state(pipe_config
);
10706 pipe_config
->cpu_transcoder
=
10707 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
10710 * Sanitize sync polarity flags based on requested ones. If neither
10711 * positive or negative polarity is requested, treat this as meaning
10712 * negative polarity.
10714 if (!(pipe_config
->base
.adjusted_mode
.flags
&
10715 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
10716 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
10718 if (!(pipe_config
->base
.adjusted_mode
.flags
&
10719 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
10720 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
10722 base_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
10728 * Determine the real pipe dimensions. Note that stereo modes can
10729 * increase the actual pipe size due to the frame doubling and
10730 * insertion of additional space for blanks between the frame. This
10731 * is stored in the crtc timings. We use the requested mode to do this
10732 * computation to clearly distinguish it from the adjusted mode, which
10733 * can be changed by the connectors in the below retry loop.
10735 drm_mode_get_hv_timing(&pipe_config
->base
.mode
,
10736 &pipe_config
->pipe_src_w
,
10737 &pipe_config
->pipe_src_h
);
10739 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10740 if (connector_state
->crtc
!= crtc
)
10743 encoder
= to_intel_encoder(connector_state
->best_encoder
);
10745 if (!check_single_encoder_cloning(state
, to_intel_crtc(crtc
), encoder
)) {
10746 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
10751 * Determine output_types before calling the .compute_config()
10752 * hooks so that the hooks can use this information safely.
10754 pipe_config
->output_types
|= 1 << encoder
->type
;
10758 /* Ensure the port clock defaults are reset when retrying. */
10759 pipe_config
->port_clock
= 0;
10760 pipe_config
->pixel_multiplier
= 1;
10762 /* Fill in default crtc timings, allow encoders to overwrite them. */
10763 drm_mode_set_crtcinfo(&pipe_config
->base
.adjusted_mode
,
10764 CRTC_STEREO_DOUBLE
);
10766 /* Pass our mode to the connectors and the CRTC to give them a chance to
10767 * adjust it according to limitations or connector properties, and also
10768 * a chance to reject the mode entirely.
10770 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10771 if (connector_state
->crtc
!= crtc
)
10774 encoder
= to_intel_encoder(connector_state
->best_encoder
);
10776 if (!(encoder
->compute_config(encoder
, pipe_config
, connector_state
))) {
10777 DRM_DEBUG_KMS("Encoder config failure\n");
10782 /* Set default port clock if not overwritten by the encoder. Needs to be
10783 * done afterwards in case the encoder adjusts the mode. */
10784 if (!pipe_config
->port_clock
)
10785 pipe_config
->port_clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
10786 * pipe_config
->pixel_multiplier
;
10788 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
10790 DRM_DEBUG_KMS("CRTC fixup failed\n");
10794 if (ret
== RETRY
) {
10795 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
10800 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
10802 goto encoder_retry
;
10805 /* Dithering seems to not pass-through bits correctly when it should, so
10806 * only enable it on 6bpc panels and when its not a compliance
10807 * test requesting 6bpc video pattern.
10809 pipe_config
->dither
= (pipe_config
->pipe_bpp
== 6*3) &&
10810 !pipe_config
->dither_force_disable
;
10811 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
10812 base_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
10819 intel_modeset_update_crtc_state(struct drm_atomic_state
*state
)
10821 struct drm_crtc
*crtc
;
10822 struct drm_crtc_state
*new_crtc_state
;
10825 /* Double check state. */
10826 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
10827 to_intel_crtc(crtc
)->config
= to_intel_crtc_state(new_crtc_state
);
10830 * Update legacy state to satisfy fbc code. This can
10831 * be removed when fbc uses the atomic state.
10833 if (drm_atomic_get_existing_plane_state(state
, crtc
->primary
)) {
10834 struct drm_plane_state
*plane_state
= crtc
->primary
->state
;
10836 crtc
->primary
->fb
= plane_state
->fb
;
10837 crtc
->x
= plane_state
->src_x
>> 16;
10838 crtc
->y
= plane_state
->src_y
>> 16;
10843 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
10847 if (clock1
== clock2
)
10850 if (!clock1
|| !clock2
)
10853 diff
= abs(clock1
- clock2
);
10855 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
10862 intel_compare_m_n(unsigned int m
, unsigned int n
,
10863 unsigned int m2
, unsigned int n2
,
10866 if (m
== m2
&& n
== n2
)
10869 if (exact
|| !m
|| !n
|| !m2
|| !n2
)
10872 BUILD_BUG_ON(DATA_LINK_M_N_MASK
> INT_MAX
);
10879 } else if (n
< n2
) {
10889 return intel_fuzzy_clock_check(m
, m2
);
10893 intel_compare_link_m_n(const struct intel_link_m_n
*m_n
,
10894 struct intel_link_m_n
*m2_n2
,
10897 if (m_n
->tu
== m2_n2
->tu
&&
10898 intel_compare_m_n(m_n
->gmch_m
, m_n
->gmch_n
,
10899 m2_n2
->gmch_m
, m2_n2
->gmch_n
, !adjust
) &&
10900 intel_compare_m_n(m_n
->link_m
, m_n
->link_n
,
10901 m2_n2
->link_m
, m2_n2
->link_n
, !adjust
)) {
10911 static void __printf(3, 4)
10912 pipe_config_err(bool adjust
, const char *name
, const char *format
, ...)
10915 unsigned int category
;
10916 struct va_format vaf
;
10920 level
= KERN_DEBUG
;
10921 category
= DRM_UT_KMS
;
10924 category
= DRM_UT_NONE
;
10927 va_start(args
, format
);
10931 drm_printk(level
, category
, "mismatch in %s %pV", name
, &vaf
);
10937 intel_pipe_config_compare(struct drm_i915_private
*dev_priv
,
10938 struct intel_crtc_state
*current_config
,
10939 struct intel_crtc_state
*pipe_config
,
10944 #define PIPE_CONF_CHECK_X(name) \
10945 if (current_config->name != pipe_config->name) { \
10946 pipe_config_err(adjust, __stringify(name), \
10947 "(expected 0x%08x, found 0x%08x)\n", \
10948 current_config->name, \
10949 pipe_config->name); \
10953 #define PIPE_CONF_CHECK_I(name) \
10954 if (current_config->name != pipe_config->name) { \
10955 pipe_config_err(adjust, __stringify(name), \
10956 "(expected %i, found %i)\n", \
10957 current_config->name, \
10958 pipe_config->name); \
10962 #define PIPE_CONF_CHECK_P(name) \
10963 if (current_config->name != pipe_config->name) { \
10964 pipe_config_err(adjust, __stringify(name), \
10965 "(expected %p, found %p)\n", \
10966 current_config->name, \
10967 pipe_config->name); \
10971 #define PIPE_CONF_CHECK_M_N(name) \
10972 if (!intel_compare_link_m_n(¤t_config->name, \
10973 &pipe_config->name,\
10975 pipe_config_err(adjust, __stringify(name), \
10976 "(expected tu %i gmch %i/%i link %i/%i, " \
10977 "found tu %i, gmch %i/%i link %i/%i)\n", \
10978 current_config->name.tu, \
10979 current_config->name.gmch_m, \
10980 current_config->name.gmch_n, \
10981 current_config->name.link_m, \
10982 current_config->name.link_n, \
10983 pipe_config->name.tu, \
10984 pipe_config->name.gmch_m, \
10985 pipe_config->name.gmch_n, \
10986 pipe_config->name.link_m, \
10987 pipe_config->name.link_n); \
10991 /* This is required for BDW+ where there is only one set of registers for
10992 * switching between high and low RR.
10993 * This macro can be used whenever a comparison has to be made between one
10994 * hw state and multiple sw state variables.
10996 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \
10997 if (!intel_compare_link_m_n(¤t_config->name, \
10998 &pipe_config->name, adjust) && \
10999 !intel_compare_link_m_n(¤t_config->alt_name, \
11000 &pipe_config->name, adjust)) { \
11001 pipe_config_err(adjust, __stringify(name), \
11002 "(expected tu %i gmch %i/%i link %i/%i, " \
11003 "or tu %i gmch %i/%i link %i/%i, " \
11004 "found tu %i, gmch %i/%i link %i/%i)\n", \
11005 current_config->name.tu, \
11006 current_config->name.gmch_m, \
11007 current_config->name.gmch_n, \
11008 current_config->name.link_m, \
11009 current_config->name.link_n, \
11010 current_config->alt_name.tu, \
11011 current_config->alt_name.gmch_m, \
11012 current_config->alt_name.gmch_n, \
11013 current_config->alt_name.link_m, \
11014 current_config->alt_name.link_n, \
11015 pipe_config->name.tu, \
11016 pipe_config->name.gmch_m, \
11017 pipe_config->name.gmch_n, \
11018 pipe_config->name.link_m, \
11019 pipe_config->name.link_n); \
11023 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
11024 if ((current_config->name ^ pipe_config->name) & (mask)) { \
11025 pipe_config_err(adjust, __stringify(name), \
11026 "(%x) (expected %i, found %i)\n", \
11028 current_config->name & (mask), \
11029 pipe_config->name & (mask)); \
11033 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
11034 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
11035 pipe_config_err(adjust, __stringify(name), \
11036 "(expected %i, found %i)\n", \
11037 current_config->name, \
11038 pipe_config->name); \
11042 #define PIPE_CONF_QUIRK(quirk) \
11043 ((current_config->quirks | pipe_config->quirks) & (quirk))
11045 PIPE_CONF_CHECK_I(cpu_transcoder
);
11047 PIPE_CONF_CHECK_I(has_pch_encoder
);
11048 PIPE_CONF_CHECK_I(fdi_lanes
);
11049 PIPE_CONF_CHECK_M_N(fdi_m_n
);
11051 PIPE_CONF_CHECK_I(lane_count
);
11052 PIPE_CONF_CHECK_X(lane_lat_optim_mask
);
11054 if (INTEL_GEN(dev_priv
) < 8) {
11055 PIPE_CONF_CHECK_M_N(dp_m_n
);
11057 if (current_config
->has_drrs
)
11058 PIPE_CONF_CHECK_M_N(dp_m2_n2
);
11060 PIPE_CONF_CHECK_M_N_ALT(dp_m_n
, dp_m2_n2
);
11062 PIPE_CONF_CHECK_X(output_types
);
11064 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hdisplay
);
11065 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_htotal
);
11066 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_start
);
11067 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_end
);
11068 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_start
);
11069 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_end
);
11071 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vdisplay
);
11072 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vtotal
);
11073 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_start
);
11074 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_end
);
11075 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_start
);
11076 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_end
);
11078 PIPE_CONF_CHECK_I(pixel_multiplier
);
11079 PIPE_CONF_CHECK_I(has_hdmi_sink
);
11080 if ((INTEL_GEN(dev_priv
) < 8 && !IS_HASWELL(dev_priv
)) ||
11081 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
11082 PIPE_CONF_CHECK_I(limited_color_range
);
11084 PIPE_CONF_CHECK_I(hdmi_scrambling
);
11085 PIPE_CONF_CHECK_I(hdmi_high_tmds_clock_ratio
);
11086 PIPE_CONF_CHECK_I(has_infoframe
);
11088 PIPE_CONF_CHECK_I(has_audio
);
11090 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11091 DRM_MODE_FLAG_INTERLACE
);
11093 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
11094 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11095 DRM_MODE_FLAG_PHSYNC
);
11096 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11097 DRM_MODE_FLAG_NHSYNC
);
11098 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11099 DRM_MODE_FLAG_PVSYNC
);
11100 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11101 DRM_MODE_FLAG_NVSYNC
);
11104 PIPE_CONF_CHECK_X(gmch_pfit
.control
);
11105 /* pfit ratios are autocomputed by the hw on gen4+ */
11106 if (INTEL_GEN(dev_priv
) < 4)
11107 PIPE_CONF_CHECK_X(gmch_pfit
.pgm_ratios
);
11108 PIPE_CONF_CHECK_X(gmch_pfit
.lvds_border_bits
);
11111 PIPE_CONF_CHECK_I(pipe_src_w
);
11112 PIPE_CONF_CHECK_I(pipe_src_h
);
11114 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
11115 if (current_config
->pch_pfit
.enabled
) {
11116 PIPE_CONF_CHECK_X(pch_pfit
.pos
);
11117 PIPE_CONF_CHECK_X(pch_pfit
.size
);
11120 PIPE_CONF_CHECK_I(scaler_state
.scaler_id
);
11121 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate
);
11124 /* BDW+ don't expose a synchronous way to read the state */
11125 if (IS_HASWELL(dev_priv
))
11126 PIPE_CONF_CHECK_I(ips_enabled
);
11128 PIPE_CONF_CHECK_I(double_wide
);
11130 PIPE_CONF_CHECK_P(shared_dpll
);
11131 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
11132 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
11133 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
11134 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
11135 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
11136 PIPE_CONF_CHECK_X(dpll_hw_state
.spll
);
11137 PIPE_CONF_CHECK_X(dpll_hw_state
.ctrl1
);
11138 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr1
);
11139 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr2
);
11141 PIPE_CONF_CHECK_X(dsi_pll
.ctrl
);
11142 PIPE_CONF_CHECK_X(dsi_pll
.div
);
11144 if (IS_G4X(dev_priv
) || INTEL_GEN(dev_priv
) >= 5)
11145 PIPE_CONF_CHECK_I(pipe_bpp
);
11147 PIPE_CONF_CHECK_CLOCK_FUZZY(base
.adjusted_mode
.crtc_clock
);
11148 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
11150 #undef PIPE_CONF_CHECK_X
11151 #undef PIPE_CONF_CHECK_I
11152 #undef PIPE_CONF_CHECK_P
11153 #undef PIPE_CONF_CHECK_FLAGS
11154 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
11155 #undef PIPE_CONF_QUIRK
11160 static void intel_pipe_config_sanity_check(struct drm_i915_private
*dev_priv
,
11161 const struct intel_crtc_state
*pipe_config
)
11163 if (pipe_config
->has_pch_encoder
) {
11164 int fdi_dotclock
= intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
11165 &pipe_config
->fdi_m_n
);
11166 int dotclock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
11169 * FDI already provided one idea for the dotclock.
11170 * Yell if the encoder disagrees.
11172 WARN(!intel_fuzzy_clock_check(fdi_dotclock
, dotclock
),
11173 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11174 fdi_dotclock
, dotclock
);
11178 static void verify_wm_state(struct drm_crtc
*crtc
,
11179 struct drm_crtc_state
*new_state
)
11181 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
11182 struct skl_ddb_allocation hw_ddb
, *sw_ddb
;
11183 struct skl_pipe_wm hw_wm
, *sw_wm
;
11184 struct skl_plane_wm
*hw_plane_wm
, *sw_plane_wm
;
11185 struct skl_ddb_entry
*hw_ddb_entry
, *sw_ddb_entry
;
11186 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11187 const enum pipe pipe
= intel_crtc
->pipe
;
11188 int plane
, level
, max_level
= ilk_wm_max_level(dev_priv
);
11190 if (INTEL_GEN(dev_priv
) < 9 || !new_state
->active
)
11193 skl_pipe_wm_get_hw_state(crtc
, &hw_wm
);
11194 sw_wm
= &to_intel_crtc_state(new_state
)->wm
.skl
.optimal
;
11196 skl_ddb_get_hw_state(dev_priv
, &hw_ddb
);
11197 sw_ddb
= &dev_priv
->wm
.skl_hw
.ddb
;
11200 for_each_universal_plane(dev_priv
, pipe
, plane
) {
11201 hw_plane_wm
= &hw_wm
.planes
[plane
];
11202 sw_plane_wm
= &sw_wm
->planes
[plane
];
11205 for (level
= 0; level
<= max_level
; level
++) {
11206 if (skl_wm_level_equals(&hw_plane_wm
->wm
[level
],
11207 &sw_plane_wm
->wm
[level
]))
11210 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",
11211 pipe_name(pipe
), plane
+ 1, level
,
11212 sw_plane_wm
->wm
[level
].plane_en
,
11213 sw_plane_wm
->wm
[level
].plane_res_b
,
11214 sw_plane_wm
->wm
[level
].plane_res_l
,
11215 hw_plane_wm
->wm
[level
].plane_en
,
11216 hw_plane_wm
->wm
[level
].plane_res_b
,
11217 hw_plane_wm
->wm
[level
].plane_res_l
);
11220 if (!skl_wm_level_equals(&hw_plane_wm
->trans_wm
,
11221 &sw_plane_wm
->trans_wm
)) {
11222 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",
11223 pipe_name(pipe
), plane
+ 1,
11224 sw_plane_wm
->trans_wm
.plane_en
,
11225 sw_plane_wm
->trans_wm
.plane_res_b
,
11226 sw_plane_wm
->trans_wm
.plane_res_l
,
11227 hw_plane_wm
->trans_wm
.plane_en
,
11228 hw_plane_wm
->trans_wm
.plane_res_b
,
11229 hw_plane_wm
->trans_wm
.plane_res_l
);
11233 hw_ddb_entry
= &hw_ddb
.plane
[pipe
][plane
];
11234 sw_ddb_entry
= &sw_ddb
->plane
[pipe
][plane
];
11236 if (!skl_ddb_entry_equal(hw_ddb_entry
, sw_ddb_entry
)) {
11237 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
11238 pipe_name(pipe
), plane
+ 1,
11239 sw_ddb_entry
->start
, sw_ddb_entry
->end
,
11240 hw_ddb_entry
->start
, hw_ddb_entry
->end
);
11246 * If the cursor plane isn't active, we may not have updated it's ddb
11247 * allocation. In that case since the ddb allocation will be updated
11248 * once the plane becomes visible, we can skip this check
11251 hw_plane_wm
= &hw_wm
.planes
[PLANE_CURSOR
];
11252 sw_plane_wm
= &sw_wm
->planes
[PLANE_CURSOR
];
11255 for (level
= 0; level
<= max_level
; level
++) {
11256 if (skl_wm_level_equals(&hw_plane_wm
->wm
[level
],
11257 &sw_plane_wm
->wm
[level
]))
11260 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",
11261 pipe_name(pipe
), level
,
11262 sw_plane_wm
->wm
[level
].plane_en
,
11263 sw_plane_wm
->wm
[level
].plane_res_b
,
11264 sw_plane_wm
->wm
[level
].plane_res_l
,
11265 hw_plane_wm
->wm
[level
].plane_en
,
11266 hw_plane_wm
->wm
[level
].plane_res_b
,
11267 hw_plane_wm
->wm
[level
].plane_res_l
);
11270 if (!skl_wm_level_equals(&hw_plane_wm
->trans_wm
,
11271 &sw_plane_wm
->trans_wm
)) {
11272 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11274 sw_plane_wm
->trans_wm
.plane_en
,
11275 sw_plane_wm
->trans_wm
.plane_res_b
,
11276 sw_plane_wm
->trans_wm
.plane_res_l
,
11277 hw_plane_wm
->trans_wm
.plane_en
,
11278 hw_plane_wm
->trans_wm
.plane_res_b
,
11279 hw_plane_wm
->trans_wm
.plane_res_l
);
11283 hw_ddb_entry
= &hw_ddb
.plane
[pipe
][PLANE_CURSOR
];
11284 sw_ddb_entry
= &sw_ddb
->plane
[pipe
][PLANE_CURSOR
];
11286 if (!skl_ddb_entry_equal(hw_ddb_entry
, sw_ddb_entry
)) {
11287 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
11289 sw_ddb_entry
->start
, sw_ddb_entry
->end
,
11290 hw_ddb_entry
->start
, hw_ddb_entry
->end
);
11296 verify_connector_state(struct drm_device
*dev
,
11297 struct drm_atomic_state
*state
,
11298 struct drm_crtc
*crtc
)
11300 struct drm_connector
*connector
;
11301 struct drm_connector_state
*new_conn_state
;
11304 for_each_new_connector_in_state(state
, connector
, new_conn_state
, i
) {
11305 struct drm_encoder
*encoder
= connector
->encoder
;
11306 struct drm_crtc_state
*crtc_state
= NULL
;
11308 if (new_conn_state
->crtc
!= crtc
)
11312 crtc_state
= drm_atomic_get_new_crtc_state(state
, new_conn_state
->crtc
);
11314 intel_connector_verify_state(crtc_state
, new_conn_state
);
11316 I915_STATE_WARN(new_conn_state
->best_encoder
!= encoder
,
11317 "connector's atomic encoder doesn't match legacy encoder\n");
11322 verify_encoder_state(struct drm_device
*dev
, struct drm_atomic_state
*state
)
11324 struct intel_encoder
*encoder
;
11325 struct drm_connector
*connector
;
11326 struct drm_connector_state
*old_conn_state
, *new_conn_state
;
11329 for_each_intel_encoder(dev
, encoder
) {
11330 bool enabled
= false, found
= false;
11333 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
11334 encoder
->base
.base
.id
,
11335 encoder
->base
.name
);
11337 for_each_oldnew_connector_in_state(state
, connector
, old_conn_state
,
11338 new_conn_state
, i
) {
11339 if (old_conn_state
->best_encoder
== &encoder
->base
)
11342 if (new_conn_state
->best_encoder
!= &encoder
->base
)
11344 found
= enabled
= true;
11346 I915_STATE_WARN(new_conn_state
->crtc
!=
11347 encoder
->base
.crtc
,
11348 "connector's crtc doesn't match encoder crtc\n");
11354 I915_STATE_WARN(!!encoder
->base
.crtc
!= enabled
,
11355 "encoder's enabled state mismatch "
11356 "(expected %i, found %i)\n",
11357 !!encoder
->base
.crtc
, enabled
);
11359 if (!encoder
->base
.crtc
) {
11362 active
= encoder
->get_hw_state(encoder
, &pipe
);
11363 I915_STATE_WARN(active
,
11364 "encoder detached but still enabled on pipe %c.\n",
11371 verify_crtc_state(struct drm_crtc
*crtc
,
11372 struct drm_crtc_state
*old_crtc_state
,
11373 struct drm_crtc_state
*new_crtc_state
)
11375 struct drm_device
*dev
= crtc
->dev
;
11376 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11377 struct intel_encoder
*encoder
;
11378 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11379 struct intel_crtc_state
*pipe_config
, *sw_config
;
11380 struct drm_atomic_state
*old_state
;
11383 old_state
= old_crtc_state
->state
;
11384 __drm_atomic_helper_crtc_destroy_state(old_crtc_state
);
11385 pipe_config
= to_intel_crtc_state(old_crtc_state
);
11386 memset(pipe_config
, 0, sizeof(*pipe_config
));
11387 pipe_config
->base
.crtc
= crtc
;
11388 pipe_config
->base
.state
= old_state
;
11390 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc
->base
.id
, crtc
->name
);
11392 active
= dev_priv
->display
.get_pipe_config(intel_crtc
, pipe_config
);
11394 /* we keep both pipes enabled on 830 */
11395 if (IS_I830(dev_priv
))
11396 active
= new_crtc_state
->active
;
11398 I915_STATE_WARN(new_crtc_state
->active
!= active
,
11399 "crtc active state doesn't match with hw state "
11400 "(expected %i, found %i)\n", new_crtc_state
->active
, active
);
11402 I915_STATE_WARN(intel_crtc
->active
!= new_crtc_state
->active
,
11403 "transitional active state does not match atomic hw state "
11404 "(expected %i, found %i)\n", new_crtc_state
->active
, intel_crtc
->active
);
11406 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
11409 active
= encoder
->get_hw_state(encoder
, &pipe
);
11410 I915_STATE_WARN(active
!= new_crtc_state
->active
,
11411 "[ENCODER:%i] active %i with crtc active %i\n",
11412 encoder
->base
.base
.id
, active
, new_crtc_state
->active
);
11414 I915_STATE_WARN(active
&& intel_crtc
->pipe
!= pipe
,
11415 "Encoder connected to wrong pipe %c\n",
11419 pipe_config
->output_types
|= 1 << encoder
->type
;
11420 encoder
->get_config(encoder
, pipe_config
);
11424 intel_crtc_compute_pixel_rate(pipe_config
);
11426 if (!new_crtc_state
->active
)
11429 intel_pipe_config_sanity_check(dev_priv
, pipe_config
);
11431 sw_config
= to_intel_crtc_state(new_crtc_state
);
11432 if (!intel_pipe_config_compare(dev_priv
, sw_config
,
11433 pipe_config
, false)) {
11434 I915_STATE_WARN(1, "pipe state doesn't match!\n");
11435 intel_dump_pipe_config(intel_crtc
, pipe_config
,
11437 intel_dump_pipe_config(intel_crtc
, sw_config
,
11443 verify_single_dpll_state(struct drm_i915_private
*dev_priv
,
11444 struct intel_shared_dpll
*pll
,
11445 struct drm_crtc
*crtc
,
11446 struct drm_crtc_state
*new_state
)
11448 struct intel_dpll_hw_state dpll_hw_state
;
11449 unsigned crtc_mask
;
11452 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
11454 DRM_DEBUG_KMS("%s\n", pll
->name
);
11456 active
= pll
->funcs
.get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
11458 if (!(pll
->flags
& INTEL_DPLL_ALWAYS_ON
)) {
11459 I915_STATE_WARN(!pll
->on
&& pll
->active_mask
,
11460 "pll in active use but not on in sw tracking\n");
11461 I915_STATE_WARN(pll
->on
&& !pll
->active_mask
,
11462 "pll is on but not used by any active crtc\n");
11463 I915_STATE_WARN(pll
->on
!= active
,
11464 "pll on state mismatch (expected %i, found %i)\n",
11469 I915_STATE_WARN(pll
->active_mask
& ~pll
->state
.crtc_mask
,
11470 "more active pll users than references: %x vs %x\n",
11471 pll
->active_mask
, pll
->state
.crtc_mask
);
11476 crtc_mask
= 1 << drm_crtc_index(crtc
);
11478 if (new_state
->active
)
11479 I915_STATE_WARN(!(pll
->active_mask
& crtc_mask
),
11480 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
11481 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
11483 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
11484 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
11485 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
11487 I915_STATE_WARN(!(pll
->state
.crtc_mask
& crtc_mask
),
11488 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
11489 crtc_mask
, pll
->state
.crtc_mask
);
11491 I915_STATE_WARN(pll
->on
&& memcmp(&pll
->state
.hw_state
,
11493 sizeof(dpll_hw_state
)),
11494 "pll hw state mismatch\n");
11498 verify_shared_dpll_state(struct drm_device
*dev
, struct drm_crtc
*crtc
,
11499 struct drm_crtc_state
*old_crtc_state
,
11500 struct drm_crtc_state
*new_crtc_state
)
11502 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11503 struct intel_crtc_state
*old_state
= to_intel_crtc_state(old_crtc_state
);
11504 struct intel_crtc_state
*new_state
= to_intel_crtc_state(new_crtc_state
);
11506 if (new_state
->shared_dpll
)
11507 verify_single_dpll_state(dev_priv
, new_state
->shared_dpll
, crtc
, new_crtc_state
);
11509 if (old_state
->shared_dpll
&&
11510 old_state
->shared_dpll
!= new_state
->shared_dpll
) {
11511 unsigned crtc_mask
= 1 << drm_crtc_index(crtc
);
11512 struct intel_shared_dpll
*pll
= old_state
->shared_dpll
;
11514 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
11515 "pll active mismatch (didn't expect pipe %c in active mask)\n",
11516 pipe_name(drm_crtc_index(crtc
)));
11517 I915_STATE_WARN(pll
->state
.crtc_mask
& crtc_mask
,
11518 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
11519 pipe_name(drm_crtc_index(crtc
)));
11524 intel_modeset_verify_crtc(struct drm_crtc
*crtc
,
11525 struct drm_atomic_state
*state
,
11526 struct drm_crtc_state
*old_state
,
11527 struct drm_crtc_state
*new_state
)
11529 if (!needs_modeset(new_state
) &&
11530 !to_intel_crtc_state(new_state
)->update_pipe
)
11533 verify_wm_state(crtc
, new_state
);
11534 verify_connector_state(crtc
->dev
, state
, crtc
);
11535 verify_crtc_state(crtc
, old_state
, new_state
);
11536 verify_shared_dpll_state(crtc
->dev
, crtc
, old_state
, new_state
);
11540 verify_disabled_dpll_state(struct drm_device
*dev
)
11542 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11545 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++)
11546 verify_single_dpll_state(dev_priv
, &dev_priv
->shared_dplls
[i
], NULL
, NULL
);
11550 intel_modeset_verify_disabled(struct drm_device
*dev
,
11551 struct drm_atomic_state
*state
)
11553 verify_encoder_state(dev
, state
);
11554 verify_connector_state(dev
, state
, NULL
);
11555 verify_disabled_dpll_state(dev
);
11558 static void update_scanline_offset(struct intel_crtc
*crtc
)
11560 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
11563 * The scanline counter increments at the leading edge of hsync.
11565 * On most platforms it starts counting from vtotal-1 on the
11566 * first active line. That means the scanline counter value is
11567 * always one less than what we would expect. Ie. just after
11568 * start of vblank, which also occurs at start of hsync (on the
11569 * last active line), the scanline counter will read vblank_start-1.
11571 * On gen2 the scanline counter starts counting from 1 instead
11572 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
11573 * to keep the value positive), instead of adding one.
11575 * On HSW+ the behaviour of the scanline counter depends on the output
11576 * type. For DP ports it behaves like most other platforms, but on HDMI
11577 * there's an extra 1 line difference. So we need to add two instead of
11578 * one to the value.
11580 * On VLV/CHV DSI the scanline counter would appear to increment
11581 * approx. 1/3 of a scanline before start of vblank. Unfortunately
11582 * that means we can't tell whether we're in vblank or not while
11583 * we're on that particular line. We must still set scanline_offset
11584 * to 1 so that the vblank timestamps come out correct when we query
11585 * the scanline counter from within the vblank interrupt handler.
11586 * However if queried just before the start of vblank we'll get an
11587 * answer that's slightly in the future.
11589 if (IS_GEN2(dev_priv
)) {
11590 const struct drm_display_mode
*adjusted_mode
= &crtc
->config
->base
.adjusted_mode
;
11593 vtotal
= adjusted_mode
->crtc_vtotal
;
11594 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
11597 crtc
->scanline_offset
= vtotal
- 1;
11598 } else if (HAS_DDI(dev_priv
) &&
11599 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_HDMI
)) {
11600 crtc
->scanline_offset
= 2;
11602 crtc
->scanline_offset
= 1;
11605 static void intel_modeset_clear_plls(struct drm_atomic_state
*state
)
11607 struct drm_device
*dev
= state
->dev
;
11608 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11609 struct drm_crtc
*crtc
;
11610 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
11613 if (!dev_priv
->display
.crtc_compute_clock
)
11616 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
11617 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11618 struct intel_shared_dpll
*old_dpll
=
11619 to_intel_crtc_state(old_crtc_state
)->shared_dpll
;
11621 if (!needs_modeset(new_crtc_state
))
11624 to_intel_crtc_state(new_crtc_state
)->shared_dpll
= NULL
;
11629 intel_release_shared_dpll(old_dpll
, intel_crtc
, state
);
11634 * This implements the workaround described in the "notes" section of the mode
11635 * set sequence documentation. When going from no pipes or single pipe to
11636 * multiple pipes, and planes are enabled after the pipe, we need to wait at
11637 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
11639 static int haswell_mode_set_planes_workaround(struct drm_atomic_state
*state
)
11641 struct drm_crtc_state
*crtc_state
;
11642 struct intel_crtc
*intel_crtc
;
11643 struct drm_crtc
*crtc
;
11644 struct intel_crtc_state
*first_crtc_state
= NULL
;
11645 struct intel_crtc_state
*other_crtc_state
= NULL
;
11646 enum pipe first_pipe
= INVALID_PIPE
, enabled_pipe
= INVALID_PIPE
;
11649 /* look at all crtc's that are going to be enabled in during modeset */
11650 for_each_new_crtc_in_state(state
, crtc
, crtc_state
, i
) {
11651 intel_crtc
= to_intel_crtc(crtc
);
11653 if (!crtc_state
->active
|| !needs_modeset(crtc_state
))
11656 if (first_crtc_state
) {
11657 other_crtc_state
= to_intel_crtc_state(crtc_state
);
11660 first_crtc_state
= to_intel_crtc_state(crtc_state
);
11661 first_pipe
= intel_crtc
->pipe
;
11665 /* No workaround needed? */
11666 if (!first_crtc_state
)
11669 /* w/a possibly needed, check how many crtc's are already enabled. */
11670 for_each_intel_crtc(state
->dev
, intel_crtc
) {
11671 struct intel_crtc_state
*pipe_config
;
11673 pipe_config
= intel_atomic_get_crtc_state(state
, intel_crtc
);
11674 if (IS_ERR(pipe_config
))
11675 return PTR_ERR(pipe_config
);
11677 pipe_config
->hsw_workaround_pipe
= INVALID_PIPE
;
11679 if (!pipe_config
->base
.active
||
11680 needs_modeset(&pipe_config
->base
))
11683 /* 2 or more enabled crtcs means no need for w/a */
11684 if (enabled_pipe
!= INVALID_PIPE
)
11687 enabled_pipe
= intel_crtc
->pipe
;
11690 if (enabled_pipe
!= INVALID_PIPE
)
11691 first_crtc_state
->hsw_workaround_pipe
= enabled_pipe
;
11692 else if (other_crtc_state
)
11693 other_crtc_state
->hsw_workaround_pipe
= first_pipe
;
11698 static int intel_lock_all_pipes(struct drm_atomic_state
*state
)
11700 struct drm_crtc
*crtc
;
11702 /* Add all pipes to the state */
11703 for_each_crtc(state
->dev
, crtc
) {
11704 struct drm_crtc_state
*crtc_state
;
11706 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
11707 if (IS_ERR(crtc_state
))
11708 return PTR_ERR(crtc_state
);
11714 static int intel_modeset_all_pipes(struct drm_atomic_state
*state
)
11716 struct drm_crtc
*crtc
;
11719 * Add all pipes to the state, and force
11720 * a modeset on all the active ones.
11722 for_each_crtc(state
->dev
, crtc
) {
11723 struct drm_crtc_state
*crtc_state
;
11726 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
11727 if (IS_ERR(crtc_state
))
11728 return PTR_ERR(crtc_state
);
11730 if (!crtc_state
->active
|| needs_modeset(crtc_state
))
11733 crtc_state
->mode_changed
= true;
11735 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
11739 ret
= drm_atomic_add_affected_planes(state
, crtc
);
11747 static int intel_modeset_checks(struct drm_atomic_state
*state
)
11749 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
11750 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
11751 struct drm_crtc
*crtc
;
11752 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
11755 if (!check_digital_port_conflicts(state
)) {
11756 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
11760 intel_state
->modeset
= true;
11761 intel_state
->active_crtcs
= dev_priv
->active_crtcs
;
11762 intel_state
->cdclk
.logical
= dev_priv
->cdclk
.logical
;
11763 intel_state
->cdclk
.actual
= dev_priv
->cdclk
.actual
;
11765 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
11766 if (new_crtc_state
->active
)
11767 intel_state
->active_crtcs
|= 1 << i
;
11769 intel_state
->active_crtcs
&= ~(1 << i
);
11771 if (old_crtc_state
->active
!= new_crtc_state
->active
)
11772 intel_state
->active_pipe_changes
|= drm_crtc_mask(crtc
);
11776 * See if the config requires any additional preparation, e.g.
11777 * to adjust global state with pipes off. We need to do this
11778 * here so we can get the modeset_pipe updated config for the new
11779 * mode set on this crtc. For other crtcs we need to use the
11780 * adjusted_mode bits in the crtc directly.
11782 if (dev_priv
->display
.modeset_calc_cdclk
) {
11783 ret
= dev_priv
->display
.modeset_calc_cdclk(state
);
11788 * Writes to dev_priv->cdclk.logical must protected by
11789 * holding all the crtc locks, even if we don't end up
11790 * touching the hardware
11792 if (!intel_cdclk_state_compare(&dev_priv
->cdclk
.logical
,
11793 &intel_state
->cdclk
.logical
)) {
11794 ret
= intel_lock_all_pipes(state
);
11799 /* All pipes must be switched off while we change the cdclk. */
11800 if (!intel_cdclk_state_compare(&dev_priv
->cdclk
.actual
,
11801 &intel_state
->cdclk
.actual
)) {
11802 ret
= intel_modeset_all_pipes(state
);
11807 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
11808 intel_state
->cdclk
.logical
.cdclk
,
11809 intel_state
->cdclk
.actual
.cdclk
);
11811 to_intel_atomic_state(state
)->cdclk
.logical
= dev_priv
->cdclk
.logical
;
11814 intel_modeset_clear_plls(state
);
11816 if (IS_HASWELL(dev_priv
))
11817 return haswell_mode_set_planes_workaround(state
);
11823 * Handle calculation of various watermark data at the end of the atomic check
11824 * phase. The code here should be run after the per-crtc and per-plane 'check'
11825 * handlers to ensure that all derived state has been updated.
11827 static int calc_watermark_data(struct drm_atomic_state
*state
)
11829 struct drm_device
*dev
= state
->dev
;
11830 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11832 /* Is there platform-specific watermark information to calculate? */
11833 if (dev_priv
->display
.compute_global_watermarks
)
11834 return dev_priv
->display
.compute_global_watermarks(state
);
11840 * intel_atomic_check - validate state object
11842 * @state: state to validate
11844 static int intel_atomic_check(struct drm_device
*dev
,
11845 struct drm_atomic_state
*state
)
11847 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11848 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
11849 struct drm_crtc
*crtc
;
11850 struct drm_crtc_state
*old_crtc_state
, *crtc_state
;
11852 bool any_ms
= false;
11854 ret
= drm_atomic_helper_check_modeset(dev
, state
);
11858 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, crtc_state
, i
) {
11859 struct intel_crtc_state
*pipe_config
=
11860 to_intel_crtc_state(crtc_state
);
11862 /* Catch I915_MODE_FLAG_INHERITED */
11863 if (crtc_state
->mode
.private_flags
!= old_crtc_state
->mode
.private_flags
)
11864 crtc_state
->mode_changed
= true;
11866 if (!needs_modeset(crtc_state
))
11869 if (!crtc_state
->enable
) {
11874 /* FIXME: For only active_changed we shouldn't need to do any
11875 * state recomputation at all. */
11877 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
11881 ret
= intel_modeset_pipe_config(crtc
, pipe_config
);
11883 intel_dump_pipe_config(to_intel_crtc(crtc
),
11884 pipe_config
, "[failed]");
11888 if (i915
.fastboot
&&
11889 intel_pipe_config_compare(dev_priv
,
11890 to_intel_crtc_state(old_crtc_state
),
11891 pipe_config
, true)) {
11892 crtc_state
->mode_changed
= false;
11893 pipe_config
->update_pipe
= true;
11896 if (needs_modeset(crtc_state
))
11899 ret
= drm_atomic_add_affected_planes(state
, crtc
);
11903 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
11904 needs_modeset(crtc_state
) ?
11905 "[modeset]" : "[fastset]");
11909 ret
= intel_modeset_checks(state
);
11914 intel_state
->cdclk
.logical
= dev_priv
->cdclk
.logical
;
11917 ret
= drm_atomic_helper_check_planes(dev
, state
);
11921 intel_fbc_choose_crtc(dev_priv
, state
);
11922 return calc_watermark_data(state
);
11925 static int intel_atomic_prepare_commit(struct drm_device
*dev
,
11926 struct drm_atomic_state
*state
)
11928 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11929 struct drm_crtc_state
*crtc_state
;
11930 struct drm_crtc
*crtc
;
11933 for_each_new_crtc_in_state(state
, crtc
, crtc_state
, i
) {
11934 if (state
->legacy_cursor_update
)
11937 ret
= intel_crtc_wait_for_pending_flips(crtc
);
11941 if (atomic_read(&to_intel_crtc(crtc
)->unpin_work_count
) >= 2)
11942 flush_workqueue(dev_priv
->wq
);
11945 ret
= mutex_lock_interruptible(&dev
->struct_mutex
);
11949 ret
= drm_atomic_helper_prepare_planes(dev
, state
);
11950 mutex_unlock(&dev
->struct_mutex
);
11955 u32
intel_crtc_get_vblank_counter(struct intel_crtc
*crtc
)
11957 struct drm_device
*dev
= crtc
->base
.dev
;
11959 if (!dev
->max_vblank_count
)
11960 return drm_accurate_vblank_count(&crtc
->base
);
11962 return dev
->driver
->get_vblank_counter(dev
, crtc
->pipe
);
11965 static void intel_atomic_wait_for_vblanks(struct drm_device
*dev
,
11966 struct drm_i915_private
*dev_priv
,
11967 unsigned crtc_mask
)
11969 unsigned last_vblank_count
[I915_MAX_PIPES
];
11976 for_each_pipe(dev_priv
, pipe
) {
11977 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
,
11980 if (!((1 << pipe
) & crtc_mask
))
11983 ret
= drm_crtc_vblank_get(&crtc
->base
);
11984 if (WARN_ON(ret
!= 0)) {
11985 crtc_mask
&= ~(1 << pipe
);
11989 last_vblank_count
[pipe
] = drm_crtc_vblank_count(&crtc
->base
);
11992 for_each_pipe(dev_priv
, pipe
) {
11993 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
,
11997 if (!((1 << pipe
) & crtc_mask
))
12000 lret
= wait_event_timeout(dev
->vblank
[pipe
].queue
,
12001 last_vblank_count
[pipe
] !=
12002 drm_crtc_vblank_count(&crtc
->base
),
12003 msecs_to_jiffies(50));
12005 WARN(!lret
, "pipe %c vblank wait timed out\n", pipe_name(pipe
));
12007 drm_crtc_vblank_put(&crtc
->base
);
12011 static bool needs_vblank_wait(struct intel_crtc_state
*crtc_state
)
12013 /* fb updated, need to unpin old fb */
12014 if (crtc_state
->fb_changed
)
12017 /* wm changes, need vblank before final wm's */
12018 if (crtc_state
->update_wm_post
)
12021 if (crtc_state
->wm
.need_postvbl_update
)
12027 static void intel_update_crtc(struct drm_crtc
*crtc
,
12028 struct drm_atomic_state
*state
,
12029 struct drm_crtc_state
*old_crtc_state
,
12030 struct drm_crtc_state
*new_crtc_state
,
12031 unsigned int *crtc_vblank_mask
)
12033 struct drm_device
*dev
= crtc
->dev
;
12034 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12035 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12036 struct intel_crtc_state
*pipe_config
= to_intel_crtc_state(new_crtc_state
);
12037 bool modeset
= needs_modeset(new_crtc_state
);
12040 update_scanline_offset(intel_crtc
);
12041 dev_priv
->display
.crtc_enable(pipe_config
, state
);
12043 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
),
12047 if (drm_atomic_get_existing_plane_state(state
, crtc
->primary
)) {
12049 intel_crtc
, pipe_config
,
12050 to_intel_plane_state(crtc
->primary
->state
));
12053 drm_atomic_helper_commit_planes_on_crtc(old_crtc_state
);
12055 if (needs_vblank_wait(pipe_config
))
12056 *crtc_vblank_mask
|= drm_crtc_mask(crtc
);
12059 static void intel_update_crtcs(struct drm_atomic_state
*state
,
12060 unsigned int *crtc_vblank_mask
)
12062 struct drm_crtc
*crtc
;
12063 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
12066 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12067 if (!new_crtc_state
->active
)
12070 intel_update_crtc(crtc
, state
, old_crtc_state
,
12071 new_crtc_state
, crtc_vblank_mask
);
12075 static void skl_update_crtcs(struct drm_atomic_state
*state
,
12076 unsigned int *crtc_vblank_mask
)
12078 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
12079 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12080 struct drm_crtc
*crtc
;
12081 struct intel_crtc
*intel_crtc
;
12082 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
12083 struct intel_crtc_state
*cstate
;
12084 unsigned int updated
= 0;
12089 const struct skl_ddb_entry
*entries
[I915_MAX_PIPES
] = {};
12091 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
)
12092 /* ignore allocations for crtc's that have been turned off. */
12093 if (new_crtc_state
->active
)
12094 entries
[i
] = &to_intel_crtc_state(old_crtc_state
)->wm
.skl
.ddb
;
12097 * Whenever the number of active pipes changes, we need to make sure we
12098 * update the pipes in the right order so that their ddb allocations
12099 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
12100 * cause pipe underruns and other bad stuff.
12105 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12106 bool vbl_wait
= false;
12107 unsigned int cmask
= drm_crtc_mask(crtc
);
12109 intel_crtc
= to_intel_crtc(crtc
);
12110 cstate
= to_intel_crtc_state(crtc
->state
);
12111 pipe
= intel_crtc
->pipe
;
12113 if (updated
& cmask
|| !cstate
->base
.active
)
12116 if (skl_ddb_allocation_overlaps(entries
, &cstate
->wm
.skl
.ddb
, i
))
12120 entries
[i
] = &cstate
->wm
.skl
.ddb
;
12123 * If this is an already active pipe, it's DDB changed,
12124 * and this isn't the last pipe that needs updating
12125 * then we need to wait for a vblank to pass for the
12126 * new ddb allocation to take effect.
12128 if (!skl_ddb_entry_equal(&cstate
->wm
.skl
.ddb
,
12129 &to_intel_crtc_state(old_crtc_state
)->wm
.skl
.ddb
) &&
12130 !new_crtc_state
->active_changed
&&
12131 intel_state
->wm_results
.dirty_pipes
!= updated
)
12134 intel_update_crtc(crtc
, state
, old_crtc_state
,
12135 new_crtc_state
, crtc_vblank_mask
);
12138 intel_wait_for_vblank(dev_priv
, pipe
);
12142 } while (progress
);
12145 static void intel_atomic_helper_free_state(struct drm_i915_private
*dev_priv
)
12147 struct intel_atomic_state
*state
, *next
;
12148 struct llist_node
*freed
;
12150 freed
= llist_del_all(&dev_priv
->atomic_helper
.free_list
);
12151 llist_for_each_entry_safe(state
, next
, freed
, freed
)
12152 drm_atomic_state_put(&state
->base
);
12155 static void intel_atomic_helper_free_state_worker(struct work_struct
*work
)
12157 struct drm_i915_private
*dev_priv
=
12158 container_of(work
, typeof(*dev_priv
), atomic_helper
.free_work
);
12160 intel_atomic_helper_free_state(dev_priv
);
12163 static void intel_atomic_commit_tail(struct drm_atomic_state
*state
)
12165 struct drm_device
*dev
= state
->dev
;
12166 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12167 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12168 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
12169 struct drm_crtc
*crtc
;
12170 struct intel_crtc_state
*intel_cstate
;
12171 bool hw_check
= intel_state
->modeset
;
12172 u64 put_domains
[I915_MAX_PIPES
] = {};
12173 unsigned crtc_vblank_mask
= 0;
12176 drm_atomic_helper_wait_for_dependencies(state
);
12178 if (intel_state
->modeset
)
12179 intel_display_power_get(dev_priv
, POWER_DOMAIN_MODESET
);
12181 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12182 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12184 if (needs_modeset(new_crtc_state
) ||
12185 to_intel_crtc_state(new_crtc_state
)->update_pipe
) {
12188 put_domains
[to_intel_crtc(crtc
)->pipe
] =
12189 modeset_get_crtc_power_domains(crtc
,
12190 to_intel_crtc_state(new_crtc_state
));
12193 if (!needs_modeset(new_crtc_state
))
12196 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
),
12197 to_intel_crtc_state(new_crtc_state
));
12199 if (old_crtc_state
->active
) {
12200 intel_crtc_disable_planes(crtc
, old_crtc_state
->plane_mask
);
12201 dev_priv
->display
.crtc_disable(to_intel_crtc_state(old_crtc_state
), state
);
12202 intel_crtc
->active
= false;
12203 intel_fbc_disable(intel_crtc
);
12204 intel_disable_shared_dpll(intel_crtc
);
12207 * Underruns don't always raise
12208 * interrupts, so check manually.
12210 intel_check_cpu_fifo_underruns(dev_priv
);
12211 intel_check_pch_fifo_underruns(dev_priv
);
12213 if (!crtc
->state
->active
) {
12215 * Make sure we don't call initial_watermarks
12216 * for ILK-style watermark updates.
12218 * No clue what this is supposed to achieve.
12220 if (INTEL_GEN(dev_priv
) >= 9)
12221 dev_priv
->display
.initial_watermarks(intel_state
,
12222 to_intel_crtc_state(crtc
->state
));
12227 /* Only after disabling all output pipelines that will be changed can we
12228 * update the the output configuration. */
12229 intel_modeset_update_crtc_state(state
);
12231 if (intel_state
->modeset
) {
12232 drm_atomic_helper_update_legacy_modeset_state(state
->dev
, state
);
12234 intel_set_cdclk(dev_priv
, &dev_priv
->cdclk
.actual
);
12237 * SKL workaround: bspec recommends we disable the SAGV when we
12238 * have more then one pipe enabled
12240 if (!intel_can_enable_sagv(state
))
12241 intel_disable_sagv(dev_priv
);
12243 intel_modeset_verify_disabled(dev
, state
);
12246 /* Complete the events for pipes that have now been disabled */
12247 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
12248 bool modeset
= needs_modeset(new_crtc_state
);
12250 /* Complete events for now disable pipes here. */
12251 if (modeset
&& !new_crtc_state
->active
&& new_crtc_state
->event
) {
12252 spin_lock_irq(&dev
->event_lock
);
12253 drm_crtc_send_vblank_event(crtc
, new_crtc_state
->event
);
12254 spin_unlock_irq(&dev
->event_lock
);
12256 new_crtc_state
->event
= NULL
;
12260 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
12261 dev_priv
->display
.update_crtcs(state
, &crtc_vblank_mask
);
12263 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
12264 * already, but still need the state for the delayed optimization. To
12266 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
12267 * - schedule that vblank worker _before_ calling hw_done
12268 * - at the start of commit_tail, cancel it _synchrously
12269 * - switch over to the vblank wait helper in the core after that since
12270 * we don't need out special handling any more.
12272 if (!state
->legacy_cursor_update
)
12273 intel_atomic_wait_for_vblanks(dev
, dev_priv
, crtc_vblank_mask
);
12276 * Now that the vblank has passed, we can go ahead and program the
12277 * optimal watermarks on platforms that need two-step watermark
12280 * TODO: Move this (and other cleanup) to an async worker eventually.
12282 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
12283 intel_cstate
= to_intel_crtc_state(new_crtc_state
);
12285 if (dev_priv
->display
.optimize_watermarks
)
12286 dev_priv
->display
.optimize_watermarks(intel_state
,
12290 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12291 intel_post_plane_update(to_intel_crtc_state(old_crtc_state
));
12293 if (put_domains
[i
])
12294 modeset_put_power_domains(dev_priv
, put_domains
[i
]);
12296 intel_modeset_verify_crtc(crtc
, state
, old_crtc_state
, new_crtc_state
);
12299 if (intel_state
->modeset
&& intel_can_enable_sagv(state
))
12300 intel_enable_sagv(dev_priv
);
12302 drm_atomic_helper_commit_hw_done(state
);
12304 if (intel_state
->modeset
) {
12305 /* As one of the primary mmio accessors, KMS has a high
12306 * likelihood of triggering bugs in unclaimed access. After we
12307 * finish modesetting, see if an error has been flagged, and if
12308 * so enable debugging for the next modeset - and hope we catch
12311 intel_uncore_arm_unclaimed_mmio_detection(dev_priv
);
12312 intel_display_power_put(dev_priv
, POWER_DOMAIN_MODESET
);
12315 mutex_lock(&dev
->struct_mutex
);
12316 drm_atomic_helper_cleanup_planes(dev
, state
);
12317 mutex_unlock(&dev
->struct_mutex
);
12319 drm_atomic_helper_commit_cleanup_done(state
);
12321 drm_atomic_state_put(state
);
12323 intel_atomic_helper_free_state(dev_priv
);
12326 static void intel_atomic_commit_work(struct work_struct
*work
)
12328 struct drm_atomic_state
*state
=
12329 container_of(work
, struct drm_atomic_state
, commit_work
);
12331 intel_atomic_commit_tail(state
);
12334 static int __i915_sw_fence_call
12335 intel_atomic_commit_ready(struct i915_sw_fence
*fence
,
12336 enum i915_sw_fence_notify notify
)
12338 struct intel_atomic_state
*state
=
12339 container_of(fence
, struct intel_atomic_state
, commit_ready
);
12342 case FENCE_COMPLETE
:
12343 if (state
->base
.commit_work
.func
)
12344 queue_work(system_unbound_wq
, &state
->base
.commit_work
);
12349 struct intel_atomic_helper
*helper
=
12350 &to_i915(state
->base
.dev
)->atomic_helper
;
12352 if (llist_add(&state
->freed
, &helper
->free_list
))
12353 schedule_work(&helper
->free_work
);
12358 return NOTIFY_DONE
;
12361 static void intel_atomic_track_fbs(struct drm_atomic_state
*state
)
12363 struct drm_plane_state
*old_plane_state
, *new_plane_state
;
12364 struct drm_plane
*plane
;
12367 for_each_oldnew_plane_in_state(state
, plane
, old_plane_state
, new_plane_state
, i
)
12368 i915_gem_track_fb(intel_fb_obj(old_plane_state
->fb
),
12369 intel_fb_obj(new_plane_state
->fb
),
12370 to_intel_plane(plane
)->frontbuffer_bit
);
12374 * intel_atomic_commit - commit validated state object
12376 * @state: the top-level driver state object
12377 * @nonblock: nonblocking commit
12379 * This function commits a top-level state object that has been validated
12380 * with drm_atomic_helper_check().
12383 * Zero for success or -errno.
12385 static int intel_atomic_commit(struct drm_device
*dev
,
12386 struct drm_atomic_state
*state
,
12389 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12390 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12393 ret
= drm_atomic_helper_setup_commit(state
, nonblock
);
12397 drm_atomic_state_get(state
);
12398 i915_sw_fence_init(&intel_state
->commit_ready
,
12399 intel_atomic_commit_ready
);
12401 ret
= intel_atomic_prepare_commit(dev
, state
);
12403 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret
);
12404 i915_sw_fence_commit(&intel_state
->commit_ready
);
12409 * The intel_legacy_cursor_update() fast path takes care
12410 * of avoiding the vblank waits for simple cursor
12411 * movement and flips. For cursor on/off and size changes,
12412 * we want to perform the vblank waits so that watermark
12413 * updates happen during the correct frames. Gen9+ have
12414 * double buffered watermarks and so shouldn't need this.
12416 * Do this after drm_atomic_helper_setup_commit() and
12417 * intel_atomic_prepare_commit() because we still want
12418 * to skip the flip and fb cleanup waits. Although that
12419 * does risk yanking the mapping from under the display
12422 * FIXME doing watermarks and fb cleanup from a vblank worker
12423 * (assuming we had any) would solve these problems.
12425 if (INTEL_GEN(dev_priv
) < 9)
12426 state
->legacy_cursor_update
= false;
12428 drm_atomic_helper_swap_state(state
, true);
12429 dev_priv
->wm
.distrust_bios_wm
= false;
12430 intel_shared_dpll_swap_state(state
);
12431 intel_atomic_track_fbs(state
);
12433 if (intel_state
->modeset
) {
12434 memcpy(dev_priv
->min_pixclk
, intel_state
->min_pixclk
,
12435 sizeof(intel_state
->min_pixclk
));
12436 dev_priv
->active_crtcs
= intel_state
->active_crtcs
;
12437 dev_priv
->cdclk
.logical
= intel_state
->cdclk
.logical
;
12438 dev_priv
->cdclk
.actual
= intel_state
->cdclk
.actual
;
12441 drm_atomic_state_get(state
);
12442 INIT_WORK(&state
->commit_work
,
12443 nonblock
? intel_atomic_commit_work
: NULL
);
12445 i915_sw_fence_commit(&intel_state
->commit_ready
);
12447 i915_sw_fence_wait(&intel_state
->commit_ready
);
12448 intel_atomic_commit_tail(state
);
12454 static const struct drm_crtc_funcs intel_crtc_funcs
= {
12455 .gamma_set
= drm_atomic_helper_legacy_gamma_set
,
12456 .set_config
= drm_atomic_helper_set_config
,
12457 .set_property
= drm_atomic_helper_crtc_set_property
,
12458 .destroy
= intel_crtc_destroy
,
12459 .page_flip
= drm_atomic_helper_page_flip
,
12460 .atomic_duplicate_state
= intel_crtc_duplicate_state
,
12461 .atomic_destroy_state
= intel_crtc_destroy_state
,
12462 .set_crc_source
= intel_crtc_set_crc_source
,
12466 * intel_prepare_plane_fb - Prepare fb for usage on plane
12467 * @plane: drm plane to prepare for
12468 * @fb: framebuffer to prepare for presentation
12470 * Prepares a framebuffer for usage on a display plane. Generally this
12471 * involves pinning the underlying object and updating the frontbuffer tracking
12472 * bits. Some older platforms need special physical address handling for
12475 * Must be called with struct_mutex held.
12477 * Returns 0 on success, negative error code on failure.
12480 intel_prepare_plane_fb(struct drm_plane
*plane
,
12481 struct drm_plane_state
*new_state
)
12483 struct intel_atomic_state
*intel_state
=
12484 to_intel_atomic_state(new_state
->state
);
12485 struct drm_i915_private
*dev_priv
= to_i915(plane
->dev
);
12486 struct drm_framebuffer
*fb
= new_state
->fb
;
12487 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
12488 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->state
->fb
);
12492 if (plane
->type
== DRM_PLANE_TYPE_CURSOR
&&
12493 INTEL_INFO(dev_priv
)->cursor_needs_physical
) {
12494 const int align
= intel_cursor_alignment(dev_priv
);
12496 ret
= i915_gem_object_attach_phys(obj
, align
);
12498 DRM_DEBUG_KMS("failed to attach phys object\n");
12502 struct i915_vma
*vma
;
12504 vma
= intel_pin_and_fence_fb_obj(fb
, new_state
->rotation
);
12506 DRM_DEBUG_KMS("failed to pin object\n");
12507 return PTR_ERR(vma
);
12510 to_intel_plane_state(new_state
)->vma
= vma
;
12514 if (!obj
&& !old_obj
)
12518 struct drm_crtc_state
*crtc_state
=
12519 drm_atomic_get_existing_crtc_state(new_state
->state
,
12520 plane
->state
->crtc
);
12522 /* Big Hammer, we also need to ensure that any pending
12523 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
12524 * current scanout is retired before unpinning the old
12525 * framebuffer. Note that we rely on userspace rendering
12526 * into the buffer attached to the pipe they are waiting
12527 * on. If not, userspace generates a GPU hang with IPEHR
12528 * point to the MI_WAIT_FOR_EVENT.
12530 * This should only fail upon a hung GPU, in which case we
12531 * can safely continue.
12533 if (needs_modeset(crtc_state
)) {
12534 ret
= i915_sw_fence_await_reservation(&intel_state
->commit_ready
,
12535 old_obj
->resv
, NULL
,
12543 if (new_state
->fence
) { /* explicit fencing */
12544 ret
= i915_sw_fence_await_dma_fence(&intel_state
->commit_ready
,
12546 I915_FENCE_TIMEOUT
,
12555 if (!new_state
->fence
) { /* implicit fencing */
12556 ret
= i915_sw_fence_await_reservation(&intel_state
->commit_ready
,
12558 false, I915_FENCE_TIMEOUT
,
12563 i915_gem_object_wait_priority(obj
, 0, I915_PRIORITY_DISPLAY
);
12570 * intel_cleanup_plane_fb - Cleans up an fb after plane use
12571 * @plane: drm plane to clean up for
12572 * @fb: old framebuffer that was on plane
12574 * Cleans up a framebuffer that has just been removed from a plane.
12576 * Must be called with struct_mutex held.
12579 intel_cleanup_plane_fb(struct drm_plane
*plane
,
12580 struct drm_plane_state
*old_state
)
12582 struct i915_vma
*vma
;
12584 /* Should only be called after a successful intel_prepare_plane_fb()! */
12585 vma
= fetch_and_zero(&to_intel_plane_state(old_state
)->vma
);
12587 intel_unpin_fb_vma(vma
);
12591 skl_max_scale(struct intel_crtc
*intel_crtc
, struct intel_crtc_state
*crtc_state
)
12593 struct drm_i915_private
*dev_priv
;
12595 int crtc_clock
, max_dotclk
;
12597 if (!intel_crtc
|| !crtc_state
->base
.enable
)
12598 return DRM_PLANE_HELPER_NO_SCALING
;
12600 dev_priv
= to_i915(intel_crtc
->base
.dev
);
12602 crtc_clock
= crtc_state
->base
.adjusted_mode
.crtc_clock
;
12603 max_dotclk
= to_intel_atomic_state(crtc_state
->base
.state
)->cdclk
.logical
.cdclk
;
12605 if (IS_GEMINILAKE(dev_priv
))
12608 if (WARN_ON_ONCE(!crtc_clock
|| max_dotclk
< crtc_clock
))
12609 return DRM_PLANE_HELPER_NO_SCALING
;
12612 * skl max scale is lower of:
12613 * close to 3 but not 3, -1 is for that purpose
12617 max_scale
= min((1 << 16) * 3 - 1,
12618 (1 << 8) * ((max_dotclk
<< 8) / crtc_clock
));
12624 intel_check_primary_plane(struct intel_plane
*plane
,
12625 struct intel_crtc_state
*crtc_state
,
12626 struct intel_plane_state
*state
)
12628 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
12629 struct drm_crtc
*crtc
= state
->base
.crtc
;
12630 int min_scale
= DRM_PLANE_HELPER_NO_SCALING
;
12631 int max_scale
= DRM_PLANE_HELPER_NO_SCALING
;
12632 bool can_position
= false;
12635 if (INTEL_GEN(dev_priv
) >= 9) {
12636 /* use scaler when colorkey is not required */
12637 if (state
->ckey
.flags
== I915_SET_COLORKEY_NONE
) {
12639 max_scale
= skl_max_scale(to_intel_crtc(crtc
), crtc_state
);
12641 can_position
= true;
12644 ret
= drm_plane_helper_check_state(&state
->base
,
12646 min_scale
, max_scale
,
12647 can_position
, true);
12651 if (!state
->base
.fb
)
12654 if (INTEL_GEN(dev_priv
) >= 9) {
12655 ret
= skl_check_plane_surface(state
);
12659 state
->ctl
= skl_plane_ctl(crtc_state
, state
);
12661 ret
= i9xx_check_plane_surface(state
);
12665 state
->ctl
= i9xx_plane_ctl(crtc_state
, state
);
12671 static void intel_begin_crtc_commit(struct drm_crtc
*crtc
,
12672 struct drm_crtc_state
*old_crtc_state
)
12674 struct drm_device
*dev
= crtc
->dev
;
12675 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12676 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12677 struct intel_crtc_state
*intel_cstate
=
12678 to_intel_crtc_state(crtc
->state
);
12679 struct intel_crtc_state
*old_intel_cstate
=
12680 to_intel_crtc_state(old_crtc_state
);
12681 struct intel_atomic_state
*old_intel_state
=
12682 to_intel_atomic_state(old_crtc_state
->state
);
12683 bool modeset
= needs_modeset(crtc
->state
);
12686 (intel_cstate
->base
.color_mgmt_changed
||
12687 intel_cstate
->update_pipe
)) {
12688 intel_color_set_csc(crtc
->state
);
12689 intel_color_load_luts(crtc
->state
);
12692 /* Perform vblank evasion around commit operation */
12693 intel_pipe_update_start(intel_crtc
);
12698 if (intel_cstate
->update_pipe
)
12699 intel_update_pipe_config(intel_crtc
, old_intel_cstate
);
12700 else if (INTEL_GEN(dev_priv
) >= 9)
12701 skl_detach_scalers(intel_crtc
);
12704 if (dev_priv
->display
.atomic_update_watermarks
)
12705 dev_priv
->display
.atomic_update_watermarks(old_intel_state
,
12709 static void intel_finish_crtc_commit(struct drm_crtc
*crtc
,
12710 struct drm_crtc_state
*old_crtc_state
)
12712 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12714 intel_pipe_update_end(intel_crtc
, NULL
);
12718 * intel_plane_destroy - destroy a plane
12719 * @plane: plane to destroy
12721 * Common destruction function for all types of planes (primary, cursor,
12724 void intel_plane_destroy(struct drm_plane
*plane
)
12726 drm_plane_cleanup(plane
);
12727 kfree(to_intel_plane(plane
));
12730 const struct drm_plane_funcs intel_plane_funcs
= {
12731 .update_plane
= drm_atomic_helper_update_plane
,
12732 .disable_plane
= drm_atomic_helper_disable_plane
,
12733 .destroy
= intel_plane_destroy
,
12734 .set_property
= drm_atomic_helper_plane_set_property
,
12735 .atomic_get_property
= intel_plane_atomic_get_property
,
12736 .atomic_set_property
= intel_plane_atomic_set_property
,
12737 .atomic_duplicate_state
= intel_plane_duplicate_state
,
12738 .atomic_destroy_state
= intel_plane_destroy_state
,
12742 intel_legacy_cursor_update(struct drm_plane
*plane
,
12743 struct drm_crtc
*crtc
,
12744 struct drm_framebuffer
*fb
,
12745 int crtc_x
, int crtc_y
,
12746 unsigned int crtc_w
, unsigned int crtc_h
,
12747 uint32_t src_x
, uint32_t src_y
,
12748 uint32_t src_w
, uint32_t src_h
,
12749 struct drm_modeset_acquire_ctx
*ctx
)
12751 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
12753 struct drm_plane_state
*old_plane_state
, *new_plane_state
;
12754 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
12755 struct drm_framebuffer
*old_fb
;
12756 struct drm_crtc_state
*crtc_state
= crtc
->state
;
12757 struct i915_vma
*old_vma
;
12760 * When crtc is inactive or there is a modeset pending,
12761 * wait for it to complete in the slowpath
12763 if (!crtc_state
->active
|| needs_modeset(crtc_state
) ||
12764 to_intel_crtc_state(crtc_state
)->update_pipe
)
12767 old_plane_state
= plane
->state
;
12770 * If any parameters change that may affect watermarks,
12771 * take the slowpath. Only changing fb or position should be
12774 if (old_plane_state
->crtc
!= crtc
||
12775 old_plane_state
->src_w
!= src_w
||
12776 old_plane_state
->src_h
!= src_h
||
12777 old_plane_state
->crtc_w
!= crtc_w
||
12778 old_plane_state
->crtc_h
!= crtc_h
||
12779 !old_plane_state
->fb
!= !fb
)
12782 new_plane_state
= intel_plane_duplicate_state(plane
);
12783 if (!new_plane_state
)
12786 drm_atomic_set_fb_for_plane(new_plane_state
, fb
);
12788 new_plane_state
->src_x
= src_x
;
12789 new_plane_state
->src_y
= src_y
;
12790 new_plane_state
->src_w
= src_w
;
12791 new_plane_state
->src_h
= src_h
;
12792 new_plane_state
->crtc_x
= crtc_x
;
12793 new_plane_state
->crtc_y
= crtc_y
;
12794 new_plane_state
->crtc_w
= crtc_w
;
12795 new_plane_state
->crtc_h
= crtc_h
;
12797 ret
= intel_plane_atomic_check_with_state(to_intel_crtc_state(crtc
->state
),
12798 to_intel_plane_state(new_plane_state
));
12802 ret
= mutex_lock_interruptible(&dev_priv
->drm
.struct_mutex
);
12806 if (INTEL_INFO(dev_priv
)->cursor_needs_physical
) {
12807 int align
= intel_cursor_alignment(dev_priv
);
12809 ret
= i915_gem_object_attach_phys(intel_fb_obj(fb
), align
);
12811 DRM_DEBUG_KMS("failed to attach phys object\n");
12815 struct i915_vma
*vma
;
12817 vma
= intel_pin_and_fence_fb_obj(fb
, new_plane_state
->rotation
);
12819 DRM_DEBUG_KMS("failed to pin object\n");
12821 ret
= PTR_ERR(vma
);
12825 to_intel_plane_state(new_plane_state
)->vma
= vma
;
12828 old_fb
= old_plane_state
->fb
;
12829 old_vma
= to_intel_plane_state(old_plane_state
)->vma
;
12831 i915_gem_track_fb(intel_fb_obj(old_fb
), intel_fb_obj(fb
),
12832 intel_plane
->frontbuffer_bit
);
12834 /* Swap plane state */
12835 new_plane_state
->fence
= old_plane_state
->fence
;
12836 *to_intel_plane_state(old_plane_state
) = *to_intel_plane_state(new_plane_state
);
12837 new_plane_state
->fence
= NULL
;
12838 new_plane_state
->fb
= old_fb
;
12839 to_intel_plane_state(new_plane_state
)->vma
= old_vma
;
12841 if (plane
->state
->visible
) {
12842 trace_intel_update_plane(plane
, to_intel_crtc(crtc
));
12843 intel_plane
->update_plane(intel_plane
,
12844 to_intel_crtc_state(crtc
->state
),
12845 to_intel_plane_state(plane
->state
));
12847 trace_intel_disable_plane(plane
, to_intel_crtc(crtc
));
12848 intel_plane
->disable_plane(intel_plane
, to_intel_crtc(crtc
));
12851 intel_cleanup_plane_fb(plane
, new_plane_state
);
12854 mutex_unlock(&dev_priv
->drm
.struct_mutex
);
12856 intel_plane_destroy_state(plane
, new_plane_state
);
12860 return drm_atomic_helper_update_plane(plane
, crtc
, fb
,
12861 crtc_x
, crtc_y
, crtc_w
, crtc_h
,
12862 src_x
, src_y
, src_w
, src_h
, ctx
);
12865 static const struct drm_plane_funcs intel_cursor_plane_funcs
= {
12866 .update_plane
= intel_legacy_cursor_update
,
12867 .disable_plane
= drm_atomic_helper_disable_plane
,
12868 .destroy
= intel_plane_destroy
,
12869 .set_property
= drm_atomic_helper_plane_set_property
,
12870 .atomic_get_property
= intel_plane_atomic_get_property
,
12871 .atomic_set_property
= intel_plane_atomic_set_property
,
12872 .atomic_duplicate_state
= intel_plane_duplicate_state
,
12873 .atomic_destroy_state
= intel_plane_destroy_state
,
12876 static struct intel_plane
*
12877 intel_primary_plane_create(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
12879 struct intel_plane
*primary
= NULL
;
12880 struct intel_plane_state
*state
= NULL
;
12881 const uint32_t *intel_primary_formats
;
12882 unsigned int supported_rotations
;
12883 unsigned int num_formats
;
12886 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
12892 state
= intel_create_plane_state(&primary
->base
);
12898 primary
->base
.state
= &state
->base
;
12900 primary
->can_scale
= false;
12901 primary
->max_downscale
= 1;
12902 if (INTEL_GEN(dev_priv
) >= 9) {
12903 primary
->can_scale
= true;
12904 state
->scaler_id
= -1;
12906 primary
->pipe
= pipe
;
12908 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
12909 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
12911 if (HAS_FBC(dev_priv
) && INTEL_GEN(dev_priv
) < 4)
12912 primary
->plane
= (enum plane
) !pipe
;
12914 primary
->plane
= (enum plane
) pipe
;
12915 primary
->id
= PLANE_PRIMARY
;
12916 primary
->frontbuffer_bit
= INTEL_FRONTBUFFER_PRIMARY(pipe
);
12917 primary
->check_plane
= intel_check_primary_plane
;
12919 if (INTEL_GEN(dev_priv
) >= 9) {
12920 intel_primary_formats
= skl_primary_formats
;
12921 num_formats
= ARRAY_SIZE(skl_primary_formats
);
12923 primary
->update_plane
= skylake_update_primary_plane
;
12924 primary
->disable_plane
= skylake_disable_primary_plane
;
12925 } else if (INTEL_GEN(dev_priv
) >= 4) {
12926 intel_primary_formats
= i965_primary_formats
;
12927 num_formats
= ARRAY_SIZE(i965_primary_formats
);
12929 primary
->update_plane
= i9xx_update_primary_plane
;
12930 primary
->disable_plane
= i9xx_disable_primary_plane
;
12932 intel_primary_formats
= i8xx_primary_formats
;
12933 num_formats
= ARRAY_SIZE(i8xx_primary_formats
);
12935 primary
->update_plane
= i9xx_update_primary_plane
;
12936 primary
->disable_plane
= i9xx_disable_primary_plane
;
12939 if (INTEL_GEN(dev_priv
) >= 9)
12940 ret
= drm_universal_plane_init(&dev_priv
->drm
, &primary
->base
,
12941 0, &intel_plane_funcs
,
12942 intel_primary_formats
, num_formats
,
12943 DRM_PLANE_TYPE_PRIMARY
,
12944 "plane 1%c", pipe_name(pipe
));
12945 else if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
))
12946 ret
= drm_universal_plane_init(&dev_priv
->drm
, &primary
->base
,
12947 0, &intel_plane_funcs
,
12948 intel_primary_formats
, num_formats
,
12949 DRM_PLANE_TYPE_PRIMARY
,
12950 "primary %c", pipe_name(pipe
));
12952 ret
= drm_universal_plane_init(&dev_priv
->drm
, &primary
->base
,
12953 0, &intel_plane_funcs
,
12954 intel_primary_formats
, num_formats
,
12955 DRM_PLANE_TYPE_PRIMARY
,
12956 "plane %c", plane_name(primary
->plane
));
12960 if (INTEL_GEN(dev_priv
) >= 9) {
12961 supported_rotations
=
12962 DRM_MODE_ROTATE_0
| DRM_MODE_ROTATE_90
|
12963 DRM_MODE_ROTATE_180
| DRM_MODE_ROTATE_270
;
12964 } else if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_B
) {
12965 supported_rotations
=
12966 DRM_MODE_ROTATE_0
| DRM_MODE_ROTATE_180
|
12967 DRM_MODE_REFLECT_X
;
12968 } else if (INTEL_GEN(dev_priv
) >= 4) {
12969 supported_rotations
=
12970 DRM_MODE_ROTATE_0
| DRM_MODE_ROTATE_180
;
12972 supported_rotations
= DRM_MODE_ROTATE_0
;
12975 if (INTEL_GEN(dev_priv
) >= 4)
12976 drm_plane_create_rotation_property(&primary
->base
,
12978 supported_rotations
);
12980 drm_plane_helper_add(&primary
->base
, &intel_plane_helper_funcs
);
12988 return ERR_PTR(ret
);
12991 static struct intel_plane
*
12992 intel_cursor_plane_create(struct drm_i915_private
*dev_priv
,
12995 struct intel_plane
*cursor
= NULL
;
12996 struct intel_plane_state
*state
= NULL
;
12999 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
13005 state
= intel_create_plane_state(&cursor
->base
);
13011 cursor
->base
.state
= &state
->base
;
13013 cursor
->can_scale
= false;
13014 cursor
->max_downscale
= 1;
13015 cursor
->pipe
= pipe
;
13016 cursor
->plane
= pipe
;
13017 cursor
->id
= PLANE_CURSOR
;
13018 cursor
->frontbuffer_bit
= INTEL_FRONTBUFFER_CURSOR(pipe
);
13020 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
)) {
13021 cursor
->update_plane
= i845_update_cursor
;
13022 cursor
->disable_plane
= i845_disable_cursor
;
13023 cursor
->check_plane
= i845_check_cursor
;
13025 cursor
->update_plane
= i9xx_update_cursor
;
13026 cursor
->disable_plane
= i9xx_disable_cursor
;
13027 cursor
->check_plane
= i9xx_check_cursor
;
13030 cursor
->cursor
.base
= ~0;
13031 cursor
->cursor
.cntl
= ~0;
13033 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
) || HAS_CUR_FBC(dev_priv
))
13034 cursor
->cursor
.size
= ~0;
13036 ret
= drm_universal_plane_init(&dev_priv
->drm
, &cursor
->base
,
13037 0, &intel_cursor_plane_funcs
,
13038 intel_cursor_formats
,
13039 ARRAY_SIZE(intel_cursor_formats
),
13040 DRM_PLANE_TYPE_CURSOR
,
13041 "cursor %c", pipe_name(pipe
));
13045 if (INTEL_GEN(dev_priv
) >= 4)
13046 drm_plane_create_rotation_property(&cursor
->base
,
13048 DRM_MODE_ROTATE_0
|
13049 DRM_MODE_ROTATE_180
);
13051 if (INTEL_GEN(dev_priv
) >= 9)
13052 state
->scaler_id
= -1;
13054 drm_plane_helper_add(&cursor
->base
, &intel_plane_helper_funcs
);
13062 return ERR_PTR(ret
);
13065 static void intel_crtc_init_scalers(struct intel_crtc
*crtc
,
13066 struct intel_crtc_state
*crtc_state
)
13068 struct intel_crtc_scaler_state
*scaler_state
=
13069 &crtc_state
->scaler_state
;
13070 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
13073 crtc
->num_scalers
= dev_priv
->info
.num_scalers
[crtc
->pipe
];
13074 if (!crtc
->num_scalers
)
13077 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
13078 struct intel_scaler
*scaler
= &scaler_state
->scalers
[i
];
13080 scaler
->in_use
= 0;
13081 scaler
->mode
= PS_SCALER_MODE_DYN
;
13084 scaler_state
->scaler_id
= -1;
13087 static int intel_crtc_init(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
13089 struct intel_crtc
*intel_crtc
;
13090 struct intel_crtc_state
*crtc_state
= NULL
;
13091 struct intel_plane
*primary
= NULL
;
13092 struct intel_plane
*cursor
= NULL
;
13095 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
13099 crtc_state
= kzalloc(sizeof(*crtc_state
), GFP_KERNEL
);
13104 intel_crtc
->config
= crtc_state
;
13105 intel_crtc
->base
.state
= &crtc_state
->base
;
13106 crtc_state
->base
.crtc
= &intel_crtc
->base
;
13108 primary
= intel_primary_plane_create(dev_priv
, pipe
);
13109 if (IS_ERR(primary
)) {
13110 ret
= PTR_ERR(primary
);
13113 intel_crtc
->plane_ids_mask
|= BIT(primary
->id
);
13115 for_each_sprite(dev_priv
, pipe
, sprite
) {
13116 struct intel_plane
*plane
;
13118 plane
= intel_sprite_plane_create(dev_priv
, pipe
, sprite
);
13119 if (IS_ERR(plane
)) {
13120 ret
= PTR_ERR(plane
);
13123 intel_crtc
->plane_ids_mask
|= BIT(plane
->id
);
13126 cursor
= intel_cursor_plane_create(dev_priv
, pipe
);
13127 if (IS_ERR(cursor
)) {
13128 ret
= PTR_ERR(cursor
);
13131 intel_crtc
->plane_ids_mask
|= BIT(cursor
->id
);
13133 ret
= drm_crtc_init_with_planes(&dev_priv
->drm
, &intel_crtc
->base
,
13134 &primary
->base
, &cursor
->base
,
13136 "pipe %c", pipe_name(pipe
));
13140 intel_crtc
->pipe
= pipe
;
13141 intel_crtc
->plane
= primary
->plane
;
13143 /* initialize shared scalers */
13144 intel_crtc_init_scalers(intel_crtc
, crtc_state
);
13146 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
13147 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
13148 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = intel_crtc
;
13149 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = intel_crtc
;
13151 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
13153 intel_color_init(&intel_crtc
->base
);
13155 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
13161 * drm_mode_config_cleanup() will free up any
13162 * crtcs/planes already initialized.
13170 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
13172 struct drm_device
*dev
= connector
->base
.dev
;
13174 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
13176 if (!connector
->base
.state
->crtc
)
13177 return INVALID_PIPE
;
13179 return to_intel_crtc(connector
->base
.state
->crtc
)->pipe
;
13182 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
13183 struct drm_file
*file
)
13185 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
13186 struct drm_crtc
*drmmode_crtc
;
13187 struct intel_crtc
*crtc
;
13189 drmmode_crtc
= drm_crtc_find(dev
, pipe_from_crtc_id
->crtc_id
);
13193 crtc
= to_intel_crtc(drmmode_crtc
);
13194 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
13199 static int intel_encoder_clones(struct intel_encoder
*encoder
)
13201 struct drm_device
*dev
= encoder
->base
.dev
;
13202 struct intel_encoder
*source_encoder
;
13203 int index_mask
= 0;
13206 for_each_intel_encoder(dev
, source_encoder
) {
13207 if (encoders_cloneable(encoder
, source_encoder
))
13208 index_mask
|= (1 << entry
);
13216 static bool has_edp_a(struct drm_i915_private
*dev_priv
)
13218 if (!IS_MOBILE(dev_priv
))
13221 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
13224 if (IS_GEN5(dev_priv
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
13230 static bool intel_crt_present(struct drm_i915_private
*dev_priv
)
13232 if (INTEL_GEN(dev_priv
) >= 9)
13235 if (IS_HSW_ULT(dev_priv
) || IS_BDW_ULT(dev_priv
))
13238 if (IS_CHERRYVIEW(dev_priv
))
13241 if (HAS_PCH_LPT_H(dev_priv
) &&
13242 I915_READ(SFUSE_STRAP
) & SFUSE_STRAP_CRT_DISABLED
)
13245 /* DDI E can't be used if DDI A requires 4 lanes */
13246 if (HAS_DDI(dev_priv
) && I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_A_4_LANES
)
13249 if (!dev_priv
->vbt
.int_crt_support
)
13255 void intel_pps_unlock_regs_wa(struct drm_i915_private
*dev_priv
)
13260 if (HAS_DDI(dev_priv
))
13263 * This w/a is needed at least on CPT/PPT, but to be sure apply it
13264 * everywhere where registers can be write protected.
13266 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
13271 for (pps_idx
= 0; pps_idx
< pps_num
; pps_idx
++) {
13272 u32 val
= I915_READ(PP_CONTROL(pps_idx
));
13274 val
= (val
& ~PANEL_UNLOCK_MASK
) | PANEL_UNLOCK_REGS
;
13275 I915_WRITE(PP_CONTROL(pps_idx
), val
);
13279 static void intel_pps_init(struct drm_i915_private
*dev_priv
)
13281 if (HAS_PCH_SPLIT(dev_priv
) || IS_GEN9_LP(dev_priv
))
13282 dev_priv
->pps_mmio_base
= PCH_PPS_BASE
;
13283 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
13284 dev_priv
->pps_mmio_base
= VLV_PPS_BASE
;
13286 dev_priv
->pps_mmio_base
= PPS_BASE
;
13288 intel_pps_unlock_regs_wa(dev_priv
);
13291 static void intel_setup_outputs(struct drm_i915_private
*dev_priv
)
13293 struct intel_encoder
*encoder
;
13294 bool dpd_is_edp
= false;
13296 intel_pps_init(dev_priv
);
13299 * intel_edp_init_connector() depends on this completing first, to
13300 * prevent the registeration of both eDP and LVDS and the incorrect
13301 * sharing of the PPS.
13303 intel_lvds_init(dev_priv
);
13305 if (intel_crt_present(dev_priv
))
13306 intel_crt_init(dev_priv
);
13308 if (IS_GEN9_LP(dev_priv
)) {
13310 * FIXME: Broxton doesn't support port detection via the
13311 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
13312 * detect the ports.
13314 intel_ddi_init(dev_priv
, PORT_A
);
13315 intel_ddi_init(dev_priv
, PORT_B
);
13316 intel_ddi_init(dev_priv
, PORT_C
);
13318 intel_dsi_init(dev_priv
);
13319 } else if (HAS_DDI(dev_priv
)) {
13323 * Haswell uses DDI functions to detect digital outputs.
13324 * On SKL pre-D0 the strap isn't connected, so we assume
13327 found
= I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_INIT_DISPLAY_DETECTED
;
13328 /* WaIgnoreDDIAStrap: skl */
13329 if (found
|| IS_GEN9_BC(dev_priv
))
13330 intel_ddi_init(dev_priv
, PORT_A
);
13332 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
13334 found
= I915_READ(SFUSE_STRAP
);
13336 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
13337 intel_ddi_init(dev_priv
, PORT_B
);
13338 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
13339 intel_ddi_init(dev_priv
, PORT_C
);
13340 if (found
& SFUSE_STRAP_DDID_DETECTED
)
13341 intel_ddi_init(dev_priv
, PORT_D
);
13343 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
13345 if (IS_GEN9_BC(dev_priv
) &&
13346 (dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dp
||
13347 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dvi
||
13348 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_hdmi
))
13349 intel_ddi_init(dev_priv
, PORT_E
);
13351 } else if (HAS_PCH_SPLIT(dev_priv
)) {
13353 dpd_is_edp
= intel_dp_is_edp(dev_priv
, PORT_D
);
13355 if (has_edp_a(dev_priv
))
13356 intel_dp_init(dev_priv
, DP_A
, PORT_A
);
13358 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
13359 /* PCH SDVOB multiplex with HDMIB */
13360 found
= intel_sdvo_init(dev_priv
, PCH_SDVOB
, PORT_B
);
13362 intel_hdmi_init(dev_priv
, PCH_HDMIB
, PORT_B
);
13363 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
13364 intel_dp_init(dev_priv
, PCH_DP_B
, PORT_B
);
13367 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
13368 intel_hdmi_init(dev_priv
, PCH_HDMIC
, PORT_C
);
13370 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
13371 intel_hdmi_init(dev_priv
, PCH_HDMID
, PORT_D
);
13373 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
13374 intel_dp_init(dev_priv
, PCH_DP_C
, PORT_C
);
13376 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
13377 intel_dp_init(dev_priv
, PCH_DP_D
, PORT_D
);
13378 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
13379 bool has_edp
, has_port
;
13382 * The DP_DETECTED bit is the latched state of the DDC
13383 * SDA pin at boot. However since eDP doesn't require DDC
13384 * (no way to plug in a DP->HDMI dongle) the DDC pins for
13385 * eDP ports may have been muxed to an alternate function.
13386 * Thus we can't rely on the DP_DETECTED bit alone to detect
13387 * eDP ports. Consult the VBT as well as DP_DETECTED to
13388 * detect eDP ports.
13390 * Sadly the straps seem to be missing sometimes even for HDMI
13391 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
13392 * and VBT for the presence of the port. Additionally we can't
13393 * trust the port type the VBT declares as we've seen at least
13394 * HDMI ports that the VBT claim are DP or eDP.
13396 has_edp
= intel_dp_is_edp(dev_priv
, PORT_B
);
13397 has_port
= intel_bios_is_port_present(dev_priv
, PORT_B
);
13398 if (I915_READ(VLV_DP_B
) & DP_DETECTED
|| has_port
)
13399 has_edp
&= intel_dp_init(dev_priv
, VLV_DP_B
, PORT_B
);
13400 if ((I915_READ(VLV_HDMIB
) & SDVO_DETECTED
|| has_port
) && !has_edp
)
13401 intel_hdmi_init(dev_priv
, VLV_HDMIB
, PORT_B
);
13403 has_edp
= intel_dp_is_edp(dev_priv
, PORT_C
);
13404 has_port
= intel_bios_is_port_present(dev_priv
, PORT_C
);
13405 if (I915_READ(VLV_DP_C
) & DP_DETECTED
|| has_port
)
13406 has_edp
&= intel_dp_init(dev_priv
, VLV_DP_C
, PORT_C
);
13407 if ((I915_READ(VLV_HDMIC
) & SDVO_DETECTED
|| has_port
) && !has_edp
)
13408 intel_hdmi_init(dev_priv
, VLV_HDMIC
, PORT_C
);
13410 if (IS_CHERRYVIEW(dev_priv
)) {
13412 * eDP not supported on port D,
13413 * so no need to worry about it
13415 has_port
= intel_bios_is_port_present(dev_priv
, PORT_D
);
13416 if (I915_READ(CHV_DP_D
) & DP_DETECTED
|| has_port
)
13417 intel_dp_init(dev_priv
, CHV_DP_D
, PORT_D
);
13418 if (I915_READ(CHV_HDMID
) & SDVO_DETECTED
|| has_port
)
13419 intel_hdmi_init(dev_priv
, CHV_HDMID
, PORT_D
);
13422 intel_dsi_init(dev_priv
);
13423 } else if (!IS_GEN2(dev_priv
) && !IS_PINEVIEW(dev_priv
)) {
13424 bool found
= false;
13426 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
13427 DRM_DEBUG_KMS("probing SDVOB\n");
13428 found
= intel_sdvo_init(dev_priv
, GEN3_SDVOB
, PORT_B
);
13429 if (!found
&& IS_G4X(dev_priv
)) {
13430 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
13431 intel_hdmi_init(dev_priv
, GEN4_HDMIB
, PORT_B
);
13434 if (!found
&& IS_G4X(dev_priv
))
13435 intel_dp_init(dev_priv
, DP_B
, PORT_B
);
13438 /* Before G4X SDVOC doesn't have its own detect register */
13440 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
13441 DRM_DEBUG_KMS("probing SDVOC\n");
13442 found
= intel_sdvo_init(dev_priv
, GEN3_SDVOC
, PORT_C
);
13445 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
13447 if (IS_G4X(dev_priv
)) {
13448 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
13449 intel_hdmi_init(dev_priv
, GEN4_HDMIC
, PORT_C
);
13451 if (IS_G4X(dev_priv
))
13452 intel_dp_init(dev_priv
, DP_C
, PORT_C
);
13455 if (IS_G4X(dev_priv
) && (I915_READ(DP_D
) & DP_DETECTED
))
13456 intel_dp_init(dev_priv
, DP_D
, PORT_D
);
13457 } else if (IS_GEN2(dev_priv
))
13458 intel_dvo_init(dev_priv
);
13460 if (SUPPORTS_TV(dev_priv
))
13461 intel_tv_init(dev_priv
);
13463 intel_psr_init(dev_priv
);
13465 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
13466 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
13467 encoder
->base
.possible_clones
=
13468 intel_encoder_clones(encoder
);
13471 intel_init_pch_refclk(dev_priv
);
13473 drm_helper_move_panel_connectors_to_head(&dev_priv
->drm
);
13476 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
13478 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
13480 drm_framebuffer_cleanup(fb
);
13482 i915_gem_object_lock(intel_fb
->obj
);
13483 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
13484 i915_gem_object_unlock(intel_fb
->obj
);
13486 i915_gem_object_put(intel_fb
->obj
);
13491 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
13492 struct drm_file
*file
,
13493 unsigned int *handle
)
13495 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
13496 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
13498 if (obj
->userptr
.mm
) {
13499 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
13503 return drm_gem_handle_create(file
, &obj
->base
, handle
);
13506 static int intel_user_framebuffer_dirty(struct drm_framebuffer
*fb
,
13507 struct drm_file
*file
,
13508 unsigned flags
, unsigned color
,
13509 struct drm_clip_rect
*clips
,
13510 unsigned num_clips
)
13512 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13514 i915_gem_object_flush_if_display(obj
);
13515 intel_fb_obj_flush(obj
, ORIGIN_DIRTYFB
);
13520 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
13521 .destroy
= intel_user_framebuffer_destroy
,
13522 .create_handle
= intel_user_framebuffer_create_handle
,
13523 .dirty
= intel_user_framebuffer_dirty
,
13527 u32
intel_fb_pitch_limit(struct drm_i915_private
*dev_priv
,
13528 uint64_t fb_modifier
, uint32_t pixel_format
)
13530 u32 gen
= INTEL_GEN(dev_priv
);
13533 int cpp
= drm_format_plane_cpp(pixel_format
, 0);
13535 /* "The stride in bytes must not exceed the of the size of 8K
13536 * pixels and 32K bytes."
13538 return min(8192 * cpp
, 32768);
13539 } else if (gen
>= 5 && !HAS_GMCH_DISPLAY(dev_priv
)) {
13541 } else if (gen
>= 4) {
13542 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
13546 } else if (gen
>= 3) {
13547 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
13552 /* XXX DSPC is limited to 4k tiled */
13557 static int intel_framebuffer_init(struct intel_framebuffer
*intel_fb
,
13558 struct drm_i915_gem_object
*obj
,
13559 struct drm_mode_fb_cmd2
*mode_cmd
)
13561 struct drm_i915_private
*dev_priv
= to_i915(obj
->base
.dev
);
13562 struct drm_format_name_buf format_name
;
13563 u32 pitch_limit
, stride_alignment
;
13564 unsigned int tiling
, stride
;
13567 i915_gem_object_lock(obj
);
13568 obj
->framebuffer_references
++;
13569 tiling
= i915_gem_object_get_tiling(obj
);
13570 stride
= i915_gem_object_get_stride(obj
);
13571 i915_gem_object_unlock(obj
);
13573 if (mode_cmd
->flags
& DRM_MODE_FB_MODIFIERS
) {
13575 * If there's a fence, enforce that
13576 * the fb modifier and tiling mode match.
13578 if (tiling
!= I915_TILING_NONE
&&
13579 tiling
!= intel_fb_modifier_to_tiling(mode_cmd
->modifier
[0])) {
13580 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
13584 if (tiling
== I915_TILING_X
) {
13585 mode_cmd
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
13586 } else if (tiling
== I915_TILING_Y
) {
13587 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
13592 /* Passed in modifier sanity checking. */
13593 switch (mode_cmd
->modifier
[0]) {
13594 case I915_FORMAT_MOD_Y_TILED
:
13595 case I915_FORMAT_MOD_Yf_TILED
:
13596 if (INTEL_GEN(dev_priv
) < 9) {
13597 DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n",
13598 mode_cmd
->modifier
[0]);
13601 case DRM_FORMAT_MOD_LINEAR
:
13602 case I915_FORMAT_MOD_X_TILED
:
13605 DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n",
13606 mode_cmd
->modifier
[0]);
13611 * gen2/3 display engine uses the fence if present,
13612 * so the tiling mode must match the fb modifier exactly.
13614 if (INTEL_INFO(dev_priv
)->gen
< 4 &&
13615 tiling
!= intel_fb_modifier_to_tiling(mode_cmd
->modifier
[0])) {
13616 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
13620 pitch_limit
= intel_fb_pitch_limit(dev_priv
, mode_cmd
->modifier
[0],
13621 mode_cmd
->pixel_format
);
13622 if (mode_cmd
->pitches
[0] > pitch_limit
) {
13623 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
13624 mode_cmd
->modifier
[0] != DRM_FORMAT_MOD_LINEAR
?
13625 "tiled" : "linear",
13626 mode_cmd
->pitches
[0], pitch_limit
);
13631 * If there's a fence, enforce that
13632 * the fb pitch and fence stride match.
13634 if (tiling
!= I915_TILING_NONE
&& mode_cmd
->pitches
[0] != stride
) {
13635 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
13636 mode_cmd
->pitches
[0], stride
);
13640 /* Reject formats not supported by any plane early. */
13641 switch (mode_cmd
->pixel_format
) {
13642 case DRM_FORMAT_C8
:
13643 case DRM_FORMAT_RGB565
:
13644 case DRM_FORMAT_XRGB8888
:
13645 case DRM_FORMAT_ARGB8888
:
13647 case DRM_FORMAT_XRGB1555
:
13648 if (INTEL_GEN(dev_priv
) > 3) {
13649 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13650 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13654 case DRM_FORMAT_ABGR8888
:
13655 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
) &&
13656 INTEL_GEN(dev_priv
) < 9) {
13657 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13658 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13662 case DRM_FORMAT_XBGR8888
:
13663 case DRM_FORMAT_XRGB2101010
:
13664 case DRM_FORMAT_XBGR2101010
:
13665 if (INTEL_GEN(dev_priv
) < 4) {
13666 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13667 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13671 case DRM_FORMAT_ABGR2101010
:
13672 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
)) {
13673 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13674 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13678 case DRM_FORMAT_YUYV
:
13679 case DRM_FORMAT_UYVY
:
13680 case DRM_FORMAT_YVYU
:
13681 case DRM_FORMAT_VYUY
:
13682 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
)) {
13683 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13684 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13689 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13690 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13694 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
13695 if (mode_cmd
->offsets
[0] != 0)
13698 drm_helper_mode_fill_fb_struct(&dev_priv
->drm
,
13699 &intel_fb
->base
, mode_cmd
);
13701 stride_alignment
= intel_fb_stride_alignment(&intel_fb
->base
, 0);
13702 if (mode_cmd
->pitches
[0] & (stride_alignment
- 1)) {
13703 DRM_DEBUG_KMS("pitch (%d) must be at least %u byte aligned\n",
13704 mode_cmd
->pitches
[0], stride_alignment
);
13708 intel_fb
->obj
= obj
;
13710 ret
= intel_fill_fb_info(dev_priv
, &intel_fb
->base
);
13714 ret
= drm_framebuffer_init(obj
->base
.dev
,
13718 DRM_ERROR("framebuffer init failed %d\n", ret
);
13725 i915_gem_object_lock(obj
);
13726 obj
->framebuffer_references
--;
13727 i915_gem_object_unlock(obj
);
13731 static struct drm_framebuffer
*
13732 intel_user_framebuffer_create(struct drm_device
*dev
,
13733 struct drm_file
*filp
,
13734 const struct drm_mode_fb_cmd2
*user_mode_cmd
)
13736 struct drm_framebuffer
*fb
;
13737 struct drm_i915_gem_object
*obj
;
13738 struct drm_mode_fb_cmd2 mode_cmd
= *user_mode_cmd
;
13740 obj
= i915_gem_object_lookup(filp
, mode_cmd
.handles
[0]);
13742 return ERR_PTR(-ENOENT
);
13744 fb
= intel_framebuffer_create(obj
, &mode_cmd
);
13746 i915_gem_object_put(obj
);
13751 static void intel_atomic_state_free(struct drm_atomic_state
*state
)
13753 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
13755 drm_atomic_state_default_release(state
);
13757 i915_sw_fence_fini(&intel_state
->commit_ready
);
13762 static const struct drm_mode_config_funcs intel_mode_funcs
= {
13763 .fb_create
= intel_user_framebuffer_create
,
13764 .output_poll_changed
= intel_fbdev_output_poll_changed
,
13765 .atomic_check
= intel_atomic_check
,
13766 .atomic_commit
= intel_atomic_commit
,
13767 .atomic_state_alloc
= intel_atomic_state_alloc
,
13768 .atomic_state_clear
= intel_atomic_state_clear
,
13769 .atomic_state_free
= intel_atomic_state_free
,
13773 * intel_init_display_hooks - initialize the display modesetting hooks
13774 * @dev_priv: device private
13776 void intel_init_display_hooks(struct drm_i915_private
*dev_priv
)
13778 intel_init_cdclk_hooks(dev_priv
);
13780 if (INTEL_INFO(dev_priv
)->gen
>= 9) {
13781 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
13782 dev_priv
->display
.get_initial_plane_config
=
13783 skylake_get_initial_plane_config
;
13784 dev_priv
->display
.crtc_compute_clock
=
13785 haswell_crtc_compute_clock
;
13786 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
13787 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
13788 } else if (HAS_DDI(dev_priv
)) {
13789 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
13790 dev_priv
->display
.get_initial_plane_config
=
13791 ironlake_get_initial_plane_config
;
13792 dev_priv
->display
.crtc_compute_clock
=
13793 haswell_crtc_compute_clock
;
13794 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
13795 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
13796 } else if (HAS_PCH_SPLIT(dev_priv
)) {
13797 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
13798 dev_priv
->display
.get_initial_plane_config
=
13799 ironlake_get_initial_plane_config
;
13800 dev_priv
->display
.crtc_compute_clock
=
13801 ironlake_crtc_compute_clock
;
13802 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
13803 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
13804 } else if (IS_CHERRYVIEW(dev_priv
)) {
13805 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13806 dev_priv
->display
.get_initial_plane_config
=
13807 i9xx_get_initial_plane_config
;
13808 dev_priv
->display
.crtc_compute_clock
= chv_crtc_compute_clock
;
13809 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
13810 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13811 } else if (IS_VALLEYVIEW(dev_priv
)) {
13812 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13813 dev_priv
->display
.get_initial_plane_config
=
13814 i9xx_get_initial_plane_config
;
13815 dev_priv
->display
.crtc_compute_clock
= vlv_crtc_compute_clock
;
13816 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
13817 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13818 } else if (IS_G4X(dev_priv
)) {
13819 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13820 dev_priv
->display
.get_initial_plane_config
=
13821 i9xx_get_initial_plane_config
;
13822 dev_priv
->display
.crtc_compute_clock
= g4x_crtc_compute_clock
;
13823 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
13824 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13825 } else if (IS_PINEVIEW(dev_priv
)) {
13826 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13827 dev_priv
->display
.get_initial_plane_config
=
13828 i9xx_get_initial_plane_config
;
13829 dev_priv
->display
.crtc_compute_clock
= pnv_crtc_compute_clock
;
13830 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
13831 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13832 } else if (!IS_GEN2(dev_priv
)) {
13833 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13834 dev_priv
->display
.get_initial_plane_config
=
13835 i9xx_get_initial_plane_config
;
13836 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
13837 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
13838 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13840 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13841 dev_priv
->display
.get_initial_plane_config
=
13842 i9xx_get_initial_plane_config
;
13843 dev_priv
->display
.crtc_compute_clock
= i8xx_crtc_compute_clock
;
13844 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
13845 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13848 if (IS_GEN5(dev_priv
)) {
13849 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
13850 } else if (IS_GEN6(dev_priv
)) {
13851 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
13852 } else if (IS_IVYBRIDGE(dev_priv
)) {
13853 /* FIXME: detect B0+ stepping and use auto training */
13854 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
13855 } else if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
13856 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
13859 if (dev_priv
->info
.gen
>= 9)
13860 dev_priv
->display
.update_crtcs
= skl_update_crtcs
;
13862 dev_priv
->display
.update_crtcs
= intel_update_crtcs
;
13866 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
13868 static void quirk_ssc_force_disable(struct drm_device
*dev
)
13870 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13871 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
13872 DRM_INFO("applying lvds SSC disable quirk\n");
13876 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
13879 static void quirk_invert_brightness(struct drm_device
*dev
)
13881 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13882 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
13883 DRM_INFO("applying inverted panel brightness quirk\n");
13886 /* Some VBT's incorrectly indicate no backlight is present */
13887 static void quirk_backlight_present(struct drm_device
*dev
)
13889 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13890 dev_priv
->quirks
|= QUIRK_BACKLIGHT_PRESENT
;
13891 DRM_INFO("applying backlight present quirk\n");
13894 /* Toshiba Satellite P50-C-18C requires T12 delay to be min 800ms
13895 * which is 300 ms greater than eDP spec T12 min.
13897 static void quirk_increase_t12_delay(struct drm_device
*dev
)
13899 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13901 dev_priv
->quirks
|= QUIRK_INCREASE_T12_DELAY
;
13902 DRM_INFO("Applying T12 delay quirk\n");
13905 struct intel_quirk
{
13907 int subsystem_vendor
;
13908 int subsystem_device
;
13909 void (*hook
)(struct drm_device
*dev
);
13912 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
13913 struct intel_dmi_quirk
{
13914 void (*hook
)(struct drm_device
*dev
);
13915 const struct dmi_system_id (*dmi_id_list
)[];
13918 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
13920 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
13924 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
13926 .dmi_id_list
= &(const struct dmi_system_id
[]) {
13928 .callback
= intel_dmi_reverse_brightness
,
13929 .ident
= "NCR Corporation",
13930 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
13931 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
13934 { } /* terminating entry */
13936 .hook
= quirk_invert_brightness
,
13940 static struct intel_quirk intel_quirks
[] = {
13941 /* Lenovo U160 cannot use SSC on LVDS */
13942 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
13944 /* Sony Vaio Y cannot use SSC on LVDS */
13945 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
13947 /* Acer Aspire 5734Z must invert backlight brightness */
13948 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
13950 /* Acer/eMachines G725 */
13951 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
13953 /* Acer/eMachines e725 */
13954 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
13956 /* Acer/Packard Bell NCL20 */
13957 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
13959 /* Acer Aspire 4736Z */
13960 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
13962 /* Acer Aspire 5336 */
13963 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
13965 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
13966 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present
},
13968 /* Acer C720 Chromebook (Core i3 4005U) */
13969 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present
},
13971 /* Apple Macbook 2,1 (Core 2 T7400) */
13972 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present
},
13974 /* Apple Macbook 4,1 */
13975 { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present
},
13977 /* Toshiba CB35 Chromebook (Celeron 2955U) */
13978 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present
},
13980 /* HP Chromebook 14 (Celeron 2955U) */
13981 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present
},
13983 /* Dell Chromebook 11 */
13984 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present
},
13986 /* Dell Chromebook 11 (2015 version) */
13987 { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present
},
13989 /* Toshiba Satellite P50-C-18C */
13990 { 0x191B, 0x1179, 0xF840, quirk_increase_t12_delay
},
13993 static void intel_init_quirks(struct drm_device
*dev
)
13995 struct pci_dev
*d
= dev
->pdev
;
13998 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
13999 struct intel_quirk
*q
= &intel_quirks
[i
];
14001 if (d
->device
== q
->device
&&
14002 (d
->subsystem_vendor
== q
->subsystem_vendor
||
14003 q
->subsystem_vendor
== PCI_ANY_ID
) &&
14004 (d
->subsystem_device
== q
->subsystem_device
||
14005 q
->subsystem_device
== PCI_ANY_ID
))
14008 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
14009 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
14010 intel_dmi_quirks
[i
].hook(dev
);
14014 /* Disable the VGA plane that we never use */
14015 static void i915_disable_vga(struct drm_i915_private
*dev_priv
)
14017 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
14019 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev_priv
);
14021 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
14022 vga_get_uninterruptible(pdev
, VGA_RSRC_LEGACY_IO
);
14023 outb(SR01
, VGA_SR_INDEX
);
14024 sr1
= inb(VGA_SR_DATA
);
14025 outb(sr1
| 1<<5, VGA_SR_DATA
);
14026 vga_put(pdev
, VGA_RSRC_LEGACY_IO
);
14029 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
14030 POSTING_READ(vga_reg
);
14033 void intel_modeset_init_hw(struct drm_device
*dev
)
14035 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14037 intel_update_cdclk(dev_priv
);
14038 dev_priv
->cdclk
.logical
= dev_priv
->cdclk
.actual
= dev_priv
->cdclk
.hw
;
14040 intel_init_clock_gating(dev_priv
);
14044 * Calculate what we think the watermarks should be for the state we've read
14045 * out of the hardware and then immediately program those watermarks so that
14046 * we ensure the hardware settings match our internal state.
14048 * We can calculate what we think WM's should be by creating a duplicate of the
14049 * current state (which was constructed during hardware readout) and running it
14050 * through the atomic check code to calculate new watermark values in the
14053 static void sanitize_watermarks(struct drm_device
*dev
)
14055 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14056 struct drm_atomic_state
*state
;
14057 struct intel_atomic_state
*intel_state
;
14058 struct drm_crtc
*crtc
;
14059 struct drm_crtc_state
*cstate
;
14060 struct drm_modeset_acquire_ctx ctx
;
14064 /* Only supported on platforms that use atomic watermark design */
14065 if (!dev_priv
->display
.optimize_watermarks
)
14069 * We need to hold connection_mutex before calling duplicate_state so
14070 * that the connector loop is protected.
14072 drm_modeset_acquire_init(&ctx
, 0);
14074 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
14075 if (ret
== -EDEADLK
) {
14076 drm_modeset_backoff(&ctx
);
14078 } else if (WARN_ON(ret
)) {
14082 state
= drm_atomic_helper_duplicate_state(dev
, &ctx
);
14083 if (WARN_ON(IS_ERR(state
)))
14086 intel_state
= to_intel_atomic_state(state
);
14089 * Hardware readout is the only time we don't want to calculate
14090 * intermediate watermarks (since we don't trust the current
14093 if (!HAS_GMCH_DISPLAY(dev_priv
))
14094 intel_state
->skip_intermediate_wm
= true;
14096 ret
= intel_atomic_check(dev
, state
);
14099 * If we fail here, it means that the hardware appears to be
14100 * programmed in a way that shouldn't be possible, given our
14101 * understanding of watermark requirements. This might mean a
14102 * mistake in the hardware readout code or a mistake in the
14103 * watermark calculations for a given platform. Raise a WARN
14104 * so that this is noticeable.
14106 * If this actually happens, we'll have to just leave the
14107 * BIOS-programmed watermarks untouched and hope for the best.
14109 WARN(true, "Could not determine valid watermarks for inherited state\n");
14113 /* Write calculated watermark values back */
14114 for_each_new_crtc_in_state(state
, crtc
, cstate
, i
) {
14115 struct intel_crtc_state
*cs
= to_intel_crtc_state(cstate
);
14117 cs
->wm
.need_postvbl_update
= true;
14118 dev_priv
->display
.optimize_watermarks(intel_state
, cs
);
14122 drm_atomic_state_put(state
);
14124 drm_modeset_drop_locks(&ctx
);
14125 drm_modeset_acquire_fini(&ctx
);
14128 int intel_modeset_init(struct drm_device
*dev
)
14130 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14131 struct i915_ggtt
*ggtt
= &dev_priv
->ggtt
;
14133 struct intel_crtc
*crtc
;
14135 drm_mode_config_init(dev
);
14137 dev
->mode_config
.min_width
= 0;
14138 dev
->mode_config
.min_height
= 0;
14140 dev
->mode_config
.preferred_depth
= 24;
14141 dev
->mode_config
.prefer_shadow
= 1;
14143 dev
->mode_config
.allow_fb_modifiers
= true;
14145 dev
->mode_config
.funcs
= &intel_mode_funcs
;
14147 init_llist_head(&dev_priv
->atomic_helper
.free_list
);
14148 INIT_WORK(&dev_priv
->atomic_helper
.free_work
,
14149 intel_atomic_helper_free_state_worker
);
14151 intel_init_quirks(dev
);
14153 intel_init_pm(dev_priv
);
14155 if (INTEL_INFO(dev_priv
)->num_pipes
== 0)
14159 * There may be no VBT; and if the BIOS enabled SSC we can
14160 * just keep using it to avoid unnecessary flicker. Whereas if the
14161 * BIOS isn't using it, don't assume it will work even if the VBT
14162 * indicates as much.
14164 if (HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
)) {
14165 bool bios_lvds_use_ssc
= !!(I915_READ(PCH_DREF_CONTROL
) &
14168 if (dev_priv
->vbt
.lvds_use_ssc
!= bios_lvds_use_ssc
) {
14169 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
14170 bios_lvds_use_ssc
? "en" : "dis",
14171 dev_priv
->vbt
.lvds_use_ssc
? "en" : "dis");
14172 dev_priv
->vbt
.lvds_use_ssc
= bios_lvds_use_ssc
;
14176 if (IS_GEN2(dev_priv
)) {
14177 dev
->mode_config
.max_width
= 2048;
14178 dev
->mode_config
.max_height
= 2048;
14179 } else if (IS_GEN3(dev_priv
)) {
14180 dev
->mode_config
.max_width
= 4096;
14181 dev
->mode_config
.max_height
= 4096;
14183 dev
->mode_config
.max_width
= 8192;
14184 dev
->mode_config
.max_height
= 8192;
14187 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
)) {
14188 dev
->mode_config
.cursor_width
= IS_I845G(dev_priv
) ? 64 : 512;
14189 dev
->mode_config
.cursor_height
= 1023;
14190 } else if (IS_GEN2(dev_priv
)) {
14191 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
14192 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
14194 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
14195 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
14198 dev
->mode_config
.fb_base
= ggtt
->mappable_base
;
14200 DRM_DEBUG_KMS("%d display pipe%s available.\n",
14201 INTEL_INFO(dev_priv
)->num_pipes
,
14202 INTEL_INFO(dev_priv
)->num_pipes
> 1 ? "s" : "");
14204 for_each_pipe(dev_priv
, pipe
) {
14207 ret
= intel_crtc_init(dev_priv
, pipe
);
14209 drm_mode_config_cleanup(dev
);
14214 intel_shared_dpll_init(dev
);
14216 intel_update_czclk(dev_priv
);
14217 intel_modeset_init_hw(dev
);
14219 if (dev_priv
->max_cdclk_freq
== 0)
14220 intel_update_max_cdclk(dev_priv
);
14222 /* Just disable it once at startup */
14223 i915_disable_vga(dev_priv
);
14224 intel_setup_outputs(dev_priv
);
14226 drm_modeset_lock_all(dev
);
14227 intel_modeset_setup_hw_state(dev
, dev
->mode_config
.acquire_ctx
);
14228 drm_modeset_unlock_all(dev
);
14230 for_each_intel_crtc(dev
, crtc
) {
14231 struct intel_initial_plane_config plane_config
= {};
14237 * Note that reserving the BIOS fb up front prevents us
14238 * from stuffing other stolen allocations like the ring
14239 * on top. This prevents some ugliness at boot time, and
14240 * can even allow for smooth boot transitions if the BIOS
14241 * fb is large enough for the active pipe configuration.
14243 dev_priv
->display
.get_initial_plane_config(crtc
,
14247 * If the fb is shared between multiple heads, we'll
14248 * just get the first one.
14250 intel_find_initial_plane_obj(crtc
, &plane_config
);
14254 * Make sure hardware watermarks really match the state we read out.
14255 * Note that we need to do this after reconstructing the BIOS fb's
14256 * since the watermark calculation done here will use pstate->fb.
14258 if (!HAS_GMCH_DISPLAY(dev_priv
))
14259 sanitize_watermarks(dev
);
14264 void i830_enable_pipe(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
14266 /* 640x480@60Hz, ~25175 kHz */
14267 struct dpll clock
= {
14277 WARN_ON(i9xx_calc_dpll_params(48000, &clock
) != 25154);
14279 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
14280 pipe_name(pipe
), clock
.vco
, clock
.dot
);
14282 fp
= i9xx_dpll_compute_fp(&clock
);
14283 dpll
= (I915_READ(DPLL(pipe
)) & DPLL_DVO_2X_MODE
) |
14284 DPLL_VGA_MODE_DIS
|
14285 ((clock
.p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
) |
14286 PLL_P2_DIVIDE_BY_4
|
14287 PLL_REF_INPUT_DREFCLK
|
14290 I915_WRITE(FP0(pipe
), fp
);
14291 I915_WRITE(FP1(pipe
), fp
);
14293 I915_WRITE(HTOTAL(pipe
), (640 - 1) | ((800 - 1) << 16));
14294 I915_WRITE(HBLANK(pipe
), (640 - 1) | ((800 - 1) << 16));
14295 I915_WRITE(HSYNC(pipe
), (656 - 1) | ((752 - 1) << 16));
14296 I915_WRITE(VTOTAL(pipe
), (480 - 1) | ((525 - 1) << 16));
14297 I915_WRITE(VBLANK(pipe
), (480 - 1) | ((525 - 1) << 16));
14298 I915_WRITE(VSYNC(pipe
), (490 - 1) | ((492 - 1) << 16));
14299 I915_WRITE(PIPESRC(pipe
), ((640 - 1) << 16) | (480 - 1));
14302 * Apparently we need to have VGA mode enabled prior to changing
14303 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
14304 * dividers, even though the register value does change.
14306 I915_WRITE(DPLL(pipe
), dpll
& ~DPLL_VGA_MODE_DIS
);
14307 I915_WRITE(DPLL(pipe
), dpll
);
14309 /* Wait for the clocks to stabilize. */
14310 POSTING_READ(DPLL(pipe
));
14313 /* The pixel multiplier can only be updated once the
14314 * DPLL is enabled and the clocks are stable.
14316 * So write it again.
14318 I915_WRITE(DPLL(pipe
), dpll
);
14320 /* We do this three times for luck */
14321 for (i
= 0; i
< 3 ; i
++) {
14322 I915_WRITE(DPLL(pipe
), dpll
);
14323 POSTING_READ(DPLL(pipe
));
14324 udelay(150); /* wait for warmup */
14327 I915_WRITE(PIPECONF(pipe
), PIPECONF_ENABLE
| PIPECONF_PROGRESSIVE
);
14328 POSTING_READ(PIPECONF(pipe
));
14331 void i830_disable_pipe(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
14333 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
14336 assert_plane_disabled(dev_priv
, PLANE_A
);
14337 assert_plane_disabled(dev_priv
, PLANE_B
);
14339 I915_WRITE(PIPECONF(pipe
), 0);
14340 POSTING_READ(PIPECONF(pipe
));
14342 if (wait_for(pipe_dsl_stopped(dev_priv
, pipe
), 100))
14343 DRM_ERROR("pipe %c off wait timed out\n", pipe_name(pipe
));
14345 I915_WRITE(DPLL(pipe
), DPLL_VGA_MODE_DIS
);
14346 POSTING_READ(DPLL(pipe
));
14350 intel_check_plane_mapping(struct intel_crtc
*crtc
)
14352 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
14355 if (INTEL_INFO(dev_priv
)->num_pipes
== 1)
14358 val
= I915_READ(DSPCNTR(!crtc
->plane
));
14360 if ((val
& DISPLAY_PLANE_ENABLE
) &&
14361 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
14367 static bool intel_crtc_has_encoders(struct intel_crtc
*crtc
)
14369 struct drm_device
*dev
= crtc
->base
.dev
;
14370 struct intel_encoder
*encoder
;
14372 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
14378 static struct intel_connector
*intel_encoder_find_connector(struct intel_encoder
*encoder
)
14380 struct drm_device
*dev
= encoder
->base
.dev
;
14381 struct intel_connector
*connector
;
14383 for_each_connector_on_encoder(dev
, &encoder
->base
, connector
)
14389 static bool has_pch_trancoder(struct drm_i915_private
*dev_priv
,
14390 enum transcoder pch_transcoder
)
14392 return HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
) ||
14393 (HAS_PCH_LPT_H(dev_priv
) && pch_transcoder
== TRANSCODER_A
);
14396 static void intel_sanitize_crtc(struct intel_crtc
*crtc
,
14397 struct drm_modeset_acquire_ctx
*ctx
)
14399 struct drm_device
*dev
= crtc
->base
.dev
;
14400 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14401 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
14403 /* Clear any frame start delays used for debugging left by the BIOS */
14404 if (!transcoder_is_dsi(cpu_transcoder
)) {
14405 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
14408 I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
14411 /* restore vblank interrupts to correct state */
14412 drm_crtc_vblank_reset(&crtc
->base
);
14413 if (crtc
->active
) {
14414 struct intel_plane
*plane
;
14416 drm_crtc_vblank_on(&crtc
->base
);
14418 /* Disable everything but the primary plane */
14419 for_each_intel_plane_on_crtc(dev
, crtc
, plane
) {
14420 if (plane
->base
.type
== DRM_PLANE_TYPE_PRIMARY
)
14423 trace_intel_disable_plane(&plane
->base
, crtc
);
14424 plane
->disable_plane(plane
, crtc
);
14428 /* We need to sanitize the plane -> pipe mapping first because this will
14429 * disable the crtc (and hence change the state) if it is wrong. Note
14430 * that gen4+ has a fixed plane -> pipe mapping. */
14431 if (INTEL_GEN(dev_priv
) < 4 && !intel_check_plane_mapping(crtc
)) {
14434 DRM_DEBUG_KMS("[CRTC:%d:%s] wrong plane connection detected!\n",
14435 crtc
->base
.base
.id
, crtc
->base
.name
);
14437 /* Pipe has the wrong plane attached and the plane is active.
14438 * Temporarily change the plane mapping and disable everything
14440 plane
= crtc
->plane
;
14441 crtc
->base
.primary
->state
->visible
= true;
14442 crtc
->plane
= !plane
;
14443 intel_crtc_disable_noatomic(&crtc
->base
, ctx
);
14444 crtc
->plane
= plane
;
14447 /* Adjust the state of the output pipe according to whether we
14448 * have active connectors/encoders. */
14449 if (crtc
->active
&& !intel_crtc_has_encoders(crtc
))
14450 intel_crtc_disable_noatomic(&crtc
->base
, ctx
);
14452 if (crtc
->active
|| HAS_GMCH_DISPLAY(dev_priv
)) {
14454 * We start out with underrun reporting disabled to avoid races.
14455 * For correct bookkeeping mark this on active crtcs.
14457 * Also on gmch platforms we dont have any hardware bits to
14458 * disable the underrun reporting. Which means we need to start
14459 * out with underrun reporting disabled also on inactive pipes,
14460 * since otherwise we'll complain about the garbage we read when
14461 * e.g. coming up after runtime pm.
14463 * No protection against concurrent access is required - at
14464 * worst a fifo underrun happens which also sets this to false.
14466 crtc
->cpu_fifo_underrun_disabled
= true;
14468 * We track the PCH trancoder underrun reporting state
14469 * within the crtc. With crtc for pipe A housing the underrun
14470 * reporting state for PCH transcoder A, crtc for pipe B housing
14471 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
14472 * and marking underrun reporting as disabled for the non-existing
14473 * PCH transcoders B and C would prevent enabling the south
14474 * error interrupt (see cpt_can_enable_serr_int()).
14476 if (has_pch_trancoder(dev_priv
, (enum transcoder
)crtc
->pipe
))
14477 crtc
->pch_fifo_underrun_disabled
= true;
14481 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
14483 struct intel_connector
*connector
;
14485 /* We need to check both for a crtc link (meaning that the
14486 * encoder is active and trying to read from a pipe) and the
14487 * pipe itself being active. */
14488 bool has_active_crtc
= encoder
->base
.crtc
&&
14489 to_intel_crtc(encoder
->base
.crtc
)->active
;
14491 connector
= intel_encoder_find_connector(encoder
);
14492 if (connector
&& !has_active_crtc
) {
14493 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
14494 encoder
->base
.base
.id
,
14495 encoder
->base
.name
);
14497 /* Connector is active, but has no active pipe. This is
14498 * fallout from our resume register restoring. Disable
14499 * the encoder manually again. */
14500 if (encoder
->base
.crtc
) {
14501 struct drm_crtc_state
*crtc_state
= encoder
->base
.crtc
->state
;
14503 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
14504 encoder
->base
.base
.id
,
14505 encoder
->base
.name
);
14506 encoder
->disable(encoder
, to_intel_crtc_state(crtc_state
), connector
->base
.state
);
14507 if (encoder
->post_disable
)
14508 encoder
->post_disable(encoder
, to_intel_crtc_state(crtc_state
), connector
->base
.state
);
14510 encoder
->base
.crtc
= NULL
;
14512 /* Inconsistent output/port/pipe state happens presumably due to
14513 * a bug in one of the get_hw_state functions. Or someplace else
14514 * in our code, like the register restore mess on resume. Clamp
14515 * things to off as a safer default. */
14517 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
14518 connector
->base
.encoder
= NULL
;
14520 /* Enabled encoders without active connectors will be fixed in
14521 * the crtc fixup. */
14524 void i915_redisable_vga_power_on(struct drm_i915_private
*dev_priv
)
14526 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev_priv
);
14528 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
14529 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
14530 i915_disable_vga(dev_priv
);
14534 void i915_redisable_vga(struct drm_i915_private
*dev_priv
)
14536 /* This function can be called both from intel_modeset_setup_hw_state or
14537 * at a very early point in our resume sequence, where the power well
14538 * structures are not yet restored. Since this function is at a very
14539 * paranoid "someone might have enabled VGA while we were not looking"
14540 * level, just check if the power well is enabled instead of trying to
14541 * follow the "don't touch the power well if we don't need it" policy
14542 * the rest of the driver uses. */
14543 if (!intel_display_power_get_if_enabled(dev_priv
, POWER_DOMAIN_VGA
))
14546 i915_redisable_vga_power_on(dev_priv
);
14548 intel_display_power_put(dev_priv
, POWER_DOMAIN_VGA
);
14551 static bool primary_get_hw_state(struct intel_plane
*plane
)
14553 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
14555 return I915_READ(DSPCNTR(plane
->plane
)) & DISPLAY_PLANE_ENABLE
;
14558 /* FIXME read out full plane state for all planes */
14559 static void readout_plane_state(struct intel_crtc
*crtc
)
14561 struct intel_plane
*primary
= to_intel_plane(crtc
->base
.primary
);
14564 visible
= crtc
->active
&& primary_get_hw_state(primary
);
14566 intel_set_plane_visible(to_intel_crtc_state(crtc
->base
.state
),
14567 to_intel_plane_state(primary
->base
.state
),
14571 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
14573 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14575 struct intel_crtc
*crtc
;
14576 struct intel_encoder
*encoder
;
14577 struct intel_connector
*connector
;
14578 struct drm_connector_list_iter conn_iter
;
14581 dev_priv
->active_crtcs
= 0;
14583 for_each_intel_crtc(dev
, crtc
) {
14584 struct intel_crtc_state
*crtc_state
=
14585 to_intel_crtc_state(crtc
->base
.state
);
14587 __drm_atomic_helper_crtc_destroy_state(&crtc_state
->base
);
14588 memset(crtc_state
, 0, sizeof(*crtc_state
));
14589 crtc_state
->base
.crtc
= &crtc
->base
;
14591 crtc_state
->base
.active
= crtc_state
->base
.enable
=
14592 dev_priv
->display
.get_pipe_config(crtc
, crtc_state
);
14594 crtc
->base
.enabled
= crtc_state
->base
.enable
;
14595 crtc
->active
= crtc_state
->base
.active
;
14597 if (crtc_state
->base
.active
)
14598 dev_priv
->active_crtcs
|= 1 << crtc
->pipe
;
14600 readout_plane_state(crtc
);
14602 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
14603 crtc
->base
.base
.id
, crtc
->base
.name
,
14604 enableddisabled(crtc_state
->base
.active
));
14607 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
14608 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
14610 pll
->on
= pll
->funcs
.get_hw_state(dev_priv
, pll
,
14611 &pll
->state
.hw_state
);
14612 pll
->state
.crtc_mask
= 0;
14613 for_each_intel_crtc(dev
, crtc
) {
14614 struct intel_crtc_state
*crtc_state
=
14615 to_intel_crtc_state(crtc
->base
.state
);
14617 if (crtc_state
->base
.active
&&
14618 crtc_state
->shared_dpll
== pll
)
14619 pll
->state
.crtc_mask
|= 1 << crtc
->pipe
;
14621 pll
->active_mask
= pll
->state
.crtc_mask
;
14623 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
14624 pll
->name
, pll
->state
.crtc_mask
, pll
->on
);
14627 for_each_intel_encoder(dev
, encoder
) {
14630 if (encoder
->get_hw_state(encoder
, &pipe
)) {
14631 struct intel_crtc_state
*crtc_state
;
14633 crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
14634 crtc_state
= to_intel_crtc_state(crtc
->base
.state
);
14636 encoder
->base
.crtc
= &crtc
->base
;
14637 crtc_state
->output_types
|= 1 << encoder
->type
;
14638 encoder
->get_config(encoder
, crtc_state
);
14640 encoder
->base
.crtc
= NULL
;
14643 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
14644 encoder
->base
.base
.id
, encoder
->base
.name
,
14645 enableddisabled(encoder
->base
.crtc
),
14649 drm_connector_list_iter_begin(dev
, &conn_iter
);
14650 for_each_intel_connector_iter(connector
, &conn_iter
) {
14651 if (connector
->get_hw_state(connector
)) {
14652 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
14654 encoder
= connector
->encoder
;
14655 connector
->base
.encoder
= &encoder
->base
;
14657 if (encoder
->base
.crtc
&&
14658 encoder
->base
.crtc
->state
->active
) {
14660 * This has to be done during hardware readout
14661 * because anything calling .crtc_disable may
14662 * rely on the connector_mask being accurate.
14664 encoder
->base
.crtc
->state
->connector_mask
|=
14665 1 << drm_connector_index(&connector
->base
);
14666 encoder
->base
.crtc
->state
->encoder_mask
|=
14667 1 << drm_encoder_index(&encoder
->base
);
14671 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
14672 connector
->base
.encoder
= NULL
;
14674 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
14675 connector
->base
.base
.id
, connector
->base
.name
,
14676 enableddisabled(connector
->base
.encoder
));
14678 drm_connector_list_iter_end(&conn_iter
);
14680 for_each_intel_crtc(dev
, crtc
) {
14681 struct intel_crtc_state
*crtc_state
=
14682 to_intel_crtc_state(crtc
->base
.state
);
14685 memset(&crtc
->base
.mode
, 0, sizeof(crtc
->base
.mode
));
14686 if (crtc_state
->base
.active
) {
14687 intel_mode_from_pipe_config(&crtc
->base
.mode
, crtc_state
);
14688 intel_mode_from_pipe_config(&crtc_state
->base
.adjusted_mode
, crtc_state
);
14689 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->base
.state
, &crtc
->base
.mode
));
14692 * The initial mode needs to be set in order to keep
14693 * the atomic core happy. It wants a valid mode if the
14694 * crtc's enabled, so we do the above call.
14696 * But we don't set all the derived state fully, hence
14697 * set a flag to indicate that a full recalculation is
14698 * needed on the next commit.
14700 crtc_state
->base
.mode
.private_flags
= I915_MODE_FLAG_INHERITED
;
14702 intel_crtc_compute_pixel_rate(crtc_state
);
14704 if (INTEL_GEN(dev_priv
) >= 9 || IS_BROADWELL(dev_priv
) ||
14705 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
14706 pixclk
= crtc_state
->pixel_rate
;
14708 WARN_ON(dev_priv
->display
.modeset_calc_cdclk
);
14710 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
14711 if (IS_BROADWELL(dev_priv
) && crtc_state
->ips_enabled
)
14712 pixclk
= DIV_ROUND_UP(pixclk
* 100, 95);
14714 drm_calc_timestamping_constants(&crtc
->base
,
14715 &crtc_state
->base
.adjusted_mode
);
14716 update_scanline_offset(crtc
);
14719 dev_priv
->min_pixclk
[crtc
->pipe
] = pixclk
;
14721 intel_pipe_config_sanity_check(dev_priv
, crtc_state
);
14726 get_encoder_power_domains(struct drm_i915_private
*dev_priv
)
14728 struct intel_encoder
*encoder
;
14730 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
14732 enum intel_display_power_domain domain
;
14734 if (!encoder
->get_power_domains
)
14737 get_domains
= encoder
->get_power_domains(encoder
);
14738 for_each_power_domain(domain
, get_domains
)
14739 intel_display_power_get(dev_priv
, domain
);
14743 /* Scan out the current hw modeset state,
14744 * and sanitizes it to the current state
14747 intel_modeset_setup_hw_state(struct drm_device
*dev
,
14748 struct drm_modeset_acquire_ctx
*ctx
)
14750 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14752 struct intel_crtc
*crtc
;
14753 struct intel_encoder
*encoder
;
14756 intel_modeset_readout_hw_state(dev
);
14758 /* HW state is read out, now we need to sanitize this mess. */
14759 get_encoder_power_domains(dev_priv
);
14761 for_each_intel_encoder(dev
, encoder
) {
14762 intel_sanitize_encoder(encoder
);
14765 for_each_pipe(dev_priv
, pipe
) {
14766 crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
14768 intel_sanitize_crtc(crtc
, ctx
);
14769 intel_dump_pipe_config(crtc
, crtc
->config
,
14770 "[setup_hw_state]");
14773 intel_modeset_update_connector_atomic_state(dev
);
14775 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
14776 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
14778 if (!pll
->on
|| pll
->active_mask
)
14781 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
14783 pll
->funcs
.disable(dev_priv
, pll
);
14787 if (IS_G4X(dev_priv
)) {
14788 g4x_wm_get_hw_state(dev
);
14789 g4x_wm_sanitize(dev_priv
);
14790 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
14791 vlv_wm_get_hw_state(dev
);
14792 vlv_wm_sanitize(dev_priv
);
14793 } else if (IS_GEN9(dev_priv
)) {
14794 skl_wm_get_hw_state(dev
);
14795 } else if (HAS_PCH_SPLIT(dev_priv
)) {
14796 ilk_wm_get_hw_state(dev
);
14799 for_each_intel_crtc(dev
, crtc
) {
14802 put_domains
= modeset_get_crtc_power_domains(&crtc
->base
, crtc
->config
);
14803 if (WARN_ON(put_domains
))
14804 modeset_put_power_domains(dev_priv
, put_domains
);
14806 intel_display_set_init_power(dev_priv
, false);
14808 intel_power_domains_verify_state(dev_priv
);
14810 intel_fbc_init_pipe_state(dev_priv
);
14813 void intel_display_resume(struct drm_device
*dev
)
14815 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14816 struct drm_atomic_state
*state
= dev_priv
->modeset_restore_state
;
14817 struct drm_modeset_acquire_ctx ctx
;
14820 dev_priv
->modeset_restore_state
= NULL
;
14822 state
->acquire_ctx
= &ctx
;
14824 drm_modeset_acquire_init(&ctx
, 0);
14827 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
14828 if (ret
!= -EDEADLK
)
14831 drm_modeset_backoff(&ctx
);
14835 ret
= __intel_display_resume(dev
, state
, &ctx
);
14837 drm_modeset_drop_locks(&ctx
);
14838 drm_modeset_acquire_fini(&ctx
);
14841 DRM_ERROR("Restoring old state failed with %i\n", ret
);
14843 drm_atomic_state_put(state
);
14846 void intel_modeset_gem_init(struct drm_device
*dev
)
14848 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14850 intel_init_gt_powersave(dev_priv
);
14852 intel_setup_overlay(dev_priv
);
14855 int intel_connector_register(struct drm_connector
*connector
)
14857 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
14860 ret
= intel_backlight_device_register(intel_connector
);
14870 void intel_connector_unregister(struct drm_connector
*connector
)
14872 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
14874 intel_backlight_device_unregister(intel_connector
);
14875 intel_panel_destroy_backlight(connector
);
14878 void intel_modeset_cleanup(struct drm_device
*dev
)
14880 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14882 flush_work(&dev_priv
->atomic_helper
.free_work
);
14883 WARN_ON(!llist_empty(&dev_priv
->atomic_helper
.free_list
));
14885 intel_disable_gt_powersave(dev_priv
);
14888 * Interrupts and polling as the first thing to avoid creating havoc.
14889 * Too much stuff here (turning of connectors, ...) would
14890 * experience fancy races otherwise.
14892 intel_irq_uninstall(dev_priv
);
14895 * Due to the hpd irq storm handling the hotplug work can re-arm the
14896 * poll handlers. Hence disable polling after hpd handling is shut down.
14898 drm_kms_helper_poll_fini(dev
);
14900 /* poll work can call into fbdev, hence clean that up afterwards */
14901 intel_fbdev_fini(dev_priv
);
14903 intel_unregister_dsm_handler();
14905 intel_fbc_global_disable(dev_priv
);
14907 /* flush any delayed tasks or pending work */
14908 flush_scheduled_work();
14910 drm_mode_config_cleanup(dev
);
14912 intel_cleanup_overlay(dev_priv
);
14914 intel_cleanup_gt_powersave(dev_priv
);
14916 intel_teardown_gmbus(dev_priv
);
14919 void intel_connector_attach_encoder(struct intel_connector
*connector
,
14920 struct intel_encoder
*encoder
)
14922 connector
->encoder
= encoder
;
14923 drm_mode_connector_attach_encoder(&connector
->base
,
14928 * set vga decode state - true == enable VGA decode
14930 int intel_modeset_vga_set_state(struct drm_i915_private
*dev_priv
, bool state
)
14932 unsigned reg
= INTEL_GEN(dev_priv
) >= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
14935 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
14936 DRM_ERROR("failed to read control word\n");
14940 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
14944 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
14946 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
14948 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
14949 DRM_ERROR("failed to write control word\n");
14956 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
14958 struct intel_display_error_state
{
14960 u32 power_well_driver
;
14962 int num_transcoders
;
14964 struct intel_cursor_error_state
{
14969 } cursor
[I915_MAX_PIPES
];
14971 struct intel_pipe_error_state
{
14972 bool power_domain_on
;
14975 } pipe
[I915_MAX_PIPES
];
14977 struct intel_plane_error_state
{
14985 } plane
[I915_MAX_PIPES
];
14987 struct intel_transcoder_error_state
{
14988 bool power_domain_on
;
14989 enum transcoder cpu_transcoder
;
15002 struct intel_display_error_state
*
15003 intel_display_capture_error_state(struct drm_i915_private
*dev_priv
)
15005 struct intel_display_error_state
*error
;
15006 int transcoders
[] = {
15014 if (INTEL_INFO(dev_priv
)->num_pipes
== 0)
15017 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
15021 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
15022 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
15024 for_each_pipe(dev_priv
, i
) {
15025 error
->pipe
[i
].power_domain_on
=
15026 __intel_display_power_is_enabled(dev_priv
,
15027 POWER_DOMAIN_PIPE(i
));
15028 if (!error
->pipe
[i
].power_domain_on
)
15031 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
15032 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
15033 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
15035 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
15036 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
15037 if (INTEL_GEN(dev_priv
) <= 3) {
15038 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
15039 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
15041 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
15042 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
15043 if (INTEL_GEN(dev_priv
) >= 4) {
15044 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
15045 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
15048 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
15050 if (HAS_GMCH_DISPLAY(dev_priv
))
15051 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
15054 /* Note: this does not include DSI transcoders. */
15055 error
->num_transcoders
= INTEL_INFO(dev_priv
)->num_pipes
;
15056 if (HAS_DDI(dev_priv
))
15057 error
->num_transcoders
++; /* Account for eDP. */
15059 for (i
= 0; i
< error
->num_transcoders
; i
++) {
15060 enum transcoder cpu_transcoder
= transcoders
[i
];
15062 error
->transcoder
[i
].power_domain_on
=
15063 __intel_display_power_is_enabled(dev_priv
,
15064 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
15065 if (!error
->transcoder
[i
].power_domain_on
)
15068 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
15070 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
15071 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
15072 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
15073 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
15074 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
15075 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
15076 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
15082 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
15085 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
15086 struct intel_display_error_state
*error
)
15088 struct drm_i915_private
*dev_priv
= m
->i915
;
15094 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev_priv
)->num_pipes
);
15095 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
15096 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
15097 error
->power_well_driver
);
15098 for_each_pipe(dev_priv
, i
) {
15099 err_printf(m
, "Pipe [%d]:\n", i
);
15100 err_printf(m
, " Power: %s\n",
15101 onoff(error
->pipe
[i
].power_domain_on
));
15102 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
15103 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
15105 err_printf(m
, "Plane [%d]:\n", i
);
15106 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
15107 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
15108 if (INTEL_GEN(dev_priv
) <= 3) {
15109 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
15110 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
15112 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
15113 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
15114 if (INTEL_GEN(dev_priv
) >= 4) {
15115 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
15116 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
15119 err_printf(m
, "Cursor [%d]:\n", i
);
15120 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
15121 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
15122 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
15125 for (i
= 0; i
< error
->num_transcoders
; i
++) {
15126 err_printf(m
, "CPU transcoder: %s\n",
15127 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
15128 err_printf(m
, " Power: %s\n",
15129 onoff(error
->transcoder
[i
].power_domain_on
));
15130 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
15131 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
15132 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
15133 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
15134 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
15135 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
15136 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);