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 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
, bool on
);
78 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
79 struct intel_crtc_config
*pipe_config
);
80 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
81 struct intel_crtc_config
*pipe_config
);
83 static int intel_set_mode(struct drm_crtc
*crtc
, struct drm_display_mode
*mode
,
84 int x
, int y
, struct drm_framebuffer
*old_fb
);
85 static int intel_framebuffer_init(struct drm_device
*dev
,
86 struct intel_framebuffer
*ifb
,
87 struct drm_mode_fb_cmd2
*mode_cmd
,
88 struct drm_i915_gem_object
*obj
);
89 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
);
90 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
);
91 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
92 struct intel_link_m_n
*m_n
,
93 struct intel_link_m_n
*m2_n2
);
94 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
);
95 static void haswell_set_pipeconf(struct drm_crtc
*crtc
);
96 static void intel_set_pipe_csc(struct drm_crtc
*crtc
);
97 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
98 const struct intel_crtc_config
*pipe_config
);
99 static void chv_prepare_pll(struct intel_crtc
*crtc
,
100 const struct intel_crtc_config
*pipe_config
);
102 static struct intel_encoder
*intel_find_encoder(struct intel_connector
*connector
, int pipe
)
104 if (!connector
->mst_port
)
105 return connector
->encoder
;
107 return &connector
->mst_port
->mst_encoders
[pipe
]->base
;
116 int p2_slow
, p2_fast
;
119 typedef struct intel_limit intel_limit_t
;
121 intel_range_t dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
126 intel_pch_rawclk(struct drm_device
*dev
)
128 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
130 WARN_ON(!HAS_PCH_SPLIT(dev
));
132 return I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
;
135 static inline u32
/* units of 100MHz */
136 intel_fdi_link_freq(struct drm_device
*dev
)
139 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
140 return (I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2;
145 static const intel_limit_t intel_limits_i8xx_dac
= {
146 .dot
= { .min
= 25000, .max
= 350000 },
147 .vco
= { .min
= 908000, .max
= 1512000 },
148 .n
= { .min
= 2, .max
= 16 },
149 .m
= { .min
= 96, .max
= 140 },
150 .m1
= { .min
= 18, .max
= 26 },
151 .m2
= { .min
= 6, .max
= 16 },
152 .p
= { .min
= 4, .max
= 128 },
153 .p1
= { .min
= 2, .max
= 33 },
154 .p2
= { .dot_limit
= 165000,
155 .p2_slow
= 4, .p2_fast
= 2 },
158 static const intel_limit_t intel_limits_i8xx_dvo
= {
159 .dot
= { .min
= 25000, .max
= 350000 },
160 .vco
= { .min
= 908000, .max
= 1512000 },
161 .n
= { .min
= 2, .max
= 16 },
162 .m
= { .min
= 96, .max
= 140 },
163 .m1
= { .min
= 18, .max
= 26 },
164 .m2
= { .min
= 6, .max
= 16 },
165 .p
= { .min
= 4, .max
= 128 },
166 .p1
= { .min
= 2, .max
= 33 },
167 .p2
= { .dot_limit
= 165000,
168 .p2_slow
= 4, .p2_fast
= 4 },
171 static const intel_limit_t intel_limits_i8xx_lvds
= {
172 .dot
= { .min
= 25000, .max
= 350000 },
173 .vco
= { .min
= 908000, .max
= 1512000 },
174 .n
= { .min
= 2, .max
= 16 },
175 .m
= { .min
= 96, .max
= 140 },
176 .m1
= { .min
= 18, .max
= 26 },
177 .m2
= { .min
= 6, .max
= 16 },
178 .p
= { .min
= 4, .max
= 128 },
179 .p1
= { .min
= 1, .max
= 6 },
180 .p2
= { .dot_limit
= 165000,
181 .p2_slow
= 14, .p2_fast
= 7 },
184 static const intel_limit_t intel_limits_i9xx_sdvo
= {
185 .dot
= { .min
= 20000, .max
= 400000 },
186 .vco
= { .min
= 1400000, .max
= 2800000 },
187 .n
= { .min
= 1, .max
= 6 },
188 .m
= { .min
= 70, .max
= 120 },
189 .m1
= { .min
= 8, .max
= 18 },
190 .m2
= { .min
= 3, .max
= 7 },
191 .p
= { .min
= 5, .max
= 80 },
192 .p1
= { .min
= 1, .max
= 8 },
193 .p2
= { .dot_limit
= 200000,
194 .p2_slow
= 10, .p2_fast
= 5 },
197 static const intel_limit_t intel_limits_i9xx_lvds
= {
198 .dot
= { .min
= 20000, .max
= 400000 },
199 .vco
= { .min
= 1400000, .max
= 2800000 },
200 .n
= { .min
= 1, .max
= 6 },
201 .m
= { .min
= 70, .max
= 120 },
202 .m1
= { .min
= 8, .max
= 18 },
203 .m2
= { .min
= 3, .max
= 7 },
204 .p
= { .min
= 7, .max
= 98 },
205 .p1
= { .min
= 1, .max
= 8 },
206 .p2
= { .dot_limit
= 112000,
207 .p2_slow
= 14, .p2_fast
= 7 },
211 static const intel_limit_t intel_limits_g4x_sdvo
= {
212 .dot
= { .min
= 25000, .max
= 270000 },
213 .vco
= { .min
= 1750000, .max
= 3500000},
214 .n
= { .min
= 1, .max
= 4 },
215 .m
= { .min
= 104, .max
= 138 },
216 .m1
= { .min
= 17, .max
= 23 },
217 .m2
= { .min
= 5, .max
= 11 },
218 .p
= { .min
= 10, .max
= 30 },
219 .p1
= { .min
= 1, .max
= 3},
220 .p2
= { .dot_limit
= 270000,
226 static const intel_limit_t intel_limits_g4x_hdmi
= {
227 .dot
= { .min
= 22000, .max
= 400000 },
228 .vco
= { .min
= 1750000, .max
= 3500000},
229 .n
= { .min
= 1, .max
= 4 },
230 .m
= { .min
= 104, .max
= 138 },
231 .m1
= { .min
= 16, .max
= 23 },
232 .m2
= { .min
= 5, .max
= 11 },
233 .p
= { .min
= 5, .max
= 80 },
234 .p1
= { .min
= 1, .max
= 8},
235 .p2
= { .dot_limit
= 165000,
236 .p2_slow
= 10, .p2_fast
= 5 },
239 static const intel_limit_t intel_limits_g4x_single_channel_lvds
= {
240 .dot
= { .min
= 20000, .max
= 115000 },
241 .vco
= { .min
= 1750000, .max
= 3500000 },
242 .n
= { .min
= 1, .max
= 3 },
243 .m
= { .min
= 104, .max
= 138 },
244 .m1
= { .min
= 17, .max
= 23 },
245 .m2
= { .min
= 5, .max
= 11 },
246 .p
= { .min
= 28, .max
= 112 },
247 .p1
= { .min
= 2, .max
= 8 },
248 .p2
= { .dot_limit
= 0,
249 .p2_slow
= 14, .p2_fast
= 14
253 static const intel_limit_t intel_limits_g4x_dual_channel_lvds
= {
254 .dot
= { .min
= 80000, .max
= 224000 },
255 .vco
= { .min
= 1750000, .max
= 3500000 },
256 .n
= { .min
= 1, .max
= 3 },
257 .m
= { .min
= 104, .max
= 138 },
258 .m1
= { .min
= 17, .max
= 23 },
259 .m2
= { .min
= 5, .max
= 11 },
260 .p
= { .min
= 14, .max
= 42 },
261 .p1
= { .min
= 2, .max
= 6 },
262 .p2
= { .dot_limit
= 0,
263 .p2_slow
= 7, .p2_fast
= 7
267 static const intel_limit_t intel_limits_pineview_sdvo
= {
268 .dot
= { .min
= 20000, .max
= 400000},
269 .vco
= { .min
= 1700000, .max
= 3500000 },
270 /* Pineview's Ncounter is a ring counter */
271 .n
= { .min
= 3, .max
= 6 },
272 .m
= { .min
= 2, .max
= 256 },
273 /* Pineview only has one combined m divider, which we treat as m2. */
274 .m1
= { .min
= 0, .max
= 0 },
275 .m2
= { .min
= 0, .max
= 254 },
276 .p
= { .min
= 5, .max
= 80 },
277 .p1
= { .min
= 1, .max
= 8 },
278 .p2
= { .dot_limit
= 200000,
279 .p2_slow
= 10, .p2_fast
= 5 },
282 static const intel_limit_t intel_limits_pineview_lvds
= {
283 .dot
= { .min
= 20000, .max
= 400000 },
284 .vco
= { .min
= 1700000, .max
= 3500000 },
285 .n
= { .min
= 3, .max
= 6 },
286 .m
= { .min
= 2, .max
= 256 },
287 .m1
= { .min
= 0, .max
= 0 },
288 .m2
= { .min
= 0, .max
= 254 },
289 .p
= { .min
= 7, .max
= 112 },
290 .p1
= { .min
= 1, .max
= 8 },
291 .p2
= { .dot_limit
= 112000,
292 .p2_slow
= 14, .p2_fast
= 14 },
295 /* Ironlake / Sandybridge
297 * We calculate clock using (register_value + 2) for N/M1/M2, so here
298 * the range value for them is (actual_value - 2).
300 static const intel_limit_t intel_limits_ironlake_dac
= {
301 .dot
= { .min
= 25000, .max
= 350000 },
302 .vco
= { .min
= 1760000, .max
= 3510000 },
303 .n
= { .min
= 1, .max
= 5 },
304 .m
= { .min
= 79, .max
= 127 },
305 .m1
= { .min
= 12, .max
= 22 },
306 .m2
= { .min
= 5, .max
= 9 },
307 .p
= { .min
= 5, .max
= 80 },
308 .p1
= { .min
= 1, .max
= 8 },
309 .p2
= { .dot_limit
= 225000,
310 .p2_slow
= 10, .p2_fast
= 5 },
313 static const intel_limit_t intel_limits_ironlake_single_lvds
= {
314 .dot
= { .min
= 25000, .max
= 350000 },
315 .vco
= { .min
= 1760000, .max
= 3510000 },
316 .n
= { .min
= 1, .max
= 3 },
317 .m
= { .min
= 79, .max
= 118 },
318 .m1
= { .min
= 12, .max
= 22 },
319 .m2
= { .min
= 5, .max
= 9 },
320 .p
= { .min
= 28, .max
= 112 },
321 .p1
= { .min
= 2, .max
= 8 },
322 .p2
= { .dot_limit
= 225000,
323 .p2_slow
= 14, .p2_fast
= 14 },
326 static const intel_limit_t intel_limits_ironlake_dual_lvds
= {
327 .dot
= { .min
= 25000, .max
= 350000 },
328 .vco
= { .min
= 1760000, .max
= 3510000 },
329 .n
= { .min
= 1, .max
= 3 },
330 .m
= { .min
= 79, .max
= 127 },
331 .m1
= { .min
= 12, .max
= 22 },
332 .m2
= { .min
= 5, .max
= 9 },
333 .p
= { .min
= 14, .max
= 56 },
334 .p1
= { .min
= 2, .max
= 8 },
335 .p2
= { .dot_limit
= 225000,
336 .p2_slow
= 7, .p2_fast
= 7 },
339 /* LVDS 100mhz refclk limits. */
340 static const intel_limit_t intel_limits_ironlake_single_lvds_100m
= {
341 .dot
= { .min
= 25000, .max
= 350000 },
342 .vco
= { .min
= 1760000, .max
= 3510000 },
343 .n
= { .min
= 1, .max
= 2 },
344 .m
= { .min
= 79, .max
= 126 },
345 .m1
= { .min
= 12, .max
= 22 },
346 .m2
= { .min
= 5, .max
= 9 },
347 .p
= { .min
= 28, .max
= 112 },
348 .p1
= { .min
= 2, .max
= 8 },
349 .p2
= { .dot_limit
= 225000,
350 .p2_slow
= 14, .p2_fast
= 14 },
353 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m
= {
354 .dot
= { .min
= 25000, .max
= 350000 },
355 .vco
= { .min
= 1760000, .max
= 3510000 },
356 .n
= { .min
= 1, .max
= 3 },
357 .m
= { .min
= 79, .max
= 126 },
358 .m1
= { .min
= 12, .max
= 22 },
359 .m2
= { .min
= 5, .max
= 9 },
360 .p
= { .min
= 14, .max
= 42 },
361 .p1
= { .min
= 2, .max
= 6 },
362 .p2
= { .dot_limit
= 225000,
363 .p2_slow
= 7, .p2_fast
= 7 },
366 static const intel_limit_t intel_limits_vlv
= {
368 * These are the data rate limits (measured in fast clocks)
369 * since those are the strictest limits we have. The fast
370 * clock and actual rate limits are more relaxed, so checking
371 * them would make no difference.
373 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
374 .vco
= { .min
= 4000000, .max
= 6000000 },
375 .n
= { .min
= 1, .max
= 7 },
376 .m1
= { .min
= 2, .max
= 3 },
377 .m2
= { .min
= 11, .max
= 156 },
378 .p1
= { .min
= 2, .max
= 3 },
379 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
382 static const intel_limit_t intel_limits_chv
= {
384 * These are the data rate limits (measured in fast clocks)
385 * since those are the strictest limits we have. The fast
386 * clock and actual rate limits are more relaxed, so checking
387 * them would make no difference.
389 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
390 .vco
= { .min
= 4860000, .max
= 6700000 },
391 .n
= { .min
= 1, .max
= 1 },
392 .m1
= { .min
= 2, .max
= 2 },
393 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
394 .p1
= { .min
= 2, .max
= 4 },
395 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
398 static void vlv_clock(int refclk
, intel_clock_t
*clock
)
400 clock
->m
= clock
->m1
* clock
->m2
;
401 clock
->p
= clock
->p1
* clock
->p2
;
402 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
404 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
405 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
409 * Returns whether any output on the specified pipe is of the specified type
411 bool intel_pipe_has_type(struct intel_crtc
*crtc
, int type
)
413 struct drm_device
*dev
= crtc
->base
.dev
;
414 struct intel_encoder
*encoder
;
416 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
417 if (encoder
->type
== type
)
423 static const intel_limit_t
*intel_ironlake_limit(struct intel_crtc
*crtc
,
426 struct drm_device
*dev
= crtc
->base
.dev
;
427 const intel_limit_t
*limit
;
429 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
430 if (intel_is_dual_link_lvds(dev
)) {
431 if (refclk
== 100000)
432 limit
= &intel_limits_ironlake_dual_lvds_100m
;
434 limit
= &intel_limits_ironlake_dual_lvds
;
436 if (refclk
== 100000)
437 limit
= &intel_limits_ironlake_single_lvds_100m
;
439 limit
= &intel_limits_ironlake_single_lvds
;
442 limit
= &intel_limits_ironlake_dac
;
447 static const intel_limit_t
*intel_g4x_limit(struct intel_crtc
*crtc
)
449 struct drm_device
*dev
= crtc
->base
.dev
;
450 const intel_limit_t
*limit
;
452 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
453 if (intel_is_dual_link_lvds(dev
))
454 limit
= &intel_limits_g4x_dual_channel_lvds
;
456 limit
= &intel_limits_g4x_single_channel_lvds
;
457 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
) ||
458 intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
)) {
459 limit
= &intel_limits_g4x_hdmi
;
460 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
)) {
461 limit
= &intel_limits_g4x_sdvo
;
462 } else /* The option is for other outputs */
463 limit
= &intel_limits_i9xx_sdvo
;
468 static const intel_limit_t
*intel_limit(struct intel_crtc
*crtc
, int refclk
)
470 struct drm_device
*dev
= crtc
->base
.dev
;
471 const intel_limit_t
*limit
;
473 if (HAS_PCH_SPLIT(dev
))
474 limit
= intel_ironlake_limit(crtc
, refclk
);
475 else if (IS_G4X(dev
)) {
476 limit
= intel_g4x_limit(crtc
);
477 } else if (IS_PINEVIEW(dev
)) {
478 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
479 limit
= &intel_limits_pineview_lvds
;
481 limit
= &intel_limits_pineview_sdvo
;
482 } else if (IS_CHERRYVIEW(dev
)) {
483 limit
= &intel_limits_chv
;
484 } else if (IS_VALLEYVIEW(dev
)) {
485 limit
= &intel_limits_vlv
;
486 } else if (!IS_GEN2(dev
)) {
487 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
488 limit
= &intel_limits_i9xx_lvds
;
490 limit
= &intel_limits_i9xx_sdvo
;
492 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
493 limit
= &intel_limits_i8xx_lvds
;
494 else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
))
495 limit
= &intel_limits_i8xx_dvo
;
497 limit
= &intel_limits_i8xx_dac
;
502 /* m1 is reserved as 0 in Pineview, n is a ring counter */
503 static void pineview_clock(int refclk
, intel_clock_t
*clock
)
505 clock
->m
= clock
->m2
+ 2;
506 clock
->p
= clock
->p1
* clock
->p2
;
507 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
509 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
510 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
513 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
515 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
518 static void i9xx_clock(int refclk
, intel_clock_t
*clock
)
520 clock
->m
= i9xx_dpll_compute_m(clock
);
521 clock
->p
= clock
->p1
* clock
->p2
;
522 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
524 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
525 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
528 static void chv_clock(int refclk
, intel_clock_t
*clock
)
530 clock
->m
= clock
->m1
* clock
->m2
;
531 clock
->p
= clock
->p1
* clock
->p2
;
532 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
534 clock
->vco
= DIV_ROUND_CLOSEST_ULL((uint64_t)refclk
* clock
->m
,
536 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
539 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
541 * Returns whether the given set of divisors are valid for a given refclk with
542 * the given connectors.
545 static bool intel_PLL_is_valid(struct drm_device
*dev
,
546 const intel_limit_t
*limit
,
547 const intel_clock_t
*clock
)
549 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
550 INTELPllInvalid("n out of range\n");
551 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
552 INTELPllInvalid("p1 out of range\n");
553 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
554 INTELPllInvalid("m2 out of range\n");
555 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
556 INTELPllInvalid("m1 out of range\n");
558 if (!IS_PINEVIEW(dev
) && !IS_VALLEYVIEW(dev
))
559 if (clock
->m1
<= clock
->m2
)
560 INTELPllInvalid("m1 <= m2\n");
562 if (!IS_VALLEYVIEW(dev
)) {
563 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
564 INTELPllInvalid("p out of range\n");
565 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
566 INTELPllInvalid("m out of range\n");
569 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
570 INTELPllInvalid("vco out of range\n");
571 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
572 * connector, etc., rather than just a single range.
574 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
575 INTELPllInvalid("dot out of range\n");
581 i9xx_find_best_dpll(const intel_limit_t
*limit
, struct intel_crtc
*crtc
,
582 int target
, int refclk
, intel_clock_t
*match_clock
,
583 intel_clock_t
*best_clock
)
585 struct drm_device
*dev
= crtc
->base
.dev
;
589 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
591 * For LVDS just rely on its current settings for dual-channel.
592 * We haven't figured out how to reliably set up different
593 * single/dual channel state, if we even can.
595 if (intel_is_dual_link_lvds(dev
))
596 clock
.p2
= limit
->p2
.p2_fast
;
598 clock
.p2
= limit
->p2
.p2_slow
;
600 if (target
< limit
->p2
.dot_limit
)
601 clock
.p2
= limit
->p2
.p2_slow
;
603 clock
.p2
= limit
->p2
.p2_fast
;
606 memset(best_clock
, 0, sizeof(*best_clock
));
608 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
610 for (clock
.m2
= limit
->m2
.min
;
611 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
612 if (clock
.m2
>= clock
.m1
)
614 for (clock
.n
= limit
->n
.min
;
615 clock
.n
<= limit
->n
.max
; clock
.n
++) {
616 for (clock
.p1
= limit
->p1
.min
;
617 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
620 i9xx_clock(refclk
, &clock
);
621 if (!intel_PLL_is_valid(dev
, limit
,
625 clock
.p
!= match_clock
->p
)
628 this_err
= abs(clock
.dot
- target
);
629 if (this_err
< err
) {
638 return (err
!= target
);
642 pnv_find_best_dpll(const intel_limit_t
*limit
, struct intel_crtc
*crtc
,
643 int target
, int refclk
, intel_clock_t
*match_clock
,
644 intel_clock_t
*best_clock
)
646 struct drm_device
*dev
= crtc
->base
.dev
;
650 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
652 * For LVDS just rely on its current settings for dual-channel.
653 * We haven't figured out how to reliably set up different
654 * single/dual channel state, if we even can.
656 if (intel_is_dual_link_lvds(dev
))
657 clock
.p2
= limit
->p2
.p2_fast
;
659 clock
.p2
= limit
->p2
.p2_slow
;
661 if (target
< limit
->p2
.dot_limit
)
662 clock
.p2
= limit
->p2
.p2_slow
;
664 clock
.p2
= limit
->p2
.p2_fast
;
667 memset(best_clock
, 0, sizeof(*best_clock
));
669 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
671 for (clock
.m2
= limit
->m2
.min
;
672 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
673 for (clock
.n
= limit
->n
.min
;
674 clock
.n
<= limit
->n
.max
; clock
.n
++) {
675 for (clock
.p1
= limit
->p1
.min
;
676 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
679 pineview_clock(refclk
, &clock
);
680 if (!intel_PLL_is_valid(dev
, limit
,
684 clock
.p
!= match_clock
->p
)
687 this_err
= abs(clock
.dot
- target
);
688 if (this_err
< err
) {
697 return (err
!= target
);
701 g4x_find_best_dpll(const intel_limit_t
*limit
, struct intel_crtc
*crtc
,
702 int target
, int refclk
, intel_clock_t
*match_clock
,
703 intel_clock_t
*best_clock
)
705 struct drm_device
*dev
= crtc
->base
.dev
;
709 /* approximately equals target * 0.00585 */
710 int err_most
= (target
>> 8) + (target
>> 9);
713 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
714 if (intel_is_dual_link_lvds(dev
))
715 clock
.p2
= limit
->p2
.p2_fast
;
717 clock
.p2
= limit
->p2
.p2_slow
;
719 if (target
< limit
->p2
.dot_limit
)
720 clock
.p2
= limit
->p2
.p2_slow
;
722 clock
.p2
= limit
->p2
.p2_fast
;
725 memset(best_clock
, 0, sizeof(*best_clock
));
726 max_n
= limit
->n
.max
;
727 /* based on hardware requirement, prefer smaller n to precision */
728 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
729 /* based on hardware requirement, prefere larger m1,m2 */
730 for (clock
.m1
= limit
->m1
.max
;
731 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
732 for (clock
.m2
= limit
->m2
.max
;
733 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
734 for (clock
.p1
= limit
->p1
.max
;
735 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
738 i9xx_clock(refclk
, &clock
);
739 if (!intel_PLL_is_valid(dev
, limit
,
743 this_err
= abs(clock
.dot
- target
);
744 if (this_err
< err_most
) {
758 vlv_find_best_dpll(const intel_limit_t
*limit
, struct intel_crtc
*crtc
,
759 int target
, int refclk
, intel_clock_t
*match_clock
,
760 intel_clock_t
*best_clock
)
762 struct drm_device
*dev
= crtc
->base
.dev
;
764 unsigned int bestppm
= 1000000;
765 /* min update 19.2 MHz */
766 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
769 target
*= 5; /* fast clock */
771 memset(best_clock
, 0, sizeof(*best_clock
));
773 /* based on hardware requirement, prefer smaller n to precision */
774 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
775 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
776 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
777 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
778 clock
.p
= clock
.p1
* clock
.p2
;
779 /* based on hardware requirement, prefer bigger m1,m2 values */
780 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
781 unsigned int ppm
, diff
;
783 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
786 vlv_clock(refclk
, &clock
);
788 if (!intel_PLL_is_valid(dev
, limit
,
792 diff
= abs(clock
.dot
- target
);
793 ppm
= div_u64(1000000ULL * diff
, target
);
795 if (ppm
< 100 && clock
.p
> best_clock
->p
) {
801 if (bestppm
>= 10 && ppm
< bestppm
- 10) {
815 chv_find_best_dpll(const intel_limit_t
*limit
, struct intel_crtc
*crtc
,
816 int target
, int refclk
, intel_clock_t
*match_clock
,
817 intel_clock_t
*best_clock
)
819 struct drm_device
*dev
= crtc
->base
.dev
;
824 memset(best_clock
, 0, sizeof(*best_clock
));
827 * Based on hardware doc, the n always set to 1, and m1 always
828 * set to 2. If requires to support 200Mhz refclk, we need to
829 * revisit this because n may not 1 anymore.
831 clock
.n
= 1, clock
.m1
= 2;
832 target
*= 5; /* fast clock */
834 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
835 for (clock
.p2
= limit
->p2
.p2_fast
;
836 clock
.p2
>= limit
->p2
.p2_slow
;
837 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
839 clock
.p
= clock
.p1
* clock
.p2
;
841 m2
= DIV_ROUND_CLOSEST_ULL(((uint64_t)target
* clock
.p
*
842 clock
.n
) << 22, refclk
* clock
.m1
);
844 if (m2
> INT_MAX
/clock
.m1
)
849 chv_clock(refclk
, &clock
);
851 if (!intel_PLL_is_valid(dev
, limit
, &clock
))
854 /* based on hardware requirement, prefer bigger p
856 if (clock
.p
> best_clock
->p
) {
866 bool intel_crtc_active(struct drm_crtc
*crtc
)
868 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
870 /* Be paranoid as we can arrive here with only partial
871 * state retrieved from the hardware during setup.
873 * We can ditch the adjusted_mode.crtc_clock check as soon
874 * as Haswell has gained clock readout/fastboot support.
876 * We can ditch the crtc->primary->fb check as soon as we can
877 * properly reconstruct framebuffers.
879 return intel_crtc
->active
&& crtc
->primary
->fb
&&
880 intel_crtc
->config
.adjusted_mode
.crtc_clock
;
883 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
886 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
887 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
889 return intel_crtc
->config
.cpu_transcoder
;
892 static bool pipe_dsl_stopped(struct drm_device
*dev
, enum pipe pipe
)
894 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
895 u32 reg
= PIPEDSL(pipe
);
900 line_mask
= DSL_LINEMASK_GEN2
;
902 line_mask
= DSL_LINEMASK_GEN3
;
904 line1
= I915_READ(reg
) & line_mask
;
906 line2
= I915_READ(reg
) & line_mask
;
908 return line1
== line2
;
912 * intel_wait_for_pipe_off - wait for pipe to turn off
913 * @crtc: crtc whose pipe to wait for
915 * After disabling a pipe, we can't wait for vblank in the usual way,
916 * spinning on the vblank interrupt status bit, since we won't actually
917 * see an interrupt when the pipe is disabled.
920 * wait for the pipe register state bit to turn off
923 * wait for the display line value to settle (it usually
924 * ends up stopping at the start of the next frame).
927 static void intel_wait_for_pipe_off(struct intel_crtc
*crtc
)
929 struct drm_device
*dev
= crtc
->base
.dev
;
930 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
931 enum transcoder cpu_transcoder
= crtc
->config
.cpu_transcoder
;
932 enum pipe pipe
= crtc
->pipe
;
934 if (INTEL_INFO(dev
)->gen
>= 4) {
935 int reg
= PIPECONF(cpu_transcoder
);
937 /* Wait for the Pipe State to go off */
938 if (wait_for((I915_READ(reg
) & I965_PIPECONF_ACTIVE
) == 0,
940 WARN(1, "pipe_off wait timed out\n");
942 /* Wait for the display line to settle */
943 if (wait_for(pipe_dsl_stopped(dev
, pipe
), 100))
944 WARN(1, "pipe_off wait timed out\n");
949 * ibx_digital_port_connected - is the specified port connected?
950 * @dev_priv: i915 private structure
951 * @port: the port to test
953 * Returns true if @port is connected, false otherwise.
955 bool ibx_digital_port_connected(struct drm_i915_private
*dev_priv
,
956 struct intel_digital_port
*port
)
960 if (HAS_PCH_IBX(dev_priv
->dev
)) {
961 switch (port
->port
) {
963 bit
= SDE_PORTB_HOTPLUG
;
966 bit
= SDE_PORTC_HOTPLUG
;
969 bit
= SDE_PORTD_HOTPLUG
;
975 switch (port
->port
) {
977 bit
= SDE_PORTB_HOTPLUG_CPT
;
980 bit
= SDE_PORTC_HOTPLUG_CPT
;
983 bit
= SDE_PORTD_HOTPLUG_CPT
;
990 return I915_READ(SDEISR
) & bit
;
993 static const char *state_string(bool enabled
)
995 return enabled
? "on" : "off";
998 /* Only for pre-ILK configs */
999 void assert_pll(struct drm_i915_private
*dev_priv
,
1000 enum pipe pipe
, bool state
)
1007 val
= I915_READ(reg
);
1008 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1009 WARN(cur_state
!= state
,
1010 "PLL state assertion failure (expected %s, current %s)\n",
1011 state_string(state
), state_string(cur_state
));
1014 /* XXX: the dsi pll is shared between MIPI DSI ports */
1015 static void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1020 mutex_lock(&dev_priv
->dpio_lock
);
1021 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1022 mutex_unlock(&dev_priv
->dpio_lock
);
1024 cur_state
= val
& DSI_PLL_VCO_EN
;
1025 WARN(cur_state
!= state
,
1026 "DSI PLL state assertion failure (expected %s, current %s)\n",
1027 state_string(state
), state_string(cur_state
));
1029 #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
1030 #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
1032 struct intel_shared_dpll
*
1033 intel_crtc_to_shared_dpll(struct intel_crtc
*crtc
)
1035 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
1037 if (crtc
->config
.shared_dpll
< 0)
1040 return &dev_priv
->shared_dplls
[crtc
->config
.shared_dpll
];
1044 void assert_shared_dpll(struct drm_i915_private
*dev_priv
,
1045 struct intel_shared_dpll
*pll
,
1049 struct intel_dpll_hw_state hw_state
;
1052 "asserting DPLL %s with no DPLL\n", state_string(state
)))
1055 cur_state
= pll
->get_hw_state(dev_priv
, pll
, &hw_state
);
1056 WARN(cur_state
!= state
,
1057 "%s assertion failure (expected %s, current %s)\n",
1058 pll
->name
, state_string(state
), state_string(cur_state
));
1061 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1062 enum pipe pipe
, bool state
)
1067 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1070 if (HAS_DDI(dev_priv
->dev
)) {
1071 /* DDI does not have a specific FDI_TX register */
1072 reg
= TRANS_DDI_FUNC_CTL(cpu_transcoder
);
1073 val
= I915_READ(reg
);
1074 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1076 reg
= FDI_TX_CTL(pipe
);
1077 val
= I915_READ(reg
);
1078 cur_state
= !!(val
& FDI_TX_ENABLE
);
1080 WARN(cur_state
!= state
,
1081 "FDI TX state assertion failure (expected %s, current %s)\n",
1082 state_string(state
), state_string(cur_state
));
1084 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1085 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1087 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1088 enum pipe pipe
, bool state
)
1094 reg
= FDI_RX_CTL(pipe
);
1095 val
= I915_READ(reg
);
1096 cur_state
= !!(val
& FDI_RX_ENABLE
);
1097 WARN(cur_state
!= state
,
1098 "FDI RX state assertion failure (expected %s, current %s)\n",
1099 state_string(state
), state_string(cur_state
));
1101 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1102 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1104 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1110 /* ILK FDI PLL is always enabled */
1111 if (INTEL_INFO(dev_priv
->dev
)->gen
== 5)
1114 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1115 if (HAS_DDI(dev_priv
->dev
))
1118 reg
= FDI_TX_CTL(pipe
);
1119 val
= I915_READ(reg
);
1120 WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1123 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1124 enum pipe pipe
, bool state
)
1130 reg
= FDI_RX_CTL(pipe
);
1131 val
= I915_READ(reg
);
1132 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1133 WARN(cur_state
!= state
,
1134 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1135 state_string(state
), state_string(cur_state
));
1138 void assert_panel_unlocked(struct drm_i915_private
*dev_priv
,
1141 struct drm_device
*dev
= dev_priv
->dev
;
1144 enum pipe panel_pipe
= PIPE_A
;
1147 if (WARN_ON(HAS_DDI(dev
)))
1150 if (HAS_PCH_SPLIT(dev
)) {
1153 pp_reg
= PCH_PP_CONTROL
;
1154 port_sel
= I915_READ(PCH_PP_ON_DELAYS
) & PANEL_PORT_SELECT_MASK
;
1156 if (port_sel
== PANEL_PORT_SELECT_LVDS
&&
1157 I915_READ(PCH_LVDS
) & LVDS_PIPEB_SELECT
)
1158 panel_pipe
= PIPE_B
;
1159 /* XXX: else fix for eDP */
1160 } else if (IS_VALLEYVIEW(dev
)) {
1161 /* presumably write lock depends on pipe, not port select */
1162 pp_reg
= VLV_PIPE_PP_CONTROL(pipe
);
1165 pp_reg
= PP_CONTROL
;
1166 if (I915_READ(LVDS
) & LVDS_PIPEB_SELECT
)
1167 panel_pipe
= PIPE_B
;
1170 val
= I915_READ(pp_reg
);
1171 if (!(val
& PANEL_POWER_ON
) ||
1172 ((val
& PANEL_UNLOCK_MASK
) == PANEL_UNLOCK_REGS
))
1175 WARN(panel_pipe
== pipe
&& locked
,
1176 "panel assertion failure, pipe %c regs locked\n",
1180 static void assert_cursor(struct drm_i915_private
*dev_priv
,
1181 enum pipe pipe
, bool state
)
1183 struct drm_device
*dev
= dev_priv
->dev
;
1186 if (IS_845G(dev
) || IS_I865G(dev
))
1187 cur_state
= I915_READ(_CURACNTR
) & CURSOR_ENABLE
;
1189 cur_state
= I915_READ(CURCNTR(pipe
)) & CURSOR_MODE
;
1191 WARN(cur_state
!= state
,
1192 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1193 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1195 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1196 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1198 void assert_pipe(struct drm_i915_private
*dev_priv
,
1199 enum pipe pipe
, bool state
)
1204 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1207 /* if we need the pipe quirk it must be always on */
1208 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1209 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1212 if (!intel_display_power_is_enabled(dev_priv
,
1213 POWER_DOMAIN_TRANSCODER(cpu_transcoder
))) {
1216 reg
= PIPECONF(cpu_transcoder
);
1217 val
= I915_READ(reg
);
1218 cur_state
= !!(val
& PIPECONF_ENABLE
);
1221 WARN(cur_state
!= state
,
1222 "pipe %c assertion failure (expected %s, current %s)\n",
1223 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1226 static void assert_plane(struct drm_i915_private
*dev_priv
,
1227 enum plane plane
, bool state
)
1233 reg
= DSPCNTR(plane
);
1234 val
= I915_READ(reg
);
1235 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1236 WARN(cur_state
!= state
,
1237 "plane %c assertion failure (expected %s, current %s)\n",
1238 plane_name(plane
), state_string(state
), state_string(cur_state
));
1241 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1242 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1244 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1247 struct drm_device
*dev
= dev_priv
->dev
;
1252 /* Primary planes are fixed to pipes on gen4+ */
1253 if (INTEL_INFO(dev
)->gen
>= 4) {
1254 reg
= DSPCNTR(pipe
);
1255 val
= I915_READ(reg
);
1256 WARN(val
& DISPLAY_PLANE_ENABLE
,
1257 "plane %c assertion failure, should be disabled but not\n",
1262 /* Need to check both planes against the pipe */
1263 for_each_pipe(dev_priv
, i
) {
1265 val
= I915_READ(reg
);
1266 cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1267 DISPPLANE_SEL_PIPE_SHIFT
;
1268 WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1269 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1270 plane_name(i
), pipe_name(pipe
));
1274 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1277 struct drm_device
*dev
= dev_priv
->dev
;
1281 if (INTEL_INFO(dev
)->gen
>= 9) {
1282 for_each_sprite(pipe
, sprite
) {
1283 val
= I915_READ(PLANE_CTL(pipe
, sprite
));
1284 WARN(val
& PLANE_CTL_ENABLE
,
1285 "plane %d assertion failure, should be off on pipe %c but is still active\n",
1286 sprite
, pipe_name(pipe
));
1288 } else if (IS_VALLEYVIEW(dev
)) {
1289 for_each_sprite(pipe
, sprite
) {
1290 reg
= SPCNTR(pipe
, sprite
);
1291 val
= I915_READ(reg
);
1292 WARN(val
& SP_ENABLE
,
1293 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1294 sprite_name(pipe
, sprite
), pipe_name(pipe
));
1296 } else if (INTEL_INFO(dev
)->gen
>= 7) {
1298 val
= I915_READ(reg
);
1299 WARN(val
& SPRITE_ENABLE
,
1300 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1301 plane_name(pipe
), pipe_name(pipe
));
1302 } else if (INTEL_INFO(dev
)->gen
>= 5) {
1303 reg
= DVSCNTR(pipe
);
1304 val
= I915_READ(reg
);
1305 WARN(val
& DVS_ENABLE
,
1306 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1307 plane_name(pipe
), pipe_name(pipe
));
1311 static void assert_vblank_disabled(struct drm_crtc
*crtc
)
1313 if (WARN_ON(drm_crtc_vblank_get(crtc
) == 0))
1314 drm_crtc_vblank_put(crtc
);
1317 static void ibx_assert_pch_refclk_enabled(struct drm_i915_private
*dev_priv
)
1322 WARN_ON(!(HAS_PCH_IBX(dev_priv
->dev
) || HAS_PCH_CPT(dev_priv
->dev
)));
1324 val
= I915_READ(PCH_DREF_CONTROL
);
1325 enabled
= !!(val
& (DREF_SSC_SOURCE_MASK
| DREF_NONSPREAD_SOURCE_MASK
|
1326 DREF_SUPERSPREAD_SOURCE_MASK
));
1327 WARN(!enabled
, "PCH refclk assertion failure, should be active but is disabled\n");
1330 static void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1337 reg
= PCH_TRANSCONF(pipe
);
1338 val
= I915_READ(reg
);
1339 enabled
= !!(val
& TRANS_ENABLE
);
1341 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1345 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1346 enum pipe pipe
, u32 port_sel
, u32 val
)
1348 if ((val
& DP_PORT_EN
) == 0)
1351 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1352 u32 trans_dp_ctl_reg
= TRANS_DP_CTL(pipe
);
1353 u32 trans_dp_ctl
= I915_READ(trans_dp_ctl_reg
);
1354 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1356 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1357 if ((val
& DP_PIPE_MASK_CHV
) != DP_PIPE_SELECT_CHV(pipe
))
1360 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1366 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1367 enum pipe pipe
, u32 val
)
1369 if ((val
& SDVO_ENABLE
) == 0)
1372 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1373 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1375 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1376 if ((val
& SDVO_PIPE_SEL_MASK_CHV
) != SDVO_PIPE_SEL_CHV(pipe
))
1379 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1385 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1386 enum pipe pipe
, u32 val
)
1388 if ((val
& LVDS_PORT_EN
) == 0)
1391 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1392 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1395 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1401 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1402 enum pipe pipe
, u32 val
)
1404 if ((val
& ADPA_DAC_ENABLE
) == 0)
1406 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1407 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1410 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1416 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1417 enum pipe pipe
, int reg
, u32 port_sel
)
1419 u32 val
= I915_READ(reg
);
1420 WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1421 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1422 reg
, pipe_name(pipe
));
1424 WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& DP_PORT_EN
) == 0
1425 && (val
& DP_PIPEB_SELECT
),
1426 "IBX PCH dp port still using transcoder B\n");
1429 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1430 enum pipe pipe
, int reg
)
1432 u32 val
= I915_READ(reg
);
1433 WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1434 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1435 reg
, pipe_name(pipe
));
1437 WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& SDVO_ENABLE
) == 0
1438 && (val
& SDVO_PIPE_B_SELECT
),
1439 "IBX PCH hdmi port still using transcoder B\n");
1442 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1448 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1449 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1450 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1453 val
= I915_READ(reg
);
1454 WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1455 "PCH VGA enabled on transcoder %c, should be disabled\n",
1459 val
= I915_READ(reg
);
1460 WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1461 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1464 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1465 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1466 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1469 static void intel_init_dpio(struct drm_device
*dev
)
1471 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1473 if (!IS_VALLEYVIEW(dev
))
1477 * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
1478 * CHV x1 PHY (DP/HDMI D)
1479 * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
1481 if (IS_CHERRYVIEW(dev
)) {
1482 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO_2
;
1483 DPIO_PHY_IOSF_PORT(DPIO_PHY1
) = IOSF_PORT_DPIO
;
1485 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO
;
1489 static void vlv_enable_pll(struct intel_crtc
*crtc
,
1490 const struct intel_crtc_config
*pipe_config
)
1492 struct drm_device
*dev
= crtc
->base
.dev
;
1493 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1494 int reg
= DPLL(crtc
->pipe
);
1495 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
1497 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1499 /* No really, not for ILK+ */
1500 BUG_ON(!IS_VALLEYVIEW(dev_priv
->dev
));
1502 /* PLL is protected by panel, make sure we can write it */
1503 if (IS_MOBILE(dev_priv
->dev
))
1504 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1506 I915_WRITE(reg
, dpll
);
1510 if (wait_for(((I915_READ(reg
) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1511 DRM_ERROR("DPLL %d failed to lock\n", crtc
->pipe
);
1513 I915_WRITE(DPLL_MD(crtc
->pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1514 POSTING_READ(DPLL_MD(crtc
->pipe
));
1516 /* We do this three times for luck */
1517 I915_WRITE(reg
, dpll
);
1519 udelay(150); /* wait for warmup */
1520 I915_WRITE(reg
, dpll
);
1522 udelay(150); /* wait for warmup */
1523 I915_WRITE(reg
, dpll
);
1525 udelay(150); /* wait for warmup */
1528 static void chv_enable_pll(struct intel_crtc
*crtc
,
1529 const struct intel_crtc_config
*pipe_config
)
1531 struct drm_device
*dev
= crtc
->base
.dev
;
1532 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1533 int pipe
= crtc
->pipe
;
1534 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1537 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1539 BUG_ON(!IS_CHERRYVIEW(dev_priv
->dev
));
1541 mutex_lock(&dev_priv
->dpio_lock
);
1543 /* Enable back the 10bit clock to display controller */
1544 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1545 tmp
|= DPIO_DCLKP_EN
;
1546 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), tmp
);
1549 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1554 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1556 /* Check PLL is locked */
1557 if (wait_for(((I915_READ(DPLL(pipe
)) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1558 DRM_ERROR("PLL %d failed to lock\n", pipe
);
1560 /* not sure when this should be written */
1561 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1562 POSTING_READ(DPLL_MD(pipe
));
1564 mutex_unlock(&dev_priv
->dpio_lock
);
1567 static int intel_num_dvo_pipes(struct drm_device
*dev
)
1569 struct intel_crtc
*crtc
;
1572 for_each_intel_crtc(dev
, crtc
)
1573 count
+= crtc
->active
&&
1574 intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
);
1579 static void i9xx_enable_pll(struct intel_crtc
*crtc
)
1581 struct drm_device
*dev
= crtc
->base
.dev
;
1582 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1583 int reg
= DPLL(crtc
->pipe
);
1584 u32 dpll
= crtc
->config
.dpll_hw_state
.dpll
;
1586 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1588 /* No really, not for ILK+ */
1589 BUG_ON(INTEL_INFO(dev
)->gen
>= 5);
1591 /* PLL is protected by panel, make sure we can write it */
1592 if (IS_MOBILE(dev
) && !IS_I830(dev
))
1593 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1595 /* Enable DVO 2x clock on both PLLs if necessary */
1596 if (IS_I830(dev
) && intel_num_dvo_pipes(dev
) > 0) {
1598 * It appears to be important that we don't enable this
1599 * for the current pipe before otherwise configuring the
1600 * PLL. No idea how this should be handled if multiple
1601 * DVO outputs are enabled simultaneosly.
1603 dpll
|= DPLL_DVO_2X_MODE
;
1604 I915_WRITE(DPLL(!crtc
->pipe
),
1605 I915_READ(DPLL(!crtc
->pipe
)) | DPLL_DVO_2X_MODE
);
1608 /* Wait for the clocks to stabilize. */
1612 if (INTEL_INFO(dev
)->gen
>= 4) {
1613 I915_WRITE(DPLL_MD(crtc
->pipe
),
1614 crtc
->config
.dpll_hw_state
.dpll_md
);
1616 /* The pixel multiplier can only be updated once the
1617 * DPLL is enabled and the clocks are stable.
1619 * So write it again.
1621 I915_WRITE(reg
, dpll
);
1624 /* We do this three times for luck */
1625 I915_WRITE(reg
, dpll
);
1627 udelay(150); /* wait for warmup */
1628 I915_WRITE(reg
, dpll
);
1630 udelay(150); /* wait for warmup */
1631 I915_WRITE(reg
, dpll
);
1633 udelay(150); /* wait for warmup */
1637 * i9xx_disable_pll - disable a PLL
1638 * @dev_priv: i915 private structure
1639 * @pipe: pipe PLL to disable
1641 * Disable the PLL for @pipe, making sure the pipe is off first.
1643 * Note! This is for pre-ILK only.
1645 static void i9xx_disable_pll(struct intel_crtc
*crtc
)
1647 struct drm_device
*dev
= crtc
->base
.dev
;
1648 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1649 enum pipe pipe
= crtc
->pipe
;
1651 /* Disable DVO 2x clock on both PLLs if necessary */
1653 intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
) &&
1654 intel_num_dvo_pipes(dev
) == 1) {
1655 I915_WRITE(DPLL(PIPE_B
),
1656 I915_READ(DPLL(PIPE_B
)) & ~DPLL_DVO_2X_MODE
);
1657 I915_WRITE(DPLL(PIPE_A
),
1658 I915_READ(DPLL(PIPE_A
)) & ~DPLL_DVO_2X_MODE
);
1661 /* Don't disable pipe or pipe PLLs if needed */
1662 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1663 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1666 /* Make sure the pipe isn't still relying on us */
1667 assert_pipe_disabled(dev_priv
, pipe
);
1669 I915_WRITE(DPLL(pipe
), 0);
1670 POSTING_READ(DPLL(pipe
));
1673 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1677 /* Make sure the pipe isn't still relying on us */
1678 assert_pipe_disabled(dev_priv
, pipe
);
1681 * Leave integrated clock source and reference clock enabled for pipe B.
1682 * The latter is needed for VGA hotplug / manual detection.
1685 val
= DPLL_INTEGRATED_CRI_CLK_VLV
| DPLL_REFA_CLK_ENABLE_VLV
;
1686 I915_WRITE(DPLL(pipe
), val
);
1687 POSTING_READ(DPLL(pipe
));
1691 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1693 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1696 /* Make sure the pipe isn't still relying on us */
1697 assert_pipe_disabled(dev_priv
, pipe
);
1699 /* Set PLL en = 0 */
1700 val
= DPLL_SSC_REF_CLOCK_CHV
| DPLL_REFA_CLK_ENABLE_VLV
;
1702 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1703 I915_WRITE(DPLL(pipe
), val
);
1704 POSTING_READ(DPLL(pipe
));
1706 mutex_lock(&dev_priv
->dpio_lock
);
1708 /* Disable 10bit clock to display controller */
1709 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1710 val
&= ~DPIO_DCLKP_EN
;
1711 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1713 /* disable left/right clock distribution */
1714 if (pipe
!= PIPE_B
) {
1715 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
);
1716 val
&= ~(CHV_BUFLEFTENA1_MASK
| CHV_BUFRIGHTENA1_MASK
);
1717 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
, val
);
1719 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
);
1720 val
&= ~(CHV_BUFLEFTENA2_MASK
| CHV_BUFRIGHTENA2_MASK
);
1721 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
, val
);
1724 mutex_unlock(&dev_priv
->dpio_lock
);
1727 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1728 struct intel_digital_port
*dport
)
1733 switch (dport
->port
) {
1735 port_mask
= DPLL_PORTB_READY_MASK
;
1739 port_mask
= DPLL_PORTC_READY_MASK
;
1743 port_mask
= DPLL_PORTD_READY_MASK
;
1744 dpll_reg
= DPIO_PHY_STATUS
;
1750 if (wait_for((I915_READ(dpll_reg
) & port_mask
) == 0, 1000))
1751 WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
1752 port_name(dport
->port
), I915_READ(dpll_reg
));
1755 static void intel_prepare_shared_dpll(struct intel_crtc
*crtc
)
1757 struct drm_device
*dev
= crtc
->base
.dev
;
1758 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1759 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1761 if (WARN_ON(pll
== NULL
))
1764 WARN_ON(!pll
->refcount
);
1765 if (pll
->active
== 0) {
1766 DRM_DEBUG_DRIVER("setting up %s\n", pll
->name
);
1768 assert_shared_dpll_disabled(dev_priv
, pll
);
1770 pll
->mode_set(dev_priv
, pll
);
1775 * intel_enable_shared_dpll - enable PCH PLL
1776 * @dev_priv: i915 private structure
1777 * @pipe: pipe PLL to enable
1779 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1780 * drives the transcoder clock.
1782 static void intel_enable_shared_dpll(struct intel_crtc
*crtc
)
1784 struct drm_device
*dev
= crtc
->base
.dev
;
1785 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1786 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1788 if (WARN_ON(pll
== NULL
))
1791 if (WARN_ON(pll
->refcount
== 0))
1794 DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n",
1795 pll
->name
, pll
->active
, pll
->on
,
1796 crtc
->base
.base
.id
);
1798 if (pll
->active
++) {
1800 assert_shared_dpll_enabled(dev_priv
, pll
);
1805 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
1807 DRM_DEBUG_KMS("enabling %s\n", pll
->name
);
1808 pll
->enable(dev_priv
, pll
);
1812 static void intel_disable_shared_dpll(struct intel_crtc
*crtc
)
1814 struct drm_device
*dev
= crtc
->base
.dev
;
1815 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1816 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1818 /* PCH only available on ILK+ */
1819 BUG_ON(INTEL_INFO(dev
)->gen
< 5);
1820 if (WARN_ON(pll
== NULL
))
1823 if (WARN_ON(pll
->refcount
== 0))
1826 DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
1827 pll
->name
, pll
->active
, pll
->on
,
1828 crtc
->base
.base
.id
);
1830 if (WARN_ON(pll
->active
== 0)) {
1831 assert_shared_dpll_disabled(dev_priv
, pll
);
1835 assert_shared_dpll_enabled(dev_priv
, pll
);
1840 DRM_DEBUG_KMS("disabling %s\n", pll
->name
);
1841 pll
->disable(dev_priv
, pll
);
1844 intel_display_power_put(dev_priv
, POWER_DOMAIN_PLLS
);
1847 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1850 struct drm_device
*dev
= dev_priv
->dev
;
1851 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1852 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1853 uint32_t reg
, val
, pipeconf_val
;
1855 /* PCH only available on ILK+ */
1856 BUG_ON(!HAS_PCH_SPLIT(dev
));
1858 /* Make sure PCH DPLL is enabled */
1859 assert_shared_dpll_enabled(dev_priv
,
1860 intel_crtc_to_shared_dpll(intel_crtc
));
1862 /* FDI must be feeding us bits for PCH ports */
1863 assert_fdi_tx_enabled(dev_priv
, pipe
);
1864 assert_fdi_rx_enabled(dev_priv
, pipe
);
1866 if (HAS_PCH_CPT(dev
)) {
1867 /* Workaround: Set the timing override bit before enabling the
1868 * pch transcoder. */
1869 reg
= TRANS_CHICKEN2(pipe
);
1870 val
= I915_READ(reg
);
1871 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1872 I915_WRITE(reg
, val
);
1875 reg
= PCH_TRANSCONF(pipe
);
1876 val
= I915_READ(reg
);
1877 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1879 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1881 * make the BPC in transcoder be consistent with
1882 * that in pipeconf reg.
1884 val
&= ~PIPECONF_BPC_MASK
;
1885 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
1888 val
&= ~TRANS_INTERLACE_MASK
;
1889 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
1890 if (HAS_PCH_IBX(dev_priv
->dev
) &&
1891 intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
1892 val
|= TRANS_LEGACY_INTERLACED_ILK
;
1894 val
|= TRANS_INTERLACED
;
1896 val
|= TRANS_PROGRESSIVE
;
1898 I915_WRITE(reg
, val
| TRANS_ENABLE
);
1899 if (wait_for(I915_READ(reg
) & TRANS_STATE_ENABLE
, 100))
1900 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
1903 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1904 enum transcoder cpu_transcoder
)
1906 u32 val
, pipeconf_val
;
1908 /* PCH only available on ILK+ */
1909 BUG_ON(!HAS_PCH_SPLIT(dev_priv
->dev
));
1911 /* FDI must be feeding us bits for PCH ports */
1912 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
1913 assert_fdi_rx_enabled(dev_priv
, TRANSCODER_A
);
1915 /* Workaround: set timing override bit. */
1916 val
= I915_READ(_TRANSA_CHICKEN2
);
1917 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1918 I915_WRITE(_TRANSA_CHICKEN2
, val
);
1921 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
1923 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
1924 PIPECONF_INTERLACED_ILK
)
1925 val
|= TRANS_INTERLACED
;
1927 val
|= TRANS_PROGRESSIVE
;
1929 I915_WRITE(LPT_TRANSCONF
, val
);
1930 if (wait_for(I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
, 100))
1931 DRM_ERROR("Failed to enable PCH transcoder\n");
1934 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1937 struct drm_device
*dev
= dev_priv
->dev
;
1940 /* FDI relies on the transcoder */
1941 assert_fdi_tx_disabled(dev_priv
, pipe
);
1942 assert_fdi_rx_disabled(dev_priv
, pipe
);
1944 /* Ports must be off as well */
1945 assert_pch_ports_disabled(dev_priv
, pipe
);
1947 reg
= PCH_TRANSCONF(pipe
);
1948 val
= I915_READ(reg
);
1949 val
&= ~TRANS_ENABLE
;
1950 I915_WRITE(reg
, val
);
1951 /* wait for PCH transcoder off, transcoder state */
1952 if (wait_for((I915_READ(reg
) & TRANS_STATE_ENABLE
) == 0, 50))
1953 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
1955 if (!HAS_PCH_IBX(dev
)) {
1956 /* Workaround: Clear the timing override chicken bit again. */
1957 reg
= TRANS_CHICKEN2(pipe
);
1958 val
= I915_READ(reg
);
1959 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1960 I915_WRITE(reg
, val
);
1964 static void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
1968 val
= I915_READ(LPT_TRANSCONF
);
1969 val
&= ~TRANS_ENABLE
;
1970 I915_WRITE(LPT_TRANSCONF
, val
);
1971 /* wait for PCH transcoder off, transcoder state */
1972 if (wait_for((I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
) == 0, 50))
1973 DRM_ERROR("Failed to disable PCH transcoder\n");
1975 /* Workaround: clear timing override bit. */
1976 val
= I915_READ(_TRANSA_CHICKEN2
);
1977 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1978 I915_WRITE(_TRANSA_CHICKEN2
, val
);
1982 * intel_enable_pipe - enable a pipe, asserting requirements
1983 * @crtc: crtc responsible for the pipe
1985 * Enable @crtc's pipe, making sure that various hardware specific requirements
1986 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
1988 static void intel_enable_pipe(struct intel_crtc
*crtc
)
1990 struct drm_device
*dev
= crtc
->base
.dev
;
1991 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1992 enum pipe pipe
= crtc
->pipe
;
1993 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1995 enum pipe pch_transcoder
;
1999 assert_planes_disabled(dev_priv
, pipe
);
2000 assert_cursor_disabled(dev_priv
, pipe
);
2001 assert_sprites_disabled(dev_priv
, pipe
);
2003 if (HAS_PCH_LPT(dev_priv
->dev
))
2004 pch_transcoder
= TRANSCODER_A
;
2006 pch_transcoder
= pipe
;
2009 * A pipe without a PLL won't actually be able to drive bits from
2010 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
2013 if (!HAS_PCH_SPLIT(dev_priv
->dev
))
2014 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
))
2015 assert_dsi_pll_enabled(dev_priv
);
2017 assert_pll_enabled(dev_priv
, pipe
);
2019 if (crtc
->config
.has_pch_encoder
) {
2020 /* if driving the PCH, we need FDI enabled */
2021 assert_fdi_rx_pll_enabled(dev_priv
, pch_transcoder
);
2022 assert_fdi_tx_pll_enabled(dev_priv
,
2023 (enum pipe
) cpu_transcoder
);
2025 /* FIXME: assert CPU port conditions for SNB+ */
2028 reg
= PIPECONF(cpu_transcoder
);
2029 val
= I915_READ(reg
);
2030 if (val
& PIPECONF_ENABLE
) {
2031 WARN_ON(!((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
2032 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
)));
2036 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
2041 * intel_disable_pipe - disable a pipe, asserting requirements
2042 * @crtc: crtc whose pipes is to be disabled
2044 * Disable the pipe of @crtc, making sure that various hardware
2045 * specific requirements are met, if applicable, e.g. plane
2046 * disabled, panel fitter off, etc.
2048 * Will wait until the pipe has shut down before returning.
2050 static void intel_disable_pipe(struct intel_crtc
*crtc
)
2052 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
2053 enum transcoder cpu_transcoder
= crtc
->config
.cpu_transcoder
;
2054 enum pipe pipe
= crtc
->pipe
;
2059 * Make sure planes won't keep trying to pump pixels to us,
2060 * or we might hang the display.
2062 assert_planes_disabled(dev_priv
, pipe
);
2063 assert_cursor_disabled(dev_priv
, pipe
);
2064 assert_sprites_disabled(dev_priv
, pipe
);
2066 reg
= PIPECONF(cpu_transcoder
);
2067 val
= I915_READ(reg
);
2068 if ((val
& PIPECONF_ENABLE
) == 0)
2072 * Double wide has implications for planes
2073 * so best keep it disabled when not needed.
2075 if (crtc
->config
.double_wide
)
2076 val
&= ~PIPECONF_DOUBLE_WIDE
;
2078 /* Don't disable pipe or pipe PLLs if needed */
2079 if (!(pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) &&
2080 !(pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
2081 val
&= ~PIPECONF_ENABLE
;
2083 I915_WRITE(reg
, val
);
2084 if ((val
& PIPECONF_ENABLE
) == 0)
2085 intel_wait_for_pipe_off(crtc
);
2089 * Plane regs are double buffered, going from enabled->disabled needs a
2090 * trigger in order to latch. The display address reg provides this.
2092 void intel_flush_primary_plane(struct drm_i915_private
*dev_priv
,
2095 struct drm_device
*dev
= dev_priv
->dev
;
2096 u32 reg
= INTEL_INFO(dev
)->gen
>= 4 ? DSPSURF(plane
) : DSPADDR(plane
);
2098 I915_WRITE(reg
, I915_READ(reg
));
2103 * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
2104 * @plane: plane to be enabled
2105 * @crtc: crtc for the plane
2107 * Enable @plane on @crtc, making sure that the pipe is running first.
2109 static void intel_enable_primary_hw_plane(struct drm_plane
*plane
,
2110 struct drm_crtc
*crtc
)
2112 struct drm_device
*dev
= plane
->dev
;
2113 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2114 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2116 /* If the pipe isn't enabled, we can't pump pixels and may hang */
2117 assert_pipe_enabled(dev_priv
, intel_crtc
->pipe
);
2119 if (intel_crtc
->primary_enabled
)
2122 intel_crtc
->primary_enabled
= true;
2124 dev_priv
->display
.update_primary_plane(crtc
, plane
->fb
,
2128 * BDW signals flip done immediately if the plane
2129 * is disabled, even if the plane enable is already
2130 * armed to occur at the next vblank :(
2132 if (IS_BROADWELL(dev
))
2133 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
2137 * intel_disable_primary_hw_plane - disable the primary hardware plane
2138 * @plane: plane to be disabled
2139 * @crtc: crtc for the plane
2141 * Disable @plane on @crtc, making sure that the pipe is running first.
2143 static void intel_disable_primary_hw_plane(struct drm_plane
*plane
,
2144 struct drm_crtc
*crtc
)
2146 struct drm_device
*dev
= plane
->dev
;
2147 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2148 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2150 assert_pipe_enabled(dev_priv
, intel_crtc
->pipe
);
2152 if (!intel_crtc
->primary_enabled
)
2155 intel_crtc
->primary_enabled
= false;
2157 dev_priv
->display
.update_primary_plane(crtc
, plane
->fb
,
2161 static bool need_vtd_wa(struct drm_device
*dev
)
2163 #ifdef CONFIG_INTEL_IOMMU
2164 if (INTEL_INFO(dev
)->gen
>= 6 && intel_iommu_gfx_mapped
)
2170 static int intel_align_height(struct drm_device
*dev
, int height
, bool tiled
)
2174 tile_height
= tiled
? (IS_GEN2(dev
) ? 16 : 8) : 1;
2175 return ALIGN(height
, tile_height
);
2179 intel_pin_and_fence_fb_obj(struct drm_device
*dev
,
2180 struct drm_i915_gem_object
*obj
,
2181 struct intel_engine_cs
*pipelined
)
2183 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2187 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
2189 switch (obj
->tiling_mode
) {
2190 case I915_TILING_NONE
:
2191 if (INTEL_INFO(dev
)->gen
>= 9)
2192 alignment
= 256 * 1024;
2193 else if (IS_BROADWATER(dev
) || IS_CRESTLINE(dev
))
2194 alignment
= 128 * 1024;
2195 else if (INTEL_INFO(dev
)->gen
>= 4)
2196 alignment
= 4 * 1024;
2198 alignment
= 64 * 1024;
2201 if (INTEL_INFO(dev
)->gen
>= 9)
2202 alignment
= 256 * 1024;
2204 /* pin() will align the object as required by fence */
2209 WARN(1, "Y tiled bo slipped through, driver bug!\n");
2215 /* Note that the w/a also requires 64 PTE of padding following the
2216 * bo. We currently fill all unused PTE with the shadow page and so
2217 * we should always have valid PTE following the scanout preventing
2220 if (need_vtd_wa(dev
) && alignment
< 256 * 1024)
2221 alignment
= 256 * 1024;
2224 * Global gtt pte registers are special registers which actually forward
2225 * writes to a chunk of system memory. Which means that there is no risk
2226 * that the register values disappear as soon as we call
2227 * intel_runtime_pm_put(), so it is correct to wrap only the
2228 * pin/unpin/fence and not more.
2230 intel_runtime_pm_get(dev_priv
);
2232 dev_priv
->mm
.interruptible
= false;
2233 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, pipelined
);
2235 goto err_interruptible
;
2237 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2238 * fence, whereas 965+ only requires a fence if using
2239 * framebuffer compression. For simplicity, we always install
2240 * a fence as the cost is not that onerous.
2242 ret
= i915_gem_object_get_fence(obj
);
2246 i915_gem_object_pin_fence(obj
);
2248 dev_priv
->mm
.interruptible
= true;
2249 intel_runtime_pm_put(dev_priv
);
2253 i915_gem_object_unpin_from_display_plane(obj
);
2255 dev_priv
->mm
.interruptible
= true;
2256 intel_runtime_pm_put(dev_priv
);
2260 void intel_unpin_fb_obj(struct drm_i915_gem_object
*obj
)
2262 WARN_ON(!mutex_is_locked(&obj
->base
.dev
->struct_mutex
));
2264 i915_gem_object_unpin_fence(obj
);
2265 i915_gem_object_unpin_from_display_plane(obj
);
2268 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
2269 * is assumed to be a power-of-two. */
2270 unsigned long intel_gen4_compute_page_offset(int *x
, int *y
,
2271 unsigned int tiling_mode
,
2275 if (tiling_mode
!= I915_TILING_NONE
) {
2276 unsigned int tile_rows
, tiles
;
2281 tiles
= *x
/ (512/cpp
);
2284 return tile_rows
* pitch
* 8 + tiles
* 4096;
2286 unsigned int offset
;
2288 offset
= *y
* pitch
+ *x
* cpp
;
2290 *x
= (offset
& 4095) / cpp
;
2291 return offset
& -4096;
2295 int intel_format_to_fourcc(int format
)
2298 case DISPPLANE_8BPP
:
2299 return DRM_FORMAT_C8
;
2300 case DISPPLANE_BGRX555
:
2301 return DRM_FORMAT_XRGB1555
;
2302 case DISPPLANE_BGRX565
:
2303 return DRM_FORMAT_RGB565
;
2305 case DISPPLANE_BGRX888
:
2306 return DRM_FORMAT_XRGB8888
;
2307 case DISPPLANE_RGBX888
:
2308 return DRM_FORMAT_XBGR8888
;
2309 case DISPPLANE_BGRX101010
:
2310 return DRM_FORMAT_XRGB2101010
;
2311 case DISPPLANE_RGBX101010
:
2312 return DRM_FORMAT_XBGR2101010
;
2316 static bool intel_alloc_plane_obj(struct intel_crtc
*crtc
,
2317 struct intel_plane_config
*plane_config
)
2319 struct drm_device
*dev
= crtc
->base
.dev
;
2320 struct drm_i915_gem_object
*obj
= NULL
;
2321 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2322 u32 base
= plane_config
->base
;
2324 if (plane_config
->size
== 0)
2327 obj
= i915_gem_object_create_stolen_for_preallocated(dev
, base
, base
,
2328 plane_config
->size
);
2332 if (plane_config
->tiled
) {
2333 obj
->tiling_mode
= I915_TILING_X
;
2334 obj
->stride
= crtc
->base
.primary
->fb
->pitches
[0];
2337 mode_cmd
.pixel_format
= crtc
->base
.primary
->fb
->pixel_format
;
2338 mode_cmd
.width
= crtc
->base
.primary
->fb
->width
;
2339 mode_cmd
.height
= crtc
->base
.primary
->fb
->height
;
2340 mode_cmd
.pitches
[0] = crtc
->base
.primary
->fb
->pitches
[0];
2342 mutex_lock(&dev
->struct_mutex
);
2344 if (intel_framebuffer_init(dev
, to_intel_framebuffer(crtc
->base
.primary
->fb
),
2346 DRM_DEBUG_KMS("intel fb init failed\n");
2350 obj
->frontbuffer_bits
= INTEL_FRONTBUFFER_PRIMARY(crtc
->pipe
);
2351 mutex_unlock(&dev
->struct_mutex
);
2353 DRM_DEBUG_KMS("plane fb obj %p\n", obj
);
2357 drm_gem_object_unreference(&obj
->base
);
2358 mutex_unlock(&dev
->struct_mutex
);
2362 static void intel_find_plane_obj(struct intel_crtc
*intel_crtc
,
2363 struct intel_plane_config
*plane_config
)
2365 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2366 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2368 struct intel_crtc
*i
;
2369 struct drm_i915_gem_object
*obj
;
2371 if (!intel_crtc
->base
.primary
->fb
)
2374 if (intel_alloc_plane_obj(intel_crtc
, plane_config
))
2377 kfree(intel_crtc
->base
.primary
->fb
);
2378 intel_crtc
->base
.primary
->fb
= NULL
;
2381 * Failed to alloc the obj, check to see if we should share
2382 * an fb with another CRTC instead
2384 for_each_crtc(dev
, c
) {
2385 i
= to_intel_crtc(c
);
2387 if (c
== &intel_crtc
->base
)
2393 obj
= intel_fb_obj(c
->primary
->fb
);
2397 if (i915_gem_obj_ggtt_offset(obj
) == plane_config
->base
) {
2398 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2399 dev_priv
->preserve_bios_swizzle
= true;
2401 drm_framebuffer_reference(c
->primary
->fb
);
2402 intel_crtc
->base
.primary
->fb
= c
->primary
->fb
;
2403 obj
->frontbuffer_bits
|= INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
);
2409 static void i9xx_update_primary_plane(struct drm_crtc
*crtc
,
2410 struct drm_framebuffer
*fb
,
2413 struct drm_device
*dev
= crtc
->dev
;
2414 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2415 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2416 struct drm_i915_gem_object
*obj
;
2417 int plane
= intel_crtc
->plane
;
2418 unsigned long linear_offset
;
2420 u32 reg
= DSPCNTR(plane
);
2423 if (!intel_crtc
->primary_enabled
) {
2425 if (INTEL_INFO(dev
)->gen
>= 4)
2426 I915_WRITE(DSPSURF(plane
), 0);
2428 I915_WRITE(DSPADDR(plane
), 0);
2433 obj
= intel_fb_obj(fb
);
2434 if (WARN_ON(obj
== NULL
))
2437 pixel_size
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2439 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2441 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2443 if (INTEL_INFO(dev
)->gen
< 4) {
2444 if (intel_crtc
->pipe
== PIPE_B
)
2445 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
2447 /* pipesrc and dspsize control the size that is scaled from,
2448 * which should always be the user's requested size.
2450 I915_WRITE(DSPSIZE(plane
),
2451 ((intel_crtc
->config
.pipe_src_h
- 1) << 16) |
2452 (intel_crtc
->config
.pipe_src_w
- 1));
2453 I915_WRITE(DSPPOS(plane
), 0);
2454 } else if (IS_CHERRYVIEW(dev
) && plane
== PLANE_B
) {
2455 I915_WRITE(PRIMSIZE(plane
),
2456 ((intel_crtc
->config
.pipe_src_h
- 1) << 16) |
2457 (intel_crtc
->config
.pipe_src_w
- 1));
2458 I915_WRITE(PRIMPOS(plane
), 0);
2459 I915_WRITE(PRIMCNSTALPHA(plane
), 0);
2462 switch (fb
->pixel_format
) {
2464 dspcntr
|= DISPPLANE_8BPP
;
2466 case DRM_FORMAT_XRGB1555
:
2467 case DRM_FORMAT_ARGB1555
:
2468 dspcntr
|= DISPPLANE_BGRX555
;
2470 case DRM_FORMAT_RGB565
:
2471 dspcntr
|= DISPPLANE_BGRX565
;
2473 case DRM_FORMAT_XRGB8888
:
2474 case DRM_FORMAT_ARGB8888
:
2475 dspcntr
|= DISPPLANE_BGRX888
;
2477 case DRM_FORMAT_XBGR8888
:
2478 case DRM_FORMAT_ABGR8888
:
2479 dspcntr
|= DISPPLANE_RGBX888
;
2481 case DRM_FORMAT_XRGB2101010
:
2482 case DRM_FORMAT_ARGB2101010
:
2483 dspcntr
|= DISPPLANE_BGRX101010
;
2485 case DRM_FORMAT_XBGR2101010
:
2486 case DRM_FORMAT_ABGR2101010
:
2487 dspcntr
|= DISPPLANE_RGBX101010
;
2493 if (INTEL_INFO(dev
)->gen
>= 4 &&
2494 obj
->tiling_mode
!= I915_TILING_NONE
)
2495 dspcntr
|= DISPPLANE_TILED
;
2498 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2500 linear_offset
= y
* fb
->pitches
[0] + x
* pixel_size
;
2502 if (INTEL_INFO(dev
)->gen
>= 4) {
2503 intel_crtc
->dspaddr_offset
=
2504 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2507 linear_offset
-= intel_crtc
->dspaddr_offset
;
2509 intel_crtc
->dspaddr_offset
= linear_offset
;
2512 if (to_intel_plane(crtc
->primary
)->rotation
== BIT(DRM_ROTATE_180
)) {
2513 dspcntr
|= DISPPLANE_ROTATE_180
;
2515 x
+= (intel_crtc
->config
.pipe_src_w
- 1);
2516 y
+= (intel_crtc
->config
.pipe_src_h
- 1);
2518 /* Finding the last pixel of the last line of the display
2519 data and adding to linear_offset*/
2521 (intel_crtc
->config
.pipe_src_h
- 1) * fb
->pitches
[0] +
2522 (intel_crtc
->config
.pipe_src_w
- 1) * pixel_size
;
2525 I915_WRITE(reg
, dspcntr
);
2527 DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
2528 i915_gem_obj_ggtt_offset(obj
), linear_offset
, x
, y
,
2530 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2531 if (INTEL_INFO(dev
)->gen
>= 4) {
2532 I915_WRITE(DSPSURF(plane
),
2533 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2534 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2535 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2537 I915_WRITE(DSPADDR(plane
), i915_gem_obj_ggtt_offset(obj
) + linear_offset
);
2541 static void ironlake_update_primary_plane(struct drm_crtc
*crtc
,
2542 struct drm_framebuffer
*fb
,
2545 struct drm_device
*dev
= crtc
->dev
;
2546 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2547 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2548 struct drm_i915_gem_object
*obj
;
2549 int plane
= intel_crtc
->plane
;
2550 unsigned long linear_offset
;
2552 u32 reg
= DSPCNTR(plane
);
2555 if (!intel_crtc
->primary_enabled
) {
2557 I915_WRITE(DSPSURF(plane
), 0);
2562 obj
= intel_fb_obj(fb
);
2563 if (WARN_ON(obj
== NULL
))
2566 pixel_size
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2568 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2570 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2572 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2573 dspcntr
|= DISPPLANE_PIPE_CSC_ENABLE
;
2575 switch (fb
->pixel_format
) {
2577 dspcntr
|= DISPPLANE_8BPP
;
2579 case DRM_FORMAT_RGB565
:
2580 dspcntr
|= DISPPLANE_BGRX565
;
2582 case DRM_FORMAT_XRGB8888
:
2583 case DRM_FORMAT_ARGB8888
:
2584 dspcntr
|= DISPPLANE_BGRX888
;
2586 case DRM_FORMAT_XBGR8888
:
2587 case DRM_FORMAT_ABGR8888
:
2588 dspcntr
|= DISPPLANE_RGBX888
;
2590 case DRM_FORMAT_XRGB2101010
:
2591 case DRM_FORMAT_ARGB2101010
:
2592 dspcntr
|= DISPPLANE_BGRX101010
;
2594 case DRM_FORMAT_XBGR2101010
:
2595 case DRM_FORMAT_ABGR2101010
:
2596 dspcntr
|= DISPPLANE_RGBX101010
;
2602 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2603 dspcntr
|= DISPPLANE_TILED
;
2605 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
))
2606 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2608 linear_offset
= y
* fb
->pitches
[0] + x
* pixel_size
;
2609 intel_crtc
->dspaddr_offset
=
2610 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2613 linear_offset
-= intel_crtc
->dspaddr_offset
;
2614 if (to_intel_plane(crtc
->primary
)->rotation
== BIT(DRM_ROTATE_180
)) {
2615 dspcntr
|= DISPPLANE_ROTATE_180
;
2617 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
)) {
2618 x
+= (intel_crtc
->config
.pipe_src_w
- 1);
2619 y
+= (intel_crtc
->config
.pipe_src_h
- 1);
2621 /* Finding the last pixel of the last line of the display
2622 data and adding to linear_offset*/
2624 (intel_crtc
->config
.pipe_src_h
- 1) * fb
->pitches
[0] +
2625 (intel_crtc
->config
.pipe_src_w
- 1) * pixel_size
;
2629 I915_WRITE(reg
, dspcntr
);
2631 DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
2632 i915_gem_obj_ggtt_offset(obj
), linear_offset
, x
, y
,
2634 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2635 I915_WRITE(DSPSURF(plane
),
2636 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2637 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2638 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
2640 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2641 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2646 static void skylake_update_primary_plane(struct drm_crtc
*crtc
,
2647 struct drm_framebuffer
*fb
,
2650 struct drm_device
*dev
= crtc
->dev
;
2651 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2652 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2653 struct intel_framebuffer
*intel_fb
;
2654 struct drm_i915_gem_object
*obj
;
2655 int pipe
= intel_crtc
->pipe
;
2656 u32 plane_ctl
, stride
;
2658 if (!intel_crtc
->primary_enabled
) {
2659 I915_WRITE(PLANE_CTL(pipe
, 0), 0);
2660 I915_WRITE(PLANE_SURF(pipe
, 0), 0);
2661 POSTING_READ(PLANE_CTL(pipe
, 0));
2665 plane_ctl
= PLANE_CTL_ENABLE
|
2666 PLANE_CTL_PIPE_GAMMA_ENABLE
|
2667 PLANE_CTL_PIPE_CSC_ENABLE
;
2669 switch (fb
->pixel_format
) {
2670 case DRM_FORMAT_RGB565
:
2671 plane_ctl
|= PLANE_CTL_FORMAT_RGB_565
;
2673 case DRM_FORMAT_XRGB8888
:
2674 plane_ctl
|= PLANE_CTL_FORMAT_XRGB_8888
;
2676 case DRM_FORMAT_XBGR8888
:
2677 plane_ctl
|= PLANE_CTL_ORDER_RGBX
;
2678 plane_ctl
|= PLANE_CTL_FORMAT_XRGB_8888
;
2680 case DRM_FORMAT_XRGB2101010
:
2681 plane_ctl
|= PLANE_CTL_FORMAT_XRGB_2101010
;
2683 case DRM_FORMAT_XBGR2101010
:
2684 plane_ctl
|= PLANE_CTL_ORDER_RGBX
;
2685 plane_ctl
|= PLANE_CTL_FORMAT_XRGB_2101010
;
2691 intel_fb
= to_intel_framebuffer(fb
);
2692 obj
= intel_fb
->obj
;
2695 * The stride is either expressed as a multiple of 64 bytes chunks for
2696 * linear buffers or in number of tiles for tiled buffers.
2698 switch (obj
->tiling_mode
) {
2699 case I915_TILING_NONE
:
2700 stride
= fb
->pitches
[0] >> 6;
2703 plane_ctl
|= PLANE_CTL_TILED_X
;
2704 stride
= fb
->pitches
[0] >> 9;
2710 plane_ctl
|= PLANE_CTL_PLANE_GAMMA_DISABLE
;
2711 if (to_intel_plane(crtc
->primary
)->rotation
== BIT(DRM_ROTATE_180
))
2712 plane_ctl
|= PLANE_CTL_ROTATE_180
;
2714 I915_WRITE(PLANE_CTL(pipe
, 0), plane_ctl
);
2716 DRM_DEBUG_KMS("Writing base %08lX %d,%d,%d,%d pitch=%d\n",
2717 i915_gem_obj_ggtt_offset(obj
),
2718 x
, y
, fb
->width
, fb
->height
,
2721 I915_WRITE(PLANE_POS(pipe
, 0), 0);
2722 I915_WRITE(PLANE_OFFSET(pipe
, 0), (y
<< 16) | x
);
2723 I915_WRITE(PLANE_SIZE(pipe
, 0),
2724 (intel_crtc
->config
.pipe_src_h
- 1) << 16 |
2725 (intel_crtc
->config
.pipe_src_w
- 1));
2726 I915_WRITE(PLANE_STRIDE(pipe
, 0), stride
);
2727 I915_WRITE(PLANE_SURF(pipe
, 0), i915_gem_obj_ggtt_offset(obj
));
2729 POSTING_READ(PLANE_SURF(pipe
, 0));
2732 /* Assume fb object is pinned & idle & fenced and just update base pointers */
2734 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
2735 int x
, int y
, enum mode_set_atomic state
)
2737 struct drm_device
*dev
= crtc
->dev
;
2738 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2740 if (dev_priv
->display
.disable_fbc
)
2741 dev_priv
->display
.disable_fbc(dev
);
2743 dev_priv
->display
.update_primary_plane(crtc
, fb
, x
, y
);
2748 void intel_display_handle_reset(struct drm_device
*dev
)
2750 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2751 struct drm_crtc
*crtc
;
2754 * Flips in the rings have been nuked by the reset,
2755 * so complete all pending flips so that user space
2756 * will get its events and not get stuck.
2758 * Also update the base address of all primary
2759 * planes to the the last fb to make sure we're
2760 * showing the correct fb after a reset.
2762 * Need to make two loops over the crtcs so that we
2763 * don't try to grab a crtc mutex before the
2764 * pending_flip_queue really got woken up.
2767 for_each_crtc(dev
, crtc
) {
2768 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2769 enum plane plane
= intel_crtc
->plane
;
2771 intel_prepare_page_flip(dev
, plane
);
2772 intel_finish_page_flip_plane(dev
, plane
);
2775 for_each_crtc(dev
, crtc
) {
2776 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2778 drm_modeset_lock(&crtc
->mutex
, NULL
);
2780 * FIXME: Once we have proper support for primary planes (and
2781 * disabling them without disabling the entire crtc) allow again
2782 * a NULL crtc->primary->fb.
2784 if (intel_crtc
->active
&& crtc
->primary
->fb
)
2785 dev_priv
->display
.update_primary_plane(crtc
,
2789 drm_modeset_unlock(&crtc
->mutex
);
2794 intel_finish_fb(struct drm_framebuffer
*old_fb
)
2796 struct drm_i915_gem_object
*obj
= intel_fb_obj(old_fb
);
2797 struct drm_i915_private
*dev_priv
= obj
->base
.dev
->dev_private
;
2798 bool was_interruptible
= dev_priv
->mm
.interruptible
;
2801 /* Big Hammer, we also need to ensure that any pending
2802 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
2803 * current scanout is retired before unpinning the old
2806 * This should only fail upon a hung GPU, in which case we
2807 * can safely continue.
2809 dev_priv
->mm
.interruptible
= false;
2810 ret
= i915_gem_object_finish_gpu(obj
);
2811 dev_priv
->mm
.interruptible
= was_interruptible
;
2816 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
2818 struct drm_device
*dev
= crtc
->dev
;
2819 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2820 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2823 if (i915_reset_in_progress(&dev_priv
->gpu_error
) ||
2824 intel_crtc
->reset_counter
!= atomic_read(&dev_priv
->gpu_error
.reset_counter
))
2827 spin_lock_irq(&dev
->event_lock
);
2828 pending
= to_intel_crtc(crtc
)->unpin_work
!= NULL
;
2829 spin_unlock_irq(&dev
->event_lock
);
2834 static void intel_update_pipe_size(struct intel_crtc
*crtc
)
2836 struct drm_device
*dev
= crtc
->base
.dev
;
2837 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2838 const struct drm_display_mode
*adjusted_mode
;
2844 * Update pipe size and adjust fitter if needed: the reason for this is
2845 * that in compute_mode_changes we check the native mode (not the pfit
2846 * mode) to see if we can flip rather than do a full mode set. In the
2847 * fastboot case, we'll flip, but if we don't update the pipesrc and
2848 * pfit state, we'll end up with a big fb scanned out into the wrong
2851 * To fix this properly, we need to hoist the checks up into
2852 * compute_mode_changes (or above), check the actual pfit state and
2853 * whether the platform allows pfit disable with pipe active, and only
2854 * then update the pipesrc and pfit state, even on the flip path.
2857 adjusted_mode
= &crtc
->config
.adjusted_mode
;
2859 I915_WRITE(PIPESRC(crtc
->pipe
),
2860 ((adjusted_mode
->crtc_hdisplay
- 1) << 16) |
2861 (adjusted_mode
->crtc_vdisplay
- 1));
2862 if (!crtc
->config
.pch_pfit
.enabled
&&
2863 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) ||
2864 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
2865 I915_WRITE(PF_CTL(crtc
->pipe
), 0);
2866 I915_WRITE(PF_WIN_POS(crtc
->pipe
), 0);
2867 I915_WRITE(PF_WIN_SZ(crtc
->pipe
), 0);
2869 crtc
->config
.pipe_src_w
= adjusted_mode
->crtc_hdisplay
;
2870 crtc
->config
.pipe_src_h
= adjusted_mode
->crtc_vdisplay
;
2874 intel_pipe_set_base(struct drm_crtc
*crtc
, int x
, int y
,
2875 struct drm_framebuffer
*fb
)
2877 struct drm_device
*dev
= crtc
->dev
;
2878 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2879 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2880 enum pipe pipe
= intel_crtc
->pipe
;
2881 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
2882 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2883 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(old_fb
);
2886 if (intel_crtc_has_pending_flip(crtc
)) {
2887 DRM_ERROR("pipe is still busy with an old pageflip\n");
2893 DRM_ERROR("No FB bound\n");
2897 if (intel_crtc
->plane
> INTEL_INFO(dev
)->num_pipes
) {
2898 DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
2899 plane_name(intel_crtc
->plane
),
2900 INTEL_INFO(dev
)->num_pipes
);
2904 mutex_lock(&dev
->struct_mutex
);
2905 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, NULL
);
2907 i915_gem_track_fb(old_obj
, obj
,
2908 INTEL_FRONTBUFFER_PRIMARY(pipe
));
2909 mutex_unlock(&dev
->struct_mutex
);
2911 DRM_ERROR("pin & fence failed\n");
2915 intel_update_pipe_size(intel_crtc
);
2917 dev_priv
->display
.update_primary_plane(crtc
, fb
, x
, y
);
2919 if (intel_crtc
->active
)
2920 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
2922 crtc
->primary
->fb
= fb
;
2927 if (intel_crtc
->active
&& old_fb
!= fb
)
2928 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
2929 mutex_lock(&dev
->struct_mutex
);
2930 intel_unpin_fb_obj(old_obj
);
2931 mutex_unlock(&dev
->struct_mutex
);
2934 mutex_lock(&dev
->struct_mutex
);
2935 intel_update_fbc(dev
);
2936 mutex_unlock(&dev
->struct_mutex
);
2941 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
2943 struct drm_device
*dev
= crtc
->dev
;
2944 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2945 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2946 int pipe
= intel_crtc
->pipe
;
2949 /* enable normal train */
2950 reg
= FDI_TX_CTL(pipe
);
2951 temp
= I915_READ(reg
);
2952 if (IS_IVYBRIDGE(dev
)) {
2953 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
2954 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2956 temp
&= ~FDI_LINK_TRAIN_NONE
;
2957 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2959 I915_WRITE(reg
, temp
);
2961 reg
= FDI_RX_CTL(pipe
);
2962 temp
= I915_READ(reg
);
2963 if (HAS_PCH_CPT(dev
)) {
2964 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2965 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
2967 temp
&= ~FDI_LINK_TRAIN_NONE
;
2968 temp
|= FDI_LINK_TRAIN_NONE
;
2970 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
2972 /* wait one idle pattern time */
2976 /* IVB wants error correction enabled */
2977 if (IS_IVYBRIDGE(dev
))
2978 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
2979 FDI_FE_ERRC_ENABLE
);
2982 static bool pipe_has_enabled_pch(struct intel_crtc
*crtc
)
2984 return crtc
->base
.enabled
&& crtc
->active
&&
2985 crtc
->config
.has_pch_encoder
;
2988 static void ivb_modeset_global_resources(struct drm_device
*dev
)
2990 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2991 struct intel_crtc
*pipe_B_crtc
=
2992 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
2993 struct intel_crtc
*pipe_C_crtc
=
2994 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]);
2998 * When everything is off disable fdi C so that we could enable fdi B
2999 * with all lanes. Note that we don't care about enabled pipes without
3000 * an enabled pch encoder.
3002 if (!pipe_has_enabled_pch(pipe_B_crtc
) &&
3003 !pipe_has_enabled_pch(pipe_C_crtc
)) {
3004 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
3005 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
3007 temp
= I915_READ(SOUTH_CHICKEN1
);
3008 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
3009 DRM_DEBUG_KMS("disabling fdi C rx\n");
3010 I915_WRITE(SOUTH_CHICKEN1
, temp
);
3014 /* The FDI link training functions for ILK/Ibexpeak. */
3015 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
3017 struct drm_device
*dev
= crtc
->dev
;
3018 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3019 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3020 int pipe
= intel_crtc
->pipe
;
3021 u32 reg
, temp
, tries
;
3023 /* FDI needs bits from pipe first */
3024 assert_pipe_enabled(dev_priv
, pipe
);
3026 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3028 reg
= FDI_RX_IMR(pipe
);
3029 temp
= I915_READ(reg
);
3030 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3031 temp
&= ~FDI_RX_BIT_LOCK
;
3032 I915_WRITE(reg
, temp
);
3036 /* enable CPU FDI TX and PCH FDI RX */
3037 reg
= FDI_TX_CTL(pipe
);
3038 temp
= I915_READ(reg
);
3039 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3040 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
3041 temp
&= ~FDI_LINK_TRAIN_NONE
;
3042 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3043 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3045 reg
= FDI_RX_CTL(pipe
);
3046 temp
= I915_READ(reg
);
3047 temp
&= ~FDI_LINK_TRAIN_NONE
;
3048 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3049 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3054 /* Ironlake workaround, enable clock pointer after FDI enable*/
3055 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3056 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
3057 FDI_RX_PHASE_SYNC_POINTER_EN
);
3059 reg
= FDI_RX_IIR(pipe
);
3060 for (tries
= 0; tries
< 5; tries
++) {
3061 temp
= I915_READ(reg
);
3062 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3064 if ((temp
& FDI_RX_BIT_LOCK
)) {
3065 DRM_DEBUG_KMS("FDI train 1 done.\n");
3066 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3071 DRM_ERROR("FDI train 1 fail!\n");
3074 reg
= FDI_TX_CTL(pipe
);
3075 temp
= I915_READ(reg
);
3076 temp
&= ~FDI_LINK_TRAIN_NONE
;
3077 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3078 I915_WRITE(reg
, temp
);
3080 reg
= FDI_RX_CTL(pipe
);
3081 temp
= I915_READ(reg
);
3082 temp
&= ~FDI_LINK_TRAIN_NONE
;
3083 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3084 I915_WRITE(reg
, temp
);
3089 reg
= FDI_RX_IIR(pipe
);
3090 for (tries
= 0; tries
< 5; tries
++) {
3091 temp
= I915_READ(reg
);
3092 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3094 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3095 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3096 DRM_DEBUG_KMS("FDI train 2 done.\n");
3101 DRM_ERROR("FDI train 2 fail!\n");
3103 DRM_DEBUG_KMS("FDI train done\n");
3107 static const int snb_b_fdi_train_param
[] = {
3108 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
3109 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
3110 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
3111 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
3114 /* The FDI link training functions for SNB/Cougarpoint. */
3115 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
3117 struct drm_device
*dev
= crtc
->dev
;
3118 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3119 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3120 int pipe
= intel_crtc
->pipe
;
3121 u32 reg
, temp
, i
, retry
;
3123 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3125 reg
= FDI_RX_IMR(pipe
);
3126 temp
= I915_READ(reg
);
3127 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3128 temp
&= ~FDI_RX_BIT_LOCK
;
3129 I915_WRITE(reg
, temp
);
3134 /* enable CPU FDI TX and PCH FDI RX */
3135 reg
= FDI_TX_CTL(pipe
);
3136 temp
= I915_READ(reg
);
3137 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3138 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
3139 temp
&= ~FDI_LINK_TRAIN_NONE
;
3140 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3141 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3143 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3144 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3146 I915_WRITE(FDI_RX_MISC(pipe
),
3147 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3149 reg
= FDI_RX_CTL(pipe
);
3150 temp
= I915_READ(reg
);
3151 if (HAS_PCH_CPT(dev
)) {
3152 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3153 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3155 temp
&= ~FDI_LINK_TRAIN_NONE
;
3156 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3158 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3163 for (i
= 0; i
< 4; i
++) {
3164 reg
= FDI_TX_CTL(pipe
);
3165 temp
= I915_READ(reg
);
3166 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3167 temp
|= snb_b_fdi_train_param
[i
];
3168 I915_WRITE(reg
, temp
);
3173 for (retry
= 0; retry
< 5; retry
++) {
3174 reg
= FDI_RX_IIR(pipe
);
3175 temp
= I915_READ(reg
);
3176 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3177 if (temp
& FDI_RX_BIT_LOCK
) {
3178 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3179 DRM_DEBUG_KMS("FDI train 1 done.\n");
3188 DRM_ERROR("FDI train 1 fail!\n");
3191 reg
= FDI_TX_CTL(pipe
);
3192 temp
= I915_READ(reg
);
3193 temp
&= ~FDI_LINK_TRAIN_NONE
;
3194 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3196 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3198 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3200 I915_WRITE(reg
, temp
);
3202 reg
= FDI_RX_CTL(pipe
);
3203 temp
= I915_READ(reg
);
3204 if (HAS_PCH_CPT(dev
)) {
3205 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3206 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3208 temp
&= ~FDI_LINK_TRAIN_NONE
;
3209 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3211 I915_WRITE(reg
, temp
);
3216 for (i
= 0; i
< 4; i
++) {
3217 reg
= FDI_TX_CTL(pipe
);
3218 temp
= I915_READ(reg
);
3219 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3220 temp
|= snb_b_fdi_train_param
[i
];
3221 I915_WRITE(reg
, temp
);
3226 for (retry
= 0; retry
< 5; retry
++) {
3227 reg
= FDI_RX_IIR(pipe
);
3228 temp
= I915_READ(reg
);
3229 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3230 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3231 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3232 DRM_DEBUG_KMS("FDI train 2 done.\n");
3241 DRM_ERROR("FDI train 2 fail!\n");
3243 DRM_DEBUG_KMS("FDI train done.\n");
3246 /* Manual link training for Ivy Bridge A0 parts */
3247 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
3249 struct drm_device
*dev
= crtc
->dev
;
3250 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3251 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3252 int pipe
= intel_crtc
->pipe
;
3253 u32 reg
, temp
, i
, j
;
3255 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3257 reg
= FDI_RX_IMR(pipe
);
3258 temp
= I915_READ(reg
);
3259 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3260 temp
&= ~FDI_RX_BIT_LOCK
;
3261 I915_WRITE(reg
, temp
);
3266 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3267 I915_READ(FDI_RX_IIR(pipe
)));
3269 /* Try each vswing and preemphasis setting twice before moving on */
3270 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
3271 /* disable first in case we need to retry */
3272 reg
= FDI_TX_CTL(pipe
);
3273 temp
= I915_READ(reg
);
3274 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
3275 temp
&= ~FDI_TX_ENABLE
;
3276 I915_WRITE(reg
, temp
);
3278 reg
= FDI_RX_CTL(pipe
);
3279 temp
= I915_READ(reg
);
3280 temp
&= ~FDI_LINK_TRAIN_AUTO
;
3281 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3282 temp
&= ~FDI_RX_ENABLE
;
3283 I915_WRITE(reg
, temp
);
3285 /* enable CPU FDI TX and PCH FDI RX */
3286 reg
= FDI_TX_CTL(pipe
);
3287 temp
= I915_READ(reg
);
3288 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3289 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
3290 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
3291 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3292 temp
|= snb_b_fdi_train_param
[j
/2];
3293 temp
|= FDI_COMPOSITE_SYNC
;
3294 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3296 I915_WRITE(FDI_RX_MISC(pipe
),
3297 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3299 reg
= FDI_RX_CTL(pipe
);
3300 temp
= I915_READ(reg
);
3301 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3302 temp
|= FDI_COMPOSITE_SYNC
;
3303 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3306 udelay(1); /* should be 0.5us */
3308 for (i
= 0; i
< 4; i
++) {
3309 reg
= FDI_RX_IIR(pipe
);
3310 temp
= I915_READ(reg
);
3311 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3313 if (temp
& FDI_RX_BIT_LOCK
||
3314 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
3315 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3316 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3320 udelay(1); /* should be 0.5us */
3323 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
3328 reg
= FDI_TX_CTL(pipe
);
3329 temp
= I915_READ(reg
);
3330 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3331 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
3332 I915_WRITE(reg
, temp
);
3334 reg
= FDI_RX_CTL(pipe
);
3335 temp
= I915_READ(reg
);
3336 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3337 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3338 I915_WRITE(reg
, temp
);
3341 udelay(2); /* should be 1.5us */
3343 for (i
= 0; i
< 4; i
++) {
3344 reg
= FDI_RX_IIR(pipe
);
3345 temp
= I915_READ(reg
);
3346 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3348 if (temp
& FDI_RX_SYMBOL_LOCK
||
3349 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
3350 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3351 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
3355 udelay(2); /* should be 1.5us */
3358 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
3362 DRM_DEBUG_KMS("FDI train done.\n");
3365 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
3367 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3368 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3369 int pipe
= intel_crtc
->pipe
;
3373 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
3374 reg
= FDI_RX_CTL(pipe
);
3375 temp
= I915_READ(reg
);
3376 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
3377 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
3378 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3379 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
3384 /* Switch from Rawclk to PCDclk */
3385 temp
= I915_READ(reg
);
3386 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
3391 /* Enable CPU FDI TX PLL, always on for Ironlake */
3392 reg
= FDI_TX_CTL(pipe
);
3393 temp
= I915_READ(reg
);
3394 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
3395 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
3402 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
3404 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3405 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3406 int pipe
= intel_crtc
->pipe
;
3409 /* Switch from PCDclk to Rawclk */
3410 reg
= FDI_RX_CTL(pipe
);
3411 temp
= I915_READ(reg
);
3412 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
3414 /* Disable CPU FDI TX PLL */
3415 reg
= FDI_TX_CTL(pipe
);
3416 temp
= I915_READ(reg
);
3417 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
3422 reg
= FDI_RX_CTL(pipe
);
3423 temp
= I915_READ(reg
);
3424 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
3426 /* Wait for the clocks to turn off. */
3431 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
3433 struct drm_device
*dev
= crtc
->dev
;
3434 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3435 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3436 int pipe
= intel_crtc
->pipe
;
3439 /* disable CPU FDI tx and PCH FDI rx */
3440 reg
= FDI_TX_CTL(pipe
);
3441 temp
= I915_READ(reg
);
3442 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
3445 reg
= FDI_RX_CTL(pipe
);
3446 temp
= I915_READ(reg
);
3447 temp
&= ~(0x7 << 16);
3448 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3449 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
3454 /* Ironlake workaround, disable clock pointer after downing FDI */
3455 if (HAS_PCH_IBX(dev
))
3456 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3458 /* still set train pattern 1 */
3459 reg
= FDI_TX_CTL(pipe
);
3460 temp
= I915_READ(reg
);
3461 temp
&= ~FDI_LINK_TRAIN_NONE
;
3462 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3463 I915_WRITE(reg
, temp
);
3465 reg
= FDI_RX_CTL(pipe
);
3466 temp
= I915_READ(reg
);
3467 if (HAS_PCH_CPT(dev
)) {
3468 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3469 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3471 temp
&= ~FDI_LINK_TRAIN_NONE
;
3472 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3474 /* BPC in FDI rx is consistent with that in PIPECONF */
3475 temp
&= ~(0x07 << 16);
3476 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3477 I915_WRITE(reg
, temp
);
3483 bool intel_has_pending_fb_unpin(struct drm_device
*dev
)
3485 struct intel_crtc
*crtc
;
3487 /* Note that we don't need to be called with mode_config.lock here
3488 * as our list of CRTC objects is static for the lifetime of the
3489 * device and so cannot disappear as we iterate. Similarly, we can
3490 * happily treat the predicates as racy, atomic checks as userspace
3491 * cannot claim and pin a new fb without at least acquring the
3492 * struct_mutex and so serialising with us.
3494 for_each_intel_crtc(dev
, crtc
) {
3495 if (atomic_read(&crtc
->unpin_work_count
) == 0)
3498 if (crtc
->unpin_work
)
3499 intel_wait_for_vblank(dev
, crtc
->pipe
);
3507 static void page_flip_completed(struct intel_crtc
*intel_crtc
)
3509 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
3510 struct intel_unpin_work
*work
= intel_crtc
->unpin_work
;
3512 /* ensure that the unpin work is consistent wrt ->pending. */
3514 intel_crtc
->unpin_work
= NULL
;
3517 drm_send_vblank_event(intel_crtc
->base
.dev
,
3521 drm_crtc_vblank_put(&intel_crtc
->base
);
3523 wake_up_all(&dev_priv
->pending_flip_queue
);
3524 queue_work(dev_priv
->wq
, &work
->work
);
3526 trace_i915_flip_complete(intel_crtc
->plane
,
3527 work
->pending_flip_obj
);
3530 void intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
3532 struct drm_device
*dev
= crtc
->dev
;
3533 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3535 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
3536 if (WARN_ON(wait_event_timeout(dev_priv
->pending_flip_queue
,
3537 !intel_crtc_has_pending_flip(crtc
),
3539 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3541 spin_lock_irq(&dev
->event_lock
);
3542 if (intel_crtc
->unpin_work
) {
3543 WARN_ONCE(1, "Removing stuck page flip\n");
3544 page_flip_completed(intel_crtc
);
3546 spin_unlock_irq(&dev
->event_lock
);
3549 if (crtc
->primary
->fb
) {
3550 mutex_lock(&dev
->struct_mutex
);
3551 intel_finish_fb(crtc
->primary
->fb
);
3552 mutex_unlock(&dev
->struct_mutex
);
3556 /* Program iCLKIP clock to the desired frequency */
3557 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
3559 struct drm_device
*dev
= crtc
->dev
;
3560 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3561 int clock
= to_intel_crtc(crtc
)->config
.adjusted_mode
.crtc_clock
;
3562 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
3565 mutex_lock(&dev_priv
->dpio_lock
);
3567 /* It is necessary to ungate the pixclk gate prior to programming
3568 * the divisors, and gate it back when it is done.
3570 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
3572 /* Disable SSCCTL */
3573 intel_sbi_write(dev_priv
, SBI_SSCCTL6
,
3574 intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
) |
3578 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
3579 if (clock
== 20000) {
3584 /* The iCLK virtual clock root frequency is in MHz,
3585 * but the adjusted_mode->crtc_clock in in KHz. To get the
3586 * divisors, it is necessary to divide one by another, so we
3587 * convert the virtual clock precision to KHz here for higher
3590 u32 iclk_virtual_root_freq
= 172800 * 1000;
3591 u32 iclk_pi_range
= 64;
3592 u32 desired_divisor
, msb_divisor_value
, pi_value
;
3594 desired_divisor
= (iclk_virtual_root_freq
/ clock
);
3595 msb_divisor_value
= desired_divisor
/ iclk_pi_range
;
3596 pi_value
= desired_divisor
% iclk_pi_range
;
3599 divsel
= msb_divisor_value
- 2;
3600 phaseinc
= pi_value
;
3603 /* This should not happen with any sane values */
3604 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
3605 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
3606 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
3607 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
3609 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3616 /* Program SSCDIVINTPHASE6 */
3617 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
3618 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
3619 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
3620 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
3621 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
3622 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
3623 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
3624 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
3626 /* Program SSCAUXDIV */
3627 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
3628 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3629 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
3630 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
3632 /* Enable modulator and associated divider */
3633 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
3634 temp
&= ~SBI_SSCCTL_DISABLE
;
3635 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
3637 /* Wait for initialization time */
3640 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
3642 mutex_unlock(&dev_priv
->dpio_lock
);
3645 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
3646 enum pipe pch_transcoder
)
3648 struct drm_device
*dev
= crtc
->base
.dev
;
3649 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3650 enum transcoder cpu_transcoder
= crtc
->config
.cpu_transcoder
;
3652 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
3653 I915_READ(HTOTAL(cpu_transcoder
)));
3654 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
3655 I915_READ(HBLANK(cpu_transcoder
)));
3656 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
3657 I915_READ(HSYNC(cpu_transcoder
)));
3659 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
3660 I915_READ(VTOTAL(cpu_transcoder
)));
3661 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
3662 I915_READ(VBLANK(cpu_transcoder
)));
3663 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
3664 I915_READ(VSYNC(cpu_transcoder
)));
3665 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
3666 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
3669 static void cpt_enable_fdi_bc_bifurcation(struct drm_device
*dev
)
3671 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3674 temp
= I915_READ(SOUTH_CHICKEN1
);
3675 if (temp
& FDI_BC_BIFURCATION_SELECT
)
3678 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
3679 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
3681 temp
|= FDI_BC_BIFURCATION_SELECT
;
3682 DRM_DEBUG_KMS("enabling fdi C rx\n");
3683 I915_WRITE(SOUTH_CHICKEN1
, temp
);
3684 POSTING_READ(SOUTH_CHICKEN1
);
3687 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
3689 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3690 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3692 switch (intel_crtc
->pipe
) {
3696 if (intel_crtc
->config
.fdi_lanes
> 2)
3697 WARN_ON(I915_READ(SOUTH_CHICKEN1
) & FDI_BC_BIFURCATION_SELECT
);
3699 cpt_enable_fdi_bc_bifurcation(dev
);
3703 cpt_enable_fdi_bc_bifurcation(dev
);
3712 * Enable PCH resources required for PCH ports:
3714 * - FDI training & RX/TX
3715 * - update transcoder timings
3716 * - DP transcoding bits
3719 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
3721 struct drm_device
*dev
= crtc
->dev
;
3722 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3723 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3724 int pipe
= intel_crtc
->pipe
;
3727 assert_pch_transcoder_disabled(dev_priv
, pipe
);
3729 if (IS_IVYBRIDGE(dev
))
3730 ivybridge_update_fdi_bc_bifurcation(intel_crtc
);
3732 /* Write the TU size bits before fdi link training, so that error
3733 * detection works. */
3734 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
3735 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
3737 /* For PCH output, training FDI link */
3738 dev_priv
->display
.fdi_link_train(crtc
);
3740 /* We need to program the right clock selection before writing the pixel
3741 * mutliplier into the DPLL. */
3742 if (HAS_PCH_CPT(dev
)) {
3745 temp
= I915_READ(PCH_DPLL_SEL
);
3746 temp
|= TRANS_DPLL_ENABLE(pipe
);
3747 sel
= TRANS_DPLLB_SEL(pipe
);
3748 if (intel_crtc
->config
.shared_dpll
== DPLL_ID_PCH_PLL_B
)
3752 I915_WRITE(PCH_DPLL_SEL
, temp
);
3755 /* XXX: pch pll's can be enabled any time before we enable the PCH
3756 * transcoder, and we actually should do this to not upset any PCH
3757 * transcoder that already use the clock when we share it.
3759 * Note that enable_shared_dpll tries to do the right thing, but
3760 * get_shared_dpll unconditionally resets the pll - we need that to have
3761 * the right LVDS enable sequence. */
3762 intel_enable_shared_dpll(intel_crtc
);
3764 /* set transcoder timing, panel must allow it */
3765 assert_panel_unlocked(dev_priv
, pipe
);
3766 ironlake_pch_transcoder_set_timings(intel_crtc
, pipe
);
3768 intel_fdi_normal_train(crtc
);
3770 /* For PCH DP, enable TRANS_DP_CTL */
3771 if (HAS_PCH_CPT(dev
) &&
3772 (intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
3773 intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_EDP
))) {
3774 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
3775 reg
= TRANS_DP_CTL(pipe
);
3776 temp
= I915_READ(reg
);
3777 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
3778 TRANS_DP_SYNC_MASK
|
3780 temp
|= (TRANS_DP_OUTPUT_ENABLE
|
3781 TRANS_DP_ENH_FRAMING
);
3782 temp
|= bpc
<< 9; /* same format but at 11:9 */
3784 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PHSYNC
)
3785 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
3786 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PVSYNC
)
3787 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
3789 switch (intel_trans_dp_port_sel(crtc
)) {
3791 temp
|= TRANS_DP_PORT_SEL_B
;
3794 temp
|= TRANS_DP_PORT_SEL_C
;
3797 temp
|= TRANS_DP_PORT_SEL_D
;
3803 I915_WRITE(reg
, temp
);
3806 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
3809 static void lpt_pch_enable(struct drm_crtc
*crtc
)
3811 struct drm_device
*dev
= crtc
->dev
;
3812 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3813 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3814 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
3816 assert_pch_transcoder_disabled(dev_priv
, TRANSCODER_A
);
3818 lpt_program_iclkip(crtc
);
3820 /* Set transcoder timing. */
3821 ironlake_pch_transcoder_set_timings(intel_crtc
, PIPE_A
);
3823 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
3826 void intel_put_shared_dpll(struct intel_crtc
*crtc
)
3828 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
3833 if (pll
->refcount
== 0) {
3834 WARN(1, "bad %s refcount\n", pll
->name
);
3838 if (--pll
->refcount
== 0) {
3840 WARN_ON(pll
->active
);
3843 crtc
->config
.shared_dpll
= DPLL_ID_PRIVATE
;
3846 struct intel_shared_dpll
*intel_get_shared_dpll(struct intel_crtc
*crtc
)
3848 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
3849 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
3850 enum intel_dpll_id i
;
3853 DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
3854 crtc
->base
.base
.id
, pll
->name
);
3855 intel_put_shared_dpll(crtc
);
3858 if (HAS_PCH_IBX(dev_priv
->dev
)) {
3859 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
3860 i
= (enum intel_dpll_id
) crtc
->pipe
;
3861 pll
= &dev_priv
->shared_dplls
[i
];
3863 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
3864 crtc
->base
.base
.id
, pll
->name
);
3866 WARN_ON(pll
->refcount
);
3871 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
3872 pll
= &dev_priv
->shared_dplls
[i
];
3874 /* Only want to check enabled timings first */
3875 if (pll
->refcount
== 0)
3878 if (memcmp(&crtc
->config
.dpll_hw_state
, &pll
->hw_state
,
3879 sizeof(pll
->hw_state
)) == 0) {
3880 DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
3882 pll
->name
, pll
->refcount
, pll
->active
);
3888 /* Ok no matching timings, maybe there's a free one? */
3889 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
3890 pll
= &dev_priv
->shared_dplls
[i
];
3891 if (pll
->refcount
== 0) {
3892 DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
3893 crtc
->base
.base
.id
, pll
->name
);
3901 if (pll
->refcount
== 0)
3902 pll
->hw_state
= crtc
->config
.dpll_hw_state
;
3904 crtc
->config
.shared_dpll
= i
;
3905 DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll
->name
,
3906 pipe_name(crtc
->pipe
));
3913 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
3915 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3916 int dslreg
= PIPEDSL(pipe
);
3919 temp
= I915_READ(dslreg
);
3921 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
3922 if (wait_for(I915_READ(dslreg
) != temp
, 5))
3923 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
3927 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
3929 struct drm_device
*dev
= crtc
->base
.dev
;
3930 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3931 int pipe
= crtc
->pipe
;
3933 if (crtc
->config
.pch_pfit
.enabled
) {
3934 /* Force use of hard-coded filter coefficients
3935 * as some pre-programmed values are broken,
3938 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
))
3939 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
3940 PF_PIPE_SEL_IVB(pipe
));
3942 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
3943 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
.pch_pfit
.pos
);
3944 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
.pch_pfit
.size
);
3948 static void intel_enable_planes(struct drm_crtc
*crtc
)
3950 struct drm_device
*dev
= crtc
->dev
;
3951 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
3952 struct drm_plane
*plane
;
3953 struct intel_plane
*intel_plane
;
3955 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
3956 intel_plane
= to_intel_plane(plane
);
3957 if (intel_plane
->pipe
== pipe
)
3958 intel_plane_restore(&intel_plane
->base
);
3962 static void intel_disable_planes(struct drm_crtc
*crtc
)
3964 struct drm_device
*dev
= crtc
->dev
;
3965 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
3966 struct drm_plane
*plane
;
3967 struct intel_plane
*intel_plane
;
3969 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
3970 intel_plane
= to_intel_plane(plane
);
3971 if (intel_plane
->pipe
== pipe
)
3972 intel_plane_disable(&intel_plane
->base
);
3976 void hsw_enable_ips(struct intel_crtc
*crtc
)
3978 struct drm_device
*dev
= crtc
->base
.dev
;
3979 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3981 if (!crtc
->config
.ips_enabled
)
3984 /* We can only enable IPS after we enable a plane and wait for a vblank */
3985 intel_wait_for_vblank(dev
, crtc
->pipe
);
3987 assert_plane_enabled(dev_priv
, crtc
->plane
);
3988 if (IS_BROADWELL(dev
)) {
3989 mutex_lock(&dev_priv
->rps
.hw_lock
);
3990 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
3991 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3992 /* Quoting Art Runyan: "its not safe to expect any particular
3993 * value in IPS_CTL bit 31 after enabling IPS through the
3994 * mailbox." Moreover, the mailbox may return a bogus state,
3995 * so we need to just enable it and continue on.
3998 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
3999 /* The bit only becomes 1 in the next vblank, so this wait here
4000 * is essentially intel_wait_for_vblank. If we don't have this
4001 * and don't wait for vblanks until the end of crtc_enable, then
4002 * the HW state readout code will complain that the expected
4003 * IPS_CTL value is not the one we read. */
4004 if (wait_for(I915_READ_NOTRACE(IPS_CTL
) & IPS_ENABLE
, 50))
4005 DRM_ERROR("Timed out waiting for IPS enable\n");
4009 void hsw_disable_ips(struct intel_crtc
*crtc
)
4011 struct drm_device
*dev
= crtc
->base
.dev
;
4012 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4014 if (!crtc
->config
.ips_enabled
)
4017 assert_plane_enabled(dev_priv
, crtc
->plane
);
4018 if (IS_BROADWELL(dev
)) {
4019 mutex_lock(&dev_priv
->rps
.hw_lock
);
4020 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
4021 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4022 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4023 if (wait_for((I915_READ(IPS_CTL
) & IPS_ENABLE
) == 0, 42))
4024 DRM_ERROR("Timed out waiting for IPS disable\n");
4026 I915_WRITE(IPS_CTL
, 0);
4027 POSTING_READ(IPS_CTL
);
4030 /* We need to wait for a vblank before we can disable the plane. */
4031 intel_wait_for_vblank(dev
, crtc
->pipe
);
4034 /** Loads the palette/gamma unit for the CRTC with the prepared values */
4035 static void intel_crtc_load_lut(struct drm_crtc
*crtc
)
4037 struct drm_device
*dev
= crtc
->dev
;
4038 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4039 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4040 enum pipe pipe
= intel_crtc
->pipe
;
4041 int palreg
= PALETTE(pipe
);
4043 bool reenable_ips
= false;
4045 /* The clocks have to be on to load the palette. */
4046 if (!crtc
->enabled
|| !intel_crtc
->active
)
4049 if (!HAS_PCH_SPLIT(dev_priv
->dev
)) {
4050 if (intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_DSI
))
4051 assert_dsi_pll_enabled(dev_priv
);
4053 assert_pll_enabled(dev_priv
, pipe
);
4056 /* use legacy palette for Ironlake */
4057 if (!HAS_GMCH_DISPLAY(dev
))
4058 palreg
= LGC_PALETTE(pipe
);
4060 /* Workaround : Do not read or write the pipe palette/gamma data while
4061 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
4063 if (IS_HASWELL(dev
) && intel_crtc
->config
.ips_enabled
&&
4064 ((I915_READ(GAMMA_MODE(pipe
)) & GAMMA_MODE_MODE_MASK
) ==
4065 GAMMA_MODE_MODE_SPLIT
)) {
4066 hsw_disable_ips(intel_crtc
);
4067 reenable_ips
= true;
4070 for (i
= 0; i
< 256; i
++) {
4071 I915_WRITE(palreg
+ 4 * i
,
4072 (intel_crtc
->lut_r
[i
] << 16) |
4073 (intel_crtc
->lut_g
[i
] << 8) |
4074 intel_crtc
->lut_b
[i
]);
4078 hsw_enable_ips(intel_crtc
);
4081 static void intel_crtc_dpms_overlay(struct intel_crtc
*intel_crtc
, bool enable
)
4083 if (!enable
&& intel_crtc
->overlay
) {
4084 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4085 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4087 mutex_lock(&dev
->struct_mutex
);
4088 dev_priv
->mm
.interruptible
= false;
4089 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
4090 dev_priv
->mm
.interruptible
= true;
4091 mutex_unlock(&dev
->struct_mutex
);
4094 /* Let userspace switch the overlay on again. In most cases userspace
4095 * has to recompute where to put it anyway.
4099 static void intel_crtc_enable_planes(struct drm_crtc
*crtc
)
4101 struct drm_device
*dev
= crtc
->dev
;
4102 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4103 int pipe
= intel_crtc
->pipe
;
4105 intel_enable_primary_hw_plane(crtc
->primary
, crtc
);
4106 intel_enable_planes(crtc
);
4107 intel_crtc_update_cursor(crtc
, true);
4108 intel_crtc_dpms_overlay(intel_crtc
, true);
4110 hsw_enable_ips(intel_crtc
);
4112 mutex_lock(&dev
->struct_mutex
);
4113 intel_update_fbc(dev
);
4114 mutex_unlock(&dev
->struct_mutex
);
4117 * FIXME: Once we grow proper nuclear flip support out of this we need
4118 * to compute the mask of flip planes precisely. For the time being
4119 * consider this a flip from a NULL plane.
4121 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_ALL_MASK(pipe
));
4124 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
)
4126 struct drm_device
*dev
= crtc
->dev
;
4127 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4128 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4129 int pipe
= intel_crtc
->pipe
;
4130 int plane
= intel_crtc
->plane
;
4132 intel_crtc_wait_for_pending_flips(crtc
);
4134 if (dev_priv
->fbc
.plane
== plane
)
4135 intel_disable_fbc(dev
);
4137 hsw_disable_ips(intel_crtc
);
4139 intel_crtc_dpms_overlay(intel_crtc
, false);
4140 intel_crtc_update_cursor(crtc
, false);
4141 intel_disable_planes(crtc
);
4142 intel_disable_primary_hw_plane(crtc
->primary
, crtc
);
4145 * FIXME: Once we grow proper nuclear flip support out of this we need
4146 * to compute the mask of flip planes precisely. For the time being
4147 * consider this a flip to a NULL plane.
4149 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_ALL_MASK(pipe
));
4152 static void ironlake_crtc_enable(struct drm_crtc
*crtc
)
4154 struct drm_device
*dev
= crtc
->dev
;
4155 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4156 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4157 struct intel_encoder
*encoder
;
4158 int pipe
= intel_crtc
->pipe
;
4160 WARN_ON(!crtc
->enabled
);
4162 if (intel_crtc
->active
)
4165 if (intel_crtc
->config
.has_pch_encoder
)
4166 intel_prepare_shared_dpll(intel_crtc
);
4168 if (intel_crtc
->config
.has_dp_encoder
)
4169 intel_dp_set_m_n(intel_crtc
);
4171 intel_set_pipe_timings(intel_crtc
);
4173 if (intel_crtc
->config
.has_pch_encoder
) {
4174 intel_cpu_transcoder_set_m_n(intel_crtc
,
4175 &intel_crtc
->config
.fdi_m_n
, NULL
);
4178 ironlake_set_pipeconf(crtc
);
4180 intel_crtc
->active
= true;
4182 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4183 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
4185 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4186 if (encoder
->pre_enable
)
4187 encoder
->pre_enable(encoder
);
4189 if (intel_crtc
->config
.has_pch_encoder
) {
4190 /* Note: FDI PLL enabling _must_ be done before we enable the
4191 * cpu pipes, hence this is separate from all the other fdi/pch
4193 ironlake_fdi_pll_enable(intel_crtc
);
4195 assert_fdi_tx_disabled(dev_priv
, pipe
);
4196 assert_fdi_rx_disabled(dev_priv
, pipe
);
4199 ironlake_pfit_enable(intel_crtc
);
4202 * On ILK+ LUT must be loaded before the pipe is running but with
4205 intel_crtc_load_lut(crtc
);
4207 intel_update_watermarks(crtc
);
4208 intel_enable_pipe(intel_crtc
);
4210 if (intel_crtc
->config
.has_pch_encoder
)
4211 ironlake_pch_enable(crtc
);
4213 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4214 encoder
->enable(encoder
);
4216 if (HAS_PCH_CPT(dev
))
4217 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
4219 assert_vblank_disabled(crtc
);
4220 drm_crtc_vblank_on(crtc
);
4222 intel_crtc_enable_planes(crtc
);
4225 /* IPS only exists on ULT machines and is tied to pipe A. */
4226 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
4228 return HAS_IPS(crtc
->base
.dev
) && crtc
->pipe
== PIPE_A
;
4232 * This implements the workaround described in the "notes" section of the mode
4233 * set sequence documentation. When going from no pipes or single pipe to
4234 * multiple pipes, and planes are enabled after the pipe, we need to wait at
4235 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
4237 static void haswell_mode_set_planes_workaround(struct intel_crtc
*crtc
)
4239 struct drm_device
*dev
= crtc
->base
.dev
;
4240 struct intel_crtc
*crtc_it
, *other_active_crtc
= NULL
;
4242 /* We want to get the other_active_crtc only if there's only 1 other
4244 for_each_intel_crtc(dev
, crtc_it
) {
4245 if (!crtc_it
->active
|| crtc_it
== crtc
)
4248 if (other_active_crtc
)
4251 other_active_crtc
= crtc_it
;
4253 if (!other_active_crtc
)
4256 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4257 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4260 static void haswell_crtc_enable(struct drm_crtc
*crtc
)
4262 struct drm_device
*dev
= crtc
->dev
;
4263 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4264 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4265 struct intel_encoder
*encoder
;
4266 int pipe
= intel_crtc
->pipe
;
4268 WARN_ON(!crtc
->enabled
);
4270 if (intel_crtc
->active
)
4273 if (intel_crtc_to_shared_dpll(intel_crtc
))
4274 intel_enable_shared_dpll(intel_crtc
);
4276 if (intel_crtc
->config
.has_dp_encoder
)
4277 intel_dp_set_m_n(intel_crtc
);
4279 intel_set_pipe_timings(intel_crtc
);
4281 if (intel_crtc
->config
.cpu_transcoder
!= TRANSCODER_EDP
) {
4282 I915_WRITE(PIPE_MULT(intel_crtc
->config
.cpu_transcoder
),
4283 intel_crtc
->config
.pixel_multiplier
- 1);
4286 if (intel_crtc
->config
.has_pch_encoder
) {
4287 intel_cpu_transcoder_set_m_n(intel_crtc
,
4288 &intel_crtc
->config
.fdi_m_n
, NULL
);
4291 haswell_set_pipeconf(crtc
);
4293 intel_set_pipe_csc(crtc
);
4295 intel_crtc
->active
= true;
4297 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4298 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4299 if (encoder
->pre_enable
)
4300 encoder
->pre_enable(encoder
);
4302 if (intel_crtc
->config
.has_pch_encoder
) {
4303 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
4305 dev_priv
->display
.fdi_link_train(crtc
);
4308 intel_ddi_enable_pipe_clock(intel_crtc
);
4310 ironlake_pfit_enable(intel_crtc
);
4313 * On ILK+ LUT must be loaded before the pipe is running but with
4316 intel_crtc_load_lut(crtc
);
4318 intel_ddi_set_pipe_settings(crtc
);
4319 intel_ddi_enable_transcoder_func(crtc
);
4321 intel_update_watermarks(crtc
);
4322 intel_enable_pipe(intel_crtc
);
4324 if (intel_crtc
->config
.has_pch_encoder
)
4325 lpt_pch_enable(crtc
);
4327 if (intel_crtc
->config
.dp_encoder_is_mst
)
4328 intel_ddi_set_vc_payload_alloc(crtc
, true);
4330 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4331 encoder
->enable(encoder
);
4332 intel_opregion_notify_encoder(encoder
, true);
4335 assert_vblank_disabled(crtc
);
4336 drm_crtc_vblank_on(crtc
);
4338 /* If we change the relative order between pipe/planes enabling, we need
4339 * to change the workaround. */
4340 haswell_mode_set_planes_workaround(intel_crtc
);
4341 intel_crtc_enable_planes(crtc
);
4344 static void ironlake_pfit_disable(struct intel_crtc
*crtc
)
4346 struct drm_device
*dev
= crtc
->base
.dev
;
4347 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4348 int pipe
= crtc
->pipe
;
4350 /* To avoid upsetting the power well on haswell only disable the pfit if
4351 * it's in use. The hw state code will make sure we get this right. */
4352 if (crtc
->config
.pch_pfit
.enabled
) {
4353 I915_WRITE(PF_CTL(pipe
), 0);
4354 I915_WRITE(PF_WIN_POS(pipe
), 0);
4355 I915_WRITE(PF_WIN_SZ(pipe
), 0);
4359 static void ironlake_crtc_disable(struct drm_crtc
*crtc
)
4361 struct drm_device
*dev
= crtc
->dev
;
4362 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4363 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4364 struct intel_encoder
*encoder
;
4365 int pipe
= intel_crtc
->pipe
;
4368 if (!intel_crtc
->active
)
4371 intel_crtc_disable_planes(crtc
);
4373 drm_crtc_vblank_off(crtc
);
4374 assert_vblank_disabled(crtc
);
4376 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4377 encoder
->disable(encoder
);
4379 if (intel_crtc
->config
.has_pch_encoder
)
4380 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
4382 intel_disable_pipe(intel_crtc
);
4384 ironlake_pfit_disable(intel_crtc
);
4386 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4387 if (encoder
->post_disable
)
4388 encoder
->post_disable(encoder
);
4390 if (intel_crtc
->config
.has_pch_encoder
) {
4391 ironlake_fdi_disable(crtc
);
4393 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
4394 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
4396 if (HAS_PCH_CPT(dev
)) {
4397 /* disable TRANS_DP_CTL */
4398 reg
= TRANS_DP_CTL(pipe
);
4399 temp
= I915_READ(reg
);
4400 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
4401 TRANS_DP_PORT_SEL_MASK
);
4402 temp
|= TRANS_DP_PORT_SEL_NONE
;
4403 I915_WRITE(reg
, temp
);
4405 /* disable DPLL_SEL */
4406 temp
= I915_READ(PCH_DPLL_SEL
);
4407 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
4408 I915_WRITE(PCH_DPLL_SEL
, temp
);
4411 /* disable PCH DPLL */
4412 intel_disable_shared_dpll(intel_crtc
);
4414 ironlake_fdi_pll_disable(intel_crtc
);
4417 intel_crtc
->active
= false;
4418 intel_update_watermarks(crtc
);
4420 mutex_lock(&dev
->struct_mutex
);
4421 intel_update_fbc(dev
);
4422 mutex_unlock(&dev
->struct_mutex
);
4425 static void haswell_crtc_disable(struct drm_crtc
*crtc
)
4427 struct drm_device
*dev
= crtc
->dev
;
4428 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4429 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4430 struct intel_encoder
*encoder
;
4431 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
4433 if (!intel_crtc
->active
)
4436 intel_crtc_disable_planes(crtc
);
4438 drm_crtc_vblank_off(crtc
);
4439 assert_vblank_disabled(crtc
);
4441 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4442 intel_opregion_notify_encoder(encoder
, false);
4443 encoder
->disable(encoder
);
4446 if (intel_crtc
->config
.has_pch_encoder
)
4447 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
4449 intel_disable_pipe(intel_crtc
);
4451 if (intel_crtc
->config
.dp_encoder_is_mst
)
4452 intel_ddi_set_vc_payload_alloc(crtc
, false);
4454 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
4456 ironlake_pfit_disable(intel_crtc
);
4458 intel_ddi_disable_pipe_clock(intel_crtc
);
4460 if (intel_crtc
->config
.has_pch_encoder
) {
4461 lpt_disable_pch_transcoder(dev_priv
);
4462 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
4464 intel_ddi_fdi_disable(crtc
);
4467 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4468 if (encoder
->post_disable
)
4469 encoder
->post_disable(encoder
);
4471 intel_crtc
->active
= false;
4472 intel_update_watermarks(crtc
);
4474 mutex_lock(&dev
->struct_mutex
);
4475 intel_update_fbc(dev
);
4476 mutex_unlock(&dev
->struct_mutex
);
4478 if (intel_crtc_to_shared_dpll(intel_crtc
))
4479 intel_disable_shared_dpll(intel_crtc
);
4482 static void ironlake_crtc_off(struct drm_crtc
*crtc
)
4484 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4485 intel_put_shared_dpll(intel_crtc
);
4489 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
4491 struct drm_device
*dev
= crtc
->base
.dev
;
4492 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4493 struct intel_crtc_config
*pipe_config
= &crtc
->config
;
4495 if (!crtc
->config
.gmch_pfit
.control
)
4499 * The panel fitter should only be adjusted whilst the pipe is disabled,
4500 * according to register description and PRM.
4502 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
4503 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
4505 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
4506 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
4508 /* Border color in case we don't scale up to the full screen. Black by
4509 * default, change to something else for debugging. */
4510 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
4513 static enum intel_display_power_domain
port_to_power_domain(enum port port
)
4517 return POWER_DOMAIN_PORT_DDI_A_4_LANES
;
4519 return POWER_DOMAIN_PORT_DDI_B_4_LANES
;
4521 return POWER_DOMAIN_PORT_DDI_C_4_LANES
;
4523 return POWER_DOMAIN_PORT_DDI_D_4_LANES
;
4526 return POWER_DOMAIN_PORT_OTHER
;
4530 #define for_each_power_domain(domain, mask) \
4531 for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
4532 if ((1 << (domain)) & (mask))
4534 enum intel_display_power_domain
4535 intel_display_port_power_domain(struct intel_encoder
*intel_encoder
)
4537 struct drm_device
*dev
= intel_encoder
->base
.dev
;
4538 struct intel_digital_port
*intel_dig_port
;
4540 switch (intel_encoder
->type
) {
4541 case INTEL_OUTPUT_UNKNOWN
:
4542 /* Only DDI platforms should ever use this output type */
4543 WARN_ON_ONCE(!HAS_DDI(dev
));
4544 case INTEL_OUTPUT_DISPLAYPORT
:
4545 case INTEL_OUTPUT_HDMI
:
4546 case INTEL_OUTPUT_EDP
:
4547 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
4548 return port_to_power_domain(intel_dig_port
->port
);
4549 case INTEL_OUTPUT_DP_MST
:
4550 intel_dig_port
= enc_to_mst(&intel_encoder
->base
)->primary
;
4551 return port_to_power_domain(intel_dig_port
->port
);
4552 case INTEL_OUTPUT_ANALOG
:
4553 return POWER_DOMAIN_PORT_CRT
;
4554 case INTEL_OUTPUT_DSI
:
4555 return POWER_DOMAIN_PORT_DSI
;
4557 return POWER_DOMAIN_PORT_OTHER
;
4561 static unsigned long get_crtc_power_domains(struct drm_crtc
*crtc
)
4563 struct drm_device
*dev
= crtc
->dev
;
4564 struct intel_encoder
*intel_encoder
;
4565 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4566 enum pipe pipe
= intel_crtc
->pipe
;
4568 enum transcoder transcoder
;
4570 transcoder
= intel_pipe_to_cpu_transcoder(dev
->dev_private
, pipe
);
4572 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
4573 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
4574 if (intel_crtc
->config
.pch_pfit
.enabled
||
4575 intel_crtc
->config
.pch_pfit
.force_thru
)
4576 mask
|= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
4578 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
4579 mask
|= BIT(intel_display_port_power_domain(intel_encoder
));
4584 static void modeset_update_crtc_power_domains(struct drm_device
*dev
)
4586 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4587 unsigned long pipe_domains
[I915_MAX_PIPES
] = { 0, };
4588 struct intel_crtc
*crtc
;
4591 * First get all needed power domains, then put all unneeded, to avoid
4592 * any unnecessary toggling of the power wells.
4594 for_each_intel_crtc(dev
, crtc
) {
4595 enum intel_display_power_domain domain
;
4597 if (!crtc
->base
.enabled
)
4600 pipe_domains
[crtc
->pipe
] = get_crtc_power_domains(&crtc
->base
);
4602 for_each_power_domain(domain
, pipe_domains
[crtc
->pipe
])
4603 intel_display_power_get(dev_priv
, domain
);
4606 for_each_intel_crtc(dev
, crtc
) {
4607 enum intel_display_power_domain domain
;
4609 for_each_power_domain(domain
, crtc
->enabled_power_domains
)
4610 intel_display_power_put(dev_priv
, domain
);
4612 crtc
->enabled_power_domains
= pipe_domains
[crtc
->pipe
];
4615 intel_display_set_init_power(dev_priv
, false);
4618 /* returns HPLL frequency in kHz */
4619 static int valleyview_get_vco(struct drm_i915_private
*dev_priv
)
4621 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
4623 /* Obtain SKU information */
4624 mutex_lock(&dev_priv
->dpio_lock
);
4625 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
4626 CCK_FUSE_HPLL_FREQ_MASK
;
4627 mutex_unlock(&dev_priv
->dpio_lock
);
4629 return vco_freq
[hpll_freq
] * 1000;
4632 static void vlv_update_cdclk(struct drm_device
*dev
)
4634 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4636 dev_priv
->vlv_cdclk_freq
= dev_priv
->display
.get_display_clock_speed(dev
);
4637 DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n",
4638 dev_priv
->vlv_cdclk_freq
);
4641 * Program the gmbus_freq based on the cdclk frequency.
4642 * BSpec erroneously claims we should aim for 4MHz, but
4643 * in fact 1MHz is the correct frequency.
4645 I915_WRITE(GMBUSFREQ_VLV
, dev_priv
->vlv_cdclk_freq
);
4648 /* Adjust CDclk dividers to allow high res or save power if possible */
4649 static void valleyview_set_cdclk(struct drm_device
*dev
, int cdclk
)
4651 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4654 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
) != dev_priv
->vlv_cdclk_freq
);
4656 if (cdclk
>= 320000) /* jump to highest voltage for 400MHz too */
4658 else if (cdclk
== 266667)
4663 mutex_lock(&dev_priv
->rps
.hw_lock
);
4664 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
4665 val
&= ~DSPFREQGUAR_MASK
;
4666 val
|= (cmd
<< DSPFREQGUAR_SHIFT
);
4667 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
4668 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
4669 DSPFREQSTAT_MASK
) == (cmd
<< DSPFREQSTAT_SHIFT
),
4671 DRM_ERROR("timed out waiting for CDclk change\n");
4673 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4675 if (cdclk
== 400000) {
4678 vco
= valleyview_get_vco(dev_priv
);
4679 divider
= DIV_ROUND_CLOSEST(vco
<< 1, cdclk
) - 1;
4681 mutex_lock(&dev_priv
->dpio_lock
);
4682 /* adjust cdclk divider */
4683 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
4684 val
&= ~DISPLAY_FREQUENCY_VALUES
;
4686 vlv_cck_write(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
, val
);
4688 if (wait_for((vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
) &
4689 DISPLAY_FREQUENCY_STATUS
) == (divider
<< DISPLAY_FREQUENCY_STATUS_SHIFT
),
4691 DRM_ERROR("timed out waiting for CDclk change\n");
4692 mutex_unlock(&dev_priv
->dpio_lock
);
4695 mutex_lock(&dev_priv
->dpio_lock
);
4696 /* adjust self-refresh exit latency value */
4697 val
= vlv_bunit_read(dev_priv
, BUNIT_REG_BISOC
);
4701 * For high bandwidth configs, we set a higher latency in the bunit
4702 * so that the core display fetch happens in time to avoid underruns.
4704 if (cdclk
== 400000)
4705 val
|= 4500 / 250; /* 4.5 usec */
4707 val
|= 3000 / 250; /* 3.0 usec */
4708 vlv_bunit_write(dev_priv
, BUNIT_REG_BISOC
, val
);
4709 mutex_unlock(&dev_priv
->dpio_lock
);
4711 vlv_update_cdclk(dev
);
4714 static void cherryview_set_cdclk(struct drm_device
*dev
, int cdclk
)
4716 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4719 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
) != dev_priv
->vlv_cdclk_freq
);
4740 mutex_lock(&dev_priv
->rps
.hw_lock
);
4741 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
4742 val
&= ~DSPFREQGUAR_MASK_CHV
;
4743 val
|= (cmd
<< DSPFREQGUAR_SHIFT_CHV
);
4744 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
4745 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
4746 DSPFREQSTAT_MASK_CHV
) == (cmd
<< DSPFREQSTAT_SHIFT_CHV
),
4748 DRM_ERROR("timed out waiting for CDclk change\n");
4750 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4752 vlv_update_cdclk(dev
);
4755 static int valleyview_calc_cdclk(struct drm_i915_private
*dev_priv
,
4758 int vco
= valleyview_get_vco(dev_priv
);
4759 int freq_320
= (vco
<< 1) % 320000 != 0 ? 333333 : 320000;
4761 /* FIXME: Punit isn't quite ready yet */
4762 if (IS_CHERRYVIEW(dev_priv
->dev
))
4766 * Really only a few cases to deal with, as only 4 CDclks are supported:
4769 * 320/333MHz (depends on HPLL freq)
4771 * So we check to see whether we're above 90% of the lower bin and
4774 * We seem to get an unstable or solid color picture at 200MHz.
4775 * Not sure what's wrong. For now use 200MHz only when all pipes
4778 if (max_pixclk
> freq_320
*9/10)
4780 else if (max_pixclk
> 266667*9/10)
4782 else if (max_pixclk
> 0)
4788 /* compute the max pixel clock for new configuration */
4789 static int intel_mode_max_pixclk(struct drm_i915_private
*dev_priv
)
4791 struct drm_device
*dev
= dev_priv
->dev
;
4792 struct intel_crtc
*intel_crtc
;
4795 for_each_intel_crtc(dev
, intel_crtc
) {
4796 if (intel_crtc
->new_enabled
)
4797 max_pixclk
= max(max_pixclk
,
4798 intel_crtc
->new_config
->adjusted_mode
.crtc_clock
);
4804 static void valleyview_modeset_global_pipes(struct drm_device
*dev
,
4805 unsigned *prepare_pipes
)
4807 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4808 struct intel_crtc
*intel_crtc
;
4809 int max_pixclk
= intel_mode_max_pixclk(dev_priv
);
4811 if (valleyview_calc_cdclk(dev_priv
, max_pixclk
) ==
4812 dev_priv
->vlv_cdclk_freq
)
4815 /* disable/enable all currently active pipes while we change cdclk */
4816 for_each_intel_crtc(dev
, intel_crtc
)
4817 if (intel_crtc
->base
.enabled
)
4818 *prepare_pipes
|= (1 << intel_crtc
->pipe
);
4821 static void valleyview_modeset_global_resources(struct drm_device
*dev
)
4823 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4824 int max_pixclk
= intel_mode_max_pixclk(dev_priv
);
4825 int req_cdclk
= valleyview_calc_cdclk(dev_priv
, max_pixclk
);
4827 if (req_cdclk
!= dev_priv
->vlv_cdclk_freq
) {
4828 if (IS_CHERRYVIEW(dev
))
4829 cherryview_set_cdclk(dev
, req_cdclk
);
4831 valleyview_set_cdclk(dev
, req_cdclk
);
4834 modeset_update_crtc_power_domains(dev
);
4837 static void valleyview_crtc_enable(struct drm_crtc
*crtc
)
4839 struct drm_device
*dev
= crtc
->dev
;
4840 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4841 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4842 struct intel_encoder
*encoder
;
4843 int pipe
= intel_crtc
->pipe
;
4846 WARN_ON(!crtc
->enabled
);
4848 if (intel_crtc
->active
)
4851 is_dsi
= intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_DSI
);
4854 if (IS_CHERRYVIEW(dev
))
4855 chv_prepare_pll(intel_crtc
, &intel_crtc
->config
);
4857 vlv_prepare_pll(intel_crtc
, &intel_crtc
->config
);
4860 if (intel_crtc
->config
.has_dp_encoder
)
4861 intel_dp_set_m_n(intel_crtc
);
4863 intel_set_pipe_timings(intel_crtc
);
4865 if (IS_CHERRYVIEW(dev
) && pipe
== PIPE_B
) {
4866 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4868 I915_WRITE(CHV_BLEND(pipe
), CHV_BLEND_LEGACY
);
4869 I915_WRITE(CHV_CANVAS(pipe
), 0);
4872 i9xx_set_pipeconf(intel_crtc
);
4874 intel_crtc
->active
= true;
4876 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4878 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4879 if (encoder
->pre_pll_enable
)
4880 encoder
->pre_pll_enable(encoder
);
4883 if (IS_CHERRYVIEW(dev
))
4884 chv_enable_pll(intel_crtc
, &intel_crtc
->config
);
4886 vlv_enable_pll(intel_crtc
, &intel_crtc
->config
);
4889 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4890 if (encoder
->pre_enable
)
4891 encoder
->pre_enable(encoder
);
4893 i9xx_pfit_enable(intel_crtc
);
4895 intel_crtc_load_lut(crtc
);
4897 intel_update_watermarks(crtc
);
4898 intel_enable_pipe(intel_crtc
);
4900 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4901 encoder
->enable(encoder
);
4903 assert_vblank_disabled(crtc
);
4904 drm_crtc_vblank_on(crtc
);
4906 intel_crtc_enable_planes(crtc
);
4908 /* Underruns don't raise interrupts, so check manually. */
4909 i9xx_check_fifo_underruns(dev_priv
);
4912 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
4914 struct drm_device
*dev
= crtc
->base
.dev
;
4915 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4917 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
.dpll_hw_state
.fp0
);
4918 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
.dpll_hw_state
.fp1
);
4921 static void i9xx_crtc_enable(struct drm_crtc
*crtc
)
4923 struct drm_device
*dev
= crtc
->dev
;
4924 struct drm_i915_private
*dev_priv
= to_i915(dev
);
4925 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4926 struct intel_encoder
*encoder
;
4927 int pipe
= intel_crtc
->pipe
;
4929 WARN_ON(!crtc
->enabled
);
4931 if (intel_crtc
->active
)
4934 i9xx_set_pll_dividers(intel_crtc
);
4936 if (intel_crtc
->config
.has_dp_encoder
)
4937 intel_dp_set_m_n(intel_crtc
);
4939 intel_set_pipe_timings(intel_crtc
);
4941 i9xx_set_pipeconf(intel_crtc
);
4943 intel_crtc
->active
= true;
4946 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4948 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4949 if (encoder
->pre_enable
)
4950 encoder
->pre_enable(encoder
);
4952 i9xx_enable_pll(intel_crtc
);
4954 i9xx_pfit_enable(intel_crtc
);
4956 intel_crtc_load_lut(crtc
);
4958 intel_update_watermarks(crtc
);
4959 intel_enable_pipe(intel_crtc
);
4961 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4962 encoder
->enable(encoder
);
4964 assert_vblank_disabled(crtc
);
4965 drm_crtc_vblank_on(crtc
);
4967 intel_crtc_enable_planes(crtc
);
4970 * Gen2 reports pipe underruns whenever all planes are disabled.
4971 * So don't enable underrun reporting before at least some planes
4973 * FIXME: Need to fix the logic to work when we turn off all planes
4974 * but leave the pipe running.
4977 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4979 /* Underruns don't raise interrupts, so check manually. */
4980 i9xx_check_fifo_underruns(dev_priv
);
4983 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
4985 struct drm_device
*dev
= crtc
->base
.dev
;
4986 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4988 if (!crtc
->config
.gmch_pfit
.control
)
4991 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
4993 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
4994 I915_READ(PFIT_CONTROL
));
4995 I915_WRITE(PFIT_CONTROL
, 0);
4998 static void i9xx_crtc_disable(struct drm_crtc
*crtc
)
5000 struct drm_device
*dev
= crtc
->dev
;
5001 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5002 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5003 struct intel_encoder
*encoder
;
5004 int pipe
= intel_crtc
->pipe
;
5006 if (!intel_crtc
->active
)
5010 * Gen2 reports pipe underruns whenever all planes are disabled.
5011 * So diasble underrun reporting before all the planes get disabled.
5012 * FIXME: Need to fix the logic to work when we turn off all planes
5013 * but leave the pipe running.
5016 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5019 * Vblank time updates from the shadow to live plane control register
5020 * are blocked if the memory self-refresh mode is active at that
5021 * moment. So to make sure the plane gets truly disabled, disable
5022 * first the self-refresh mode. The self-refresh enable bit in turn
5023 * will be checked/applied by the HW only at the next frame start
5024 * event which is after the vblank start event, so we need to have a
5025 * wait-for-vblank between disabling the plane and the pipe.
5027 intel_set_memory_cxsr(dev_priv
, false);
5028 intel_crtc_disable_planes(crtc
);
5031 * On gen2 planes are double buffered but the pipe isn't, so we must
5032 * wait for planes to fully turn off before disabling the pipe.
5033 * We also need to wait on all gmch platforms because of the
5034 * self-refresh mode constraint explained above.
5036 intel_wait_for_vblank(dev
, pipe
);
5038 drm_crtc_vblank_off(crtc
);
5039 assert_vblank_disabled(crtc
);
5041 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5042 encoder
->disable(encoder
);
5044 intel_disable_pipe(intel_crtc
);
5046 i9xx_pfit_disable(intel_crtc
);
5048 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5049 if (encoder
->post_disable
)
5050 encoder
->post_disable(encoder
);
5052 if (!intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_DSI
)) {
5053 if (IS_CHERRYVIEW(dev
))
5054 chv_disable_pll(dev_priv
, pipe
);
5055 else if (IS_VALLEYVIEW(dev
))
5056 vlv_disable_pll(dev_priv
, pipe
);
5058 i9xx_disable_pll(intel_crtc
);
5062 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5064 intel_crtc
->active
= false;
5065 intel_update_watermarks(crtc
);
5067 mutex_lock(&dev
->struct_mutex
);
5068 intel_update_fbc(dev
);
5069 mutex_unlock(&dev
->struct_mutex
);
5072 static void i9xx_crtc_off(struct drm_crtc
*crtc
)
5076 static void intel_crtc_update_sarea(struct drm_crtc
*crtc
,
5079 struct drm_device
*dev
= crtc
->dev
;
5080 struct drm_i915_master_private
*master_priv
;
5081 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5082 int pipe
= intel_crtc
->pipe
;
5084 if (!dev
->primary
->master
)
5087 master_priv
= dev
->primary
->master
->driver_priv
;
5088 if (!master_priv
->sarea_priv
)
5093 master_priv
->sarea_priv
->pipeA_w
= enabled
? crtc
->mode
.hdisplay
: 0;
5094 master_priv
->sarea_priv
->pipeA_h
= enabled
? crtc
->mode
.vdisplay
: 0;
5097 master_priv
->sarea_priv
->pipeB_w
= enabled
? crtc
->mode
.hdisplay
: 0;
5098 master_priv
->sarea_priv
->pipeB_h
= enabled
? crtc
->mode
.vdisplay
: 0;
5101 DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe
));
5106 /* Master function to enable/disable CRTC and corresponding power wells */
5107 void intel_crtc_control(struct drm_crtc
*crtc
, bool enable
)
5109 struct drm_device
*dev
= crtc
->dev
;
5110 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5111 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5112 enum intel_display_power_domain domain
;
5113 unsigned long domains
;
5116 if (!intel_crtc
->active
) {
5117 domains
= get_crtc_power_domains(crtc
);
5118 for_each_power_domain(domain
, domains
)
5119 intel_display_power_get(dev_priv
, domain
);
5120 intel_crtc
->enabled_power_domains
= domains
;
5122 dev_priv
->display
.crtc_enable(crtc
);
5125 if (intel_crtc
->active
) {
5126 dev_priv
->display
.crtc_disable(crtc
);
5128 domains
= intel_crtc
->enabled_power_domains
;
5129 for_each_power_domain(domain
, domains
)
5130 intel_display_power_put(dev_priv
, domain
);
5131 intel_crtc
->enabled_power_domains
= 0;
5137 * Sets the power management mode of the pipe and plane.
5139 void intel_crtc_update_dpms(struct drm_crtc
*crtc
)
5141 struct drm_device
*dev
= crtc
->dev
;
5142 struct intel_encoder
*intel_encoder
;
5143 bool enable
= false;
5145 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
5146 enable
|= intel_encoder
->connectors_active
;
5148 intel_crtc_control(crtc
, enable
);
5150 intel_crtc_update_sarea(crtc
, enable
);
5153 static void intel_crtc_disable(struct drm_crtc
*crtc
)
5155 struct drm_device
*dev
= crtc
->dev
;
5156 struct drm_connector
*connector
;
5157 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5158 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(crtc
->primary
->fb
);
5159 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
5161 /* crtc should still be enabled when we disable it. */
5162 WARN_ON(!crtc
->enabled
);
5164 dev_priv
->display
.crtc_disable(crtc
);
5165 intel_crtc_update_sarea(crtc
, false);
5166 dev_priv
->display
.off(crtc
);
5168 if (crtc
->primary
->fb
) {
5169 mutex_lock(&dev
->struct_mutex
);
5170 intel_unpin_fb_obj(old_obj
);
5171 i915_gem_track_fb(old_obj
, NULL
,
5172 INTEL_FRONTBUFFER_PRIMARY(pipe
));
5173 mutex_unlock(&dev
->struct_mutex
);
5174 crtc
->primary
->fb
= NULL
;
5177 /* Update computed state. */
5178 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
5179 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
5182 if (connector
->encoder
->crtc
!= crtc
)
5185 connector
->dpms
= DRM_MODE_DPMS_OFF
;
5186 to_intel_encoder(connector
->encoder
)->connectors_active
= false;
5190 void intel_encoder_destroy(struct drm_encoder
*encoder
)
5192 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5194 drm_encoder_cleanup(encoder
);
5195 kfree(intel_encoder
);
5198 /* Simple dpms helper for encoders with just one connector, no cloning and only
5199 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
5200 * state of the entire output pipe. */
5201 static void intel_encoder_dpms(struct intel_encoder
*encoder
, int mode
)
5203 if (mode
== DRM_MODE_DPMS_ON
) {
5204 encoder
->connectors_active
= true;
5206 intel_crtc_update_dpms(encoder
->base
.crtc
);
5208 encoder
->connectors_active
= false;
5210 intel_crtc_update_dpms(encoder
->base
.crtc
);
5214 /* Cross check the actual hw state with our own modeset state tracking (and it's
5215 * internal consistency). */
5216 static void intel_connector_check_state(struct intel_connector
*connector
)
5218 if (connector
->get_hw_state(connector
)) {
5219 struct intel_encoder
*encoder
= connector
->encoder
;
5220 struct drm_crtc
*crtc
;
5221 bool encoder_enabled
;
5224 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
5225 connector
->base
.base
.id
,
5226 connector
->base
.name
);
5228 /* there is no real hw state for MST connectors */
5229 if (connector
->mst_port
)
5232 WARN(connector
->base
.dpms
== DRM_MODE_DPMS_OFF
,
5233 "wrong connector dpms state\n");
5234 WARN(connector
->base
.encoder
!= &encoder
->base
,
5235 "active connector not linked to encoder\n");
5238 WARN(!encoder
->connectors_active
,
5239 "encoder->connectors_active not set\n");
5241 encoder_enabled
= encoder
->get_hw_state(encoder
, &pipe
);
5242 WARN(!encoder_enabled
, "encoder not enabled\n");
5243 if (WARN_ON(!encoder
->base
.crtc
))
5246 crtc
= encoder
->base
.crtc
;
5248 WARN(!crtc
->enabled
, "crtc not enabled\n");
5249 WARN(!to_intel_crtc(crtc
)->active
, "crtc not active\n");
5250 WARN(pipe
!= to_intel_crtc(crtc
)->pipe
,
5251 "encoder active on the wrong pipe\n");
5256 /* Even simpler default implementation, if there's really no special case to
5258 void intel_connector_dpms(struct drm_connector
*connector
, int mode
)
5260 /* All the simple cases only support two dpms states. */
5261 if (mode
!= DRM_MODE_DPMS_ON
)
5262 mode
= DRM_MODE_DPMS_OFF
;
5264 if (mode
== connector
->dpms
)
5267 connector
->dpms
= mode
;
5269 /* Only need to change hw state when actually enabled */
5270 if (connector
->encoder
)
5271 intel_encoder_dpms(to_intel_encoder(connector
->encoder
), mode
);
5273 intel_modeset_check_state(connector
->dev
);
5276 /* Simple connector->get_hw_state implementation for encoders that support only
5277 * one connector and no cloning and hence the encoder state determines the state
5278 * of the connector. */
5279 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
5282 struct intel_encoder
*encoder
= connector
->encoder
;
5284 return encoder
->get_hw_state(encoder
, &pipe
);
5287 static bool ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
5288 struct intel_crtc_config
*pipe_config
)
5290 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5291 struct intel_crtc
*pipe_B_crtc
=
5292 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
5294 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
5295 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5296 if (pipe_config
->fdi_lanes
> 4) {
5297 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
5298 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5302 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
5303 if (pipe_config
->fdi_lanes
> 2) {
5304 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
5305 pipe_config
->fdi_lanes
);
5312 if (INTEL_INFO(dev
)->num_pipes
== 2)
5315 /* Ivybridge 3 pipe is really complicated */
5320 if (dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]->enabled
&&
5321 pipe_config
->fdi_lanes
> 2) {
5322 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5323 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5328 if (!pipe_has_enabled_pch(pipe_B_crtc
) ||
5329 pipe_B_crtc
->config
.fdi_lanes
<= 2) {
5330 if (pipe_config
->fdi_lanes
> 2) {
5331 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5332 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5336 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
5346 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
5347 struct intel_crtc_config
*pipe_config
)
5349 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5350 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
5351 int lane
, link_bw
, fdi_dotclock
;
5352 bool setup_ok
, needs_recompute
= false;
5355 /* FDI is a binary signal running at ~2.7GHz, encoding
5356 * each output octet as 10 bits. The actual frequency
5357 * is stored as a divider into a 100MHz clock, and the
5358 * mode pixel clock is stored in units of 1KHz.
5359 * Hence the bw of each lane in terms of the mode signal
5362 link_bw
= intel_fdi_link_freq(dev
) * MHz(100)/KHz(1)/10;
5364 fdi_dotclock
= adjusted_mode
->crtc_clock
;
5366 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
5367 pipe_config
->pipe_bpp
);
5369 pipe_config
->fdi_lanes
= lane
;
5371 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
5372 link_bw
, &pipe_config
->fdi_m_n
);
5374 setup_ok
= ironlake_check_fdi_lanes(intel_crtc
->base
.dev
,
5375 intel_crtc
->pipe
, pipe_config
);
5376 if (!setup_ok
&& pipe_config
->pipe_bpp
> 6*3) {
5377 pipe_config
->pipe_bpp
-= 2*3;
5378 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
5379 pipe_config
->pipe_bpp
);
5380 needs_recompute
= true;
5381 pipe_config
->bw_constrained
= true;
5386 if (needs_recompute
)
5389 return setup_ok
? 0 : -EINVAL
;
5392 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
5393 struct intel_crtc_config
*pipe_config
)
5395 pipe_config
->ips_enabled
= i915
.enable_ips
&&
5396 hsw_crtc_supports_ips(crtc
) &&
5397 pipe_config
->pipe_bpp
<= 24;
5400 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
5401 struct intel_crtc_config
*pipe_config
)
5403 struct drm_device
*dev
= crtc
->base
.dev
;
5404 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
5406 /* FIXME should check pixel clock limits on all platforms */
5407 if (INTEL_INFO(dev
)->gen
< 4) {
5408 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5410 dev_priv
->display
.get_display_clock_speed(dev
);
5413 * Enable pixel doubling when the dot clock
5414 * is > 90% of the (display) core speed.
5416 * GDG double wide on either pipe,
5417 * otherwise pipe A only.
5419 if ((crtc
->pipe
== PIPE_A
|| IS_I915G(dev
)) &&
5420 adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10) {
5422 pipe_config
->double_wide
= true;
5425 if (adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10)
5430 * Pipe horizontal size must be even in:
5432 * - LVDS dual channel mode
5433 * - Double wide pipe
5435 if ((intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
5436 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
5437 pipe_config
->pipe_src_w
&= ~1;
5439 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
5440 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
5442 if ((INTEL_INFO(dev
)->gen
> 4 || IS_G4X(dev
)) &&
5443 adjusted_mode
->hsync_start
== adjusted_mode
->hdisplay
)
5446 if ((IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) && pipe_config
->pipe_bpp
> 10*3) {
5447 pipe_config
->pipe_bpp
= 10*3; /* 12bpc is gen5+ */
5448 } else if (INTEL_INFO(dev
)->gen
<= 4 && pipe_config
->pipe_bpp
> 8*3) {
5449 /* only a 8bpc pipe, with 6bpc dither through the panel fitter
5451 pipe_config
->pipe_bpp
= 8*3;
5455 hsw_compute_ips_config(crtc
, pipe_config
);
5458 * XXX: PCH/WRPLL clock sharing is done in ->mode_set, so make sure the
5459 * old clock survives for now.
5461 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
) || HAS_DDI(dev
))
5462 pipe_config
->shared_dpll
= crtc
->config
.shared_dpll
;
5464 if (pipe_config
->has_pch_encoder
)
5465 return ironlake_fdi_compute_config(crtc
, pipe_config
);
5470 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
5472 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5473 int vco
= valleyview_get_vco(dev_priv
);
5477 /* FIXME: Punit isn't quite ready yet */
5478 if (IS_CHERRYVIEW(dev
))
5481 mutex_lock(&dev_priv
->dpio_lock
);
5482 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
5483 mutex_unlock(&dev_priv
->dpio_lock
);
5485 divider
= val
& DISPLAY_FREQUENCY_VALUES
;
5487 WARN((val
& DISPLAY_FREQUENCY_STATUS
) !=
5488 (divider
<< DISPLAY_FREQUENCY_STATUS_SHIFT
),
5489 "cdclk change in progress\n");
5491 return DIV_ROUND_CLOSEST(vco
<< 1, divider
+ 1);
5494 static int i945_get_display_clock_speed(struct drm_device
*dev
)
5499 static int i915_get_display_clock_speed(struct drm_device
*dev
)
5504 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
5509 static int pnv_get_display_clock_speed(struct drm_device
*dev
)
5513 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
5515 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
5516 case GC_DISPLAY_CLOCK_267_MHZ_PNV
:
5518 case GC_DISPLAY_CLOCK_333_MHZ_PNV
:
5520 case GC_DISPLAY_CLOCK_444_MHZ_PNV
:
5522 case GC_DISPLAY_CLOCK_200_MHZ_PNV
:
5525 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc
);
5526 case GC_DISPLAY_CLOCK_133_MHZ_PNV
:
5528 case GC_DISPLAY_CLOCK_167_MHZ_PNV
:
5533 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
5537 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
5539 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
5542 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
5543 case GC_DISPLAY_CLOCK_333_MHZ
:
5546 case GC_DISPLAY_CLOCK_190_200_MHZ
:
5552 static int i865_get_display_clock_speed(struct drm_device
*dev
)
5557 static int i855_get_display_clock_speed(struct drm_device
*dev
)
5560 /* Assume that the hardware is in the high speed state. This
5561 * should be the default.
5563 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
5564 case GC_CLOCK_133_200
:
5565 case GC_CLOCK_100_200
:
5567 case GC_CLOCK_166_250
:
5569 case GC_CLOCK_100_133
:
5573 /* Shouldn't happen */
5577 static int i830_get_display_clock_speed(struct drm_device
*dev
)
5583 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
5585 while (*num
> DATA_LINK_M_N_MASK
||
5586 *den
> DATA_LINK_M_N_MASK
) {
5592 static void compute_m_n(unsigned int m
, unsigned int n
,
5593 uint32_t *ret_m
, uint32_t *ret_n
)
5595 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
5596 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
5597 intel_reduce_m_n_ratio(ret_m
, ret_n
);
5601 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
5602 int pixel_clock
, int link_clock
,
5603 struct intel_link_m_n
*m_n
)
5607 compute_m_n(bits_per_pixel
* pixel_clock
,
5608 link_clock
* nlanes
* 8,
5609 &m_n
->gmch_m
, &m_n
->gmch_n
);
5611 compute_m_n(pixel_clock
, link_clock
,
5612 &m_n
->link_m
, &m_n
->link_n
);
5615 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
5617 if (i915
.panel_use_ssc
>= 0)
5618 return i915
.panel_use_ssc
!= 0;
5619 return dev_priv
->vbt
.lvds_use_ssc
5620 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
5623 static int i9xx_get_refclk(struct intel_crtc
*crtc
, int num_connectors
)
5625 struct drm_device
*dev
= crtc
->base
.dev
;
5626 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5629 if (IS_VALLEYVIEW(dev
)) {
5631 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
5632 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
5633 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
5634 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
5635 } else if (!IS_GEN2(dev
)) {
5644 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
5646 return (1 << dpll
->n
) << 16 | dpll
->m2
;
5649 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
5651 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
5654 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
5655 intel_clock_t
*reduced_clock
)
5657 struct drm_device
*dev
= crtc
->base
.dev
;
5660 if (IS_PINEVIEW(dev
)) {
5661 fp
= pnv_dpll_compute_fp(&crtc
->config
.dpll
);
5663 fp2
= pnv_dpll_compute_fp(reduced_clock
);
5665 fp
= i9xx_dpll_compute_fp(&crtc
->config
.dpll
);
5667 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
5670 crtc
->config
.dpll_hw_state
.fp0
= fp
;
5672 crtc
->lowfreq_avail
= false;
5673 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
5674 reduced_clock
&& i915
.powersave
) {
5675 crtc
->config
.dpll_hw_state
.fp1
= fp2
;
5676 crtc
->lowfreq_avail
= true;
5678 crtc
->config
.dpll_hw_state
.fp1
= fp
;
5682 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
5688 * PLLB opamp always calibrates to max value of 0x3f, force enable it
5689 * and set it to a reasonable value instead.
5691 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
5692 reg_val
&= 0xffffff00;
5693 reg_val
|= 0x00000030;
5694 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
5696 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
5697 reg_val
&= 0x8cffffff;
5698 reg_val
= 0x8c000000;
5699 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
5701 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
5702 reg_val
&= 0xffffff00;
5703 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
5705 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
5706 reg_val
&= 0x00ffffff;
5707 reg_val
|= 0xb0000000;
5708 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
5711 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
5712 struct intel_link_m_n
*m_n
)
5714 struct drm_device
*dev
= crtc
->base
.dev
;
5715 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5716 int pipe
= crtc
->pipe
;
5718 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5719 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
5720 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
5721 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
5724 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
5725 struct intel_link_m_n
*m_n
,
5726 struct intel_link_m_n
*m2_n2
)
5728 struct drm_device
*dev
= crtc
->base
.dev
;
5729 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5730 int pipe
= crtc
->pipe
;
5731 enum transcoder transcoder
= crtc
->config
.cpu_transcoder
;
5733 if (INTEL_INFO(dev
)->gen
>= 5) {
5734 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5735 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
5736 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
5737 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
5738 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
5739 * for gen < 8) and if DRRS is supported (to make sure the
5740 * registers are not unnecessarily accessed).
5742 if (m2_n2
&& INTEL_INFO(dev
)->gen
< 8 &&
5743 crtc
->config
.has_drrs
) {
5744 I915_WRITE(PIPE_DATA_M2(transcoder
),
5745 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
5746 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
5747 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
5748 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
5751 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5752 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
5753 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
5754 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
5758 void intel_dp_set_m_n(struct intel_crtc
*crtc
)
5760 if (crtc
->config
.has_pch_encoder
)
5761 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
.dp_m_n
);
5763 intel_cpu_transcoder_set_m_n(crtc
, &crtc
->config
.dp_m_n
,
5764 &crtc
->config
.dp_m2_n2
);
5767 static void vlv_update_pll(struct intel_crtc
*crtc
,
5768 struct intel_crtc_config
*pipe_config
)
5773 * Enable DPIO clock input. We should never disable the reference
5774 * clock for pipe B, since VGA hotplug / manual detection depends
5777 dpll
= DPLL_EXT_BUFFER_ENABLE_VLV
| DPLL_REFA_CLK_ENABLE_VLV
|
5778 DPLL_VGA_MODE_DIS
| DPLL_INTEGRATED_CLOCK_VLV
;
5779 /* We should never disable this, set it here for state tracking */
5780 if (crtc
->pipe
== PIPE_B
)
5781 dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
5782 dpll
|= DPLL_VCO_ENABLE
;
5783 pipe_config
->dpll_hw_state
.dpll
= dpll
;
5785 dpll_md
= (pipe_config
->pixel_multiplier
- 1)
5786 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5787 pipe_config
->dpll_hw_state
.dpll_md
= dpll_md
;
5790 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
5791 const struct intel_crtc_config
*pipe_config
)
5793 struct drm_device
*dev
= crtc
->base
.dev
;
5794 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5795 int pipe
= crtc
->pipe
;
5797 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
5798 u32 coreclk
, reg_val
;
5800 mutex_lock(&dev_priv
->dpio_lock
);
5802 bestn
= pipe_config
->dpll
.n
;
5803 bestm1
= pipe_config
->dpll
.m1
;
5804 bestm2
= pipe_config
->dpll
.m2
;
5805 bestp1
= pipe_config
->dpll
.p1
;
5806 bestp2
= pipe_config
->dpll
.p2
;
5808 /* See eDP HDMI DPIO driver vbios notes doc */
5810 /* PLL B needs special handling */
5812 vlv_pllb_recal_opamp(dev_priv
, pipe
);
5814 /* Set up Tx target for periodic Rcomp update */
5815 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
5817 /* Disable target IRef on PLL */
5818 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
5819 reg_val
&= 0x00ffffff;
5820 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
5822 /* Disable fast lock */
5823 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
5825 /* Set idtafcrecal before PLL is enabled */
5826 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
5827 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
5828 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
5829 mdiv
|= (1 << DPIO_K_SHIFT
);
5832 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
5833 * but we don't support that).
5834 * Note: don't use the DAC post divider as it seems unstable.
5836 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
5837 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
5839 mdiv
|= DPIO_ENABLE_CALIBRATION
;
5840 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
5842 /* Set HBR and RBR LPF coefficients */
5843 if (pipe_config
->port_clock
== 162000 ||
5844 intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
) ||
5845 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
))
5846 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
5849 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
5852 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
) ||
5853 intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
5854 /* Use SSC source */
5856 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5859 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5861 } else { /* HDMI or VGA */
5862 /* Use bend source */
5864 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5867 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5871 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
5872 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
5873 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
5874 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))
5875 coreclk
|= 0x01000000;
5876 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
5878 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
5879 mutex_unlock(&dev_priv
->dpio_lock
);
5882 static void chv_update_pll(struct intel_crtc
*crtc
,
5883 struct intel_crtc_config
*pipe_config
)
5885 pipe_config
->dpll_hw_state
.dpll
= DPLL_SSC_REF_CLOCK_CHV
|
5886 DPLL_REFA_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
|
5888 if (crtc
->pipe
!= PIPE_A
)
5889 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
5891 pipe_config
->dpll_hw_state
.dpll_md
=
5892 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5895 static void chv_prepare_pll(struct intel_crtc
*crtc
,
5896 const struct intel_crtc_config
*pipe_config
)
5898 struct drm_device
*dev
= crtc
->base
.dev
;
5899 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5900 int pipe
= crtc
->pipe
;
5901 int dpll_reg
= DPLL(crtc
->pipe
);
5902 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
5903 u32 loopfilter
, intcoeff
;
5904 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
5907 bestn
= pipe_config
->dpll
.n
;
5908 bestm2_frac
= pipe_config
->dpll
.m2
& 0x3fffff;
5909 bestm1
= pipe_config
->dpll
.m1
;
5910 bestm2
= pipe_config
->dpll
.m2
>> 22;
5911 bestp1
= pipe_config
->dpll
.p1
;
5912 bestp2
= pipe_config
->dpll
.p2
;
5915 * Enable Refclk and SSC
5917 I915_WRITE(dpll_reg
,
5918 pipe_config
->dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
5920 mutex_lock(&dev_priv
->dpio_lock
);
5922 /* p1 and p2 divider */
5923 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
5924 5 << DPIO_CHV_S1_DIV_SHIFT
|
5925 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
5926 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
5927 1 << DPIO_CHV_K_DIV_SHIFT
);
5929 /* Feedback post-divider - m2 */
5930 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
5932 /* Feedback refclk divider - n and m1 */
5933 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
5934 DPIO_CHV_M1_DIV_BY_2
|
5935 1 << DPIO_CHV_N_DIV_SHIFT
);
5937 /* M2 fraction division */
5938 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
5940 /* M2 fraction division enable */
5941 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
),
5942 DPIO_CHV_FRAC_DIV_EN
|
5943 (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
));
5946 refclk
= i9xx_get_refclk(crtc
, 0);
5947 loopfilter
= 5 << DPIO_CHV_PROP_COEFF_SHIFT
|
5948 2 << DPIO_CHV_GAIN_CTRL_SHIFT
;
5949 if (refclk
== 100000)
5951 else if (refclk
== 38400)
5955 loopfilter
|= intcoeff
<< DPIO_CHV_INT_COEFF_SHIFT
;
5956 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
5959 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
5960 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
5963 mutex_unlock(&dev_priv
->dpio_lock
);
5967 * vlv_force_pll_on - forcibly enable just the PLL
5968 * @dev_priv: i915 private structure
5969 * @pipe: pipe PLL to enable
5970 * @dpll: PLL configuration
5972 * Enable the PLL for @pipe using the supplied @dpll config. To be used
5973 * in cases where we need the PLL enabled even when @pipe is not going to
5976 void vlv_force_pll_on(struct drm_device
*dev
, enum pipe pipe
,
5977 const struct dpll
*dpll
)
5979 struct intel_crtc
*crtc
=
5980 to_intel_crtc(intel_get_crtc_for_pipe(dev
, pipe
));
5981 struct intel_crtc_config pipe_config
= {
5982 .pixel_multiplier
= 1,
5986 if (IS_CHERRYVIEW(dev
)) {
5987 chv_update_pll(crtc
, &pipe_config
);
5988 chv_prepare_pll(crtc
, &pipe_config
);
5989 chv_enable_pll(crtc
, &pipe_config
);
5991 vlv_update_pll(crtc
, &pipe_config
);
5992 vlv_prepare_pll(crtc
, &pipe_config
);
5993 vlv_enable_pll(crtc
, &pipe_config
);
5998 * vlv_force_pll_off - forcibly disable just the PLL
5999 * @dev_priv: i915 private structure
6000 * @pipe: pipe PLL to disable
6002 * Disable the PLL for @pipe. To be used in cases where we need
6003 * the PLL enabled even when @pipe is not going to be enabled.
6005 void vlv_force_pll_off(struct drm_device
*dev
, enum pipe pipe
)
6007 if (IS_CHERRYVIEW(dev
))
6008 chv_disable_pll(to_i915(dev
), pipe
);
6010 vlv_disable_pll(to_i915(dev
), pipe
);
6013 static void i9xx_update_pll(struct intel_crtc
*crtc
,
6014 intel_clock_t
*reduced_clock
,
6017 struct drm_device
*dev
= crtc
->base
.dev
;
6018 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6021 struct dpll
*clock
= &crtc
->config
.dpll
;
6023 i9xx_update_pll_dividers(crtc
, reduced_clock
);
6025 is_sdvo
= intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
) ||
6026 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
);
6028 dpll
= DPLL_VGA_MODE_DIS
;
6030 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
6031 dpll
|= DPLLB_MODE_LVDS
;
6033 dpll
|= DPLLB_MODE_DAC_SERIAL
;
6035 if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
6036 dpll
|= (crtc
->config
.pixel_multiplier
- 1)
6037 << SDVO_MULTIPLIER_SHIFT_HIRES
;
6041 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6043 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
))
6044 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6046 /* compute bitmask from p1 value */
6047 if (IS_PINEVIEW(dev
))
6048 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
6050 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6051 if (IS_G4X(dev
) && reduced_clock
)
6052 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
6054 switch (clock
->p2
) {
6056 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
6059 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
6062 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
6065 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
6068 if (INTEL_INFO(dev
)->gen
>= 4)
6069 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
6071 if (crtc
->config
.sdvo_tv_clock
)
6072 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
6073 else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
6074 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
6075 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
6077 dpll
|= PLL_REF_INPUT_DREFCLK
;
6079 dpll
|= DPLL_VCO_ENABLE
;
6080 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
6082 if (INTEL_INFO(dev
)->gen
>= 4) {
6083 u32 dpll_md
= (crtc
->config
.pixel_multiplier
- 1)
6084 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6085 crtc
->config
.dpll_hw_state
.dpll_md
= dpll_md
;
6089 static void i8xx_update_pll(struct intel_crtc
*crtc
,
6090 intel_clock_t
*reduced_clock
,
6093 struct drm_device
*dev
= crtc
->base
.dev
;
6094 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6096 struct dpll
*clock
= &crtc
->config
.dpll
;
6098 i9xx_update_pll_dividers(crtc
, reduced_clock
);
6100 dpll
= DPLL_VGA_MODE_DIS
;
6102 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
6103 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6106 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
6108 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6110 dpll
|= PLL_P2_DIVIDE_BY_4
;
6113 if (!IS_I830(dev
) && intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
))
6114 dpll
|= DPLL_DVO_2X_MODE
;
6116 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
6117 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
6118 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
6120 dpll
|= PLL_REF_INPUT_DREFCLK
;
6122 dpll
|= DPLL_VCO_ENABLE
;
6123 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
6126 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
6128 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6129 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6130 enum pipe pipe
= intel_crtc
->pipe
;
6131 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
6132 struct drm_display_mode
*adjusted_mode
=
6133 &intel_crtc
->config
.adjusted_mode
;
6134 uint32_t crtc_vtotal
, crtc_vblank_end
;
6137 /* We need to be careful not to changed the adjusted mode, for otherwise
6138 * the hw state checker will get angry at the mismatch. */
6139 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
6140 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
6142 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
6143 /* the chip adds 2 halflines automatically */
6145 crtc_vblank_end
-= 1;
6147 if (intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
6148 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
6150 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
6151 adjusted_mode
->crtc_htotal
/ 2;
6153 vsyncshift
+= adjusted_mode
->crtc_htotal
;
6156 if (INTEL_INFO(dev
)->gen
> 3)
6157 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
6159 I915_WRITE(HTOTAL(cpu_transcoder
),
6160 (adjusted_mode
->crtc_hdisplay
- 1) |
6161 ((adjusted_mode
->crtc_htotal
- 1) << 16));
6162 I915_WRITE(HBLANK(cpu_transcoder
),
6163 (adjusted_mode
->crtc_hblank_start
- 1) |
6164 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
6165 I915_WRITE(HSYNC(cpu_transcoder
),
6166 (adjusted_mode
->crtc_hsync_start
- 1) |
6167 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
6169 I915_WRITE(VTOTAL(cpu_transcoder
),
6170 (adjusted_mode
->crtc_vdisplay
- 1) |
6171 ((crtc_vtotal
- 1) << 16));
6172 I915_WRITE(VBLANK(cpu_transcoder
),
6173 (adjusted_mode
->crtc_vblank_start
- 1) |
6174 ((crtc_vblank_end
- 1) << 16));
6175 I915_WRITE(VSYNC(cpu_transcoder
),
6176 (adjusted_mode
->crtc_vsync_start
- 1) |
6177 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
6179 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
6180 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
6181 * documented on the DDI_FUNC_CTL register description, EDP Input Select
6183 if (IS_HASWELL(dev
) && cpu_transcoder
== TRANSCODER_EDP
&&
6184 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
6185 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
6187 /* pipesrc controls the size that is scaled from, which should
6188 * always be the user's requested size.
6190 I915_WRITE(PIPESRC(pipe
),
6191 ((intel_crtc
->config
.pipe_src_w
- 1) << 16) |
6192 (intel_crtc
->config
.pipe_src_h
- 1));
6195 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
6196 struct intel_crtc_config
*pipe_config
)
6198 struct drm_device
*dev
= crtc
->base
.dev
;
6199 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6200 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
6203 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
6204 pipe_config
->adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
6205 pipe_config
->adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
6206 tmp
= I915_READ(HBLANK(cpu_transcoder
));
6207 pipe_config
->adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
6208 pipe_config
->adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
6209 tmp
= I915_READ(HSYNC(cpu_transcoder
));
6210 pipe_config
->adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
6211 pipe_config
->adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
6213 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
6214 pipe_config
->adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
6215 pipe_config
->adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
6216 tmp
= I915_READ(VBLANK(cpu_transcoder
));
6217 pipe_config
->adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
6218 pipe_config
->adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
6219 tmp
= I915_READ(VSYNC(cpu_transcoder
));
6220 pipe_config
->adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
6221 pipe_config
->adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
6223 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
6224 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
6225 pipe_config
->adjusted_mode
.crtc_vtotal
+= 1;
6226 pipe_config
->adjusted_mode
.crtc_vblank_end
+= 1;
6229 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
6230 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
6231 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
6233 pipe_config
->requested_mode
.vdisplay
= pipe_config
->pipe_src_h
;
6234 pipe_config
->requested_mode
.hdisplay
= pipe_config
->pipe_src_w
;
6237 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
6238 struct intel_crtc_config
*pipe_config
)
6240 mode
->hdisplay
= pipe_config
->adjusted_mode
.crtc_hdisplay
;
6241 mode
->htotal
= pipe_config
->adjusted_mode
.crtc_htotal
;
6242 mode
->hsync_start
= pipe_config
->adjusted_mode
.crtc_hsync_start
;
6243 mode
->hsync_end
= pipe_config
->adjusted_mode
.crtc_hsync_end
;
6245 mode
->vdisplay
= pipe_config
->adjusted_mode
.crtc_vdisplay
;
6246 mode
->vtotal
= pipe_config
->adjusted_mode
.crtc_vtotal
;
6247 mode
->vsync_start
= pipe_config
->adjusted_mode
.crtc_vsync_start
;
6248 mode
->vsync_end
= pipe_config
->adjusted_mode
.crtc_vsync_end
;
6250 mode
->flags
= pipe_config
->adjusted_mode
.flags
;
6252 mode
->clock
= pipe_config
->adjusted_mode
.crtc_clock
;
6253 mode
->flags
|= pipe_config
->adjusted_mode
.flags
;
6256 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
6258 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6259 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6264 if ((intel_crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
6265 (intel_crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
6266 pipeconf
|= I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
;
6268 if (intel_crtc
->config
.double_wide
)
6269 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
6271 /* only g4x and later have fancy bpc/dither controls */
6272 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
6273 /* Bspec claims that we can't use dithering for 30bpp pipes. */
6274 if (intel_crtc
->config
.dither
&& intel_crtc
->config
.pipe_bpp
!= 30)
6275 pipeconf
|= PIPECONF_DITHER_EN
|
6276 PIPECONF_DITHER_TYPE_SP
;
6278 switch (intel_crtc
->config
.pipe_bpp
) {
6280 pipeconf
|= PIPECONF_6BPC
;
6283 pipeconf
|= PIPECONF_8BPC
;
6286 pipeconf
|= PIPECONF_10BPC
;
6289 /* Case prevented by intel_choose_pipe_bpp_dither. */
6294 if (HAS_PIPE_CXSR(dev
)) {
6295 if (intel_crtc
->lowfreq_avail
) {
6296 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
6297 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
6299 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
6303 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
6304 if (INTEL_INFO(dev
)->gen
< 4 ||
6305 intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
6306 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
6308 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
6310 pipeconf
|= PIPECONF_PROGRESSIVE
;
6312 if (IS_VALLEYVIEW(dev
) && intel_crtc
->config
.limited_color_range
)
6313 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
6315 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
6316 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
6319 static int i9xx_crtc_mode_set(struct intel_crtc
*crtc
,
6321 struct drm_framebuffer
*fb
)
6323 struct drm_device
*dev
= crtc
->base
.dev
;
6324 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6325 int refclk
, num_connectors
= 0;
6326 intel_clock_t clock
, reduced_clock
;
6327 bool ok
, has_reduced_clock
= false;
6328 bool is_lvds
= false, is_dsi
= false;
6329 struct intel_encoder
*encoder
;
6330 const intel_limit_t
*limit
;
6332 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
6333 switch (encoder
->type
) {
6334 case INTEL_OUTPUT_LVDS
:
6337 case INTEL_OUTPUT_DSI
:
6350 if (!crtc
->config
.clock_set
) {
6351 refclk
= i9xx_get_refclk(crtc
, num_connectors
);
6354 * Returns a set of divisors for the desired target clock with
6355 * the given refclk, or FALSE. The returned values represent
6356 * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
6359 limit
= intel_limit(crtc
, refclk
);
6360 ok
= dev_priv
->display
.find_dpll(limit
, crtc
,
6361 crtc
->config
.port_clock
,
6362 refclk
, NULL
, &clock
);
6364 DRM_ERROR("Couldn't find PLL settings for mode!\n");
6368 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
6370 * Ensure we match the reduced clock's P to the target
6371 * clock. If the clocks don't match, we can't switch
6372 * the display clock by using the FP0/FP1. In such case
6373 * we will disable the LVDS downclock feature.
6376 dev_priv
->display
.find_dpll(limit
, crtc
,
6377 dev_priv
->lvds_downclock
,
6381 /* Compat-code for transition, will disappear. */
6382 crtc
->config
.dpll
.n
= clock
.n
;
6383 crtc
->config
.dpll
.m1
= clock
.m1
;
6384 crtc
->config
.dpll
.m2
= clock
.m2
;
6385 crtc
->config
.dpll
.p1
= clock
.p1
;
6386 crtc
->config
.dpll
.p2
= clock
.p2
;
6390 i8xx_update_pll(crtc
,
6391 has_reduced_clock
? &reduced_clock
: NULL
,
6393 } else if (IS_CHERRYVIEW(dev
)) {
6394 chv_update_pll(crtc
, &crtc
->config
);
6395 } else if (IS_VALLEYVIEW(dev
)) {
6396 vlv_update_pll(crtc
, &crtc
->config
);
6398 i9xx_update_pll(crtc
,
6399 has_reduced_clock
? &reduced_clock
: NULL
,
6406 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
6407 struct intel_crtc_config
*pipe_config
)
6409 struct drm_device
*dev
= crtc
->base
.dev
;
6410 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6413 if (INTEL_INFO(dev
)->gen
<= 3 && (IS_I830(dev
) || !IS_MOBILE(dev
)))
6416 tmp
= I915_READ(PFIT_CONTROL
);
6417 if (!(tmp
& PFIT_ENABLE
))
6420 /* Check whether the pfit is attached to our pipe. */
6421 if (INTEL_INFO(dev
)->gen
< 4) {
6422 if (crtc
->pipe
!= PIPE_B
)
6425 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
6429 pipe_config
->gmch_pfit
.control
= tmp
;
6430 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
6431 if (INTEL_INFO(dev
)->gen
< 5)
6432 pipe_config
->gmch_pfit
.lvds_border_bits
=
6433 I915_READ(LVDS
) & LVDS_BORDER_ENABLE
;
6436 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
6437 struct intel_crtc_config
*pipe_config
)
6439 struct drm_device
*dev
= crtc
->base
.dev
;
6440 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6441 int pipe
= pipe_config
->cpu_transcoder
;
6442 intel_clock_t clock
;
6444 int refclk
= 100000;
6446 /* In case of MIPI DPLL will not even be used */
6447 if (!(pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
))
6450 mutex_lock(&dev_priv
->dpio_lock
);
6451 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
6452 mutex_unlock(&dev_priv
->dpio_lock
);
6454 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
6455 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
6456 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
6457 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
6458 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
6460 vlv_clock(refclk
, &clock
);
6462 /* clock.dot is the fast clock */
6463 pipe_config
->port_clock
= clock
.dot
/ 5;
6466 static void i9xx_get_plane_config(struct intel_crtc
*crtc
,
6467 struct intel_plane_config
*plane_config
)
6469 struct drm_device
*dev
= crtc
->base
.dev
;
6470 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6471 u32 val
, base
, offset
;
6472 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
6473 int fourcc
, pixel_format
;
6476 crtc
->base
.primary
->fb
= kzalloc(sizeof(struct intel_framebuffer
), GFP_KERNEL
);
6477 if (!crtc
->base
.primary
->fb
) {
6478 DRM_DEBUG_KMS("failed to alloc fb\n");
6482 val
= I915_READ(DSPCNTR(plane
));
6484 if (INTEL_INFO(dev
)->gen
>= 4)
6485 if (val
& DISPPLANE_TILED
)
6486 plane_config
->tiled
= true;
6488 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
6489 fourcc
= intel_format_to_fourcc(pixel_format
);
6490 crtc
->base
.primary
->fb
->pixel_format
= fourcc
;
6491 crtc
->base
.primary
->fb
->bits_per_pixel
=
6492 drm_format_plane_cpp(fourcc
, 0) * 8;
6494 if (INTEL_INFO(dev
)->gen
>= 4) {
6495 if (plane_config
->tiled
)
6496 offset
= I915_READ(DSPTILEOFF(plane
));
6498 offset
= I915_READ(DSPLINOFF(plane
));
6499 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
6501 base
= I915_READ(DSPADDR(plane
));
6503 plane_config
->base
= base
;
6505 val
= I915_READ(PIPESRC(pipe
));
6506 crtc
->base
.primary
->fb
->width
= ((val
>> 16) & 0xfff) + 1;
6507 crtc
->base
.primary
->fb
->height
= ((val
>> 0) & 0xfff) + 1;
6509 val
= I915_READ(DSPSTRIDE(pipe
));
6510 crtc
->base
.primary
->fb
->pitches
[0] = val
& 0xffffffc0;
6512 aligned_height
= intel_align_height(dev
, crtc
->base
.primary
->fb
->height
,
6513 plane_config
->tiled
);
6515 plane_config
->size
= PAGE_ALIGN(crtc
->base
.primary
->fb
->pitches
[0] *
6518 DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
6519 pipe
, plane
, crtc
->base
.primary
->fb
->width
,
6520 crtc
->base
.primary
->fb
->height
,
6521 crtc
->base
.primary
->fb
->bits_per_pixel
, base
,
6522 crtc
->base
.primary
->fb
->pitches
[0],
6523 plane_config
->size
);
6527 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
6528 struct intel_crtc_config
*pipe_config
)
6530 struct drm_device
*dev
= crtc
->base
.dev
;
6531 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6532 int pipe
= pipe_config
->cpu_transcoder
;
6533 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
6534 intel_clock_t clock
;
6535 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
;
6536 int refclk
= 100000;
6538 mutex_lock(&dev_priv
->dpio_lock
);
6539 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
6540 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
6541 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
6542 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
6543 mutex_unlock(&dev_priv
->dpio_lock
);
6545 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
6546 clock
.m2
= ((pll_dw0
& 0xff) << 22) | (pll_dw2
& 0x3fffff);
6547 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
6548 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
6549 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
6551 chv_clock(refclk
, &clock
);
6553 /* clock.dot is the fast clock */
6554 pipe_config
->port_clock
= clock
.dot
/ 5;
6557 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
6558 struct intel_crtc_config
*pipe_config
)
6560 struct drm_device
*dev
= crtc
->base
.dev
;
6561 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6564 if (!intel_display_power_is_enabled(dev_priv
,
6565 POWER_DOMAIN_PIPE(crtc
->pipe
)))
6568 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
6569 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
6571 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
6572 if (!(tmp
& PIPECONF_ENABLE
))
6575 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
6576 switch (tmp
& PIPECONF_BPC_MASK
) {
6578 pipe_config
->pipe_bpp
= 18;
6581 pipe_config
->pipe_bpp
= 24;
6583 case PIPECONF_10BPC
:
6584 pipe_config
->pipe_bpp
= 30;
6591 if (IS_VALLEYVIEW(dev
) && (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
6592 pipe_config
->limited_color_range
= true;
6594 if (INTEL_INFO(dev
)->gen
< 4)
6595 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
6597 intel_get_pipe_timings(crtc
, pipe_config
);
6599 i9xx_get_pfit_config(crtc
, pipe_config
);
6601 if (INTEL_INFO(dev
)->gen
>= 4) {
6602 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
6603 pipe_config
->pixel_multiplier
=
6604 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
6605 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
6606 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
6607 } else if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
6608 tmp
= I915_READ(DPLL(crtc
->pipe
));
6609 pipe_config
->pixel_multiplier
=
6610 ((tmp
& SDVO_MULTIPLIER_MASK
)
6611 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
6613 /* Note that on i915G/GM the pixel multiplier is in the sdvo
6614 * port and will be fixed up in the encoder->get_config
6616 pipe_config
->pixel_multiplier
= 1;
6618 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
6619 if (!IS_VALLEYVIEW(dev
)) {
6621 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
6622 * on 830. Filter it out here so that we don't
6623 * report errors due to that.
6626 pipe_config
->dpll_hw_state
.dpll
&= ~DPLL_DVO_2X_MODE
;
6628 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
6629 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
6631 /* Mask out read-only status bits. */
6632 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
6633 DPLL_PORTC_READY_MASK
|
6634 DPLL_PORTB_READY_MASK
);
6637 if (IS_CHERRYVIEW(dev
))
6638 chv_crtc_clock_get(crtc
, pipe_config
);
6639 else if (IS_VALLEYVIEW(dev
))
6640 vlv_crtc_clock_get(crtc
, pipe_config
);
6642 i9xx_crtc_clock_get(crtc
, pipe_config
);
6647 static void ironlake_init_pch_refclk(struct drm_device
*dev
)
6649 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6650 struct intel_encoder
*encoder
;
6652 bool has_lvds
= false;
6653 bool has_cpu_edp
= false;
6654 bool has_panel
= false;
6655 bool has_ck505
= false;
6656 bool can_ssc
= false;
6658 /* We need to take the global config into account */
6659 for_each_intel_encoder(dev
, encoder
) {
6660 switch (encoder
->type
) {
6661 case INTEL_OUTPUT_LVDS
:
6665 case INTEL_OUTPUT_EDP
:
6667 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
6675 if (HAS_PCH_IBX(dev
)) {
6676 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
6677 can_ssc
= has_ck505
;
6683 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
6684 has_panel
, has_lvds
, has_ck505
);
6686 /* Ironlake: try to setup display ref clock before DPLL
6687 * enabling. This is only under driver's control after
6688 * PCH B stepping, previous chipset stepping should be
6689 * ignoring this setting.
6691 val
= I915_READ(PCH_DREF_CONTROL
);
6693 /* As we must carefully and slowly disable/enable each source in turn,
6694 * compute the final state we want first and check if we need to
6695 * make any changes at all.
6698 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
6700 final
|= DREF_NONSPREAD_CK505_ENABLE
;
6702 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
6704 final
&= ~DREF_SSC_SOURCE_MASK
;
6705 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6706 final
&= ~DREF_SSC1_ENABLE
;
6709 final
|= DREF_SSC_SOURCE_ENABLE
;
6711 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
6712 final
|= DREF_SSC1_ENABLE
;
6715 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
6716 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
6718 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
6720 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6722 final
|= DREF_SSC_SOURCE_DISABLE
;
6723 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6729 /* Always enable nonspread source */
6730 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
6733 val
|= DREF_NONSPREAD_CK505_ENABLE
;
6735 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
6738 val
&= ~DREF_SSC_SOURCE_MASK
;
6739 val
|= DREF_SSC_SOURCE_ENABLE
;
6741 /* SSC must be turned on before enabling the CPU output */
6742 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
6743 DRM_DEBUG_KMS("Using SSC on panel\n");
6744 val
|= DREF_SSC1_ENABLE
;
6746 val
&= ~DREF_SSC1_ENABLE
;
6748 /* Get SSC going before enabling the outputs */
6749 I915_WRITE(PCH_DREF_CONTROL
, val
);
6750 POSTING_READ(PCH_DREF_CONTROL
);
6753 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6755 /* Enable CPU source on CPU attached eDP */
6757 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
6758 DRM_DEBUG_KMS("Using SSC on eDP\n");
6759 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
6761 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
6763 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6765 I915_WRITE(PCH_DREF_CONTROL
, val
);
6766 POSTING_READ(PCH_DREF_CONTROL
);
6769 DRM_DEBUG_KMS("Disabling SSC entirely\n");
6771 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6773 /* Turn off CPU output */
6774 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6776 I915_WRITE(PCH_DREF_CONTROL
, val
);
6777 POSTING_READ(PCH_DREF_CONTROL
);
6780 /* Turn off the SSC source */
6781 val
&= ~DREF_SSC_SOURCE_MASK
;
6782 val
|= DREF_SSC_SOURCE_DISABLE
;
6785 val
&= ~DREF_SSC1_ENABLE
;
6787 I915_WRITE(PCH_DREF_CONTROL
, val
);
6788 POSTING_READ(PCH_DREF_CONTROL
);
6792 BUG_ON(val
!= final
);
6795 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
6799 tmp
= I915_READ(SOUTH_CHICKEN2
);
6800 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
6801 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
6803 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2
) &
6804 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
6805 DRM_ERROR("FDI mPHY reset assert timeout\n");
6807 tmp
= I915_READ(SOUTH_CHICKEN2
);
6808 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
6809 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
6811 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2
) &
6812 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
6813 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
6816 /* WaMPhyProgramming:hsw */
6817 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
6821 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
6822 tmp
&= ~(0xFF << 24);
6823 tmp
|= (0x12 << 24);
6824 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
6826 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
6828 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
6830 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
6832 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
6834 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
6835 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
6836 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
6838 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
6839 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
6840 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
6842 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
6845 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
6847 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
6850 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
6852 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
6855 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
6857 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
6860 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
6862 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
6863 tmp
&= ~(0xFF << 16);
6864 tmp
|= (0x1C << 16);
6865 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
6867 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
6868 tmp
&= ~(0xFF << 16);
6869 tmp
|= (0x1C << 16);
6870 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
6872 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
6874 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
6876 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
6878 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
6880 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
6881 tmp
&= ~(0xF << 28);
6883 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
6885 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
6886 tmp
&= ~(0xF << 28);
6888 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
6891 /* Implements 3 different sequences from BSpec chapter "Display iCLK
6892 * Programming" based on the parameters passed:
6893 * - Sequence to enable CLKOUT_DP
6894 * - Sequence to enable CLKOUT_DP without spread
6895 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
6897 static void lpt_enable_clkout_dp(struct drm_device
*dev
, bool with_spread
,
6900 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6903 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
6905 if (WARN(dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
&&
6906 with_fdi
, "LP PCH doesn't have FDI\n"))
6909 mutex_lock(&dev_priv
->dpio_lock
);
6911 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6912 tmp
&= ~SBI_SSCCTL_DISABLE
;
6913 tmp
|= SBI_SSCCTL_PATHALT
;
6914 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6919 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6920 tmp
&= ~SBI_SSCCTL_PATHALT
;
6921 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6924 lpt_reset_fdi_mphy(dev_priv
);
6925 lpt_program_fdi_mphy(dev_priv
);
6929 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
6930 SBI_GEN0
: SBI_DBUFF0
;
6931 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
6932 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
6933 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
6935 mutex_unlock(&dev_priv
->dpio_lock
);
6938 /* Sequence to disable CLKOUT_DP */
6939 static void lpt_disable_clkout_dp(struct drm_device
*dev
)
6941 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6944 mutex_lock(&dev_priv
->dpio_lock
);
6946 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
6947 SBI_GEN0
: SBI_DBUFF0
;
6948 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
6949 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
6950 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
6952 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6953 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
6954 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
6955 tmp
|= SBI_SSCCTL_PATHALT
;
6956 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6959 tmp
|= SBI_SSCCTL_DISABLE
;
6960 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6963 mutex_unlock(&dev_priv
->dpio_lock
);
6966 static void lpt_init_pch_refclk(struct drm_device
*dev
)
6968 struct intel_encoder
*encoder
;
6969 bool has_vga
= false;
6971 for_each_intel_encoder(dev
, encoder
) {
6972 switch (encoder
->type
) {
6973 case INTEL_OUTPUT_ANALOG
:
6982 lpt_enable_clkout_dp(dev
, true, true);
6984 lpt_disable_clkout_dp(dev
);
6988 * Initialize reference clocks when the driver loads
6990 void intel_init_pch_refclk(struct drm_device
*dev
)
6992 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
6993 ironlake_init_pch_refclk(dev
);
6994 else if (HAS_PCH_LPT(dev
))
6995 lpt_init_pch_refclk(dev
);
6998 static int ironlake_get_refclk(struct drm_crtc
*crtc
)
7000 struct drm_device
*dev
= crtc
->dev
;
7001 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7002 struct intel_encoder
*encoder
;
7003 int num_connectors
= 0;
7004 bool is_lvds
= false;
7006 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
7007 switch (encoder
->type
) {
7008 case INTEL_OUTPUT_LVDS
:
7017 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
7018 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
7019 dev_priv
->vbt
.lvds_ssc_freq
);
7020 return dev_priv
->vbt
.lvds_ssc_freq
;
7026 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
7028 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
7029 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7030 int pipe
= intel_crtc
->pipe
;
7035 switch (intel_crtc
->config
.pipe_bpp
) {
7037 val
|= PIPECONF_6BPC
;
7040 val
|= PIPECONF_8BPC
;
7043 val
|= PIPECONF_10BPC
;
7046 val
|= PIPECONF_12BPC
;
7049 /* Case prevented by intel_choose_pipe_bpp_dither. */
7053 if (intel_crtc
->config
.dither
)
7054 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
7056 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
7057 val
|= PIPECONF_INTERLACED_ILK
;
7059 val
|= PIPECONF_PROGRESSIVE
;
7061 if (intel_crtc
->config
.limited_color_range
)
7062 val
|= PIPECONF_COLOR_RANGE_SELECT
;
7064 I915_WRITE(PIPECONF(pipe
), val
);
7065 POSTING_READ(PIPECONF(pipe
));
7069 * Set up the pipe CSC unit.
7071 * Currently only full range RGB to limited range RGB conversion
7072 * is supported, but eventually this should handle various
7073 * RGB<->YCbCr scenarios as well.
7075 static void intel_set_pipe_csc(struct drm_crtc
*crtc
)
7077 struct drm_device
*dev
= crtc
->dev
;
7078 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7079 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7080 int pipe
= intel_crtc
->pipe
;
7081 uint16_t coeff
= 0x7800; /* 1.0 */
7084 * TODO: Check what kind of values actually come out of the pipe
7085 * with these coeff/postoff values and adjust to get the best
7086 * accuracy. Perhaps we even need to take the bpc value into
7090 if (intel_crtc
->config
.limited_color_range
)
7091 coeff
= ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
7094 * GY/GU and RY/RU should be the other way around according
7095 * to BSpec, but reality doesn't agree. Just set them up in
7096 * a way that results in the correct picture.
7098 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe
), coeff
<< 16);
7099 I915_WRITE(PIPE_CSC_COEFF_BY(pipe
), 0);
7101 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe
), coeff
);
7102 I915_WRITE(PIPE_CSC_COEFF_BU(pipe
), 0);
7104 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe
), 0);
7105 I915_WRITE(PIPE_CSC_COEFF_BV(pipe
), coeff
<< 16);
7107 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe
), 0);
7108 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe
), 0);
7109 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe
), 0);
7111 if (INTEL_INFO(dev
)->gen
> 6) {
7112 uint16_t postoff
= 0;
7114 if (intel_crtc
->config
.limited_color_range
)
7115 postoff
= (16 * (1 << 12) / 255) & 0x1fff;
7117 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe
), postoff
);
7118 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe
), postoff
);
7119 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe
), postoff
);
7121 I915_WRITE(PIPE_CSC_MODE(pipe
), 0);
7123 uint32_t mode
= CSC_MODE_YUV_TO_RGB
;
7125 if (intel_crtc
->config
.limited_color_range
)
7126 mode
|= CSC_BLACK_SCREEN_OFFSET
;
7128 I915_WRITE(PIPE_CSC_MODE(pipe
), mode
);
7132 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
7134 struct drm_device
*dev
= crtc
->dev
;
7135 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7136 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7137 enum pipe pipe
= intel_crtc
->pipe
;
7138 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
7143 if (IS_HASWELL(dev
) && intel_crtc
->config
.dither
)
7144 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
7146 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
7147 val
|= PIPECONF_INTERLACED_ILK
;
7149 val
|= PIPECONF_PROGRESSIVE
;
7151 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
7152 POSTING_READ(PIPECONF(cpu_transcoder
));
7154 I915_WRITE(GAMMA_MODE(intel_crtc
->pipe
), GAMMA_MODE_MODE_8BIT
);
7155 POSTING_READ(GAMMA_MODE(intel_crtc
->pipe
));
7157 if (IS_BROADWELL(dev
) || INTEL_INFO(dev
)->gen
>= 9) {
7160 switch (intel_crtc
->config
.pipe_bpp
) {
7162 val
|= PIPEMISC_DITHER_6_BPC
;
7165 val
|= PIPEMISC_DITHER_8_BPC
;
7168 val
|= PIPEMISC_DITHER_10_BPC
;
7171 val
|= PIPEMISC_DITHER_12_BPC
;
7174 /* Case prevented by pipe_config_set_bpp. */
7178 if (intel_crtc
->config
.dither
)
7179 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
7181 I915_WRITE(PIPEMISC(pipe
), val
);
7185 static bool ironlake_compute_clocks(struct drm_crtc
*crtc
,
7186 intel_clock_t
*clock
,
7187 bool *has_reduced_clock
,
7188 intel_clock_t
*reduced_clock
)
7190 struct drm_device
*dev
= crtc
->dev
;
7191 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7192 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7194 const intel_limit_t
*limit
;
7195 bool ret
, is_lvds
= false;
7197 is_lvds
= intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_LVDS
);
7199 refclk
= ironlake_get_refclk(crtc
);
7202 * Returns a set of divisors for the desired target clock with the given
7203 * refclk, or FALSE. The returned values represent the clock equation:
7204 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
7206 limit
= intel_limit(intel_crtc
, refclk
);
7207 ret
= dev_priv
->display
.find_dpll(limit
, intel_crtc
,
7208 intel_crtc
->config
.port_clock
,
7209 refclk
, NULL
, clock
);
7213 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
7215 * Ensure we match the reduced clock's P to the target clock.
7216 * If the clocks don't match, we can't switch the display clock
7217 * by using the FP0/FP1. In such case we will disable the LVDS
7218 * downclock feature.
7220 *has_reduced_clock
=
7221 dev_priv
->display
.find_dpll(limit
, intel_crtc
,
7222 dev_priv
->lvds_downclock
,
7230 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
7233 * Account for spread spectrum to avoid
7234 * oversubscribing the link. Max center spread
7235 * is 2.5%; use 5% for safety's sake.
7237 u32 bps
= target_clock
* bpp
* 21 / 20;
7238 return DIV_ROUND_UP(bps
, link_bw
* 8);
7241 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
7243 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
7246 static uint32_t ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
7248 intel_clock_t
*reduced_clock
, u32
*fp2
)
7250 struct drm_crtc
*crtc
= &intel_crtc
->base
;
7251 struct drm_device
*dev
= crtc
->dev
;
7252 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7253 struct intel_encoder
*intel_encoder
;
7255 int factor
, num_connectors
= 0;
7256 bool is_lvds
= false, is_sdvo
= false;
7258 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
7259 switch (intel_encoder
->type
) {
7260 case INTEL_OUTPUT_LVDS
:
7263 case INTEL_OUTPUT_SDVO
:
7264 case INTEL_OUTPUT_HDMI
:
7274 /* Enable autotuning of the PLL clock (if permissible) */
7277 if ((intel_panel_use_ssc(dev_priv
) &&
7278 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
7279 (HAS_PCH_IBX(dev
) && intel_is_dual_link_lvds(dev
)))
7281 } else if (intel_crtc
->config
.sdvo_tv_clock
)
7284 if (ironlake_needs_fb_cb_tune(&intel_crtc
->config
.dpll
, factor
))
7287 if (fp2
&& (reduced_clock
->m
< factor
* reduced_clock
->n
))
7293 dpll
|= DPLLB_MODE_LVDS
;
7295 dpll
|= DPLLB_MODE_DAC_SERIAL
;
7297 dpll
|= (intel_crtc
->config
.pixel_multiplier
- 1)
7298 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
7301 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7302 if (intel_crtc
->config
.has_dp_encoder
)
7303 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7305 /* compute bitmask from p1 value */
7306 dpll
|= (1 << (intel_crtc
->config
.dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7308 dpll
|= (1 << (intel_crtc
->config
.dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
7310 switch (intel_crtc
->config
.dpll
.p2
) {
7312 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
7315 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
7318 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
7321 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
7325 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
7326 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7328 dpll
|= PLL_REF_INPUT_DREFCLK
;
7330 return dpll
| DPLL_VCO_ENABLE
;
7333 static int ironlake_crtc_mode_set(struct intel_crtc
*crtc
,
7335 struct drm_framebuffer
*fb
)
7337 struct drm_device
*dev
= crtc
->base
.dev
;
7338 intel_clock_t clock
, reduced_clock
;
7339 u32 dpll
= 0, fp
= 0, fp2
= 0;
7340 bool ok
, has_reduced_clock
= false;
7341 bool is_lvds
= false;
7342 struct intel_shared_dpll
*pll
;
7344 is_lvds
= intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
);
7346 WARN(!(HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)),
7347 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev
));
7349 ok
= ironlake_compute_clocks(&crtc
->base
, &clock
,
7350 &has_reduced_clock
, &reduced_clock
);
7351 if (!ok
&& !crtc
->config
.clock_set
) {
7352 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7355 /* Compat-code for transition, will disappear. */
7356 if (!crtc
->config
.clock_set
) {
7357 crtc
->config
.dpll
.n
= clock
.n
;
7358 crtc
->config
.dpll
.m1
= clock
.m1
;
7359 crtc
->config
.dpll
.m2
= clock
.m2
;
7360 crtc
->config
.dpll
.p1
= clock
.p1
;
7361 crtc
->config
.dpll
.p2
= clock
.p2
;
7364 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
7365 if (crtc
->config
.has_pch_encoder
) {
7366 fp
= i9xx_dpll_compute_fp(&crtc
->config
.dpll
);
7367 if (has_reduced_clock
)
7368 fp2
= i9xx_dpll_compute_fp(&reduced_clock
);
7370 dpll
= ironlake_compute_dpll(crtc
,
7371 &fp
, &reduced_clock
,
7372 has_reduced_clock
? &fp2
: NULL
);
7374 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
7375 crtc
->config
.dpll_hw_state
.fp0
= fp
;
7376 if (has_reduced_clock
)
7377 crtc
->config
.dpll_hw_state
.fp1
= fp2
;
7379 crtc
->config
.dpll_hw_state
.fp1
= fp
;
7381 pll
= intel_get_shared_dpll(crtc
);
7383 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
7384 pipe_name(crtc
->pipe
));
7388 intel_put_shared_dpll(crtc
);
7390 if (is_lvds
&& has_reduced_clock
&& i915
.powersave
)
7391 crtc
->lowfreq_avail
= true;
7393 crtc
->lowfreq_avail
= false;
7398 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
7399 struct intel_link_m_n
*m_n
)
7401 struct drm_device
*dev
= crtc
->base
.dev
;
7402 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7403 enum pipe pipe
= crtc
->pipe
;
7405 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
7406 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
7407 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
7409 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
7410 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
7411 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7414 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
7415 enum transcoder transcoder
,
7416 struct intel_link_m_n
*m_n
,
7417 struct intel_link_m_n
*m2_n2
)
7419 struct drm_device
*dev
= crtc
->base
.dev
;
7420 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7421 enum pipe pipe
= crtc
->pipe
;
7423 if (INTEL_INFO(dev
)->gen
>= 5) {
7424 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
7425 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
7426 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
7428 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
7429 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
7430 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7431 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
7432 * gen < 8) and if DRRS is supported (to make sure the
7433 * registers are not unnecessarily read).
7435 if (m2_n2
&& INTEL_INFO(dev
)->gen
< 8 &&
7436 crtc
->config
.has_drrs
) {
7437 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
7438 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
7439 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
7441 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
7442 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
7443 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7446 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
7447 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
7448 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
7450 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
7451 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
7452 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7456 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
7457 struct intel_crtc_config
*pipe_config
)
7459 if (crtc
->config
.has_pch_encoder
)
7460 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
7462 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
7463 &pipe_config
->dp_m_n
,
7464 &pipe_config
->dp_m2_n2
);
7467 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
7468 struct intel_crtc_config
*pipe_config
)
7470 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
7471 &pipe_config
->fdi_m_n
, NULL
);
7474 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
7475 struct intel_crtc_config
*pipe_config
)
7477 struct drm_device
*dev
= crtc
->base
.dev
;
7478 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7481 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
7483 if (tmp
& PF_ENABLE
) {
7484 pipe_config
->pch_pfit
.enabled
= true;
7485 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
7486 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
7488 /* We currently do not free assignements of panel fitters on
7489 * ivb/hsw (since we don't use the higher upscaling modes which
7490 * differentiates them) so just WARN about this case for now. */
7492 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
7493 PF_PIPE_SEL_IVB(crtc
->pipe
));
7498 static void ironlake_get_plane_config(struct intel_crtc
*crtc
,
7499 struct intel_plane_config
*plane_config
)
7501 struct drm_device
*dev
= crtc
->base
.dev
;
7502 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7503 u32 val
, base
, offset
;
7504 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
7505 int fourcc
, pixel_format
;
7508 crtc
->base
.primary
->fb
= kzalloc(sizeof(struct intel_framebuffer
), GFP_KERNEL
);
7509 if (!crtc
->base
.primary
->fb
) {
7510 DRM_DEBUG_KMS("failed to alloc fb\n");
7514 val
= I915_READ(DSPCNTR(plane
));
7516 if (INTEL_INFO(dev
)->gen
>= 4)
7517 if (val
& DISPPLANE_TILED
)
7518 plane_config
->tiled
= true;
7520 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
7521 fourcc
= intel_format_to_fourcc(pixel_format
);
7522 crtc
->base
.primary
->fb
->pixel_format
= fourcc
;
7523 crtc
->base
.primary
->fb
->bits_per_pixel
=
7524 drm_format_plane_cpp(fourcc
, 0) * 8;
7526 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
7527 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
7528 offset
= I915_READ(DSPOFFSET(plane
));
7530 if (plane_config
->tiled
)
7531 offset
= I915_READ(DSPTILEOFF(plane
));
7533 offset
= I915_READ(DSPLINOFF(plane
));
7535 plane_config
->base
= base
;
7537 val
= I915_READ(PIPESRC(pipe
));
7538 crtc
->base
.primary
->fb
->width
= ((val
>> 16) & 0xfff) + 1;
7539 crtc
->base
.primary
->fb
->height
= ((val
>> 0) & 0xfff) + 1;
7541 val
= I915_READ(DSPSTRIDE(pipe
));
7542 crtc
->base
.primary
->fb
->pitches
[0] = val
& 0xffffffc0;
7544 aligned_height
= intel_align_height(dev
, crtc
->base
.primary
->fb
->height
,
7545 plane_config
->tiled
);
7547 plane_config
->size
= PAGE_ALIGN(crtc
->base
.primary
->fb
->pitches
[0] *
7550 DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7551 pipe
, plane
, crtc
->base
.primary
->fb
->width
,
7552 crtc
->base
.primary
->fb
->height
,
7553 crtc
->base
.primary
->fb
->bits_per_pixel
, base
,
7554 crtc
->base
.primary
->fb
->pitches
[0],
7555 plane_config
->size
);
7558 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
7559 struct intel_crtc_config
*pipe_config
)
7561 struct drm_device
*dev
= crtc
->base
.dev
;
7562 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7565 if (!intel_display_power_is_enabled(dev_priv
,
7566 POWER_DOMAIN_PIPE(crtc
->pipe
)))
7569 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7570 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
7572 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
7573 if (!(tmp
& PIPECONF_ENABLE
))
7576 switch (tmp
& PIPECONF_BPC_MASK
) {
7578 pipe_config
->pipe_bpp
= 18;
7581 pipe_config
->pipe_bpp
= 24;
7583 case PIPECONF_10BPC
:
7584 pipe_config
->pipe_bpp
= 30;
7586 case PIPECONF_12BPC
:
7587 pipe_config
->pipe_bpp
= 36;
7593 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
7594 pipe_config
->limited_color_range
= true;
7596 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
7597 struct intel_shared_dpll
*pll
;
7599 pipe_config
->has_pch_encoder
= true;
7601 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
7602 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
7603 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
7605 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
7607 if (HAS_PCH_IBX(dev_priv
->dev
)) {
7608 pipe_config
->shared_dpll
=
7609 (enum intel_dpll_id
) crtc
->pipe
;
7611 tmp
= I915_READ(PCH_DPLL_SEL
);
7612 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
7613 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_B
;
7615 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_A
;
7618 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
7620 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
7621 &pipe_config
->dpll_hw_state
));
7623 tmp
= pipe_config
->dpll_hw_state
.dpll
;
7624 pipe_config
->pixel_multiplier
=
7625 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
7626 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
7628 ironlake_pch_clock_get(crtc
, pipe_config
);
7630 pipe_config
->pixel_multiplier
= 1;
7633 intel_get_pipe_timings(crtc
, pipe_config
);
7635 ironlake_get_pfit_config(crtc
, pipe_config
);
7640 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
7642 struct drm_device
*dev
= dev_priv
->dev
;
7643 struct intel_crtc
*crtc
;
7645 for_each_intel_crtc(dev
, crtc
)
7646 WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
7647 pipe_name(crtc
->pipe
));
7649 WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
7650 WARN(I915_READ(SPLL_CTL
) & SPLL_PLL_ENABLE
, "SPLL enabled\n");
7651 WARN(I915_READ(WRPLL_CTL1
) & WRPLL_PLL_ENABLE
, "WRPLL1 enabled\n");
7652 WARN(I915_READ(WRPLL_CTL2
) & WRPLL_PLL_ENABLE
, "WRPLL2 enabled\n");
7653 WARN(I915_READ(PCH_PP_STATUS
) & PP_ON
, "Panel power on\n");
7654 WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
7655 "CPU PWM1 enabled\n");
7656 if (IS_HASWELL(dev
))
7657 WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
7658 "CPU PWM2 enabled\n");
7659 WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
7660 "PCH PWM1 enabled\n");
7661 WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
7662 "Utility pin enabled\n");
7663 WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
7666 * In theory we can still leave IRQs enabled, as long as only the HPD
7667 * interrupts remain enabled. We used to check for that, but since it's
7668 * gen-specific and since we only disable LCPLL after we fully disable
7669 * the interrupts, the check below should be enough.
7671 WARN(intel_irqs_enabled(dev_priv
), "IRQs enabled\n");
7674 static uint32_t hsw_read_dcomp(struct drm_i915_private
*dev_priv
)
7676 struct drm_device
*dev
= dev_priv
->dev
;
7678 if (IS_HASWELL(dev
))
7679 return I915_READ(D_COMP_HSW
);
7681 return I915_READ(D_COMP_BDW
);
7684 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
7686 struct drm_device
*dev
= dev_priv
->dev
;
7688 if (IS_HASWELL(dev
)) {
7689 mutex_lock(&dev_priv
->rps
.hw_lock
);
7690 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
7692 DRM_ERROR("Failed to write to D_COMP\n");
7693 mutex_unlock(&dev_priv
->rps
.hw_lock
);
7695 I915_WRITE(D_COMP_BDW
, val
);
7696 POSTING_READ(D_COMP_BDW
);
7701 * This function implements pieces of two sequences from BSpec:
7702 * - Sequence for display software to disable LCPLL
7703 * - Sequence for display software to allow package C8+
7704 * The steps implemented here are just the steps that actually touch the LCPLL
7705 * register. Callers should take care of disabling all the display engine
7706 * functions, doing the mode unset, fixing interrupts, etc.
7708 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
7709 bool switch_to_fclk
, bool allow_power_down
)
7713 assert_can_disable_lcpll(dev_priv
);
7715 val
= I915_READ(LCPLL_CTL
);
7717 if (switch_to_fclk
) {
7718 val
|= LCPLL_CD_SOURCE_FCLK
;
7719 I915_WRITE(LCPLL_CTL
, val
);
7721 if (wait_for_atomic_us(I915_READ(LCPLL_CTL
) &
7722 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
7723 DRM_ERROR("Switching to FCLK failed\n");
7725 val
= I915_READ(LCPLL_CTL
);
7728 val
|= LCPLL_PLL_DISABLE
;
7729 I915_WRITE(LCPLL_CTL
, val
);
7730 POSTING_READ(LCPLL_CTL
);
7732 if (wait_for((I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
) == 0, 1))
7733 DRM_ERROR("LCPLL still locked\n");
7735 val
= hsw_read_dcomp(dev_priv
);
7736 val
|= D_COMP_COMP_DISABLE
;
7737 hsw_write_dcomp(dev_priv
, val
);
7740 if (wait_for((hsw_read_dcomp(dev_priv
) & D_COMP_RCOMP_IN_PROGRESS
) == 0,
7742 DRM_ERROR("D_COMP RCOMP still in progress\n");
7744 if (allow_power_down
) {
7745 val
= I915_READ(LCPLL_CTL
);
7746 val
|= LCPLL_POWER_DOWN_ALLOW
;
7747 I915_WRITE(LCPLL_CTL
, val
);
7748 POSTING_READ(LCPLL_CTL
);
7753 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
7756 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
7760 val
= I915_READ(LCPLL_CTL
);
7762 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
7763 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
7767 * Make sure we're not on PC8 state before disabling PC8, otherwise
7768 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
7770 * The other problem is that hsw_restore_lcpll() is called as part of
7771 * the runtime PM resume sequence, so we can't just call
7772 * gen6_gt_force_wake_get() because that function calls
7773 * intel_runtime_pm_get(), and we can't change the runtime PM refcount
7774 * while we are on the resume sequence. So to solve this problem we have
7775 * to call special forcewake code that doesn't touch runtime PM and
7776 * doesn't enable the forcewake delayed work.
7778 spin_lock_irq(&dev_priv
->uncore
.lock
);
7779 if (dev_priv
->uncore
.forcewake_count
++ == 0)
7780 dev_priv
->uncore
.funcs
.force_wake_get(dev_priv
, FORCEWAKE_ALL
);
7781 spin_unlock_irq(&dev_priv
->uncore
.lock
);
7783 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
7784 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
7785 I915_WRITE(LCPLL_CTL
, val
);
7786 POSTING_READ(LCPLL_CTL
);
7789 val
= hsw_read_dcomp(dev_priv
);
7790 val
|= D_COMP_COMP_FORCE
;
7791 val
&= ~D_COMP_COMP_DISABLE
;
7792 hsw_write_dcomp(dev_priv
, val
);
7794 val
= I915_READ(LCPLL_CTL
);
7795 val
&= ~LCPLL_PLL_DISABLE
;
7796 I915_WRITE(LCPLL_CTL
, val
);
7798 if (wait_for(I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
, 5))
7799 DRM_ERROR("LCPLL not locked yet\n");
7801 if (val
& LCPLL_CD_SOURCE_FCLK
) {
7802 val
= I915_READ(LCPLL_CTL
);
7803 val
&= ~LCPLL_CD_SOURCE_FCLK
;
7804 I915_WRITE(LCPLL_CTL
, val
);
7806 if (wait_for_atomic_us((I915_READ(LCPLL_CTL
) &
7807 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
7808 DRM_ERROR("Switching back to LCPLL failed\n");
7811 /* See the big comment above. */
7812 spin_lock_irq(&dev_priv
->uncore
.lock
);
7813 if (--dev_priv
->uncore
.forcewake_count
== 0)
7814 dev_priv
->uncore
.funcs
.force_wake_put(dev_priv
, FORCEWAKE_ALL
);
7815 spin_unlock_irq(&dev_priv
->uncore
.lock
);
7819 * Package states C8 and deeper are really deep PC states that can only be
7820 * reached when all the devices on the system allow it, so even if the graphics
7821 * device allows PC8+, it doesn't mean the system will actually get to these
7822 * states. Our driver only allows PC8+ when going into runtime PM.
7824 * The requirements for PC8+ are that all the outputs are disabled, the power
7825 * well is disabled and most interrupts are disabled, and these are also
7826 * requirements for runtime PM. When these conditions are met, we manually do
7827 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
7828 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
7831 * When we really reach PC8 or deeper states (not just when we allow it) we lose
7832 * the state of some registers, so when we come back from PC8+ we need to
7833 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
7834 * need to take care of the registers kept by RC6. Notice that this happens even
7835 * if we don't put the device in PCI D3 state (which is what currently happens
7836 * because of the runtime PM support).
7838 * For more, read "Display Sequences for Package C8" on the hardware
7841 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
7843 struct drm_device
*dev
= dev_priv
->dev
;
7846 DRM_DEBUG_KMS("Enabling package C8+\n");
7848 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
7849 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
7850 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
7851 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
7854 lpt_disable_clkout_dp(dev
);
7855 hsw_disable_lcpll(dev_priv
, true, true);
7858 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
7860 struct drm_device
*dev
= dev_priv
->dev
;
7863 DRM_DEBUG_KMS("Disabling package C8+\n");
7865 hsw_restore_lcpll(dev_priv
);
7866 lpt_init_pch_refclk(dev
);
7868 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
7869 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
7870 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
7871 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
7874 intel_prepare_ddi(dev
);
7877 static void snb_modeset_global_resources(struct drm_device
*dev
)
7879 modeset_update_crtc_power_domains(dev
);
7882 static void haswell_modeset_global_resources(struct drm_device
*dev
)
7884 modeset_update_crtc_power_domains(dev
);
7887 static int haswell_crtc_mode_set(struct intel_crtc
*crtc
,
7889 struct drm_framebuffer
*fb
)
7891 if (!intel_ddi_pll_select(crtc
))
7894 crtc
->lowfreq_avail
= false;
7899 static void haswell_get_ddi_pll(struct drm_i915_private
*dev_priv
,
7901 struct intel_crtc_config
*pipe_config
)
7903 pipe_config
->ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
7905 switch (pipe_config
->ddi_pll_sel
) {
7906 case PORT_CLK_SEL_WRPLL1
:
7907 pipe_config
->shared_dpll
= DPLL_ID_WRPLL1
;
7909 case PORT_CLK_SEL_WRPLL2
:
7910 pipe_config
->shared_dpll
= DPLL_ID_WRPLL2
;
7915 static void haswell_get_ddi_port_state(struct intel_crtc
*crtc
,
7916 struct intel_crtc_config
*pipe_config
)
7918 struct drm_device
*dev
= crtc
->base
.dev
;
7919 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7920 struct intel_shared_dpll
*pll
;
7924 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
7926 port
= (tmp
& TRANS_DDI_PORT_MASK
) >> TRANS_DDI_PORT_SHIFT
;
7928 haswell_get_ddi_pll(dev_priv
, port
, pipe_config
);
7930 if (pipe_config
->shared_dpll
>= 0) {
7931 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
7933 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
7934 &pipe_config
->dpll_hw_state
));
7938 * Haswell has only FDI/PCH transcoder A. It is which is connected to
7939 * DDI E. So just check whether this pipe is wired to DDI E and whether
7940 * the PCH transcoder is on.
7942 if (INTEL_INFO(dev
)->gen
< 9 &&
7943 (port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
7944 pipe_config
->has_pch_encoder
= true;
7946 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
7947 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
7948 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
7950 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
7954 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
7955 struct intel_crtc_config
*pipe_config
)
7957 struct drm_device
*dev
= crtc
->base
.dev
;
7958 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7959 enum intel_display_power_domain pfit_domain
;
7962 if (!intel_display_power_is_enabled(dev_priv
,
7963 POWER_DOMAIN_PIPE(crtc
->pipe
)))
7966 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7967 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
7969 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
7970 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
7971 enum pipe trans_edp_pipe
;
7972 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
7974 WARN(1, "unknown pipe linked to edp transcoder\n");
7975 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
7976 case TRANS_DDI_EDP_INPUT_A_ON
:
7977 trans_edp_pipe
= PIPE_A
;
7979 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
7980 trans_edp_pipe
= PIPE_B
;
7982 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
7983 trans_edp_pipe
= PIPE_C
;
7987 if (trans_edp_pipe
== crtc
->pipe
)
7988 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
7991 if (!intel_display_power_is_enabled(dev_priv
,
7992 POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
)))
7995 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
7996 if (!(tmp
& PIPECONF_ENABLE
))
7999 haswell_get_ddi_port_state(crtc
, pipe_config
);
8001 intel_get_pipe_timings(crtc
, pipe_config
);
8003 pfit_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
8004 if (intel_display_power_is_enabled(dev_priv
, pfit_domain
))
8005 ironlake_get_pfit_config(crtc
, pipe_config
);
8007 if (IS_HASWELL(dev
))
8008 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
8009 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
8011 if (pipe_config
->cpu_transcoder
!= TRANSCODER_EDP
) {
8012 pipe_config
->pixel_multiplier
=
8013 I915_READ(PIPE_MULT(pipe_config
->cpu_transcoder
)) + 1;
8015 pipe_config
->pixel_multiplier
= 1;
8021 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
)
8023 struct drm_device
*dev
= crtc
->dev
;
8024 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8025 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8026 uint32_t cntl
= 0, size
= 0;
8029 unsigned int width
= intel_crtc
->cursor_width
;
8030 unsigned int height
= intel_crtc
->cursor_height
;
8031 unsigned int stride
= roundup_pow_of_two(width
) * 4;
8035 WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
8046 cntl
|= CURSOR_ENABLE
|
8047 CURSOR_GAMMA_ENABLE
|
8048 CURSOR_FORMAT_ARGB
|
8049 CURSOR_STRIDE(stride
);
8051 size
= (height
<< 12) | width
;
8054 if (intel_crtc
->cursor_cntl
!= 0 &&
8055 (intel_crtc
->cursor_base
!= base
||
8056 intel_crtc
->cursor_size
!= size
||
8057 intel_crtc
->cursor_cntl
!= cntl
)) {
8058 /* On these chipsets we can only modify the base/size/stride
8059 * whilst the cursor is disabled.
8061 I915_WRITE(_CURACNTR
, 0);
8062 POSTING_READ(_CURACNTR
);
8063 intel_crtc
->cursor_cntl
= 0;
8066 if (intel_crtc
->cursor_base
!= base
) {
8067 I915_WRITE(_CURABASE
, base
);
8068 intel_crtc
->cursor_base
= base
;
8071 if (intel_crtc
->cursor_size
!= size
) {
8072 I915_WRITE(CURSIZE
, size
);
8073 intel_crtc
->cursor_size
= size
;
8076 if (intel_crtc
->cursor_cntl
!= cntl
) {
8077 I915_WRITE(_CURACNTR
, cntl
);
8078 POSTING_READ(_CURACNTR
);
8079 intel_crtc
->cursor_cntl
= cntl
;
8083 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
)
8085 struct drm_device
*dev
= crtc
->dev
;
8086 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8087 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8088 int pipe
= intel_crtc
->pipe
;
8093 cntl
= MCURSOR_GAMMA_ENABLE
;
8094 switch (intel_crtc
->cursor_width
) {
8096 cntl
|= CURSOR_MODE_64_ARGB_AX
;
8099 cntl
|= CURSOR_MODE_128_ARGB_AX
;
8102 cntl
|= CURSOR_MODE_256_ARGB_AX
;
8108 cntl
|= pipe
<< 28; /* Connect to correct pipe */
8110 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
8111 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
8114 if (to_intel_plane(crtc
->cursor
)->rotation
== BIT(DRM_ROTATE_180
))
8115 cntl
|= CURSOR_ROTATE_180
;
8117 if (intel_crtc
->cursor_cntl
!= cntl
) {
8118 I915_WRITE(CURCNTR(pipe
), cntl
);
8119 POSTING_READ(CURCNTR(pipe
));
8120 intel_crtc
->cursor_cntl
= cntl
;
8123 /* and commit changes on next vblank */
8124 I915_WRITE(CURBASE(pipe
), base
);
8125 POSTING_READ(CURBASE(pipe
));
8127 intel_crtc
->cursor_base
= base
;
8130 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
8131 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
8134 struct drm_device
*dev
= crtc
->dev
;
8135 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8136 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8137 int pipe
= intel_crtc
->pipe
;
8138 int x
= crtc
->cursor_x
;
8139 int y
= crtc
->cursor_y
;
8140 u32 base
= 0, pos
= 0;
8143 base
= intel_crtc
->cursor_addr
;
8145 if (x
>= intel_crtc
->config
.pipe_src_w
)
8148 if (y
>= intel_crtc
->config
.pipe_src_h
)
8152 if (x
+ intel_crtc
->cursor_width
<= 0)
8155 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
8158 pos
|= x
<< CURSOR_X_SHIFT
;
8161 if (y
+ intel_crtc
->cursor_height
<= 0)
8164 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
8167 pos
|= y
<< CURSOR_Y_SHIFT
;
8169 if (base
== 0 && intel_crtc
->cursor_base
== 0)
8172 I915_WRITE(CURPOS(pipe
), pos
);
8174 /* ILK+ do this automagically */
8175 if (HAS_GMCH_DISPLAY(dev
) &&
8176 to_intel_plane(crtc
->cursor
)->rotation
== BIT(DRM_ROTATE_180
)) {
8177 base
+= (intel_crtc
->cursor_height
*
8178 intel_crtc
->cursor_width
- 1) * 4;
8181 if (IS_845G(dev
) || IS_I865G(dev
))
8182 i845_update_cursor(crtc
, base
);
8184 i9xx_update_cursor(crtc
, base
);
8187 static bool cursor_size_ok(struct drm_device
*dev
,
8188 uint32_t width
, uint32_t height
)
8190 if (width
== 0 || height
== 0)
8194 * 845g/865g are special in that they are only limited by
8195 * the width of their cursors, the height is arbitrary up to
8196 * the precision of the register. Everything else requires
8197 * square cursors, limited to a few power-of-two sizes.
8199 if (IS_845G(dev
) || IS_I865G(dev
)) {
8200 if ((width
& 63) != 0)
8203 if (width
> (IS_845G(dev
) ? 64 : 512))
8209 switch (width
| height
) {
8224 static int intel_crtc_cursor_set_obj(struct drm_crtc
*crtc
,
8225 struct drm_i915_gem_object
*obj
,
8226 uint32_t width
, uint32_t height
)
8228 struct drm_device
*dev
= crtc
->dev
;
8229 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8230 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8231 enum pipe pipe
= intel_crtc
->pipe
;
8236 /* if we want to turn off the cursor ignore width and height */
8238 DRM_DEBUG_KMS("cursor off\n");
8240 mutex_lock(&dev
->struct_mutex
);
8244 /* we only need to pin inside GTT if cursor is non-phy */
8245 mutex_lock(&dev
->struct_mutex
);
8246 if (!INTEL_INFO(dev
)->cursor_needs_physical
) {
8250 * Global gtt pte registers are special registers which actually
8251 * forward writes to a chunk of system memory. Which means that
8252 * there is no risk that the register values disappear as soon
8253 * as we call intel_runtime_pm_put(), so it is correct to wrap
8254 * only the pin/unpin/fence and not more.
8256 intel_runtime_pm_get(dev_priv
);
8258 /* Note that the w/a also requires 2 PTE of padding following
8259 * the bo. We currently fill all unused PTE with the shadow
8260 * page and so we should always have valid PTE following the
8261 * cursor preventing the VT-d warning.
8264 if (need_vtd_wa(dev
))
8265 alignment
= 64*1024;
8267 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, NULL
);
8269 DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n");
8270 intel_runtime_pm_put(dev_priv
);
8274 ret
= i915_gem_object_put_fence(obj
);
8276 DRM_DEBUG_KMS("failed to release fence for cursor");
8277 intel_runtime_pm_put(dev_priv
);
8281 addr
= i915_gem_obj_ggtt_offset(obj
);
8283 intel_runtime_pm_put(dev_priv
);
8285 int align
= IS_I830(dev
) ? 16 * 1024 : 256;
8286 ret
= i915_gem_object_attach_phys(obj
, align
);
8288 DRM_DEBUG_KMS("failed to attach phys object\n");
8291 addr
= obj
->phys_handle
->busaddr
;
8295 if (intel_crtc
->cursor_bo
) {
8296 if (!INTEL_INFO(dev
)->cursor_needs_physical
)
8297 i915_gem_object_unpin_from_display_plane(intel_crtc
->cursor_bo
);
8300 i915_gem_track_fb(intel_crtc
->cursor_bo
, obj
,
8301 INTEL_FRONTBUFFER_CURSOR(pipe
));
8302 mutex_unlock(&dev
->struct_mutex
);
8304 old_width
= intel_crtc
->cursor_width
;
8306 intel_crtc
->cursor_addr
= addr
;
8307 intel_crtc
->cursor_bo
= obj
;
8308 intel_crtc
->cursor_width
= width
;
8309 intel_crtc
->cursor_height
= height
;
8311 if (intel_crtc
->active
) {
8312 if (old_width
!= width
)
8313 intel_update_watermarks(crtc
);
8314 intel_crtc_update_cursor(crtc
, intel_crtc
->cursor_bo
!= NULL
);
8316 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_CURSOR(pipe
));
8321 i915_gem_object_unpin_from_display_plane(obj
);
8323 mutex_unlock(&dev
->struct_mutex
);
8327 static void intel_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
8328 u16
*blue
, uint32_t start
, uint32_t size
)
8330 int end
= (start
+ size
> 256) ? 256 : start
+ size
, i
;
8331 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8333 for (i
= start
; i
< end
; i
++) {
8334 intel_crtc
->lut_r
[i
] = red
[i
] >> 8;
8335 intel_crtc
->lut_g
[i
] = green
[i
] >> 8;
8336 intel_crtc
->lut_b
[i
] = blue
[i
] >> 8;
8339 intel_crtc_load_lut(crtc
);
8342 /* VESA 640x480x72Hz mode to set on the pipe */
8343 static struct drm_display_mode load_detect_mode
= {
8344 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
8345 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
8348 struct drm_framebuffer
*
8349 __intel_framebuffer_create(struct drm_device
*dev
,
8350 struct drm_mode_fb_cmd2
*mode_cmd
,
8351 struct drm_i915_gem_object
*obj
)
8353 struct intel_framebuffer
*intel_fb
;
8356 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8358 drm_gem_object_unreference_unlocked(&obj
->base
);
8359 return ERR_PTR(-ENOMEM
);
8362 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
8366 return &intel_fb
->base
;
8368 drm_gem_object_unreference_unlocked(&obj
->base
);
8371 return ERR_PTR(ret
);
8374 static struct drm_framebuffer
*
8375 intel_framebuffer_create(struct drm_device
*dev
,
8376 struct drm_mode_fb_cmd2
*mode_cmd
,
8377 struct drm_i915_gem_object
*obj
)
8379 struct drm_framebuffer
*fb
;
8382 ret
= i915_mutex_lock_interruptible(dev
);
8384 return ERR_PTR(ret
);
8385 fb
= __intel_framebuffer_create(dev
, mode_cmd
, obj
);
8386 mutex_unlock(&dev
->struct_mutex
);
8392 intel_framebuffer_pitch_for_width(int width
, int bpp
)
8394 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
8395 return ALIGN(pitch
, 64);
8399 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
8401 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
8402 return PAGE_ALIGN(pitch
* mode
->vdisplay
);
8405 static struct drm_framebuffer
*
8406 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
8407 struct drm_display_mode
*mode
,
8410 struct drm_i915_gem_object
*obj
;
8411 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
8413 obj
= i915_gem_alloc_object(dev
,
8414 intel_framebuffer_size_for_mode(mode
, bpp
));
8416 return ERR_PTR(-ENOMEM
);
8418 mode_cmd
.width
= mode
->hdisplay
;
8419 mode_cmd
.height
= mode
->vdisplay
;
8420 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
8422 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
8424 return intel_framebuffer_create(dev
, &mode_cmd
, obj
);
8427 static struct drm_framebuffer
*
8428 mode_fits_in_fbdev(struct drm_device
*dev
,
8429 struct drm_display_mode
*mode
)
8431 #ifdef CONFIG_DRM_I915_FBDEV
8432 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8433 struct drm_i915_gem_object
*obj
;
8434 struct drm_framebuffer
*fb
;
8436 if (!dev_priv
->fbdev
)
8439 if (!dev_priv
->fbdev
->fb
)
8442 obj
= dev_priv
->fbdev
->fb
->obj
;
8445 fb
= &dev_priv
->fbdev
->fb
->base
;
8446 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
8447 fb
->bits_per_pixel
))
8450 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
8459 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
8460 struct drm_display_mode
*mode
,
8461 struct intel_load_detect_pipe
*old
,
8462 struct drm_modeset_acquire_ctx
*ctx
)
8464 struct intel_crtc
*intel_crtc
;
8465 struct intel_encoder
*intel_encoder
=
8466 intel_attached_encoder(connector
);
8467 struct drm_crtc
*possible_crtc
;
8468 struct drm_encoder
*encoder
= &intel_encoder
->base
;
8469 struct drm_crtc
*crtc
= NULL
;
8470 struct drm_device
*dev
= encoder
->dev
;
8471 struct drm_framebuffer
*fb
;
8472 struct drm_mode_config
*config
= &dev
->mode_config
;
8475 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
8476 connector
->base
.id
, connector
->name
,
8477 encoder
->base
.id
, encoder
->name
);
8480 ret
= drm_modeset_lock(&config
->connection_mutex
, ctx
);
8485 * Algorithm gets a little messy:
8487 * - if the connector already has an assigned crtc, use it (but make
8488 * sure it's on first)
8490 * - try to find the first unused crtc that can drive this connector,
8491 * and use that if we find one
8494 /* See if we already have a CRTC for this connector */
8495 if (encoder
->crtc
) {
8496 crtc
= encoder
->crtc
;
8498 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
8502 old
->dpms_mode
= connector
->dpms
;
8503 old
->load_detect_temp
= false;
8505 /* Make sure the crtc and connector are running */
8506 if (connector
->dpms
!= DRM_MODE_DPMS_ON
)
8507 connector
->funcs
->dpms(connector
, DRM_MODE_DPMS_ON
);
8512 /* Find an unused one (if possible) */
8513 for_each_crtc(dev
, possible_crtc
) {
8515 if (!(encoder
->possible_crtcs
& (1 << i
)))
8517 if (possible_crtc
->enabled
)
8519 /* This can occur when applying the pipe A quirk on resume. */
8520 if (to_intel_crtc(possible_crtc
)->new_enabled
)
8523 crtc
= possible_crtc
;
8528 * If we didn't find an unused CRTC, don't use any.
8531 DRM_DEBUG_KMS("no pipe available for load-detect\n");
8535 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
8538 intel_encoder
->new_crtc
= to_intel_crtc(crtc
);
8539 to_intel_connector(connector
)->new_encoder
= intel_encoder
;
8541 intel_crtc
= to_intel_crtc(crtc
);
8542 intel_crtc
->new_enabled
= true;
8543 intel_crtc
->new_config
= &intel_crtc
->config
;
8544 old
->dpms_mode
= connector
->dpms
;
8545 old
->load_detect_temp
= true;
8546 old
->release_fb
= NULL
;
8549 mode
= &load_detect_mode
;
8551 /* We need a framebuffer large enough to accommodate all accesses
8552 * that the plane may generate whilst we perform load detection.
8553 * We can not rely on the fbcon either being present (we get called
8554 * during its initialisation to detect all boot displays, or it may
8555 * not even exist) or that it is large enough to satisfy the
8558 fb
= mode_fits_in_fbdev(dev
, mode
);
8560 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
8561 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
8562 old
->release_fb
= fb
;
8564 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
8566 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
8570 if (intel_set_mode(crtc
, mode
, 0, 0, fb
)) {
8571 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
8572 if (old
->release_fb
)
8573 old
->release_fb
->funcs
->destroy(old
->release_fb
);
8577 /* let the connector get through one full cycle before testing */
8578 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
8582 intel_crtc
->new_enabled
= crtc
->enabled
;
8583 if (intel_crtc
->new_enabled
)
8584 intel_crtc
->new_config
= &intel_crtc
->config
;
8586 intel_crtc
->new_config
= NULL
;
8588 if (ret
== -EDEADLK
) {
8589 drm_modeset_backoff(ctx
);
8596 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
8597 struct intel_load_detect_pipe
*old
)
8599 struct intel_encoder
*intel_encoder
=
8600 intel_attached_encoder(connector
);
8601 struct drm_encoder
*encoder
= &intel_encoder
->base
;
8602 struct drm_crtc
*crtc
= encoder
->crtc
;
8603 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8605 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
8606 connector
->base
.id
, connector
->name
,
8607 encoder
->base
.id
, encoder
->name
);
8609 if (old
->load_detect_temp
) {
8610 to_intel_connector(connector
)->new_encoder
= NULL
;
8611 intel_encoder
->new_crtc
= NULL
;
8612 intel_crtc
->new_enabled
= false;
8613 intel_crtc
->new_config
= NULL
;
8614 intel_set_mode(crtc
, NULL
, 0, 0, NULL
);
8616 if (old
->release_fb
) {
8617 drm_framebuffer_unregister_private(old
->release_fb
);
8618 drm_framebuffer_unreference(old
->release_fb
);
8624 /* Switch crtc and encoder back off if necessary */
8625 if (old
->dpms_mode
!= DRM_MODE_DPMS_ON
)
8626 connector
->funcs
->dpms(connector
, old
->dpms_mode
);
8629 static int i9xx_pll_refclk(struct drm_device
*dev
,
8630 const struct intel_crtc_config
*pipe_config
)
8632 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8633 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
8635 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
8636 return dev_priv
->vbt
.lvds_ssc_freq
;
8637 else if (HAS_PCH_SPLIT(dev
))
8639 else if (!IS_GEN2(dev
))
8645 /* Returns the clock of the currently programmed mode of the given pipe. */
8646 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
8647 struct intel_crtc_config
*pipe_config
)
8649 struct drm_device
*dev
= crtc
->base
.dev
;
8650 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8651 int pipe
= pipe_config
->cpu_transcoder
;
8652 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
8654 intel_clock_t clock
;
8655 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
8657 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
8658 fp
= pipe_config
->dpll_hw_state
.fp0
;
8660 fp
= pipe_config
->dpll_hw_state
.fp1
;
8662 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
8663 if (IS_PINEVIEW(dev
)) {
8664 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
8665 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
8667 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
8668 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
8671 if (!IS_GEN2(dev
)) {
8672 if (IS_PINEVIEW(dev
))
8673 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
8674 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
8676 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
8677 DPLL_FPA01_P1_POST_DIV_SHIFT
);
8679 switch (dpll
& DPLL_MODE_MASK
) {
8680 case DPLLB_MODE_DAC_SERIAL
:
8681 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
8684 case DPLLB_MODE_LVDS
:
8685 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
8689 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
8690 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
8694 if (IS_PINEVIEW(dev
))
8695 pineview_clock(refclk
, &clock
);
8697 i9xx_clock(refclk
, &clock
);
8699 u32 lvds
= IS_I830(dev
) ? 0 : I915_READ(LVDS
);
8700 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
8703 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
8704 DPLL_FPA01_P1_POST_DIV_SHIFT
);
8706 if (lvds
& LVDS_CLKB_POWER_UP
)
8711 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
8714 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
8715 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
8717 if (dpll
& PLL_P2_DIVIDE_BY_4
)
8723 i9xx_clock(refclk
, &clock
);
8727 * This value includes pixel_multiplier. We will use
8728 * port_clock to compute adjusted_mode.crtc_clock in the
8729 * encoder's get_config() function.
8731 pipe_config
->port_clock
= clock
.dot
;
8734 int intel_dotclock_calculate(int link_freq
,
8735 const struct intel_link_m_n
*m_n
)
8738 * The calculation for the data clock is:
8739 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
8740 * But we want to avoid losing precison if possible, so:
8741 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
8743 * and the link clock is simpler:
8744 * link_clock = (m * link_clock) / n
8750 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
8753 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
8754 struct intel_crtc_config
*pipe_config
)
8756 struct drm_device
*dev
= crtc
->base
.dev
;
8758 /* read out port_clock from the DPLL */
8759 i9xx_crtc_clock_get(crtc
, pipe_config
);
8762 * This value does not include pixel_multiplier.
8763 * We will check that port_clock and adjusted_mode.crtc_clock
8764 * agree once we know their relationship in the encoder's
8765 * get_config() function.
8767 pipe_config
->adjusted_mode
.crtc_clock
=
8768 intel_dotclock_calculate(intel_fdi_link_freq(dev
) * 10000,
8769 &pipe_config
->fdi_m_n
);
8772 /** Returns the currently programmed mode of the given pipe. */
8773 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
8774 struct drm_crtc
*crtc
)
8776 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8777 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8778 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
8779 struct drm_display_mode
*mode
;
8780 struct intel_crtc_config pipe_config
;
8781 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
8782 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
8783 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
8784 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
8785 enum pipe pipe
= intel_crtc
->pipe
;
8787 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
8792 * Construct a pipe_config sufficient for getting the clock info
8793 * back out of crtc_clock_get.
8795 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
8796 * to use a real value here instead.
8798 pipe_config
.cpu_transcoder
= (enum transcoder
) pipe
;
8799 pipe_config
.pixel_multiplier
= 1;
8800 pipe_config
.dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
8801 pipe_config
.dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
8802 pipe_config
.dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
8803 i9xx_crtc_clock_get(intel_crtc
, &pipe_config
);
8805 mode
->clock
= pipe_config
.port_clock
/ pipe_config
.pixel_multiplier
;
8806 mode
->hdisplay
= (htot
& 0xffff) + 1;
8807 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
8808 mode
->hsync_start
= (hsync
& 0xffff) + 1;
8809 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
8810 mode
->vdisplay
= (vtot
& 0xffff) + 1;
8811 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
8812 mode
->vsync_start
= (vsync
& 0xffff) + 1;
8813 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
8815 drm_mode_set_name(mode
);
8820 static void intel_decrease_pllclock(struct drm_crtc
*crtc
)
8822 struct drm_device
*dev
= crtc
->dev
;
8823 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8824 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8826 if (!HAS_GMCH_DISPLAY(dev
))
8829 if (!dev_priv
->lvds_downclock_avail
)
8833 * Since this is called by a timer, we should never get here in
8836 if (!HAS_PIPE_CXSR(dev
) && intel_crtc
->lowfreq_avail
) {
8837 int pipe
= intel_crtc
->pipe
;
8838 int dpll_reg
= DPLL(pipe
);
8841 DRM_DEBUG_DRIVER("downclocking LVDS\n");
8843 assert_panel_unlocked(dev_priv
, pipe
);
8845 dpll
= I915_READ(dpll_reg
);
8846 dpll
|= DISPLAY_RATE_SELECT_FPA1
;
8847 I915_WRITE(dpll_reg
, dpll
);
8848 intel_wait_for_vblank(dev
, pipe
);
8849 dpll
= I915_READ(dpll_reg
);
8850 if (!(dpll
& DISPLAY_RATE_SELECT_FPA1
))
8851 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
8856 void intel_mark_busy(struct drm_device
*dev
)
8858 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8860 if (dev_priv
->mm
.busy
)
8863 intel_runtime_pm_get(dev_priv
);
8864 i915_update_gfx_val(dev_priv
);
8865 dev_priv
->mm
.busy
= true;
8868 void intel_mark_idle(struct drm_device
*dev
)
8870 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8871 struct drm_crtc
*crtc
;
8873 if (!dev_priv
->mm
.busy
)
8876 dev_priv
->mm
.busy
= false;
8878 if (!i915
.powersave
)
8881 for_each_crtc(dev
, crtc
) {
8882 if (!crtc
->primary
->fb
)
8885 intel_decrease_pllclock(crtc
);
8888 if (INTEL_INFO(dev
)->gen
>= 6)
8889 gen6_rps_idle(dev
->dev_private
);
8892 intel_runtime_pm_put(dev_priv
);
8895 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
8897 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8898 struct drm_device
*dev
= crtc
->dev
;
8899 struct intel_unpin_work
*work
;
8901 spin_lock_irq(&dev
->event_lock
);
8902 work
= intel_crtc
->unpin_work
;
8903 intel_crtc
->unpin_work
= NULL
;
8904 spin_unlock_irq(&dev
->event_lock
);
8907 cancel_work_sync(&work
->work
);
8911 drm_crtc_cleanup(crtc
);
8916 static void intel_unpin_work_fn(struct work_struct
*__work
)
8918 struct intel_unpin_work
*work
=
8919 container_of(__work
, struct intel_unpin_work
, work
);
8920 struct drm_device
*dev
= work
->crtc
->dev
;
8921 enum pipe pipe
= to_intel_crtc(work
->crtc
)->pipe
;
8923 mutex_lock(&dev
->struct_mutex
);
8924 intel_unpin_fb_obj(work
->old_fb_obj
);
8925 drm_gem_object_unreference(&work
->pending_flip_obj
->base
);
8926 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
8928 intel_update_fbc(dev
);
8929 mutex_unlock(&dev
->struct_mutex
);
8931 intel_frontbuffer_flip_complete(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
8933 BUG_ON(atomic_read(&to_intel_crtc(work
->crtc
)->unpin_work_count
) == 0);
8934 atomic_dec(&to_intel_crtc(work
->crtc
)->unpin_work_count
);
8939 static void do_intel_finish_page_flip(struct drm_device
*dev
,
8940 struct drm_crtc
*crtc
)
8942 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8943 struct intel_unpin_work
*work
;
8944 unsigned long flags
;
8946 /* Ignore early vblank irqs */
8947 if (intel_crtc
== NULL
)
8951 * This is called both by irq handlers and the reset code (to complete
8952 * lost pageflips) so needs the full irqsave spinlocks.
8954 spin_lock_irqsave(&dev
->event_lock
, flags
);
8955 work
= intel_crtc
->unpin_work
;
8957 /* Ensure we don't miss a work->pending update ... */
8960 if (work
== NULL
|| atomic_read(&work
->pending
) < INTEL_FLIP_COMPLETE
) {
8961 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
8965 page_flip_completed(intel_crtc
);
8967 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
8970 void intel_finish_page_flip(struct drm_device
*dev
, int pipe
)
8972 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8973 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
8975 do_intel_finish_page_flip(dev
, crtc
);
8978 void intel_finish_page_flip_plane(struct drm_device
*dev
, int plane
)
8980 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8981 struct drm_crtc
*crtc
= dev_priv
->plane_to_crtc_mapping
[plane
];
8983 do_intel_finish_page_flip(dev
, crtc
);
8986 /* Is 'a' after or equal to 'b'? */
8987 static bool g4x_flip_count_after_eq(u32 a
, u32 b
)
8989 return !((a
- b
) & 0x80000000);
8992 static bool page_flip_finished(struct intel_crtc
*crtc
)
8994 struct drm_device
*dev
= crtc
->base
.dev
;
8995 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8998 * The relevant registers doen't exist on pre-ctg.
8999 * As the flip done interrupt doesn't trigger for mmio
9000 * flips on gmch platforms, a flip count check isn't
9001 * really needed there. But since ctg has the registers,
9002 * include it in the check anyway.
9004 if (INTEL_INFO(dev
)->gen
< 5 && !IS_G4X(dev
))
9008 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
9009 * used the same base address. In that case the mmio flip might
9010 * have completed, but the CS hasn't even executed the flip yet.
9012 * A flip count check isn't enough as the CS might have updated
9013 * the base address just after start of vblank, but before we
9014 * managed to process the interrupt. This means we'd complete the
9017 * Combining both checks should get us a good enough result. It may
9018 * still happen that the CS flip has been executed, but has not
9019 * yet actually completed. But in case the base address is the same
9020 * anyway, we don't really care.
9022 return (I915_READ(DSPSURFLIVE(crtc
->plane
)) & ~0xfff) ==
9023 crtc
->unpin_work
->gtt_offset
&&
9024 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc
->pipe
)),
9025 crtc
->unpin_work
->flip_count
);
9028 void intel_prepare_page_flip(struct drm_device
*dev
, int plane
)
9030 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9031 struct intel_crtc
*intel_crtc
=
9032 to_intel_crtc(dev_priv
->plane_to_crtc_mapping
[plane
]);
9033 unsigned long flags
;
9037 * This is called both by irq handlers and the reset code (to complete
9038 * lost pageflips) so needs the full irqsave spinlocks.
9040 * NB: An MMIO update of the plane base pointer will also
9041 * generate a page-flip completion irq, i.e. every modeset
9042 * is also accompanied by a spurious intel_prepare_page_flip().
9044 spin_lock_irqsave(&dev
->event_lock
, flags
);
9045 if (intel_crtc
->unpin_work
&& page_flip_finished(intel_crtc
))
9046 atomic_inc_not_zero(&intel_crtc
->unpin_work
->pending
);
9047 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9050 static inline void intel_mark_page_flip_active(struct intel_crtc
*intel_crtc
)
9052 /* Ensure that the work item is consistent when activating it ... */
9054 atomic_set(&intel_crtc
->unpin_work
->pending
, INTEL_FLIP_PENDING
);
9055 /* and that it is marked active as soon as the irq could fire. */
9059 static int intel_gen2_queue_flip(struct drm_device
*dev
,
9060 struct drm_crtc
*crtc
,
9061 struct drm_framebuffer
*fb
,
9062 struct drm_i915_gem_object
*obj
,
9063 struct intel_engine_cs
*ring
,
9066 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9070 ret
= intel_ring_begin(ring
, 6);
9074 /* Can't queue multiple flips, so wait for the previous
9075 * one to finish before executing the next.
9077 if (intel_crtc
->plane
)
9078 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
9080 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
9081 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
9082 intel_ring_emit(ring
, MI_NOOP
);
9083 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9084 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9085 intel_ring_emit(ring
, fb
->pitches
[0]);
9086 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9087 intel_ring_emit(ring
, 0); /* aux display base address, unused */
9089 intel_mark_page_flip_active(intel_crtc
);
9090 __intel_ring_advance(ring
);
9094 static int intel_gen3_queue_flip(struct drm_device
*dev
,
9095 struct drm_crtc
*crtc
,
9096 struct drm_framebuffer
*fb
,
9097 struct drm_i915_gem_object
*obj
,
9098 struct intel_engine_cs
*ring
,
9101 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9105 ret
= intel_ring_begin(ring
, 6);
9109 if (intel_crtc
->plane
)
9110 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
9112 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
9113 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
9114 intel_ring_emit(ring
, MI_NOOP
);
9115 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
|
9116 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9117 intel_ring_emit(ring
, fb
->pitches
[0]);
9118 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9119 intel_ring_emit(ring
, MI_NOOP
);
9121 intel_mark_page_flip_active(intel_crtc
);
9122 __intel_ring_advance(ring
);
9126 static int intel_gen4_queue_flip(struct drm_device
*dev
,
9127 struct drm_crtc
*crtc
,
9128 struct drm_framebuffer
*fb
,
9129 struct drm_i915_gem_object
*obj
,
9130 struct intel_engine_cs
*ring
,
9133 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9134 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9135 uint32_t pf
, pipesrc
;
9138 ret
= intel_ring_begin(ring
, 4);
9142 /* i965+ uses the linear or tiled offsets from the
9143 * Display Registers (which do not change across a page-flip)
9144 * so we need only reprogram the base address.
9146 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9147 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9148 intel_ring_emit(ring
, fb
->pitches
[0]);
9149 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
|
9152 /* XXX Enabling the panel-fitter across page-flip is so far
9153 * untested on non-native modes, so ignore it for now.
9154 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
9157 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
9158 intel_ring_emit(ring
, pf
| pipesrc
);
9160 intel_mark_page_flip_active(intel_crtc
);
9161 __intel_ring_advance(ring
);
9165 static int intel_gen6_queue_flip(struct drm_device
*dev
,
9166 struct drm_crtc
*crtc
,
9167 struct drm_framebuffer
*fb
,
9168 struct drm_i915_gem_object
*obj
,
9169 struct intel_engine_cs
*ring
,
9172 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9173 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9174 uint32_t pf
, pipesrc
;
9177 ret
= intel_ring_begin(ring
, 4);
9181 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9182 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9183 intel_ring_emit(ring
, fb
->pitches
[0] | obj
->tiling_mode
);
9184 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9186 /* Contrary to the suggestions in the documentation,
9187 * "Enable Panel Fitter" does not seem to be required when page
9188 * flipping with a non-native mode, and worse causes a normal
9190 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
9193 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
9194 intel_ring_emit(ring
, pf
| pipesrc
);
9196 intel_mark_page_flip_active(intel_crtc
);
9197 __intel_ring_advance(ring
);
9201 static int intel_gen7_queue_flip(struct drm_device
*dev
,
9202 struct drm_crtc
*crtc
,
9203 struct drm_framebuffer
*fb
,
9204 struct drm_i915_gem_object
*obj
,
9205 struct intel_engine_cs
*ring
,
9208 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9209 uint32_t plane_bit
= 0;
9212 switch (intel_crtc
->plane
) {
9214 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
9217 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
9220 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
9223 WARN_ONCE(1, "unknown plane in flip command\n");
9228 if (ring
->id
== RCS
) {
9231 * On Gen 8, SRM is now taking an extra dword to accommodate
9232 * 48bits addresses, and we need a NOOP for the batch size to
9240 * BSpec MI_DISPLAY_FLIP for IVB:
9241 * "The full packet must be contained within the same cache line."
9243 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
9244 * cacheline, if we ever start emitting more commands before
9245 * the MI_DISPLAY_FLIP we may need to first emit everything else,
9246 * then do the cacheline alignment, and finally emit the
9249 ret
= intel_ring_cacheline_align(ring
);
9253 ret
= intel_ring_begin(ring
, len
);
9257 /* Unmask the flip-done completion message. Note that the bspec says that
9258 * we should do this for both the BCS and RCS, and that we must not unmask
9259 * more than one flip event at any time (or ensure that one flip message
9260 * can be sent by waiting for flip-done prior to queueing new flips).
9261 * Experimentation says that BCS works despite DERRMR masking all
9262 * flip-done completion events and that unmasking all planes at once
9263 * for the RCS also doesn't appear to drop events. Setting the DERRMR
9264 * to zero does lead to lockups within MI_DISPLAY_FLIP.
9266 if (ring
->id
== RCS
) {
9267 intel_ring_emit(ring
, MI_LOAD_REGISTER_IMM(1));
9268 intel_ring_emit(ring
, DERRMR
);
9269 intel_ring_emit(ring
, ~(DERRMR_PIPEA_PRI_FLIP_DONE
|
9270 DERRMR_PIPEB_PRI_FLIP_DONE
|
9271 DERRMR_PIPEC_PRI_FLIP_DONE
));
9273 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM_GEN8(1) |
9274 MI_SRM_LRM_GLOBAL_GTT
);
9276 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM(1) |
9277 MI_SRM_LRM_GLOBAL_GTT
);
9278 intel_ring_emit(ring
, DERRMR
);
9279 intel_ring_emit(ring
, ring
->scratch
.gtt_offset
+ 256);
9281 intel_ring_emit(ring
, 0);
9282 intel_ring_emit(ring
, MI_NOOP
);
9286 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
| plane_bit
);
9287 intel_ring_emit(ring
, (fb
->pitches
[0] | obj
->tiling_mode
));
9288 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9289 intel_ring_emit(ring
, (MI_NOOP
));
9291 intel_mark_page_flip_active(intel_crtc
);
9292 __intel_ring_advance(ring
);
9296 static bool use_mmio_flip(struct intel_engine_cs
*ring
,
9297 struct drm_i915_gem_object
*obj
)
9300 * This is not being used for older platforms, because
9301 * non-availability of flip done interrupt forces us to use
9302 * CS flips. Older platforms derive flip done using some clever
9303 * tricks involving the flip_pending status bits and vblank irqs.
9304 * So using MMIO flips there would disrupt this mechanism.
9310 if (INTEL_INFO(ring
->dev
)->gen
< 5)
9313 if (i915
.use_mmio_flip
< 0)
9315 else if (i915
.use_mmio_flip
> 0)
9317 else if (i915
.enable_execlists
)
9320 return ring
!= obj
->ring
;
9323 static void intel_do_mmio_flip(struct intel_crtc
*intel_crtc
)
9325 struct drm_device
*dev
= intel_crtc
->base
.dev
;
9326 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9327 struct intel_framebuffer
*intel_fb
=
9328 to_intel_framebuffer(intel_crtc
->base
.primary
->fb
);
9329 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
9333 intel_mark_page_flip_active(intel_crtc
);
9335 reg
= DSPCNTR(intel_crtc
->plane
);
9336 dspcntr
= I915_READ(reg
);
9338 if (obj
->tiling_mode
!= I915_TILING_NONE
)
9339 dspcntr
|= DISPPLANE_TILED
;
9341 dspcntr
&= ~DISPPLANE_TILED
;
9343 I915_WRITE(reg
, dspcntr
);
9345 I915_WRITE(DSPSURF(intel_crtc
->plane
),
9346 intel_crtc
->unpin_work
->gtt_offset
);
9347 POSTING_READ(DSPSURF(intel_crtc
->plane
));
9350 static int intel_postpone_flip(struct drm_i915_gem_object
*obj
)
9352 struct intel_engine_cs
*ring
;
9355 lockdep_assert_held(&obj
->base
.dev
->struct_mutex
);
9357 if (!obj
->last_write_seqno
)
9362 if (i915_seqno_passed(ring
->get_seqno(ring
, true),
9363 obj
->last_write_seqno
))
9366 ret
= i915_gem_check_olr(ring
, obj
->last_write_seqno
);
9370 if (WARN_ON(!ring
->irq_get(ring
)))
9376 void intel_notify_mmio_flip(struct intel_engine_cs
*ring
)
9378 struct drm_i915_private
*dev_priv
= to_i915(ring
->dev
);
9379 struct intel_crtc
*intel_crtc
;
9380 unsigned long irq_flags
;
9383 seqno
= ring
->get_seqno(ring
, false);
9385 spin_lock_irqsave(&dev_priv
->mmio_flip_lock
, irq_flags
);
9386 for_each_intel_crtc(ring
->dev
, intel_crtc
) {
9387 struct intel_mmio_flip
*mmio_flip
;
9389 mmio_flip
= &intel_crtc
->mmio_flip
;
9390 if (mmio_flip
->seqno
== 0)
9393 if (ring
->id
!= mmio_flip
->ring_id
)
9396 if (i915_seqno_passed(seqno
, mmio_flip
->seqno
)) {
9397 intel_do_mmio_flip(intel_crtc
);
9398 mmio_flip
->seqno
= 0;
9399 ring
->irq_put(ring
);
9402 spin_unlock_irqrestore(&dev_priv
->mmio_flip_lock
, irq_flags
);
9405 static int intel_queue_mmio_flip(struct drm_device
*dev
,
9406 struct drm_crtc
*crtc
,
9407 struct drm_framebuffer
*fb
,
9408 struct drm_i915_gem_object
*obj
,
9409 struct intel_engine_cs
*ring
,
9412 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9413 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9416 if (WARN_ON(intel_crtc
->mmio_flip
.seqno
))
9419 ret
= intel_postpone_flip(obj
);
9423 intel_do_mmio_flip(intel_crtc
);
9427 spin_lock_irq(&dev_priv
->mmio_flip_lock
);
9428 intel_crtc
->mmio_flip
.seqno
= obj
->last_write_seqno
;
9429 intel_crtc
->mmio_flip
.ring_id
= obj
->ring
->id
;
9430 spin_unlock_irq(&dev_priv
->mmio_flip_lock
);
9433 * Double check to catch cases where irq fired before
9434 * mmio flip data was ready
9436 intel_notify_mmio_flip(obj
->ring
);
9440 static int intel_default_queue_flip(struct drm_device
*dev
,
9441 struct drm_crtc
*crtc
,
9442 struct drm_framebuffer
*fb
,
9443 struct drm_i915_gem_object
*obj
,
9444 struct intel_engine_cs
*ring
,
9450 static bool __intel_pageflip_stall_check(struct drm_device
*dev
,
9451 struct drm_crtc
*crtc
)
9453 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9454 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9455 struct intel_unpin_work
*work
= intel_crtc
->unpin_work
;
9458 if (atomic_read(&work
->pending
) >= INTEL_FLIP_COMPLETE
)
9461 if (!work
->enable_stall_check
)
9464 if (work
->flip_ready_vblank
== 0) {
9465 if (work
->flip_queued_ring
&&
9466 !i915_seqno_passed(work
->flip_queued_ring
->get_seqno(work
->flip_queued_ring
, true),
9467 work
->flip_queued_seqno
))
9470 work
->flip_ready_vblank
= drm_vblank_count(dev
, intel_crtc
->pipe
);
9473 if (drm_vblank_count(dev
, intel_crtc
->pipe
) - work
->flip_ready_vblank
< 3)
9476 /* Potential stall - if we see that the flip has happened,
9477 * assume a missed interrupt. */
9478 if (INTEL_INFO(dev
)->gen
>= 4)
9479 addr
= I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc
->plane
)));
9481 addr
= I915_READ(DSPADDR(intel_crtc
->plane
));
9483 /* There is a potential issue here with a false positive after a flip
9484 * to the same address. We could address this by checking for a
9485 * non-incrementing frame counter.
9487 return addr
== work
->gtt_offset
;
9490 void intel_check_page_flip(struct drm_device
*dev
, int pipe
)
9492 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9493 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
9494 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9501 spin_lock(&dev
->event_lock
);
9502 if (intel_crtc
->unpin_work
&& __intel_pageflip_stall_check(dev
, crtc
)) {
9503 WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n",
9504 intel_crtc
->unpin_work
->flip_queued_vblank
, drm_vblank_count(dev
, pipe
));
9505 page_flip_completed(intel_crtc
);
9507 spin_unlock(&dev
->event_lock
);
9510 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
9511 struct drm_framebuffer
*fb
,
9512 struct drm_pending_vblank_event
*event
,
9513 uint32_t page_flip_flags
)
9515 struct drm_device
*dev
= crtc
->dev
;
9516 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9517 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
9518 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
9519 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9520 enum pipe pipe
= intel_crtc
->pipe
;
9521 struct intel_unpin_work
*work
;
9522 struct intel_engine_cs
*ring
;
9526 * drm_mode_page_flip_ioctl() should already catch this, but double
9527 * check to be safe. In the future we may enable pageflipping from
9528 * a disabled primary plane.
9530 if (WARN_ON(intel_fb_obj(old_fb
) == NULL
))
9533 /* Can't change pixel format via MI display flips. */
9534 if (fb
->pixel_format
!= crtc
->primary
->fb
->pixel_format
)
9538 * TILEOFF/LINOFF registers can't be changed via MI display flips.
9539 * Note that pitch changes could also affect these register.
9541 if (INTEL_INFO(dev
)->gen
> 3 &&
9542 (fb
->offsets
[0] != crtc
->primary
->fb
->offsets
[0] ||
9543 fb
->pitches
[0] != crtc
->primary
->fb
->pitches
[0]))
9546 if (i915_terminally_wedged(&dev_priv
->gpu_error
))
9549 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
9553 work
->event
= event
;
9555 work
->old_fb_obj
= intel_fb_obj(old_fb
);
9556 INIT_WORK(&work
->work
, intel_unpin_work_fn
);
9558 ret
= drm_crtc_vblank_get(crtc
);
9562 /* We borrow the event spin lock for protecting unpin_work */
9563 spin_lock_irq(&dev
->event_lock
);
9564 if (intel_crtc
->unpin_work
) {
9565 /* Before declaring the flip queue wedged, check if
9566 * the hardware completed the operation behind our backs.
9568 if (__intel_pageflip_stall_check(dev
, crtc
)) {
9569 DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
9570 page_flip_completed(intel_crtc
);
9572 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
9573 spin_unlock_irq(&dev
->event_lock
);
9575 drm_crtc_vblank_put(crtc
);
9580 intel_crtc
->unpin_work
= work
;
9581 spin_unlock_irq(&dev
->event_lock
);
9583 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
9584 flush_workqueue(dev_priv
->wq
);
9586 ret
= i915_mutex_lock_interruptible(dev
);
9590 /* Reference the objects for the scheduled work. */
9591 drm_gem_object_reference(&work
->old_fb_obj
->base
);
9592 drm_gem_object_reference(&obj
->base
);
9594 crtc
->primary
->fb
= fb
;
9596 work
->pending_flip_obj
= obj
;
9598 atomic_inc(&intel_crtc
->unpin_work_count
);
9599 intel_crtc
->reset_counter
= atomic_read(&dev_priv
->gpu_error
.reset_counter
);
9601 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
9602 work
->flip_count
= I915_READ(PIPE_FLIPCOUNT_GM45(pipe
)) + 1;
9604 if (IS_VALLEYVIEW(dev
)) {
9605 ring
= &dev_priv
->ring
[BCS
];
9606 if (obj
->tiling_mode
!= work
->old_fb_obj
->tiling_mode
)
9607 /* vlv: DISPLAY_FLIP fails to change tiling */
9609 } else if (IS_IVYBRIDGE(dev
)) {
9610 ring
= &dev_priv
->ring
[BCS
];
9611 } else if (INTEL_INFO(dev
)->gen
>= 7) {
9613 if (ring
== NULL
|| ring
->id
!= RCS
)
9614 ring
= &dev_priv
->ring
[BCS
];
9616 ring
= &dev_priv
->ring
[RCS
];
9619 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
9621 goto cleanup_pending
;
9624 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
;
9626 if (use_mmio_flip(ring
, obj
)) {
9627 ret
= intel_queue_mmio_flip(dev
, crtc
, fb
, obj
, ring
,
9632 work
->flip_queued_seqno
= obj
->last_write_seqno
;
9633 work
->flip_queued_ring
= obj
->ring
;
9635 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
, ring
,
9640 work
->flip_queued_seqno
= intel_ring_get_seqno(ring
);
9641 work
->flip_queued_ring
= ring
;
9644 work
->flip_queued_vblank
= drm_vblank_count(dev
, intel_crtc
->pipe
);
9645 work
->enable_stall_check
= true;
9647 i915_gem_track_fb(work
->old_fb_obj
, obj
,
9648 INTEL_FRONTBUFFER_PRIMARY(pipe
));
9650 intel_disable_fbc(dev
);
9651 intel_frontbuffer_flip_prepare(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
9652 mutex_unlock(&dev
->struct_mutex
);
9654 trace_i915_flip_request(intel_crtc
->plane
, obj
);
9659 intel_unpin_fb_obj(obj
);
9661 atomic_dec(&intel_crtc
->unpin_work_count
);
9662 crtc
->primary
->fb
= old_fb
;
9663 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
9664 drm_gem_object_unreference(&obj
->base
);
9665 mutex_unlock(&dev
->struct_mutex
);
9668 spin_lock_irq(&dev
->event_lock
);
9669 intel_crtc
->unpin_work
= NULL
;
9670 spin_unlock_irq(&dev
->event_lock
);
9672 drm_crtc_vblank_put(crtc
);
9678 intel_crtc_wait_for_pending_flips(crtc
);
9679 ret
= intel_pipe_set_base(crtc
, crtc
->x
, crtc
->y
, fb
);
9680 if (ret
== 0 && event
) {
9681 spin_lock_irq(&dev
->event_lock
);
9682 drm_send_vblank_event(dev
, pipe
, event
);
9683 spin_unlock_irq(&dev
->event_lock
);
9689 static struct drm_crtc_helper_funcs intel_helper_funcs
= {
9690 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
9691 .load_lut
= intel_crtc_load_lut
,
9695 * intel_modeset_update_staged_output_state
9697 * Updates the staged output configuration state, e.g. after we've read out the
9700 static void intel_modeset_update_staged_output_state(struct drm_device
*dev
)
9702 struct intel_crtc
*crtc
;
9703 struct intel_encoder
*encoder
;
9704 struct intel_connector
*connector
;
9706 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9708 connector
->new_encoder
=
9709 to_intel_encoder(connector
->base
.encoder
);
9712 for_each_intel_encoder(dev
, encoder
) {
9714 to_intel_crtc(encoder
->base
.crtc
);
9717 for_each_intel_crtc(dev
, crtc
) {
9718 crtc
->new_enabled
= crtc
->base
.enabled
;
9720 if (crtc
->new_enabled
)
9721 crtc
->new_config
= &crtc
->config
;
9723 crtc
->new_config
= NULL
;
9728 * intel_modeset_commit_output_state
9730 * This function copies the stage display pipe configuration to the real one.
9732 static void intel_modeset_commit_output_state(struct drm_device
*dev
)
9734 struct intel_crtc
*crtc
;
9735 struct intel_encoder
*encoder
;
9736 struct intel_connector
*connector
;
9738 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9740 connector
->base
.encoder
= &connector
->new_encoder
->base
;
9743 for_each_intel_encoder(dev
, encoder
) {
9744 encoder
->base
.crtc
= &encoder
->new_crtc
->base
;
9747 for_each_intel_crtc(dev
, crtc
) {
9748 crtc
->base
.enabled
= crtc
->new_enabled
;
9753 connected_sink_compute_bpp(struct intel_connector
*connector
,
9754 struct intel_crtc_config
*pipe_config
)
9756 int bpp
= pipe_config
->pipe_bpp
;
9758 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
9759 connector
->base
.base
.id
,
9760 connector
->base
.name
);
9762 /* Don't use an invalid EDID bpc value */
9763 if (connector
->base
.display_info
.bpc
&&
9764 connector
->base
.display_info
.bpc
* 3 < bpp
) {
9765 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
9766 bpp
, connector
->base
.display_info
.bpc
*3);
9767 pipe_config
->pipe_bpp
= connector
->base
.display_info
.bpc
*3;
9770 /* Clamp bpp to 8 on screens without EDID 1.4 */
9771 if (connector
->base
.display_info
.bpc
== 0 && bpp
> 24) {
9772 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
9774 pipe_config
->pipe_bpp
= 24;
9779 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
9780 struct drm_framebuffer
*fb
,
9781 struct intel_crtc_config
*pipe_config
)
9783 struct drm_device
*dev
= crtc
->base
.dev
;
9784 struct intel_connector
*connector
;
9787 switch (fb
->pixel_format
) {
9789 bpp
= 8*3; /* since we go through a colormap */
9791 case DRM_FORMAT_XRGB1555
:
9792 case DRM_FORMAT_ARGB1555
:
9793 /* checked in intel_framebuffer_init already */
9794 if (WARN_ON(INTEL_INFO(dev
)->gen
> 3))
9796 case DRM_FORMAT_RGB565
:
9797 bpp
= 6*3; /* min is 18bpp */
9799 case DRM_FORMAT_XBGR8888
:
9800 case DRM_FORMAT_ABGR8888
:
9801 /* checked in intel_framebuffer_init already */
9802 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
9804 case DRM_FORMAT_XRGB8888
:
9805 case DRM_FORMAT_ARGB8888
:
9808 case DRM_FORMAT_XRGB2101010
:
9809 case DRM_FORMAT_ARGB2101010
:
9810 case DRM_FORMAT_XBGR2101010
:
9811 case DRM_FORMAT_ABGR2101010
:
9812 /* checked in intel_framebuffer_init already */
9813 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
9817 /* TODO: gen4+ supports 16 bpc floating point, too. */
9819 DRM_DEBUG_KMS("unsupported depth\n");
9823 pipe_config
->pipe_bpp
= bpp
;
9825 /* Clamp display bpp to EDID value */
9826 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9828 if (!connector
->new_encoder
||
9829 connector
->new_encoder
->new_crtc
!= crtc
)
9832 connected_sink_compute_bpp(connector
, pipe_config
);
9838 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
9840 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
9841 "type: 0x%x flags: 0x%x\n",
9843 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
9844 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
9845 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
9846 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
9849 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
9850 struct intel_crtc_config
*pipe_config
,
9851 const char *context
)
9853 DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc
->base
.base
.id
,
9854 context
, pipe_name(crtc
->pipe
));
9856 DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config
->cpu_transcoder
));
9857 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
9858 pipe_config
->pipe_bpp
, pipe_config
->dither
);
9859 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
9860 pipe_config
->has_pch_encoder
,
9861 pipe_config
->fdi_lanes
,
9862 pipe_config
->fdi_m_n
.gmch_m
, pipe_config
->fdi_m_n
.gmch_n
,
9863 pipe_config
->fdi_m_n
.link_m
, pipe_config
->fdi_m_n
.link_n
,
9864 pipe_config
->fdi_m_n
.tu
);
9865 DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
9866 pipe_config
->has_dp_encoder
,
9867 pipe_config
->dp_m_n
.gmch_m
, pipe_config
->dp_m_n
.gmch_n
,
9868 pipe_config
->dp_m_n
.link_m
, pipe_config
->dp_m_n
.link_n
,
9869 pipe_config
->dp_m_n
.tu
);
9871 DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
9872 pipe_config
->has_dp_encoder
,
9873 pipe_config
->dp_m2_n2
.gmch_m
,
9874 pipe_config
->dp_m2_n2
.gmch_n
,
9875 pipe_config
->dp_m2_n2
.link_m
,
9876 pipe_config
->dp_m2_n2
.link_n
,
9877 pipe_config
->dp_m2_n2
.tu
);
9879 DRM_DEBUG_KMS("requested mode:\n");
9880 drm_mode_debug_printmodeline(&pipe_config
->requested_mode
);
9881 DRM_DEBUG_KMS("adjusted mode:\n");
9882 drm_mode_debug_printmodeline(&pipe_config
->adjusted_mode
);
9883 intel_dump_crtc_timings(&pipe_config
->adjusted_mode
);
9884 DRM_DEBUG_KMS("port clock: %d\n", pipe_config
->port_clock
);
9885 DRM_DEBUG_KMS("pipe src size: %dx%d\n",
9886 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
9887 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
9888 pipe_config
->gmch_pfit
.control
,
9889 pipe_config
->gmch_pfit
.pgm_ratios
,
9890 pipe_config
->gmch_pfit
.lvds_border_bits
);
9891 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
9892 pipe_config
->pch_pfit
.pos
,
9893 pipe_config
->pch_pfit
.size
,
9894 pipe_config
->pch_pfit
.enabled
? "enabled" : "disabled");
9895 DRM_DEBUG_KMS("ips: %i\n", pipe_config
->ips_enabled
);
9896 DRM_DEBUG_KMS("double wide: %i\n", pipe_config
->double_wide
);
9899 static bool encoders_cloneable(const struct intel_encoder
*a
,
9900 const struct intel_encoder
*b
)
9902 /* masks could be asymmetric, so check both ways */
9903 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
9904 b
->cloneable
& (1 << a
->type
));
9907 static bool check_single_encoder_cloning(struct intel_crtc
*crtc
,
9908 struct intel_encoder
*encoder
)
9910 struct drm_device
*dev
= crtc
->base
.dev
;
9911 struct intel_encoder
*source_encoder
;
9913 for_each_intel_encoder(dev
, source_encoder
) {
9914 if (source_encoder
->new_crtc
!= crtc
)
9917 if (!encoders_cloneable(encoder
, source_encoder
))
9924 static bool check_encoder_cloning(struct intel_crtc
*crtc
)
9926 struct drm_device
*dev
= crtc
->base
.dev
;
9927 struct intel_encoder
*encoder
;
9929 for_each_intel_encoder(dev
, encoder
) {
9930 if (encoder
->new_crtc
!= crtc
)
9933 if (!check_single_encoder_cloning(crtc
, encoder
))
9940 static struct intel_crtc_config
*
9941 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
9942 struct drm_framebuffer
*fb
,
9943 struct drm_display_mode
*mode
)
9945 struct drm_device
*dev
= crtc
->dev
;
9946 struct intel_encoder
*encoder
;
9947 struct intel_crtc_config
*pipe_config
;
9948 int plane_bpp
, ret
= -EINVAL
;
9951 if (!check_encoder_cloning(to_intel_crtc(crtc
))) {
9952 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
9953 return ERR_PTR(-EINVAL
);
9956 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
9958 return ERR_PTR(-ENOMEM
);
9960 drm_mode_copy(&pipe_config
->adjusted_mode
, mode
);
9961 drm_mode_copy(&pipe_config
->requested_mode
, mode
);
9963 pipe_config
->cpu_transcoder
=
9964 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
9965 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
9968 * Sanitize sync polarity flags based on requested ones. If neither
9969 * positive or negative polarity is requested, treat this as meaning
9970 * negative polarity.
9972 if (!(pipe_config
->adjusted_mode
.flags
&
9973 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
9974 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
9976 if (!(pipe_config
->adjusted_mode
.flags
&
9977 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
9978 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
9980 /* Compute a starting value for pipe_config->pipe_bpp taking the source
9981 * plane pixel format and any sink constraints into account. Returns the
9982 * source plane bpp so that dithering can be selected on mismatches
9983 * after encoders and crtc also have had their say. */
9984 plane_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
9990 * Determine the real pipe dimensions. Note that stereo modes can
9991 * increase the actual pipe size due to the frame doubling and
9992 * insertion of additional space for blanks between the frame. This
9993 * is stored in the crtc timings. We use the requested mode to do this
9994 * computation to clearly distinguish it from the adjusted mode, which
9995 * can be changed by the connectors in the below retry loop.
9997 drm_mode_set_crtcinfo(&pipe_config
->requested_mode
, CRTC_STEREO_DOUBLE
);
9998 pipe_config
->pipe_src_w
= pipe_config
->requested_mode
.crtc_hdisplay
;
9999 pipe_config
->pipe_src_h
= pipe_config
->requested_mode
.crtc_vdisplay
;
10002 /* Ensure the port clock defaults are reset when retrying. */
10003 pipe_config
->port_clock
= 0;
10004 pipe_config
->pixel_multiplier
= 1;
10006 /* Fill in default crtc timings, allow encoders to overwrite them. */
10007 drm_mode_set_crtcinfo(&pipe_config
->adjusted_mode
, CRTC_STEREO_DOUBLE
);
10009 /* Pass our mode to the connectors and the CRTC to give them a chance to
10010 * adjust it according to limitations or connector properties, and also
10011 * a chance to reject the mode entirely.
10013 for_each_intel_encoder(dev
, encoder
) {
10015 if (&encoder
->new_crtc
->base
!= crtc
)
10018 if (!(encoder
->compute_config(encoder
, pipe_config
))) {
10019 DRM_DEBUG_KMS("Encoder config failure\n");
10024 /* Set default port clock if not overwritten by the encoder. Needs to be
10025 * done afterwards in case the encoder adjusts the mode. */
10026 if (!pipe_config
->port_clock
)
10027 pipe_config
->port_clock
= pipe_config
->adjusted_mode
.crtc_clock
10028 * pipe_config
->pixel_multiplier
;
10030 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
10032 DRM_DEBUG_KMS("CRTC fixup failed\n");
10036 if (ret
== RETRY
) {
10037 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
10042 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
10044 goto encoder_retry
;
10047 pipe_config
->dither
= pipe_config
->pipe_bpp
!= plane_bpp
;
10048 DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
10049 plane_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
10051 return pipe_config
;
10053 kfree(pipe_config
);
10054 return ERR_PTR(ret
);
10057 /* Computes which crtcs are affected and sets the relevant bits in the mask. For
10058 * simplicity we use the crtc's pipe number (because it's easier to obtain). */
10060 intel_modeset_affected_pipes(struct drm_crtc
*crtc
, unsigned *modeset_pipes
,
10061 unsigned *prepare_pipes
, unsigned *disable_pipes
)
10063 struct intel_crtc
*intel_crtc
;
10064 struct drm_device
*dev
= crtc
->dev
;
10065 struct intel_encoder
*encoder
;
10066 struct intel_connector
*connector
;
10067 struct drm_crtc
*tmp_crtc
;
10069 *disable_pipes
= *modeset_pipes
= *prepare_pipes
= 0;
10071 /* Check which crtcs have changed outputs connected to them, these need
10072 * to be part of the prepare_pipes mask. We don't (yet) support global
10073 * modeset across multiple crtcs, so modeset_pipes will only have one
10074 * bit set at most. */
10075 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10077 if (connector
->base
.encoder
== &connector
->new_encoder
->base
)
10080 if (connector
->base
.encoder
) {
10081 tmp_crtc
= connector
->base
.encoder
->crtc
;
10083 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
10086 if (connector
->new_encoder
)
10088 1 << connector
->new_encoder
->new_crtc
->pipe
;
10091 for_each_intel_encoder(dev
, encoder
) {
10092 if (encoder
->base
.crtc
== &encoder
->new_crtc
->base
)
10095 if (encoder
->base
.crtc
) {
10096 tmp_crtc
= encoder
->base
.crtc
;
10098 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
10101 if (encoder
->new_crtc
)
10102 *prepare_pipes
|= 1 << encoder
->new_crtc
->pipe
;
10105 /* Check for pipes that will be enabled/disabled ... */
10106 for_each_intel_crtc(dev
, intel_crtc
) {
10107 if (intel_crtc
->base
.enabled
== intel_crtc
->new_enabled
)
10110 if (!intel_crtc
->new_enabled
)
10111 *disable_pipes
|= 1 << intel_crtc
->pipe
;
10113 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
10117 /* set_mode is also used to update properties on life display pipes. */
10118 intel_crtc
= to_intel_crtc(crtc
);
10119 if (intel_crtc
->new_enabled
)
10120 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
10123 * For simplicity do a full modeset on any pipe where the output routing
10124 * changed. We could be more clever, but that would require us to be
10125 * more careful with calling the relevant encoder->mode_set functions.
10127 if (*prepare_pipes
)
10128 *modeset_pipes
= *prepare_pipes
;
10130 /* ... and mask these out. */
10131 *modeset_pipes
&= ~(*disable_pipes
);
10132 *prepare_pipes
&= ~(*disable_pipes
);
10135 * HACK: We don't (yet) fully support global modesets. intel_set_config
10136 * obies this rule, but the modeset restore mode of
10137 * intel_modeset_setup_hw_state does not.
10139 *modeset_pipes
&= 1 << intel_crtc
->pipe
;
10140 *prepare_pipes
&= 1 << intel_crtc
->pipe
;
10142 DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
10143 *modeset_pipes
, *prepare_pipes
, *disable_pipes
);
10146 static bool intel_crtc_in_use(struct drm_crtc
*crtc
)
10148 struct drm_encoder
*encoder
;
10149 struct drm_device
*dev
= crtc
->dev
;
10151 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
10152 if (encoder
->crtc
== crtc
)
10159 intel_modeset_update_state(struct drm_device
*dev
, unsigned prepare_pipes
)
10161 struct intel_encoder
*intel_encoder
;
10162 struct intel_crtc
*intel_crtc
;
10163 struct drm_connector
*connector
;
10165 for_each_intel_encoder(dev
, intel_encoder
) {
10166 if (!intel_encoder
->base
.crtc
)
10169 intel_crtc
= to_intel_crtc(intel_encoder
->base
.crtc
);
10171 if (prepare_pipes
& (1 << intel_crtc
->pipe
))
10172 intel_encoder
->connectors_active
= false;
10175 intel_modeset_commit_output_state(dev
);
10177 /* Double check state. */
10178 for_each_intel_crtc(dev
, intel_crtc
) {
10179 WARN_ON(intel_crtc
->base
.enabled
!= intel_crtc_in_use(&intel_crtc
->base
));
10180 WARN_ON(intel_crtc
->new_config
&&
10181 intel_crtc
->new_config
!= &intel_crtc
->config
);
10182 WARN_ON(intel_crtc
->base
.enabled
!= !!intel_crtc
->new_config
);
10185 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
10186 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
10189 intel_crtc
= to_intel_crtc(connector
->encoder
->crtc
);
10191 if (prepare_pipes
& (1 << intel_crtc
->pipe
)) {
10192 struct drm_property
*dpms_property
=
10193 dev
->mode_config
.dpms_property
;
10195 connector
->dpms
= DRM_MODE_DPMS_ON
;
10196 drm_object_property_set_value(&connector
->base
,
10200 intel_encoder
= to_intel_encoder(connector
->encoder
);
10201 intel_encoder
->connectors_active
= true;
10207 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
10211 if (clock1
== clock2
)
10214 if (!clock1
|| !clock2
)
10217 diff
= abs(clock1
- clock2
);
10219 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
10225 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
10226 list_for_each_entry((intel_crtc), \
10227 &(dev)->mode_config.crtc_list, \
10229 if (mask & (1 <<(intel_crtc)->pipe))
10232 intel_pipe_config_compare(struct drm_device
*dev
,
10233 struct intel_crtc_config
*current_config
,
10234 struct intel_crtc_config
*pipe_config
)
10236 #define PIPE_CONF_CHECK_X(name) \
10237 if (current_config->name != pipe_config->name) { \
10238 DRM_ERROR("mismatch in " #name " " \
10239 "(expected 0x%08x, found 0x%08x)\n", \
10240 current_config->name, \
10241 pipe_config->name); \
10245 #define PIPE_CONF_CHECK_I(name) \
10246 if (current_config->name != pipe_config->name) { \
10247 DRM_ERROR("mismatch in " #name " " \
10248 "(expected %i, found %i)\n", \
10249 current_config->name, \
10250 pipe_config->name); \
10254 /* This is required for BDW+ where there is only one set of registers for
10255 * switching between high and low RR.
10256 * This macro can be used whenever a comparison has to be made between one
10257 * hw state and multiple sw state variables.
10259 #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \
10260 if ((current_config->name != pipe_config->name) && \
10261 (current_config->alt_name != pipe_config->name)) { \
10262 DRM_ERROR("mismatch in " #name " " \
10263 "(expected %i or %i, found %i)\n", \
10264 current_config->name, \
10265 current_config->alt_name, \
10266 pipe_config->name); \
10270 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
10271 if ((current_config->name ^ pipe_config->name) & (mask)) { \
10272 DRM_ERROR("mismatch in " #name "(" #mask ") " \
10273 "(expected %i, found %i)\n", \
10274 current_config->name & (mask), \
10275 pipe_config->name & (mask)); \
10279 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
10280 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
10281 DRM_ERROR("mismatch in " #name " " \
10282 "(expected %i, found %i)\n", \
10283 current_config->name, \
10284 pipe_config->name); \
10288 #define PIPE_CONF_QUIRK(quirk) \
10289 ((current_config->quirks | pipe_config->quirks) & (quirk))
10291 PIPE_CONF_CHECK_I(cpu_transcoder
);
10293 PIPE_CONF_CHECK_I(has_pch_encoder
);
10294 PIPE_CONF_CHECK_I(fdi_lanes
);
10295 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_m
);
10296 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_n
);
10297 PIPE_CONF_CHECK_I(fdi_m_n
.link_m
);
10298 PIPE_CONF_CHECK_I(fdi_m_n
.link_n
);
10299 PIPE_CONF_CHECK_I(fdi_m_n
.tu
);
10301 PIPE_CONF_CHECK_I(has_dp_encoder
);
10303 if (INTEL_INFO(dev
)->gen
< 8) {
10304 PIPE_CONF_CHECK_I(dp_m_n
.gmch_m
);
10305 PIPE_CONF_CHECK_I(dp_m_n
.gmch_n
);
10306 PIPE_CONF_CHECK_I(dp_m_n
.link_m
);
10307 PIPE_CONF_CHECK_I(dp_m_n
.link_n
);
10308 PIPE_CONF_CHECK_I(dp_m_n
.tu
);
10310 if (current_config
->has_drrs
) {
10311 PIPE_CONF_CHECK_I(dp_m2_n2
.gmch_m
);
10312 PIPE_CONF_CHECK_I(dp_m2_n2
.gmch_n
);
10313 PIPE_CONF_CHECK_I(dp_m2_n2
.link_m
);
10314 PIPE_CONF_CHECK_I(dp_m2_n2
.link_n
);
10315 PIPE_CONF_CHECK_I(dp_m2_n2
.tu
);
10318 PIPE_CONF_CHECK_I_ALT(dp_m_n
.gmch_m
, dp_m2_n2
.gmch_m
);
10319 PIPE_CONF_CHECK_I_ALT(dp_m_n
.gmch_n
, dp_m2_n2
.gmch_n
);
10320 PIPE_CONF_CHECK_I_ALT(dp_m_n
.link_m
, dp_m2_n2
.link_m
);
10321 PIPE_CONF_CHECK_I_ALT(dp_m_n
.link_n
, dp_m2_n2
.link_n
);
10322 PIPE_CONF_CHECK_I_ALT(dp_m_n
.tu
, dp_m2_n2
.tu
);
10325 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hdisplay
);
10326 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_htotal
);
10327 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hblank_start
);
10328 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hblank_end
);
10329 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hsync_start
);
10330 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hsync_end
);
10332 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vdisplay
);
10333 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vtotal
);
10334 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vblank_start
);
10335 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vblank_end
);
10336 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vsync_start
);
10337 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vsync_end
);
10339 PIPE_CONF_CHECK_I(pixel_multiplier
);
10340 PIPE_CONF_CHECK_I(has_hdmi_sink
);
10341 if ((INTEL_INFO(dev
)->gen
< 8 && !IS_HASWELL(dev
)) ||
10342 IS_VALLEYVIEW(dev
))
10343 PIPE_CONF_CHECK_I(limited_color_range
);
10345 PIPE_CONF_CHECK_I(has_audio
);
10347 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10348 DRM_MODE_FLAG_INTERLACE
);
10350 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
10351 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10352 DRM_MODE_FLAG_PHSYNC
);
10353 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10354 DRM_MODE_FLAG_NHSYNC
);
10355 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10356 DRM_MODE_FLAG_PVSYNC
);
10357 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10358 DRM_MODE_FLAG_NVSYNC
);
10361 PIPE_CONF_CHECK_I(pipe_src_w
);
10362 PIPE_CONF_CHECK_I(pipe_src_h
);
10365 * FIXME: BIOS likes to set up a cloned config with lvds+external
10366 * screen. Since we don't yet re-compute the pipe config when moving
10367 * just the lvds port away to another pipe the sw tracking won't match.
10369 * Proper atomic modesets with recomputed global state will fix this.
10370 * Until then just don't check gmch state for inherited modes.
10372 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE
)) {
10373 PIPE_CONF_CHECK_I(gmch_pfit
.control
);
10374 /* pfit ratios are autocomputed by the hw on gen4+ */
10375 if (INTEL_INFO(dev
)->gen
< 4)
10376 PIPE_CONF_CHECK_I(gmch_pfit
.pgm_ratios
);
10377 PIPE_CONF_CHECK_I(gmch_pfit
.lvds_border_bits
);
10380 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
10381 if (current_config
->pch_pfit
.enabled
) {
10382 PIPE_CONF_CHECK_I(pch_pfit
.pos
);
10383 PIPE_CONF_CHECK_I(pch_pfit
.size
);
10386 /* BDW+ don't expose a synchronous way to read the state */
10387 if (IS_HASWELL(dev
))
10388 PIPE_CONF_CHECK_I(ips_enabled
);
10390 PIPE_CONF_CHECK_I(double_wide
);
10392 PIPE_CONF_CHECK_X(ddi_pll_sel
);
10394 PIPE_CONF_CHECK_I(shared_dpll
);
10395 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
10396 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
10397 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
10398 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
10399 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
10401 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5)
10402 PIPE_CONF_CHECK_I(pipe_bpp
);
10404 PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode
.crtc_clock
);
10405 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
10407 #undef PIPE_CONF_CHECK_X
10408 #undef PIPE_CONF_CHECK_I
10409 #undef PIPE_CONF_CHECK_I_ALT
10410 #undef PIPE_CONF_CHECK_FLAGS
10411 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
10412 #undef PIPE_CONF_QUIRK
10418 check_connector_state(struct drm_device
*dev
)
10420 struct intel_connector
*connector
;
10422 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10424 /* This also checks the encoder/connector hw state with the
10425 * ->get_hw_state callbacks. */
10426 intel_connector_check_state(connector
);
10428 WARN(&connector
->new_encoder
->base
!= connector
->base
.encoder
,
10429 "connector's staged encoder doesn't match current encoder\n");
10434 check_encoder_state(struct drm_device
*dev
)
10436 struct intel_encoder
*encoder
;
10437 struct intel_connector
*connector
;
10439 for_each_intel_encoder(dev
, encoder
) {
10440 bool enabled
= false;
10441 bool active
= false;
10442 enum pipe pipe
, tracked_pipe
;
10444 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
10445 encoder
->base
.base
.id
,
10446 encoder
->base
.name
);
10448 WARN(&encoder
->new_crtc
->base
!= encoder
->base
.crtc
,
10449 "encoder's stage crtc doesn't match current crtc\n");
10450 WARN(encoder
->connectors_active
&& !encoder
->base
.crtc
,
10451 "encoder's active_connectors set, but no crtc\n");
10453 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10455 if (connector
->base
.encoder
!= &encoder
->base
)
10458 if (connector
->base
.dpms
!= DRM_MODE_DPMS_OFF
)
10462 * for MST connectors if we unplug the connector is gone
10463 * away but the encoder is still connected to a crtc
10464 * until a modeset happens in response to the hotplug.
10466 if (!enabled
&& encoder
->base
.encoder_type
== DRM_MODE_ENCODER_DPMST
)
10469 WARN(!!encoder
->base
.crtc
!= enabled
,
10470 "encoder's enabled state mismatch "
10471 "(expected %i, found %i)\n",
10472 !!encoder
->base
.crtc
, enabled
);
10473 WARN(active
&& !encoder
->base
.crtc
,
10474 "active encoder with no crtc\n");
10476 WARN(encoder
->connectors_active
!= active
,
10477 "encoder's computed active state doesn't match tracked active state "
10478 "(expected %i, found %i)\n", active
, encoder
->connectors_active
);
10480 active
= encoder
->get_hw_state(encoder
, &pipe
);
10481 WARN(active
!= encoder
->connectors_active
,
10482 "encoder's hw state doesn't match sw tracking "
10483 "(expected %i, found %i)\n",
10484 encoder
->connectors_active
, active
);
10486 if (!encoder
->base
.crtc
)
10489 tracked_pipe
= to_intel_crtc(encoder
->base
.crtc
)->pipe
;
10490 WARN(active
&& pipe
!= tracked_pipe
,
10491 "active encoder's pipe doesn't match"
10492 "(expected %i, found %i)\n",
10493 tracked_pipe
, pipe
);
10499 check_crtc_state(struct drm_device
*dev
)
10501 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10502 struct intel_crtc
*crtc
;
10503 struct intel_encoder
*encoder
;
10504 struct intel_crtc_config pipe_config
;
10506 for_each_intel_crtc(dev
, crtc
) {
10507 bool enabled
= false;
10508 bool active
= false;
10510 memset(&pipe_config
, 0, sizeof(pipe_config
));
10512 DRM_DEBUG_KMS("[CRTC:%d]\n",
10513 crtc
->base
.base
.id
);
10515 WARN(crtc
->active
&& !crtc
->base
.enabled
,
10516 "active crtc, but not enabled in sw tracking\n");
10518 for_each_intel_encoder(dev
, encoder
) {
10519 if (encoder
->base
.crtc
!= &crtc
->base
)
10522 if (encoder
->connectors_active
)
10526 WARN(active
!= crtc
->active
,
10527 "crtc's computed active state doesn't match tracked active state "
10528 "(expected %i, found %i)\n", active
, crtc
->active
);
10529 WARN(enabled
!= crtc
->base
.enabled
,
10530 "crtc's computed enabled state doesn't match tracked enabled state "
10531 "(expected %i, found %i)\n", enabled
, crtc
->base
.enabled
);
10533 active
= dev_priv
->display
.get_pipe_config(crtc
,
10536 /* hw state is inconsistent with the pipe quirk */
10537 if ((crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
10538 (crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
10539 active
= crtc
->active
;
10541 for_each_intel_encoder(dev
, encoder
) {
10543 if (encoder
->base
.crtc
!= &crtc
->base
)
10545 if (encoder
->get_hw_state(encoder
, &pipe
))
10546 encoder
->get_config(encoder
, &pipe_config
);
10549 WARN(crtc
->active
!= active
,
10550 "crtc active state doesn't match with hw state "
10551 "(expected %i, found %i)\n", crtc
->active
, active
);
10554 !intel_pipe_config_compare(dev
, &crtc
->config
, &pipe_config
)) {
10555 WARN(1, "pipe state doesn't match!\n");
10556 intel_dump_pipe_config(crtc
, &pipe_config
,
10558 intel_dump_pipe_config(crtc
, &crtc
->config
,
10565 check_shared_dpll_state(struct drm_device
*dev
)
10567 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10568 struct intel_crtc
*crtc
;
10569 struct intel_dpll_hw_state dpll_hw_state
;
10572 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
10573 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
10574 int enabled_crtcs
= 0, active_crtcs
= 0;
10577 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
10579 DRM_DEBUG_KMS("%s\n", pll
->name
);
10581 active
= pll
->get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
10583 WARN(pll
->active
> pll
->refcount
,
10584 "more active pll users than references: %i vs %i\n",
10585 pll
->active
, pll
->refcount
);
10586 WARN(pll
->active
&& !pll
->on
,
10587 "pll in active use but not on in sw tracking\n");
10588 WARN(pll
->on
&& !pll
->active
,
10589 "pll in on but not on in use in sw tracking\n");
10590 WARN(pll
->on
!= active
,
10591 "pll on state mismatch (expected %i, found %i)\n",
10594 for_each_intel_crtc(dev
, crtc
) {
10595 if (crtc
->base
.enabled
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
10597 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
10600 WARN(pll
->active
!= active_crtcs
,
10601 "pll active crtcs mismatch (expected %i, found %i)\n",
10602 pll
->active
, active_crtcs
);
10603 WARN(pll
->refcount
!= enabled_crtcs
,
10604 "pll enabled crtcs mismatch (expected %i, found %i)\n",
10605 pll
->refcount
, enabled_crtcs
);
10607 WARN(pll
->on
&& memcmp(&pll
->hw_state
, &dpll_hw_state
,
10608 sizeof(dpll_hw_state
)),
10609 "pll hw state mismatch\n");
10614 intel_modeset_check_state(struct drm_device
*dev
)
10616 check_connector_state(dev
);
10617 check_encoder_state(dev
);
10618 check_crtc_state(dev
);
10619 check_shared_dpll_state(dev
);
10622 void ironlake_check_encoder_dotclock(const struct intel_crtc_config
*pipe_config
,
10626 * FDI already provided one idea for the dotclock.
10627 * Yell if the encoder disagrees.
10629 WARN(!intel_fuzzy_clock_check(pipe_config
->adjusted_mode
.crtc_clock
, dotclock
),
10630 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
10631 pipe_config
->adjusted_mode
.crtc_clock
, dotclock
);
10634 static void update_scanline_offset(struct intel_crtc
*crtc
)
10636 struct drm_device
*dev
= crtc
->base
.dev
;
10639 * The scanline counter increments at the leading edge of hsync.
10641 * On most platforms it starts counting from vtotal-1 on the
10642 * first active line. That means the scanline counter value is
10643 * always one less than what we would expect. Ie. just after
10644 * start of vblank, which also occurs at start of hsync (on the
10645 * last active line), the scanline counter will read vblank_start-1.
10647 * On gen2 the scanline counter starts counting from 1 instead
10648 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
10649 * to keep the value positive), instead of adding one.
10651 * On HSW+ the behaviour of the scanline counter depends on the output
10652 * type. For DP ports it behaves like most other platforms, but on HDMI
10653 * there's an extra 1 line difference. So we need to add two instead of
10654 * one to the value.
10656 if (IS_GEN2(dev
)) {
10657 const struct drm_display_mode
*mode
= &crtc
->config
.adjusted_mode
;
10660 vtotal
= mode
->crtc_vtotal
;
10661 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
10664 crtc
->scanline_offset
= vtotal
- 1;
10665 } else if (HAS_DDI(dev
) &&
10666 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
)) {
10667 crtc
->scanline_offset
= 2;
10669 crtc
->scanline_offset
= 1;
10672 static int __intel_set_mode(struct drm_crtc
*crtc
,
10673 struct drm_display_mode
*mode
,
10674 int x
, int y
, struct drm_framebuffer
*fb
)
10676 struct drm_device
*dev
= crtc
->dev
;
10677 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10678 struct drm_display_mode
*saved_mode
;
10679 struct intel_crtc_config
*pipe_config
= NULL
;
10680 struct intel_crtc
*intel_crtc
;
10681 unsigned disable_pipes
, prepare_pipes
, modeset_pipes
;
10684 saved_mode
= kmalloc(sizeof(*saved_mode
), GFP_KERNEL
);
10688 intel_modeset_affected_pipes(crtc
, &modeset_pipes
,
10689 &prepare_pipes
, &disable_pipes
);
10691 *saved_mode
= crtc
->mode
;
10693 /* Hack: Because we don't (yet) support global modeset on multiple
10694 * crtcs, we don't keep track of the new mode for more than one crtc.
10695 * Hence simply check whether any bit is set in modeset_pipes in all the
10696 * pieces of code that are not yet converted to deal with mutliple crtcs
10697 * changing their mode at the same time. */
10698 if (modeset_pipes
) {
10699 pipe_config
= intel_modeset_pipe_config(crtc
, fb
, mode
);
10700 if (IS_ERR(pipe_config
)) {
10701 ret
= PTR_ERR(pipe_config
);
10702 pipe_config
= NULL
;
10706 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
10708 to_intel_crtc(crtc
)->new_config
= pipe_config
;
10712 * See if the config requires any additional preparation, e.g.
10713 * to adjust global state with pipes off. We need to do this
10714 * here so we can get the modeset_pipe updated config for the new
10715 * mode set on this crtc. For other crtcs we need to use the
10716 * adjusted_mode bits in the crtc directly.
10718 if (IS_VALLEYVIEW(dev
)) {
10719 valleyview_modeset_global_pipes(dev
, &prepare_pipes
);
10721 /* may have added more to prepare_pipes than we should */
10722 prepare_pipes
&= ~disable_pipes
;
10725 for_each_intel_crtc_masked(dev
, disable_pipes
, intel_crtc
)
10726 intel_crtc_disable(&intel_crtc
->base
);
10728 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
10729 if (intel_crtc
->base
.enabled
)
10730 dev_priv
->display
.crtc_disable(&intel_crtc
->base
);
10733 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
10734 * to set it here already despite that we pass it down the callchain.
10736 if (modeset_pipes
) {
10737 crtc
->mode
= *mode
;
10738 /* mode_set/enable/disable functions rely on a correct pipe
10740 to_intel_crtc(crtc
)->config
= *pipe_config
;
10741 to_intel_crtc(crtc
)->new_config
= &to_intel_crtc(crtc
)->config
;
10744 * Calculate and store various constants which
10745 * are later needed by vblank and swap-completion
10746 * timestamping. They are derived from true hwmode.
10748 drm_calc_timestamping_constants(crtc
,
10749 &pipe_config
->adjusted_mode
);
10752 /* Only after disabling all output pipelines that will be changed can we
10753 * update the the output configuration. */
10754 intel_modeset_update_state(dev
, prepare_pipes
);
10756 if (dev_priv
->display
.modeset_global_resources
)
10757 dev_priv
->display
.modeset_global_resources(dev
);
10759 /* Set up the DPLL and any encoders state that needs to adjust or depend
10762 for_each_intel_crtc_masked(dev
, modeset_pipes
, intel_crtc
) {
10763 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
10764 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(old_fb
);
10765 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
10767 mutex_lock(&dev
->struct_mutex
);
10768 ret
= intel_pin_and_fence_fb_obj(dev
,
10772 DRM_ERROR("pin & fence failed\n");
10773 mutex_unlock(&dev
->struct_mutex
);
10777 intel_unpin_fb_obj(old_obj
);
10778 i915_gem_track_fb(old_obj
, obj
,
10779 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
10780 mutex_unlock(&dev
->struct_mutex
);
10782 crtc
->primary
->fb
= fb
;
10786 ret
= dev_priv
->display
.crtc_mode_set(intel_crtc
, x
, y
, fb
);
10791 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
10792 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
10793 update_scanline_offset(intel_crtc
);
10795 dev_priv
->display
.crtc_enable(&intel_crtc
->base
);
10798 /* FIXME: add subpixel order */
10800 if (ret
&& crtc
->enabled
)
10801 crtc
->mode
= *saved_mode
;
10804 kfree(pipe_config
);
10809 static int intel_set_mode(struct drm_crtc
*crtc
,
10810 struct drm_display_mode
*mode
,
10811 int x
, int y
, struct drm_framebuffer
*fb
)
10815 ret
= __intel_set_mode(crtc
, mode
, x
, y
, fb
);
10818 intel_modeset_check_state(crtc
->dev
);
10823 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
10825 intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
, crtc
->primary
->fb
);
10828 #undef for_each_intel_crtc_masked
10830 static void intel_set_config_free(struct intel_set_config
*config
)
10835 kfree(config
->save_connector_encoders
);
10836 kfree(config
->save_encoder_crtcs
);
10837 kfree(config
->save_crtc_enabled
);
10841 static int intel_set_config_save_state(struct drm_device
*dev
,
10842 struct intel_set_config
*config
)
10844 struct drm_crtc
*crtc
;
10845 struct drm_encoder
*encoder
;
10846 struct drm_connector
*connector
;
10849 config
->save_crtc_enabled
=
10850 kcalloc(dev
->mode_config
.num_crtc
,
10851 sizeof(bool), GFP_KERNEL
);
10852 if (!config
->save_crtc_enabled
)
10855 config
->save_encoder_crtcs
=
10856 kcalloc(dev
->mode_config
.num_encoder
,
10857 sizeof(struct drm_crtc
*), GFP_KERNEL
);
10858 if (!config
->save_encoder_crtcs
)
10861 config
->save_connector_encoders
=
10862 kcalloc(dev
->mode_config
.num_connector
,
10863 sizeof(struct drm_encoder
*), GFP_KERNEL
);
10864 if (!config
->save_connector_encoders
)
10867 /* Copy data. Note that driver private data is not affected.
10868 * Should anything bad happen only the expected state is
10869 * restored, not the drivers personal bookkeeping.
10872 for_each_crtc(dev
, crtc
) {
10873 config
->save_crtc_enabled
[count
++] = crtc
->enabled
;
10877 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
10878 config
->save_encoder_crtcs
[count
++] = encoder
->crtc
;
10882 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
10883 config
->save_connector_encoders
[count
++] = connector
->encoder
;
10889 static void intel_set_config_restore_state(struct drm_device
*dev
,
10890 struct intel_set_config
*config
)
10892 struct intel_crtc
*crtc
;
10893 struct intel_encoder
*encoder
;
10894 struct intel_connector
*connector
;
10898 for_each_intel_crtc(dev
, crtc
) {
10899 crtc
->new_enabled
= config
->save_crtc_enabled
[count
++];
10901 if (crtc
->new_enabled
)
10902 crtc
->new_config
= &crtc
->config
;
10904 crtc
->new_config
= NULL
;
10908 for_each_intel_encoder(dev
, encoder
) {
10909 encoder
->new_crtc
=
10910 to_intel_crtc(config
->save_encoder_crtcs
[count
++]);
10914 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, base
.head
) {
10915 connector
->new_encoder
=
10916 to_intel_encoder(config
->save_connector_encoders
[count
++]);
10921 is_crtc_connector_off(struct drm_mode_set
*set
)
10925 if (set
->num_connectors
== 0)
10928 if (WARN_ON(set
->connectors
== NULL
))
10931 for (i
= 0; i
< set
->num_connectors
; i
++)
10932 if (set
->connectors
[i
]->encoder
&&
10933 set
->connectors
[i
]->encoder
->crtc
== set
->crtc
&&
10934 set
->connectors
[i
]->dpms
!= DRM_MODE_DPMS_ON
)
10941 intel_set_config_compute_mode_changes(struct drm_mode_set
*set
,
10942 struct intel_set_config
*config
)
10945 /* We should be able to check here if the fb has the same properties
10946 * and then just flip_or_move it */
10947 if (is_crtc_connector_off(set
)) {
10948 config
->mode_changed
= true;
10949 } else if (set
->crtc
->primary
->fb
!= set
->fb
) {
10951 * If we have no fb, we can only flip as long as the crtc is
10952 * active, otherwise we need a full mode set. The crtc may
10953 * be active if we've only disabled the primary plane, or
10954 * in fastboot situations.
10956 if (set
->crtc
->primary
->fb
== NULL
) {
10957 struct intel_crtc
*intel_crtc
=
10958 to_intel_crtc(set
->crtc
);
10960 if (intel_crtc
->active
) {
10961 DRM_DEBUG_KMS("crtc has no fb, will flip\n");
10962 config
->fb_changed
= true;
10964 DRM_DEBUG_KMS("inactive crtc, full mode set\n");
10965 config
->mode_changed
= true;
10967 } else if (set
->fb
== NULL
) {
10968 config
->mode_changed
= true;
10969 } else if (set
->fb
->pixel_format
!=
10970 set
->crtc
->primary
->fb
->pixel_format
) {
10971 config
->mode_changed
= true;
10973 config
->fb_changed
= true;
10977 if (set
->fb
&& (set
->x
!= set
->crtc
->x
|| set
->y
!= set
->crtc
->y
))
10978 config
->fb_changed
= true;
10980 if (set
->mode
&& !drm_mode_equal(set
->mode
, &set
->crtc
->mode
)) {
10981 DRM_DEBUG_KMS("modes are different, full mode set\n");
10982 drm_mode_debug_printmodeline(&set
->crtc
->mode
);
10983 drm_mode_debug_printmodeline(set
->mode
);
10984 config
->mode_changed
= true;
10987 DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
10988 set
->crtc
->base
.id
, config
->mode_changed
, config
->fb_changed
);
10992 intel_modeset_stage_output_state(struct drm_device
*dev
,
10993 struct drm_mode_set
*set
,
10994 struct intel_set_config
*config
)
10996 struct intel_connector
*connector
;
10997 struct intel_encoder
*encoder
;
10998 struct intel_crtc
*crtc
;
11001 /* The upper layers ensure that we either disable a crtc or have a list
11002 * of connectors. For paranoia, double-check this. */
11003 WARN_ON(!set
->fb
&& (set
->num_connectors
!= 0));
11004 WARN_ON(set
->fb
&& (set
->num_connectors
== 0));
11006 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
11008 /* Otherwise traverse passed in connector list and get encoders
11010 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
11011 if (set
->connectors
[ro
] == &connector
->base
) {
11012 connector
->new_encoder
= intel_find_encoder(connector
, to_intel_crtc(set
->crtc
)->pipe
);
11017 /* If we disable the crtc, disable all its connectors. Also, if
11018 * the connector is on the changing crtc but not on the new
11019 * connector list, disable it. */
11020 if ((!set
->fb
|| ro
== set
->num_connectors
) &&
11021 connector
->base
.encoder
&&
11022 connector
->base
.encoder
->crtc
== set
->crtc
) {
11023 connector
->new_encoder
= NULL
;
11025 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
11026 connector
->base
.base
.id
,
11027 connector
->base
.name
);
11031 if (&connector
->new_encoder
->base
!= connector
->base
.encoder
) {
11032 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
11033 config
->mode_changed
= true;
11036 /* connector->new_encoder is now updated for all connectors. */
11038 /* Update crtc of enabled connectors. */
11039 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
11041 struct drm_crtc
*new_crtc
;
11043 if (!connector
->new_encoder
)
11046 new_crtc
= connector
->new_encoder
->base
.crtc
;
11048 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
11049 if (set
->connectors
[ro
] == &connector
->base
)
11050 new_crtc
= set
->crtc
;
11053 /* Make sure the new CRTC will work with the encoder */
11054 if (!drm_encoder_crtc_ok(&connector
->new_encoder
->base
,
11058 connector
->new_encoder
->new_crtc
= to_intel_crtc(new_crtc
);
11060 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
11061 connector
->base
.base
.id
,
11062 connector
->base
.name
,
11063 new_crtc
->base
.id
);
11066 /* Check for any encoders that needs to be disabled. */
11067 for_each_intel_encoder(dev
, encoder
) {
11068 int num_connectors
= 0;
11069 list_for_each_entry(connector
,
11070 &dev
->mode_config
.connector_list
,
11072 if (connector
->new_encoder
== encoder
) {
11073 WARN_ON(!connector
->new_encoder
->new_crtc
);
11078 if (num_connectors
== 0)
11079 encoder
->new_crtc
= NULL
;
11080 else if (num_connectors
> 1)
11083 /* Only now check for crtc changes so we don't miss encoders
11084 * that will be disabled. */
11085 if (&encoder
->new_crtc
->base
!= encoder
->base
.crtc
) {
11086 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
11087 config
->mode_changed
= true;
11090 /* Now we've also updated encoder->new_crtc for all encoders. */
11091 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
11093 if (connector
->new_encoder
)
11094 if (connector
->new_encoder
!= connector
->encoder
)
11095 connector
->encoder
= connector
->new_encoder
;
11097 for_each_intel_crtc(dev
, crtc
) {
11098 crtc
->new_enabled
= false;
11100 for_each_intel_encoder(dev
, encoder
) {
11101 if (encoder
->new_crtc
== crtc
) {
11102 crtc
->new_enabled
= true;
11107 if (crtc
->new_enabled
!= crtc
->base
.enabled
) {
11108 DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
11109 crtc
->new_enabled
? "en" : "dis");
11110 config
->mode_changed
= true;
11113 if (crtc
->new_enabled
)
11114 crtc
->new_config
= &crtc
->config
;
11116 crtc
->new_config
= NULL
;
11122 static void disable_crtc_nofb(struct intel_crtc
*crtc
)
11124 struct drm_device
*dev
= crtc
->base
.dev
;
11125 struct intel_encoder
*encoder
;
11126 struct intel_connector
*connector
;
11128 DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
11129 pipe_name(crtc
->pipe
));
11131 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, base
.head
) {
11132 if (connector
->new_encoder
&&
11133 connector
->new_encoder
->new_crtc
== crtc
)
11134 connector
->new_encoder
= NULL
;
11137 for_each_intel_encoder(dev
, encoder
) {
11138 if (encoder
->new_crtc
== crtc
)
11139 encoder
->new_crtc
= NULL
;
11142 crtc
->new_enabled
= false;
11143 crtc
->new_config
= NULL
;
11146 static int intel_crtc_set_config(struct drm_mode_set
*set
)
11148 struct drm_device
*dev
;
11149 struct drm_mode_set save_set
;
11150 struct intel_set_config
*config
;
11154 BUG_ON(!set
->crtc
);
11155 BUG_ON(!set
->crtc
->helper_private
);
11157 /* Enforce sane interface api - has been abused by the fb helper. */
11158 BUG_ON(!set
->mode
&& set
->fb
);
11159 BUG_ON(set
->fb
&& set
->num_connectors
== 0);
11162 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
11163 set
->crtc
->base
.id
, set
->fb
->base
.id
,
11164 (int)set
->num_connectors
, set
->x
, set
->y
);
11166 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set
->crtc
->base
.id
);
11169 dev
= set
->crtc
->dev
;
11172 config
= kzalloc(sizeof(*config
), GFP_KERNEL
);
11176 ret
= intel_set_config_save_state(dev
, config
);
11180 save_set
.crtc
= set
->crtc
;
11181 save_set
.mode
= &set
->crtc
->mode
;
11182 save_set
.x
= set
->crtc
->x
;
11183 save_set
.y
= set
->crtc
->y
;
11184 save_set
.fb
= set
->crtc
->primary
->fb
;
11186 /* Compute whether we need a full modeset, only an fb base update or no
11187 * change at all. In the future we might also check whether only the
11188 * mode changed, e.g. for LVDS where we only change the panel fitter in
11190 intel_set_config_compute_mode_changes(set
, config
);
11192 ret
= intel_modeset_stage_output_state(dev
, set
, config
);
11196 if (config
->mode_changed
) {
11197 ret
= intel_set_mode(set
->crtc
, set
->mode
,
11198 set
->x
, set
->y
, set
->fb
);
11199 } else if (config
->fb_changed
) {
11200 struct intel_crtc
*intel_crtc
= to_intel_crtc(set
->crtc
);
11202 intel_crtc_wait_for_pending_flips(set
->crtc
);
11204 ret
= intel_pipe_set_base(set
->crtc
,
11205 set
->x
, set
->y
, set
->fb
);
11208 * We need to make sure the primary plane is re-enabled if it
11209 * has previously been turned off.
11211 if (!intel_crtc
->primary_enabled
&& ret
== 0) {
11212 WARN_ON(!intel_crtc
->active
);
11213 intel_enable_primary_hw_plane(set
->crtc
->primary
, set
->crtc
);
11217 * In the fastboot case this may be our only check of the
11218 * state after boot. It would be better to only do it on
11219 * the first update, but we don't have a nice way of doing that
11220 * (and really, set_config isn't used much for high freq page
11221 * flipping, so increasing its cost here shouldn't be a big
11224 if (i915
.fastboot
&& ret
== 0)
11225 intel_modeset_check_state(set
->crtc
->dev
);
11229 DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
11230 set
->crtc
->base
.id
, ret
);
11232 intel_set_config_restore_state(dev
, config
);
11235 * HACK: if the pipe was on, but we didn't have a framebuffer,
11236 * force the pipe off to avoid oopsing in the modeset code
11237 * due to fb==NULL. This should only happen during boot since
11238 * we don't yet reconstruct the FB from the hardware state.
11240 if (to_intel_crtc(save_set
.crtc
)->new_enabled
&& !save_set
.fb
)
11241 disable_crtc_nofb(to_intel_crtc(save_set
.crtc
));
11243 /* Try to restore the config */
11244 if (config
->mode_changed
&&
11245 intel_set_mode(save_set
.crtc
, save_set
.mode
,
11246 save_set
.x
, save_set
.y
, save_set
.fb
))
11247 DRM_ERROR("failed to restore config after modeset failure\n");
11251 intel_set_config_free(config
);
11255 static const struct drm_crtc_funcs intel_crtc_funcs
= {
11256 .gamma_set
= intel_crtc_gamma_set
,
11257 .set_config
= intel_crtc_set_config
,
11258 .destroy
= intel_crtc_destroy
,
11259 .page_flip
= intel_crtc_page_flip
,
11262 static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private
*dev_priv
,
11263 struct intel_shared_dpll
*pll
,
11264 struct intel_dpll_hw_state
*hw_state
)
11268 if (!intel_display_power_is_enabled(dev_priv
, POWER_DOMAIN_PLLS
))
11271 val
= I915_READ(PCH_DPLL(pll
->id
));
11272 hw_state
->dpll
= val
;
11273 hw_state
->fp0
= I915_READ(PCH_FP0(pll
->id
));
11274 hw_state
->fp1
= I915_READ(PCH_FP1(pll
->id
));
11276 return val
& DPLL_VCO_ENABLE
;
11279 static void ibx_pch_dpll_mode_set(struct drm_i915_private
*dev_priv
,
11280 struct intel_shared_dpll
*pll
)
11282 I915_WRITE(PCH_FP0(pll
->id
), pll
->hw_state
.fp0
);
11283 I915_WRITE(PCH_FP1(pll
->id
), pll
->hw_state
.fp1
);
11286 static void ibx_pch_dpll_enable(struct drm_i915_private
*dev_priv
,
11287 struct intel_shared_dpll
*pll
)
11289 /* PCH refclock must be enabled first */
11290 ibx_assert_pch_refclk_enabled(dev_priv
);
11292 I915_WRITE(PCH_DPLL(pll
->id
), pll
->hw_state
.dpll
);
11294 /* Wait for the clocks to stabilize. */
11295 POSTING_READ(PCH_DPLL(pll
->id
));
11298 /* The pixel multiplier can only be updated once the
11299 * DPLL is enabled and the clocks are stable.
11301 * So write it again.
11303 I915_WRITE(PCH_DPLL(pll
->id
), pll
->hw_state
.dpll
);
11304 POSTING_READ(PCH_DPLL(pll
->id
));
11308 static void ibx_pch_dpll_disable(struct drm_i915_private
*dev_priv
,
11309 struct intel_shared_dpll
*pll
)
11311 struct drm_device
*dev
= dev_priv
->dev
;
11312 struct intel_crtc
*crtc
;
11314 /* Make sure no transcoder isn't still depending on us. */
11315 for_each_intel_crtc(dev
, crtc
) {
11316 if (intel_crtc_to_shared_dpll(crtc
) == pll
)
11317 assert_pch_transcoder_disabled(dev_priv
, crtc
->pipe
);
11320 I915_WRITE(PCH_DPLL(pll
->id
), 0);
11321 POSTING_READ(PCH_DPLL(pll
->id
));
11325 static char *ibx_pch_dpll_names
[] = {
11330 static void ibx_pch_dpll_init(struct drm_device
*dev
)
11332 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11335 dev_priv
->num_shared_dpll
= 2;
11337 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
11338 dev_priv
->shared_dplls
[i
].id
= i
;
11339 dev_priv
->shared_dplls
[i
].name
= ibx_pch_dpll_names
[i
];
11340 dev_priv
->shared_dplls
[i
].mode_set
= ibx_pch_dpll_mode_set
;
11341 dev_priv
->shared_dplls
[i
].enable
= ibx_pch_dpll_enable
;
11342 dev_priv
->shared_dplls
[i
].disable
= ibx_pch_dpll_disable
;
11343 dev_priv
->shared_dplls
[i
].get_hw_state
=
11344 ibx_pch_dpll_get_hw_state
;
11348 static void intel_shared_dpll_init(struct drm_device
*dev
)
11350 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11353 intel_ddi_pll_init(dev
);
11354 else if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
11355 ibx_pch_dpll_init(dev
);
11357 dev_priv
->num_shared_dpll
= 0;
11359 BUG_ON(dev_priv
->num_shared_dpll
> I915_NUM_PLLS
);
11363 intel_primary_plane_disable(struct drm_plane
*plane
)
11365 struct drm_device
*dev
= plane
->dev
;
11366 struct intel_crtc
*intel_crtc
;
11371 BUG_ON(!plane
->crtc
);
11373 intel_crtc
= to_intel_crtc(plane
->crtc
);
11376 * Even though we checked plane->fb above, it's still possible that
11377 * the primary plane has been implicitly disabled because the crtc
11378 * coordinates given weren't visible, or because we detected
11379 * that it was 100% covered by a sprite plane. Or, the CRTC may be
11380 * off and we've set a fb, but haven't actually turned on the CRTC yet.
11381 * In either case, we need to unpin the FB and let the fb pointer get
11382 * updated, but otherwise we don't need to touch the hardware.
11384 if (!intel_crtc
->primary_enabled
)
11385 goto disable_unpin
;
11387 intel_crtc_wait_for_pending_flips(plane
->crtc
);
11388 intel_disable_primary_hw_plane(plane
, plane
->crtc
);
11391 mutex_lock(&dev
->struct_mutex
);
11392 i915_gem_track_fb(intel_fb_obj(plane
->fb
), NULL
,
11393 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
11394 intel_unpin_fb_obj(intel_fb_obj(plane
->fb
));
11395 mutex_unlock(&dev
->struct_mutex
);
11402 intel_check_primary_plane(struct drm_plane
*plane
,
11403 struct intel_plane_state
*state
)
11405 struct drm_crtc
*crtc
= state
->crtc
;
11406 struct drm_framebuffer
*fb
= state
->fb
;
11407 struct drm_rect
*dest
= &state
->dst
;
11408 struct drm_rect
*src
= &state
->src
;
11409 const struct drm_rect
*clip
= &state
->clip
;
11411 return drm_plane_helper_check_update(plane
, crtc
, fb
,
11413 DRM_PLANE_HELPER_NO_SCALING
,
11414 DRM_PLANE_HELPER_NO_SCALING
,
11415 false, true, &state
->visible
);
11419 intel_prepare_primary_plane(struct drm_plane
*plane
,
11420 struct intel_plane_state
*state
)
11422 struct drm_crtc
*crtc
= state
->crtc
;
11423 struct drm_framebuffer
*fb
= state
->fb
;
11424 struct drm_device
*dev
= crtc
->dev
;
11425 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11426 enum pipe pipe
= intel_crtc
->pipe
;
11427 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
11428 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->fb
);
11431 intel_crtc_wait_for_pending_flips(crtc
);
11433 if (intel_crtc_has_pending_flip(crtc
)) {
11434 DRM_ERROR("pipe is still busy with an old pageflip\n");
11438 if (old_obj
!= obj
) {
11439 mutex_lock(&dev
->struct_mutex
);
11440 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, NULL
);
11442 i915_gem_track_fb(old_obj
, obj
,
11443 INTEL_FRONTBUFFER_PRIMARY(pipe
));
11444 mutex_unlock(&dev
->struct_mutex
);
11446 DRM_DEBUG_KMS("pin & fence failed\n");
11455 intel_commit_primary_plane(struct drm_plane
*plane
,
11456 struct intel_plane_state
*state
)
11458 struct drm_crtc
*crtc
= state
->crtc
;
11459 struct drm_framebuffer
*fb
= state
->fb
;
11460 struct drm_device
*dev
= crtc
->dev
;
11461 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11462 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11463 enum pipe pipe
= intel_crtc
->pipe
;
11464 struct drm_framebuffer
*old_fb
= plane
->fb
;
11465 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
11466 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->fb
);
11467 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
11468 struct drm_rect
*src
= &state
->src
;
11470 crtc
->primary
->fb
= fb
;
11474 intel_plane
->crtc_x
= state
->orig_dst
.x1
;
11475 intel_plane
->crtc_y
= state
->orig_dst
.y1
;
11476 intel_plane
->crtc_w
= drm_rect_width(&state
->orig_dst
);
11477 intel_plane
->crtc_h
= drm_rect_height(&state
->orig_dst
);
11478 intel_plane
->src_x
= state
->orig_src
.x1
;
11479 intel_plane
->src_y
= state
->orig_src
.y1
;
11480 intel_plane
->src_w
= drm_rect_width(&state
->orig_src
);
11481 intel_plane
->src_h
= drm_rect_height(&state
->orig_src
);
11482 intel_plane
->obj
= obj
;
11484 if (intel_crtc
->active
) {
11486 * FBC does not work on some platforms for rotated
11487 * planes, so disable it when rotation is not 0 and
11488 * update it when rotation is set back to 0.
11490 * FIXME: This is redundant with the fbc update done in
11491 * the primary plane enable function except that that
11492 * one is done too late. We eventually need to unify
11495 if (intel_crtc
->primary_enabled
&&
11496 INTEL_INFO(dev
)->gen
<= 4 && !IS_G4X(dev
) &&
11497 dev_priv
->fbc
.plane
== intel_crtc
->plane
&&
11498 intel_plane
->rotation
!= BIT(DRM_ROTATE_0
)) {
11499 intel_disable_fbc(dev
);
11502 if (state
->visible
) {
11503 bool was_enabled
= intel_crtc
->primary_enabled
;
11505 /* FIXME: kill this fastboot hack */
11506 intel_update_pipe_size(intel_crtc
);
11508 intel_crtc
->primary_enabled
= true;
11510 dev_priv
->display
.update_primary_plane(crtc
, plane
->fb
,
11514 * BDW signals flip done immediately if the plane
11515 * is disabled, even if the plane enable is already
11516 * armed to occur at the next vblank :(
11518 if (IS_BROADWELL(dev
) && !was_enabled
)
11519 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
11522 * If clipping results in a non-visible primary plane,
11523 * we'll disable the primary plane. Note that this is
11524 * a bit different than what happens if userspace
11525 * explicitly disables the plane by passing fb=0
11526 * because plane->fb still gets set and pinned.
11528 intel_disable_primary_hw_plane(plane
, crtc
);
11531 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
11533 mutex_lock(&dev
->struct_mutex
);
11534 intel_update_fbc(dev
);
11535 mutex_unlock(&dev
->struct_mutex
);
11538 if (old_fb
&& old_fb
!= fb
) {
11539 if (intel_crtc
->active
)
11540 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
11542 mutex_lock(&dev
->struct_mutex
);
11543 intel_unpin_fb_obj(old_obj
);
11544 mutex_unlock(&dev
->struct_mutex
);
11549 intel_primary_plane_setplane(struct drm_plane
*plane
, struct drm_crtc
*crtc
,
11550 struct drm_framebuffer
*fb
, int crtc_x
, int crtc_y
,
11551 unsigned int crtc_w
, unsigned int crtc_h
,
11552 uint32_t src_x
, uint32_t src_y
,
11553 uint32_t src_w
, uint32_t src_h
)
11555 struct intel_plane_state state
;
11556 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11562 /* sample coordinates in 16.16 fixed point */
11563 state
.src
.x1
= src_x
;
11564 state
.src
.x2
= src_x
+ src_w
;
11565 state
.src
.y1
= src_y
;
11566 state
.src
.y2
= src_y
+ src_h
;
11568 /* integer pixels */
11569 state
.dst
.x1
= crtc_x
;
11570 state
.dst
.x2
= crtc_x
+ crtc_w
;
11571 state
.dst
.y1
= crtc_y
;
11572 state
.dst
.y2
= crtc_y
+ crtc_h
;
11576 state
.clip
.x2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_w
: 0;
11577 state
.clip
.y2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_h
: 0;
11579 state
.orig_src
= state
.src
;
11580 state
.orig_dst
= state
.dst
;
11582 ret
= intel_check_primary_plane(plane
, &state
);
11586 ret
= intel_prepare_primary_plane(plane
, &state
);
11590 intel_commit_primary_plane(plane
, &state
);
11595 /* Common destruction function for both primary and cursor planes */
11596 static void intel_plane_destroy(struct drm_plane
*plane
)
11598 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
11599 drm_plane_cleanup(plane
);
11600 kfree(intel_plane
);
11603 static const struct drm_plane_funcs intel_primary_plane_funcs
= {
11604 .update_plane
= intel_primary_plane_setplane
,
11605 .disable_plane
= intel_primary_plane_disable
,
11606 .destroy
= intel_plane_destroy
,
11607 .set_property
= intel_plane_set_property
11610 static struct drm_plane
*intel_primary_plane_create(struct drm_device
*dev
,
11613 struct intel_plane
*primary
;
11614 const uint32_t *intel_primary_formats
;
11617 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
11618 if (primary
== NULL
)
11621 primary
->can_scale
= false;
11622 primary
->max_downscale
= 1;
11623 primary
->pipe
= pipe
;
11624 primary
->plane
= pipe
;
11625 primary
->rotation
= BIT(DRM_ROTATE_0
);
11626 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4)
11627 primary
->plane
= !pipe
;
11629 if (INTEL_INFO(dev
)->gen
<= 3) {
11630 intel_primary_formats
= intel_primary_formats_gen2
;
11631 num_formats
= ARRAY_SIZE(intel_primary_formats_gen2
);
11633 intel_primary_formats
= intel_primary_formats_gen4
;
11634 num_formats
= ARRAY_SIZE(intel_primary_formats_gen4
);
11637 drm_universal_plane_init(dev
, &primary
->base
, 0,
11638 &intel_primary_plane_funcs
,
11639 intel_primary_formats
, num_formats
,
11640 DRM_PLANE_TYPE_PRIMARY
);
11642 if (INTEL_INFO(dev
)->gen
>= 4) {
11643 if (!dev
->mode_config
.rotation_property
)
11644 dev
->mode_config
.rotation_property
=
11645 drm_mode_create_rotation_property(dev
,
11646 BIT(DRM_ROTATE_0
) |
11647 BIT(DRM_ROTATE_180
));
11648 if (dev
->mode_config
.rotation_property
)
11649 drm_object_attach_property(&primary
->base
.base
,
11650 dev
->mode_config
.rotation_property
,
11651 primary
->rotation
);
11654 return &primary
->base
;
11658 intel_cursor_plane_disable(struct drm_plane
*plane
)
11663 BUG_ON(!plane
->crtc
);
11665 return intel_crtc_cursor_set_obj(plane
->crtc
, NULL
, 0, 0);
11669 intel_check_cursor_plane(struct drm_plane
*plane
,
11670 struct intel_plane_state
*state
)
11672 struct drm_crtc
*crtc
= state
->crtc
;
11673 struct drm_device
*dev
= crtc
->dev
;
11674 struct drm_framebuffer
*fb
= state
->fb
;
11675 struct drm_rect
*dest
= &state
->dst
;
11676 struct drm_rect
*src
= &state
->src
;
11677 const struct drm_rect
*clip
= &state
->clip
;
11678 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
11679 int crtc_w
, crtc_h
;
11683 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
11685 DRM_PLANE_HELPER_NO_SCALING
,
11686 DRM_PLANE_HELPER_NO_SCALING
,
11687 true, true, &state
->visible
);
11692 /* if we want to turn off the cursor ignore width and height */
11696 /* Check for which cursor types we support */
11697 crtc_w
= drm_rect_width(&state
->orig_dst
);
11698 crtc_h
= drm_rect_height(&state
->orig_dst
);
11699 if (!cursor_size_ok(dev
, crtc_w
, crtc_h
)) {
11700 DRM_DEBUG("Cursor dimension not supported\n");
11704 stride
= roundup_pow_of_two(crtc_w
) * 4;
11705 if (obj
->base
.size
< stride
* crtc_h
) {
11706 DRM_DEBUG_KMS("buffer is too small\n");
11710 if (fb
== crtc
->cursor
->fb
)
11713 /* we only need to pin inside GTT if cursor is non-phy */
11714 mutex_lock(&dev
->struct_mutex
);
11715 if (!INTEL_INFO(dev
)->cursor_needs_physical
&& obj
->tiling_mode
) {
11716 DRM_DEBUG_KMS("cursor cannot be tiled\n");
11719 mutex_unlock(&dev
->struct_mutex
);
11725 intel_commit_cursor_plane(struct drm_plane
*plane
,
11726 struct intel_plane_state
*state
)
11728 struct drm_crtc
*crtc
= state
->crtc
;
11729 struct drm_framebuffer
*fb
= state
->fb
;
11730 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11731 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
11732 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
11733 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
11734 int crtc_w
, crtc_h
;
11736 crtc
->cursor_x
= state
->orig_dst
.x1
;
11737 crtc
->cursor_y
= state
->orig_dst
.y1
;
11739 intel_plane
->crtc_x
= state
->orig_dst
.x1
;
11740 intel_plane
->crtc_y
= state
->orig_dst
.y1
;
11741 intel_plane
->crtc_w
= drm_rect_width(&state
->orig_dst
);
11742 intel_plane
->crtc_h
= drm_rect_height(&state
->orig_dst
);
11743 intel_plane
->src_x
= state
->orig_src
.x1
;
11744 intel_plane
->src_y
= state
->orig_src
.y1
;
11745 intel_plane
->src_w
= drm_rect_width(&state
->orig_src
);
11746 intel_plane
->src_h
= drm_rect_height(&state
->orig_src
);
11747 intel_plane
->obj
= obj
;
11749 if (fb
!= crtc
->cursor
->fb
) {
11750 crtc_w
= drm_rect_width(&state
->orig_dst
);
11751 crtc_h
= drm_rect_height(&state
->orig_dst
);
11752 return intel_crtc_cursor_set_obj(crtc
, obj
, crtc_w
, crtc_h
);
11754 intel_crtc_update_cursor(crtc
, state
->visible
);
11756 intel_frontbuffer_flip(crtc
->dev
,
11757 INTEL_FRONTBUFFER_CURSOR(intel_crtc
->pipe
));
11764 intel_cursor_plane_update(struct drm_plane
*plane
, struct drm_crtc
*crtc
,
11765 struct drm_framebuffer
*fb
, int crtc_x
, int crtc_y
,
11766 unsigned int crtc_w
, unsigned int crtc_h
,
11767 uint32_t src_x
, uint32_t src_y
,
11768 uint32_t src_w
, uint32_t src_h
)
11770 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11771 struct intel_plane_state state
;
11777 /* sample coordinates in 16.16 fixed point */
11778 state
.src
.x1
= src_x
;
11779 state
.src
.x2
= src_x
+ src_w
;
11780 state
.src
.y1
= src_y
;
11781 state
.src
.y2
= src_y
+ src_h
;
11783 /* integer pixels */
11784 state
.dst
.x1
= crtc_x
;
11785 state
.dst
.x2
= crtc_x
+ crtc_w
;
11786 state
.dst
.y1
= crtc_y
;
11787 state
.dst
.y2
= crtc_y
+ crtc_h
;
11791 state
.clip
.x2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_w
: 0;
11792 state
.clip
.y2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_h
: 0;
11794 state
.orig_src
= state
.src
;
11795 state
.orig_dst
= state
.dst
;
11797 ret
= intel_check_cursor_plane(plane
, &state
);
11801 return intel_commit_cursor_plane(plane
, &state
);
11804 static const struct drm_plane_funcs intel_cursor_plane_funcs
= {
11805 .update_plane
= intel_cursor_plane_update
,
11806 .disable_plane
= intel_cursor_plane_disable
,
11807 .destroy
= intel_plane_destroy
,
11808 .set_property
= intel_plane_set_property
,
11811 static struct drm_plane
*intel_cursor_plane_create(struct drm_device
*dev
,
11814 struct intel_plane
*cursor
;
11816 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
11817 if (cursor
== NULL
)
11820 cursor
->can_scale
= false;
11821 cursor
->max_downscale
= 1;
11822 cursor
->pipe
= pipe
;
11823 cursor
->plane
= pipe
;
11824 cursor
->rotation
= BIT(DRM_ROTATE_0
);
11826 drm_universal_plane_init(dev
, &cursor
->base
, 0,
11827 &intel_cursor_plane_funcs
,
11828 intel_cursor_formats
,
11829 ARRAY_SIZE(intel_cursor_formats
),
11830 DRM_PLANE_TYPE_CURSOR
);
11832 if (INTEL_INFO(dev
)->gen
>= 4) {
11833 if (!dev
->mode_config
.rotation_property
)
11834 dev
->mode_config
.rotation_property
=
11835 drm_mode_create_rotation_property(dev
,
11836 BIT(DRM_ROTATE_0
) |
11837 BIT(DRM_ROTATE_180
));
11838 if (dev
->mode_config
.rotation_property
)
11839 drm_object_attach_property(&cursor
->base
.base
,
11840 dev
->mode_config
.rotation_property
,
11844 return &cursor
->base
;
11847 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
11849 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11850 struct intel_crtc
*intel_crtc
;
11851 struct drm_plane
*primary
= NULL
;
11852 struct drm_plane
*cursor
= NULL
;
11855 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
11856 if (intel_crtc
== NULL
)
11859 primary
= intel_primary_plane_create(dev
, pipe
);
11863 cursor
= intel_cursor_plane_create(dev
, pipe
);
11867 ret
= drm_crtc_init_with_planes(dev
, &intel_crtc
->base
, primary
,
11868 cursor
, &intel_crtc_funcs
);
11872 drm_mode_crtc_set_gamma_size(&intel_crtc
->base
, 256);
11873 for (i
= 0; i
< 256; i
++) {
11874 intel_crtc
->lut_r
[i
] = i
;
11875 intel_crtc
->lut_g
[i
] = i
;
11876 intel_crtc
->lut_b
[i
] = i
;
11880 * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
11881 * is hooked to pipe B. Hence we want plane A feeding pipe B.
11883 intel_crtc
->pipe
= pipe
;
11884 intel_crtc
->plane
= pipe
;
11885 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4) {
11886 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
11887 intel_crtc
->plane
= !pipe
;
11890 intel_crtc
->cursor_base
= ~0;
11891 intel_crtc
->cursor_cntl
= ~0;
11892 intel_crtc
->cursor_size
= ~0;
11894 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
11895 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
11896 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
11897 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
11899 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
11901 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
11906 drm_plane_cleanup(primary
);
11908 drm_plane_cleanup(cursor
);
11912 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
11914 struct drm_encoder
*encoder
= connector
->base
.encoder
;
11915 struct drm_device
*dev
= connector
->base
.dev
;
11917 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
11920 return INVALID_PIPE
;
11922 return to_intel_crtc(encoder
->crtc
)->pipe
;
11925 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
11926 struct drm_file
*file
)
11928 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
11929 struct drm_crtc
*drmmode_crtc
;
11930 struct intel_crtc
*crtc
;
11932 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
11935 drmmode_crtc
= drm_crtc_find(dev
, pipe_from_crtc_id
->crtc_id
);
11937 if (!drmmode_crtc
) {
11938 DRM_ERROR("no such CRTC id\n");
11942 crtc
= to_intel_crtc(drmmode_crtc
);
11943 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
11948 static int intel_encoder_clones(struct intel_encoder
*encoder
)
11950 struct drm_device
*dev
= encoder
->base
.dev
;
11951 struct intel_encoder
*source_encoder
;
11952 int index_mask
= 0;
11955 for_each_intel_encoder(dev
, source_encoder
) {
11956 if (encoders_cloneable(encoder
, source_encoder
))
11957 index_mask
|= (1 << entry
);
11965 static bool has_edp_a(struct drm_device
*dev
)
11967 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11969 if (!IS_MOBILE(dev
))
11972 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
11975 if (IS_GEN5(dev
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
11981 const char *intel_output_name(int output
)
11983 static const char *names
[] = {
11984 [INTEL_OUTPUT_UNUSED
] = "Unused",
11985 [INTEL_OUTPUT_ANALOG
] = "Analog",
11986 [INTEL_OUTPUT_DVO
] = "DVO",
11987 [INTEL_OUTPUT_SDVO
] = "SDVO",
11988 [INTEL_OUTPUT_LVDS
] = "LVDS",
11989 [INTEL_OUTPUT_TVOUT
] = "TV",
11990 [INTEL_OUTPUT_HDMI
] = "HDMI",
11991 [INTEL_OUTPUT_DISPLAYPORT
] = "DisplayPort",
11992 [INTEL_OUTPUT_EDP
] = "eDP",
11993 [INTEL_OUTPUT_DSI
] = "DSI",
11994 [INTEL_OUTPUT_UNKNOWN
] = "Unknown",
11997 if (output
< 0 || output
>= ARRAY_SIZE(names
) || !names
[output
])
12000 return names
[output
];
12003 static bool intel_crt_present(struct drm_device
*dev
)
12005 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12007 if (INTEL_INFO(dev
)->gen
>= 9)
12010 if (IS_HSW_ULT(dev
) || IS_BDW_ULT(dev
))
12013 if (IS_CHERRYVIEW(dev
))
12016 if (IS_VALLEYVIEW(dev
) && !dev_priv
->vbt
.int_crt_support
)
12022 static void intel_setup_outputs(struct drm_device
*dev
)
12024 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12025 struct intel_encoder
*encoder
;
12026 bool dpd_is_edp
= false;
12028 intel_lvds_init(dev
);
12030 if (intel_crt_present(dev
))
12031 intel_crt_init(dev
);
12033 if (HAS_DDI(dev
)) {
12036 /* Haswell uses DDI functions to detect digital outputs */
12037 found
= I915_READ(DDI_BUF_CTL_A
) & DDI_INIT_DISPLAY_DETECTED
;
12038 /* DDI A only supports eDP */
12040 intel_ddi_init(dev
, PORT_A
);
12042 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
12044 found
= I915_READ(SFUSE_STRAP
);
12046 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
12047 intel_ddi_init(dev
, PORT_B
);
12048 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
12049 intel_ddi_init(dev
, PORT_C
);
12050 if (found
& SFUSE_STRAP_DDID_DETECTED
)
12051 intel_ddi_init(dev
, PORT_D
);
12052 } else if (HAS_PCH_SPLIT(dev
)) {
12054 dpd_is_edp
= intel_dp_is_edp(dev
, PORT_D
);
12056 if (has_edp_a(dev
))
12057 intel_dp_init(dev
, DP_A
, PORT_A
);
12059 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
12060 /* PCH SDVOB multiplex with HDMIB */
12061 found
= intel_sdvo_init(dev
, PCH_SDVOB
, true);
12063 intel_hdmi_init(dev
, PCH_HDMIB
, PORT_B
);
12064 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
12065 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
12068 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
12069 intel_hdmi_init(dev
, PCH_HDMIC
, PORT_C
);
12071 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
12072 intel_hdmi_init(dev
, PCH_HDMID
, PORT_D
);
12074 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
12075 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
12077 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
12078 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
12079 } else if (IS_VALLEYVIEW(dev
)) {
12081 * The DP_DETECTED bit is the latched state of the DDC
12082 * SDA pin at boot. However since eDP doesn't require DDC
12083 * (no way to plug in a DP->HDMI dongle) the DDC pins for
12084 * eDP ports may have been muxed to an alternate function.
12085 * Thus we can't rely on the DP_DETECTED bit alone to detect
12086 * eDP ports. Consult the VBT as well as DP_DETECTED to
12087 * detect eDP ports.
12089 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIB
) & SDVO_DETECTED
)
12090 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIB
,
12092 if (I915_READ(VLV_DISPLAY_BASE
+ DP_B
) & DP_DETECTED
||
12093 intel_dp_is_edp(dev
, PORT_B
))
12094 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_B
, PORT_B
);
12096 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIC
) & SDVO_DETECTED
)
12097 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIC
,
12099 if (I915_READ(VLV_DISPLAY_BASE
+ DP_C
) & DP_DETECTED
||
12100 intel_dp_is_edp(dev
, PORT_C
))
12101 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_C
, PORT_C
);
12103 if (IS_CHERRYVIEW(dev
)) {
12104 if (I915_READ(VLV_DISPLAY_BASE
+ CHV_HDMID
) & SDVO_DETECTED
)
12105 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ CHV_HDMID
,
12107 /* eDP not supported on port D, so don't check VBT */
12108 if (I915_READ(VLV_DISPLAY_BASE
+ DP_D
) & DP_DETECTED
)
12109 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_D
, PORT_D
);
12112 intel_dsi_init(dev
);
12113 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev
)) {
12114 bool found
= false;
12116 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
12117 DRM_DEBUG_KMS("probing SDVOB\n");
12118 found
= intel_sdvo_init(dev
, GEN3_SDVOB
, true);
12119 if (!found
&& SUPPORTS_INTEGRATED_HDMI(dev
)) {
12120 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
12121 intel_hdmi_init(dev
, GEN4_HDMIB
, PORT_B
);
12124 if (!found
&& SUPPORTS_INTEGRATED_DP(dev
))
12125 intel_dp_init(dev
, DP_B
, PORT_B
);
12128 /* Before G4X SDVOC doesn't have its own detect register */
12130 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
12131 DRM_DEBUG_KMS("probing SDVOC\n");
12132 found
= intel_sdvo_init(dev
, GEN3_SDVOC
, false);
12135 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
12137 if (SUPPORTS_INTEGRATED_HDMI(dev
)) {
12138 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
12139 intel_hdmi_init(dev
, GEN4_HDMIC
, PORT_C
);
12141 if (SUPPORTS_INTEGRATED_DP(dev
))
12142 intel_dp_init(dev
, DP_C
, PORT_C
);
12145 if (SUPPORTS_INTEGRATED_DP(dev
) &&
12146 (I915_READ(DP_D
) & DP_DETECTED
))
12147 intel_dp_init(dev
, DP_D
, PORT_D
);
12148 } else if (IS_GEN2(dev
))
12149 intel_dvo_init(dev
);
12151 if (SUPPORTS_TV(dev
))
12152 intel_tv_init(dev
);
12154 intel_edp_psr_init(dev
);
12156 for_each_intel_encoder(dev
, encoder
) {
12157 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
12158 encoder
->base
.possible_clones
=
12159 intel_encoder_clones(encoder
);
12162 intel_init_pch_refclk(dev
);
12164 drm_helper_move_panel_connectors_to_head(dev
);
12167 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
12169 struct drm_device
*dev
= fb
->dev
;
12170 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
12172 drm_framebuffer_cleanup(fb
);
12173 mutex_lock(&dev
->struct_mutex
);
12174 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
12175 drm_gem_object_unreference(&intel_fb
->obj
->base
);
12176 mutex_unlock(&dev
->struct_mutex
);
12180 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
12181 struct drm_file
*file
,
12182 unsigned int *handle
)
12184 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
12185 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
12187 return drm_gem_handle_create(file
, &obj
->base
, handle
);
12190 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
12191 .destroy
= intel_user_framebuffer_destroy
,
12192 .create_handle
= intel_user_framebuffer_create_handle
,
12195 static int intel_framebuffer_init(struct drm_device
*dev
,
12196 struct intel_framebuffer
*intel_fb
,
12197 struct drm_mode_fb_cmd2
*mode_cmd
,
12198 struct drm_i915_gem_object
*obj
)
12200 int aligned_height
;
12204 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
12206 if (obj
->tiling_mode
== I915_TILING_Y
) {
12207 DRM_DEBUG("hardware does not support tiling Y\n");
12211 if (mode_cmd
->pitches
[0] & 63) {
12212 DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
12213 mode_cmd
->pitches
[0]);
12217 if (INTEL_INFO(dev
)->gen
>= 5 && !IS_VALLEYVIEW(dev
)) {
12218 pitch_limit
= 32*1024;
12219 } else if (INTEL_INFO(dev
)->gen
>= 4) {
12220 if (obj
->tiling_mode
)
12221 pitch_limit
= 16*1024;
12223 pitch_limit
= 32*1024;
12224 } else if (INTEL_INFO(dev
)->gen
>= 3) {
12225 if (obj
->tiling_mode
)
12226 pitch_limit
= 8*1024;
12228 pitch_limit
= 16*1024;
12230 /* XXX DSPC is limited to 4k tiled */
12231 pitch_limit
= 8*1024;
12233 if (mode_cmd
->pitches
[0] > pitch_limit
) {
12234 DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
12235 obj
->tiling_mode
? "tiled" : "linear",
12236 mode_cmd
->pitches
[0], pitch_limit
);
12240 if (obj
->tiling_mode
!= I915_TILING_NONE
&&
12241 mode_cmd
->pitches
[0] != obj
->stride
) {
12242 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
12243 mode_cmd
->pitches
[0], obj
->stride
);
12247 /* Reject formats not supported by any plane early. */
12248 switch (mode_cmd
->pixel_format
) {
12249 case DRM_FORMAT_C8
:
12250 case DRM_FORMAT_RGB565
:
12251 case DRM_FORMAT_XRGB8888
:
12252 case DRM_FORMAT_ARGB8888
:
12254 case DRM_FORMAT_XRGB1555
:
12255 case DRM_FORMAT_ARGB1555
:
12256 if (INTEL_INFO(dev
)->gen
> 3) {
12257 DRM_DEBUG("unsupported pixel format: %s\n",
12258 drm_get_format_name(mode_cmd
->pixel_format
));
12262 case DRM_FORMAT_XBGR8888
:
12263 case DRM_FORMAT_ABGR8888
:
12264 case DRM_FORMAT_XRGB2101010
:
12265 case DRM_FORMAT_ARGB2101010
:
12266 case DRM_FORMAT_XBGR2101010
:
12267 case DRM_FORMAT_ABGR2101010
:
12268 if (INTEL_INFO(dev
)->gen
< 4) {
12269 DRM_DEBUG("unsupported pixel format: %s\n",
12270 drm_get_format_name(mode_cmd
->pixel_format
));
12274 case DRM_FORMAT_YUYV
:
12275 case DRM_FORMAT_UYVY
:
12276 case DRM_FORMAT_YVYU
:
12277 case DRM_FORMAT_VYUY
:
12278 if (INTEL_INFO(dev
)->gen
< 5) {
12279 DRM_DEBUG("unsupported pixel format: %s\n",
12280 drm_get_format_name(mode_cmd
->pixel_format
));
12285 DRM_DEBUG("unsupported pixel format: %s\n",
12286 drm_get_format_name(mode_cmd
->pixel_format
));
12290 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
12291 if (mode_cmd
->offsets
[0] != 0)
12294 aligned_height
= intel_align_height(dev
, mode_cmd
->height
,
12296 /* FIXME drm helper for size checks (especially planar formats)? */
12297 if (obj
->base
.size
< aligned_height
* mode_cmd
->pitches
[0])
12300 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
12301 intel_fb
->obj
= obj
;
12302 intel_fb
->obj
->framebuffer_references
++;
12304 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
12306 DRM_ERROR("framebuffer init failed %d\n", ret
);
12313 static struct drm_framebuffer
*
12314 intel_user_framebuffer_create(struct drm_device
*dev
,
12315 struct drm_file
*filp
,
12316 struct drm_mode_fb_cmd2
*mode_cmd
)
12318 struct drm_i915_gem_object
*obj
;
12320 obj
= to_intel_bo(drm_gem_object_lookup(dev
, filp
,
12321 mode_cmd
->handles
[0]));
12322 if (&obj
->base
== NULL
)
12323 return ERR_PTR(-ENOENT
);
12325 return intel_framebuffer_create(dev
, mode_cmd
, obj
);
12328 #ifndef CONFIG_DRM_I915_FBDEV
12329 static inline void intel_fbdev_output_poll_changed(struct drm_device
*dev
)
12334 static const struct drm_mode_config_funcs intel_mode_funcs
= {
12335 .fb_create
= intel_user_framebuffer_create
,
12336 .output_poll_changed
= intel_fbdev_output_poll_changed
,
12339 /* Set up chip specific display functions */
12340 static void intel_init_display(struct drm_device
*dev
)
12342 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12344 if (HAS_PCH_SPLIT(dev
) || IS_G4X(dev
))
12345 dev_priv
->display
.find_dpll
= g4x_find_best_dpll
;
12346 else if (IS_CHERRYVIEW(dev
))
12347 dev_priv
->display
.find_dpll
= chv_find_best_dpll
;
12348 else if (IS_VALLEYVIEW(dev
))
12349 dev_priv
->display
.find_dpll
= vlv_find_best_dpll
;
12350 else if (IS_PINEVIEW(dev
))
12351 dev_priv
->display
.find_dpll
= pnv_find_best_dpll
;
12353 dev_priv
->display
.find_dpll
= i9xx_find_best_dpll
;
12355 if (HAS_DDI(dev
)) {
12356 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
12357 dev_priv
->display
.get_plane_config
= ironlake_get_plane_config
;
12358 dev_priv
->display
.crtc_mode_set
= haswell_crtc_mode_set
;
12359 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
12360 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
12361 dev_priv
->display
.off
= ironlake_crtc_off
;
12362 if (INTEL_INFO(dev
)->gen
>= 9)
12363 dev_priv
->display
.update_primary_plane
=
12364 skylake_update_primary_plane
;
12366 dev_priv
->display
.update_primary_plane
=
12367 ironlake_update_primary_plane
;
12368 } else if (HAS_PCH_SPLIT(dev
)) {
12369 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
12370 dev_priv
->display
.get_plane_config
= ironlake_get_plane_config
;
12371 dev_priv
->display
.crtc_mode_set
= ironlake_crtc_mode_set
;
12372 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
12373 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
12374 dev_priv
->display
.off
= ironlake_crtc_off
;
12375 dev_priv
->display
.update_primary_plane
=
12376 ironlake_update_primary_plane
;
12377 } else if (IS_VALLEYVIEW(dev
)) {
12378 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
12379 dev_priv
->display
.get_plane_config
= i9xx_get_plane_config
;
12380 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
12381 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
12382 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
12383 dev_priv
->display
.off
= i9xx_crtc_off
;
12384 dev_priv
->display
.update_primary_plane
=
12385 i9xx_update_primary_plane
;
12387 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
12388 dev_priv
->display
.get_plane_config
= i9xx_get_plane_config
;
12389 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
12390 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
12391 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
12392 dev_priv
->display
.off
= i9xx_crtc_off
;
12393 dev_priv
->display
.update_primary_plane
=
12394 i9xx_update_primary_plane
;
12397 /* Returns the core display clock speed */
12398 if (IS_VALLEYVIEW(dev
))
12399 dev_priv
->display
.get_display_clock_speed
=
12400 valleyview_get_display_clock_speed
;
12401 else if (IS_I945G(dev
) || (IS_G33(dev
) && !IS_PINEVIEW_M(dev
)))
12402 dev_priv
->display
.get_display_clock_speed
=
12403 i945_get_display_clock_speed
;
12404 else if (IS_I915G(dev
))
12405 dev_priv
->display
.get_display_clock_speed
=
12406 i915_get_display_clock_speed
;
12407 else if (IS_I945GM(dev
) || IS_845G(dev
))
12408 dev_priv
->display
.get_display_clock_speed
=
12409 i9xx_misc_get_display_clock_speed
;
12410 else if (IS_PINEVIEW(dev
))
12411 dev_priv
->display
.get_display_clock_speed
=
12412 pnv_get_display_clock_speed
;
12413 else if (IS_I915GM(dev
))
12414 dev_priv
->display
.get_display_clock_speed
=
12415 i915gm_get_display_clock_speed
;
12416 else if (IS_I865G(dev
))
12417 dev_priv
->display
.get_display_clock_speed
=
12418 i865_get_display_clock_speed
;
12419 else if (IS_I85X(dev
))
12420 dev_priv
->display
.get_display_clock_speed
=
12421 i855_get_display_clock_speed
;
12422 else /* 852, 830 */
12423 dev_priv
->display
.get_display_clock_speed
=
12424 i830_get_display_clock_speed
;
12426 if (IS_GEN5(dev
)) {
12427 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
12428 } else if (IS_GEN6(dev
)) {
12429 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
12430 dev_priv
->display
.modeset_global_resources
=
12431 snb_modeset_global_resources
;
12432 } else if (IS_IVYBRIDGE(dev
)) {
12433 /* FIXME: detect B0+ stepping and use auto training */
12434 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
12435 dev_priv
->display
.modeset_global_resources
=
12436 ivb_modeset_global_resources
;
12437 } else if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
12438 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
12439 dev_priv
->display
.modeset_global_resources
=
12440 haswell_modeset_global_resources
;
12441 } else if (IS_VALLEYVIEW(dev
)) {
12442 dev_priv
->display
.modeset_global_resources
=
12443 valleyview_modeset_global_resources
;
12444 } else if (INTEL_INFO(dev
)->gen
>= 9) {
12445 dev_priv
->display
.modeset_global_resources
=
12446 haswell_modeset_global_resources
;
12449 /* Default just returns -ENODEV to indicate unsupported */
12450 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
12452 switch (INTEL_INFO(dev
)->gen
) {
12454 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
12458 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
12463 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
12467 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
12470 case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
12471 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
12475 intel_panel_init_backlight_funcs(dev
);
12477 mutex_init(&dev_priv
->pps_mutex
);
12481 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
12482 * resume, or other times. This quirk makes sure that's the case for
12483 * affected systems.
12485 static void quirk_pipea_force(struct drm_device
*dev
)
12487 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12489 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
12490 DRM_INFO("applying pipe a force quirk\n");
12493 static void quirk_pipeb_force(struct drm_device
*dev
)
12495 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12497 dev_priv
->quirks
|= QUIRK_PIPEB_FORCE
;
12498 DRM_INFO("applying pipe b force quirk\n");
12502 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
12504 static void quirk_ssc_force_disable(struct drm_device
*dev
)
12506 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12507 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
12508 DRM_INFO("applying lvds SSC disable quirk\n");
12512 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
12515 static void quirk_invert_brightness(struct drm_device
*dev
)
12517 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12518 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
12519 DRM_INFO("applying inverted panel brightness quirk\n");
12522 /* Some VBT's incorrectly indicate no backlight is present */
12523 static void quirk_backlight_present(struct drm_device
*dev
)
12525 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12526 dev_priv
->quirks
|= QUIRK_BACKLIGHT_PRESENT
;
12527 DRM_INFO("applying backlight present quirk\n");
12530 struct intel_quirk
{
12532 int subsystem_vendor
;
12533 int subsystem_device
;
12534 void (*hook
)(struct drm_device
*dev
);
12537 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
12538 struct intel_dmi_quirk
{
12539 void (*hook
)(struct drm_device
*dev
);
12540 const struct dmi_system_id (*dmi_id_list
)[];
12543 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
12545 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
12549 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
12551 .dmi_id_list
= &(const struct dmi_system_id
[]) {
12553 .callback
= intel_dmi_reverse_brightness
,
12554 .ident
= "NCR Corporation",
12555 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
12556 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
12559 { } /* terminating entry */
12561 .hook
= quirk_invert_brightness
,
12565 static struct intel_quirk intel_quirks
[] = {
12566 /* HP Mini needs pipe A force quirk (LP: #322104) */
12567 { 0x27ae, 0x103c, 0x361a, quirk_pipea_force
},
12569 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
12570 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
12572 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
12573 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
12575 /* 830 needs to leave pipe A & dpll A up */
12576 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
12578 /* 830 needs to leave pipe B & dpll B up */
12579 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipeb_force
},
12581 /* Lenovo U160 cannot use SSC on LVDS */
12582 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
12584 /* Sony Vaio Y cannot use SSC on LVDS */
12585 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
12587 /* Acer Aspire 5734Z must invert backlight brightness */
12588 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
12590 /* Acer/eMachines G725 */
12591 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
12593 /* Acer/eMachines e725 */
12594 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
12596 /* Acer/Packard Bell NCL20 */
12597 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
12599 /* Acer Aspire 4736Z */
12600 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
12602 /* Acer Aspire 5336 */
12603 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
12605 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
12606 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present
},
12608 /* Acer C720 Chromebook (Core i3 4005U) */
12609 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present
},
12611 /* Toshiba CB35 Chromebook (Celeron 2955U) */
12612 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present
},
12614 /* HP Chromebook 14 (Celeron 2955U) */
12615 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present
},
12618 static void intel_init_quirks(struct drm_device
*dev
)
12620 struct pci_dev
*d
= dev
->pdev
;
12623 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
12624 struct intel_quirk
*q
= &intel_quirks
[i
];
12626 if (d
->device
== q
->device
&&
12627 (d
->subsystem_vendor
== q
->subsystem_vendor
||
12628 q
->subsystem_vendor
== PCI_ANY_ID
) &&
12629 (d
->subsystem_device
== q
->subsystem_device
||
12630 q
->subsystem_device
== PCI_ANY_ID
))
12633 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
12634 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
12635 intel_dmi_quirks
[i
].hook(dev
);
12639 /* Disable the VGA plane that we never use */
12640 static void i915_disable_vga(struct drm_device
*dev
)
12642 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12644 u32 vga_reg
= i915_vgacntrl_reg(dev
);
12646 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
12647 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
12648 outb(SR01
, VGA_SR_INDEX
);
12649 sr1
= inb(VGA_SR_DATA
);
12650 outb(sr1
| 1<<5, VGA_SR_DATA
);
12651 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
12655 * Fujitsu-Siemens Lifebook S6010 (830) has problems resuming
12656 * from S3 without preserving (some of?) the other bits.
12658 I915_WRITE(vga_reg
, dev_priv
->bios_vgacntr
| VGA_DISP_DISABLE
);
12659 POSTING_READ(vga_reg
);
12662 void intel_modeset_init_hw(struct drm_device
*dev
)
12664 intel_prepare_ddi(dev
);
12666 if (IS_VALLEYVIEW(dev
))
12667 vlv_update_cdclk(dev
);
12669 intel_init_clock_gating(dev
);
12671 intel_enable_gt_powersave(dev
);
12674 void intel_modeset_init(struct drm_device
*dev
)
12676 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12679 struct intel_crtc
*crtc
;
12681 drm_mode_config_init(dev
);
12683 dev
->mode_config
.min_width
= 0;
12684 dev
->mode_config
.min_height
= 0;
12686 dev
->mode_config
.preferred_depth
= 24;
12687 dev
->mode_config
.prefer_shadow
= 1;
12689 dev
->mode_config
.funcs
= &intel_mode_funcs
;
12691 intel_init_quirks(dev
);
12693 intel_init_pm(dev
);
12695 if (INTEL_INFO(dev
)->num_pipes
== 0)
12698 intel_init_display(dev
);
12699 intel_init_audio(dev
);
12701 if (IS_GEN2(dev
)) {
12702 dev
->mode_config
.max_width
= 2048;
12703 dev
->mode_config
.max_height
= 2048;
12704 } else if (IS_GEN3(dev
)) {
12705 dev
->mode_config
.max_width
= 4096;
12706 dev
->mode_config
.max_height
= 4096;
12708 dev
->mode_config
.max_width
= 8192;
12709 dev
->mode_config
.max_height
= 8192;
12712 if (IS_845G(dev
) || IS_I865G(dev
)) {
12713 dev
->mode_config
.cursor_width
= IS_845G(dev
) ? 64 : 512;
12714 dev
->mode_config
.cursor_height
= 1023;
12715 } else if (IS_GEN2(dev
)) {
12716 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
12717 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
12719 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
12720 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
12723 dev
->mode_config
.fb_base
= dev_priv
->gtt
.mappable_base
;
12725 DRM_DEBUG_KMS("%d display pipe%s available.\n",
12726 INTEL_INFO(dev
)->num_pipes
,
12727 INTEL_INFO(dev
)->num_pipes
> 1 ? "s" : "");
12729 for_each_pipe(dev_priv
, pipe
) {
12730 intel_crtc_init(dev
, pipe
);
12731 for_each_sprite(pipe
, sprite
) {
12732 ret
= intel_plane_init(dev
, pipe
, sprite
);
12734 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
12735 pipe_name(pipe
), sprite_name(pipe
, sprite
), ret
);
12739 intel_init_dpio(dev
);
12741 intel_shared_dpll_init(dev
);
12743 /* save the BIOS value before clobbering it */
12744 dev_priv
->bios_vgacntr
= I915_READ(i915_vgacntrl_reg(dev
));
12745 /* Just disable it once at startup */
12746 i915_disable_vga(dev
);
12747 intel_setup_outputs(dev
);
12749 /* Just in case the BIOS is doing something questionable. */
12750 intel_disable_fbc(dev
);
12752 drm_modeset_lock_all(dev
);
12753 intel_modeset_setup_hw_state(dev
, false);
12754 drm_modeset_unlock_all(dev
);
12756 for_each_intel_crtc(dev
, crtc
) {
12761 * Note that reserving the BIOS fb up front prevents us
12762 * from stuffing other stolen allocations like the ring
12763 * on top. This prevents some ugliness at boot time, and
12764 * can even allow for smooth boot transitions if the BIOS
12765 * fb is large enough for the active pipe configuration.
12767 if (dev_priv
->display
.get_plane_config
) {
12768 dev_priv
->display
.get_plane_config(crtc
,
12769 &crtc
->plane_config
);
12771 * If the fb is shared between multiple heads, we'll
12772 * just get the first one.
12774 intel_find_plane_obj(crtc
, &crtc
->plane_config
);
12779 static void intel_enable_pipe_a(struct drm_device
*dev
)
12781 struct intel_connector
*connector
;
12782 struct drm_connector
*crt
= NULL
;
12783 struct intel_load_detect_pipe load_detect_temp
;
12784 struct drm_modeset_acquire_ctx
*ctx
= dev
->mode_config
.acquire_ctx
;
12786 /* We can't just switch on the pipe A, we need to set things up with a
12787 * proper mode and output configuration. As a gross hack, enable pipe A
12788 * by enabling the load detect pipe once. */
12789 list_for_each_entry(connector
,
12790 &dev
->mode_config
.connector_list
,
12792 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
12793 crt
= &connector
->base
;
12801 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
, ctx
))
12802 intel_release_load_detect_pipe(crt
, &load_detect_temp
);
12806 intel_check_plane_mapping(struct intel_crtc
*crtc
)
12808 struct drm_device
*dev
= crtc
->base
.dev
;
12809 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12812 if (INTEL_INFO(dev
)->num_pipes
== 1)
12815 reg
= DSPCNTR(!crtc
->plane
);
12816 val
= I915_READ(reg
);
12818 if ((val
& DISPLAY_PLANE_ENABLE
) &&
12819 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
12825 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
12827 struct drm_device
*dev
= crtc
->base
.dev
;
12828 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12831 /* Clear any frame start delays used for debugging left by the BIOS */
12832 reg
= PIPECONF(crtc
->config
.cpu_transcoder
);
12833 I915_WRITE(reg
, I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
12835 /* restore vblank interrupts to correct state */
12836 if (crtc
->active
) {
12837 update_scanline_offset(crtc
);
12838 drm_vblank_on(dev
, crtc
->pipe
);
12840 drm_vblank_off(dev
, crtc
->pipe
);
12842 /* We need to sanitize the plane -> pipe mapping first because this will
12843 * disable the crtc (and hence change the state) if it is wrong. Note
12844 * that gen4+ has a fixed plane -> pipe mapping. */
12845 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
12846 struct intel_connector
*connector
;
12849 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
12850 crtc
->base
.base
.id
);
12852 /* Pipe has the wrong plane attached and the plane is active.
12853 * Temporarily change the plane mapping and disable everything
12855 plane
= crtc
->plane
;
12856 crtc
->plane
= !plane
;
12857 crtc
->primary_enabled
= true;
12858 dev_priv
->display
.crtc_disable(&crtc
->base
);
12859 crtc
->plane
= plane
;
12861 /* ... and break all links. */
12862 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
12864 if (connector
->encoder
->base
.crtc
!= &crtc
->base
)
12867 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
12868 connector
->base
.encoder
= NULL
;
12870 /* multiple connectors may have the same encoder:
12871 * handle them and break crtc link separately */
12872 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
12874 if (connector
->encoder
->base
.crtc
== &crtc
->base
) {
12875 connector
->encoder
->base
.crtc
= NULL
;
12876 connector
->encoder
->connectors_active
= false;
12879 WARN_ON(crtc
->active
);
12880 crtc
->base
.enabled
= false;
12883 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
12884 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
12885 /* BIOS forgot to enable pipe A, this mostly happens after
12886 * resume. Force-enable the pipe to fix this, the update_dpms
12887 * call below we restore the pipe to the right state, but leave
12888 * the required bits on. */
12889 intel_enable_pipe_a(dev
);
12892 /* Adjust the state of the output pipe according to whether we
12893 * have active connectors/encoders. */
12894 intel_crtc_update_dpms(&crtc
->base
);
12896 if (crtc
->active
!= crtc
->base
.enabled
) {
12897 struct intel_encoder
*encoder
;
12899 /* This can happen either due to bugs in the get_hw_state
12900 * functions or because the pipe is force-enabled due to the
12902 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
12903 crtc
->base
.base
.id
,
12904 crtc
->base
.enabled
? "enabled" : "disabled",
12905 crtc
->active
? "enabled" : "disabled");
12907 crtc
->base
.enabled
= crtc
->active
;
12909 /* Because we only establish the connector -> encoder ->
12910 * crtc links if something is active, this means the
12911 * crtc is now deactivated. Break the links. connector
12912 * -> encoder links are only establish when things are
12913 * actually up, hence no need to break them. */
12914 WARN_ON(crtc
->active
);
12916 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
12917 WARN_ON(encoder
->connectors_active
);
12918 encoder
->base
.crtc
= NULL
;
12922 if (crtc
->active
|| HAS_GMCH_DISPLAY(dev
)) {
12924 * We start out with underrun reporting disabled to avoid races.
12925 * For correct bookkeeping mark this on active crtcs.
12927 * Also on gmch platforms we dont have any hardware bits to
12928 * disable the underrun reporting. Which means we need to start
12929 * out with underrun reporting disabled also on inactive pipes,
12930 * since otherwise we'll complain about the garbage we read when
12931 * e.g. coming up after runtime pm.
12933 * No protection against concurrent access is required - at
12934 * worst a fifo underrun happens which also sets this to false.
12936 crtc
->cpu_fifo_underrun_disabled
= true;
12937 crtc
->pch_fifo_underrun_disabled
= true;
12941 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
12943 struct intel_connector
*connector
;
12944 struct drm_device
*dev
= encoder
->base
.dev
;
12946 /* We need to check both for a crtc link (meaning that the
12947 * encoder is active and trying to read from a pipe) and the
12948 * pipe itself being active. */
12949 bool has_active_crtc
= encoder
->base
.crtc
&&
12950 to_intel_crtc(encoder
->base
.crtc
)->active
;
12952 if (encoder
->connectors_active
&& !has_active_crtc
) {
12953 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
12954 encoder
->base
.base
.id
,
12955 encoder
->base
.name
);
12957 /* Connector is active, but has no active pipe. This is
12958 * fallout from our resume register restoring. Disable
12959 * the encoder manually again. */
12960 if (encoder
->base
.crtc
) {
12961 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
12962 encoder
->base
.base
.id
,
12963 encoder
->base
.name
);
12964 encoder
->disable(encoder
);
12965 if (encoder
->post_disable
)
12966 encoder
->post_disable(encoder
);
12968 encoder
->base
.crtc
= NULL
;
12969 encoder
->connectors_active
= false;
12971 /* Inconsistent output/port/pipe state happens presumably due to
12972 * a bug in one of the get_hw_state functions. Or someplace else
12973 * in our code, like the register restore mess on resume. Clamp
12974 * things to off as a safer default. */
12975 list_for_each_entry(connector
,
12976 &dev
->mode_config
.connector_list
,
12978 if (connector
->encoder
!= encoder
)
12980 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
12981 connector
->base
.encoder
= NULL
;
12984 /* Enabled encoders without active connectors will be fixed in
12985 * the crtc fixup. */
12988 void i915_redisable_vga_power_on(struct drm_device
*dev
)
12990 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12991 u32 vga_reg
= i915_vgacntrl_reg(dev
);
12993 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
12994 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
12995 i915_disable_vga(dev
);
12999 void i915_redisable_vga(struct drm_device
*dev
)
13001 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13003 /* This function can be called both from intel_modeset_setup_hw_state or
13004 * at a very early point in our resume sequence, where the power well
13005 * structures are not yet restored. Since this function is at a very
13006 * paranoid "someone might have enabled VGA while we were not looking"
13007 * level, just check if the power well is enabled instead of trying to
13008 * follow the "don't touch the power well if we don't need it" policy
13009 * the rest of the driver uses. */
13010 if (!intel_display_power_is_enabled(dev_priv
, POWER_DOMAIN_VGA
))
13013 i915_redisable_vga_power_on(dev
);
13016 static bool primary_get_hw_state(struct intel_crtc
*crtc
)
13018 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
13023 return I915_READ(DSPCNTR(crtc
->plane
)) & DISPLAY_PLANE_ENABLE
;
13026 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
13028 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13030 struct intel_crtc
*crtc
;
13031 struct intel_encoder
*encoder
;
13032 struct intel_connector
*connector
;
13035 for_each_intel_crtc(dev
, crtc
) {
13036 memset(&crtc
->config
, 0, sizeof(crtc
->config
));
13038 crtc
->config
.quirks
|= PIPE_CONFIG_QUIRK_INHERITED_MODE
;
13040 crtc
->active
= dev_priv
->display
.get_pipe_config(crtc
,
13043 crtc
->base
.enabled
= crtc
->active
;
13044 crtc
->primary_enabled
= primary_get_hw_state(crtc
);
13046 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
13047 crtc
->base
.base
.id
,
13048 crtc
->active
? "enabled" : "disabled");
13051 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
13052 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
13054 pll
->on
= pll
->get_hw_state(dev_priv
, pll
, &pll
->hw_state
);
13056 for_each_intel_crtc(dev
, crtc
) {
13057 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
13060 pll
->refcount
= pll
->active
;
13062 DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n",
13063 pll
->name
, pll
->refcount
, pll
->on
);
13066 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
13069 for_each_intel_encoder(dev
, encoder
) {
13072 if (encoder
->get_hw_state(encoder
, &pipe
)) {
13073 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
13074 encoder
->base
.crtc
= &crtc
->base
;
13075 encoder
->get_config(encoder
, &crtc
->config
);
13077 encoder
->base
.crtc
= NULL
;
13080 encoder
->connectors_active
= false;
13081 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
13082 encoder
->base
.base
.id
,
13083 encoder
->base
.name
,
13084 encoder
->base
.crtc
? "enabled" : "disabled",
13088 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
13090 if (connector
->get_hw_state(connector
)) {
13091 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
13092 connector
->encoder
->connectors_active
= true;
13093 connector
->base
.encoder
= &connector
->encoder
->base
;
13095 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
13096 connector
->base
.encoder
= NULL
;
13098 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
13099 connector
->base
.base
.id
,
13100 connector
->base
.name
,
13101 connector
->base
.encoder
? "enabled" : "disabled");
13105 /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
13106 * and i915 state tracking structures. */
13107 void intel_modeset_setup_hw_state(struct drm_device
*dev
,
13108 bool force_restore
)
13110 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13112 struct intel_crtc
*crtc
;
13113 struct intel_encoder
*encoder
;
13116 intel_modeset_readout_hw_state(dev
);
13119 * Now that we have the config, copy it to each CRTC struct
13120 * Note that this could go away if we move to using crtc_config
13121 * checking everywhere.
13123 for_each_intel_crtc(dev
, crtc
) {
13124 if (crtc
->active
&& i915
.fastboot
) {
13125 intel_mode_from_pipe_config(&crtc
->base
.mode
, &crtc
->config
);
13126 DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
13127 crtc
->base
.base
.id
);
13128 drm_mode_debug_printmodeline(&crtc
->base
.mode
);
13132 /* HW state is read out, now we need to sanitize this mess. */
13133 for_each_intel_encoder(dev
, encoder
) {
13134 intel_sanitize_encoder(encoder
);
13137 for_each_pipe(dev_priv
, pipe
) {
13138 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
13139 intel_sanitize_crtc(crtc
);
13140 intel_dump_pipe_config(crtc
, &crtc
->config
, "[setup_hw_state]");
13143 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
13144 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
13146 if (!pll
->on
|| pll
->active
)
13149 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
13151 pll
->disable(dev_priv
, pll
);
13155 if (HAS_PCH_SPLIT(dev
))
13156 ilk_wm_get_hw_state(dev
);
13158 if (force_restore
) {
13159 i915_redisable_vga(dev
);
13162 * We need to use raw interfaces for restoring state to avoid
13163 * checking (bogus) intermediate states.
13165 for_each_pipe(dev_priv
, pipe
) {
13166 struct drm_crtc
*crtc
=
13167 dev_priv
->pipe_to_crtc_mapping
[pipe
];
13169 __intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
,
13170 crtc
->primary
->fb
);
13173 intel_modeset_update_staged_output_state(dev
);
13176 intel_modeset_check_state(dev
);
13179 void intel_modeset_gem_init(struct drm_device
*dev
)
13181 struct drm_crtc
*c
;
13182 struct drm_i915_gem_object
*obj
;
13184 mutex_lock(&dev
->struct_mutex
);
13185 intel_init_gt_powersave(dev
);
13186 mutex_unlock(&dev
->struct_mutex
);
13188 intel_modeset_init_hw(dev
);
13190 intel_setup_overlay(dev
);
13193 * Make sure any fbs we allocated at startup are properly
13194 * pinned & fenced. When we do the allocation it's too early
13197 mutex_lock(&dev
->struct_mutex
);
13198 for_each_crtc(dev
, c
) {
13199 obj
= intel_fb_obj(c
->primary
->fb
);
13203 if (intel_pin_and_fence_fb_obj(dev
, obj
, NULL
)) {
13204 DRM_ERROR("failed to pin boot fb on pipe %d\n",
13205 to_intel_crtc(c
)->pipe
);
13206 drm_framebuffer_unreference(c
->primary
->fb
);
13207 c
->primary
->fb
= NULL
;
13210 mutex_unlock(&dev
->struct_mutex
);
13213 void intel_connector_unregister(struct intel_connector
*intel_connector
)
13215 struct drm_connector
*connector
= &intel_connector
->base
;
13217 intel_panel_destroy_backlight(connector
);
13218 drm_connector_unregister(connector
);
13221 void intel_modeset_cleanup(struct drm_device
*dev
)
13223 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13224 struct drm_connector
*connector
;
13227 * Interrupts and polling as the first thing to avoid creating havoc.
13228 * Too much stuff here (turning of rps, connectors, ...) would
13229 * experience fancy races otherwise.
13231 intel_irq_uninstall(dev_priv
);
13234 * Due to the hpd irq storm handling the hotplug work can re-arm the
13235 * poll handlers. Hence disable polling after hpd handling is shut down.
13237 drm_kms_helper_poll_fini(dev
);
13239 mutex_lock(&dev
->struct_mutex
);
13241 intel_unregister_dsm_handler();
13243 intel_disable_fbc(dev
);
13245 intel_disable_gt_powersave(dev
);
13247 ironlake_teardown_rc6(dev
);
13249 mutex_unlock(&dev
->struct_mutex
);
13251 /* flush any delayed tasks or pending work */
13252 flush_scheduled_work();
13254 /* destroy the backlight and sysfs files before encoders/connectors */
13255 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
13256 struct intel_connector
*intel_connector
;
13258 intel_connector
= to_intel_connector(connector
);
13259 intel_connector
->unregister(intel_connector
);
13262 drm_mode_config_cleanup(dev
);
13264 intel_cleanup_overlay(dev
);
13266 mutex_lock(&dev
->struct_mutex
);
13267 intel_cleanup_gt_powersave(dev
);
13268 mutex_unlock(&dev
->struct_mutex
);
13272 * Return which encoder is currently attached for connector.
13274 struct drm_encoder
*intel_best_encoder(struct drm_connector
*connector
)
13276 return &intel_attached_encoder(connector
)->base
;
13279 void intel_connector_attach_encoder(struct intel_connector
*connector
,
13280 struct intel_encoder
*encoder
)
13282 connector
->encoder
= encoder
;
13283 drm_mode_connector_attach_encoder(&connector
->base
,
13288 * set vga decode state - true == enable VGA decode
13290 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
13292 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13293 unsigned reg
= INTEL_INFO(dev
)->gen
>= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
13296 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
13297 DRM_ERROR("failed to read control word\n");
13301 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
13305 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
13307 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
13309 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
13310 DRM_ERROR("failed to write control word\n");
13317 struct intel_display_error_state
{
13319 u32 power_well_driver
;
13321 int num_transcoders
;
13323 struct intel_cursor_error_state
{
13328 } cursor
[I915_MAX_PIPES
];
13330 struct intel_pipe_error_state
{
13331 bool power_domain_on
;
13334 } pipe
[I915_MAX_PIPES
];
13336 struct intel_plane_error_state
{
13344 } plane
[I915_MAX_PIPES
];
13346 struct intel_transcoder_error_state
{
13347 bool power_domain_on
;
13348 enum transcoder cpu_transcoder
;
13361 struct intel_display_error_state
*
13362 intel_display_capture_error_state(struct drm_device
*dev
)
13364 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13365 struct intel_display_error_state
*error
;
13366 int transcoders
[] = {
13374 if (INTEL_INFO(dev
)->num_pipes
== 0)
13377 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
13381 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
13382 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
13384 for_each_pipe(dev_priv
, i
) {
13385 error
->pipe
[i
].power_domain_on
=
13386 __intel_display_power_is_enabled(dev_priv
,
13387 POWER_DOMAIN_PIPE(i
));
13388 if (!error
->pipe
[i
].power_domain_on
)
13391 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
13392 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
13393 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
13395 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
13396 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
13397 if (INTEL_INFO(dev
)->gen
<= 3) {
13398 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
13399 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
13401 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
13402 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
13403 if (INTEL_INFO(dev
)->gen
>= 4) {
13404 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
13405 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
13408 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
13410 if (HAS_GMCH_DISPLAY(dev
))
13411 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
13414 error
->num_transcoders
= INTEL_INFO(dev
)->num_pipes
;
13415 if (HAS_DDI(dev_priv
->dev
))
13416 error
->num_transcoders
++; /* Account for eDP. */
13418 for (i
= 0; i
< error
->num_transcoders
; i
++) {
13419 enum transcoder cpu_transcoder
= transcoders
[i
];
13421 error
->transcoder
[i
].power_domain_on
=
13422 __intel_display_power_is_enabled(dev_priv
,
13423 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
13424 if (!error
->transcoder
[i
].power_domain_on
)
13427 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
13429 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
13430 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
13431 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
13432 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
13433 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
13434 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
13435 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
13441 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
13444 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
13445 struct drm_device
*dev
,
13446 struct intel_display_error_state
*error
)
13448 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13454 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev
)->num_pipes
);
13455 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
13456 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
13457 error
->power_well_driver
);
13458 for_each_pipe(dev_priv
, i
) {
13459 err_printf(m
, "Pipe [%d]:\n", i
);
13460 err_printf(m
, " Power: %s\n",
13461 error
->pipe
[i
].power_domain_on
? "on" : "off");
13462 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
13463 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
13465 err_printf(m
, "Plane [%d]:\n", i
);
13466 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
13467 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
13468 if (INTEL_INFO(dev
)->gen
<= 3) {
13469 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
13470 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
13472 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
13473 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
13474 if (INTEL_INFO(dev
)->gen
>= 4) {
13475 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
13476 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
13479 err_printf(m
, "Cursor [%d]:\n", i
);
13480 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
13481 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
13482 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
13485 for (i
= 0; i
< error
->num_transcoders
; i
++) {
13486 err_printf(m
, "CPU transcoder: %c\n",
13487 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
13488 err_printf(m
, " Power: %s\n",
13489 error
->transcoder
[i
].power_domain_on
? "on" : "off");
13490 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
13491 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
13492 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
13493 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
13494 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
13495 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
13496 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);
13500 void intel_modeset_preclose(struct drm_device
*dev
, struct drm_file
*file
)
13502 struct intel_crtc
*crtc
;
13504 for_each_intel_crtc(dev
, crtc
) {
13505 struct intel_unpin_work
*work
;
13507 spin_lock_irq(&dev
->event_lock
);
13509 work
= crtc
->unpin_work
;
13511 if (work
&& work
->event
&&
13512 work
->event
->base
.file_priv
== file
) {
13513 kfree(work
->event
);
13514 work
->event
= NULL
;
13517 spin_unlock_irq(&dev
->event_lock
);