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 /* Primary plane formats for gen <= 3 */
53 static const uint32_t i8xx_primary_formats
[] = {
60 /* Primary plane formats for gen >= 4 */
61 static const uint32_t i965_primary_formats
[] = {
66 DRM_FORMAT_XRGB2101010
,
67 DRM_FORMAT_XBGR2101010
,
70 static const uint32_t skl_primary_formats
[] = {
77 DRM_FORMAT_XRGB2101010
,
78 DRM_FORMAT_XBGR2101010
,
86 static const uint32_t intel_cursor_formats
[] = {
90 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
91 struct intel_crtc_state
*pipe_config
);
92 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
93 struct intel_crtc_state
*pipe_config
);
95 static int intel_framebuffer_init(struct intel_framebuffer
*ifb
,
96 struct drm_i915_gem_object
*obj
,
97 struct drm_mode_fb_cmd2
*mode_cmd
);
98 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
);
99 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
);
100 static void intel_set_pipe_src_size(struct intel_crtc
*intel_crtc
);
101 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
102 struct intel_link_m_n
*m_n
,
103 struct intel_link_m_n
*m2_n2
);
104 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
);
105 static void haswell_set_pipeconf(struct drm_crtc
*crtc
);
106 static void haswell_set_pipemisc(struct drm_crtc
*crtc
);
107 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
108 const struct intel_crtc_state
*pipe_config
);
109 static void chv_prepare_pll(struct intel_crtc
*crtc
,
110 const struct intel_crtc_state
*pipe_config
);
111 static void intel_begin_crtc_commit(struct drm_crtc
*, struct drm_crtc_state
*);
112 static void intel_finish_crtc_commit(struct drm_crtc
*, struct drm_crtc_state
*);
113 static void intel_crtc_init_scalers(struct intel_crtc
*crtc
,
114 struct intel_crtc_state
*crtc_state
);
115 static void skylake_pfit_enable(struct intel_crtc
*crtc
);
116 static void ironlake_pfit_disable(struct intel_crtc
*crtc
, bool force
);
117 static void ironlake_pfit_enable(struct intel_crtc
*crtc
);
118 static void intel_modeset_setup_hw_state(struct drm_device
*dev
,
119 struct drm_modeset_acquire_ctx
*ctx
);
120 static void intel_pre_disable_primary_noatomic(struct drm_crtc
*crtc
);
125 } dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
129 int p2_slow
, p2_fast
;
133 /* returns HPLL frequency in kHz */
134 int vlv_get_hpll_vco(struct drm_i915_private
*dev_priv
)
136 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
138 /* Obtain SKU information */
139 mutex_lock(&dev_priv
->sb_lock
);
140 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
141 CCK_FUSE_HPLL_FREQ_MASK
;
142 mutex_unlock(&dev_priv
->sb_lock
);
144 return vco_freq
[hpll_freq
] * 1000;
147 int vlv_get_cck_clock(struct drm_i915_private
*dev_priv
,
148 const char *name
, u32 reg
, int ref_freq
)
153 mutex_lock(&dev_priv
->sb_lock
);
154 val
= vlv_cck_read(dev_priv
, reg
);
155 mutex_unlock(&dev_priv
->sb_lock
);
157 divider
= val
& CCK_FREQUENCY_VALUES
;
159 WARN((val
& CCK_FREQUENCY_STATUS
) !=
160 (divider
<< CCK_FREQUENCY_STATUS_SHIFT
),
161 "%s change in progress\n", name
);
163 return DIV_ROUND_CLOSEST(ref_freq
<< 1, divider
+ 1);
166 int vlv_get_cck_clock_hpll(struct drm_i915_private
*dev_priv
,
167 const char *name
, u32 reg
)
169 if (dev_priv
->hpll_freq
== 0)
170 dev_priv
->hpll_freq
= vlv_get_hpll_vco(dev_priv
);
172 return vlv_get_cck_clock(dev_priv
, name
, reg
,
173 dev_priv
->hpll_freq
);
176 static void intel_update_czclk(struct drm_i915_private
*dev_priv
)
178 if (!(IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)))
181 dev_priv
->czclk_freq
= vlv_get_cck_clock_hpll(dev_priv
, "czclk",
182 CCK_CZ_CLOCK_CONTROL
);
184 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv
->czclk_freq
);
187 static inline u32
/* units of 100MHz */
188 intel_fdi_link_freq(struct drm_i915_private
*dev_priv
,
189 const struct intel_crtc_state
*pipe_config
)
191 if (HAS_DDI(dev_priv
))
192 return pipe_config
->port_clock
; /* SPLL */
193 else if (IS_GEN5(dev_priv
))
194 return ((I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2) * 10000;
199 static const struct intel_limit intel_limits_i8xx_dac
= {
200 .dot
= { .min
= 25000, .max
= 350000 },
201 .vco
= { .min
= 908000, .max
= 1512000 },
202 .n
= { .min
= 2, .max
= 16 },
203 .m
= { .min
= 96, .max
= 140 },
204 .m1
= { .min
= 18, .max
= 26 },
205 .m2
= { .min
= 6, .max
= 16 },
206 .p
= { .min
= 4, .max
= 128 },
207 .p1
= { .min
= 2, .max
= 33 },
208 .p2
= { .dot_limit
= 165000,
209 .p2_slow
= 4, .p2_fast
= 2 },
212 static const struct intel_limit intel_limits_i8xx_dvo
= {
213 .dot
= { .min
= 25000, .max
= 350000 },
214 .vco
= { .min
= 908000, .max
= 1512000 },
215 .n
= { .min
= 2, .max
= 16 },
216 .m
= { .min
= 96, .max
= 140 },
217 .m1
= { .min
= 18, .max
= 26 },
218 .m2
= { .min
= 6, .max
= 16 },
219 .p
= { .min
= 4, .max
= 128 },
220 .p1
= { .min
= 2, .max
= 33 },
221 .p2
= { .dot_limit
= 165000,
222 .p2_slow
= 4, .p2_fast
= 4 },
225 static const struct intel_limit intel_limits_i8xx_lvds
= {
226 .dot
= { .min
= 25000, .max
= 350000 },
227 .vco
= { .min
= 908000, .max
= 1512000 },
228 .n
= { .min
= 2, .max
= 16 },
229 .m
= { .min
= 96, .max
= 140 },
230 .m1
= { .min
= 18, .max
= 26 },
231 .m2
= { .min
= 6, .max
= 16 },
232 .p
= { .min
= 4, .max
= 128 },
233 .p1
= { .min
= 1, .max
= 6 },
234 .p2
= { .dot_limit
= 165000,
235 .p2_slow
= 14, .p2_fast
= 7 },
238 static const struct intel_limit intel_limits_i9xx_sdvo
= {
239 .dot
= { .min
= 20000, .max
= 400000 },
240 .vco
= { .min
= 1400000, .max
= 2800000 },
241 .n
= { .min
= 1, .max
= 6 },
242 .m
= { .min
= 70, .max
= 120 },
243 .m1
= { .min
= 8, .max
= 18 },
244 .m2
= { .min
= 3, .max
= 7 },
245 .p
= { .min
= 5, .max
= 80 },
246 .p1
= { .min
= 1, .max
= 8 },
247 .p2
= { .dot_limit
= 200000,
248 .p2_slow
= 10, .p2_fast
= 5 },
251 static const struct intel_limit intel_limits_i9xx_lvds
= {
252 .dot
= { .min
= 20000, .max
= 400000 },
253 .vco
= { .min
= 1400000, .max
= 2800000 },
254 .n
= { .min
= 1, .max
= 6 },
255 .m
= { .min
= 70, .max
= 120 },
256 .m1
= { .min
= 8, .max
= 18 },
257 .m2
= { .min
= 3, .max
= 7 },
258 .p
= { .min
= 7, .max
= 98 },
259 .p1
= { .min
= 1, .max
= 8 },
260 .p2
= { .dot_limit
= 112000,
261 .p2_slow
= 14, .p2_fast
= 7 },
265 static const struct intel_limit intel_limits_g4x_sdvo
= {
266 .dot
= { .min
= 25000, .max
= 270000 },
267 .vco
= { .min
= 1750000, .max
= 3500000},
268 .n
= { .min
= 1, .max
= 4 },
269 .m
= { .min
= 104, .max
= 138 },
270 .m1
= { .min
= 17, .max
= 23 },
271 .m2
= { .min
= 5, .max
= 11 },
272 .p
= { .min
= 10, .max
= 30 },
273 .p1
= { .min
= 1, .max
= 3},
274 .p2
= { .dot_limit
= 270000,
280 static const struct intel_limit intel_limits_g4x_hdmi
= {
281 .dot
= { .min
= 22000, .max
= 400000 },
282 .vco
= { .min
= 1750000, .max
= 3500000},
283 .n
= { .min
= 1, .max
= 4 },
284 .m
= { .min
= 104, .max
= 138 },
285 .m1
= { .min
= 16, .max
= 23 },
286 .m2
= { .min
= 5, .max
= 11 },
287 .p
= { .min
= 5, .max
= 80 },
288 .p1
= { .min
= 1, .max
= 8},
289 .p2
= { .dot_limit
= 165000,
290 .p2_slow
= 10, .p2_fast
= 5 },
293 static const struct intel_limit intel_limits_g4x_single_channel_lvds
= {
294 .dot
= { .min
= 20000, .max
= 115000 },
295 .vco
= { .min
= 1750000, .max
= 3500000 },
296 .n
= { .min
= 1, .max
= 3 },
297 .m
= { .min
= 104, .max
= 138 },
298 .m1
= { .min
= 17, .max
= 23 },
299 .m2
= { .min
= 5, .max
= 11 },
300 .p
= { .min
= 28, .max
= 112 },
301 .p1
= { .min
= 2, .max
= 8 },
302 .p2
= { .dot_limit
= 0,
303 .p2_slow
= 14, .p2_fast
= 14
307 static const struct intel_limit intel_limits_g4x_dual_channel_lvds
= {
308 .dot
= { .min
= 80000, .max
= 224000 },
309 .vco
= { .min
= 1750000, .max
= 3500000 },
310 .n
= { .min
= 1, .max
= 3 },
311 .m
= { .min
= 104, .max
= 138 },
312 .m1
= { .min
= 17, .max
= 23 },
313 .m2
= { .min
= 5, .max
= 11 },
314 .p
= { .min
= 14, .max
= 42 },
315 .p1
= { .min
= 2, .max
= 6 },
316 .p2
= { .dot_limit
= 0,
317 .p2_slow
= 7, .p2_fast
= 7
321 static const struct intel_limit intel_limits_pineview_sdvo
= {
322 .dot
= { .min
= 20000, .max
= 400000},
323 .vco
= { .min
= 1700000, .max
= 3500000 },
324 /* Pineview's Ncounter is a ring counter */
325 .n
= { .min
= 3, .max
= 6 },
326 .m
= { .min
= 2, .max
= 256 },
327 /* Pineview only has one combined m divider, which we treat as m2. */
328 .m1
= { .min
= 0, .max
= 0 },
329 .m2
= { .min
= 0, .max
= 254 },
330 .p
= { .min
= 5, .max
= 80 },
331 .p1
= { .min
= 1, .max
= 8 },
332 .p2
= { .dot_limit
= 200000,
333 .p2_slow
= 10, .p2_fast
= 5 },
336 static const struct intel_limit intel_limits_pineview_lvds
= {
337 .dot
= { .min
= 20000, .max
= 400000 },
338 .vco
= { .min
= 1700000, .max
= 3500000 },
339 .n
= { .min
= 3, .max
= 6 },
340 .m
= { .min
= 2, .max
= 256 },
341 .m1
= { .min
= 0, .max
= 0 },
342 .m2
= { .min
= 0, .max
= 254 },
343 .p
= { .min
= 7, .max
= 112 },
344 .p1
= { .min
= 1, .max
= 8 },
345 .p2
= { .dot_limit
= 112000,
346 .p2_slow
= 14, .p2_fast
= 14 },
349 /* Ironlake / Sandybridge
351 * We calculate clock using (register_value + 2) for N/M1/M2, so here
352 * the range value for them is (actual_value - 2).
354 static const struct intel_limit intel_limits_ironlake_dac
= {
355 .dot
= { .min
= 25000, .max
= 350000 },
356 .vco
= { .min
= 1760000, .max
= 3510000 },
357 .n
= { .min
= 1, .max
= 5 },
358 .m
= { .min
= 79, .max
= 127 },
359 .m1
= { .min
= 12, .max
= 22 },
360 .m2
= { .min
= 5, .max
= 9 },
361 .p
= { .min
= 5, .max
= 80 },
362 .p1
= { .min
= 1, .max
= 8 },
363 .p2
= { .dot_limit
= 225000,
364 .p2_slow
= 10, .p2_fast
= 5 },
367 static const struct intel_limit intel_limits_ironlake_single_lvds
= {
368 .dot
= { .min
= 25000, .max
= 350000 },
369 .vco
= { .min
= 1760000, .max
= 3510000 },
370 .n
= { .min
= 1, .max
= 3 },
371 .m
= { .min
= 79, .max
= 118 },
372 .m1
= { .min
= 12, .max
= 22 },
373 .m2
= { .min
= 5, .max
= 9 },
374 .p
= { .min
= 28, .max
= 112 },
375 .p1
= { .min
= 2, .max
= 8 },
376 .p2
= { .dot_limit
= 225000,
377 .p2_slow
= 14, .p2_fast
= 14 },
380 static const struct intel_limit intel_limits_ironlake_dual_lvds
= {
381 .dot
= { .min
= 25000, .max
= 350000 },
382 .vco
= { .min
= 1760000, .max
= 3510000 },
383 .n
= { .min
= 1, .max
= 3 },
384 .m
= { .min
= 79, .max
= 127 },
385 .m1
= { .min
= 12, .max
= 22 },
386 .m2
= { .min
= 5, .max
= 9 },
387 .p
= { .min
= 14, .max
= 56 },
388 .p1
= { .min
= 2, .max
= 8 },
389 .p2
= { .dot_limit
= 225000,
390 .p2_slow
= 7, .p2_fast
= 7 },
393 /* LVDS 100mhz refclk limits. */
394 static const struct intel_limit intel_limits_ironlake_single_lvds_100m
= {
395 .dot
= { .min
= 25000, .max
= 350000 },
396 .vco
= { .min
= 1760000, .max
= 3510000 },
397 .n
= { .min
= 1, .max
= 2 },
398 .m
= { .min
= 79, .max
= 126 },
399 .m1
= { .min
= 12, .max
= 22 },
400 .m2
= { .min
= 5, .max
= 9 },
401 .p
= { .min
= 28, .max
= 112 },
402 .p1
= { .min
= 2, .max
= 8 },
403 .p2
= { .dot_limit
= 225000,
404 .p2_slow
= 14, .p2_fast
= 14 },
407 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m
= {
408 .dot
= { .min
= 25000, .max
= 350000 },
409 .vco
= { .min
= 1760000, .max
= 3510000 },
410 .n
= { .min
= 1, .max
= 3 },
411 .m
= { .min
= 79, .max
= 126 },
412 .m1
= { .min
= 12, .max
= 22 },
413 .m2
= { .min
= 5, .max
= 9 },
414 .p
= { .min
= 14, .max
= 42 },
415 .p1
= { .min
= 2, .max
= 6 },
416 .p2
= { .dot_limit
= 225000,
417 .p2_slow
= 7, .p2_fast
= 7 },
420 static const struct intel_limit intel_limits_vlv
= {
422 * These are the data rate limits (measured in fast clocks)
423 * since those are the strictest limits we have. The fast
424 * clock and actual rate limits are more relaxed, so checking
425 * them would make no difference.
427 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
428 .vco
= { .min
= 4000000, .max
= 6000000 },
429 .n
= { .min
= 1, .max
= 7 },
430 .m1
= { .min
= 2, .max
= 3 },
431 .m2
= { .min
= 11, .max
= 156 },
432 .p1
= { .min
= 2, .max
= 3 },
433 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
436 static const struct intel_limit intel_limits_chv
= {
438 * These are the data rate limits (measured in fast clocks)
439 * since those are the strictest limits we have. The fast
440 * clock and actual rate limits are more relaxed, so checking
441 * them would make no difference.
443 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
444 .vco
= { .min
= 4800000, .max
= 6480000 },
445 .n
= { .min
= 1, .max
= 1 },
446 .m1
= { .min
= 2, .max
= 2 },
447 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
448 .p1
= { .min
= 2, .max
= 4 },
449 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
452 static const struct intel_limit intel_limits_bxt
= {
453 /* FIXME: find real dot limits */
454 .dot
= { .min
= 0, .max
= INT_MAX
},
455 .vco
= { .min
= 4800000, .max
= 6700000 },
456 .n
= { .min
= 1, .max
= 1 },
457 .m1
= { .min
= 2, .max
= 2 },
458 /* FIXME: find real m2 limits */
459 .m2
= { .min
= 2 << 22, .max
= 255 << 22 },
460 .p1
= { .min
= 2, .max
= 4 },
461 .p2
= { .p2_slow
= 1, .p2_fast
= 20 },
465 needs_modeset(struct drm_crtc_state
*state
)
467 return drm_atomic_crtc_needs_modeset(state
);
471 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
472 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
473 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
474 * The helpers' return value is the rate of the clock that is fed to the
475 * display engine's pipe which can be the above fast dot clock rate or a
476 * divided-down version of it.
478 /* m1 is reserved as 0 in Pineview, n is a ring counter */
479 static int pnv_calc_dpll_params(int refclk
, struct dpll
*clock
)
481 clock
->m
= clock
->m2
+ 2;
482 clock
->p
= clock
->p1
* clock
->p2
;
483 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
485 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
486 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
491 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
493 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
496 static int i9xx_calc_dpll_params(int refclk
, struct dpll
*clock
)
498 clock
->m
= i9xx_dpll_compute_m(clock
);
499 clock
->p
= clock
->p1
* clock
->p2
;
500 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
502 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
503 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
508 static int vlv_calc_dpll_params(int refclk
, struct dpll
*clock
)
510 clock
->m
= clock
->m1
* clock
->m2
;
511 clock
->p
= clock
->p1
* clock
->p2
;
512 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
514 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
515 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
517 return clock
->dot
/ 5;
520 int chv_calc_dpll_params(int refclk
, struct dpll
*clock
)
522 clock
->m
= clock
->m1
* clock
->m2
;
523 clock
->p
= clock
->p1
* clock
->p2
;
524 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
526 clock
->vco
= DIV_ROUND_CLOSEST_ULL((uint64_t)refclk
* clock
->m
,
528 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
530 return clock
->dot
/ 5;
533 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
535 * Returns whether the given set of divisors are valid for a given refclk with
536 * the given connectors.
539 static bool intel_PLL_is_valid(struct drm_i915_private
*dev_priv
,
540 const struct intel_limit
*limit
,
541 const struct dpll
*clock
)
543 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
544 INTELPllInvalid("n out of range\n");
545 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
546 INTELPllInvalid("p1 out of range\n");
547 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
548 INTELPllInvalid("m2 out of range\n");
549 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
550 INTELPllInvalid("m1 out of range\n");
552 if (!IS_PINEVIEW(dev_priv
) && !IS_VALLEYVIEW(dev_priv
) &&
553 !IS_CHERRYVIEW(dev_priv
) && !IS_GEN9_LP(dev_priv
))
554 if (clock
->m1
<= clock
->m2
)
555 INTELPllInvalid("m1 <= m2\n");
557 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
) &&
558 !IS_GEN9_LP(dev_priv
)) {
559 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
560 INTELPllInvalid("p out of range\n");
561 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
562 INTELPllInvalid("m out of range\n");
565 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
566 INTELPllInvalid("vco out of range\n");
567 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
568 * connector, etc., rather than just a single range.
570 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
571 INTELPllInvalid("dot out of range\n");
577 i9xx_select_p2_div(const struct intel_limit
*limit
,
578 const struct intel_crtc_state
*crtc_state
,
581 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
583 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
585 * For LVDS just rely on its current settings for dual-channel.
586 * We haven't figured out how to reliably set up different
587 * single/dual channel state, if we even can.
589 if (intel_is_dual_link_lvds(dev
))
590 return limit
->p2
.p2_fast
;
592 return limit
->p2
.p2_slow
;
594 if (target
< limit
->p2
.dot_limit
)
595 return limit
->p2
.p2_slow
;
597 return limit
->p2
.p2_fast
;
602 * Returns a set of divisors for the desired target clock with the given
603 * refclk, or FALSE. The returned values represent the clock equation:
604 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
606 * Target and reference clocks are specified in kHz.
608 * If match_clock is provided, then best_clock P divider must match the P
609 * divider from @match_clock used for LVDS downclocking.
612 i9xx_find_best_dpll(const struct intel_limit
*limit
,
613 struct intel_crtc_state
*crtc_state
,
614 int target
, int refclk
, struct dpll
*match_clock
,
615 struct dpll
*best_clock
)
617 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
621 memset(best_clock
, 0, sizeof(*best_clock
));
623 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
625 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
627 for (clock
.m2
= limit
->m2
.min
;
628 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
629 if (clock
.m2
>= clock
.m1
)
631 for (clock
.n
= limit
->n
.min
;
632 clock
.n
<= limit
->n
.max
; clock
.n
++) {
633 for (clock
.p1
= limit
->p1
.min
;
634 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
637 i9xx_calc_dpll_params(refclk
, &clock
);
638 if (!intel_PLL_is_valid(to_i915(dev
),
643 clock
.p
!= match_clock
->p
)
646 this_err
= abs(clock
.dot
- target
);
647 if (this_err
< err
) {
656 return (err
!= target
);
660 * Returns a set of divisors for the desired target clock with the given
661 * refclk, or FALSE. The returned values represent the clock equation:
662 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
664 * Target and reference clocks are specified in kHz.
666 * If match_clock is provided, then best_clock P divider must match the P
667 * divider from @match_clock used for LVDS downclocking.
670 pnv_find_best_dpll(const struct intel_limit
*limit
,
671 struct intel_crtc_state
*crtc_state
,
672 int target
, int refclk
, struct dpll
*match_clock
,
673 struct dpll
*best_clock
)
675 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
679 memset(best_clock
, 0, sizeof(*best_clock
));
681 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
683 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
685 for (clock
.m2
= limit
->m2
.min
;
686 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
687 for (clock
.n
= limit
->n
.min
;
688 clock
.n
<= limit
->n
.max
; clock
.n
++) {
689 for (clock
.p1
= limit
->p1
.min
;
690 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
693 pnv_calc_dpll_params(refclk
, &clock
);
694 if (!intel_PLL_is_valid(to_i915(dev
),
699 clock
.p
!= match_clock
->p
)
702 this_err
= abs(clock
.dot
- target
);
703 if (this_err
< err
) {
712 return (err
!= target
);
716 * Returns a set of divisors for the desired target clock with the given
717 * refclk, or FALSE. The returned values represent the clock equation:
718 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
720 * Target and reference clocks are specified in kHz.
722 * If match_clock is provided, then best_clock P divider must match the P
723 * divider from @match_clock used for LVDS downclocking.
726 g4x_find_best_dpll(const struct intel_limit
*limit
,
727 struct intel_crtc_state
*crtc_state
,
728 int target
, int refclk
, struct dpll
*match_clock
,
729 struct dpll
*best_clock
)
731 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
735 /* approximately equals target * 0.00585 */
736 int err_most
= (target
>> 8) + (target
>> 9);
738 memset(best_clock
, 0, sizeof(*best_clock
));
740 clock
.p2
= i9xx_select_p2_div(limit
, crtc_state
, target
);
742 max_n
= limit
->n
.max
;
743 /* based on hardware requirement, prefer smaller n to precision */
744 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
745 /* based on hardware requirement, prefere larger m1,m2 */
746 for (clock
.m1
= limit
->m1
.max
;
747 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
748 for (clock
.m2
= limit
->m2
.max
;
749 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
750 for (clock
.p1
= limit
->p1
.max
;
751 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
754 i9xx_calc_dpll_params(refclk
, &clock
);
755 if (!intel_PLL_is_valid(to_i915(dev
),
760 this_err
= abs(clock
.dot
- target
);
761 if (this_err
< err_most
) {
775 * Check if the calculated PLL configuration is more optimal compared to the
776 * best configuration and error found so far. Return the calculated error.
778 static bool vlv_PLL_is_optimal(struct drm_device
*dev
, int target_freq
,
779 const struct dpll
*calculated_clock
,
780 const struct dpll
*best_clock
,
781 unsigned int best_error_ppm
,
782 unsigned int *error_ppm
)
785 * For CHV ignore the error and consider only the P value.
786 * Prefer a bigger P value based on HW requirements.
788 if (IS_CHERRYVIEW(to_i915(dev
))) {
791 return calculated_clock
->p
> best_clock
->p
;
794 if (WARN_ON_ONCE(!target_freq
))
797 *error_ppm
= div_u64(1000000ULL *
798 abs(target_freq
- calculated_clock
->dot
),
801 * Prefer a better P value over a better (smaller) error if the error
802 * is small. Ensure this preference for future configurations too by
803 * setting the error to 0.
805 if (*error_ppm
< 100 && calculated_clock
->p
> best_clock
->p
) {
811 return *error_ppm
+ 10 < best_error_ppm
;
815 * Returns a set of divisors for the desired target clock with the given
816 * refclk, or FALSE. The returned values represent the clock equation:
817 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
820 vlv_find_best_dpll(const struct intel_limit
*limit
,
821 struct intel_crtc_state
*crtc_state
,
822 int target
, int refclk
, struct dpll
*match_clock
,
823 struct dpll
*best_clock
)
825 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
826 struct drm_device
*dev
= crtc
->base
.dev
;
828 unsigned int bestppm
= 1000000;
829 /* min update 19.2 MHz */
830 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
833 target
*= 5; /* fast clock */
835 memset(best_clock
, 0, sizeof(*best_clock
));
837 /* based on hardware requirement, prefer smaller n to precision */
838 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
839 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
840 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
841 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
842 clock
.p
= clock
.p1
* clock
.p2
;
843 /* based on hardware requirement, prefer bigger m1,m2 values */
844 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
847 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
850 vlv_calc_dpll_params(refclk
, &clock
);
852 if (!intel_PLL_is_valid(to_i915(dev
),
857 if (!vlv_PLL_is_optimal(dev
, target
,
875 * Returns a set of divisors for the desired target clock with the given
876 * refclk, or FALSE. The returned values represent the clock equation:
877 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
880 chv_find_best_dpll(const struct intel_limit
*limit
,
881 struct intel_crtc_state
*crtc_state
,
882 int target
, int refclk
, struct dpll
*match_clock
,
883 struct dpll
*best_clock
)
885 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
886 struct drm_device
*dev
= crtc
->base
.dev
;
887 unsigned int best_error_ppm
;
892 memset(best_clock
, 0, sizeof(*best_clock
));
893 best_error_ppm
= 1000000;
896 * Based on hardware doc, the n always set to 1, and m1 always
897 * set to 2. If requires to support 200Mhz refclk, we need to
898 * revisit this because n may not 1 anymore.
900 clock
.n
= 1, clock
.m1
= 2;
901 target
*= 5; /* fast clock */
903 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
904 for (clock
.p2
= limit
->p2
.p2_fast
;
905 clock
.p2
>= limit
->p2
.p2_slow
;
906 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
907 unsigned int error_ppm
;
909 clock
.p
= clock
.p1
* clock
.p2
;
911 m2
= DIV_ROUND_CLOSEST_ULL(((uint64_t)target
* clock
.p
*
912 clock
.n
) << 22, refclk
* clock
.m1
);
914 if (m2
> INT_MAX
/clock
.m1
)
919 chv_calc_dpll_params(refclk
, &clock
);
921 if (!intel_PLL_is_valid(to_i915(dev
), limit
, &clock
))
924 if (!vlv_PLL_is_optimal(dev
, target
, &clock
, best_clock
,
925 best_error_ppm
, &error_ppm
))
929 best_error_ppm
= error_ppm
;
937 bool bxt_find_best_dpll(struct intel_crtc_state
*crtc_state
, int target_clock
,
938 struct dpll
*best_clock
)
941 const struct intel_limit
*limit
= &intel_limits_bxt
;
943 return chv_find_best_dpll(limit
, crtc_state
,
944 target_clock
, refclk
, NULL
, best_clock
);
947 bool intel_crtc_active(struct intel_crtc
*crtc
)
949 /* Be paranoid as we can arrive here with only partial
950 * state retrieved from the hardware during setup.
952 * We can ditch the adjusted_mode.crtc_clock check as soon
953 * as Haswell has gained clock readout/fastboot support.
955 * We can ditch the crtc->primary->fb check as soon as we can
956 * properly reconstruct framebuffers.
958 * FIXME: The intel_crtc->active here should be switched to
959 * crtc->state->active once we have proper CRTC states wired up
962 return crtc
->active
&& crtc
->base
.primary
->state
->fb
&&
963 crtc
->config
->base
.adjusted_mode
.crtc_clock
;
966 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
969 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
971 return crtc
->config
->cpu_transcoder
;
974 static bool pipe_dsl_stopped(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
976 i915_reg_t reg
= PIPEDSL(pipe
);
980 if (IS_GEN2(dev_priv
))
981 line_mask
= DSL_LINEMASK_GEN2
;
983 line_mask
= DSL_LINEMASK_GEN3
;
985 line1
= I915_READ(reg
) & line_mask
;
987 line2
= I915_READ(reg
) & line_mask
;
989 return line1
== line2
;
993 * intel_wait_for_pipe_off - wait for pipe to turn off
994 * @crtc: crtc whose pipe to wait for
996 * After disabling a pipe, we can't wait for vblank in the usual way,
997 * spinning on the vblank interrupt status bit, since we won't actually
998 * see an interrupt when the pipe is disabled.
1000 * On Gen4 and above:
1001 * wait for the pipe register state bit to turn off
1004 * wait for the display line value to settle (it usually
1005 * ends up stopping at the start of the next frame).
1008 static void intel_wait_for_pipe_off(struct intel_crtc
*crtc
)
1010 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1011 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1012 enum pipe pipe
= crtc
->pipe
;
1014 if (INTEL_GEN(dev_priv
) >= 4) {
1015 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
1017 /* Wait for the Pipe State to go off */
1018 if (intel_wait_for_register(dev_priv
,
1019 reg
, I965_PIPECONF_ACTIVE
, 0,
1021 WARN(1, "pipe_off wait timed out\n");
1023 /* Wait for the display line to settle */
1024 if (wait_for(pipe_dsl_stopped(dev_priv
, pipe
), 100))
1025 WARN(1, "pipe_off wait timed out\n");
1029 /* Only for pre-ILK configs */
1030 void assert_pll(struct drm_i915_private
*dev_priv
,
1031 enum pipe pipe
, bool state
)
1036 val
= I915_READ(DPLL(pipe
));
1037 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1038 I915_STATE_WARN(cur_state
!= state
,
1039 "PLL state assertion failure (expected %s, current %s)\n",
1040 onoff(state
), onoff(cur_state
));
1043 /* XXX: the dsi pll is shared between MIPI DSI ports */
1044 void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1049 mutex_lock(&dev_priv
->sb_lock
);
1050 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1051 mutex_unlock(&dev_priv
->sb_lock
);
1053 cur_state
= val
& DSI_PLL_VCO_EN
;
1054 I915_STATE_WARN(cur_state
!= state
,
1055 "DSI PLL state assertion failure (expected %s, current %s)\n",
1056 onoff(state
), onoff(cur_state
));
1059 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1060 enum pipe pipe
, bool state
)
1063 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1066 if (HAS_DDI(dev_priv
)) {
1067 /* DDI does not have a specific FDI_TX register */
1068 u32 val
= I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder
));
1069 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1071 u32 val
= I915_READ(FDI_TX_CTL(pipe
));
1072 cur_state
= !!(val
& FDI_TX_ENABLE
);
1074 I915_STATE_WARN(cur_state
!= state
,
1075 "FDI TX state assertion failure (expected %s, current %s)\n",
1076 onoff(state
), onoff(cur_state
));
1078 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1079 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1081 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1082 enum pipe pipe
, bool state
)
1087 val
= I915_READ(FDI_RX_CTL(pipe
));
1088 cur_state
= !!(val
& FDI_RX_ENABLE
);
1089 I915_STATE_WARN(cur_state
!= state
,
1090 "FDI RX state assertion failure (expected %s, current %s)\n",
1091 onoff(state
), onoff(cur_state
));
1093 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1094 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1096 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1101 /* ILK FDI PLL is always enabled */
1102 if (IS_GEN5(dev_priv
))
1105 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1106 if (HAS_DDI(dev_priv
))
1109 val
= I915_READ(FDI_TX_CTL(pipe
));
1110 I915_STATE_WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1113 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1114 enum pipe pipe
, bool state
)
1119 val
= I915_READ(FDI_RX_CTL(pipe
));
1120 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1121 I915_STATE_WARN(cur_state
!= state
,
1122 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1123 onoff(state
), onoff(cur_state
));
1126 void assert_panel_unlocked(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1130 enum pipe panel_pipe
= PIPE_A
;
1133 if (WARN_ON(HAS_DDI(dev_priv
)))
1136 if (HAS_PCH_SPLIT(dev_priv
)) {
1139 pp_reg
= PP_CONTROL(0);
1140 port_sel
= I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK
;
1142 if (port_sel
== PANEL_PORT_SELECT_LVDS
&&
1143 I915_READ(PCH_LVDS
) & LVDS_PIPEB_SELECT
)
1144 panel_pipe
= PIPE_B
;
1145 /* XXX: else fix for eDP */
1146 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
1147 /* presumably write lock depends on pipe, not port select */
1148 pp_reg
= PP_CONTROL(pipe
);
1151 pp_reg
= PP_CONTROL(0);
1152 if (I915_READ(LVDS
) & LVDS_PIPEB_SELECT
)
1153 panel_pipe
= PIPE_B
;
1156 val
= I915_READ(pp_reg
);
1157 if (!(val
& PANEL_POWER_ON
) ||
1158 ((val
& PANEL_UNLOCK_MASK
) == PANEL_UNLOCK_REGS
))
1161 I915_STATE_WARN(panel_pipe
== pipe
&& locked
,
1162 "panel assertion failure, pipe %c regs locked\n",
1166 static void assert_cursor(struct drm_i915_private
*dev_priv
,
1167 enum pipe pipe
, bool state
)
1171 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
))
1172 cur_state
= I915_READ(CURCNTR(PIPE_A
)) & CURSOR_ENABLE
;
1174 cur_state
= I915_READ(CURCNTR(pipe
)) & CURSOR_MODE
;
1176 I915_STATE_WARN(cur_state
!= state
,
1177 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1178 pipe_name(pipe
), onoff(state
), onoff(cur_state
));
1180 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1181 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1183 void assert_pipe(struct drm_i915_private
*dev_priv
,
1184 enum pipe pipe
, bool state
)
1187 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1189 enum intel_display_power_domain power_domain
;
1191 /* we keep both pipes enabled on 830 */
1192 if (IS_I830(dev_priv
))
1195 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
1196 if (intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
1197 u32 val
= I915_READ(PIPECONF(cpu_transcoder
));
1198 cur_state
= !!(val
& PIPECONF_ENABLE
);
1200 intel_display_power_put(dev_priv
, power_domain
);
1205 I915_STATE_WARN(cur_state
!= state
,
1206 "pipe %c assertion failure (expected %s, current %s)\n",
1207 pipe_name(pipe
), onoff(state
), onoff(cur_state
));
1210 static void assert_plane(struct drm_i915_private
*dev_priv
,
1211 enum plane plane
, bool state
)
1216 val
= I915_READ(DSPCNTR(plane
));
1217 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1218 I915_STATE_WARN(cur_state
!= state
,
1219 "plane %c assertion failure (expected %s, current %s)\n",
1220 plane_name(plane
), onoff(state
), onoff(cur_state
));
1223 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1224 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1226 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1231 /* Primary planes are fixed to pipes on gen4+ */
1232 if (INTEL_GEN(dev_priv
) >= 4) {
1233 u32 val
= I915_READ(DSPCNTR(pipe
));
1234 I915_STATE_WARN(val
& DISPLAY_PLANE_ENABLE
,
1235 "plane %c assertion failure, should be disabled but not\n",
1240 /* Need to check both planes against the pipe */
1241 for_each_pipe(dev_priv
, i
) {
1242 u32 val
= I915_READ(DSPCNTR(i
));
1243 enum pipe cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1244 DISPPLANE_SEL_PIPE_SHIFT
;
1245 I915_STATE_WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1246 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1247 plane_name(i
), pipe_name(pipe
));
1251 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1256 if (INTEL_GEN(dev_priv
) >= 9) {
1257 for_each_sprite(dev_priv
, pipe
, sprite
) {
1258 u32 val
= I915_READ(PLANE_CTL(pipe
, sprite
));
1259 I915_STATE_WARN(val
& PLANE_CTL_ENABLE
,
1260 "plane %d assertion failure, should be off on pipe %c but is still active\n",
1261 sprite
, pipe_name(pipe
));
1263 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
1264 for_each_sprite(dev_priv
, pipe
, sprite
) {
1265 u32 val
= I915_READ(SPCNTR(pipe
, PLANE_SPRITE0
+ sprite
));
1266 I915_STATE_WARN(val
& SP_ENABLE
,
1267 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1268 sprite_name(pipe
, sprite
), pipe_name(pipe
));
1270 } else if (INTEL_GEN(dev_priv
) >= 7) {
1271 u32 val
= I915_READ(SPRCTL(pipe
));
1272 I915_STATE_WARN(val
& SPRITE_ENABLE
,
1273 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1274 plane_name(pipe
), pipe_name(pipe
));
1275 } else if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
)) {
1276 u32 val
= I915_READ(DVSCNTR(pipe
));
1277 I915_STATE_WARN(val
& DVS_ENABLE
,
1278 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1279 plane_name(pipe
), pipe_name(pipe
));
1283 static void assert_vblank_disabled(struct drm_crtc
*crtc
)
1285 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc
) == 0))
1286 drm_crtc_vblank_put(crtc
);
1289 void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1295 val
= I915_READ(PCH_TRANSCONF(pipe
));
1296 enabled
= !!(val
& TRANS_ENABLE
);
1297 I915_STATE_WARN(enabled
,
1298 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1302 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1303 enum pipe pipe
, u32 port_sel
, u32 val
)
1305 if ((val
& DP_PORT_EN
) == 0)
1308 if (HAS_PCH_CPT(dev_priv
)) {
1309 u32 trans_dp_ctl
= I915_READ(TRANS_DP_CTL(pipe
));
1310 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1312 } else if (IS_CHERRYVIEW(dev_priv
)) {
1313 if ((val
& DP_PIPE_MASK_CHV
) != DP_PIPE_SELECT_CHV(pipe
))
1316 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1322 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1323 enum pipe pipe
, u32 val
)
1325 if ((val
& SDVO_ENABLE
) == 0)
1328 if (HAS_PCH_CPT(dev_priv
)) {
1329 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1331 } else if (IS_CHERRYVIEW(dev_priv
)) {
1332 if ((val
& SDVO_PIPE_SEL_MASK_CHV
) != SDVO_PIPE_SEL_CHV(pipe
))
1335 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1341 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1342 enum pipe pipe
, u32 val
)
1344 if ((val
& LVDS_PORT_EN
) == 0)
1347 if (HAS_PCH_CPT(dev_priv
)) {
1348 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1351 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1357 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1358 enum pipe pipe
, u32 val
)
1360 if ((val
& ADPA_DAC_ENABLE
) == 0)
1362 if (HAS_PCH_CPT(dev_priv
)) {
1363 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1366 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1372 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1373 enum pipe pipe
, i915_reg_t reg
,
1376 u32 val
= I915_READ(reg
);
1377 I915_STATE_WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1378 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1379 i915_mmio_reg_offset(reg
), pipe_name(pipe
));
1381 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
) && (val
& DP_PORT_EN
) == 0
1382 && (val
& DP_PIPEB_SELECT
),
1383 "IBX PCH dp port still using transcoder B\n");
1386 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1387 enum pipe pipe
, i915_reg_t reg
)
1389 u32 val
= I915_READ(reg
);
1390 I915_STATE_WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1391 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1392 i915_mmio_reg_offset(reg
), pipe_name(pipe
));
1394 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
) && (val
& SDVO_ENABLE
) == 0
1395 && (val
& SDVO_PIPE_B_SELECT
),
1396 "IBX PCH hdmi port still using transcoder B\n");
1399 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1404 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1405 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1406 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1408 val
= I915_READ(PCH_ADPA
);
1409 I915_STATE_WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1410 "PCH VGA enabled on transcoder %c, should be disabled\n",
1413 val
= I915_READ(PCH_LVDS
);
1414 I915_STATE_WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1415 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1418 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1419 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1420 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1423 static void _vlv_enable_pll(struct intel_crtc
*crtc
,
1424 const struct intel_crtc_state
*pipe_config
)
1426 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1427 enum pipe pipe
= crtc
->pipe
;
1429 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1430 POSTING_READ(DPLL(pipe
));
1433 if (intel_wait_for_register(dev_priv
,
1438 DRM_ERROR("DPLL %d failed to lock\n", pipe
);
1441 static void vlv_enable_pll(struct intel_crtc
*crtc
,
1442 const struct intel_crtc_state
*pipe_config
)
1444 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1445 enum pipe pipe
= crtc
->pipe
;
1447 assert_pipe_disabled(dev_priv
, pipe
);
1449 /* PLL is protected by panel, make sure we can write it */
1450 assert_panel_unlocked(dev_priv
, pipe
);
1452 if (pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
)
1453 _vlv_enable_pll(crtc
, pipe_config
);
1455 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1456 POSTING_READ(DPLL_MD(pipe
));
1460 static void _chv_enable_pll(struct intel_crtc
*crtc
,
1461 const struct intel_crtc_state
*pipe_config
)
1463 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1464 enum pipe pipe
= crtc
->pipe
;
1465 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1468 mutex_lock(&dev_priv
->sb_lock
);
1470 /* Enable back the 10bit clock to display controller */
1471 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1472 tmp
|= DPIO_DCLKP_EN
;
1473 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), tmp
);
1475 mutex_unlock(&dev_priv
->sb_lock
);
1478 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1483 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1485 /* Check PLL is locked */
1486 if (intel_wait_for_register(dev_priv
,
1487 DPLL(pipe
), DPLL_LOCK_VLV
, DPLL_LOCK_VLV
,
1489 DRM_ERROR("PLL %d failed to lock\n", pipe
);
1492 static void chv_enable_pll(struct intel_crtc
*crtc
,
1493 const struct intel_crtc_state
*pipe_config
)
1495 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1496 enum pipe pipe
= crtc
->pipe
;
1498 assert_pipe_disabled(dev_priv
, pipe
);
1500 /* PLL is protected by panel, make sure we can write it */
1501 assert_panel_unlocked(dev_priv
, pipe
);
1503 if (pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
)
1504 _chv_enable_pll(crtc
, pipe_config
);
1506 if (pipe
!= PIPE_A
) {
1508 * WaPixelRepeatModeFixForC0:chv
1510 * DPLLCMD is AWOL. Use chicken bits to propagate
1511 * the value from DPLLBMD to either pipe B or C.
1513 I915_WRITE(CBR4_VLV
, pipe
== PIPE_B
? CBR_DPLLBMD_PIPE_B
: CBR_DPLLBMD_PIPE_C
);
1514 I915_WRITE(DPLL_MD(PIPE_B
), pipe_config
->dpll_hw_state
.dpll_md
);
1515 I915_WRITE(CBR4_VLV
, 0);
1516 dev_priv
->chv_dpll_md
[pipe
] = pipe_config
->dpll_hw_state
.dpll_md
;
1519 * DPLLB VGA mode also seems to cause problems.
1520 * We should always have it disabled.
1522 WARN_ON((I915_READ(DPLL(PIPE_B
)) & DPLL_VGA_MODE_DIS
) == 0);
1524 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1525 POSTING_READ(DPLL_MD(pipe
));
1529 static int intel_num_dvo_pipes(struct drm_i915_private
*dev_priv
)
1531 struct intel_crtc
*crtc
;
1534 for_each_intel_crtc(&dev_priv
->drm
, crtc
) {
1535 count
+= crtc
->base
.state
->active
&&
1536 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_DVO
);
1542 static void i9xx_enable_pll(struct intel_crtc
*crtc
)
1544 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1545 i915_reg_t reg
= DPLL(crtc
->pipe
);
1546 u32 dpll
= crtc
->config
->dpll_hw_state
.dpll
;
1549 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1551 /* PLL is protected by panel, make sure we can write it */
1552 if (IS_MOBILE(dev_priv
) && !IS_I830(dev_priv
))
1553 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1555 /* Enable DVO 2x clock on both PLLs if necessary */
1556 if (IS_I830(dev_priv
) && intel_num_dvo_pipes(dev_priv
) > 0) {
1558 * It appears to be important that we don't enable this
1559 * for the current pipe before otherwise configuring the
1560 * PLL. No idea how this should be handled if multiple
1561 * DVO outputs are enabled simultaneosly.
1563 dpll
|= DPLL_DVO_2X_MODE
;
1564 I915_WRITE(DPLL(!crtc
->pipe
),
1565 I915_READ(DPLL(!crtc
->pipe
)) | DPLL_DVO_2X_MODE
);
1569 * Apparently we need to have VGA mode enabled prior to changing
1570 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1571 * dividers, even though the register value does change.
1575 I915_WRITE(reg
, dpll
);
1577 /* Wait for the clocks to stabilize. */
1581 if (INTEL_GEN(dev_priv
) >= 4) {
1582 I915_WRITE(DPLL_MD(crtc
->pipe
),
1583 crtc
->config
->dpll_hw_state
.dpll_md
);
1585 /* The pixel multiplier can only be updated once the
1586 * DPLL is enabled and the clocks are stable.
1588 * So write it again.
1590 I915_WRITE(reg
, dpll
);
1593 /* We do this three times for luck */
1594 for (i
= 0; i
< 3; i
++) {
1595 I915_WRITE(reg
, dpll
);
1597 udelay(150); /* wait for warmup */
1602 * i9xx_disable_pll - disable a PLL
1603 * @dev_priv: i915 private structure
1604 * @pipe: pipe PLL to disable
1606 * Disable the PLL for @pipe, making sure the pipe is off first.
1608 * Note! This is for pre-ILK only.
1610 static void i9xx_disable_pll(struct intel_crtc
*crtc
)
1612 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1613 enum pipe pipe
= crtc
->pipe
;
1615 /* Disable DVO 2x clock on both PLLs if necessary */
1616 if (IS_I830(dev_priv
) &&
1617 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_DVO
) &&
1618 !intel_num_dvo_pipes(dev_priv
)) {
1619 I915_WRITE(DPLL(PIPE_B
),
1620 I915_READ(DPLL(PIPE_B
)) & ~DPLL_DVO_2X_MODE
);
1621 I915_WRITE(DPLL(PIPE_A
),
1622 I915_READ(DPLL(PIPE_A
)) & ~DPLL_DVO_2X_MODE
);
1625 /* Don't disable pipe or pipe PLLs if needed */
1626 if (IS_I830(dev_priv
))
1629 /* Make sure the pipe isn't still relying on us */
1630 assert_pipe_disabled(dev_priv
, pipe
);
1632 I915_WRITE(DPLL(pipe
), DPLL_VGA_MODE_DIS
);
1633 POSTING_READ(DPLL(pipe
));
1636 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1640 /* Make sure the pipe isn't still relying on us */
1641 assert_pipe_disabled(dev_priv
, pipe
);
1643 val
= DPLL_INTEGRATED_REF_CLK_VLV
|
1644 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1646 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1648 I915_WRITE(DPLL(pipe
), val
);
1649 POSTING_READ(DPLL(pipe
));
1652 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1654 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1657 /* Make sure the pipe isn't still relying on us */
1658 assert_pipe_disabled(dev_priv
, pipe
);
1660 val
= DPLL_SSC_REF_CLK_CHV
|
1661 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1663 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1665 I915_WRITE(DPLL(pipe
), val
);
1666 POSTING_READ(DPLL(pipe
));
1668 mutex_lock(&dev_priv
->sb_lock
);
1670 /* Disable 10bit clock to display controller */
1671 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1672 val
&= ~DPIO_DCLKP_EN
;
1673 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1675 mutex_unlock(&dev_priv
->sb_lock
);
1678 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1679 struct intel_digital_port
*dport
,
1680 unsigned int expected_mask
)
1683 i915_reg_t dpll_reg
;
1685 switch (dport
->port
) {
1687 port_mask
= DPLL_PORTB_READY_MASK
;
1691 port_mask
= DPLL_PORTC_READY_MASK
;
1693 expected_mask
<<= 4;
1696 port_mask
= DPLL_PORTD_READY_MASK
;
1697 dpll_reg
= DPIO_PHY_STATUS
;
1703 if (intel_wait_for_register(dev_priv
,
1704 dpll_reg
, port_mask
, expected_mask
,
1706 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1707 port_name(dport
->port
), I915_READ(dpll_reg
) & port_mask
, expected_mask
);
1710 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1713 struct intel_crtc
*intel_crtc
= intel_get_crtc_for_pipe(dev_priv
,
1716 uint32_t val
, pipeconf_val
;
1718 /* Make sure PCH DPLL is enabled */
1719 assert_shared_dpll_enabled(dev_priv
, intel_crtc
->config
->shared_dpll
);
1721 /* FDI must be feeding us bits for PCH ports */
1722 assert_fdi_tx_enabled(dev_priv
, pipe
);
1723 assert_fdi_rx_enabled(dev_priv
, pipe
);
1725 if (HAS_PCH_CPT(dev_priv
)) {
1726 /* Workaround: Set the timing override bit before enabling the
1727 * pch transcoder. */
1728 reg
= TRANS_CHICKEN2(pipe
);
1729 val
= I915_READ(reg
);
1730 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1731 I915_WRITE(reg
, val
);
1734 reg
= PCH_TRANSCONF(pipe
);
1735 val
= I915_READ(reg
);
1736 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1738 if (HAS_PCH_IBX(dev_priv
)) {
1740 * Make the BPC in transcoder be consistent with
1741 * that in pipeconf reg. For HDMI we must use 8bpc
1742 * here for both 8bpc and 12bpc.
1744 val
&= ~PIPECONF_BPC_MASK
;
1745 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_HDMI
))
1746 val
|= PIPECONF_8BPC
;
1748 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
1751 val
&= ~TRANS_INTERLACE_MASK
;
1752 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
1753 if (HAS_PCH_IBX(dev_priv
) &&
1754 intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
1755 val
|= TRANS_LEGACY_INTERLACED_ILK
;
1757 val
|= TRANS_INTERLACED
;
1759 val
|= TRANS_PROGRESSIVE
;
1761 I915_WRITE(reg
, val
| TRANS_ENABLE
);
1762 if (intel_wait_for_register(dev_priv
,
1763 reg
, TRANS_STATE_ENABLE
, TRANS_STATE_ENABLE
,
1765 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
1768 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1769 enum transcoder cpu_transcoder
)
1771 u32 val
, pipeconf_val
;
1773 /* FDI must be feeding us bits for PCH ports */
1774 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
1775 assert_fdi_rx_enabled(dev_priv
, PIPE_A
);
1777 /* Workaround: set timing override bit. */
1778 val
= I915_READ(TRANS_CHICKEN2(PIPE_A
));
1779 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1780 I915_WRITE(TRANS_CHICKEN2(PIPE_A
), val
);
1783 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
1785 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
1786 PIPECONF_INTERLACED_ILK
)
1787 val
|= TRANS_INTERLACED
;
1789 val
|= TRANS_PROGRESSIVE
;
1791 I915_WRITE(LPT_TRANSCONF
, val
);
1792 if (intel_wait_for_register(dev_priv
,
1797 DRM_ERROR("Failed to enable PCH transcoder\n");
1800 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1806 /* FDI relies on the transcoder */
1807 assert_fdi_tx_disabled(dev_priv
, pipe
);
1808 assert_fdi_rx_disabled(dev_priv
, pipe
);
1810 /* Ports must be off as well */
1811 assert_pch_ports_disabled(dev_priv
, pipe
);
1813 reg
= PCH_TRANSCONF(pipe
);
1814 val
= I915_READ(reg
);
1815 val
&= ~TRANS_ENABLE
;
1816 I915_WRITE(reg
, val
);
1817 /* wait for PCH transcoder off, transcoder state */
1818 if (intel_wait_for_register(dev_priv
,
1819 reg
, TRANS_STATE_ENABLE
, 0,
1821 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
1823 if (HAS_PCH_CPT(dev_priv
)) {
1824 /* Workaround: Clear the timing override chicken bit again. */
1825 reg
= TRANS_CHICKEN2(pipe
);
1826 val
= I915_READ(reg
);
1827 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1828 I915_WRITE(reg
, val
);
1832 void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
1836 val
= I915_READ(LPT_TRANSCONF
);
1837 val
&= ~TRANS_ENABLE
;
1838 I915_WRITE(LPT_TRANSCONF
, val
);
1839 /* wait for PCH transcoder off, transcoder state */
1840 if (intel_wait_for_register(dev_priv
,
1841 LPT_TRANSCONF
, TRANS_STATE_ENABLE
, 0,
1843 DRM_ERROR("Failed to disable PCH transcoder\n");
1845 /* Workaround: clear timing override bit. */
1846 val
= I915_READ(TRANS_CHICKEN2(PIPE_A
));
1847 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1848 I915_WRITE(TRANS_CHICKEN2(PIPE_A
), val
);
1851 enum pipe
intel_crtc_pch_transcoder(struct intel_crtc
*crtc
)
1853 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1855 WARN_ON(!crtc
->config
->has_pch_encoder
);
1857 if (HAS_PCH_LPT(dev_priv
))
1864 * intel_enable_pipe - enable a pipe, asserting requirements
1865 * @crtc: crtc responsible for the pipe
1867 * Enable @crtc's pipe, making sure that various hardware specific requirements
1868 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
1870 static void intel_enable_pipe(struct intel_crtc
*crtc
)
1872 struct drm_device
*dev
= crtc
->base
.dev
;
1873 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1874 enum pipe pipe
= crtc
->pipe
;
1875 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1879 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe
));
1881 assert_planes_disabled(dev_priv
, pipe
);
1882 assert_cursor_disabled(dev_priv
, pipe
);
1883 assert_sprites_disabled(dev_priv
, pipe
);
1886 * A pipe without a PLL won't actually be able to drive bits from
1887 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1890 if (HAS_GMCH_DISPLAY(dev_priv
)) {
1891 if (intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_DSI
))
1892 assert_dsi_pll_enabled(dev_priv
);
1894 assert_pll_enabled(dev_priv
, pipe
);
1896 if (crtc
->config
->has_pch_encoder
) {
1897 /* if driving the PCH, we need FDI enabled */
1898 assert_fdi_rx_pll_enabled(dev_priv
,
1899 intel_crtc_pch_transcoder(crtc
));
1900 assert_fdi_tx_pll_enabled(dev_priv
,
1901 (enum pipe
) cpu_transcoder
);
1903 /* FIXME: assert CPU port conditions for SNB+ */
1906 reg
= PIPECONF(cpu_transcoder
);
1907 val
= I915_READ(reg
);
1908 if (val
& PIPECONF_ENABLE
) {
1909 /* we keep both pipes enabled on 830 */
1910 WARN_ON(!IS_I830(dev_priv
));
1914 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
1918 * Until the pipe starts DSL will read as 0, which would cause
1919 * an apparent vblank timestamp jump, which messes up also the
1920 * frame count when it's derived from the timestamps. So let's
1921 * wait for the pipe to start properly before we call
1922 * drm_crtc_vblank_on()
1924 if (dev
->max_vblank_count
== 0 &&
1925 wait_for(intel_get_crtc_scanline(crtc
) != crtc
->scanline_offset
, 50))
1926 DRM_ERROR("pipe %c didn't start\n", pipe_name(pipe
));
1930 * intel_disable_pipe - disable a pipe, asserting requirements
1931 * @crtc: crtc whose pipes is to be disabled
1933 * Disable the pipe of @crtc, making sure that various hardware
1934 * specific requirements are met, if applicable, e.g. plane
1935 * disabled, panel fitter off, etc.
1937 * Will wait until the pipe has shut down before returning.
1939 static void intel_disable_pipe(struct intel_crtc
*crtc
)
1941 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1942 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1943 enum pipe pipe
= crtc
->pipe
;
1947 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe
));
1950 * Make sure planes won't keep trying to pump pixels to us,
1951 * or we might hang the display.
1953 assert_planes_disabled(dev_priv
, pipe
);
1954 assert_cursor_disabled(dev_priv
, pipe
);
1955 assert_sprites_disabled(dev_priv
, pipe
);
1957 reg
= PIPECONF(cpu_transcoder
);
1958 val
= I915_READ(reg
);
1959 if ((val
& PIPECONF_ENABLE
) == 0)
1963 * Double wide has implications for planes
1964 * so best keep it disabled when not needed.
1966 if (crtc
->config
->double_wide
)
1967 val
&= ~PIPECONF_DOUBLE_WIDE
;
1969 /* Don't disable pipe or pipe PLLs if needed */
1970 if (!IS_I830(dev_priv
))
1971 val
&= ~PIPECONF_ENABLE
;
1973 I915_WRITE(reg
, val
);
1974 if ((val
& PIPECONF_ENABLE
) == 0)
1975 intel_wait_for_pipe_off(crtc
);
1978 static unsigned int intel_tile_size(const struct drm_i915_private
*dev_priv
)
1980 return IS_GEN2(dev_priv
) ? 2048 : 4096;
1984 intel_tile_width_bytes(const struct drm_framebuffer
*fb
, int plane
)
1986 struct drm_i915_private
*dev_priv
= to_i915(fb
->dev
);
1987 unsigned int cpp
= fb
->format
->cpp
[plane
];
1989 switch (fb
->modifier
) {
1990 case DRM_FORMAT_MOD_LINEAR
:
1992 case I915_FORMAT_MOD_X_TILED
:
1993 if (IS_GEN2(dev_priv
))
1997 case I915_FORMAT_MOD_Y_TILED
:
1998 if (IS_GEN2(dev_priv
) || HAS_128_BYTE_Y_TILING(dev_priv
))
2002 case I915_FORMAT_MOD_Yf_TILED
:
2018 MISSING_CASE(fb
->modifier
);
2024 intel_tile_height(const struct drm_framebuffer
*fb
, int plane
)
2026 if (fb
->modifier
== DRM_FORMAT_MOD_LINEAR
)
2029 return intel_tile_size(to_i915(fb
->dev
)) /
2030 intel_tile_width_bytes(fb
, plane
);
2033 /* Return the tile dimensions in pixel units */
2034 static void intel_tile_dims(const struct drm_framebuffer
*fb
, int plane
,
2035 unsigned int *tile_width
,
2036 unsigned int *tile_height
)
2038 unsigned int tile_width_bytes
= intel_tile_width_bytes(fb
, plane
);
2039 unsigned int cpp
= fb
->format
->cpp
[plane
];
2041 *tile_width
= tile_width_bytes
/ cpp
;
2042 *tile_height
= intel_tile_size(to_i915(fb
->dev
)) / tile_width_bytes
;
2046 intel_fb_align_height(const struct drm_framebuffer
*fb
,
2047 int plane
, unsigned int height
)
2049 unsigned int tile_height
= intel_tile_height(fb
, plane
);
2051 return ALIGN(height
, tile_height
);
2054 unsigned int intel_rotation_info_size(const struct intel_rotation_info
*rot_info
)
2056 unsigned int size
= 0;
2059 for (i
= 0 ; i
< ARRAY_SIZE(rot_info
->plane
); i
++)
2060 size
+= rot_info
->plane
[i
].width
* rot_info
->plane
[i
].height
;
2066 intel_fill_fb_ggtt_view(struct i915_ggtt_view
*view
,
2067 const struct drm_framebuffer
*fb
,
2068 unsigned int rotation
)
2070 view
->type
= I915_GGTT_VIEW_NORMAL
;
2071 if (drm_rotation_90_or_270(rotation
)) {
2072 view
->type
= I915_GGTT_VIEW_ROTATED
;
2073 view
->rotated
= to_intel_framebuffer(fb
)->rot_info
;
2077 static unsigned int intel_cursor_alignment(const struct drm_i915_private
*dev_priv
)
2079 if (IS_I830(dev_priv
))
2081 else if (IS_I85X(dev_priv
))
2083 else if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
))
2089 static unsigned int intel_linear_alignment(const struct drm_i915_private
*dev_priv
)
2091 if (INTEL_INFO(dev_priv
)->gen
>= 9)
2093 else if (IS_I965G(dev_priv
) || IS_I965GM(dev_priv
) ||
2094 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
2096 else if (INTEL_INFO(dev_priv
)->gen
>= 4)
2102 static unsigned int intel_surf_alignment(const struct drm_framebuffer
*fb
,
2105 struct drm_i915_private
*dev_priv
= to_i915(fb
->dev
);
2107 /* AUX_DIST needs only 4K alignment */
2108 if (fb
->format
->format
== DRM_FORMAT_NV12
&& plane
== 1)
2111 switch (fb
->modifier
) {
2112 case DRM_FORMAT_MOD_LINEAR
:
2113 return intel_linear_alignment(dev_priv
);
2114 case I915_FORMAT_MOD_X_TILED
:
2115 if (INTEL_GEN(dev_priv
) >= 9)
2118 case I915_FORMAT_MOD_Y_TILED
:
2119 case I915_FORMAT_MOD_Yf_TILED
:
2120 return 1 * 1024 * 1024;
2122 MISSING_CASE(fb
->modifier
);
2128 intel_pin_and_fence_fb_obj(struct drm_framebuffer
*fb
, unsigned int rotation
)
2130 struct drm_device
*dev
= fb
->dev
;
2131 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2132 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2133 struct i915_ggtt_view view
;
2134 struct i915_vma
*vma
;
2137 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
2139 alignment
= intel_surf_alignment(fb
, 0);
2141 intel_fill_fb_ggtt_view(&view
, fb
, rotation
);
2143 /* Note that the w/a also requires 64 PTE of padding following the
2144 * bo. We currently fill all unused PTE with the shadow page and so
2145 * we should always have valid PTE following the scanout preventing
2148 if (intel_scanout_needs_vtd_wa(dev_priv
) && alignment
< 256 * 1024)
2149 alignment
= 256 * 1024;
2152 * Global gtt pte registers are special registers which actually forward
2153 * writes to a chunk of system memory. Which means that there is no risk
2154 * that the register values disappear as soon as we call
2155 * intel_runtime_pm_put(), so it is correct to wrap only the
2156 * pin/unpin/fence and not more.
2158 intel_runtime_pm_get(dev_priv
);
2160 vma
= i915_gem_object_pin_to_display_plane(obj
, alignment
, &view
);
2164 if (i915_vma_is_map_and_fenceable(vma
)) {
2165 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2166 * fence, whereas 965+ only requires a fence if using
2167 * framebuffer compression. For simplicity, we always, when
2168 * possible, install a fence as the cost is not that onerous.
2170 * If we fail to fence the tiled scanout, then either the
2171 * modeset will reject the change (which is highly unlikely as
2172 * the affected systems, all but one, do not have unmappable
2173 * space) or we will not be able to enable full powersaving
2174 * techniques (also likely not to apply due to various limits
2175 * FBC and the like impose on the size of the buffer, which
2176 * presumably we violated anyway with this unmappable buffer).
2177 * Anyway, it is presumably better to stumble onwards with
2178 * something and try to run the system in a "less than optimal"
2179 * mode that matches the user configuration.
2181 if (i915_vma_get_fence(vma
) == 0)
2182 i915_vma_pin_fence(vma
);
2187 intel_runtime_pm_put(dev_priv
);
2191 void intel_unpin_fb_vma(struct i915_vma
*vma
)
2193 lockdep_assert_held(&vma
->vm
->i915
->drm
.struct_mutex
);
2195 i915_vma_unpin_fence(vma
);
2196 i915_gem_object_unpin_from_display_plane(vma
);
2200 static int intel_fb_pitch(const struct drm_framebuffer
*fb
, int plane
,
2201 unsigned int rotation
)
2203 if (drm_rotation_90_or_270(rotation
))
2204 return to_intel_framebuffer(fb
)->rotated
[plane
].pitch
;
2206 return fb
->pitches
[plane
];
2210 * Convert the x/y offsets into a linear offset.
2211 * Only valid with 0/180 degree rotation, which is fine since linear
2212 * offset is only used with linear buffers on pre-hsw and tiled buffers
2213 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2215 u32
intel_fb_xy_to_linear(int x
, int y
,
2216 const struct intel_plane_state
*state
,
2219 const struct drm_framebuffer
*fb
= state
->base
.fb
;
2220 unsigned int cpp
= fb
->format
->cpp
[plane
];
2221 unsigned int pitch
= fb
->pitches
[plane
];
2223 return y
* pitch
+ x
* cpp
;
2227 * Add the x/y offsets derived from fb->offsets[] to the user
2228 * specified plane src x/y offsets. The resulting x/y offsets
2229 * specify the start of scanout from the beginning of the gtt mapping.
2231 void intel_add_fb_offsets(int *x
, int *y
,
2232 const struct intel_plane_state
*state
,
2236 const struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(state
->base
.fb
);
2237 unsigned int rotation
= state
->base
.rotation
;
2239 if (drm_rotation_90_or_270(rotation
)) {
2240 *x
+= intel_fb
->rotated
[plane
].x
;
2241 *y
+= intel_fb
->rotated
[plane
].y
;
2243 *x
+= intel_fb
->normal
[plane
].x
;
2244 *y
+= intel_fb
->normal
[plane
].y
;
2249 * Input tile dimensions and pitch must already be
2250 * rotated to match x and y, and in pixel units.
2252 static u32
_intel_adjust_tile_offset(int *x
, int *y
,
2253 unsigned int tile_width
,
2254 unsigned int tile_height
,
2255 unsigned int tile_size
,
2256 unsigned int pitch_tiles
,
2260 unsigned int pitch_pixels
= pitch_tiles
* tile_width
;
2263 WARN_ON(old_offset
& (tile_size
- 1));
2264 WARN_ON(new_offset
& (tile_size
- 1));
2265 WARN_ON(new_offset
> old_offset
);
2267 tiles
= (old_offset
- new_offset
) / tile_size
;
2269 *y
+= tiles
/ pitch_tiles
* tile_height
;
2270 *x
+= tiles
% pitch_tiles
* tile_width
;
2272 /* minimize x in case it got needlessly big */
2273 *y
+= *x
/ pitch_pixels
* tile_height
;
2280 * Adjust the tile offset by moving the difference into
2283 static u32
intel_adjust_tile_offset(int *x
, int *y
,
2284 const struct intel_plane_state
*state
, int plane
,
2285 u32 old_offset
, u32 new_offset
)
2287 const struct drm_i915_private
*dev_priv
= to_i915(state
->base
.plane
->dev
);
2288 const struct drm_framebuffer
*fb
= state
->base
.fb
;
2289 unsigned int cpp
= fb
->format
->cpp
[plane
];
2290 unsigned int rotation
= state
->base
.rotation
;
2291 unsigned int pitch
= intel_fb_pitch(fb
, plane
, rotation
);
2293 WARN_ON(new_offset
> old_offset
);
2295 if (fb
->modifier
!= DRM_FORMAT_MOD_LINEAR
) {
2296 unsigned int tile_size
, tile_width
, tile_height
;
2297 unsigned int pitch_tiles
;
2299 tile_size
= intel_tile_size(dev_priv
);
2300 intel_tile_dims(fb
, plane
, &tile_width
, &tile_height
);
2302 if (drm_rotation_90_or_270(rotation
)) {
2303 pitch_tiles
= pitch
/ tile_height
;
2304 swap(tile_width
, tile_height
);
2306 pitch_tiles
= pitch
/ (tile_width
* cpp
);
2309 _intel_adjust_tile_offset(x
, y
, tile_width
, tile_height
,
2310 tile_size
, pitch_tiles
,
2311 old_offset
, new_offset
);
2313 old_offset
+= *y
* pitch
+ *x
* cpp
;
2315 *y
= (old_offset
- new_offset
) / pitch
;
2316 *x
= ((old_offset
- new_offset
) - *y
* pitch
) / cpp
;
2323 * Computes the linear offset to the base tile and adjusts
2324 * x, y. bytes per pixel is assumed to be a power-of-two.
2326 * In the 90/270 rotated case, x and y are assumed
2327 * to be already rotated to match the rotated GTT view, and
2328 * pitch is the tile_height aligned framebuffer height.
2330 * This function is used when computing the derived information
2331 * under intel_framebuffer, so using any of that information
2332 * here is not allowed. Anything under drm_framebuffer can be
2333 * used. This is why the user has to pass in the pitch since it
2334 * is specified in the rotated orientation.
2336 static u32
_intel_compute_tile_offset(const struct drm_i915_private
*dev_priv
,
2338 const struct drm_framebuffer
*fb
, int plane
,
2340 unsigned int rotation
,
2343 uint64_t fb_modifier
= fb
->modifier
;
2344 unsigned int cpp
= fb
->format
->cpp
[plane
];
2345 u32 offset
, offset_aligned
;
2350 if (fb_modifier
!= DRM_FORMAT_MOD_LINEAR
) {
2351 unsigned int tile_size
, tile_width
, tile_height
;
2352 unsigned int tile_rows
, tiles
, pitch_tiles
;
2354 tile_size
= intel_tile_size(dev_priv
);
2355 intel_tile_dims(fb
, plane
, &tile_width
, &tile_height
);
2357 if (drm_rotation_90_or_270(rotation
)) {
2358 pitch_tiles
= pitch
/ tile_height
;
2359 swap(tile_width
, tile_height
);
2361 pitch_tiles
= pitch
/ (tile_width
* cpp
);
2364 tile_rows
= *y
/ tile_height
;
2367 tiles
= *x
/ tile_width
;
2370 offset
= (tile_rows
* pitch_tiles
+ tiles
) * tile_size
;
2371 offset_aligned
= offset
& ~alignment
;
2373 _intel_adjust_tile_offset(x
, y
, tile_width
, tile_height
,
2374 tile_size
, pitch_tiles
,
2375 offset
, offset_aligned
);
2377 offset
= *y
* pitch
+ *x
* cpp
;
2378 offset_aligned
= offset
& ~alignment
;
2380 *y
= (offset
& alignment
) / pitch
;
2381 *x
= ((offset
& alignment
) - *y
* pitch
) / cpp
;
2384 return offset_aligned
;
2387 u32
intel_compute_tile_offset(int *x
, int *y
,
2388 const struct intel_plane_state
*state
,
2391 struct intel_plane
*intel_plane
= to_intel_plane(state
->base
.plane
);
2392 struct drm_i915_private
*dev_priv
= to_i915(intel_plane
->base
.dev
);
2393 const struct drm_framebuffer
*fb
= state
->base
.fb
;
2394 unsigned int rotation
= state
->base
.rotation
;
2395 int pitch
= intel_fb_pitch(fb
, plane
, rotation
);
2398 if (intel_plane
->id
== PLANE_CURSOR
)
2399 alignment
= intel_cursor_alignment(dev_priv
);
2401 alignment
= intel_surf_alignment(fb
, plane
);
2403 return _intel_compute_tile_offset(dev_priv
, x
, y
, fb
, plane
, pitch
,
2404 rotation
, alignment
);
2407 /* Convert the fb->offset[] linear offset into x/y offsets */
2408 static void intel_fb_offset_to_xy(int *x
, int *y
,
2409 const struct drm_framebuffer
*fb
, int plane
)
2411 unsigned int cpp
= fb
->format
->cpp
[plane
];
2412 unsigned int pitch
= fb
->pitches
[plane
];
2413 u32 linear_offset
= fb
->offsets
[plane
];
2415 *y
= linear_offset
/ pitch
;
2416 *x
= linear_offset
% pitch
/ cpp
;
2419 static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier
)
2421 switch (fb_modifier
) {
2422 case I915_FORMAT_MOD_X_TILED
:
2423 return I915_TILING_X
;
2424 case I915_FORMAT_MOD_Y_TILED
:
2425 return I915_TILING_Y
;
2427 return I915_TILING_NONE
;
2432 intel_fill_fb_info(struct drm_i915_private
*dev_priv
,
2433 struct drm_framebuffer
*fb
)
2435 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
2436 struct intel_rotation_info
*rot_info
= &intel_fb
->rot_info
;
2437 u32 gtt_offset_rotated
= 0;
2438 unsigned int max_size
= 0;
2439 int i
, num_planes
= fb
->format
->num_planes
;
2440 unsigned int tile_size
= intel_tile_size(dev_priv
);
2442 for (i
= 0; i
< num_planes
; i
++) {
2443 unsigned int width
, height
;
2444 unsigned int cpp
, size
;
2448 cpp
= fb
->format
->cpp
[i
];
2449 width
= drm_framebuffer_plane_width(fb
->width
, fb
, i
);
2450 height
= drm_framebuffer_plane_height(fb
->height
, fb
, i
);
2452 intel_fb_offset_to_xy(&x
, &y
, fb
, i
);
2455 * The fence (if used) is aligned to the start of the object
2456 * so having the framebuffer wrap around across the edge of the
2457 * fenced region doesn't really work. We have no API to configure
2458 * the fence start offset within the object (nor could we probably
2459 * on gen2/3). So it's just easier if we just require that the
2460 * fb layout agrees with the fence layout. We already check that the
2461 * fb stride matches the fence stride elsewhere.
2463 if (i915_gem_object_is_tiled(intel_fb
->obj
) &&
2464 (x
+ width
) * cpp
> fb
->pitches
[i
]) {
2465 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2471 * First pixel of the framebuffer from
2472 * the start of the normal gtt mapping.
2474 intel_fb
->normal
[i
].x
= x
;
2475 intel_fb
->normal
[i
].y
= y
;
2477 offset
= _intel_compute_tile_offset(dev_priv
, &x
, &y
,
2478 fb
, i
, fb
->pitches
[i
],
2479 DRM_MODE_ROTATE_0
, tile_size
);
2480 offset
/= tile_size
;
2482 if (fb
->modifier
!= DRM_FORMAT_MOD_LINEAR
) {
2483 unsigned int tile_width
, tile_height
;
2484 unsigned int pitch_tiles
;
2487 intel_tile_dims(fb
, i
, &tile_width
, &tile_height
);
2489 rot_info
->plane
[i
].offset
= offset
;
2490 rot_info
->plane
[i
].stride
= DIV_ROUND_UP(fb
->pitches
[i
], tile_width
* cpp
);
2491 rot_info
->plane
[i
].width
= DIV_ROUND_UP(x
+ width
, tile_width
);
2492 rot_info
->plane
[i
].height
= DIV_ROUND_UP(y
+ height
, tile_height
);
2494 intel_fb
->rotated
[i
].pitch
=
2495 rot_info
->plane
[i
].height
* tile_height
;
2497 /* how many tiles does this plane need */
2498 size
= rot_info
->plane
[i
].stride
* rot_info
->plane
[i
].height
;
2500 * If the plane isn't horizontally tile aligned,
2501 * we need one more tile.
2506 /* rotate the x/y offsets to match the GTT view */
2512 rot_info
->plane
[i
].width
* tile_width
,
2513 rot_info
->plane
[i
].height
* tile_height
,
2514 DRM_MODE_ROTATE_270
);
2518 /* rotate the tile dimensions to match the GTT view */
2519 pitch_tiles
= intel_fb
->rotated
[i
].pitch
/ tile_height
;
2520 swap(tile_width
, tile_height
);
2523 * We only keep the x/y offsets, so push all of the
2524 * gtt offset into the x/y offsets.
2526 _intel_adjust_tile_offset(&x
, &y
,
2527 tile_width
, tile_height
,
2528 tile_size
, pitch_tiles
,
2529 gtt_offset_rotated
* tile_size
, 0);
2531 gtt_offset_rotated
+= rot_info
->plane
[i
].width
* rot_info
->plane
[i
].height
;
2534 * First pixel of the framebuffer from
2535 * the start of the rotated gtt mapping.
2537 intel_fb
->rotated
[i
].x
= x
;
2538 intel_fb
->rotated
[i
].y
= y
;
2540 size
= DIV_ROUND_UP((y
+ height
) * fb
->pitches
[i
] +
2541 x
* cpp
, tile_size
);
2544 /* how many tiles in total needed in the bo */
2545 max_size
= max(max_size
, offset
+ size
);
2548 if (max_size
* tile_size
> intel_fb
->obj
->base
.size
) {
2549 DRM_DEBUG_KMS("fb too big for bo (need %u bytes, have %zu bytes)\n",
2550 max_size
* tile_size
, intel_fb
->obj
->base
.size
);
2557 static int i9xx_format_to_fourcc(int format
)
2560 case DISPPLANE_8BPP
:
2561 return DRM_FORMAT_C8
;
2562 case DISPPLANE_BGRX555
:
2563 return DRM_FORMAT_XRGB1555
;
2564 case DISPPLANE_BGRX565
:
2565 return DRM_FORMAT_RGB565
;
2567 case DISPPLANE_BGRX888
:
2568 return DRM_FORMAT_XRGB8888
;
2569 case DISPPLANE_RGBX888
:
2570 return DRM_FORMAT_XBGR8888
;
2571 case DISPPLANE_BGRX101010
:
2572 return DRM_FORMAT_XRGB2101010
;
2573 case DISPPLANE_RGBX101010
:
2574 return DRM_FORMAT_XBGR2101010
;
2578 static int skl_format_to_fourcc(int format
, bool rgb_order
, bool alpha
)
2581 case PLANE_CTL_FORMAT_RGB_565
:
2582 return DRM_FORMAT_RGB565
;
2584 case PLANE_CTL_FORMAT_XRGB_8888
:
2587 return DRM_FORMAT_ABGR8888
;
2589 return DRM_FORMAT_XBGR8888
;
2592 return DRM_FORMAT_ARGB8888
;
2594 return DRM_FORMAT_XRGB8888
;
2596 case PLANE_CTL_FORMAT_XRGB_2101010
:
2598 return DRM_FORMAT_XBGR2101010
;
2600 return DRM_FORMAT_XRGB2101010
;
2605 intel_alloc_initial_plane_obj(struct intel_crtc
*crtc
,
2606 struct intel_initial_plane_config
*plane_config
)
2608 struct drm_device
*dev
= crtc
->base
.dev
;
2609 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2610 struct i915_ggtt
*ggtt
= &dev_priv
->ggtt
;
2611 struct drm_i915_gem_object
*obj
= NULL
;
2612 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2613 struct drm_framebuffer
*fb
= &plane_config
->fb
->base
;
2614 u32 base_aligned
= round_down(plane_config
->base
, PAGE_SIZE
);
2615 u32 size_aligned
= round_up(plane_config
->base
+ plane_config
->size
,
2618 size_aligned
-= base_aligned
;
2620 if (plane_config
->size
== 0)
2623 /* If the FB is too big, just don't use it since fbdev is not very
2624 * important and we should probably use that space with FBC or other
2626 if (size_aligned
* 2 > ggtt
->stolen_usable_size
)
2629 mutex_lock(&dev
->struct_mutex
);
2630 obj
= i915_gem_object_create_stolen_for_preallocated(dev_priv
,
2634 mutex_unlock(&dev
->struct_mutex
);
2638 if (plane_config
->tiling
== I915_TILING_X
)
2639 obj
->tiling_and_stride
= fb
->pitches
[0] | I915_TILING_X
;
2641 mode_cmd
.pixel_format
= fb
->format
->format
;
2642 mode_cmd
.width
= fb
->width
;
2643 mode_cmd
.height
= fb
->height
;
2644 mode_cmd
.pitches
[0] = fb
->pitches
[0];
2645 mode_cmd
.modifier
[0] = fb
->modifier
;
2646 mode_cmd
.flags
= DRM_MODE_FB_MODIFIERS
;
2648 if (intel_framebuffer_init(to_intel_framebuffer(fb
), obj
, &mode_cmd
)) {
2649 DRM_DEBUG_KMS("intel fb init failed\n");
2654 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj
);
2658 i915_gem_object_put(obj
);
2663 intel_set_plane_visible(struct intel_crtc_state
*crtc_state
,
2664 struct intel_plane_state
*plane_state
,
2667 struct intel_plane
*plane
= to_intel_plane(plane_state
->base
.plane
);
2669 plane_state
->base
.visible
= visible
;
2671 /* FIXME pre-g4x don't work like this */
2673 crtc_state
->base
.plane_mask
|= BIT(drm_plane_index(&plane
->base
));
2674 crtc_state
->active_planes
|= BIT(plane
->id
);
2676 crtc_state
->base
.plane_mask
&= ~BIT(drm_plane_index(&plane
->base
));
2677 crtc_state
->active_planes
&= ~BIT(plane
->id
);
2680 DRM_DEBUG_KMS("%s active planes 0x%x\n",
2681 crtc_state
->base
.crtc
->name
,
2682 crtc_state
->active_planes
);
2686 intel_find_initial_plane_obj(struct intel_crtc
*intel_crtc
,
2687 struct intel_initial_plane_config
*plane_config
)
2689 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2690 struct drm_i915_private
*dev_priv
= to_i915(dev
);
2692 struct drm_i915_gem_object
*obj
;
2693 struct drm_plane
*primary
= intel_crtc
->base
.primary
;
2694 struct drm_plane_state
*plane_state
= primary
->state
;
2695 struct drm_crtc_state
*crtc_state
= intel_crtc
->base
.state
;
2696 struct intel_plane
*intel_plane
= to_intel_plane(primary
);
2697 struct intel_plane_state
*intel_state
=
2698 to_intel_plane_state(plane_state
);
2699 struct drm_framebuffer
*fb
;
2701 if (!plane_config
->fb
)
2704 if (intel_alloc_initial_plane_obj(intel_crtc
, plane_config
)) {
2705 fb
= &plane_config
->fb
->base
;
2709 kfree(plane_config
->fb
);
2712 * Failed to alloc the obj, check to see if we should share
2713 * an fb with another CRTC instead
2715 for_each_crtc(dev
, c
) {
2716 struct intel_plane_state
*state
;
2718 if (c
== &intel_crtc
->base
)
2721 if (!to_intel_crtc(c
)->active
)
2724 state
= to_intel_plane_state(c
->primary
->state
);
2728 if (intel_plane_ggtt_offset(state
) == plane_config
->base
) {
2729 fb
= c
->primary
->fb
;
2730 drm_framebuffer_reference(fb
);
2736 * We've failed to reconstruct the BIOS FB. Current display state
2737 * indicates that the primary plane is visible, but has a NULL FB,
2738 * which will lead to problems later if we don't fix it up. The
2739 * simplest solution is to just disable the primary plane now and
2740 * pretend the BIOS never had it enabled.
2742 intel_set_plane_visible(to_intel_crtc_state(crtc_state
),
2743 to_intel_plane_state(plane_state
),
2745 intel_pre_disable_primary_noatomic(&intel_crtc
->base
);
2746 trace_intel_disable_plane(primary
, intel_crtc
);
2747 intel_plane
->disable_plane(intel_plane
, intel_crtc
);
2752 mutex_lock(&dev
->struct_mutex
);
2754 intel_pin_and_fence_fb_obj(fb
, primary
->state
->rotation
);
2755 mutex_unlock(&dev
->struct_mutex
);
2756 if (IS_ERR(intel_state
->vma
)) {
2757 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2758 intel_crtc
->pipe
, PTR_ERR(intel_state
->vma
));
2760 intel_state
->vma
= NULL
;
2761 drm_framebuffer_unreference(fb
);
2765 plane_state
->src_x
= 0;
2766 plane_state
->src_y
= 0;
2767 plane_state
->src_w
= fb
->width
<< 16;
2768 plane_state
->src_h
= fb
->height
<< 16;
2770 plane_state
->crtc_x
= 0;
2771 plane_state
->crtc_y
= 0;
2772 plane_state
->crtc_w
= fb
->width
;
2773 plane_state
->crtc_h
= fb
->height
;
2775 intel_state
->base
.src
= drm_plane_state_src(plane_state
);
2776 intel_state
->base
.dst
= drm_plane_state_dest(plane_state
);
2778 obj
= intel_fb_obj(fb
);
2779 if (i915_gem_object_is_tiled(obj
))
2780 dev_priv
->preserve_bios_swizzle
= true;
2782 drm_framebuffer_reference(fb
);
2783 primary
->fb
= primary
->state
->fb
= fb
;
2784 primary
->crtc
= primary
->state
->crtc
= &intel_crtc
->base
;
2786 intel_set_plane_visible(to_intel_crtc_state(crtc_state
),
2787 to_intel_plane_state(plane_state
),
2790 atomic_or(to_intel_plane(primary
)->frontbuffer_bit
,
2791 &obj
->frontbuffer_bits
);
2794 static int skl_max_plane_width(const struct drm_framebuffer
*fb
, int plane
,
2795 unsigned int rotation
)
2797 int cpp
= fb
->format
->cpp
[plane
];
2799 switch (fb
->modifier
) {
2800 case DRM_FORMAT_MOD_LINEAR
:
2801 case I915_FORMAT_MOD_X_TILED
:
2814 case I915_FORMAT_MOD_Y_TILED
:
2815 case I915_FORMAT_MOD_Yf_TILED
:
2830 MISSING_CASE(fb
->modifier
);
2836 static int skl_check_main_surface(struct intel_plane_state
*plane_state
)
2838 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2839 unsigned int rotation
= plane_state
->base
.rotation
;
2840 int x
= plane_state
->base
.src
.x1
>> 16;
2841 int y
= plane_state
->base
.src
.y1
>> 16;
2842 int w
= drm_rect_width(&plane_state
->base
.src
) >> 16;
2843 int h
= drm_rect_height(&plane_state
->base
.src
) >> 16;
2844 int max_width
= skl_max_plane_width(fb
, 0, rotation
);
2845 int max_height
= 4096;
2846 u32 alignment
, offset
, aux_offset
= plane_state
->aux
.offset
;
2848 if (w
> max_width
|| h
> max_height
) {
2849 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
2850 w
, h
, max_width
, max_height
);
2854 intel_add_fb_offsets(&x
, &y
, plane_state
, 0);
2855 offset
= intel_compute_tile_offset(&x
, &y
, plane_state
, 0);
2856 alignment
= intel_surf_alignment(fb
, 0);
2859 * AUX surface offset is specified as the distance from the
2860 * main surface offset, and it must be non-negative. Make
2861 * sure that is what we will get.
2863 if (offset
> aux_offset
)
2864 offset
= intel_adjust_tile_offset(&x
, &y
, plane_state
, 0,
2865 offset
, aux_offset
& ~(alignment
- 1));
2868 * When using an X-tiled surface, the plane blows up
2869 * if the x offset + width exceed the stride.
2871 * TODO: linear and Y-tiled seem fine, Yf untested,
2873 if (fb
->modifier
== I915_FORMAT_MOD_X_TILED
) {
2874 int cpp
= fb
->format
->cpp
[0];
2876 while ((x
+ w
) * cpp
> fb
->pitches
[0]) {
2878 DRM_DEBUG_KMS("Unable to find suitable display surface offset\n");
2882 offset
= intel_adjust_tile_offset(&x
, &y
, plane_state
, 0,
2883 offset
, offset
- alignment
);
2887 plane_state
->main
.offset
= offset
;
2888 plane_state
->main
.x
= x
;
2889 plane_state
->main
.y
= y
;
2894 static int skl_check_nv12_aux_surface(struct intel_plane_state
*plane_state
)
2896 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2897 unsigned int rotation
= plane_state
->base
.rotation
;
2898 int max_width
= skl_max_plane_width(fb
, 1, rotation
);
2899 int max_height
= 4096;
2900 int x
= plane_state
->base
.src
.x1
>> 17;
2901 int y
= plane_state
->base
.src
.y1
>> 17;
2902 int w
= drm_rect_width(&plane_state
->base
.src
) >> 17;
2903 int h
= drm_rect_height(&plane_state
->base
.src
) >> 17;
2906 intel_add_fb_offsets(&x
, &y
, plane_state
, 1);
2907 offset
= intel_compute_tile_offset(&x
, &y
, plane_state
, 1);
2909 /* FIXME not quite sure how/if these apply to the chroma plane */
2910 if (w
> max_width
|| h
> max_height
) {
2911 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
2912 w
, h
, max_width
, max_height
);
2916 plane_state
->aux
.offset
= offset
;
2917 plane_state
->aux
.x
= x
;
2918 plane_state
->aux
.y
= y
;
2923 int skl_check_plane_surface(struct intel_plane_state
*plane_state
)
2925 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2926 unsigned int rotation
= plane_state
->base
.rotation
;
2929 if (!plane_state
->base
.visible
)
2932 /* Rotate src coordinates to match rotated GTT view */
2933 if (drm_rotation_90_or_270(rotation
))
2934 drm_rect_rotate(&plane_state
->base
.src
,
2935 fb
->width
<< 16, fb
->height
<< 16,
2936 DRM_MODE_ROTATE_270
);
2939 * Handle the AUX surface first since
2940 * the main surface setup depends on it.
2942 if (fb
->format
->format
== DRM_FORMAT_NV12
) {
2943 ret
= skl_check_nv12_aux_surface(plane_state
);
2947 plane_state
->aux
.offset
= ~0xfff;
2948 plane_state
->aux
.x
= 0;
2949 plane_state
->aux
.y
= 0;
2952 ret
= skl_check_main_surface(plane_state
);
2959 static u32
i9xx_plane_ctl(const struct intel_crtc_state
*crtc_state
,
2960 const struct intel_plane_state
*plane_state
)
2962 struct drm_i915_private
*dev_priv
=
2963 to_i915(plane_state
->base
.plane
->dev
);
2964 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
2965 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
2966 unsigned int rotation
= plane_state
->base
.rotation
;
2969 dspcntr
= DISPLAY_PLANE_ENABLE
| DISPPLANE_GAMMA_ENABLE
;
2971 if (IS_G4X(dev_priv
) || IS_GEN5(dev_priv
) ||
2972 IS_GEN6(dev_priv
) || IS_IVYBRIDGE(dev_priv
))
2973 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2975 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
2976 dspcntr
|= DISPPLANE_PIPE_CSC_ENABLE
;
2978 if (INTEL_GEN(dev_priv
) < 4)
2979 dspcntr
|= DISPPLANE_SEL_PIPE(crtc
->pipe
);
2981 switch (fb
->format
->format
) {
2983 dspcntr
|= DISPPLANE_8BPP
;
2985 case DRM_FORMAT_XRGB1555
:
2986 dspcntr
|= DISPPLANE_BGRX555
;
2988 case DRM_FORMAT_RGB565
:
2989 dspcntr
|= DISPPLANE_BGRX565
;
2991 case DRM_FORMAT_XRGB8888
:
2992 dspcntr
|= DISPPLANE_BGRX888
;
2994 case DRM_FORMAT_XBGR8888
:
2995 dspcntr
|= DISPPLANE_RGBX888
;
2997 case DRM_FORMAT_XRGB2101010
:
2998 dspcntr
|= DISPPLANE_BGRX101010
;
3000 case DRM_FORMAT_XBGR2101010
:
3001 dspcntr
|= DISPPLANE_RGBX101010
;
3004 MISSING_CASE(fb
->format
->format
);
3008 if (INTEL_GEN(dev_priv
) >= 4 &&
3009 fb
->modifier
== I915_FORMAT_MOD_X_TILED
)
3010 dspcntr
|= DISPPLANE_TILED
;
3012 if (rotation
& DRM_MODE_ROTATE_180
)
3013 dspcntr
|= DISPPLANE_ROTATE_180
;
3015 if (rotation
& DRM_MODE_REFLECT_X
)
3016 dspcntr
|= DISPPLANE_MIRROR
;
3021 int i9xx_check_plane_surface(struct intel_plane_state
*plane_state
)
3023 struct drm_i915_private
*dev_priv
=
3024 to_i915(plane_state
->base
.plane
->dev
);
3025 int src_x
= plane_state
->base
.src
.x1
>> 16;
3026 int src_y
= plane_state
->base
.src
.y1
>> 16;
3029 intel_add_fb_offsets(&src_x
, &src_y
, plane_state
, 0);
3031 if (INTEL_GEN(dev_priv
) >= 4)
3032 offset
= intel_compute_tile_offset(&src_x
, &src_y
,
3037 /* HSW/BDW do this automagically in hardware */
3038 if (!IS_HASWELL(dev_priv
) && !IS_BROADWELL(dev_priv
)) {
3039 unsigned int rotation
= plane_state
->base
.rotation
;
3040 int src_w
= drm_rect_width(&plane_state
->base
.src
) >> 16;
3041 int src_h
= drm_rect_height(&plane_state
->base
.src
) >> 16;
3043 if (rotation
& DRM_MODE_ROTATE_180
) {
3046 } else if (rotation
& DRM_MODE_REFLECT_X
) {
3051 plane_state
->main
.offset
= offset
;
3052 plane_state
->main
.x
= src_x
;
3053 plane_state
->main
.y
= src_y
;
3058 static void i9xx_update_primary_plane(struct intel_plane
*primary
,
3059 const struct intel_crtc_state
*crtc_state
,
3060 const struct intel_plane_state
*plane_state
)
3062 struct drm_i915_private
*dev_priv
= to_i915(primary
->base
.dev
);
3063 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
3064 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
3065 enum plane plane
= primary
->plane
;
3067 u32 dspcntr
= plane_state
->ctl
;
3068 i915_reg_t reg
= DSPCNTR(plane
);
3069 int x
= plane_state
->main
.x
;
3070 int y
= plane_state
->main
.y
;
3071 unsigned long irqflags
;
3073 linear_offset
= intel_fb_xy_to_linear(x
, y
, plane_state
, 0);
3075 if (INTEL_GEN(dev_priv
) >= 4)
3076 crtc
->dspaddr_offset
= plane_state
->main
.offset
;
3078 crtc
->dspaddr_offset
= linear_offset
;
3080 crtc
->adjusted_x
= x
;
3081 crtc
->adjusted_y
= y
;
3083 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
3085 if (INTEL_GEN(dev_priv
) < 4) {
3086 /* pipesrc and dspsize control the size that is scaled from,
3087 * which should always be the user's requested size.
3089 I915_WRITE_FW(DSPSIZE(plane
),
3090 ((crtc_state
->pipe_src_h
- 1) << 16) |
3091 (crtc_state
->pipe_src_w
- 1));
3092 I915_WRITE_FW(DSPPOS(plane
), 0);
3093 } else if (IS_CHERRYVIEW(dev_priv
) && plane
== PLANE_B
) {
3094 I915_WRITE_FW(PRIMSIZE(plane
),
3095 ((crtc_state
->pipe_src_h
- 1) << 16) |
3096 (crtc_state
->pipe_src_w
- 1));
3097 I915_WRITE_FW(PRIMPOS(plane
), 0);
3098 I915_WRITE_FW(PRIMCNSTALPHA(plane
), 0);
3101 I915_WRITE_FW(reg
, dspcntr
);
3103 I915_WRITE_FW(DSPSTRIDE(plane
), fb
->pitches
[0]);
3104 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
3105 I915_WRITE_FW(DSPSURF(plane
),
3106 intel_plane_ggtt_offset(plane_state
) +
3107 crtc
->dspaddr_offset
);
3108 I915_WRITE_FW(DSPOFFSET(plane
), (y
<< 16) | x
);
3109 } else if (INTEL_GEN(dev_priv
) >= 4) {
3110 I915_WRITE_FW(DSPSURF(plane
),
3111 intel_plane_ggtt_offset(plane_state
) +
3112 crtc
->dspaddr_offset
);
3113 I915_WRITE_FW(DSPTILEOFF(plane
), (y
<< 16) | x
);
3114 I915_WRITE_FW(DSPLINOFF(plane
), linear_offset
);
3116 I915_WRITE_FW(DSPADDR(plane
),
3117 intel_plane_ggtt_offset(plane_state
) +
3118 crtc
->dspaddr_offset
);
3120 POSTING_READ_FW(reg
);
3122 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
3125 static void i9xx_disable_primary_plane(struct intel_plane
*primary
,
3126 struct intel_crtc
*crtc
)
3128 struct drm_i915_private
*dev_priv
= to_i915(primary
->base
.dev
);
3129 enum plane plane
= primary
->plane
;
3130 unsigned long irqflags
;
3132 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
3134 I915_WRITE_FW(DSPCNTR(plane
), 0);
3135 if (INTEL_INFO(dev_priv
)->gen
>= 4)
3136 I915_WRITE_FW(DSPSURF(plane
), 0);
3138 I915_WRITE_FW(DSPADDR(plane
), 0);
3139 POSTING_READ_FW(DSPCNTR(plane
));
3141 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
3145 intel_fb_stride_alignment(const struct drm_framebuffer
*fb
, int plane
)
3147 if (fb
->modifier
== DRM_FORMAT_MOD_LINEAR
)
3150 return intel_tile_width_bytes(fb
, plane
);
3153 static void skl_detach_scaler(struct intel_crtc
*intel_crtc
, int id
)
3155 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3156 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3158 I915_WRITE(SKL_PS_CTRL(intel_crtc
->pipe
, id
), 0);
3159 I915_WRITE(SKL_PS_WIN_POS(intel_crtc
->pipe
, id
), 0);
3160 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc
->pipe
, id
), 0);
3164 * This function detaches (aka. unbinds) unused scalers in hardware
3166 static void skl_detach_scalers(struct intel_crtc
*intel_crtc
)
3168 struct intel_crtc_scaler_state
*scaler_state
;
3171 scaler_state
= &intel_crtc
->config
->scaler_state
;
3173 /* loop through and disable scalers that aren't in use */
3174 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
3175 if (!scaler_state
->scalers
[i
].in_use
)
3176 skl_detach_scaler(intel_crtc
, i
);
3180 u32
skl_plane_stride(const struct drm_framebuffer
*fb
, int plane
,
3181 unsigned int rotation
)
3185 if (plane
>= fb
->format
->num_planes
)
3188 stride
= intel_fb_pitch(fb
, plane
, rotation
);
3191 * The stride is either expressed as a multiple of 64 bytes chunks for
3192 * linear buffers or in number of tiles for tiled buffers.
3194 if (drm_rotation_90_or_270(rotation
))
3195 stride
/= intel_tile_height(fb
, plane
);
3197 stride
/= intel_fb_stride_alignment(fb
, plane
);
3202 static u32
skl_plane_ctl_format(uint32_t pixel_format
)
3204 switch (pixel_format
) {
3206 return PLANE_CTL_FORMAT_INDEXED
;
3207 case DRM_FORMAT_RGB565
:
3208 return PLANE_CTL_FORMAT_RGB_565
;
3209 case DRM_FORMAT_XBGR8888
:
3210 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
;
3211 case DRM_FORMAT_XRGB8888
:
3212 return PLANE_CTL_FORMAT_XRGB_8888
;
3214 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
3215 * to be already pre-multiplied. We need to add a knob (or a different
3216 * DRM_FORMAT) for user-space to configure that.
3218 case DRM_FORMAT_ABGR8888
:
3219 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
|
3220 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
3221 case DRM_FORMAT_ARGB8888
:
3222 return PLANE_CTL_FORMAT_XRGB_8888
|
3223 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
3224 case DRM_FORMAT_XRGB2101010
:
3225 return PLANE_CTL_FORMAT_XRGB_2101010
;
3226 case DRM_FORMAT_XBGR2101010
:
3227 return PLANE_CTL_ORDER_RGBX
| PLANE_CTL_FORMAT_XRGB_2101010
;
3228 case DRM_FORMAT_YUYV
:
3229 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YUYV
;
3230 case DRM_FORMAT_YVYU
:
3231 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YVYU
;
3232 case DRM_FORMAT_UYVY
:
3233 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_UYVY
;
3234 case DRM_FORMAT_VYUY
:
3235 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_VYUY
;
3237 MISSING_CASE(pixel_format
);
3243 static u32
skl_plane_ctl_tiling(uint64_t fb_modifier
)
3245 switch (fb_modifier
) {
3246 case DRM_FORMAT_MOD_LINEAR
:
3248 case I915_FORMAT_MOD_X_TILED
:
3249 return PLANE_CTL_TILED_X
;
3250 case I915_FORMAT_MOD_Y_TILED
:
3251 return PLANE_CTL_TILED_Y
;
3252 case I915_FORMAT_MOD_Yf_TILED
:
3253 return PLANE_CTL_TILED_YF
;
3255 MISSING_CASE(fb_modifier
);
3261 static u32
skl_plane_ctl_rotation(unsigned int rotation
)
3264 case DRM_MODE_ROTATE_0
:
3267 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
3268 * while i915 HW rotation is clockwise, thats why this swapping.
3270 case DRM_MODE_ROTATE_90
:
3271 return PLANE_CTL_ROTATE_270
;
3272 case DRM_MODE_ROTATE_180
:
3273 return PLANE_CTL_ROTATE_180
;
3274 case DRM_MODE_ROTATE_270
:
3275 return PLANE_CTL_ROTATE_90
;
3277 MISSING_CASE(rotation
);
3283 u32
skl_plane_ctl(const struct intel_crtc_state
*crtc_state
,
3284 const struct intel_plane_state
*plane_state
)
3286 struct drm_i915_private
*dev_priv
=
3287 to_i915(plane_state
->base
.plane
->dev
);
3288 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
3289 unsigned int rotation
= plane_state
->base
.rotation
;
3290 const struct drm_intel_sprite_colorkey
*key
= &plane_state
->ckey
;
3293 plane_ctl
= PLANE_CTL_ENABLE
;
3295 if (!IS_GEMINILAKE(dev_priv
) && !IS_CANNONLAKE(dev_priv
)) {
3297 PLANE_CTL_PIPE_GAMMA_ENABLE
|
3298 PLANE_CTL_PIPE_CSC_ENABLE
|
3299 PLANE_CTL_PLANE_GAMMA_DISABLE
;
3302 plane_ctl
|= skl_plane_ctl_format(fb
->format
->format
);
3303 plane_ctl
|= skl_plane_ctl_tiling(fb
->modifier
);
3304 plane_ctl
|= skl_plane_ctl_rotation(rotation
);
3306 if (key
->flags
& I915_SET_COLORKEY_DESTINATION
)
3307 plane_ctl
|= PLANE_CTL_KEY_ENABLE_DESTINATION
;
3308 else if (key
->flags
& I915_SET_COLORKEY_SOURCE
)
3309 plane_ctl
|= PLANE_CTL_KEY_ENABLE_SOURCE
;
3314 static void skylake_update_primary_plane(struct intel_plane
*plane
,
3315 const struct intel_crtc_state
*crtc_state
,
3316 const struct intel_plane_state
*plane_state
)
3318 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
3319 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
3320 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
3321 enum plane_id plane_id
= plane
->id
;
3322 enum pipe pipe
= plane
->pipe
;
3323 u32 plane_ctl
= plane_state
->ctl
;
3324 unsigned int rotation
= plane_state
->base
.rotation
;
3325 u32 stride
= skl_plane_stride(fb
, 0, rotation
);
3326 u32 surf_addr
= plane_state
->main
.offset
;
3327 int scaler_id
= plane_state
->scaler_id
;
3328 int src_x
= plane_state
->main
.x
;
3329 int src_y
= plane_state
->main
.y
;
3330 int src_w
= drm_rect_width(&plane_state
->base
.src
) >> 16;
3331 int src_h
= drm_rect_height(&plane_state
->base
.src
) >> 16;
3332 int dst_x
= plane_state
->base
.dst
.x1
;
3333 int dst_y
= plane_state
->base
.dst
.y1
;
3334 int dst_w
= drm_rect_width(&plane_state
->base
.dst
);
3335 int dst_h
= drm_rect_height(&plane_state
->base
.dst
);
3336 unsigned long irqflags
;
3338 /* Sizes are 0 based */
3344 crtc
->dspaddr_offset
= surf_addr
;
3346 crtc
->adjusted_x
= src_x
;
3347 crtc
->adjusted_y
= src_y
;
3349 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
3351 if (IS_GEMINILAKE(dev_priv
) || IS_CANNONLAKE(dev_priv
)) {
3352 I915_WRITE_FW(PLANE_COLOR_CTL(pipe
, plane_id
),
3353 PLANE_COLOR_PIPE_GAMMA_ENABLE
|
3354 PLANE_COLOR_PIPE_CSC_ENABLE
|
3355 PLANE_COLOR_PLANE_GAMMA_DISABLE
);
3358 I915_WRITE_FW(PLANE_CTL(pipe
, plane_id
), plane_ctl
);
3359 I915_WRITE_FW(PLANE_OFFSET(pipe
, plane_id
), (src_y
<< 16) | src_x
);
3360 I915_WRITE_FW(PLANE_STRIDE(pipe
, plane_id
), stride
);
3361 I915_WRITE_FW(PLANE_SIZE(pipe
, plane_id
), (src_h
<< 16) | src_w
);
3363 if (scaler_id
>= 0) {
3364 uint32_t ps_ctrl
= 0;
3366 WARN_ON(!dst_w
|| !dst_h
);
3367 ps_ctrl
= PS_SCALER_EN
| PS_PLANE_SEL(plane_id
) |
3368 crtc_state
->scaler_state
.scalers
[scaler_id
].mode
;
3369 I915_WRITE_FW(SKL_PS_CTRL(pipe
, scaler_id
), ps_ctrl
);
3370 I915_WRITE_FW(SKL_PS_PWR_GATE(pipe
, scaler_id
), 0);
3371 I915_WRITE_FW(SKL_PS_WIN_POS(pipe
, scaler_id
), (dst_x
<< 16) | dst_y
);
3372 I915_WRITE_FW(SKL_PS_WIN_SZ(pipe
, scaler_id
), (dst_w
<< 16) | dst_h
);
3373 I915_WRITE_FW(PLANE_POS(pipe
, plane_id
), 0);
3375 I915_WRITE_FW(PLANE_POS(pipe
, plane_id
), (dst_y
<< 16) | dst_x
);
3378 I915_WRITE_FW(PLANE_SURF(pipe
, plane_id
),
3379 intel_plane_ggtt_offset(plane_state
) + surf_addr
);
3381 POSTING_READ_FW(PLANE_SURF(pipe
, plane_id
));
3383 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
3386 static void skylake_disable_primary_plane(struct intel_plane
*primary
,
3387 struct intel_crtc
*crtc
)
3389 struct drm_i915_private
*dev_priv
= to_i915(primary
->base
.dev
);
3390 enum plane_id plane_id
= primary
->id
;
3391 enum pipe pipe
= primary
->pipe
;
3392 unsigned long irqflags
;
3394 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
3396 I915_WRITE_FW(PLANE_CTL(pipe
, plane_id
), 0);
3397 I915_WRITE_FW(PLANE_SURF(pipe
, plane_id
), 0);
3398 POSTING_READ_FW(PLANE_SURF(pipe
, plane_id
));
3400 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
3404 __intel_display_resume(struct drm_device
*dev
,
3405 struct drm_atomic_state
*state
,
3406 struct drm_modeset_acquire_ctx
*ctx
)
3408 struct drm_crtc_state
*crtc_state
;
3409 struct drm_crtc
*crtc
;
3412 intel_modeset_setup_hw_state(dev
, ctx
);
3413 i915_redisable_vga(to_i915(dev
));
3419 * We've duplicated the state, pointers to the old state are invalid.
3421 * Don't attempt to use the old state until we commit the duplicated state.
3423 for_each_new_crtc_in_state(state
, crtc
, crtc_state
, i
) {
3425 * Force recalculation even if we restore
3426 * current state. With fast modeset this may not result
3427 * in a modeset when the state is compatible.
3429 crtc_state
->mode_changed
= true;
3432 /* ignore any reset values/BIOS leftovers in the WM registers */
3433 if (!HAS_GMCH_DISPLAY(to_i915(dev
)))
3434 to_intel_atomic_state(state
)->skip_intermediate_wm
= true;
3436 ret
= drm_atomic_helper_commit_duplicated_state(state
, ctx
);
3438 WARN_ON(ret
== -EDEADLK
);
3442 static bool gpu_reset_clobbers_display(struct drm_i915_private
*dev_priv
)
3444 return intel_has_gpu_reset(dev_priv
) &&
3445 INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
);
3448 void intel_prepare_reset(struct drm_i915_private
*dev_priv
)
3450 struct drm_device
*dev
= &dev_priv
->drm
;
3451 struct drm_modeset_acquire_ctx
*ctx
= &dev_priv
->reset_ctx
;
3452 struct drm_atomic_state
*state
;
3456 /* reset doesn't touch the display */
3457 if (!i915
.force_reset_modeset_test
&&
3458 !gpu_reset_clobbers_display(dev_priv
))
3462 * Need mode_config.mutex so that we don't
3463 * trample ongoing ->detect() and whatnot.
3465 mutex_lock(&dev
->mode_config
.mutex
);
3466 drm_modeset_acquire_init(ctx
, 0);
3468 ret
= drm_modeset_lock_all_ctx(dev
, ctx
);
3469 if (ret
!= -EDEADLK
)
3472 drm_modeset_backoff(ctx
);
3475 * Disabling the crtcs gracefully seems nicer. Also the
3476 * g33 docs say we should at least disable all the planes.
3478 state
= drm_atomic_helper_duplicate_state(dev
, ctx
);
3479 if (IS_ERR(state
)) {
3480 ret
= PTR_ERR(state
);
3481 DRM_ERROR("Duplicating state failed with %i\n", ret
);
3485 ret
= drm_atomic_helper_disable_all(dev
, ctx
);
3487 DRM_ERROR("Suspending crtc's failed with %i\n", ret
);
3488 drm_atomic_state_put(state
);
3492 dev_priv
->modeset_restore_state
= state
;
3493 state
->acquire_ctx
= ctx
;
3496 void intel_finish_reset(struct drm_i915_private
*dev_priv
)
3498 struct drm_device
*dev
= &dev_priv
->drm
;
3499 struct drm_modeset_acquire_ctx
*ctx
= &dev_priv
->reset_ctx
;
3500 struct drm_atomic_state
*state
= dev_priv
->modeset_restore_state
;
3503 /* reset doesn't touch the display */
3504 if (!i915
.force_reset_modeset_test
&&
3505 !gpu_reset_clobbers_display(dev_priv
))
3511 dev_priv
->modeset_restore_state
= NULL
;
3513 /* reset doesn't touch the display */
3514 if (!gpu_reset_clobbers_display(dev_priv
)) {
3515 /* for testing only restore the display */
3516 ret
= __intel_display_resume(dev
, state
, ctx
);
3518 DRM_ERROR("Restoring old state failed with %i\n", ret
);
3521 * The display has been reset as well,
3522 * so need a full re-initialization.
3524 intel_runtime_pm_disable_interrupts(dev_priv
);
3525 intel_runtime_pm_enable_interrupts(dev_priv
);
3527 intel_pps_unlock_regs_wa(dev_priv
);
3528 intel_modeset_init_hw(dev
);
3530 spin_lock_irq(&dev_priv
->irq_lock
);
3531 if (dev_priv
->display
.hpd_irq_setup
)
3532 dev_priv
->display
.hpd_irq_setup(dev_priv
);
3533 spin_unlock_irq(&dev_priv
->irq_lock
);
3535 ret
= __intel_display_resume(dev
, state
, ctx
);
3537 DRM_ERROR("Restoring old state failed with %i\n", ret
);
3539 intel_hpd_init(dev_priv
);
3542 drm_atomic_state_put(state
);
3544 drm_modeset_drop_locks(ctx
);
3545 drm_modeset_acquire_fini(ctx
);
3546 mutex_unlock(&dev
->mode_config
.mutex
);
3549 static void intel_update_pipe_config(struct intel_crtc
*crtc
,
3550 struct intel_crtc_state
*old_crtc_state
)
3552 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
3553 struct intel_crtc_state
*pipe_config
=
3554 to_intel_crtc_state(crtc
->base
.state
);
3556 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
3557 crtc
->base
.mode
= crtc
->base
.state
->mode
;
3560 * Update pipe size and adjust fitter if needed: the reason for this is
3561 * that in compute_mode_changes we check the native mode (not the pfit
3562 * mode) to see if we can flip rather than do a full mode set. In the
3563 * fastboot case, we'll flip, but if we don't update the pipesrc and
3564 * pfit state, we'll end up with a big fb scanned out into the wrong
3568 I915_WRITE(PIPESRC(crtc
->pipe
),
3569 ((pipe_config
->pipe_src_w
- 1) << 16) |
3570 (pipe_config
->pipe_src_h
- 1));
3572 /* on skylake this is done by detaching scalers */
3573 if (INTEL_GEN(dev_priv
) >= 9) {
3574 skl_detach_scalers(crtc
);
3576 if (pipe_config
->pch_pfit
.enabled
)
3577 skylake_pfit_enable(crtc
);
3578 } else if (HAS_PCH_SPLIT(dev_priv
)) {
3579 if (pipe_config
->pch_pfit
.enabled
)
3580 ironlake_pfit_enable(crtc
);
3581 else if (old_crtc_state
->pch_pfit
.enabled
)
3582 ironlake_pfit_disable(crtc
, true);
3586 static void intel_fdi_normal_train(struct intel_crtc
*crtc
)
3588 struct drm_device
*dev
= crtc
->base
.dev
;
3589 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3590 int pipe
= crtc
->pipe
;
3594 /* enable normal train */
3595 reg
= FDI_TX_CTL(pipe
);
3596 temp
= I915_READ(reg
);
3597 if (IS_IVYBRIDGE(dev_priv
)) {
3598 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3599 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3601 temp
&= ~FDI_LINK_TRAIN_NONE
;
3602 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3604 I915_WRITE(reg
, temp
);
3606 reg
= FDI_RX_CTL(pipe
);
3607 temp
= I915_READ(reg
);
3608 if (HAS_PCH_CPT(dev_priv
)) {
3609 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3610 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
3612 temp
&= ~FDI_LINK_TRAIN_NONE
;
3613 temp
|= FDI_LINK_TRAIN_NONE
;
3615 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
3617 /* wait one idle pattern time */
3621 /* IVB wants error correction enabled */
3622 if (IS_IVYBRIDGE(dev_priv
))
3623 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
3624 FDI_FE_ERRC_ENABLE
);
3627 /* The FDI link training functions for ILK/Ibexpeak. */
3628 static void ironlake_fdi_link_train(struct intel_crtc
*crtc
,
3629 const struct intel_crtc_state
*crtc_state
)
3631 struct drm_device
*dev
= crtc
->base
.dev
;
3632 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3633 int pipe
= crtc
->pipe
;
3637 /* FDI needs bits from pipe first */
3638 assert_pipe_enabled(dev_priv
, pipe
);
3640 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3642 reg
= FDI_RX_IMR(pipe
);
3643 temp
= I915_READ(reg
);
3644 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3645 temp
&= ~FDI_RX_BIT_LOCK
;
3646 I915_WRITE(reg
, temp
);
3650 /* enable CPU FDI TX and PCH FDI RX */
3651 reg
= FDI_TX_CTL(pipe
);
3652 temp
= I915_READ(reg
);
3653 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3654 temp
|= FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
3655 temp
&= ~FDI_LINK_TRAIN_NONE
;
3656 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3657 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3659 reg
= FDI_RX_CTL(pipe
);
3660 temp
= I915_READ(reg
);
3661 temp
&= ~FDI_LINK_TRAIN_NONE
;
3662 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3663 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3668 /* Ironlake workaround, enable clock pointer after FDI enable*/
3669 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3670 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
3671 FDI_RX_PHASE_SYNC_POINTER_EN
);
3673 reg
= FDI_RX_IIR(pipe
);
3674 for (tries
= 0; tries
< 5; tries
++) {
3675 temp
= I915_READ(reg
);
3676 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3678 if ((temp
& FDI_RX_BIT_LOCK
)) {
3679 DRM_DEBUG_KMS("FDI train 1 done.\n");
3680 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3685 DRM_ERROR("FDI train 1 fail!\n");
3688 reg
= FDI_TX_CTL(pipe
);
3689 temp
= I915_READ(reg
);
3690 temp
&= ~FDI_LINK_TRAIN_NONE
;
3691 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3692 I915_WRITE(reg
, temp
);
3694 reg
= FDI_RX_CTL(pipe
);
3695 temp
= I915_READ(reg
);
3696 temp
&= ~FDI_LINK_TRAIN_NONE
;
3697 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3698 I915_WRITE(reg
, temp
);
3703 reg
= FDI_RX_IIR(pipe
);
3704 for (tries
= 0; tries
< 5; tries
++) {
3705 temp
= I915_READ(reg
);
3706 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3708 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3709 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3710 DRM_DEBUG_KMS("FDI train 2 done.\n");
3715 DRM_ERROR("FDI train 2 fail!\n");
3717 DRM_DEBUG_KMS("FDI train done\n");
3721 static const int snb_b_fdi_train_param
[] = {
3722 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
3723 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
3724 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
3725 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
3728 /* The FDI link training functions for SNB/Cougarpoint. */
3729 static void gen6_fdi_link_train(struct intel_crtc
*crtc
,
3730 const struct intel_crtc_state
*crtc_state
)
3732 struct drm_device
*dev
= crtc
->base
.dev
;
3733 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3734 int pipe
= crtc
->pipe
;
3738 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3740 reg
= FDI_RX_IMR(pipe
);
3741 temp
= I915_READ(reg
);
3742 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3743 temp
&= ~FDI_RX_BIT_LOCK
;
3744 I915_WRITE(reg
, temp
);
3749 /* enable CPU FDI TX and PCH FDI RX */
3750 reg
= FDI_TX_CTL(pipe
);
3751 temp
= I915_READ(reg
);
3752 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3753 temp
|= FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
3754 temp
&= ~FDI_LINK_TRAIN_NONE
;
3755 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3756 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3758 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3759 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3761 I915_WRITE(FDI_RX_MISC(pipe
),
3762 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3764 reg
= FDI_RX_CTL(pipe
);
3765 temp
= I915_READ(reg
);
3766 if (HAS_PCH_CPT(dev_priv
)) {
3767 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3768 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3770 temp
&= ~FDI_LINK_TRAIN_NONE
;
3771 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3773 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3778 for (i
= 0; i
< 4; i
++) {
3779 reg
= FDI_TX_CTL(pipe
);
3780 temp
= I915_READ(reg
);
3781 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3782 temp
|= snb_b_fdi_train_param
[i
];
3783 I915_WRITE(reg
, temp
);
3788 for (retry
= 0; retry
< 5; retry
++) {
3789 reg
= FDI_RX_IIR(pipe
);
3790 temp
= I915_READ(reg
);
3791 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3792 if (temp
& FDI_RX_BIT_LOCK
) {
3793 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3794 DRM_DEBUG_KMS("FDI train 1 done.\n");
3803 DRM_ERROR("FDI train 1 fail!\n");
3806 reg
= FDI_TX_CTL(pipe
);
3807 temp
= I915_READ(reg
);
3808 temp
&= ~FDI_LINK_TRAIN_NONE
;
3809 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3810 if (IS_GEN6(dev_priv
)) {
3811 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3813 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3815 I915_WRITE(reg
, temp
);
3817 reg
= FDI_RX_CTL(pipe
);
3818 temp
= I915_READ(reg
);
3819 if (HAS_PCH_CPT(dev_priv
)) {
3820 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3821 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3823 temp
&= ~FDI_LINK_TRAIN_NONE
;
3824 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3826 I915_WRITE(reg
, temp
);
3831 for (i
= 0; i
< 4; i
++) {
3832 reg
= FDI_TX_CTL(pipe
);
3833 temp
= I915_READ(reg
);
3834 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3835 temp
|= snb_b_fdi_train_param
[i
];
3836 I915_WRITE(reg
, temp
);
3841 for (retry
= 0; retry
< 5; retry
++) {
3842 reg
= FDI_RX_IIR(pipe
);
3843 temp
= I915_READ(reg
);
3844 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3845 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3846 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3847 DRM_DEBUG_KMS("FDI train 2 done.\n");
3856 DRM_ERROR("FDI train 2 fail!\n");
3858 DRM_DEBUG_KMS("FDI train done.\n");
3861 /* Manual link training for Ivy Bridge A0 parts */
3862 static void ivb_manual_fdi_link_train(struct intel_crtc
*crtc
,
3863 const struct intel_crtc_state
*crtc_state
)
3865 struct drm_device
*dev
= crtc
->base
.dev
;
3866 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3867 int pipe
= crtc
->pipe
;
3871 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3873 reg
= FDI_RX_IMR(pipe
);
3874 temp
= I915_READ(reg
);
3875 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3876 temp
&= ~FDI_RX_BIT_LOCK
;
3877 I915_WRITE(reg
, temp
);
3882 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3883 I915_READ(FDI_RX_IIR(pipe
)));
3885 /* Try each vswing and preemphasis setting twice before moving on */
3886 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
3887 /* disable first in case we need to retry */
3888 reg
= FDI_TX_CTL(pipe
);
3889 temp
= I915_READ(reg
);
3890 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
3891 temp
&= ~FDI_TX_ENABLE
;
3892 I915_WRITE(reg
, temp
);
3894 reg
= FDI_RX_CTL(pipe
);
3895 temp
= I915_READ(reg
);
3896 temp
&= ~FDI_LINK_TRAIN_AUTO
;
3897 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3898 temp
&= ~FDI_RX_ENABLE
;
3899 I915_WRITE(reg
, temp
);
3901 /* enable CPU FDI TX and PCH FDI RX */
3902 reg
= FDI_TX_CTL(pipe
);
3903 temp
= I915_READ(reg
);
3904 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3905 temp
|= FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
3906 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
3907 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3908 temp
|= snb_b_fdi_train_param
[j
/2];
3909 temp
|= FDI_COMPOSITE_SYNC
;
3910 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3912 I915_WRITE(FDI_RX_MISC(pipe
),
3913 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3915 reg
= FDI_RX_CTL(pipe
);
3916 temp
= I915_READ(reg
);
3917 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3918 temp
|= FDI_COMPOSITE_SYNC
;
3919 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3922 udelay(1); /* should be 0.5us */
3924 for (i
= 0; i
< 4; i
++) {
3925 reg
= FDI_RX_IIR(pipe
);
3926 temp
= I915_READ(reg
);
3927 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3929 if (temp
& FDI_RX_BIT_LOCK
||
3930 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
3931 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3932 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3936 udelay(1); /* should be 0.5us */
3939 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
3944 reg
= FDI_TX_CTL(pipe
);
3945 temp
= I915_READ(reg
);
3946 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3947 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
3948 I915_WRITE(reg
, temp
);
3950 reg
= FDI_RX_CTL(pipe
);
3951 temp
= I915_READ(reg
);
3952 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3953 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3954 I915_WRITE(reg
, temp
);
3957 udelay(2); /* should be 1.5us */
3959 for (i
= 0; i
< 4; i
++) {
3960 reg
= FDI_RX_IIR(pipe
);
3961 temp
= I915_READ(reg
);
3962 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3964 if (temp
& FDI_RX_SYMBOL_LOCK
||
3965 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
3966 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3967 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
3971 udelay(2); /* should be 1.5us */
3974 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
3978 DRM_DEBUG_KMS("FDI train done.\n");
3981 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
3983 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3984 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3985 int pipe
= intel_crtc
->pipe
;
3989 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
3990 reg
= FDI_RX_CTL(pipe
);
3991 temp
= I915_READ(reg
);
3992 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
3993 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3994 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3995 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
4000 /* Switch from Rawclk to PCDclk */
4001 temp
= I915_READ(reg
);
4002 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
4007 /* Enable CPU FDI TX PLL, always on for Ironlake */
4008 reg
= FDI_TX_CTL(pipe
);
4009 temp
= I915_READ(reg
);
4010 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
4011 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
4018 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
4020 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4021 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4022 int pipe
= intel_crtc
->pipe
;
4026 /* Switch from PCDclk to Rawclk */
4027 reg
= FDI_RX_CTL(pipe
);
4028 temp
= I915_READ(reg
);
4029 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
4031 /* Disable CPU FDI TX PLL */
4032 reg
= FDI_TX_CTL(pipe
);
4033 temp
= I915_READ(reg
);
4034 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
4039 reg
= FDI_RX_CTL(pipe
);
4040 temp
= I915_READ(reg
);
4041 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
4043 /* Wait for the clocks to turn off. */
4048 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
4050 struct drm_device
*dev
= crtc
->dev
;
4051 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4052 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4053 int pipe
= intel_crtc
->pipe
;
4057 /* disable CPU FDI tx and PCH FDI rx */
4058 reg
= FDI_TX_CTL(pipe
);
4059 temp
= I915_READ(reg
);
4060 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
4063 reg
= FDI_RX_CTL(pipe
);
4064 temp
= I915_READ(reg
);
4065 temp
&= ~(0x7 << 16);
4066 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
4067 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
4072 /* Ironlake workaround, disable clock pointer after downing FDI */
4073 if (HAS_PCH_IBX(dev_priv
))
4074 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
4076 /* still set train pattern 1 */
4077 reg
= FDI_TX_CTL(pipe
);
4078 temp
= I915_READ(reg
);
4079 temp
&= ~FDI_LINK_TRAIN_NONE
;
4080 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
4081 I915_WRITE(reg
, temp
);
4083 reg
= FDI_RX_CTL(pipe
);
4084 temp
= I915_READ(reg
);
4085 if (HAS_PCH_CPT(dev_priv
)) {
4086 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
4087 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
4089 temp
&= ~FDI_LINK_TRAIN_NONE
;
4090 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
4092 /* BPC in FDI rx is consistent with that in PIPECONF */
4093 temp
&= ~(0x07 << 16);
4094 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
4095 I915_WRITE(reg
, temp
);
4101 bool intel_has_pending_fb_unpin(struct drm_i915_private
*dev_priv
)
4103 struct drm_crtc
*crtc
;
4106 drm_for_each_crtc(crtc
, &dev_priv
->drm
) {
4107 struct drm_crtc_commit
*commit
;
4108 spin_lock(&crtc
->commit_lock
);
4109 commit
= list_first_entry_or_null(&crtc
->commit_list
,
4110 struct drm_crtc_commit
, commit_entry
);
4111 cleanup_done
= commit
?
4112 try_wait_for_completion(&commit
->cleanup_done
) : true;
4113 spin_unlock(&crtc
->commit_lock
);
4118 drm_crtc_wait_one_vblank(crtc
);
4126 void lpt_disable_iclkip(struct drm_i915_private
*dev_priv
)
4130 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
4132 mutex_lock(&dev_priv
->sb_lock
);
4134 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4135 temp
|= SBI_SSCCTL_DISABLE
;
4136 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
4138 mutex_unlock(&dev_priv
->sb_lock
);
4141 /* Program iCLKIP clock to the desired frequency */
4142 static void lpt_program_iclkip(struct intel_crtc
*crtc
)
4144 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
4145 int clock
= crtc
->config
->base
.adjusted_mode
.crtc_clock
;
4146 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
4149 lpt_disable_iclkip(dev_priv
);
4151 /* The iCLK virtual clock root frequency is in MHz,
4152 * but the adjusted_mode->crtc_clock in in KHz. To get the
4153 * divisors, it is necessary to divide one by another, so we
4154 * convert the virtual clock precision to KHz here for higher
4157 for (auxdiv
= 0; auxdiv
< 2; auxdiv
++) {
4158 u32 iclk_virtual_root_freq
= 172800 * 1000;
4159 u32 iclk_pi_range
= 64;
4160 u32 desired_divisor
;
4162 desired_divisor
= DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
4164 divsel
= (desired_divisor
/ iclk_pi_range
) - 2;
4165 phaseinc
= desired_divisor
% iclk_pi_range
;
4168 * Near 20MHz is a corner case which is
4169 * out of range for the 7-bit divisor
4175 /* This should not happen with any sane values */
4176 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
4177 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
4178 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
4179 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
4181 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4188 mutex_lock(&dev_priv
->sb_lock
);
4190 /* Program SSCDIVINTPHASE6 */
4191 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
4192 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
4193 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
4194 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
4195 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
4196 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
4197 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
4198 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
4200 /* Program SSCAUXDIV */
4201 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
4202 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4203 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
4204 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
4206 /* Enable modulator and associated divider */
4207 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4208 temp
&= ~SBI_SSCCTL_DISABLE
;
4209 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
4211 mutex_unlock(&dev_priv
->sb_lock
);
4213 /* Wait for initialization time */
4216 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
4219 int lpt_get_iclkip(struct drm_i915_private
*dev_priv
)
4221 u32 divsel
, phaseinc
, auxdiv
;
4222 u32 iclk_virtual_root_freq
= 172800 * 1000;
4223 u32 iclk_pi_range
= 64;
4224 u32 desired_divisor
;
4227 if ((I915_READ(PIXCLK_GATE
) & PIXCLK_GATE_UNGATE
) == 0)
4230 mutex_lock(&dev_priv
->sb_lock
);
4232 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4233 if (temp
& SBI_SSCCTL_DISABLE
) {
4234 mutex_unlock(&dev_priv
->sb_lock
);
4238 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
4239 divsel
= (temp
& SBI_SSCDIVINTPHASE_DIVSEL_MASK
) >>
4240 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT
;
4241 phaseinc
= (temp
& SBI_SSCDIVINTPHASE_INCVAL_MASK
) >>
4242 SBI_SSCDIVINTPHASE_INCVAL_SHIFT
;
4244 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
4245 auxdiv
= (temp
& SBI_SSCAUXDIV_FINALDIV2SEL_MASK
) >>
4246 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT
;
4248 mutex_unlock(&dev_priv
->sb_lock
);
4250 desired_divisor
= (divsel
+ 2) * iclk_pi_range
+ phaseinc
;
4252 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq
,
4253 desired_divisor
<< auxdiv
);
4256 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
4257 enum pipe pch_transcoder
)
4259 struct drm_device
*dev
= crtc
->base
.dev
;
4260 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4261 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
4263 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
4264 I915_READ(HTOTAL(cpu_transcoder
)));
4265 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
4266 I915_READ(HBLANK(cpu_transcoder
)));
4267 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
4268 I915_READ(HSYNC(cpu_transcoder
)));
4270 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
4271 I915_READ(VTOTAL(cpu_transcoder
)));
4272 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
4273 I915_READ(VBLANK(cpu_transcoder
)));
4274 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
4275 I915_READ(VSYNC(cpu_transcoder
)));
4276 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
4277 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
4280 static void cpt_set_fdi_bc_bifurcation(struct drm_device
*dev
, bool enable
)
4282 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4285 temp
= I915_READ(SOUTH_CHICKEN1
);
4286 if (!!(temp
& FDI_BC_BIFURCATION_SELECT
) == enable
)
4289 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
4290 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
4292 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
4294 temp
|= FDI_BC_BIFURCATION_SELECT
;
4296 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable
? "en" : "dis");
4297 I915_WRITE(SOUTH_CHICKEN1
, temp
);
4298 POSTING_READ(SOUTH_CHICKEN1
);
4301 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
4303 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4305 switch (intel_crtc
->pipe
) {
4309 if (intel_crtc
->config
->fdi_lanes
> 2)
4310 cpt_set_fdi_bc_bifurcation(dev
, false);
4312 cpt_set_fdi_bc_bifurcation(dev
, true);
4316 cpt_set_fdi_bc_bifurcation(dev
, true);
4324 /* Return which DP Port should be selected for Transcoder DP control */
4326 intel_trans_dp_port_sel(struct intel_crtc
*crtc
)
4328 struct drm_device
*dev
= crtc
->base
.dev
;
4329 struct intel_encoder
*encoder
;
4331 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
4332 if (encoder
->type
== INTEL_OUTPUT_DP
||
4333 encoder
->type
== INTEL_OUTPUT_EDP
)
4334 return enc_to_dig_port(&encoder
->base
)->port
;
4341 * Enable PCH resources required for PCH ports:
4343 * - FDI training & RX/TX
4344 * - update transcoder timings
4345 * - DP transcoding bits
4348 static void ironlake_pch_enable(const struct intel_crtc_state
*crtc_state
)
4350 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
4351 struct drm_device
*dev
= crtc
->base
.dev
;
4352 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4353 int pipe
= crtc
->pipe
;
4356 assert_pch_transcoder_disabled(dev_priv
, pipe
);
4358 if (IS_IVYBRIDGE(dev_priv
))
4359 ivybridge_update_fdi_bc_bifurcation(crtc
);
4361 /* Write the TU size bits before fdi link training, so that error
4362 * detection works. */
4363 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
4364 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
4366 /* For PCH output, training FDI link */
4367 dev_priv
->display
.fdi_link_train(crtc
, crtc_state
);
4369 /* We need to program the right clock selection before writing the pixel
4370 * mutliplier into the DPLL. */
4371 if (HAS_PCH_CPT(dev_priv
)) {
4374 temp
= I915_READ(PCH_DPLL_SEL
);
4375 temp
|= TRANS_DPLL_ENABLE(pipe
);
4376 sel
= TRANS_DPLLB_SEL(pipe
);
4377 if (crtc_state
->shared_dpll
==
4378 intel_get_shared_dpll_by_id(dev_priv
, DPLL_ID_PCH_PLL_B
))
4382 I915_WRITE(PCH_DPLL_SEL
, temp
);
4385 /* XXX: pch pll's can be enabled any time before we enable the PCH
4386 * transcoder, and we actually should do this to not upset any PCH
4387 * transcoder that already use the clock when we share it.
4389 * Note that enable_shared_dpll tries to do the right thing, but
4390 * get_shared_dpll unconditionally resets the pll - we need that to have
4391 * the right LVDS enable sequence. */
4392 intel_enable_shared_dpll(crtc
);
4394 /* set transcoder timing, panel must allow it */
4395 assert_panel_unlocked(dev_priv
, pipe
);
4396 ironlake_pch_transcoder_set_timings(crtc
, pipe
);
4398 intel_fdi_normal_train(crtc
);
4400 /* For PCH DP, enable TRANS_DP_CTL */
4401 if (HAS_PCH_CPT(dev_priv
) &&
4402 intel_crtc_has_dp_encoder(crtc_state
)) {
4403 const struct drm_display_mode
*adjusted_mode
=
4404 &crtc_state
->base
.adjusted_mode
;
4405 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
4406 i915_reg_t reg
= TRANS_DP_CTL(pipe
);
4407 temp
= I915_READ(reg
);
4408 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
4409 TRANS_DP_SYNC_MASK
|
4411 temp
|= TRANS_DP_OUTPUT_ENABLE
;
4412 temp
|= bpc
<< 9; /* same format but at 11:9 */
4414 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
4415 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
4416 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
4417 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
4419 switch (intel_trans_dp_port_sel(crtc
)) {
4421 temp
|= TRANS_DP_PORT_SEL_B
;
4424 temp
|= TRANS_DP_PORT_SEL_C
;
4427 temp
|= TRANS_DP_PORT_SEL_D
;
4433 I915_WRITE(reg
, temp
);
4436 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
4439 static void lpt_pch_enable(const struct intel_crtc_state
*crtc_state
)
4441 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
4442 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
4443 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
4445 assert_pch_transcoder_disabled(dev_priv
, PIPE_A
);
4447 lpt_program_iclkip(crtc
);
4449 /* Set transcoder timing. */
4450 ironlake_pch_transcoder_set_timings(crtc
, PIPE_A
);
4452 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
4455 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
4457 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4458 i915_reg_t dslreg
= PIPEDSL(pipe
);
4461 temp
= I915_READ(dslreg
);
4463 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
4464 if (wait_for(I915_READ(dslreg
) != temp
, 5))
4465 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
4470 skl_update_scaler(struct intel_crtc_state
*crtc_state
, bool force_detach
,
4471 unsigned int scaler_user
, int *scaler_id
,
4472 int src_w
, int src_h
, int dst_w
, int dst_h
)
4474 struct intel_crtc_scaler_state
*scaler_state
=
4475 &crtc_state
->scaler_state
;
4476 struct intel_crtc
*intel_crtc
=
4477 to_intel_crtc(crtc_state
->base
.crtc
);
4478 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
4479 const struct drm_display_mode
*adjusted_mode
=
4480 &crtc_state
->base
.adjusted_mode
;
4484 * Src coordinates are already rotated by 270 degrees for
4485 * the 90/270 degree plane rotation cases (to match the
4486 * GTT mapping), hence no need to account for rotation here.
4488 need_scaling
= src_w
!= dst_w
|| src_h
!= dst_h
;
4491 * Scaling/fitting not supported in IF-ID mode in GEN9+
4492 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4493 * Once NV12 is enabled, handle it here while allocating scaler
4496 if (INTEL_GEN(dev_priv
) >= 9 && crtc_state
->base
.enable
&&
4497 need_scaling
&& adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
4498 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
4503 * if plane is being disabled or scaler is no more required or force detach
4504 * - free scaler binded to this plane/crtc
4505 * - in order to do this, update crtc->scaler_usage
4507 * Here scaler state in crtc_state is set free so that
4508 * scaler can be assigned to other user. Actual register
4509 * update to free the scaler is done in plane/panel-fit programming.
4510 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4512 if (force_detach
|| !need_scaling
) {
4513 if (*scaler_id
>= 0) {
4514 scaler_state
->scaler_users
&= ~(1 << scaler_user
);
4515 scaler_state
->scalers
[*scaler_id
].in_use
= 0;
4517 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4518 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4519 intel_crtc
->pipe
, scaler_user
, *scaler_id
,
4520 scaler_state
->scaler_users
);
4527 if (src_w
< SKL_MIN_SRC_W
|| src_h
< SKL_MIN_SRC_H
||
4528 dst_w
< SKL_MIN_DST_W
|| dst_h
< SKL_MIN_DST_H
||
4530 src_w
> SKL_MAX_SRC_W
|| src_h
> SKL_MAX_SRC_H
||
4531 dst_w
> SKL_MAX_DST_W
|| dst_h
> SKL_MAX_DST_H
) {
4532 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4533 "size is out of scaler range\n",
4534 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
);
4538 /* mark this plane as a scaler user in crtc_state */
4539 scaler_state
->scaler_users
|= (1 << scaler_user
);
4540 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4541 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4542 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
,
4543 scaler_state
->scaler_users
);
4549 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4551 * @state: crtc's scaler state
4554 * 0 - scaler_usage updated successfully
4555 * error - requested scaling cannot be supported or other error condition
4557 int skl_update_scaler_crtc(struct intel_crtc_state
*state
)
4559 const struct drm_display_mode
*adjusted_mode
= &state
->base
.adjusted_mode
;
4561 return skl_update_scaler(state
, !state
->base
.active
, SKL_CRTC_INDEX
,
4562 &state
->scaler_state
.scaler_id
,
4563 state
->pipe_src_w
, state
->pipe_src_h
,
4564 adjusted_mode
->crtc_hdisplay
, adjusted_mode
->crtc_vdisplay
);
4568 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4570 * @state: crtc's scaler state
4571 * @plane_state: atomic plane state to update
4574 * 0 - scaler_usage updated successfully
4575 * error - requested scaling cannot be supported or other error condition
4577 static int skl_update_scaler_plane(struct intel_crtc_state
*crtc_state
,
4578 struct intel_plane_state
*plane_state
)
4581 struct intel_plane
*intel_plane
=
4582 to_intel_plane(plane_state
->base
.plane
);
4583 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
4586 bool force_detach
= !fb
|| !plane_state
->base
.visible
;
4588 ret
= skl_update_scaler(crtc_state
, force_detach
,
4589 drm_plane_index(&intel_plane
->base
),
4590 &plane_state
->scaler_id
,
4591 drm_rect_width(&plane_state
->base
.src
) >> 16,
4592 drm_rect_height(&plane_state
->base
.src
) >> 16,
4593 drm_rect_width(&plane_state
->base
.dst
),
4594 drm_rect_height(&plane_state
->base
.dst
));
4596 if (ret
|| plane_state
->scaler_id
< 0)
4599 /* check colorkey */
4600 if (plane_state
->ckey
.flags
!= I915_SET_COLORKEY_NONE
) {
4601 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
4602 intel_plane
->base
.base
.id
,
4603 intel_plane
->base
.name
);
4607 /* Check src format */
4608 switch (fb
->format
->format
) {
4609 case DRM_FORMAT_RGB565
:
4610 case DRM_FORMAT_XBGR8888
:
4611 case DRM_FORMAT_XRGB8888
:
4612 case DRM_FORMAT_ABGR8888
:
4613 case DRM_FORMAT_ARGB8888
:
4614 case DRM_FORMAT_XRGB2101010
:
4615 case DRM_FORMAT_XBGR2101010
:
4616 case DRM_FORMAT_YUYV
:
4617 case DRM_FORMAT_YVYU
:
4618 case DRM_FORMAT_UYVY
:
4619 case DRM_FORMAT_VYUY
:
4622 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
4623 intel_plane
->base
.base
.id
, intel_plane
->base
.name
,
4624 fb
->base
.id
, fb
->format
->format
);
4631 static void skylake_scaler_disable(struct intel_crtc
*crtc
)
4635 for (i
= 0; i
< crtc
->num_scalers
; i
++)
4636 skl_detach_scaler(crtc
, i
);
4639 static void skylake_pfit_enable(struct intel_crtc
*crtc
)
4641 struct drm_device
*dev
= crtc
->base
.dev
;
4642 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4643 int pipe
= crtc
->pipe
;
4644 struct intel_crtc_scaler_state
*scaler_state
=
4645 &crtc
->config
->scaler_state
;
4647 if (crtc
->config
->pch_pfit
.enabled
) {
4650 if (WARN_ON(crtc
->config
->scaler_state
.scaler_id
< 0))
4653 id
= scaler_state
->scaler_id
;
4654 I915_WRITE(SKL_PS_CTRL(pipe
, id
), PS_SCALER_EN
|
4655 PS_FILTER_MEDIUM
| scaler_state
->scalers
[id
].mode
);
4656 I915_WRITE(SKL_PS_WIN_POS(pipe
, id
), crtc
->config
->pch_pfit
.pos
);
4657 I915_WRITE(SKL_PS_WIN_SZ(pipe
, id
), crtc
->config
->pch_pfit
.size
);
4661 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
4663 struct drm_device
*dev
= crtc
->base
.dev
;
4664 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4665 int pipe
= crtc
->pipe
;
4667 if (crtc
->config
->pch_pfit
.enabled
) {
4668 /* Force use of hard-coded filter coefficients
4669 * as some pre-programmed values are broken,
4672 if (IS_IVYBRIDGE(dev_priv
) || IS_HASWELL(dev_priv
))
4673 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
4674 PF_PIPE_SEL_IVB(pipe
));
4676 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
4677 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
->pch_pfit
.pos
);
4678 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
->pch_pfit
.size
);
4682 void hsw_enable_ips(struct intel_crtc
*crtc
)
4684 struct drm_device
*dev
= crtc
->base
.dev
;
4685 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4687 if (!crtc
->config
->ips_enabled
)
4691 * We can only enable IPS after we enable a plane and wait for a vblank
4692 * This function is called from post_plane_update, which is run after
4696 assert_plane_enabled(dev_priv
, crtc
->plane
);
4697 if (IS_BROADWELL(dev_priv
)) {
4698 mutex_lock(&dev_priv
->rps
.hw_lock
);
4699 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
4700 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4701 /* Quoting Art Runyan: "its not safe to expect any particular
4702 * value in IPS_CTL bit 31 after enabling IPS through the
4703 * mailbox." Moreover, the mailbox may return a bogus state,
4704 * so we need to just enable it and continue on.
4707 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
4708 /* The bit only becomes 1 in the next vblank, so this wait here
4709 * is essentially intel_wait_for_vblank. If we don't have this
4710 * and don't wait for vblanks until the end of crtc_enable, then
4711 * the HW state readout code will complain that the expected
4712 * IPS_CTL value is not the one we read. */
4713 if (intel_wait_for_register(dev_priv
,
4714 IPS_CTL
, IPS_ENABLE
, IPS_ENABLE
,
4716 DRM_ERROR("Timed out waiting for IPS enable\n");
4720 void hsw_disable_ips(struct intel_crtc
*crtc
)
4722 struct drm_device
*dev
= crtc
->base
.dev
;
4723 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4725 if (!crtc
->config
->ips_enabled
)
4728 assert_plane_enabled(dev_priv
, crtc
->plane
);
4729 if (IS_BROADWELL(dev_priv
)) {
4730 mutex_lock(&dev_priv
->rps
.hw_lock
);
4731 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
4732 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4733 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4734 if (intel_wait_for_register(dev_priv
,
4735 IPS_CTL
, IPS_ENABLE
, 0,
4737 DRM_ERROR("Timed out waiting for IPS disable\n");
4739 I915_WRITE(IPS_CTL
, 0);
4740 POSTING_READ(IPS_CTL
);
4743 /* We need to wait for a vblank before we can disable the plane. */
4744 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
4747 static void intel_crtc_dpms_overlay_disable(struct intel_crtc
*intel_crtc
)
4749 if (intel_crtc
->overlay
) {
4750 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4752 mutex_lock(&dev
->struct_mutex
);
4753 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
4754 mutex_unlock(&dev
->struct_mutex
);
4757 /* Let userspace switch the overlay on again. In most cases userspace
4758 * has to recompute where to put it anyway.
4763 * intel_post_enable_primary - Perform operations after enabling primary plane
4764 * @crtc: the CRTC whose primary plane was just enabled
4766 * Performs potentially sleeping operations that must be done after the primary
4767 * plane is enabled, such as updating FBC and IPS. Note that this may be
4768 * called due to an explicit primary plane update, or due to an implicit
4769 * re-enable that is caused when a sprite plane is updated to no longer
4770 * completely hide the primary plane.
4773 intel_post_enable_primary(struct drm_crtc
*crtc
)
4775 struct drm_device
*dev
= crtc
->dev
;
4776 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4777 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4778 int pipe
= intel_crtc
->pipe
;
4781 * FIXME IPS should be fine as long as one plane is
4782 * enabled, but in practice it seems to have problems
4783 * when going from primary only to sprite only and vice
4786 hsw_enable_ips(intel_crtc
);
4789 * Gen2 reports pipe underruns whenever all planes are disabled.
4790 * So don't enable underrun reporting before at least some planes
4792 * FIXME: Need to fix the logic to work when we turn off all planes
4793 * but leave the pipe running.
4795 if (IS_GEN2(dev_priv
))
4796 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4798 /* Underruns don't always raise interrupts, so check manually. */
4799 intel_check_cpu_fifo_underruns(dev_priv
);
4800 intel_check_pch_fifo_underruns(dev_priv
);
4803 /* FIXME move all this to pre_plane_update() with proper state tracking */
4805 intel_pre_disable_primary(struct drm_crtc
*crtc
)
4807 struct drm_device
*dev
= crtc
->dev
;
4808 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4809 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4810 int pipe
= intel_crtc
->pipe
;
4813 * Gen2 reports pipe underruns whenever all planes are disabled.
4814 * So diasble underrun reporting before all the planes get disabled.
4815 * FIXME: Need to fix the logic to work when we turn off all planes
4816 * but leave the pipe running.
4818 if (IS_GEN2(dev_priv
))
4819 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4822 * FIXME IPS should be fine as long as one plane is
4823 * enabled, but in practice it seems to have problems
4824 * when going from primary only to sprite only and vice
4827 hsw_disable_ips(intel_crtc
);
4830 /* FIXME get rid of this and use pre_plane_update */
4832 intel_pre_disable_primary_noatomic(struct drm_crtc
*crtc
)
4834 struct drm_device
*dev
= crtc
->dev
;
4835 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4836 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4837 int pipe
= intel_crtc
->pipe
;
4839 intel_pre_disable_primary(crtc
);
4842 * Vblank time updates from the shadow to live plane control register
4843 * are blocked if the memory self-refresh mode is active at that
4844 * moment. So to make sure the plane gets truly disabled, disable
4845 * first the self-refresh mode. The self-refresh enable bit in turn
4846 * will be checked/applied by the HW only at the next frame start
4847 * event which is after the vblank start event, so we need to have a
4848 * wait-for-vblank between disabling the plane and the pipe.
4850 if (HAS_GMCH_DISPLAY(dev_priv
) &&
4851 intel_set_memory_cxsr(dev_priv
, false))
4852 intel_wait_for_vblank(dev_priv
, pipe
);
4855 static void intel_post_plane_update(struct intel_crtc_state
*old_crtc_state
)
4857 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
4858 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
4859 struct intel_crtc_state
*pipe_config
=
4860 to_intel_crtc_state(crtc
->base
.state
);
4861 struct drm_plane
*primary
= crtc
->base
.primary
;
4862 struct drm_plane_state
*old_pri_state
=
4863 drm_atomic_get_existing_plane_state(old_state
, primary
);
4865 intel_frontbuffer_flip(to_i915(crtc
->base
.dev
), pipe_config
->fb_bits
);
4867 if (pipe_config
->update_wm_post
&& pipe_config
->base
.active
)
4868 intel_update_watermarks(crtc
);
4870 if (old_pri_state
) {
4871 struct intel_plane_state
*primary_state
=
4872 to_intel_plane_state(primary
->state
);
4873 struct intel_plane_state
*old_primary_state
=
4874 to_intel_plane_state(old_pri_state
);
4876 intel_fbc_post_update(crtc
);
4878 if (primary_state
->base
.visible
&&
4879 (needs_modeset(&pipe_config
->base
) ||
4880 !old_primary_state
->base
.visible
))
4881 intel_post_enable_primary(&crtc
->base
);
4885 static void intel_pre_plane_update(struct intel_crtc_state
*old_crtc_state
,
4886 struct intel_crtc_state
*pipe_config
)
4888 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
4889 struct drm_device
*dev
= crtc
->base
.dev
;
4890 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4891 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
4892 struct drm_plane
*primary
= crtc
->base
.primary
;
4893 struct drm_plane_state
*old_pri_state
=
4894 drm_atomic_get_existing_plane_state(old_state
, primary
);
4895 bool modeset
= needs_modeset(&pipe_config
->base
);
4896 struct intel_atomic_state
*old_intel_state
=
4897 to_intel_atomic_state(old_state
);
4899 if (old_pri_state
) {
4900 struct intel_plane_state
*primary_state
=
4901 to_intel_plane_state(primary
->state
);
4902 struct intel_plane_state
*old_primary_state
=
4903 to_intel_plane_state(old_pri_state
);
4905 intel_fbc_pre_update(crtc
, pipe_config
, primary_state
);
4907 if (old_primary_state
->base
.visible
&&
4908 (modeset
|| !primary_state
->base
.visible
))
4909 intel_pre_disable_primary(&crtc
->base
);
4913 * Vblank time updates from the shadow to live plane control register
4914 * are blocked if the memory self-refresh mode is active at that
4915 * moment. So to make sure the plane gets truly disabled, disable
4916 * first the self-refresh mode. The self-refresh enable bit in turn
4917 * will be checked/applied by the HW only at the next frame start
4918 * event which is after the vblank start event, so we need to have a
4919 * wait-for-vblank between disabling the plane and the pipe.
4921 if (HAS_GMCH_DISPLAY(dev_priv
) && old_crtc_state
->base
.active
&&
4922 pipe_config
->disable_cxsr
&& intel_set_memory_cxsr(dev_priv
, false))
4923 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
4926 * IVB workaround: must disable low power watermarks for at least
4927 * one frame before enabling scaling. LP watermarks can be re-enabled
4928 * when scaling is disabled.
4930 * WaCxSRDisabledForSpriteScaling:ivb
4932 if (pipe_config
->disable_lp_wm
&& ilk_disable_lp_wm(dev
))
4933 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
4936 * If we're doing a modeset, we're done. No need to do any pre-vblank
4937 * watermark programming here.
4939 if (needs_modeset(&pipe_config
->base
))
4943 * For platforms that support atomic watermarks, program the
4944 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
4945 * will be the intermediate values that are safe for both pre- and
4946 * post- vblank; when vblank happens, the 'active' values will be set
4947 * to the final 'target' values and we'll do this again to get the
4948 * optimal watermarks. For gen9+ platforms, the values we program here
4949 * will be the final target values which will get automatically latched
4950 * at vblank time; no further programming will be necessary.
4952 * If a platform hasn't been transitioned to atomic watermarks yet,
4953 * we'll continue to update watermarks the old way, if flags tell
4956 if (dev_priv
->display
.initial_watermarks
!= NULL
)
4957 dev_priv
->display
.initial_watermarks(old_intel_state
,
4959 else if (pipe_config
->update_wm_pre
)
4960 intel_update_watermarks(crtc
);
4963 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
, unsigned plane_mask
)
4965 struct drm_device
*dev
= crtc
->dev
;
4966 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4967 struct drm_plane
*p
;
4968 int pipe
= intel_crtc
->pipe
;
4970 intel_crtc_dpms_overlay_disable(intel_crtc
);
4972 drm_for_each_plane_mask(p
, dev
, plane_mask
)
4973 to_intel_plane(p
)->disable_plane(to_intel_plane(p
), intel_crtc
);
4976 * FIXME: Once we grow proper nuclear flip support out of this we need
4977 * to compute the mask of flip planes precisely. For the time being
4978 * consider this a flip to a NULL plane.
4980 intel_frontbuffer_flip(to_i915(dev
), INTEL_FRONTBUFFER_ALL_MASK(pipe
));
4983 static void intel_encoders_pre_pll_enable(struct drm_crtc
*crtc
,
4984 struct intel_crtc_state
*crtc_state
,
4985 struct drm_atomic_state
*old_state
)
4987 struct drm_connector_state
*conn_state
;
4988 struct drm_connector
*conn
;
4991 for_each_new_connector_in_state(old_state
, conn
, conn_state
, i
) {
4992 struct intel_encoder
*encoder
=
4993 to_intel_encoder(conn_state
->best_encoder
);
4995 if (conn_state
->crtc
!= crtc
)
4998 if (encoder
->pre_pll_enable
)
4999 encoder
->pre_pll_enable(encoder
, crtc_state
, conn_state
);
5003 static void intel_encoders_pre_enable(struct drm_crtc
*crtc
,
5004 struct intel_crtc_state
*crtc_state
,
5005 struct drm_atomic_state
*old_state
)
5007 struct drm_connector_state
*conn_state
;
5008 struct drm_connector
*conn
;
5011 for_each_new_connector_in_state(old_state
, conn
, conn_state
, i
) {
5012 struct intel_encoder
*encoder
=
5013 to_intel_encoder(conn_state
->best_encoder
);
5015 if (conn_state
->crtc
!= crtc
)
5018 if (encoder
->pre_enable
)
5019 encoder
->pre_enable(encoder
, crtc_state
, conn_state
);
5023 static void intel_encoders_enable(struct drm_crtc
*crtc
,
5024 struct intel_crtc_state
*crtc_state
,
5025 struct drm_atomic_state
*old_state
)
5027 struct drm_connector_state
*conn_state
;
5028 struct drm_connector
*conn
;
5031 for_each_new_connector_in_state(old_state
, conn
, conn_state
, i
) {
5032 struct intel_encoder
*encoder
=
5033 to_intel_encoder(conn_state
->best_encoder
);
5035 if (conn_state
->crtc
!= crtc
)
5038 encoder
->enable(encoder
, crtc_state
, conn_state
);
5039 intel_opregion_notify_encoder(encoder
, true);
5043 static void intel_encoders_disable(struct drm_crtc
*crtc
,
5044 struct intel_crtc_state
*old_crtc_state
,
5045 struct drm_atomic_state
*old_state
)
5047 struct drm_connector_state
*old_conn_state
;
5048 struct drm_connector
*conn
;
5051 for_each_old_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5052 struct intel_encoder
*encoder
=
5053 to_intel_encoder(old_conn_state
->best_encoder
);
5055 if (old_conn_state
->crtc
!= crtc
)
5058 intel_opregion_notify_encoder(encoder
, false);
5059 encoder
->disable(encoder
, old_crtc_state
, old_conn_state
);
5063 static void intel_encoders_post_disable(struct drm_crtc
*crtc
,
5064 struct intel_crtc_state
*old_crtc_state
,
5065 struct drm_atomic_state
*old_state
)
5067 struct drm_connector_state
*old_conn_state
;
5068 struct drm_connector
*conn
;
5071 for_each_old_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5072 struct intel_encoder
*encoder
=
5073 to_intel_encoder(old_conn_state
->best_encoder
);
5075 if (old_conn_state
->crtc
!= crtc
)
5078 if (encoder
->post_disable
)
5079 encoder
->post_disable(encoder
, old_crtc_state
, old_conn_state
);
5083 static void intel_encoders_post_pll_disable(struct drm_crtc
*crtc
,
5084 struct intel_crtc_state
*old_crtc_state
,
5085 struct drm_atomic_state
*old_state
)
5087 struct drm_connector_state
*old_conn_state
;
5088 struct drm_connector
*conn
;
5091 for_each_old_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5092 struct intel_encoder
*encoder
=
5093 to_intel_encoder(old_conn_state
->best_encoder
);
5095 if (old_conn_state
->crtc
!= crtc
)
5098 if (encoder
->post_pll_disable
)
5099 encoder
->post_pll_disable(encoder
, old_crtc_state
, old_conn_state
);
5103 static void ironlake_crtc_enable(struct intel_crtc_state
*pipe_config
,
5104 struct drm_atomic_state
*old_state
)
5106 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5107 struct drm_device
*dev
= crtc
->dev
;
5108 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5109 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5110 int pipe
= intel_crtc
->pipe
;
5111 struct intel_atomic_state
*old_intel_state
=
5112 to_intel_atomic_state(old_state
);
5114 if (WARN_ON(intel_crtc
->active
))
5118 * Sometimes spurious CPU pipe underruns happen during FDI
5119 * training, at least with VGA+HDMI cloning. Suppress them.
5121 * On ILK we get an occasional spurious CPU pipe underruns
5122 * between eDP port A enable and vdd enable. Also PCH port
5123 * enable seems to result in the occasional CPU pipe underrun.
5125 * Spurious PCH underruns also occur during PCH enabling.
5127 if (intel_crtc
->config
->has_pch_encoder
|| IS_GEN5(dev_priv
))
5128 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5129 if (intel_crtc
->config
->has_pch_encoder
)
5130 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
5132 if (intel_crtc
->config
->has_pch_encoder
)
5133 intel_prepare_shared_dpll(intel_crtc
);
5135 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5136 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5138 intel_set_pipe_timings(intel_crtc
);
5139 intel_set_pipe_src_size(intel_crtc
);
5141 if (intel_crtc
->config
->has_pch_encoder
) {
5142 intel_cpu_transcoder_set_m_n(intel_crtc
,
5143 &intel_crtc
->config
->fdi_m_n
, NULL
);
5146 ironlake_set_pipeconf(crtc
);
5148 intel_crtc
->active
= true;
5150 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5152 if (intel_crtc
->config
->has_pch_encoder
) {
5153 /* Note: FDI PLL enabling _must_ be done before we enable the
5154 * cpu pipes, hence this is separate from all the other fdi/pch
5156 ironlake_fdi_pll_enable(intel_crtc
);
5158 assert_fdi_tx_disabled(dev_priv
, pipe
);
5159 assert_fdi_rx_disabled(dev_priv
, pipe
);
5162 ironlake_pfit_enable(intel_crtc
);
5165 * On ILK+ LUT must be loaded before the pipe is running but with
5168 intel_color_load_luts(&pipe_config
->base
);
5170 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5171 dev_priv
->display
.initial_watermarks(old_intel_state
, intel_crtc
->config
);
5172 intel_enable_pipe(intel_crtc
);
5174 if (intel_crtc
->config
->has_pch_encoder
)
5175 ironlake_pch_enable(pipe_config
);
5177 assert_vblank_disabled(crtc
);
5178 drm_crtc_vblank_on(crtc
);
5180 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5182 if (HAS_PCH_CPT(dev_priv
))
5183 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
5185 /* Must wait for vblank to avoid spurious PCH FIFO underruns */
5186 if (intel_crtc
->config
->has_pch_encoder
)
5187 intel_wait_for_vblank(dev_priv
, pipe
);
5188 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5189 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
5192 /* IPS only exists on ULT machines and is tied to pipe A. */
5193 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
5195 return HAS_IPS(to_i915(crtc
->base
.dev
)) && crtc
->pipe
== PIPE_A
;
5198 static void haswell_crtc_enable(struct intel_crtc_state
*pipe_config
,
5199 struct drm_atomic_state
*old_state
)
5201 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5202 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5203 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5204 int pipe
= intel_crtc
->pipe
, hsw_workaround_pipe
;
5205 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5206 struct intel_atomic_state
*old_intel_state
=
5207 to_intel_atomic_state(old_state
);
5209 if (WARN_ON(intel_crtc
->active
))
5212 if (intel_crtc
->config
->has_pch_encoder
)
5213 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, false);
5215 intel_encoders_pre_pll_enable(crtc
, pipe_config
, old_state
);
5217 if (intel_crtc
->config
->shared_dpll
)
5218 intel_enable_shared_dpll(intel_crtc
);
5220 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5221 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5223 if (!transcoder_is_dsi(cpu_transcoder
))
5224 intel_set_pipe_timings(intel_crtc
);
5226 intel_set_pipe_src_size(intel_crtc
);
5228 if (cpu_transcoder
!= TRANSCODER_EDP
&&
5229 !transcoder_is_dsi(cpu_transcoder
)) {
5230 I915_WRITE(PIPE_MULT(cpu_transcoder
),
5231 intel_crtc
->config
->pixel_multiplier
- 1);
5234 if (intel_crtc
->config
->has_pch_encoder
) {
5235 intel_cpu_transcoder_set_m_n(intel_crtc
,
5236 &intel_crtc
->config
->fdi_m_n
, NULL
);
5239 if (!transcoder_is_dsi(cpu_transcoder
))
5240 haswell_set_pipeconf(crtc
);
5242 haswell_set_pipemisc(crtc
);
5244 intel_color_set_csc(&pipe_config
->base
);
5246 intel_crtc
->active
= true;
5248 if (intel_crtc
->config
->has_pch_encoder
)
5249 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5251 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5253 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5255 if (intel_crtc
->config
->has_pch_encoder
)
5256 dev_priv
->display
.fdi_link_train(intel_crtc
, pipe_config
);
5258 if (!transcoder_is_dsi(cpu_transcoder
))
5259 intel_ddi_enable_pipe_clock(pipe_config
);
5261 if (INTEL_GEN(dev_priv
) >= 9)
5262 skylake_pfit_enable(intel_crtc
);
5264 ironlake_pfit_enable(intel_crtc
);
5267 * On ILK+ LUT must be loaded before the pipe is running but with
5270 intel_color_load_luts(&pipe_config
->base
);
5272 intel_ddi_set_pipe_settings(pipe_config
);
5273 if (!transcoder_is_dsi(cpu_transcoder
))
5274 intel_ddi_enable_transcoder_func(pipe_config
);
5276 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5277 dev_priv
->display
.initial_watermarks(old_intel_state
, pipe_config
);
5279 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5280 if (!transcoder_is_dsi(cpu_transcoder
))
5281 intel_enable_pipe(intel_crtc
);
5283 if (intel_crtc
->config
->has_pch_encoder
)
5284 lpt_pch_enable(pipe_config
);
5286 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DP_MST
))
5287 intel_ddi_set_vc_payload_alloc(pipe_config
, true);
5289 assert_vblank_disabled(crtc
);
5290 drm_crtc_vblank_on(crtc
);
5292 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5294 if (intel_crtc
->config
->has_pch_encoder
) {
5295 intel_wait_for_vblank(dev_priv
, pipe
);
5296 intel_wait_for_vblank(dev_priv
, pipe
);
5297 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5298 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, true);
5301 /* If we change the relative order between pipe/planes enabling, we need
5302 * to change the workaround. */
5303 hsw_workaround_pipe
= pipe_config
->hsw_workaround_pipe
;
5304 if (IS_HASWELL(dev_priv
) && hsw_workaround_pipe
!= INVALID_PIPE
) {
5305 intel_wait_for_vblank(dev_priv
, hsw_workaround_pipe
);
5306 intel_wait_for_vblank(dev_priv
, hsw_workaround_pipe
);
5310 static void ironlake_pfit_disable(struct intel_crtc
*crtc
, bool force
)
5312 struct drm_device
*dev
= crtc
->base
.dev
;
5313 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5314 int pipe
= crtc
->pipe
;
5316 /* To avoid upsetting the power well on haswell only disable the pfit if
5317 * it's in use. The hw state code will make sure we get this right. */
5318 if (force
|| crtc
->config
->pch_pfit
.enabled
) {
5319 I915_WRITE(PF_CTL(pipe
), 0);
5320 I915_WRITE(PF_WIN_POS(pipe
), 0);
5321 I915_WRITE(PF_WIN_SZ(pipe
), 0);
5325 static void ironlake_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5326 struct drm_atomic_state
*old_state
)
5328 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5329 struct drm_device
*dev
= crtc
->dev
;
5330 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5331 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5332 int pipe
= intel_crtc
->pipe
;
5335 * Sometimes spurious CPU pipe underruns happen when the
5336 * pipe is already disabled, but FDI RX/TX is still enabled.
5337 * Happens at least with VGA+HDMI cloning. Suppress them.
5339 if (intel_crtc
->config
->has_pch_encoder
) {
5340 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5341 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
5344 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5346 drm_crtc_vblank_off(crtc
);
5347 assert_vblank_disabled(crtc
);
5349 intel_disable_pipe(intel_crtc
);
5351 ironlake_pfit_disable(intel_crtc
, false);
5353 if (intel_crtc
->config
->has_pch_encoder
)
5354 ironlake_fdi_disable(crtc
);
5356 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5358 if (intel_crtc
->config
->has_pch_encoder
) {
5359 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
5361 if (HAS_PCH_CPT(dev_priv
)) {
5365 /* disable TRANS_DP_CTL */
5366 reg
= TRANS_DP_CTL(pipe
);
5367 temp
= I915_READ(reg
);
5368 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
5369 TRANS_DP_PORT_SEL_MASK
);
5370 temp
|= TRANS_DP_PORT_SEL_NONE
;
5371 I915_WRITE(reg
, temp
);
5373 /* disable DPLL_SEL */
5374 temp
= I915_READ(PCH_DPLL_SEL
);
5375 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
5376 I915_WRITE(PCH_DPLL_SEL
, temp
);
5379 ironlake_fdi_pll_disable(intel_crtc
);
5382 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5383 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
5386 static void haswell_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5387 struct drm_atomic_state
*old_state
)
5389 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5390 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5391 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5392 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5394 if (intel_crtc
->config
->has_pch_encoder
)
5395 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, false);
5397 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5399 drm_crtc_vblank_off(crtc
);
5400 assert_vblank_disabled(crtc
);
5402 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5403 if (!transcoder_is_dsi(cpu_transcoder
))
5404 intel_disable_pipe(intel_crtc
);
5406 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DP_MST
))
5407 intel_ddi_set_vc_payload_alloc(intel_crtc
->config
, false);
5409 if (!transcoder_is_dsi(cpu_transcoder
))
5410 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
5412 if (INTEL_GEN(dev_priv
) >= 9)
5413 skylake_scaler_disable(intel_crtc
);
5415 ironlake_pfit_disable(intel_crtc
, false);
5417 if (!transcoder_is_dsi(cpu_transcoder
))
5418 intel_ddi_disable_pipe_clock(intel_crtc
->config
);
5420 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5422 if (old_crtc_state
->has_pch_encoder
)
5423 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, true);
5426 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
5428 struct drm_device
*dev
= crtc
->base
.dev
;
5429 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5430 struct intel_crtc_state
*pipe_config
= crtc
->config
;
5432 if (!pipe_config
->gmch_pfit
.control
)
5436 * The panel fitter should only be adjusted whilst the pipe is disabled,
5437 * according to register description and PRM.
5439 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
5440 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5442 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
5443 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
5445 /* Border color in case we don't scale up to the full screen. Black by
5446 * default, change to something else for debugging. */
5447 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
5450 enum intel_display_power_domain
intel_port_to_power_domain(enum port port
)
5454 return POWER_DOMAIN_PORT_DDI_A_LANES
;
5456 return POWER_DOMAIN_PORT_DDI_B_LANES
;
5458 return POWER_DOMAIN_PORT_DDI_C_LANES
;
5460 return POWER_DOMAIN_PORT_DDI_D_LANES
;
5462 return POWER_DOMAIN_PORT_DDI_E_LANES
;
5465 return POWER_DOMAIN_PORT_OTHER
;
5469 static u64
get_crtc_power_domains(struct drm_crtc
*crtc
,
5470 struct intel_crtc_state
*crtc_state
)
5472 struct drm_device
*dev
= crtc
->dev
;
5473 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5474 struct drm_encoder
*encoder
;
5475 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5476 enum pipe pipe
= intel_crtc
->pipe
;
5478 enum transcoder transcoder
= crtc_state
->cpu_transcoder
;
5480 if (!crtc_state
->base
.active
)
5483 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
5484 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
5485 if (crtc_state
->pch_pfit
.enabled
||
5486 crtc_state
->pch_pfit
.force_thru
)
5487 mask
|= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
5489 drm_for_each_encoder_mask(encoder
, dev
, crtc_state
->base
.encoder_mask
) {
5490 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5492 mask
|= BIT_ULL(intel_encoder
->power_domain
);
5495 if (HAS_DDI(dev_priv
) && crtc_state
->has_audio
)
5496 mask
|= BIT(POWER_DOMAIN_AUDIO
);
5498 if (crtc_state
->shared_dpll
)
5499 mask
|= BIT_ULL(POWER_DOMAIN_PLLS
);
5505 modeset_get_crtc_power_domains(struct drm_crtc
*crtc
,
5506 struct intel_crtc_state
*crtc_state
)
5508 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5509 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5510 enum intel_display_power_domain domain
;
5511 u64 domains
, new_domains
, old_domains
;
5513 old_domains
= intel_crtc
->enabled_power_domains
;
5514 intel_crtc
->enabled_power_domains
= new_domains
=
5515 get_crtc_power_domains(crtc
, crtc_state
);
5517 domains
= new_domains
& ~old_domains
;
5519 for_each_power_domain(domain
, domains
)
5520 intel_display_power_get(dev_priv
, domain
);
5522 return old_domains
& ~new_domains
;
5525 static void modeset_put_power_domains(struct drm_i915_private
*dev_priv
,
5528 enum intel_display_power_domain domain
;
5530 for_each_power_domain(domain
, domains
)
5531 intel_display_power_put(dev_priv
, domain
);
5534 static void valleyview_crtc_enable(struct intel_crtc_state
*pipe_config
,
5535 struct drm_atomic_state
*old_state
)
5537 struct intel_atomic_state
*old_intel_state
=
5538 to_intel_atomic_state(old_state
);
5539 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5540 struct drm_device
*dev
= crtc
->dev
;
5541 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5542 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5543 int pipe
= intel_crtc
->pipe
;
5545 if (WARN_ON(intel_crtc
->active
))
5548 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5549 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5551 intel_set_pipe_timings(intel_crtc
);
5552 intel_set_pipe_src_size(intel_crtc
);
5554 if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_B
) {
5555 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5557 I915_WRITE(CHV_BLEND(pipe
), CHV_BLEND_LEGACY
);
5558 I915_WRITE(CHV_CANVAS(pipe
), 0);
5561 i9xx_set_pipeconf(intel_crtc
);
5563 intel_crtc
->active
= true;
5565 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5567 intel_encoders_pre_pll_enable(crtc
, pipe_config
, old_state
);
5569 if (IS_CHERRYVIEW(dev_priv
)) {
5570 chv_prepare_pll(intel_crtc
, intel_crtc
->config
);
5571 chv_enable_pll(intel_crtc
, intel_crtc
->config
);
5573 vlv_prepare_pll(intel_crtc
, intel_crtc
->config
);
5574 vlv_enable_pll(intel_crtc
, intel_crtc
->config
);
5577 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5579 i9xx_pfit_enable(intel_crtc
);
5581 intel_color_load_luts(&pipe_config
->base
);
5583 dev_priv
->display
.initial_watermarks(old_intel_state
,
5585 intel_enable_pipe(intel_crtc
);
5587 assert_vblank_disabled(crtc
);
5588 drm_crtc_vblank_on(crtc
);
5590 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5593 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
5595 struct drm_device
*dev
= crtc
->base
.dev
;
5596 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5598 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp0
);
5599 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp1
);
5602 static void i9xx_crtc_enable(struct intel_crtc_state
*pipe_config
,
5603 struct drm_atomic_state
*old_state
)
5605 struct intel_atomic_state
*old_intel_state
=
5606 to_intel_atomic_state(old_state
);
5607 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5608 struct drm_device
*dev
= crtc
->dev
;
5609 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5610 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5611 enum pipe pipe
= intel_crtc
->pipe
;
5613 if (WARN_ON(intel_crtc
->active
))
5616 i9xx_set_pll_dividers(intel_crtc
);
5618 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5619 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5621 intel_set_pipe_timings(intel_crtc
);
5622 intel_set_pipe_src_size(intel_crtc
);
5624 i9xx_set_pipeconf(intel_crtc
);
5626 intel_crtc
->active
= true;
5628 if (!IS_GEN2(dev_priv
))
5629 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5631 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5633 i9xx_enable_pll(intel_crtc
);
5635 i9xx_pfit_enable(intel_crtc
);
5637 intel_color_load_luts(&pipe_config
->base
);
5639 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5640 dev_priv
->display
.initial_watermarks(old_intel_state
,
5641 intel_crtc
->config
);
5643 intel_update_watermarks(intel_crtc
);
5644 intel_enable_pipe(intel_crtc
);
5646 assert_vblank_disabled(crtc
);
5647 drm_crtc_vblank_on(crtc
);
5649 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5652 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
5654 struct drm_device
*dev
= crtc
->base
.dev
;
5655 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5657 if (!crtc
->config
->gmch_pfit
.control
)
5660 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5662 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
5663 I915_READ(PFIT_CONTROL
));
5664 I915_WRITE(PFIT_CONTROL
, 0);
5667 static void i9xx_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5668 struct drm_atomic_state
*old_state
)
5670 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5671 struct drm_device
*dev
= crtc
->dev
;
5672 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5673 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5674 int pipe
= intel_crtc
->pipe
;
5677 * On gen2 planes are double buffered but the pipe isn't, so we must
5678 * wait for planes to fully turn off before disabling the pipe.
5680 if (IS_GEN2(dev_priv
))
5681 intel_wait_for_vblank(dev_priv
, pipe
);
5683 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5685 drm_crtc_vblank_off(crtc
);
5686 assert_vblank_disabled(crtc
);
5688 intel_disable_pipe(intel_crtc
);
5690 i9xx_pfit_disable(intel_crtc
);
5692 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5694 if (!intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DSI
)) {
5695 if (IS_CHERRYVIEW(dev_priv
))
5696 chv_disable_pll(dev_priv
, pipe
);
5697 else if (IS_VALLEYVIEW(dev_priv
))
5698 vlv_disable_pll(dev_priv
, pipe
);
5700 i9xx_disable_pll(intel_crtc
);
5703 intel_encoders_post_pll_disable(crtc
, old_crtc_state
, old_state
);
5705 if (!IS_GEN2(dev_priv
))
5706 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5708 if (!dev_priv
->display
.initial_watermarks
)
5709 intel_update_watermarks(intel_crtc
);
5711 /* clock the pipe down to 640x480@60 to potentially save power */
5712 if (IS_I830(dev_priv
))
5713 i830_enable_pipe(dev_priv
, pipe
);
5716 static void intel_crtc_disable_noatomic(struct drm_crtc
*crtc
,
5717 struct drm_modeset_acquire_ctx
*ctx
)
5719 struct intel_encoder
*encoder
;
5720 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5721 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5722 enum intel_display_power_domain domain
;
5724 struct drm_atomic_state
*state
;
5725 struct intel_crtc_state
*crtc_state
;
5728 if (!intel_crtc
->active
)
5731 if (crtc
->primary
->state
->visible
) {
5732 intel_pre_disable_primary_noatomic(crtc
);
5734 intel_crtc_disable_planes(crtc
, 1 << drm_plane_index(crtc
->primary
));
5735 crtc
->primary
->state
->visible
= false;
5738 state
= drm_atomic_state_alloc(crtc
->dev
);
5740 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
5741 crtc
->base
.id
, crtc
->name
);
5745 state
->acquire_ctx
= ctx
;
5747 /* Everything's already locked, -EDEADLK can't happen. */
5748 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
5749 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
5751 WARN_ON(IS_ERR(crtc_state
) || ret
);
5753 dev_priv
->display
.crtc_disable(crtc_state
, state
);
5755 drm_atomic_state_put(state
);
5757 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
5758 crtc
->base
.id
, crtc
->name
);
5760 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->state
, NULL
) < 0);
5761 crtc
->state
->active
= false;
5762 intel_crtc
->active
= false;
5763 crtc
->enabled
= false;
5764 crtc
->state
->connector_mask
= 0;
5765 crtc
->state
->encoder_mask
= 0;
5767 for_each_encoder_on_crtc(crtc
->dev
, crtc
, encoder
)
5768 encoder
->base
.crtc
= NULL
;
5770 intel_fbc_disable(intel_crtc
);
5771 intel_update_watermarks(intel_crtc
);
5772 intel_disable_shared_dpll(intel_crtc
);
5774 domains
= intel_crtc
->enabled_power_domains
;
5775 for_each_power_domain(domain
, domains
)
5776 intel_display_power_put(dev_priv
, domain
);
5777 intel_crtc
->enabled_power_domains
= 0;
5779 dev_priv
->active_crtcs
&= ~(1 << intel_crtc
->pipe
);
5780 dev_priv
->min_pixclk
[intel_crtc
->pipe
] = 0;
5784 * turn all crtc's off, but do not adjust state
5785 * This has to be paired with a call to intel_modeset_setup_hw_state.
5787 int intel_display_suspend(struct drm_device
*dev
)
5789 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5790 struct drm_atomic_state
*state
;
5793 state
= drm_atomic_helper_suspend(dev
);
5794 ret
= PTR_ERR_OR_ZERO(state
);
5796 DRM_ERROR("Suspending crtc's failed with %i\n", ret
);
5798 dev_priv
->modeset_restore_state
= state
;
5802 void intel_encoder_destroy(struct drm_encoder
*encoder
)
5804 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5806 drm_encoder_cleanup(encoder
);
5807 kfree(intel_encoder
);
5810 /* Cross check the actual hw state with our own modeset state tracking (and it's
5811 * internal consistency). */
5812 static void intel_connector_verify_state(struct drm_crtc_state
*crtc_state
,
5813 struct drm_connector_state
*conn_state
)
5815 struct intel_connector
*connector
= to_intel_connector(conn_state
->connector
);
5817 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
5818 connector
->base
.base
.id
,
5819 connector
->base
.name
);
5821 if (connector
->get_hw_state(connector
)) {
5822 struct intel_encoder
*encoder
= connector
->encoder
;
5824 I915_STATE_WARN(!crtc_state
,
5825 "connector enabled without attached crtc\n");
5830 I915_STATE_WARN(!crtc_state
->active
,
5831 "connector is active, but attached crtc isn't\n");
5833 if (!encoder
|| encoder
->type
== INTEL_OUTPUT_DP_MST
)
5836 I915_STATE_WARN(conn_state
->best_encoder
!= &encoder
->base
,
5837 "atomic encoder doesn't match attached encoder\n");
5839 I915_STATE_WARN(conn_state
->crtc
!= encoder
->base
.crtc
,
5840 "attached encoder crtc differs from connector crtc\n");
5842 I915_STATE_WARN(crtc_state
&& crtc_state
->active
,
5843 "attached crtc is active, but connector isn't\n");
5844 I915_STATE_WARN(!crtc_state
&& conn_state
->best_encoder
,
5845 "best encoder set without crtc!\n");
5849 int intel_connector_init(struct intel_connector
*connector
)
5851 struct intel_digital_connector_state
*conn_state
;
5854 * Allocate enough memory to hold intel_digital_connector_state,
5855 * This might be a few bytes too many, but for connectors that don't
5856 * need it we'll free the state and allocate a smaller one on the first
5857 * succesful commit anyway.
5859 conn_state
= kzalloc(sizeof(*conn_state
), GFP_KERNEL
);
5863 __drm_atomic_helper_connector_reset(&connector
->base
,
5869 struct intel_connector
*intel_connector_alloc(void)
5871 struct intel_connector
*connector
;
5873 connector
= kzalloc(sizeof *connector
, GFP_KERNEL
);
5877 if (intel_connector_init(connector
) < 0) {
5885 /* Simple connector->get_hw_state implementation for encoders that support only
5886 * one connector and no cloning and hence the encoder state determines the state
5887 * of the connector. */
5888 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
5891 struct intel_encoder
*encoder
= connector
->encoder
;
5893 return encoder
->get_hw_state(encoder
, &pipe
);
5896 static int pipe_required_fdi_lanes(struct intel_crtc_state
*crtc_state
)
5898 if (crtc_state
->base
.enable
&& crtc_state
->has_pch_encoder
)
5899 return crtc_state
->fdi_lanes
;
5904 static int ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
5905 struct intel_crtc_state
*pipe_config
)
5907 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5908 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
5909 struct intel_crtc
*other_crtc
;
5910 struct intel_crtc_state
*other_crtc_state
;
5912 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
5913 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5914 if (pipe_config
->fdi_lanes
> 4) {
5915 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
5916 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5920 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
5921 if (pipe_config
->fdi_lanes
> 2) {
5922 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
5923 pipe_config
->fdi_lanes
);
5930 if (INTEL_INFO(dev_priv
)->num_pipes
== 2)
5933 /* Ivybridge 3 pipe is really complicated */
5938 if (pipe_config
->fdi_lanes
<= 2)
5941 other_crtc
= intel_get_crtc_for_pipe(dev_priv
, PIPE_C
);
5943 intel_atomic_get_crtc_state(state
, other_crtc
);
5944 if (IS_ERR(other_crtc_state
))
5945 return PTR_ERR(other_crtc_state
);
5947 if (pipe_required_fdi_lanes(other_crtc_state
) > 0) {
5948 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5949 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5954 if (pipe_config
->fdi_lanes
> 2) {
5955 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
5956 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5960 other_crtc
= intel_get_crtc_for_pipe(dev_priv
, PIPE_B
);
5962 intel_atomic_get_crtc_state(state
, other_crtc
);
5963 if (IS_ERR(other_crtc_state
))
5964 return PTR_ERR(other_crtc_state
);
5966 if (pipe_required_fdi_lanes(other_crtc_state
) > 2) {
5967 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
5977 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
5978 struct intel_crtc_state
*pipe_config
)
5980 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5981 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
5982 int lane
, link_bw
, fdi_dotclock
, ret
;
5983 bool needs_recompute
= false;
5986 /* FDI is a binary signal running at ~2.7GHz, encoding
5987 * each output octet as 10 bits. The actual frequency
5988 * is stored as a divider into a 100MHz clock, and the
5989 * mode pixel clock is stored in units of 1KHz.
5990 * Hence the bw of each lane in terms of the mode signal
5993 link_bw
= intel_fdi_link_freq(to_i915(dev
), pipe_config
);
5995 fdi_dotclock
= adjusted_mode
->crtc_clock
;
5997 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
5998 pipe_config
->pipe_bpp
);
6000 pipe_config
->fdi_lanes
= lane
;
6002 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
6003 link_bw
, &pipe_config
->fdi_m_n
, false);
6005 ret
= ironlake_check_fdi_lanes(dev
, intel_crtc
->pipe
, pipe_config
);
6006 if (ret
== -EINVAL
&& pipe_config
->pipe_bpp
> 6*3) {
6007 pipe_config
->pipe_bpp
-= 2*3;
6008 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6009 pipe_config
->pipe_bpp
);
6010 needs_recompute
= true;
6011 pipe_config
->bw_constrained
= true;
6016 if (needs_recompute
)
6022 static bool pipe_config_supports_ips(struct drm_i915_private
*dev_priv
,
6023 struct intel_crtc_state
*pipe_config
)
6025 if (pipe_config
->pipe_bpp
> 24)
6028 /* HSW can handle pixel rate up to cdclk? */
6029 if (IS_HASWELL(dev_priv
))
6033 * We compare against max which means we must take
6034 * the increased cdclk requirement into account when
6035 * calculating the new cdclk.
6037 * Should measure whether using a lower cdclk w/o IPS
6039 return pipe_config
->pixel_rate
<=
6040 dev_priv
->max_cdclk_freq
* 95 / 100;
6043 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
6044 struct intel_crtc_state
*pipe_config
)
6046 struct drm_device
*dev
= crtc
->base
.dev
;
6047 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6049 pipe_config
->ips_enabled
= i915
.enable_ips
&&
6050 hsw_crtc_supports_ips(crtc
) &&
6051 pipe_config_supports_ips(dev_priv
, pipe_config
);
6054 static bool intel_crtc_supports_double_wide(const struct intel_crtc
*crtc
)
6056 const struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6058 /* GDG double wide on either pipe, otherwise pipe A only */
6059 return INTEL_INFO(dev_priv
)->gen
< 4 &&
6060 (crtc
->pipe
== PIPE_A
|| IS_I915G(dev_priv
));
6063 static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state
*pipe_config
)
6065 uint32_t pixel_rate
;
6067 pixel_rate
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
6070 * We only use IF-ID interlacing. If we ever use
6071 * PF-ID we'll need to adjust the pixel_rate here.
6074 if (pipe_config
->pch_pfit
.enabled
) {
6075 uint64_t pipe_w
, pipe_h
, pfit_w
, pfit_h
;
6076 uint32_t pfit_size
= pipe_config
->pch_pfit
.size
;
6078 pipe_w
= pipe_config
->pipe_src_w
;
6079 pipe_h
= pipe_config
->pipe_src_h
;
6081 pfit_w
= (pfit_size
>> 16) & 0xFFFF;
6082 pfit_h
= pfit_size
& 0xFFFF;
6083 if (pipe_w
< pfit_w
)
6085 if (pipe_h
< pfit_h
)
6088 if (WARN_ON(!pfit_w
|| !pfit_h
))
6091 pixel_rate
= div_u64((uint64_t) pixel_rate
* pipe_w
* pipe_h
,
6098 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state
*crtc_state
)
6100 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->base
.crtc
->dev
);
6102 if (HAS_GMCH_DISPLAY(dev_priv
))
6103 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6104 crtc_state
->pixel_rate
=
6105 crtc_state
->base
.adjusted_mode
.crtc_clock
;
6107 crtc_state
->pixel_rate
=
6108 ilk_pipe_pixel_rate(crtc_state
);
6111 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
6112 struct intel_crtc_state
*pipe_config
)
6114 struct drm_device
*dev
= crtc
->base
.dev
;
6115 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6116 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6117 int clock_limit
= dev_priv
->max_dotclk_freq
;
6119 if (INTEL_GEN(dev_priv
) < 4) {
6120 clock_limit
= dev_priv
->max_cdclk_freq
* 9 / 10;
6123 * Enable double wide mode when the dot clock
6124 * is > 90% of the (display) core speed.
6126 if (intel_crtc_supports_double_wide(crtc
) &&
6127 adjusted_mode
->crtc_clock
> clock_limit
) {
6128 clock_limit
= dev_priv
->max_dotclk_freq
;
6129 pipe_config
->double_wide
= true;
6133 if (adjusted_mode
->crtc_clock
> clock_limit
) {
6134 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6135 adjusted_mode
->crtc_clock
, clock_limit
,
6136 yesno(pipe_config
->double_wide
));
6141 * Pipe horizontal size must be even in:
6143 * - LVDS dual channel mode
6144 * - Double wide pipe
6146 if ((intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_LVDS
) &&
6147 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
6148 pipe_config
->pipe_src_w
&= ~1;
6150 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6151 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6153 if ((INTEL_GEN(dev_priv
) > 4 || IS_G4X(dev_priv
)) &&
6154 adjusted_mode
->crtc_hsync_start
== adjusted_mode
->crtc_hdisplay
)
6157 intel_crtc_compute_pixel_rate(pipe_config
);
6159 if (HAS_IPS(dev_priv
))
6160 hsw_compute_ips_config(crtc
, pipe_config
);
6162 if (pipe_config
->has_pch_encoder
)
6163 return ironlake_fdi_compute_config(crtc
, pipe_config
);
6169 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
6171 while (*num
> DATA_LINK_M_N_MASK
||
6172 *den
> DATA_LINK_M_N_MASK
) {
6178 static void compute_m_n(unsigned int m
, unsigned int n
,
6179 uint32_t *ret_m
, uint32_t *ret_n
,
6183 * Reduce M/N as much as possible without loss in precision. Several DP
6184 * dongles in particular seem to be fussy about too large *link* M/N
6185 * values. The passed in values are more likely to have the least
6186 * significant bits zero than M after rounding below, so do this first.
6189 while ((m
& 1) == 0 && (n
& 1) == 0) {
6195 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
6196 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
6197 intel_reduce_m_n_ratio(ret_m
, ret_n
);
6201 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
6202 int pixel_clock
, int link_clock
,
6203 struct intel_link_m_n
*m_n
,
6208 compute_m_n(bits_per_pixel
* pixel_clock
,
6209 link_clock
* nlanes
* 8,
6210 &m_n
->gmch_m
, &m_n
->gmch_n
,
6213 compute_m_n(pixel_clock
, link_clock
,
6214 &m_n
->link_m
, &m_n
->link_n
,
6218 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
6220 if (i915
.panel_use_ssc
>= 0)
6221 return i915
.panel_use_ssc
!= 0;
6222 return dev_priv
->vbt
.lvds_use_ssc
6223 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
6226 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
6228 return (1 << dpll
->n
) << 16 | dpll
->m2
;
6231 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
6233 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
6236 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
6237 struct intel_crtc_state
*crtc_state
,
6238 struct dpll
*reduced_clock
)
6240 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6243 if (IS_PINEVIEW(dev_priv
)) {
6244 fp
= pnv_dpll_compute_fp(&crtc_state
->dpll
);
6246 fp2
= pnv_dpll_compute_fp(reduced_clock
);
6248 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
6250 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
6253 crtc_state
->dpll_hw_state
.fp0
= fp
;
6255 crtc
->lowfreq_avail
= false;
6256 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6258 crtc_state
->dpll_hw_state
.fp1
= fp2
;
6259 crtc
->lowfreq_avail
= true;
6261 crtc_state
->dpll_hw_state
.fp1
= fp
;
6265 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
6271 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6272 * and set it to a reasonable value instead.
6274 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6275 reg_val
&= 0xffffff00;
6276 reg_val
|= 0x00000030;
6277 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6279 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6280 reg_val
&= 0x00ffffff;
6281 reg_val
|= 0x8c000000;
6282 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6284 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6285 reg_val
&= 0xffffff00;
6286 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6288 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6289 reg_val
&= 0x00ffffff;
6290 reg_val
|= 0xb0000000;
6291 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6294 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
6295 struct intel_link_m_n
*m_n
)
6297 struct drm_device
*dev
= crtc
->base
.dev
;
6298 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6299 int pipe
= crtc
->pipe
;
6301 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6302 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
6303 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
6304 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
6307 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
6308 struct intel_link_m_n
*m_n
,
6309 struct intel_link_m_n
*m2_n2
)
6311 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6312 int pipe
= crtc
->pipe
;
6313 enum transcoder transcoder
= crtc
->config
->cpu_transcoder
;
6315 if (INTEL_GEN(dev_priv
) >= 5) {
6316 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6317 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
6318 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
6319 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
6320 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
6321 * for gen < 8) and if DRRS is supported (to make sure the
6322 * registers are not unnecessarily accessed).
6324 if (m2_n2
&& (IS_CHERRYVIEW(dev_priv
) ||
6325 INTEL_GEN(dev_priv
) < 8) && crtc
->config
->has_drrs
) {
6326 I915_WRITE(PIPE_DATA_M2(transcoder
),
6327 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
6328 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
6329 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
6330 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
6333 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6334 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
6335 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
6336 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
6340 void intel_dp_set_m_n(struct intel_crtc
*crtc
, enum link_m_n_set m_n
)
6342 struct intel_link_m_n
*dp_m_n
, *dp_m2_n2
= NULL
;
6345 dp_m_n
= &crtc
->config
->dp_m_n
;
6346 dp_m2_n2
= &crtc
->config
->dp_m2_n2
;
6347 } else if (m_n
== M2_N2
) {
6350 * M2_N2 registers are not supported. Hence m2_n2 divider value
6351 * needs to be programmed into M1_N1.
6353 dp_m_n
= &crtc
->config
->dp_m2_n2
;
6355 DRM_ERROR("Unsupported divider value\n");
6359 if (crtc
->config
->has_pch_encoder
)
6360 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
->dp_m_n
);
6362 intel_cpu_transcoder_set_m_n(crtc
, dp_m_n
, dp_m2_n2
);
6365 static void vlv_compute_dpll(struct intel_crtc
*crtc
,
6366 struct intel_crtc_state
*pipe_config
)
6368 pipe_config
->dpll_hw_state
.dpll
= DPLL_INTEGRATED_REF_CLK_VLV
|
6369 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
6370 if (crtc
->pipe
!= PIPE_A
)
6371 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
6373 /* DPLL not used with DSI, but still need the rest set up */
6374 if (!intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_DSI
))
6375 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
|
6376 DPLL_EXT_BUFFER_ENABLE_VLV
;
6378 pipe_config
->dpll_hw_state
.dpll_md
=
6379 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6382 static void chv_compute_dpll(struct intel_crtc
*crtc
,
6383 struct intel_crtc_state
*pipe_config
)
6385 pipe_config
->dpll_hw_state
.dpll
= DPLL_SSC_REF_CLK_CHV
|
6386 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
6387 if (crtc
->pipe
!= PIPE_A
)
6388 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
6390 /* DPLL not used with DSI, but still need the rest set up */
6391 if (!intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_DSI
))
6392 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
;
6394 pipe_config
->dpll_hw_state
.dpll_md
=
6395 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6398 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
6399 const struct intel_crtc_state
*pipe_config
)
6401 struct drm_device
*dev
= crtc
->base
.dev
;
6402 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6403 enum pipe pipe
= crtc
->pipe
;
6405 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
6406 u32 coreclk
, reg_val
;
6409 I915_WRITE(DPLL(pipe
),
6410 pipe_config
->dpll_hw_state
.dpll
&
6411 ~(DPLL_VCO_ENABLE
| DPLL_EXT_BUFFER_ENABLE_VLV
));
6413 /* No need to actually set up the DPLL with DSI */
6414 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
6417 mutex_lock(&dev_priv
->sb_lock
);
6419 bestn
= pipe_config
->dpll
.n
;
6420 bestm1
= pipe_config
->dpll
.m1
;
6421 bestm2
= pipe_config
->dpll
.m2
;
6422 bestp1
= pipe_config
->dpll
.p1
;
6423 bestp2
= pipe_config
->dpll
.p2
;
6425 /* See eDP HDMI DPIO driver vbios notes doc */
6427 /* PLL B needs special handling */
6429 vlv_pllb_recal_opamp(dev_priv
, pipe
);
6431 /* Set up Tx target for periodic Rcomp update */
6432 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
6434 /* Disable target IRef on PLL */
6435 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
6436 reg_val
&= 0x00ffffff;
6437 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
6439 /* Disable fast lock */
6440 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
6442 /* Set idtafcrecal before PLL is enabled */
6443 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
6444 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
6445 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
6446 mdiv
|= (1 << DPIO_K_SHIFT
);
6449 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6450 * but we don't support that).
6451 * Note: don't use the DAC post divider as it seems unstable.
6453 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
6454 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
6456 mdiv
|= DPIO_ENABLE_CALIBRATION
;
6457 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
6459 /* Set HBR and RBR LPF coefficients */
6460 if (pipe_config
->port_clock
== 162000 ||
6461 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_ANALOG
) ||
6462 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_HDMI
))
6463 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
6466 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
6469 if (intel_crtc_has_dp_encoder(pipe_config
)) {
6470 /* Use SSC source */
6472 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6475 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6477 } else { /* HDMI or VGA */
6478 /* Use bend source */
6480 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6483 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6487 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
6488 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
6489 if (intel_crtc_has_dp_encoder(crtc
->config
))
6490 coreclk
|= 0x01000000;
6491 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
6493 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
6494 mutex_unlock(&dev_priv
->sb_lock
);
6497 static void chv_prepare_pll(struct intel_crtc
*crtc
,
6498 const struct intel_crtc_state
*pipe_config
)
6500 struct drm_device
*dev
= crtc
->base
.dev
;
6501 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6502 enum pipe pipe
= crtc
->pipe
;
6503 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
6504 u32 loopfilter
, tribuf_calcntr
;
6505 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
6509 /* Enable Refclk and SSC */
6510 I915_WRITE(DPLL(pipe
),
6511 pipe_config
->dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
6513 /* No need to actually set up the DPLL with DSI */
6514 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
6517 bestn
= pipe_config
->dpll
.n
;
6518 bestm2_frac
= pipe_config
->dpll
.m2
& 0x3fffff;
6519 bestm1
= pipe_config
->dpll
.m1
;
6520 bestm2
= pipe_config
->dpll
.m2
>> 22;
6521 bestp1
= pipe_config
->dpll
.p1
;
6522 bestp2
= pipe_config
->dpll
.p2
;
6523 vco
= pipe_config
->dpll
.vco
;
6527 mutex_lock(&dev_priv
->sb_lock
);
6529 /* p1 and p2 divider */
6530 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
6531 5 << DPIO_CHV_S1_DIV_SHIFT
|
6532 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
6533 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
6534 1 << DPIO_CHV_K_DIV_SHIFT
);
6536 /* Feedback post-divider - m2 */
6537 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
6539 /* Feedback refclk divider - n and m1 */
6540 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
6541 DPIO_CHV_M1_DIV_BY_2
|
6542 1 << DPIO_CHV_N_DIV_SHIFT
);
6544 /* M2 fraction division */
6545 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
6547 /* M2 fraction division enable */
6548 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
6549 dpio_val
&= ~(DPIO_CHV_FEEDFWD_GAIN_MASK
| DPIO_CHV_FRAC_DIV_EN
);
6550 dpio_val
|= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
);
6552 dpio_val
|= DPIO_CHV_FRAC_DIV_EN
;
6553 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
), dpio_val
);
6555 /* Program digital lock detect threshold */
6556 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW9(port
));
6557 dpio_val
&= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK
|
6558 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
);
6559 dpio_val
|= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT
);
6561 dpio_val
|= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
;
6562 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW9(port
), dpio_val
);
6565 if (vco
== 5400000) {
6566 loopfilter
|= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT
);
6567 loopfilter
|= (0x8 << DPIO_CHV_INT_COEFF_SHIFT
);
6568 loopfilter
|= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6569 tribuf_calcntr
= 0x9;
6570 } else if (vco
<= 6200000) {
6571 loopfilter
|= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT
);
6572 loopfilter
|= (0xB << DPIO_CHV_INT_COEFF_SHIFT
);
6573 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6574 tribuf_calcntr
= 0x9;
6575 } else if (vco
<= 6480000) {
6576 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
6577 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
6578 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6579 tribuf_calcntr
= 0x8;
6581 /* Not supported. Apply the same limits as in the max case */
6582 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
6583 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
6584 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6587 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
6589 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW8(port
));
6590 dpio_val
&= ~DPIO_CHV_TDC_TARGET_CNT_MASK
;
6591 dpio_val
|= (tribuf_calcntr
<< DPIO_CHV_TDC_TARGET_CNT_SHIFT
);
6592 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW8(port
), dpio_val
);
6595 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
6596 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
6599 mutex_unlock(&dev_priv
->sb_lock
);
6603 * vlv_force_pll_on - forcibly enable just the PLL
6604 * @dev_priv: i915 private structure
6605 * @pipe: pipe PLL to enable
6606 * @dpll: PLL configuration
6608 * Enable the PLL for @pipe using the supplied @dpll config. To be used
6609 * in cases where we need the PLL enabled even when @pipe is not going to
6612 int vlv_force_pll_on(struct drm_i915_private
*dev_priv
, enum pipe pipe
,
6613 const struct dpll
*dpll
)
6615 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
6616 struct intel_crtc_state
*pipe_config
;
6618 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
6622 pipe_config
->base
.crtc
= &crtc
->base
;
6623 pipe_config
->pixel_multiplier
= 1;
6624 pipe_config
->dpll
= *dpll
;
6626 if (IS_CHERRYVIEW(dev_priv
)) {
6627 chv_compute_dpll(crtc
, pipe_config
);
6628 chv_prepare_pll(crtc
, pipe_config
);
6629 chv_enable_pll(crtc
, pipe_config
);
6631 vlv_compute_dpll(crtc
, pipe_config
);
6632 vlv_prepare_pll(crtc
, pipe_config
);
6633 vlv_enable_pll(crtc
, pipe_config
);
6642 * vlv_force_pll_off - forcibly disable just the PLL
6643 * @dev_priv: i915 private structure
6644 * @pipe: pipe PLL to disable
6646 * Disable the PLL for @pipe. To be used in cases where we need
6647 * the PLL enabled even when @pipe is not going to be enabled.
6649 void vlv_force_pll_off(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
6651 if (IS_CHERRYVIEW(dev_priv
))
6652 chv_disable_pll(dev_priv
, pipe
);
6654 vlv_disable_pll(dev_priv
, pipe
);
6657 static void i9xx_compute_dpll(struct intel_crtc
*crtc
,
6658 struct intel_crtc_state
*crtc_state
,
6659 struct dpll
*reduced_clock
)
6661 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6663 struct dpll
*clock
= &crtc_state
->dpll
;
6665 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
6667 dpll
= DPLL_VGA_MODE_DIS
;
6669 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
))
6670 dpll
|= DPLLB_MODE_LVDS
;
6672 dpll
|= DPLLB_MODE_DAC_SERIAL
;
6674 if (IS_I945G(dev_priv
) || IS_I945GM(dev_priv
) ||
6675 IS_G33(dev_priv
) || IS_PINEVIEW(dev_priv
)) {
6676 dpll
|= (crtc_state
->pixel_multiplier
- 1)
6677 << SDVO_MULTIPLIER_SHIFT_HIRES
;
6680 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
6681 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
6682 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6684 if (intel_crtc_has_dp_encoder(crtc_state
))
6685 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6687 /* compute bitmask from p1 value */
6688 if (IS_PINEVIEW(dev_priv
))
6689 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
6691 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6692 if (IS_G4X(dev_priv
) && reduced_clock
)
6693 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
6695 switch (clock
->p2
) {
6697 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
6700 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
6703 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
6706 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
6709 if (INTEL_GEN(dev_priv
) >= 4)
6710 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
6712 if (crtc_state
->sdvo_tv_clock
)
6713 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
6714 else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6715 intel_panel_use_ssc(dev_priv
))
6716 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
6718 dpll
|= PLL_REF_INPUT_DREFCLK
;
6720 dpll
|= DPLL_VCO_ENABLE
;
6721 crtc_state
->dpll_hw_state
.dpll
= dpll
;
6723 if (INTEL_GEN(dev_priv
) >= 4) {
6724 u32 dpll_md
= (crtc_state
->pixel_multiplier
- 1)
6725 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6726 crtc_state
->dpll_hw_state
.dpll_md
= dpll_md
;
6730 static void i8xx_compute_dpll(struct intel_crtc
*crtc
,
6731 struct intel_crtc_state
*crtc_state
,
6732 struct dpll
*reduced_clock
)
6734 struct drm_device
*dev
= crtc
->base
.dev
;
6735 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6737 struct dpll
*clock
= &crtc_state
->dpll
;
6739 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
6741 dpll
= DPLL_VGA_MODE_DIS
;
6743 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
6744 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6747 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
6749 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6751 dpll
|= PLL_P2_DIVIDE_BY_4
;
6754 if (!IS_I830(dev_priv
) &&
6755 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DVO
))
6756 dpll
|= DPLL_DVO_2X_MODE
;
6758 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6759 intel_panel_use_ssc(dev_priv
))
6760 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
6762 dpll
|= PLL_REF_INPUT_DREFCLK
;
6764 dpll
|= DPLL_VCO_ENABLE
;
6765 crtc_state
->dpll_hw_state
.dpll
= dpll
;
6768 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
6770 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
6771 enum pipe pipe
= intel_crtc
->pipe
;
6772 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
6773 const struct drm_display_mode
*adjusted_mode
= &intel_crtc
->config
->base
.adjusted_mode
;
6774 uint32_t crtc_vtotal
, crtc_vblank_end
;
6777 /* We need to be careful not to changed the adjusted mode, for otherwise
6778 * the hw state checker will get angry at the mismatch. */
6779 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
6780 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
6782 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
6783 /* the chip adds 2 halflines automatically */
6785 crtc_vblank_end
-= 1;
6787 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
6788 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
6790 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
6791 adjusted_mode
->crtc_htotal
/ 2;
6793 vsyncshift
+= adjusted_mode
->crtc_htotal
;
6796 if (INTEL_GEN(dev_priv
) > 3)
6797 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
6799 I915_WRITE(HTOTAL(cpu_transcoder
),
6800 (adjusted_mode
->crtc_hdisplay
- 1) |
6801 ((adjusted_mode
->crtc_htotal
- 1) << 16));
6802 I915_WRITE(HBLANK(cpu_transcoder
),
6803 (adjusted_mode
->crtc_hblank_start
- 1) |
6804 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
6805 I915_WRITE(HSYNC(cpu_transcoder
),
6806 (adjusted_mode
->crtc_hsync_start
- 1) |
6807 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
6809 I915_WRITE(VTOTAL(cpu_transcoder
),
6810 (adjusted_mode
->crtc_vdisplay
- 1) |
6811 ((crtc_vtotal
- 1) << 16));
6812 I915_WRITE(VBLANK(cpu_transcoder
),
6813 (adjusted_mode
->crtc_vblank_start
- 1) |
6814 ((crtc_vblank_end
- 1) << 16));
6815 I915_WRITE(VSYNC(cpu_transcoder
),
6816 (adjusted_mode
->crtc_vsync_start
- 1) |
6817 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
6819 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
6820 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
6821 * documented on the DDI_FUNC_CTL register description, EDP Input Select
6823 if (IS_HASWELL(dev_priv
) && cpu_transcoder
== TRANSCODER_EDP
&&
6824 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
6825 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
6829 static void intel_set_pipe_src_size(struct intel_crtc
*intel_crtc
)
6831 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6832 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6833 enum pipe pipe
= intel_crtc
->pipe
;
6835 /* pipesrc controls the size that is scaled from, which should
6836 * always be the user's requested size.
6838 I915_WRITE(PIPESRC(pipe
),
6839 ((intel_crtc
->config
->pipe_src_w
- 1) << 16) |
6840 (intel_crtc
->config
->pipe_src_h
- 1));
6843 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
6844 struct intel_crtc_state
*pipe_config
)
6846 struct drm_device
*dev
= crtc
->base
.dev
;
6847 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6848 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
6851 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
6852 pipe_config
->base
.adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
6853 pipe_config
->base
.adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
6854 tmp
= I915_READ(HBLANK(cpu_transcoder
));
6855 pipe_config
->base
.adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
6856 pipe_config
->base
.adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
6857 tmp
= I915_READ(HSYNC(cpu_transcoder
));
6858 pipe_config
->base
.adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
6859 pipe_config
->base
.adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
6861 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
6862 pipe_config
->base
.adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
6863 pipe_config
->base
.adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
6864 tmp
= I915_READ(VBLANK(cpu_transcoder
));
6865 pipe_config
->base
.adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
6866 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
6867 tmp
= I915_READ(VSYNC(cpu_transcoder
));
6868 pipe_config
->base
.adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
6869 pipe_config
->base
.adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
6871 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
6872 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
6873 pipe_config
->base
.adjusted_mode
.crtc_vtotal
+= 1;
6874 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
+= 1;
6878 static void intel_get_pipe_src_size(struct intel_crtc
*crtc
,
6879 struct intel_crtc_state
*pipe_config
)
6881 struct drm_device
*dev
= crtc
->base
.dev
;
6882 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6885 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
6886 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
6887 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
6889 pipe_config
->base
.mode
.vdisplay
= pipe_config
->pipe_src_h
;
6890 pipe_config
->base
.mode
.hdisplay
= pipe_config
->pipe_src_w
;
6893 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
6894 struct intel_crtc_state
*pipe_config
)
6896 mode
->hdisplay
= pipe_config
->base
.adjusted_mode
.crtc_hdisplay
;
6897 mode
->htotal
= pipe_config
->base
.adjusted_mode
.crtc_htotal
;
6898 mode
->hsync_start
= pipe_config
->base
.adjusted_mode
.crtc_hsync_start
;
6899 mode
->hsync_end
= pipe_config
->base
.adjusted_mode
.crtc_hsync_end
;
6901 mode
->vdisplay
= pipe_config
->base
.adjusted_mode
.crtc_vdisplay
;
6902 mode
->vtotal
= pipe_config
->base
.adjusted_mode
.crtc_vtotal
;
6903 mode
->vsync_start
= pipe_config
->base
.adjusted_mode
.crtc_vsync_start
;
6904 mode
->vsync_end
= pipe_config
->base
.adjusted_mode
.crtc_vsync_end
;
6906 mode
->flags
= pipe_config
->base
.adjusted_mode
.flags
;
6907 mode
->type
= DRM_MODE_TYPE_DRIVER
;
6909 mode
->clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
6911 mode
->hsync
= drm_mode_hsync(mode
);
6912 mode
->vrefresh
= drm_mode_vrefresh(mode
);
6913 drm_mode_set_name(mode
);
6916 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
6918 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
6923 /* we keep both pipes enabled on 830 */
6924 if (IS_I830(dev_priv
))
6925 pipeconf
|= I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
;
6927 if (intel_crtc
->config
->double_wide
)
6928 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
6930 /* only g4x and later have fancy bpc/dither controls */
6931 if (IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
6932 IS_CHERRYVIEW(dev_priv
)) {
6933 /* Bspec claims that we can't use dithering for 30bpp pipes. */
6934 if (intel_crtc
->config
->dither
&& intel_crtc
->config
->pipe_bpp
!= 30)
6935 pipeconf
|= PIPECONF_DITHER_EN
|
6936 PIPECONF_DITHER_TYPE_SP
;
6938 switch (intel_crtc
->config
->pipe_bpp
) {
6940 pipeconf
|= PIPECONF_6BPC
;
6943 pipeconf
|= PIPECONF_8BPC
;
6946 pipeconf
|= PIPECONF_10BPC
;
6949 /* Case prevented by intel_choose_pipe_bpp_dither. */
6954 if (HAS_PIPE_CXSR(dev_priv
)) {
6955 if (intel_crtc
->lowfreq_avail
) {
6956 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
6957 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
6959 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
6963 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
6964 if (INTEL_GEN(dev_priv
) < 4 ||
6965 intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
6966 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
6968 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
6970 pipeconf
|= PIPECONF_PROGRESSIVE
;
6972 if ((IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) &&
6973 intel_crtc
->config
->limited_color_range
)
6974 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
6976 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
6977 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
6980 static int i8xx_crtc_compute_clock(struct intel_crtc
*crtc
,
6981 struct intel_crtc_state
*crtc_state
)
6983 struct drm_device
*dev
= crtc
->base
.dev
;
6984 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6985 const struct intel_limit
*limit
;
6988 memset(&crtc_state
->dpll_hw_state
, 0,
6989 sizeof(crtc_state
->dpll_hw_state
));
6991 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
6992 if (intel_panel_use_ssc(dev_priv
)) {
6993 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
6994 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
6997 limit
= &intel_limits_i8xx_lvds
;
6998 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DVO
)) {
6999 limit
= &intel_limits_i8xx_dvo
;
7001 limit
= &intel_limits_i8xx_dac
;
7004 if (!crtc_state
->clock_set
&&
7005 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7006 refclk
, NULL
, &crtc_state
->dpll
)) {
7007 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7011 i8xx_compute_dpll(crtc
, crtc_state
, NULL
);
7016 static int g4x_crtc_compute_clock(struct intel_crtc
*crtc
,
7017 struct intel_crtc_state
*crtc_state
)
7019 struct drm_device
*dev
= crtc
->base
.dev
;
7020 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7021 const struct intel_limit
*limit
;
7024 memset(&crtc_state
->dpll_hw_state
, 0,
7025 sizeof(crtc_state
->dpll_hw_state
));
7027 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7028 if (intel_panel_use_ssc(dev_priv
)) {
7029 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7030 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7033 if (intel_is_dual_link_lvds(dev
))
7034 limit
= &intel_limits_g4x_dual_channel_lvds
;
7036 limit
= &intel_limits_g4x_single_channel_lvds
;
7037 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
) ||
7038 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
)) {
7039 limit
= &intel_limits_g4x_hdmi
;
7040 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
)) {
7041 limit
= &intel_limits_g4x_sdvo
;
7043 /* The option is for other outputs */
7044 limit
= &intel_limits_i9xx_sdvo
;
7047 if (!crtc_state
->clock_set
&&
7048 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7049 refclk
, NULL
, &crtc_state
->dpll
)) {
7050 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7054 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7059 static int pnv_crtc_compute_clock(struct intel_crtc
*crtc
,
7060 struct intel_crtc_state
*crtc_state
)
7062 struct drm_device
*dev
= crtc
->base
.dev
;
7063 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7064 const struct intel_limit
*limit
;
7067 memset(&crtc_state
->dpll_hw_state
, 0,
7068 sizeof(crtc_state
->dpll_hw_state
));
7070 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7071 if (intel_panel_use_ssc(dev_priv
)) {
7072 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7073 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7076 limit
= &intel_limits_pineview_lvds
;
7078 limit
= &intel_limits_pineview_sdvo
;
7081 if (!crtc_state
->clock_set
&&
7082 !pnv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7083 refclk
, NULL
, &crtc_state
->dpll
)) {
7084 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7088 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7093 static int i9xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7094 struct intel_crtc_state
*crtc_state
)
7096 struct drm_device
*dev
= crtc
->base
.dev
;
7097 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7098 const struct intel_limit
*limit
;
7101 memset(&crtc_state
->dpll_hw_state
, 0,
7102 sizeof(crtc_state
->dpll_hw_state
));
7104 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7105 if (intel_panel_use_ssc(dev_priv
)) {
7106 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7107 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7110 limit
= &intel_limits_i9xx_lvds
;
7112 limit
= &intel_limits_i9xx_sdvo
;
7115 if (!crtc_state
->clock_set
&&
7116 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7117 refclk
, NULL
, &crtc_state
->dpll
)) {
7118 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7122 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7127 static int chv_crtc_compute_clock(struct intel_crtc
*crtc
,
7128 struct intel_crtc_state
*crtc_state
)
7130 int refclk
= 100000;
7131 const struct intel_limit
*limit
= &intel_limits_chv
;
7133 memset(&crtc_state
->dpll_hw_state
, 0,
7134 sizeof(crtc_state
->dpll_hw_state
));
7136 if (!crtc_state
->clock_set
&&
7137 !chv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7138 refclk
, NULL
, &crtc_state
->dpll
)) {
7139 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7143 chv_compute_dpll(crtc
, crtc_state
);
7148 static int vlv_crtc_compute_clock(struct intel_crtc
*crtc
,
7149 struct intel_crtc_state
*crtc_state
)
7151 int refclk
= 100000;
7152 const struct intel_limit
*limit
= &intel_limits_vlv
;
7154 memset(&crtc_state
->dpll_hw_state
, 0,
7155 sizeof(crtc_state
->dpll_hw_state
));
7157 if (!crtc_state
->clock_set
&&
7158 !vlv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7159 refclk
, NULL
, &crtc_state
->dpll
)) {
7160 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7164 vlv_compute_dpll(crtc
, crtc_state
);
7169 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
7170 struct intel_crtc_state
*pipe_config
)
7172 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7175 if (INTEL_GEN(dev_priv
) <= 3 &&
7176 (IS_I830(dev_priv
) || !IS_MOBILE(dev_priv
)))
7179 tmp
= I915_READ(PFIT_CONTROL
);
7180 if (!(tmp
& PFIT_ENABLE
))
7183 /* Check whether the pfit is attached to our pipe. */
7184 if (INTEL_GEN(dev_priv
) < 4) {
7185 if (crtc
->pipe
!= PIPE_B
)
7188 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
7192 pipe_config
->gmch_pfit
.control
= tmp
;
7193 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
7196 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
7197 struct intel_crtc_state
*pipe_config
)
7199 struct drm_device
*dev
= crtc
->base
.dev
;
7200 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7201 int pipe
= pipe_config
->cpu_transcoder
;
7204 int refclk
= 100000;
7206 /* In case of DSI, DPLL will not be used */
7207 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7210 mutex_lock(&dev_priv
->sb_lock
);
7211 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
7212 mutex_unlock(&dev_priv
->sb_lock
);
7214 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
7215 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
7216 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
7217 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
7218 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
7220 pipe_config
->port_clock
= vlv_calc_dpll_params(refclk
, &clock
);
7224 i9xx_get_initial_plane_config(struct intel_crtc
*crtc
,
7225 struct intel_initial_plane_config
*plane_config
)
7227 struct drm_device
*dev
= crtc
->base
.dev
;
7228 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7229 u32 val
, base
, offset
;
7230 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
7231 int fourcc
, pixel_format
;
7232 unsigned int aligned_height
;
7233 struct drm_framebuffer
*fb
;
7234 struct intel_framebuffer
*intel_fb
;
7236 val
= I915_READ(DSPCNTR(plane
));
7237 if (!(val
& DISPLAY_PLANE_ENABLE
))
7240 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
7242 DRM_DEBUG_KMS("failed to alloc fb\n");
7246 fb
= &intel_fb
->base
;
7250 if (INTEL_GEN(dev_priv
) >= 4) {
7251 if (val
& DISPPLANE_TILED
) {
7252 plane_config
->tiling
= I915_TILING_X
;
7253 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
7257 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
7258 fourcc
= i9xx_format_to_fourcc(pixel_format
);
7259 fb
->format
= drm_format_info(fourcc
);
7261 if (INTEL_GEN(dev_priv
) >= 4) {
7262 if (plane_config
->tiling
)
7263 offset
= I915_READ(DSPTILEOFF(plane
));
7265 offset
= I915_READ(DSPLINOFF(plane
));
7266 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
7268 base
= I915_READ(DSPADDR(plane
));
7270 plane_config
->base
= base
;
7272 val
= I915_READ(PIPESRC(pipe
));
7273 fb
->width
= ((val
>> 16) & 0xfff) + 1;
7274 fb
->height
= ((val
>> 0) & 0xfff) + 1;
7276 val
= I915_READ(DSPSTRIDE(pipe
));
7277 fb
->pitches
[0] = val
& 0xffffffc0;
7279 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
7281 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
7283 DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7284 pipe_name(pipe
), plane
, fb
->width
, fb
->height
,
7285 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
7286 plane_config
->size
);
7288 plane_config
->fb
= intel_fb
;
7291 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
7292 struct intel_crtc_state
*pipe_config
)
7294 struct drm_device
*dev
= crtc
->base
.dev
;
7295 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7296 int pipe
= pipe_config
->cpu_transcoder
;
7297 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
7299 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
, pll_dw3
;
7300 int refclk
= 100000;
7302 /* In case of DSI, DPLL will not be used */
7303 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7306 mutex_lock(&dev_priv
->sb_lock
);
7307 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
7308 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
7309 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
7310 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
7311 pll_dw3
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
7312 mutex_unlock(&dev_priv
->sb_lock
);
7314 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
7315 clock
.m2
= (pll_dw0
& 0xff) << 22;
7316 if (pll_dw3
& DPIO_CHV_FRAC_DIV_EN
)
7317 clock
.m2
|= pll_dw2
& 0x3fffff;
7318 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
7319 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
7320 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
7322 pipe_config
->port_clock
= chv_calc_dpll_params(refclk
, &clock
);
7325 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
7326 struct intel_crtc_state
*pipe_config
)
7328 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7329 enum intel_display_power_domain power_domain
;
7333 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
7334 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
7337 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7338 pipe_config
->shared_dpll
= NULL
;
7342 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
7343 if (!(tmp
& PIPECONF_ENABLE
))
7346 if (IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
7347 IS_CHERRYVIEW(dev_priv
)) {
7348 switch (tmp
& PIPECONF_BPC_MASK
) {
7350 pipe_config
->pipe_bpp
= 18;
7353 pipe_config
->pipe_bpp
= 24;
7355 case PIPECONF_10BPC
:
7356 pipe_config
->pipe_bpp
= 30;
7363 if ((IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) &&
7364 (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
7365 pipe_config
->limited_color_range
= true;
7367 if (INTEL_GEN(dev_priv
) < 4)
7368 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
7370 intel_get_pipe_timings(crtc
, pipe_config
);
7371 intel_get_pipe_src_size(crtc
, pipe_config
);
7373 i9xx_get_pfit_config(crtc
, pipe_config
);
7375 if (INTEL_GEN(dev_priv
) >= 4) {
7376 /* No way to read it out on pipes B and C */
7377 if (IS_CHERRYVIEW(dev_priv
) && crtc
->pipe
!= PIPE_A
)
7378 tmp
= dev_priv
->chv_dpll_md
[crtc
->pipe
];
7380 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
7381 pipe_config
->pixel_multiplier
=
7382 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
7383 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
7384 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
7385 } else if (IS_I945G(dev_priv
) || IS_I945GM(dev_priv
) ||
7386 IS_G33(dev_priv
) || IS_PINEVIEW(dev_priv
)) {
7387 tmp
= I915_READ(DPLL(crtc
->pipe
));
7388 pipe_config
->pixel_multiplier
=
7389 ((tmp
& SDVO_MULTIPLIER_MASK
)
7390 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
7392 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7393 * port and will be fixed up in the encoder->get_config
7395 pipe_config
->pixel_multiplier
= 1;
7397 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
7398 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
)) {
7400 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
7401 * on 830. Filter it out here so that we don't
7402 * report errors due to that.
7404 if (IS_I830(dev_priv
))
7405 pipe_config
->dpll_hw_state
.dpll
&= ~DPLL_DVO_2X_MODE
;
7407 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
7408 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
7410 /* Mask out read-only status bits. */
7411 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
7412 DPLL_PORTC_READY_MASK
|
7413 DPLL_PORTB_READY_MASK
);
7416 if (IS_CHERRYVIEW(dev_priv
))
7417 chv_crtc_clock_get(crtc
, pipe_config
);
7418 else if (IS_VALLEYVIEW(dev_priv
))
7419 vlv_crtc_clock_get(crtc
, pipe_config
);
7421 i9xx_crtc_clock_get(crtc
, pipe_config
);
7424 * Normally the dotclock is filled in by the encoder .get_config()
7425 * but in case the pipe is enabled w/o any ports we need a sane
7428 pipe_config
->base
.adjusted_mode
.crtc_clock
=
7429 pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
7434 intel_display_power_put(dev_priv
, power_domain
);
7439 static void ironlake_init_pch_refclk(struct drm_i915_private
*dev_priv
)
7441 struct intel_encoder
*encoder
;
7444 bool has_lvds
= false;
7445 bool has_cpu_edp
= false;
7446 bool has_panel
= false;
7447 bool has_ck505
= false;
7448 bool can_ssc
= false;
7449 bool using_ssc_source
= false;
7451 /* We need to take the global config into account */
7452 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
7453 switch (encoder
->type
) {
7454 case INTEL_OUTPUT_LVDS
:
7458 case INTEL_OUTPUT_EDP
:
7460 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
7468 if (HAS_PCH_IBX(dev_priv
)) {
7469 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
7470 can_ssc
= has_ck505
;
7476 /* Check if any DPLLs are using the SSC source */
7477 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
7478 u32 temp
= I915_READ(PCH_DPLL(i
));
7480 if (!(temp
& DPLL_VCO_ENABLE
))
7483 if ((temp
& PLL_REF_INPUT_MASK
) ==
7484 PLLB_REF_INPUT_SPREADSPECTRUMIN
) {
7485 using_ssc_source
= true;
7490 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
7491 has_panel
, has_lvds
, has_ck505
, using_ssc_source
);
7493 /* Ironlake: try to setup display ref clock before DPLL
7494 * enabling. This is only under driver's control after
7495 * PCH B stepping, previous chipset stepping should be
7496 * ignoring this setting.
7498 val
= I915_READ(PCH_DREF_CONTROL
);
7500 /* As we must carefully and slowly disable/enable each source in turn,
7501 * compute the final state we want first and check if we need to
7502 * make any changes at all.
7505 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
7507 final
|= DREF_NONSPREAD_CK505_ENABLE
;
7509 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
7511 final
&= ~DREF_SSC_SOURCE_MASK
;
7512 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7513 final
&= ~DREF_SSC1_ENABLE
;
7516 final
|= DREF_SSC_SOURCE_ENABLE
;
7518 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
7519 final
|= DREF_SSC1_ENABLE
;
7522 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
7523 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
7525 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
7527 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7528 } else if (using_ssc_source
) {
7529 final
|= DREF_SSC_SOURCE_ENABLE
;
7530 final
|= DREF_SSC1_ENABLE
;
7536 /* Always enable nonspread source */
7537 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
7540 val
|= DREF_NONSPREAD_CK505_ENABLE
;
7542 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
7545 val
&= ~DREF_SSC_SOURCE_MASK
;
7546 val
|= DREF_SSC_SOURCE_ENABLE
;
7548 /* SSC must be turned on before enabling the CPU output */
7549 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
7550 DRM_DEBUG_KMS("Using SSC on panel\n");
7551 val
|= DREF_SSC1_ENABLE
;
7553 val
&= ~DREF_SSC1_ENABLE
;
7555 /* Get SSC going before enabling the outputs */
7556 I915_WRITE(PCH_DREF_CONTROL
, val
);
7557 POSTING_READ(PCH_DREF_CONTROL
);
7560 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7562 /* Enable CPU source on CPU attached eDP */
7564 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
7565 DRM_DEBUG_KMS("Using SSC on eDP\n");
7566 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
7568 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
7570 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7572 I915_WRITE(PCH_DREF_CONTROL
, val
);
7573 POSTING_READ(PCH_DREF_CONTROL
);
7576 DRM_DEBUG_KMS("Disabling CPU source output\n");
7578 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7580 /* Turn off CPU output */
7581 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7583 I915_WRITE(PCH_DREF_CONTROL
, val
);
7584 POSTING_READ(PCH_DREF_CONTROL
);
7587 if (!using_ssc_source
) {
7588 DRM_DEBUG_KMS("Disabling SSC source\n");
7590 /* Turn off the SSC source */
7591 val
&= ~DREF_SSC_SOURCE_MASK
;
7592 val
|= DREF_SSC_SOURCE_DISABLE
;
7595 val
&= ~DREF_SSC1_ENABLE
;
7597 I915_WRITE(PCH_DREF_CONTROL
, val
);
7598 POSTING_READ(PCH_DREF_CONTROL
);
7603 BUG_ON(val
!= final
);
7606 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
7610 tmp
= I915_READ(SOUTH_CHICKEN2
);
7611 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
7612 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
7614 if (wait_for_us(I915_READ(SOUTH_CHICKEN2
) &
7615 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
7616 DRM_ERROR("FDI mPHY reset assert timeout\n");
7618 tmp
= I915_READ(SOUTH_CHICKEN2
);
7619 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
7620 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
7622 if (wait_for_us((I915_READ(SOUTH_CHICKEN2
) &
7623 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
7624 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
7627 /* WaMPhyProgramming:hsw */
7628 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
7632 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
7633 tmp
&= ~(0xFF << 24);
7634 tmp
|= (0x12 << 24);
7635 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
7637 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
7639 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
7641 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
7643 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
7645 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
7646 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
7647 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
7649 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
7650 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
7651 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
7653 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
7656 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
7658 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
7661 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
7663 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
7666 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
7668 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
7671 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
7673 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
7674 tmp
&= ~(0xFF << 16);
7675 tmp
|= (0x1C << 16);
7676 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
7678 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
7679 tmp
&= ~(0xFF << 16);
7680 tmp
|= (0x1C << 16);
7681 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
7683 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
7685 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
7687 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
7689 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
7691 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
7692 tmp
&= ~(0xF << 28);
7694 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
7696 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
7697 tmp
&= ~(0xF << 28);
7699 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
7702 /* Implements 3 different sequences from BSpec chapter "Display iCLK
7703 * Programming" based on the parameters passed:
7704 * - Sequence to enable CLKOUT_DP
7705 * - Sequence to enable CLKOUT_DP without spread
7706 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
7708 static void lpt_enable_clkout_dp(struct drm_i915_private
*dev_priv
,
7709 bool with_spread
, bool with_fdi
)
7713 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
7715 if (WARN(HAS_PCH_LPT_LP(dev_priv
) &&
7716 with_fdi
, "LP PCH doesn't have FDI\n"))
7719 mutex_lock(&dev_priv
->sb_lock
);
7721 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7722 tmp
&= ~SBI_SSCCTL_DISABLE
;
7723 tmp
|= SBI_SSCCTL_PATHALT
;
7724 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7729 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7730 tmp
&= ~SBI_SSCCTL_PATHALT
;
7731 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7734 lpt_reset_fdi_mphy(dev_priv
);
7735 lpt_program_fdi_mphy(dev_priv
);
7739 reg
= HAS_PCH_LPT_LP(dev_priv
) ? SBI_GEN0
: SBI_DBUFF0
;
7740 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
7741 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
7742 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
7744 mutex_unlock(&dev_priv
->sb_lock
);
7747 /* Sequence to disable CLKOUT_DP */
7748 static void lpt_disable_clkout_dp(struct drm_i915_private
*dev_priv
)
7752 mutex_lock(&dev_priv
->sb_lock
);
7754 reg
= HAS_PCH_LPT_LP(dev_priv
) ? SBI_GEN0
: SBI_DBUFF0
;
7755 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
7756 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
7757 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
7759 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7760 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
7761 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
7762 tmp
|= SBI_SSCCTL_PATHALT
;
7763 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7766 tmp
|= SBI_SSCCTL_DISABLE
;
7767 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7770 mutex_unlock(&dev_priv
->sb_lock
);
7773 #define BEND_IDX(steps) ((50 + (steps)) / 5)
7775 static const uint16_t sscdivintphase
[] = {
7776 [BEND_IDX( 50)] = 0x3B23,
7777 [BEND_IDX( 45)] = 0x3B23,
7778 [BEND_IDX( 40)] = 0x3C23,
7779 [BEND_IDX( 35)] = 0x3C23,
7780 [BEND_IDX( 30)] = 0x3D23,
7781 [BEND_IDX( 25)] = 0x3D23,
7782 [BEND_IDX( 20)] = 0x3E23,
7783 [BEND_IDX( 15)] = 0x3E23,
7784 [BEND_IDX( 10)] = 0x3F23,
7785 [BEND_IDX( 5)] = 0x3F23,
7786 [BEND_IDX( 0)] = 0x0025,
7787 [BEND_IDX( -5)] = 0x0025,
7788 [BEND_IDX(-10)] = 0x0125,
7789 [BEND_IDX(-15)] = 0x0125,
7790 [BEND_IDX(-20)] = 0x0225,
7791 [BEND_IDX(-25)] = 0x0225,
7792 [BEND_IDX(-30)] = 0x0325,
7793 [BEND_IDX(-35)] = 0x0325,
7794 [BEND_IDX(-40)] = 0x0425,
7795 [BEND_IDX(-45)] = 0x0425,
7796 [BEND_IDX(-50)] = 0x0525,
7801 * steps -50 to 50 inclusive, in steps of 5
7802 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
7803 * change in clock period = -(steps / 10) * 5.787 ps
7805 static void lpt_bend_clkout_dp(struct drm_i915_private
*dev_priv
, int steps
)
7808 int idx
= BEND_IDX(steps
);
7810 if (WARN_ON(steps
% 5 != 0))
7813 if (WARN_ON(idx
>= ARRAY_SIZE(sscdivintphase
)))
7816 mutex_lock(&dev_priv
->sb_lock
);
7818 if (steps
% 10 != 0)
7822 intel_sbi_write(dev_priv
, SBI_SSCDITHPHASE
, tmp
, SBI_ICLK
);
7824 tmp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE
, SBI_ICLK
);
7826 tmp
|= sscdivintphase
[idx
];
7827 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE
, tmp
, SBI_ICLK
);
7829 mutex_unlock(&dev_priv
->sb_lock
);
7834 static void lpt_init_pch_refclk(struct drm_i915_private
*dev_priv
)
7836 struct intel_encoder
*encoder
;
7837 bool has_vga
= false;
7839 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
7840 switch (encoder
->type
) {
7841 case INTEL_OUTPUT_ANALOG
:
7850 lpt_bend_clkout_dp(dev_priv
, 0);
7851 lpt_enable_clkout_dp(dev_priv
, true, true);
7853 lpt_disable_clkout_dp(dev_priv
);
7858 * Initialize reference clocks when the driver loads
7860 void intel_init_pch_refclk(struct drm_i915_private
*dev_priv
)
7862 if (HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
))
7863 ironlake_init_pch_refclk(dev_priv
);
7864 else if (HAS_PCH_LPT(dev_priv
))
7865 lpt_init_pch_refclk(dev_priv
);
7868 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
7870 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
7871 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7872 int pipe
= intel_crtc
->pipe
;
7877 switch (intel_crtc
->config
->pipe_bpp
) {
7879 val
|= PIPECONF_6BPC
;
7882 val
|= PIPECONF_8BPC
;
7885 val
|= PIPECONF_10BPC
;
7888 val
|= PIPECONF_12BPC
;
7891 /* Case prevented by intel_choose_pipe_bpp_dither. */
7895 if (intel_crtc
->config
->dither
)
7896 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
7898 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
7899 val
|= PIPECONF_INTERLACED_ILK
;
7901 val
|= PIPECONF_PROGRESSIVE
;
7903 if (intel_crtc
->config
->limited_color_range
)
7904 val
|= PIPECONF_COLOR_RANGE_SELECT
;
7906 I915_WRITE(PIPECONF(pipe
), val
);
7907 POSTING_READ(PIPECONF(pipe
));
7910 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
7912 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
7913 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7914 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
7917 if (IS_HASWELL(dev_priv
) && intel_crtc
->config
->dither
)
7918 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
7920 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
7921 val
|= PIPECONF_INTERLACED_ILK
;
7923 val
|= PIPECONF_PROGRESSIVE
;
7925 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
7926 POSTING_READ(PIPECONF(cpu_transcoder
));
7929 static void haswell_set_pipemisc(struct drm_crtc
*crtc
)
7931 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
7932 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7934 if (IS_BROADWELL(dev_priv
) || INTEL_INFO(dev_priv
)->gen
>= 9) {
7937 switch (intel_crtc
->config
->pipe_bpp
) {
7939 val
|= PIPEMISC_DITHER_6_BPC
;
7942 val
|= PIPEMISC_DITHER_8_BPC
;
7945 val
|= PIPEMISC_DITHER_10_BPC
;
7948 val
|= PIPEMISC_DITHER_12_BPC
;
7951 /* Case prevented by pipe_config_set_bpp. */
7955 if (intel_crtc
->config
->dither
)
7956 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
7958 I915_WRITE(PIPEMISC(intel_crtc
->pipe
), val
);
7962 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
7965 * Account for spread spectrum to avoid
7966 * oversubscribing the link. Max center spread
7967 * is 2.5%; use 5% for safety's sake.
7969 u32 bps
= target_clock
* bpp
* 21 / 20;
7970 return DIV_ROUND_UP(bps
, link_bw
* 8);
7973 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
7975 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
7978 static void ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
7979 struct intel_crtc_state
*crtc_state
,
7980 struct dpll
*reduced_clock
)
7982 struct drm_crtc
*crtc
= &intel_crtc
->base
;
7983 struct drm_device
*dev
= crtc
->dev
;
7984 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7988 /* Enable autotuning of the PLL clock (if permissible) */
7990 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7991 if ((intel_panel_use_ssc(dev_priv
) &&
7992 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
7993 (HAS_PCH_IBX(dev_priv
) && intel_is_dual_link_lvds(dev
)))
7995 } else if (crtc_state
->sdvo_tv_clock
)
7998 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
8000 if (ironlake_needs_fb_cb_tune(&crtc_state
->dpll
, factor
))
8003 if (reduced_clock
) {
8004 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
8006 if (reduced_clock
->m
< factor
* reduced_clock
->n
)
8014 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
))
8015 dpll
|= DPLLB_MODE_LVDS
;
8017 dpll
|= DPLLB_MODE_DAC_SERIAL
;
8019 dpll
|= (crtc_state
->pixel_multiplier
- 1)
8020 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
8022 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
8023 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
8024 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8026 if (intel_crtc_has_dp_encoder(crtc_state
))
8027 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8030 * The high speed IO clock is only really required for
8031 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8032 * possible to share the DPLL between CRT and HDMI. Enabling
8033 * the clock needlessly does no real harm, except use up a
8034 * bit of power potentially.
8036 * We'll limit this to IVB with 3 pipes, since it has only two
8037 * DPLLs and so DPLL sharing is the only way to get three pipes
8038 * driving PCH ports at the same time. On SNB we could do this,
8039 * and potentially avoid enabling the second DPLL, but it's not
8040 * clear if it''s a win or loss power wise. No point in doing
8041 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8043 if (INTEL_INFO(dev_priv
)->num_pipes
== 3 &&
8044 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
))
8045 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8047 /* compute bitmask from p1 value */
8048 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8050 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
8052 switch (crtc_state
->dpll
.p2
) {
8054 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
8057 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
8060 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
8063 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
8067 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
8068 intel_panel_use_ssc(dev_priv
))
8069 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
8071 dpll
|= PLL_REF_INPUT_DREFCLK
;
8073 dpll
|= DPLL_VCO_ENABLE
;
8075 crtc_state
->dpll_hw_state
.dpll
= dpll
;
8076 crtc_state
->dpll_hw_state
.fp0
= fp
;
8077 crtc_state
->dpll_hw_state
.fp1
= fp2
;
8080 static int ironlake_crtc_compute_clock(struct intel_crtc
*crtc
,
8081 struct intel_crtc_state
*crtc_state
)
8083 struct drm_device
*dev
= crtc
->base
.dev
;
8084 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8085 const struct intel_limit
*limit
;
8086 int refclk
= 120000;
8088 memset(&crtc_state
->dpll_hw_state
, 0,
8089 sizeof(crtc_state
->dpll_hw_state
));
8091 crtc
->lowfreq_avail
= false;
8093 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8094 if (!crtc_state
->has_pch_encoder
)
8097 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8098 if (intel_panel_use_ssc(dev_priv
)) {
8099 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8100 dev_priv
->vbt
.lvds_ssc_freq
);
8101 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8104 if (intel_is_dual_link_lvds(dev
)) {
8105 if (refclk
== 100000)
8106 limit
= &intel_limits_ironlake_dual_lvds_100m
;
8108 limit
= &intel_limits_ironlake_dual_lvds
;
8110 if (refclk
== 100000)
8111 limit
= &intel_limits_ironlake_single_lvds_100m
;
8113 limit
= &intel_limits_ironlake_single_lvds
;
8116 limit
= &intel_limits_ironlake_dac
;
8119 if (!crtc_state
->clock_set
&&
8120 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8121 refclk
, NULL
, &crtc_state
->dpll
)) {
8122 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8126 ironlake_compute_dpll(crtc
, crtc_state
, NULL
);
8128 if (!intel_get_shared_dpll(crtc
, crtc_state
, NULL
)) {
8129 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8130 pipe_name(crtc
->pipe
));
8137 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
8138 struct intel_link_m_n
*m_n
)
8140 struct drm_device
*dev
= crtc
->base
.dev
;
8141 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8142 enum pipe pipe
= crtc
->pipe
;
8144 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
8145 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
8146 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
8148 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
8149 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
8150 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8153 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
8154 enum transcoder transcoder
,
8155 struct intel_link_m_n
*m_n
,
8156 struct intel_link_m_n
*m2_n2
)
8158 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
8159 enum pipe pipe
= crtc
->pipe
;
8161 if (INTEL_GEN(dev_priv
) >= 5) {
8162 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
8163 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
8164 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
8166 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
8167 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
8168 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8169 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8170 * gen < 8) and if DRRS is supported (to make sure the
8171 * registers are not unnecessarily read).
8173 if (m2_n2
&& INTEL_GEN(dev_priv
) < 8 &&
8174 crtc
->config
->has_drrs
) {
8175 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
8176 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
8177 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
8179 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
8180 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
8181 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8184 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
8185 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
8186 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
8188 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
8189 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
8190 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8194 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
8195 struct intel_crtc_state
*pipe_config
)
8197 if (pipe_config
->has_pch_encoder
)
8198 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
8200 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8201 &pipe_config
->dp_m_n
,
8202 &pipe_config
->dp_m2_n2
);
8205 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
8206 struct intel_crtc_state
*pipe_config
)
8208 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8209 &pipe_config
->fdi_m_n
, NULL
);
8212 static void skylake_get_pfit_config(struct intel_crtc
*crtc
,
8213 struct intel_crtc_state
*pipe_config
)
8215 struct drm_device
*dev
= crtc
->base
.dev
;
8216 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8217 struct intel_crtc_scaler_state
*scaler_state
= &pipe_config
->scaler_state
;
8218 uint32_t ps_ctrl
= 0;
8222 /* find scaler attached to this pipe */
8223 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
8224 ps_ctrl
= I915_READ(SKL_PS_CTRL(crtc
->pipe
, i
));
8225 if (ps_ctrl
& PS_SCALER_EN
&& !(ps_ctrl
& PS_PLANE_SEL_MASK
)) {
8227 pipe_config
->pch_pfit
.enabled
= true;
8228 pipe_config
->pch_pfit
.pos
= I915_READ(SKL_PS_WIN_POS(crtc
->pipe
, i
));
8229 pipe_config
->pch_pfit
.size
= I915_READ(SKL_PS_WIN_SZ(crtc
->pipe
, i
));
8234 scaler_state
->scaler_id
= id
;
8236 scaler_state
->scaler_users
|= (1 << SKL_CRTC_INDEX
);
8238 scaler_state
->scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
8243 skylake_get_initial_plane_config(struct intel_crtc
*crtc
,
8244 struct intel_initial_plane_config
*plane_config
)
8246 struct drm_device
*dev
= crtc
->base
.dev
;
8247 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8248 u32 val
, base
, offset
, stride_mult
, tiling
;
8249 int pipe
= crtc
->pipe
;
8250 int fourcc
, pixel_format
;
8251 unsigned int aligned_height
;
8252 struct drm_framebuffer
*fb
;
8253 struct intel_framebuffer
*intel_fb
;
8255 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8257 DRM_DEBUG_KMS("failed to alloc fb\n");
8261 fb
= &intel_fb
->base
;
8265 val
= I915_READ(PLANE_CTL(pipe
, 0));
8266 if (!(val
& PLANE_CTL_ENABLE
))
8269 pixel_format
= val
& PLANE_CTL_FORMAT_MASK
;
8270 fourcc
= skl_format_to_fourcc(pixel_format
,
8271 val
& PLANE_CTL_ORDER_RGBX
,
8272 val
& PLANE_CTL_ALPHA_MASK
);
8273 fb
->format
= drm_format_info(fourcc
);
8275 tiling
= val
& PLANE_CTL_TILED_MASK
;
8277 case PLANE_CTL_TILED_LINEAR
:
8278 fb
->modifier
= DRM_FORMAT_MOD_LINEAR
;
8280 case PLANE_CTL_TILED_X
:
8281 plane_config
->tiling
= I915_TILING_X
;
8282 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
8284 case PLANE_CTL_TILED_Y
:
8285 fb
->modifier
= I915_FORMAT_MOD_Y_TILED
;
8287 case PLANE_CTL_TILED_YF
:
8288 fb
->modifier
= I915_FORMAT_MOD_Yf_TILED
;
8291 MISSING_CASE(tiling
);
8295 base
= I915_READ(PLANE_SURF(pipe
, 0)) & 0xfffff000;
8296 plane_config
->base
= base
;
8298 offset
= I915_READ(PLANE_OFFSET(pipe
, 0));
8300 val
= I915_READ(PLANE_SIZE(pipe
, 0));
8301 fb
->height
= ((val
>> 16) & 0xfff) + 1;
8302 fb
->width
= ((val
>> 0) & 0x1fff) + 1;
8304 val
= I915_READ(PLANE_STRIDE(pipe
, 0));
8305 stride_mult
= intel_fb_stride_alignment(fb
, 0);
8306 fb
->pitches
[0] = (val
& 0x3ff) * stride_mult
;
8308 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
8310 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8312 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8313 pipe_name(pipe
), fb
->width
, fb
->height
,
8314 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
8315 plane_config
->size
);
8317 plane_config
->fb
= intel_fb
;
8324 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
8325 struct intel_crtc_state
*pipe_config
)
8327 struct drm_device
*dev
= crtc
->base
.dev
;
8328 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8331 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
8333 if (tmp
& PF_ENABLE
) {
8334 pipe_config
->pch_pfit
.enabled
= true;
8335 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
8336 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
8338 /* We currently do not free assignements of panel fitters on
8339 * ivb/hsw (since we don't use the higher upscaling modes which
8340 * differentiates them) so just WARN about this case for now. */
8341 if (IS_GEN7(dev_priv
)) {
8342 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
8343 PF_PIPE_SEL_IVB(crtc
->pipe
));
8349 ironlake_get_initial_plane_config(struct intel_crtc
*crtc
,
8350 struct intel_initial_plane_config
*plane_config
)
8352 struct drm_device
*dev
= crtc
->base
.dev
;
8353 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8354 u32 val
, base
, offset
;
8355 int pipe
= crtc
->pipe
;
8356 int fourcc
, pixel_format
;
8357 unsigned int aligned_height
;
8358 struct drm_framebuffer
*fb
;
8359 struct intel_framebuffer
*intel_fb
;
8361 val
= I915_READ(DSPCNTR(pipe
));
8362 if (!(val
& DISPLAY_PLANE_ENABLE
))
8365 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8367 DRM_DEBUG_KMS("failed to alloc fb\n");
8371 fb
= &intel_fb
->base
;
8375 if (INTEL_GEN(dev_priv
) >= 4) {
8376 if (val
& DISPPLANE_TILED
) {
8377 plane_config
->tiling
= I915_TILING_X
;
8378 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
8382 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
8383 fourcc
= i9xx_format_to_fourcc(pixel_format
);
8384 fb
->format
= drm_format_info(fourcc
);
8386 base
= I915_READ(DSPSURF(pipe
)) & 0xfffff000;
8387 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
8388 offset
= I915_READ(DSPOFFSET(pipe
));
8390 if (plane_config
->tiling
)
8391 offset
= I915_READ(DSPTILEOFF(pipe
));
8393 offset
= I915_READ(DSPLINOFF(pipe
));
8395 plane_config
->base
= base
;
8397 val
= I915_READ(PIPESRC(pipe
));
8398 fb
->width
= ((val
>> 16) & 0xfff) + 1;
8399 fb
->height
= ((val
>> 0) & 0xfff) + 1;
8401 val
= I915_READ(DSPSTRIDE(pipe
));
8402 fb
->pitches
[0] = val
& 0xffffffc0;
8404 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
8406 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8408 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8409 pipe_name(pipe
), fb
->width
, fb
->height
,
8410 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
8411 plane_config
->size
);
8413 plane_config
->fb
= intel_fb
;
8416 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
8417 struct intel_crtc_state
*pipe_config
)
8419 struct drm_device
*dev
= crtc
->base
.dev
;
8420 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8421 enum intel_display_power_domain power_domain
;
8425 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
8426 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8429 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8430 pipe_config
->shared_dpll
= NULL
;
8433 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
8434 if (!(tmp
& PIPECONF_ENABLE
))
8437 switch (tmp
& PIPECONF_BPC_MASK
) {
8439 pipe_config
->pipe_bpp
= 18;
8442 pipe_config
->pipe_bpp
= 24;
8444 case PIPECONF_10BPC
:
8445 pipe_config
->pipe_bpp
= 30;
8447 case PIPECONF_12BPC
:
8448 pipe_config
->pipe_bpp
= 36;
8454 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
8455 pipe_config
->limited_color_range
= true;
8457 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
8458 struct intel_shared_dpll
*pll
;
8459 enum intel_dpll_id pll_id
;
8461 pipe_config
->has_pch_encoder
= true;
8463 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
8464 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
8465 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
8467 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
8469 if (HAS_PCH_IBX(dev_priv
)) {
8471 * The pipe->pch transcoder and pch transcoder->pll
8474 pll_id
= (enum intel_dpll_id
) crtc
->pipe
;
8476 tmp
= I915_READ(PCH_DPLL_SEL
);
8477 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
8478 pll_id
= DPLL_ID_PCH_PLL_B
;
8480 pll_id
= DPLL_ID_PCH_PLL_A
;
8483 pipe_config
->shared_dpll
=
8484 intel_get_shared_dpll_by_id(dev_priv
, pll_id
);
8485 pll
= pipe_config
->shared_dpll
;
8487 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
8488 &pipe_config
->dpll_hw_state
));
8490 tmp
= pipe_config
->dpll_hw_state
.dpll
;
8491 pipe_config
->pixel_multiplier
=
8492 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
8493 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
8495 ironlake_pch_clock_get(crtc
, pipe_config
);
8497 pipe_config
->pixel_multiplier
= 1;
8500 intel_get_pipe_timings(crtc
, pipe_config
);
8501 intel_get_pipe_src_size(crtc
, pipe_config
);
8503 ironlake_get_pfit_config(crtc
, pipe_config
);
8508 intel_display_power_put(dev_priv
, power_domain
);
8513 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
8515 struct drm_device
*dev
= &dev_priv
->drm
;
8516 struct intel_crtc
*crtc
;
8518 for_each_intel_crtc(dev
, crtc
)
8519 I915_STATE_WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
8520 pipe_name(crtc
->pipe
));
8522 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
8523 I915_STATE_WARN(I915_READ(SPLL_CTL
) & SPLL_PLL_ENABLE
, "SPLL enabled\n");
8524 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE
, "WRPLL1 enabled\n");
8525 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE
, "WRPLL2 enabled\n");
8526 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON
, "Panel power on\n");
8527 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
8528 "CPU PWM1 enabled\n");
8529 if (IS_HASWELL(dev_priv
))
8530 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
8531 "CPU PWM2 enabled\n");
8532 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
8533 "PCH PWM1 enabled\n");
8534 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
8535 "Utility pin enabled\n");
8536 I915_STATE_WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
8539 * In theory we can still leave IRQs enabled, as long as only the HPD
8540 * interrupts remain enabled. We used to check for that, but since it's
8541 * gen-specific and since we only disable LCPLL after we fully disable
8542 * the interrupts, the check below should be enough.
8544 I915_STATE_WARN(intel_irqs_enabled(dev_priv
), "IRQs enabled\n");
8547 static uint32_t hsw_read_dcomp(struct drm_i915_private
*dev_priv
)
8549 if (IS_HASWELL(dev_priv
))
8550 return I915_READ(D_COMP_HSW
);
8552 return I915_READ(D_COMP_BDW
);
8555 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
8557 if (IS_HASWELL(dev_priv
)) {
8558 mutex_lock(&dev_priv
->rps
.hw_lock
);
8559 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
8561 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
8562 mutex_unlock(&dev_priv
->rps
.hw_lock
);
8564 I915_WRITE(D_COMP_BDW
, val
);
8565 POSTING_READ(D_COMP_BDW
);
8570 * This function implements pieces of two sequences from BSpec:
8571 * - Sequence for display software to disable LCPLL
8572 * - Sequence for display software to allow package C8+
8573 * The steps implemented here are just the steps that actually touch the LCPLL
8574 * register. Callers should take care of disabling all the display engine
8575 * functions, doing the mode unset, fixing interrupts, etc.
8577 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
8578 bool switch_to_fclk
, bool allow_power_down
)
8582 assert_can_disable_lcpll(dev_priv
);
8584 val
= I915_READ(LCPLL_CTL
);
8586 if (switch_to_fclk
) {
8587 val
|= LCPLL_CD_SOURCE_FCLK
;
8588 I915_WRITE(LCPLL_CTL
, val
);
8590 if (wait_for_us(I915_READ(LCPLL_CTL
) &
8591 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
8592 DRM_ERROR("Switching to FCLK failed\n");
8594 val
= I915_READ(LCPLL_CTL
);
8597 val
|= LCPLL_PLL_DISABLE
;
8598 I915_WRITE(LCPLL_CTL
, val
);
8599 POSTING_READ(LCPLL_CTL
);
8601 if (intel_wait_for_register(dev_priv
, LCPLL_CTL
, LCPLL_PLL_LOCK
, 0, 1))
8602 DRM_ERROR("LCPLL still locked\n");
8604 val
= hsw_read_dcomp(dev_priv
);
8605 val
|= D_COMP_COMP_DISABLE
;
8606 hsw_write_dcomp(dev_priv
, val
);
8609 if (wait_for((hsw_read_dcomp(dev_priv
) & D_COMP_RCOMP_IN_PROGRESS
) == 0,
8611 DRM_ERROR("D_COMP RCOMP still in progress\n");
8613 if (allow_power_down
) {
8614 val
= I915_READ(LCPLL_CTL
);
8615 val
|= LCPLL_POWER_DOWN_ALLOW
;
8616 I915_WRITE(LCPLL_CTL
, val
);
8617 POSTING_READ(LCPLL_CTL
);
8622 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
8625 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
8629 val
= I915_READ(LCPLL_CTL
);
8631 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
8632 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
8636 * Make sure we're not on PC8 state before disabling PC8, otherwise
8637 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
8639 intel_uncore_forcewake_get(dev_priv
, FORCEWAKE_ALL
);
8641 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
8642 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
8643 I915_WRITE(LCPLL_CTL
, val
);
8644 POSTING_READ(LCPLL_CTL
);
8647 val
= hsw_read_dcomp(dev_priv
);
8648 val
|= D_COMP_COMP_FORCE
;
8649 val
&= ~D_COMP_COMP_DISABLE
;
8650 hsw_write_dcomp(dev_priv
, val
);
8652 val
= I915_READ(LCPLL_CTL
);
8653 val
&= ~LCPLL_PLL_DISABLE
;
8654 I915_WRITE(LCPLL_CTL
, val
);
8656 if (intel_wait_for_register(dev_priv
,
8657 LCPLL_CTL
, LCPLL_PLL_LOCK
, LCPLL_PLL_LOCK
,
8659 DRM_ERROR("LCPLL not locked yet\n");
8661 if (val
& LCPLL_CD_SOURCE_FCLK
) {
8662 val
= I915_READ(LCPLL_CTL
);
8663 val
&= ~LCPLL_CD_SOURCE_FCLK
;
8664 I915_WRITE(LCPLL_CTL
, val
);
8666 if (wait_for_us((I915_READ(LCPLL_CTL
) &
8667 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
8668 DRM_ERROR("Switching back to LCPLL failed\n");
8671 intel_uncore_forcewake_put(dev_priv
, FORCEWAKE_ALL
);
8672 intel_update_cdclk(dev_priv
);
8676 * Package states C8 and deeper are really deep PC states that can only be
8677 * reached when all the devices on the system allow it, so even if the graphics
8678 * device allows PC8+, it doesn't mean the system will actually get to these
8679 * states. Our driver only allows PC8+ when going into runtime PM.
8681 * The requirements for PC8+ are that all the outputs are disabled, the power
8682 * well is disabled and most interrupts are disabled, and these are also
8683 * requirements for runtime PM. When these conditions are met, we manually do
8684 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
8685 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
8688 * When we really reach PC8 or deeper states (not just when we allow it) we lose
8689 * the state of some registers, so when we come back from PC8+ we need to
8690 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
8691 * need to take care of the registers kept by RC6. Notice that this happens even
8692 * if we don't put the device in PCI D3 state (which is what currently happens
8693 * because of the runtime PM support).
8695 * For more, read "Display Sequences for Package C8" on the hardware
8698 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
8702 DRM_DEBUG_KMS("Enabling package C8+\n");
8704 if (HAS_PCH_LPT_LP(dev_priv
)) {
8705 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
8706 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
8707 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
8710 lpt_disable_clkout_dp(dev_priv
);
8711 hsw_disable_lcpll(dev_priv
, true, true);
8714 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
8718 DRM_DEBUG_KMS("Disabling package C8+\n");
8720 hsw_restore_lcpll(dev_priv
);
8721 lpt_init_pch_refclk(dev_priv
);
8723 if (HAS_PCH_LPT_LP(dev_priv
)) {
8724 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
8725 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
8726 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
8730 static int haswell_crtc_compute_clock(struct intel_crtc
*crtc
,
8731 struct intel_crtc_state
*crtc_state
)
8733 if (!intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DSI
)) {
8734 struct intel_encoder
*encoder
=
8735 intel_ddi_get_crtc_new_encoder(crtc_state
);
8737 if (!intel_get_shared_dpll(crtc
, crtc_state
, encoder
)) {
8738 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8739 pipe_name(crtc
->pipe
));
8744 crtc
->lowfreq_avail
= false;
8749 static void cannonlake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8751 struct intel_crtc_state
*pipe_config
)
8753 enum intel_dpll_id id
;
8756 temp
= I915_READ(DPCLKA_CFGCR0
) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port
);
8757 id
= temp
>> (port
* 2);
8759 if (WARN_ON(id
< SKL_DPLL0
|| id
> SKL_DPLL2
))
8762 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8765 static void bxt_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8767 struct intel_crtc_state
*pipe_config
)
8769 enum intel_dpll_id id
;
8773 id
= DPLL_ID_SKL_DPLL0
;
8776 id
= DPLL_ID_SKL_DPLL1
;
8779 id
= DPLL_ID_SKL_DPLL2
;
8782 DRM_ERROR("Incorrect port type\n");
8786 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8789 static void skylake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8791 struct intel_crtc_state
*pipe_config
)
8793 enum intel_dpll_id id
;
8796 temp
= I915_READ(DPLL_CTRL2
) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port
);
8797 id
= temp
>> (port
* 3 + 1);
8799 if (WARN_ON(id
< SKL_DPLL0
|| id
> SKL_DPLL3
))
8802 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8805 static void haswell_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8807 struct intel_crtc_state
*pipe_config
)
8809 enum intel_dpll_id id
;
8810 uint32_t ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
8812 switch (ddi_pll_sel
) {
8813 case PORT_CLK_SEL_WRPLL1
:
8814 id
= DPLL_ID_WRPLL1
;
8816 case PORT_CLK_SEL_WRPLL2
:
8817 id
= DPLL_ID_WRPLL2
;
8819 case PORT_CLK_SEL_SPLL
:
8822 case PORT_CLK_SEL_LCPLL_810
:
8823 id
= DPLL_ID_LCPLL_810
;
8825 case PORT_CLK_SEL_LCPLL_1350
:
8826 id
= DPLL_ID_LCPLL_1350
;
8828 case PORT_CLK_SEL_LCPLL_2700
:
8829 id
= DPLL_ID_LCPLL_2700
;
8832 MISSING_CASE(ddi_pll_sel
);
8834 case PORT_CLK_SEL_NONE
:
8838 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8841 static bool hsw_get_transcoder_state(struct intel_crtc
*crtc
,
8842 struct intel_crtc_state
*pipe_config
,
8843 u64
*power_domain_mask
)
8845 struct drm_device
*dev
= crtc
->base
.dev
;
8846 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8847 enum intel_display_power_domain power_domain
;
8851 * The pipe->transcoder mapping is fixed with the exception of the eDP
8852 * transcoder handled below.
8854 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8857 * XXX: Do intel_display_power_get_if_enabled before reading this (for
8858 * consistency and less surprising code; it's in always on power).
8860 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
8861 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
8862 enum pipe trans_edp_pipe
;
8863 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
8865 WARN(1, "unknown pipe linked to edp transcoder\n");
8866 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
8867 case TRANS_DDI_EDP_INPUT_A_ON
:
8868 trans_edp_pipe
= PIPE_A
;
8870 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
8871 trans_edp_pipe
= PIPE_B
;
8873 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
8874 trans_edp_pipe
= PIPE_C
;
8878 if (trans_edp_pipe
== crtc
->pipe
)
8879 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
8882 power_domain
= POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
);
8883 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8885 *power_domain_mask
|= BIT_ULL(power_domain
);
8887 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
8889 return tmp
& PIPECONF_ENABLE
;
8892 static bool bxt_get_dsi_transcoder_state(struct intel_crtc
*crtc
,
8893 struct intel_crtc_state
*pipe_config
,
8894 u64
*power_domain_mask
)
8896 struct drm_device
*dev
= crtc
->base
.dev
;
8897 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8898 enum intel_display_power_domain power_domain
;
8900 enum transcoder cpu_transcoder
;
8903 for_each_port_masked(port
, BIT(PORT_A
) | BIT(PORT_C
)) {
8905 cpu_transcoder
= TRANSCODER_DSI_A
;
8907 cpu_transcoder
= TRANSCODER_DSI_C
;
8909 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
8910 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8912 *power_domain_mask
|= BIT_ULL(power_domain
);
8915 * The PLL needs to be enabled with a valid divider
8916 * configuration, otherwise accessing DSI registers will hang
8917 * the machine. See BSpec North Display Engine
8918 * registers/MIPI[BXT]. We can break out here early, since we
8919 * need the same DSI PLL to be enabled for both DSI ports.
8921 if (!intel_dsi_pll_is_enabled(dev_priv
))
8924 /* XXX: this works for video mode only */
8925 tmp
= I915_READ(BXT_MIPI_PORT_CTRL(port
));
8926 if (!(tmp
& DPI_ENABLE
))
8929 tmp
= I915_READ(MIPI_CTRL(port
));
8930 if ((tmp
& BXT_PIPE_SELECT_MASK
) != BXT_PIPE_SELECT(crtc
->pipe
))
8933 pipe_config
->cpu_transcoder
= cpu_transcoder
;
8937 return transcoder_is_dsi(pipe_config
->cpu_transcoder
);
8940 static void haswell_get_ddi_port_state(struct intel_crtc
*crtc
,
8941 struct intel_crtc_state
*pipe_config
)
8943 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
8944 struct intel_shared_dpll
*pll
;
8948 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
8950 port
= (tmp
& TRANS_DDI_PORT_MASK
) >> TRANS_DDI_PORT_SHIFT
;
8952 if (IS_CANNONLAKE(dev_priv
))
8953 cannonlake_get_ddi_pll(dev_priv
, port
, pipe_config
);
8954 else if (IS_GEN9_BC(dev_priv
))
8955 skylake_get_ddi_pll(dev_priv
, port
, pipe_config
);
8956 else if (IS_GEN9_LP(dev_priv
))
8957 bxt_get_ddi_pll(dev_priv
, port
, pipe_config
);
8959 haswell_get_ddi_pll(dev_priv
, port
, pipe_config
);
8961 pll
= pipe_config
->shared_dpll
;
8963 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
8964 &pipe_config
->dpll_hw_state
));
8968 * Haswell has only FDI/PCH transcoder A. It is which is connected to
8969 * DDI E. So just check whether this pipe is wired to DDI E and whether
8970 * the PCH transcoder is on.
8972 if (INTEL_GEN(dev_priv
) < 9 &&
8973 (port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
8974 pipe_config
->has_pch_encoder
= true;
8976 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
8977 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
8978 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
8980 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
8984 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
8985 struct intel_crtc_state
*pipe_config
)
8987 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
8988 enum intel_display_power_domain power_domain
;
8989 u64 power_domain_mask
;
8992 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
8993 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8995 power_domain_mask
= BIT_ULL(power_domain
);
8997 pipe_config
->shared_dpll
= NULL
;
8999 active
= hsw_get_transcoder_state(crtc
, pipe_config
, &power_domain_mask
);
9001 if (IS_GEN9_LP(dev_priv
) &&
9002 bxt_get_dsi_transcoder_state(crtc
, pipe_config
, &power_domain_mask
)) {
9010 if (!transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
9011 haswell_get_ddi_port_state(crtc
, pipe_config
);
9012 intel_get_pipe_timings(crtc
, pipe_config
);
9015 intel_get_pipe_src_size(crtc
, pipe_config
);
9017 pipe_config
->gamma_mode
=
9018 I915_READ(GAMMA_MODE(crtc
->pipe
)) & GAMMA_MODE_MODE_MASK
;
9020 if (INTEL_GEN(dev_priv
) >= 9) {
9021 intel_crtc_init_scalers(crtc
, pipe_config
);
9023 pipe_config
->scaler_state
.scaler_id
= -1;
9024 pipe_config
->scaler_state
.scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
9027 power_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
9028 if (intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
9029 power_domain_mask
|= BIT_ULL(power_domain
);
9030 if (INTEL_GEN(dev_priv
) >= 9)
9031 skylake_get_pfit_config(crtc
, pipe_config
);
9033 ironlake_get_pfit_config(crtc
, pipe_config
);
9036 if (IS_HASWELL(dev_priv
))
9037 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
9038 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
9040 if (pipe_config
->cpu_transcoder
!= TRANSCODER_EDP
&&
9041 !transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
9042 pipe_config
->pixel_multiplier
=
9043 I915_READ(PIPE_MULT(pipe_config
->cpu_transcoder
)) + 1;
9045 pipe_config
->pixel_multiplier
= 1;
9049 for_each_power_domain(power_domain
, power_domain_mask
)
9050 intel_display_power_put(dev_priv
, power_domain
);
9055 static u32
intel_cursor_base(const struct intel_plane_state
*plane_state
)
9057 struct drm_i915_private
*dev_priv
=
9058 to_i915(plane_state
->base
.plane
->dev
);
9059 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9060 const struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
9063 if (INTEL_INFO(dev_priv
)->cursor_needs_physical
)
9064 base
= obj
->phys_handle
->busaddr
;
9066 base
= intel_plane_ggtt_offset(plane_state
);
9068 base
+= plane_state
->main
.offset
;
9070 /* ILK+ do this automagically */
9071 if (HAS_GMCH_DISPLAY(dev_priv
) &&
9072 plane_state
->base
.rotation
& DRM_MODE_ROTATE_180
)
9073 base
+= (plane_state
->base
.crtc_h
*
9074 plane_state
->base
.crtc_w
- 1) * fb
->format
->cpp
[0];
9079 static u32
intel_cursor_position(const struct intel_plane_state
*plane_state
)
9081 int x
= plane_state
->base
.crtc_x
;
9082 int y
= plane_state
->base
.crtc_y
;
9086 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
9089 pos
|= x
<< CURSOR_X_SHIFT
;
9092 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
9095 pos
|= y
<< CURSOR_Y_SHIFT
;
9100 static bool intel_cursor_size_ok(const struct intel_plane_state
*plane_state
)
9102 const struct drm_mode_config
*config
=
9103 &plane_state
->base
.plane
->dev
->mode_config
;
9104 int width
= plane_state
->base
.crtc_w
;
9105 int height
= plane_state
->base
.crtc_h
;
9107 return width
> 0 && width
<= config
->cursor_width
&&
9108 height
> 0 && height
<= config
->cursor_height
;
9111 static int intel_check_cursor(struct intel_crtc_state
*crtc_state
,
9112 struct intel_plane_state
*plane_state
)
9114 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9119 ret
= drm_plane_helper_check_state(&plane_state
->base
,
9121 DRM_PLANE_HELPER_NO_SCALING
,
9122 DRM_PLANE_HELPER_NO_SCALING
,
9130 if (fb
->modifier
!= DRM_FORMAT_MOD_LINEAR
) {
9131 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9135 src_x
= plane_state
->base
.src_x
>> 16;
9136 src_y
= plane_state
->base
.src_y
>> 16;
9138 intel_add_fb_offsets(&src_x
, &src_y
, plane_state
, 0);
9139 offset
= intel_compute_tile_offset(&src_x
, &src_y
, plane_state
, 0);
9141 if (src_x
!= 0 || src_y
!= 0) {
9142 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9146 plane_state
->main
.offset
= offset
;
9151 static u32
i845_cursor_ctl(const struct intel_crtc_state
*crtc_state
,
9152 const struct intel_plane_state
*plane_state
)
9154 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9156 return CURSOR_ENABLE
|
9157 CURSOR_GAMMA_ENABLE
|
9158 CURSOR_FORMAT_ARGB
|
9159 CURSOR_STRIDE(fb
->pitches
[0]);
9162 static bool i845_cursor_size_ok(const struct intel_plane_state
*plane_state
)
9164 int width
= plane_state
->base
.crtc_w
;
9167 * 845g/865g are only limited by the width of their cursors,
9168 * the height is arbitrary up to the precision of the register.
9170 return intel_cursor_size_ok(plane_state
) && IS_ALIGNED(width
, 64);
9173 static int i845_check_cursor(struct intel_plane
*plane
,
9174 struct intel_crtc_state
*crtc_state
,
9175 struct intel_plane_state
*plane_state
)
9177 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9180 ret
= intel_check_cursor(crtc_state
, plane_state
);
9184 /* if we want to turn off the cursor ignore width and height */
9188 /* Check for which cursor types we support */
9189 if (!i845_cursor_size_ok(plane_state
)) {
9190 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9191 plane_state
->base
.crtc_w
,
9192 plane_state
->base
.crtc_h
);
9196 switch (fb
->pitches
[0]) {
9203 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
9208 plane_state
->ctl
= i845_cursor_ctl(crtc_state
, plane_state
);
9213 static void i845_update_cursor(struct intel_plane
*plane
,
9214 const struct intel_crtc_state
*crtc_state
,
9215 const struct intel_plane_state
*plane_state
)
9217 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
9218 u32 cntl
= 0, base
= 0, pos
= 0, size
= 0;
9219 unsigned long irqflags
;
9221 if (plane_state
&& plane_state
->base
.visible
) {
9222 unsigned int width
= plane_state
->base
.crtc_w
;
9223 unsigned int height
= plane_state
->base
.crtc_h
;
9225 cntl
= plane_state
->ctl
;
9226 size
= (height
<< 12) | width
;
9228 base
= intel_cursor_base(plane_state
);
9229 pos
= intel_cursor_position(plane_state
);
9232 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
9234 /* On these chipsets we can only modify the base/size/stride
9235 * whilst the cursor is disabled.
9237 if (plane
->cursor
.base
!= base
||
9238 plane
->cursor
.size
!= size
||
9239 plane
->cursor
.cntl
!= cntl
) {
9240 I915_WRITE_FW(CURCNTR(PIPE_A
), 0);
9241 I915_WRITE_FW(CURBASE(PIPE_A
), base
);
9242 I915_WRITE_FW(CURSIZE
, size
);
9243 I915_WRITE_FW(CURPOS(PIPE_A
), pos
);
9244 I915_WRITE_FW(CURCNTR(PIPE_A
), cntl
);
9246 plane
->cursor
.base
= base
;
9247 plane
->cursor
.size
= size
;
9248 plane
->cursor
.cntl
= cntl
;
9250 I915_WRITE_FW(CURPOS(PIPE_A
), pos
);
9253 POSTING_READ_FW(CURCNTR(PIPE_A
));
9255 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
9258 static void i845_disable_cursor(struct intel_plane
*plane
,
9259 struct intel_crtc
*crtc
)
9261 i845_update_cursor(plane
, NULL
, NULL
);
9264 static u32
i9xx_cursor_ctl(const struct intel_crtc_state
*crtc_state
,
9265 const struct intel_plane_state
*plane_state
)
9267 struct drm_i915_private
*dev_priv
=
9268 to_i915(plane_state
->base
.plane
->dev
);
9269 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
9272 cntl
= MCURSOR_GAMMA_ENABLE
;
9274 if (HAS_DDI(dev_priv
))
9275 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
9277 cntl
|= MCURSOR_PIPE_SELECT(crtc
->pipe
);
9279 switch (plane_state
->base
.crtc_w
) {
9281 cntl
|= CURSOR_MODE_64_ARGB_AX
;
9284 cntl
|= CURSOR_MODE_128_ARGB_AX
;
9287 cntl
|= CURSOR_MODE_256_ARGB_AX
;
9290 MISSING_CASE(plane_state
->base
.crtc_w
);
9294 if (plane_state
->base
.rotation
& DRM_MODE_ROTATE_180
)
9295 cntl
|= CURSOR_ROTATE_180
;
9300 static bool i9xx_cursor_size_ok(const struct intel_plane_state
*plane_state
)
9302 struct drm_i915_private
*dev_priv
=
9303 to_i915(plane_state
->base
.plane
->dev
);
9304 int width
= plane_state
->base
.crtc_w
;
9305 int height
= plane_state
->base
.crtc_h
;
9307 if (!intel_cursor_size_ok(plane_state
))
9310 /* Cursor width is limited to a few power-of-two sizes */
9321 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
9322 * height from 8 lines up to the cursor width, when the
9323 * cursor is not rotated. Everything else requires square
9326 if (HAS_CUR_FBC(dev_priv
) &&
9327 plane_state
->base
.rotation
& DRM_MODE_ROTATE_0
) {
9328 if (height
< 8 || height
> width
)
9331 if (height
!= width
)
9338 static int i9xx_check_cursor(struct intel_plane
*plane
,
9339 struct intel_crtc_state
*crtc_state
,
9340 struct intel_plane_state
*plane_state
)
9342 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
9343 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9344 enum pipe pipe
= plane
->pipe
;
9347 ret
= intel_check_cursor(crtc_state
, plane_state
);
9351 /* if we want to turn off the cursor ignore width and height */
9355 /* Check for which cursor types we support */
9356 if (!i9xx_cursor_size_ok(plane_state
)) {
9357 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9358 plane_state
->base
.crtc_w
,
9359 plane_state
->base
.crtc_h
);
9363 if (fb
->pitches
[0] != plane_state
->base
.crtc_w
* fb
->format
->cpp
[0]) {
9364 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
9365 fb
->pitches
[0], plane_state
->base
.crtc_w
);
9370 * There's something wrong with the cursor on CHV pipe C.
9371 * If it straddles the left edge of the screen then
9372 * moving it away from the edge or disabling it often
9373 * results in a pipe underrun, and often that can lead to
9374 * dead pipe (constant underrun reported, and it scans
9375 * out just a solid color). To recover from that, the
9376 * display power well must be turned off and on again.
9377 * Refuse the put the cursor into that compromised position.
9379 if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_C
&&
9380 plane_state
->base
.visible
&& plane_state
->base
.crtc_x
< 0) {
9381 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
9385 plane_state
->ctl
= i9xx_cursor_ctl(crtc_state
, plane_state
);
9390 static void i9xx_update_cursor(struct intel_plane
*plane
,
9391 const struct intel_crtc_state
*crtc_state
,
9392 const struct intel_plane_state
*plane_state
)
9394 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
9395 enum pipe pipe
= plane
->pipe
;
9396 u32 cntl
= 0, base
= 0, pos
= 0, fbc_ctl
= 0;
9397 unsigned long irqflags
;
9399 if (plane_state
&& plane_state
->base
.visible
) {
9400 cntl
= plane_state
->ctl
;
9402 if (plane_state
->base
.crtc_h
!= plane_state
->base
.crtc_w
)
9403 fbc_ctl
= CUR_FBC_CTL_EN
| (plane_state
->base
.crtc_h
- 1);
9405 base
= intel_cursor_base(plane_state
);
9406 pos
= intel_cursor_position(plane_state
);
9409 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
9412 * On some platforms writing CURCNTR first will also
9413 * cause CURPOS to be armed by the CURBASE write.
9414 * Without the CURCNTR write the CURPOS write would
9415 * arm itself. Thus we always start the full update
9416 * with a CURCNTR write.
9418 * On other platforms CURPOS always requires the
9419 * CURBASE write to arm the update. Additonally
9420 * a write to any of the cursor register will cancel
9421 * an already armed cursor update. Thus leaving out
9422 * the CURBASE write after CURPOS could lead to a
9423 * cursor that doesn't appear to move, or even change
9424 * shape. Thus we always write CURBASE.
9426 * CURCNTR and CUR_FBC_CTL are always
9427 * armed by the CURBASE write only.
9429 if (plane
->cursor
.base
!= base
||
9430 plane
->cursor
.size
!= fbc_ctl
||
9431 plane
->cursor
.cntl
!= cntl
) {
9432 I915_WRITE_FW(CURCNTR(pipe
), cntl
);
9433 if (HAS_CUR_FBC(dev_priv
))
9434 I915_WRITE_FW(CUR_FBC_CTL(pipe
), fbc_ctl
);
9435 I915_WRITE_FW(CURPOS(pipe
), pos
);
9436 I915_WRITE_FW(CURBASE(pipe
), base
);
9438 plane
->cursor
.base
= base
;
9439 plane
->cursor
.size
= fbc_ctl
;
9440 plane
->cursor
.cntl
= cntl
;
9442 I915_WRITE_FW(CURPOS(pipe
), pos
);
9443 I915_WRITE_FW(CURBASE(pipe
), base
);
9446 POSTING_READ_FW(CURBASE(pipe
));
9448 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
9451 static void i9xx_disable_cursor(struct intel_plane
*plane
,
9452 struct intel_crtc
*crtc
)
9454 i9xx_update_cursor(plane
, NULL
, NULL
);
9458 /* VESA 640x480x72Hz mode to set on the pipe */
9459 static struct drm_display_mode load_detect_mode
= {
9460 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
9461 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
9464 struct drm_framebuffer
*
9465 intel_framebuffer_create(struct drm_i915_gem_object
*obj
,
9466 struct drm_mode_fb_cmd2
*mode_cmd
)
9468 struct intel_framebuffer
*intel_fb
;
9471 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9473 return ERR_PTR(-ENOMEM
);
9475 ret
= intel_framebuffer_init(intel_fb
, obj
, mode_cmd
);
9479 return &intel_fb
->base
;
9483 return ERR_PTR(ret
);
9487 intel_framebuffer_pitch_for_width(int width
, int bpp
)
9489 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
9490 return ALIGN(pitch
, 64);
9494 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
9496 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
9497 return PAGE_ALIGN(pitch
* mode
->vdisplay
);
9500 static struct drm_framebuffer
*
9501 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
9502 struct drm_display_mode
*mode
,
9505 struct drm_framebuffer
*fb
;
9506 struct drm_i915_gem_object
*obj
;
9507 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
9509 obj
= i915_gem_object_create(to_i915(dev
),
9510 intel_framebuffer_size_for_mode(mode
, bpp
));
9512 return ERR_CAST(obj
);
9514 mode_cmd
.width
= mode
->hdisplay
;
9515 mode_cmd
.height
= mode
->vdisplay
;
9516 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
9518 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
9520 fb
= intel_framebuffer_create(obj
, &mode_cmd
);
9522 i915_gem_object_put(obj
);
9527 static struct drm_framebuffer
*
9528 mode_fits_in_fbdev(struct drm_device
*dev
,
9529 struct drm_display_mode
*mode
)
9531 #ifdef CONFIG_DRM_FBDEV_EMULATION
9532 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9533 struct drm_i915_gem_object
*obj
;
9534 struct drm_framebuffer
*fb
;
9536 if (!dev_priv
->fbdev
)
9539 if (!dev_priv
->fbdev
->fb
)
9542 obj
= dev_priv
->fbdev
->fb
->obj
;
9545 fb
= &dev_priv
->fbdev
->fb
->base
;
9546 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
9547 fb
->format
->cpp
[0] * 8))
9550 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
9553 drm_framebuffer_reference(fb
);
9560 static int intel_modeset_setup_plane_state(struct drm_atomic_state
*state
,
9561 struct drm_crtc
*crtc
,
9562 struct drm_display_mode
*mode
,
9563 struct drm_framebuffer
*fb
,
9566 struct drm_plane_state
*plane_state
;
9567 int hdisplay
, vdisplay
;
9570 plane_state
= drm_atomic_get_plane_state(state
, crtc
->primary
);
9571 if (IS_ERR(plane_state
))
9572 return PTR_ERR(plane_state
);
9575 drm_mode_get_hv_timing(mode
, &hdisplay
, &vdisplay
);
9577 hdisplay
= vdisplay
= 0;
9579 ret
= drm_atomic_set_crtc_for_plane(plane_state
, fb
? crtc
: NULL
);
9582 drm_atomic_set_fb_for_plane(plane_state
, fb
);
9583 plane_state
->crtc_x
= 0;
9584 plane_state
->crtc_y
= 0;
9585 plane_state
->crtc_w
= hdisplay
;
9586 plane_state
->crtc_h
= vdisplay
;
9587 plane_state
->src_x
= x
<< 16;
9588 plane_state
->src_y
= y
<< 16;
9589 plane_state
->src_w
= hdisplay
<< 16;
9590 plane_state
->src_h
= vdisplay
<< 16;
9595 int intel_get_load_detect_pipe(struct drm_connector
*connector
,
9596 struct drm_display_mode
*mode
,
9597 struct intel_load_detect_pipe
*old
,
9598 struct drm_modeset_acquire_ctx
*ctx
)
9600 struct intel_crtc
*intel_crtc
;
9601 struct intel_encoder
*intel_encoder
=
9602 intel_attached_encoder(connector
);
9603 struct drm_crtc
*possible_crtc
;
9604 struct drm_encoder
*encoder
= &intel_encoder
->base
;
9605 struct drm_crtc
*crtc
= NULL
;
9606 struct drm_device
*dev
= encoder
->dev
;
9607 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9608 struct drm_framebuffer
*fb
;
9609 struct drm_mode_config
*config
= &dev
->mode_config
;
9610 struct drm_atomic_state
*state
= NULL
, *restore_state
= NULL
;
9611 struct drm_connector_state
*connector_state
;
9612 struct intel_crtc_state
*crtc_state
;
9615 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9616 connector
->base
.id
, connector
->name
,
9617 encoder
->base
.id
, encoder
->name
);
9619 old
->restore_state
= NULL
;
9621 WARN_ON(!drm_modeset_is_locked(&config
->connection_mutex
));
9624 * Algorithm gets a little messy:
9626 * - if the connector already has an assigned crtc, use it (but make
9627 * sure it's on first)
9629 * - try to find the first unused crtc that can drive this connector,
9630 * and use that if we find one
9633 /* See if we already have a CRTC for this connector */
9634 if (connector
->state
->crtc
) {
9635 crtc
= connector
->state
->crtc
;
9637 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
9641 /* Make sure the crtc and connector are running */
9645 /* Find an unused one (if possible) */
9646 for_each_crtc(dev
, possible_crtc
) {
9648 if (!(encoder
->possible_crtcs
& (1 << i
)))
9651 ret
= drm_modeset_lock(&possible_crtc
->mutex
, ctx
);
9655 if (possible_crtc
->state
->enable
) {
9656 drm_modeset_unlock(&possible_crtc
->mutex
);
9660 crtc
= possible_crtc
;
9665 * If we didn't find an unused CRTC, don't use any.
9668 DRM_DEBUG_KMS("no pipe available for load-detect\n");
9674 intel_crtc
= to_intel_crtc(crtc
);
9676 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
9680 state
= drm_atomic_state_alloc(dev
);
9681 restore_state
= drm_atomic_state_alloc(dev
);
9682 if (!state
|| !restore_state
) {
9687 state
->acquire_ctx
= ctx
;
9688 restore_state
->acquire_ctx
= ctx
;
9690 connector_state
= drm_atomic_get_connector_state(state
, connector
);
9691 if (IS_ERR(connector_state
)) {
9692 ret
= PTR_ERR(connector_state
);
9696 ret
= drm_atomic_set_crtc_for_connector(connector_state
, crtc
);
9700 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
9701 if (IS_ERR(crtc_state
)) {
9702 ret
= PTR_ERR(crtc_state
);
9706 crtc_state
->base
.active
= crtc_state
->base
.enable
= true;
9709 mode
= &load_detect_mode
;
9711 /* We need a framebuffer large enough to accommodate all accesses
9712 * that the plane may generate whilst we perform load detection.
9713 * We can not rely on the fbcon either being present (we get called
9714 * during its initialisation to detect all boot displays, or it may
9715 * not even exist) or that it is large enough to satisfy the
9718 fb
= mode_fits_in_fbdev(dev
, mode
);
9720 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
9721 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
9723 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
9725 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
9730 ret
= intel_modeset_setup_plane_state(state
, crtc
, mode
, fb
, 0, 0);
9734 drm_framebuffer_unreference(fb
);
9736 ret
= drm_atomic_set_mode_for_crtc(&crtc_state
->base
, mode
);
9740 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state
, connector
));
9742 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state
, crtc
));
9744 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state
, crtc
->primary
));
9746 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret
);
9750 ret
= drm_atomic_commit(state
);
9752 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
9756 old
->restore_state
= restore_state
;
9757 drm_atomic_state_put(state
);
9759 /* let the connector get through one full cycle before testing */
9760 intel_wait_for_vblank(dev_priv
, intel_crtc
->pipe
);
9765 drm_atomic_state_put(state
);
9768 if (restore_state
) {
9769 drm_atomic_state_put(restore_state
);
9770 restore_state
= NULL
;
9773 if (ret
== -EDEADLK
)
9779 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
9780 struct intel_load_detect_pipe
*old
,
9781 struct drm_modeset_acquire_ctx
*ctx
)
9783 struct intel_encoder
*intel_encoder
=
9784 intel_attached_encoder(connector
);
9785 struct drm_encoder
*encoder
= &intel_encoder
->base
;
9786 struct drm_atomic_state
*state
= old
->restore_state
;
9789 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9790 connector
->base
.id
, connector
->name
,
9791 encoder
->base
.id
, encoder
->name
);
9796 ret
= drm_atomic_helper_commit_duplicated_state(state
, ctx
);
9798 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret
);
9799 drm_atomic_state_put(state
);
9802 static int i9xx_pll_refclk(struct drm_device
*dev
,
9803 const struct intel_crtc_state
*pipe_config
)
9805 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9806 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
9808 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
9809 return dev_priv
->vbt
.lvds_ssc_freq
;
9810 else if (HAS_PCH_SPLIT(dev_priv
))
9812 else if (!IS_GEN2(dev_priv
))
9818 /* Returns the clock of the currently programmed mode of the given pipe. */
9819 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
9820 struct intel_crtc_state
*pipe_config
)
9822 struct drm_device
*dev
= crtc
->base
.dev
;
9823 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9824 int pipe
= pipe_config
->cpu_transcoder
;
9825 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
9829 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
9831 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
9832 fp
= pipe_config
->dpll_hw_state
.fp0
;
9834 fp
= pipe_config
->dpll_hw_state
.fp1
;
9836 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
9837 if (IS_PINEVIEW(dev_priv
)) {
9838 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
9839 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
9841 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
9842 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
9845 if (!IS_GEN2(dev_priv
)) {
9846 if (IS_PINEVIEW(dev_priv
))
9847 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
9848 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
9850 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
9851 DPLL_FPA01_P1_POST_DIV_SHIFT
);
9853 switch (dpll
& DPLL_MODE_MASK
) {
9854 case DPLLB_MODE_DAC_SERIAL
:
9855 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
9858 case DPLLB_MODE_LVDS
:
9859 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
9863 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
9864 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
9868 if (IS_PINEVIEW(dev_priv
))
9869 port_clock
= pnv_calc_dpll_params(refclk
, &clock
);
9871 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
9873 u32 lvds
= IS_I830(dev_priv
) ? 0 : I915_READ(LVDS
);
9874 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
9877 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
9878 DPLL_FPA01_P1_POST_DIV_SHIFT
);
9880 if (lvds
& LVDS_CLKB_POWER_UP
)
9885 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
9888 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
9889 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
9891 if (dpll
& PLL_P2_DIVIDE_BY_4
)
9897 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
9901 * This value includes pixel_multiplier. We will use
9902 * port_clock to compute adjusted_mode.crtc_clock in the
9903 * encoder's get_config() function.
9905 pipe_config
->port_clock
= port_clock
;
9908 int intel_dotclock_calculate(int link_freq
,
9909 const struct intel_link_m_n
*m_n
)
9912 * The calculation for the data clock is:
9913 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
9914 * But we want to avoid losing precison if possible, so:
9915 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
9917 * and the link clock is simpler:
9918 * link_clock = (m * link_clock) / n
9924 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
9927 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
9928 struct intel_crtc_state
*pipe_config
)
9930 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9932 /* read out port_clock from the DPLL */
9933 i9xx_crtc_clock_get(crtc
, pipe_config
);
9936 * In case there is an active pipe without active ports,
9937 * we may need some idea for the dotclock anyway.
9938 * Calculate one based on the FDI configuration.
9940 pipe_config
->base
.adjusted_mode
.crtc_clock
=
9941 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
9942 &pipe_config
->fdi_m_n
);
9945 /** Returns the currently programmed mode of the given pipe. */
9946 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
9947 struct drm_crtc
*crtc
)
9949 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9950 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9951 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
9952 struct drm_display_mode
*mode
;
9953 struct intel_crtc_state
*pipe_config
;
9954 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
9955 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
9956 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
9957 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
9958 enum pipe pipe
= intel_crtc
->pipe
;
9960 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
9964 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
9971 * Construct a pipe_config sufficient for getting the clock info
9972 * back out of crtc_clock_get.
9974 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
9975 * to use a real value here instead.
9977 pipe_config
->cpu_transcoder
= (enum transcoder
) pipe
;
9978 pipe_config
->pixel_multiplier
= 1;
9979 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
9980 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
9981 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
9982 i9xx_crtc_clock_get(intel_crtc
, pipe_config
);
9984 mode
->clock
= pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
9985 mode
->hdisplay
= (htot
& 0xffff) + 1;
9986 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
9987 mode
->hsync_start
= (hsync
& 0xffff) + 1;
9988 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
9989 mode
->vdisplay
= (vtot
& 0xffff) + 1;
9990 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
9991 mode
->vsync_start
= (vsync
& 0xffff) + 1;
9992 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
9994 drm_mode_set_name(mode
);
10001 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
10003 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10005 drm_crtc_cleanup(crtc
);
10010 * intel_wm_need_update - Check whether watermarks need updating
10011 * @plane: drm plane
10012 * @state: new plane state
10014 * Check current plane state versus the new one to determine whether
10015 * watermarks need to be recalculated.
10017 * Returns true or false.
10019 static bool intel_wm_need_update(struct drm_plane
*plane
,
10020 struct drm_plane_state
*state
)
10022 struct intel_plane_state
*new = to_intel_plane_state(state
);
10023 struct intel_plane_state
*cur
= to_intel_plane_state(plane
->state
);
10025 /* Update watermarks on tiling or size changes. */
10026 if (new->base
.visible
!= cur
->base
.visible
)
10029 if (!cur
->base
.fb
|| !new->base
.fb
)
10032 if (cur
->base
.fb
->modifier
!= new->base
.fb
->modifier
||
10033 cur
->base
.rotation
!= new->base
.rotation
||
10034 drm_rect_width(&new->base
.src
) != drm_rect_width(&cur
->base
.src
) ||
10035 drm_rect_height(&new->base
.src
) != drm_rect_height(&cur
->base
.src
) ||
10036 drm_rect_width(&new->base
.dst
) != drm_rect_width(&cur
->base
.dst
) ||
10037 drm_rect_height(&new->base
.dst
) != drm_rect_height(&cur
->base
.dst
))
10043 static bool needs_scaling(struct intel_plane_state
*state
)
10045 int src_w
= drm_rect_width(&state
->base
.src
) >> 16;
10046 int src_h
= drm_rect_height(&state
->base
.src
) >> 16;
10047 int dst_w
= drm_rect_width(&state
->base
.dst
);
10048 int dst_h
= drm_rect_height(&state
->base
.dst
);
10050 return (src_w
!= dst_w
|| src_h
!= dst_h
);
10053 int intel_plane_atomic_calc_changes(struct drm_crtc_state
*crtc_state
,
10054 struct drm_plane_state
*plane_state
)
10056 struct intel_crtc_state
*pipe_config
= to_intel_crtc_state(crtc_state
);
10057 struct drm_crtc
*crtc
= crtc_state
->crtc
;
10058 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10059 struct intel_plane
*plane
= to_intel_plane(plane_state
->plane
);
10060 struct drm_device
*dev
= crtc
->dev
;
10061 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10062 struct intel_plane_state
*old_plane_state
=
10063 to_intel_plane_state(plane
->base
.state
);
10064 bool mode_changed
= needs_modeset(crtc_state
);
10065 bool was_crtc_enabled
= crtc
->state
->active
;
10066 bool is_crtc_enabled
= crtc_state
->active
;
10067 bool turn_off
, turn_on
, visible
, was_visible
;
10068 struct drm_framebuffer
*fb
= plane_state
->fb
;
10071 if (INTEL_GEN(dev_priv
) >= 9 && plane
->id
!= PLANE_CURSOR
) {
10072 ret
= skl_update_scaler_plane(
10073 to_intel_crtc_state(crtc_state
),
10074 to_intel_plane_state(plane_state
));
10079 was_visible
= old_plane_state
->base
.visible
;
10080 visible
= plane_state
->visible
;
10082 if (!was_crtc_enabled
&& WARN_ON(was_visible
))
10083 was_visible
= false;
10086 * Visibility is calculated as if the crtc was on, but
10087 * after scaler setup everything depends on it being off
10088 * when the crtc isn't active.
10090 * FIXME this is wrong for watermarks. Watermarks should also
10091 * be computed as if the pipe would be active. Perhaps move
10092 * per-plane wm computation to the .check_plane() hook, and
10093 * only combine the results from all planes in the current place?
10095 if (!is_crtc_enabled
) {
10096 plane_state
->visible
= visible
= false;
10097 to_intel_crtc_state(crtc_state
)->active_planes
&= ~BIT(plane
->id
);
10100 if (!was_visible
&& !visible
)
10103 if (fb
!= old_plane_state
->base
.fb
)
10104 pipe_config
->fb_changed
= true;
10106 turn_off
= was_visible
&& (!visible
|| mode_changed
);
10107 turn_on
= visible
&& (!was_visible
|| mode_changed
);
10109 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
10110 intel_crtc
->base
.base
.id
, intel_crtc
->base
.name
,
10111 plane
->base
.base
.id
, plane
->base
.name
,
10112 fb
? fb
->base
.id
: -1);
10114 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
10115 plane
->base
.base
.id
, plane
->base
.name
,
10116 was_visible
, visible
,
10117 turn_off
, turn_on
, mode_changed
);
10120 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
))
10121 pipe_config
->update_wm_pre
= true;
10123 /* must disable cxsr around plane enable/disable */
10124 if (plane
->id
!= PLANE_CURSOR
)
10125 pipe_config
->disable_cxsr
= true;
10126 } else if (turn_off
) {
10127 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
))
10128 pipe_config
->update_wm_post
= true;
10130 /* must disable cxsr around plane enable/disable */
10131 if (plane
->id
!= PLANE_CURSOR
)
10132 pipe_config
->disable_cxsr
= true;
10133 } else if (intel_wm_need_update(&plane
->base
, plane_state
)) {
10134 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
)) {
10135 /* FIXME bollocks */
10136 pipe_config
->update_wm_pre
= true;
10137 pipe_config
->update_wm_post
= true;
10141 if (visible
|| was_visible
)
10142 pipe_config
->fb_bits
|= plane
->frontbuffer_bit
;
10145 * WaCxSRDisabledForSpriteScaling:ivb
10147 * cstate->update_wm was already set above, so this flag will
10148 * take effect when we commit and program watermarks.
10150 if (plane
->id
== PLANE_SPRITE0
&& IS_IVYBRIDGE(dev_priv
) &&
10151 needs_scaling(to_intel_plane_state(plane_state
)) &&
10152 !needs_scaling(old_plane_state
))
10153 pipe_config
->disable_lp_wm
= true;
10158 static bool encoders_cloneable(const struct intel_encoder
*a
,
10159 const struct intel_encoder
*b
)
10161 /* masks could be asymmetric, so check both ways */
10162 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
10163 b
->cloneable
& (1 << a
->type
));
10166 static bool check_single_encoder_cloning(struct drm_atomic_state
*state
,
10167 struct intel_crtc
*crtc
,
10168 struct intel_encoder
*encoder
)
10170 struct intel_encoder
*source_encoder
;
10171 struct drm_connector
*connector
;
10172 struct drm_connector_state
*connector_state
;
10175 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10176 if (connector_state
->crtc
!= &crtc
->base
)
10180 to_intel_encoder(connector_state
->best_encoder
);
10181 if (!encoders_cloneable(encoder
, source_encoder
))
10188 static int intel_crtc_atomic_check(struct drm_crtc
*crtc
,
10189 struct drm_crtc_state
*crtc_state
)
10191 struct drm_device
*dev
= crtc
->dev
;
10192 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10193 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10194 struct intel_crtc_state
*pipe_config
=
10195 to_intel_crtc_state(crtc_state
);
10196 struct drm_atomic_state
*state
= crtc_state
->state
;
10198 bool mode_changed
= needs_modeset(crtc_state
);
10200 if (mode_changed
&& !crtc_state
->active
)
10201 pipe_config
->update_wm_post
= true;
10203 if (mode_changed
&& crtc_state
->enable
&&
10204 dev_priv
->display
.crtc_compute_clock
&&
10205 !WARN_ON(pipe_config
->shared_dpll
)) {
10206 ret
= dev_priv
->display
.crtc_compute_clock(intel_crtc
,
10212 if (crtc_state
->color_mgmt_changed
) {
10213 ret
= intel_color_check(crtc
, crtc_state
);
10218 * Changing color management on Intel hardware is
10219 * handled as part of planes update.
10221 crtc_state
->planes_changed
= true;
10225 if (dev_priv
->display
.compute_pipe_wm
) {
10226 ret
= dev_priv
->display
.compute_pipe_wm(pipe_config
);
10228 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
10233 if (dev_priv
->display
.compute_intermediate_wm
&&
10234 !to_intel_atomic_state(state
)->skip_intermediate_wm
) {
10235 if (WARN_ON(!dev_priv
->display
.compute_pipe_wm
))
10239 * Calculate 'intermediate' watermarks that satisfy both the
10240 * old state and the new state. We can program these
10243 ret
= dev_priv
->display
.compute_intermediate_wm(dev
,
10247 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
10250 } else if (dev_priv
->display
.compute_intermediate_wm
) {
10251 if (HAS_PCH_SPLIT(dev_priv
) && INTEL_GEN(dev_priv
) < 9)
10252 pipe_config
->wm
.ilk
.intermediate
= pipe_config
->wm
.ilk
.optimal
;
10255 if (INTEL_GEN(dev_priv
) >= 9) {
10257 ret
= skl_update_scaler_crtc(pipe_config
);
10260 ret
= skl_check_pipe_max_pixel_rate(intel_crtc
,
10263 ret
= intel_atomic_setup_scalers(dev_priv
, intel_crtc
,
10270 static const struct drm_crtc_helper_funcs intel_helper_funcs
= {
10271 .atomic_begin
= intel_begin_crtc_commit
,
10272 .atomic_flush
= intel_finish_crtc_commit
,
10273 .atomic_check
= intel_crtc_atomic_check
,
10276 static void intel_modeset_update_connector_atomic_state(struct drm_device
*dev
)
10278 struct intel_connector
*connector
;
10279 struct drm_connector_list_iter conn_iter
;
10281 drm_connector_list_iter_begin(dev
, &conn_iter
);
10282 for_each_intel_connector_iter(connector
, &conn_iter
) {
10283 if (connector
->base
.state
->crtc
)
10284 drm_connector_unreference(&connector
->base
);
10286 if (connector
->base
.encoder
) {
10287 connector
->base
.state
->best_encoder
=
10288 connector
->base
.encoder
;
10289 connector
->base
.state
->crtc
=
10290 connector
->base
.encoder
->crtc
;
10292 drm_connector_reference(&connector
->base
);
10294 connector
->base
.state
->best_encoder
= NULL
;
10295 connector
->base
.state
->crtc
= NULL
;
10298 drm_connector_list_iter_end(&conn_iter
);
10302 connected_sink_compute_bpp(struct intel_connector
*connector
,
10303 struct intel_crtc_state
*pipe_config
)
10305 const struct drm_display_info
*info
= &connector
->base
.display_info
;
10306 int bpp
= pipe_config
->pipe_bpp
;
10308 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
10309 connector
->base
.base
.id
,
10310 connector
->base
.name
);
10312 /* Don't use an invalid EDID bpc value */
10313 if (info
->bpc
!= 0 && info
->bpc
* 3 < bpp
) {
10314 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
10315 bpp
, info
->bpc
* 3);
10316 pipe_config
->pipe_bpp
= info
->bpc
* 3;
10319 /* Clamp bpp to 8 on screens without EDID 1.4 */
10320 if (info
->bpc
== 0 && bpp
> 24) {
10321 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
10323 pipe_config
->pipe_bpp
= 24;
10328 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
10329 struct intel_crtc_state
*pipe_config
)
10331 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
10332 struct drm_atomic_state
*state
;
10333 struct drm_connector
*connector
;
10334 struct drm_connector_state
*connector_state
;
10337 if ((IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
10338 IS_CHERRYVIEW(dev_priv
)))
10340 else if (INTEL_GEN(dev_priv
) >= 5)
10346 pipe_config
->pipe_bpp
= bpp
;
10348 state
= pipe_config
->base
.state
;
10350 /* Clamp display bpp to EDID value */
10351 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10352 if (connector_state
->crtc
!= &crtc
->base
)
10355 connected_sink_compute_bpp(to_intel_connector(connector
),
10362 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
10364 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
10365 "type: 0x%x flags: 0x%x\n",
10367 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
10368 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
10369 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
10370 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
10374 intel_dump_m_n_config(struct intel_crtc_state
*pipe_config
, char *id
,
10375 unsigned int lane_count
, struct intel_link_m_n
*m_n
)
10377 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10379 m_n
->gmch_m
, m_n
->gmch_n
,
10380 m_n
->link_m
, m_n
->link_n
, m_n
->tu
);
10383 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
10384 struct intel_crtc_state
*pipe_config
,
10385 const char *context
)
10387 struct drm_device
*dev
= crtc
->base
.dev
;
10388 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10389 struct drm_plane
*plane
;
10390 struct intel_plane
*intel_plane
;
10391 struct intel_plane_state
*state
;
10392 struct drm_framebuffer
*fb
;
10394 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
10395 crtc
->base
.base
.id
, crtc
->base
.name
, context
);
10397 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
10398 transcoder_name(pipe_config
->cpu_transcoder
),
10399 pipe_config
->pipe_bpp
, pipe_config
->dither
);
10401 if (pipe_config
->has_pch_encoder
)
10402 intel_dump_m_n_config(pipe_config
, "fdi",
10403 pipe_config
->fdi_lanes
,
10404 &pipe_config
->fdi_m_n
);
10406 if (intel_crtc_has_dp_encoder(pipe_config
)) {
10407 intel_dump_m_n_config(pipe_config
, "dp m_n",
10408 pipe_config
->lane_count
, &pipe_config
->dp_m_n
);
10409 if (pipe_config
->has_drrs
)
10410 intel_dump_m_n_config(pipe_config
, "dp m2_n2",
10411 pipe_config
->lane_count
,
10412 &pipe_config
->dp_m2_n2
);
10415 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
10416 pipe_config
->has_audio
, pipe_config
->has_infoframe
);
10418 DRM_DEBUG_KMS("requested mode:\n");
10419 drm_mode_debug_printmodeline(&pipe_config
->base
.mode
);
10420 DRM_DEBUG_KMS("adjusted mode:\n");
10421 drm_mode_debug_printmodeline(&pipe_config
->base
.adjusted_mode
);
10422 intel_dump_crtc_timings(&pipe_config
->base
.adjusted_mode
);
10423 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
10424 pipe_config
->port_clock
,
10425 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
,
10426 pipe_config
->pixel_rate
);
10428 if (INTEL_GEN(dev_priv
) >= 9)
10429 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
10431 pipe_config
->scaler_state
.scaler_users
,
10432 pipe_config
->scaler_state
.scaler_id
);
10434 if (HAS_GMCH_DISPLAY(dev_priv
))
10435 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
10436 pipe_config
->gmch_pfit
.control
,
10437 pipe_config
->gmch_pfit
.pgm_ratios
,
10438 pipe_config
->gmch_pfit
.lvds_border_bits
);
10440 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
10441 pipe_config
->pch_pfit
.pos
,
10442 pipe_config
->pch_pfit
.size
,
10443 enableddisabled(pipe_config
->pch_pfit
.enabled
));
10445 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
10446 pipe_config
->ips_enabled
, pipe_config
->double_wide
);
10448 intel_dpll_dump_hw_state(dev_priv
, &pipe_config
->dpll_hw_state
);
10450 DRM_DEBUG_KMS("planes on this crtc\n");
10451 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
10452 struct drm_format_name_buf format_name
;
10453 intel_plane
= to_intel_plane(plane
);
10454 if (intel_plane
->pipe
!= crtc
->pipe
)
10457 state
= to_intel_plane_state(plane
->state
);
10458 fb
= state
->base
.fb
;
10460 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
10461 plane
->base
.id
, plane
->name
, state
->scaler_id
);
10465 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
10466 plane
->base
.id
, plane
->name
,
10467 fb
->base
.id
, fb
->width
, fb
->height
,
10468 drm_get_format_name(fb
->format
->format
, &format_name
));
10469 if (INTEL_GEN(dev_priv
) >= 9)
10470 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
10472 state
->base
.src
.x1
>> 16,
10473 state
->base
.src
.y1
>> 16,
10474 drm_rect_width(&state
->base
.src
) >> 16,
10475 drm_rect_height(&state
->base
.src
) >> 16,
10476 state
->base
.dst
.x1
, state
->base
.dst
.y1
,
10477 drm_rect_width(&state
->base
.dst
),
10478 drm_rect_height(&state
->base
.dst
));
10482 static bool check_digital_port_conflicts(struct drm_atomic_state
*state
)
10484 struct drm_device
*dev
= state
->dev
;
10485 struct drm_connector
*connector
;
10486 struct drm_connector_list_iter conn_iter
;
10487 unsigned int used_ports
= 0;
10488 unsigned int used_mst_ports
= 0;
10491 * Walk the connector list instead of the encoder
10492 * list to detect the problem on ddi platforms
10493 * where there's just one encoder per digital port.
10495 drm_connector_list_iter_begin(dev
, &conn_iter
);
10496 drm_for_each_connector_iter(connector
, &conn_iter
) {
10497 struct drm_connector_state
*connector_state
;
10498 struct intel_encoder
*encoder
;
10500 connector_state
= drm_atomic_get_existing_connector_state(state
, connector
);
10501 if (!connector_state
)
10502 connector_state
= connector
->state
;
10504 if (!connector_state
->best_encoder
)
10507 encoder
= to_intel_encoder(connector_state
->best_encoder
);
10509 WARN_ON(!connector_state
->crtc
);
10511 switch (encoder
->type
) {
10512 unsigned int port_mask
;
10513 case INTEL_OUTPUT_UNKNOWN
:
10514 if (WARN_ON(!HAS_DDI(to_i915(dev
))))
10516 case INTEL_OUTPUT_DP
:
10517 case INTEL_OUTPUT_HDMI
:
10518 case INTEL_OUTPUT_EDP
:
10519 port_mask
= 1 << enc_to_dig_port(&encoder
->base
)->port
;
10521 /* the same port mustn't appear more than once */
10522 if (used_ports
& port_mask
)
10525 used_ports
|= port_mask
;
10527 case INTEL_OUTPUT_DP_MST
:
10529 1 << enc_to_mst(&encoder
->base
)->primary
->port
;
10535 drm_connector_list_iter_end(&conn_iter
);
10537 /* can't mix MST and SST/HDMI on the same port */
10538 if (used_ports
& used_mst_ports
)
10545 clear_intel_crtc_state(struct intel_crtc_state
*crtc_state
)
10547 struct drm_i915_private
*dev_priv
=
10548 to_i915(crtc_state
->base
.crtc
->dev
);
10549 struct intel_crtc_scaler_state scaler_state
;
10550 struct intel_dpll_hw_state dpll_hw_state
;
10551 struct intel_shared_dpll
*shared_dpll
;
10552 struct intel_crtc_wm_state wm_state
;
10555 /* FIXME: before the switch to atomic started, a new pipe_config was
10556 * kzalloc'd. Code that depends on any field being zero should be
10557 * fixed, so that the crtc_state can be safely duplicated. For now,
10558 * only fields that are know to not cause problems are preserved. */
10560 scaler_state
= crtc_state
->scaler_state
;
10561 shared_dpll
= crtc_state
->shared_dpll
;
10562 dpll_hw_state
= crtc_state
->dpll_hw_state
;
10563 force_thru
= crtc_state
->pch_pfit
.force_thru
;
10564 if (IS_G4X(dev_priv
) ||
10565 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
10566 wm_state
= crtc_state
->wm
;
10568 /* Keep base drm_crtc_state intact, only clear our extended struct */
10569 BUILD_BUG_ON(offsetof(struct intel_crtc_state
, base
));
10570 memset(&crtc_state
->base
+ 1, 0,
10571 sizeof(*crtc_state
) - sizeof(crtc_state
->base
));
10573 crtc_state
->scaler_state
= scaler_state
;
10574 crtc_state
->shared_dpll
= shared_dpll
;
10575 crtc_state
->dpll_hw_state
= dpll_hw_state
;
10576 crtc_state
->pch_pfit
.force_thru
= force_thru
;
10577 if (IS_G4X(dev_priv
) ||
10578 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
10579 crtc_state
->wm
= wm_state
;
10583 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
10584 struct intel_crtc_state
*pipe_config
)
10586 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
10587 struct intel_encoder
*encoder
;
10588 struct drm_connector
*connector
;
10589 struct drm_connector_state
*connector_state
;
10590 int base_bpp
, ret
= -EINVAL
;
10594 clear_intel_crtc_state(pipe_config
);
10596 pipe_config
->cpu_transcoder
=
10597 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
10600 * Sanitize sync polarity flags based on requested ones. If neither
10601 * positive or negative polarity is requested, treat this as meaning
10602 * negative polarity.
10604 if (!(pipe_config
->base
.adjusted_mode
.flags
&
10605 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
10606 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
10608 if (!(pipe_config
->base
.adjusted_mode
.flags
&
10609 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
10610 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
10612 base_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
10618 * Determine the real pipe dimensions. Note that stereo modes can
10619 * increase the actual pipe size due to the frame doubling and
10620 * insertion of additional space for blanks between the frame. This
10621 * is stored in the crtc timings. We use the requested mode to do this
10622 * computation to clearly distinguish it from the adjusted mode, which
10623 * can be changed by the connectors in the below retry loop.
10625 drm_mode_get_hv_timing(&pipe_config
->base
.mode
,
10626 &pipe_config
->pipe_src_w
,
10627 &pipe_config
->pipe_src_h
);
10629 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10630 if (connector_state
->crtc
!= crtc
)
10633 encoder
= to_intel_encoder(connector_state
->best_encoder
);
10635 if (!check_single_encoder_cloning(state
, to_intel_crtc(crtc
), encoder
)) {
10636 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
10641 * Determine output_types before calling the .compute_config()
10642 * hooks so that the hooks can use this information safely.
10644 pipe_config
->output_types
|= 1 << encoder
->type
;
10648 /* Ensure the port clock defaults are reset when retrying. */
10649 pipe_config
->port_clock
= 0;
10650 pipe_config
->pixel_multiplier
= 1;
10652 /* Fill in default crtc timings, allow encoders to overwrite them. */
10653 drm_mode_set_crtcinfo(&pipe_config
->base
.adjusted_mode
,
10654 CRTC_STEREO_DOUBLE
);
10656 /* Pass our mode to the connectors and the CRTC to give them a chance to
10657 * adjust it according to limitations or connector properties, and also
10658 * a chance to reject the mode entirely.
10660 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10661 if (connector_state
->crtc
!= crtc
)
10664 encoder
= to_intel_encoder(connector_state
->best_encoder
);
10666 if (!(encoder
->compute_config(encoder
, pipe_config
, connector_state
))) {
10667 DRM_DEBUG_KMS("Encoder config failure\n");
10672 /* Set default port clock if not overwritten by the encoder. Needs to be
10673 * done afterwards in case the encoder adjusts the mode. */
10674 if (!pipe_config
->port_clock
)
10675 pipe_config
->port_clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
10676 * pipe_config
->pixel_multiplier
;
10678 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
10680 DRM_DEBUG_KMS("CRTC fixup failed\n");
10684 if (ret
== RETRY
) {
10685 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
10690 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
10692 goto encoder_retry
;
10695 /* Dithering seems to not pass-through bits correctly when it should, so
10696 * only enable it on 6bpc panels and when its not a compliance
10697 * test requesting 6bpc video pattern.
10699 pipe_config
->dither
= (pipe_config
->pipe_bpp
== 6*3) &&
10700 !pipe_config
->dither_force_disable
;
10701 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
10702 base_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
10709 intel_modeset_update_crtc_state(struct drm_atomic_state
*state
)
10711 struct drm_crtc
*crtc
;
10712 struct drm_crtc_state
*new_crtc_state
;
10715 /* Double check state. */
10716 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
10717 to_intel_crtc(crtc
)->config
= to_intel_crtc_state(new_crtc_state
);
10720 * Update legacy state to satisfy fbc code. This can
10721 * be removed when fbc uses the atomic state.
10723 if (drm_atomic_get_existing_plane_state(state
, crtc
->primary
)) {
10724 struct drm_plane_state
*plane_state
= crtc
->primary
->state
;
10726 crtc
->primary
->fb
= plane_state
->fb
;
10727 crtc
->x
= plane_state
->src_x
>> 16;
10728 crtc
->y
= plane_state
->src_y
>> 16;
10733 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
10737 if (clock1
== clock2
)
10740 if (!clock1
|| !clock2
)
10743 diff
= abs(clock1
- clock2
);
10745 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
10752 intel_compare_m_n(unsigned int m
, unsigned int n
,
10753 unsigned int m2
, unsigned int n2
,
10756 if (m
== m2
&& n
== n2
)
10759 if (exact
|| !m
|| !n
|| !m2
|| !n2
)
10762 BUILD_BUG_ON(DATA_LINK_M_N_MASK
> INT_MAX
);
10769 } else if (n
< n2
) {
10779 return intel_fuzzy_clock_check(m
, m2
);
10783 intel_compare_link_m_n(const struct intel_link_m_n
*m_n
,
10784 struct intel_link_m_n
*m2_n2
,
10787 if (m_n
->tu
== m2_n2
->tu
&&
10788 intel_compare_m_n(m_n
->gmch_m
, m_n
->gmch_n
,
10789 m2_n2
->gmch_m
, m2_n2
->gmch_n
, !adjust
) &&
10790 intel_compare_m_n(m_n
->link_m
, m_n
->link_n
,
10791 m2_n2
->link_m
, m2_n2
->link_n
, !adjust
)) {
10801 static void __printf(3, 4)
10802 pipe_config_err(bool adjust
, const char *name
, const char *format
, ...)
10805 unsigned int category
;
10806 struct va_format vaf
;
10810 level
= KERN_DEBUG
;
10811 category
= DRM_UT_KMS
;
10814 category
= DRM_UT_NONE
;
10817 va_start(args
, format
);
10821 drm_printk(level
, category
, "mismatch in %s %pV", name
, &vaf
);
10827 intel_pipe_config_compare(struct drm_i915_private
*dev_priv
,
10828 struct intel_crtc_state
*current_config
,
10829 struct intel_crtc_state
*pipe_config
,
10834 #define PIPE_CONF_CHECK_X(name) \
10835 if (current_config->name != pipe_config->name) { \
10836 pipe_config_err(adjust, __stringify(name), \
10837 "(expected 0x%08x, found 0x%08x)\n", \
10838 current_config->name, \
10839 pipe_config->name); \
10843 #define PIPE_CONF_CHECK_I(name) \
10844 if (current_config->name != pipe_config->name) { \
10845 pipe_config_err(adjust, __stringify(name), \
10846 "(expected %i, found %i)\n", \
10847 current_config->name, \
10848 pipe_config->name); \
10852 #define PIPE_CONF_CHECK_P(name) \
10853 if (current_config->name != pipe_config->name) { \
10854 pipe_config_err(adjust, __stringify(name), \
10855 "(expected %p, found %p)\n", \
10856 current_config->name, \
10857 pipe_config->name); \
10861 #define PIPE_CONF_CHECK_M_N(name) \
10862 if (!intel_compare_link_m_n(¤t_config->name, \
10863 &pipe_config->name,\
10865 pipe_config_err(adjust, __stringify(name), \
10866 "(expected tu %i gmch %i/%i link %i/%i, " \
10867 "found tu %i, gmch %i/%i link %i/%i)\n", \
10868 current_config->name.tu, \
10869 current_config->name.gmch_m, \
10870 current_config->name.gmch_n, \
10871 current_config->name.link_m, \
10872 current_config->name.link_n, \
10873 pipe_config->name.tu, \
10874 pipe_config->name.gmch_m, \
10875 pipe_config->name.gmch_n, \
10876 pipe_config->name.link_m, \
10877 pipe_config->name.link_n); \
10881 /* This is required for BDW+ where there is only one set of registers for
10882 * switching between high and low RR.
10883 * This macro can be used whenever a comparison has to be made between one
10884 * hw state and multiple sw state variables.
10886 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \
10887 if (!intel_compare_link_m_n(¤t_config->name, \
10888 &pipe_config->name, adjust) && \
10889 !intel_compare_link_m_n(¤t_config->alt_name, \
10890 &pipe_config->name, adjust)) { \
10891 pipe_config_err(adjust, __stringify(name), \
10892 "(expected tu %i gmch %i/%i link %i/%i, " \
10893 "or tu %i gmch %i/%i link %i/%i, " \
10894 "found tu %i, gmch %i/%i link %i/%i)\n", \
10895 current_config->name.tu, \
10896 current_config->name.gmch_m, \
10897 current_config->name.gmch_n, \
10898 current_config->name.link_m, \
10899 current_config->name.link_n, \
10900 current_config->alt_name.tu, \
10901 current_config->alt_name.gmch_m, \
10902 current_config->alt_name.gmch_n, \
10903 current_config->alt_name.link_m, \
10904 current_config->alt_name.link_n, \
10905 pipe_config->name.tu, \
10906 pipe_config->name.gmch_m, \
10907 pipe_config->name.gmch_n, \
10908 pipe_config->name.link_m, \
10909 pipe_config->name.link_n); \
10913 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
10914 if ((current_config->name ^ pipe_config->name) & (mask)) { \
10915 pipe_config_err(adjust, __stringify(name), \
10916 "(%x) (expected %i, found %i)\n", \
10918 current_config->name & (mask), \
10919 pipe_config->name & (mask)); \
10923 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
10924 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
10925 pipe_config_err(adjust, __stringify(name), \
10926 "(expected %i, found %i)\n", \
10927 current_config->name, \
10928 pipe_config->name); \
10932 #define PIPE_CONF_QUIRK(quirk) \
10933 ((current_config->quirks | pipe_config->quirks) & (quirk))
10935 PIPE_CONF_CHECK_I(cpu_transcoder
);
10937 PIPE_CONF_CHECK_I(has_pch_encoder
);
10938 PIPE_CONF_CHECK_I(fdi_lanes
);
10939 PIPE_CONF_CHECK_M_N(fdi_m_n
);
10941 PIPE_CONF_CHECK_I(lane_count
);
10942 PIPE_CONF_CHECK_X(lane_lat_optim_mask
);
10944 if (INTEL_GEN(dev_priv
) < 8) {
10945 PIPE_CONF_CHECK_M_N(dp_m_n
);
10947 if (current_config
->has_drrs
)
10948 PIPE_CONF_CHECK_M_N(dp_m2_n2
);
10950 PIPE_CONF_CHECK_M_N_ALT(dp_m_n
, dp_m2_n2
);
10952 PIPE_CONF_CHECK_X(output_types
);
10954 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hdisplay
);
10955 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_htotal
);
10956 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_start
);
10957 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_end
);
10958 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_start
);
10959 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_end
);
10961 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vdisplay
);
10962 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vtotal
);
10963 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_start
);
10964 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_end
);
10965 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_start
);
10966 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_end
);
10968 PIPE_CONF_CHECK_I(pixel_multiplier
);
10969 PIPE_CONF_CHECK_I(has_hdmi_sink
);
10970 if ((INTEL_GEN(dev_priv
) < 8 && !IS_HASWELL(dev_priv
)) ||
10971 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
10972 PIPE_CONF_CHECK_I(limited_color_range
);
10974 PIPE_CONF_CHECK_I(hdmi_scrambling
);
10975 PIPE_CONF_CHECK_I(hdmi_high_tmds_clock_ratio
);
10976 PIPE_CONF_CHECK_I(has_infoframe
);
10978 PIPE_CONF_CHECK_I(has_audio
);
10980 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
10981 DRM_MODE_FLAG_INTERLACE
);
10983 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
10984 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
10985 DRM_MODE_FLAG_PHSYNC
);
10986 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
10987 DRM_MODE_FLAG_NHSYNC
);
10988 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
10989 DRM_MODE_FLAG_PVSYNC
);
10990 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
10991 DRM_MODE_FLAG_NVSYNC
);
10994 PIPE_CONF_CHECK_X(gmch_pfit
.control
);
10995 /* pfit ratios are autocomputed by the hw on gen4+ */
10996 if (INTEL_GEN(dev_priv
) < 4)
10997 PIPE_CONF_CHECK_X(gmch_pfit
.pgm_ratios
);
10998 PIPE_CONF_CHECK_X(gmch_pfit
.lvds_border_bits
);
11001 PIPE_CONF_CHECK_I(pipe_src_w
);
11002 PIPE_CONF_CHECK_I(pipe_src_h
);
11004 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
11005 if (current_config
->pch_pfit
.enabled
) {
11006 PIPE_CONF_CHECK_X(pch_pfit
.pos
);
11007 PIPE_CONF_CHECK_X(pch_pfit
.size
);
11010 PIPE_CONF_CHECK_I(scaler_state
.scaler_id
);
11011 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate
);
11014 /* BDW+ don't expose a synchronous way to read the state */
11015 if (IS_HASWELL(dev_priv
))
11016 PIPE_CONF_CHECK_I(ips_enabled
);
11018 PIPE_CONF_CHECK_I(double_wide
);
11020 PIPE_CONF_CHECK_P(shared_dpll
);
11021 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
11022 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
11023 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
11024 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
11025 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
11026 PIPE_CONF_CHECK_X(dpll_hw_state
.spll
);
11027 PIPE_CONF_CHECK_X(dpll_hw_state
.ctrl1
);
11028 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr1
);
11029 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr2
);
11031 PIPE_CONF_CHECK_X(dsi_pll
.ctrl
);
11032 PIPE_CONF_CHECK_X(dsi_pll
.div
);
11034 if (IS_G4X(dev_priv
) || INTEL_GEN(dev_priv
) >= 5)
11035 PIPE_CONF_CHECK_I(pipe_bpp
);
11037 PIPE_CONF_CHECK_CLOCK_FUZZY(base
.adjusted_mode
.crtc_clock
);
11038 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
11040 #undef PIPE_CONF_CHECK_X
11041 #undef PIPE_CONF_CHECK_I
11042 #undef PIPE_CONF_CHECK_P
11043 #undef PIPE_CONF_CHECK_FLAGS
11044 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
11045 #undef PIPE_CONF_QUIRK
11050 static void intel_pipe_config_sanity_check(struct drm_i915_private
*dev_priv
,
11051 const struct intel_crtc_state
*pipe_config
)
11053 if (pipe_config
->has_pch_encoder
) {
11054 int fdi_dotclock
= intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
11055 &pipe_config
->fdi_m_n
);
11056 int dotclock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
11059 * FDI already provided one idea for the dotclock.
11060 * Yell if the encoder disagrees.
11062 WARN(!intel_fuzzy_clock_check(fdi_dotclock
, dotclock
),
11063 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11064 fdi_dotclock
, dotclock
);
11068 static void verify_wm_state(struct drm_crtc
*crtc
,
11069 struct drm_crtc_state
*new_state
)
11071 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
11072 struct skl_ddb_allocation hw_ddb
, *sw_ddb
;
11073 struct skl_pipe_wm hw_wm
, *sw_wm
;
11074 struct skl_plane_wm
*hw_plane_wm
, *sw_plane_wm
;
11075 struct skl_ddb_entry
*hw_ddb_entry
, *sw_ddb_entry
;
11076 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11077 const enum pipe pipe
= intel_crtc
->pipe
;
11078 int plane
, level
, max_level
= ilk_wm_max_level(dev_priv
);
11080 if (INTEL_GEN(dev_priv
) < 9 || !new_state
->active
)
11083 skl_pipe_wm_get_hw_state(crtc
, &hw_wm
);
11084 sw_wm
= &to_intel_crtc_state(new_state
)->wm
.skl
.optimal
;
11086 skl_ddb_get_hw_state(dev_priv
, &hw_ddb
);
11087 sw_ddb
= &dev_priv
->wm
.skl_hw
.ddb
;
11090 for_each_universal_plane(dev_priv
, pipe
, plane
) {
11091 hw_plane_wm
= &hw_wm
.planes
[plane
];
11092 sw_plane_wm
= &sw_wm
->planes
[plane
];
11095 for (level
= 0; level
<= max_level
; level
++) {
11096 if (skl_wm_level_equals(&hw_plane_wm
->wm
[level
],
11097 &sw_plane_wm
->wm
[level
]))
11100 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",
11101 pipe_name(pipe
), plane
+ 1, level
,
11102 sw_plane_wm
->wm
[level
].plane_en
,
11103 sw_plane_wm
->wm
[level
].plane_res_b
,
11104 sw_plane_wm
->wm
[level
].plane_res_l
,
11105 hw_plane_wm
->wm
[level
].plane_en
,
11106 hw_plane_wm
->wm
[level
].plane_res_b
,
11107 hw_plane_wm
->wm
[level
].plane_res_l
);
11110 if (!skl_wm_level_equals(&hw_plane_wm
->trans_wm
,
11111 &sw_plane_wm
->trans_wm
)) {
11112 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",
11113 pipe_name(pipe
), plane
+ 1,
11114 sw_plane_wm
->trans_wm
.plane_en
,
11115 sw_plane_wm
->trans_wm
.plane_res_b
,
11116 sw_plane_wm
->trans_wm
.plane_res_l
,
11117 hw_plane_wm
->trans_wm
.plane_en
,
11118 hw_plane_wm
->trans_wm
.plane_res_b
,
11119 hw_plane_wm
->trans_wm
.plane_res_l
);
11123 hw_ddb_entry
= &hw_ddb
.plane
[pipe
][plane
];
11124 sw_ddb_entry
= &sw_ddb
->plane
[pipe
][plane
];
11126 if (!skl_ddb_entry_equal(hw_ddb_entry
, sw_ddb_entry
)) {
11127 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
11128 pipe_name(pipe
), plane
+ 1,
11129 sw_ddb_entry
->start
, sw_ddb_entry
->end
,
11130 hw_ddb_entry
->start
, hw_ddb_entry
->end
);
11136 * If the cursor plane isn't active, we may not have updated it's ddb
11137 * allocation. In that case since the ddb allocation will be updated
11138 * once the plane becomes visible, we can skip this check
11141 hw_plane_wm
= &hw_wm
.planes
[PLANE_CURSOR
];
11142 sw_plane_wm
= &sw_wm
->planes
[PLANE_CURSOR
];
11145 for (level
= 0; level
<= max_level
; level
++) {
11146 if (skl_wm_level_equals(&hw_plane_wm
->wm
[level
],
11147 &sw_plane_wm
->wm
[level
]))
11150 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",
11151 pipe_name(pipe
), level
,
11152 sw_plane_wm
->wm
[level
].plane_en
,
11153 sw_plane_wm
->wm
[level
].plane_res_b
,
11154 sw_plane_wm
->wm
[level
].plane_res_l
,
11155 hw_plane_wm
->wm
[level
].plane_en
,
11156 hw_plane_wm
->wm
[level
].plane_res_b
,
11157 hw_plane_wm
->wm
[level
].plane_res_l
);
11160 if (!skl_wm_level_equals(&hw_plane_wm
->trans_wm
,
11161 &sw_plane_wm
->trans_wm
)) {
11162 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11164 sw_plane_wm
->trans_wm
.plane_en
,
11165 sw_plane_wm
->trans_wm
.plane_res_b
,
11166 sw_plane_wm
->trans_wm
.plane_res_l
,
11167 hw_plane_wm
->trans_wm
.plane_en
,
11168 hw_plane_wm
->trans_wm
.plane_res_b
,
11169 hw_plane_wm
->trans_wm
.plane_res_l
);
11173 hw_ddb_entry
= &hw_ddb
.plane
[pipe
][PLANE_CURSOR
];
11174 sw_ddb_entry
= &sw_ddb
->plane
[pipe
][PLANE_CURSOR
];
11176 if (!skl_ddb_entry_equal(hw_ddb_entry
, sw_ddb_entry
)) {
11177 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
11179 sw_ddb_entry
->start
, sw_ddb_entry
->end
,
11180 hw_ddb_entry
->start
, hw_ddb_entry
->end
);
11186 verify_connector_state(struct drm_device
*dev
,
11187 struct drm_atomic_state
*state
,
11188 struct drm_crtc
*crtc
)
11190 struct drm_connector
*connector
;
11191 struct drm_connector_state
*new_conn_state
;
11194 for_each_new_connector_in_state(state
, connector
, new_conn_state
, i
) {
11195 struct drm_encoder
*encoder
= connector
->encoder
;
11196 struct drm_crtc_state
*crtc_state
= NULL
;
11198 if (new_conn_state
->crtc
!= crtc
)
11202 crtc_state
= drm_atomic_get_new_crtc_state(state
, new_conn_state
->crtc
);
11204 intel_connector_verify_state(crtc_state
, new_conn_state
);
11206 I915_STATE_WARN(new_conn_state
->best_encoder
!= encoder
,
11207 "connector's atomic encoder doesn't match legacy encoder\n");
11212 verify_encoder_state(struct drm_device
*dev
, struct drm_atomic_state
*state
)
11214 struct intel_encoder
*encoder
;
11215 struct drm_connector
*connector
;
11216 struct drm_connector_state
*old_conn_state
, *new_conn_state
;
11219 for_each_intel_encoder(dev
, encoder
) {
11220 bool enabled
= false, found
= false;
11223 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
11224 encoder
->base
.base
.id
,
11225 encoder
->base
.name
);
11227 for_each_oldnew_connector_in_state(state
, connector
, old_conn_state
,
11228 new_conn_state
, i
) {
11229 if (old_conn_state
->best_encoder
== &encoder
->base
)
11232 if (new_conn_state
->best_encoder
!= &encoder
->base
)
11234 found
= enabled
= true;
11236 I915_STATE_WARN(new_conn_state
->crtc
!=
11237 encoder
->base
.crtc
,
11238 "connector's crtc doesn't match encoder crtc\n");
11244 I915_STATE_WARN(!!encoder
->base
.crtc
!= enabled
,
11245 "encoder's enabled state mismatch "
11246 "(expected %i, found %i)\n",
11247 !!encoder
->base
.crtc
, enabled
);
11249 if (!encoder
->base
.crtc
) {
11252 active
= encoder
->get_hw_state(encoder
, &pipe
);
11253 I915_STATE_WARN(active
,
11254 "encoder detached but still enabled on pipe %c.\n",
11261 verify_crtc_state(struct drm_crtc
*crtc
,
11262 struct drm_crtc_state
*old_crtc_state
,
11263 struct drm_crtc_state
*new_crtc_state
)
11265 struct drm_device
*dev
= crtc
->dev
;
11266 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11267 struct intel_encoder
*encoder
;
11268 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11269 struct intel_crtc_state
*pipe_config
, *sw_config
;
11270 struct drm_atomic_state
*old_state
;
11273 old_state
= old_crtc_state
->state
;
11274 __drm_atomic_helper_crtc_destroy_state(old_crtc_state
);
11275 pipe_config
= to_intel_crtc_state(old_crtc_state
);
11276 memset(pipe_config
, 0, sizeof(*pipe_config
));
11277 pipe_config
->base
.crtc
= crtc
;
11278 pipe_config
->base
.state
= old_state
;
11280 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc
->base
.id
, crtc
->name
);
11282 active
= dev_priv
->display
.get_pipe_config(intel_crtc
, pipe_config
);
11284 /* we keep both pipes enabled on 830 */
11285 if (IS_I830(dev_priv
))
11286 active
= new_crtc_state
->active
;
11288 I915_STATE_WARN(new_crtc_state
->active
!= active
,
11289 "crtc active state doesn't match with hw state "
11290 "(expected %i, found %i)\n", new_crtc_state
->active
, active
);
11292 I915_STATE_WARN(intel_crtc
->active
!= new_crtc_state
->active
,
11293 "transitional active state does not match atomic hw state "
11294 "(expected %i, found %i)\n", new_crtc_state
->active
, intel_crtc
->active
);
11296 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
11299 active
= encoder
->get_hw_state(encoder
, &pipe
);
11300 I915_STATE_WARN(active
!= new_crtc_state
->active
,
11301 "[ENCODER:%i] active %i with crtc active %i\n",
11302 encoder
->base
.base
.id
, active
, new_crtc_state
->active
);
11304 I915_STATE_WARN(active
&& intel_crtc
->pipe
!= pipe
,
11305 "Encoder connected to wrong pipe %c\n",
11309 pipe_config
->output_types
|= 1 << encoder
->type
;
11310 encoder
->get_config(encoder
, pipe_config
);
11314 intel_crtc_compute_pixel_rate(pipe_config
);
11316 if (!new_crtc_state
->active
)
11319 intel_pipe_config_sanity_check(dev_priv
, pipe_config
);
11321 sw_config
= to_intel_crtc_state(new_crtc_state
);
11322 if (!intel_pipe_config_compare(dev_priv
, sw_config
,
11323 pipe_config
, false)) {
11324 I915_STATE_WARN(1, "pipe state doesn't match!\n");
11325 intel_dump_pipe_config(intel_crtc
, pipe_config
,
11327 intel_dump_pipe_config(intel_crtc
, sw_config
,
11333 verify_single_dpll_state(struct drm_i915_private
*dev_priv
,
11334 struct intel_shared_dpll
*pll
,
11335 struct drm_crtc
*crtc
,
11336 struct drm_crtc_state
*new_state
)
11338 struct intel_dpll_hw_state dpll_hw_state
;
11339 unsigned crtc_mask
;
11342 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
11344 DRM_DEBUG_KMS("%s\n", pll
->name
);
11346 active
= pll
->funcs
.get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
11348 if (!(pll
->flags
& INTEL_DPLL_ALWAYS_ON
)) {
11349 I915_STATE_WARN(!pll
->on
&& pll
->active_mask
,
11350 "pll in active use but not on in sw tracking\n");
11351 I915_STATE_WARN(pll
->on
&& !pll
->active_mask
,
11352 "pll is on but not used by any active crtc\n");
11353 I915_STATE_WARN(pll
->on
!= active
,
11354 "pll on state mismatch (expected %i, found %i)\n",
11359 I915_STATE_WARN(pll
->active_mask
& ~pll
->state
.crtc_mask
,
11360 "more active pll users than references: %x vs %x\n",
11361 pll
->active_mask
, pll
->state
.crtc_mask
);
11366 crtc_mask
= 1 << drm_crtc_index(crtc
);
11368 if (new_state
->active
)
11369 I915_STATE_WARN(!(pll
->active_mask
& crtc_mask
),
11370 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
11371 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
11373 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
11374 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
11375 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
11377 I915_STATE_WARN(!(pll
->state
.crtc_mask
& crtc_mask
),
11378 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
11379 crtc_mask
, pll
->state
.crtc_mask
);
11381 I915_STATE_WARN(pll
->on
&& memcmp(&pll
->state
.hw_state
,
11383 sizeof(dpll_hw_state
)),
11384 "pll hw state mismatch\n");
11388 verify_shared_dpll_state(struct drm_device
*dev
, struct drm_crtc
*crtc
,
11389 struct drm_crtc_state
*old_crtc_state
,
11390 struct drm_crtc_state
*new_crtc_state
)
11392 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11393 struct intel_crtc_state
*old_state
= to_intel_crtc_state(old_crtc_state
);
11394 struct intel_crtc_state
*new_state
= to_intel_crtc_state(new_crtc_state
);
11396 if (new_state
->shared_dpll
)
11397 verify_single_dpll_state(dev_priv
, new_state
->shared_dpll
, crtc
, new_crtc_state
);
11399 if (old_state
->shared_dpll
&&
11400 old_state
->shared_dpll
!= new_state
->shared_dpll
) {
11401 unsigned crtc_mask
= 1 << drm_crtc_index(crtc
);
11402 struct intel_shared_dpll
*pll
= old_state
->shared_dpll
;
11404 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
11405 "pll active mismatch (didn't expect pipe %c in active mask)\n",
11406 pipe_name(drm_crtc_index(crtc
)));
11407 I915_STATE_WARN(pll
->state
.crtc_mask
& crtc_mask
,
11408 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
11409 pipe_name(drm_crtc_index(crtc
)));
11414 intel_modeset_verify_crtc(struct drm_crtc
*crtc
,
11415 struct drm_atomic_state
*state
,
11416 struct drm_crtc_state
*old_state
,
11417 struct drm_crtc_state
*new_state
)
11419 if (!needs_modeset(new_state
) &&
11420 !to_intel_crtc_state(new_state
)->update_pipe
)
11423 verify_wm_state(crtc
, new_state
);
11424 verify_connector_state(crtc
->dev
, state
, crtc
);
11425 verify_crtc_state(crtc
, old_state
, new_state
);
11426 verify_shared_dpll_state(crtc
->dev
, crtc
, old_state
, new_state
);
11430 verify_disabled_dpll_state(struct drm_device
*dev
)
11432 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11435 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++)
11436 verify_single_dpll_state(dev_priv
, &dev_priv
->shared_dplls
[i
], NULL
, NULL
);
11440 intel_modeset_verify_disabled(struct drm_device
*dev
,
11441 struct drm_atomic_state
*state
)
11443 verify_encoder_state(dev
, state
);
11444 verify_connector_state(dev
, state
, NULL
);
11445 verify_disabled_dpll_state(dev
);
11448 static void update_scanline_offset(struct intel_crtc
*crtc
)
11450 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
11453 * The scanline counter increments at the leading edge of hsync.
11455 * On most platforms it starts counting from vtotal-1 on the
11456 * first active line. That means the scanline counter value is
11457 * always one less than what we would expect. Ie. just after
11458 * start of vblank, which also occurs at start of hsync (on the
11459 * last active line), the scanline counter will read vblank_start-1.
11461 * On gen2 the scanline counter starts counting from 1 instead
11462 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
11463 * to keep the value positive), instead of adding one.
11465 * On HSW+ the behaviour of the scanline counter depends on the output
11466 * type. For DP ports it behaves like most other platforms, but on HDMI
11467 * there's an extra 1 line difference. So we need to add two instead of
11468 * one to the value.
11470 * On VLV/CHV DSI the scanline counter would appear to increment
11471 * approx. 1/3 of a scanline before start of vblank. Unfortunately
11472 * that means we can't tell whether we're in vblank or not while
11473 * we're on that particular line. We must still set scanline_offset
11474 * to 1 so that the vblank timestamps come out correct when we query
11475 * the scanline counter from within the vblank interrupt handler.
11476 * However if queried just before the start of vblank we'll get an
11477 * answer that's slightly in the future.
11479 if (IS_GEN2(dev_priv
)) {
11480 const struct drm_display_mode
*adjusted_mode
= &crtc
->config
->base
.adjusted_mode
;
11483 vtotal
= adjusted_mode
->crtc_vtotal
;
11484 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
11487 crtc
->scanline_offset
= vtotal
- 1;
11488 } else if (HAS_DDI(dev_priv
) &&
11489 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_HDMI
)) {
11490 crtc
->scanline_offset
= 2;
11492 crtc
->scanline_offset
= 1;
11495 static void intel_modeset_clear_plls(struct drm_atomic_state
*state
)
11497 struct drm_device
*dev
= state
->dev
;
11498 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11499 struct drm_crtc
*crtc
;
11500 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
11503 if (!dev_priv
->display
.crtc_compute_clock
)
11506 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
11507 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11508 struct intel_shared_dpll
*old_dpll
=
11509 to_intel_crtc_state(old_crtc_state
)->shared_dpll
;
11511 if (!needs_modeset(new_crtc_state
))
11514 to_intel_crtc_state(new_crtc_state
)->shared_dpll
= NULL
;
11519 intel_release_shared_dpll(old_dpll
, intel_crtc
, state
);
11524 * This implements the workaround described in the "notes" section of the mode
11525 * set sequence documentation. When going from no pipes or single pipe to
11526 * multiple pipes, and planes are enabled after the pipe, we need to wait at
11527 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
11529 static int haswell_mode_set_planes_workaround(struct drm_atomic_state
*state
)
11531 struct drm_crtc_state
*crtc_state
;
11532 struct intel_crtc
*intel_crtc
;
11533 struct drm_crtc
*crtc
;
11534 struct intel_crtc_state
*first_crtc_state
= NULL
;
11535 struct intel_crtc_state
*other_crtc_state
= NULL
;
11536 enum pipe first_pipe
= INVALID_PIPE
, enabled_pipe
= INVALID_PIPE
;
11539 /* look at all crtc's that are going to be enabled in during modeset */
11540 for_each_new_crtc_in_state(state
, crtc
, crtc_state
, i
) {
11541 intel_crtc
= to_intel_crtc(crtc
);
11543 if (!crtc_state
->active
|| !needs_modeset(crtc_state
))
11546 if (first_crtc_state
) {
11547 other_crtc_state
= to_intel_crtc_state(crtc_state
);
11550 first_crtc_state
= to_intel_crtc_state(crtc_state
);
11551 first_pipe
= intel_crtc
->pipe
;
11555 /* No workaround needed? */
11556 if (!first_crtc_state
)
11559 /* w/a possibly needed, check how many crtc's are already enabled. */
11560 for_each_intel_crtc(state
->dev
, intel_crtc
) {
11561 struct intel_crtc_state
*pipe_config
;
11563 pipe_config
= intel_atomic_get_crtc_state(state
, intel_crtc
);
11564 if (IS_ERR(pipe_config
))
11565 return PTR_ERR(pipe_config
);
11567 pipe_config
->hsw_workaround_pipe
= INVALID_PIPE
;
11569 if (!pipe_config
->base
.active
||
11570 needs_modeset(&pipe_config
->base
))
11573 /* 2 or more enabled crtcs means no need for w/a */
11574 if (enabled_pipe
!= INVALID_PIPE
)
11577 enabled_pipe
= intel_crtc
->pipe
;
11580 if (enabled_pipe
!= INVALID_PIPE
)
11581 first_crtc_state
->hsw_workaround_pipe
= enabled_pipe
;
11582 else if (other_crtc_state
)
11583 other_crtc_state
->hsw_workaround_pipe
= first_pipe
;
11588 static int intel_lock_all_pipes(struct drm_atomic_state
*state
)
11590 struct drm_crtc
*crtc
;
11592 /* Add all pipes to the state */
11593 for_each_crtc(state
->dev
, crtc
) {
11594 struct drm_crtc_state
*crtc_state
;
11596 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
11597 if (IS_ERR(crtc_state
))
11598 return PTR_ERR(crtc_state
);
11604 static int intel_modeset_all_pipes(struct drm_atomic_state
*state
)
11606 struct drm_crtc
*crtc
;
11609 * Add all pipes to the state, and force
11610 * a modeset on all the active ones.
11612 for_each_crtc(state
->dev
, crtc
) {
11613 struct drm_crtc_state
*crtc_state
;
11616 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
11617 if (IS_ERR(crtc_state
))
11618 return PTR_ERR(crtc_state
);
11620 if (!crtc_state
->active
|| needs_modeset(crtc_state
))
11623 crtc_state
->mode_changed
= true;
11625 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
11629 ret
= drm_atomic_add_affected_planes(state
, crtc
);
11637 static int intel_modeset_checks(struct drm_atomic_state
*state
)
11639 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
11640 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
11641 struct drm_crtc
*crtc
;
11642 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
11645 if (!check_digital_port_conflicts(state
)) {
11646 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
11650 intel_state
->modeset
= true;
11651 intel_state
->active_crtcs
= dev_priv
->active_crtcs
;
11652 intel_state
->cdclk
.logical
= dev_priv
->cdclk
.logical
;
11653 intel_state
->cdclk
.actual
= dev_priv
->cdclk
.actual
;
11655 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
11656 if (new_crtc_state
->active
)
11657 intel_state
->active_crtcs
|= 1 << i
;
11659 intel_state
->active_crtcs
&= ~(1 << i
);
11661 if (old_crtc_state
->active
!= new_crtc_state
->active
)
11662 intel_state
->active_pipe_changes
|= drm_crtc_mask(crtc
);
11666 * See if the config requires any additional preparation, e.g.
11667 * to adjust global state with pipes off. We need to do this
11668 * here so we can get the modeset_pipe updated config for the new
11669 * mode set on this crtc. For other crtcs we need to use the
11670 * adjusted_mode bits in the crtc directly.
11672 if (dev_priv
->display
.modeset_calc_cdclk
) {
11673 ret
= dev_priv
->display
.modeset_calc_cdclk(state
);
11678 * Writes to dev_priv->cdclk.logical must protected by
11679 * holding all the crtc locks, even if we don't end up
11680 * touching the hardware
11682 if (!intel_cdclk_state_compare(&dev_priv
->cdclk
.logical
,
11683 &intel_state
->cdclk
.logical
)) {
11684 ret
= intel_lock_all_pipes(state
);
11689 /* All pipes must be switched off while we change the cdclk. */
11690 if (!intel_cdclk_state_compare(&dev_priv
->cdclk
.actual
,
11691 &intel_state
->cdclk
.actual
)) {
11692 ret
= intel_modeset_all_pipes(state
);
11697 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
11698 intel_state
->cdclk
.logical
.cdclk
,
11699 intel_state
->cdclk
.actual
.cdclk
);
11701 to_intel_atomic_state(state
)->cdclk
.logical
= dev_priv
->cdclk
.logical
;
11704 intel_modeset_clear_plls(state
);
11706 if (IS_HASWELL(dev_priv
))
11707 return haswell_mode_set_planes_workaround(state
);
11713 * Handle calculation of various watermark data at the end of the atomic check
11714 * phase. The code here should be run after the per-crtc and per-plane 'check'
11715 * handlers to ensure that all derived state has been updated.
11717 static int calc_watermark_data(struct drm_atomic_state
*state
)
11719 struct drm_device
*dev
= state
->dev
;
11720 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11722 /* Is there platform-specific watermark information to calculate? */
11723 if (dev_priv
->display
.compute_global_watermarks
)
11724 return dev_priv
->display
.compute_global_watermarks(state
);
11730 * intel_atomic_check - validate state object
11732 * @state: state to validate
11734 static int intel_atomic_check(struct drm_device
*dev
,
11735 struct drm_atomic_state
*state
)
11737 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11738 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
11739 struct drm_crtc
*crtc
;
11740 struct drm_crtc_state
*old_crtc_state
, *crtc_state
;
11742 bool any_ms
= false;
11744 ret
= drm_atomic_helper_check_modeset(dev
, state
);
11748 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, crtc_state
, i
) {
11749 struct intel_crtc_state
*pipe_config
=
11750 to_intel_crtc_state(crtc_state
);
11752 /* Catch I915_MODE_FLAG_INHERITED */
11753 if (crtc_state
->mode
.private_flags
!= old_crtc_state
->mode
.private_flags
)
11754 crtc_state
->mode_changed
= true;
11756 if (!needs_modeset(crtc_state
))
11759 if (!crtc_state
->enable
) {
11764 /* FIXME: For only active_changed we shouldn't need to do any
11765 * state recomputation at all. */
11767 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
11771 ret
= intel_modeset_pipe_config(crtc
, pipe_config
);
11773 intel_dump_pipe_config(to_intel_crtc(crtc
),
11774 pipe_config
, "[failed]");
11778 if (i915
.fastboot
&&
11779 intel_pipe_config_compare(dev_priv
,
11780 to_intel_crtc_state(old_crtc_state
),
11781 pipe_config
, true)) {
11782 crtc_state
->mode_changed
= false;
11783 pipe_config
->update_pipe
= true;
11786 if (needs_modeset(crtc_state
))
11789 ret
= drm_atomic_add_affected_planes(state
, crtc
);
11793 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
11794 needs_modeset(crtc_state
) ?
11795 "[modeset]" : "[fastset]");
11799 ret
= intel_modeset_checks(state
);
11804 intel_state
->cdclk
.logical
= dev_priv
->cdclk
.logical
;
11807 ret
= drm_atomic_helper_check_planes(dev
, state
);
11811 intel_fbc_choose_crtc(dev_priv
, state
);
11812 return calc_watermark_data(state
);
11815 static int intel_atomic_prepare_commit(struct drm_device
*dev
,
11816 struct drm_atomic_state
*state
)
11818 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11819 struct drm_crtc_state
*crtc_state
;
11820 struct drm_crtc
*crtc
;
11823 for_each_new_crtc_in_state(state
, crtc
, crtc_state
, i
) {
11824 if (state
->legacy_cursor_update
)
11827 if (atomic_read(&to_intel_crtc(crtc
)->unpin_work_count
) >= 2)
11828 flush_workqueue(dev_priv
->wq
);
11831 ret
= mutex_lock_interruptible(&dev
->struct_mutex
);
11835 ret
= drm_atomic_helper_prepare_planes(dev
, state
);
11836 mutex_unlock(&dev
->struct_mutex
);
11841 u32
intel_crtc_get_vblank_counter(struct intel_crtc
*crtc
)
11843 struct drm_device
*dev
= crtc
->base
.dev
;
11845 if (!dev
->max_vblank_count
)
11846 return drm_accurate_vblank_count(&crtc
->base
);
11848 return dev
->driver
->get_vblank_counter(dev
, crtc
->pipe
);
11851 static void intel_atomic_wait_for_vblanks(struct drm_device
*dev
,
11852 struct drm_i915_private
*dev_priv
,
11853 unsigned crtc_mask
)
11855 unsigned last_vblank_count
[I915_MAX_PIPES
];
11862 for_each_pipe(dev_priv
, pipe
) {
11863 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
,
11866 if (!((1 << pipe
) & crtc_mask
))
11869 ret
= drm_crtc_vblank_get(&crtc
->base
);
11870 if (WARN_ON(ret
!= 0)) {
11871 crtc_mask
&= ~(1 << pipe
);
11875 last_vblank_count
[pipe
] = drm_crtc_vblank_count(&crtc
->base
);
11878 for_each_pipe(dev_priv
, pipe
) {
11879 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
,
11883 if (!((1 << pipe
) & crtc_mask
))
11886 lret
= wait_event_timeout(dev
->vblank
[pipe
].queue
,
11887 last_vblank_count
[pipe
] !=
11888 drm_crtc_vblank_count(&crtc
->base
),
11889 msecs_to_jiffies(50));
11891 WARN(!lret
, "pipe %c vblank wait timed out\n", pipe_name(pipe
));
11893 drm_crtc_vblank_put(&crtc
->base
);
11897 static bool needs_vblank_wait(struct intel_crtc_state
*crtc_state
)
11899 /* fb updated, need to unpin old fb */
11900 if (crtc_state
->fb_changed
)
11903 /* wm changes, need vblank before final wm's */
11904 if (crtc_state
->update_wm_post
)
11907 if (crtc_state
->wm
.need_postvbl_update
)
11913 static void intel_update_crtc(struct drm_crtc
*crtc
,
11914 struct drm_atomic_state
*state
,
11915 struct drm_crtc_state
*old_crtc_state
,
11916 struct drm_crtc_state
*new_crtc_state
,
11917 unsigned int *crtc_vblank_mask
)
11919 struct drm_device
*dev
= crtc
->dev
;
11920 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11921 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11922 struct intel_crtc_state
*pipe_config
= to_intel_crtc_state(new_crtc_state
);
11923 bool modeset
= needs_modeset(new_crtc_state
);
11926 update_scanline_offset(intel_crtc
);
11927 dev_priv
->display
.crtc_enable(pipe_config
, state
);
11929 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
),
11933 if (drm_atomic_get_existing_plane_state(state
, crtc
->primary
)) {
11935 intel_crtc
, pipe_config
,
11936 to_intel_plane_state(crtc
->primary
->state
));
11939 drm_atomic_helper_commit_planes_on_crtc(old_crtc_state
);
11941 if (needs_vblank_wait(pipe_config
))
11942 *crtc_vblank_mask
|= drm_crtc_mask(crtc
);
11945 static void intel_update_crtcs(struct drm_atomic_state
*state
,
11946 unsigned int *crtc_vblank_mask
)
11948 struct drm_crtc
*crtc
;
11949 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
11952 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
11953 if (!new_crtc_state
->active
)
11956 intel_update_crtc(crtc
, state
, old_crtc_state
,
11957 new_crtc_state
, crtc_vblank_mask
);
11961 static void skl_update_crtcs(struct drm_atomic_state
*state
,
11962 unsigned int *crtc_vblank_mask
)
11964 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
11965 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
11966 struct drm_crtc
*crtc
;
11967 struct intel_crtc
*intel_crtc
;
11968 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
11969 struct intel_crtc_state
*cstate
;
11970 unsigned int updated
= 0;
11975 const struct skl_ddb_entry
*entries
[I915_MAX_PIPES
] = {};
11977 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
)
11978 /* ignore allocations for crtc's that have been turned off. */
11979 if (new_crtc_state
->active
)
11980 entries
[i
] = &to_intel_crtc_state(old_crtc_state
)->wm
.skl
.ddb
;
11983 * Whenever the number of active pipes changes, we need to make sure we
11984 * update the pipes in the right order so that their ddb allocations
11985 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
11986 * cause pipe underruns and other bad stuff.
11991 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
11992 bool vbl_wait
= false;
11993 unsigned int cmask
= drm_crtc_mask(crtc
);
11995 intel_crtc
= to_intel_crtc(crtc
);
11996 cstate
= to_intel_crtc_state(crtc
->state
);
11997 pipe
= intel_crtc
->pipe
;
11999 if (updated
& cmask
|| !cstate
->base
.active
)
12002 if (skl_ddb_allocation_overlaps(entries
, &cstate
->wm
.skl
.ddb
, i
))
12006 entries
[i
] = &cstate
->wm
.skl
.ddb
;
12009 * If this is an already active pipe, it's DDB changed,
12010 * and this isn't the last pipe that needs updating
12011 * then we need to wait for a vblank to pass for the
12012 * new ddb allocation to take effect.
12014 if (!skl_ddb_entry_equal(&cstate
->wm
.skl
.ddb
,
12015 &to_intel_crtc_state(old_crtc_state
)->wm
.skl
.ddb
) &&
12016 !new_crtc_state
->active_changed
&&
12017 intel_state
->wm_results
.dirty_pipes
!= updated
)
12020 intel_update_crtc(crtc
, state
, old_crtc_state
,
12021 new_crtc_state
, crtc_vblank_mask
);
12024 intel_wait_for_vblank(dev_priv
, pipe
);
12028 } while (progress
);
12031 static void intel_atomic_helper_free_state(struct drm_i915_private
*dev_priv
)
12033 struct intel_atomic_state
*state
, *next
;
12034 struct llist_node
*freed
;
12036 freed
= llist_del_all(&dev_priv
->atomic_helper
.free_list
);
12037 llist_for_each_entry_safe(state
, next
, freed
, freed
)
12038 drm_atomic_state_put(&state
->base
);
12041 static void intel_atomic_helper_free_state_worker(struct work_struct
*work
)
12043 struct drm_i915_private
*dev_priv
=
12044 container_of(work
, typeof(*dev_priv
), atomic_helper
.free_work
);
12046 intel_atomic_helper_free_state(dev_priv
);
12049 static void intel_atomic_commit_tail(struct drm_atomic_state
*state
)
12051 struct drm_device
*dev
= state
->dev
;
12052 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12053 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12054 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
12055 struct drm_crtc
*crtc
;
12056 struct intel_crtc_state
*intel_cstate
;
12057 bool hw_check
= intel_state
->modeset
;
12058 u64 put_domains
[I915_MAX_PIPES
] = {};
12059 unsigned crtc_vblank_mask
= 0;
12062 drm_atomic_helper_wait_for_dependencies(state
);
12064 if (intel_state
->modeset
)
12065 intel_display_power_get(dev_priv
, POWER_DOMAIN_MODESET
);
12067 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12068 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12070 if (needs_modeset(new_crtc_state
) ||
12071 to_intel_crtc_state(new_crtc_state
)->update_pipe
) {
12074 put_domains
[to_intel_crtc(crtc
)->pipe
] =
12075 modeset_get_crtc_power_domains(crtc
,
12076 to_intel_crtc_state(new_crtc_state
));
12079 if (!needs_modeset(new_crtc_state
))
12082 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
),
12083 to_intel_crtc_state(new_crtc_state
));
12085 if (old_crtc_state
->active
) {
12086 intel_crtc_disable_planes(crtc
, old_crtc_state
->plane_mask
);
12087 dev_priv
->display
.crtc_disable(to_intel_crtc_state(old_crtc_state
), state
);
12088 intel_crtc
->active
= false;
12089 intel_fbc_disable(intel_crtc
);
12090 intel_disable_shared_dpll(intel_crtc
);
12093 * Underruns don't always raise
12094 * interrupts, so check manually.
12096 intel_check_cpu_fifo_underruns(dev_priv
);
12097 intel_check_pch_fifo_underruns(dev_priv
);
12099 if (!crtc
->state
->active
) {
12101 * Make sure we don't call initial_watermarks
12102 * for ILK-style watermark updates.
12104 * No clue what this is supposed to achieve.
12106 if (INTEL_GEN(dev_priv
) >= 9)
12107 dev_priv
->display
.initial_watermarks(intel_state
,
12108 to_intel_crtc_state(crtc
->state
));
12113 /* Only after disabling all output pipelines that will be changed can we
12114 * update the the output configuration. */
12115 intel_modeset_update_crtc_state(state
);
12117 if (intel_state
->modeset
) {
12118 drm_atomic_helper_update_legacy_modeset_state(state
->dev
, state
);
12120 intel_set_cdclk(dev_priv
, &dev_priv
->cdclk
.actual
);
12123 * SKL workaround: bspec recommends we disable the SAGV when we
12124 * have more then one pipe enabled
12126 if (!intel_can_enable_sagv(state
))
12127 intel_disable_sagv(dev_priv
);
12129 intel_modeset_verify_disabled(dev
, state
);
12132 /* Complete the events for pipes that have now been disabled */
12133 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
12134 bool modeset
= needs_modeset(new_crtc_state
);
12136 /* Complete events for now disable pipes here. */
12137 if (modeset
&& !new_crtc_state
->active
&& new_crtc_state
->event
) {
12138 spin_lock_irq(&dev
->event_lock
);
12139 drm_crtc_send_vblank_event(crtc
, new_crtc_state
->event
);
12140 spin_unlock_irq(&dev
->event_lock
);
12142 new_crtc_state
->event
= NULL
;
12146 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
12147 dev_priv
->display
.update_crtcs(state
, &crtc_vblank_mask
);
12149 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
12150 * already, but still need the state for the delayed optimization. To
12152 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
12153 * - schedule that vblank worker _before_ calling hw_done
12154 * - at the start of commit_tail, cancel it _synchrously
12155 * - switch over to the vblank wait helper in the core after that since
12156 * we don't need out special handling any more.
12158 if (!state
->legacy_cursor_update
)
12159 intel_atomic_wait_for_vblanks(dev
, dev_priv
, crtc_vblank_mask
);
12162 * Now that the vblank has passed, we can go ahead and program the
12163 * optimal watermarks on platforms that need two-step watermark
12166 * TODO: Move this (and other cleanup) to an async worker eventually.
12168 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
12169 intel_cstate
= to_intel_crtc_state(new_crtc_state
);
12171 if (dev_priv
->display
.optimize_watermarks
)
12172 dev_priv
->display
.optimize_watermarks(intel_state
,
12176 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12177 intel_post_plane_update(to_intel_crtc_state(old_crtc_state
));
12179 if (put_domains
[i
])
12180 modeset_put_power_domains(dev_priv
, put_domains
[i
]);
12182 intel_modeset_verify_crtc(crtc
, state
, old_crtc_state
, new_crtc_state
);
12185 if (intel_state
->modeset
&& intel_can_enable_sagv(state
))
12186 intel_enable_sagv(dev_priv
);
12188 drm_atomic_helper_commit_hw_done(state
);
12190 if (intel_state
->modeset
) {
12191 /* As one of the primary mmio accessors, KMS has a high
12192 * likelihood of triggering bugs in unclaimed access. After we
12193 * finish modesetting, see if an error has been flagged, and if
12194 * so enable debugging for the next modeset - and hope we catch
12197 intel_uncore_arm_unclaimed_mmio_detection(dev_priv
);
12198 intel_display_power_put(dev_priv
, POWER_DOMAIN_MODESET
);
12201 mutex_lock(&dev
->struct_mutex
);
12202 drm_atomic_helper_cleanup_planes(dev
, state
);
12203 mutex_unlock(&dev
->struct_mutex
);
12205 drm_atomic_helper_commit_cleanup_done(state
);
12207 drm_atomic_state_put(state
);
12209 intel_atomic_helper_free_state(dev_priv
);
12212 static void intel_atomic_commit_work(struct work_struct
*work
)
12214 struct drm_atomic_state
*state
=
12215 container_of(work
, struct drm_atomic_state
, commit_work
);
12217 intel_atomic_commit_tail(state
);
12220 static int __i915_sw_fence_call
12221 intel_atomic_commit_ready(struct i915_sw_fence
*fence
,
12222 enum i915_sw_fence_notify notify
)
12224 struct intel_atomic_state
*state
=
12225 container_of(fence
, struct intel_atomic_state
, commit_ready
);
12228 case FENCE_COMPLETE
:
12229 if (state
->base
.commit_work
.func
)
12230 queue_work(system_unbound_wq
, &state
->base
.commit_work
);
12235 struct intel_atomic_helper
*helper
=
12236 &to_i915(state
->base
.dev
)->atomic_helper
;
12238 if (llist_add(&state
->freed
, &helper
->free_list
))
12239 schedule_work(&helper
->free_work
);
12244 return NOTIFY_DONE
;
12247 static void intel_atomic_track_fbs(struct drm_atomic_state
*state
)
12249 struct drm_plane_state
*old_plane_state
, *new_plane_state
;
12250 struct drm_plane
*plane
;
12253 for_each_oldnew_plane_in_state(state
, plane
, old_plane_state
, new_plane_state
, i
)
12254 i915_gem_track_fb(intel_fb_obj(old_plane_state
->fb
),
12255 intel_fb_obj(new_plane_state
->fb
),
12256 to_intel_plane(plane
)->frontbuffer_bit
);
12260 * intel_atomic_commit - commit validated state object
12262 * @state: the top-level driver state object
12263 * @nonblock: nonblocking commit
12265 * This function commits a top-level state object that has been validated
12266 * with drm_atomic_helper_check().
12269 * Zero for success or -errno.
12271 static int intel_atomic_commit(struct drm_device
*dev
,
12272 struct drm_atomic_state
*state
,
12275 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12276 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12279 ret
= drm_atomic_helper_setup_commit(state
, nonblock
);
12283 drm_atomic_state_get(state
);
12284 i915_sw_fence_init(&intel_state
->commit_ready
,
12285 intel_atomic_commit_ready
);
12287 ret
= intel_atomic_prepare_commit(dev
, state
);
12289 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret
);
12290 i915_sw_fence_commit(&intel_state
->commit_ready
);
12295 * The intel_legacy_cursor_update() fast path takes care
12296 * of avoiding the vblank waits for simple cursor
12297 * movement and flips. For cursor on/off and size changes,
12298 * we want to perform the vblank waits so that watermark
12299 * updates happen during the correct frames. Gen9+ have
12300 * double buffered watermarks and so shouldn't need this.
12302 * Do this after drm_atomic_helper_setup_commit() and
12303 * intel_atomic_prepare_commit() because we still want
12304 * to skip the flip and fb cleanup waits. Although that
12305 * does risk yanking the mapping from under the display
12308 * FIXME doing watermarks and fb cleanup from a vblank worker
12309 * (assuming we had any) would solve these problems.
12311 if (INTEL_GEN(dev_priv
) < 9)
12312 state
->legacy_cursor_update
= false;
12314 drm_atomic_helper_swap_state(state
, true);
12315 dev_priv
->wm
.distrust_bios_wm
= false;
12316 intel_shared_dpll_swap_state(state
);
12317 intel_atomic_track_fbs(state
);
12319 if (intel_state
->modeset
) {
12320 memcpy(dev_priv
->min_pixclk
, intel_state
->min_pixclk
,
12321 sizeof(intel_state
->min_pixclk
));
12322 dev_priv
->active_crtcs
= intel_state
->active_crtcs
;
12323 dev_priv
->cdclk
.logical
= intel_state
->cdclk
.logical
;
12324 dev_priv
->cdclk
.actual
= intel_state
->cdclk
.actual
;
12327 drm_atomic_state_get(state
);
12328 INIT_WORK(&state
->commit_work
,
12329 nonblock
? intel_atomic_commit_work
: NULL
);
12331 i915_sw_fence_commit(&intel_state
->commit_ready
);
12333 i915_sw_fence_wait(&intel_state
->commit_ready
);
12334 intel_atomic_commit_tail(state
);
12340 static const struct drm_crtc_funcs intel_crtc_funcs
= {
12341 .gamma_set
= drm_atomic_helper_legacy_gamma_set
,
12342 .set_config
= drm_atomic_helper_set_config
,
12343 .set_property
= drm_atomic_helper_crtc_set_property
,
12344 .destroy
= intel_crtc_destroy
,
12345 .page_flip
= drm_atomic_helper_page_flip
,
12346 .atomic_duplicate_state
= intel_crtc_duplicate_state
,
12347 .atomic_destroy_state
= intel_crtc_destroy_state
,
12348 .set_crc_source
= intel_crtc_set_crc_source
,
12352 * intel_prepare_plane_fb - Prepare fb for usage on plane
12353 * @plane: drm plane to prepare for
12354 * @fb: framebuffer to prepare for presentation
12356 * Prepares a framebuffer for usage on a display plane. Generally this
12357 * involves pinning the underlying object and updating the frontbuffer tracking
12358 * bits. Some older platforms need special physical address handling for
12361 * Must be called with struct_mutex held.
12363 * Returns 0 on success, negative error code on failure.
12366 intel_prepare_plane_fb(struct drm_plane
*plane
,
12367 struct drm_plane_state
*new_state
)
12369 struct intel_atomic_state
*intel_state
=
12370 to_intel_atomic_state(new_state
->state
);
12371 struct drm_i915_private
*dev_priv
= to_i915(plane
->dev
);
12372 struct drm_framebuffer
*fb
= new_state
->fb
;
12373 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
12374 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->state
->fb
);
12378 if (plane
->type
== DRM_PLANE_TYPE_CURSOR
&&
12379 INTEL_INFO(dev_priv
)->cursor_needs_physical
) {
12380 const int align
= intel_cursor_alignment(dev_priv
);
12382 ret
= i915_gem_object_attach_phys(obj
, align
);
12384 DRM_DEBUG_KMS("failed to attach phys object\n");
12388 struct i915_vma
*vma
;
12390 vma
= intel_pin_and_fence_fb_obj(fb
, new_state
->rotation
);
12392 DRM_DEBUG_KMS("failed to pin object\n");
12393 return PTR_ERR(vma
);
12396 to_intel_plane_state(new_state
)->vma
= vma
;
12400 if (!obj
&& !old_obj
)
12404 struct drm_crtc_state
*crtc_state
=
12405 drm_atomic_get_existing_crtc_state(new_state
->state
,
12406 plane
->state
->crtc
);
12408 /* Big Hammer, we also need to ensure that any pending
12409 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
12410 * current scanout is retired before unpinning the old
12411 * framebuffer. Note that we rely on userspace rendering
12412 * into the buffer attached to the pipe they are waiting
12413 * on. If not, userspace generates a GPU hang with IPEHR
12414 * point to the MI_WAIT_FOR_EVENT.
12416 * This should only fail upon a hung GPU, in which case we
12417 * can safely continue.
12419 if (needs_modeset(crtc_state
)) {
12420 ret
= i915_sw_fence_await_reservation(&intel_state
->commit_ready
,
12421 old_obj
->resv
, NULL
,
12429 if (new_state
->fence
) { /* explicit fencing */
12430 ret
= i915_sw_fence_await_dma_fence(&intel_state
->commit_ready
,
12432 I915_FENCE_TIMEOUT
,
12441 if (!new_state
->fence
) { /* implicit fencing */
12442 ret
= i915_sw_fence_await_reservation(&intel_state
->commit_ready
,
12444 false, I915_FENCE_TIMEOUT
,
12449 i915_gem_object_wait_priority(obj
, 0, I915_PRIORITY_DISPLAY
);
12456 * intel_cleanup_plane_fb - Cleans up an fb after plane use
12457 * @plane: drm plane to clean up for
12458 * @fb: old framebuffer that was on plane
12460 * Cleans up a framebuffer that has just been removed from a plane.
12462 * Must be called with struct_mutex held.
12465 intel_cleanup_plane_fb(struct drm_plane
*plane
,
12466 struct drm_plane_state
*old_state
)
12468 struct i915_vma
*vma
;
12470 /* Should only be called after a successful intel_prepare_plane_fb()! */
12471 vma
= fetch_and_zero(&to_intel_plane_state(old_state
)->vma
);
12473 intel_unpin_fb_vma(vma
);
12477 skl_max_scale(struct intel_crtc
*intel_crtc
, struct intel_crtc_state
*crtc_state
)
12479 struct drm_i915_private
*dev_priv
;
12481 int crtc_clock
, max_dotclk
;
12483 if (!intel_crtc
|| !crtc_state
->base
.enable
)
12484 return DRM_PLANE_HELPER_NO_SCALING
;
12486 dev_priv
= to_i915(intel_crtc
->base
.dev
);
12488 crtc_clock
= crtc_state
->base
.adjusted_mode
.crtc_clock
;
12489 max_dotclk
= to_intel_atomic_state(crtc_state
->base
.state
)->cdclk
.logical
.cdclk
;
12491 if (IS_GEMINILAKE(dev_priv
))
12494 if (WARN_ON_ONCE(!crtc_clock
|| max_dotclk
< crtc_clock
))
12495 return DRM_PLANE_HELPER_NO_SCALING
;
12498 * skl max scale is lower of:
12499 * close to 3 but not 3, -1 is for that purpose
12503 max_scale
= min((1 << 16) * 3 - 1,
12504 (1 << 8) * ((max_dotclk
<< 8) / crtc_clock
));
12510 intel_check_primary_plane(struct intel_plane
*plane
,
12511 struct intel_crtc_state
*crtc_state
,
12512 struct intel_plane_state
*state
)
12514 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
12515 struct drm_crtc
*crtc
= state
->base
.crtc
;
12516 int min_scale
= DRM_PLANE_HELPER_NO_SCALING
;
12517 int max_scale
= DRM_PLANE_HELPER_NO_SCALING
;
12518 bool can_position
= false;
12521 if (INTEL_GEN(dev_priv
) >= 9) {
12522 /* use scaler when colorkey is not required */
12523 if (state
->ckey
.flags
== I915_SET_COLORKEY_NONE
) {
12525 max_scale
= skl_max_scale(to_intel_crtc(crtc
), crtc_state
);
12527 can_position
= true;
12530 ret
= drm_plane_helper_check_state(&state
->base
,
12532 min_scale
, max_scale
,
12533 can_position
, true);
12537 if (!state
->base
.fb
)
12540 if (INTEL_GEN(dev_priv
) >= 9) {
12541 ret
= skl_check_plane_surface(state
);
12545 state
->ctl
= skl_plane_ctl(crtc_state
, state
);
12547 ret
= i9xx_check_plane_surface(state
);
12551 state
->ctl
= i9xx_plane_ctl(crtc_state
, state
);
12557 static void intel_begin_crtc_commit(struct drm_crtc
*crtc
,
12558 struct drm_crtc_state
*old_crtc_state
)
12560 struct drm_device
*dev
= crtc
->dev
;
12561 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12562 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12563 struct intel_crtc_state
*intel_cstate
=
12564 to_intel_crtc_state(crtc
->state
);
12565 struct intel_crtc_state
*old_intel_cstate
=
12566 to_intel_crtc_state(old_crtc_state
);
12567 struct intel_atomic_state
*old_intel_state
=
12568 to_intel_atomic_state(old_crtc_state
->state
);
12569 bool modeset
= needs_modeset(crtc
->state
);
12572 (intel_cstate
->base
.color_mgmt_changed
||
12573 intel_cstate
->update_pipe
)) {
12574 intel_color_set_csc(crtc
->state
);
12575 intel_color_load_luts(crtc
->state
);
12578 /* Perform vblank evasion around commit operation */
12579 intel_pipe_update_start(intel_crtc
);
12584 if (intel_cstate
->update_pipe
)
12585 intel_update_pipe_config(intel_crtc
, old_intel_cstate
);
12586 else if (INTEL_GEN(dev_priv
) >= 9)
12587 skl_detach_scalers(intel_crtc
);
12590 if (dev_priv
->display
.atomic_update_watermarks
)
12591 dev_priv
->display
.atomic_update_watermarks(old_intel_state
,
12595 static void intel_finish_crtc_commit(struct drm_crtc
*crtc
,
12596 struct drm_crtc_state
*old_crtc_state
)
12598 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12600 intel_pipe_update_end(intel_crtc
);
12604 * intel_plane_destroy - destroy a plane
12605 * @plane: plane to destroy
12607 * Common destruction function for all types of planes (primary, cursor,
12610 void intel_plane_destroy(struct drm_plane
*plane
)
12612 drm_plane_cleanup(plane
);
12613 kfree(to_intel_plane(plane
));
12616 const struct drm_plane_funcs intel_plane_funcs
= {
12617 .update_plane
= drm_atomic_helper_update_plane
,
12618 .disable_plane
= drm_atomic_helper_disable_plane
,
12619 .destroy
= intel_plane_destroy
,
12620 .set_property
= drm_atomic_helper_plane_set_property
,
12621 .atomic_get_property
= intel_plane_atomic_get_property
,
12622 .atomic_set_property
= intel_plane_atomic_set_property
,
12623 .atomic_duplicate_state
= intel_plane_duplicate_state
,
12624 .atomic_destroy_state
= intel_plane_destroy_state
,
12628 intel_legacy_cursor_update(struct drm_plane
*plane
,
12629 struct drm_crtc
*crtc
,
12630 struct drm_framebuffer
*fb
,
12631 int crtc_x
, int crtc_y
,
12632 unsigned int crtc_w
, unsigned int crtc_h
,
12633 uint32_t src_x
, uint32_t src_y
,
12634 uint32_t src_w
, uint32_t src_h
,
12635 struct drm_modeset_acquire_ctx
*ctx
)
12637 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
12639 struct drm_plane_state
*old_plane_state
, *new_plane_state
;
12640 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
12641 struct drm_framebuffer
*old_fb
;
12642 struct drm_crtc_state
*crtc_state
= crtc
->state
;
12643 struct i915_vma
*old_vma
;
12646 * When crtc is inactive or there is a modeset pending,
12647 * wait for it to complete in the slowpath
12649 if (!crtc_state
->active
|| needs_modeset(crtc_state
) ||
12650 to_intel_crtc_state(crtc_state
)->update_pipe
)
12653 old_plane_state
= plane
->state
;
12656 * If any parameters change that may affect watermarks,
12657 * take the slowpath. Only changing fb or position should be
12660 if (old_plane_state
->crtc
!= crtc
||
12661 old_plane_state
->src_w
!= src_w
||
12662 old_plane_state
->src_h
!= src_h
||
12663 old_plane_state
->crtc_w
!= crtc_w
||
12664 old_plane_state
->crtc_h
!= crtc_h
||
12665 !old_plane_state
->fb
!= !fb
)
12668 new_plane_state
= intel_plane_duplicate_state(plane
);
12669 if (!new_plane_state
)
12672 drm_atomic_set_fb_for_plane(new_plane_state
, fb
);
12674 new_plane_state
->src_x
= src_x
;
12675 new_plane_state
->src_y
= src_y
;
12676 new_plane_state
->src_w
= src_w
;
12677 new_plane_state
->src_h
= src_h
;
12678 new_plane_state
->crtc_x
= crtc_x
;
12679 new_plane_state
->crtc_y
= crtc_y
;
12680 new_plane_state
->crtc_w
= crtc_w
;
12681 new_plane_state
->crtc_h
= crtc_h
;
12683 ret
= intel_plane_atomic_check_with_state(to_intel_crtc_state(crtc
->state
),
12684 to_intel_plane_state(new_plane_state
));
12688 ret
= mutex_lock_interruptible(&dev_priv
->drm
.struct_mutex
);
12692 if (INTEL_INFO(dev_priv
)->cursor_needs_physical
) {
12693 int align
= intel_cursor_alignment(dev_priv
);
12695 ret
= i915_gem_object_attach_phys(intel_fb_obj(fb
), align
);
12697 DRM_DEBUG_KMS("failed to attach phys object\n");
12701 struct i915_vma
*vma
;
12703 vma
= intel_pin_and_fence_fb_obj(fb
, new_plane_state
->rotation
);
12705 DRM_DEBUG_KMS("failed to pin object\n");
12707 ret
= PTR_ERR(vma
);
12711 to_intel_plane_state(new_plane_state
)->vma
= vma
;
12714 old_fb
= old_plane_state
->fb
;
12715 old_vma
= to_intel_plane_state(old_plane_state
)->vma
;
12717 i915_gem_track_fb(intel_fb_obj(old_fb
), intel_fb_obj(fb
),
12718 intel_plane
->frontbuffer_bit
);
12720 /* Swap plane state */
12721 new_plane_state
->fence
= old_plane_state
->fence
;
12722 *to_intel_plane_state(old_plane_state
) = *to_intel_plane_state(new_plane_state
);
12723 new_plane_state
->fence
= NULL
;
12724 new_plane_state
->fb
= old_fb
;
12725 to_intel_plane_state(new_plane_state
)->vma
= old_vma
;
12727 if (plane
->state
->visible
) {
12728 trace_intel_update_plane(plane
, to_intel_crtc(crtc
));
12729 intel_plane
->update_plane(intel_plane
,
12730 to_intel_crtc_state(crtc
->state
),
12731 to_intel_plane_state(plane
->state
));
12733 trace_intel_disable_plane(plane
, to_intel_crtc(crtc
));
12734 intel_plane
->disable_plane(intel_plane
, to_intel_crtc(crtc
));
12737 intel_cleanup_plane_fb(plane
, new_plane_state
);
12740 mutex_unlock(&dev_priv
->drm
.struct_mutex
);
12742 intel_plane_destroy_state(plane
, new_plane_state
);
12746 return drm_atomic_helper_update_plane(plane
, crtc
, fb
,
12747 crtc_x
, crtc_y
, crtc_w
, crtc_h
,
12748 src_x
, src_y
, src_w
, src_h
, ctx
);
12751 static const struct drm_plane_funcs intel_cursor_plane_funcs
= {
12752 .update_plane
= intel_legacy_cursor_update
,
12753 .disable_plane
= drm_atomic_helper_disable_plane
,
12754 .destroy
= intel_plane_destroy
,
12755 .set_property
= drm_atomic_helper_plane_set_property
,
12756 .atomic_get_property
= intel_plane_atomic_get_property
,
12757 .atomic_set_property
= intel_plane_atomic_set_property
,
12758 .atomic_duplicate_state
= intel_plane_duplicate_state
,
12759 .atomic_destroy_state
= intel_plane_destroy_state
,
12762 static struct intel_plane
*
12763 intel_primary_plane_create(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
12765 struct intel_plane
*primary
= NULL
;
12766 struct intel_plane_state
*state
= NULL
;
12767 const uint32_t *intel_primary_formats
;
12768 unsigned int supported_rotations
;
12769 unsigned int num_formats
;
12772 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
12778 state
= intel_create_plane_state(&primary
->base
);
12784 primary
->base
.state
= &state
->base
;
12786 primary
->can_scale
= false;
12787 primary
->max_downscale
= 1;
12788 if (INTEL_GEN(dev_priv
) >= 9) {
12789 primary
->can_scale
= true;
12790 state
->scaler_id
= -1;
12792 primary
->pipe
= pipe
;
12794 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
12795 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
12797 if (HAS_FBC(dev_priv
) && INTEL_GEN(dev_priv
) < 4)
12798 primary
->plane
= (enum plane
) !pipe
;
12800 primary
->plane
= (enum plane
) pipe
;
12801 primary
->id
= PLANE_PRIMARY
;
12802 primary
->frontbuffer_bit
= INTEL_FRONTBUFFER_PRIMARY(pipe
);
12803 primary
->check_plane
= intel_check_primary_plane
;
12805 if (INTEL_GEN(dev_priv
) >= 9) {
12806 intel_primary_formats
= skl_primary_formats
;
12807 num_formats
= ARRAY_SIZE(skl_primary_formats
);
12809 primary
->update_plane
= skylake_update_primary_plane
;
12810 primary
->disable_plane
= skylake_disable_primary_plane
;
12811 } else if (INTEL_GEN(dev_priv
) >= 4) {
12812 intel_primary_formats
= i965_primary_formats
;
12813 num_formats
= ARRAY_SIZE(i965_primary_formats
);
12815 primary
->update_plane
= i9xx_update_primary_plane
;
12816 primary
->disable_plane
= i9xx_disable_primary_plane
;
12818 intel_primary_formats
= i8xx_primary_formats
;
12819 num_formats
= ARRAY_SIZE(i8xx_primary_formats
);
12821 primary
->update_plane
= i9xx_update_primary_plane
;
12822 primary
->disable_plane
= i9xx_disable_primary_plane
;
12825 if (INTEL_GEN(dev_priv
) >= 9)
12826 ret
= drm_universal_plane_init(&dev_priv
->drm
, &primary
->base
,
12827 0, &intel_plane_funcs
,
12828 intel_primary_formats
, num_formats
,
12829 DRM_PLANE_TYPE_PRIMARY
,
12830 "plane 1%c", pipe_name(pipe
));
12831 else if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
))
12832 ret
= drm_universal_plane_init(&dev_priv
->drm
, &primary
->base
,
12833 0, &intel_plane_funcs
,
12834 intel_primary_formats
, num_formats
,
12835 DRM_PLANE_TYPE_PRIMARY
,
12836 "primary %c", pipe_name(pipe
));
12838 ret
= drm_universal_plane_init(&dev_priv
->drm
, &primary
->base
,
12839 0, &intel_plane_funcs
,
12840 intel_primary_formats
, num_formats
,
12841 DRM_PLANE_TYPE_PRIMARY
,
12842 "plane %c", plane_name(primary
->plane
));
12846 if (INTEL_GEN(dev_priv
) >= 9) {
12847 supported_rotations
=
12848 DRM_MODE_ROTATE_0
| DRM_MODE_ROTATE_90
|
12849 DRM_MODE_ROTATE_180
| DRM_MODE_ROTATE_270
;
12850 } else if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_B
) {
12851 supported_rotations
=
12852 DRM_MODE_ROTATE_0
| DRM_MODE_ROTATE_180
|
12853 DRM_MODE_REFLECT_X
;
12854 } else if (INTEL_GEN(dev_priv
) >= 4) {
12855 supported_rotations
=
12856 DRM_MODE_ROTATE_0
| DRM_MODE_ROTATE_180
;
12858 supported_rotations
= DRM_MODE_ROTATE_0
;
12861 if (INTEL_GEN(dev_priv
) >= 4)
12862 drm_plane_create_rotation_property(&primary
->base
,
12864 supported_rotations
);
12866 drm_plane_helper_add(&primary
->base
, &intel_plane_helper_funcs
);
12874 return ERR_PTR(ret
);
12877 static struct intel_plane
*
12878 intel_cursor_plane_create(struct drm_i915_private
*dev_priv
,
12881 struct intel_plane
*cursor
= NULL
;
12882 struct intel_plane_state
*state
= NULL
;
12885 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
12891 state
= intel_create_plane_state(&cursor
->base
);
12897 cursor
->base
.state
= &state
->base
;
12899 cursor
->can_scale
= false;
12900 cursor
->max_downscale
= 1;
12901 cursor
->pipe
= pipe
;
12902 cursor
->plane
= pipe
;
12903 cursor
->id
= PLANE_CURSOR
;
12904 cursor
->frontbuffer_bit
= INTEL_FRONTBUFFER_CURSOR(pipe
);
12906 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
)) {
12907 cursor
->update_plane
= i845_update_cursor
;
12908 cursor
->disable_plane
= i845_disable_cursor
;
12909 cursor
->check_plane
= i845_check_cursor
;
12911 cursor
->update_plane
= i9xx_update_cursor
;
12912 cursor
->disable_plane
= i9xx_disable_cursor
;
12913 cursor
->check_plane
= i9xx_check_cursor
;
12916 cursor
->cursor
.base
= ~0;
12917 cursor
->cursor
.cntl
= ~0;
12919 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
) || HAS_CUR_FBC(dev_priv
))
12920 cursor
->cursor
.size
= ~0;
12922 ret
= drm_universal_plane_init(&dev_priv
->drm
, &cursor
->base
,
12923 0, &intel_cursor_plane_funcs
,
12924 intel_cursor_formats
,
12925 ARRAY_SIZE(intel_cursor_formats
),
12926 DRM_PLANE_TYPE_CURSOR
,
12927 "cursor %c", pipe_name(pipe
));
12931 if (INTEL_GEN(dev_priv
) >= 4)
12932 drm_plane_create_rotation_property(&cursor
->base
,
12934 DRM_MODE_ROTATE_0
|
12935 DRM_MODE_ROTATE_180
);
12937 if (INTEL_GEN(dev_priv
) >= 9)
12938 state
->scaler_id
= -1;
12940 drm_plane_helper_add(&cursor
->base
, &intel_plane_helper_funcs
);
12948 return ERR_PTR(ret
);
12951 static void intel_crtc_init_scalers(struct intel_crtc
*crtc
,
12952 struct intel_crtc_state
*crtc_state
)
12954 struct intel_crtc_scaler_state
*scaler_state
=
12955 &crtc_state
->scaler_state
;
12956 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
12959 crtc
->num_scalers
= dev_priv
->info
.num_scalers
[crtc
->pipe
];
12960 if (!crtc
->num_scalers
)
12963 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
12964 struct intel_scaler
*scaler
= &scaler_state
->scalers
[i
];
12966 scaler
->in_use
= 0;
12967 scaler
->mode
= PS_SCALER_MODE_DYN
;
12970 scaler_state
->scaler_id
= -1;
12973 static int intel_crtc_init(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
12975 struct intel_crtc
*intel_crtc
;
12976 struct intel_crtc_state
*crtc_state
= NULL
;
12977 struct intel_plane
*primary
= NULL
;
12978 struct intel_plane
*cursor
= NULL
;
12981 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
12985 crtc_state
= kzalloc(sizeof(*crtc_state
), GFP_KERNEL
);
12990 intel_crtc
->config
= crtc_state
;
12991 intel_crtc
->base
.state
= &crtc_state
->base
;
12992 crtc_state
->base
.crtc
= &intel_crtc
->base
;
12994 primary
= intel_primary_plane_create(dev_priv
, pipe
);
12995 if (IS_ERR(primary
)) {
12996 ret
= PTR_ERR(primary
);
12999 intel_crtc
->plane_ids_mask
|= BIT(primary
->id
);
13001 for_each_sprite(dev_priv
, pipe
, sprite
) {
13002 struct intel_plane
*plane
;
13004 plane
= intel_sprite_plane_create(dev_priv
, pipe
, sprite
);
13005 if (IS_ERR(plane
)) {
13006 ret
= PTR_ERR(plane
);
13009 intel_crtc
->plane_ids_mask
|= BIT(plane
->id
);
13012 cursor
= intel_cursor_plane_create(dev_priv
, pipe
);
13013 if (IS_ERR(cursor
)) {
13014 ret
= PTR_ERR(cursor
);
13017 intel_crtc
->plane_ids_mask
|= BIT(cursor
->id
);
13019 ret
= drm_crtc_init_with_planes(&dev_priv
->drm
, &intel_crtc
->base
,
13020 &primary
->base
, &cursor
->base
,
13022 "pipe %c", pipe_name(pipe
));
13026 intel_crtc
->pipe
= pipe
;
13027 intel_crtc
->plane
= primary
->plane
;
13029 /* initialize shared scalers */
13030 intel_crtc_init_scalers(intel_crtc
, crtc_state
);
13032 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
13033 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
13034 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = intel_crtc
;
13035 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = intel_crtc
;
13037 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
13039 intel_color_init(&intel_crtc
->base
);
13041 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
13047 * drm_mode_config_cleanup() will free up any
13048 * crtcs/planes already initialized.
13056 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
13058 struct drm_device
*dev
= connector
->base
.dev
;
13060 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
13062 if (!connector
->base
.state
->crtc
)
13063 return INVALID_PIPE
;
13065 return to_intel_crtc(connector
->base
.state
->crtc
)->pipe
;
13068 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
13069 struct drm_file
*file
)
13071 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
13072 struct drm_crtc
*drmmode_crtc
;
13073 struct intel_crtc
*crtc
;
13075 drmmode_crtc
= drm_crtc_find(dev
, pipe_from_crtc_id
->crtc_id
);
13079 crtc
= to_intel_crtc(drmmode_crtc
);
13080 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
13085 static int intel_encoder_clones(struct intel_encoder
*encoder
)
13087 struct drm_device
*dev
= encoder
->base
.dev
;
13088 struct intel_encoder
*source_encoder
;
13089 int index_mask
= 0;
13092 for_each_intel_encoder(dev
, source_encoder
) {
13093 if (encoders_cloneable(encoder
, source_encoder
))
13094 index_mask
|= (1 << entry
);
13102 static bool has_edp_a(struct drm_i915_private
*dev_priv
)
13104 if (!IS_MOBILE(dev_priv
))
13107 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
13110 if (IS_GEN5(dev_priv
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
13116 static bool intel_crt_present(struct drm_i915_private
*dev_priv
)
13118 if (INTEL_GEN(dev_priv
) >= 9)
13121 if (IS_HSW_ULT(dev_priv
) || IS_BDW_ULT(dev_priv
))
13124 if (IS_CHERRYVIEW(dev_priv
))
13127 if (HAS_PCH_LPT_H(dev_priv
) &&
13128 I915_READ(SFUSE_STRAP
) & SFUSE_STRAP_CRT_DISABLED
)
13131 /* DDI E can't be used if DDI A requires 4 lanes */
13132 if (HAS_DDI(dev_priv
) && I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_A_4_LANES
)
13135 if (!dev_priv
->vbt
.int_crt_support
)
13141 void intel_pps_unlock_regs_wa(struct drm_i915_private
*dev_priv
)
13146 if (HAS_DDI(dev_priv
))
13149 * This w/a is needed at least on CPT/PPT, but to be sure apply it
13150 * everywhere where registers can be write protected.
13152 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
13157 for (pps_idx
= 0; pps_idx
< pps_num
; pps_idx
++) {
13158 u32 val
= I915_READ(PP_CONTROL(pps_idx
));
13160 val
= (val
& ~PANEL_UNLOCK_MASK
) | PANEL_UNLOCK_REGS
;
13161 I915_WRITE(PP_CONTROL(pps_idx
), val
);
13165 static void intel_pps_init(struct drm_i915_private
*dev_priv
)
13167 if (HAS_PCH_SPLIT(dev_priv
) || IS_GEN9_LP(dev_priv
))
13168 dev_priv
->pps_mmio_base
= PCH_PPS_BASE
;
13169 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
13170 dev_priv
->pps_mmio_base
= VLV_PPS_BASE
;
13172 dev_priv
->pps_mmio_base
= PPS_BASE
;
13174 intel_pps_unlock_regs_wa(dev_priv
);
13177 static void intel_setup_outputs(struct drm_i915_private
*dev_priv
)
13179 struct intel_encoder
*encoder
;
13180 bool dpd_is_edp
= false;
13182 intel_pps_init(dev_priv
);
13185 * intel_edp_init_connector() depends on this completing first, to
13186 * prevent the registeration of both eDP and LVDS and the incorrect
13187 * sharing of the PPS.
13189 intel_lvds_init(dev_priv
);
13191 if (intel_crt_present(dev_priv
))
13192 intel_crt_init(dev_priv
);
13194 if (IS_GEN9_LP(dev_priv
)) {
13196 * FIXME: Broxton doesn't support port detection via the
13197 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
13198 * detect the ports.
13200 intel_ddi_init(dev_priv
, PORT_A
);
13201 intel_ddi_init(dev_priv
, PORT_B
);
13202 intel_ddi_init(dev_priv
, PORT_C
);
13204 intel_dsi_init(dev_priv
);
13205 } else if (HAS_DDI(dev_priv
)) {
13209 * Haswell uses DDI functions to detect digital outputs.
13210 * On SKL pre-D0 the strap isn't connected, so we assume
13213 found
= I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_INIT_DISPLAY_DETECTED
;
13214 /* WaIgnoreDDIAStrap: skl */
13215 if (found
|| IS_GEN9_BC(dev_priv
))
13216 intel_ddi_init(dev_priv
, PORT_A
);
13218 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
13220 found
= I915_READ(SFUSE_STRAP
);
13222 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
13223 intel_ddi_init(dev_priv
, PORT_B
);
13224 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
13225 intel_ddi_init(dev_priv
, PORT_C
);
13226 if (found
& SFUSE_STRAP_DDID_DETECTED
)
13227 intel_ddi_init(dev_priv
, PORT_D
);
13229 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
13231 if (IS_GEN9_BC(dev_priv
) &&
13232 (dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dp
||
13233 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dvi
||
13234 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_hdmi
))
13235 intel_ddi_init(dev_priv
, PORT_E
);
13237 } else if (HAS_PCH_SPLIT(dev_priv
)) {
13239 dpd_is_edp
= intel_dp_is_edp(dev_priv
, PORT_D
);
13241 if (has_edp_a(dev_priv
))
13242 intel_dp_init(dev_priv
, DP_A
, PORT_A
);
13244 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
13245 /* PCH SDVOB multiplex with HDMIB */
13246 found
= intel_sdvo_init(dev_priv
, PCH_SDVOB
, PORT_B
);
13248 intel_hdmi_init(dev_priv
, PCH_HDMIB
, PORT_B
);
13249 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
13250 intel_dp_init(dev_priv
, PCH_DP_B
, PORT_B
);
13253 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
13254 intel_hdmi_init(dev_priv
, PCH_HDMIC
, PORT_C
);
13256 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
13257 intel_hdmi_init(dev_priv
, PCH_HDMID
, PORT_D
);
13259 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
13260 intel_dp_init(dev_priv
, PCH_DP_C
, PORT_C
);
13262 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
13263 intel_dp_init(dev_priv
, PCH_DP_D
, PORT_D
);
13264 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
13265 bool has_edp
, has_port
;
13268 * The DP_DETECTED bit is the latched state of the DDC
13269 * SDA pin at boot. However since eDP doesn't require DDC
13270 * (no way to plug in a DP->HDMI dongle) the DDC pins for
13271 * eDP ports may have been muxed to an alternate function.
13272 * Thus we can't rely on the DP_DETECTED bit alone to detect
13273 * eDP ports. Consult the VBT as well as DP_DETECTED to
13274 * detect eDP ports.
13276 * Sadly the straps seem to be missing sometimes even for HDMI
13277 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
13278 * and VBT for the presence of the port. Additionally we can't
13279 * trust the port type the VBT declares as we've seen at least
13280 * HDMI ports that the VBT claim are DP or eDP.
13282 has_edp
= intel_dp_is_edp(dev_priv
, PORT_B
);
13283 has_port
= intel_bios_is_port_present(dev_priv
, PORT_B
);
13284 if (I915_READ(VLV_DP_B
) & DP_DETECTED
|| has_port
)
13285 has_edp
&= intel_dp_init(dev_priv
, VLV_DP_B
, PORT_B
);
13286 if ((I915_READ(VLV_HDMIB
) & SDVO_DETECTED
|| has_port
) && !has_edp
)
13287 intel_hdmi_init(dev_priv
, VLV_HDMIB
, PORT_B
);
13289 has_edp
= intel_dp_is_edp(dev_priv
, PORT_C
);
13290 has_port
= intel_bios_is_port_present(dev_priv
, PORT_C
);
13291 if (I915_READ(VLV_DP_C
) & DP_DETECTED
|| has_port
)
13292 has_edp
&= intel_dp_init(dev_priv
, VLV_DP_C
, PORT_C
);
13293 if ((I915_READ(VLV_HDMIC
) & SDVO_DETECTED
|| has_port
) && !has_edp
)
13294 intel_hdmi_init(dev_priv
, VLV_HDMIC
, PORT_C
);
13296 if (IS_CHERRYVIEW(dev_priv
)) {
13298 * eDP not supported on port D,
13299 * so no need to worry about it
13301 has_port
= intel_bios_is_port_present(dev_priv
, PORT_D
);
13302 if (I915_READ(CHV_DP_D
) & DP_DETECTED
|| has_port
)
13303 intel_dp_init(dev_priv
, CHV_DP_D
, PORT_D
);
13304 if (I915_READ(CHV_HDMID
) & SDVO_DETECTED
|| has_port
)
13305 intel_hdmi_init(dev_priv
, CHV_HDMID
, PORT_D
);
13308 intel_dsi_init(dev_priv
);
13309 } else if (!IS_GEN2(dev_priv
) && !IS_PINEVIEW(dev_priv
)) {
13310 bool found
= false;
13312 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
13313 DRM_DEBUG_KMS("probing SDVOB\n");
13314 found
= intel_sdvo_init(dev_priv
, GEN3_SDVOB
, PORT_B
);
13315 if (!found
&& IS_G4X(dev_priv
)) {
13316 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
13317 intel_hdmi_init(dev_priv
, GEN4_HDMIB
, PORT_B
);
13320 if (!found
&& IS_G4X(dev_priv
))
13321 intel_dp_init(dev_priv
, DP_B
, PORT_B
);
13324 /* Before G4X SDVOC doesn't have its own detect register */
13326 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
13327 DRM_DEBUG_KMS("probing SDVOC\n");
13328 found
= intel_sdvo_init(dev_priv
, GEN3_SDVOC
, PORT_C
);
13331 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
13333 if (IS_G4X(dev_priv
)) {
13334 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
13335 intel_hdmi_init(dev_priv
, GEN4_HDMIC
, PORT_C
);
13337 if (IS_G4X(dev_priv
))
13338 intel_dp_init(dev_priv
, DP_C
, PORT_C
);
13341 if (IS_G4X(dev_priv
) && (I915_READ(DP_D
) & DP_DETECTED
))
13342 intel_dp_init(dev_priv
, DP_D
, PORT_D
);
13343 } else if (IS_GEN2(dev_priv
))
13344 intel_dvo_init(dev_priv
);
13346 if (SUPPORTS_TV(dev_priv
))
13347 intel_tv_init(dev_priv
);
13349 intel_psr_init(dev_priv
);
13351 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
13352 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
13353 encoder
->base
.possible_clones
=
13354 intel_encoder_clones(encoder
);
13357 intel_init_pch_refclk(dev_priv
);
13359 drm_helper_move_panel_connectors_to_head(&dev_priv
->drm
);
13362 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
13364 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
13366 drm_framebuffer_cleanup(fb
);
13368 i915_gem_object_lock(intel_fb
->obj
);
13369 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
13370 i915_gem_object_unlock(intel_fb
->obj
);
13372 i915_gem_object_put(intel_fb
->obj
);
13377 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
13378 struct drm_file
*file
,
13379 unsigned int *handle
)
13381 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
13382 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
13384 if (obj
->userptr
.mm
) {
13385 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
13389 return drm_gem_handle_create(file
, &obj
->base
, handle
);
13392 static int intel_user_framebuffer_dirty(struct drm_framebuffer
*fb
,
13393 struct drm_file
*file
,
13394 unsigned flags
, unsigned color
,
13395 struct drm_clip_rect
*clips
,
13396 unsigned num_clips
)
13398 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13400 i915_gem_object_flush_if_display(obj
);
13401 intel_fb_obj_flush(obj
, ORIGIN_DIRTYFB
);
13406 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
13407 .destroy
= intel_user_framebuffer_destroy
,
13408 .create_handle
= intel_user_framebuffer_create_handle
,
13409 .dirty
= intel_user_framebuffer_dirty
,
13413 u32
intel_fb_pitch_limit(struct drm_i915_private
*dev_priv
,
13414 uint64_t fb_modifier
, uint32_t pixel_format
)
13416 u32 gen
= INTEL_GEN(dev_priv
);
13419 int cpp
= drm_format_plane_cpp(pixel_format
, 0);
13421 /* "The stride in bytes must not exceed the of the size of 8K
13422 * pixels and 32K bytes."
13424 return min(8192 * cpp
, 32768);
13425 } else if (gen
>= 5 && !HAS_GMCH_DISPLAY(dev_priv
)) {
13427 } else if (gen
>= 4) {
13428 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
13432 } else if (gen
>= 3) {
13433 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
13438 /* XXX DSPC is limited to 4k tiled */
13443 static int intel_framebuffer_init(struct intel_framebuffer
*intel_fb
,
13444 struct drm_i915_gem_object
*obj
,
13445 struct drm_mode_fb_cmd2
*mode_cmd
)
13447 struct drm_i915_private
*dev_priv
= to_i915(obj
->base
.dev
);
13448 struct drm_format_name_buf format_name
;
13449 u32 pitch_limit
, stride_alignment
;
13450 unsigned int tiling
, stride
;
13453 i915_gem_object_lock(obj
);
13454 obj
->framebuffer_references
++;
13455 tiling
= i915_gem_object_get_tiling(obj
);
13456 stride
= i915_gem_object_get_stride(obj
);
13457 i915_gem_object_unlock(obj
);
13459 if (mode_cmd
->flags
& DRM_MODE_FB_MODIFIERS
) {
13461 * If there's a fence, enforce that
13462 * the fb modifier and tiling mode match.
13464 if (tiling
!= I915_TILING_NONE
&&
13465 tiling
!= intel_fb_modifier_to_tiling(mode_cmd
->modifier
[0])) {
13466 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
13470 if (tiling
== I915_TILING_X
) {
13471 mode_cmd
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
13472 } else if (tiling
== I915_TILING_Y
) {
13473 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
13478 /* Passed in modifier sanity checking. */
13479 switch (mode_cmd
->modifier
[0]) {
13480 case I915_FORMAT_MOD_Y_TILED
:
13481 case I915_FORMAT_MOD_Yf_TILED
:
13482 if (INTEL_GEN(dev_priv
) < 9) {
13483 DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n",
13484 mode_cmd
->modifier
[0]);
13487 case DRM_FORMAT_MOD_LINEAR
:
13488 case I915_FORMAT_MOD_X_TILED
:
13491 DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n",
13492 mode_cmd
->modifier
[0]);
13497 * gen2/3 display engine uses the fence if present,
13498 * so the tiling mode must match the fb modifier exactly.
13500 if (INTEL_INFO(dev_priv
)->gen
< 4 &&
13501 tiling
!= intel_fb_modifier_to_tiling(mode_cmd
->modifier
[0])) {
13502 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
13506 pitch_limit
= intel_fb_pitch_limit(dev_priv
, mode_cmd
->modifier
[0],
13507 mode_cmd
->pixel_format
);
13508 if (mode_cmd
->pitches
[0] > pitch_limit
) {
13509 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
13510 mode_cmd
->modifier
[0] != DRM_FORMAT_MOD_LINEAR
?
13511 "tiled" : "linear",
13512 mode_cmd
->pitches
[0], pitch_limit
);
13517 * If there's a fence, enforce that
13518 * the fb pitch and fence stride match.
13520 if (tiling
!= I915_TILING_NONE
&& mode_cmd
->pitches
[0] != stride
) {
13521 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
13522 mode_cmd
->pitches
[0], stride
);
13526 /* Reject formats not supported by any plane early. */
13527 switch (mode_cmd
->pixel_format
) {
13528 case DRM_FORMAT_C8
:
13529 case DRM_FORMAT_RGB565
:
13530 case DRM_FORMAT_XRGB8888
:
13531 case DRM_FORMAT_ARGB8888
:
13533 case DRM_FORMAT_XRGB1555
:
13534 if (INTEL_GEN(dev_priv
) > 3) {
13535 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13536 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13540 case DRM_FORMAT_ABGR8888
:
13541 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
) &&
13542 INTEL_GEN(dev_priv
) < 9) {
13543 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13544 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13548 case DRM_FORMAT_XBGR8888
:
13549 case DRM_FORMAT_XRGB2101010
:
13550 case DRM_FORMAT_XBGR2101010
:
13551 if (INTEL_GEN(dev_priv
) < 4) {
13552 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13553 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13557 case DRM_FORMAT_ABGR2101010
:
13558 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
)) {
13559 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13560 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13564 case DRM_FORMAT_YUYV
:
13565 case DRM_FORMAT_UYVY
:
13566 case DRM_FORMAT_YVYU
:
13567 case DRM_FORMAT_VYUY
:
13568 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
)) {
13569 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13570 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13575 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13576 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13580 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
13581 if (mode_cmd
->offsets
[0] != 0)
13584 drm_helper_mode_fill_fb_struct(&dev_priv
->drm
,
13585 &intel_fb
->base
, mode_cmd
);
13587 stride_alignment
= intel_fb_stride_alignment(&intel_fb
->base
, 0);
13588 if (mode_cmd
->pitches
[0] & (stride_alignment
- 1)) {
13589 DRM_DEBUG_KMS("pitch (%d) must be at least %u byte aligned\n",
13590 mode_cmd
->pitches
[0], stride_alignment
);
13594 intel_fb
->obj
= obj
;
13596 ret
= intel_fill_fb_info(dev_priv
, &intel_fb
->base
);
13600 ret
= drm_framebuffer_init(obj
->base
.dev
,
13604 DRM_ERROR("framebuffer init failed %d\n", ret
);
13611 i915_gem_object_lock(obj
);
13612 obj
->framebuffer_references
--;
13613 i915_gem_object_unlock(obj
);
13617 static struct drm_framebuffer
*
13618 intel_user_framebuffer_create(struct drm_device
*dev
,
13619 struct drm_file
*filp
,
13620 const struct drm_mode_fb_cmd2
*user_mode_cmd
)
13622 struct drm_framebuffer
*fb
;
13623 struct drm_i915_gem_object
*obj
;
13624 struct drm_mode_fb_cmd2 mode_cmd
= *user_mode_cmd
;
13626 obj
= i915_gem_object_lookup(filp
, mode_cmd
.handles
[0]);
13628 return ERR_PTR(-ENOENT
);
13630 fb
= intel_framebuffer_create(obj
, &mode_cmd
);
13632 i915_gem_object_put(obj
);
13637 static void intel_atomic_state_free(struct drm_atomic_state
*state
)
13639 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
13641 drm_atomic_state_default_release(state
);
13643 i915_sw_fence_fini(&intel_state
->commit_ready
);
13648 static const struct drm_mode_config_funcs intel_mode_funcs
= {
13649 .fb_create
= intel_user_framebuffer_create
,
13650 .output_poll_changed
= intel_fbdev_output_poll_changed
,
13651 .atomic_check
= intel_atomic_check
,
13652 .atomic_commit
= intel_atomic_commit
,
13653 .atomic_state_alloc
= intel_atomic_state_alloc
,
13654 .atomic_state_clear
= intel_atomic_state_clear
,
13655 .atomic_state_free
= intel_atomic_state_free
,
13659 * intel_init_display_hooks - initialize the display modesetting hooks
13660 * @dev_priv: device private
13662 void intel_init_display_hooks(struct drm_i915_private
*dev_priv
)
13664 intel_init_cdclk_hooks(dev_priv
);
13666 if (INTEL_INFO(dev_priv
)->gen
>= 9) {
13667 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
13668 dev_priv
->display
.get_initial_plane_config
=
13669 skylake_get_initial_plane_config
;
13670 dev_priv
->display
.crtc_compute_clock
=
13671 haswell_crtc_compute_clock
;
13672 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
13673 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
13674 } else if (HAS_DDI(dev_priv
)) {
13675 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
13676 dev_priv
->display
.get_initial_plane_config
=
13677 ironlake_get_initial_plane_config
;
13678 dev_priv
->display
.crtc_compute_clock
=
13679 haswell_crtc_compute_clock
;
13680 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
13681 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
13682 } else if (HAS_PCH_SPLIT(dev_priv
)) {
13683 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
13684 dev_priv
->display
.get_initial_plane_config
=
13685 ironlake_get_initial_plane_config
;
13686 dev_priv
->display
.crtc_compute_clock
=
13687 ironlake_crtc_compute_clock
;
13688 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
13689 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
13690 } else if (IS_CHERRYVIEW(dev_priv
)) {
13691 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13692 dev_priv
->display
.get_initial_plane_config
=
13693 i9xx_get_initial_plane_config
;
13694 dev_priv
->display
.crtc_compute_clock
= chv_crtc_compute_clock
;
13695 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
13696 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13697 } else if (IS_VALLEYVIEW(dev_priv
)) {
13698 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13699 dev_priv
->display
.get_initial_plane_config
=
13700 i9xx_get_initial_plane_config
;
13701 dev_priv
->display
.crtc_compute_clock
= vlv_crtc_compute_clock
;
13702 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
13703 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13704 } else if (IS_G4X(dev_priv
)) {
13705 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13706 dev_priv
->display
.get_initial_plane_config
=
13707 i9xx_get_initial_plane_config
;
13708 dev_priv
->display
.crtc_compute_clock
= g4x_crtc_compute_clock
;
13709 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
13710 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13711 } else if (IS_PINEVIEW(dev_priv
)) {
13712 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13713 dev_priv
->display
.get_initial_plane_config
=
13714 i9xx_get_initial_plane_config
;
13715 dev_priv
->display
.crtc_compute_clock
= pnv_crtc_compute_clock
;
13716 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
13717 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13718 } else if (!IS_GEN2(dev_priv
)) {
13719 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13720 dev_priv
->display
.get_initial_plane_config
=
13721 i9xx_get_initial_plane_config
;
13722 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
13723 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
13724 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13726 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13727 dev_priv
->display
.get_initial_plane_config
=
13728 i9xx_get_initial_plane_config
;
13729 dev_priv
->display
.crtc_compute_clock
= i8xx_crtc_compute_clock
;
13730 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
13731 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13734 if (IS_GEN5(dev_priv
)) {
13735 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
13736 } else if (IS_GEN6(dev_priv
)) {
13737 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
13738 } else if (IS_IVYBRIDGE(dev_priv
)) {
13739 /* FIXME: detect B0+ stepping and use auto training */
13740 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
13741 } else if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
13742 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
13745 if (dev_priv
->info
.gen
>= 9)
13746 dev_priv
->display
.update_crtcs
= skl_update_crtcs
;
13748 dev_priv
->display
.update_crtcs
= intel_update_crtcs
;
13752 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
13754 static void quirk_ssc_force_disable(struct drm_device
*dev
)
13756 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13757 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
13758 DRM_INFO("applying lvds SSC disable quirk\n");
13762 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
13765 static void quirk_invert_brightness(struct drm_device
*dev
)
13767 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13768 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
13769 DRM_INFO("applying inverted panel brightness quirk\n");
13772 /* Some VBT's incorrectly indicate no backlight is present */
13773 static void quirk_backlight_present(struct drm_device
*dev
)
13775 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13776 dev_priv
->quirks
|= QUIRK_BACKLIGHT_PRESENT
;
13777 DRM_INFO("applying backlight present quirk\n");
13780 /* Toshiba Satellite P50-C-18C requires T12 delay to be min 800ms
13781 * which is 300 ms greater than eDP spec T12 min.
13783 static void quirk_increase_t12_delay(struct drm_device
*dev
)
13785 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13787 dev_priv
->quirks
|= QUIRK_INCREASE_T12_DELAY
;
13788 DRM_INFO("Applying T12 delay quirk\n");
13791 struct intel_quirk
{
13793 int subsystem_vendor
;
13794 int subsystem_device
;
13795 void (*hook
)(struct drm_device
*dev
);
13798 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
13799 struct intel_dmi_quirk
{
13800 void (*hook
)(struct drm_device
*dev
);
13801 const struct dmi_system_id (*dmi_id_list
)[];
13804 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
13806 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
13810 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
13812 .dmi_id_list
= &(const struct dmi_system_id
[]) {
13814 .callback
= intel_dmi_reverse_brightness
,
13815 .ident
= "NCR Corporation",
13816 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
13817 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
13820 { } /* terminating entry */
13822 .hook
= quirk_invert_brightness
,
13826 static struct intel_quirk intel_quirks
[] = {
13827 /* Lenovo U160 cannot use SSC on LVDS */
13828 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
13830 /* Sony Vaio Y cannot use SSC on LVDS */
13831 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
13833 /* Acer Aspire 5734Z must invert backlight brightness */
13834 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
13836 /* Acer/eMachines G725 */
13837 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
13839 /* Acer/eMachines e725 */
13840 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
13842 /* Acer/Packard Bell NCL20 */
13843 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
13845 /* Acer Aspire 4736Z */
13846 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
13848 /* Acer Aspire 5336 */
13849 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
13851 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
13852 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present
},
13854 /* Acer C720 Chromebook (Core i3 4005U) */
13855 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present
},
13857 /* Apple Macbook 2,1 (Core 2 T7400) */
13858 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present
},
13860 /* Apple Macbook 4,1 */
13861 { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present
},
13863 /* Toshiba CB35 Chromebook (Celeron 2955U) */
13864 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present
},
13866 /* HP Chromebook 14 (Celeron 2955U) */
13867 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present
},
13869 /* Dell Chromebook 11 */
13870 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present
},
13872 /* Dell Chromebook 11 (2015 version) */
13873 { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present
},
13875 /* Toshiba Satellite P50-C-18C */
13876 { 0x191B, 0x1179, 0xF840, quirk_increase_t12_delay
},
13879 static void intel_init_quirks(struct drm_device
*dev
)
13881 struct pci_dev
*d
= dev
->pdev
;
13884 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
13885 struct intel_quirk
*q
= &intel_quirks
[i
];
13887 if (d
->device
== q
->device
&&
13888 (d
->subsystem_vendor
== q
->subsystem_vendor
||
13889 q
->subsystem_vendor
== PCI_ANY_ID
) &&
13890 (d
->subsystem_device
== q
->subsystem_device
||
13891 q
->subsystem_device
== PCI_ANY_ID
))
13894 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
13895 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
13896 intel_dmi_quirks
[i
].hook(dev
);
13900 /* Disable the VGA plane that we never use */
13901 static void i915_disable_vga(struct drm_i915_private
*dev_priv
)
13903 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
13905 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev_priv
);
13907 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
13908 vga_get_uninterruptible(pdev
, VGA_RSRC_LEGACY_IO
);
13909 outb(SR01
, VGA_SR_INDEX
);
13910 sr1
= inb(VGA_SR_DATA
);
13911 outb(sr1
| 1<<5, VGA_SR_DATA
);
13912 vga_put(pdev
, VGA_RSRC_LEGACY_IO
);
13915 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
13916 POSTING_READ(vga_reg
);
13919 void intel_modeset_init_hw(struct drm_device
*dev
)
13921 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13923 intel_update_cdclk(dev_priv
);
13924 dev_priv
->cdclk
.logical
= dev_priv
->cdclk
.actual
= dev_priv
->cdclk
.hw
;
13926 intel_init_clock_gating(dev_priv
);
13930 * Calculate what we think the watermarks should be for the state we've read
13931 * out of the hardware and then immediately program those watermarks so that
13932 * we ensure the hardware settings match our internal state.
13934 * We can calculate what we think WM's should be by creating a duplicate of the
13935 * current state (which was constructed during hardware readout) and running it
13936 * through the atomic check code to calculate new watermark values in the
13939 static void sanitize_watermarks(struct drm_device
*dev
)
13941 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13942 struct drm_atomic_state
*state
;
13943 struct intel_atomic_state
*intel_state
;
13944 struct drm_crtc
*crtc
;
13945 struct drm_crtc_state
*cstate
;
13946 struct drm_modeset_acquire_ctx ctx
;
13950 /* Only supported on platforms that use atomic watermark design */
13951 if (!dev_priv
->display
.optimize_watermarks
)
13955 * We need to hold connection_mutex before calling duplicate_state so
13956 * that the connector loop is protected.
13958 drm_modeset_acquire_init(&ctx
, 0);
13960 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
13961 if (ret
== -EDEADLK
) {
13962 drm_modeset_backoff(&ctx
);
13964 } else if (WARN_ON(ret
)) {
13968 state
= drm_atomic_helper_duplicate_state(dev
, &ctx
);
13969 if (WARN_ON(IS_ERR(state
)))
13972 intel_state
= to_intel_atomic_state(state
);
13975 * Hardware readout is the only time we don't want to calculate
13976 * intermediate watermarks (since we don't trust the current
13979 if (!HAS_GMCH_DISPLAY(dev_priv
))
13980 intel_state
->skip_intermediate_wm
= true;
13982 ret
= intel_atomic_check(dev
, state
);
13985 * If we fail here, it means that the hardware appears to be
13986 * programmed in a way that shouldn't be possible, given our
13987 * understanding of watermark requirements. This might mean a
13988 * mistake in the hardware readout code or a mistake in the
13989 * watermark calculations for a given platform. Raise a WARN
13990 * so that this is noticeable.
13992 * If this actually happens, we'll have to just leave the
13993 * BIOS-programmed watermarks untouched and hope for the best.
13995 WARN(true, "Could not determine valid watermarks for inherited state\n");
13999 /* Write calculated watermark values back */
14000 for_each_new_crtc_in_state(state
, crtc
, cstate
, i
) {
14001 struct intel_crtc_state
*cs
= to_intel_crtc_state(cstate
);
14003 cs
->wm
.need_postvbl_update
= true;
14004 dev_priv
->display
.optimize_watermarks(intel_state
, cs
);
14008 drm_atomic_state_put(state
);
14010 drm_modeset_drop_locks(&ctx
);
14011 drm_modeset_acquire_fini(&ctx
);
14014 int intel_modeset_init(struct drm_device
*dev
)
14016 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14017 struct i915_ggtt
*ggtt
= &dev_priv
->ggtt
;
14019 struct intel_crtc
*crtc
;
14021 drm_mode_config_init(dev
);
14023 dev
->mode_config
.min_width
= 0;
14024 dev
->mode_config
.min_height
= 0;
14026 dev
->mode_config
.preferred_depth
= 24;
14027 dev
->mode_config
.prefer_shadow
= 1;
14029 dev
->mode_config
.allow_fb_modifiers
= true;
14031 dev
->mode_config
.funcs
= &intel_mode_funcs
;
14033 init_llist_head(&dev_priv
->atomic_helper
.free_list
);
14034 INIT_WORK(&dev_priv
->atomic_helper
.free_work
,
14035 intel_atomic_helper_free_state_worker
);
14037 intel_init_quirks(dev
);
14039 intel_init_pm(dev_priv
);
14041 if (INTEL_INFO(dev_priv
)->num_pipes
== 0)
14045 * There may be no VBT; and if the BIOS enabled SSC we can
14046 * just keep using it to avoid unnecessary flicker. Whereas if the
14047 * BIOS isn't using it, don't assume it will work even if the VBT
14048 * indicates as much.
14050 if (HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
)) {
14051 bool bios_lvds_use_ssc
= !!(I915_READ(PCH_DREF_CONTROL
) &
14054 if (dev_priv
->vbt
.lvds_use_ssc
!= bios_lvds_use_ssc
) {
14055 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
14056 bios_lvds_use_ssc
? "en" : "dis",
14057 dev_priv
->vbt
.lvds_use_ssc
? "en" : "dis");
14058 dev_priv
->vbt
.lvds_use_ssc
= bios_lvds_use_ssc
;
14062 if (IS_GEN2(dev_priv
)) {
14063 dev
->mode_config
.max_width
= 2048;
14064 dev
->mode_config
.max_height
= 2048;
14065 } else if (IS_GEN3(dev_priv
)) {
14066 dev
->mode_config
.max_width
= 4096;
14067 dev
->mode_config
.max_height
= 4096;
14069 dev
->mode_config
.max_width
= 8192;
14070 dev
->mode_config
.max_height
= 8192;
14073 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
)) {
14074 dev
->mode_config
.cursor_width
= IS_I845G(dev_priv
) ? 64 : 512;
14075 dev
->mode_config
.cursor_height
= 1023;
14076 } else if (IS_GEN2(dev_priv
)) {
14077 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
14078 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
14080 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
14081 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
14084 dev
->mode_config
.fb_base
= ggtt
->mappable_base
;
14086 DRM_DEBUG_KMS("%d display pipe%s available.\n",
14087 INTEL_INFO(dev_priv
)->num_pipes
,
14088 INTEL_INFO(dev_priv
)->num_pipes
> 1 ? "s" : "");
14090 for_each_pipe(dev_priv
, pipe
) {
14093 ret
= intel_crtc_init(dev_priv
, pipe
);
14095 drm_mode_config_cleanup(dev
);
14100 intel_shared_dpll_init(dev
);
14102 intel_update_czclk(dev_priv
);
14103 intel_modeset_init_hw(dev
);
14105 if (dev_priv
->max_cdclk_freq
== 0)
14106 intel_update_max_cdclk(dev_priv
);
14108 /* Just disable it once at startup */
14109 i915_disable_vga(dev_priv
);
14110 intel_setup_outputs(dev_priv
);
14112 drm_modeset_lock_all(dev
);
14113 intel_modeset_setup_hw_state(dev
, dev
->mode_config
.acquire_ctx
);
14114 drm_modeset_unlock_all(dev
);
14116 for_each_intel_crtc(dev
, crtc
) {
14117 struct intel_initial_plane_config plane_config
= {};
14123 * Note that reserving the BIOS fb up front prevents us
14124 * from stuffing other stolen allocations like the ring
14125 * on top. This prevents some ugliness at boot time, and
14126 * can even allow for smooth boot transitions if the BIOS
14127 * fb is large enough for the active pipe configuration.
14129 dev_priv
->display
.get_initial_plane_config(crtc
,
14133 * If the fb is shared between multiple heads, we'll
14134 * just get the first one.
14136 intel_find_initial_plane_obj(crtc
, &plane_config
);
14140 * Make sure hardware watermarks really match the state we read out.
14141 * Note that we need to do this after reconstructing the BIOS fb's
14142 * since the watermark calculation done here will use pstate->fb.
14144 if (!HAS_GMCH_DISPLAY(dev_priv
))
14145 sanitize_watermarks(dev
);
14150 void i830_enable_pipe(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
14152 /* 640x480@60Hz, ~25175 kHz */
14153 struct dpll clock
= {
14163 WARN_ON(i9xx_calc_dpll_params(48000, &clock
) != 25154);
14165 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
14166 pipe_name(pipe
), clock
.vco
, clock
.dot
);
14168 fp
= i9xx_dpll_compute_fp(&clock
);
14169 dpll
= (I915_READ(DPLL(pipe
)) & DPLL_DVO_2X_MODE
) |
14170 DPLL_VGA_MODE_DIS
|
14171 ((clock
.p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
) |
14172 PLL_P2_DIVIDE_BY_4
|
14173 PLL_REF_INPUT_DREFCLK
|
14176 I915_WRITE(FP0(pipe
), fp
);
14177 I915_WRITE(FP1(pipe
), fp
);
14179 I915_WRITE(HTOTAL(pipe
), (640 - 1) | ((800 - 1) << 16));
14180 I915_WRITE(HBLANK(pipe
), (640 - 1) | ((800 - 1) << 16));
14181 I915_WRITE(HSYNC(pipe
), (656 - 1) | ((752 - 1) << 16));
14182 I915_WRITE(VTOTAL(pipe
), (480 - 1) | ((525 - 1) << 16));
14183 I915_WRITE(VBLANK(pipe
), (480 - 1) | ((525 - 1) << 16));
14184 I915_WRITE(VSYNC(pipe
), (490 - 1) | ((492 - 1) << 16));
14185 I915_WRITE(PIPESRC(pipe
), ((640 - 1) << 16) | (480 - 1));
14188 * Apparently we need to have VGA mode enabled prior to changing
14189 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
14190 * dividers, even though the register value does change.
14192 I915_WRITE(DPLL(pipe
), dpll
& ~DPLL_VGA_MODE_DIS
);
14193 I915_WRITE(DPLL(pipe
), dpll
);
14195 /* Wait for the clocks to stabilize. */
14196 POSTING_READ(DPLL(pipe
));
14199 /* The pixel multiplier can only be updated once the
14200 * DPLL is enabled and the clocks are stable.
14202 * So write it again.
14204 I915_WRITE(DPLL(pipe
), dpll
);
14206 /* We do this three times for luck */
14207 for (i
= 0; i
< 3 ; i
++) {
14208 I915_WRITE(DPLL(pipe
), dpll
);
14209 POSTING_READ(DPLL(pipe
));
14210 udelay(150); /* wait for warmup */
14213 I915_WRITE(PIPECONF(pipe
), PIPECONF_ENABLE
| PIPECONF_PROGRESSIVE
);
14214 POSTING_READ(PIPECONF(pipe
));
14217 void i830_disable_pipe(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
14219 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
14222 assert_plane_disabled(dev_priv
, PLANE_A
);
14223 assert_plane_disabled(dev_priv
, PLANE_B
);
14225 I915_WRITE(PIPECONF(pipe
), 0);
14226 POSTING_READ(PIPECONF(pipe
));
14228 if (wait_for(pipe_dsl_stopped(dev_priv
, pipe
), 100))
14229 DRM_ERROR("pipe %c off wait timed out\n", pipe_name(pipe
));
14231 I915_WRITE(DPLL(pipe
), DPLL_VGA_MODE_DIS
);
14232 POSTING_READ(DPLL(pipe
));
14236 intel_check_plane_mapping(struct intel_crtc
*crtc
)
14238 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
14241 if (INTEL_INFO(dev_priv
)->num_pipes
== 1)
14244 val
= I915_READ(DSPCNTR(!crtc
->plane
));
14246 if ((val
& DISPLAY_PLANE_ENABLE
) &&
14247 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
14253 static bool intel_crtc_has_encoders(struct intel_crtc
*crtc
)
14255 struct drm_device
*dev
= crtc
->base
.dev
;
14256 struct intel_encoder
*encoder
;
14258 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
14264 static struct intel_connector
*intel_encoder_find_connector(struct intel_encoder
*encoder
)
14266 struct drm_device
*dev
= encoder
->base
.dev
;
14267 struct intel_connector
*connector
;
14269 for_each_connector_on_encoder(dev
, &encoder
->base
, connector
)
14275 static bool has_pch_trancoder(struct drm_i915_private
*dev_priv
,
14276 enum transcoder pch_transcoder
)
14278 return HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
) ||
14279 (HAS_PCH_LPT_H(dev_priv
) && pch_transcoder
== TRANSCODER_A
);
14282 static void intel_sanitize_crtc(struct intel_crtc
*crtc
,
14283 struct drm_modeset_acquire_ctx
*ctx
)
14285 struct drm_device
*dev
= crtc
->base
.dev
;
14286 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14287 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
14289 /* Clear any frame start delays used for debugging left by the BIOS */
14290 if (!transcoder_is_dsi(cpu_transcoder
)) {
14291 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
14294 I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
14297 /* restore vblank interrupts to correct state */
14298 drm_crtc_vblank_reset(&crtc
->base
);
14299 if (crtc
->active
) {
14300 struct intel_plane
*plane
;
14302 drm_crtc_vblank_on(&crtc
->base
);
14304 /* Disable everything but the primary plane */
14305 for_each_intel_plane_on_crtc(dev
, crtc
, plane
) {
14306 if (plane
->base
.type
== DRM_PLANE_TYPE_PRIMARY
)
14309 trace_intel_disable_plane(&plane
->base
, crtc
);
14310 plane
->disable_plane(plane
, crtc
);
14314 /* We need to sanitize the plane -> pipe mapping first because this will
14315 * disable the crtc (and hence change the state) if it is wrong. Note
14316 * that gen4+ has a fixed plane -> pipe mapping. */
14317 if (INTEL_GEN(dev_priv
) < 4 && !intel_check_plane_mapping(crtc
)) {
14320 DRM_DEBUG_KMS("[CRTC:%d:%s] wrong plane connection detected!\n",
14321 crtc
->base
.base
.id
, crtc
->base
.name
);
14323 /* Pipe has the wrong plane attached and the plane is active.
14324 * Temporarily change the plane mapping and disable everything
14326 plane
= crtc
->plane
;
14327 crtc
->base
.primary
->state
->visible
= true;
14328 crtc
->plane
= !plane
;
14329 intel_crtc_disable_noatomic(&crtc
->base
, ctx
);
14330 crtc
->plane
= plane
;
14333 /* Adjust the state of the output pipe according to whether we
14334 * have active connectors/encoders. */
14335 if (crtc
->active
&& !intel_crtc_has_encoders(crtc
))
14336 intel_crtc_disable_noatomic(&crtc
->base
, ctx
);
14338 if (crtc
->active
|| HAS_GMCH_DISPLAY(dev_priv
)) {
14340 * We start out with underrun reporting disabled to avoid races.
14341 * For correct bookkeeping mark this on active crtcs.
14343 * Also on gmch platforms we dont have any hardware bits to
14344 * disable the underrun reporting. Which means we need to start
14345 * out with underrun reporting disabled also on inactive pipes,
14346 * since otherwise we'll complain about the garbage we read when
14347 * e.g. coming up after runtime pm.
14349 * No protection against concurrent access is required - at
14350 * worst a fifo underrun happens which also sets this to false.
14352 crtc
->cpu_fifo_underrun_disabled
= true;
14354 * We track the PCH trancoder underrun reporting state
14355 * within the crtc. With crtc for pipe A housing the underrun
14356 * reporting state for PCH transcoder A, crtc for pipe B housing
14357 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
14358 * and marking underrun reporting as disabled for the non-existing
14359 * PCH transcoders B and C would prevent enabling the south
14360 * error interrupt (see cpt_can_enable_serr_int()).
14362 if (has_pch_trancoder(dev_priv
, (enum transcoder
)crtc
->pipe
))
14363 crtc
->pch_fifo_underrun_disabled
= true;
14367 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
14369 struct intel_connector
*connector
;
14371 /* We need to check both for a crtc link (meaning that the
14372 * encoder is active and trying to read from a pipe) and the
14373 * pipe itself being active. */
14374 bool has_active_crtc
= encoder
->base
.crtc
&&
14375 to_intel_crtc(encoder
->base
.crtc
)->active
;
14377 connector
= intel_encoder_find_connector(encoder
);
14378 if (connector
&& !has_active_crtc
) {
14379 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
14380 encoder
->base
.base
.id
,
14381 encoder
->base
.name
);
14383 /* Connector is active, but has no active pipe. This is
14384 * fallout from our resume register restoring. Disable
14385 * the encoder manually again. */
14386 if (encoder
->base
.crtc
) {
14387 struct drm_crtc_state
*crtc_state
= encoder
->base
.crtc
->state
;
14389 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
14390 encoder
->base
.base
.id
,
14391 encoder
->base
.name
);
14392 encoder
->disable(encoder
, to_intel_crtc_state(crtc_state
), connector
->base
.state
);
14393 if (encoder
->post_disable
)
14394 encoder
->post_disable(encoder
, to_intel_crtc_state(crtc_state
), connector
->base
.state
);
14396 encoder
->base
.crtc
= NULL
;
14398 /* Inconsistent output/port/pipe state happens presumably due to
14399 * a bug in one of the get_hw_state functions. Or someplace else
14400 * in our code, like the register restore mess on resume. Clamp
14401 * things to off as a safer default. */
14403 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
14404 connector
->base
.encoder
= NULL
;
14406 /* Enabled encoders without active connectors will be fixed in
14407 * the crtc fixup. */
14410 void i915_redisable_vga_power_on(struct drm_i915_private
*dev_priv
)
14412 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev_priv
);
14414 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
14415 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
14416 i915_disable_vga(dev_priv
);
14420 void i915_redisable_vga(struct drm_i915_private
*dev_priv
)
14422 /* This function can be called both from intel_modeset_setup_hw_state or
14423 * at a very early point in our resume sequence, where the power well
14424 * structures are not yet restored. Since this function is at a very
14425 * paranoid "someone might have enabled VGA while we were not looking"
14426 * level, just check if the power well is enabled instead of trying to
14427 * follow the "don't touch the power well if we don't need it" policy
14428 * the rest of the driver uses. */
14429 if (!intel_display_power_get_if_enabled(dev_priv
, POWER_DOMAIN_VGA
))
14432 i915_redisable_vga_power_on(dev_priv
);
14434 intel_display_power_put(dev_priv
, POWER_DOMAIN_VGA
);
14437 static bool primary_get_hw_state(struct intel_plane
*plane
)
14439 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
14441 return I915_READ(DSPCNTR(plane
->plane
)) & DISPLAY_PLANE_ENABLE
;
14444 /* FIXME read out full plane state for all planes */
14445 static void readout_plane_state(struct intel_crtc
*crtc
)
14447 struct intel_plane
*primary
= to_intel_plane(crtc
->base
.primary
);
14450 visible
= crtc
->active
&& primary_get_hw_state(primary
);
14452 intel_set_plane_visible(to_intel_crtc_state(crtc
->base
.state
),
14453 to_intel_plane_state(primary
->base
.state
),
14457 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
14459 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14461 struct intel_crtc
*crtc
;
14462 struct intel_encoder
*encoder
;
14463 struct intel_connector
*connector
;
14464 struct drm_connector_list_iter conn_iter
;
14467 dev_priv
->active_crtcs
= 0;
14469 for_each_intel_crtc(dev
, crtc
) {
14470 struct intel_crtc_state
*crtc_state
=
14471 to_intel_crtc_state(crtc
->base
.state
);
14473 __drm_atomic_helper_crtc_destroy_state(&crtc_state
->base
);
14474 memset(crtc_state
, 0, sizeof(*crtc_state
));
14475 crtc_state
->base
.crtc
= &crtc
->base
;
14477 crtc_state
->base
.active
= crtc_state
->base
.enable
=
14478 dev_priv
->display
.get_pipe_config(crtc
, crtc_state
);
14480 crtc
->base
.enabled
= crtc_state
->base
.enable
;
14481 crtc
->active
= crtc_state
->base
.active
;
14483 if (crtc_state
->base
.active
)
14484 dev_priv
->active_crtcs
|= 1 << crtc
->pipe
;
14486 readout_plane_state(crtc
);
14488 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
14489 crtc
->base
.base
.id
, crtc
->base
.name
,
14490 enableddisabled(crtc_state
->base
.active
));
14493 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
14494 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
14496 pll
->on
= pll
->funcs
.get_hw_state(dev_priv
, pll
,
14497 &pll
->state
.hw_state
);
14498 pll
->state
.crtc_mask
= 0;
14499 for_each_intel_crtc(dev
, crtc
) {
14500 struct intel_crtc_state
*crtc_state
=
14501 to_intel_crtc_state(crtc
->base
.state
);
14503 if (crtc_state
->base
.active
&&
14504 crtc_state
->shared_dpll
== pll
)
14505 pll
->state
.crtc_mask
|= 1 << crtc
->pipe
;
14507 pll
->active_mask
= pll
->state
.crtc_mask
;
14509 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
14510 pll
->name
, pll
->state
.crtc_mask
, pll
->on
);
14513 for_each_intel_encoder(dev
, encoder
) {
14516 if (encoder
->get_hw_state(encoder
, &pipe
)) {
14517 struct intel_crtc_state
*crtc_state
;
14519 crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
14520 crtc_state
= to_intel_crtc_state(crtc
->base
.state
);
14522 encoder
->base
.crtc
= &crtc
->base
;
14523 crtc_state
->output_types
|= 1 << encoder
->type
;
14524 encoder
->get_config(encoder
, crtc_state
);
14526 encoder
->base
.crtc
= NULL
;
14529 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
14530 encoder
->base
.base
.id
, encoder
->base
.name
,
14531 enableddisabled(encoder
->base
.crtc
),
14535 drm_connector_list_iter_begin(dev
, &conn_iter
);
14536 for_each_intel_connector_iter(connector
, &conn_iter
) {
14537 if (connector
->get_hw_state(connector
)) {
14538 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
14540 encoder
= connector
->encoder
;
14541 connector
->base
.encoder
= &encoder
->base
;
14543 if (encoder
->base
.crtc
&&
14544 encoder
->base
.crtc
->state
->active
) {
14546 * This has to be done during hardware readout
14547 * because anything calling .crtc_disable may
14548 * rely on the connector_mask being accurate.
14550 encoder
->base
.crtc
->state
->connector_mask
|=
14551 1 << drm_connector_index(&connector
->base
);
14552 encoder
->base
.crtc
->state
->encoder_mask
|=
14553 1 << drm_encoder_index(&encoder
->base
);
14557 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
14558 connector
->base
.encoder
= NULL
;
14560 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
14561 connector
->base
.base
.id
, connector
->base
.name
,
14562 enableddisabled(connector
->base
.encoder
));
14564 drm_connector_list_iter_end(&conn_iter
);
14566 for_each_intel_crtc(dev
, crtc
) {
14567 struct intel_crtc_state
*crtc_state
=
14568 to_intel_crtc_state(crtc
->base
.state
);
14571 memset(&crtc
->base
.mode
, 0, sizeof(crtc
->base
.mode
));
14572 if (crtc_state
->base
.active
) {
14573 intel_mode_from_pipe_config(&crtc
->base
.mode
, crtc_state
);
14574 intel_mode_from_pipe_config(&crtc_state
->base
.adjusted_mode
, crtc_state
);
14575 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->base
.state
, &crtc
->base
.mode
));
14578 * The initial mode needs to be set in order to keep
14579 * the atomic core happy. It wants a valid mode if the
14580 * crtc's enabled, so we do the above call.
14582 * But we don't set all the derived state fully, hence
14583 * set a flag to indicate that a full recalculation is
14584 * needed on the next commit.
14586 crtc_state
->base
.mode
.private_flags
= I915_MODE_FLAG_INHERITED
;
14588 intel_crtc_compute_pixel_rate(crtc_state
);
14590 if (INTEL_GEN(dev_priv
) >= 9 || IS_BROADWELL(dev_priv
) ||
14591 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
14592 pixclk
= crtc_state
->pixel_rate
;
14594 WARN_ON(dev_priv
->display
.modeset_calc_cdclk
);
14596 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
14597 if (IS_BROADWELL(dev_priv
) && crtc_state
->ips_enabled
)
14598 pixclk
= DIV_ROUND_UP(pixclk
* 100, 95);
14600 drm_calc_timestamping_constants(&crtc
->base
,
14601 &crtc_state
->base
.adjusted_mode
);
14602 update_scanline_offset(crtc
);
14605 dev_priv
->min_pixclk
[crtc
->pipe
] = pixclk
;
14607 intel_pipe_config_sanity_check(dev_priv
, crtc_state
);
14612 get_encoder_power_domains(struct drm_i915_private
*dev_priv
)
14614 struct intel_encoder
*encoder
;
14616 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
14618 enum intel_display_power_domain domain
;
14620 if (!encoder
->get_power_domains
)
14623 get_domains
= encoder
->get_power_domains(encoder
);
14624 for_each_power_domain(domain
, get_domains
)
14625 intel_display_power_get(dev_priv
, domain
);
14629 /* Scan out the current hw modeset state,
14630 * and sanitizes it to the current state
14633 intel_modeset_setup_hw_state(struct drm_device
*dev
,
14634 struct drm_modeset_acquire_ctx
*ctx
)
14636 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14638 struct intel_crtc
*crtc
;
14639 struct intel_encoder
*encoder
;
14642 intel_modeset_readout_hw_state(dev
);
14644 /* HW state is read out, now we need to sanitize this mess. */
14645 get_encoder_power_domains(dev_priv
);
14647 for_each_intel_encoder(dev
, encoder
) {
14648 intel_sanitize_encoder(encoder
);
14651 for_each_pipe(dev_priv
, pipe
) {
14652 crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
14654 intel_sanitize_crtc(crtc
, ctx
);
14655 intel_dump_pipe_config(crtc
, crtc
->config
,
14656 "[setup_hw_state]");
14659 intel_modeset_update_connector_atomic_state(dev
);
14661 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
14662 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
14664 if (!pll
->on
|| pll
->active_mask
)
14667 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
14669 pll
->funcs
.disable(dev_priv
, pll
);
14673 if (IS_G4X(dev_priv
)) {
14674 g4x_wm_get_hw_state(dev
);
14675 g4x_wm_sanitize(dev_priv
);
14676 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
14677 vlv_wm_get_hw_state(dev
);
14678 vlv_wm_sanitize(dev_priv
);
14679 } else if (IS_GEN9(dev_priv
)) {
14680 skl_wm_get_hw_state(dev
);
14681 } else if (HAS_PCH_SPLIT(dev_priv
)) {
14682 ilk_wm_get_hw_state(dev
);
14685 for_each_intel_crtc(dev
, crtc
) {
14688 put_domains
= modeset_get_crtc_power_domains(&crtc
->base
, crtc
->config
);
14689 if (WARN_ON(put_domains
))
14690 modeset_put_power_domains(dev_priv
, put_domains
);
14692 intel_display_set_init_power(dev_priv
, false);
14694 intel_power_domains_verify_state(dev_priv
);
14696 intel_fbc_init_pipe_state(dev_priv
);
14699 void intel_display_resume(struct drm_device
*dev
)
14701 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14702 struct drm_atomic_state
*state
= dev_priv
->modeset_restore_state
;
14703 struct drm_modeset_acquire_ctx ctx
;
14706 dev_priv
->modeset_restore_state
= NULL
;
14708 state
->acquire_ctx
= &ctx
;
14710 drm_modeset_acquire_init(&ctx
, 0);
14713 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
14714 if (ret
!= -EDEADLK
)
14717 drm_modeset_backoff(&ctx
);
14721 ret
= __intel_display_resume(dev
, state
, &ctx
);
14723 drm_modeset_drop_locks(&ctx
);
14724 drm_modeset_acquire_fini(&ctx
);
14727 DRM_ERROR("Restoring old state failed with %i\n", ret
);
14729 drm_atomic_state_put(state
);
14732 void intel_modeset_gem_init(struct drm_device
*dev
)
14734 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14736 intel_init_gt_powersave(dev_priv
);
14738 intel_setup_overlay(dev_priv
);
14741 int intel_connector_register(struct drm_connector
*connector
)
14743 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
14746 ret
= intel_backlight_device_register(intel_connector
);
14756 void intel_connector_unregister(struct drm_connector
*connector
)
14758 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
14760 intel_backlight_device_unregister(intel_connector
);
14761 intel_panel_destroy_backlight(connector
);
14764 void intel_modeset_cleanup(struct drm_device
*dev
)
14766 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14768 flush_work(&dev_priv
->atomic_helper
.free_work
);
14769 WARN_ON(!llist_empty(&dev_priv
->atomic_helper
.free_list
));
14771 intel_disable_gt_powersave(dev_priv
);
14774 * Interrupts and polling as the first thing to avoid creating havoc.
14775 * Too much stuff here (turning of connectors, ...) would
14776 * experience fancy races otherwise.
14778 intel_irq_uninstall(dev_priv
);
14781 * Due to the hpd irq storm handling the hotplug work can re-arm the
14782 * poll handlers. Hence disable polling after hpd handling is shut down.
14784 drm_kms_helper_poll_fini(dev
);
14786 /* poll work can call into fbdev, hence clean that up afterwards */
14787 intel_fbdev_fini(dev_priv
);
14789 intel_unregister_dsm_handler();
14791 intel_fbc_global_disable(dev_priv
);
14793 /* flush any delayed tasks or pending work */
14794 flush_scheduled_work();
14796 drm_mode_config_cleanup(dev
);
14798 intel_cleanup_overlay(dev_priv
);
14800 intel_cleanup_gt_powersave(dev_priv
);
14802 intel_teardown_gmbus(dev_priv
);
14805 void intel_connector_attach_encoder(struct intel_connector
*connector
,
14806 struct intel_encoder
*encoder
)
14808 connector
->encoder
= encoder
;
14809 drm_mode_connector_attach_encoder(&connector
->base
,
14814 * set vga decode state - true == enable VGA decode
14816 int intel_modeset_vga_set_state(struct drm_i915_private
*dev_priv
, bool state
)
14818 unsigned reg
= INTEL_GEN(dev_priv
) >= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
14821 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
14822 DRM_ERROR("failed to read control word\n");
14826 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
14830 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
14832 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
14834 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
14835 DRM_ERROR("failed to write control word\n");
14842 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
14844 struct intel_display_error_state
{
14846 u32 power_well_driver
;
14848 int num_transcoders
;
14850 struct intel_cursor_error_state
{
14855 } cursor
[I915_MAX_PIPES
];
14857 struct intel_pipe_error_state
{
14858 bool power_domain_on
;
14861 } pipe
[I915_MAX_PIPES
];
14863 struct intel_plane_error_state
{
14871 } plane
[I915_MAX_PIPES
];
14873 struct intel_transcoder_error_state
{
14874 bool power_domain_on
;
14875 enum transcoder cpu_transcoder
;
14888 struct intel_display_error_state
*
14889 intel_display_capture_error_state(struct drm_i915_private
*dev_priv
)
14891 struct intel_display_error_state
*error
;
14892 int transcoders
[] = {
14900 if (INTEL_INFO(dev_priv
)->num_pipes
== 0)
14903 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
14907 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
14908 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
14910 for_each_pipe(dev_priv
, i
) {
14911 error
->pipe
[i
].power_domain_on
=
14912 __intel_display_power_is_enabled(dev_priv
,
14913 POWER_DOMAIN_PIPE(i
));
14914 if (!error
->pipe
[i
].power_domain_on
)
14917 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
14918 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
14919 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
14921 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
14922 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
14923 if (INTEL_GEN(dev_priv
) <= 3) {
14924 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
14925 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
14927 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
14928 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
14929 if (INTEL_GEN(dev_priv
) >= 4) {
14930 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
14931 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
14934 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
14936 if (HAS_GMCH_DISPLAY(dev_priv
))
14937 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
14940 /* Note: this does not include DSI transcoders. */
14941 error
->num_transcoders
= INTEL_INFO(dev_priv
)->num_pipes
;
14942 if (HAS_DDI(dev_priv
))
14943 error
->num_transcoders
++; /* Account for eDP. */
14945 for (i
= 0; i
< error
->num_transcoders
; i
++) {
14946 enum transcoder cpu_transcoder
= transcoders
[i
];
14948 error
->transcoder
[i
].power_domain_on
=
14949 __intel_display_power_is_enabled(dev_priv
,
14950 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
14951 if (!error
->transcoder
[i
].power_domain_on
)
14954 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
14956 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
14957 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
14958 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
14959 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
14960 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
14961 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
14962 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
14968 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
14971 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
14972 struct intel_display_error_state
*error
)
14974 struct drm_i915_private
*dev_priv
= m
->i915
;
14980 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev_priv
)->num_pipes
);
14981 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
14982 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
14983 error
->power_well_driver
);
14984 for_each_pipe(dev_priv
, i
) {
14985 err_printf(m
, "Pipe [%d]:\n", i
);
14986 err_printf(m
, " Power: %s\n",
14987 onoff(error
->pipe
[i
].power_domain_on
));
14988 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
14989 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
14991 err_printf(m
, "Plane [%d]:\n", i
);
14992 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
14993 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
14994 if (INTEL_GEN(dev_priv
) <= 3) {
14995 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
14996 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
14998 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
14999 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
15000 if (INTEL_GEN(dev_priv
) >= 4) {
15001 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
15002 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
15005 err_printf(m
, "Cursor [%d]:\n", i
);
15006 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
15007 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
15008 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
15011 for (i
= 0; i
< error
->num_transcoders
; i
++) {
15012 err_printf(m
, "CPU transcoder: %s\n",
15013 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
15014 err_printf(m
, " Power: %s\n",
15015 onoff(error
->transcoder
[i
].power_domain_on
));
15016 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
15017 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
15018 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
15019 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
15020 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
15021 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
15022 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);