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 <drm/i915_drm.h>
39 #include "i915_trace.h"
40 #include <drm/drm_dp_helper.h>
41 #include <drm/drm_crtc_helper.h>
42 #include <drm/drm_plane_helper.h>
43 #include <drm/drm_rect.h>
44 #include <linux/dma_remapping.h>
46 /* Primary plane formats supported by all gen */
47 #define COMMON_PRIMARY_FORMATS \
50 DRM_FORMAT_XRGB8888, \
53 /* Primary plane formats for gen <= 3 */
54 static const uint32_t intel_primary_formats_gen2
[] = {
55 COMMON_PRIMARY_FORMATS
,
60 /* Primary plane formats for gen >= 4 */
61 static const uint32_t intel_primary_formats_gen4
[] = {
62 COMMON_PRIMARY_FORMATS
, \
65 DRM_FORMAT_XRGB2101010
,
66 DRM_FORMAT_ARGB2101010
,
67 DRM_FORMAT_XBGR2101010
,
68 DRM_FORMAT_ABGR2101010
,
72 static const uint32_t intel_cursor_formats
[] = {
76 #define DIV_ROUND_CLOSEST_ULL(ll, d) \
77 ({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; })
79 static void intel_increase_pllclock(struct drm_device
*dev
,
81 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
, bool on
);
83 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
84 struct intel_crtc_config
*pipe_config
);
85 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
86 struct intel_crtc_config
*pipe_config
);
88 static int intel_set_mode(struct drm_crtc
*crtc
, struct drm_display_mode
*mode
,
89 int x
, int y
, struct drm_framebuffer
*old_fb
);
90 static int intel_framebuffer_init(struct drm_device
*dev
,
91 struct intel_framebuffer
*ifb
,
92 struct drm_mode_fb_cmd2
*mode_cmd
,
93 struct drm_i915_gem_object
*obj
);
94 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
);
95 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
);
96 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
97 struct intel_link_m_n
*m_n
,
98 struct intel_link_m_n
*m2_n2
);
99 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
);
100 static void haswell_set_pipeconf(struct drm_crtc
*crtc
);
101 static void intel_set_pipe_csc(struct drm_crtc
*crtc
);
102 static void vlv_prepare_pll(struct intel_crtc
*crtc
);
103 static void chv_prepare_pll(struct intel_crtc
*crtc
);
105 static struct intel_encoder
*intel_find_encoder(struct intel_connector
*connector
, int pipe
)
107 if (!connector
->mst_port
)
108 return connector
->encoder
;
110 return &connector
->mst_port
->mst_encoders
[pipe
]->base
;
119 int p2_slow
, p2_fast
;
122 typedef struct intel_limit intel_limit_t
;
124 intel_range_t dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
129 intel_pch_rawclk(struct drm_device
*dev
)
131 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
133 WARN_ON(!HAS_PCH_SPLIT(dev
));
135 return I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
;
138 static inline u32
/* units of 100MHz */
139 intel_fdi_link_freq(struct drm_device
*dev
)
142 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
143 return (I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2;
148 static const intel_limit_t intel_limits_i8xx_dac
= {
149 .dot
= { .min
= 25000, .max
= 350000 },
150 .vco
= { .min
= 908000, .max
= 1512000 },
151 .n
= { .min
= 2, .max
= 16 },
152 .m
= { .min
= 96, .max
= 140 },
153 .m1
= { .min
= 18, .max
= 26 },
154 .m2
= { .min
= 6, .max
= 16 },
155 .p
= { .min
= 4, .max
= 128 },
156 .p1
= { .min
= 2, .max
= 33 },
157 .p2
= { .dot_limit
= 165000,
158 .p2_slow
= 4, .p2_fast
= 2 },
161 static const intel_limit_t intel_limits_i8xx_dvo
= {
162 .dot
= { .min
= 25000, .max
= 350000 },
163 .vco
= { .min
= 908000, .max
= 1512000 },
164 .n
= { .min
= 2, .max
= 16 },
165 .m
= { .min
= 96, .max
= 140 },
166 .m1
= { .min
= 18, .max
= 26 },
167 .m2
= { .min
= 6, .max
= 16 },
168 .p
= { .min
= 4, .max
= 128 },
169 .p1
= { .min
= 2, .max
= 33 },
170 .p2
= { .dot_limit
= 165000,
171 .p2_slow
= 4, .p2_fast
= 4 },
174 static const intel_limit_t intel_limits_i8xx_lvds
= {
175 .dot
= { .min
= 25000, .max
= 350000 },
176 .vco
= { .min
= 908000, .max
= 1512000 },
177 .n
= { .min
= 2, .max
= 16 },
178 .m
= { .min
= 96, .max
= 140 },
179 .m1
= { .min
= 18, .max
= 26 },
180 .m2
= { .min
= 6, .max
= 16 },
181 .p
= { .min
= 4, .max
= 128 },
182 .p1
= { .min
= 1, .max
= 6 },
183 .p2
= { .dot_limit
= 165000,
184 .p2_slow
= 14, .p2_fast
= 7 },
187 static const intel_limit_t intel_limits_i9xx_sdvo
= {
188 .dot
= { .min
= 20000, .max
= 400000 },
189 .vco
= { .min
= 1400000, .max
= 2800000 },
190 .n
= { .min
= 1, .max
= 6 },
191 .m
= { .min
= 70, .max
= 120 },
192 .m1
= { .min
= 8, .max
= 18 },
193 .m2
= { .min
= 3, .max
= 7 },
194 .p
= { .min
= 5, .max
= 80 },
195 .p1
= { .min
= 1, .max
= 8 },
196 .p2
= { .dot_limit
= 200000,
197 .p2_slow
= 10, .p2_fast
= 5 },
200 static const intel_limit_t intel_limits_i9xx_lvds
= {
201 .dot
= { .min
= 20000, .max
= 400000 },
202 .vco
= { .min
= 1400000, .max
= 2800000 },
203 .n
= { .min
= 1, .max
= 6 },
204 .m
= { .min
= 70, .max
= 120 },
205 .m1
= { .min
= 8, .max
= 18 },
206 .m2
= { .min
= 3, .max
= 7 },
207 .p
= { .min
= 7, .max
= 98 },
208 .p1
= { .min
= 1, .max
= 8 },
209 .p2
= { .dot_limit
= 112000,
210 .p2_slow
= 14, .p2_fast
= 7 },
214 static const intel_limit_t intel_limits_g4x_sdvo
= {
215 .dot
= { .min
= 25000, .max
= 270000 },
216 .vco
= { .min
= 1750000, .max
= 3500000},
217 .n
= { .min
= 1, .max
= 4 },
218 .m
= { .min
= 104, .max
= 138 },
219 .m1
= { .min
= 17, .max
= 23 },
220 .m2
= { .min
= 5, .max
= 11 },
221 .p
= { .min
= 10, .max
= 30 },
222 .p1
= { .min
= 1, .max
= 3},
223 .p2
= { .dot_limit
= 270000,
229 static const intel_limit_t intel_limits_g4x_hdmi
= {
230 .dot
= { .min
= 22000, .max
= 400000 },
231 .vco
= { .min
= 1750000, .max
= 3500000},
232 .n
= { .min
= 1, .max
= 4 },
233 .m
= { .min
= 104, .max
= 138 },
234 .m1
= { .min
= 16, .max
= 23 },
235 .m2
= { .min
= 5, .max
= 11 },
236 .p
= { .min
= 5, .max
= 80 },
237 .p1
= { .min
= 1, .max
= 8},
238 .p2
= { .dot_limit
= 165000,
239 .p2_slow
= 10, .p2_fast
= 5 },
242 static const intel_limit_t intel_limits_g4x_single_channel_lvds
= {
243 .dot
= { .min
= 20000, .max
= 115000 },
244 .vco
= { .min
= 1750000, .max
= 3500000 },
245 .n
= { .min
= 1, .max
= 3 },
246 .m
= { .min
= 104, .max
= 138 },
247 .m1
= { .min
= 17, .max
= 23 },
248 .m2
= { .min
= 5, .max
= 11 },
249 .p
= { .min
= 28, .max
= 112 },
250 .p1
= { .min
= 2, .max
= 8 },
251 .p2
= { .dot_limit
= 0,
252 .p2_slow
= 14, .p2_fast
= 14
256 static const intel_limit_t intel_limits_g4x_dual_channel_lvds
= {
257 .dot
= { .min
= 80000, .max
= 224000 },
258 .vco
= { .min
= 1750000, .max
= 3500000 },
259 .n
= { .min
= 1, .max
= 3 },
260 .m
= { .min
= 104, .max
= 138 },
261 .m1
= { .min
= 17, .max
= 23 },
262 .m2
= { .min
= 5, .max
= 11 },
263 .p
= { .min
= 14, .max
= 42 },
264 .p1
= { .min
= 2, .max
= 6 },
265 .p2
= { .dot_limit
= 0,
266 .p2_slow
= 7, .p2_fast
= 7
270 static const intel_limit_t intel_limits_pineview_sdvo
= {
271 .dot
= { .min
= 20000, .max
= 400000},
272 .vco
= { .min
= 1700000, .max
= 3500000 },
273 /* Pineview's Ncounter is a ring counter */
274 .n
= { .min
= 3, .max
= 6 },
275 .m
= { .min
= 2, .max
= 256 },
276 /* Pineview only has one combined m divider, which we treat as m2. */
277 .m1
= { .min
= 0, .max
= 0 },
278 .m2
= { .min
= 0, .max
= 254 },
279 .p
= { .min
= 5, .max
= 80 },
280 .p1
= { .min
= 1, .max
= 8 },
281 .p2
= { .dot_limit
= 200000,
282 .p2_slow
= 10, .p2_fast
= 5 },
285 static const intel_limit_t intel_limits_pineview_lvds
= {
286 .dot
= { .min
= 20000, .max
= 400000 },
287 .vco
= { .min
= 1700000, .max
= 3500000 },
288 .n
= { .min
= 3, .max
= 6 },
289 .m
= { .min
= 2, .max
= 256 },
290 .m1
= { .min
= 0, .max
= 0 },
291 .m2
= { .min
= 0, .max
= 254 },
292 .p
= { .min
= 7, .max
= 112 },
293 .p1
= { .min
= 1, .max
= 8 },
294 .p2
= { .dot_limit
= 112000,
295 .p2_slow
= 14, .p2_fast
= 14 },
298 /* Ironlake / Sandybridge
300 * We calculate clock using (register_value + 2) for N/M1/M2, so here
301 * the range value for them is (actual_value - 2).
303 static const intel_limit_t intel_limits_ironlake_dac
= {
304 .dot
= { .min
= 25000, .max
= 350000 },
305 .vco
= { .min
= 1760000, .max
= 3510000 },
306 .n
= { .min
= 1, .max
= 5 },
307 .m
= { .min
= 79, .max
= 127 },
308 .m1
= { .min
= 12, .max
= 22 },
309 .m2
= { .min
= 5, .max
= 9 },
310 .p
= { .min
= 5, .max
= 80 },
311 .p1
= { .min
= 1, .max
= 8 },
312 .p2
= { .dot_limit
= 225000,
313 .p2_slow
= 10, .p2_fast
= 5 },
316 static const intel_limit_t intel_limits_ironlake_single_lvds
= {
317 .dot
= { .min
= 25000, .max
= 350000 },
318 .vco
= { .min
= 1760000, .max
= 3510000 },
319 .n
= { .min
= 1, .max
= 3 },
320 .m
= { .min
= 79, .max
= 118 },
321 .m1
= { .min
= 12, .max
= 22 },
322 .m2
= { .min
= 5, .max
= 9 },
323 .p
= { .min
= 28, .max
= 112 },
324 .p1
= { .min
= 2, .max
= 8 },
325 .p2
= { .dot_limit
= 225000,
326 .p2_slow
= 14, .p2_fast
= 14 },
329 static const intel_limit_t intel_limits_ironlake_dual_lvds
= {
330 .dot
= { .min
= 25000, .max
= 350000 },
331 .vco
= { .min
= 1760000, .max
= 3510000 },
332 .n
= { .min
= 1, .max
= 3 },
333 .m
= { .min
= 79, .max
= 127 },
334 .m1
= { .min
= 12, .max
= 22 },
335 .m2
= { .min
= 5, .max
= 9 },
336 .p
= { .min
= 14, .max
= 56 },
337 .p1
= { .min
= 2, .max
= 8 },
338 .p2
= { .dot_limit
= 225000,
339 .p2_slow
= 7, .p2_fast
= 7 },
342 /* LVDS 100mhz refclk limits. */
343 static const intel_limit_t intel_limits_ironlake_single_lvds_100m
= {
344 .dot
= { .min
= 25000, .max
= 350000 },
345 .vco
= { .min
= 1760000, .max
= 3510000 },
346 .n
= { .min
= 1, .max
= 2 },
347 .m
= { .min
= 79, .max
= 126 },
348 .m1
= { .min
= 12, .max
= 22 },
349 .m2
= { .min
= 5, .max
= 9 },
350 .p
= { .min
= 28, .max
= 112 },
351 .p1
= { .min
= 2, .max
= 8 },
352 .p2
= { .dot_limit
= 225000,
353 .p2_slow
= 14, .p2_fast
= 14 },
356 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m
= {
357 .dot
= { .min
= 25000, .max
= 350000 },
358 .vco
= { .min
= 1760000, .max
= 3510000 },
359 .n
= { .min
= 1, .max
= 3 },
360 .m
= { .min
= 79, .max
= 126 },
361 .m1
= { .min
= 12, .max
= 22 },
362 .m2
= { .min
= 5, .max
= 9 },
363 .p
= { .min
= 14, .max
= 42 },
364 .p1
= { .min
= 2, .max
= 6 },
365 .p2
= { .dot_limit
= 225000,
366 .p2_slow
= 7, .p2_fast
= 7 },
369 static const intel_limit_t intel_limits_vlv
= {
371 * These are the data rate limits (measured in fast clocks)
372 * since those are the strictest limits we have. The fast
373 * clock and actual rate limits are more relaxed, so checking
374 * them would make no difference.
376 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
377 .vco
= { .min
= 4000000, .max
= 6000000 },
378 .n
= { .min
= 1, .max
= 7 },
379 .m1
= { .min
= 2, .max
= 3 },
380 .m2
= { .min
= 11, .max
= 156 },
381 .p1
= { .min
= 2, .max
= 3 },
382 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
385 static const intel_limit_t intel_limits_chv
= {
387 * These are the data rate limits (measured in fast clocks)
388 * since those are the strictest limits we have. The fast
389 * clock and actual rate limits are more relaxed, so checking
390 * them would make no difference.
392 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
393 .vco
= { .min
= 4860000, .max
= 6700000 },
394 .n
= { .min
= 1, .max
= 1 },
395 .m1
= { .min
= 2, .max
= 2 },
396 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
397 .p1
= { .min
= 2, .max
= 4 },
398 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
401 static void vlv_clock(int refclk
, intel_clock_t
*clock
)
403 clock
->m
= clock
->m1
* clock
->m2
;
404 clock
->p
= clock
->p1
* clock
->p2
;
405 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
407 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
408 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
412 * Returns whether any output on the specified pipe is of the specified type
414 static bool intel_pipe_has_type(struct drm_crtc
*crtc
, int type
)
416 struct drm_device
*dev
= crtc
->dev
;
417 struct intel_encoder
*encoder
;
419 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
420 if (encoder
->type
== type
)
426 static const intel_limit_t
*intel_ironlake_limit(struct drm_crtc
*crtc
,
429 struct drm_device
*dev
= crtc
->dev
;
430 const intel_limit_t
*limit
;
432 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
433 if (intel_is_dual_link_lvds(dev
)) {
434 if (refclk
== 100000)
435 limit
= &intel_limits_ironlake_dual_lvds_100m
;
437 limit
= &intel_limits_ironlake_dual_lvds
;
439 if (refclk
== 100000)
440 limit
= &intel_limits_ironlake_single_lvds_100m
;
442 limit
= &intel_limits_ironlake_single_lvds
;
445 limit
= &intel_limits_ironlake_dac
;
450 static const intel_limit_t
*intel_g4x_limit(struct drm_crtc
*crtc
)
452 struct drm_device
*dev
= crtc
->dev
;
453 const intel_limit_t
*limit
;
455 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
456 if (intel_is_dual_link_lvds(dev
))
457 limit
= &intel_limits_g4x_dual_channel_lvds
;
459 limit
= &intel_limits_g4x_single_channel_lvds
;
460 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
) ||
461 intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
)) {
462 limit
= &intel_limits_g4x_hdmi
;
463 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
)) {
464 limit
= &intel_limits_g4x_sdvo
;
465 } else /* The option is for other outputs */
466 limit
= &intel_limits_i9xx_sdvo
;
471 static const intel_limit_t
*intel_limit(struct drm_crtc
*crtc
, int refclk
)
473 struct drm_device
*dev
= crtc
->dev
;
474 const intel_limit_t
*limit
;
476 if (HAS_PCH_SPLIT(dev
))
477 limit
= intel_ironlake_limit(crtc
, refclk
);
478 else if (IS_G4X(dev
)) {
479 limit
= intel_g4x_limit(crtc
);
480 } else if (IS_PINEVIEW(dev
)) {
481 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
482 limit
= &intel_limits_pineview_lvds
;
484 limit
= &intel_limits_pineview_sdvo
;
485 } else if (IS_CHERRYVIEW(dev
)) {
486 limit
= &intel_limits_chv
;
487 } else if (IS_VALLEYVIEW(dev
)) {
488 limit
= &intel_limits_vlv
;
489 } else if (!IS_GEN2(dev
)) {
490 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
491 limit
= &intel_limits_i9xx_lvds
;
493 limit
= &intel_limits_i9xx_sdvo
;
495 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
496 limit
= &intel_limits_i8xx_lvds
;
497 else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
))
498 limit
= &intel_limits_i8xx_dvo
;
500 limit
= &intel_limits_i8xx_dac
;
505 /* m1 is reserved as 0 in Pineview, n is a ring counter */
506 static void pineview_clock(int refclk
, intel_clock_t
*clock
)
508 clock
->m
= clock
->m2
+ 2;
509 clock
->p
= clock
->p1
* clock
->p2
;
510 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
512 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
513 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
516 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
518 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
521 static void i9xx_clock(int refclk
, intel_clock_t
*clock
)
523 clock
->m
= i9xx_dpll_compute_m(clock
);
524 clock
->p
= clock
->p1
* clock
->p2
;
525 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
527 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
528 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
531 static void chv_clock(int refclk
, intel_clock_t
*clock
)
533 clock
->m
= clock
->m1
* clock
->m2
;
534 clock
->p
= clock
->p1
* clock
->p2
;
535 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
537 clock
->vco
= DIV_ROUND_CLOSEST_ULL((uint64_t)refclk
* clock
->m
,
539 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
542 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
544 * Returns whether the given set of divisors are valid for a given refclk with
545 * the given connectors.
548 static bool intel_PLL_is_valid(struct drm_device
*dev
,
549 const intel_limit_t
*limit
,
550 const intel_clock_t
*clock
)
552 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
553 INTELPllInvalid("n out of range\n");
554 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
555 INTELPllInvalid("p1 out of range\n");
556 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
557 INTELPllInvalid("m2 out of range\n");
558 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
559 INTELPllInvalid("m1 out of range\n");
561 if (!IS_PINEVIEW(dev
) && !IS_VALLEYVIEW(dev
))
562 if (clock
->m1
<= clock
->m2
)
563 INTELPllInvalid("m1 <= m2\n");
565 if (!IS_VALLEYVIEW(dev
)) {
566 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
567 INTELPllInvalid("p out of range\n");
568 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
569 INTELPllInvalid("m out of range\n");
572 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
573 INTELPllInvalid("vco out of range\n");
574 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
575 * connector, etc., rather than just a single range.
577 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
578 INTELPllInvalid("dot out of range\n");
584 i9xx_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
585 int target
, int refclk
, intel_clock_t
*match_clock
,
586 intel_clock_t
*best_clock
)
588 struct drm_device
*dev
= crtc
->dev
;
592 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
594 * For LVDS just rely on its current settings for dual-channel.
595 * We haven't figured out how to reliably set up different
596 * single/dual channel state, if we even can.
598 if (intel_is_dual_link_lvds(dev
))
599 clock
.p2
= limit
->p2
.p2_fast
;
601 clock
.p2
= limit
->p2
.p2_slow
;
603 if (target
< limit
->p2
.dot_limit
)
604 clock
.p2
= limit
->p2
.p2_slow
;
606 clock
.p2
= limit
->p2
.p2_fast
;
609 memset(best_clock
, 0, sizeof(*best_clock
));
611 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
613 for (clock
.m2
= limit
->m2
.min
;
614 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
615 if (clock
.m2
>= clock
.m1
)
617 for (clock
.n
= limit
->n
.min
;
618 clock
.n
<= limit
->n
.max
; clock
.n
++) {
619 for (clock
.p1
= limit
->p1
.min
;
620 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
623 i9xx_clock(refclk
, &clock
);
624 if (!intel_PLL_is_valid(dev
, limit
,
628 clock
.p
!= match_clock
->p
)
631 this_err
= abs(clock
.dot
- target
);
632 if (this_err
< err
) {
641 return (err
!= target
);
645 pnv_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
646 int target
, int refclk
, intel_clock_t
*match_clock
,
647 intel_clock_t
*best_clock
)
649 struct drm_device
*dev
= crtc
->dev
;
653 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
655 * For LVDS just rely on its current settings for dual-channel.
656 * We haven't figured out how to reliably set up different
657 * single/dual channel state, if we even can.
659 if (intel_is_dual_link_lvds(dev
))
660 clock
.p2
= limit
->p2
.p2_fast
;
662 clock
.p2
= limit
->p2
.p2_slow
;
664 if (target
< limit
->p2
.dot_limit
)
665 clock
.p2
= limit
->p2
.p2_slow
;
667 clock
.p2
= limit
->p2
.p2_fast
;
670 memset(best_clock
, 0, sizeof(*best_clock
));
672 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
674 for (clock
.m2
= limit
->m2
.min
;
675 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
676 for (clock
.n
= limit
->n
.min
;
677 clock
.n
<= limit
->n
.max
; clock
.n
++) {
678 for (clock
.p1
= limit
->p1
.min
;
679 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
682 pineview_clock(refclk
, &clock
);
683 if (!intel_PLL_is_valid(dev
, limit
,
687 clock
.p
!= match_clock
->p
)
690 this_err
= abs(clock
.dot
- target
);
691 if (this_err
< err
) {
700 return (err
!= target
);
704 g4x_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
705 int target
, int refclk
, intel_clock_t
*match_clock
,
706 intel_clock_t
*best_clock
)
708 struct drm_device
*dev
= crtc
->dev
;
712 /* approximately equals target * 0.00585 */
713 int err_most
= (target
>> 8) + (target
>> 9);
716 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
717 if (intel_is_dual_link_lvds(dev
))
718 clock
.p2
= limit
->p2
.p2_fast
;
720 clock
.p2
= limit
->p2
.p2_slow
;
722 if (target
< limit
->p2
.dot_limit
)
723 clock
.p2
= limit
->p2
.p2_slow
;
725 clock
.p2
= limit
->p2
.p2_fast
;
728 memset(best_clock
, 0, sizeof(*best_clock
));
729 max_n
= limit
->n
.max
;
730 /* based on hardware requirement, prefer smaller n to precision */
731 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
732 /* based on hardware requirement, prefere larger m1,m2 */
733 for (clock
.m1
= limit
->m1
.max
;
734 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
735 for (clock
.m2
= limit
->m2
.max
;
736 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
737 for (clock
.p1
= limit
->p1
.max
;
738 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
741 i9xx_clock(refclk
, &clock
);
742 if (!intel_PLL_is_valid(dev
, limit
,
746 this_err
= abs(clock
.dot
- target
);
747 if (this_err
< err_most
) {
761 vlv_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
762 int target
, int refclk
, intel_clock_t
*match_clock
,
763 intel_clock_t
*best_clock
)
765 struct drm_device
*dev
= crtc
->dev
;
767 unsigned int bestppm
= 1000000;
768 /* min update 19.2 MHz */
769 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
772 target
*= 5; /* fast clock */
774 memset(best_clock
, 0, sizeof(*best_clock
));
776 /* based on hardware requirement, prefer smaller n to precision */
777 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
778 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
779 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
780 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
781 clock
.p
= clock
.p1
* clock
.p2
;
782 /* based on hardware requirement, prefer bigger m1,m2 values */
783 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
784 unsigned int ppm
, diff
;
786 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
789 vlv_clock(refclk
, &clock
);
791 if (!intel_PLL_is_valid(dev
, limit
,
795 diff
= abs(clock
.dot
- target
);
796 ppm
= div_u64(1000000ULL * diff
, target
);
798 if (ppm
< 100 && clock
.p
> best_clock
->p
) {
804 if (bestppm
>= 10 && ppm
< bestppm
- 10) {
818 chv_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
819 int target
, int refclk
, intel_clock_t
*match_clock
,
820 intel_clock_t
*best_clock
)
822 struct drm_device
*dev
= crtc
->dev
;
827 memset(best_clock
, 0, sizeof(*best_clock
));
830 * Based on hardware doc, the n always set to 1, and m1 always
831 * set to 2. If requires to support 200Mhz refclk, we need to
832 * revisit this because n may not 1 anymore.
834 clock
.n
= 1, clock
.m1
= 2;
835 target
*= 5; /* fast clock */
837 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
838 for (clock
.p2
= limit
->p2
.p2_fast
;
839 clock
.p2
>= limit
->p2
.p2_slow
;
840 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
842 clock
.p
= clock
.p1
* clock
.p2
;
844 m2
= DIV_ROUND_CLOSEST_ULL(((uint64_t)target
* clock
.p
*
845 clock
.n
) << 22, refclk
* clock
.m1
);
847 if (m2
> INT_MAX
/clock
.m1
)
852 chv_clock(refclk
, &clock
);
854 if (!intel_PLL_is_valid(dev
, limit
, &clock
))
857 /* based on hardware requirement, prefer bigger p
859 if (clock
.p
> best_clock
->p
) {
869 bool intel_crtc_active(struct drm_crtc
*crtc
)
871 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
873 /* Be paranoid as we can arrive here with only partial
874 * state retrieved from the hardware during setup.
876 * We can ditch the adjusted_mode.crtc_clock check as soon
877 * as Haswell has gained clock readout/fastboot support.
879 * We can ditch the crtc->primary->fb check as soon as we can
880 * properly reconstruct framebuffers.
882 return intel_crtc
->active
&& crtc
->primary
->fb
&&
883 intel_crtc
->config
.adjusted_mode
.crtc_clock
;
886 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
889 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
890 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
892 return intel_crtc
->config
.cpu_transcoder
;
895 static void g4x_wait_for_vblank(struct drm_device
*dev
, int pipe
)
897 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
898 u32 frame
, frame_reg
= PIPE_FRMCOUNT_GM45(pipe
);
900 frame
= I915_READ(frame_reg
);
902 if (wait_for(I915_READ_NOTRACE(frame_reg
) != frame
, 50))
903 WARN(1, "vblank wait on pipe %c timed out\n",
908 * intel_wait_for_vblank - wait for vblank on a given pipe
910 * @pipe: pipe to wait for
912 * Wait for vblank to occur on a given pipe. Needed for various bits of
915 void intel_wait_for_vblank(struct drm_device
*dev
, int pipe
)
917 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
918 int pipestat_reg
= PIPESTAT(pipe
);
920 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5) {
921 g4x_wait_for_vblank(dev
, pipe
);
925 /* Clear existing vblank status. Note this will clear any other
926 * sticky status fields as well.
928 * This races with i915_driver_irq_handler() with the result
929 * that either function could miss a vblank event. Here it is not
930 * fatal, as we will either wait upon the next vblank interrupt or
931 * timeout. Generally speaking intel_wait_for_vblank() is only
932 * called during modeset at which time the GPU should be idle and
933 * should *not* be performing page flips and thus not waiting on
935 * Currently, the result of us stealing a vblank from the irq
936 * handler is that a single frame will be skipped during swapbuffers.
938 I915_WRITE(pipestat_reg
,
939 I915_READ(pipestat_reg
) | PIPE_VBLANK_INTERRUPT_STATUS
);
941 /* Wait for vblank interrupt bit to set */
942 if (wait_for(I915_READ(pipestat_reg
) &
943 PIPE_VBLANK_INTERRUPT_STATUS
,
945 DRM_DEBUG_KMS("vblank wait on pipe %c timed out\n",
949 static bool pipe_dsl_stopped(struct drm_device
*dev
, enum pipe pipe
)
951 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
952 u32 reg
= PIPEDSL(pipe
);
957 line_mask
= DSL_LINEMASK_GEN2
;
959 line_mask
= DSL_LINEMASK_GEN3
;
961 line1
= I915_READ(reg
) & line_mask
;
963 line2
= I915_READ(reg
) & line_mask
;
965 return line1
== line2
;
969 * intel_wait_for_pipe_off - wait for pipe to turn off
970 * @crtc: crtc whose pipe to wait for
972 * After disabling a pipe, we can't wait for vblank in the usual way,
973 * spinning on the vblank interrupt status bit, since we won't actually
974 * see an interrupt when the pipe is disabled.
977 * wait for the pipe register state bit to turn off
980 * wait for the display line value to settle (it usually
981 * ends up stopping at the start of the next frame).
984 static void intel_wait_for_pipe_off(struct intel_crtc
*crtc
)
986 struct drm_device
*dev
= crtc
->base
.dev
;
987 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
988 enum transcoder cpu_transcoder
= crtc
->config
.cpu_transcoder
;
989 enum pipe pipe
= crtc
->pipe
;
991 if (INTEL_INFO(dev
)->gen
>= 4) {
992 int reg
= PIPECONF(cpu_transcoder
);
994 /* Wait for the Pipe State to go off */
995 if (wait_for((I915_READ(reg
) & I965_PIPECONF_ACTIVE
) == 0,
997 WARN(1, "pipe_off wait timed out\n");
999 /* Wait for the display line to settle */
1000 if (wait_for(pipe_dsl_stopped(dev
, pipe
), 100))
1001 WARN(1, "pipe_off wait timed out\n");
1006 * ibx_digital_port_connected - is the specified port connected?
1007 * @dev_priv: i915 private structure
1008 * @port: the port to test
1010 * Returns true if @port is connected, false otherwise.
1012 bool ibx_digital_port_connected(struct drm_i915_private
*dev_priv
,
1013 struct intel_digital_port
*port
)
1017 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1018 switch (port
->port
) {
1020 bit
= SDE_PORTB_HOTPLUG
;
1023 bit
= SDE_PORTC_HOTPLUG
;
1026 bit
= SDE_PORTD_HOTPLUG
;
1032 switch (port
->port
) {
1034 bit
= SDE_PORTB_HOTPLUG_CPT
;
1037 bit
= SDE_PORTC_HOTPLUG_CPT
;
1040 bit
= SDE_PORTD_HOTPLUG_CPT
;
1047 return I915_READ(SDEISR
) & bit
;
1050 static const char *state_string(bool enabled
)
1052 return enabled
? "on" : "off";
1055 /* Only for pre-ILK configs */
1056 void assert_pll(struct drm_i915_private
*dev_priv
,
1057 enum pipe pipe
, bool state
)
1064 val
= I915_READ(reg
);
1065 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1066 WARN(cur_state
!= state
,
1067 "PLL state assertion failure (expected %s, current %s)\n",
1068 state_string(state
), state_string(cur_state
));
1071 /* XXX: the dsi pll is shared between MIPI DSI ports */
1072 static void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1077 mutex_lock(&dev_priv
->dpio_lock
);
1078 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1079 mutex_unlock(&dev_priv
->dpio_lock
);
1081 cur_state
= val
& DSI_PLL_VCO_EN
;
1082 WARN(cur_state
!= state
,
1083 "DSI PLL state assertion failure (expected %s, current %s)\n",
1084 state_string(state
), state_string(cur_state
));
1086 #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
1087 #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
1089 struct intel_shared_dpll
*
1090 intel_crtc_to_shared_dpll(struct intel_crtc
*crtc
)
1092 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
1094 if (crtc
->config
.shared_dpll
< 0)
1097 return &dev_priv
->shared_dplls
[crtc
->config
.shared_dpll
];
1101 void assert_shared_dpll(struct drm_i915_private
*dev_priv
,
1102 struct intel_shared_dpll
*pll
,
1106 struct intel_dpll_hw_state hw_state
;
1109 "asserting DPLL %s with no DPLL\n", state_string(state
)))
1112 cur_state
= pll
->get_hw_state(dev_priv
, pll
, &hw_state
);
1113 WARN(cur_state
!= state
,
1114 "%s assertion failure (expected %s, current %s)\n",
1115 pll
->name
, state_string(state
), state_string(cur_state
));
1118 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1119 enum pipe pipe
, bool state
)
1124 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1127 if (HAS_DDI(dev_priv
->dev
)) {
1128 /* DDI does not have a specific FDI_TX register */
1129 reg
= TRANS_DDI_FUNC_CTL(cpu_transcoder
);
1130 val
= I915_READ(reg
);
1131 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1133 reg
= FDI_TX_CTL(pipe
);
1134 val
= I915_READ(reg
);
1135 cur_state
= !!(val
& FDI_TX_ENABLE
);
1137 WARN(cur_state
!= state
,
1138 "FDI TX state assertion failure (expected %s, current %s)\n",
1139 state_string(state
), state_string(cur_state
));
1141 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1142 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1144 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1145 enum pipe pipe
, bool state
)
1151 reg
= FDI_RX_CTL(pipe
);
1152 val
= I915_READ(reg
);
1153 cur_state
= !!(val
& FDI_RX_ENABLE
);
1154 WARN(cur_state
!= state
,
1155 "FDI RX state assertion failure (expected %s, current %s)\n",
1156 state_string(state
), state_string(cur_state
));
1158 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1159 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1161 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1167 /* ILK FDI PLL is always enabled */
1168 if (INTEL_INFO(dev_priv
->dev
)->gen
== 5)
1171 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1172 if (HAS_DDI(dev_priv
->dev
))
1175 reg
= FDI_TX_CTL(pipe
);
1176 val
= I915_READ(reg
);
1177 WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1180 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1181 enum pipe pipe
, bool state
)
1187 reg
= FDI_RX_CTL(pipe
);
1188 val
= I915_READ(reg
);
1189 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1190 WARN(cur_state
!= state
,
1191 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1192 state_string(state
), state_string(cur_state
));
1195 static void assert_panel_unlocked(struct drm_i915_private
*dev_priv
,
1198 struct drm_device
*dev
= dev_priv
->dev
;
1201 enum pipe panel_pipe
= PIPE_A
;
1204 if (WARN_ON(HAS_DDI(dev
)))
1207 if (HAS_PCH_SPLIT(dev
)) {
1210 pp_reg
= PCH_PP_CONTROL
;
1211 port_sel
= I915_READ(PCH_PP_ON_DELAYS
) & PANEL_PORT_SELECT_MASK
;
1213 if (port_sel
== PANEL_PORT_SELECT_LVDS
&&
1214 I915_READ(PCH_LVDS
) & LVDS_PIPEB_SELECT
)
1215 panel_pipe
= PIPE_B
;
1216 /* XXX: else fix for eDP */
1217 } else if (IS_VALLEYVIEW(dev
)) {
1218 /* presumably write lock depends on pipe, not port select */
1219 pp_reg
= VLV_PIPE_PP_CONTROL(pipe
);
1222 pp_reg
= PP_CONTROL
;
1223 if (I915_READ(LVDS
) & LVDS_PIPEB_SELECT
)
1224 panel_pipe
= PIPE_B
;
1227 val
= I915_READ(pp_reg
);
1228 if (!(val
& PANEL_POWER_ON
) ||
1229 ((val
& PANEL_UNLOCK_MASK
) == PANEL_UNLOCK_REGS
))
1232 WARN(panel_pipe
== pipe
&& locked
,
1233 "panel assertion failure, pipe %c regs locked\n",
1237 static void assert_cursor(struct drm_i915_private
*dev_priv
,
1238 enum pipe pipe
, bool state
)
1240 struct drm_device
*dev
= dev_priv
->dev
;
1243 if (IS_845G(dev
) || IS_I865G(dev
))
1244 cur_state
= I915_READ(_CURACNTR
) & CURSOR_ENABLE
;
1246 cur_state
= I915_READ(CURCNTR(pipe
)) & CURSOR_MODE
;
1248 WARN(cur_state
!= state
,
1249 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1250 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1252 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1253 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1255 void assert_pipe(struct drm_i915_private
*dev_priv
,
1256 enum pipe pipe
, bool state
)
1261 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1264 /* if we need the pipe quirk it must be always on */
1265 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1266 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1269 if (!intel_display_power_enabled(dev_priv
,
1270 POWER_DOMAIN_TRANSCODER(cpu_transcoder
))) {
1273 reg
= PIPECONF(cpu_transcoder
);
1274 val
= I915_READ(reg
);
1275 cur_state
= !!(val
& PIPECONF_ENABLE
);
1278 WARN(cur_state
!= state
,
1279 "pipe %c assertion failure (expected %s, current %s)\n",
1280 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1283 static void assert_plane(struct drm_i915_private
*dev_priv
,
1284 enum plane plane
, bool state
)
1290 reg
= DSPCNTR(plane
);
1291 val
= I915_READ(reg
);
1292 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1293 WARN(cur_state
!= state
,
1294 "plane %c assertion failure (expected %s, current %s)\n",
1295 plane_name(plane
), state_string(state
), state_string(cur_state
));
1298 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1299 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1301 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1304 struct drm_device
*dev
= dev_priv
->dev
;
1309 /* Primary planes are fixed to pipes on gen4+ */
1310 if (INTEL_INFO(dev
)->gen
>= 4) {
1311 reg
= DSPCNTR(pipe
);
1312 val
= I915_READ(reg
);
1313 WARN(val
& DISPLAY_PLANE_ENABLE
,
1314 "plane %c assertion failure, should be disabled but not\n",
1319 /* Need to check both planes against the pipe */
1320 for_each_pipe(dev_priv
, i
) {
1322 val
= I915_READ(reg
);
1323 cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1324 DISPPLANE_SEL_PIPE_SHIFT
;
1325 WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1326 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1327 plane_name(i
), pipe_name(pipe
));
1331 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1334 struct drm_device
*dev
= dev_priv
->dev
;
1338 if (IS_VALLEYVIEW(dev
)) {
1339 for_each_sprite(pipe
, sprite
) {
1340 reg
= SPCNTR(pipe
, sprite
);
1341 val
= I915_READ(reg
);
1342 WARN(val
& SP_ENABLE
,
1343 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1344 sprite_name(pipe
, sprite
), pipe_name(pipe
));
1346 } else if (INTEL_INFO(dev
)->gen
>= 7) {
1348 val
= I915_READ(reg
);
1349 WARN(val
& SPRITE_ENABLE
,
1350 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1351 plane_name(pipe
), pipe_name(pipe
));
1352 } else if (INTEL_INFO(dev
)->gen
>= 5) {
1353 reg
= DVSCNTR(pipe
);
1354 val
= I915_READ(reg
);
1355 WARN(val
& DVS_ENABLE
,
1356 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1357 plane_name(pipe
), pipe_name(pipe
));
1361 static void ibx_assert_pch_refclk_enabled(struct drm_i915_private
*dev_priv
)
1366 WARN_ON(!(HAS_PCH_IBX(dev_priv
->dev
) || HAS_PCH_CPT(dev_priv
->dev
)));
1368 val
= I915_READ(PCH_DREF_CONTROL
);
1369 enabled
= !!(val
& (DREF_SSC_SOURCE_MASK
| DREF_NONSPREAD_SOURCE_MASK
|
1370 DREF_SUPERSPREAD_SOURCE_MASK
));
1371 WARN(!enabled
, "PCH refclk assertion failure, should be active but is disabled\n");
1374 static void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1381 reg
= PCH_TRANSCONF(pipe
);
1382 val
= I915_READ(reg
);
1383 enabled
= !!(val
& TRANS_ENABLE
);
1385 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1389 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1390 enum pipe pipe
, u32 port_sel
, u32 val
)
1392 if ((val
& DP_PORT_EN
) == 0)
1395 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1396 u32 trans_dp_ctl_reg
= TRANS_DP_CTL(pipe
);
1397 u32 trans_dp_ctl
= I915_READ(trans_dp_ctl_reg
);
1398 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1400 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1401 if ((val
& DP_PIPE_MASK_CHV
) != DP_PIPE_SELECT_CHV(pipe
))
1404 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1410 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1411 enum pipe pipe
, u32 val
)
1413 if ((val
& SDVO_ENABLE
) == 0)
1416 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1417 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1419 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1420 if ((val
& SDVO_PIPE_SEL_MASK_CHV
) != SDVO_PIPE_SEL_CHV(pipe
))
1423 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1429 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1430 enum pipe pipe
, u32 val
)
1432 if ((val
& LVDS_PORT_EN
) == 0)
1435 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1436 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1439 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1445 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1446 enum pipe pipe
, u32 val
)
1448 if ((val
& ADPA_DAC_ENABLE
) == 0)
1450 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1451 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1454 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1460 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1461 enum pipe pipe
, int reg
, u32 port_sel
)
1463 u32 val
= I915_READ(reg
);
1464 WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1465 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1466 reg
, pipe_name(pipe
));
1468 WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& DP_PORT_EN
) == 0
1469 && (val
& DP_PIPEB_SELECT
),
1470 "IBX PCH dp port still using transcoder B\n");
1473 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1474 enum pipe pipe
, int reg
)
1476 u32 val
= I915_READ(reg
);
1477 WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1478 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1479 reg
, pipe_name(pipe
));
1481 WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& SDVO_ENABLE
) == 0
1482 && (val
& SDVO_PIPE_B_SELECT
),
1483 "IBX PCH hdmi port still using transcoder B\n");
1486 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1492 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1493 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1494 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1497 val
= I915_READ(reg
);
1498 WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1499 "PCH VGA enabled on transcoder %c, should be disabled\n",
1503 val
= I915_READ(reg
);
1504 WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1505 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1508 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1509 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1510 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1513 static void intel_init_dpio(struct drm_device
*dev
)
1515 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1517 if (!IS_VALLEYVIEW(dev
))
1521 * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
1522 * CHV x1 PHY (DP/HDMI D)
1523 * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
1525 if (IS_CHERRYVIEW(dev
)) {
1526 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO_2
;
1527 DPIO_PHY_IOSF_PORT(DPIO_PHY1
) = IOSF_PORT_DPIO
;
1529 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO
;
1533 static void vlv_enable_pll(struct intel_crtc
*crtc
)
1535 struct drm_device
*dev
= crtc
->base
.dev
;
1536 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1537 int reg
= DPLL(crtc
->pipe
);
1538 u32 dpll
= crtc
->config
.dpll_hw_state
.dpll
;
1540 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1542 /* No really, not for ILK+ */
1543 BUG_ON(!IS_VALLEYVIEW(dev_priv
->dev
));
1545 /* PLL is protected by panel, make sure we can write it */
1546 if (IS_MOBILE(dev_priv
->dev
))
1547 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1549 I915_WRITE(reg
, dpll
);
1553 if (wait_for(((I915_READ(reg
) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1554 DRM_ERROR("DPLL %d failed to lock\n", crtc
->pipe
);
1556 I915_WRITE(DPLL_MD(crtc
->pipe
), crtc
->config
.dpll_hw_state
.dpll_md
);
1557 POSTING_READ(DPLL_MD(crtc
->pipe
));
1559 /* We do this three times for luck */
1560 I915_WRITE(reg
, dpll
);
1562 udelay(150); /* wait for warmup */
1563 I915_WRITE(reg
, dpll
);
1565 udelay(150); /* wait for warmup */
1566 I915_WRITE(reg
, dpll
);
1568 udelay(150); /* wait for warmup */
1571 static void chv_enable_pll(struct intel_crtc
*crtc
)
1573 struct drm_device
*dev
= crtc
->base
.dev
;
1574 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1575 int pipe
= crtc
->pipe
;
1576 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1579 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1581 BUG_ON(!IS_CHERRYVIEW(dev_priv
->dev
));
1583 mutex_lock(&dev_priv
->dpio_lock
);
1585 /* Enable back the 10bit clock to display controller */
1586 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1587 tmp
|= DPIO_DCLKP_EN
;
1588 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), tmp
);
1591 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1596 I915_WRITE(DPLL(pipe
), crtc
->config
.dpll_hw_state
.dpll
);
1598 /* Check PLL is locked */
1599 if (wait_for(((I915_READ(DPLL(pipe
)) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1600 DRM_ERROR("PLL %d failed to lock\n", pipe
);
1602 /* not sure when this should be written */
1603 I915_WRITE(DPLL_MD(pipe
), crtc
->config
.dpll_hw_state
.dpll_md
);
1604 POSTING_READ(DPLL_MD(pipe
));
1606 mutex_unlock(&dev_priv
->dpio_lock
);
1609 static void i9xx_enable_pll(struct intel_crtc
*crtc
)
1611 struct drm_device
*dev
= crtc
->base
.dev
;
1612 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1613 int reg
= DPLL(crtc
->pipe
);
1614 u32 dpll
= crtc
->config
.dpll_hw_state
.dpll
;
1616 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1618 /* No really, not for ILK+ */
1619 BUG_ON(INTEL_INFO(dev
)->gen
>= 5);
1621 /* PLL is protected by panel, make sure we can write it */
1622 if (IS_MOBILE(dev
) && !IS_I830(dev
))
1623 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1625 I915_WRITE(reg
, dpll
);
1627 /* Wait for the clocks to stabilize. */
1631 if (INTEL_INFO(dev
)->gen
>= 4) {
1632 I915_WRITE(DPLL_MD(crtc
->pipe
),
1633 crtc
->config
.dpll_hw_state
.dpll_md
);
1635 /* The pixel multiplier can only be updated once the
1636 * DPLL is enabled and the clocks are stable.
1638 * So write it again.
1640 I915_WRITE(reg
, dpll
);
1643 /* We do this three times for luck */
1644 I915_WRITE(reg
, dpll
);
1646 udelay(150); /* wait for warmup */
1647 I915_WRITE(reg
, dpll
);
1649 udelay(150); /* wait for warmup */
1650 I915_WRITE(reg
, dpll
);
1652 udelay(150); /* wait for warmup */
1656 * i9xx_disable_pll - disable a PLL
1657 * @dev_priv: i915 private structure
1658 * @pipe: pipe PLL to disable
1660 * Disable the PLL for @pipe, making sure the pipe is off first.
1662 * Note! This is for pre-ILK only.
1664 static void i9xx_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1666 /* Don't disable pipe or pipe PLLs if needed */
1667 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1668 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1671 /* Make sure the pipe isn't still relying on us */
1672 assert_pipe_disabled(dev_priv
, pipe
);
1674 I915_WRITE(DPLL(pipe
), 0);
1675 POSTING_READ(DPLL(pipe
));
1678 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1682 /* Make sure the pipe isn't still relying on us */
1683 assert_pipe_disabled(dev_priv
, pipe
);
1686 * Leave integrated clock source and reference clock enabled for pipe B.
1687 * The latter is needed for VGA hotplug / manual detection.
1690 val
= DPLL_INTEGRATED_CRI_CLK_VLV
| DPLL_REFA_CLK_ENABLE_VLV
;
1691 I915_WRITE(DPLL(pipe
), val
);
1692 POSTING_READ(DPLL(pipe
));
1696 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1698 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1701 /* Make sure the pipe isn't still relying on us */
1702 assert_pipe_disabled(dev_priv
, pipe
);
1704 /* Set PLL en = 0 */
1705 val
= DPLL_SSC_REF_CLOCK_CHV
| DPLL_REFA_CLK_ENABLE_VLV
;
1707 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1708 I915_WRITE(DPLL(pipe
), val
);
1709 POSTING_READ(DPLL(pipe
));
1711 mutex_lock(&dev_priv
->dpio_lock
);
1713 /* Disable 10bit clock to display controller */
1714 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1715 val
&= ~DPIO_DCLKP_EN
;
1716 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1718 /* disable left/right clock distribution */
1719 if (pipe
!= PIPE_B
) {
1720 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
);
1721 val
&= ~(CHV_BUFLEFTENA1_MASK
| CHV_BUFRIGHTENA1_MASK
);
1722 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
, val
);
1724 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
);
1725 val
&= ~(CHV_BUFLEFTENA2_MASK
| CHV_BUFRIGHTENA2_MASK
);
1726 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
, val
);
1729 mutex_unlock(&dev_priv
->dpio_lock
);
1732 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1733 struct intel_digital_port
*dport
)
1738 switch (dport
->port
) {
1740 port_mask
= DPLL_PORTB_READY_MASK
;
1744 port_mask
= DPLL_PORTC_READY_MASK
;
1748 port_mask
= DPLL_PORTD_READY_MASK
;
1749 dpll_reg
= DPIO_PHY_STATUS
;
1755 if (wait_for((I915_READ(dpll_reg
) & port_mask
) == 0, 1000))
1756 WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
1757 port_name(dport
->port
), I915_READ(dpll_reg
));
1760 static void intel_prepare_shared_dpll(struct intel_crtc
*crtc
)
1762 struct drm_device
*dev
= crtc
->base
.dev
;
1763 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1764 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1766 if (WARN_ON(pll
== NULL
))
1769 WARN_ON(!pll
->refcount
);
1770 if (pll
->active
== 0) {
1771 DRM_DEBUG_DRIVER("setting up %s\n", pll
->name
);
1773 assert_shared_dpll_disabled(dev_priv
, pll
);
1775 pll
->mode_set(dev_priv
, pll
);
1780 * intel_enable_shared_dpll - enable PCH PLL
1781 * @dev_priv: i915 private structure
1782 * @pipe: pipe PLL to enable
1784 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1785 * drives the transcoder clock.
1787 static void intel_enable_shared_dpll(struct intel_crtc
*crtc
)
1789 struct drm_device
*dev
= crtc
->base
.dev
;
1790 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1791 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1793 if (WARN_ON(pll
== NULL
))
1796 if (WARN_ON(pll
->refcount
== 0))
1799 DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n",
1800 pll
->name
, pll
->active
, pll
->on
,
1801 crtc
->base
.base
.id
);
1803 if (pll
->active
++) {
1805 assert_shared_dpll_enabled(dev_priv
, pll
);
1810 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
1812 DRM_DEBUG_KMS("enabling %s\n", pll
->name
);
1813 pll
->enable(dev_priv
, pll
);
1817 static void intel_disable_shared_dpll(struct intel_crtc
*crtc
)
1819 struct drm_device
*dev
= crtc
->base
.dev
;
1820 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1821 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1823 /* PCH only available on ILK+ */
1824 BUG_ON(INTEL_INFO(dev
)->gen
< 5);
1825 if (WARN_ON(pll
== NULL
))
1828 if (WARN_ON(pll
->refcount
== 0))
1831 DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
1832 pll
->name
, pll
->active
, pll
->on
,
1833 crtc
->base
.base
.id
);
1835 if (WARN_ON(pll
->active
== 0)) {
1836 assert_shared_dpll_disabled(dev_priv
, pll
);
1840 assert_shared_dpll_enabled(dev_priv
, pll
);
1845 DRM_DEBUG_KMS("disabling %s\n", pll
->name
);
1846 pll
->disable(dev_priv
, pll
);
1849 intel_display_power_put(dev_priv
, POWER_DOMAIN_PLLS
);
1852 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1855 struct drm_device
*dev
= dev_priv
->dev
;
1856 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1857 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1858 uint32_t reg
, val
, pipeconf_val
;
1860 /* PCH only available on ILK+ */
1861 BUG_ON(!HAS_PCH_SPLIT(dev
));
1863 /* Make sure PCH DPLL is enabled */
1864 assert_shared_dpll_enabled(dev_priv
,
1865 intel_crtc_to_shared_dpll(intel_crtc
));
1867 /* FDI must be feeding us bits for PCH ports */
1868 assert_fdi_tx_enabled(dev_priv
, pipe
);
1869 assert_fdi_rx_enabled(dev_priv
, pipe
);
1871 if (HAS_PCH_CPT(dev
)) {
1872 /* Workaround: Set the timing override bit before enabling the
1873 * pch transcoder. */
1874 reg
= TRANS_CHICKEN2(pipe
);
1875 val
= I915_READ(reg
);
1876 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1877 I915_WRITE(reg
, val
);
1880 reg
= PCH_TRANSCONF(pipe
);
1881 val
= I915_READ(reg
);
1882 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1884 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1886 * make the BPC in transcoder be consistent with
1887 * that in pipeconf reg.
1889 val
&= ~PIPECONF_BPC_MASK
;
1890 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
1893 val
&= ~TRANS_INTERLACE_MASK
;
1894 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
1895 if (HAS_PCH_IBX(dev_priv
->dev
) &&
1896 intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
))
1897 val
|= TRANS_LEGACY_INTERLACED_ILK
;
1899 val
|= TRANS_INTERLACED
;
1901 val
|= TRANS_PROGRESSIVE
;
1903 I915_WRITE(reg
, val
| TRANS_ENABLE
);
1904 if (wait_for(I915_READ(reg
) & TRANS_STATE_ENABLE
, 100))
1905 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
1908 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1909 enum transcoder cpu_transcoder
)
1911 u32 val
, pipeconf_val
;
1913 /* PCH only available on ILK+ */
1914 BUG_ON(!HAS_PCH_SPLIT(dev_priv
->dev
));
1916 /* FDI must be feeding us bits for PCH ports */
1917 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
1918 assert_fdi_rx_enabled(dev_priv
, TRANSCODER_A
);
1920 /* Workaround: set timing override bit. */
1921 val
= I915_READ(_TRANSA_CHICKEN2
);
1922 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1923 I915_WRITE(_TRANSA_CHICKEN2
, val
);
1926 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
1928 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
1929 PIPECONF_INTERLACED_ILK
)
1930 val
|= TRANS_INTERLACED
;
1932 val
|= TRANS_PROGRESSIVE
;
1934 I915_WRITE(LPT_TRANSCONF
, val
);
1935 if (wait_for(I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
, 100))
1936 DRM_ERROR("Failed to enable PCH transcoder\n");
1939 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1942 struct drm_device
*dev
= dev_priv
->dev
;
1945 /* FDI relies on the transcoder */
1946 assert_fdi_tx_disabled(dev_priv
, pipe
);
1947 assert_fdi_rx_disabled(dev_priv
, pipe
);
1949 /* Ports must be off as well */
1950 assert_pch_ports_disabled(dev_priv
, pipe
);
1952 reg
= PCH_TRANSCONF(pipe
);
1953 val
= I915_READ(reg
);
1954 val
&= ~TRANS_ENABLE
;
1955 I915_WRITE(reg
, val
);
1956 /* wait for PCH transcoder off, transcoder state */
1957 if (wait_for((I915_READ(reg
) & TRANS_STATE_ENABLE
) == 0, 50))
1958 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
1960 if (!HAS_PCH_IBX(dev
)) {
1961 /* Workaround: Clear the timing override chicken bit again. */
1962 reg
= TRANS_CHICKEN2(pipe
);
1963 val
= I915_READ(reg
);
1964 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1965 I915_WRITE(reg
, val
);
1969 static void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
1973 val
= I915_READ(LPT_TRANSCONF
);
1974 val
&= ~TRANS_ENABLE
;
1975 I915_WRITE(LPT_TRANSCONF
, val
);
1976 /* wait for PCH transcoder off, transcoder state */
1977 if (wait_for((I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
) == 0, 50))
1978 DRM_ERROR("Failed to disable PCH transcoder\n");
1980 /* Workaround: clear timing override bit. */
1981 val
= I915_READ(_TRANSA_CHICKEN2
);
1982 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1983 I915_WRITE(_TRANSA_CHICKEN2
, val
);
1987 * intel_enable_pipe - enable a pipe, asserting requirements
1988 * @crtc: crtc responsible for the pipe
1990 * Enable @crtc's pipe, making sure that various hardware specific requirements
1991 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
1993 static void intel_enable_pipe(struct intel_crtc
*crtc
)
1995 struct drm_device
*dev
= crtc
->base
.dev
;
1996 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1997 enum pipe pipe
= crtc
->pipe
;
1998 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
2000 enum pipe pch_transcoder
;
2004 assert_planes_disabled(dev_priv
, pipe
);
2005 assert_cursor_disabled(dev_priv
, pipe
);
2006 assert_sprites_disabled(dev_priv
, pipe
);
2008 if (HAS_PCH_LPT(dev_priv
->dev
))
2009 pch_transcoder
= TRANSCODER_A
;
2011 pch_transcoder
= pipe
;
2014 * A pipe without a PLL won't actually be able to drive bits from
2015 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
2018 if (!HAS_PCH_SPLIT(dev_priv
->dev
))
2019 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DSI
))
2020 assert_dsi_pll_enabled(dev_priv
);
2022 assert_pll_enabled(dev_priv
, pipe
);
2024 if (crtc
->config
.has_pch_encoder
) {
2025 /* if driving the PCH, we need FDI enabled */
2026 assert_fdi_rx_pll_enabled(dev_priv
, pch_transcoder
);
2027 assert_fdi_tx_pll_enabled(dev_priv
,
2028 (enum pipe
) cpu_transcoder
);
2030 /* FIXME: assert CPU port conditions for SNB+ */
2033 reg
= PIPECONF(cpu_transcoder
);
2034 val
= I915_READ(reg
);
2035 if (val
& PIPECONF_ENABLE
) {
2036 WARN_ON(!((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
2037 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
)));
2041 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
2046 * intel_disable_pipe - disable a pipe, asserting requirements
2047 * @crtc: crtc whose pipes is to be disabled
2049 * Disable the pipe of @crtc, making sure that various hardware
2050 * specific requirements are met, if applicable, e.g. plane
2051 * disabled, panel fitter off, etc.
2053 * Will wait until the pipe has shut down before returning.
2055 static void intel_disable_pipe(struct intel_crtc
*crtc
)
2057 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
2058 enum transcoder cpu_transcoder
= crtc
->config
.cpu_transcoder
;
2059 enum pipe pipe
= crtc
->pipe
;
2064 * Make sure planes won't keep trying to pump pixels to us,
2065 * or we might hang the display.
2067 assert_planes_disabled(dev_priv
, pipe
);
2068 assert_cursor_disabled(dev_priv
, pipe
);
2069 assert_sprites_disabled(dev_priv
, pipe
);
2071 reg
= PIPECONF(cpu_transcoder
);
2072 val
= I915_READ(reg
);
2073 if ((val
& PIPECONF_ENABLE
) == 0)
2077 * Double wide has implications for planes
2078 * so best keep it disabled when not needed.
2080 if (crtc
->config
.double_wide
)
2081 val
&= ~PIPECONF_DOUBLE_WIDE
;
2083 /* Don't disable pipe or pipe PLLs if needed */
2084 if (!(pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) &&
2085 !(pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
2086 val
&= ~PIPECONF_ENABLE
;
2088 I915_WRITE(reg
, val
);
2089 if ((val
& PIPECONF_ENABLE
) == 0)
2090 intel_wait_for_pipe_off(crtc
);
2094 * Plane regs are double buffered, going from enabled->disabled needs a
2095 * trigger in order to latch. The display address reg provides this.
2097 void intel_flush_primary_plane(struct drm_i915_private
*dev_priv
,
2100 struct drm_device
*dev
= dev_priv
->dev
;
2101 u32 reg
= INTEL_INFO(dev
)->gen
>= 4 ? DSPSURF(plane
) : DSPADDR(plane
);
2103 I915_WRITE(reg
, I915_READ(reg
));
2108 * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
2109 * @plane: plane to be enabled
2110 * @crtc: crtc for the plane
2112 * Enable @plane on @crtc, making sure that the pipe is running first.
2114 static void intel_enable_primary_hw_plane(struct drm_plane
*plane
,
2115 struct drm_crtc
*crtc
)
2117 struct drm_device
*dev
= plane
->dev
;
2118 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2119 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2121 /* If the pipe isn't enabled, we can't pump pixels and may hang */
2122 assert_pipe_enabled(dev_priv
, intel_crtc
->pipe
);
2124 if (intel_crtc
->primary_enabled
)
2127 intel_crtc
->primary_enabled
= true;
2129 dev_priv
->display
.update_primary_plane(crtc
, plane
->fb
,
2133 * BDW signals flip done immediately if the plane
2134 * is disabled, even if the plane enable is already
2135 * armed to occur at the next vblank :(
2137 if (IS_BROADWELL(dev
))
2138 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
2142 * intel_disable_primary_hw_plane - disable the primary hardware plane
2143 * @plane: plane to be disabled
2144 * @crtc: crtc for the plane
2146 * Disable @plane on @crtc, making sure that the pipe is running first.
2148 static void intel_disable_primary_hw_plane(struct drm_plane
*plane
,
2149 struct drm_crtc
*crtc
)
2151 struct drm_device
*dev
= plane
->dev
;
2152 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2153 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2155 assert_pipe_enabled(dev_priv
, intel_crtc
->pipe
);
2157 if (!intel_crtc
->primary_enabled
)
2160 intel_crtc
->primary_enabled
= false;
2162 dev_priv
->display
.update_primary_plane(crtc
, plane
->fb
,
2166 static bool need_vtd_wa(struct drm_device
*dev
)
2168 #ifdef CONFIG_INTEL_IOMMU
2169 if (INTEL_INFO(dev
)->gen
>= 6 && intel_iommu_gfx_mapped
)
2175 static int intel_align_height(struct drm_device
*dev
, int height
, bool tiled
)
2179 tile_height
= tiled
? (IS_GEN2(dev
) ? 16 : 8) : 1;
2180 return ALIGN(height
, tile_height
);
2184 intel_pin_and_fence_fb_obj(struct drm_device
*dev
,
2185 struct drm_i915_gem_object
*obj
,
2186 struct intel_engine_cs
*pipelined
)
2188 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2192 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
2194 switch (obj
->tiling_mode
) {
2195 case I915_TILING_NONE
:
2196 if (IS_BROADWATER(dev
) || IS_CRESTLINE(dev
))
2197 alignment
= 128 * 1024;
2198 else if (INTEL_INFO(dev
)->gen
>= 4)
2199 alignment
= 4 * 1024;
2201 alignment
= 64 * 1024;
2204 /* pin() will align the object as required by fence */
2208 WARN(1, "Y tiled bo slipped through, driver bug!\n");
2214 /* Note that the w/a also requires 64 PTE of padding following the
2215 * bo. We currently fill all unused PTE with the shadow page and so
2216 * we should always have valid PTE following the scanout preventing
2219 if (need_vtd_wa(dev
) && alignment
< 256 * 1024)
2220 alignment
= 256 * 1024;
2222 dev_priv
->mm
.interruptible
= false;
2223 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, pipelined
);
2225 goto err_interruptible
;
2227 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2228 * fence, whereas 965+ only requires a fence if using
2229 * framebuffer compression. For simplicity, we always install
2230 * a fence as the cost is not that onerous.
2232 ret
= i915_gem_object_get_fence(obj
);
2236 i915_gem_object_pin_fence(obj
);
2238 dev_priv
->mm
.interruptible
= true;
2242 i915_gem_object_unpin_from_display_plane(obj
);
2244 dev_priv
->mm
.interruptible
= true;
2248 void intel_unpin_fb_obj(struct drm_i915_gem_object
*obj
)
2250 WARN_ON(!mutex_is_locked(&obj
->base
.dev
->struct_mutex
));
2252 i915_gem_object_unpin_fence(obj
);
2253 i915_gem_object_unpin_from_display_plane(obj
);
2256 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
2257 * is assumed to be a power-of-two. */
2258 unsigned long intel_gen4_compute_page_offset(int *x
, int *y
,
2259 unsigned int tiling_mode
,
2263 if (tiling_mode
!= I915_TILING_NONE
) {
2264 unsigned int tile_rows
, tiles
;
2269 tiles
= *x
/ (512/cpp
);
2272 return tile_rows
* pitch
* 8 + tiles
* 4096;
2274 unsigned int offset
;
2276 offset
= *y
* pitch
+ *x
* cpp
;
2278 *x
= (offset
& 4095) / cpp
;
2279 return offset
& -4096;
2283 int intel_format_to_fourcc(int format
)
2286 case DISPPLANE_8BPP
:
2287 return DRM_FORMAT_C8
;
2288 case DISPPLANE_BGRX555
:
2289 return DRM_FORMAT_XRGB1555
;
2290 case DISPPLANE_BGRX565
:
2291 return DRM_FORMAT_RGB565
;
2293 case DISPPLANE_BGRX888
:
2294 return DRM_FORMAT_XRGB8888
;
2295 case DISPPLANE_RGBX888
:
2296 return DRM_FORMAT_XBGR8888
;
2297 case DISPPLANE_BGRX101010
:
2298 return DRM_FORMAT_XRGB2101010
;
2299 case DISPPLANE_RGBX101010
:
2300 return DRM_FORMAT_XBGR2101010
;
2304 static bool intel_alloc_plane_obj(struct intel_crtc
*crtc
,
2305 struct intel_plane_config
*plane_config
)
2307 struct drm_device
*dev
= crtc
->base
.dev
;
2308 struct drm_i915_gem_object
*obj
= NULL
;
2309 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2310 u32 base
= plane_config
->base
;
2312 if (plane_config
->size
== 0)
2315 obj
= i915_gem_object_create_stolen_for_preallocated(dev
, base
, base
,
2316 plane_config
->size
);
2320 if (plane_config
->tiled
) {
2321 obj
->tiling_mode
= I915_TILING_X
;
2322 obj
->stride
= crtc
->base
.primary
->fb
->pitches
[0];
2325 mode_cmd
.pixel_format
= crtc
->base
.primary
->fb
->pixel_format
;
2326 mode_cmd
.width
= crtc
->base
.primary
->fb
->width
;
2327 mode_cmd
.height
= crtc
->base
.primary
->fb
->height
;
2328 mode_cmd
.pitches
[0] = crtc
->base
.primary
->fb
->pitches
[0];
2330 mutex_lock(&dev
->struct_mutex
);
2332 if (intel_framebuffer_init(dev
, to_intel_framebuffer(crtc
->base
.primary
->fb
),
2334 DRM_DEBUG_KMS("intel fb init failed\n");
2338 obj
->frontbuffer_bits
= INTEL_FRONTBUFFER_PRIMARY(crtc
->pipe
);
2339 mutex_unlock(&dev
->struct_mutex
);
2341 DRM_DEBUG_KMS("plane fb obj %p\n", obj
);
2345 drm_gem_object_unreference(&obj
->base
);
2346 mutex_unlock(&dev
->struct_mutex
);
2350 static void intel_find_plane_obj(struct intel_crtc
*intel_crtc
,
2351 struct intel_plane_config
*plane_config
)
2353 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2355 struct intel_crtc
*i
;
2356 struct drm_i915_gem_object
*obj
;
2358 if (!intel_crtc
->base
.primary
->fb
)
2361 if (intel_alloc_plane_obj(intel_crtc
, plane_config
))
2364 kfree(intel_crtc
->base
.primary
->fb
);
2365 intel_crtc
->base
.primary
->fb
= NULL
;
2368 * Failed to alloc the obj, check to see if we should share
2369 * an fb with another CRTC instead
2371 for_each_crtc(dev
, c
) {
2372 i
= to_intel_crtc(c
);
2374 if (c
== &intel_crtc
->base
)
2380 obj
= intel_fb_obj(c
->primary
->fb
);
2384 if (i915_gem_obj_ggtt_offset(obj
) == plane_config
->base
) {
2385 drm_framebuffer_reference(c
->primary
->fb
);
2386 intel_crtc
->base
.primary
->fb
= c
->primary
->fb
;
2387 obj
->frontbuffer_bits
|= INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
);
2393 static void i9xx_update_primary_plane(struct drm_crtc
*crtc
,
2394 struct drm_framebuffer
*fb
,
2397 struct drm_device
*dev
= crtc
->dev
;
2398 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2399 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2400 struct drm_i915_gem_object
*obj
;
2401 int plane
= intel_crtc
->plane
;
2402 unsigned long linear_offset
;
2404 u32 reg
= DSPCNTR(plane
);
2407 if (!intel_crtc
->primary_enabled
) {
2409 if (INTEL_INFO(dev
)->gen
>= 4)
2410 I915_WRITE(DSPSURF(plane
), 0);
2412 I915_WRITE(DSPADDR(plane
), 0);
2417 obj
= intel_fb_obj(fb
);
2418 if (WARN_ON(obj
== NULL
))
2421 pixel_size
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2423 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2425 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2427 if (INTEL_INFO(dev
)->gen
< 4) {
2428 if (intel_crtc
->pipe
== PIPE_B
)
2429 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
2431 /* pipesrc and dspsize control the size that is scaled from,
2432 * which should always be the user's requested size.
2434 I915_WRITE(DSPSIZE(plane
),
2435 ((intel_crtc
->config
.pipe_src_h
- 1) << 16) |
2436 (intel_crtc
->config
.pipe_src_w
- 1));
2437 I915_WRITE(DSPPOS(plane
), 0);
2440 switch (fb
->pixel_format
) {
2442 dspcntr
|= DISPPLANE_8BPP
;
2444 case DRM_FORMAT_XRGB1555
:
2445 case DRM_FORMAT_ARGB1555
:
2446 dspcntr
|= DISPPLANE_BGRX555
;
2448 case DRM_FORMAT_RGB565
:
2449 dspcntr
|= DISPPLANE_BGRX565
;
2451 case DRM_FORMAT_XRGB8888
:
2452 case DRM_FORMAT_ARGB8888
:
2453 dspcntr
|= DISPPLANE_BGRX888
;
2455 case DRM_FORMAT_XBGR8888
:
2456 case DRM_FORMAT_ABGR8888
:
2457 dspcntr
|= DISPPLANE_RGBX888
;
2459 case DRM_FORMAT_XRGB2101010
:
2460 case DRM_FORMAT_ARGB2101010
:
2461 dspcntr
|= DISPPLANE_BGRX101010
;
2463 case DRM_FORMAT_XBGR2101010
:
2464 case DRM_FORMAT_ABGR2101010
:
2465 dspcntr
|= DISPPLANE_RGBX101010
;
2471 if (INTEL_INFO(dev
)->gen
>= 4 &&
2472 obj
->tiling_mode
!= I915_TILING_NONE
)
2473 dspcntr
|= DISPPLANE_TILED
;
2476 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2478 linear_offset
= y
* fb
->pitches
[0] + x
* pixel_size
;
2480 if (INTEL_INFO(dev
)->gen
>= 4) {
2481 intel_crtc
->dspaddr_offset
=
2482 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2485 linear_offset
-= intel_crtc
->dspaddr_offset
;
2487 intel_crtc
->dspaddr_offset
= linear_offset
;
2490 if (to_intel_plane(crtc
->primary
)->rotation
== BIT(DRM_ROTATE_180
)) {
2491 dspcntr
|= DISPPLANE_ROTATE_180
;
2493 x
+= (intel_crtc
->config
.pipe_src_w
- 1);
2494 y
+= (intel_crtc
->config
.pipe_src_h
- 1);
2496 /* Finding the last pixel of the last line of the display
2497 data and adding to linear_offset*/
2499 (intel_crtc
->config
.pipe_src_h
- 1) * fb
->pitches
[0] +
2500 (intel_crtc
->config
.pipe_src_w
- 1) * pixel_size
;
2503 I915_WRITE(reg
, dspcntr
);
2505 DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
2506 i915_gem_obj_ggtt_offset(obj
), linear_offset
, x
, y
,
2508 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2509 if (INTEL_INFO(dev
)->gen
>= 4) {
2510 I915_WRITE(DSPSURF(plane
),
2511 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2512 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2513 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2515 I915_WRITE(DSPADDR(plane
), i915_gem_obj_ggtt_offset(obj
) + linear_offset
);
2519 static void ironlake_update_primary_plane(struct drm_crtc
*crtc
,
2520 struct drm_framebuffer
*fb
,
2523 struct drm_device
*dev
= crtc
->dev
;
2524 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2525 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2526 struct drm_i915_gem_object
*obj
;
2527 int plane
= intel_crtc
->plane
;
2528 unsigned long linear_offset
;
2530 u32 reg
= DSPCNTR(plane
);
2533 if (!intel_crtc
->primary_enabled
) {
2535 I915_WRITE(DSPSURF(plane
), 0);
2540 obj
= intel_fb_obj(fb
);
2541 if (WARN_ON(obj
== NULL
))
2544 pixel_size
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2546 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2548 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2550 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2551 dspcntr
|= DISPPLANE_PIPE_CSC_ENABLE
;
2553 switch (fb
->pixel_format
) {
2555 dspcntr
|= DISPPLANE_8BPP
;
2557 case DRM_FORMAT_RGB565
:
2558 dspcntr
|= DISPPLANE_BGRX565
;
2560 case DRM_FORMAT_XRGB8888
:
2561 case DRM_FORMAT_ARGB8888
:
2562 dspcntr
|= DISPPLANE_BGRX888
;
2564 case DRM_FORMAT_XBGR8888
:
2565 case DRM_FORMAT_ABGR8888
:
2566 dspcntr
|= DISPPLANE_RGBX888
;
2568 case DRM_FORMAT_XRGB2101010
:
2569 case DRM_FORMAT_ARGB2101010
:
2570 dspcntr
|= DISPPLANE_BGRX101010
;
2572 case DRM_FORMAT_XBGR2101010
:
2573 case DRM_FORMAT_ABGR2101010
:
2574 dspcntr
|= DISPPLANE_RGBX101010
;
2580 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2581 dspcntr
|= DISPPLANE_TILED
;
2583 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
))
2584 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2586 linear_offset
= y
* fb
->pitches
[0] + x
* pixel_size
;
2587 intel_crtc
->dspaddr_offset
=
2588 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2591 linear_offset
-= intel_crtc
->dspaddr_offset
;
2592 if (to_intel_plane(crtc
->primary
)->rotation
== BIT(DRM_ROTATE_180
)) {
2593 dspcntr
|= DISPPLANE_ROTATE_180
;
2595 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
)) {
2596 x
+= (intel_crtc
->config
.pipe_src_w
- 1);
2597 y
+= (intel_crtc
->config
.pipe_src_h
- 1);
2599 /* Finding the last pixel of the last line of the display
2600 data and adding to linear_offset*/
2602 (intel_crtc
->config
.pipe_src_h
- 1) * fb
->pitches
[0] +
2603 (intel_crtc
->config
.pipe_src_w
- 1) * pixel_size
;
2607 I915_WRITE(reg
, dspcntr
);
2609 DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
2610 i915_gem_obj_ggtt_offset(obj
), linear_offset
, x
, y
,
2612 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2613 I915_WRITE(DSPSURF(plane
),
2614 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2615 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2616 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
2618 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2619 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2624 /* Assume fb object is pinned & idle & fenced and just update base pointers */
2626 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
2627 int x
, int y
, enum mode_set_atomic state
)
2629 struct drm_device
*dev
= crtc
->dev
;
2630 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2632 if (dev_priv
->display
.disable_fbc
)
2633 dev_priv
->display
.disable_fbc(dev
);
2634 intel_increase_pllclock(dev
, to_intel_crtc(crtc
)->pipe
);
2636 dev_priv
->display
.update_primary_plane(crtc
, fb
, x
, y
);
2641 void intel_display_handle_reset(struct drm_device
*dev
)
2643 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2644 struct drm_crtc
*crtc
;
2647 * Flips in the rings have been nuked by the reset,
2648 * so complete all pending flips so that user space
2649 * will get its events and not get stuck.
2651 * Also update the base address of all primary
2652 * planes to the the last fb to make sure we're
2653 * showing the correct fb after a reset.
2655 * Need to make two loops over the crtcs so that we
2656 * don't try to grab a crtc mutex before the
2657 * pending_flip_queue really got woken up.
2660 for_each_crtc(dev
, crtc
) {
2661 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2662 enum plane plane
= intel_crtc
->plane
;
2664 intel_prepare_page_flip(dev
, plane
);
2665 intel_finish_page_flip_plane(dev
, plane
);
2668 for_each_crtc(dev
, crtc
) {
2669 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2671 drm_modeset_lock(&crtc
->mutex
, NULL
);
2673 * FIXME: Once we have proper support for primary planes (and
2674 * disabling them without disabling the entire crtc) allow again
2675 * a NULL crtc->primary->fb.
2677 if (intel_crtc
->active
&& crtc
->primary
->fb
)
2678 dev_priv
->display
.update_primary_plane(crtc
,
2682 drm_modeset_unlock(&crtc
->mutex
);
2687 intel_finish_fb(struct drm_framebuffer
*old_fb
)
2689 struct drm_i915_gem_object
*obj
= intel_fb_obj(old_fb
);
2690 struct drm_i915_private
*dev_priv
= obj
->base
.dev
->dev_private
;
2691 bool was_interruptible
= dev_priv
->mm
.interruptible
;
2694 /* Big Hammer, we also need to ensure that any pending
2695 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
2696 * current scanout is retired before unpinning the old
2699 * This should only fail upon a hung GPU, in which case we
2700 * can safely continue.
2702 dev_priv
->mm
.interruptible
= false;
2703 ret
= i915_gem_object_finish_gpu(obj
);
2704 dev_priv
->mm
.interruptible
= was_interruptible
;
2709 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
2711 struct drm_device
*dev
= crtc
->dev
;
2712 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2713 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2714 unsigned long flags
;
2717 if (i915_reset_in_progress(&dev_priv
->gpu_error
) ||
2718 intel_crtc
->reset_counter
!= atomic_read(&dev_priv
->gpu_error
.reset_counter
))
2721 spin_lock_irqsave(&dev
->event_lock
, flags
);
2722 pending
= to_intel_crtc(crtc
)->unpin_work
!= NULL
;
2723 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2729 intel_pipe_set_base(struct drm_crtc
*crtc
, int x
, int y
,
2730 struct drm_framebuffer
*fb
)
2732 struct drm_device
*dev
= crtc
->dev
;
2733 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2734 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2735 enum pipe pipe
= intel_crtc
->pipe
;
2736 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
2737 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2738 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(old_fb
);
2741 if (intel_crtc_has_pending_flip(crtc
)) {
2742 DRM_ERROR("pipe is still busy with an old pageflip\n");
2748 DRM_ERROR("No FB bound\n");
2752 if (intel_crtc
->plane
> INTEL_INFO(dev
)->num_pipes
) {
2753 DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
2754 plane_name(intel_crtc
->plane
),
2755 INTEL_INFO(dev
)->num_pipes
);
2759 mutex_lock(&dev
->struct_mutex
);
2760 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, NULL
);
2762 i915_gem_track_fb(old_obj
, obj
,
2763 INTEL_FRONTBUFFER_PRIMARY(pipe
));
2764 mutex_unlock(&dev
->struct_mutex
);
2766 DRM_ERROR("pin & fence failed\n");
2771 * Update pipe size and adjust fitter if needed: the reason for this is
2772 * that in compute_mode_changes we check the native mode (not the pfit
2773 * mode) to see if we can flip rather than do a full mode set. In the
2774 * fastboot case, we'll flip, but if we don't update the pipesrc and
2775 * pfit state, we'll end up with a big fb scanned out into the wrong
2778 * To fix this properly, we need to hoist the checks up into
2779 * compute_mode_changes (or above), check the actual pfit state and
2780 * whether the platform allows pfit disable with pipe active, and only
2781 * then update the pipesrc and pfit state, even on the flip path.
2783 if (i915
.fastboot
) {
2784 const struct drm_display_mode
*adjusted_mode
=
2785 &intel_crtc
->config
.adjusted_mode
;
2787 I915_WRITE(PIPESRC(intel_crtc
->pipe
),
2788 ((adjusted_mode
->crtc_hdisplay
- 1) << 16) |
2789 (adjusted_mode
->crtc_vdisplay
- 1));
2790 if (!intel_crtc
->config
.pch_pfit
.enabled
&&
2791 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) ||
2792 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
2793 I915_WRITE(PF_CTL(intel_crtc
->pipe
), 0);
2794 I915_WRITE(PF_WIN_POS(intel_crtc
->pipe
), 0);
2795 I915_WRITE(PF_WIN_SZ(intel_crtc
->pipe
), 0);
2797 intel_crtc
->config
.pipe_src_w
= adjusted_mode
->crtc_hdisplay
;
2798 intel_crtc
->config
.pipe_src_h
= adjusted_mode
->crtc_vdisplay
;
2801 dev_priv
->display
.update_primary_plane(crtc
, fb
, x
, y
);
2803 if (intel_crtc
->active
)
2804 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
2806 crtc
->primary
->fb
= fb
;
2811 if (intel_crtc
->active
&& old_fb
!= fb
)
2812 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
2813 mutex_lock(&dev
->struct_mutex
);
2814 intel_unpin_fb_obj(old_obj
);
2815 mutex_unlock(&dev
->struct_mutex
);
2818 mutex_lock(&dev
->struct_mutex
);
2819 intel_update_fbc(dev
);
2820 mutex_unlock(&dev
->struct_mutex
);
2825 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
2827 struct drm_device
*dev
= crtc
->dev
;
2828 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2829 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2830 int pipe
= intel_crtc
->pipe
;
2833 /* enable normal train */
2834 reg
= FDI_TX_CTL(pipe
);
2835 temp
= I915_READ(reg
);
2836 if (IS_IVYBRIDGE(dev
)) {
2837 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
2838 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2840 temp
&= ~FDI_LINK_TRAIN_NONE
;
2841 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2843 I915_WRITE(reg
, temp
);
2845 reg
= FDI_RX_CTL(pipe
);
2846 temp
= I915_READ(reg
);
2847 if (HAS_PCH_CPT(dev
)) {
2848 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2849 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
2851 temp
&= ~FDI_LINK_TRAIN_NONE
;
2852 temp
|= FDI_LINK_TRAIN_NONE
;
2854 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
2856 /* wait one idle pattern time */
2860 /* IVB wants error correction enabled */
2861 if (IS_IVYBRIDGE(dev
))
2862 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
2863 FDI_FE_ERRC_ENABLE
);
2866 static bool pipe_has_enabled_pch(struct intel_crtc
*crtc
)
2868 return crtc
->base
.enabled
&& crtc
->active
&&
2869 crtc
->config
.has_pch_encoder
;
2872 static void ivb_modeset_global_resources(struct drm_device
*dev
)
2874 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2875 struct intel_crtc
*pipe_B_crtc
=
2876 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
2877 struct intel_crtc
*pipe_C_crtc
=
2878 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]);
2882 * When everything is off disable fdi C so that we could enable fdi B
2883 * with all lanes. Note that we don't care about enabled pipes without
2884 * an enabled pch encoder.
2886 if (!pipe_has_enabled_pch(pipe_B_crtc
) &&
2887 !pipe_has_enabled_pch(pipe_C_crtc
)) {
2888 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
2889 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
2891 temp
= I915_READ(SOUTH_CHICKEN1
);
2892 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
2893 DRM_DEBUG_KMS("disabling fdi C rx\n");
2894 I915_WRITE(SOUTH_CHICKEN1
, temp
);
2898 /* The FDI link training functions for ILK/Ibexpeak. */
2899 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
2901 struct drm_device
*dev
= crtc
->dev
;
2902 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2903 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2904 int pipe
= intel_crtc
->pipe
;
2905 u32 reg
, temp
, tries
;
2907 /* FDI needs bits from pipe first */
2908 assert_pipe_enabled(dev_priv
, pipe
);
2910 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2912 reg
= FDI_RX_IMR(pipe
);
2913 temp
= I915_READ(reg
);
2914 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2915 temp
&= ~FDI_RX_BIT_LOCK
;
2916 I915_WRITE(reg
, temp
);
2920 /* enable CPU FDI TX and PCH FDI RX */
2921 reg
= FDI_TX_CTL(pipe
);
2922 temp
= I915_READ(reg
);
2923 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
2924 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
2925 temp
&= ~FDI_LINK_TRAIN_NONE
;
2926 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2927 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2929 reg
= FDI_RX_CTL(pipe
);
2930 temp
= I915_READ(reg
);
2931 temp
&= ~FDI_LINK_TRAIN_NONE
;
2932 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2933 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
2938 /* Ironlake workaround, enable clock pointer after FDI enable*/
2939 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
2940 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
2941 FDI_RX_PHASE_SYNC_POINTER_EN
);
2943 reg
= FDI_RX_IIR(pipe
);
2944 for (tries
= 0; tries
< 5; tries
++) {
2945 temp
= I915_READ(reg
);
2946 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2948 if ((temp
& FDI_RX_BIT_LOCK
)) {
2949 DRM_DEBUG_KMS("FDI train 1 done.\n");
2950 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
2955 DRM_ERROR("FDI train 1 fail!\n");
2958 reg
= FDI_TX_CTL(pipe
);
2959 temp
= I915_READ(reg
);
2960 temp
&= ~FDI_LINK_TRAIN_NONE
;
2961 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2962 I915_WRITE(reg
, temp
);
2964 reg
= FDI_RX_CTL(pipe
);
2965 temp
= I915_READ(reg
);
2966 temp
&= ~FDI_LINK_TRAIN_NONE
;
2967 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2968 I915_WRITE(reg
, temp
);
2973 reg
= FDI_RX_IIR(pipe
);
2974 for (tries
= 0; tries
< 5; tries
++) {
2975 temp
= I915_READ(reg
);
2976 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2978 if (temp
& FDI_RX_SYMBOL_LOCK
) {
2979 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
2980 DRM_DEBUG_KMS("FDI train 2 done.\n");
2985 DRM_ERROR("FDI train 2 fail!\n");
2987 DRM_DEBUG_KMS("FDI train done\n");
2991 static const int snb_b_fdi_train_param
[] = {
2992 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
2993 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
2994 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
2995 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
2998 /* The FDI link training functions for SNB/Cougarpoint. */
2999 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
3001 struct drm_device
*dev
= crtc
->dev
;
3002 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3003 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3004 int pipe
= intel_crtc
->pipe
;
3005 u32 reg
, temp
, i
, retry
;
3007 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3009 reg
= FDI_RX_IMR(pipe
);
3010 temp
= I915_READ(reg
);
3011 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3012 temp
&= ~FDI_RX_BIT_LOCK
;
3013 I915_WRITE(reg
, temp
);
3018 /* enable CPU FDI TX and PCH FDI RX */
3019 reg
= FDI_TX_CTL(pipe
);
3020 temp
= I915_READ(reg
);
3021 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3022 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
3023 temp
&= ~FDI_LINK_TRAIN_NONE
;
3024 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3025 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3027 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3028 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3030 I915_WRITE(FDI_RX_MISC(pipe
),
3031 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3033 reg
= FDI_RX_CTL(pipe
);
3034 temp
= I915_READ(reg
);
3035 if (HAS_PCH_CPT(dev
)) {
3036 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3037 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3039 temp
&= ~FDI_LINK_TRAIN_NONE
;
3040 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3042 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3047 for (i
= 0; i
< 4; i
++) {
3048 reg
= FDI_TX_CTL(pipe
);
3049 temp
= I915_READ(reg
);
3050 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3051 temp
|= snb_b_fdi_train_param
[i
];
3052 I915_WRITE(reg
, temp
);
3057 for (retry
= 0; retry
< 5; retry
++) {
3058 reg
= FDI_RX_IIR(pipe
);
3059 temp
= I915_READ(reg
);
3060 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3061 if (temp
& FDI_RX_BIT_LOCK
) {
3062 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3063 DRM_DEBUG_KMS("FDI train 1 done.\n");
3072 DRM_ERROR("FDI train 1 fail!\n");
3075 reg
= FDI_TX_CTL(pipe
);
3076 temp
= I915_READ(reg
);
3077 temp
&= ~FDI_LINK_TRAIN_NONE
;
3078 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3080 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3082 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3084 I915_WRITE(reg
, temp
);
3086 reg
= FDI_RX_CTL(pipe
);
3087 temp
= I915_READ(reg
);
3088 if (HAS_PCH_CPT(dev
)) {
3089 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3090 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3092 temp
&= ~FDI_LINK_TRAIN_NONE
;
3093 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3095 I915_WRITE(reg
, temp
);
3100 for (i
= 0; i
< 4; i
++) {
3101 reg
= FDI_TX_CTL(pipe
);
3102 temp
= I915_READ(reg
);
3103 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3104 temp
|= snb_b_fdi_train_param
[i
];
3105 I915_WRITE(reg
, temp
);
3110 for (retry
= 0; retry
< 5; retry
++) {
3111 reg
= FDI_RX_IIR(pipe
);
3112 temp
= I915_READ(reg
);
3113 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3114 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3115 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3116 DRM_DEBUG_KMS("FDI train 2 done.\n");
3125 DRM_ERROR("FDI train 2 fail!\n");
3127 DRM_DEBUG_KMS("FDI train done.\n");
3130 /* Manual link training for Ivy Bridge A0 parts */
3131 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
3133 struct drm_device
*dev
= crtc
->dev
;
3134 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3135 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3136 int pipe
= intel_crtc
->pipe
;
3137 u32 reg
, temp
, i
, j
;
3139 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3141 reg
= FDI_RX_IMR(pipe
);
3142 temp
= I915_READ(reg
);
3143 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3144 temp
&= ~FDI_RX_BIT_LOCK
;
3145 I915_WRITE(reg
, temp
);
3150 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3151 I915_READ(FDI_RX_IIR(pipe
)));
3153 /* Try each vswing and preemphasis setting twice before moving on */
3154 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
3155 /* disable first in case we need to retry */
3156 reg
= FDI_TX_CTL(pipe
);
3157 temp
= I915_READ(reg
);
3158 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
3159 temp
&= ~FDI_TX_ENABLE
;
3160 I915_WRITE(reg
, temp
);
3162 reg
= FDI_RX_CTL(pipe
);
3163 temp
= I915_READ(reg
);
3164 temp
&= ~FDI_LINK_TRAIN_AUTO
;
3165 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3166 temp
&= ~FDI_RX_ENABLE
;
3167 I915_WRITE(reg
, temp
);
3169 /* enable CPU FDI TX and PCH FDI RX */
3170 reg
= FDI_TX_CTL(pipe
);
3171 temp
= I915_READ(reg
);
3172 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3173 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
3174 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
3175 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3176 temp
|= snb_b_fdi_train_param
[j
/2];
3177 temp
|= FDI_COMPOSITE_SYNC
;
3178 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3180 I915_WRITE(FDI_RX_MISC(pipe
),
3181 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3183 reg
= FDI_RX_CTL(pipe
);
3184 temp
= I915_READ(reg
);
3185 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3186 temp
|= FDI_COMPOSITE_SYNC
;
3187 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3190 udelay(1); /* should be 0.5us */
3192 for (i
= 0; i
< 4; i
++) {
3193 reg
= FDI_RX_IIR(pipe
);
3194 temp
= I915_READ(reg
);
3195 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3197 if (temp
& FDI_RX_BIT_LOCK
||
3198 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
3199 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3200 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3204 udelay(1); /* should be 0.5us */
3207 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
3212 reg
= FDI_TX_CTL(pipe
);
3213 temp
= I915_READ(reg
);
3214 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3215 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
3216 I915_WRITE(reg
, temp
);
3218 reg
= FDI_RX_CTL(pipe
);
3219 temp
= I915_READ(reg
);
3220 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3221 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3222 I915_WRITE(reg
, temp
);
3225 udelay(2); /* should be 1.5us */
3227 for (i
= 0; i
< 4; i
++) {
3228 reg
= FDI_RX_IIR(pipe
);
3229 temp
= I915_READ(reg
);
3230 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3232 if (temp
& FDI_RX_SYMBOL_LOCK
||
3233 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
3234 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3235 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
3239 udelay(2); /* should be 1.5us */
3242 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
3246 DRM_DEBUG_KMS("FDI train done.\n");
3249 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
3251 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3252 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3253 int pipe
= intel_crtc
->pipe
;
3257 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
3258 reg
= FDI_RX_CTL(pipe
);
3259 temp
= I915_READ(reg
);
3260 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
3261 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
3262 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3263 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
3268 /* Switch from Rawclk to PCDclk */
3269 temp
= I915_READ(reg
);
3270 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
3275 /* Enable CPU FDI TX PLL, always on for Ironlake */
3276 reg
= FDI_TX_CTL(pipe
);
3277 temp
= I915_READ(reg
);
3278 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
3279 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
3286 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
3288 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3289 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3290 int pipe
= intel_crtc
->pipe
;
3293 /* Switch from PCDclk to Rawclk */
3294 reg
= FDI_RX_CTL(pipe
);
3295 temp
= I915_READ(reg
);
3296 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
3298 /* Disable CPU FDI TX PLL */
3299 reg
= FDI_TX_CTL(pipe
);
3300 temp
= I915_READ(reg
);
3301 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
3306 reg
= FDI_RX_CTL(pipe
);
3307 temp
= I915_READ(reg
);
3308 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
3310 /* Wait for the clocks to turn off. */
3315 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
3317 struct drm_device
*dev
= crtc
->dev
;
3318 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3319 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3320 int pipe
= intel_crtc
->pipe
;
3323 /* disable CPU FDI tx and PCH FDI rx */
3324 reg
= FDI_TX_CTL(pipe
);
3325 temp
= I915_READ(reg
);
3326 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
3329 reg
= FDI_RX_CTL(pipe
);
3330 temp
= I915_READ(reg
);
3331 temp
&= ~(0x7 << 16);
3332 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3333 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
3338 /* Ironlake workaround, disable clock pointer after downing FDI */
3339 if (HAS_PCH_IBX(dev
))
3340 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3342 /* still set train pattern 1 */
3343 reg
= FDI_TX_CTL(pipe
);
3344 temp
= I915_READ(reg
);
3345 temp
&= ~FDI_LINK_TRAIN_NONE
;
3346 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3347 I915_WRITE(reg
, temp
);
3349 reg
= FDI_RX_CTL(pipe
);
3350 temp
= I915_READ(reg
);
3351 if (HAS_PCH_CPT(dev
)) {
3352 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3353 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3355 temp
&= ~FDI_LINK_TRAIN_NONE
;
3356 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3358 /* BPC in FDI rx is consistent with that in PIPECONF */
3359 temp
&= ~(0x07 << 16);
3360 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3361 I915_WRITE(reg
, temp
);
3367 bool intel_has_pending_fb_unpin(struct drm_device
*dev
)
3369 struct intel_crtc
*crtc
;
3371 /* Note that we don't need to be called with mode_config.lock here
3372 * as our list of CRTC objects is static for the lifetime of the
3373 * device and so cannot disappear as we iterate. Similarly, we can
3374 * happily treat the predicates as racy, atomic checks as userspace
3375 * cannot claim and pin a new fb without at least acquring the
3376 * struct_mutex and so serialising with us.
3378 for_each_intel_crtc(dev
, crtc
) {
3379 if (atomic_read(&crtc
->unpin_work_count
) == 0)
3382 if (crtc
->unpin_work
)
3383 intel_wait_for_vblank(dev
, crtc
->pipe
);
3391 static void page_flip_completed(struct intel_crtc
*intel_crtc
)
3393 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
3394 struct intel_unpin_work
*work
= intel_crtc
->unpin_work
;
3396 /* ensure that the unpin work is consistent wrt ->pending. */
3398 intel_crtc
->unpin_work
= NULL
;
3401 drm_send_vblank_event(intel_crtc
->base
.dev
,
3405 drm_crtc_vblank_put(&intel_crtc
->base
);
3407 wake_up_all(&dev_priv
->pending_flip_queue
);
3408 queue_work(dev_priv
->wq
, &work
->work
);
3410 trace_i915_flip_complete(intel_crtc
->plane
,
3411 work
->pending_flip_obj
);
3414 void intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
3416 struct drm_device
*dev
= crtc
->dev
;
3417 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3419 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
3420 WARN_ON(wait_event_timeout(dev_priv
->pending_flip_queue
,
3421 !intel_crtc_has_pending_flip(crtc
),
3424 if (crtc
->primary
->fb
) {
3425 mutex_lock(&dev
->struct_mutex
);
3426 intel_finish_fb(crtc
->primary
->fb
);
3427 mutex_unlock(&dev
->struct_mutex
);
3431 /* Program iCLKIP clock to the desired frequency */
3432 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
3434 struct drm_device
*dev
= crtc
->dev
;
3435 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3436 int clock
= to_intel_crtc(crtc
)->config
.adjusted_mode
.crtc_clock
;
3437 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
3440 mutex_lock(&dev_priv
->dpio_lock
);
3442 /* It is necessary to ungate the pixclk gate prior to programming
3443 * the divisors, and gate it back when it is done.
3445 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
3447 /* Disable SSCCTL */
3448 intel_sbi_write(dev_priv
, SBI_SSCCTL6
,
3449 intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
) |
3453 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
3454 if (clock
== 20000) {
3459 /* The iCLK virtual clock root frequency is in MHz,
3460 * but the adjusted_mode->crtc_clock in in KHz. To get the
3461 * divisors, it is necessary to divide one by another, so we
3462 * convert the virtual clock precision to KHz here for higher
3465 u32 iclk_virtual_root_freq
= 172800 * 1000;
3466 u32 iclk_pi_range
= 64;
3467 u32 desired_divisor
, msb_divisor_value
, pi_value
;
3469 desired_divisor
= (iclk_virtual_root_freq
/ clock
);
3470 msb_divisor_value
= desired_divisor
/ iclk_pi_range
;
3471 pi_value
= desired_divisor
% iclk_pi_range
;
3474 divsel
= msb_divisor_value
- 2;
3475 phaseinc
= pi_value
;
3478 /* This should not happen with any sane values */
3479 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
3480 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
3481 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
3482 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
3484 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3491 /* Program SSCDIVINTPHASE6 */
3492 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
3493 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
3494 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
3495 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
3496 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
3497 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
3498 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
3499 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
3501 /* Program SSCAUXDIV */
3502 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
3503 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3504 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
3505 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
3507 /* Enable modulator and associated divider */
3508 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
3509 temp
&= ~SBI_SSCCTL_DISABLE
;
3510 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
3512 /* Wait for initialization time */
3515 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
3517 mutex_unlock(&dev_priv
->dpio_lock
);
3520 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
3521 enum pipe pch_transcoder
)
3523 struct drm_device
*dev
= crtc
->base
.dev
;
3524 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3525 enum transcoder cpu_transcoder
= crtc
->config
.cpu_transcoder
;
3527 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
3528 I915_READ(HTOTAL(cpu_transcoder
)));
3529 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
3530 I915_READ(HBLANK(cpu_transcoder
)));
3531 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
3532 I915_READ(HSYNC(cpu_transcoder
)));
3534 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
3535 I915_READ(VTOTAL(cpu_transcoder
)));
3536 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
3537 I915_READ(VBLANK(cpu_transcoder
)));
3538 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
3539 I915_READ(VSYNC(cpu_transcoder
)));
3540 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
3541 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
3544 static void cpt_enable_fdi_bc_bifurcation(struct drm_device
*dev
)
3546 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3549 temp
= I915_READ(SOUTH_CHICKEN1
);
3550 if (temp
& FDI_BC_BIFURCATION_SELECT
)
3553 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
3554 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
3556 temp
|= FDI_BC_BIFURCATION_SELECT
;
3557 DRM_DEBUG_KMS("enabling fdi C rx\n");
3558 I915_WRITE(SOUTH_CHICKEN1
, temp
);
3559 POSTING_READ(SOUTH_CHICKEN1
);
3562 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
3564 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3565 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3567 switch (intel_crtc
->pipe
) {
3571 if (intel_crtc
->config
.fdi_lanes
> 2)
3572 WARN_ON(I915_READ(SOUTH_CHICKEN1
) & FDI_BC_BIFURCATION_SELECT
);
3574 cpt_enable_fdi_bc_bifurcation(dev
);
3578 cpt_enable_fdi_bc_bifurcation(dev
);
3587 * Enable PCH resources required for PCH ports:
3589 * - FDI training & RX/TX
3590 * - update transcoder timings
3591 * - DP transcoding bits
3594 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
3596 struct drm_device
*dev
= crtc
->dev
;
3597 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3598 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3599 int pipe
= intel_crtc
->pipe
;
3602 assert_pch_transcoder_disabled(dev_priv
, pipe
);
3604 if (IS_IVYBRIDGE(dev
))
3605 ivybridge_update_fdi_bc_bifurcation(intel_crtc
);
3607 /* Write the TU size bits before fdi link training, so that error
3608 * detection works. */
3609 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
3610 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
3612 /* For PCH output, training FDI link */
3613 dev_priv
->display
.fdi_link_train(crtc
);
3615 /* We need to program the right clock selection before writing the pixel
3616 * mutliplier into the DPLL. */
3617 if (HAS_PCH_CPT(dev
)) {
3620 temp
= I915_READ(PCH_DPLL_SEL
);
3621 temp
|= TRANS_DPLL_ENABLE(pipe
);
3622 sel
= TRANS_DPLLB_SEL(pipe
);
3623 if (intel_crtc
->config
.shared_dpll
== DPLL_ID_PCH_PLL_B
)
3627 I915_WRITE(PCH_DPLL_SEL
, temp
);
3630 /* XXX: pch pll's can be enabled any time before we enable the PCH
3631 * transcoder, and we actually should do this to not upset any PCH
3632 * transcoder that already use the clock when we share it.
3634 * Note that enable_shared_dpll tries to do the right thing, but
3635 * get_shared_dpll unconditionally resets the pll - we need that to have
3636 * the right LVDS enable sequence. */
3637 intel_enable_shared_dpll(intel_crtc
);
3639 /* set transcoder timing, panel must allow it */
3640 assert_panel_unlocked(dev_priv
, pipe
);
3641 ironlake_pch_transcoder_set_timings(intel_crtc
, pipe
);
3643 intel_fdi_normal_train(crtc
);
3645 /* For PCH DP, enable TRANS_DP_CTL */
3646 if (HAS_PCH_CPT(dev
) &&
3647 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
3648 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
3649 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
3650 reg
= TRANS_DP_CTL(pipe
);
3651 temp
= I915_READ(reg
);
3652 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
3653 TRANS_DP_SYNC_MASK
|
3655 temp
|= (TRANS_DP_OUTPUT_ENABLE
|
3656 TRANS_DP_ENH_FRAMING
);
3657 temp
|= bpc
<< 9; /* same format but at 11:9 */
3659 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PHSYNC
)
3660 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
3661 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PVSYNC
)
3662 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
3664 switch (intel_trans_dp_port_sel(crtc
)) {
3666 temp
|= TRANS_DP_PORT_SEL_B
;
3669 temp
|= TRANS_DP_PORT_SEL_C
;
3672 temp
|= TRANS_DP_PORT_SEL_D
;
3678 I915_WRITE(reg
, temp
);
3681 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
3684 static void lpt_pch_enable(struct drm_crtc
*crtc
)
3686 struct drm_device
*dev
= crtc
->dev
;
3687 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3688 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3689 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
3691 assert_pch_transcoder_disabled(dev_priv
, TRANSCODER_A
);
3693 lpt_program_iclkip(crtc
);
3695 /* Set transcoder timing. */
3696 ironlake_pch_transcoder_set_timings(intel_crtc
, PIPE_A
);
3698 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
3701 void intel_put_shared_dpll(struct intel_crtc
*crtc
)
3703 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
3708 if (pll
->refcount
== 0) {
3709 WARN(1, "bad %s refcount\n", pll
->name
);
3713 if (--pll
->refcount
== 0) {
3715 WARN_ON(pll
->active
);
3718 crtc
->config
.shared_dpll
= DPLL_ID_PRIVATE
;
3721 struct intel_shared_dpll
*intel_get_shared_dpll(struct intel_crtc
*crtc
)
3723 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
3724 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
3725 enum intel_dpll_id i
;
3728 DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
3729 crtc
->base
.base
.id
, pll
->name
);
3730 intel_put_shared_dpll(crtc
);
3733 if (HAS_PCH_IBX(dev_priv
->dev
)) {
3734 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
3735 i
= (enum intel_dpll_id
) crtc
->pipe
;
3736 pll
= &dev_priv
->shared_dplls
[i
];
3738 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
3739 crtc
->base
.base
.id
, pll
->name
);
3741 WARN_ON(pll
->refcount
);
3746 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
3747 pll
= &dev_priv
->shared_dplls
[i
];
3749 /* Only want to check enabled timings first */
3750 if (pll
->refcount
== 0)
3753 if (memcmp(&crtc
->config
.dpll_hw_state
, &pll
->hw_state
,
3754 sizeof(pll
->hw_state
)) == 0) {
3755 DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
3757 pll
->name
, pll
->refcount
, pll
->active
);
3763 /* Ok no matching timings, maybe there's a free one? */
3764 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
3765 pll
= &dev_priv
->shared_dplls
[i
];
3766 if (pll
->refcount
== 0) {
3767 DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
3768 crtc
->base
.base
.id
, pll
->name
);
3776 if (pll
->refcount
== 0)
3777 pll
->hw_state
= crtc
->config
.dpll_hw_state
;
3779 crtc
->config
.shared_dpll
= i
;
3780 DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll
->name
,
3781 pipe_name(crtc
->pipe
));
3788 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
3790 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3791 int dslreg
= PIPEDSL(pipe
);
3794 temp
= I915_READ(dslreg
);
3796 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
3797 if (wait_for(I915_READ(dslreg
) != temp
, 5))
3798 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
3802 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
3804 struct drm_device
*dev
= crtc
->base
.dev
;
3805 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3806 int pipe
= crtc
->pipe
;
3808 if (crtc
->config
.pch_pfit
.enabled
) {
3809 /* Force use of hard-coded filter coefficients
3810 * as some pre-programmed values are broken,
3813 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
))
3814 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
3815 PF_PIPE_SEL_IVB(pipe
));
3817 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
3818 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
.pch_pfit
.pos
);
3819 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
.pch_pfit
.size
);
3823 static void intel_enable_planes(struct drm_crtc
*crtc
)
3825 struct drm_device
*dev
= crtc
->dev
;
3826 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
3827 struct drm_plane
*plane
;
3828 struct intel_plane
*intel_plane
;
3830 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
3831 intel_plane
= to_intel_plane(plane
);
3832 if (intel_plane
->pipe
== pipe
)
3833 intel_plane_restore(&intel_plane
->base
);
3837 static void intel_disable_planes(struct drm_crtc
*crtc
)
3839 struct drm_device
*dev
= crtc
->dev
;
3840 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
3841 struct drm_plane
*plane
;
3842 struct intel_plane
*intel_plane
;
3844 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
3845 intel_plane
= to_intel_plane(plane
);
3846 if (intel_plane
->pipe
== pipe
)
3847 intel_plane_disable(&intel_plane
->base
);
3851 void hsw_enable_ips(struct intel_crtc
*crtc
)
3853 struct drm_device
*dev
= crtc
->base
.dev
;
3854 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3856 if (!crtc
->config
.ips_enabled
)
3859 /* We can only enable IPS after we enable a plane and wait for a vblank */
3860 intel_wait_for_vblank(dev
, crtc
->pipe
);
3862 assert_plane_enabled(dev_priv
, crtc
->plane
);
3863 if (IS_BROADWELL(dev
)) {
3864 mutex_lock(&dev_priv
->rps
.hw_lock
);
3865 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
3866 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3867 /* Quoting Art Runyan: "its not safe to expect any particular
3868 * value in IPS_CTL bit 31 after enabling IPS through the
3869 * mailbox." Moreover, the mailbox may return a bogus state,
3870 * so we need to just enable it and continue on.
3873 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
3874 /* The bit only becomes 1 in the next vblank, so this wait here
3875 * is essentially intel_wait_for_vblank. If we don't have this
3876 * and don't wait for vblanks until the end of crtc_enable, then
3877 * the HW state readout code will complain that the expected
3878 * IPS_CTL value is not the one we read. */
3879 if (wait_for(I915_READ_NOTRACE(IPS_CTL
) & IPS_ENABLE
, 50))
3880 DRM_ERROR("Timed out waiting for IPS enable\n");
3884 void hsw_disable_ips(struct intel_crtc
*crtc
)
3886 struct drm_device
*dev
= crtc
->base
.dev
;
3887 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3889 if (!crtc
->config
.ips_enabled
)
3892 assert_plane_enabled(dev_priv
, crtc
->plane
);
3893 if (IS_BROADWELL(dev
)) {
3894 mutex_lock(&dev_priv
->rps
.hw_lock
);
3895 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
3896 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3897 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
3898 if (wait_for((I915_READ(IPS_CTL
) & IPS_ENABLE
) == 0, 42))
3899 DRM_ERROR("Timed out waiting for IPS disable\n");
3901 I915_WRITE(IPS_CTL
, 0);
3902 POSTING_READ(IPS_CTL
);
3905 /* We need to wait for a vblank before we can disable the plane. */
3906 intel_wait_for_vblank(dev
, crtc
->pipe
);
3909 /** Loads the palette/gamma unit for the CRTC with the prepared values */
3910 static void intel_crtc_load_lut(struct drm_crtc
*crtc
)
3912 struct drm_device
*dev
= crtc
->dev
;
3913 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3914 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3915 enum pipe pipe
= intel_crtc
->pipe
;
3916 int palreg
= PALETTE(pipe
);
3918 bool reenable_ips
= false;
3920 /* The clocks have to be on to load the palette. */
3921 if (!crtc
->enabled
|| !intel_crtc
->active
)
3924 if (!HAS_PCH_SPLIT(dev_priv
->dev
)) {
3925 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
))
3926 assert_dsi_pll_enabled(dev_priv
);
3928 assert_pll_enabled(dev_priv
, pipe
);
3931 /* use legacy palette for Ironlake */
3932 if (!HAS_GMCH_DISPLAY(dev
))
3933 palreg
= LGC_PALETTE(pipe
);
3935 /* Workaround : Do not read or write the pipe palette/gamma data while
3936 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
3938 if (IS_HASWELL(dev
) && intel_crtc
->config
.ips_enabled
&&
3939 ((I915_READ(GAMMA_MODE(pipe
)) & GAMMA_MODE_MODE_MASK
) ==
3940 GAMMA_MODE_MODE_SPLIT
)) {
3941 hsw_disable_ips(intel_crtc
);
3942 reenable_ips
= true;
3945 for (i
= 0; i
< 256; i
++) {
3946 I915_WRITE(palreg
+ 4 * i
,
3947 (intel_crtc
->lut_r
[i
] << 16) |
3948 (intel_crtc
->lut_g
[i
] << 8) |
3949 intel_crtc
->lut_b
[i
]);
3953 hsw_enable_ips(intel_crtc
);
3956 static void intel_crtc_dpms_overlay(struct intel_crtc
*intel_crtc
, bool enable
)
3958 if (!enable
&& intel_crtc
->overlay
) {
3959 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3960 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3962 mutex_lock(&dev
->struct_mutex
);
3963 dev_priv
->mm
.interruptible
= false;
3964 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
3965 dev_priv
->mm
.interruptible
= true;
3966 mutex_unlock(&dev
->struct_mutex
);
3969 /* Let userspace switch the overlay on again. In most cases userspace
3970 * has to recompute where to put it anyway.
3974 static void intel_crtc_enable_planes(struct drm_crtc
*crtc
)
3976 struct drm_device
*dev
= crtc
->dev
;
3977 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3978 int pipe
= intel_crtc
->pipe
;
3980 drm_vblank_on(dev
, pipe
);
3982 intel_enable_primary_hw_plane(crtc
->primary
, crtc
);
3983 intel_enable_planes(crtc
);
3984 intel_crtc_update_cursor(crtc
, true);
3985 intel_crtc_dpms_overlay(intel_crtc
, true);
3987 hsw_enable_ips(intel_crtc
);
3989 mutex_lock(&dev
->struct_mutex
);
3990 intel_update_fbc(dev
);
3991 mutex_unlock(&dev
->struct_mutex
);
3994 * FIXME: Once we grow proper nuclear flip support out of this we need
3995 * to compute the mask of flip planes precisely. For the time being
3996 * consider this a flip from a NULL plane.
3998 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_ALL_MASK(pipe
));
4001 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
)
4003 struct drm_device
*dev
= crtc
->dev
;
4004 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4005 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4006 int pipe
= intel_crtc
->pipe
;
4007 int plane
= intel_crtc
->plane
;
4009 intel_crtc_wait_for_pending_flips(crtc
);
4011 if (dev_priv
->fbc
.plane
== plane
)
4012 intel_disable_fbc(dev
);
4014 hsw_disable_ips(intel_crtc
);
4016 intel_crtc_dpms_overlay(intel_crtc
, false);
4017 intel_crtc_update_cursor(crtc
, false);
4018 intel_disable_planes(crtc
);
4019 intel_disable_primary_hw_plane(crtc
->primary
, crtc
);
4022 * FIXME: Once we grow proper nuclear flip support out of this we need
4023 * to compute the mask of flip planes precisely. For the time being
4024 * consider this a flip to a NULL plane.
4026 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_ALL_MASK(pipe
));
4028 drm_vblank_off(dev
, pipe
);
4031 static void ironlake_crtc_enable(struct drm_crtc
*crtc
)
4033 struct drm_device
*dev
= crtc
->dev
;
4034 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4035 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4036 struct intel_encoder
*encoder
;
4037 int pipe
= intel_crtc
->pipe
;
4039 WARN_ON(!crtc
->enabled
);
4041 if (intel_crtc
->active
)
4044 if (intel_crtc
->config
.has_pch_encoder
)
4045 intel_prepare_shared_dpll(intel_crtc
);
4047 if (intel_crtc
->config
.has_dp_encoder
)
4048 intel_dp_set_m_n(intel_crtc
);
4050 intel_set_pipe_timings(intel_crtc
);
4052 if (intel_crtc
->config
.has_pch_encoder
) {
4053 intel_cpu_transcoder_set_m_n(intel_crtc
,
4054 &intel_crtc
->config
.fdi_m_n
, NULL
);
4057 ironlake_set_pipeconf(crtc
);
4059 intel_crtc
->active
= true;
4061 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4062 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, true);
4064 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4065 if (encoder
->pre_enable
)
4066 encoder
->pre_enable(encoder
);
4068 if (intel_crtc
->config
.has_pch_encoder
) {
4069 /* Note: FDI PLL enabling _must_ be done before we enable the
4070 * cpu pipes, hence this is separate from all the other fdi/pch
4072 ironlake_fdi_pll_enable(intel_crtc
);
4074 assert_fdi_tx_disabled(dev_priv
, pipe
);
4075 assert_fdi_rx_disabled(dev_priv
, pipe
);
4078 ironlake_pfit_enable(intel_crtc
);
4081 * On ILK+ LUT must be loaded before the pipe is running but with
4084 intel_crtc_load_lut(crtc
);
4086 intel_update_watermarks(crtc
);
4087 intel_enable_pipe(intel_crtc
);
4089 if (intel_crtc
->config
.has_pch_encoder
)
4090 ironlake_pch_enable(crtc
);
4092 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4093 encoder
->enable(encoder
);
4095 if (HAS_PCH_CPT(dev
))
4096 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
4098 intel_crtc_enable_planes(crtc
);
4101 /* IPS only exists on ULT machines and is tied to pipe A. */
4102 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
4104 return HAS_IPS(crtc
->base
.dev
) && crtc
->pipe
== PIPE_A
;
4108 * This implements the workaround described in the "notes" section of the mode
4109 * set sequence documentation. When going from no pipes or single pipe to
4110 * multiple pipes, and planes are enabled after the pipe, we need to wait at
4111 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
4113 static void haswell_mode_set_planes_workaround(struct intel_crtc
*crtc
)
4115 struct drm_device
*dev
= crtc
->base
.dev
;
4116 struct intel_crtc
*crtc_it
, *other_active_crtc
= NULL
;
4118 /* We want to get the other_active_crtc only if there's only 1 other
4120 for_each_intel_crtc(dev
, crtc_it
) {
4121 if (!crtc_it
->active
|| crtc_it
== crtc
)
4124 if (other_active_crtc
)
4127 other_active_crtc
= crtc_it
;
4129 if (!other_active_crtc
)
4132 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4133 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4136 static void haswell_crtc_enable(struct drm_crtc
*crtc
)
4138 struct drm_device
*dev
= crtc
->dev
;
4139 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4140 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4141 struct intel_encoder
*encoder
;
4142 int pipe
= intel_crtc
->pipe
;
4144 WARN_ON(!crtc
->enabled
);
4146 if (intel_crtc
->active
)
4149 if (intel_crtc_to_shared_dpll(intel_crtc
))
4150 intel_enable_shared_dpll(intel_crtc
);
4152 if (intel_crtc
->config
.has_dp_encoder
)
4153 intel_dp_set_m_n(intel_crtc
);
4155 intel_set_pipe_timings(intel_crtc
);
4157 if (intel_crtc
->config
.has_pch_encoder
) {
4158 intel_cpu_transcoder_set_m_n(intel_crtc
,
4159 &intel_crtc
->config
.fdi_m_n
, NULL
);
4162 haswell_set_pipeconf(crtc
);
4164 intel_set_pipe_csc(crtc
);
4166 intel_crtc
->active
= true;
4168 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4169 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4170 if (encoder
->pre_enable
)
4171 encoder
->pre_enable(encoder
);
4173 if (intel_crtc
->config
.has_pch_encoder
) {
4174 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, true);
4175 dev_priv
->display
.fdi_link_train(crtc
);
4178 intel_ddi_enable_pipe_clock(intel_crtc
);
4180 ironlake_pfit_enable(intel_crtc
);
4183 * On ILK+ LUT must be loaded before the pipe is running but with
4186 intel_crtc_load_lut(crtc
);
4188 intel_ddi_set_pipe_settings(crtc
);
4189 intel_ddi_enable_transcoder_func(crtc
);
4191 intel_update_watermarks(crtc
);
4192 intel_enable_pipe(intel_crtc
);
4194 if (intel_crtc
->config
.has_pch_encoder
)
4195 lpt_pch_enable(crtc
);
4197 if (intel_crtc
->config
.dp_encoder_is_mst
)
4198 intel_ddi_set_vc_payload_alloc(crtc
, true);
4200 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4201 encoder
->enable(encoder
);
4202 intel_opregion_notify_encoder(encoder
, true);
4205 /* If we change the relative order between pipe/planes enabling, we need
4206 * to change the workaround. */
4207 haswell_mode_set_planes_workaround(intel_crtc
);
4208 intel_crtc_enable_planes(crtc
);
4211 static void ironlake_pfit_disable(struct intel_crtc
*crtc
)
4213 struct drm_device
*dev
= crtc
->base
.dev
;
4214 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4215 int pipe
= crtc
->pipe
;
4217 /* To avoid upsetting the power well on haswell only disable the pfit if
4218 * it's in use. The hw state code will make sure we get this right. */
4219 if (crtc
->config
.pch_pfit
.enabled
) {
4220 I915_WRITE(PF_CTL(pipe
), 0);
4221 I915_WRITE(PF_WIN_POS(pipe
), 0);
4222 I915_WRITE(PF_WIN_SZ(pipe
), 0);
4226 static void ironlake_crtc_disable(struct drm_crtc
*crtc
)
4228 struct drm_device
*dev
= crtc
->dev
;
4229 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4230 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4231 struct intel_encoder
*encoder
;
4232 int pipe
= intel_crtc
->pipe
;
4235 if (!intel_crtc
->active
)
4238 intel_crtc_disable_planes(crtc
);
4240 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4241 encoder
->disable(encoder
);
4243 if (intel_crtc
->config
.has_pch_encoder
)
4244 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, false);
4246 intel_disable_pipe(intel_crtc
);
4248 if (intel_crtc
->config
.dp_encoder_is_mst
)
4249 intel_ddi_set_vc_payload_alloc(crtc
, false);
4251 ironlake_pfit_disable(intel_crtc
);
4253 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4254 if (encoder
->post_disable
)
4255 encoder
->post_disable(encoder
);
4257 if (intel_crtc
->config
.has_pch_encoder
) {
4258 ironlake_fdi_disable(crtc
);
4260 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
4261 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, true);
4263 if (HAS_PCH_CPT(dev
)) {
4264 /* disable TRANS_DP_CTL */
4265 reg
= TRANS_DP_CTL(pipe
);
4266 temp
= I915_READ(reg
);
4267 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
4268 TRANS_DP_PORT_SEL_MASK
);
4269 temp
|= TRANS_DP_PORT_SEL_NONE
;
4270 I915_WRITE(reg
, temp
);
4272 /* disable DPLL_SEL */
4273 temp
= I915_READ(PCH_DPLL_SEL
);
4274 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
4275 I915_WRITE(PCH_DPLL_SEL
, temp
);
4278 /* disable PCH DPLL */
4279 intel_disable_shared_dpll(intel_crtc
);
4281 ironlake_fdi_pll_disable(intel_crtc
);
4284 intel_crtc
->active
= false;
4285 intel_update_watermarks(crtc
);
4287 mutex_lock(&dev
->struct_mutex
);
4288 intel_update_fbc(dev
);
4289 mutex_unlock(&dev
->struct_mutex
);
4292 static void haswell_crtc_disable(struct drm_crtc
*crtc
)
4294 struct drm_device
*dev
= crtc
->dev
;
4295 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4296 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4297 struct intel_encoder
*encoder
;
4298 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
4300 if (!intel_crtc
->active
)
4303 intel_crtc_disable_planes(crtc
);
4305 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4306 intel_opregion_notify_encoder(encoder
, false);
4307 encoder
->disable(encoder
);
4310 if (intel_crtc
->config
.has_pch_encoder
)
4311 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, false);
4312 intel_disable_pipe(intel_crtc
);
4314 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
4316 ironlake_pfit_disable(intel_crtc
);
4318 intel_ddi_disable_pipe_clock(intel_crtc
);
4320 if (intel_crtc
->config
.has_pch_encoder
) {
4321 lpt_disable_pch_transcoder(dev_priv
);
4322 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, true);
4323 intel_ddi_fdi_disable(crtc
);
4326 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4327 if (encoder
->post_disable
)
4328 encoder
->post_disable(encoder
);
4330 intel_crtc
->active
= false;
4331 intel_update_watermarks(crtc
);
4333 mutex_lock(&dev
->struct_mutex
);
4334 intel_update_fbc(dev
);
4335 mutex_unlock(&dev
->struct_mutex
);
4337 if (intel_crtc_to_shared_dpll(intel_crtc
))
4338 intel_disable_shared_dpll(intel_crtc
);
4341 static void ironlake_crtc_off(struct drm_crtc
*crtc
)
4343 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4344 intel_put_shared_dpll(intel_crtc
);
4348 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
4350 struct drm_device
*dev
= crtc
->base
.dev
;
4351 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4352 struct intel_crtc_config
*pipe_config
= &crtc
->config
;
4354 if (!crtc
->config
.gmch_pfit
.control
)
4358 * The panel fitter should only be adjusted whilst the pipe is disabled,
4359 * according to register description and PRM.
4361 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
4362 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
4364 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
4365 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
4367 /* Border color in case we don't scale up to the full screen. Black by
4368 * default, change to something else for debugging. */
4369 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
4372 static enum intel_display_power_domain
port_to_power_domain(enum port port
)
4376 return POWER_DOMAIN_PORT_DDI_A_4_LANES
;
4378 return POWER_DOMAIN_PORT_DDI_B_4_LANES
;
4380 return POWER_DOMAIN_PORT_DDI_C_4_LANES
;
4382 return POWER_DOMAIN_PORT_DDI_D_4_LANES
;
4385 return POWER_DOMAIN_PORT_OTHER
;
4389 #define for_each_power_domain(domain, mask) \
4390 for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
4391 if ((1 << (domain)) & (mask))
4393 enum intel_display_power_domain
4394 intel_display_port_power_domain(struct intel_encoder
*intel_encoder
)
4396 struct drm_device
*dev
= intel_encoder
->base
.dev
;
4397 struct intel_digital_port
*intel_dig_port
;
4399 switch (intel_encoder
->type
) {
4400 case INTEL_OUTPUT_UNKNOWN
:
4401 /* Only DDI platforms should ever use this output type */
4402 WARN_ON_ONCE(!HAS_DDI(dev
));
4403 case INTEL_OUTPUT_DISPLAYPORT
:
4404 case INTEL_OUTPUT_HDMI
:
4405 case INTEL_OUTPUT_EDP
:
4406 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
4407 return port_to_power_domain(intel_dig_port
->port
);
4408 case INTEL_OUTPUT_DP_MST
:
4409 intel_dig_port
= enc_to_mst(&intel_encoder
->base
)->primary
;
4410 return port_to_power_domain(intel_dig_port
->port
);
4411 case INTEL_OUTPUT_ANALOG
:
4412 return POWER_DOMAIN_PORT_CRT
;
4413 case INTEL_OUTPUT_DSI
:
4414 return POWER_DOMAIN_PORT_DSI
;
4416 return POWER_DOMAIN_PORT_OTHER
;
4420 static unsigned long get_crtc_power_domains(struct drm_crtc
*crtc
)
4422 struct drm_device
*dev
= crtc
->dev
;
4423 struct intel_encoder
*intel_encoder
;
4424 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4425 enum pipe pipe
= intel_crtc
->pipe
;
4427 enum transcoder transcoder
;
4429 transcoder
= intel_pipe_to_cpu_transcoder(dev
->dev_private
, pipe
);
4431 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
4432 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
4433 if (intel_crtc
->config
.pch_pfit
.enabled
||
4434 intel_crtc
->config
.pch_pfit
.force_thru
)
4435 mask
|= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
4437 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
4438 mask
|= BIT(intel_display_port_power_domain(intel_encoder
));
4443 void intel_display_set_init_power(struct drm_i915_private
*dev_priv
,
4446 if (dev_priv
->power_domains
.init_power_on
== enable
)
4450 intel_display_power_get(dev_priv
, POWER_DOMAIN_INIT
);
4452 intel_display_power_put(dev_priv
, POWER_DOMAIN_INIT
);
4454 dev_priv
->power_domains
.init_power_on
= enable
;
4457 static void modeset_update_crtc_power_domains(struct drm_device
*dev
)
4459 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4460 unsigned long pipe_domains
[I915_MAX_PIPES
] = { 0, };
4461 struct intel_crtc
*crtc
;
4464 * First get all needed power domains, then put all unneeded, to avoid
4465 * any unnecessary toggling of the power wells.
4467 for_each_intel_crtc(dev
, crtc
) {
4468 enum intel_display_power_domain domain
;
4470 if (!crtc
->base
.enabled
)
4473 pipe_domains
[crtc
->pipe
] = get_crtc_power_domains(&crtc
->base
);
4475 for_each_power_domain(domain
, pipe_domains
[crtc
->pipe
])
4476 intel_display_power_get(dev_priv
, domain
);
4479 for_each_intel_crtc(dev
, crtc
) {
4480 enum intel_display_power_domain domain
;
4482 for_each_power_domain(domain
, crtc
->enabled_power_domains
)
4483 intel_display_power_put(dev_priv
, domain
);
4485 crtc
->enabled_power_domains
= pipe_domains
[crtc
->pipe
];
4488 intel_display_set_init_power(dev_priv
, false);
4491 /* returns HPLL frequency in kHz */
4492 static int valleyview_get_vco(struct drm_i915_private
*dev_priv
)
4494 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
4496 /* Obtain SKU information */
4497 mutex_lock(&dev_priv
->dpio_lock
);
4498 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
4499 CCK_FUSE_HPLL_FREQ_MASK
;
4500 mutex_unlock(&dev_priv
->dpio_lock
);
4502 return vco_freq
[hpll_freq
] * 1000;
4505 static void vlv_update_cdclk(struct drm_device
*dev
)
4507 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4509 dev_priv
->vlv_cdclk_freq
= dev_priv
->display
.get_display_clock_speed(dev
);
4510 DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz",
4511 dev_priv
->vlv_cdclk_freq
);
4514 * Program the gmbus_freq based on the cdclk frequency.
4515 * BSpec erroneously claims we should aim for 4MHz, but
4516 * in fact 1MHz is the correct frequency.
4518 I915_WRITE(GMBUSFREQ_VLV
, dev_priv
->vlv_cdclk_freq
);
4521 /* Adjust CDclk dividers to allow high res or save power if possible */
4522 static void valleyview_set_cdclk(struct drm_device
*dev
, int cdclk
)
4524 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4527 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
) != dev_priv
->vlv_cdclk_freq
);
4529 if (cdclk
>= 320000) /* jump to highest voltage for 400MHz too */
4531 else if (cdclk
== 266667)
4536 mutex_lock(&dev_priv
->rps
.hw_lock
);
4537 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
4538 val
&= ~DSPFREQGUAR_MASK
;
4539 val
|= (cmd
<< DSPFREQGUAR_SHIFT
);
4540 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
4541 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
4542 DSPFREQSTAT_MASK
) == (cmd
<< DSPFREQSTAT_SHIFT
),
4544 DRM_ERROR("timed out waiting for CDclk change\n");
4546 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4548 if (cdclk
== 400000) {
4551 vco
= valleyview_get_vco(dev_priv
);
4552 divider
= DIV_ROUND_CLOSEST(vco
<< 1, cdclk
) - 1;
4554 mutex_lock(&dev_priv
->dpio_lock
);
4555 /* adjust cdclk divider */
4556 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
4557 val
&= ~DISPLAY_FREQUENCY_VALUES
;
4559 vlv_cck_write(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
, val
);
4561 if (wait_for((vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
) &
4562 DISPLAY_FREQUENCY_STATUS
) == (divider
<< DISPLAY_FREQUENCY_STATUS_SHIFT
),
4564 DRM_ERROR("timed out waiting for CDclk change\n");
4565 mutex_unlock(&dev_priv
->dpio_lock
);
4568 mutex_lock(&dev_priv
->dpio_lock
);
4569 /* adjust self-refresh exit latency value */
4570 val
= vlv_bunit_read(dev_priv
, BUNIT_REG_BISOC
);
4574 * For high bandwidth configs, we set a higher latency in the bunit
4575 * so that the core display fetch happens in time to avoid underruns.
4577 if (cdclk
== 400000)
4578 val
|= 4500 / 250; /* 4.5 usec */
4580 val
|= 3000 / 250; /* 3.0 usec */
4581 vlv_bunit_write(dev_priv
, BUNIT_REG_BISOC
, val
);
4582 mutex_unlock(&dev_priv
->dpio_lock
);
4584 vlv_update_cdclk(dev
);
4587 static void cherryview_set_cdclk(struct drm_device
*dev
, int cdclk
)
4589 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4592 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
) != dev_priv
->vlv_cdclk_freq
);
4613 mutex_lock(&dev_priv
->rps
.hw_lock
);
4614 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
4615 val
&= ~DSPFREQGUAR_MASK_CHV
;
4616 val
|= (cmd
<< DSPFREQGUAR_SHIFT_CHV
);
4617 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
4618 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
4619 DSPFREQSTAT_MASK_CHV
) == (cmd
<< DSPFREQSTAT_SHIFT_CHV
),
4621 DRM_ERROR("timed out waiting for CDclk change\n");
4623 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4625 vlv_update_cdclk(dev
);
4628 static int valleyview_calc_cdclk(struct drm_i915_private
*dev_priv
,
4631 int vco
= valleyview_get_vco(dev_priv
);
4632 int freq_320
= (vco
<< 1) % 320000 != 0 ? 333333 : 320000;
4634 /* FIXME: Punit isn't quite ready yet */
4635 if (IS_CHERRYVIEW(dev_priv
->dev
))
4639 * Really only a few cases to deal with, as only 4 CDclks are supported:
4642 * 320/333MHz (depends on HPLL freq)
4644 * So we check to see whether we're above 90% of the lower bin and
4647 * We seem to get an unstable or solid color picture at 200MHz.
4648 * Not sure what's wrong. For now use 200MHz only when all pipes
4651 if (max_pixclk
> freq_320
*9/10)
4653 else if (max_pixclk
> 266667*9/10)
4655 else if (max_pixclk
> 0)
4661 /* compute the max pixel clock for new configuration */
4662 static int intel_mode_max_pixclk(struct drm_i915_private
*dev_priv
)
4664 struct drm_device
*dev
= dev_priv
->dev
;
4665 struct intel_crtc
*intel_crtc
;
4668 for_each_intel_crtc(dev
, intel_crtc
) {
4669 if (intel_crtc
->new_enabled
)
4670 max_pixclk
= max(max_pixclk
,
4671 intel_crtc
->new_config
->adjusted_mode
.crtc_clock
);
4677 static void valleyview_modeset_global_pipes(struct drm_device
*dev
,
4678 unsigned *prepare_pipes
)
4680 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4681 struct intel_crtc
*intel_crtc
;
4682 int max_pixclk
= intel_mode_max_pixclk(dev_priv
);
4684 if (valleyview_calc_cdclk(dev_priv
, max_pixclk
) ==
4685 dev_priv
->vlv_cdclk_freq
)
4688 /* disable/enable all currently active pipes while we change cdclk */
4689 for_each_intel_crtc(dev
, intel_crtc
)
4690 if (intel_crtc
->base
.enabled
)
4691 *prepare_pipes
|= (1 << intel_crtc
->pipe
);
4694 static void valleyview_modeset_global_resources(struct drm_device
*dev
)
4696 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4697 int max_pixclk
= intel_mode_max_pixclk(dev_priv
);
4698 int req_cdclk
= valleyview_calc_cdclk(dev_priv
, max_pixclk
);
4700 if (req_cdclk
!= dev_priv
->vlv_cdclk_freq
) {
4701 if (IS_CHERRYVIEW(dev
))
4702 cherryview_set_cdclk(dev
, req_cdclk
);
4704 valleyview_set_cdclk(dev
, req_cdclk
);
4707 modeset_update_crtc_power_domains(dev
);
4710 static void valleyview_crtc_enable(struct drm_crtc
*crtc
)
4712 struct drm_device
*dev
= crtc
->dev
;
4713 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4714 struct intel_encoder
*encoder
;
4715 int pipe
= intel_crtc
->pipe
;
4718 WARN_ON(!crtc
->enabled
);
4720 if (intel_crtc
->active
)
4723 is_dsi
= intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
);
4726 if (IS_CHERRYVIEW(dev
))
4727 chv_prepare_pll(intel_crtc
);
4729 vlv_prepare_pll(intel_crtc
);
4732 if (intel_crtc
->config
.has_dp_encoder
)
4733 intel_dp_set_m_n(intel_crtc
);
4735 intel_set_pipe_timings(intel_crtc
);
4737 i9xx_set_pipeconf(intel_crtc
);
4739 intel_crtc
->active
= true;
4741 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4743 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4744 if (encoder
->pre_pll_enable
)
4745 encoder
->pre_pll_enable(encoder
);
4748 if (IS_CHERRYVIEW(dev
))
4749 chv_enable_pll(intel_crtc
);
4751 vlv_enable_pll(intel_crtc
);
4754 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4755 if (encoder
->pre_enable
)
4756 encoder
->pre_enable(encoder
);
4758 i9xx_pfit_enable(intel_crtc
);
4760 intel_crtc_load_lut(crtc
);
4762 intel_update_watermarks(crtc
);
4763 intel_enable_pipe(intel_crtc
);
4765 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4766 encoder
->enable(encoder
);
4768 intel_crtc_enable_planes(crtc
);
4770 /* Underruns don't raise interrupts, so check manually. */
4771 i9xx_check_fifo_underruns(dev
);
4774 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
4776 struct drm_device
*dev
= crtc
->base
.dev
;
4777 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4779 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
.dpll_hw_state
.fp0
);
4780 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
.dpll_hw_state
.fp1
);
4783 static void i9xx_crtc_enable(struct drm_crtc
*crtc
)
4785 struct drm_device
*dev
= crtc
->dev
;
4786 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4787 struct intel_encoder
*encoder
;
4788 int pipe
= intel_crtc
->pipe
;
4790 WARN_ON(!crtc
->enabled
);
4792 if (intel_crtc
->active
)
4795 i9xx_set_pll_dividers(intel_crtc
);
4797 if (intel_crtc
->config
.has_dp_encoder
)
4798 intel_dp_set_m_n(intel_crtc
);
4800 intel_set_pipe_timings(intel_crtc
);
4802 i9xx_set_pipeconf(intel_crtc
);
4804 intel_crtc
->active
= true;
4807 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4809 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4810 if (encoder
->pre_enable
)
4811 encoder
->pre_enable(encoder
);
4813 i9xx_enable_pll(intel_crtc
);
4815 i9xx_pfit_enable(intel_crtc
);
4817 intel_crtc_load_lut(crtc
);
4819 intel_update_watermarks(crtc
);
4820 intel_enable_pipe(intel_crtc
);
4822 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4823 encoder
->enable(encoder
);
4825 intel_crtc_enable_planes(crtc
);
4828 * Gen2 reports pipe underruns whenever all planes are disabled.
4829 * So don't enable underrun reporting before at least some planes
4831 * FIXME: Need to fix the logic to work when we turn off all planes
4832 * but leave the pipe running.
4835 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4837 /* Underruns don't raise interrupts, so check manually. */
4838 i9xx_check_fifo_underruns(dev
);
4841 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
4843 struct drm_device
*dev
= crtc
->base
.dev
;
4844 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4846 if (!crtc
->config
.gmch_pfit
.control
)
4849 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
4851 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
4852 I915_READ(PFIT_CONTROL
));
4853 I915_WRITE(PFIT_CONTROL
, 0);
4856 static void i9xx_crtc_disable(struct drm_crtc
*crtc
)
4858 struct drm_device
*dev
= crtc
->dev
;
4859 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4860 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4861 struct intel_encoder
*encoder
;
4862 int pipe
= intel_crtc
->pipe
;
4864 if (!intel_crtc
->active
)
4868 * Gen2 reports pipe underruns whenever all planes are disabled.
4869 * So diasble underrun reporting before all the planes get disabled.
4870 * FIXME: Need to fix the logic to work when we turn off all planes
4871 * but leave the pipe running.
4874 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, false);
4877 * Vblank time updates from the shadow to live plane control register
4878 * are blocked if the memory self-refresh mode is active at that
4879 * moment. So to make sure the plane gets truly disabled, disable
4880 * first the self-refresh mode. The self-refresh enable bit in turn
4881 * will be checked/applied by the HW only at the next frame start
4882 * event which is after the vblank start event, so we need to have a
4883 * wait-for-vblank between disabling the plane and the pipe.
4885 intel_set_memory_cxsr(dev_priv
, false);
4886 intel_crtc_disable_planes(crtc
);
4888 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4889 encoder
->disable(encoder
);
4892 * On gen2 planes are double buffered but the pipe isn't, so we must
4893 * wait for planes to fully turn off before disabling the pipe.
4894 * We also need to wait on all gmch platforms because of the
4895 * self-refresh mode constraint explained above.
4897 intel_wait_for_vblank(dev
, pipe
);
4899 intel_disable_pipe(intel_crtc
);
4901 i9xx_pfit_disable(intel_crtc
);
4903 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4904 if (encoder
->post_disable
)
4905 encoder
->post_disable(encoder
);
4907 if (!intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
)) {
4908 if (IS_CHERRYVIEW(dev
))
4909 chv_disable_pll(dev_priv
, pipe
);
4910 else if (IS_VALLEYVIEW(dev
))
4911 vlv_disable_pll(dev_priv
, pipe
);
4913 i9xx_disable_pll(dev_priv
, pipe
);
4917 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, false);
4919 intel_crtc
->active
= false;
4920 intel_update_watermarks(crtc
);
4922 mutex_lock(&dev
->struct_mutex
);
4923 intel_update_fbc(dev
);
4924 mutex_unlock(&dev
->struct_mutex
);
4927 static void i9xx_crtc_off(struct drm_crtc
*crtc
)
4931 static void intel_crtc_update_sarea(struct drm_crtc
*crtc
,
4934 struct drm_device
*dev
= crtc
->dev
;
4935 struct drm_i915_master_private
*master_priv
;
4936 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4937 int pipe
= intel_crtc
->pipe
;
4939 if (!dev
->primary
->master
)
4942 master_priv
= dev
->primary
->master
->driver_priv
;
4943 if (!master_priv
->sarea_priv
)
4948 master_priv
->sarea_priv
->pipeA_w
= enabled
? crtc
->mode
.hdisplay
: 0;
4949 master_priv
->sarea_priv
->pipeA_h
= enabled
? crtc
->mode
.vdisplay
: 0;
4952 master_priv
->sarea_priv
->pipeB_w
= enabled
? crtc
->mode
.hdisplay
: 0;
4953 master_priv
->sarea_priv
->pipeB_h
= enabled
? crtc
->mode
.vdisplay
: 0;
4956 DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe
));
4961 /* Master function to enable/disable CRTC and corresponding power wells */
4962 void intel_crtc_control(struct drm_crtc
*crtc
, bool enable
)
4964 struct drm_device
*dev
= crtc
->dev
;
4965 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4966 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4967 enum intel_display_power_domain domain
;
4968 unsigned long domains
;
4971 if (!intel_crtc
->active
) {
4972 domains
= get_crtc_power_domains(crtc
);
4973 for_each_power_domain(domain
, domains
)
4974 intel_display_power_get(dev_priv
, domain
);
4975 intel_crtc
->enabled_power_domains
= domains
;
4977 dev_priv
->display
.crtc_enable(crtc
);
4980 if (intel_crtc
->active
) {
4981 dev_priv
->display
.crtc_disable(crtc
);
4983 domains
= intel_crtc
->enabled_power_domains
;
4984 for_each_power_domain(domain
, domains
)
4985 intel_display_power_put(dev_priv
, domain
);
4986 intel_crtc
->enabled_power_domains
= 0;
4992 * Sets the power management mode of the pipe and plane.
4994 void intel_crtc_update_dpms(struct drm_crtc
*crtc
)
4996 struct drm_device
*dev
= crtc
->dev
;
4997 struct intel_encoder
*intel_encoder
;
4998 bool enable
= false;
5000 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
5001 enable
|= intel_encoder
->connectors_active
;
5003 intel_crtc_control(crtc
, enable
);
5005 intel_crtc_update_sarea(crtc
, enable
);
5008 static void intel_crtc_disable(struct drm_crtc
*crtc
)
5010 struct drm_device
*dev
= crtc
->dev
;
5011 struct drm_connector
*connector
;
5012 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5013 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(crtc
->primary
->fb
);
5014 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
5016 /* crtc should still be enabled when we disable it. */
5017 WARN_ON(!crtc
->enabled
);
5019 dev_priv
->display
.crtc_disable(crtc
);
5020 intel_crtc_update_sarea(crtc
, false);
5021 dev_priv
->display
.off(crtc
);
5023 if (crtc
->primary
->fb
) {
5024 mutex_lock(&dev
->struct_mutex
);
5025 intel_unpin_fb_obj(old_obj
);
5026 i915_gem_track_fb(old_obj
, NULL
,
5027 INTEL_FRONTBUFFER_PRIMARY(pipe
));
5028 mutex_unlock(&dev
->struct_mutex
);
5029 crtc
->primary
->fb
= NULL
;
5032 /* Update computed state. */
5033 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
5034 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
5037 if (connector
->encoder
->crtc
!= crtc
)
5040 connector
->dpms
= DRM_MODE_DPMS_OFF
;
5041 to_intel_encoder(connector
->encoder
)->connectors_active
= false;
5045 void intel_encoder_destroy(struct drm_encoder
*encoder
)
5047 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5049 drm_encoder_cleanup(encoder
);
5050 kfree(intel_encoder
);
5053 /* Simple dpms helper for encoders with just one connector, no cloning and only
5054 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
5055 * state of the entire output pipe. */
5056 static void intel_encoder_dpms(struct intel_encoder
*encoder
, int mode
)
5058 if (mode
== DRM_MODE_DPMS_ON
) {
5059 encoder
->connectors_active
= true;
5061 intel_crtc_update_dpms(encoder
->base
.crtc
);
5063 encoder
->connectors_active
= false;
5065 intel_crtc_update_dpms(encoder
->base
.crtc
);
5069 /* Cross check the actual hw state with our own modeset state tracking (and it's
5070 * internal consistency). */
5071 static void intel_connector_check_state(struct intel_connector
*connector
)
5073 if (connector
->get_hw_state(connector
)) {
5074 struct intel_encoder
*encoder
= connector
->encoder
;
5075 struct drm_crtc
*crtc
;
5076 bool encoder_enabled
;
5079 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
5080 connector
->base
.base
.id
,
5081 connector
->base
.name
);
5083 /* there is no real hw state for MST connectors */
5084 if (connector
->mst_port
)
5087 WARN(connector
->base
.dpms
== DRM_MODE_DPMS_OFF
,
5088 "wrong connector dpms state\n");
5089 WARN(connector
->base
.encoder
!= &encoder
->base
,
5090 "active connector not linked to encoder\n");
5093 WARN(!encoder
->connectors_active
,
5094 "encoder->connectors_active not set\n");
5096 encoder_enabled
= encoder
->get_hw_state(encoder
, &pipe
);
5097 WARN(!encoder_enabled
, "encoder not enabled\n");
5098 if (WARN_ON(!encoder
->base
.crtc
))
5101 crtc
= encoder
->base
.crtc
;
5103 WARN(!crtc
->enabled
, "crtc not enabled\n");
5104 WARN(!to_intel_crtc(crtc
)->active
, "crtc not active\n");
5105 WARN(pipe
!= to_intel_crtc(crtc
)->pipe
,
5106 "encoder active on the wrong pipe\n");
5111 /* Even simpler default implementation, if there's really no special case to
5113 void intel_connector_dpms(struct drm_connector
*connector
, int mode
)
5115 /* All the simple cases only support two dpms states. */
5116 if (mode
!= DRM_MODE_DPMS_ON
)
5117 mode
= DRM_MODE_DPMS_OFF
;
5119 if (mode
== connector
->dpms
)
5122 connector
->dpms
= mode
;
5124 /* Only need to change hw state when actually enabled */
5125 if (connector
->encoder
)
5126 intel_encoder_dpms(to_intel_encoder(connector
->encoder
), mode
);
5128 intel_modeset_check_state(connector
->dev
);
5131 /* Simple connector->get_hw_state implementation for encoders that support only
5132 * one connector and no cloning and hence the encoder state determines the state
5133 * of the connector. */
5134 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
5137 struct intel_encoder
*encoder
= connector
->encoder
;
5139 return encoder
->get_hw_state(encoder
, &pipe
);
5142 static bool ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
5143 struct intel_crtc_config
*pipe_config
)
5145 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5146 struct intel_crtc
*pipe_B_crtc
=
5147 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
5149 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
5150 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5151 if (pipe_config
->fdi_lanes
> 4) {
5152 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
5153 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5157 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
5158 if (pipe_config
->fdi_lanes
> 2) {
5159 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
5160 pipe_config
->fdi_lanes
);
5167 if (INTEL_INFO(dev
)->num_pipes
== 2)
5170 /* Ivybridge 3 pipe is really complicated */
5175 if (dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]->enabled
&&
5176 pipe_config
->fdi_lanes
> 2) {
5177 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5178 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5183 if (!pipe_has_enabled_pch(pipe_B_crtc
) ||
5184 pipe_B_crtc
->config
.fdi_lanes
<= 2) {
5185 if (pipe_config
->fdi_lanes
> 2) {
5186 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5187 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5191 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
5201 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
5202 struct intel_crtc_config
*pipe_config
)
5204 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5205 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
5206 int lane
, link_bw
, fdi_dotclock
;
5207 bool setup_ok
, needs_recompute
= false;
5210 /* FDI is a binary signal running at ~2.7GHz, encoding
5211 * each output octet as 10 bits. The actual frequency
5212 * is stored as a divider into a 100MHz clock, and the
5213 * mode pixel clock is stored in units of 1KHz.
5214 * Hence the bw of each lane in terms of the mode signal
5217 link_bw
= intel_fdi_link_freq(dev
) * MHz(100)/KHz(1)/10;
5219 fdi_dotclock
= adjusted_mode
->crtc_clock
;
5221 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
5222 pipe_config
->pipe_bpp
);
5224 pipe_config
->fdi_lanes
= lane
;
5226 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
5227 link_bw
, &pipe_config
->fdi_m_n
);
5229 setup_ok
= ironlake_check_fdi_lanes(intel_crtc
->base
.dev
,
5230 intel_crtc
->pipe
, pipe_config
);
5231 if (!setup_ok
&& pipe_config
->pipe_bpp
> 6*3) {
5232 pipe_config
->pipe_bpp
-= 2*3;
5233 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
5234 pipe_config
->pipe_bpp
);
5235 needs_recompute
= true;
5236 pipe_config
->bw_constrained
= true;
5241 if (needs_recompute
)
5244 return setup_ok
? 0 : -EINVAL
;
5247 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
5248 struct intel_crtc_config
*pipe_config
)
5250 pipe_config
->ips_enabled
= i915
.enable_ips
&&
5251 hsw_crtc_supports_ips(crtc
) &&
5252 pipe_config
->pipe_bpp
<= 24;
5255 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
5256 struct intel_crtc_config
*pipe_config
)
5258 struct drm_device
*dev
= crtc
->base
.dev
;
5259 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
5261 /* FIXME should check pixel clock limits on all platforms */
5262 if (INTEL_INFO(dev
)->gen
< 4) {
5263 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5265 dev_priv
->display
.get_display_clock_speed(dev
);
5268 * Enable pixel doubling when the dot clock
5269 * is > 90% of the (display) core speed.
5271 * GDG double wide on either pipe,
5272 * otherwise pipe A only.
5274 if ((crtc
->pipe
== PIPE_A
|| IS_I915G(dev
)) &&
5275 adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10) {
5277 pipe_config
->double_wide
= true;
5280 if (adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10)
5285 * Pipe horizontal size must be even in:
5287 * - LVDS dual channel mode
5288 * - Double wide pipe
5290 if ((intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5291 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
5292 pipe_config
->pipe_src_w
&= ~1;
5294 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
5295 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
5297 if ((INTEL_INFO(dev
)->gen
> 4 || IS_G4X(dev
)) &&
5298 adjusted_mode
->hsync_start
== adjusted_mode
->hdisplay
)
5301 if ((IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) && pipe_config
->pipe_bpp
> 10*3) {
5302 pipe_config
->pipe_bpp
= 10*3; /* 12bpc is gen5+ */
5303 } else if (INTEL_INFO(dev
)->gen
<= 4 && pipe_config
->pipe_bpp
> 8*3) {
5304 /* only a 8bpc pipe, with 6bpc dither through the panel fitter
5306 pipe_config
->pipe_bpp
= 8*3;
5310 hsw_compute_ips_config(crtc
, pipe_config
);
5313 * XXX: PCH/WRPLL clock sharing is done in ->mode_set, so make sure the
5314 * old clock survives for now.
5316 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
) || HAS_DDI(dev
))
5317 pipe_config
->shared_dpll
= crtc
->config
.shared_dpll
;
5319 if (pipe_config
->has_pch_encoder
)
5320 return ironlake_fdi_compute_config(crtc
, pipe_config
);
5325 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
5327 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5328 int vco
= valleyview_get_vco(dev_priv
);
5332 /* FIXME: Punit isn't quite ready yet */
5333 if (IS_CHERRYVIEW(dev
))
5336 mutex_lock(&dev_priv
->dpio_lock
);
5337 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
5338 mutex_unlock(&dev_priv
->dpio_lock
);
5340 divider
= val
& DISPLAY_FREQUENCY_VALUES
;
5342 WARN((val
& DISPLAY_FREQUENCY_STATUS
) !=
5343 (divider
<< DISPLAY_FREQUENCY_STATUS_SHIFT
),
5344 "cdclk change in progress\n");
5346 return DIV_ROUND_CLOSEST(vco
<< 1, divider
+ 1);
5349 static int i945_get_display_clock_speed(struct drm_device
*dev
)
5354 static int i915_get_display_clock_speed(struct drm_device
*dev
)
5359 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
5364 static int pnv_get_display_clock_speed(struct drm_device
*dev
)
5368 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
5370 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
5371 case GC_DISPLAY_CLOCK_267_MHZ_PNV
:
5373 case GC_DISPLAY_CLOCK_333_MHZ_PNV
:
5375 case GC_DISPLAY_CLOCK_444_MHZ_PNV
:
5377 case GC_DISPLAY_CLOCK_200_MHZ_PNV
:
5380 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc
);
5381 case GC_DISPLAY_CLOCK_133_MHZ_PNV
:
5383 case GC_DISPLAY_CLOCK_167_MHZ_PNV
:
5388 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
5392 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
5394 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
5397 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
5398 case GC_DISPLAY_CLOCK_333_MHZ
:
5401 case GC_DISPLAY_CLOCK_190_200_MHZ
:
5407 static int i865_get_display_clock_speed(struct drm_device
*dev
)
5412 static int i855_get_display_clock_speed(struct drm_device
*dev
)
5415 /* Assume that the hardware is in the high speed state. This
5416 * should be the default.
5418 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
5419 case GC_CLOCK_133_200
:
5420 case GC_CLOCK_100_200
:
5422 case GC_CLOCK_166_250
:
5424 case GC_CLOCK_100_133
:
5428 /* Shouldn't happen */
5432 static int i830_get_display_clock_speed(struct drm_device
*dev
)
5438 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
5440 while (*num
> DATA_LINK_M_N_MASK
||
5441 *den
> DATA_LINK_M_N_MASK
) {
5447 static void compute_m_n(unsigned int m
, unsigned int n
,
5448 uint32_t *ret_m
, uint32_t *ret_n
)
5450 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
5451 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
5452 intel_reduce_m_n_ratio(ret_m
, ret_n
);
5456 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
5457 int pixel_clock
, int link_clock
,
5458 struct intel_link_m_n
*m_n
)
5462 compute_m_n(bits_per_pixel
* pixel_clock
,
5463 link_clock
* nlanes
* 8,
5464 &m_n
->gmch_m
, &m_n
->gmch_n
);
5466 compute_m_n(pixel_clock
, link_clock
,
5467 &m_n
->link_m
, &m_n
->link_n
);
5470 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
5472 if (i915
.panel_use_ssc
>= 0)
5473 return i915
.panel_use_ssc
!= 0;
5474 return dev_priv
->vbt
.lvds_use_ssc
5475 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
5478 static int i9xx_get_refclk(struct drm_crtc
*crtc
, int num_connectors
)
5480 struct drm_device
*dev
= crtc
->dev
;
5481 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5484 if (IS_VALLEYVIEW(dev
)) {
5486 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
5487 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
5488 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
5489 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
5490 } else if (!IS_GEN2(dev
)) {
5499 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
5501 return (1 << dpll
->n
) << 16 | dpll
->m2
;
5504 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
5506 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
5509 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
5510 intel_clock_t
*reduced_clock
)
5512 struct drm_device
*dev
= crtc
->base
.dev
;
5515 if (IS_PINEVIEW(dev
)) {
5516 fp
= pnv_dpll_compute_fp(&crtc
->config
.dpll
);
5518 fp2
= pnv_dpll_compute_fp(reduced_clock
);
5520 fp
= i9xx_dpll_compute_fp(&crtc
->config
.dpll
);
5522 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
5525 crtc
->config
.dpll_hw_state
.fp0
= fp
;
5527 crtc
->lowfreq_avail
= false;
5528 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5529 reduced_clock
&& i915
.powersave
) {
5530 crtc
->config
.dpll_hw_state
.fp1
= fp2
;
5531 crtc
->lowfreq_avail
= true;
5533 crtc
->config
.dpll_hw_state
.fp1
= fp
;
5537 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
5543 * PLLB opamp always calibrates to max value of 0x3f, force enable it
5544 * and set it to a reasonable value instead.
5546 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
5547 reg_val
&= 0xffffff00;
5548 reg_val
|= 0x00000030;
5549 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
5551 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
5552 reg_val
&= 0x8cffffff;
5553 reg_val
= 0x8c000000;
5554 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
5556 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
5557 reg_val
&= 0xffffff00;
5558 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
5560 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
5561 reg_val
&= 0x00ffffff;
5562 reg_val
|= 0xb0000000;
5563 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
5566 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
5567 struct intel_link_m_n
*m_n
)
5569 struct drm_device
*dev
= crtc
->base
.dev
;
5570 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5571 int pipe
= crtc
->pipe
;
5573 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5574 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
5575 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
5576 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
5579 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
5580 struct intel_link_m_n
*m_n
,
5581 struct intel_link_m_n
*m2_n2
)
5583 struct drm_device
*dev
= crtc
->base
.dev
;
5584 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5585 int pipe
= crtc
->pipe
;
5586 enum transcoder transcoder
= crtc
->config
.cpu_transcoder
;
5588 if (INTEL_INFO(dev
)->gen
>= 5) {
5589 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5590 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
5591 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
5592 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
5593 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
5594 * for gen < 8) and if DRRS is supported (to make sure the
5595 * registers are not unnecessarily accessed).
5597 if (m2_n2
&& INTEL_INFO(dev
)->gen
< 8 &&
5598 crtc
->config
.has_drrs
) {
5599 I915_WRITE(PIPE_DATA_M2(transcoder
),
5600 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
5601 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
5602 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
5603 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
5606 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5607 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
5608 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
5609 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
5613 void intel_dp_set_m_n(struct intel_crtc
*crtc
)
5615 if (crtc
->config
.has_pch_encoder
)
5616 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
.dp_m_n
);
5618 intel_cpu_transcoder_set_m_n(crtc
, &crtc
->config
.dp_m_n
,
5619 &crtc
->config
.dp_m2_n2
);
5622 static void vlv_update_pll(struct intel_crtc
*crtc
)
5627 * Enable DPIO clock input. We should never disable the reference
5628 * clock for pipe B, since VGA hotplug / manual detection depends
5631 dpll
= DPLL_EXT_BUFFER_ENABLE_VLV
| DPLL_REFA_CLK_ENABLE_VLV
|
5632 DPLL_VGA_MODE_DIS
| DPLL_INTEGRATED_CLOCK_VLV
;
5633 /* We should never disable this, set it here for state tracking */
5634 if (crtc
->pipe
== PIPE_B
)
5635 dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
5636 dpll
|= DPLL_VCO_ENABLE
;
5637 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
5639 dpll_md
= (crtc
->config
.pixel_multiplier
- 1)
5640 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5641 crtc
->config
.dpll_hw_state
.dpll_md
= dpll_md
;
5644 static void vlv_prepare_pll(struct intel_crtc
*crtc
)
5646 struct drm_device
*dev
= crtc
->base
.dev
;
5647 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5648 int pipe
= crtc
->pipe
;
5650 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
5651 u32 coreclk
, reg_val
;
5653 mutex_lock(&dev_priv
->dpio_lock
);
5655 bestn
= crtc
->config
.dpll
.n
;
5656 bestm1
= crtc
->config
.dpll
.m1
;
5657 bestm2
= crtc
->config
.dpll
.m2
;
5658 bestp1
= crtc
->config
.dpll
.p1
;
5659 bestp2
= crtc
->config
.dpll
.p2
;
5661 /* See eDP HDMI DPIO driver vbios notes doc */
5663 /* PLL B needs special handling */
5665 vlv_pllb_recal_opamp(dev_priv
, pipe
);
5667 /* Set up Tx target for periodic Rcomp update */
5668 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
5670 /* Disable target IRef on PLL */
5671 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
5672 reg_val
&= 0x00ffffff;
5673 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
5675 /* Disable fast lock */
5676 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
5678 /* Set idtafcrecal before PLL is enabled */
5679 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
5680 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
5681 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
5682 mdiv
|= (1 << DPIO_K_SHIFT
);
5685 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
5686 * but we don't support that).
5687 * Note: don't use the DAC post divider as it seems unstable.
5689 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
5690 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
5692 mdiv
|= DPIO_ENABLE_CALIBRATION
;
5693 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
5695 /* Set HBR and RBR LPF coefficients */
5696 if (crtc
->config
.port_clock
== 162000 ||
5697 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_ANALOG
) ||
5698 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
))
5699 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
5702 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
5705 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_EDP
) ||
5706 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
)) {
5707 /* Use SSC source */
5709 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5712 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5714 } else { /* HDMI or VGA */
5715 /* Use bend source */
5717 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5720 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5724 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
5725 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
5726 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
) ||
5727 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_EDP
))
5728 coreclk
|= 0x01000000;
5729 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
5731 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
5732 mutex_unlock(&dev_priv
->dpio_lock
);
5735 static void chv_update_pll(struct intel_crtc
*crtc
)
5737 crtc
->config
.dpll_hw_state
.dpll
= DPLL_SSC_REF_CLOCK_CHV
|
5738 DPLL_REFA_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
|
5740 if (crtc
->pipe
!= PIPE_A
)
5741 crtc
->config
.dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
5743 crtc
->config
.dpll_hw_state
.dpll_md
=
5744 (crtc
->config
.pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5747 static void chv_prepare_pll(struct intel_crtc
*crtc
)
5749 struct drm_device
*dev
= crtc
->base
.dev
;
5750 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5751 int pipe
= crtc
->pipe
;
5752 int dpll_reg
= DPLL(crtc
->pipe
);
5753 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
5754 u32 loopfilter
, intcoeff
;
5755 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
5758 bestn
= crtc
->config
.dpll
.n
;
5759 bestm2_frac
= crtc
->config
.dpll
.m2
& 0x3fffff;
5760 bestm1
= crtc
->config
.dpll
.m1
;
5761 bestm2
= crtc
->config
.dpll
.m2
>> 22;
5762 bestp1
= crtc
->config
.dpll
.p1
;
5763 bestp2
= crtc
->config
.dpll
.p2
;
5766 * Enable Refclk and SSC
5768 I915_WRITE(dpll_reg
,
5769 crtc
->config
.dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
5771 mutex_lock(&dev_priv
->dpio_lock
);
5773 /* p1 and p2 divider */
5774 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
5775 5 << DPIO_CHV_S1_DIV_SHIFT
|
5776 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
5777 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
5778 1 << DPIO_CHV_K_DIV_SHIFT
);
5780 /* Feedback post-divider - m2 */
5781 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
5783 /* Feedback refclk divider - n and m1 */
5784 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
5785 DPIO_CHV_M1_DIV_BY_2
|
5786 1 << DPIO_CHV_N_DIV_SHIFT
);
5788 /* M2 fraction division */
5789 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
5791 /* M2 fraction division enable */
5792 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
),
5793 DPIO_CHV_FRAC_DIV_EN
|
5794 (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
));
5797 refclk
= i9xx_get_refclk(&crtc
->base
, 0);
5798 loopfilter
= 5 << DPIO_CHV_PROP_COEFF_SHIFT
|
5799 2 << DPIO_CHV_GAIN_CTRL_SHIFT
;
5800 if (refclk
== 100000)
5802 else if (refclk
== 38400)
5806 loopfilter
|= intcoeff
<< DPIO_CHV_INT_COEFF_SHIFT
;
5807 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
5810 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
5811 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
5814 mutex_unlock(&dev_priv
->dpio_lock
);
5817 static void i9xx_update_pll(struct intel_crtc
*crtc
,
5818 intel_clock_t
*reduced_clock
,
5821 struct drm_device
*dev
= crtc
->base
.dev
;
5822 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5825 struct dpll
*clock
= &crtc
->config
.dpll
;
5827 i9xx_update_pll_dividers(crtc
, reduced_clock
);
5829 is_sdvo
= intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_SDVO
) ||
5830 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
);
5832 dpll
= DPLL_VGA_MODE_DIS
;
5834 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
))
5835 dpll
|= DPLLB_MODE_LVDS
;
5837 dpll
|= DPLLB_MODE_DAC_SERIAL
;
5839 if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
5840 dpll
|= (crtc
->config
.pixel_multiplier
- 1)
5841 << SDVO_MULTIPLIER_SHIFT_HIRES
;
5845 dpll
|= DPLL_SDVO_HIGH_SPEED
;
5847 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
))
5848 dpll
|= DPLL_SDVO_HIGH_SPEED
;
5850 /* compute bitmask from p1 value */
5851 if (IS_PINEVIEW(dev
))
5852 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
5854 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5855 if (IS_G4X(dev
) && reduced_clock
)
5856 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
5858 switch (clock
->p2
) {
5860 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
5863 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
5866 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
5869 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
5872 if (INTEL_INFO(dev
)->gen
>= 4)
5873 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
5875 if (crtc
->config
.sdvo_tv_clock
)
5876 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
5877 else if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5878 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
5879 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
5881 dpll
|= PLL_REF_INPUT_DREFCLK
;
5883 dpll
|= DPLL_VCO_ENABLE
;
5884 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
5886 if (INTEL_INFO(dev
)->gen
>= 4) {
5887 u32 dpll_md
= (crtc
->config
.pixel_multiplier
- 1)
5888 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5889 crtc
->config
.dpll_hw_state
.dpll_md
= dpll_md
;
5893 static void i8xx_update_pll(struct intel_crtc
*crtc
,
5894 intel_clock_t
*reduced_clock
,
5897 struct drm_device
*dev
= crtc
->base
.dev
;
5898 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5900 struct dpll
*clock
= &crtc
->config
.dpll
;
5902 i9xx_update_pll_dividers(crtc
, reduced_clock
);
5904 dpll
= DPLL_VGA_MODE_DIS
;
5906 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
)) {
5907 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5910 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
5912 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5914 dpll
|= PLL_P2_DIVIDE_BY_4
;
5917 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DVO
))
5918 dpll
|= DPLL_DVO_2X_MODE
;
5920 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5921 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
5922 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
5924 dpll
|= PLL_REF_INPUT_DREFCLK
;
5926 dpll
|= DPLL_VCO_ENABLE
;
5927 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
5930 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
5932 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5933 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5934 enum pipe pipe
= intel_crtc
->pipe
;
5935 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
5936 struct drm_display_mode
*adjusted_mode
=
5937 &intel_crtc
->config
.adjusted_mode
;
5938 uint32_t crtc_vtotal
, crtc_vblank_end
;
5941 /* We need to be careful not to changed the adjusted mode, for otherwise
5942 * the hw state checker will get angry at the mismatch. */
5943 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
5944 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
5946 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
5947 /* the chip adds 2 halflines automatically */
5949 crtc_vblank_end
-= 1;
5951 if (intel_pipe_has_type(&intel_crtc
->base
, INTEL_OUTPUT_SDVO
))
5952 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
5954 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
5955 adjusted_mode
->crtc_htotal
/ 2;
5957 vsyncshift
+= adjusted_mode
->crtc_htotal
;
5960 if (INTEL_INFO(dev
)->gen
> 3)
5961 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
5963 I915_WRITE(HTOTAL(cpu_transcoder
),
5964 (adjusted_mode
->crtc_hdisplay
- 1) |
5965 ((adjusted_mode
->crtc_htotal
- 1) << 16));
5966 I915_WRITE(HBLANK(cpu_transcoder
),
5967 (adjusted_mode
->crtc_hblank_start
- 1) |
5968 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
5969 I915_WRITE(HSYNC(cpu_transcoder
),
5970 (adjusted_mode
->crtc_hsync_start
- 1) |
5971 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
5973 I915_WRITE(VTOTAL(cpu_transcoder
),
5974 (adjusted_mode
->crtc_vdisplay
- 1) |
5975 ((crtc_vtotal
- 1) << 16));
5976 I915_WRITE(VBLANK(cpu_transcoder
),
5977 (adjusted_mode
->crtc_vblank_start
- 1) |
5978 ((crtc_vblank_end
- 1) << 16));
5979 I915_WRITE(VSYNC(cpu_transcoder
),
5980 (adjusted_mode
->crtc_vsync_start
- 1) |
5981 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
5983 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
5984 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
5985 * documented on the DDI_FUNC_CTL register description, EDP Input Select
5987 if (IS_HASWELL(dev
) && cpu_transcoder
== TRANSCODER_EDP
&&
5988 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
5989 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
5991 /* pipesrc controls the size that is scaled from, which should
5992 * always be the user's requested size.
5994 I915_WRITE(PIPESRC(pipe
),
5995 ((intel_crtc
->config
.pipe_src_w
- 1) << 16) |
5996 (intel_crtc
->config
.pipe_src_h
- 1));
5999 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
6000 struct intel_crtc_config
*pipe_config
)
6002 struct drm_device
*dev
= crtc
->base
.dev
;
6003 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6004 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
6007 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
6008 pipe_config
->adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
6009 pipe_config
->adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
6010 tmp
= I915_READ(HBLANK(cpu_transcoder
));
6011 pipe_config
->adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
6012 pipe_config
->adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
6013 tmp
= I915_READ(HSYNC(cpu_transcoder
));
6014 pipe_config
->adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
6015 pipe_config
->adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
6017 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
6018 pipe_config
->adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
6019 pipe_config
->adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
6020 tmp
= I915_READ(VBLANK(cpu_transcoder
));
6021 pipe_config
->adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
6022 pipe_config
->adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
6023 tmp
= I915_READ(VSYNC(cpu_transcoder
));
6024 pipe_config
->adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
6025 pipe_config
->adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
6027 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
6028 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
6029 pipe_config
->adjusted_mode
.crtc_vtotal
+= 1;
6030 pipe_config
->adjusted_mode
.crtc_vblank_end
+= 1;
6033 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
6034 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
6035 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
6037 pipe_config
->requested_mode
.vdisplay
= pipe_config
->pipe_src_h
;
6038 pipe_config
->requested_mode
.hdisplay
= pipe_config
->pipe_src_w
;
6041 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
6042 struct intel_crtc_config
*pipe_config
)
6044 mode
->hdisplay
= pipe_config
->adjusted_mode
.crtc_hdisplay
;
6045 mode
->htotal
= pipe_config
->adjusted_mode
.crtc_htotal
;
6046 mode
->hsync_start
= pipe_config
->adjusted_mode
.crtc_hsync_start
;
6047 mode
->hsync_end
= pipe_config
->adjusted_mode
.crtc_hsync_end
;
6049 mode
->vdisplay
= pipe_config
->adjusted_mode
.crtc_vdisplay
;
6050 mode
->vtotal
= pipe_config
->adjusted_mode
.crtc_vtotal
;
6051 mode
->vsync_start
= pipe_config
->adjusted_mode
.crtc_vsync_start
;
6052 mode
->vsync_end
= pipe_config
->adjusted_mode
.crtc_vsync_end
;
6054 mode
->flags
= pipe_config
->adjusted_mode
.flags
;
6056 mode
->clock
= pipe_config
->adjusted_mode
.crtc_clock
;
6057 mode
->flags
|= pipe_config
->adjusted_mode
.flags
;
6060 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
6062 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6063 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6068 if ((intel_crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
6069 (intel_crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
6070 pipeconf
|= I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
;
6072 if (intel_crtc
->config
.double_wide
)
6073 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
6075 /* only g4x and later have fancy bpc/dither controls */
6076 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
6077 /* Bspec claims that we can't use dithering for 30bpp pipes. */
6078 if (intel_crtc
->config
.dither
&& intel_crtc
->config
.pipe_bpp
!= 30)
6079 pipeconf
|= PIPECONF_DITHER_EN
|
6080 PIPECONF_DITHER_TYPE_SP
;
6082 switch (intel_crtc
->config
.pipe_bpp
) {
6084 pipeconf
|= PIPECONF_6BPC
;
6087 pipeconf
|= PIPECONF_8BPC
;
6090 pipeconf
|= PIPECONF_10BPC
;
6093 /* Case prevented by intel_choose_pipe_bpp_dither. */
6098 if (HAS_PIPE_CXSR(dev
)) {
6099 if (intel_crtc
->lowfreq_avail
) {
6100 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
6101 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
6103 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
6107 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
6108 if (INTEL_INFO(dev
)->gen
< 4 ||
6109 intel_pipe_has_type(&intel_crtc
->base
, INTEL_OUTPUT_SDVO
))
6110 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
6112 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
6114 pipeconf
|= PIPECONF_PROGRESSIVE
;
6116 if (IS_VALLEYVIEW(dev
) && intel_crtc
->config
.limited_color_range
)
6117 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
6119 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
6120 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
6123 static int i9xx_crtc_mode_set(struct drm_crtc
*crtc
,
6125 struct drm_framebuffer
*fb
)
6127 struct drm_device
*dev
= crtc
->dev
;
6128 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6129 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6130 int refclk
, num_connectors
= 0;
6131 intel_clock_t clock
, reduced_clock
;
6132 bool ok
, has_reduced_clock
= false;
6133 bool is_lvds
= false, is_dsi
= false;
6134 struct intel_encoder
*encoder
;
6135 const intel_limit_t
*limit
;
6137 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
6138 switch (encoder
->type
) {
6139 case INTEL_OUTPUT_LVDS
:
6142 case INTEL_OUTPUT_DSI
:
6153 if (!intel_crtc
->config
.clock_set
) {
6154 refclk
= i9xx_get_refclk(crtc
, num_connectors
);
6157 * Returns a set of divisors for the desired target clock with
6158 * the given refclk, or FALSE. The returned values represent
6159 * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
6162 limit
= intel_limit(crtc
, refclk
);
6163 ok
= dev_priv
->display
.find_dpll(limit
, crtc
,
6164 intel_crtc
->config
.port_clock
,
6165 refclk
, NULL
, &clock
);
6167 DRM_ERROR("Couldn't find PLL settings for mode!\n");
6171 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
6173 * Ensure we match the reduced clock's P to the target
6174 * clock. If the clocks don't match, we can't switch
6175 * the display clock by using the FP0/FP1. In such case
6176 * we will disable the LVDS downclock feature.
6179 dev_priv
->display
.find_dpll(limit
, crtc
,
6180 dev_priv
->lvds_downclock
,
6184 /* Compat-code for transition, will disappear. */
6185 intel_crtc
->config
.dpll
.n
= clock
.n
;
6186 intel_crtc
->config
.dpll
.m1
= clock
.m1
;
6187 intel_crtc
->config
.dpll
.m2
= clock
.m2
;
6188 intel_crtc
->config
.dpll
.p1
= clock
.p1
;
6189 intel_crtc
->config
.dpll
.p2
= clock
.p2
;
6193 i8xx_update_pll(intel_crtc
,
6194 has_reduced_clock
? &reduced_clock
: NULL
,
6196 } else if (IS_CHERRYVIEW(dev
)) {
6197 chv_update_pll(intel_crtc
);
6198 } else if (IS_VALLEYVIEW(dev
)) {
6199 vlv_update_pll(intel_crtc
);
6201 i9xx_update_pll(intel_crtc
,
6202 has_reduced_clock
? &reduced_clock
: NULL
,
6209 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
6210 struct intel_crtc_config
*pipe_config
)
6212 struct drm_device
*dev
= crtc
->base
.dev
;
6213 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6216 if (INTEL_INFO(dev
)->gen
<= 3 && (IS_I830(dev
) || !IS_MOBILE(dev
)))
6219 tmp
= I915_READ(PFIT_CONTROL
);
6220 if (!(tmp
& PFIT_ENABLE
))
6223 /* Check whether the pfit is attached to our pipe. */
6224 if (INTEL_INFO(dev
)->gen
< 4) {
6225 if (crtc
->pipe
!= PIPE_B
)
6228 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
6232 pipe_config
->gmch_pfit
.control
= tmp
;
6233 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
6234 if (INTEL_INFO(dev
)->gen
< 5)
6235 pipe_config
->gmch_pfit
.lvds_border_bits
=
6236 I915_READ(LVDS
) & LVDS_BORDER_ENABLE
;
6239 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
6240 struct intel_crtc_config
*pipe_config
)
6242 struct drm_device
*dev
= crtc
->base
.dev
;
6243 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6244 int pipe
= pipe_config
->cpu_transcoder
;
6245 intel_clock_t clock
;
6247 int refclk
= 100000;
6249 /* In case of MIPI DPLL will not even be used */
6250 if (!(pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
))
6253 mutex_lock(&dev_priv
->dpio_lock
);
6254 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
6255 mutex_unlock(&dev_priv
->dpio_lock
);
6257 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
6258 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
6259 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
6260 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
6261 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
6263 vlv_clock(refclk
, &clock
);
6265 /* clock.dot is the fast clock */
6266 pipe_config
->port_clock
= clock
.dot
/ 5;
6269 static void i9xx_get_plane_config(struct intel_crtc
*crtc
,
6270 struct intel_plane_config
*plane_config
)
6272 struct drm_device
*dev
= crtc
->base
.dev
;
6273 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6274 u32 val
, base
, offset
;
6275 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
6276 int fourcc
, pixel_format
;
6279 crtc
->base
.primary
->fb
= kzalloc(sizeof(struct intel_framebuffer
), GFP_KERNEL
);
6280 if (!crtc
->base
.primary
->fb
) {
6281 DRM_DEBUG_KMS("failed to alloc fb\n");
6285 val
= I915_READ(DSPCNTR(plane
));
6287 if (INTEL_INFO(dev
)->gen
>= 4)
6288 if (val
& DISPPLANE_TILED
)
6289 plane_config
->tiled
= true;
6291 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
6292 fourcc
= intel_format_to_fourcc(pixel_format
);
6293 crtc
->base
.primary
->fb
->pixel_format
= fourcc
;
6294 crtc
->base
.primary
->fb
->bits_per_pixel
=
6295 drm_format_plane_cpp(fourcc
, 0) * 8;
6297 if (INTEL_INFO(dev
)->gen
>= 4) {
6298 if (plane_config
->tiled
)
6299 offset
= I915_READ(DSPTILEOFF(plane
));
6301 offset
= I915_READ(DSPLINOFF(plane
));
6302 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
6304 base
= I915_READ(DSPADDR(plane
));
6306 plane_config
->base
= base
;
6308 val
= I915_READ(PIPESRC(pipe
));
6309 crtc
->base
.primary
->fb
->width
= ((val
>> 16) & 0xfff) + 1;
6310 crtc
->base
.primary
->fb
->height
= ((val
>> 0) & 0xfff) + 1;
6312 val
= I915_READ(DSPSTRIDE(pipe
));
6313 crtc
->base
.primary
->fb
->pitches
[0] = val
& 0xffffffc0;
6315 aligned_height
= intel_align_height(dev
, crtc
->base
.primary
->fb
->height
,
6316 plane_config
->tiled
);
6318 plane_config
->size
= PAGE_ALIGN(crtc
->base
.primary
->fb
->pitches
[0] *
6321 DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
6322 pipe
, plane
, crtc
->base
.primary
->fb
->width
,
6323 crtc
->base
.primary
->fb
->height
,
6324 crtc
->base
.primary
->fb
->bits_per_pixel
, base
,
6325 crtc
->base
.primary
->fb
->pitches
[0],
6326 plane_config
->size
);
6330 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
6331 struct intel_crtc_config
*pipe_config
)
6333 struct drm_device
*dev
= crtc
->base
.dev
;
6334 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6335 int pipe
= pipe_config
->cpu_transcoder
;
6336 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
6337 intel_clock_t clock
;
6338 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
;
6339 int refclk
= 100000;
6341 mutex_lock(&dev_priv
->dpio_lock
);
6342 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
6343 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
6344 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
6345 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
6346 mutex_unlock(&dev_priv
->dpio_lock
);
6348 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
6349 clock
.m2
= ((pll_dw0
& 0xff) << 22) | (pll_dw2
& 0x3fffff);
6350 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
6351 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
6352 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
6354 chv_clock(refclk
, &clock
);
6356 /* clock.dot is the fast clock */
6357 pipe_config
->port_clock
= clock
.dot
/ 5;
6360 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
6361 struct intel_crtc_config
*pipe_config
)
6363 struct drm_device
*dev
= crtc
->base
.dev
;
6364 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6367 if (!intel_display_power_enabled(dev_priv
,
6368 POWER_DOMAIN_PIPE(crtc
->pipe
)))
6371 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
6372 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
6374 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
6375 if (!(tmp
& PIPECONF_ENABLE
))
6378 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
6379 switch (tmp
& PIPECONF_BPC_MASK
) {
6381 pipe_config
->pipe_bpp
= 18;
6384 pipe_config
->pipe_bpp
= 24;
6386 case PIPECONF_10BPC
:
6387 pipe_config
->pipe_bpp
= 30;
6394 if (IS_VALLEYVIEW(dev
) && (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
6395 pipe_config
->limited_color_range
= true;
6397 if (INTEL_INFO(dev
)->gen
< 4)
6398 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
6400 intel_get_pipe_timings(crtc
, pipe_config
);
6402 i9xx_get_pfit_config(crtc
, pipe_config
);
6404 if (INTEL_INFO(dev
)->gen
>= 4) {
6405 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
6406 pipe_config
->pixel_multiplier
=
6407 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
6408 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
6409 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
6410 } else if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
6411 tmp
= I915_READ(DPLL(crtc
->pipe
));
6412 pipe_config
->pixel_multiplier
=
6413 ((tmp
& SDVO_MULTIPLIER_MASK
)
6414 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
6416 /* Note that on i915G/GM the pixel multiplier is in the sdvo
6417 * port and will be fixed up in the encoder->get_config
6419 pipe_config
->pixel_multiplier
= 1;
6421 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
6422 if (!IS_VALLEYVIEW(dev
)) {
6423 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
6424 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
6426 /* Mask out read-only status bits. */
6427 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
6428 DPLL_PORTC_READY_MASK
|
6429 DPLL_PORTB_READY_MASK
);
6432 if (IS_CHERRYVIEW(dev
))
6433 chv_crtc_clock_get(crtc
, pipe_config
);
6434 else if (IS_VALLEYVIEW(dev
))
6435 vlv_crtc_clock_get(crtc
, pipe_config
);
6437 i9xx_crtc_clock_get(crtc
, pipe_config
);
6442 static void ironlake_init_pch_refclk(struct drm_device
*dev
)
6444 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6445 struct intel_encoder
*encoder
;
6447 bool has_lvds
= false;
6448 bool has_cpu_edp
= false;
6449 bool has_panel
= false;
6450 bool has_ck505
= false;
6451 bool can_ssc
= false;
6453 /* We need to take the global config into account */
6454 for_each_intel_encoder(dev
, encoder
) {
6455 switch (encoder
->type
) {
6456 case INTEL_OUTPUT_LVDS
:
6460 case INTEL_OUTPUT_EDP
:
6462 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
6468 if (HAS_PCH_IBX(dev
)) {
6469 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
6470 can_ssc
= has_ck505
;
6476 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
6477 has_panel
, has_lvds
, has_ck505
);
6479 /* Ironlake: try to setup display ref clock before DPLL
6480 * enabling. This is only under driver's control after
6481 * PCH B stepping, previous chipset stepping should be
6482 * ignoring this setting.
6484 val
= I915_READ(PCH_DREF_CONTROL
);
6486 /* As we must carefully and slowly disable/enable each source in turn,
6487 * compute the final state we want first and check if we need to
6488 * make any changes at all.
6491 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
6493 final
|= DREF_NONSPREAD_CK505_ENABLE
;
6495 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
6497 final
&= ~DREF_SSC_SOURCE_MASK
;
6498 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6499 final
&= ~DREF_SSC1_ENABLE
;
6502 final
|= DREF_SSC_SOURCE_ENABLE
;
6504 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
6505 final
|= DREF_SSC1_ENABLE
;
6508 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
6509 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
6511 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
6513 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6515 final
|= DREF_SSC_SOURCE_DISABLE
;
6516 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6522 /* Always enable nonspread source */
6523 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
6526 val
|= DREF_NONSPREAD_CK505_ENABLE
;
6528 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
6531 val
&= ~DREF_SSC_SOURCE_MASK
;
6532 val
|= DREF_SSC_SOURCE_ENABLE
;
6534 /* SSC must be turned on before enabling the CPU output */
6535 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
6536 DRM_DEBUG_KMS("Using SSC on panel\n");
6537 val
|= DREF_SSC1_ENABLE
;
6539 val
&= ~DREF_SSC1_ENABLE
;
6541 /* Get SSC going before enabling the outputs */
6542 I915_WRITE(PCH_DREF_CONTROL
, val
);
6543 POSTING_READ(PCH_DREF_CONTROL
);
6546 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6548 /* Enable CPU source on CPU attached eDP */
6550 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
6551 DRM_DEBUG_KMS("Using SSC on eDP\n");
6552 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
6554 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
6556 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6558 I915_WRITE(PCH_DREF_CONTROL
, val
);
6559 POSTING_READ(PCH_DREF_CONTROL
);
6562 DRM_DEBUG_KMS("Disabling SSC entirely\n");
6564 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6566 /* Turn off CPU output */
6567 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6569 I915_WRITE(PCH_DREF_CONTROL
, val
);
6570 POSTING_READ(PCH_DREF_CONTROL
);
6573 /* Turn off the SSC source */
6574 val
&= ~DREF_SSC_SOURCE_MASK
;
6575 val
|= DREF_SSC_SOURCE_DISABLE
;
6578 val
&= ~DREF_SSC1_ENABLE
;
6580 I915_WRITE(PCH_DREF_CONTROL
, val
);
6581 POSTING_READ(PCH_DREF_CONTROL
);
6585 BUG_ON(val
!= final
);
6588 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
6592 tmp
= I915_READ(SOUTH_CHICKEN2
);
6593 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
6594 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
6596 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2
) &
6597 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
6598 DRM_ERROR("FDI mPHY reset assert timeout\n");
6600 tmp
= I915_READ(SOUTH_CHICKEN2
);
6601 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
6602 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
6604 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2
) &
6605 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
6606 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
6609 /* WaMPhyProgramming:hsw */
6610 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
6614 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
6615 tmp
&= ~(0xFF << 24);
6616 tmp
|= (0x12 << 24);
6617 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
6619 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
6621 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
6623 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
6625 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
6627 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
6628 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
6629 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
6631 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
6632 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
6633 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
6635 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
6638 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
6640 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
6643 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
6645 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
6648 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
6650 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
6653 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
6655 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
6656 tmp
&= ~(0xFF << 16);
6657 tmp
|= (0x1C << 16);
6658 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
6660 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
6661 tmp
&= ~(0xFF << 16);
6662 tmp
|= (0x1C << 16);
6663 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
6665 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
6667 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
6669 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
6671 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
6673 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
6674 tmp
&= ~(0xF << 28);
6676 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
6678 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
6679 tmp
&= ~(0xF << 28);
6681 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
6684 /* Implements 3 different sequences from BSpec chapter "Display iCLK
6685 * Programming" based on the parameters passed:
6686 * - Sequence to enable CLKOUT_DP
6687 * - Sequence to enable CLKOUT_DP without spread
6688 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
6690 static void lpt_enable_clkout_dp(struct drm_device
*dev
, bool with_spread
,
6693 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6696 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
6698 if (WARN(dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
&&
6699 with_fdi
, "LP PCH doesn't have FDI\n"))
6702 mutex_lock(&dev_priv
->dpio_lock
);
6704 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6705 tmp
&= ~SBI_SSCCTL_DISABLE
;
6706 tmp
|= SBI_SSCCTL_PATHALT
;
6707 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6712 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6713 tmp
&= ~SBI_SSCCTL_PATHALT
;
6714 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6717 lpt_reset_fdi_mphy(dev_priv
);
6718 lpt_program_fdi_mphy(dev_priv
);
6722 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
6723 SBI_GEN0
: SBI_DBUFF0
;
6724 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
6725 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
6726 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
6728 mutex_unlock(&dev_priv
->dpio_lock
);
6731 /* Sequence to disable CLKOUT_DP */
6732 static void lpt_disable_clkout_dp(struct drm_device
*dev
)
6734 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6737 mutex_lock(&dev_priv
->dpio_lock
);
6739 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
6740 SBI_GEN0
: SBI_DBUFF0
;
6741 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
6742 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
6743 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
6745 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6746 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
6747 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
6748 tmp
|= SBI_SSCCTL_PATHALT
;
6749 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6752 tmp
|= SBI_SSCCTL_DISABLE
;
6753 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6756 mutex_unlock(&dev_priv
->dpio_lock
);
6759 static void lpt_init_pch_refclk(struct drm_device
*dev
)
6761 struct intel_encoder
*encoder
;
6762 bool has_vga
= false;
6764 for_each_intel_encoder(dev
, encoder
) {
6765 switch (encoder
->type
) {
6766 case INTEL_OUTPUT_ANALOG
:
6773 lpt_enable_clkout_dp(dev
, true, true);
6775 lpt_disable_clkout_dp(dev
);
6779 * Initialize reference clocks when the driver loads
6781 void intel_init_pch_refclk(struct drm_device
*dev
)
6783 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
6784 ironlake_init_pch_refclk(dev
);
6785 else if (HAS_PCH_LPT(dev
))
6786 lpt_init_pch_refclk(dev
);
6789 static int ironlake_get_refclk(struct drm_crtc
*crtc
)
6791 struct drm_device
*dev
= crtc
->dev
;
6792 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6793 struct intel_encoder
*encoder
;
6794 int num_connectors
= 0;
6795 bool is_lvds
= false;
6797 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
6798 switch (encoder
->type
) {
6799 case INTEL_OUTPUT_LVDS
:
6806 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
6807 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
6808 dev_priv
->vbt
.lvds_ssc_freq
);
6809 return dev_priv
->vbt
.lvds_ssc_freq
;
6815 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
6817 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
6818 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6819 int pipe
= intel_crtc
->pipe
;
6824 switch (intel_crtc
->config
.pipe_bpp
) {
6826 val
|= PIPECONF_6BPC
;
6829 val
|= PIPECONF_8BPC
;
6832 val
|= PIPECONF_10BPC
;
6835 val
|= PIPECONF_12BPC
;
6838 /* Case prevented by intel_choose_pipe_bpp_dither. */
6842 if (intel_crtc
->config
.dither
)
6843 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
6845 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
6846 val
|= PIPECONF_INTERLACED_ILK
;
6848 val
|= PIPECONF_PROGRESSIVE
;
6850 if (intel_crtc
->config
.limited_color_range
)
6851 val
|= PIPECONF_COLOR_RANGE_SELECT
;
6853 I915_WRITE(PIPECONF(pipe
), val
);
6854 POSTING_READ(PIPECONF(pipe
));
6858 * Set up the pipe CSC unit.
6860 * Currently only full range RGB to limited range RGB conversion
6861 * is supported, but eventually this should handle various
6862 * RGB<->YCbCr scenarios as well.
6864 static void intel_set_pipe_csc(struct drm_crtc
*crtc
)
6866 struct drm_device
*dev
= crtc
->dev
;
6867 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6868 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6869 int pipe
= intel_crtc
->pipe
;
6870 uint16_t coeff
= 0x7800; /* 1.0 */
6873 * TODO: Check what kind of values actually come out of the pipe
6874 * with these coeff/postoff values and adjust to get the best
6875 * accuracy. Perhaps we even need to take the bpc value into
6879 if (intel_crtc
->config
.limited_color_range
)
6880 coeff
= ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
6883 * GY/GU and RY/RU should be the other way around according
6884 * to BSpec, but reality doesn't agree. Just set them up in
6885 * a way that results in the correct picture.
6887 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe
), coeff
<< 16);
6888 I915_WRITE(PIPE_CSC_COEFF_BY(pipe
), 0);
6890 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe
), coeff
);
6891 I915_WRITE(PIPE_CSC_COEFF_BU(pipe
), 0);
6893 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe
), 0);
6894 I915_WRITE(PIPE_CSC_COEFF_BV(pipe
), coeff
<< 16);
6896 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe
), 0);
6897 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe
), 0);
6898 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe
), 0);
6900 if (INTEL_INFO(dev
)->gen
> 6) {
6901 uint16_t postoff
= 0;
6903 if (intel_crtc
->config
.limited_color_range
)
6904 postoff
= (16 * (1 << 12) / 255) & 0x1fff;
6906 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe
), postoff
);
6907 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe
), postoff
);
6908 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe
), postoff
);
6910 I915_WRITE(PIPE_CSC_MODE(pipe
), 0);
6912 uint32_t mode
= CSC_MODE_YUV_TO_RGB
;
6914 if (intel_crtc
->config
.limited_color_range
)
6915 mode
|= CSC_BLACK_SCREEN_OFFSET
;
6917 I915_WRITE(PIPE_CSC_MODE(pipe
), mode
);
6921 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
6923 struct drm_device
*dev
= crtc
->dev
;
6924 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6925 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6926 enum pipe pipe
= intel_crtc
->pipe
;
6927 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
6932 if (IS_HASWELL(dev
) && intel_crtc
->config
.dither
)
6933 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
6935 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
6936 val
|= PIPECONF_INTERLACED_ILK
;
6938 val
|= PIPECONF_PROGRESSIVE
;
6940 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
6941 POSTING_READ(PIPECONF(cpu_transcoder
));
6943 I915_WRITE(GAMMA_MODE(intel_crtc
->pipe
), GAMMA_MODE_MODE_8BIT
);
6944 POSTING_READ(GAMMA_MODE(intel_crtc
->pipe
));
6946 if (IS_BROADWELL(dev
)) {
6949 switch (intel_crtc
->config
.pipe_bpp
) {
6951 val
|= PIPEMISC_DITHER_6_BPC
;
6954 val
|= PIPEMISC_DITHER_8_BPC
;
6957 val
|= PIPEMISC_DITHER_10_BPC
;
6960 val
|= PIPEMISC_DITHER_12_BPC
;
6963 /* Case prevented by pipe_config_set_bpp. */
6967 if (intel_crtc
->config
.dither
)
6968 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
6970 I915_WRITE(PIPEMISC(pipe
), val
);
6974 static bool ironlake_compute_clocks(struct drm_crtc
*crtc
,
6975 intel_clock_t
*clock
,
6976 bool *has_reduced_clock
,
6977 intel_clock_t
*reduced_clock
)
6979 struct drm_device
*dev
= crtc
->dev
;
6980 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6981 struct intel_encoder
*intel_encoder
;
6983 const intel_limit_t
*limit
;
6984 bool ret
, is_lvds
= false;
6986 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
6987 switch (intel_encoder
->type
) {
6988 case INTEL_OUTPUT_LVDS
:
6994 refclk
= ironlake_get_refclk(crtc
);
6997 * Returns a set of divisors for the desired target clock with the given
6998 * refclk, or FALSE. The returned values represent the clock equation:
6999 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
7001 limit
= intel_limit(crtc
, refclk
);
7002 ret
= dev_priv
->display
.find_dpll(limit
, crtc
,
7003 to_intel_crtc(crtc
)->config
.port_clock
,
7004 refclk
, NULL
, clock
);
7008 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
7010 * Ensure we match the reduced clock's P to the target clock.
7011 * If the clocks don't match, we can't switch the display clock
7012 * by using the FP0/FP1. In such case we will disable the LVDS
7013 * downclock feature.
7015 *has_reduced_clock
=
7016 dev_priv
->display
.find_dpll(limit
, crtc
,
7017 dev_priv
->lvds_downclock
,
7025 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
7028 * Account for spread spectrum to avoid
7029 * oversubscribing the link. Max center spread
7030 * is 2.5%; use 5% for safety's sake.
7032 u32 bps
= target_clock
* bpp
* 21 / 20;
7033 return DIV_ROUND_UP(bps
, link_bw
* 8);
7036 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
7038 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
7041 static uint32_t ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
7043 intel_clock_t
*reduced_clock
, u32
*fp2
)
7045 struct drm_crtc
*crtc
= &intel_crtc
->base
;
7046 struct drm_device
*dev
= crtc
->dev
;
7047 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7048 struct intel_encoder
*intel_encoder
;
7050 int factor
, num_connectors
= 0;
7051 bool is_lvds
= false, is_sdvo
= false;
7053 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
7054 switch (intel_encoder
->type
) {
7055 case INTEL_OUTPUT_LVDS
:
7058 case INTEL_OUTPUT_SDVO
:
7059 case INTEL_OUTPUT_HDMI
:
7067 /* Enable autotuning of the PLL clock (if permissible) */
7070 if ((intel_panel_use_ssc(dev_priv
) &&
7071 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
7072 (HAS_PCH_IBX(dev
) && intel_is_dual_link_lvds(dev
)))
7074 } else if (intel_crtc
->config
.sdvo_tv_clock
)
7077 if (ironlake_needs_fb_cb_tune(&intel_crtc
->config
.dpll
, factor
))
7080 if (fp2
&& (reduced_clock
->m
< factor
* reduced_clock
->n
))
7086 dpll
|= DPLLB_MODE_LVDS
;
7088 dpll
|= DPLLB_MODE_DAC_SERIAL
;
7090 dpll
|= (intel_crtc
->config
.pixel_multiplier
- 1)
7091 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
7094 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7095 if (intel_crtc
->config
.has_dp_encoder
)
7096 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7098 /* compute bitmask from p1 value */
7099 dpll
|= (1 << (intel_crtc
->config
.dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7101 dpll
|= (1 << (intel_crtc
->config
.dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
7103 switch (intel_crtc
->config
.dpll
.p2
) {
7105 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
7108 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
7111 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
7114 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
7118 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
7119 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7121 dpll
|= PLL_REF_INPUT_DREFCLK
;
7123 return dpll
| DPLL_VCO_ENABLE
;
7126 static int ironlake_crtc_mode_set(struct drm_crtc
*crtc
,
7128 struct drm_framebuffer
*fb
)
7130 struct drm_device
*dev
= crtc
->dev
;
7131 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7132 int num_connectors
= 0;
7133 intel_clock_t clock
, reduced_clock
;
7134 u32 dpll
= 0, fp
= 0, fp2
= 0;
7135 bool ok
, has_reduced_clock
= false;
7136 bool is_lvds
= false;
7137 struct intel_encoder
*encoder
;
7138 struct intel_shared_dpll
*pll
;
7140 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
7141 switch (encoder
->type
) {
7142 case INTEL_OUTPUT_LVDS
:
7150 WARN(!(HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)),
7151 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev
));
7153 ok
= ironlake_compute_clocks(crtc
, &clock
,
7154 &has_reduced_clock
, &reduced_clock
);
7155 if (!ok
&& !intel_crtc
->config
.clock_set
) {
7156 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7159 /* Compat-code for transition, will disappear. */
7160 if (!intel_crtc
->config
.clock_set
) {
7161 intel_crtc
->config
.dpll
.n
= clock
.n
;
7162 intel_crtc
->config
.dpll
.m1
= clock
.m1
;
7163 intel_crtc
->config
.dpll
.m2
= clock
.m2
;
7164 intel_crtc
->config
.dpll
.p1
= clock
.p1
;
7165 intel_crtc
->config
.dpll
.p2
= clock
.p2
;
7168 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
7169 if (intel_crtc
->config
.has_pch_encoder
) {
7170 fp
= i9xx_dpll_compute_fp(&intel_crtc
->config
.dpll
);
7171 if (has_reduced_clock
)
7172 fp2
= i9xx_dpll_compute_fp(&reduced_clock
);
7174 dpll
= ironlake_compute_dpll(intel_crtc
,
7175 &fp
, &reduced_clock
,
7176 has_reduced_clock
? &fp2
: NULL
);
7178 intel_crtc
->config
.dpll_hw_state
.dpll
= dpll
;
7179 intel_crtc
->config
.dpll_hw_state
.fp0
= fp
;
7180 if (has_reduced_clock
)
7181 intel_crtc
->config
.dpll_hw_state
.fp1
= fp2
;
7183 intel_crtc
->config
.dpll_hw_state
.fp1
= fp
;
7185 pll
= intel_get_shared_dpll(intel_crtc
);
7187 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
7188 pipe_name(intel_crtc
->pipe
));
7192 intel_put_shared_dpll(intel_crtc
);
7194 if (is_lvds
&& has_reduced_clock
&& i915
.powersave
)
7195 intel_crtc
->lowfreq_avail
= true;
7197 intel_crtc
->lowfreq_avail
= false;
7202 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
7203 struct intel_link_m_n
*m_n
)
7205 struct drm_device
*dev
= crtc
->base
.dev
;
7206 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7207 enum pipe pipe
= crtc
->pipe
;
7209 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
7210 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
7211 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
7213 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
7214 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
7215 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7218 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
7219 enum transcoder transcoder
,
7220 struct intel_link_m_n
*m_n
,
7221 struct intel_link_m_n
*m2_n2
)
7223 struct drm_device
*dev
= crtc
->base
.dev
;
7224 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7225 enum pipe pipe
= crtc
->pipe
;
7227 if (INTEL_INFO(dev
)->gen
>= 5) {
7228 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
7229 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
7230 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
7232 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
7233 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
7234 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7235 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
7236 * gen < 8) and if DRRS is supported (to make sure the
7237 * registers are not unnecessarily read).
7239 if (m2_n2
&& INTEL_INFO(dev
)->gen
< 8 &&
7240 crtc
->config
.has_drrs
) {
7241 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
7242 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
7243 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
7245 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
7246 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
7247 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7250 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
7251 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
7252 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
7254 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
7255 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
7256 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7260 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
7261 struct intel_crtc_config
*pipe_config
)
7263 if (crtc
->config
.has_pch_encoder
)
7264 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
7266 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
7267 &pipe_config
->dp_m_n
,
7268 &pipe_config
->dp_m2_n2
);
7271 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
7272 struct intel_crtc_config
*pipe_config
)
7274 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
7275 &pipe_config
->fdi_m_n
, NULL
);
7278 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
7279 struct intel_crtc_config
*pipe_config
)
7281 struct drm_device
*dev
= crtc
->base
.dev
;
7282 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7285 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
7287 if (tmp
& PF_ENABLE
) {
7288 pipe_config
->pch_pfit
.enabled
= true;
7289 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
7290 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
7292 /* We currently do not free assignements of panel fitters on
7293 * ivb/hsw (since we don't use the higher upscaling modes which
7294 * differentiates them) so just WARN about this case for now. */
7296 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
7297 PF_PIPE_SEL_IVB(crtc
->pipe
));
7302 static void ironlake_get_plane_config(struct intel_crtc
*crtc
,
7303 struct intel_plane_config
*plane_config
)
7305 struct drm_device
*dev
= crtc
->base
.dev
;
7306 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7307 u32 val
, base
, offset
;
7308 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
7309 int fourcc
, pixel_format
;
7312 crtc
->base
.primary
->fb
= kzalloc(sizeof(struct intel_framebuffer
), GFP_KERNEL
);
7313 if (!crtc
->base
.primary
->fb
) {
7314 DRM_DEBUG_KMS("failed to alloc fb\n");
7318 val
= I915_READ(DSPCNTR(plane
));
7320 if (INTEL_INFO(dev
)->gen
>= 4)
7321 if (val
& DISPPLANE_TILED
)
7322 plane_config
->tiled
= true;
7324 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
7325 fourcc
= intel_format_to_fourcc(pixel_format
);
7326 crtc
->base
.primary
->fb
->pixel_format
= fourcc
;
7327 crtc
->base
.primary
->fb
->bits_per_pixel
=
7328 drm_format_plane_cpp(fourcc
, 0) * 8;
7330 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
7331 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
7332 offset
= I915_READ(DSPOFFSET(plane
));
7334 if (plane_config
->tiled
)
7335 offset
= I915_READ(DSPTILEOFF(plane
));
7337 offset
= I915_READ(DSPLINOFF(plane
));
7339 plane_config
->base
= base
;
7341 val
= I915_READ(PIPESRC(pipe
));
7342 crtc
->base
.primary
->fb
->width
= ((val
>> 16) & 0xfff) + 1;
7343 crtc
->base
.primary
->fb
->height
= ((val
>> 0) & 0xfff) + 1;
7345 val
= I915_READ(DSPSTRIDE(pipe
));
7346 crtc
->base
.primary
->fb
->pitches
[0] = val
& 0xffffffc0;
7348 aligned_height
= intel_align_height(dev
, crtc
->base
.primary
->fb
->height
,
7349 plane_config
->tiled
);
7351 plane_config
->size
= PAGE_ALIGN(crtc
->base
.primary
->fb
->pitches
[0] *
7354 DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7355 pipe
, plane
, crtc
->base
.primary
->fb
->width
,
7356 crtc
->base
.primary
->fb
->height
,
7357 crtc
->base
.primary
->fb
->bits_per_pixel
, base
,
7358 crtc
->base
.primary
->fb
->pitches
[0],
7359 plane_config
->size
);
7362 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
7363 struct intel_crtc_config
*pipe_config
)
7365 struct drm_device
*dev
= crtc
->base
.dev
;
7366 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7369 if (!intel_display_power_enabled(dev_priv
,
7370 POWER_DOMAIN_PIPE(crtc
->pipe
)))
7373 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7374 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
7376 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
7377 if (!(tmp
& PIPECONF_ENABLE
))
7380 switch (tmp
& PIPECONF_BPC_MASK
) {
7382 pipe_config
->pipe_bpp
= 18;
7385 pipe_config
->pipe_bpp
= 24;
7387 case PIPECONF_10BPC
:
7388 pipe_config
->pipe_bpp
= 30;
7390 case PIPECONF_12BPC
:
7391 pipe_config
->pipe_bpp
= 36;
7397 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
7398 pipe_config
->limited_color_range
= true;
7400 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
7401 struct intel_shared_dpll
*pll
;
7403 pipe_config
->has_pch_encoder
= true;
7405 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
7406 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
7407 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
7409 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
7411 if (HAS_PCH_IBX(dev_priv
->dev
)) {
7412 pipe_config
->shared_dpll
=
7413 (enum intel_dpll_id
) crtc
->pipe
;
7415 tmp
= I915_READ(PCH_DPLL_SEL
);
7416 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
7417 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_B
;
7419 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_A
;
7422 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
7424 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
7425 &pipe_config
->dpll_hw_state
));
7427 tmp
= pipe_config
->dpll_hw_state
.dpll
;
7428 pipe_config
->pixel_multiplier
=
7429 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
7430 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
7432 ironlake_pch_clock_get(crtc
, pipe_config
);
7434 pipe_config
->pixel_multiplier
= 1;
7437 intel_get_pipe_timings(crtc
, pipe_config
);
7439 ironlake_get_pfit_config(crtc
, pipe_config
);
7444 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
7446 struct drm_device
*dev
= dev_priv
->dev
;
7447 struct intel_crtc
*crtc
;
7449 for_each_intel_crtc(dev
, crtc
)
7450 WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
7451 pipe_name(crtc
->pipe
));
7453 WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
7454 WARN(I915_READ(SPLL_CTL
) & SPLL_PLL_ENABLE
, "SPLL enabled\n");
7455 WARN(I915_READ(WRPLL_CTL1
) & WRPLL_PLL_ENABLE
, "WRPLL1 enabled\n");
7456 WARN(I915_READ(WRPLL_CTL2
) & WRPLL_PLL_ENABLE
, "WRPLL2 enabled\n");
7457 WARN(I915_READ(PCH_PP_STATUS
) & PP_ON
, "Panel power on\n");
7458 WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
7459 "CPU PWM1 enabled\n");
7460 if (IS_HASWELL(dev
))
7461 WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
7462 "CPU PWM2 enabled\n");
7463 WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
7464 "PCH PWM1 enabled\n");
7465 WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
7466 "Utility pin enabled\n");
7467 WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
7470 * In theory we can still leave IRQs enabled, as long as only the HPD
7471 * interrupts remain enabled. We used to check for that, but since it's
7472 * gen-specific and since we only disable LCPLL after we fully disable
7473 * the interrupts, the check below should be enough.
7475 WARN(intel_irqs_enabled(dev_priv
), "IRQs enabled\n");
7478 static uint32_t hsw_read_dcomp(struct drm_i915_private
*dev_priv
)
7480 struct drm_device
*dev
= dev_priv
->dev
;
7482 if (IS_HASWELL(dev
))
7483 return I915_READ(D_COMP_HSW
);
7485 return I915_READ(D_COMP_BDW
);
7488 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
7490 struct drm_device
*dev
= dev_priv
->dev
;
7492 if (IS_HASWELL(dev
)) {
7493 mutex_lock(&dev_priv
->rps
.hw_lock
);
7494 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
7496 DRM_ERROR("Failed to write to D_COMP\n");
7497 mutex_unlock(&dev_priv
->rps
.hw_lock
);
7499 I915_WRITE(D_COMP_BDW
, val
);
7500 POSTING_READ(D_COMP_BDW
);
7505 * This function implements pieces of two sequences from BSpec:
7506 * - Sequence for display software to disable LCPLL
7507 * - Sequence for display software to allow package C8+
7508 * The steps implemented here are just the steps that actually touch the LCPLL
7509 * register. Callers should take care of disabling all the display engine
7510 * functions, doing the mode unset, fixing interrupts, etc.
7512 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
7513 bool switch_to_fclk
, bool allow_power_down
)
7517 assert_can_disable_lcpll(dev_priv
);
7519 val
= I915_READ(LCPLL_CTL
);
7521 if (switch_to_fclk
) {
7522 val
|= LCPLL_CD_SOURCE_FCLK
;
7523 I915_WRITE(LCPLL_CTL
, val
);
7525 if (wait_for_atomic_us(I915_READ(LCPLL_CTL
) &
7526 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
7527 DRM_ERROR("Switching to FCLK failed\n");
7529 val
= I915_READ(LCPLL_CTL
);
7532 val
|= LCPLL_PLL_DISABLE
;
7533 I915_WRITE(LCPLL_CTL
, val
);
7534 POSTING_READ(LCPLL_CTL
);
7536 if (wait_for((I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
) == 0, 1))
7537 DRM_ERROR("LCPLL still locked\n");
7539 val
= hsw_read_dcomp(dev_priv
);
7540 val
|= D_COMP_COMP_DISABLE
;
7541 hsw_write_dcomp(dev_priv
, val
);
7544 if (wait_for((hsw_read_dcomp(dev_priv
) & D_COMP_RCOMP_IN_PROGRESS
) == 0,
7546 DRM_ERROR("D_COMP RCOMP still in progress\n");
7548 if (allow_power_down
) {
7549 val
= I915_READ(LCPLL_CTL
);
7550 val
|= LCPLL_POWER_DOWN_ALLOW
;
7551 I915_WRITE(LCPLL_CTL
, val
);
7552 POSTING_READ(LCPLL_CTL
);
7557 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
7560 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
7563 unsigned long irqflags
;
7565 val
= I915_READ(LCPLL_CTL
);
7567 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
7568 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
7572 * Make sure we're not on PC8 state before disabling PC8, otherwise
7573 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
7575 * The other problem is that hsw_restore_lcpll() is called as part of
7576 * the runtime PM resume sequence, so we can't just call
7577 * gen6_gt_force_wake_get() because that function calls
7578 * intel_runtime_pm_get(), and we can't change the runtime PM refcount
7579 * while we are on the resume sequence. So to solve this problem we have
7580 * to call special forcewake code that doesn't touch runtime PM and
7581 * doesn't enable the forcewake delayed work.
7583 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
7584 if (dev_priv
->uncore
.forcewake_count
++ == 0)
7585 dev_priv
->uncore
.funcs
.force_wake_get(dev_priv
, FORCEWAKE_ALL
);
7586 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
7588 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
7589 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
7590 I915_WRITE(LCPLL_CTL
, val
);
7591 POSTING_READ(LCPLL_CTL
);
7594 val
= hsw_read_dcomp(dev_priv
);
7595 val
|= D_COMP_COMP_FORCE
;
7596 val
&= ~D_COMP_COMP_DISABLE
;
7597 hsw_write_dcomp(dev_priv
, val
);
7599 val
= I915_READ(LCPLL_CTL
);
7600 val
&= ~LCPLL_PLL_DISABLE
;
7601 I915_WRITE(LCPLL_CTL
, val
);
7603 if (wait_for(I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
, 5))
7604 DRM_ERROR("LCPLL not locked yet\n");
7606 if (val
& LCPLL_CD_SOURCE_FCLK
) {
7607 val
= I915_READ(LCPLL_CTL
);
7608 val
&= ~LCPLL_CD_SOURCE_FCLK
;
7609 I915_WRITE(LCPLL_CTL
, val
);
7611 if (wait_for_atomic_us((I915_READ(LCPLL_CTL
) &
7612 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
7613 DRM_ERROR("Switching back to LCPLL failed\n");
7616 /* See the big comment above. */
7617 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
7618 if (--dev_priv
->uncore
.forcewake_count
== 0)
7619 dev_priv
->uncore
.funcs
.force_wake_put(dev_priv
, FORCEWAKE_ALL
);
7620 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
7624 * Package states C8 and deeper are really deep PC states that can only be
7625 * reached when all the devices on the system allow it, so even if the graphics
7626 * device allows PC8+, it doesn't mean the system will actually get to these
7627 * states. Our driver only allows PC8+ when going into runtime PM.
7629 * The requirements for PC8+ are that all the outputs are disabled, the power
7630 * well is disabled and most interrupts are disabled, and these are also
7631 * requirements for runtime PM. When these conditions are met, we manually do
7632 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
7633 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
7636 * When we really reach PC8 or deeper states (not just when we allow it) we lose
7637 * the state of some registers, so when we come back from PC8+ we need to
7638 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
7639 * need to take care of the registers kept by RC6. Notice that this happens even
7640 * if we don't put the device in PCI D3 state (which is what currently happens
7641 * because of the runtime PM support).
7643 * For more, read "Display Sequences for Package C8" on the hardware
7646 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
7648 struct drm_device
*dev
= dev_priv
->dev
;
7651 DRM_DEBUG_KMS("Enabling package C8+\n");
7653 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
7654 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
7655 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
7656 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
7659 lpt_disable_clkout_dp(dev
);
7660 hsw_disable_lcpll(dev_priv
, true, true);
7663 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
7665 struct drm_device
*dev
= dev_priv
->dev
;
7668 DRM_DEBUG_KMS("Disabling package C8+\n");
7670 hsw_restore_lcpll(dev_priv
);
7671 lpt_init_pch_refclk(dev
);
7673 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
7674 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
7675 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
7676 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
7679 intel_prepare_ddi(dev
);
7682 static void snb_modeset_global_resources(struct drm_device
*dev
)
7684 modeset_update_crtc_power_domains(dev
);
7687 static void haswell_modeset_global_resources(struct drm_device
*dev
)
7689 modeset_update_crtc_power_domains(dev
);
7692 static int haswell_crtc_mode_set(struct drm_crtc
*crtc
,
7694 struct drm_framebuffer
*fb
)
7696 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7698 if (!intel_ddi_pll_select(intel_crtc
))
7701 intel_crtc
->lowfreq_avail
= false;
7706 static void haswell_get_ddi_pll(struct drm_i915_private
*dev_priv
,
7708 struct intel_crtc_config
*pipe_config
)
7710 pipe_config
->ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
7712 switch (pipe_config
->ddi_pll_sel
) {
7713 case PORT_CLK_SEL_WRPLL1
:
7714 pipe_config
->shared_dpll
= DPLL_ID_WRPLL1
;
7716 case PORT_CLK_SEL_WRPLL2
:
7717 pipe_config
->shared_dpll
= DPLL_ID_WRPLL2
;
7722 static void haswell_get_ddi_port_state(struct intel_crtc
*crtc
,
7723 struct intel_crtc_config
*pipe_config
)
7725 struct drm_device
*dev
= crtc
->base
.dev
;
7726 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7727 struct intel_shared_dpll
*pll
;
7731 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
7733 port
= (tmp
& TRANS_DDI_PORT_MASK
) >> TRANS_DDI_PORT_SHIFT
;
7735 haswell_get_ddi_pll(dev_priv
, port
, pipe_config
);
7737 if (pipe_config
->shared_dpll
>= 0) {
7738 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
7740 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
7741 &pipe_config
->dpll_hw_state
));
7745 * Haswell has only FDI/PCH transcoder A. It is which is connected to
7746 * DDI E. So just check whether this pipe is wired to DDI E and whether
7747 * the PCH transcoder is on.
7749 if ((port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
7750 pipe_config
->has_pch_encoder
= true;
7752 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
7753 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
7754 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
7756 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
7760 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
7761 struct intel_crtc_config
*pipe_config
)
7763 struct drm_device
*dev
= crtc
->base
.dev
;
7764 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7765 enum intel_display_power_domain pfit_domain
;
7768 if (!intel_display_power_enabled(dev_priv
,
7769 POWER_DOMAIN_PIPE(crtc
->pipe
)))
7772 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7773 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
7775 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
7776 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
7777 enum pipe trans_edp_pipe
;
7778 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
7780 WARN(1, "unknown pipe linked to edp transcoder\n");
7781 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
7782 case TRANS_DDI_EDP_INPUT_A_ON
:
7783 trans_edp_pipe
= PIPE_A
;
7785 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
7786 trans_edp_pipe
= PIPE_B
;
7788 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
7789 trans_edp_pipe
= PIPE_C
;
7793 if (trans_edp_pipe
== crtc
->pipe
)
7794 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
7797 if (!intel_display_power_enabled(dev_priv
,
7798 POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
)))
7801 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
7802 if (!(tmp
& PIPECONF_ENABLE
))
7805 haswell_get_ddi_port_state(crtc
, pipe_config
);
7807 intel_get_pipe_timings(crtc
, pipe_config
);
7809 pfit_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
7810 if (intel_display_power_enabled(dev_priv
, pfit_domain
))
7811 ironlake_get_pfit_config(crtc
, pipe_config
);
7813 if (IS_HASWELL(dev
))
7814 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
7815 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
7817 pipe_config
->pixel_multiplier
= 1;
7825 } hdmi_audio_clock
[] = {
7826 { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175
},
7827 { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200
}, /* default per bspec */
7828 { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000
},
7829 { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027
},
7830 { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000
},
7831 { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054
},
7832 { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176
},
7833 { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250
},
7834 { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352
},
7835 { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500
},
7838 /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */
7839 static u32
audio_config_hdmi_pixel_clock(struct drm_display_mode
*mode
)
7843 for (i
= 0; i
< ARRAY_SIZE(hdmi_audio_clock
); i
++) {
7844 if (mode
->clock
== hdmi_audio_clock
[i
].clock
)
7848 if (i
== ARRAY_SIZE(hdmi_audio_clock
)) {
7849 DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode
->clock
);
7853 DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n",
7854 hdmi_audio_clock
[i
].clock
,
7855 hdmi_audio_clock
[i
].config
);
7857 return hdmi_audio_clock
[i
].config
;
7860 static bool intel_eld_uptodate(struct drm_connector
*connector
,
7861 int reg_eldv
, uint32_t bits_eldv
,
7862 int reg_elda
, uint32_t bits_elda
,
7865 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7866 uint8_t *eld
= connector
->eld
;
7869 i
= I915_READ(reg_eldv
);
7878 i
= I915_READ(reg_elda
);
7880 I915_WRITE(reg_elda
, i
);
7882 for (i
= 0; i
< eld
[2]; i
++)
7883 if (I915_READ(reg_edid
) != *((uint32_t *)eld
+ i
))
7889 static void g4x_write_eld(struct drm_connector
*connector
,
7890 struct drm_crtc
*crtc
,
7891 struct drm_display_mode
*mode
)
7893 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7894 uint8_t *eld
= connector
->eld
;
7899 i
= I915_READ(G4X_AUD_VID_DID
);
7901 if (i
== INTEL_AUDIO_DEVBLC
|| i
== INTEL_AUDIO_DEVCL
)
7902 eldv
= G4X_ELDV_DEVCL_DEVBLC
;
7904 eldv
= G4X_ELDV_DEVCTG
;
7906 if (intel_eld_uptodate(connector
,
7907 G4X_AUD_CNTL_ST
, eldv
,
7908 G4X_AUD_CNTL_ST
, G4X_ELD_ADDR
,
7909 G4X_HDMIW_HDMIEDID
))
7912 i
= I915_READ(G4X_AUD_CNTL_ST
);
7913 i
&= ~(eldv
| G4X_ELD_ADDR
);
7914 len
= (i
>> 9) & 0x1f; /* ELD buffer size */
7915 I915_WRITE(G4X_AUD_CNTL_ST
, i
);
7920 len
= min_t(uint8_t, eld
[2], len
);
7921 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
7922 for (i
= 0; i
< len
; i
++)
7923 I915_WRITE(G4X_HDMIW_HDMIEDID
, *((uint32_t *)eld
+ i
));
7925 i
= I915_READ(G4X_AUD_CNTL_ST
);
7927 I915_WRITE(G4X_AUD_CNTL_ST
, i
);
7930 static void haswell_write_eld(struct drm_connector
*connector
,
7931 struct drm_crtc
*crtc
,
7932 struct drm_display_mode
*mode
)
7934 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7935 uint8_t *eld
= connector
->eld
;
7939 int pipe
= to_intel_crtc(crtc
)->pipe
;
7942 int hdmiw_hdmiedid
= HSW_AUD_EDID_DATA(pipe
);
7943 int aud_cntl_st
= HSW_AUD_DIP_ELD_CTRL(pipe
);
7944 int aud_config
= HSW_AUD_CFG(pipe
);
7945 int aud_cntrl_st2
= HSW_AUD_PIN_ELD_CP_VLD
;
7947 /* Audio output enable */
7948 DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
7949 tmp
= I915_READ(aud_cntrl_st2
);
7950 tmp
|= (AUDIO_OUTPUT_ENABLE_A
<< (pipe
* 4));
7951 I915_WRITE(aud_cntrl_st2
, tmp
);
7952 POSTING_READ(aud_cntrl_st2
);
7954 assert_pipe_disabled(dev_priv
, to_intel_crtc(crtc
)->pipe
);
7956 /* Set ELD valid state */
7957 tmp
= I915_READ(aud_cntrl_st2
);
7958 DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp
);
7959 tmp
|= (AUDIO_ELD_VALID_A
<< (pipe
* 4));
7960 I915_WRITE(aud_cntrl_st2
, tmp
);
7961 tmp
= I915_READ(aud_cntrl_st2
);
7962 DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp
);
7964 /* Enable HDMI mode */
7965 tmp
= I915_READ(aud_config
);
7966 DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp
);
7967 /* clear N_programing_enable and N_value_index */
7968 tmp
&= ~(AUD_CONFIG_N_VALUE_INDEX
| AUD_CONFIG_N_PROG_ENABLE
);
7969 I915_WRITE(aud_config
, tmp
);
7971 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe
));
7973 eldv
= AUDIO_ELD_VALID_A
<< (pipe
* 4);
7975 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
7976 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
7977 eld
[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
7978 I915_WRITE(aud_config
, AUD_CONFIG_N_VALUE_INDEX
); /* 0x1 = DP */
7980 I915_WRITE(aud_config
, audio_config_hdmi_pixel_clock(mode
));
7983 if (intel_eld_uptodate(connector
,
7984 aud_cntrl_st2
, eldv
,
7985 aud_cntl_st
, IBX_ELD_ADDRESS
,
7989 i
= I915_READ(aud_cntrl_st2
);
7991 I915_WRITE(aud_cntrl_st2
, i
);
7996 i
= I915_READ(aud_cntl_st
);
7997 i
&= ~IBX_ELD_ADDRESS
;
7998 I915_WRITE(aud_cntl_st
, i
);
7999 i
= (i
>> 29) & DIP_PORT_SEL_MASK
; /* DIP_Port_Select, 0x1 = PortB */
8000 DRM_DEBUG_DRIVER("port num:%d\n", i
);
8002 len
= min_t(uint8_t, eld
[2], 21); /* 84 bytes of hw ELD buffer */
8003 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
8004 for (i
= 0; i
< len
; i
++)
8005 I915_WRITE(hdmiw_hdmiedid
, *((uint32_t *)eld
+ i
));
8007 i
= I915_READ(aud_cntrl_st2
);
8009 I915_WRITE(aud_cntrl_st2
, i
);
8013 static void ironlake_write_eld(struct drm_connector
*connector
,
8014 struct drm_crtc
*crtc
,
8015 struct drm_display_mode
*mode
)
8017 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
8018 uint8_t *eld
= connector
->eld
;
8026 int pipe
= to_intel_crtc(crtc
)->pipe
;
8028 if (HAS_PCH_IBX(connector
->dev
)) {
8029 hdmiw_hdmiedid
= IBX_HDMIW_HDMIEDID(pipe
);
8030 aud_config
= IBX_AUD_CFG(pipe
);
8031 aud_cntl_st
= IBX_AUD_CNTL_ST(pipe
);
8032 aud_cntrl_st2
= IBX_AUD_CNTL_ST2
;
8033 } else if (IS_VALLEYVIEW(connector
->dev
)) {
8034 hdmiw_hdmiedid
= VLV_HDMIW_HDMIEDID(pipe
);
8035 aud_config
= VLV_AUD_CFG(pipe
);
8036 aud_cntl_st
= VLV_AUD_CNTL_ST(pipe
);
8037 aud_cntrl_st2
= VLV_AUD_CNTL_ST2
;
8039 hdmiw_hdmiedid
= CPT_HDMIW_HDMIEDID(pipe
);
8040 aud_config
= CPT_AUD_CFG(pipe
);
8041 aud_cntl_st
= CPT_AUD_CNTL_ST(pipe
);
8042 aud_cntrl_st2
= CPT_AUD_CNTRL_ST2
;
8045 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe
));
8047 if (IS_VALLEYVIEW(connector
->dev
)) {
8048 struct intel_encoder
*intel_encoder
;
8049 struct intel_digital_port
*intel_dig_port
;
8051 intel_encoder
= intel_attached_encoder(connector
);
8052 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
8053 i
= intel_dig_port
->port
;
8055 i
= I915_READ(aud_cntl_st
);
8056 i
= (i
>> 29) & DIP_PORT_SEL_MASK
;
8057 /* DIP_Port_Select, 0x1 = PortB */
8061 DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
8062 /* operate blindly on all ports */
8063 eldv
= IBX_ELD_VALIDB
;
8064 eldv
|= IBX_ELD_VALIDB
<< 4;
8065 eldv
|= IBX_ELD_VALIDB
<< 8;
8067 DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i
));
8068 eldv
= IBX_ELD_VALIDB
<< ((i
- 1) * 4);
8071 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
8072 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
8073 eld
[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
8074 I915_WRITE(aud_config
, AUD_CONFIG_N_VALUE_INDEX
); /* 0x1 = DP */
8076 I915_WRITE(aud_config
, audio_config_hdmi_pixel_clock(mode
));
8079 if (intel_eld_uptodate(connector
,
8080 aud_cntrl_st2
, eldv
,
8081 aud_cntl_st
, IBX_ELD_ADDRESS
,
8085 i
= I915_READ(aud_cntrl_st2
);
8087 I915_WRITE(aud_cntrl_st2
, i
);
8092 i
= I915_READ(aud_cntl_st
);
8093 i
&= ~IBX_ELD_ADDRESS
;
8094 I915_WRITE(aud_cntl_st
, i
);
8096 len
= min_t(uint8_t, eld
[2], 21); /* 84 bytes of hw ELD buffer */
8097 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
8098 for (i
= 0; i
< len
; i
++)
8099 I915_WRITE(hdmiw_hdmiedid
, *((uint32_t *)eld
+ i
));
8101 i
= I915_READ(aud_cntrl_st2
);
8103 I915_WRITE(aud_cntrl_st2
, i
);
8106 void intel_write_eld(struct drm_encoder
*encoder
,
8107 struct drm_display_mode
*mode
)
8109 struct drm_crtc
*crtc
= encoder
->crtc
;
8110 struct drm_connector
*connector
;
8111 struct drm_device
*dev
= encoder
->dev
;
8112 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8114 connector
= drm_select_eld(encoder
, mode
);
8118 DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
8121 connector
->encoder
->base
.id
,
8122 connector
->encoder
->name
);
8124 connector
->eld
[6] = drm_av_sync_delay(connector
, mode
) / 2;
8126 if (dev_priv
->display
.write_eld
)
8127 dev_priv
->display
.write_eld(connector
, crtc
, mode
);
8130 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
)
8132 struct drm_device
*dev
= crtc
->dev
;
8133 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8134 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8135 uint32_t cntl
= 0, size
= 0;
8138 unsigned int width
= intel_crtc
->cursor_width
;
8139 unsigned int height
= intel_crtc
->cursor_height
;
8140 unsigned int stride
= roundup_pow_of_two(width
) * 4;
8144 WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
8155 cntl
|= CURSOR_ENABLE
|
8156 CURSOR_GAMMA_ENABLE
|
8157 CURSOR_FORMAT_ARGB
|
8158 CURSOR_STRIDE(stride
);
8160 size
= (height
<< 12) | width
;
8163 if (intel_crtc
->cursor_cntl
!= 0 &&
8164 (intel_crtc
->cursor_base
!= base
||
8165 intel_crtc
->cursor_size
!= size
||
8166 intel_crtc
->cursor_cntl
!= cntl
)) {
8167 /* On these chipsets we can only modify the base/size/stride
8168 * whilst the cursor is disabled.
8170 I915_WRITE(_CURACNTR
, 0);
8171 POSTING_READ(_CURACNTR
);
8172 intel_crtc
->cursor_cntl
= 0;
8175 if (intel_crtc
->cursor_base
!= base
)
8176 I915_WRITE(_CURABASE
, base
);
8178 if (intel_crtc
->cursor_size
!= size
) {
8179 I915_WRITE(CURSIZE
, size
);
8180 intel_crtc
->cursor_size
= size
;
8183 if (intel_crtc
->cursor_cntl
!= cntl
) {
8184 I915_WRITE(_CURACNTR
, cntl
);
8185 POSTING_READ(_CURACNTR
);
8186 intel_crtc
->cursor_cntl
= cntl
;
8190 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
)
8192 struct drm_device
*dev
= crtc
->dev
;
8193 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8194 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8195 int pipe
= intel_crtc
->pipe
;
8200 cntl
= MCURSOR_GAMMA_ENABLE
;
8201 switch (intel_crtc
->cursor_width
) {
8203 cntl
|= CURSOR_MODE_64_ARGB_AX
;
8206 cntl
|= CURSOR_MODE_128_ARGB_AX
;
8209 cntl
|= CURSOR_MODE_256_ARGB_AX
;
8215 cntl
|= pipe
<< 28; /* Connect to correct pipe */
8217 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
8218 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
8220 if (intel_crtc
->cursor_cntl
!= cntl
) {
8221 I915_WRITE(CURCNTR(pipe
), cntl
);
8222 POSTING_READ(CURCNTR(pipe
));
8223 intel_crtc
->cursor_cntl
= cntl
;
8226 /* and commit changes on next vblank */
8227 I915_WRITE(CURBASE(pipe
), base
);
8228 POSTING_READ(CURBASE(pipe
));
8231 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
8232 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
8235 struct drm_device
*dev
= crtc
->dev
;
8236 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8237 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8238 int pipe
= intel_crtc
->pipe
;
8239 int x
= crtc
->cursor_x
;
8240 int y
= crtc
->cursor_y
;
8241 u32 base
= 0, pos
= 0;
8244 base
= intel_crtc
->cursor_addr
;
8246 if (x
>= intel_crtc
->config
.pipe_src_w
)
8249 if (y
>= intel_crtc
->config
.pipe_src_h
)
8253 if (x
+ intel_crtc
->cursor_width
<= 0)
8256 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
8259 pos
|= x
<< CURSOR_X_SHIFT
;
8262 if (y
+ intel_crtc
->cursor_height
<= 0)
8265 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
8268 pos
|= y
<< CURSOR_Y_SHIFT
;
8270 if (base
== 0 && intel_crtc
->cursor_base
== 0)
8273 I915_WRITE(CURPOS(pipe
), pos
);
8275 if (IS_845G(dev
) || IS_I865G(dev
))
8276 i845_update_cursor(crtc
, base
);
8278 i9xx_update_cursor(crtc
, base
);
8279 intel_crtc
->cursor_base
= base
;
8282 static bool cursor_size_ok(struct drm_device
*dev
,
8283 uint32_t width
, uint32_t height
)
8285 if (width
== 0 || height
== 0)
8289 * 845g/865g are special in that they are only limited by
8290 * the width of their cursors, the height is arbitrary up to
8291 * the precision of the register. Everything else requires
8292 * square cursors, limited to a few power-of-two sizes.
8294 if (IS_845G(dev
) || IS_I865G(dev
)) {
8295 if ((width
& 63) != 0)
8298 if (width
> (IS_845G(dev
) ? 64 : 512))
8304 switch (width
| height
) {
8320 * intel_crtc_cursor_set_obj - Set cursor to specified GEM object
8322 * Note that the object's reference will be consumed if the update fails. If
8323 * the update succeeds, the reference of the old object (if any) will be
8326 static int intel_crtc_cursor_set_obj(struct drm_crtc
*crtc
,
8327 struct drm_i915_gem_object
*obj
,
8328 uint32_t width
, uint32_t height
)
8330 struct drm_device
*dev
= crtc
->dev
;
8331 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8332 enum pipe pipe
= intel_crtc
->pipe
;
8333 unsigned old_width
, stride
;
8337 /* if we want to turn off the cursor ignore width and height */
8339 DRM_DEBUG_KMS("cursor off\n");
8341 mutex_lock(&dev
->struct_mutex
);
8345 /* Check for which cursor types we support */
8346 if (!cursor_size_ok(dev
, width
, height
)) {
8347 DRM_DEBUG("Cursor dimension not supported\n");
8351 stride
= roundup_pow_of_two(width
) * 4;
8352 if (obj
->base
.size
< stride
* height
) {
8353 DRM_DEBUG_KMS("buffer is too small\n");
8358 /* we only need to pin inside GTT if cursor is non-phy */
8359 mutex_lock(&dev
->struct_mutex
);
8360 if (!INTEL_INFO(dev
)->cursor_needs_physical
) {
8363 if (obj
->tiling_mode
) {
8364 DRM_DEBUG_KMS("cursor cannot be tiled\n");
8369 /* Note that the w/a also requires 2 PTE of padding following
8370 * the bo. We currently fill all unused PTE with the shadow
8371 * page and so we should always have valid PTE following the
8372 * cursor preventing the VT-d warning.
8375 if (need_vtd_wa(dev
))
8376 alignment
= 64*1024;
8378 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, NULL
);
8380 DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n");
8384 ret
= i915_gem_object_put_fence(obj
);
8386 DRM_DEBUG_KMS("failed to release fence for cursor");
8390 addr
= i915_gem_obj_ggtt_offset(obj
);
8392 int align
= IS_I830(dev
) ? 16 * 1024 : 256;
8393 ret
= i915_gem_object_attach_phys(obj
, align
);
8395 DRM_DEBUG_KMS("failed to attach phys object\n");
8398 addr
= obj
->phys_handle
->busaddr
;
8402 if (intel_crtc
->cursor_bo
) {
8403 if (!INTEL_INFO(dev
)->cursor_needs_physical
)
8404 i915_gem_object_unpin_from_display_plane(intel_crtc
->cursor_bo
);
8407 i915_gem_track_fb(intel_crtc
->cursor_bo
, obj
,
8408 INTEL_FRONTBUFFER_CURSOR(pipe
));
8409 mutex_unlock(&dev
->struct_mutex
);
8411 old_width
= intel_crtc
->cursor_width
;
8413 intel_crtc
->cursor_addr
= addr
;
8414 intel_crtc
->cursor_bo
= obj
;
8415 intel_crtc
->cursor_width
= width
;
8416 intel_crtc
->cursor_height
= height
;
8418 if (intel_crtc
->active
) {
8419 if (old_width
!= width
)
8420 intel_update_watermarks(crtc
);
8421 intel_crtc_update_cursor(crtc
, intel_crtc
->cursor_bo
!= NULL
);
8424 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_CURSOR(pipe
));
8428 i915_gem_object_unpin_from_display_plane(obj
);
8430 mutex_unlock(&dev
->struct_mutex
);
8432 drm_gem_object_unreference_unlocked(&obj
->base
);
8436 static void intel_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
8437 u16
*blue
, uint32_t start
, uint32_t size
)
8439 int end
= (start
+ size
> 256) ? 256 : start
+ size
, i
;
8440 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8442 for (i
= start
; i
< end
; i
++) {
8443 intel_crtc
->lut_r
[i
] = red
[i
] >> 8;
8444 intel_crtc
->lut_g
[i
] = green
[i
] >> 8;
8445 intel_crtc
->lut_b
[i
] = blue
[i
] >> 8;
8448 intel_crtc_load_lut(crtc
);
8451 /* VESA 640x480x72Hz mode to set on the pipe */
8452 static struct drm_display_mode load_detect_mode
= {
8453 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
8454 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
8457 struct drm_framebuffer
*
8458 __intel_framebuffer_create(struct drm_device
*dev
,
8459 struct drm_mode_fb_cmd2
*mode_cmd
,
8460 struct drm_i915_gem_object
*obj
)
8462 struct intel_framebuffer
*intel_fb
;
8465 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8467 drm_gem_object_unreference_unlocked(&obj
->base
);
8468 return ERR_PTR(-ENOMEM
);
8471 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
8475 return &intel_fb
->base
;
8477 drm_gem_object_unreference_unlocked(&obj
->base
);
8480 return ERR_PTR(ret
);
8483 static struct drm_framebuffer
*
8484 intel_framebuffer_create(struct drm_device
*dev
,
8485 struct drm_mode_fb_cmd2
*mode_cmd
,
8486 struct drm_i915_gem_object
*obj
)
8488 struct drm_framebuffer
*fb
;
8491 ret
= i915_mutex_lock_interruptible(dev
);
8493 return ERR_PTR(ret
);
8494 fb
= __intel_framebuffer_create(dev
, mode_cmd
, obj
);
8495 mutex_unlock(&dev
->struct_mutex
);
8501 intel_framebuffer_pitch_for_width(int width
, int bpp
)
8503 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
8504 return ALIGN(pitch
, 64);
8508 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
8510 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
8511 return PAGE_ALIGN(pitch
* mode
->vdisplay
);
8514 static struct drm_framebuffer
*
8515 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
8516 struct drm_display_mode
*mode
,
8519 struct drm_i915_gem_object
*obj
;
8520 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
8522 obj
= i915_gem_alloc_object(dev
,
8523 intel_framebuffer_size_for_mode(mode
, bpp
));
8525 return ERR_PTR(-ENOMEM
);
8527 mode_cmd
.width
= mode
->hdisplay
;
8528 mode_cmd
.height
= mode
->vdisplay
;
8529 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
8531 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
8533 return intel_framebuffer_create(dev
, &mode_cmd
, obj
);
8536 static struct drm_framebuffer
*
8537 mode_fits_in_fbdev(struct drm_device
*dev
,
8538 struct drm_display_mode
*mode
)
8540 #ifdef CONFIG_DRM_I915_FBDEV
8541 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8542 struct drm_i915_gem_object
*obj
;
8543 struct drm_framebuffer
*fb
;
8545 if (!dev_priv
->fbdev
)
8548 if (!dev_priv
->fbdev
->fb
)
8551 obj
= dev_priv
->fbdev
->fb
->obj
;
8554 fb
= &dev_priv
->fbdev
->fb
->base
;
8555 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
8556 fb
->bits_per_pixel
))
8559 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
8568 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
8569 struct drm_display_mode
*mode
,
8570 struct intel_load_detect_pipe
*old
,
8571 struct drm_modeset_acquire_ctx
*ctx
)
8573 struct intel_crtc
*intel_crtc
;
8574 struct intel_encoder
*intel_encoder
=
8575 intel_attached_encoder(connector
);
8576 struct drm_crtc
*possible_crtc
;
8577 struct drm_encoder
*encoder
= &intel_encoder
->base
;
8578 struct drm_crtc
*crtc
= NULL
;
8579 struct drm_device
*dev
= encoder
->dev
;
8580 struct drm_framebuffer
*fb
;
8581 struct drm_mode_config
*config
= &dev
->mode_config
;
8584 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
8585 connector
->base
.id
, connector
->name
,
8586 encoder
->base
.id
, encoder
->name
);
8589 ret
= drm_modeset_lock(&config
->connection_mutex
, ctx
);
8594 * Algorithm gets a little messy:
8596 * - if the connector already has an assigned crtc, use it (but make
8597 * sure it's on first)
8599 * - try to find the first unused crtc that can drive this connector,
8600 * and use that if we find one
8603 /* See if we already have a CRTC for this connector */
8604 if (encoder
->crtc
) {
8605 crtc
= encoder
->crtc
;
8607 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
8611 old
->dpms_mode
= connector
->dpms
;
8612 old
->load_detect_temp
= false;
8614 /* Make sure the crtc and connector are running */
8615 if (connector
->dpms
!= DRM_MODE_DPMS_ON
)
8616 connector
->funcs
->dpms(connector
, DRM_MODE_DPMS_ON
);
8621 /* Find an unused one (if possible) */
8622 for_each_crtc(dev
, possible_crtc
) {
8624 if (!(encoder
->possible_crtcs
& (1 << i
)))
8626 if (possible_crtc
->enabled
)
8628 /* This can occur when applying the pipe A quirk on resume. */
8629 if (to_intel_crtc(possible_crtc
)->new_enabled
)
8632 crtc
= possible_crtc
;
8637 * If we didn't find an unused CRTC, don't use any.
8640 DRM_DEBUG_KMS("no pipe available for load-detect\n");
8644 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
8647 intel_encoder
->new_crtc
= to_intel_crtc(crtc
);
8648 to_intel_connector(connector
)->new_encoder
= intel_encoder
;
8650 intel_crtc
= to_intel_crtc(crtc
);
8651 intel_crtc
->new_enabled
= true;
8652 intel_crtc
->new_config
= &intel_crtc
->config
;
8653 old
->dpms_mode
= connector
->dpms
;
8654 old
->load_detect_temp
= true;
8655 old
->release_fb
= NULL
;
8658 mode
= &load_detect_mode
;
8660 /* We need a framebuffer large enough to accommodate all accesses
8661 * that the plane may generate whilst we perform load detection.
8662 * We can not rely on the fbcon either being present (we get called
8663 * during its initialisation to detect all boot displays, or it may
8664 * not even exist) or that it is large enough to satisfy the
8667 fb
= mode_fits_in_fbdev(dev
, mode
);
8669 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
8670 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
8671 old
->release_fb
= fb
;
8673 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
8675 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
8679 if (intel_set_mode(crtc
, mode
, 0, 0, fb
)) {
8680 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
8681 if (old
->release_fb
)
8682 old
->release_fb
->funcs
->destroy(old
->release_fb
);
8686 /* let the connector get through one full cycle before testing */
8687 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
8691 intel_crtc
->new_enabled
= crtc
->enabled
;
8692 if (intel_crtc
->new_enabled
)
8693 intel_crtc
->new_config
= &intel_crtc
->config
;
8695 intel_crtc
->new_config
= NULL
;
8697 if (ret
== -EDEADLK
) {
8698 drm_modeset_backoff(ctx
);
8705 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
8706 struct intel_load_detect_pipe
*old
)
8708 struct intel_encoder
*intel_encoder
=
8709 intel_attached_encoder(connector
);
8710 struct drm_encoder
*encoder
= &intel_encoder
->base
;
8711 struct drm_crtc
*crtc
= encoder
->crtc
;
8712 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8714 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
8715 connector
->base
.id
, connector
->name
,
8716 encoder
->base
.id
, encoder
->name
);
8718 if (old
->load_detect_temp
) {
8719 to_intel_connector(connector
)->new_encoder
= NULL
;
8720 intel_encoder
->new_crtc
= NULL
;
8721 intel_crtc
->new_enabled
= false;
8722 intel_crtc
->new_config
= NULL
;
8723 intel_set_mode(crtc
, NULL
, 0, 0, NULL
);
8725 if (old
->release_fb
) {
8726 drm_framebuffer_unregister_private(old
->release_fb
);
8727 drm_framebuffer_unreference(old
->release_fb
);
8733 /* Switch crtc and encoder back off if necessary */
8734 if (old
->dpms_mode
!= DRM_MODE_DPMS_ON
)
8735 connector
->funcs
->dpms(connector
, old
->dpms_mode
);
8738 static int i9xx_pll_refclk(struct drm_device
*dev
,
8739 const struct intel_crtc_config
*pipe_config
)
8741 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8742 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
8744 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
8745 return dev_priv
->vbt
.lvds_ssc_freq
;
8746 else if (HAS_PCH_SPLIT(dev
))
8748 else if (!IS_GEN2(dev
))
8754 /* Returns the clock of the currently programmed mode of the given pipe. */
8755 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
8756 struct intel_crtc_config
*pipe_config
)
8758 struct drm_device
*dev
= crtc
->base
.dev
;
8759 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8760 int pipe
= pipe_config
->cpu_transcoder
;
8761 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
8763 intel_clock_t clock
;
8764 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
8766 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
8767 fp
= pipe_config
->dpll_hw_state
.fp0
;
8769 fp
= pipe_config
->dpll_hw_state
.fp1
;
8771 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
8772 if (IS_PINEVIEW(dev
)) {
8773 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
8774 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
8776 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
8777 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
8780 if (!IS_GEN2(dev
)) {
8781 if (IS_PINEVIEW(dev
))
8782 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
8783 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
8785 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
8786 DPLL_FPA01_P1_POST_DIV_SHIFT
);
8788 switch (dpll
& DPLL_MODE_MASK
) {
8789 case DPLLB_MODE_DAC_SERIAL
:
8790 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
8793 case DPLLB_MODE_LVDS
:
8794 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
8798 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
8799 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
8803 if (IS_PINEVIEW(dev
))
8804 pineview_clock(refclk
, &clock
);
8806 i9xx_clock(refclk
, &clock
);
8808 u32 lvds
= IS_I830(dev
) ? 0 : I915_READ(LVDS
);
8809 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
8812 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
8813 DPLL_FPA01_P1_POST_DIV_SHIFT
);
8815 if (lvds
& LVDS_CLKB_POWER_UP
)
8820 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
8823 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
8824 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
8826 if (dpll
& PLL_P2_DIVIDE_BY_4
)
8832 i9xx_clock(refclk
, &clock
);
8836 * This value includes pixel_multiplier. We will use
8837 * port_clock to compute adjusted_mode.crtc_clock in the
8838 * encoder's get_config() function.
8840 pipe_config
->port_clock
= clock
.dot
;
8843 int intel_dotclock_calculate(int link_freq
,
8844 const struct intel_link_m_n
*m_n
)
8847 * The calculation for the data clock is:
8848 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
8849 * But we want to avoid losing precison if possible, so:
8850 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
8852 * and the link clock is simpler:
8853 * link_clock = (m * link_clock) / n
8859 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
8862 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
8863 struct intel_crtc_config
*pipe_config
)
8865 struct drm_device
*dev
= crtc
->base
.dev
;
8867 /* read out port_clock from the DPLL */
8868 i9xx_crtc_clock_get(crtc
, pipe_config
);
8871 * This value does not include pixel_multiplier.
8872 * We will check that port_clock and adjusted_mode.crtc_clock
8873 * agree once we know their relationship in the encoder's
8874 * get_config() function.
8876 pipe_config
->adjusted_mode
.crtc_clock
=
8877 intel_dotclock_calculate(intel_fdi_link_freq(dev
) * 10000,
8878 &pipe_config
->fdi_m_n
);
8881 /** Returns the currently programmed mode of the given pipe. */
8882 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
8883 struct drm_crtc
*crtc
)
8885 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8886 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8887 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
8888 struct drm_display_mode
*mode
;
8889 struct intel_crtc_config pipe_config
;
8890 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
8891 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
8892 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
8893 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
8894 enum pipe pipe
= intel_crtc
->pipe
;
8896 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
8901 * Construct a pipe_config sufficient for getting the clock info
8902 * back out of crtc_clock_get.
8904 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
8905 * to use a real value here instead.
8907 pipe_config
.cpu_transcoder
= (enum transcoder
) pipe
;
8908 pipe_config
.pixel_multiplier
= 1;
8909 pipe_config
.dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
8910 pipe_config
.dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
8911 pipe_config
.dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
8912 i9xx_crtc_clock_get(intel_crtc
, &pipe_config
);
8914 mode
->clock
= pipe_config
.port_clock
/ pipe_config
.pixel_multiplier
;
8915 mode
->hdisplay
= (htot
& 0xffff) + 1;
8916 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
8917 mode
->hsync_start
= (hsync
& 0xffff) + 1;
8918 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
8919 mode
->vdisplay
= (vtot
& 0xffff) + 1;
8920 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
8921 mode
->vsync_start
= (vsync
& 0xffff) + 1;
8922 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
8924 drm_mode_set_name(mode
);
8929 static void intel_increase_pllclock(struct drm_device
*dev
,
8932 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8933 int dpll_reg
= DPLL(pipe
);
8936 if (!HAS_GMCH_DISPLAY(dev
))
8939 if (!dev_priv
->lvds_downclock_avail
)
8942 dpll
= I915_READ(dpll_reg
);
8943 if (!HAS_PIPE_CXSR(dev
) && (dpll
& DISPLAY_RATE_SELECT_FPA1
)) {
8944 DRM_DEBUG_DRIVER("upclocking LVDS\n");
8946 assert_panel_unlocked(dev_priv
, pipe
);
8948 dpll
&= ~DISPLAY_RATE_SELECT_FPA1
;
8949 I915_WRITE(dpll_reg
, dpll
);
8950 intel_wait_for_vblank(dev
, pipe
);
8952 dpll
= I915_READ(dpll_reg
);
8953 if (dpll
& DISPLAY_RATE_SELECT_FPA1
)
8954 DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
8958 static void intel_decrease_pllclock(struct drm_crtc
*crtc
)
8960 struct drm_device
*dev
= crtc
->dev
;
8961 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8962 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8964 if (!HAS_GMCH_DISPLAY(dev
))
8967 if (!dev_priv
->lvds_downclock_avail
)
8971 * Since this is called by a timer, we should never get here in
8974 if (!HAS_PIPE_CXSR(dev
) && intel_crtc
->lowfreq_avail
) {
8975 int pipe
= intel_crtc
->pipe
;
8976 int dpll_reg
= DPLL(pipe
);
8979 DRM_DEBUG_DRIVER("downclocking LVDS\n");
8981 assert_panel_unlocked(dev_priv
, pipe
);
8983 dpll
= I915_READ(dpll_reg
);
8984 dpll
|= DISPLAY_RATE_SELECT_FPA1
;
8985 I915_WRITE(dpll_reg
, dpll
);
8986 intel_wait_for_vblank(dev
, pipe
);
8987 dpll
= I915_READ(dpll_reg
);
8988 if (!(dpll
& DISPLAY_RATE_SELECT_FPA1
))
8989 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
8994 void intel_mark_busy(struct drm_device
*dev
)
8996 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8998 if (dev_priv
->mm
.busy
)
9001 intel_runtime_pm_get(dev_priv
);
9002 i915_update_gfx_val(dev_priv
);
9003 dev_priv
->mm
.busy
= true;
9006 void intel_mark_idle(struct drm_device
*dev
)
9008 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9009 struct drm_crtc
*crtc
;
9011 if (!dev_priv
->mm
.busy
)
9014 dev_priv
->mm
.busy
= false;
9016 if (!i915
.powersave
)
9019 for_each_crtc(dev
, crtc
) {
9020 if (!crtc
->primary
->fb
)
9023 intel_decrease_pllclock(crtc
);
9026 if (INTEL_INFO(dev
)->gen
>= 6)
9027 gen6_rps_idle(dev
->dev_private
);
9030 intel_runtime_pm_put(dev_priv
);
9035 * intel_mark_fb_busy - mark given planes as busy
9037 * @frontbuffer_bits: bits for the affected planes
9038 * @ring: optional ring for asynchronous commands
9040 * This function gets called every time the screen contents change. It can be
9041 * used to keep e.g. the update rate at the nominal refresh rate with DRRS.
9043 static void intel_mark_fb_busy(struct drm_device
*dev
,
9044 unsigned frontbuffer_bits
,
9045 struct intel_engine_cs
*ring
)
9047 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9050 if (!i915
.powersave
)
9053 for_each_pipe(dev_priv
, pipe
) {
9054 if (!(frontbuffer_bits
& INTEL_FRONTBUFFER_ALL_MASK(pipe
)))
9057 intel_increase_pllclock(dev
, pipe
);
9058 if (ring
&& intel_fbc_enabled(dev
))
9059 ring
->fbc_dirty
= true;
9064 * intel_fb_obj_invalidate - invalidate frontbuffer object
9065 * @obj: GEM object to invalidate
9066 * @ring: set for asynchronous rendering
9068 * This function gets called every time rendering on the given object starts and
9069 * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
9070 * be invalidated. If @ring is non-NULL any subsequent invalidation will be delayed
9071 * until the rendering completes or a flip on this frontbuffer plane is
9074 void intel_fb_obj_invalidate(struct drm_i915_gem_object
*obj
,
9075 struct intel_engine_cs
*ring
)
9077 struct drm_device
*dev
= obj
->base
.dev
;
9078 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9080 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
9082 if (!obj
->frontbuffer_bits
)
9086 mutex_lock(&dev_priv
->fb_tracking
.lock
);
9087 dev_priv
->fb_tracking
.busy_bits
9088 |= obj
->frontbuffer_bits
;
9089 dev_priv
->fb_tracking
.flip_bits
9090 &= ~obj
->frontbuffer_bits
;
9091 mutex_unlock(&dev_priv
->fb_tracking
.lock
);
9094 intel_mark_fb_busy(dev
, obj
->frontbuffer_bits
, ring
);
9096 intel_edp_psr_invalidate(dev
, obj
->frontbuffer_bits
);
9100 * intel_frontbuffer_flush - flush frontbuffer
9102 * @frontbuffer_bits: frontbuffer plane tracking bits
9104 * This function gets called every time rendering on the given planes has
9105 * completed and frontbuffer caching can be started again. Flushes will get
9106 * delayed if they're blocked by some oustanding asynchronous rendering.
9108 * Can be called without any locks held.
9110 void intel_frontbuffer_flush(struct drm_device
*dev
,
9111 unsigned frontbuffer_bits
)
9113 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9115 /* Delay flushing when rings are still busy.*/
9116 mutex_lock(&dev_priv
->fb_tracking
.lock
);
9117 frontbuffer_bits
&= ~dev_priv
->fb_tracking
.busy_bits
;
9118 mutex_unlock(&dev_priv
->fb_tracking
.lock
);
9120 intel_mark_fb_busy(dev
, frontbuffer_bits
, NULL
);
9122 intel_edp_psr_flush(dev
, frontbuffer_bits
);
9125 * FIXME: Unconditional fbc flushing here is a rather gross hack and
9126 * needs to be reworked into a proper frontbuffer tracking scheme like
9129 if (IS_BROADWELL(dev
))
9130 gen8_fbc_sw_flush(dev
, FBC_REND_CACHE_CLEAN
);
9134 * intel_fb_obj_flush - flush frontbuffer object
9135 * @obj: GEM object to flush
9136 * @retire: set when retiring asynchronous rendering
9138 * This function gets called every time rendering on the given object has
9139 * completed and frontbuffer caching can be started again. If @retire is true
9140 * then any delayed flushes will be unblocked.
9142 void intel_fb_obj_flush(struct drm_i915_gem_object
*obj
,
9145 struct drm_device
*dev
= obj
->base
.dev
;
9146 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9147 unsigned frontbuffer_bits
;
9149 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
9151 if (!obj
->frontbuffer_bits
)
9154 frontbuffer_bits
= obj
->frontbuffer_bits
;
9157 mutex_lock(&dev_priv
->fb_tracking
.lock
);
9158 /* Filter out new bits since rendering started. */
9159 frontbuffer_bits
&= dev_priv
->fb_tracking
.busy_bits
;
9161 dev_priv
->fb_tracking
.busy_bits
&= ~frontbuffer_bits
;
9162 mutex_unlock(&dev_priv
->fb_tracking
.lock
);
9165 intel_frontbuffer_flush(dev
, frontbuffer_bits
);
9169 * intel_frontbuffer_flip_prepare - prepare asnychronous frontbuffer flip
9171 * @frontbuffer_bits: frontbuffer plane tracking bits
9173 * This function gets called after scheduling a flip on @obj. The actual
9174 * frontbuffer flushing will be delayed until completion is signalled with
9175 * intel_frontbuffer_flip_complete. If an invalidate happens in between this
9176 * flush will be cancelled.
9178 * Can be called without any locks held.
9180 void intel_frontbuffer_flip_prepare(struct drm_device
*dev
,
9181 unsigned frontbuffer_bits
)
9183 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9185 mutex_lock(&dev_priv
->fb_tracking
.lock
);
9186 dev_priv
->fb_tracking
.flip_bits
9187 |= frontbuffer_bits
;
9188 mutex_unlock(&dev_priv
->fb_tracking
.lock
);
9192 * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flush
9194 * @frontbuffer_bits: frontbuffer plane tracking bits
9196 * This function gets called after the flip has been latched and will complete
9197 * on the next vblank. It will execute the fush if it hasn't been cancalled yet.
9199 * Can be called without any locks held.
9201 void intel_frontbuffer_flip_complete(struct drm_device
*dev
,
9202 unsigned frontbuffer_bits
)
9204 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9206 mutex_lock(&dev_priv
->fb_tracking
.lock
);
9207 /* Mask any cancelled flips. */
9208 frontbuffer_bits
&= dev_priv
->fb_tracking
.flip_bits
;
9209 dev_priv
->fb_tracking
.flip_bits
&= ~frontbuffer_bits
;
9210 mutex_unlock(&dev_priv
->fb_tracking
.lock
);
9212 intel_frontbuffer_flush(dev
, frontbuffer_bits
);
9215 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
9217 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9218 struct drm_device
*dev
= crtc
->dev
;
9219 struct intel_unpin_work
*work
;
9220 unsigned long flags
;
9222 spin_lock_irqsave(&dev
->event_lock
, flags
);
9223 work
= intel_crtc
->unpin_work
;
9224 intel_crtc
->unpin_work
= NULL
;
9225 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9228 cancel_work_sync(&work
->work
);
9232 drm_crtc_cleanup(crtc
);
9237 static void intel_unpin_work_fn(struct work_struct
*__work
)
9239 struct intel_unpin_work
*work
=
9240 container_of(__work
, struct intel_unpin_work
, work
);
9241 struct drm_device
*dev
= work
->crtc
->dev
;
9242 enum pipe pipe
= to_intel_crtc(work
->crtc
)->pipe
;
9244 mutex_lock(&dev
->struct_mutex
);
9245 intel_unpin_fb_obj(work
->old_fb_obj
);
9246 drm_gem_object_unreference(&work
->pending_flip_obj
->base
);
9247 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
9249 intel_update_fbc(dev
);
9250 mutex_unlock(&dev
->struct_mutex
);
9252 intel_frontbuffer_flip_complete(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
9254 BUG_ON(atomic_read(&to_intel_crtc(work
->crtc
)->unpin_work_count
) == 0);
9255 atomic_dec(&to_intel_crtc(work
->crtc
)->unpin_work_count
);
9260 static void do_intel_finish_page_flip(struct drm_device
*dev
,
9261 struct drm_crtc
*crtc
)
9263 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9264 struct intel_unpin_work
*work
;
9265 unsigned long flags
;
9267 /* Ignore early vblank irqs */
9268 if (intel_crtc
== NULL
)
9271 spin_lock_irqsave(&dev
->event_lock
, flags
);
9272 work
= intel_crtc
->unpin_work
;
9274 /* Ensure we don't miss a work->pending update ... */
9277 if (work
== NULL
|| atomic_read(&work
->pending
) < INTEL_FLIP_COMPLETE
) {
9278 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9282 page_flip_completed(intel_crtc
);
9284 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9287 void intel_finish_page_flip(struct drm_device
*dev
, int pipe
)
9289 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9290 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
9292 do_intel_finish_page_flip(dev
, crtc
);
9295 void intel_finish_page_flip_plane(struct drm_device
*dev
, int plane
)
9297 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9298 struct drm_crtc
*crtc
= dev_priv
->plane_to_crtc_mapping
[plane
];
9300 do_intel_finish_page_flip(dev
, crtc
);
9303 /* Is 'a' after or equal to 'b'? */
9304 static bool g4x_flip_count_after_eq(u32 a
, u32 b
)
9306 return !((a
- b
) & 0x80000000);
9309 static bool page_flip_finished(struct intel_crtc
*crtc
)
9311 struct drm_device
*dev
= crtc
->base
.dev
;
9312 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9315 * The relevant registers doen't exist on pre-ctg.
9316 * As the flip done interrupt doesn't trigger for mmio
9317 * flips on gmch platforms, a flip count check isn't
9318 * really needed there. But since ctg has the registers,
9319 * include it in the check anyway.
9321 if (INTEL_INFO(dev
)->gen
< 5 && !IS_G4X(dev
))
9325 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
9326 * used the same base address. In that case the mmio flip might
9327 * have completed, but the CS hasn't even executed the flip yet.
9329 * A flip count check isn't enough as the CS might have updated
9330 * the base address just after start of vblank, but before we
9331 * managed to process the interrupt. This means we'd complete the
9334 * Combining both checks should get us a good enough result. It may
9335 * still happen that the CS flip has been executed, but has not
9336 * yet actually completed. But in case the base address is the same
9337 * anyway, we don't really care.
9339 return (I915_READ(DSPSURFLIVE(crtc
->plane
)) & ~0xfff) ==
9340 crtc
->unpin_work
->gtt_offset
&&
9341 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc
->pipe
)),
9342 crtc
->unpin_work
->flip_count
);
9345 void intel_prepare_page_flip(struct drm_device
*dev
, int plane
)
9347 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9348 struct intel_crtc
*intel_crtc
=
9349 to_intel_crtc(dev_priv
->plane_to_crtc_mapping
[plane
]);
9350 unsigned long flags
;
9352 /* NB: An MMIO update of the plane base pointer will also
9353 * generate a page-flip completion irq, i.e. every modeset
9354 * is also accompanied by a spurious intel_prepare_page_flip().
9356 spin_lock_irqsave(&dev
->event_lock
, flags
);
9357 if (intel_crtc
->unpin_work
&& page_flip_finished(intel_crtc
))
9358 atomic_inc_not_zero(&intel_crtc
->unpin_work
->pending
);
9359 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9362 static inline void intel_mark_page_flip_active(struct intel_crtc
*intel_crtc
)
9364 /* Ensure that the work item is consistent when activating it ... */
9366 atomic_set(&intel_crtc
->unpin_work
->pending
, INTEL_FLIP_PENDING
);
9367 /* and that it is marked active as soon as the irq could fire. */
9371 static int intel_gen2_queue_flip(struct drm_device
*dev
,
9372 struct drm_crtc
*crtc
,
9373 struct drm_framebuffer
*fb
,
9374 struct drm_i915_gem_object
*obj
,
9375 struct intel_engine_cs
*ring
,
9378 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9382 ret
= intel_ring_begin(ring
, 6);
9386 /* Can't queue multiple flips, so wait for the previous
9387 * one to finish before executing the next.
9389 if (intel_crtc
->plane
)
9390 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
9392 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
9393 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
9394 intel_ring_emit(ring
, MI_NOOP
);
9395 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9396 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9397 intel_ring_emit(ring
, fb
->pitches
[0]);
9398 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9399 intel_ring_emit(ring
, 0); /* aux display base address, unused */
9401 intel_mark_page_flip_active(intel_crtc
);
9402 __intel_ring_advance(ring
);
9406 static int intel_gen3_queue_flip(struct drm_device
*dev
,
9407 struct drm_crtc
*crtc
,
9408 struct drm_framebuffer
*fb
,
9409 struct drm_i915_gem_object
*obj
,
9410 struct intel_engine_cs
*ring
,
9413 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9417 ret
= intel_ring_begin(ring
, 6);
9421 if (intel_crtc
->plane
)
9422 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
9424 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
9425 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
9426 intel_ring_emit(ring
, MI_NOOP
);
9427 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
|
9428 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9429 intel_ring_emit(ring
, fb
->pitches
[0]);
9430 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9431 intel_ring_emit(ring
, MI_NOOP
);
9433 intel_mark_page_flip_active(intel_crtc
);
9434 __intel_ring_advance(ring
);
9438 static int intel_gen4_queue_flip(struct drm_device
*dev
,
9439 struct drm_crtc
*crtc
,
9440 struct drm_framebuffer
*fb
,
9441 struct drm_i915_gem_object
*obj
,
9442 struct intel_engine_cs
*ring
,
9445 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9446 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9447 uint32_t pf
, pipesrc
;
9450 ret
= intel_ring_begin(ring
, 4);
9454 /* i965+ uses the linear or tiled offsets from the
9455 * Display Registers (which do not change across a page-flip)
9456 * so we need only reprogram the base address.
9458 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9459 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9460 intel_ring_emit(ring
, fb
->pitches
[0]);
9461 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
|
9464 /* XXX Enabling the panel-fitter across page-flip is so far
9465 * untested on non-native modes, so ignore it for now.
9466 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
9469 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
9470 intel_ring_emit(ring
, pf
| pipesrc
);
9472 intel_mark_page_flip_active(intel_crtc
);
9473 __intel_ring_advance(ring
);
9477 static int intel_gen6_queue_flip(struct drm_device
*dev
,
9478 struct drm_crtc
*crtc
,
9479 struct drm_framebuffer
*fb
,
9480 struct drm_i915_gem_object
*obj
,
9481 struct intel_engine_cs
*ring
,
9484 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9485 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9486 uint32_t pf
, pipesrc
;
9489 ret
= intel_ring_begin(ring
, 4);
9493 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9494 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9495 intel_ring_emit(ring
, fb
->pitches
[0] | obj
->tiling_mode
);
9496 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9498 /* Contrary to the suggestions in the documentation,
9499 * "Enable Panel Fitter" does not seem to be required when page
9500 * flipping with a non-native mode, and worse causes a normal
9502 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
9505 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
9506 intel_ring_emit(ring
, pf
| pipesrc
);
9508 intel_mark_page_flip_active(intel_crtc
);
9509 __intel_ring_advance(ring
);
9513 static int intel_gen7_queue_flip(struct drm_device
*dev
,
9514 struct drm_crtc
*crtc
,
9515 struct drm_framebuffer
*fb
,
9516 struct drm_i915_gem_object
*obj
,
9517 struct intel_engine_cs
*ring
,
9520 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9521 uint32_t plane_bit
= 0;
9524 switch (intel_crtc
->plane
) {
9526 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
9529 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
9532 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
9535 WARN_ONCE(1, "unknown plane in flip command\n");
9540 if (ring
->id
== RCS
) {
9543 * On Gen 8, SRM is now taking an extra dword to accommodate
9544 * 48bits addresses, and we need a NOOP for the batch size to
9552 * BSpec MI_DISPLAY_FLIP for IVB:
9553 * "The full packet must be contained within the same cache line."
9555 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
9556 * cacheline, if we ever start emitting more commands before
9557 * the MI_DISPLAY_FLIP we may need to first emit everything else,
9558 * then do the cacheline alignment, and finally emit the
9561 ret
= intel_ring_cacheline_align(ring
);
9565 ret
= intel_ring_begin(ring
, len
);
9569 /* Unmask the flip-done completion message. Note that the bspec says that
9570 * we should do this for both the BCS and RCS, and that we must not unmask
9571 * more than one flip event at any time (or ensure that one flip message
9572 * can be sent by waiting for flip-done prior to queueing new flips).
9573 * Experimentation says that BCS works despite DERRMR masking all
9574 * flip-done completion events and that unmasking all planes at once
9575 * for the RCS also doesn't appear to drop events. Setting the DERRMR
9576 * to zero does lead to lockups within MI_DISPLAY_FLIP.
9578 if (ring
->id
== RCS
) {
9579 intel_ring_emit(ring
, MI_LOAD_REGISTER_IMM(1));
9580 intel_ring_emit(ring
, DERRMR
);
9581 intel_ring_emit(ring
, ~(DERRMR_PIPEA_PRI_FLIP_DONE
|
9582 DERRMR_PIPEB_PRI_FLIP_DONE
|
9583 DERRMR_PIPEC_PRI_FLIP_DONE
));
9585 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM_GEN8(1) |
9586 MI_SRM_LRM_GLOBAL_GTT
);
9588 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM(1) |
9589 MI_SRM_LRM_GLOBAL_GTT
);
9590 intel_ring_emit(ring
, DERRMR
);
9591 intel_ring_emit(ring
, ring
->scratch
.gtt_offset
+ 256);
9593 intel_ring_emit(ring
, 0);
9594 intel_ring_emit(ring
, MI_NOOP
);
9598 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
| plane_bit
);
9599 intel_ring_emit(ring
, (fb
->pitches
[0] | obj
->tiling_mode
));
9600 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9601 intel_ring_emit(ring
, (MI_NOOP
));
9603 intel_mark_page_flip_active(intel_crtc
);
9604 __intel_ring_advance(ring
);
9608 static bool use_mmio_flip(struct intel_engine_cs
*ring
,
9609 struct drm_i915_gem_object
*obj
)
9612 * This is not being used for older platforms, because
9613 * non-availability of flip done interrupt forces us to use
9614 * CS flips. Older platforms derive flip done using some clever
9615 * tricks involving the flip_pending status bits and vblank irqs.
9616 * So using MMIO flips there would disrupt this mechanism.
9622 if (INTEL_INFO(ring
->dev
)->gen
< 5)
9625 if (i915
.use_mmio_flip
< 0)
9627 else if (i915
.use_mmio_flip
> 0)
9629 else if (i915
.enable_execlists
)
9632 return ring
!= obj
->ring
;
9635 static void intel_do_mmio_flip(struct intel_crtc
*intel_crtc
)
9637 struct drm_device
*dev
= intel_crtc
->base
.dev
;
9638 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9639 struct intel_framebuffer
*intel_fb
=
9640 to_intel_framebuffer(intel_crtc
->base
.primary
->fb
);
9641 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
9645 intel_mark_page_flip_active(intel_crtc
);
9647 reg
= DSPCNTR(intel_crtc
->plane
);
9648 dspcntr
= I915_READ(reg
);
9650 if (INTEL_INFO(dev
)->gen
>= 4) {
9651 if (obj
->tiling_mode
!= I915_TILING_NONE
)
9652 dspcntr
|= DISPPLANE_TILED
;
9654 dspcntr
&= ~DISPPLANE_TILED
;
9656 I915_WRITE(reg
, dspcntr
);
9658 I915_WRITE(DSPSURF(intel_crtc
->plane
),
9659 intel_crtc
->unpin_work
->gtt_offset
);
9660 POSTING_READ(DSPSURF(intel_crtc
->plane
));
9663 static int intel_postpone_flip(struct drm_i915_gem_object
*obj
)
9665 struct intel_engine_cs
*ring
;
9668 lockdep_assert_held(&obj
->base
.dev
->struct_mutex
);
9670 if (!obj
->last_write_seqno
)
9675 if (i915_seqno_passed(ring
->get_seqno(ring
, true),
9676 obj
->last_write_seqno
))
9679 ret
= i915_gem_check_olr(ring
, obj
->last_write_seqno
);
9683 if (WARN_ON(!ring
->irq_get(ring
)))
9689 void intel_notify_mmio_flip(struct intel_engine_cs
*ring
)
9691 struct drm_i915_private
*dev_priv
= to_i915(ring
->dev
);
9692 struct intel_crtc
*intel_crtc
;
9693 unsigned long irq_flags
;
9696 seqno
= ring
->get_seqno(ring
, false);
9698 spin_lock_irqsave(&dev_priv
->mmio_flip_lock
, irq_flags
);
9699 for_each_intel_crtc(ring
->dev
, intel_crtc
) {
9700 struct intel_mmio_flip
*mmio_flip
;
9702 mmio_flip
= &intel_crtc
->mmio_flip
;
9703 if (mmio_flip
->seqno
== 0)
9706 if (ring
->id
!= mmio_flip
->ring_id
)
9709 if (i915_seqno_passed(seqno
, mmio_flip
->seqno
)) {
9710 intel_do_mmio_flip(intel_crtc
);
9711 mmio_flip
->seqno
= 0;
9712 ring
->irq_put(ring
);
9715 spin_unlock_irqrestore(&dev_priv
->mmio_flip_lock
, irq_flags
);
9718 static int intel_queue_mmio_flip(struct drm_device
*dev
,
9719 struct drm_crtc
*crtc
,
9720 struct drm_framebuffer
*fb
,
9721 struct drm_i915_gem_object
*obj
,
9722 struct intel_engine_cs
*ring
,
9725 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9726 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9727 unsigned long irq_flags
;
9730 if (WARN_ON(intel_crtc
->mmio_flip
.seqno
))
9733 ret
= intel_postpone_flip(obj
);
9737 intel_do_mmio_flip(intel_crtc
);
9741 spin_lock_irqsave(&dev_priv
->mmio_flip_lock
, irq_flags
);
9742 intel_crtc
->mmio_flip
.seqno
= obj
->last_write_seqno
;
9743 intel_crtc
->mmio_flip
.ring_id
= obj
->ring
->id
;
9744 spin_unlock_irqrestore(&dev_priv
->mmio_flip_lock
, irq_flags
);
9747 * Double check to catch cases where irq fired before
9748 * mmio flip data was ready
9750 intel_notify_mmio_flip(obj
->ring
);
9754 static int intel_default_queue_flip(struct drm_device
*dev
,
9755 struct drm_crtc
*crtc
,
9756 struct drm_framebuffer
*fb
,
9757 struct drm_i915_gem_object
*obj
,
9758 struct intel_engine_cs
*ring
,
9764 static bool __intel_pageflip_stall_check(struct drm_device
*dev
,
9765 struct drm_crtc
*crtc
)
9767 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9768 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9769 struct intel_unpin_work
*work
= intel_crtc
->unpin_work
;
9772 if (atomic_read(&work
->pending
) >= INTEL_FLIP_COMPLETE
)
9775 if (!work
->enable_stall_check
)
9778 if (work
->flip_ready_vblank
== 0) {
9779 if (work
->flip_queued_ring
&&
9780 !i915_seqno_passed(work
->flip_queued_ring
->get_seqno(work
->flip_queued_ring
, true),
9781 work
->flip_queued_seqno
))
9784 work
->flip_ready_vblank
= drm_vblank_count(dev
, intel_crtc
->pipe
);
9787 if (drm_vblank_count(dev
, intel_crtc
->pipe
) - work
->flip_ready_vblank
< 3)
9790 /* Potential stall - if we see that the flip has happened,
9791 * assume a missed interrupt. */
9792 if (INTEL_INFO(dev
)->gen
>= 4)
9793 addr
= I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc
->plane
)));
9795 addr
= I915_READ(DSPADDR(intel_crtc
->plane
));
9797 /* There is a potential issue here with a false positive after a flip
9798 * to the same address. We could address this by checking for a
9799 * non-incrementing frame counter.
9801 return addr
== work
->gtt_offset
;
9804 void intel_check_page_flip(struct drm_device
*dev
, int pipe
)
9806 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9807 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
9808 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9809 unsigned long flags
;
9814 spin_lock_irqsave(&dev
->event_lock
, flags
);
9815 if (intel_crtc
->unpin_work
&& __intel_pageflip_stall_check(dev
, crtc
)) {
9816 WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n",
9817 intel_crtc
->unpin_work
->flip_queued_vblank
, drm_vblank_count(dev
, pipe
));
9818 page_flip_completed(intel_crtc
);
9820 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9823 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
9824 struct drm_framebuffer
*fb
,
9825 struct drm_pending_vblank_event
*event
,
9826 uint32_t page_flip_flags
)
9828 struct drm_device
*dev
= crtc
->dev
;
9829 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9830 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
9831 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
9832 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9833 enum pipe pipe
= intel_crtc
->pipe
;
9834 struct intel_unpin_work
*work
;
9835 struct intel_engine_cs
*ring
;
9836 unsigned long flags
;
9839 //trigger software GT busyness calculation
9840 gen8_flip_interrupt(dev
);
9843 * drm_mode_page_flip_ioctl() should already catch this, but double
9844 * check to be safe. In the future we may enable pageflipping from
9845 * a disabled primary plane.
9847 if (WARN_ON(intel_fb_obj(old_fb
) == NULL
))
9850 /* Can't change pixel format via MI display flips. */
9851 if (fb
->pixel_format
!= crtc
->primary
->fb
->pixel_format
)
9855 * TILEOFF/LINOFF registers can't be changed via MI display flips.
9856 * Note that pitch changes could also affect these register.
9858 if (INTEL_INFO(dev
)->gen
> 3 &&
9859 (fb
->offsets
[0] != crtc
->primary
->fb
->offsets
[0] ||
9860 fb
->pitches
[0] != crtc
->primary
->fb
->pitches
[0]))
9863 if (i915_terminally_wedged(&dev_priv
->gpu_error
))
9866 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
9870 work
->event
= event
;
9872 work
->old_fb_obj
= intel_fb_obj(old_fb
);
9873 INIT_WORK(&work
->work
, intel_unpin_work_fn
);
9875 ret
= drm_crtc_vblank_get(crtc
);
9879 /* We borrow the event spin lock for protecting unpin_work */
9880 spin_lock_irqsave(&dev
->event_lock
, flags
);
9881 if (intel_crtc
->unpin_work
) {
9882 /* Before declaring the flip queue wedged, check if
9883 * the hardware completed the operation behind our backs.
9885 if (__intel_pageflip_stall_check(dev
, crtc
)) {
9886 DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
9887 page_flip_completed(intel_crtc
);
9889 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
9890 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9892 drm_crtc_vblank_put(crtc
);
9897 intel_crtc
->unpin_work
= work
;
9898 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9900 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
9901 flush_workqueue(dev_priv
->wq
);
9903 ret
= i915_mutex_lock_interruptible(dev
);
9907 /* Reference the objects for the scheduled work. */
9908 drm_gem_object_reference(&work
->old_fb_obj
->base
);
9909 drm_gem_object_reference(&obj
->base
);
9911 crtc
->primary
->fb
= fb
;
9913 work
->pending_flip_obj
= obj
;
9915 atomic_inc(&intel_crtc
->unpin_work_count
);
9916 intel_crtc
->reset_counter
= atomic_read(&dev_priv
->gpu_error
.reset_counter
);
9918 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
9919 work
->flip_count
= I915_READ(PIPE_FLIPCOUNT_GM45(pipe
)) + 1;
9921 if (IS_VALLEYVIEW(dev
)) {
9922 ring
= &dev_priv
->ring
[BCS
];
9923 if (obj
->tiling_mode
!= work
->old_fb_obj
->tiling_mode
)
9924 /* vlv: DISPLAY_FLIP fails to change tiling */
9926 } else if (IS_IVYBRIDGE(dev
)) {
9927 ring
= &dev_priv
->ring
[BCS
];
9928 } else if (INTEL_INFO(dev
)->gen
>= 7) {
9930 if (ring
== NULL
|| ring
->id
!= RCS
)
9931 ring
= &dev_priv
->ring
[BCS
];
9933 ring
= &dev_priv
->ring
[RCS
];
9936 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
9938 goto cleanup_pending
;
9941 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
;
9943 if (use_mmio_flip(ring
, obj
)) {
9944 ret
= intel_queue_mmio_flip(dev
, crtc
, fb
, obj
, ring
,
9949 work
->flip_queued_seqno
= obj
->last_write_seqno
;
9950 work
->flip_queued_ring
= obj
->ring
;
9952 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
, ring
,
9957 work
->flip_queued_seqno
= intel_ring_get_seqno(ring
);
9958 work
->flip_queued_ring
= ring
;
9961 work
->flip_queued_vblank
= drm_vblank_count(dev
, intel_crtc
->pipe
);
9962 work
->enable_stall_check
= true;
9964 i915_gem_track_fb(work
->old_fb_obj
, obj
,
9965 INTEL_FRONTBUFFER_PRIMARY(pipe
));
9967 intel_disable_fbc(dev
);
9968 intel_frontbuffer_flip_prepare(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
9969 mutex_unlock(&dev
->struct_mutex
);
9971 trace_i915_flip_request(intel_crtc
->plane
, obj
);
9976 intel_unpin_fb_obj(obj
);
9978 atomic_dec(&intel_crtc
->unpin_work_count
);
9979 crtc
->primary
->fb
= old_fb
;
9980 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
9981 drm_gem_object_unreference(&obj
->base
);
9982 mutex_unlock(&dev
->struct_mutex
);
9985 spin_lock_irqsave(&dev
->event_lock
, flags
);
9986 intel_crtc
->unpin_work
= NULL
;
9987 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9989 drm_crtc_vblank_put(crtc
);
9995 intel_crtc_wait_for_pending_flips(crtc
);
9996 ret
= intel_pipe_set_base(crtc
, crtc
->x
, crtc
->y
, fb
);
9997 if (ret
== 0 && event
)
9998 drm_send_vblank_event(dev
, pipe
, event
);
10003 static struct drm_crtc_helper_funcs intel_helper_funcs
= {
10004 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
10005 .load_lut
= intel_crtc_load_lut
,
10009 * intel_modeset_update_staged_output_state
10011 * Updates the staged output configuration state, e.g. after we've read out the
10012 * current hw state.
10014 static void intel_modeset_update_staged_output_state(struct drm_device
*dev
)
10016 struct intel_crtc
*crtc
;
10017 struct intel_encoder
*encoder
;
10018 struct intel_connector
*connector
;
10020 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10022 connector
->new_encoder
=
10023 to_intel_encoder(connector
->base
.encoder
);
10026 for_each_intel_encoder(dev
, encoder
) {
10027 encoder
->new_crtc
=
10028 to_intel_crtc(encoder
->base
.crtc
);
10031 for_each_intel_crtc(dev
, crtc
) {
10032 crtc
->new_enabled
= crtc
->base
.enabled
;
10034 if (crtc
->new_enabled
)
10035 crtc
->new_config
= &crtc
->config
;
10037 crtc
->new_config
= NULL
;
10042 * intel_modeset_commit_output_state
10044 * This function copies the stage display pipe configuration to the real one.
10046 static void intel_modeset_commit_output_state(struct drm_device
*dev
)
10048 struct intel_crtc
*crtc
;
10049 struct intel_encoder
*encoder
;
10050 struct intel_connector
*connector
;
10052 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10054 connector
->base
.encoder
= &connector
->new_encoder
->base
;
10057 for_each_intel_encoder(dev
, encoder
) {
10058 encoder
->base
.crtc
= &encoder
->new_crtc
->base
;
10061 for_each_intel_crtc(dev
, crtc
) {
10062 crtc
->base
.enabled
= crtc
->new_enabled
;
10067 connected_sink_compute_bpp(struct intel_connector
*connector
,
10068 struct intel_crtc_config
*pipe_config
)
10070 int bpp
= pipe_config
->pipe_bpp
;
10072 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
10073 connector
->base
.base
.id
,
10074 connector
->base
.name
);
10076 /* Don't use an invalid EDID bpc value */
10077 if (connector
->base
.display_info
.bpc
&&
10078 connector
->base
.display_info
.bpc
* 3 < bpp
) {
10079 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
10080 bpp
, connector
->base
.display_info
.bpc
*3);
10081 pipe_config
->pipe_bpp
= connector
->base
.display_info
.bpc
*3;
10084 /* Clamp bpp to 8 on screens without EDID 1.4 */
10085 if (connector
->base
.display_info
.bpc
== 0 && bpp
> 24) {
10086 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
10088 pipe_config
->pipe_bpp
= 24;
10093 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
10094 struct drm_framebuffer
*fb
,
10095 struct intel_crtc_config
*pipe_config
)
10097 struct drm_device
*dev
= crtc
->base
.dev
;
10098 struct intel_connector
*connector
;
10101 switch (fb
->pixel_format
) {
10102 case DRM_FORMAT_C8
:
10103 bpp
= 8*3; /* since we go through a colormap */
10105 case DRM_FORMAT_XRGB1555
:
10106 case DRM_FORMAT_ARGB1555
:
10107 /* checked in intel_framebuffer_init already */
10108 if (WARN_ON(INTEL_INFO(dev
)->gen
> 3))
10110 case DRM_FORMAT_RGB565
:
10111 bpp
= 6*3; /* min is 18bpp */
10113 case DRM_FORMAT_XBGR8888
:
10114 case DRM_FORMAT_ABGR8888
:
10115 /* checked in intel_framebuffer_init already */
10116 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
10118 case DRM_FORMAT_XRGB8888
:
10119 case DRM_FORMAT_ARGB8888
:
10122 case DRM_FORMAT_XRGB2101010
:
10123 case DRM_FORMAT_ARGB2101010
:
10124 case DRM_FORMAT_XBGR2101010
:
10125 case DRM_FORMAT_ABGR2101010
:
10126 /* checked in intel_framebuffer_init already */
10127 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
10131 /* TODO: gen4+ supports 16 bpc floating point, too. */
10133 DRM_DEBUG_KMS("unsupported depth\n");
10137 pipe_config
->pipe_bpp
= bpp
;
10139 /* Clamp display bpp to EDID value */
10140 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10142 if (!connector
->new_encoder
||
10143 connector
->new_encoder
->new_crtc
!= crtc
)
10146 connected_sink_compute_bpp(connector
, pipe_config
);
10152 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
10154 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
10155 "type: 0x%x flags: 0x%x\n",
10157 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
10158 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
10159 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
10160 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
10163 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
10164 struct intel_crtc_config
*pipe_config
,
10165 const char *context
)
10167 DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc
->base
.base
.id
,
10168 context
, pipe_name(crtc
->pipe
));
10170 DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config
->cpu_transcoder
));
10171 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
10172 pipe_config
->pipe_bpp
, pipe_config
->dither
);
10173 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10174 pipe_config
->has_pch_encoder
,
10175 pipe_config
->fdi_lanes
,
10176 pipe_config
->fdi_m_n
.gmch_m
, pipe_config
->fdi_m_n
.gmch_n
,
10177 pipe_config
->fdi_m_n
.link_m
, pipe_config
->fdi_m_n
.link_n
,
10178 pipe_config
->fdi_m_n
.tu
);
10179 DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10180 pipe_config
->has_dp_encoder
,
10181 pipe_config
->dp_m_n
.gmch_m
, pipe_config
->dp_m_n
.gmch_n
,
10182 pipe_config
->dp_m_n
.link_m
, pipe_config
->dp_m_n
.link_n
,
10183 pipe_config
->dp_m_n
.tu
);
10185 DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
10186 pipe_config
->has_dp_encoder
,
10187 pipe_config
->dp_m2_n2
.gmch_m
,
10188 pipe_config
->dp_m2_n2
.gmch_n
,
10189 pipe_config
->dp_m2_n2
.link_m
,
10190 pipe_config
->dp_m2_n2
.link_n
,
10191 pipe_config
->dp_m2_n2
.tu
);
10193 DRM_DEBUG_KMS("requested mode:\n");
10194 drm_mode_debug_printmodeline(&pipe_config
->requested_mode
);
10195 DRM_DEBUG_KMS("adjusted mode:\n");
10196 drm_mode_debug_printmodeline(&pipe_config
->adjusted_mode
);
10197 intel_dump_crtc_timings(&pipe_config
->adjusted_mode
);
10198 DRM_DEBUG_KMS("port clock: %d\n", pipe_config
->port_clock
);
10199 DRM_DEBUG_KMS("pipe src size: %dx%d\n",
10200 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
10201 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
10202 pipe_config
->gmch_pfit
.control
,
10203 pipe_config
->gmch_pfit
.pgm_ratios
,
10204 pipe_config
->gmch_pfit
.lvds_border_bits
);
10205 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
10206 pipe_config
->pch_pfit
.pos
,
10207 pipe_config
->pch_pfit
.size
,
10208 pipe_config
->pch_pfit
.enabled
? "enabled" : "disabled");
10209 DRM_DEBUG_KMS("ips: %i\n", pipe_config
->ips_enabled
);
10210 DRM_DEBUG_KMS("double wide: %i\n", pipe_config
->double_wide
);
10213 static bool encoders_cloneable(const struct intel_encoder
*a
,
10214 const struct intel_encoder
*b
)
10216 /* masks could be asymmetric, so check both ways */
10217 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
10218 b
->cloneable
& (1 << a
->type
));
10221 static bool check_single_encoder_cloning(struct intel_crtc
*crtc
,
10222 struct intel_encoder
*encoder
)
10224 struct drm_device
*dev
= crtc
->base
.dev
;
10225 struct intel_encoder
*source_encoder
;
10227 for_each_intel_encoder(dev
, source_encoder
) {
10228 if (source_encoder
->new_crtc
!= crtc
)
10231 if (!encoders_cloneable(encoder
, source_encoder
))
10238 static bool check_encoder_cloning(struct intel_crtc
*crtc
)
10240 struct drm_device
*dev
= crtc
->base
.dev
;
10241 struct intel_encoder
*encoder
;
10243 for_each_intel_encoder(dev
, encoder
) {
10244 if (encoder
->new_crtc
!= crtc
)
10247 if (!check_single_encoder_cloning(crtc
, encoder
))
10254 static struct intel_crtc_config
*
10255 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
10256 struct drm_framebuffer
*fb
,
10257 struct drm_display_mode
*mode
)
10259 struct drm_device
*dev
= crtc
->dev
;
10260 struct intel_encoder
*encoder
;
10261 struct intel_crtc_config
*pipe_config
;
10262 int plane_bpp
, ret
= -EINVAL
;
10265 if (!check_encoder_cloning(to_intel_crtc(crtc
))) {
10266 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
10267 return ERR_PTR(-EINVAL
);
10270 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
10272 return ERR_PTR(-ENOMEM
);
10274 drm_mode_copy(&pipe_config
->adjusted_mode
, mode
);
10275 drm_mode_copy(&pipe_config
->requested_mode
, mode
);
10277 pipe_config
->cpu_transcoder
=
10278 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
10279 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
10282 * Sanitize sync polarity flags based on requested ones. If neither
10283 * positive or negative polarity is requested, treat this as meaning
10284 * negative polarity.
10286 if (!(pipe_config
->adjusted_mode
.flags
&
10287 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
10288 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
10290 if (!(pipe_config
->adjusted_mode
.flags
&
10291 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
10292 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
10294 /* Compute a starting value for pipe_config->pipe_bpp taking the source
10295 * plane pixel format and any sink constraints into account. Returns the
10296 * source plane bpp so that dithering can be selected on mismatches
10297 * after encoders and crtc also have had their say. */
10298 plane_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
10304 * Determine the real pipe dimensions. Note that stereo modes can
10305 * increase the actual pipe size due to the frame doubling and
10306 * insertion of additional space for blanks between the frame. This
10307 * is stored in the crtc timings. We use the requested mode to do this
10308 * computation to clearly distinguish it from the adjusted mode, which
10309 * can be changed by the connectors in the below retry loop.
10311 drm_mode_set_crtcinfo(&pipe_config
->requested_mode
, CRTC_STEREO_DOUBLE
);
10312 pipe_config
->pipe_src_w
= pipe_config
->requested_mode
.crtc_hdisplay
;
10313 pipe_config
->pipe_src_h
= pipe_config
->requested_mode
.crtc_vdisplay
;
10316 /* Ensure the port clock defaults are reset when retrying. */
10317 pipe_config
->port_clock
= 0;
10318 pipe_config
->pixel_multiplier
= 1;
10320 /* Fill in default crtc timings, allow encoders to overwrite them. */
10321 drm_mode_set_crtcinfo(&pipe_config
->adjusted_mode
, CRTC_STEREO_DOUBLE
);
10323 /* Pass our mode to the connectors and the CRTC to give them a chance to
10324 * adjust it according to limitations or connector properties, and also
10325 * a chance to reject the mode entirely.
10327 for_each_intel_encoder(dev
, encoder
) {
10329 if (&encoder
->new_crtc
->base
!= crtc
)
10332 if (!(encoder
->compute_config(encoder
, pipe_config
))) {
10333 DRM_DEBUG_KMS("Encoder config failure\n");
10338 /* Set default port clock if not overwritten by the encoder. Needs to be
10339 * done afterwards in case the encoder adjusts the mode. */
10340 if (!pipe_config
->port_clock
)
10341 pipe_config
->port_clock
= pipe_config
->adjusted_mode
.crtc_clock
10342 * pipe_config
->pixel_multiplier
;
10344 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
10346 DRM_DEBUG_KMS("CRTC fixup failed\n");
10350 if (ret
== RETRY
) {
10351 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
10356 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
10358 goto encoder_retry
;
10361 pipe_config
->dither
= pipe_config
->pipe_bpp
!= plane_bpp
;
10362 DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
10363 plane_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
10365 return pipe_config
;
10367 kfree(pipe_config
);
10368 return ERR_PTR(ret
);
10371 /* Computes which crtcs are affected and sets the relevant bits in the mask. For
10372 * simplicity we use the crtc's pipe number (because it's easier to obtain). */
10374 intel_modeset_affected_pipes(struct drm_crtc
*crtc
, unsigned *modeset_pipes
,
10375 unsigned *prepare_pipes
, unsigned *disable_pipes
)
10377 struct intel_crtc
*intel_crtc
;
10378 struct drm_device
*dev
= crtc
->dev
;
10379 struct intel_encoder
*encoder
;
10380 struct intel_connector
*connector
;
10381 struct drm_crtc
*tmp_crtc
;
10383 *disable_pipes
= *modeset_pipes
= *prepare_pipes
= 0;
10385 /* Check which crtcs have changed outputs connected to them, these need
10386 * to be part of the prepare_pipes mask. We don't (yet) support global
10387 * modeset across multiple crtcs, so modeset_pipes will only have one
10388 * bit set at most. */
10389 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10391 if (connector
->base
.encoder
== &connector
->new_encoder
->base
)
10394 if (connector
->base
.encoder
) {
10395 tmp_crtc
= connector
->base
.encoder
->crtc
;
10397 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
10400 if (connector
->new_encoder
)
10402 1 << connector
->new_encoder
->new_crtc
->pipe
;
10405 for_each_intel_encoder(dev
, encoder
) {
10406 if (encoder
->base
.crtc
== &encoder
->new_crtc
->base
)
10409 if (encoder
->base
.crtc
) {
10410 tmp_crtc
= encoder
->base
.crtc
;
10412 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
10415 if (encoder
->new_crtc
)
10416 *prepare_pipes
|= 1 << encoder
->new_crtc
->pipe
;
10419 /* Check for pipes that will be enabled/disabled ... */
10420 for_each_intel_crtc(dev
, intel_crtc
) {
10421 if (intel_crtc
->base
.enabled
== intel_crtc
->new_enabled
)
10424 if (!intel_crtc
->new_enabled
)
10425 *disable_pipes
|= 1 << intel_crtc
->pipe
;
10427 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
10431 /* set_mode is also used to update properties on life display pipes. */
10432 intel_crtc
= to_intel_crtc(crtc
);
10433 if (intel_crtc
->new_enabled
)
10434 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
10437 * For simplicity do a full modeset on any pipe where the output routing
10438 * changed. We could be more clever, but that would require us to be
10439 * more careful with calling the relevant encoder->mode_set functions.
10441 if (*prepare_pipes
)
10442 *modeset_pipes
= *prepare_pipes
;
10444 /* ... and mask these out. */
10445 *modeset_pipes
&= ~(*disable_pipes
);
10446 *prepare_pipes
&= ~(*disable_pipes
);
10449 * HACK: We don't (yet) fully support global modesets. intel_set_config
10450 * obies this rule, but the modeset restore mode of
10451 * intel_modeset_setup_hw_state does not.
10453 *modeset_pipes
&= 1 << intel_crtc
->pipe
;
10454 *prepare_pipes
&= 1 << intel_crtc
->pipe
;
10456 DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
10457 *modeset_pipes
, *prepare_pipes
, *disable_pipes
);
10460 static bool intel_crtc_in_use(struct drm_crtc
*crtc
)
10462 struct drm_encoder
*encoder
;
10463 struct drm_device
*dev
= crtc
->dev
;
10465 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
10466 if (encoder
->crtc
== crtc
)
10473 intel_modeset_update_state(struct drm_device
*dev
, unsigned prepare_pipes
)
10475 struct intel_encoder
*intel_encoder
;
10476 struct intel_crtc
*intel_crtc
;
10477 struct drm_connector
*connector
;
10479 for_each_intel_encoder(dev
, intel_encoder
) {
10480 if (!intel_encoder
->base
.crtc
)
10483 intel_crtc
= to_intel_crtc(intel_encoder
->base
.crtc
);
10485 if (prepare_pipes
& (1 << intel_crtc
->pipe
))
10486 intel_encoder
->connectors_active
= false;
10489 intel_modeset_commit_output_state(dev
);
10491 /* Double check state. */
10492 for_each_intel_crtc(dev
, intel_crtc
) {
10493 WARN_ON(intel_crtc
->base
.enabled
!= intel_crtc_in_use(&intel_crtc
->base
));
10494 WARN_ON(intel_crtc
->new_config
&&
10495 intel_crtc
->new_config
!= &intel_crtc
->config
);
10496 WARN_ON(intel_crtc
->base
.enabled
!= !!intel_crtc
->new_config
);
10499 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
10500 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
10503 intel_crtc
= to_intel_crtc(connector
->encoder
->crtc
);
10505 if (prepare_pipes
& (1 << intel_crtc
->pipe
)) {
10506 struct drm_property
*dpms_property
=
10507 dev
->mode_config
.dpms_property
;
10509 connector
->dpms
= DRM_MODE_DPMS_ON
;
10510 drm_object_property_set_value(&connector
->base
,
10514 intel_encoder
= to_intel_encoder(connector
->encoder
);
10515 intel_encoder
->connectors_active
= true;
10521 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
10525 if (clock1
== clock2
)
10528 if (!clock1
|| !clock2
)
10531 diff
= abs(clock1
- clock2
);
10533 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
10539 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
10540 list_for_each_entry((intel_crtc), \
10541 &(dev)->mode_config.crtc_list, \
10543 if (mask & (1 <<(intel_crtc)->pipe))
10546 intel_pipe_config_compare(struct drm_device
*dev
,
10547 struct intel_crtc_config
*current_config
,
10548 struct intel_crtc_config
*pipe_config
)
10550 #define PIPE_CONF_CHECK_X(name) \
10551 if (current_config->name != pipe_config->name) { \
10552 DRM_ERROR("mismatch in " #name " " \
10553 "(expected 0x%08x, found 0x%08x)\n", \
10554 current_config->name, \
10555 pipe_config->name); \
10559 #define PIPE_CONF_CHECK_I(name) \
10560 if (current_config->name != pipe_config->name) { \
10561 DRM_ERROR("mismatch in " #name " " \
10562 "(expected %i, found %i)\n", \
10563 current_config->name, \
10564 pipe_config->name); \
10568 /* This is required for BDW+ where there is only one set of registers for
10569 * switching between high and low RR.
10570 * This macro can be used whenever a comparison has to be made between one
10571 * hw state and multiple sw state variables.
10573 #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \
10574 if ((current_config->name != pipe_config->name) && \
10575 (current_config->alt_name != pipe_config->name)) { \
10576 DRM_ERROR("mismatch in " #name " " \
10577 "(expected %i or %i, found %i)\n", \
10578 current_config->name, \
10579 current_config->alt_name, \
10580 pipe_config->name); \
10584 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
10585 if ((current_config->name ^ pipe_config->name) & (mask)) { \
10586 DRM_ERROR("mismatch in " #name "(" #mask ") " \
10587 "(expected %i, found %i)\n", \
10588 current_config->name & (mask), \
10589 pipe_config->name & (mask)); \
10593 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
10594 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
10595 DRM_ERROR("mismatch in " #name " " \
10596 "(expected %i, found %i)\n", \
10597 current_config->name, \
10598 pipe_config->name); \
10602 #define PIPE_CONF_QUIRK(quirk) \
10603 ((current_config->quirks | pipe_config->quirks) & (quirk))
10605 PIPE_CONF_CHECK_I(cpu_transcoder
);
10607 PIPE_CONF_CHECK_I(has_pch_encoder
);
10608 PIPE_CONF_CHECK_I(fdi_lanes
);
10609 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_m
);
10610 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_n
);
10611 PIPE_CONF_CHECK_I(fdi_m_n
.link_m
);
10612 PIPE_CONF_CHECK_I(fdi_m_n
.link_n
);
10613 PIPE_CONF_CHECK_I(fdi_m_n
.tu
);
10615 PIPE_CONF_CHECK_I(has_dp_encoder
);
10617 if (INTEL_INFO(dev
)->gen
< 8) {
10618 PIPE_CONF_CHECK_I(dp_m_n
.gmch_m
);
10619 PIPE_CONF_CHECK_I(dp_m_n
.gmch_n
);
10620 PIPE_CONF_CHECK_I(dp_m_n
.link_m
);
10621 PIPE_CONF_CHECK_I(dp_m_n
.link_n
);
10622 PIPE_CONF_CHECK_I(dp_m_n
.tu
);
10624 if (current_config
->has_drrs
) {
10625 PIPE_CONF_CHECK_I(dp_m2_n2
.gmch_m
);
10626 PIPE_CONF_CHECK_I(dp_m2_n2
.gmch_n
);
10627 PIPE_CONF_CHECK_I(dp_m2_n2
.link_m
);
10628 PIPE_CONF_CHECK_I(dp_m2_n2
.link_n
);
10629 PIPE_CONF_CHECK_I(dp_m2_n2
.tu
);
10632 PIPE_CONF_CHECK_I_ALT(dp_m_n
.gmch_m
, dp_m2_n2
.gmch_m
);
10633 PIPE_CONF_CHECK_I_ALT(dp_m_n
.gmch_n
, dp_m2_n2
.gmch_n
);
10634 PIPE_CONF_CHECK_I_ALT(dp_m_n
.link_m
, dp_m2_n2
.link_m
);
10635 PIPE_CONF_CHECK_I_ALT(dp_m_n
.link_n
, dp_m2_n2
.link_n
);
10636 PIPE_CONF_CHECK_I_ALT(dp_m_n
.tu
, dp_m2_n2
.tu
);
10639 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hdisplay
);
10640 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_htotal
);
10641 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hblank_start
);
10642 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hblank_end
);
10643 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hsync_start
);
10644 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hsync_end
);
10646 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vdisplay
);
10647 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vtotal
);
10648 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vblank_start
);
10649 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vblank_end
);
10650 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vsync_start
);
10651 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vsync_end
);
10653 PIPE_CONF_CHECK_I(pixel_multiplier
);
10654 PIPE_CONF_CHECK_I(has_hdmi_sink
);
10655 if ((INTEL_INFO(dev
)->gen
< 8 && !IS_HASWELL(dev
)) ||
10656 IS_VALLEYVIEW(dev
))
10657 PIPE_CONF_CHECK_I(limited_color_range
);
10659 PIPE_CONF_CHECK_I(has_audio
);
10661 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10662 DRM_MODE_FLAG_INTERLACE
);
10664 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
10665 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10666 DRM_MODE_FLAG_PHSYNC
);
10667 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10668 DRM_MODE_FLAG_NHSYNC
);
10669 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10670 DRM_MODE_FLAG_PVSYNC
);
10671 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10672 DRM_MODE_FLAG_NVSYNC
);
10675 PIPE_CONF_CHECK_I(pipe_src_w
);
10676 PIPE_CONF_CHECK_I(pipe_src_h
);
10679 * FIXME: BIOS likes to set up a cloned config with lvds+external
10680 * screen. Since we don't yet re-compute the pipe config when moving
10681 * just the lvds port away to another pipe the sw tracking won't match.
10683 * Proper atomic modesets with recomputed global state will fix this.
10684 * Until then just don't check gmch state for inherited modes.
10686 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE
)) {
10687 PIPE_CONF_CHECK_I(gmch_pfit
.control
);
10688 /* pfit ratios are autocomputed by the hw on gen4+ */
10689 if (INTEL_INFO(dev
)->gen
< 4)
10690 PIPE_CONF_CHECK_I(gmch_pfit
.pgm_ratios
);
10691 PIPE_CONF_CHECK_I(gmch_pfit
.lvds_border_bits
);
10694 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
10695 if (current_config
->pch_pfit
.enabled
) {
10696 PIPE_CONF_CHECK_I(pch_pfit
.pos
);
10697 PIPE_CONF_CHECK_I(pch_pfit
.size
);
10700 /* BDW+ don't expose a synchronous way to read the state */
10701 if (IS_HASWELL(dev
))
10702 PIPE_CONF_CHECK_I(ips_enabled
);
10704 PIPE_CONF_CHECK_I(double_wide
);
10706 PIPE_CONF_CHECK_X(ddi_pll_sel
);
10708 PIPE_CONF_CHECK_I(shared_dpll
);
10709 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
10710 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
10711 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
10712 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
10713 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
10715 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5)
10716 PIPE_CONF_CHECK_I(pipe_bpp
);
10718 PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode
.crtc_clock
);
10719 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
10721 #undef PIPE_CONF_CHECK_X
10722 #undef PIPE_CONF_CHECK_I
10723 #undef PIPE_CONF_CHECK_I_ALT
10724 #undef PIPE_CONF_CHECK_FLAGS
10725 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
10726 #undef PIPE_CONF_QUIRK
10732 check_connector_state(struct drm_device
*dev
)
10734 struct intel_connector
*connector
;
10736 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10738 /* This also checks the encoder/connector hw state with the
10739 * ->get_hw_state callbacks. */
10740 intel_connector_check_state(connector
);
10742 WARN(&connector
->new_encoder
->base
!= connector
->base
.encoder
,
10743 "connector's staged encoder doesn't match current encoder\n");
10748 check_encoder_state(struct drm_device
*dev
)
10750 struct intel_encoder
*encoder
;
10751 struct intel_connector
*connector
;
10753 for_each_intel_encoder(dev
, encoder
) {
10754 bool enabled
= false;
10755 bool active
= false;
10756 enum pipe pipe
, tracked_pipe
;
10758 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
10759 encoder
->base
.base
.id
,
10760 encoder
->base
.name
);
10762 WARN(&encoder
->new_crtc
->base
!= encoder
->base
.crtc
,
10763 "encoder's stage crtc doesn't match current crtc\n");
10764 WARN(encoder
->connectors_active
&& !encoder
->base
.crtc
,
10765 "encoder's active_connectors set, but no crtc\n");
10767 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10769 if (connector
->base
.encoder
!= &encoder
->base
)
10772 if (connector
->base
.dpms
!= DRM_MODE_DPMS_OFF
)
10776 * for MST connectors if we unplug the connector is gone
10777 * away but the encoder is still connected to a crtc
10778 * until a modeset happens in response to the hotplug.
10780 if (!enabled
&& encoder
->base
.encoder_type
== DRM_MODE_ENCODER_DPMST
)
10783 WARN(!!encoder
->base
.crtc
!= enabled
,
10784 "encoder's enabled state mismatch "
10785 "(expected %i, found %i)\n",
10786 !!encoder
->base
.crtc
, enabled
);
10787 WARN(active
&& !encoder
->base
.crtc
,
10788 "active encoder with no crtc\n");
10790 WARN(encoder
->connectors_active
!= active
,
10791 "encoder's computed active state doesn't match tracked active state "
10792 "(expected %i, found %i)\n", active
, encoder
->connectors_active
);
10794 active
= encoder
->get_hw_state(encoder
, &pipe
);
10795 WARN(active
!= encoder
->connectors_active
,
10796 "encoder's hw state doesn't match sw tracking "
10797 "(expected %i, found %i)\n",
10798 encoder
->connectors_active
, active
);
10800 if (!encoder
->base
.crtc
)
10803 tracked_pipe
= to_intel_crtc(encoder
->base
.crtc
)->pipe
;
10804 WARN(active
&& pipe
!= tracked_pipe
,
10805 "active encoder's pipe doesn't match"
10806 "(expected %i, found %i)\n",
10807 tracked_pipe
, pipe
);
10813 check_crtc_state(struct drm_device
*dev
)
10815 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10816 struct intel_crtc
*crtc
;
10817 struct intel_encoder
*encoder
;
10818 struct intel_crtc_config pipe_config
;
10820 for_each_intel_crtc(dev
, crtc
) {
10821 bool enabled
= false;
10822 bool active
= false;
10824 memset(&pipe_config
, 0, sizeof(pipe_config
));
10826 DRM_DEBUG_KMS("[CRTC:%d]\n",
10827 crtc
->base
.base
.id
);
10829 WARN(crtc
->active
&& !crtc
->base
.enabled
,
10830 "active crtc, but not enabled in sw tracking\n");
10832 for_each_intel_encoder(dev
, encoder
) {
10833 if (encoder
->base
.crtc
!= &crtc
->base
)
10836 if (encoder
->connectors_active
)
10840 WARN(active
!= crtc
->active
,
10841 "crtc's computed active state doesn't match tracked active state "
10842 "(expected %i, found %i)\n", active
, crtc
->active
);
10843 WARN(enabled
!= crtc
->base
.enabled
,
10844 "crtc's computed enabled state doesn't match tracked enabled state "
10845 "(expected %i, found %i)\n", enabled
, crtc
->base
.enabled
);
10847 active
= dev_priv
->display
.get_pipe_config(crtc
,
10850 /* hw state is inconsistent with the pipe quirk */
10851 if ((crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
10852 (crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
10853 active
= crtc
->active
;
10855 for_each_intel_encoder(dev
, encoder
) {
10857 if (encoder
->base
.crtc
!= &crtc
->base
)
10859 if (encoder
->get_hw_state(encoder
, &pipe
))
10860 encoder
->get_config(encoder
, &pipe_config
);
10863 WARN(crtc
->active
!= active
,
10864 "crtc active state doesn't match with hw state "
10865 "(expected %i, found %i)\n", crtc
->active
, active
);
10868 !intel_pipe_config_compare(dev
, &crtc
->config
, &pipe_config
)) {
10869 WARN(1, "pipe state doesn't match!\n");
10870 intel_dump_pipe_config(crtc
, &pipe_config
,
10872 intel_dump_pipe_config(crtc
, &crtc
->config
,
10879 check_shared_dpll_state(struct drm_device
*dev
)
10881 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10882 struct intel_crtc
*crtc
;
10883 struct intel_dpll_hw_state dpll_hw_state
;
10886 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
10887 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
10888 int enabled_crtcs
= 0, active_crtcs
= 0;
10891 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
10893 DRM_DEBUG_KMS("%s\n", pll
->name
);
10895 active
= pll
->get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
10897 WARN(pll
->active
> pll
->refcount
,
10898 "more active pll users than references: %i vs %i\n",
10899 pll
->active
, pll
->refcount
);
10900 WARN(pll
->active
&& !pll
->on
,
10901 "pll in active use but not on in sw tracking\n");
10902 WARN(pll
->on
&& !pll
->active
,
10903 "pll in on but not on in use in sw tracking\n");
10904 WARN(pll
->on
!= active
,
10905 "pll on state mismatch (expected %i, found %i)\n",
10908 for_each_intel_crtc(dev
, crtc
) {
10909 if (crtc
->base
.enabled
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
10911 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
10914 WARN(pll
->active
!= active_crtcs
,
10915 "pll active crtcs mismatch (expected %i, found %i)\n",
10916 pll
->active
, active_crtcs
);
10917 WARN(pll
->refcount
!= enabled_crtcs
,
10918 "pll enabled crtcs mismatch (expected %i, found %i)\n",
10919 pll
->refcount
, enabled_crtcs
);
10921 WARN(pll
->on
&& memcmp(&pll
->hw_state
, &dpll_hw_state
,
10922 sizeof(dpll_hw_state
)),
10923 "pll hw state mismatch\n");
10928 intel_modeset_check_state(struct drm_device
*dev
)
10930 check_connector_state(dev
);
10931 check_encoder_state(dev
);
10932 check_crtc_state(dev
);
10933 check_shared_dpll_state(dev
);
10936 void ironlake_check_encoder_dotclock(const struct intel_crtc_config
*pipe_config
,
10940 * FDI already provided one idea for the dotclock.
10941 * Yell if the encoder disagrees.
10943 WARN(!intel_fuzzy_clock_check(pipe_config
->adjusted_mode
.crtc_clock
, dotclock
),
10944 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
10945 pipe_config
->adjusted_mode
.crtc_clock
, dotclock
);
10948 static void update_scanline_offset(struct intel_crtc
*crtc
)
10950 struct drm_device
*dev
= crtc
->base
.dev
;
10953 * The scanline counter increments at the leading edge of hsync.
10955 * On most platforms it starts counting from vtotal-1 on the
10956 * first active line. That means the scanline counter value is
10957 * always one less than what we would expect. Ie. just after
10958 * start of vblank, which also occurs at start of hsync (on the
10959 * last active line), the scanline counter will read vblank_start-1.
10961 * On gen2 the scanline counter starts counting from 1 instead
10962 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
10963 * to keep the value positive), instead of adding one.
10965 * On HSW+ the behaviour of the scanline counter depends on the output
10966 * type. For DP ports it behaves like most other platforms, but on HDMI
10967 * there's an extra 1 line difference. So we need to add two instead of
10968 * one to the value.
10970 if (IS_GEN2(dev
)) {
10971 const struct drm_display_mode
*mode
= &crtc
->config
.adjusted_mode
;
10974 vtotal
= mode
->crtc_vtotal
;
10975 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
10978 crtc
->scanline_offset
= vtotal
- 1;
10979 } else if (HAS_DDI(dev
) &&
10980 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
)) {
10981 crtc
->scanline_offset
= 2;
10983 crtc
->scanline_offset
= 1;
10986 static int __intel_set_mode(struct drm_crtc
*crtc
,
10987 struct drm_display_mode
*mode
,
10988 int x
, int y
, struct drm_framebuffer
*fb
)
10990 struct drm_device
*dev
= crtc
->dev
;
10991 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10992 struct drm_display_mode
*saved_mode
;
10993 struct intel_crtc_config
*pipe_config
= NULL
;
10994 struct intel_crtc
*intel_crtc
;
10995 unsigned disable_pipes
, prepare_pipes
, modeset_pipes
;
10998 saved_mode
= kmalloc(sizeof(*saved_mode
), GFP_KERNEL
);
11002 intel_modeset_affected_pipes(crtc
, &modeset_pipes
,
11003 &prepare_pipes
, &disable_pipes
);
11005 *saved_mode
= crtc
->mode
;
11007 /* Hack: Because we don't (yet) support global modeset on multiple
11008 * crtcs, we don't keep track of the new mode for more than one crtc.
11009 * Hence simply check whether any bit is set in modeset_pipes in all the
11010 * pieces of code that are not yet converted to deal with mutliple crtcs
11011 * changing their mode at the same time. */
11012 if (modeset_pipes
) {
11013 pipe_config
= intel_modeset_pipe_config(crtc
, fb
, mode
);
11014 if (IS_ERR(pipe_config
)) {
11015 ret
= PTR_ERR(pipe_config
);
11016 pipe_config
= NULL
;
11020 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
11022 to_intel_crtc(crtc
)->new_config
= pipe_config
;
11026 * See if the config requires any additional preparation, e.g.
11027 * to adjust global state with pipes off. We need to do this
11028 * here so we can get the modeset_pipe updated config for the new
11029 * mode set on this crtc. For other crtcs we need to use the
11030 * adjusted_mode bits in the crtc directly.
11032 if (IS_VALLEYVIEW(dev
)) {
11033 valleyview_modeset_global_pipes(dev
, &prepare_pipes
);
11035 /* may have added more to prepare_pipes than we should */
11036 prepare_pipes
&= ~disable_pipes
;
11039 for_each_intel_crtc_masked(dev
, disable_pipes
, intel_crtc
)
11040 intel_crtc_disable(&intel_crtc
->base
);
11042 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
11043 if (intel_crtc
->base
.enabled
)
11044 dev_priv
->display
.crtc_disable(&intel_crtc
->base
);
11047 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
11048 * to set it here already despite that we pass it down the callchain.
11050 if (modeset_pipes
) {
11051 crtc
->mode
= *mode
;
11052 /* mode_set/enable/disable functions rely on a correct pipe
11054 to_intel_crtc(crtc
)->config
= *pipe_config
;
11055 to_intel_crtc(crtc
)->new_config
= &to_intel_crtc(crtc
)->config
;
11058 * Calculate and store various constants which
11059 * are later needed by vblank and swap-completion
11060 * timestamping. They are derived from true hwmode.
11062 drm_calc_timestamping_constants(crtc
,
11063 &pipe_config
->adjusted_mode
);
11066 /* Only after disabling all output pipelines that will be changed can we
11067 * update the the output configuration. */
11068 intel_modeset_update_state(dev
, prepare_pipes
);
11070 if (dev_priv
->display
.modeset_global_resources
)
11071 dev_priv
->display
.modeset_global_resources(dev
);
11073 /* Set up the DPLL and any encoders state that needs to adjust or depend
11076 for_each_intel_crtc_masked(dev
, modeset_pipes
, intel_crtc
) {
11077 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
11078 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(old_fb
);
11079 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
11081 mutex_lock(&dev
->struct_mutex
);
11082 ret
= intel_pin_and_fence_fb_obj(dev
,
11086 DRM_ERROR("pin & fence failed\n");
11087 mutex_unlock(&dev
->struct_mutex
);
11091 intel_unpin_fb_obj(old_obj
);
11092 i915_gem_track_fb(old_obj
, obj
,
11093 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
11094 mutex_unlock(&dev
->struct_mutex
);
11096 crtc
->primary
->fb
= fb
;
11100 ret
= dev_priv
->display
.crtc_mode_set(&intel_crtc
->base
,
11106 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
11107 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
11108 update_scanline_offset(intel_crtc
);
11110 dev_priv
->display
.crtc_enable(&intel_crtc
->base
);
11113 /* FIXME: add subpixel order */
11115 if (ret
&& crtc
->enabled
)
11116 crtc
->mode
= *saved_mode
;
11119 kfree(pipe_config
);
11124 static int intel_set_mode(struct drm_crtc
*crtc
,
11125 struct drm_display_mode
*mode
,
11126 int x
, int y
, struct drm_framebuffer
*fb
)
11130 ret
= __intel_set_mode(crtc
, mode
, x
, y
, fb
);
11133 intel_modeset_check_state(crtc
->dev
);
11138 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
11140 intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
, crtc
->primary
->fb
);
11143 #undef for_each_intel_crtc_masked
11145 static void intel_set_config_free(struct intel_set_config
*config
)
11150 kfree(config
->save_connector_encoders
);
11151 kfree(config
->save_encoder_crtcs
);
11152 kfree(config
->save_crtc_enabled
);
11156 static int intel_set_config_save_state(struct drm_device
*dev
,
11157 struct intel_set_config
*config
)
11159 struct drm_crtc
*crtc
;
11160 struct drm_encoder
*encoder
;
11161 struct drm_connector
*connector
;
11164 config
->save_crtc_enabled
=
11165 kcalloc(dev
->mode_config
.num_crtc
,
11166 sizeof(bool), GFP_KERNEL
);
11167 if (!config
->save_crtc_enabled
)
11170 config
->save_encoder_crtcs
=
11171 kcalloc(dev
->mode_config
.num_encoder
,
11172 sizeof(struct drm_crtc
*), GFP_KERNEL
);
11173 if (!config
->save_encoder_crtcs
)
11176 config
->save_connector_encoders
=
11177 kcalloc(dev
->mode_config
.num_connector
,
11178 sizeof(struct drm_encoder
*), GFP_KERNEL
);
11179 if (!config
->save_connector_encoders
)
11182 /* Copy data. Note that driver private data is not affected.
11183 * Should anything bad happen only the expected state is
11184 * restored, not the drivers personal bookkeeping.
11187 for_each_crtc(dev
, crtc
) {
11188 config
->save_crtc_enabled
[count
++] = crtc
->enabled
;
11192 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
11193 config
->save_encoder_crtcs
[count
++] = encoder
->crtc
;
11197 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
11198 config
->save_connector_encoders
[count
++] = connector
->encoder
;
11204 static void intel_set_config_restore_state(struct drm_device
*dev
,
11205 struct intel_set_config
*config
)
11207 struct intel_crtc
*crtc
;
11208 struct intel_encoder
*encoder
;
11209 struct intel_connector
*connector
;
11213 for_each_intel_crtc(dev
, crtc
) {
11214 crtc
->new_enabled
= config
->save_crtc_enabled
[count
++];
11216 if (crtc
->new_enabled
)
11217 crtc
->new_config
= &crtc
->config
;
11219 crtc
->new_config
= NULL
;
11223 for_each_intel_encoder(dev
, encoder
) {
11224 encoder
->new_crtc
=
11225 to_intel_crtc(config
->save_encoder_crtcs
[count
++]);
11229 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, base
.head
) {
11230 connector
->new_encoder
=
11231 to_intel_encoder(config
->save_connector_encoders
[count
++]);
11236 is_crtc_connector_off(struct drm_mode_set
*set
)
11240 if (set
->num_connectors
== 0)
11243 if (WARN_ON(set
->connectors
== NULL
))
11246 for (i
= 0; i
< set
->num_connectors
; i
++)
11247 if (set
->connectors
[i
]->encoder
&&
11248 set
->connectors
[i
]->encoder
->crtc
== set
->crtc
&&
11249 set
->connectors
[i
]->dpms
!= DRM_MODE_DPMS_ON
)
11256 intel_set_config_compute_mode_changes(struct drm_mode_set
*set
,
11257 struct intel_set_config
*config
)
11260 /* We should be able to check here if the fb has the same properties
11261 * and then just flip_or_move it */
11262 if (is_crtc_connector_off(set
)) {
11263 config
->mode_changed
= true;
11264 } else if (set
->crtc
->primary
->fb
!= set
->fb
) {
11266 * If we have no fb, we can only flip as long as the crtc is
11267 * active, otherwise we need a full mode set. The crtc may
11268 * be active if we've only disabled the primary plane, or
11269 * in fastboot situations.
11271 if (set
->crtc
->primary
->fb
== NULL
) {
11272 struct intel_crtc
*intel_crtc
=
11273 to_intel_crtc(set
->crtc
);
11275 if (intel_crtc
->active
) {
11276 DRM_DEBUG_KMS("crtc has no fb, will flip\n");
11277 config
->fb_changed
= true;
11279 DRM_DEBUG_KMS("inactive crtc, full mode set\n");
11280 config
->mode_changed
= true;
11282 } else if (set
->fb
== NULL
) {
11283 config
->mode_changed
= true;
11284 } else if (set
->fb
->pixel_format
!=
11285 set
->crtc
->primary
->fb
->pixel_format
) {
11286 config
->mode_changed
= true;
11288 config
->fb_changed
= true;
11292 if (set
->fb
&& (set
->x
!= set
->crtc
->x
|| set
->y
!= set
->crtc
->y
))
11293 config
->fb_changed
= true;
11295 if (set
->mode
&& !drm_mode_equal(set
->mode
, &set
->crtc
->mode
)) {
11296 DRM_DEBUG_KMS("modes are different, full mode set\n");
11297 drm_mode_debug_printmodeline(&set
->crtc
->mode
);
11298 drm_mode_debug_printmodeline(set
->mode
);
11299 config
->mode_changed
= true;
11302 DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
11303 set
->crtc
->base
.id
, config
->mode_changed
, config
->fb_changed
);
11307 intel_modeset_stage_output_state(struct drm_device
*dev
,
11308 struct drm_mode_set
*set
,
11309 struct intel_set_config
*config
)
11311 struct intel_connector
*connector
;
11312 struct intel_encoder
*encoder
;
11313 struct intel_crtc
*crtc
;
11316 /* The upper layers ensure that we either disable a crtc or have a list
11317 * of connectors. For paranoia, double-check this. */
11318 WARN_ON(!set
->fb
&& (set
->num_connectors
!= 0));
11319 WARN_ON(set
->fb
&& (set
->num_connectors
== 0));
11321 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
11323 /* Otherwise traverse passed in connector list and get encoders
11325 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
11326 if (set
->connectors
[ro
] == &connector
->base
) {
11327 connector
->new_encoder
= intel_find_encoder(connector
, to_intel_crtc(set
->crtc
)->pipe
);
11332 /* If we disable the crtc, disable all its connectors. Also, if
11333 * the connector is on the changing crtc but not on the new
11334 * connector list, disable it. */
11335 if ((!set
->fb
|| ro
== set
->num_connectors
) &&
11336 connector
->base
.encoder
&&
11337 connector
->base
.encoder
->crtc
== set
->crtc
) {
11338 connector
->new_encoder
= NULL
;
11340 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
11341 connector
->base
.base
.id
,
11342 connector
->base
.name
);
11346 if (&connector
->new_encoder
->base
!= connector
->base
.encoder
) {
11347 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
11348 config
->mode_changed
= true;
11351 /* connector->new_encoder is now updated for all connectors. */
11353 /* Update crtc of enabled connectors. */
11354 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
11356 struct drm_crtc
*new_crtc
;
11358 if (!connector
->new_encoder
)
11361 new_crtc
= connector
->new_encoder
->base
.crtc
;
11363 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
11364 if (set
->connectors
[ro
] == &connector
->base
)
11365 new_crtc
= set
->crtc
;
11368 /* Make sure the new CRTC will work with the encoder */
11369 if (!drm_encoder_crtc_ok(&connector
->new_encoder
->base
,
11373 connector
->new_encoder
->new_crtc
= to_intel_crtc(new_crtc
);
11375 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
11376 connector
->base
.base
.id
,
11377 connector
->base
.name
,
11378 new_crtc
->base
.id
);
11381 /* Check for any encoders that needs to be disabled. */
11382 for_each_intel_encoder(dev
, encoder
) {
11383 int num_connectors
= 0;
11384 list_for_each_entry(connector
,
11385 &dev
->mode_config
.connector_list
,
11387 if (connector
->new_encoder
== encoder
) {
11388 WARN_ON(!connector
->new_encoder
->new_crtc
);
11393 if (num_connectors
== 0)
11394 encoder
->new_crtc
= NULL
;
11395 else if (num_connectors
> 1)
11398 /* Only now check for crtc changes so we don't miss encoders
11399 * that will be disabled. */
11400 if (&encoder
->new_crtc
->base
!= encoder
->base
.crtc
) {
11401 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
11402 config
->mode_changed
= true;
11405 /* Now we've also updated encoder->new_crtc for all encoders. */
11406 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
11408 if (connector
->new_encoder
)
11409 if (connector
->new_encoder
!= connector
->encoder
)
11410 connector
->encoder
= connector
->new_encoder
;
11412 for_each_intel_crtc(dev
, crtc
) {
11413 crtc
->new_enabled
= false;
11415 for_each_intel_encoder(dev
, encoder
) {
11416 if (encoder
->new_crtc
== crtc
) {
11417 crtc
->new_enabled
= true;
11422 if (crtc
->new_enabled
!= crtc
->base
.enabled
) {
11423 DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
11424 crtc
->new_enabled
? "en" : "dis");
11425 config
->mode_changed
= true;
11428 if (crtc
->new_enabled
)
11429 crtc
->new_config
= &crtc
->config
;
11431 crtc
->new_config
= NULL
;
11437 static void disable_crtc_nofb(struct intel_crtc
*crtc
)
11439 struct drm_device
*dev
= crtc
->base
.dev
;
11440 struct intel_encoder
*encoder
;
11441 struct intel_connector
*connector
;
11443 DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
11444 pipe_name(crtc
->pipe
));
11446 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, base
.head
) {
11447 if (connector
->new_encoder
&&
11448 connector
->new_encoder
->new_crtc
== crtc
)
11449 connector
->new_encoder
= NULL
;
11452 for_each_intel_encoder(dev
, encoder
) {
11453 if (encoder
->new_crtc
== crtc
)
11454 encoder
->new_crtc
= NULL
;
11457 crtc
->new_enabled
= false;
11458 crtc
->new_config
= NULL
;
11461 static int intel_crtc_set_config(struct drm_mode_set
*set
)
11463 struct drm_device
*dev
;
11464 struct drm_mode_set save_set
;
11465 struct intel_set_config
*config
;
11469 BUG_ON(!set
->crtc
);
11470 BUG_ON(!set
->crtc
->helper_private
);
11472 /* Enforce sane interface api - has been abused by the fb helper. */
11473 BUG_ON(!set
->mode
&& set
->fb
);
11474 BUG_ON(set
->fb
&& set
->num_connectors
== 0);
11477 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
11478 set
->crtc
->base
.id
, set
->fb
->base
.id
,
11479 (int)set
->num_connectors
, set
->x
, set
->y
);
11481 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set
->crtc
->base
.id
);
11484 dev
= set
->crtc
->dev
;
11487 config
= kzalloc(sizeof(*config
), GFP_KERNEL
);
11491 ret
= intel_set_config_save_state(dev
, config
);
11495 save_set
.crtc
= set
->crtc
;
11496 save_set
.mode
= &set
->crtc
->mode
;
11497 save_set
.x
= set
->crtc
->x
;
11498 save_set
.y
= set
->crtc
->y
;
11499 save_set
.fb
= set
->crtc
->primary
->fb
;
11501 /* Compute whether we need a full modeset, only an fb base update or no
11502 * change at all. In the future we might also check whether only the
11503 * mode changed, e.g. for LVDS where we only change the panel fitter in
11505 intel_set_config_compute_mode_changes(set
, config
);
11507 ret
= intel_modeset_stage_output_state(dev
, set
, config
);
11511 if (config
->mode_changed
) {
11512 ret
= intel_set_mode(set
->crtc
, set
->mode
,
11513 set
->x
, set
->y
, set
->fb
);
11514 } else if (config
->fb_changed
) {
11515 struct intel_crtc
*intel_crtc
= to_intel_crtc(set
->crtc
);
11517 intel_crtc_wait_for_pending_flips(set
->crtc
);
11519 ret
= intel_pipe_set_base(set
->crtc
,
11520 set
->x
, set
->y
, set
->fb
);
11523 * We need to make sure the primary plane is re-enabled if it
11524 * has previously been turned off.
11526 if (!intel_crtc
->primary_enabled
&& ret
== 0) {
11527 WARN_ON(!intel_crtc
->active
);
11528 intel_enable_primary_hw_plane(set
->crtc
->primary
, set
->crtc
);
11532 * In the fastboot case this may be our only check of the
11533 * state after boot. It would be better to only do it on
11534 * the first update, but we don't have a nice way of doing that
11535 * (and really, set_config isn't used much for high freq page
11536 * flipping, so increasing its cost here shouldn't be a big
11539 if (i915
.fastboot
&& ret
== 0)
11540 intel_modeset_check_state(set
->crtc
->dev
);
11544 DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
11545 set
->crtc
->base
.id
, ret
);
11547 intel_set_config_restore_state(dev
, config
);
11550 * HACK: if the pipe was on, but we didn't have a framebuffer,
11551 * force the pipe off to avoid oopsing in the modeset code
11552 * due to fb==NULL. This should only happen during boot since
11553 * we don't yet reconstruct the FB from the hardware state.
11555 if (to_intel_crtc(save_set
.crtc
)->new_enabled
&& !save_set
.fb
)
11556 disable_crtc_nofb(to_intel_crtc(save_set
.crtc
));
11558 /* Try to restore the config */
11559 if (config
->mode_changed
&&
11560 intel_set_mode(save_set
.crtc
, save_set
.mode
,
11561 save_set
.x
, save_set
.y
, save_set
.fb
))
11562 DRM_ERROR("failed to restore config after modeset failure\n");
11566 intel_set_config_free(config
);
11570 static const struct drm_crtc_funcs intel_crtc_funcs
= {
11571 .gamma_set
= intel_crtc_gamma_set
,
11572 .set_config
= intel_crtc_set_config
,
11573 .destroy
= intel_crtc_destroy
,
11574 .page_flip
= intel_crtc_page_flip
,
11577 static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private
*dev_priv
,
11578 struct intel_shared_dpll
*pll
,
11579 struct intel_dpll_hw_state
*hw_state
)
11583 if (!intel_display_power_enabled(dev_priv
, POWER_DOMAIN_PLLS
))
11586 val
= I915_READ(PCH_DPLL(pll
->id
));
11587 hw_state
->dpll
= val
;
11588 hw_state
->fp0
= I915_READ(PCH_FP0(pll
->id
));
11589 hw_state
->fp1
= I915_READ(PCH_FP1(pll
->id
));
11591 return val
& DPLL_VCO_ENABLE
;
11594 static void ibx_pch_dpll_mode_set(struct drm_i915_private
*dev_priv
,
11595 struct intel_shared_dpll
*pll
)
11597 I915_WRITE(PCH_FP0(pll
->id
), pll
->hw_state
.fp0
);
11598 I915_WRITE(PCH_FP1(pll
->id
), pll
->hw_state
.fp1
);
11601 static void ibx_pch_dpll_enable(struct drm_i915_private
*dev_priv
,
11602 struct intel_shared_dpll
*pll
)
11604 /* PCH refclock must be enabled first */
11605 ibx_assert_pch_refclk_enabled(dev_priv
);
11607 I915_WRITE(PCH_DPLL(pll
->id
), pll
->hw_state
.dpll
);
11609 /* Wait for the clocks to stabilize. */
11610 POSTING_READ(PCH_DPLL(pll
->id
));
11613 /* The pixel multiplier can only be updated once the
11614 * DPLL is enabled and the clocks are stable.
11616 * So write it again.
11618 I915_WRITE(PCH_DPLL(pll
->id
), pll
->hw_state
.dpll
);
11619 POSTING_READ(PCH_DPLL(pll
->id
));
11623 static void ibx_pch_dpll_disable(struct drm_i915_private
*dev_priv
,
11624 struct intel_shared_dpll
*pll
)
11626 struct drm_device
*dev
= dev_priv
->dev
;
11627 struct intel_crtc
*crtc
;
11629 /* Make sure no transcoder isn't still depending on us. */
11630 for_each_intel_crtc(dev
, crtc
) {
11631 if (intel_crtc_to_shared_dpll(crtc
) == pll
)
11632 assert_pch_transcoder_disabled(dev_priv
, crtc
->pipe
);
11635 I915_WRITE(PCH_DPLL(pll
->id
), 0);
11636 POSTING_READ(PCH_DPLL(pll
->id
));
11640 static char *ibx_pch_dpll_names
[] = {
11645 static void ibx_pch_dpll_init(struct drm_device
*dev
)
11647 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11650 dev_priv
->num_shared_dpll
= 2;
11652 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
11653 dev_priv
->shared_dplls
[i
].id
= i
;
11654 dev_priv
->shared_dplls
[i
].name
= ibx_pch_dpll_names
[i
];
11655 dev_priv
->shared_dplls
[i
].mode_set
= ibx_pch_dpll_mode_set
;
11656 dev_priv
->shared_dplls
[i
].enable
= ibx_pch_dpll_enable
;
11657 dev_priv
->shared_dplls
[i
].disable
= ibx_pch_dpll_disable
;
11658 dev_priv
->shared_dplls
[i
].get_hw_state
=
11659 ibx_pch_dpll_get_hw_state
;
11663 static void intel_shared_dpll_init(struct drm_device
*dev
)
11665 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11668 intel_ddi_pll_init(dev
);
11669 else if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
11670 ibx_pch_dpll_init(dev
);
11672 dev_priv
->num_shared_dpll
= 0;
11674 BUG_ON(dev_priv
->num_shared_dpll
> I915_NUM_PLLS
);
11678 intel_primary_plane_disable(struct drm_plane
*plane
)
11680 struct drm_device
*dev
= plane
->dev
;
11681 struct intel_crtc
*intel_crtc
;
11686 BUG_ON(!plane
->crtc
);
11688 intel_crtc
= to_intel_crtc(plane
->crtc
);
11691 * Even though we checked plane->fb above, it's still possible that
11692 * the primary plane has been implicitly disabled because the crtc
11693 * coordinates given weren't visible, or because we detected
11694 * that it was 100% covered by a sprite plane. Or, the CRTC may be
11695 * off and we've set a fb, but haven't actually turned on the CRTC yet.
11696 * In either case, we need to unpin the FB and let the fb pointer get
11697 * updated, but otherwise we don't need to touch the hardware.
11699 if (!intel_crtc
->primary_enabled
)
11700 goto disable_unpin
;
11702 intel_crtc_wait_for_pending_flips(plane
->crtc
);
11703 intel_disable_primary_hw_plane(plane
, plane
->crtc
);
11706 mutex_lock(&dev
->struct_mutex
);
11707 i915_gem_track_fb(intel_fb_obj(plane
->fb
), NULL
,
11708 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
11709 intel_unpin_fb_obj(intel_fb_obj(plane
->fb
));
11710 mutex_unlock(&dev
->struct_mutex
);
11717 intel_primary_plane_setplane(struct drm_plane
*plane
, struct drm_crtc
*crtc
,
11718 struct drm_framebuffer
*fb
, int crtc_x
, int crtc_y
,
11719 unsigned int crtc_w
, unsigned int crtc_h
,
11720 uint32_t src_x
, uint32_t src_y
,
11721 uint32_t src_w
, uint32_t src_h
)
11723 struct drm_device
*dev
= crtc
->dev
;
11724 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11725 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11726 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
11727 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->fb
);
11728 struct drm_rect dest
= {
11729 /* integer pixels */
11732 .x2
= crtc_x
+ crtc_w
,
11733 .y2
= crtc_y
+ crtc_h
,
11735 struct drm_rect src
= {
11736 /* 16.16 fixed point */
11739 .x2
= src_x
+ src_w
,
11740 .y2
= src_y
+ src_h
,
11742 const struct drm_rect clip
= {
11743 /* integer pixels */
11744 .x2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_w
: 0,
11745 .y2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_h
: 0,
11748 int crtc_x
, crtc_y
;
11749 unsigned int crtc_w
, crtc_h
;
11750 uint32_t src_x
, src_y
, src_w
, src_h
;
11761 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
11765 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
11766 &src
, &dest
, &clip
,
11767 DRM_PLANE_HELPER_NO_SCALING
,
11768 DRM_PLANE_HELPER_NO_SCALING
,
11769 false, true, &visible
);
11775 * If the CRTC isn't enabled, we're just pinning the framebuffer,
11776 * updating the fb pointer, and returning without touching the
11777 * hardware. This allows us to later do a drmModeSetCrtc with fb=-1 to
11778 * turn on the display with all planes setup as desired.
11780 if (!crtc
->enabled
) {
11781 mutex_lock(&dev
->struct_mutex
);
11784 * If we already called setplane while the crtc was disabled,
11785 * we may have an fb pinned; unpin it.
11788 intel_unpin_fb_obj(old_obj
);
11790 i915_gem_track_fb(old_obj
, obj
,
11791 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
11793 /* Pin and return without programming hardware */
11794 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, NULL
);
11795 mutex_unlock(&dev
->struct_mutex
);
11800 intel_crtc_wait_for_pending_flips(crtc
);
11803 * If clipping results in a non-visible primary plane, we'll disable
11804 * the primary plane. Note that this is a bit different than what
11805 * happens if userspace explicitly disables the plane by passing fb=0
11806 * because plane->fb still gets set and pinned.
11809 mutex_lock(&dev
->struct_mutex
);
11812 * Try to pin the new fb first so that we can bail out if we
11815 if (plane
->fb
!= fb
) {
11816 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, NULL
);
11818 mutex_unlock(&dev
->struct_mutex
);
11823 i915_gem_track_fb(old_obj
, obj
,
11824 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
11826 if (intel_crtc
->primary_enabled
)
11827 intel_disable_primary_hw_plane(plane
, crtc
);
11830 if (plane
->fb
!= fb
)
11832 intel_unpin_fb_obj(old_obj
);
11834 mutex_unlock(&dev
->struct_mutex
);
11837 if (intel_crtc
&& intel_crtc
->active
&&
11838 intel_crtc
->primary_enabled
) {
11840 * FBC does not work on some platforms for rotated
11841 * planes, so disable it when rotation is not 0 and
11842 * update it when rotation is set back to 0.
11844 * FIXME: This is redundant with the fbc update done in
11845 * the primary plane enable function except that that
11846 * one is done too late. We eventually need to unify
11849 if (INTEL_INFO(dev
)->gen
<= 4 && !IS_G4X(dev
) &&
11850 dev_priv
->fbc
.plane
== intel_crtc
->plane
&&
11851 intel_plane
->rotation
!= BIT(DRM_ROTATE_0
)) {
11852 intel_disable_fbc(dev
);
11855 ret
= intel_pipe_set_base(crtc
, src
.x1
, src
.y1
, fb
);
11859 if (!intel_crtc
->primary_enabled
)
11860 intel_enable_primary_hw_plane(plane
, crtc
);
11863 intel_plane
->crtc_x
= orig
.crtc_x
;
11864 intel_plane
->crtc_y
= orig
.crtc_y
;
11865 intel_plane
->crtc_w
= orig
.crtc_w
;
11866 intel_plane
->crtc_h
= orig
.crtc_h
;
11867 intel_plane
->src_x
= orig
.src_x
;
11868 intel_plane
->src_y
= orig
.src_y
;
11869 intel_plane
->src_w
= orig
.src_w
;
11870 intel_plane
->src_h
= orig
.src_h
;
11871 intel_plane
->obj
= obj
;
11876 /* Common destruction function for both primary and cursor planes */
11877 static void intel_plane_destroy(struct drm_plane
*plane
)
11879 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
11880 drm_plane_cleanup(plane
);
11881 kfree(intel_plane
);
11884 static const struct drm_plane_funcs intel_primary_plane_funcs
= {
11885 .update_plane
= intel_primary_plane_setplane
,
11886 .disable_plane
= intel_primary_plane_disable
,
11887 .destroy
= intel_plane_destroy
,
11888 .set_property
= intel_plane_set_property
11891 static struct drm_plane
*intel_primary_plane_create(struct drm_device
*dev
,
11894 struct intel_plane
*primary
;
11895 const uint32_t *intel_primary_formats
;
11898 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
11899 if (primary
== NULL
)
11902 primary
->can_scale
= false;
11903 primary
->max_downscale
= 1;
11904 primary
->pipe
= pipe
;
11905 primary
->plane
= pipe
;
11906 primary
->rotation
= BIT(DRM_ROTATE_0
);
11907 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4)
11908 primary
->plane
= !pipe
;
11910 if (INTEL_INFO(dev
)->gen
<= 3) {
11911 intel_primary_formats
= intel_primary_formats_gen2
;
11912 num_formats
= ARRAY_SIZE(intel_primary_formats_gen2
);
11914 intel_primary_formats
= intel_primary_formats_gen4
;
11915 num_formats
= ARRAY_SIZE(intel_primary_formats_gen4
);
11918 drm_universal_plane_init(dev
, &primary
->base
, 0,
11919 &intel_primary_plane_funcs
,
11920 intel_primary_formats
, num_formats
,
11921 DRM_PLANE_TYPE_PRIMARY
);
11923 if (INTEL_INFO(dev
)->gen
>= 4) {
11924 if (!dev
->mode_config
.rotation_property
)
11925 dev
->mode_config
.rotation_property
=
11926 drm_mode_create_rotation_property(dev
,
11927 BIT(DRM_ROTATE_0
) |
11928 BIT(DRM_ROTATE_180
));
11929 if (dev
->mode_config
.rotation_property
)
11930 drm_object_attach_property(&primary
->base
.base
,
11931 dev
->mode_config
.rotation_property
,
11932 primary
->rotation
);
11935 return &primary
->base
;
11939 intel_cursor_plane_disable(struct drm_plane
*plane
)
11944 BUG_ON(!plane
->crtc
);
11946 return intel_crtc_cursor_set_obj(plane
->crtc
, NULL
, 0, 0);
11950 intel_cursor_plane_update(struct drm_plane
*plane
, struct drm_crtc
*crtc
,
11951 struct drm_framebuffer
*fb
, int crtc_x
, int crtc_y
,
11952 unsigned int crtc_w
, unsigned int crtc_h
,
11953 uint32_t src_x
, uint32_t src_y
,
11954 uint32_t src_w
, uint32_t src_h
)
11956 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11957 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
11958 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
11959 struct drm_rect dest
= {
11960 /* integer pixels */
11963 .x2
= crtc_x
+ crtc_w
,
11964 .y2
= crtc_y
+ crtc_h
,
11966 struct drm_rect src
= {
11967 /* 16.16 fixed point */
11970 .x2
= src_x
+ src_w
,
11971 .y2
= src_y
+ src_h
,
11973 const struct drm_rect clip
= {
11974 /* integer pixels */
11975 .x2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_w
: 0,
11976 .y2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_h
: 0,
11981 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
11982 &src
, &dest
, &clip
,
11983 DRM_PLANE_HELPER_NO_SCALING
,
11984 DRM_PLANE_HELPER_NO_SCALING
,
11985 true, true, &visible
);
11989 crtc
->cursor_x
= crtc_x
;
11990 crtc
->cursor_y
= crtc_y
;
11991 if (fb
!= crtc
->cursor
->fb
) {
11992 return intel_crtc_cursor_set_obj(crtc
, obj
, crtc_w
, crtc_h
);
11994 intel_crtc_update_cursor(crtc
, visible
);
11996 intel_frontbuffer_flip(crtc
->dev
,
11997 INTEL_FRONTBUFFER_CURSOR(intel_crtc
->pipe
));
12002 static const struct drm_plane_funcs intel_cursor_plane_funcs
= {
12003 .update_plane
= intel_cursor_plane_update
,
12004 .disable_plane
= intel_cursor_plane_disable
,
12005 .destroy
= intel_plane_destroy
,
12008 static struct drm_plane
*intel_cursor_plane_create(struct drm_device
*dev
,
12011 struct intel_plane
*cursor
;
12013 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
12014 if (cursor
== NULL
)
12017 cursor
->can_scale
= false;
12018 cursor
->max_downscale
= 1;
12019 cursor
->pipe
= pipe
;
12020 cursor
->plane
= pipe
;
12022 drm_universal_plane_init(dev
, &cursor
->base
, 0,
12023 &intel_cursor_plane_funcs
,
12024 intel_cursor_formats
,
12025 ARRAY_SIZE(intel_cursor_formats
),
12026 DRM_PLANE_TYPE_CURSOR
);
12027 return &cursor
->base
;
12030 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
12032 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12033 struct intel_crtc
*intel_crtc
;
12034 struct drm_plane
*primary
= NULL
;
12035 struct drm_plane
*cursor
= NULL
;
12038 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
12039 if (intel_crtc
== NULL
)
12042 primary
= intel_primary_plane_create(dev
, pipe
);
12046 cursor
= intel_cursor_plane_create(dev
, pipe
);
12050 ret
= drm_crtc_init_with_planes(dev
, &intel_crtc
->base
, primary
,
12051 cursor
, &intel_crtc_funcs
);
12055 drm_mode_crtc_set_gamma_size(&intel_crtc
->base
, 256);
12056 for (i
= 0; i
< 256; i
++) {
12057 intel_crtc
->lut_r
[i
] = i
;
12058 intel_crtc
->lut_g
[i
] = i
;
12059 intel_crtc
->lut_b
[i
] = i
;
12063 * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
12064 * is hooked to pipe B. Hence we want plane A feeding pipe B.
12066 intel_crtc
->pipe
= pipe
;
12067 intel_crtc
->plane
= pipe
;
12068 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4) {
12069 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
12070 intel_crtc
->plane
= !pipe
;
12073 intel_crtc
->cursor_base
= ~0;
12074 intel_crtc
->cursor_cntl
= ~0;
12075 intel_crtc
->cursor_size
= ~0;
12077 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
12078 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
12079 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
12080 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
12082 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
12084 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
12089 drm_plane_cleanup(primary
);
12091 drm_plane_cleanup(cursor
);
12095 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
12097 struct drm_encoder
*encoder
= connector
->base
.encoder
;
12098 struct drm_device
*dev
= connector
->base
.dev
;
12100 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
12103 return INVALID_PIPE
;
12105 return to_intel_crtc(encoder
->crtc
)->pipe
;
12108 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
12109 struct drm_file
*file
)
12111 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
12112 struct drm_crtc
*drmmode_crtc
;
12113 struct intel_crtc
*crtc
;
12115 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
12118 drmmode_crtc
= drm_crtc_find(dev
, pipe_from_crtc_id
->crtc_id
);
12120 if (!drmmode_crtc
) {
12121 DRM_ERROR("no such CRTC id\n");
12125 crtc
= to_intel_crtc(drmmode_crtc
);
12126 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
12131 static int intel_encoder_clones(struct intel_encoder
*encoder
)
12133 struct drm_device
*dev
= encoder
->base
.dev
;
12134 struct intel_encoder
*source_encoder
;
12135 int index_mask
= 0;
12138 for_each_intel_encoder(dev
, source_encoder
) {
12139 if (encoders_cloneable(encoder
, source_encoder
))
12140 index_mask
|= (1 << entry
);
12148 static bool has_edp_a(struct drm_device
*dev
)
12150 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12152 if (!IS_MOBILE(dev
))
12155 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
12158 if (IS_GEN5(dev
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
12164 const char *intel_output_name(int output
)
12166 static const char *names
[] = {
12167 [INTEL_OUTPUT_UNUSED
] = "Unused",
12168 [INTEL_OUTPUT_ANALOG
] = "Analog",
12169 [INTEL_OUTPUT_DVO
] = "DVO",
12170 [INTEL_OUTPUT_SDVO
] = "SDVO",
12171 [INTEL_OUTPUT_LVDS
] = "LVDS",
12172 [INTEL_OUTPUT_TVOUT
] = "TV",
12173 [INTEL_OUTPUT_HDMI
] = "HDMI",
12174 [INTEL_OUTPUT_DISPLAYPORT
] = "DisplayPort",
12175 [INTEL_OUTPUT_EDP
] = "eDP",
12176 [INTEL_OUTPUT_DSI
] = "DSI",
12177 [INTEL_OUTPUT_UNKNOWN
] = "Unknown",
12180 if (output
< 0 || output
>= ARRAY_SIZE(names
) || !names
[output
])
12183 return names
[output
];
12186 static bool intel_crt_present(struct drm_device
*dev
)
12188 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12193 if (IS_CHERRYVIEW(dev
))
12196 if (IS_VALLEYVIEW(dev
) && !dev_priv
->vbt
.int_crt_support
)
12202 static void intel_setup_outputs(struct drm_device
*dev
)
12204 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12205 struct intel_encoder
*encoder
;
12206 bool dpd_is_edp
= false;
12208 intel_lvds_init(dev
);
12210 if (intel_crt_present(dev
))
12211 intel_crt_init(dev
);
12213 if (HAS_DDI(dev
)) {
12216 /* Haswell uses DDI functions to detect digital outputs */
12217 found
= I915_READ(DDI_BUF_CTL_A
) & DDI_INIT_DISPLAY_DETECTED
;
12218 /* DDI A only supports eDP */
12220 intel_ddi_init(dev
, PORT_A
);
12222 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
12224 found
= I915_READ(SFUSE_STRAP
);
12226 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
12227 intel_ddi_init(dev
, PORT_B
);
12228 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
12229 intel_ddi_init(dev
, PORT_C
);
12230 if (found
& SFUSE_STRAP_DDID_DETECTED
)
12231 intel_ddi_init(dev
, PORT_D
);
12232 } else if (HAS_PCH_SPLIT(dev
)) {
12234 dpd_is_edp
= intel_dp_is_edp(dev
, PORT_D
);
12236 if (has_edp_a(dev
))
12237 intel_dp_init(dev
, DP_A
, PORT_A
);
12239 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
12240 /* PCH SDVOB multiplex with HDMIB */
12241 found
= intel_sdvo_init(dev
, PCH_SDVOB
, true);
12243 intel_hdmi_init(dev
, PCH_HDMIB
, PORT_B
);
12244 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
12245 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
12248 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
12249 intel_hdmi_init(dev
, PCH_HDMIC
, PORT_C
);
12251 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
12252 intel_hdmi_init(dev
, PCH_HDMID
, PORT_D
);
12254 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
12255 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
12257 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
12258 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
12259 } else if (IS_VALLEYVIEW(dev
)) {
12260 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIB
) & SDVO_DETECTED
) {
12261 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIB
,
12263 if (I915_READ(VLV_DISPLAY_BASE
+ DP_B
) & DP_DETECTED
)
12264 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_B
, PORT_B
);
12267 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIC
) & SDVO_DETECTED
) {
12268 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIC
,
12270 if (I915_READ(VLV_DISPLAY_BASE
+ DP_C
) & DP_DETECTED
)
12271 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_C
, PORT_C
);
12274 if (IS_CHERRYVIEW(dev
)) {
12275 if (I915_READ(VLV_DISPLAY_BASE
+ CHV_HDMID
) & SDVO_DETECTED
) {
12276 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ CHV_HDMID
,
12278 if (I915_READ(VLV_DISPLAY_BASE
+ DP_D
) & DP_DETECTED
)
12279 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_D
, PORT_D
);
12283 intel_dsi_init(dev
);
12284 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev
)) {
12285 bool found
= false;
12287 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
12288 DRM_DEBUG_KMS("probing SDVOB\n");
12289 found
= intel_sdvo_init(dev
, GEN3_SDVOB
, true);
12290 if (!found
&& SUPPORTS_INTEGRATED_HDMI(dev
)) {
12291 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
12292 intel_hdmi_init(dev
, GEN4_HDMIB
, PORT_B
);
12295 if (!found
&& SUPPORTS_INTEGRATED_DP(dev
))
12296 intel_dp_init(dev
, DP_B
, PORT_B
);
12299 /* Before G4X SDVOC doesn't have its own detect register */
12301 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
12302 DRM_DEBUG_KMS("probing SDVOC\n");
12303 found
= intel_sdvo_init(dev
, GEN3_SDVOC
, false);
12306 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
12308 if (SUPPORTS_INTEGRATED_HDMI(dev
)) {
12309 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
12310 intel_hdmi_init(dev
, GEN4_HDMIC
, PORT_C
);
12312 if (SUPPORTS_INTEGRATED_DP(dev
))
12313 intel_dp_init(dev
, DP_C
, PORT_C
);
12316 if (SUPPORTS_INTEGRATED_DP(dev
) &&
12317 (I915_READ(DP_D
) & DP_DETECTED
))
12318 intel_dp_init(dev
, DP_D
, PORT_D
);
12319 } else if (IS_GEN2(dev
))
12320 intel_dvo_init(dev
);
12322 if (SUPPORTS_TV(dev
))
12323 intel_tv_init(dev
);
12325 intel_edp_psr_init(dev
);
12327 for_each_intel_encoder(dev
, encoder
) {
12328 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
12329 encoder
->base
.possible_clones
=
12330 intel_encoder_clones(encoder
);
12333 intel_init_pch_refclk(dev
);
12335 drm_helper_move_panel_connectors_to_head(dev
);
12338 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
12340 struct drm_device
*dev
= fb
->dev
;
12341 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
12343 drm_framebuffer_cleanup(fb
);
12344 mutex_lock(&dev
->struct_mutex
);
12345 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
12346 drm_gem_object_unreference(&intel_fb
->obj
->base
);
12347 mutex_unlock(&dev
->struct_mutex
);
12351 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
12352 struct drm_file
*file
,
12353 unsigned int *handle
)
12355 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
12356 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
12358 return drm_gem_handle_create(file
, &obj
->base
, handle
);
12361 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
12362 .destroy
= intel_user_framebuffer_destroy
,
12363 .create_handle
= intel_user_framebuffer_create_handle
,
12366 static int intel_framebuffer_init(struct drm_device
*dev
,
12367 struct intel_framebuffer
*intel_fb
,
12368 struct drm_mode_fb_cmd2
*mode_cmd
,
12369 struct drm_i915_gem_object
*obj
)
12371 int aligned_height
;
12375 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
12377 if (obj
->tiling_mode
== I915_TILING_Y
) {
12378 DRM_DEBUG("hardware does not support tiling Y\n");
12382 if (mode_cmd
->pitches
[0] & 63) {
12383 DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
12384 mode_cmd
->pitches
[0]);
12388 if (INTEL_INFO(dev
)->gen
>= 5 && !IS_VALLEYVIEW(dev
)) {
12389 pitch_limit
= 32*1024;
12390 } else if (INTEL_INFO(dev
)->gen
>= 4) {
12391 if (obj
->tiling_mode
)
12392 pitch_limit
= 16*1024;
12394 pitch_limit
= 32*1024;
12395 } else if (INTEL_INFO(dev
)->gen
>= 3) {
12396 if (obj
->tiling_mode
)
12397 pitch_limit
= 8*1024;
12399 pitch_limit
= 16*1024;
12401 /* XXX DSPC is limited to 4k tiled */
12402 pitch_limit
= 8*1024;
12404 if (mode_cmd
->pitches
[0] > pitch_limit
) {
12405 DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
12406 obj
->tiling_mode
? "tiled" : "linear",
12407 mode_cmd
->pitches
[0], pitch_limit
);
12411 if (obj
->tiling_mode
!= I915_TILING_NONE
&&
12412 mode_cmd
->pitches
[0] != obj
->stride
) {
12413 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
12414 mode_cmd
->pitches
[0], obj
->stride
);
12418 /* Reject formats not supported by any plane early. */
12419 switch (mode_cmd
->pixel_format
) {
12420 case DRM_FORMAT_C8
:
12421 case DRM_FORMAT_RGB565
:
12422 case DRM_FORMAT_XRGB8888
:
12423 case DRM_FORMAT_ARGB8888
:
12425 case DRM_FORMAT_XRGB1555
:
12426 case DRM_FORMAT_ARGB1555
:
12427 if (INTEL_INFO(dev
)->gen
> 3) {
12428 DRM_DEBUG("unsupported pixel format: %s\n",
12429 drm_get_format_name(mode_cmd
->pixel_format
));
12433 case DRM_FORMAT_XBGR8888
:
12434 case DRM_FORMAT_ABGR8888
:
12435 case DRM_FORMAT_XRGB2101010
:
12436 case DRM_FORMAT_ARGB2101010
:
12437 case DRM_FORMAT_XBGR2101010
:
12438 case DRM_FORMAT_ABGR2101010
:
12439 if (INTEL_INFO(dev
)->gen
< 4) {
12440 DRM_DEBUG("unsupported pixel format: %s\n",
12441 drm_get_format_name(mode_cmd
->pixel_format
));
12445 case DRM_FORMAT_YUYV
:
12446 case DRM_FORMAT_UYVY
:
12447 case DRM_FORMAT_YVYU
:
12448 case DRM_FORMAT_VYUY
:
12449 if (INTEL_INFO(dev
)->gen
< 5) {
12450 DRM_DEBUG("unsupported pixel format: %s\n",
12451 drm_get_format_name(mode_cmd
->pixel_format
));
12456 DRM_DEBUG("unsupported pixel format: %s\n",
12457 drm_get_format_name(mode_cmd
->pixel_format
));
12461 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
12462 if (mode_cmd
->offsets
[0] != 0)
12465 aligned_height
= intel_align_height(dev
, mode_cmd
->height
,
12467 /* FIXME drm helper for size checks (especially planar formats)? */
12468 if (obj
->base
.size
< aligned_height
* mode_cmd
->pitches
[0])
12471 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
12472 intel_fb
->obj
= obj
;
12473 intel_fb
->obj
->framebuffer_references
++;
12475 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
12477 DRM_ERROR("framebuffer init failed %d\n", ret
);
12484 static struct drm_framebuffer
*
12485 intel_user_framebuffer_create(struct drm_device
*dev
,
12486 struct drm_file
*filp
,
12487 struct drm_mode_fb_cmd2
*mode_cmd
)
12489 struct drm_i915_gem_object
*obj
;
12491 obj
= to_intel_bo(drm_gem_object_lookup(dev
, filp
,
12492 mode_cmd
->handles
[0]));
12493 if (&obj
->base
== NULL
)
12494 return ERR_PTR(-ENOENT
);
12496 return intel_framebuffer_create(dev
, mode_cmd
, obj
);
12499 #ifndef CONFIG_DRM_I915_FBDEV
12500 static inline void intel_fbdev_output_poll_changed(struct drm_device
*dev
)
12505 static const struct drm_mode_config_funcs intel_mode_funcs
= {
12506 .fb_create
= intel_user_framebuffer_create
,
12507 .output_poll_changed
= intel_fbdev_output_poll_changed
,
12510 /* Set up chip specific display functions */
12511 static void intel_init_display(struct drm_device
*dev
)
12513 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12515 if (HAS_PCH_SPLIT(dev
) || IS_G4X(dev
))
12516 dev_priv
->display
.find_dpll
= g4x_find_best_dpll
;
12517 else if (IS_CHERRYVIEW(dev
))
12518 dev_priv
->display
.find_dpll
= chv_find_best_dpll
;
12519 else if (IS_VALLEYVIEW(dev
))
12520 dev_priv
->display
.find_dpll
= vlv_find_best_dpll
;
12521 else if (IS_PINEVIEW(dev
))
12522 dev_priv
->display
.find_dpll
= pnv_find_best_dpll
;
12524 dev_priv
->display
.find_dpll
= i9xx_find_best_dpll
;
12526 if (HAS_DDI(dev
)) {
12527 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
12528 dev_priv
->display
.get_plane_config
= ironlake_get_plane_config
;
12529 dev_priv
->display
.crtc_mode_set
= haswell_crtc_mode_set
;
12530 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
12531 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
12532 dev_priv
->display
.off
= ironlake_crtc_off
;
12533 dev_priv
->display
.update_primary_plane
=
12534 ironlake_update_primary_plane
;
12535 } else if (HAS_PCH_SPLIT(dev
)) {
12536 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
12537 dev_priv
->display
.get_plane_config
= ironlake_get_plane_config
;
12538 dev_priv
->display
.crtc_mode_set
= ironlake_crtc_mode_set
;
12539 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
12540 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
12541 dev_priv
->display
.off
= ironlake_crtc_off
;
12542 dev_priv
->display
.update_primary_plane
=
12543 ironlake_update_primary_plane
;
12544 } else if (IS_VALLEYVIEW(dev
)) {
12545 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
12546 dev_priv
->display
.get_plane_config
= i9xx_get_plane_config
;
12547 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
12548 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
12549 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
12550 dev_priv
->display
.off
= i9xx_crtc_off
;
12551 dev_priv
->display
.update_primary_plane
=
12552 i9xx_update_primary_plane
;
12554 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
12555 dev_priv
->display
.get_plane_config
= i9xx_get_plane_config
;
12556 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
12557 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
12558 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
12559 dev_priv
->display
.off
= i9xx_crtc_off
;
12560 dev_priv
->display
.update_primary_plane
=
12561 i9xx_update_primary_plane
;
12564 /* Returns the core display clock speed */
12565 if (IS_VALLEYVIEW(dev
))
12566 dev_priv
->display
.get_display_clock_speed
=
12567 valleyview_get_display_clock_speed
;
12568 else if (IS_I945G(dev
) || (IS_G33(dev
) && !IS_PINEVIEW_M(dev
)))
12569 dev_priv
->display
.get_display_clock_speed
=
12570 i945_get_display_clock_speed
;
12571 else if (IS_I915G(dev
))
12572 dev_priv
->display
.get_display_clock_speed
=
12573 i915_get_display_clock_speed
;
12574 else if (IS_I945GM(dev
) || IS_845G(dev
))
12575 dev_priv
->display
.get_display_clock_speed
=
12576 i9xx_misc_get_display_clock_speed
;
12577 else if (IS_PINEVIEW(dev
))
12578 dev_priv
->display
.get_display_clock_speed
=
12579 pnv_get_display_clock_speed
;
12580 else if (IS_I915GM(dev
))
12581 dev_priv
->display
.get_display_clock_speed
=
12582 i915gm_get_display_clock_speed
;
12583 else if (IS_I865G(dev
))
12584 dev_priv
->display
.get_display_clock_speed
=
12585 i865_get_display_clock_speed
;
12586 else if (IS_I85X(dev
))
12587 dev_priv
->display
.get_display_clock_speed
=
12588 i855_get_display_clock_speed
;
12589 else /* 852, 830 */
12590 dev_priv
->display
.get_display_clock_speed
=
12591 i830_get_display_clock_speed
;
12594 dev_priv
->display
.write_eld
= g4x_write_eld
;
12595 } else if (IS_GEN5(dev
)) {
12596 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
12597 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12598 } else if (IS_GEN6(dev
)) {
12599 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
12600 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12601 dev_priv
->display
.modeset_global_resources
=
12602 snb_modeset_global_resources
;
12603 } else if (IS_IVYBRIDGE(dev
)) {
12604 /* FIXME: detect B0+ stepping and use auto training */
12605 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
12606 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12607 dev_priv
->display
.modeset_global_resources
=
12608 ivb_modeset_global_resources
;
12609 } else if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
12610 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
12611 dev_priv
->display
.write_eld
= haswell_write_eld
;
12612 dev_priv
->display
.modeset_global_resources
=
12613 haswell_modeset_global_resources
;
12614 } else if (IS_VALLEYVIEW(dev
)) {
12615 dev_priv
->display
.modeset_global_resources
=
12616 valleyview_modeset_global_resources
;
12617 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12620 /* Default just returns -ENODEV to indicate unsupported */
12621 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
12623 switch (INTEL_INFO(dev
)->gen
) {
12625 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
12629 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
12634 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
12638 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
12641 case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
12642 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
12646 intel_panel_init_backlight_funcs(dev
);
12648 mutex_init(&dev_priv
->pps_mutex
);
12652 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
12653 * resume, or other times. This quirk makes sure that's the case for
12654 * affected systems.
12656 static void quirk_pipea_force(struct drm_device
*dev
)
12658 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12660 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
12661 DRM_INFO("applying pipe a force quirk\n");
12664 static void quirk_pipeb_force(struct drm_device
*dev
)
12666 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12668 dev_priv
->quirks
|= QUIRK_PIPEB_FORCE
;
12669 DRM_INFO("applying pipe b force quirk\n");
12673 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
12675 static void quirk_ssc_force_disable(struct drm_device
*dev
)
12677 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12678 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
12679 DRM_INFO("applying lvds SSC disable quirk\n");
12683 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
12686 static void quirk_invert_brightness(struct drm_device
*dev
)
12688 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12689 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
12690 DRM_INFO("applying inverted panel brightness quirk\n");
12693 /* Some VBT's incorrectly indicate no backlight is present */
12694 static void quirk_backlight_present(struct drm_device
*dev
)
12696 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12697 dev_priv
->quirks
|= QUIRK_BACKLIGHT_PRESENT
;
12698 DRM_INFO("applying backlight present quirk\n");
12701 struct intel_quirk
{
12703 int subsystem_vendor
;
12704 int subsystem_device
;
12705 void (*hook
)(struct drm_device
*dev
);
12708 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
12709 struct intel_dmi_quirk
{
12710 void (*hook
)(struct drm_device
*dev
);
12711 const struct dmi_system_id (*dmi_id_list
)[];
12714 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
12716 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
12720 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
12722 .dmi_id_list
= &(const struct dmi_system_id
[]) {
12724 .callback
= intel_dmi_reverse_brightness
,
12725 .ident
= "NCR Corporation",
12726 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
12727 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
12730 { } /* terminating entry */
12732 .hook
= quirk_invert_brightness
,
12736 static struct intel_quirk intel_quirks
[] = {
12737 /* HP Mini needs pipe A force quirk (LP: #322104) */
12738 { 0x27ae, 0x103c, 0x361a, quirk_pipea_force
},
12740 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
12741 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
12743 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
12744 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
12746 /* 830 needs to leave pipe A & dpll A up */
12747 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
12749 /* 830 needs to leave pipe B & dpll B up */
12750 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipeb_force
},
12752 /* Lenovo U160 cannot use SSC on LVDS */
12753 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
12755 /* Sony Vaio Y cannot use SSC on LVDS */
12756 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
12758 /* Acer Aspire 5734Z must invert backlight brightness */
12759 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
12761 /* Acer/eMachines G725 */
12762 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
12764 /* Acer/eMachines e725 */
12765 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
12767 /* Acer/Packard Bell NCL20 */
12768 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
12770 /* Acer Aspire 4736Z */
12771 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
12773 /* Acer Aspire 5336 */
12774 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
12776 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
12777 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present
},
12779 /* Toshiba CB35 Chromebook (Celeron 2955U) */
12780 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present
},
12782 /* HP Chromebook 14 (Celeron 2955U) */
12783 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present
},
12786 static void intel_init_quirks(struct drm_device
*dev
)
12788 struct pci_dev
*d
= dev
->pdev
;
12791 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
12792 struct intel_quirk
*q
= &intel_quirks
[i
];
12794 if (d
->device
== q
->device
&&
12795 (d
->subsystem_vendor
== q
->subsystem_vendor
||
12796 q
->subsystem_vendor
== PCI_ANY_ID
) &&
12797 (d
->subsystem_device
== q
->subsystem_device
||
12798 q
->subsystem_device
== PCI_ANY_ID
))
12801 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
12802 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
12803 intel_dmi_quirks
[i
].hook(dev
);
12807 /* Disable the VGA plane that we never use */
12808 static void i915_disable_vga(struct drm_device
*dev
)
12810 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12812 u32 vga_reg
= i915_vgacntrl_reg(dev
);
12814 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
12815 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
12816 outb(SR01
, VGA_SR_INDEX
);
12817 sr1
= inb(VGA_SR_DATA
);
12818 outb(sr1
| 1<<5, VGA_SR_DATA
);
12819 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
12823 * Fujitsu-Siemens Lifebook S6010 (830) has problems resuming
12824 * from S3 without preserving (some of?) the other bits.
12826 I915_WRITE(vga_reg
, dev_priv
->bios_vgacntr
| VGA_DISP_DISABLE
);
12827 POSTING_READ(vga_reg
);
12830 void intel_modeset_init_hw(struct drm_device
*dev
)
12832 intel_prepare_ddi(dev
);
12834 if (IS_VALLEYVIEW(dev
))
12835 vlv_update_cdclk(dev
);
12837 intel_init_clock_gating(dev
);
12839 intel_enable_gt_powersave(dev
);
12842 void intel_modeset_suspend_hw(struct drm_device
*dev
)
12844 intel_suspend_hw(dev
);
12847 void intel_modeset_init(struct drm_device
*dev
)
12849 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12852 struct intel_crtc
*crtc
;
12854 drm_mode_config_init(dev
);
12856 dev
->mode_config
.min_width
= 0;
12857 dev
->mode_config
.min_height
= 0;
12859 dev
->mode_config
.preferred_depth
= 24;
12860 dev
->mode_config
.prefer_shadow
= 1;
12862 dev
->mode_config
.funcs
= &intel_mode_funcs
;
12864 intel_init_quirks(dev
);
12866 intel_init_pm(dev
);
12868 if (INTEL_INFO(dev
)->num_pipes
== 0)
12871 intel_init_display(dev
);
12873 if (IS_GEN2(dev
)) {
12874 dev
->mode_config
.max_width
= 2048;
12875 dev
->mode_config
.max_height
= 2048;
12876 } else if (IS_GEN3(dev
)) {
12877 dev
->mode_config
.max_width
= 4096;
12878 dev
->mode_config
.max_height
= 4096;
12880 dev
->mode_config
.max_width
= 8192;
12881 dev
->mode_config
.max_height
= 8192;
12884 if (IS_845G(dev
) || IS_I865G(dev
)) {
12885 dev
->mode_config
.cursor_width
= IS_845G(dev
) ? 64 : 512;
12886 dev
->mode_config
.cursor_height
= 1023;
12887 } else if (IS_GEN2(dev
)) {
12888 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
12889 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
12891 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
12892 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
12895 dev
->mode_config
.fb_base
= dev_priv
->gtt
.mappable_base
;
12897 DRM_DEBUG_KMS("%d display pipe%s available.\n",
12898 INTEL_INFO(dev
)->num_pipes
,
12899 INTEL_INFO(dev
)->num_pipes
> 1 ? "s" : "");
12901 for_each_pipe(dev_priv
, pipe
) {
12902 intel_crtc_init(dev
, pipe
);
12903 for_each_sprite(pipe
, sprite
) {
12904 ret
= intel_plane_init(dev
, pipe
, sprite
);
12906 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
12907 pipe_name(pipe
), sprite_name(pipe
, sprite
), ret
);
12911 intel_init_dpio(dev
);
12913 intel_shared_dpll_init(dev
);
12915 /* save the BIOS value before clobbering it */
12916 dev_priv
->bios_vgacntr
= I915_READ(i915_vgacntrl_reg(dev
));
12917 /* Just disable it once at startup */
12918 i915_disable_vga(dev
);
12919 intel_setup_outputs(dev
);
12921 /* Just in case the BIOS is doing something questionable. */
12922 intel_disable_fbc(dev
);
12924 drm_modeset_lock_all(dev
);
12925 intel_modeset_setup_hw_state(dev
, false);
12926 drm_modeset_unlock_all(dev
);
12928 for_each_intel_crtc(dev
, crtc
) {
12933 * Note that reserving the BIOS fb up front prevents us
12934 * from stuffing other stolen allocations like the ring
12935 * on top. This prevents some ugliness at boot time, and
12936 * can even allow for smooth boot transitions if the BIOS
12937 * fb is large enough for the active pipe configuration.
12939 if (dev_priv
->display
.get_plane_config
) {
12940 dev_priv
->display
.get_plane_config(crtc
,
12941 &crtc
->plane_config
);
12943 * If the fb is shared between multiple heads, we'll
12944 * just get the first one.
12946 intel_find_plane_obj(crtc
, &crtc
->plane_config
);
12951 static void intel_enable_pipe_a(struct drm_device
*dev
)
12953 struct intel_connector
*connector
;
12954 struct drm_connector
*crt
= NULL
;
12955 struct intel_load_detect_pipe load_detect_temp
;
12956 struct drm_modeset_acquire_ctx
*ctx
= dev
->mode_config
.acquire_ctx
;
12958 /* We can't just switch on the pipe A, we need to set things up with a
12959 * proper mode and output configuration. As a gross hack, enable pipe A
12960 * by enabling the load detect pipe once. */
12961 list_for_each_entry(connector
,
12962 &dev
->mode_config
.connector_list
,
12964 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
12965 crt
= &connector
->base
;
12973 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
, ctx
))
12974 intel_release_load_detect_pipe(crt
, &load_detect_temp
);
12978 intel_check_plane_mapping(struct intel_crtc
*crtc
)
12980 struct drm_device
*dev
= crtc
->base
.dev
;
12981 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12984 if (INTEL_INFO(dev
)->num_pipes
== 1)
12987 reg
= DSPCNTR(!crtc
->plane
);
12988 val
= I915_READ(reg
);
12990 if ((val
& DISPLAY_PLANE_ENABLE
) &&
12991 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
12997 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
12999 struct drm_device
*dev
= crtc
->base
.dev
;
13000 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13003 /* Clear any frame start delays used for debugging left by the BIOS */
13004 reg
= PIPECONF(crtc
->config
.cpu_transcoder
);
13005 I915_WRITE(reg
, I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
13007 /* restore vblank interrupts to correct state */
13009 drm_vblank_on(dev
, crtc
->pipe
);
13011 drm_vblank_off(dev
, crtc
->pipe
);
13013 /* We need to sanitize the plane -> pipe mapping first because this will
13014 * disable the crtc (and hence change the state) if it is wrong. Note
13015 * that gen4+ has a fixed plane -> pipe mapping. */
13016 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
13017 struct intel_connector
*connector
;
13020 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
13021 crtc
->base
.base
.id
);
13023 /* Pipe has the wrong plane attached and the plane is active.
13024 * Temporarily change the plane mapping and disable everything
13026 plane
= crtc
->plane
;
13027 crtc
->plane
= !plane
;
13028 crtc
->primary_enabled
= true;
13029 dev_priv
->display
.crtc_disable(&crtc
->base
);
13030 crtc
->plane
= plane
;
13032 /* ... and break all links. */
13033 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
13035 if (connector
->encoder
->base
.crtc
!= &crtc
->base
)
13038 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
13039 connector
->base
.encoder
= NULL
;
13041 /* multiple connectors may have the same encoder:
13042 * handle them and break crtc link separately */
13043 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
13045 if (connector
->encoder
->base
.crtc
== &crtc
->base
) {
13046 connector
->encoder
->base
.crtc
= NULL
;
13047 connector
->encoder
->connectors_active
= false;
13050 WARN_ON(crtc
->active
);
13051 crtc
->base
.enabled
= false;
13054 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
13055 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
13056 /* BIOS forgot to enable pipe A, this mostly happens after
13057 * resume. Force-enable the pipe to fix this, the update_dpms
13058 * call below we restore the pipe to the right state, but leave
13059 * the required bits on. */
13060 intel_enable_pipe_a(dev
);
13063 /* Adjust the state of the output pipe according to whether we
13064 * have active connectors/encoders. */
13065 intel_crtc_update_dpms(&crtc
->base
);
13067 if (crtc
->active
!= crtc
->base
.enabled
) {
13068 struct intel_encoder
*encoder
;
13070 /* This can happen either due to bugs in the get_hw_state
13071 * functions or because the pipe is force-enabled due to the
13073 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
13074 crtc
->base
.base
.id
,
13075 crtc
->base
.enabled
? "enabled" : "disabled",
13076 crtc
->active
? "enabled" : "disabled");
13078 crtc
->base
.enabled
= crtc
->active
;
13080 /* Because we only establish the connector -> encoder ->
13081 * crtc links if something is active, this means the
13082 * crtc is now deactivated. Break the links. connector
13083 * -> encoder links are only establish when things are
13084 * actually up, hence no need to break them. */
13085 WARN_ON(crtc
->active
);
13087 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
13088 WARN_ON(encoder
->connectors_active
);
13089 encoder
->base
.crtc
= NULL
;
13093 if (crtc
->active
|| HAS_GMCH_DISPLAY(dev
)) {
13095 * We start out with underrun reporting disabled to avoid races.
13096 * For correct bookkeeping mark this on active crtcs.
13098 * Also on gmch platforms we dont have any hardware bits to
13099 * disable the underrun reporting. Which means we need to start
13100 * out with underrun reporting disabled also on inactive pipes,
13101 * since otherwise we'll complain about the garbage we read when
13102 * e.g. coming up after runtime pm.
13104 * No protection against concurrent access is required - at
13105 * worst a fifo underrun happens which also sets this to false.
13107 crtc
->cpu_fifo_underrun_disabled
= true;
13108 crtc
->pch_fifo_underrun_disabled
= true;
13110 update_scanline_offset(crtc
);
13114 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
13116 struct intel_connector
*connector
;
13117 struct drm_device
*dev
= encoder
->base
.dev
;
13119 /* We need to check both for a crtc link (meaning that the
13120 * encoder is active and trying to read from a pipe) and the
13121 * pipe itself being active. */
13122 bool has_active_crtc
= encoder
->base
.crtc
&&
13123 to_intel_crtc(encoder
->base
.crtc
)->active
;
13125 if (encoder
->connectors_active
&& !has_active_crtc
) {
13126 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
13127 encoder
->base
.base
.id
,
13128 encoder
->base
.name
);
13130 /* Connector is active, but has no active pipe. This is
13131 * fallout from our resume register restoring. Disable
13132 * the encoder manually again. */
13133 if (encoder
->base
.crtc
) {
13134 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
13135 encoder
->base
.base
.id
,
13136 encoder
->base
.name
);
13137 encoder
->disable(encoder
);
13138 if (encoder
->post_disable
)
13139 encoder
->post_disable(encoder
);
13141 encoder
->base
.crtc
= NULL
;
13142 encoder
->connectors_active
= false;
13144 /* Inconsistent output/port/pipe state happens presumably due to
13145 * a bug in one of the get_hw_state functions. Or someplace else
13146 * in our code, like the register restore mess on resume. Clamp
13147 * things to off as a safer default. */
13148 list_for_each_entry(connector
,
13149 &dev
->mode_config
.connector_list
,
13151 if (connector
->encoder
!= encoder
)
13153 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
13154 connector
->base
.encoder
= NULL
;
13157 /* Enabled encoders without active connectors will be fixed in
13158 * the crtc fixup. */
13161 void i915_redisable_vga_power_on(struct drm_device
*dev
)
13163 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13164 u32 vga_reg
= i915_vgacntrl_reg(dev
);
13166 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
13167 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
13168 i915_disable_vga(dev
);
13172 void i915_redisable_vga(struct drm_device
*dev
)
13174 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13176 /* This function can be called both from intel_modeset_setup_hw_state or
13177 * at a very early point in our resume sequence, where the power well
13178 * structures are not yet restored. Since this function is at a very
13179 * paranoid "someone might have enabled VGA while we were not looking"
13180 * level, just check if the power well is enabled instead of trying to
13181 * follow the "don't touch the power well if we don't need it" policy
13182 * the rest of the driver uses. */
13183 if (!intel_display_power_enabled(dev_priv
, POWER_DOMAIN_VGA
))
13186 i915_redisable_vga_power_on(dev
);
13189 static bool primary_get_hw_state(struct intel_crtc
*crtc
)
13191 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
13196 return I915_READ(DSPCNTR(crtc
->plane
)) & DISPLAY_PLANE_ENABLE
;
13199 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
13201 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13203 struct intel_crtc
*crtc
;
13204 struct intel_encoder
*encoder
;
13205 struct intel_connector
*connector
;
13208 for_each_intel_crtc(dev
, crtc
) {
13209 memset(&crtc
->config
, 0, sizeof(crtc
->config
));
13211 crtc
->config
.quirks
|= PIPE_CONFIG_QUIRK_INHERITED_MODE
;
13213 crtc
->active
= dev_priv
->display
.get_pipe_config(crtc
,
13216 crtc
->base
.enabled
= crtc
->active
;
13217 crtc
->primary_enabled
= primary_get_hw_state(crtc
);
13219 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
13220 crtc
->base
.base
.id
,
13221 crtc
->active
? "enabled" : "disabled");
13224 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
13225 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
13227 pll
->on
= pll
->get_hw_state(dev_priv
, pll
, &pll
->hw_state
);
13229 for_each_intel_crtc(dev
, crtc
) {
13230 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
13233 pll
->refcount
= pll
->active
;
13235 DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n",
13236 pll
->name
, pll
->refcount
, pll
->on
);
13239 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
13242 for_each_intel_encoder(dev
, encoder
) {
13245 if (encoder
->get_hw_state(encoder
, &pipe
)) {
13246 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
13247 encoder
->base
.crtc
= &crtc
->base
;
13248 encoder
->get_config(encoder
, &crtc
->config
);
13250 encoder
->base
.crtc
= NULL
;
13253 encoder
->connectors_active
= false;
13254 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
13255 encoder
->base
.base
.id
,
13256 encoder
->base
.name
,
13257 encoder
->base
.crtc
? "enabled" : "disabled",
13261 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
13263 if (connector
->get_hw_state(connector
)) {
13264 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
13265 connector
->encoder
->connectors_active
= true;
13266 connector
->base
.encoder
= &connector
->encoder
->base
;
13268 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
13269 connector
->base
.encoder
= NULL
;
13271 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
13272 connector
->base
.base
.id
,
13273 connector
->base
.name
,
13274 connector
->base
.encoder
? "enabled" : "disabled");
13278 /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
13279 * and i915 state tracking structures. */
13280 void intel_modeset_setup_hw_state(struct drm_device
*dev
,
13281 bool force_restore
)
13283 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13285 struct intel_crtc
*crtc
;
13286 struct intel_encoder
*encoder
;
13289 intel_modeset_readout_hw_state(dev
);
13292 * Now that we have the config, copy it to each CRTC struct
13293 * Note that this could go away if we move to using crtc_config
13294 * checking everywhere.
13296 for_each_intel_crtc(dev
, crtc
) {
13297 if (crtc
->active
&& i915
.fastboot
) {
13298 intel_mode_from_pipe_config(&crtc
->base
.mode
, &crtc
->config
);
13299 DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
13300 crtc
->base
.base
.id
);
13301 drm_mode_debug_printmodeline(&crtc
->base
.mode
);
13305 /* HW state is read out, now we need to sanitize this mess. */
13306 for_each_intel_encoder(dev
, encoder
) {
13307 intel_sanitize_encoder(encoder
);
13310 for_each_pipe(dev_priv
, pipe
) {
13311 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
13312 intel_sanitize_crtc(crtc
);
13313 intel_dump_pipe_config(crtc
, &crtc
->config
, "[setup_hw_state]");
13316 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
13317 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
13319 if (!pll
->on
|| pll
->active
)
13322 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
13324 pll
->disable(dev_priv
, pll
);
13328 if (HAS_PCH_SPLIT(dev
))
13329 ilk_wm_get_hw_state(dev
);
13331 if (force_restore
) {
13332 i915_redisable_vga(dev
);
13335 * We need to use raw interfaces for restoring state to avoid
13336 * checking (bogus) intermediate states.
13338 for_each_pipe(dev_priv
, pipe
) {
13339 struct drm_crtc
*crtc
=
13340 dev_priv
->pipe_to_crtc_mapping
[pipe
];
13342 __intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
,
13343 crtc
->primary
->fb
);
13346 intel_modeset_update_staged_output_state(dev
);
13349 intel_modeset_check_state(dev
);
13352 void intel_modeset_gem_init(struct drm_device
*dev
)
13354 struct drm_crtc
*c
;
13355 struct drm_i915_gem_object
*obj
;
13357 mutex_lock(&dev
->struct_mutex
);
13358 intel_init_gt_powersave(dev
);
13359 mutex_unlock(&dev
->struct_mutex
);
13361 intel_modeset_init_hw(dev
);
13363 intel_setup_overlay(dev
);
13366 * Make sure any fbs we allocated at startup are properly
13367 * pinned & fenced. When we do the allocation it's too early
13370 mutex_lock(&dev
->struct_mutex
);
13371 for_each_crtc(dev
, c
) {
13372 obj
= intel_fb_obj(c
->primary
->fb
);
13376 if (intel_pin_and_fence_fb_obj(dev
, obj
, NULL
)) {
13377 DRM_ERROR("failed to pin boot fb on pipe %d\n",
13378 to_intel_crtc(c
)->pipe
);
13379 drm_framebuffer_unreference(c
->primary
->fb
);
13380 c
->primary
->fb
= NULL
;
13383 mutex_unlock(&dev
->struct_mutex
);
13386 void intel_connector_unregister(struct intel_connector
*intel_connector
)
13388 struct drm_connector
*connector
= &intel_connector
->base
;
13390 intel_panel_destroy_backlight(connector
);
13391 drm_connector_unregister(connector
);
13394 void intel_modeset_cleanup(struct drm_device
*dev
)
13396 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13397 struct drm_connector
*connector
;
13400 * Interrupts and polling as the first thing to avoid creating havoc.
13401 * Too much stuff here (turning of rps, connectors, ...) would
13402 * experience fancy races otherwise.
13404 drm_irq_uninstall(dev
);
13405 intel_hpd_cancel_work(dev_priv
);
13406 dev_priv
->pm
._irqs_disabled
= true;
13409 * Due to the hpd irq storm handling the hotplug work can re-arm the
13410 * poll handlers. Hence disable polling after hpd handling is shut down.
13412 drm_kms_helper_poll_fini(dev
);
13414 mutex_lock(&dev
->struct_mutex
);
13416 intel_unregister_dsm_handler();
13418 intel_disable_fbc(dev
);
13420 intel_disable_gt_powersave(dev
);
13422 ironlake_teardown_rc6(dev
);
13424 mutex_unlock(&dev
->struct_mutex
);
13426 /* flush any delayed tasks or pending work */
13427 flush_scheduled_work();
13429 /* destroy the backlight and sysfs files before encoders/connectors */
13430 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
13431 struct intel_connector
*intel_connector
;
13433 intel_connector
= to_intel_connector(connector
);
13434 intel_connector
->unregister(intel_connector
);
13437 drm_mode_config_cleanup(dev
);
13439 intel_cleanup_overlay(dev
);
13441 mutex_lock(&dev
->struct_mutex
);
13442 intel_cleanup_gt_powersave(dev
);
13443 mutex_unlock(&dev
->struct_mutex
);
13447 * Return which encoder is currently attached for connector.
13449 struct drm_encoder
*intel_best_encoder(struct drm_connector
*connector
)
13451 return &intel_attached_encoder(connector
)->base
;
13454 void intel_connector_attach_encoder(struct intel_connector
*connector
,
13455 struct intel_encoder
*encoder
)
13457 connector
->encoder
= encoder
;
13458 drm_mode_connector_attach_encoder(&connector
->base
,
13463 * set vga decode state - true == enable VGA decode
13465 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
13467 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13468 unsigned reg
= INTEL_INFO(dev
)->gen
>= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
13471 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
13472 DRM_ERROR("failed to read control word\n");
13476 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
13480 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
13482 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
13484 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
13485 DRM_ERROR("failed to write control word\n");
13492 struct intel_display_error_state
{
13494 u32 power_well_driver
;
13496 int num_transcoders
;
13498 struct intel_cursor_error_state
{
13503 } cursor
[I915_MAX_PIPES
];
13505 struct intel_pipe_error_state
{
13506 bool power_domain_on
;
13509 } pipe
[I915_MAX_PIPES
];
13511 struct intel_plane_error_state
{
13519 } plane
[I915_MAX_PIPES
];
13521 struct intel_transcoder_error_state
{
13522 bool power_domain_on
;
13523 enum transcoder cpu_transcoder
;
13536 struct intel_display_error_state
*
13537 intel_display_capture_error_state(struct drm_device
*dev
)
13539 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13540 struct intel_display_error_state
*error
;
13541 int transcoders
[] = {
13549 if (INTEL_INFO(dev
)->num_pipes
== 0)
13552 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
13556 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
13557 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
13559 for_each_pipe(dev_priv
, i
) {
13560 error
->pipe
[i
].power_domain_on
=
13561 intel_display_power_enabled_unlocked(dev_priv
,
13562 POWER_DOMAIN_PIPE(i
));
13563 if (!error
->pipe
[i
].power_domain_on
)
13566 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
13567 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
13568 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
13570 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
13571 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
13572 if (INTEL_INFO(dev
)->gen
<= 3) {
13573 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
13574 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
13576 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
13577 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
13578 if (INTEL_INFO(dev
)->gen
>= 4) {
13579 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
13580 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
13583 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
13585 if (HAS_GMCH_DISPLAY(dev
))
13586 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
13589 error
->num_transcoders
= INTEL_INFO(dev
)->num_pipes
;
13590 if (HAS_DDI(dev_priv
->dev
))
13591 error
->num_transcoders
++; /* Account for eDP. */
13593 for (i
= 0; i
< error
->num_transcoders
; i
++) {
13594 enum transcoder cpu_transcoder
= transcoders
[i
];
13596 error
->transcoder
[i
].power_domain_on
=
13597 intel_display_power_enabled_unlocked(dev_priv
,
13598 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
13599 if (!error
->transcoder
[i
].power_domain_on
)
13602 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
13604 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
13605 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
13606 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
13607 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
13608 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
13609 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
13610 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
13616 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
13619 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
13620 struct drm_device
*dev
,
13621 struct intel_display_error_state
*error
)
13623 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13629 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev
)->num_pipes
);
13630 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
13631 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
13632 error
->power_well_driver
);
13633 for_each_pipe(dev_priv
, i
) {
13634 err_printf(m
, "Pipe [%d]:\n", i
);
13635 err_printf(m
, " Power: %s\n",
13636 error
->pipe
[i
].power_domain_on
? "on" : "off");
13637 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
13638 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
13640 err_printf(m
, "Plane [%d]:\n", i
);
13641 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
13642 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
13643 if (INTEL_INFO(dev
)->gen
<= 3) {
13644 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
13645 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
13647 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
13648 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
13649 if (INTEL_INFO(dev
)->gen
>= 4) {
13650 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
13651 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
13654 err_printf(m
, "Cursor [%d]:\n", i
);
13655 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
13656 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
13657 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
13660 for (i
= 0; i
< error
->num_transcoders
; i
++) {
13661 err_printf(m
, "CPU transcoder: %c\n",
13662 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
13663 err_printf(m
, " Power: %s\n",
13664 error
->transcoder
[i
].power_domain_on
? "on" : "off");
13665 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
13666 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
13667 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
13668 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
13669 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
13670 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
13671 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);
13675 void intel_modeset_preclose(struct drm_device
*dev
, struct drm_file
*file
)
13677 struct intel_crtc
*crtc
;
13679 for_each_intel_crtc(dev
, crtc
) {
13680 struct intel_unpin_work
*work
;
13681 unsigned long irqflags
;
13683 spin_lock_irqsave(&dev
->event_lock
, irqflags
);
13685 work
= crtc
->unpin_work
;
13687 if (work
&& work
->event
&&
13688 work
->event
->base
.file_priv
== file
) {
13689 kfree(work
->event
);
13690 work
->event
= NULL
;
13693 spin_unlock_irqrestore(&dev
->event_lock
, irqflags
);