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 static void intel_pre_disable_primary_noatomic(struct drm_crtc
*crtc
);
129 } dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
133 int p2_slow
, p2_fast
;
137 /* returns HPLL frequency in kHz */
138 int vlv_get_hpll_vco(struct drm_i915_private
*dev_priv
)
140 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
142 /* Obtain SKU information */
143 mutex_lock(&dev_priv
->sb_lock
);
144 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
145 CCK_FUSE_HPLL_FREQ_MASK
;
146 mutex_unlock(&dev_priv
->sb_lock
);
148 return vco_freq
[hpll_freq
] * 1000;
151 int vlv_get_cck_clock(struct drm_i915_private
*dev_priv
,
152 const char *name
, u32 reg
, int ref_freq
)
157 mutex_lock(&dev_priv
->sb_lock
);
158 val
= vlv_cck_read(dev_priv
, reg
);
159 mutex_unlock(&dev_priv
->sb_lock
);
161 divider
= val
& CCK_FREQUENCY_VALUES
;
163 WARN((val
& CCK_FREQUENCY_STATUS
) !=
164 (divider
<< CCK_FREQUENCY_STATUS_SHIFT
),
165 "%s change in progress\n", name
);
167 return DIV_ROUND_CLOSEST(ref_freq
<< 1, divider
+ 1);
170 int vlv_get_cck_clock_hpll(struct drm_i915_private
*dev_priv
,
171 const char *name
, u32 reg
)
173 if (dev_priv
->hpll_freq
== 0)
174 dev_priv
->hpll_freq
= vlv_get_hpll_vco(dev_priv
);
176 return vlv_get_cck_clock(dev_priv
, name
, reg
,
177 dev_priv
->hpll_freq
);
180 static void intel_update_czclk(struct drm_i915_private
*dev_priv
)
182 if (!(IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)))
185 dev_priv
->czclk_freq
= vlv_get_cck_clock_hpll(dev_priv
, "czclk",
186 CCK_CZ_CLOCK_CONTROL
);
188 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv
->czclk_freq
);
191 static inline u32
/* units of 100MHz */
192 intel_fdi_link_freq(struct drm_i915_private
*dev_priv
,
193 const struct intel_crtc_state
*pipe_config
)
195 if (HAS_DDI(dev_priv
))
196 return pipe_config
->port_clock
; /* SPLL */
197 else if (IS_GEN5(dev_priv
))
198 return ((I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2) * 10000;
203 static const struct intel_limit intel_limits_i8xx_dac
= {
204 .dot
= { .min
= 25000, .max
= 350000 },
205 .vco
= { .min
= 908000, .max
= 1512000 },
206 .n
= { .min
= 2, .max
= 16 },
207 .m
= { .min
= 96, .max
= 140 },
208 .m1
= { .min
= 18, .max
= 26 },
209 .m2
= { .min
= 6, .max
= 16 },
210 .p
= { .min
= 4, .max
= 128 },
211 .p1
= { .min
= 2, .max
= 33 },
212 .p2
= { .dot_limit
= 165000,
213 .p2_slow
= 4, .p2_fast
= 2 },
216 static const struct intel_limit intel_limits_i8xx_dvo
= {
217 .dot
= { .min
= 25000, .max
= 350000 },
218 .vco
= { .min
= 908000, .max
= 1512000 },
219 .n
= { .min
= 2, .max
= 16 },
220 .m
= { .min
= 96, .max
= 140 },
221 .m1
= { .min
= 18, .max
= 26 },
222 .m2
= { .min
= 6, .max
= 16 },
223 .p
= { .min
= 4, .max
= 128 },
224 .p1
= { .min
= 2, .max
= 33 },
225 .p2
= { .dot_limit
= 165000,
226 .p2_slow
= 4, .p2_fast
= 4 },
229 static const struct intel_limit intel_limits_i8xx_lvds
= {
230 .dot
= { .min
= 25000, .max
= 350000 },
231 .vco
= { .min
= 908000, .max
= 1512000 },
232 .n
= { .min
= 2, .max
= 16 },
233 .m
= { .min
= 96, .max
= 140 },
234 .m1
= { .min
= 18, .max
= 26 },
235 .m2
= { .min
= 6, .max
= 16 },
236 .p
= { .min
= 4, .max
= 128 },
237 .p1
= { .min
= 1, .max
= 6 },
238 .p2
= { .dot_limit
= 165000,
239 .p2_slow
= 14, .p2_fast
= 7 },
242 static const struct intel_limit intel_limits_i9xx_sdvo
= {
243 .dot
= { .min
= 20000, .max
= 400000 },
244 .vco
= { .min
= 1400000, .max
= 2800000 },
245 .n
= { .min
= 1, .max
= 6 },
246 .m
= { .min
= 70, .max
= 120 },
247 .m1
= { .min
= 8, .max
= 18 },
248 .m2
= { .min
= 3, .max
= 7 },
249 .p
= { .min
= 5, .max
= 80 },
250 .p1
= { .min
= 1, .max
= 8 },
251 .p2
= { .dot_limit
= 200000,
252 .p2_slow
= 10, .p2_fast
= 5 },
255 static const struct intel_limit intel_limits_i9xx_lvds
= {
256 .dot
= { .min
= 20000, .max
= 400000 },
257 .vco
= { .min
= 1400000, .max
= 2800000 },
258 .n
= { .min
= 1, .max
= 6 },
259 .m
= { .min
= 70, .max
= 120 },
260 .m1
= { .min
= 8, .max
= 18 },
261 .m2
= { .min
= 3, .max
= 7 },
262 .p
= { .min
= 7, .max
= 98 },
263 .p1
= { .min
= 1, .max
= 8 },
264 .p2
= { .dot_limit
= 112000,
265 .p2_slow
= 14, .p2_fast
= 7 },
269 static const struct intel_limit intel_limits_g4x_sdvo
= {
270 .dot
= { .min
= 25000, .max
= 270000 },
271 .vco
= { .min
= 1750000, .max
= 3500000},
272 .n
= { .min
= 1, .max
= 4 },
273 .m
= { .min
= 104, .max
= 138 },
274 .m1
= { .min
= 17, .max
= 23 },
275 .m2
= { .min
= 5, .max
= 11 },
276 .p
= { .min
= 10, .max
= 30 },
277 .p1
= { .min
= 1, .max
= 3},
278 .p2
= { .dot_limit
= 270000,
284 static const struct intel_limit intel_limits_g4x_hdmi
= {
285 .dot
= { .min
= 22000, .max
= 400000 },
286 .vco
= { .min
= 1750000, .max
= 3500000},
287 .n
= { .min
= 1, .max
= 4 },
288 .m
= { .min
= 104, .max
= 138 },
289 .m1
= { .min
= 16, .max
= 23 },
290 .m2
= { .min
= 5, .max
= 11 },
291 .p
= { .min
= 5, .max
= 80 },
292 .p1
= { .min
= 1, .max
= 8},
293 .p2
= { .dot_limit
= 165000,
294 .p2_slow
= 10, .p2_fast
= 5 },
297 static const struct intel_limit intel_limits_g4x_single_channel_lvds
= {
298 .dot
= { .min
= 20000, .max
= 115000 },
299 .vco
= { .min
= 1750000, .max
= 3500000 },
300 .n
= { .min
= 1, .max
= 3 },
301 .m
= { .min
= 104, .max
= 138 },
302 .m1
= { .min
= 17, .max
= 23 },
303 .m2
= { .min
= 5, .max
= 11 },
304 .p
= { .min
= 28, .max
= 112 },
305 .p1
= { .min
= 2, .max
= 8 },
306 .p2
= { .dot_limit
= 0,
307 .p2_slow
= 14, .p2_fast
= 14
311 static const struct intel_limit intel_limits_g4x_dual_channel_lvds
= {
312 .dot
= { .min
= 80000, .max
= 224000 },
313 .vco
= { .min
= 1750000, .max
= 3500000 },
314 .n
= { .min
= 1, .max
= 3 },
315 .m
= { .min
= 104, .max
= 138 },
316 .m1
= { .min
= 17, .max
= 23 },
317 .m2
= { .min
= 5, .max
= 11 },
318 .p
= { .min
= 14, .max
= 42 },
319 .p1
= { .min
= 2, .max
= 6 },
320 .p2
= { .dot_limit
= 0,
321 .p2_slow
= 7, .p2_fast
= 7
325 static const struct intel_limit intel_limits_pineview_sdvo
= {
326 .dot
= { .min
= 20000, .max
= 400000},
327 .vco
= { .min
= 1700000, .max
= 3500000 },
328 /* Pineview's Ncounter is a ring counter */
329 .n
= { .min
= 3, .max
= 6 },
330 .m
= { .min
= 2, .max
= 256 },
331 /* Pineview only has one combined m divider, which we treat as m2. */
332 .m1
= { .min
= 0, .max
= 0 },
333 .m2
= { .min
= 0, .max
= 254 },
334 .p
= { .min
= 5, .max
= 80 },
335 .p1
= { .min
= 1, .max
= 8 },
336 .p2
= { .dot_limit
= 200000,
337 .p2_slow
= 10, .p2_fast
= 5 },
340 static const struct intel_limit intel_limits_pineview_lvds
= {
341 .dot
= { .min
= 20000, .max
= 400000 },
342 .vco
= { .min
= 1700000, .max
= 3500000 },
343 .n
= { .min
= 3, .max
= 6 },
344 .m
= { .min
= 2, .max
= 256 },
345 .m1
= { .min
= 0, .max
= 0 },
346 .m2
= { .min
= 0, .max
= 254 },
347 .p
= { .min
= 7, .max
= 112 },
348 .p1
= { .min
= 1, .max
= 8 },
349 .p2
= { .dot_limit
= 112000,
350 .p2_slow
= 14, .p2_fast
= 14 },
353 /* Ironlake / Sandybridge
355 * We calculate clock using (register_value + 2) for N/M1/M2, so here
356 * the range value for them is (actual_value - 2).
358 static const struct intel_limit intel_limits_ironlake_dac
= {
359 .dot
= { .min
= 25000, .max
= 350000 },
360 .vco
= { .min
= 1760000, .max
= 3510000 },
361 .n
= { .min
= 1, .max
= 5 },
362 .m
= { .min
= 79, .max
= 127 },
363 .m1
= { .min
= 12, .max
= 22 },
364 .m2
= { .min
= 5, .max
= 9 },
365 .p
= { .min
= 5, .max
= 80 },
366 .p1
= { .min
= 1, .max
= 8 },
367 .p2
= { .dot_limit
= 225000,
368 .p2_slow
= 10, .p2_fast
= 5 },
371 static const struct intel_limit intel_limits_ironlake_single_lvds
= {
372 .dot
= { .min
= 25000, .max
= 350000 },
373 .vco
= { .min
= 1760000, .max
= 3510000 },
374 .n
= { .min
= 1, .max
= 3 },
375 .m
= { .min
= 79, .max
= 118 },
376 .m1
= { .min
= 12, .max
= 22 },
377 .m2
= { .min
= 5, .max
= 9 },
378 .p
= { .min
= 28, .max
= 112 },
379 .p1
= { .min
= 2, .max
= 8 },
380 .p2
= { .dot_limit
= 225000,
381 .p2_slow
= 14, .p2_fast
= 14 },
384 static const struct intel_limit intel_limits_ironlake_dual_lvds
= {
385 .dot
= { .min
= 25000, .max
= 350000 },
386 .vco
= { .min
= 1760000, .max
= 3510000 },
387 .n
= { .min
= 1, .max
= 3 },
388 .m
= { .min
= 79, .max
= 127 },
389 .m1
= { .min
= 12, .max
= 22 },
390 .m2
= { .min
= 5, .max
= 9 },
391 .p
= { .min
= 14, .max
= 56 },
392 .p1
= { .min
= 2, .max
= 8 },
393 .p2
= { .dot_limit
= 225000,
394 .p2_slow
= 7, .p2_fast
= 7 },
397 /* LVDS 100mhz refclk limits. */
398 static const struct intel_limit intel_limits_ironlake_single_lvds_100m
= {
399 .dot
= { .min
= 25000, .max
= 350000 },
400 .vco
= { .min
= 1760000, .max
= 3510000 },
401 .n
= { .min
= 1, .max
= 2 },
402 .m
= { .min
= 79, .max
= 126 },
403 .m1
= { .min
= 12, .max
= 22 },
404 .m2
= { .min
= 5, .max
= 9 },
405 .p
= { .min
= 28, .max
= 112 },
406 .p1
= { .min
= 2, .max
= 8 },
407 .p2
= { .dot_limit
= 225000,
408 .p2_slow
= 14, .p2_fast
= 14 },
411 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m
= {
412 .dot
= { .min
= 25000, .max
= 350000 },
413 .vco
= { .min
= 1760000, .max
= 3510000 },
414 .n
= { .min
= 1, .max
= 3 },
415 .m
= { .min
= 79, .max
= 126 },
416 .m1
= { .min
= 12, .max
= 22 },
417 .m2
= { .min
= 5, .max
= 9 },
418 .p
= { .min
= 14, .max
= 42 },
419 .p1
= { .min
= 2, .max
= 6 },
420 .p2
= { .dot_limit
= 225000,
421 .p2_slow
= 7, .p2_fast
= 7 },
424 static const struct intel_limit intel_limits_vlv
= {
426 * These are the data rate limits (measured in fast clocks)
427 * since those are the strictest limits we have. The fast
428 * clock and actual rate limits are more relaxed, so checking
429 * them would make no difference.
431 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
432 .vco
= { .min
= 4000000, .max
= 6000000 },
433 .n
= { .min
= 1, .max
= 7 },
434 .m1
= { .min
= 2, .max
= 3 },
435 .m2
= { .min
= 11, .max
= 156 },
436 .p1
= { .min
= 2, .max
= 3 },
437 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
440 static const struct intel_limit intel_limits_chv
= {
442 * These are the data rate limits (measured in fast clocks)
443 * since those are the strictest limits we have. The fast
444 * clock and actual rate limits are more relaxed, so checking
445 * them would make no difference.
447 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
448 .vco
= { .min
= 4800000, .max
= 6480000 },
449 .n
= { .min
= 1, .max
= 1 },
450 .m1
= { .min
= 2, .max
= 2 },
451 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
452 .p1
= { .min
= 2, .max
= 4 },
453 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
456 static const struct intel_limit intel_limits_bxt
= {
457 /* FIXME: find real dot limits */
458 .dot
= { .min
= 0, .max
= INT_MAX
},
459 .vco
= { .min
= 4800000, .max
= 6700000 },
460 .n
= { .min
= 1, .max
= 1 },
461 .m1
= { .min
= 2, .max
= 2 },
462 /* FIXME: find real m2 limits */
463 .m2
= { .min
= 2 << 22, .max
= 255 << 22 },
464 .p1
= { .min
= 2, .max
= 4 },
465 .p2
= { .p2_slow
= 1, .p2_fast
= 20 },
469 needs_modeset(struct drm_crtc_state
*state
)
471 return drm_atomic_crtc_needs_modeset(state
);
475 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
476 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
477 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
478 * The helpers' return value is the rate of the clock that is fed to the
479 * display engine's pipe which can be the above fast dot clock rate or a
480 * divided-down version of it.
482 /* m1 is reserved as 0 in Pineview, n is a ring counter */
483 static int pnv_calc_dpll_params(int refclk
, struct dpll
*clock
)
485 clock
->m
= clock
->m2
+ 2;
486 clock
->p
= clock
->p1
* clock
->p2
;
487 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
489 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
490 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
495 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
497 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
500 static int i9xx_calc_dpll_params(int refclk
, struct dpll
*clock
)
502 clock
->m
= i9xx_dpll_compute_m(clock
);
503 clock
->p
= clock
->p1
* clock
->p2
;
504 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
506 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
507 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
512 static int vlv_calc_dpll_params(int refclk
, struct dpll
*clock
)
514 clock
->m
= clock
->m1
* clock
->m2
;
515 clock
->p
= clock
->p1
* clock
->p2
;
516 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
518 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
519 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
521 return clock
->dot
/ 5;
524 int chv_calc_dpll_params(int refclk
, struct dpll
*clock
)
526 clock
->m
= clock
->m1
* clock
->m2
;
527 clock
->p
= clock
->p1
* clock
->p2
;
528 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
530 clock
->vco
= DIV_ROUND_CLOSEST_ULL((uint64_t)refclk
* clock
->m
,
532 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
534 return clock
->dot
/ 5;
537 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
539 * Returns whether the given set of divisors are valid for a given refclk with
540 * the given connectors.
543 static bool intel_PLL_is_valid(struct drm_i915_private
*dev_priv
,
544 const struct intel_limit
*limit
,
545 const struct dpll
*clock
)
547 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
548 INTELPllInvalid("n out of range\n");
549 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
550 INTELPllInvalid("p1 out of range\n");
551 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
552 INTELPllInvalid("m2 out of range\n");
553 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
554 INTELPllInvalid("m1 out of range\n");
556 if (!IS_PINEVIEW(dev_priv
) && !IS_VALLEYVIEW(dev_priv
) &&
557 !IS_CHERRYVIEW(dev_priv
) && !IS_GEN9_LP(dev_priv
))
558 if (clock
->m1
<= clock
->m2
)
559 INTELPllInvalid("m1 <= m2\n");
561 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
) &&
562 !IS_GEN9_LP(dev_priv
)) {
563 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
564 INTELPllInvalid("p out of range\n");
565 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
566 INTELPllInvalid("m out of range\n");
569 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
570 INTELPllInvalid("vco out of range\n");
571 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
572 * connector, etc., rather than just a single range.
574 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
575 INTELPllInvalid("dot out of range\n");
581 i9xx_select_p2_div(const struct intel_limit
*limit
,
582 const struct intel_crtc_state
*crtc_state
,
585 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
587 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
589 * For LVDS just rely on its current settings for dual-channel.
590 * We haven't figured out how to reliably set up different
591 * single/dual channel state, if we even can.
593 if (intel_is_dual_link_lvds(dev
))
594 return limit
->p2
.p2_fast
;
596 return limit
->p2
.p2_slow
;
598 if (target
< limit
->p2
.dot_limit
)
599 return limit
->p2
.p2_slow
;
601 return limit
->p2
.p2_fast
;
606 * Returns a set of divisors for the desired target clock with the given
607 * refclk, or FALSE. The returned values represent the clock equation:
608 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
610 * Target and reference clocks are specified in kHz.
612 * If match_clock is provided, then best_clock P divider must match the P
613 * divider from @match_clock used for LVDS downclocking.
616 i9xx_find_best_dpll(const struct intel_limit
*limit
,
617 struct intel_crtc_state
*crtc_state
,
618 int target
, int refclk
, struct dpll
*match_clock
,
619 struct dpll
*best_clock
)
621 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
625 memset(best_clock
, 0, sizeof(*best_clock
));
627 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
629 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
631 for (clock
.m2
= limit
->m2
.min
;
632 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
633 if (clock
.m2
>= clock
.m1
)
635 for (clock
.n
= limit
->n
.min
;
636 clock
.n
<= limit
->n
.max
; clock
.n
++) {
637 for (clock
.p1
= limit
->p1
.min
;
638 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
641 i9xx_calc_dpll_params(refclk
, &clock
);
642 if (!intel_PLL_is_valid(to_i915(dev
),
647 clock
.p
!= match_clock
->p
)
650 this_err
= abs(clock
.dot
- target
);
651 if (this_err
< err
) {
660 return (err
!= target
);
664 * Returns a set of divisors for the desired target clock with the given
665 * refclk, or FALSE. The returned values represent the clock equation:
666 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
668 * Target and reference clocks are specified in kHz.
670 * If match_clock is provided, then best_clock P divider must match the P
671 * divider from @match_clock used for LVDS downclocking.
674 pnv_find_best_dpll(const struct intel_limit
*limit
,
675 struct intel_crtc_state
*crtc_state
,
676 int target
, int refclk
, struct dpll
*match_clock
,
677 struct dpll
*best_clock
)
679 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
683 memset(best_clock
, 0, sizeof(*best_clock
));
685 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
687 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
689 for (clock
.m2
= limit
->m2
.min
;
690 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
691 for (clock
.n
= limit
->n
.min
;
692 clock
.n
<= limit
->n
.max
; clock
.n
++) {
693 for (clock
.p1
= limit
->p1
.min
;
694 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
697 pnv_calc_dpll_params(refclk
, &clock
);
698 if (!intel_PLL_is_valid(to_i915(dev
),
703 clock
.p
!= match_clock
->p
)
706 this_err
= abs(clock
.dot
- target
);
707 if (this_err
< err
) {
716 return (err
!= target
);
720 * Returns a set of divisors for the desired target clock with the given
721 * refclk, or FALSE. The returned values represent the clock equation:
722 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
724 * Target and reference clocks are specified in kHz.
726 * If match_clock is provided, then best_clock P divider must match the P
727 * divider from @match_clock used for LVDS downclocking.
730 g4x_find_best_dpll(const struct intel_limit
*limit
,
731 struct intel_crtc_state
*crtc_state
,
732 int target
, int refclk
, struct dpll
*match_clock
,
733 struct dpll
*best_clock
)
735 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
739 /* approximately equals target * 0.00585 */
740 int err_most
= (target
>> 8) + (target
>> 9);
742 memset(best_clock
, 0, sizeof(*best_clock
));
744 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
746 max_n
= limit
->n
.max
;
747 /* based on hardware requirement, prefer smaller n to precision */
748 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
749 /* based on hardware requirement, prefere larger m1,m2 */
750 for (clock
.m1
= limit
->m1
.max
;
751 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
752 for (clock
.m2
= limit
->m2
.max
;
753 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
754 for (clock
.p1
= limit
->p1
.max
;
755 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
758 i9xx_calc_dpll_params(refclk
, &clock
);
759 if (!intel_PLL_is_valid(to_i915(dev
),
764 this_err
= abs(clock
.dot
- target
);
765 if (this_err
< err_most
) {
779 * Check if the calculated PLL configuration is more optimal compared to the
780 * best configuration and error found so far. Return the calculated error.
782 static bool vlv_PLL_is_optimal(struct drm_device
*dev
, int target_freq
,
783 const struct dpll
*calculated_clock
,
784 const struct dpll
*best_clock
,
785 unsigned int best_error_ppm
,
786 unsigned int *error_ppm
)
789 * For CHV ignore the error and consider only the P value.
790 * Prefer a bigger P value based on HW requirements.
792 if (IS_CHERRYVIEW(to_i915(dev
))) {
795 return calculated_clock
->p
> best_clock
->p
;
798 if (WARN_ON_ONCE(!target_freq
))
801 *error_ppm
= div_u64(1000000ULL *
802 abs(target_freq
- calculated_clock
->dot
),
805 * Prefer a better P value over a better (smaller) error if the error
806 * is small. Ensure this preference for future configurations too by
807 * setting the error to 0.
809 if (*error_ppm
< 100 && calculated_clock
->p
> best_clock
->p
) {
815 return *error_ppm
+ 10 < best_error_ppm
;
819 * Returns a set of divisors for the desired target clock with the given
820 * refclk, or FALSE. The returned values represent the clock equation:
821 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
824 vlv_find_best_dpll(const struct intel_limit
*limit
,
825 struct intel_crtc_state
*crtc_state
,
826 int target
, int refclk
, struct dpll
*match_clock
,
827 struct dpll
*best_clock
)
829 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
830 struct drm_device
*dev
= crtc
->base
.dev
;
832 unsigned int bestppm
= 1000000;
833 /* min update 19.2 MHz */
834 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
837 target
*= 5; /* fast clock */
839 memset(best_clock
, 0, sizeof(*best_clock
));
841 /* based on hardware requirement, prefer smaller n to precision */
842 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
843 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
844 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
845 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
846 clock
.p
= clock
.p1
* clock
.p2
;
847 /* based on hardware requirement, prefer bigger m1,m2 values */
848 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
851 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
854 vlv_calc_dpll_params(refclk
, &clock
);
856 if (!intel_PLL_is_valid(to_i915(dev
),
861 if (!vlv_PLL_is_optimal(dev
, target
,
879 * Returns a set of divisors for the desired target clock with the given
880 * refclk, or FALSE. The returned values represent the clock equation:
881 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
884 chv_find_best_dpll(const struct intel_limit
*limit
,
885 struct intel_crtc_state
*crtc_state
,
886 int target
, int refclk
, struct dpll
*match_clock
,
887 struct dpll
*best_clock
)
889 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
890 struct drm_device
*dev
= crtc
->base
.dev
;
891 unsigned int best_error_ppm
;
896 memset(best_clock
, 0, sizeof(*best_clock
));
897 best_error_ppm
= 1000000;
900 * Based on hardware doc, the n always set to 1, and m1 always
901 * set to 2. If requires to support 200Mhz refclk, we need to
902 * revisit this because n may not 1 anymore.
904 clock
.n
= 1, clock
.m1
= 2;
905 target
*= 5; /* fast clock */
907 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
908 for (clock
.p2
= limit
->p2
.p2_fast
;
909 clock
.p2
>= limit
->p2
.p2_slow
;
910 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
911 unsigned int error_ppm
;
913 clock
.p
= clock
.p1
* clock
.p2
;
915 m2
= DIV_ROUND_CLOSEST_ULL(((uint64_t)target
* clock
.p
*
916 clock
.n
) << 22, refclk
* clock
.m1
);
918 if (m2
> INT_MAX
/clock
.m1
)
923 chv_calc_dpll_params(refclk
, &clock
);
925 if (!intel_PLL_is_valid(to_i915(dev
), limit
, &clock
))
928 if (!vlv_PLL_is_optimal(dev
, target
, &clock
, best_clock
,
929 best_error_ppm
, &error_ppm
))
933 best_error_ppm
= error_ppm
;
941 bool bxt_find_best_dpll(struct intel_crtc_state
*crtc_state
, int target_clock
,
942 struct dpll
*best_clock
)
945 const struct intel_limit
*limit
= &intel_limits_bxt
;
947 return chv_find_best_dpll(limit
, crtc_state
,
948 target_clock
, refclk
, NULL
, best_clock
);
951 bool intel_crtc_active(struct intel_crtc
*crtc
)
953 /* Be paranoid as we can arrive here with only partial
954 * state retrieved from the hardware during setup.
956 * We can ditch the adjusted_mode.crtc_clock check as soon
957 * as Haswell has gained clock readout/fastboot support.
959 * We can ditch the crtc->primary->fb check as soon as we can
960 * properly reconstruct framebuffers.
962 * FIXME: The intel_crtc->active here should be switched to
963 * crtc->state->active once we have proper CRTC states wired up
966 return crtc
->active
&& crtc
->base
.primary
->state
->fb
&&
967 crtc
->config
->base
.adjusted_mode
.crtc_clock
;
970 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
973 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
975 return crtc
->config
->cpu_transcoder
;
978 static bool pipe_dsl_stopped(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
980 i915_reg_t reg
= PIPEDSL(pipe
);
984 if (IS_GEN2(dev_priv
))
985 line_mask
= DSL_LINEMASK_GEN2
;
987 line_mask
= DSL_LINEMASK_GEN3
;
989 line1
= I915_READ(reg
) & line_mask
;
991 line2
= I915_READ(reg
) & line_mask
;
993 return line1
== line2
;
997 * intel_wait_for_pipe_off - wait for pipe to turn off
998 * @crtc: crtc whose pipe to wait for
1000 * After disabling a pipe, we can't wait for vblank in the usual way,
1001 * spinning on the vblank interrupt status bit, since we won't actually
1002 * see an interrupt when the pipe is disabled.
1004 * On Gen4 and above:
1005 * wait for the pipe register state bit to turn off
1008 * wait for the display line value to settle (it usually
1009 * ends up stopping at the start of the next frame).
1012 static void intel_wait_for_pipe_off(struct intel_crtc
*crtc
)
1014 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1015 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1016 enum pipe pipe
= crtc
->pipe
;
1018 if (INTEL_GEN(dev_priv
) >= 4) {
1019 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
1021 /* Wait for the Pipe State to go off */
1022 if (intel_wait_for_register(dev_priv
,
1023 reg
, I965_PIPECONF_ACTIVE
, 0,
1025 WARN(1, "pipe_off wait timed out\n");
1027 /* Wait for the display line to settle */
1028 if (wait_for(pipe_dsl_stopped(dev_priv
, pipe
), 100))
1029 WARN(1, "pipe_off wait timed out\n");
1033 /* Only for pre-ILK configs */
1034 void assert_pll(struct drm_i915_private
*dev_priv
,
1035 enum pipe pipe
, bool state
)
1040 val
= I915_READ(DPLL(pipe
));
1041 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1042 I915_STATE_WARN(cur_state
!= state
,
1043 "PLL state assertion failure (expected %s, current %s)\n",
1044 onoff(state
), onoff(cur_state
));
1047 /* XXX: the dsi pll is shared between MIPI DSI ports */
1048 void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1053 mutex_lock(&dev_priv
->sb_lock
);
1054 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1055 mutex_unlock(&dev_priv
->sb_lock
);
1057 cur_state
= val
& DSI_PLL_VCO_EN
;
1058 I915_STATE_WARN(cur_state
!= state
,
1059 "DSI PLL state assertion failure (expected %s, current %s)\n",
1060 onoff(state
), onoff(cur_state
));
1063 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1064 enum pipe pipe
, bool state
)
1067 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1070 if (HAS_DDI(dev_priv
)) {
1071 /* DDI does not have a specific FDI_TX register */
1072 u32 val
= I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder
));
1073 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1075 u32 val
= I915_READ(FDI_TX_CTL(pipe
));
1076 cur_state
= !!(val
& FDI_TX_ENABLE
);
1078 I915_STATE_WARN(cur_state
!= state
,
1079 "FDI TX state assertion failure (expected %s, current %s)\n",
1080 onoff(state
), onoff(cur_state
));
1082 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1083 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1085 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1086 enum pipe pipe
, bool state
)
1091 val
= I915_READ(FDI_RX_CTL(pipe
));
1092 cur_state
= !!(val
& FDI_RX_ENABLE
);
1093 I915_STATE_WARN(cur_state
!= state
,
1094 "FDI RX state assertion failure (expected %s, current %s)\n",
1095 onoff(state
), onoff(cur_state
));
1097 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1098 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1100 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1105 /* ILK FDI PLL is always enabled */
1106 if (IS_GEN5(dev_priv
))
1109 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1110 if (HAS_DDI(dev_priv
))
1113 val
= I915_READ(FDI_TX_CTL(pipe
));
1114 I915_STATE_WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1117 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1118 enum pipe pipe
, bool state
)
1123 val
= I915_READ(FDI_RX_CTL(pipe
));
1124 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1125 I915_STATE_WARN(cur_state
!= state
,
1126 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1127 onoff(state
), onoff(cur_state
));
1130 void assert_panel_unlocked(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1134 enum pipe panel_pipe
= PIPE_A
;
1137 if (WARN_ON(HAS_DDI(dev_priv
)))
1140 if (HAS_PCH_SPLIT(dev_priv
)) {
1143 pp_reg
= PP_CONTROL(0);
1144 port_sel
= I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK
;
1146 if (port_sel
== PANEL_PORT_SELECT_LVDS
&&
1147 I915_READ(PCH_LVDS
) & LVDS_PIPEB_SELECT
)
1148 panel_pipe
= PIPE_B
;
1149 /* XXX: else fix for eDP */
1150 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
1151 /* presumably write lock depends on pipe, not port select */
1152 pp_reg
= PP_CONTROL(pipe
);
1155 pp_reg
= PP_CONTROL(0);
1156 if (I915_READ(LVDS
) & LVDS_PIPEB_SELECT
)
1157 panel_pipe
= PIPE_B
;
1160 val
= I915_READ(pp_reg
);
1161 if (!(val
& PANEL_POWER_ON
) ||
1162 ((val
& PANEL_UNLOCK_MASK
) == PANEL_UNLOCK_REGS
))
1165 I915_STATE_WARN(panel_pipe
== pipe
&& locked
,
1166 "panel assertion failure, pipe %c regs locked\n",
1170 static void assert_cursor(struct drm_i915_private
*dev_priv
,
1171 enum pipe pipe
, bool state
)
1175 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
))
1176 cur_state
= I915_READ(CURCNTR(PIPE_A
)) & CURSOR_ENABLE
;
1178 cur_state
= I915_READ(CURCNTR(pipe
)) & CURSOR_MODE
;
1180 I915_STATE_WARN(cur_state
!= state
,
1181 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1182 pipe_name(pipe
), onoff(state
), onoff(cur_state
));
1184 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1185 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1187 void assert_pipe(struct drm_i915_private
*dev_priv
,
1188 enum pipe pipe
, bool state
)
1191 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1193 enum intel_display_power_domain power_domain
;
1195 /* if we need the pipe quirk it must be always on */
1196 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1197 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
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) {
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
;
1553 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1555 /* PLL is protected by panel, make sure we can write it */
1556 if (IS_MOBILE(dev_priv
) && !IS_I830(dev_priv
))
1557 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1559 /* Enable DVO 2x clock on both PLLs if necessary */
1560 if (IS_I830(dev_priv
) && intel_num_dvo_pipes(dev_priv
) > 0) {
1562 * It appears to be important that we don't enable this
1563 * for the current pipe before otherwise configuring the
1564 * PLL. No idea how this should be handled if multiple
1565 * DVO outputs are enabled simultaneosly.
1567 dpll
|= DPLL_DVO_2X_MODE
;
1568 I915_WRITE(DPLL(!crtc
->pipe
),
1569 I915_READ(DPLL(!crtc
->pipe
)) | DPLL_DVO_2X_MODE
);
1573 * Apparently we need to have VGA mode enabled prior to changing
1574 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1575 * dividers, even though the register value does change.
1579 I915_WRITE(reg
, dpll
);
1581 /* Wait for the clocks to stabilize. */
1585 if (INTEL_GEN(dev_priv
) >= 4) {
1586 I915_WRITE(DPLL_MD(crtc
->pipe
),
1587 crtc
->config
->dpll_hw_state
.dpll_md
);
1589 /* The pixel multiplier can only be updated once the
1590 * DPLL is enabled and the clocks are stable.
1592 * So write it again.
1594 I915_WRITE(reg
, dpll
);
1597 /* We do this three times for luck */
1598 I915_WRITE(reg
, dpll
);
1600 udelay(150); /* wait for warmup */
1601 I915_WRITE(reg
, dpll
);
1603 udelay(150); /* wait for warmup */
1604 I915_WRITE(reg
, dpll
);
1606 udelay(150); /* wait for warmup */
1610 * i9xx_disable_pll - disable a PLL
1611 * @dev_priv: i915 private structure
1612 * @pipe: pipe PLL to disable
1614 * Disable the PLL for @pipe, making sure the pipe is off first.
1616 * Note! This is for pre-ILK only.
1618 static void i9xx_disable_pll(struct intel_crtc
*crtc
)
1620 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1621 enum pipe pipe
= crtc
->pipe
;
1623 /* Disable DVO 2x clock on both PLLs if necessary */
1624 if (IS_I830(dev_priv
) &&
1625 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_DVO
) &&
1626 !intel_num_dvo_pipes(dev_priv
)) {
1627 I915_WRITE(DPLL(PIPE_B
),
1628 I915_READ(DPLL(PIPE_B
)) & ~DPLL_DVO_2X_MODE
);
1629 I915_WRITE(DPLL(PIPE_A
),
1630 I915_READ(DPLL(PIPE_A
)) & ~DPLL_DVO_2X_MODE
);
1633 /* Don't disable pipe or pipe PLLs if needed */
1634 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1635 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1638 /* Make sure the pipe isn't still relying on us */
1639 assert_pipe_disabled(dev_priv
, pipe
);
1641 I915_WRITE(DPLL(pipe
), DPLL_VGA_MODE_DIS
);
1642 POSTING_READ(DPLL(pipe
));
1645 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1649 /* Make sure the pipe isn't still relying on us */
1650 assert_pipe_disabled(dev_priv
, pipe
);
1652 val
= DPLL_INTEGRATED_REF_CLK_VLV
|
1653 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1655 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1657 I915_WRITE(DPLL(pipe
), val
);
1658 POSTING_READ(DPLL(pipe
));
1661 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1663 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1666 /* Make sure the pipe isn't still relying on us */
1667 assert_pipe_disabled(dev_priv
, pipe
);
1669 val
= DPLL_SSC_REF_CLK_CHV
|
1670 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1672 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1674 I915_WRITE(DPLL(pipe
), val
);
1675 POSTING_READ(DPLL(pipe
));
1677 mutex_lock(&dev_priv
->sb_lock
);
1679 /* Disable 10bit clock to display controller */
1680 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1681 val
&= ~DPIO_DCLKP_EN
;
1682 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1684 mutex_unlock(&dev_priv
->sb_lock
);
1687 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1688 struct intel_digital_port
*dport
,
1689 unsigned int expected_mask
)
1692 i915_reg_t dpll_reg
;
1694 switch (dport
->port
) {
1696 port_mask
= DPLL_PORTB_READY_MASK
;
1700 port_mask
= DPLL_PORTC_READY_MASK
;
1702 expected_mask
<<= 4;
1705 port_mask
= DPLL_PORTD_READY_MASK
;
1706 dpll_reg
= DPIO_PHY_STATUS
;
1712 if (intel_wait_for_register(dev_priv
,
1713 dpll_reg
, port_mask
, expected_mask
,
1715 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1716 port_name(dport
->port
), I915_READ(dpll_reg
) & port_mask
, expected_mask
);
1719 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1722 struct intel_crtc
*intel_crtc
= intel_get_crtc_for_pipe(dev_priv
,
1725 uint32_t val
, pipeconf_val
;
1727 /* Make sure PCH DPLL is enabled */
1728 assert_shared_dpll_enabled(dev_priv
, intel_crtc
->config
->shared_dpll
);
1730 /* FDI must be feeding us bits for PCH ports */
1731 assert_fdi_tx_enabled(dev_priv
, pipe
);
1732 assert_fdi_rx_enabled(dev_priv
, pipe
);
1734 if (HAS_PCH_CPT(dev_priv
)) {
1735 /* Workaround: Set the timing override bit before enabling the
1736 * pch transcoder. */
1737 reg
= TRANS_CHICKEN2(pipe
);
1738 val
= I915_READ(reg
);
1739 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1740 I915_WRITE(reg
, val
);
1743 reg
= PCH_TRANSCONF(pipe
);
1744 val
= I915_READ(reg
);
1745 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1747 if (HAS_PCH_IBX(dev_priv
)) {
1749 * Make the BPC in transcoder be consistent with
1750 * that in pipeconf reg. For HDMI we must use 8bpc
1751 * here for both 8bpc and 12bpc.
1753 val
&= ~PIPECONF_BPC_MASK
;
1754 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_HDMI
))
1755 val
|= PIPECONF_8BPC
;
1757 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
1760 val
&= ~TRANS_INTERLACE_MASK
;
1761 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
1762 if (HAS_PCH_IBX(dev_priv
) &&
1763 intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
1764 val
|= TRANS_LEGACY_INTERLACED_ILK
;
1766 val
|= TRANS_INTERLACED
;
1768 val
|= TRANS_PROGRESSIVE
;
1770 I915_WRITE(reg
, val
| TRANS_ENABLE
);
1771 if (intel_wait_for_register(dev_priv
,
1772 reg
, TRANS_STATE_ENABLE
, TRANS_STATE_ENABLE
,
1774 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
1777 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1778 enum transcoder cpu_transcoder
)
1780 u32 val
, pipeconf_val
;
1782 /* FDI must be feeding us bits for PCH ports */
1783 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
1784 assert_fdi_rx_enabled(dev_priv
, TRANSCODER_A
);
1786 /* Workaround: set timing override bit. */
1787 val
= I915_READ(TRANS_CHICKEN2(PIPE_A
));
1788 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1789 I915_WRITE(TRANS_CHICKEN2(PIPE_A
), val
);
1792 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
1794 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
1795 PIPECONF_INTERLACED_ILK
)
1796 val
|= TRANS_INTERLACED
;
1798 val
|= TRANS_PROGRESSIVE
;
1800 I915_WRITE(LPT_TRANSCONF
, val
);
1801 if (intel_wait_for_register(dev_priv
,
1806 DRM_ERROR("Failed to enable PCH transcoder\n");
1809 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1815 /* FDI relies on the transcoder */
1816 assert_fdi_tx_disabled(dev_priv
, pipe
);
1817 assert_fdi_rx_disabled(dev_priv
, pipe
);
1819 /* Ports must be off as well */
1820 assert_pch_ports_disabled(dev_priv
, pipe
);
1822 reg
= PCH_TRANSCONF(pipe
);
1823 val
= I915_READ(reg
);
1824 val
&= ~TRANS_ENABLE
;
1825 I915_WRITE(reg
, val
);
1826 /* wait for PCH transcoder off, transcoder state */
1827 if (intel_wait_for_register(dev_priv
,
1828 reg
, TRANS_STATE_ENABLE
, 0,
1830 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
1832 if (HAS_PCH_CPT(dev_priv
)) {
1833 /* Workaround: Clear the timing override chicken bit again. */
1834 reg
= TRANS_CHICKEN2(pipe
);
1835 val
= I915_READ(reg
);
1836 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1837 I915_WRITE(reg
, val
);
1841 void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
1845 val
= I915_READ(LPT_TRANSCONF
);
1846 val
&= ~TRANS_ENABLE
;
1847 I915_WRITE(LPT_TRANSCONF
, val
);
1848 /* wait for PCH transcoder off, transcoder state */
1849 if (intel_wait_for_register(dev_priv
,
1850 LPT_TRANSCONF
, TRANS_STATE_ENABLE
, 0,
1852 DRM_ERROR("Failed to disable PCH transcoder\n");
1854 /* Workaround: clear timing override bit. */
1855 val
= I915_READ(TRANS_CHICKEN2(PIPE_A
));
1856 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1857 I915_WRITE(TRANS_CHICKEN2(PIPE_A
), val
);
1860 enum transcoder
intel_crtc_pch_transcoder(struct intel_crtc
*crtc
)
1862 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1864 WARN_ON(!crtc
->config
->has_pch_encoder
);
1866 if (HAS_PCH_LPT(dev_priv
))
1867 return TRANSCODER_A
;
1869 return (enum transcoder
) crtc
->pipe
;
1873 * intel_enable_pipe - enable a pipe, asserting requirements
1874 * @crtc: crtc responsible for the pipe
1876 * Enable @crtc's pipe, making sure that various hardware specific requirements
1877 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
1879 static void intel_enable_pipe(struct intel_crtc
*crtc
)
1881 struct drm_device
*dev
= crtc
->base
.dev
;
1882 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1883 enum pipe pipe
= crtc
->pipe
;
1884 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1888 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe
));
1890 assert_planes_disabled(dev_priv
, pipe
);
1891 assert_cursor_disabled(dev_priv
, pipe
);
1892 assert_sprites_disabled(dev_priv
, pipe
);
1895 * A pipe without a PLL won't actually be able to drive bits from
1896 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1899 if (HAS_GMCH_DISPLAY(dev_priv
)) {
1900 if (intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_DSI
))
1901 assert_dsi_pll_enabled(dev_priv
);
1903 assert_pll_enabled(dev_priv
, pipe
);
1905 if (crtc
->config
->has_pch_encoder
) {
1906 /* if driving the PCH, we need FDI enabled */
1907 assert_fdi_rx_pll_enabled(dev_priv
,
1908 (enum pipe
) intel_crtc_pch_transcoder(crtc
));
1909 assert_fdi_tx_pll_enabled(dev_priv
,
1910 (enum pipe
) cpu_transcoder
);
1912 /* FIXME: assert CPU port conditions for SNB+ */
1915 reg
= PIPECONF(cpu_transcoder
);
1916 val
= I915_READ(reg
);
1917 if (val
& PIPECONF_ENABLE
) {
1918 WARN_ON(!((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1919 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
)));
1923 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
1927 * Until the pipe starts DSL will read as 0, which would cause
1928 * an apparent vblank timestamp jump, which messes up also the
1929 * frame count when it's derived from the timestamps. So let's
1930 * wait for the pipe to start properly before we call
1931 * drm_crtc_vblank_on()
1933 if (dev
->max_vblank_count
== 0 &&
1934 wait_for(intel_get_crtc_scanline(crtc
) != crtc
->scanline_offset
, 50))
1935 DRM_ERROR("pipe %c didn't start\n", pipe_name(pipe
));
1939 * intel_disable_pipe - disable a pipe, asserting requirements
1940 * @crtc: crtc whose pipes is to be disabled
1942 * Disable the pipe of @crtc, making sure that various hardware
1943 * specific requirements are met, if applicable, e.g. plane
1944 * disabled, panel fitter off, etc.
1946 * Will wait until the pipe has shut down before returning.
1948 static void intel_disable_pipe(struct intel_crtc
*crtc
)
1950 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1951 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1952 enum pipe pipe
= crtc
->pipe
;
1956 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe
));
1959 * Make sure planes won't keep trying to pump pixels to us,
1960 * or we might hang the display.
1962 assert_planes_disabled(dev_priv
, pipe
);
1963 assert_cursor_disabled(dev_priv
, pipe
);
1964 assert_sprites_disabled(dev_priv
, pipe
);
1966 reg
= PIPECONF(cpu_transcoder
);
1967 val
= I915_READ(reg
);
1968 if ((val
& PIPECONF_ENABLE
) == 0)
1972 * Double wide has implications for planes
1973 * so best keep it disabled when not needed.
1975 if (crtc
->config
->double_wide
)
1976 val
&= ~PIPECONF_DOUBLE_WIDE
;
1978 /* Don't disable pipe or pipe PLLs if needed */
1979 if (!(pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) &&
1980 !(pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1981 val
&= ~PIPECONF_ENABLE
;
1983 I915_WRITE(reg
, val
);
1984 if ((val
& PIPECONF_ENABLE
) == 0)
1985 intel_wait_for_pipe_off(crtc
);
1988 static unsigned int intel_tile_size(const struct drm_i915_private
*dev_priv
)
1990 return IS_GEN2(dev_priv
) ? 2048 : 4096;
1994 intel_tile_width_bytes(const struct drm_framebuffer
*fb
, int plane
)
1996 struct drm_i915_private
*dev_priv
= to_i915(fb
->dev
);
1997 unsigned int cpp
= fb
->format
->cpp
[plane
];
1999 switch (fb
->modifier
) {
2000 case DRM_FORMAT_MOD_NONE
:
2002 case I915_FORMAT_MOD_X_TILED
:
2003 if (IS_GEN2(dev_priv
))
2007 case I915_FORMAT_MOD_Y_TILED
:
2008 if (IS_GEN2(dev_priv
) || HAS_128_BYTE_Y_TILING(dev_priv
))
2012 case I915_FORMAT_MOD_Yf_TILED
:
2028 MISSING_CASE(fb
->modifier
);
2034 intel_tile_height(const struct drm_framebuffer
*fb
, int plane
)
2036 if (fb
->modifier
== DRM_FORMAT_MOD_NONE
)
2039 return intel_tile_size(to_i915(fb
->dev
)) /
2040 intel_tile_width_bytes(fb
, plane
);
2043 /* Return the tile dimensions in pixel units */
2044 static void intel_tile_dims(const struct drm_framebuffer
*fb
, int plane
,
2045 unsigned int *tile_width
,
2046 unsigned int *tile_height
)
2048 unsigned int tile_width_bytes
= intel_tile_width_bytes(fb
, plane
);
2049 unsigned int cpp
= fb
->format
->cpp
[plane
];
2051 *tile_width
= tile_width_bytes
/ cpp
;
2052 *tile_height
= intel_tile_size(to_i915(fb
->dev
)) / tile_width_bytes
;
2056 intel_fb_align_height(const struct drm_framebuffer
*fb
,
2057 int plane
, unsigned int height
)
2059 unsigned int tile_height
= intel_tile_height(fb
, plane
);
2061 return ALIGN(height
, tile_height
);
2064 unsigned int intel_rotation_info_size(const struct intel_rotation_info
*rot_info
)
2066 unsigned int size
= 0;
2069 for (i
= 0 ; i
< ARRAY_SIZE(rot_info
->plane
); i
++)
2070 size
+= rot_info
->plane
[i
].width
* rot_info
->plane
[i
].height
;
2076 intel_fill_fb_ggtt_view(struct i915_ggtt_view
*view
,
2077 const struct drm_framebuffer
*fb
,
2078 unsigned int rotation
)
2080 view
->type
= I915_GGTT_VIEW_NORMAL
;
2081 if (drm_rotation_90_or_270(rotation
)) {
2082 view
->type
= I915_GGTT_VIEW_ROTATED
;
2083 view
->rotated
= to_intel_framebuffer(fb
)->rot_info
;
2087 static unsigned int intel_linear_alignment(const struct drm_i915_private
*dev_priv
)
2089 if (INTEL_INFO(dev_priv
)->gen
>= 9)
2091 else if (IS_I965G(dev_priv
) || IS_I965GM(dev_priv
) ||
2092 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
2094 else if (INTEL_INFO(dev_priv
)->gen
>= 4)
2100 static unsigned int intel_surf_alignment(const struct drm_framebuffer
*fb
,
2103 struct drm_i915_private
*dev_priv
= to_i915(fb
->dev
);
2105 /* AUX_DIST needs only 4K alignment */
2106 if (fb
->format
->format
== DRM_FORMAT_NV12
&& plane
== 1)
2109 switch (fb
->modifier
) {
2110 case DRM_FORMAT_MOD_NONE
:
2111 return intel_linear_alignment(dev_priv
);
2112 case I915_FORMAT_MOD_X_TILED
:
2113 if (INTEL_GEN(dev_priv
) >= 9)
2116 case I915_FORMAT_MOD_Y_TILED
:
2117 case I915_FORMAT_MOD_Yf_TILED
:
2118 return 1 * 1024 * 1024;
2120 MISSING_CASE(fb
->modifier
);
2126 intel_pin_and_fence_fb_obj(struct drm_framebuffer
*fb
, unsigned int rotation
)
2128 struct drm_device
*dev
= fb
->dev
;
2129 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2130 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2131 struct i915_ggtt_view view
;
2132 struct i915_vma
*vma
;
2135 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
2137 alignment
= intel_surf_alignment(fb
, 0);
2139 intel_fill_fb_ggtt_view(&view
, fb
, rotation
);
2141 /* Note that the w/a also requires 64 PTE of padding following the
2142 * bo. We currently fill all unused PTE with the shadow page and so
2143 * we should always have valid PTE following the scanout preventing
2146 if (intel_scanout_needs_vtd_wa(dev_priv
) && alignment
< 256 * 1024)
2147 alignment
= 256 * 1024;
2150 * Global gtt pte registers are special registers which actually forward
2151 * writes to a chunk of system memory. Which means that there is no risk
2152 * that the register values disappear as soon as we call
2153 * intel_runtime_pm_put(), so it is correct to wrap only the
2154 * pin/unpin/fence and not more.
2156 intel_runtime_pm_get(dev_priv
);
2158 vma
= i915_gem_object_pin_to_display_plane(obj
, alignment
, &view
);
2162 if (i915_vma_is_map_and_fenceable(vma
)) {
2163 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2164 * fence, whereas 965+ only requires a fence if using
2165 * framebuffer compression. For simplicity, we always, when
2166 * possible, install a fence as the cost is not that onerous.
2168 * If we fail to fence the tiled scanout, then either the
2169 * modeset will reject the change (which is highly unlikely as
2170 * the affected systems, all but one, do not have unmappable
2171 * space) or we will not be able to enable full powersaving
2172 * techniques (also likely not to apply due to various limits
2173 * FBC and the like impose on the size of the buffer, which
2174 * presumably we violated anyway with this unmappable buffer).
2175 * Anyway, it is presumably better to stumble onwards with
2176 * something and try to run the system in a "less than optimal"
2177 * mode that matches the user configuration.
2179 if (i915_vma_get_fence(vma
) == 0)
2180 i915_vma_pin_fence(vma
);
2185 intel_runtime_pm_put(dev_priv
);
2189 void intel_unpin_fb_vma(struct i915_vma
*vma
)
2191 lockdep_assert_held(&vma
->vm
->i915
->drm
.struct_mutex
);
2193 i915_vma_unpin_fence(vma
);
2194 i915_gem_object_unpin_from_display_plane(vma
);
2198 static int intel_fb_pitch(const struct drm_framebuffer
*fb
, int plane
,
2199 unsigned int rotation
)
2201 if (drm_rotation_90_or_270(rotation
))
2202 return to_intel_framebuffer(fb
)->rotated
[plane
].pitch
;
2204 return fb
->pitches
[plane
];
2208 * Convert the x/y offsets into a linear offset.
2209 * Only valid with 0/180 degree rotation, which is fine since linear
2210 * offset is only used with linear buffers on pre-hsw and tiled buffers
2211 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2213 u32
intel_fb_xy_to_linear(int x
, int y
,
2214 const struct intel_plane_state
*state
,
2217 const struct drm_framebuffer
*fb
= state
->base
.fb
;
2218 unsigned int cpp
= fb
->format
->cpp
[plane
];
2219 unsigned int pitch
= fb
->pitches
[plane
];
2221 return y
* pitch
+ x
* cpp
;
2225 * Add the x/y offsets derived from fb->offsets[] to the user
2226 * specified plane src x/y offsets. The resulting x/y offsets
2227 * specify the start of scanout from the beginning of the gtt mapping.
2229 void intel_add_fb_offsets(int *x
, int *y
,
2230 const struct intel_plane_state
*state
,
2234 const struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(state
->base
.fb
);
2235 unsigned int rotation
= state
->base
.rotation
;
2237 if (drm_rotation_90_or_270(rotation
)) {
2238 *x
+= intel_fb
->rotated
[plane
].x
;
2239 *y
+= intel_fb
->rotated
[plane
].y
;
2241 *x
+= intel_fb
->normal
[plane
].x
;
2242 *y
+= intel_fb
->normal
[plane
].y
;
2247 * Input tile dimensions and pitch must already be
2248 * rotated to match x and y, and in pixel units.
2250 static u32
_intel_adjust_tile_offset(int *x
, int *y
,
2251 unsigned int tile_width
,
2252 unsigned int tile_height
,
2253 unsigned int tile_size
,
2254 unsigned int pitch_tiles
,
2258 unsigned int pitch_pixels
= pitch_tiles
* tile_width
;
2261 WARN_ON(old_offset
& (tile_size
- 1));
2262 WARN_ON(new_offset
& (tile_size
- 1));
2263 WARN_ON(new_offset
> old_offset
);
2265 tiles
= (old_offset
- new_offset
) / tile_size
;
2267 *y
+= tiles
/ pitch_tiles
* tile_height
;
2268 *x
+= tiles
% pitch_tiles
* tile_width
;
2270 /* minimize x in case it got needlessly big */
2271 *y
+= *x
/ pitch_pixels
* tile_height
;
2278 * Adjust the tile offset by moving the difference into
2281 static u32
intel_adjust_tile_offset(int *x
, int *y
,
2282 const struct intel_plane_state
*state
, int plane
,
2283 u32 old_offset
, u32 new_offset
)
2285 const struct drm_i915_private
*dev_priv
= to_i915(state
->base
.plane
->dev
);
2286 const struct drm_framebuffer
*fb
= state
->base
.fb
;
2287 unsigned int cpp
= fb
->format
->cpp
[plane
];
2288 unsigned int rotation
= state
->base
.rotation
;
2289 unsigned int pitch
= intel_fb_pitch(fb
, plane
, rotation
);
2291 WARN_ON(new_offset
> old_offset
);
2293 if (fb
->modifier
!= DRM_FORMAT_MOD_NONE
) {
2294 unsigned int tile_size
, tile_width
, tile_height
;
2295 unsigned int pitch_tiles
;
2297 tile_size
= intel_tile_size(dev_priv
);
2298 intel_tile_dims(fb
, plane
, &tile_width
, &tile_height
);
2300 if (drm_rotation_90_or_270(rotation
)) {
2301 pitch_tiles
= pitch
/ tile_height
;
2302 swap(tile_width
, tile_height
);
2304 pitch_tiles
= pitch
/ (tile_width
* cpp
);
2307 _intel_adjust_tile_offset(x
, y
, tile_width
, tile_height
,
2308 tile_size
, pitch_tiles
,
2309 old_offset
, new_offset
);
2311 old_offset
+= *y
* pitch
+ *x
* cpp
;
2313 *y
= (old_offset
- new_offset
) / pitch
;
2314 *x
= ((old_offset
- new_offset
) - *y
* pitch
) / cpp
;
2321 * Computes the linear offset to the base tile and adjusts
2322 * x, y. bytes per pixel is assumed to be a power-of-two.
2324 * In the 90/270 rotated case, x and y are assumed
2325 * to be already rotated to match the rotated GTT view, and
2326 * pitch is the tile_height aligned framebuffer height.
2328 * This function is used when computing the derived information
2329 * under intel_framebuffer, so using any of that information
2330 * here is not allowed. Anything under drm_framebuffer can be
2331 * used. This is why the user has to pass in the pitch since it
2332 * is specified in the rotated orientation.
2334 static u32
_intel_compute_tile_offset(const struct drm_i915_private
*dev_priv
,
2336 const struct drm_framebuffer
*fb
, int plane
,
2338 unsigned int rotation
,
2341 uint64_t fb_modifier
= fb
->modifier
;
2342 unsigned int cpp
= fb
->format
->cpp
[plane
];
2343 u32 offset
, offset_aligned
;
2348 if (fb_modifier
!= DRM_FORMAT_MOD_NONE
) {
2349 unsigned int tile_size
, tile_width
, tile_height
;
2350 unsigned int tile_rows
, tiles
, pitch_tiles
;
2352 tile_size
= intel_tile_size(dev_priv
);
2353 intel_tile_dims(fb
, plane
, &tile_width
, &tile_height
);
2355 if (drm_rotation_90_or_270(rotation
)) {
2356 pitch_tiles
= pitch
/ tile_height
;
2357 swap(tile_width
, tile_height
);
2359 pitch_tiles
= pitch
/ (tile_width
* cpp
);
2362 tile_rows
= *y
/ tile_height
;
2365 tiles
= *x
/ tile_width
;
2368 offset
= (tile_rows
* pitch_tiles
+ tiles
) * tile_size
;
2369 offset_aligned
= offset
& ~alignment
;
2371 _intel_adjust_tile_offset(x
, y
, tile_width
, tile_height
,
2372 tile_size
, pitch_tiles
,
2373 offset
, offset_aligned
);
2375 offset
= *y
* pitch
+ *x
* cpp
;
2376 offset_aligned
= offset
& ~alignment
;
2378 *y
= (offset
& alignment
) / pitch
;
2379 *x
= ((offset
& alignment
) - *y
* pitch
) / cpp
;
2382 return offset_aligned
;
2385 u32
intel_compute_tile_offset(int *x
, int *y
,
2386 const struct intel_plane_state
*state
,
2389 const struct drm_i915_private
*dev_priv
= to_i915(state
->base
.plane
->dev
);
2390 const struct drm_framebuffer
*fb
= state
->base
.fb
;
2391 unsigned int rotation
= state
->base
.rotation
;
2392 int pitch
= intel_fb_pitch(fb
, plane
, rotation
);
2393 u32 alignment
= intel_surf_alignment(fb
, plane
);
2395 return _intel_compute_tile_offset(dev_priv
, x
, y
, fb
, plane
, pitch
,
2396 rotation
, alignment
);
2399 /* Convert the fb->offset[] linear offset into x/y offsets */
2400 static void intel_fb_offset_to_xy(int *x
, int *y
,
2401 const struct drm_framebuffer
*fb
, int plane
)
2403 unsigned int cpp
= fb
->format
->cpp
[plane
];
2404 unsigned int pitch
= fb
->pitches
[plane
];
2405 u32 linear_offset
= fb
->offsets
[plane
];
2407 *y
= linear_offset
/ pitch
;
2408 *x
= linear_offset
% pitch
/ cpp
;
2411 static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier
)
2413 switch (fb_modifier
) {
2414 case I915_FORMAT_MOD_X_TILED
:
2415 return I915_TILING_X
;
2416 case I915_FORMAT_MOD_Y_TILED
:
2417 return I915_TILING_Y
;
2419 return I915_TILING_NONE
;
2424 intel_fill_fb_info(struct drm_i915_private
*dev_priv
,
2425 struct drm_framebuffer
*fb
)
2427 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
2428 struct intel_rotation_info
*rot_info
= &intel_fb
->rot_info
;
2429 u32 gtt_offset_rotated
= 0;
2430 unsigned int max_size
= 0;
2431 int i
, num_planes
= fb
->format
->num_planes
;
2432 unsigned int tile_size
= intel_tile_size(dev_priv
);
2434 for (i
= 0; i
< num_planes
; i
++) {
2435 unsigned int width
, height
;
2436 unsigned int cpp
, size
;
2440 cpp
= fb
->format
->cpp
[i
];
2441 width
= drm_framebuffer_plane_width(fb
->width
, fb
, i
);
2442 height
= drm_framebuffer_plane_height(fb
->height
, fb
, i
);
2444 intel_fb_offset_to_xy(&x
, &y
, fb
, i
);
2447 * The fence (if used) is aligned to the start of the object
2448 * so having the framebuffer wrap around across the edge of the
2449 * fenced region doesn't really work. We have no API to configure
2450 * the fence start offset within the object (nor could we probably
2451 * on gen2/3). So it's just easier if we just require that the
2452 * fb layout agrees with the fence layout. We already check that the
2453 * fb stride matches the fence stride elsewhere.
2455 if (i915_gem_object_is_tiled(intel_fb
->obj
) &&
2456 (x
+ width
) * cpp
> fb
->pitches
[i
]) {
2457 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2463 * First pixel of the framebuffer from
2464 * the start of the normal gtt mapping.
2466 intel_fb
->normal
[i
].x
= x
;
2467 intel_fb
->normal
[i
].y
= y
;
2469 offset
= _intel_compute_tile_offset(dev_priv
, &x
, &y
,
2470 fb
, i
, fb
->pitches
[i
],
2471 DRM_ROTATE_0
, tile_size
);
2472 offset
/= tile_size
;
2474 if (fb
->modifier
!= DRM_FORMAT_MOD_NONE
) {
2475 unsigned int tile_width
, tile_height
;
2476 unsigned int pitch_tiles
;
2479 intel_tile_dims(fb
, i
, &tile_width
, &tile_height
);
2481 rot_info
->plane
[i
].offset
= offset
;
2482 rot_info
->plane
[i
].stride
= DIV_ROUND_UP(fb
->pitches
[i
], tile_width
* cpp
);
2483 rot_info
->plane
[i
].width
= DIV_ROUND_UP(x
+ width
, tile_width
);
2484 rot_info
->plane
[i
].height
= DIV_ROUND_UP(y
+ height
, tile_height
);
2486 intel_fb
->rotated
[i
].pitch
=
2487 rot_info
->plane
[i
].height
* tile_height
;
2489 /* how many tiles does this plane need */
2490 size
= rot_info
->plane
[i
].stride
* rot_info
->plane
[i
].height
;
2492 * If the plane isn't horizontally tile aligned,
2493 * we need one more tile.
2498 /* rotate the x/y offsets to match the GTT view */
2504 rot_info
->plane
[i
].width
* tile_width
,
2505 rot_info
->plane
[i
].height
* tile_height
,
2510 /* rotate the tile dimensions to match the GTT view */
2511 pitch_tiles
= intel_fb
->rotated
[i
].pitch
/ tile_height
;
2512 swap(tile_width
, tile_height
);
2515 * We only keep the x/y offsets, so push all of the
2516 * gtt offset into the x/y offsets.
2518 _intel_adjust_tile_offset(&x
, &y
,
2519 tile_width
, tile_height
,
2520 tile_size
, pitch_tiles
,
2521 gtt_offset_rotated
* tile_size
, 0);
2523 gtt_offset_rotated
+= rot_info
->plane
[i
].width
* rot_info
->plane
[i
].height
;
2526 * First pixel of the framebuffer from
2527 * the start of the rotated gtt mapping.
2529 intel_fb
->rotated
[i
].x
= x
;
2530 intel_fb
->rotated
[i
].y
= y
;
2532 size
= DIV_ROUND_UP((y
+ height
) * fb
->pitches
[i
] +
2533 x
* cpp
, tile_size
);
2536 /* how many tiles in total needed in the bo */
2537 max_size
= max(max_size
, offset
+ size
);
2540 if (max_size
* tile_size
> intel_fb
->obj
->base
.size
) {
2541 DRM_DEBUG_KMS("fb too big for bo (need %u bytes, have %zu bytes)\n",
2542 max_size
* tile_size
, intel_fb
->obj
->base
.size
);
2549 static int i9xx_format_to_fourcc(int format
)
2552 case DISPPLANE_8BPP
:
2553 return DRM_FORMAT_C8
;
2554 case DISPPLANE_BGRX555
:
2555 return DRM_FORMAT_XRGB1555
;
2556 case DISPPLANE_BGRX565
:
2557 return DRM_FORMAT_RGB565
;
2559 case DISPPLANE_BGRX888
:
2560 return DRM_FORMAT_XRGB8888
;
2561 case DISPPLANE_RGBX888
:
2562 return DRM_FORMAT_XBGR8888
;
2563 case DISPPLANE_BGRX101010
:
2564 return DRM_FORMAT_XRGB2101010
;
2565 case DISPPLANE_RGBX101010
:
2566 return DRM_FORMAT_XBGR2101010
;
2570 static int skl_format_to_fourcc(int format
, bool rgb_order
, bool alpha
)
2573 case PLANE_CTL_FORMAT_RGB_565
:
2574 return DRM_FORMAT_RGB565
;
2576 case PLANE_CTL_FORMAT_XRGB_8888
:
2579 return DRM_FORMAT_ABGR8888
;
2581 return DRM_FORMAT_XBGR8888
;
2584 return DRM_FORMAT_ARGB8888
;
2586 return DRM_FORMAT_XRGB8888
;
2588 case PLANE_CTL_FORMAT_XRGB_2101010
:
2590 return DRM_FORMAT_XBGR2101010
;
2592 return DRM_FORMAT_XRGB2101010
;
2597 intel_alloc_initial_plane_obj(struct intel_crtc
*crtc
,
2598 struct intel_initial_plane_config
*plane_config
)
2600 struct drm_device
*dev
= crtc
->base
.dev
;
2601 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2602 struct i915_ggtt
*ggtt
= &dev_priv
->ggtt
;
2603 struct drm_i915_gem_object
*obj
= NULL
;
2604 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2605 struct drm_framebuffer
*fb
= &plane_config
->fb
->base
;
2606 u32 base_aligned
= round_down(plane_config
->base
, PAGE_SIZE
);
2607 u32 size_aligned
= round_up(plane_config
->base
+ plane_config
->size
,
2610 size_aligned
-= base_aligned
;
2612 if (plane_config
->size
== 0)
2615 /* If the FB is too big, just don't use it since fbdev is not very
2616 * important and we should probably use that space with FBC or other
2618 if (size_aligned
* 2 > ggtt
->stolen_usable_size
)
2621 mutex_lock(&dev
->struct_mutex
);
2622 obj
= i915_gem_object_create_stolen_for_preallocated(dev_priv
,
2626 mutex_unlock(&dev
->struct_mutex
);
2630 if (plane_config
->tiling
== I915_TILING_X
)
2631 obj
->tiling_and_stride
= fb
->pitches
[0] | I915_TILING_X
;
2633 mode_cmd
.pixel_format
= fb
->format
->format
;
2634 mode_cmd
.width
= fb
->width
;
2635 mode_cmd
.height
= fb
->height
;
2636 mode_cmd
.pitches
[0] = fb
->pitches
[0];
2637 mode_cmd
.modifier
[0] = fb
->modifier
;
2638 mode_cmd
.flags
= DRM_MODE_FB_MODIFIERS
;
2640 if (intel_framebuffer_init(to_intel_framebuffer(fb
), obj
, &mode_cmd
)) {
2641 DRM_DEBUG_KMS("intel fb init failed\n");
2646 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj
);
2650 i915_gem_object_put(obj
);
2654 /* Update plane->state->fb to match plane->fb after driver-internal updates */
2656 update_state_fb(struct drm_plane
*plane
)
2658 if (plane
->fb
== plane
->state
->fb
)
2661 if (plane
->state
->fb
)
2662 drm_framebuffer_unreference(plane
->state
->fb
);
2663 plane
->state
->fb
= plane
->fb
;
2664 if (plane
->state
->fb
)
2665 drm_framebuffer_reference(plane
->state
->fb
);
2669 intel_set_plane_visible(struct intel_crtc_state
*crtc_state
,
2670 struct intel_plane_state
*plane_state
,
2673 struct intel_plane
*plane
= to_intel_plane(plane_state
->base
.plane
);
2675 plane_state
->base
.visible
= visible
;
2677 /* FIXME pre-g4x don't work like this */
2679 crtc_state
->base
.plane_mask
|= BIT(drm_plane_index(&plane
->base
));
2680 crtc_state
->active_planes
|= BIT(plane
->id
);
2682 crtc_state
->base
.plane_mask
&= ~BIT(drm_plane_index(&plane
->base
));
2683 crtc_state
->active_planes
&= ~BIT(plane
->id
);
2686 DRM_DEBUG_KMS("%s active planes 0x%x\n",
2687 crtc_state
->base
.crtc
->name
,
2688 crtc_state
->active_planes
);
2692 intel_find_initial_plane_obj(struct intel_crtc
*intel_crtc
,
2693 struct intel_initial_plane_config
*plane_config
)
2695 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2696 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2698 struct drm_i915_gem_object
*obj
;
2699 struct drm_plane
*primary
= intel_crtc
->base
.primary
;
2700 struct drm_plane_state
*plane_state
= primary
->state
;
2701 struct drm_crtc_state
*crtc_state
= intel_crtc
->base
.state
;
2702 struct intel_plane
*intel_plane
= to_intel_plane(primary
);
2703 struct intel_plane_state
*intel_state
=
2704 to_intel_plane_state(plane_state
);
2705 struct drm_framebuffer
*fb
;
2707 if (!plane_config
->fb
)
2710 if (intel_alloc_initial_plane_obj(intel_crtc
, plane_config
)) {
2711 fb
= &plane_config
->fb
->base
;
2715 kfree(plane_config
->fb
);
2718 * Failed to alloc the obj, check to see if we should share
2719 * an fb with another CRTC instead
2721 for_each_crtc(dev
, c
) {
2722 struct intel_plane_state
*state
;
2724 if (c
== &intel_crtc
->base
)
2727 if (!to_intel_crtc(c
)->active
)
2730 state
= to_intel_plane_state(c
->primary
->state
);
2734 if (intel_plane_ggtt_offset(state
) == plane_config
->base
) {
2735 fb
= c
->primary
->fb
;
2736 drm_framebuffer_reference(fb
);
2742 * We've failed to reconstruct the BIOS FB. Current display state
2743 * indicates that the primary plane is visible, but has a NULL FB,
2744 * which will lead to problems later if we don't fix it up. The
2745 * simplest solution is to just disable the primary plane now and
2746 * pretend the BIOS never had it enabled.
2748 intel_set_plane_visible(to_intel_crtc_state(crtc_state
),
2749 to_intel_plane_state(plane_state
),
2751 intel_pre_disable_primary_noatomic(&intel_crtc
->base
);
2752 trace_intel_disable_plane(primary
, intel_crtc
);
2753 intel_plane
->disable_plane(primary
, &intel_crtc
->base
);
2758 mutex_lock(&dev
->struct_mutex
);
2760 intel_pin_and_fence_fb_obj(fb
, primary
->state
->rotation
);
2761 mutex_unlock(&dev
->struct_mutex
);
2762 if (IS_ERR(intel_state
->vma
)) {
2763 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2764 intel_crtc
->pipe
, PTR_ERR(intel_state
->vma
));
2766 intel_state
->vma
= NULL
;
2767 drm_framebuffer_unreference(fb
);
2771 plane_state
->src_x
= 0;
2772 plane_state
->src_y
= 0;
2773 plane_state
->src_w
= fb
->width
<< 16;
2774 plane_state
->src_h
= fb
->height
<< 16;
2776 plane_state
->crtc_x
= 0;
2777 plane_state
->crtc_y
= 0;
2778 plane_state
->crtc_w
= fb
->width
;
2779 plane_state
->crtc_h
= fb
->height
;
2781 intel_state
->base
.src
= drm_plane_state_src(plane_state
);
2782 intel_state
->base
.dst
= drm_plane_state_dest(plane_state
);
2784 obj
= intel_fb_obj(fb
);
2785 if (i915_gem_object_is_tiled(obj
))
2786 dev_priv
->preserve_bios_swizzle
= true;
2788 drm_framebuffer_reference(fb
);
2789 primary
->fb
= primary
->state
->fb
= fb
;
2790 primary
->crtc
= primary
->state
->crtc
= &intel_crtc
->base
;
2792 intel_set_plane_visible(to_intel_crtc_state(crtc_state
),
2793 to_intel_plane_state(plane_state
),
2796 atomic_or(to_intel_plane(primary
)->frontbuffer_bit
,
2797 &obj
->frontbuffer_bits
);
2800 static int skl_max_plane_width(const struct drm_framebuffer
*fb
, int plane
,
2801 unsigned int rotation
)
2803 int cpp
= fb
->format
->cpp
[plane
];
2805 switch (fb
->modifier
) {
2806 case DRM_FORMAT_MOD_NONE
:
2807 case I915_FORMAT_MOD_X_TILED
:
2820 case I915_FORMAT_MOD_Y_TILED
:
2821 case I915_FORMAT_MOD_Yf_TILED
:
2836 MISSING_CASE(fb
->modifier
);
2842 static int skl_check_main_surface(struct intel_plane_state
*plane_state
)
2844 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2845 unsigned int rotation
= plane_state
->base
.rotation
;
2846 int x
= plane_state
->base
.src
.x1
>> 16;
2847 int y
= plane_state
->base
.src
.y1
>> 16;
2848 int w
= drm_rect_width(&plane_state
->base
.src
) >> 16;
2849 int h
= drm_rect_height(&plane_state
->base
.src
) >> 16;
2850 int max_width
= skl_max_plane_width(fb
, 0, rotation
);
2851 int max_height
= 4096;
2852 u32 alignment
, offset
, aux_offset
= plane_state
->aux
.offset
;
2854 if (w
> max_width
|| h
> max_height
) {
2855 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
2856 w
, h
, max_width
, max_height
);
2860 intel_add_fb_offsets(&x
, &y
, plane_state
, 0);
2861 offset
= intel_compute_tile_offset(&x
, &y
, plane_state
, 0);
2862 alignment
= intel_surf_alignment(fb
, 0);
2865 * AUX surface offset is specified as the distance from the
2866 * main surface offset, and it must be non-negative. Make
2867 * sure that is what we will get.
2869 if (offset
> aux_offset
)
2870 offset
= intel_adjust_tile_offset(&x
, &y
, plane_state
, 0,
2871 offset
, aux_offset
& ~(alignment
- 1));
2874 * When using an X-tiled surface, the plane blows up
2875 * if the x offset + width exceed the stride.
2877 * TODO: linear and Y-tiled seem fine, Yf untested,
2879 if (fb
->modifier
== I915_FORMAT_MOD_X_TILED
) {
2880 int cpp
= fb
->format
->cpp
[0];
2882 while ((x
+ w
) * cpp
> fb
->pitches
[0]) {
2884 DRM_DEBUG_KMS("Unable to find suitable display surface offset\n");
2888 offset
= intel_adjust_tile_offset(&x
, &y
, plane_state
, 0,
2889 offset
, offset
- alignment
);
2893 plane_state
->main
.offset
= offset
;
2894 plane_state
->main
.x
= x
;
2895 plane_state
->main
.y
= y
;
2900 static int skl_check_nv12_aux_surface(struct intel_plane_state
*plane_state
)
2902 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2903 unsigned int rotation
= plane_state
->base
.rotation
;
2904 int max_width
= skl_max_plane_width(fb
, 1, rotation
);
2905 int max_height
= 4096;
2906 int x
= plane_state
->base
.src
.x1
>> 17;
2907 int y
= plane_state
->base
.src
.y1
>> 17;
2908 int w
= drm_rect_width(&plane_state
->base
.src
) >> 17;
2909 int h
= drm_rect_height(&plane_state
->base
.src
) >> 17;
2912 intel_add_fb_offsets(&x
, &y
, plane_state
, 1);
2913 offset
= intel_compute_tile_offset(&x
, &y
, plane_state
, 1);
2915 /* FIXME not quite sure how/if these apply to the chroma plane */
2916 if (w
> max_width
|| h
> max_height
) {
2917 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
2918 w
, h
, max_width
, max_height
);
2922 plane_state
->aux
.offset
= offset
;
2923 plane_state
->aux
.x
= x
;
2924 plane_state
->aux
.y
= y
;
2929 int skl_check_plane_surface(struct intel_plane_state
*plane_state
)
2931 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2932 unsigned int rotation
= plane_state
->base
.rotation
;
2935 if (!plane_state
->base
.visible
)
2938 /* Rotate src coordinates to match rotated GTT view */
2939 if (drm_rotation_90_or_270(rotation
))
2940 drm_rect_rotate(&plane_state
->base
.src
,
2941 fb
->width
<< 16, fb
->height
<< 16,
2945 * Handle the AUX surface first since
2946 * the main surface setup depends on it.
2948 if (fb
->format
->format
== DRM_FORMAT_NV12
) {
2949 ret
= skl_check_nv12_aux_surface(plane_state
);
2953 plane_state
->aux
.offset
= ~0xfff;
2954 plane_state
->aux
.x
= 0;
2955 plane_state
->aux
.y
= 0;
2958 ret
= skl_check_main_surface(plane_state
);
2965 static u32
i9xx_plane_ctl(const struct intel_crtc_state
*crtc_state
,
2966 const struct intel_plane_state
*plane_state
)
2968 struct drm_i915_private
*dev_priv
=
2969 to_i915(plane_state
->base
.plane
->dev
);
2970 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
2971 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2972 unsigned int rotation
= plane_state
->base
.rotation
;
2975 dspcntr
= DISPLAY_PLANE_ENABLE
| DISPPLANE_GAMMA_ENABLE
;
2977 if (IS_G4X(dev_priv
))
2978 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2980 if (INTEL_GEN(dev_priv
) < 4) {
2981 if (crtc
->pipe
== PIPE_B
)
2982 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
2985 switch (fb
->format
->format
) {
2987 dspcntr
|= DISPPLANE_8BPP
;
2989 case DRM_FORMAT_XRGB1555
:
2990 dspcntr
|= DISPPLANE_BGRX555
;
2992 case DRM_FORMAT_RGB565
:
2993 dspcntr
|= DISPPLANE_BGRX565
;
2995 case DRM_FORMAT_XRGB8888
:
2996 dspcntr
|= DISPPLANE_BGRX888
;
2998 case DRM_FORMAT_XBGR8888
:
2999 dspcntr
|= DISPPLANE_RGBX888
;
3001 case DRM_FORMAT_XRGB2101010
:
3002 dspcntr
|= DISPPLANE_BGRX101010
;
3004 case DRM_FORMAT_XBGR2101010
:
3005 dspcntr
|= DISPPLANE_RGBX101010
;
3008 MISSING_CASE(fb
->format
->format
);
3012 if (INTEL_GEN(dev_priv
) >= 4 &&
3013 fb
->modifier
== I915_FORMAT_MOD_X_TILED
)
3014 dspcntr
|= DISPPLANE_TILED
;
3016 if (rotation
& DRM_ROTATE_180
)
3017 dspcntr
|= DISPPLANE_ROTATE_180
;
3019 if (rotation
& DRM_REFLECT_X
)
3020 dspcntr
|= DISPPLANE_MIRROR
;
3025 static void i9xx_update_primary_plane(struct drm_plane
*primary
,
3026 const struct intel_crtc_state
*crtc_state
,
3027 const struct intel_plane_state
*plane_state
)
3029 struct drm_i915_private
*dev_priv
= to_i915(primary
->dev
);
3030 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
3031 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
3032 int plane
= intel_crtc
->plane
;
3035 i915_reg_t reg
= DSPCNTR(plane
);
3036 unsigned int rotation
= plane_state
->base
.rotation
;
3037 int x
= plane_state
->base
.src
.x1
>> 16;
3038 int y
= plane_state
->base
.src
.y1
>> 16;
3039 unsigned long irqflags
;
3041 dspcntr
= i9xx_plane_ctl(crtc_state
, plane_state
);
3043 intel_add_fb_offsets(&x
, &y
, plane_state
, 0);
3045 if (INTEL_GEN(dev_priv
) >= 4)
3046 intel_crtc
->dspaddr_offset
=
3047 intel_compute_tile_offset(&x
, &y
, plane_state
, 0);
3049 if (rotation
& DRM_ROTATE_180
) {
3050 x
+= crtc_state
->pipe_src_w
- 1;
3051 y
+= crtc_state
->pipe_src_h
- 1;
3052 } else if (rotation
& DRM_REFLECT_X
) {
3053 x
+= crtc_state
->pipe_src_w
- 1;
3056 linear_offset
= intel_fb_xy_to_linear(x
, y
, plane_state
, 0);
3058 if (INTEL_GEN(dev_priv
) < 4)
3059 intel_crtc
->dspaddr_offset
= linear_offset
;
3061 intel_crtc
->adjusted_x
= x
;
3062 intel_crtc
->adjusted_y
= y
;
3064 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
3066 if (INTEL_GEN(dev_priv
) < 4) {
3067 /* pipesrc and dspsize control the size that is scaled from,
3068 * which should always be the user's requested size.
3070 I915_WRITE_FW(DSPSIZE(plane
),
3071 ((crtc_state
->pipe_src_h
- 1) << 16) |
3072 (crtc_state
->pipe_src_w
- 1));
3073 I915_WRITE_FW(DSPPOS(plane
), 0);
3074 } else if (IS_CHERRYVIEW(dev_priv
) && plane
== PLANE_B
) {
3075 I915_WRITE_FW(PRIMSIZE(plane
),
3076 ((crtc_state
->pipe_src_h
- 1) << 16) |
3077 (crtc_state
->pipe_src_w
- 1));
3078 I915_WRITE_FW(PRIMPOS(plane
), 0);
3079 I915_WRITE_FW(PRIMCNSTALPHA(plane
), 0);
3082 I915_WRITE_FW(reg
, dspcntr
);
3084 I915_WRITE_FW(DSPSTRIDE(plane
), fb
->pitches
[0]);
3085 if (INTEL_GEN(dev_priv
) >= 4) {
3086 I915_WRITE_FW(DSPSURF(plane
),
3087 intel_plane_ggtt_offset(plane_state
) +
3088 intel_crtc
->dspaddr_offset
);
3089 I915_WRITE_FW(DSPTILEOFF(plane
), (y
<< 16) | x
);
3090 I915_WRITE_FW(DSPLINOFF(plane
), linear_offset
);
3092 I915_WRITE_FW(DSPADDR(plane
),
3093 intel_plane_ggtt_offset(plane_state
) +
3094 intel_crtc
->dspaddr_offset
);
3096 POSTING_READ_FW(reg
);
3098 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
3101 static void i9xx_disable_primary_plane(struct drm_plane
*primary
,
3102 struct drm_crtc
*crtc
)
3104 struct drm_device
*dev
= crtc
->dev
;
3105 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3106 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3107 int plane
= intel_crtc
->plane
;
3108 unsigned long irqflags
;
3110 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
3112 I915_WRITE_FW(DSPCNTR(plane
), 0);
3113 if (INTEL_INFO(dev_priv
)->gen
>= 4)
3114 I915_WRITE_FW(DSPSURF(plane
), 0);
3116 I915_WRITE_FW(DSPADDR(plane
), 0);
3117 POSTING_READ_FW(DSPCNTR(plane
));
3119 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
3122 static u32
ironlake_plane_ctl(const struct intel_crtc_state
*crtc_state
,
3123 const struct intel_plane_state
*plane_state
)
3125 struct drm_i915_private
*dev_priv
=
3126 to_i915(plane_state
->base
.plane
->dev
);
3127 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
3128 unsigned int rotation
= plane_state
->base
.rotation
;
3131 dspcntr
= DISPLAY_PLANE_ENABLE
| DISPPLANE_GAMMA_ENABLE
;
3133 if (!IS_HASWELL(dev_priv
) && !IS_BROADWELL(dev_priv
))
3134 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
3136 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
3137 dspcntr
|= DISPPLANE_PIPE_CSC_ENABLE
;
3139 switch (fb
->format
->format
) {
3141 dspcntr
|= DISPPLANE_8BPP
;
3143 case DRM_FORMAT_RGB565
:
3144 dspcntr
|= DISPPLANE_BGRX565
;
3146 case DRM_FORMAT_XRGB8888
:
3147 dspcntr
|= DISPPLANE_BGRX888
;
3149 case DRM_FORMAT_XBGR8888
:
3150 dspcntr
|= DISPPLANE_RGBX888
;
3152 case DRM_FORMAT_XRGB2101010
:
3153 dspcntr
|= DISPPLANE_BGRX101010
;
3155 case DRM_FORMAT_XBGR2101010
:
3156 dspcntr
|= DISPPLANE_RGBX101010
;
3159 MISSING_CASE(fb
->format
->format
);
3163 if (fb
->modifier
== I915_FORMAT_MOD_X_TILED
)
3164 dspcntr
|= DISPPLANE_TILED
;
3166 if (rotation
& DRM_ROTATE_180
)
3167 dspcntr
|= DISPPLANE_ROTATE_180
;
3172 static void ironlake_update_primary_plane(struct drm_plane
*primary
,
3173 const struct intel_crtc_state
*crtc_state
,
3174 const struct intel_plane_state
*plane_state
)
3176 struct drm_device
*dev
= primary
->dev
;
3177 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3178 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
3179 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
3180 int plane
= intel_crtc
->plane
;
3183 i915_reg_t reg
= DSPCNTR(plane
);
3184 unsigned int rotation
= plane_state
->base
.rotation
;
3185 int x
= plane_state
->base
.src
.x1
>> 16;
3186 int y
= plane_state
->base
.src
.y1
>> 16;
3187 unsigned long irqflags
;
3189 dspcntr
= ironlake_plane_ctl(crtc_state
, plane_state
);
3191 intel_add_fb_offsets(&x
, &y
, plane_state
, 0);
3193 intel_crtc
->dspaddr_offset
=
3194 intel_compute_tile_offset(&x
, &y
, plane_state
, 0);
3196 /* HSW+ does this automagically in hardware */
3197 if (!IS_HASWELL(dev_priv
) && !IS_BROADWELL(dev_priv
) &&
3198 rotation
& DRM_ROTATE_180
) {
3199 x
+= crtc_state
->pipe_src_w
- 1;
3200 y
+= crtc_state
->pipe_src_h
- 1;
3203 linear_offset
= intel_fb_xy_to_linear(x
, y
, plane_state
, 0);
3205 intel_crtc
->adjusted_x
= x
;
3206 intel_crtc
->adjusted_y
= y
;
3208 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
3210 I915_WRITE_FW(reg
, dspcntr
);
3212 I915_WRITE_FW(DSPSTRIDE(plane
), fb
->pitches
[0]);
3213 I915_WRITE_FW(DSPSURF(plane
),
3214 intel_plane_ggtt_offset(plane_state
) +
3215 intel_crtc
->dspaddr_offset
);
3216 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
3217 I915_WRITE_FW(DSPOFFSET(plane
), (y
<< 16) | x
);
3219 I915_WRITE_FW(DSPTILEOFF(plane
), (y
<< 16) | x
);
3220 I915_WRITE_FW(DSPLINOFF(plane
), linear_offset
);
3222 POSTING_READ_FW(reg
);
3224 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
3228 intel_fb_stride_alignment(const struct drm_framebuffer
*fb
, int plane
)
3230 if (fb
->modifier
== DRM_FORMAT_MOD_NONE
)
3233 return intel_tile_width_bytes(fb
, plane
);
3236 static void skl_detach_scaler(struct intel_crtc
*intel_crtc
, int id
)
3238 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3239 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3241 I915_WRITE(SKL_PS_CTRL(intel_crtc
->pipe
, id
), 0);
3242 I915_WRITE(SKL_PS_WIN_POS(intel_crtc
->pipe
, id
), 0);
3243 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc
->pipe
, id
), 0);
3247 * This function detaches (aka. unbinds) unused scalers in hardware
3249 static void skl_detach_scalers(struct intel_crtc
*intel_crtc
)
3251 struct intel_crtc_scaler_state
*scaler_state
;
3254 scaler_state
= &intel_crtc
->config
->scaler_state
;
3256 /* loop through and disable scalers that aren't in use */
3257 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
3258 if (!scaler_state
->scalers
[i
].in_use
)
3259 skl_detach_scaler(intel_crtc
, i
);
3263 u32
skl_plane_stride(const struct drm_framebuffer
*fb
, int plane
,
3264 unsigned int rotation
)
3268 if (plane
>= fb
->format
->num_planes
)
3271 stride
= intel_fb_pitch(fb
, plane
, rotation
);
3274 * The stride is either expressed as a multiple of 64 bytes chunks for
3275 * linear buffers or in number of tiles for tiled buffers.
3277 if (drm_rotation_90_or_270(rotation
))
3278 stride
/= intel_tile_height(fb
, plane
);
3280 stride
/= intel_fb_stride_alignment(fb
, plane
);
3285 static u32
skl_plane_ctl_format(uint32_t pixel_format
)
3287 switch (pixel_format
) {
3289 return PLANE_CTL_FORMAT_INDEXED
;
3290 case DRM_FORMAT_RGB565
:
3291 return PLANE_CTL_FORMAT_RGB_565
;
3292 case DRM_FORMAT_XBGR8888
:
3293 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
;
3294 case DRM_FORMAT_XRGB8888
:
3295 return PLANE_CTL_FORMAT_XRGB_8888
;
3297 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
3298 * to be already pre-multiplied. We need to add a knob (or a different
3299 * DRM_FORMAT) for user-space to configure that.
3301 case DRM_FORMAT_ABGR8888
:
3302 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
|
3303 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
3304 case DRM_FORMAT_ARGB8888
:
3305 return PLANE_CTL_FORMAT_XRGB_8888
|
3306 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
3307 case DRM_FORMAT_XRGB2101010
:
3308 return PLANE_CTL_FORMAT_XRGB_2101010
;
3309 case DRM_FORMAT_XBGR2101010
:
3310 return PLANE_CTL_ORDER_RGBX
| PLANE_CTL_FORMAT_XRGB_2101010
;
3311 case DRM_FORMAT_YUYV
:
3312 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YUYV
;
3313 case DRM_FORMAT_YVYU
:
3314 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YVYU
;
3315 case DRM_FORMAT_UYVY
:
3316 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_UYVY
;
3317 case DRM_FORMAT_VYUY
:
3318 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_VYUY
;
3320 MISSING_CASE(pixel_format
);
3326 static u32
skl_plane_ctl_tiling(uint64_t fb_modifier
)
3328 switch (fb_modifier
) {
3329 case DRM_FORMAT_MOD_NONE
:
3331 case I915_FORMAT_MOD_X_TILED
:
3332 return PLANE_CTL_TILED_X
;
3333 case I915_FORMAT_MOD_Y_TILED
:
3334 return PLANE_CTL_TILED_Y
;
3335 case I915_FORMAT_MOD_Yf_TILED
:
3336 return PLANE_CTL_TILED_YF
;
3338 MISSING_CASE(fb_modifier
);
3344 static u32
skl_plane_ctl_rotation(unsigned int rotation
)
3350 * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr
3351 * while i915 HW rotation is clockwise, thats why this swapping.
3354 return PLANE_CTL_ROTATE_270
;
3355 case DRM_ROTATE_180
:
3356 return PLANE_CTL_ROTATE_180
;
3357 case DRM_ROTATE_270
:
3358 return PLANE_CTL_ROTATE_90
;
3360 MISSING_CASE(rotation
);
3366 u32
skl_plane_ctl(const struct intel_crtc_state
*crtc_state
,
3367 const struct intel_plane_state
*plane_state
)
3369 struct drm_i915_private
*dev_priv
=
3370 to_i915(plane_state
->base
.plane
->dev
);
3371 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
3372 unsigned int rotation
= plane_state
->base
.rotation
;
3373 const struct drm_intel_sprite_colorkey
*key
= &plane_state
->ckey
;
3376 plane_ctl
= PLANE_CTL_ENABLE
;
3378 if (!IS_GEMINILAKE(dev_priv
)) {
3380 PLANE_CTL_PIPE_GAMMA_ENABLE
|
3381 PLANE_CTL_PIPE_CSC_ENABLE
|
3382 PLANE_CTL_PLANE_GAMMA_DISABLE
;
3385 plane_ctl
|= skl_plane_ctl_format(fb
->format
->format
);
3386 plane_ctl
|= skl_plane_ctl_tiling(fb
->modifier
);
3387 plane_ctl
|= skl_plane_ctl_rotation(rotation
);
3389 if (key
->flags
& I915_SET_COLORKEY_DESTINATION
)
3390 plane_ctl
|= PLANE_CTL_KEY_ENABLE_DESTINATION
;
3391 else if (key
->flags
& I915_SET_COLORKEY_SOURCE
)
3392 plane_ctl
|= PLANE_CTL_KEY_ENABLE_SOURCE
;
3397 static void skylake_update_primary_plane(struct drm_plane
*plane
,
3398 const struct intel_crtc_state
*crtc_state
,
3399 const struct intel_plane_state
*plane_state
)
3401 struct drm_device
*dev
= plane
->dev
;
3402 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3403 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
3404 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
3405 enum plane_id plane_id
= to_intel_plane(plane
)->id
;
3406 enum pipe pipe
= to_intel_plane(plane
)->pipe
;
3408 unsigned int rotation
= plane_state
->base
.rotation
;
3409 u32 stride
= skl_plane_stride(fb
, 0, rotation
);
3410 u32 surf_addr
= plane_state
->main
.offset
;
3411 int scaler_id
= plane_state
->scaler_id
;
3412 int src_x
= plane_state
->main
.x
;
3413 int src_y
= plane_state
->main
.y
;
3414 int src_w
= drm_rect_width(&plane_state
->base
.src
) >> 16;
3415 int src_h
= drm_rect_height(&plane_state
->base
.src
) >> 16;
3416 int dst_x
= plane_state
->base
.dst
.x1
;
3417 int dst_y
= plane_state
->base
.dst
.y1
;
3418 int dst_w
= drm_rect_width(&plane_state
->base
.dst
);
3419 int dst_h
= drm_rect_height(&plane_state
->base
.dst
);
3420 unsigned long irqflags
;
3422 plane_ctl
= skl_plane_ctl(crtc_state
, plane_state
);
3424 /* Sizes are 0 based */
3430 intel_crtc
->dspaddr_offset
= surf_addr
;
3432 intel_crtc
->adjusted_x
= src_x
;
3433 intel_crtc
->adjusted_y
= src_y
;
3435 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
3437 if (IS_GEMINILAKE(dev_priv
)) {
3438 I915_WRITE_FW(PLANE_COLOR_CTL(pipe
, plane_id
),
3439 PLANE_COLOR_PIPE_GAMMA_ENABLE
|
3440 PLANE_COLOR_PIPE_CSC_ENABLE
|
3441 PLANE_COLOR_PLANE_GAMMA_DISABLE
);
3444 I915_WRITE_FW(PLANE_CTL(pipe
, plane_id
), plane_ctl
);
3445 I915_WRITE_FW(PLANE_OFFSET(pipe
, plane_id
), (src_y
<< 16) | src_x
);
3446 I915_WRITE_FW(PLANE_STRIDE(pipe
, plane_id
), stride
);
3447 I915_WRITE_FW(PLANE_SIZE(pipe
, plane_id
), (src_h
<< 16) | src_w
);
3449 if (scaler_id
>= 0) {
3450 uint32_t ps_ctrl
= 0;
3452 WARN_ON(!dst_w
|| !dst_h
);
3453 ps_ctrl
= PS_SCALER_EN
| PS_PLANE_SEL(plane_id
) |
3454 crtc_state
->scaler_state
.scalers
[scaler_id
].mode
;
3455 I915_WRITE_FW(SKL_PS_CTRL(pipe
, scaler_id
), ps_ctrl
);
3456 I915_WRITE_FW(SKL_PS_PWR_GATE(pipe
, scaler_id
), 0);
3457 I915_WRITE_FW(SKL_PS_WIN_POS(pipe
, scaler_id
), (dst_x
<< 16) | dst_y
);
3458 I915_WRITE_FW(SKL_PS_WIN_SZ(pipe
, scaler_id
), (dst_w
<< 16) | dst_h
);
3459 I915_WRITE_FW(PLANE_POS(pipe
, plane_id
), 0);
3461 I915_WRITE_FW(PLANE_POS(pipe
, plane_id
), (dst_y
<< 16) | dst_x
);
3464 I915_WRITE_FW(PLANE_SURF(pipe
, plane_id
),
3465 intel_plane_ggtt_offset(plane_state
) + surf_addr
);
3467 POSTING_READ_FW(PLANE_SURF(pipe
, plane_id
));
3469 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
3472 static void skylake_disable_primary_plane(struct drm_plane
*primary
,
3473 struct drm_crtc
*crtc
)
3475 struct drm_device
*dev
= crtc
->dev
;
3476 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3477 enum plane_id plane_id
= to_intel_plane(primary
)->id
;
3478 enum pipe pipe
= to_intel_plane(primary
)->pipe
;
3479 unsigned long irqflags
;
3481 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
3483 I915_WRITE_FW(PLANE_CTL(pipe
, plane_id
), 0);
3484 I915_WRITE_FW(PLANE_SURF(pipe
, plane_id
), 0);
3485 POSTING_READ_FW(PLANE_SURF(pipe
, plane_id
));
3487 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
3490 /* Assume fb object is pinned & idle & fenced and just update base pointers */
3492 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
3493 int x
, int y
, enum mode_set_atomic state
)
3495 /* Support for kgdboc is disabled, this needs a major rework. */
3496 DRM_ERROR("legacy panic handler not supported any more.\n");
3501 static void intel_complete_page_flips(struct drm_i915_private
*dev_priv
)
3503 struct intel_crtc
*crtc
;
3505 for_each_intel_crtc(&dev_priv
->drm
, crtc
)
3506 intel_finish_page_flip_cs(dev_priv
, crtc
->pipe
);
3509 static void intel_update_primary_planes(struct drm_device
*dev
)
3511 struct drm_crtc
*crtc
;
3513 for_each_crtc(dev
, crtc
) {
3514 struct intel_plane
*plane
= to_intel_plane(crtc
->primary
);
3515 struct intel_plane_state
*plane_state
=
3516 to_intel_plane_state(plane
->base
.state
);
3518 if (plane_state
->base
.visible
) {
3519 trace_intel_update_plane(&plane
->base
,
3520 to_intel_crtc(crtc
));
3522 plane
->update_plane(&plane
->base
,
3523 to_intel_crtc_state(crtc
->state
),
3530 __intel_display_resume(struct drm_device
*dev
,
3531 struct drm_atomic_state
*state
,
3532 struct drm_modeset_acquire_ctx
*ctx
)
3534 struct drm_crtc_state
*crtc_state
;
3535 struct drm_crtc
*crtc
;
3538 intel_modeset_setup_hw_state(dev
);
3539 i915_redisable_vga(to_i915(dev
));
3545 * We've duplicated the state, pointers to the old state are invalid.
3547 * Don't attempt to use the old state until we commit the duplicated state.
3549 for_each_new_crtc_in_state(state
, crtc
, crtc_state
, i
) {
3551 * Force recalculation even if we restore
3552 * current state. With fast modeset this may not result
3553 * in a modeset when the state is compatible.
3555 crtc_state
->mode_changed
= true;
3558 /* ignore any reset values/BIOS leftovers in the WM registers */
3559 if (!HAS_GMCH_DISPLAY(to_i915(dev
)))
3560 to_intel_atomic_state(state
)->skip_intermediate_wm
= true;
3562 ret
= drm_atomic_helper_commit_duplicated_state(state
, ctx
);
3564 WARN_ON(ret
== -EDEADLK
);
3568 static bool gpu_reset_clobbers_display(struct drm_i915_private
*dev_priv
)
3570 return intel_has_gpu_reset(dev_priv
) &&
3571 INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
);
3574 void intel_prepare_reset(struct drm_i915_private
*dev_priv
)
3576 struct drm_device
*dev
= &dev_priv
->drm
;
3577 struct drm_modeset_acquire_ctx
*ctx
= &dev_priv
->reset_ctx
;
3578 struct drm_atomic_state
*state
;
3582 * Need mode_config.mutex so that we don't
3583 * trample ongoing ->detect() and whatnot.
3585 mutex_lock(&dev
->mode_config
.mutex
);
3586 drm_modeset_acquire_init(ctx
, 0);
3588 ret
= drm_modeset_lock_all_ctx(dev
, ctx
);
3589 if (ret
!= -EDEADLK
)
3592 drm_modeset_backoff(ctx
);
3595 /* reset doesn't touch the display, but flips might get nuked anyway, */
3596 if (!i915
.force_reset_modeset_test
&&
3597 !gpu_reset_clobbers_display(dev_priv
))
3601 * Disabling the crtcs gracefully seems nicer. Also the
3602 * g33 docs say we should at least disable all the planes.
3604 state
= drm_atomic_helper_duplicate_state(dev
, ctx
);
3605 if (IS_ERR(state
)) {
3606 ret
= PTR_ERR(state
);
3607 DRM_ERROR("Duplicating state failed with %i\n", ret
);
3611 ret
= drm_atomic_helper_disable_all(dev
, ctx
);
3613 DRM_ERROR("Suspending crtc's failed with %i\n", ret
);
3614 drm_atomic_state_put(state
);
3618 dev_priv
->modeset_restore_state
= state
;
3619 state
->acquire_ctx
= ctx
;
3622 void intel_finish_reset(struct drm_i915_private
*dev_priv
)
3624 struct drm_device
*dev
= &dev_priv
->drm
;
3625 struct drm_modeset_acquire_ctx
*ctx
= &dev_priv
->reset_ctx
;
3626 struct drm_atomic_state
*state
= dev_priv
->modeset_restore_state
;
3630 * Flips in the rings will be nuked by the reset,
3631 * so complete all pending flips so that user space
3632 * will get its events and not get stuck.
3634 intel_complete_page_flips(dev_priv
);
3636 dev_priv
->modeset_restore_state
= NULL
;
3638 /* reset doesn't touch the display */
3639 if (!gpu_reset_clobbers_display(dev_priv
)) {
3642 * Flips in the rings have been nuked by the reset,
3643 * so update the base address of all primary
3644 * planes to the the last fb to make sure we're
3645 * showing the correct fb after a reset.
3647 * FIXME: Atomic will make this obsolete since we won't schedule
3648 * CS-based flips (which might get lost in gpu resets) any more.
3650 intel_update_primary_planes(dev
);
3652 ret
= __intel_display_resume(dev
, state
, ctx
);
3654 DRM_ERROR("Restoring old state failed with %i\n", ret
);
3658 * The display has been reset as well,
3659 * so need a full re-initialization.
3661 intel_runtime_pm_disable_interrupts(dev_priv
);
3662 intel_runtime_pm_enable_interrupts(dev_priv
);
3664 intel_pps_unlock_regs_wa(dev_priv
);
3665 intel_modeset_init_hw(dev
);
3667 spin_lock_irq(&dev_priv
->irq_lock
);
3668 if (dev_priv
->display
.hpd_irq_setup
)
3669 dev_priv
->display
.hpd_irq_setup(dev_priv
);
3670 spin_unlock_irq(&dev_priv
->irq_lock
);
3672 ret
= __intel_display_resume(dev
, state
, ctx
);
3674 DRM_ERROR("Restoring old state failed with %i\n", ret
);
3676 intel_hpd_init(dev_priv
);
3680 drm_atomic_state_put(state
);
3681 drm_modeset_drop_locks(ctx
);
3682 drm_modeset_acquire_fini(ctx
);
3683 mutex_unlock(&dev
->mode_config
.mutex
);
3686 static bool abort_flip_on_reset(struct intel_crtc
*crtc
)
3688 struct i915_gpu_error
*error
= &to_i915(crtc
->base
.dev
)->gpu_error
;
3690 if (i915_reset_backoff(error
))
3693 if (crtc
->reset_count
!= i915_reset_count(error
))
3699 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
3701 struct drm_device
*dev
= crtc
->dev
;
3702 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3705 if (abort_flip_on_reset(intel_crtc
))
3708 spin_lock_irq(&dev
->event_lock
);
3709 pending
= to_intel_crtc(crtc
)->flip_work
!= NULL
;
3710 spin_unlock_irq(&dev
->event_lock
);
3715 static void intel_update_pipe_config(struct intel_crtc
*crtc
,
3716 struct intel_crtc_state
*old_crtc_state
)
3718 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
3719 struct intel_crtc_state
*pipe_config
=
3720 to_intel_crtc_state(crtc
->base
.state
);
3722 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
3723 crtc
->base
.mode
= crtc
->base
.state
->mode
;
3726 * Update pipe size and adjust fitter if needed: the reason for this is
3727 * that in compute_mode_changes we check the native mode (not the pfit
3728 * mode) to see if we can flip rather than do a full mode set. In the
3729 * fastboot case, we'll flip, but if we don't update the pipesrc and
3730 * pfit state, we'll end up with a big fb scanned out into the wrong
3734 I915_WRITE(PIPESRC(crtc
->pipe
),
3735 ((pipe_config
->pipe_src_w
- 1) << 16) |
3736 (pipe_config
->pipe_src_h
- 1));
3738 /* on skylake this is done by detaching scalers */
3739 if (INTEL_GEN(dev_priv
) >= 9) {
3740 skl_detach_scalers(crtc
);
3742 if (pipe_config
->pch_pfit
.enabled
)
3743 skylake_pfit_enable(crtc
);
3744 } else if (HAS_PCH_SPLIT(dev_priv
)) {
3745 if (pipe_config
->pch_pfit
.enabled
)
3746 ironlake_pfit_enable(crtc
);
3747 else if (old_crtc_state
->pch_pfit
.enabled
)
3748 ironlake_pfit_disable(crtc
, true);
3752 static void intel_fdi_normal_train(struct intel_crtc
*crtc
)
3754 struct drm_device
*dev
= crtc
->base
.dev
;
3755 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3756 int pipe
= crtc
->pipe
;
3760 /* enable normal train */
3761 reg
= FDI_TX_CTL(pipe
);
3762 temp
= I915_READ(reg
);
3763 if (IS_IVYBRIDGE(dev_priv
)) {
3764 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3765 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3767 temp
&= ~FDI_LINK_TRAIN_NONE
;
3768 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3770 I915_WRITE(reg
, temp
);
3772 reg
= FDI_RX_CTL(pipe
);
3773 temp
= I915_READ(reg
);
3774 if (HAS_PCH_CPT(dev_priv
)) {
3775 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3776 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
3778 temp
&= ~FDI_LINK_TRAIN_NONE
;
3779 temp
|= FDI_LINK_TRAIN_NONE
;
3781 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
3783 /* wait one idle pattern time */
3787 /* IVB wants error correction enabled */
3788 if (IS_IVYBRIDGE(dev_priv
))
3789 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
3790 FDI_FE_ERRC_ENABLE
);
3793 /* The FDI link training functions for ILK/Ibexpeak. */
3794 static void ironlake_fdi_link_train(struct intel_crtc
*crtc
,
3795 const struct intel_crtc_state
*crtc_state
)
3797 struct drm_device
*dev
= crtc
->base
.dev
;
3798 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3799 int pipe
= crtc
->pipe
;
3803 /* FDI needs bits from pipe first */
3804 assert_pipe_enabled(dev_priv
, pipe
);
3806 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3808 reg
= FDI_RX_IMR(pipe
);
3809 temp
= I915_READ(reg
);
3810 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3811 temp
&= ~FDI_RX_BIT_LOCK
;
3812 I915_WRITE(reg
, temp
);
3816 /* enable CPU FDI TX and PCH FDI RX */
3817 reg
= FDI_TX_CTL(pipe
);
3818 temp
= I915_READ(reg
);
3819 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3820 temp
|= FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
3821 temp
&= ~FDI_LINK_TRAIN_NONE
;
3822 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3823 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3825 reg
= FDI_RX_CTL(pipe
);
3826 temp
= I915_READ(reg
);
3827 temp
&= ~FDI_LINK_TRAIN_NONE
;
3828 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3829 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3834 /* Ironlake workaround, enable clock pointer after FDI enable*/
3835 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3836 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
3837 FDI_RX_PHASE_SYNC_POINTER_EN
);
3839 reg
= FDI_RX_IIR(pipe
);
3840 for (tries
= 0; tries
< 5; tries
++) {
3841 temp
= I915_READ(reg
);
3842 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3844 if ((temp
& FDI_RX_BIT_LOCK
)) {
3845 DRM_DEBUG_KMS("FDI train 1 done.\n");
3846 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3851 DRM_ERROR("FDI train 1 fail!\n");
3854 reg
= FDI_TX_CTL(pipe
);
3855 temp
= I915_READ(reg
);
3856 temp
&= ~FDI_LINK_TRAIN_NONE
;
3857 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3858 I915_WRITE(reg
, temp
);
3860 reg
= FDI_RX_CTL(pipe
);
3861 temp
= I915_READ(reg
);
3862 temp
&= ~FDI_LINK_TRAIN_NONE
;
3863 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3864 I915_WRITE(reg
, temp
);
3869 reg
= FDI_RX_IIR(pipe
);
3870 for (tries
= 0; tries
< 5; tries
++) {
3871 temp
= I915_READ(reg
);
3872 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3874 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3875 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3876 DRM_DEBUG_KMS("FDI train 2 done.\n");
3881 DRM_ERROR("FDI train 2 fail!\n");
3883 DRM_DEBUG_KMS("FDI train done\n");
3887 static const int snb_b_fdi_train_param
[] = {
3888 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
3889 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
3890 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
3891 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
3894 /* The FDI link training functions for SNB/Cougarpoint. */
3895 static void gen6_fdi_link_train(struct intel_crtc
*crtc
,
3896 const struct intel_crtc_state
*crtc_state
)
3898 struct drm_device
*dev
= crtc
->base
.dev
;
3899 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3900 int pipe
= crtc
->pipe
;
3904 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3906 reg
= FDI_RX_IMR(pipe
);
3907 temp
= I915_READ(reg
);
3908 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3909 temp
&= ~FDI_RX_BIT_LOCK
;
3910 I915_WRITE(reg
, temp
);
3915 /* enable CPU FDI TX and PCH FDI RX */
3916 reg
= FDI_TX_CTL(pipe
);
3917 temp
= I915_READ(reg
);
3918 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3919 temp
|= FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
3920 temp
&= ~FDI_LINK_TRAIN_NONE
;
3921 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3922 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3924 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3925 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3927 I915_WRITE(FDI_RX_MISC(pipe
),
3928 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3930 reg
= FDI_RX_CTL(pipe
);
3931 temp
= I915_READ(reg
);
3932 if (HAS_PCH_CPT(dev_priv
)) {
3933 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3934 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3936 temp
&= ~FDI_LINK_TRAIN_NONE
;
3937 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3939 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3944 for (i
= 0; i
< 4; i
++) {
3945 reg
= FDI_TX_CTL(pipe
);
3946 temp
= I915_READ(reg
);
3947 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3948 temp
|= snb_b_fdi_train_param
[i
];
3949 I915_WRITE(reg
, temp
);
3954 for (retry
= 0; retry
< 5; retry
++) {
3955 reg
= FDI_RX_IIR(pipe
);
3956 temp
= I915_READ(reg
);
3957 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3958 if (temp
& FDI_RX_BIT_LOCK
) {
3959 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3960 DRM_DEBUG_KMS("FDI train 1 done.\n");
3969 DRM_ERROR("FDI train 1 fail!\n");
3972 reg
= FDI_TX_CTL(pipe
);
3973 temp
= I915_READ(reg
);
3974 temp
&= ~FDI_LINK_TRAIN_NONE
;
3975 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3976 if (IS_GEN6(dev_priv
)) {
3977 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3979 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3981 I915_WRITE(reg
, temp
);
3983 reg
= FDI_RX_CTL(pipe
);
3984 temp
= I915_READ(reg
);
3985 if (HAS_PCH_CPT(dev_priv
)) {
3986 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3987 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3989 temp
&= ~FDI_LINK_TRAIN_NONE
;
3990 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3992 I915_WRITE(reg
, temp
);
3997 for (i
= 0; i
< 4; i
++) {
3998 reg
= FDI_TX_CTL(pipe
);
3999 temp
= I915_READ(reg
);
4000 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
4001 temp
|= snb_b_fdi_train_param
[i
];
4002 I915_WRITE(reg
, temp
);
4007 for (retry
= 0; retry
< 5; retry
++) {
4008 reg
= FDI_RX_IIR(pipe
);
4009 temp
= I915_READ(reg
);
4010 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
4011 if (temp
& FDI_RX_SYMBOL_LOCK
) {
4012 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
4013 DRM_DEBUG_KMS("FDI train 2 done.\n");
4022 DRM_ERROR("FDI train 2 fail!\n");
4024 DRM_DEBUG_KMS("FDI train done.\n");
4027 /* Manual link training for Ivy Bridge A0 parts */
4028 static void ivb_manual_fdi_link_train(struct intel_crtc
*crtc
,
4029 const struct intel_crtc_state
*crtc_state
)
4031 struct drm_device
*dev
= crtc
->base
.dev
;
4032 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4033 int pipe
= crtc
->pipe
;
4037 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4039 reg
= FDI_RX_IMR(pipe
);
4040 temp
= I915_READ(reg
);
4041 temp
&= ~FDI_RX_SYMBOL_LOCK
;
4042 temp
&= ~FDI_RX_BIT_LOCK
;
4043 I915_WRITE(reg
, temp
);
4048 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4049 I915_READ(FDI_RX_IIR(pipe
)));
4051 /* Try each vswing and preemphasis setting twice before moving on */
4052 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
4053 /* disable first in case we need to retry */
4054 reg
= FDI_TX_CTL(pipe
);
4055 temp
= I915_READ(reg
);
4056 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
4057 temp
&= ~FDI_TX_ENABLE
;
4058 I915_WRITE(reg
, temp
);
4060 reg
= FDI_RX_CTL(pipe
);
4061 temp
= I915_READ(reg
);
4062 temp
&= ~FDI_LINK_TRAIN_AUTO
;
4063 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
4064 temp
&= ~FDI_RX_ENABLE
;
4065 I915_WRITE(reg
, temp
);
4067 /* enable CPU FDI TX and PCH FDI RX */
4068 reg
= FDI_TX_CTL(pipe
);
4069 temp
= I915_READ(reg
);
4070 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
4071 temp
|= FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
4072 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
4073 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
4074 temp
|= snb_b_fdi_train_param
[j
/2];
4075 temp
|= FDI_COMPOSITE_SYNC
;
4076 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
4078 I915_WRITE(FDI_RX_MISC(pipe
),
4079 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
4081 reg
= FDI_RX_CTL(pipe
);
4082 temp
= I915_READ(reg
);
4083 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
4084 temp
|= FDI_COMPOSITE_SYNC
;
4085 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
4088 udelay(1); /* should be 0.5us */
4090 for (i
= 0; i
< 4; i
++) {
4091 reg
= FDI_RX_IIR(pipe
);
4092 temp
= I915_READ(reg
);
4093 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
4095 if (temp
& FDI_RX_BIT_LOCK
||
4096 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
4097 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
4098 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4102 udelay(1); /* should be 0.5us */
4105 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
4110 reg
= FDI_TX_CTL(pipe
);
4111 temp
= I915_READ(reg
);
4112 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
4113 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
4114 I915_WRITE(reg
, temp
);
4116 reg
= FDI_RX_CTL(pipe
);
4117 temp
= I915_READ(reg
);
4118 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
4119 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
4120 I915_WRITE(reg
, temp
);
4123 udelay(2); /* should be 1.5us */
4125 for (i
= 0; i
< 4; i
++) {
4126 reg
= FDI_RX_IIR(pipe
);
4127 temp
= I915_READ(reg
);
4128 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
4130 if (temp
& FDI_RX_SYMBOL_LOCK
||
4131 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
4132 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
4133 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4137 udelay(2); /* should be 1.5us */
4140 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
4144 DRM_DEBUG_KMS("FDI train done.\n");
4147 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
4149 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4150 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4151 int pipe
= intel_crtc
->pipe
;
4155 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4156 reg
= FDI_RX_CTL(pipe
);
4157 temp
= I915_READ(reg
);
4158 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
4159 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
4160 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
4161 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
4166 /* Switch from Rawclk to PCDclk */
4167 temp
= I915_READ(reg
);
4168 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
4173 /* Enable CPU FDI TX PLL, always on for Ironlake */
4174 reg
= FDI_TX_CTL(pipe
);
4175 temp
= I915_READ(reg
);
4176 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
4177 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
4184 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
4186 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4187 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4188 int pipe
= intel_crtc
->pipe
;
4192 /* Switch from PCDclk to Rawclk */
4193 reg
= FDI_RX_CTL(pipe
);
4194 temp
= I915_READ(reg
);
4195 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
4197 /* Disable CPU FDI TX PLL */
4198 reg
= FDI_TX_CTL(pipe
);
4199 temp
= I915_READ(reg
);
4200 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
4205 reg
= FDI_RX_CTL(pipe
);
4206 temp
= I915_READ(reg
);
4207 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
4209 /* Wait for the clocks to turn off. */
4214 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
4216 struct drm_device
*dev
= crtc
->dev
;
4217 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4218 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4219 int pipe
= intel_crtc
->pipe
;
4223 /* disable CPU FDI tx and PCH FDI rx */
4224 reg
= FDI_TX_CTL(pipe
);
4225 temp
= I915_READ(reg
);
4226 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
4229 reg
= FDI_RX_CTL(pipe
);
4230 temp
= I915_READ(reg
);
4231 temp
&= ~(0x7 << 16);
4232 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
4233 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
4238 /* Ironlake workaround, disable clock pointer after downing FDI */
4239 if (HAS_PCH_IBX(dev_priv
))
4240 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
4242 /* still set train pattern 1 */
4243 reg
= FDI_TX_CTL(pipe
);
4244 temp
= I915_READ(reg
);
4245 temp
&= ~FDI_LINK_TRAIN_NONE
;
4246 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
4247 I915_WRITE(reg
, temp
);
4249 reg
= FDI_RX_CTL(pipe
);
4250 temp
= I915_READ(reg
);
4251 if (HAS_PCH_CPT(dev_priv
)) {
4252 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
4253 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
4255 temp
&= ~FDI_LINK_TRAIN_NONE
;
4256 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
4258 /* BPC in FDI rx is consistent with that in PIPECONF */
4259 temp
&= ~(0x07 << 16);
4260 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
4261 I915_WRITE(reg
, temp
);
4267 bool intel_has_pending_fb_unpin(struct drm_i915_private
*dev_priv
)
4269 struct intel_crtc
*crtc
;
4271 /* Note that we don't need to be called with mode_config.lock here
4272 * as our list of CRTC objects is static for the lifetime of the
4273 * device and so cannot disappear as we iterate. Similarly, we can
4274 * happily treat the predicates as racy, atomic checks as userspace
4275 * cannot claim and pin a new fb without at least acquring the
4276 * struct_mutex and so serialising with us.
4278 for_each_intel_crtc(&dev_priv
->drm
, crtc
) {
4279 if (atomic_read(&crtc
->unpin_work_count
) == 0)
4282 if (crtc
->flip_work
)
4283 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
4291 static void page_flip_completed(struct intel_crtc
*intel_crtc
)
4293 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
4294 struct intel_flip_work
*work
= intel_crtc
->flip_work
;
4296 intel_crtc
->flip_work
= NULL
;
4299 drm_crtc_send_vblank_event(&intel_crtc
->base
, work
->event
);
4301 drm_crtc_vblank_put(&intel_crtc
->base
);
4303 wake_up_all(&dev_priv
->pending_flip_queue
);
4304 trace_i915_flip_complete(intel_crtc
->plane
,
4305 work
->pending_flip_obj
);
4307 queue_work(dev_priv
->wq
, &work
->unpin_work
);
4310 static int intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
4312 struct drm_device
*dev
= crtc
->dev
;
4313 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4316 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
4318 ret
= wait_event_interruptible_timeout(
4319 dev_priv
->pending_flip_queue
,
4320 !intel_crtc_has_pending_flip(crtc
),
4327 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4328 struct intel_flip_work
*work
;
4330 spin_lock_irq(&dev
->event_lock
);
4331 work
= intel_crtc
->flip_work
;
4332 if (work
&& !is_mmio_work(work
)) {
4333 WARN_ONCE(1, "Removing stuck page flip\n");
4334 page_flip_completed(intel_crtc
);
4336 spin_unlock_irq(&dev
->event_lock
);
4342 void lpt_disable_iclkip(struct drm_i915_private
*dev_priv
)
4346 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
4348 mutex_lock(&dev_priv
->sb_lock
);
4350 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4351 temp
|= SBI_SSCCTL_DISABLE
;
4352 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
4354 mutex_unlock(&dev_priv
->sb_lock
);
4357 /* Program iCLKIP clock to the desired frequency */
4358 static void lpt_program_iclkip(struct intel_crtc
*crtc
)
4360 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
4361 int clock
= crtc
->config
->base
.adjusted_mode
.crtc_clock
;
4362 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
4365 lpt_disable_iclkip(dev_priv
);
4367 /* The iCLK virtual clock root frequency is in MHz,
4368 * but the adjusted_mode->crtc_clock in in KHz. To get the
4369 * divisors, it is necessary to divide one by another, so we
4370 * convert the virtual clock precision to KHz here for higher
4373 for (auxdiv
= 0; auxdiv
< 2; auxdiv
++) {
4374 u32 iclk_virtual_root_freq
= 172800 * 1000;
4375 u32 iclk_pi_range
= 64;
4376 u32 desired_divisor
;
4378 desired_divisor
= DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
4380 divsel
= (desired_divisor
/ iclk_pi_range
) - 2;
4381 phaseinc
= desired_divisor
% iclk_pi_range
;
4384 * Near 20MHz is a corner case which is
4385 * out of range for the 7-bit divisor
4391 /* This should not happen with any sane values */
4392 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
4393 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
4394 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
4395 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
4397 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4404 mutex_lock(&dev_priv
->sb_lock
);
4406 /* Program SSCDIVINTPHASE6 */
4407 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
4408 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
4409 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
4410 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
4411 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
4412 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
4413 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
4414 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
4416 /* Program SSCAUXDIV */
4417 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
4418 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4419 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
4420 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
4422 /* Enable modulator and associated divider */
4423 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4424 temp
&= ~SBI_SSCCTL_DISABLE
;
4425 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
4427 mutex_unlock(&dev_priv
->sb_lock
);
4429 /* Wait for initialization time */
4432 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
4435 int lpt_get_iclkip(struct drm_i915_private
*dev_priv
)
4437 u32 divsel
, phaseinc
, auxdiv
;
4438 u32 iclk_virtual_root_freq
= 172800 * 1000;
4439 u32 iclk_pi_range
= 64;
4440 u32 desired_divisor
;
4443 if ((I915_READ(PIXCLK_GATE
) & PIXCLK_GATE_UNGATE
) == 0)
4446 mutex_lock(&dev_priv
->sb_lock
);
4448 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4449 if (temp
& SBI_SSCCTL_DISABLE
) {
4450 mutex_unlock(&dev_priv
->sb_lock
);
4454 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
4455 divsel
= (temp
& SBI_SSCDIVINTPHASE_DIVSEL_MASK
) >>
4456 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT
;
4457 phaseinc
= (temp
& SBI_SSCDIVINTPHASE_INCVAL_MASK
) >>
4458 SBI_SSCDIVINTPHASE_INCVAL_SHIFT
;
4460 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
4461 auxdiv
= (temp
& SBI_SSCAUXDIV_FINALDIV2SEL_MASK
) >>
4462 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT
;
4464 mutex_unlock(&dev_priv
->sb_lock
);
4466 desired_divisor
= (divsel
+ 2) * iclk_pi_range
+ phaseinc
;
4468 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
4469 desired_divisor
<< auxdiv
);
4472 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
4473 enum pipe pch_transcoder
)
4475 struct drm_device
*dev
= crtc
->base
.dev
;
4476 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4477 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
4479 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
4480 I915_READ(HTOTAL(cpu_transcoder
)));
4481 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
4482 I915_READ(HBLANK(cpu_transcoder
)));
4483 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
4484 I915_READ(HSYNC(cpu_transcoder
)));
4486 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
4487 I915_READ(VTOTAL(cpu_transcoder
)));
4488 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
4489 I915_READ(VBLANK(cpu_transcoder
)));
4490 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
4491 I915_READ(VSYNC(cpu_transcoder
)));
4492 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
4493 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
4496 static void cpt_set_fdi_bc_bifurcation(struct drm_device
*dev
, bool enable
)
4498 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4501 temp
= I915_READ(SOUTH_CHICKEN1
);
4502 if (!!(temp
& FDI_BC_BIFURCATION_SELECT
) == enable
)
4505 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
4506 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
4508 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
4510 temp
|= FDI_BC_BIFURCATION_SELECT
;
4512 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable
? "en" : "dis");
4513 I915_WRITE(SOUTH_CHICKEN1
, temp
);
4514 POSTING_READ(SOUTH_CHICKEN1
);
4517 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
4519 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4521 switch (intel_crtc
->pipe
) {
4525 if (intel_crtc
->config
->fdi_lanes
> 2)
4526 cpt_set_fdi_bc_bifurcation(dev
, false);
4528 cpt_set_fdi_bc_bifurcation(dev
, true);
4532 cpt_set_fdi_bc_bifurcation(dev
, true);
4540 /* Return which DP Port should be selected for Transcoder DP control */
4542 intel_trans_dp_port_sel(struct intel_crtc
*crtc
)
4544 struct drm_device
*dev
= crtc
->base
.dev
;
4545 struct intel_encoder
*encoder
;
4547 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
4548 if (encoder
->type
== INTEL_OUTPUT_DP
||
4549 encoder
->type
== INTEL_OUTPUT_EDP
)
4550 return enc_to_dig_port(&encoder
->base
)->port
;
4557 * Enable PCH resources required for PCH ports:
4559 * - FDI training & RX/TX
4560 * - update transcoder timings
4561 * - DP transcoding bits
4564 static void ironlake_pch_enable(const struct intel_crtc_state
*crtc_state
)
4566 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
4567 struct drm_device
*dev
= crtc
->base
.dev
;
4568 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4569 int pipe
= crtc
->pipe
;
4572 assert_pch_transcoder_disabled(dev_priv
, pipe
);
4574 if (IS_IVYBRIDGE(dev_priv
))
4575 ivybridge_update_fdi_bc_bifurcation(crtc
);
4577 /* Write the TU size bits before fdi link training, so that error
4578 * detection works. */
4579 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
4580 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
4582 /* For PCH output, training FDI link */
4583 dev_priv
->display
.fdi_link_train(crtc
, crtc_state
);
4585 /* We need to program the right clock selection before writing the pixel
4586 * mutliplier into the DPLL. */
4587 if (HAS_PCH_CPT(dev_priv
)) {
4590 temp
= I915_READ(PCH_DPLL_SEL
);
4591 temp
|= TRANS_DPLL_ENABLE(pipe
);
4592 sel
= TRANS_DPLLB_SEL(pipe
);
4593 if (crtc_state
->shared_dpll
==
4594 intel_get_shared_dpll_by_id(dev_priv
, DPLL_ID_PCH_PLL_B
))
4598 I915_WRITE(PCH_DPLL_SEL
, temp
);
4601 /* XXX: pch pll's can be enabled any time before we enable the PCH
4602 * transcoder, and we actually should do this to not upset any PCH
4603 * transcoder that already use the clock when we share it.
4605 * Note that enable_shared_dpll tries to do the right thing, but
4606 * get_shared_dpll unconditionally resets the pll - we need that to have
4607 * the right LVDS enable sequence. */
4608 intel_enable_shared_dpll(crtc
);
4610 /* set transcoder timing, panel must allow it */
4611 assert_panel_unlocked(dev_priv
, pipe
);
4612 ironlake_pch_transcoder_set_timings(crtc
, pipe
);
4614 intel_fdi_normal_train(crtc
);
4616 /* For PCH DP, enable TRANS_DP_CTL */
4617 if (HAS_PCH_CPT(dev_priv
) &&
4618 intel_crtc_has_dp_encoder(crtc_state
)) {
4619 const struct drm_display_mode
*adjusted_mode
=
4620 &crtc_state
->base
.adjusted_mode
;
4621 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
4622 i915_reg_t reg
= TRANS_DP_CTL(pipe
);
4623 temp
= I915_READ(reg
);
4624 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
4625 TRANS_DP_SYNC_MASK
|
4627 temp
|= TRANS_DP_OUTPUT_ENABLE
;
4628 temp
|= bpc
<< 9; /* same format but at 11:9 */
4630 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
4631 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
4632 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
4633 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
4635 switch (intel_trans_dp_port_sel(crtc
)) {
4637 temp
|= TRANS_DP_PORT_SEL_B
;
4640 temp
|= TRANS_DP_PORT_SEL_C
;
4643 temp
|= TRANS_DP_PORT_SEL_D
;
4649 I915_WRITE(reg
, temp
);
4652 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
4655 static void lpt_pch_enable(const struct intel_crtc_state
*crtc_state
)
4657 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
4658 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
4659 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
4661 assert_pch_transcoder_disabled(dev_priv
, TRANSCODER_A
);
4663 lpt_program_iclkip(crtc
);
4665 /* Set transcoder timing. */
4666 ironlake_pch_transcoder_set_timings(crtc
, PIPE_A
);
4668 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
4671 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
4673 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4674 i915_reg_t dslreg
= PIPEDSL(pipe
);
4677 temp
= I915_READ(dslreg
);
4679 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
4680 if (wait_for(I915_READ(dslreg
) != temp
, 5))
4681 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
4686 skl_update_scaler(struct intel_crtc_state
*crtc_state
, bool force_detach
,
4687 unsigned scaler_user
, int *scaler_id
, unsigned int rotation
,
4688 int src_w
, int src_h
, int dst_w
, int dst_h
)
4690 struct intel_crtc_scaler_state
*scaler_state
=
4691 &crtc_state
->scaler_state
;
4692 struct intel_crtc
*intel_crtc
=
4693 to_intel_crtc(crtc_state
->base
.crtc
);
4696 need_scaling
= drm_rotation_90_or_270(rotation
) ?
4697 (src_h
!= dst_w
|| src_w
!= dst_h
):
4698 (src_w
!= dst_w
|| src_h
!= dst_h
);
4701 * if plane is being disabled or scaler is no more required or force detach
4702 * - free scaler binded to this plane/crtc
4703 * - in order to do this, update crtc->scaler_usage
4705 * Here scaler state in crtc_state is set free so that
4706 * scaler can be assigned to other user. Actual register
4707 * update to free the scaler is done in plane/panel-fit programming.
4708 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4710 if (force_detach
|| !need_scaling
) {
4711 if (*scaler_id
>= 0) {
4712 scaler_state
->scaler_users
&= ~(1 << scaler_user
);
4713 scaler_state
->scalers
[*scaler_id
].in_use
= 0;
4715 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4716 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4717 intel_crtc
->pipe
, scaler_user
, *scaler_id
,
4718 scaler_state
->scaler_users
);
4725 if (src_w
< SKL_MIN_SRC_W
|| src_h
< SKL_MIN_SRC_H
||
4726 dst_w
< SKL_MIN_DST_W
|| dst_h
< SKL_MIN_DST_H
||
4728 src_w
> SKL_MAX_SRC_W
|| src_h
> SKL_MAX_SRC_H
||
4729 dst_w
> SKL_MAX_DST_W
|| dst_h
> SKL_MAX_DST_H
) {
4730 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4731 "size is out of scaler range\n",
4732 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
);
4736 /* mark this plane as a scaler user in crtc_state */
4737 scaler_state
->scaler_users
|= (1 << scaler_user
);
4738 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4739 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4740 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
,
4741 scaler_state
->scaler_users
);
4747 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4749 * @state: crtc's scaler state
4752 * 0 - scaler_usage updated successfully
4753 * error - requested scaling cannot be supported or other error condition
4755 int skl_update_scaler_crtc(struct intel_crtc_state
*state
)
4757 const struct drm_display_mode
*adjusted_mode
= &state
->base
.adjusted_mode
;
4759 return skl_update_scaler(state
, !state
->base
.active
, SKL_CRTC_INDEX
,
4760 &state
->scaler_state
.scaler_id
, DRM_ROTATE_0
,
4761 state
->pipe_src_w
, state
->pipe_src_h
,
4762 adjusted_mode
->crtc_hdisplay
, adjusted_mode
->crtc_vdisplay
);
4766 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4768 * @state: crtc's scaler state
4769 * @plane_state: atomic plane state to update
4772 * 0 - scaler_usage updated successfully
4773 * error - requested scaling cannot be supported or other error condition
4775 static int skl_update_scaler_plane(struct intel_crtc_state
*crtc_state
,
4776 struct intel_plane_state
*plane_state
)
4779 struct intel_plane
*intel_plane
=
4780 to_intel_plane(plane_state
->base
.plane
);
4781 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
4784 bool force_detach
= !fb
|| !plane_state
->base
.visible
;
4786 ret
= skl_update_scaler(crtc_state
, force_detach
,
4787 drm_plane_index(&intel_plane
->base
),
4788 &plane_state
->scaler_id
,
4789 plane_state
->base
.rotation
,
4790 drm_rect_width(&plane_state
->base
.src
) >> 16,
4791 drm_rect_height(&plane_state
->base
.src
) >> 16,
4792 drm_rect_width(&plane_state
->base
.dst
),
4793 drm_rect_height(&plane_state
->base
.dst
));
4795 if (ret
|| plane_state
->scaler_id
< 0)
4798 /* check colorkey */
4799 if (plane_state
->ckey
.flags
!= I915_SET_COLORKEY_NONE
) {
4800 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
4801 intel_plane
->base
.base
.id
,
4802 intel_plane
->base
.name
);
4806 /* Check src format */
4807 switch (fb
->format
->format
) {
4808 case DRM_FORMAT_RGB565
:
4809 case DRM_FORMAT_XBGR8888
:
4810 case DRM_FORMAT_XRGB8888
:
4811 case DRM_FORMAT_ABGR8888
:
4812 case DRM_FORMAT_ARGB8888
:
4813 case DRM_FORMAT_XRGB2101010
:
4814 case DRM_FORMAT_XBGR2101010
:
4815 case DRM_FORMAT_YUYV
:
4816 case DRM_FORMAT_YVYU
:
4817 case DRM_FORMAT_UYVY
:
4818 case DRM_FORMAT_VYUY
:
4821 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
4822 intel_plane
->base
.base
.id
, intel_plane
->base
.name
,
4823 fb
->base
.id
, fb
->format
->format
);
4830 static void skylake_scaler_disable(struct intel_crtc
*crtc
)
4834 for (i
= 0; i
< crtc
->num_scalers
; i
++)
4835 skl_detach_scaler(crtc
, i
);
4838 static void skylake_pfit_enable(struct intel_crtc
*crtc
)
4840 struct drm_device
*dev
= crtc
->base
.dev
;
4841 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4842 int pipe
= crtc
->pipe
;
4843 struct intel_crtc_scaler_state
*scaler_state
=
4844 &crtc
->config
->scaler_state
;
4846 if (crtc
->config
->pch_pfit
.enabled
) {
4849 if (WARN_ON(crtc
->config
->scaler_state
.scaler_id
< 0))
4852 id
= scaler_state
->scaler_id
;
4853 I915_WRITE(SKL_PS_CTRL(pipe
, id
), PS_SCALER_EN
|
4854 PS_FILTER_MEDIUM
| scaler_state
->scalers
[id
].mode
);
4855 I915_WRITE(SKL_PS_WIN_POS(pipe
, id
), crtc
->config
->pch_pfit
.pos
);
4856 I915_WRITE(SKL_PS_WIN_SZ(pipe
, id
), crtc
->config
->pch_pfit
.size
);
4860 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
4862 struct drm_device
*dev
= crtc
->base
.dev
;
4863 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4864 int pipe
= crtc
->pipe
;
4866 if (crtc
->config
->pch_pfit
.enabled
) {
4867 /* Force use of hard-coded filter coefficients
4868 * as some pre-programmed values are broken,
4871 if (IS_IVYBRIDGE(dev_priv
) || IS_HASWELL(dev_priv
))
4872 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
4873 PF_PIPE_SEL_IVB(pipe
));
4875 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
4876 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
->pch_pfit
.pos
);
4877 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
->pch_pfit
.size
);
4881 void hsw_enable_ips(struct intel_crtc
*crtc
)
4883 struct drm_device
*dev
= crtc
->base
.dev
;
4884 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4886 if (!crtc
->config
->ips_enabled
)
4890 * We can only enable IPS after we enable a plane and wait for a vblank
4891 * This function is called from post_plane_update, which is run after
4895 assert_plane_enabled(dev_priv
, crtc
->plane
);
4896 if (IS_BROADWELL(dev_priv
)) {
4897 mutex_lock(&dev_priv
->rps
.hw_lock
);
4898 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
4899 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4900 /* Quoting Art Runyan: "its not safe to expect any particular
4901 * value in IPS_CTL bit 31 after enabling IPS through the
4902 * mailbox." Moreover, the mailbox may return a bogus state,
4903 * so we need to just enable it and continue on.
4906 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
4907 /* The bit only becomes 1 in the next vblank, so this wait here
4908 * is essentially intel_wait_for_vblank. If we don't have this
4909 * and don't wait for vblanks until the end of crtc_enable, then
4910 * the HW state readout code will complain that the expected
4911 * IPS_CTL value is not the one we read. */
4912 if (intel_wait_for_register(dev_priv
,
4913 IPS_CTL
, IPS_ENABLE
, IPS_ENABLE
,
4915 DRM_ERROR("Timed out waiting for IPS enable\n");
4919 void hsw_disable_ips(struct intel_crtc
*crtc
)
4921 struct drm_device
*dev
= crtc
->base
.dev
;
4922 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4924 if (!crtc
->config
->ips_enabled
)
4927 assert_plane_enabled(dev_priv
, crtc
->plane
);
4928 if (IS_BROADWELL(dev_priv
)) {
4929 mutex_lock(&dev_priv
->rps
.hw_lock
);
4930 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
4931 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4932 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4933 if (intel_wait_for_register(dev_priv
,
4934 IPS_CTL
, IPS_ENABLE
, 0,
4936 DRM_ERROR("Timed out waiting for IPS disable\n");
4938 I915_WRITE(IPS_CTL
, 0);
4939 POSTING_READ(IPS_CTL
);
4942 /* We need to wait for a vblank before we can disable the plane. */
4943 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
4946 static void intel_crtc_dpms_overlay_disable(struct intel_crtc
*intel_crtc
)
4948 if (intel_crtc
->overlay
) {
4949 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4950 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4952 mutex_lock(&dev
->struct_mutex
);
4953 dev_priv
->mm
.interruptible
= false;
4954 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
4955 dev_priv
->mm
.interruptible
= true;
4956 mutex_unlock(&dev
->struct_mutex
);
4959 /* Let userspace switch the overlay on again. In most cases userspace
4960 * has to recompute where to put it anyway.
4965 * intel_post_enable_primary - Perform operations after enabling primary plane
4966 * @crtc: the CRTC whose primary plane was just enabled
4968 * Performs potentially sleeping operations that must be done after the primary
4969 * plane is enabled, such as updating FBC and IPS. Note that this may be
4970 * called due to an explicit primary plane update, or due to an implicit
4971 * re-enable that is caused when a sprite plane is updated to no longer
4972 * completely hide the primary plane.
4975 intel_post_enable_primary(struct drm_crtc
*crtc
)
4977 struct drm_device
*dev
= crtc
->dev
;
4978 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4979 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4980 int pipe
= intel_crtc
->pipe
;
4983 * FIXME IPS should be fine as long as one plane is
4984 * enabled, but in practice it seems to have problems
4985 * when going from primary only to sprite only and vice
4988 hsw_enable_ips(intel_crtc
);
4991 * Gen2 reports pipe underruns whenever all planes are disabled.
4992 * So don't enable underrun reporting before at least some planes
4994 * FIXME: Need to fix the logic to work when we turn off all planes
4995 * but leave the pipe running.
4997 if (IS_GEN2(dev_priv
))
4998 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5000 /* Underruns don't always raise interrupts, so check manually. */
5001 intel_check_cpu_fifo_underruns(dev_priv
);
5002 intel_check_pch_fifo_underruns(dev_priv
);
5005 /* FIXME move all this to pre_plane_update() with proper state tracking */
5007 intel_pre_disable_primary(struct drm_crtc
*crtc
)
5009 struct drm_device
*dev
= crtc
->dev
;
5010 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5011 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5012 int pipe
= intel_crtc
->pipe
;
5015 * Gen2 reports pipe underruns whenever all planes are disabled.
5016 * So diasble underrun reporting before all the planes get disabled.
5017 * FIXME: Need to fix the logic to work when we turn off all planes
5018 * but leave the pipe running.
5020 if (IS_GEN2(dev_priv
))
5021 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5024 * FIXME IPS should be fine as long as one plane is
5025 * enabled, but in practice it seems to have problems
5026 * when going from primary only to sprite only and vice
5029 hsw_disable_ips(intel_crtc
);
5032 /* FIXME get rid of this and use pre_plane_update */
5034 intel_pre_disable_primary_noatomic(struct drm_crtc
*crtc
)
5036 struct drm_device
*dev
= crtc
->dev
;
5037 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5038 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5039 int pipe
= intel_crtc
->pipe
;
5041 intel_pre_disable_primary(crtc
);
5044 * Vblank time updates from the shadow to live plane control register
5045 * are blocked if the memory self-refresh mode is active at that
5046 * moment. So to make sure the plane gets truly disabled, disable
5047 * first the self-refresh mode. The self-refresh enable bit in turn
5048 * will be checked/applied by the HW only at the next frame start
5049 * event which is after the vblank start event, so we need to have a
5050 * wait-for-vblank between disabling the plane and the pipe.
5052 if (HAS_GMCH_DISPLAY(dev_priv
) &&
5053 intel_set_memory_cxsr(dev_priv
, false))
5054 intel_wait_for_vblank(dev_priv
, pipe
);
5057 static void intel_post_plane_update(struct intel_crtc_state
*old_crtc_state
)
5059 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
5060 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
5061 struct intel_crtc_state
*pipe_config
=
5062 to_intel_crtc_state(crtc
->base
.state
);
5063 struct drm_plane
*primary
= crtc
->base
.primary
;
5064 struct drm_plane_state
*old_pri_state
=
5065 drm_atomic_get_existing_plane_state(old_state
, primary
);
5067 intel_frontbuffer_flip(to_i915(crtc
->base
.dev
), pipe_config
->fb_bits
);
5069 if (pipe_config
->update_wm_post
&& pipe_config
->base
.active
)
5070 intel_update_watermarks(crtc
);
5072 if (old_pri_state
) {
5073 struct intel_plane_state
*primary_state
=
5074 to_intel_plane_state(primary
->state
);
5075 struct intel_plane_state
*old_primary_state
=
5076 to_intel_plane_state(old_pri_state
);
5078 intel_fbc_post_update(crtc
);
5080 if (primary_state
->base
.visible
&&
5081 (needs_modeset(&pipe_config
->base
) ||
5082 !old_primary_state
->base
.visible
))
5083 intel_post_enable_primary(&crtc
->base
);
5087 static void intel_pre_plane_update(struct intel_crtc_state
*old_crtc_state
,
5088 struct intel_crtc_state
*pipe_config
)
5090 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
5091 struct drm_device
*dev
= crtc
->base
.dev
;
5092 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5093 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
5094 struct drm_plane
*primary
= crtc
->base
.primary
;
5095 struct drm_plane_state
*old_pri_state
=
5096 drm_atomic_get_existing_plane_state(old_state
, primary
);
5097 bool modeset
= needs_modeset(&pipe_config
->base
);
5098 struct intel_atomic_state
*old_intel_state
=
5099 to_intel_atomic_state(old_state
);
5101 if (old_pri_state
) {
5102 struct intel_plane_state
*primary_state
=
5103 to_intel_plane_state(primary
->state
);
5104 struct intel_plane_state
*old_primary_state
=
5105 to_intel_plane_state(old_pri_state
);
5107 intel_fbc_pre_update(crtc
, pipe_config
, primary_state
);
5109 if (old_primary_state
->base
.visible
&&
5110 (modeset
|| !primary_state
->base
.visible
))
5111 intel_pre_disable_primary(&crtc
->base
);
5115 * Vblank time updates from the shadow to live plane control register
5116 * are blocked if the memory self-refresh mode is active at that
5117 * moment. So to make sure the plane gets truly disabled, disable
5118 * first the self-refresh mode. The self-refresh enable bit in turn
5119 * will be checked/applied by the HW only at the next frame start
5120 * event which is after the vblank start event, so we need to have a
5121 * wait-for-vblank between disabling the plane and the pipe.
5123 if (HAS_GMCH_DISPLAY(dev_priv
) && old_crtc_state
->base
.active
&&
5124 pipe_config
->disable_cxsr
&& intel_set_memory_cxsr(dev_priv
, false))
5125 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
5128 * IVB workaround: must disable low power watermarks for at least
5129 * one frame before enabling scaling. LP watermarks can be re-enabled
5130 * when scaling is disabled.
5132 * WaCxSRDisabledForSpriteScaling:ivb
5134 if (pipe_config
->disable_lp_wm
&& ilk_disable_lp_wm(dev
))
5135 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
5138 * If we're doing a modeset, we're done. No need to do any pre-vblank
5139 * watermark programming here.
5141 if (needs_modeset(&pipe_config
->base
))
5145 * For platforms that support atomic watermarks, program the
5146 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5147 * will be the intermediate values that are safe for both pre- and
5148 * post- vblank; when vblank happens, the 'active' values will be set
5149 * to the final 'target' values and we'll do this again to get the
5150 * optimal watermarks. For gen9+ platforms, the values we program here
5151 * will be the final target values which will get automatically latched
5152 * at vblank time; no further programming will be necessary.
5154 * If a platform hasn't been transitioned to atomic watermarks yet,
5155 * we'll continue to update watermarks the old way, if flags tell
5158 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5159 dev_priv
->display
.initial_watermarks(old_intel_state
,
5161 else if (pipe_config
->update_wm_pre
)
5162 intel_update_watermarks(crtc
);
5165 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
, unsigned plane_mask
)
5167 struct drm_device
*dev
= crtc
->dev
;
5168 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5169 struct drm_plane
*p
;
5170 int pipe
= intel_crtc
->pipe
;
5172 intel_crtc_dpms_overlay_disable(intel_crtc
);
5174 drm_for_each_plane_mask(p
, dev
, plane_mask
)
5175 to_intel_plane(p
)->disable_plane(p
, crtc
);
5178 * FIXME: Once we grow proper nuclear flip support out of this we need
5179 * to compute the mask of flip planes precisely. For the time being
5180 * consider this a flip to a NULL plane.
5182 intel_frontbuffer_flip(to_i915(dev
), INTEL_FRONTBUFFER_ALL_MASK(pipe
));
5185 static void intel_encoders_pre_pll_enable(struct drm_crtc
*crtc
,
5186 struct intel_crtc_state
*crtc_state
,
5187 struct drm_atomic_state
*old_state
)
5189 struct drm_connector_state
*conn_state
;
5190 struct drm_connector
*conn
;
5193 for_each_new_connector_in_state(old_state
, conn
, conn_state
, i
) {
5194 struct intel_encoder
*encoder
=
5195 to_intel_encoder(conn_state
->best_encoder
);
5197 if (conn_state
->crtc
!= crtc
)
5200 if (encoder
->pre_pll_enable
)
5201 encoder
->pre_pll_enable(encoder
, crtc_state
, conn_state
);
5205 static void intel_encoders_pre_enable(struct drm_crtc
*crtc
,
5206 struct intel_crtc_state
*crtc_state
,
5207 struct drm_atomic_state
*old_state
)
5209 struct drm_connector_state
*conn_state
;
5210 struct drm_connector
*conn
;
5213 for_each_new_connector_in_state(old_state
, conn
, conn_state
, i
) {
5214 struct intel_encoder
*encoder
=
5215 to_intel_encoder(conn_state
->best_encoder
);
5217 if (conn_state
->crtc
!= crtc
)
5220 if (encoder
->pre_enable
)
5221 encoder
->pre_enable(encoder
, crtc_state
, conn_state
);
5225 static void intel_encoders_enable(struct drm_crtc
*crtc
,
5226 struct intel_crtc_state
*crtc_state
,
5227 struct drm_atomic_state
*old_state
)
5229 struct drm_connector_state
*conn_state
;
5230 struct drm_connector
*conn
;
5233 for_each_new_connector_in_state(old_state
, conn
, conn_state
, i
) {
5234 struct intel_encoder
*encoder
=
5235 to_intel_encoder(conn_state
->best_encoder
);
5237 if (conn_state
->crtc
!= crtc
)
5240 encoder
->enable(encoder
, crtc_state
, conn_state
);
5241 intel_opregion_notify_encoder(encoder
, true);
5245 static void intel_encoders_disable(struct drm_crtc
*crtc
,
5246 struct intel_crtc_state
*old_crtc_state
,
5247 struct drm_atomic_state
*old_state
)
5249 struct drm_connector_state
*old_conn_state
;
5250 struct drm_connector
*conn
;
5253 for_each_old_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5254 struct intel_encoder
*encoder
=
5255 to_intel_encoder(old_conn_state
->best_encoder
);
5257 if (old_conn_state
->crtc
!= crtc
)
5260 intel_opregion_notify_encoder(encoder
, false);
5261 encoder
->disable(encoder
, old_crtc_state
, old_conn_state
);
5265 static void intel_encoders_post_disable(struct drm_crtc
*crtc
,
5266 struct intel_crtc_state
*old_crtc_state
,
5267 struct drm_atomic_state
*old_state
)
5269 struct drm_connector_state
*old_conn_state
;
5270 struct drm_connector
*conn
;
5273 for_each_old_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5274 struct intel_encoder
*encoder
=
5275 to_intel_encoder(old_conn_state
->best_encoder
);
5277 if (old_conn_state
->crtc
!= crtc
)
5280 if (encoder
->post_disable
)
5281 encoder
->post_disable(encoder
, old_crtc_state
, old_conn_state
);
5285 static void intel_encoders_post_pll_disable(struct drm_crtc
*crtc
,
5286 struct intel_crtc_state
*old_crtc_state
,
5287 struct drm_atomic_state
*old_state
)
5289 struct drm_connector_state
*old_conn_state
;
5290 struct drm_connector
*conn
;
5293 for_each_old_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5294 struct intel_encoder
*encoder
=
5295 to_intel_encoder(old_conn_state
->best_encoder
);
5297 if (old_conn_state
->crtc
!= crtc
)
5300 if (encoder
->post_pll_disable
)
5301 encoder
->post_pll_disable(encoder
, old_crtc_state
, old_conn_state
);
5305 static void ironlake_crtc_enable(struct intel_crtc_state
*pipe_config
,
5306 struct drm_atomic_state
*old_state
)
5308 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5309 struct drm_device
*dev
= crtc
->dev
;
5310 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5311 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5312 int pipe
= intel_crtc
->pipe
;
5313 struct intel_atomic_state
*old_intel_state
=
5314 to_intel_atomic_state(old_state
);
5316 if (WARN_ON(intel_crtc
->active
))
5320 * Sometimes spurious CPU pipe underruns happen during FDI
5321 * training, at least with VGA+HDMI cloning. Suppress them.
5323 * On ILK we get an occasional spurious CPU pipe underruns
5324 * between eDP port A enable and vdd enable. Also PCH port
5325 * enable seems to result in the occasional CPU pipe underrun.
5327 * Spurious PCH underruns also occur during PCH enabling.
5329 if (intel_crtc
->config
->has_pch_encoder
|| IS_GEN5(dev_priv
))
5330 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5331 if (intel_crtc
->config
->has_pch_encoder
)
5332 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
5334 if (intel_crtc
->config
->has_pch_encoder
)
5335 intel_prepare_shared_dpll(intel_crtc
);
5337 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5338 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5340 intel_set_pipe_timings(intel_crtc
);
5341 intel_set_pipe_src_size(intel_crtc
);
5343 if (intel_crtc
->config
->has_pch_encoder
) {
5344 intel_cpu_transcoder_set_m_n(intel_crtc
,
5345 &intel_crtc
->config
->fdi_m_n
, NULL
);
5348 ironlake_set_pipeconf(crtc
);
5350 intel_crtc
->active
= true;
5352 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5354 if (intel_crtc
->config
->has_pch_encoder
) {
5355 /* Note: FDI PLL enabling _must_ be done before we enable the
5356 * cpu pipes, hence this is separate from all the other fdi/pch
5358 ironlake_fdi_pll_enable(intel_crtc
);
5360 assert_fdi_tx_disabled(dev_priv
, pipe
);
5361 assert_fdi_rx_disabled(dev_priv
, pipe
);
5364 ironlake_pfit_enable(intel_crtc
);
5367 * On ILK+ LUT must be loaded before the pipe is running but with
5370 intel_color_load_luts(&pipe_config
->base
);
5372 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5373 dev_priv
->display
.initial_watermarks(old_intel_state
, intel_crtc
->config
);
5374 intel_enable_pipe(intel_crtc
);
5376 if (intel_crtc
->config
->has_pch_encoder
)
5377 ironlake_pch_enable(pipe_config
);
5379 assert_vblank_disabled(crtc
);
5380 drm_crtc_vblank_on(crtc
);
5382 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5384 if (HAS_PCH_CPT(dev_priv
))
5385 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
5387 /* Must wait for vblank to avoid spurious PCH FIFO underruns */
5388 if (intel_crtc
->config
->has_pch_encoder
)
5389 intel_wait_for_vblank(dev_priv
, pipe
);
5390 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5391 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
5394 /* IPS only exists on ULT machines and is tied to pipe A. */
5395 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
5397 return HAS_IPS(to_i915(crtc
->base
.dev
)) && crtc
->pipe
== PIPE_A
;
5400 static void haswell_crtc_enable(struct intel_crtc_state
*pipe_config
,
5401 struct drm_atomic_state
*old_state
)
5403 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5404 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5405 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5406 int pipe
= intel_crtc
->pipe
, hsw_workaround_pipe
;
5407 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5408 struct intel_atomic_state
*old_intel_state
=
5409 to_intel_atomic_state(old_state
);
5411 if (WARN_ON(intel_crtc
->active
))
5414 if (intel_crtc
->config
->has_pch_encoder
)
5415 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5418 intel_encoders_pre_pll_enable(crtc
, pipe_config
, old_state
);
5420 if (intel_crtc
->config
->shared_dpll
)
5421 intel_enable_shared_dpll(intel_crtc
);
5423 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5424 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5426 if (!transcoder_is_dsi(cpu_transcoder
))
5427 intel_set_pipe_timings(intel_crtc
);
5429 intel_set_pipe_src_size(intel_crtc
);
5431 if (cpu_transcoder
!= TRANSCODER_EDP
&&
5432 !transcoder_is_dsi(cpu_transcoder
)) {
5433 I915_WRITE(PIPE_MULT(cpu_transcoder
),
5434 intel_crtc
->config
->pixel_multiplier
- 1);
5437 if (intel_crtc
->config
->has_pch_encoder
) {
5438 intel_cpu_transcoder_set_m_n(intel_crtc
,
5439 &intel_crtc
->config
->fdi_m_n
, NULL
);
5442 if (!transcoder_is_dsi(cpu_transcoder
))
5443 haswell_set_pipeconf(crtc
);
5445 haswell_set_pipemisc(crtc
);
5447 intel_color_set_csc(&pipe_config
->base
);
5449 intel_crtc
->active
= true;
5451 if (intel_crtc
->config
->has_pch_encoder
)
5452 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5454 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5456 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5458 if (intel_crtc
->config
->has_pch_encoder
)
5459 dev_priv
->display
.fdi_link_train(intel_crtc
, pipe_config
);
5461 if (!transcoder_is_dsi(cpu_transcoder
))
5462 intel_ddi_enable_pipe_clock(pipe_config
);
5464 if (INTEL_GEN(dev_priv
) >= 9)
5465 skylake_pfit_enable(intel_crtc
);
5467 ironlake_pfit_enable(intel_crtc
);
5470 * On ILK+ LUT must be loaded before the pipe is running but with
5473 intel_color_load_luts(&pipe_config
->base
);
5475 intel_ddi_set_pipe_settings(pipe_config
);
5476 if (!transcoder_is_dsi(cpu_transcoder
))
5477 intel_ddi_enable_transcoder_func(pipe_config
);
5479 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5480 dev_priv
->display
.initial_watermarks(old_intel_state
, pipe_config
);
5482 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5483 if (!transcoder_is_dsi(cpu_transcoder
))
5484 intel_enable_pipe(intel_crtc
);
5486 if (intel_crtc
->config
->has_pch_encoder
)
5487 lpt_pch_enable(pipe_config
);
5489 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DP_MST
))
5490 intel_ddi_set_vc_payload_alloc(pipe_config
, true);
5492 assert_vblank_disabled(crtc
);
5493 drm_crtc_vblank_on(crtc
);
5495 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5497 if (intel_crtc
->config
->has_pch_encoder
) {
5498 intel_wait_for_vblank(dev_priv
, pipe
);
5499 intel_wait_for_vblank(dev_priv
, pipe
);
5500 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5501 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5505 /* If we change the relative order between pipe/planes enabling, we need
5506 * to change the workaround. */
5507 hsw_workaround_pipe
= pipe_config
->hsw_workaround_pipe
;
5508 if (IS_HASWELL(dev_priv
) && hsw_workaround_pipe
!= INVALID_PIPE
) {
5509 intel_wait_for_vblank(dev_priv
, hsw_workaround_pipe
);
5510 intel_wait_for_vblank(dev_priv
, hsw_workaround_pipe
);
5514 static void ironlake_pfit_disable(struct intel_crtc
*crtc
, bool force
)
5516 struct drm_device
*dev
= crtc
->base
.dev
;
5517 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5518 int pipe
= crtc
->pipe
;
5520 /* To avoid upsetting the power well on haswell only disable the pfit if
5521 * it's in use. The hw state code will make sure we get this right. */
5522 if (force
|| crtc
->config
->pch_pfit
.enabled
) {
5523 I915_WRITE(PF_CTL(pipe
), 0);
5524 I915_WRITE(PF_WIN_POS(pipe
), 0);
5525 I915_WRITE(PF_WIN_SZ(pipe
), 0);
5529 static void ironlake_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5530 struct drm_atomic_state
*old_state
)
5532 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5533 struct drm_device
*dev
= crtc
->dev
;
5534 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5535 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5536 int pipe
= intel_crtc
->pipe
;
5539 * Sometimes spurious CPU pipe underruns happen when the
5540 * pipe is already disabled, but FDI RX/TX is still enabled.
5541 * Happens at least with VGA+HDMI cloning. Suppress them.
5543 if (intel_crtc
->config
->has_pch_encoder
) {
5544 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5545 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
5548 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5550 drm_crtc_vblank_off(crtc
);
5551 assert_vblank_disabled(crtc
);
5553 intel_disable_pipe(intel_crtc
);
5555 ironlake_pfit_disable(intel_crtc
, false);
5557 if (intel_crtc
->config
->has_pch_encoder
)
5558 ironlake_fdi_disable(crtc
);
5560 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5562 if (intel_crtc
->config
->has_pch_encoder
) {
5563 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
5565 if (HAS_PCH_CPT(dev_priv
)) {
5569 /* disable TRANS_DP_CTL */
5570 reg
= TRANS_DP_CTL(pipe
);
5571 temp
= I915_READ(reg
);
5572 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
5573 TRANS_DP_PORT_SEL_MASK
);
5574 temp
|= TRANS_DP_PORT_SEL_NONE
;
5575 I915_WRITE(reg
, temp
);
5577 /* disable DPLL_SEL */
5578 temp
= I915_READ(PCH_DPLL_SEL
);
5579 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
5580 I915_WRITE(PCH_DPLL_SEL
, temp
);
5583 ironlake_fdi_pll_disable(intel_crtc
);
5586 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5587 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
5590 static void haswell_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5591 struct drm_atomic_state
*old_state
)
5593 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5594 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5595 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5596 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5598 if (intel_crtc
->config
->has_pch_encoder
)
5599 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5602 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5604 drm_crtc_vblank_off(crtc
);
5605 assert_vblank_disabled(crtc
);
5607 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5608 if (!transcoder_is_dsi(cpu_transcoder
))
5609 intel_disable_pipe(intel_crtc
);
5611 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DP_MST
))
5612 intel_ddi_set_vc_payload_alloc(intel_crtc
->config
, false);
5614 if (!transcoder_is_dsi(cpu_transcoder
))
5615 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
5617 if (INTEL_GEN(dev_priv
) >= 9)
5618 skylake_scaler_disable(intel_crtc
);
5620 ironlake_pfit_disable(intel_crtc
, false);
5622 if (!transcoder_is_dsi(cpu_transcoder
))
5623 intel_ddi_disable_pipe_clock(intel_crtc
->config
);
5625 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5627 if (old_crtc_state
->has_pch_encoder
)
5628 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5632 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
5634 struct drm_device
*dev
= crtc
->base
.dev
;
5635 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5636 struct intel_crtc_state
*pipe_config
= crtc
->config
;
5638 if (!pipe_config
->gmch_pfit
.control
)
5642 * The panel fitter should only be adjusted whilst the pipe is disabled,
5643 * according to register description and PRM.
5645 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
5646 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5648 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
5649 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
5651 /* Border color in case we don't scale up to the full screen. Black by
5652 * default, change to something else for debugging. */
5653 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
5656 enum intel_display_power_domain
intel_port_to_power_domain(enum port port
)
5660 return POWER_DOMAIN_PORT_DDI_A_LANES
;
5662 return POWER_DOMAIN_PORT_DDI_B_LANES
;
5664 return POWER_DOMAIN_PORT_DDI_C_LANES
;
5666 return POWER_DOMAIN_PORT_DDI_D_LANES
;
5668 return POWER_DOMAIN_PORT_DDI_E_LANES
;
5671 return POWER_DOMAIN_PORT_OTHER
;
5675 static u64
get_crtc_power_domains(struct drm_crtc
*crtc
,
5676 struct intel_crtc_state
*crtc_state
)
5678 struct drm_device
*dev
= crtc
->dev
;
5679 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5680 struct drm_encoder
*encoder
;
5681 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5682 enum pipe pipe
= intel_crtc
->pipe
;
5684 enum transcoder transcoder
= crtc_state
->cpu_transcoder
;
5686 if (!crtc_state
->base
.active
)
5689 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
5690 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
5691 if (crtc_state
->pch_pfit
.enabled
||
5692 crtc_state
->pch_pfit
.force_thru
)
5693 mask
|= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
5695 drm_for_each_encoder_mask(encoder
, dev
, crtc_state
->base
.encoder_mask
) {
5696 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5698 mask
|= BIT_ULL(intel_encoder
->power_domain
);
5701 if (HAS_DDI(dev_priv
) && crtc_state
->has_audio
)
5702 mask
|= BIT(POWER_DOMAIN_AUDIO
);
5704 if (crtc_state
->shared_dpll
)
5705 mask
|= BIT_ULL(POWER_DOMAIN_PLLS
);
5711 modeset_get_crtc_power_domains(struct drm_crtc
*crtc
,
5712 struct intel_crtc_state
*crtc_state
)
5714 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5715 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5716 enum intel_display_power_domain domain
;
5717 u64 domains
, new_domains
, old_domains
;
5719 old_domains
= intel_crtc
->enabled_power_domains
;
5720 intel_crtc
->enabled_power_domains
= new_domains
=
5721 get_crtc_power_domains(crtc
, crtc_state
);
5723 domains
= new_domains
& ~old_domains
;
5725 for_each_power_domain(domain
, domains
)
5726 intel_display_power_get(dev_priv
, domain
);
5728 return old_domains
& ~new_domains
;
5731 static void modeset_put_power_domains(struct drm_i915_private
*dev_priv
,
5734 enum intel_display_power_domain domain
;
5736 for_each_power_domain(domain
, domains
)
5737 intel_display_power_put(dev_priv
, domain
);
5740 static void valleyview_crtc_enable(struct intel_crtc_state
*pipe_config
,
5741 struct drm_atomic_state
*old_state
)
5743 struct intel_atomic_state
*old_intel_state
=
5744 to_intel_atomic_state(old_state
);
5745 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5746 struct drm_device
*dev
= crtc
->dev
;
5747 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5748 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5749 int pipe
= intel_crtc
->pipe
;
5751 if (WARN_ON(intel_crtc
->active
))
5754 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5755 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5757 intel_set_pipe_timings(intel_crtc
);
5758 intel_set_pipe_src_size(intel_crtc
);
5760 if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_B
) {
5761 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5763 I915_WRITE(CHV_BLEND(pipe
), CHV_BLEND_LEGACY
);
5764 I915_WRITE(CHV_CANVAS(pipe
), 0);
5767 i9xx_set_pipeconf(intel_crtc
);
5769 intel_crtc
->active
= true;
5771 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5773 intel_encoders_pre_pll_enable(crtc
, pipe_config
, old_state
);
5775 if (IS_CHERRYVIEW(dev_priv
)) {
5776 chv_prepare_pll(intel_crtc
, intel_crtc
->config
);
5777 chv_enable_pll(intel_crtc
, intel_crtc
->config
);
5779 vlv_prepare_pll(intel_crtc
, intel_crtc
->config
);
5780 vlv_enable_pll(intel_crtc
, intel_crtc
->config
);
5783 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5785 i9xx_pfit_enable(intel_crtc
);
5787 intel_color_load_luts(&pipe_config
->base
);
5789 dev_priv
->display
.initial_watermarks(old_intel_state
,
5791 intel_enable_pipe(intel_crtc
);
5793 assert_vblank_disabled(crtc
);
5794 drm_crtc_vblank_on(crtc
);
5796 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5799 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
5801 struct drm_device
*dev
= crtc
->base
.dev
;
5802 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5804 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp0
);
5805 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp1
);
5808 static void i9xx_crtc_enable(struct intel_crtc_state
*pipe_config
,
5809 struct drm_atomic_state
*old_state
)
5811 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5812 struct drm_device
*dev
= crtc
->dev
;
5813 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5814 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5815 enum pipe pipe
= intel_crtc
->pipe
;
5817 if (WARN_ON(intel_crtc
->active
))
5820 i9xx_set_pll_dividers(intel_crtc
);
5822 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5823 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5825 intel_set_pipe_timings(intel_crtc
);
5826 intel_set_pipe_src_size(intel_crtc
);
5828 i9xx_set_pipeconf(intel_crtc
);
5830 intel_crtc
->active
= true;
5832 if (!IS_GEN2(dev_priv
))
5833 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5835 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5837 i9xx_enable_pll(intel_crtc
);
5839 i9xx_pfit_enable(intel_crtc
);
5841 intel_color_load_luts(&pipe_config
->base
);
5843 intel_update_watermarks(intel_crtc
);
5844 intel_enable_pipe(intel_crtc
);
5846 assert_vblank_disabled(crtc
);
5847 drm_crtc_vblank_on(crtc
);
5849 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5852 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
5854 struct drm_device
*dev
= crtc
->base
.dev
;
5855 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5857 if (!crtc
->config
->gmch_pfit
.control
)
5860 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5862 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
5863 I915_READ(PFIT_CONTROL
));
5864 I915_WRITE(PFIT_CONTROL
, 0);
5867 static void i9xx_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5868 struct drm_atomic_state
*old_state
)
5870 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5871 struct drm_device
*dev
= crtc
->dev
;
5872 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5873 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5874 int pipe
= intel_crtc
->pipe
;
5877 * On gen2 planes are double buffered but the pipe isn't, so we must
5878 * wait for planes to fully turn off before disabling the pipe.
5880 if (IS_GEN2(dev_priv
))
5881 intel_wait_for_vblank(dev_priv
, pipe
);
5883 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5885 drm_crtc_vblank_off(crtc
);
5886 assert_vblank_disabled(crtc
);
5888 intel_disable_pipe(intel_crtc
);
5890 i9xx_pfit_disable(intel_crtc
);
5892 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5894 if (!intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DSI
)) {
5895 if (IS_CHERRYVIEW(dev_priv
))
5896 chv_disable_pll(dev_priv
, pipe
);
5897 else if (IS_VALLEYVIEW(dev_priv
))
5898 vlv_disable_pll(dev_priv
, pipe
);
5900 i9xx_disable_pll(intel_crtc
);
5903 intel_encoders_post_pll_disable(crtc
, old_crtc_state
, old_state
);
5905 if (!IS_GEN2(dev_priv
))
5906 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5908 if (!dev_priv
->display
.initial_watermarks
)
5909 intel_update_watermarks(intel_crtc
);
5912 static void intel_crtc_disable_noatomic(struct drm_crtc
*crtc
)
5914 struct intel_encoder
*encoder
;
5915 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5916 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5917 enum intel_display_power_domain domain
;
5919 struct drm_atomic_state
*state
;
5920 struct intel_crtc_state
*crtc_state
;
5923 if (!intel_crtc
->active
)
5926 if (crtc
->primary
->state
->visible
) {
5927 WARN_ON(intel_crtc
->flip_work
);
5929 intel_pre_disable_primary_noatomic(crtc
);
5931 intel_crtc_disable_planes(crtc
, 1 << drm_plane_index(crtc
->primary
));
5932 crtc
->primary
->state
->visible
= false;
5935 state
= drm_atomic_state_alloc(crtc
->dev
);
5937 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
5938 crtc
->base
.id
, crtc
->name
);
5942 state
->acquire_ctx
= crtc
->dev
->mode_config
.acquire_ctx
;
5944 /* Everything's already locked, -EDEADLK can't happen. */
5945 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
5946 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
5948 WARN_ON(IS_ERR(crtc_state
) || ret
);
5950 dev_priv
->display
.crtc_disable(crtc_state
, state
);
5952 drm_atomic_state_put(state
);
5954 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
5955 crtc
->base
.id
, crtc
->name
);
5957 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->state
, NULL
) < 0);
5958 crtc
->state
->active
= false;
5959 intel_crtc
->active
= false;
5960 crtc
->enabled
= false;
5961 crtc
->state
->connector_mask
= 0;
5962 crtc
->state
->encoder_mask
= 0;
5964 for_each_encoder_on_crtc(crtc
->dev
, crtc
, encoder
)
5965 encoder
->base
.crtc
= NULL
;
5967 intel_fbc_disable(intel_crtc
);
5968 intel_update_watermarks(intel_crtc
);
5969 intel_disable_shared_dpll(intel_crtc
);
5971 domains
= intel_crtc
->enabled_power_domains
;
5972 for_each_power_domain(domain
, domains
)
5973 intel_display_power_put(dev_priv
, domain
);
5974 intel_crtc
->enabled_power_domains
= 0;
5976 dev_priv
->active_crtcs
&= ~(1 << intel_crtc
->pipe
);
5977 dev_priv
->min_pixclk
[intel_crtc
->pipe
] = 0;
5981 * turn all crtc's off, but do not adjust state
5982 * This has to be paired with a call to intel_modeset_setup_hw_state.
5984 int intel_display_suspend(struct drm_device
*dev
)
5986 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5987 struct drm_atomic_state
*state
;
5990 state
= drm_atomic_helper_suspend(dev
);
5991 ret
= PTR_ERR_OR_ZERO(state
);
5993 DRM_ERROR("Suspending crtc's failed with %i\n", ret
);
5995 dev_priv
->modeset_restore_state
= state
;
5999 void intel_encoder_destroy(struct drm_encoder
*encoder
)
6001 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
6003 drm_encoder_cleanup(encoder
);
6004 kfree(intel_encoder
);
6007 /* Cross check the actual hw state with our own modeset state tracking (and it's
6008 * internal consistency). */
6009 static void intel_connector_verify_state(struct intel_connector
*connector
)
6011 struct drm_crtc
*crtc
= connector
->base
.state
->crtc
;
6013 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6014 connector
->base
.base
.id
,
6015 connector
->base
.name
);
6017 if (connector
->get_hw_state(connector
)) {
6018 struct intel_encoder
*encoder
= connector
->encoder
;
6019 struct drm_connector_state
*conn_state
= connector
->base
.state
;
6021 I915_STATE_WARN(!crtc
,
6022 "connector enabled without attached crtc\n");
6027 I915_STATE_WARN(!crtc
->state
->active
,
6028 "connector is active, but attached crtc isn't\n");
6030 if (!encoder
|| encoder
->type
== INTEL_OUTPUT_DP_MST
)
6033 I915_STATE_WARN(conn_state
->best_encoder
!= &encoder
->base
,
6034 "atomic encoder doesn't match attached encoder\n");
6036 I915_STATE_WARN(conn_state
->crtc
!= encoder
->base
.crtc
,
6037 "attached encoder crtc differs from connector crtc\n");
6039 I915_STATE_WARN(crtc
&& crtc
->state
->active
,
6040 "attached crtc is active, but connector isn't\n");
6041 I915_STATE_WARN(!crtc
&& connector
->base
.state
->best_encoder
,
6042 "best encoder set without crtc!\n");
6046 int intel_connector_init(struct intel_connector
*connector
)
6048 drm_atomic_helper_connector_reset(&connector
->base
);
6050 if (!connector
->base
.state
)
6056 struct intel_connector
*intel_connector_alloc(void)
6058 struct intel_connector
*connector
;
6060 connector
= kzalloc(sizeof *connector
, GFP_KERNEL
);
6064 if (intel_connector_init(connector
) < 0) {
6072 /* Simple connector->get_hw_state implementation for encoders that support only
6073 * one connector and no cloning and hence the encoder state determines the state
6074 * of the connector. */
6075 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
6078 struct intel_encoder
*encoder
= connector
->encoder
;
6080 return encoder
->get_hw_state(encoder
, &pipe
);
6083 static int pipe_required_fdi_lanes(struct intel_crtc_state
*crtc_state
)
6085 if (crtc_state
->base
.enable
&& crtc_state
->has_pch_encoder
)
6086 return crtc_state
->fdi_lanes
;
6091 static int ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
6092 struct intel_crtc_state
*pipe_config
)
6094 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6095 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
6096 struct intel_crtc
*other_crtc
;
6097 struct intel_crtc_state
*other_crtc_state
;
6099 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6100 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6101 if (pipe_config
->fdi_lanes
> 4) {
6102 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6103 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6107 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
6108 if (pipe_config
->fdi_lanes
> 2) {
6109 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6110 pipe_config
->fdi_lanes
);
6117 if (INTEL_INFO(dev_priv
)->num_pipes
== 2)
6120 /* Ivybridge 3 pipe is really complicated */
6125 if (pipe_config
->fdi_lanes
<= 2)
6128 other_crtc
= intel_get_crtc_for_pipe(dev_priv
, PIPE_C
);
6130 intel_atomic_get_crtc_state(state
, other_crtc
);
6131 if (IS_ERR(other_crtc_state
))
6132 return PTR_ERR(other_crtc_state
);
6134 if (pipe_required_fdi_lanes(other_crtc_state
) > 0) {
6135 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6136 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6141 if (pipe_config
->fdi_lanes
> 2) {
6142 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6143 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6147 other_crtc
= intel_get_crtc_for_pipe(dev_priv
, PIPE_B
);
6149 intel_atomic_get_crtc_state(state
, other_crtc
);
6150 if (IS_ERR(other_crtc_state
))
6151 return PTR_ERR(other_crtc_state
);
6153 if (pipe_required_fdi_lanes(other_crtc_state
) > 2) {
6154 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6164 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
6165 struct intel_crtc_state
*pipe_config
)
6167 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6168 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6169 int lane
, link_bw
, fdi_dotclock
, ret
;
6170 bool needs_recompute
= false;
6173 /* FDI is a binary signal running at ~2.7GHz, encoding
6174 * each output octet as 10 bits. The actual frequency
6175 * is stored as a divider into a 100MHz clock, and the
6176 * mode pixel clock is stored in units of 1KHz.
6177 * Hence the bw of each lane in terms of the mode signal
6180 link_bw
= intel_fdi_link_freq(to_i915(dev
), pipe_config
);
6182 fdi_dotclock
= adjusted_mode
->crtc_clock
;
6184 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
6185 pipe_config
->pipe_bpp
);
6187 pipe_config
->fdi_lanes
= lane
;
6189 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
6190 link_bw
, &pipe_config
->fdi_m_n
);
6192 ret
= ironlake_check_fdi_lanes(dev
, intel_crtc
->pipe
, pipe_config
);
6193 if (ret
== -EINVAL
&& pipe_config
->pipe_bpp
> 6*3) {
6194 pipe_config
->pipe_bpp
-= 2*3;
6195 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6196 pipe_config
->pipe_bpp
);
6197 needs_recompute
= true;
6198 pipe_config
->bw_constrained
= true;
6203 if (needs_recompute
)
6209 static bool pipe_config_supports_ips(struct drm_i915_private
*dev_priv
,
6210 struct intel_crtc_state
*pipe_config
)
6212 if (pipe_config
->pipe_bpp
> 24)
6215 /* HSW can handle pixel rate up to cdclk? */
6216 if (IS_HASWELL(dev_priv
))
6220 * We compare against max which means we must take
6221 * the increased cdclk requirement into account when
6222 * calculating the new cdclk.
6224 * Should measure whether using a lower cdclk w/o IPS
6226 return pipe_config
->pixel_rate
<=
6227 dev_priv
->max_cdclk_freq
* 95 / 100;
6230 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
6231 struct intel_crtc_state
*pipe_config
)
6233 struct drm_device
*dev
= crtc
->base
.dev
;
6234 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6236 pipe_config
->ips_enabled
= i915
.enable_ips
&&
6237 hsw_crtc_supports_ips(crtc
) &&
6238 pipe_config_supports_ips(dev_priv
, pipe_config
);
6241 static bool intel_crtc_supports_double_wide(const struct intel_crtc
*crtc
)
6243 const struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6245 /* GDG double wide on either pipe, otherwise pipe A only */
6246 return INTEL_INFO(dev_priv
)->gen
< 4 &&
6247 (crtc
->pipe
== PIPE_A
|| IS_I915G(dev_priv
));
6250 static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state
*pipe_config
)
6252 uint32_t pixel_rate
;
6254 pixel_rate
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
6257 * We only use IF-ID interlacing. If we ever use
6258 * PF-ID we'll need to adjust the pixel_rate here.
6261 if (pipe_config
->pch_pfit
.enabled
) {
6262 uint64_t pipe_w
, pipe_h
, pfit_w
, pfit_h
;
6263 uint32_t pfit_size
= pipe_config
->pch_pfit
.size
;
6265 pipe_w
= pipe_config
->pipe_src_w
;
6266 pipe_h
= pipe_config
->pipe_src_h
;
6268 pfit_w
= (pfit_size
>> 16) & 0xFFFF;
6269 pfit_h
= pfit_size
& 0xFFFF;
6270 if (pipe_w
< pfit_w
)
6272 if (pipe_h
< pfit_h
)
6275 if (WARN_ON(!pfit_w
|| !pfit_h
))
6278 pixel_rate
= div_u64((uint64_t) pixel_rate
* pipe_w
* pipe_h
,
6285 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state
*crtc_state
)
6287 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->base
.crtc
->dev
);
6289 if (HAS_GMCH_DISPLAY(dev_priv
))
6290 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6291 crtc_state
->pixel_rate
=
6292 crtc_state
->base
.adjusted_mode
.crtc_clock
;
6294 crtc_state
->pixel_rate
=
6295 ilk_pipe_pixel_rate(crtc_state
);
6298 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
6299 struct intel_crtc_state
*pipe_config
)
6301 struct drm_device
*dev
= crtc
->base
.dev
;
6302 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6303 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6304 int clock_limit
= dev_priv
->max_dotclk_freq
;
6306 if (INTEL_GEN(dev_priv
) < 4) {
6307 clock_limit
= dev_priv
->max_cdclk_freq
* 9 / 10;
6310 * Enable double wide mode when the dot clock
6311 * is > 90% of the (display) core speed.
6313 if (intel_crtc_supports_double_wide(crtc
) &&
6314 adjusted_mode
->crtc_clock
> clock_limit
) {
6315 clock_limit
= dev_priv
->max_dotclk_freq
;
6316 pipe_config
->double_wide
= true;
6320 if (adjusted_mode
->crtc_clock
> clock_limit
) {
6321 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6322 adjusted_mode
->crtc_clock
, clock_limit
,
6323 yesno(pipe_config
->double_wide
));
6328 * Pipe horizontal size must be even in:
6330 * - LVDS dual channel mode
6331 * - Double wide pipe
6333 if ((intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_LVDS
) &&
6334 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
6335 pipe_config
->pipe_src_w
&= ~1;
6337 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6338 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6340 if ((INTEL_GEN(dev_priv
) > 4 || IS_G4X(dev_priv
)) &&
6341 adjusted_mode
->crtc_hsync_start
== adjusted_mode
->crtc_hdisplay
)
6344 intel_crtc_compute_pixel_rate(pipe_config
);
6346 if (HAS_IPS(dev_priv
))
6347 hsw_compute_ips_config(crtc
, pipe_config
);
6349 if (pipe_config
->has_pch_encoder
)
6350 return ironlake_fdi_compute_config(crtc
, pipe_config
);
6356 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
6358 while (*num
> DATA_LINK_M_N_MASK
||
6359 *den
> DATA_LINK_M_N_MASK
) {
6365 static void compute_m_n(unsigned int m
, unsigned int n
,
6366 uint32_t *ret_m
, uint32_t *ret_n
)
6368 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
6369 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
6370 intel_reduce_m_n_ratio(ret_m
, ret_n
);
6374 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
6375 int pixel_clock
, int link_clock
,
6376 struct intel_link_m_n
*m_n
)
6380 compute_m_n(bits_per_pixel
* pixel_clock
,
6381 link_clock
* nlanes
* 8,
6382 &m_n
->gmch_m
, &m_n
->gmch_n
);
6384 compute_m_n(pixel_clock
, link_clock
,
6385 &m_n
->link_m
, &m_n
->link_n
);
6388 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
6390 if (i915
.panel_use_ssc
>= 0)
6391 return i915
.panel_use_ssc
!= 0;
6392 return dev_priv
->vbt
.lvds_use_ssc
6393 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
6396 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
6398 return (1 << dpll
->n
) << 16 | dpll
->m2
;
6401 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
6403 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
6406 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
6407 struct intel_crtc_state
*crtc_state
,
6408 struct dpll
*reduced_clock
)
6410 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6413 if (IS_PINEVIEW(dev_priv
)) {
6414 fp
= pnv_dpll_compute_fp(&crtc_state
->dpll
);
6416 fp2
= pnv_dpll_compute_fp(reduced_clock
);
6418 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
6420 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
6423 crtc_state
->dpll_hw_state
.fp0
= fp
;
6425 crtc
->lowfreq_avail
= false;
6426 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6428 crtc_state
->dpll_hw_state
.fp1
= fp2
;
6429 crtc
->lowfreq_avail
= true;
6431 crtc_state
->dpll_hw_state
.fp1
= fp
;
6435 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
6441 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6442 * and set it to a reasonable value instead.
6444 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6445 reg_val
&= 0xffffff00;
6446 reg_val
|= 0x00000030;
6447 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6449 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6450 reg_val
&= 0x8cffffff;
6451 reg_val
= 0x8c000000;
6452 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6454 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6455 reg_val
&= 0xffffff00;
6456 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6458 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6459 reg_val
&= 0x00ffffff;
6460 reg_val
|= 0xb0000000;
6461 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6464 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
6465 struct intel_link_m_n
*m_n
)
6467 struct drm_device
*dev
= crtc
->base
.dev
;
6468 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6469 int pipe
= crtc
->pipe
;
6471 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6472 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
6473 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
6474 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
6477 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
6478 struct intel_link_m_n
*m_n
,
6479 struct intel_link_m_n
*m2_n2
)
6481 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6482 int pipe
= crtc
->pipe
;
6483 enum transcoder transcoder
= crtc
->config
->cpu_transcoder
;
6485 if (INTEL_GEN(dev_priv
) >= 5) {
6486 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6487 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
6488 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
6489 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
6490 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
6491 * for gen < 8) and if DRRS is supported (to make sure the
6492 * registers are not unnecessarily accessed).
6494 if (m2_n2
&& (IS_CHERRYVIEW(dev_priv
) ||
6495 INTEL_GEN(dev_priv
) < 8) && crtc
->config
->has_drrs
) {
6496 I915_WRITE(PIPE_DATA_M2(transcoder
),
6497 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
6498 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
6499 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
6500 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
6503 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6504 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
6505 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
6506 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
6510 void intel_dp_set_m_n(struct intel_crtc
*crtc
, enum link_m_n_set m_n
)
6512 struct intel_link_m_n
*dp_m_n
, *dp_m2_n2
= NULL
;
6515 dp_m_n
= &crtc
->config
->dp_m_n
;
6516 dp_m2_n2
= &crtc
->config
->dp_m2_n2
;
6517 } else if (m_n
== M2_N2
) {
6520 * M2_N2 registers are not supported. Hence m2_n2 divider value
6521 * needs to be programmed into M1_N1.
6523 dp_m_n
= &crtc
->config
->dp_m2_n2
;
6525 DRM_ERROR("Unsupported divider value\n");
6529 if (crtc
->config
->has_pch_encoder
)
6530 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
->dp_m_n
);
6532 intel_cpu_transcoder_set_m_n(crtc
, dp_m_n
, dp_m2_n2
);
6535 static void vlv_compute_dpll(struct intel_crtc
*crtc
,
6536 struct intel_crtc_state
*pipe_config
)
6538 pipe_config
->dpll_hw_state
.dpll
= DPLL_INTEGRATED_REF_CLK_VLV
|
6539 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
6540 if (crtc
->pipe
!= PIPE_A
)
6541 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
6543 /* DPLL not used with DSI, but still need the rest set up */
6544 if (!intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_DSI
))
6545 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
|
6546 DPLL_EXT_BUFFER_ENABLE_VLV
;
6548 pipe_config
->dpll_hw_state
.dpll_md
=
6549 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6552 static void chv_compute_dpll(struct intel_crtc
*crtc
,
6553 struct intel_crtc_state
*pipe_config
)
6555 pipe_config
->dpll_hw_state
.dpll
= DPLL_SSC_REF_CLK_CHV
|
6556 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
6557 if (crtc
->pipe
!= PIPE_A
)
6558 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
6560 /* DPLL not used with DSI, but still need the rest set up */
6561 if (!intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_DSI
))
6562 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
;
6564 pipe_config
->dpll_hw_state
.dpll_md
=
6565 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6568 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
6569 const struct intel_crtc_state
*pipe_config
)
6571 struct drm_device
*dev
= crtc
->base
.dev
;
6572 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6573 enum pipe pipe
= crtc
->pipe
;
6575 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
6576 u32 coreclk
, reg_val
;
6579 I915_WRITE(DPLL(pipe
),
6580 pipe_config
->dpll_hw_state
.dpll
&
6581 ~(DPLL_VCO_ENABLE
| DPLL_EXT_BUFFER_ENABLE_VLV
));
6583 /* No need to actually set up the DPLL with DSI */
6584 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
6587 mutex_lock(&dev_priv
->sb_lock
);
6589 bestn
= pipe_config
->dpll
.n
;
6590 bestm1
= pipe_config
->dpll
.m1
;
6591 bestm2
= pipe_config
->dpll
.m2
;
6592 bestp1
= pipe_config
->dpll
.p1
;
6593 bestp2
= pipe_config
->dpll
.p2
;
6595 /* See eDP HDMI DPIO driver vbios notes doc */
6597 /* PLL B needs special handling */
6599 vlv_pllb_recal_opamp(dev_priv
, pipe
);
6601 /* Set up Tx target for periodic Rcomp update */
6602 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
6604 /* Disable target IRef on PLL */
6605 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
6606 reg_val
&= 0x00ffffff;
6607 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
6609 /* Disable fast lock */
6610 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
6612 /* Set idtafcrecal before PLL is enabled */
6613 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
6614 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
6615 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
6616 mdiv
|= (1 << DPIO_K_SHIFT
);
6619 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6620 * but we don't support that).
6621 * Note: don't use the DAC post divider as it seems unstable.
6623 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
6624 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
6626 mdiv
|= DPIO_ENABLE_CALIBRATION
;
6627 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
6629 /* Set HBR and RBR LPF coefficients */
6630 if (pipe_config
->port_clock
== 162000 ||
6631 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_ANALOG
) ||
6632 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_HDMI
))
6633 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
6636 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
6639 if (intel_crtc_has_dp_encoder(pipe_config
)) {
6640 /* Use SSC source */
6642 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6645 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6647 } else { /* HDMI or VGA */
6648 /* Use bend source */
6650 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6653 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6657 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
6658 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
6659 if (intel_crtc_has_dp_encoder(crtc
->config
))
6660 coreclk
|= 0x01000000;
6661 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
6663 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
6664 mutex_unlock(&dev_priv
->sb_lock
);
6667 static void chv_prepare_pll(struct intel_crtc
*crtc
,
6668 const struct intel_crtc_state
*pipe_config
)
6670 struct drm_device
*dev
= crtc
->base
.dev
;
6671 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6672 enum pipe pipe
= crtc
->pipe
;
6673 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
6674 u32 loopfilter
, tribuf_calcntr
;
6675 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
6679 /* Enable Refclk and SSC */
6680 I915_WRITE(DPLL(pipe
),
6681 pipe_config
->dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
6683 /* No need to actually set up the DPLL with DSI */
6684 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
6687 bestn
= pipe_config
->dpll
.n
;
6688 bestm2_frac
= pipe_config
->dpll
.m2
& 0x3fffff;
6689 bestm1
= pipe_config
->dpll
.m1
;
6690 bestm2
= pipe_config
->dpll
.m2
>> 22;
6691 bestp1
= pipe_config
->dpll
.p1
;
6692 bestp2
= pipe_config
->dpll
.p2
;
6693 vco
= pipe_config
->dpll
.vco
;
6697 mutex_lock(&dev_priv
->sb_lock
);
6699 /* p1 and p2 divider */
6700 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
6701 5 << DPIO_CHV_S1_DIV_SHIFT
|
6702 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
6703 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
6704 1 << DPIO_CHV_K_DIV_SHIFT
);
6706 /* Feedback post-divider - m2 */
6707 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
6709 /* Feedback refclk divider - n and m1 */
6710 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
6711 DPIO_CHV_M1_DIV_BY_2
|
6712 1 << DPIO_CHV_N_DIV_SHIFT
);
6714 /* M2 fraction division */
6715 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
6717 /* M2 fraction division enable */
6718 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
6719 dpio_val
&= ~(DPIO_CHV_FEEDFWD_GAIN_MASK
| DPIO_CHV_FRAC_DIV_EN
);
6720 dpio_val
|= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
);
6722 dpio_val
|= DPIO_CHV_FRAC_DIV_EN
;
6723 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
), dpio_val
);
6725 /* Program digital lock detect threshold */
6726 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW9(port
));
6727 dpio_val
&= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK
|
6728 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
);
6729 dpio_val
|= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT
);
6731 dpio_val
|= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
;
6732 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW9(port
), dpio_val
);
6735 if (vco
== 5400000) {
6736 loopfilter
|= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT
);
6737 loopfilter
|= (0x8 << DPIO_CHV_INT_COEFF_SHIFT
);
6738 loopfilter
|= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6739 tribuf_calcntr
= 0x9;
6740 } else if (vco
<= 6200000) {
6741 loopfilter
|= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT
);
6742 loopfilter
|= (0xB << DPIO_CHV_INT_COEFF_SHIFT
);
6743 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6744 tribuf_calcntr
= 0x9;
6745 } else if (vco
<= 6480000) {
6746 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
6747 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
6748 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6749 tribuf_calcntr
= 0x8;
6751 /* Not supported. Apply the same limits as in the max case */
6752 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
6753 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
6754 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6757 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
6759 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW8(port
));
6760 dpio_val
&= ~DPIO_CHV_TDC_TARGET_CNT_MASK
;
6761 dpio_val
|= (tribuf_calcntr
<< DPIO_CHV_TDC_TARGET_CNT_SHIFT
);
6762 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW8(port
), dpio_val
);
6765 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
6766 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
6769 mutex_unlock(&dev_priv
->sb_lock
);
6773 * vlv_force_pll_on - forcibly enable just the PLL
6774 * @dev_priv: i915 private structure
6775 * @pipe: pipe PLL to enable
6776 * @dpll: PLL configuration
6778 * Enable the PLL for @pipe using the supplied @dpll config. To be used
6779 * in cases where we need the PLL enabled even when @pipe is not going to
6782 int vlv_force_pll_on(struct drm_i915_private
*dev_priv
, enum pipe pipe
,
6783 const struct dpll
*dpll
)
6785 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
6786 struct intel_crtc_state
*pipe_config
;
6788 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
6792 pipe_config
->base
.crtc
= &crtc
->base
;
6793 pipe_config
->pixel_multiplier
= 1;
6794 pipe_config
->dpll
= *dpll
;
6796 if (IS_CHERRYVIEW(dev_priv
)) {
6797 chv_compute_dpll(crtc
, pipe_config
);
6798 chv_prepare_pll(crtc
, pipe_config
);
6799 chv_enable_pll(crtc
, pipe_config
);
6801 vlv_compute_dpll(crtc
, pipe_config
);
6802 vlv_prepare_pll(crtc
, pipe_config
);
6803 vlv_enable_pll(crtc
, pipe_config
);
6812 * vlv_force_pll_off - forcibly disable just the PLL
6813 * @dev_priv: i915 private structure
6814 * @pipe: pipe PLL to disable
6816 * Disable the PLL for @pipe. To be used in cases where we need
6817 * the PLL enabled even when @pipe is not going to be enabled.
6819 void vlv_force_pll_off(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
6821 if (IS_CHERRYVIEW(dev_priv
))
6822 chv_disable_pll(dev_priv
, pipe
);
6824 vlv_disable_pll(dev_priv
, pipe
);
6827 static void i9xx_compute_dpll(struct intel_crtc
*crtc
,
6828 struct intel_crtc_state
*crtc_state
,
6829 struct dpll
*reduced_clock
)
6831 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6833 struct dpll
*clock
= &crtc_state
->dpll
;
6835 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
6837 dpll
= DPLL_VGA_MODE_DIS
;
6839 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
))
6840 dpll
|= DPLLB_MODE_LVDS
;
6842 dpll
|= DPLLB_MODE_DAC_SERIAL
;
6844 if (IS_I945G(dev_priv
) || IS_I945GM(dev_priv
) ||
6845 IS_G33(dev_priv
) || IS_PINEVIEW(dev_priv
)) {
6846 dpll
|= (crtc_state
->pixel_multiplier
- 1)
6847 << SDVO_MULTIPLIER_SHIFT_HIRES
;
6850 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
6851 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
6852 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6854 if (intel_crtc_has_dp_encoder(crtc_state
))
6855 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6857 /* compute bitmask from p1 value */
6858 if (IS_PINEVIEW(dev_priv
))
6859 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
6861 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6862 if (IS_G4X(dev_priv
) && reduced_clock
)
6863 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
6865 switch (clock
->p2
) {
6867 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
6870 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
6873 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
6876 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
6879 if (INTEL_GEN(dev_priv
) >= 4)
6880 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
6882 if (crtc_state
->sdvo_tv_clock
)
6883 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
6884 else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6885 intel_panel_use_ssc(dev_priv
))
6886 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
6888 dpll
|= PLL_REF_INPUT_DREFCLK
;
6890 dpll
|= DPLL_VCO_ENABLE
;
6891 crtc_state
->dpll_hw_state
.dpll
= dpll
;
6893 if (INTEL_GEN(dev_priv
) >= 4) {
6894 u32 dpll_md
= (crtc_state
->pixel_multiplier
- 1)
6895 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6896 crtc_state
->dpll_hw_state
.dpll_md
= dpll_md
;
6900 static void i8xx_compute_dpll(struct intel_crtc
*crtc
,
6901 struct intel_crtc_state
*crtc_state
,
6902 struct dpll
*reduced_clock
)
6904 struct drm_device
*dev
= crtc
->base
.dev
;
6905 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6907 struct dpll
*clock
= &crtc_state
->dpll
;
6909 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
6911 dpll
= DPLL_VGA_MODE_DIS
;
6913 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
6914 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6917 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
6919 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6921 dpll
|= PLL_P2_DIVIDE_BY_4
;
6924 if (!IS_I830(dev_priv
) &&
6925 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DVO
))
6926 dpll
|= DPLL_DVO_2X_MODE
;
6928 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6929 intel_panel_use_ssc(dev_priv
))
6930 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
6932 dpll
|= PLL_REF_INPUT_DREFCLK
;
6934 dpll
|= DPLL_VCO_ENABLE
;
6935 crtc_state
->dpll_hw_state
.dpll
= dpll
;
6938 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
6940 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
6941 enum pipe pipe
= intel_crtc
->pipe
;
6942 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
6943 const struct drm_display_mode
*adjusted_mode
= &intel_crtc
->config
->base
.adjusted_mode
;
6944 uint32_t crtc_vtotal
, crtc_vblank_end
;
6947 /* We need to be careful not to changed the adjusted mode, for otherwise
6948 * the hw state checker will get angry at the mismatch. */
6949 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
6950 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
6952 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
6953 /* the chip adds 2 halflines automatically */
6955 crtc_vblank_end
-= 1;
6957 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
6958 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
6960 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
6961 adjusted_mode
->crtc_htotal
/ 2;
6963 vsyncshift
+= adjusted_mode
->crtc_htotal
;
6966 if (INTEL_GEN(dev_priv
) > 3)
6967 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
6969 I915_WRITE(HTOTAL(cpu_transcoder
),
6970 (adjusted_mode
->crtc_hdisplay
- 1) |
6971 ((adjusted_mode
->crtc_htotal
- 1) << 16));
6972 I915_WRITE(HBLANK(cpu_transcoder
),
6973 (adjusted_mode
->crtc_hblank_start
- 1) |
6974 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
6975 I915_WRITE(HSYNC(cpu_transcoder
),
6976 (adjusted_mode
->crtc_hsync_start
- 1) |
6977 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
6979 I915_WRITE(VTOTAL(cpu_transcoder
),
6980 (adjusted_mode
->crtc_vdisplay
- 1) |
6981 ((crtc_vtotal
- 1) << 16));
6982 I915_WRITE(VBLANK(cpu_transcoder
),
6983 (adjusted_mode
->crtc_vblank_start
- 1) |
6984 ((crtc_vblank_end
- 1) << 16));
6985 I915_WRITE(VSYNC(cpu_transcoder
),
6986 (adjusted_mode
->crtc_vsync_start
- 1) |
6987 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
6989 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
6990 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
6991 * documented on the DDI_FUNC_CTL register description, EDP Input Select
6993 if (IS_HASWELL(dev_priv
) && cpu_transcoder
== TRANSCODER_EDP
&&
6994 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
6995 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
6999 static void intel_set_pipe_src_size(struct intel_crtc
*intel_crtc
)
7001 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7002 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7003 enum pipe pipe
= intel_crtc
->pipe
;
7005 /* pipesrc controls the size that is scaled from, which should
7006 * always be the user's requested size.
7008 I915_WRITE(PIPESRC(pipe
),
7009 ((intel_crtc
->config
->pipe_src_w
- 1) << 16) |
7010 (intel_crtc
->config
->pipe_src_h
- 1));
7013 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
7014 struct intel_crtc_state
*pipe_config
)
7016 struct drm_device
*dev
= crtc
->base
.dev
;
7017 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7018 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
7021 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
7022 pipe_config
->base
.adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
7023 pipe_config
->base
.adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
7024 tmp
= I915_READ(HBLANK(cpu_transcoder
));
7025 pipe_config
->base
.adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
7026 pipe_config
->base
.adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
7027 tmp
= I915_READ(HSYNC(cpu_transcoder
));
7028 pipe_config
->base
.adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
7029 pipe_config
->base
.adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
7031 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
7032 pipe_config
->base
.adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
7033 pipe_config
->base
.adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
7034 tmp
= I915_READ(VBLANK(cpu_transcoder
));
7035 pipe_config
->base
.adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
7036 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
7037 tmp
= I915_READ(VSYNC(cpu_transcoder
));
7038 pipe_config
->base
.adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
7039 pipe_config
->base
.adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
7041 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
7042 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
7043 pipe_config
->base
.adjusted_mode
.crtc_vtotal
+= 1;
7044 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
+= 1;
7048 static void intel_get_pipe_src_size(struct intel_crtc
*crtc
,
7049 struct intel_crtc_state
*pipe_config
)
7051 struct drm_device
*dev
= crtc
->base
.dev
;
7052 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7055 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
7056 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
7057 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
7059 pipe_config
->base
.mode
.vdisplay
= pipe_config
->pipe_src_h
;
7060 pipe_config
->base
.mode
.hdisplay
= pipe_config
->pipe_src_w
;
7063 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
7064 struct intel_crtc_state
*pipe_config
)
7066 mode
->hdisplay
= pipe_config
->base
.adjusted_mode
.crtc_hdisplay
;
7067 mode
->htotal
= pipe_config
->base
.adjusted_mode
.crtc_htotal
;
7068 mode
->hsync_start
= pipe_config
->base
.adjusted_mode
.crtc_hsync_start
;
7069 mode
->hsync_end
= pipe_config
->base
.adjusted_mode
.crtc_hsync_end
;
7071 mode
->vdisplay
= pipe_config
->base
.adjusted_mode
.crtc_vdisplay
;
7072 mode
->vtotal
= pipe_config
->base
.adjusted_mode
.crtc_vtotal
;
7073 mode
->vsync_start
= pipe_config
->base
.adjusted_mode
.crtc_vsync_start
;
7074 mode
->vsync_end
= pipe_config
->base
.adjusted_mode
.crtc_vsync_end
;
7076 mode
->flags
= pipe_config
->base
.adjusted_mode
.flags
;
7077 mode
->type
= DRM_MODE_TYPE_DRIVER
;
7079 mode
->clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
7081 mode
->hsync
= drm_mode_hsync(mode
);
7082 mode
->vrefresh
= drm_mode_vrefresh(mode
);
7083 drm_mode_set_name(mode
);
7086 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
7088 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
7093 if ((intel_crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
7094 (intel_crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
7095 pipeconf
|= I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
;
7097 if (intel_crtc
->config
->double_wide
)
7098 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
7100 /* only g4x and later have fancy bpc/dither controls */
7101 if (IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
7102 IS_CHERRYVIEW(dev_priv
)) {
7103 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7104 if (intel_crtc
->config
->dither
&& intel_crtc
->config
->pipe_bpp
!= 30)
7105 pipeconf
|= PIPECONF_DITHER_EN
|
7106 PIPECONF_DITHER_TYPE_SP
;
7108 switch (intel_crtc
->config
->pipe_bpp
) {
7110 pipeconf
|= PIPECONF_6BPC
;
7113 pipeconf
|= PIPECONF_8BPC
;
7116 pipeconf
|= PIPECONF_10BPC
;
7119 /* Case prevented by intel_choose_pipe_bpp_dither. */
7124 if (HAS_PIPE_CXSR(dev_priv
)) {
7125 if (intel_crtc
->lowfreq_avail
) {
7126 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
7127 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
7129 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
7133 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
7134 if (INTEL_GEN(dev_priv
) < 4 ||
7135 intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
7136 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
7138 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
7140 pipeconf
|= PIPECONF_PROGRESSIVE
;
7142 if ((IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) &&
7143 intel_crtc
->config
->limited_color_range
)
7144 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
7146 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
7147 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
7150 static int i8xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7151 struct intel_crtc_state
*crtc_state
)
7153 struct drm_device
*dev
= crtc
->base
.dev
;
7154 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7155 const struct intel_limit
*limit
;
7158 memset(&crtc_state
->dpll_hw_state
, 0,
7159 sizeof(crtc_state
->dpll_hw_state
));
7161 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7162 if (intel_panel_use_ssc(dev_priv
)) {
7163 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7164 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7167 limit
= &intel_limits_i8xx_lvds
;
7168 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DVO
)) {
7169 limit
= &intel_limits_i8xx_dvo
;
7171 limit
= &intel_limits_i8xx_dac
;
7174 if (!crtc_state
->clock_set
&&
7175 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7176 refclk
, NULL
, &crtc_state
->dpll
)) {
7177 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7181 i8xx_compute_dpll(crtc
, crtc_state
, NULL
);
7186 static int g4x_crtc_compute_clock(struct intel_crtc
*crtc
,
7187 struct intel_crtc_state
*crtc_state
)
7189 struct drm_device
*dev
= crtc
->base
.dev
;
7190 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7191 const struct intel_limit
*limit
;
7194 memset(&crtc_state
->dpll_hw_state
, 0,
7195 sizeof(crtc_state
->dpll_hw_state
));
7197 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7198 if (intel_panel_use_ssc(dev_priv
)) {
7199 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7200 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7203 if (intel_is_dual_link_lvds(dev
))
7204 limit
= &intel_limits_g4x_dual_channel_lvds
;
7206 limit
= &intel_limits_g4x_single_channel_lvds
;
7207 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
) ||
7208 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
)) {
7209 limit
= &intel_limits_g4x_hdmi
;
7210 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
)) {
7211 limit
= &intel_limits_g4x_sdvo
;
7213 /* The option is for other outputs */
7214 limit
= &intel_limits_i9xx_sdvo
;
7217 if (!crtc_state
->clock_set
&&
7218 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7219 refclk
, NULL
, &crtc_state
->dpll
)) {
7220 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7224 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7229 static int pnv_crtc_compute_clock(struct intel_crtc
*crtc
,
7230 struct intel_crtc_state
*crtc_state
)
7232 struct drm_device
*dev
= crtc
->base
.dev
;
7233 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7234 const struct intel_limit
*limit
;
7237 memset(&crtc_state
->dpll_hw_state
, 0,
7238 sizeof(crtc_state
->dpll_hw_state
));
7240 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7241 if (intel_panel_use_ssc(dev_priv
)) {
7242 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7243 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7246 limit
= &intel_limits_pineview_lvds
;
7248 limit
= &intel_limits_pineview_sdvo
;
7251 if (!crtc_state
->clock_set
&&
7252 !pnv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7253 refclk
, NULL
, &crtc_state
->dpll
)) {
7254 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7258 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7263 static int i9xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7264 struct intel_crtc_state
*crtc_state
)
7266 struct drm_device
*dev
= crtc
->base
.dev
;
7267 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7268 const struct intel_limit
*limit
;
7271 memset(&crtc_state
->dpll_hw_state
, 0,
7272 sizeof(crtc_state
->dpll_hw_state
));
7274 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7275 if (intel_panel_use_ssc(dev_priv
)) {
7276 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7277 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7280 limit
= &intel_limits_i9xx_lvds
;
7282 limit
= &intel_limits_i9xx_sdvo
;
7285 if (!crtc_state
->clock_set
&&
7286 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7287 refclk
, NULL
, &crtc_state
->dpll
)) {
7288 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7292 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7297 static int chv_crtc_compute_clock(struct intel_crtc
*crtc
,
7298 struct intel_crtc_state
*crtc_state
)
7300 int refclk
= 100000;
7301 const struct intel_limit
*limit
= &intel_limits_chv
;
7303 memset(&crtc_state
->dpll_hw_state
, 0,
7304 sizeof(crtc_state
->dpll_hw_state
));
7306 if (!crtc_state
->clock_set
&&
7307 !chv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7308 refclk
, NULL
, &crtc_state
->dpll
)) {
7309 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7313 chv_compute_dpll(crtc
, crtc_state
);
7318 static int vlv_crtc_compute_clock(struct intel_crtc
*crtc
,
7319 struct intel_crtc_state
*crtc_state
)
7321 int refclk
= 100000;
7322 const struct intel_limit
*limit
= &intel_limits_vlv
;
7324 memset(&crtc_state
->dpll_hw_state
, 0,
7325 sizeof(crtc_state
->dpll_hw_state
));
7327 if (!crtc_state
->clock_set
&&
7328 !vlv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7329 refclk
, NULL
, &crtc_state
->dpll
)) {
7330 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7334 vlv_compute_dpll(crtc
, crtc_state
);
7339 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
7340 struct intel_crtc_state
*pipe_config
)
7342 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7345 if (INTEL_GEN(dev_priv
) <= 3 &&
7346 (IS_I830(dev_priv
) || !IS_MOBILE(dev_priv
)))
7349 tmp
= I915_READ(PFIT_CONTROL
);
7350 if (!(tmp
& PFIT_ENABLE
))
7353 /* Check whether the pfit is attached to our pipe. */
7354 if (INTEL_GEN(dev_priv
) < 4) {
7355 if (crtc
->pipe
!= PIPE_B
)
7358 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
7362 pipe_config
->gmch_pfit
.control
= tmp
;
7363 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
7366 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
7367 struct intel_crtc_state
*pipe_config
)
7369 struct drm_device
*dev
= crtc
->base
.dev
;
7370 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7371 int pipe
= pipe_config
->cpu_transcoder
;
7374 int refclk
= 100000;
7376 /* In case of DSI, DPLL will not be used */
7377 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7380 mutex_lock(&dev_priv
->sb_lock
);
7381 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
7382 mutex_unlock(&dev_priv
->sb_lock
);
7384 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
7385 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
7386 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
7387 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
7388 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
7390 pipe_config
->port_clock
= vlv_calc_dpll_params(refclk
, &clock
);
7394 i9xx_get_initial_plane_config(struct intel_crtc
*crtc
,
7395 struct intel_initial_plane_config
*plane_config
)
7397 struct drm_device
*dev
= crtc
->base
.dev
;
7398 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7399 u32 val
, base
, offset
;
7400 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
7401 int fourcc
, pixel_format
;
7402 unsigned int aligned_height
;
7403 struct drm_framebuffer
*fb
;
7404 struct intel_framebuffer
*intel_fb
;
7406 val
= I915_READ(DSPCNTR(plane
));
7407 if (!(val
& DISPLAY_PLANE_ENABLE
))
7410 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
7412 DRM_DEBUG_KMS("failed to alloc fb\n");
7416 fb
= &intel_fb
->base
;
7420 if (INTEL_GEN(dev_priv
) >= 4) {
7421 if (val
& DISPPLANE_TILED
) {
7422 plane_config
->tiling
= I915_TILING_X
;
7423 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
7427 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
7428 fourcc
= i9xx_format_to_fourcc(pixel_format
);
7429 fb
->format
= drm_format_info(fourcc
);
7431 if (INTEL_GEN(dev_priv
) >= 4) {
7432 if (plane_config
->tiling
)
7433 offset
= I915_READ(DSPTILEOFF(plane
));
7435 offset
= I915_READ(DSPLINOFF(plane
));
7436 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
7438 base
= I915_READ(DSPADDR(plane
));
7440 plane_config
->base
= base
;
7442 val
= I915_READ(PIPESRC(pipe
));
7443 fb
->width
= ((val
>> 16) & 0xfff) + 1;
7444 fb
->height
= ((val
>> 0) & 0xfff) + 1;
7446 val
= I915_READ(DSPSTRIDE(pipe
));
7447 fb
->pitches
[0] = val
& 0xffffffc0;
7449 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
7451 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
7453 DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7454 pipe_name(pipe
), plane
, fb
->width
, fb
->height
,
7455 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
7456 plane_config
->size
);
7458 plane_config
->fb
= intel_fb
;
7461 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
7462 struct intel_crtc_state
*pipe_config
)
7464 struct drm_device
*dev
= crtc
->base
.dev
;
7465 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7466 int pipe
= pipe_config
->cpu_transcoder
;
7467 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
7469 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
, pll_dw3
;
7470 int refclk
= 100000;
7472 /* In case of DSI, DPLL will not be used */
7473 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7476 mutex_lock(&dev_priv
->sb_lock
);
7477 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
7478 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
7479 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
7480 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
7481 pll_dw3
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
7482 mutex_unlock(&dev_priv
->sb_lock
);
7484 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
7485 clock
.m2
= (pll_dw0
& 0xff) << 22;
7486 if (pll_dw3
& DPIO_CHV_FRAC_DIV_EN
)
7487 clock
.m2
|= pll_dw2
& 0x3fffff;
7488 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
7489 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
7490 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
7492 pipe_config
->port_clock
= chv_calc_dpll_params(refclk
, &clock
);
7495 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
7496 struct intel_crtc_state
*pipe_config
)
7498 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7499 enum intel_display_power_domain power_domain
;
7503 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
7504 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
7507 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7508 pipe_config
->shared_dpll
= NULL
;
7512 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
7513 if (!(tmp
& PIPECONF_ENABLE
))
7516 if (IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
7517 IS_CHERRYVIEW(dev_priv
)) {
7518 switch (tmp
& PIPECONF_BPC_MASK
) {
7520 pipe_config
->pipe_bpp
= 18;
7523 pipe_config
->pipe_bpp
= 24;
7525 case PIPECONF_10BPC
:
7526 pipe_config
->pipe_bpp
= 30;
7533 if ((IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) &&
7534 (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
7535 pipe_config
->limited_color_range
= true;
7537 if (INTEL_GEN(dev_priv
) < 4)
7538 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
7540 intel_get_pipe_timings(crtc
, pipe_config
);
7541 intel_get_pipe_src_size(crtc
, pipe_config
);
7543 i9xx_get_pfit_config(crtc
, pipe_config
);
7545 if (INTEL_GEN(dev_priv
) >= 4) {
7546 /* No way to read it out on pipes B and C */
7547 if (IS_CHERRYVIEW(dev_priv
) && crtc
->pipe
!= PIPE_A
)
7548 tmp
= dev_priv
->chv_dpll_md
[crtc
->pipe
];
7550 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
7551 pipe_config
->pixel_multiplier
=
7552 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
7553 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
7554 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
7555 } else if (IS_I945G(dev_priv
) || IS_I945GM(dev_priv
) ||
7556 IS_G33(dev_priv
) || IS_PINEVIEW(dev_priv
)) {
7557 tmp
= I915_READ(DPLL(crtc
->pipe
));
7558 pipe_config
->pixel_multiplier
=
7559 ((tmp
& SDVO_MULTIPLIER_MASK
)
7560 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
7562 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7563 * port and will be fixed up in the encoder->get_config
7565 pipe_config
->pixel_multiplier
= 1;
7567 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
7568 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
)) {
7570 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
7571 * on 830. Filter it out here so that we don't
7572 * report errors due to that.
7574 if (IS_I830(dev_priv
))
7575 pipe_config
->dpll_hw_state
.dpll
&= ~DPLL_DVO_2X_MODE
;
7577 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
7578 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
7580 /* Mask out read-only status bits. */
7581 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
7582 DPLL_PORTC_READY_MASK
|
7583 DPLL_PORTB_READY_MASK
);
7586 if (IS_CHERRYVIEW(dev_priv
))
7587 chv_crtc_clock_get(crtc
, pipe_config
);
7588 else if (IS_VALLEYVIEW(dev_priv
))
7589 vlv_crtc_clock_get(crtc
, pipe_config
);
7591 i9xx_crtc_clock_get(crtc
, pipe_config
);
7594 * Normally the dotclock is filled in by the encoder .get_config()
7595 * but in case the pipe is enabled w/o any ports we need a sane
7598 pipe_config
->base
.adjusted_mode
.crtc_clock
=
7599 pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
7604 intel_display_power_put(dev_priv
, power_domain
);
7609 static void ironlake_init_pch_refclk(struct drm_i915_private
*dev_priv
)
7611 struct intel_encoder
*encoder
;
7614 bool has_lvds
= false;
7615 bool has_cpu_edp
= false;
7616 bool has_panel
= false;
7617 bool has_ck505
= false;
7618 bool can_ssc
= false;
7619 bool using_ssc_source
= false;
7621 /* We need to take the global config into account */
7622 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
7623 switch (encoder
->type
) {
7624 case INTEL_OUTPUT_LVDS
:
7628 case INTEL_OUTPUT_EDP
:
7630 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
7638 if (HAS_PCH_IBX(dev_priv
)) {
7639 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
7640 can_ssc
= has_ck505
;
7646 /* Check if any DPLLs are using the SSC source */
7647 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
7648 u32 temp
= I915_READ(PCH_DPLL(i
));
7650 if (!(temp
& DPLL_VCO_ENABLE
))
7653 if ((temp
& PLL_REF_INPUT_MASK
) ==
7654 PLLB_REF_INPUT_SPREADSPECTRUMIN
) {
7655 using_ssc_source
= true;
7660 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
7661 has_panel
, has_lvds
, has_ck505
, using_ssc_source
);
7663 /* Ironlake: try to setup display ref clock before DPLL
7664 * enabling. This is only under driver's control after
7665 * PCH B stepping, previous chipset stepping should be
7666 * ignoring this setting.
7668 val
= I915_READ(PCH_DREF_CONTROL
);
7670 /* As we must carefully and slowly disable/enable each source in turn,
7671 * compute the final state we want first and check if we need to
7672 * make any changes at all.
7675 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
7677 final
|= DREF_NONSPREAD_CK505_ENABLE
;
7679 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
7681 final
&= ~DREF_SSC_SOURCE_MASK
;
7682 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7683 final
&= ~DREF_SSC1_ENABLE
;
7686 final
|= DREF_SSC_SOURCE_ENABLE
;
7688 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
7689 final
|= DREF_SSC1_ENABLE
;
7692 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
7693 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
7695 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
7697 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7698 } else if (using_ssc_source
) {
7699 final
|= DREF_SSC_SOURCE_ENABLE
;
7700 final
|= DREF_SSC1_ENABLE
;
7706 /* Always enable nonspread source */
7707 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
7710 val
|= DREF_NONSPREAD_CK505_ENABLE
;
7712 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
7715 val
&= ~DREF_SSC_SOURCE_MASK
;
7716 val
|= DREF_SSC_SOURCE_ENABLE
;
7718 /* SSC must be turned on before enabling the CPU output */
7719 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
7720 DRM_DEBUG_KMS("Using SSC on panel\n");
7721 val
|= DREF_SSC1_ENABLE
;
7723 val
&= ~DREF_SSC1_ENABLE
;
7725 /* Get SSC going before enabling the outputs */
7726 I915_WRITE(PCH_DREF_CONTROL
, val
);
7727 POSTING_READ(PCH_DREF_CONTROL
);
7730 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7732 /* Enable CPU source on CPU attached eDP */
7734 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
7735 DRM_DEBUG_KMS("Using SSC on eDP\n");
7736 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
7738 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
7740 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7742 I915_WRITE(PCH_DREF_CONTROL
, val
);
7743 POSTING_READ(PCH_DREF_CONTROL
);
7746 DRM_DEBUG_KMS("Disabling CPU source output\n");
7748 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7750 /* Turn off CPU output */
7751 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7753 I915_WRITE(PCH_DREF_CONTROL
, val
);
7754 POSTING_READ(PCH_DREF_CONTROL
);
7757 if (!using_ssc_source
) {
7758 DRM_DEBUG_KMS("Disabling SSC source\n");
7760 /* Turn off the SSC source */
7761 val
&= ~DREF_SSC_SOURCE_MASK
;
7762 val
|= DREF_SSC_SOURCE_DISABLE
;
7765 val
&= ~DREF_SSC1_ENABLE
;
7767 I915_WRITE(PCH_DREF_CONTROL
, val
);
7768 POSTING_READ(PCH_DREF_CONTROL
);
7773 BUG_ON(val
!= final
);
7776 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
7780 tmp
= I915_READ(SOUTH_CHICKEN2
);
7781 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
7782 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
7784 if (wait_for_us(I915_READ(SOUTH_CHICKEN2
) &
7785 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
7786 DRM_ERROR("FDI mPHY reset assert timeout\n");
7788 tmp
= I915_READ(SOUTH_CHICKEN2
);
7789 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
7790 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
7792 if (wait_for_us((I915_READ(SOUTH_CHICKEN2
) &
7793 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
7794 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
7797 /* WaMPhyProgramming:hsw */
7798 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
7802 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
7803 tmp
&= ~(0xFF << 24);
7804 tmp
|= (0x12 << 24);
7805 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
7807 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
7809 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
7811 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
7813 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
7815 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
7816 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
7817 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
7819 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
7820 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
7821 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
7823 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
7826 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
7828 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
7831 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
7833 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
7836 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
7838 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
7841 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
7843 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
7844 tmp
&= ~(0xFF << 16);
7845 tmp
|= (0x1C << 16);
7846 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
7848 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
7849 tmp
&= ~(0xFF << 16);
7850 tmp
|= (0x1C << 16);
7851 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
7853 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
7855 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
7857 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
7859 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
7861 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
7862 tmp
&= ~(0xF << 28);
7864 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
7866 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
7867 tmp
&= ~(0xF << 28);
7869 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
7872 /* Implements 3 different sequences from BSpec chapter "Display iCLK
7873 * Programming" based on the parameters passed:
7874 * - Sequence to enable CLKOUT_DP
7875 * - Sequence to enable CLKOUT_DP without spread
7876 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
7878 static void lpt_enable_clkout_dp(struct drm_i915_private
*dev_priv
,
7879 bool with_spread
, bool with_fdi
)
7883 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
7885 if (WARN(HAS_PCH_LPT_LP(dev_priv
) &&
7886 with_fdi
, "LP PCH doesn't have FDI\n"))
7889 mutex_lock(&dev_priv
->sb_lock
);
7891 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7892 tmp
&= ~SBI_SSCCTL_DISABLE
;
7893 tmp
|= SBI_SSCCTL_PATHALT
;
7894 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7899 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7900 tmp
&= ~SBI_SSCCTL_PATHALT
;
7901 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7904 lpt_reset_fdi_mphy(dev_priv
);
7905 lpt_program_fdi_mphy(dev_priv
);
7909 reg
= HAS_PCH_LPT_LP(dev_priv
) ? SBI_GEN0
: SBI_DBUFF0
;
7910 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
7911 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
7912 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
7914 mutex_unlock(&dev_priv
->sb_lock
);
7917 /* Sequence to disable CLKOUT_DP */
7918 static void lpt_disable_clkout_dp(struct drm_i915_private
*dev_priv
)
7922 mutex_lock(&dev_priv
->sb_lock
);
7924 reg
= HAS_PCH_LPT_LP(dev_priv
) ? SBI_GEN0
: SBI_DBUFF0
;
7925 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
7926 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
7927 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
7929 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7930 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
7931 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
7932 tmp
|= SBI_SSCCTL_PATHALT
;
7933 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7936 tmp
|= SBI_SSCCTL_DISABLE
;
7937 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7940 mutex_unlock(&dev_priv
->sb_lock
);
7943 #define BEND_IDX(steps) ((50 + (steps)) / 5)
7945 static const uint16_t sscdivintphase
[] = {
7946 [BEND_IDX( 50)] = 0x3B23,
7947 [BEND_IDX( 45)] = 0x3B23,
7948 [BEND_IDX( 40)] = 0x3C23,
7949 [BEND_IDX( 35)] = 0x3C23,
7950 [BEND_IDX( 30)] = 0x3D23,
7951 [BEND_IDX( 25)] = 0x3D23,
7952 [BEND_IDX( 20)] = 0x3E23,
7953 [BEND_IDX( 15)] = 0x3E23,
7954 [BEND_IDX( 10)] = 0x3F23,
7955 [BEND_IDX( 5)] = 0x3F23,
7956 [BEND_IDX( 0)] = 0x0025,
7957 [BEND_IDX( -5)] = 0x0025,
7958 [BEND_IDX(-10)] = 0x0125,
7959 [BEND_IDX(-15)] = 0x0125,
7960 [BEND_IDX(-20)] = 0x0225,
7961 [BEND_IDX(-25)] = 0x0225,
7962 [BEND_IDX(-30)] = 0x0325,
7963 [BEND_IDX(-35)] = 0x0325,
7964 [BEND_IDX(-40)] = 0x0425,
7965 [BEND_IDX(-45)] = 0x0425,
7966 [BEND_IDX(-50)] = 0x0525,
7971 * steps -50 to 50 inclusive, in steps of 5
7972 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
7973 * change in clock period = -(steps / 10) * 5.787 ps
7975 static void lpt_bend_clkout_dp(struct drm_i915_private
*dev_priv
, int steps
)
7978 int idx
= BEND_IDX(steps
);
7980 if (WARN_ON(steps
% 5 != 0))
7983 if (WARN_ON(idx
>= ARRAY_SIZE(sscdivintphase
)))
7986 mutex_lock(&dev_priv
->sb_lock
);
7988 if (steps
% 10 != 0)
7992 intel_sbi_write(dev_priv
, SBI_SSCDITHPHASE
, tmp
, SBI_ICLK
);
7994 tmp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE
, SBI_ICLK
);
7996 tmp
|= sscdivintphase
[idx
];
7997 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE
, tmp
, SBI_ICLK
);
7999 mutex_unlock(&dev_priv
->sb_lock
);
8004 static void lpt_init_pch_refclk(struct drm_i915_private
*dev_priv
)
8006 struct intel_encoder
*encoder
;
8007 bool has_vga
= false;
8009 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
8010 switch (encoder
->type
) {
8011 case INTEL_OUTPUT_ANALOG
:
8020 lpt_bend_clkout_dp(dev_priv
, 0);
8021 lpt_enable_clkout_dp(dev_priv
, true, true);
8023 lpt_disable_clkout_dp(dev_priv
);
8028 * Initialize reference clocks when the driver loads
8030 void intel_init_pch_refclk(struct drm_i915_private
*dev_priv
)
8032 if (HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
))
8033 ironlake_init_pch_refclk(dev_priv
);
8034 else if (HAS_PCH_LPT(dev_priv
))
8035 lpt_init_pch_refclk(dev_priv
);
8038 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
8040 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
8041 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8042 int pipe
= intel_crtc
->pipe
;
8047 switch (intel_crtc
->config
->pipe_bpp
) {
8049 val
|= PIPECONF_6BPC
;
8052 val
|= PIPECONF_8BPC
;
8055 val
|= PIPECONF_10BPC
;
8058 val
|= PIPECONF_12BPC
;
8061 /* Case prevented by intel_choose_pipe_bpp_dither. */
8065 if (intel_crtc
->config
->dither
)
8066 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
8068 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8069 val
|= PIPECONF_INTERLACED_ILK
;
8071 val
|= PIPECONF_PROGRESSIVE
;
8073 if (intel_crtc
->config
->limited_color_range
)
8074 val
|= PIPECONF_COLOR_RANGE_SELECT
;
8076 I915_WRITE(PIPECONF(pipe
), val
);
8077 POSTING_READ(PIPECONF(pipe
));
8080 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
8082 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
8083 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8084 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
8087 if (IS_HASWELL(dev_priv
) && intel_crtc
->config
->dither
)
8088 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
8090 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8091 val
|= PIPECONF_INTERLACED_ILK
;
8093 val
|= PIPECONF_PROGRESSIVE
;
8095 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
8096 POSTING_READ(PIPECONF(cpu_transcoder
));
8099 static void haswell_set_pipemisc(struct drm_crtc
*crtc
)
8101 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
8102 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8104 if (IS_BROADWELL(dev_priv
) || INTEL_INFO(dev_priv
)->gen
>= 9) {
8107 switch (intel_crtc
->config
->pipe_bpp
) {
8109 val
|= PIPEMISC_DITHER_6_BPC
;
8112 val
|= PIPEMISC_DITHER_8_BPC
;
8115 val
|= PIPEMISC_DITHER_10_BPC
;
8118 val
|= PIPEMISC_DITHER_12_BPC
;
8121 /* Case prevented by pipe_config_set_bpp. */
8125 if (intel_crtc
->config
->dither
)
8126 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
8128 I915_WRITE(PIPEMISC(intel_crtc
->pipe
), val
);
8132 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
8135 * Account for spread spectrum to avoid
8136 * oversubscribing the link. Max center spread
8137 * is 2.5%; use 5% for safety's sake.
8139 u32 bps
= target_clock
* bpp
* 21 / 20;
8140 return DIV_ROUND_UP(bps
, link_bw
* 8);
8143 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
8145 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
8148 static void ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
8149 struct intel_crtc_state
*crtc_state
,
8150 struct dpll
*reduced_clock
)
8152 struct drm_crtc
*crtc
= &intel_crtc
->base
;
8153 struct drm_device
*dev
= crtc
->dev
;
8154 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8158 /* Enable autotuning of the PLL clock (if permissible) */
8160 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8161 if ((intel_panel_use_ssc(dev_priv
) &&
8162 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
8163 (HAS_PCH_IBX(dev_priv
) && intel_is_dual_link_lvds(dev
)))
8165 } else if (crtc_state
->sdvo_tv_clock
)
8168 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
8170 if (ironlake_needs_fb_cb_tune(&crtc_state
->dpll
, factor
))
8173 if (reduced_clock
) {
8174 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
8176 if (reduced_clock
->m
< factor
* reduced_clock
->n
)
8184 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
))
8185 dpll
|= DPLLB_MODE_LVDS
;
8187 dpll
|= DPLLB_MODE_DAC_SERIAL
;
8189 dpll
|= (crtc_state
->pixel_multiplier
- 1)
8190 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
8192 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
8193 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
8194 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8196 if (intel_crtc_has_dp_encoder(crtc_state
))
8197 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8200 * The high speed IO clock is only really required for
8201 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8202 * possible to share the DPLL between CRT and HDMI. Enabling
8203 * the clock needlessly does no real harm, except use up a
8204 * bit of power potentially.
8206 * We'll limit this to IVB with 3 pipes, since it has only two
8207 * DPLLs and so DPLL sharing is the only way to get three pipes
8208 * driving PCH ports at the same time. On SNB we could do this,
8209 * and potentially avoid enabling the second DPLL, but it's not
8210 * clear if it''s a win or loss power wise. No point in doing
8211 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8213 if (INTEL_INFO(dev_priv
)->num_pipes
== 3 &&
8214 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
))
8215 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8217 /* compute bitmask from p1 value */
8218 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8220 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
8222 switch (crtc_state
->dpll
.p2
) {
8224 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
8227 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
8230 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
8233 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
8237 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
8238 intel_panel_use_ssc(dev_priv
))
8239 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
8241 dpll
|= PLL_REF_INPUT_DREFCLK
;
8243 dpll
|= DPLL_VCO_ENABLE
;
8245 crtc_state
->dpll_hw_state
.dpll
= dpll
;
8246 crtc_state
->dpll_hw_state
.fp0
= fp
;
8247 crtc_state
->dpll_hw_state
.fp1
= fp2
;
8250 static int ironlake_crtc_compute_clock(struct intel_crtc
*crtc
,
8251 struct intel_crtc_state
*crtc_state
)
8253 struct drm_device
*dev
= crtc
->base
.dev
;
8254 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8255 struct dpll reduced_clock
;
8256 bool has_reduced_clock
= false;
8257 struct intel_shared_dpll
*pll
;
8258 const struct intel_limit
*limit
;
8259 int refclk
= 120000;
8261 memset(&crtc_state
->dpll_hw_state
, 0,
8262 sizeof(crtc_state
->dpll_hw_state
));
8264 crtc
->lowfreq_avail
= false;
8266 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8267 if (!crtc_state
->has_pch_encoder
)
8270 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8271 if (intel_panel_use_ssc(dev_priv
)) {
8272 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8273 dev_priv
->vbt
.lvds_ssc_freq
);
8274 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8277 if (intel_is_dual_link_lvds(dev
)) {
8278 if (refclk
== 100000)
8279 limit
= &intel_limits_ironlake_dual_lvds_100m
;
8281 limit
= &intel_limits_ironlake_dual_lvds
;
8283 if (refclk
== 100000)
8284 limit
= &intel_limits_ironlake_single_lvds_100m
;
8286 limit
= &intel_limits_ironlake_single_lvds
;
8289 limit
= &intel_limits_ironlake_dac
;
8292 if (!crtc_state
->clock_set
&&
8293 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8294 refclk
, NULL
, &crtc_state
->dpll
)) {
8295 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8299 ironlake_compute_dpll(crtc
, crtc_state
,
8300 has_reduced_clock
? &reduced_clock
: NULL
);
8302 pll
= intel_get_shared_dpll(crtc
, crtc_state
, NULL
);
8304 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8305 pipe_name(crtc
->pipe
));
8309 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
8311 crtc
->lowfreq_avail
= true;
8316 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
8317 struct intel_link_m_n
*m_n
)
8319 struct drm_device
*dev
= crtc
->base
.dev
;
8320 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8321 enum pipe pipe
= crtc
->pipe
;
8323 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
8324 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
8325 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
8327 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
8328 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
8329 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8332 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
8333 enum transcoder transcoder
,
8334 struct intel_link_m_n
*m_n
,
8335 struct intel_link_m_n
*m2_n2
)
8337 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
8338 enum pipe pipe
= crtc
->pipe
;
8340 if (INTEL_GEN(dev_priv
) >= 5) {
8341 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
8342 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
8343 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
8345 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
8346 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
8347 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8348 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8349 * gen < 8) and if DRRS is supported (to make sure the
8350 * registers are not unnecessarily read).
8352 if (m2_n2
&& INTEL_GEN(dev_priv
) < 8 &&
8353 crtc
->config
->has_drrs
) {
8354 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
8355 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
8356 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
8358 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
8359 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
8360 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8363 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
8364 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
8365 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
8367 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
8368 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
8369 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8373 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
8374 struct intel_crtc_state
*pipe_config
)
8376 if (pipe_config
->has_pch_encoder
)
8377 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
8379 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8380 &pipe_config
->dp_m_n
,
8381 &pipe_config
->dp_m2_n2
);
8384 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
8385 struct intel_crtc_state
*pipe_config
)
8387 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8388 &pipe_config
->fdi_m_n
, NULL
);
8391 static void skylake_get_pfit_config(struct intel_crtc
*crtc
,
8392 struct intel_crtc_state
*pipe_config
)
8394 struct drm_device
*dev
= crtc
->base
.dev
;
8395 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8396 struct intel_crtc_scaler_state
*scaler_state
= &pipe_config
->scaler_state
;
8397 uint32_t ps_ctrl
= 0;
8401 /* find scaler attached to this pipe */
8402 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
8403 ps_ctrl
= I915_READ(SKL_PS_CTRL(crtc
->pipe
, i
));
8404 if (ps_ctrl
& PS_SCALER_EN
&& !(ps_ctrl
& PS_PLANE_SEL_MASK
)) {
8406 pipe_config
->pch_pfit
.enabled
= true;
8407 pipe_config
->pch_pfit
.pos
= I915_READ(SKL_PS_WIN_POS(crtc
->pipe
, i
));
8408 pipe_config
->pch_pfit
.size
= I915_READ(SKL_PS_WIN_SZ(crtc
->pipe
, i
));
8413 scaler_state
->scaler_id
= id
;
8415 scaler_state
->scaler_users
|= (1 << SKL_CRTC_INDEX
);
8417 scaler_state
->scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
8422 skylake_get_initial_plane_config(struct intel_crtc
*crtc
,
8423 struct intel_initial_plane_config
*plane_config
)
8425 struct drm_device
*dev
= crtc
->base
.dev
;
8426 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8427 u32 val
, base
, offset
, stride_mult
, tiling
;
8428 int pipe
= crtc
->pipe
;
8429 int fourcc
, pixel_format
;
8430 unsigned int aligned_height
;
8431 struct drm_framebuffer
*fb
;
8432 struct intel_framebuffer
*intel_fb
;
8434 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8436 DRM_DEBUG_KMS("failed to alloc fb\n");
8440 fb
= &intel_fb
->base
;
8444 val
= I915_READ(PLANE_CTL(pipe
, 0));
8445 if (!(val
& PLANE_CTL_ENABLE
))
8448 pixel_format
= val
& PLANE_CTL_FORMAT_MASK
;
8449 fourcc
= skl_format_to_fourcc(pixel_format
,
8450 val
& PLANE_CTL_ORDER_RGBX
,
8451 val
& PLANE_CTL_ALPHA_MASK
);
8452 fb
->format
= drm_format_info(fourcc
);
8454 tiling
= val
& PLANE_CTL_TILED_MASK
;
8456 case PLANE_CTL_TILED_LINEAR
:
8457 fb
->modifier
= DRM_FORMAT_MOD_NONE
;
8459 case PLANE_CTL_TILED_X
:
8460 plane_config
->tiling
= I915_TILING_X
;
8461 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
8463 case PLANE_CTL_TILED_Y
:
8464 fb
->modifier
= I915_FORMAT_MOD_Y_TILED
;
8466 case PLANE_CTL_TILED_YF
:
8467 fb
->modifier
= I915_FORMAT_MOD_Yf_TILED
;
8470 MISSING_CASE(tiling
);
8474 base
= I915_READ(PLANE_SURF(pipe
, 0)) & 0xfffff000;
8475 plane_config
->base
= base
;
8477 offset
= I915_READ(PLANE_OFFSET(pipe
, 0));
8479 val
= I915_READ(PLANE_SIZE(pipe
, 0));
8480 fb
->height
= ((val
>> 16) & 0xfff) + 1;
8481 fb
->width
= ((val
>> 0) & 0x1fff) + 1;
8483 val
= I915_READ(PLANE_STRIDE(pipe
, 0));
8484 stride_mult
= intel_fb_stride_alignment(fb
, 0);
8485 fb
->pitches
[0] = (val
& 0x3ff) * stride_mult
;
8487 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
8489 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8491 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8492 pipe_name(pipe
), fb
->width
, fb
->height
,
8493 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
8494 plane_config
->size
);
8496 plane_config
->fb
= intel_fb
;
8503 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
8504 struct intel_crtc_state
*pipe_config
)
8506 struct drm_device
*dev
= crtc
->base
.dev
;
8507 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8510 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
8512 if (tmp
& PF_ENABLE
) {
8513 pipe_config
->pch_pfit
.enabled
= true;
8514 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
8515 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
8517 /* We currently do not free assignements of panel fitters on
8518 * ivb/hsw (since we don't use the higher upscaling modes which
8519 * differentiates them) so just WARN about this case for now. */
8520 if (IS_GEN7(dev_priv
)) {
8521 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
8522 PF_PIPE_SEL_IVB(crtc
->pipe
));
8528 ironlake_get_initial_plane_config(struct intel_crtc
*crtc
,
8529 struct intel_initial_plane_config
*plane_config
)
8531 struct drm_device
*dev
= crtc
->base
.dev
;
8532 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8533 u32 val
, base
, offset
;
8534 int pipe
= crtc
->pipe
;
8535 int fourcc
, pixel_format
;
8536 unsigned int aligned_height
;
8537 struct drm_framebuffer
*fb
;
8538 struct intel_framebuffer
*intel_fb
;
8540 val
= I915_READ(DSPCNTR(pipe
));
8541 if (!(val
& DISPLAY_PLANE_ENABLE
))
8544 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8546 DRM_DEBUG_KMS("failed to alloc fb\n");
8550 fb
= &intel_fb
->base
;
8554 if (INTEL_GEN(dev_priv
) >= 4) {
8555 if (val
& DISPPLANE_TILED
) {
8556 plane_config
->tiling
= I915_TILING_X
;
8557 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
8561 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
8562 fourcc
= i9xx_format_to_fourcc(pixel_format
);
8563 fb
->format
= drm_format_info(fourcc
);
8565 base
= I915_READ(DSPSURF(pipe
)) & 0xfffff000;
8566 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
8567 offset
= I915_READ(DSPOFFSET(pipe
));
8569 if (plane_config
->tiling
)
8570 offset
= I915_READ(DSPTILEOFF(pipe
));
8572 offset
= I915_READ(DSPLINOFF(pipe
));
8574 plane_config
->base
= base
;
8576 val
= I915_READ(PIPESRC(pipe
));
8577 fb
->width
= ((val
>> 16) & 0xfff) + 1;
8578 fb
->height
= ((val
>> 0) & 0xfff) + 1;
8580 val
= I915_READ(DSPSTRIDE(pipe
));
8581 fb
->pitches
[0] = val
& 0xffffffc0;
8583 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
8585 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8587 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8588 pipe_name(pipe
), fb
->width
, fb
->height
,
8589 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
8590 plane_config
->size
);
8592 plane_config
->fb
= intel_fb
;
8595 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
8596 struct intel_crtc_state
*pipe_config
)
8598 struct drm_device
*dev
= crtc
->base
.dev
;
8599 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8600 enum intel_display_power_domain power_domain
;
8604 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
8605 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8608 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8609 pipe_config
->shared_dpll
= NULL
;
8612 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
8613 if (!(tmp
& PIPECONF_ENABLE
))
8616 switch (tmp
& PIPECONF_BPC_MASK
) {
8618 pipe_config
->pipe_bpp
= 18;
8621 pipe_config
->pipe_bpp
= 24;
8623 case PIPECONF_10BPC
:
8624 pipe_config
->pipe_bpp
= 30;
8626 case PIPECONF_12BPC
:
8627 pipe_config
->pipe_bpp
= 36;
8633 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
8634 pipe_config
->limited_color_range
= true;
8636 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
8637 struct intel_shared_dpll
*pll
;
8638 enum intel_dpll_id pll_id
;
8640 pipe_config
->has_pch_encoder
= true;
8642 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
8643 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
8644 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
8646 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
8648 if (HAS_PCH_IBX(dev_priv
)) {
8650 * The pipe->pch transcoder and pch transcoder->pll
8653 pll_id
= (enum intel_dpll_id
) crtc
->pipe
;
8655 tmp
= I915_READ(PCH_DPLL_SEL
);
8656 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
8657 pll_id
= DPLL_ID_PCH_PLL_B
;
8659 pll_id
= DPLL_ID_PCH_PLL_A
;
8662 pipe_config
->shared_dpll
=
8663 intel_get_shared_dpll_by_id(dev_priv
, pll_id
);
8664 pll
= pipe_config
->shared_dpll
;
8666 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
8667 &pipe_config
->dpll_hw_state
));
8669 tmp
= pipe_config
->dpll_hw_state
.dpll
;
8670 pipe_config
->pixel_multiplier
=
8671 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
8672 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
8674 ironlake_pch_clock_get(crtc
, pipe_config
);
8676 pipe_config
->pixel_multiplier
= 1;
8679 intel_get_pipe_timings(crtc
, pipe_config
);
8680 intel_get_pipe_src_size(crtc
, pipe_config
);
8682 ironlake_get_pfit_config(crtc
, pipe_config
);
8687 intel_display_power_put(dev_priv
, power_domain
);
8692 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
8694 struct drm_device
*dev
= &dev_priv
->drm
;
8695 struct intel_crtc
*crtc
;
8697 for_each_intel_crtc(dev
, crtc
)
8698 I915_STATE_WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
8699 pipe_name(crtc
->pipe
));
8701 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
8702 I915_STATE_WARN(I915_READ(SPLL_CTL
) & SPLL_PLL_ENABLE
, "SPLL enabled\n");
8703 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE
, "WRPLL1 enabled\n");
8704 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE
, "WRPLL2 enabled\n");
8705 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON
, "Panel power on\n");
8706 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
8707 "CPU PWM1 enabled\n");
8708 if (IS_HASWELL(dev_priv
))
8709 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
8710 "CPU PWM2 enabled\n");
8711 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
8712 "PCH PWM1 enabled\n");
8713 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
8714 "Utility pin enabled\n");
8715 I915_STATE_WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
8718 * In theory we can still leave IRQs enabled, as long as only the HPD
8719 * interrupts remain enabled. We used to check for that, but since it's
8720 * gen-specific and since we only disable LCPLL after we fully disable
8721 * the interrupts, the check below should be enough.
8723 I915_STATE_WARN(intel_irqs_enabled(dev_priv
), "IRQs enabled\n");
8726 static uint32_t hsw_read_dcomp(struct drm_i915_private
*dev_priv
)
8728 if (IS_HASWELL(dev_priv
))
8729 return I915_READ(D_COMP_HSW
);
8731 return I915_READ(D_COMP_BDW
);
8734 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
8736 if (IS_HASWELL(dev_priv
)) {
8737 mutex_lock(&dev_priv
->rps
.hw_lock
);
8738 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
8740 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
8741 mutex_unlock(&dev_priv
->rps
.hw_lock
);
8743 I915_WRITE(D_COMP_BDW
, val
);
8744 POSTING_READ(D_COMP_BDW
);
8749 * This function implements pieces of two sequences from BSpec:
8750 * - Sequence for display software to disable LCPLL
8751 * - Sequence for display software to allow package C8+
8752 * The steps implemented here are just the steps that actually touch the LCPLL
8753 * register. Callers should take care of disabling all the display engine
8754 * functions, doing the mode unset, fixing interrupts, etc.
8756 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
8757 bool switch_to_fclk
, bool allow_power_down
)
8761 assert_can_disable_lcpll(dev_priv
);
8763 val
= I915_READ(LCPLL_CTL
);
8765 if (switch_to_fclk
) {
8766 val
|= LCPLL_CD_SOURCE_FCLK
;
8767 I915_WRITE(LCPLL_CTL
, val
);
8769 if (wait_for_us(I915_READ(LCPLL_CTL
) &
8770 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
8771 DRM_ERROR("Switching to FCLK failed\n");
8773 val
= I915_READ(LCPLL_CTL
);
8776 val
|= LCPLL_PLL_DISABLE
;
8777 I915_WRITE(LCPLL_CTL
, val
);
8778 POSTING_READ(LCPLL_CTL
);
8780 if (intel_wait_for_register(dev_priv
, LCPLL_CTL
, LCPLL_PLL_LOCK
, 0, 1))
8781 DRM_ERROR("LCPLL still locked\n");
8783 val
= hsw_read_dcomp(dev_priv
);
8784 val
|= D_COMP_COMP_DISABLE
;
8785 hsw_write_dcomp(dev_priv
, val
);
8788 if (wait_for((hsw_read_dcomp(dev_priv
) & D_COMP_RCOMP_IN_PROGRESS
) == 0,
8790 DRM_ERROR("D_COMP RCOMP still in progress\n");
8792 if (allow_power_down
) {
8793 val
= I915_READ(LCPLL_CTL
);
8794 val
|= LCPLL_POWER_DOWN_ALLOW
;
8795 I915_WRITE(LCPLL_CTL
, val
);
8796 POSTING_READ(LCPLL_CTL
);
8801 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
8804 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
8808 val
= I915_READ(LCPLL_CTL
);
8810 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
8811 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
8815 * Make sure we're not on PC8 state before disabling PC8, otherwise
8816 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
8818 intel_uncore_forcewake_get(dev_priv
, FORCEWAKE_ALL
);
8820 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
8821 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
8822 I915_WRITE(LCPLL_CTL
, val
);
8823 POSTING_READ(LCPLL_CTL
);
8826 val
= hsw_read_dcomp(dev_priv
);
8827 val
|= D_COMP_COMP_FORCE
;
8828 val
&= ~D_COMP_COMP_DISABLE
;
8829 hsw_write_dcomp(dev_priv
, val
);
8831 val
= I915_READ(LCPLL_CTL
);
8832 val
&= ~LCPLL_PLL_DISABLE
;
8833 I915_WRITE(LCPLL_CTL
, val
);
8835 if (intel_wait_for_register(dev_priv
,
8836 LCPLL_CTL
, LCPLL_PLL_LOCK
, LCPLL_PLL_LOCK
,
8838 DRM_ERROR("LCPLL not locked yet\n");
8840 if (val
& LCPLL_CD_SOURCE_FCLK
) {
8841 val
= I915_READ(LCPLL_CTL
);
8842 val
&= ~LCPLL_CD_SOURCE_FCLK
;
8843 I915_WRITE(LCPLL_CTL
, val
);
8845 if (wait_for_us((I915_READ(LCPLL_CTL
) &
8846 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
8847 DRM_ERROR("Switching back to LCPLL failed\n");
8850 intel_uncore_forcewake_put(dev_priv
, FORCEWAKE_ALL
);
8851 intel_update_cdclk(dev_priv
);
8855 * Package states C8 and deeper are really deep PC states that can only be
8856 * reached when all the devices on the system allow it, so even if the graphics
8857 * device allows PC8+, it doesn't mean the system will actually get to these
8858 * states. Our driver only allows PC8+ when going into runtime PM.
8860 * The requirements for PC8+ are that all the outputs are disabled, the power
8861 * well is disabled and most interrupts are disabled, and these are also
8862 * requirements for runtime PM. When these conditions are met, we manually do
8863 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
8864 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
8867 * When we really reach PC8 or deeper states (not just when we allow it) we lose
8868 * the state of some registers, so when we come back from PC8+ we need to
8869 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
8870 * need to take care of the registers kept by RC6. Notice that this happens even
8871 * if we don't put the device in PCI D3 state (which is what currently happens
8872 * because of the runtime PM support).
8874 * For more, read "Display Sequences for Package C8" on the hardware
8877 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
8881 DRM_DEBUG_KMS("Enabling package C8+\n");
8883 if (HAS_PCH_LPT_LP(dev_priv
)) {
8884 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
8885 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
8886 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
8889 lpt_disable_clkout_dp(dev_priv
);
8890 hsw_disable_lcpll(dev_priv
, true, true);
8893 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
8897 DRM_DEBUG_KMS("Disabling package C8+\n");
8899 hsw_restore_lcpll(dev_priv
);
8900 lpt_init_pch_refclk(dev_priv
);
8902 if (HAS_PCH_LPT_LP(dev_priv
)) {
8903 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
8904 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
8905 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
8909 static int haswell_crtc_compute_clock(struct intel_crtc
*crtc
,
8910 struct intel_crtc_state
*crtc_state
)
8912 if (!intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DSI
)) {
8913 if (!intel_ddi_pll_select(crtc
, crtc_state
))
8917 crtc
->lowfreq_avail
= false;
8922 static void bxt_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8924 struct intel_crtc_state
*pipe_config
)
8926 enum intel_dpll_id id
;
8930 id
= DPLL_ID_SKL_DPLL0
;
8933 id
= DPLL_ID_SKL_DPLL1
;
8936 id
= DPLL_ID_SKL_DPLL2
;
8939 DRM_ERROR("Incorrect port type\n");
8943 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8946 static void skylake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8948 struct intel_crtc_state
*pipe_config
)
8950 enum intel_dpll_id id
;
8953 temp
= I915_READ(DPLL_CTRL2
) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port
);
8954 id
= temp
>> (port
* 3 + 1);
8956 if (WARN_ON(id
< SKL_DPLL0
|| id
> SKL_DPLL3
))
8959 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8962 static void haswell_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8964 struct intel_crtc_state
*pipe_config
)
8966 enum intel_dpll_id id
;
8967 uint32_t ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
8969 switch (ddi_pll_sel
) {
8970 case PORT_CLK_SEL_WRPLL1
:
8971 id
= DPLL_ID_WRPLL1
;
8973 case PORT_CLK_SEL_WRPLL2
:
8974 id
= DPLL_ID_WRPLL2
;
8976 case PORT_CLK_SEL_SPLL
:
8979 case PORT_CLK_SEL_LCPLL_810
:
8980 id
= DPLL_ID_LCPLL_810
;
8982 case PORT_CLK_SEL_LCPLL_1350
:
8983 id
= DPLL_ID_LCPLL_1350
;
8985 case PORT_CLK_SEL_LCPLL_2700
:
8986 id
= DPLL_ID_LCPLL_2700
;
8989 MISSING_CASE(ddi_pll_sel
);
8991 case PORT_CLK_SEL_NONE
:
8995 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8998 static bool hsw_get_transcoder_state(struct intel_crtc
*crtc
,
8999 struct intel_crtc_state
*pipe_config
,
9000 u64
*power_domain_mask
)
9002 struct drm_device
*dev
= crtc
->base
.dev
;
9003 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9004 enum intel_display_power_domain power_domain
;
9008 * The pipe->transcoder mapping is fixed with the exception of the eDP
9009 * transcoder handled below.
9011 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
9014 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9015 * consistency and less surprising code; it's in always on power).
9017 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
9018 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
9019 enum pipe trans_edp_pipe
;
9020 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
9022 WARN(1, "unknown pipe linked to edp transcoder\n");
9023 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
9024 case TRANS_DDI_EDP_INPUT_A_ON
:
9025 trans_edp_pipe
= PIPE_A
;
9027 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
9028 trans_edp_pipe
= PIPE_B
;
9030 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
9031 trans_edp_pipe
= PIPE_C
;
9035 if (trans_edp_pipe
== crtc
->pipe
)
9036 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
9039 power_domain
= POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
);
9040 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9042 *power_domain_mask
|= BIT_ULL(power_domain
);
9044 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
9046 return tmp
& PIPECONF_ENABLE
;
9049 static bool bxt_get_dsi_transcoder_state(struct intel_crtc
*crtc
,
9050 struct intel_crtc_state
*pipe_config
,
9051 u64
*power_domain_mask
)
9053 struct drm_device
*dev
= crtc
->base
.dev
;
9054 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9055 enum intel_display_power_domain power_domain
;
9057 enum transcoder cpu_transcoder
;
9060 for_each_port_masked(port
, BIT(PORT_A
) | BIT(PORT_C
)) {
9062 cpu_transcoder
= TRANSCODER_DSI_A
;
9064 cpu_transcoder
= TRANSCODER_DSI_C
;
9066 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
9067 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9069 *power_domain_mask
|= BIT_ULL(power_domain
);
9072 * The PLL needs to be enabled with a valid divider
9073 * configuration, otherwise accessing DSI registers will hang
9074 * the machine. See BSpec North Display Engine
9075 * registers/MIPI[BXT]. We can break out here early, since we
9076 * need the same DSI PLL to be enabled for both DSI ports.
9078 if (!intel_dsi_pll_is_enabled(dev_priv
))
9081 /* XXX: this works for video mode only */
9082 tmp
= I915_READ(BXT_MIPI_PORT_CTRL(port
));
9083 if (!(tmp
& DPI_ENABLE
))
9086 tmp
= I915_READ(MIPI_CTRL(port
));
9087 if ((tmp
& BXT_PIPE_SELECT_MASK
) != BXT_PIPE_SELECT(crtc
->pipe
))
9090 pipe_config
->cpu_transcoder
= cpu_transcoder
;
9094 return transcoder_is_dsi(pipe_config
->cpu_transcoder
);
9097 static void haswell_get_ddi_port_state(struct intel_crtc
*crtc
,
9098 struct intel_crtc_state
*pipe_config
)
9100 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9101 struct intel_shared_dpll
*pll
;
9105 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
9107 port
= (tmp
& TRANS_DDI_PORT_MASK
) >> TRANS_DDI_PORT_SHIFT
;
9109 if (IS_GEN9_BC(dev_priv
))
9110 skylake_get_ddi_pll(dev_priv
, port
, pipe_config
);
9111 else if (IS_GEN9_LP(dev_priv
))
9112 bxt_get_ddi_pll(dev_priv
, port
, pipe_config
);
9114 haswell_get_ddi_pll(dev_priv
, port
, pipe_config
);
9116 pll
= pipe_config
->shared_dpll
;
9118 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
9119 &pipe_config
->dpll_hw_state
));
9123 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9124 * DDI E. So just check whether this pipe is wired to DDI E and whether
9125 * the PCH transcoder is on.
9127 if (INTEL_GEN(dev_priv
) < 9 &&
9128 (port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
9129 pipe_config
->has_pch_encoder
= true;
9131 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
9132 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
9133 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
9135 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
9139 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
9140 struct intel_crtc_state
*pipe_config
)
9142 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9143 enum intel_display_power_domain power_domain
;
9144 u64 power_domain_mask
;
9147 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
9148 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9150 power_domain_mask
= BIT_ULL(power_domain
);
9152 pipe_config
->shared_dpll
= NULL
;
9154 active
= hsw_get_transcoder_state(crtc
, pipe_config
, &power_domain_mask
);
9156 if (IS_GEN9_LP(dev_priv
) &&
9157 bxt_get_dsi_transcoder_state(crtc
, pipe_config
, &power_domain_mask
)) {
9165 if (!transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
9166 haswell_get_ddi_port_state(crtc
, pipe_config
);
9167 intel_get_pipe_timings(crtc
, pipe_config
);
9170 intel_get_pipe_src_size(crtc
, pipe_config
);
9172 pipe_config
->gamma_mode
=
9173 I915_READ(GAMMA_MODE(crtc
->pipe
)) & GAMMA_MODE_MODE_MASK
;
9175 if (INTEL_GEN(dev_priv
) >= 9) {
9176 intel_crtc_init_scalers(crtc
, pipe_config
);
9178 pipe_config
->scaler_state
.scaler_id
= -1;
9179 pipe_config
->scaler_state
.scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
9182 power_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
9183 if (intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
9184 power_domain_mask
|= BIT_ULL(power_domain
);
9185 if (INTEL_GEN(dev_priv
) >= 9)
9186 skylake_get_pfit_config(crtc
, pipe_config
);
9188 ironlake_get_pfit_config(crtc
, pipe_config
);
9191 if (IS_HASWELL(dev_priv
))
9192 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
9193 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
9195 if (pipe_config
->cpu_transcoder
!= TRANSCODER_EDP
&&
9196 !transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
9197 pipe_config
->pixel_multiplier
=
9198 I915_READ(PIPE_MULT(pipe_config
->cpu_transcoder
)) + 1;
9200 pipe_config
->pixel_multiplier
= 1;
9204 for_each_power_domain(power_domain
, power_domain_mask
)
9205 intel_display_power_put(dev_priv
, power_domain
);
9210 static u32
i845_cursor_ctl(const struct intel_crtc_state
*crtc_state
,
9211 const struct intel_plane_state
*plane_state
)
9213 unsigned int width
= plane_state
->base
.crtc_w
;
9214 unsigned int stride
= roundup_pow_of_two(width
) * 4;
9218 WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
9229 return CURSOR_ENABLE
|
9230 CURSOR_GAMMA_ENABLE
|
9231 CURSOR_FORMAT_ARGB
|
9232 CURSOR_STRIDE(stride
);
9235 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
,
9236 const struct intel_crtc_state
*crtc_state
,
9237 const struct intel_plane_state
*plane_state
)
9239 struct drm_device
*dev
= crtc
->dev
;
9240 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9241 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9242 uint32_t cntl
= 0, size
= 0;
9244 if (plane_state
&& plane_state
->base
.visible
) {
9245 unsigned int width
= plane_state
->base
.crtc_w
;
9246 unsigned int height
= plane_state
->base
.crtc_h
;
9248 cntl
= i845_cursor_ctl(crtc_state
, plane_state
);
9249 size
= (height
<< 12) | width
;
9252 if (intel_crtc
->cursor_cntl
!= 0 &&
9253 (intel_crtc
->cursor_base
!= base
||
9254 intel_crtc
->cursor_size
!= size
||
9255 intel_crtc
->cursor_cntl
!= cntl
)) {
9256 /* On these chipsets we can only modify the base/size/stride
9257 * whilst the cursor is disabled.
9259 I915_WRITE_FW(CURCNTR(PIPE_A
), 0);
9260 POSTING_READ_FW(CURCNTR(PIPE_A
));
9261 intel_crtc
->cursor_cntl
= 0;
9264 if (intel_crtc
->cursor_base
!= base
) {
9265 I915_WRITE_FW(CURBASE(PIPE_A
), base
);
9266 intel_crtc
->cursor_base
= base
;
9269 if (intel_crtc
->cursor_size
!= size
) {
9270 I915_WRITE_FW(CURSIZE
, size
);
9271 intel_crtc
->cursor_size
= size
;
9274 if (intel_crtc
->cursor_cntl
!= cntl
) {
9275 I915_WRITE_FW(CURCNTR(PIPE_A
), cntl
);
9276 POSTING_READ_FW(CURCNTR(PIPE_A
));
9277 intel_crtc
->cursor_cntl
= cntl
;
9281 static u32
i9xx_cursor_ctl(const struct intel_crtc_state
*crtc_state
,
9282 const struct intel_plane_state
*plane_state
)
9284 struct drm_i915_private
*dev_priv
=
9285 to_i915(plane_state
->base
.plane
->dev
);
9286 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
9287 enum pipe pipe
= crtc
->pipe
;
9290 cntl
= MCURSOR_GAMMA_ENABLE
;
9292 if (HAS_DDI(dev_priv
))
9293 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
9295 cntl
|= pipe
<< 28; /* Connect to correct pipe */
9297 switch (plane_state
->base
.crtc_w
) {
9299 cntl
|= CURSOR_MODE_64_ARGB_AX
;
9302 cntl
|= CURSOR_MODE_128_ARGB_AX
;
9305 cntl
|= CURSOR_MODE_256_ARGB_AX
;
9308 MISSING_CASE(plane_state
->base
.crtc_w
);
9312 if (plane_state
->base
.rotation
& DRM_ROTATE_180
)
9313 cntl
|= CURSOR_ROTATE_180
;
9318 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
,
9319 const struct intel_crtc_state
*crtc_state
,
9320 const struct intel_plane_state
*plane_state
)
9322 struct drm_device
*dev
= crtc
->dev
;
9323 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9324 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9325 int pipe
= intel_crtc
->pipe
;
9328 if (plane_state
&& plane_state
->base
.visible
)
9329 cntl
= i9xx_cursor_ctl(crtc_state
, plane_state
);
9331 if (intel_crtc
->cursor_cntl
!= cntl
) {
9332 I915_WRITE_FW(CURCNTR(pipe
), cntl
);
9333 POSTING_READ_FW(CURCNTR(pipe
));
9334 intel_crtc
->cursor_cntl
= cntl
;
9337 /* and commit changes on next vblank */
9338 I915_WRITE_FW(CURBASE(pipe
), base
);
9339 POSTING_READ_FW(CURBASE(pipe
));
9341 intel_crtc
->cursor_base
= base
;
9344 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
9345 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
9346 const struct intel_crtc_state
*crtc_state
,
9347 const struct intel_plane_state
*plane_state
)
9349 struct drm_device
*dev
= crtc
->dev
;
9350 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9351 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9352 int pipe
= intel_crtc
->pipe
;
9353 u32 base
= intel_crtc
->cursor_addr
;
9354 unsigned long irqflags
;
9358 int x
= plane_state
->base
.crtc_x
;
9359 int y
= plane_state
->base
.crtc_y
;
9362 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
9365 pos
|= x
<< CURSOR_X_SHIFT
;
9368 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
9371 pos
|= y
<< CURSOR_Y_SHIFT
;
9373 /* ILK+ do this automagically */
9374 if (HAS_GMCH_DISPLAY(dev_priv
) &&
9375 plane_state
->base
.rotation
& DRM_ROTATE_180
) {
9376 base
+= (plane_state
->base
.crtc_h
*
9377 plane_state
->base
.crtc_w
- 1) * 4;
9381 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
9383 I915_WRITE_FW(CURPOS(pipe
), pos
);
9385 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
))
9386 i845_update_cursor(crtc
, base
, crtc_state
, plane_state
);
9388 i9xx_update_cursor(crtc
, base
, crtc_state
, plane_state
);
9390 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
9393 static bool cursor_size_ok(struct drm_i915_private
*dev_priv
,
9394 uint32_t width
, uint32_t height
)
9396 if (width
== 0 || height
== 0)
9400 * 845g/865g are special in that they are only limited by
9401 * the width of their cursors, the height is arbitrary up to
9402 * the precision of the register. Everything else requires
9403 * square cursors, limited to a few power-of-two sizes.
9405 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
)) {
9406 if ((width
& 63) != 0)
9409 if (width
> (IS_I845G(dev_priv
) ? 64 : 512))
9415 switch (width
| height
) {
9418 if (IS_GEN2(dev_priv
))
9430 /* VESA 640x480x72Hz mode to set on the pipe */
9431 static struct drm_display_mode load_detect_mode
= {
9432 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
9433 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
9436 struct drm_framebuffer
*
9437 intel_framebuffer_create(struct drm_i915_gem_object
*obj
,
9438 struct drm_mode_fb_cmd2
*mode_cmd
)
9440 struct intel_framebuffer
*intel_fb
;
9443 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9445 return ERR_PTR(-ENOMEM
);
9447 ret
= intel_framebuffer_init(intel_fb
, obj
, mode_cmd
);
9451 return &intel_fb
->base
;
9455 return ERR_PTR(ret
);
9459 intel_framebuffer_pitch_for_width(int width
, int bpp
)
9461 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
9462 return ALIGN(pitch
, 64);
9466 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
9468 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
9469 return PAGE_ALIGN(pitch
* mode
->vdisplay
);
9472 static struct drm_framebuffer
*
9473 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
9474 struct drm_display_mode
*mode
,
9477 struct drm_framebuffer
*fb
;
9478 struct drm_i915_gem_object
*obj
;
9479 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
9481 obj
= i915_gem_object_create(to_i915(dev
),
9482 intel_framebuffer_size_for_mode(mode
, bpp
));
9484 return ERR_CAST(obj
);
9486 mode_cmd
.width
= mode
->hdisplay
;
9487 mode_cmd
.height
= mode
->vdisplay
;
9488 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
9490 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
9492 fb
= intel_framebuffer_create(obj
, &mode_cmd
);
9494 i915_gem_object_put(obj
);
9499 static struct drm_framebuffer
*
9500 mode_fits_in_fbdev(struct drm_device
*dev
,
9501 struct drm_display_mode
*mode
)
9503 #ifdef CONFIG_DRM_FBDEV_EMULATION
9504 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9505 struct drm_i915_gem_object
*obj
;
9506 struct drm_framebuffer
*fb
;
9508 if (!dev_priv
->fbdev
)
9511 if (!dev_priv
->fbdev
->fb
)
9514 obj
= dev_priv
->fbdev
->fb
->obj
;
9517 fb
= &dev_priv
->fbdev
->fb
->base
;
9518 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
9519 fb
->format
->cpp
[0] * 8))
9522 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
9525 drm_framebuffer_reference(fb
);
9532 static int intel_modeset_setup_plane_state(struct drm_atomic_state
*state
,
9533 struct drm_crtc
*crtc
,
9534 struct drm_display_mode
*mode
,
9535 struct drm_framebuffer
*fb
,
9538 struct drm_plane_state
*plane_state
;
9539 int hdisplay
, vdisplay
;
9542 plane_state
= drm_atomic_get_plane_state(state
, crtc
->primary
);
9543 if (IS_ERR(plane_state
))
9544 return PTR_ERR(plane_state
);
9547 drm_mode_get_hv_timing(mode
, &hdisplay
, &vdisplay
);
9549 hdisplay
= vdisplay
= 0;
9551 ret
= drm_atomic_set_crtc_for_plane(plane_state
, fb
? crtc
: NULL
);
9554 drm_atomic_set_fb_for_plane(plane_state
, fb
);
9555 plane_state
->crtc_x
= 0;
9556 plane_state
->crtc_y
= 0;
9557 plane_state
->crtc_w
= hdisplay
;
9558 plane_state
->crtc_h
= vdisplay
;
9559 plane_state
->src_x
= x
<< 16;
9560 plane_state
->src_y
= y
<< 16;
9561 plane_state
->src_w
= hdisplay
<< 16;
9562 plane_state
->src_h
= vdisplay
<< 16;
9567 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
9568 struct drm_display_mode
*mode
,
9569 struct intel_load_detect_pipe
*old
,
9570 struct drm_modeset_acquire_ctx
*ctx
)
9572 struct intel_crtc
*intel_crtc
;
9573 struct intel_encoder
*intel_encoder
=
9574 intel_attached_encoder(connector
);
9575 struct drm_crtc
*possible_crtc
;
9576 struct drm_encoder
*encoder
= &intel_encoder
->base
;
9577 struct drm_crtc
*crtc
= NULL
;
9578 struct drm_device
*dev
= encoder
->dev
;
9579 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9580 struct drm_framebuffer
*fb
;
9581 struct drm_mode_config
*config
= &dev
->mode_config
;
9582 struct drm_atomic_state
*state
= NULL
, *restore_state
= NULL
;
9583 struct drm_connector_state
*connector_state
;
9584 struct intel_crtc_state
*crtc_state
;
9587 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9588 connector
->base
.id
, connector
->name
,
9589 encoder
->base
.id
, encoder
->name
);
9591 old
->restore_state
= NULL
;
9594 ret
= drm_modeset_lock(&config
->connection_mutex
, ctx
);
9599 * Algorithm gets a little messy:
9601 * - if the connector already has an assigned crtc, use it (but make
9602 * sure it's on first)
9604 * - try to find the first unused crtc that can drive this connector,
9605 * and use that if we find one
9608 /* See if we already have a CRTC for this connector */
9609 if (connector
->state
->crtc
) {
9610 crtc
= connector
->state
->crtc
;
9612 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
9616 /* Make sure the crtc and connector are running */
9620 /* Find an unused one (if possible) */
9621 for_each_crtc(dev
, possible_crtc
) {
9623 if (!(encoder
->possible_crtcs
& (1 << i
)))
9626 ret
= drm_modeset_lock(&possible_crtc
->mutex
, ctx
);
9630 if (possible_crtc
->state
->enable
) {
9631 drm_modeset_unlock(&possible_crtc
->mutex
);
9635 crtc
= possible_crtc
;
9640 * If we didn't find an unused CRTC, don't use any.
9643 DRM_DEBUG_KMS("no pipe available for load-detect\n");
9648 intel_crtc
= to_intel_crtc(crtc
);
9650 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
9654 state
= drm_atomic_state_alloc(dev
);
9655 restore_state
= drm_atomic_state_alloc(dev
);
9656 if (!state
|| !restore_state
) {
9661 state
->acquire_ctx
= ctx
;
9662 restore_state
->acquire_ctx
= ctx
;
9664 connector_state
= drm_atomic_get_connector_state(state
, connector
);
9665 if (IS_ERR(connector_state
)) {
9666 ret
= PTR_ERR(connector_state
);
9670 ret
= drm_atomic_set_crtc_for_connector(connector_state
, crtc
);
9674 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
9675 if (IS_ERR(crtc_state
)) {
9676 ret
= PTR_ERR(crtc_state
);
9680 crtc_state
->base
.active
= crtc_state
->base
.enable
= true;
9683 mode
= &load_detect_mode
;
9685 /* We need a framebuffer large enough to accommodate all accesses
9686 * that the plane may generate whilst we perform load detection.
9687 * We can not rely on the fbcon either being present (we get called
9688 * during its initialisation to detect all boot displays, or it may
9689 * not even exist) or that it is large enough to satisfy the
9692 fb
= mode_fits_in_fbdev(dev
, mode
);
9694 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
9695 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
9697 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
9699 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
9703 ret
= intel_modeset_setup_plane_state(state
, crtc
, mode
, fb
, 0, 0);
9707 drm_framebuffer_unreference(fb
);
9709 ret
= drm_atomic_set_mode_for_crtc(&crtc_state
->base
, mode
);
9713 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state
, connector
));
9715 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state
, crtc
));
9717 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state
, crtc
->primary
));
9719 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret
);
9723 ret
= drm_atomic_commit(state
);
9725 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
9729 old
->restore_state
= restore_state
;
9730 drm_atomic_state_put(state
);
9732 /* let the connector get through one full cycle before testing */
9733 intel_wait_for_vblank(dev_priv
, intel_crtc
->pipe
);
9738 drm_atomic_state_put(state
);
9741 if (restore_state
) {
9742 drm_atomic_state_put(restore_state
);
9743 restore_state
= NULL
;
9746 if (ret
== -EDEADLK
) {
9747 drm_modeset_backoff(ctx
);
9754 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
9755 struct intel_load_detect_pipe
*old
,
9756 struct drm_modeset_acquire_ctx
*ctx
)
9758 struct intel_encoder
*intel_encoder
=
9759 intel_attached_encoder(connector
);
9760 struct drm_encoder
*encoder
= &intel_encoder
->base
;
9761 struct drm_atomic_state
*state
= old
->restore_state
;
9764 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9765 connector
->base
.id
, connector
->name
,
9766 encoder
->base
.id
, encoder
->name
);
9771 ret
= drm_atomic_helper_commit_duplicated_state(state
, ctx
);
9773 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret
);
9774 drm_atomic_state_put(state
);
9777 static int i9xx_pll_refclk(struct drm_device
*dev
,
9778 const struct intel_crtc_state
*pipe_config
)
9780 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9781 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
9783 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
9784 return dev_priv
->vbt
.lvds_ssc_freq
;
9785 else if (HAS_PCH_SPLIT(dev_priv
))
9787 else if (!IS_GEN2(dev_priv
))
9793 /* Returns the clock of the currently programmed mode of the given pipe. */
9794 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
9795 struct intel_crtc_state
*pipe_config
)
9797 struct drm_device
*dev
= crtc
->base
.dev
;
9798 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9799 int pipe
= pipe_config
->cpu_transcoder
;
9800 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
9804 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
9806 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
9807 fp
= pipe_config
->dpll_hw_state
.fp0
;
9809 fp
= pipe_config
->dpll_hw_state
.fp1
;
9811 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
9812 if (IS_PINEVIEW(dev_priv
)) {
9813 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
9814 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
9816 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
9817 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
9820 if (!IS_GEN2(dev_priv
)) {
9821 if (IS_PINEVIEW(dev_priv
))
9822 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
9823 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
9825 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
9826 DPLL_FPA01_P1_POST_DIV_SHIFT
);
9828 switch (dpll
& DPLL_MODE_MASK
) {
9829 case DPLLB_MODE_DAC_SERIAL
:
9830 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
9833 case DPLLB_MODE_LVDS
:
9834 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
9838 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
9839 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
9843 if (IS_PINEVIEW(dev_priv
))
9844 port_clock
= pnv_calc_dpll_params(refclk
, &clock
);
9846 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
9848 u32 lvds
= IS_I830(dev_priv
) ? 0 : I915_READ(LVDS
);
9849 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
9852 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
9853 DPLL_FPA01_P1_POST_DIV_SHIFT
);
9855 if (lvds
& LVDS_CLKB_POWER_UP
)
9860 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
9863 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
9864 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
9866 if (dpll
& PLL_P2_DIVIDE_BY_4
)
9872 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
9876 * This value includes pixel_multiplier. We will use
9877 * port_clock to compute adjusted_mode.crtc_clock in the
9878 * encoder's get_config() function.
9880 pipe_config
->port_clock
= port_clock
;
9883 int intel_dotclock_calculate(int link_freq
,
9884 const struct intel_link_m_n
*m_n
)
9887 * The calculation for the data clock is:
9888 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
9889 * But we want to avoid losing precison if possible, so:
9890 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
9892 * and the link clock is simpler:
9893 * link_clock = (m * link_clock) / n
9899 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
9902 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
9903 struct intel_crtc_state
*pipe_config
)
9905 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9907 /* read out port_clock from the DPLL */
9908 i9xx_crtc_clock_get(crtc
, pipe_config
);
9911 * In case there is an active pipe without active ports,
9912 * we may need some idea for the dotclock anyway.
9913 * Calculate one based on the FDI configuration.
9915 pipe_config
->base
.adjusted_mode
.crtc_clock
=
9916 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
9917 &pipe_config
->fdi_m_n
);
9920 /** Returns the currently programmed mode of the given pipe. */
9921 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
9922 struct drm_crtc
*crtc
)
9924 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9925 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9926 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
9927 struct drm_display_mode
*mode
;
9928 struct intel_crtc_state
*pipe_config
;
9929 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
9930 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
9931 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
9932 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
9933 enum pipe pipe
= intel_crtc
->pipe
;
9935 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
9939 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
9946 * Construct a pipe_config sufficient for getting the clock info
9947 * back out of crtc_clock_get.
9949 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
9950 * to use a real value here instead.
9952 pipe_config
->cpu_transcoder
= (enum transcoder
) pipe
;
9953 pipe_config
->pixel_multiplier
= 1;
9954 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
9955 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
9956 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
9957 i9xx_crtc_clock_get(intel_crtc
, pipe_config
);
9959 mode
->clock
= pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
9960 mode
->hdisplay
= (htot
& 0xffff) + 1;
9961 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
9962 mode
->hsync_start
= (hsync
& 0xffff) + 1;
9963 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
9964 mode
->vdisplay
= (vtot
& 0xffff) + 1;
9965 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
9966 mode
->vsync_start
= (vsync
& 0xffff) + 1;
9967 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
9969 drm_mode_set_name(mode
);
9976 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
9978 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9979 struct drm_device
*dev
= crtc
->dev
;
9980 struct intel_flip_work
*work
;
9982 spin_lock_irq(&dev
->event_lock
);
9983 work
= intel_crtc
->flip_work
;
9984 intel_crtc
->flip_work
= NULL
;
9985 spin_unlock_irq(&dev
->event_lock
);
9988 cancel_work_sync(&work
->mmio_work
);
9989 cancel_work_sync(&work
->unpin_work
);
9993 drm_crtc_cleanup(crtc
);
9998 static void intel_unpin_work_fn(struct work_struct
*__work
)
10000 struct intel_flip_work
*work
=
10001 container_of(__work
, struct intel_flip_work
, unpin_work
);
10002 struct intel_crtc
*crtc
= to_intel_crtc(work
->crtc
);
10003 struct drm_device
*dev
= crtc
->base
.dev
;
10004 struct drm_plane
*primary
= crtc
->base
.primary
;
10006 if (is_mmio_work(work
))
10007 flush_work(&work
->mmio_work
);
10009 mutex_lock(&dev
->struct_mutex
);
10010 intel_unpin_fb_vma(work
->old_vma
);
10011 i915_gem_object_put(work
->pending_flip_obj
);
10012 mutex_unlock(&dev
->struct_mutex
);
10014 i915_gem_request_put(work
->flip_queued_req
);
10016 intel_frontbuffer_flip_complete(to_i915(dev
),
10017 to_intel_plane(primary
)->frontbuffer_bit
);
10018 intel_fbc_post_update(crtc
);
10019 drm_framebuffer_unreference(work
->old_fb
);
10021 BUG_ON(atomic_read(&crtc
->unpin_work_count
) == 0);
10022 atomic_dec(&crtc
->unpin_work_count
);
10027 /* Is 'a' after or equal to 'b'? */
10028 static bool g4x_flip_count_after_eq(u32 a
, u32 b
)
10030 return !((a
- b
) & 0x80000000);
10033 static bool __pageflip_finished_cs(struct intel_crtc
*crtc
,
10034 struct intel_flip_work
*work
)
10036 struct drm_device
*dev
= crtc
->base
.dev
;
10037 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10039 if (abort_flip_on_reset(crtc
))
10043 * The relevant registers doen't exist on pre-ctg.
10044 * As the flip done interrupt doesn't trigger for mmio
10045 * flips on gmch platforms, a flip count check isn't
10046 * really needed there. But since ctg has the registers,
10047 * include it in the check anyway.
10049 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
))
10053 * BDW signals flip done immediately if the plane
10054 * is disabled, even if the plane enable is already
10055 * armed to occur at the next vblank :(
10059 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
10060 * used the same base address. In that case the mmio flip might
10061 * have completed, but the CS hasn't even executed the flip yet.
10063 * A flip count check isn't enough as the CS might have updated
10064 * the base address just after start of vblank, but before we
10065 * managed to process the interrupt. This means we'd complete the
10066 * CS flip too soon.
10068 * Combining both checks should get us a good enough result. It may
10069 * still happen that the CS flip has been executed, but has not
10070 * yet actually completed. But in case the base address is the same
10071 * anyway, we don't really care.
10073 return (I915_READ(DSPSURFLIVE(crtc
->plane
)) & ~0xfff) ==
10074 crtc
->flip_work
->gtt_offset
&&
10075 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc
->pipe
)),
10076 crtc
->flip_work
->flip_count
);
10080 __pageflip_finished_mmio(struct intel_crtc
*crtc
,
10081 struct intel_flip_work
*work
)
10084 * MMIO work completes when vblank is different from
10085 * flip_queued_vblank.
10087 * Reset counter value doesn't matter, this is handled by
10088 * i915_wait_request finishing early, so no need to handle
10091 return intel_crtc_get_vblank_counter(crtc
) != work
->flip_queued_vblank
;
10095 static bool pageflip_finished(struct intel_crtc
*crtc
,
10096 struct intel_flip_work
*work
)
10098 if (!atomic_read(&work
->pending
))
10103 if (is_mmio_work(work
))
10104 return __pageflip_finished_mmio(crtc
, work
);
10106 return __pageflip_finished_cs(crtc
, work
);
10109 void intel_finish_page_flip_cs(struct drm_i915_private
*dev_priv
, int pipe
)
10111 struct drm_device
*dev
= &dev_priv
->drm
;
10112 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
10113 struct intel_flip_work
*work
;
10114 unsigned long flags
;
10116 /* Ignore early vblank irqs */
10121 * This is called both by irq handlers and the reset code (to complete
10122 * lost pageflips) so needs the full irqsave spinlocks.
10124 spin_lock_irqsave(&dev
->event_lock
, flags
);
10125 work
= crtc
->flip_work
;
10127 if (work
!= NULL
&&
10128 !is_mmio_work(work
) &&
10129 pageflip_finished(crtc
, work
))
10130 page_flip_completed(crtc
);
10132 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
10135 void intel_finish_page_flip_mmio(struct drm_i915_private
*dev_priv
, int pipe
)
10137 struct drm_device
*dev
= &dev_priv
->drm
;
10138 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
10139 struct intel_flip_work
*work
;
10140 unsigned long flags
;
10142 /* Ignore early vblank irqs */
10147 * This is called both by irq handlers and the reset code (to complete
10148 * lost pageflips) so needs the full irqsave spinlocks.
10150 spin_lock_irqsave(&dev
->event_lock
, flags
);
10151 work
= crtc
->flip_work
;
10153 if (work
!= NULL
&&
10154 is_mmio_work(work
) &&
10155 pageflip_finished(crtc
, work
))
10156 page_flip_completed(crtc
);
10158 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
10161 static inline void intel_mark_page_flip_active(struct intel_crtc
*crtc
,
10162 struct intel_flip_work
*work
)
10164 work
->flip_queued_vblank
= intel_crtc_get_vblank_counter(crtc
);
10166 /* Ensure that the work item is consistent when activating it ... */
10167 smp_mb__before_atomic();
10168 atomic_set(&work
->pending
, 1);
10171 static int intel_gen2_queue_flip(struct drm_device
*dev
,
10172 struct drm_crtc
*crtc
,
10173 struct drm_framebuffer
*fb
,
10174 struct drm_i915_gem_object
*obj
,
10175 struct drm_i915_gem_request
*req
,
10178 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10179 u32 flip_mask
, *cs
;
10181 cs
= intel_ring_begin(req
, 6);
10183 return PTR_ERR(cs
);
10185 /* Can't queue multiple flips, so wait for the previous
10186 * one to finish before executing the next.
10188 if (intel_crtc
->plane
)
10189 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
10191 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
10192 *cs
++ = MI_WAIT_FOR_EVENT
| flip_mask
;
10194 *cs
++ = MI_DISPLAY_FLIP
| MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
);
10195 *cs
++ = fb
->pitches
[0];
10196 *cs
++ = intel_crtc
->flip_work
->gtt_offset
;
10197 *cs
++ = 0; /* aux display base address, unused */
10202 static int intel_gen3_queue_flip(struct drm_device
*dev
,
10203 struct drm_crtc
*crtc
,
10204 struct drm_framebuffer
*fb
,
10205 struct drm_i915_gem_object
*obj
,
10206 struct drm_i915_gem_request
*req
,
10209 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10210 u32 flip_mask
, *cs
;
10212 cs
= intel_ring_begin(req
, 6);
10214 return PTR_ERR(cs
);
10216 if (intel_crtc
->plane
)
10217 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
10219 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
10220 *cs
++ = MI_WAIT_FOR_EVENT
| flip_mask
;
10222 *cs
++ = MI_DISPLAY_FLIP_I915
| MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
);
10223 *cs
++ = fb
->pitches
[0];
10224 *cs
++ = intel_crtc
->flip_work
->gtt_offset
;
10230 static int intel_gen4_queue_flip(struct drm_device
*dev
,
10231 struct drm_crtc
*crtc
,
10232 struct drm_framebuffer
*fb
,
10233 struct drm_i915_gem_object
*obj
,
10234 struct drm_i915_gem_request
*req
,
10237 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10238 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10239 u32 pf
, pipesrc
, *cs
;
10241 cs
= intel_ring_begin(req
, 4);
10243 return PTR_ERR(cs
);
10245 /* i965+ uses the linear or tiled offsets from the
10246 * Display Registers (which do not change across a page-flip)
10247 * so we need only reprogram the base address.
10249 *cs
++ = MI_DISPLAY_FLIP
| MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
);
10250 *cs
++ = fb
->pitches
[0];
10251 *cs
++ = intel_crtc
->flip_work
->gtt_offset
|
10252 intel_fb_modifier_to_tiling(fb
->modifier
);
10254 /* XXX Enabling the panel-fitter across page-flip is so far
10255 * untested on non-native modes, so ignore it for now.
10256 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
10259 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
10260 *cs
++ = pf
| pipesrc
;
10265 static int intel_gen6_queue_flip(struct drm_device
*dev
,
10266 struct drm_crtc
*crtc
,
10267 struct drm_framebuffer
*fb
,
10268 struct drm_i915_gem_object
*obj
,
10269 struct drm_i915_gem_request
*req
,
10272 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10273 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10274 u32 pf
, pipesrc
, *cs
;
10276 cs
= intel_ring_begin(req
, 4);
10278 return PTR_ERR(cs
);
10280 *cs
++ = MI_DISPLAY_FLIP
| MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
);
10281 *cs
++ = fb
->pitches
[0] | intel_fb_modifier_to_tiling(fb
->modifier
);
10282 *cs
++ = intel_crtc
->flip_work
->gtt_offset
;
10284 /* Contrary to the suggestions in the documentation,
10285 * "Enable Panel Fitter" does not seem to be required when page
10286 * flipping with a non-native mode, and worse causes a normal
10288 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
10291 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
10292 *cs
++ = pf
| pipesrc
;
10297 static int intel_gen7_queue_flip(struct drm_device
*dev
,
10298 struct drm_crtc
*crtc
,
10299 struct drm_framebuffer
*fb
,
10300 struct drm_i915_gem_object
*obj
,
10301 struct drm_i915_gem_request
*req
,
10304 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10305 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10306 u32
*cs
, plane_bit
= 0;
10309 switch (intel_crtc
->plane
) {
10311 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
10314 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
10317 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
10320 WARN_ONCE(1, "unknown plane in flip command\n");
10325 if (req
->engine
->id
== RCS
) {
10328 * On Gen 8, SRM is now taking an extra dword to accommodate
10329 * 48bits addresses, and we need a NOOP for the batch size to
10332 if (IS_GEN8(dev_priv
))
10337 * BSpec MI_DISPLAY_FLIP for IVB:
10338 * "The full packet must be contained within the same cache line."
10340 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
10341 * cacheline, if we ever start emitting more commands before
10342 * the MI_DISPLAY_FLIP we may need to first emit everything else,
10343 * then do the cacheline alignment, and finally emit the
10346 ret
= intel_ring_cacheline_align(req
);
10350 cs
= intel_ring_begin(req
, len
);
10352 return PTR_ERR(cs
);
10354 /* Unmask the flip-done completion message. Note that the bspec says that
10355 * we should do this for both the BCS and RCS, and that we must not unmask
10356 * more than one flip event at any time (or ensure that one flip message
10357 * can be sent by waiting for flip-done prior to queueing new flips).
10358 * Experimentation says that BCS works despite DERRMR masking all
10359 * flip-done completion events and that unmasking all planes at once
10360 * for the RCS also doesn't appear to drop events. Setting the DERRMR
10361 * to zero does lead to lockups within MI_DISPLAY_FLIP.
10363 if (req
->engine
->id
== RCS
) {
10364 *cs
++ = MI_LOAD_REGISTER_IMM(1);
10365 *cs
++ = i915_mmio_reg_offset(DERRMR
);
10366 *cs
++ = ~(DERRMR_PIPEA_PRI_FLIP_DONE
|
10367 DERRMR_PIPEB_PRI_FLIP_DONE
|
10368 DERRMR_PIPEC_PRI_FLIP_DONE
);
10369 if (IS_GEN8(dev_priv
))
10370 *cs
++ = MI_STORE_REGISTER_MEM_GEN8
|
10371 MI_SRM_LRM_GLOBAL_GTT
;
10373 *cs
++ = MI_STORE_REGISTER_MEM
| MI_SRM_LRM_GLOBAL_GTT
;
10374 *cs
++ = i915_mmio_reg_offset(DERRMR
);
10375 *cs
++ = i915_ggtt_offset(req
->engine
->scratch
) + 256;
10376 if (IS_GEN8(dev_priv
)) {
10382 *cs
++ = MI_DISPLAY_FLIP_I915
| plane_bit
;
10383 *cs
++ = fb
->pitches
[0] | intel_fb_modifier_to_tiling(fb
->modifier
);
10384 *cs
++ = intel_crtc
->flip_work
->gtt_offset
;
10390 static bool use_mmio_flip(struct intel_engine_cs
*engine
,
10391 struct drm_i915_gem_object
*obj
)
10394 * This is not being used for older platforms, because
10395 * non-availability of flip done interrupt forces us to use
10396 * CS flips. Older platforms derive flip done using some clever
10397 * tricks involving the flip_pending status bits and vblank irqs.
10398 * So using MMIO flips there would disrupt this mechanism.
10401 if (engine
== NULL
)
10404 if (INTEL_GEN(engine
->i915
) < 5)
10407 if (i915
.use_mmio_flip
< 0)
10409 else if (i915
.use_mmio_flip
> 0)
10411 else if (i915
.enable_execlists
)
10414 return engine
!= i915_gem_object_last_write_engine(obj
);
10417 static void skl_do_mmio_flip(struct intel_crtc
*intel_crtc
,
10418 unsigned int rotation
,
10419 struct intel_flip_work
*work
)
10421 struct drm_device
*dev
= intel_crtc
->base
.dev
;
10422 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10423 struct drm_framebuffer
*fb
= intel_crtc
->base
.primary
->fb
;
10424 const enum pipe pipe
= intel_crtc
->pipe
;
10425 u32 ctl
, stride
= skl_plane_stride(fb
, 0, rotation
);
10427 ctl
= I915_READ(PLANE_CTL(pipe
, 0));
10428 ctl
&= ~PLANE_CTL_TILED_MASK
;
10429 switch (fb
->modifier
) {
10430 case DRM_FORMAT_MOD_NONE
:
10432 case I915_FORMAT_MOD_X_TILED
:
10433 ctl
|= PLANE_CTL_TILED_X
;
10435 case I915_FORMAT_MOD_Y_TILED
:
10436 ctl
|= PLANE_CTL_TILED_Y
;
10438 case I915_FORMAT_MOD_Yf_TILED
:
10439 ctl
|= PLANE_CTL_TILED_YF
;
10442 MISSING_CASE(fb
->modifier
);
10446 * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on
10447 * PLANE_SURF updates, the update is then guaranteed to be atomic.
10449 I915_WRITE(PLANE_CTL(pipe
, 0), ctl
);
10450 I915_WRITE(PLANE_STRIDE(pipe
, 0), stride
);
10452 I915_WRITE(PLANE_SURF(pipe
, 0), work
->gtt_offset
);
10453 POSTING_READ(PLANE_SURF(pipe
, 0));
10456 static void ilk_do_mmio_flip(struct intel_crtc
*intel_crtc
,
10457 struct intel_flip_work
*work
)
10459 struct drm_device
*dev
= intel_crtc
->base
.dev
;
10460 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10461 struct drm_framebuffer
*fb
= intel_crtc
->base
.primary
->fb
;
10462 i915_reg_t reg
= DSPCNTR(intel_crtc
->plane
);
10465 dspcntr
= I915_READ(reg
);
10467 if (fb
->modifier
== I915_FORMAT_MOD_X_TILED
)
10468 dspcntr
|= DISPPLANE_TILED
;
10470 dspcntr
&= ~DISPPLANE_TILED
;
10472 I915_WRITE(reg
, dspcntr
);
10474 I915_WRITE(DSPSURF(intel_crtc
->plane
), work
->gtt_offset
);
10475 POSTING_READ(DSPSURF(intel_crtc
->plane
));
10478 static void intel_mmio_flip_work_func(struct work_struct
*w
)
10480 struct intel_flip_work
*work
=
10481 container_of(w
, struct intel_flip_work
, mmio_work
);
10482 struct intel_crtc
*crtc
= to_intel_crtc(work
->crtc
);
10483 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
10484 struct intel_framebuffer
*intel_fb
=
10485 to_intel_framebuffer(crtc
->base
.primary
->fb
);
10486 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
10488 WARN_ON(i915_gem_object_wait(obj
, 0, MAX_SCHEDULE_TIMEOUT
, NULL
) < 0);
10490 intel_pipe_update_start(crtc
);
10492 if (INTEL_GEN(dev_priv
) >= 9)
10493 skl_do_mmio_flip(crtc
, work
->rotation
, work
);
10495 /* use_mmio_flip() retricts MMIO flips to ilk+ */
10496 ilk_do_mmio_flip(crtc
, work
);
10498 intel_pipe_update_end(crtc
, work
);
10501 static int intel_default_queue_flip(struct drm_device
*dev
,
10502 struct drm_crtc
*crtc
,
10503 struct drm_framebuffer
*fb
,
10504 struct drm_i915_gem_object
*obj
,
10505 struct drm_i915_gem_request
*req
,
10511 static bool __pageflip_stall_check_cs(struct drm_i915_private
*dev_priv
,
10512 struct intel_crtc
*intel_crtc
,
10513 struct intel_flip_work
*work
)
10517 if (!atomic_read(&work
->pending
))
10522 vblank
= intel_crtc_get_vblank_counter(intel_crtc
);
10523 if (work
->flip_ready_vblank
== 0) {
10524 if (work
->flip_queued_req
&&
10525 !i915_gem_request_completed(work
->flip_queued_req
))
10528 work
->flip_ready_vblank
= vblank
;
10531 if (vblank
- work
->flip_ready_vblank
< 3)
10534 /* Potential stall - if we see that the flip has happened,
10535 * assume a missed interrupt. */
10536 if (INTEL_GEN(dev_priv
) >= 4)
10537 addr
= I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc
->plane
)));
10539 addr
= I915_READ(DSPADDR(intel_crtc
->plane
));
10541 /* There is a potential issue here with a false positive after a flip
10542 * to the same address. We could address this by checking for a
10543 * non-incrementing frame counter.
10545 return addr
== work
->gtt_offset
;
10548 void intel_check_page_flip(struct drm_i915_private
*dev_priv
, int pipe
)
10550 struct drm_device
*dev
= &dev_priv
->drm
;
10551 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
10552 struct intel_flip_work
*work
;
10554 WARN_ON(!in_interrupt());
10559 spin_lock(&dev
->event_lock
);
10560 work
= crtc
->flip_work
;
10562 if (work
!= NULL
&& !is_mmio_work(work
) &&
10563 __pageflip_stall_check_cs(dev_priv
, crtc
, work
)) {
10565 "Kicking stuck page flip: queued at %d, now %d\n",
10566 work
->flip_queued_vblank
, intel_crtc_get_vblank_counter(crtc
));
10567 page_flip_completed(crtc
);
10571 if (work
!= NULL
&& !is_mmio_work(work
) &&
10572 intel_crtc_get_vblank_counter(crtc
) - work
->flip_queued_vblank
> 1)
10573 intel_queue_rps_boost_for_request(work
->flip_queued_req
);
10574 spin_unlock(&dev
->event_lock
);
10578 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
10579 struct drm_framebuffer
*fb
,
10580 struct drm_pending_vblank_event
*event
,
10581 uint32_t page_flip_flags
)
10583 struct drm_device
*dev
= crtc
->dev
;
10584 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10585 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
10586 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
10587 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10588 struct drm_plane
*primary
= crtc
->primary
;
10589 enum pipe pipe
= intel_crtc
->pipe
;
10590 struct intel_flip_work
*work
;
10591 struct intel_engine_cs
*engine
;
10593 struct drm_i915_gem_request
*request
;
10594 struct i915_vma
*vma
;
10598 * drm_mode_page_flip_ioctl() should already catch this, but double
10599 * check to be safe. In the future we may enable pageflipping from
10600 * a disabled primary plane.
10602 if (WARN_ON(intel_fb_obj(old_fb
) == NULL
))
10605 /* Can't change pixel format via MI display flips. */
10606 if (fb
->format
!= crtc
->primary
->fb
->format
)
10610 * TILEOFF/LINOFF registers can't be changed via MI display flips.
10611 * Note that pitch changes could also affect these register.
10613 if (INTEL_GEN(dev_priv
) > 3 &&
10614 (fb
->offsets
[0] != crtc
->primary
->fb
->offsets
[0] ||
10615 fb
->pitches
[0] != crtc
->primary
->fb
->pitches
[0]))
10618 if (i915_terminally_wedged(&dev_priv
->gpu_error
))
10621 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
10625 work
->event
= event
;
10627 work
->old_fb
= old_fb
;
10628 INIT_WORK(&work
->unpin_work
, intel_unpin_work_fn
);
10630 ret
= drm_crtc_vblank_get(crtc
);
10634 /* We borrow the event spin lock for protecting flip_work */
10635 spin_lock_irq(&dev
->event_lock
);
10636 if (intel_crtc
->flip_work
) {
10637 /* Before declaring the flip queue wedged, check if
10638 * the hardware completed the operation behind our backs.
10640 if (pageflip_finished(intel_crtc
, intel_crtc
->flip_work
)) {
10641 DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
10642 page_flip_completed(intel_crtc
);
10644 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
10645 spin_unlock_irq(&dev
->event_lock
);
10647 drm_crtc_vblank_put(crtc
);
10652 intel_crtc
->flip_work
= work
;
10653 spin_unlock_irq(&dev
->event_lock
);
10655 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
10656 flush_workqueue(dev_priv
->wq
);
10658 /* Reference the objects for the scheduled work. */
10659 drm_framebuffer_reference(work
->old_fb
);
10661 crtc
->primary
->fb
= fb
;
10662 update_state_fb(crtc
->primary
);
10664 work
->pending_flip_obj
= i915_gem_object_get(obj
);
10666 ret
= i915_mutex_lock_interruptible(dev
);
10670 intel_crtc
->reset_count
= i915_reset_count(&dev_priv
->gpu_error
);
10671 if (i915_reset_backoff_or_wedged(&dev_priv
->gpu_error
)) {
10676 atomic_inc(&intel_crtc
->unpin_work_count
);
10678 if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
))
10679 work
->flip_count
= I915_READ(PIPE_FLIPCOUNT_G4X(pipe
)) + 1;
10681 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
10682 engine
= dev_priv
->engine
[BCS
];
10683 if (fb
->modifier
!= old_fb
->modifier
)
10684 /* vlv: DISPLAY_FLIP fails to change tiling */
10686 } else if (IS_IVYBRIDGE(dev_priv
) || IS_HASWELL(dev_priv
)) {
10687 engine
= dev_priv
->engine
[BCS
];
10688 } else if (INTEL_GEN(dev_priv
) >= 7) {
10689 engine
= i915_gem_object_last_write_engine(obj
);
10690 if (engine
== NULL
|| engine
->id
!= RCS
)
10691 engine
= dev_priv
->engine
[BCS
];
10693 engine
= dev_priv
->engine
[RCS
];
10696 mmio_flip
= use_mmio_flip(engine
, obj
);
10698 vma
= intel_pin_and_fence_fb_obj(fb
, primary
->state
->rotation
);
10700 ret
= PTR_ERR(vma
);
10701 goto cleanup_pending
;
10704 work
->old_vma
= to_intel_plane_state(primary
->state
)->vma
;
10705 to_intel_plane_state(primary
->state
)->vma
= vma
;
10707 work
->gtt_offset
= i915_ggtt_offset(vma
) + intel_crtc
->dspaddr_offset
;
10708 work
->rotation
= crtc
->primary
->state
->rotation
;
10711 * There's the potential that the next frame will not be compatible with
10712 * FBC, so we want to call pre_update() before the actual page flip.
10713 * The problem is that pre_update() caches some information about the fb
10714 * object, so we want to do this only after the object is pinned. Let's
10715 * be on the safe side and do this immediately before scheduling the
10718 intel_fbc_pre_update(intel_crtc
, intel_crtc
->config
,
10719 to_intel_plane_state(primary
->state
));
10722 INIT_WORK(&work
->mmio_work
, intel_mmio_flip_work_func
);
10723 queue_work(system_unbound_wq
, &work
->mmio_work
);
10725 request
= i915_gem_request_alloc(engine
,
10726 dev_priv
->kernel_context
);
10727 if (IS_ERR(request
)) {
10728 ret
= PTR_ERR(request
);
10729 goto cleanup_unpin
;
10732 ret
= i915_gem_request_await_object(request
, obj
, false);
10734 goto cleanup_request
;
10736 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
, request
,
10739 goto cleanup_request
;
10741 intel_mark_page_flip_active(intel_crtc
, work
);
10743 work
->flip_queued_req
= i915_gem_request_get(request
);
10744 i915_add_request(request
);
10747 i915_gem_object_wait_priority(obj
, 0, I915_PRIORITY_DISPLAY
);
10748 i915_gem_track_fb(intel_fb_obj(old_fb
), obj
,
10749 to_intel_plane(primary
)->frontbuffer_bit
);
10750 mutex_unlock(&dev
->struct_mutex
);
10752 intel_frontbuffer_flip_prepare(to_i915(dev
),
10753 to_intel_plane(primary
)->frontbuffer_bit
);
10755 trace_i915_flip_request(intel_crtc
->plane
, obj
);
10760 i915_add_request(request
);
10762 to_intel_plane_state(primary
->state
)->vma
= work
->old_vma
;
10763 intel_unpin_fb_vma(vma
);
10765 atomic_dec(&intel_crtc
->unpin_work_count
);
10767 mutex_unlock(&dev
->struct_mutex
);
10769 crtc
->primary
->fb
= old_fb
;
10770 update_state_fb(crtc
->primary
);
10772 i915_gem_object_put(obj
);
10773 drm_framebuffer_unreference(work
->old_fb
);
10775 spin_lock_irq(&dev
->event_lock
);
10776 intel_crtc
->flip_work
= NULL
;
10777 spin_unlock_irq(&dev
->event_lock
);
10779 drm_crtc_vblank_put(crtc
);
10784 struct drm_atomic_state
*state
;
10785 struct drm_plane_state
*plane_state
;
10788 state
= drm_atomic_state_alloc(dev
);
10791 state
->acquire_ctx
= drm_modeset_legacy_acquire_ctx(crtc
);
10794 plane_state
= drm_atomic_get_plane_state(state
, primary
);
10795 ret
= PTR_ERR_OR_ZERO(plane_state
);
10797 drm_atomic_set_fb_for_plane(plane_state
, fb
);
10799 ret
= drm_atomic_set_crtc_for_plane(plane_state
, crtc
);
10801 ret
= drm_atomic_commit(state
);
10804 if (ret
== -EDEADLK
) {
10805 drm_modeset_backoff(state
->acquire_ctx
);
10806 drm_atomic_state_clear(state
);
10810 drm_atomic_state_put(state
);
10812 if (ret
== 0 && event
) {
10813 spin_lock_irq(&dev
->event_lock
);
10814 drm_crtc_send_vblank_event(crtc
, event
);
10815 spin_unlock_irq(&dev
->event_lock
);
10823 * intel_wm_need_update - Check whether watermarks need updating
10824 * @plane: drm plane
10825 * @state: new plane state
10827 * Check current plane state versus the new one to determine whether
10828 * watermarks need to be recalculated.
10830 * Returns true or false.
10832 static bool intel_wm_need_update(struct drm_plane
*plane
,
10833 struct drm_plane_state
*state
)
10835 struct intel_plane_state
*new = to_intel_plane_state(state
);
10836 struct intel_plane_state
*cur
= to_intel_plane_state(plane
->state
);
10838 /* Update watermarks on tiling or size changes. */
10839 if (new->base
.visible
!= cur
->base
.visible
)
10842 if (!cur
->base
.fb
|| !new->base
.fb
)
10845 if (cur
->base
.fb
->modifier
!= new->base
.fb
->modifier
||
10846 cur
->base
.rotation
!= new->base
.rotation
||
10847 drm_rect_width(&new->base
.src
) != drm_rect_width(&cur
->base
.src
) ||
10848 drm_rect_height(&new->base
.src
) != drm_rect_height(&cur
->base
.src
) ||
10849 drm_rect_width(&new->base
.dst
) != drm_rect_width(&cur
->base
.dst
) ||
10850 drm_rect_height(&new->base
.dst
) != drm_rect_height(&cur
->base
.dst
))
10856 static bool needs_scaling(struct intel_plane_state
*state
)
10858 int src_w
= drm_rect_width(&state
->base
.src
) >> 16;
10859 int src_h
= drm_rect_height(&state
->base
.src
) >> 16;
10860 int dst_w
= drm_rect_width(&state
->base
.dst
);
10861 int dst_h
= drm_rect_height(&state
->base
.dst
);
10863 return (src_w
!= dst_w
|| src_h
!= dst_h
);
10866 int intel_plane_atomic_calc_changes(struct drm_crtc_state
*crtc_state
,
10867 struct drm_plane_state
*plane_state
)
10869 struct intel_crtc_state
*pipe_config
= to_intel_crtc_state(crtc_state
);
10870 struct drm_crtc
*crtc
= crtc_state
->crtc
;
10871 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10872 struct intel_plane
*plane
= to_intel_plane(plane_state
->plane
);
10873 struct drm_device
*dev
= crtc
->dev
;
10874 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10875 struct intel_plane_state
*old_plane_state
=
10876 to_intel_plane_state(plane
->base
.state
);
10877 bool mode_changed
= needs_modeset(crtc_state
);
10878 bool was_crtc_enabled
= crtc
->state
->active
;
10879 bool is_crtc_enabled
= crtc_state
->active
;
10880 bool turn_off
, turn_on
, visible
, was_visible
;
10881 struct drm_framebuffer
*fb
= plane_state
->fb
;
10884 if (INTEL_GEN(dev_priv
) >= 9 && plane
->id
!= PLANE_CURSOR
) {
10885 ret
= skl_update_scaler_plane(
10886 to_intel_crtc_state(crtc_state
),
10887 to_intel_plane_state(plane_state
));
10892 was_visible
= old_plane_state
->base
.visible
;
10893 visible
= plane_state
->visible
;
10895 if (!was_crtc_enabled
&& WARN_ON(was_visible
))
10896 was_visible
= false;
10899 * Visibility is calculated as if the crtc was on, but
10900 * after scaler setup everything depends on it being off
10901 * when the crtc isn't active.
10903 * FIXME this is wrong for watermarks. Watermarks should also
10904 * be computed as if the pipe would be active. Perhaps move
10905 * per-plane wm computation to the .check_plane() hook, and
10906 * only combine the results from all planes in the current place?
10908 if (!is_crtc_enabled
) {
10909 plane_state
->visible
= visible
= false;
10910 to_intel_crtc_state(crtc_state
)->active_planes
&= ~BIT(plane
->id
);
10913 if (!was_visible
&& !visible
)
10916 if (fb
!= old_plane_state
->base
.fb
)
10917 pipe_config
->fb_changed
= true;
10919 turn_off
= was_visible
&& (!visible
|| mode_changed
);
10920 turn_on
= visible
&& (!was_visible
|| mode_changed
);
10922 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
10923 intel_crtc
->base
.base
.id
, intel_crtc
->base
.name
,
10924 plane
->base
.base
.id
, plane
->base
.name
,
10925 fb
? fb
->base
.id
: -1);
10927 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
10928 plane
->base
.base
.id
, plane
->base
.name
,
10929 was_visible
, visible
,
10930 turn_off
, turn_on
, mode_changed
);
10933 if (INTEL_GEN(dev_priv
) < 5)
10934 pipe_config
->update_wm_pre
= true;
10936 /* must disable cxsr around plane enable/disable */
10937 if (plane
->id
!= PLANE_CURSOR
)
10938 pipe_config
->disable_cxsr
= true;
10939 } else if (turn_off
) {
10940 if (INTEL_GEN(dev_priv
) < 5)
10941 pipe_config
->update_wm_post
= true;
10943 /* must disable cxsr around plane enable/disable */
10944 if (plane
->id
!= PLANE_CURSOR
)
10945 pipe_config
->disable_cxsr
= true;
10946 } else if (intel_wm_need_update(&plane
->base
, plane_state
)) {
10947 if (INTEL_GEN(dev_priv
) < 5) {
10948 /* FIXME bollocks */
10949 pipe_config
->update_wm_pre
= true;
10950 pipe_config
->update_wm_post
= true;
10954 if (visible
|| was_visible
)
10955 pipe_config
->fb_bits
|= plane
->frontbuffer_bit
;
10958 * WaCxSRDisabledForSpriteScaling:ivb
10960 * cstate->update_wm was already set above, so this flag will
10961 * take effect when we commit and program watermarks.
10963 if (plane
->id
== PLANE_SPRITE0
&& IS_IVYBRIDGE(dev_priv
) &&
10964 needs_scaling(to_intel_plane_state(plane_state
)) &&
10965 !needs_scaling(old_plane_state
))
10966 pipe_config
->disable_lp_wm
= true;
10971 static bool encoders_cloneable(const struct intel_encoder
*a
,
10972 const struct intel_encoder
*b
)
10974 /* masks could be asymmetric, so check both ways */
10975 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
10976 b
->cloneable
& (1 << a
->type
));
10979 static bool check_single_encoder_cloning(struct drm_atomic_state
*state
,
10980 struct intel_crtc
*crtc
,
10981 struct intel_encoder
*encoder
)
10983 struct intel_encoder
*source_encoder
;
10984 struct drm_connector
*connector
;
10985 struct drm_connector_state
*connector_state
;
10988 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10989 if (connector_state
->crtc
!= &crtc
->base
)
10993 to_intel_encoder(connector_state
->best_encoder
);
10994 if (!encoders_cloneable(encoder
, source_encoder
))
11001 static int intel_crtc_atomic_check(struct drm_crtc
*crtc
,
11002 struct drm_crtc_state
*crtc_state
)
11004 struct drm_device
*dev
= crtc
->dev
;
11005 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11006 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11007 struct intel_crtc_state
*pipe_config
=
11008 to_intel_crtc_state(crtc_state
);
11009 struct drm_atomic_state
*state
= crtc_state
->state
;
11011 bool mode_changed
= needs_modeset(crtc_state
);
11013 if (mode_changed
&& !crtc_state
->active
)
11014 pipe_config
->update_wm_post
= true;
11016 if (mode_changed
&& crtc_state
->enable
&&
11017 dev_priv
->display
.crtc_compute_clock
&&
11018 !WARN_ON(pipe_config
->shared_dpll
)) {
11019 ret
= dev_priv
->display
.crtc_compute_clock(intel_crtc
,
11025 if (crtc_state
->color_mgmt_changed
) {
11026 ret
= intel_color_check(crtc
, crtc_state
);
11031 * Changing color management on Intel hardware is
11032 * handled as part of planes update.
11034 crtc_state
->planes_changed
= true;
11038 if (dev_priv
->display
.compute_pipe_wm
) {
11039 ret
= dev_priv
->display
.compute_pipe_wm(pipe_config
);
11041 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
11046 if (dev_priv
->display
.compute_intermediate_wm
&&
11047 !to_intel_atomic_state(state
)->skip_intermediate_wm
) {
11048 if (WARN_ON(!dev_priv
->display
.compute_pipe_wm
))
11052 * Calculate 'intermediate' watermarks that satisfy both the
11053 * old state and the new state. We can program these
11056 ret
= dev_priv
->display
.compute_intermediate_wm(dev
,
11060 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
11063 } else if (dev_priv
->display
.compute_intermediate_wm
) {
11064 if (HAS_PCH_SPLIT(dev_priv
) && INTEL_GEN(dev_priv
) < 9)
11065 pipe_config
->wm
.ilk
.intermediate
= pipe_config
->wm
.ilk
.optimal
;
11068 if (INTEL_GEN(dev_priv
) >= 9) {
11070 ret
= skl_update_scaler_crtc(pipe_config
);
11073 ret
= intel_atomic_setup_scalers(dev_priv
, intel_crtc
,
11080 static const struct drm_crtc_helper_funcs intel_helper_funcs
= {
11081 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
11082 .atomic_begin
= intel_begin_crtc_commit
,
11083 .atomic_flush
= intel_finish_crtc_commit
,
11084 .atomic_check
= intel_crtc_atomic_check
,
11087 static void intel_modeset_update_connector_atomic_state(struct drm_device
*dev
)
11089 struct intel_connector
*connector
;
11090 struct drm_connector_list_iter conn_iter
;
11092 drm_connector_list_iter_begin(dev
, &conn_iter
);
11093 for_each_intel_connector_iter(connector
, &conn_iter
) {
11094 if (connector
->base
.state
->crtc
)
11095 drm_connector_unreference(&connector
->base
);
11097 if (connector
->base
.encoder
) {
11098 connector
->base
.state
->best_encoder
=
11099 connector
->base
.encoder
;
11100 connector
->base
.state
->crtc
=
11101 connector
->base
.encoder
->crtc
;
11103 drm_connector_reference(&connector
->base
);
11105 connector
->base
.state
->best_encoder
= NULL
;
11106 connector
->base
.state
->crtc
= NULL
;
11109 drm_connector_list_iter_end(&conn_iter
);
11113 connected_sink_compute_bpp(struct intel_connector
*connector
,
11114 struct intel_crtc_state
*pipe_config
)
11116 const struct drm_display_info
*info
= &connector
->base
.display_info
;
11117 int bpp
= pipe_config
->pipe_bpp
;
11119 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
11120 connector
->base
.base
.id
,
11121 connector
->base
.name
);
11123 /* Don't use an invalid EDID bpc value */
11124 if (info
->bpc
!= 0 && info
->bpc
* 3 < bpp
) {
11125 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
11126 bpp
, info
->bpc
* 3);
11127 pipe_config
->pipe_bpp
= info
->bpc
* 3;
11130 /* Clamp bpp to 8 on screens without EDID 1.4 */
11131 if (info
->bpc
== 0 && bpp
> 24) {
11132 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
11134 pipe_config
->pipe_bpp
= 24;
11139 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
11140 struct intel_crtc_state
*pipe_config
)
11142 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
11143 struct drm_atomic_state
*state
;
11144 struct drm_connector
*connector
;
11145 struct drm_connector_state
*connector_state
;
11148 if ((IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
11149 IS_CHERRYVIEW(dev_priv
)))
11151 else if (INTEL_GEN(dev_priv
) >= 5)
11157 pipe_config
->pipe_bpp
= bpp
;
11159 state
= pipe_config
->base
.state
;
11161 /* Clamp display bpp to EDID value */
11162 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
11163 if (connector_state
->crtc
!= &crtc
->base
)
11166 connected_sink_compute_bpp(to_intel_connector(connector
),
11173 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
11175 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11176 "type: 0x%x flags: 0x%x\n",
11178 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
11179 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
11180 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
11181 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
11185 intel_dump_m_n_config(struct intel_crtc_state
*pipe_config
, char *id
,
11186 unsigned int lane_count
, struct intel_link_m_n
*m_n
)
11188 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11190 m_n
->gmch_m
, m_n
->gmch_n
,
11191 m_n
->link_m
, m_n
->link_n
, m_n
->tu
);
11194 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
11195 struct intel_crtc_state
*pipe_config
,
11196 const char *context
)
11198 struct drm_device
*dev
= crtc
->base
.dev
;
11199 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11200 struct drm_plane
*plane
;
11201 struct intel_plane
*intel_plane
;
11202 struct intel_plane_state
*state
;
11203 struct drm_framebuffer
*fb
;
11205 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
11206 crtc
->base
.base
.id
, crtc
->base
.name
, context
);
11208 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
11209 transcoder_name(pipe_config
->cpu_transcoder
),
11210 pipe_config
->pipe_bpp
, pipe_config
->dither
);
11212 if (pipe_config
->has_pch_encoder
)
11213 intel_dump_m_n_config(pipe_config
, "fdi",
11214 pipe_config
->fdi_lanes
,
11215 &pipe_config
->fdi_m_n
);
11217 if (intel_crtc_has_dp_encoder(pipe_config
)) {
11218 intel_dump_m_n_config(pipe_config
, "dp m_n",
11219 pipe_config
->lane_count
, &pipe_config
->dp_m_n
);
11220 if (pipe_config
->has_drrs
)
11221 intel_dump_m_n_config(pipe_config
, "dp m2_n2",
11222 pipe_config
->lane_count
,
11223 &pipe_config
->dp_m2_n2
);
11226 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
11227 pipe_config
->has_audio
, pipe_config
->has_infoframe
);
11229 DRM_DEBUG_KMS("requested mode:\n");
11230 drm_mode_debug_printmodeline(&pipe_config
->base
.mode
);
11231 DRM_DEBUG_KMS("adjusted mode:\n");
11232 drm_mode_debug_printmodeline(&pipe_config
->base
.adjusted_mode
);
11233 intel_dump_crtc_timings(&pipe_config
->base
.adjusted_mode
);
11234 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
11235 pipe_config
->port_clock
,
11236 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
,
11237 pipe_config
->pixel_rate
);
11239 if (INTEL_GEN(dev_priv
) >= 9)
11240 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
11242 pipe_config
->scaler_state
.scaler_users
,
11243 pipe_config
->scaler_state
.scaler_id
);
11245 if (HAS_GMCH_DISPLAY(dev_priv
))
11246 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
11247 pipe_config
->gmch_pfit
.control
,
11248 pipe_config
->gmch_pfit
.pgm_ratios
,
11249 pipe_config
->gmch_pfit
.lvds_border_bits
);
11251 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
11252 pipe_config
->pch_pfit
.pos
,
11253 pipe_config
->pch_pfit
.size
,
11254 enableddisabled(pipe_config
->pch_pfit
.enabled
));
11256 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
11257 pipe_config
->ips_enabled
, pipe_config
->double_wide
);
11259 intel_dpll_dump_hw_state(dev_priv
, &pipe_config
->dpll_hw_state
);
11261 DRM_DEBUG_KMS("planes on this crtc\n");
11262 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
11263 struct drm_format_name_buf format_name
;
11264 intel_plane
= to_intel_plane(plane
);
11265 if (intel_plane
->pipe
!= crtc
->pipe
)
11268 state
= to_intel_plane_state(plane
->state
);
11269 fb
= state
->base
.fb
;
11271 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
11272 plane
->base
.id
, plane
->name
, state
->scaler_id
);
11276 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
11277 plane
->base
.id
, plane
->name
,
11278 fb
->base
.id
, fb
->width
, fb
->height
,
11279 drm_get_format_name(fb
->format
->format
, &format_name
));
11280 if (INTEL_GEN(dev_priv
) >= 9)
11281 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
11283 state
->base
.src
.x1
>> 16,
11284 state
->base
.src
.y1
>> 16,
11285 drm_rect_width(&state
->base
.src
) >> 16,
11286 drm_rect_height(&state
->base
.src
) >> 16,
11287 state
->base
.dst
.x1
, state
->base
.dst
.y1
,
11288 drm_rect_width(&state
->base
.dst
),
11289 drm_rect_height(&state
->base
.dst
));
11293 static bool check_digital_port_conflicts(struct drm_atomic_state
*state
)
11295 struct drm_device
*dev
= state
->dev
;
11296 struct drm_connector
*connector
;
11297 unsigned int used_ports
= 0;
11298 unsigned int used_mst_ports
= 0;
11301 * Walk the connector list instead of the encoder
11302 * list to detect the problem on ddi platforms
11303 * where there's just one encoder per digital port.
11305 drm_for_each_connector(connector
, dev
) {
11306 struct drm_connector_state
*connector_state
;
11307 struct intel_encoder
*encoder
;
11309 connector_state
= drm_atomic_get_existing_connector_state(state
, connector
);
11310 if (!connector_state
)
11311 connector_state
= connector
->state
;
11313 if (!connector_state
->best_encoder
)
11316 encoder
= to_intel_encoder(connector_state
->best_encoder
);
11318 WARN_ON(!connector_state
->crtc
);
11320 switch (encoder
->type
) {
11321 unsigned int port_mask
;
11322 case INTEL_OUTPUT_UNKNOWN
:
11323 if (WARN_ON(!HAS_DDI(to_i915(dev
))))
11325 case INTEL_OUTPUT_DP
:
11326 case INTEL_OUTPUT_HDMI
:
11327 case INTEL_OUTPUT_EDP
:
11328 port_mask
= 1 << enc_to_dig_port(&encoder
->base
)->port
;
11330 /* the same port mustn't appear more than once */
11331 if (used_ports
& port_mask
)
11334 used_ports
|= port_mask
;
11336 case INTEL_OUTPUT_DP_MST
:
11338 1 << enc_to_mst(&encoder
->base
)->primary
->port
;
11345 /* can't mix MST and SST/HDMI on the same port */
11346 if (used_ports
& used_mst_ports
)
11353 clear_intel_crtc_state(struct intel_crtc_state
*crtc_state
)
11355 struct drm_i915_private
*dev_priv
=
11356 to_i915(crtc_state
->base
.crtc
->dev
);
11357 struct intel_crtc_scaler_state scaler_state
;
11358 struct intel_dpll_hw_state dpll_hw_state
;
11359 struct intel_shared_dpll
*shared_dpll
;
11360 struct intel_crtc_wm_state wm_state
;
11363 /* FIXME: before the switch to atomic started, a new pipe_config was
11364 * kzalloc'd. Code that depends on any field being zero should be
11365 * fixed, so that the crtc_state can be safely duplicated. For now,
11366 * only fields that are know to not cause problems are preserved. */
11368 scaler_state
= crtc_state
->scaler_state
;
11369 shared_dpll
= crtc_state
->shared_dpll
;
11370 dpll_hw_state
= crtc_state
->dpll_hw_state
;
11371 force_thru
= crtc_state
->pch_pfit
.force_thru
;
11372 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
11373 wm_state
= crtc_state
->wm
;
11375 /* Keep base drm_crtc_state intact, only clear our extended struct */
11376 BUILD_BUG_ON(offsetof(struct intel_crtc_state
, base
));
11377 memset(&crtc_state
->base
+ 1, 0,
11378 sizeof(*crtc_state
) - sizeof(crtc_state
->base
));
11380 crtc_state
->scaler_state
= scaler_state
;
11381 crtc_state
->shared_dpll
= shared_dpll
;
11382 crtc_state
->dpll_hw_state
= dpll_hw_state
;
11383 crtc_state
->pch_pfit
.force_thru
= force_thru
;
11384 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
11385 crtc_state
->wm
= wm_state
;
11389 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
11390 struct intel_crtc_state
*pipe_config
)
11392 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
11393 struct intel_encoder
*encoder
;
11394 struct drm_connector
*connector
;
11395 struct drm_connector_state
*connector_state
;
11396 int base_bpp
, ret
= -EINVAL
;
11400 clear_intel_crtc_state(pipe_config
);
11402 pipe_config
->cpu_transcoder
=
11403 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
11406 * Sanitize sync polarity flags based on requested ones. If neither
11407 * positive or negative polarity is requested, treat this as meaning
11408 * negative polarity.
11410 if (!(pipe_config
->base
.adjusted_mode
.flags
&
11411 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
11412 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
11414 if (!(pipe_config
->base
.adjusted_mode
.flags
&
11415 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
11416 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
11418 base_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
11424 * Determine the real pipe dimensions. Note that stereo modes can
11425 * increase the actual pipe size due to the frame doubling and
11426 * insertion of additional space for blanks between the frame. This
11427 * is stored in the crtc timings. We use the requested mode to do this
11428 * computation to clearly distinguish it from the adjusted mode, which
11429 * can be changed by the connectors in the below retry loop.
11431 drm_mode_get_hv_timing(&pipe_config
->base
.mode
,
11432 &pipe_config
->pipe_src_w
,
11433 &pipe_config
->pipe_src_h
);
11435 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
11436 if (connector_state
->crtc
!= crtc
)
11439 encoder
= to_intel_encoder(connector_state
->best_encoder
);
11441 if (!check_single_encoder_cloning(state
, to_intel_crtc(crtc
), encoder
)) {
11442 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
11447 * Determine output_types before calling the .compute_config()
11448 * hooks so that the hooks can use this information safely.
11450 pipe_config
->output_types
|= 1 << encoder
->type
;
11454 /* Ensure the port clock defaults are reset when retrying. */
11455 pipe_config
->port_clock
= 0;
11456 pipe_config
->pixel_multiplier
= 1;
11458 /* Fill in default crtc timings, allow encoders to overwrite them. */
11459 drm_mode_set_crtcinfo(&pipe_config
->base
.adjusted_mode
,
11460 CRTC_STEREO_DOUBLE
);
11462 /* Pass our mode to the connectors and the CRTC to give them a chance to
11463 * adjust it according to limitations or connector properties, and also
11464 * a chance to reject the mode entirely.
11466 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
11467 if (connector_state
->crtc
!= crtc
)
11470 encoder
= to_intel_encoder(connector_state
->best_encoder
);
11472 if (!(encoder
->compute_config(encoder
, pipe_config
, connector_state
))) {
11473 DRM_DEBUG_KMS("Encoder config failure\n");
11478 /* Set default port clock if not overwritten by the encoder. Needs to be
11479 * done afterwards in case the encoder adjusts the mode. */
11480 if (!pipe_config
->port_clock
)
11481 pipe_config
->port_clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
11482 * pipe_config
->pixel_multiplier
;
11484 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
11486 DRM_DEBUG_KMS("CRTC fixup failed\n");
11490 if (ret
== RETRY
) {
11491 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
11496 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11498 goto encoder_retry
;
11501 /* Dithering seems to not pass-through bits correctly when it should, so
11502 * only enable it on 6bpc panels and when its not a compliance
11503 * test requesting 6bpc video pattern.
11505 pipe_config
->dither
= (pipe_config
->pipe_bpp
== 6*3) &&
11506 !pipe_config
->dither_force_disable
;
11507 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
11508 base_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
11515 intel_modeset_update_crtc_state(struct drm_atomic_state
*state
)
11517 struct drm_crtc
*crtc
;
11518 struct drm_crtc_state
*new_crtc_state
;
11521 /* Double check state. */
11522 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
11523 to_intel_crtc(crtc
)->config
= to_intel_crtc_state(new_crtc_state
);
11525 /* Update hwmode for vblank functions */
11526 if (new_crtc_state
->active
)
11527 crtc
->hwmode
= new_crtc_state
->adjusted_mode
;
11529 crtc
->hwmode
.crtc_clock
= 0;
11532 * Update legacy state to satisfy fbc code. This can
11533 * be removed when fbc uses the atomic state.
11535 if (drm_atomic_get_existing_plane_state(state
, crtc
->primary
)) {
11536 struct drm_plane_state
*plane_state
= crtc
->primary
->state
;
11538 crtc
->primary
->fb
= plane_state
->fb
;
11539 crtc
->x
= plane_state
->src_x
>> 16;
11540 crtc
->y
= plane_state
->src_y
>> 16;
11545 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
11549 if (clock1
== clock2
)
11552 if (!clock1
|| !clock2
)
11555 diff
= abs(clock1
- clock2
);
11557 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
11564 intel_compare_m_n(unsigned int m
, unsigned int n
,
11565 unsigned int m2
, unsigned int n2
,
11568 if (m
== m2
&& n
== n2
)
11571 if (exact
|| !m
|| !n
|| !m2
|| !n2
)
11574 BUILD_BUG_ON(DATA_LINK_M_N_MASK
> INT_MAX
);
11581 } else if (n
< n2
) {
11591 return intel_fuzzy_clock_check(m
, m2
);
11595 intel_compare_link_m_n(const struct intel_link_m_n
*m_n
,
11596 struct intel_link_m_n
*m2_n2
,
11599 if (m_n
->tu
== m2_n2
->tu
&&
11600 intel_compare_m_n(m_n
->gmch_m
, m_n
->gmch_n
,
11601 m2_n2
->gmch_m
, m2_n2
->gmch_n
, !adjust
) &&
11602 intel_compare_m_n(m_n
->link_m
, m_n
->link_n
,
11603 m2_n2
->link_m
, m2_n2
->link_n
, !adjust
)) {
11613 static void __printf(3, 4)
11614 pipe_config_err(bool adjust
, const char *name
, const char *format
, ...)
11617 unsigned int category
;
11618 struct va_format vaf
;
11622 level
= KERN_DEBUG
;
11623 category
= DRM_UT_KMS
;
11626 category
= DRM_UT_NONE
;
11629 va_start(args
, format
);
11633 drm_printk(level
, category
, "mismatch in %s %pV", name
, &vaf
);
11639 intel_pipe_config_compare(struct drm_i915_private
*dev_priv
,
11640 struct intel_crtc_state
*current_config
,
11641 struct intel_crtc_state
*pipe_config
,
11646 #define PIPE_CONF_CHECK_X(name) \
11647 if (current_config->name != pipe_config->name) { \
11648 pipe_config_err(adjust, __stringify(name), \
11649 "(expected 0x%08x, found 0x%08x)\n", \
11650 current_config->name, \
11651 pipe_config->name); \
11655 #define PIPE_CONF_CHECK_I(name) \
11656 if (current_config->name != pipe_config->name) { \
11657 pipe_config_err(adjust, __stringify(name), \
11658 "(expected %i, found %i)\n", \
11659 current_config->name, \
11660 pipe_config->name); \
11664 #define PIPE_CONF_CHECK_P(name) \
11665 if (current_config->name != pipe_config->name) { \
11666 pipe_config_err(adjust, __stringify(name), \
11667 "(expected %p, found %p)\n", \
11668 current_config->name, \
11669 pipe_config->name); \
11673 #define PIPE_CONF_CHECK_M_N(name) \
11674 if (!intel_compare_link_m_n(¤t_config->name, \
11675 &pipe_config->name,\
11677 pipe_config_err(adjust, __stringify(name), \
11678 "(expected tu %i gmch %i/%i link %i/%i, " \
11679 "found tu %i, gmch %i/%i link %i/%i)\n", \
11680 current_config->name.tu, \
11681 current_config->name.gmch_m, \
11682 current_config->name.gmch_n, \
11683 current_config->name.link_m, \
11684 current_config->name.link_n, \
11685 pipe_config->name.tu, \
11686 pipe_config->name.gmch_m, \
11687 pipe_config->name.gmch_n, \
11688 pipe_config->name.link_m, \
11689 pipe_config->name.link_n); \
11693 /* This is required for BDW+ where there is only one set of registers for
11694 * switching between high and low RR.
11695 * This macro can be used whenever a comparison has to be made between one
11696 * hw state and multiple sw state variables.
11698 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \
11699 if (!intel_compare_link_m_n(¤t_config->name, \
11700 &pipe_config->name, adjust) && \
11701 !intel_compare_link_m_n(¤t_config->alt_name, \
11702 &pipe_config->name, adjust)) { \
11703 pipe_config_err(adjust, __stringify(name), \
11704 "(expected tu %i gmch %i/%i link %i/%i, " \
11705 "or tu %i gmch %i/%i link %i/%i, " \
11706 "found tu %i, gmch %i/%i link %i/%i)\n", \
11707 current_config->name.tu, \
11708 current_config->name.gmch_m, \
11709 current_config->name.gmch_n, \
11710 current_config->name.link_m, \
11711 current_config->name.link_n, \
11712 current_config->alt_name.tu, \
11713 current_config->alt_name.gmch_m, \
11714 current_config->alt_name.gmch_n, \
11715 current_config->alt_name.link_m, \
11716 current_config->alt_name.link_n, \
11717 pipe_config->name.tu, \
11718 pipe_config->name.gmch_m, \
11719 pipe_config->name.gmch_n, \
11720 pipe_config->name.link_m, \
11721 pipe_config->name.link_n); \
11725 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
11726 if ((current_config->name ^ pipe_config->name) & (mask)) { \
11727 pipe_config_err(adjust, __stringify(name), \
11728 "(%x) (expected %i, found %i)\n", \
11730 current_config->name & (mask), \
11731 pipe_config->name & (mask)); \
11735 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
11736 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
11737 pipe_config_err(adjust, __stringify(name), \
11738 "(expected %i, found %i)\n", \
11739 current_config->name, \
11740 pipe_config->name); \
11744 #define PIPE_CONF_QUIRK(quirk) \
11745 ((current_config->quirks | pipe_config->quirks) & (quirk))
11747 PIPE_CONF_CHECK_I(cpu_transcoder
);
11749 PIPE_CONF_CHECK_I(has_pch_encoder
);
11750 PIPE_CONF_CHECK_I(fdi_lanes
);
11751 PIPE_CONF_CHECK_M_N(fdi_m_n
);
11753 PIPE_CONF_CHECK_I(lane_count
);
11754 PIPE_CONF_CHECK_X(lane_lat_optim_mask
);
11756 if (INTEL_GEN(dev_priv
) < 8) {
11757 PIPE_CONF_CHECK_M_N(dp_m_n
);
11759 if (current_config
->has_drrs
)
11760 PIPE_CONF_CHECK_M_N(dp_m2_n2
);
11762 PIPE_CONF_CHECK_M_N_ALT(dp_m_n
, dp_m2_n2
);
11764 PIPE_CONF_CHECK_X(output_types
);
11766 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hdisplay
);
11767 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_htotal
);
11768 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_start
);
11769 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_end
);
11770 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_start
);
11771 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_end
);
11773 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vdisplay
);
11774 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vtotal
);
11775 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_start
);
11776 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_end
);
11777 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_start
);
11778 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_end
);
11780 PIPE_CONF_CHECK_I(pixel_multiplier
);
11781 PIPE_CONF_CHECK_I(has_hdmi_sink
);
11782 if ((INTEL_GEN(dev_priv
) < 8 && !IS_HASWELL(dev_priv
)) ||
11783 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
11784 PIPE_CONF_CHECK_I(limited_color_range
);
11785 PIPE_CONF_CHECK_I(has_infoframe
);
11787 PIPE_CONF_CHECK_I(has_audio
);
11789 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11790 DRM_MODE_FLAG_INTERLACE
);
11792 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
11793 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11794 DRM_MODE_FLAG_PHSYNC
);
11795 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11796 DRM_MODE_FLAG_NHSYNC
);
11797 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11798 DRM_MODE_FLAG_PVSYNC
);
11799 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11800 DRM_MODE_FLAG_NVSYNC
);
11803 PIPE_CONF_CHECK_X(gmch_pfit
.control
);
11804 /* pfit ratios are autocomputed by the hw on gen4+ */
11805 if (INTEL_GEN(dev_priv
) < 4)
11806 PIPE_CONF_CHECK_X(gmch_pfit
.pgm_ratios
);
11807 PIPE_CONF_CHECK_X(gmch_pfit
.lvds_border_bits
);
11810 PIPE_CONF_CHECK_I(pipe_src_w
);
11811 PIPE_CONF_CHECK_I(pipe_src_h
);
11813 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
11814 if (current_config
->pch_pfit
.enabled
) {
11815 PIPE_CONF_CHECK_X(pch_pfit
.pos
);
11816 PIPE_CONF_CHECK_X(pch_pfit
.size
);
11819 PIPE_CONF_CHECK_I(scaler_state
.scaler_id
);
11820 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate
);
11823 /* BDW+ don't expose a synchronous way to read the state */
11824 if (IS_HASWELL(dev_priv
))
11825 PIPE_CONF_CHECK_I(ips_enabled
);
11827 PIPE_CONF_CHECK_I(double_wide
);
11829 PIPE_CONF_CHECK_P(shared_dpll
);
11830 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
11831 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
11832 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
11833 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
11834 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
11835 PIPE_CONF_CHECK_X(dpll_hw_state
.spll
);
11836 PIPE_CONF_CHECK_X(dpll_hw_state
.ctrl1
);
11837 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr1
);
11838 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr2
);
11840 PIPE_CONF_CHECK_X(dsi_pll
.ctrl
);
11841 PIPE_CONF_CHECK_X(dsi_pll
.div
);
11843 if (IS_G4X(dev_priv
) || INTEL_GEN(dev_priv
) >= 5)
11844 PIPE_CONF_CHECK_I(pipe_bpp
);
11846 PIPE_CONF_CHECK_CLOCK_FUZZY(base
.adjusted_mode
.crtc_clock
);
11847 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
11849 #undef PIPE_CONF_CHECK_X
11850 #undef PIPE_CONF_CHECK_I
11851 #undef PIPE_CONF_CHECK_P
11852 #undef PIPE_CONF_CHECK_FLAGS
11853 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
11854 #undef PIPE_CONF_QUIRK
11859 static void intel_pipe_config_sanity_check(struct drm_i915_private
*dev_priv
,
11860 const struct intel_crtc_state
*pipe_config
)
11862 if (pipe_config
->has_pch_encoder
) {
11863 int fdi_dotclock
= intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
11864 &pipe_config
->fdi_m_n
);
11865 int dotclock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
11868 * FDI already provided one idea for the dotclock.
11869 * Yell if the encoder disagrees.
11871 WARN(!intel_fuzzy_clock_check(fdi_dotclock
, dotclock
),
11872 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11873 fdi_dotclock
, dotclock
);
11877 static void verify_wm_state(struct drm_crtc
*crtc
,
11878 struct drm_crtc_state
*new_state
)
11880 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
11881 struct skl_ddb_allocation hw_ddb
, *sw_ddb
;
11882 struct skl_pipe_wm hw_wm
, *sw_wm
;
11883 struct skl_plane_wm
*hw_plane_wm
, *sw_plane_wm
;
11884 struct skl_ddb_entry
*hw_ddb_entry
, *sw_ddb_entry
;
11885 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11886 const enum pipe pipe
= intel_crtc
->pipe
;
11887 int plane
, level
, max_level
= ilk_wm_max_level(dev_priv
);
11889 if (INTEL_GEN(dev_priv
) < 9 || !new_state
->active
)
11892 skl_pipe_wm_get_hw_state(crtc
, &hw_wm
);
11893 sw_wm
= &to_intel_crtc_state(new_state
)->wm
.skl
.optimal
;
11895 skl_ddb_get_hw_state(dev_priv
, &hw_ddb
);
11896 sw_ddb
= &dev_priv
->wm
.skl_hw
.ddb
;
11899 for_each_universal_plane(dev_priv
, pipe
, plane
) {
11900 hw_plane_wm
= &hw_wm
.planes
[plane
];
11901 sw_plane_wm
= &sw_wm
->planes
[plane
];
11904 for (level
= 0; level
<= max_level
; level
++) {
11905 if (skl_wm_level_equals(&hw_plane_wm
->wm
[level
],
11906 &sw_plane_wm
->wm
[level
]))
11909 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",
11910 pipe_name(pipe
), plane
+ 1, level
,
11911 sw_plane_wm
->wm
[level
].plane_en
,
11912 sw_plane_wm
->wm
[level
].plane_res_b
,
11913 sw_plane_wm
->wm
[level
].plane_res_l
,
11914 hw_plane_wm
->wm
[level
].plane_en
,
11915 hw_plane_wm
->wm
[level
].plane_res_b
,
11916 hw_plane_wm
->wm
[level
].plane_res_l
);
11919 if (!skl_wm_level_equals(&hw_plane_wm
->trans_wm
,
11920 &sw_plane_wm
->trans_wm
)) {
11921 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",
11922 pipe_name(pipe
), plane
+ 1,
11923 sw_plane_wm
->trans_wm
.plane_en
,
11924 sw_plane_wm
->trans_wm
.plane_res_b
,
11925 sw_plane_wm
->trans_wm
.plane_res_l
,
11926 hw_plane_wm
->trans_wm
.plane_en
,
11927 hw_plane_wm
->trans_wm
.plane_res_b
,
11928 hw_plane_wm
->trans_wm
.plane_res_l
);
11932 hw_ddb_entry
= &hw_ddb
.plane
[pipe
][plane
];
11933 sw_ddb_entry
= &sw_ddb
->plane
[pipe
][plane
];
11935 if (!skl_ddb_entry_equal(hw_ddb_entry
, sw_ddb_entry
)) {
11936 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
11937 pipe_name(pipe
), plane
+ 1,
11938 sw_ddb_entry
->start
, sw_ddb_entry
->end
,
11939 hw_ddb_entry
->start
, hw_ddb_entry
->end
);
11945 * If the cursor plane isn't active, we may not have updated it's ddb
11946 * allocation. In that case since the ddb allocation will be updated
11947 * once the plane becomes visible, we can skip this check
11949 if (intel_crtc
->cursor_addr
) {
11950 hw_plane_wm
= &hw_wm
.planes
[PLANE_CURSOR
];
11951 sw_plane_wm
= &sw_wm
->planes
[PLANE_CURSOR
];
11954 for (level
= 0; level
<= max_level
; level
++) {
11955 if (skl_wm_level_equals(&hw_plane_wm
->wm
[level
],
11956 &sw_plane_wm
->wm
[level
]))
11959 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",
11960 pipe_name(pipe
), level
,
11961 sw_plane_wm
->wm
[level
].plane_en
,
11962 sw_plane_wm
->wm
[level
].plane_res_b
,
11963 sw_plane_wm
->wm
[level
].plane_res_l
,
11964 hw_plane_wm
->wm
[level
].plane_en
,
11965 hw_plane_wm
->wm
[level
].plane_res_b
,
11966 hw_plane_wm
->wm
[level
].plane_res_l
);
11969 if (!skl_wm_level_equals(&hw_plane_wm
->trans_wm
,
11970 &sw_plane_wm
->trans_wm
)) {
11971 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11973 sw_plane_wm
->trans_wm
.plane_en
,
11974 sw_plane_wm
->trans_wm
.plane_res_b
,
11975 sw_plane_wm
->trans_wm
.plane_res_l
,
11976 hw_plane_wm
->trans_wm
.plane_en
,
11977 hw_plane_wm
->trans_wm
.plane_res_b
,
11978 hw_plane_wm
->trans_wm
.plane_res_l
);
11982 hw_ddb_entry
= &hw_ddb
.plane
[pipe
][PLANE_CURSOR
];
11983 sw_ddb_entry
= &sw_ddb
->plane
[pipe
][PLANE_CURSOR
];
11985 if (!skl_ddb_entry_equal(hw_ddb_entry
, sw_ddb_entry
)) {
11986 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
11988 sw_ddb_entry
->start
, sw_ddb_entry
->end
,
11989 hw_ddb_entry
->start
, hw_ddb_entry
->end
);
11995 verify_connector_state(struct drm_device
*dev
,
11996 struct drm_atomic_state
*state
,
11997 struct drm_crtc
*crtc
)
11999 struct drm_connector
*connector
;
12000 struct drm_connector_state
*new_conn_state
;
12003 for_each_new_connector_in_state(state
, connector
, new_conn_state
, i
) {
12004 struct drm_encoder
*encoder
= connector
->encoder
;
12006 if (new_conn_state
->crtc
!= crtc
)
12009 intel_connector_verify_state(to_intel_connector(connector
));
12011 I915_STATE_WARN(new_conn_state
->best_encoder
!= encoder
,
12012 "connector's atomic encoder doesn't match legacy encoder\n");
12017 verify_encoder_state(struct drm_device
*dev
, struct drm_atomic_state
*state
)
12019 struct intel_encoder
*encoder
;
12020 struct drm_connector
*connector
;
12021 struct drm_connector_state
*old_conn_state
, *new_conn_state
;
12024 for_each_intel_encoder(dev
, encoder
) {
12025 bool enabled
= false, found
= false;
12028 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
12029 encoder
->base
.base
.id
,
12030 encoder
->base
.name
);
12032 for_each_oldnew_connector_in_state(state
, connector
, old_conn_state
,
12033 new_conn_state
, i
) {
12034 if (old_conn_state
->best_encoder
== &encoder
->base
)
12037 if (new_conn_state
->best_encoder
!= &encoder
->base
)
12039 found
= enabled
= true;
12041 I915_STATE_WARN(new_conn_state
->crtc
!=
12042 encoder
->base
.crtc
,
12043 "connector's crtc doesn't match encoder crtc\n");
12049 I915_STATE_WARN(!!encoder
->base
.crtc
!= enabled
,
12050 "encoder's enabled state mismatch "
12051 "(expected %i, found %i)\n",
12052 !!encoder
->base
.crtc
, enabled
);
12054 if (!encoder
->base
.crtc
) {
12057 active
= encoder
->get_hw_state(encoder
, &pipe
);
12058 I915_STATE_WARN(active
,
12059 "encoder detached but still enabled on pipe %c.\n",
12066 verify_crtc_state(struct drm_crtc
*crtc
,
12067 struct drm_crtc_state
*old_crtc_state
,
12068 struct drm_crtc_state
*new_crtc_state
)
12070 struct drm_device
*dev
= crtc
->dev
;
12071 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12072 struct intel_encoder
*encoder
;
12073 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12074 struct intel_crtc_state
*pipe_config
, *sw_config
;
12075 struct drm_atomic_state
*old_state
;
12078 old_state
= old_crtc_state
->state
;
12079 __drm_atomic_helper_crtc_destroy_state(old_crtc_state
);
12080 pipe_config
= to_intel_crtc_state(old_crtc_state
);
12081 memset(pipe_config
, 0, sizeof(*pipe_config
));
12082 pipe_config
->base
.crtc
= crtc
;
12083 pipe_config
->base
.state
= old_state
;
12085 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc
->base
.id
, crtc
->name
);
12087 active
= dev_priv
->display
.get_pipe_config(intel_crtc
, pipe_config
);
12089 /* hw state is inconsistent with the pipe quirk */
12090 if ((intel_crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
12091 (intel_crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
12092 active
= new_crtc_state
->active
;
12094 I915_STATE_WARN(new_crtc_state
->active
!= active
,
12095 "crtc active state doesn't match with hw state "
12096 "(expected %i, found %i)\n", new_crtc_state
->active
, active
);
12098 I915_STATE_WARN(intel_crtc
->active
!= new_crtc_state
->active
,
12099 "transitional active state does not match atomic hw state "
12100 "(expected %i, found %i)\n", new_crtc_state
->active
, intel_crtc
->active
);
12102 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
12105 active
= encoder
->get_hw_state(encoder
, &pipe
);
12106 I915_STATE_WARN(active
!= new_crtc_state
->active
,
12107 "[ENCODER:%i] active %i with crtc active %i\n",
12108 encoder
->base
.base
.id
, active
, new_crtc_state
->active
);
12110 I915_STATE_WARN(active
&& intel_crtc
->pipe
!= pipe
,
12111 "Encoder connected to wrong pipe %c\n",
12115 pipe_config
->output_types
|= 1 << encoder
->type
;
12116 encoder
->get_config(encoder
, pipe_config
);
12120 intel_crtc_compute_pixel_rate(pipe_config
);
12122 if (!new_crtc_state
->active
)
12125 intel_pipe_config_sanity_check(dev_priv
, pipe_config
);
12127 sw_config
= to_intel_crtc_state(crtc
->state
);
12128 if (!intel_pipe_config_compare(dev_priv
, sw_config
,
12129 pipe_config
, false)) {
12130 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12131 intel_dump_pipe_config(intel_crtc
, pipe_config
,
12133 intel_dump_pipe_config(intel_crtc
, sw_config
,
12139 verify_single_dpll_state(struct drm_i915_private
*dev_priv
,
12140 struct intel_shared_dpll
*pll
,
12141 struct drm_crtc
*crtc
,
12142 struct drm_crtc_state
*new_state
)
12144 struct intel_dpll_hw_state dpll_hw_state
;
12145 unsigned crtc_mask
;
12148 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
12150 DRM_DEBUG_KMS("%s\n", pll
->name
);
12152 active
= pll
->funcs
.get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
12154 if (!(pll
->flags
& INTEL_DPLL_ALWAYS_ON
)) {
12155 I915_STATE_WARN(!pll
->on
&& pll
->active_mask
,
12156 "pll in active use but not on in sw tracking\n");
12157 I915_STATE_WARN(pll
->on
&& !pll
->active_mask
,
12158 "pll is on but not used by any active crtc\n");
12159 I915_STATE_WARN(pll
->on
!= active
,
12160 "pll on state mismatch (expected %i, found %i)\n",
12165 I915_STATE_WARN(pll
->active_mask
& ~pll
->state
.crtc_mask
,
12166 "more active pll users than references: %x vs %x\n",
12167 pll
->active_mask
, pll
->state
.crtc_mask
);
12172 crtc_mask
= 1 << drm_crtc_index(crtc
);
12174 if (new_state
->active
)
12175 I915_STATE_WARN(!(pll
->active_mask
& crtc_mask
),
12176 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
12177 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
12179 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
12180 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
12181 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
12183 I915_STATE_WARN(!(pll
->state
.crtc_mask
& crtc_mask
),
12184 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
12185 crtc_mask
, pll
->state
.crtc_mask
);
12187 I915_STATE_WARN(pll
->on
&& memcmp(&pll
->state
.hw_state
,
12189 sizeof(dpll_hw_state
)),
12190 "pll hw state mismatch\n");
12194 verify_shared_dpll_state(struct drm_device
*dev
, struct drm_crtc
*crtc
,
12195 struct drm_crtc_state
*old_crtc_state
,
12196 struct drm_crtc_state
*new_crtc_state
)
12198 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12199 struct intel_crtc_state
*old_state
= to_intel_crtc_state(old_crtc_state
);
12200 struct intel_crtc_state
*new_state
= to_intel_crtc_state(new_crtc_state
);
12202 if (new_state
->shared_dpll
)
12203 verify_single_dpll_state(dev_priv
, new_state
->shared_dpll
, crtc
, new_crtc_state
);
12205 if (old_state
->shared_dpll
&&
12206 old_state
->shared_dpll
!= new_state
->shared_dpll
) {
12207 unsigned crtc_mask
= 1 << drm_crtc_index(crtc
);
12208 struct intel_shared_dpll
*pll
= old_state
->shared_dpll
;
12210 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
12211 "pll active mismatch (didn't expect pipe %c in active mask)\n",
12212 pipe_name(drm_crtc_index(crtc
)));
12213 I915_STATE_WARN(pll
->state
.crtc_mask
& crtc_mask
,
12214 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
12215 pipe_name(drm_crtc_index(crtc
)));
12220 intel_modeset_verify_crtc(struct drm_crtc
*crtc
,
12221 struct drm_atomic_state
*state
,
12222 struct drm_crtc_state
*old_state
,
12223 struct drm_crtc_state
*new_state
)
12225 if (!needs_modeset(new_state
) &&
12226 !to_intel_crtc_state(new_state
)->update_pipe
)
12229 verify_wm_state(crtc
, new_state
);
12230 verify_connector_state(crtc
->dev
, state
, crtc
);
12231 verify_crtc_state(crtc
, old_state
, new_state
);
12232 verify_shared_dpll_state(crtc
->dev
, crtc
, old_state
, new_state
);
12236 verify_disabled_dpll_state(struct drm_device
*dev
)
12238 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12241 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++)
12242 verify_single_dpll_state(dev_priv
, &dev_priv
->shared_dplls
[i
], NULL
, NULL
);
12246 intel_modeset_verify_disabled(struct drm_device
*dev
,
12247 struct drm_atomic_state
*state
)
12249 verify_encoder_state(dev
, state
);
12250 verify_connector_state(dev
, state
, NULL
);
12251 verify_disabled_dpll_state(dev
);
12254 static void update_scanline_offset(struct intel_crtc
*crtc
)
12256 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
12259 * The scanline counter increments at the leading edge of hsync.
12261 * On most platforms it starts counting from vtotal-1 on the
12262 * first active line. That means the scanline counter value is
12263 * always one less than what we would expect. Ie. just after
12264 * start of vblank, which also occurs at start of hsync (on the
12265 * last active line), the scanline counter will read vblank_start-1.
12267 * On gen2 the scanline counter starts counting from 1 instead
12268 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12269 * to keep the value positive), instead of adding one.
12271 * On HSW+ the behaviour of the scanline counter depends on the output
12272 * type. For DP ports it behaves like most other platforms, but on HDMI
12273 * there's an extra 1 line difference. So we need to add two instead of
12274 * one to the value.
12276 if (IS_GEN2(dev_priv
)) {
12277 const struct drm_display_mode
*adjusted_mode
= &crtc
->config
->base
.adjusted_mode
;
12280 vtotal
= adjusted_mode
->crtc_vtotal
;
12281 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
12284 crtc
->scanline_offset
= vtotal
- 1;
12285 } else if (HAS_DDI(dev_priv
) &&
12286 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_HDMI
)) {
12287 crtc
->scanline_offset
= 2;
12289 crtc
->scanline_offset
= 1;
12292 static void intel_modeset_clear_plls(struct drm_atomic_state
*state
)
12294 struct drm_device
*dev
= state
->dev
;
12295 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12296 struct drm_crtc
*crtc
;
12297 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
12300 if (!dev_priv
->display
.crtc_compute_clock
)
12303 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12304 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12305 struct intel_shared_dpll
*old_dpll
=
12306 to_intel_crtc_state(old_crtc_state
)->shared_dpll
;
12308 if (!needs_modeset(new_crtc_state
))
12311 to_intel_crtc_state(new_crtc_state
)->shared_dpll
= NULL
;
12316 intel_release_shared_dpll(old_dpll
, intel_crtc
, state
);
12321 * This implements the workaround described in the "notes" section of the mode
12322 * set sequence documentation. When going from no pipes or single pipe to
12323 * multiple pipes, and planes are enabled after the pipe, we need to wait at
12324 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
12326 static int haswell_mode_set_planes_workaround(struct drm_atomic_state
*state
)
12328 struct drm_crtc_state
*crtc_state
;
12329 struct intel_crtc
*intel_crtc
;
12330 struct drm_crtc
*crtc
;
12331 struct intel_crtc_state
*first_crtc_state
= NULL
;
12332 struct intel_crtc_state
*other_crtc_state
= NULL
;
12333 enum pipe first_pipe
= INVALID_PIPE
, enabled_pipe
= INVALID_PIPE
;
12336 /* look at all crtc's that are going to be enabled in during modeset */
12337 for_each_new_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12338 intel_crtc
= to_intel_crtc(crtc
);
12340 if (!crtc_state
->active
|| !needs_modeset(crtc_state
))
12343 if (first_crtc_state
) {
12344 other_crtc_state
= to_intel_crtc_state(crtc_state
);
12347 first_crtc_state
= to_intel_crtc_state(crtc_state
);
12348 first_pipe
= intel_crtc
->pipe
;
12352 /* No workaround needed? */
12353 if (!first_crtc_state
)
12356 /* w/a possibly needed, check how many crtc's are already enabled. */
12357 for_each_intel_crtc(state
->dev
, intel_crtc
) {
12358 struct intel_crtc_state
*pipe_config
;
12360 pipe_config
= intel_atomic_get_crtc_state(state
, intel_crtc
);
12361 if (IS_ERR(pipe_config
))
12362 return PTR_ERR(pipe_config
);
12364 pipe_config
->hsw_workaround_pipe
= INVALID_PIPE
;
12366 if (!pipe_config
->base
.active
||
12367 needs_modeset(&pipe_config
->base
))
12370 /* 2 or more enabled crtcs means no need for w/a */
12371 if (enabled_pipe
!= INVALID_PIPE
)
12374 enabled_pipe
= intel_crtc
->pipe
;
12377 if (enabled_pipe
!= INVALID_PIPE
)
12378 first_crtc_state
->hsw_workaround_pipe
= enabled_pipe
;
12379 else if (other_crtc_state
)
12380 other_crtc_state
->hsw_workaround_pipe
= first_pipe
;
12385 static int intel_lock_all_pipes(struct drm_atomic_state
*state
)
12387 struct drm_crtc
*crtc
;
12389 /* Add all pipes to the state */
12390 for_each_crtc(state
->dev
, crtc
) {
12391 struct drm_crtc_state
*crtc_state
;
12393 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
12394 if (IS_ERR(crtc_state
))
12395 return PTR_ERR(crtc_state
);
12401 static int intel_modeset_all_pipes(struct drm_atomic_state
*state
)
12403 struct drm_crtc
*crtc
;
12406 * Add all pipes to the state, and force
12407 * a modeset on all the active ones.
12409 for_each_crtc(state
->dev
, crtc
) {
12410 struct drm_crtc_state
*crtc_state
;
12413 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
12414 if (IS_ERR(crtc_state
))
12415 return PTR_ERR(crtc_state
);
12417 if (!crtc_state
->active
|| needs_modeset(crtc_state
))
12420 crtc_state
->mode_changed
= true;
12422 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
12426 ret
= drm_atomic_add_affected_planes(state
, crtc
);
12434 static int intel_modeset_checks(struct drm_atomic_state
*state
)
12436 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12437 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
12438 struct drm_crtc
*crtc
;
12439 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
12442 if (!check_digital_port_conflicts(state
)) {
12443 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12447 intel_state
->modeset
= true;
12448 intel_state
->active_crtcs
= dev_priv
->active_crtcs
;
12449 intel_state
->cdclk
.logical
= dev_priv
->cdclk
.logical
;
12450 intel_state
->cdclk
.actual
= dev_priv
->cdclk
.actual
;
12452 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12453 if (new_crtc_state
->active
)
12454 intel_state
->active_crtcs
|= 1 << i
;
12456 intel_state
->active_crtcs
&= ~(1 << i
);
12458 if (old_crtc_state
->active
!= new_crtc_state
->active
)
12459 intel_state
->active_pipe_changes
|= drm_crtc_mask(crtc
);
12463 * See if the config requires any additional preparation, e.g.
12464 * to adjust global state with pipes off. We need to do this
12465 * here so we can get the modeset_pipe updated config for the new
12466 * mode set on this crtc. For other crtcs we need to use the
12467 * adjusted_mode bits in the crtc directly.
12469 if (dev_priv
->display
.modeset_calc_cdclk
) {
12470 ret
= dev_priv
->display
.modeset_calc_cdclk(state
);
12475 * Writes to dev_priv->cdclk.logical must protected by
12476 * holding all the crtc locks, even if we don't end up
12477 * touching the hardware
12479 if (!intel_cdclk_state_compare(&dev_priv
->cdclk
.logical
,
12480 &intel_state
->cdclk
.logical
)) {
12481 ret
= intel_lock_all_pipes(state
);
12486 /* All pipes must be switched off while we change the cdclk. */
12487 if (!intel_cdclk_state_compare(&dev_priv
->cdclk
.actual
,
12488 &intel_state
->cdclk
.actual
)) {
12489 ret
= intel_modeset_all_pipes(state
);
12494 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12495 intel_state
->cdclk
.logical
.cdclk
,
12496 intel_state
->cdclk
.actual
.cdclk
);
12498 to_intel_atomic_state(state
)->cdclk
.logical
= dev_priv
->cdclk
.logical
;
12501 intel_modeset_clear_plls(state
);
12503 if (IS_HASWELL(dev_priv
))
12504 return haswell_mode_set_planes_workaround(state
);
12510 * Handle calculation of various watermark data at the end of the atomic check
12511 * phase. The code here should be run after the per-crtc and per-plane 'check'
12512 * handlers to ensure that all derived state has been updated.
12514 static int calc_watermark_data(struct drm_atomic_state
*state
)
12516 struct drm_device
*dev
= state
->dev
;
12517 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12519 /* Is there platform-specific watermark information to calculate? */
12520 if (dev_priv
->display
.compute_global_watermarks
)
12521 return dev_priv
->display
.compute_global_watermarks(state
);
12527 * intel_atomic_check - validate state object
12529 * @state: state to validate
12531 static int intel_atomic_check(struct drm_device
*dev
,
12532 struct drm_atomic_state
*state
)
12534 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12535 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12536 struct drm_crtc
*crtc
;
12537 struct drm_crtc_state
*old_crtc_state
, *crtc_state
;
12539 bool any_ms
= false;
12541 ret
= drm_atomic_helper_check_modeset(dev
, state
);
12545 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, crtc_state
, i
) {
12546 struct intel_crtc_state
*pipe_config
=
12547 to_intel_crtc_state(crtc_state
);
12549 /* Catch I915_MODE_FLAG_INHERITED */
12550 if (crtc_state
->mode
.private_flags
!= old_crtc_state
->mode
.private_flags
)
12551 crtc_state
->mode_changed
= true;
12553 if (!needs_modeset(crtc_state
))
12556 if (!crtc_state
->enable
) {
12561 /* FIXME: For only active_changed we shouldn't need to do any
12562 * state recomputation at all. */
12564 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
12568 ret
= intel_modeset_pipe_config(crtc
, pipe_config
);
12570 intel_dump_pipe_config(to_intel_crtc(crtc
),
12571 pipe_config
, "[failed]");
12575 if (i915
.fastboot
&&
12576 intel_pipe_config_compare(dev_priv
,
12577 to_intel_crtc_state(old_crtc_state
),
12578 pipe_config
, true)) {
12579 crtc_state
->mode_changed
= false;
12580 pipe_config
->update_pipe
= true;
12583 if (needs_modeset(crtc_state
))
12586 ret
= drm_atomic_add_affected_planes(state
, crtc
);
12590 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
12591 needs_modeset(crtc_state
) ?
12592 "[modeset]" : "[fastset]");
12596 ret
= intel_modeset_checks(state
);
12601 intel_state
->cdclk
.logical
= dev_priv
->cdclk
.logical
;
12604 ret
= drm_atomic_helper_check_planes(dev
, state
);
12608 intel_fbc_choose_crtc(dev_priv
, state
);
12609 return calc_watermark_data(state
);
12612 static int intel_atomic_prepare_commit(struct drm_device
*dev
,
12613 struct drm_atomic_state
*state
)
12615 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12616 struct drm_crtc_state
*crtc_state
;
12617 struct drm_crtc
*crtc
;
12620 for_each_new_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12621 if (state
->legacy_cursor_update
)
12624 ret
= intel_crtc_wait_for_pending_flips(crtc
);
12628 if (atomic_read(&to_intel_crtc(crtc
)->unpin_work_count
) >= 2)
12629 flush_workqueue(dev_priv
->wq
);
12632 ret
= mutex_lock_interruptible(&dev
->struct_mutex
);
12636 ret
= drm_atomic_helper_prepare_planes(dev
, state
);
12637 mutex_unlock(&dev
->struct_mutex
);
12642 u32
intel_crtc_get_vblank_counter(struct intel_crtc
*crtc
)
12644 struct drm_device
*dev
= crtc
->base
.dev
;
12646 if (!dev
->max_vblank_count
)
12647 return drm_accurate_vblank_count(&crtc
->base
);
12649 return dev
->driver
->get_vblank_counter(dev
, crtc
->pipe
);
12652 static void intel_atomic_wait_for_vblanks(struct drm_device
*dev
,
12653 struct drm_i915_private
*dev_priv
,
12654 unsigned crtc_mask
)
12656 unsigned last_vblank_count
[I915_MAX_PIPES
];
12663 for_each_pipe(dev_priv
, pipe
) {
12664 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
,
12667 if (!((1 << pipe
) & crtc_mask
))
12670 ret
= drm_crtc_vblank_get(&crtc
->base
);
12671 if (WARN_ON(ret
!= 0)) {
12672 crtc_mask
&= ~(1 << pipe
);
12676 last_vblank_count
[pipe
] = drm_crtc_vblank_count(&crtc
->base
);
12679 for_each_pipe(dev_priv
, pipe
) {
12680 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
,
12684 if (!((1 << pipe
) & crtc_mask
))
12687 lret
= wait_event_timeout(dev
->vblank
[pipe
].queue
,
12688 last_vblank_count
[pipe
] !=
12689 drm_crtc_vblank_count(&crtc
->base
),
12690 msecs_to_jiffies(50));
12692 WARN(!lret
, "pipe %c vblank wait timed out\n", pipe_name(pipe
));
12694 drm_crtc_vblank_put(&crtc
->base
);
12698 static bool needs_vblank_wait(struct intel_crtc_state
*crtc_state
)
12700 /* fb updated, need to unpin old fb */
12701 if (crtc_state
->fb_changed
)
12704 /* wm changes, need vblank before final wm's */
12705 if (crtc_state
->update_wm_post
)
12708 if (crtc_state
->wm
.need_postvbl_update
)
12714 static void intel_update_crtc(struct drm_crtc
*crtc
,
12715 struct drm_atomic_state
*state
,
12716 struct drm_crtc_state
*old_crtc_state
,
12717 struct drm_crtc_state
*new_crtc_state
,
12718 unsigned int *crtc_vblank_mask
)
12720 struct drm_device
*dev
= crtc
->dev
;
12721 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12722 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12723 struct intel_crtc_state
*pipe_config
= to_intel_crtc_state(new_crtc_state
);
12724 bool modeset
= needs_modeset(new_crtc_state
);
12727 update_scanline_offset(intel_crtc
);
12728 dev_priv
->display
.crtc_enable(pipe_config
, state
);
12730 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
),
12734 if (drm_atomic_get_existing_plane_state(state
, crtc
->primary
)) {
12736 intel_crtc
, pipe_config
,
12737 to_intel_plane_state(crtc
->primary
->state
));
12740 drm_atomic_helper_commit_planes_on_crtc(old_crtc_state
);
12742 if (needs_vblank_wait(pipe_config
))
12743 *crtc_vblank_mask
|= drm_crtc_mask(crtc
);
12746 static void intel_update_crtcs(struct drm_atomic_state
*state
,
12747 unsigned int *crtc_vblank_mask
)
12749 struct drm_crtc
*crtc
;
12750 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
12753 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12754 if (!new_crtc_state
->active
)
12757 intel_update_crtc(crtc
, state
, old_crtc_state
,
12758 new_crtc_state
, crtc_vblank_mask
);
12762 static void skl_update_crtcs(struct drm_atomic_state
*state
,
12763 unsigned int *crtc_vblank_mask
)
12765 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
12766 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12767 struct drm_crtc
*crtc
;
12768 struct intel_crtc
*intel_crtc
;
12769 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
12770 struct intel_crtc_state
*cstate
;
12771 unsigned int updated
= 0;
12776 const struct skl_ddb_entry
*entries
[I915_MAX_PIPES
] = {};
12778 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
)
12779 /* ignore allocations for crtc's that have been turned off. */
12780 if (new_crtc_state
->active
)
12781 entries
[i
] = &to_intel_crtc_state(old_crtc_state
)->wm
.skl
.ddb
;
12784 * Whenever the number of active pipes changes, we need to make sure we
12785 * update the pipes in the right order so that their ddb allocations
12786 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
12787 * cause pipe underruns and other bad stuff.
12792 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12793 bool vbl_wait
= false;
12794 unsigned int cmask
= drm_crtc_mask(crtc
);
12796 intel_crtc
= to_intel_crtc(crtc
);
12797 cstate
= to_intel_crtc_state(crtc
->state
);
12798 pipe
= intel_crtc
->pipe
;
12800 if (updated
& cmask
|| !cstate
->base
.active
)
12803 if (skl_ddb_allocation_overlaps(entries
, &cstate
->wm
.skl
.ddb
, i
))
12807 entries
[i
] = &cstate
->wm
.skl
.ddb
;
12810 * If this is an already active pipe, it's DDB changed,
12811 * and this isn't the last pipe that needs updating
12812 * then we need to wait for a vblank to pass for the
12813 * new ddb allocation to take effect.
12815 if (!skl_ddb_entry_equal(&cstate
->wm
.skl
.ddb
,
12816 &to_intel_crtc_state(old_crtc_state
)->wm
.skl
.ddb
) &&
12817 !new_crtc_state
->active_changed
&&
12818 intel_state
->wm_results
.dirty_pipes
!= updated
)
12821 intel_update_crtc(crtc
, state
, old_crtc_state
,
12822 new_crtc_state
, crtc_vblank_mask
);
12825 intel_wait_for_vblank(dev_priv
, pipe
);
12829 } while (progress
);
12832 static void intel_atomic_helper_free_state(struct drm_i915_private
*dev_priv
)
12834 struct intel_atomic_state
*state
, *next
;
12835 struct llist_node
*freed
;
12837 freed
= llist_del_all(&dev_priv
->atomic_helper
.free_list
);
12838 llist_for_each_entry_safe(state
, next
, freed
, freed
)
12839 drm_atomic_state_put(&state
->base
);
12842 static void intel_atomic_helper_free_state_worker(struct work_struct
*work
)
12844 struct drm_i915_private
*dev_priv
=
12845 container_of(work
, typeof(*dev_priv
), atomic_helper
.free_work
);
12847 intel_atomic_helper_free_state(dev_priv
);
12850 static void intel_atomic_commit_tail(struct drm_atomic_state
*state
)
12852 struct drm_device
*dev
= state
->dev
;
12853 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12854 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12855 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
12856 struct drm_crtc
*crtc
;
12857 struct intel_crtc_state
*intel_cstate
;
12858 bool hw_check
= intel_state
->modeset
;
12859 u64 put_domains
[I915_MAX_PIPES
] = {};
12860 unsigned crtc_vblank_mask
= 0;
12863 drm_atomic_helper_wait_for_dependencies(state
);
12865 if (intel_state
->modeset
)
12866 intel_display_power_get(dev_priv
, POWER_DOMAIN_MODESET
);
12868 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12869 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12871 if (needs_modeset(new_crtc_state
) ||
12872 to_intel_crtc_state(new_crtc_state
)->update_pipe
) {
12875 put_domains
[to_intel_crtc(crtc
)->pipe
] =
12876 modeset_get_crtc_power_domains(crtc
,
12877 to_intel_crtc_state(new_crtc_state
));
12880 if (!needs_modeset(new_crtc_state
))
12883 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
),
12884 to_intel_crtc_state(new_crtc_state
));
12886 if (old_crtc_state
->active
) {
12887 intel_crtc_disable_planes(crtc
, old_crtc_state
->plane_mask
);
12888 dev_priv
->display
.crtc_disable(to_intel_crtc_state(old_crtc_state
), state
);
12889 intel_crtc
->active
= false;
12890 intel_fbc_disable(intel_crtc
);
12891 intel_disable_shared_dpll(intel_crtc
);
12894 * Underruns don't always raise
12895 * interrupts, so check manually.
12897 intel_check_cpu_fifo_underruns(dev_priv
);
12898 intel_check_pch_fifo_underruns(dev_priv
);
12900 if (!crtc
->state
->active
) {
12902 * Make sure we don't call initial_watermarks
12903 * for ILK-style watermark updates.
12905 * No clue what this is supposed to achieve.
12907 if (INTEL_GEN(dev_priv
) >= 9)
12908 dev_priv
->display
.initial_watermarks(intel_state
,
12909 to_intel_crtc_state(crtc
->state
));
12914 /* Only after disabling all output pipelines that will be changed can we
12915 * update the the output configuration. */
12916 intel_modeset_update_crtc_state(state
);
12918 if (intel_state
->modeset
) {
12919 drm_atomic_helper_update_legacy_modeset_state(state
->dev
, state
);
12921 intel_set_cdclk(dev_priv
, &dev_priv
->cdclk
.actual
);
12924 * SKL workaround: bspec recommends we disable the SAGV when we
12925 * have more then one pipe enabled
12927 if (!intel_can_enable_sagv(state
))
12928 intel_disable_sagv(dev_priv
);
12930 intel_modeset_verify_disabled(dev
, state
);
12933 /* Complete the events for pipes that have now been disabled */
12934 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
12935 bool modeset
= needs_modeset(new_crtc_state
);
12937 /* Complete events for now disable pipes here. */
12938 if (modeset
&& !new_crtc_state
->active
&& new_crtc_state
->event
) {
12939 spin_lock_irq(&dev
->event_lock
);
12940 drm_crtc_send_vblank_event(crtc
, new_crtc_state
->event
);
12941 spin_unlock_irq(&dev
->event_lock
);
12943 new_crtc_state
->event
= NULL
;
12947 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
12948 dev_priv
->display
.update_crtcs(state
, &crtc_vblank_mask
);
12950 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
12951 * already, but still need the state for the delayed optimization. To
12953 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
12954 * - schedule that vblank worker _before_ calling hw_done
12955 * - at the start of commit_tail, cancel it _synchrously
12956 * - switch over to the vblank wait helper in the core after that since
12957 * we don't need out special handling any more.
12959 if (!state
->legacy_cursor_update
)
12960 intel_atomic_wait_for_vblanks(dev
, dev_priv
, crtc_vblank_mask
);
12963 * Now that the vblank has passed, we can go ahead and program the
12964 * optimal watermarks on platforms that need two-step watermark
12967 * TODO: Move this (and other cleanup) to an async worker eventually.
12969 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
12970 intel_cstate
= to_intel_crtc_state(new_crtc_state
);
12972 if (dev_priv
->display
.optimize_watermarks
)
12973 dev_priv
->display
.optimize_watermarks(intel_state
,
12977 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12978 intel_post_plane_update(to_intel_crtc_state(old_crtc_state
));
12980 if (put_domains
[i
])
12981 modeset_put_power_domains(dev_priv
, put_domains
[i
]);
12983 intel_modeset_verify_crtc(crtc
, state
, old_crtc_state
, new_crtc_state
);
12986 if (intel_state
->modeset
&& intel_can_enable_sagv(state
))
12987 intel_enable_sagv(dev_priv
);
12989 drm_atomic_helper_commit_hw_done(state
);
12991 if (intel_state
->modeset
)
12992 intel_display_power_put(dev_priv
, POWER_DOMAIN_MODESET
);
12994 mutex_lock(&dev
->struct_mutex
);
12995 drm_atomic_helper_cleanup_planes(dev
, state
);
12996 mutex_unlock(&dev
->struct_mutex
);
12998 drm_atomic_helper_commit_cleanup_done(state
);
13000 drm_atomic_state_put(state
);
13002 /* As one of the primary mmio accessors, KMS has a high likelihood
13003 * of triggering bugs in unclaimed access. After we finish
13004 * modesetting, see if an error has been flagged, and if so
13005 * enable debugging for the next modeset - and hope we catch
13008 * XXX note that we assume display power is on at this point.
13009 * This might hold true now but we need to add pm helper to check
13010 * unclaimed only when the hardware is on, as atomic commits
13011 * can happen also when the device is completely off.
13013 intel_uncore_arm_unclaimed_mmio_detection(dev_priv
);
13015 intel_atomic_helper_free_state(dev_priv
);
13018 static void intel_atomic_commit_work(struct work_struct
*work
)
13020 struct drm_atomic_state
*state
=
13021 container_of(work
, struct drm_atomic_state
, commit_work
);
13023 intel_atomic_commit_tail(state
);
13026 static int __i915_sw_fence_call
13027 intel_atomic_commit_ready(struct i915_sw_fence
*fence
,
13028 enum i915_sw_fence_notify notify
)
13030 struct intel_atomic_state
*state
=
13031 container_of(fence
, struct intel_atomic_state
, commit_ready
);
13034 case FENCE_COMPLETE
:
13035 if (state
->base
.commit_work
.func
)
13036 queue_work(system_unbound_wq
, &state
->base
.commit_work
);
13041 struct intel_atomic_helper
*helper
=
13042 &to_i915(state
->base
.dev
)->atomic_helper
;
13044 if (llist_add(&state
->freed
, &helper
->free_list
))
13045 schedule_work(&helper
->free_work
);
13050 return NOTIFY_DONE
;
13053 static void intel_atomic_track_fbs(struct drm_atomic_state
*state
)
13055 struct drm_plane_state
*old_plane_state
, *new_plane_state
;
13056 struct drm_plane
*plane
;
13059 for_each_oldnew_plane_in_state(state
, plane
, old_plane_state
, new_plane_state
, i
)
13060 i915_gem_track_fb(intel_fb_obj(old_plane_state
->fb
),
13061 intel_fb_obj(new_plane_state
->fb
),
13062 to_intel_plane(plane
)->frontbuffer_bit
);
13066 * intel_atomic_commit - commit validated state object
13068 * @state: the top-level driver state object
13069 * @nonblock: nonblocking commit
13071 * This function commits a top-level state object that has been validated
13072 * with drm_atomic_helper_check().
13075 * Zero for success or -errno.
13077 static int intel_atomic_commit(struct drm_device
*dev
,
13078 struct drm_atomic_state
*state
,
13081 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
13082 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13086 * The intel_legacy_cursor_update() fast path takes care
13087 * of avoiding the vblank waits for simple cursor
13088 * movement and flips. For cursor on/off and size changes,
13089 * we want to perform the vblank waits so that watermark
13090 * updates happen during the correct frames. Gen9+ have
13091 * double buffered watermarks and so shouldn't need this.
13093 if (INTEL_GEN(dev_priv
) < 9)
13094 state
->legacy_cursor_update
= false;
13096 ret
= drm_atomic_helper_setup_commit(state
, nonblock
);
13100 drm_atomic_state_get(state
);
13101 i915_sw_fence_init(&intel_state
->commit_ready
,
13102 intel_atomic_commit_ready
);
13104 ret
= intel_atomic_prepare_commit(dev
, state
);
13106 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret
);
13107 i915_sw_fence_commit(&intel_state
->commit_ready
);
13111 drm_atomic_helper_swap_state(state
, true);
13112 dev_priv
->wm
.distrust_bios_wm
= false;
13113 intel_shared_dpll_swap_state(state
);
13114 intel_atomic_track_fbs(state
);
13116 if (intel_state
->modeset
) {
13117 memcpy(dev_priv
->min_pixclk
, intel_state
->min_pixclk
,
13118 sizeof(intel_state
->min_pixclk
));
13119 dev_priv
->active_crtcs
= intel_state
->active_crtcs
;
13120 dev_priv
->cdclk
.logical
= intel_state
->cdclk
.logical
;
13121 dev_priv
->cdclk
.actual
= intel_state
->cdclk
.actual
;
13124 drm_atomic_state_get(state
);
13125 INIT_WORK(&state
->commit_work
,
13126 nonblock
? intel_atomic_commit_work
: NULL
);
13128 i915_sw_fence_commit(&intel_state
->commit_ready
);
13130 i915_sw_fence_wait(&intel_state
->commit_ready
);
13131 intel_atomic_commit_tail(state
);
13137 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
13139 struct drm_device
*dev
= crtc
->dev
;
13140 struct drm_atomic_state
*state
;
13141 struct drm_crtc_state
*crtc_state
;
13144 state
= drm_atomic_state_alloc(dev
);
13146 DRM_DEBUG_KMS("[CRTC:%d:%s] crtc restore failed, out of memory",
13147 crtc
->base
.id
, crtc
->name
);
13151 state
->acquire_ctx
= drm_modeset_legacy_acquire_ctx(crtc
);
13154 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
13155 ret
= PTR_ERR_OR_ZERO(crtc_state
);
13157 if (!crtc_state
->active
)
13160 crtc_state
->mode_changed
= true;
13161 ret
= drm_atomic_commit(state
);
13164 if (ret
== -EDEADLK
) {
13165 drm_atomic_state_clear(state
);
13166 drm_modeset_backoff(state
->acquire_ctx
);
13171 drm_atomic_state_put(state
);
13175 * FIXME: Remove this once i915 is fully DRIVER_ATOMIC by calling
13176 * drm_atomic_helper_legacy_gamma_set() directly.
13178 static int intel_atomic_legacy_gamma_set(struct drm_crtc
*crtc
,
13179 u16
*red
, u16
*green
, u16
*blue
,
13182 struct drm_device
*dev
= crtc
->dev
;
13183 struct drm_mode_config
*config
= &dev
->mode_config
;
13184 struct drm_crtc_state
*state
;
13187 ret
= drm_atomic_helper_legacy_gamma_set(crtc
, red
, green
, blue
, size
);
13192 * Make sure we update the legacy properties so this works when
13193 * atomic is not enabled.
13196 state
= crtc
->state
;
13198 drm_object_property_set_value(&crtc
->base
,
13199 config
->degamma_lut_property
,
13200 (state
->degamma_lut
) ?
13201 state
->degamma_lut
->base
.id
: 0);
13203 drm_object_property_set_value(&crtc
->base
,
13204 config
->ctm_property
,
13206 state
->ctm
->base
.id
: 0);
13208 drm_object_property_set_value(&crtc
->base
,
13209 config
->gamma_lut_property
,
13210 (state
->gamma_lut
) ?
13211 state
->gamma_lut
->base
.id
: 0);
13216 static const struct drm_crtc_funcs intel_crtc_funcs
= {
13217 .gamma_set
= intel_atomic_legacy_gamma_set
,
13218 .set_config
= drm_atomic_helper_set_config
,
13219 .set_property
= drm_atomic_helper_crtc_set_property
,
13220 .destroy
= intel_crtc_destroy
,
13221 .page_flip
= drm_atomic_helper_page_flip
,
13222 .atomic_duplicate_state
= intel_crtc_duplicate_state
,
13223 .atomic_destroy_state
= intel_crtc_destroy_state
,
13224 .set_crc_source
= intel_crtc_set_crc_source
,
13228 * intel_prepare_plane_fb - Prepare fb for usage on plane
13229 * @plane: drm plane to prepare for
13230 * @fb: framebuffer to prepare for presentation
13232 * Prepares a framebuffer for usage on a display plane. Generally this
13233 * involves pinning the underlying object and updating the frontbuffer tracking
13234 * bits. Some older platforms need special physical address handling for
13237 * Must be called with struct_mutex held.
13239 * Returns 0 on success, negative error code on failure.
13242 intel_prepare_plane_fb(struct drm_plane
*plane
,
13243 struct drm_plane_state
*new_state
)
13245 struct intel_atomic_state
*intel_state
=
13246 to_intel_atomic_state(new_state
->state
);
13247 struct drm_i915_private
*dev_priv
= to_i915(plane
->dev
);
13248 struct drm_framebuffer
*fb
= new_state
->fb
;
13249 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13250 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->state
->fb
);
13254 if (plane
->type
== DRM_PLANE_TYPE_CURSOR
&&
13255 INTEL_INFO(dev_priv
)->cursor_needs_physical
) {
13256 const int align
= IS_I830(dev_priv
) ? 16 * 1024 : 256;
13258 ret
= i915_gem_object_attach_phys(obj
, align
);
13260 DRM_DEBUG_KMS("failed to attach phys object\n");
13264 struct i915_vma
*vma
;
13266 vma
= intel_pin_and_fence_fb_obj(fb
, new_state
->rotation
);
13268 DRM_DEBUG_KMS("failed to pin object\n");
13269 return PTR_ERR(vma
);
13272 to_intel_plane_state(new_state
)->vma
= vma
;
13276 if (!obj
&& !old_obj
)
13280 struct drm_crtc_state
*crtc_state
=
13281 drm_atomic_get_existing_crtc_state(new_state
->state
,
13282 plane
->state
->crtc
);
13284 /* Big Hammer, we also need to ensure that any pending
13285 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
13286 * current scanout is retired before unpinning the old
13287 * framebuffer. Note that we rely on userspace rendering
13288 * into the buffer attached to the pipe they are waiting
13289 * on. If not, userspace generates a GPU hang with IPEHR
13290 * point to the MI_WAIT_FOR_EVENT.
13292 * This should only fail upon a hung GPU, in which case we
13293 * can safely continue.
13295 if (needs_modeset(crtc_state
)) {
13296 ret
= i915_sw_fence_await_reservation(&intel_state
->commit_ready
,
13297 old_obj
->resv
, NULL
,
13305 if (new_state
->fence
) { /* explicit fencing */
13306 ret
= i915_sw_fence_await_dma_fence(&intel_state
->commit_ready
,
13308 I915_FENCE_TIMEOUT
,
13317 if (!new_state
->fence
) { /* implicit fencing */
13318 ret
= i915_sw_fence_await_reservation(&intel_state
->commit_ready
,
13320 false, I915_FENCE_TIMEOUT
,
13325 i915_gem_object_wait_priority(obj
, 0, I915_PRIORITY_DISPLAY
);
13332 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13333 * @plane: drm plane to clean up for
13334 * @fb: old framebuffer that was on plane
13336 * Cleans up a framebuffer that has just been removed from a plane.
13338 * Must be called with struct_mutex held.
13341 intel_cleanup_plane_fb(struct drm_plane
*plane
,
13342 struct drm_plane_state
*old_state
)
13344 struct i915_vma
*vma
;
13346 /* Should only be called after a successful intel_prepare_plane_fb()! */
13347 vma
= fetch_and_zero(&to_intel_plane_state(old_state
)->vma
);
13349 intel_unpin_fb_vma(vma
);
13353 skl_max_scale(struct intel_crtc
*intel_crtc
, struct intel_crtc_state
*crtc_state
)
13355 struct drm_i915_private
*dev_priv
;
13357 int crtc_clock
, max_dotclk
;
13359 if (!intel_crtc
|| !crtc_state
->base
.enable
)
13360 return DRM_PLANE_HELPER_NO_SCALING
;
13362 dev_priv
= to_i915(intel_crtc
->base
.dev
);
13364 crtc_clock
= crtc_state
->base
.adjusted_mode
.crtc_clock
;
13365 max_dotclk
= to_intel_atomic_state(crtc_state
->base
.state
)->cdclk
.logical
.cdclk
;
13367 if (IS_GEMINILAKE(dev_priv
))
13370 if (WARN_ON_ONCE(!crtc_clock
|| max_dotclk
< crtc_clock
))
13371 return DRM_PLANE_HELPER_NO_SCALING
;
13374 * skl max scale is lower of:
13375 * close to 3 but not 3, -1 is for that purpose
13379 max_scale
= min((1 << 16) * 3 - 1,
13380 (1 << 8) * ((max_dotclk
<< 8) / crtc_clock
));
13386 intel_check_primary_plane(struct drm_plane
*plane
,
13387 struct intel_crtc_state
*crtc_state
,
13388 struct intel_plane_state
*state
)
13390 struct drm_i915_private
*dev_priv
= to_i915(plane
->dev
);
13391 struct drm_crtc
*crtc
= state
->base
.crtc
;
13392 int min_scale
= DRM_PLANE_HELPER_NO_SCALING
;
13393 int max_scale
= DRM_PLANE_HELPER_NO_SCALING
;
13394 bool can_position
= false;
13397 if (INTEL_GEN(dev_priv
) >= 9) {
13398 /* use scaler when colorkey is not required */
13399 if (state
->ckey
.flags
== I915_SET_COLORKEY_NONE
) {
13401 max_scale
= skl_max_scale(to_intel_crtc(crtc
), crtc_state
);
13403 can_position
= true;
13406 ret
= drm_plane_helper_check_state(&state
->base
,
13408 min_scale
, max_scale
,
13409 can_position
, true);
13413 if (!state
->base
.fb
)
13416 if (INTEL_GEN(dev_priv
) >= 9) {
13417 ret
= skl_check_plane_surface(state
);
13425 static void intel_begin_crtc_commit(struct drm_crtc
*crtc
,
13426 struct drm_crtc_state
*old_crtc_state
)
13428 struct drm_device
*dev
= crtc
->dev
;
13429 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13430 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13431 struct intel_crtc_state
*intel_cstate
=
13432 to_intel_crtc_state(crtc
->state
);
13433 struct intel_crtc_state
*old_intel_cstate
=
13434 to_intel_crtc_state(old_crtc_state
);
13435 struct intel_atomic_state
*old_intel_state
=
13436 to_intel_atomic_state(old_crtc_state
->state
);
13437 bool modeset
= needs_modeset(crtc
->state
);
13440 (intel_cstate
->base
.color_mgmt_changed
||
13441 intel_cstate
->update_pipe
)) {
13442 intel_color_set_csc(crtc
->state
);
13443 intel_color_load_luts(crtc
->state
);
13446 /* Perform vblank evasion around commit operation */
13447 intel_pipe_update_start(intel_crtc
);
13452 if (intel_cstate
->update_pipe
)
13453 intel_update_pipe_config(intel_crtc
, old_intel_cstate
);
13454 else if (INTEL_GEN(dev_priv
) >= 9)
13455 skl_detach_scalers(intel_crtc
);
13458 if (dev_priv
->display
.atomic_update_watermarks
)
13459 dev_priv
->display
.atomic_update_watermarks(old_intel_state
,
13463 static void intel_finish_crtc_commit(struct drm_crtc
*crtc
,
13464 struct drm_crtc_state
*old_crtc_state
)
13466 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13468 intel_pipe_update_end(intel_crtc
, NULL
);
13472 * intel_plane_destroy - destroy a plane
13473 * @plane: plane to destroy
13475 * Common destruction function for all types of planes (primary, cursor,
13478 void intel_plane_destroy(struct drm_plane
*plane
)
13480 drm_plane_cleanup(plane
);
13481 kfree(to_intel_plane(plane
));
13484 const struct drm_plane_funcs intel_plane_funcs
= {
13485 .update_plane
= drm_atomic_helper_update_plane
,
13486 .disable_plane
= drm_atomic_helper_disable_plane
,
13487 .destroy
= intel_plane_destroy
,
13488 .set_property
= drm_atomic_helper_plane_set_property
,
13489 .atomic_get_property
= intel_plane_atomic_get_property
,
13490 .atomic_set_property
= intel_plane_atomic_set_property
,
13491 .atomic_duplicate_state
= intel_plane_duplicate_state
,
13492 .atomic_destroy_state
= intel_plane_destroy_state
,
13496 intel_legacy_cursor_update(struct drm_plane
*plane
,
13497 struct drm_crtc
*crtc
,
13498 struct drm_framebuffer
*fb
,
13499 int crtc_x
, int crtc_y
,
13500 unsigned int crtc_w
, unsigned int crtc_h
,
13501 uint32_t src_x
, uint32_t src_y
,
13502 uint32_t src_w
, uint32_t src_h
)
13504 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
13506 struct drm_plane_state
*old_plane_state
, *new_plane_state
;
13507 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
13508 struct drm_framebuffer
*old_fb
;
13509 struct drm_crtc_state
*crtc_state
= crtc
->state
;
13510 struct i915_vma
*old_vma
;
13513 * When crtc is inactive or there is a modeset pending,
13514 * wait for it to complete in the slowpath
13516 if (!crtc_state
->active
|| needs_modeset(crtc_state
) ||
13517 to_intel_crtc_state(crtc_state
)->update_pipe
)
13520 old_plane_state
= plane
->state
;
13523 * If any parameters change that may affect watermarks,
13524 * take the slowpath. Only changing fb or position should be
13527 if (old_plane_state
->crtc
!= crtc
||
13528 old_plane_state
->src_w
!= src_w
||
13529 old_plane_state
->src_h
!= src_h
||
13530 old_plane_state
->crtc_w
!= crtc_w
||
13531 old_plane_state
->crtc_h
!= crtc_h
||
13532 !old_plane_state
->fb
!= !fb
)
13535 new_plane_state
= intel_plane_duplicate_state(plane
);
13536 if (!new_plane_state
)
13539 drm_atomic_set_fb_for_plane(new_plane_state
, fb
);
13541 new_plane_state
->src_x
= src_x
;
13542 new_plane_state
->src_y
= src_y
;
13543 new_plane_state
->src_w
= src_w
;
13544 new_plane_state
->src_h
= src_h
;
13545 new_plane_state
->crtc_x
= crtc_x
;
13546 new_plane_state
->crtc_y
= crtc_y
;
13547 new_plane_state
->crtc_w
= crtc_w
;
13548 new_plane_state
->crtc_h
= crtc_h
;
13550 ret
= intel_plane_atomic_check_with_state(to_intel_crtc_state(crtc
->state
),
13551 to_intel_plane_state(new_plane_state
));
13555 ret
= mutex_lock_interruptible(&dev_priv
->drm
.struct_mutex
);
13559 if (INTEL_INFO(dev_priv
)->cursor_needs_physical
) {
13560 int align
= IS_I830(dev_priv
) ? 16 * 1024 : 256;
13562 ret
= i915_gem_object_attach_phys(intel_fb_obj(fb
), align
);
13564 DRM_DEBUG_KMS("failed to attach phys object\n");
13568 struct i915_vma
*vma
;
13570 vma
= intel_pin_and_fence_fb_obj(fb
, new_plane_state
->rotation
);
13572 DRM_DEBUG_KMS("failed to pin object\n");
13574 ret
= PTR_ERR(vma
);
13578 to_intel_plane_state(new_plane_state
)->vma
= vma
;
13581 old_fb
= old_plane_state
->fb
;
13582 old_vma
= to_intel_plane_state(old_plane_state
)->vma
;
13584 i915_gem_track_fb(intel_fb_obj(old_fb
), intel_fb_obj(fb
),
13585 intel_plane
->frontbuffer_bit
);
13587 /* Swap plane state */
13588 new_plane_state
->fence
= old_plane_state
->fence
;
13589 *to_intel_plane_state(old_plane_state
) = *to_intel_plane_state(new_plane_state
);
13590 new_plane_state
->fence
= NULL
;
13591 new_plane_state
->fb
= old_fb
;
13592 to_intel_plane_state(new_plane_state
)->vma
= old_vma
;
13594 if (plane
->state
->visible
) {
13595 trace_intel_update_plane(plane
, to_intel_crtc(crtc
));
13596 intel_plane
->update_plane(plane
,
13597 to_intel_crtc_state(crtc
->state
),
13598 to_intel_plane_state(plane
->state
));
13600 trace_intel_disable_plane(plane
, to_intel_crtc(crtc
));
13601 intel_plane
->disable_plane(plane
, crtc
);
13604 intel_cleanup_plane_fb(plane
, new_plane_state
);
13607 mutex_unlock(&dev_priv
->drm
.struct_mutex
);
13609 intel_plane_destroy_state(plane
, new_plane_state
);
13613 return drm_atomic_helper_update_plane(plane
, crtc
, fb
,
13614 crtc_x
, crtc_y
, crtc_w
, crtc_h
,
13615 src_x
, src_y
, src_w
, src_h
);
13618 static const struct drm_plane_funcs intel_cursor_plane_funcs
= {
13619 .update_plane
= intel_legacy_cursor_update
,
13620 .disable_plane
= drm_atomic_helper_disable_plane
,
13621 .destroy
= intel_plane_destroy
,
13622 .set_property
= drm_atomic_helper_plane_set_property
,
13623 .atomic_get_property
= intel_plane_atomic_get_property
,
13624 .atomic_set_property
= intel_plane_atomic_set_property
,
13625 .atomic_duplicate_state
= intel_plane_duplicate_state
,
13626 .atomic_destroy_state
= intel_plane_destroy_state
,
13629 static struct intel_plane
*
13630 intel_primary_plane_create(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
13632 struct intel_plane
*primary
= NULL
;
13633 struct intel_plane_state
*state
= NULL
;
13634 const uint32_t *intel_primary_formats
;
13635 unsigned int supported_rotations
;
13636 unsigned int num_formats
;
13639 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
13645 state
= intel_create_plane_state(&primary
->base
);
13651 primary
->base
.state
= &state
->base
;
13653 primary
->can_scale
= false;
13654 primary
->max_downscale
= 1;
13655 if (INTEL_GEN(dev_priv
) >= 9) {
13656 primary
->can_scale
= true;
13657 state
->scaler_id
= -1;
13659 primary
->pipe
= pipe
;
13661 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
13662 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
13664 if (HAS_FBC(dev_priv
) && INTEL_GEN(dev_priv
) < 4)
13665 primary
->plane
= (enum plane
) !pipe
;
13667 primary
->plane
= (enum plane
) pipe
;
13668 primary
->id
= PLANE_PRIMARY
;
13669 primary
->frontbuffer_bit
= INTEL_FRONTBUFFER_PRIMARY(pipe
);
13670 primary
->check_plane
= intel_check_primary_plane
;
13672 if (INTEL_GEN(dev_priv
) >= 9) {
13673 intel_primary_formats
= skl_primary_formats
;
13674 num_formats
= ARRAY_SIZE(skl_primary_formats
);
13676 primary
->update_plane
= skylake_update_primary_plane
;
13677 primary
->disable_plane
= skylake_disable_primary_plane
;
13678 } else if (HAS_PCH_SPLIT(dev_priv
)) {
13679 intel_primary_formats
= i965_primary_formats
;
13680 num_formats
= ARRAY_SIZE(i965_primary_formats
);
13682 primary
->update_plane
= ironlake_update_primary_plane
;
13683 primary
->disable_plane
= i9xx_disable_primary_plane
;
13684 } else if (INTEL_GEN(dev_priv
) >= 4) {
13685 intel_primary_formats
= i965_primary_formats
;
13686 num_formats
= ARRAY_SIZE(i965_primary_formats
);
13688 primary
->update_plane
= i9xx_update_primary_plane
;
13689 primary
->disable_plane
= i9xx_disable_primary_plane
;
13691 intel_primary_formats
= i8xx_primary_formats
;
13692 num_formats
= ARRAY_SIZE(i8xx_primary_formats
);
13694 primary
->update_plane
= i9xx_update_primary_plane
;
13695 primary
->disable_plane
= i9xx_disable_primary_plane
;
13698 if (INTEL_GEN(dev_priv
) >= 9)
13699 ret
= drm_universal_plane_init(&dev_priv
->drm
, &primary
->base
,
13700 0, &intel_plane_funcs
,
13701 intel_primary_formats
, num_formats
,
13702 DRM_PLANE_TYPE_PRIMARY
,
13703 "plane 1%c", pipe_name(pipe
));
13704 else if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
))
13705 ret
= drm_universal_plane_init(&dev_priv
->drm
, &primary
->base
,
13706 0, &intel_plane_funcs
,
13707 intel_primary_formats
, num_formats
,
13708 DRM_PLANE_TYPE_PRIMARY
,
13709 "primary %c", pipe_name(pipe
));
13711 ret
= drm_universal_plane_init(&dev_priv
->drm
, &primary
->base
,
13712 0, &intel_plane_funcs
,
13713 intel_primary_formats
, num_formats
,
13714 DRM_PLANE_TYPE_PRIMARY
,
13715 "plane %c", plane_name(primary
->plane
));
13719 if (INTEL_GEN(dev_priv
) >= 9) {
13720 supported_rotations
=
13721 DRM_ROTATE_0
| DRM_ROTATE_90
|
13722 DRM_ROTATE_180
| DRM_ROTATE_270
;
13723 } else if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_B
) {
13724 supported_rotations
=
13725 DRM_ROTATE_0
| DRM_ROTATE_180
|
13727 } else if (INTEL_GEN(dev_priv
) >= 4) {
13728 supported_rotations
=
13729 DRM_ROTATE_0
| DRM_ROTATE_180
;
13731 supported_rotations
= DRM_ROTATE_0
;
13734 if (INTEL_GEN(dev_priv
) >= 4)
13735 drm_plane_create_rotation_property(&primary
->base
,
13737 supported_rotations
);
13739 drm_plane_helper_add(&primary
->base
, &intel_plane_helper_funcs
);
13747 return ERR_PTR(ret
);
13751 intel_check_cursor_plane(struct drm_plane
*plane
,
13752 struct intel_crtc_state
*crtc_state
,
13753 struct intel_plane_state
*state
)
13755 struct drm_framebuffer
*fb
= state
->base
.fb
;
13756 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13757 enum pipe pipe
= to_intel_plane(plane
)->pipe
;
13761 ret
= drm_plane_helper_check_state(&state
->base
,
13763 DRM_PLANE_HELPER_NO_SCALING
,
13764 DRM_PLANE_HELPER_NO_SCALING
,
13769 /* if we want to turn off the cursor ignore width and height */
13773 /* Check for which cursor types we support */
13774 if (!cursor_size_ok(to_i915(plane
->dev
), state
->base
.crtc_w
,
13775 state
->base
.crtc_h
)) {
13776 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
13777 state
->base
.crtc_w
, state
->base
.crtc_h
);
13781 stride
= roundup_pow_of_two(state
->base
.crtc_w
) * 4;
13782 if (obj
->base
.size
< stride
* state
->base
.crtc_h
) {
13783 DRM_DEBUG_KMS("buffer is too small\n");
13787 if (fb
->modifier
!= DRM_FORMAT_MOD_NONE
) {
13788 DRM_DEBUG_KMS("cursor cannot be tiled\n");
13793 * There's something wrong with the cursor on CHV pipe C.
13794 * If it straddles the left edge of the screen then
13795 * moving it away from the edge or disabling it often
13796 * results in a pipe underrun, and often that can lead to
13797 * dead pipe (constant underrun reported, and it scans
13798 * out just a solid color). To recover from that, the
13799 * display power well must be turned off and on again.
13800 * Refuse the put the cursor into that compromised position.
13802 if (IS_CHERRYVIEW(to_i915(plane
->dev
)) && pipe
== PIPE_C
&&
13803 state
->base
.visible
&& state
->base
.crtc_x
< 0) {
13804 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
13812 intel_disable_cursor_plane(struct drm_plane
*plane
,
13813 struct drm_crtc
*crtc
)
13815 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13817 intel_crtc
->cursor_addr
= 0;
13818 intel_crtc_update_cursor(crtc
, NULL
, NULL
);
13822 intel_update_cursor_plane(struct drm_plane
*plane
,
13823 const struct intel_crtc_state
*crtc_state
,
13824 const struct intel_plane_state
*state
)
13826 struct drm_crtc
*crtc
= crtc_state
->base
.crtc
;
13827 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13828 struct drm_i915_private
*dev_priv
= to_i915(plane
->dev
);
13829 struct drm_i915_gem_object
*obj
= intel_fb_obj(state
->base
.fb
);
13834 else if (!INTEL_INFO(dev_priv
)->cursor_needs_physical
)
13835 addr
= intel_plane_ggtt_offset(state
);
13837 addr
= obj
->phys_handle
->busaddr
;
13839 intel_crtc
->cursor_addr
= addr
;
13840 intel_crtc_update_cursor(crtc
, crtc_state
, state
);
13843 static struct intel_plane
*
13844 intel_cursor_plane_create(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
13846 struct intel_plane
*cursor
= NULL
;
13847 struct intel_plane_state
*state
= NULL
;
13850 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
13856 state
= intel_create_plane_state(&cursor
->base
);
13862 cursor
->base
.state
= &state
->base
;
13864 cursor
->can_scale
= false;
13865 cursor
->max_downscale
= 1;
13866 cursor
->pipe
= pipe
;
13867 cursor
->plane
= pipe
;
13868 cursor
->id
= PLANE_CURSOR
;
13869 cursor
->frontbuffer_bit
= INTEL_FRONTBUFFER_CURSOR(pipe
);
13870 cursor
->check_plane
= intel_check_cursor_plane
;
13871 cursor
->update_plane
= intel_update_cursor_plane
;
13872 cursor
->disable_plane
= intel_disable_cursor_plane
;
13874 ret
= drm_universal_plane_init(&dev_priv
->drm
, &cursor
->base
,
13875 0, &intel_cursor_plane_funcs
,
13876 intel_cursor_formats
,
13877 ARRAY_SIZE(intel_cursor_formats
),
13878 DRM_PLANE_TYPE_CURSOR
,
13879 "cursor %c", pipe_name(pipe
));
13883 if (INTEL_GEN(dev_priv
) >= 4)
13884 drm_plane_create_rotation_property(&cursor
->base
,
13889 if (INTEL_GEN(dev_priv
) >= 9)
13890 state
->scaler_id
= -1;
13892 drm_plane_helper_add(&cursor
->base
, &intel_plane_helper_funcs
);
13900 return ERR_PTR(ret
);
13903 static void intel_crtc_init_scalers(struct intel_crtc
*crtc
,
13904 struct intel_crtc_state
*crtc_state
)
13906 struct intel_crtc_scaler_state
*scaler_state
=
13907 &crtc_state
->scaler_state
;
13908 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
13911 crtc
->num_scalers
= dev_priv
->info
.num_scalers
[crtc
->pipe
];
13912 if (!crtc
->num_scalers
)
13915 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
13916 struct intel_scaler
*scaler
= &scaler_state
->scalers
[i
];
13918 scaler
->in_use
= 0;
13919 scaler
->mode
= PS_SCALER_MODE_DYN
;
13922 scaler_state
->scaler_id
= -1;
13925 static int intel_crtc_init(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
13927 struct intel_crtc
*intel_crtc
;
13928 struct intel_crtc_state
*crtc_state
= NULL
;
13929 struct intel_plane
*primary
= NULL
;
13930 struct intel_plane
*cursor
= NULL
;
13933 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
13937 crtc_state
= kzalloc(sizeof(*crtc_state
), GFP_KERNEL
);
13942 intel_crtc
->config
= crtc_state
;
13943 intel_crtc
->base
.state
= &crtc_state
->base
;
13944 crtc_state
->base
.crtc
= &intel_crtc
->base
;
13946 primary
= intel_primary_plane_create(dev_priv
, pipe
);
13947 if (IS_ERR(primary
)) {
13948 ret
= PTR_ERR(primary
);
13951 intel_crtc
->plane_ids_mask
|= BIT(primary
->id
);
13953 for_each_sprite(dev_priv
, pipe
, sprite
) {
13954 struct intel_plane
*plane
;
13956 plane
= intel_sprite_plane_create(dev_priv
, pipe
, sprite
);
13957 if (IS_ERR(plane
)) {
13958 ret
= PTR_ERR(plane
);
13961 intel_crtc
->plane_ids_mask
|= BIT(plane
->id
);
13964 cursor
= intel_cursor_plane_create(dev_priv
, pipe
);
13965 if (IS_ERR(cursor
)) {
13966 ret
= PTR_ERR(cursor
);
13969 intel_crtc
->plane_ids_mask
|= BIT(cursor
->id
);
13971 ret
= drm_crtc_init_with_planes(&dev_priv
->drm
, &intel_crtc
->base
,
13972 &primary
->base
, &cursor
->base
,
13974 "pipe %c", pipe_name(pipe
));
13978 intel_crtc
->pipe
= pipe
;
13979 intel_crtc
->plane
= primary
->plane
;
13981 intel_crtc
->cursor_base
= ~0;
13982 intel_crtc
->cursor_cntl
= ~0;
13983 intel_crtc
->cursor_size
= ~0;
13985 /* initialize shared scalers */
13986 intel_crtc_init_scalers(intel_crtc
, crtc_state
);
13988 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
13989 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
13990 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = intel_crtc
;
13991 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = intel_crtc
;
13993 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
13995 intel_color_init(&intel_crtc
->base
);
13997 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
14003 * drm_mode_config_cleanup() will free up any
14004 * crtcs/planes already initialized.
14012 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
14014 struct drm_device
*dev
= connector
->base
.dev
;
14016 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
14018 if (!connector
->base
.state
->crtc
)
14019 return INVALID_PIPE
;
14021 return to_intel_crtc(connector
->base
.state
->crtc
)->pipe
;
14024 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
14025 struct drm_file
*file
)
14027 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
14028 struct drm_crtc
*drmmode_crtc
;
14029 struct intel_crtc
*crtc
;
14031 drmmode_crtc
= drm_crtc_find(dev
, pipe_from_crtc_id
->crtc_id
);
14035 crtc
= to_intel_crtc(drmmode_crtc
);
14036 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
14041 static int intel_encoder_clones(struct intel_encoder
*encoder
)
14043 struct drm_device
*dev
= encoder
->base
.dev
;
14044 struct intel_encoder
*source_encoder
;
14045 int index_mask
= 0;
14048 for_each_intel_encoder(dev
, source_encoder
) {
14049 if (encoders_cloneable(encoder
, source_encoder
))
14050 index_mask
|= (1 << entry
);
14058 static bool has_edp_a(struct drm_i915_private
*dev_priv
)
14060 if (!IS_MOBILE(dev_priv
))
14063 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
14066 if (IS_GEN5(dev_priv
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
14072 static bool intel_crt_present(struct drm_i915_private
*dev_priv
)
14074 if (INTEL_GEN(dev_priv
) >= 9)
14077 if (IS_HSW_ULT(dev_priv
) || IS_BDW_ULT(dev_priv
))
14080 if (IS_CHERRYVIEW(dev_priv
))
14083 if (HAS_PCH_LPT_H(dev_priv
) &&
14084 I915_READ(SFUSE_STRAP
) & SFUSE_STRAP_CRT_DISABLED
)
14087 /* DDI E can't be used if DDI A requires 4 lanes */
14088 if (HAS_DDI(dev_priv
) && I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_A_4_LANES
)
14091 if (!dev_priv
->vbt
.int_crt_support
)
14097 void intel_pps_unlock_regs_wa(struct drm_i915_private
*dev_priv
)
14102 if (HAS_DDI(dev_priv
))
14105 * This w/a is needed at least on CPT/PPT, but to be sure apply it
14106 * everywhere where registers can be write protected.
14108 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
14113 for (pps_idx
= 0; pps_idx
< pps_num
; pps_idx
++) {
14114 u32 val
= I915_READ(PP_CONTROL(pps_idx
));
14116 val
= (val
& ~PANEL_UNLOCK_MASK
) | PANEL_UNLOCK_REGS
;
14117 I915_WRITE(PP_CONTROL(pps_idx
), val
);
14121 static void intel_pps_init(struct drm_i915_private
*dev_priv
)
14123 if (HAS_PCH_SPLIT(dev_priv
) || IS_GEN9_LP(dev_priv
))
14124 dev_priv
->pps_mmio_base
= PCH_PPS_BASE
;
14125 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
14126 dev_priv
->pps_mmio_base
= VLV_PPS_BASE
;
14128 dev_priv
->pps_mmio_base
= PPS_BASE
;
14130 intel_pps_unlock_regs_wa(dev_priv
);
14133 static void intel_setup_outputs(struct drm_i915_private
*dev_priv
)
14135 struct intel_encoder
*encoder
;
14136 bool dpd_is_edp
= false;
14138 intel_pps_init(dev_priv
);
14141 * intel_edp_init_connector() depends on this completing first, to
14142 * prevent the registeration of both eDP and LVDS and the incorrect
14143 * sharing of the PPS.
14145 intel_lvds_init(dev_priv
);
14147 if (intel_crt_present(dev_priv
))
14148 intel_crt_init(dev_priv
);
14150 if (IS_GEN9_LP(dev_priv
)) {
14152 * FIXME: Broxton doesn't support port detection via the
14153 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
14154 * detect the ports.
14156 intel_ddi_init(dev_priv
, PORT_A
);
14157 intel_ddi_init(dev_priv
, PORT_B
);
14158 intel_ddi_init(dev_priv
, PORT_C
);
14160 intel_dsi_init(dev_priv
);
14161 } else if (HAS_DDI(dev_priv
)) {
14165 * Haswell uses DDI functions to detect digital outputs.
14166 * On SKL pre-D0 the strap isn't connected, so we assume
14169 found
= I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_INIT_DISPLAY_DETECTED
;
14170 /* WaIgnoreDDIAStrap: skl */
14171 if (found
|| IS_GEN9_BC(dev_priv
))
14172 intel_ddi_init(dev_priv
, PORT_A
);
14174 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
14176 found
= I915_READ(SFUSE_STRAP
);
14178 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
14179 intel_ddi_init(dev_priv
, PORT_B
);
14180 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
14181 intel_ddi_init(dev_priv
, PORT_C
);
14182 if (found
& SFUSE_STRAP_DDID_DETECTED
)
14183 intel_ddi_init(dev_priv
, PORT_D
);
14185 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14187 if (IS_GEN9_BC(dev_priv
) &&
14188 (dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dp
||
14189 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dvi
||
14190 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_hdmi
))
14191 intel_ddi_init(dev_priv
, PORT_E
);
14193 } else if (HAS_PCH_SPLIT(dev_priv
)) {
14195 dpd_is_edp
= intel_dp_is_edp(dev_priv
, PORT_D
);
14197 if (has_edp_a(dev_priv
))
14198 intel_dp_init(dev_priv
, DP_A
, PORT_A
);
14200 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
14201 /* PCH SDVOB multiplex with HDMIB */
14202 found
= intel_sdvo_init(dev_priv
, PCH_SDVOB
, PORT_B
);
14204 intel_hdmi_init(dev_priv
, PCH_HDMIB
, PORT_B
);
14205 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
14206 intel_dp_init(dev_priv
, PCH_DP_B
, PORT_B
);
14209 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
14210 intel_hdmi_init(dev_priv
, PCH_HDMIC
, PORT_C
);
14212 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
14213 intel_hdmi_init(dev_priv
, PCH_HDMID
, PORT_D
);
14215 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
14216 intel_dp_init(dev_priv
, PCH_DP_C
, PORT_C
);
14218 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
14219 intel_dp_init(dev_priv
, PCH_DP_D
, PORT_D
);
14220 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
14221 bool has_edp
, has_port
;
14224 * The DP_DETECTED bit is the latched state of the DDC
14225 * SDA pin at boot. However since eDP doesn't require DDC
14226 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14227 * eDP ports may have been muxed to an alternate function.
14228 * Thus we can't rely on the DP_DETECTED bit alone to detect
14229 * eDP ports. Consult the VBT as well as DP_DETECTED to
14230 * detect eDP ports.
14232 * Sadly the straps seem to be missing sometimes even for HDMI
14233 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
14234 * and VBT for the presence of the port. Additionally we can't
14235 * trust the port type the VBT declares as we've seen at least
14236 * HDMI ports that the VBT claim are DP or eDP.
14238 has_edp
= intel_dp_is_edp(dev_priv
, PORT_B
);
14239 has_port
= intel_bios_is_port_present(dev_priv
, PORT_B
);
14240 if (I915_READ(VLV_DP_B
) & DP_DETECTED
|| has_port
)
14241 has_edp
&= intel_dp_init(dev_priv
, VLV_DP_B
, PORT_B
);
14242 if ((I915_READ(VLV_HDMIB
) & SDVO_DETECTED
|| has_port
) && !has_edp
)
14243 intel_hdmi_init(dev_priv
, VLV_HDMIB
, PORT_B
);
14245 has_edp
= intel_dp_is_edp(dev_priv
, PORT_C
);
14246 has_port
= intel_bios_is_port_present(dev_priv
, PORT_C
);
14247 if (I915_READ(VLV_DP_C
) & DP_DETECTED
|| has_port
)
14248 has_edp
&= intel_dp_init(dev_priv
, VLV_DP_C
, PORT_C
);
14249 if ((I915_READ(VLV_HDMIC
) & SDVO_DETECTED
|| has_port
) && !has_edp
)
14250 intel_hdmi_init(dev_priv
, VLV_HDMIC
, PORT_C
);
14252 if (IS_CHERRYVIEW(dev_priv
)) {
14254 * eDP not supported on port D,
14255 * so no need to worry about it
14257 has_port
= intel_bios_is_port_present(dev_priv
, PORT_D
);
14258 if (I915_READ(CHV_DP_D
) & DP_DETECTED
|| has_port
)
14259 intel_dp_init(dev_priv
, CHV_DP_D
, PORT_D
);
14260 if (I915_READ(CHV_HDMID
) & SDVO_DETECTED
|| has_port
)
14261 intel_hdmi_init(dev_priv
, CHV_HDMID
, PORT_D
);
14264 intel_dsi_init(dev_priv
);
14265 } else if (!IS_GEN2(dev_priv
) && !IS_PINEVIEW(dev_priv
)) {
14266 bool found
= false;
14268 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
14269 DRM_DEBUG_KMS("probing SDVOB\n");
14270 found
= intel_sdvo_init(dev_priv
, GEN3_SDVOB
, PORT_B
);
14271 if (!found
&& IS_G4X(dev_priv
)) {
14272 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
14273 intel_hdmi_init(dev_priv
, GEN4_HDMIB
, PORT_B
);
14276 if (!found
&& IS_G4X(dev_priv
))
14277 intel_dp_init(dev_priv
, DP_B
, PORT_B
);
14280 /* Before G4X SDVOC doesn't have its own detect register */
14282 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
14283 DRM_DEBUG_KMS("probing SDVOC\n");
14284 found
= intel_sdvo_init(dev_priv
, GEN3_SDVOC
, PORT_C
);
14287 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
14289 if (IS_G4X(dev_priv
)) {
14290 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
14291 intel_hdmi_init(dev_priv
, GEN4_HDMIC
, PORT_C
);
14293 if (IS_G4X(dev_priv
))
14294 intel_dp_init(dev_priv
, DP_C
, PORT_C
);
14297 if (IS_G4X(dev_priv
) && (I915_READ(DP_D
) & DP_DETECTED
))
14298 intel_dp_init(dev_priv
, DP_D
, PORT_D
);
14299 } else if (IS_GEN2(dev_priv
))
14300 intel_dvo_init(dev_priv
);
14302 if (SUPPORTS_TV(dev_priv
))
14303 intel_tv_init(dev_priv
);
14305 intel_psr_init(dev_priv
);
14307 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
14308 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
14309 encoder
->base
.possible_clones
=
14310 intel_encoder_clones(encoder
);
14313 intel_init_pch_refclk(dev_priv
);
14315 drm_helper_move_panel_connectors_to_head(&dev_priv
->drm
);
14318 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
14320 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
14322 drm_framebuffer_cleanup(fb
);
14324 i915_gem_object_lock(intel_fb
->obj
);
14325 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
14326 i915_gem_object_unlock(intel_fb
->obj
);
14328 i915_gem_object_put(intel_fb
->obj
);
14333 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
14334 struct drm_file
*file
,
14335 unsigned int *handle
)
14337 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
14338 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
14340 if (obj
->userptr
.mm
) {
14341 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14345 return drm_gem_handle_create(file
, &obj
->base
, handle
);
14348 static int intel_user_framebuffer_dirty(struct drm_framebuffer
*fb
,
14349 struct drm_file
*file
,
14350 unsigned flags
, unsigned color
,
14351 struct drm_clip_rect
*clips
,
14352 unsigned num_clips
)
14354 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
14356 i915_gem_object_flush_if_display(obj
);
14357 intel_fb_obj_flush(obj
, ORIGIN_DIRTYFB
);
14362 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
14363 .destroy
= intel_user_framebuffer_destroy
,
14364 .create_handle
= intel_user_framebuffer_create_handle
,
14365 .dirty
= intel_user_framebuffer_dirty
,
14369 u32
intel_fb_pitch_limit(struct drm_i915_private
*dev_priv
,
14370 uint64_t fb_modifier
, uint32_t pixel_format
)
14372 u32 gen
= INTEL_GEN(dev_priv
);
14375 int cpp
= drm_format_plane_cpp(pixel_format
, 0);
14377 /* "The stride in bytes must not exceed the of the size of 8K
14378 * pixels and 32K bytes."
14380 return min(8192 * cpp
, 32768);
14381 } else if (gen
>= 5 && !HAS_GMCH_DISPLAY(dev_priv
)) {
14383 } else if (gen
>= 4) {
14384 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
14388 } else if (gen
>= 3) {
14389 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
14394 /* XXX DSPC is limited to 4k tiled */
14399 static int intel_framebuffer_init(struct intel_framebuffer
*intel_fb
,
14400 struct drm_i915_gem_object
*obj
,
14401 struct drm_mode_fb_cmd2
*mode_cmd
)
14403 struct drm_i915_private
*dev_priv
= to_i915(obj
->base
.dev
);
14404 struct drm_format_name_buf format_name
;
14405 u32 pitch_limit
, stride_alignment
;
14406 unsigned int tiling
, stride
;
14409 i915_gem_object_lock(obj
);
14410 obj
->framebuffer_references
++;
14411 tiling
= i915_gem_object_get_tiling(obj
);
14412 stride
= i915_gem_object_get_stride(obj
);
14413 i915_gem_object_unlock(obj
);
14415 if (mode_cmd
->flags
& DRM_MODE_FB_MODIFIERS
) {
14417 * If there's a fence, enforce that
14418 * the fb modifier and tiling mode match.
14420 if (tiling
!= I915_TILING_NONE
&&
14421 tiling
!= intel_fb_modifier_to_tiling(mode_cmd
->modifier
[0])) {
14422 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
14426 if (tiling
== I915_TILING_X
) {
14427 mode_cmd
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
14428 } else if (tiling
== I915_TILING_Y
) {
14429 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
14434 /* Passed in modifier sanity checking. */
14435 switch (mode_cmd
->modifier
[0]) {
14436 case I915_FORMAT_MOD_Y_TILED
:
14437 case I915_FORMAT_MOD_Yf_TILED
:
14438 if (INTEL_GEN(dev_priv
) < 9) {
14439 DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n",
14440 mode_cmd
->modifier
[0]);
14443 case DRM_FORMAT_MOD_NONE
:
14444 case I915_FORMAT_MOD_X_TILED
:
14447 DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n",
14448 mode_cmd
->modifier
[0]);
14453 * gen2/3 display engine uses the fence if present,
14454 * so the tiling mode must match the fb modifier exactly.
14456 if (INTEL_INFO(dev_priv
)->gen
< 4 &&
14457 tiling
!= intel_fb_modifier_to_tiling(mode_cmd
->modifier
[0])) {
14458 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
14462 pitch_limit
= intel_fb_pitch_limit(dev_priv
, mode_cmd
->modifier
[0],
14463 mode_cmd
->pixel_format
);
14464 if (mode_cmd
->pitches
[0] > pitch_limit
) {
14465 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
14466 mode_cmd
->modifier
[0] != DRM_FORMAT_MOD_NONE
?
14467 "tiled" : "linear",
14468 mode_cmd
->pitches
[0], pitch_limit
);
14473 * If there's a fence, enforce that
14474 * the fb pitch and fence stride match.
14476 if (tiling
!= I915_TILING_NONE
&& mode_cmd
->pitches
[0] != stride
) {
14477 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
14478 mode_cmd
->pitches
[0], stride
);
14482 /* Reject formats not supported by any plane early. */
14483 switch (mode_cmd
->pixel_format
) {
14484 case DRM_FORMAT_C8
:
14485 case DRM_FORMAT_RGB565
:
14486 case DRM_FORMAT_XRGB8888
:
14487 case DRM_FORMAT_ARGB8888
:
14489 case DRM_FORMAT_XRGB1555
:
14490 if (INTEL_GEN(dev_priv
) > 3) {
14491 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14492 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
14496 case DRM_FORMAT_ABGR8888
:
14497 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
) &&
14498 INTEL_GEN(dev_priv
) < 9) {
14499 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14500 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
14504 case DRM_FORMAT_XBGR8888
:
14505 case DRM_FORMAT_XRGB2101010
:
14506 case DRM_FORMAT_XBGR2101010
:
14507 if (INTEL_GEN(dev_priv
) < 4) {
14508 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14509 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
14513 case DRM_FORMAT_ABGR2101010
:
14514 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
)) {
14515 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14516 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
14520 case DRM_FORMAT_YUYV
:
14521 case DRM_FORMAT_UYVY
:
14522 case DRM_FORMAT_YVYU
:
14523 case DRM_FORMAT_VYUY
:
14524 if (INTEL_GEN(dev_priv
) < 5) {
14525 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14526 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
14531 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14532 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
14536 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14537 if (mode_cmd
->offsets
[0] != 0)
14540 drm_helper_mode_fill_fb_struct(&dev_priv
->drm
,
14541 &intel_fb
->base
, mode_cmd
);
14543 stride_alignment
= intel_fb_stride_alignment(&intel_fb
->base
, 0);
14544 if (mode_cmd
->pitches
[0] & (stride_alignment
- 1)) {
14545 DRM_DEBUG_KMS("pitch (%d) must be at least %u byte aligned\n",
14546 mode_cmd
->pitches
[0], stride_alignment
);
14550 intel_fb
->obj
= obj
;
14552 ret
= intel_fill_fb_info(dev_priv
, &intel_fb
->base
);
14556 ret
= drm_framebuffer_init(obj
->base
.dev
,
14560 DRM_ERROR("framebuffer init failed %d\n", ret
);
14567 i915_gem_object_lock(obj
);
14568 obj
->framebuffer_references
--;
14569 i915_gem_object_unlock(obj
);
14573 static struct drm_framebuffer
*
14574 intel_user_framebuffer_create(struct drm_device
*dev
,
14575 struct drm_file
*filp
,
14576 const struct drm_mode_fb_cmd2
*user_mode_cmd
)
14578 struct drm_framebuffer
*fb
;
14579 struct drm_i915_gem_object
*obj
;
14580 struct drm_mode_fb_cmd2 mode_cmd
= *user_mode_cmd
;
14582 obj
= i915_gem_object_lookup(filp
, mode_cmd
.handles
[0]);
14584 return ERR_PTR(-ENOENT
);
14586 fb
= intel_framebuffer_create(obj
, &mode_cmd
);
14588 i915_gem_object_put(obj
);
14593 static void intel_atomic_state_free(struct drm_atomic_state
*state
)
14595 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
14597 drm_atomic_state_default_release(state
);
14599 i915_sw_fence_fini(&intel_state
->commit_ready
);
14604 static const struct drm_mode_config_funcs intel_mode_funcs
= {
14605 .fb_create
= intel_user_framebuffer_create
,
14606 .output_poll_changed
= intel_fbdev_output_poll_changed
,
14607 .atomic_check
= intel_atomic_check
,
14608 .atomic_commit
= intel_atomic_commit
,
14609 .atomic_state_alloc
= intel_atomic_state_alloc
,
14610 .atomic_state_clear
= intel_atomic_state_clear
,
14611 .atomic_state_free
= intel_atomic_state_free
,
14615 * intel_init_display_hooks - initialize the display modesetting hooks
14616 * @dev_priv: device private
14618 void intel_init_display_hooks(struct drm_i915_private
*dev_priv
)
14620 intel_init_cdclk_hooks(dev_priv
);
14622 if (INTEL_INFO(dev_priv
)->gen
>= 9) {
14623 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
14624 dev_priv
->display
.get_initial_plane_config
=
14625 skylake_get_initial_plane_config
;
14626 dev_priv
->display
.crtc_compute_clock
=
14627 haswell_crtc_compute_clock
;
14628 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
14629 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
14630 } else if (HAS_DDI(dev_priv
)) {
14631 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
14632 dev_priv
->display
.get_initial_plane_config
=
14633 ironlake_get_initial_plane_config
;
14634 dev_priv
->display
.crtc_compute_clock
=
14635 haswell_crtc_compute_clock
;
14636 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
14637 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
14638 } else if (HAS_PCH_SPLIT(dev_priv
)) {
14639 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
14640 dev_priv
->display
.get_initial_plane_config
=
14641 ironlake_get_initial_plane_config
;
14642 dev_priv
->display
.crtc_compute_clock
=
14643 ironlake_crtc_compute_clock
;
14644 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
14645 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
14646 } else if (IS_CHERRYVIEW(dev_priv
)) {
14647 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14648 dev_priv
->display
.get_initial_plane_config
=
14649 i9xx_get_initial_plane_config
;
14650 dev_priv
->display
.crtc_compute_clock
= chv_crtc_compute_clock
;
14651 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
14652 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14653 } else if (IS_VALLEYVIEW(dev_priv
)) {
14654 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14655 dev_priv
->display
.get_initial_plane_config
=
14656 i9xx_get_initial_plane_config
;
14657 dev_priv
->display
.crtc_compute_clock
= vlv_crtc_compute_clock
;
14658 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
14659 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14660 } else if (IS_G4X(dev_priv
)) {
14661 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14662 dev_priv
->display
.get_initial_plane_config
=
14663 i9xx_get_initial_plane_config
;
14664 dev_priv
->display
.crtc_compute_clock
= g4x_crtc_compute_clock
;
14665 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14666 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14667 } else if (IS_PINEVIEW(dev_priv
)) {
14668 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14669 dev_priv
->display
.get_initial_plane_config
=
14670 i9xx_get_initial_plane_config
;
14671 dev_priv
->display
.crtc_compute_clock
= pnv_crtc_compute_clock
;
14672 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14673 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14674 } else if (!IS_GEN2(dev_priv
)) {
14675 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14676 dev_priv
->display
.get_initial_plane_config
=
14677 i9xx_get_initial_plane_config
;
14678 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
14679 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14680 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14682 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14683 dev_priv
->display
.get_initial_plane_config
=
14684 i9xx_get_initial_plane_config
;
14685 dev_priv
->display
.crtc_compute_clock
= i8xx_crtc_compute_clock
;
14686 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14687 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14690 if (IS_GEN5(dev_priv
)) {
14691 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
14692 } else if (IS_GEN6(dev_priv
)) {
14693 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
14694 } else if (IS_IVYBRIDGE(dev_priv
)) {
14695 /* FIXME: detect B0+ stepping and use auto training */
14696 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
14697 } else if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
14698 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
14701 if (dev_priv
->info
.gen
>= 9)
14702 dev_priv
->display
.update_crtcs
= skl_update_crtcs
;
14704 dev_priv
->display
.update_crtcs
= intel_update_crtcs
;
14706 switch (INTEL_INFO(dev_priv
)->gen
) {
14708 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
14712 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
14717 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
14721 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
14724 case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
14725 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
14728 /* Drop through - unsupported since execlist only. */
14730 /* Default just returns -ENODEV to indicate unsupported */
14731 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
14736 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
14737 * resume, or other times. This quirk makes sure that's the case for
14738 * affected systems.
14740 static void quirk_pipea_force(struct drm_device
*dev
)
14742 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14744 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
14745 DRM_INFO("applying pipe a force quirk\n");
14748 static void quirk_pipeb_force(struct drm_device
*dev
)
14750 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14752 dev_priv
->quirks
|= QUIRK_PIPEB_FORCE
;
14753 DRM_INFO("applying pipe b force quirk\n");
14757 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
14759 static void quirk_ssc_force_disable(struct drm_device
*dev
)
14761 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14762 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
14763 DRM_INFO("applying lvds SSC disable quirk\n");
14767 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
14770 static void quirk_invert_brightness(struct drm_device
*dev
)
14772 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14773 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
14774 DRM_INFO("applying inverted panel brightness quirk\n");
14777 /* Some VBT's incorrectly indicate no backlight is present */
14778 static void quirk_backlight_present(struct drm_device
*dev
)
14780 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14781 dev_priv
->quirks
|= QUIRK_BACKLIGHT_PRESENT
;
14782 DRM_INFO("applying backlight present quirk\n");
14785 struct intel_quirk
{
14787 int subsystem_vendor
;
14788 int subsystem_device
;
14789 void (*hook
)(struct drm_device
*dev
);
14792 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
14793 struct intel_dmi_quirk
{
14794 void (*hook
)(struct drm_device
*dev
);
14795 const struct dmi_system_id (*dmi_id_list
)[];
14798 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
14800 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
14804 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
14806 .dmi_id_list
= &(const struct dmi_system_id
[]) {
14808 .callback
= intel_dmi_reverse_brightness
,
14809 .ident
= "NCR Corporation",
14810 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
14811 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
14814 { } /* terminating entry */
14816 .hook
= quirk_invert_brightness
,
14820 static struct intel_quirk intel_quirks
[] = {
14821 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
14822 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
14824 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
14825 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
14827 /* 830 needs to leave pipe A & dpll A up */
14828 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
14830 /* 830 needs to leave pipe B & dpll B up */
14831 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipeb_force
},
14833 /* Lenovo U160 cannot use SSC on LVDS */
14834 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
14836 /* Sony Vaio Y cannot use SSC on LVDS */
14837 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
14839 /* Acer Aspire 5734Z must invert backlight brightness */
14840 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
14842 /* Acer/eMachines G725 */
14843 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
14845 /* Acer/eMachines e725 */
14846 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
14848 /* Acer/Packard Bell NCL20 */
14849 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
14851 /* Acer Aspire 4736Z */
14852 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
14854 /* Acer Aspire 5336 */
14855 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
14857 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
14858 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present
},
14860 /* Acer C720 Chromebook (Core i3 4005U) */
14861 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present
},
14863 /* Apple Macbook 2,1 (Core 2 T7400) */
14864 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present
},
14866 /* Apple Macbook 4,1 */
14867 { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present
},
14869 /* Toshiba CB35 Chromebook (Celeron 2955U) */
14870 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present
},
14872 /* HP Chromebook 14 (Celeron 2955U) */
14873 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present
},
14875 /* Dell Chromebook 11 */
14876 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present
},
14878 /* Dell Chromebook 11 (2015 version) */
14879 { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present
},
14882 static void intel_init_quirks(struct drm_device
*dev
)
14884 struct pci_dev
*d
= dev
->pdev
;
14887 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
14888 struct intel_quirk
*q
= &intel_quirks
[i
];
14890 if (d
->device
== q
->device
&&
14891 (d
->subsystem_vendor
== q
->subsystem_vendor
||
14892 q
->subsystem_vendor
== PCI_ANY_ID
) &&
14893 (d
->subsystem_device
== q
->subsystem_device
||
14894 q
->subsystem_device
== PCI_ANY_ID
))
14897 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
14898 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
14899 intel_dmi_quirks
[i
].hook(dev
);
14903 /* Disable the VGA plane that we never use */
14904 static void i915_disable_vga(struct drm_i915_private
*dev_priv
)
14906 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
14908 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev_priv
);
14910 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
14911 vga_get_uninterruptible(pdev
, VGA_RSRC_LEGACY_IO
);
14912 outb(SR01
, VGA_SR_INDEX
);
14913 sr1
= inb(VGA_SR_DATA
);
14914 outb(sr1
| 1<<5, VGA_SR_DATA
);
14915 vga_put(pdev
, VGA_RSRC_LEGACY_IO
);
14918 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
14919 POSTING_READ(vga_reg
);
14922 void intel_modeset_init_hw(struct drm_device
*dev
)
14924 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14926 intel_update_cdclk(dev_priv
);
14927 dev_priv
->cdclk
.logical
= dev_priv
->cdclk
.actual
= dev_priv
->cdclk
.hw
;
14929 intel_init_clock_gating(dev_priv
);
14933 * Calculate what we think the watermarks should be for the state we've read
14934 * out of the hardware and then immediately program those watermarks so that
14935 * we ensure the hardware settings match our internal state.
14937 * We can calculate what we think WM's should be by creating a duplicate of the
14938 * current state (which was constructed during hardware readout) and running it
14939 * through the atomic check code to calculate new watermark values in the
14942 static void sanitize_watermarks(struct drm_device
*dev
)
14944 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14945 struct drm_atomic_state
*state
;
14946 struct intel_atomic_state
*intel_state
;
14947 struct drm_crtc
*crtc
;
14948 struct drm_crtc_state
*cstate
;
14949 struct drm_modeset_acquire_ctx ctx
;
14953 /* Only supported on platforms that use atomic watermark design */
14954 if (!dev_priv
->display
.optimize_watermarks
)
14958 * We need to hold connection_mutex before calling duplicate_state so
14959 * that the connector loop is protected.
14961 drm_modeset_acquire_init(&ctx
, 0);
14963 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
14964 if (ret
== -EDEADLK
) {
14965 drm_modeset_backoff(&ctx
);
14967 } else if (WARN_ON(ret
)) {
14971 state
= drm_atomic_helper_duplicate_state(dev
, &ctx
);
14972 if (WARN_ON(IS_ERR(state
)))
14975 intel_state
= to_intel_atomic_state(state
);
14978 * Hardware readout is the only time we don't want to calculate
14979 * intermediate watermarks (since we don't trust the current
14982 if (!HAS_GMCH_DISPLAY(dev_priv
))
14983 intel_state
->skip_intermediate_wm
= true;
14985 ret
= intel_atomic_check(dev
, state
);
14988 * If we fail here, it means that the hardware appears to be
14989 * programmed in a way that shouldn't be possible, given our
14990 * understanding of watermark requirements. This might mean a
14991 * mistake in the hardware readout code or a mistake in the
14992 * watermark calculations for a given platform. Raise a WARN
14993 * so that this is noticeable.
14995 * If this actually happens, we'll have to just leave the
14996 * BIOS-programmed watermarks untouched and hope for the best.
14998 WARN(true, "Could not determine valid watermarks for inherited state\n");
15002 /* Write calculated watermark values back */
15003 for_each_new_crtc_in_state(state
, crtc
, cstate
, i
) {
15004 struct intel_crtc_state
*cs
= to_intel_crtc_state(cstate
);
15006 cs
->wm
.need_postvbl_update
= true;
15007 dev_priv
->display
.optimize_watermarks(intel_state
, cs
);
15011 drm_atomic_state_put(state
);
15013 drm_modeset_drop_locks(&ctx
);
15014 drm_modeset_acquire_fini(&ctx
);
15017 int intel_modeset_init(struct drm_device
*dev
)
15019 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15020 struct i915_ggtt
*ggtt
= &dev_priv
->ggtt
;
15022 struct intel_crtc
*crtc
;
15024 drm_mode_config_init(dev
);
15026 dev
->mode_config
.min_width
= 0;
15027 dev
->mode_config
.min_height
= 0;
15029 dev
->mode_config
.preferred_depth
= 24;
15030 dev
->mode_config
.prefer_shadow
= 1;
15032 dev
->mode_config
.allow_fb_modifiers
= true;
15034 dev
->mode_config
.funcs
= &intel_mode_funcs
;
15036 INIT_WORK(&dev_priv
->atomic_helper
.free_work
,
15037 intel_atomic_helper_free_state_worker
);
15039 intel_init_quirks(dev
);
15041 intel_init_pm(dev_priv
);
15043 if (INTEL_INFO(dev_priv
)->num_pipes
== 0)
15047 * There may be no VBT; and if the BIOS enabled SSC we can
15048 * just keep using it to avoid unnecessary flicker. Whereas if the
15049 * BIOS isn't using it, don't assume it will work even if the VBT
15050 * indicates as much.
15052 if (HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
)) {
15053 bool bios_lvds_use_ssc
= !!(I915_READ(PCH_DREF_CONTROL
) &
15056 if (dev_priv
->vbt
.lvds_use_ssc
!= bios_lvds_use_ssc
) {
15057 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
15058 bios_lvds_use_ssc
? "en" : "dis",
15059 dev_priv
->vbt
.lvds_use_ssc
? "en" : "dis");
15060 dev_priv
->vbt
.lvds_use_ssc
= bios_lvds_use_ssc
;
15064 if (IS_GEN2(dev_priv
)) {
15065 dev
->mode_config
.max_width
= 2048;
15066 dev
->mode_config
.max_height
= 2048;
15067 } else if (IS_GEN3(dev_priv
)) {
15068 dev
->mode_config
.max_width
= 4096;
15069 dev
->mode_config
.max_height
= 4096;
15071 dev
->mode_config
.max_width
= 8192;
15072 dev
->mode_config
.max_height
= 8192;
15075 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
)) {
15076 dev
->mode_config
.cursor_width
= IS_I845G(dev_priv
) ? 64 : 512;
15077 dev
->mode_config
.cursor_height
= 1023;
15078 } else if (IS_GEN2(dev_priv
)) {
15079 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
15080 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
15082 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
15083 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
15086 dev
->mode_config
.fb_base
= ggtt
->mappable_base
;
15088 DRM_DEBUG_KMS("%d display pipe%s available.\n",
15089 INTEL_INFO(dev_priv
)->num_pipes
,
15090 INTEL_INFO(dev_priv
)->num_pipes
> 1 ? "s" : "");
15092 for_each_pipe(dev_priv
, pipe
) {
15095 ret
= intel_crtc_init(dev_priv
, pipe
);
15097 drm_mode_config_cleanup(dev
);
15102 intel_shared_dpll_init(dev
);
15104 intel_update_czclk(dev_priv
);
15105 intel_modeset_init_hw(dev
);
15107 if (dev_priv
->max_cdclk_freq
== 0)
15108 intel_update_max_cdclk(dev_priv
);
15110 /* Just disable it once at startup */
15111 i915_disable_vga(dev_priv
);
15112 intel_setup_outputs(dev_priv
);
15114 drm_modeset_lock_all(dev
);
15115 intel_modeset_setup_hw_state(dev
);
15116 drm_modeset_unlock_all(dev
);
15118 for_each_intel_crtc(dev
, crtc
) {
15119 struct intel_initial_plane_config plane_config
= {};
15125 * Note that reserving the BIOS fb up front prevents us
15126 * from stuffing other stolen allocations like the ring
15127 * on top. This prevents some ugliness at boot time, and
15128 * can even allow for smooth boot transitions if the BIOS
15129 * fb is large enough for the active pipe configuration.
15131 dev_priv
->display
.get_initial_plane_config(crtc
,
15135 * If the fb is shared between multiple heads, we'll
15136 * just get the first one.
15138 intel_find_initial_plane_obj(crtc
, &plane_config
);
15142 * Make sure hardware watermarks really match the state we read out.
15143 * Note that we need to do this after reconstructing the BIOS fb's
15144 * since the watermark calculation done here will use pstate->fb.
15146 if (!HAS_GMCH_DISPLAY(dev_priv
))
15147 sanitize_watermarks(dev
);
15152 static void intel_enable_pipe_a(struct drm_device
*dev
)
15154 struct intel_connector
*connector
;
15155 struct drm_connector_list_iter conn_iter
;
15156 struct drm_connector
*crt
= NULL
;
15157 struct intel_load_detect_pipe load_detect_temp
;
15158 struct drm_modeset_acquire_ctx
*ctx
= dev
->mode_config
.acquire_ctx
;
15160 /* We can't just switch on the pipe A, we need to set things up with a
15161 * proper mode and output configuration. As a gross hack, enable pipe A
15162 * by enabling the load detect pipe once. */
15163 drm_connector_list_iter_begin(dev
, &conn_iter
);
15164 for_each_intel_connector_iter(connector
, &conn_iter
) {
15165 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
15166 crt
= &connector
->base
;
15170 drm_connector_list_iter_end(&conn_iter
);
15175 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
, ctx
))
15176 intel_release_load_detect_pipe(crt
, &load_detect_temp
, ctx
);
15180 intel_check_plane_mapping(struct intel_crtc
*crtc
)
15182 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
15185 if (INTEL_INFO(dev_priv
)->num_pipes
== 1)
15188 val
= I915_READ(DSPCNTR(!crtc
->plane
));
15190 if ((val
& DISPLAY_PLANE_ENABLE
) &&
15191 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
15197 static bool intel_crtc_has_encoders(struct intel_crtc
*crtc
)
15199 struct drm_device
*dev
= crtc
->base
.dev
;
15200 struct intel_encoder
*encoder
;
15202 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
15208 static struct intel_connector
*intel_encoder_find_connector(struct intel_encoder
*encoder
)
15210 struct drm_device
*dev
= encoder
->base
.dev
;
15211 struct intel_connector
*connector
;
15213 for_each_connector_on_encoder(dev
, &encoder
->base
, connector
)
15219 static bool has_pch_trancoder(struct drm_i915_private
*dev_priv
,
15220 enum transcoder pch_transcoder
)
15222 return HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
) ||
15223 (HAS_PCH_LPT_H(dev_priv
) && pch_transcoder
== TRANSCODER_A
);
15226 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
15228 struct drm_device
*dev
= crtc
->base
.dev
;
15229 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15230 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
15232 /* Clear any frame start delays used for debugging left by the BIOS */
15233 if (!transcoder_is_dsi(cpu_transcoder
)) {
15234 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
15237 I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
15240 /* restore vblank interrupts to correct state */
15241 drm_crtc_vblank_reset(&crtc
->base
);
15242 if (crtc
->active
) {
15243 struct intel_plane
*plane
;
15245 drm_crtc_vblank_on(&crtc
->base
);
15247 /* Disable everything but the primary plane */
15248 for_each_intel_plane_on_crtc(dev
, crtc
, plane
) {
15249 if (plane
->base
.type
== DRM_PLANE_TYPE_PRIMARY
)
15252 trace_intel_disable_plane(&plane
->base
, crtc
);
15253 plane
->disable_plane(&plane
->base
, &crtc
->base
);
15257 /* We need to sanitize the plane -> pipe mapping first because this will
15258 * disable the crtc (and hence change the state) if it is wrong. Note
15259 * that gen4+ has a fixed plane -> pipe mapping. */
15260 if (INTEL_GEN(dev_priv
) < 4 && !intel_check_plane_mapping(crtc
)) {
15263 DRM_DEBUG_KMS("[CRTC:%d:%s] wrong plane connection detected!\n",
15264 crtc
->base
.base
.id
, crtc
->base
.name
);
15266 /* Pipe has the wrong plane attached and the plane is active.
15267 * Temporarily change the plane mapping and disable everything
15269 plane
= crtc
->plane
;
15270 crtc
->base
.primary
->state
->visible
= true;
15271 crtc
->plane
= !plane
;
15272 intel_crtc_disable_noatomic(&crtc
->base
);
15273 crtc
->plane
= plane
;
15276 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
15277 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
15278 /* BIOS forgot to enable pipe A, this mostly happens after
15279 * resume. Force-enable the pipe to fix this, the update_dpms
15280 * call below we restore the pipe to the right state, but leave
15281 * the required bits on. */
15282 intel_enable_pipe_a(dev
);
15285 /* Adjust the state of the output pipe according to whether we
15286 * have active connectors/encoders. */
15287 if (crtc
->active
&& !intel_crtc_has_encoders(crtc
))
15288 intel_crtc_disable_noatomic(&crtc
->base
);
15290 if (crtc
->active
|| HAS_GMCH_DISPLAY(dev_priv
)) {
15292 * We start out with underrun reporting disabled to avoid races.
15293 * For correct bookkeeping mark this on active crtcs.
15295 * Also on gmch platforms we dont have any hardware bits to
15296 * disable the underrun reporting. Which means we need to start
15297 * out with underrun reporting disabled also on inactive pipes,
15298 * since otherwise we'll complain about the garbage we read when
15299 * e.g. coming up after runtime pm.
15301 * No protection against concurrent access is required - at
15302 * worst a fifo underrun happens which also sets this to false.
15304 crtc
->cpu_fifo_underrun_disabled
= true;
15306 * We track the PCH trancoder underrun reporting state
15307 * within the crtc. With crtc for pipe A housing the underrun
15308 * reporting state for PCH transcoder A, crtc for pipe B housing
15309 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
15310 * and marking underrun reporting as disabled for the non-existing
15311 * PCH transcoders B and C would prevent enabling the south
15312 * error interrupt (see cpt_can_enable_serr_int()).
15314 if (has_pch_trancoder(dev_priv
, (enum transcoder
)crtc
->pipe
))
15315 crtc
->pch_fifo_underrun_disabled
= true;
15319 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
15321 struct intel_connector
*connector
;
15323 /* We need to check both for a crtc link (meaning that the
15324 * encoder is active and trying to read from a pipe) and the
15325 * pipe itself being active. */
15326 bool has_active_crtc
= encoder
->base
.crtc
&&
15327 to_intel_crtc(encoder
->base
.crtc
)->active
;
15329 connector
= intel_encoder_find_connector(encoder
);
15330 if (connector
&& !has_active_crtc
) {
15331 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15332 encoder
->base
.base
.id
,
15333 encoder
->base
.name
);
15335 /* Connector is active, but has no active pipe. This is
15336 * fallout from our resume register restoring. Disable
15337 * the encoder manually again. */
15338 if (encoder
->base
.crtc
) {
15339 struct drm_crtc_state
*crtc_state
= encoder
->base
.crtc
->state
;
15341 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15342 encoder
->base
.base
.id
,
15343 encoder
->base
.name
);
15344 encoder
->disable(encoder
, to_intel_crtc_state(crtc_state
), connector
->base
.state
);
15345 if (encoder
->post_disable
)
15346 encoder
->post_disable(encoder
, to_intel_crtc_state(crtc_state
), connector
->base
.state
);
15348 encoder
->base
.crtc
= NULL
;
15350 /* Inconsistent output/port/pipe state happens presumably due to
15351 * a bug in one of the get_hw_state functions. Or someplace else
15352 * in our code, like the register restore mess on resume. Clamp
15353 * things to off as a safer default. */
15355 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
15356 connector
->base
.encoder
= NULL
;
15358 /* Enabled encoders without active connectors will be fixed in
15359 * the crtc fixup. */
15362 void i915_redisable_vga_power_on(struct drm_i915_private
*dev_priv
)
15364 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev_priv
);
15366 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
15367 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
15368 i915_disable_vga(dev_priv
);
15372 void i915_redisable_vga(struct drm_i915_private
*dev_priv
)
15374 /* This function can be called both from intel_modeset_setup_hw_state or
15375 * at a very early point in our resume sequence, where the power well
15376 * structures are not yet restored. Since this function is at a very
15377 * paranoid "someone might have enabled VGA while we were not looking"
15378 * level, just check if the power well is enabled instead of trying to
15379 * follow the "don't touch the power well if we don't need it" policy
15380 * the rest of the driver uses. */
15381 if (!intel_display_power_get_if_enabled(dev_priv
, POWER_DOMAIN_VGA
))
15384 i915_redisable_vga_power_on(dev_priv
);
15386 intel_display_power_put(dev_priv
, POWER_DOMAIN_VGA
);
15389 static bool primary_get_hw_state(struct intel_plane
*plane
)
15391 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
15393 return I915_READ(DSPCNTR(plane
->plane
)) & DISPLAY_PLANE_ENABLE
;
15396 /* FIXME read out full plane state for all planes */
15397 static void readout_plane_state(struct intel_crtc
*crtc
)
15399 struct intel_plane
*primary
= to_intel_plane(crtc
->base
.primary
);
15402 visible
= crtc
->active
&& primary_get_hw_state(primary
);
15404 intel_set_plane_visible(to_intel_crtc_state(crtc
->base
.state
),
15405 to_intel_plane_state(primary
->base
.state
),
15409 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
15411 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15413 struct intel_crtc
*crtc
;
15414 struct intel_encoder
*encoder
;
15415 struct intel_connector
*connector
;
15416 struct drm_connector_list_iter conn_iter
;
15419 dev_priv
->active_crtcs
= 0;
15421 for_each_intel_crtc(dev
, crtc
) {
15422 struct intel_crtc_state
*crtc_state
=
15423 to_intel_crtc_state(crtc
->base
.state
);
15425 __drm_atomic_helper_crtc_destroy_state(&crtc_state
->base
);
15426 memset(crtc_state
, 0, sizeof(*crtc_state
));
15427 crtc_state
->base
.crtc
= &crtc
->base
;
15429 crtc_state
->base
.active
= crtc_state
->base
.enable
=
15430 dev_priv
->display
.get_pipe_config(crtc
, crtc_state
);
15432 crtc
->base
.enabled
= crtc_state
->base
.enable
;
15433 crtc
->active
= crtc_state
->base
.active
;
15435 if (crtc_state
->base
.active
)
15436 dev_priv
->active_crtcs
|= 1 << crtc
->pipe
;
15438 readout_plane_state(crtc
);
15440 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15441 crtc
->base
.base
.id
, crtc
->base
.name
,
15442 enableddisabled(crtc_state
->base
.active
));
15445 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
15446 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
15448 pll
->on
= pll
->funcs
.get_hw_state(dev_priv
, pll
,
15449 &pll
->state
.hw_state
);
15450 pll
->state
.crtc_mask
= 0;
15451 for_each_intel_crtc(dev
, crtc
) {
15452 struct intel_crtc_state
*crtc_state
=
15453 to_intel_crtc_state(crtc
->base
.state
);
15455 if (crtc_state
->base
.active
&&
15456 crtc_state
->shared_dpll
== pll
)
15457 pll
->state
.crtc_mask
|= 1 << crtc
->pipe
;
15459 pll
->active_mask
= pll
->state
.crtc_mask
;
15461 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15462 pll
->name
, pll
->state
.crtc_mask
, pll
->on
);
15465 for_each_intel_encoder(dev
, encoder
) {
15468 if (encoder
->get_hw_state(encoder
, &pipe
)) {
15469 struct intel_crtc_state
*crtc_state
;
15471 crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
15472 crtc_state
= to_intel_crtc_state(crtc
->base
.state
);
15474 encoder
->base
.crtc
= &crtc
->base
;
15475 crtc_state
->output_types
|= 1 << encoder
->type
;
15476 encoder
->get_config(encoder
, crtc_state
);
15478 encoder
->base
.crtc
= NULL
;
15481 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15482 encoder
->base
.base
.id
, encoder
->base
.name
,
15483 enableddisabled(encoder
->base
.crtc
),
15487 drm_connector_list_iter_begin(dev
, &conn_iter
);
15488 for_each_intel_connector_iter(connector
, &conn_iter
) {
15489 if (connector
->get_hw_state(connector
)) {
15490 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
15492 encoder
= connector
->encoder
;
15493 connector
->base
.encoder
= &encoder
->base
;
15495 if (encoder
->base
.crtc
&&
15496 encoder
->base
.crtc
->state
->active
) {
15498 * This has to be done during hardware readout
15499 * because anything calling .crtc_disable may
15500 * rely on the connector_mask being accurate.
15502 encoder
->base
.crtc
->state
->connector_mask
|=
15503 1 << drm_connector_index(&connector
->base
);
15504 encoder
->base
.crtc
->state
->encoder_mask
|=
15505 1 << drm_encoder_index(&encoder
->base
);
15509 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
15510 connector
->base
.encoder
= NULL
;
15512 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
15513 connector
->base
.base
.id
, connector
->base
.name
,
15514 enableddisabled(connector
->base
.encoder
));
15516 drm_connector_list_iter_end(&conn_iter
);
15518 for_each_intel_crtc(dev
, crtc
) {
15519 struct intel_crtc_state
*crtc_state
=
15520 to_intel_crtc_state(crtc
->base
.state
);
15523 crtc
->base
.hwmode
= crtc_state
->base
.adjusted_mode
;
15525 memset(&crtc
->base
.mode
, 0, sizeof(crtc
->base
.mode
));
15526 if (crtc_state
->base
.active
) {
15527 intel_mode_from_pipe_config(&crtc
->base
.mode
, crtc_state
);
15528 intel_mode_from_pipe_config(&crtc_state
->base
.adjusted_mode
, crtc_state
);
15529 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->base
.state
, &crtc
->base
.mode
));
15532 * The initial mode needs to be set in order to keep
15533 * the atomic core happy. It wants a valid mode if the
15534 * crtc's enabled, so we do the above call.
15536 * But we don't set all the derived state fully, hence
15537 * set a flag to indicate that a full recalculation is
15538 * needed on the next commit.
15540 crtc_state
->base
.mode
.private_flags
= I915_MODE_FLAG_INHERITED
;
15542 intel_crtc_compute_pixel_rate(crtc_state
);
15544 if (INTEL_GEN(dev_priv
) >= 9 || IS_BROADWELL(dev_priv
) ||
15545 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
15546 pixclk
= crtc_state
->pixel_rate
;
15548 WARN_ON(dev_priv
->display
.modeset_calc_cdclk
);
15550 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
15551 if (IS_BROADWELL(dev_priv
) && crtc_state
->ips_enabled
)
15552 pixclk
= DIV_ROUND_UP(pixclk
* 100, 95);
15554 drm_calc_timestamping_constants(&crtc
->base
, &crtc
->base
.hwmode
);
15555 update_scanline_offset(crtc
);
15558 dev_priv
->min_pixclk
[crtc
->pipe
] = pixclk
;
15560 intel_pipe_config_sanity_check(dev_priv
, crtc_state
);
15565 get_encoder_power_domains(struct drm_i915_private
*dev_priv
)
15567 struct intel_encoder
*encoder
;
15569 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
15571 enum intel_display_power_domain domain
;
15573 if (!encoder
->get_power_domains
)
15576 get_domains
= encoder
->get_power_domains(encoder
);
15577 for_each_power_domain(domain
, get_domains
)
15578 intel_display_power_get(dev_priv
, domain
);
15582 /* Scan out the current hw modeset state,
15583 * and sanitizes it to the current state
15586 intel_modeset_setup_hw_state(struct drm_device
*dev
)
15588 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15590 struct intel_crtc
*crtc
;
15591 struct intel_encoder
*encoder
;
15594 intel_modeset_readout_hw_state(dev
);
15596 /* HW state is read out, now we need to sanitize this mess. */
15597 get_encoder_power_domains(dev_priv
);
15599 for_each_intel_encoder(dev
, encoder
) {
15600 intel_sanitize_encoder(encoder
);
15603 for_each_pipe(dev_priv
, pipe
) {
15604 crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
15606 intel_sanitize_crtc(crtc
);
15607 intel_dump_pipe_config(crtc
, crtc
->config
,
15608 "[setup_hw_state]");
15611 intel_modeset_update_connector_atomic_state(dev
);
15613 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
15614 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
15616 if (!pll
->on
|| pll
->active_mask
)
15619 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
15621 pll
->funcs
.disable(dev_priv
, pll
);
15625 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
15626 vlv_wm_get_hw_state(dev
);
15627 vlv_wm_sanitize(dev_priv
);
15628 } else if (IS_GEN9(dev_priv
)) {
15629 skl_wm_get_hw_state(dev
);
15630 } else if (HAS_PCH_SPLIT(dev_priv
)) {
15631 ilk_wm_get_hw_state(dev
);
15634 for_each_intel_crtc(dev
, crtc
) {
15637 put_domains
= modeset_get_crtc_power_domains(&crtc
->base
, crtc
->config
);
15638 if (WARN_ON(put_domains
))
15639 modeset_put_power_domains(dev_priv
, put_domains
);
15641 intel_display_set_init_power(dev_priv
, false);
15643 intel_power_domains_verify_state(dev_priv
);
15645 intel_fbc_init_pipe_state(dev_priv
);
15648 void intel_display_resume(struct drm_device
*dev
)
15650 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15651 struct drm_atomic_state
*state
= dev_priv
->modeset_restore_state
;
15652 struct drm_modeset_acquire_ctx ctx
;
15655 dev_priv
->modeset_restore_state
= NULL
;
15657 state
->acquire_ctx
= &ctx
;
15660 * This is a cludge because with real atomic modeset mode_config.mutex
15661 * won't be taken. Unfortunately some probed state like
15662 * audio_codec_enable is still protected by mode_config.mutex, so lock
15665 mutex_lock(&dev
->mode_config
.mutex
);
15666 drm_modeset_acquire_init(&ctx
, 0);
15669 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
15670 if (ret
!= -EDEADLK
)
15673 drm_modeset_backoff(&ctx
);
15677 ret
= __intel_display_resume(dev
, state
, &ctx
);
15679 drm_modeset_drop_locks(&ctx
);
15680 drm_modeset_acquire_fini(&ctx
);
15681 mutex_unlock(&dev
->mode_config
.mutex
);
15684 DRM_ERROR("Restoring old state failed with %i\n", ret
);
15686 drm_atomic_state_put(state
);
15689 void intel_modeset_gem_init(struct drm_device
*dev
)
15691 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15693 intel_init_gt_powersave(dev_priv
);
15695 intel_setup_overlay(dev_priv
);
15698 int intel_connector_register(struct drm_connector
*connector
)
15700 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
15703 ret
= intel_backlight_device_register(intel_connector
);
15713 void intel_connector_unregister(struct drm_connector
*connector
)
15715 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
15717 intel_backlight_device_unregister(intel_connector
);
15718 intel_panel_destroy_backlight(connector
);
15721 void intel_modeset_cleanup(struct drm_device
*dev
)
15723 struct drm_i915_private
*dev_priv
= to_i915(dev
);
15725 flush_work(&dev_priv
->atomic_helper
.free_work
);
15726 WARN_ON(!llist_empty(&dev_priv
->atomic_helper
.free_list
));
15728 intel_disable_gt_powersave(dev_priv
);
15731 * Interrupts and polling as the first thing to avoid creating havoc.
15732 * Too much stuff here (turning of connectors, ...) would
15733 * experience fancy races otherwise.
15735 intel_irq_uninstall(dev_priv
);
15738 * Due to the hpd irq storm handling the hotplug work can re-arm the
15739 * poll handlers. Hence disable polling after hpd handling is shut down.
15741 drm_kms_helper_poll_fini(dev
);
15743 intel_unregister_dsm_handler();
15745 intel_fbc_global_disable(dev_priv
);
15747 /* flush any delayed tasks or pending work */
15748 flush_scheduled_work();
15750 drm_mode_config_cleanup(dev
);
15752 intel_cleanup_overlay(dev_priv
);
15754 intel_cleanup_gt_powersave(dev_priv
);
15756 intel_teardown_gmbus(dev_priv
);
15759 void intel_connector_attach_encoder(struct intel_connector
*connector
,
15760 struct intel_encoder
*encoder
)
15762 connector
->encoder
= encoder
;
15763 drm_mode_connector_attach_encoder(&connector
->base
,
15768 * set vga decode state - true == enable VGA decode
15770 int intel_modeset_vga_set_state(struct drm_i915_private
*dev_priv
, bool state
)
15772 unsigned reg
= INTEL_GEN(dev_priv
) >= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
15775 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
15776 DRM_ERROR("failed to read control word\n");
15780 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
15784 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
15786 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
15788 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
15789 DRM_ERROR("failed to write control word\n");
15796 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
15798 struct intel_display_error_state
{
15800 u32 power_well_driver
;
15802 int num_transcoders
;
15804 struct intel_cursor_error_state
{
15809 } cursor
[I915_MAX_PIPES
];
15811 struct intel_pipe_error_state
{
15812 bool power_domain_on
;
15815 } pipe
[I915_MAX_PIPES
];
15817 struct intel_plane_error_state
{
15825 } plane
[I915_MAX_PIPES
];
15827 struct intel_transcoder_error_state
{
15828 bool power_domain_on
;
15829 enum transcoder cpu_transcoder
;
15842 struct intel_display_error_state
*
15843 intel_display_capture_error_state(struct drm_i915_private
*dev_priv
)
15845 struct intel_display_error_state
*error
;
15846 int transcoders
[] = {
15854 if (INTEL_INFO(dev_priv
)->num_pipes
== 0)
15857 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
15861 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
15862 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
15864 for_each_pipe(dev_priv
, i
) {
15865 error
->pipe
[i
].power_domain_on
=
15866 __intel_display_power_is_enabled(dev_priv
,
15867 POWER_DOMAIN_PIPE(i
));
15868 if (!error
->pipe
[i
].power_domain_on
)
15871 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
15872 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
15873 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
15875 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
15876 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
15877 if (INTEL_GEN(dev_priv
) <= 3) {
15878 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
15879 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
15881 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
15882 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
15883 if (INTEL_GEN(dev_priv
) >= 4) {
15884 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
15885 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
15888 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
15890 if (HAS_GMCH_DISPLAY(dev_priv
))
15891 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
15894 /* Note: this does not include DSI transcoders. */
15895 error
->num_transcoders
= INTEL_INFO(dev_priv
)->num_pipes
;
15896 if (HAS_DDI(dev_priv
))
15897 error
->num_transcoders
++; /* Account for eDP. */
15899 for (i
= 0; i
< error
->num_transcoders
; i
++) {
15900 enum transcoder cpu_transcoder
= transcoders
[i
];
15902 error
->transcoder
[i
].power_domain_on
=
15903 __intel_display_power_is_enabled(dev_priv
,
15904 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
15905 if (!error
->transcoder
[i
].power_domain_on
)
15908 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
15910 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
15911 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
15912 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
15913 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
15914 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
15915 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
15916 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
15922 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
15925 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
15926 struct intel_display_error_state
*error
)
15928 struct drm_i915_private
*dev_priv
= m
->i915
;
15934 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev_priv
)->num_pipes
);
15935 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
15936 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
15937 error
->power_well_driver
);
15938 for_each_pipe(dev_priv
, i
) {
15939 err_printf(m
, "Pipe [%d]:\n", i
);
15940 err_printf(m
, " Power: %s\n",
15941 onoff(error
->pipe
[i
].power_domain_on
));
15942 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
15943 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
15945 err_printf(m
, "Plane [%d]:\n", i
);
15946 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
15947 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
15948 if (INTEL_GEN(dev_priv
) <= 3) {
15949 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
15950 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
15952 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
15953 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
15954 if (INTEL_GEN(dev_priv
) >= 4) {
15955 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
15956 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
15959 err_printf(m
, "Cursor [%d]:\n", i
);
15960 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
15961 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
15962 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
15965 for (i
= 0; i
< error
->num_transcoders
; i
++) {
15966 err_printf(m
, "CPU transcoder: %s\n",
15967 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
15968 err_printf(m
, " Power: %s\n",
15969 onoff(error
->transcoder
[i
].power_domain_on
));
15970 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
15971 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
15972 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
15973 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
15974 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
15975 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
15976 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);