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_atomic.h>
41 #include <drm/drm_atomic_helper.h>
42 #include <drm/drm_dp_helper.h>
43 #include <drm/drm_crtc_helper.h>
44 #include <drm/drm_plane_helper.h>
45 #include <drm/drm_rect.h>
46 #include <linux/dma_remapping.h>
48 /* Primary plane formats supported by all gen */
49 #define COMMON_PRIMARY_FORMATS \
52 DRM_FORMAT_XRGB8888, \
55 /* Primary plane formats for gen <= 3 */
56 static const uint32_t intel_primary_formats_gen2
[] = {
57 COMMON_PRIMARY_FORMATS
,
62 /* Primary plane formats for gen >= 4 */
63 static const uint32_t intel_primary_formats_gen4
[] = {
64 COMMON_PRIMARY_FORMATS
, \
67 DRM_FORMAT_XRGB2101010
,
68 DRM_FORMAT_ARGB2101010
,
69 DRM_FORMAT_XBGR2101010
,
70 DRM_FORMAT_ABGR2101010
,
74 static const uint32_t intel_cursor_formats
[] = {
78 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
, bool on
);
80 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
81 struct intel_crtc_state
*pipe_config
);
82 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
83 struct intel_crtc_state
*pipe_config
);
85 static int intel_set_mode(struct drm_crtc
*crtc
, struct drm_display_mode
*mode
,
86 int x
, int y
, struct drm_framebuffer
*old_fb
);
87 static int intel_framebuffer_init(struct drm_device
*dev
,
88 struct intel_framebuffer
*ifb
,
89 struct drm_mode_fb_cmd2
*mode_cmd
,
90 struct drm_i915_gem_object
*obj
);
91 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
);
92 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
);
93 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
94 struct intel_link_m_n
*m_n
,
95 struct intel_link_m_n
*m2_n2
);
96 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
);
97 static void haswell_set_pipeconf(struct drm_crtc
*crtc
);
98 static void intel_set_pipe_csc(struct drm_crtc
*crtc
);
99 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
100 const struct intel_crtc_state
*pipe_config
);
101 static void chv_prepare_pll(struct intel_crtc
*crtc
,
102 const struct intel_crtc_state
*pipe_config
);
103 static void intel_begin_crtc_commit(struct drm_crtc
*crtc
);
104 static void intel_finish_crtc_commit(struct drm_crtc
*crtc
);
106 static struct intel_encoder
*intel_find_encoder(struct intel_connector
*connector
, int pipe
)
108 if (!connector
->mst_port
)
109 return connector
->encoder
;
111 return &connector
->mst_port
->mst_encoders
[pipe
]->base
;
120 int p2_slow
, p2_fast
;
123 typedef struct intel_limit intel_limit_t
;
125 intel_range_t dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
130 intel_pch_rawclk(struct drm_device
*dev
)
132 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
134 WARN_ON(!HAS_PCH_SPLIT(dev
));
136 return I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
;
139 static inline u32
/* units of 100MHz */
140 intel_fdi_link_freq(struct drm_device
*dev
)
143 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
144 return (I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2;
149 static const intel_limit_t intel_limits_i8xx_dac
= {
150 .dot
= { .min
= 25000, .max
= 350000 },
151 .vco
= { .min
= 908000, .max
= 1512000 },
152 .n
= { .min
= 2, .max
= 16 },
153 .m
= { .min
= 96, .max
= 140 },
154 .m1
= { .min
= 18, .max
= 26 },
155 .m2
= { .min
= 6, .max
= 16 },
156 .p
= { .min
= 4, .max
= 128 },
157 .p1
= { .min
= 2, .max
= 33 },
158 .p2
= { .dot_limit
= 165000,
159 .p2_slow
= 4, .p2_fast
= 2 },
162 static const intel_limit_t intel_limits_i8xx_dvo
= {
163 .dot
= { .min
= 25000, .max
= 350000 },
164 .vco
= { .min
= 908000, .max
= 1512000 },
165 .n
= { .min
= 2, .max
= 16 },
166 .m
= { .min
= 96, .max
= 140 },
167 .m1
= { .min
= 18, .max
= 26 },
168 .m2
= { .min
= 6, .max
= 16 },
169 .p
= { .min
= 4, .max
= 128 },
170 .p1
= { .min
= 2, .max
= 33 },
171 .p2
= { .dot_limit
= 165000,
172 .p2_slow
= 4, .p2_fast
= 4 },
175 static const intel_limit_t intel_limits_i8xx_lvds
= {
176 .dot
= { .min
= 25000, .max
= 350000 },
177 .vco
= { .min
= 908000, .max
= 1512000 },
178 .n
= { .min
= 2, .max
= 16 },
179 .m
= { .min
= 96, .max
= 140 },
180 .m1
= { .min
= 18, .max
= 26 },
181 .m2
= { .min
= 6, .max
= 16 },
182 .p
= { .min
= 4, .max
= 128 },
183 .p1
= { .min
= 1, .max
= 6 },
184 .p2
= { .dot_limit
= 165000,
185 .p2_slow
= 14, .p2_fast
= 7 },
188 static const intel_limit_t intel_limits_i9xx_sdvo
= {
189 .dot
= { .min
= 20000, .max
= 400000 },
190 .vco
= { .min
= 1400000, .max
= 2800000 },
191 .n
= { .min
= 1, .max
= 6 },
192 .m
= { .min
= 70, .max
= 120 },
193 .m1
= { .min
= 8, .max
= 18 },
194 .m2
= { .min
= 3, .max
= 7 },
195 .p
= { .min
= 5, .max
= 80 },
196 .p1
= { .min
= 1, .max
= 8 },
197 .p2
= { .dot_limit
= 200000,
198 .p2_slow
= 10, .p2_fast
= 5 },
201 static const intel_limit_t intel_limits_i9xx_lvds
= {
202 .dot
= { .min
= 20000, .max
= 400000 },
203 .vco
= { .min
= 1400000, .max
= 2800000 },
204 .n
= { .min
= 1, .max
= 6 },
205 .m
= { .min
= 70, .max
= 120 },
206 .m1
= { .min
= 8, .max
= 18 },
207 .m2
= { .min
= 3, .max
= 7 },
208 .p
= { .min
= 7, .max
= 98 },
209 .p1
= { .min
= 1, .max
= 8 },
210 .p2
= { .dot_limit
= 112000,
211 .p2_slow
= 14, .p2_fast
= 7 },
215 static const intel_limit_t intel_limits_g4x_sdvo
= {
216 .dot
= { .min
= 25000, .max
= 270000 },
217 .vco
= { .min
= 1750000, .max
= 3500000},
218 .n
= { .min
= 1, .max
= 4 },
219 .m
= { .min
= 104, .max
= 138 },
220 .m1
= { .min
= 17, .max
= 23 },
221 .m2
= { .min
= 5, .max
= 11 },
222 .p
= { .min
= 10, .max
= 30 },
223 .p1
= { .min
= 1, .max
= 3},
224 .p2
= { .dot_limit
= 270000,
230 static const intel_limit_t intel_limits_g4x_hdmi
= {
231 .dot
= { .min
= 22000, .max
= 400000 },
232 .vco
= { .min
= 1750000, .max
= 3500000},
233 .n
= { .min
= 1, .max
= 4 },
234 .m
= { .min
= 104, .max
= 138 },
235 .m1
= { .min
= 16, .max
= 23 },
236 .m2
= { .min
= 5, .max
= 11 },
237 .p
= { .min
= 5, .max
= 80 },
238 .p1
= { .min
= 1, .max
= 8},
239 .p2
= { .dot_limit
= 165000,
240 .p2_slow
= 10, .p2_fast
= 5 },
243 static const intel_limit_t intel_limits_g4x_single_channel_lvds
= {
244 .dot
= { .min
= 20000, .max
= 115000 },
245 .vco
= { .min
= 1750000, .max
= 3500000 },
246 .n
= { .min
= 1, .max
= 3 },
247 .m
= { .min
= 104, .max
= 138 },
248 .m1
= { .min
= 17, .max
= 23 },
249 .m2
= { .min
= 5, .max
= 11 },
250 .p
= { .min
= 28, .max
= 112 },
251 .p1
= { .min
= 2, .max
= 8 },
252 .p2
= { .dot_limit
= 0,
253 .p2_slow
= 14, .p2_fast
= 14
257 static const intel_limit_t intel_limits_g4x_dual_channel_lvds
= {
258 .dot
= { .min
= 80000, .max
= 224000 },
259 .vco
= { .min
= 1750000, .max
= 3500000 },
260 .n
= { .min
= 1, .max
= 3 },
261 .m
= { .min
= 104, .max
= 138 },
262 .m1
= { .min
= 17, .max
= 23 },
263 .m2
= { .min
= 5, .max
= 11 },
264 .p
= { .min
= 14, .max
= 42 },
265 .p1
= { .min
= 2, .max
= 6 },
266 .p2
= { .dot_limit
= 0,
267 .p2_slow
= 7, .p2_fast
= 7
271 static const intel_limit_t intel_limits_pineview_sdvo
= {
272 .dot
= { .min
= 20000, .max
= 400000},
273 .vco
= { .min
= 1700000, .max
= 3500000 },
274 /* Pineview's Ncounter is a ring counter */
275 .n
= { .min
= 3, .max
= 6 },
276 .m
= { .min
= 2, .max
= 256 },
277 /* Pineview only has one combined m divider, which we treat as m2. */
278 .m1
= { .min
= 0, .max
= 0 },
279 .m2
= { .min
= 0, .max
= 254 },
280 .p
= { .min
= 5, .max
= 80 },
281 .p1
= { .min
= 1, .max
= 8 },
282 .p2
= { .dot_limit
= 200000,
283 .p2_slow
= 10, .p2_fast
= 5 },
286 static const intel_limit_t intel_limits_pineview_lvds
= {
287 .dot
= { .min
= 20000, .max
= 400000 },
288 .vco
= { .min
= 1700000, .max
= 3500000 },
289 .n
= { .min
= 3, .max
= 6 },
290 .m
= { .min
= 2, .max
= 256 },
291 .m1
= { .min
= 0, .max
= 0 },
292 .m2
= { .min
= 0, .max
= 254 },
293 .p
= { .min
= 7, .max
= 112 },
294 .p1
= { .min
= 1, .max
= 8 },
295 .p2
= { .dot_limit
= 112000,
296 .p2_slow
= 14, .p2_fast
= 14 },
299 /* Ironlake / Sandybridge
301 * We calculate clock using (register_value + 2) for N/M1/M2, so here
302 * the range value for them is (actual_value - 2).
304 static const intel_limit_t intel_limits_ironlake_dac
= {
305 .dot
= { .min
= 25000, .max
= 350000 },
306 .vco
= { .min
= 1760000, .max
= 3510000 },
307 .n
= { .min
= 1, .max
= 5 },
308 .m
= { .min
= 79, .max
= 127 },
309 .m1
= { .min
= 12, .max
= 22 },
310 .m2
= { .min
= 5, .max
= 9 },
311 .p
= { .min
= 5, .max
= 80 },
312 .p1
= { .min
= 1, .max
= 8 },
313 .p2
= { .dot_limit
= 225000,
314 .p2_slow
= 10, .p2_fast
= 5 },
317 static const intel_limit_t intel_limits_ironlake_single_lvds
= {
318 .dot
= { .min
= 25000, .max
= 350000 },
319 .vco
= { .min
= 1760000, .max
= 3510000 },
320 .n
= { .min
= 1, .max
= 3 },
321 .m
= { .min
= 79, .max
= 118 },
322 .m1
= { .min
= 12, .max
= 22 },
323 .m2
= { .min
= 5, .max
= 9 },
324 .p
= { .min
= 28, .max
= 112 },
325 .p1
= { .min
= 2, .max
= 8 },
326 .p2
= { .dot_limit
= 225000,
327 .p2_slow
= 14, .p2_fast
= 14 },
330 static const intel_limit_t intel_limits_ironlake_dual_lvds
= {
331 .dot
= { .min
= 25000, .max
= 350000 },
332 .vco
= { .min
= 1760000, .max
= 3510000 },
333 .n
= { .min
= 1, .max
= 3 },
334 .m
= { .min
= 79, .max
= 127 },
335 .m1
= { .min
= 12, .max
= 22 },
336 .m2
= { .min
= 5, .max
= 9 },
337 .p
= { .min
= 14, .max
= 56 },
338 .p1
= { .min
= 2, .max
= 8 },
339 .p2
= { .dot_limit
= 225000,
340 .p2_slow
= 7, .p2_fast
= 7 },
343 /* LVDS 100mhz refclk limits. */
344 static const intel_limit_t intel_limits_ironlake_single_lvds_100m
= {
345 .dot
= { .min
= 25000, .max
= 350000 },
346 .vco
= { .min
= 1760000, .max
= 3510000 },
347 .n
= { .min
= 1, .max
= 2 },
348 .m
= { .min
= 79, .max
= 126 },
349 .m1
= { .min
= 12, .max
= 22 },
350 .m2
= { .min
= 5, .max
= 9 },
351 .p
= { .min
= 28, .max
= 112 },
352 .p1
= { .min
= 2, .max
= 8 },
353 .p2
= { .dot_limit
= 225000,
354 .p2_slow
= 14, .p2_fast
= 14 },
357 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m
= {
358 .dot
= { .min
= 25000, .max
= 350000 },
359 .vco
= { .min
= 1760000, .max
= 3510000 },
360 .n
= { .min
= 1, .max
= 3 },
361 .m
= { .min
= 79, .max
= 126 },
362 .m1
= { .min
= 12, .max
= 22 },
363 .m2
= { .min
= 5, .max
= 9 },
364 .p
= { .min
= 14, .max
= 42 },
365 .p1
= { .min
= 2, .max
= 6 },
366 .p2
= { .dot_limit
= 225000,
367 .p2_slow
= 7, .p2_fast
= 7 },
370 static const intel_limit_t intel_limits_vlv
= {
372 * These are the data rate limits (measured in fast clocks)
373 * since those are the strictest limits we have. The fast
374 * clock and actual rate limits are more relaxed, so checking
375 * them would make no difference.
377 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
378 .vco
= { .min
= 4000000, .max
= 6000000 },
379 .n
= { .min
= 1, .max
= 7 },
380 .m1
= { .min
= 2, .max
= 3 },
381 .m2
= { .min
= 11, .max
= 156 },
382 .p1
= { .min
= 2, .max
= 3 },
383 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
386 static const intel_limit_t intel_limits_chv
= {
388 * These are the data rate limits (measured in fast clocks)
389 * since those are the strictest limits we have. The fast
390 * clock and actual rate limits are more relaxed, so checking
391 * them would make no difference.
393 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
394 .vco
= { .min
= 4800000, .max
= 6480000 },
395 .n
= { .min
= 1, .max
= 1 },
396 .m1
= { .min
= 2, .max
= 2 },
397 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
398 .p1
= { .min
= 2, .max
= 4 },
399 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
402 static void vlv_clock(int refclk
, intel_clock_t
*clock
)
404 clock
->m
= clock
->m1
* clock
->m2
;
405 clock
->p
= clock
->p1
* clock
->p2
;
406 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
408 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
409 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
413 * Returns whether any output on the specified pipe is of the specified type
415 bool intel_pipe_has_type(struct intel_crtc
*crtc
, enum intel_output_type type
)
417 struct drm_device
*dev
= crtc
->base
.dev
;
418 struct intel_encoder
*encoder
;
420 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
421 if (encoder
->type
== type
)
428 * Returns whether any output on the specified pipe will have the specified
429 * type after a staged modeset is complete, i.e., the same as
430 * intel_pipe_has_type() but looking at encoder->new_crtc instead of
433 static bool intel_pipe_will_have_type(struct intel_crtc
*crtc
, int type
)
435 struct drm_device
*dev
= crtc
->base
.dev
;
436 struct intel_encoder
*encoder
;
438 for_each_intel_encoder(dev
, encoder
)
439 if (encoder
->new_crtc
== crtc
&& encoder
->type
== type
)
445 static const intel_limit_t
*intel_ironlake_limit(struct intel_crtc
*crtc
,
448 struct drm_device
*dev
= crtc
->base
.dev
;
449 const intel_limit_t
*limit
;
451 if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_LVDS
)) {
452 if (intel_is_dual_link_lvds(dev
)) {
453 if (refclk
== 100000)
454 limit
= &intel_limits_ironlake_dual_lvds_100m
;
456 limit
= &intel_limits_ironlake_dual_lvds
;
458 if (refclk
== 100000)
459 limit
= &intel_limits_ironlake_single_lvds_100m
;
461 limit
= &intel_limits_ironlake_single_lvds
;
464 limit
= &intel_limits_ironlake_dac
;
469 static const intel_limit_t
*intel_g4x_limit(struct intel_crtc
*crtc
)
471 struct drm_device
*dev
= crtc
->base
.dev
;
472 const intel_limit_t
*limit
;
474 if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_LVDS
)) {
475 if (intel_is_dual_link_lvds(dev
))
476 limit
= &intel_limits_g4x_dual_channel_lvds
;
478 limit
= &intel_limits_g4x_single_channel_lvds
;
479 } else if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_HDMI
) ||
480 intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_ANALOG
)) {
481 limit
= &intel_limits_g4x_hdmi
;
482 } else if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_SDVO
)) {
483 limit
= &intel_limits_g4x_sdvo
;
484 } else /* The option is for other outputs */
485 limit
= &intel_limits_i9xx_sdvo
;
490 static const intel_limit_t
*intel_limit(struct intel_crtc
*crtc
, int refclk
)
492 struct drm_device
*dev
= crtc
->base
.dev
;
493 const intel_limit_t
*limit
;
495 if (HAS_PCH_SPLIT(dev
))
496 limit
= intel_ironlake_limit(crtc
, refclk
);
497 else if (IS_G4X(dev
)) {
498 limit
= intel_g4x_limit(crtc
);
499 } else if (IS_PINEVIEW(dev
)) {
500 if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_LVDS
))
501 limit
= &intel_limits_pineview_lvds
;
503 limit
= &intel_limits_pineview_sdvo
;
504 } else if (IS_CHERRYVIEW(dev
)) {
505 limit
= &intel_limits_chv
;
506 } else if (IS_VALLEYVIEW(dev
)) {
507 limit
= &intel_limits_vlv
;
508 } else if (!IS_GEN2(dev
)) {
509 if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_LVDS
))
510 limit
= &intel_limits_i9xx_lvds
;
512 limit
= &intel_limits_i9xx_sdvo
;
514 if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_LVDS
))
515 limit
= &intel_limits_i8xx_lvds
;
516 else if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_DVO
))
517 limit
= &intel_limits_i8xx_dvo
;
519 limit
= &intel_limits_i8xx_dac
;
524 /* m1 is reserved as 0 in Pineview, n is a ring counter */
525 static void pineview_clock(int refclk
, intel_clock_t
*clock
)
527 clock
->m
= clock
->m2
+ 2;
528 clock
->p
= clock
->p1
* clock
->p2
;
529 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
531 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
532 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
535 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
537 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
540 static void i9xx_clock(int refclk
, intel_clock_t
*clock
)
542 clock
->m
= i9xx_dpll_compute_m(clock
);
543 clock
->p
= clock
->p1
* clock
->p2
;
544 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
546 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
547 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
550 static void chv_clock(int refclk
, intel_clock_t
*clock
)
552 clock
->m
= clock
->m1
* clock
->m2
;
553 clock
->p
= clock
->p1
* clock
->p2
;
554 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
556 clock
->vco
= DIV_ROUND_CLOSEST_ULL((uint64_t)refclk
* clock
->m
,
558 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
561 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
563 * Returns whether the given set of divisors are valid for a given refclk with
564 * the given connectors.
567 static bool intel_PLL_is_valid(struct drm_device
*dev
,
568 const intel_limit_t
*limit
,
569 const intel_clock_t
*clock
)
571 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
572 INTELPllInvalid("n out of range\n");
573 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
574 INTELPllInvalid("p1 out of range\n");
575 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
576 INTELPllInvalid("m2 out of range\n");
577 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
578 INTELPllInvalid("m1 out of range\n");
580 if (!IS_PINEVIEW(dev
) && !IS_VALLEYVIEW(dev
))
581 if (clock
->m1
<= clock
->m2
)
582 INTELPllInvalid("m1 <= m2\n");
584 if (!IS_VALLEYVIEW(dev
)) {
585 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
586 INTELPllInvalid("p out of range\n");
587 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
588 INTELPllInvalid("m out of range\n");
591 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
592 INTELPllInvalid("vco out of range\n");
593 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
594 * connector, etc., rather than just a single range.
596 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
597 INTELPllInvalid("dot out of range\n");
603 i9xx_find_best_dpll(const intel_limit_t
*limit
, struct intel_crtc
*crtc
,
604 int target
, int refclk
, intel_clock_t
*match_clock
,
605 intel_clock_t
*best_clock
)
607 struct drm_device
*dev
= crtc
->base
.dev
;
611 if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_LVDS
)) {
613 * For LVDS just rely on its current settings for dual-channel.
614 * We haven't figured out how to reliably set up different
615 * single/dual channel state, if we even can.
617 if (intel_is_dual_link_lvds(dev
))
618 clock
.p2
= limit
->p2
.p2_fast
;
620 clock
.p2
= limit
->p2
.p2_slow
;
622 if (target
< limit
->p2
.dot_limit
)
623 clock
.p2
= limit
->p2
.p2_slow
;
625 clock
.p2
= limit
->p2
.p2_fast
;
628 memset(best_clock
, 0, sizeof(*best_clock
));
630 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
632 for (clock
.m2
= limit
->m2
.min
;
633 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
634 if (clock
.m2
>= clock
.m1
)
636 for (clock
.n
= limit
->n
.min
;
637 clock
.n
<= limit
->n
.max
; clock
.n
++) {
638 for (clock
.p1
= limit
->p1
.min
;
639 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
642 i9xx_clock(refclk
, &clock
);
643 if (!intel_PLL_is_valid(dev
, limit
,
647 clock
.p
!= match_clock
->p
)
650 this_err
= abs(clock
.dot
- target
);
651 if (this_err
< err
) {
660 return (err
!= target
);
664 pnv_find_best_dpll(const intel_limit_t
*limit
, struct intel_crtc
*crtc
,
665 int target
, int refclk
, intel_clock_t
*match_clock
,
666 intel_clock_t
*best_clock
)
668 struct drm_device
*dev
= crtc
->base
.dev
;
672 if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_LVDS
)) {
674 * For LVDS just rely on its current settings for dual-channel.
675 * We haven't figured out how to reliably set up different
676 * single/dual channel state, if we even can.
678 if (intel_is_dual_link_lvds(dev
))
679 clock
.p2
= limit
->p2
.p2_fast
;
681 clock
.p2
= limit
->p2
.p2_slow
;
683 if (target
< limit
->p2
.dot_limit
)
684 clock
.p2
= limit
->p2
.p2_slow
;
686 clock
.p2
= limit
->p2
.p2_fast
;
689 memset(best_clock
, 0, sizeof(*best_clock
));
691 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
693 for (clock
.m2
= limit
->m2
.min
;
694 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
695 for (clock
.n
= limit
->n
.min
;
696 clock
.n
<= limit
->n
.max
; clock
.n
++) {
697 for (clock
.p1
= limit
->p1
.min
;
698 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
701 pineview_clock(refclk
, &clock
);
702 if (!intel_PLL_is_valid(dev
, limit
,
706 clock
.p
!= match_clock
->p
)
709 this_err
= abs(clock
.dot
- target
);
710 if (this_err
< err
) {
719 return (err
!= target
);
723 g4x_find_best_dpll(const intel_limit_t
*limit
, struct intel_crtc
*crtc
,
724 int target
, int refclk
, intel_clock_t
*match_clock
,
725 intel_clock_t
*best_clock
)
727 struct drm_device
*dev
= crtc
->base
.dev
;
731 /* approximately equals target * 0.00585 */
732 int err_most
= (target
>> 8) + (target
>> 9);
735 if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_LVDS
)) {
736 if (intel_is_dual_link_lvds(dev
))
737 clock
.p2
= limit
->p2
.p2_fast
;
739 clock
.p2
= limit
->p2
.p2_slow
;
741 if (target
< limit
->p2
.dot_limit
)
742 clock
.p2
= limit
->p2
.p2_slow
;
744 clock
.p2
= limit
->p2
.p2_fast
;
747 memset(best_clock
, 0, sizeof(*best_clock
));
748 max_n
= limit
->n
.max
;
749 /* based on hardware requirement, prefer smaller n to precision */
750 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
751 /* based on hardware requirement, prefere larger m1,m2 */
752 for (clock
.m1
= limit
->m1
.max
;
753 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
754 for (clock
.m2
= limit
->m2
.max
;
755 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
756 for (clock
.p1
= limit
->p1
.max
;
757 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
760 i9xx_clock(refclk
, &clock
);
761 if (!intel_PLL_is_valid(dev
, limit
,
765 this_err
= abs(clock
.dot
- target
);
766 if (this_err
< err_most
) {
780 * Check if the calculated PLL configuration is more optimal compared to the
781 * best configuration and error found so far. Return the calculated error.
783 static bool vlv_PLL_is_optimal(struct drm_device
*dev
, int target_freq
,
784 const intel_clock_t
*calculated_clock
,
785 const intel_clock_t
*best_clock
,
786 unsigned int best_error_ppm
,
787 unsigned int *error_ppm
)
790 * For CHV ignore the error and consider only the P value.
791 * Prefer a bigger P value based on HW requirements.
793 if (IS_CHERRYVIEW(dev
)) {
796 return calculated_clock
->p
> best_clock
->p
;
799 if (WARN_ON_ONCE(!target_freq
))
802 *error_ppm
= div_u64(1000000ULL *
803 abs(target_freq
- calculated_clock
->dot
),
806 * Prefer a better P value over a better (smaller) error if the error
807 * is small. Ensure this preference for future configurations too by
808 * setting the error to 0.
810 if (*error_ppm
< 100 && calculated_clock
->p
> best_clock
->p
) {
816 return *error_ppm
+ 10 < best_error_ppm
;
820 vlv_find_best_dpll(const intel_limit_t
*limit
, struct intel_crtc
*crtc
,
821 int target
, int refclk
, intel_clock_t
*match_clock
,
822 intel_clock_t
*best_clock
)
824 struct drm_device
*dev
= crtc
->base
.dev
;
826 unsigned int bestppm
= 1000000;
827 /* min update 19.2 MHz */
828 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
831 target
*= 5; /* fast clock */
833 memset(best_clock
, 0, sizeof(*best_clock
));
835 /* based on hardware requirement, prefer smaller n to precision */
836 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
837 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
838 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
839 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
840 clock
.p
= clock
.p1
* clock
.p2
;
841 /* based on hardware requirement, prefer bigger m1,m2 values */
842 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
845 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
848 vlv_clock(refclk
, &clock
);
850 if (!intel_PLL_is_valid(dev
, limit
,
854 if (!vlv_PLL_is_optimal(dev
, target
,
872 chv_find_best_dpll(const intel_limit_t
*limit
, struct intel_crtc
*crtc
,
873 int target
, int refclk
, intel_clock_t
*match_clock
,
874 intel_clock_t
*best_clock
)
876 struct drm_device
*dev
= crtc
->base
.dev
;
877 unsigned int best_error_ppm
;
882 memset(best_clock
, 0, sizeof(*best_clock
));
883 best_error_ppm
= 1000000;
886 * Based on hardware doc, the n always set to 1, and m1 always
887 * set to 2. If requires to support 200Mhz refclk, we need to
888 * revisit this because n may not 1 anymore.
890 clock
.n
= 1, clock
.m1
= 2;
891 target
*= 5; /* fast clock */
893 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
894 for (clock
.p2
= limit
->p2
.p2_fast
;
895 clock
.p2
>= limit
->p2
.p2_slow
;
896 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
897 unsigned int error_ppm
;
899 clock
.p
= clock
.p1
* clock
.p2
;
901 m2
= DIV_ROUND_CLOSEST_ULL(((uint64_t)target
* clock
.p
*
902 clock
.n
) << 22, refclk
* clock
.m1
);
904 if (m2
> INT_MAX
/clock
.m1
)
909 chv_clock(refclk
, &clock
);
911 if (!intel_PLL_is_valid(dev
, limit
, &clock
))
914 if (!vlv_PLL_is_optimal(dev
, target
, &clock
, best_clock
,
915 best_error_ppm
, &error_ppm
))
919 best_error_ppm
= error_ppm
;
927 bool intel_crtc_active(struct drm_crtc
*crtc
)
929 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
931 /* Be paranoid as we can arrive here with only partial
932 * state retrieved from the hardware during setup.
934 * We can ditch the adjusted_mode.crtc_clock check as soon
935 * as Haswell has gained clock readout/fastboot support.
937 * We can ditch the crtc->primary->fb check as soon as we can
938 * properly reconstruct framebuffers.
940 * FIXME: The intel_crtc->active here should be switched to
941 * crtc->state->active once we have proper CRTC states wired up
944 return intel_crtc
->active
&& crtc
->primary
->state
->fb
&&
945 intel_crtc
->config
->base
.adjusted_mode
.crtc_clock
;
948 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
951 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
952 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
954 return intel_crtc
->config
->cpu_transcoder
;
957 static bool pipe_dsl_stopped(struct drm_device
*dev
, enum pipe pipe
)
959 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
960 u32 reg
= PIPEDSL(pipe
);
965 line_mask
= DSL_LINEMASK_GEN2
;
967 line_mask
= DSL_LINEMASK_GEN3
;
969 line1
= I915_READ(reg
) & line_mask
;
971 line2
= I915_READ(reg
) & line_mask
;
973 return line1
== line2
;
977 * intel_wait_for_pipe_off - wait for pipe to turn off
978 * @crtc: crtc whose pipe to wait for
980 * After disabling a pipe, we can't wait for vblank in the usual way,
981 * spinning on the vblank interrupt status bit, since we won't actually
982 * see an interrupt when the pipe is disabled.
985 * wait for the pipe register state bit to turn off
988 * wait for the display line value to settle (it usually
989 * ends up stopping at the start of the next frame).
992 static void intel_wait_for_pipe_off(struct intel_crtc
*crtc
)
994 struct drm_device
*dev
= crtc
->base
.dev
;
995 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
996 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
997 enum pipe pipe
= crtc
->pipe
;
999 if (INTEL_INFO(dev
)->gen
>= 4) {
1000 int reg
= PIPECONF(cpu_transcoder
);
1002 /* Wait for the Pipe State to go off */
1003 if (wait_for((I915_READ(reg
) & I965_PIPECONF_ACTIVE
) == 0,
1005 WARN(1, "pipe_off wait timed out\n");
1007 /* Wait for the display line to settle */
1008 if (wait_for(pipe_dsl_stopped(dev
, pipe
), 100))
1009 WARN(1, "pipe_off wait timed out\n");
1014 * ibx_digital_port_connected - is the specified port connected?
1015 * @dev_priv: i915 private structure
1016 * @port: the port to test
1018 * Returns true if @port is connected, false otherwise.
1020 bool ibx_digital_port_connected(struct drm_i915_private
*dev_priv
,
1021 struct intel_digital_port
*port
)
1025 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1026 switch (port
->port
) {
1028 bit
= SDE_PORTB_HOTPLUG
;
1031 bit
= SDE_PORTC_HOTPLUG
;
1034 bit
= SDE_PORTD_HOTPLUG
;
1040 switch (port
->port
) {
1042 bit
= SDE_PORTB_HOTPLUG_CPT
;
1045 bit
= SDE_PORTC_HOTPLUG_CPT
;
1048 bit
= SDE_PORTD_HOTPLUG_CPT
;
1055 return I915_READ(SDEISR
) & bit
;
1058 static const char *state_string(bool enabled
)
1060 return enabled
? "on" : "off";
1063 /* Only for pre-ILK configs */
1064 void assert_pll(struct drm_i915_private
*dev_priv
,
1065 enum pipe pipe
, bool state
)
1072 val
= I915_READ(reg
);
1073 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1074 I915_STATE_WARN(cur_state
!= state
,
1075 "PLL state assertion failure (expected %s, current %s)\n",
1076 state_string(state
), state_string(cur_state
));
1079 /* XXX: the dsi pll is shared between MIPI DSI ports */
1080 static void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1085 mutex_lock(&dev_priv
->dpio_lock
);
1086 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1087 mutex_unlock(&dev_priv
->dpio_lock
);
1089 cur_state
= val
& DSI_PLL_VCO_EN
;
1090 I915_STATE_WARN(cur_state
!= state
,
1091 "DSI PLL state assertion failure (expected %s, current %s)\n",
1092 state_string(state
), state_string(cur_state
));
1094 #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
1095 #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
1097 struct intel_shared_dpll
*
1098 intel_crtc_to_shared_dpll(struct intel_crtc
*crtc
)
1100 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
1102 if (crtc
->config
->shared_dpll
< 0)
1105 return &dev_priv
->shared_dplls
[crtc
->config
->shared_dpll
];
1109 void assert_shared_dpll(struct drm_i915_private
*dev_priv
,
1110 struct intel_shared_dpll
*pll
,
1114 struct intel_dpll_hw_state hw_state
;
1117 "asserting DPLL %s with no DPLL\n", state_string(state
)))
1120 cur_state
= pll
->get_hw_state(dev_priv
, pll
, &hw_state
);
1121 I915_STATE_WARN(cur_state
!= state
,
1122 "%s assertion failure (expected %s, current %s)\n",
1123 pll
->name
, state_string(state
), state_string(cur_state
));
1126 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1127 enum pipe pipe
, bool state
)
1132 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1135 if (HAS_DDI(dev_priv
->dev
)) {
1136 /* DDI does not have a specific FDI_TX register */
1137 reg
= TRANS_DDI_FUNC_CTL(cpu_transcoder
);
1138 val
= I915_READ(reg
);
1139 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1141 reg
= FDI_TX_CTL(pipe
);
1142 val
= I915_READ(reg
);
1143 cur_state
= !!(val
& FDI_TX_ENABLE
);
1145 I915_STATE_WARN(cur_state
!= state
,
1146 "FDI TX state assertion failure (expected %s, current %s)\n",
1147 state_string(state
), state_string(cur_state
));
1149 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1150 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1152 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1153 enum pipe pipe
, bool state
)
1159 reg
= FDI_RX_CTL(pipe
);
1160 val
= I915_READ(reg
);
1161 cur_state
= !!(val
& FDI_RX_ENABLE
);
1162 I915_STATE_WARN(cur_state
!= state
,
1163 "FDI RX state assertion failure (expected %s, current %s)\n",
1164 state_string(state
), state_string(cur_state
));
1166 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1167 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1169 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1175 /* ILK FDI PLL is always enabled */
1176 if (INTEL_INFO(dev_priv
->dev
)->gen
== 5)
1179 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1180 if (HAS_DDI(dev_priv
->dev
))
1183 reg
= FDI_TX_CTL(pipe
);
1184 val
= I915_READ(reg
);
1185 I915_STATE_WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1188 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1189 enum pipe pipe
, bool state
)
1195 reg
= FDI_RX_CTL(pipe
);
1196 val
= I915_READ(reg
);
1197 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1198 I915_STATE_WARN(cur_state
!= state
,
1199 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1200 state_string(state
), state_string(cur_state
));
1203 void assert_panel_unlocked(struct drm_i915_private
*dev_priv
,
1206 struct drm_device
*dev
= dev_priv
->dev
;
1209 enum pipe panel_pipe
= PIPE_A
;
1212 if (WARN_ON(HAS_DDI(dev
)))
1215 if (HAS_PCH_SPLIT(dev
)) {
1218 pp_reg
= PCH_PP_CONTROL
;
1219 port_sel
= I915_READ(PCH_PP_ON_DELAYS
) & PANEL_PORT_SELECT_MASK
;
1221 if (port_sel
== PANEL_PORT_SELECT_LVDS
&&
1222 I915_READ(PCH_LVDS
) & LVDS_PIPEB_SELECT
)
1223 panel_pipe
= PIPE_B
;
1224 /* XXX: else fix for eDP */
1225 } else if (IS_VALLEYVIEW(dev
)) {
1226 /* presumably write lock depends on pipe, not port select */
1227 pp_reg
= VLV_PIPE_PP_CONTROL(pipe
);
1230 pp_reg
= PP_CONTROL
;
1231 if (I915_READ(LVDS
) & LVDS_PIPEB_SELECT
)
1232 panel_pipe
= PIPE_B
;
1235 val
= I915_READ(pp_reg
);
1236 if (!(val
& PANEL_POWER_ON
) ||
1237 ((val
& PANEL_UNLOCK_MASK
) == PANEL_UNLOCK_REGS
))
1240 I915_STATE_WARN(panel_pipe
== pipe
&& locked
,
1241 "panel assertion failure, pipe %c regs locked\n",
1245 static void assert_cursor(struct drm_i915_private
*dev_priv
,
1246 enum pipe pipe
, bool state
)
1248 struct drm_device
*dev
= dev_priv
->dev
;
1251 if (IS_845G(dev
) || IS_I865G(dev
))
1252 cur_state
= I915_READ(_CURACNTR
) & CURSOR_ENABLE
;
1254 cur_state
= I915_READ(CURCNTR(pipe
)) & CURSOR_MODE
;
1256 I915_STATE_WARN(cur_state
!= state
,
1257 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1258 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1260 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1261 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1263 void assert_pipe(struct drm_i915_private
*dev_priv
,
1264 enum pipe pipe
, bool state
)
1269 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1272 /* if we need the pipe quirk it must be always on */
1273 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1274 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1277 if (!intel_display_power_is_enabled(dev_priv
,
1278 POWER_DOMAIN_TRANSCODER(cpu_transcoder
))) {
1281 reg
= PIPECONF(cpu_transcoder
);
1282 val
= I915_READ(reg
);
1283 cur_state
= !!(val
& PIPECONF_ENABLE
);
1286 I915_STATE_WARN(cur_state
!= state
,
1287 "pipe %c assertion failure (expected %s, current %s)\n",
1288 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1291 static void assert_plane(struct drm_i915_private
*dev_priv
,
1292 enum plane plane
, bool state
)
1298 reg
= DSPCNTR(plane
);
1299 val
= I915_READ(reg
);
1300 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1301 I915_STATE_WARN(cur_state
!= state
,
1302 "plane %c assertion failure (expected %s, current %s)\n",
1303 plane_name(plane
), state_string(state
), state_string(cur_state
));
1306 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1307 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1309 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1312 struct drm_device
*dev
= dev_priv
->dev
;
1317 /* Primary planes are fixed to pipes on gen4+ */
1318 if (INTEL_INFO(dev
)->gen
>= 4) {
1319 reg
= DSPCNTR(pipe
);
1320 val
= I915_READ(reg
);
1321 I915_STATE_WARN(val
& DISPLAY_PLANE_ENABLE
,
1322 "plane %c assertion failure, should be disabled but not\n",
1327 /* Need to check both planes against the pipe */
1328 for_each_pipe(dev_priv
, i
) {
1330 val
= I915_READ(reg
);
1331 cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1332 DISPPLANE_SEL_PIPE_SHIFT
;
1333 I915_STATE_WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1334 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1335 plane_name(i
), pipe_name(pipe
));
1339 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1342 struct drm_device
*dev
= dev_priv
->dev
;
1346 if (INTEL_INFO(dev
)->gen
>= 9) {
1347 for_each_sprite(dev_priv
, pipe
, sprite
) {
1348 val
= I915_READ(PLANE_CTL(pipe
, sprite
));
1349 I915_STATE_WARN(val
& PLANE_CTL_ENABLE
,
1350 "plane %d assertion failure, should be off on pipe %c but is still active\n",
1351 sprite
, pipe_name(pipe
));
1353 } else if (IS_VALLEYVIEW(dev
)) {
1354 for_each_sprite(dev_priv
, pipe
, sprite
) {
1355 reg
= SPCNTR(pipe
, sprite
);
1356 val
= I915_READ(reg
);
1357 I915_STATE_WARN(val
& SP_ENABLE
,
1358 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1359 sprite_name(pipe
, sprite
), pipe_name(pipe
));
1361 } else if (INTEL_INFO(dev
)->gen
>= 7) {
1363 val
= I915_READ(reg
);
1364 I915_STATE_WARN(val
& SPRITE_ENABLE
,
1365 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1366 plane_name(pipe
), pipe_name(pipe
));
1367 } else if (INTEL_INFO(dev
)->gen
>= 5) {
1368 reg
= DVSCNTR(pipe
);
1369 val
= I915_READ(reg
);
1370 I915_STATE_WARN(val
& DVS_ENABLE
,
1371 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1372 plane_name(pipe
), pipe_name(pipe
));
1376 static void assert_vblank_disabled(struct drm_crtc
*crtc
)
1378 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc
) == 0))
1379 drm_crtc_vblank_put(crtc
);
1382 static void ibx_assert_pch_refclk_enabled(struct drm_i915_private
*dev_priv
)
1387 I915_STATE_WARN_ON(!(HAS_PCH_IBX(dev_priv
->dev
) || HAS_PCH_CPT(dev_priv
->dev
)));
1389 val
= I915_READ(PCH_DREF_CONTROL
);
1390 enabled
= !!(val
& (DREF_SSC_SOURCE_MASK
| DREF_NONSPREAD_SOURCE_MASK
|
1391 DREF_SUPERSPREAD_SOURCE_MASK
));
1392 I915_STATE_WARN(!enabled
, "PCH refclk assertion failure, should be active but is disabled\n");
1395 static void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1402 reg
= PCH_TRANSCONF(pipe
);
1403 val
= I915_READ(reg
);
1404 enabled
= !!(val
& TRANS_ENABLE
);
1405 I915_STATE_WARN(enabled
,
1406 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1410 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1411 enum pipe pipe
, u32 port_sel
, u32 val
)
1413 if ((val
& DP_PORT_EN
) == 0)
1416 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1417 u32 trans_dp_ctl_reg
= TRANS_DP_CTL(pipe
);
1418 u32 trans_dp_ctl
= I915_READ(trans_dp_ctl_reg
);
1419 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1421 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1422 if ((val
& DP_PIPE_MASK_CHV
) != DP_PIPE_SELECT_CHV(pipe
))
1425 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1431 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1432 enum pipe pipe
, u32 val
)
1434 if ((val
& SDVO_ENABLE
) == 0)
1437 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1438 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1440 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1441 if ((val
& SDVO_PIPE_SEL_MASK_CHV
) != SDVO_PIPE_SEL_CHV(pipe
))
1444 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1450 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1451 enum pipe pipe
, u32 val
)
1453 if ((val
& LVDS_PORT_EN
) == 0)
1456 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1457 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1460 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1466 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1467 enum pipe pipe
, u32 val
)
1469 if ((val
& ADPA_DAC_ENABLE
) == 0)
1471 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1472 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1475 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1481 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1482 enum pipe pipe
, int reg
, u32 port_sel
)
1484 u32 val
= I915_READ(reg
);
1485 I915_STATE_WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1486 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1487 reg
, pipe_name(pipe
));
1489 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& DP_PORT_EN
) == 0
1490 && (val
& DP_PIPEB_SELECT
),
1491 "IBX PCH dp port still using transcoder B\n");
1494 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1495 enum pipe pipe
, int reg
)
1497 u32 val
= I915_READ(reg
);
1498 I915_STATE_WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1499 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1500 reg
, pipe_name(pipe
));
1502 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& SDVO_ENABLE
) == 0
1503 && (val
& SDVO_PIPE_B_SELECT
),
1504 "IBX PCH hdmi port still using transcoder B\n");
1507 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1513 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1514 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1515 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1518 val
= I915_READ(reg
);
1519 I915_STATE_WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1520 "PCH VGA enabled on transcoder %c, should be disabled\n",
1524 val
= I915_READ(reg
);
1525 I915_STATE_WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1526 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1529 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1530 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1531 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1534 static void intel_init_dpio(struct drm_device
*dev
)
1536 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1538 if (!IS_VALLEYVIEW(dev
))
1542 * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
1543 * CHV x1 PHY (DP/HDMI D)
1544 * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
1546 if (IS_CHERRYVIEW(dev
)) {
1547 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO_2
;
1548 DPIO_PHY_IOSF_PORT(DPIO_PHY1
) = IOSF_PORT_DPIO
;
1550 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO
;
1554 static void vlv_enable_pll(struct intel_crtc
*crtc
,
1555 const struct intel_crtc_state
*pipe_config
)
1557 struct drm_device
*dev
= crtc
->base
.dev
;
1558 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1559 int reg
= DPLL(crtc
->pipe
);
1560 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
1562 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1564 /* No really, not for ILK+ */
1565 BUG_ON(!IS_VALLEYVIEW(dev_priv
->dev
));
1567 /* PLL is protected by panel, make sure we can write it */
1568 if (IS_MOBILE(dev_priv
->dev
))
1569 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1571 I915_WRITE(reg
, dpll
);
1575 if (wait_for(((I915_READ(reg
) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1576 DRM_ERROR("DPLL %d failed to lock\n", crtc
->pipe
);
1578 I915_WRITE(DPLL_MD(crtc
->pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1579 POSTING_READ(DPLL_MD(crtc
->pipe
));
1581 /* We do this three times for luck */
1582 I915_WRITE(reg
, dpll
);
1584 udelay(150); /* wait for warmup */
1585 I915_WRITE(reg
, dpll
);
1587 udelay(150); /* wait for warmup */
1588 I915_WRITE(reg
, dpll
);
1590 udelay(150); /* wait for warmup */
1593 static void chv_enable_pll(struct intel_crtc
*crtc
,
1594 const struct intel_crtc_state
*pipe_config
)
1596 struct drm_device
*dev
= crtc
->base
.dev
;
1597 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1598 int pipe
= crtc
->pipe
;
1599 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1602 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1604 BUG_ON(!IS_CHERRYVIEW(dev_priv
->dev
));
1606 mutex_lock(&dev_priv
->dpio_lock
);
1608 /* Enable back the 10bit clock to display controller */
1609 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1610 tmp
|= DPIO_DCLKP_EN
;
1611 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), tmp
);
1614 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1619 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1621 /* Check PLL is locked */
1622 if (wait_for(((I915_READ(DPLL(pipe
)) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1623 DRM_ERROR("PLL %d failed to lock\n", pipe
);
1625 /* not sure when this should be written */
1626 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1627 POSTING_READ(DPLL_MD(pipe
));
1629 mutex_unlock(&dev_priv
->dpio_lock
);
1632 static int intel_num_dvo_pipes(struct drm_device
*dev
)
1634 struct intel_crtc
*crtc
;
1637 for_each_intel_crtc(dev
, crtc
)
1638 count
+= crtc
->active
&&
1639 intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
);
1644 static void i9xx_enable_pll(struct intel_crtc
*crtc
)
1646 struct drm_device
*dev
= crtc
->base
.dev
;
1647 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1648 int reg
= DPLL(crtc
->pipe
);
1649 u32 dpll
= crtc
->config
->dpll_hw_state
.dpll
;
1651 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1653 /* No really, not for ILK+ */
1654 BUG_ON(INTEL_INFO(dev
)->gen
>= 5);
1656 /* PLL is protected by panel, make sure we can write it */
1657 if (IS_MOBILE(dev
) && !IS_I830(dev
))
1658 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1660 /* Enable DVO 2x clock on both PLLs if necessary */
1661 if (IS_I830(dev
) && intel_num_dvo_pipes(dev
) > 0) {
1663 * It appears to be important that we don't enable this
1664 * for the current pipe before otherwise configuring the
1665 * PLL. No idea how this should be handled if multiple
1666 * DVO outputs are enabled simultaneosly.
1668 dpll
|= DPLL_DVO_2X_MODE
;
1669 I915_WRITE(DPLL(!crtc
->pipe
),
1670 I915_READ(DPLL(!crtc
->pipe
)) | DPLL_DVO_2X_MODE
);
1673 /* Wait for the clocks to stabilize. */
1677 if (INTEL_INFO(dev
)->gen
>= 4) {
1678 I915_WRITE(DPLL_MD(crtc
->pipe
),
1679 crtc
->config
->dpll_hw_state
.dpll_md
);
1681 /* The pixel multiplier can only be updated once the
1682 * DPLL is enabled and the clocks are stable.
1684 * So write it again.
1686 I915_WRITE(reg
, dpll
);
1689 /* We do this three times for luck */
1690 I915_WRITE(reg
, dpll
);
1692 udelay(150); /* wait for warmup */
1693 I915_WRITE(reg
, dpll
);
1695 udelay(150); /* wait for warmup */
1696 I915_WRITE(reg
, dpll
);
1698 udelay(150); /* wait for warmup */
1702 * i9xx_disable_pll - disable a PLL
1703 * @dev_priv: i915 private structure
1704 * @pipe: pipe PLL to disable
1706 * Disable the PLL for @pipe, making sure the pipe is off first.
1708 * Note! This is for pre-ILK only.
1710 static void i9xx_disable_pll(struct intel_crtc
*crtc
)
1712 struct drm_device
*dev
= crtc
->base
.dev
;
1713 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1714 enum pipe pipe
= crtc
->pipe
;
1716 /* Disable DVO 2x clock on both PLLs if necessary */
1718 intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
) &&
1719 intel_num_dvo_pipes(dev
) == 1) {
1720 I915_WRITE(DPLL(PIPE_B
),
1721 I915_READ(DPLL(PIPE_B
)) & ~DPLL_DVO_2X_MODE
);
1722 I915_WRITE(DPLL(PIPE_A
),
1723 I915_READ(DPLL(PIPE_A
)) & ~DPLL_DVO_2X_MODE
);
1726 /* Don't disable pipe or pipe PLLs if needed */
1727 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1728 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1731 /* Make sure the pipe isn't still relying on us */
1732 assert_pipe_disabled(dev_priv
, pipe
);
1734 I915_WRITE(DPLL(pipe
), 0);
1735 POSTING_READ(DPLL(pipe
));
1738 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1742 /* Make sure the pipe isn't still relying on us */
1743 assert_pipe_disabled(dev_priv
, pipe
);
1746 * Leave integrated clock source and reference clock enabled for pipe B.
1747 * The latter is needed for VGA hotplug / manual detection.
1750 val
= DPLL_INTEGRATED_CRI_CLK_VLV
| DPLL_REFA_CLK_ENABLE_VLV
;
1751 I915_WRITE(DPLL(pipe
), val
);
1752 POSTING_READ(DPLL(pipe
));
1756 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1758 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1761 /* Make sure the pipe isn't still relying on us */
1762 assert_pipe_disabled(dev_priv
, pipe
);
1764 /* Set PLL en = 0 */
1765 val
= DPLL_SSC_REF_CLOCK_CHV
| DPLL_REFA_CLK_ENABLE_VLV
;
1767 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1768 I915_WRITE(DPLL(pipe
), val
);
1769 POSTING_READ(DPLL(pipe
));
1771 mutex_lock(&dev_priv
->dpio_lock
);
1773 /* Disable 10bit clock to display controller */
1774 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1775 val
&= ~DPIO_DCLKP_EN
;
1776 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1778 /* disable left/right clock distribution */
1779 if (pipe
!= PIPE_B
) {
1780 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
);
1781 val
&= ~(CHV_BUFLEFTENA1_MASK
| CHV_BUFRIGHTENA1_MASK
);
1782 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
, val
);
1784 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
);
1785 val
&= ~(CHV_BUFLEFTENA2_MASK
| CHV_BUFRIGHTENA2_MASK
);
1786 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
, val
);
1789 mutex_unlock(&dev_priv
->dpio_lock
);
1792 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1793 struct intel_digital_port
*dport
)
1798 switch (dport
->port
) {
1800 port_mask
= DPLL_PORTB_READY_MASK
;
1804 port_mask
= DPLL_PORTC_READY_MASK
;
1808 port_mask
= DPLL_PORTD_READY_MASK
;
1809 dpll_reg
= DPIO_PHY_STATUS
;
1815 if (wait_for((I915_READ(dpll_reg
) & port_mask
) == 0, 1000))
1816 WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
1817 port_name(dport
->port
), I915_READ(dpll_reg
));
1820 static void intel_prepare_shared_dpll(struct intel_crtc
*crtc
)
1822 struct drm_device
*dev
= crtc
->base
.dev
;
1823 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1824 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1826 if (WARN_ON(pll
== NULL
))
1829 WARN_ON(!pll
->config
.crtc_mask
);
1830 if (pll
->active
== 0) {
1831 DRM_DEBUG_DRIVER("setting up %s\n", pll
->name
);
1833 assert_shared_dpll_disabled(dev_priv
, pll
);
1835 pll
->mode_set(dev_priv
, pll
);
1840 * intel_enable_shared_dpll - enable PCH PLL
1841 * @dev_priv: i915 private structure
1842 * @pipe: pipe PLL to enable
1844 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1845 * drives the transcoder clock.
1847 static void intel_enable_shared_dpll(struct intel_crtc
*crtc
)
1849 struct drm_device
*dev
= crtc
->base
.dev
;
1850 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1851 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1853 if (WARN_ON(pll
== NULL
))
1856 if (WARN_ON(pll
->config
.crtc_mask
== 0))
1859 DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n",
1860 pll
->name
, pll
->active
, pll
->on
,
1861 crtc
->base
.base
.id
);
1863 if (pll
->active
++) {
1865 assert_shared_dpll_enabled(dev_priv
, pll
);
1870 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
1872 DRM_DEBUG_KMS("enabling %s\n", pll
->name
);
1873 pll
->enable(dev_priv
, pll
);
1877 static void intel_disable_shared_dpll(struct intel_crtc
*crtc
)
1879 struct drm_device
*dev
= crtc
->base
.dev
;
1880 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1881 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1883 /* PCH only available on ILK+ */
1884 BUG_ON(INTEL_INFO(dev
)->gen
< 5);
1885 if (WARN_ON(pll
== NULL
))
1888 if (WARN_ON(pll
->config
.crtc_mask
== 0))
1891 DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
1892 pll
->name
, pll
->active
, pll
->on
,
1893 crtc
->base
.base
.id
);
1895 if (WARN_ON(pll
->active
== 0)) {
1896 assert_shared_dpll_disabled(dev_priv
, pll
);
1900 assert_shared_dpll_enabled(dev_priv
, pll
);
1905 DRM_DEBUG_KMS("disabling %s\n", pll
->name
);
1906 pll
->disable(dev_priv
, pll
);
1909 intel_display_power_put(dev_priv
, POWER_DOMAIN_PLLS
);
1912 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1915 struct drm_device
*dev
= dev_priv
->dev
;
1916 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1917 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1918 uint32_t reg
, val
, pipeconf_val
;
1920 /* PCH only available on ILK+ */
1921 BUG_ON(!HAS_PCH_SPLIT(dev
));
1923 /* Make sure PCH DPLL is enabled */
1924 assert_shared_dpll_enabled(dev_priv
,
1925 intel_crtc_to_shared_dpll(intel_crtc
));
1927 /* FDI must be feeding us bits for PCH ports */
1928 assert_fdi_tx_enabled(dev_priv
, pipe
);
1929 assert_fdi_rx_enabled(dev_priv
, pipe
);
1931 if (HAS_PCH_CPT(dev
)) {
1932 /* Workaround: Set the timing override bit before enabling the
1933 * pch transcoder. */
1934 reg
= TRANS_CHICKEN2(pipe
);
1935 val
= I915_READ(reg
);
1936 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1937 I915_WRITE(reg
, val
);
1940 reg
= PCH_TRANSCONF(pipe
);
1941 val
= I915_READ(reg
);
1942 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1944 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1946 * make the BPC in transcoder be consistent with
1947 * that in pipeconf reg.
1949 val
&= ~PIPECONF_BPC_MASK
;
1950 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
1953 val
&= ~TRANS_INTERLACE_MASK
;
1954 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
1955 if (HAS_PCH_IBX(dev_priv
->dev
) &&
1956 intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
1957 val
|= TRANS_LEGACY_INTERLACED_ILK
;
1959 val
|= TRANS_INTERLACED
;
1961 val
|= TRANS_PROGRESSIVE
;
1963 I915_WRITE(reg
, val
| TRANS_ENABLE
);
1964 if (wait_for(I915_READ(reg
) & TRANS_STATE_ENABLE
, 100))
1965 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
1968 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1969 enum transcoder cpu_transcoder
)
1971 u32 val
, pipeconf_val
;
1973 /* PCH only available on ILK+ */
1974 BUG_ON(!HAS_PCH_SPLIT(dev_priv
->dev
));
1976 /* FDI must be feeding us bits for PCH ports */
1977 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
1978 assert_fdi_rx_enabled(dev_priv
, TRANSCODER_A
);
1980 /* Workaround: set timing override bit. */
1981 val
= I915_READ(_TRANSA_CHICKEN2
);
1982 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1983 I915_WRITE(_TRANSA_CHICKEN2
, val
);
1986 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
1988 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
1989 PIPECONF_INTERLACED_ILK
)
1990 val
|= TRANS_INTERLACED
;
1992 val
|= TRANS_PROGRESSIVE
;
1994 I915_WRITE(LPT_TRANSCONF
, val
);
1995 if (wait_for(I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
, 100))
1996 DRM_ERROR("Failed to enable PCH transcoder\n");
1999 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
2002 struct drm_device
*dev
= dev_priv
->dev
;
2005 /* FDI relies on the transcoder */
2006 assert_fdi_tx_disabled(dev_priv
, pipe
);
2007 assert_fdi_rx_disabled(dev_priv
, pipe
);
2009 /* Ports must be off as well */
2010 assert_pch_ports_disabled(dev_priv
, pipe
);
2012 reg
= PCH_TRANSCONF(pipe
);
2013 val
= I915_READ(reg
);
2014 val
&= ~TRANS_ENABLE
;
2015 I915_WRITE(reg
, val
);
2016 /* wait for PCH transcoder off, transcoder state */
2017 if (wait_for((I915_READ(reg
) & TRANS_STATE_ENABLE
) == 0, 50))
2018 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
2020 if (!HAS_PCH_IBX(dev
)) {
2021 /* Workaround: Clear the timing override chicken bit again. */
2022 reg
= TRANS_CHICKEN2(pipe
);
2023 val
= I915_READ(reg
);
2024 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
2025 I915_WRITE(reg
, val
);
2029 static void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
2033 val
= I915_READ(LPT_TRANSCONF
);
2034 val
&= ~TRANS_ENABLE
;
2035 I915_WRITE(LPT_TRANSCONF
, val
);
2036 /* wait for PCH transcoder off, transcoder state */
2037 if (wait_for((I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
) == 0, 50))
2038 DRM_ERROR("Failed to disable PCH transcoder\n");
2040 /* Workaround: clear timing override bit. */
2041 val
= I915_READ(_TRANSA_CHICKEN2
);
2042 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
2043 I915_WRITE(_TRANSA_CHICKEN2
, val
);
2047 * intel_enable_pipe - enable a pipe, asserting requirements
2048 * @crtc: crtc responsible for the pipe
2050 * Enable @crtc's pipe, making sure that various hardware specific requirements
2051 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
2053 static void intel_enable_pipe(struct intel_crtc
*crtc
)
2055 struct drm_device
*dev
= crtc
->base
.dev
;
2056 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2057 enum pipe pipe
= crtc
->pipe
;
2058 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
2060 enum pipe pch_transcoder
;
2064 assert_planes_disabled(dev_priv
, pipe
);
2065 assert_cursor_disabled(dev_priv
, pipe
);
2066 assert_sprites_disabled(dev_priv
, pipe
);
2068 if (HAS_PCH_LPT(dev_priv
->dev
))
2069 pch_transcoder
= TRANSCODER_A
;
2071 pch_transcoder
= pipe
;
2074 * A pipe without a PLL won't actually be able to drive bits from
2075 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
2078 if (!HAS_PCH_SPLIT(dev_priv
->dev
))
2079 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
))
2080 assert_dsi_pll_enabled(dev_priv
);
2082 assert_pll_enabled(dev_priv
, pipe
);
2084 if (crtc
->config
->has_pch_encoder
) {
2085 /* if driving the PCH, we need FDI enabled */
2086 assert_fdi_rx_pll_enabled(dev_priv
, pch_transcoder
);
2087 assert_fdi_tx_pll_enabled(dev_priv
,
2088 (enum pipe
) cpu_transcoder
);
2090 /* FIXME: assert CPU port conditions for SNB+ */
2093 reg
= PIPECONF(cpu_transcoder
);
2094 val
= I915_READ(reg
);
2095 if (val
& PIPECONF_ENABLE
) {
2096 WARN_ON(!((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
2097 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
)));
2101 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
2106 * intel_disable_pipe - disable a pipe, asserting requirements
2107 * @crtc: crtc whose pipes is to be disabled
2109 * Disable the pipe of @crtc, making sure that various hardware
2110 * specific requirements are met, if applicable, e.g. plane
2111 * disabled, panel fitter off, etc.
2113 * Will wait until the pipe has shut down before returning.
2115 static void intel_disable_pipe(struct intel_crtc
*crtc
)
2117 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
2118 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
2119 enum pipe pipe
= crtc
->pipe
;
2124 * Make sure planes won't keep trying to pump pixels to us,
2125 * or we might hang the display.
2127 assert_planes_disabled(dev_priv
, pipe
);
2128 assert_cursor_disabled(dev_priv
, pipe
);
2129 assert_sprites_disabled(dev_priv
, pipe
);
2131 reg
= PIPECONF(cpu_transcoder
);
2132 val
= I915_READ(reg
);
2133 if ((val
& PIPECONF_ENABLE
) == 0)
2137 * Double wide has implications for planes
2138 * so best keep it disabled when not needed.
2140 if (crtc
->config
->double_wide
)
2141 val
&= ~PIPECONF_DOUBLE_WIDE
;
2143 /* Don't disable pipe or pipe PLLs if needed */
2144 if (!(pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) &&
2145 !(pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
2146 val
&= ~PIPECONF_ENABLE
;
2148 I915_WRITE(reg
, val
);
2149 if ((val
& PIPECONF_ENABLE
) == 0)
2150 intel_wait_for_pipe_off(crtc
);
2154 * Plane regs are double buffered, going from enabled->disabled needs a
2155 * trigger in order to latch. The display address reg provides this.
2157 void intel_flush_primary_plane(struct drm_i915_private
*dev_priv
,
2160 struct drm_device
*dev
= dev_priv
->dev
;
2161 u32 reg
= INTEL_INFO(dev
)->gen
>= 4 ? DSPSURF(plane
) : DSPADDR(plane
);
2163 I915_WRITE(reg
, I915_READ(reg
));
2168 * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
2169 * @plane: plane to be enabled
2170 * @crtc: crtc for the plane
2172 * Enable @plane on @crtc, making sure that the pipe is running first.
2174 static void intel_enable_primary_hw_plane(struct drm_plane
*plane
,
2175 struct drm_crtc
*crtc
)
2177 struct drm_device
*dev
= plane
->dev
;
2178 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2179 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2181 /* If the pipe isn't enabled, we can't pump pixels and may hang */
2182 assert_pipe_enabled(dev_priv
, intel_crtc
->pipe
);
2184 if (intel_crtc
->primary_enabled
)
2187 intel_crtc
->primary_enabled
= true;
2189 dev_priv
->display
.update_primary_plane(crtc
, plane
->fb
,
2193 * BDW signals flip done immediately if the plane
2194 * is disabled, even if the plane enable is already
2195 * armed to occur at the next vblank :(
2197 if (IS_BROADWELL(dev
))
2198 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
2202 * intel_disable_primary_hw_plane - disable the primary hardware plane
2203 * @plane: plane to be disabled
2204 * @crtc: crtc for the plane
2206 * Disable @plane on @crtc, making sure that the pipe is running first.
2208 static void intel_disable_primary_hw_plane(struct drm_plane
*plane
,
2209 struct drm_crtc
*crtc
)
2211 struct drm_device
*dev
= plane
->dev
;
2212 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2213 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2215 if (WARN_ON(!intel_crtc
->active
))
2218 if (!intel_crtc
->primary_enabled
)
2221 intel_crtc
->primary_enabled
= false;
2223 dev_priv
->display
.update_primary_plane(crtc
, plane
->fb
,
2227 static bool need_vtd_wa(struct drm_device
*dev
)
2229 #ifdef CONFIG_INTEL_IOMMU
2230 if (INTEL_INFO(dev
)->gen
>= 6 && intel_iommu_gfx_mapped
)
2237 intel_tile_height(struct drm_device
*dev
, uint32_t pixel_format
,
2238 uint64_t fb_format_modifier
)
2240 unsigned int tile_height
;
2241 uint32_t pixel_bytes
;
2243 switch (fb_format_modifier
) {
2244 case DRM_FORMAT_MOD_NONE
:
2247 case I915_FORMAT_MOD_X_TILED
:
2248 tile_height
= IS_GEN2(dev
) ? 16 : 8;
2250 case I915_FORMAT_MOD_Y_TILED
:
2253 case I915_FORMAT_MOD_Yf_TILED
:
2254 pixel_bytes
= drm_format_plane_cpp(pixel_format
, 0);
2255 switch (pixel_bytes
) {
2269 "128-bit pixels are not supported for display!");
2275 MISSING_CASE(fb_format_modifier
);
2284 intel_fb_align_height(struct drm_device
*dev
, unsigned int height
,
2285 uint32_t pixel_format
, uint64_t fb_format_modifier
)
2287 return ALIGN(height
, intel_tile_height(dev
, pixel_format
,
2288 fb_format_modifier
));
2292 intel_pin_and_fence_fb_obj(struct drm_plane
*plane
,
2293 struct drm_framebuffer
*fb
,
2294 const struct drm_plane_state
*plane_state
,
2295 struct intel_engine_cs
*pipelined
)
2297 struct drm_device
*dev
= fb
->dev
;
2298 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2299 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2303 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
2305 switch (fb
->modifier
[0]) {
2306 case DRM_FORMAT_MOD_NONE
:
2307 if (INTEL_INFO(dev
)->gen
>= 9)
2308 alignment
= 256 * 1024;
2309 else if (IS_BROADWATER(dev
) || IS_CRESTLINE(dev
))
2310 alignment
= 128 * 1024;
2311 else if (INTEL_INFO(dev
)->gen
>= 4)
2312 alignment
= 4 * 1024;
2314 alignment
= 64 * 1024;
2316 case I915_FORMAT_MOD_X_TILED
:
2317 if (INTEL_INFO(dev
)->gen
>= 9)
2318 alignment
= 256 * 1024;
2320 /* pin() will align the object as required by fence */
2324 case I915_FORMAT_MOD_Y_TILED
:
2325 case I915_FORMAT_MOD_Yf_TILED
:
2326 if (WARN_ONCE(INTEL_INFO(dev
)->gen
< 9,
2327 "Y tiling bo slipped through, driver bug!\n"))
2329 alignment
= 1 * 1024 * 1024;
2332 MISSING_CASE(fb
->modifier
[0]);
2336 /* Note that the w/a also requires 64 PTE of padding following the
2337 * bo. We currently fill all unused PTE with the shadow page and so
2338 * we should always have valid PTE following the scanout preventing
2341 if (need_vtd_wa(dev
) && alignment
< 256 * 1024)
2342 alignment
= 256 * 1024;
2345 * Global gtt pte registers are special registers which actually forward
2346 * writes to a chunk of system memory. Which means that there is no risk
2347 * that the register values disappear as soon as we call
2348 * intel_runtime_pm_put(), so it is correct to wrap only the
2349 * pin/unpin/fence and not more.
2351 intel_runtime_pm_get(dev_priv
);
2353 dev_priv
->mm
.interruptible
= false;
2354 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, pipelined
,
2355 &i915_ggtt_view_normal
);
2357 goto err_interruptible
;
2359 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2360 * fence, whereas 965+ only requires a fence if using
2361 * framebuffer compression. For simplicity, we always install
2362 * a fence as the cost is not that onerous.
2364 ret
= i915_gem_object_get_fence(obj
);
2368 i915_gem_object_pin_fence(obj
);
2370 dev_priv
->mm
.interruptible
= true;
2371 intel_runtime_pm_put(dev_priv
);
2375 i915_gem_object_unpin_from_display_plane(obj
, &i915_ggtt_view_normal
);
2377 dev_priv
->mm
.interruptible
= true;
2378 intel_runtime_pm_put(dev_priv
);
2382 static void intel_unpin_fb_obj(struct drm_framebuffer
*fb
,
2383 const struct drm_plane_state
*plane_state
)
2385 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2387 WARN_ON(!mutex_is_locked(&obj
->base
.dev
->struct_mutex
));
2389 i915_gem_object_unpin_fence(obj
);
2390 i915_gem_object_unpin_from_display_plane(obj
, &i915_ggtt_view_normal
);
2393 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
2394 * is assumed to be a power-of-two. */
2395 unsigned long intel_gen4_compute_page_offset(int *x
, int *y
,
2396 unsigned int tiling_mode
,
2400 if (tiling_mode
!= I915_TILING_NONE
) {
2401 unsigned int tile_rows
, tiles
;
2406 tiles
= *x
/ (512/cpp
);
2409 return tile_rows
* pitch
* 8 + tiles
* 4096;
2411 unsigned int offset
;
2413 offset
= *y
* pitch
+ *x
* cpp
;
2415 *x
= (offset
& 4095) / cpp
;
2416 return offset
& -4096;
2420 static int i9xx_format_to_fourcc(int format
)
2423 case DISPPLANE_8BPP
:
2424 return DRM_FORMAT_C8
;
2425 case DISPPLANE_BGRX555
:
2426 return DRM_FORMAT_XRGB1555
;
2427 case DISPPLANE_BGRX565
:
2428 return DRM_FORMAT_RGB565
;
2430 case DISPPLANE_BGRX888
:
2431 return DRM_FORMAT_XRGB8888
;
2432 case DISPPLANE_RGBX888
:
2433 return DRM_FORMAT_XBGR8888
;
2434 case DISPPLANE_BGRX101010
:
2435 return DRM_FORMAT_XRGB2101010
;
2436 case DISPPLANE_RGBX101010
:
2437 return DRM_FORMAT_XBGR2101010
;
2441 static int skl_format_to_fourcc(int format
, bool rgb_order
, bool alpha
)
2444 case PLANE_CTL_FORMAT_RGB_565
:
2445 return DRM_FORMAT_RGB565
;
2447 case PLANE_CTL_FORMAT_XRGB_8888
:
2450 return DRM_FORMAT_ABGR8888
;
2452 return DRM_FORMAT_XBGR8888
;
2455 return DRM_FORMAT_ARGB8888
;
2457 return DRM_FORMAT_XRGB8888
;
2459 case PLANE_CTL_FORMAT_XRGB_2101010
:
2461 return DRM_FORMAT_XBGR2101010
;
2463 return DRM_FORMAT_XRGB2101010
;
2468 intel_alloc_plane_obj(struct intel_crtc
*crtc
,
2469 struct intel_initial_plane_config
*plane_config
)
2471 struct drm_device
*dev
= crtc
->base
.dev
;
2472 struct drm_i915_gem_object
*obj
= NULL
;
2473 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2474 struct drm_framebuffer
*fb
= &plane_config
->fb
->base
;
2475 u32 base_aligned
= round_down(plane_config
->base
, PAGE_SIZE
);
2476 u32 size_aligned
= round_up(plane_config
->base
+ plane_config
->size
,
2479 size_aligned
-= base_aligned
;
2481 if (plane_config
->size
== 0)
2484 obj
= i915_gem_object_create_stolen_for_preallocated(dev
,
2491 obj
->tiling_mode
= plane_config
->tiling
;
2492 if (obj
->tiling_mode
== I915_TILING_X
)
2493 obj
->stride
= fb
->pitches
[0];
2495 mode_cmd
.pixel_format
= fb
->pixel_format
;
2496 mode_cmd
.width
= fb
->width
;
2497 mode_cmd
.height
= fb
->height
;
2498 mode_cmd
.pitches
[0] = fb
->pitches
[0];
2499 mode_cmd
.modifier
[0] = fb
->modifier
[0];
2500 mode_cmd
.flags
= DRM_MODE_FB_MODIFIERS
;
2502 mutex_lock(&dev
->struct_mutex
);
2504 if (intel_framebuffer_init(dev
, to_intel_framebuffer(fb
),
2506 DRM_DEBUG_KMS("intel fb init failed\n");
2510 obj
->frontbuffer_bits
= INTEL_FRONTBUFFER_PRIMARY(crtc
->pipe
);
2511 mutex_unlock(&dev
->struct_mutex
);
2513 DRM_DEBUG_KMS("plane fb obj %p\n", obj
);
2517 drm_gem_object_unreference(&obj
->base
);
2518 mutex_unlock(&dev
->struct_mutex
);
2522 /* Update plane->state->fb to match plane->fb after driver-internal updates */
2524 update_state_fb(struct drm_plane
*plane
)
2526 if (plane
->fb
== plane
->state
->fb
)
2529 if (plane
->state
->fb
)
2530 drm_framebuffer_unreference(plane
->state
->fb
);
2531 plane
->state
->fb
= plane
->fb
;
2532 if (plane
->state
->fb
)
2533 drm_framebuffer_reference(plane
->state
->fb
);
2537 intel_find_plane_obj(struct intel_crtc
*intel_crtc
,
2538 struct intel_initial_plane_config
*plane_config
)
2540 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2541 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2543 struct intel_crtc
*i
;
2544 struct drm_i915_gem_object
*obj
;
2546 if (!plane_config
->fb
)
2549 if (intel_alloc_plane_obj(intel_crtc
, plane_config
)) {
2550 struct drm_plane
*primary
= intel_crtc
->base
.primary
;
2552 primary
->fb
= &plane_config
->fb
->base
;
2553 primary
->state
->crtc
= &intel_crtc
->base
;
2554 update_state_fb(primary
);
2559 kfree(plane_config
->fb
);
2562 * Failed to alloc the obj, check to see if we should share
2563 * an fb with another CRTC instead
2565 for_each_crtc(dev
, c
) {
2566 i
= to_intel_crtc(c
);
2568 if (c
== &intel_crtc
->base
)
2574 obj
= intel_fb_obj(c
->primary
->fb
);
2578 if (i915_gem_obj_ggtt_offset(obj
) == plane_config
->base
) {
2579 struct drm_plane
*primary
= intel_crtc
->base
.primary
;
2581 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2582 dev_priv
->preserve_bios_swizzle
= true;
2584 drm_framebuffer_reference(c
->primary
->fb
);
2585 primary
->fb
= c
->primary
->fb
;
2586 primary
->state
->crtc
= &intel_crtc
->base
;
2587 update_state_fb(intel_crtc
->base
.primary
);
2588 obj
->frontbuffer_bits
|= INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
);
2594 static void i9xx_update_primary_plane(struct drm_crtc
*crtc
,
2595 struct drm_framebuffer
*fb
,
2598 struct drm_device
*dev
= crtc
->dev
;
2599 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2600 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2601 struct drm_i915_gem_object
*obj
;
2602 int plane
= intel_crtc
->plane
;
2603 unsigned long linear_offset
;
2605 u32 reg
= DSPCNTR(plane
);
2608 if (!intel_crtc
->primary_enabled
) {
2610 if (INTEL_INFO(dev
)->gen
>= 4)
2611 I915_WRITE(DSPSURF(plane
), 0);
2613 I915_WRITE(DSPADDR(plane
), 0);
2618 obj
= intel_fb_obj(fb
);
2619 if (WARN_ON(obj
== NULL
))
2622 pixel_size
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2624 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2626 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2628 if (INTEL_INFO(dev
)->gen
< 4) {
2629 if (intel_crtc
->pipe
== PIPE_B
)
2630 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
2632 /* pipesrc and dspsize control the size that is scaled from,
2633 * which should always be the user's requested size.
2635 I915_WRITE(DSPSIZE(plane
),
2636 ((intel_crtc
->config
->pipe_src_h
- 1) << 16) |
2637 (intel_crtc
->config
->pipe_src_w
- 1));
2638 I915_WRITE(DSPPOS(plane
), 0);
2639 } else if (IS_CHERRYVIEW(dev
) && plane
== PLANE_B
) {
2640 I915_WRITE(PRIMSIZE(plane
),
2641 ((intel_crtc
->config
->pipe_src_h
- 1) << 16) |
2642 (intel_crtc
->config
->pipe_src_w
- 1));
2643 I915_WRITE(PRIMPOS(plane
), 0);
2644 I915_WRITE(PRIMCNSTALPHA(plane
), 0);
2647 switch (fb
->pixel_format
) {
2649 dspcntr
|= DISPPLANE_8BPP
;
2651 case DRM_FORMAT_XRGB1555
:
2652 case DRM_FORMAT_ARGB1555
:
2653 dspcntr
|= DISPPLANE_BGRX555
;
2655 case DRM_FORMAT_RGB565
:
2656 dspcntr
|= DISPPLANE_BGRX565
;
2658 case DRM_FORMAT_XRGB8888
:
2659 case DRM_FORMAT_ARGB8888
:
2660 dspcntr
|= DISPPLANE_BGRX888
;
2662 case DRM_FORMAT_XBGR8888
:
2663 case DRM_FORMAT_ABGR8888
:
2664 dspcntr
|= DISPPLANE_RGBX888
;
2666 case DRM_FORMAT_XRGB2101010
:
2667 case DRM_FORMAT_ARGB2101010
:
2668 dspcntr
|= DISPPLANE_BGRX101010
;
2670 case DRM_FORMAT_XBGR2101010
:
2671 case DRM_FORMAT_ABGR2101010
:
2672 dspcntr
|= DISPPLANE_RGBX101010
;
2678 if (INTEL_INFO(dev
)->gen
>= 4 &&
2679 obj
->tiling_mode
!= I915_TILING_NONE
)
2680 dspcntr
|= DISPPLANE_TILED
;
2683 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2685 linear_offset
= y
* fb
->pitches
[0] + x
* pixel_size
;
2687 if (INTEL_INFO(dev
)->gen
>= 4) {
2688 intel_crtc
->dspaddr_offset
=
2689 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2692 linear_offset
-= intel_crtc
->dspaddr_offset
;
2694 intel_crtc
->dspaddr_offset
= linear_offset
;
2697 if (crtc
->primary
->state
->rotation
== BIT(DRM_ROTATE_180
)) {
2698 dspcntr
|= DISPPLANE_ROTATE_180
;
2700 x
+= (intel_crtc
->config
->pipe_src_w
- 1);
2701 y
+= (intel_crtc
->config
->pipe_src_h
- 1);
2703 /* Finding the last pixel of the last line of the display
2704 data and adding to linear_offset*/
2706 (intel_crtc
->config
->pipe_src_h
- 1) * fb
->pitches
[0] +
2707 (intel_crtc
->config
->pipe_src_w
- 1) * pixel_size
;
2710 I915_WRITE(reg
, dspcntr
);
2712 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2713 if (INTEL_INFO(dev
)->gen
>= 4) {
2714 I915_WRITE(DSPSURF(plane
),
2715 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2716 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2717 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2719 I915_WRITE(DSPADDR(plane
), i915_gem_obj_ggtt_offset(obj
) + linear_offset
);
2723 static void ironlake_update_primary_plane(struct drm_crtc
*crtc
,
2724 struct drm_framebuffer
*fb
,
2727 struct drm_device
*dev
= crtc
->dev
;
2728 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2729 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2730 struct drm_i915_gem_object
*obj
;
2731 int plane
= intel_crtc
->plane
;
2732 unsigned long linear_offset
;
2734 u32 reg
= DSPCNTR(plane
);
2737 if (!intel_crtc
->primary_enabled
) {
2739 I915_WRITE(DSPSURF(plane
), 0);
2744 obj
= intel_fb_obj(fb
);
2745 if (WARN_ON(obj
== NULL
))
2748 pixel_size
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2750 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2752 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2754 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2755 dspcntr
|= DISPPLANE_PIPE_CSC_ENABLE
;
2757 switch (fb
->pixel_format
) {
2759 dspcntr
|= DISPPLANE_8BPP
;
2761 case DRM_FORMAT_RGB565
:
2762 dspcntr
|= DISPPLANE_BGRX565
;
2764 case DRM_FORMAT_XRGB8888
:
2765 case DRM_FORMAT_ARGB8888
:
2766 dspcntr
|= DISPPLANE_BGRX888
;
2768 case DRM_FORMAT_XBGR8888
:
2769 case DRM_FORMAT_ABGR8888
:
2770 dspcntr
|= DISPPLANE_RGBX888
;
2772 case DRM_FORMAT_XRGB2101010
:
2773 case DRM_FORMAT_ARGB2101010
:
2774 dspcntr
|= DISPPLANE_BGRX101010
;
2776 case DRM_FORMAT_XBGR2101010
:
2777 case DRM_FORMAT_ABGR2101010
:
2778 dspcntr
|= DISPPLANE_RGBX101010
;
2784 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2785 dspcntr
|= DISPPLANE_TILED
;
2787 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
))
2788 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2790 linear_offset
= y
* fb
->pitches
[0] + x
* pixel_size
;
2791 intel_crtc
->dspaddr_offset
=
2792 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2795 linear_offset
-= intel_crtc
->dspaddr_offset
;
2796 if (crtc
->primary
->state
->rotation
== BIT(DRM_ROTATE_180
)) {
2797 dspcntr
|= DISPPLANE_ROTATE_180
;
2799 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
)) {
2800 x
+= (intel_crtc
->config
->pipe_src_w
- 1);
2801 y
+= (intel_crtc
->config
->pipe_src_h
- 1);
2803 /* Finding the last pixel of the last line of the display
2804 data and adding to linear_offset*/
2806 (intel_crtc
->config
->pipe_src_h
- 1) * fb
->pitches
[0] +
2807 (intel_crtc
->config
->pipe_src_w
- 1) * pixel_size
;
2811 I915_WRITE(reg
, dspcntr
);
2813 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2814 I915_WRITE(DSPSURF(plane
),
2815 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2816 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2817 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
2819 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2820 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2825 u32
intel_fb_stride_alignment(struct drm_device
*dev
, uint64_t fb_modifier
,
2826 uint32_t pixel_format
)
2828 u32 bits_per_pixel
= drm_format_plane_cpp(pixel_format
, 0) * 8;
2831 * The stride is either expressed as a multiple of 64 bytes
2832 * chunks for linear buffers or in number of tiles for tiled
2835 switch (fb_modifier
) {
2836 case DRM_FORMAT_MOD_NONE
:
2838 case I915_FORMAT_MOD_X_TILED
:
2839 if (INTEL_INFO(dev
)->gen
== 2)
2842 case I915_FORMAT_MOD_Y_TILED
:
2843 /* No need to check for old gens and Y tiling since this is
2844 * about the display engine and those will be blocked before
2848 case I915_FORMAT_MOD_Yf_TILED
:
2849 if (bits_per_pixel
== 8)
2854 MISSING_CASE(fb_modifier
);
2859 static void skylake_update_primary_plane(struct drm_crtc
*crtc
,
2860 struct drm_framebuffer
*fb
,
2863 struct drm_device
*dev
= crtc
->dev
;
2864 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2865 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2866 struct drm_i915_gem_object
*obj
;
2867 int pipe
= intel_crtc
->pipe
;
2868 u32 plane_ctl
, stride_div
;
2870 if (!intel_crtc
->primary_enabled
) {
2871 I915_WRITE(PLANE_CTL(pipe
, 0), 0);
2872 I915_WRITE(PLANE_SURF(pipe
, 0), 0);
2873 POSTING_READ(PLANE_CTL(pipe
, 0));
2877 plane_ctl
= PLANE_CTL_ENABLE
|
2878 PLANE_CTL_PIPE_GAMMA_ENABLE
|
2879 PLANE_CTL_PIPE_CSC_ENABLE
;
2881 switch (fb
->pixel_format
) {
2882 case DRM_FORMAT_RGB565
:
2883 plane_ctl
|= PLANE_CTL_FORMAT_RGB_565
;
2885 case DRM_FORMAT_XRGB8888
:
2886 plane_ctl
|= PLANE_CTL_FORMAT_XRGB_8888
;
2888 case DRM_FORMAT_ARGB8888
:
2889 plane_ctl
|= PLANE_CTL_FORMAT_XRGB_8888
;
2890 plane_ctl
|= PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
2892 case DRM_FORMAT_XBGR8888
:
2893 plane_ctl
|= PLANE_CTL_ORDER_RGBX
;
2894 plane_ctl
|= PLANE_CTL_FORMAT_XRGB_8888
;
2896 case DRM_FORMAT_ABGR8888
:
2897 plane_ctl
|= PLANE_CTL_ORDER_RGBX
;
2898 plane_ctl
|= PLANE_CTL_FORMAT_XRGB_8888
;
2899 plane_ctl
|= PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
2901 case DRM_FORMAT_XRGB2101010
:
2902 plane_ctl
|= PLANE_CTL_FORMAT_XRGB_2101010
;
2904 case DRM_FORMAT_XBGR2101010
:
2905 plane_ctl
|= PLANE_CTL_ORDER_RGBX
;
2906 plane_ctl
|= PLANE_CTL_FORMAT_XRGB_2101010
;
2912 switch (fb
->modifier
[0]) {
2913 case DRM_FORMAT_MOD_NONE
:
2915 case I915_FORMAT_MOD_X_TILED
:
2916 plane_ctl
|= PLANE_CTL_TILED_X
;
2918 case I915_FORMAT_MOD_Y_TILED
:
2919 plane_ctl
|= PLANE_CTL_TILED_Y
;
2921 case I915_FORMAT_MOD_Yf_TILED
:
2922 plane_ctl
|= PLANE_CTL_TILED_YF
;
2925 MISSING_CASE(fb
->modifier
[0]);
2928 plane_ctl
|= PLANE_CTL_PLANE_GAMMA_DISABLE
;
2929 if (crtc
->primary
->state
->rotation
== BIT(DRM_ROTATE_180
))
2930 plane_ctl
|= PLANE_CTL_ROTATE_180
;
2932 obj
= intel_fb_obj(fb
);
2933 stride_div
= intel_fb_stride_alignment(dev
, fb
->modifier
[0],
2936 I915_WRITE(PLANE_CTL(pipe
, 0), plane_ctl
);
2938 I915_WRITE(PLANE_POS(pipe
, 0), 0);
2939 I915_WRITE(PLANE_OFFSET(pipe
, 0), (y
<< 16) | x
);
2940 I915_WRITE(PLANE_SIZE(pipe
, 0),
2941 (intel_crtc
->config
->pipe_src_h
- 1) << 16 |
2942 (intel_crtc
->config
->pipe_src_w
- 1));
2943 I915_WRITE(PLANE_STRIDE(pipe
, 0), fb
->pitches
[0] / stride_div
);
2944 I915_WRITE(PLANE_SURF(pipe
, 0), i915_gem_obj_ggtt_offset(obj
));
2946 POSTING_READ(PLANE_SURF(pipe
, 0));
2949 /* Assume fb object is pinned & idle & fenced and just update base pointers */
2951 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
2952 int x
, int y
, enum mode_set_atomic state
)
2954 struct drm_device
*dev
= crtc
->dev
;
2955 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2957 if (dev_priv
->display
.disable_fbc
)
2958 dev_priv
->display
.disable_fbc(dev
);
2960 dev_priv
->display
.update_primary_plane(crtc
, fb
, x
, y
);
2965 static void intel_complete_page_flips(struct drm_device
*dev
)
2967 struct drm_crtc
*crtc
;
2969 for_each_crtc(dev
, crtc
) {
2970 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2971 enum plane plane
= intel_crtc
->plane
;
2973 intel_prepare_page_flip(dev
, plane
);
2974 intel_finish_page_flip_plane(dev
, plane
);
2978 static void intel_update_primary_planes(struct drm_device
*dev
)
2980 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2981 struct drm_crtc
*crtc
;
2983 for_each_crtc(dev
, crtc
) {
2984 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2986 drm_modeset_lock(&crtc
->mutex
, NULL
);
2988 * FIXME: Once we have proper support for primary planes (and
2989 * disabling them without disabling the entire crtc) allow again
2990 * a NULL crtc->primary->fb.
2992 if (intel_crtc
->active
&& crtc
->primary
->fb
)
2993 dev_priv
->display
.update_primary_plane(crtc
,
2997 drm_modeset_unlock(&crtc
->mutex
);
3001 void intel_prepare_reset(struct drm_device
*dev
)
3003 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3004 struct intel_crtc
*crtc
;
3006 /* no reset support for gen2 */
3010 /* reset doesn't touch the display */
3011 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
3014 drm_modeset_lock_all(dev
);
3017 * Disabling the crtcs gracefully seems nicer. Also the
3018 * g33 docs say we should at least disable all the planes.
3020 for_each_intel_crtc(dev
, crtc
) {
3022 dev_priv
->display
.crtc_disable(&crtc
->base
);
3026 void intel_finish_reset(struct drm_device
*dev
)
3028 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3031 * Flips in the rings will be nuked by the reset,
3032 * so complete all pending flips so that user space
3033 * will get its events and not get stuck.
3035 intel_complete_page_flips(dev
);
3037 /* no reset support for gen2 */
3041 /* reset doesn't touch the display */
3042 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
)) {
3044 * Flips in the rings have been nuked by the reset,
3045 * so update the base address of all primary
3046 * planes to the the last fb to make sure we're
3047 * showing the correct fb after a reset.
3049 intel_update_primary_planes(dev
);
3054 * The display has been reset as well,
3055 * so need a full re-initialization.
3057 intel_runtime_pm_disable_interrupts(dev_priv
);
3058 intel_runtime_pm_enable_interrupts(dev_priv
);
3060 intel_modeset_init_hw(dev
);
3062 spin_lock_irq(&dev_priv
->irq_lock
);
3063 if (dev_priv
->display
.hpd_irq_setup
)
3064 dev_priv
->display
.hpd_irq_setup(dev
);
3065 spin_unlock_irq(&dev_priv
->irq_lock
);
3067 intel_modeset_setup_hw_state(dev
, true);
3069 intel_hpd_init(dev_priv
);
3071 drm_modeset_unlock_all(dev
);
3075 intel_finish_fb(struct drm_framebuffer
*old_fb
)
3077 struct drm_i915_gem_object
*obj
= intel_fb_obj(old_fb
);
3078 struct drm_i915_private
*dev_priv
= obj
->base
.dev
->dev_private
;
3079 bool was_interruptible
= dev_priv
->mm
.interruptible
;
3082 /* Big Hammer, we also need to ensure that any pending
3083 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
3084 * current scanout is retired before unpinning the old
3087 * This should only fail upon a hung GPU, in which case we
3088 * can safely continue.
3090 dev_priv
->mm
.interruptible
= false;
3091 ret
= i915_gem_object_finish_gpu(obj
);
3092 dev_priv
->mm
.interruptible
= was_interruptible
;
3097 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
3099 struct drm_device
*dev
= crtc
->dev
;
3100 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3101 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3104 if (i915_reset_in_progress(&dev_priv
->gpu_error
) ||
3105 intel_crtc
->reset_counter
!= atomic_read(&dev_priv
->gpu_error
.reset_counter
))
3108 spin_lock_irq(&dev
->event_lock
);
3109 pending
= to_intel_crtc(crtc
)->unpin_work
!= NULL
;
3110 spin_unlock_irq(&dev
->event_lock
);
3115 static void intel_update_pipe_size(struct intel_crtc
*crtc
)
3117 struct drm_device
*dev
= crtc
->base
.dev
;
3118 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3119 const struct drm_display_mode
*adjusted_mode
;
3125 * Update pipe size and adjust fitter if needed: the reason for this is
3126 * that in compute_mode_changes we check the native mode (not the pfit
3127 * mode) to see if we can flip rather than do a full mode set. In the
3128 * fastboot case, we'll flip, but if we don't update the pipesrc and
3129 * pfit state, we'll end up with a big fb scanned out into the wrong
3132 * To fix this properly, we need to hoist the checks up into
3133 * compute_mode_changes (or above), check the actual pfit state and
3134 * whether the platform allows pfit disable with pipe active, and only
3135 * then update the pipesrc and pfit state, even on the flip path.
3138 adjusted_mode
= &crtc
->config
->base
.adjusted_mode
;
3140 I915_WRITE(PIPESRC(crtc
->pipe
),
3141 ((adjusted_mode
->crtc_hdisplay
- 1) << 16) |
3142 (adjusted_mode
->crtc_vdisplay
- 1));
3143 if (!crtc
->config
->pch_pfit
.enabled
&&
3144 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) ||
3145 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
3146 I915_WRITE(PF_CTL(crtc
->pipe
), 0);
3147 I915_WRITE(PF_WIN_POS(crtc
->pipe
), 0);
3148 I915_WRITE(PF_WIN_SZ(crtc
->pipe
), 0);
3150 crtc
->config
->pipe_src_w
= adjusted_mode
->crtc_hdisplay
;
3151 crtc
->config
->pipe_src_h
= adjusted_mode
->crtc_vdisplay
;
3154 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
3156 struct drm_device
*dev
= crtc
->dev
;
3157 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3158 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3159 int pipe
= intel_crtc
->pipe
;
3162 /* enable normal train */
3163 reg
= FDI_TX_CTL(pipe
);
3164 temp
= I915_READ(reg
);
3165 if (IS_IVYBRIDGE(dev
)) {
3166 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3167 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3169 temp
&= ~FDI_LINK_TRAIN_NONE
;
3170 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3172 I915_WRITE(reg
, temp
);
3174 reg
= FDI_RX_CTL(pipe
);
3175 temp
= I915_READ(reg
);
3176 if (HAS_PCH_CPT(dev
)) {
3177 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3178 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
3180 temp
&= ~FDI_LINK_TRAIN_NONE
;
3181 temp
|= FDI_LINK_TRAIN_NONE
;
3183 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
3185 /* wait one idle pattern time */
3189 /* IVB wants error correction enabled */
3190 if (IS_IVYBRIDGE(dev
))
3191 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
3192 FDI_FE_ERRC_ENABLE
);
3195 /* The FDI link training functions for ILK/Ibexpeak. */
3196 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
3198 struct drm_device
*dev
= crtc
->dev
;
3199 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3200 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3201 int pipe
= intel_crtc
->pipe
;
3202 u32 reg
, temp
, tries
;
3204 /* FDI needs bits from pipe first */
3205 assert_pipe_enabled(dev_priv
, pipe
);
3207 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3209 reg
= FDI_RX_IMR(pipe
);
3210 temp
= I915_READ(reg
);
3211 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3212 temp
&= ~FDI_RX_BIT_LOCK
;
3213 I915_WRITE(reg
, temp
);
3217 /* enable CPU FDI TX and PCH FDI RX */
3218 reg
= FDI_TX_CTL(pipe
);
3219 temp
= I915_READ(reg
);
3220 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3221 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3222 temp
&= ~FDI_LINK_TRAIN_NONE
;
3223 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3224 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3226 reg
= FDI_RX_CTL(pipe
);
3227 temp
= I915_READ(reg
);
3228 temp
&= ~FDI_LINK_TRAIN_NONE
;
3229 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3230 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3235 /* Ironlake workaround, enable clock pointer after FDI enable*/
3236 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3237 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
3238 FDI_RX_PHASE_SYNC_POINTER_EN
);
3240 reg
= FDI_RX_IIR(pipe
);
3241 for (tries
= 0; tries
< 5; tries
++) {
3242 temp
= I915_READ(reg
);
3243 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3245 if ((temp
& FDI_RX_BIT_LOCK
)) {
3246 DRM_DEBUG_KMS("FDI train 1 done.\n");
3247 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3252 DRM_ERROR("FDI train 1 fail!\n");
3255 reg
= FDI_TX_CTL(pipe
);
3256 temp
= I915_READ(reg
);
3257 temp
&= ~FDI_LINK_TRAIN_NONE
;
3258 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3259 I915_WRITE(reg
, temp
);
3261 reg
= FDI_RX_CTL(pipe
);
3262 temp
= I915_READ(reg
);
3263 temp
&= ~FDI_LINK_TRAIN_NONE
;
3264 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3265 I915_WRITE(reg
, temp
);
3270 reg
= FDI_RX_IIR(pipe
);
3271 for (tries
= 0; tries
< 5; tries
++) {
3272 temp
= I915_READ(reg
);
3273 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3275 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3276 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3277 DRM_DEBUG_KMS("FDI train 2 done.\n");
3282 DRM_ERROR("FDI train 2 fail!\n");
3284 DRM_DEBUG_KMS("FDI train done\n");
3288 static const int snb_b_fdi_train_param
[] = {
3289 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
3290 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
3291 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
3292 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
3295 /* The FDI link training functions for SNB/Cougarpoint. */
3296 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
3298 struct drm_device
*dev
= crtc
->dev
;
3299 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3300 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3301 int pipe
= intel_crtc
->pipe
;
3302 u32 reg
, temp
, i
, retry
;
3304 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3306 reg
= FDI_RX_IMR(pipe
);
3307 temp
= I915_READ(reg
);
3308 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3309 temp
&= ~FDI_RX_BIT_LOCK
;
3310 I915_WRITE(reg
, temp
);
3315 /* enable CPU FDI TX and PCH FDI RX */
3316 reg
= FDI_TX_CTL(pipe
);
3317 temp
= I915_READ(reg
);
3318 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3319 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3320 temp
&= ~FDI_LINK_TRAIN_NONE
;
3321 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3322 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3324 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3325 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3327 I915_WRITE(FDI_RX_MISC(pipe
),
3328 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3330 reg
= FDI_RX_CTL(pipe
);
3331 temp
= I915_READ(reg
);
3332 if (HAS_PCH_CPT(dev
)) {
3333 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3334 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3336 temp
&= ~FDI_LINK_TRAIN_NONE
;
3337 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3339 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3344 for (i
= 0; i
< 4; i
++) {
3345 reg
= FDI_TX_CTL(pipe
);
3346 temp
= I915_READ(reg
);
3347 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3348 temp
|= snb_b_fdi_train_param
[i
];
3349 I915_WRITE(reg
, temp
);
3354 for (retry
= 0; retry
< 5; retry
++) {
3355 reg
= FDI_RX_IIR(pipe
);
3356 temp
= I915_READ(reg
);
3357 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3358 if (temp
& FDI_RX_BIT_LOCK
) {
3359 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3360 DRM_DEBUG_KMS("FDI train 1 done.\n");
3369 DRM_ERROR("FDI train 1 fail!\n");
3372 reg
= FDI_TX_CTL(pipe
);
3373 temp
= I915_READ(reg
);
3374 temp
&= ~FDI_LINK_TRAIN_NONE
;
3375 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3377 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3379 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3381 I915_WRITE(reg
, temp
);
3383 reg
= FDI_RX_CTL(pipe
);
3384 temp
= I915_READ(reg
);
3385 if (HAS_PCH_CPT(dev
)) {
3386 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3387 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3389 temp
&= ~FDI_LINK_TRAIN_NONE
;
3390 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3392 I915_WRITE(reg
, temp
);
3397 for (i
= 0; i
< 4; i
++) {
3398 reg
= FDI_TX_CTL(pipe
);
3399 temp
= I915_READ(reg
);
3400 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3401 temp
|= snb_b_fdi_train_param
[i
];
3402 I915_WRITE(reg
, temp
);
3407 for (retry
= 0; retry
< 5; retry
++) {
3408 reg
= FDI_RX_IIR(pipe
);
3409 temp
= I915_READ(reg
);
3410 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3411 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3412 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3413 DRM_DEBUG_KMS("FDI train 2 done.\n");
3422 DRM_ERROR("FDI train 2 fail!\n");
3424 DRM_DEBUG_KMS("FDI train done.\n");
3427 /* Manual link training for Ivy Bridge A0 parts */
3428 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
3430 struct drm_device
*dev
= crtc
->dev
;
3431 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3432 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3433 int pipe
= intel_crtc
->pipe
;
3434 u32 reg
, temp
, i
, j
;
3436 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3438 reg
= FDI_RX_IMR(pipe
);
3439 temp
= I915_READ(reg
);
3440 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3441 temp
&= ~FDI_RX_BIT_LOCK
;
3442 I915_WRITE(reg
, temp
);
3447 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3448 I915_READ(FDI_RX_IIR(pipe
)));
3450 /* Try each vswing and preemphasis setting twice before moving on */
3451 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
3452 /* disable first in case we need to retry */
3453 reg
= FDI_TX_CTL(pipe
);
3454 temp
= I915_READ(reg
);
3455 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
3456 temp
&= ~FDI_TX_ENABLE
;
3457 I915_WRITE(reg
, temp
);
3459 reg
= FDI_RX_CTL(pipe
);
3460 temp
= I915_READ(reg
);
3461 temp
&= ~FDI_LINK_TRAIN_AUTO
;
3462 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3463 temp
&= ~FDI_RX_ENABLE
;
3464 I915_WRITE(reg
, temp
);
3466 /* enable CPU FDI TX and PCH FDI RX */
3467 reg
= FDI_TX_CTL(pipe
);
3468 temp
= I915_READ(reg
);
3469 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3470 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3471 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
3472 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3473 temp
|= snb_b_fdi_train_param
[j
/2];
3474 temp
|= FDI_COMPOSITE_SYNC
;
3475 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3477 I915_WRITE(FDI_RX_MISC(pipe
),
3478 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3480 reg
= FDI_RX_CTL(pipe
);
3481 temp
= I915_READ(reg
);
3482 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3483 temp
|= FDI_COMPOSITE_SYNC
;
3484 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3487 udelay(1); /* should be 0.5us */
3489 for (i
= 0; i
< 4; i
++) {
3490 reg
= FDI_RX_IIR(pipe
);
3491 temp
= I915_READ(reg
);
3492 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3494 if (temp
& FDI_RX_BIT_LOCK
||
3495 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
3496 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3497 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3501 udelay(1); /* should be 0.5us */
3504 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
3509 reg
= FDI_TX_CTL(pipe
);
3510 temp
= I915_READ(reg
);
3511 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3512 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
3513 I915_WRITE(reg
, temp
);
3515 reg
= FDI_RX_CTL(pipe
);
3516 temp
= I915_READ(reg
);
3517 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3518 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3519 I915_WRITE(reg
, temp
);
3522 udelay(2); /* should be 1.5us */
3524 for (i
= 0; i
< 4; i
++) {
3525 reg
= FDI_RX_IIR(pipe
);
3526 temp
= I915_READ(reg
);
3527 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3529 if (temp
& FDI_RX_SYMBOL_LOCK
||
3530 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
3531 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3532 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
3536 udelay(2); /* should be 1.5us */
3539 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
3543 DRM_DEBUG_KMS("FDI train done.\n");
3546 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
3548 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3549 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3550 int pipe
= intel_crtc
->pipe
;
3554 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
3555 reg
= FDI_RX_CTL(pipe
);
3556 temp
= I915_READ(reg
);
3557 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
3558 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3559 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3560 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
3565 /* Switch from Rawclk to PCDclk */
3566 temp
= I915_READ(reg
);
3567 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
3572 /* Enable CPU FDI TX PLL, always on for Ironlake */
3573 reg
= FDI_TX_CTL(pipe
);
3574 temp
= I915_READ(reg
);
3575 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
3576 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
3583 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
3585 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3586 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3587 int pipe
= intel_crtc
->pipe
;
3590 /* Switch from PCDclk to Rawclk */
3591 reg
= FDI_RX_CTL(pipe
);
3592 temp
= I915_READ(reg
);
3593 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
3595 /* Disable CPU FDI TX PLL */
3596 reg
= FDI_TX_CTL(pipe
);
3597 temp
= I915_READ(reg
);
3598 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
3603 reg
= FDI_RX_CTL(pipe
);
3604 temp
= I915_READ(reg
);
3605 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
3607 /* Wait for the clocks to turn off. */
3612 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
3614 struct drm_device
*dev
= crtc
->dev
;
3615 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3616 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3617 int pipe
= intel_crtc
->pipe
;
3620 /* disable CPU FDI tx and PCH FDI rx */
3621 reg
= FDI_TX_CTL(pipe
);
3622 temp
= I915_READ(reg
);
3623 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
3626 reg
= FDI_RX_CTL(pipe
);
3627 temp
= I915_READ(reg
);
3628 temp
&= ~(0x7 << 16);
3629 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3630 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
3635 /* Ironlake workaround, disable clock pointer after downing FDI */
3636 if (HAS_PCH_IBX(dev
))
3637 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3639 /* still set train pattern 1 */
3640 reg
= FDI_TX_CTL(pipe
);
3641 temp
= I915_READ(reg
);
3642 temp
&= ~FDI_LINK_TRAIN_NONE
;
3643 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3644 I915_WRITE(reg
, temp
);
3646 reg
= FDI_RX_CTL(pipe
);
3647 temp
= I915_READ(reg
);
3648 if (HAS_PCH_CPT(dev
)) {
3649 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3650 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3652 temp
&= ~FDI_LINK_TRAIN_NONE
;
3653 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3655 /* BPC in FDI rx is consistent with that in PIPECONF */
3656 temp
&= ~(0x07 << 16);
3657 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3658 I915_WRITE(reg
, temp
);
3664 bool intel_has_pending_fb_unpin(struct drm_device
*dev
)
3666 struct intel_crtc
*crtc
;
3668 /* Note that we don't need to be called with mode_config.lock here
3669 * as our list of CRTC objects is static for the lifetime of the
3670 * device and so cannot disappear as we iterate. Similarly, we can
3671 * happily treat the predicates as racy, atomic checks as userspace
3672 * cannot claim and pin a new fb without at least acquring the
3673 * struct_mutex and so serialising with us.
3675 for_each_intel_crtc(dev
, crtc
) {
3676 if (atomic_read(&crtc
->unpin_work_count
) == 0)
3679 if (crtc
->unpin_work
)
3680 intel_wait_for_vblank(dev
, crtc
->pipe
);
3688 static void page_flip_completed(struct intel_crtc
*intel_crtc
)
3690 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
3691 struct intel_unpin_work
*work
= intel_crtc
->unpin_work
;
3693 /* ensure that the unpin work is consistent wrt ->pending. */
3695 intel_crtc
->unpin_work
= NULL
;
3698 drm_send_vblank_event(intel_crtc
->base
.dev
,
3702 drm_crtc_vblank_put(&intel_crtc
->base
);
3704 wake_up_all(&dev_priv
->pending_flip_queue
);
3705 queue_work(dev_priv
->wq
, &work
->work
);
3707 trace_i915_flip_complete(intel_crtc
->plane
,
3708 work
->pending_flip_obj
);
3711 void intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
3713 struct drm_device
*dev
= crtc
->dev
;
3714 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3716 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
3717 if (WARN_ON(wait_event_timeout(dev_priv
->pending_flip_queue
,
3718 !intel_crtc_has_pending_flip(crtc
),
3720 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3722 spin_lock_irq(&dev
->event_lock
);
3723 if (intel_crtc
->unpin_work
) {
3724 WARN_ONCE(1, "Removing stuck page flip\n");
3725 page_flip_completed(intel_crtc
);
3727 spin_unlock_irq(&dev
->event_lock
);
3730 if (crtc
->primary
->fb
) {
3731 mutex_lock(&dev
->struct_mutex
);
3732 intel_finish_fb(crtc
->primary
->fb
);
3733 mutex_unlock(&dev
->struct_mutex
);
3737 /* Program iCLKIP clock to the desired frequency */
3738 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
3740 struct drm_device
*dev
= crtc
->dev
;
3741 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3742 int clock
= to_intel_crtc(crtc
)->config
->base
.adjusted_mode
.crtc_clock
;
3743 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
3746 mutex_lock(&dev_priv
->dpio_lock
);
3748 /* It is necessary to ungate the pixclk gate prior to programming
3749 * the divisors, and gate it back when it is done.
3751 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
3753 /* Disable SSCCTL */
3754 intel_sbi_write(dev_priv
, SBI_SSCCTL6
,
3755 intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
) |
3759 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
3760 if (clock
== 20000) {
3765 /* The iCLK virtual clock root frequency is in MHz,
3766 * but the adjusted_mode->crtc_clock in in KHz. To get the
3767 * divisors, it is necessary to divide one by another, so we
3768 * convert the virtual clock precision to KHz here for higher
3771 u32 iclk_virtual_root_freq
= 172800 * 1000;
3772 u32 iclk_pi_range
= 64;
3773 u32 desired_divisor
, msb_divisor_value
, pi_value
;
3775 desired_divisor
= (iclk_virtual_root_freq
/ clock
);
3776 msb_divisor_value
= desired_divisor
/ iclk_pi_range
;
3777 pi_value
= desired_divisor
% iclk_pi_range
;
3780 divsel
= msb_divisor_value
- 2;
3781 phaseinc
= pi_value
;
3784 /* This should not happen with any sane values */
3785 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
3786 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
3787 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
3788 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
3790 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3797 /* Program SSCDIVINTPHASE6 */
3798 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
3799 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
3800 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
3801 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
3802 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
3803 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
3804 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
3805 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
3807 /* Program SSCAUXDIV */
3808 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
3809 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3810 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
3811 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
3813 /* Enable modulator and associated divider */
3814 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
3815 temp
&= ~SBI_SSCCTL_DISABLE
;
3816 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
3818 /* Wait for initialization time */
3821 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
3823 mutex_unlock(&dev_priv
->dpio_lock
);
3826 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
3827 enum pipe pch_transcoder
)
3829 struct drm_device
*dev
= crtc
->base
.dev
;
3830 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3831 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
3833 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
3834 I915_READ(HTOTAL(cpu_transcoder
)));
3835 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
3836 I915_READ(HBLANK(cpu_transcoder
)));
3837 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
3838 I915_READ(HSYNC(cpu_transcoder
)));
3840 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
3841 I915_READ(VTOTAL(cpu_transcoder
)));
3842 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
3843 I915_READ(VBLANK(cpu_transcoder
)));
3844 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
3845 I915_READ(VSYNC(cpu_transcoder
)));
3846 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
3847 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
3850 static void cpt_set_fdi_bc_bifurcation(struct drm_device
*dev
, bool enable
)
3852 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3855 temp
= I915_READ(SOUTH_CHICKEN1
);
3856 if (!!(temp
& FDI_BC_BIFURCATION_SELECT
) == enable
)
3859 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
3860 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
3862 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
3864 temp
|= FDI_BC_BIFURCATION_SELECT
;
3866 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable
? "en" : "dis");
3867 I915_WRITE(SOUTH_CHICKEN1
, temp
);
3868 POSTING_READ(SOUTH_CHICKEN1
);
3871 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
3873 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3875 switch (intel_crtc
->pipe
) {
3879 if (intel_crtc
->config
->fdi_lanes
> 2)
3880 cpt_set_fdi_bc_bifurcation(dev
, false);
3882 cpt_set_fdi_bc_bifurcation(dev
, true);
3886 cpt_set_fdi_bc_bifurcation(dev
, true);
3895 * Enable PCH resources required for PCH ports:
3897 * - FDI training & RX/TX
3898 * - update transcoder timings
3899 * - DP transcoding bits
3902 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
3904 struct drm_device
*dev
= crtc
->dev
;
3905 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3906 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3907 int pipe
= intel_crtc
->pipe
;
3910 assert_pch_transcoder_disabled(dev_priv
, pipe
);
3912 if (IS_IVYBRIDGE(dev
))
3913 ivybridge_update_fdi_bc_bifurcation(intel_crtc
);
3915 /* Write the TU size bits before fdi link training, so that error
3916 * detection works. */
3917 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
3918 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
3920 /* For PCH output, training FDI link */
3921 dev_priv
->display
.fdi_link_train(crtc
);
3923 /* We need to program the right clock selection before writing the pixel
3924 * mutliplier into the DPLL. */
3925 if (HAS_PCH_CPT(dev
)) {
3928 temp
= I915_READ(PCH_DPLL_SEL
);
3929 temp
|= TRANS_DPLL_ENABLE(pipe
);
3930 sel
= TRANS_DPLLB_SEL(pipe
);
3931 if (intel_crtc
->config
->shared_dpll
== DPLL_ID_PCH_PLL_B
)
3935 I915_WRITE(PCH_DPLL_SEL
, temp
);
3938 /* XXX: pch pll's can be enabled any time before we enable the PCH
3939 * transcoder, and we actually should do this to not upset any PCH
3940 * transcoder that already use the clock when we share it.
3942 * Note that enable_shared_dpll tries to do the right thing, but
3943 * get_shared_dpll unconditionally resets the pll - we need that to have
3944 * the right LVDS enable sequence. */
3945 intel_enable_shared_dpll(intel_crtc
);
3947 /* set transcoder timing, panel must allow it */
3948 assert_panel_unlocked(dev_priv
, pipe
);
3949 ironlake_pch_transcoder_set_timings(intel_crtc
, pipe
);
3951 intel_fdi_normal_train(crtc
);
3953 /* For PCH DP, enable TRANS_DP_CTL */
3954 if (HAS_PCH_CPT(dev
) && intel_crtc
->config
->has_dp_encoder
) {
3955 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
3956 reg
= TRANS_DP_CTL(pipe
);
3957 temp
= I915_READ(reg
);
3958 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
3959 TRANS_DP_SYNC_MASK
|
3961 temp
|= (TRANS_DP_OUTPUT_ENABLE
|
3962 TRANS_DP_ENH_FRAMING
);
3963 temp
|= bpc
<< 9; /* same format but at 11:9 */
3965 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PHSYNC
)
3966 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
3967 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PVSYNC
)
3968 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
3970 switch (intel_trans_dp_port_sel(crtc
)) {
3972 temp
|= TRANS_DP_PORT_SEL_B
;
3975 temp
|= TRANS_DP_PORT_SEL_C
;
3978 temp
|= TRANS_DP_PORT_SEL_D
;
3984 I915_WRITE(reg
, temp
);
3987 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
3990 static void lpt_pch_enable(struct drm_crtc
*crtc
)
3992 struct drm_device
*dev
= crtc
->dev
;
3993 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3994 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3995 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
3997 assert_pch_transcoder_disabled(dev_priv
, TRANSCODER_A
);
3999 lpt_program_iclkip(crtc
);
4001 /* Set transcoder timing. */
4002 ironlake_pch_transcoder_set_timings(intel_crtc
, PIPE_A
);
4004 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
4007 void intel_put_shared_dpll(struct intel_crtc
*crtc
)
4009 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
4014 if (!(pll
->config
.crtc_mask
& (1 << crtc
->pipe
))) {
4015 WARN(1, "bad %s crtc mask\n", pll
->name
);
4019 pll
->config
.crtc_mask
&= ~(1 << crtc
->pipe
);
4020 if (pll
->config
.crtc_mask
== 0) {
4022 WARN_ON(pll
->active
);
4025 crtc
->config
->shared_dpll
= DPLL_ID_PRIVATE
;
4028 struct intel_shared_dpll
*intel_get_shared_dpll(struct intel_crtc
*crtc
,
4029 struct intel_crtc_state
*crtc_state
)
4031 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
4032 struct intel_shared_dpll
*pll
;
4033 enum intel_dpll_id i
;
4035 if (HAS_PCH_IBX(dev_priv
->dev
)) {
4036 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
4037 i
= (enum intel_dpll_id
) crtc
->pipe
;
4038 pll
= &dev_priv
->shared_dplls
[i
];
4040 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
4041 crtc
->base
.base
.id
, pll
->name
);
4043 WARN_ON(pll
->new_config
->crtc_mask
);
4048 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4049 pll
= &dev_priv
->shared_dplls
[i
];
4051 /* Only want to check enabled timings first */
4052 if (pll
->new_config
->crtc_mask
== 0)
4055 if (memcmp(&crtc_state
->dpll_hw_state
,
4056 &pll
->new_config
->hw_state
,
4057 sizeof(pll
->new_config
->hw_state
)) == 0) {
4058 DRM_DEBUG_KMS("CRTC:%d sharing existing %s (crtc mask 0x%08x, ative %d)\n",
4059 crtc
->base
.base
.id
, pll
->name
,
4060 pll
->new_config
->crtc_mask
,
4066 /* Ok no matching timings, maybe there's a free one? */
4067 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4068 pll
= &dev_priv
->shared_dplls
[i
];
4069 if (pll
->new_config
->crtc_mask
== 0) {
4070 DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
4071 crtc
->base
.base
.id
, pll
->name
);
4079 if (pll
->new_config
->crtc_mask
== 0)
4080 pll
->new_config
->hw_state
= crtc_state
->dpll_hw_state
;
4082 crtc_state
->shared_dpll
= i
;
4083 DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll
->name
,
4084 pipe_name(crtc
->pipe
));
4086 pll
->new_config
->crtc_mask
|= 1 << crtc
->pipe
;
4092 * intel_shared_dpll_start_config - start a new PLL staged config
4093 * @dev_priv: DRM device
4094 * @clear_pipes: mask of pipes that will have their PLLs freed
4096 * Starts a new PLL staged config, copying the current config but
4097 * releasing the references of pipes specified in clear_pipes.
4099 static int intel_shared_dpll_start_config(struct drm_i915_private
*dev_priv
,
4100 unsigned clear_pipes
)
4102 struct intel_shared_dpll
*pll
;
4103 enum intel_dpll_id i
;
4105 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4106 pll
= &dev_priv
->shared_dplls
[i
];
4108 pll
->new_config
= kmemdup(&pll
->config
, sizeof pll
->config
,
4110 if (!pll
->new_config
)
4113 pll
->new_config
->crtc_mask
&= ~clear_pipes
;
4120 pll
= &dev_priv
->shared_dplls
[i
];
4121 kfree(pll
->new_config
);
4122 pll
->new_config
= NULL
;
4128 static void intel_shared_dpll_commit(struct drm_i915_private
*dev_priv
)
4130 struct intel_shared_dpll
*pll
;
4131 enum intel_dpll_id i
;
4133 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4134 pll
= &dev_priv
->shared_dplls
[i
];
4136 WARN_ON(pll
->new_config
== &pll
->config
);
4138 pll
->config
= *pll
->new_config
;
4139 kfree(pll
->new_config
);
4140 pll
->new_config
= NULL
;
4144 static void intel_shared_dpll_abort_config(struct drm_i915_private
*dev_priv
)
4146 struct intel_shared_dpll
*pll
;
4147 enum intel_dpll_id i
;
4149 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4150 pll
= &dev_priv
->shared_dplls
[i
];
4152 WARN_ON(pll
->new_config
== &pll
->config
);
4154 kfree(pll
->new_config
);
4155 pll
->new_config
= NULL
;
4159 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
4161 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4162 int dslreg
= PIPEDSL(pipe
);
4165 temp
= I915_READ(dslreg
);
4167 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
4168 if (wait_for(I915_READ(dslreg
) != temp
, 5))
4169 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
4173 static void skylake_pfit_enable(struct intel_crtc
*crtc
)
4175 struct drm_device
*dev
= crtc
->base
.dev
;
4176 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4177 int pipe
= crtc
->pipe
;
4179 if (crtc
->config
->pch_pfit
.enabled
) {
4180 I915_WRITE(PS_CTL(pipe
), PS_ENABLE
);
4181 I915_WRITE(PS_WIN_POS(pipe
), crtc
->config
->pch_pfit
.pos
);
4182 I915_WRITE(PS_WIN_SZ(pipe
), crtc
->config
->pch_pfit
.size
);
4186 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
4188 struct drm_device
*dev
= crtc
->base
.dev
;
4189 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4190 int pipe
= crtc
->pipe
;
4192 if (crtc
->config
->pch_pfit
.enabled
) {
4193 /* Force use of hard-coded filter coefficients
4194 * as some pre-programmed values are broken,
4197 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
))
4198 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
4199 PF_PIPE_SEL_IVB(pipe
));
4201 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
4202 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
->pch_pfit
.pos
);
4203 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
->pch_pfit
.size
);
4207 static void intel_enable_sprite_planes(struct drm_crtc
*crtc
)
4209 struct drm_device
*dev
= crtc
->dev
;
4210 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
4211 struct drm_plane
*plane
;
4212 struct intel_plane
*intel_plane
;
4214 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
4215 intel_plane
= to_intel_plane(plane
);
4216 if (intel_plane
->pipe
== pipe
)
4217 intel_plane_restore(&intel_plane
->base
);
4222 * Disable a plane internally without actually modifying the plane's state.
4223 * This will allow us to easily restore the plane later by just reprogramming
4226 static void disable_plane_internal(struct drm_plane
*plane
)
4228 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
4229 struct drm_plane_state
*state
=
4230 plane
->funcs
->atomic_duplicate_state(plane
);
4231 struct intel_plane_state
*intel_state
= to_intel_plane_state(state
);
4233 intel_state
->visible
= false;
4234 intel_plane
->commit_plane(plane
, intel_state
);
4236 intel_plane_destroy_state(plane
, state
);
4239 static void intel_disable_sprite_planes(struct drm_crtc
*crtc
)
4241 struct drm_device
*dev
= crtc
->dev
;
4242 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
4243 struct drm_plane
*plane
;
4244 struct intel_plane
*intel_plane
;
4246 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
4247 intel_plane
= to_intel_plane(plane
);
4248 if (plane
->fb
&& intel_plane
->pipe
== pipe
)
4249 disable_plane_internal(plane
);
4253 void hsw_enable_ips(struct intel_crtc
*crtc
)
4255 struct drm_device
*dev
= crtc
->base
.dev
;
4256 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4258 if (!crtc
->config
->ips_enabled
)
4261 /* We can only enable IPS after we enable a plane and wait for a vblank */
4262 intel_wait_for_vblank(dev
, crtc
->pipe
);
4264 assert_plane_enabled(dev_priv
, crtc
->plane
);
4265 if (IS_BROADWELL(dev
)) {
4266 mutex_lock(&dev_priv
->rps
.hw_lock
);
4267 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
4268 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4269 /* Quoting Art Runyan: "its not safe to expect any particular
4270 * value in IPS_CTL bit 31 after enabling IPS through the
4271 * mailbox." Moreover, the mailbox may return a bogus state,
4272 * so we need to just enable it and continue on.
4275 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
4276 /* The bit only becomes 1 in the next vblank, so this wait here
4277 * is essentially intel_wait_for_vblank. If we don't have this
4278 * and don't wait for vblanks until the end of crtc_enable, then
4279 * the HW state readout code will complain that the expected
4280 * IPS_CTL value is not the one we read. */
4281 if (wait_for(I915_READ_NOTRACE(IPS_CTL
) & IPS_ENABLE
, 50))
4282 DRM_ERROR("Timed out waiting for IPS enable\n");
4286 void hsw_disable_ips(struct intel_crtc
*crtc
)
4288 struct drm_device
*dev
= crtc
->base
.dev
;
4289 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4291 if (!crtc
->config
->ips_enabled
)
4294 assert_plane_enabled(dev_priv
, crtc
->plane
);
4295 if (IS_BROADWELL(dev
)) {
4296 mutex_lock(&dev_priv
->rps
.hw_lock
);
4297 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
4298 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4299 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4300 if (wait_for((I915_READ(IPS_CTL
) & IPS_ENABLE
) == 0, 42))
4301 DRM_ERROR("Timed out waiting for IPS disable\n");
4303 I915_WRITE(IPS_CTL
, 0);
4304 POSTING_READ(IPS_CTL
);
4307 /* We need to wait for a vblank before we can disable the plane. */
4308 intel_wait_for_vblank(dev
, crtc
->pipe
);
4311 /** Loads the palette/gamma unit for the CRTC with the prepared values */
4312 static void intel_crtc_load_lut(struct drm_crtc
*crtc
)
4314 struct drm_device
*dev
= crtc
->dev
;
4315 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4316 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4317 enum pipe pipe
= intel_crtc
->pipe
;
4318 int palreg
= PALETTE(pipe
);
4320 bool reenable_ips
= false;
4322 /* The clocks have to be on to load the palette. */
4323 if (!crtc
->state
->enable
|| !intel_crtc
->active
)
4326 if (!HAS_PCH_SPLIT(dev_priv
->dev
)) {
4327 if (intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_DSI
))
4328 assert_dsi_pll_enabled(dev_priv
);
4330 assert_pll_enabled(dev_priv
, pipe
);
4333 /* use legacy palette for Ironlake */
4334 if (!HAS_GMCH_DISPLAY(dev
))
4335 palreg
= LGC_PALETTE(pipe
);
4337 /* Workaround : Do not read or write the pipe palette/gamma data while
4338 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
4340 if (IS_HASWELL(dev
) && intel_crtc
->config
->ips_enabled
&&
4341 ((I915_READ(GAMMA_MODE(pipe
)) & GAMMA_MODE_MODE_MASK
) ==
4342 GAMMA_MODE_MODE_SPLIT
)) {
4343 hsw_disable_ips(intel_crtc
);
4344 reenable_ips
= true;
4347 for (i
= 0; i
< 256; i
++) {
4348 I915_WRITE(palreg
+ 4 * i
,
4349 (intel_crtc
->lut_r
[i
] << 16) |
4350 (intel_crtc
->lut_g
[i
] << 8) |
4351 intel_crtc
->lut_b
[i
]);
4355 hsw_enable_ips(intel_crtc
);
4358 static void intel_crtc_dpms_overlay(struct intel_crtc
*intel_crtc
, bool enable
)
4360 if (!enable
&& intel_crtc
->overlay
) {
4361 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4362 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4364 mutex_lock(&dev
->struct_mutex
);
4365 dev_priv
->mm
.interruptible
= false;
4366 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
4367 dev_priv
->mm
.interruptible
= true;
4368 mutex_unlock(&dev
->struct_mutex
);
4371 /* Let userspace switch the overlay on again. In most cases userspace
4372 * has to recompute where to put it anyway.
4376 static void intel_crtc_enable_planes(struct drm_crtc
*crtc
)
4378 struct drm_device
*dev
= crtc
->dev
;
4379 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4380 int pipe
= intel_crtc
->pipe
;
4382 intel_enable_primary_hw_plane(crtc
->primary
, crtc
);
4383 intel_enable_sprite_planes(crtc
);
4384 intel_crtc_update_cursor(crtc
, true);
4385 intel_crtc_dpms_overlay(intel_crtc
, true);
4387 hsw_enable_ips(intel_crtc
);
4389 mutex_lock(&dev
->struct_mutex
);
4390 intel_fbc_update(dev
);
4391 mutex_unlock(&dev
->struct_mutex
);
4394 * FIXME: Once we grow proper nuclear flip support out of this we need
4395 * to compute the mask of flip planes precisely. For the time being
4396 * consider this a flip from a NULL plane.
4398 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_ALL_MASK(pipe
));
4401 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
)
4403 struct drm_device
*dev
= crtc
->dev
;
4404 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4405 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4406 int pipe
= intel_crtc
->pipe
;
4408 intel_crtc_wait_for_pending_flips(crtc
);
4410 if (dev_priv
->fbc
.crtc
== intel_crtc
)
4411 intel_fbc_disable(dev
);
4413 hsw_disable_ips(intel_crtc
);
4415 intel_crtc_dpms_overlay(intel_crtc
, false);
4416 intel_crtc_update_cursor(crtc
, false);
4417 intel_disable_sprite_planes(crtc
);
4418 intel_disable_primary_hw_plane(crtc
->primary
, crtc
);
4421 * FIXME: Once we grow proper nuclear flip support out of this we need
4422 * to compute the mask of flip planes precisely. For the time being
4423 * consider this a flip to a NULL plane.
4425 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_ALL_MASK(pipe
));
4428 static void ironlake_crtc_enable(struct drm_crtc
*crtc
)
4430 struct drm_device
*dev
= crtc
->dev
;
4431 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4432 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4433 struct intel_encoder
*encoder
;
4434 int pipe
= intel_crtc
->pipe
;
4436 WARN_ON(!crtc
->state
->enable
);
4438 if (intel_crtc
->active
)
4441 if (intel_crtc
->config
->has_pch_encoder
)
4442 intel_prepare_shared_dpll(intel_crtc
);
4444 if (intel_crtc
->config
->has_dp_encoder
)
4445 intel_dp_set_m_n(intel_crtc
, M1_N1
);
4447 intel_set_pipe_timings(intel_crtc
);
4449 if (intel_crtc
->config
->has_pch_encoder
) {
4450 intel_cpu_transcoder_set_m_n(intel_crtc
,
4451 &intel_crtc
->config
->fdi_m_n
, NULL
);
4454 ironlake_set_pipeconf(crtc
);
4456 intel_crtc
->active
= true;
4458 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4459 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
4461 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4462 if (encoder
->pre_enable
)
4463 encoder
->pre_enable(encoder
);
4465 if (intel_crtc
->config
->has_pch_encoder
) {
4466 /* Note: FDI PLL enabling _must_ be done before we enable the
4467 * cpu pipes, hence this is separate from all the other fdi/pch
4469 ironlake_fdi_pll_enable(intel_crtc
);
4471 assert_fdi_tx_disabled(dev_priv
, pipe
);
4472 assert_fdi_rx_disabled(dev_priv
, pipe
);
4475 ironlake_pfit_enable(intel_crtc
);
4478 * On ILK+ LUT must be loaded before the pipe is running but with
4481 intel_crtc_load_lut(crtc
);
4483 intel_update_watermarks(crtc
);
4484 intel_enable_pipe(intel_crtc
);
4486 if (intel_crtc
->config
->has_pch_encoder
)
4487 ironlake_pch_enable(crtc
);
4489 assert_vblank_disabled(crtc
);
4490 drm_crtc_vblank_on(crtc
);
4492 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4493 encoder
->enable(encoder
);
4495 if (HAS_PCH_CPT(dev
))
4496 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
4498 intel_crtc_enable_planes(crtc
);
4501 /* IPS only exists on ULT machines and is tied to pipe A. */
4502 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
4504 return HAS_IPS(crtc
->base
.dev
) && crtc
->pipe
== PIPE_A
;
4508 * This implements the workaround described in the "notes" section of the mode
4509 * set sequence documentation. When going from no pipes or single pipe to
4510 * multiple pipes, and planes are enabled after the pipe, we need to wait at
4511 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
4513 static void haswell_mode_set_planes_workaround(struct intel_crtc
*crtc
)
4515 struct drm_device
*dev
= crtc
->base
.dev
;
4516 struct intel_crtc
*crtc_it
, *other_active_crtc
= NULL
;
4518 /* We want to get the other_active_crtc only if there's only 1 other
4520 for_each_intel_crtc(dev
, crtc_it
) {
4521 if (!crtc_it
->active
|| crtc_it
== crtc
)
4524 if (other_active_crtc
)
4527 other_active_crtc
= crtc_it
;
4529 if (!other_active_crtc
)
4532 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4533 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4536 static void haswell_crtc_enable(struct drm_crtc
*crtc
)
4538 struct drm_device
*dev
= crtc
->dev
;
4539 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4540 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4541 struct intel_encoder
*encoder
;
4542 int pipe
= intel_crtc
->pipe
;
4544 WARN_ON(!crtc
->state
->enable
);
4546 if (intel_crtc
->active
)
4549 if (intel_crtc_to_shared_dpll(intel_crtc
))
4550 intel_enable_shared_dpll(intel_crtc
);
4552 if (intel_crtc
->config
->has_dp_encoder
)
4553 intel_dp_set_m_n(intel_crtc
, M1_N1
);
4555 intel_set_pipe_timings(intel_crtc
);
4557 if (intel_crtc
->config
->cpu_transcoder
!= TRANSCODER_EDP
) {
4558 I915_WRITE(PIPE_MULT(intel_crtc
->config
->cpu_transcoder
),
4559 intel_crtc
->config
->pixel_multiplier
- 1);
4562 if (intel_crtc
->config
->has_pch_encoder
) {
4563 intel_cpu_transcoder_set_m_n(intel_crtc
,
4564 &intel_crtc
->config
->fdi_m_n
, NULL
);
4567 haswell_set_pipeconf(crtc
);
4569 intel_set_pipe_csc(crtc
);
4571 intel_crtc
->active
= true;
4573 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4574 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4575 if (encoder
->pre_enable
)
4576 encoder
->pre_enable(encoder
);
4578 if (intel_crtc
->config
->has_pch_encoder
) {
4579 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
4581 dev_priv
->display
.fdi_link_train(crtc
);
4584 intel_ddi_enable_pipe_clock(intel_crtc
);
4586 if (IS_SKYLAKE(dev
))
4587 skylake_pfit_enable(intel_crtc
);
4589 ironlake_pfit_enable(intel_crtc
);
4592 * On ILK+ LUT must be loaded before the pipe is running but with
4595 intel_crtc_load_lut(crtc
);
4597 intel_ddi_set_pipe_settings(crtc
);
4598 intel_ddi_enable_transcoder_func(crtc
);
4600 intel_update_watermarks(crtc
);
4601 intel_enable_pipe(intel_crtc
);
4603 if (intel_crtc
->config
->has_pch_encoder
)
4604 lpt_pch_enable(crtc
);
4606 if (intel_crtc
->config
->dp_encoder_is_mst
)
4607 intel_ddi_set_vc_payload_alloc(crtc
, true);
4609 assert_vblank_disabled(crtc
);
4610 drm_crtc_vblank_on(crtc
);
4612 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4613 encoder
->enable(encoder
);
4614 intel_opregion_notify_encoder(encoder
, true);
4617 /* If we change the relative order between pipe/planes enabling, we need
4618 * to change the workaround. */
4619 haswell_mode_set_planes_workaround(intel_crtc
);
4620 intel_crtc_enable_planes(crtc
);
4623 static void skylake_pfit_disable(struct intel_crtc
*crtc
)
4625 struct drm_device
*dev
= crtc
->base
.dev
;
4626 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4627 int pipe
= crtc
->pipe
;
4629 /* To avoid upsetting the power well on haswell only disable the pfit if
4630 * it's in use. The hw state code will make sure we get this right. */
4631 if (crtc
->config
->pch_pfit
.enabled
) {
4632 I915_WRITE(PS_CTL(pipe
), 0);
4633 I915_WRITE(PS_WIN_POS(pipe
), 0);
4634 I915_WRITE(PS_WIN_SZ(pipe
), 0);
4638 static void ironlake_pfit_disable(struct intel_crtc
*crtc
)
4640 struct drm_device
*dev
= crtc
->base
.dev
;
4641 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4642 int pipe
= crtc
->pipe
;
4644 /* To avoid upsetting the power well on haswell only disable the pfit if
4645 * it's in use. The hw state code will make sure we get this right. */
4646 if (crtc
->config
->pch_pfit
.enabled
) {
4647 I915_WRITE(PF_CTL(pipe
), 0);
4648 I915_WRITE(PF_WIN_POS(pipe
), 0);
4649 I915_WRITE(PF_WIN_SZ(pipe
), 0);
4653 static void ironlake_crtc_disable(struct drm_crtc
*crtc
)
4655 struct drm_device
*dev
= crtc
->dev
;
4656 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4657 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4658 struct intel_encoder
*encoder
;
4659 int pipe
= intel_crtc
->pipe
;
4662 if (!intel_crtc
->active
)
4665 intel_crtc_disable_planes(crtc
);
4667 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4668 encoder
->disable(encoder
);
4670 drm_crtc_vblank_off(crtc
);
4671 assert_vblank_disabled(crtc
);
4673 if (intel_crtc
->config
->has_pch_encoder
)
4674 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
4676 intel_disable_pipe(intel_crtc
);
4678 ironlake_pfit_disable(intel_crtc
);
4680 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4681 if (encoder
->post_disable
)
4682 encoder
->post_disable(encoder
);
4684 if (intel_crtc
->config
->has_pch_encoder
) {
4685 ironlake_fdi_disable(crtc
);
4687 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
4689 if (HAS_PCH_CPT(dev
)) {
4690 /* disable TRANS_DP_CTL */
4691 reg
= TRANS_DP_CTL(pipe
);
4692 temp
= I915_READ(reg
);
4693 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
4694 TRANS_DP_PORT_SEL_MASK
);
4695 temp
|= TRANS_DP_PORT_SEL_NONE
;
4696 I915_WRITE(reg
, temp
);
4698 /* disable DPLL_SEL */
4699 temp
= I915_READ(PCH_DPLL_SEL
);
4700 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
4701 I915_WRITE(PCH_DPLL_SEL
, temp
);
4704 /* disable PCH DPLL */
4705 intel_disable_shared_dpll(intel_crtc
);
4707 ironlake_fdi_pll_disable(intel_crtc
);
4710 intel_crtc
->active
= false;
4711 intel_update_watermarks(crtc
);
4713 mutex_lock(&dev
->struct_mutex
);
4714 intel_fbc_update(dev
);
4715 mutex_unlock(&dev
->struct_mutex
);
4718 static void haswell_crtc_disable(struct drm_crtc
*crtc
)
4720 struct drm_device
*dev
= crtc
->dev
;
4721 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4722 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4723 struct intel_encoder
*encoder
;
4724 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
4726 if (!intel_crtc
->active
)
4729 intel_crtc_disable_planes(crtc
);
4731 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4732 intel_opregion_notify_encoder(encoder
, false);
4733 encoder
->disable(encoder
);
4736 drm_crtc_vblank_off(crtc
);
4737 assert_vblank_disabled(crtc
);
4739 if (intel_crtc
->config
->has_pch_encoder
)
4740 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
4742 intel_disable_pipe(intel_crtc
);
4744 if (intel_crtc
->config
->dp_encoder_is_mst
)
4745 intel_ddi_set_vc_payload_alloc(crtc
, false);
4747 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
4749 if (IS_SKYLAKE(dev
))
4750 skylake_pfit_disable(intel_crtc
);
4752 ironlake_pfit_disable(intel_crtc
);
4754 intel_ddi_disable_pipe_clock(intel_crtc
);
4756 if (intel_crtc
->config
->has_pch_encoder
) {
4757 lpt_disable_pch_transcoder(dev_priv
);
4758 intel_ddi_fdi_disable(crtc
);
4761 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4762 if (encoder
->post_disable
)
4763 encoder
->post_disable(encoder
);
4765 intel_crtc
->active
= false;
4766 intel_update_watermarks(crtc
);
4768 mutex_lock(&dev
->struct_mutex
);
4769 intel_fbc_update(dev
);
4770 mutex_unlock(&dev
->struct_mutex
);
4772 if (intel_crtc_to_shared_dpll(intel_crtc
))
4773 intel_disable_shared_dpll(intel_crtc
);
4776 static void ironlake_crtc_off(struct drm_crtc
*crtc
)
4778 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4779 intel_put_shared_dpll(intel_crtc
);
4783 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
4785 struct drm_device
*dev
= crtc
->base
.dev
;
4786 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4787 struct intel_crtc_state
*pipe_config
= crtc
->config
;
4789 if (!pipe_config
->gmch_pfit
.control
)
4793 * The panel fitter should only be adjusted whilst the pipe is disabled,
4794 * according to register description and PRM.
4796 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
4797 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
4799 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
4800 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
4802 /* Border color in case we don't scale up to the full screen. Black by
4803 * default, change to something else for debugging. */
4804 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
4807 static enum intel_display_power_domain
port_to_power_domain(enum port port
)
4811 return POWER_DOMAIN_PORT_DDI_A_4_LANES
;
4813 return POWER_DOMAIN_PORT_DDI_B_4_LANES
;
4815 return POWER_DOMAIN_PORT_DDI_C_4_LANES
;
4817 return POWER_DOMAIN_PORT_DDI_D_4_LANES
;
4820 return POWER_DOMAIN_PORT_OTHER
;
4824 #define for_each_power_domain(domain, mask) \
4825 for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
4826 if ((1 << (domain)) & (mask))
4828 enum intel_display_power_domain
4829 intel_display_port_power_domain(struct intel_encoder
*intel_encoder
)
4831 struct drm_device
*dev
= intel_encoder
->base
.dev
;
4832 struct intel_digital_port
*intel_dig_port
;
4834 switch (intel_encoder
->type
) {
4835 case INTEL_OUTPUT_UNKNOWN
:
4836 /* Only DDI platforms should ever use this output type */
4837 WARN_ON_ONCE(!HAS_DDI(dev
));
4838 case INTEL_OUTPUT_DISPLAYPORT
:
4839 case INTEL_OUTPUT_HDMI
:
4840 case INTEL_OUTPUT_EDP
:
4841 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
4842 return port_to_power_domain(intel_dig_port
->port
);
4843 case INTEL_OUTPUT_DP_MST
:
4844 intel_dig_port
= enc_to_mst(&intel_encoder
->base
)->primary
;
4845 return port_to_power_domain(intel_dig_port
->port
);
4846 case INTEL_OUTPUT_ANALOG
:
4847 return POWER_DOMAIN_PORT_CRT
;
4848 case INTEL_OUTPUT_DSI
:
4849 return POWER_DOMAIN_PORT_DSI
;
4851 return POWER_DOMAIN_PORT_OTHER
;
4855 static unsigned long get_crtc_power_domains(struct drm_crtc
*crtc
)
4857 struct drm_device
*dev
= crtc
->dev
;
4858 struct intel_encoder
*intel_encoder
;
4859 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4860 enum pipe pipe
= intel_crtc
->pipe
;
4862 enum transcoder transcoder
;
4864 transcoder
= intel_pipe_to_cpu_transcoder(dev
->dev_private
, pipe
);
4866 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
4867 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
4868 if (intel_crtc
->config
->pch_pfit
.enabled
||
4869 intel_crtc
->config
->pch_pfit
.force_thru
)
4870 mask
|= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
4872 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
4873 mask
|= BIT(intel_display_port_power_domain(intel_encoder
));
4878 static void modeset_update_crtc_power_domains(struct drm_device
*dev
)
4880 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4881 unsigned long pipe_domains
[I915_MAX_PIPES
] = { 0, };
4882 struct intel_crtc
*crtc
;
4885 * First get all needed power domains, then put all unneeded, to avoid
4886 * any unnecessary toggling of the power wells.
4888 for_each_intel_crtc(dev
, crtc
) {
4889 enum intel_display_power_domain domain
;
4891 if (!crtc
->base
.state
->enable
)
4894 pipe_domains
[crtc
->pipe
] = get_crtc_power_domains(&crtc
->base
);
4896 for_each_power_domain(domain
, pipe_domains
[crtc
->pipe
])
4897 intel_display_power_get(dev_priv
, domain
);
4900 if (dev_priv
->display
.modeset_global_resources
)
4901 dev_priv
->display
.modeset_global_resources(dev
);
4903 for_each_intel_crtc(dev
, crtc
) {
4904 enum intel_display_power_domain domain
;
4906 for_each_power_domain(domain
, crtc
->enabled_power_domains
)
4907 intel_display_power_put(dev_priv
, domain
);
4909 crtc
->enabled_power_domains
= pipe_domains
[crtc
->pipe
];
4912 intel_display_set_init_power(dev_priv
, false);
4915 /* returns HPLL frequency in kHz */
4916 static int valleyview_get_vco(struct drm_i915_private
*dev_priv
)
4918 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
4920 /* Obtain SKU information */
4921 mutex_lock(&dev_priv
->dpio_lock
);
4922 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
4923 CCK_FUSE_HPLL_FREQ_MASK
;
4924 mutex_unlock(&dev_priv
->dpio_lock
);
4926 return vco_freq
[hpll_freq
] * 1000;
4929 static void vlv_update_cdclk(struct drm_device
*dev
)
4931 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4933 dev_priv
->vlv_cdclk_freq
= dev_priv
->display
.get_display_clock_speed(dev
);
4934 DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n",
4935 dev_priv
->vlv_cdclk_freq
);
4938 * Program the gmbus_freq based on the cdclk frequency.
4939 * BSpec erroneously claims we should aim for 4MHz, but
4940 * in fact 1MHz is the correct frequency.
4942 I915_WRITE(GMBUSFREQ_VLV
, DIV_ROUND_UP(dev_priv
->vlv_cdclk_freq
, 1000));
4945 /* Adjust CDclk dividers to allow high res or save power if possible */
4946 static void valleyview_set_cdclk(struct drm_device
*dev
, int cdclk
)
4948 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4951 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
) != dev_priv
->vlv_cdclk_freq
);
4953 if (cdclk
>= 320000) /* jump to highest voltage for 400MHz too */
4955 else if (cdclk
== 266667)
4960 mutex_lock(&dev_priv
->rps
.hw_lock
);
4961 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
4962 val
&= ~DSPFREQGUAR_MASK
;
4963 val
|= (cmd
<< DSPFREQGUAR_SHIFT
);
4964 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
4965 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
4966 DSPFREQSTAT_MASK
) == (cmd
<< DSPFREQSTAT_SHIFT
),
4968 DRM_ERROR("timed out waiting for CDclk change\n");
4970 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4972 if (cdclk
== 400000) {
4975 divider
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
4977 mutex_lock(&dev_priv
->dpio_lock
);
4978 /* adjust cdclk divider */
4979 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
4980 val
&= ~DISPLAY_FREQUENCY_VALUES
;
4982 vlv_cck_write(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
, val
);
4984 if (wait_for((vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
) &
4985 DISPLAY_FREQUENCY_STATUS
) == (divider
<< DISPLAY_FREQUENCY_STATUS_SHIFT
),
4987 DRM_ERROR("timed out waiting for CDclk change\n");
4988 mutex_unlock(&dev_priv
->dpio_lock
);
4991 mutex_lock(&dev_priv
->dpio_lock
);
4992 /* adjust self-refresh exit latency value */
4993 val
= vlv_bunit_read(dev_priv
, BUNIT_REG_BISOC
);
4997 * For high bandwidth configs, we set a higher latency in the bunit
4998 * so that the core display fetch happens in time to avoid underruns.
5000 if (cdclk
== 400000)
5001 val
|= 4500 / 250; /* 4.5 usec */
5003 val
|= 3000 / 250; /* 3.0 usec */
5004 vlv_bunit_write(dev_priv
, BUNIT_REG_BISOC
, val
);
5005 mutex_unlock(&dev_priv
->dpio_lock
);
5007 vlv_update_cdclk(dev
);
5010 static void cherryview_set_cdclk(struct drm_device
*dev
, int cdclk
)
5012 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5015 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
) != dev_priv
->vlv_cdclk_freq
);
5024 MISSING_CASE(cdclk
);
5029 * Specs are full of misinformation, but testing on actual
5030 * hardware has shown that we just need to write the desired
5031 * CCK divider into the Punit register.
5033 cmd
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
5035 mutex_lock(&dev_priv
->rps
.hw_lock
);
5036 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
5037 val
&= ~DSPFREQGUAR_MASK_CHV
;
5038 val
|= (cmd
<< DSPFREQGUAR_SHIFT_CHV
);
5039 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
5040 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
5041 DSPFREQSTAT_MASK_CHV
) == (cmd
<< DSPFREQSTAT_SHIFT_CHV
),
5043 DRM_ERROR("timed out waiting for CDclk change\n");
5045 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5047 vlv_update_cdclk(dev
);
5050 static int valleyview_calc_cdclk(struct drm_i915_private
*dev_priv
,
5053 int freq_320
= (dev_priv
->hpll_freq
<< 1) % 320000 != 0 ? 333333 : 320000;
5054 int limit
= IS_CHERRYVIEW(dev_priv
) ? 95 : 90;
5057 * Really only a few cases to deal with, as only 4 CDclks are supported:
5060 * 320/333MHz (depends on HPLL freq)
5062 * So we check to see whether we're above 90% (VLV) or 95% (CHV)
5063 * of the lower bin and adjust if needed.
5065 * We seem to get an unstable or solid color picture at 200MHz.
5066 * Not sure what's wrong. For now use 200MHz only when all pipes
5069 if (!IS_CHERRYVIEW(dev_priv
) &&
5070 max_pixclk
> freq_320
*limit
/100)
5072 else if (max_pixclk
> 266667*limit
/100)
5074 else if (max_pixclk
> 0)
5080 /* compute the max pixel clock for new configuration */
5081 static int intel_mode_max_pixclk(struct drm_i915_private
*dev_priv
)
5083 struct drm_device
*dev
= dev_priv
->dev
;
5084 struct intel_crtc
*intel_crtc
;
5087 for_each_intel_crtc(dev
, intel_crtc
) {
5088 if (intel_crtc
->new_enabled
)
5089 max_pixclk
= max(max_pixclk
,
5090 intel_crtc
->new_config
->base
.adjusted_mode
.crtc_clock
);
5096 static void valleyview_modeset_global_pipes(struct drm_device
*dev
,
5097 unsigned *prepare_pipes
)
5099 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5100 struct intel_crtc
*intel_crtc
;
5101 int max_pixclk
= intel_mode_max_pixclk(dev_priv
);
5103 if (valleyview_calc_cdclk(dev_priv
, max_pixclk
) ==
5104 dev_priv
->vlv_cdclk_freq
)
5107 /* disable/enable all currently active pipes while we change cdclk */
5108 for_each_intel_crtc(dev
, intel_crtc
)
5109 if (intel_crtc
->base
.state
->enable
)
5110 *prepare_pipes
|= (1 << intel_crtc
->pipe
);
5113 static void vlv_program_pfi_credits(struct drm_i915_private
*dev_priv
)
5115 unsigned int credits
, default_credits
;
5117 if (IS_CHERRYVIEW(dev_priv
))
5118 default_credits
= PFI_CREDIT(12);
5120 default_credits
= PFI_CREDIT(8);
5122 if (DIV_ROUND_CLOSEST(dev_priv
->vlv_cdclk_freq
, 1000) >= dev_priv
->rps
.cz_freq
) {
5123 /* CHV suggested value is 31 or 63 */
5124 if (IS_CHERRYVIEW(dev_priv
))
5125 credits
= PFI_CREDIT_31
;
5127 credits
= PFI_CREDIT(15);
5129 credits
= default_credits
;
5133 * WA - write default credits before re-programming
5134 * FIXME: should we also set the resend bit here?
5136 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
5139 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
5140 credits
| PFI_CREDIT_RESEND
);
5143 * FIXME is this guaranteed to clear
5144 * immediately or should we poll for it?
5146 WARN_ON(I915_READ(GCI_CONTROL
) & PFI_CREDIT_RESEND
);
5149 static void valleyview_modeset_global_resources(struct drm_device
*dev
)
5151 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5152 int max_pixclk
= intel_mode_max_pixclk(dev_priv
);
5153 int req_cdclk
= valleyview_calc_cdclk(dev_priv
, max_pixclk
);
5155 if (req_cdclk
!= dev_priv
->vlv_cdclk_freq
) {
5157 * FIXME: We can end up here with all power domains off, yet
5158 * with a CDCLK frequency other than the minimum. To account
5159 * for this take the PIPE-A power domain, which covers the HW
5160 * blocks needed for the following programming. This can be
5161 * removed once it's guaranteed that we get here either with
5162 * the minimum CDCLK set, or the required power domains
5165 intel_display_power_get(dev_priv
, POWER_DOMAIN_PIPE_A
);
5167 if (IS_CHERRYVIEW(dev
))
5168 cherryview_set_cdclk(dev
, req_cdclk
);
5170 valleyview_set_cdclk(dev
, req_cdclk
);
5172 vlv_program_pfi_credits(dev_priv
);
5174 intel_display_power_put(dev_priv
, POWER_DOMAIN_PIPE_A
);
5178 static void valleyview_crtc_enable(struct drm_crtc
*crtc
)
5180 struct drm_device
*dev
= crtc
->dev
;
5181 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5182 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5183 struct intel_encoder
*encoder
;
5184 int pipe
= intel_crtc
->pipe
;
5187 WARN_ON(!crtc
->state
->enable
);
5189 if (intel_crtc
->active
)
5192 is_dsi
= intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_DSI
);
5195 if (IS_CHERRYVIEW(dev
))
5196 chv_prepare_pll(intel_crtc
, intel_crtc
->config
);
5198 vlv_prepare_pll(intel_crtc
, intel_crtc
->config
);
5201 if (intel_crtc
->config
->has_dp_encoder
)
5202 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5204 intel_set_pipe_timings(intel_crtc
);
5206 if (IS_CHERRYVIEW(dev
) && pipe
== PIPE_B
) {
5207 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5209 I915_WRITE(CHV_BLEND(pipe
), CHV_BLEND_LEGACY
);
5210 I915_WRITE(CHV_CANVAS(pipe
), 0);
5213 i9xx_set_pipeconf(intel_crtc
);
5215 intel_crtc
->active
= true;
5217 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5219 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5220 if (encoder
->pre_pll_enable
)
5221 encoder
->pre_pll_enable(encoder
);
5224 if (IS_CHERRYVIEW(dev
))
5225 chv_enable_pll(intel_crtc
, intel_crtc
->config
);
5227 vlv_enable_pll(intel_crtc
, intel_crtc
->config
);
5230 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5231 if (encoder
->pre_enable
)
5232 encoder
->pre_enable(encoder
);
5234 i9xx_pfit_enable(intel_crtc
);
5236 intel_crtc_load_lut(crtc
);
5238 intel_update_watermarks(crtc
);
5239 intel_enable_pipe(intel_crtc
);
5241 assert_vblank_disabled(crtc
);
5242 drm_crtc_vblank_on(crtc
);
5244 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5245 encoder
->enable(encoder
);
5247 intel_crtc_enable_planes(crtc
);
5249 /* Underruns don't raise interrupts, so check manually. */
5250 i9xx_check_fifo_underruns(dev_priv
);
5253 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
5255 struct drm_device
*dev
= crtc
->base
.dev
;
5256 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5258 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp0
);
5259 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp1
);
5262 static void i9xx_crtc_enable(struct drm_crtc
*crtc
)
5264 struct drm_device
*dev
= crtc
->dev
;
5265 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5266 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5267 struct intel_encoder
*encoder
;
5268 int pipe
= intel_crtc
->pipe
;
5270 WARN_ON(!crtc
->state
->enable
);
5272 if (intel_crtc
->active
)
5275 i9xx_set_pll_dividers(intel_crtc
);
5277 if (intel_crtc
->config
->has_dp_encoder
)
5278 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5280 intel_set_pipe_timings(intel_crtc
);
5282 i9xx_set_pipeconf(intel_crtc
);
5284 intel_crtc
->active
= true;
5287 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5289 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5290 if (encoder
->pre_enable
)
5291 encoder
->pre_enable(encoder
);
5293 i9xx_enable_pll(intel_crtc
);
5295 i9xx_pfit_enable(intel_crtc
);
5297 intel_crtc_load_lut(crtc
);
5299 intel_update_watermarks(crtc
);
5300 intel_enable_pipe(intel_crtc
);
5302 assert_vblank_disabled(crtc
);
5303 drm_crtc_vblank_on(crtc
);
5305 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5306 encoder
->enable(encoder
);
5308 intel_crtc_enable_planes(crtc
);
5311 * Gen2 reports pipe underruns whenever all planes are disabled.
5312 * So don't enable underrun reporting before at least some planes
5314 * FIXME: Need to fix the logic to work when we turn off all planes
5315 * but leave the pipe running.
5318 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5320 /* Underruns don't raise interrupts, so check manually. */
5321 i9xx_check_fifo_underruns(dev_priv
);
5324 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
5326 struct drm_device
*dev
= crtc
->base
.dev
;
5327 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5329 if (!crtc
->config
->gmch_pfit
.control
)
5332 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5334 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
5335 I915_READ(PFIT_CONTROL
));
5336 I915_WRITE(PFIT_CONTROL
, 0);
5339 static void i9xx_crtc_disable(struct drm_crtc
*crtc
)
5341 struct drm_device
*dev
= crtc
->dev
;
5342 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5343 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5344 struct intel_encoder
*encoder
;
5345 int pipe
= intel_crtc
->pipe
;
5347 if (!intel_crtc
->active
)
5351 * Gen2 reports pipe underruns whenever all planes are disabled.
5352 * So diasble underrun reporting before all the planes get disabled.
5353 * FIXME: Need to fix the logic to work when we turn off all planes
5354 * but leave the pipe running.
5357 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5360 * Vblank time updates from the shadow to live plane control register
5361 * are blocked if the memory self-refresh mode is active at that
5362 * moment. So to make sure the plane gets truly disabled, disable
5363 * first the self-refresh mode. The self-refresh enable bit in turn
5364 * will be checked/applied by the HW only at the next frame start
5365 * event which is after the vblank start event, so we need to have a
5366 * wait-for-vblank between disabling the plane and the pipe.
5368 intel_set_memory_cxsr(dev_priv
, false);
5369 intel_crtc_disable_planes(crtc
);
5372 * On gen2 planes are double buffered but the pipe isn't, so we must
5373 * wait for planes to fully turn off before disabling the pipe.
5374 * We also need to wait on all gmch platforms because of the
5375 * self-refresh mode constraint explained above.
5377 intel_wait_for_vblank(dev
, pipe
);
5379 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5380 encoder
->disable(encoder
);
5382 drm_crtc_vblank_off(crtc
);
5383 assert_vblank_disabled(crtc
);
5385 intel_disable_pipe(intel_crtc
);
5387 i9xx_pfit_disable(intel_crtc
);
5389 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5390 if (encoder
->post_disable
)
5391 encoder
->post_disable(encoder
);
5393 if (!intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_DSI
)) {
5394 if (IS_CHERRYVIEW(dev
))
5395 chv_disable_pll(dev_priv
, pipe
);
5396 else if (IS_VALLEYVIEW(dev
))
5397 vlv_disable_pll(dev_priv
, pipe
);
5399 i9xx_disable_pll(intel_crtc
);
5403 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
5405 intel_crtc
->active
= false;
5406 intel_update_watermarks(crtc
);
5408 mutex_lock(&dev
->struct_mutex
);
5409 intel_fbc_update(dev
);
5410 mutex_unlock(&dev
->struct_mutex
);
5413 static void i9xx_crtc_off(struct drm_crtc
*crtc
)
5417 /* Master function to enable/disable CRTC and corresponding power wells */
5418 void intel_crtc_control(struct drm_crtc
*crtc
, bool enable
)
5420 struct drm_device
*dev
= crtc
->dev
;
5421 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5422 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5423 enum intel_display_power_domain domain
;
5424 unsigned long domains
;
5427 if (!intel_crtc
->active
) {
5428 domains
= get_crtc_power_domains(crtc
);
5429 for_each_power_domain(domain
, domains
)
5430 intel_display_power_get(dev_priv
, domain
);
5431 intel_crtc
->enabled_power_domains
= domains
;
5433 dev_priv
->display
.crtc_enable(crtc
);
5436 if (intel_crtc
->active
) {
5437 dev_priv
->display
.crtc_disable(crtc
);
5439 domains
= intel_crtc
->enabled_power_domains
;
5440 for_each_power_domain(domain
, domains
)
5441 intel_display_power_put(dev_priv
, domain
);
5442 intel_crtc
->enabled_power_domains
= 0;
5448 * Sets the power management mode of the pipe and plane.
5450 void intel_crtc_update_dpms(struct drm_crtc
*crtc
)
5452 struct drm_device
*dev
= crtc
->dev
;
5453 struct intel_encoder
*intel_encoder
;
5454 bool enable
= false;
5456 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
5457 enable
|= intel_encoder
->connectors_active
;
5459 intel_crtc_control(crtc
, enable
);
5462 static void intel_crtc_disable(struct drm_crtc
*crtc
)
5464 struct drm_device
*dev
= crtc
->dev
;
5465 struct drm_connector
*connector
;
5466 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5468 /* crtc should still be enabled when we disable it. */
5469 WARN_ON(!crtc
->state
->enable
);
5471 dev_priv
->display
.crtc_disable(crtc
);
5472 dev_priv
->display
.off(crtc
);
5474 crtc
->primary
->funcs
->disable_plane(crtc
->primary
);
5476 /* Update computed state. */
5477 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
5478 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
5481 if (connector
->encoder
->crtc
!= crtc
)
5484 connector
->dpms
= DRM_MODE_DPMS_OFF
;
5485 to_intel_encoder(connector
->encoder
)->connectors_active
= false;
5489 void intel_encoder_destroy(struct drm_encoder
*encoder
)
5491 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5493 drm_encoder_cleanup(encoder
);
5494 kfree(intel_encoder
);
5497 /* Simple dpms helper for encoders with just one connector, no cloning and only
5498 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
5499 * state of the entire output pipe. */
5500 static void intel_encoder_dpms(struct intel_encoder
*encoder
, int mode
)
5502 if (mode
== DRM_MODE_DPMS_ON
) {
5503 encoder
->connectors_active
= true;
5505 intel_crtc_update_dpms(encoder
->base
.crtc
);
5507 encoder
->connectors_active
= false;
5509 intel_crtc_update_dpms(encoder
->base
.crtc
);
5513 /* Cross check the actual hw state with our own modeset state tracking (and it's
5514 * internal consistency). */
5515 static void intel_connector_check_state(struct intel_connector
*connector
)
5517 if (connector
->get_hw_state(connector
)) {
5518 struct intel_encoder
*encoder
= connector
->encoder
;
5519 struct drm_crtc
*crtc
;
5520 bool encoder_enabled
;
5523 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
5524 connector
->base
.base
.id
,
5525 connector
->base
.name
);
5527 /* there is no real hw state for MST connectors */
5528 if (connector
->mst_port
)
5531 I915_STATE_WARN(connector
->base
.dpms
== DRM_MODE_DPMS_OFF
,
5532 "wrong connector dpms state\n");
5533 I915_STATE_WARN(connector
->base
.encoder
!= &encoder
->base
,
5534 "active connector not linked to encoder\n");
5537 I915_STATE_WARN(!encoder
->connectors_active
,
5538 "encoder->connectors_active not set\n");
5540 encoder_enabled
= encoder
->get_hw_state(encoder
, &pipe
);
5541 I915_STATE_WARN(!encoder_enabled
, "encoder not enabled\n");
5542 if (I915_STATE_WARN_ON(!encoder
->base
.crtc
))
5545 crtc
= encoder
->base
.crtc
;
5547 I915_STATE_WARN(!crtc
->state
->enable
,
5548 "crtc not enabled\n");
5549 I915_STATE_WARN(!to_intel_crtc(crtc
)->active
, "crtc not active\n");
5550 I915_STATE_WARN(pipe
!= to_intel_crtc(crtc
)->pipe
,
5551 "encoder active on the wrong pipe\n");
5556 /* Even simpler default implementation, if there's really no special case to
5558 void intel_connector_dpms(struct drm_connector
*connector
, int mode
)
5560 /* All the simple cases only support two dpms states. */
5561 if (mode
!= DRM_MODE_DPMS_ON
)
5562 mode
= DRM_MODE_DPMS_OFF
;
5564 if (mode
== connector
->dpms
)
5567 connector
->dpms
= mode
;
5569 /* Only need to change hw state when actually enabled */
5570 if (connector
->encoder
)
5571 intel_encoder_dpms(to_intel_encoder(connector
->encoder
), mode
);
5573 intel_modeset_check_state(connector
->dev
);
5576 /* Simple connector->get_hw_state implementation for encoders that support only
5577 * one connector and no cloning and hence the encoder state determines the state
5578 * of the connector. */
5579 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
5582 struct intel_encoder
*encoder
= connector
->encoder
;
5584 return encoder
->get_hw_state(encoder
, &pipe
);
5587 static int pipe_required_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
)
5589 struct intel_crtc
*crtc
=
5590 to_intel_crtc(intel_get_crtc_for_pipe(dev
, pipe
));
5592 if (crtc
->base
.state
->enable
&&
5593 crtc
->config
->has_pch_encoder
)
5594 return crtc
->config
->fdi_lanes
;
5599 static bool ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
5600 struct intel_crtc_state
*pipe_config
)
5602 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
5603 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5604 if (pipe_config
->fdi_lanes
> 4) {
5605 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
5606 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5610 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
5611 if (pipe_config
->fdi_lanes
> 2) {
5612 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
5613 pipe_config
->fdi_lanes
);
5620 if (INTEL_INFO(dev
)->num_pipes
== 2)
5623 /* Ivybridge 3 pipe is really complicated */
5628 if (pipe_config
->fdi_lanes
> 2 &&
5629 pipe_required_fdi_lanes(dev
, PIPE_C
) > 0) {
5630 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5631 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5636 if (pipe_config
->fdi_lanes
> 2) {
5637 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
5638 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5641 if (pipe_required_fdi_lanes(dev
, PIPE_B
) > 2) {
5642 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
5652 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
5653 struct intel_crtc_state
*pipe_config
)
5655 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5656 struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
5657 int lane
, link_bw
, fdi_dotclock
;
5658 bool setup_ok
, needs_recompute
= false;
5661 /* FDI is a binary signal running at ~2.7GHz, encoding
5662 * each output octet as 10 bits. The actual frequency
5663 * is stored as a divider into a 100MHz clock, and the
5664 * mode pixel clock is stored in units of 1KHz.
5665 * Hence the bw of each lane in terms of the mode signal
5668 link_bw
= intel_fdi_link_freq(dev
) * MHz(100)/KHz(1)/10;
5670 fdi_dotclock
= adjusted_mode
->crtc_clock
;
5672 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
5673 pipe_config
->pipe_bpp
);
5675 pipe_config
->fdi_lanes
= lane
;
5677 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
5678 link_bw
, &pipe_config
->fdi_m_n
);
5680 setup_ok
= ironlake_check_fdi_lanes(intel_crtc
->base
.dev
,
5681 intel_crtc
->pipe
, pipe_config
);
5682 if (!setup_ok
&& pipe_config
->pipe_bpp
> 6*3) {
5683 pipe_config
->pipe_bpp
-= 2*3;
5684 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
5685 pipe_config
->pipe_bpp
);
5686 needs_recompute
= true;
5687 pipe_config
->bw_constrained
= true;
5692 if (needs_recompute
)
5695 return setup_ok
? 0 : -EINVAL
;
5698 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
5699 struct intel_crtc_state
*pipe_config
)
5701 pipe_config
->ips_enabled
= i915
.enable_ips
&&
5702 hsw_crtc_supports_ips(crtc
) &&
5703 pipe_config
->pipe_bpp
<= 24;
5706 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
5707 struct intel_crtc_state
*pipe_config
)
5709 struct drm_device
*dev
= crtc
->base
.dev
;
5710 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5711 struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
5713 /* FIXME should check pixel clock limits on all platforms */
5714 if (INTEL_INFO(dev
)->gen
< 4) {
5716 dev_priv
->display
.get_display_clock_speed(dev
);
5719 * Enable pixel doubling when the dot clock
5720 * is > 90% of the (display) core speed.
5722 * GDG double wide on either pipe,
5723 * otherwise pipe A only.
5725 if ((crtc
->pipe
== PIPE_A
|| IS_I915G(dev
)) &&
5726 adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10) {
5728 pipe_config
->double_wide
= true;
5731 if (adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10)
5736 * Pipe horizontal size must be even in:
5738 * - LVDS dual channel mode
5739 * - Double wide pipe
5741 if ((intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_LVDS
) &&
5742 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
5743 pipe_config
->pipe_src_w
&= ~1;
5745 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
5746 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
5748 if ((INTEL_INFO(dev
)->gen
> 4 || IS_G4X(dev
)) &&
5749 adjusted_mode
->hsync_start
== adjusted_mode
->hdisplay
)
5752 if ((IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) && pipe_config
->pipe_bpp
> 10*3) {
5753 pipe_config
->pipe_bpp
= 10*3; /* 12bpc is gen5+ */
5754 } else if (INTEL_INFO(dev
)->gen
<= 4 && pipe_config
->pipe_bpp
> 8*3) {
5755 /* only a 8bpc pipe, with 6bpc dither through the panel fitter
5757 pipe_config
->pipe_bpp
= 8*3;
5761 hsw_compute_ips_config(crtc
, pipe_config
);
5763 if (pipe_config
->has_pch_encoder
)
5764 return ironlake_fdi_compute_config(crtc
, pipe_config
);
5769 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
5771 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5775 if (dev_priv
->hpll_freq
== 0)
5776 dev_priv
->hpll_freq
= valleyview_get_vco(dev_priv
);
5778 mutex_lock(&dev_priv
->dpio_lock
);
5779 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
5780 mutex_unlock(&dev_priv
->dpio_lock
);
5782 divider
= val
& DISPLAY_FREQUENCY_VALUES
;
5784 WARN((val
& DISPLAY_FREQUENCY_STATUS
) !=
5785 (divider
<< DISPLAY_FREQUENCY_STATUS_SHIFT
),
5786 "cdclk change in progress\n");
5788 return DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, divider
+ 1);
5791 static int i945_get_display_clock_speed(struct drm_device
*dev
)
5796 static int i915_get_display_clock_speed(struct drm_device
*dev
)
5801 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
5806 static int pnv_get_display_clock_speed(struct drm_device
*dev
)
5810 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
5812 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
5813 case GC_DISPLAY_CLOCK_267_MHZ_PNV
:
5815 case GC_DISPLAY_CLOCK_333_MHZ_PNV
:
5817 case GC_DISPLAY_CLOCK_444_MHZ_PNV
:
5819 case GC_DISPLAY_CLOCK_200_MHZ_PNV
:
5822 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc
);
5823 case GC_DISPLAY_CLOCK_133_MHZ_PNV
:
5825 case GC_DISPLAY_CLOCK_167_MHZ_PNV
:
5830 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
5834 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
5836 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
5839 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
5840 case GC_DISPLAY_CLOCK_333_MHZ
:
5843 case GC_DISPLAY_CLOCK_190_200_MHZ
:
5849 static int i865_get_display_clock_speed(struct drm_device
*dev
)
5854 static int i855_get_display_clock_speed(struct drm_device
*dev
)
5857 /* Assume that the hardware is in the high speed state. This
5858 * should be the default.
5860 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
5861 case GC_CLOCK_133_200
:
5862 case GC_CLOCK_100_200
:
5864 case GC_CLOCK_166_250
:
5866 case GC_CLOCK_100_133
:
5870 /* Shouldn't happen */
5874 static int i830_get_display_clock_speed(struct drm_device
*dev
)
5880 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
5882 while (*num
> DATA_LINK_M_N_MASK
||
5883 *den
> DATA_LINK_M_N_MASK
) {
5889 static void compute_m_n(unsigned int m
, unsigned int n
,
5890 uint32_t *ret_m
, uint32_t *ret_n
)
5892 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
5893 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
5894 intel_reduce_m_n_ratio(ret_m
, ret_n
);
5898 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
5899 int pixel_clock
, int link_clock
,
5900 struct intel_link_m_n
*m_n
)
5904 compute_m_n(bits_per_pixel
* pixel_clock
,
5905 link_clock
* nlanes
* 8,
5906 &m_n
->gmch_m
, &m_n
->gmch_n
);
5908 compute_m_n(pixel_clock
, link_clock
,
5909 &m_n
->link_m
, &m_n
->link_n
);
5912 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
5914 if (i915
.panel_use_ssc
>= 0)
5915 return i915
.panel_use_ssc
!= 0;
5916 return dev_priv
->vbt
.lvds_use_ssc
5917 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
5920 static int i9xx_get_refclk(struct intel_crtc
*crtc
, int num_connectors
)
5922 struct drm_device
*dev
= crtc
->base
.dev
;
5923 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5926 if (IS_VALLEYVIEW(dev
)) {
5928 } else if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_LVDS
) &&
5929 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
5930 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
5931 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
5932 } else if (!IS_GEN2(dev
)) {
5941 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
5943 return (1 << dpll
->n
) << 16 | dpll
->m2
;
5946 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
5948 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
5951 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
5952 struct intel_crtc_state
*crtc_state
,
5953 intel_clock_t
*reduced_clock
)
5955 struct drm_device
*dev
= crtc
->base
.dev
;
5958 if (IS_PINEVIEW(dev
)) {
5959 fp
= pnv_dpll_compute_fp(&crtc_state
->dpll
);
5961 fp2
= pnv_dpll_compute_fp(reduced_clock
);
5963 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
5965 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
5968 crtc_state
->dpll_hw_state
.fp0
= fp
;
5970 crtc
->lowfreq_avail
= false;
5971 if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_LVDS
) &&
5972 reduced_clock
&& i915
.powersave
) {
5973 crtc_state
->dpll_hw_state
.fp1
= fp2
;
5974 crtc
->lowfreq_avail
= true;
5976 crtc_state
->dpll_hw_state
.fp1
= fp
;
5980 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
5986 * PLLB opamp always calibrates to max value of 0x3f, force enable it
5987 * and set it to a reasonable value instead.
5989 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
5990 reg_val
&= 0xffffff00;
5991 reg_val
|= 0x00000030;
5992 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
5994 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
5995 reg_val
&= 0x8cffffff;
5996 reg_val
= 0x8c000000;
5997 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
5999 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6000 reg_val
&= 0xffffff00;
6001 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6003 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6004 reg_val
&= 0x00ffffff;
6005 reg_val
|= 0xb0000000;
6006 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6009 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
6010 struct intel_link_m_n
*m_n
)
6012 struct drm_device
*dev
= crtc
->base
.dev
;
6013 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6014 int pipe
= crtc
->pipe
;
6016 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6017 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
6018 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
6019 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
6022 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
6023 struct intel_link_m_n
*m_n
,
6024 struct intel_link_m_n
*m2_n2
)
6026 struct drm_device
*dev
= crtc
->base
.dev
;
6027 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6028 int pipe
= crtc
->pipe
;
6029 enum transcoder transcoder
= crtc
->config
->cpu_transcoder
;
6031 if (INTEL_INFO(dev
)->gen
>= 5) {
6032 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6033 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
6034 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
6035 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
6036 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
6037 * for gen < 8) and if DRRS is supported (to make sure the
6038 * registers are not unnecessarily accessed).
6040 if (m2_n2
&& (IS_CHERRYVIEW(dev
) || INTEL_INFO(dev
)->gen
< 8) &&
6041 crtc
->config
->has_drrs
) {
6042 I915_WRITE(PIPE_DATA_M2(transcoder
),
6043 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
6044 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
6045 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
6046 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
6049 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6050 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
6051 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
6052 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
6056 void intel_dp_set_m_n(struct intel_crtc
*crtc
, enum link_m_n_set m_n
)
6058 struct intel_link_m_n
*dp_m_n
, *dp_m2_n2
= NULL
;
6061 dp_m_n
= &crtc
->config
->dp_m_n
;
6062 dp_m2_n2
= &crtc
->config
->dp_m2_n2
;
6063 } else if (m_n
== M2_N2
) {
6066 * M2_N2 registers are not supported. Hence m2_n2 divider value
6067 * needs to be programmed into M1_N1.
6069 dp_m_n
= &crtc
->config
->dp_m2_n2
;
6071 DRM_ERROR("Unsupported divider value\n");
6075 if (crtc
->config
->has_pch_encoder
)
6076 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
->dp_m_n
);
6078 intel_cpu_transcoder_set_m_n(crtc
, dp_m_n
, dp_m2_n2
);
6081 static void vlv_update_pll(struct intel_crtc
*crtc
,
6082 struct intel_crtc_state
*pipe_config
)
6087 * Enable DPIO clock input. We should never disable the reference
6088 * clock for pipe B, since VGA hotplug / manual detection depends
6091 dpll
= DPLL_EXT_BUFFER_ENABLE_VLV
| DPLL_REFA_CLK_ENABLE_VLV
|
6092 DPLL_VGA_MODE_DIS
| DPLL_INTEGRATED_CLOCK_VLV
;
6093 /* We should never disable this, set it here for state tracking */
6094 if (crtc
->pipe
== PIPE_B
)
6095 dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
6096 dpll
|= DPLL_VCO_ENABLE
;
6097 pipe_config
->dpll_hw_state
.dpll
= dpll
;
6099 dpll_md
= (pipe_config
->pixel_multiplier
- 1)
6100 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6101 pipe_config
->dpll_hw_state
.dpll_md
= dpll_md
;
6104 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
6105 const struct intel_crtc_state
*pipe_config
)
6107 struct drm_device
*dev
= crtc
->base
.dev
;
6108 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6109 int pipe
= crtc
->pipe
;
6111 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
6112 u32 coreclk
, reg_val
;
6114 mutex_lock(&dev_priv
->dpio_lock
);
6116 bestn
= pipe_config
->dpll
.n
;
6117 bestm1
= pipe_config
->dpll
.m1
;
6118 bestm2
= pipe_config
->dpll
.m2
;
6119 bestp1
= pipe_config
->dpll
.p1
;
6120 bestp2
= pipe_config
->dpll
.p2
;
6122 /* See eDP HDMI DPIO driver vbios notes doc */
6124 /* PLL B needs special handling */
6126 vlv_pllb_recal_opamp(dev_priv
, pipe
);
6128 /* Set up Tx target for periodic Rcomp update */
6129 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
6131 /* Disable target IRef on PLL */
6132 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
6133 reg_val
&= 0x00ffffff;
6134 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
6136 /* Disable fast lock */
6137 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
6139 /* Set idtafcrecal before PLL is enabled */
6140 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
6141 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
6142 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
6143 mdiv
|= (1 << DPIO_K_SHIFT
);
6146 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6147 * but we don't support that).
6148 * Note: don't use the DAC post divider as it seems unstable.
6150 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
6151 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
6153 mdiv
|= DPIO_ENABLE_CALIBRATION
;
6154 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
6156 /* Set HBR and RBR LPF coefficients */
6157 if (pipe_config
->port_clock
== 162000 ||
6158 intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
) ||
6159 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
))
6160 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
6163 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
6166 if (pipe_config
->has_dp_encoder
) {
6167 /* Use SSC source */
6169 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6172 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6174 } else { /* HDMI or VGA */
6175 /* Use bend source */
6177 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6180 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6184 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
6185 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
6186 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
6187 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))
6188 coreclk
|= 0x01000000;
6189 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
6191 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
6192 mutex_unlock(&dev_priv
->dpio_lock
);
6195 static void chv_update_pll(struct intel_crtc
*crtc
,
6196 struct intel_crtc_state
*pipe_config
)
6198 pipe_config
->dpll_hw_state
.dpll
= DPLL_SSC_REF_CLOCK_CHV
|
6199 DPLL_REFA_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
|
6201 if (crtc
->pipe
!= PIPE_A
)
6202 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
6204 pipe_config
->dpll_hw_state
.dpll_md
=
6205 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6208 static void chv_prepare_pll(struct intel_crtc
*crtc
,
6209 const struct intel_crtc_state
*pipe_config
)
6211 struct drm_device
*dev
= crtc
->base
.dev
;
6212 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6213 int pipe
= crtc
->pipe
;
6214 int dpll_reg
= DPLL(crtc
->pipe
);
6215 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
6216 u32 loopfilter
, tribuf_calcntr
;
6217 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
6221 bestn
= pipe_config
->dpll
.n
;
6222 bestm2_frac
= pipe_config
->dpll
.m2
& 0x3fffff;
6223 bestm1
= pipe_config
->dpll
.m1
;
6224 bestm2
= pipe_config
->dpll
.m2
>> 22;
6225 bestp1
= pipe_config
->dpll
.p1
;
6226 bestp2
= pipe_config
->dpll
.p2
;
6227 vco
= pipe_config
->dpll
.vco
;
6232 * Enable Refclk and SSC
6234 I915_WRITE(dpll_reg
,
6235 pipe_config
->dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
6237 mutex_lock(&dev_priv
->dpio_lock
);
6239 /* p1 and p2 divider */
6240 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
6241 5 << DPIO_CHV_S1_DIV_SHIFT
|
6242 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
6243 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
6244 1 << DPIO_CHV_K_DIV_SHIFT
);
6246 /* Feedback post-divider - m2 */
6247 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
6249 /* Feedback refclk divider - n and m1 */
6250 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
6251 DPIO_CHV_M1_DIV_BY_2
|
6252 1 << DPIO_CHV_N_DIV_SHIFT
);
6254 /* M2 fraction division */
6256 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
6258 /* M2 fraction division enable */
6259 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
6260 dpio_val
&= ~(DPIO_CHV_FEEDFWD_GAIN_MASK
| DPIO_CHV_FRAC_DIV_EN
);
6261 dpio_val
|= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
);
6263 dpio_val
|= DPIO_CHV_FRAC_DIV_EN
;
6264 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
), dpio_val
);
6266 /* Program digital lock detect threshold */
6267 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW9(port
));
6268 dpio_val
&= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK
|
6269 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
);
6270 dpio_val
|= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT
);
6272 dpio_val
|= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
;
6273 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW9(port
), dpio_val
);
6276 if (vco
== 5400000) {
6277 loopfilter
|= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT
);
6278 loopfilter
|= (0x8 << DPIO_CHV_INT_COEFF_SHIFT
);
6279 loopfilter
|= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6280 tribuf_calcntr
= 0x9;
6281 } else if (vco
<= 6200000) {
6282 loopfilter
|= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT
);
6283 loopfilter
|= (0xB << DPIO_CHV_INT_COEFF_SHIFT
);
6284 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6285 tribuf_calcntr
= 0x9;
6286 } else if (vco
<= 6480000) {
6287 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
6288 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
6289 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6290 tribuf_calcntr
= 0x8;
6292 /* Not supported. Apply the same limits as in the max case */
6293 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
6294 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
6295 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
6298 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
6300 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW8(port
));
6301 dpio_val
&= ~DPIO_CHV_TDC_TARGET_CNT_MASK
;
6302 dpio_val
|= (tribuf_calcntr
<< DPIO_CHV_TDC_TARGET_CNT_SHIFT
);
6303 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW8(port
), dpio_val
);
6306 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
6307 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
6310 mutex_unlock(&dev_priv
->dpio_lock
);
6314 * vlv_force_pll_on - forcibly enable just the PLL
6315 * @dev_priv: i915 private structure
6316 * @pipe: pipe PLL to enable
6317 * @dpll: PLL configuration
6319 * Enable the PLL for @pipe using the supplied @dpll config. To be used
6320 * in cases where we need the PLL enabled even when @pipe is not going to
6323 void vlv_force_pll_on(struct drm_device
*dev
, enum pipe pipe
,
6324 const struct dpll
*dpll
)
6326 struct intel_crtc
*crtc
=
6327 to_intel_crtc(intel_get_crtc_for_pipe(dev
, pipe
));
6328 struct intel_crtc_state pipe_config
= {
6329 .pixel_multiplier
= 1,
6333 if (IS_CHERRYVIEW(dev
)) {
6334 chv_update_pll(crtc
, &pipe_config
);
6335 chv_prepare_pll(crtc
, &pipe_config
);
6336 chv_enable_pll(crtc
, &pipe_config
);
6338 vlv_update_pll(crtc
, &pipe_config
);
6339 vlv_prepare_pll(crtc
, &pipe_config
);
6340 vlv_enable_pll(crtc
, &pipe_config
);
6345 * vlv_force_pll_off - forcibly disable just the PLL
6346 * @dev_priv: i915 private structure
6347 * @pipe: pipe PLL to disable
6349 * Disable the PLL for @pipe. To be used in cases where we need
6350 * the PLL enabled even when @pipe is not going to be enabled.
6352 void vlv_force_pll_off(struct drm_device
*dev
, enum pipe pipe
)
6354 if (IS_CHERRYVIEW(dev
))
6355 chv_disable_pll(to_i915(dev
), pipe
);
6357 vlv_disable_pll(to_i915(dev
), pipe
);
6360 static void i9xx_update_pll(struct intel_crtc
*crtc
,
6361 struct intel_crtc_state
*crtc_state
,
6362 intel_clock_t
*reduced_clock
,
6365 struct drm_device
*dev
= crtc
->base
.dev
;
6366 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6369 struct dpll
*clock
= &crtc_state
->dpll
;
6371 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
6373 is_sdvo
= intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_SDVO
) ||
6374 intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_HDMI
);
6376 dpll
= DPLL_VGA_MODE_DIS
;
6378 if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_LVDS
))
6379 dpll
|= DPLLB_MODE_LVDS
;
6381 dpll
|= DPLLB_MODE_DAC_SERIAL
;
6383 if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
6384 dpll
|= (crtc_state
->pixel_multiplier
- 1)
6385 << SDVO_MULTIPLIER_SHIFT_HIRES
;
6389 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6391 if (crtc_state
->has_dp_encoder
)
6392 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6394 /* compute bitmask from p1 value */
6395 if (IS_PINEVIEW(dev
))
6396 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
6398 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6399 if (IS_G4X(dev
) && reduced_clock
)
6400 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
6402 switch (clock
->p2
) {
6404 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
6407 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
6410 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
6413 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
6416 if (INTEL_INFO(dev
)->gen
>= 4)
6417 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
6419 if (crtc_state
->sdvo_tv_clock
)
6420 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
6421 else if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_LVDS
) &&
6422 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
6423 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
6425 dpll
|= PLL_REF_INPUT_DREFCLK
;
6427 dpll
|= DPLL_VCO_ENABLE
;
6428 crtc_state
->dpll_hw_state
.dpll
= dpll
;
6430 if (INTEL_INFO(dev
)->gen
>= 4) {
6431 u32 dpll_md
= (crtc_state
->pixel_multiplier
- 1)
6432 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6433 crtc_state
->dpll_hw_state
.dpll_md
= dpll_md
;
6437 static void i8xx_update_pll(struct intel_crtc
*crtc
,
6438 struct intel_crtc_state
*crtc_state
,
6439 intel_clock_t
*reduced_clock
,
6442 struct drm_device
*dev
= crtc
->base
.dev
;
6443 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6445 struct dpll
*clock
= &crtc_state
->dpll
;
6447 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
6449 dpll
= DPLL_VGA_MODE_DIS
;
6451 if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_LVDS
)) {
6452 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6455 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
6457 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6459 dpll
|= PLL_P2_DIVIDE_BY_4
;
6462 if (!IS_I830(dev
) && intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_DVO
))
6463 dpll
|= DPLL_DVO_2X_MODE
;
6465 if (intel_pipe_will_have_type(crtc
, INTEL_OUTPUT_LVDS
) &&
6466 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
6467 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
6469 dpll
|= PLL_REF_INPUT_DREFCLK
;
6471 dpll
|= DPLL_VCO_ENABLE
;
6472 crtc_state
->dpll_hw_state
.dpll
= dpll
;
6475 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
6477 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6478 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6479 enum pipe pipe
= intel_crtc
->pipe
;
6480 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
6481 struct drm_display_mode
*adjusted_mode
=
6482 &intel_crtc
->config
->base
.adjusted_mode
;
6483 uint32_t crtc_vtotal
, crtc_vblank_end
;
6486 /* We need to be careful not to changed the adjusted mode, for otherwise
6487 * the hw state checker will get angry at the mismatch. */
6488 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
6489 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
6491 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
6492 /* the chip adds 2 halflines automatically */
6494 crtc_vblank_end
-= 1;
6496 if (intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
6497 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
6499 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
6500 adjusted_mode
->crtc_htotal
/ 2;
6502 vsyncshift
+= adjusted_mode
->crtc_htotal
;
6505 if (INTEL_INFO(dev
)->gen
> 3)
6506 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
6508 I915_WRITE(HTOTAL(cpu_transcoder
),
6509 (adjusted_mode
->crtc_hdisplay
- 1) |
6510 ((adjusted_mode
->crtc_htotal
- 1) << 16));
6511 I915_WRITE(HBLANK(cpu_transcoder
),
6512 (adjusted_mode
->crtc_hblank_start
- 1) |
6513 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
6514 I915_WRITE(HSYNC(cpu_transcoder
),
6515 (adjusted_mode
->crtc_hsync_start
- 1) |
6516 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
6518 I915_WRITE(VTOTAL(cpu_transcoder
),
6519 (adjusted_mode
->crtc_vdisplay
- 1) |
6520 ((crtc_vtotal
- 1) << 16));
6521 I915_WRITE(VBLANK(cpu_transcoder
),
6522 (adjusted_mode
->crtc_vblank_start
- 1) |
6523 ((crtc_vblank_end
- 1) << 16));
6524 I915_WRITE(VSYNC(cpu_transcoder
),
6525 (adjusted_mode
->crtc_vsync_start
- 1) |
6526 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
6528 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
6529 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
6530 * documented on the DDI_FUNC_CTL register description, EDP Input Select
6532 if (IS_HASWELL(dev
) && cpu_transcoder
== TRANSCODER_EDP
&&
6533 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
6534 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
6536 /* pipesrc controls the size that is scaled from, which should
6537 * always be the user's requested size.
6539 I915_WRITE(PIPESRC(pipe
),
6540 ((intel_crtc
->config
->pipe_src_w
- 1) << 16) |
6541 (intel_crtc
->config
->pipe_src_h
- 1));
6544 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
6545 struct intel_crtc_state
*pipe_config
)
6547 struct drm_device
*dev
= crtc
->base
.dev
;
6548 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6549 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
6552 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
6553 pipe_config
->base
.adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
6554 pipe_config
->base
.adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
6555 tmp
= I915_READ(HBLANK(cpu_transcoder
));
6556 pipe_config
->base
.adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
6557 pipe_config
->base
.adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
6558 tmp
= I915_READ(HSYNC(cpu_transcoder
));
6559 pipe_config
->base
.adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
6560 pipe_config
->base
.adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
6562 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
6563 pipe_config
->base
.adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
6564 pipe_config
->base
.adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
6565 tmp
= I915_READ(VBLANK(cpu_transcoder
));
6566 pipe_config
->base
.adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
6567 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
6568 tmp
= I915_READ(VSYNC(cpu_transcoder
));
6569 pipe_config
->base
.adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
6570 pipe_config
->base
.adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
6572 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
6573 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
6574 pipe_config
->base
.adjusted_mode
.crtc_vtotal
+= 1;
6575 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
+= 1;
6578 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
6579 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
6580 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
6582 pipe_config
->base
.mode
.vdisplay
= pipe_config
->pipe_src_h
;
6583 pipe_config
->base
.mode
.hdisplay
= pipe_config
->pipe_src_w
;
6586 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
6587 struct intel_crtc_state
*pipe_config
)
6589 mode
->hdisplay
= pipe_config
->base
.adjusted_mode
.crtc_hdisplay
;
6590 mode
->htotal
= pipe_config
->base
.adjusted_mode
.crtc_htotal
;
6591 mode
->hsync_start
= pipe_config
->base
.adjusted_mode
.crtc_hsync_start
;
6592 mode
->hsync_end
= pipe_config
->base
.adjusted_mode
.crtc_hsync_end
;
6594 mode
->vdisplay
= pipe_config
->base
.adjusted_mode
.crtc_vdisplay
;
6595 mode
->vtotal
= pipe_config
->base
.adjusted_mode
.crtc_vtotal
;
6596 mode
->vsync_start
= pipe_config
->base
.adjusted_mode
.crtc_vsync_start
;
6597 mode
->vsync_end
= pipe_config
->base
.adjusted_mode
.crtc_vsync_end
;
6599 mode
->flags
= pipe_config
->base
.adjusted_mode
.flags
;
6601 mode
->clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
6602 mode
->flags
|= pipe_config
->base
.adjusted_mode
.flags
;
6605 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
6607 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6608 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6613 if ((intel_crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
6614 (intel_crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
6615 pipeconf
|= I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
;
6617 if (intel_crtc
->config
->double_wide
)
6618 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
6620 /* only g4x and later have fancy bpc/dither controls */
6621 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
6622 /* Bspec claims that we can't use dithering for 30bpp pipes. */
6623 if (intel_crtc
->config
->dither
&& intel_crtc
->config
->pipe_bpp
!= 30)
6624 pipeconf
|= PIPECONF_DITHER_EN
|
6625 PIPECONF_DITHER_TYPE_SP
;
6627 switch (intel_crtc
->config
->pipe_bpp
) {
6629 pipeconf
|= PIPECONF_6BPC
;
6632 pipeconf
|= PIPECONF_8BPC
;
6635 pipeconf
|= PIPECONF_10BPC
;
6638 /* Case prevented by intel_choose_pipe_bpp_dither. */
6643 if (HAS_PIPE_CXSR(dev
)) {
6644 if (intel_crtc
->lowfreq_avail
) {
6645 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
6646 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
6648 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
6652 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
6653 if (INTEL_INFO(dev
)->gen
< 4 ||
6654 intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
6655 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
6657 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
6659 pipeconf
|= PIPECONF_PROGRESSIVE
;
6661 if (IS_VALLEYVIEW(dev
) && intel_crtc
->config
->limited_color_range
)
6662 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
6664 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
6665 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
6668 static int i9xx_crtc_compute_clock(struct intel_crtc
*crtc
,
6669 struct intel_crtc_state
*crtc_state
)
6671 struct drm_device
*dev
= crtc
->base
.dev
;
6672 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6673 int refclk
, num_connectors
= 0;
6674 intel_clock_t clock
, reduced_clock
;
6675 bool ok
, has_reduced_clock
= false;
6676 bool is_lvds
= false, is_dsi
= false;
6677 struct intel_encoder
*encoder
;
6678 const intel_limit_t
*limit
;
6680 for_each_intel_encoder(dev
, encoder
) {
6681 if (encoder
->new_crtc
!= crtc
)
6684 switch (encoder
->type
) {
6685 case INTEL_OUTPUT_LVDS
:
6688 case INTEL_OUTPUT_DSI
:
6701 if (!crtc_state
->clock_set
) {
6702 refclk
= i9xx_get_refclk(crtc
, num_connectors
);
6705 * Returns a set of divisors for the desired target clock with
6706 * the given refclk, or FALSE. The returned values represent
6707 * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
6710 limit
= intel_limit(crtc
, refclk
);
6711 ok
= dev_priv
->display
.find_dpll(limit
, crtc
,
6712 crtc_state
->port_clock
,
6713 refclk
, NULL
, &clock
);
6715 DRM_ERROR("Couldn't find PLL settings for mode!\n");
6719 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
6721 * Ensure we match the reduced clock's P to the target
6722 * clock. If the clocks don't match, we can't switch
6723 * the display clock by using the FP0/FP1. In such case
6724 * we will disable the LVDS downclock feature.
6727 dev_priv
->display
.find_dpll(limit
, crtc
,
6728 dev_priv
->lvds_downclock
,
6732 /* Compat-code for transition, will disappear. */
6733 crtc_state
->dpll
.n
= clock
.n
;
6734 crtc_state
->dpll
.m1
= clock
.m1
;
6735 crtc_state
->dpll
.m2
= clock
.m2
;
6736 crtc_state
->dpll
.p1
= clock
.p1
;
6737 crtc_state
->dpll
.p2
= clock
.p2
;
6741 i8xx_update_pll(crtc
, crtc_state
,
6742 has_reduced_clock
? &reduced_clock
: NULL
,
6744 } else if (IS_CHERRYVIEW(dev
)) {
6745 chv_update_pll(crtc
, crtc_state
);
6746 } else if (IS_VALLEYVIEW(dev
)) {
6747 vlv_update_pll(crtc
, crtc_state
);
6749 i9xx_update_pll(crtc
, crtc_state
,
6750 has_reduced_clock
? &reduced_clock
: NULL
,
6757 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
6758 struct intel_crtc_state
*pipe_config
)
6760 struct drm_device
*dev
= crtc
->base
.dev
;
6761 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6764 if (INTEL_INFO(dev
)->gen
<= 3 && (IS_I830(dev
) || !IS_MOBILE(dev
)))
6767 tmp
= I915_READ(PFIT_CONTROL
);
6768 if (!(tmp
& PFIT_ENABLE
))
6771 /* Check whether the pfit is attached to our pipe. */
6772 if (INTEL_INFO(dev
)->gen
< 4) {
6773 if (crtc
->pipe
!= PIPE_B
)
6776 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
6780 pipe_config
->gmch_pfit
.control
= tmp
;
6781 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
6782 if (INTEL_INFO(dev
)->gen
< 5)
6783 pipe_config
->gmch_pfit
.lvds_border_bits
=
6784 I915_READ(LVDS
) & LVDS_BORDER_ENABLE
;
6787 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
6788 struct intel_crtc_state
*pipe_config
)
6790 struct drm_device
*dev
= crtc
->base
.dev
;
6791 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6792 int pipe
= pipe_config
->cpu_transcoder
;
6793 intel_clock_t clock
;
6795 int refclk
= 100000;
6797 /* In case of MIPI DPLL will not even be used */
6798 if (!(pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
))
6801 mutex_lock(&dev_priv
->dpio_lock
);
6802 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
6803 mutex_unlock(&dev_priv
->dpio_lock
);
6805 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
6806 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
6807 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
6808 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
6809 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
6811 vlv_clock(refclk
, &clock
);
6813 /* clock.dot is the fast clock */
6814 pipe_config
->port_clock
= clock
.dot
/ 5;
6818 i9xx_get_initial_plane_config(struct intel_crtc
*crtc
,
6819 struct intel_initial_plane_config
*plane_config
)
6821 struct drm_device
*dev
= crtc
->base
.dev
;
6822 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6823 u32 val
, base
, offset
;
6824 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
6825 int fourcc
, pixel_format
;
6826 unsigned int aligned_height
;
6827 struct drm_framebuffer
*fb
;
6828 struct intel_framebuffer
*intel_fb
;
6830 val
= I915_READ(DSPCNTR(plane
));
6831 if (!(val
& DISPLAY_PLANE_ENABLE
))
6834 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
6836 DRM_DEBUG_KMS("failed to alloc fb\n");
6840 fb
= &intel_fb
->base
;
6842 if (INTEL_INFO(dev
)->gen
>= 4) {
6843 if (val
& DISPPLANE_TILED
) {
6844 plane_config
->tiling
= I915_TILING_X
;
6845 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
6849 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
6850 fourcc
= i9xx_format_to_fourcc(pixel_format
);
6851 fb
->pixel_format
= fourcc
;
6852 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
6854 if (INTEL_INFO(dev
)->gen
>= 4) {
6855 if (plane_config
->tiling
)
6856 offset
= I915_READ(DSPTILEOFF(plane
));
6858 offset
= I915_READ(DSPLINOFF(plane
));
6859 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
6861 base
= I915_READ(DSPADDR(plane
));
6863 plane_config
->base
= base
;
6865 val
= I915_READ(PIPESRC(pipe
));
6866 fb
->width
= ((val
>> 16) & 0xfff) + 1;
6867 fb
->height
= ((val
>> 0) & 0xfff) + 1;
6869 val
= I915_READ(DSPSTRIDE(pipe
));
6870 fb
->pitches
[0] = val
& 0xffffffc0;
6872 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
6876 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
6878 DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
6879 pipe_name(pipe
), plane
, fb
->width
, fb
->height
,
6880 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
6881 plane_config
->size
);
6883 plane_config
->fb
= intel_fb
;
6886 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
6887 struct intel_crtc_state
*pipe_config
)
6889 struct drm_device
*dev
= crtc
->base
.dev
;
6890 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6891 int pipe
= pipe_config
->cpu_transcoder
;
6892 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
6893 intel_clock_t clock
;
6894 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
;
6895 int refclk
= 100000;
6897 mutex_lock(&dev_priv
->dpio_lock
);
6898 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
6899 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
6900 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
6901 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
6902 mutex_unlock(&dev_priv
->dpio_lock
);
6904 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
6905 clock
.m2
= ((pll_dw0
& 0xff) << 22) | (pll_dw2
& 0x3fffff);
6906 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
6907 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
6908 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
6910 chv_clock(refclk
, &clock
);
6912 /* clock.dot is the fast clock */
6913 pipe_config
->port_clock
= clock
.dot
/ 5;
6916 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
6917 struct intel_crtc_state
*pipe_config
)
6919 struct drm_device
*dev
= crtc
->base
.dev
;
6920 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6923 if (!intel_display_power_is_enabled(dev_priv
,
6924 POWER_DOMAIN_PIPE(crtc
->pipe
)))
6927 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
6928 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
6930 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
6931 if (!(tmp
& PIPECONF_ENABLE
))
6934 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
6935 switch (tmp
& PIPECONF_BPC_MASK
) {
6937 pipe_config
->pipe_bpp
= 18;
6940 pipe_config
->pipe_bpp
= 24;
6942 case PIPECONF_10BPC
:
6943 pipe_config
->pipe_bpp
= 30;
6950 if (IS_VALLEYVIEW(dev
) && (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
6951 pipe_config
->limited_color_range
= true;
6953 if (INTEL_INFO(dev
)->gen
< 4)
6954 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
6956 intel_get_pipe_timings(crtc
, pipe_config
);
6958 i9xx_get_pfit_config(crtc
, pipe_config
);
6960 if (INTEL_INFO(dev
)->gen
>= 4) {
6961 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
6962 pipe_config
->pixel_multiplier
=
6963 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
6964 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
6965 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
6966 } else if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
6967 tmp
= I915_READ(DPLL(crtc
->pipe
));
6968 pipe_config
->pixel_multiplier
=
6969 ((tmp
& SDVO_MULTIPLIER_MASK
)
6970 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
6972 /* Note that on i915G/GM the pixel multiplier is in the sdvo
6973 * port and will be fixed up in the encoder->get_config
6975 pipe_config
->pixel_multiplier
= 1;
6977 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
6978 if (!IS_VALLEYVIEW(dev
)) {
6980 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
6981 * on 830. Filter it out here so that we don't
6982 * report errors due to that.
6985 pipe_config
->dpll_hw_state
.dpll
&= ~DPLL_DVO_2X_MODE
;
6987 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
6988 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
6990 /* Mask out read-only status bits. */
6991 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
6992 DPLL_PORTC_READY_MASK
|
6993 DPLL_PORTB_READY_MASK
);
6996 if (IS_CHERRYVIEW(dev
))
6997 chv_crtc_clock_get(crtc
, pipe_config
);
6998 else if (IS_VALLEYVIEW(dev
))
6999 vlv_crtc_clock_get(crtc
, pipe_config
);
7001 i9xx_crtc_clock_get(crtc
, pipe_config
);
7006 static void ironlake_init_pch_refclk(struct drm_device
*dev
)
7008 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7009 struct intel_encoder
*encoder
;
7011 bool has_lvds
= false;
7012 bool has_cpu_edp
= false;
7013 bool has_panel
= false;
7014 bool has_ck505
= false;
7015 bool can_ssc
= false;
7017 /* We need to take the global config into account */
7018 for_each_intel_encoder(dev
, encoder
) {
7019 switch (encoder
->type
) {
7020 case INTEL_OUTPUT_LVDS
:
7024 case INTEL_OUTPUT_EDP
:
7026 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
7034 if (HAS_PCH_IBX(dev
)) {
7035 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
7036 can_ssc
= has_ck505
;
7042 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
7043 has_panel
, has_lvds
, has_ck505
);
7045 /* Ironlake: try to setup display ref clock before DPLL
7046 * enabling. This is only under driver's control after
7047 * PCH B stepping, previous chipset stepping should be
7048 * ignoring this setting.
7050 val
= I915_READ(PCH_DREF_CONTROL
);
7052 /* As we must carefully and slowly disable/enable each source in turn,
7053 * compute the final state we want first and check if we need to
7054 * make any changes at all.
7057 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
7059 final
|= DREF_NONSPREAD_CK505_ENABLE
;
7061 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
7063 final
&= ~DREF_SSC_SOURCE_MASK
;
7064 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7065 final
&= ~DREF_SSC1_ENABLE
;
7068 final
|= DREF_SSC_SOURCE_ENABLE
;
7070 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
7071 final
|= DREF_SSC1_ENABLE
;
7074 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
7075 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
7077 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
7079 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7081 final
|= DREF_SSC_SOURCE_DISABLE
;
7082 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7088 /* Always enable nonspread source */
7089 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
7092 val
|= DREF_NONSPREAD_CK505_ENABLE
;
7094 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
7097 val
&= ~DREF_SSC_SOURCE_MASK
;
7098 val
|= DREF_SSC_SOURCE_ENABLE
;
7100 /* SSC must be turned on before enabling the CPU output */
7101 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
7102 DRM_DEBUG_KMS("Using SSC on panel\n");
7103 val
|= DREF_SSC1_ENABLE
;
7105 val
&= ~DREF_SSC1_ENABLE
;
7107 /* Get SSC going before enabling the outputs */
7108 I915_WRITE(PCH_DREF_CONTROL
, val
);
7109 POSTING_READ(PCH_DREF_CONTROL
);
7112 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7114 /* Enable CPU source on CPU attached eDP */
7116 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
7117 DRM_DEBUG_KMS("Using SSC on eDP\n");
7118 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
7120 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
7122 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7124 I915_WRITE(PCH_DREF_CONTROL
, val
);
7125 POSTING_READ(PCH_DREF_CONTROL
);
7128 DRM_DEBUG_KMS("Disabling SSC entirely\n");
7130 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7132 /* Turn off CPU output */
7133 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7135 I915_WRITE(PCH_DREF_CONTROL
, val
);
7136 POSTING_READ(PCH_DREF_CONTROL
);
7139 /* Turn off the SSC source */
7140 val
&= ~DREF_SSC_SOURCE_MASK
;
7141 val
|= DREF_SSC_SOURCE_DISABLE
;
7144 val
&= ~DREF_SSC1_ENABLE
;
7146 I915_WRITE(PCH_DREF_CONTROL
, val
);
7147 POSTING_READ(PCH_DREF_CONTROL
);
7151 BUG_ON(val
!= final
);
7154 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
7158 tmp
= I915_READ(SOUTH_CHICKEN2
);
7159 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
7160 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
7162 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2
) &
7163 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
7164 DRM_ERROR("FDI mPHY reset assert timeout\n");
7166 tmp
= I915_READ(SOUTH_CHICKEN2
);
7167 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
7168 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
7170 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2
) &
7171 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
7172 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
7175 /* WaMPhyProgramming:hsw */
7176 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
7180 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
7181 tmp
&= ~(0xFF << 24);
7182 tmp
|= (0x12 << 24);
7183 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
7185 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
7187 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
7189 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
7191 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
7193 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
7194 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
7195 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
7197 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
7198 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
7199 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
7201 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
7204 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
7206 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
7209 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
7211 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
7214 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
7216 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
7219 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
7221 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
7222 tmp
&= ~(0xFF << 16);
7223 tmp
|= (0x1C << 16);
7224 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
7226 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
7227 tmp
&= ~(0xFF << 16);
7228 tmp
|= (0x1C << 16);
7229 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
7231 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
7233 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
7235 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
7237 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
7239 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
7240 tmp
&= ~(0xF << 28);
7242 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
7244 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
7245 tmp
&= ~(0xF << 28);
7247 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
7250 /* Implements 3 different sequences from BSpec chapter "Display iCLK
7251 * Programming" based on the parameters passed:
7252 * - Sequence to enable CLKOUT_DP
7253 * - Sequence to enable CLKOUT_DP without spread
7254 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
7256 static void lpt_enable_clkout_dp(struct drm_device
*dev
, bool with_spread
,
7259 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7262 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
7264 if (WARN(dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
&&
7265 with_fdi
, "LP PCH doesn't have FDI\n"))
7268 mutex_lock(&dev_priv
->dpio_lock
);
7270 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7271 tmp
&= ~SBI_SSCCTL_DISABLE
;
7272 tmp
|= SBI_SSCCTL_PATHALT
;
7273 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7278 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7279 tmp
&= ~SBI_SSCCTL_PATHALT
;
7280 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7283 lpt_reset_fdi_mphy(dev_priv
);
7284 lpt_program_fdi_mphy(dev_priv
);
7288 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
7289 SBI_GEN0
: SBI_DBUFF0
;
7290 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
7291 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
7292 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
7294 mutex_unlock(&dev_priv
->dpio_lock
);
7297 /* Sequence to disable CLKOUT_DP */
7298 static void lpt_disable_clkout_dp(struct drm_device
*dev
)
7300 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7303 mutex_lock(&dev_priv
->dpio_lock
);
7305 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
7306 SBI_GEN0
: SBI_DBUFF0
;
7307 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
7308 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
7309 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
7311 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
7312 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
7313 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
7314 tmp
|= SBI_SSCCTL_PATHALT
;
7315 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7318 tmp
|= SBI_SSCCTL_DISABLE
;
7319 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
7322 mutex_unlock(&dev_priv
->dpio_lock
);
7325 static void lpt_init_pch_refclk(struct drm_device
*dev
)
7327 struct intel_encoder
*encoder
;
7328 bool has_vga
= false;
7330 for_each_intel_encoder(dev
, encoder
) {
7331 switch (encoder
->type
) {
7332 case INTEL_OUTPUT_ANALOG
:
7341 lpt_enable_clkout_dp(dev
, true, true);
7343 lpt_disable_clkout_dp(dev
);
7347 * Initialize reference clocks when the driver loads
7349 void intel_init_pch_refclk(struct drm_device
*dev
)
7351 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
7352 ironlake_init_pch_refclk(dev
);
7353 else if (HAS_PCH_LPT(dev
))
7354 lpt_init_pch_refclk(dev
);
7357 static int ironlake_get_refclk(struct drm_crtc
*crtc
)
7359 struct drm_device
*dev
= crtc
->dev
;
7360 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7361 struct intel_encoder
*encoder
;
7362 int num_connectors
= 0;
7363 bool is_lvds
= false;
7365 for_each_intel_encoder(dev
, encoder
) {
7366 if (encoder
->new_crtc
!= to_intel_crtc(crtc
))
7369 switch (encoder
->type
) {
7370 case INTEL_OUTPUT_LVDS
:
7379 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
7380 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
7381 dev_priv
->vbt
.lvds_ssc_freq
);
7382 return dev_priv
->vbt
.lvds_ssc_freq
;
7388 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
7390 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
7391 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7392 int pipe
= intel_crtc
->pipe
;
7397 switch (intel_crtc
->config
->pipe_bpp
) {
7399 val
|= PIPECONF_6BPC
;
7402 val
|= PIPECONF_8BPC
;
7405 val
|= PIPECONF_10BPC
;
7408 val
|= PIPECONF_12BPC
;
7411 /* Case prevented by intel_choose_pipe_bpp_dither. */
7415 if (intel_crtc
->config
->dither
)
7416 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
7418 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
7419 val
|= PIPECONF_INTERLACED_ILK
;
7421 val
|= PIPECONF_PROGRESSIVE
;
7423 if (intel_crtc
->config
->limited_color_range
)
7424 val
|= PIPECONF_COLOR_RANGE_SELECT
;
7426 I915_WRITE(PIPECONF(pipe
), val
);
7427 POSTING_READ(PIPECONF(pipe
));
7431 * Set up the pipe CSC unit.
7433 * Currently only full range RGB to limited range RGB conversion
7434 * is supported, but eventually this should handle various
7435 * RGB<->YCbCr scenarios as well.
7437 static void intel_set_pipe_csc(struct drm_crtc
*crtc
)
7439 struct drm_device
*dev
= crtc
->dev
;
7440 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7441 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7442 int pipe
= intel_crtc
->pipe
;
7443 uint16_t coeff
= 0x7800; /* 1.0 */
7446 * TODO: Check what kind of values actually come out of the pipe
7447 * with these coeff/postoff values and adjust to get the best
7448 * accuracy. Perhaps we even need to take the bpc value into
7452 if (intel_crtc
->config
->limited_color_range
)
7453 coeff
= ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
7456 * GY/GU and RY/RU should be the other way around according
7457 * to BSpec, but reality doesn't agree. Just set them up in
7458 * a way that results in the correct picture.
7460 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe
), coeff
<< 16);
7461 I915_WRITE(PIPE_CSC_COEFF_BY(pipe
), 0);
7463 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe
), coeff
);
7464 I915_WRITE(PIPE_CSC_COEFF_BU(pipe
), 0);
7466 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe
), 0);
7467 I915_WRITE(PIPE_CSC_COEFF_BV(pipe
), coeff
<< 16);
7469 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe
), 0);
7470 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe
), 0);
7471 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe
), 0);
7473 if (INTEL_INFO(dev
)->gen
> 6) {
7474 uint16_t postoff
= 0;
7476 if (intel_crtc
->config
->limited_color_range
)
7477 postoff
= (16 * (1 << 12) / 255) & 0x1fff;
7479 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe
), postoff
);
7480 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe
), postoff
);
7481 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe
), postoff
);
7483 I915_WRITE(PIPE_CSC_MODE(pipe
), 0);
7485 uint32_t mode
= CSC_MODE_YUV_TO_RGB
;
7487 if (intel_crtc
->config
->limited_color_range
)
7488 mode
|= CSC_BLACK_SCREEN_OFFSET
;
7490 I915_WRITE(PIPE_CSC_MODE(pipe
), mode
);
7494 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
7496 struct drm_device
*dev
= crtc
->dev
;
7497 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7498 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7499 enum pipe pipe
= intel_crtc
->pipe
;
7500 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
7505 if (IS_HASWELL(dev
) && intel_crtc
->config
->dither
)
7506 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
7508 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
7509 val
|= PIPECONF_INTERLACED_ILK
;
7511 val
|= PIPECONF_PROGRESSIVE
;
7513 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
7514 POSTING_READ(PIPECONF(cpu_transcoder
));
7516 I915_WRITE(GAMMA_MODE(intel_crtc
->pipe
), GAMMA_MODE_MODE_8BIT
);
7517 POSTING_READ(GAMMA_MODE(intel_crtc
->pipe
));
7519 if (IS_BROADWELL(dev
) || INTEL_INFO(dev
)->gen
>= 9) {
7522 switch (intel_crtc
->config
->pipe_bpp
) {
7524 val
|= PIPEMISC_DITHER_6_BPC
;
7527 val
|= PIPEMISC_DITHER_8_BPC
;
7530 val
|= PIPEMISC_DITHER_10_BPC
;
7533 val
|= PIPEMISC_DITHER_12_BPC
;
7536 /* Case prevented by pipe_config_set_bpp. */
7540 if (intel_crtc
->config
->dither
)
7541 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
7543 I915_WRITE(PIPEMISC(pipe
), val
);
7547 static bool ironlake_compute_clocks(struct drm_crtc
*crtc
,
7548 struct intel_crtc_state
*crtc_state
,
7549 intel_clock_t
*clock
,
7550 bool *has_reduced_clock
,
7551 intel_clock_t
*reduced_clock
)
7553 struct drm_device
*dev
= crtc
->dev
;
7554 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7555 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7557 const intel_limit_t
*limit
;
7558 bool ret
, is_lvds
= false;
7560 is_lvds
= intel_pipe_will_have_type(intel_crtc
, INTEL_OUTPUT_LVDS
);
7562 refclk
= ironlake_get_refclk(crtc
);
7565 * Returns a set of divisors for the desired target clock with the given
7566 * refclk, or FALSE. The returned values represent the clock equation:
7567 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
7569 limit
= intel_limit(intel_crtc
, refclk
);
7570 ret
= dev_priv
->display
.find_dpll(limit
, intel_crtc
,
7571 crtc_state
->port_clock
,
7572 refclk
, NULL
, clock
);
7576 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
7578 * Ensure we match the reduced clock's P to the target clock.
7579 * If the clocks don't match, we can't switch the display clock
7580 * by using the FP0/FP1. In such case we will disable the LVDS
7581 * downclock feature.
7583 *has_reduced_clock
=
7584 dev_priv
->display
.find_dpll(limit
, intel_crtc
,
7585 dev_priv
->lvds_downclock
,
7593 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
7596 * Account for spread spectrum to avoid
7597 * oversubscribing the link. Max center spread
7598 * is 2.5%; use 5% for safety's sake.
7600 u32 bps
= target_clock
* bpp
* 21 / 20;
7601 return DIV_ROUND_UP(bps
, link_bw
* 8);
7604 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
7606 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
7609 static uint32_t ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
7610 struct intel_crtc_state
*crtc_state
,
7612 intel_clock_t
*reduced_clock
, u32
*fp2
)
7614 struct drm_crtc
*crtc
= &intel_crtc
->base
;
7615 struct drm_device
*dev
= crtc
->dev
;
7616 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7617 struct intel_encoder
*intel_encoder
;
7619 int factor
, num_connectors
= 0;
7620 bool is_lvds
= false, is_sdvo
= false;
7622 for_each_intel_encoder(dev
, intel_encoder
) {
7623 if (intel_encoder
->new_crtc
!= to_intel_crtc(crtc
))
7626 switch (intel_encoder
->type
) {
7627 case INTEL_OUTPUT_LVDS
:
7630 case INTEL_OUTPUT_SDVO
:
7631 case INTEL_OUTPUT_HDMI
:
7641 /* Enable autotuning of the PLL clock (if permissible) */
7644 if ((intel_panel_use_ssc(dev_priv
) &&
7645 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
7646 (HAS_PCH_IBX(dev
) && intel_is_dual_link_lvds(dev
)))
7648 } else if (crtc_state
->sdvo_tv_clock
)
7651 if (ironlake_needs_fb_cb_tune(&crtc_state
->dpll
, factor
))
7654 if (fp2
&& (reduced_clock
->m
< factor
* reduced_clock
->n
))
7660 dpll
|= DPLLB_MODE_LVDS
;
7662 dpll
|= DPLLB_MODE_DAC_SERIAL
;
7664 dpll
|= (crtc_state
->pixel_multiplier
- 1)
7665 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
7668 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7669 if (crtc_state
->has_dp_encoder
)
7670 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7672 /* compute bitmask from p1 value */
7673 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7675 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
7677 switch (crtc_state
->dpll
.p2
) {
7679 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
7682 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
7685 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
7688 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
7692 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
7693 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7695 dpll
|= PLL_REF_INPUT_DREFCLK
;
7697 return dpll
| DPLL_VCO_ENABLE
;
7700 static int ironlake_crtc_compute_clock(struct intel_crtc
*crtc
,
7701 struct intel_crtc_state
*crtc_state
)
7703 struct drm_device
*dev
= crtc
->base
.dev
;
7704 intel_clock_t clock
, reduced_clock
;
7705 u32 dpll
= 0, fp
= 0, fp2
= 0;
7706 bool ok
, has_reduced_clock
= false;
7707 bool is_lvds
= false;
7708 struct intel_shared_dpll
*pll
;
7710 is_lvds
= intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
);
7712 WARN(!(HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)),
7713 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev
));
7715 ok
= ironlake_compute_clocks(&crtc
->base
, crtc_state
, &clock
,
7716 &has_reduced_clock
, &reduced_clock
);
7717 if (!ok
&& !crtc_state
->clock_set
) {
7718 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7721 /* Compat-code for transition, will disappear. */
7722 if (!crtc_state
->clock_set
) {
7723 crtc_state
->dpll
.n
= clock
.n
;
7724 crtc_state
->dpll
.m1
= clock
.m1
;
7725 crtc_state
->dpll
.m2
= clock
.m2
;
7726 crtc_state
->dpll
.p1
= clock
.p1
;
7727 crtc_state
->dpll
.p2
= clock
.p2
;
7730 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
7731 if (crtc_state
->has_pch_encoder
) {
7732 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
7733 if (has_reduced_clock
)
7734 fp2
= i9xx_dpll_compute_fp(&reduced_clock
);
7736 dpll
= ironlake_compute_dpll(crtc
, crtc_state
,
7737 &fp
, &reduced_clock
,
7738 has_reduced_clock
? &fp2
: NULL
);
7740 crtc_state
->dpll_hw_state
.dpll
= dpll
;
7741 crtc_state
->dpll_hw_state
.fp0
= fp
;
7742 if (has_reduced_clock
)
7743 crtc_state
->dpll_hw_state
.fp1
= fp2
;
7745 crtc_state
->dpll_hw_state
.fp1
= fp
;
7747 pll
= intel_get_shared_dpll(crtc
, crtc_state
);
7749 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
7750 pipe_name(crtc
->pipe
));
7755 if (is_lvds
&& has_reduced_clock
&& i915
.powersave
)
7756 crtc
->lowfreq_avail
= true;
7758 crtc
->lowfreq_avail
= false;
7763 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
7764 struct intel_link_m_n
*m_n
)
7766 struct drm_device
*dev
= crtc
->base
.dev
;
7767 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7768 enum pipe pipe
= crtc
->pipe
;
7770 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
7771 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
7772 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
7774 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
7775 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
7776 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7779 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
7780 enum transcoder transcoder
,
7781 struct intel_link_m_n
*m_n
,
7782 struct intel_link_m_n
*m2_n2
)
7784 struct drm_device
*dev
= crtc
->base
.dev
;
7785 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7786 enum pipe pipe
= crtc
->pipe
;
7788 if (INTEL_INFO(dev
)->gen
>= 5) {
7789 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
7790 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
7791 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
7793 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
7794 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
7795 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7796 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
7797 * gen < 8) and if DRRS is supported (to make sure the
7798 * registers are not unnecessarily read).
7800 if (m2_n2
&& INTEL_INFO(dev
)->gen
< 8 &&
7801 crtc
->config
->has_drrs
) {
7802 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
7803 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
7804 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
7806 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
7807 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
7808 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7811 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
7812 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
7813 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
7815 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
7816 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
7817 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7821 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
7822 struct intel_crtc_state
*pipe_config
)
7824 if (pipe_config
->has_pch_encoder
)
7825 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
7827 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
7828 &pipe_config
->dp_m_n
,
7829 &pipe_config
->dp_m2_n2
);
7832 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
7833 struct intel_crtc_state
*pipe_config
)
7835 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
7836 &pipe_config
->fdi_m_n
, NULL
);
7839 static void skylake_get_pfit_config(struct intel_crtc
*crtc
,
7840 struct intel_crtc_state
*pipe_config
)
7842 struct drm_device
*dev
= crtc
->base
.dev
;
7843 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7846 tmp
= I915_READ(PS_CTL(crtc
->pipe
));
7848 if (tmp
& PS_ENABLE
) {
7849 pipe_config
->pch_pfit
.enabled
= true;
7850 pipe_config
->pch_pfit
.pos
= I915_READ(PS_WIN_POS(crtc
->pipe
));
7851 pipe_config
->pch_pfit
.size
= I915_READ(PS_WIN_SZ(crtc
->pipe
));
7856 skylake_get_initial_plane_config(struct intel_crtc
*crtc
,
7857 struct intel_initial_plane_config
*plane_config
)
7859 struct drm_device
*dev
= crtc
->base
.dev
;
7860 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7861 u32 val
, base
, offset
, stride_mult
, tiling
;
7862 int pipe
= crtc
->pipe
;
7863 int fourcc
, pixel_format
;
7864 unsigned int aligned_height
;
7865 struct drm_framebuffer
*fb
;
7866 struct intel_framebuffer
*intel_fb
;
7868 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
7870 DRM_DEBUG_KMS("failed to alloc fb\n");
7874 fb
= &intel_fb
->base
;
7876 val
= I915_READ(PLANE_CTL(pipe
, 0));
7877 if (!(val
& PLANE_CTL_ENABLE
))
7880 pixel_format
= val
& PLANE_CTL_FORMAT_MASK
;
7881 fourcc
= skl_format_to_fourcc(pixel_format
,
7882 val
& PLANE_CTL_ORDER_RGBX
,
7883 val
& PLANE_CTL_ALPHA_MASK
);
7884 fb
->pixel_format
= fourcc
;
7885 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
7887 tiling
= val
& PLANE_CTL_TILED_MASK
;
7889 case PLANE_CTL_TILED_LINEAR
:
7890 fb
->modifier
[0] = DRM_FORMAT_MOD_NONE
;
7892 case PLANE_CTL_TILED_X
:
7893 plane_config
->tiling
= I915_TILING_X
;
7894 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
7896 case PLANE_CTL_TILED_Y
:
7897 fb
->modifier
[0] = I915_FORMAT_MOD_Y_TILED
;
7899 case PLANE_CTL_TILED_YF
:
7900 fb
->modifier
[0] = I915_FORMAT_MOD_Yf_TILED
;
7903 MISSING_CASE(tiling
);
7907 base
= I915_READ(PLANE_SURF(pipe
, 0)) & 0xfffff000;
7908 plane_config
->base
= base
;
7910 offset
= I915_READ(PLANE_OFFSET(pipe
, 0));
7912 val
= I915_READ(PLANE_SIZE(pipe
, 0));
7913 fb
->height
= ((val
>> 16) & 0xfff) + 1;
7914 fb
->width
= ((val
>> 0) & 0x1fff) + 1;
7916 val
= I915_READ(PLANE_STRIDE(pipe
, 0));
7917 stride_mult
= intel_fb_stride_alignment(dev
, fb
->modifier
[0],
7919 fb
->pitches
[0] = (val
& 0x3ff) * stride_mult
;
7921 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
7925 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
7927 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7928 pipe_name(pipe
), fb
->width
, fb
->height
,
7929 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
7930 plane_config
->size
);
7932 plane_config
->fb
= intel_fb
;
7939 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
7940 struct intel_crtc_state
*pipe_config
)
7942 struct drm_device
*dev
= crtc
->base
.dev
;
7943 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7946 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
7948 if (tmp
& PF_ENABLE
) {
7949 pipe_config
->pch_pfit
.enabled
= true;
7950 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
7951 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
7953 /* We currently do not free assignements of panel fitters on
7954 * ivb/hsw (since we don't use the higher upscaling modes which
7955 * differentiates them) so just WARN about this case for now. */
7957 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
7958 PF_PIPE_SEL_IVB(crtc
->pipe
));
7964 ironlake_get_initial_plane_config(struct intel_crtc
*crtc
,
7965 struct intel_initial_plane_config
*plane_config
)
7967 struct drm_device
*dev
= crtc
->base
.dev
;
7968 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7969 u32 val
, base
, offset
;
7970 int pipe
= crtc
->pipe
;
7971 int fourcc
, pixel_format
;
7972 unsigned int aligned_height
;
7973 struct drm_framebuffer
*fb
;
7974 struct intel_framebuffer
*intel_fb
;
7976 val
= I915_READ(DSPCNTR(pipe
));
7977 if (!(val
& DISPLAY_PLANE_ENABLE
))
7980 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
7982 DRM_DEBUG_KMS("failed to alloc fb\n");
7986 fb
= &intel_fb
->base
;
7988 if (INTEL_INFO(dev
)->gen
>= 4) {
7989 if (val
& DISPPLANE_TILED
) {
7990 plane_config
->tiling
= I915_TILING_X
;
7991 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
7995 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
7996 fourcc
= i9xx_format_to_fourcc(pixel_format
);
7997 fb
->pixel_format
= fourcc
;
7998 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
8000 base
= I915_READ(DSPSURF(pipe
)) & 0xfffff000;
8001 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
8002 offset
= I915_READ(DSPOFFSET(pipe
));
8004 if (plane_config
->tiling
)
8005 offset
= I915_READ(DSPTILEOFF(pipe
));
8007 offset
= I915_READ(DSPLINOFF(pipe
));
8009 plane_config
->base
= base
;
8011 val
= I915_READ(PIPESRC(pipe
));
8012 fb
->width
= ((val
>> 16) & 0xfff) + 1;
8013 fb
->height
= ((val
>> 0) & 0xfff) + 1;
8015 val
= I915_READ(DSPSTRIDE(pipe
));
8016 fb
->pitches
[0] = val
& 0xffffffc0;
8018 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
8022 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8024 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8025 pipe_name(pipe
), fb
->width
, fb
->height
,
8026 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
8027 plane_config
->size
);
8029 plane_config
->fb
= intel_fb
;
8032 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
8033 struct intel_crtc_state
*pipe_config
)
8035 struct drm_device
*dev
= crtc
->base
.dev
;
8036 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8039 if (!intel_display_power_is_enabled(dev_priv
,
8040 POWER_DOMAIN_PIPE(crtc
->pipe
)))
8043 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8044 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
8046 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
8047 if (!(tmp
& PIPECONF_ENABLE
))
8050 switch (tmp
& PIPECONF_BPC_MASK
) {
8052 pipe_config
->pipe_bpp
= 18;
8055 pipe_config
->pipe_bpp
= 24;
8057 case PIPECONF_10BPC
:
8058 pipe_config
->pipe_bpp
= 30;
8060 case PIPECONF_12BPC
:
8061 pipe_config
->pipe_bpp
= 36;
8067 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
8068 pipe_config
->limited_color_range
= true;
8070 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
8071 struct intel_shared_dpll
*pll
;
8073 pipe_config
->has_pch_encoder
= true;
8075 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
8076 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
8077 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
8079 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
8081 if (HAS_PCH_IBX(dev_priv
->dev
)) {
8082 pipe_config
->shared_dpll
=
8083 (enum intel_dpll_id
) crtc
->pipe
;
8085 tmp
= I915_READ(PCH_DPLL_SEL
);
8086 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
8087 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_B
;
8089 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_A
;
8092 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
8094 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
8095 &pipe_config
->dpll_hw_state
));
8097 tmp
= pipe_config
->dpll_hw_state
.dpll
;
8098 pipe_config
->pixel_multiplier
=
8099 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
8100 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
8102 ironlake_pch_clock_get(crtc
, pipe_config
);
8104 pipe_config
->pixel_multiplier
= 1;
8107 intel_get_pipe_timings(crtc
, pipe_config
);
8109 ironlake_get_pfit_config(crtc
, pipe_config
);
8114 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
8116 struct drm_device
*dev
= dev_priv
->dev
;
8117 struct intel_crtc
*crtc
;
8119 for_each_intel_crtc(dev
, crtc
)
8120 I915_STATE_WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
8121 pipe_name(crtc
->pipe
));
8123 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
8124 I915_STATE_WARN(I915_READ(SPLL_CTL
) & SPLL_PLL_ENABLE
, "SPLL enabled\n");
8125 I915_STATE_WARN(I915_READ(WRPLL_CTL1
) & WRPLL_PLL_ENABLE
, "WRPLL1 enabled\n");
8126 I915_STATE_WARN(I915_READ(WRPLL_CTL2
) & WRPLL_PLL_ENABLE
, "WRPLL2 enabled\n");
8127 I915_STATE_WARN(I915_READ(PCH_PP_STATUS
) & PP_ON
, "Panel power on\n");
8128 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
8129 "CPU PWM1 enabled\n");
8130 if (IS_HASWELL(dev
))
8131 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
8132 "CPU PWM2 enabled\n");
8133 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
8134 "PCH PWM1 enabled\n");
8135 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
8136 "Utility pin enabled\n");
8137 I915_STATE_WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
8140 * In theory we can still leave IRQs enabled, as long as only the HPD
8141 * interrupts remain enabled. We used to check for that, but since it's
8142 * gen-specific and since we only disable LCPLL after we fully disable
8143 * the interrupts, the check below should be enough.
8145 I915_STATE_WARN(intel_irqs_enabled(dev_priv
), "IRQs enabled\n");
8148 static uint32_t hsw_read_dcomp(struct drm_i915_private
*dev_priv
)
8150 struct drm_device
*dev
= dev_priv
->dev
;
8152 if (IS_HASWELL(dev
))
8153 return I915_READ(D_COMP_HSW
);
8155 return I915_READ(D_COMP_BDW
);
8158 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
8160 struct drm_device
*dev
= dev_priv
->dev
;
8162 if (IS_HASWELL(dev
)) {
8163 mutex_lock(&dev_priv
->rps
.hw_lock
);
8164 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
8166 DRM_ERROR("Failed to write to D_COMP\n");
8167 mutex_unlock(&dev_priv
->rps
.hw_lock
);
8169 I915_WRITE(D_COMP_BDW
, val
);
8170 POSTING_READ(D_COMP_BDW
);
8175 * This function implements pieces of two sequences from BSpec:
8176 * - Sequence for display software to disable LCPLL
8177 * - Sequence for display software to allow package C8+
8178 * The steps implemented here are just the steps that actually touch the LCPLL
8179 * register. Callers should take care of disabling all the display engine
8180 * functions, doing the mode unset, fixing interrupts, etc.
8182 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
8183 bool switch_to_fclk
, bool allow_power_down
)
8187 assert_can_disable_lcpll(dev_priv
);
8189 val
= I915_READ(LCPLL_CTL
);
8191 if (switch_to_fclk
) {
8192 val
|= LCPLL_CD_SOURCE_FCLK
;
8193 I915_WRITE(LCPLL_CTL
, val
);
8195 if (wait_for_atomic_us(I915_READ(LCPLL_CTL
) &
8196 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
8197 DRM_ERROR("Switching to FCLK failed\n");
8199 val
= I915_READ(LCPLL_CTL
);
8202 val
|= LCPLL_PLL_DISABLE
;
8203 I915_WRITE(LCPLL_CTL
, val
);
8204 POSTING_READ(LCPLL_CTL
);
8206 if (wait_for((I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
) == 0, 1))
8207 DRM_ERROR("LCPLL still locked\n");
8209 val
= hsw_read_dcomp(dev_priv
);
8210 val
|= D_COMP_COMP_DISABLE
;
8211 hsw_write_dcomp(dev_priv
, val
);
8214 if (wait_for((hsw_read_dcomp(dev_priv
) & D_COMP_RCOMP_IN_PROGRESS
) == 0,
8216 DRM_ERROR("D_COMP RCOMP still in progress\n");
8218 if (allow_power_down
) {
8219 val
= I915_READ(LCPLL_CTL
);
8220 val
|= LCPLL_POWER_DOWN_ALLOW
;
8221 I915_WRITE(LCPLL_CTL
, val
);
8222 POSTING_READ(LCPLL_CTL
);
8227 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
8230 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
8234 val
= I915_READ(LCPLL_CTL
);
8236 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
8237 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
8241 * Make sure we're not on PC8 state before disabling PC8, otherwise
8242 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
8244 intel_uncore_forcewake_get(dev_priv
, FORCEWAKE_ALL
);
8246 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
8247 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
8248 I915_WRITE(LCPLL_CTL
, val
);
8249 POSTING_READ(LCPLL_CTL
);
8252 val
= hsw_read_dcomp(dev_priv
);
8253 val
|= D_COMP_COMP_FORCE
;
8254 val
&= ~D_COMP_COMP_DISABLE
;
8255 hsw_write_dcomp(dev_priv
, val
);
8257 val
= I915_READ(LCPLL_CTL
);
8258 val
&= ~LCPLL_PLL_DISABLE
;
8259 I915_WRITE(LCPLL_CTL
, val
);
8261 if (wait_for(I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
, 5))
8262 DRM_ERROR("LCPLL not locked yet\n");
8264 if (val
& LCPLL_CD_SOURCE_FCLK
) {
8265 val
= I915_READ(LCPLL_CTL
);
8266 val
&= ~LCPLL_CD_SOURCE_FCLK
;
8267 I915_WRITE(LCPLL_CTL
, val
);
8269 if (wait_for_atomic_us((I915_READ(LCPLL_CTL
) &
8270 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
8271 DRM_ERROR("Switching back to LCPLL failed\n");
8274 intel_uncore_forcewake_put(dev_priv
, FORCEWAKE_ALL
);
8278 * Package states C8 and deeper are really deep PC states that can only be
8279 * reached when all the devices on the system allow it, so even if the graphics
8280 * device allows PC8+, it doesn't mean the system will actually get to these
8281 * states. Our driver only allows PC8+ when going into runtime PM.
8283 * The requirements for PC8+ are that all the outputs are disabled, the power
8284 * well is disabled and most interrupts are disabled, and these are also
8285 * requirements for runtime PM. When these conditions are met, we manually do
8286 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
8287 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
8290 * When we really reach PC8 or deeper states (not just when we allow it) we lose
8291 * the state of some registers, so when we come back from PC8+ we need to
8292 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
8293 * need to take care of the registers kept by RC6. Notice that this happens even
8294 * if we don't put the device in PCI D3 state (which is what currently happens
8295 * because of the runtime PM support).
8297 * For more, read "Display Sequences for Package C8" on the hardware
8300 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
8302 struct drm_device
*dev
= dev_priv
->dev
;
8305 DRM_DEBUG_KMS("Enabling package C8+\n");
8307 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
8308 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
8309 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
8310 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
8313 lpt_disable_clkout_dp(dev
);
8314 hsw_disable_lcpll(dev_priv
, true, true);
8317 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
8319 struct drm_device
*dev
= dev_priv
->dev
;
8322 DRM_DEBUG_KMS("Disabling package C8+\n");
8324 hsw_restore_lcpll(dev_priv
);
8325 lpt_init_pch_refclk(dev
);
8327 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
8328 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
8329 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
8330 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
8333 intel_prepare_ddi(dev
);
8336 static int haswell_crtc_compute_clock(struct intel_crtc
*crtc
,
8337 struct intel_crtc_state
*crtc_state
)
8339 if (!intel_ddi_pll_select(crtc
, crtc_state
))
8342 crtc
->lowfreq_avail
= false;
8347 static void skylake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8349 struct intel_crtc_state
*pipe_config
)
8351 u32 temp
, dpll_ctl1
;
8353 temp
= I915_READ(DPLL_CTRL2
) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port
);
8354 pipe_config
->ddi_pll_sel
= temp
>> (port
* 3 + 1);
8356 switch (pipe_config
->ddi_pll_sel
) {
8359 * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part
8360 * of the shared DPLL framework and thus needs to be read out
8363 dpll_ctl1
= I915_READ(DPLL_CTRL1
);
8364 pipe_config
->dpll_hw_state
.ctrl1
= dpll_ctl1
& 0x3f;
8367 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL1
;
8370 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL2
;
8373 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL3
;
8378 static void haswell_get_ddi_pll(struct drm_i915_private
*dev_priv
,
8380 struct intel_crtc_state
*pipe_config
)
8382 pipe_config
->ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
8384 switch (pipe_config
->ddi_pll_sel
) {
8385 case PORT_CLK_SEL_WRPLL1
:
8386 pipe_config
->shared_dpll
= DPLL_ID_WRPLL1
;
8388 case PORT_CLK_SEL_WRPLL2
:
8389 pipe_config
->shared_dpll
= DPLL_ID_WRPLL2
;
8394 static void haswell_get_ddi_port_state(struct intel_crtc
*crtc
,
8395 struct intel_crtc_state
*pipe_config
)
8397 struct drm_device
*dev
= crtc
->base
.dev
;
8398 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8399 struct intel_shared_dpll
*pll
;
8403 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
8405 port
= (tmp
& TRANS_DDI_PORT_MASK
) >> TRANS_DDI_PORT_SHIFT
;
8407 if (IS_SKYLAKE(dev
))
8408 skylake_get_ddi_pll(dev_priv
, port
, pipe_config
);
8410 haswell_get_ddi_pll(dev_priv
, port
, pipe_config
);
8412 if (pipe_config
->shared_dpll
>= 0) {
8413 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
8415 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
8416 &pipe_config
->dpll_hw_state
));
8420 * Haswell has only FDI/PCH transcoder A. It is which is connected to
8421 * DDI E. So just check whether this pipe is wired to DDI E and whether
8422 * the PCH transcoder is on.
8424 if (INTEL_INFO(dev
)->gen
< 9 &&
8425 (port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
8426 pipe_config
->has_pch_encoder
= true;
8428 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
8429 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
8430 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
8432 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
8436 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
8437 struct intel_crtc_state
*pipe_config
)
8439 struct drm_device
*dev
= crtc
->base
.dev
;
8440 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8441 enum intel_display_power_domain pfit_domain
;
8444 if (!intel_display_power_is_enabled(dev_priv
,
8445 POWER_DOMAIN_PIPE(crtc
->pipe
)))
8448 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8449 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
8451 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
8452 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
8453 enum pipe trans_edp_pipe
;
8454 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
8456 WARN(1, "unknown pipe linked to edp transcoder\n");
8457 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
8458 case TRANS_DDI_EDP_INPUT_A_ON
:
8459 trans_edp_pipe
= PIPE_A
;
8461 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
8462 trans_edp_pipe
= PIPE_B
;
8464 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
8465 trans_edp_pipe
= PIPE_C
;
8469 if (trans_edp_pipe
== crtc
->pipe
)
8470 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
8473 if (!intel_display_power_is_enabled(dev_priv
,
8474 POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
)))
8477 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
8478 if (!(tmp
& PIPECONF_ENABLE
))
8481 haswell_get_ddi_port_state(crtc
, pipe_config
);
8483 intel_get_pipe_timings(crtc
, pipe_config
);
8485 pfit_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
8486 if (intel_display_power_is_enabled(dev_priv
, pfit_domain
)) {
8487 if (IS_SKYLAKE(dev
))
8488 skylake_get_pfit_config(crtc
, pipe_config
);
8490 ironlake_get_pfit_config(crtc
, pipe_config
);
8493 if (IS_HASWELL(dev
))
8494 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
8495 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
8497 if (pipe_config
->cpu_transcoder
!= TRANSCODER_EDP
) {
8498 pipe_config
->pixel_multiplier
=
8499 I915_READ(PIPE_MULT(pipe_config
->cpu_transcoder
)) + 1;
8501 pipe_config
->pixel_multiplier
= 1;
8507 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
)
8509 struct drm_device
*dev
= crtc
->dev
;
8510 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8511 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8512 uint32_t cntl
= 0, size
= 0;
8515 unsigned int width
= intel_crtc
->base
.cursor
->state
->crtc_w
;
8516 unsigned int height
= intel_crtc
->base
.cursor
->state
->crtc_h
;
8517 unsigned int stride
= roundup_pow_of_two(width
) * 4;
8521 WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
8532 cntl
|= CURSOR_ENABLE
|
8533 CURSOR_GAMMA_ENABLE
|
8534 CURSOR_FORMAT_ARGB
|
8535 CURSOR_STRIDE(stride
);
8537 size
= (height
<< 12) | width
;
8540 if (intel_crtc
->cursor_cntl
!= 0 &&
8541 (intel_crtc
->cursor_base
!= base
||
8542 intel_crtc
->cursor_size
!= size
||
8543 intel_crtc
->cursor_cntl
!= cntl
)) {
8544 /* On these chipsets we can only modify the base/size/stride
8545 * whilst the cursor is disabled.
8547 I915_WRITE(_CURACNTR
, 0);
8548 POSTING_READ(_CURACNTR
);
8549 intel_crtc
->cursor_cntl
= 0;
8552 if (intel_crtc
->cursor_base
!= base
) {
8553 I915_WRITE(_CURABASE
, base
);
8554 intel_crtc
->cursor_base
= base
;
8557 if (intel_crtc
->cursor_size
!= size
) {
8558 I915_WRITE(CURSIZE
, size
);
8559 intel_crtc
->cursor_size
= size
;
8562 if (intel_crtc
->cursor_cntl
!= cntl
) {
8563 I915_WRITE(_CURACNTR
, cntl
);
8564 POSTING_READ(_CURACNTR
);
8565 intel_crtc
->cursor_cntl
= cntl
;
8569 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
)
8571 struct drm_device
*dev
= crtc
->dev
;
8572 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8573 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8574 int pipe
= intel_crtc
->pipe
;
8579 cntl
= MCURSOR_GAMMA_ENABLE
;
8580 switch (intel_crtc
->base
.cursor
->state
->crtc_w
) {
8582 cntl
|= CURSOR_MODE_64_ARGB_AX
;
8585 cntl
|= CURSOR_MODE_128_ARGB_AX
;
8588 cntl
|= CURSOR_MODE_256_ARGB_AX
;
8591 MISSING_CASE(intel_crtc
->base
.cursor
->state
->crtc_w
);
8594 cntl
|= pipe
<< 28; /* Connect to correct pipe */
8596 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
8597 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
8600 if (crtc
->cursor
->state
->rotation
== BIT(DRM_ROTATE_180
))
8601 cntl
|= CURSOR_ROTATE_180
;
8603 if (intel_crtc
->cursor_cntl
!= cntl
) {
8604 I915_WRITE(CURCNTR(pipe
), cntl
);
8605 POSTING_READ(CURCNTR(pipe
));
8606 intel_crtc
->cursor_cntl
= cntl
;
8609 /* and commit changes on next vblank */
8610 I915_WRITE(CURBASE(pipe
), base
);
8611 POSTING_READ(CURBASE(pipe
));
8613 intel_crtc
->cursor_base
= base
;
8616 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
8617 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
8620 struct drm_device
*dev
= crtc
->dev
;
8621 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8622 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8623 int pipe
= intel_crtc
->pipe
;
8624 int x
= crtc
->cursor_x
;
8625 int y
= crtc
->cursor_y
;
8626 u32 base
= 0, pos
= 0;
8629 base
= intel_crtc
->cursor_addr
;
8631 if (x
>= intel_crtc
->config
->pipe_src_w
)
8634 if (y
>= intel_crtc
->config
->pipe_src_h
)
8638 if (x
+ intel_crtc
->base
.cursor
->state
->crtc_w
<= 0)
8641 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
8644 pos
|= x
<< CURSOR_X_SHIFT
;
8647 if (y
+ intel_crtc
->base
.cursor
->state
->crtc_h
<= 0)
8650 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
8653 pos
|= y
<< CURSOR_Y_SHIFT
;
8655 if (base
== 0 && intel_crtc
->cursor_base
== 0)
8658 I915_WRITE(CURPOS(pipe
), pos
);
8660 /* ILK+ do this automagically */
8661 if (HAS_GMCH_DISPLAY(dev
) &&
8662 crtc
->cursor
->state
->rotation
== BIT(DRM_ROTATE_180
)) {
8663 base
+= (intel_crtc
->base
.cursor
->state
->crtc_h
*
8664 intel_crtc
->base
.cursor
->state
->crtc_w
- 1) * 4;
8667 if (IS_845G(dev
) || IS_I865G(dev
))
8668 i845_update_cursor(crtc
, base
);
8670 i9xx_update_cursor(crtc
, base
);
8673 static bool cursor_size_ok(struct drm_device
*dev
,
8674 uint32_t width
, uint32_t height
)
8676 if (width
== 0 || height
== 0)
8680 * 845g/865g are special in that they are only limited by
8681 * the width of their cursors, the height is arbitrary up to
8682 * the precision of the register. Everything else requires
8683 * square cursors, limited to a few power-of-two sizes.
8685 if (IS_845G(dev
) || IS_I865G(dev
)) {
8686 if ((width
& 63) != 0)
8689 if (width
> (IS_845G(dev
) ? 64 : 512))
8695 switch (width
| height
) {
8710 static void intel_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
8711 u16
*blue
, uint32_t start
, uint32_t size
)
8713 int end
= (start
+ size
> 256) ? 256 : start
+ size
, i
;
8714 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8716 for (i
= start
; i
< end
; i
++) {
8717 intel_crtc
->lut_r
[i
] = red
[i
] >> 8;
8718 intel_crtc
->lut_g
[i
] = green
[i
] >> 8;
8719 intel_crtc
->lut_b
[i
] = blue
[i
] >> 8;
8722 intel_crtc_load_lut(crtc
);
8725 /* VESA 640x480x72Hz mode to set on the pipe */
8726 static struct drm_display_mode load_detect_mode
= {
8727 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
8728 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
8731 struct drm_framebuffer
*
8732 __intel_framebuffer_create(struct drm_device
*dev
,
8733 struct drm_mode_fb_cmd2
*mode_cmd
,
8734 struct drm_i915_gem_object
*obj
)
8736 struct intel_framebuffer
*intel_fb
;
8739 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8741 drm_gem_object_unreference(&obj
->base
);
8742 return ERR_PTR(-ENOMEM
);
8745 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
8749 return &intel_fb
->base
;
8751 drm_gem_object_unreference(&obj
->base
);
8754 return ERR_PTR(ret
);
8757 static struct drm_framebuffer
*
8758 intel_framebuffer_create(struct drm_device
*dev
,
8759 struct drm_mode_fb_cmd2
*mode_cmd
,
8760 struct drm_i915_gem_object
*obj
)
8762 struct drm_framebuffer
*fb
;
8765 ret
= i915_mutex_lock_interruptible(dev
);
8767 return ERR_PTR(ret
);
8768 fb
= __intel_framebuffer_create(dev
, mode_cmd
, obj
);
8769 mutex_unlock(&dev
->struct_mutex
);
8775 intel_framebuffer_pitch_for_width(int width
, int bpp
)
8777 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
8778 return ALIGN(pitch
, 64);
8782 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
8784 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
8785 return PAGE_ALIGN(pitch
* mode
->vdisplay
);
8788 static struct drm_framebuffer
*
8789 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
8790 struct drm_display_mode
*mode
,
8793 struct drm_i915_gem_object
*obj
;
8794 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
8796 obj
= i915_gem_alloc_object(dev
,
8797 intel_framebuffer_size_for_mode(mode
, bpp
));
8799 return ERR_PTR(-ENOMEM
);
8801 mode_cmd
.width
= mode
->hdisplay
;
8802 mode_cmd
.height
= mode
->vdisplay
;
8803 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
8805 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
8807 return intel_framebuffer_create(dev
, &mode_cmd
, obj
);
8810 static struct drm_framebuffer
*
8811 mode_fits_in_fbdev(struct drm_device
*dev
,
8812 struct drm_display_mode
*mode
)
8814 #ifdef CONFIG_DRM_I915_FBDEV
8815 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8816 struct drm_i915_gem_object
*obj
;
8817 struct drm_framebuffer
*fb
;
8819 if (!dev_priv
->fbdev
)
8822 if (!dev_priv
->fbdev
->fb
)
8825 obj
= dev_priv
->fbdev
->fb
->obj
;
8828 fb
= &dev_priv
->fbdev
->fb
->base
;
8829 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
8830 fb
->bits_per_pixel
))
8833 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
8842 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
8843 struct drm_display_mode
*mode
,
8844 struct intel_load_detect_pipe
*old
,
8845 struct drm_modeset_acquire_ctx
*ctx
)
8847 struct intel_crtc
*intel_crtc
;
8848 struct intel_encoder
*intel_encoder
=
8849 intel_attached_encoder(connector
);
8850 struct drm_crtc
*possible_crtc
;
8851 struct drm_encoder
*encoder
= &intel_encoder
->base
;
8852 struct drm_crtc
*crtc
= NULL
;
8853 struct drm_device
*dev
= encoder
->dev
;
8854 struct drm_framebuffer
*fb
;
8855 struct drm_mode_config
*config
= &dev
->mode_config
;
8858 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
8859 connector
->base
.id
, connector
->name
,
8860 encoder
->base
.id
, encoder
->name
);
8863 ret
= drm_modeset_lock(&config
->connection_mutex
, ctx
);
8868 * Algorithm gets a little messy:
8870 * - if the connector already has an assigned crtc, use it (but make
8871 * sure it's on first)
8873 * - try to find the first unused crtc that can drive this connector,
8874 * and use that if we find one
8877 /* See if we already have a CRTC for this connector */
8878 if (encoder
->crtc
) {
8879 crtc
= encoder
->crtc
;
8881 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
8884 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
8888 old
->dpms_mode
= connector
->dpms
;
8889 old
->load_detect_temp
= false;
8891 /* Make sure the crtc and connector are running */
8892 if (connector
->dpms
!= DRM_MODE_DPMS_ON
)
8893 connector
->funcs
->dpms(connector
, DRM_MODE_DPMS_ON
);
8898 /* Find an unused one (if possible) */
8899 for_each_crtc(dev
, possible_crtc
) {
8901 if (!(encoder
->possible_crtcs
& (1 << i
)))
8903 if (possible_crtc
->state
->enable
)
8905 /* This can occur when applying the pipe A quirk on resume. */
8906 if (to_intel_crtc(possible_crtc
)->new_enabled
)
8909 crtc
= possible_crtc
;
8914 * If we didn't find an unused CRTC, don't use any.
8917 DRM_DEBUG_KMS("no pipe available for load-detect\n");
8921 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
8924 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
8927 intel_encoder
->new_crtc
= to_intel_crtc(crtc
);
8928 to_intel_connector(connector
)->new_encoder
= intel_encoder
;
8930 intel_crtc
= to_intel_crtc(crtc
);
8931 intel_crtc
->new_enabled
= true;
8932 intel_crtc
->new_config
= intel_crtc
->config
;
8933 old
->dpms_mode
= connector
->dpms
;
8934 old
->load_detect_temp
= true;
8935 old
->release_fb
= NULL
;
8938 mode
= &load_detect_mode
;
8940 /* We need a framebuffer large enough to accommodate all accesses
8941 * that the plane may generate whilst we perform load detection.
8942 * We can not rely on the fbcon either being present (we get called
8943 * during its initialisation to detect all boot displays, or it may
8944 * not even exist) or that it is large enough to satisfy the
8947 fb
= mode_fits_in_fbdev(dev
, mode
);
8949 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
8950 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
8951 old
->release_fb
= fb
;
8953 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
8955 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
8959 if (intel_set_mode(crtc
, mode
, 0, 0, fb
)) {
8960 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
8961 if (old
->release_fb
)
8962 old
->release_fb
->funcs
->destroy(old
->release_fb
);
8965 crtc
->primary
->crtc
= crtc
;
8967 /* let the connector get through one full cycle before testing */
8968 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
8972 intel_crtc
->new_enabled
= crtc
->state
->enable
;
8973 if (intel_crtc
->new_enabled
)
8974 intel_crtc
->new_config
= intel_crtc
->config
;
8976 intel_crtc
->new_config
= NULL
;
8978 if (ret
== -EDEADLK
) {
8979 drm_modeset_backoff(ctx
);
8986 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
8987 struct intel_load_detect_pipe
*old
)
8989 struct intel_encoder
*intel_encoder
=
8990 intel_attached_encoder(connector
);
8991 struct drm_encoder
*encoder
= &intel_encoder
->base
;
8992 struct drm_crtc
*crtc
= encoder
->crtc
;
8993 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8995 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
8996 connector
->base
.id
, connector
->name
,
8997 encoder
->base
.id
, encoder
->name
);
8999 if (old
->load_detect_temp
) {
9000 to_intel_connector(connector
)->new_encoder
= NULL
;
9001 intel_encoder
->new_crtc
= NULL
;
9002 intel_crtc
->new_enabled
= false;
9003 intel_crtc
->new_config
= NULL
;
9004 intel_set_mode(crtc
, NULL
, 0, 0, NULL
);
9006 if (old
->release_fb
) {
9007 drm_framebuffer_unregister_private(old
->release_fb
);
9008 drm_framebuffer_unreference(old
->release_fb
);
9014 /* Switch crtc and encoder back off if necessary */
9015 if (old
->dpms_mode
!= DRM_MODE_DPMS_ON
)
9016 connector
->funcs
->dpms(connector
, old
->dpms_mode
);
9019 static int i9xx_pll_refclk(struct drm_device
*dev
,
9020 const struct intel_crtc_state
*pipe_config
)
9022 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9023 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
9025 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
9026 return dev_priv
->vbt
.lvds_ssc_freq
;
9027 else if (HAS_PCH_SPLIT(dev
))
9029 else if (!IS_GEN2(dev
))
9035 /* Returns the clock of the currently programmed mode of the given pipe. */
9036 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
9037 struct intel_crtc_state
*pipe_config
)
9039 struct drm_device
*dev
= crtc
->base
.dev
;
9040 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9041 int pipe
= pipe_config
->cpu_transcoder
;
9042 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
9044 intel_clock_t clock
;
9045 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
9047 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
9048 fp
= pipe_config
->dpll_hw_state
.fp0
;
9050 fp
= pipe_config
->dpll_hw_state
.fp1
;
9052 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
9053 if (IS_PINEVIEW(dev
)) {
9054 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
9055 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
9057 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
9058 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
9061 if (!IS_GEN2(dev
)) {
9062 if (IS_PINEVIEW(dev
))
9063 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
9064 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
9066 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
9067 DPLL_FPA01_P1_POST_DIV_SHIFT
);
9069 switch (dpll
& DPLL_MODE_MASK
) {
9070 case DPLLB_MODE_DAC_SERIAL
:
9071 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
9074 case DPLLB_MODE_LVDS
:
9075 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
9079 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
9080 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
9084 if (IS_PINEVIEW(dev
))
9085 pineview_clock(refclk
, &clock
);
9087 i9xx_clock(refclk
, &clock
);
9089 u32 lvds
= IS_I830(dev
) ? 0 : I915_READ(LVDS
);
9090 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
9093 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
9094 DPLL_FPA01_P1_POST_DIV_SHIFT
);
9096 if (lvds
& LVDS_CLKB_POWER_UP
)
9101 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
9104 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
9105 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
9107 if (dpll
& PLL_P2_DIVIDE_BY_4
)
9113 i9xx_clock(refclk
, &clock
);
9117 * This value includes pixel_multiplier. We will use
9118 * port_clock to compute adjusted_mode.crtc_clock in the
9119 * encoder's get_config() function.
9121 pipe_config
->port_clock
= clock
.dot
;
9124 int intel_dotclock_calculate(int link_freq
,
9125 const struct intel_link_m_n
*m_n
)
9128 * The calculation for the data clock is:
9129 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
9130 * But we want to avoid losing precison if possible, so:
9131 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
9133 * and the link clock is simpler:
9134 * link_clock = (m * link_clock) / n
9140 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
9143 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
9144 struct intel_crtc_state
*pipe_config
)
9146 struct drm_device
*dev
= crtc
->base
.dev
;
9148 /* read out port_clock from the DPLL */
9149 i9xx_crtc_clock_get(crtc
, pipe_config
);
9152 * This value does not include pixel_multiplier.
9153 * We will check that port_clock and adjusted_mode.crtc_clock
9154 * agree once we know their relationship in the encoder's
9155 * get_config() function.
9157 pipe_config
->base
.adjusted_mode
.crtc_clock
=
9158 intel_dotclock_calculate(intel_fdi_link_freq(dev
) * 10000,
9159 &pipe_config
->fdi_m_n
);
9162 /** Returns the currently programmed mode of the given pipe. */
9163 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
9164 struct drm_crtc
*crtc
)
9166 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9167 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9168 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
9169 struct drm_display_mode
*mode
;
9170 struct intel_crtc_state pipe_config
;
9171 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
9172 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
9173 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
9174 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
9175 enum pipe pipe
= intel_crtc
->pipe
;
9177 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
9182 * Construct a pipe_config sufficient for getting the clock info
9183 * back out of crtc_clock_get.
9185 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
9186 * to use a real value here instead.
9188 pipe_config
.cpu_transcoder
= (enum transcoder
) pipe
;
9189 pipe_config
.pixel_multiplier
= 1;
9190 pipe_config
.dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
9191 pipe_config
.dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
9192 pipe_config
.dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
9193 i9xx_crtc_clock_get(intel_crtc
, &pipe_config
);
9195 mode
->clock
= pipe_config
.port_clock
/ pipe_config
.pixel_multiplier
;
9196 mode
->hdisplay
= (htot
& 0xffff) + 1;
9197 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
9198 mode
->hsync_start
= (hsync
& 0xffff) + 1;
9199 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
9200 mode
->vdisplay
= (vtot
& 0xffff) + 1;
9201 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
9202 mode
->vsync_start
= (vsync
& 0xffff) + 1;
9203 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
9205 drm_mode_set_name(mode
);
9210 static void intel_decrease_pllclock(struct drm_crtc
*crtc
)
9212 struct drm_device
*dev
= crtc
->dev
;
9213 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9214 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9216 if (!HAS_GMCH_DISPLAY(dev
))
9219 if (!dev_priv
->lvds_downclock_avail
)
9223 * Since this is called by a timer, we should never get here in
9226 if (!HAS_PIPE_CXSR(dev
) && intel_crtc
->lowfreq_avail
) {
9227 int pipe
= intel_crtc
->pipe
;
9228 int dpll_reg
= DPLL(pipe
);
9231 DRM_DEBUG_DRIVER("downclocking LVDS\n");
9233 assert_panel_unlocked(dev_priv
, pipe
);
9235 dpll
= I915_READ(dpll_reg
);
9236 dpll
|= DISPLAY_RATE_SELECT_FPA1
;
9237 I915_WRITE(dpll_reg
, dpll
);
9238 intel_wait_for_vblank(dev
, pipe
);
9239 dpll
= I915_READ(dpll_reg
);
9240 if (!(dpll
& DISPLAY_RATE_SELECT_FPA1
))
9241 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
9246 void intel_mark_busy(struct drm_device
*dev
)
9248 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9250 if (dev_priv
->mm
.busy
)
9253 intel_runtime_pm_get(dev_priv
);
9254 i915_update_gfx_val(dev_priv
);
9255 if (INTEL_INFO(dev
)->gen
>= 6)
9256 gen6_rps_busy(dev_priv
);
9257 dev_priv
->mm
.busy
= true;
9260 void intel_mark_idle(struct drm_device
*dev
)
9262 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9263 struct drm_crtc
*crtc
;
9265 if (!dev_priv
->mm
.busy
)
9268 dev_priv
->mm
.busy
= false;
9270 if (!i915
.powersave
)
9273 for_each_crtc(dev
, crtc
) {
9274 if (!crtc
->primary
->fb
)
9277 intel_decrease_pllclock(crtc
);
9280 if (INTEL_INFO(dev
)->gen
>= 6)
9281 gen6_rps_idle(dev
->dev_private
);
9284 intel_runtime_pm_put(dev_priv
);
9287 static void intel_crtc_set_state(struct intel_crtc
*crtc
,
9288 struct intel_crtc_state
*crtc_state
)
9290 kfree(crtc
->config
);
9291 crtc
->config
= crtc_state
;
9292 crtc
->base
.state
= &crtc_state
->base
;
9295 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
9297 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9298 struct drm_device
*dev
= crtc
->dev
;
9299 struct intel_unpin_work
*work
;
9301 spin_lock_irq(&dev
->event_lock
);
9302 work
= intel_crtc
->unpin_work
;
9303 intel_crtc
->unpin_work
= NULL
;
9304 spin_unlock_irq(&dev
->event_lock
);
9307 cancel_work_sync(&work
->work
);
9311 intel_crtc_set_state(intel_crtc
, NULL
);
9312 drm_crtc_cleanup(crtc
);
9317 static void intel_unpin_work_fn(struct work_struct
*__work
)
9319 struct intel_unpin_work
*work
=
9320 container_of(__work
, struct intel_unpin_work
, work
);
9321 struct drm_device
*dev
= work
->crtc
->dev
;
9322 enum pipe pipe
= to_intel_crtc(work
->crtc
)->pipe
;
9324 mutex_lock(&dev
->struct_mutex
);
9325 intel_unpin_fb_obj(work
->old_fb
, work
->crtc
->primary
->state
);
9326 drm_gem_object_unreference(&work
->pending_flip_obj
->base
);
9328 intel_fbc_update(dev
);
9330 if (work
->flip_queued_req
)
9331 i915_gem_request_assign(&work
->flip_queued_req
, NULL
);
9332 mutex_unlock(&dev
->struct_mutex
);
9334 intel_frontbuffer_flip_complete(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
9335 drm_framebuffer_unreference(work
->old_fb
);
9337 BUG_ON(atomic_read(&to_intel_crtc(work
->crtc
)->unpin_work_count
) == 0);
9338 atomic_dec(&to_intel_crtc(work
->crtc
)->unpin_work_count
);
9343 static void do_intel_finish_page_flip(struct drm_device
*dev
,
9344 struct drm_crtc
*crtc
)
9346 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9347 struct intel_unpin_work
*work
;
9348 unsigned long flags
;
9350 /* Ignore early vblank irqs */
9351 if (intel_crtc
== NULL
)
9355 * This is called both by irq handlers and the reset code (to complete
9356 * lost pageflips) so needs the full irqsave spinlocks.
9358 spin_lock_irqsave(&dev
->event_lock
, flags
);
9359 work
= intel_crtc
->unpin_work
;
9361 /* Ensure we don't miss a work->pending update ... */
9364 if (work
== NULL
|| atomic_read(&work
->pending
) < INTEL_FLIP_COMPLETE
) {
9365 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9369 page_flip_completed(intel_crtc
);
9371 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9374 void intel_finish_page_flip(struct drm_device
*dev
, int pipe
)
9376 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9377 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
9379 do_intel_finish_page_flip(dev
, crtc
);
9382 void intel_finish_page_flip_plane(struct drm_device
*dev
, int plane
)
9384 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9385 struct drm_crtc
*crtc
= dev_priv
->plane_to_crtc_mapping
[plane
];
9387 do_intel_finish_page_flip(dev
, crtc
);
9390 /* Is 'a' after or equal to 'b'? */
9391 static bool g4x_flip_count_after_eq(u32 a
, u32 b
)
9393 return !((a
- b
) & 0x80000000);
9396 static bool page_flip_finished(struct intel_crtc
*crtc
)
9398 struct drm_device
*dev
= crtc
->base
.dev
;
9399 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9401 if (i915_reset_in_progress(&dev_priv
->gpu_error
) ||
9402 crtc
->reset_counter
!= atomic_read(&dev_priv
->gpu_error
.reset_counter
))
9406 * The relevant registers doen't exist on pre-ctg.
9407 * As the flip done interrupt doesn't trigger for mmio
9408 * flips on gmch platforms, a flip count check isn't
9409 * really needed there. But since ctg has the registers,
9410 * include it in the check anyway.
9412 if (INTEL_INFO(dev
)->gen
< 5 && !IS_G4X(dev
))
9416 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
9417 * used the same base address. In that case the mmio flip might
9418 * have completed, but the CS hasn't even executed the flip yet.
9420 * A flip count check isn't enough as the CS might have updated
9421 * the base address just after start of vblank, but before we
9422 * managed to process the interrupt. This means we'd complete the
9425 * Combining both checks should get us a good enough result. It may
9426 * still happen that the CS flip has been executed, but has not
9427 * yet actually completed. But in case the base address is the same
9428 * anyway, we don't really care.
9430 return (I915_READ(DSPSURFLIVE(crtc
->plane
)) & ~0xfff) ==
9431 crtc
->unpin_work
->gtt_offset
&&
9432 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc
->pipe
)),
9433 crtc
->unpin_work
->flip_count
);
9436 void intel_prepare_page_flip(struct drm_device
*dev
, int plane
)
9438 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9439 struct intel_crtc
*intel_crtc
=
9440 to_intel_crtc(dev_priv
->plane_to_crtc_mapping
[plane
]);
9441 unsigned long flags
;
9445 * This is called both by irq handlers and the reset code (to complete
9446 * lost pageflips) so needs the full irqsave spinlocks.
9448 * NB: An MMIO update of the plane base pointer will also
9449 * generate a page-flip completion irq, i.e. every modeset
9450 * is also accompanied by a spurious intel_prepare_page_flip().
9452 spin_lock_irqsave(&dev
->event_lock
, flags
);
9453 if (intel_crtc
->unpin_work
&& page_flip_finished(intel_crtc
))
9454 atomic_inc_not_zero(&intel_crtc
->unpin_work
->pending
);
9455 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9458 static inline void intel_mark_page_flip_active(struct intel_crtc
*intel_crtc
)
9460 /* Ensure that the work item is consistent when activating it ... */
9462 atomic_set(&intel_crtc
->unpin_work
->pending
, INTEL_FLIP_PENDING
);
9463 /* and that it is marked active as soon as the irq could fire. */
9467 static int intel_gen2_queue_flip(struct drm_device
*dev
,
9468 struct drm_crtc
*crtc
,
9469 struct drm_framebuffer
*fb
,
9470 struct drm_i915_gem_object
*obj
,
9471 struct intel_engine_cs
*ring
,
9474 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9478 ret
= intel_ring_begin(ring
, 6);
9482 /* Can't queue multiple flips, so wait for the previous
9483 * one to finish before executing the next.
9485 if (intel_crtc
->plane
)
9486 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
9488 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
9489 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
9490 intel_ring_emit(ring
, MI_NOOP
);
9491 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9492 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9493 intel_ring_emit(ring
, fb
->pitches
[0]);
9494 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9495 intel_ring_emit(ring
, 0); /* aux display base address, unused */
9497 intel_mark_page_flip_active(intel_crtc
);
9498 __intel_ring_advance(ring
);
9502 static int intel_gen3_queue_flip(struct drm_device
*dev
,
9503 struct drm_crtc
*crtc
,
9504 struct drm_framebuffer
*fb
,
9505 struct drm_i915_gem_object
*obj
,
9506 struct intel_engine_cs
*ring
,
9509 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9513 ret
= intel_ring_begin(ring
, 6);
9517 if (intel_crtc
->plane
)
9518 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
9520 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
9521 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
9522 intel_ring_emit(ring
, MI_NOOP
);
9523 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
|
9524 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9525 intel_ring_emit(ring
, fb
->pitches
[0]);
9526 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9527 intel_ring_emit(ring
, MI_NOOP
);
9529 intel_mark_page_flip_active(intel_crtc
);
9530 __intel_ring_advance(ring
);
9534 static int intel_gen4_queue_flip(struct drm_device
*dev
,
9535 struct drm_crtc
*crtc
,
9536 struct drm_framebuffer
*fb
,
9537 struct drm_i915_gem_object
*obj
,
9538 struct intel_engine_cs
*ring
,
9541 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9542 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9543 uint32_t pf
, pipesrc
;
9546 ret
= intel_ring_begin(ring
, 4);
9550 /* i965+ uses the linear or tiled offsets from the
9551 * Display Registers (which do not change across a page-flip)
9552 * so we need only reprogram the base address.
9554 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9555 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9556 intel_ring_emit(ring
, fb
->pitches
[0]);
9557 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
|
9560 /* XXX Enabling the panel-fitter across page-flip is so far
9561 * untested on non-native modes, so ignore it for now.
9562 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
9565 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
9566 intel_ring_emit(ring
, pf
| pipesrc
);
9568 intel_mark_page_flip_active(intel_crtc
);
9569 __intel_ring_advance(ring
);
9573 static int intel_gen6_queue_flip(struct drm_device
*dev
,
9574 struct drm_crtc
*crtc
,
9575 struct drm_framebuffer
*fb
,
9576 struct drm_i915_gem_object
*obj
,
9577 struct intel_engine_cs
*ring
,
9580 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9581 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9582 uint32_t pf
, pipesrc
;
9585 ret
= intel_ring_begin(ring
, 4);
9589 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9590 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9591 intel_ring_emit(ring
, fb
->pitches
[0] | obj
->tiling_mode
);
9592 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9594 /* Contrary to the suggestions in the documentation,
9595 * "Enable Panel Fitter" does not seem to be required when page
9596 * flipping with a non-native mode, and worse causes a normal
9598 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
9601 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
9602 intel_ring_emit(ring
, pf
| pipesrc
);
9604 intel_mark_page_flip_active(intel_crtc
);
9605 __intel_ring_advance(ring
);
9609 static int intel_gen7_queue_flip(struct drm_device
*dev
,
9610 struct drm_crtc
*crtc
,
9611 struct drm_framebuffer
*fb
,
9612 struct drm_i915_gem_object
*obj
,
9613 struct intel_engine_cs
*ring
,
9616 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9617 uint32_t plane_bit
= 0;
9620 switch (intel_crtc
->plane
) {
9622 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
9625 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
9628 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
9631 WARN_ONCE(1, "unknown plane in flip command\n");
9636 if (ring
->id
== RCS
) {
9639 * On Gen 8, SRM is now taking an extra dword to accommodate
9640 * 48bits addresses, and we need a NOOP for the batch size to
9648 * BSpec MI_DISPLAY_FLIP for IVB:
9649 * "The full packet must be contained within the same cache line."
9651 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
9652 * cacheline, if we ever start emitting more commands before
9653 * the MI_DISPLAY_FLIP we may need to first emit everything else,
9654 * then do the cacheline alignment, and finally emit the
9657 ret
= intel_ring_cacheline_align(ring
);
9661 ret
= intel_ring_begin(ring
, len
);
9665 /* Unmask the flip-done completion message. Note that the bspec says that
9666 * we should do this for both the BCS and RCS, and that we must not unmask
9667 * more than one flip event at any time (or ensure that one flip message
9668 * can be sent by waiting for flip-done prior to queueing new flips).
9669 * Experimentation says that BCS works despite DERRMR masking all
9670 * flip-done completion events and that unmasking all planes at once
9671 * for the RCS also doesn't appear to drop events. Setting the DERRMR
9672 * to zero does lead to lockups within MI_DISPLAY_FLIP.
9674 if (ring
->id
== RCS
) {
9675 intel_ring_emit(ring
, MI_LOAD_REGISTER_IMM(1));
9676 intel_ring_emit(ring
, DERRMR
);
9677 intel_ring_emit(ring
, ~(DERRMR_PIPEA_PRI_FLIP_DONE
|
9678 DERRMR_PIPEB_PRI_FLIP_DONE
|
9679 DERRMR_PIPEC_PRI_FLIP_DONE
));
9681 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM_GEN8(1) |
9682 MI_SRM_LRM_GLOBAL_GTT
);
9684 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM(1) |
9685 MI_SRM_LRM_GLOBAL_GTT
);
9686 intel_ring_emit(ring
, DERRMR
);
9687 intel_ring_emit(ring
, ring
->scratch
.gtt_offset
+ 256);
9689 intel_ring_emit(ring
, 0);
9690 intel_ring_emit(ring
, MI_NOOP
);
9694 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
| plane_bit
);
9695 intel_ring_emit(ring
, (fb
->pitches
[0] | obj
->tiling_mode
));
9696 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9697 intel_ring_emit(ring
, (MI_NOOP
));
9699 intel_mark_page_flip_active(intel_crtc
);
9700 __intel_ring_advance(ring
);
9704 static bool use_mmio_flip(struct intel_engine_cs
*ring
,
9705 struct drm_i915_gem_object
*obj
)
9708 * This is not being used for older platforms, because
9709 * non-availability of flip done interrupt forces us to use
9710 * CS flips. Older platforms derive flip done using some clever
9711 * tricks involving the flip_pending status bits and vblank irqs.
9712 * So using MMIO flips there would disrupt this mechanism.
9718 if (INTEL_INFO(ring
->dev
)->gen
< 5)
9721 if (i915
.use_mmio_flip
< 0)
9723 else if (i915
.use_mmio_flip
> 0)
9725 else if (i915
.enable_execlists
)
9728 return ring
!= i915_gem_request_get_ring(obj
->last_read_req
);
9731 static void skl_do_mmio_flip(struct intel_crtc
*intel_crtc
)
9733 struct drm_device
*dev
= intel_crtc
->base
.dev
;
9734 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9735 struct drm_framebuffer
*fb
= intel_crtc
->base
.primary
->fb
;
9736 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
9737 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
9738 const enum pipe pipe
= intel_crtc
->pipe
;
9741 ctl
= I915_READ(PLANE_CTL(pipe
, 0));
9742 ctl
&= ~PLANE_CTL_TILED_MASK
;
9743 if (obj
->tiling_mode
== I915_TILING_X
)
9744 ctl
|= PLANE_CTL_TILED_X
;
9747 * The stride is either expressed as a multiple of 64 bytes chunks for
9748 * linear buffers or in number of tiles for tiled buffers.
9750 stride
= fb
->pitches
[0] >> 6;
9751 if (obj
->tiling_mode
== I915_TILING_X
)
9752 stride
= fb
->pitches
[0] >> 9; /* X tiles are 512 bytes wide */
9755 * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on
9756 * PLANE_SURF updates, the update is then guaranteed to be atomic.
9758 I915_WRITE(PLANE_CTL(pipe
, 0), ctl
);
9759 I915_WRITE(PLANE_STRIDE(pipe
, 0), stride
);
9761 I915_WRITE(PLANE_SURF(pipe
, 0), intel_crtc
->unpin_work
->gtt_offset
);
9762 POSTING_READ(PLANE_SURF(pipe
, 0));
9765 static void ilk_do_mmio_flip(struct intel_crtc
*intel_crtc
)
9767 struct drm_device
*dev
= intel_crtc
->base
.dev
;
9768 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9769 struct intel_framebuffer
*intel_fb
=
9770 to_intel_framebuffer(intel_crtc
->base
.primary
->fb
);
9771 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
9775 reg
= DSPCNTR(intel_crtc
->plane
);
9776 dspcntr
= I915_READ(reg
);
9778 if (obj
->tiling_mode
!= I915_TILING_NONE
)
9779 dspcntr
|= DISPPLANE_TILED
;
9781 dspcntr
&= ~DISPPLANE_TILED
;
9783 I915_WRITE(reg
, dspcntr
);
9785 I915_WRITE(DSPSURF(intel_crtc
->plane
),
9786 intel_crtc
->unpin_work
->gtt_offset
);
9787 POSTING_READ(DSPSURF(intel_crtc
->plane
));
9792 * XXX: This is the temporary way to update the plane registers until we get
9793 * around to using the usual plane update functions for MMIO flips
9795 static void intel_do_mmio_flip(struct intel_crtc
*intel_crtc
)
9797 struct drm_device
*dev
= intel_crtc
->base
.dev
;
9799 u32 start_vbl_count
;
9801 intel_mark_page_flip_active(intel_crtc
);
9803 atomic_update
= intel_pipe_update_start(intel_crtc
, &start_vbl_count
);
9805 if (INTEL_INFO(dev
)->gen
>= 9)
9806 skl_do_mmio_flip(intel_crtc
);
9808 /* use_mmio_flip() retricts MMIO flips to ilk+ */
9809 ilk_do_mmio_flip(intel_crtc
);
9812 intel_pipe_update_end(intel_crtc
, start_vbl_count
);
9815 static void intel_mmio_flip_work_func(struct work_struct
*work
)
9817 struct intel_crtc
*crtc
=
9818 container_of(work
, struct intel_crtc
, mmio_flip
.work
);
9819 struct intel_mmio_flip
*mmio_flip
;
9821 mmio_flip
= &crtc
->mmio_flip
;
9823 WARN_ON(__i915_wait_request(mmio_flip
->req
,
9824 crtc
->reset_counter
,
9825 false, NULL
, NULL
) != 0);
9827 intel_do_mmio_flip(crtc
);
9828 if (mmio_flip
->req
) {
9829 mutex_lock(&crtc
->base
.dev
->struct_mutex
);
9830 i915_gem_request_assign(&mmio_flip
->req
, NULL
);
9831 mutex_unlock(&crtc
->base
.dev
->struct_mutex
);
9835 static int intel_queue_mmio_flip(struct drm_device
*dev
,
9836 struct drm_crtc
*crtc
,
9837 struct drm_framebuffer
*fb
,
9838 struct drm_i915_gem_object
*obj
,
9839 struct intel_engine_cs
*ring
,
9842 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9844 i915_gem_request_assign(&intel_crtc
->mmio_flip
.req
,
9845 obj
->last_write_req
);
9847 schedule_work(&intel_crtc
->mmio_flip
.work
);
9852 static int intel_default_queue_flip(struct drm_device
*dev
,
9853 struct drm_crtc
*crtc
,
9854 struct drm_framebuffer
*fb
,
9855 struct drm_i915_gem_object
*obj
,
9856 struct intel_engine_cs
*ring
,
9862 static bool __intel_pageflip_stall_check(struct drm_device
*dev
,
9863 struct drm_crtc
*crtc
)
9865 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9866 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9867 struct intel_unpin_work
*work
= intel_crtc
->unpin_work
;
9870 if (atomic_read(&work
->pending
) >= INTEL_FLIP_COMPLETE
)
9873 if (!work
->enable_stall_check
)
9876 if (work
->flip_ready_vblank
== 0) {
9877 if (work
->flip_queued_req
&&
9878 !i915_gem_request_completed(work
->flip_queued_req
, true))
9881 work
->flip_ready_vblank
= drm_crtc_vblank_count(crtc
);
9884 if (drm_crtc_vblank_count(crtc
) - work
->flip_ready_vblank
< 3)
9887 /* Potential stall - if we see that the flip has happened,
9888 * assume a missed interrupt. */
9889 if (INTEL_INFO(dev
)->gen
>= 4)
9890 addr
= I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc
->plane
)));
9892 addr
= I915_READ(DSPADDR(intel_crtc
->plane
));
9894 /* There is a potential issue here with a false positive after a flip
9895 * to the same address. We could address this by checking for a
9896 * non-incrementing frame counter.
9898 return addr
== work
->gtt_offset
;
9901 void intel_check_page_flip(struct drm_device
*dev
, int pipe
)
9903 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9904 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
9905 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9907 WARN_ON(!in_interrupt());
9912 spin_lock(&dev
->event_lock
);
9913 if (intel_crtc
->unpin_work
&& __intel_pageflip_stall_check(dev
, crtc
)) {
9914 WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n",
9915 intel_crtc
->unpin_work
->flip_queued_vblank
,
9916 drm_vblank_count(dev
, pipe
));
9917 page_flip_completed(intel_crtc
);
9919 spin_unlock(&dev
->event_lock
);
9922 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
9923 struct drm_framebuffer
*fb
,
9924 struct drm_pending_vblank_event
*event
,
9925 uint32_t page_flip_flags
)
9927 struct drm_device
*dev
= crtc
->dev
;
9928 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9929 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
9930 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
9931 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9932 struct drm_plane
*primary
= crtc
->primary
;
9933 enum pipe pipe
= intel_crtc
->pipe
;
9934 struct intel_unpin_work
*work
;
9935 struct intel_engine_cs
*ring
;
9939 * drm_mode_page_flip_ioctl() should already catch this, but double
9940 * check to be safe. In the future we may enable pageflipping from
9941 * a disabled primary plane.
9943 if (WARN_ON(intel_fb_obj(old_fb
) == NULL
))
9946 /* Can't change pixel format via MI display flips. */
9947 if (fb
->pixel_format
!= crtc
->primary
->fb
->pixel_format
)
9951 * TILEOFF/LINOFF registers can't be changed via MI display flips.
9952 * Note that pitch changes could also affect these register.
9954 if (INTEL_INFO(dev
)->gen
> 3 &&
9955 (fb
->offsets
[0] != crtc
->primary
->fb
->offsets
[0] ||
9956 fb
->pitches
[0] != crtc
->primary
->fb
->pitches
[0]))
9959 if (i915_terminally_wedged(&dev_priv
->gpu_error
))
9962 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
9966 work
->event
= event
;
9968 work
->old_fb
= old_fb
;
9969 INIT_WORK(&work
->work
, intel_unpin_work_fn
);
9971 ret
= drm_crtc_vblank_get(crtc
);
9975 /* We borrow the event spin lock for protecting unpin_work */
9976 spin_lock_irq(&dev
->event_lock
);
9977 if (intel_crtc
->unpin_work
) {
9978 /* Before declaring the flip queue wedged, check if
9979 * the hardware completed the operation behind our backs.
9981 if (__intel_pageflip_stall_check(dev
, crtc
)) {
9982 DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
9983 page_flip_completed(intel_crtc
);
9985 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
9986 spin_unlock_irq(&dev
->event_lock
);
9988 drm_crtc_vblank_put(crtc
);
9993 intel_crtc
->unpin_work
= work
;
9994 spin_unlock_irq(&dev
->event_lock
);
9996 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
9997 flush_workqueue(dev_priv
->wq
);
9999 /* Reference the objects for the scheduled work. */
10000 drm_framebuffer_reference(work
->old_fb
);
10001 drm_gem_object_reference(&obj
->base
);
10003 crtc
->primary
->fb
= fb
;
10004 update_state_fb(crtc
->primary
);
10006 work
->pending_flip_obj
= obj
;
10008 ret
= i915_mutex_lock_interruptible(dev
);
10012 atomic_inc(&intel_crtc
->unpin_work_count
);
10013 intel_crtc
->reset_counter
= atomic_read(&dev_priv
->gpu_error
.reset_counter
);
10015 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
10016 work
->flip_count
= I915_READ(PIPE_FLIPCOUNT_GM45(pipe
)) + 1;
10018 if (IS_VALLEYVIEW(dev
)) {
10019 ring
= &dev_priv
->ring
[BCS
];
10020 if (obj
->tiling_mode
!= intel_fb_obj(work
->old_fb
)->tiling_mode
)
10021 /* vlv: DISPLAY_FLIP fails to change tiling */
10023 } else if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
)) {
10024 ring
= &dev_priv
->ring
[BCS
];
10025 } else if (INTEL_INFO(dev
)->gen
>= 7) {
10026 ring
= i915_gem_request_get_ring(obj
->last_read_req
);
10027 if (ring
== NULL
|| ring
->id
!= RCS
)
10028 ring
= &dev_priv
->ring
[BCS
];
10030 ring
= &dev_priv
->ring
[RCS
];
10033 ret
= intel_pin_and_fence_fb_obj(crtc
->primary
, fb
,
10034 crtc
->primary
->state
, ring
);
10036 goto cleanup_pending
;
10039 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
;
10041 if (use_mmio_flip(ring
, obj
)) {
10042 ret
= intel_queue_mmio_flip(dev
, crtc
, fb
, obj
, ring
,
10045 goto cleanup_unpin
;
10047 i915_gem_request_assign(&work
->flip_queued_req
,
10048 obj
->last_write_req
);
10050 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
, ring
,
10053 goto cleanup_unpin
;
10055 i915_gem_request_assign(&work
->flip_queued_req
,
10056 intel_ring_get_request(ring
));
10059 work
->flip_queued_vblank
= drm_crtc_vblank_count(crtc
);
10060 work
->enable_stall_check
= true;
10062 i915_gem_track_fb(intel_fb_obj(work
->old_fb
), obj
,
10063 INTEL_FRONTBUFFER_PRIMARY(pipe
));
10065 intel_fbc_disable(dev
);
10066 intel_frontbuffer_flip_prepare(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
10067 mutex_unlock(&dev
->struct_mutex
);
10069 trace_i915_flip_request(intel_crtc
->plane
, obj
);
10074 intel_unpin_fb_obj(fb
, crtc
->primary
->state
);
10076 atomic_dec(&intel_crtc
->unpin_work_count
);
10077 mutex_unlock(&dev
->struct_mutex
);
10079 crtc
->primary
->fb
= old_fb
;
10080 update_state_fb(crtc
->primary
);
10082 drm_gem_object_unreference_unlocked(&obj
->base
);
10083 drm_framebuffer_unreference(work
->old_fb
);
10085 spin_lock_irq(&dev
->event_lock
);
10086 intel_crtc
->unpin_work
= NULL
;
10087 spin_unlock_irq(&dev
->event_lock
);
10089 drm_crtc_vblank_put(crtc
);
10095 ret
= intel_plane_restore(primary
);
10096 if (ret
== 0 && event
) {
10097 spin_lock_irq(&dev
->event_lock
);
10098 drm_send_vblank_event(dev
, pipe
, event
);
10099 spin_unlock_irq(&dev
->event_lock
);
10105 static struct drm_crtc_helper_funcs intel_helper_funcs
= {
10106 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
10107 .load_lut
= intel_crtc_load_lut
,
10108 .atomic_begin
= intel_begin_crtc_commit
,
10109 .atomic_flush
= intel_finish_crtc_commit
,
10113 * intel_modeset_update_staged_output_state
10115 * Updates the staged output configuration state, e.g. after we've read out the
10116 * current hw state.
10118 static void intel_modeset_update_staged_output_state(struct drm_device
*dev
)
10120 struct intel_crtc
*crtc
;
10121 struct intel_encoder
*encoder
;
10122 struct intel_connector
*connector
;
10124 for_each_intel_connector(dev
, connector
) {
10125 connector
->new_encoder
=
10126 to_intel_encoder(connector
->base
.encoder
);
10129 for_each_intel_encoder(dev
, encoder
) {
10130 encoder
->new_crtc
=
10131 to_intel_crtc(encoder
->base
.crtc
);
10134 for_each_intel_crtc(dev
, crtc
) {
10135 crtc
->new_enabled
= crtc
->base
.state
->enable
;
10137 if (crtc
->new_enabled
)
10138 crtc
->new_config
= crtc
->config
;
10140 crtc
->new_config
= NULL
;
10145 * intel_modeset_commit_output_state
10147 * This function copies the stage display pipe configuration to the real one.
10149 static void intel_modeset_commit_output_state(struct drm_device
*dev
)
10151 struct intel_crtc
*crtc
;
10152 struct intel_encoder
*encoder
;
10153 struct intel_connector
*connector
;
10155 for_each_intel_connector(dev
, connector
) {
10156 connector
->base
.encoder
= &connector
->new_encoder
->base
;
10159 for_each_intel_encoder(dev
, encoder
) {
10160 encoder
->base
.crtc
= &encoder
->new_crtc
->base
;
10163 for_each_intel_crtc(dev
, crtc
) {
10164 crtc
->base
.state
->enable
= crtc
->new_enabled
;
10165 crtc
->base
.enabled
= crtc
->new_enabled
;
10170 connected_sink_compute_bpp(struct intel_connector
*connector
,
10171 struct intel_crtc_state
*pipe_config
)
10173 int bpp
= pipe_config
->pipe_bpp
;
10175 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
10176 connector
->base
.base
.id
,
10177 connector
->base
.name
);
10179 /* Don't use an invalid EDID bpc value */
10180 if (connector
->base
.display_info
.bpc
&&
10181 connector
->base
.display_info
.bpc
* 3 < bpp
) {
10182 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
10183 bpp
, connector
->base
.display_info
.bpc
*3);
10184 pipe_config
->pipe_bpp
= connector
->base
.display_info
.bpc
*3;
10187 /* Clamp bpp to 8 on screens without EDID 1.4 */
10188 if (connector
->base
.display_info
.bpc
== 0 && bpp
> 24) {
10189 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
10191 pipe_config
->pipe_bpp
= 24;
10196 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
10197 struct drm_framebuffer
*fb
,
10198 struct intel_crtc_state
*pipe_config
)
10200 struct drm_device
*dev
= crtc
->base
.dev
;
10201 struct intel_connector
*connector
;
10204 switch (fb
->pixel_format
) {
10205 case DRM_FORMAT_C8
:
10206 bpp
= 8*3; /* since we go through a colormap */
10208 case DRM_FORMAT_XRGB1555
:
10209 case DRM_FORMAT_ARGB1555
:
10210 /* checked in intel_framebuffer_init already */
10211 if (WARN_ON(INTEL_INFO(dev
)->gen
> 3))
10213 case DRM_FORMAT_RGB565
:
10214 bpp
= 6*3; /* min is 18bpp */
10216 case DRM_FORMAT_XBGR8888
:
10217 case DRM_FORMAT_ABGR8888
:
10218 /* checked in intel_framebuffer_init already */
10219 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
10221 case DRM_FORMAT_XRGB8888
:
10222 case DRM_FORMAT_ARGB8888
:
10225 case DRM_FORMAT_XRGB2101010
:
10226 case DRM_FORMAT_ARGB2101010
:
10227 case DRM_FORMAT_XBGR2101010
:
10228 case DRM_FORMAT_ABGR2101010
:
10229 /* checked in intel_framebuffer_init already */
10230 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
10234 /* TODO: gen4+ supports 16 bpc floating point, too. */
10236 DRM_DEBUG_KMS("unsupported depth\n");
10240 pipe_config
->pipe_bpp
= bpp
;
10242 /* Clamp display bpp to EDID value */
10243 for_each_intel_connector(dev
, connector
) {
10244 if (!connector
->new_encoder
||
10245 connector
->new_encoder
->new_crtc
!= crtc
)
10248 connected_sink_compute_bpp(connector
, pipe_config
);
10254 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
10256 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
10257 "type: 0x%x flags: 0x%x\n",
10259 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
10260 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
10261 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
10262 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
10265 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
10266 struct intel_crtc_state
*pipe_config
,
10267 const char *context
)
10269 DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc
->base
.base
.id
,
10270 context
, pipe_name(crtc
->pipe
));
10272 DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config
->cpu_transcoder
));
10273 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
10274 pipe_config
->pipe_bpp
, pipe_config
->dither
);
10275 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10276 pipe_config
->has_pch_encoder
,
10277 pipe_config
->fdi_lanes
,
10278 pipe_config
->fdi_m_n
.gmch_m
, pipe_config
->fdi_m_n
.gmch_n
,
10279 pipe_config
->fdi_m_n
.link_m
, pipe_config
->fdi_m_n
.link_n
,
10280 pipe_config
->fdi_m_n
.tu
);
10281 DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10282 pipe_config
->has_dp_encoder
,
10283 pipe_config
->dp_m_n
.gmch_m
, pipe_config
->dp_m_n
.gmch_n
,
10284 pipe_config
->dp_m_n
.link_m
, pipe_config
->dp_m_n
.link_n
,
10285 pipe_config
->dp_m_n
.tu
);
10287 DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
10288 pipe_config
->has_dp_encoder
,
10289 pipe_config
->dp_m2_n2
.gmch_m
,
10290 pipe_config
->dp_m2_n2
.gmch_n
,
10291 pipe_config
->dp_m2_n2
.link_m
,
10292 pipe_config
->dp_m2_n2
.link_n
,
10293 pipe_config
->dp_m2_n2
.tu
);
10295 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
10296 pipe_config
->has_audio
,
10297 pipe_config
->has_infoframe
);
10299 DRM_DEBUG_KMS("requested mode:\n");
10300 drm_mode_debug_printmodeline(&pipe_config
->base
.mode
);
10301 DRM_DEBUG_KMS("adjusted mode:\n");
10302 drm_mode_debug_printmodeline(&pipe_config
->base
.adjusted_mode
);
10303 intel_dump_crtc_timings(&pipe_config
->base
.adjusted_mode
);
10304 DRM_DEBUG_KMS("port clock: %d\n", pipe_config
->port_clock
);
10305 DRM_DEBUG_KMS("pipe src size: %dx%d\n",
10306 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
10307 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
10308 pipe_config
->gmch_pfit
.control
,
10309 pipe_config
->gmch_pfit
.pgm_ratios
,
10310 pipe_config
->gmch_pfit
.lvds_border_bits
);
10311 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
10312 pipe_config
->pch_pfit
.pos
,
10313 pipe_config
->pch_pfit
.size
,
10314 pipe_config
->pch_pfit
.enabled
? "enabled" : "disabled");
10315 DRM_DEBUG_KMS("ips: %i\n", pipe_config
->ips_enabled
);
10316 DRM_DEBUG_KMS("double wide: %i\n", pipe_config
->double_wide
);
10319 static bool encoders_cloneable(const struct intel_encoder
*a
,
10320 const struct intel_encoder
*b
)
10322 /* masks could be asymmetric, so check both ways */
10323 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
10324 b
->cloneable
& (1 << a
->type
));
10327 static bool check_single_encoder_cloning(struct intel_crtc
*crtc
,
10328 struct intel_encoder
*encoder
)
10330 struct drm_device
*dev
= crtc
->base
.dev
;
10331 struct intel_encoder
*source_encoder
;
10333 for_each_intel_encoder(dev
, source_encoder
) {
10334 if (source_encoder
->new_crtc
!= crtc
)
10337 if (!encoders_cloneable(encoder
, source_encoder
))
10344 static bool check_encoder_cloning(struct intel_crtc
*crtc
)
10346 struct drm_device
*dev
= crtc
->base
.dev
;
10347 struct intel_encoder
*encoder
;
10349 for_each_intel_encoder(dev
, encoder
) {
10350 if (encoder
->new_crtc
!= crtc
)
10353 if (!check_single_encoder_cloning(crtc
, encoder
))
10360 static bool check_digital_port_conflicts(struct drm_device
*dev
)
10362 struct intel_connector
*connector
;
10363 unsigned int used_ports
= 0;
10366 * Walk the connector list instead of the encoder
10367 * list to detect the problem on ddi platforms
10368 * where there's just one encoder per digital port.
10370 for_each_intel_connector(dev
, connector
) {
10371 struct intel_encoder
*encoder
= connector
->new_encoder
;
10376 WARN_ON(!encoder
->new_crtc
);
10378 switch (encoder
->type
) {
10379 unsigned int port_mask
;
10380 case INTEL_OUTPUT_UNKNOWN
:
10381 if (WARN_ON(!HAS_DDI(dev
)))
10383 case INTEL_OUTPUT_DISPLAYPORT
:
10384 case INTEL_OUTPUT_HDMI
:
10385 case INTEL_OUTPUT_EDP
:
10386 port_mask
= 1 << enc_to_dig_port(&encoder
->base
)->port
;
10388 /* the same port mustn't appear more than once */
10389 if (used_ports
& port_mask
)
10392 used_ports
|= port_mask
;
10401 static struct intel_crtc_state
*
10402 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
10403 struct drm_framebuffer
*fb
,
10404 struct drm_display_mode
*mode
)
10406 struct drm_device
*dev
= crtc
->dev
;
10407 struct intel_encoder
*encoder
;
10408 struct intel_crtc_state
*pipe_config
;
10409 int plane_bpp
, ret
= -EINVAL
;
10412 if (!check_encoder_cloning(to_intel_crtc(crtc
))) {
10413 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
10414 return ERR_PTR(-EINVAL
);
10417 if (!check_digital_port_conflicts(dev
)) {
10418 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
10419 return ERR_PTR(-EINVAL
);
10422 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
10424 return ERR_PTR(-ENOMEM
);
10426 pipe_config
->base
.crtc
= crtc
;
10427 drm_mode_copy(&pipe_config
->base
.adjusted_mode
, mode
);
10428 drm_mode_copy(&pipe_config
->base
.mode
, mode
);
10430 pipe_config
->cpu_transcoder
=
10431 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
10432 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
10435 * Sanitize sync polarity flags based on requested ones. If neither
10436 * positive or negative polarity is requested, treat this as meaning
10437 * negative polarity.
10439 if (!(pipe_config
->base
.adjusted_mode
.flags
&
10440 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
10441 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
10443 if (!(pipe_config
->base
.adjusted_mode
.flags
&
10444 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
10445 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
10447 /* Compute a starting value for pipe_config->pipe_bpp taking the source
10448 * plane pixel format and any sink constraints into account. Returns the
10449 * source plane bpp so that dithering can be selected on mismatches
10450 * after encoders and crtc also have had their say. */
10451 plane_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
10457 * Determine the real pipe dimensions. Note that stereo modes can
10458 * increase the actual pipe size due to the frame doubling and
10459 * insertion of additional space for blanks between the frame. This
10460 * is stored in the crtc timings. We use the requested mode to do this
10461 * computation to clearly distinguish it from the adjusted mode, which
10462 * can be changed by the connectors in the below retry loop.
10464 drm_crtc_get_hv_timing(&pipe_config
->base
.mode
,
10465 &pipe_config
->pipe_src_w
,
10466 &pipe_config
->pipe_src_h
);
10469 /* Ensure the port clock defaults are reset when retrying. */
10470 pipe_config
->port_clock
= 0;
10471 pipe_config
->pixel_multiplier
= 1;
10473 /* Fill in default crtc timings, allow encoders to overwrite them. */
10474 drm_mode_set_crtcinfo(&pipe_config
->base
.adjusted_mode
,
10475 CRTC_STEREO_DOUBLE
);
10477 /* Pass our mode to the connectors and the CRTC to give them a chance to
10478 * adjust it according to limitations or connector properties, and also
10479 * a chance to reject the mode entirely.
10481 for_each_intel_encoder(dev
, encoder
) {
10483 if (&encoder
->new_crtc
->base
!= crtc
)
10486 if (!(encoder
->compute_config(encoder
, pipe_config
))) {
10487 DRM_DEBUG_KMS("Encoder config failure\n");
10492 /* Set default port clock if not overwritten by the encoder. Needs to be
10493 * done afterwards in case the encoder adjusts the mode. */
10494 if (!pipe_config
->port_clock
)
10495 pipe_config
->port_clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
10496 * pipe_config
->pixel_multiplier
;
10498 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
10500 DRM_DEBUG_KMS("CRTC fixup failed\n");
10504 if (ret
== RETRY
) {
10505 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
10510 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
10512 goto encoder_retry
;
10515 pipe_config
->dither
= pipe_config
->pipe_bpp
!= plane_bpp
;
10516 DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
10517 plane_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
10519 return pipe_config
;
10521 kfree(pipe_config
);
10522 return ERR_PTR(ret
);
10525 /* Computes which crtcs are affected and sets the relevant bits in the mask. For
10526 * simplicity we use the crtc's pipe number (because it's easier to obtain). */
10528 intel_modeset_affected_pipes(struct drm_crtc
*crtc
, unsigned *modeset_pipes
,
10529 unsigned *prepare_pipes
, unsigned *disable_pipes
)
10531 struct intel_crtc
*intel_crtc
;
10532 struct drm_device
*dev
= crtc
->dev
;
10533 struct intel_encoder
*encoder
;
10534 struct intel_connector
*connector
;
10535 struct drm_crtc
*tmp_crtc
;
10537 *disable_pipes
= *modeset_pipes
= *prepare_pipes
= 0;
10539 /* Check which crtcs have changed outputs connected to them, these need
10540 * to be part of the prepare_pipes mask. We don't (yet) support global
10541 * modeset across multiple crtcs, so modeset_pipes will only have one
10542 * bit set at most. */
10543 for_each_intel_connector(dev
, connector
) {
10544 if (connector
->base
.encoder
== &connector
->new_encoder
->base
)
10547 if (connector
->base
.encoder
) {
10548 tmp_crtc
= connector
->base
.encoder
->crtc
;
10550 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
10553 if (connector
->new_encoder
)
10555 1 << connector
->new_encoder
->new_crtc
->pipe
;
10558 for_each_intel_encoder(dev
, encoder
) {
10559 if (encoder
->base
.crtc
== &encoder
->new_crtc
->base
)
10562 if (encoder
->base
.crtc
) {
10563 tmp_crtc
= encoder
->base
.crtc
;
10565 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
10568 if (encoder
->new_crtc
)
10569 *prepare_pipes
|= 1 << encoder
->new_crtc
->pipe
;
10572 /* Check for pipes that will be enabled/disabled ... */
10573 for_each_intel_crtc(dev
, intel_crtc
) {
10574 if (intel_crtc
->base
.state
->enable
== intel_crtc
->new_enabled
)
10577 if (!intel_crtc
->new_enabled
)
10578 *disable_pipes
|= 1 << intel_crtc
->pipe
;
10580 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
10584 /* set_mode is also used to update properties on life display pipes. */
10585 intel_crtc
= to_intel_crtc(crtc
);
10586 if (intel_crtc
->new_enabled
)
10587 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
10590 * For simplicity do a full modeset on any pipe where the output routing
10591 * changed. We could be more clever, but that would require us to be
10592 * more careful with calling the relevant encoder->mode_set functions.
10594 if (*prepare_pipes
)
10595 *modeset_pipes
= *prepare_pipes
;
10597 /* ... and mask these out. */
10598 *modeset_pipes
&= ~(*disable_pipes
);
10599 *prepare_pipes
&= ~(*disable_pipes
);
10602 * HACK: We don't (yet) fully support global modesets. intel_set_config
10603 * obies this rule, but the modeset restore mode of
10604 * intel_modeset_setup_hw_state does not.
10606 *modeset_pipes
&= 1 << intel_crtc
->pipe
;
10607 *prepare_pipes
&= 1 << intel_crtc
->pipe
;
10609 DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
10610 *modeset_pipes
, *prepare_pipes
, *disable_pipes
);
10613 static bool intel_crtc_in_use(struct drm_crtc
*crtc
)
10615 struct drm_encoder
*encoder
;
10616 struct drm_device
*dev
= crtc
->dev
;
10618 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
10619 if (encoder
->crtc
== crtc
)
10626 intel_modeset_update_state(struct drm_device
*dev
, unsigned prepare_pipes
)
10628 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10629 struct intel_encoder
*intel_encoder
;
10630 struct intel_crtc
*intel_crtc
;
10631 struct drm_connector
*connector
;
10633 intel_shared_dpll_commit(dev_priv
);
10635 for_each_intel_encoder(dev
, intel_encoder
) {
10636 if (!intel_encoder
->base
.crtc
)
10639 intel_crtc
= to_intel_crtc(intel_encoder
->base
.crtc
);
10641 if (prepare_pipes
& (1 << intel_crtc
->pipe
))
10642 intel_encoder
->connectors_active
= false;
10645 intel_modeset_commit_output_state(dev
);
10647 /* Double check state. */
10648 for_each_intel_crtc(dev
, intel_crtc
) {
10649 WARN_ON(intel_crtc
->base
.state
->enable
!= intel_crtc_in_use(&intel_crtc
->base
));
10650 WARN_ON(intel_crtc
->new_config
&&
10651 intel_crtc
->new_config
!= intel_crtc
->config
);
10652 WARN_ON(intel_crtc
->base
.state
->enable
!= !!intel_crtc
->new_config
);
10655 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
10656 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
10659 intel_crtc
= to_intel_crtc(connector
->encoder
->crtc
);
10661 if (prepare_pipes
& (1 << intel_crtc
->pipe
)) {
10662 struct drm_property
*dpms_property
=
10663 dev
->mode_config
.dpms_property
;
10665 connector
->dpms
= DRM_MODE_DPMS_ON
;
10666 drm_object_property_set_value(&connector
->base
,
10670 intel_encoder
= to_intel_encoder(connector
->encoder
);
10671 intel_encoder
->connectors_active
= true;
10677 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
10681 if (clock1
== clock2
)
10684 if (!clock1
|| !clock2
)
10687 diff
= abs(clock1
- clock2
);
10689 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
10695 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
10696 list_for_each_entry((intel_crtc), \
10697 &(dev)->mode_config.crtc_list, \
10699 if (mask & (1 <<(intel_crtc)->pipe))
10702 intel_pipe_config_compare(struct drm_device
*dev
,
10703 struct intel_crtc_state
*current_config
,
10704 struct intel_crtc_state
*pipe_config
)
10706 #define PIPE_CONF_CHECK_X(name) \
10707 if (current_config->name != pipe_config->name) { \
10708 DRM_ERROR("mismatch in " #name " " \
10709 "(expected 0x%08x, found 0x%08x)\n", \
10710 current_config->name, \
10711 pipe_config->name); \
10715 #define PIPE_CONF_CHECK_I(name) \
10716 if (current_config->name != pipe_config->name) { \
10717 DRM_ERROR("mismatch in " #name " " \
10718 "(expected %i, found %i)\n", \
10719 current_config->name, \
10720 pipe_config->name); \
10724 /* This is required for BDW+ where there is only one set of registers for
10725 * switching between high and low RR.
10726 * This macro can be used whenever a comparison has to be made between one
10727 * hw state and multiple sw state variables.
10729 #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \
10730 if ((current_config->name != pipe_config->name) && \
10731 (current_config->alt_name != pipe_config->name)) { \
10732 DRM_ERROR("mismatch in " #name " " \
10733 "(expected %i or %i, found %i)\n", \
10734 current_config->name, \
10735 current_config->alt_name, \
10736 pipe_config->name); \
10740 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
10741 if ((current_config->name ^ pipe_config->name) & (mask)) { \
10742 DRM_ERROR("mismatch in " #name "(" #mask ") " \
10743 "(expected %i, found %i)\n", \
10744 current_config->name & (mask), \
10745 pipe_config->name & (mask)); \
10749 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
10750 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
10751 DRM_ERROR("mismatch in " #name " " \
10752 "(expected %i, found %i)\n", \
10753 current_config->name, \
10754 pipe_config->name); \
10758 #define PIPE_CONF_QUIRK(quirk) \
10759 ((current_config->quirks | pipe_config->quirks) & (quirk))
10761 PIPE_CONF_CHECK_I(cpu_transcoder
);
10763 PIPE_CONF_CHECK_I(has_pch_encoder
);
10764 PIPE_CONF_CHECK_I(fdi_lanes
);
10765 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_m
);
10766 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_n
);
10767 PIPE_CONF_CHECK_I(fdi_m_n
.link_m
);
10768 PIPE_CONF_CHECK_I(fdi_m_n
.link_n
);
10769 PIPE_CONF_CHECK_I(fdi_m_n
.tu
);
10771 PIPE_CONF_CHECK_I(has_dp_encoder
);
10773 if (INTEL_INFO(dev
)->gen
< 8) {
10774 PIPE_CONF_CHECK_I(dp_m_n
.gmch_m
);
10775 PIPE_CONF_CHECK_I(dp_m_n
.gmch_n
);
10776 PIPE_CONF_CHECK_I(dp_m_n
.link_m
);
10777 PIPE_CONF_CHECK_I(dp_m_n
.link_n
);
10778 PIPE_CONF_CHECK_I(dp_m_n
.tu
);
10780 if (current_config
->has_drrs
) {
10781 PIPE_CONF_CHECK_I(dp_m2_n2
.gmch_m
);
10782 PIPE_CONF_CHECK_I(dp_m2_n2
.gmch_n
);
10783 PIPE_CONF_CHECK_I(dp_m2_n2
.link_m
);
10784 PIPE_CONF_CHECK_I(dp_m2_n2
.link_n
);
10785 PIPE_CONF_CHECK_I(dp_m2_n2
.tu
);
10788 PIPE_CONF_CHECK_I_ALT(dp_m_n
.gmch_m
, dp_m2_n2
.gmch_m
);
10789 PIPE_CONF_CHECK_I_ALT(dp_m_n
.gmch_n
, dp_m2_n2
.gmch_n
);
10790 PIPE_CONF_CHECK_I_ALT(dp_m_n
.link_m
, dp_m2_n2
.link_m
);
10791 PIPE_CONF_CHECK_I_ALT(dp_m_n
.link_n
, dp_m2_n2
.link_n
);
10792 PIPE_CONF_CHECK_I_ALT(dp_m_n
.tu
, dp_m2_n2
.tu
);
10795 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hdisplay
);
10796 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_htotal
);
10797 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_start
);
10798 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_end
);
10799 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_start
);
10800 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_end
);
10802 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vdisplay
);
10803 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vtotal
);
10804 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_start
);
10805 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_end
);
10806 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_start
);
10807 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_end
);
10809 PIPE_CONF_CHECK_I(pixel_multiplier
);
10810 PIPE_CONF_CHECK_I(has_hdmi_sink
);
10811 if ((INTEL_INFO(dev
)->gen
< 8 && !IS_HASWELL(dev
)) ||
10812 IS_VALLEYVIEW(dev
))
10813 PIPE_CONF_CHECK_I(limited_color_range
);
10814 PIPE_CONF_CHECK_I(has_infoframe
);
10816 PIPE_CONF_CHECK_I(has_audio
);
10818 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
10819 DRM_MODE_FLAG_INTERLACE
);
10821 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
10822 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
10823 DRM_MODE_FLAG_PHSYNC
);
10824 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
10825 DRM_MODE_FLAG_NHSYNC
);
10826 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
10827 DRM_MODE_FLAG_PVSYNC
);
10828 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
10829 DRM_MODE_FLAG_NVSYNC
);
10832 PIPE_CONF_CHECK_I(pipe_src_w
);
10833 PIPE_CONF_CHECK_I(pipe_src_h
);
10836 * FIXME: BIOS likes to set up a cloned config with lvds+external
10837 * screen. Since we don't yet re-compute the pipe config when moving
10838 * just the lvds port away to another pipe the sw tracking won't match.
10840 * Proper atomic modesets with recomputed global state will fix this.
10841 * Until then just don't check gmch state for inherited modes.
10843 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE
)) {
10844 PIPE_CONF_CHECK_I(gmch_pfit
.control
);
10845 /* pfit ratios are autocomputed by the hw on gen4+ */
10846 if (INTEL_INFO(dev
)->gen
< 4)
10847 PIPE_CONF_CHECK_I(gmch_pfit
.pgm_ratios
);
10848 PIPE_CONF_CHECK_I(gmch_pfit
.lvds_border_bits
);
10851 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
10852 if (current_config
->pch_pfit
.enabled
) {
10853 PIPE_CONF_CHECK_I(pch_pfit
.pos
);
10854 PIPE_CONF_CHECK_I(pch_pfit
.size
);
10857 /* BDW+ don't expose a synchronous way to read the state */
10858 if (IS_HASWELL(dev
))
10859 PIPE_CONF_CHECK_I(ips_enabled
);
10861 PIPE_CONF_CHECK_I(double_wide
);
10863 PIPE_CONF_CHECK_X(ddi_pll_sel
);
10865 PIPE_CONF_CHECK_I(shared_dpll
);
10866 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
10867 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
10868 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
10869 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
10870 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
10871 PIPE_CONF_CHECK_X(dpll_hw_state
.ctrl1
);
10872 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr1
);
10873 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr2
);
10875 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5)
10876 PIPE_CONF_CHECK_I(pipe_bpp
);
10878 PIPE_CONF_CHECK_CLOCK_FUZZY(base
.adjusted_mode
.crtc_clock
);
10879 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
10881 #undef PIPE_CONF_CHECK_X
10882 #undef PIPE_CONF_CHECK_I
10883 #undef PIPE_CONF_CHECK_I_ALT
10884 #undef PIPE_CONF_CHECK_FLAGS
10885 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
10886 #undef PIPE_CONF_QUIRK
10891 static void check_wm_state(struct drm_device
*dev
)
10893 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10894 struct skl_ddb_allocation hw_ddb
, *sw_ddb
;
10895 struct intel_crtc
*intel_crtc
;
10898 if (INTEL_INFO(dev
)->gen
< 9)
10901 skl_ddb_get_hw_state(dev_priv
, &hw_ddb
);
10902 sw_ddb
= &dev_priv
->wm
.skl_hw
.ddb
;
10904 for_each_intel_crtc(dev
, intel_crtc
) {
10905 struct skl_ddb_entry
*hw_entry
, *sw_entry
;
10906 const enum pipe pipe
= intel_crtc
->pipe
;
10908 if (!intel_crtc
->active
)
10912 for_each_plane(dev_priv
, pipe
, plane
) {
10913 hw_entry
= &hw_ddb
.plane
[pipe
][plane
];
10914 sw_entry
= &sw_ddb
->plane
[pipe
][plane
];
10916 if (skl_ddb_entry_equal(hw_entry
, sw_entry
))
10919 DRM_ERROR("mismatch in DDB state pipe %c plane %d "
10920 "(expected (%u,%u), found (%u,%u))\n",
10921 pipe_name(pipe
), plane
+ 1,
10922 sw_entry
->start
, sw_entry
->end
,
10923 hw_entry
->start
, hw_entry
->end
);
10927 hw_entry
= &hw_ddb
.cursor
[pipe
];
10928 sw_entry
= &sw_ddb
->cursor
[pipe
];
10930 if (skl_ddb_entry_equal(hw_entry
, sw_entry
))
10933 DRM_ERROR("mismatch in DDB state pipe %c cursor "
10934 "(expected (%u,%u), found (%u,%u))\n",
10936 sw_entry
->start
, sw_entry
->end
,
10937 hw_entry
->start
, hw_entry
->end
);
10942 check_connector_state(struct drm_device
*dev
)
10944 struct intel_connector
*connector
;
10946 for_each_intel_connector(dev
, connector
) {
10947 /* This also checks the encoder/connector hw state with the
10948 * ->get_hw_state callbacks. */
10949 intel_connector_check_state(connector
);
10951 I915_STATE_WARN(&connector
->new_encoder
->base
!= connector
->base
.encoder
,
10952 "connector's staged encoder doesn't match current encoder\n");
10957 check_encoder_state(struct drm_device
*dev
)
10959 struct intel_encoder
*encoder
;
10960 struct intel_connector
*connector
;
10962 for_each_intel_encoder(dev
, encoder
) {
10963 bool enabled
= false;
10964 bool active
= false;
10965 enum pipe pipe
, tracked_pipe
;
10967 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
10968 encoder
->base
.base
.id
,
10969 encoder
->base
.name
);
10971 I915_STATE_WARN(&encoder
->new_crtc
->base
!= encoder
->base
.crtc
,
10972 "encoder's stage crtc doesn't match current crtc\n");
10973 I915_STATE_WARN(encoder
->connectors_active
&& !encoder
->base
.crtc
,
10974 "encoder's active_connectors set, but no crtc\n");
10976 for_each_intel_connector(dev
, connector
) {
10977 if (connector
->base
.encoder
!= &encoder
->base
)
10980 if (connector
->base
.dpms
!= DRM_MODE_DPMS_OFF
)
10984 * for MST connectors if we unplug the connector is gone
10985 * away but the encoder is still connected to a crtc
10986 * until a modeset happens in response to the hotplug.
10988 if (!enabled
&& encoder
->base
.encoder_type
== DRM_MODE_ENCODER_DPMST
)
10991 I915_STATE_WARN(!!encoder
->base
.crtc
!= enabled
,
10992 "encoder's enabled state mismatch "
10993 "(expected %i, found %i)\n",
10994 !!encoder
->base
.crtc
, enabled
);
10995 I915_STATE_WARN(active
&& !encoder
->base
.crtc
,
10996 "active encoder with no crtc\n");
10998 I915_STATE_WARN(encoder
->connectors_active
!= active
,
10999 "encoder's computed active state doesn't match tracked active state "
11000 "(expected %i, found %i)\n", active
, encoder
->connectors_active
);
11002 active
= encoder
->get_hw_state(encoder
, &pipe
);
11003 I915_STATE_WARN(active
!= encoder
->connectors_active
,
11004 "encoder's hw state doesn't match sw tracking "
11005 "(expected %i, found %i)\n",
11006 encoder
->connectors_active
, active
);
11008 if (!encoder
->base
.crtc
)
11011 tracked_pipe
= to_intel_crtc(encoder
->base
.crtc
)->pipe
;
11012 I915_STATE_WARN(active
&& pipe
!= tracked_pipe
,
11013 "active encoder's pipe doesn't match"
11014 "(expected %i, found %i)\n",
11015 tracked_pipe
, pipe
);
11021 check_crtc_state(struct drm_device
*dev
)
11023 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11024 struct intel_crtc
*crtc
;
11025 struct intel_encoder
*encoder
;
11026 struct intel_crtc_state pipe_config
;
11028 for_each_intel_crtc(dev
, crtc
) {
11029 bool enabled
= false;
11030 bool active
= false;
11032 memset(&pipe_config
, 0, sizeof(pipe_config
));
11034 DRM_DEBUG_KMS("[CRTC:%d]\n",
11035 crtc
->base
.base
.id
);
11037 I915_STATE_WARN(crtc
->active
&& !crtc
->base
.state
->enable
,
11038 "active crtc, but not enabled in sw tracking\n");
11040 for_each_intel_encoder(dev
, encoder
) {
11041 if (encoder
->base
.crtc
!= &crtc
->base
)
11044 if (encoder
->connectors_active
)
11048 I915_STATE_WARN(active
!= crtc
->active
,
11049 "crtc's computed active state doesn't match tracked active state "
11050 "(expected %i, found %i)\n", active
, crtc
->active
);
11051 I915_STATE_WARN(enabled
!= crtc
->base
.state
->enable
,
11052 "crtc's computed enabled state doesn't match tracked enabled state "
11053 "(expected %i, found %i)\n", enabled
,
11054 crtc
->base
.state
->enable
);
11056 active
= dev_priv
->display
.get_pipe_config(crtc
,
11059 /* hw state is inconsistent with the pipe quirk */
11060 if ((crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
11061 (crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
11062 active
= crtc
->active
;
11064 for_each_intel_encoder(dev
, encoder
) {
11066 if (encoder
->base
.crtc
!= &crtc
->base
)
11068 if (encoder
->get_hw_state(encoder
, &pipe
))
11069 encoder
->get_config(encoder
, &pipe_config
);
11072 I915_STATE_WARN(crtc
->active
!= active
,
11073 "crtc active state doesn't match with hw state "
11074 "(expected %i, found %i)\n", crtc
->active
, active
);
11077 !intel_pipe_config_compare(dev
, crtc
->config
, &pipe_config
)) {
11078 I915_STATE_WARN(1, "pipe state doesn't match!\n");
11079 intel_dump_pipe_config(crtc
, &pipe_config
,
11081 intel_dump_pipe_config(crtc
, crtc
->config
,
11088 check_shared_dpll_state(struct drm_device
*dev
)
11090 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11091 struct intel_crtc
*crtc
;
11092 struct intel_dpll_hw_state dpll_hw_state
;
11095 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
11096 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
11097 int enabled_crtcs
= 0, active_crtcs
= 0;
11100 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
11102 DRM_DEBUG_KMS("%s\n", pll
->name
);
11104 active
= pll
->get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
11106 I915_STATE_WARN(pll
->active
> hweight32(pll
->config
.crtc_mask
),
11107 "more active pll users than references: %i vs %i\n",
11108 pll
->active
, hweight32(pll
->config
.crtc_mask
));
11109 I915_STATE_WARN(pll
->active
&& !pll
->on
,
11110 "pll in active use but not on in sw tracking\n");
11111 I915_STATE_WARN(pll
->on
&& !pll
->active
,
11112 "pll in on but not on in use in sw tracking\n");
11113 I915_STATE_WARN(pll
->on
!= active
,
11114 "pll on state mismatch (expected %i, found %i)\n",
11117 for_each_intel_crtc(dev
, crtc
) {
11118 if (crtc
->base
.state
->enable
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
11120 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
11123 I915_STATE_WARN(pll
->active
!= active_crtcs
,
11124 "pll active crtcs mismatch (expected %i, found %i)\n",
11125 pll
->active
, active_crtcs
);
11126 I915_STATE_WARN(hweight32(pll
->config
.crtc_mask
) != enabled_crtcs
,
11127 "pll enabled crtcs mismatch (expected %i, found %i)\n",
11128 hweight32(pll
->config
.crtc_mask
), enabled_crtcs
);
11130 I915_STATE_WARN(pll
->on
&& memcmp(&pll
->config
.hw_state
, &dpll_hw_state
,
11131 sizeof(dpll_hw_state
)),
11132 "pll hw state mismatch\n");
11137 intel_modeset_check_state(struct drm_device
*dev
)
11139 check_wm_state(dev
);
11140 check_connector_state(dev
);
11141 check_encoder_state(dev
);
11142 check_crtc_state(dev
);
11143 check_shared_dpll_state(dev
);
11146 void ironlake_check_encoder_dotclock(const struct intel_crtc_state
*pipe_config
,
11150 * FDI already provided one idea for the dotclock.
11151 * Yell if the encoder disagrees.
11153 WARN(!intel_fuzzy_clock_check(pipe_config
->base
.adjusted_mode
.crtc_clock
, dotclock
),
11154 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11155 pipe_config
->base
.adjusted_mode
.crtc_clock
, dotclock
);
11158 static void update_scanline_offset(struct intel_crtc
*crtc
)
11160 struct drm_device
*dev
= crtc
->base
.dev
;
11163 * The scanline counter increments at the leading edge of hsync.
11165 * On most platforms it starts counting from vtotal-1 on the
11166 * first active line. That means the scanline counter value is
11167 * always one less than what we would expect. Ie. just after
11168 * start of vblank, which also occurs at start of hsync (on the
11169 * last active line), the scanline counter will read vblank_start-1.
11171 * On gen2 the scanline counter starts counting from 1 instead
11172 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
11173 * to keep the value positive), instead of adding one.
11175 * On HSW+ the behaviour of the scanline counter depends on the output
11176 * type. For DP ports it behaves like most other platforms, but on HDMI
11177 * there's an extra 1 line difference. So we need to add two instead of
11178 * one to the value.
11180 if (IS_GEN2(dev
)) {
11181 const struct drm_display_mode
*mode
= &crtc
->config
->base
.adjusted_mode
;
11184 vtotal
= mode
->crtc_vtotal
;
11185 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
11188 crtc
->scanline_offset
= vtotal
- 1;
11189 } else if (HAS_DDI(dev
) &&
11190 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
)) {
11191 crtc
->scanline_offset
= 2;
11193 crtc
->scanline_offset
= 1;
11196 static struct intel_crtc_state
*
11197 intel_modeset_compute_config(struct drm_crtc
*crtc
,
11198 struct drm_display_mode
*mode
,
11199 struct drm_framebuffer
*fb
,
11200 unsigned *modeset_pipes
,
11201 unsigned *prepare_pipes
,
11202 unsigned *disable_pipes
)
11204 struct intel_crtc_state
*pipe_config
= NULL
;
11206 intel_modeset_affected_pipes(crtc
, modeset_pipes
,
11207 prepare_pipes
, disable_pipes
);
11209 if ((*modeset_pipes
) == 0)
11213 * Note this needs changes when we start tracking multiple modes
11214 * and crtcs. At that point we'll need to compute the whole config
11215 * (i.e. one pipe_config for each crtc) rather than just the one
11218 pipe_config
= intel_modeset_pipe_config(crtc
, fb
, mode
);
11219 if (IS_ERR(pipe_config
)) {
11222 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
11226 return pipe_config
;
11229 static int __intel_set_mode_setup_plls(struct drm_device
*dev
,
11230 unsigned modeset_pipes
,
11231 unsigned disable_pipes
)
11233 struct drm_i915_private
*dev_priv
= to_i915(dev
);
11234 unsigned clear_pipes
= modeset_pipes
| disable_pipes
;
11235 struct intel_crtc
*intel_crtc
;
11238 if (!dev_priv
->display
.crtc_compute_clock
)
11241 ret
= intel_shared_dpll_start_config(dev_priv
, clear_pipes
);
11245 for_each_intel_crtc_masked(dev
, modeset_pipes
, intel_crtc
) {
11246 struct intel_crtc_state
*state
= intel_crtc
->new_config
;
11247 ret
= dev_priv
->display
.crtc_compute_clock(intel_crtc
,
11250 intel_shared_dpll_abort_config(dev_priv
);
11259 static int __intel_set_mode(struct drm_crtc
*crtc
,
11260 struct drm_display_mode
*mode
,
11261 int x
, int y
, struct drm_framebuffer
*fb
,
11262 struct intel_crtc_state
*pipe_config
,
11263 unsigned modeset_pipes
,
11264 unsigned prepare_pipes
,
11265 unsigned disable_pipes
)
11267 struct drm_device
*dev
= crtc
->dev
;
11268 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11269 struct drm_display_mode
*saved_mode
;
11270 struct intel_crtc
*intel_crtc
;
11273 saved_mode
= kmalloc(sizeof(*saved_mode
), GFP_KERNEL
);
11277 *saved_mode
= crtc
->mode
;
11280 to_intel_crtc(crtc
)->new_config
= pipe_config
;
11283 * See if the config requires any additional preparation, e.g.
11284 * to adjust global state with pipes off. We need to do this
11285 * here so we can get the modeset_pipe updated config for the new
11286 * mode set on this crtc. For other crtcs we need to use the
11287 * adjusted_mode bits in the crtc directly.
11289 if (IS_VALLEYVIEW(dev
)) {
11290 valleyview_modeset_global_pipes(dev
, &prepare_pipes
);
11292 /* may have added more to prepare_pipes than we should */
11293 prepare_pipes
&= ~disable_pipes
;
11296 ret
= __intel_set_mode_setup_plls(dev
, modeset_pipes
, disable_pipes
);
11300 for_each_intel_crtc_masked(dev
, disable_pipes
, intel_crtc
)
11301 intel_crtc_disable(&intel_crtc
->base
);
11303 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
11304 if (intel_crtc
->base
.state
->enable
)
11305 dev_priv
->display
.crtc_disable(&intel_crtc
->base
);
11308 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
11309 * to set it here already despite that we pass it down the callchain.
11311 * Note we'll need to fix this up when we start tracking multiple
11312 * pipes; here we assume a single modeset_pipe and only track the
11313 * single crtc and mode.
11315 if (modeset_pipes
) {
11316 crtc
->mode
= *mode
;
11317 /* mode_set/enable/disable functions rely on a correct pipe
11319 intel_crtc_set_state(to_intel_crtc(crtc
), pipe_config
);
11322 * Calculate and store various constants which
11323 * are later needed by vblank and swap-completion
11324 * timestamping. They are derived from true hwmode.
11326 drm_calc_timestamping_constants(crtc
,
11327 &pipe_config
->base
.adjusted_mode
);
11330 /* Only after disabling all output pipelines that will be changed can we
11331 * update the the output configuration. */
11332 intel_modeset_update_state(dev
, prepare_pipes
);
11334 modeset_update_crtc_power_domains(dev
);
11336 /* Set up the DPLL and any encoders state that needs to adjust or depend
11339 for_each_intel_crtc_masked(dev
, modeset_pipes
, intel_crtc
) {
11340 struct drm_plane
*primary
= intel_crtc
->base
.primary
;
11341 int vdisplay
, hdisplay
;
11343 drm_crtc_get_hv_timing(mode
, &hdisplay
, &vdisplay
);
11344 ret
= primary
->funcs
->update_plane(primary
, &intel_crtc
->base
,
11346 hdisplay
, vdisplay
,
11348 hdisplay
<< 16, vdisplay
<< 16);
11351 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
11352 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
11353 update_scanline_offset(intel_crtc
);
11355 dev_priv
->display
.crtc_enable(&intel_crtc
->base
);
11358 /* FIXME: add subpixel order */
11360 if (ret
&& crtc
->state
->enable
)
11361 crtc
->mode
= *saved_mode
;
11367 static int intel_set_mode_pipes(struct drm_crtc
*crtc
,
11368 struct drm_display_mode
*mode
,
11369 int x
, int y
, struct drm_framebuffer
*fb
,
11370 struct intel_crtc_state
*pipe_config
,
11371 unsigned modeset_pipes
,
11372 unsigned prepare_pipes
,
11373 unsigned disable_pipes
)
11377 ret
= __intel_set_mode(crtc
, mode
, x
, y
, fb
, pipe_config
, modeset_pipes
,
11378 prepare_pipes
, disable_pipes
);
11381 intel_modeset_check_state(crtc
->dev
);
11386 static int intel_set_mode(struct drm_crtc
*crtc
,
11387 struct drm_display_mode
*mode
,
11388 int x
, int y
, struct drm_framebuffer
*fb
)
11390 struct intel_crtc_state
*pipe_config
;
11391 unsigned modeset_pipes
, prepare_pipes
, disable_pipes
;
11393 pipe_config
= intel_modeset_compute_config(crtc
, mode
, fb
,
11398 if (IS_ERR(pipe_config
))
11399 return PTR_ERR(pipe_config
);
11401 return intel_set_mode_pipes(crtc
, mode
, x
, y
, fb
, pipe_config
,
11402 modeset_pipes
, prepare_pipes
,
11406 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
11408 intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
, crtc
->primary
->fb
);
11411 #undef for_each_intel_crtc_masked
11413 static void intel_set_config_free(struct intel_set_config
*config
)
11418 kfree(config
->save_connector_encoders
);
11419 kfree(config
->save_encoder_crtcs
);
11420 kfree(config
->save_crtc_enabled
);
11424 static int intel_set_config_save_state(struct drm_device
*dev
,
11425 struct intel_set_config
*config
)
11427 struct drm_crtc
*crtc
;
11428 struct drm_encoder
*encoder
;
11429 struct drm_connector
*connector
;
11432 config
->save_crtc_enabled
=
11433 kcalloc(dev
->mode_config
.num_crtc
,
11434 sizeof(bool), GFP_KERNEL
);
11435 if (!config
->save_crtc_enabled
)
11438 config
->save_encoder_crtcs
=
11439 kcalloc(dev
->mode_config
.num_encoder
,
11440 sizeof(struct drm_crtc
*), GFP_KERNEL
);
11441 if (!config
->save_encoder_crtcs
)
11444 config
->save_connector_encoders
=
11445 kcalloc(dev
->mode_config
.num_connector
,
11446 sizeof(struct drm_encoder
*), GFP_KERNEL
);
11447 if (!config
->save_connector_encoders
)
11450 /* Copy data. Note that driver private data is not affected.
11451 * Should anything bad happen only the expected state is
11452 * restored, not the drivers personal bookkeeping.
11455 for_each_crtc(dev
, crtc
) {
11456 config
->save_crtc_enabled
[count
++] = crtc
->state
->enable
;
11460 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
11461 config
->save_encoder_crtcs
[count
++] = encoder
->crtc
;
11465 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
11466 config
->save_connector_encoders
[count
++] = connector
->encoder
;
11472 static void intel_set_config_restore_state(struct drm_device
*dev
,
11473 struct intel_set_config
*config
)
11475 struct intel_crtc
*crtc
;
11476 struct intel_encoder
*encoder
;
11477 struct intel_connector
*connector
;
11481 for_each_intel_crtc(dev
, crtc
) {
11482 crtc
->new_enabled
= config
->save_crtc_enabled
[count
++];
11484 if (crtc
->new_enabled
)
11485 crtc
->new_config
= crtc
->config
;
11487 crtc
->new_config
= NULL
;
11491 for_each_intel_encoder(dev
, encoder
) {
11492 encoder
->new_crtc
=
11493 to_intel_crtc(config
->save_encoder_crtcs
[count
++]);
11497 for_each_intel_connector(dev
, connector
) {
11498 connector
->new_encoder
=
11499 to_intel_encoder(config
->save_connector_encoders
[count
++]);
11504 is_crtc_connector_off(struct drm_mode_set
*set
)
11508 if (set
->num_connectors
== 0)
11511 if (WARN_ON(set
->connectors
== NULL
))
11514 for (i
= 0; i
< set
->num_connectors
; i
++)
11515 if (set
->connectors
[i
]->encoder
&&
11516 set
->connectors
[i
]->encoder
->crtc
== set
->crtc
&&
11517 set
->connectors
[i
]->dpms
!= DRM_MODE_DPMS_ON
)
11524 intel_set_config_compute_mode_changes(struct drm_mode_set
*set
,
11525 struct intel_set_config
*config
)
11528 /* We should be able to check here if the fb has the same properties
11529 * and then just flip_or_move it */
11530 if (is_crtc_connector_off(set
)) {
11531 config
->mode_changed
= true;
11532 } else if (set
->crtc
->primary
->fb
!= set
->fb
) {
11534 * If we have no fb, we can only flip as long as the crtc is
11535 * active, otherwise we need a full mode set. The crtc may
11536 * be active if we've only disabled the primary plane, or
11537 * in fastboot situations.
11539 if (set
->crtc
->primary
->fb
== NULL
) {
11540 struct intel_crtc
*intel_crtc
=
11541 to_intel_crtc(set
->crtc
);
11543 if (intel_crtc
->active
) {
11544 DRM_DEBUG_KMS("crtc has no fb, will flip\n");
11545 config
->fb_changed
= true;
11547 DRM_DEBUG_KMS("inactive crtc, full mode set\n");
11548 config
->mode_changed
= true;
11550 } else if (set
->fb
== NULL
) {
11551 config
->mode_changed
= true;
11552 } else if (set
->fb
->pixel_format
!=
11553 set
->crtc
->primary
->fb
->pixel_format
) {
11554 config
->mode_changed
= true;
11556 config
->fb_changed
= true;
11560 if (set
->fb
&& (set
->x
!= set
->crtc
->x
|| set
->y
!= set
->crtc
->y
))
11561 config
->fb_changed
= true;
11563 if (set
->mode
&& !drm_mode_equal(set
->mode
, &set
->crtc
->mode
)) {
11564 DRM_DEBUG_KMS("modes are different, full mode set\n");
11565 drm_mode_debug_printmodeline(&set
->crtc
->mode
);
11566 drm_mode_debug_printmodeline(set
->mode
);
11567 config
->mode_changed
= true;
11570 DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
11571 set
->crtc
->base
.id
, config
->mode_changed
, config
->fb_changed
);
11575 intel_modeset_stage_output_state(struct drm_device
*dev
,
11576 struct drm_mode_set
*set
,
11577 struct intel_set_config
*config
)
11579 struct intel_connector
*connector
;
11580 struct intel_encoder
*encoder
;
11581 struct intel_crtc
*crtc
;
11584 /* The upper layers ensure that we either disable a crtc or have a list
11585 * of connectors. For paranoia, double-check this. */
11586 WARN_ON(!set
->fb
&& (set
->num_connectors
!= 0));
11587 WARN_ON(set
->fb
&& (set
->num_connectors
== 0));
11589 for_each_intel_connector(dev
, connector
) {
11590 /* Otherwise traverse passed in connector list and get encoders
11592 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
11593 if (set
->connectors
[ro
] == &connector
->base
) {
11594 connector
->new_encoder
= intel_find_encoder(connector
, to_intel_crtc(set
->crtc
)->pipe
);
11599 /* If we disable the crtc, disable all its connectors. Also, if
11600 * the connector is on the changing crtc but not on the new
11601 * connector list, disable it. */
11602 if ((!set
->fb
|| ro
== set
->num_connectors
) &&
11603 connector
->base
.encoder
&&
11604 connector
->base
.encoder
->crtc
== set
->crtc
) {
11605 connector
->new_encoder
= NULL
;
11607 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
11608 connector
->base
.base
.id
,
11609 connector
->base
.name
);
11613 if (&connector
->new_encoder
->base
!= connector
->base
.encoder
) {
11614 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] encoder changed, full mode switch\n",
11615 connector
->base
.base
.id
,
11616 connector
->base
.name
);
11617 config
->mode_changed
= true;
11620 /* connector->new_encoder is now updated for all connectors. */
11622 /* Update crtc of enabled connectors. */
11623 for_each_intel_connector(dev
, connector
) {
11624 struct drm_crtc
*new_crtc
;
11626 if (!connector
->new_encoder
)
11629 new_crtc
= connector
->new_encoder
->base
.crtc
;
11631 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
11632 if (set
->connectors
[ro
] == &connector
->base
)
11633 new_crtc
= set
->crtc
;
11636 /* Make sure the new CRTC will work with the encoder */
11637 if (!drm_encoder_crtc_ok(&connector
->new_encoder
->base
,
11641 connector
->new_encoder
->new_crtc
= to_intel_crtc(new_crtc
);
11643 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
11644 connector
->base
.base
.id
,
11645 connector
->base
.name
,
11646 new_crtc
->base
.id
);
11649 /* Check for any encoders that needs to be disabled. */
11650 for_each_intel_encoder(dev
, encoder
) {
11651 int num_connectors
= 0;
11652 for_each_intel_connector(dev
, connector
) {
11653 if (connector
->new_encoder
== encoder
) {
11654 WARN_ON(!connector
->new_encoder
->new_crtc
);
11659 if (num_connectors
== 0)
11660 encoder
->new_crtc
= NULL
;
11661 else if (num_connectors
> 1)
11664 /* Only now check for crtc changes so we don't miss encoders
11665 * that will be disabled. */
11666 if (&encoder
->new_crtc
->base
!= encoder
->base
.crtc
) {
11667 DRM_DEBUG_KMS("[ENCODER:%d:%s] crtc changed, full mode switch\n",
11668 encoder
->base
.base
.id
,
11669 encoder
->base
.name
);
11670 config
->mode_changed
= true;
11673 /* Now we've also updated encoder->new_crtc for all encoders. */
11674 for_each_intel_connector(dev
, connector
) {
11675 if (connector
->new_encoder
)
11676 if (connector
->new_encoder
!= connector
->encoder
)
11677 connector
->encoder
= connector
->new_encoder
;
11679 for_each_intel_crtc(dev
, crtc
) {
11680 crtc
->new_enabled
= false;
11682 for_each_intel_encoder(dev
, encoder
) {
11683 if (encoder
->new_crtc
== crtc
) {
11684 crtc
->new_enabled
= true;
11689 if (crtc
->new_enabled
!= crtc
->base
.state
->enable
) {
11690 DRM_DEBUG_KMS("[CRTC:%d] %sabled, full mode switch\n",
11691 crtc
->base
.base
.id
,
11692 crtc
->new_enabled
? "en" : "dis");
11693 config
->mode_changed
= true;
11696 if (crtc
->new_enabled
)
11697 crtc
->new_config
= crtc
->config
;
11699 crtc
->new_config
= NULL
;
11705 static void disable_crtc_nofb(struct intel_crtc
*crtc
)
11707 struct drm_device
*dev
= crtc
->base
.dev
;
11708 struct intel_encoder
*encoder
;
11709 struct intel_connector
*connector
;
11711 DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
11712 pipe_name(crtc
->pipe
));
11714 for_each_intel_connector(dev
, connector
) {
11715 if (connector
->new_encoder
&&
11716 connector
->new_encoder
->new_crtc
== crtc
)
11717 connector
->new_encoder
= NULL
;
11720 for_each_intel_encoder(dev
, encoder
) {
11721 if (encoder
->new_crtc
== crtc
)
11722 encoder
->new_crtc
= NULL
;
11725 crtc
->new_enabled
= false;
11726 crtc
->new_config
= NULL
;
11729 static int intel_crtc_set_config(struct drm_mode_set
*set
)
11731 struct drm_device
*dev
;
11732 struct drm_mode_set save_set
;
11733 struct intel_set_config
*config
;
11734 struct intel_crtc_state
*pipe_config
;
11735 unsigned modeset_pipes
, prepare_pipes
, disable_pipes
;
11739 BUG_ON(!set
->crtc
);
11740 BUG_ON(!set
->crtc
->helper_private
);
11742 /* Enforce sane interface api - has been abused by the fb helper. */
11743 BUG_ON(!set
->mode
&& set
->fb
);
11744 BUG_ON(set
->fb
&& set
->num_connectors
== 0);
11747 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
11748 set
->crtc
->base
.id
, set
->fb
->base
.id
,
11749 (int)set
->num_connectors
, set
->x
, set
->y
);
11751 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set
->crtc
->base
.id
);
11754 dev
= set
->crtc
->dev
;
11757 config
= kzalloc(sizeof(*config
), GFP_KERNEL
);
11761 ret
= intel_set_config_save_state(dev
, config
);
11765 save_set
.crtc
= set
->crtc
;
11766 save_set
.mode
= &set
->crtc
->mode
;
11767 save_set
.x
= set
->crtc
->x
;
11768 save_set
.y
= set
->crtc
->y
;
11769 save_set
.fb
= set
->crtc
->primary
->fb
;
11771 /* Compute whether we need a full modeset, only an fb base update or no
11772 * change at all. In the future we might also check whether only the
11773 * mode changed, e.g. for LVDS where we only change the panel fitter in
11775 intel_set_config_compute_mode_changes(set
, config
);
11777 ret
= intel_modeset_stage_output_state(dev
, set
, config
);
11781 pipe_config
= intel_modeset_compute_config(set
->crtc
, set
->mode
,
11786 if (IS_ERR(pipe_config
)) {
11787 ret
= PTR_ERR(pipe_config
);
11789 } else if (pipe_config
) {
11790 if (pipe_config
->has_audio
!=
11791 to_intel_crtc(set
->crtc
)->config
->has_audio
)
11792 config
->mode_changed
= true;
11795 * Note we have an issue here with infoframes: current code
11796 * only updates them on the full mode set path per hw
11797 * requirements. So here we should be checking for any
11798 * required changes and forcing a mode set.
11802 /* set_mode will free it in the mode_changed case */
11803 if (!config
->mode_changed
)
11804 kfree(pipe_config
);
11806 intel_update_pipe_size(to_intel_crtc(set
->crtc
));
11808 if (config
->mode_changed
) {
11809 ret
= intel_set_mode_pipes(set
->crtc
, set
->mode
,
11810 set
->x
, set
->y
, set
->fb
, pipe_config
,
11811 modeset_pipes
, prepare_pipes
,
11813 } else if (config
->fb_changed
) {
11814 struct intel_crtc
*intel_crtc
= to_intel_crtc(set
->crtc
);
11815 struct drm_plane
*primary
= set
->crtc
->primary
;
11816 int vdisplay
, hdisplay
;
11818 drm_crtc_get_hv_timing(set
->mode
, &hdisplay
, &vdisplay
);
11819 ret
= primary
->funcs
->update_plane(primary
, set
->crtc
, set
->fb
,
11820 0, 0, hdisplay
, vdisplay
,
11821 set
->x
<< 16, set
->y
<< 16,
11822 hdisplay
<< 16, vdisplay
<< 16);
11825 * We need to make sure the primary plane is re-enabled if it
11826 * has previously been turned off.
11828 if (!intel_crtc
->primary_enabled
&& ret
== 0) {
11829 WARN_ON(!intel_crtc
->active
);
11830 intel_enable_primary_hw_plane(set
->crtc
->primary
, set
->crtc
);
11834 * In the fastboot case this may be our only check of the
11835 * state after boot. It would be better to only do it on
11836 * the first update, but we don't have a nice way of doing that
11837 * (and really, set_config isn't used much for high freq page
11838 * flipping, so increasing its cost here shouldn't be a big
11841 if (i915
.fastboot
&& ret
== 0)
11842 intel_modeset_check_state(set
->crtc
->dev
);
11846 DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
11847 set
->crtc
->base
.id
, ret
);
11849 intel_set_config_restore_state(dev
, config
);
11852 * HACK: if the pipe was on, but we didn't have a framebuffer,
11853 * force the pipe off to avoid oopsing in the modeset code
11854 * due to fb==NULL. This should only happen during boot since
11855 * we don't yet reconstruct the FB from the hardware state.
11857 if (to_intel_crtc(save_set
.crtc
)->new_enabled
&& !save_set
.fb
)
11858 disable_crtc_nofb(to_intel_crtc(save_set
.crtc
));
11860 /* Try to restore the config */
11861 if (config
->mode_changed
&&
11862 intel_set_mode(save_set
.crtc
, save_set
.mode
,
11863 save_set
.x
, save_set
.y
, save_set
.fb
))
11864 DRM_ERROR("failed to restore config after modeset failure\n");
11868 intel_set_config_free(config
);
11872 static const struct drm_crtc_funcs intel_crtc_funcs
= {
11873 .gamma_set
= intel_crtc_gamma_set
,
11874 .set_config
= intel_crtc_set_config
,
11875 .destroy
= intel_crtc_destroy
,
11876 .page_flip
= intel_crtc_page_flip
,
11877 .atomic_duplicate_state
= intel_crtc_duplicate_state
,
11878 .atomic_destroy_state
= intel_crtc_destroy_state
,
11881 static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private
*dev_priv
,
11882 struct intel_shared_dpll
*pll
,
11883 struct intel_dpll_hw_state
*hw_state
)
11887 if (!intel_display_power_is_enabled(dev_priv
, POWER_DOMAIN_PLLS
))
11890 val
= I915_READ(PCH_DPLL(pll
->id
));
11891 hw_state
->dpll
= val
;
11892 hw_state
->fp0
= I915_READ(PCH_FP0(pll
->id
));
11893 hw_state
->fp1
= I915_READ(PCH_FP1(pll
->id
));
11895 return val
& DPLL_VCO_ENABLE
;
11898 static void ibx_pch_dpll_mode_set(struct drm_i915_private
*dev_priv
,
11899 struct intel_shared_dpll
*pll
)
11901 I915_WRITE(PCH_FP0(pll
->id
), pll
->config
.hw_state
.fp0
);
11902 I915_WRITE(PCH_FP1(pll
->id
), pll
->config
.hw_state
.fp1
);
11905 static void ibx_pch_dpll_enable(struct drm_i915_private
*dev_priv
,
11906 struct intel_shared_dpll
*pll
)
11908 /* PCH refclock must be enabled first */
11909 ibx_assert_pch_refclk_enabled(dev_priv
);
11911 I915_WRITE(PCH_DPLL(pll
->id
), pll
->config
.hw_state
.dpll
);
11913 /* Wait for the clocks to stabilize. */
11914 POSTING_READ(PCH_DPLL(pll
->id
));
11917 /* The pixel multiplier can only be updated once the
11918 * DPLL is enabled and the clocks are stable.
11920 * So write it again.
11922 I915_WRITE(PCH_DPLL(pll
->id
), pll
->config
.hw_state
.dpll
);
11923 POSTING_READ(PCH_DPLL(pll
->id
));
11927 static void ibx_pch_dpll_disable(struct drm_i915_private
*dev_priv
,
11928 struct intel_shared_dpll
*pll
)
11930 struct drm_device
*dev
= dev_priv
->dev
;
11931 struct intel_crtc
*crtc
;
11933 /* Make sure no transcoder isn't still depending on us. */
11934 for_each_intel_crtc(dev
, crtc
) {
11935 if (intel_crtc_to_shared_dpll(crtc
) == pll
)
11936 assert_pch_transcoder_disabled(dev_priv
, crtc
->pipe
);
11939 I915_WRITE(PCH_DPLL(pll
->id
), 0);
11940 POSTING_READ(PCH_DPLL(pll
->id
));
11944 static char *ibx_pch_dpll_names
[] = {
11949 static void ibx_pch_dpll_init(struct drm_device
*dev
)
11951 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11954 dev_priv
->num_shared_dpll
= 2;
11956 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
11957 dev_priv
->shared_dplls
[i
].id
= i
;
11958 dev_priv
->shared_dplls
[i
].name
= ibx_pch_dpll_names
[i
];
11959 dev_priv
->shared_dplls
[i
].mode_set
= ibx_pch_dpll_mode_set
;
11960 dev_priv
->shared_dplls
[i
].enable
= ibx_pch_dpll_enable
;
11961 dev_priv
->shared_dplls
[i
].disable
= ibx_pch_dpll_disable
;
11962 dev_priv
->shared_dplls
[i
].get_hw_state
=
11963 ibx_pch_dpll_get_hw_state
;
11967 static void intel_shared_dpll_init(struct drm_device
*dev
)
11969 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11972 intel_ddi_pll_init(dev
);
11973 else if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
11974 ibx_pch_dpll_init(dev
);
11976 dev_priv
->num_shared_dpll
= 0;
11978 BUG_ON(dev_priv
->num_shared_dpll
> I915_NUM_PLLS
);
11982 * intel_prepare_plane_fb - Prepare fb for usage on plane
11983 * @plane: drm plane to prepare for
11984 * @fb: framebuffer to prepare for presentation
11986 * Prepares a framebuffer for usage on a display plane. Generally this
11987 * involves pinning the underlying object and updating the frontbuffer tracking
11988 * bits. Some older platforms need special physical address handling for
11991 * Returns 0 on success, negative error code on failure.
11994 intel_prepare_plane_fb(struct drm_plane
*plane
,
11995 struct drm_framebuffer
*fb
,
11996 const struct drm_plane_state
*new_state
)
11998 struct drm_device
*dev
= plane
->dev
;
11999 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
12000 enum pipe pipe
= intel_plane
->pipe
;
12001 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
12002 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->fb
);
12003 unsigned frontbuffer_bits
= 0;
12009 switch (plane
->type
) {
12010 case DRM_PLANE_TYPE_PRIMARY
:
12011 frontbuffer_bits
= INTEL_FRONTBUFFER_PRIMARY(pipe
);
12013 case DRM_PLANE_TYPE_CURSOR
:
12014 frontbuffer_bits
= INTEL_FRONTBUFFER_CURSOR(pipe
);
12016 case DRM_PLANE_TYPE_OVERLAY
:
12017 frontbuffer_bits
= INTEL_FRONTBUFFER_SPRITE(pipe
);
12021 mutex_lock(&dev
->struct_mutex
);
12023 if (plane
->type
== DRM_PLANE_TYPE_CURSOR
&&
12024 INTEL_INFO(dev
)->cursor_needs_physical
) {
12025 int align
= IS_I830(dev
) ? 16 * 1024 : 256;
12026 ret
= i915_gem_object_attach_phys(obj
, align
);
12028 DRM_DEBUG_KMS("failed to attach phys object\n");
12030 ret
= intel_pin_and_fence_fb_obj(plane
, fb
, new_state
, NULL
);
12034 i915_gem_track_fb(old_obj
, obj
, frontbuffer_bits
);
12036 mutex_unlock(&dev
->struct_mutex
);
12042 * intel_cleanup_plane_fb - Cleans up an fb after plane use
12043 * @plane: drm plane to clean up for
12044 * @fb: old framebuffer that was on plane
12046 * Cleans up a framebuffer that has just been removed from a plane.
12049 intel_cleanup_plane_fb(struct drm_plane
*plane
,
12050 struct drm_framebuffer
*fb
,
12051 const struct drm_plane_state
*old_state
)
12053 struct drm_device
*dev
= plane
->dev
;
12054 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
12059 if (plane
->type
!= DRM_PLANE_TYPE_CURSOR
||
12060 !INTEL_INFO(dev
)->cursor_needs_physical
) {
12061 mutex_lock(&dev
->struct_mutex
);
12062 intel_unpin_fb_obj(fb
, old_state
);
12063 mutex_unlock(&dev
->struct_mutex
);
12068 intel_check_primary_plane(struct drm_plane
*plane
,
12069 struct intel_plane_state
*state
)
12071 struct drm_device
*dev
= plane
->dev
;
12072 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12073 struct drm_crtc
*crtc
= state
->base
.crtc
;
12074 struct intel_crtc
*intel_crtc
;
12075 struct drm_framebuffer
*fb
= state
->base
.fb
;
12076 struct drm_rect
*dest
= &state
->dst
;
12077 struct drm_rect
*src
= &state
->src
;
12078 const struct drm_rect
*clip
= &state
->clip
;
12081 crtc
= crtc
? crtc
: plane
->crtc
;
12082 intel_crtc
= to_intel_crtc(crtc
);
12084 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
12086 DRM_PLANE_HELPER_NO_SCALING
,
12087 DRM_PLANE_HELPER_NO_SCALING
,
12088 false, true, &state
->visible
);
12092 if (intel_crtc
->active
) {
12093 intel_crtc
->atomic
.wait_for_flips
= true;
12096 * FBC does not work on some platforms for rotated
12097 * planes, so disable it when rotation is not 0 and
12098 * update it when rotation is set back to 0.
12100 * FIXME: This is redundant with the fbc update done in
12101 * the primary plane enable function except that that
12102 * one is done too late. We eventually need to unify
12105 if (intel_crtc
->primary_enabled
&&
12106 INTEL_INFO(dev
)->gen
<= 4 && !IS_G4X(dev
) &&
12107 dev_priv
->fbc
.crtc
== intel_crtc
&&
12108 state
->base
.rotation
!= BIT(DRM_ROTATE_0
)) {
12109 intel_crtc
->atomic
.disable_fbc
= true;
12112 if (state
->visible
) {
12114 * BDW signals flip done immediately if the plane
12115 * is disabled, even if the plane enable is already
12116 * armed to occur at the next vblank :(
12118 if (IS_BROADWELL(dev
) && !intel_crtc
->primary_enabled
)
12119 intel_crtc
->atomic
.wait_vblank
= true;
12122 intel_crtc
->atomic
.fb_bits
|=
12123 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
);
12125 intel_crtc
->atomic
.update_fbc
= true;
12127 /* Update watermarks on tiling changes. */
12128 if (!plane
->state
->fb
|| !state
->base
.fb
||
12129 plane
->state
->fb
->modifier
[0] !=
12130 state
->base
.fb
->modifier
[0])
12131 intel_crtc
->atomic
.update_wm
= true;
12138 intel_commit_primary_plane(struct drm_plane
*plane
,
12139 struct intel_plane_state
*state
)
12141 struct drm_crtc
*crtc
= state
->base
.crtc
;
12142 struct drm_framebuffer
*fb
= state
->base
.fb
;
12143 struct drm_device
*dev
= plane
->dev
;
12144 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12145 struct intel_crtc
*intel_crtc
;
12146 struct drm_rect
*src
= &state
->src
;
12148 crtc
= crtc
? crtc
: plane
->crtc
;
12149 intel_crtc
= to_intel_crtc(crtc
);
12152 crtc
->x
= src
->x1
>> 16;
12153 crtc
->y
= src
->y1
>> 16;
12155 if (intel_crtc
->active
) {
12156 if (state
->visible
) {
12157 /* FIXME: kill this fastboot hack */
12158 intel_update_pipe_size(intel_crtc
);
12160 intel_crtc
->primary_enabled
= true;
12162 dev_priv
->display
.update_primary_plane(crtc
, plane
->fb
,
12166 * If clipping results in a non-visible primary plane,
12167 * we'll disable the primary plane. Note that this is
12168 * a bit different than what happens if userspace
12169 * explicitly disables the plane by passing fb=0
12170 * because plane->fb still gets set and pinned.
12172 intel_disable_primary_hw_plane(plane
, crtc
);
12177 static void intel_begin_crtc_commit(struct drm_crtc
*crtc
)
12179 struct drm_device
*dev
= crtc
->dev
;
12180 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12181 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12182 struct intel_plane
*intel_plane
;
12183 struct drm_plane
*p
;
12184 unsigned fb_bits
= 0;
12186 /* Track fb's for any planes being disabled */
12187 list_for_each_entry(p
, &dev
->mode_config
.plane_list
, head
) {
12188 intel_plane
= to_intel_plane(p
);
12190 if (intel_crtc
->atomic
.disabled_planes
&
12191 (1 << drm_plane_index(p
))) {
12193 case DRM_PLANE_TYPE_PRIMARY
:
12194 fb_bits
= INTEL_FRONTBUFFER_PRIMARY(intel_plane
->pipe
);
12196 case DRM_PLANE_TYPE_CURSOR
:
12197 fb_bits
= INTEL_FRONTBUFFER_CURSOR(intel_plane
->pipe
);
12199 case DRM_PLANE_TYPE_OVERLAY
:
12200 fb_bits
= INTEL_FRONTBUFFER_SPRITE(intel_plane
->pipe
);
12204 mutex_lock(&dev
->struct_mutex
);
12205 i915_gem_track_fb(intel_fb_obj(p
->fb
), NULL
, fb_bits
);
12206 mutex_unlock(&dev
->struct_mutex
);
12210 if (intel_crtc
->atomic
.wait_for_flips
)
12211 intel_crtc_wait_for_pending_flips(crtc
);
12213 if (intel_crtc
->atomic
.disable_fbc
)
12214 intel_fbc_disable(dev
);
12216 if (intel_crtc
->atomic
.pre_disable_primary
)
12217 intel_pre_disable_primary(crtc
);
12219 if (intel_crtc
->atomic
.update_wm
)
12220 intel_update_watermarks(crtc
);
12222 intel_runtime_pm_get(dev_priv
);
12224 /* Perform vblank evasion around commit operation */
12225 if (intel_crtc
->active
)
12226 intel_crtc
->atomic
.evade
=
12227 intel_pipe_update_start(intel_crtc
,
12228 &intel_crtc
->atomic
.start_vbl_count
);
12231 static void intel_finish_crtc_commit(struct drm_crtc
*crtc
)
12233 struct drm_device
*dev
= crtc
->dev
;
12234 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12235 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
12236 struct drm_plane
*p
;
12238 if (intel_crtc
->atomic
.evade
)
12239 intel_pipe_update_end(intel_crtc
,
12240 intel_crtc
->atomic
.start_vbl_count
);
12242 intel_runtime_pm_put(dev_priv
);
12244 if (intel_crtc
->atomic
.wait_vblank
)
12245 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
12247 intel_frontbuffer_flip(dev
, intel_crtc
->atomic
.fb_bits
);
12249 if (intel_crtc
->atomic
.update_fbc
) {
12250 mutex_lock(&dev
->struct_mutex
);
12251 intel_fbc_update(dev
);
12252 mutex_unlock(&dev
->struct_mutex
);
12255 if (intel_crtc
->atomic
.post_enable_primary
)
12256 intel_post_enable_primary(crtc
);
12258 drm_for_each_legacy_plane(p
, &dev
->mode_config
.plane_list
)
12259 if (intel_crtc
->atomic
.update_sprite_watermarks
& drm_plane_index(p
))
12260 intel_update_sprite_watermarks(p
, crtc
, 0, 0, 0,
12263 memset(&intel_crtc
->atomic
, 0, sizeof(intel_crtc
->atomic
));
12267 * intel_plane_destroy - destroy a plane
12268 * @plane: plane to destroy
12270 * Common destruction function for all types of planes (primary, cursor,
12273 void intel_plane_destroy(struct drm_plane
*plane
)
12275 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
12276 drm_plane_cleanup(plane
);
12277 kfree(intel_plane
);
12280 const struct drm_plane_funcs intel_plane_funcs
= {
12281 .update_plane
= drm_plane_helper_update
,
12282 .disable_plane
= drm_plane_helper_disable
,
12283 .destroy
= intel_plane_destroy
,
12284 .set_property
= drm_atomic_helper_plane_set_property
,
12285 .atomic_get_property
= intel_plane_atomic_get_property
,
12286 .atomic_set_property
= intel_plane_atomic_set_property
,
12287 .atomic_duplicate_state
= intel_plane_duplicate_state
,
12288 .atomic_destroy_state
= intel_plane_destroy_state
,
12292 static struct drm_plane
*intel_primary_plane_create(struct drm_device
*dev
,
12295 struct intel_plane
*primary
;
12296 struct intel_plane_state
*state
;
12297 const uint32_t *intel_primary_formats
;
12300 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
12301 if (primary
== NULL
)
12304 state
= intel_create_plane_state(&primary
->base
);
12309 primary
->base
.state
= &state
->base
;
12311 primary
->can_scale
= false;
12312 primary
->max_downscale
= 1;
12313 primary
->pipe
= pipe
;
12314 primary
->plane
= pipe
;
12315 primary
->check_plane
= intel_check_primary_plane
;
12316 primary
->commit_plane
= intel_commit_primary_plane
;
12317 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4)
12318 primary
->plane
= !pipe
;
12320 if (INTEL_INFO(dev
)->gen
<= 3) {
12321 intel_primary_formats
= intel_primary_formats_gen2
;
12322 num_formats
= ARRAY_SIZE(intel_primary_formats_gen2
);
12324 intel_primary_formats
= intel_primary_formats_gen4
;
12325 num_formats
= ARRAY_SIZE(intel_primary_formats_gen4
);
12328 drm_universal_plane_init(dev
, &primary
->base
, 0,
12329 &intel_plane_funcs
,
12330 intel_primary_formats
, num_formats
,
12331 DRM_PLANE_TYPE_PRIMARY
);
12333 if (INTEL_INFO(dev
)->gen
>= 4) {
12334 if (!dev
->mode_config
.rotation_property
)
12335 dev
->mode_config
.rotation_property
=
12336 drm_mode_create_rotation_property(dev
,
12337 BIT(DRM_ROTATE_0
) |
12338 BIT(DRM_ROTATE_180
));
12339 if (dev
->mode_config
.rotation_property
)
12340 drm_object_attach_property(&primary
->base
.base
,
12341 dev
->mode_config
.rotation_property
,
12342 state
->base
.rotation
);
12345 drm_plane_helper_add(&primary
->base
, &intel_plane_helper_funcs
);
12347 return &primary
->base
;
12351 intel_check_cursor_plane(struct drm_plane
*plane
,
12352 struct intel_plane_state
*state
)
12354 struct drm_crtc
*crtc
= state
->base
.crtc
;
12355 struct drm_device
*dev
= plane
->dev
;
12356 struct drm_framebuffer
*fb
= state
->base
.fb
;
12357 struct drm_rect
*dest
= &state
->dst
;
12358 struct drm_rect
*src
= &state
->src
;
12359 const struct drm_rect
*clip
= &state
->clip
;
12360 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
12361 struct intel_crtc
*intel_crtc
;
12365 crtc
= crtc
? crtc
: plane
->crtc
;
12366 intel_crtc
= to_intel_crtc(crtc
);
12368 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
12370 DRM_PLANE_HELPER_NO_SCALING
,
12371 DRM_PLANE_HELPER_NO_SCALING
,
12372 true, true, &state
->visible
);
12377 /* if we want to turn off the cursor ignore width and height */
12381 /* Check for which cursor types we support */
12382 if (!cursor_size_ok(dev
, state
->base
.crtc_w
, state
->base
.crtc_h
)) {
12383 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
12384 state
->base
.crtc_w
, state
->base
.crtc_h
);
12388 stride
= roundup_pow_of_two(state
->base
.crtc_w
) * 4;
12389 if (obj
->base
.size
< stride
* state
->base
.crtc_h
) {
12390 DRM_DEBUG_KMS("buffer is too small\n");
12394 if (fb
->modifier
[0] != DRM_FORMAT_MOD_NONE
) {
12395 DRM_DEBUG_KMS("cursor cannot be tiled\n");
12400 if (intel_crtc
->active
) {
12401 if (plane
->state
->crtc_w
!= state
->base
.crtc_w
)
12402 intel_crtc
->atomic
.update_wm
= true;
12404 intel_crtc
->atomic
.fb_bits
|=
12405 INTEL_FRONTBUFFER_CURSOR(intel_crtc
->pipe
);
12412 intel_commit_cursor_plane(struct drm_plane
*plane
,
12413 struct intel_plane_state
*state
)
12415 struct drm_crtc
*crtc
= state
->base
.crtc
;
12416 struct drm_device
*dev
= plane
->dev
;
12417 struct intel_crtc
*intel_crtc
;
12418 struct drm_i915_gem_object
*obj
= intel_fb_obj(state
->base
.fb
);
12421 crtc
= crtc
? crtc
: plane
->crtc
;
12422 intel_crtc
= to_intel_crtc(crtc
);
12424 plane
->fb
= state
->base
.fb
;
12425 crtc
->cursor_x
= state
->base
.crtc_x
;
12426 crtc
->cursor_y
= state
->base
.crtc_y
;
12428 if (intel_crtc
->cursor_bo
== obj
)
12433 else if (!INTEL_INFO(dev
)->cursor_needs_physical
)
12434 addr
= i915_gem_obj_ggtt_offset(obj
);
12436 addr
= obj
->phys_handle
->busaddr
;
12438 intel_crtc
->cursor_addr
= addr
;
12439 intel_crtc
->cursor_bo
= obj
;
12442 if (intel_crtc
->active
)
12443 intel_crtc_update_cursor(crtc
, state
->visible
);
12446 static struct drm_plane
*intel_cursor_plane_create(struct drm_device
*dev
,
12449 struct intel_plane
*cursor
;
12450 struct intel_plane_state
*state
;
12452 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
12453 if (cursor
== NULL
)
12456 state
= intel_create_plane_state(&cursor
->base
);
12461 cursor
->base
.state
= &state
->base
;
12463 cursor
->can_scale
= false;
12464 cursor
->max_downscale
= 1;
12465 cursor
->pipe
= pipe
;
12466 cursor
->plane
= pipe
;
12467 cursor
->check_plane
= intel_check_cursor_plane
;
12468 cursor
->commit_plane
= intel_commit_cursor_plane
;
12470 drm_universal_plane_init(dev
, &cursor
->base
, 0,
12471 &intel_plane_funcs
,
12472 intel_cursor_formats
,
12473 ARRAY_SIZE(intel_cursor_formats
),
12474 DRM_PLANE_TYPE_CURSOR
);
12476 if (INTEL_INFO(dev
)->gen
>= 4) {
12477 if (!dev
->mode_config
.rotation_property
)
12478 dev
->mode_config
.rotation_property
=
12479 drm_mode_create_rotation_property(dev
,
12480 BIT(DRM_ROTATE_0
) |
12481 BIT(DRM_ROTATE_180
));
12482 if (dev
->mode_config
.rotation_property
)
12483 drm_object_attach_property(&cursor
->base
.base
,
12484 dev
->mode_config
.rotation_property
,
12485 state
->base
.rotation
);
12488 drm_plane_helper_add(&cursor
->base
, &intel_plane_helper_funcs
);
12490 return &cursor
->base
;
12493 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
12495 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12496 struct intel_crtc
*intel_crtc
;
12497 struct intel_crtc_state
*crtc_state
= NULL
;
12498 struct drm_plane
*primary
= NULL
;
12499 struct drm_plane
*cursor
= NULL
;
12502 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
12503 if (intel_crtc
== NULL
)
12506 crtc_state
= kzalloc(sizeof(*crtc_state
), GFP_KERNEL
);
12509 intel_crtc_set_state(intel_crtc
, crtc_state
);
12510 crtc_state
->base
.crtc
= &intel_crtc
->base
;
12512 primary
= intel_primary_plane_create(dev
, pipe
);
12516 cursor
= intel_cursor_plane_create(dev
, pipe
);
12520 ret
= drm_crtc_init_with_planes(dev
, &intel_crtc
->base
, primary
,
12521 cursor
, &intel_crtc_funcs
);
12525 drm_mode_crtc_set_gamma_size(&intel_crtc
->base
, 256);
12526 for (i
= 0; i
< 256; i
++) {
12527 intel_crtc
->lut_r
[i
] = i
;
12528 intel_crtc
->lut_g
[i
] = i
;
12529 intel_crtc
->lut_b
[i
] = i
;
12533 * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
12534 * is hooked to pipe B. Hence we want plane A feeding pipe B.
12536 intel_crtc
->pipe
= pipe
;
12537 intel_crtc
->plane
= pipe
;
12538 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4) {
12539 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
12540 intel_crtc
->plane
= !pipe
;
12543 intel_crtc
->cursor_base
= ~0;
12544 intel_crtc
->cursor_cntl
= ~0;
12545 intel_crtc
->cursor_size
= ~0;
12547 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
12548 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
12549 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
12550 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
12552 INIT_WORK(&intel_crtc
->mmio_flip
.work
, intel_mmio_flip_work_func
);
12554 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
12556 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
12561 drm_plane_cleanup(primary
);
12563 drm_plane_cleanup(cursor
);
12568 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
12570 struct drm_encoder
*encoder
= connector
->base
.encoder
;
12571 struct drm_device
*dev
= connector
->base
.dev
;
12573 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
12575 if (!encoder
|| WARN_ON(!encoder
->crtc
))
12576 return INVALID_PIPE
;
12578 return to_intel_crtc(encoder
->crtc
)->pipe
;
12581 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
12582 struct drm_file
*file
)
12584 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
12585 struct drm_crtc
*drmmode_crtc
;
12586 struct intel_crtc
*crtc
;
12588 drmmode_crtc
= drm_crtc_find(dev
, pipe_from_crtc_id
->crtc_id
);
12590 if (!drmmode_crtc
) {
12591 DRM_ERROR("no such CRTC id\n");
12595 crtc
= to_intel_crtc(drmmode_crtc
);
12596 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
12601 static int intel_encoder_clones(struct intel_encoder
*encoder
)
12603 struct drm_device
*dev
= encoder
->base
.dev
;
12604 struct intel_encoder
*source_encoder
;
12605 int index_mask
= 0;
12608 for_each_intel_encoder(dev
, source_encoder
) {
12609 if (encoders_cloneable(encoder
, source_encoder
))
12610 index_mask
|= (1 << entry
);
12618 static bool has_edp_a(struct drm_device
*dev
)
12620 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12622 if (!IS_MOBILE(dev
))
12625 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
12628 if (IS_GEN5(dev
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
12634 static bool intel_crt_present(struct drm_device
*dev
)
12636 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12638 if (INTEL_INFO(dev
)->gen
>= 9)
12641 if (IS_HSW_ULT(dev
) || IS_BDW_ULT(dev
))
12644 if (IS_CHERRYVIEW(dev
))
12647 if (IS_VALLEYVIEW(dev
) && !dev_priv
->vbt
.int_crt_support
)
12653 static void intel_setup_outputs(struct drm_device
*dev
)
12655 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12656 struct intel_encoder
*encoder
;
12657 struct drm_connector
*connector
;
12658 bool dpd_is_edp
= false;
12660 intel_lvds_init(dev
);
12662 if (intel_crt_present(dev
))
12663 intel_crt_init(dev
);
12665 if (HAS_DDI(dev
)) {
12669 * Haswell uses DDI functions to detect digital outputs.
12670 * On SKL pre-D0 the strap isn't connected, so we assume
12673 found
= I915_READ(DDI_BUF_CTL_A
) & DDI_INIT_DISPLAY_DETECTED
;
12674 /* WaIgnoreDDIAStrap: skl */
12676 (IS_SKYLAKE(dev
) && INTEL_REVID(dev
) < SKL_REVID_D0
))
12677 intel_ddi_init(dev
, PORT_A
);
12679 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
12681 found
= I915_READ(SFUSE_STRAP
);
12683 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
12684 intel_ddi_init(dev
, PORT_B
);
12685 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
12686 intel_ddi_init(dev
, PORT_C
);
12687 if (found
& SFUSE_STRAP_DDID_DETECTED
)
12688 intel_ddi_init(dev
, PORT_D
);
12689 } else if (HAS_PCH_SPLIT(dev
)) {
12691 dpd_is_edp
= intel_dp_is_edp(dev
, PORT_D
);
12693 if (has_edp_a(dev
))
12694 intel_dp_init(dev
, DP_A
, PORT_A
);
12696 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
12697 /* PCH SDVOB multiplex with HDMIB */
12698 found
= intel_sdvo_init(dev
, PCH_SDVOB
, true);
12700 intel_hdmi_init(dev
, PCH_HDMIB
, PORT_B
);
12701 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
12702 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
12705 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
12706 intel_hdmi_init(dev
, PCH_HDMIC
, PORT_C
);
12708 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
12709 intel_hdmi_init(dev
, PCH_HDMID
, PORT_D
);
12711 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
12712 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
12714 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
12715 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
12716 } else if (IS_VALLEYVIEW(dev
)) {
12718 * The DP_DETECTED bit is the latched state of the DDC
12719 * SDA pin at boot. However since eDP doesn't require DDC
12720 * (no way to plug in a DP->HDMI dongle) the DDC pins for
12721 * eDP ports may have been muxed to an alternate function.
12722 * Thus we can't rely on the DP_DETECTED bit alone to detect
12723 * eDP ports. Consult the VBT as well as DP_DETECTED to
12724 * detect eDP ports.
12726 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIB
) & SDVO_DETECTED
&&
12727 !intel_dp_is_edp(dev
, PORT_B
))
12728 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIB
,
12730 if (I915_READ(VLV_DISPLAY_BASE
+ DP_B
) & DP_DETECTED
||
12731 intel_dp_is_edp(dev
, PORT_B
))
12732 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_B
, PORT_B
);
12734 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIC
) & SDVO_DETECTED
&&
12735 !intel_dp_is_edp(dev
, PORT_C
))
12736 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIC
,
12738 if (I915_READ(VLV_DISPLAY_BASE
+ DP_C
) & DP_DETECTED
||
12739 intel_dp_is_edp(dev
, PORT_C
))
12740 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_C
, PORT_C
);
12742 if (IS_CHERRYVIEW(dev
)) {
12743 if (I915_READ(VLV_DISPLAY_BASE
+ CHV_HDMID
) & SDVO_DETECTED
)
12744 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ CHV_HDMID
,
12746 /* eDP not supported on port D, so don't check VBT */
12747 if (I915_READ(VLV_DISPLAY_BASE
+ DP_D
) & DP_DETECTED
)
12748 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_D
, PORT_D
);
12751 intel_dsi_init(dev
);
12752 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev
)) {
12753 bool found
= false;
12755 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
12756 DRM_DEBUG_KMS("probing SDVOB\n");
12757 found
= intel_sdvo_init(dev
, GEN3_SDVOB
, true);
12758 if (!found
&& SUPPORTS_INTEGRATED_HDMI(dev
)) {
12759 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
12760 intel_hdmi_init(dev
, GEN4_HDMIB
, PORT_B
);
12763 if (!found
&& SUPPORTS_INTEGRATED_DP(dev
))
12764 intel_dp_init(dev
, DP_B
, PORT_B
);
12767 /* Before G4X SDVOC doesn't have its own detect register */
12769 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
12770 DRM_DEBUG_KMS("probing SDVOC\n");
12771 found
= intel_sdvo_init(dev
, GEN3_SDVOC
, false);
12774 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
12776 if (SUPPORTS_INTEGRATED_HDMI(dev
)) {
12777 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
12778 intel_hdmi_init(dev
, GEN4_HDMIC
, PORT_C
);
12780 if (SUPPORTS_INTEGRATED_DP(dev
))
12781 intel_dp_init(dev
, DP_C
, PORT_C
);
12784 if (SUPPORTS_INTEGRATED_DP(dev
) &&
12785 (I915_READ(DP_D
) & DP_DETECTED
))
12786 intel_dp_init(dev
, DP_D
, PORT_D
);
12787 } else if (IS_GEN2(dev
))
12788 intel_dvo_init(dev
);
12790 if (SUPPORTS_TV(dev
))
12791 intel_tv_init(dev
);
12794 * FIXME: We don't have full atomic support yet, but we want to be
12795 * able to enable/test plane updates via the atomic interface in the
12796 * meantime. However as soon as we flip DRIVER_ATOMIC on, the DRM core
12797 * will take some atomic codepaths to lookup properties during
12798 * drmModeGetConnector() that unconditionally dereference
12799 * connector->state.
12801 * We create a dummy connector state here for each connector to ensure
12802 * the DRM core doesn't try to dereference a NULL connector->state.
12803 * The actual connector properties will never be updated or contain
12804 * useful information, but since we're doing this specifically for
12805 * testing/debug of the plane operations (and only when a specific
12806 * kernel module option is given), that shouldn't really matter.
12808 * Once atomic support for crtc's + connectors lands, this loop should
12809 * be removed since we'll be setting up real connector state, which
12810 * will contain Intel-specific properties.
12812 if (drm_core_check_feature(dev
, DRIVER_ATOMIC
)) {
12813 list_for_each_entry(connector
,
12814 &dev
->mode_config
.connector_list
,
12816 if (!WARN_ON(connector
->state
)) {
12818 kzalloc(sizeof(*connector
->state
),
12824 intel_psr_init(dev
);
12826 for_each_intel_encoder(dev
, encoder
) {
12827 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
12828 encoder
->base
.possible_clones
=
12829 intel_encoder_clones(encoder
);
12832 intel_init_pch_refclk(dev
);
12834 drm_helper_move_panel_connectors_to_head(dev
);
12837 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
12839 struct drm_device
*dev
= fb
->dev
;
12840 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
12842 drm_framebuffer_cleanup(fb
);
12843 mutex_lock(&dev
->struct_mutex
);
12844 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
12845 drm_gem_object_unreference(&intel_fb
->obj
->base
);
12846 mutex_unlock(&dev
->struct_mutex
);
12850 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
12851 struct drm_file
*file
,
12852 unsigned int *handle
)
12854 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
12855 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
12857 return drm_gem_handle_create(file
, &obj
->base
, handle
);
12860 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
12861 .destroy
= intel_user_framebuffer_destroy
,
12862 .create_handle
= intel_user_framebuffer_create_handle
,
12866 u32
intel_fb_pitch_limit(struct drm_device
*dev
, uint64_t fb_modifier
,
12867 uint32_t pixel_format
)
12869 u32 gen
= INTEL_INFO(dev
)->gen
;
12872 /* "The stride in bytes must not exceed the of the size of 8K
12873 * pixels and 32K bytes."
12875 return min(8192*drm_format_plane_cpp(pixel_format
, 0), 32768);
12876 } else if (gen
>= 5 && !IS_VALLEYVIEW(dev
)) {
12878 } else if (gen
>= 4) {
12879 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
12883 } else if (gen
>= 3) {
12884 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
12889 /* XXX DSPC is limited to 4k tiled */
12894 static int intel_framebuffer_init(struct drm_device
*dev
,
12895 struct intel_framebuffer
*intel_fb
,
12896 struct drm_mode_fb_cmd2
*mode_cmd
,
12897 struct drm_i915_gem_object
*obj
)
12899 unsigned int aligned_height
;
12901 u32 pitch_limit
, stride_alignment
;
12903 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
12905 if (mode_cmd
->flags
& DRM_MODE_FB_MODIFIERS
) {
12906 /* Enforce that fb modifier and tiling mode match, but only for
12907 * X-tiled. This is needed for FBC. */
12908 if (!!(obj
->tiling_mode
== I915_TILING_X
) !=
12909 !!(mode_cmd
->modifier
[0] == I915_FORMAT_MOD_X_TILED
)) {
12910 DRM_DEBUG("tiling_mode doesn't match fb modifier\n");
12914 if (obj
->tiling_mode
== I915_TILING_X
)
12915 mode_cmd
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
12916 else if (obj
->tiling_mode
== I915_TILING_Y
) {
12917 DRM_DEBUG("No Y tiling for legacy addfb\n");
12922 /* Passed in modifier sanity checking. */
12923 switch (mode_cmd
->modifier
[0]) {
12924 case I915_FORMAT_MOD_Y_TILED
:
12925 case I915_FORMAT_MOD_Yf_TILED
:
12926 if (INTEL_INFO(dev
)->gen
< 9) {
12927 DRM_DEBUG("Unsupported tiling 0x%llx!\n",
12928 mode_cmd
->modifier
[0]);
12931 case DRM_FORMAT_MOD_NONE
:
12932 case I915_FORMAT_MOD_X_TILED
:
12935 DRM_ERROR("Unsupported fb modifier 0x%llx!\n",
12936 mode_cmd
->modifier
[0]);
12940 stride_alignment
= intel_fb_stride_alignment(dev
, mode_cmd
->modifier
[0],
12941 mode_cmd
->pixel_format
);
12942 if (mode_cmd
->pitches
[0] & (stride_alignment
- 1)) {
12943 DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n",
12944 mode_cmd
->pitches
[0], stride_alignment
);
12948 pitch_limit
= intel_fb_pitch_limit(dev
, mode_cmd
->modifier
[0],
12949 mode_cmd
->pixel_format
);
12950 if (mode_cmd
->pitches
[0] > pitch_limit
) {
12951 DRM_DEBUG("%s pitch (%u) must be at less than %d\n",
12952 mode_cmd
->modifier
[0] != DRM_FORMAT_MOD_NONE
?
12953 "tiled" : "linear",
12954 mode_cmd
->pitches
[0], pitch_limit
);
12958 if (mode_cmd
->modifier
[0] == I915_FORMAT_MOD_X_TILED
&&
12959 mode_cmd
->pitches
[0] != obj
->stride
) {
12960 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
12961 mode_cmd
->pitches
[0], obj
->stride
);
12965 /* Reject formats not supported by any plane early. */
12966 switch (mode_cmd
->pixel_format
) {
12967 case DRM_FORMAT_C8
:
12968 case DRM_FORMAT_RGB565
:
12969 case DRM_FORMAT_XRGB8888
:
12970 case DRM_FORMAT_ARGB8888
:
12972 case DRM_FORMAT_XRGB1555
:
12973 case DRM_FORMAT_ARGB1555
:
12974 if (INTEL_INFO(dev
)->gen
> 3) {
12975 DRM_DEBUG("unsupported pixel format: %s\n",
12976 drm_get_format_name(mode_cmd
->pixel_format
));
12980 case DRM_FORMAT_XBGR8888
:
12981 case DRM_FORMAT_ABGR8888
:
12982 case DRM_FORMAT_XRGB2101010
:
12983 case DRM_FORMAT_ARGB2101010
:
12984 case DRM_FORMAT_XBGR2101010
:
12985 case DRM_FORMAT_ABGR2101010
:
12986 if (INTEL_INFO(dev
)->gen
< 4) {
12987 DRM_DEBUG("unsupported pixel format: %s\n",
12988 drm_get_format_name(mode_cmd
->pixel_format
));
12992 case DRM_FORMAT_YUYV
:
12993 case DRM_FORMAT_UYVY
:
12994 case DRM_FORMAT_YVYU
:
12995 case DRM_FORMAT_VYUY
:
12996 if (INTEL_INFO(dev
)->gen
< 5) {
12997 DRM_DEBUG("unsupported pixel format: %s\n",
12998 drm_get_format_name(mode_cmd
->pixel_format
));
13003 DRM_DEBUG("unsupported pixel format: %s\n",
13004 drm_get_format_name(mode_cmd
->pixel_format
));
13008 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
13009 if (mode_cmd
->offsets
[0] != 0)
13012 aligned_height
= intel_fb_align_height(dev
, mode_cmd
->height
,
13013 mode_cmd
->pixel_format
,
13014 mode_cmd
->modifier
[0]);
13015 /* FIXME drm helper for size checks (especially planar formats)? */
13016 if (obj
->base
.size
< aligned_height
* mode_cmd
->pitches
[0])
13019 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
13020 intel_fb
->obj
= obj
;
13021 intel_fb
->obj
->framebuffer_references
++;
13023 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
13025 DRM_ERROR("framebuffer init failed %d\n", ret
);
13032 static struct drm_framebuffer
*
13033 intel_user_framebuffer_create(struct drm_device
*dev
,
13034 struct drm_file
*filp
,
13035 struct drm_mode_fb_cmd2
*mode_cmd
)
13037 struct drm_i915_gem_object
*obj
;
13039 obj
= to_intel_bo(drm_gem_object_lookup(dev
, filp
,
13040 mode_cmd
->handles
[0]));
13041 if (&obj
->base
== NULL
)
13042 return ERR_PTR(-ENOENT
);
13044 return intel_framebuffer_create(dev
, mode_cmd
, obj
);
13047 #ifndef CONFIG_DRM_I915_FBDEV
13048 static inline void intel_fbdev_output_poll_changed(struct drm_device
*dev
)
13053 static const struct drm_mode_config_funcs intel_mode_funcs
= {
13054 .fb_create
= intel_user_framebuffer_create
,
13055 .output_poll_changed
= intel_fbdev_output_poll_changed
,
13056 .atomic_check
= intel_atomic_check
,
13057 .atomic_commit
= intel_atomic_commit
,
13060 /* Set up chip specific display functions */
13061 static void intel_init_display(struct drm_device
*dev
)
13063 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13065 if (HAS_PCH_SPLIT(dev
) || IS_G4X(dev
))
13066 dev_priv
->display
.find_dpll
= g4x_find_best_dpll
;
13067 else if (IS_CHERRYVIEW(dev
))
13068 dev_priv
->display
.find_dpll
= chv_find_best_dpll
;
13069 else if (IS_VALLEYVIEW(dev
))
13070 dev_priv
->display
.find_dpll
= vlv_find_best_dpll
;
13071 else if (IS_PINEVIEW(dev
))
13072 dev_priv
->display
.find_dpll
= pnv_find_best_dpll
;
13074 dev_priv
->display
.find_dpll
= i9xx_find_best_dpll
;
13076 if (INTEL_INFO(dev
)->gen
>= 9) {
13077 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
13078 dev_priv
->display
.get_initial_plane_config
=
13079 skylake_get_initial_plane_config
;
13080 dev_priv
->display
.crtc_compute_clock
=
13081 haswell_crtc_compute_clock
;
13082 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
13083 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
13084 dev_priv
->display
.off
= ironlake_crtc_off
;
13085 dev_priv
->display
.update_primary_plane
=
13086 skylake_update_primary_plane
;
13087 } else if (HAS_DDI(dev
)) {
13088 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
13089 dev_priv
->display
.get_initial_plane_config
=
13090 ironlake_get_initial_plane_config
;
13091 dev_priv
->display
.crtc_compute_clock
=
13092 haswell_crtc_compute_clock
;
13093 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
13094 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
13095 dev_priv
->display
.off
= ironlake_crtc_off
;
13096 dev_priv
->display
.update_primary_plane
=
13097 ironlake_update_primary_plane
;
13098 } else if (HAS_PCH_SPLIT(dev
)) {
13099 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
13100 dev_priv
->display
.get_initial_plane_config
=
13101 ironlake_get_initial_plane_config
;
13102 dev_priv
->display
.crtc_compute_clock
=
13103 ironlake_crtc_compute_clock
;
13104 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
13105 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
13106 dev_priv
->display
.off
= ironlake_crtc_off
;
13107 dev_priv
->display
.update_primary_plane
=
13108 ironlake_update_primary_plane
;
13109 } else if (IS_VALLEYVIEW(dev
)) {
13110 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13111 dev_priv
->display
.get_initial_plane_config
=
13112 i9xx_get_initial_plane_config
;
13113 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
13114 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
13115 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13116 dev_priv
->display
.off
= i9xx_crtc_off
;
13117 dev_priv
->display
.update_primary_plane
=
13118 i9xx_update_primary_plane
;
13120 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
13121 dev_priv
->display
.get_initial_plane_config
=
13122 i9xx_get_initial_plane_config
;
13123 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
13124 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
13125 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
13126 dev_priv
->display
.off
= i9xx_crtc_off
;
13127 dev_priv
->display
.update_primary_plane
=
13128 i9xx_update_primary_plane
;
13131 /* Returns the core display clock speed */
13132 if (IS_VALLEYVIEW(dev
))
13133 dev_priv
->display
.get_display_clock_speed
=
13134 valleyview_get_display_clock_speed
;
13135 else if (IS_I945G(dev
) || (IS_G33(dev
) && !IS_PINEVIEW_M(dev
)))
13136 dev_priv
->display
.get_display_clock_speed
=
13137 i945_get_display_clock_speed
;
13138 else if (IS_I915G(dev
))
13139 dev_priv
->display
.get_display_clock_speed
=
13140 i915_get_display_clock_speed
;
13141 else if (IS_I945GM(dev
) || IS_845G(dev
))
13142 dev_priv
->display
.get_display_clock_speed
=
13143 i9xx_misc_get_display_clock_speed
;
13144 else if (IS_PINEVIEW(dev
))
13145 dev_priv
->display
.get_display_clock_speed
=
13146 pnv_get_display_clock_speed
;
13147 else if (IS_I915GM(dev
))
13148 dev_priv
->display
.get_display_clock_speed
=
13149 i915gm_get_display_clock_speed
;
13150 else if (IS_I865G(dev
))
13151 dev_priv
->display
.get_display_clock_speed
=
13152 i865_get_display_clock_speed
;
13153 else if (IS_I85X(dev
))
13154 dev_priv
->display
.get_display_clock_speed
=
13155 i855_get_display_clock_speed
;
13156 else /* 852, 830 */
13157 dev_priv
->display
.get_display_clock_speed
=
13158 i830_get_display_clock_speed
;
13160 if (IS_GEN5(dev
)) {
13161 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
13162 } else if (IS_GEN6(dev
)) {
13163 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
13164 } else if (IS_IVYBRIDGE(dev
)) {
13165 /* FIXME: detect B0+ stepping and use auto training */
13166 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
13167 } else if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
13168 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
13169 } else if (IS_VALLEYVIEW(dev
)) {
13170 dev_priv
->display
.modeset_global_resources
=
13171 valleyview_modeset_global_resources
;
13174 switch (INTEL_INFO(dev
)->gen
) {
13176 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
13180 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
13185 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
13189 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
13192 case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
13193 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
13196 /* Drop through - unsupported since execlist only. */
13198 /* Default just returns -ENODEV to indicate unsupported */
13199 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
13202 intel_panel_init_backlight_funcs(dev
);
13204 mutex_init(&dev_priv
->pps_mutex
);
13208 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
13209 * resume, or other times. This quirk makes sure that's the case for
13210 * affected systems.
13212 static void quirk_pipea_force(struct drm_device
*dev
)
13214 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13216 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
13217 DRM_INFO("applying pipe a force quirk\n");
13220 static void quirk_pipeb_force(struct drm_device
*dev
)
13222 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13224 dev_priv
->quirks
|= QUIRK_PIPEB_FORCE
;
13225 DRM_INFO("applying pipe b force quirk\n");
13229 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
13231 static void quirk_ssc_force_disable(struct drm_device
*dev
)
13233 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13234 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
13235 DRM_INFO("applying lvds SSC disable quirk\n");
13239 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
13242 static void quirk_invert_brightness(struct drm_device
*dev
)
13244 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13245 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
13246 DRM_INFO("applying inverted panel brightness quirk\n");
13249 /* Some VBT's incorrectly indicate no backlight is present */
13250 static void quirk_backlight_present(struct drm_device
*dev
)
13252 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13253 dev_priv
->quirks
|= QUIRK_BACKLIGHT_PRESENT
;
13254 DRM_INFO("applying backlight present quirk\n");
13257 struct intel_quirk
{
13259 int subsystem_vendor
;
13260 int subsystem_device
;
13261 void (*hook
)(struct drm_device
*dev
);
13264 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
13265 struct intel_dmi_quirk
{
13266 void (*hook
)(struct drm_device
*dev
);
13267 const struct dmi_system_id (*dmi_id_list
)[];
13270 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
13272 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
13276 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
13278 .dmi_id_list
= &(const struct dmi_system_id
[]) {
13280 .callback
= intel_dmi_reverse_brightness
,
13281 .ident
= "NCR Corporation",
13282 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
13283 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
13286 { } /* terminating entry */
13288 .hook
= quirk_invert_brightness
,
13292 static struct intel_quirk intel_quirks
[] = {
13293 /* HP Mini needs pipe A force quirk (LP: #322104) */
13294 { 0x27ae, 0x103c, 0x361a, quirk_pipea_force
},
13296 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
13297 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
13299 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
13300 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
13302 /* 830 needs to leave pipe A & dpll A up */
13303 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
13305 /* 830 needs to leave pipe B & dpll B up */
13306 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipeb_force
},
13308 /* Lenovo U160 cannot use SSC on LVDS */
13309 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
13311 /* Sony Vaio Y cannot use SSC on LVDS */
13312 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
13314 /* Acer Aspire 5734Z must invert backlight brightness */
13315 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
13317 /* Acer/eMachines G725 */
13318 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
13320 /* Acer/eMachines e725 */
13321 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
13323 /* Acer/Packard Bell NCL20 */
13324 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
13326 /* Acer Aspire 4736Z */
13327 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
13329 /* Acer Aspire 5336 */
13330 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
13332 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
13333 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present
},
13335 /* Acer C720 Chromebook (Core i3 4005U) */
13336 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present
},
13338 /* Apple Macbook 2,1 (Core 2 T7400) */
13339 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present
},
13341 /* Toshiba CB35 Chromebook (Celeron 2955U) */
13342 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present
},
13344 /* HP Chromebook 14 (Celeron 2955U) */
13345 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present
},
13347 /* Dell Chromebook 11 */
13348 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present
},
13351 static void intel_init_quirks(struct drm_device
*dev
)
13353 struct pci_dev
*d
= dev
->pdev
;
13356 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
13357 struct intel_quirk
*q
= &intel_quirks
[i
];
13359 if (d
->device
== q
->device
&&
13360 (d
->subsystem_vendor
== q
->subsystem_vendor
||
13361 q
->subsystem_vendor
== PCI_ANY_ID
) &&
13362 (d
->subsystem_device
== q
->subsystem_device
||
13363 q
->subsystem_device
== PCI_ANY_ID
))
13366 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
13367 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
13368 intel_dmi_quirks
[i
].hook(dev
);
13372 /* Disable the VGA plane that we never use */
13373 static void i915_disable_vga(struct drm_device
*dev
)
13375 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13377 u32 vga_reg
= i915_vgacntrl_reg(dev
);
13379 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
13380 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
13381 outb(SR01
, VGA_SR_INDEX
);
13382 sr1
= inb(VGA_SR_DATA
);
13383 outb(sr1
| 1<<5, VGA_SR_DATA
);
13384 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
13387 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
13388 POSTING_READ(vga_reg
);
13391 void intel_modeset_init_hw(struct drm_device
*dev
)
13393 intel_prepare_ddi(dev
);
13395 if (IS_VALLEYVIEW(dev
))
13396 vlv_update_cdclk(dev
);
13398 intel_init_clock_gating(dev
);
13400 intel_enable_gt_powersave(dev
);
13403 void intel_modeset_init(struct drm_device
*dev
)
13405 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13408 struct intel_crtc
*crtc
;
13410 drm_mode_config_init(dev
);
13412 dev
->mode_config
.min_width
= 0;
13413 dev
->mode_config
.min_height
= 0;
13415 dev
->mode_config
.preferred_depth
= 24;
13416 dev
->mode_config
.prefer_shadow
= 1;
13418 dev
->mode_config
.allow_fb_modifiers
= true;
13420 dev
->mode_config
.funcs
= &intel_mode_funcs
;
13422 intel_init_quirks(dev
);
13424 intel_init_pm(dev
);
13426 if (INTEL_INFO(dev
)->num_pipes
== 0)
13429 intel_init_display(dev
);
13430 intel_init_audio(dev
);
13432 if (IS_GEN2(dev
)) {
13433 dev
->mode_config
.max_width
= 2048;
13434 dev
->mode_config
.max_height
= 2048;
13435 } else if (IS_GEN3(dev
)) {
13436 dev
->mode_config
.max_width
= 4096;
13437 dev
->mode_config
.max_height
= 4096;
13439 dev
->mode_config
.max_width
= 8192;
13440 dev
->mode_config
.max_height
= 8192;
13443 if (IS_845G(dev
) || IS_I865G(dev
)) {
13444 dev
->mode_config
.cursor_width
= IS_845G(dev
) ? 64 : 512;
13445 dev
->mode_config
.cursor_height
= 1023;
13446 } else if (IS_GEN2(dev
)) {
13447 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
13448 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
13450 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
13451 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
13454 dev
->mode_config
.fb_base
= dev_priv
->gtt
.mappable_base
;
13456 DRM_DEBUG_KMS("%d display pipe%s available.\n",
13457 INTEL_INFO(dev
)->num_pipes
,
13458 INTEL_INFO(dev
)->num_pipes
> 1 ? "s" : "");
13460 for_each_pipe(dev_priv
, pipe
) {
13461 intel_crtc_init(dev
, pipe
);
13462 for_each_sprite(dev_priv
, pipe
, sprite
) {
13463 ret
= intel_plane_init(dev
, pipe
, sprite
);
13465 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
13466 pipe_name(pipe
), sprite_name(pipe
, sprite
), ret
);
13470 intel_init_dpio(dev
);
13472 intel_shared_dpll_init(dev
);
13474 /* Just disable it once at startup */
13475 i915_disable_vga(dev
);
13476 intel_setup_outputs(dev
);
13478 /* Just in case the BIOS is doing something questionable. */
13479 intel_fbc_disable(dev
);
13481 drm_modeset_lock_all(dev
);
13482 intel_modeset_setup_hw_state(dev
, false);
13483 drm_modeset_unlock_all(dev
);
13485 for_each_intel_crtc(dev
, crtc
) {
13490 * Note that reserving the BIOS fb up front prevents us
13491 * from stuffing other stolen allocations like the ring
13492 * on top. This prevents some ugliness at boot time, and
13493 * can even allow for smooth boot transitions if the BIOS
13494 * fb is large enough for the active pipe configuration.
13496 if (dev_priv
->display
.get_initial_plane_config
) {
13497 dev_priv
->display
.get_initial_plane_config(crtc
,
13498 &crtc
->plane_config
);
13500 * If the fb is shared between multiple heads, we'll
13501 * just get the first one.
13503 intel_find_plane_obj(crtc
, &crtc
->plane_config
);
13508 static void intel_enable_pipe_a(struct drm_device
*dev
)
13510 struct intel_connector
*connector
;
13511 struct drm_connector
*crt
= NULL
;
13512 struct intel_load_detect_pipe load_detect_temp
;
13513 struct drm_modeset_acquire_ctx
*ctx
= dev
->mode_config
.acquire_ctx
;
13515 /* We can't just switch on the pipe A, we need to set things up with a
13516 * proper mode and output configuration. As a gross hack, enable pipe A
13517 * by enabling the load detect pipe once. */
13518 for_each_intel_connector(dev
, connector
) {
13519 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
13520 crt
= &connector
->base
;
13528 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
, ctx
))
13529 intel_release_load_detect_pipe(crt
, &load_detect_temp
);
13533 intel_check_plane_mapping(struct intel_crtc
*crtc
)
13535 struct drm_device
*dev
= crtc
->base
.dev
;
13536 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13539 if (INTEL_INFO(dev
)->num_pipes
== 1)
13542 reg
= DSPCNTR(!crtc
->plane
);
13543 val
= I915_READ(reg
);
13545 if ((val
& DISPLAY_PLANE_ENABLE
) &&
13546 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
13552 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
13554 struct drm_device
*dev
= crtc
->base
.dev
;
13555 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13558 /* Clear any frame start delays used for debugging left by the BIOS */
13559 reg
= PIPECONF(crtc
->config
->cpu_transcoder
);
13560 I915_WRITE(reg
, I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
13562 /* restore vblank interrupts to correct state */
13563 drm_crtc_vblank_reset(&crtc
->base
);
13564 if (crtc
->active
) {
13565 update_scanline_offset(crtc
);
13566 drm_crtc_vblank_on(&crtc
->base
);
13569 /* We need to sanitize the plane -> pipe mapping first because this will
13570 * disable the crtc (and hence change the state) if it is wrong. Note
13571 * that gen4+ has a fixed plane -> pipe mapping. */
13572 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
13573 struct intel_connector
*connector
;
13576 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
13577 crtc
->base
.base
.id
);
13579 /* Pipe has the wrong plane attached and the plane is active.
13580 * Temporarily change the plane mapping and disable everything
13582 plane
= crtc
->plane
;
13583 crtc
->plane
= !plane
;
13584 crtc
->primary_enabled
= true;
13585 dev_priv
->display
.crtc_disable(&crtc
->base
);
13586 crtc
->plane
= plane
;
13588 /* ... and break all links. */
13589 for_each_intel_connector(dev
, connector
) {
13590 if (connector
->encoder
->base
.crtc
!= &crtc
->base
)
13593 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
13594 connector
->base
.encoder
= NULL
;
13596 /* multiple connectors may have the same encoder:
13597 * handle them and break crtc link separately */
13598 for_each_intel_connector(dev
, connector
)
13599 if (connector
->encoder
->base
.crtc
== &crtc
->base
) {
13600 connector
->encoder
->base
.crtc
= NULL
;
13601 connector
->encoder
->connectors_active
= false;
13604 WARN_ON(crtc
->active
);
13605 crtc
->base
.state
->enable
= false;
13606 crtc
->base
.enabled
= false;
13609 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
13610 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
13611 /* BIOS forgot to enable pipe A, this mostly happens after
13612 * resume. Force-enable the pipe to fix this, the update_dpms
13613 * call below we restore the pipe to the right state, but leave
13614 * the required bits on. */
13615 intel_enable_pipe_a(dev
);
13618 /* Adjust the state of the output pipe according to whether we
13619 * have active connectors/encoders. */
13620 intel_crtc_update_dpms(&crtc
->base
);
13622 if (crtc
->active
!= crtc
->base
.state
->enable
) {
13623 struct intel_encoder
*encoder
;
13625 /* This can happen either due to bugs in the get_hw_state
13626 * functions or because the pipe is force-enabled due to the
13628 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
13629 crtc
->base
.base
.id
,
13630 crtc
->base
.state
->enable
? "enabled" : "disabled",
13631 crtc
->active
? "enabled" : "disabled");
13633 crtc
->base
.state
->enable
= crtc
->active
;
13634 crtc
->base
.enabled
= crtc
->active
;
13636 /* Because we only establish the connector -> encoder ->
13637 * crtc links if something is active, this means the
13638 * crtc is now deactivated. Break the links. connector
13639 * -> encoder links are only establish when things are
13640 * actually up, hence no need to break them. */
13641 WARN_ON(crtc
->active
);
13643 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
13644 WARN_ON(encoder
->connectors_active
);
13645 encoder
->base
.crtc
= NULL
;
13649 if (crtc
->active
|| HAS_GMCH_DISPLAY(dev
)) {
13651 * We start out with underrun reporting disabled to avoid races.
13652 * For correct bookkeeping mark this on active crtcs.
13654 * Also on gmch platforms we dont have any hardware bits to
13655 * disable the underrun reporting. Which means we need to start
13656 * out with underrun reporting disabled also on inactive pipes,
13657 * since otherwise we'll complain about the garbage we read when
13658 * e.g. coming up after runtime pm.
13660 * No protection against concurrent access is required - at
13661 * worst a fifo underrun happens which also sets this to false.
13663 crtc
->cpu_fifo_underrun_disabled
= true;
13664 crtc
->pch_fifo_underrun_disabled
= true;
13668 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
13670 struct intel_connector
*connector
;
13671 struct drm_device
*dev
= encoder
->base
.dev
;
13673 /* We need to check both for a crtc link (meaning that the
13674 * encoder is active and trying to read from a pipe) and the
13675 * pipe itself being active. */
13676 bool has_active_crtc
= encoder
->base
.crtc
&&
13677 to_intel_crtc(encoder
->base
.crtc
)->active
;
13679 if (encoder
->connectors_active
&& !has_active_crtc
) {
13680 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
13681 encoder
->base
.base
.id
,
13682 encoder
->base
.name
);
13684 /* Connector is active, but has no active pipe. This is
13685 * fallout from our resume register restoring. Disable
13686 * the encoder manually again. */
13687 if (encoder
->base
.crtc
) {
13688 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
13689 encoder
->base
.base
.id
,
13690 encoder
->base
.name
);
13691 encoder
->disable(encoder
);
13692 if (encoder
->post_disable
)
13693 encoder
->post_disable(encoder
);
13695 encoder
->base
.crtc
= NULL
;
13696 encoder
->connectors_active
= false;
13698 /* Inconsistent output/port/pipe state happens presumably due to
13699 * a bug in one of the get_hw_state functions. Or someplace else
13700 * in our code, like the register restore mess on resume. Clamp
13701 * things to off as a safer default. */
13702 for_each_intel_connector(dev
, connector
) {
13703 if (connector
->encoder
!= encoder
)
13705 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
13706 connector
->base
.encoder
= NULL
;
13709 /* Enabled encoders without active connectors will be fixed in
13710 * the crtc fixup. */
13713 void i915_redisable_vga_power_on(struct drm_device
*dev
)
13715 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13716 u32 vga_reg
= i915_vgacntrl_reg(dev
);
13718 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
13719 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
13720 i915_disable_vga(dev
);
13724 void i915_redisable_vga(struct drm_device
*dev
)
13726 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13728 /* This function can be called both from intel_modeset_setup_hw_state or
13729 * at a very early point in our resume sequence, where the power well
13730 * structures are not yet restored. Since this function is at a very
13731 * paranoid "someone might have enabled VGA while we were not looking"
13732 * level, just check if the power well is enabled instead of trying to
13733 * follow the "don't touch the power well if we don't need it" policy
13734 * the rest of the driver uses. */
13735 if (!intel_display_power_is_enabled(dev_priv
, POWER_DOMAIN_VGA
))
13738 i915_redisable_vga_power_on(dev
);
13741 static bool primary_get_hw_state(struct intel_crtc
*crtc
)
13743 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
13748 return I915_READ(DSPCNTR(crtc
->plane
)) & DISPLAY_PLANE_ENABLE
;
13751 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
13753 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13755 struct intel_crtc
*crtc
;
13756 struct intel_encoder
*encoder
;
13757 struct intel_connector
*connector
;
13760 for_each_intel_crtc(dev
, crtc
) {
13761 memset(crtc
->config
, 0, sizeof(*crtc
->config
));
13763 crtc
->config
->quirks
|= PIPE_CONFIG_QUIRK_INHERITED_MODE
;
13765 crtc
->active
= dev_priv
->display
.get_pipe_config(crtc
,
13768 crtc
->base
.state
->enable
= crtc
->active
;
13769 crtc
->base
.enabled
= crtc
->active
;
13770 crtc
->primary_enabled
= primary_get_hw_state(crtc
);
13772 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
13773 crtc
->base
.base
.id
,
13774 crtc
->active
? "enabled" : "disabled");
13777 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
13778 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
13780 pll
->on
= pll
->get_hw_state(dev_priv
, pll
,
13781 &pll
->config
.hw_state
);
13783 pll
->config
.crtc_mask
= 0;
13784 for_each_intel_crtc(dev
, crtc
) {
13785 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
) {
13787 pll
->config
.crtc_mask
|= 1 << crtc
->pipe
;
13791 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
13792 pll
->name
, pll
->config
.crtc_mask
, pll
->on
);
13794 if (pll
->config
.crtc_mask
)
13795 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
13798 for_each_intel_encoder(dev
, encoder
) {
13801 if (encoder
->get_hw_state(encoder
, &pipe
)) {
13802 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
13803 encoder
->base
.crtc
= &crtc
->base
;
13804 encoder
->get_config(encoder
, crtc
->config
);
13806 encoder
->base
.crtc
= NULL
;
13809 encoder
->connectors_active
= false;
13810 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
13811 encoder
->base
.base
.id
,
13812 encoder
->base
.name
,
13813 encoder
->base
.crtc
? "enabled" : "disabled",
13817 for_each_intel_connector(dev
, connector
) {
13818 if (connector
->get_hw_state(connector
)) {
13819 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
13820 connector
->encoder
->connectors_active
= true;
13821 connector
->base
.encoder
= &connector
->encoder
->base
;
13823 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
13824 connector
->base
.encoder
= NULL
;
13826 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
13827 connector
->base
.base
.id
,
13828 connector
->base
.name
,
13829 connector
->base
.encoder
? "enabled" : "disabled");
13833 /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
13834 * and i915 state tracking structures. */
13835 void intel_modeset_setup_hw_state(struct drm_device
*dev
,
13836 bool force_restore
)
13838 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13840 struct intel_crtc
*crtc
;
13841 struct intel_encoder
*encoder
;
13844 intel_modeset_readout_hw_state(dev
);
13847 * Now that we have the config, copy it to each CRTC struct
13848 * Note that this could go away if we move to using crtc_config
13849 * checking everywhere.
13851 for_each_intel_crtc(dev
, crtc
) {
13852 if (crtc
->active
&& i915
.fastboot
) {
13853 intel_mode_from_pipe_config(&crtc
->base
.mode
,
13855 DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
13856 crtc
->base
.base
.id
);
13857 drm_mode_debug_printmodeline(&crtc
->base
.mode
);
13861 /* HW state is read out, now we need to sanitize this mess. */
13862 for_each_intel_encoder(dev
, encoder
) {
13863 intel_sanitize_encoder(encoder
);
13866 for_each_pipe(dev_priv
, pipe
) {
13867 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
13868 intel_sanitize_crtc(crtc
);
13869 intel_dump_pipe_config(crtc
, crtc
->config
,
13870 "[setup_hw_state]");
13873 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
13874 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
13876 if (!pll
->on
|| pll
->active
)
13879 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
13881 pll
->disable(dev_priv
, pll
);
13886 skl_wm_get_hw_state(dev
);
13887 else if (HAS_PCH_SPLIT(dev
))
13888 ilk_wm_get_hw_state(dev
);
13890 if (force_restore
) {
13891 i915_redisable_vga(dev
);
13894 * We need to use raw interfaces for restoring state to avoid
13895 * checking (bogus) intermediate states.
13897 for_each_pipe(dev_priv
, pipe
) {
13898 struct drm_crtc
*crtc
=
13899 dev_priv
->pipe_to_crtc_mapping
[pipe
];
13901 intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
,
13902 crtc
->primary
->fb
);
13905 intel_modeset_update_staged_output_state(dev
);
13908 intel_modeset_check_state(dev
);
13911 void intel_modeset_gem_init(struct drm_device
*dev
)
13913 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13914 struct drm_crtc
*c
;
13915 struct drm_i915_gem_object
*obj
;
13917 mutex_lock(&dev
->struct_mutex
);
13918 intel_init_gt_powersave(dev
);
13919 mutex_unlock(&dev
->struct_mutex
);
13922 * There may be no VBT; and if the BIOS enabled SSC we can
13923 * just keep using it to avoid unnecessary flicker. Whereas if the
13924 * BIOS isn't using it, don't assume it will work even if the VBT
13925 * indicates as much.
13927 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
13928 dev_priv
->vbt
.lvds_use_ssc
= !!(I915_READ(PCH_DREF_CONTROL
) &
13931 intel_modeset_init_hw(dev
);
13933 intel_setup_overlay(dev
);
13936 * Make sure any fbs we allocated at startup are properly
13937 * pinned & fenced. When we do the allocation it's too early
13940 mutex_lock(&dev
->struct_mutex
);
13941 for_each_crtc(dev
, c
) {
13942 obj
= intel_fb_obj(c
->primary
->fb
);
13946 if (intel_pin_and_fence_fb_obj(c
->primary
,
13950 DRM_ERROR("failed to pin boot fb on pipe %d\n",
13951 to_intel_crtc(c
)->pipe
);
13952 drm_framebuffer_unreference(c
->primary
->fb
);
13953 c
->primary
->fb
= NULL
;
13954 update_state_fb(c
->primary
);
13957 mutex_unlock(&dev
->struct_mutex
);
13959 intel_backlight_register(dev
);
13962 void intel_connector_unregister(struct intel_connector
*intel_connector
)
13964 struct drm_connector
*connector
= &intel_connector
->base
;
13966 intel_panel_destroy_backlight(connector
);
13967 drm_connector_unregister(connector
);
13970 void intel_modeset_cleanup(struct drm_device
*dev
)
13972 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13973 struct drm_connector
*connector
;
13975 intel_disable_gt_powersave(dev
);
13977 intel_backlight_unregister(dev
);
13980 * Interrupts and polling as the first thing to avoid creating havoc.
13981 * Too much stuff here (turning of connectors, ...) would
13982 * experience fancy races otherwise.
13984 intel_irq_uninstall(dev_priv
);
13987 * Due to the hpd irq storm handling the hotplug work can re-arm the
13988 * poll handlers. Hence disable polling after hpd handling is shut down.
13990 drm_kms_helper_poll_fini(dev
);
13992 mutex_lock(&dev
->struct_mutex
);
13994 intel_unregister_dsm_handler();
13996 intel_fbc_disable(dev
);
13998 mutex_unlock(&dev
->struct_mutex
);
14000 /* flush any delayed tasks or pending work */
14001 flush_scheduled_work();
14003 /* destroy the backlight and sysfs files before encoders/connectors */
14004 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
14005 struct intel_connector
*intel_connector
;
14007 intel_connector
= to_intel_connector(connector
);
14008 intel_connector
->unregister(intel_connector
);
14011 drm_mode_config_cleanup(dev
);
14013 intel_cleanup_overlay(dev
);
14015 mutex_lock(&dev
->struct_mutex
);
14016 intel_cleanup_gt_powersave(dev
);
14017 mutex_unlock(&dev
->struct_mutex
);
14021 * Return which encoder is currently attached for connector.
14023 struct drm_encoder
*intel_best_encoder(struct drm_connector
*connector
)
14025 return &intel_attached_encoder(connector
)->base
;
14028 void intel_connector_attach_encoder(struct intel_connector
*connector
,
14029 struct intel_encoder
*encoder
)
14031 connector
->encoder
= encoder
;
14032 drm_mode_connector_attach_encoder(&connector
->base
,
14037 * set vga decode state - true == enable VGA decode
14039 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
14041 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14042 unsigned reg
= INTEL_INFO(dev
)->gen
>= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
14045 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
14046 DRM_ERROR("failed to read control word\n");
14050 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
14054 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
14056 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
14058 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
14059 DRM_ERROR("failed to write control word\n");
14066 struct intel_display_error_state
{
14068 u32 power_well_driver
;
14070 int num_transcoders
;
14072 struct intel_cursor_error_state
{
14077 } cursor
[I915_MAX_PIPES
];
14079 struct intel_pipe_error_state
{
14080 bool power_domain_on
;
14083 } pipe
[I915_MAX_PIPES
];
14085 struct intel_plane_error_state
{
14093 } plane
[I915_MAX_PIPES
];
14095 struct intel_transcoder_error_state
{
14096 bool power_domain_on
;
14097 enum transcoder cpu_transcoder
;
14110 struct intel_display_error_state
*
14111 intel_display_capture_error_state(struct drm_device
*dev
)
14113 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14114 struct intel_display_error_state
*error
;
14115 int transcoders
[] = {
14123 if (INTEL_INFO(dev
)->num_pipes
== 0)
14126 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
14130 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
14131 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
14133 for_each_pipe(dev_priv
, i
) {
14134 error
->pipe
[i
].power_domain_on
=
14135 __intel_display_power_is_enabled(dev_priv
,
14136 POWER_DOMAIN_PIPE(i
));
14137 if (!error
->pipe
[i
].power_domain_on
)
14140 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
14141 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
14142 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
14144 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
14145 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
14146 if (INTEL_INFO(dev
)->gen
<= 3) {
14147 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
14148 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
14150 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
14151 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
14152 if (INTEL_INFO(dev
)->gen
>= 4) {
14153 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
14154 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
14157 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
14159 if (HAS_GMCH_DISPLAY(dev
))
14160 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
14163 error
->num_transcoders
= INTEL_INFO(dev
)->num_pipes
;
14164 if (HAS_DDI(dev_priv
->dev
))
14165 error
->num_transcoders
++; /* Account for eDP. */
14167 for (i
= 0; i
< error
->num_transcoders
; i
++) {
14168 enum transcoder cpu_transcoder
= transcoders
[i
];
14170 error
->transcoder
[i
].power_domain_on
=
14171 __intel_display_power_is_enabled(dev_priv
,
14172 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
14173 if (!error
->transcoder
[i
].power_domain_on
)
14176 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
14178 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
14179 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
14180 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
14181 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
14182 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
14183 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
14184 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
14190 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
14193 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
14194 struct drm_device
*dev
,
14195 struct intel_display_error_state
*error
)
14197 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14203 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev
)->num_pipes
);
14204 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
14205 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
14206 error
->power_well_driver
);
14207 for_each_pipe(dev_priv
, i
) {
14208 err_printf(m
, "Pipe [%d]:\n", i
);
14209 err_printf(m
, " Power: %s\n",
14210 error
->pipe
[i
].power_domain_on
? "on" : "off");
14211 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
14212 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
14214 err_printf(m
, "Plane [%d]:\n", i
);
14215 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
14216 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
14217 if (INTEL_INFO(dev
)->gen
<= 3) {
14218 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
14219 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
14221 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
14222 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
14223 if (INTEL_INFO(dev
)->gen
>= 4) {
14224 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
14225 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
14228 err_printf(m
, "Cursor [%d]:\n", i
);
14229 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
14230 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
14231 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
14234 for (i
= 0; i
< error
->num_transcoders
; i
++) {
14235 err_printf(m
, "CPU transcoder: %c\n",
14236 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
14237 err_printf(m
, " Power: %s\n",
14238 error
->transcoder
[i
].power_domain_on
? "on" : "off");
14239 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
14240 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
14241 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
14242 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
14243 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
14244 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
14245 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);
14249 void intel_modeset_preclose(struct drm_device
*dev
, struct drm_file
*file
)
14251 struct intel_crtc
*crtc
;
14253 for_each_intel_crtc(dev
, crtc
) {
14254 struct intel_unpin_work
*work
;
14256 spin_lock_irq(&dev
->event_lock
);
14258 work
= crtc
->unpin_work
;
14260 if (work
&& work
->event
&&
14261 work
->event
->base
.file_priv
== file
) {
14262 kfree(work
->event
);
14263 work
->event
= NULL
;
14266 spin_unlock_irq(&dev
->event_lock
);