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
;
4490 if (crtc_state
->ycbcr420
&& scaler_user
== SKL_CRTC_INDEX
)
4491 need_scaling
= true;
4494 * Scaling/fitting not supported in IF-ID mode in GEN9+
4495 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4496 * Once NV12 is enabled, handle it here while allocating scaler
4499 if (INTEL_GEN(dev_priv
) >= 9 && crtc_state
->base
.enable
&&
4500 need_scaling
&& adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
4501 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
4506 * if plane is being disabled or scaler is no more required or force detach
4507 * - free scaler binded to this plane/crtc
4508 * - in order to do this, update crtc->scaler_usage
4510 * Here scaler state in crtc_state is set free so that
4511 * scaler can be assigned to other user. Actual register
4512 * update to free the scaler is done in plane/panel-fit programming.
4513 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4515 if (force_detach
|| !need_scaling
) {
4516 if (*scaler_id
>= 0) {
4517 scaler_state
->scaler_users
&= ~(1 << scaler_user
);
4518 scaler_state
->scalers
[*scaler_id
].in_use
= 0;
4520 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4521 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4522 intel_crtc
->pipe
, scaler_user
, *scaler_id
,
4523 scaler_state
->scaler_users
);
4530 if (src_w
< SKL_MIN_SRC_W
|| src_h
< SKL_MIN_SRC_H
||
4531 dst_w
< SKL_MIN_DST_W
|| dst_h
< SKL_MIN_DST_H
||
4533 src_w
> SKL_MAX_SRC_W
|| src_h
> SKL_MAX_SRC_H
||
4534 dst_w
> SKL_MAX_DST_W
|| dst_h
> SKL_MAX_DST_H
) {
4535 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4536 "size is out of scaler range\n",
4537 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
);
4541 /* mark this plane as a scaler user in crtc_state */
4542 scaler_state
->scaler_users
|= (1 << scaler_user
);
4543 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4544 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4545 intel_crtc
->pipe
, scaler_user
, src_w
, src_h
, dst_w
, dst_h
,
4546 scaler_state
->scaler_users
);
4552 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4554 * @state: crtc's scaler state
4557 * 0 - scaler_usage updated successfully
4558 * error - requested scaling cannot be supported or other error condition
4560 int skl_update_scaler_crtc(struct intel_crtc_state
*state
)
4562 const struct drm_display_mode
*adjusted_mode
= &state
->base
.adjusted_mode
;
4564 return skl_update_scaler(state
, !state
->base
.active
, SKL_CRTC_INDEX
,
4565 &state
->scaler_state
.scaler_id
,
4566 state
->pipe_src_w
, state
->pipe_src_h
,
4567 adjusted_mode
->crtc_hdisplay
, adjusted_mode
->crtc_vdisplay
);
4571 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4573 * @state: crtc's scaler state
4574 * @plane_state: atomic plane state to update
4577 * 0 - scaler_usage updated successfully
4578 * error - requested scaling cannot be supported or other error condition
4580 static int skl_update_scaler_plane(struct intel_crtc_state
*crtc_state
,
4581 struct intel_plane_state
*plane_state
)
4584 struct intel_plane
*intel_plane
=
4585 to_intel_plane(plane_state
->base
.plane
);
4586 struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
4589 bool force_detach
= !fb
|| !plane_state
->base
.visible
;
4591 ret
= skl_update_scaler(crtc_state
, force_detach
,
4592 drm_plane_index(&intel_plane
->base
),
4593 &plane_state
->scaler_id
,
4594 drm_rect_width(&plane_state
->base
.src
) >> 16,
4595 drm_rect_height(&plane_state
->base
.src
) >> 16,
4596 drm_rect_width(&plane_state
->base
.dst
),
4597 drm_rect_height(&plane_state
->base
.dst
));
4599 if (ret
|| plane_state
->scaler_id
< 0)
4602 /* check colorkey */
4603 if (plane_state
->ckey
.flags
!= I915_SET_COLORKEY_NONE
) {
4604 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
4605 intel_plane
->base
.base
.id
,
4606 intel_plane
->base
.name
);
4610 /* Check src format */
4611 switch (fb
->format
->format
) {
4612 case DRM_FORMAT_RGB565
:
4613 case DRM_FORMAT_XBGR8888
:
4614 case DRM_FORMAT_XRGB8888
:
4615 case DRM_FORMAT_ABGR8888
:
4616 case DRM_FORMAT_ARGB8888
:
4617 case DRM_FORMAT_XRGB2101010
:
4618 case DRM_FORMAT_XBGR2101010
:
4619 case DRM_FORMAT_YUYV
:
4620 case DRM_FORMAT_YVYU
:
4621 case DRM_FORMAT_UYVY
:
4622 case DRM_FORMAT_VYUY
:
4625 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
4626 intel_plane
->base
.base
.id
, intel_plane
->base
.name
,
4627 fb
->base
.id
, fb
->format
->format
);
4634 static void skylake_scaler_disable(struct intel_crtc
*crtc
)
4638 for (i
= 0; i
< crtc
->num_scalers
; i
++)
4639 skl_detach_scaler(crtc
, i
);
4642 static void skylake_pfit_enable(struct intel_crtc
*crtc
)
4644 struct drm_device
*dev
= crtc
->base
.dev
;
4645 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4646 int pipe
= crtc
->pipe
;
4647 struct intel_crtc_scaler_state
*scaler_state
=
4648 &crtc
->config
->scaler_state
;
4650 if (crtc
->config
->pch_pfit
.enabled
) {
4653 if (WARN_ON(crtc
->config
->scaler_state
.scaler_id
< 0))
4656 id
= scaler_state
->scaler_id
;
4657 I915_WRITE(SKL_PS_CTRL(pipe
, id
), PS_SCALER_EN
|
4658 PS_FILTER_MEDIUM
| scaler_state
->scalers
[id
].mode
);
4659 I915_WRITE(SKL_PS_WIN_POS(pipe
, id
), crtc
->config
->pch_pfit
.pos
);
4660 I915_WRITE(SKL_PS_WIN_SZ(pipe
, id
), crtc
->config
->pch_pfit
.size
);
4664 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
4666 struct drm_device
*dev
= crtc
->base
.dev
;
4667 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4668 int pipe
= crtc
->pipe
;
4670 if (crtc
->config
->pch_pfit
.enabled
) {
4671 /* Force use of hard-coded filter coefficients
4672 * as some pre-programmed values are broken,
4675 if (IS_IVYBRIDGE(dev_priv
) || IS_HASWELL(dev_priv
))
4676 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
4677 PF_PIPE_SEL_IVB(pipe
));
4679 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
4680 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
->pch_pfit
.pos
);
4681 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
->pch_pfit
.size
);
4685 void hsw_enable_ips(struct intel_crtc
*crtc
)
4687 struct drm_device
*dev
= crtc
->base
.dev
;
4688 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4690 if (!crtc
->config
->ips_enabled
)
4694 * We can only enable IPS after we enable a plane and wait for a vblank
4695 * This function is called from post_plane_update, which is run after
4699 assert_plane_enabled(dev_priv
, crtc
->plane
);
4700 if (IS_BROADWELL(dev_priv
)) {
4701 mutex_lock(&dev_priv
->rps
.hw_lock
);
4702 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
4703 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4704 /* Quoting Art Runyan: "its not safe to expect any particular
4705 * value in IPS_CTL bit 31 after enabling IPS through the
4706 * mailbox." Moreover, the mailbox may return a bogus state,
4707 * so we need to just enable it and continue on.
4710 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
4711 /* The bit only becomes 1 in the next vblank, so this wait here
4712 * is essentially intel_wait_for_vblank. If we don't have this
4713 * and don't wait for vblanks until the end of crtc_enable, then
4714 * the HW state readout code will complain that the expected
4715 * IPS_CTL value is not the one we read. */
4716 if (intel_wait_for_register(dev_priv
,
4717 IPS_CTL
, IPS_ENABLE
, IPS_ENABLE
,
4719 DRM_ERROR("Timed out waiting for IPS enable\n");
4723 void hsw_disable_ips(struct intel_crtc
*crtc
)
4725 struct drm_device
*dev
= crtc
->base
.dev
;
4726 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4728 if (!crtc
->config
->ips_enabled
)
4731 assert_plane_enabled(dev_priv
, crtc
->plane
);
4732 if (IS_BROADWELL(dev_priv
)) {
4733 mutex_lock(&dev_priv
->rps
.hw_lock
);
4734 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
4735 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4736 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4737 if (intel_wait_for_register(dev_priv
,
4738 IPS_CTL
, IPS_ENABLE
, 0,
4740 DRM_ERROR("Timed out waiting for IPS disable\n");
4742 I915_WRITE(IPS_CTL
, 0);
4743 POSTING_READ(IPS_CTL
);
4746 /* We need to wait for a vblank before we can disable the plane. */
4747 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
4750 static void intel_crtc_dpms_overlay_disable(struct intel_crtc
*intel_crtc
)
4752 if (intel_crtc
->overlay
) {
4753 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4755 mutex_lock(&dev
->struct_mutex
);
4756 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
4757 mutex_unlock(&dev
->struct_mutex
);
4760 /* Let userspace switch the overlay on again. In most cases userspace
4761 * has to recompute where to put it anyway.
4766 * intel_post_enable_primary - Perform operations after enabling primary plane
4767 * @crtc: the CRTC whose primary plane was just enabled
4769 * Performs potentially sleeping operations that must be done after the primary
4770 * plane is enabled, such as updating FBC and IPS. Note that this may be
4771 * called due to an explicit primary plane update, or due to an implicit
4772 * re-enable that is caused when a sprite plane is updated to no longer
4773 * completely hide the primary plane.
4776 intel_post_enable_primary(struct drm_crtc
*crtc
)
4778 struct drm_device
*dev
= crtc
->dev
;
4779 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4780 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4781 int pipe
= intel_crtc
->pipe
;
4784 * FIXME IPS should be fine as long as one plane is
4785 * enabled, but in practice it seems to have problems
4786 * when going from primary only to sprite only and vice
4789 hsw_enable_ips(intel_crtc
);
4792 * Gen2 reports pipe underruns whenever all planes are disabled.
4793 * So don't enable underrun reporting before at least some planes
4795 * FIXME: Need to fix the logic to work when we turn off all planes
4796 * but leave the pipe running.
4798 if (IS_GEN2(dev_priv
))
4799 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4801 /* Underruns don't always raise interrupts, so check manually. */
4802 intel_check_cpu_fifo_underruns(dev_priv
);
4803 intel_check_pch_fifo_underruns(dev_priv
);
4806 /* FIXME move all this to pre_plane_update() with proper state tracking */
4808 intel_pre_disable_primary(struct drm_crtc
*crtc
)
4810 struct drm_device
*dev
= crtc
->dev
;
4811 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4812 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4813 int pipe
= intel_crtc
->pipe
;
4816 * Gen2 reports pipe underruns whenever all planes are disabled.
4817 * So diasble underrun reporting before all the planes get disabled.
4818 * FIXME: Need to fix the logic to work when we turn off all planes
4819 * but leave the pipe running.
4821 if (IS_GEN2(dev_priv
))
4822 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4825 * FIXME IPS should be fine as long as one plane is
4826 * enabled, but in practice it seems to have problems
4827 * when going from primary only to sprite only and vice
4830 hsw_disable_ips(intel_crtc
);
4833 /* FIXME get rid of this and use pre_plane_update */
4835 intel_pre_disable_primary_noatomic(struct drm_crtc
*crtc
)
4837 struct drm_device
*dev
= crtc
->dev
;
4838 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4839 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4840 int pipe
= intel_crtc
->pipe
;
4842 intel_pre_disable_primary(crtc
);
4845 * Vblank time updates from the shadow to live plane control register
4846 * are blocked if the memory self-refresh mode is active at that
4847 * moment. So to make sure the plane gets truly disabled, disable
4848 * first the self-refresh mode. The self-refresh enable bit in turn
4849 * will be checked/applied by the HW only at the next frame start
4850 * event which is after the vblank start event, so we need to have a
4851 * wait-for-vblank between disabling the plane and the pipe.
4853 if (HAS_GMCH_DISPLAY(dev_priv
) &&
4854 intel_set_memory_cxsr(dev_priv
, false))
4855 intel_wait_for_vblank(dev_priv
, pipe
);
4858 static void intel_post_plane_update(struct intel_crtc_state
*old_crtc_state
)
4860 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
4861 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
4862 struct intel_crtc_state
*pipe_config
=
4863 to_intel_crtc_state(crtc
->base
.state
);
4864 struct drm_plane
*primary
= crtc
->base
.primary
;
4865 struct drm_plane_state
*old_pri_state
=
4866 drm_atomic_get_existing_plane_state(old_state
, primary
);
4868 intel_frontbuffer_flip(to_i915(crtc
->base
.dev
), pipe_config
->fb_bits
);
4870 if (pipe_config
->update_wm_post
&& pipe_config
->base
.active
)
4871 intel_update_watermarks(crtc
);
4873 if (old_pri_state
) {
4874 struct intel_plane_state
*primary_state
=
4875 to_intel_plane_state(primary
->state
);
4876 struct intel_plane_state
*old_primary_state
=
4877 to_intel_plane_state(old_pri_state
);
4879 intel_fbc_post_update(crtc
);
4881 if (primary_state
->base
.visible
&&
4882 (needs_modeset(&pipe_config
->base
) ||
4883 !old_primary_state
->base
.visible
))
4884 intel_post_enable_primary(&crtc
->base
);
4888 static void intel_pre_plane_update(struct intel_crtc_state
*old_crtc_state
,
4889 struct intel_crtc_state
*pipe_config
)
4891 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->base
.crtc
);
4892 struct drm_device
*dev
= crtc
->base
.dev
;
4893 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4894 struct drm_atomic_state
*old_state
= old_crtc_state
->base
.state
;
4895 struct drm_plane
*primary
= crtc
->base
.primary
;
4896 struct drm_plane_state
*old_pri_state
=
4897 drm_atomic_get_existing_plane_state(old_state
, primary
);
4898 bool modeset
= needs_modeset(&pipe_config
->base
);
4899 struct intel_atomic_state
*old_intel_state
=
4900 to_intel_atomic_state(old_state
);
4902 if (old_pri_state
) {
4903 struct intel_plane_state
*primary_state
=
4904 to_intel_plane_state(primary
->state
);
4905 struct intel_plane_state
*old_primary_state
=
4906 to_intel_plane_state(old_pri_state
);
4908 intel_fbc_pre_update(crtc
, pipe_config
, primary_state
);
4910 if (old_primary_state
->base
.visible
&&
4911 (modeset
|| !primary_state
->base
.visible
))
4912 intel_pre_disable_primary(&crtc
->base
);
4916 * Vblank time updates from the shadow to live plane control register
4917 * are blocked if the memory self-refresh mode is active at that
4918 * moment. So to make sure the plane gets truly disabled, disable
4919 * first the self-refresh mode. The self-refresh enable bit in turn
4920 * will be checked/applied by the HW only at the next frame start
4921 * event which is after the vblank start event, so we need to have a
4922 * wait-for-vblank between disabling the plane and the pipe.
4924 if (HAS_GMCH_DISPLAY(dev_priv
) && old_crtc_state
->base
.active
&&
4925 pipe_config
->disable_cxsr
&& intel_set_memory_cxsr(dev_priv
, false))
4926 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
4929 * IVB workaround: must disable low power watermarks for at least
4930 * one frame before enabling scaling. LP watermarks can be re-enabled
4931 * when scaling is disabled.
4933 * WaCxSRDisabledForSpriteScaling:ivb
4935 if (pipe_config
->disable_lp_wm
&& ilk_disable_lp_wm(dev
))
4936 intel_wait_for_vblank(dev_priv
, crtc
->pipe
);
4939 * If we're doing a modeset, we're done. No need to do any pre-vblank
4940 * watermark programming here.
4942 if (needs_modeset(&pipe_config
->base
))
4946 * For platforms that support atomic watermarks, program the
4947 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
4948 * will be the intermediate values that are safe for both pre- and
4949 * post- vblank; when vblank happens, the 'active' values will be set
4950 * to the final 'target' values and we'll do this again to get the
4951 * optimal watermarks. For gen9+ platforms, the values we program here
4952 * will be the final target values which will get automatically latched
4953 * at vblank time; no further programming will be necessary.
4955 * If a platform hasn't been transitioned to atomic watermarks yet,
4956 * we'll continue to update watermarks the old way, if flags tell
4959 if (dev_priv
->display
.initial_watermarks
!= NULL
)
4960 dev_priv
->display
.initial_watermarks(old_intel_state
,
4962 else if (pipe_config
->update_wm_pre
)
4963 intel_update_watermarks(crtc
);
4966 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
, unsigned plane_mask
)
4968 struct drm_device
*dev
= crtc
->dev
;
4969 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4970 struct drm_plane
*p
;
4971 int pipe
= intel_crtc
->pipe
;
4973 intel_crtc_dpms_overlay_disable(intel_crtc
);
4975 drm_for_each_plane_mask(p
, dev
, plane_mask
)
4976 to_intel_plane(p
)->disable_plane(to_intel_plane(p
), intel_crtc
);
4979 * FIXME: Once we grow proper nuclear flip support out of this we need
4980 * to compute the mask of flip planes precisely. For the time being
4981 * consider this a flip to a NULL plane.
4983 intel_frontbuffer_flip(to_i915(dev
), INTEL_FRONTBUFFER_ALL_MASK(pipe
));
4986 static void intel_encoders_pre_pll_enable(struct drm_crtc
*crtc
,
4987 struct intel_crtc_state
*crtc_state
,
4988 struct drm_atomic_state
*old_state
)
4990 struct drm_connector_state
*conn_state
;
4991 struct drm_connector
*conn
;
4994 for_each_new_connector_in_state(old_state
, conn
, conn_state
, i
) {
4995 struct intel_encoder
*encoder
=
4996 to_intel_encoder(conn_state
->best_encoder
);
4998 if (conn_state
->crtc
!= crtc
)
5001 if (encoder
->pre_pll_enable
)
5002 encoder
->pre_pll_enable(encoder
, crtc_state
, conn_state
);
5006 static void intel_encoders_pre_enable(struct drm_crtc
*crtc
,
5007 struct intel_crtc_state
*crtc_state
,
5008 struct drm_atomic_state
*old_state
)
5010 struct drm_connector_state
*conn_state
;
5011 struct drm_connector
*conn
;
5014 for_each_new_connector_in_state(old_state
, conn
, conn_state
, i
) {
5015 struct intel_encoder
*encoder
=
5016 to_intel_encoder(conn_state
->best_encoder
);
5018 if (conn_state
->crtc
!= crtc
)
5021 if (encoder
->pre_enable
)
5022 encoder
->pre_enable(encoder
, crtc_state
, conn_state
);
5026 static void intel_encoders_enable(struct drm_crtc
*crtc
,
5027 struct intel_crtc_state
*crtc_state
,
5028 struct drm_atomic_state
*old_state
)
5030 struct drm_connector_state
*conn_state
;
5031 struct drm_connector
*conn
;
5034 for_each_new_connector_in_state(old_state
, conn
, conn_state
, i
) {
5035 struct intel_encoder
*encoder
=
5036 to_intel_encoder(conn_state
->best_encoder
);
5038 if (conn_state
->crtc
!= crtc
)
5041 encoder
->enable(encoder
, crtc_state
, conn_state
);
5042 intel_opregion_notify_encoder(encoder
, true);
5046 static void intel_encoders_disable(struct drm_crtc
*crtc
,
5047 struct intel_crtc_state
*old_crtc_state
,
5048 struct drm_atomic_state
*old_state
)
5050 struct drm_connector_state
*old_conn_state
;
5051 struct drm_connector
*conn
;
5054 for_each_old_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5055 struct intel_encoder
*encoder
=
5056 to_intel_encoder(old_conn_state
->best_encoder
);
5058 if (old_conn_state
->crtc
!= crtc
)
5061 intel_opregion_notify_encoder(encoder
, false);
5062 encoder
->disable(encoder
, old_crtc_state
, old_conn_state
);
5066 static void intel_encoders_post_disable(struct drm_crtc
*crtc
,
5067 struct intel_crtc_state
*old_crtc_state
,
5068 struct drm_atomic_state
*old_state
)
5070 struct drm_connector_state
*old_conn_state
;
5071 struct drm_connector
*conn
;
5074 for_each_old_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5075 struct intel_encoder
*encoder
=
5076 to_intel_encoder(old_conn_state
->best_encoder
);
5078 if (old_conn_state
->crtc
!= crtc
)
5081 if (encoder
->post_disable
)
5082 encoder
->post_disable(encoder
, old_crtc_state
, old_conn_state
);
5086 static void intel_encoders_post_pll_disable(struct drm_crtc
*crtc
,
5087 struct intel_crtc_state
*old_crtc_state
,
5088 struct drm_atomic_state
*old_state
)
5090 struct drm_connector_state
*old_conn_state
;
5091 struct drm_connector
*conn
;
5094 for_each_old_connector_in_state(old_state
, conn
, old_conn_state
, i
) {
5095 struct intel_encoder
*encoder
=
5096 to_intel_encoder(old_conn_state
->best_encoder
);
5098 if (old_conn_state
->crtc
!= crtc
)
5101 if (encoder
->post_pll_disable
)
5102 encoder
->post_pll_disable(encoder
, old_crtc_state
, old_conn_state
);
5106 static void ironlake_crtc_enable(struct intel_crtc_state
*pipe_config
,
5107 struct drm_atomic_state
*old_state
)
5109 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5110 struct drm_device
*dev
= crtc
->dev
;
5111 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5112 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5113 int pipe
= intel_crtc
->pipe
;
5114 struct intel_atomic_state
*old_intel_state
=
5115 to_intel_atomic_state(old_state
);
5117 if (WARN_ON(intel_crtc
->active
))
5121 * Sometimes spurious CPU pipe underruns happen during FDI
5122 * training, at least with VGA+HDMI cloning. Suppress them.
5124 * On ILK we get an occasional spurious CPU pipe underruns
5125 * between eDP port A enable and vdd enable. Also PCH port
5126 * enable seems to result in the occasional CPU pipe underrun.
5128 * Spurious PCH underruns also occur during PCH enabling.
5130 if (intel_crtc
->config
->has_pch_encoder
|| IS_GEN5(dev_priv
))
5131 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5132 if (intel_crtc
->config
->has_pch_encoder
)
5133 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
5135 if (intel_crtc
->config
->has_pch_encoder
)
5136 intel_prepare_shared_dpll(intel_crtc
);
5138 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5139 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5141 intel_set_pipe_timings(intel_crtc
);
5142 intel_set_pipe_src_size(intel_crtc
);
5144 if (intel_crtc
->config
->has_pch_encoder
) {
5145 intel_cpu_transcoder_set_m_n(intel_crtc
,
5146 &intel_crtc
->config
->fdi_m_n
, NULL
);
5149 ironlake_set_pipeconf(crtc
);
5151 intel_crtc
->active
= true;
5153 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5155 if (intel_crtc
->config
->has_pch_encoder
) {
5156 /* Note: FDI PLL enabling _must_ be done before we enable the
5157 * cpu pipes, hence this is separate from all the other fdi/pch
5159 ironlake_fdi_pll_enable(intel_crtc
);
5161 assert_fdi_tx_disabled(dev_priv
, pipe
);
5162 assert_fdi_rx_disabled(dev_priv
, pipe
);
5165 ironlake_pfit_enable(intel_crtc
);
5168 * On ILK+ LUT must be loaded before the pipe is running but with
5171 intel_color_load_luts(&pipe_config
->base
);
5173 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5174 dev_priv
->display
.initial_watermarks(old_intel_state
, intel_crtc
->config
);
5175 intel_enable_pipe(intel_crtc
);
5177 if (intel_crtc
->config
->has_pch_encoder
)
5178 ironlake_pch_enable(pipe_config
);
5180 assert_vblank_disabled(crtc
);
5181 drm_crtc_vblank_on(crtc
);
5183 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5185 if (HAS_PCH_CPT(dev_priv
))
5186 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
5188 /* Must wait for vblank to avoid spurious PCH FIFO underruns */
5189 if (intel_crtc
->config
->has_pch_encoder
)
5190 intel_wait_for_vblank(dev_priv
, pipe
);
5191 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5192 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
5195 /* IPS only exists on ULT machines and is tied to pipe A. */
5196 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
5198 return HAS_IPS(to_i915(crtc
->base
.dev
)) && crtc
->pipe
== PIPE_A
;
5201 static void haswell_crtc_enable(struct intel_crtc_state
*pipe_config
,
5202 struct drm_atomic_state
*old_state
)
5204 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5205 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5206 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5207 int pipe
= intel_crtc
->pipe
, hsw_workaround_pipe
;
5208 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5209 struct intel_atomic_state
*old_intel_state
=
5210 to_intel_atomic_state(old_state
);
5212 if (WARN_ON(intel_crtc
->active
))
5215 if (intel_crtc
->config
->has_pch_encoder
)
5216 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, false);
5218 intel_encoders_pre_pll_enable(crtc
, pipe_config
, old_state
);
5220 if (intel_crtc
->config
->shared_dpll
)
5221 intel_enable_shared_dpll(intel_crtc
);
5223 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5224 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5226 if (!transcoder_is_dsi(cpu_transcoder
))
5227 intel_set_pipe_timings(intel_crtc
);
5229 intel_set_pipe_src_size(intel_crtc
);
5231 if (cpu_transcoder
!= TRANSCODER_EDP
&&
5232 !transcoder_is_dsi(cpu_transcoder
)) {
5233 I915_WRITE(PIPE_MULT(cpu_transcoder
),
5234 intel_crtc
->config
->pixel_multiplier
- 1);
5237 if (intel_crtc
->config
->has_pch_encoder
) {
5238 intel_cpu_transcoder_set_m_n(intel_crtc
,
5239 &intel_crtc
->config
->fdi_m_n
, NULL
);
5242 if (!transcoder_is_dsi(cpu_transcoder
))
5243 haswell_set_pipeconf(crtc
);
5245 haswell_set_pipemisc(crtc
);
5247 intel_color_set_csc(&pipe_config
->base
);
5249 intel_crtc
->active
= true;
5251 if (intel_crtc
->config
->has_pch_encoder
)
5252 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5254 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5256 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5258 if (intel_crtc
->config
->has_pch_encoder
)
5259 dev_priv
->display
.fdi_link_train(intel_crtc
, pipe_config
);
5261 if (!transcoder_is_dsi(cpu_transcoder
))
5262 intel_ddi_enable_pipe_clock(pipe_config
);
5264 if (INTEL_GEN(dev_priv
) >= 9)
5265 skylake_pfit_enable(intel_crtc
);
5267 ironlake_pfit_enable(intel_crtc
);
5270 * On ILK+ LUT must be loaded before the pipe is running but with
5273 intel_color_load_luts(&pipe_config
->base
);
5275 intel_ddi_set_pipe_settings(pipe_config
);
5276 if (!transcoder_is_dsi(cpu_transcoder
))
5277 intel_ddi_enable_transcoder_func(pipe_config
);
5279 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5280 dev_priv
->display
.initial_watermarks(old_intel_state
, pipe_config
);
5282 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5283 if (!transcoder_is_dsi(cpu_transcoder
))
5284 intel_enable_pipe(intel_crtc
);
5286 if (intel_crtc
->config
->has_pch_encoder
)
5287 lpt_pch_enable(pipe_config
);
5289 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DP_MST
))
5290 intel_ddi_set_vc_payload_alloc(pipe_config
, true);
5292 assert_vblank_disabled(crtc
);
5293 drm_crtc_vblank_on(crtc
);
5295 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5297 if (intel_crtc
->config
->has_pch_encoder
) {
5298 intel_wait_for_vblank(dev_priv
, pipe
);
5299 intel_wait_for_vblank(dev_priv
, pipe
);
5300 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5301 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, true);
5304 /* If we change the relative order between pipe/planes enabling, we need
5305 * to change the workaround. */
5306 hsw_workaround_pipe
= pipe_config
->hsw_workaround_pipe
;
5307 if (IS_HASWELL(dev_priv
) && hsw_workaround_pipe
!= INVALID_PIPE
) {
5308 intel_wait_for_vblank(dev_priv
, hsw_workaround_pipe
);
5309 intel_wait_for_vblank(dev_priv
, hsw_workaround_pipe
);
5313 static void ironlake_pfit_disable(struct intel_crtc
*crtc
, bool force
)
5315 struct drm_device
*dev
= crtc
->base
.dev
;
5316 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5317 int pipe
= crtc
->pipe
;
5319 /* To avoid upsetting the power well on haswell only disable the pfit if
5320 * it's in use. The hw state code will make sure we get this right. */
5321 if (force
|| crtc
->config
->pch_pfit
.enabled
) {
5322 I915_WRITE(PF_CTL(pipe
), 0);
5323 I915_WRITE(PF_WIN_POS(pipe
), 0);
5324 I915_WRITE(PF_WIN_SZ(pipe
), 0);
5328 static void ironlake_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5329 struct drm_atomic_state
*old_state
)
5331 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5332 struct drm_device
*dev
= crtc
->dev
;
5333 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5334 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5335 int pipe
= intel_crtc
->pipe
;
5338 * Sometimes spurious CPU pipe underruns happen when the
5339 * pipe is already disabled, but FDI RX/TX is still enabled.
5340 * Happens at least with VGA+HDMI cloning. Suppress them.
5342 if (intel_crtc
->config
->has_pch_encoder
) {
5343 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5344 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
5347 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5349 drm_crtc_vblank_off(crtc
);
5350 assert_vblank_disabled(crtc
);
5352 intel_disable_pipe(intel_crtc
);
5354 ironlake_pfit_disable(intel_crtc
, false);
5356 if (intel_crtc
->config
->has_pch_encoder
)
5357 ironlake_fdi_disable(crtc
);
5359 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5361 if (intel_crtc
->config
->has_pch_encoder
) {
5362 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
5364 if (HAS_PCH_CPT(dev_priv
)) {
5368 /* disable TRANS_DP_CTL */
5369 reg
= TRANS_DP_CTL(pipe
);
5370 temp
= I915_READ(reg
);
5371 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
5372 TRANS_DP_PORT_SEL_MASK
);
5373 temp
|= TRANS_DP_PORT_SEL_NONE
;
5374 I915_WRITE(reg
, temp
);
5376 /* disable DPLL_SEL */
5377 temp
= I915_READ(PCH_DPLL_SEL
);
5378 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
5379 I915_WRITE(PCH_DPLL_SEL
, temp
);
5382 ironlake_fdi_pll_disable(intel_crtc
);
5385 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5386 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
5389 static void haswell_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5390 struct drm_atomic_state
*old_state
)
5392 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5393 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5394 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5395 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5397 if (intel_crtc
->config
->has_pch_encoder
)
5398 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, false);
5400 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5402 drm_crtc_vblank_off(crtc
);
5403 assert_vblank_disabled(crtc
);
5405 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5406 if (!transcoder_is_dsi(cpu_transcoder
))
5407 intel_disable_pipe(intel_crtc
);
5409 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DP_MST
))
5410 intel_ddi_set_vc_payload_alloc(intel_crtc
->config
, false);
5412 if (!transcoder_is_dsi(cpu_transcoder
))
5413 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
5415 if (INTEL_GEN(dev_priv
) >= 9)
5416 skylake_scaler_disable(intel_crtc
);
5418 ironlake_pfit_disable(intel_crtc
, false);
5420 if (!transcoder_is_dsi(cpu_transcoder
))
5421 intel_ddi_disable_pipe_clock(intel_crtc
->config
);
5423 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5425 if (old_crtc_state
->has_pch_encoder
)
5426 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, true);
5429 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
5431 struct drm_device
*dev
= crtc
->base
.dev
;
5432 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5433 struct intel_crtc_state
*pipe_config
= crtc
->config
;
5435 if (!pipe_config
->gmch_pfit
.control
)
5439 * The panel fitter should only be adjusted whilst the pipe is disabled,
5440 * according to register description and PRM.
5442 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
5443 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5445 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
5446 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
5448 /* Border color in case we don't scale up to the full screen. Black by
5449 * default, change to something else for debugging. */
5450 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
5453 enum intel_display_power_domain
intel_port_to_power_domain(enum port port
)
5457 return POWER_DOMAIN_PORT_DDI_A_LANES
;
5459 return POWER_DOMAIN_PORT_DDI_B_LANES
;
5461 return POWER_DOMAIN_PORT_DDI_C_LANES
;
5463 return POWER_DOMAIN_PORT_DDI_D_LANES
;
5465 return POWER_DOMAIN_PORT_DDI_E_LANES
;
5468 return POWER_DOMAIN_PORT_OTHER
;
5472 static u64
get_crtc_power_domains(struct drm_crtc
*crtc
,
5473 struct intel_crtc_state
*crtc_state
)
5475 struct drm_device
*dev
= crtc
->dev
;
5476 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5477 struct drm_encoder
*encoder
;
5478 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5479 enum pipe pipe
= intel_crtc
->pipe
;
5481 enum transcoder transcoder
= crtc_state
->cpu_transcoder
;
5483 if (!crtc_state
->base
.active
)
5486 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
5487 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
5488 if (crtc_state
->pch_pfit
.enabled
||
5489 crtc_state
->pch_pfit
.force_thru
)
5490 mask
|= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
5492 drm_for_each_encoder_mask(encoder
, dev
, crtc_state
->base
.encoder_mask
) {
5493 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5495 mask
|= BIT_ULL(intel_encoder
->power_domain
);
5498 if (HAS_DDI(dev_priv
) && crtc_state
->has_audio
)
5499 mask
|= BIT(POWER_DOMAIN_AUDIO
);
5501 if (crtc_state
->shared_dpll
)
5502 mask
|= BIT_ULL(POWER_DOMAIN_PLLS
);
5508 modeset_get_crtc_power_domains(struct drm_crtc
*crtc
,
5509 struct intel_crtc_state
*crtc_state
)
5511 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5512 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5513 enum intel_display_power_domain domain
;
5514 u64 domains
, new_domains
, old_domains
;
5516 old_domains
= intel_crtc
->enabled_power_domains
;
5517 intel_crtc
->enabled_power_domains
= new_domains
=
5518 get_crtc_power_domains(crtc
, crtc_state
);
5520 domains
= new_domains
& ~old_domains
;
5522 for_each_power_domain(domain
, domains
)
5523 intel_display_power_get(dev_priv
, domain
);
5525 return old_domains
& ~new_domains
;
5528 static void modeset_put_power_domains(struct drm_i915_private
*dev_priv
,
5531 enum intel_display_power_domain domain
;
5533 for_each_power_domain(domain
, domains
)
5534 intel_display_power_put(dev_priv
, domain
);
5537 static void valleyview_crtc_enable(struct intel_crtc_state
*pipe_config
,
5538 struct drm_atomic_state
*old_state
)
5540 struct intel_atomic_state
*old_intel_state
=
5541 to_intel_atomic_state(old_state
);
5542 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5543 struct drm_device
*dev
= crtc
->dev
;
5544 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5545 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5546 int pipe
= intel_crtc
->pipe
;
5548 if (WARN_ON(intel_crtc
->active
))
5551 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5552 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5554 intel_set_pipe_timings(intel_crtc
);
5555 intel_set_pipe_src_size(intel_crtc
);
5557 if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_B
) {
5558 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5560 I915_WRITE(CHV_BLEND(pipe
), CHV_BLEND_LEGACY
);
5561 I915_WRITE(CHV_CANVAS(pipe
), 0);
5564 i9xx_set_pipeconf(intel_crtc
);
5566 intel_crtc
->active
= true;
5568 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5570 intel_encoders_pre_pll_enable(crtc
, pipe_config
, old_state
);
5572 if (IS_CHERRYVIEW(dev_priv
)) {
5573 chv_prepare_pll(intel_crtc
, intel_crtc
->config
);
5574 chv_enable_pll(intel_crtc
, intel_crtc
->config
);
5576 vlv_prepare_pll(intel_crtc
, intel_crtc
->config
);
5577 vlv_enable_pll(intel_crtc
, intel_crtc
->config
);
5580 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5582 i9xx_pfit_enable(intel_crtc
);
5584 intel_color_load_luts(&pipe_config
->base
);
5586 dev_priv
->display
.initial_watermarks(old_intel_state
,
5588 intel_enable_pipe(intel_crtc
);
5590 assert_vblank_disabled(crtc
);
5591 drm_crtc_vblank_on(crtc
);
5593 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5596 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
5598 struct drm_device
*dev
= crtc
->base
.dev
;
5599 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5601 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp0
);
5602 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp1
);
5605 static void i9xx_crtc_enable(struct intel_crtc_state
*pipe_config
,
5606 struct drm_atomic_state
*old_state
)
5608 struct intel_atomic_state
*old_intel_state
=
5609 to_intel_atomic_state(old_state
);
5610 struct drm_crtc
*crtc
= pipe_config
->base
.crtc
;
5611 struct drm_device
*dev
= crtc
->dev
;
5612 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5613 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5614 enum pipe pipe
= intel_crtc
->pipe
;
5616 if (WARN_ON(intel_crtc
->active
))
5619 i9xx_set_pll_dividers(intel_crtc
);
5621 if (intel_crtc_has_dp_encoder(intel_crtc
->config
))
5622 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5624 intel_set_pipe_timings(intel_crtc
);
5625 intel_set_pipe_src_size(intel_crtc
);
5627 i9xx_set_pipeconf(intel_crtc
);
5629 intel_crtc
->active
= true;
5631 if (!IS_GEN2(dev_priv
))
5632 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5634 intel_encoders_pre_enable(crtc
, pipe_config
, old_state
);
5636 i9xx_enable_pll(intel_crtc
);
5638 i9xx_pfit_enable(intel_crtc
);
5640 intel_color_load_luts(&pipe_config
->base
);
5642 if (dev_priv
->display
.initial_watermarks
!= NULL
)
5643 dev_priv
->display
.initial_watermarks(old_intel_state
,
5644 intel_crtc
->config
);
5646 intel_update_watermarks(intel_crtc
);
5647 intel_enable_pipe(intel_crtc
);
5649 assert_vblank_disabled(crtc
);
5650 drm_crtc_vblank_on(crtc
);
5652 intel_encoders_enable(crtc
, pipe_config
, old_state
);
5655 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
5657 struct drm_device
*dev
= crtc
->base
.dev
;
5658 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5660 if (!crtc
->config
->gmch_pfit
.control
)
5663 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5665 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
5666 I915_READ(PFIT_CONTROL
));
5667 I915_WRITE(PFIT_CONTROL
, 0);
5670 static void i9xx_crtc_disable(struct intel_crtc_state
*old_crtc_state
,
5671 struct drm_atomic_state
*old_state
)
5673 struct drm_crtc
*crtc
= old_crtc_state
->base
.crtc
;
5674 struct drm_device
*dev
= crtc
->dev
;
5675 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5676 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5677 int pipe
= intel_crtc
->pipe
;
5680 * On gen2 planes are double buffered but the pipe isn't, so we must
5681 * wait for planes to fully turn off before disabling the pipe.
5683 if (IS_GEN2(dev_priv
))
5684 intel_wait_for_vblank(dev_priv
, pipe
);
5686 intel_encoders_disable(crtc
, old_crtc_state
, old_state
);
5688 drm_crtc_vblank_off(crtc
);
5689 assert_vblank_disabled(crtc
);
5691 intel_disable_pipe(intel_crtc
);
5693 i9xx_pfit_disable(intel_crtc
);
5695 intel_encoders_post_disable(crtc
, old_crtc_state
, old_state
);
5697 if (!intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_DSI
)) {
5698 if (IS_CHERRYVIEW(dev_priv
))
5699 chv_disable_pll(dev_priv
, pipe
);
5700 else if (IS_VALLEYVIEW(dev_priv
))
5701 vlv_disable_pll(dev_priv
, pipe
);
5703 i9xx_disable_pll(intel_crtc
);
5706 intel_encoders_post_pll_disable(crtc
, old_crtc_state
, old_state
);
5708 if (!IS_GEN2(dev_priv
))
5709 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5711 if (!dev_priv
->display
.initial_watermarks
)
5712 intel_update_watermarks(intel_crtc
);
5714 /* clock the pipe down to 640x480@60 to potentially save power */
5715 if (IS_I830(dev_priv
))
5716 i830_enable_pipe(dev_priv
, pipe
);
5719 static void intel_crtc_disable_noatomic(struct drm_crtc
*crtc
,
5720 struct drm_modeset_acquire_ctx
*ctx
)
5722 struct intel_encoder
*encoder
;
5723 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5724 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
5725 enum intel_display_power_domain domain
;
5727 struct drm_atomic_state
*state
;
5728 struct intel_crtc_state
*crtc_state
;
5731 if (!intel_crtc
->active
)
5734 if (crtc
->primary
->state
->visible
) {
5735 intel_pre_disable_primary_noatomic(crtc
);
5737 intel_crtc_disable_planes(crtc
, 1 << drm_plane_index(crtc
->primary
));
5738 crtc
->primary
->state
->visible
= false;
5741 state
= drm_atomic_state_alloc(crtc
->dev
);
5743 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
5744 crtc
->base
.id
, crtc
->name
);
5748 state
->acquire_ctx
= ctx
;
5750 /* Everything's already locked, -EDEADLK can't happen. */
5751 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
5752 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
5754 WARN_ON(IS_ERR(crtc_state
) || ret
);
5756 dev_priv
->display
.crtc_disable(crtc_state
, state
);
5758 drm_atomic_state_put(state
);
5760 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
5761 crtc
->base
.id
, crtc
->name
);
5763 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->state
, NULL
) < 0);
5764 crtc
->state
->active
= false;
5765 intel_crtc
->active
= false;
5766 crtc
->enabled
= false;
5767 crtc
->state
->connector_mask
= 0;
5768 crtc
->state
->encoder_mask
= 0;
5770 for_each_encoder_on_crtc(crtc
->dev
, crtc
, encoder
)
5771 encoder
->base
.crtc
= NULL
;
5773 intel_fbc_disable(intel_crtc
);
5774 intel_update_watermarks(intel_crtc
);
5775 intel_disable_shared_dpll(intel_crtc
);
5777 domains
= intel_crtc
->enabled_power_domains
;
5778 for_each_power_domain(domain
, domains
)
5779 intel_display_power_put(dev_priv
, domain
);
5780 intel_crtc
->enabled_power_domains
= 0;
5782 dev_priv
->active_crtcs
&= ~(1 << intel_crtc
->pipe
);
5783 dev_priv
->min_pixclk
[intel_crtc
->pipe
] = 0;
5787 * turn all crtc's off, but do not adjust state
5788 * This has to be paired with a call to intel_modeset_setup_hw_state.
5790 int intel_display_suspend(struct drm_device
*dev
)
5792 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5793 struct drm_atomic_state
*state
;
5796 state
= drm_atomic_helper_suspend(dev
);
5797 ret
= PTR_ERR_OR_ZERO(state
);
5799 DRM_ERROR("Suspending crtc's failed with %i\n", ret
);
5801 dev_priv
->modeset_restore_state
= state
;
5805 void intel_encoder_destroy(struct drm_encoder
*encoder
)
5807 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5809 drm_encoder_cleanup(encoder
);
5810 kfree(intel_encoder
);
5813 /* Cross check the actual hw state with our own modeset state tracking (and it's
5814 * internal consistency). */
5815 static void intel_connector_verify_state(struct drm_crtc_state
*crtc_state
,
5816 struct drm_connector_state
*conn_state
)
5818 struct intel_connector
*connector
= to_intel_connector(conn_state
->connector
);
5820 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
5821 connector
->base
.base
.id
,
5822 connector
->base
.name
);
5824 if (connector
->get_hw_state(connector
)) {
5825 struct intel_encoder
*encoder
= connector
->encoder
;
5827 I915_STATE_WARN(!crtc_state
,
5828 "connector enabled without attached crtc\n");
5833 I915_STATE_WARN(!crtc_state
->active
,
5834 "connector is active, but attached crtc isn't\n");
5836 if (!encoder
|| encoder
->type
== INTEL_OUTPUT_DP_MST
)
5839 I915_STATE_WARN(conn_state
->best_encoder
!= &encoder
->base
,
5840 "atomic encoder doesn't match attached encoder\n");
5842 I915_STATE_WARN(conn_state
->crtc
!= encoder
->base
.crtc
,
5843 "attached encoder crtc differs from connector crtc\n");
5845 I915_STATE_WARN(crtc_state
&& crtc_state
->active
,
5846 "attached crtc is active, but connector isn't\n");
5847 I915_STATE_WARN(!crtc_state
&& conn_state
->best_encoder
,
5848 "best encoder set without crtc!\n");
5852 int intel_connector_init(struct intel_connector
*connector
)
5854 struct intel_digital_connector_state
*conn_state
;
5857 * Allocate enough memory to hold intel_digital_connector_state,
5858 * This might be a few bytes too many, but for connectors that don't
5859 * need it we'll free the state and allocate a smaller one on the first
5860 * succesful commit anyway.
5862 conn_state
= kzalloc(sizeof(*conn_state
), GFP_KERNEL
);
5866 __drm_atomic_helper_connector_reset(&connector
->base
,
5872 struct intel_connector
*intel_connector_alloc(void)
5874 struct intel_connector
*connector
;
5876 connector
= kzalloc(sizeof *connector
, GFP_KERNEL
);
5880 if (intel_connector_init(connector
) < 0) {
5888 /* Simple connector->get_hw_state implementation for encoders that support only
5889 * one connector and no cloning and hence the encoder state determines the state
5890 * of the connector. */
5891 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
5894 struct intel_encoder
*encoder
= connector
->encoder
;
5896 return encoder
->get_hw_state(encoder
, &pipe
);
5899 static int pipe_required_fdi_lanes(struct intel_crtc_state
*crtc_state
)
5901 if (crtc_state
->base
.enable
&& crtc_state
->has_pch_encoder
)
5902 return crtc_state
->fdi_lanes
;
5907 static int ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
5908 struct intel_crtc_state
*pipe_config
)
5910 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5911 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
5912 struct intel_crtc
*other_crtc
;
5913 struct intel_crtc_state
*other_crtc_state
;
5915 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
5916 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5917 if (pipe_config
->fdi_lanes
> 4) {
5918 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
5919 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5923 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
5924 if (pipe_config
->fdi_lanes
> 2) {
5925 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
5926 pipe_config
->fdi_lanes
);
5933 if (INTEL_INFO(dev_priv
)->num_pipes
== 2)
5936 /* Ivybridge 3 pipe is really complicated */
5941 if (pipe_config
->fdi_lanes
<= 2)
5944 other_crtc
= intel_get_crtc_for_pipe(dev_priv
, PIPE_C
);
5946 intel_atomic_get_crtc_state(state
, other_crtc
);
5947 if (IS_ERR(other_crtc_state
))
5948 return PTR_ERR(other_crtc_state
);
5950 if (pipe_required_fdi_lanes(other_crtc_state
) > 0) {
5951 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5952 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5957 if (pipe_config
->fdi_lanes
> 2) {
5958 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
5959 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5963 other_crtc
= intel_get_crtc_for_pipe(dev_priv
, PIPE_B
);
5965 intel_atomic_get_crtc_state(state
, other_crtc
);
5966 if (IS_ERR(other_crtc_state
))
5967 return PTR_ERR(other_crtc_state
);
5969 if (pipe_required_fdi_lanes(other_crtc_state
) > 2) {
5970 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
5980 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
5981 struct intel_crtc_state
*pipe_config
)
5983 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5984 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
5985 int lane
, link_bw
, fdi_dotclock
, ret
;
5986 bool needs_recompute
= false;
5989 /* FDI is a binary signal running at ~2.7GHz, encoding
5990 * each output octet as 10 bits. The actual frequency
5991 * is stored as a divider into a 100MHz clock, and the
5992 * mode pixel clock is stored in units of 1KHz.
5993 * Hence the bw of each lane in terms of the mode signal
5996 link_bw
= intel_fdi_link_freq(to_i915(dev
), pipe_config
);
5998 fdi_dotclock
= adjusted_mode
->crtc_clock
;
6000 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
6001 pipe_config
->pipe_bpp
);
6003 pipe_config
->fdi_lanes
= lane
;
6005 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
6006 link_bw
, &pipe_config
->fdi_m_n
, false);
6008 ret
= ironlake_check_fdi_lanes(dev
, intel_crtc
->pipe
, pipe_config
);
6009 if (ret
== -EINVAL
&& pipe_config
->pipe_bpp
> 6*3) {
6010 pipe_config
->pipe_bpp
-= 2*3;
6011 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6012 pipe_config
->pipe_bpp
);
6013 needs_recompute
= true;
6014 pipe_config
->bw_constrained
= true;
6019 if (needs_recompute
)
6025 static bool pipe_config_supports_ips(struct drm_i915_private
*dev_priv
,
6026 struct intel_crtc_state
*pipe_config
)
6028 if (pipe_config
->pipe_bpp
> 24)
6031 /* HSW can handle pixel rate up to cdclk? */
6032 if (IS_HASWELL(dev_priv
))
6036 * We compare against max which means we must take
6037 * the increased cdclk requirement into account when
6038 * calculating the new cdclk.
6040 * Should measure whether using a lower cdclk w/o IPS
6042 return pipe_config
->pixel_rate
<=
6043 dev_priv
->max_cdclk_freq
* 95 / 100;
6046 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
6047 struct intel_crtc_state
*pipe_config
)
6049 struct drm_device
*dev
= crtc
->base
.dev
;
6050 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6052 pipe_config
->ips_enabled
= i915
.enable_ips
&&
6053 hsw_crtc_supports_ips(crtc
) &&
6054 pipe_config_supports_ips(dev_priv
, pipe_config
);
6057 static bool intel_crtc_supports_double_wide(const struct intel_crtc
*crtc
)
6059 const struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6061 /* GDG double wide on either pipe, otherwise pipe A only */
6062 return INTEL_INFO(dev_priv
)->gen
< 4 &&
6063 (crtc
->pipe
== PIPE_A
|| IS_I915G(dev_priv
));
6066 static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state
*pipe_config
)
6068 uint32_t pixel_rate
;
6070 pixel_rate
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
6073 * We only use IF-ID interlacing. If we ever use
6074 * PF-ID we'll need to adjust the pixel_rate here.
6077 if (pipe_config
->pch_pfit
.enabled
) {
6078 uint64_t pipe_w
, pipe_h
, pfit_w
, pfit_h
;
6079 uint32_t pfit_size
= pipe_config
->pch_pfit
.size
;
6081 pipe_w
= pipe_config
->pipe_src_w
;
6082 pipe_h
= pipe_config
->pipe_src_h
;
6084 pfit_w
= (pfit_size
>> 16) & 0xFFFF;
6085 pfit_h
= pfit_size
& 0xFFFF;
6086 if (pipe_w
< pfit_w
)
6088 if (pipe_h
< pfit_h
)
6091 if (WARN_ON(!pfit_w
|| !pfit_h
))
6094 pixel_rate
= div_u64((uint64_t) pixel_rate
* pipe_w
* pipe_h
,
6101 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state
*crtc_state
)
6103 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->base
.crtc
->dev
);
6105 if (HAS_GMCH_DISPLAY(dev_priv
))
6106 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6107 crtc_state
->pixel_rate
=
6108 crtc_state
->base
.adjusted_mode
.crtc_clock
;
6110 crtc_state
->pixel_rate
=
6111 ilk_pipe_pixel_rate(crtc_state
);
6114 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
6115 struct intel_crtc_state
*pipe_config
)
6117 struct drm_device
*dev
= crtc
->base
.dev
;
6118 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6119 const struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6120 int clock_limit
= dev_priv
->max_dotclk_freq
;
6122 if (INTEL_GEN(dev_priv
) < 4) {
6123 clock_limit
= dev_priv
->max_cdclk_freq
* 9 / 10;
6126 * Enable double wide mode when the dot clock
6127 * is > 90% of the (display) core speed.
6129 if (intel_crtc_supports_double_wide(crtc
) &&
6130 adjusted_mode
->crtc_clock
> clock_limit
) {
6131 clock_limit
= dev_priv
->max_dotclk_freq
;
6132 pipe_config
->double_wide
= true;
6136 if (adjusted_mode
->crtc_clock
> clock_limit
) {
6137 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6138 adjusted_mode
->crtc_clock
, clock_limit
,
6139 yesno(pipe_config
->double_wide
));
6143 if (pipe_config
->ycbcr420
&& pipe_config
->base
.ctm
) {
6145 * There is only one pipe CSC unit per pipe, and we need that
6146 * for output conversion from RGB->YCBCR. So if CTM is already
6147 * applied we can't support YCBCR420 output.
6149 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6154 * Pipe horizontal size must be even in:
6156 * - LVDS dual channel mode
6157 * - Double wide pipe
6159 if ((intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_LVDS
) &&
6160 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
6161 pipe_config
->pipe_src_w
&= ~1;
6163 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6164 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6166 if ((INTEL_GEN(dev_priv
) > 4 || IS_G4X(dev_priv
)) &&
6167 adjusted_mode
->crtc_hsync_start
== adjusted_mode
->crtc_hdisplay
)
6170 intel_crtc_compute_pixel_rate(pipe_config
);
6172 if (HAS_IPS(dev_priv
))
6173 hsw_compute_ips_config(crtc
, pipe_config
);
6175 if (pipe_config
->has_pch_encoder
)
6176 return ironlake_fdi_compute_config(crtc
, pipe_config
);
6182 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
6184 while (*num
> DATA_LINK_M_N_MASK
||
6185 *den
> DATA_LINK_M_N_MASK
) {
6191 static void compute_m_n(unsigned int m
, unsigned int n
,
6192 uint32_t *ret_m
, uint32_t *ret_n
,
6196 * Reduce M/N as much as possible without loss in precision. Several DP
6197 * dongles in particular seem to be fussy about too large *link* M/N
6198 * values. The passed in values are more likely to have the least
6199 * significant bits zero than M after rounding below, so do this first.
6202 while ((m
& 1) == 0 && (n
& 1) == 0) {
6208 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
6209 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
6210 intel_reduce_m_n_ratio(ret_m
, ret_n
);
6214 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
6215 int pixel_clock
, int link_clock
,
6216 struct intel_link_m_n
*m_n
,
6221 compute_m_n(bits_per_pixel
* pixel_clock
,
6222 link_clock
* nlanes
* 8,
6223 &m_n
->gmch_m
, &m_n
->gmch_n
,
6226 compute_m_n(pixel_clock
, link_clock
,
6227 &m_n
->link_m
, &m_n
->link_n
,
6231 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
6233 if (i915
.panel_use_ssc
>= 0)
6234 return i915
.panel_use_ssc
!= 0;
6235 return dev_priv
->vbt
.lvds_use_ssc
6236 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
6239 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
6241 return (1 << dpll
->n
) << 16 | dpll
->m2
;
6244 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
6246 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
6249 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
6250 struct intel_crtc_state
*crtc_state
,
6251 struct dpll
*reduced_clock
)
6253 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6256 if (IS_PINEVIEW(dev_priv
)) {
6257 fp
= pnv_dpll_compute_fp(&crtc_state
->dpll
);
6259 fp2
= pnv_dpll_compute_fp(reduced_clock
);
6261 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
6263 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
6266 crtc_state
->dpll_hw_state
.fp0
= fp
;
6268 crtc
->lowfreq_avail
= false;
6269 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6271 crtc_state
->dpll_hw_state
.fp1
= fp2
;
6272 crtc
->lowfreq_avail
= true;
6274 crtc_state
->dpll_hw_state
.fp1
= fp
;
6278 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
6284 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6285 * and set it to a reasonable value instead.
6287 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6288 reg_val
&= 0xffffff00;
6289 reg_val
|= 0x00000030;
6290 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6292 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6293 reg_val
&= 0x00ffffff;
6294 reg_val
|= 0x8c000000;
6295 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6297 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6298 reg_val
&= 0xffffff00;
6299 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6301 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6302 reg_val
&= 0x00ffffff;
6303 reg_val
|= 0xb0000000;
6304 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6307 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
6308 struct intel_link_m_n
*m_n
)
6310 struct drm_device
*dev
= crtc
->base
.dev
;
6311 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6312 int pipe
= crtc
->pipe
;
6314 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6315 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
6316 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
6317 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
6320 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
6321 struct intel_link_m_n
*m_n
,
6322 struct intel_link_m_n
*m2_n2
)
6324 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6325 int pipe
= crtc
->pipe
;
6326 enum transcoder transcoder
= crtc
->config
->cpu_transcoder
;
6328 if (INTEL_GEN(dev_priv
) >= 5) {
6329 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6330 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
6331 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
6332 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
6333 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
6334 * for gen < 8) and if DRRS is supported (to make sure the
6335 * registers are not unnecessarily accessed).
6337 if (m2_n2
&& (IS_CHERRYVIEW(dev_priv
) ||
6338 INTEL_GEN(dev_priv
) < 8) && crtc
->config
->has_drrs
) {
6339 I915_WRITE(PIPE_DATA_M2(transcoder
),
6340 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
6341 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
6342 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
6343 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
6346 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6347 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
6348 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
6349 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
6353 void intel_dp_set_m_n(struct intel_crtc
*crtc
, enum link_m_n_set m_n
)
6355 struct intel_link_m_n
*dp_m_n
, *dp_m2_n2
= NULL
;
6358 dp_m_n
= &crtc
->config
->dp_m_n
;
6359 dp_m2_n2
= &crtc
->config
->dp_m2_n2
;
6360 } else if (m_n
== M2_N2
) {
6363 * M2_N2 registers are not supported. Hence m2_n2 divider value
6364 * needs to be programmed into M1_N1.
6366 dp_m_n
= &crtc
->config
->dp_m2_n2
;
6368 DRM_ERROR("Unsupported divider value\n");
6372 if (crtc
->config
->has_pch_encoder
)
6373 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
->dp_m_n
);
6375 intel_cpu_transcoder_set_m_n(crtc
, dp_m_n
, dp_m2_n2
);
6378 static void vlv_compute_dpll(struct intel_crtc
*crtc
,
6379 struct intel_crtc_state
*pipe_config
)
6381 pipe_config
->dpll_hw_state
.dpll
= DPLL_INTEGRATED_REF_CLK_VLV
|
6382 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
6383 if (crtc
->pipe
!= PIPE_A
)
6384 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
6386 /* DPLL not used with DSI, but still need the rest set up */
6387 if (!intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_DSI
))
6388 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
|
6389 DPLL_EXT_BUFFER_ENABLE_VLV
;
6391 pipe_config
->dpll_hw_state
.dpll_md
=
6392 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6395 static void chv_compute_dpll(struct intel_crtc
*crtc
,
6396 struct intel_crtc_state
*pipe_config
)
6398 pipe_config
->dpll_hw_state
.dpll
= DPLL_SSC_REF_CLK_CHV
|
6399 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
6400 if (crtc
->pipe
!= PIPE_A
)
6401 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
6403 /* DPLL not used with DSI, but still need the rest set up */
6404 if (!intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_DSI
))
6405 pipe_config
->dpll_hw_state
.dpll
|= DPLL_VCO_ENABLE
;
6407 pipe_config
->dpll_hw_state
.dpll_md
=
6408 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6411 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
6412 const struct intel_crtc_state
*pipe_config
)
6414 struct drm_device
*dev
= crtc
->base
.dev
;
6415 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6416 enum pipe pipe
= crtc
->pipe
;
6418 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
6419 u32 coreclk
, reg_val
;
6422 I915_WRITE(DPLL(pipe
),
6423 pipe_config
->dpll_hw_state
.dpll
&
6424 ~(DPLL_VCO_ENABLE
| DPLL_EXT_BUFFER_ENABLE_VLV
));
6426 /* No need to actually set up the DPLL with DSI */
6427 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
6430 mutex_lock(&dev_priv
->sb_lock
);
6432 bestn
= pipe_config
->dpll
.n
;
6433 bestm1
= pipe_config
->dpll
.m1
;
6434 bestm2
= pipe_config
->dpll
.m2
;
6435 bestp1
= pipe_config
->dpll
.p1
;
6436 bestp2
= pipe_config
->dpll
.p2
;
6438 /* See eDP HDMI DPIO driver vbios notes doc */
6440 /* PLL B needs special handling */
6442 vlv_pllb_recal_opamp(dev_priv
, pipe
);
6444 /* Set up Tx target for periodic Rcomp update */
6445 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
6447 /* Disable target IRef on PLL */
6448 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
6449 reg_val
&= 0x00ffffff;
6450 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
6452 /* Disable fast lock */
6453 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
6455 /* Set idtafcrecal before PLL is enabled */
6456 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
6457 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
6458 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
6459 mdiv
|= (1 << DPIO_K_SHIFT
);
6462 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6463 * but we don't support that).
6464 * Note: don't use the DAC post divider as it seems unstable.
6466 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
6467 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
6469 mdiv
|= DPIO_ENABLE_CALIBRATION
;
6470 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
6472 /* Set HBR and RBR LPF coefficients */
6473 if (pipe_config
->port_clock
== 162000 ||
6474 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_ANALOG
) ||
6475 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_HDMI
))
6476 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
6479 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
6482 if (intel_crtc_has_dp_encoder(pipe_config
)) {
6483 /* Use SSC source */
6485 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6488 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6490 } else { /* HDMI or VGA */
6491 /* Use bend source */
6493 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6496 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6500 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
6501 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
6502 if (intel_crtc_has_dp_encoder(crtc
->config
))
6503 coreclk
|= 0x01000000;
6504 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
6506 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
6507 mutex_unlock(&dev_priv
->sb_lock
);
6510 static void chv_prepare_pll(struct intel_crtc
*crtc
,
6511 const struct intel_crtc_state
*pipe_config
)
6513 struct drm_device
*dev
= crtc
->base
.dev
;
6514 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6515 enum pipe pipe
= crtc
->pipe
;
6516 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
6517 u32 loopfilter
, tribuf_calcntr
;
6518 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
6522 /* Enable Refclk and SSC */
6523 I915_WRITE(DPLL(pipe
),
6524 pipe_config
->dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
6526 /* No need to actually set up the DPLL with DSI */
6527 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
6530 bestn
= pipe_config
->dpll
.n
;
6531 bestm2_frac
= pipe_config
->dpll
.m2
& 0x3fffff;
6532 bestm1
= pipe_config
->dpll
.m1
;
6533 bestm2
= pipe_config
->dpll
.m2
>> 22;
6534 bestp1
= pipe_config
->dpll
.p1
;
6535 bestp2
= pipe_config
->dpll
.p2
;
6536 vco
= pipe_config
->dpll
.vco
;
6540 mutex_lock(&dev_priv
->sb_lock
);
6542 /* p1 and p2 divider */
6543 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
6544 5 << DPIO_CHV_S1_DIV_SHIFT
|
6545 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
6546 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
6547 1 << DPIO_CHV_K_DIV_SHIFT
);
6549 /* Feedback post-divider - m2 */
6550 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
6552 /* Feedback refclk divider - n and m1 */
6553 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
6554 DPIO_CHV_M1_DIV_BY_2
|
6555 1 << DPIO_CHV_N_DIV_SHIFT
);
6557 /* M2 fraction division */
6558 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
6560 /* M2 fraction division enable */
6561 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
6562 dpio_val
&= ~(DPIO_CHV_FEEDFWD_GAIN_MASK
| DPIO_CHV_FRAC_DIV_EN
);
6563 dpio_val
|= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
);
6565 dpio_val
|= DPIO_CHV_FRAC_DIV_EN
;
6566 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
), dpio_val
);
6568 /* Program digital lock detect threshold */
6569 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW9(port
));
6570 dpio_val
&= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK
|
6571 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
);
6572 dpio_val
|= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT
);
6574 dpio_val
|= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
;
6575 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW9(port
), dpio_val
);
6578 if (vco
== 5400000) {
6579 loopfilter
|= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT
);
6580 loopfilter
|= (0x8 << DPIO_CHV_INT_COEFF_SHIFT
);
6581 loopfilter
|= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6582 tribuf_calcntr
= 0x9;
6583 } else if (vco
<= 6200000) {
6584 loopfilter
|= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT
);
6585 loopfilter
|= (0xB << DPIO_CHV_INT_COEFF_SHIFT
);
6586 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6587 tribuf_calcntr
= 0x9;
6588 } else if (vco
<= 6480000) {
6589 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
6590 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
6591 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6592 tribuf_calcntr
= 0x8;
6594 /* Not supported. Apply the same limits as in the max case */
6595 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
6596 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
6597 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6600 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
6602 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW8(port
));
6603 dpio_val
&= ~DPIO_CHV_TDC_TARGET_CNT_MASK
;
6604 dpio_val
|= (tribuf_calcntr
<< DPIO_CHV_TDC_TARGET_CNT_SHIFT
);
6605 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW8(port
), dpio_val
);
6608 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
6609 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
6612 mutex_unlock(&dev_priv
->sb_lock
);
6616 * vlv_force_pll_on - forcibly enable just the PLL
6617 * @dev_priv: i915 private structure
6618 * @pipe: pipe PLL to enable
6619 * @dpll: PLL configuration
6621 * Enable the PLL for @pipe using the supplied @dpll config. To be used
6622 * in cases where we need the PLL enabled even when @pipe is not going to
6625 int vlv_force_pll_on(struct drm_i915_private
*dev_priv
, enum pipe pipe
,
6626 const struct dpll
*dpll
)
6628 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
6629 struct intel_crtc_state
*pipe_config
;
6631 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
6635 pipe_config
->base
.crtc
= &crtc
->base
;
6636 pipe_config
->pixel_multiplier
= 1;
6637 pipe_config
->dpll
= *dpll
;
6639 if (IS_CHERRYVIEW(dev_priv
)) {
6640 chv_compute_dpll(crtc
, pipe_config
);
6641 chv_prepare_pll(crtc
, pipe_config
);
6642 chv_enable_pll(crtc
, pipe_config
);
6644 vlv_compute_dpll(crtc
, pipe_config
);
6645 vlv_prepare_pll(crtc
, pipe_config
);
6646 vlv_enable_pll(crtc
, pipe_config
);
6655 * vlv_force_pll_off - forcibly disable just the PLL
6656 * @dev_priv: i915 private structure
6657 * @pipe: pipe PLL to disable
6659 * Disable the PLL for @pipe. To be used in cases where we need
6660 * the PLL enabled even when @pipe is not going to be enabled.
6662 void vlv_force_pll_off(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
6664 if (IS_CHERRYVIEW(dev_priv
))
6665 chv_disable_pll(dev_priv
, pipe
);
6667 vlv_disable_pll(dev_priv
, pipe
);
6670 static void i9xx_compute_dpll(struct intel_crtc
*crtc
,
6671 struct intel_crtc_state
*crtc_state
,
6672 struct dpll
*reduced_clock
)
6674 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
6676 struct dpll
*clock
= &crtc_state
->dpll
;
6678 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
6680 dpll
= DPLL_VGA_MODE_DIS
;
6682 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
))
6683 dpll
|= DPLLB_MODE_LVDS
;
6685 dpll
|= DPLLB_MODE_DAC_SERIAL
;
6687 if (IS_I945G(dev_priv
) || IS_I945GM(dev_priv
) ||
6688 IS_G33(dev_priv
) || IS_PINEVIEW(dev_priv
)) {
6689 dpll
|= (crtc_state
->pixel_multiplier
- 1)
6690 << SDVO_MULTIPLIER_SHIFT_HIRES
;
6693 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
6694 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
6695 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6697 if (intel_crtc_has_dp_encoder(crtc_state
))
6698 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6700 /* compute bitmask from p1 value */
6701 if (IS_PINEVIEW(dev_priv
))
6702 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
6704 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6705 if (IS_G4X(dev_priv
) && reduced_clock
)
6706 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
6708 switch (clock
->p2
) {
6710 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
6713 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
6716 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
6719 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
6722 if (INTEL_GEN(dev_priv
) >= 4)
6723 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
6725 if (crtc_state
->sdvo_tv_clock
)
6726 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
6727 else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6728 intel_panel_use_ssc(dev_priv
))
6729 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
6731 dpll
|= PLL_REF_INPUT_DREFCLK
;
6733 dpll
|= DPLL_VCO_ENABLE
;
6734 crtc_state
->dpll_hw_state
.dpll
= dpll
;
6736 if (INTEL_GEN(dev_priv
) >= 4) {
6737 u32 dpll_md
= (crtc_state
->pixel_multiplier
- 1)
6738 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6739 crtc_state
->dpll_hw_state
.dpll_md
= dpll_md
;
6743 static void i8xx_compute_dpll(struct intel_crtc
*crtc
,
6744 struct intel_crtc_state
*crtc_state
,
6745 struct dpll
*reduced_clock
)
6747 struct drm_device
*dev
= crtc
->base
.dev
;
6748 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6750 struct dpll
*clock
= &crtc_state
->dpll
;
6752 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
6754 dpll
= DPLL_VGA_MODE_DIS
;
6756 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
6757 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6760 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
6762 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6764 dpll
|= PLL_P2_DIVIDE_BY_4
;
6767 if (!IS_I830(dev_priv
) &&
6768 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DVO
))
6769 dpll
|= DPLL_DVO_2X_MODE
;
6771 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6772 intel_panel_use_ssc(dev_priv
))
6773 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
6775 dpll
|= PLL_REF_INPUT_DREFCLK
;
6777 dpll
|= DPLL_VCO_ENABLE
;
6778 crtc_state
->dpll_hw_state
.dpll
= dpll
;
6781 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
6783 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
6784 enum pipe pipe
= intel_crtc
->pipe
;
6785 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
6786 const struct drm_display_mode
*adjusted_mode
= &intel_crtc
->config
->base
.adjusted_mode
;
6787 uint32_t crtc_vtotal
, crtc_vblank_end
;
6790 /* We need to be careful not to changed the adjusted mode, for otherwise
6791 * the hw state checker will get angry at the mismatch. */
6792 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
6793 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
6795 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
6796 /* the chip adds 2 halflines automatically */
6798 crtc_vblank_end
-= 1;
6800 if (intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
6801 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
6803 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
6804 adjusted_mode
->crtc_htotal
/ 2;
6806 vsyncshift
+= adjusted_mode
->crtc_htotal
;
6809 if (INTEL_GEN(dev_priv
) > 3)
6810 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
6812 I915_WRITE(HTOTAL(cpu_transcoder
),
6813 (adjusted_mode
->crtc_hdisplay
- 1) |
6814 ((adjusted_mode
->crtc_htotal
- 1) << 16));
6815 I915_WRITE(HBLANK(cpu_transcoder
),
6816 (adjusted_mode
->crtc_hblank_start
- 1) |
6817 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
6818 I915_WRITE(HSYNC(cpu_transcoder
),
6819 (adjusted_mode
->crtc_hsync_start
- 1) |
6820 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
6822 I915_WRITE(VTOTAL(cpu_transcoder
),
6823 (adjusted_mode
->crtc_vdisplay
- 1) |
6824 ((crtc_vtotal
- 1) << 16));
6825 I915_WRITE(VBLANK(cpu_transcoder
),
6826 (adjusted_mode
->crtc_vblank_start
- 1) |
6827 ((crtc_vblank_end
- 1) << 16));
6828 I915_WRITE(VSYNC(cpu_transcoder
),
6829 (adjusted_mode
->crtc_vsync_start
- 1) |
6830 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
6832 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
6833 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
6834 * documented on the DDI_FUNC_CTL register description, EDP Input Select
6836 if (IS_HASWELL(dev_priv
) && cpu_transcoder
== TRANSCODER_EDP
&&
6837 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
6838 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
6842 static void intel_set_pipe_src_size(struct intel_crtc
*intel_crtc
)
6844 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6845 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6846 enum pipe pipe
= intel_crtc
->pipe
;
6848 /* pipesrc controls the size that is scaled from, which should
6849 * always be the user's requested size.
6851 I915_WRITE(PIPESRC(pipe
),
6852 ((intel_crtc
->config
->pipe_src_w
- 1) << 16) |
6853 (intel_crtc
->config
->pipe_src_h
- 1));
6856 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
6857 struct intel_crtc_state
*pipe_config
)
6859 struct drm_device
*dev
= crtc
->base
.dev
;
6860 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6861 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
6864 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
6865 pipe_config
->base
.adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
6866 pipe_config
->base
.adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
6867 tmp
= I915_READ(HBLANK(cpu_transcoder
));
6868 pipe_config
->base
.adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
6869 pipe_config
->base
.adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
6870 tmp
= I915_READ(HSYNC(cpu_transcoder
));
6871 pipe_config
->base
.adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
6872 pipe_config
->base
.adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
6874 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
6875 pipe_config
->base
.adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
6876 pipe_config
->base
.adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
6877 tmp
= I915_READ(VBLANK(cpu_transcoder
));
6878 pipe_config
->base
.adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
6879 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
6880 tmp
= I915_READ(VSYNC(cpu_transcoder
));
6881 pipe_config
->base
.adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
6882 pipe_config
->base
.adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
6884 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
6885 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
6886 pipe_config
->base
.adjusted_mode
.crtc_vtotal
+= 1;
6887 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
+= 1;
6891 static void intel_get_pipe_src_size(struct intel_crtc
*crtc
,
6892 struct intel_crtc_state
*pipe_config
)
6894 struct drm_device
*dev
= crtc
->base
.dev
;
6895 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6898 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
6899 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
6900 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
6902 pipe_config
->base
.mode
.vdisplay
= pipe_config
->pipe_src_h
;
6903 pipe_config
->base
.mode
.hdisplay
= pipe_config
->pipe_src_w
;
6906 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
6907 struct intel_crtc_state
*pipe_config
)
6909 mode
->hdisplay
= pipe_config
->base
.adjusted_mode
.crtc_hdisplay
;
6910 mode
->htotal
= pipe_config
->base
.adjusted_mode
.crtc_htotal
;
6911 mode
->hsync_start
= pipe_config
->base
.adjusted_mode
.crtc_hsync_start
;
6912 mode
->hsync_end
= pipe_config
->base
.adjusted_mode
.crtc_hsync_end
;
6914 mode
->vdisplay
= pipe_config
->base
.adjusted_mode
.crtc_vdisplay
;
6915 mode
->vtotal
= pipe_config
->base
.adjusted_mode
.crtc_vtotal
;
6916 mode
->vsync_start
= pipe_config
->base
.adjusted_mode
.crtc_vsync_start
;
6917 mode
->vsync_end
= pipe_config
->base
.adjusted_mode
.crtc_vsync_end
;
6919 mode
->flags
= pipe_config
->base
.adjusted_mode
.flags
;
6920 mode
->type
= DRM_MODE_TYPE_DRIVER
;
6922 mode
->clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
6924 mode
->hsync
= drm_mode_hsync(mode
);
6925 mode
->vrefresh
= drm_mode_vrefresh(mode
);
6926 drm_mode_set_name(mode
);
6929 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
6931 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
6936 /* we keep both pipes enabled on 830 */
6937 if (IS_I830(dev_priv
))
6938 pipeconf
|= I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
;
6940 if (intel_crtc
->config
->double_wide
)
6941 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
6943 /* only g4x and later have fancy bpc/dither controls */
6944 if (IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
6945 IS_CHERRYVIEW(dev_priv
)) {
6946 /* Bspec claims that we can't use dithering for 30bpp pipes. */
6947 if (intel_crtc
->config
->dither
&& intel_crtc
->config
->pipe_bpp
!= 30)
6948 pipeconf
|= PIPECONF_DITHER_EN
|
6949 PIPECONF_DITHER_TYPE_SP
;
6951 switch (intel_crtc
->config
->pipe_bpp
) {
6953 pipeconf
|= PIPECONF_6BPC
;
6956 pipeconf
|= PIPECONF_8BPC
;
6959 pipeconf
|= PIPECONF_10BPC
;
6962 /* Case prevented by intel_choose_pipe_bpp_dither. */
6967 if (HAS_PIPE_CXSR(dev_priv
)) {
6968 if (intel_crtc
->lowfreq_avail
) {
6969 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
6970 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
6972 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
6976 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
6977 if (INTEL_GEN(dev_priv
) < 4 ||
6978 intel_crtc_has_type(intel_crtc
->config
, INTEL_OUTPUT_SDVO
))
6979 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
6981 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
6983 pipeconf
|= PIPECONF_PROGRESSIVE
;
6985 if ((IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) &&
6986 intel_crtc
->config
->limited_color_range
)
6987 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
6989 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
6990 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
6993 static int i8xx_crtc_compute_clock(struct intel_crtc
*crtc
,
6994 struct intel_crtc_state
*crtc_state
)
6996 struct drm_device
*dev
= crtc
->base
.dev
;
6997 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6998 const struct intel_limit
*limit
;
7001 memset(&crtc_state
->dpll_hw_state
, 0,
7002 sizeof(crtc_state
->dpll_hw_state
));
7004 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7005 if (intel_panel_use_ssc(dev_priv
)) {
7006 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7007 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7010 limit
= &intel_limits_i8xx_lvds
;
7011 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DVO
)) {
7012 limit
= &intel_limits_i8xx_dvo
;
7014 limit
= &intel_limits_i8xx_dac
;
7017 if (!crtc_state
->clock_set
&&
7018 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7019 refclk
, NULL
, &crtc_state
->dpll
)) {
7020 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7024 i8xx_compute_dpll(crtc
, crtc_state
, NULL
);
7029 static int g4x_crtc_compute_clock(struct intel_crtc
*crtc
,
7030 struct intel_crtc_state
*crtc_state
)
7032 struct drm_device
*dev
= crtc
->base
.dev
;
7033 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7034 const struct intel_limit
*limit
;
7037 memset(&crtc_state
->dpll_hw_state
, 0,
7038 sizeof(crtc_state
->dpll_hw_state
));
7040 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7041 if (intel_panel_use_ssc(dev_priv
)) {
7042 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7043 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7046 if (intel_is_dual_link_lvds(dev
))
7047 limit
= &intel_limits_g4x_dual_channel_lvds
;
7049 limit
= &intel_limits_g4x_single_channel_lvds
;
7050 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
) ||
7051 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
)) {
7052 limit
= &intel_limits_g4x_hdmi
;
7053 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
)) {
7054 limit
= &intel_limits_g4x_sdvo
;
7056 /* The option is for other outputs */
7057 limit
= &intel_limits_i9xx_sdvo
;
7060 if (!crtc_state
->clock_set
&&
7061 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7062 refclk
, NULL
, &crtc_state
->dpll
)) {
7063 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7067 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7072 static int pnv_crtc_compute_clock(struct intel_crtc
*crtc
,
7073 struct intel_crtc_state
*crtc_state
)
7075 struct drm_device
*dev
= crtc
->base
.dev
;
7076 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7077 const struct intel_limit
*limit
;
7080 memset(&crtc_state
->dpll_hw_state
, 0,
7081 sizeof(crtc_state
->dpll_hw_state
));
7083 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7084 if (intel_panel_use_ssc(dev_priv
)) {
7085 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7086 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7089 limit
= &intel_limits_pineview_lvds
;
7091 limit
= &intel_limits_pineview_sdvo
;
7094 if (!crtc_state
->clock_set
&&
7095 !pnv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7096 refclk
, NULL
, &crtc_state
->dpll
)) {
7097 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7101 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7106 static int i9xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7107 struct intel_crtc_state
*crtc_state
)
7109 struct drm_device
*dev
= crtc
->base
.dev
;
7110 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7111 const struct intel_limit
*limit
;
7114 memset(&crtc_state
->dpll_hw_state
, 0,
7115 sizeof(crtc_state
->dpll_hw_state
));
7117 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7118 if (intel_panel_use_ssc(dev_priv
)) {
7119 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
7120 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
7123 limit
= &intel_limits_i9xx_lvds
;
7125 limit
= &intel_limits_i9xx_sdvo
;
7128 if (!crtc_state
->clock_set
&&
7129 !i9xx_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7130 refclk
, NULL
, &crtc_state
->dpll
)) {
7131 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7135 i9xx_compute_dpll(crtc
, crtc_state
, NULL
);
7140 static int chv_crtc_compute_clock(struct intel_crtc
*crtc
,
7141 struct intel_crtc_state
*crtc_state
)
7143 int refclk
= 100000;
7144 const struct intel_limit
*limit
= &intel_limits_chv
;
7146 memset(&crtc_state
->dpll_hw_state
, 0,
7147 sizeof(crtc_state
->dpll_hw_state
));
7149 if (!crtc_state
->clock_set
&&
7150 !chv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7151 refclk
, NULL
, &crtc_state
->dpll
)) {
7152 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7156 chv_compute_dpll(crtc
, crtc_state
);
7161 static int vlv_crtc_compute_clock(struct intel_crtc
*crtc
,
7162 struct intel_crtc_state
*crtc_state
)
7164 int refclk
= 100000;
7165 const struct intel_limit
*limit
= &intel_limits_vlv
;
7167 memset(&crtc_state
->dpll_hw_state
, 0,
7168 sizeof(crtc_state
->dpll_hw_state
));
7170 if (!crtc_state
->clock_set
&&
7171 !vlv_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
7172 refclk
, NULL
, &crtc_state
->dpll
)) {
7173 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7177 vlv_compute_dpll(crtc
, crtc_state
);
7182 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
7183 struct intel_crtc_state
*pipe_config
)
7185 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7188 if (INTEL_GEN(dev_priv
) <= 3 &&
7189 (IS_I830(dev_priv
) || !IS_MOBILE(dev_priv
)))
7192 tmp
= I915_READ(PFIT_CONTROL
);
7193 if (!(tmp
& PFIT_ENABLE
))
7196 /* Check whether the pfit is attached to our pipe. */
7197 if (INTEL_GEN(dev_priv
) < 4) {
7198 if (crtc
->pipe
!= PIPE_B
)
7201 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
7205 pipe_config
->gmch_pfit
.control
= tmp
;
7206 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
7209 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
7210 struct intel_crtc_state
*pipe_config
)
7212 struct drm_device
*dev
= crtc
->base
.dev
;
7213 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7214 int pipe
= pipe_config
->cpu_transcoder
;
7217 int refclk
= 100000;
7219 /* In case of DSI, DPLL will not be used */
7220 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7223 mutex_lock(&dev_priv
->sb_lock
);
7224 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
7225 mutex_unlock(&dev_priv
->sb_lock
);
7227 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
7228 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
7229 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
7230 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
7231 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
7233 pipe_config
->port_clock
= vlv_calc_dpll_params(refclk
, &clock
);
7237 i9xx_get_initial_plane_config(struct intel_crtc
*crtc
,
7238 struct intel_initial_plane_config
*plane_config
)
7240 struct drm_device
*dev
= crtc
->base
.dev
;
7241 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7242 u32 val
, base
, offset
;
7243 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
7244 int fourcc
, pixel_format
;
7245 unsigned int aligned_height
;
7246 struct drm_framebuffer
*fb
;
7247 struct intel_framebuffer
*intel_fb
;
7249 val
= I915_READ(DSPCNTR(plane
));
7250 if (!(val
& DISPLAY_PLANE_ENABLE
))
7253 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
7255 DRM_DEBUG_KMS("failed to alloc fb\n");
7259 fb
= &intel_fb
->base
;
7263 if (INTEL_GEN(dev_priv
) >= 4) {
7264 if (val
& DISPPLANE_TILED
) {
7265 plane_config
->tiling
= I915_TILING_X
;
7266 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
7270 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
7271 fourcc
= i9xx_format_to_fourcc(pixel_format
);
7272 fb
->format
= drm_format_info(fourcc
);
7274 if (INTEL_GEN(dev_priv
) >= 4) {
7275 if (plane_config
->tiling
)
7276 offset
= I915_READ(DSPTILEOFF(plane
));
7278 offset
= I915_READ(DSPLINOFF(plane
));
7279 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
7281 base
= I915_READ(DSPADDR(plane
));
7283 plane_config
->base
= base
;
7285 val
= I915_READ(PIPESRC(pipe
));
7286 fb
->width
= ((val
>> 16) & 0xfff) + 1;
7287 fb
->height
= ((val
>> 0) & 0xfff) + 1;
7289 val
= I915_READ(DSPSTRIDE(pipe
));
7290 fb
->pitches
[0] = val
& 0xffffffc0;
7292 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
7294 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
7296 DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7297 pipe_name(pipe
), plane
, fb
->width
, fb
->height
,
7298 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
7299 plane_config
->size
);
7301 plane_config
->fb
= intel_fb
;
7304 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
7305 struct intel_crtc_state
*pipe_config
)
7307 struct drm_device
*dev
= crtc
->base
.dev
;
7308 struct drm_i915_private
*dev_priv
= to_i915(dev
);
7309 int pipe
= pipe_config
->cpu_transcoder
;
7310 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
7312 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
, pll_dw3
;
7313 int refclk
= 100000;
7315 /* In case of DSI, DPLL will not be used */
7316 if ((pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
) == 0)
7319 mutex_lock(&dev_priv
->sb_lock
);
7320 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
7321 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
7322 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
7323 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
7324 pll_dw3
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
7325 mutex_unlock(&dev_priv
->sb_lock
);
7327 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
7328 clock
.m2
= (pll_dw0
& 0xff) << 22;
7329 if (pll_dw3
& DPIO_CHV_FRAC_DIV_EN
)
7330 clock
.m2
|= pll_dw2
& 0x3fffff;
7331 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
7332 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
7333 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
7335 pipe_config
->port_clock
= chv_calc_dpll_params(refclk
, &clock
);
7338 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
7339 struct intel_crtc_state
*pipe_config
)
7341 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
7342 enum intel_display_power_domain power_domain
;
7346 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
7347 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
7350 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7351 pipe_config
->shared_dpll
= NULL
;
7355 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
7356 if (!(tmp
& PIPECONF_ENABLE
))
7359 if (IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
7360 IS_CHERRYVIEW(dev_priv
)) {
7361 switch (tmp
& PIPECONF_BPC_MASK
) {
7363 pipe_config
->pipe_bpp
= 18;
7366 pipe_config
->pipe_bpp
= 24;
7368 case PIPECONF_10BPC
:
7369 pipe_config
->pipe_bpp
= 30;
7376 if ((IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) &&
7377 (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
7378 pipe_config
->limited_color_range
= true;
7380 if (INTEL_GEN(dev_priv
) < 4)
7381 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
7383 intel_get_pipe_timings(crtc
, pipe_config
);
7384 intel_get_pipe_src_size(crtc
, pipe_config
);
7386 i9xx_get_pfit_config(crtc
, pipe_config
);
7388 if (INTEL_GEN(dev_priv
) >= 4) {
7389 /* No way to read it out on pipes B and C */
7390 if (IS_CHERRYVIEW(dev_priv
) && crtc
->pipe
!= PIPE_A
)
7391 tmp
= dev_priv
->chv_dpll_md
[crtc
->pipe
];
7393 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
7394 pipe_config
->pixel_multiplier
=
7395 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
7396 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
7397 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
7398 } else if (IS_I945G(dev_priv
) || IS_I945GM(dev_priv
) ||
7399 IS_G33(dev_priv
) || IS_PINEVIEW(dev_priv
)) {
7400 tmp
= I915_READ(DPLL(crtc
->pipe
));
7401 pipe_config
->pixel_multiplier
=
7402 ((tmp
& SDVO_MULTIPLIER_MASK
)
7403 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
7405 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7406 * port and will be fixed up in the encoder->get_config
7408 pipe_config
->pixel_multiplier
= 1;
7410 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
7411 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
)) {
7413 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
7414 * on 830. Filter it out here so that we don't
7415 * report errors due to that.
7417 if (IS_I830(dev_priv
))
7418 pipe_config
->dpll_hw_state
.dpll
&= ~DPLL_DVO_2X_MODE
;
7420 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
7421 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
7423 /* Mask out read-only status bits. */
7424 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
7425 DPLL_PORTC_READY_MASK
|
7426 DPLL_PORTB_READY_MASK
);
7429 if (IS_CHERRYVIEW(dev_priv
))
7430 chv_crtc_clock_get(crtc
, pipe_config
);
7431 else if (IS_VALLEYVIEW(dev_priv
))
7432 vlv_crtc_clock_get(crtc
, pipe_config
);
7434 i9xx_crtc_clock_get(crtc
, pipe_config
);
7437 * Normally the dotclock is filled in by the encoder .get_config()
7438 * but in case the pipe is enabled w/o any ports we need a sane
7441 pipe_config
->base
.adjusted_mode
.crtc_clock
=
7442 pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
7447 intel_display_power_put(dev_priv
, power_domain
);
7452 static void ironlake_init_pch_refclk(struct drm_i915_private
*dev_priv
)
7454 struct intel_encoder
*encoder
;
7457 bool has_lvds
= false;
7458 bool has_cpu_edp
= false;
7459 bool has_panel
= false;
7460 bool has_ck505
= false;
7461 bool can_ssc
= false;
7462 bool using_ssc_source
= false;
7464 /* We need to take the global config into account */
7465 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
7466 switch (encoder
->type
) {
7467 case INTEL_OUTPUT_LVDS
:
7471 case INTEL_OUTPUT_EDP
:
7473 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
7481 if (HAS_PCH_IBX(dev_priv
)) {
7482 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
7483 can_ssc
= has_ck505
;
7489 /* Check if any DPLLs are using the SSC source */
7490 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
7491 u32 temp
= I915_READ(PCH_DPLL(i
));
7493 if (!(temp
& DPLL_VCO_ENABLE
))
7496 if ((temp
& PLL_REF_INPUT_MASK
) ==
7497 PLLB_REF_INPUT_SPREADSPECTRUMIN
) {
7498 using_ssc_source
= true;
7503 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
7504 has_panel
, has_lvds
, has_ck505
, using_ssc_source
);
7506 /* Ironlake: try to setup display ref clock before DPLL
7507 * enabling. This is only under driver's control after
7508 * PCH B stepping, previous chipset stepping should be
7509 * ignoring this setting.
7511 val
= I915_READ(PCH_DREF_CONTROL
);
7513 /* As we must carefully and slowly disable/enable each source in turn,
7514 * compute the final state we want first and check if we need to
7515 * make any changes at all.
7518 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
7520 final
|= DREF_NONSPREAD_CK505_ENABLE
;
7522 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
7524 final
&= ~DREF_SSC_SOURCE_MASK
;
7525 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7526 final
&= ~DREF_SSC1_ENABLE
;
7529 final
|= DREF_SSC_SOURCE_ENABLE
;
7531 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
7532 final
|= DREF_SSC1_ENABLE
;
7535 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
7536 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
7538 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
7540 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7541 } else if (using_ssc_source
) {
7542 final
|= DREF_SSC_SOURCE_ENABLE
;
7543 final
|= DREF_SSC1_ENABLE
;
7549 /* Always enable nonspread source */
7550 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
7553 val
|= DREF_NONSPREAD_CK505_ENABLE
;
7555 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
7558 val
&= ~DREF_SSC_SOURCE_MASK
;
7559 val
|= DREF_SSC_SOURCE_ENABLE
;
7561 /* SSC must be turned on before enabling the CPU output */
7562 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
7563 DRM_DEBUG_KMS("Using SSC on panel\n");
7564 val
|= DREF_SSC1_ENABLE
;
7566 val
&= ~DREF_SSC1_ENABLE
;
7568 /* Get SSC going before enabling the outputs */
7569 I915_WRITE(PCH_DREF_CONTROL
, val
);
7570 POSTING_READ(PCH_DREF_CONTROL
);
7573 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7575 /* Enable CPU source on CPU attached eDP */
7577 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
7578 DRM_DEBUG_KMS("Using SSC on eDP\n");
7579 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
7581 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
7583 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7585 I915_WRITE(PCH_DREF_CONTROL
, val
);
7586 POSTING_READ(PCH_DREF_CONTROL
);
7589 DRM_DEBUG_KMS("Disabling CPU source output\n");
7591 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7593 /* Turn off CPU output */
7594 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7596 I915_WRITE(PCH_DREF_CONTROL
, val
);
7597 POSTING_READ(PCH_DREF_CONTROL
);
7600 if (!using_ssc_source
) {
7601 DRM_DEBUG_KMS("Disabling SSC source\n");
7603 /* Turn off the SSC source */
7604 val
&= ~DREF_SSC_SOURCE_MASK
;
7605 val
|= DREF_SSC_SOURCE_DISABLE
;
7608 val
&= ~DREF_SSC1_ENABLE
;
7610 I915_WRITE(PCH_DREF_CONTROL
, val
);
7611 POSTING_READ(PCH_DREF_CONTROL
);
7616 BUG_ON(val
!= final
);
7619 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
7623 tmp
= I915_READ(SOUTH_CHICKEN2
);
7624 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
7625 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
7627 if (wait_for_us(I915_READ(SOUTH_CHICKEN2
) &
7628 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
7629 DRM_ERROR("FDI mPHY reset assert timeout\n");
7631 tmp
= I915_READ(SOUTH_CHICKEN2
);
7632 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
7633 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
7635 if (wait_for_us((I915_READ(SOUTH_CHICKEN2
) &
7636 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
7637 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
7640 /* WaMPhyProgramming:hsw */
7641 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
7645 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
7646 tmp
&= ~(0xFF << 24);
7647 tmp
|= (0x12 << 24);
7648 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
7650 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
7652 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
7654 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
7656 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
7658 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
7659 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
7660 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
7662 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
7663 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
7664 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
7666 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
7669 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
7671 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
7674 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
7676 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
7679 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
7681 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
7684 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
7686 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
7687 tmp
&= ~(0xFF << 16);
7688 tmp
|= (0x1C << 16);
7689 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
7691 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
7692 tmp
&= ~(0xFF << 16);
7693 tmp
|= (0x1C << 16);
7694 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
7696 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
7698 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
7700 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
7702 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
7704 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
7705 tmp
&= ~(0xF << 28);
7707 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
7709 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
7710 tmp
&= ~(0xF << 28);
7712 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
7715 /* Implements 3 different sequences from BSpec chapter "Display iCLK
7716 * Programming" based on the parameters passed:
7717 * - Sequence to enable CLKOUT_DP
7718 * - Sequence to enable CLKOUT_DP without spread
7719 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
7721 static void lpt_enable_clkout_dp(struct drm_i915_private
*dev_priv
,
7722 bool with_spread
, bool with_fdi
)
7726 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
7728 if (WARN(HAS_PCH_LPT_LP(dev_priv
) &&
7729 with_fdi
, "LP PCH doesn't have FDI\n"))
7732 mutex_lock(&dev_priv
->sb_lock
);
7734 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7735 tmp
&= ~SBI_SSCCTL_DISABLE
;
7736 tmp
|= SBI_SSCCTL_PATHALT
;
7737 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7742 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7743 tmp
&= ~SBI_SSCCTL_PATHALT
;
7744 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7747 lpt_reset_fdi_mphy(dev_priv
);
7748 lpt_program_fdi_mphy(dev_priv
);
7752 reg
= HAS_PCH_LPT_LP(dev_priv
) ? SBI_GEN0
: SBI_DBUFF0
;
7753 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
7754 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
7755 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
7757 mutex_unlock(&dev_priv
->sb_lock
);
7760 /* Sequence to disable CLKOUT_DP */
7761 static void lpt_disable_clkout_dp(struct drm_i915_private
*dev_priv
)
7765 mutex_lock(&dev_priv
->sb_lock
);
7767 reg
= HAS_PCH_LPT_LP(dev_priv
) ? SBI_GEN0
: SBI_DBUFF0
;
7768 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
7769 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
7770 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
7772 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7773 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
7774 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
7775 tmp
|= SBI_SSCCTL_PATHALT
;
7776 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7779 tmp
|= SBI_SSCCTL_DISABLE
;
7780 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7783 mutex_unlock(&dev_priv
->sb_lock
);
7786 #define BEND_IDX(steps) ((50 + (steps)) / 5)
7788 static const uint16_t sscdivintphase
[] = {
7789 [BEND_IDX( 50)] = 0x3B23,
7790 [BEND_IDX( 45)] = 0x3B23,
7791 [BEND_IDX( 40)] = 0x3C23,
7792 [BEND_IDX( 35)] = 0x3C23,
7793 [BEND_IDX( 30)] = 0x3D23,
7794 [BEND_IDX( 25)] = 0x3D23,
7795 [BEND_IDX( 20)] = 0x3E23,
7796 [BEND_IDX( 15)] = 0x3E23,
7797 [BEND_IDX( 10)] = 0x3F23,
7798 [BEND_IDX( 5)] = 0x3F23,
7799 [BEND_IDX( 0)] = 0x0025,
7800 [BEND_IDX( -5)] = 0x0025,
7801 [BEND_IDX(-10)] = 0x0125,
7802 [BEND_IDX(-15)] = 0x0125,
7803 [BEND_IDX(-20)] = 0x0225,
7804 [BEND_IDX(-25)] = 0x0225,
7805 [BEND_IDX(-30)] = 0x0325,
7806 [BEND_IDX(-35)] = 0x0325,
7807 [BEND_IDX(-40)] = 0x0425,
7808 [BEND_IDX(-45)] = 0x0425,
7809 [BEND_IDX(-50)] = 0x0525,
7814 * steps -50 to 50 inclusive, in steps of 5
7815 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
7816 * change in clock period = -(steps / 10) * 5.787 ps
7818 static void lpt_bend_clkout_dp(struct drm_i915_private
*dev_priv
, int steps
)
7821 int idx
= BEND_IDX(steps
);
7823 if (WARN_ON(steps
% 5 != 0))
7826 if (WARN_ON(idx
>= ARRAY_SIZE(sscdivintphase
)))
7829 mutex_lock(&dev_priv
->sb_lock
);
7831 if (steps
% 10 != 0)
7835 intel_sbi_write(dev_priv
, SBI_SSCDITHPHASE
, tmp
, SBI_ICLK
);
7837 tmp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE
, SBI_ICLK
);
7839 tmp
|= sscdivintphase
[idx
];
7840 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE
, tmp
, SBI_ICLK
);
7842 mutex_unlock(&dev_priv
->sb_lock
);
7847 static void lpt_init_pch_refclk(struct drm_i915_private
*dev_priv
)
7849 struct intel_encoder
*encoder
;
7850 bool has_vga
= false;
7852 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
7853 switch (encoder
->type
) {
7854 case INTEL_OUTPUT_ANALOG
:
7863 lpt_bend_clkout_dp(dev_priv
, 0);
7864 lpt_enable_clkout_dp(dev_priv
, true, true);
7866 lpt_disable_clkout_dp(dev_priv
);
7871 * Initialize reference clocks when the driver loads
7873 void intel_init_pch_refclk(struct drm_i915_private
*dev_priv
)
7875 if (HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
))
7876 ironlake_init_pch_refclk(dev_priv
);
7877 else if (HAS_PCH_LPT(dev_priv
))
7878 lpt_init_pch_refclk(dev_priv
);
7881 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
7883 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
7884 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7885 int pipe
= intel_crtc
->pipe
;
7890 switch (intel_crtc
->config
->pipe_bpp
) {
7892 val
|= PIPECONF_6BPC
;
7895 val
|= PIPECONF_8BPC
;
7898 val
|= PIPECONF_10BPC
;
7901 val
|= PIPECONF_12BPC
;
7904 /* Case prevented by intel_choose_pipe_bpp_dither. */
7908 if (intel_crtc
->config
->dither
)
7909 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
7911 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
7912 val
|= PIPECONF_INTERLACED_ILK
;
7914 val
|= PIPECONF_PROGRESSIVE
;
7916 if (intel_crtc
->config
->limited_color_range
)
7917 val
|= PIPECONF_COLOR_RANGE_SELECT
;
7919 I915_WRITE(PIPECONF(pipe
), val
);
7920 POSTING_READ(PIPECONF(pipe
));
7923 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
7925 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
7926 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7927 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
7930 if (IS_HASWELL(dev_priv
) && intel_crtc
->config
->dither
)
7931 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
7933 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
7934 val
|= PIPECONF_INTERLACED_ILK
;
7936 val
|= PIPECONF_PROGRESSIVE
;
7938 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
7939 POSTING_READ(PIPECONF(cpu_transcoder
));
7942 static void haswell_set_pipemisc(struct drm_crtc
*crtc
)
7944 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
7945 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7946 struct intel_crtc_state
*config
= intel_crtc
->config
;
7948 if (IS_BROADWELL(dev_priv
) || INTEL_INFO(dev_priv
)->gen
>= 9) {
7951 switch (intel_crtc
->config
->pipe_bpp
) {
7953 val
|= PIPEMISC_DITHER_6_BPC
;
7956 val
|= PIPEMISC_DITHER_8_BPC
;
7959 val
|= PIPEMISC_DITHER_10_BPC
;
7962 val
|= PIPEMISC_DITHER_12_BPC
;
7965 /* Case prevented by pipe_config_set_bpp. */
7969 if (intel_crtc
->config
->dither
)
7970 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
7972 if (config
->ycbcr420
) {
7973 val
|= PIPEMISC_OUTPUT_COLORSPACE_YUV
|
7974 PIPEMISC_YUV420_ENABLE
|
7975 PIPEMISC_YUV420_MODE_FULL_BLEND
;
7978 I915_WRITE(PIPEMISC(intel_crtc
->pipe
), val
);
7982 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
7985 * Account for spread spectrum to avoid
7986 * oversubscribing the link. Max center spread
7987 * is 2.5%; use 5% for safety's sake.
7989 u32 bps
= target_clock
* bpp
* 21 / 20;
7990 return DIV_ROUND_UP(bps
, link_bw
* 8);
7993 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
7995 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
7998 static void ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
7999 struct intel_crtc_state
*crtc_state
,
8000 struct dpll
*reduced_clock
)
8002 struct drm_crtc
*crtc
= &intel_crtc
->base
;
8003 struct drm_device
*dev
= crtc
->dev
;
8004 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8008 /* Enable autotuning of the PLL clock (if permissible) */
8010 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8011 if ((intel_panel_use_ssc(dev_priv
) &&
8012 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
8013 (HAS_PCH_IBX(dev_priv
) && intel_is_dual_link_lvds(dev
)))
8015 } else if (crtc_state
->sdvo_tv_clock
)
8018 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
8020 if (ironlake_needs_fb_cb_tune(&crtc_state
->dpll
, factor
))
8023 if (reduced_clock
) {
8024 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
8026 if (reduced_clock
->m
< factor
* reduced_clock
->n
)
8034 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
))
8035 dpll
|= DPLLB_MODE_LVDS
;
8037 dpll
|= DPLLB_MODE_DAC_SERIAL
;
8039 dpll
|= (crtc_state
->pixel_multiplier
- 1)
8040 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
8042 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
8043 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
8044 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8046 if (intel_crtc_has_dp_encoder(crtc_state
))
8047 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8050 * The high speed IO clock is only really required for
8051 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8052 * possible to share the DPLL between CRT and HDMI. Enabling
8053 * the clock needlessly does no real harm, except use up a
8054 * bit of power potentially.
8056 * We'll limit this to IVB with 3 pipes, since it has only two
8057 * DPLLs and so DPLL sharing is the only way to get three pipes
8058 * driving PCH ports at the same time. On SNB we could do this,
8059 * and potentially avoid enabling the second DPLL, but it's not
8060 * clear if it''s a win or loss power wise. No point in doing
8061 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8063 if (INTEL_INFO(dev_priv
)->num_pipes
== 3 &&
8064 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
))
8065 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8067 /* compute bitmask from p1 value */
8068 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8070 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
8072 switch (crtc_state
->dpll
.p2
) {
8074 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
8077 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
8080 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
8083 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
8087 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
8088 intel_panel_use_ssc(dev_priv
))
8089 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
8091 dpll
|= PLL_REF_INPUT_DREFCLK
;
8093 dpll
|= DPLL_VCO_ENABLE
;
8095 crtc_state
->dpll_hw_state
.dpll
= dpll
;
8096 crtc_state
->dpll_hw_state
.fp0
= fp
;
8097 crtc_state
->dpll_hw_state
.fp1
= fp2
;
8100 static int ironlake_crtc_compute_clock(struct intel_crtc
*crtc
,
8101 struct intel_crtc_state
*crtc_state
)
8103 struct drm_device
*dev
= crtc
->base
.dev
;
8104 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8105 const struct intel_limit
*limit
;
8106 int refclk
= 120000;
8108 memset(&crtc_state
->dpll_hw_state
, 0,
8109 sizeof(crtc_state
->dpll_hw_state
));
8111 crtc
->lowfreq_avail
= false;
8113 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8114 if (!crtc_state
->has_pch_encoder
)
8117 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
8118 if (intel_panel_use_ssc(dev_priv
)) {
8119 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8120 dev_priv
->vbt
.lvds_ssc_freq
);
8121 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
8124 if (intel_is_dual_link_lvds(dev
)) {
8125 if (refclk
== 100000)
8126 limit
= &intel_limits_ironlake_dual_lvds_100m
;
8128 limit
= &intel_limits_ironlake_dual_lvds
;
8130 if (refclk
== 100000)
8131 limit
= &intel_limits_ironlake_single_lvds_100m
;
8133 limit
= &intel_limits_ironlake_single_lvds
;
8136 limit
= &intel_limits_ironlake_dac
;
8139 if (!crtc_state
->clock_set
&&
8140 !g4x_find_best_dpll(limit
, crtc_state
, crtc_state
->port_clock
,
8141 refclk
, NULL
, &crtc_state
->dpll
)) {
8142 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8146 ironlake_compute_dpll(crtc
, crtc_state
, NULL
);
8148 if (!intel_get_shared_dpll(crtc
, crtc_state
, NULL
)) {
8149 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8150 pipe_name(crtc
->pipe
));
8157 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
8158 struct intel_link_m_n
*m_n
)
8160 struct drm_device
*dev
= crtc
->base
.dev
;
8161 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8162 enum pipe pipe
= crtc
->pipe
;
8164 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
8165 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
8166 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
8168 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
8169 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
8170 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8173 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
8174 enum transcoder transcoder
,
8175 struct intel_link_m_n
*m_n
,
8176 struct intel_link_m_n
*m2_n2
)
8178 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
8179 enum pipe pipe
= crtc
->pipe
;
8181 if (INTEL_GEN(dev_priv
) >= 5) {
8182 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
8183 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
8184 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
8186 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
8187 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
8188 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8189 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8190 * gen < 8) and if DRRS is supported (to make sure the
8191 * registers are not unnecessarily read).
8193 if (m2_n2
&& INTEL_GEN(dev_priv
) < 8 &&
8194 crtc
->config
->has_drrs
) {
8195 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
8196 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
8197 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
8199 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
8200 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
8201 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8204 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
8205 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
8206 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
8208 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
8209 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
8210 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8214 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
8215 struct intel_crtc_state
*pipe_config
)
8217 if (pipe_config
->has_pch_encoder
)
8218 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
8220 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8221 &pipe_config
->dp_m_n
,
8222 &pipe_config
->dp_m2_n2
);
8225 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
8226 struct intel_crtc_state
*pipe_config
)
8228 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8229 &pipe_config
->fdi_m_n
, NULL
);
8232 static void skylake_get_pfit_config(struct intel_crtc
*crtc
,
8233 struct intel_crtc_state
*pipe_config
)
8235 struct drm_device
*dev
= crtc
->base
.dev
;
8236 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8237 struct intel_crtc_scaler_state
*scaler_state
= &pipe_config
->scaler_state
;
8238 uint32_t ps_ctrl
= 0;
8242 /* find scaler attached to this pipe */
8243 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
8244 ps_ctrl
= I915_READ(SKL_PS_CTRL(crtc
->pipe
, i
));
8245 if (ps_ctrl
& PS_SCALER_EN
&& !(ps_ctrl
& PS_PLANE_SEL_MASK
)) {
8247 pipe_config
->pch_pfit
.enabled
= true;
8248 pipe_config
->pch_pfit
.pos
= I915_READ(SKL_PS_WIN_POS(crtc
->pipe
, i
));
8249 pipe_config
->pch_pfit
.size
= I915_READ(SKL_PS_WIN_SZ(crtc
->pipe
, i
));
8254 scaler_state
->scaler_id
= id
;
8256 scaler_state
->scaler_users
|= (1 << SKL_CRTC_INDEX
);
8258 scaler_state
->scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
8263 skylake_get_initial_plane_config(struct intel_crtc
*crtc
,
8264 struct intel_initial_plane_config
*plane_config
)
8266 struct drm_device
*dev
= crtc
->base
.dev
;
8267 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8268 u32 val
, base
, offset
, stride_mult
, tiling
;
8269 int pipe
= crtc
->pipe
;
8270 int fourcc
, pixel_format
;
8271 unsigned int aligned_height
;
8272 struct drm_framebuffer
*fb
;
8273 struct intel_framebuffer
*intel_fb
;
8275 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8277 DRM_DEBUG_KMS("failed to alloc fb\n");
8281 fb
= &intel_fb
->base
;
8285 val
= I915_READ(PLANE_CTL(pipe
, 0));
8286 if (!(val
& PLANE_CTL_ENABLE
))
8289 pixel_format
= val
& PLANE_CTL_FORMAT_MASK
;
8290 fourcc
= skl_format_to_fourcc(pixel_format
,
8291 val
& PLANE_CTL_ORDER_RGBX
,
8292 val
& PLANE_CTL_ALPHA_MASK
);
8293 fb
->format
= drm_format_info(fourcc
);
8295 tiling
= val
& PLANE_CTL_TILED_MASK
;
8297 case PLANE_CTL_TILED_LINEAR
:
8298 fb
->modifier
= DRM_FORMAT_MOD_LINEAR
;
8300 case PLANE_CTL_TILED_X
:
8301 plane_config
->tiling
= I915_TILING_X
;
8302 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
8304 case PLANE_CTL_TILED_Y
:
8305 fb
->modifier
= I915_FORMAT_MOD_Y_TILED
;
8307 case PLANE_CTL_TILED_YF
:
8308 fb
->modifier
= I915_FORMAT_MOD_Yf_TILED
;
8311 MISSING_CASE(tiling
);
8315 base
= I915_READ(PLANE_SURF(pipe
, 0)) & 0xfffff000;
8316 plane_config
->base
= base
;
8318 offset
= I915_READ(PLANE_OFFSET(pipe
, 0));
8320 val
= I915_READ(PLANE_SIZE(pipe
, 0));
8321 fb
->height
= ((val
>> 16) & 0xfff) + 1;
8322 fb
->width
= ((val
>> 0) & 0x1fff) + 1;
8324 val
= I915_READ(PLANE_STRIDE(pipe
, 0));
8325 stride_mult
= intel_fb_stride_alignment(fb
, 0);
8326 fb
->pitches
[0] = (val
& 0x3ff) * stride_mult
;
8328 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
8330 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8332 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8333 pipe_name(pipe
), fb
->width
, fb
->height
,
8334 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
8335 plane_config
->size
);
8337 plane_config
->fb
= intel_fb
;
8344 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
8345 struct intel_crtc_state
*pipe_config
)
8347 struct drm_device
*dev
= crtc
->base
.dev
;
8348 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8351 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
8353 if (tmp
& PF_ENABLE
) {
8354 pipe_config
->pch_pfit
.enabled
= true;
8355 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
8356 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
8358 /* We currently do not free assignements of panel fitters on
8359 * ivb/hsw (since we don't use the higher upscaling modes which
8360 * differentiates them) so just WARN about this case for now. */
8361 if (IS_GEN7(dev_priv
)) {
8362 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
8363 PF_PIPE_SEL_IVB(crtc
->pipe
));
8369 ironlake_get_initial_plane_config(struct intel_crtc
*crtc
,
8370 struct intel_initial_plane_config
*plane_config
)
8372 struct drm_device
*dev
= crtc
->base
.dev
;
8373 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8374 u32 val
, base
, offset
;
8375 int pipe
= crtc
->pipe
;
8376 int fourcc
, pixel_format
;
8377 unsigned int aligned_height
;
8378 struct drm_framebuffer
*fb
;
8379 struct intel_framebuffer
*intel_fb
;
8381 val
= I915_READ(DSPCNTR(pipe
));
8382 if (!(val
& DISPLAY_PLANE_ENABLE
))
8385 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8387 DRM_DEBUG_KMS("failed to alloc fb\n");
8391 fb
= &intel_fb
->base
;
8395 if (INTEL_GEN(dev_priv
) >= 4) {
8396 if (val
& DISPPLANE_TILED
) {
8397 plane_config
->tiling
= I915_TILING_X
;
8398 fb
->modifier
= I915_FORMAT_MOD_X_TILED
;
8402 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
8403 fourcc
= i9xx_format_to_fourcc(pixel_format
);
8404 fb
->format
= drm_format_info(fourcc
);
8406 base
= I915_READ(DSPSURF(pipe
)) & 0xfffff000;
8407 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
8408 offset
= I915_READ(DSPOFFSET(pipe
));
8410 if (plane_config
->tiling
)
8411 offset
= I915_READ(DSPTILEOFF(pipe
));
8413 offset
= I915_READ(DSPLINOFF(pipe
));
8415 plane_config
->base
= base
;
8417 val
= I915_READ(PIPESRC(pipe
));
8418 fb
->width
= ((val
>> 16) & 0xfff) + 1;
8419 fb
->height
= ((val
>> 0) & 0xfff) + 1;
8421 val
= I915_READ(DSPSTRIDE(pipe
));
8422 fb
->pitches
[0] = val
& 0xffffffc0;
8424 aligned_height
= intel_fb_align_height(fb
, 0, fb
->height
);
8426 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8428 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8429 pipe_name(pipe
), fb
->width
, fb
->height
,
8430 fb
->format
->cpp
[0] * 8, base
, fb
->pitches
[0],
8431 plane_config
->size
);
8433 plane_config
->fb
= intel_fb
;
8436 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
8437 struct intel_crtc_state
*pipe_config
)
8439 struct drm_device
*dev
= crtc
->base
.dev
;
8440 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8441 enum intel_display_power_domain power_domain
;
8445 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
8446 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8449 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8450 pipe_config
->shared_dpll
= NULL
;
8453 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
8454 if (!(tmp
& PIPECONF_ENABLE
))
8457 switch (tmp
& PIPECONF_BPC_MASK
) {
8459 pipe_config
->pipe_bpp
= 18;
8462 pipe_config
->pipe_bpp
= 24;
8464 case PIPECONF_10BPC
:
8465 pipe_config
->pipe_bpp
= 30;
8467 case PIPECONF_12BPC
:
8468 pipe_config
->pipe_bpp
= 36;
8474 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
8475 pipe_config
->limited_color_range
= true;
8477 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
8478 struct intel_shared_dpll
*pll
;
8479 enum intel_dpll_id pll_id
;
8481 pipe_config
->has_pch_encoder
= true;
8483 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
8484 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
8485 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
8487 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
8489 if (HAS_PCH_IBX(dev_priv
)) {
8491 * The pipe->pch transcoder and pch transcoder->pll
8494 pll_id
= (enum intel_dpll_id
) crtc
->pipe
;
8496 tmp
= I915_READ(PCH_DPLL_SEL
);
8497 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
8498 pll_id
= DPLL_ID_PCH_PLL_B
;
8500 pll_id
= DPLL_ID_PCH_PLL_A
;
8503 pipe_config
->shared_dpll
=
8504 intel_get_shared_dpll_by_id(dev_priv
, pll_id
);
8505 pll
= pipe_config
->shared_dpll
;
8507 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
8508 &pipe_config
->dpll_hw_state
));
8510 tmp
= pipe_config
->dpll_hw_state
.dpll
;
8511 pipe_config
->pixel_multiplier
=
8512 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
8513 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
8515 ironlake_pch_clock_get(crtc
, pipe_config
);
8517 pipe_config
->pixel_multiplier
= 1;
8520 intel_get_pipe_timings(crtc
, pipe_config
);
8521 intel_get_pipe_src_size(crtc
, pipe_config
);
8523 ironlake_get_pfit_config(crtc
, pipe_config
);
8528 intel_display_power_put(dev_priv
, power_domain
);
8533 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
8535 struct drm_device
*dev
= &dev_priv
->drm
;
8536 struct intel_crtc
*crtc
;
8538 for_each_intel_crtc(dev
, crtc
)
8539 I915_STATE_WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
8540 pipe_name(crtc
->pipe
));
8542 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
8543 I915_STATE_WARN(I915_READ(SPLL_CTL
) & SPLL_PLL_ENABLE
, "SPLL enabled\n");
8544 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE
, "WRPLL1 enabled\n");
8545 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE
, "WRPLL2 enabled\n");
8546 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON
, "Panel power on\n");
8547 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
8548 "CPU PWM1 enabled\n");
8549 if (IS_HASWELL(dev_priv
))
8550 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
8551 "CPU PWM2 enabled\n");
8552 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
8553 "PCH PWM1 enabled\n");
8554 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
8555 "Utility pin enabled\n");
8556 I915_STATE_WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
8559 * In theory we can still leave IRQs enabled, as long as only the HPD
8560 * interrupts remain enabled. We used to check for that, but since it's
8561 * gen-specific and since we only disable LCPLL after we fully disable
8562 * the interrupts, the check below should be enough.
8564 I915_STATE_WARN(intel_irqs_enabled(dev_priv
), "IRQs enabled\n");
8567 static uint32_t hsw_read_dcomp(struct drm_i915_private
*dev_priv
)
8569 if (IS_HASWELL(dev_priv
))
8570 return I915_READ(D_COMP_HSW
);
8572 return I915_READ(D_COMP_BDW
);
8575 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
8577 if (IS_HASWELL(dev_priv
)) {
8578 mutex_lock(&dev_priv
->rps
.hw_lock
);
8579 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
8581 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
8582 mutex_unlock(&dev_priv
->rps
.hw_lock
);
8584 I915_WRITE(D_COMP_BDW
, val
);
8585 POSTING_READ(D_COMP_BDW
);
8590 * This function implements pieces of two sequences from BSpec:
8591 * - Sequence for display software to disable LCPLL
8592 * - Sequence for display software to allow package C8+
8593 * The steps implemented here are just the steps that actually touch the LCPLL
8594 * register. Callers should take care of disabling all the display engine
8595 * functions, doing the mode unset, fixing interrupts, etc.
8597 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
8598 bool switch_to_fclk
, bool allow_power_down
)
8602 assert_can_disable_lcpll(dev_priv
);
8604 val
= I915_READ(LCPLL_CTL
);
8606 if (switch_to_fclk
) {
8607 val
|= LCPLL_CD_SOURCE_FCLK
;
8608 I915_WRITE(LCPLL_CTL
, val
);
8610 if (wait_for_us(I915_READ(LCPLL_CTL
) &
8611 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
8612 DRM_ERROR("Switching to FCLK failed\n");
8614 val
= I915_READ(LCPLL_CTL
);
8617 val
|= LCPLL_PLL_DISABLE
;
8618 I915_WRITE(LCPLL_CTL
, val
);
8619 POSTING_READ(LCPLL_CTL
);
8621 if (intel_wait_for_register(dev_priv
, LCPLL_CTL
, LCPLL_PLL_LOCK
, 0, 1))
8622 DRM_ERROR("LCPLL still locked\n");
8624 val
= hsw_read_dcomp(dev_priv
);
8625 val
|= D_COMP_COMP_DISABLE
;
8626 hsw_write_dcomp(dev_priv
, val
);
8629 if (wait_for((hsw_read_dcomp(dev_priv
) & D_COMP_RCOMP_IN_PROGRESS
) == 0,
8631 DRM_ERROR("D_COMP RCOMP still in progress\n");
8633 if (allow_power_down
) {
8634 val
= I915_READ(LCPLL_CTL
);
8635 val
|= LCPLL_POWER_DOWN_ALLOW
;
8636 I915_WRITE(LCPLL_CTL
, val
);
8637 POSTING_READ(LCPLL_CTL
);
8642 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
8645 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
8649 val
= I915_READ(LCPLL_CTL
);
8651 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
8652 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
8656 * Make sure we're not on PC8 state before disabling PC8, otherwise
8657 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
8659 intel_uncore_forcewake_get(dev_priv
, FORCEWAKE_ALL
);
8661 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
8662 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
8663 I915_WRITE(LCPLL_CTL
, val
);
8664 POSTING_READ(LCPLL_CTL
);
8667 val
= hsw_read_dcomp(dev_priv
);
8668 val
|= D_COMP_COMP_FORCE
;
8669 val
&= ~D_COMP_COMP_DISABLE
;
8670 hsw_write_dcomp(dev_priv
, val
);
8672 val
= I915_READ(LCPLL_CTL
);
8673 val
&= ~LCPLL_PLL_DISABLE
;
8674 I915_WRITE(LCPLL_CTL
, val
);
8676 if (intel_wait_for_register(dev_priv
,
8677 LCPLL_CTL
, LCPLL_PLL_LOCK
, LCPLL_PLL_LOCK
,
8679 DRM_ERROR("LCPLL not locked yet\n");
8681 if (val
& LCPLL_CD_SOURCE_FCLK
) {
8682 val
= I915_READ(LCPLL_CTL
);
8683 val
&= ~LCPLL_CD_SOURCE_FCLK
;
8684 I915_WRITE(LCPLL_CTL
, val
);
8686 if (wait_for_us((I915_READ(LCPLL_CTL
) &
8687 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
8688 DRM_ERROR("Switching back to LCPLL failed\n");
8691 intel_uncore_forcewake_put(dev_priv
, FORCEWAKE_ALL
);
8692 intel_update_cdclk(dev_priv
);
8696 * Package states C8 and deeper are really deep PC states that can only be
8697 * reached when all the devices on the system allow it, so even if the graphics
8698 * device allows PC8+, it doesn't mean the system will actually get to these
8699 * states. Our driver only allows PC8+ when going into runtime PM.
8701 * The requirements for PC8+ are that all the outputs are disabled, the power
8702 * well is disabled and most interrupts are disabled, and these are also
8703 * requirements for runtime PM. When these conditions are met, we manually do
8704 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
8705 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
8708 * When we really reach PC8 or deeper states (not just when we allow it) we lose
8709 * the state of some registers, so when we come back from PC8+ we need to
8710 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
8711 * need to take care of the registers kept by RC6. Notice that this happens even
8712 * if we don't put the device in PCI D3 state (which is what currently happens
8713 * because of the runtime PM support).
8715 * For more, read "Display Sequences for Package C8" on the hardware
8718 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
8722 DRM_DEBUG_KMS("Enabling package C8+\n");
8724 if (HAS_PCH_LPT_LP(dev_priv
)) {
8725 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
8726 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
8727 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
8730 lpt_disable_clkout_dp(dev_priv
);
8731 hsw_disable_lcpll(dev_priv
, true, true);
8734 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
8738 DRM_DEBUG_KMS("Disabling package C8+\n");
8740 hsw_restore_lcpll(dev_priv
);
8741 lpt_init_pch_refclk(dev_priv
);
8743 if (HAS_PCH_LPT_LP(dev_priv
)) {
8744 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
8745 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
8746 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
8750 static int haswell_crtc_compute_clock(struct intel_crtc
*crtc
,
8751 struct intel_crtc_state
*crtc_state
)
8753 if (!intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DSI
)) {
8754 struct intel_encoder
*encoder
=
8755 intel_ddi_get_crtc_new_encoder(crtc_state
);
8757 if (!intel_get_shared_dpll(crtc
, crtc_state
, encoder
)) {
8758 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8759 pipe_name(crtc
->pipe
));
8764 crtc
->lowfreq_avail
= false;
8769 static void cannonlake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8771 struct intel_crtc_state
*pipe_config
)
8773 enum intel_dpll_id id
;
8776 temp
= I915_READ(DPCLKA_CFGCR0
) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port
);
8777 id
= temp
>> (port
* 2);
8779 if (WARN_ON(id
< SKL_DPLL0
|| id
> SKL_DPLL2
))
8782 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8785 static void bxt_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8787 struct intel_crtc_state
*pipe_config
)
8789 enum intel_dpll_id id
;
8793 id
= DPLL_ID_SKL_DPLL0
;
8796 id
= DPLL_ID_SKL_DPLL1
;
8799 id
= DPLL_ID_SKL_DPLL2
;
8802 DRM_ERROR("Incorrect port type\n");
8806 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8809 static void skylake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8811 struct intel_crtc_state
*pipe_config
)
8813 enum intel_dpll_id id
;
8816 temp
= I915_READ(DPLL_CTRL2
) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port
);
8817 id
= temp
>> (port
* 3 + 1);
8819 if (WARN_ON(id
< SKL_DPLL0
|| id
> SKL_DPLL3
))
8822 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8825 static void haswell_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8827 struct intel_crtc_state
*pipe_config
)
8829 enum intel_dpll_id id
;
8830 uint32_t ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
8832 switch (ddi_pll_sel
) {
8833 case PORT_CLK_SEL_WRPLL1
:
8834 id
= DPLL_ID_WRPLL1
;
8836 case PORT_CLK_SEL_WRPLL2
:
8837 id
= DPLL_ID_WRPLL2
;
8839 case PORT_CLK_SEL_SPLL
:
8842 case PORT_CLK_SEL_LCPLL_810
:
8843 id
= DPLL_ID_LCPLL_810
;
8845 case PORT_CLK_SEL_LCPLL_1350
:
8846 id
= DPLL_ID_LCPLL_1350
;
8848 case PORT_CLK_SEL_LCPLL_2700
:
8849 id
= DPLL_ID_LCPLL_2700
;
8852 MISSING_CASE(ddi_pll_sel
);
8854 case PORT_CLK_SEL_NONE
:
8858 pipe_config
->shared_dpll
= intel_get_shared_dpll_by_id(dev_priv
, id
);
8861 static bool hsw_get_transcoder_state(struct intel_crtc
*crtc
,
8862 struct intel_crtc_state
*pipe_config
,
8863 u64
*power_domain_mask
)
8865 struct drm_device
*dev
= crtc
->base
.dev
;
8866 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8867 enum intel_display_power_domain power_domain
;
8871 * The pipe->transcoder mapping is fixed with the exception of the eDP
8872 * transcoder handled below.
8874 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8877 * XXX: Do intel_display_power_get_if_enabled before reading this (for
8878 * consistency and less surprising code; it's in always on power).
8880 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
8881 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
8882 enum pipe trans_edp_pipe
;
8883 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
8885 WARN(1, "unknown pipe linked to edp transcoder\n");
8886 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
8887 case TRANS_DDI_EDP_INPUT_A_ON
:
8888 trans_edp_pipe
= PIPE_A
;
8890 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
8891 trans_edp_pipe
= PIPE_B
;
8893 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
8894 trans_edp_pipe
= PIPE_C
;
8898 if (trans_edp_pipe
== crtc
->pipe
)
8899 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
8902 power_domain
= POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
);
8903 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8905 *power_domain_mask
|= BIT_ULL(power_domain
);
8907 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
8909 return tmp
& PIPECONF_ENABLE
;
8912 static bool bxt_get_dsi_transcoder_state(struct intel_crtc
*crtc
,
8913 struct intel_crtc_state
*pipe_config
,
8914 u64
*power_domain_mask
)
8916 struct drm_device
*dev
= crtc
->base
.dev
;
8917 struct drm_i915_private
*dev_priv
= to_i915(dev
);
8918 enum intel_display_power_domain power_domain
;
8920 enum transcoder cpu_transcoder
;
8923 for_each_port_masked(port
, BIT(PORT_A
) | BIT(PORT_C
)) {
8925 cpu_transcoder
= TRANSCODER_DSI_A
;
8927 cpu_transcoder
= TRANSCODER_DSI_C
;
8929 power_domain
= POWER_DOMAIN_TRANSCODER(cpu_transcoder
);
8930 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
8932 *power_domain_mask
|= BIT_ULL(power_domain
);
8935 * The PLL needs to be enabled with a valid divider
8936 * configuration, otherwise accessing DSI registers will hang
8937 * the machine. See BSpec North Display Engine
8938 * registers/MIPI[BXT]. We can break out here early, since we
8939 * need the same DSI PLL to be enabled for both DSI ports.
8941 if (!intel_dsi_pll_is_enabled(dev_priv
))
8944 /* XXX: this works for video mode only */
8945 tmp
= I915_READ(BXT_MIPI_PORT_CTRL(port
));
8946 if (!(tmp
& DPI_ENABLE
))
8949 tmp
= I915_READ(MIPI_CTRL(port
));
8950 if ((tmp
& BXT_PIPE_SELECT_MASK
) != BXT_PIPE_SELECT(crtc
->pipe
))
8953 pipe_config
->cpu_transcoder
= cpu_transcoder
;
8957 return transcoder_is_dsi(pipe_config
->cpu_transcoder
);
8960 static void haswell_get_ddi_port_state(struct intel_crtc
*crtc
,
8961 struct intel_crtc_state
*pipe_config
)
8963 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
8964 struct intel_shared_dpll
*pll
;
8968 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
8970 port
= (tmp
& TRANS_DDI_PORT_MASK
) >> TRANS_DDI_PORT_SHIFT
;
8972 if (IS_CANNONLAKE(dev_priv
))
8973 cannonlake_get_ddi_pll(dev_priv
, port
, pipe_config
);
8974 else if (IS_GEN9_BC(dev_priv
))
8975 skylake_get_ddi_pll(dev_priv
, port
, pipe_config
);
8976 else if (IS_GEN9_LP(dev_priv
))
8977 bxt_get_ddi_pll(dev_priv
, port
, pipe_config
);
8979 haswell_get_ddi_pll(dev_priv
, port
, pipe_config
);
8981 pll
= pipe_config
->shared_dpll
;
8983 WARN_ON(!pll
->funcs
.get_hw_state(dev_priv
, pll
,
8984 &pipe_config
->dpll_hw_state
));
8988 * Haswell has only FDI/PCH transcoder A. It is which is connected to
8989 * DDI E. So just check whether this pipe is wired to DDI E and whether
8990 * the PCH transcoder is on.
8992 if (INTEL_GEN(dev_priv
) < 9 &&
8993 (port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
8994 pipe_config
->has_pch_encoder
= true;
8996 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
8997 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
8998 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
9000 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
9004 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
9005 struct intel_crtc_state
*pipe_config
)
9007 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9008 enum intel_display_power_domain power_domain
;
9009 u64 power_domain_mask
;
9012 intel_crtc_init_scalers(crtc
, pipe_config
);
9014 power_domain
= POWER_DOMAIN_PIPE(crtc
->pipe
);
9015 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
9017 power_domain_mask
= BIT_ULL(power_domain
);
9019 pipe_config
->shared_dpll
= NULL
;
9021 active
= hsw_get_transcoder_state(crtc
, pipe_config
, &power_domain_mask
);
9023 if (IS_GEN9_LP(dev_priv
) &&
9024 bxt_get_dsi_transcoder_state(crtc
, pipe_config
, &power_domain_mask
)) {
9032 if (!transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
9033 haswell_get_ddi_port_state(crtc
, pipe_config
);
9034 intel_get_pipe_timings(crtc
, pipe_config
);
9037 intel_get_pipe_src_size(crtc
, pipe_config
);
9039 pipe_config
->gamma_mode
=
9040 I915_READ(GAMMA_MODE(crtc
->pipe
)) & GAMMA_MODE_MODE_MASK
;
9042 if (IS_BROADWELL(dev_priv
) || dev_priv
->info
.gen
>= 9) {
9043 u32 tmp
= I915_READ(PIPEMISC(crtc
->pipe
));
9044 bool clrspace_yuv
= tmp
& PIPEMISC_OUTPUT_COLORSPACE_YUV
;
9046 if (IS_GEMINILAKE(dev_priv
) || dev_priv
->info
.gen
>= 10) {
9047 bool blend_mode_420
= tmp
&
9048 PIPEMISC_YUV420_MODE_FULL_BLEND
;
9050 pipe_config
->ycbcr420
= tmp
& PIPEMISC_YUV420_ENABLE
;
9051 if (pipe_config
->ycbcr420
!= clrspace_yuv
||
9052 pipe_config
->ycbcr420
!= blend_mode_420
)
9053 DRM_DEBUG_KMS("Bad 4:2:0 mode (%08x)\n", tmp
);
9054 } else if (clrspace_yuv
) {
9055 DRM_DEBUG_KMS("YCbCr 4:2:0 Unsupported\n");
9059 power_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
9060 if (intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
9061 power_domain_mask
|= BIT_ULL(power_domain
);
9062 if (INTEL_GEN(dev_priv
) >= 9)
9063 skylake_get_pfit_config(crtc
, pipe_config
);
9065 ironlake_get_pfit_config(crtc
, pipe_config
);
9068 if (IS_HASWELL(dev_priv
))
9069 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
9070 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
9072 if (pipe_config
->cpu_transcoder
!= TRANSCODER_EDP
&&
9073 !transcoder_is_dsi(pipe_config
->cpu_transcoder
)) {
9074 pipe_config
->pixel_multiplier
=
9075 I915_READ(PIPE_MULT(pipe_config
->cpu_transcoder
)) + 1;
9077 pipe_config
->pixel_multiplier
= 1;
9081 for_each_power_domain(power_domain
, power_domain_mask
)
9082 intel_display_power_put(dev_priv
, power_domain
);
9087 static u32
intel_cursor_base(const struct intel_plane_state
*plane_state
)
9089 struct drm_i915_private
*dev_priv
=
9090 to_i915(plane_state
->base
.plane
->dev
);
9091 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9092 const struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
9095 if (INTEL_INFO(dev_priv
)->cursor_needs_physical
)
9096 base
= obj
->phys_handle
->busaddr
;
9098 base
= intel_plane_ggtt_offset(plane_state
);
9100 base
+= plane_state
->main
.offset
;
9102 /* ILK+ do this automagically */
9103 if (HAS_GMCH_DISPLAY(dev_priv
) &&
9104 plane_state
->base
.rotation
& DRM_MODE_ROTATE_180
)
9105 base
+= (plane_state
->base
.crtc_h
*
9106 plane_state
->base
.crtc_w
- 1) * fb
->format
->cpp
[0];
9111 static u32
intel_cursor_position(const struct intel_plane_state
*plane_state
)
9113 int x
= plane_state
->base
.crtc_x
;
9114 int y
= plane_state
->base
.crtc_y
;
9118 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
9121 pos
|= x
<< CURSOR_X_SHIFT
;
9124 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
9127 pos
|= y
<< CURSOR_Y_SHIFT
;
9132 static bool intel_cursor_size_ok(const struct intel_plane_state
*plane_state
)
9134 const struct drm_mode_config
*config
=
9135 &plane_state
->base
.plane
->dev
->mode_config
;
9136 int width
= plane_state
->base
.crtc_w
;
9137 int height
= plane_state
->base
.crtc_h
;
9139 return width
> 0 && width
<= config
->cursor_width
&&
9140 height
> 0 && height
<= config
->cursor_height
;
9143 static int intel_check_cursor(struct intel_crtc_state
*crtc_state
,
9144 struct intel_plane_state
*plane_state
)
9146 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9151 ret
= drm_plane_helper_check_state(&plane_state
->base
,
9153 DRM_PLANE_HELPER_NO_SCALING
,
9154 DRM_PLANE_HELPER_NO_SCALING
,
9162 if (fb
->modifier
!= DRM_FORMAT_MOD_LINEAR
) {
9163 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9167 src_x
= plane_state
->base
.src_x
>> 16;
9168 src_y
= plane_state
->base
.src_y
>> 16;
9170 intel_add_fb_offsets(&src_x
, &src_y
, plane_state
, 0);
9171 offset
= intel_compute_tile_offset(&src_x
, &src_y
, plane_state
, 0);
9173 if (src_x
!= 0 || src_y
!= 0) {
9174 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9178 plane_state
->main
.offset
= offset
;
9183 static u32
i845_cursor_ctl(const struct intel_crtc_state
*crtc_state
,
9184 const struct intel_plane_state
*plane_state
)
9186 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9188 return CURSOR_ENABLE
|
9189 CURSOR_GAMMA_ENABLE
|
9190 CURSOR_FORMAT_ARGB
|
9191 CURSOR_STRIDE(fb
->pitches
[0]);
9194 static bool i845_cursor_size_ok(const struct intel_plane_state
*plane_state
)
9196 int width
= plane_state
->base
.crtc_w
;
9199 * 845g/865g are only limited by the width of their cursors,
9200 * the height is arbitrary up to the precision of the register.
9202 return intel_cursor_size_ok(plane_state
) && IS_ALIGNED(width
, 64);
9205 static int i845_check_cursor(struct intel_plane
*plane
,
9206 struct intel_crtc_state
*crtc_state
,
9207 struct intel_plane_state
*plane_state
)
9209 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9212 ret
= intel_check_cursor(crtc_state
, plane_state
);
9216 /* if we want to turn off the cursor ignore width and height */
9220 /* Check for which cursor types we support */
9221 if (!i845_cursor_size_ok(plane_state
)) {
9222 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9223 plane_state
->base
.crtc_w
,
9224 plane_state
->base
.crtc_h
);
9228 switch (fb
->pitches
[0]) {
9235 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
9240 plane_state
->ctl
= i845_cursor_ctl(crtc_state
, plane_state
);
9245 static void i845_update_cursor(struct intel_plane
*plane
,
9246 const struct intel_crtc_state
*crtc_state
,
9247 const struct intel_plane_state
*plane_state
)
9249 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
9250 u32 cntl
= 0, base
= 0, pos
= 0, size
= 0;
9251 unsigned long irqflags
;
9253 if (plane_state
&& plane_state
->base
.visible
) {
9254 unsigned int width
= plane_state
->base
.crtc_w
;
9255 unsigned int height
= plane_state
->base
.crtc_h
;
9257 cntl
= plane_state
->ctl
;
9258 size
= (height
<< 12) | width
;
9260 base
= intel_cursor_base(plane_state
);
9261 pos
= intel_cursor_position(plane_state
);
9264 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
9266 /* On these chipsets we can only modify the base/size/stride
9267 * whilst the cursor is disabled.
9269 if (plane
->cursor
.base
!= base
||
9270 plane
->cursor
.size
!= size
||
9271 plane
->cursor
.cntl
!= cntl
) {
9272 I915_WRITE_FW(CURCNTR(PIPE_A
), 0);
9273 I915_WRITE_FW(CURBASE(PIPE_A
), base
);
9274 I915_WRITE_FW(CURSIZE
, size
);
9275 I915_WRITE_FW(CURPOS(PIPE_A
), pos
);
9276 I915_WRITE_FW(CURCNTR(PIPE_A
), cntl
);
9278 plane
->cursor
.base
= base
;
9279 plane
->cursor
.size
= size
;
9280 plane
->cursor
.cntl
= cntl
;
9282 I915_WRITE_FW(CURPOS(PIPE_A
), pos
);
9285 POSTING_READ_FW(CURCNTR(PIPE_A
));
9287 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
9290 static void i845_disable_cursor(struct intel_plane
*plane
,
9291 struct intel_crtc
*crtc
)
9293 i845_update_cursor(plane
, NULL
, NULL
);
9296 static u32
i9xx_cursor_ctl(const struct intel_crtc_state
*crtc_state
,
9297 const struct intel_plane_state
*plane_state
)
9299 struct drm_i915_private
*dev_priv
=
9300 to_i915(plane_state
->base
.plane
->dev
);
9301 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
9304 cntl
= MCURSOR_GAMMA_ENABLE
;
9306 if (HAS_DDI(dev_priv
))
9307 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
9309 cntl
|= MCURSOR_PIPE_SELECT(crtc
->pipe
);
9311 switch (plane_state
->base
.crtc_w
) {
9313 cntl
|= CURSOR_MODE_64_ARGB_AX
;
9316 cntl
|= CURSOR_MODE_128_ARGB_AX
;
9319 cntl
|= CURSOR_MODE_256_ARGB_AX
;
9322 MISSING_CASE(plane_state
->base
.crtc_w
);
9326 if (plane_state
->base
.rotation
& DRM_MODE_ROTATE_180
)
9327 cntl
|= CURSOR_ROTATE_180
;
9332 static bool i9xx_cursor_size_ok(const struct intel_plane_state
*plane_state
)
9334 struct drm_i915_private
*dev_priv
=
9335 to_i915(plane_state
->base
.plane
->dev
);
9336 int width
= plane_state
->base
.crtc_w
;
9337 int height
= plane_state
->base
.crtc_h
;
9339 if (!intel_cursor_size_ok(plane_state
))
9342 /* Cursor width is limited to a few power-of-two sizes */
9353 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
9354 * height from 8 lines up to the cursor width, when the
9355 * cursor is not rotated. Everything else requires square
9358 if (HAS_CUR_FBC(dev_priv
) &&
9359 plane_state
->base
.rotation
& DRM_MODE_ROTATE_0
) {
9360 if (height
< 8 || height
> width
)
9363 if (height
!= width
)
9370 static int i9xx_check_cursor(struct intel_plane
*plane
,
9371 struct intel_crtc_state
*crtc_state
,
9372 struct intel_plane_state
*plane_state
)
9374 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
9375 const struct drm_framebuffer
*fb
= plane_state
->base
.fb
;
9376 enum pipe pipe
= plane
->pipe
;
9379 ret
= intel_check_cursor(crtc_state
, plane_state
);
9383 /* if we want to turn off the cursor ignore width and height */
9387 /* Check for which cursor types we support */
9388 if (!i9xx_cursor_size_ok(plane_state
)) {
9389 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9390 plane_state
->base
.crtc_w
,
9391 plane_state
->base
.crtc_h
);
9395 if (fb
->pitches
[0] != plane_state
->base
.crtc_w
* fb
->format
->cpp
[0]) {
9396 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
9397 fb
->pitches
[0], plane_state
->base
.crtc_w
);
9402 * There's something wrong with the cursor on CHV pipe C.
9403 * If it straddles the left edge of the screen then
9404 * moving it away from the edge or disabling it often
9405 * results in a pipe underrun, and often that can lead to
9406 * dead pipe (constant underrun reported, and it scans
9407 * out just a solid color). To recover from that, the
9408 * display power well must be turned off and on again.
9409 * Refuse the put the cursor into that compromised position.
9411 if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_C
&&
9412 plane_state
->base
.visible
&& plane_state
->base
.crtc_x
< 0) {
9413 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
9417 plane_state
->ctl
= i9xx_cursor_ctl(crtc_state
, plane_state
);
9422 static void i9xx_update_cursor(struct intel_plane
*plane
,
9423 const struct intel_crtc_state
*crtc_state
,
9424 const struct intel_plane_state
*plane_state
)
9426 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
9427 enum pipe pipe
= plane
->pipe
;
9428 u32 cntl
= 0, base
= 0, pos
= 0, fbc_ctl
= 0;
9429 unsigned long irqflags
;
9431 if (plane_state
&& plane_state
->base
.visible
) {
9432 cntl
= plane_state
->ctl
;
9434 if (plane_state
->base
.crtc_h
!= plane_state
->base
.crtc_w
)
9435 fbc_ctl
= CUR_FBC_CTL_EN
| (plane_state
->base
.crtc_h
- 1);
9437 base
= intel_cursor_base(plane_state
);
9438 pos
= intel_cursor_position(plane_state
);
9441 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
9444 * On some platforms writing CURCNTR first will also
9445 * cause CURPOS to be armed by the CURBASE write.
9446 * Without the CURCNTR write the CURPOS write would
9447 * arm itself. Thus we always start the full update
9448 * with a CURCNTR write.
9450 * On other platforms CURPOS always requires the
9451 * CURBASE write to arm the update. Additonally
9452 * a write to any of the cursor register will cancel
9453 * an already armed cursor update. Thus leaving out
9454 * the CURBASE write after CURPOS could lead to a
9455 * cursor that doesn't appear to move, or even change
9456 * shape. Thus we always write CURBASE.
9458 * CURCNTR and CUR_FBC_CTL are always
9459 * armed by the CURBASE write only.
9461 if (plane
->cursor
.base
!= base
||
9462 plane
->cursor
.size
!= fbc_ctl
||
9463 plane
->cursor
.cntl
!= cntl
) {
9464 I915_WRITE_FW(CURCNTR(pipe
), cntl
);
9465 if (HAS_CUR_FBC(dev_priv
))
9466 I915_WRITE_FW(CUR_FBC_CTL(pipe
), fbc_ctl
);
9467 I915_WRITE_FW(CURPOS(pipe
), pos
);
9468 I915_WRITE_FW(CURBASE(pipe
), base
);
9470 plane
->cursor
.base
= base
;
9471 plane
->cursor
.size
= fbc_ctl
;
9472 plane
->cursor
.cntl
= cntl
;
9474 I915_WRITE_FW(CURPOS(pipe
), pos
);
9475 I915_WRITE_FW(CURBASE(pipe
), base
);
9478 POSTING_READ_FW(CURBASE(pipe
));
9480 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
9483 static void i9xx_disable_cursor(struct intel_plane
*plane
,
9484 struct intel_crtc
*crtc
)
9486 i9xx_update_cursor(plane
, NULL
, NULL
);
9490 /* VESA 640x480x72Hz mode to set on the pipe */
9491 static struct drm_display_mode load_detect_mode
= {
9492 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
9493 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
9496 struct drm_framebuffer
*
9497 intel_framebuffer_create(struct drm_i915_gem_object
*obj
,
9498 struct drm_mode_fb_cmd2
*mode_cmd
)
9500 struct intel_framebuffer
*intel_fb
;
9503 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9505 return ERR_PTR(-ENOMEM
);
9507 ret
= intel_framebuffer_init(intel_fb
, obj
, mode_cmd
);
9511 return &intel_fb
->base
;
9515 return ERR_PTR(ret
);
9519 intel_framebuffer_pitch_for_width(int width
, int bpp
)
9521 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
9522 return ALIGN(pitch
, 64);
9526 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
9528 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
9529 return PAGE_ALIGN(pitch
* mode
->vdisplay
);
9532 static struct drm_framebuffer
*
9533 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
9534 struct drm_display_mode
*mode
,
9537 struct drm_framebuffer
*fb
;
9538 struct drm_i915_gem_object
*obj
;
9539 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
9541 obj
= i915_gem_object_create(to_i915(dev
),
9542 intel_framebuffer_size_for_mode(mode
, bpp
));
9544 return ERR_CAST(obj
);
9546 mode_cmd
.width
= mode
->hdisplay
;
9547 mode_cmd
.height
= mode
->vdisplay
;
9548 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
9550 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
9552 fb
= intel_framebuffer_create(obj
, &mode_cmd
);
9554 i915_gem_object_put(obj
);
9559 static struct drm_framebuffer
*
9560 mode_fits_in_fbdev(struct drm_device
*dev
,
9561 struct drm_display_mode
*mode
)
9563 #ifdef CONFIG_DRM_FBDEV_EMULATION
9564 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9565 struct drm_i915_gem_object
*obj
;
9566 struct drm_framebuffer
*fb
;
9568 if (!dev_priv
->fbdev
)
9571 if (!dev_priv
->fbdev
->fb
)
9574 obj
= dev_priv
->fbdev
->fb
->obj
;
9577 fb
= &dev_priv
->fbdev
->fb
->base
;
9578 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
9579 fb
->format
->cpp
[0] * 8))
9582 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
9585 drm_framebuffer_reference(fb
);
9592 static int intel_modeset_setup_plane_state(struct drm_atomic_state
*state
,
9593 struct drm_crtc
*crtc
,
9594 struct drm_display_mode
*mode
,
9595 struct drm_framebuffer
*fb
,
9598 struct drm_plane_state
*plane_state
;
9599 int hdisplay
, vdisplay
;
9602 plane_state
= drm_atomic_get_plane_state(state
, crtc
->primary
);
9603 if (IS_ERR(plane_state
))
9604 return PTR_ERR(plane_state
);
9607 drm_mode_get_hv_timing(mode
, &hdisplay
, &vdisplay
);
9609 hdisplay
= vdisplay
= 0;
9611 ret
= drm_atomic_set_crtc_for_plane(plane_state
, fb
? crtc
: NULL
);
9614 drm_atomic_set_fb_for_plane(plane_state
, fb
);
9615 plane_state
->crtc_x
= 0;
9616 plane_state
->crtc_y
= 0;
9617 plane_state
->crtc_w
= hdisplay
;
9618 plane_state
->crtc_h
= vdisplay
;
9619 plane_state
->src_x
= x
<< 16;
9620 plane_state
->src_y
= y
<< 16;
9621 plane_state
->src_w
= hdisplay
<< 16;
9622 plane_state
->src_h
= vdisplay
<< 16;
9627 int intel_get_load_detect_pipe(struct drm_connector
*connector
,
9628 struct drm_display_mode
*mode
,
9629 struct intel_load_detect_pipe
*old
,
9630 struct drm_modeset_acquire_ctx
*ctx
)
9632 struct intel_crtc
*intel_crtc
;
9633 struct intel_encoder
*intel_encoder
=
9634 intel_attached_encoder(connector
);
9635 struct drm_crtc
*possible_crtc
;
9636 struct drm_encoder
*encoder
= &intel_encoder
->base
;
9637 struct drm_crtc
*crtc
= NULL
;
9638 struct drm_device
*dev
= encoder
->dev
;
9639 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9640 struct drm_framebuffer
*fb
;
9641 struct drm_mode_config
*config
= &dev
->mode_config
;
9642 struct drm_atomic_state
*state
= NULL
, *restore_state
= NULL
;
9643 struct drm_connector_state
*connector_state
;
9644 struct intel_crtc_state
*crtc_state
;
9647 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9648 connector
->base
.id
, connector
->name
,
9649 encoder
->base
.id
, encoder
->name
);
9651 old
->restore_state
= NULL
;
9653 WARN_ON(!drm_modeset_is_locked(&config
->connection_mutex
));
9656 * Algorithm gets a little messy:
9658 * - if the connector already has an assigned crtc, use it (but make
9659 * sure it's on first)
9661 * - try to find the first unused crtc that can drive this connector,
9662 * and use that if we find one
9665 /* See if we already have a CRTC for this connector */
9666 if (connector
->state
->crtc
) {
9667 crtc
= connector
->state
->crtc
;
9669 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
9673 /* Make sure the crtc and connector are running */
9677 /* Find an unused one (if possible) */
9678 for_each_crtc(dev
, possible_crtc
) {
9680 if (!(encoder
->possible_crtcs
& (1 << i
)))
9683 ret
= drm_modeset_lock(&possible_crtc
->mutex
, ctx
);
9687 if (possible_crtc
->state
->enable
) {
9688 drm_modeset_unlock(&possible_crtc
->mutex
);
9692 crtc
= possible_crtc
;
9697 * If we didn't find an unused CRTC, don't use any.
9700 DRM_DEBUG_KMS("no pipe available for load-detect\n");
9706 intel_crtc
= to_intel_crtc(crtc
);
9708 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
9712 state
= drm_atomic_state_alloc(dev
);
9713 restore_state
= drm_atomic_state_alloc(dev
);
9714 if (!state
|| !restore_state
) {
9719 state
->acquire_ctx
= ctx
;
9720 restore_state
->acquire_ctx
= ctx
;
9722 connector_state
= drm_atomic_get_connector_state(state
, connector
);
9723 if (IS_ERR(connector_state
)) {
9724 ret
= PTR_ERR(connector_state
);
9728 ret
= drm_atomic_set_crtc_for_connector(connector_state
, crtc
);
9732 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
9733 if (IS_ERR(crtc_state
)) {
9734 ret
= PTR_ERR(crtc_state
);
9738 crtc_state
->base
.active
= crtc_state
->base
.enable
= true;
9741 mode
= &load_detect_mode
;
9743 /* We need a framebuffer large enough to accommodate all accesses
9744 * that the plane may generate whilst we perform load detection.
9745 * We can not rely on the fbcon either being present (we get called
9746 * during its initialisation to detect all boot displays, or it may
9747 * not even exist) or that it is large enough to satisfy the
9750 fb
= mode_fits_in_fbdev(dev
, mode
);
9752 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
9753 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
9755 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
9757 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
9762 ret
= intel_modeset_setup_plane_state(state
, crtc
, mode
, fb
, 0, 0);
9766 drm_framebuffer_unreference(fb
);
9768 ret
= drm_atomic_set_mode_for_crtc(&crtc_state
->base
, mode
);
9772 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state
, connector
));
9774 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state
, crtc
));
9776 ret
= PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state
, crtc
->primary
));
9778 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret
);
9782 ret
= drm_atomic_commit(state
);
9784 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
9788 old
->restore_state
= restore_state
;
9789 drm_atomic_state_put(state
);
9791 /* let the connector get through one full cycle before testing */
9792 intel_wait_for_vblank(dev_priv
, intel_crtc
->pipe
);
9797 drm_atomic_state_put(state
);
9800 if (restore_state
) {
9801 drm_atomic_state_put(restore_state
);
9802 restore_state
= NULL
;
9805 if (ret
== -EDEADLK
)
9811 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
9812 struct intel_load_detect_pipe
*old
,
9813 struct drm_modeset_acquire_ctx
*ctx
)
9815 struct intel_encoder
*intel_encoder
=
9816 intel_attached_encoder(connector
);
9817 struct drm_encoder
*encoder
= &intel_encoder
->base
;
9818 struct drm_atomic_state
*state
= old
->restore_state
;
9821 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9822 connector
->base
.id
, connector
->name
,
9823 encoder
->base
.id
, encoder
->name
);
9828 ret
= drm_atomic_helper_commit_duplicated_state(state
, ctx
);
9830 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret
);
9831 drm_atomic_state_put(state
);
9834 static int i9xx_pll_refclk(struct drm_device
*dev
,
9835 const struct intel_crtc_state
*pipe_config
)
9837 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9838 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
9840 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
9841 return dev_priv
->vbt
.lvds_ssc_freq
;
9842 else if (HAS_PCH_SPLIT(dev_priv
))
9844 else if (!IS_GEN2(dev_priv
))
9850 /* Returns the clock of the currently programmed mode of the given pipe. */
9851 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
9852 struct intel_crtc_state
*pipe_config
)
9854 struct drm_device
*dev
= crtc
->base
.dev
;
9855 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9856 int pipe
= pipe_config
->cpu_transcoder
;
9857 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
9861 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
9863 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
9864 fp
= pipe_config
->dpll_hw_state
.fp0
;
9866 fp
= pipe_config
->dpll_hw_state
.fp1
;
9868 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
9869 if (IS_PINEVIEW(dev_priv
)) {
9870 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
9871 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
9873 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
9874 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
9877 if (!IS_GEN2(dev_priv
)) {
9878 if (IS_PINEVIEW(dev_priv
))
9879 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
9880 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
9882 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
9883 DPLL_FPA01_P1_POST_DIV_SHIFT
);
9885 switch (dpll
& DPLL_MODE_MASK
) {
9886 case DPLLB_MODE_DAC_SERIAL
:
9887 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
9890 case DPLLB_MODE_LVDS
:
9891 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
9895 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
9896 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
9900 if (IS_PINEVIEW(dev_priv
))
9901 port_clock
= pnv_calc_dpll_params(refclk
, &clock
);
9903 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
9905 u32 lvds
= IS_I830(dev_priv
) ? 0 : I915_READ(LVDS
);
9906 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
9909 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
9910 DPLL_FPA01_P1_POST_DIV_SHIFT
);
9912 if (lvds
& LVDS_CLKB_POWER_UP
)
9917 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
9920 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
9921 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
9923 if (dpll
& PLL_P2_DIVIDE_BY_4
)
9929 port_clock
= i9xx_calc_dpll_params(refclk
, &clock
);
9933 * This value includes pixel_multiplier. We will use
9934 * port_clock to compute adjusted_mode.crtc_clock in the
9935 * encoder's get_config() function.
9937 pipe_config
->port_clock
= port_clock
;
9940 int intel_dotclock_calculate(int link_freq
,
9941 const struct intel_link_m_n
*m_n
)
9944 * The calculation for the data clock is:
9945 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
9946 * But we want to avoid losing precison if possible, so:
9947 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
9949 * and the link clock is simpler:
9950 * link_clock = (m * link_clock) / n
9956 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
9959 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
9960 struct intel_crtc_state
*pipe_config
)
9962 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
9964 /* read out port_clock from the DPLL */
9965 i9xx_crtc_clock_get(crtc
, pipe_config
);
9968 * In case there is an active pipe without active ports,
9969 * we may need some idea for the dotclock anyway.
9970 * Calculate one based on the FDI configuration.
9972 pipe_config
->base
.adjusted_mode
.crtc_clock
=
9973 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
9974 &pipe_config
->fdi_m_n
);
9977 /** Returns the currently programmed mode of the given pipe. */
9978 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
9979 struct drm_crtc
*crtc
)
9981 struct drm_i915_private
*dev_priv
= to_i915(dev
);
9982 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9983 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
9984 struct drm_display_mode
*mode
;
9985 struct intel_crtc_state
*pipe_config
;
9986 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
9987 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
9988 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
9989 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
9990 enum pipe pipe
= intel_crtc
->pipe
;
9992 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
9996 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
10003 * Construct a pipe_config sufficient for getting the clock info
10004 * back out of crtc_clock_get.
10006 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
10007 * to use a real value here instead.
10009 pipe_config
->cpu_transcoder
= (enum transcoder
) pipe
;
10010 pipe_config
->pixel_multiplier
= 1;
10011 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
10012 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
10013 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
10014 i9xx_crtc_clock_get(intel_crtc
, pipe_config
);
10016 mode
->clock
= pipe_config
->port_clock
/ pipe_config
->pixel_multiplier
;
10017 mode
->hdisplay
= (htot
& 0xffff) + 1;
10018 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
10019 mode
->hsync_start
= (hsync
& 0xffff) + 1;
10020 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
10021 mode
->vdisplay
= (vtot
& 0xffff) + 1;
10022 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
10023 mode
->vsync_start
= (vsync
& 0xffff) + 1;
10024 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
10026 drm_mode_set_name(mode
);
10028 kfree(pipe_config
);
10033 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
10035 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10037 drm_crtc_cleanup(crtc
);
10042 * intel_wm_need_update - Check whether watermarks need updating
10043 * @plane: drm plane
10044 * @state: new plane state
10046 * Check current plane state versus the new one to determine whether
10047 * watermarks need to be recalculated.
10049 * Returns true or false.
10051 static bool intel_wm_need_update(struct drm_plane
*plane
,
10052 struct drm_plane_state
*state
)
10054 struct intel_plane_state
*new = to_intel_plane_state(state
);
10055 struct intel_plane_state
*cur
= to_intel_plane_state(plane
->state
);
10057 /* Update watermarks on tiling or size changes. */
10058 if (new->base
.visible
!= cur
->base
.visible
)
10061 if (!cur
->base
.fb
|| !new->base
.fb
)
10064 if (cur
->base
.fb
->modifier
!= new->base
.fb
->modifier
||
10065 cur
->base
.rotation
!= new->base
.rotation
||
10066 drm_rect_width(&new->base
.src
) != drm_rect_width(&cur
->base
.src
) ||
10067 drm_rect_height(&new->base
.src
) != drm_rect_height(&cur
->base
.src
) ||
10068 drm_rect_width(&new->base
.dst
) != drm_rect_width(&cur
->base
.dst
) ||
10069 drm_rect_height(&new->base
.dst
) != drm_rect_height(&cur
->base
.dst
))
10075 static bool needs_scaling(struct intel_plane_state
*state
)
10077 int src_w
= drm_rect_width(&state
->base
.src
) >> 16;
10078 int src_h
= drm_rect_height(&state
->base
.src
) >> 16;
10079 int dst_w
= drm_rect_width(&state
->base
.dst
);
10080 int dst_h
= drm_rect_height(&state
->base
.dst
);
10082 return (src_w
!= dst_w
|| src_h
!= dst_h
);
10085 int intel_plane_atomic_calc_changes(struct drm_crtc_state
*crtc_state
,
10086 struct drm_plane_state
*plane_state
)
10088 struct intel_crtc_state
*pipe_config
= to_intel_crtc_state(crtc_state
);
10089 struct drm_crtc
*crtc
= crtc_state
->crtc
;
10090 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10091 struct intel_plane
*plane
= to_intel_plane(plane_state
->plane
);
10092 struct drm_device
*dev
= crtc
->dev
;
10093 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10094 struct intel_plane_state
*old_plane_state
=
10095 to_intel_plane_state(plane
->base
.state
);
10096 bool mode_changed
= needs_modeset(crtc_state
);
10097 bool was_crtc_enabled
= crtc
->state
->active
;
10098 bool is_crtc_enabled
= crtc_state
->active
;
10099 bool turn_off
, turn_on
, visible
, was_visible
;
10100 struct drm_framebuffer
*fb
= plane_state
->fb
;
10103 if (INTEL_GEN(dev_priv
) >= 9 && plane
->id
!= PLANE_CURSOR
) {
10104 ret
= skl_update_scaler_plane(
10105 to_intel_crtc_state(crtc_state
),
10106 to_intel_plane_state(plane_state
));
10111 was_visible
= old_plane_state
->base
.visible
;
10112 visible
= plane_state
->visible
;
10114 if (!was_crtc_enabled
&& WARN_ON(was_visible
))
10115 was_visible
= false;
10118 * Visibility is calculated as if the crtc was on, but
10119 * after scaler setup everything depends on it being off
10120 * when the crtc isn't active.
10122 * FIXME this is wrong for watermarks. Watermarks should also
10123 * be computed as if the pipe would be active. Perhaps move
10124 * per-plane wm computation to the .check_plane() hook, and
10125 * only combine the results from all planes in the current place?
10127 if (!is_crtc_enabled
) {
10128 plane_state
->visible
= visible
= false;
10129 to_intel_crtc_state(crtc_state
)->active_planes
&= ~BIT(plane
->id
);
10132 if (!was_visible
&& !visible
)
10135 if (fb
!= old_plane_state
->base
.fb
)
10136 pipe_config
->fb_changed
= true;
10138 turn_off
= was_visible
&& (!visible
|| mode_changed
);
10139 turn_on
= visible
&& (!was_visible
|| mode_changed
);
10141 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
10142 intel_crtc
->base
.base
.id
, intel_crtc
->base
.name
,
10143 plane
->base
.base
.id
, plane
->base
.name
,
10144 fb
? fb
->base
.id
: -1);
10146 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
10147 plane
->base
.base
.id
, plane
->base
.name
,
10148 was_visible
, visible
,
10149 turn_off
, turn_on
, mode_changed
);
10152 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
))
10153 pipe_config
->update_wm_pre
= true;
10155 /* must disable cxsr around plane enable/disable */
10156 if (plane
->id
!= PLANE_CURSOR
)
10157 pipe_config
->disable_cxsr
= true;
10158 } else if (turn_off
) {
10159 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
))
10160 pipe_config
->update_wm_post
= true;
10162 /* must disable cxsr around plane enable/disable */
10163 if (plane
->id
!= PLANE_CURSOR
)
10164 pipe_config
->disable_cxsr
= true;
10165 } else if (intel_wm_need_update(&plane
->base
, plane_state
)) {
10166 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
)) {
10167 /* FIXME bollocks */
10168 pipe_config
->update_wm_pre
= true;
10169 pipe_config
->update_wm_post
= true;
10173 if (visible
|| was_visible
)
10174 pipe_config
->fb_bits
|= plane
->frontbuffer_bit
;
10177 * WaCxSRDisabledForSpriteScaling:ivb
10179 * cstate->update_wm was already set above, so this flag will
10180 * take effect when we commit and program watermarks.
10182 if (plane
->id
== PLANE_SPRITE0
&& IS_IVYBRIDGE(dev_priv
) &&
10183 needs_scaling(to_intel_plane_state(plane_state
)) &&
10184 !needs_scaling(old_plane_state
))
10185 pipe_config
->disable_lp_wm
= true;
10190 static bool encoders_cloneable(const struct intel_encoder
*a
,
10191 const struct intel_encoder
*b
)
10193 /* masks could be asymmetric, so check both ways */
10194 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
10195 b
->cloneable
& (1 << a
->type
));
10198 static bool check_single_encoder_cloning(struct drm_atomic_state
*state
,
10199 struct intel_crtc
*crtc
,
10200 struct intel_encoder
*encoder
)
10202 struct intel_encoder
*source_encoder
;
10203 struct drm_connector
*connector
;
10204 struct drm_connector_state
*connector_state
;
10207 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10208 if (connector_state
->crtc
!= &crtc
->base
)
10212 to_intel_encoder(connector_state
->best_encoder
);
10213 if (!encoders_cloneable(encoder
, source_encoder
))
10220 static int intel_crtc_atomic_check(struct drm_crtc
*crtc
,
10221 struct drm_crtc_state
*crtc_state
)
10223 struct drm_device
*dev
= crtc
->dev
;
10224 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10225 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10226 struct intel_crtc_state
*pipe_config
=
10227 to_intel_crtc_state(crtc_state
);
10228 struct drm_atomic_state
*state
= crtc_state
->state
;
10230 bool mode_changed
= needs_modeset(crtc_state
);
10232 if (mode_changed
&& !crtc_state
->active
)
10233 pipe_config
->update_wm_post
= true;
10235 if (mode_changed
&& crtc_state
->enable
&&
10236 dev_priv
->display
.crtc_compute_clock
&&
10237 !WARN_ON(pipe_config
->shared_dpll
)) {
10238 ret
= dev_priv
->display
.crtc_compute_clock(intel_crtc
,
10244 if (crtc_state
->color_mgmt_changed
) {
10245 ret
= intel_color_check(crtc
, crtc_state
);
10250 * Changing color management on Intel hardware is
10251 * handled as part of planes update.
10253 crtc_state
->planes_changed
= true;
10257 if (dev_priv
->display
.compute_pipe_wm
) {
10258 ret
= dev_priv
->display
.compute_pipe_wm(pipe_config
);
10260 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
10265 if (dev_priv
->display
.compute_intermediate_wm
&&
10266 !to_intel_atomic_state(state
)->skip_intermediate_wm
) {
10267 if (WARN_ON(!dev_priv
->display
.compute_pipe_wm
))
10271 * Calculate 'intermediate' watermarks that satisfy both the
10272 * old state and the new state. We can program these
10275 ret
= dev_priv
->display
.compute_intermediate_wm(dev
,
10279 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
10282 } else if (dev_priv
->display
.compute_intermediate_wm
) {
10283 if (HAS_PCH_SPLIT(dev_priv
) && INTEL_GEN(dev_priv
) < 9)
10284 pipe_config
->wm
.ilk
.intermediate
= pipe_config
->wm
.ilk
.optimal
;
10287 if (INTEL_GEN(dev_priv
) >= 9) {
10289 ret
= skl_update_scaler_crtc(pipe_config
);
10292 ret
= skl_check_pipe_max_pixel_rate(intel_crtc
,
10295 ret
= intel_atomic_setup_scalers(dev_priv
, intel_crtc
,
10302 static const struct drm_crtc_helper_funcs intel_helper_funcs
= {
10303 .atomic_begin
= intel_begin_crtc_commit
,
10304 .atomic_flush
= intel_finish_crtc_commit
,
10305 .atomic_check
= intel_crtc_atomic_check
,
10308 static void intel_modeset_update_connector_atomic_state(struct drm_device
*dev
)
10310 struct intel_connector
*connector
;
10311 struct drm_connector_list_iter conn_iter
;
10313 drm_connector_list_iter_begin(dev
, &conn_iter
);
10314 for_each_intel_connector_iter(connector
, &conn_iter
) {
10315 if (connector
->base
.state
->crtc
)
10316 drm_connector_unreference(&connector
->base
);
10318 if (connector
->base
.encoder
) {
10319 connector
->base
.state
->best_encoder
=
10320 connector
->base
.encoder
;
10321 connector
->base
.state
->crtc
=
10322 connector
->base
.encoder
->crtc
;
10324 drm_connector_reference(&connector
->base
);
10326 connector
->base
.state
->best_encoder
= NULL
;
10327 connector
->base
.state
->crtc
= NULL
;
10330 drm_connector_list_iter_end(&conn_iter
);
10334 connected_sink_compute_bpp(struct intel_connector
*connector
,
10335 struct intel_crtc_state
*pipe_config
)
10337 const struct drm_display_info
*info
= &connector
->base
.display_info
;
10338 int bpp
= pipe_config
->pipe_bpp
;
10340 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
10341 connector
->base
.base
.id
,
10342 connector
->base
.name
);
10344 /* Don't use an invalid EDID bpc value */
10345 if (info
->bpc
!= 0 && info
->bpc
* 3 < bpp
) {
10346 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
10347 bpp
, info
->bpc
* 3);
10348 pipe_config
->pipe_bpp
= info
->bpc
* 3;
10351 /* Clamp bpp to 8 on screens without EDID 1.4 */
10352 if (info
->bpc
== 0 && bpp
> 24) {
10353 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
10355 pipe_config
->pipe_bpp
= 24;
10360 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
10361 struct intel_crtc_state
*pipe_config
)
10363 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
10364 struct drm_atomic_state
*state
;
10365 struct drm_connector
*connector
;
10366 struct drm_connector_state
*connector_state
;
10369 if ((IS_G4X(dev_priv
) || IS_VALLEYVIEW(dev_priv
) ||
10370 IS_CHERRYVIEW(dev_priv
)))
10372 else if (INTEL_GEN(dev_priv
) >= 5)
10378 pipe_config
->pipe_bpp
= bpp
;
10380 state
= pipe_config
->base
.state
;
10382 /* Clamp display bpp to EDID value */
10383 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10384 if (connector_state
->crtc
!= &crtc
->base
)
10387 connected_sink_compute_bpp(to_intel_connector(connector
),
10394 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
10396 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
10397 "type: 0x%x flags: 0x%x\n",
10399 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
10400 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
10401 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
10402 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
10406 intel_dump_m_n_config(struct intel_crtc_state
*pipe_config
, char *id
,
10407 unsigned int lane_count
, struct intel_link_m_n
*m_n
)
10409 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10411 m_n
->gmch_m
, m_n
->gmch_n
,
10412 m_n
->link_m
, m_n
->link_n
, m_n
->tu
);
10415 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
10416 struct intel_crtc_state
*pipe_config
,
10417 const char *context
)
10419 struct drm_device
*dev
= crtc
->base
.dev
;
10420 struct drm_i915_private
*dev_priv
= to_i915(dev
);
10421 struct drm_plane
*plane
;
10422 struct intel_plane
*intel_plane
;
10423 struct intel_plane_state
*state
;
10424 struct drm_framebuffer
*fb
;
10426 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
10427 crtc
->base
.base
.id
, crtc
->base
.name
, context
);
10429 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
10430 transcoder_name(pipe_config
->cpu_transcoder
),
10431 pipe_config
->pipe_bpp
, pipe_config
->dither
);
10433 if (pipe_config
->has_pch_encoder
)
10434 intel_dump_m_n_config(pipe_config
, "fdi",
10435 pipe_config
->fdi_lanes
,
10436 &pipe_config
->fdi_m_n
);
10438 if (pipe_config
->ycbcr420
)
10439 DRM_DEBUG_KMS("YCbCr 4:2:0 output enabled\n");
10441 if (intel_crtc_has_dp_encoder(pipe_config
)) {
10442 intel_dump_m_n_config(pipe_config
, "dp m_n",
10443 pipe_config
->lane_count
, &pipe_config
->dp_m_n
);
10444 if (pipe_config
->has_drrs
)
10445 intel_dump_m_n_config(pipe_config
, "dp m2_n2",
10446 pipe_config
->lane_count
,
10447 &pipe_config
->dp_m2_n2
);
10450 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
10451 pipe_config
->has_audio
, pipe_config
->has_infoframe
);
10453 DRM_DEBUG_KMS("requested mode:\n");
10454 drm_mode_debug_printmodeline(&pipe_config
->base
.mode
);
10455 DRM_DEBUG_KMS("adjusted mode:\n");
10456 drm_mode_debug_printmodeline(&pipe_config
->base
.adjusted_mode
);
10457 intel_dump_crtc_timings(&pipe_config
->base
.adjusted_mode
);
10458 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
10459 pipe_config
->port_clock
,
10460 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
,
10461 pipe_config
->pixel_rate
);
10463 if (INTEL_GEN(dev_priv
) >= 9)
10464 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
10466 pipe_config
->scaler_state
.scaler_users
,
10467 pipe_config
->scaler_state
.scaler_id
);
10469 if (HAS_GMCH_DISPLAY(dev_priv
))
10470 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
10471 pipe_config
->gmch_pfit
.control
,
10472 pipe_config
->gmch_pfit
.pgm_ratios
,
10473 pipe_config
->gmch_pfit
.lvds_border_bits
);
10475 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
10476 pipe_config
->pch_pfit
.pos
,
10477 pipe_config
->pch_pfit
.size
,
10478 enableddisabled(pipe_config
->pch_pfit
.enabled
));
10480 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
10481 pipe_config
->ips_enabled
, pipe_config
->double_wide
);
10483 intel_dpll_dump_hw_state(dev_priv
, &pipe_config
->dpll_hw_state
);
10485 DRM_DEBUG_KMS("planes on this crtc\n");
10486 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
10487 struct drm_format_name_buf format_name
;
10488 intel_plane
= to_intel_plane(plane
);
10489 if (intel_plane
->pipe
!= crtc
->pipe
)
10492 state
= to_intel_plane_state(plane
->state
);
10493 fb
= state
->base
.fb
;
10495 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
10496 plane
->base
.id
, plane
->name
, state
->scaler_id
);
10500 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
10501 plane
->base
.id
, plane
->name
,
10502 fb
->base
.id
, fb
->width
, fb
->height
,
10503 drm_get_format_name(fb
->format
->format
, &format_name
));
10504 if (INTEL_GEN(dev_priv
) >= 9)
10505 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
10507 state
->base
.src
.x1
>> 16,
10508 state
->base
.src
.y1
>> 16,
10509 drm_rect_width(&state
->base
.src
) >> 16,
10510 drm_rect_height(&state
->base
.src
) >> 16,
10511 state
->base
.dst
.x1
, state
->base
.dst
.y1
,
10512 drm_rect_width(&state
->base
.dst
),
10513 drm_rect_height(&state
->base
.dst
));
10517 static bool check_digital_port_conflicts(struct drm_atomic_state
*state
)
10519 struct drm_device
*dev
= state
->dev
;
10520 struct drm_connector
*connector
;
10521 struct drm_connector_list_iter conn_iter
;
10522 unsigned int used_ports
= 0;
10523 unsigned int used_mst_ports
= 0;
10526 * Walk the connector list instead of the encoder
10527 * list to detect the problem on ddi platforms
10528 * where there's just one encoder per digital port.
10530 drm_connector_list_iter_begin(dev
, &conn_iter
);
10531 drm_for_each_connector_iter(connector
, &conn_iter
) {
10532 struct drm_connector_state
*connector_state
;
10533 struct intel_encoder
*encoder
;
10535 connector_state
= drm_atomic_get_existing_connector_state(state
, connector
);
10536 if (!connector_state
)
10537 connector_state
= connector
->state
;
10539 if (!connector_state
->best_encoder
)
10542 encoder
= to_intel_encoder(connector_state
->best_encoder
);
10544 WARN_ON(!connector_state
->crtc
);
10546 switch (encoder
->type
) {
10547 unsigned int port_mask
;
10548 case INTEL_OUTPUT_UNKNOWN
:
10549 if (WARN_ON(!HAS_DDI(to_i915(dev
))))
10551 case INTEL_OUTPUT_DP
:
10552 case INTEL_OUTPUT_HDMI
:
10553 case INTEL_OUTPUT_EDP
:
10554 port_mask
= 1 << enc_to_dig_port(&encoder
->base
)->port
;
10556 /* the same port mustn't appear more than once */
10557 if (used_ports
& port_mask
)
10560 used_ports
|= port_mask
;
10562 case INTEL_OUTPUT_DP_MST
:
10564 1 << enc_to_mst(&encoder
->base
)->primary
->port
;
10570 drm_connector_list_iter_end(&conn_iter
);
10572 /* can't mix MST and SST/HDMI on the same port */
10573 if (used_ports
& used_mst_ports
)
10580 clear_intel_crtc_state(struct intel_crtc_state
*crtc_state
)
10582 struct drm_i915_private
*dev_priv
=
10583 to_i915(crtc_state
->base
.crtc
->dev
);
10584 struct intel_crtc_scaler_state scaler_state
;
10585 struct intel_dpll_hw_state dpll_hw_state
;
10586 struct intel_shared_dpll
*shared_dpll
;
10587 struct intel_crtc_wm_state wm_state
;
10590 /* FIXME: before the switch to atomic started, a new pipe_config was
10591 * kzalloc'd. Code that depends on any field being zero should be
10592 * fixed, so that the crtc_state can be safely duplicated. For now,
10593 * only fields that are know to not cause problems are preserved. */
10595 scaler_state
= crtc_state
->scaler_state
;
10596 shared_dpll
= crtc_state
->shared_dpll
;
10597 dpll_hw_state
= crtc_state
->dpll_hw_state
;
10598 force_thru
= crtc_state
->pch_pfit
.force_thru
;
10599 if (IS_G4X(dev_priv
) ||
10600 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
10601 wm_state
= crtc_state
->wm
;
10603 /* Keep base drm_crtc_state intact, only clear our extended struct */
10604 BUILD_BUG_ON(offsetof(struct intel_crtc_state
, base
));
10605 memset(&crtc_state
->base
+ 1, 0,
10606 sizeof(*crtc_state
) - sizeof(crtc_state
->base
));
10608 crtc_state
->scaler_state
= scaler_state
;
10609 crtc_state
->shared_dpll
= shared_dpll
;
10610 crtc_state
->dpll_hw_state
= dpll_hw_state
;
10611 crtc_state
->pch_pfit
.force_thru
= force_thru
;
10612 if (IS_G4X(dev_priv
) ||
10613 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
10614 crtc_state
->wm
= wm_state
;
10618 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
10619 struct intel_crtc_state
*pipe_config
)
10621 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
10622 struct intel_encoder
*encoder
;
10623 struct drm_connector
*connector
;
10624 struct drm_connector_state
*connector_state
;
10625 int base_bpp
, ret
= -EINVAL
;
10629 clear_intel_crtc_state(pipe_config
);
10631 pipe_config
->cpu_transcoder
=
10632 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
10635 * Sanitize sync polarity flags based on requested ones. If neither
10636 * positive or negative polarity is requested, treat this as meaning
10637 * negative polarity.
10639 if (!(pipe_config
->base
.adjusted_mode
.flags
&
10640 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
10641 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
10643 if (!(pipe_config
->base
.adjusted_mode
.flags
&
10644 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
10645 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
10647 base_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
10653 * Determine the real pipe dimensions. Note that stereo modes can
10654 * increase the actual pipe size due to the frame doubling and
10655 * insertion of additional space for blanks between the frame. This
10656 * is stored in the crtc timings. We use the requested mode to do this
10657 * computation to clearly distinguish it from the adjusted mode, which
10658 * can be changed by the connectors in the below retry loop.
10660 drm_mode_get_hv_timing(&pipe_config
->base
.mode
,
10661 &pipe_config
->pipe_src_w
,
10662 &pipe_config
->pipe_src_h
);
10664 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10665 if (connector_state
->crtc
!= crtc
)
10668 encoder
= to_intel_encoder(connector_state
->best_encoder
);
10670 if (!check_single_encoder_cloning(state
, to_intel_crtc(crtc
), encoder
)) {
10671 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
10676 * Determine output_types before calling the .compute_config()
10677 * hooks so that the hooks can use this information safely.
10679 pipe_config
->output_types
|= 1 << encoder
->type
;
10683 /* Ensure the port clock defaults are reset when retrying. */
10684 pipe_config
->port_clock
= 0;
10685 pipe_config
->pixel_multiplier
= 1;
10687 /* Fill in default crtc timings, allow encoders to overwrite them. */
10688 drm_mode_set_crtcinfo(&pipe_config
->base
.adjusted_mode
,
10689 CRTC_STEREO_DOUBLE
);
10691 /* Pass our mode to the connectors and the CRTC to give them a chance to
10692 * adjust it according to limitations or connector properties, and also
10693 * a chance to reject the mode entirely.
10695 for_each_new_connector_in_state(state
, connector
, connector_state
, i
) {
10696 if (connector_state
->crtc
!= crtc
)
10699 encoder
= to_intel_encoder(connector_state
->best_encoder
);
10701 if (!(encoder
->compute_config(encoder
, pipe_config
, connector_state
))) {
10702 DRM_DEBUG_KMS("Encoder config failure\n");
10707 /* Set default port clock if not overwritten by the encoder. Needs to be
10708 * done afterwards in case the encoder adjusts the mode. */
10709 if (!pipe_config
->port_clock
)
10710 pipe_config
->port_clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
10711 * pipe_config
->pixel_multiplier
;
10713 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
10715 DRM_DEBUG_KMS("CRTC fixup failed\n");
10719 if (ret
== RETRY
) {
10720 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
10725 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
10727 goto encoder_retry
;
10730 /* Dithering seems to not pass-through bits correctly when it should, so
10731 * only enable it on 6bpc panels and when its not a compliance
10732 * test requesting 6bpc video pattern.
10734 pipe_config
->dither
= (pipe_config
->pipe_bpp
== 6*3) &&
10735 !pipe_config
->dither_force_disable
;
10736 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
10737 base_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
10744 intel_modeset_update_crtc_state(struct drm_atomic_state
*state
)
10746 struct drm_crtc
*crtc
;
10747 struct drm_crtc_state
*new_crtc_state
;
10750 /* Double check state. */
10751 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
10752 to_intel_crtc(crtc
)->config
= to_intel_crtc_state(new_crtc_state
);
10755 * Update legacy state to satisfy fbc code. This can
10756 * be removed when fbc uses the atomic state.
10758 if (drm_atomic_get_existing_plane_state(state
, crtc
->primary
)) {
10759 struct drm_plane_state
*plane_state
= crtc
->primary
->state
;
10761 crtc
->primary
->fb
= plane_state
->fb
;
10762 crtc
->x
= plane_state
->src_x
>> 16;
10763 crtc
->y
= plane_state
->src_y
>> 16;
10768 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
10772 if (clock1
== clock2
)
10775 if (!clock1
|| !clock2
)
10778 diff
= abs(clock1
- clock2
);
10780 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
10787 intel_compare_m_n(unsigned int m
, unsigned int n
,
10788 unsigned int m2
, unsigned int n2
,
10791 if (m
== m2
&& n
== n2
)
10794 if (exact
|| !m
|| !n
|| !m2
|| !n2
)
10797 BUILD_BUG_ON(DATA_LINK_M_N_MASK
> INT_MAX
);
10804 } else if (n
< n2
) {
10814 return intel_fuzzy_clock_check(m
, m2
);
10818 intel_compare_link_m_n(const struct intel_link_m_n
*m_n
,
10819 struct intel_link_m_n
*m2_n2
,
10822 if (m_n
->tu
== m2_n2
->tu
&&
10823 intel_compare_m_n(m_n
->gmch_m
, m_n
->gmch_n
,
10824 m2_n2
->gmch_m
, m2_n2
->gmch_n
, !adjust
) &&
10825 intel_compare_m_n(m_n
->link_m
, m_n
->link_n
,
10826 m2_n2
->link_m
, m2_n2
->link_n
, !adjust
)) {
10836 static void __printf(3, 4)
10837 pipe_config_err(bool adjust
, const char *name
, const char *format
, ...)
10840 unsigned int category
;
10841 struct va_format vaf
;
10845 level
= KERN_DEBUG
;
10846 category
= DRM_UT_KMS
;
10849 category
= DRM_UT_NONE
;
10852 va_start(args
, format
);
10856 drm_printk(level
, category
, "mismatch in %s %pV", name
, &vaf
);
10862 intel_pipe_config_compare(struct drm_i915_private
*dev_priv
,
10863 struct intel_crtc_state
*current_config
,
10864 struct intel_crtc_state
*pipe_config
,
10869 #define PIPE_CONF_CHECK_X(name) \
10870 if (current_config->name != pipe_config->name) { \
10871 pipe_config_err(adjust, __stringify(name), \
10872 "(expected 0x%08x, found 0x%08x)\n", \
10873 current_config->name, \
10874 pipe_config->name); \
10878 #define PIPE_CONF_CHECK_I(name) \
10879 if (current_config->name != pipe_config->name) { \
10880 pipe_config_err(adjust, __stringify(name), \
10881 "(expected %i, found %i)\n", \
10882 current_config->name, \
10883 pipe_config->name); \
10887 #define PIPE_CONF_CHECK_P(name) \
10888 if (current_config->name != pipe_config->name) { \
10889 pipe_config_err(adjust, __stringify(name), \
10890 "(expected %p, found %p)\n", \
10891 current_config->name, \
10892 pipe_config->name); \
10896 #define PIPE_CONF_CHECK_M_N(name) \
10897 if (!intel_compare_link_m_n(¤t_config->name, \
10898 &pipe_config->name,\
10900 pipe_config_err(adjust, __stringify(name), \
10901 "(expected tu %i gmch %i/%i link %i/%i, " \
10902 "found tu %i, gmch %i/%i link %i/%i)\n", \
10903 current_config->name.tu, \
10904 current_config->name.gmch_m, \
10905 current_config->name.gmch_n, \
10906 current_config->name.link_m, \
10907 current_config->name.link_n, \
10908 pipe_config->name.tu, \
10909 pipe_config->name.gmch_m, \
10910 pipe_config->name.gmch_n, \
10911 pipe_config->name.link_m, \
10912 pipe_config->name.link_n); \
10916 /* This is required for BDW+ where there is only one set of registers for
10917 * switching between high and low RR.
10918 * This macro can be used whenever a comparison has to be made between one
10919 * hw state and multiple sw state variables.
10921 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \
10922 if (!intel_compare_link_m_n(¤t_config->name, \
10923 &pipe_config->name, adjust) && \
10924 !intel_compare_link_m_n(¤t_config->alt_name, \
10925 &pipe_config->name, adjust)) { \
10926 pipe_config_err(adjust, __stringify(name), \
10927 "(expected tu %i gmch %i/%i link %i/%i, " \
10928 "or tu %i gmch %i/%i link %i/%i, " \
10929 "found tu %i, gmch %i/%i link %i/%i)\n", \
10930 current_config->name.tu, \
10931 current_config->name.gmch_m, \
10932 current_config->name.gmch_n, \
10933 current_config->name.link_m, \
10934 current_config->name.link_n, \
10935 current_config->alt_name.tu, \
10936 current_config->alt_name.gmch_m, \
10937 current_config->alt_name.gmch_n, \
10938 current_config->alt_name.link_m, \
10939 current_config->alt_name.link_n, \
10940 pipe_config->name.tu, \
10941 pipe_config->name.gmch_m, \
10942 pipe_config->name.gmch_n, \
10943 pipe_config->name.link_m, \
10944 pipe_config->name.link_n); \
10948 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
10949 if ((current_config->name ^ pipe_config->name) & (mask)) { \
10950 pipe_config_err(adjust, __stringify(name), \
10951 "(%x) (expected %i, found %i)\n", \
10953 current_config->name & (mask), \
10954 pipe_config->name & (mask)); \
10958 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
10959 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
10960 pipe_config_err(adjust, __stringify(name), \
10961 "(expected %i, found %i)\n", \
10962 current_config->name, \
10963 pipe_config->name); \
10967 #define PIPE_CONF_QUIRK(quirk) \
10968 ((current_config->quirks | pipe_config->quirks) & (quirk))
10970 PIPE_CONF_CHECK_I(cpu_transcoder
);
10972 PIPE_CONF_CHECK_I(has_pch_encoder
);
10973 PIPE_CONF_CHECK_I(fdi_lanes
);
10974 PIPE_CONF_CHECK_M_N(fdi_m_n
);
10976 PIPE_CONF_CHECK_I(lane_count
);
10977 PIPE_CONF_CHECK_X(lane_lat_optim_mask
);
10979 if (INTEL_GEN(dev_priv
) < 8) {
10980 PIPE_CONF_CHECK_M_N(dp_m_n
);
10982 if (current_config
->has_drrs
)
10983 PIPE_CONF_CHECK_M_N(dp_m2_n2
);
10985 PIPE_CONF_CHECK_M_N_ALT(dp_m_n
, dp_m2_n2
);
10987 PIPE_CONF_CHECK_X(output_types
);
10989 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hdisplay
);
10990 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_htotal
);
10991 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_start
);
10992 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_end
);
10993 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_start
);
10994 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_end
);
10996 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vdisplay
);
10997 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vtotal
);
10998 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_start
);
10999 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_end
);
11000 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_start
);
11001 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_end
);
11003 PIPE_CONF_CHECK_I(pixel_multiplier
);
11004 PIPE_CONF_CHECK_I(has_hdmi_sink
);
11005 if ((INTEL_GEN(dev_priv
) < 8 && !IS_HASWELL(dev_priv
)) ||
11006 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
11007 PIPE_CONF_CHECK_I(limited_color_range
);
11009 PIPE_CONF_CHECK_I(hdmi_scrambling
);
11010 PIPE_CONF_CHECK_I(hdmi_high_tmds_clock_ratio
);
11011 PIPE_CONF_CHECK_I(has_infoframe
);
11012 PIPE_CONF_CHECK_I(ycbcr420
);
11014 PIPE_CONF_CHECK_I(has_audio
);
11016 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11017 DRM_MODE_FLAG_INTERLACE
);
11019 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
11020 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11021 DRM_MODE_FLAG_PHSYNC
);
11022 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11023 DRM_MODE_FLAG_NHSYNC
);
11024 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11025 DRM_MODE_FLAG_PVSYNC
);
11026 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11027 DRM_MODE_FLAG_NVSYNC
);
11030 PIPE_CONF_CHECK_X(gmch_pfit
.control
);
11031 /* pfit ratios are autocomputed by the hw on gen4+ */
11032 if (INTEL_GEN(dev_priv
) < 4)
11033 PIPE_CONF_CHECK_X(gmch_pfit
.pgm_ratios
);
11034 PIPE_CONF_CHECK_X(gmch_pfit
.lvds_border_bits
);
11037 PIPE_CONF_CHECK_I(pipe_src_w
);
11038 PIPE_CONF_CHECK_I(pipe_src_h
);
11040 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
11041 if (current_config
->pch_pfit
.enabled
) {
11042 PIPE_CONF_CHECK_X(pch_pfit
.pos
);
11043 PIPE_CONF_CHECK_X(pch_pfit
.size
);
11046 PIPE_CONF_CHECK_I(scaler_state
.scaler_id
);
11047 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate
);
11050 /* BDW+ don't expose a synchronous way to read the state */
11051 if (IS_HASWELL(dev_priv
))
11052 PIPE_CONF_CHECK_I(ips_enabled
);
11054 PIPE_CONF_CHECK_I(double_wide
);
11056 PIPE_CONF_CHECK_P(shared_dpll
);
11057 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
11058 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
11059 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
11060 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
11061 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
11062 PIPE_CONF_CHECK_X(dpll_hw_state
.spll
);
11063 PIPE_CONF_CHECK_X(dpll_hw_state
.ctrl1
);
11064 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr1
);
11065 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr2
);
11067 PIPE_CONF_CHECK_X(dsi_pll
.ctrl
);
11068 PIPE_CONF_CHECK_X(dsi_pll
.div
);
11070 if (IS_G4X(dev_priv
) || INTEL_GEN(dev_priv
) >= 5)
11071 PIPE_CONF_CHECK_I(pipe_bpp
);
11073 PIPE_CONF_CHECK_CLOCK_FUZZY(base
.adjusted_mode
.crtc_clock
);
11074 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
11076 #undef PIPE_CONF_CHECK_X
11077 #undef PIPE_CONF_CHECK_I
11078 #undef PIPE_CONF_CHECK_P
11079 #undef PIPE_CONF_CHECK_FLAGS
11080 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
11081 #undef PIPE_CONF_QUIRK
11086 static void intel_pipe_config_sanity_check(struct drm_i915_private
*dev_priv
,
11087 const struct intel_crtc_state
*pipe_config
)
11089 if (pipe_config
->has_pch_encoder
) {
11090 int fdi_dotclock
= intel_dotclock_calculate(intel_fdi_link_freq(dev_priv
, pipe_config
),
11091 &pipe_config
->fdi_m_n
);
11092 int dotclock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
11095 * FDI already provided one idea for the dotclock.
11096 * Yell if the encoder disagrees.
11098 WARN(!intel_fuzzy_clock_check(fdi_dotclock
, dotclock
),
11099 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11100 fdi_dotclock
, dotclock
);
11104 static void verify_wm_state(struct drm_crtc
*crtc
,
11105 struct drm_crtc_state
*new_state
)
11107 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
11108 struct skl_ddb_allocation hw_ddb
, *sw_ddb
;
11109 struct skl_pipe_wm hw_wm
, *sw_wm
;
11110 struct skl_plane_wm
*hw_plane_wm
, *sw_plane_wm
;
11111 struct skl_ddb_entry
*hw_ddb_entry
, *sw_ddb_entry
;
11112 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11113 const enum pipe pipe
= intel_crtc
->pipe
;
11114 int plane
, level
, max_level
= ilk_wm_max_level(dev_priv
);
11116 if (INTEL_GEN(dev_priv
) < 9 || !new_state
->active
)
11119 skl_pipe_wm_get_hw_state(crtc
, &hw_wm
);
11120 sw_wm
= &to_intel_crtc_state(new_state
)->wm
.skl
.optimal
;
11122 skl_ddb_get_hw_state(dev_priv
, &hw_ddb
);
11123 sw_ddb
= &dev_priv
->wm
.skl_hw
.ddb
;
11126 for_each_universal_plane(dev_priv
, pipe
, plane
) {
11127 hw_plane_wm
= &hw_wm
.planes
[plane
];
11128 sw_plane_wm
= &sw_wm
->planes
[plane
];
11131 for (level
= 0; level
<= max_level
; level
++) {
11132 if (skl_wm_level_equals(&hw_plane_wm
->wm
[level
],
11133 &sw_plane_wm
->wm
[level
]))
11136 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",
11137 pipe_name(pipe
), plane
+ 1, level
,
11138 sw_plane_wm
->wm
[level
].plane_en
,
11139 sw_plane_wm
->wm
[level
].plane_res_b
,
11140 sw_plane_wm
->wm
[level
].plane_res_l
,
11141 hw_plane_wm
->wm
[level
].plane_en
,
11142 hw_plane_wm
->wm
[level
].plane_res_b
,
11143 hw_plane_wm
->wm
[level
].plane_res_l
);
11146 if (!skl_wm_level_equals(&hw_plane_wm
->trans_wm
,
11147 &sw_plane_wm
->trans_wm
)) {
11148 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",
11149 pipe_name(pipe
), plane
+ 1,
11150 sw_plane_wm
->trans_wm
.plane_en
,
11151 sw_plane_wm
->trans_wm
.plane_res_b
,
11152 sw_plane_wm
->trans_wm
.plane_res_l
,
11153 hw_plane_wm
->trans_wm
.plane_en
,
11154 hw_plane_wm
->trans_wm
.plane_res_b
,
11155 hw_plane_wm
->trans_wm
.plane_res_l
);
11159 hw_ddb_entry
= &hw_ddb
.plane
[pipe
][plane
];
11160 sw_ddb_entry
= &sw_ddb
->plane
[pipe
][plane
];
11162 if (!skl_ddb_entry_equal(hw_ddb_entry
, sw_ddb_entry
)) {
11163 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
11164 pipe_name(pipe
), plane
+ 1,
11165 sw_ddb_entry
->start
, sw_ddb_entry
->end
,
11166 hw_ddb_entry
->start
, hw_ddb_entry
->end
);
11172 * If the cursor plane isn't active, we may not have updated it's ddb
11173 * allocation. In that case since the ddb allocation will be updated
11174 * once the plane becomes visible, we can skip this check
11177 hw_plane_wm
= &hw_wm
.planes
[PLANE_CURSOR
];
11178 sw_plane_wm
= &sw_wm
->planes
[PLANE_CURSOR
];
11181 for (level
= 0; level
<= max_level
; level
++) {
11182 if (skl_wm_level_equals(&hw_plane_wm
->wm
[level
],
11183 &sw_plane_wm
->wm
[level
]))
11186 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",
11187 pipe_name(pipe
), level
,
11188 sw_plane_wm
->wm
[level
].plane_en
,
11189 sw_plane_wm
->wm
[level
].plane_res_b
,
11190 sw_plane_wm
->wm
[level
].plane_res_l
,
11191 hw_plane_wm
->wm
[level
].plane_en
,
11192 hw_plane_wm
->wm
[level
].plane_res_b
,
11193 hw_plane_wm
->wm
[level
].plane_res_l
);
11196 if (!skl_wm_level_equals(&hw_plane_wm
->trans_wm
,
11197 &sw_plane_wm
->trans_wm
)) {
11198 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11200 sw_plane_wm
->trans_wm
.plane_en
,
11201 sw_plane_wm
->trans_wm
.plane_res_b
,
11202 sw_plane_wm
->trans_wm
.plane_res_l
,
11203 hw_plane_wm
->trans_wm
.plane_en
,
11204 hw_plane_wm
->trans_wm
.plane_res_b
,
11205 hw_plane_wm
->trans_wm
.plane_res_l
);
11209 hw_ddb_entry
= &hw_ddb
.plane
[pipe
][PLANE_CURSOR
];
11210 sw_ddb_entry
= &sw_ddb
->plane
[pipe
][PLANE_CURSOR
];
11212 if (!skl_ddb_entry_equal(hw_ddb_entry
, sw_ddb_entry
)) {
11213 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
11215 sw_ddb_entry
->start
, sw_ddb_entry
->end
,
11216 hw_ddb_entry
->start
, hw_ddb_entry
->end
);
11222 verify_connector_state(struct drm_device
*dev
,
11223 struct drm_atomic_state
*state
,
11224 struct drm_crtc
*crtc
)
11226 struct drm_connector
*connector
;
11227 struct drm_connector_state
*new_conn_state
;
11230 for_each_new_connector_in_state(state
, connector
, new_conn_state
, i
) {
11231 struct drm_encoder
*encoder
= connector
->encoder
;
11232 struct drm_crtc_state
*crtc_state
= NULL
;
11234 if (new_conn_state
->crtc
!= crtc
)
11238 crtc_state
= drm_atomic_get_new_crtc_state(state
, new_conn_state
->crtc
);
11240 intel_connector_verify_state(crtc_state
, new_conn_state
);
11242 I915_STATE_WARN(new_conn_state
->best_encoder
!= encoder
,
11243 "connector's atomic encoder doesn't match legacy encoder\n");
11248 verify_encoder_state(struct drm_device
*dev
, struct drm_atomic_state
*state
)
11250 struct intel_encoder
*encoder
;
11251 struct drm_connector
*connector
;
11252 struct drm_connector_state
*old_conn_state
, *new_conn_state
;
11255 for_each_intel_encoder(dev
, encoder
) {
11256 bool enabled
= false, found
= false;
11259 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
11260 encoder
->base
.base
.id
,
11261 encoder
->base
.name
);
11263 for_each_oldnew_connector_in_state(state
, connector
, old_conn_state
,
11264 new_conn_state
, i
) {
11265 if (old_conn_state
->best_encoder
== &encoder
->base
)
11268 if (new_conn_state
->best_encoder
!= &encoder
->base
)
11270 found
= enabled
= true;
11272 I915_STATE_WARN(new_conn_state
->crtc
!=
11273 encoder
->base
.crtc
,
11274 "connector's crtc doesn't match encoder crtc\n");
11280 I915_STATE_WARN(!!encoder
->base
.crtc
!= enabled
,
11281 "encoder's enabled state mismatch "
11282 "(expected %i, found %i)\n",
11283 !!encoder
->base
.crtc
, enabled
);
11285 if (!encoder
->base
.crtc
) {
11288 active
= encoder
->get_hw_state(encoder
, &pipe
);
11289 I915_STATE_WARN(active
,
11290 "encoder detached but still enabled on pipe %c.\n",
11297 verify_crtc_state(struct drm_crtc
*crtc
,
11298 struct drm_crtc_state
*old_crtc_state
,
11299 struct drm_crtc_state
*new_crtc_state
)
11301 struct drm_device
*dev
= crtc
->dev
;
11302 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11303 struct intel_encoder
*encoder
;
11304 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11305 struct intel_crtc_state
*pipe_config
, *sw_config
;
11306 struct drm_atomic_state
*old_state
;
11309 old_state
= old_crtc_state
->state
;
11310 __drm_atomic_helper_crtc_destroy_state(old_crtc_state
);
11311 pipe_config
= to_intel_crtc_state(old_crtc_state
);
11312 memset(pipe_config
, 0, sizeof(*pipe_config
));
11313 pipe_config
->base
.crtc
= crtc
;
11314 pipe_config
->base
.state
= old_state
;
11316 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc
->base
.id
, crtc
->name
);
11318 active
= dev_priv
->display
.get_pipe_config(intel_crtc
, pipe_config
);
11320 /* we keep both pipes enabled on 830 */
11321 if (IS_I830(dev_priv
))
11322 active
= new_crtc_state
->active
;
11324 I915_STATE_WARN(new_crtc_state
->active
!= active
,
11325 "crtc active state doesn't match with hw state "
11326 "(expected %i, found %i)\n", new_crtc_state
->active
, active
);
11328 I915_STATE_WARN(intel_crtc
->active
!= new_crtc_state
->active
,
11329 "transitional active state does not match atomic hw state "
11330 "(expected %i, found %i)\n", new_crtc_state
->active
, intel_crtc
->active
);
11332 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
11335 active
= encoder
->get_hw_state(encoder
, &pipe
);
11336 I915_STATE_WARN(active
!= new_crtc_state
->active
,
11337 "[ENCODER:%i] active %i with crtc active %i\n",
11338 encoder
->base
.base
.id
, active
, new_crtc_state
->active
);
11340 I915_STATE_WARN(active
&& intel_crtc
->pipe
!= pipe
,
11341 "Encoder connected to wrong pipe %c\n",
11345 pipe_config
->output_types
|= 1 << encoder
->type
;
11346 encoder
->get_config(encoder
, pipe_config
);
11350 intel_crtc_compute_pixel_rate(pipe_config
);
11352 if (!new_crtc_state
->active
)
11355 intel_pipe_config_sanity_check(dev_priv
, pipe_config
);
11357 sw_config
= to_intel_crtc_state(new_crtc_state
);
11358 if (!intel_pipe_config_compare(dev_priv
, sw_config
,
11359 pipe_config
, false)) {
11360 I915_STATE_WARN(1, "pipe state doesn't match!\n");
11361 intel_dump_pipe_config(intel_crtc
, pipe_config
,
11363 intel_dump_pipe_config(intel_crtc
, sw_config
,
11369 verify_single_dpll_state(struct drm_i915_private
*dev_priv
,
11370 struct intel_shared_dpll
*pll
,
11371 struct drm_crtc
*crtc
,
11372 struct drm_crtc_state
*new_state
)
11374 struct intel_dpll_hw_state dpll_hw_state
;
11375 unsigned crtc_mask
;
11378 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
11380 DRM_DEBUG_KMS("%s\n", pll
->name
);
11382 active
= pll
->funcs
.get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
11384 if (!(pll
->flags
& INTEL_DPLL_ALWAYS_ON
)) {
11385 I915_STATE_WARN(!pll
->on
&& pll
->active_mask
,
11386 "pll in active use but not on in sw tracking\n");
11387 I915_STATE_WARN(pll
->on
&& !pll
->active_mask
,
11388 "pll is on but not used by any active crtc\n");
11389 I915_STATE_WARN(pll
->on
!= active
,
11390 "pll on state mismatch (expected %i, found %i)\n",
11395 I915_STATE_WARN(pll
->active_mask
& ~pll
->state
.crtc_mask
,
11396 "more active pll users than references: %x vs %x\n",
11397 pll
->active_mask
, pll
->state
.crtc_mask
);
11402 crtc_mask
= 1 << drm_crtc_index(crtc
);
11404 if (new_state
->active
)
11405 I915_STATE_WARN(!(pll
->active_mask
& crtc_mask
),
11406 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
11407 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
11409 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
11410 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
11411 pipe_name(drm_crtc_index(crtc
)), pll
->active_mask
);
11413 I915_STATE_WARN(!(pll
->state
.crtc_mask
& crtc_mask
),
11414 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
11415 crtc_mask
, pll
->state
.crtc_mask
);
11417 I915_STATE_WARN(pll
->on
&& memcmp(&pll
->state
.hw_state
,
11419 sizeof(dpll_hw_state
)),
11420 "pll hw state mismatch\n");
11424 verify_shared_dpll_state(struct drm_device
*dev
, struct drm_crtc
*crtc
,
11425 struct drm_crtc_state
*old_crtc_state
,
11426 struct drm_crtc_state
*new_crtc_state
)
11428 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11429 struct intel_crtc_state
*old_state
= to_intel_crtc_state(old_crtc_state
);
11430 struct intel_crtc_state
*new_state
= to_intel_crtc_state(new_crtc_state
);
11432 if (new_state
->shared_dpll
)
11433 verify_single_dpll_state(dev_priv
, new_state
->shared_dpll
, crtc
, new_crtc_state
);
11435 if (old_state
->shared_dpll
&&
11436 old_state
->shared_dpll
!= new_state
->shared_dpll
) {
11437 unsigned crtc_mask
= 1 << drm_crtc_index(crtc
);
11438 struct intel_shared_dpll
*pll
= old_state
->shared_dpll
;
11440 I915_STATE_WARN(pll
->active_mask
& crtc_mask
,
11441 "pll active mismatch (didn't expect pipe %c in active mask)\n",
11442 pipe_name(drm_crtc_index(crtc
)));
11443 I915_STATE_WARN(pll
->state
.crtc_mask
& crtc_mask
,
11444 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
11445 pipe_name(drm_crtc_index(crtc
)));
11450 intel_modeset_verify_crtc(struct drm_crtc
*crtc
,
11451 struct drm_atomic_state
*state
,
11452 struct drm_crtc_state
*old_state
,
11453 struct drm_crtc_state
*new_state
)
11455 if (!needs_modeset(new_state
) &&
11456 !to_intel_crtc_state(new_state
)->update_pipe
)
11459 verify_wm_state(crtc
, new_state
);
11460 verify_connector_state(crtc
->dev
, state
, crtc
);
11461 verify_crtc_state(crtc
, old_state
, new_state
);
11462 verify_shared_dpll_state(crtc
->dev
, crtc
, old_state
, new_state
);
11466 verify_disabled_dpll_state(struct drm_device
*dev
)
11468 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11471 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++)
11472 verify_single_dpll_state(dev_priv
, &dev_priv
->shared_dplls
[i
], NULL
, NULL
);
11476 intel_modeset_verify_disabled(struct drm_device
*dev
,
11477 struct drm_atomic_state
*state
)
11479 verify_encoder_state(dev
, state
);
11480 verify_connector_state(dev
, state
, NULL
);
11481 verify_disabled_dpll_state(dev
);
11484 static void update_scanline_offset(struct intel_crtc
*crtc
)
11486 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
11489 * The scanline counter increments at the leading edge of hsync.
11491 * On most platforms it starts counting from vtotal-1 on the
11492 * first active line. That means the scanline counter value is
11493 * always one less than what we would expect. Ie. just after
11494 * start of vblank, which also occurs at start of hsync (on the
11495 * last active line), the scanline counter will read vblank_start-1.
11497 * On gen2 the scanline counter starts counting from 1 instead
11498 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
11499 * to keep the value positive), instead of adding one.
11501 * On HSW+ the behaviour of the scanline counter depends on the output
11502 * type. For DP ports it behaves like most other platforms, but on HDMI
11503 * there's an extra 1 line difference. So we need to add two instead of
11504 * one to the value.
11506 * On VLV/CHV DSI the scanline counter would appear to increment
11507 * approx. 1/3 of a scanline before start of vblank. Unfortunately
11508 * that means we can't tell whether we're in vblank or not while
11509 * we're on that particular line. We must still set scanline_offset
11510 * to 1 so that the vblank timestamps come out correct when we query
11511 * the scanline counter from within the vblank interrupt handler.
11512 * However if queried just before the start of vblank we'll get an
11513 * answer that's slightly in the future.
11515 if (IS_GEN2(dev_priv
)) {
11516 const struct drm_display_mode
*adjusted_mode
= &crtc
->config
->base
.adjusted_mode
;
11519 vtotal
= adjusted_mode
->crtc_vtotal
;
11520 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
11523 crtc
->scanline_offset
= vtotal
- 1;
11524 } else if (HAS_DDI(dev_priv
) &&
11525 intel_crtc_has_type(crtc
->config
, INTEL_OUTPUT_HDMI
)) {
11526 crtc
->scanline_offset
= 2;
11528 crtc
->scanline_offset
= 1;
11531 static void intel_modeset_clear_plls(struct drm_atomic_state
*state
)
11533 struct drm_device
*dev
= state
->dev
;
11534 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11535 struct drm_crtc
*crtc
;
11536 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
11539 if (!dev_priv
->display
.crtc_compute_clock
)
11542 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
11543 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11544 struct intel_shared_dpll
*old_dpll
=
11545 to_intel_crtc_state(old_crtc_state
)->shared_dpll
;
11547 if (!needs_modeset(new_crtc_state
))
11550 to_intel_crtc_state(new_crtc_state
)->shared_dpll
= NULL
;
11555 intel_release_shared_dpll(old_dpll
, intel_crtc
, state
);
11560 * This implements the workaround described in the "notes" section of the mode
11561 * set sequence documentation. When going from no pipes or single pipe to
11562 * multiple pipes, and planes are enabled after the pipe, we need to wait at
11563 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
11565 static int haswell_mode_set_planes_workaround(struct drm_atomic_state
*state
)
11567 struct drm_crtc_state
*crtc_state
;
11568 struct intel_crtc
*intel_crtc
;
11569 struct drm_crtc
*crtc
;
11570 struct intel_crtc_state
*first_crtc_state
= NULL
;
11571 struct intel_crtc_state
*other_crtc_state
= NULL
;
11572 enum pipe first_pipe
= INVALID_PIPE
, enabled_pipe
= INVALID_PIPE
;
11575 /* look at all crtc's that are going to be enabled in during modeset */
11576 for_each_new_crtc_in_state(state
, crtc
, crtc_state
, i
) {
11577 intel_crtc
= to_intel_crtc(crtc
);
11579 if (!crtc_state
->active
|| !needs_modeset(crtc_state
))
11582 if (first_crtc_state
) {
11583 other_crtc_state
= to_intel_crtc_state(crtc_state
);
11586 first_crtc_state
= to_intel_crtc_state(crtc_state
);
11587 first_pipe
= intel_crtc
->pipe
;
11591 /* No workaround needed? */
11592 if (!first_crtc_state
)
11595 /* w/a possibly needed, check how many crtc's are already enabled. */
11596 for_each_intel_crtc(state
->dev
, intel_crtc
) {
11597 struct intel_crtc_state
*pipe_config
;
11599 pipe_config
= intel_atomic_get_crtc_state(state
, intel_crtc
);
11600 if (IS_ERR(pipe_config
))
11601 return PTR_ERR(pipe_config
);
11603 pipe_config
->hsw_workaround_pipe
= INVALID_PIPE
;
11605 if (!pipe_config
->base
.active
||
11606 needs_modeset(&pipe_config
->base
))
11609 /* 2 or more enabled crtcs means no need for w/a */
11610 if (enabled_pipe
!= INVALID_PIPE
)
11613 enabled_pipe
= intel_crtc
->pipe
;
11616 if (enabled_pipe
!= INVALID_PIPE
)
11617 first_crtc_state
->hsw_workaround_pipe
= enabled_pipe
;
11618 else if (other_crtc_state
)
11619 other_crtc_state
->hsw_workaround_pipe
= first_pipe
;
11624 static int intel_lock_all_pipes(struct drm_atomic_state
*state
)
11626 struct drm_crtc
*crtc
;
11628 /* Add all pipes to the state */
11629 for_each_crtc(state
->dev
, crtc
) {
11630 struct drm_crtc_state
*crtc_state
;
11632 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
11633 if (IS_ERR(crtc_state
))
11634 return PTR_ERR(crtc_state
);
11640 static int intel_modeset_all_pipes(struct drm_atomic_state
*state
)
11642 struct drm_crtc
*crtc
;
11645 * Add all pipes to the state, and force
11646 * a modeset on all the active ones.
11648 for_each_crtc(state
->dev
, crtc
) {
11649 struct drm_crtc_state
*crtc_state
;
11652 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
11653 if (IS_ERR(crtc_state
))
11654 return PTR_ERR(crtc_state
);
11656 if (!crtc_state
->active
|| needs_modeset(crtc_state
))
11659 crtc_state
->mode_changed
= true;
11661 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
11665 ret
= drm_atomic_add_affected_planes(state
, crtc
);
11673 static int intel_modeset_checks(struct drm_atomic_state
*state
)
11675 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
11676 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
11677 struct drm_crtc
*crtc
;
11678 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
11681 if (!check_digital_port_conflicts(state
)) {
11682 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
11686 intel_state
->modeset
= true;
11687 intel_state
->active_crtcs
= dev_priv
->active_crtcs
;
11688 intel_state
->cdclk
.logical
= dev_priv
->cdclk
.logical
;
11689 intel_state
->cdclk
.actual
= dev_priv
->cdclk
.actual
;
11691 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
11692 if (new_crtc_state
->active
)
11693 intel_state
->active_crtcs
|= 1 << i
;
11695 intel_state
->active_crtcs
&= ~(1 << i
);
11697 if (old_crtc_state
->active
!= new_crtc_state
->active
)
11698 intel_state
->active_pipe_changes
|= drm_crtc_mask(crtc
);
11702 * See if the config requires any additional preparation, e.g.
11703 * to adjust global state with pipes off. We need to do this
11704 * here so we can get the modeset_pipe updated config for the new
11705 * mode set on this crtc. For other crtcs we need to use the
11706 * adjusted_mode bits in the crtc directly.
11708 if (dev_priv
->display
.modeset_calc_cdclk
) {
11709 ret
= dev_priv
->display
.modeset_calc_cdclk(state
);
11714 * Writes to dev_priv->cdclk.logical must protected by
11715 * holding all the crtc locks, even if we don't end up
11716 * touching the hardware
11718 if (!intel_cdclk_state_compare(&dev_priv
->cdclk
.logical
,
11719 &intel_state
->cdclk
.logical
)) {
11720 ret
= intel_lock_all_pipes(state
);
11725 /* All pipes must be switched off while we change the cdclk. */
11726 if (!intel_cdclk_state_compare(&dev_priv
->cdclk
.actual
,
11727 &intel_state
->cdclk
.actual
)) {
11728 ret
= intel_modeset_all_pipes(state
);
11733 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
11734 intel_state
->cdclk
.logical
.cdclk
,
11735 intel_state
->cdclk
.actual
.cdclk
);
11737 to_intel_atomic_state(state
)->cdclk
.logical
= dev_priv
->cdclk
.logical
;
11740 intel_modeset_clear_plls(state
);
11742 if (IS_HASWELL(dev_priv
))
11743 return haswell_mode_set_planes_workaround(state
);
11749 * Handle calculation of various watermark data at the end of the atomic check
11750 * phase. The code here should be run after the per-crtc and per-plane 'check'
11751 * handlers to ensure that all derived state has been updated.
11753 static int calc_watermark_data(struct drm_atomic_state
*state
)
11755 struct drm_device
*dev
= state
->dev
;
11756 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11758 /* Is there platform-specific watermark information to calculate? */
11759 if (dev_priv
->display
.compute_global_watermarks
)
11760 return dev_priv
->display
.compute_global_watermarks(state
);
11766 * intel_atomic_check - validate state object
11768 * @state: state to validate
11770 static int intel_atomic_check(struct drm_device
*dev
,
11771 struct drm_atomic_state
*state
)
11773 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11774 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
11775 struct drm_crtc
*crtc
;
11776 struct drm_crtc_state
*old_crtc_state
, *crtc_state
;
11778 bool any_ms
= false;
11780 ret
= drm_atomic_helper_check_modeset(dev
, state
);
11784 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, crtc_state
, i
) {
11785 struct intel_crtc_state
*pipe_config
=
11786 to_intel_crtc_state(crtc_state
);
11788 /* Catch I915_MODE_FLAG_INHERITED */
11789 if (crtc_state
->mode
.private_flags
!= old_crtc_state
->mode
.private_flags
)
11790 crtc_state
->mode_changed
= true;
11792 if (!needs_modeset(crtc_state
))
11795 if (!crtc_state
->enable
) {
11800 /* FIXME: For only active_changed we shouldn't need to do any
11801 * state recomputation at all. */
11803 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
11807 ret
= intel_modeset_pipe_config(crtc
, pipe_config
);
11809 intel_dump_pipe_config(to_intel_crtc(crtc
),
11810 pipe_config
, "[failed]");
11814 if (i915
.fastboot
&&
11815 intel_pipe_config_compare(dev_priv
,
11816 to_intel_crtc_state(old_crtc_state
),
11817 pipe_config
, true)) {
11818 crtc_state
->mode_changed
= false;
11819 pipe_config
->update_pipe
= true;
11822 if (needs_modeset(crtc_state
))
11825 ret
= drm_atomic_add_affected_planes(state
, crtc
);
11829 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
11830 needs_modeset(crtc_state
) ?
11831 "[modeset]" : "[fastset]");
11835 ret
= intel_modeset_checks(state
);
11840 intel_state
->cdclk
.logical
= dev_priv
->cdclk
.logical
;
11843 ret
= drm_atomic_helper_check_planes(dev
, state
);
11847 intel_fbc_choose_crtc(dev_priv
, state
);
11848 return calc_watermark_data(state
);
11851 static int intel_atomic_prepare_commit(struct drm_device
*dev
,
11852 struct drm_atomic_state
*state
)
11854 return drm_atomic_helper_prepare_planes(dev
, state
);
11857 u32
intel_crtc_get_vblank_counter(struct intel_crtc
*crtc
)
11859 struct drm_device
*dev
= crtc
->base
.dev
;
11861 if (!dev
->max_vblank_count
)
11862 return drm_crtc_accurate_vblank_count(&crtc
->base
);
11864 return dev
->driver
->get_vblank_counter(dev
, crtc
->pipe
);
11867 static void intel_atomic_wait_for_vblanks(struct drm_device
*dev
,
11868 struct drm_i915_private
*dev_priv
,
11869 unsigned crtc_mask
)
11871 unsigned last_vblank_count
[I915_MAX_PIPES
];
11878 for_each_pipe(dev_priv
, pipe
) {
11879 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
,
11882 if (!((1 << pipe
) & crtc_mask
))
11885 ret
= drm_crtc_vblank_get(&crtc
->base
);
11886 if (WARN_ON(ret
!= 0)) {
11887 crtc_mask
&= ~(1 << pipe
);
11891 last_vblank_count
[pipe
] = drm_crtc_vblank_count(&crtc
->base
);
11894 for_each_pipe(dev_priv
, pipe
) {
11895 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
,
11899 if (!((1 << pipe
) & crtc_mask
))
11902 lret
= wait_event_timeout(dev
->vblank
[pipe
].queue
,
11903 last_vblank_count
[pipe
] !=
11904 drm_crtc_vblank_count(&crtc
->base
),
11905 msecs_to_jiffies(50));
11907 WARN(!lret
, "pipe %c vblank wait timed out\n", pipe_name(pipe
));
11909 drm_crtc_vblank_put(&crtc
->base
);
11913 static bool needs_vblank_wait(struct intel_crtc_state
*crtc_state
)
11915 /* fb updated, need to unpin old fb */
11916 if (crtc_state
->fb_changed
)
11919 /* wm changes, need vblank before final wm's */
11920 if (crtc_state
->update_wm_post
)
11923 if (crtc_state
->wm
.need_postvbl_update
)
11929 static void intel_update_crtc(struct drm_crtc
*crtc
,
11930 struct drm_atomic_state
*state
,
11931 struct drm_crtc_state
*old_crtc_state
,
11932 struct drm_crtc_state
*new_crtc_state
,
11933 unsigned int *crtc_vblank_mask
)
11935 struct drm_device
*dev
= crtc
->dev
;
11936 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11937 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11938 struct intel_crtc_state
*pipe_config
= to_intel_crtc_state(new_crtc_state
);
11939 bool modeset
= needs_modeset(new_crtc_state
);
11942 update_scanline_offset(intel_crtc
);
11943 dev_priv
->display
.crtc_enable(pipe_config
, state
);
11945 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
),
11949 if (drm_atomic_get_existing_plane_state(state
, crtc
->primary
)) {
11951 intel_crtc
, pipe_config
,
11952 to_intel_plane_state(crtc
->primary
->state
));
11955 drm_atomic_helper_commit_planes_on_crtc(old_crtc_state
);
11957 if (needs_vblank_wait(pipe_config
))
11958 *crtc_vblank_mask
|= drm_crtc_mask(crtc
);
11961 static void intel_update_crtcs(struct drm_atomic_state
*state
,
11962 unsigned int *crtc_vblank_mask
)
11964 struct drm_crtc
*crtc
;
11965 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
11968 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
11969 if (!new_crtc_state
->active
)
11972 intel_update_crtc(crtc
, state
, old_crtc_state
,
11973 new_crtc_state
, crtc_vblank_mask
);
11977 static void skl_update_crtcs(struct drm_atomic_state
*state
,
11978 unsigned int *crtc_vblank_mask
)
11980 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
11981 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
11982 struct drm_crtc
*crtc
;
11983 struct intel_crtc
*intel_crtc
;
11984 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
11985 struct intel_crtc_state
*cstate
;
11986 unsigned int updated
= 0;
11991 const struct skl_ddb_entry
*entries
[I915_MAX_PIPES
] = {};
11993 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
)
11994 /* ignore allocations for crtc's that have been turned off. */
11995 if (new_crtc_state
->active
)
11996 entries
[i
] = &to_intel_crtc_state(old_crtc_state
)->wm
.skl
.ddb
;
11999 * Whenever the number of active pipes changes, we need to make sure we
12000 * update the pipes in the right order so that their ddb allocations
12001 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
12002 * cause pipe underruns and other bad stuff.
12007 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12008 bool vbl_wait
= false;
12009 unsigned int cmask
= drm_crtc_mask(crtc
);
12011 intel_crtc
= to_intel_crtc(crtc
);
12012 cstate
= to_intel_crtc_state(crtc
->state
);
12013 pipe
= intel_crtc
->pipe
;
12015 if (updated
& cmask
|| !cstate
->base
.active
)
12018 if (skl_ddb_allocation_overlaps(entries
, &cstate
->wm
.skl
.ddb
, i
))
12022 entries
[i
] = &cstate
->wm
.skl
.ddb
;
12025 * If this is an already active pipe, it's DDB changed,
12026 * and this isn't the last pipe that needs updating
12027 * then we need to wait for a vblank to pass for the
12028 * new ddb allocation to take effect.
12030 if (!skl_ddb_entry_equal(&cstate
->wm
.skl
.ddb
,
12031 &to_intel_crtc_state(old_crtc_state
)->wm
.skl
.ddb
) &&
12032 !new_crtc_state
->active_changed
&&
12033 intel_state
->wm_results
.dirty_pipes
!= updated
)
12036 intel_update_crtc(crtc
, state
, old_crtc_state
,
12037 new_crtc_state
, crtc_vblank_mask
);
12040 intel_wait_for_vblank(dev_priv
, pipe
);
12044 } while (progress
);
12047 static void intel_atomic_helper_free_state(struct drm_i915_private
*dev_priv
)
12049 struct intel_atomic_state
*state
, *next
;
12050 struct llist_node
*freed
;
12052 freed
= llist_del_all(&dev_priv
->atomic_helper
.free_list
);
12053 llist_for_each_entry_safe(state
, next
, freed
, freed
)
12054 drm_atomic_state_put(&state
->base
);
12057 static void intel_atomic_helper_free_state_worker(struct work_struct
*work
)
12059 struct drm_i915_private
*dev_priv
=
12060 container_of(work
, typeof(*dev_priv
), atomic_helper
.free_work
);
12062 intel_atomic_helper_free_state(dev_priv
);
12065 static void intel_atomic_commit_tail(struct drm_atomic_state
*state
)
12067 struct drm_device
*dev
= state
->dev
;
12068 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12069 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12070 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
12071 struct drm_crtc
*crtc
;
12072 struct intel_crtc_state
*intel_cstate
;
12073 bool hw_check
= intel_state
->modeset
;
12074 u64 put_domains
[I915_MAX_PIPES
] = {};
12075 unsigned crtc_vblank_mask
= 0;
12078 drm_atomic_helper_wait_for_dependencies(state
);
12080 if (intel_state
->modeset
)
12081 intel_display_power_get(dev_priv
, POWER_DOMAIN_MODESET
);
12083 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12084 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12086 if (needs_modeset(new_crtc_state
) ||
12087 to_intel_crtc_state(new_crtc_state
)->update_pipe
) {
12090 put_domains
[to_intel_crtc(crtc
)->pipe
] =
12091 modeset_get_crtc_power_domains(crtc
,
12092 to_intel_crtc_state(new_crtc_state
));
12095 if (!needs_modeset(new_crtc_state
))
12098 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state
),
12099 to_intel_crtc_state(new_crtc_state
));
12101 if (old_crtc_state
->active
) {
12102 intel_crtc_disable_planes(crtc
, old_crtc_state
->plane_mask
);
12103 dev_priv
->display
.crtc_disable(to_intel_crtc_state(old_crtc_state
), state
);
12104 intel_crtc
->active
= false;
12105 intel_fbc_disable(intel_crtc
);
12106 intel_disable_shared_dpll(intel_crtc
);
12109 * Underruns don't always raise
12110 * interrupts, so check manually.
12112 intel_check_cpu_fifo_underruns(dev_priv
);
12113 intel_check_pch_fifo_underruns(dev_priv
);
12115 if (!crtc
->state
->active
) {
12117 * Make sure we don't call initial_watermarks
12118 * for ILK-style watermark updates.
12120 * No clue what this is supposed to achieve.
12122 if (INTEL_GEN(dev_priv
) >= 9)
12123 dev_priv
->display
.initial_watermarks(intel_state
,
12124 to_intel_crtc_state(crtc
->state
));
12129 /* Only after disabling all output pipelines that will be changed can we
12130 * update the the output configuration. */
12131 intel_modeset_update_crtc_state(state
);
12133 if (intel_state
->modeset
) {
12134 drm_atomic_helper_update_legacy_modeset_state(state
->dev
, state
);
12136 intel_set_cdclk(dev_priv
, &dev_priv
->cdclk
.actual
);
12139 * SKL workaround: bspec recommends we disable the SAGV when we
12140 * have more then one pipe enabled
12142 if (!intel_can_enable_sagv(state
))
12143 intel_disable_sagv(dev_priv
);
12145 intel_modeset_verify_disabled(dev
, state
);
12148 /* Complete the events for pipes that have now been disabled */
12149 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
12150 bool modeset
= needs_modeset(new_crtc_state
);
12152 /* Complete events for now disable pipes here. */
12153 if (modeset
&& !new_crtc_state
->active
&& new_crtc_state
->event
) {
12154 spin_lock_irq(&dev
->event_lock
);
12155 drm_crtc_send_vblank_event(crtc
, new_crtc_state
->event
);
12156 spin_unlock_irq(&dev
->event_lock
);
12158 new_crtc_state
->event
= NULL
;
12162 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
12163 dev_priv
->display
.update_crtcs(state
, &crtc_vblank_mask
);
12165 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
12166 * already, but still need the state for the delayed optimization. To
12168 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
12169 * - schedule that vblank worker _before_ calling hw_done
12170 * - at the start of commit_tail, cancel it _synchrously
12171 * - switch over to the vblank wait helper in the core after that since
12172 * we don't need out special handling any more.
12174 if (!state
->legacy_cursor_update
)
12175 intel_atomic_wait_for_vblanks(dev
, dev_priv
, crtc_vblank_mask
);
12178 * Now that the vblank has passed, we can go ahead and program the
12179 * optimal watermarks on platforms that need two-step watermark
12182 * TODO: Move this (and other cleanup) to an async worker eventually.
12184 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
12185 intel_cstate
= to_intel_crtc_state(new_crtc_state
);
12187 if (dev_priv
->display
.optimize_watermarks
)
12188 dev_priv
->display
.optimize_watermarks(intel_state
,
12192 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
12193 intel_post_plane_update(to_intel_crtc_state(old_crtc_state
));
12195 if (put_domains
[i
])
12196 modeset_put_power_domains(dev_priv
, put_domains
[i
]);
12198 intel_modeset_verify_crtc(crtc
, state
, old_crtc_state
, new_crtc_state
);
12201 if (intel_state
->modeset
&& intel_can_enable_sagv(state
))
12202 intel_enable_sagv(dev_priv
);
12204 drm_atomic_helper_commit_hw_done(state
);
12206 if (intel_state
->modeset
) {
12207 /* As one of the primary mmio accessors, KMS has a high
12208 * likelihood of triggering bugs in unclaimed access. After we
12209 * finish modesetting, see if an error has been flagged, and if
12210 * so enable debugging for the next modeset - and hope we catch
12213 intel_uncore_arm_unclaimed_mmio_detection(dev_priv
);
12214 intel_display_power_put(dev_priv
, POWER_DOMAIN_MODESET
);
12217 drm_atomic_helper_cleanup_planes(dev
, state
);
12219 drm_atomic_helper_commit_cleanup_done(state
);
12221 drm_atomic_state_put(state
);
12223 intel_atomic_helper_free_state(dev_priv
);
12226 static void intel_atomic_commit_work(struct work_struct
*work
)
12228 struct drm_atomic_state
*state
=
12229 container_of(work
, struct drm_atomic_state
, commit_work
);
12231 intel_atomic_commit_tail(state
);
12234 static int __i915_sw_fence_call
12235 intel_atomic_commit_ready(struct i915_sw_fence
*fence
,
12236 enum i915_sw_fence_notify notify
)
12238 struct intel_atomic_state
*state
=
12239 container_of(fence
, struct intel_atomic_state
, commit_ready
);
12242 case FENCE_COMPLETE
:
12243 if (state
->base
.commit_work
.func
)
12244 queue_work(system_unbound_wq
, &state
->base
.commit_work
);
12249 struct intel_atomic_helper
*helper
=
12250 &to_i915(state
->base
.dev
)->atomic_helper
;
12252 if (llist_add(&state
->freed
, &helper
->free_list
))
12253 schedule_work(&helper
->free_work
);
12258 return NOTIFY_DONE
;
12261 static void intel_atomic_track_fbs(struct drm_atomic_state
*state
)
12263 struct drm_plane_state
*old_plane_state
, *new_plane_state
;
12264 struct drm_plane
*plane
;
12267 for_each_oldnew_plane_in_state(state
, plane
, old_plane_state
, new_plane_state
, i
)
12268 i915_gem_track_fb(intel_fb_obj(old_plane_state
->fb
),
12269 intel_fb_obj(new_plane_state
->fb
),
12270 to_intel_plane(plane
)->frontbuffer_bit
);
12274 * intel_atomic_commit - commit validated state object
12276 * @state: the top-level driver state object
12277 * @nonblock: nonblocking commit
12279 * This function commits a top-level state object that has been validated
12280 * with drm_atomic_helper_check().
12283 * Zero for success or -errno.
12285 static int intel_atomic_commit(struct drm_device
*dev
,
12286 struct drm_atomic_state
*state
,
12289 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
12290 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12293 ret
= drm_atomic_helper_setup_commit(state
, nonblock
);
12297 drm_atomic_state_get(state
);
12298 i915_sw_fence_init(&intel_state
->commit_ready
,
12299 intel_atomic_commit_ready
);
12301 ret
= intel_atomic_prepare_commit(dev
, state
);
12303 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret
);
12304 i915_sw_fence_commit(&intel_state
->commit_ready
);
12309 * The intel_legacy_cursor_update() fast path takes care
12310 * of avoiding the vblank waits for simple cursor
12311 * movement and flips. For cursor on/off and size changes,
12312 * we want to perform the vblank waits so that watermark
12313 * updates happen during the correct frames. Gen9+ have
12314 * double buffered watermarks and so shouldn't need this.
12316 * Do this after drm_atomic_helper_setup_commit() and
12317 * intel_atomic_prepare_commit() because we still want
12318 * to skip the flip and fb cleanup waits. Although that
12319 * does risk yanking the mapping from under the display
12322 * FIXME doing watermarks and fb cleanup from a vblank worker
12323 * (assuming we had any) would solve these problems.
12325 if (INTEL_GEN(dev_priv
) < 9)
12326 state
->legacy_cursor_update
= false;
12328 ret
= drm_atomic_helper_swap_state(state
, true);
12330 i915_sw_fence_commit(&intel_state
->commit_ready
);
12332 drm_atomic_helper_cleanup_planes(dev
, state
);
12335 dev_priv
->wm
.distrust_bios_wm
= false;
12336 intel_shared_dpll_swap_state(state
);
12337 intel_atomic_track_fbs(state
);
12339 if (intel_state
->modeset
) {
12340 memcpy(dev_priv
->min_pixclk
, intel_state
->min_pixclk
,
12341 sizeof(intel_state
->min_pixclk
));
12342 dev_priv
->active_crtcs
= intel_state
->active_crtcs
;
12343 dev_priv
->cdclk
.logical
= intel_state
->cdclk
.logical
;
12344 dev_priv
->cdclk
.actual
= intel_state
->cdclk
.actual
;
12347 drm_atomic_state_get(state
);
12348 INIT_WORK(&state
->commit_work
,
12349 nonblock
? intel_atomic_commit_work
: NULL
);
12351 i915_sw_fence_commit(&intel_state
->commit_ready
);
12353 i915_sw_fence_wait(&intel_state
->commit_ready
);
12354 intel_atomic_commit_tail(state
);
12360 static const struct drm_crtc_funcs intel_crtc_funcs
= {
12361 .gamma_set
= drm_atomic_helper_legacy_gamma_set
,
12362 .set_config
= drm_atomic_helper_set_config
,
12363 .destroy
= intel_crtc_destroy
,
12364 .page_flip
= drm_atomic_helper_page_flip
,
12365 .atomic_duplicate_state
= intel_crtc_duplicate_state
,
12366 .atomic_destroy_state
= intel_crtc_destroy_state
,
12367 .set_crc_source
= intel_crtc_set_crc_source
,
12371 * intel_prepare_plane_fb - Prepare fb for usage on plane
12372 * @plane: drm plane to prepare for
12373 * @fb: framebuffer to prepare for presentation
12375 * Prepares a framebuffer for usage on a display plane. Generally this
12376 * involves pinning the underlying object and updating the frontbuffer tracking
12377 * bits. Some older platforms need special physical address handling for
12380 * Must be called with struct_mutex held.
12382 * Returns 0 on success, negative error code on failure.
12385 intel_prepare_plane_fb(struct drm_plane
*plane
,
12386 struct drm_plane_state
*new_state
)
12388 struct intel_atomic_state
*intel_state
=
12389 to_intel_atomic_state(new_state
->state
);
12390 struct drm_i915_private
*dev_priv
= to_i915(plane
->dev
);
12391 struct drm_framebuffer
*fb
= new_state
->fb
;
12392 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
12393 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->state
->fb
);
12397 struct drm_crtc_state
*crtc_state
=
12398 drm_atomic_get_existing_crtc_state(new_state
->state
,
12399 plane
->state
->crtc
);
12401 /* Big Hammer, we also need to ensure that any pending
12402 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
12403 * current scanout is retired before unpinning the old
12404 * framebuffer. Note that we rely on userspace rendering
12405 * into the buffer attached to the pipe they are waiting
12406 * on. If not, userspace generates a GPU hang with IPEHR
12407 * point to the MI_WAIT_FOR_EVENT.
12409 * This should only fail upon a hung GPU, in which case we
12410 * can safely continue.
12412 if (needs_modeset(crtc_state
)) {
12413 ret
= i915_sw_fence_await_reservation(&intel_state
->commit_ready
,
12414 old_obj
->resv
, NULL
,
12422 if (new_state
->fence
) { /* explicit fencing */
12423 ret
= i915_sw_fence_await_dma_fence(&intel_state
->commit_ready
,
12425 I915_FENCE_TIMEOUT
,
12434 ret
= i915_gem_object_pin_pages(obj
);
12438 ret
= mutex_lock_interruptible(&dev_priv
->drm
.struct_mutex
);
12440 i915_gem_object_unpin_pages(obj
);
12444 if (plane
->type
== DRM_PLANE_TYPE_CURSOR
&&
12445 INTEL_INFO(dev_priv
)->cursor_needs_physical
) {
12446 const int align
= intel_cursor_alignment(dev_priv
);
12448 ret
= i915_gem_object_attach_phys(obj
, align
);
12450 struct i915_vma
*vma
;
12452 vma
= intel_pin_and_fence_fb_obj(fb
, new_state
->rotation
);
12454 to_intel_plane_state(new_state
)->vma
= vma
;
12456 ret
= PTR_ERR(vma
);
12459 i915_gem_object_wait_priority(obj
, 0, I915_PRIORITY_DISPLAY
);
12461 mutex_unlock(&dev_priv
->drm
.struct_mutex
);
12462 i915_gem_object_unpin_pages(obj
);
12466 if (!new_state
->fence
) { /* implicit fencing */
12467 ret
= i915_sw_fence_await_reservation(&intel_state
->commit_ready
,
12469 false, I915_FENCE_TIMEOUT
,
12479 * intel_cleanup_plane_fb - Cleans up an fb after plane use
12480 * @plane: drm plane to clean up for
12481 * @fb: old framebuffer that was on plane
12483 * Cleans up a framebuffer that has just been removed from a plane.
12485 * Must be called with struct_mutex held.
12488 intel_cleanup_plane_fb(struct drm_plane
*plane
,
12489 struct drm_plane_state
*old_state
)
12491 struct i915_vma
*vma
;
12493 /* Should only be called after a successful intel_prepare_plane_fb()! */
12494 vma
= fetch_and_zero(&to_intel_plane_state(old_state
)->vma
);
12496 mutex_lock(&plane
->dev
->struct_mutex
);
12497 intel_unpin_fb_vma(vma
);
12498 mutex_unlock(&plane
->dev
->struct_mutex
);
12503 skl_max_scale(struct intel_crtc
*intel_crtc
, struct intel_crtc_state
*crtc_state
)
12505 struct drm_i915_private
*dev_priv
;
12507 int crtc_clock
, max_dotclk
;
12509 if (!intel_crtc
|| !crtc_state
->base
.enable
)
12510 return DRM_PLANE_HELPER_NO_SCALING
;
12512 dev_priv
= to_i915(intel_crtc
->base
.dev
);
12514 crtc_clock
= crtc_state
->base
.adjusted_mode
.crtc_clock
;
12515 max_dotclk
= to_intel_atomic_state(crtc_state
->base
.state
)->cdclk
.logical
.cdclk
;
12517 if (IS_GEMINILAKE(dev_priv
))
12520 if (WARN_ON_ONCE(!crtc_clock
|| max_dotclk
< crtc_clock
))
12521 return DRM_PLANE_HELPER_NO_SCALING
;
12524 * skl max scale is lower of:
12525 * close to 3 but not 3, -1 is for that purpose
12529 max_scale
= min((1 << 16) * 3 - 1,
12530 (1 << 8) * ((max_dotclk
<< 8) / crtc_clock
));
12536 intel_check_primary_plane(struct intel_plane
*plane
,
12537 struct intel_crtc_state
*crtc_state
,
12538 struct intel_plane_state
*state
)
12540 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
12541 struct drm_crtc
*crtc
= state
->base
.crtc
;
12542 int min_scale
= DRM_PLANE_HELPER_NO_SCALING
;
12543 int max_scale
= DRM_PLANE_HELPER_NO_SCALING
;
12544 bool can_position
= false;
12547 if (INTEL_GEN(dev_priv
) >= 9) {
12548 /* use scaler when colorkey is not required */
12549 if (state
->ckey
.flags
== I915_SET_COLORKEY_NONE
) {
12551 max_scale
= skl_max_scale(to_intel_crtc(crtc
), crtc_state
);
12553 can_position
= true;
12556 ret
= drm_plane_helper_check_state(&state
->base
,
12558 min_scale
, max_scale
,
12559 can_position
, true);
12563 if (!state
->base
.fb
)
12566 if (INTEL_GEN(dev_priv
) >= 9) {
12567 ret
= skl_check_plane_surface(state
);
12571 state
->ctl
= skl_plane_ctl(crtc_state
, state
);
12573 ret
= i9xx_check_plane_surface(state
);
12577 state
->ctl
= i9xx_plane_ctl(crtc_state
, state
);
12583 static void intel_begin_crtc_commit(struct drm_crtc
*crtc
,
12584 struct drm_crtc_state
*old_crtc_state
)
12586 struct drm_device
*dev
= crtc
->dev
;
12587 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12588 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12589 struct intel_crtc_state
*intel_cstate
=
12590 to_intel_crtc_state(crtc
->state
);
12591 struct intel_crtc_state
*old_intel_cstate
=
12592 to_intel_crtc_state(old_crtc_state
);
12593 struct intel_atomic_state
*old_intel_state
=
12594 to_intel_atomic_state(old_crtc_state
->state
);
12595 bool modeset
= needs_modeset(crtc
->state
);
12598 (intel_cstate
->base
.color_mgmt_changed
||
12599 intel_cstate
->update_pipe
)) {
12600 intel_color_set_csc(crtc
->state
);
12601 intel_color_load_luts(crtc
->state
);
12604 /* Perform vblank evasion around commit operation */
12605 intel_pipe_update_start(intel_crtc
);
12610 if (intel_cstate
->update_pipe
)
12611 intel_update_pipe_config(intel_crtc
, old_intel_cstate
);
12612 else if (INTEL_GEN(dev_priv
) >= 9)
12613 skl_detach_scalers(intel_crtc
);
12616 if (dev_priv
->display
.atomic_update_watermarks
)
12617 dev_priv
->display
.atomic_update_watermarks(old_intel_state
,
12621 static void intel_finish_crtc_commit(struct drm_crtc
*crtc
,
12622 struct drm_crtc_state
*old_crtc_state
)
12624 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12626 intel_pipe_update_end(intel_crtc
);
12630 * intel_plane_destroy - destroy a plane
12631 * @plane: plane to destroy
12633 * Common destruction function for all types of planes (primary, cursor,
12636 void intel_plane_destroy(struct drm_plane
*plane
)
12638 drm_plane_cleanup(plane
);
12639 kfree(to_intel_plane(plane
));
12642 const struct drm_plane_funcs intel_plane_funcs
= {
12643 .update_plane
= drm_atomic_helper_update_plane
,
12644 .disable_plane
= drm_atomic_helper_disable_plane
,
12645 .destroy
= intel_plane_destroy
,
12646 .atomic_get_property
= intel_plane_atomic_get_property
,
12647 .atomic_set_property
= intel_plane_atomic_set_property
,
12648 .atomic_duplicate_state
= intel_plane_duplicate_state
,
12649 .atomic_destroy_state
= intel_plane_destroy_state
,
12653 intel_legacy_cursor_update(struct drm_plane
*plane
,
12654 struct drm_crtc
*crtc
,
12655 struct drm_framebuffer
*fb
,
12656 int crtc_x
, int crtc_y
,
12657 unsigned int crtc_w
, unsigned int crtc_h
,
12658 uint32_t src_x
, uint32_t src_y
,
12659 uint32_t src_w
, uint32_t src_h
,
12660 struct drm_modeset_acquire_ctx
*ctx
)
12662 struct drm_i915_private
*dev_priv
= to_i915(crtc
->dev
);
12664 struct drm_plane_state
*old_plane_state
, *new_plane_state
;
12665 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
12666 struct drm_framebuffer
*old_fb
;
12667 struct drm_crtc_state
*crtc_state
= crtc
->state
;
12668 struct i915_vma
*old_vma
, *vma
;
12671 * When crtc is inactive or there is a modeset pending,
12672 * wait for it to complete in the slowpath
12674 if (!crtc_state
->active
|| needs_modeset(crtc_state
) ||
12675 to_intel_crtc_state(crtc_state
)->update_pipe
)
12678 old_plane_state
= plane
->state
;
12681 * If any parameters change that may affect watermarks,
12682 * take the slowpath. Only changing fb or position should be
12685 if (old_plane_state
->crtc
!= crtc
||
12686 old_plane_state
->src_w
!= src_w
||
12687 old_plane_state
->src_h
!= src_h
||
12688 old_plane_state
->crtc_w
!= crtc_w
||
12689 old_plane_state
->crtc_h
!= crtc_h
||
12690 !old_plane_state
->fb
!= !fb
)
12693 new_plane_state
= intel_plane_duplicate_state(plane
);
12694 if (!new_plane_state
)
12697 drm_atomic_set_fb_for_plane(new_plane_state
, fb
);
12699 new_plane_state
->src_x
= src_x
;
12700 new_plane_state
->src_y
= src_y
;
12701 new_plane_state
->src_w
= src_w
;
12702 new_plane_state
->src_h
= src_h
;
12703 new_plane_state
->crtc_x
= crtc_x
;
12704 new_plane_state
->crtc_y
= crtc_y
;
12705 new_plane_state
->crtc_w
= crtc_w
;
12706 new_plane_state
->crtc_h
= crtc_h
;
12708 ret
= intel_plane_atomic_check_with_state(to_intel_crtc_state(crtc
->state
),
12709 to_intel_plane_state(new_plane_state
));
12713 ret
= mutex_lock_interruptible(&dev_priv
->drm
.struct_mutex
);
12717 if (INTEL_INFO(dev_priv
)->cursor_needs_physical
) {
12718 int align
= intel_cursor_alignment(dev_priv
);
12720 ret
= i915_gem_object_attach_phys(intel_fb_obj(fb
), align
);
12722 DRM_DEBUG_KMS("failed to attach phys object\n");
12726 vma
= intel_pin_and_fence_fb_obj(fb
, new_plane_state
->rotation
);
12728 DRM_DEBUG_KMS("failed to pin object\n");
12730 ret
= PTR_ERR(vma
);
12734 to_intel_plane_state(new_plane_state
)->vma
= vma
;
12737 old_fb
= old_plane_state
->fb
;
12738 old_vma
= to_intel_plane_state(old_plane_state
)->vma
;
12740 i915_gem_track_fb(intel_fb_obj(old_fb
), intel_fb_obj(fb
),
12741 intel_plane
->frontbuffer_bit
);
12743 /* Swap plane state */
12744 new_plane_state
->fence
= old_plane_state
->fence
;
12745 *to_intel_plane_state(old_plane_state
) = *to_intel_plane_state(new_plane_state
);
12746 new_plane_state
->fence
= NULL
;
12747 new_plane_state
->fb
= old_fb
;
12748 to_intel_plane_state(new_plane_state
)->vma
= NULL
;
12750 if (plane
->state
->visible
) {
12751 trace_intel_update_plane(plane
, to_intel_crtc(crtc
));
12752 intel_plane
->update_plane(intel_plane
,
12753 to_intel_crtc_state(crtc
->state
),
12754 to_intel_plane_state(plane
->state
));
12756 trace_intel_disable_plane(plane
, to_intel_crtc(crtc
));
12757 intel_plane
->disable_plane(intel_plane
, to_intel_crtc(crtc
));
12761 intel_unpin_fb_vma(old_vma
);
12764 mutex_unlock(&dev_priv
->drm
.struct_mutex
);
12766 intel_plane_destroy_state(plane
, new_plane_state
);
12770 return drm_atomic_helper_update_plane(plane
, crtc
, fb
,
12771 crtc_x
, crtc_y
, crtc_w
, crtc_h
,
12772 src_x
, src_y
, src_w
, src_h
, ctx
);
12775 static const struct drm_plane_funcs intel_cursor_plane_funcs
= {
12776 .update_plane
= intel_legacy_cursor_update
,
12777 .disable_plane
= drm_atomic_helper_disable_plane
,
12778 .destroy
= intel_plane_destroy
,
12779 .atomic_get_property
= intel_plane_atomic_get_property
,
12780 .atomic_set_property
= intel_plane_atomic_set_property
,
12781 .atomic_duplicate_state
= intel_plane_duplicate_state
,
12782 .atomic_destroy_state
= intel_plane_destroy_state
,
12785 static struct intel_plane
*
12786 intel_primary_plane_create(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
12788 struct intel_plane
*primary
= NULL
;
12789 struct intel_plane_state
*state
= NULL
;
12790 const uint32_t *intel_primary_formats
;
12791 unsigned int supported_rotations
;
12792 unsigned int num_formats
;
12795 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
12801 state
= intel_create_plane_state(&primary
->base
);
12807 primary
->base
.state
= &state
->base
;
12809 primary
->can_scale
= false;
12810 primary
->max_downscale
= 1;
12811 if (INTEL_GEN(dev_priv
) >= 9) {
12812 primary
->can_scale
= true;
12813 state
->scaler_id
= -1;
12815 primary
->pipe
= pipe
;
12817 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
12818 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
12820 if (HAS_FBC(dev_priv
) && INTEL_GEN(dev_priv
) < 4)
12821 primary
->plane
= (enum plane
) !pipe
;
12823 primary
->plane
= (enum plane
) pipe
;
12824 primary
->id
= PLANE_PRIMARY
;
12825 primary
->frontbuffer_bit
= INTEL_FRONTBUFFER_PRIMARY(pipe
);
12826 primary
->check_plane
= intel_check_primary_plane
;
12828 if (INTEL_GEN(dev_priv
) >= 9) {
12829 intel_primary_formats
= skl_primary_formats
;
12830 num_formats
= ARRAY_SIZE(skl_primary_formats
);
12832 primary
->update_plane
= skylake_update_primary_plane
;
12833 primary
->disable_plane
= skylake_disable_primary_plane
;
12834 } else if (INTEL_GEN(dev_priv
) >= 4) {
12835 intel_primary_formats
= i965_primary_formats
;
12836 num_formats
= ARRAY_SIZE(i965_primary_formats
);
12838 primary
->update_plane
= i9xx_update_primary_plane
;
12839 primary
->disable_plane
= i9xx_disable_primary_plane
;
12841 intel_primary_formats
= i8xx_primary_formats
;
12842 num_formats
= ARRAY_SIZE(i8xx_primary_formats
);
12844 primary
->update_plane
= i9xx_update_primary_plane
;
12845 primary
->disable_plane
= i9xx_disable_primary_plane
;
12848 if (INTEL_GEN(dev_priv
) >= 9)
12849 ret
= drm_universal_plane_init(&dev_priv
->drm
, &primary
->base
,
12850 0, &intel_plane_funcs
,
12851 intel_primary_formats
, num_formats
,
12853 DRM_PLANE_TYPE_PRIMARY
,
12854 "plane 1%c", pipe_name(pipe
));
12855 else if (INTEL_GEN(dev_priv
) >= 5 || IS_G4X(dev_priv
))
12856 ret
= drm_universal_plane_init(&dev_priv
->drm
, &primary
->base
,
12857 0, &intel_plane_funcs
,
12858 intel_primary_formats
, num_formats
,
12860 DRM_PLANE_TYPE_PRIMARY
,
12861 "primary %c", pipe_name(pipe
));
12863 ret
= drm_universal_plane_init(&dev_priv
->drm
, &primary
->base
,
12864 0, &intel_plane_funcs
,
12865 intel_primary_formats
, num_formats
,
12867 DRM_PLANE_TYPE_PRIMARY
,
12868 "plane %c", plane_name(primary
->plane
));
12872 if (INTEL_GEN(dev_priv
) >= 9) {
12873 supported_rotations
=
12874 DRM_MODE_ROTATE_0
| DRM_MODE_ROTATE_90
|
12875 DRM_MODE_ROTATE_180
| DRM_MODE_ROTATE_270
;
12876 } else if (IS_CHERRYVIEW(dev_priv
) && pipe
== PIPE_B
) {
12877 supported_rotations
=
12878 DRM_MODE_ROTATE_0
| DRM_MODE_ROTATE_180
|
12879 DRM_MODE_REFLECT_X
;
12880 } else if (INTEL_GEN(dev_priv
) >= 4) {
12881 supported_rotations
=
12882 DRM_MODE_ROTATE_0
| DRM_MODE_ROTATE_180
;
12884 supported_rotations
= DRM_MODE_ROTATE_0
;
12887 if (INTEL_GEN(dev_priv
) >= 4)
12888 drm_plane_create_rotation_property(&primary
->base
,
12890 supported_rotations
);
12892 drm_plane_helper_add(&primary
->base
, &intel_plane_helper_funcs
);
12900 return ERR_PTR(ret
);
12903 static struct intel_plane
*
12904 intel_cursor_plane_create(struct drm_i915_private
*dev_priv
,
12907 struct intel_plane
*cursor
= NULL
;
12908 struct intel_plane_state
*state
= NULL
;
12911 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
12917 state
= intel_create_plane_state(&cursor
->base
);
12923 cursor
->base
.state
= &state
->base
;
12925 cursor
->can_scale
= false;
12926 cursor
->max_downscale
= 1;
12927 cursor
->pipe
= pipe
;
12928 cursor
->plane
= pipe
;
12929 cursor
->id
= PLANE_CURSOR
;
12930 cursor
->frontbuffer_bit
= INTEL_FRONTBUFFER_CURSOR(pipe
);
12932 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
)) {
12933 cursor
->update_plane
= i845_update_cursor
;
12934 cursor
->disable_plane
= i845_disable_cursor
;
12935 cursor
->check_plane
= i845_check_cursor
;
12937 cursor
->update_plane
= i9xx_update_cursor
;
12938 cursor
->disable_plane
= i9xx_disable_cursor
;
12939 cursor
->check_plane
= i9xx_check_cursor
;
12942 cursor
->cursor
.base
= ~0;
12943 cursor
->cursor
.cntl
= ~0;
12945 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
) || HAS_CUR_FBC(dev_priv
))
12946 cursor
->cursor
.size
= ~0;
12948 ret
= drm_universal_plane_init(&dev_priv
->drm
, &cursor
->base
,
12949 0, &intel_cursor_plane_funcs
,
12950 intel_cursor_formats
,
12951 ARRAY_SIZE(intel_cursor_formats
),
12952 NULL
, DRM_PLANE_TYPE_CURSOR
,
12953 "cursor %c", pipe_name(pipe
));
12957 if (INTEL_GEN(dev_priv
) >= 4)
12958 drm_plane_create_rotation_property(&cursor
->base
,
12960 DRM_MODE_ROTATE_0
|
12961 DRM_MODE_ROTATE_180
);
12963 if (INTEL_GEN(dev_priv
) >= 9)
12964 state
->scaler_id
= -1;
12966 drm_plane_helper_add(&cursor
->base
, &intel_plane_helper_funcs
);
12974 return ERR_PTR(ret
);
12977 static void intel_crtc_init_scalers(struct intel_crtc
*crtc
,
12978 struct intel_crtc_state
*crtc_state
)
12980 struct intel_crtc_scaler_state
*scaler_state
=
12981 &crtc_state
->scaler_state
;
12982 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
12985 crtc
->num_scalers
= dev_priv
->info
.num_scalers
[crtc
->pipe
];
12986 if (!crtc
->num_scalers
)
12989 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
12990 struct intel_scaler
*scaler
= &scaler_state
->scalers
[i
];
12992 scaler
->in_use
= 0;
12993 scaler
->mode
= PS_SCALER_MODE_DYN
;
12996 scaler_state
->scaler_id
= -1;
12999 static int intel_crtc_init(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
13001 struct intel_crtc
*intel_crtc
;
13002 struct intel_crtc_state
*crtc_state
= NULL
;
13003 struct intel_plane
*primary
= NULL
;
13004 struct intel_plane
*cursor
= NULL
;
13007 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
13011 crtc_state
= kzalloc(sizeof(*crtc_state
), GFP_KERNEL
);
13016 intel_crtc
->config
= crtc_state
;
13017 intel_crtc
->base
.state
= &crtc_state
->base
;
13018 crtc_state
->base
.crtc
= &intel_crtc
->base
;
13020 primary
= intel_primary_plane_create(dev_priv
, pipe
);
13021 if (IS_ERR(primary
)) {
13022 ret
= PTR_ERR(primary
);
13025 intel_crtc
->plane_ids_mask
|= BIT(primary
->id
);
13027 for_each_sprite(dev_priv
, pipe
, sprite
) {
13028 struct intel_plane
*plane
;
13030 plane
= intel_sprite_plane_create(dev_priv
, pipe
, sprite
);
13031 if (IS_ERR(plane
)) {
13032 ret
= PTR_ERR(plane
);
13035 intel_crtc
->plane_ids_mask
|= BIT(plane
->id
);
13038 cursor
= intel_cursor_plane_create(dev_priv
, pipe
);
13039 if (IS_ERR(cursor
)) {
13040 ret
= PTR_ERR(cursor
);
13043 intel_crtc
->plane_ids_mask
|= BIT(cursor
->id
);
13045 ret
= drm_crtc_init_with_planes(&dev_priv
->drm
, &intel_crtc
->base
,
13046 &primary
->base
, &cursor
->base
,
13048 "pipe %c", pipe_name(pipe
));
13052 intel_crtc
->pipe
= pipe
;
13053 intel_crtc
->plane
= primary
->plane
;
13055 /* initialize shared scalers */
13056 intel_crtc_init_scalers(intel_crtc
, crtc_state
);
13058 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
13059 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
13060 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = intel_crtc
;
13061 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = intel_crtc
;
13063 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
13065 intel_color_init(&intel_crtc
->base
);
13067 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
13073 * drm_mode_config_cleanup() will free up any
13074 * crtcs/planes already initialized.
13082 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
13084 struct drm_device
*dev
= connector
->base
.dev
;
13086 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
13088 if (!connector
->base
.state
->crtc
)
13089 return INVALID_PIPE
;
13091 return to_intel_crtc(connector
->base
.state
->crtc
)->pipe
;
13094 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
13095 struct drm_file
*file
)
13097 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
13098 struct drm_crtc
*drmmode_crtc
;
13099 struct intel_crtc
*crtc
;
13101 drmmode_crtc
= drm_crtc_find(dev
, pipe_from_crtc_id
->crtc_id
);
13105 crtc
= to_intel_crtc(drmmode_crtc
);
13106 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
13111 static int intel_encoder_clones(struct intel_encoder
*encoder
)
13113 struct drm_device
*dev
= encoder
->base
.dev
;
13114 struct intel_encoder
*source_encoder
;
13115 int index_mask
= 0;
13118 for_each_intel_encoder(dev
, source_encoder
) {
13119 if (encoders_cloneable(encoder
, source_encoder
))
13120 index_mask
|= (1 << entry
);
13128 static bool has_edp_a(struct drm_i915_private
*dev_priv
)
13130 if (!IS_MOBILE(dev_priv
))
13133 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
13136 if (IS_GEN5(dev_priv
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
13142 static bool intel_crt_present(struct drm_i915_private
*dev_priv
)
13144 if (INTEL_GEN(dev_priv
) >= 9)
13147 if (IS_HSW_ULT(dev_priv
) || IS_BDW_ULT(dev_priv
))
13150 if (IS_CHERRYVIEW(dev_priv
))
13153 if (HAS_PCH_LPT_H(dev_priv
) &&
13154 I915_READ(SFUSE_STRAP
) & SFUSE_STRAP_CRT_DISABLED
)
13157 /* DDI E can't be used if DDI A requires 4 lanes */
13158 if (HAS_DDI(dev_priv
) && I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_A_4_LANES
)
13161 if (!dev_priv
->vbt
.int_crt_support
)
13167 void intel_pps_unlock_regs_wa(struct drm_i915_private
*dev_priv
)
13172 if (HAS_DDI(dev_priv
))
13175 * This w/a is needed at least on CPT/PPT, but to be sure apply it
13176 * everywhere where registers can be write protected.
13178 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
13183 for (pps_idx
= 0; pps_idx
< pps_num
; pps_idx
++) {
13184 u32 val
= I915_READ(PP_CONTROL(pps_idx
));
13186 val
= (val
& ~PANEL_UNLOCK_MASK
) | PANEL_UNLOCK_REGS
;
13187 I915_WRITE(PP_CONTROL(pps_idx
), val
);
13191 static void intel_pps_init(struct drm_i915_private
*dev_priv
)
13193 if (HAS_PCH_SPLIT(dev_priv
) || IS_GEN9_LP(dev_priv
))
13194 dev_priv
->pps_mmio_base
= PCH_PPS_BASE
;
13195 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
13196 dev_priv
->pps_mmio_base
= VLV_PPS_BASE
;
13198 dev_priv
->pps_mmio_base
= PPS_BASE
;
13200 intel_pps_unlock_regs_wa(dev_priv
);
13203 static void intel_setup_outputs(struct drm_i915_private
*dev_priv
)
13205 struct intel_encoder
*encoder
;
13206 bool dpd_is_edp
= false;
13208 intel_pps_init(dev_priv
);
13211 * intel_edp_init_connector() depends on this completing first, to
13212 * prevent the registeration of both eDP and LVDS and the incorrect
13213 * sharing of the PPS.
13215 intel_lvds_init(dev_priv
);
13217 if (intel_crt_present(dev_priv
))
13218 intel_crt_init(dev_priv
);
13220 if (IS_GEN9_LP(dev_priv
)) {
13222 * FIXME: Broxton doesn't support port detection via the
13223 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
13224 * detect the ports.
13226 intel_ddi_init(dev_priv
, PORT_A
);
13227 intel_ddi_init(dev_priv
, PORT_B
);
13228 intel_ddi_init(dev_priv
, PORT_C
);
13230 intel_dsi_init(dev_priv
);
13231 } else if (HAS_DDI(dev_priv
)) {
13235 * Haswell uses DDI functions to detect digital outputs.
13236 * On SKL pre-D0 the strap isn't connected, so we assume
13239 found
= I915_READ(DDI_BUF_CTL(PORT_A
)) & DDI_INIT_DISPLAY_DETECTED
;
13240 /* WaIgnoreDDIAStrap: skl */
13241 if (found
|| IS_GEN9_BC(dev_priv
))
13242 intel_ddi_init(dev_priv
, PORT_A
);
13244 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
13246 found
= I915_READ(SFUSE_STRAP
);
13248 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
13249 intel_ddi_init(dev_priv
, PORT_B
);
13250 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
13251 intel_ddi_init(dev_priv
, PORT_C
);
13252 if (found
& SFUSE_STRAP_DDID_DETECTED
)
13253 intel_ddi_init(dev_priv
, PORT_D
);
13255 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
13257 if (IS_GEN9_BC(dev_priv
) &&
13258 (dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dp
||
13259 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_dvi
||
13260 dev_priv
->vbt
.ddi_port_info
[PORT_E
].supports_hdmi
))
13261 intel_ddi_init(dev_priv
, PORT_E
);
13263 } else if (HAS_PCH_SPLIT(dev_priv
)) {
13265 dpd_is_edp
= intel_dp_is_edp(dev_priv
, PORT_D
);
13267 if (has_edp_a(dev_priv
))
13268 intel_dp_init(dev_priv
, DP_A
, PORT_A
);
13270 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
13271 /* PCH SDVOB multiplex with HDMIB */
13272 found
= intel_sdvo_init(dev_priv
, PCH_SDVOB
, PORT_B
);
13274 intel_hdmi_init(dev_priv
, PCH_HDMIB
, PORT_B
);
13275 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
13276 intel_dp_init(dev_priv
, PCH_DP_B
, PORT_B
);
13279 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
13280 intel_hdmi_init(dev_priv
, PCH_HDMIC
, PORT_C
);
13282 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
13283 intel_hdmi_init(dev_priv
, PCH_HDMID
, PORT_D
);
13285 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
13286 intel_dp_init(dev_priv
, PCH_DP_C
, PORT_C
);
13288 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
13289 intel_dp_init(dev_priv
, PCH_DP_D
, PORT_D
);
13290 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
13291 bool has_edp
, has_port
;
13294 * The DP_DETECTED bit is the latched state of the DDC
13295 * SDA pin at boot. However since eDP doesn't require DDC
13296 * (no way to plug in a DP->HDMI dongle) the DDC pins for
13297 * eDP ports may have been muxed to an alternate function.
13298 * Thus we can't rely on the DP_DETECTED bit alone to detect
13299 * eDP ports. Consult the VBT as well as DP_DETECTED to
13300 * detect eDP ports.
13302 * Sadly the straps seem to be missing sometimes even for HDMI
13303 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
13304 * and VBT for the presence of the port. Additionally we can't
13305 * trust the port type the VBT declares as we've seen at least
13306 * HDMI ports that the VBT claim are DP or eDP.
13308 has_edp
= intel_dp_is_edp(dev_priv
, PORT_B
);
13309 has_port
= intel_bios_is_port_present(dev_priv
, PORT_B
);
13310 if (I915_READ(VLV_DP_B
) & DP_DETECTED
|| has_port
)
13311 has_edp
&= intel_dp_init(dev_priv
, VLV_DP_B
, PORT_B
);
13312 if ((I915_READ(VLV_HDMIB
) & SDVO_DETECTED
|| has_port
) && !has_edp
)
13313 intel_hdmi_init(dev_priv
, VLV_HDMIB
, PORT_B
);
13315 has_edp
= intel_dp_is_edp(dev_priv
, PORT_C
);
13316 has_port
= intel_bios_is_port_present(dev_priv
, PORT_C
);
13317 if (I915_READ(VLV_DP_C
) & DP_DETECTED
|| has_port
)
13318 has_edp
&= intel_dp_init(dev_priv
, VLV_DP_C
, PORT_C
);
13319 if ((I915_READ(VLV_HDMIC
) & SDVO_DETECTED
|| has_port
) && !has_edp
)
13320 intel_hdmi_init(dev_priv
, VLV_HDMIC
, PORT_C
);
13322 if (IS_CHERRYVIEW(dev_priv
)) {
13324 * eDP not supported on port D,
13325 * so no need to worry about it
13327 has_port
= intel_bios_is_port_present(dev_priv
, PORT_D
);
13328 if (I915_READ(CHV_DP_D
) & DP_DETECTED
|| has_port
)
13329 intel_dp_init(dev_priv
, CHV_DP_D
, PORT_D
);
13330 if (I915_READ(CHV_HDMID
) & SDVO_DETECTED
|| has_port
)
13331 intel_hdmi_init(dev_priv
, CHV_HDMID
, PORT_D
);
13334 intel_dsi_init(dev_priv
);
13335 } else if (!IS_GEN2(dev_priv
) && !IS_PINEVIEW(dev_priv
)) {
13336 bool found
= false;
13338 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
13339 DRM_DEBUG_KMS("probing SDVOB\n");
13340 found
= intel_sdvo_init(dev_priv
, GEN3_SDVOB
, PORT_B
);
13341 if (!found
&& IS_G4X(dev_priv
)) {
13342 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
13343 intel_hdmi_init(dev_priv
, GEN4_HDMIB
, PORT_B
);
13346 if (!found
&& IS_G4X(dev_priv
))
13347 intel_dp_init(dev_priv
, DP_B
, PORT_B
);
13350 /* Before G4X SDVOC doesn't have its own detect register */
13352 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
13353 DRM_DEBUG_KMS("probing SDVOC\n");
13354 found
= intel_sdvo_init(dev_priv
, GEN3_SDVOC
, PORT_C
);
13357 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
13359 if (IS_G4X(dev_priv
)) {
13360 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
13361 intel_hdmi_init(dev_priv
, GEN4_HDMIC
, PORT_C
);
13363 if (IS_G4X(dev_priv
))
13364 intel_dp_init(dev_priv
, DP_C
, PORT_C
);
13367 if (IS_G4X(dev_priv
) && (I915_READ(DP_D
) & DP_DETECTED
))
13368 intel_dp_init(dev_priv
, DP_D
, PORT_D
);
13369 } else if (IS_GEN2(dev_priv
))
13370 intel_dvo_init(dev_priv
);
13372 if (SUPPORTS_TV(dev_priv
))
13373 intel_tv_init(dev_priv
);
13375 intel_psr_init(dev_priv
);
13377 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
13378 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
13379 encoder
->base
.possible_clones
=
13380 intel_encoder_clones(encoder
);
13383 intel_init_pch_refclk(dev_priv
);
13385 drm_helper_move_panel_connectors_to_head(&dev_priv
->drm
);
13388 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
13390 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
13392 drm_framebuffer_cleanup(fb
);
13394 i915_gem_object_lock(intel_fb
->obj
);
13395 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
13396 i915_gem_object_unlock(intel_fb
->obj
);
13398 i915_gem_object_put(intel_fb
->obj
);
13403 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
13404 struct drm_file
*file
,
13405 unsigned int *handle
)
13407 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
13408 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
13410 if (obj
->userptr
.mm
) {
13411 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
13415 return drm_gem_handle_create(file
, &obj
->base
, handle
);
13418 static int intel_user_framebuffer_dirty(struct drm_framebuffer
*fb
,
13419 struct drm_file
*file
,
13420 unsigned flags
, unsigned color
,
13421 struct drm_clip_rect
*clips
,
13422 unsigned num_clips
)
13424 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13426 i915_gem_object_flush_if_display(obj
);
13427 intel_fb_obj_flush(obj
, ORIGIN_DIRTYFB
);
13432 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
13433 .destroy
= intel_user_framebuffer_destroy
,
13434 .create_handle
= intel_user_framebuffer_create_handle
,
13435 .dirty
= intel_user_framebuffer_dirty
,
13439 u32
intel_fb_pitch_limit(struct drm_i915_private
*dev_priv
,
13440 uint64_t fb_modifier
, uint32_t pixel_format
)
13442 u32 gen
= INTEL_GEN(dev_priv
);
13445 int cpp
= drm_format_plane_cpp(pixel_format
, 0);
13447 /* "The stride in bytes must not exceed the of the size of 8K
13448 * pixels and 32K bytes."
13450 return min(8192 * cpp
, 32768);
13451 } else if (gen
>= 5 && !HAS_GMCH_DISPLAY(dev_priv
)) {
13453 } else if (gen
>= 4) {
13454 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
13458 } else if (gen
>= 3) {
13459 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
13464 /* XXX DSPC is limited to 4k tiled */
13469 static int intel_framebuffer_init(struct intel_framebuffer
*intel_fb
,
13470 struct drm_i915_gem_object
*obj
,
13471 struct drm_mode_fb_cmd2
*mode_cmd
)
13473 struct drm_i915_private
*dev_priv
= to_i915(obj
->base
.dev
);
13474 struct drm_format_name_buf format_name
;
13475 u32 pitch_limit
, stride_alignment
;
13476 unsigned int tiling
, stride
;
13479 i915_gem_object_lock(obj
);
13480 obj
->framebuffer_references
++;
13481 tiling
= i915_gem_object_get_tiling(obj
);
13482 stride
= i915_gem_object_get_stride(obj
);
13483 i915_gem_object_unlock(obj
);
13485 if (mode_cmd
->flags
& DRM_MODE_FB_MODIFIERS
) {
13487 * If there's a fence, enforce that
13488 * the fb modifier and tiling mode match.
13490 if (tiling
!= I915_TILING_NONE
&&
13491 tiling
!= intel_fb_modifier_to_tiling(mode_cmd
->modifier
[0])) {
13492 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
13496 if (tiling
== I915_TILING_X
) {
13497 mode_cmd
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
13498 } else if (tiling
== I915_TILING_Y
) {
13499 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
13504 /* Passed in modifier sanity checking. */
13505 switch (mode_cmd
->modifier
[0]) {
13506 case I915_FORMAT_MOD_Y_TILED
:
13507 case I915_FORMAT_MOD_Yf_TILED
:
13508 if (INTEL_GEN(dev_priv
) < 9) {
13509 DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n",
13510 mode_cmd
->modifier
[0]);
13513 case DRM_FORMAT_MOD_LINEAR
:
13514 case I915_FORMAT_MOD_X_TILED
:
13517 DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n",
13518 mode_cmd
->modifier
[0]);
13523 * gen2/3 display engine uses the fence if present,
13524 * so the tiling mode must match the fb modifier exactly.
13526 if (INTEL_INFO(dev_priv
)->gen
< 4 &&
13527 tiling
!= intel_fb_modifier_to_tiling(mode_cmd
->modifier
[0])) {
13528 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
13532 pitch_limit
= intel_fb_pitch_limit(dev_priv
, mode_cmd
->modifier
[0],
13533 mode_cmd
->pixel_format
);
13534 if (mode_cmd
->pitches
[0] > pitch_limit
) {
13535 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
13536 mode_cmd
->modifier
[0] != DRM_FORMAT_MOD_LINEAR
?
13537 "tiled" : "linear",
13538 mode_cmd
->pitches
[0], pitch_limit
);
13543 * If there's a fence, enforce that
13544 * the fb pitch and fence stride match.
13546 if (tiling
!= I915_TILING_NONE
&& mode_cmd
->pitches
[0] != stride
) {
13547 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
13548 mode_cmd
->pitches
[0], stride
);
13552 /* Reject formats not supported by any plane early. */
13553 switch (mode_cmd
->pixel_format
) {
13554 case DRM_FORMAT_C8
:
13555 case DRM_FORMAT_RGB565
:
13556 case DRM_FORMAT_XRGB8888
:
13557 case DRM_FORMAT_ARGB8888
:
13559 case DRM_FORMAT_XRGB1555
:
13560 if (INTEL_GEN(dev_priv
) > 3) {
13561 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13562 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13566 case DRM_FORMAT_ABGR8888
:
13567 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
) &&
13568 INTEL_GEN(dev_priv
) < 9) {
13569 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13570 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13574 case DRM_FORMAT_XBGR8888
:
13575 case DRM_FORMAT_XRGB2101010
:
13576 case DRM_FORMAT_XBGR2101010
:
13577 if (INTEL_GEN(dev_priv
) < 4) {
13578 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13579 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13583 case DRM_FORMAT_ABGR2101010
:
13584 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
)) {
13585 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13586 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13590 case DRM_FORMAT_YUYV
:
13591 case DRM_FORMAT_UYVY
:
13592 case DRM_FORMAT_YVYU
:
13593 case DRM_FORMAT_VYUY
:
13594 if (INTEL_GEN(dev_priv
) < 5 && !IS_G4X(dev_priv
)) {
13595 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13596 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13601 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
13602 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
13606 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
13607 if (mode_cmd
->offsets
[0] != 0)
13610 drm_helper_mode_fill_fb_struct(&dev_priv
->drm
,
13611 &intel_fb
->base
, mode_cmd
);
13613 stride_alignment
= intel_fb_stride_alignment(&intel_fb
->base
, 0);
13614 if (mode_cmd
->pitches
[0] & (stride_alignment
- 1)) {
13615 DRM_DEBUG_KMS("pitch (%d) must be at least %u byte aligned\n",
13616 mode_cmd
->pitches
[0], stride_alignment
);
13620 intel_fb
->obj
= obj
;
13622 ret
= intel_fill_fb_info(dev_priv
, &intel_fb
->base
);
13626 ret
= drm_framebuffer_init(obj
->base
.dev
,
13630 DRM_ERROR("framebuffer init failed %d\n", ret
);
13637 i915_gem_object_lock(obj
);
13638 obj
->framebuffer_references
--;
13639 i915_gem_object_unlock(obj
);
13643 static struct drm_framebuffer
*
13644 intel_user_framebuffer_create(struct drm_device
*dev
,
13645 struct drm_file
*filp
,
13646 const struct drm_mode_fb_cmd2
*user_mode_cmd
)
13648 struct drm_framebuffer
*fb
;
13649 struct drm_i915_gem_object
*obj
;
13650 struct drm_mode_fb_cmd2 mode_cmd
= *user_mode_cmd
;
13652 obj
= i915_gem_object_lookup(filp
, mode_cmd
.handles
[0]);
13654 return ERR_PTR(-ENOENT
);
13656 fb
= intel_framebuffer_create(obj
, &mode_cmd
);
13658 i915_gem_object_put(obj
);
13663 static void intel_atomic_state_free(struct drm_atomic_state
*state
)
13665 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
13667 drm_atomic_state_default_release(state
);
13669 i915_sw_fence_fini(&intel_state
->commit_ready
);
13674 static const struct drm_mode_config_funcs intel_mode_funcs
= {
13675 .fb_create
= intel_user_framebuffer_create
,
13676 .output_poll_changed
= intel_fbdev_output_poll_changed
,
13677 .atomic_check
= intel_atomic_check
,
13678 .atomic_commit
= intel_atomic_commit
,
13679 .atomic_state_alloc
= intel_atomic_state_alloc
,
13680 .atomic_state_clear
= intel_atomic_state_clear
,
13681 .atomic_state_free
= intel_atomic_state_free
,
13685 * intel_init_display_hooks - initialize the display modesetting hooks
13686 * @dev_priv: device private
13688 void intel_init_display_hooks(struct drm_i915_private
*dev_priv
)
13690 intel_init_cdclk_hooks(dev_priv
);
13692 if (INTEL_INFO(dev_priv
)->gen
>= 9) {
13693 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
13694 dev_priv
->display
.get_initial_plane_config
=
13695 skylake_get_initial_plane_config
;
13696 dev_priv
->display
.crtc_compute_clock
=
13697 haswell_crtc_compute_clock
;
13698 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
13699 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
13700 } else if (HAS_DDI(dev_priv
)) {
13701 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
13702 dev_priv
->display
.get_initial_plane_config
=
13703 ironlake_get_initial_plane_config
;
13704 dev_priv
->display
.crtc_compute_clock
=
13705 haswell_crtc_compute_clock
;
13706 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
13707 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
13708 } else if (HAS_PCH_SPLIT(dev_priv
)) {
13709 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
13710 dev_priv
->display
.get_initial_plane_config
=
13711 ironlake_get_initial_plane_config
;
13712 dev_priv
->display
.crtc_compute_clock
=
13713 ironlake_crtc_compute_clock
;
13714 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
13715 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
13716 } else if (IS_CHERRYVIEW(dev_priv
)) {
13717 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13718 dev_priv
->display
.get_initial_plane_config
=
13719 i9xx_get_initial_plane_config
;
13720 dev_priv
->display
.crtc_compute_clock
= chv_crtc_compute_clock
;
13721 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
13722 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13723 } else if (IS_VALLEYVIEW(dev_priv
)) {
13724 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13725 dev_priv
->display
.get_initial_plane_config
=
13726 i9xx_get_initial_plane_config
;
13727 dev_priv
->display
.crtc_compute_clock
= vlv_crtc_compute_clock
;
13728 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
13729 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13730 } else if (IS_G4X(dev_priv
)) {
13731 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13732 dev_priv
->display
.get_initial_plane_config
=
13733 i9xx_get_initial_plane_config
;
13734 dev_priv
->display
.crtc_compute_clock
= g4x_crtc_compute_clock
;
13735 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
13736 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13737 } else if (IS_PINEVIEW(dev_priv
)) {
13738 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13739 dev_priv
->display
.get_initial_plane_config
=
13740 i9xx_get_initial_plane_config
;
13741 dev_priv
->display
.crtc_compute_clock
= pnv_crtc_compute_clock
;
13742 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
13743 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13744 } else if (!IS_GEN2(dev_priv
)) {
13745 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13746 dev_priv
->display
.get_initial_plane_config
=
13747 i9xx_get_initial_plane_config
;
13748 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
13749 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
13750 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13752 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13753 dev_priv
->display
.get_initial_plane_config
=
13754 i9xx_get_initial_plane_config
;
13755 dev_priv
->display
.crtc_compute_clock
= i8xx_crtc_compute_clock
;
13756 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
13757 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13760 if (IS_GEN5(dev_priv
)) {
13761 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
13762 } else if (IS_GEN6(dev_priv
)) {
13763 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
13764 } else if (IS_IVYBRIDGE(dev_priv
)) {
13765 /* FIXME: detect B0+ stepping and use auto training */
13766 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
13767 } else if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
)) {
13768 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
13771 if (dev_priv
->info
.gen
>= 9)
13772 dev_priv
->display
.update_crtcs
= skl_update_crtcs
;
13774 dev_priv
->display
.update_crtcs
= intel_update_crtcs
;
13778 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
13780 static void quirk_ssc_force_disable(struct drm_device
*dev
)
13782 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13783 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
13784 DRM_INFO("applying lvds SSC disable quirk\n");
13788 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
13791 static void quirk_invert_brightness(struct drm_device
*dev
)
13793 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13794 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
13795 DRM_INFO("applying inverted panel brightness quirk\n");
13798 /* Some VBT's incorrectly indicate no backlight is present */
13799 static void quirk_backlight_present(struct drm_device
*dev
)
13801 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13802 dev_priv
->quirks
|= QUIRK_BACKLIGHT_PRESENT
;
13803 DRM_INFO("applying backlight present quirk\n");
13806 /* Toshiba Satellite P50-C-18C requires T12 delay to be min 800ms
13807 * which is 300 ms greater than eDP spec T12 min.
13809 static void quirk_increase_t12_delay(struct drm_device
*dev
)
13811 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13813 dev_priv
->quirks
|= QUIRK_INCREASE_T12_DELAY
;
13814 DRM_INFO("Applying T12 delay quirk\n");
13817 struct intel_quirk
{
13819 int subsystem_vendor
;
13820 int subsystem_device
;
13821 void (*hook
)(struct drm_device
*dev
);
13824 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
13825 struct intel_dmi_quirk
{
13826 void (*hook
)(struct drm_device
*dev
);
13827 const struct dmi_system_id (*dmi_id_list
)[];
13830 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
13832 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
13836 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
13838 .dmi_id_list
= &(const struct dmi_system_id
[]) {
13840 .callback
= intel_dmi_reverse_brightness
,
13841 .ident
= "NCR Corporation",
13842 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
13843 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
13846 { } /* terminating entry */
13848 .hook
= quirk_invert_brightness
,
13852 static struct intel_quirk intel_quirks
[] = {
13853 /* Lenovo U160 cannot use SSC on LVDS */
13854 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
13856 /* Sony Vaio Y cannot use SSC on LVDS */
13857 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
13859 /* Acer Aspire 5734Z must invert backlight brightness */
13860 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
13862 /* Acer/eMachines G725 */
13863 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
13865 /* Acer/eMachines e725 */
13866 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
13868 /* Acer/Packard Bell NCL20 */
13869 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
13871 /* Acer Aspire 4736Z */
13872 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
13874 /* Acer Aspire 5336 */
13875 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
13877 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
13878 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present
},
13880 /* Acer C720 Chromebook (Core i3 4005U) */
13881 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present
},
13883 /* Apple Macbook 2,1 (Core 2 T7400) */
13884 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present
},
13886 /* Apple Macbook 4,1 */
13887 { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present
},
13889 /* Toshiba CB35 Chromebook (Celeron 2955U) */
13890 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present
},
13892 /* HP Chromebook 14 (Celeron 2955U) */
13893 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present
},
13895 /* Dell Chromebook 11 */
13896 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present
},
13898 /* Dell Chromebook 11 (2015 version) */
13899 { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present
},
13901 /* Toshiba Satellite P50-C-18C */
13902 { 0x191B, 0x1179, 0xF840, quirk_increase_t12_delay
},
13905 static void intel_init_quirks(struct drm_device
*dev
)
13907 struct pci_dev
*d
= dev
->pdev
;
13910 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
13911 struct intel_quirk
*q
= &intel_quirks
[i
];
13913 if (d
->device
== q
->device
&&
13914 (d
->subsystem_vendor
== q
->subsystem_vendor
||
13915 q
->subsystem_vendor
== PCI_ANY_ID
) &&
13916 (d
->subsystem_device
== q
->subsystem_device
||
13917 q
->subsystem_device
== PCI_ANY_ID
))
13920 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
13921 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
13922 intel_dmi_quirks
[i
].hook(dev
);
13926 /* Disable the VGA plane that we never use */
13927 static void i915_disable_vga(struct drm_i915_private
*dev_priv
)
13929 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
13931 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev_priv
);
13933 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
13934 vga_get_uninterruptible(pdev
, VGA_RSRC_LEGACY_IO
);
13935 outb(SR01
, VGA_SR_INDEX
);
13936 sr1
= inb(VGA_SR_DATA
);
13937 outb(sr1
| 1<<5, VGA_SR_DATA
);
13938 vga_put(pdev
, VGA_RSRC_LEGACY_IO
);
13941 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
13942 POSTING_READ(vga_reg
);
13945 void intel_modeset_init_hw(struct drm_device
*dev
)
13947 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13949 intel_update_cdclk(dev_priv
);
13950 dev_priv
->cdclk
.logical
= dev_priv
->cdclk
.actual
= dev_priv
->cdclk
.hw
;
13952 intel_init_clock_gating(dev_priv
);
13956 * Calculate what we think the watermarks should be for the state we've read
13957 * out of the hardware and then immediately program those watermarks so that
13958 * we ensure the hardware settings match our internal state.
13960 * We can calculate what we think WM's should be by creating a duplicate of the
13961 * current state (which was constructed during hardware readout) and running it
13962 * through the atomic check code to calculate new watermark values in the
13965 static void sanitize_watermarks(struct drm_device
*dev
)
13967 struct drm_i915_private
*dev_priv
= to_i915(dev
);
13968 struct drm_atomic_state
*state
;
13969 struct intel_atomic_state
*intel_state
;
13970 struct drm_crtc
*crtc
;
13971 struct drm_crtc_state
*cstate
;
13972 struct drm_modeset_acquire_ctx ctx
;
13976 /* Only supported on platforms that use atomic watermark design */
13977 if (!dev_priv
->display
.optimize_watermarks
)
13981 * We need to hold connection_mutex before calling duplicate_state so
13982 * that the connector loop is protected.
13984 drm_modeset_acquire_init(&ctx
, 0);
13986 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
13987 if (ret
== -EDEADLK
) {
13988 drm_modeset_backoff(&ctx
);
13990 } else if (WARN_ON(ret
)) {
13994 state
= drm_atomic_helper_duplicate_state(dev
, &ctx
);
13995 if (WARN_ON(IS_ERR(state
)))
13998 intel_state
= to_intel_atomic_state(state
);
14001 * Hardware readout is the only time we don't want to calculate
14002 * intermediate watermarks (since we don't trust the current
14005 if (!HAS_GMCH_DISPLAY(dev_priv
))
14006 intel_state
->skip_intermediate_wm
= true;
14008 ret
= intel_atomic_check(dev
, state
);
14011 * If we fail here, it means that the hardware appears to be
14012 * programmed in a way that shouldn't be possible, given our
14013 * understanding of watermark requirements. This might mean a
14014 * mistake in the hardware readout code or a mistake in the
14015 * watermark calculations for a given platform. Raise a WARN
14016 * so that this is noticeable.
14018 * If this actually happens, we'll have to just leave the
14019 * BIOS-programmed watermarks untouched and hope for the best.
14021 WARN(true, "Could not determine valid watermarks for inherited state\n");
14025 /* Write calculated watermark values back */
14026 for_each_new_crtc_in_state(state
, crtc
, cstate
, i
) {
14027 struct intel_crtc_state
*cs
= to_intel_crtc_state(cstate
);
14029 cs
->wm
.need_postvbl_update
= true;
14030 dev_priv
->display
.optimize_watermarks(intel_state
, cs
);
14034 drm_atomic_state_put(state
);
14036 drm_modeset_drop_locks(&ctx
);
14037 drm_modeset_acquire_fini(&ctx
);
14040 int intel_modeset_init(struct drm_device
*dev
)
14042 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14043 struct i915_ggtt
*ggtt
= &dev_priv
->ggtt
;
14045 struct intel_crtc
*crtc
;
14047 drm_mode_config_init(dev
);
14049 dev
->mode_config
.min_width
= 0;
14050 dev
->mode_config
.min_height
= 0;
14052 dev
->mode_config
.preferred_depth
= 24;
14053 dev
->mode_config
.prefer_shadow
= 1;
14055 dev
->mode_config
.allow_fb_modifiers
= true;
14057 dev
->mode_config
.funcs
= &intel_mode_funcs
;
14059 init_llist_head(&dev_priv
->atomic_helper
.free_list
);
14060 INIT_WORK(&dev_priv
->atomic_helper
.free_work
,
14061 intel_atomic_helper_free_state_worker
);
14063 intel_init_quirks(dev
);
14065 intel_init_pm(dev_priv
);
14067 if (INTEL_INFO(dev_priv
)->num_pipes
== 0)
14071 * There may be no VBT; and if the BIOS enabled SSC we can
14072 * just keep using it to avoid unnecessary flicker. Whereas if the
14073 * BIOS isn't using it, don't assume it will work even if the VBT
14074 * indicates as much.
14076 if (HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
)) {
14077 bool bios_lvds_use_ssc
= !!(I915_READ(PCH_DREF_CONTROL
) &
14080 if (dev_priv
->vbt
.lvds_use_ssc
!= bios_lvds_use_ssc
) {
14081 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
14082 bios_lvds_use_ssc
? "en" : "dis",
14083 dev_priv
->vbt
.lvds_use_ssc
? "en" : "dis");
14084 dev_priv
->vbt
.lvds_use_ssc
= bios_lvds_use_ssc
;
14088 if (IS_GEN2(dev_priv
)) {
14089 dev
->mode_config
.max_width
= 2048;
14090 dev
->mode_config
.max_height
= 2048;
14091 } else if (IS_GEN3(dev_priv
)) {
14092 dev
->mode_config
.max_width
= 4096;
14093 dev
->mode_config
.max_height
= 4096;
14095 dev
->mode_config
.max_width
= 8192;
14096 dev
->mode_config
.max_height
= 8192;
14099 if (IS_I845G(dev_priv
) || IS_I865G(dev_priv
)) {
14100 dev
->mode_config
.cursor_width
= IS_I845G(dev_priv
) ? 64 : 512;
14101 dev
->mode_config
.cursor_height
= 1023;
14102 } else if (IS_GEN2(dev_priv
)) {
14103 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
14104 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
14106 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
14107 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
14110 dev
->mode_config
.fb_base
= ggtt
->mappable_base
;
14112 DRM_DEBUG_KMS("%d display pipe%s available.\n",
14113 INTEL_INFO(dev_priv
)->num_pipes
,
14114 INTEL_INFO(dev_priv
)->num_pipes
> 1 ? "s" : "");
14116 for_each_pipe(dev_priv
, pipe
) {
14119 ret
= intel_crtc_init(dev_priv
, pipe
);
14121 drm_mode_config_cleanup(dev
);
14126 intel_shared_dpll_init(dev
);
14128 intel_update_czclk(dev_priv
);
14129 intel_modeset_init_hw(dev
);
14131 if (dev_priv
->max_cdclk_freq
== 0)
14132 intel_update_max_cdclk(dev_priv
);
14134 /* Just disable it once at startup */
14135 i915_disable_vga(dev_priv
);
14136 intel_setup_outputs(dev_priv
);
14138 drm_modeset_lock_all(dev
);
14139 intel_modeset_setup_hw_state(dev
, dev
->mode_config
.acquire_ctx
);
14140 drm_modeset_unlock_all(dev
);
14142 for_each_intel_crtc(dev
, crtc
) {
14143 struct intel_initial_plane_config plane_config
= {};
14149 * Note that reserving the BIOS fb up front prevents us
14150 * from stuffing other stolen allocations like the ring
14151 * on top. This prevents some ugliness at boot time, and
14152 * can even allow for smooth boot transitions if the BIOS
14153 * fb is large enough for the active pipe configuration.
14155 dev_priv
->display
.get_initial_plane_config(crtc
,
14159 * If the fb is shared between multiple heads, we'll
14160 * just get the first one.
14162 intel_find_initial_plane_obj(crtc
, &plane_config
);
14166 * Make sure hardware watermarks really match the state we read out.
14167 * Note that we need to do this after reconstructing the BIOS fb's
14168 * since the watermark calculation done here will use pstate->fb.
14170 if (!HAS_GMCH_DISPLAY(dev_priv
))
14171 sanitize_watermarks(dev
);
14176 void i830_enable_pipe(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
14178 /* 640x480@60Hz, ~25175 kHz */
14179 struct dpll clock
= {
14189 WARN_ON(i9xx_calc_dpll_params(48000, &clock
) != 25154);
14191 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
14192 pipe_name(pipe
), clock
.vco
, clock
.dot
);
14194 fp
= i9xx_dpll_compute_fp(&clock
);
14195 dpll
= (I915_READ(DPLL(pipe
)) & DPLL_DVO_2X_MODE
) |
14196 DPLL_VGA_MODE_DIS
|
14197 ((clock
.p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
) |
14198 PLL_P2_DIVIDE_BY_4
|
14199 PLL_REF_INPUT_DREFCLK
|
14202 I915_WRITE(FP0(pipe
), fp
);
14203 I915_WRITE(FP1(pipe
), fp
);
14205 I915_WRITE(HTOTAL(pipe
), (640 - 1) | ((800 - 1) << 16));
14206 I915_WRITE(HBLANK(pipe
), (640 - 1) | ((800 - 1) << 16));
14207 I915_WRITE(HSYNC(pipe
), (656 - 1) | ((752 - 1) << 16));
14208 I915_WRITE(VTOTAL(pipe
), (480 - 1) | ((525 - 1) << 16));
14209 I915_WRITE(VBLANK(pipe
), (480 - 1) | ((525 - 1) << 16));
14210 I915_WRITE(VSYNC(pipe
), (490 - 1) | ((492 - 1) << 16));
14211 I915_WRITE(PIPESRC(pipe
), ((640 - 1) << 16) | (480 - 1));
14214 * Apparently we need to have VGA mode enabled prior to changing
14215 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
14216 * dividers, even though the register value does change.
14218 I915_WRITE(DPLL(pipe
), dpll
& ~DPLL_VGA_MODE_DIS
);
14219 I915_WRITE(DPLL(pipe
), dpll
);
14221 /* Wait for the clocks to stabilize. */
14222 POSTING_READ(DPLL(pipe
));
14225 /* The pixel multiplier can only be updated once the
14226 * DPLL is enabled and the clocks are stable.
14228 * So write it again.
14230 I915_WRITE(DPLL(pipe
), dpll
);
14232 /* We do this three times for luck */
14233 for (i
= 0; i
< 3 ; i
++) {
14234 I915_WRITE(DPLL(pipe
), dpll
);
14235 POSTING_READ(DPLL(pipe
));
14236 udelay(150); /* wait for warmup */
14239 I915_WRITE(PIPECONF(pipe
), PIPECONF_ENABLE
| PIPECONF_PROGRESSIVE
);
14240 POSTING_READ(PIPECONF(pipe
));
14243 void i830_disable_pipe(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
14245 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
14248 assert_plane_disabled(dev_priv
, PLANE_A
);
14249 assert_plane_disabled(dev_priv
, PLANE_B
);
14251 I915_WRITE(PIPECONF(pipe
), 0);
14252 POSTING_READ(PIPECONF(pipe
));
14254 if (wait_for(pipe_dsl_stopped(dev_priv
, pipe
), 100))
14255 DRM_ERROR("pipe %c off wait timed out\n", pipe_name(pipe
));
14257 I915_WRITE(DPLL(pipe
), DPLL_VGA_MODE_DIS
);
14258 POSTING_READ(DPLL(pipe
));
14262 intel_check_plane_mapping(struct intel_crtc
*crtc
)
14264 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
14267 if (INTEL_INFO(dev_priv
)->num_pipes
== 1)
14270 val
= I915_READ(DSPCNTR(!crtc
->plane
));
14272 if ((val
& DISPLAY_PLANE_ENABLE
) &&
14273 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
14279 static bool intel_crtc_has_encoders(struct intel_crtc
*crtc
)
14281 struct drm_device
*dev
= crtc
->base
.dev
;
14282 struct intel_encoder
*encoder
;
14284 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
14290 static struct intel_connector
*intel_encoder_find_connector(struct intel_encoder
*encoder
)
14292 struct drm_device
*dev
= encoder
->base
.dev
;
14293 struct intel_connector
*connector
;
14295 for_each_connector_on_encoder(dev
, &encoder
->base
, connector
)
14301 static bool has_pch_trancoder(struct drm_i915_private
*dev_priv
,
14302 enum transcoder pch_transcoder
)
14304 return HAS_PCH_IBX(dev_priv
) || HAS_PCH_CPT(dev_priv
) ||
14305 (HAS_PCH_LPT_H(dev_priv
) && pch_transcoder
== TRANSCODER_A
);
14308 static void intel_sanitize_crtc(struct intel_crtc
*crtc
,
14309 struct drm_modeset_acquire_ctx
*ctx
)
14311 struct drm_device
*dev
= crtc
->base
.dev
;
14312 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14313 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
14315 /* Clear any frame start delays used for debugging left by the BIOS */
14316 if (!transcoder_is_dsi(cpu_transcoder
)) {
14317 i915_reg_t reg
= PIPECONF(cpu_transcoder
);
14320 I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
14323 /* restore vblank interrupts to correct state */
14324 drm_crtc_vblank_reset(&crtc
->base
);
14325 if (crtc
->active
) {
14326 struct intel_plane
*plane
;
14328 drm_crtc_vblank_on(&crtc
->base
);
14330 /* Disable everything but the primary plane */
14331 for_each_intel_plane_on_crtc(dev
, crtc
, plane
) {
14332 if (plane
->base
.type
== DRM_PLANE_TYPE_PRIMARY
)
14335 trace_intel_disable_plane(&plane
->base
, crtc
);
14336 plane
->disable_plane(plane
, crtc
);
14340 /* We need to sanitize the plane -> pipe mapping first because this will
14341 * disable the crtc (and hence change the state) if it is wrong. Note
14342 * that gen4+ has a fixed plane -> pipe mapping. */
14343 if (INTEL_GEN(dev_priv
) < 4 && !intel_check_plane_mapping(crtc
)) {
14346 DRM_DEBUG_KMS("[CRTC:%d:%s] wrong plane connection detected!\n",
14347 crtc
->base
.base
.id
, crtc
->base
.name
);
14349 /* Pipe has the wrong plane attached and the plane is active.
14350 * Temporarily change the plane mapping and disable everything
14352 plane
= crtc
->plane
;
14353 crtc
->base
.primary
->state
->visible
= true;
14354 crtc
->plane
= !plane
;
14355 intel_crtc_disable_noatomic(&crtc
->base
, ctx
);
14356 crtc
->plane
= plane
;
14359 /* Adjust the state of the output pipe according to whether we
14360 * have active connectors/encoders. */
14361 if (crtc
->active
&& !intel_crtc_has_encoders(crtc
))
14362 intel_crtc_disable_noatomic(&crtc
->base
, ctx
);
14364 if (crtc
->active
|| HAS_GMCH_DISPLAY(dev_priv
)) {
14366 * We start out with underrun reporting disabled to avoid races.
14367 * For correct bookkeeping mark this on active crtcs.
14369 * Also on gmch platforms we dont have any hardware bits to
14370 * disable the underrun reporting. Which means we need to start
14371 * out with underrun reporting disabled also on inactive pipes,
14372 * since otherwise we'll complain about the garbage we read when
14373 * e.g. coming up after runtime pm.
14375 * No protection against concurrent access is required - at
14376 * worst a fifo underrun happens which also sets this to false.
14378 crtc
->cpu_fifo_underrun_disabled
= true;
14380 * We track the PCH trancoder underrun reporting state
14381 * within the crtc. With crtc for pipe A housing the underrun
14382 * reporting state for PCH transcoder A, crtc for pipe B housing
14383 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
14384 * and marking underrun reporting as disabled for the non-existing
14385 * PCH transcoders B and C would prevent enabling the south
14386 * error interrupt (see cpt_can_enable_serr_int()).
14388 if (has_pch_trancoder(dev_priv
, (enum transcoder
)crtc
->pipe
))
14389 crtc
->pch_fifo_underrun_disabled
= true;
14393 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
14395 struct intel_connector
*connector
;
14397 /* We need to check both for a crtc link (meaning that the
14398 * encoder is active and trying to read from a pipe) and the
14399 * pipe itself being active. */
14400 bool has_active_crtc
= encoder
->base
.crtc
&&
14401 to_intel_crtc(encoder
->base
.crtc
)->active
;
14403 connector
= intel_encoder_find_connector(encoder
);
14404 if (connector
&& !has_active_crtc
) {
14405 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
14406 encoder
->base
.base
.id
,
14407 encoder
->base
.name
);
14409 /* Connector is active, but has no active pipe. This is
14410 * fallout from our resume register restoring. Disable
14411 * the encoder manually again. */
14412 if (encoder
->base
.crtc
) {
14413 struct drm_crtc_state
*crtc_state
= encoder
->base
.crtc
->state
;
14415 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
14416 encoder
->base
.base
.id
,
14417 encoder
->base
.name
);
14418 encoder
->disable(encoder
, to_intel_crtc_state(crtc_state
), connector
->base
.state
);
14419 if (encoder
->post_disable
)
14420 encoder
->post_disable(encoder
, to_intel_crtc_state(crtc_state
), connector
->base
.state
);
14422 encoder
->base
.crtc
= NULL
;
14424 /* Inconsistent output/port/pipe state happens presumably due to
14425 * a bug in one of the get_hw_state functions. Or someplace else
14426 * in our code, like the register restore mess on resume. Clamp
14427 * things to off as a safer default. */
14429 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
14430 connector
->base
.encoder
= NULL
;
14432 /* Enabled encoders without active connectors will be fixed in
14433 * the crtc fixup. */
14436 void i915_redisable_vga_power_on(struct drm_i915_private
*dev_priv
)
14438 i915_reg_t vga_reg
= i915_vgacntrl_reg(dev_priv
);
14440 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
14441 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
14442 i915_disable_vga(dev_priv
);
14446 void i915_redisable_vga(struct drm_i915_private
*dev_priv
)
14448 /* This function can be called both from intel_modeset_setup_hw_state or
14449 * at a very early point in our resume sequence, where the power well
14450 * structures are not yet restored. Since this function is at a very
14451 * paranoid "someone might have enabled VGA while we were not looking"
14452 * level, just check if the power well is enabled instead of trying to
14453 * follow the "don't touch the power well if we don't need it" policy
14454 * the rest of the driver uses. */
14455 if (!intel_display_power_get_if_enabled(dev_priv
, POWER_DOMAIN_VGA
))
14458 i915_redisable_vga_power_on(dev_priv
);
14460 intel_display_power_put(dev_priv
, POWER_DOMAIN_VGA
);
14463 static bool primary_get_hw_state(struct intel_plane
*plane
)
14465 struct drm_i915_private
*dev_priv
= to_i915(plane
->base
.dev
);
14467 return I915_READ(DSPCNTR(plane
->plane
)) & DISPLAY_PLANE_ENABLE
;
14470 /* FIXME read out full plane state for all planes */
14471 static void readout_plane_state(struct intel_crtc
*crtc
)
14473 struct intel_plane
*primary
= to_intel_plane(crtc
->base
.primary
);
14476 visible
= crtc
->active
&& primary_get_hw_state(primary
);
14478 intel_set_plane_visible(to_intel_crtc_state(crtc
->base
.state
),
14479 to_intel_plane_state(primary
->base
.state
),
14483 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
14485 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14487 struct intel_crtc
*crtc
;
14488 struct intel_encoder
*encoder
;
14489 struct intel_connector
*connector
;
14490 struct drm_connector_list_iter conn_iter
;
14493 dev_priv
->active_crtcs
= 0;
14495 for_each_intel_crtc(dev
, crtc
) {
14496 struct intel_crtc_state
*crtc_state
=
14497 to_intel_crtc_state(crtc
->base
.state
);
14499 __drm_atomic_helper_crtc_destroy_state(&crtc_state
->base
);
14500 memset(crtc_state
, 0, sizeof(*crtc_state
));
14501 crtc_state
->base
.crtc
= &crtc
->base
;
14503 crtc_state
->base
.active
= crtc_state
->base
.enable
=
14504 dev_priv
->display
.get_pipe_config(crtc
, crtc_state
);
14506 crtc
->base
.enabled
= crtc_state
->base
.enable
;
14507 crtc
->active
= crtc_state
->base
.active
;
14509 if (crtc_state
->base
.active
)
14510 dev_priv
->active_crtcs
|= 1 << crtc
->pipe
;
14512 readout_plane_state(crtc
);
14514 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
14515 crtc
->base
.base
.id
, crtc
->base
.name
,
14516 enableddisabled(crtc_state
->base
.active
));
14519 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
14520 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
14522 pll
->on
= pll
->funcs
.get_hw_state(dev_priv
, pll
,
14523 &pll
->state
.hw_state
);
14524 pll
->state
.crtc_mask
= 0;
14525 for_each_intel_crtc(dev
, crtc
) {
14526 struct intel_crtc_state
*crtc_state
=
14527 to_intel_crtc_state(crtc
->base
.state
);
14529 if (crtc_state
->base
.active
&&
14530 crtc_state
->shared_dpll
== pll
)
14531 pll
->state
.crtc_mask
|= 1 << crtc
->pipe
;
14533 pll
->active_mask
= pll
->state
.crtc_mask
;
14535 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
14536 pll
->name
, pll
->state
.crtc_mask
, pll
->on
);
14539 for_each_intel_encoder(dev
, encoder
) {
14542 if (encoder
->get_hw_state(encoder
, &pipe
)) {
14543 struct intel_crtc_state
*crtc_state
;
14545 crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
14546 crtc_state
= to_intel_crtc_state(crtc
->base
.state
);
14548 encoder
->base
.crtc
= &crtc
->base
;
14549 crtc_state
->output_types
|= 1 << encoder
->type
;
14550 encoder
->get_config(encoder
, crtc_state
);
14552 encoder
->base
.crtc
= NULL
;
14555 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
14556 encoder
->base
.base
.id
, encoder
->base
.name
,
14557 enableddisabled(encoder
->base
.crtc
),
14561 drm_connector_list_iter_begin(dev
, &conn_iter
);
14562 for_each_intel_connector_iter(connector
, &conn_iter
) {
14563 if (connector
->get_hw_state(connector
)) {
14564 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
14566 encoder
= connector
->encoder
;
14567 connector
->base
.encoder
= &encoder
->base
;
14569 if (encoder
->base
.crtc
&&
14570 encoder
->base
.crtc
->state
->active
) {
14572 * This has to be done during hardware readout
14573 * because anything calling .crtc_disable may
14574 * rely on the connector_mask being accurate.
14576 encoder
->base
.crtc
->state
->connector_mask
|=
14577 1 << drm_connector_index(&connector
->base
);
14578 encoder
->base
.crtc
->state
->encoder_mask
|=
14579 1 << drm_encoder_index(&encoder
->base
);
14583 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
14584 connector
->base
.encoder
= NULL
;
14586 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
14587 connector
->base
.base
.id
, connector
->base
.name
,
14588 enableddisabled(connector
->base
.encoder
));
14590 drm_connector_list_iter_end(&conn_iter
);
14592 for_each_intel_crtc(dev
, crtc
) {
14593 struct intel_crtc_state
*crtc_state
=
14594 to_intel_crtc_state(crtc
->base
.state
);
14597 memset(&crtc
->base
.mode
, 0, sizeof(crtc
->base
.mode
));
14598 if (crtc_state
->base
.active
) {
14599 intel_mode_from_pipe_config(&crtc
->base
.mode
, crtc_state
);
14600 intel_mode_from_pipe_config(&crtc_state
->base
.adjusted_mode
, crtc_state
);
14601 WARN_ON(drm_atomic_set_mode_for_crtc(crtc
->base
.state
, &crtc
->base
.mode
));
14604 * The initial mode needs to be set in order to keep
14605 * the atomic core happy. It wants a valid mode if the
14606 * crtc's enabled, so we do the above call.
14608 * But we don't set all the derived state fully, hence
14609 * set a flag to indicate that a full recalculation is
14610 * needed on the next commit.
14612 crtc_state
->base
.mode
.private_flags
= I915_MODE_FLAG_INHERITED
;
14614 intel_crtc_compute_pixel_rate(crtc_state
);
14616 if (INTEL_GEN(dev_priv
) >= 9 || IS_BROADWELL(dev_priv
) ||
14617 IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
14618 pixclk
= crtc_state
->pixel_rate
;
14620 WARN_ON(dev_priv
->display
.modeset_calc_cdclk
);
14622 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
14623 if (IS_BROADWELL(dev_priv
) && crtc_state
->ips_enabled
)
14624 pixclk
= DIV_ROUND_UP(pixclk
* 100, 95);
14626 drm_calc_timestamping_constants(&crtc
->base
,
14627 &crtc_state
->base
.adjusted_mode
);
14628 update_scanline_offset(crtc
);
14631 dev_priv
->min_pixclk
[crtc
->pipe
] = pixclk
;
14633 intel_pipe_config_sanity_check(dev_priv
, crtc_state
);
14638 get_encoder_power_domains(struct drm_i915_private
*dev_priv
)
14640 struct intel_encoder
*encoder
;
14642 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
14644 enum intel_display_power_domain domain
;
14646 if (!encoder
->get_power_domains
)
14649 get_domains
= encoder
->get_power_domains(encoder
);
14650 for_each_power_domain(domain
, get_domains
)
14651 intel_display_power_get(dev_priv
, domain
);
14655 /* Scan out the current hw modeset state,
14656 * and sanitizes it to the current state
14659 intel_modeset_setup_hw_state(struct drm_device
*dev
,
14660 struct drm_modeset_acquire_ctx
*ctx
)
14662 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14664 struct intel_crtc
*crtc
;
14665 struct intel_encoder
*encoder
;
14668 intel_modeset_readout_hw_state(dev
);
14670 /* HW state is read out, now we need to sanitize this mess. */
14671 get_encoder_power_domains(dev_priv
);
14673 for_each_intel_encoder(dev
, encoder
) {
14674 intel_sanitize_encoder(encoder
);
14677 for_each_pipe(dev_priv
, pipe
) {
14678 crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
14680 intel_sanitize_crtc(crtc
, ctx
);
14681 intel_dump_pipe_config(crtc
, crtc
->config
,
14682 "[setup_hw_state]");
14685 intel_modeset_update_connector_atomic_state(dev
);
14687 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
14688 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
14690 if (!pll
->on
|| pll
->active_mask
)
14693 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
14695 pll
->funcs
.disable(dev_priv
, pll
);
14699 if (IS_G4X(dev_priv
)) {
14700 g4x_wm_get_hw_state(dev
);
14701 g4x_wm_sanitize(dev_priv
);
14702 } else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
)) {
14703 vlv_wm_get_hw_state(dev
);
14704 vlv_wm_sanitize(dev_priv
);
14705 } else if (IS_GEN9(dev_priv
)) {
14706 skl_wm_get_hw_state(dev
);
14707 } else if (HAS_PCH_SPLIT(dev_priv
)) {
14708 ilk_wm_get_hw_state(dev
);
14711 for_each_intel_crtc(dev
, crtc
) {
14714 put_domains
= modeset_get_crtc_power_domains(&crtc
->base
, crtc
->config
);
14715 if (WARN_ON(put_domains
))
14716 modeset_put_power_domains(dev_priv
, put_domains
);
14718 intel_display_set_init_power(dev_priv
, false);
14720 intel_power_domains_verify_state(dev_priv
);
14722 intel_fbc_init_pipe_state(dev_priv
);
14725 void intel_display_resume(struct drm_device
*dev
)
14727 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14728 struct drm_atomic_state
*state
= dev_priv
->modeset_restore_state
;
14729 struct drm_modeset_acquire_ctx ctx
;
14732 dev_priv
->modeset_restore_state
= NULL
;
14734 state
->acquire_ctx
= &ctx
;
14736 drm_modeset_acquire_init(&ctx
, 0);
14739 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
14740 if (ret
!= -EDEADLK
)
14743 drm_modeset_backoff(&ctx
);
14747 ret
= __intel_display_resume(dev
, state
, &ctx
);
14749 drm_modeset_drop_locks(&ctx
);
14750 drm_modeset_acquire_fini(&ctx
);
14753 DRM_ERROR("Restoring old state failed with %i\n", ret
);
14755 drm_atomic_state_put(state
);
14758 void intel_modeset_gem_init(struct drm_device
*dev
)
14760 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14762 intel_init_gt_powersave(dev_priv
);
14764 intel_setup_overlay(dev_priv
);
14767 int intel_connector_register(struct drm_connector
*connector
)
14769 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
14772 ret
= intel_backlight_device_register(intel_connector
);
14782 void intel_connector_unregister(struct drm_connector
*connector
)
14784 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
14786 intel_backlight_device_unregister(intel_connector
);
14787 intel_panel_destroy_backlight(connector
);
14790 void intel_modeset_cleanup(struct drm_device
*dev
)
14792 struct drm_i915_private
*dev_priv
= to_i915(dev
);
14794 flush_work(&dev_priv
->atomic_helper
.free_work
);
14795 WARN_ON(!llist_empty(&dev_priv
->atomic_helper
.free_list
));
14797 intel_disable_gt_powersave(dev_priv
);
14800 * Interrupts and polling as the first thing to avoid creating havoc.
14801 * Too much stuff here (turning of connectors, ...) would
14802 * experience fancy races otherwise.
14804 intel_irq_uninstall(dev_priv
);
14807 * Due to the hpd irq storm handling the hotplug work can re-arm the
14808 * poll handlers. Hence disable polling after hpd handling is shut down.
14810 drm_kms_helper_poll_fini(dev
);
14812 /* poll work can call into fbdev, hence clean that up afterwards */
14813 intel_fbdev_fini(dev_priv
);
14815 intel_unregister_dsm_handler();
14817 intel_fbc_global_disable(dev_priv
);
14819 /* flush any delayed tasks or pending work */
14820 flush_scheduled_work();
14822 drm_mode_config_cleanup(dev
);
14824 intel_cleanup_overlay(dev_priv
);
14826 intel_cleanup_gt_powersave(dev_priv
);
14828 intel_teardown_gmbus(dev_priv
);
14831 void intel_connector_attach_encoder(struct intel_connector
*connector
,
14832 struct intel_encoder
*encoder
)
14834 connector
->encoder
= encoder
;
14835 drm_mode_connector_attach_encoder(&connector
->base
,
14840 * set vga decode state - true == enable VGA decode
14842 int intel_modeset_vga_set_state(struct drm_i915_private
*dev_priv
, bool state
)
14844 unsigned reg
= INTEL_GEN(dev_priv
) >= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
14847 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
14848 DRM_ERROR("failed to read control word\n");
14852 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
14856 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
14858 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
14860 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
14861 DRM_ERROR("failed to write control word\n");
14868 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
14870 struct intel_display_error_state
{
14872 u32 power_well_driver
;
14874 int num_transcoders
;
14876 struct intel_cursor_error_state
{
14881 } cursor
[I915_MAX_PIPES
];
14883 struct intel_pipe_error_state
{
14884 bool power_domain_on
;
14887 } pipe
[I915_MAX_PIPES
];
14889 struct intel_plane_error_state
{
14897 } plane
[I915_MAX_PIPES
];
14899 struct intel_transcoder_error_state
{
14900 bool power_domain_on
;
14901 enum transcoder cpu_transcoder
;
14914 struct intel_display_error_state
*
14915 intel_display_capture_error_state(struct drm_i915_private
*dev_priv
)
14917 struct intel_display_error_state
*error
;
14918 int transcoders
[] = {
14926 if (INTEL_INFO(dev_priv
)->num_pipes
== 0)
14929 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
14933 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
14934 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
14936 for_each_pipe(dev_priv
, i
) {
14937 error
->pipe
[i
].power_domain_on
=
14938 __intel_display_power_is_enabled(dev_priv
,
14939 POWER_DOMAIN_PIPE(i
));
14940 if (!error
->pipe
[i
].power_domain_on
)
14943 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
14944 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
14945 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
14947 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
14948 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
14949 if (INTEL_GEN(dev_priv
) <= 3) {
14950 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
14951 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
14953 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
14954 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
14955 if (INTEL_GEN(dev_priv
) >= 4) {
14956 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
14957 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
14960 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
14962 if (HAS_GMCH_DISPLAY(dev_priv
))
14963 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
14966 /* Note: this does not include DSI transcoders. */
14967 error
->num_transcoders
= INTEL_INFO(dev_priv
)->num_pipes
;
14968 if (HAS_DDI(dev_priv
))
14969 error
->num_transcoders
++; /* Account for eDP. */
14971 for (i
= 0; i
< error
->num_transcoders
; i
++) {
14972 enum transcoder cpu_transcoder
= transcoders
[i
];
14974 error
->transcoder
[i
].power_domain_on
=
14975 __intel_display_power_is_enabled(dev_priv
,
14976 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
14977 if (!error
->transcoder
[i
].power_domain_on
)
14980 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
14982 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
14983 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
14984 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
14985 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
14986 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
14987 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
14988 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
14994 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
14997 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
14998 struct intel_display_error_state
*error
)
15000 struct drm_i915_private
*dev_priv
= m
->i915
;
15006 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev_priv
)->num_pipes
);
15007 if (IS_HASWELL(dev_priv
) || IS_BROADWELL(dev_priv
))
15008 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
15009 error
->power_well_driver
);
15010 for_each_pipe(dev_priv
, i
) {
15011 err_printf(m
, "Pipe [%d]:\n", i
);
15012 err_printf(m
, " Power: %s\n",
15013 onoff(error
->pipe
[i
].power_domain_on
));
15014 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
15015 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
15017 err_printf(m
, "Plane [%d]:\n", i
);
15018 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
15019 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
15020 if (INTEL_GEN(dev_priv
) <= 3) {
15021 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
15022 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
15024 if (INTEL_GEN(dev_priv
) <= 7 && !IS_HASWELL(dev_priv
))
15025 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
15026 if (INTEL_GEN(dev_priv
) >= 4) {
15027 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
15028 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
15031 err_printf(m
, "Cursor [%d]:\n", i
);
15032 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
15033 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
15034 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
15037 for (i
= 0; i
< error
->num_transcoders
; i
++) {
15038 err_printf(m
, "CPU transcoder: %s\n",
15039 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
15040 err_printf(m
, " Power: %s\n",
15041 onoff(error
->transcoder
[i
].power_domain_on
));
15042 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
15043 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
15044 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
15045 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
15046 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
15047 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
15048 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);