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 struct drm_atomic_state
*state
);
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
);
105 static void skl_init_scalers(struct drm_device
*dev
, struct intel_crtc
*intel_crtc
,
106 struct intel_crtc_state
*crtc_state
);
107 static int i9xx_get_refclk(const struct intel_crtc_state
*crtc_state
,
109 static void intel_crtc_enable_planes(struct drm_crtc
*crtc
);
110 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
);
112 static struct intel_encoder
*intel_find_encoder(struct intel_connector
*connector
, int pipe
)
114 if (!connector
->mst_port
)
115 return connector
->encoder
;
117 return &connector
->mst_port
->mst_encoders
[pipe
]->base
;
126 int p2_slow
, p2_fast
;
129 typedef struct intel_limit intel_limit_t
;
131 intel_range_t dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
136 intel_pch_rawclk(struct drm_device
*dev
)
138 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
140 WARN_ON(!HAS_PCH_SPLIT(dev
));
142 return I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
;
145 static inline u32
/* units of 100MHz */
146 intel_fdi_link_freq(struct drm_device
*dev
)
149 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
150 return (I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2;
155 static const intel_limit_t intel_limits_i8xx_dac
= {
156 .dot
= { .min
= 25000, .max
= 350000 },
157 .vco
= { .min
= 908000, .max
= 1512000 },
158 .n
= { .min
= 2, .max
= 16 },
159 .m
= { .min
= 96, .max
= 140 },
160 .m1
= { .min
= 18, .max
= 26 },
161 .m2
= { .min
= 6, .max
= 16 },
162 .p
= { .min
= 4, .max
= 128 },
163 .p1
= { .min
= 2, .max
= 33 },
164 .p2
= { .dot_limit
= 165000,
165 .p2_slow
= 4, .p2_fast
= 2 },
168 static const intel_limit_t intel_limits_i8xx_dvo
= {
169 .dot
= { .min
= 25000, .max
= 350000 },
170 .vco
= { .min
= 908000, .max
= 1512000 },
171 .n
= { .min
= 2, .max
= 16 },
172 .m
= { .min
= 96, .max
= 140 },
173 .m1
= { .min
= 18, .max
= 26 },
174 .m2
= { .min
= 6, .max
= 16 },
175 .p
= { .min
= 4, .max
= 128 },
176 .p1
= { .min
= 2, .max
= 33 },
177 .p2
= { .dot_limit
= 165000,
178 .p2_slow
= 4, .p2_fast
= 4 },
181 static const intel_limit_t intel_limits_i8xx_lvds
= {
182 .dot
= { .min
= 25000, .max
= 350000 },
183 .vco
= { .min
= 908000, .max
= 1512000 },
184 .n
= { .min
= 2, .max
= 16 },
185 .m
= { .min
= 96, .max
= 140 },
186 .m1
= { .min
= 18, .max
= 26 },
187 .m2
= { .min
= 6, .max
= 16 },
188 .p
= { .min
= 4, .max
= 128 },
189 .p1
= { .min
= 1, .max
= 6 },
190 .p2
= { .dot_limit
= 165000,
191 .p2_slow
= 14, .p2_fast
= 7 },
194 static const intel_limit_t intel_limits_i9xx_sdvo
= {
195 .dot
= { .min
= 20000, .max
= 400000 },
196 .vco
= { .min
= 1400000, .max
= 2800000 },
197 .n
= { .min
= 1, .max
= 6 },
198 .m
= { .min
= 70, .max
= 120 },
199 .m1
= { .min
= 8, .max
= 18 },
200 .m2
= { .min
= 3, .max
= 7 },
201 .p
= { .min
= 5, .max
= 80 },
202 .p1
= { .min
= 1, .max
= 8 },
203 .p2
= { .dot_limit
= 200000,
204 .p2_slow
= 10, .p2_fast
= 5 },
207 static const intel_limit_t intel_limits_i9xx_lvds
= {
208 .dot
= { .min
= 20000, .max
= 400000 },
209 .vco
= { .min
= 1400000, .max
= 2800000 },
210 .n
= { .min
= 1, .max
= 6 },
211 .m
= { .min
= 70, .max
= 120 },
212 .m1
= { .min
= 8, .max
= 18 },
213 .m2
= { .min
= 3, .max
= 7 },
214 .p
= { .min
= 7, .max
= 98 },
215 .p1
= { .min
= 1, .max
= 8 },
216 .p2
= { .dot_limit
= 112000,
217 .p2_slow
= 14, .p2_fast
= 7 },
221 static const intel_limit_t intel_limits_g4x_sdvo
= {
222 .dot
= { .min
= 25000, .max
= 270000 },
223 .vco
= { .min
= 1750000, .max
= 3500000},
224 .n
= { .min
= 1, .max
= 4 },
225 .m
= { .min
= 104, .max
= 138 },
226 .m1
= { .min
= 17, .max
= 23 },
227 .m2
= { .min
= 5, .max
= 11 },
228 .p
= { .min
= 10, .max
= 30 },
229 .p1
= { .min
= 1, .max
= 3},
230 .p2
= { .dot_limit
= 270000,
236 static const intel_limit_t intel_limits_g4x_hdmi
= {
237 .dot
= { .min
= 22000, .max
= 400000 },
238 .vco
= { .min
= 1750000, .max
= 3500000},
239 .n
= { .min
= 1, .max
= 4 },
240 .m
= { .min
= 104, .max
= 138 },
241 .m1
= { .min
= 16, .max
= 23 },
242 .m2
= { .min
= 5, .max
= 11 },
243 .p
= { .min
= 5, .max
= 80 },
244 .p1
= { .min
= 1, .max
= 8},
245 .p2
= { .dot_limit
= 165000,
246 .p2_slow
= 10, .p2_fast
= 5 },
249 static const intel_limit_t intel_limits_g4x_single_channel_lvds
= {
250 .dot
= { .min
= 20000, .max
= 115000 },
251 .vco
= { .min
= 1750000, .max
= 3500000 },
252 .n
= { .min
= 1, .max
= 3 },
253 .m
= { .min
= 104, .max
= 138 },
254 .m1
= { .min
= 17, .max
= 23 },
255 .m2
= { .min
= 5, .max
= 11 },
256 .p
= { .min
= 28, .max
= 112 },
257 .p1
= { .min
= 2, .max
= 8 },
258 .p2
= { .dot_limit
= 0,
259 .p2_slow
= 14, .p2_fast
= 14
263 static const intel_limit_t intel_limits_g4x_dual_channel_lvds
= {
264 .dot
= { .min
= 80000, .max
= 224000 },
265 .vco
= { .min
= 1750000, .max
= 3500000 },
266 .n
= { .min
= 1, .max
= 3 },
267 .m
= { .min
= 104, .max
= 138 },
268 .m1
= { .min
= 17, .max
= 23 },
269 .m2
= { .min
= 5, .max
= 11 },
270 .p
= { .min
= 14, .max
= 42 },
271 .p1
= { .min
= 2, .max
= 6 },
272 .p2
= { .dot_limit
= 0,
273 .p2_slow
= 7, .p2_fast
= 7
277 static const intel_limit_t intel_limits_pineview_sdvo
= {
278 .dot
= { .min
= 20000, .max
= 400000},
279 .vco
= { .min
= 1700000, .max
= 3500000 },
280 /* Pineview's Ncounter is a ring counter */
281 .n
= { .min
= 3, .max
= 6 },
282 .m
= { .min
= 2, .max
= 256 },
283 /* Pineview only has one combined m divider, which we treat as m2. */
284 .m1
= { .min
= 0, .max
= 0 },
285 .m2
= { .min
= 0, .max
= 254 },
286 .p
= { .min
= 5, .max
= 80 },
287 .p1
= { .min
= 1, .max
= 8 },
288 .p2
= { .dot_limit
= 200000,
289 .p2_slow
= 10, .p2_fast
= 5 },
292 static const intel_limit_t intel_limits_pineview_lvds
= {
293 .dot
= { .min
= 20000, .max
= 400000 },
294 .vco
= { .min
= 1700000, .max
= 3500000 },
295 .n
= { .min
= 3, .max
= 6 },
296 .m
= { .min
= 2, .max
= 256 },
297 .m1
= { .min
= 0, .max
= 0 },
298 .m2
= { .min
= 0, .max
= 254 },
299 .p
= { .min
= 7, .max
= 112 },
300 .p1
= { .min
= 1, .max
= 8 },
301 .p2
= { .dot_limit
= 112000,
302 .p2_slow
= 14, .p2_fast
= 14 },
305 /* Ironlake / Sandybridge
307 * We calculate clock using (register_value + 2) for N/M1/M2, so here
308 * the range value for them is (actual_value - 2).
310 static const intel_limit_t intel_limits_ironlake_dac
= {
311 .dot
= { .min
= 25000, .max
= 350000 },
312 .vco
= { .min
= 1760000, .max
= 3510000 },
313 .n
= { .min
= 1, .max
= 5 },
314 .m
= { .min
= 79, .max
= 127 },
315 .m1
= { .min
= 12, .max
= 22 },
316 .m2
= { .min
= 5, .max
= 9 },
317 .p
= { .min
= 5, .max
= 80 },
318 .p1
= { .min
= 1, .max
= 8 },
319 .p2
= { .dot_limit
= 225000,
320 .p2_slow
= 10, .p2_fast
= 5 },
323 static const intel_limit_t intel_limits_ironlake_single_lvds
= {
324 .dot
= { .min
= 25000, .max
= 350000 },
325 .vco
= { .min
= 1760000, .max
= 3510000 },
326 .n
= { .min
= 1, .max
= 3 },
327 .m
= { .min
= 79, .max
= 118 },
328 .m1
= { .min
= 12, .max
= 22 },
329 .m2
= { .min
= 5, .max
= 9 },
330 .p
= { .min
= 28, .max
= 112 },
331 .p1
= { .min
= 2, .max
= 8 },
332 .p2
= { .dot_limit
= 225000,
333 .p2_slow
= 14, .p2_fast
= 14 },
336 static const intel_limit_t intel_limits_ironlake_dual_lvds
= {
337 .dot
= { .min
= 25000, .max
= 350000 },
338 .vco
= { .min
= 1760000, .max
= 3510000 },
339 .n
= { .min
= 1, .max
= 3 },
340 .m
= { .min
= 79, .max
= 127 },
341 .m1
= { .min
= 12, .max
= 22 },
342 .m2
= { .min
= 5, .max
= 9 },
343 .p
= { .min
= 14, .max
= 56 },
344 .p1
= { .min
= 2, .max
= 8 },
345 .p2
= { .dot_limit
= 225000,
346 .p2_slow
= 7, .p2_fast
= 7 },
349 /* LVDS 100mhz refclk limits. */
350 static const intel_limit_t intel_limits_ironlake_single_lvds_100m
= {
351 .dot
= { .min
= 25000, .max
= 350000 },
352 .vco
= { .min
= 1760000, .max
= 3510000 },
353 .n
= { .min
= 1, .max
= 2 },
354 .m
= { .min
= 79, .max
= 126 },
355 .m1
= { .min
= 12, .max
= 22 },
356 .m2
= { .min
= 5, .max
= 9 },
357 .p
= { .min
= 28, .max
= 112 },
358 .p1
= { .min
= 2, .max
= 8 },
359 .p2
= { .dot_limit
= 225000,
360 .p2_slow
= 14, .p2_fast
= 14 },
363 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m
= {
364 .dot
= { .min
= 25000, .max
= 350000 },
365 .vco
= { .min
= 1760000, .max
= 3510000 },
366 .n
= { .min
= 1, .max
= 3 },
367 .m
= { .min
= 79, .max
= 126 },
368 .m1
= { .min
= 12, .max
= 22 },
369 .m2
= { .min
= 5, .max
= 9 },
370 .p
= { .min
= 14, .max
= 42 },
371 .p1
= { .min
= 2, .max
= 6 },
372 .p2
= { .dot_limit
= 225000,
373 .p2_slow
= 7, .p2_fast
= 7 },
376 static const intel_limit_t intel_limits_vlv
= {
378 * These are the data rate limits (measured in fast clocks)
379 * since those are the strictest limits we have. The fast
380 * clock and actual rate limits are more relaxed, so checking
381 * them would make no difference.
383 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
384 .vco
= { .min
= 4000000, .max
= 6000000 },
385 .n
= { .min
= 1, .max
= 7 },
386 .m1
= { .min
= 2, .max
= 3 },
387 .m2
= { .min
= 11, .max
= 156 },
388 .p1
= { .min
= 2, .max
= 3 },
389 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
392 static const intel_limit_t intel_limits_chv
= {
394 * These are the data rate limits (measured in fast clocks)
395 * since those are the strictest limits we have. The fast
396 * clock and actual rate limits are more relaxed, so checking
397 * them would make no difference.
399 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
400 .vco
= { .min
= 4800000, .max
= 6480000 },
401 .n
= { .min
= 1, .max
= 1 },
402 .m1
= { .min
= 2, .max
= 2 },
403 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
404 .p1
= { .min
= 2, .max
= 4 },
405 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
408 static const intel_limit_t intel_limits_bxt
= {
409 /* FIXME: find real dot limits */
410 .dot
= { .min
= 0, .max
= INT_MAX
},
411 .vco
= { .min
= 4800000, .max
= 6480000 },
412 .n
= { .min
= 1, .max
= 1 },
413 .m1
= { .min
= 2, .max
= 2 },
414 /* FIXME: find real m2 limits */
415 .m2
= { .min
= 2 << 22, .max
= 255 << 22 },
416 .p1
= { .min
= 2, .max
= 4 },
417 .p2
= { .p2_slow
= 1, .p2_fast
= 20 },
420 static void vlv_clock(int refclk
, intel_clock_t
*clock
)
422 clock
->m
= clock
->m1
* clock
->m2
;
423 clock
->p
= clock
->p1
* clock
->p2
;
424 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
426 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
427 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
431 * Returns whether any output on the specified pipe is of the specified type
433 bool intel_pipe_has_type(struct intel_crtc
*crtc
, enum intel_output_type type
)
435 struct drm_device
*dev
= crtc
->base
.dev
;
436 struct intel_encoder
*encoder
;
438 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
439 if (encoder
->type
== type
)
446 * Returns whether any output on the specified pipe will have the specified
447 * type after a staged modeset is complete, i.e., the same as
448 * intel_pipe_has_type() but looking at encoder->new_crtc instead of
451 static bool intel_pipe_will_have_type(const struct intel_crtc_state
*crtc_state
,
454 struct drm_atomic_state
*state
= crtc_state
->base
.state
;
455 struct drm_connector
*connector
;
456 struct drm_connector_state
*connector_state
;
457 struct intel_encoder
*encoder
;
458 int i
, num_connectors
= 0;
460 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
461 if (connector_state
->crtc
!= crtc_state
->base
.crtc
)
466 encoder
= to_intel_encoder(connector_state
->best_encoder
);
467 if (encoder
->type
== type
)
471 WARN_ON(num_connectors
== 0);
476 static const intel_limit_t
*
477 intel_ironlake_limit(struct intel_crtc_state
*crtc_state
, int refclk
)
479 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
480 const intel_limit_t
*limit
;
482 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
483 if (intel_is_dual_link_lvds(dev
)) {
484 if (refclk
== 100000)
485 limit
= &intel_limits_ironlake_dual_lvds_100m
;
487 limit
= &intel_limits_ironlake_dual_lvds
;
489 if (refclk
== 100000)
490 limit
= &intel_limits_ironlake_single_lvds_100m
;
492 limit
= &intel_limits_ironlake_single_lvds
;
495 limit
= &intel_limits_ironlake_dac
;
500 static const intel_limit_t
*
501 intel_g4x_limit(struct intel_crtc_state
*crtc_state
)
503 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
504 const intel_limit_t
*limit
;
506 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
507 if (intel_is_dual_link_lvds(dev
))
508 limit
= &intel_limits_g4x_dual_channel_lvds
;
510 limit
= &intel_limits_g4x_single_channel_lvds
;
511 } else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_HDMI
) ||
512 intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_ANALOG
)) {
513 limit
= &intel_limits_g4x_hdmi
;
514 } else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_SDVO
)) {
515 limit
= &intel_limits_g4x_sdvo
;
516 } else /* The option is for other outputs */
517 limit
= &intel_limits_i9xx_sdvo
;
522 static const intel_limit_t
*
523 intel_limit(struct intel_crtc_state
*crtc_state
, int refclk
)
525 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
526 const intel_limit_t
*limit
;
529 limit
= &intel_limits_bxt
;
530 else if (HAS_PCH_SPLIT(dev
))
531 limit
= intel_ironlake_limit(crtc_state
, refclk
);
532 else if (IS_G4X(dev
)) {
533 limit
= intel_g4x_limit(crtc_state
);
534 } else if (IS_PINEVIEW(dev
)) {
535 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
))
536 limit
= &intel_limits_pineview_lvds
;
538 limit
= &intel_limits_pineview_sdvo
;
539 } else if (IS_CHERRYVIEW(dev
)) {
540 limit
= &intel_limits_chv
;
541 } else if (IS_VALLEYVIEW(dev
)) {
542 limit
= &intel_limits_vlv
;
543 } else if (!IS_GEN2(dev
)) {
544 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
))
545 limit
= &intel_limits_i9xx_lvds
;
547 limit
= &intel_limits_i9xx_sdvo
;
549 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
))
550 limit
= &intel_limits_i8xx_lvds
;
551 else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_DVO
))
552 limit
= &intel_limits_i8xx_dvo
;
554 limit
= &intel_limits_i8xx_dac
;
559 /* m1 is reserved as 0 in Pineview, n is a ring counter */
560 static void pineview_clock(int refclk
, intel_clock_t
*clock
)
562 clock
->m
= clock
->m2
+ 2;
563 clock
->p
= clock
->p1
* clock
->p2
;
564 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
566 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
567 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
570 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
572 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
575 static void i9xx_clock(int refclk
, intel_clock_t
*clock
)
577 clock
->m
= i9xx_dpll_compute_m(clock
);
578 clock
->p
= clock
->p1
* clock
->p2
;
579 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
581 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
582 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
585 static void chv_clock(int refclk
, intel_clock_t
*clock
)
587 clock
->m
= clock
->m1
* clock
->m2
;
588 clock
->p
= clock
->p1
* clock
->p2
;
589 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
591 clock
->vco
= DIV_ROUND_CLOSEST_ULL((uint64_t)refclk
* clock
->m
,
593 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
596 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
598 * Returns whether the given set of divisors are valid for a given refclk with
599 * the given connectors.
602 static bool intel_PLL_is_valid(struct drm_device
*dev
,
603 const intel_limit_t
*limit
,
604 const intel_clock_t
*clock
)
606 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
607 INTELPllInvalid("n out of range\n");
608 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
609 INTELPllInvalid("p1 out of range\n");
610 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
611 INTELPllInvalid("m2 out of range\n");
612 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
613 INTELPllInvalid("m1 out of range\n");
615 if (!IS_PINEVIEW(dev
) && !IS_VALLEYVIEW(dev
) && !IS_BROXTON(dev
))
616 if (clock
->m1
<= clock
->m2
)
617 INTELPllInvalid("m1 <= m2\n");
619 if (!IS_VALLEYVIEW(dev
) && !IS_BROXTON(dev
)) {
620 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
621 INTELPllInvalid("p out of range\n");
622 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
623 INTELPllInvalid("m out of range\n");
626 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
627 INTELPllInvalid("vco out of range\n");
628 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
629 * connector, etc., rather than just a single range.
631 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
632 INTELPllInvalid("dot out of range\n");
638 i9xx_find_best_dpll(const intel_limit_t
*limit
,
639 struct intel_crtc_state
*crtc_state
,
640 int target
, int refclk
, intel_clock_t
*match_clock
,
641 intel_clock_t
*best_clock
)
643 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
644 struct drm_device
*dev
= crtc
->base
.dev
;
648 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
650 * For LVDS just rely on its current settings for dual-channel.
651 * We haven't figured out how to reliably set up different
652 * single/dual channel state, if we even can.
654 if (intel_is_dual_link_lvds(dev
))
655 clock
.p2
= limit
->p2
.p2_fast
;
657 clock
.p2
= limit
->p2
.p2_slow
;
659 if (target
< limit
->p2
.dot_limit
)
660 clock
.p2
= limit
->p2
.p2_slow
;
662 clock
.p2
= limit
->p2
.p2_fast
;
665 memset(best_clock
, 0, sizeof(*best_clock
));
667 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
669 for (clock
.m2
= limit
->m2
.min
;
670 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
671 if (clock
.m2
>= clock
.m1
)
673 for (clock
.n
= limit
->n
.min
;
674 clock
.n
<= limit
->n
.max
; clock
.n
++) {
675 for (clock
.p1
= limit
->p1
.min
;
676 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
679 i9xx_clock(refclk
, &clock
);
680 if (!intel_PLL_is_valid(dev
, limit
,
684 clock
.p
!= match_clock
->p
)
687 this_err
= abs(clock
.dot
- target
);
688 if (this_err
< err
) {
697 return (err
!= target
);
701 pnv_find_best_dpll(const intel_limit_t
*limit
,
702 struct intel_crtc_state
*crtc_state
,
703 int target
, int refclk
, intel_clock_t
*match_clock
,
704 intel_clock_t
*best_clock
)
706 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
707 struct drm_device
*dev
= crtc
->base
.dev
;
711 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
713 * For LVDS just rely on its current settings for dual-channel.
714 * We haven't figured out how to reliably set up different
715 * single/dual channel state, if we even can.
717 if (intel_is_dual_link_lvds(dev
))
718 clock
.p2
= limit
->p2
.p2_fast
;
720 clock
.p2
= limit
->p2
.p2_slow
;
722 if (target
< limit
->p2
.dot_limit
)
723 clock
.p2
= limit
->p2
.p2_slow
;
725 clock
.p2
= limit
->p2
.p2_fast
;
728 memset(best_clock
, 0, sizeof(*best_clock
));
730 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
732 for (clock
.m2
= limit
->m2
.min
;
733 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
734 for (clock
.n
= limit
->n
.min
;
735 clock
.n
<= limit
->n
.max
; clock
.n
++) {
736 for (clock
.p1
= limit
->p1
.min
;
737 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
740 pineview_clock(refclk
, &clock
);
741 if (!intel_PLL_is_valid(dev
, limit
,
745 clock
.p
!= match_clock
->p
)
748 this_err
= abs(clock
.dot
- target
);
749 if (this_err
< err
) {
758 return (err
!= target
);
762 g4x_find_best_dpll(const intel_limit_t
*limit
,
763 struct intel_crtc_state
*crtc_state
,
764 int target
, int refclk
, intel_clock_t
*match_clock
,
765 intel_clock_t
*best_clock
)
767 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
768 struct drm_device
*dev
= crtc
->base
.dev
;
772 /* approximately equals target * 0.00585 */
773 int err_most
= (target
>> 8) + (target
>> 9);
776 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
777 if (intel_is_dual_link_lvds(dev
))
778 clock
.p2
= limit
->p2
.p2_fast
;
780 clock
.p2
= limit
->p2
.p2_slow
;
782 if (target
< limit
->p2
.dot_limit
)
783 clock
.p2
= limit
->p2
.p2_slow
;
785 clock
.p2
= limit
->p2
.p2_fast
;
788 memset(best_clock
, 0, sizeof(*best_clock
));
789 max_n
= limit
->n
.max
;
790 /* based on hardware requirement, prefer smaller n to precision */
791 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
792 /* based on hardware requirement, prefere larger m1,m2 */
793 for (clock
.m1
= limit
->m1
.max
;
794 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
795 for (clock
.m2
= limit
->m2
.max
;
796 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
797 for (clock
.p1
= limit
->p1
.max
;
798 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
801 i9xx_clock(refclk
, &clock
);
802 if (!intel_PLL_is_valid(dev
, limit
,
806 this_err
= abs(clock
.dot
- target
);
807 if (this_err
< err_most
) {
821 * Check if the calculated PLL configuration is more optimal compared to the
822 * best configuration and error found so far. Return the calculated error.
824 static bool vlv_PLL_is_optimal(struct drm_device
*dev
, int target_freq
,
825 const intel_clock_t
*calculated_clock
,
826 const intel_clock_t
*best_clock
,
827 unsigned int best_error_ppm
,
828 unsigned int *error_ppm
)
831 * For CHV ignore the error and consider only the P value.
832 * Prefer a bigger P value based on HW requirements.
834 if (IS_CHERRYVIEW(dev
)) {
837 return calculated_clock
->p
> best_clock
->p
;
840 if (WARN_ON_ONCE(!target_freq
))
843 *error_ppm
= div_u64(1000000ULL *
844 abs(target_freq
- calculated_clock
->dot
),
847 * Prefer a better P value over a better (smaller) error if the error
848 * is small. Ensure this preference for future configurations too by
849 * setting the error to 0.
851 if (*error_ppm
< 100 && calculated_clock
->p
> best_clock
->p
) {
857 return *error_ppm
+ 10 < best_error_ppm
;
861 vlv_find_best_dpll(const intel_limit_t
*limit
,
862 struct intel_crtc_state
*crtc_state
,
863 int target
, int refclk
, intel_clock_t
*match_clock
,
864 intel_clock_t
*best_clock
)
866 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
867 struct drm_device
*dev
= crtc
->base
.dev
;
869 unsigned int bestppm
= 1000000;
870 /* min update 19.2 MHz */
871 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
874 target
*= 5; /* fast clock */
876 memset(best_clock
, 0, sizeof(*best_clock
));
878 /* based on hardware requirement, prefer smaller n to precision */
879 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
880 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
881 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
882 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
883 clock
.p
= clock
.p1
* clock
.p2
;
884 /* based on hardware requirement, prefer bigger m1,m2 values */
885 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
888 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
891 vlv_clock(refclk
, &clock
);
893 if (!intel_PLL_is_valid(dev
, limit
,
897 if (!vlv_PLL_is_optimal(dev
, target
,
915 chv_find_best_dpll(const intel_limit_t
*limit
,
916 struct intel_crtc_state
*crtc_state
,
917 int target
, int refclk
, intel_clock_t
*match_clock
,
918 intel_clock_t
*best_clock
)
920 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
921 struct drm_device
*dev
= crtc
->base
.dev
;
922 unsigned int best_error_ppm
;
927 memset(best_clock
, 0, sizeof(*best_clock
));
928 best_error_ppm
= 1000000;
931 * Based on hardware doc, the n always set to 1, and m1 always
932 * set to 2. If requires to support 200Mhz refclk, we need to
933 * revisit this because n may not 1 anymore.
935 clock
.n
= 1, clock
.m1
= 2;
936 target
*= 5; /* fast clock */
938 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
939 for (clock
.p2
= limit
->p2
.p2_fast
;
940 clock
.p2
>= limit
->p2
.p2_slow
;
941 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
942 unsigned int error_ppm
;
944 clock
.p
= clock
.p1
* clock
.p2
;
946 m2
= DIV_ROUND_CLOSEST_ULL(((uint64_t)target
* clock
.p
*
947 clock
.n
) << 22, refclk
* clock
.m1
);
949 if (m2
> INT_MAX
/clock
.m1
)
954 chv_clock(refclk
, &clock
);
956 if (!intel_PLL_is_valid(dev
, limit
, &clock
))
959 if (!vlv_PLL_is_optimal(dev
, target
, &clock
, best_clock
,
960 best_error_ppm
, &error_ppm
))
964 best_error_ppm
= error_ppm
;
972 bool bxt_find_best_dpll(struct intel_crtc_state
*crtc_state
, int target_clock
,
973 intel_clock_t
*best_clock
)
975 int refclk
= i9xx_get_refclk(crtc_state
, 0);
977 return chv_find_best_dpll(intel_limit(crtc_state
, refclk
), crtc_state
,
978 target_clock
, refclk
, NULL
, best_clock
);
981 bool intel_crtc_active(struct drm_crtc
*crtc
)
983 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
985 /* Be paranoid as we can arrive here with only partial
986 * state retrieved from the hardware during setup.
988 * We can ditch the adjusted_mode.crtc_clock check as soon
989 * as Haswell has gained clock readout/fastboot support.
991 * We can ditch the crtc->primary->fb check as soon as we can
992 * properly reconstruct framebuffers.
994 * FIXME: The intel_crtc->active here should be switched to
995 * crtc->state->active once we have proper CRTC states wired up
998 return intel_crtc
->active
&& crtc
->primary
->state
->fb
&&
999 intel_crtc
->config
->base
.adjusted_mode
.crtc_clock
;
1002 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
1005 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1006 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1008 return intel_crtc
->config
->cpu_transcoder
;
1011 static bool pipe_dsl_stopped(struct drm_device
*dev
, enum pipe pipe
)
1013 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1014 u32 reg
= PIPEDSL(pipe
);
1019 line_mask
= DSL_LINEMASK_GEN2
;
1021 line_mask
= DSL_LINEMASK_GEN3
;
1023 line1
= I915_READ(reg
) & line_mask
;
1025 line2
= I915_READ(reg
) & line_mask
;
1027 return line1
== line2
;
1031 * intel_wait_for_pipe_off - wait for pipe to turn off
1032 * @crtc: crtc whose pipe to wait for
1034 * After disabling a pipe, we can't wait for vblank in the usual way,
1035 * spinning on the vblank interrupt status bit, since we won't actually
1036 * see an interrupt when the pipe is disabled.
1038 * On Gen4 and above:
1039 * wait for the pipe register state bit to turn off
1042 * wait for the display line value to settle (it usually
1043 * ends up stopping at the start of the next frame).
1046 static void intel_wait_for_pipe_off(struct intel_crtc
*crtc
)
1048 struct drm_device
*dev
= crtc
->base
.dev
;
1049 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1050 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1051 enum pipe pipe
= crtc
->pipe
;
1053 if (INTEL_INFO(dev
)->gen
>= 4) {
1054 int reg
= PIPECONF(cpu_transcoder
);
1056 /* Wait for the Pipe State to go off */
1057 if (wait_for((I915_READ(reg
) & I965_PIPECONF_ACTIVE
) == 0,
1059 WARN(1, "pipe_off wait timed out\n");
1061 /* Wait for the display line to settle */
1062 if (wait_for(pipe_dsl_stopped(dev
, pipe
), 100))
1063 WARN(1, "pipe_off wait timed out\n");
1068 * ibx_digital_port_connected - is the specified port connected?
1069 * @dev_priv: i915 private structure
1070 * @port: the port to test
1072 * Returns true if @port is connected, false otherwise.
1074 bool ibx_digital_port_connected(struct drm_i915_private
*dev_priv
,
1075 struct intel_digital_port
*port
)
1079 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1080 switch (port
->port
) {
1082 bit
= SDE_PORTB_HOTPLUG
;
1085 bit
= SDE_PORTC_HOTPLUG
;
1088 bit
= SDE_PORTD_HOTPLUG
;
1094 switch (port
->port
) {
1096 bit
= SDE_PORTB_HOTPLUG_CPT
;
1099 bit
= SDE_PORTC_HOTPLUG_CPT
;
1102 bit
= SDE_PORTD_HOTPLUG_CPT
;
1109 return I915_READ(SDEISR
) & bit
;
1112 static const char *state_string(bool enabled
)
1114 return enabled
? "on" : "off";
1117 /* Only for pre-ILK configs */
1118 void assert_pll(struct drm_i915_private
*dev_priv
,
1119 enum pipe pipe
, bool state
)
1126 val
= I915_READ(reg
);
1127 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1128 I915_STATE_WARN(cur_state
!= state
,
1129 "PLL state assertion failure (expected %s, current %s)\n",
1130 state_string(state
), state_string(cur_state
));
1133 /* XXX: the dsi pll is shared between MIPI DSI ports */
1134 static void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1139 mutex_lock(&dev_priv
->dpio_lock
);
1140 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1141 mutex_unlock(&dev_priv
->dpio_lock
);
1143 cur_state
= val
& DSI_PLL_VCO_EN
;
1144 I915_STATE_WARN(cur_state
!= state
,
1145 "DSI PLL state assertion failure (expected %s, current %s)\n",
1146 state_string(state
), state_string(cur_state
));
1148 #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
1149 #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
1151 struct intel_shared_dpll
*
1152 intel_crtc_to_shared_dpll(struct intel_crtc
*crtc
)
1154 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
1156 if (crtc
->config
->shared_dpll
< 0)
1159 return &dev_priv
->shared_dplls
[crtc
->config
->shared_dpll
];
1163 void assert_shared_dpll(struct drm_i915_private
*dev_priv
,
1164 struct intel_shared_dpll
*pll
,
1168 struct intel_dpll_hw_state hw_state
;
1171 "asserting DPLL %s with no DPLL\n", state_string(state
)))
1174 cur_state
= pll
->get_hw_state(dev_priv
, pll
, &hw_state
);
1175 I915_STATE_WARN(cur_state
!= state
,
1176 "%s assertion failure (expected %s, current %s)\n",
1177 pll
->name
, state_string(state
), state_string(cur_state
));
1180 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1181 enum pipe pipe
, bool state
)
1186 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1189 if (HAS_DDI(dev_priv
->dev
)) {
1190 /* DDI does not have a specific FDI_TX register */
1191 reg
= TRANS_DDI_FUNC_CTL(cpu_transcoder
);
1192 val
= I915_READ(reg
);
1193 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1195 reg
= FDI_TX_CTL(pipe
);
1196 val
= I915_READ(reg
);
1197 cur_state
= !!(val
& FDI_TX_ENABLE
);
1199 I915_STATE_WARN(cur_state
!= state
,
1200 "FDI TX state assertion failure (expected %s, current %s)\n",
1201 state_string(state
), state_string(cur_state
));
1203 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1204 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1206 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1207 enum pipe pipe
, bool state
)
1213 reg
= FDI_RX_CTL(pipe
);
1214 val
= I915_READ(reg
);
1215 cur_state
= !!(val
& FDI_RX_ENABLE
);
1216 I915_STATE_WARN(cur_state
!= state
,
1217 "FDI RX state assertion failure (expected %s, current %s)\n",
1218 state_string(state
), state_string(cur_state
));
1220 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1221 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1223 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1229 /* ILK FDI PLL is always enabled */
1230 if (INTEL_INFO(dev_priv
->dev
)->gen
== 5)
1233 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1234 if (HAS_DDI(dev_priv
->dev
))
1237 reg
= FDI_TX_CTL(pipe
);
1238 val
= I915_READ(reg
);
1239 I915_STATE_WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1242 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1243 enum pipe pipe
, bool state
)
1249 reg
= FDI_RX_CTL(pipe
);
1250 val
= I915_READ(reg
);
1251 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1252 I915_STATE_WARN(cur_state
!= state
,
1253 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1254 state_string(state
), state_string(cur_state
));
1257 void assert_panel_unlocked(struct drm_i915_private
*dev_priv
,
1260 struct drm_device
*dev
= dev_priv
->dev
;
1263 enum pipe panel_pipe
= PIPE_A
;
1266 if (WARN_ON(HAS_DDI(dev
)))
1269 if (HAS_PCH_SPLIT(dev
)) {
1272 pp_reg
= PCH_PP_CONTROL
;
1273 port_sel
= I915_READ(PCH_PP_ON_DELAYS
) & PANEL_PORT_SELECT_MASK
;
1275 if (port_sel
== PANEL_PORT_SELECT_LVDS
&&
1276 I915_READ(PCH_LVDS
) & LVDS_PIPEB_SELECT
)
1277 panel_pipe
= PIPE_B
;
1278 /* XXX: else fix for eDP */
1279 } else if (IS_VALLEYVIEW(dev
)) {
1280 /* presumably write lock depends on pipe, not port select */
1281 pp_reg
= VLV_PIPE_PP_CONTROL(pipe
);
1284 pp_reg
= PP_CONTROL
;
1285 if (I915_READ(LVDS
) & LVDS_PIPEB_SELECT
)
1286 panel_pipe
= PIPE_B
;
1289 val
= I915_READ(pp_reg
);
1290 if (!(val
& PANEL_POWER_ON
) ||
1291 ((val
& PANEL_UNLOCK_MASK
) == PANEL_UNLOCK_REGS
))
1294 I915_STATE_WARN(panel_pipe
== pipe
&& locked
,
1295 "panel assertion failure, pipe %c regs locked\n",
1299 static void assert_cursor(struct drm_i915_private
*dev_priv
,
1300 enum pipe pipe
, bool state
)
1302 struct drm_device
*dev
= dev_priv
->dev
;
1305 if (IS_845G(dev
) || IS_I865G(dev
))
1306 cur_state
= I915_READ(_CURACNTR
) & CURSOR_ENABLE
;
1308 cur_state
= I915_READ(CURCNTR(pipe
)) & CURSOR_MODE
;
1310 I915_STATE_WARN(cur_state
!= state
,
1311 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1312 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1314 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1315 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1317 void assert_pipe(struct drm_i915_private
*dev_priv
,
1318 enum pipe pipe
, bool state
)
1323 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1326 /* if we need the pipe quirk it must be always on */
1327 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1328 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1331 if (!intel_display_power_is_enabled(dev_priv
,
1332 POWER_DOMAIN_TRANSCODER(cpu_transcoder
))) {
1335 reg
= PIPECONF(cpu_transcoder
);
1336 val
= I915_READ(reg
);
1337 cur_state
= !!(val
& PIPECONF_ENABLE
);
1340 I915_STATE_WARN(cur_state
!= state
,
1341 "pipe %c assertion failure (expected %s, current %s)\n",
1342 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1345 static void assert_plane(struct drm_i915_private
*dev_priv
,
1346 enum plane plane
, bool state
)
1352 reg
= DSPCNTR(plane
);
1353 val
= I915_READ(reg
);
1354 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1355 I915_STATE_WARN(cur_state
!= state
,
1356 "plane %c assertion failure (expected %s, current %s)\n",
1357 plane_name(plane
), state_string(state
), state_string(cur_state
));
1360 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1361 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1363 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1366 struct drm_device
*dev
= dev_priv
->dev
;
1371 /* Primary planes are fixed to pipes on gen4+ */
1372 if (INTEL_INFO(dev
)->gen
>= 4) {
1373 reg
= DSPCNTR(pipe
);
1374 val
= I915_READ(reg
);
1375 I915_STATE_WARN(val
& DISPLAY_PLANE_ENABLE
,
1376 "plane %c assertion failure, should be disabled but not\n",
1381 /* Need to check both planes against the pipe */
1382 for_each_pipe(dev_priv
, i
) {
1384 val
= I915_READ(reg
);
1385 cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1386 DISPPLANE_SEL_PIPE_SHIFT
;
1387 I915_STATE_WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1388 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1389 plane_name(i
), pipe_name(pipe
));
1393 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1396 struct drm_device
*dev
= dev_priv
->dev
;
1400 if (INTEL_INFO(dev
)->gen
>= 9) {
1401 for_each_sprite(dev_priv
, pipe
, sprite
) {
1402 val
= I915_READ(PLANE_CTL(pipe
, sprite
));
1403 I915_STATE_WARN(val
& PLANE_CTL_ENABLE
,
1404 "plane %d assertion failure, should be off on pipe %c but is still active\n",
1405 sprite
, pipe_name(pipe
));
1407 } else if (IS_VALLEYVIEW(dev
)) {
1408 for_each_sprite(dev_priv
, pipe
, sprite
) {
1409 reg
= SPCNTR(pipe
, sprite
);
1410 val
= I915_READ(reg
);
1411 I915_STATE_WARN(val
& SP_ENABLE
,
1412 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1413 sprite_name(pipe
, sprite
), pipe_name(pipe
));
1415 } else if (INTEL_INFO(dev
)->gen
>= 7) {
1417 val
= I915_READ(reg
);
1418 I915_STATE_WARN(val
& SPRITE_ENABLE
,
1419 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1420 plane_name(pipe
), pipe_name(pipe
));
1421 } else if (INTEL_INFO(dev
)->gen
>= 5) {
1422 reg
= DVSCNTR(pipe
);
1423 val
= I915_READ(reg
);
1424 I915_STATE_WARN(val
& DVS_ENABLE
,
1425 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1426 plane_name(pipe
), pipe_name(pipe
));
1430 static void assert_vblank_disabled(struct drm_crtc
*crtc
)
1432 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc
) == 0))
1433 drm_crtc_vblank_put(crtc
);
1436 static void ibx_assert_pch_refclk_enabled(struct drm_i915_private
*dev_priv
)
1441 I915_STATE_WARN_ON(!(HAS_PCH_IBX(dev_priv
->dev
) || HAS_PCH_CPT(dev_priv
->dev
)));
1443 val
= I915_READ(PCH_DREF_CONTROL
);
1444 enabled
= !!(val
& (DREF_SSC_SOURCE_MASK
| DREF_NONSPREAD_SOURCE_MASK
|
1445 DREF_SUPERSPREAD_SOURCE_MASK
));
1446 I915_STATE_WARN(!enabled
, "PCH refclk assertion failure, should be active but is disabled\n");
1449 static void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1456 reg
= PCH_TRANSCONF(pipe
);
1457 val
= I915_READ(reg
);
1458 enabled
= !!(val
& TRANS_ENABLE
);
1459 I915_STATE_WARN(enabled
,
1460 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1464 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1465 enum pipe pipe
, u32 port_sel
, u32 val
)
1467 if ((val
& DP_PORT_EN
) == 0)
1470 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1471 u32 trans_dp_ctl_reg
= TRANS_DP_CTL(pipe
);
1472 u32 trans_dp_ctl
= I915_READ(trans_dp_ctl_reg
);
1473 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1475 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1476 if ((val
& DP_PIPE_MASK_CHV
) != DP_PIPE_SELECT_CHV(pipe
))
1479 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1485 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1486 enum pipe pipe
, u32 val
)
1488 if ((val
& SDVO_ENABLE
) == 0)
1491 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1492 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1494 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1495 if ((val
& SDVO_PIPE_SEL_MASK_CHV
) != SDVO_PIPE_SEL_CHV(pipe
))
1498 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1504 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1505 enum pipe pipe
, u32 val
)
1507 if ((val
& LVDS_PORT_EN
) == 0)
1510 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1511 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1514 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1520 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1521 enum pipe pipe
, u32 val
)
1523 if ((val
& ADPA_DAC_ENABLE
) == 0)
1525 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1526 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1529 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1535 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1536 enum pipe pipe
, int reg
, u32 port_sel
)
1538 u32 val
= I915_READ(reg
);
1539 I915_STATE_WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1540 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1541 reg
, pipe_name(pipe
));
1543 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& DP_PORT_EN
) == 0
1544 && (val
& DP_PIPEB_SELECT
),
1545 "IBX PCH dp port still using transcoder B\n");
1548 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1549 enum pipe pipe
, int reg
)
1551 u32 val
= I915_READ(reg
);
1552 I915_STATE_WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1553 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1554 reg
, pipe_name(pipe
));
1556 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& SDVO_ENABLE
) == 0
1557 && (val
& SDVO_PIPE_B_SELECT
),
1558 "IBX PCH hdmi port still using transcoder B\n");
1561 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1567 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1568 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1569 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1572 val
= I915_READ(reg
);
1573 I915_STATE_WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1574 "PCH VGA enabled on transcoder %c, should be disabled\n",
1578 val
= I915_READ(reg
);
1579 I915_STATE_WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1580 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1583 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1584 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1585 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1588 static void intel_init_dpio(struct drm_device
*dev
)
1590 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1592 if (!IS_VALLEYVIEW(dev
))
1596 * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
1597 * CHV x1 PHY (DP/HDMI D)
1598 * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
1600 if (IS_CHERRYVIEW(dev
)) {
1601 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO_2
;
1602 DPIO_PHY_IOSF_PORT(DPIO_PHY1
) = IOSF_PORT_DPIO
;
1604 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO
;
1608 static void vlv_enable_pll(struct intel_crtc
*crtc
,
1609 const struct intel_crtc_state
*pipe_config
)
1611 struct drm_device
*dev
= crtc
->base
.dev
;
1612 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1613 int reg
= DPLL(crtc
->pipe
);
1614 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
1616 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1618 /* No really, not for ILK+ */
1619 BUG_ON(!IS_VALLEYVIEW(dev_priv
->dev
));
1621 /* PLL is protected by panel, make sure we can write it */
1622 if (IS_MOBILE(dev_priv
->dev
))
1623 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1625 I915_WRITE(reg
, dpll
);
1629 if (wait_for(((I915_READ(reg
) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1630 DRM_ERROR("DPLL %d failed to lock\n", crtc
->pipe
);
1632 I915_WRITE(DPLL_MD(crtc
->pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1633 POSTING_READ(DPLL_MD(crtc
->pipe
));
1635 /* We do this three times for luck */
1636 I915_WRITE(reg
, dpll
);
1638 udelay(150); /* wait for warmup */
1639 I915_WRITE(reg
, dpll
);
1641 udelay(150); /* wait for warmup */
1642 I915_WRITE(reg
, dpll
);
1644 udelay(150); /* wait for warmup */
1647 static void chv_enable_pll(struct intel_crtc
*crtc
,
1648 const struct intel_crtc_state
*pipe_config
)
1650 struct drm_device
*dev
= crtc
->base
.dev
;
1651 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1652 int pipe
= crtc
->pipe
;
1653 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1656 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1658 BUG_ON(!IS_CHERRYVIEW(dev_priv
->dev
));
1660 mutex_lock(&dev_priv
->dpio_lock
);
1662 /* Enable back the 10bit clock to display controller */
1663 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1664 tmp
|= DPIO_DCLKP_EN
;
1665 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), tmp
);
1668 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1673 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1675 /* Check PLL is locked */
1676 if (wait_for(((I915_READ(DPLL(pipe
)) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1677 DRM_ERROR("PLL %d failed to lock\n", pipe
);
1679 /* not sure when this should be written */
1680 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1681 POSTING_READ(DPLL_MD(pipe
));
1683 mutex_unlock(&dev_priv
->dpio_lock
);
1686 static int intel_num_dvo_pipes(struct drm_device
*dev
)
1688 struct intel_crtc
*crtc
;
1691 for_each_intel_crtc(dev
, crtc
)
1692 count
+= crtc
->active
&&
1693 intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
);
1698 static void i9xx_enable_pll(struct intel_crtc
*crtc
)
1700 struct drm_device
*dev
= crtc
->base
.dev
;
1701 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1702 int reg
= DPLL(crtc
->pipe
);
1703 u32 dpll
= crtc
->config
->dpll_hw_state
.dpll
;
1705 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1707 /* No really, not for ILK+ */
1708 BUG_ON(INTEL_INFO(dev
)->gen
>= 5);
1710 /* PLL is protected by panel, make sure we can write it */
1711 if (IS_MOBILE(dev
) && !IS_I830(dev
))
1712 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1714 /* Enable DVO 2x clock on both PLLs if necessary */
1715 if (IS_I830(dev
) && intel_num_dvo_pipes(dev
) > 0) {
1717 * It appears to be important that we don't enable this
1718 * for the current pipe before otherwise configuring the
1719 * PLL. No idea how this should be handled if multiple
1720 * DVO outputs are enabled simultaneosly.
1722 dpll
|= DPLL_DVO_2X_MODE
;
1723 I915_WRITE(DPLL(!crtc
->pipe
),
1724 I915_READ(DPLL(!crtc
->pipe
)) | DPLL_DVO_2X_MODE
);
1727 /* Wait for the clocks to stabilize. */
1731 if (INTEL_INFO(dev
)->gen
>= 4) {
1732 I915_WRITE(DPLL_MD(crtc
->pipe
),
1733 crtc
->config
->dpll_hw_state
.dpll_md
);
1735 /* The pixel multiplier can only be updated once the
1736 * DPLL is enabled and the clocks are stable.
1738 * So write it again.
1740 I915_WRITE(reg
, dpll
);
1743 /* We do this three times for luck */
1744 I915_WRITE(reg
, dpll
);
1746 udelay(150); /* wait for warmup */
1747 I915_WRITE(reg
, dpll
);
1749 udelay(150); /* wait for warmup */
1750 I915_WRITE(reg
, dpll
);
1752 udelay(150); /* wait for warmup */
1756 * i9xx_disable_pll - disable a PLL
1757 * @dev_priv: i915 private structure
1758 * @pipe: pipe PLL to disable
1760 * Disable the PLL for @pipe, making sure the pipe is off first.
1762 * Note! This is for pre-ILK only.
1764 static void i9xx_disable_pll(struct intel_crtc
*crtc
)
1766 struct drm_device
*dev
= crtc
->base
.dev
;
1767 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1768 enum pipe pipe
= crtc
->pipe
;
1770 /* Disable DVO 2x clock on both PLLs if necessary */
1772 intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
) &&
1773 intel_num_dvo_pipes(dev
) == 1) {
1774 I915_WRITE(DPLL(PIPE_B
),
1775 I915_READ(DPLL(PIPE_B
)) & ~DPLL_DVO_2X_MODE
);
1776 I915_WRITE(DPLL(PIPE_A
),
1777 I915_READ(DPLL(PIPE_A
)) & ~DPLL_DVO_2X_MODE
);
1780 /* Don't disable pipe or pipe PLLs if needed */
1781 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1782 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1785 /* Make sure the pipe isn't still relying on us */
1786 assert_pipe_disabled(dev_priv
, pipe
);
1788 I915_WRITE(DPLL(pipe
), 0);
1789 POSTING_READ(DPLL(pipe
));
1792 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1796 /* Make sure the pipe isn't still relying on us */
1797 assert_pipe_disabled(dev_priv
, pipe
);
1800 * Leave integrated clock source and reference clock enabled for pipe B.
1801 * The latter is needed for VGA hotplug / manual detection.
1804 val
= DPLL_INTEGRATED_CRI_CLK_VLV
| DPLL_REFA_CLK_ENABLE_VLV
;
1805 I915_WRITE(DPLL(pipe
), val
);
1806 POSTING_READ(DPLL(pipe
));
1810 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1812 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1815 /* Make sure the pipe isn't still relying on us */
1816 assert_pipe_disabled(dev_priv
, pipe
);
1818 /* Set PLL en = 0 */
1819 val
= DPLL_SSC_REF_CLOCK_CHV
| DPLL_REFA_CLK_ENABLE_VLV
;
1821 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1822 I915_WRITE(DPLL(pipe
), val
);
1823 POSTING_READ(DPLL(pipe
));
1825 mutex_lock(&dev_priv
->dpio_lock
);
1827 /* Disable 10bit clock to display controller */
1828 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1829 val
&= ~DPIO_DCLKP_EN
;
1830 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1832 /* disable left/right clock distribution */
1833 if (pipe
!= PIPE_B
) {
1834 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
);
1835 val
&= ~(CHV_BUFLEFTENA1_MASK
| CHV_BUFRIGHTENA1_MASK
);
1836 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
, val
);
1838 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
);
1839 val
&= ~(CHV_BUFLEFTENA2_MASK
| CHV_BUFRIGHTENA2_MASK
);
1840 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
, val
);
1843 mutex_unlock(&dev_priv
->dpio_lock
);
1846 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1847 struct intel_digital_port
*dport
)
1852 switch (dport
->port
) {
1854 port_mask
= DPLL_PORTB_READY_MASK
;
1858 port_mask
= DPLL_PORTC_READY_MASK
;
1862 port_mask
= DPLL_PORTD_READY_MASK
;
1863 dpll_reg
= DPIO_PHY_STATUS
;
1869 if (wait_for((I915_READ(dpll_reg
) & port_mask
) == 0, 1000))
1870 WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
1871 port_name(dport
->port
), I915_READ(dpll_reg
));
1874 static void intel_prepare_shared_dpll(struct intel_crtc
*crtc
)
1876 struct drm_device
*dev
= crtc
->base
.dev
;
1877 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1878 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1880 if (WARN_ON(pll
== NULL
))
1883 WARN_ON(!pll
->config
.crtc_mask
);
1884 if (pll
->active
== 0) {
1885 DRM_DEBUG_DRIVER("setting up %s\n", pll
->name
);
1887 assert_shared_dpll_disabled(dev_priv
, pll
);
1889 pll
->mode_set(dev_priv
, pll
);
1894 * intel_enable_shared_dpll - enable PCH PLL
1895 * @dev_priv: i915 private structure
1896 * @pipe: pipe PLL to enable
1898 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1899 * drives the transcoder clock.
1901 static void intel_enable_shared_dpll(struct intel_crtc
*crtc
)
1903 struct drm_device
*dev
= crtc
->base
.dev
;
1904 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1905 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1907 if (WARN_ON(pll
== NULL
))
1910 if (WARN_ON(pll
->config
.crtc_mask
== 0))
1913 DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n",
1914 pll
->name
, pll
->active
, pll
->on
,
1915 crtc
->base
.base
.id
);
1917 if (pll
->active
++) {
1919 assert_shared_dpll_enabled(dev_priv
, pll
);
1924 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
1926 DRM_DEBUG_KMS("enabling %s\n", pll
->name
);
1927 pll
->enable(dev_priv
, pll
);
1931 static void intel_disable_shared_dpll(struct intel_crtc
*crtc
)
1933 struct drm_device
*dev
= crtc
->base
.dev
;
1934 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1935 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1937 /* PCH only available on ILK+ */
1938 BUG_ON(INTEL_INFO(dev
)->gen
< 5);
1939 if (WARN_ON(pll
== NULL
))
1942 if (WARN_ON(pll
->config
.crtc_mask
== 0))
1945 DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
1946 pll
->name
, pll
->active
, pll
->on
,
1947 crtc
->base
.base
.id
);
1949 if (WARN_ON(pll
->active
== 0)) {
1950 assert_shared_dpll_disabled(dev_priv
, pll
);
1954 assert_shared_dpll_enabled(dev_priv
, pll
);
1959 DRM_DEBUG_KMS("disabling %s\n", pll
->name
);
1960 pll
->disable(dev_priv
, pll
);
1963 intel_display_power_put(dev_priv
, POWER_DOMAIN_PLLS
);
1966 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1969 struct drm_device
*dev
= dev_priv
->dev
;
1970 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1971 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1972 uint32_t reg
, val
, pipeconf_val
;
1974 /* PCH only available on ILK+ */
1975 BUG_ON(!HAS_PCH_SPLIT(dev
));
1977 /* Make sure PCH DPLL is enabled */
1978 assert_shared_dpll_enabled(dev_priv
,
1979 intel_crtc_to_shared_dpll(intel_crtc
));
1981 /* FDI must be feeding us bits for PCH ports */
1982 assert_fdi_tx_enabled(dev_priv
, pipe
);
1983 assert_fdi_rx_enabled(dev_priv
, pipe
);
1985 if (HAS_PCH_CPT(dev
)) {
1986 /* Workaround: Set the timing override bit before enabling the
1987 * pch transcoder. */
1988 reg
= TRANS_CHICKEN2(pipe
);
1989 val
= I915_READ(reg
);
1990 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1991 I915_WRITE(reg
, val
);
1994 reg
= PCH_TRANSCONF(pipe
);
1995 val
= I915_READ(reg
);
1996 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1998 if (HAS_PCH_IBX(dev_priv
->dev
)) {
2000 * make the BPC in transcoder be consistent with
2001 * that in pipeconf reg.
2003 val
&= ~PIPECONF_BPC_MASK
;
2004 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
2007 val
&= ~TRANS_INTERLACE_MASK
;
2008 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
2009 if (HAS_PCH_IBX(dev_priv
->dev
) &&
2010 intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
2011 val
|= TRANS_LEGACY_INTERLACED_ILK
;
2013 val
|= TRANS_INTERLACED
;
2015 val
|= TRANS_PROGRESSIVE
;
2017 I915_WRITE(reg
, val
| TRANS_ENABLE
);
2018 if (wait_for(I915_READ(reg
) & TRANS_STATE_ENABLE
, 100))
2019 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
2022 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
2023 enum transcoder cpu_transcoder
)
2025 u32 val
, pipeconf_val
;
2027 /* PCH only available on ILK+ */
2028 BUG_ON(!HAS_PCH_SPLIT(dev_priv
->dev
));
2030 /* FDI must be feeding us bits for PCH ports */
2031 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
2032 assert_fdi_rx_enabled(dev_priv
, TRANSCODER_A
);
2034 /* Workaround: set timing override bit. */
2035 val
= I915_READ(_TRANSA_CHICKEN2
);
2036 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
2037 I915_WRITE(_TRANSA_CHICKEN2
, val
);
2040 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
2042 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
2043 PIPECONF_INTERLACED_ILK
)
2044 val
|= TRANS_INTERLACED
;
2046 val
|= TRANS_PROGRESSIVE
;
2048 I915_WRITE(LPT_TRANSCONF
, val
);
2049 if (wait_for(I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
, 100))
2050 DRM_ERROR("Failed to enable PCH transcoder\n");
2053 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
2056 struct drm_device
*dev
= dev_priv
->dev
;
2059 /* FDI relies on the transcoder */
2060 assert_fdi_tx_disabled(dev_priv
, pipe
);
2061 assert_fdi_rx_disabled(dev_priv
, pipe
);
2063 /* Ports must be off as well */
2064 assert_pch_ports_disabled(dev_priv
, pipe
);
2066 reg
= PCH_TRANSCONF(pipe
);
2067 val
= I915_READ(reg
);
2068 val
&= ~TRANS_ENABLE
;
2069 I915_WRITE(reg
, val
);
2070 /* wait for PCH transcoder off, transcoder state */
2071 if (wait_for((I915_READ(reg
) & TRANS_STATE_ENABLE
) == 0, 50))
2072 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
2074 if (!HAS_PCH_IBX(dev
)) {
2075 /* Workaround: Clear the timing override chicken bit again. */
2076 reg
= TRANS_CHICKEN2(pipe
);
2077 val
= I915_READ(reg
);
2078 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
2079 I915_WRITE(reg
, val
);
2083 static void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
2087 val
= I915_READ(LPT_TRANSCONF
);
2088 val
&= ~TRANS_ENABLE
;
2089 I915_WRITE(LPT_TRANSCONF
, val
);
2090 /* wait for PCH transcoder off, transcoder state */
2091 if (wait_for((I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
) == 0, 50))
2092 DRM_ERROR("Failed to disable PCH transcoder\n");
2094 /* Workaround: clear timing override bit. */
2095 val
= I915_READ(_TRANSA_CHICKEN2
);
2096 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
2097 I915_WRITE(_TRANSA_CHICKEN2
, val
);
2101 * intel_enable_pipe - enable a pipe, asserting requirements
2102 * @crtc: crtc responsible for the pipe
2104 * Enable @crtc's pipe, making sure that various hardware specific requirements
2105 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
2107 static void intel_enable_pipe(struct intel_crtc
*crtc
)
2109 struct drm_device
*dev
= crtc
->base
.dev
;
2110 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2111 enum pipe pipe
= crtc
->pipe
;
2112 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
2114 enum pipe pch_transcoder
;
2118 assert_planes_disabled(dev_priv
, pipe
);
2119 assert_cursor_disabled(dev_priv
, pipe
);
2120 assert_sprites_disabled(dev_priv
, pipe
);
2122 if (HAS_PCH_LPT(dev_priv
->dev
))
2123 pch_transcoder
= TRANSCODER_A
;
2125 pch_transcoder
= pipe
;
2128 * A pipe without a PLL won't actually be able to drive bits from
2129 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
2132 if (HAS_GMCH_DISPLAY(dev_priv
->dev
))
2133 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
))
2134 assert_dsi_pll_enabled(dev_priv
);
2136 assert_pll_enabled(dev_priv
, pipe
);
2138 if (crtc
->config
->has_pch_encoder
) {
2139 /* if driving the PCH, we need FDI enabled */
2140 assert_fdi_rx_pll_enabled(dev_priv
, pch_transcoder
);
2141 assert_fdi_tx_pll_enabled(dev_priv
,
2142 (enum pipe
) cpu_transcoder
);
2144 /* FIXME: assert CPU port conditions for SNB+ */
2147 reg
= PIPECONF(cpu_transcoder
);
2148 val
= I915_READ(reg
);
2149 if (val
& PIPECONF_ENABLE
) {
2150 WARN_ON(!((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
2151 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
)));
2155 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
2160 * intel_disable_pipe - disable a pipe, asserting requirements
2161 * @crtc: crtc whose pipes is to be disabled
2163 * Disable the pipe of @crtc, making sure that various hardware
2164 * specific requirements are met, if applicable, e.g. plane
2165 * disabled, panel fitter off, etc.
2167 * Will wait until the pipe has shut down before returning.
2169 static void intel_disable_pipe(struct intel_crtc
*crtc
)
2171 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
2172 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
2173 enum pipe pipe
= crtc
->pipe
;
2178 * Make sure planes won't keep trying to pump pixels to us,
2179 * or we might hang the display.
2181 assert_planes_disabled(dev_priv
, pipe
);
2182 assert_cursor_disabled(dev_priv
, pipe
);
2183 assert_sprites_disabled(dev_priv
, pipe
);
2185 reg
= PIPECONF(cpu_transcoder
);
2186 val
= I915_READ(reg
);
2187 if ((val
& PIPECONF_ENABLE
) == 0)
2191 * Double wide has implications for planes
2192 * so best keep it disabled when not needed.
2194 if (crtc
->config
->double_wide
)
2195 val
&= ~PIPECONF_DOUBLE_WIDE
;
2197 /* Don't disable pipe or pipe PLLs if needed */
2198 if (!(pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) &&
2199 !(pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
2200 val
&= ~PIPECONF_ENABLE
;
2202 I915_WRITE(reg
, val
);
2203 if ((val
& PIPECONF_ENABLE
) == 0)
2204 intel_wait_for_pipe_off(crtc
);
2208 * Plane regs are double buffered, going from enabled->disabled needs a
2209 * trigger in order to latch. The display address reg provides this.
2211 void intel_flush_primary_plane(struct drm_i915_private
*dev_priv
,
2214 struct drm_device
*dev
= dev_priv
->dev
;
2215 u32 reg
= INTEL_INFO(dev
)->gen
>= 4 ? DSPSURF(plane
) : DSPADDR(plane
);
2217 I915_WRITE(reg
, I915_READ(reg
));
2222 * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
2223 * @plane: plane to be enabled
2224 * @crtc: crtc for the plane
2226 * Enable @plane on @crtc, making sure that the pipe is running first.
2228 static void intel_enable_primary_hw_plane(struct drm_plane
*plane
,
2229 struct drm_crtc
*crtc
)
2231 struct drm_device
*dev
= plane
->dev
;
2232 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2233 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2235 /* If the pipe isn't enabled, we can't pump pixels and may hang */
2236 assert_pipe_enabled(dev_priv
, intel_crtc
->pipe
);
2237 to_intel_plane_state(plane
->state
)->visible
= true;
2239 dev_priv
->display
.update_primary_plane(crtc
, plane
->fb
,
2243 static bool need_vtd_wa(struct drm_device
*dev
)
2245 #ifdef CONFIG_INTEL_IOMMU
2246 if (INTEL_INFO(dev
)->gen
>= 6 && intel_iommu_gfx_mapped
)
2253 intel_tile_height(struct drm_device
*dev
, uint32_t pixel_format
,
2254 uint64_t fb_format_modifier
)
2256 unsigned int tile_height
;
2257 uint32_t pixel_bytes
;
2259 switch (fb_format_modifier
) {
2260 case DRM_FORMAT_MOD_NONE
:
2263 case I915_FORMAT_MOD_X_TILED
:
2264 tile_height
= IS_GEN2(dev
) ? 16 : 8;
2266 case I915_FORMAT_MOD_Y_TILED
:
2269 case I915_FORMAT_MOD_Yf_TILED
:
2270 pixel_bytes
= drm_format_plane_cpp(pixel_format
, 0);
2271 switch (pixel_bytes
) {
2285 "128-bit pixels are not supported for display!");
2291 MISSING_CASE(fb_format_modifier
);
2300 intel_fb_align_height(struct drm_device
*dev
, unsigned int height
,
2301 uint32_t pixel_format
, uint64_t fb_format_modifier
)
2303 return ALIGN(height
, intel_tile_height(dev
, pixel_format
,
2304 fb_format_modifier
));
2308 intel_fill_fb_ggtt_view(struct i915_ggtt_view
*view
, struct drm_framebuffer
*fb
,
2309 const struct drm_plane_state
*plane_state
)
2311 struct intel_rotation_info
*info
= &view
->rotation_info
;
2313 *view
= i915_ggtt_view_normal
;
2318 if (!intel_rotation_90_or_270(plane_state
->rotation
))
2321 *view
= i915_ggtt_view_rotated
;
2323 info
->height
= fb
->height
;
2324 info
->pixel_format
= fb
->pixel_format
;
2325 info
->pitch
= fb
->pitches
[0];
2326 info
->fb_modifier
= fb
->modifier
[0];
2332 intel_pin_and_fence_fb_obj(struct drm_plane
*plane
,
2333 struct drm_framebuffer
*fb
,
2334 const struct drm_plane_state
*plane_state
,
2335 struct intel_engine_cs
*pipelined
)
2337 struct drm_device
*dev
= fb
->dev
;
2338 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2339 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2340 struct i915_ggtt_view view
;
2344 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
2346 switch (fb
->modifier
[0]) {
2347 case DRM_FORMAT_MOD_NONE
:
2348 if (INTEL_INFO(dev
)->gen
>= 9)
2349 alignment
= 256 * 1024;
2350 else if (IS_BROADWATER(dev
) || IS_CRESTLINE(dev
))
2351 alignment
= 128 * 1024;
2352 else if (INTEL_INFO(dev
)->gen
>= 4)
2353 alignment
= 4 * 1024;
2355 alignment
= 64 * 1024;
2357 case I915_FORMAT_MOD_X_TILED
:
2358 if (INTEL_INFO(dev
)->gen
>= 9)
2359 alignment
= 256 * 1024;
2361 /* pin() will align the object as required by fence */
2365 case I915_FORMAT_MOD_Y_TILED
:
2366 case I915_FORMAT_MOD_Yf_TILED
:
2367 if (WARN_ONCE(INTEL_INFO(dev
)->gen
< 9,
2368 "Y tiling bo slipped through, driver bug!\n"))
2370 alignment
= 1 * 1024 * 1024;
2373 MISSING_CASE(fb
->modifier
[0]);
2377 ret
= intel_fill_fb_ggtt_view(&view
, fb
, plane_state
);
2381 /* Note that the w/a also requires 64 PTE of padding following the
2382 * bo. We currently fill all unused PTE with the shadow page and so
2383 * we should always have valid PTE following the scanout preventing
2386 if (need_vtd_wa(dev
) && alignment
< 256 * 1024)
2387 alignment
= 256 * 1024;
2390 * Global gtt pte registers are special registers which actually forward
2391 * writes to a chunk of system memory. Which means that there is no risk
2392 * that the register values disappear as soon as we call
2393 * intel_runtime_pm_put(), so it is correct to wrap only the
2394 * pin/unpin/fence and not more.
2396 intel_runtime_pm_get(dev_priv
);
2398 dev_priv
->mm
.interruptible
= false;
2399 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, pipelined
,
2402 goto err_interruptible
;
2404 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2405 * fence, whereas 965+ only requires a fence if using
2406 * framebuffer compression. For simplicity, we always install
2407 * a fence as the cost is not that onerous.
2409 ret
= i915_gem_object_get_fence(obj
);
2413 i915_gem_object_pin_fence(obj
);
2415 dev_priv
->mm
.interruptible
= true;
2416 intel_runtime_pm_put(dev_priv
);
2420 i915_gem_object_unpin_from_display_plane(obj
, &view
);
2422 dev_priv
->mm
.interruptible
= true;
2423 intel_runtime_pm_put(dev_priv
);
2427 static void intel_unpin_fb_obj(struct drm_framebuffer
*fb
,
2428 const struct drm_plane_state
*plane_state
)
2430 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2431 struct i915_ggtt_view view
;
2434 WARN_ON(!mutex_is_locked(&obj
->base
.dev
->struct_mutex
));
2436 ret
= intel_fill_fb_ggtt_view(&view
, fb
, plane_state
);
2437 WARN_ONCE(ret
, "Couldn't get view from plane state!");
2439 i915_gem_object_unpin_fence(obj
);
2440 i915_gem_object_unpin_from_display_plane(obj
, &view
);
2443 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
2444 * is assumed to be a power-of-two. */
2445 unsigned long intel_gen4_compute_page_offset(int *x
, int *y
,
2446 unsigned int tiling_mode
,
2450 if (tiling_mode
!= I915_TILING_NONE
) {
2451 unsigned int tile_rows
, tiles
;
2456 tiles
= *x
/ (512/cpp
);
2459 return tile_rows
* pitch
* 8 + tiles
* 4096;
2461 unsigned int offset
;
2463 offset
= *y
* pitch
+ *x
* cpp
;
2465 *x
= (offset
& 4095) / cpp
;
2466 return offset
& -4096;
2470 static int i9xx_format_to_fourcc(int format
)
2473 case DISPPLANE_8BPP
:
2474 return DRM_FORMAT_C8
;
2475 case DISPPLANE_BGRX555
:
2476 return DRM_FORMAT_XRGB1555
;
2477 case DISPPLANE_BGRX565
:
2478 return DRM_FORMAT_RGB565
;
2480 case DISPPLANE_BGRX888
:
2481 return DRM_FORMAT_XRGB8888
;
2482 case DISPPLANE_RGBX888
:
2483 return DRM_FORMAT_XBGR8888
;
2484 case DISPPLANE_BGRX101010
:
2485 return DRM_FORMAT_XRGB2101010
;
2486 case DISPPLANE_RGBX101010
:
2487 return DRM_FORMAT_XBGR2101010
;
2491 static int skl_format_to_fourcc(int format
, bool rgb_order
, bool alpha
)
2494 case PLANE_CTL_FORMAT_RGB_565
:
2495 return DRM_FORMAT_RGB565
;
2497 case PLANE_CTL_FORMAT_XRGB_8888
:
2500 return DRM_FORMAT_ABGR8888
;
2502 return DRM_FORMAT_XBGR8888
;
2505 return DRM_FORMAT_ARGB8888
;
2507 return DRM_FORMAT_XRGB8888
;
2509 case PLANE_CTL_FORMAT_XRGB_2101010
:
2511 return DRM_FORMAT_XBGR2101010
;
2513 return DRM_FORMAT_XRGB2101010
;
2518 intel_alloc_initial_plane_obj(struct intel_crtc
*crtc
,
2519 struct intel_initial_plane_config
*plane_config
)
2521 struct drm_device
*dev
= crtc
->base
.dev
;
2522 struct drm_i915_gem_object
*obj
= NULL
;
2523 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2524 struct drm_framebuffer
*fb
= &plane_config
->fb
->base
;
2525 u32 base_aligned
= round_down(plane_config
->base
, PAGE_SIZE
);
2526 u32 size_aligned
= round_up(plane_config
->base
+ plane_config
->size
,
2529 size_aligned
-= base_aligned
;
2531 if (plane_config
->size
== 0)
2534 obj
= i915_gem_object_create_stolen_for_preallocated(dev
,
2541 obj
->tiling_mode
= plane_config
->tiling
;
2542 if (obj
->tiling_mode
== I915_TILING_X
)
2543 obj
->stride
= fb
->pitches
[0];
2545 mode_cmd
.pixel_format
= fb
->pixel_format
;
2546 mode_cmd
.width
= fb
->width
;
2547 mode_cmd
.height
= fb
->height
;
2548 mode_cmd
.pitches
[0] = fb
->pitches
[0];
2549 mode_cmd
.modifier
[0] = fb
->modifier
[0];
2550 mode_cmd
.flags
= DRM_MODE_FB_MODIFIERS
;
2552 mutex_lock(&dev
->struct_mutex
);
2553 if (intel_framebuffer_init(dev
, to_intel_framebuffer(fb
),
2555 DRM_DEBUG_KMS("intel fb init failed\n");
2558 mutex_unlock(&dev
->struct_mutex
);
2560 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj
);
2564 drm_gem_object_unreference(&obj
->base
);
2565 mutex_unlock(&dev
->struct_mutex
);
2569 /* Update plane->state->fb to match plane->fb after driver-internal updates */
2571 update_state_fb(struct drm_plane
*plane
)
2573 if (plane
->fb
== plane
->state
->fb
)
2576 if (plane
->state
->fb
)
2577 drm_framebuffer_unreference(plane
->state
->fb
);
2578 plane
->state
->fb
= plane
->fb
;
2579 if (plane
->state
->fb
)
2580 drm_framebuffer_reference(plane
->state
->fb
);
2584 intel_find_initial_plane_obj(struct intel_crtc
*intel_crtc
,
2585 struct intel_initial_plane_config
*plane_config
)
2587 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2588 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2590 struct intel_crtc
*i
;
2591 struct drm_i915_gem_object
*obj
;
2592 struct drm_plane
*primary
= intel_crtc
->base
.primary
;
2593 struct drm_framebuffer
*fb
;
2595 if (!plane_config
->fb
)
2598 if (intel_alloc_initial_plane_obj(intel_crtc
, plane_config
)) {
2599 fb
= &plane_config
->fb
->base
;
2603 kfree(plane_config
->fb
);
2606 * Failed to alloc the obj, check to see if we should share
2607 * an fb with another CRTC instead
2609 for_each_crtc(dev
, c
) {
2610 i
= to_intel_crtc(c
);
2612 if (c
== &intel_crtc
->base
)
2618 fb
= c
->primary
->fb
;
2622 obj
= intel_fb_obj(fb
);
2623 if (i915_gem_obj_ggtt_offset(obj
) == plane_config
->base
) {
2624 drm_framebuffer_reference(fb
);
2632 obj
= intel_fb_obj(fb
);
2633 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2634 dev_priv
->preserve_bios_swizzle
= true;
2637 primary
->state
->crtc
= &intel_crtc
->base
;
2638 primary
->crtc
= &intel_crtc
->base
;
2639 update_state_fb(primary
);
2640 obj
->frontbuffer_bits
|= INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
);
2643 static void i9xx_update_primary_plane(struct drm_crtc
*crtc
,
2644 struct drm_framebuffer
*fb
,
2647 struct drm_device
*dev
= crtc
->dev
;
2648 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2649 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2650 struct drm_plane
*primary
= crtc
->primary
;
2651 bool visible
= to_intel_plane_state(primary
->state
)->visible
;
2652 struct drm_i915_gem_object
*obj
;
2653 int plane
= intel_crtc
->plane
;
2654 unsigned long linear_offset
;
2656 u32 reg
= DSPCNTR(plane
);
2659 if (!visible
|| !fb
) {
2661 if (INTEL_INFO(dev
)->gen
>= 4)
2662 I915_WRITE(DSPSURF(plane
), 0);
2664 I915_WRITE(DSPADDR(plane
), 0);
2669 obj
= intel_fb_obj(fb
);
2670 if (WARN_ON(obj
== NULL
))
2673 pixel_size
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2675 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2677 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2679 if (INTEL_INFO(dev
)->gen
< 4) {
2680 if (intel_crtc
->pipe
== PIPE_B
)
2681 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
2683 /* pipesrc and dspsize control the size that is scaled from,
2684 * which should always be the user's requested size.
2686 I915_WRITE(DSPSIZE(plane
),
2687 ((intel_crtc
->config
->pipe_src_h
- 1) << 16) |
2688 (intel_crtc
->config
->pipe_src_w
- 1));
2689 I915_WRITE(DSPPOS(plane
), 0);
2690 } else if (IS_CHERRYVIEW(dev
) && plane
== PLANE_B
) {
2691 I915_WRITE(PRIMSIZE(plane
),
2692 ((intel_crtc
->config
->pipe_src_h
- 1) << 16) |
2693 (intel_crtc
->config
->pipe_src_w
- 1));
2694 I915_WRITE(PRIMPOS(plane
), 0);
2695 I915_WRITE(PRIMCNSTALPHA(plane
), 0);
2698 switch (fb
->pixel_format
) {
2700 dspcntr
|= DISPPLANE_8BPP
;
2702 case DRM_FORMAT_XRGB1555
:
2703 case DRM_FORMAT_ARGB1555
:
2704 dspcntr
|= DISPPLANE_BGRX555
;
2706 case DRM_FORMAT_RGB565
:
2707 dspcntr
|= DISPPLANE_BGRX565
;
2709 case DRM_FORMAT_XRGB8888
:
2710 case DRM_FORMAT_ARGB8888
:
2711 dspcntr
|= DISPPLANE_BGRX888
;
2713 case DRM_FORMAT_XBGR8888
:
2714 case DRM_FORMAT_ABGR8888
:
2715 dspcntr
|= DISPPLANE_RGBX888
;
2717 case DRM_FORMAT_XRGB2101010
:
2718 case DRM_FORMAT_ARGB2101010
:
2719 dspcntr
|= DISPPLANE_BGRX101010
;
2721 case DRM_FORMAT_XBGR2101010
:
2722 case DRM_FORMAT_ABGR2101010
:
2723 dspcntr
|= DISPPLANE_RGBX101010
;
2729 if (INTEL_INFO(dev
)->gen
>= 4 &&
2730 obj
->tiling_mode
!= I915_TILING_NONE
)
2731 dspcntr
|= DISPPLANE_TILED
;
2734 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2736 linear_offset
= y
* fb
->pitches
[0] + x
* pixel_size
;
2738 if (INTEL_INFO(dev
)->gen
>= 4) {
2739 intel_crtc
->dspaddr_offset
=
2740 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2743 linear_offset
-= intel_crtc
->dspaddr_offset
;
2745 intel_crtc
->dspaddr_offset
= linear_offset
;
2748 if (crtc
->primary
->state
->rotation
== BIT(DRM_ROTATE_180
)) {
2749 dspcntr
|= DISPPLANE_ROTATE_180
;
2751 x
+= (intel_crtc
->config
->pipe_src_w
- 1);
2752 y
+= (intel_crtc
->config
->pipe_src_h
- 1);
2754 /* Finding the last pixel of the last line of the display
2755 data and adding to linear_offset*/
2757 (intel_crtc
->config
->pipe_src_h
- 1) * fb
->pitches
[0] +
2758 (intel_crtc
->config
->pipe_src_w
- 1) * pixel_size
;
2761 I915_WRITE(reg
, dspcntr
);
2763 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2764 if (INTEL_INFO(dev
)->gen
>= 4) {
2765 I915_WRITE(DSPSURF(plane
),
2766 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2767 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2768 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2770 I915_WRITE(DSPADDR(plane
), i915_gem_obj_ggtt_offset(obj
) + linear_offset
);
2774 static void ironlake_update_primary_plane(struct drm_crtc
*crtc
,
2775 struct drm_framebuffer
*fb
,
2778 struct drm_device
*dev
= crtc
->dev
;
2779 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2780 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2781 struct drm_plane
*primary
= crtc
->primary
;
2782 bool visible
= to_intel_plane_state(primary
->state
)->visible
;
2783 struct drm_i915_gem_object
*obj
;
2784 int plane
= intel_crtc
->plane
;
2785 unsigned long linear_offset
;
2787 u32 reg
= DSPCNTR(plane
);
2790 if (!visible
|| !fb
) {
2792 I915_WRITE(DSPSURF(plane
), 0);
2797 obj
= intel_fb_obj(fb
);
2798 if (WARN_ON(obj
== NULL
))
2801 pixel_size
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2803 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2805 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2807 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2808 dspcntr
|= DISPPLANE_PIPE_CSC_ENABLE
;
2810 switch (fb
->pixel_format
) {
2812 dspcntr
|= DISPPLANE_8BPP
;
2814 case DRM_FORMAT_RGB565
:
2815 dspcntr
|= DISPPLANE_BGRX565
;
2817 case DRM_FORMAT_XRGB8888
:
2818 case DRM_FORMAT_ARGB8888
:
2819 dspcntr
|= DISPPLANE_BGRX888
;
2821 case DRM_FORMAT_XBGR8888
:
2822 case DRM_FORMAT_ABGR8888
:
2823 dspcntr
|= DISPPLANE_RGBX888
;
2825 case DRM_FORMAT_XRGB2101010
:
2826 case DRM_FORMAT_ARGB2101010
:
2827 dspcntr
|= DISPPLANE_BGRX101010
;
2829 case DRM_FORMAT_XBGR2101010
:
2830 case DRM_FORMAT_ABGR2101010
:
2831 dspcntr
|= DISPPLANE_RGBX101010
;
2837 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2838 dspcntr
|= DISPPLANE_TILED
;
2840 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
))
2841 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2843 linear_offset
= y
* fb
->pitches
[0] + x
* pixel_size
;
2844 intel_crtc
->dspaddr_offset
=
2845 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2848 linear_offset
-= intel_crtc
->dspaddr_offset
;
2849 if (crtc
->primary
->state
->rotation
== BIT(DRM_ROTATE_180
)) {
2850 dspcntr
|= DISPPLANE_ROTATE_180
;
2852 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
)) {
2853 x
+= (intel_crtc
->config
->pipe_src_w
- 1);
2854 y
+= (intel_crtc
->config
->pipe_src_h
- 1);
2856 /* Finding the last pixel of the last line of the display
2857 data and adding to linear_offset*/
2859 (intel_crtc
->config
->pipe_src_h
- 1) * fb
->pitches
[0] +
2860 (intel_crtc
->config
->pipe_src_w
- 1) * pixel_size
;
2864 I915_WRITE(reg
, dspcntr
);
2866 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2867 I915_WRITE(DSPSURF(plane
),
2868 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2869 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2870 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
2872 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2873 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2878 u32
intel_fb_stride_alignment(struct drm_device
*dev
, uint64_t fb_modifier
,
2879 uint32_t pixel_format
)
2881 u32 bits_per_pixel
= drm_format_plane_cpp(pixel_format
, 0) * 8;
2884 * The stride is either expressed as a multiple of 64 bytes
2885 * chunks for linear buffers or in number of tiles for tiled
2888 switch (fb_modifier
) {
2889 case DRM_FORMAT_MOD_NONE
:
2891 case I915_FORMAT_MOD_X_TILED
:
2892 if (INTEL_INFO(dev
)->gen
== 2)
2895 case I915_FORMAT_MOD_Y_TILED
:
2896 /* No need to check for old gens and Y tiling since this is
2897 * about the display engine and those will be blocked before
2901 case I915_FORMAT_MOD_Yf_TILED
:
2902 if (bits_per_pixel
== 8)
2907 MISSING_CASE(fb_modifier
);
2912 unsigned long intel_plane_obj_offset(struct intel_plane
*intel_plane
,
2913 struct drm_i915_gem_object
*obj
)
2915 const struct i915_ggtt_view
*view
= &i915_ggtt_view_normal
;
2917 if (intel_rotation_90_or_270(intel_plane
->base
.state
->rotation
))
2918 view
= &i915_ggtt_view_rotated
;
2920 return i915_gem_obj_ggtt_offset_view(obj
, view
);
2924 * This function detaches (aka. unbinds) unused scalers in hardware
2926 void skl_detach_scalers(struct intel_crtc
*intel_crtc
)
2928 struct drm_device
*dev
;
2929 struct drm_i915_private
*dev_priv
;
2930 struct intel_crtc_scaler_state
*scaler_state
;
2933 if (!intel_crtc
|| !intel_crtc
->config
)
2936 dev
= intel_crtc
->base
.dev
;
2937 dev_priv
= dev
->dev_private
;
2938 scaler_state
= &intel_crtc
->config
->scaler_state
;
2940 /* loop through and disable scalers that aren't in use */
2941 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
2942 if (!scaler_state
->scalers
[i
].in_use
) {
2943 I915_WRITE(SKL_PS_CTRL(intel_crtc
->pipe
, i
), 0);
2944 I915_WRITE(SKL_PS_WIN_POS(intel_crtc
->pipe
, i
), 0);
2945 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc
->pipe
, i
), 0);
2946 DRM_DEBUG_KMS("CRTC:%d Disabled scaler id %u.%u\n",
2947 intel_crtc
->base
.base
.id
, intel_crtc
->pipe
, i
);
2952 u32
skl_plane_ctl_format(uint32_t pixel_format
)
2954 u32 plane_ctl_format
= 0;
2955 switch (pixel_format
) {
2956 case DRM_FORMAT_RGB565
:
2957 plane_ctl_format
= PLANE_CTL_FORMAT_RGB_565
;
2959 case DRM_FORMAT_XBGR8888
:
2960 plane_ctl_format
= PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
;
2962 case DRM_FORMAT_XRGB8888
:
2963 plane_ctl_format
= PLANE_CTL_FORMAT_XRGB_8888
;
2966 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
2967 * to be already pre-multiplied. We need to add a knob (or a different
2968 * DRM_FORMAT) for user-space to configure that.
2970 case DRM_FORMAT_ABGR8888
:
2971 plane_ctl_format
= PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
|
2972 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
2974 case DRM_FORMAT_ARGB8888
:
2975 plane_ctl_format
= PLANE_CTL_FORMAT_XRGB_8888
|
2976 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
2978 case DRM_FORMAT_XRGB2101010
:
2979 plane_ctl_format
= PLANE_CTL_FORMAT_XRGB_2101010
;
2981 case DRM_FORMAT_XBGR2101010
:
2982 plane_ctl_format
= PLANE_CTL_ORDER_RGBX
| PLANE_CTL_FORMAT_XRGB_2101010
;
2984 case DRM_FORMAT_YUYV
:
2985 plane_ctl_format
= PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YUYV
;
2987 case DRM_FORMAT_YVYU
:
2988 plane_ctl_format
= PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YVYU
;
2990 case DRM_FORMAT_UYVY
:
2991 plane_ctl_format
= PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_UYVY
;
2993 case DRM_FORMAT_VYUY
:
2994 plane_ctl_format
= PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_VYUY
;
2999 return plane_ctl_format
;
3002 u32
skl_plane_ctl_tiling(uint64_t fb_modifier
)
3004 u32 plane_ctl_tiling
= 0;
3005 switch (fb_modifier
) {
3006 case DRM_FORMAT_MOD_NONE
:
3008 case I915_FORMAT_MOD_X_TILED
:
3009 plane_ctl_tiling
= PLANE_CTL_TILED_X
;
3011 case I915_FORMAT_MOD_Y_TILED
:
3012 plane_ctl_tiling
= PLANE_CTL_TILED_Y
;
3014 case I915_FORMAT_MOD_Yf_TILED
:
3015 plane_ctl_tiling
= PLANE_CTL_TILED_YF
;
3018 MISSING_CASE(fb_modifier
);
3020 return plane_ctl_tiling
;
3023 u32
skl_plane_ctl_rotation(unsigned int rotation
)
3025 u32 plane_ctl_rotation
= 0;
3027 case BIT(DRM_ROTATE_0
):
3029 case BIT(DRM_ROTATE_90
):
3030 plane_ctl_rotation
= PLANE_CTL_ROTATE_90
;
3032 case BIT(DRM_ROTATE_180
):
3033 plane_ctl_rotation
= PLANE_CTL_ROTATE_180
;
3035 case BIT(DRM_ROTATE_270
):
3036 plane_ctl_rotation
= PLANE_CTL_ROTATE_270
;
3039 MISSING_CASE(rotation
);
3042 return plane_ctl_rotation
;
3045 static void skylake_update_primary_plane(struct drm_crtc
*crtc
,
3046 struct drm_framebuffer
*fb
,
3049 struct drm_device
*dev
= crtc
->dev
;
3050 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3051 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3052 struct drm_plane
*plane
= crtc
->primary
;
3053 bool visible
= to_intel_plane_state(plane
->state
)->visible
;
3054 struct drm_i915_gem_object
*obj
;
3055 int pipe
= intel_crtc
->pipe
;
3056 u32 plane_ctl
, stride_div
, stride
;
3057 u32 tile_height
, plane_offset
, plane_size
;
3058 unsigned int rotation
;
3059 int x_offset
, y_offset
;
3060 unsigned long surf_addr
;
3061 struct intel_crtc_state
*crtc_state
= intel_crtc
->config
;
3062 struct intel_plane_state
*plane_state
;
3063 int src_x
= 0, src_y
= 0, src_w
= 0, src_h
= 0;
3064 int dst_x
= 0, dst_y
= 0, dst_w
= 0, dst_h
= 0;
3067 plane_state
= to_intel_plane_state(plane
->state
);
3069 if (!visible
|| !fb
) {
3070 I915_WRITE(PLANE_CTL(pipe
, 0), 0);
3071 I915_WRITE(PLANE_SURF(pipe
, 0), 0);
3072 POSTING_READ(PLANE_CTL(pipe
, 0));
3076 plane_ctl
= PLANE_CTL_ENABLE
|
3077 PLANE_CTL_PIPE_GAMMA_ENABLE
|
3078 PLANE_CTL_PIPE_CSC_ENABLE
;
3080 plane_ctl
|= skl_plane_ctl_format(fb
->pixel_format
);
3081 plane_ctl
|= skl_plane_ctl_tiling(fb
->modifier
[0]);
3082 plane_ctl
|= PLANE_CTL_PLANE_GAMMA_DISABLE
;
3084 rotation
= plane
->state
->rotation
;
3085 plane_ctl
|= skl_plane_ctl_rotation(rotation
);
3087 obj
= intel_fb_obj(fb
);
3088 stride_div
= intel_fb_stride_alignment(dev
, fb
->modifier
[0],
3090 surf_addr
= intel_plane_obj_offset(to_intel_plane(plane
), obj
);
3093 * FIXME: intel_plane_state->src, dst aren't set when transitional
3094 * update_plane helpers are called from legacy paths.
3095 * Once full atomic crtc is available, below check can be avoided.
3097 if (drm_rect_width(&plane_state
->src
)) {
3098 scaler_id
= plane_state
->scaler_id
;
3099 src_x
= plane_state
->src
.x1
>> 16;
3100 src_y
= plane_state
->src
.y1
>> 16;
3101 src_w
= drm_rect_width(&plane_state
->src
) >> 16;
3102 src_h
= drm_rect_height(&plane_state
->src
) >> 16;
3103 dst_x
= plane_state
->dst
.x1
;
3104 dst_y
= plane_state
->dst
.y1
;
3105 dst_w
= drm_rect_width(&plane_state
->dst
);
3106 dst_h
= drm_rect_height(&plane_state
->dst
);
3108 WARN_ON(x
!= src_x
|| y
!= src_y
);
3110 src_w
= intel_crtc
->config
->pipe_src_w
;
3111 src_h
= intel_crtc
->config
->pipe_src_h
;
3114 if (intel_rotation_90_or_270(rotation
)) {
3115 /* stride = Surface height in tiles */
3116 tile_height
= intel_tile_height(dev
, fb
->bits_per_pixel
,
3118 stride
= DIV_ROUND_UP(fb
->height
, tile_height
);
3119 x_offset
= stride
* tile_height
- y
- src_h
;
3121 plane_size
= (src_w
- 1) << 16 | (src_h
- 1);
3123 stride
= fb
->pitches
[0] / stride_div
;
3126 plane_size
= (src_h
- 1) << 16 | (src_w
- 1);
3128 plane_offset
= y_offset
<< 16 | x_offset
;
3130 I915_WRITE(PLANE_CTL(pipe
, 0), plane_ctl
);
3131 I915_WRITE(PLANE_OFFSET(pipe
, 0), plane_offset
);
3132 I915_WRITE(PLANE_SIZE(pipe
, 0), plane_size
);
3133 I915_WRITE(PLANE_STRIDE(pipe
, 0), stride
);
3135 if (scaler_id
>= 0) {
3136 uint32_t ps_ctrl
= 0;
3138 WARN_ON(!dst_w
|| !dst_h
);
3139 ps_ctrl
= PS_SCALER_EN
| PS_PLANE_SEL(0) |
3140 crtc_state
->scaler_state
.scalers
[scaler_id
].mode
;
3141 I915_WRITE(SKL_PS_CTRL(pipe
, scaler_id
), ps_ctrl
);
3142 I915_WRITE(SKL_PS_PWR_GATE(pipe
, scaler_id
), 0);
3143 I915_WRITE(SKL_PS_WIN_POS(pipe
, scaler_id
), (dst_x
<< 16) | dst_y
);
3144 I915_WRITE(SKL_PS_WIN_SZ(pipe
, scaler_id
), (dst_w
<< 16) | dst_h
);
3145 I915_WRITE(PLANE_POS(pipe
, 0), 0);
3147 I915_WRITE(PLANE_POS(pipe
, 0), (dst_y
<< 16) | dst_x
);
3150 I915_WRITE(PLANE_SURF(pipe
, 0), surf_addr
);
3152 POSTING_READ(PLANE_SURF(pipe
, 0));
3155 /* Assume fb object is pinned & idle & fenced and just update base pointers */
3157 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
3158 int x
, int y
, enum mode_set_atomic state
)
3160 struct drm_device
*dev
= crtc
->dev
;
3161 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3163 if (dev_priv
->display
.disable_fbc
)
3164 dev_priv
->display
.disable_fbc(dev
);
3166 dev_priv
->display
.update_primary_plane(crtc
, fb
, x
, y
);
3171 static void intel_complete_page_flips(struct drm_device
*dev
)
3173 struct drm_crtc
*crtc
;
3175 for_each_crtc(dev
, crtc
) {
3176 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3177 enum plane plane
= intel_crtc
->plane
;
3179 intel_prepare_page_flip(dev
, plane
);
3180 intel_finish_page_flip_plane(dev
, plane
);
3184 static void intel_update_primary_planes(struct drm_device
*dev
)
3186 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3187 struct drm_crtc
*crtc
;
3189 for_each_crtc(dev
, crtc
) {
3190 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3192 drm_modeset_lock(&crtc
->mutex
, NULL
);
3194 * FIXME: Once we have proper support for primary planes (and
3195 * disabling them without disabling the entire crtc) allow again
3196 * a NULL crtc->primary->fb.
3198 if (intel_crtc
->active
&& crtc
->primary
->fb
)
3199 dev_priv
->display
.update_primary_plane(crtc
,
3203 drm_modeset_unlock(&crtc
->mutex
);
3207 void intel_crtc_reset(struct intel_crtc
*crtc
)
3209 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
3214 intel_crtc_disable_planes(&crtc
->base
);
3215 dev_priv
->display
.crtc_disable(&crtc
->base
);
3216 dev_priv
->display
.crtc_enable(&crtc
->base
);
3217 intel_crtc_enable_planes(&crtc
->base
);
3220 void intel_prepare_reset(struct drm_device
*dev
)
3222 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3223 struct intel_crtc
*crtc
;
3225 /* no reset support for gen2 */
3229 /* reset doesn't touch the display */
3230 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
3233 drm_modeset_lock_all(dev
);
3236 * Disabling the crtcs gracefully seems nicer. Also the
3237 * g33 docs say we should at least disable all the planes.
3239 for_each_intel_crtc(dev
, crtc
) {
3243 intel_crtc_disable_planes(&crtc
->base
);
3244 dev_priv
->display
.crtc_disable(&crtc
->base
);
3248 void intel_finish_reset(struct drm_device
*dev
)
3250 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3253 * Flips in the rings will be nuked by the reset,
3254 * so complete all pending flips so that user space
3255 * will get its events and not get stuck.
3257 intel_complete_page_flips(dev
);
3259 /* no reset support for gen2 */
3263 /* reset doesn't touch the display */
3264 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
)) {
3266 * Flips in the rings have been nuked by the reset,
3267 * so update the base address of all primary
3268 * planes to the the last fb to make sure we're
3269 * showing the correct fb after a reset.
3271 intel_update_primary_planes(dev
);
3276 * The display has been reset as well,
3277 * so need a full re-initialization.
3279 intel_runtime_pm_disable_interrupts(dev_priv
);
3280 intel_runtime_pm_enable_interrupts(dev_priv
);
3282 intel_modeset_init_hw(dev
);
3284 spin_lock_irq(&dev_priv
->irq_lock
);
3285 if (dev_priv
->display
.hpd_irq_setup
)
3286 dev_priv
->display
.hpd_irq_setup(dev
);
3287 spin_unlock_irq(&dev_priv
->irq_lock
);
3289 intel_modeset_setup_hw_state(dev
, true);
3291 intel_hpd_init(dev_priv
);
3293 drm_modeset_unlock_all(dev
);
3297 intel_finish_fb(struct drm_framebuffer
*old_fb
)
3299 struct drm_i915_gem_object
*obj
= intel_fb_obj(old_fb
);
3300 struct drm_i915_private
*dev_priv
= obj
->base
.dev
->dev_private
;
3301 bool was_interruptible
= dev_priv
->mm
.interruptible
;
3304 /* Big Hammer, we also need to ensure that any pending
3305 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
3306 * current scanout is retired before unpinning the old
3309 * This should only fail upon a hung GPU, in which case we
3310 * can safely continue.
3312 dev_priv
->mm
.interruptible
= false;
3313 ret
= i915_gem_object_finish_gpu(obj
);
3314 dev_priv
->mm
.interruptible
= was_interruptible
;
3319 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
3321 struct drm_device
*dev
= crtc
->dev
;
3322 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3323 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3326 if (i915_reset_in_progress(&dev_priv
->gpu_error
) ||
3327 intel_crtc
->reset_counter
!= atomic_read(&dev_priv
->gpu_error
.reset_counter
))
3330 spin_lock_irq(&dev
->event_lock
);
3331 pending
= to_intel_crtc(crtc
)->unpin_work
!= NULL
;
3332 spin_unlock_irq(&dev
->event_lock
);
3337 static void intel_update_pipe_size(struct intel_crtc
*crtc
)
3339 struct drm_device
*dev
= crtc
->base
.dev
;
3340 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3341 const struct drm_display_mode
*adjusted_mode
;
3347 * Update pipe size and adjust fitter if needed: the reason for this is
3348 * that in compute_mode_changes we check the native mode (not the pfit
3349 * mode) to see if we can flip rather than do a full mode set. In the
3350 * fastboot case, we'll flip, but if we don't update the pipesrc and
3351 * pfit state, we'll end up with a big fb scanned out into the wrong
3354 * To fix this properly, we need to hoist the checks up into
3355 * compute_mode_changes (or above), check the actual pfit state and
3356 * whether the platform allows pfit disable with pipe active, and only
3357 * then update the pipesrc and pfit state, even on the flip path.
3360 adjusted_mode
= &crtc
->config
->base
.adjusted_mode
;
3362 I915_WRITE(PIPESRC(crtc
->pipe
),
3363 ((adjusted_mode
->crtc_hdisplay
- 1) << 16) |
3364 (adjusted_mode
->crtc_vdisplay
- 1));
3365 if (!crtc
->config
->pch_pfit
.enabled
&&
3366 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) ||
3367 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
3368 I915_WRITE(PF_CTL(crtc
->pipe
), 0);
3369 I915_WRITE(PF_WIN_POS(crtc
->pipe
), 0);
3370 I915_WRITE(PF_WIN_SZ(crtc
->pipe
), 0);
3372 crtc
->config
->pipe_src_w
= adjusted_mode
->crtc_hdisplay
;
3373 crtc
->config
->pipe_src_h
= adjusted_mode
->crtc_vdisplay
;
3376 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
3378 struct drm_device
*dev
= crtc
->dev
;
3379 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3380 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3381 int pipe
= intel_crtc
->pipe
;
3384 /* enable normal train */
3385 reg
= FDI_TX_CTL(pipe
);
3386 temp
= I915_READ(reg
);
3387 if (IS_IVYBRIDGE(dev
)) {
3388 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3389 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3391 temp
&= ~FDI_LINK_TRAIN_NONE
;
3392 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3394 I915_WRITE(reg
, temp
);
3396 reg
= FDI_RX_CTL(pipe
);
3397 temp
= I915_READ(reg
);
3398 if (HAS_PCH_CPT(dev
)) {
3399 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3400 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
3402 temp
&= ~FDI_LINK_TRAIN_NONE
;
3403 temp
|= FDI_LINK_TRAIN_NONE
;
3405 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
3407 /* wait one idle pattern time */
3411 /* IVB wants error correction enabled */
3412 if (IS_IVYBRIDGE(dev
))
3413 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
3414 FDI_FE_ERRC_ENABLE
);
3417 /* The FDI link training functions for ILK/Ibexpeak. */
3418 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
3420 struct drm_device
*dev
= crtc
->dev
;
3421 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3422 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3423 int pipe
= intel_crtc
->pipe
;
3424 u32 reg
, temp
, tries
;
3426 /* FDI needs bits from pipe first */
3427 assert_pipe_enabled(dev_priv
, pipe
);
3429 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3431 reg
= FDI_RX_IMR(pipe
);
3432 temp
= I915_READ(reg
);
3433 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3434 temp
&= ~FDI_RX_BIT_LOCK
;
3435 I915_WRITE(reg
, temp
);
3439 /* enable CPU FDI TX and PCH FDI RX */
3440 reg
= FDI_TX_CTL(pipe
);
3441 temp
= I915_READ(reg
);
3442 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3443 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3444 temp
&= ~FDI_LINK_TRAIN_NONE
;
3445 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3446 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3448 reg
= FDI_RX_CTL(pipe
);
3449 temp
= I915_READ(reg
);
3450 temp
&= ~FDI_LINK_TRAIN_NONE
;
3451 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3452 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3457 /* Ironlake workaround, enable clock pointer after FDI enable*/
3458 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3459 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
3460 FDI_RX_PHASE_SYNC_POINTER_EN
);
3462 reg
= FDI_RX_IIR(pipe
);
3463 for (tries
= 0; tries
< 5; tries
++) {
3464 temp
= I915_READ(reg
);
3465 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3467 if ((temp
& FDI_RX_BIT_LOCK
)) {
3468 DRM_DEBUG_KMS("FDI train 1 done.\n");
3469 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3474 DRM_ERROR("FDI train 1 fail!\n");
3477 reg
= FDI_TX_CTL(pipe
);
3478 temp
= I915_READ(reg
);
3479 temp
&= ~FDI_LINK_TRAIN_NONE
;
3480 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3481 I915_WRITE(reg
, temp
);
3483 reg
= FDI_RX_CTL(pipe
);
3484 temp
= I915_READ(reg
);
3485 temp
&= ~FDI_LINK_TRAIN_NONE
;
3486 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3487 I915_WRITE(reg
, temp
);
3492 reg
= FDI_RX_IIR(pipe
);
3493 for (tries
= 0; tries
< 5; tries
++) {
3494 temp
= I915_READ(reg
);
3495 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3497 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3498 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3499 DRM_DEBUG_KMS("FDI train 2 done.\n");
3504 DRM_ERROR("FDI train 2 fail!\n");
3506 DRM_DEBUG_KMS("FDI train done\n");
3510 static const int snb_b_fdi_train_param
[] = {
3511 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
3512 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
3513 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
3514 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
3517 /* The FDI link training functions for SNB/Cougarpoint. */
3518 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
3520 struct drm_device
*dev
= crtc
->dev
;
3521 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3522 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3523 int pipe
= intel_crtc
->pipe
;
3524 u32 reg
, temp
, i
, retry
;
3526 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3528 reg
= FDI_RX_IMR(pipe
);
3529 temp
= I915_READ(reg
);
3530 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3531 temp
&= ~FDI_RX_BIT_LOCK
;
3532 I915_WRITE(reg
, temp
);
3537 /* enable CPU FDI TX and PCH FDI RX */
3538 reg
= FDI_TX_CTL(pipe
);
3539 temp
= I915_READ(reg
);
3540 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3541 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3542 temp
&= ~FDI_LINK_TRAIN_NONE
;
3543 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3544 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3546 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3547 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3549 I915_WRITE(FDI_RX_MISC(pipe
),
3550 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3552 reg
= FDI_RX_CTL(pipe
);
3553 temp
= I915_READ(reg
);
3554 if (HAS_PCH_CPT(dev
)) {
3555 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3556 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3558 temp
&= ~FDI_LINK_TRAIN_NONE
;
3559 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3561 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3566 for (i
= 0; i
< 4; i
++) {
3567 reg
= FDI_TX_CTL(pipe
);
3568 temp
= I915_READ(reg
);
3569 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3570 temp
|= snb_b_fdi_train_param
[i
];
3571 I915_WRITE(reg
, temp
);
3576 for (retry
= 0; retry
< 5; retry
++) {
3577 reg
= FDI_RX_IIR(pipe
);
3578 temp
= I915_READ(reg
);
3579 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3580 if (temp
& FDI_RX_BIT_LOCK
) {
3581 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3582 DRM_DEBUG_KMS("FDI train 1 done.\n");
3591 DRM_ERROR("FDI train 1 fail!\n");
3594 reg
= FDI_TX_CTL(pipe
);
3595 temp
= I915_READ(reg
);
3596 temp
&= ~FDI_LINK_TRAIN_NONE
;
3597 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3599 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3601 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3603 I915_WRITE(reg
, temp
);
3605 reg
= FDI_RX_CTL(pipe
);
3606 temp
= I915_READ(reg
);
3607 if (HAS_PCH_CPT(dev
)) {
3608 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3609 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3611 temp
&= ~FDI_LINK_TRAIN_NONE
;
3612 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3614 I915_WRITE(reg
, temp
);
3619 for (i
= 0; i
< 4; i
++) {
3620 reg
= FDI_TX_CTL(pipe
);
3621 temp
= I915_READ(reg
);
3622 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3623 temp
|= snb_b_fdi_train_param
[i
];
3624 I915_WRITE(reg
, temp
);
3629 for (retry
= 0; retry
< 5; retry
++) {
3630 reg
= FDI_RX_IIR(pipe
);
3631 temp
= I915_READ(reg
);
3632 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3633 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3634 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3635 DRM_DEBUG_KMS("FDI train 2 done.\n");
3644 DRM_ERROR("FDI train 2 fail!\n");
3646 DRM_DEBUG_KMS("FDI train done.\n");
3649 /* Manual link training for Ivy Bridge A0 parts */
3650 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
3652 struct drm_device
*dev
= crtc
->dev
;
3653 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3654 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3655 int pipe
= intel_crtc
->pipe
;
3656 u32 reg
, temp
, i
, j
;
3658 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3660 reg
= FDI_RX_IMR(pipe
);
3661 temp
= I915_READ(reg
);
3662 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3663 temp
&= ~FDI_RX_BIT_LOCK
;
3664 I915_WRITE(reg
, temp
);
3669 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3670 I915_READ(FDI_RX_IIR(pipe
)));
3672 /* Try each vswing and preemphasis setting twice before moving on */
3673 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
3674 /* disable first in case we need to retry */
3675 reg
= FDI_TX_CTL(pipe
);
3676 temp
= I915_READ(reg
);
3677 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
3678 temp
&= ~FDI_TX_ENABLE
;
3679 I915_WRITE(reg
, temp
);
3681 reg
= FDI_RX_CTL(pipe
);
3682 temp
= I915_READ(reg
);
3683 temp
&= ~FDI_LINK_TRAIN_AUTO
;
3684 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3685 temp
&= ~FDI_RX_ENABLE
;
3686 I915_WRITE(reg
, temp
);
3688 /* enable CPU FDI TX and PCH FDI RX */
3689 reg
= FDI_TX_CTL(pipe
);
3690 temp
= I915_READ(reg
);
3691 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3692 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3693 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
3694 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3695 temp
|= snb_b_fdi_train_param
[j
/2];
3696 temp
|= FDI_COMPOSITE_SYNC
;
3697 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3699 I915_WRITE(FDI_RX_MISC(pipe
),
3700 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3702 reg
= FDI_RX_CTL(pipe
);
3703 temp
= I915_READ(reg
);
3704 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3705 temp
|= FDI_COMPOSITE_SYNC
;
3706 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3709 udelay(1); /* should be 0.5us */
3711 for (i
= 0; i
< 4; i
++) {
3712 reg
= FDI_RX_IIR(pipe
);
3713 temp
= I915_READ(reg
);
3714 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3716 if (temp
& FDI_RX_BIT_LOCK
||
3717 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
3718 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3719 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3723 udelay(1); /* should be 0.5us */
3726 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
3731 reg
= FDI_TX_CTL(pipe
);
3732 temp
= I915_READ(reg
);
3733 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3734 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
3735 I915_WRITE(reg
, temp
);
3737 reg
= FDI_RX_CTL(pipe
);
3738 temp
= I915_READ(reg
);
3739 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3740 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3741 I915_WRITE(reg
, temp
);
3744 udelay(2); /* should be 1.5us */
3746 for (i
= 0; i
< 4; i
++) {
3747 reg
= FDI_RX_IIR(pipe
);
3748 temp
= I915_READ(reg
);
3749 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3751 if (temp
& FDI_RX_SYMBOL_LOCK
||
3752 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
3753 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3754 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
3758 udelay(2); /* should be 1.5us */
3761 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
3765 DRM_DEBUG_KMS("FDI train done.\n");
3768 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
3770 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3771 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3772 int pipe
= intel_crtc
->pipe
;
3776 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
3777 reg
= FDI_RX_CTL(pipe
);
3778 temp
= I915_READ(reg
);
3779 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
3780 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3781 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3782 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
3787 /* Switch from Rawclk to PCDclk */
3788 temp
= I915_READ(reg
);
3789 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
3794 /* Enable CPU FDI TX PLL, always on for Ironlake */
3795 reg
= FDI_TX_CTL(pipe
);
3796 temp
= I915_READ(reg
);
3797 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
3798 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
3805 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
3807 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3808 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3809 int pipe
= intel_crtc
->pipe
;
3812 /* Switch from PCDclk to Rawclk */
3813 reg
= FDI_RX_CTL(pipe
);
3814 temp
= I915_READ(reg
);
3815 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
3817 /* Disable CPU FDI TX PLL */
3818 reg
= FDI_TX_CTL(pipe
);
3819 temp
= I915_READ(reg
);
3820 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
3825 reg
= FDI_RX_CTL(pipe
);
3826 temp
= I915_READ(reg
);
3827 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
3829 /* Wait for the clocks to turn off. */
3834 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
3836 struct drm_device
*dev
= crtc
->dev
;
3837 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3838 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3839 int pipe
= intel_crtc
->pipe
;
3842 /* disable CPU FDI tx and PCH FDI rx */
3843 reg
= FDI_TX_CTL(pipe
);
3844 temp
= I915_READ(reg
);
3845 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
3848 reg
= FDI_RX_CTL(pipe
);
3849 temp
= I915_READ(reg
);
3850 temp
&= ~(0x7 << 16);
3851 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3852 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
3857 /* Ironlake workaround, disable clock pointer after downing FDI */
3858 if (HAS_PCH_IBX(dev
))
3859 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3861 /* still set train pattern 1 */
3862 reg
= FDI_TX_CTL(pipe
);
3863 temp
= I915_READ(reg
);
3864 temp
&= ~FDI_LINK_TRAIN_NONE
;
3865 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3866 I915_WRITE(reg
, temp
);
3868 reg
= FDI_RX_CTL(pipe
);
3869 temp
= I915_READ(reg
);
3870 if (HAS_PCH_CPT(dev
)) {
3871 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3872 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3874 temp
&= ~FDI_LINK_TRAIN_NONE
;
3875 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3877 /* BPC in FDI rx is consistent with that in PIPECONF */
3878 temp
&= ~(0x07 << 16);
3879 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3880 I915_WRITE(reg
, temp
);
3886 bool intel_has_pending_fb_unpin(struct drm_device
*dev
)
3888 struct intel_crtc
*crtc
;
3890 /* Note that we don't need to be called with mode_config.lock here
3891 * as our list of CRTC objects is static for the lifetime of the
3892 * device and so cannot disappear as we iterate. Similarly, we can
3893 * happily treat the predicates as racy, atomic checks as userspace
3894 * cannot claim and pin a new fb without at least acquring the
3895 * struct_mutex and so serialising with us.
3897 for_each_intel_crtc(dev
, crtc
) {
3898 if (atomic_read(&crtc
->unpin_work_count
) == 0)
3901 if (crtc
->unpin_work
)
3902 intel_wait_for_vblank(dev
, crtc
->pipe
);
3910 static void page_flip_completed(struct intel_crtc
*intel_crtc
)
3912 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
3913 struct intel_unpin_work
*work
= intel_crtc
->unpin_work
;
3915 /* ensure that the unpin work is consistent wrt ->pending. */
3917 intel_crtc
->unpin_work
= NULL
;
3920 drm_send_vblank_event(intel_crtc
->base
.dev
,
3924 drm_crtc_vblank_put(&intel_crtc
->base
);
3926 wake_up_all(&dev_priv
->pending_flip_queue
);
3927 queue_work(dev_priv
->wq
, &work
->work
);
3929 trace_i915_flip_complete(intel_crtc
->plane
,
3930 work
->pending_flip_obj
);
3933 void intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
3935 struct drm_device
*dev
= crtc
->dev
;
3936 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3938 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
3939 if (WARN_ON(wait_event_timeout(dev_priv
->pending_flip_queue
,
3940 !intel_crtc_has_pending_flip(crtc
),
3942 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3944 spin_lock_irq(&dev
->event_lock
);
3945 if (intel_crtc
->unpin_work
) {
3946 WARN_ONCE(1, "Removing stuck page flip\n");
3947 page_flip_completed(intel_crtc
);
3949 spin_unlock_irq(&dev
->event_lock
);
3952 if (crtc
->primary
->fb
) {
3953 mutex_lock(&dev
->struct_mutex
);
3954 intel_finish_fb(crtc
->primary
->fb
);
3955 mutex_unlock(&dev
->struct_mutex
);
3959 /* Program iCLKIP clock to the desired frequency */
3960 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
3962 struct drm_device
*dev
= crtc
->dev
;
3963 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3964 int clock
= to_intel_crtc(crtc
)->config
->base
.adjusted_mode
.crtc_clock
;
3965 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
3968 mutex_lock(&dev_priv
->dpio_lock
);
3970 /* It is necessary to ungate the pixclk gate prior to programming
3971 * the divisors, and gate it back when it is done.
3973 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
3975 /* Disable SSCCTL */
3976 intel_sbi_write(dev_priv
, SBI_SSCCTL6
,
3977 intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
) |
3981 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
3982 if (clock
== 20000) {
3987 /* The iCLK virtual clock root frequency is in MHz,
3988 * but the adjusted_mode->crtc_clock in in KHz. To get the
3989 * divisors, it is necessary to divide one by another, so we
3990 * convert the virtual clock precision to KHz here for higher
3993 u32 iclk_virtual_root_freq
= 172800 * 1000;
3994 u32 iclk_pi_range
= 64;
3995 u32 desired_divisor
, msb_divisor_value
, pi_value
;
3997 desired_divisor
= (iclk_virtual_root_freq
/ clock
);
3998 msb_divisor_value
= desired_divisor
/ iclk_pi_range
;
3999 pi_value
= desired_divisor
% iclk_pi_range
;
4002 divsel
= msb_divisor_value
- 2;
4003 phaseinc
= pi_value
;
4006 /* This should not happen with any sane values */
4007 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
4008 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
4009 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
4010 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
4012 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4019 /* Program SSCDIVINTPHASE6 */
4020 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
4021 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
4022 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
4023 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
4024 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
4025 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
4026 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
4027 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
4029 /* Program SSCAUXDIV */
4030 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
4031 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4032 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
4033 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
4035 /* Enable modulator and associated divider */
4036 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4037 temp
&= ~SBI_SSCCTL_DISABLE
;
4038 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
4040 /* Wait for initialization time */
4043 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
4045 mutex_unlock(&dev_priv
->dpio_lock
);
4048 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
4049 enum pipe pch_transcoder
)
4051 struct drm_device
*dev
= crtc
->base
.dev
;
4052 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4053 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
4055 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
4056 I915_READ(HTOTAL(cpu_transcoder
)));
4057 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
4058 I915_READ(HBLANK(cpu_transcoder
)));
4059 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
4060 I915_READ(HSYNC(cpu_transcoder
)));
4062 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
4063 I915_READ(VTOTAL(cpu_transcoder
)));
4064 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
4065 I915_READ(VBLANK(cpu_transcoder
)));
4066 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
4067 I915_READ(VSYNC(cpu_transcoder
)));
4068 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
4069 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
4072 static void cpt_set_fdi_bc_bifurcation(struct drm_device
*dev
, bool enable
)
4074 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4077 temp
= I915_READ(SOUTH_CHICKEN1
);
4078 if (!!(temp
& FDI_BC_BIFURCATION_SELECT
) == enable
)
4081 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
4082 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
4084 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
4086 temp
|= FDI_BC_BIFURCATION_SELECT
;
4088 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable
? "en" : "dis");
4089 I915_WRITE(SOUTH_CHICKEN1
, temp
);
4090 POSTING_READ(SOUTH_CHICKEN1
);
4093 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
4095 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4097 switch (intel_crtc
->pipe
) {
4101 if (intel_crtc
->config
->fdi_lanes
> 2)
4102 cpt_set_fdi_bc_bifurcation(dev
, false);
4104 cpt_set_fdi_bc_bifurcation(dev
, true);
4108 cpt_set_fdi_bc_bifurcation(dev
, true);
4117 * Enable PCH resources required for PCH ports:
4119 * - FDI training & RX/TX
4120 * - update transcoder timings
4121 * - DP transcoding bits
4124 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
4126 struct drm_device
*dev
= crtc
->dev
;
4127 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4128 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4129 int pipe
= intel_crtc
->pipe
;
4132 assert_pch_transcoder_disabled(dev_priv
, pipe
);
4134 if (IS_IVYBRIDGE(dev
))
4135 ivybridge_update_fdi_bc_bifurcation(intel_crtc
);
4137 /* Write the TU size bits before fdi link training, so that error
4138 * detection works. */
4139 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
4140 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
4142 /* For PCH output, training FDI link */
4143 dev_priv
->display
.fdi_link_train(crtc
);
4145 /* We need to program the right clock selection before writing the pixel
4146 * mutliplier into the DPLL. */
4147 if (HAS_PCH_CPT(dev
)) {
4150 temp
= I915_READ(PCH_DPLL_SEL
);
4151 temp
|= TRANS_DPLL_ENABLE(pipe
);
4152 sel
= TRANS_DPLLB_SEL(pipe
);
4153 if (intel_crtc
->config
->shared_dpll
== DPLL_ID_PCH_PLL_B
)
4157 I915_WRITE(PCH_DPLL_SEL
, temp
);
4160 /* XXX: pch pll's can be enabled any time before we enable the PCH
4161 * transcoder, and we actually should do this to not upset any PCH
4162 * transcoder that already use the clock when we share it.
4164 * Note that enable_shared_dpll tries to do the right thing, but
4165 * get_shared_dpll unconditionally resets the pll - we need that to have
4166 * the right LVDS enable sequence. */
4167 intel_enable_shared_dpll(intel_crtc
);
4169 /* set transcoder timing, panel must allow it */
4170 assert_panel_unlocked(dev_priv
, pipe
);
4171 ironlake_pch_transcoder_set_timings(intel_crtc
, pipe
);
4173 intel_fdi_normal_train(crtc
);
4175 /* For PCH DP, enable TRANS_DP_CTL */
4176 if (HAS_PCH_CPT(dev
) && intel_crtc
->config
->has_dp_encoder
) {
4177 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
4178 reg
= TRANS_DP_CTL(pipe
);
4179 temp
= I915_READ(reg
);
4180 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
4181 TRANS_DP_SYNC_MASK
|
4183 temp
|= (TRANS_DP_OUTPUT_ENABLE
|
4184 TRANS_DP_ENH_FRAMING
);
4185 temp
|= bpc
<< 9; /* same format but at 11:9 */
4187 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PHSYNC
)
4188 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
4189 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PVSYNC
)
4190 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
4192 switch (intel_trans_dp_port_sel(crtc
)) {
4194 temp
|= TRANS_DP_PORT_SEL_B
;
4197 temp
|= TRANS_DP_PORT_SEL_C
;
4200 temp
|= TRANS_DP_PORT_SEL_D
;
4206 I915_WRITE(reg
, temp
);
4209 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
4212 static void lpt_pch_enable(struct drm_crtc
*crtc
)
4214 struct drm_device
*dev
= crtc
->dev
;
4215 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4216 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4217 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
4219 assert_pch_transcoder_disabled(dev_priv
, TRANSCODER_A
);
4221 lpt_program_iclkip(crtc
);
4223 /* Set transcoder timing. */
4224 ironlake_pch_transcoder_set_timings(intel_crtc
, PIPE_A
);
4226 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
4229 void intel_put_shared_dpll(struct intel_crtc
*crtc
)
4231 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
4236 if (!(pll
->config
.crtc_mask
& (1 << crtc
->pipe
))) {
4237 WARN(1, "bad %s crtc mask\n", pll
->name
);
4241 pll
->config
.crtc_mask
&= ~(1 << crtc
->pipe
);
4242 if (pll
->config
.crtc_mask
== 0) {
4244 WARN_ON(pll
->active
);
4247 crtc
->config
->shared_dpll
= DPLL_ID_PRIVATE
;
4250 struct intel_shared_dpll
*intel_get_shared_dpll(struct intel_crtc
*crtc
,
4251 struct intel_crtc_state
*crtc_state
)
4253 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
4254 struct intel_shared_dpll
*pll
;
4255 enum intel_dpll_id i
;
4257 if (HAS_PCH_IBX(dev_priv
->dev
)) {
4258 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
4259 i
= (enum intel_dpll_id
) crtc
->pipe
;
4260 pll
= &dev_priv
->shared_dplls
[i
];
4262 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
4263 crtc
->base
.base
.id
, pll
->name
);
4265 WARN_ON(pll
->new_config
->crtc_mask
);
4270 if (IS_BROXTON(dev_priv
->dev
)) {
4271 /* PLL is attached to port in bxt */
4272 struct intel_encoder
*encoder
;
4273 struct intel_digital_port
*intel_dig_port
;
4275 encoder
= intel_ddi_get_crtc_new_encoder(crtc_state
);
4276 if (WARN_ON(!encoder
))
4279 intel_dig_port
= enc_to_dig_port(&encoder
->base
);
4280 /* 1:1 mapping between ports and PLLs */
4281 i
= (enum intel_dpll_id
)intel_dig_port
->port
;
4282 pll
= &dev_priv
->shared_dplls
[i
];
4283 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
4284 crtc
->base
.base
.id
, pll
->name
);
4285 WARN_ON(pll
->new_config
->crtc_mask
);
4290 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4291 pll
= &dev_priv
->shared_dplls
[i
];
4293 /* Only want to check enabled timings first */
4294 if (pll
->new_config
->crtc_mask
== 0)
4297 if (memcmp(&crtc_state
->dpll_hw_state
,
4298 &pll
->new_config
->hw_state
,
4299 sizeof(pll
->new_config
->hw_state
)) == 0) {
4300 DRM_DEBUG_KMS("CRTC:%d sharing existing %s (crtc mask 0x%08x, ative %d)\n",
4301 crtc
->base
.base
.id
, pll
->name
,
4302 pll
->new_config
->crtc_mask
,
4308 /* Ok no matching timings, maybe there's a free one? */
4309 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4310 pll
= &dev_priv
->shared_dplls
[i
];
4311 if (pll
->new_config
->crtc_mask
== 0) {
4312 DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
4313 crtc
->base
.base
.id
, pll
->name
);
4321 if (pll
->new_config
->crtc_mask
== 0)
4322 pll
->new_config
->hw_state
= crtc_state
->dpll_hw_state
;
4324 crtc_state
->shared_dpll
= i
;
4325 DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll
->name
,
4326 pipe_name(crtc
->pipe
));
4328 pll
->new_config
->crtc_mask
|= 1 << crtc
->pipe
;
4334 * intel_shared_dpll_start_config - start a new PLL staged config
4335 * @dev_priv: DRM device
4336 * @clear_pipes: mask of pipes that will have their PLLs freed
4338 * Starts a new PLL staged config, copying the current config but
4339 * releasing the references of pipes specified in clear_pipes.
4341 static int intel_shared_dpll_start_config(struct drm_i915_private
*dev_priv
,
4342 unsigned clear_pipes
)
4344 struct intel_shared_dpll
*pll
;
4345 enum intel_dpll_id i
;
4347 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4348 pll
= &dev_priv
->shared_dplls
[i
];
4350 pll
->new_config
= kmemdup(&pll
->config
, sizeof pll
->config
,
4352 if (!pll
->new_config
)
4355 pll
->new_config
->crtc_mask
&= ~clear_pipes
;
4362 pll
= &dev_priv
->shared_dplls
[i
];
4363 kfree(pll
->new_config
);
4364 pll
->new_config
= NULL
;
4370 static void intel_shared_dpll_commit(struct drm_i915_private
*dev_priv
)
4372 struct intel_shared_dpll
*pll
;
4373 enum intel_dpll_id i
;
4375 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4376 pll
= &dev_priv
->shared_dplls
[i
];
4378 WARN_ON(pll
->new_config
== &pll
->config
);
4380 pll
->config
= *pll
->new_config
;
4381 kfree(pll
->new_config
);
4382 pll
->new_config
= NULL
;
4386 static void intel_shared_dpll_abort_config(struct drm_i915_private
*dev_priv
)
4388 struct intel_shared_dpll
*pll
;
4389 enum intel_dpll_id i
;
4391 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4392 pll
= &dev_priv
->shared_dplls
[i
];
4394 WARN_ON(pll
->new_config
== &pll
->config
);
4396 kfree(pll
->new_config
);
4397 pll
->new_config
= NULL
;
4401 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
4403 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4404 int dslreg
= PIPEDSL(pipe
);
4407 temp
= I915_READ(dslreg
);
4409 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
4410 if (wait_for(I915_READ(dslreg
) != temp
, 5))
4411 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
4416 * skl_update_scaler_users - Stages update to crtc's scaler state
4418 * @crtc_state: crtc_state
4419 * @plane: plane (NULL indicates crtc is requesting update)
4420 * @plane_state: plane's state
4421 * @force_detach: request unconditional detachment of scaler
4423 * This function updates scaler state for requested plane or crtc.
4424 * To request scaler usage update for a plane, caller shall pass plane pointer.
4425 * To request scaler usage update for crtc, caller shall pass plane pointer
4429 * 0 - scaler_usage updated successfully
4430 * error - requested scaling cannot be supported or other error condition
4433 skl_update_scaler_users(
4434 struct intel_crtc
*intel_crtc
, struct intel_crtc_state
*crtc_state
,
4435 struct intel_plane
*intel_plane
, struct intel_plane_state
*plane_state
,
4440 int src_w
, src_h
, dst_w
, dst_h
;
4442 struct drm_framebuffer
*fb
;
4443 struct intel_crtc_scaler_state
*scaler_state
;
4444 unsigned int rotation
;
4446 if (!intel_crtc
|| !crtc_state
)
4449 scaler_state
= &crtc_state
->scaler_state
;
4451 idx
= intel_plane
? drm_plane_index(&intel_plane
->base
) : SKL_CRTC_INDEX
;
4452 fb
= intel_plane
? plane_state
->base
.fb
: NULL
;
4455 src_w
= drm_rect_width(&plane_state
->src
) >> 16;
4456 src_h
= drm_rect_height(&plane_state
->src
) >> 16;
4457 dst_w
= drm_rect_width(&plane_state
->dst
);
4458 dst_h
= drm_rect_height(&plane_state
->dst
);
4459 scaler_id
= &plane_state
->scaler_id
;
4460 rotation
= plane_state
->base
.rotation
;
4462 struct drm_display_mode
*adjusted_mode
=
4463 &crtc_state
->base
.adjusted_mode
;
4464 src_w
= crtc_state
->pipe_src_w
;
4465 src_h
= crtc_state
->pipe_src_h
;
4466 dst_w
= adjusted_mode
->hdisplay
;
4467 dst_h
= adjusted_mode
->vdisplay
;
4468 scaler_id
= &scaler_state
->scaler_id
;
4469 rotation
= DRM_ROTATE_0
;
4472 need_scaling
= intel_rotation_90_or_270(rotation
) ?
4473 (src_h
!= dst_w
|| src_w
!= dst_h
):
4474 (src_w
!= dst_w
|| src_h
!= dst_h
);
4477 * if plane is being disabled or scaler is no more required or force detach
4478 * - free scaler binded to this plane/crtc
4479 * - in order to do this, update crtc->scaler_usage
4481 * Here scaler state in crtc_state is set free so that
4482 * scaler can be assigned to other user. Actual register
4483 * update to free the scaler is done in plane/panel-fit programming.
4484 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4486 if (force_detach
|| !need_scaling
|| (intel_plane
&&
4487 (!fb
|| !plane_state
->visible
))) {
4488 if (*scaler_id
>= 0) {
4489 scaler_state
->scaler_users
&= ~(1 << idx
);
4490 scaler_state
->scalers
[*scaler_id
].in_use
= 0;
4492 DRM_DEBUG_KMS("Staged freeing scaler id %d.%d from %s:%d "
4493 "crtc_state = %p scaler_users = 0x%x\n",
4494 intel_crtc
->pipe
, *scaler_id
, intel_plane
? "PLANE" : "CRTC",
4495 intel_plane
? intel_plane
->base
.base
.id
:
4496 intel_crtc
->base
.base
.id
, crtc_state
,
4497 scaler_state
->scaler_users
);
4504 if (src_w
< SKL_MIN_SRC_W
|| src_h
< SKL_MIN_SRC_H
||
4505 dst_w
< SKL_MIN_DST_W
|| dst_h
< SKL_MIN_DST_H
||
4507 src_w
> SKL_MAX_SRC_W
|| src_h
> SKL_MAX_SRC_H
||
4508 dst_w
> SKL_MAX_DST_W
|| dst_h
> SKL_MAX_DST_H
) {
4509 DRM_DEBUG_KMS("%s:%d scaler_user index %u.%u: src %ux%u dst %ux%u "
4510 "size is out of scaler range\n",
4511 intel_plane
? "PLANE" : "CRTC",
4512 intel_plane
? intel_plane
->base
.base
.id
: intel_crtc
->base
.base
.id
,
4513 intel_crtc
->pipe
, idx
, src_w
, src_h
, dst_w
, dst_h
);
4517 /* check colorkey */
4518 if (intel_plane
&& intel_plane
->ckey
.flags
!= I915_SET_COLORKEY_NONE
) {
4519 DRM_DEBUG_KMS("PLANE:%d scaling with color key not allowed",
4520 intel_plane
->base
.base
.id
);
4524 /* Check src format */
4526 switch (fb
->pixel_format
) {
4527 case DRM_FORMAT_RGB565
:
4528 case DRM_FORMAT_XBGR8888
:
4529 case DRM_FORMAT_XRGB8888
:
4530 case DRM_FORMAT_ABGR8888
:
4531 case DRM_FORMAT_ARGB8888
:
4532 case DRM_FORMAT_XRGB2101010
:
4533 case DRM_FORMAT_ARGB2101010
:
4534 case DRM_FORMAT_XBGR2101010
:
4535 case DRM_FORMAT_ABGR2101010
:
4536 case DRM_FORMAT_YUYV
:
4537 case DRM_FORMAT_YVYU
:
4538 case DRM_FORMAT_UYVY
:
4539 case DRM_FORMAT_VYUY
:
4542 DRM_DEBUG_KMS("PLANE:%d FB:%d unsupported scaling format 0x%x\n",
4543 intel_plane
->base
.base
.id
, fb
->base
.id
, fb
->pixel_format
);
4548 /* mark this plane as a scaler user in crtc_state */
4549 scaler_state
->scaler_users
|= (1 << idx
);
4550 DRM_DEBUG_KMS("%s:%d staged scaling request for %ux%u->%ux%u "
4551 "crtc_state = %p scaler_users = 0x%x\n",
4552 intel_plane
? "PLANE" : "CRTC",
4553 intel_plane
? intel_plane
->base
.base
.id
: intel_crtc
->base
.base
.id
,
4554 src_w
, src_h
, dst_w
, dst_h
, crtc_state
, scaler_state
->scaler_users
);
4558 static void skylake_pfit_update(struct intel_crtc
*crtc
, int enable
)
4560 struct drm_device
*dev
= crtc
->base
.dev
;
4561 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4562 int pipe
= crtc
->pipe
;
4563 struct intel_crtc_scaler_state
*scaler_state
=
4564 &crtc
->config
->scaler_state
;
4566 DRM_DEBUG_KMS("for crtc_state = %p\n", crtc
->config
);
4568 /* To update pfit, first update scaler state */
4569 skl_update_scaler_users(crtc
, crtc
->config
, NULL
, NULL
, !enable
);
4570 intel_atomic_setup_scalers(crtc
->base
.dev
, crtc
, crtc
->config
);
4571 skl_detach_scalers(crtc
);
4575 if (crtc
->config
->pch_pfit
.enabled
) {
4578 if (WARN_ON(crtc
->config
->scaler_state
.scaler_id
< 0)) {
4579 DRM_ERROR("Requesting pfit without getting a scaler first\n");
4583 id
= scaler_state
->scaler_id
;
4584 I915_WRITE(SKL_PS_CTRL(pipe
, id
), PS_SCALER_EN
|
4585 PS_FILTER_MEDIUM
| scaler_state
->scalers
[id
].mode
);
4586 I915_WRITE(SKL_PS_WIN_POS(pipe
, id
), crtc
->config
->pch_pfit
.pos
);
4587 I915_WRITE(SKL_PS_WIN_SZ(pipe
, id
), crtc
->config
->pch_pfit
.size
);
4589 DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc
->config
, id
);
4593 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
4595 struct drm_device
*dev
= crtc
->base
.dev
;
4596 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4597 int pipe
= crtc
->pipe
;
4599 if (crtc
->config
->pch_pfit
.enabled
) {
4600 /* Force use of hard-coded filter coefficients
4601 * as some pre-programmed values are broken,
4604 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
))
4605 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
4606 PF_PIPE_SEL_IVB(pipe
));
4608 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
4609 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
->pch_pfit
.pos
);
4610 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
->pch_pfit
.size
);
4614 static void intel_enable_sprite_planes(struct drm_crtc
*crtc
)
4616 struct drm_device
*dev
= crtc
->dev
;
4617 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
4618 struct drm_plane
*plane
;
4619 struct intel_plane
*intel_plane
;
4621 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
4622 intel_plane
= to_intel_plane(plane
);
4623 if (intel_plane
->pipe
== pipe
)
4624 intel_plane_restore(&intel_plane
->base
);
4628 void hsw_enable_ips(struct intel_crtc
*crtc
)
4630 struct drm_device
*dev
= crtc
->base
.dev
;
4631 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4633 if (!crtc
->config
->ips_enabled
)
4636 /* We can only enable IPS after we enable a plane and wait for a vblank */
4637 intel_wait_for_vblank(dev
, crtc
->pipe
);
4639 assert_plane_enabled(dev_priv
, crtc
->plane
);
4640 if (IS_BROADWELL(dev
)) {
4641 mutex_lock(&dev_priv
->rps
.hw_lock
);
4642 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
4643 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4644 /* Quoting Art Runyan: "its not safe to expect any particular
4645 * value in IPS_CTL bit 31 after enabling IPS through the
4646 * mailbox." Moreover, the mailbox may return a bogus state,
4647 * so we need to just enable it and continue on.
4650 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
4651 /* The bit only becomes 1 in the next vblank, so this wait here
4652 * is essentially intel_wait_for_vblank. If we don't have this
4653 * and don't wait for vblanks until the end of crtc_enable, then
4654 * the HW state readout code will complain that the expected
4655 * IPS_CTL value is not the one we read. */
4656 if (wait_for(I915_READ_NOTRACE(IPS_CTL
) & IPS_ENABLE
, 50))
4657 DRM_ERROR("Timed out waiting for IPS enable\n");
4661 void hsw_disable_ips(struct intel_crtc
*crtc
)
4663 struct drm_device
*dev
= crtc
->base
.dev
;
4664 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4666 if (!crtc
->config
->ips_enabled
)
4669 assert_plane_enabled(dev_priv
, crtc
->plane
);
4670 if (IS_BROADWELL(dev
)) {
4671 mutex_lock(&dev_priv
->rps
.hw_lock
);
4672 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
4673 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4674 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4675 if (wait_for((I915_READ(IPS_CTL
) & IPS_ENABLE
) == 0, 42))
4676 DRM_ERROR("Timed out waiting for IPS disable\n");
4678 I915_WRITE(IPS_CTL
, 0);
4679 POSTING_READ(IPS_CTL
);
4682 /* We need to wait for a vblank before we can disable the plane. */
4683 intel_wait_for_vblank(dev
, crtc
->pipe
);
4686 /** Loads the palette/gamma unit for the CRTC with the prepared values */
4687 static void intel_crtc_load_lut(struct drm_crtc
*crtc
)
4689 struct drm_device
*dev
= crtc
->dev
;
4690 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4691 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4692 enum pipe pipe
= intel_crtc
->pipe
;
4693 int palreg
= PALETTE(pipe
);
4695 bool reenable_ips
= false;
4697 /* The clocks have to be on to load the palette. */
4698 if (!crtc
->state
->enable
|| !intel_crtc
->active
)
4701 if (HAS_GMCH_DISPLAY(dev_priv
->dev
)) {
4702 if (intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_DSI
))
4703 assert_dsi_pll_enabled(dev_priv
);
4705 assert_pll_enabled(dev_priv
, pipe
);
4708 /* use legacy palette for Ironlake */
4709 if (!HAS_GMCH_DISPLAY(dev
))
4710 palreg
= LGC_PALETTE(pipe
);
4712 /* Workaround : Do not read or write the pipe palette/gamma data while
4713 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
4715 if (IS_HASWELL(dev
) && intel_crtc
->config
->ips_enabled
&&
4716 ((I915_READ(GAMMA_MODE(pipe
)) & GAMMA_MODE_MODE_MASK
) ==
4717 GAMMA_MODE_MODE_SPLIT
)) {
4718 hsw_disable_ips(intel_crtc
);
4719 reenable_ips
= true;
4722 for (i
= 0; i
< 256; i
++) {
4723 I915_WRITE(palreg
+ 4 * i
,
4724 (intel_crtc
->lut_r
[i
] << 16) |
4725 (intel_crtc
->lut_g
[i
] << 8) |
4726 intel_crtc
->lut_b
[i
]);
4730 hsw_enable_ips(intel_crtc
);
4733 static void intel_crtc_dpms_overlay_disable(struct intel_crtc
*intel_crtc
)
4735 if (intel_crtc
->overlay
) {
4736 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4737 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4739 mutex_lock(&dev
->struct_mutex
);
4740 dev_priv
->mm
.interruptible
= false;
4741 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
4742 dev_priv
->mm
.interruptible
= true;
4743 mutex_unlock(&dev
->struct_mutex
);
4746 /* Let userspace switch the overlay on again. In most cases userspace
4747 * has to recompute where to put it anyway.
4752 * intel_post_enable_primary - Perform operations after enabling primary plane
4753 * @crtc: the CRTC whose primary plane was just enabled
4755 * Performs potentially sleeping operations that must be done after the primary
4756 * plane is enabled, such as updating FBC and IPS. Note that this may be
4757 * called due to an explicit primary plane update, or due to an implicit
4758 * re-enable that is caused when a sprite plane is updated to no longer
4759 * completely hide the primary plane.
4762 intel_post_enable_primary(struct drm_crtc
*crtc
)
4764 struct drm_device
*dev
= crtc
->dev
;
4765 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4766 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4767 int pipe
= intel_crtc
->pipe
;
4770 * BDW signals flip done immediately if the plane
4771 * is disabled, even if the plane enable is already
4772 * armed to occur at the next vblank :(
4774 if (IS_BROADWELL(dev
))
4775 intel_wait_for_vblank(dev
, pipe
);
4778 * FIXME IPS should be fine as long as one plane is
4779 * enabled, but in practice it seems to have problems
4780 * when going from primary only to sprite only and vice
4783 hsw_enable_ips(intel_crtc
);
4785 mutex_lock(&dev
->struct_mutex
);
4786 intel_fbc_update(dev
);
4787 mutex_unlock(&dev
->struct_mutex
);
4790 * Gen2 reports pipe underruns whenever all planes are disabled.
4791 * So don't enable underrun reporting before at least some planes
4793 * FIXME: Need to fix the logic to work when we turn off all planes
4794 * but leave the pipe running.
4797 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4799 /* Underruns don't raise interrupts, so check manually. */
4800 if (HAS_GMCH_DISPLAY(dev
))
4801 i9xx_check_fifo_underruns(dev_priv
);
4805 * intel_pre_disable_primary - Perform operations before disabling primary plane
4806 * @crtc: the CRTC whose primary plane is to be disabled
4808 * Performs potentially sleeping operations that must be done before the
4809 * primary plane is disabled, such as updating FBC and IPS. Note that this may
4810 * be called due to an explicit primary plane update, or due to an implicit
4811 * disable that is caused when a sprite plane completely hides the primary
4815 intel_pre_disable_primary(struct drm_crtc
*crtc
)
4817 struct drm_device
*dev
= crtc
->dev
;
4818 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4819 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4820 int pipe
= intel_crtc
->pipe
;
4823 * Gen2 reports pipe underruns whenever all planes are disabled.
4824 * So diasble underrun reporting before all the planes get disabled.
4825 * FIXME: Need to fix the logic to work when we turn off all planes
4826 * but leave the pipe running.
4829 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4832 * Vblank time updates from the shadow to live plane control register
4833 * are blocked if the memory self-refresh mode is active at that
4834 * moment. So to make sure the plane gets truly disabled, disable
4835 * first the self-refresh mode. The self-refresh enable bit in turn
4836 * will be checked/applied by the HW only at the next frame start
4837 * event which is after the vblank start event, so we need to have a
4838 * wait-for-vblank between disabling the plane and the pipe.
4840 if (HAS_GMCH_DISPLAY(dev
))
4841 intel_set_memory_cxsr(dev_priv
, false);
4843 mutex_lock(&dev
->struct_mutex
);
4844 if (dev_priv
->fbc
.crtc
== intel_crtc
)
4845 intel_fbc_disable(dev
);
4846 mutex_unlock(&dev
->struct_mutex
);
4849 * FIXME IPS should be fine as long as one plane is
4850 * enabled, but in practice it seems to have problems
4851 * when going from primary only to sprite only and vice
4854 hsw_disable_ips(intel_crtc
);
4857 static void intel_crtc_enable_planes(struct drm_crtc
*crtc
)
4859 intel_enable_primary_hw_plane(crtc
->primary
, crtc
);
4860 intel_enable_sprite_planes(crtc
);
4861 intel_crtc_update_cursor(crtc
, true);
4863 intel_post_enable_primary(crtc
);
4866 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
)
4868 struct drm_device
*dev
= crtc
->dev
;
4869 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4870 struct intel_plane
*intel_plane
;
4871 int pipe
= intel_crtc
->pipe
;
4873 intel_crtc_wait_for_pending_flips(crtc
);
4875 intel_pre_disable_primary(crtc
);
4877 intel_crtc_dpms_overlay_disable(intel_crtc
);
4878 for_each_intel_plane(dev
, intel_plane
) {
4879 if (intel_plane
->pipe
== pipe
) {
4880 struct drm_crtc
*from
= intel_plane
->base
.crtc
;
4882 intel_plane
->disable_plane(&intel_plane
->base
,
4883 from
?: crtc
, true);
4888 * FIXME: Once we grow proper nuclear flip support out of this we need
4889 * to compute the mask of flip planes precisely. For the time being
4890 * consider this a flip to a NULL plane.
4892 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_ALL_MASK(pipe
));
4895 static void ironlake_crtc_enable(struct drm_crtc
*crtc
)
4897 struct drm_device
*dev
= crtc
->dev
;
4898 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4899 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4900 struct intel_encoder
*encoder
;
4901 int pipe
= intel_crtc
->pipe
;
4903 WARN_ON(!crtc
->state
->enable
);
4905 if (intel_crtc
->active
)
4908 if (intel_crtc
->config
->has_pch_encoder
)
4909 intel_prepare_shared_dpll(intel_crtc
);
4911 if (intel_crtc
->config
->has_dp_encoder
)
4912 intel_dp_set_m_n(intel_crtc
, M1_N1
);
4914 intel_set_pipe_timings(intel_crtc
);
4916 if (intel_crtc
->config
->has_pch_encoder
) {
4917 intel_cpu_transcoder_set_m_n(intel_crtc
,
4918 &intel_crtc
->config
->fdi_m_n
, NULL
);
4921 ironlake_set_pipeconf(crtc
);
4923 intel_crtc
->active
= true;
4925 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4926 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
4928 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4929 if (encoder
->pre_enable
)
4930 encoder
->pre_enable(encoder
);
4932 if (intel_crtc
->config
->has_pch_encoder
) {
4933 /* Note: FDI PLL enabling _must_ be done before we enable the
4934 * cpu pipes, hence this is separate from all the other fdi/pch
4936 ironlake_fdi_pll_enable(intel_crtc
);
4938 assert_fdi_tx_disabled(dev_priv
, pipe
);
4939 assert_fdi_rx_disabled(dev_priv
, pipe
);
4942 ironlake_pfit_enable(intel_crtc
);
4945 * On ILK+ LUT must be loaded before the pipe is running but with
4948 intel_crtc_load_lut(crtc
);
4950 intel_update_watermarks(crtc
);
4951 intel_enable_pipe(intel_crtc
);
4953 if (intel_crtc
->config
->has_pch_encoder
)
4954 ironlake_pch_enable(crtc
);
4956 assert_vblank_disabled(crtc
);
4957 drm_crtc_vblank_on(crtc
);
4959 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4960 encoder
->enable(encoder
);
4962 if (HAS_PCH_CPT(dev
))
4963 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
4966 /* IPS only exists on ULT machines and is tied to pipe A. */
4967 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
4969 return HAS_IPS(crtc
->base
.dev
) && crtc
->pipe
== PIPE_A
;
4973 * This implements the workaround described in the "notes" section of the mode
4974 * set sequence documentation. When going from no pipes or single pipe to
4975 * multiple pipes, and planes are enabled after the pipe, we need to wait at
4976 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
4978 static void haswell_mode_set_planes_workaround(struct intel_crtc
*crtc
)
4980 struct drm_device
*dev
= crtc
->base
.dev
;
4981 struct intel_crtc
*crtc_it
, *other_active_crtc
= NULL
;
4983 /* We want to get the other_active_crtc only if there's only 1 other
4985 for_each_intel_crtc(dev
, crtc_it
) {
4986 if (!crtc_it
->active
|| crtc_it
== crtc
)
4989 if (other_active_crtc
)
4992 other_active_crtc
= crtc_it
;
4994 if (!other_active_crtc
)
4997 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4998 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
5001 static void haswell_crtc_enable(struct drm_crtc
*crtc
)
5003 struct drm_device
*dev
= crtc
->dev
;
5004 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5005 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5006 struct intel_encoder
*encoder
;
5007 int pipe
= intel_crtc
->pipe
;
5009 WARN_ON(!crtc
->state
->enable
);
5011 if (intel_crtc
->active
)
5014 if (intel_crtc_to_shared_dpll(intel_crtc
))
5015 intel_enable_shared_dpll(intel_crtc
);
5017 if (intel_crtc
->config
->has_dp_encoder
)
5018 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5020 intel_set_pipe_timings(intel_crtc
);
5022 if (intel_crtc
->config
->cpu_transcoder
!= TRANSCODER_EDP
) {
5023 I915_WRITE(PIPE_MULT(intel_crtc
->config
->cpu_transcoder
),
5024 intel_crtc
->config
->pixel_multiplier
- 1);
5027 if (intel_crtc
->config
->has_pch_encoder
) {
5028 intel_cpu_transcoder_set_m_n(intel_crtc
,
5029 &intel_crtc
->config
->fdi_m_n
, NULL
);
5032 haswell_set_pipeconf(crtc
);
5034 intel_set_pipe_csc(crtc
);
5036 intel_crtc
->active
= true;
5038 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5039 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5040 if (encoder
->pre_enable
)
5041 encoder
->pre_enable(encoder
);
5043 if (intel_crtc
->config
->has_pch_encoder
) {
5044 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5046 dev_priv
->display
.fdi_link_train(crtc
);
5049 intel_ddi_enable_pipe_clock(intel_crtc
);
5051 if (INTEL_INFO(dev
)->gen
== 9)
5052 skylake_pfit_update(intel_crtc
, 1);
5053 else if (INTEL_INFO(dev
)->gen
< 9)
5054 ironlake_pfit_enable(intel_crtc
);
5056 MISSING_CASE(INTEL_INFO(dev
)->gen
);
5059 * On ILK+ LUT must be loaded before the pipe is running but with
5062 intel_crtc_load_lut(crtc
);
5064 intel_ddi_set_pipe_settings(crtc
);
5065 intel_ddi_enable_transcoder_func(crtc
);
5067 intel_update_watermarks(crtc
);
5068 intel_enable_pipe(intel_crtc
);
5070 if (intel_crtc
->config
->has_pch_encoder
)
5071 lpt_pch_enable(crtc
);
5073 if (intel_crtc
->config
->dp_encoder_is_mst
)
5074 intel_ddi_set_vc_payload_alloc(crtc
, true);
5076 assert_vblank_disabled(crtc
);
5077 drm_crtc_vblank_on(crtc
);
5079 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5080 encoder
->enable(encoder
);
5081 intel_opregion_notify_encoder(encoder
, true);
5084 /* If we change the relative order between pipe/planes enabling, we need
5085 * to change the workaround. */
5086 haswell_mode_set_planes_workaround(intel_crtc
);
5089 static void ironlake_pfit_disable(struct intel_crtc
*crtc
)
5091 struct drm_device
*dev
= crtc
->base
.dev
;
5092 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5093 int pipe
= crtc
->pipe
;
5095 /* To avoid upsetting the power well on haswell only disable the pfit if
5096 * it's in use. The hw state code will make sure we get this right. */
5097 if (crtc
->config
->pch_pfit
.enabled
) {
5098 I915_WRITE(PF_CTL(pipe
), 0);
5099 I915_WRITE(PF_WIN_POS(pipe
), 0);
5100 I915_WRITE(PF_WIN_SZ(pipe
), 0);
5104 static void ironlake_crtc_disable(struct drm_crtc
*crtc
)
5106 struct drm_device
*dev
= crtc
->dev
;
5107 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5108 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5109 struct intel_encoder
*encoder
;
5110 int pipe
= intel_crtc
->pipe
;
5113 if (!intel_crtc
->active
)
5116 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5117 encoder
->disable(encoder
);
5119 drm_crtc_vblank_off(crtc
);
5120 assert_vblank_disabled(crtc
);
5122 if (intel_crtc
->config
->has_pch_encoder
)
5123 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
5125 intel_disable_pipe(intel_crtc
);
5127 ironlake_pfit_disable(intel_crtc
);
5129 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5130 if (encoder
->post_disable
)
5131 encoder
->post_disable(encoder
);
5133 if (intel_crtc
->config
->has_pch_encoder
) {
5134 ironlake_fdi_disable(crtc
);
5136 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
5138 if (HAS_PCH_CPT(dev
)) {
5139 /* disable TRANS_DP_CTL */
5140 reg
= TRANS_DP_CTL(pipe
);
5141 temp
= I915_READ(reg
);
5142 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
5143 TRANS_DP_PORT_SEL_MASK
);
5144 temp
|= TRANS_DP_PORT_SEL_NONE
;
5145 I915_WRITE(reg
, temp
);
5147 /* disable DPLL_SEL */
5148 temp
= I915_READ(PCH_DPLL_SEL
);
5149 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
5150 I915_WRITE(PCH_DPLL_SEL
, temp
);
5153 /* disable PCH DPLL */
5154 intel_disable_shared_dpll(intel_crtc
);
5156 ironlake_fdi_pll_disable(intel_crtc
);
5159 intel_crtc
->active
= false;
5160 intel_update_watermarks(crtc
);
5162 mutex_lock(&dev
->struct_mutex
);
5163 intel_fbc_update(dev
);
5164 mutex_unlock(&dev
->struct_mutex
);
5167 static void haswell_crtc_disable(struct drm_crtc
*crtc
)
5169 struct drm_device
*dev
= crtc
->dev
;
5170 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5171 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5172 struct intel_encoder
*encoder
;
5173 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5175 if (!intel_crtc
->active
)
5178 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5179 intel_opregion_notify_encoder(encoder
, false);
5180 encoder
->disable(encoder
);
5183 drm_crtc_vblank_off(crtc
);
5184 assert_vblank_disabled(crtc
);
5186 if (intel_crtc
->config
->has_pch_encoder
)
5187 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5189 intel_disable_pipe(intel_crtc
);
5191 if (intel_crtc
->config
->dp_encoder_is_mst
)
5192 intel_ddi_set_vc_payload_alloc(crtc
, false);
5194 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
5196 if (INTEL_INFO(dev
)->gen
== 9)
5197 skylake_pfit_update(intel_crtc
, 0);
5198 else if (INTEL_INFO(dev
)->gen
< 9)
5199 ironlake_pfit_disable(intel_crtc
);
5201 MISSING_CASE(INTEL_INFO(dev
)->gen
);
5203 intel_ddi_disable_pipe_clock(intel_crtc
);
5205 if (intel_crtc
->config
->has_pch_encoder
) {
5206 lpt_disable_pch_transcoder(dev_priv
);
5207 intel_ddi_fdi_disable(crtc
);
5210 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5211 if (encoder
->post_disable
)
5212 encoder
->post_disable(encoder
);
5214 intel_crtc
->active
= false;
5215 intel_update_watermarks(crtc
);
5217 mutex_lock(&dev
->struct_mutex
);
5218 intel_fbc_update(dev
);
5219 mutex_unlock(&dev
->struct_mutex
);
5221 if (intel_crtc_to_shared_dpll(intel_crtc
))
5222 intel_disable_shared_dpll(intel_crtc
);
5225 static void ironlake_crtc_off(struct drm_crtc
*crtc
)
5227 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5228 intel_put_shared_dpll(intel_crtc
);
5232 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
5234 struct drm_device
*dev
= crtc
->base
.dev
;
5235 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5236 struct intel_crtc_state
*pipe_config
= crtc
->config
;
5238 if (!pipe_config
->gmch_pfit
.control
)
5242 * The panel fitter should only be adjusted whilst the pipe is disabled,
5243 * according to register description and PRM.
5245 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
5246 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5248 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
5249 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
5251 /* Border color in case we don't scale up to the full screen. Black by
5252 * default, change to something else for debugging. */
5253 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
5256 static enum intel_display_power_domain
port_to_power_domain(enum port port
)
5260 return POWER_DOMAIN_PORT_DDI_A_4_LANES
;
5262 return POWER_DOMAIN_PORT_DDI_B_4_LANES
;
5264 return POWER_DOMAIN_PORT_DDI_C_4_LANES
;
5266 return POWER_DOMAIN_PORT_DDI_D_4_LANES
;
5269 return POWER_DOMAIN_PORT_OTHER
;
5273 #define for_each_power_domain(domain, mask) \
5274 for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
5275 if ((1 << (domain)) & (mask))
5277 enum intel_display_power_domain
5278 intel_display_port_power_domain(struct intel_encoder
*intel_encoder
)
5280 struct drm_device
*dev
= intel_encoder
->base
.dev
;
5281 struct intel_digital_port
*intel_dig_port
;
5283 switch (intel_encoder
->type
) {
5284 case INTEL_OUTPUT_UNKNOWN
:
5285 /* Only DDI platforms should ever use this output type */
5286 WARN_ON_ONCE(!HAS_DDI(dev
));
5287 case INTEL_OUTPUT_DISPLAYPORT
:
5288 case INTEL_OUTPUT_HDMI
:
5289 case INTEL_OUTPUT_EDP
:
5290 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
5291 return port_to_power_domain(intel_dig_port
->port
);
5292 case INTEL_OUTPUT_DP_MST
:
5293 intel_dig_port
= enc_to_mst(&intel_encoder
->base
)->primary
;
5294 return port_to_power_domain(intel_dig_port
->port
);
5295 case INTEL_OUTPUT_ANALOG
:
5296 return POWER_DOMAIN_PORT_CRT
;
5297 case INTEL_OUTPUT_DSI
:
5298 return POWER_DOMAIN_PORT_DSI
;
5300 return POWER_DOMAIN_PORT_OTHER
;
5304 static unsigned long get_crtc_power_domains(struct drm_crtc
*crtc
)
5306 struct drm_device
*dev
= crtc
->dev
;
5307 struct intel_encoder
*intel_encoder
;
5308 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5309 enum pipe pipe
= intel_crtc
->pipe
;
5311 enum transcoder transcoder
;
5313 transcoder
= intel_pipe_to_cpu_transcoder(dev
->dev_private
, pipe
);
5315 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
5316 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
5317 if (intel_crtc
->config
->pch_pfit
.enabled
||
5318 intel_crtc
->config
->pch_pfit
.force_thru
)
5319 mask
|= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
5321 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
5322 mask
|= BIT(intel_display_port_power_domain(intel_encoder
));
5327 static void modeset_update_crtc_power_domains(struct drm_atomic_state
*state
)
5329 struct drm_device
*dev
= state
->dev
;
5330 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5331 unsigned long pipe_domains
[I915_MAX_PIPES
] = { 0, };
5332 struct intel_crtc
*crtc
;
5335 * First get all needed power domains, then put all unneeded, to avoid
5336 * any unnecessary toggling of the power wells.
5338 for_each_intel_crtc(dev
, crtc
) {
5339 enum intel_display_power_domain domain
;
5341 if (!crtc
->base
.state
->enable
)
5344 pipe_domains
[crtc
->pipe
] = get_crtc_power_domains(&crtc
->base
);
5346 for_each_power_domain(domain
, pipe_domains
[crtc
->pipe
])
5347 intel_display_power_get(dev_priv
, domain
);
5350 if (dev_priv
->display
.modeset_global_resources
)
5351 dev_priv
->display
.modeset_global_resources(state
);
5353 for_each_intel_crtc(dev
, crtc
) {
5354 enum intel_display_power_domain domain
;
5356 for_each_power_domain(domain
, crtc
->enabled_power_domains
)
5357 intel_display_power_put(dev_priv
, domain
);
5359 crtc
->enabled_power_domains
= pipe_domains
[crtc
->pipe
];
5362 intel_display_set_init_power(dev_priv
, false);
5365 void broxton_set_cdclk(struct drm_device
*dev
, int frequency
)
5367 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5370 uint32_t current_freq
;
5373 /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */
5374 switch (frequency
) {
5376 divider
= BXT_CDCLK_CD2X_DIV_SEL_4
;
5377 ratio
= BXT_DE_PLL_RATIO(60);
5380 divider
= BXT_CDCLK_CD2X_DIV_SEL_2
;
5381 ratio
= BXT_DE_PLL_RATIO(60);
5384 divider
= BXT_CDCLK_CD2X_DIV_SEL_1_5
;
5385 ratio
= BXT_DE_PLL_RATIO(60);
5388 divider
= BXT_CDCLK_CD2X_DIV_SEL_1
;
5389 ratio
= BXT_DE_PLL_RATIO(60);
5392 divider
= BXT_CDCLK_CD2X_DIV_SEL_1
;
5393 ratio
= BXT_DE_PLL_RATIO(65);
5397 * Bypass frequency with DE PLL disabled. Init ratio, divider
5398 * to suppress GCC warning.
5404 DRM_ERROR("unsupported CDCLK freq %d", frequency
);
5409 mutex_lock(&dev_priv
->rps
.hw_lock
);
5410 /* Inform power controller of upcoming frequency change */
5411 ret
= sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
,
5413 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5416 DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n",
5421 current_freq
= I915_READ(CDCLK_CTL
) & CDCLK_FREQ_DECIMAL_MASK
;
5422 /* convert from .1 fixpoint MHz with -1MHz offset to kHz */
5423 current_freq
= current_freq
* 500 + 1000;
5426 * DE PLL has to be disabled when
5427 * - setting to 19.2MHz (bypass, PLL isn't used)
5428 * - before setting to 624MHz (PLL needs toggling)
5429 * - before setting to any frequency from 624MHz (PLL needs toggling)
5431 if (frequency
== 19200 || frequency
== 624000 ||
5432 current_freq
== 624000) {
5433 I915_WRITE(BXT_DE_PLL_ENABLE
, ~BXT_DE_PLL_PLL_ENABLE
);
5435 if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_LOCK
),
5437 DRM_ERROR("timout waiting for DE PLL unlock\n");
5440 if (frequency
!= 19200) {
5443 val
= I915_READ(BXT_DE_PLL_CTL
);
5444 val
&= ~BXT_DE_PLL_RATIO_MASK
;
5446 I915_WRITE(BXT_DE_PLL_CTL
, val
);
5448 I915_WRITE(BXT_DE_PLL_ENABLE
, BXT_DE_PLL_PLL_ENABLE
);
5450 if (wait_for(I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_LOCK
, 1))
5451 DRM_ERROR("timeout waiting for DE PLL lock\n");
5453 val
= I915_READ(CDCLK_CTL
);
5454 val
&= ~BXT_CDCLK_CD2X_DIV_SEL_MASK
;
5457 * Disable SSA Precharge when CD clock frequency < 500 MHz,
5460 val
&= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE
;
5461 if (frequency
>= 500000)
5462 val
|= BXT_CDCLK_SSA_PRECHARGE_ENABLE
;
5464 val
&= ~CDCLK_FREQ_DECIMAL_MASK
;
5465 /* convert from kHz to .1 fixpoint MHz with -1MHz offset */
5466 val
|= (frequency
- 1000) / 500;
5467 I915_WRITE(CDCLK_CTL
, val
);
5470 mutex_lock(&dev_priv
->rps
.hw_lock
);
5471 ret
= sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
,
5472 DIV_ROUND_UP(frequency
, 25000));
5473 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5476 DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n",
5481 dev_priv
->cdclk_freq
= frequency
;
5484 void broxton_init_cdclk(struct drm_device
*dev
)
5486 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5490 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
5491 * or else the reset will hang because there is no PCH to respond.
5492 * Move the handshake programming to initialization sequence.
5493 * Previously was left up to BIOS.
5495 val
= I915_READ(HSW_NDE_RSTWRN_OPT
);
5496 val
&= ~RESET_PCH_HANDSHAKE_ENABLE
;
5497 I915_WRITE(HSW_NDE_RSTWRN_OPT
, val
);
5499 /* Enable PG1 for cdclk */
5500 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
5502 /* check if cd clock is enabled */
5503 if (I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_PLL_ENABLE
) {
5504 DRM_DEBUG_KMS("Display already initialized\n");
5510 * - The initial CDCLK needs to be read from VBT.
5511 * Need to make this change after VBT has changes for BXT.
5512 * - check if setting the max (or any) cdclk freq is really necessary
5513 * here, it belongs to modeset time
5515 broxton_set_cdclk(dev
, 624000);
5517 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) | DBUF_POWER_REQUEST
);
5518 POSTING_READ(DBUF_CTL
);
5522 if (!(I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
))
5523 DRM_ERROR("DBuf power enable timeout!\n");
5526 void broxton_uninit_cdclk(struct drm_device
*dev
)
5528 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5530 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) & ~DBUF_POWER_REQUEST
);
5531 POSTING_READ(DBUF_CTL
);
5535 if (I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
)
5536 DRM_ERROR("DBuf power disable timeout!\n");
5538 /* Set minimum (bypass) frequency, in effect turning off the DE PLL */
5539 broxton_set_cdclk(dev
, 19200);
5541 intel_display_power_put(dev_priv
, POWER_DOMAIN_PLLS
);
5544 /* returns HPLL frequency in kHz */
5545 static int valleyview_get_vco(struct drm_i915_private
*dev_priv
)
5547 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
5549 /* Obtain SKU information */
5550 mutex_lock(&dev_priv
->dpio_lock
);
5551 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
5552 CCK_FUSE_HPLL_FREQ_MASK
;
5553 mutex_unlock(&dev_priv
->dpio_lock
);
5555 return vco_freq
[hpll_freq
] * 1000;
5558 static void vlv_update_cdclk(struct drm_device
*dev
)
5560 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5562 dev_priv
->cdclk_freq
= dev_priv
->display
.get_display_clock_speed(dev
);
5563 DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n",
5564 dev_priv
->cdclk_freq
);
5567 * Program the gmbus_freq based on the cdclk frequency.
5568 * BSpec erroneously claims we should aim for 4MHz, but
5569 * in fact 1MHz is the correct frequency.
5571 I915_WRITE(GMBUSFREQ_VLV
, DIV_ROUND_UP(dev_priv
->cdclk_freq
, 1000));
5574 /* Adjust CDclk dividers to allow high res or save power if possible */
5575 static void valleyview_set_cdclk(struct drm_device
*dev
, int cdclk
)
5577 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5580 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
)
5581 != dev_priv
->cdclk_freq
);
5583 if (cdclk
>= 320000) /* jump to highest voltage for 400MHz too */
5585 else if (cdclk
== 266667)
5590 mutex_lock(&dev_priv
->rps
.hw_lock
);
5591 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
5592 val
&= ~DSPFREQGUAR_MASK
;
5593 val
|= (cmd
<< DSPFREQGUAR_SHIFT
);
5594 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
5595 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
5596 DSPFREQSTAT_MASK
) == (cmd
<< DSPFREQSTAT_SHIFT
),
5598 DRM_ERROR("timed out waiting for CDclk change\n");
5600 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5602 if (cdclk
== 400000) {
5605 divider
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
5607 mutex_lock(&dev_priv
->dpio_lock
);
5608 /* adjust cdclk divider */
5609 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
5610 val
&= ~DISPLAY_FREQUENCY_VALUES
;
5612 vlv_cck_write(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
, val
);
5614 if (wait_for((vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
) &
5615 DISPLAY_FREQUENCY_STATUS
) == (divider
<< DISPLAY_FREQUENCY_STATUS_SHIFT
),
5617 DRM_ERROR("timed out waiting for CDclk change\n");
5618 mutex_unlock(&dev_priv
->dpio_lock
);
5621 mutex_lock(&dev_priv
->dpio_lock
);
5622 /* adjust self-refresh exit latency value */
5623 val
= vlv_bunit_read(dev_priv
, BUNIT_REG_BISOC
);
5627 * For high bandwidth configs, we set a higher latency in the bunit
5628 * so that the core display fetch happens in time to avoid underruns.
5630 if (cdclk
== 400000)
5631 val
|= 4500 / 250; /* 4.5 usec */
5633 val
|= 3000 / 250; /* 3.0 usec */
5634 vlv_bunit_write(dev_priv
, BUNIT_REG_BISOC
, val
);
5635 mutex_unlock(&dev_priv
->dpio_lock
);
5637 vlv_update_cdclk(dev
);
5640 static void cherryview_set_cdclk(struct drm_device
*dev
, int cdclk
)
5642 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5645 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
)
5646 != dev_priv
->cdclk_freq
);
5655 MISSING_CASE(cdclk
);
5660 * Specs are full of misinformation, but testing on actual
5661 * hardware has shown that we just need to write the desired
5662 * CCK divider into the Punit register.
5664 cmd
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
5666 mutex_lock(&dev_priv
->rps
.hw_lock
);
5667 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
5668 val
&= ~DSPFREQGUAR_MASK_CHV
;
5669 val
|= (cmd
<< DSPFREQGUAR_SHIFT_CHV
);
5670 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
5671 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
5672 DSPFREQSTAT_MASK_CHV
) == (cmd
<< DSPFREQSTAT_SHIFT_CHV
),
5674 DRM_ERROR("timed out waiting for CDclk change\n");
5676 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5678 vlv_update_cdclk(dev
);
5681 static int valleyview_calc_cdclk(struct drm_i915_private
*dev_priv
,
5684 int freq_320
= (dev_priv
->hpll_freq
<< 1) % 320000 != 0 ? 333333 : 320000;
5685 int limit
= IS_CHERRYVIEW(dev_priv
) ? 95 : 90;
5688 * Really only a few cases to deal with, as only 4 CDclks are supported:
5691 * 320/333MHz (depends on HPLL freq)
5693 * So we check to see whether we're above 90% (VLV) or 95% (CHV)
5694 * of the lower bin and adjust if needed.
5696 * We seem to get an unstable or solid color picture at 200MHz.
5697 * Not sure what's wrong. For now use 200MHz only when all pipes
5700 if (!IS_CHERRYVIEW(dev_priv
) &&
5701 max_pixclk
> freq_320
*limit
/100)
5703 else if (max_pixclk
> 266667*limit
/100)
5705 else if (max_pixclk
> 0)
5711 static int broxton_calc_cdclk(struct drm_i915_private
*dev_priv
,
5716 * - remove the guardband, it's not needed on BXT
5717 * - set 19.2MHz bypass frequency if there are no active pipes
5719 if (max_pixclk
> 576000*9/10)
5721 else if (max_pixclk
> 384000*9/10)
5723 else if (max_pixclk
> 288000*9/10)
5725 else if (max_pixclk
> 144000*9/10)
5731 /* compute the max pixel clock for new configuration */
5732 static int intel_mode_max_pixclk(struct drm_atomic_state
*state
)
5734 struct drm_device
*dev
= state
->dev
;
5735 struct intel_crtc
*intel_crtc
;
5736 struct intel_crtc_state
*crtc_state
;
5739 for_each_intel_crtc(dev
, intel_crtc
) {
5740 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
5741 if (IS_ERR(crtc_state
))
5742 return PTR_ERR(crtc_state
);
5744 if (!crtc_state
->base
.enable
)
5747 max_pixclk
= max(max_pixclk
,
5748 crtc_state
->base
.adjusted_mode
.crtc_clock
);
5754 static int valleyview_modeset_global_pipes(struct drm_atomic_state
*state
)
5756 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
5757 struct drm_crtc
*crtc
;
5758 struct drm_crtc_state
*crtc_state
;
5759 int max_pixclk
= intel_mode_max_pixclk(state
);
5765 if (IS_VALLEYVIEW(dev_priv
))
5766 cdclk
= valleyview_calc_cdclk(dev_priv
, max_pixclk
);
5768 cdclk
= broxton_calc_cdclk(dev_priv
, max_pixclk
);
5770 if (cdclk
== dev_priv
->cdclk_freq
)
5773 /* add all active pipes to the state */
5774 for_each_crtc(state
->dev
, crtc
) {
5775 if (!crtc
->state
->enable
)
5778 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
5779 if (IS_ERR(crtc_state
))
5780 return PTR_ERR(crtc_state
);
5783 /* disable/enable all currently active pipes while we change cdclk */
5784 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
)
5785 if (crtc_state
->enable
)
5786 crtc_state
->mode_changed
= true;
5791 static void vlv_program_pfi_credits(struct drm_i915_private
*dev_priv
)
5793 unsigned int credits
, default_credits
;
5795 if (IS_CHERRYVIEW(dev_priv
))
5796 default_credits
= PFI_CREDIT(12);
5798 default_credits
= PFI_CREDIT(8);
5800 if (DIV_ROUND_CLOSEST(dev_priv
->cdclk_freq
, 1000) >= dev_priv
->rps
.cz_freq
) {
5801 /* CHV suggested value is 31 or 63 */
5802 if (IS_CHERRYVIEW(dev_priv
))
5803 credits
= PFI_CREDIT_31
;
5805 credits
= PFI_CREDIT(15);
5807 credits
= default_credits
;
5811 * WA - write default credits before re-programming
5812 * FIXME: should we also set the resend bit here?
5814 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
5817 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
5818 credits
| PFI_CREDIT_RESEND
);
5821 * FIXME is this guaranteed to clear
5822 * immediately or should we poll for it?
5824 WARN_ON(I915_READ(GCI_CONTROL
) & PFI_CREDIT_RESEND
);
5827 static void valleyview_modeset_global_resources(struct drm_atomic_state
*state
)
5829 struct drm_device
*dev
= state
->dev
;
5830 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5831 int max_pixclk
= intel_mode_max_pixclk(state
);
5834 /* The only reason this can fail is if we fail to add the crtc_state
5835 * to the atomic state. But that can't happen since the call to
5836 * intel_mode_max_pixclk() in valleyview_modeset_global_pipes() (which
5837 * can't have failed otherwise the mode set would be aborted) added all
5838 * the states already. */
5839 if (WARN_ON(max_pixclk
< 0))
5842 req_cdclk
= valleyview_calc_cdclk(dev_priv
, max_pixclk
);
5844 if (req_cdclk
!= dev_priv
->cdclk_freq
) {
5846 * FIXME: We can end up here with all power domains off, yet
5847 * with a CDCLK frequency other than the minimum. To account
5848 * for this take the PIPE-A power domain, which covers the HW
5849 * blocks needed for the following programming. This can be
5850 * removed once it's guaranteed that we get here either with
5851 * the minimum CDCLK set, or the required power domains
5854 intel_display_power_get(dev_priv
, POWER_DOMAIN_PIPE_A
);
5856 if (IS_CHERRYVIEW(dev
))
5857 cherryview_set_cdclk(dev
, req_cdclk
);
5859 valleyview_set_cdclk(dev
, req_cdclk
);
5861 vlv_program_pfi_credits(dev_priv
);
5863 intel_display_power_put(dev_priv
, POWER_DOMAIN_PIPE_A
);
5867 static void valleyview_crtc_enable(struct drm_crtc
*crtc
)
5869 struct drm_device
*dev
= crtc
->dev
;
5870 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5871 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5872 struct intel_encoder
*encoder
;
5873 int pipe
= intel_crtc
->pipe
;
5876 WARN_ON(!crtc
->state
->enable
);
5878 if (intel_crtc
->active
)
5881 is_dsi
= intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_DSI
);
5884 if (IS_CHERRYVIEW(dev
))
5885 chv_prepare_pll(intel_crtc
, intel_crtc
->config
);
5887 vlv_prepare_pll(intel_crtc
, intel_crtc
->config
);
5890 if (intel_crtc
->config
->has_dp_encoder
)
5891 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5893 intel_set_pipe_timings(intel_crtc
);
5895 if (IS_CHERRYVIEW(dev
) && pipe
== PIPE_B
) {
5896 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5898 I915_WRITE(CHV_BLEND(pipe
), CHV_BLEND_LEGACY
);
5899 I915_WRITE(CHV_CANVAS(pipe
), 0);
5902 i9xx_set_pipeconf(intel_crtc
);
5904 intel_crtc
->active
= true;
5906 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5908 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5909 if (encoder
->pre_pll_enable
)
5910 encoder
->pre_pll_enable(encoder
);
5913 if (IS_CHERRYVIEW(dev
))
5914 chv_enable_pll(intel_crtc
, intel_crtc
->config
);
5916 vlv_enable_pll(intel_crtc
, intel_crtc
->config
);
5919 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5920 if (encoder
->pre_enable
)
5921 encoder
->pre_enable(encoder
);
5923 i9xx_pfit_enable(intel_crtc
);
5925 intel_crtc_load_lut(crtc
);
5927 intel_update_watermarks(crtc
);
5928 intel_enable_pipe(intel_crtc
);
5930 assert_vblank_disabled(crtc
);
5931 drm_crtc_vblank_on(crtc
);
5933 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5934 encoder
->enable(encoder
);
5937 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
5939 struct drm_device
*dev
= crtc
->base
.dev
;
5940 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5942 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp0
);
5943 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp1
);
5946 static void i9xx_crtc_enable(struct drm_crtc
*crtc
)
5948 struct drm_device
*dev
= crtc
->dev
;
5949 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5950 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5951 struct intel_encoder
*encoder
;
5952 int pipe
= intel_crtc
->pipe
;
5954 WARN_ON(!crtc
->state
->enable
);
5956 if (intel_crtc
->active
)
5959 i9xx_set_pll_dividers(intel_crtc
);
5961 if (intel_crtc
->config
->has_dp_encoder
)
5962 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5964 intel_set_pipe_timings(intel_crtc
);
5966 i9xx_set_pipeconf(intel_crtc
);
5968 intel_crtc
->active
= true;
5971 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5973 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5974 if (encoder
->pre_enable
)
5975 encoder
->pre_enable(encoder
);
5977 i9xx_enable_pll(intel_crtc
);
5979 i9xx_pfit_enable(intel_crtc
);
5981 intel_crtc_load_lut(crtc
);
5983 intel_update_watermarks(crtc
);
5984 intel_enable_pipe(intel_crtc
);
5986 assert_vblank_disabled(crtc
);
5987 drm_crtc_vblank_on(crtc
);
5989 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5990 encoder
->enable(encoder
);
5993 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
5995 struct drm_device
*dev
= crtc
->base
.dev
;
5996 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5998 if (!crtc
->config
->gmch_pfit
.control
)
6001 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
6003 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
6004 I915_READ(PFIT_CONTROL
));
6005 I915_WRITE(PFIT_CONTROL
, 0);
6008 static void i9xx_crtc_disable(struct drm_crtc
*crtc
)
6010 struct drm_device
*dev
= crtc
->dev
;
6011 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6012 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6013 struct intel_encoder
*encoder
;
6014 int pipe
= intel_crtc
->pipe
;
6016 if (!intel_crtc
->active
)
6020 * On gen2 planes are double buffered but the pipe isn't, so we must
6021 * wait for planes to fully turn off before disabling the pipe.
6022 * We also need to wait on all gmch platforms because of the
6023 * self-refresh mode constraint explained above.
6025 intel_wait_for_vblank(dev
, pipe
);
6027 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6028 encoder
->disable(encoder
);
6030 drm_crtc_vblank_off(crtc
);
6031 assert_vblank_disabled(crtc
);
6033 intel_disable_pipe(intel_crtc
);
6035 i9xx_pfit_disable(intel_crtc
);
6037 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6038 if (encoder
->post_disable
)
6039 encoder
->post_disable(encoder
);
6041 if (!intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_DSI
)) {
6042 if (IS_CHERRYVIEW(dev
))
6043 chv_disable_pll(dev_priv
, pipe
);
6044 else if (IS_VALLEYVIEW(dev
))
6045 vlv_disable_pll(dev_priv
, pipe
);
6047 i9xx_disable_pll(intel_crtc
);
6051 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
6053 intel_crtc
->active
= false;
6054 intel_update_watermarks(crtc
);
6056 mutex_lock(&dev
->struct_mutex
);
6057 intel_fbc_update(dev
);
6058 mutex_unlock(&dev
->struct_mutex
);
6061 static void i9xx_crtc_off(struct drm_crtc
*crtc
)
6065 /* Master function to enable/disable CRTC and corresponding power wells */
6066 void intel_crtc_control(struct drm_crtc
*crtc
, bool enable
)
6068 struct drm_device
*dev
= crtc
->dev
;
6069 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6070 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6071 enum intel_display_power_domain domain
;
6072 unsigned long domains
;
6075 if (!intel_crtc
->active
) {
6076 domains
= get_crtc_power_domains(crtc
);
6077 for_each_power_domain(domain
, domains
)
6078 intel_display_power_get(dev_priv
, domain
);
6079 intel_crtc
->enabled_power_domains
= domains
;
6081 dev_priv
->display
.crtc_enable(crtc
);
6082 intel_crtc_enable_planes(crtc
);
6085 if (intel_crtc
->active
) {
6086 intel_crtc_disable_planes(crtc
);
6087 dev_priv
->display
.crtc_disable(crtc
);
6089 domains
= intel_crtc
->enabled_power_domains
;
6090 for_each_power_domain(domain
, domains
)
6091 intel_display_power_put(dev_priv
, domain
);
6092 intel_crtc
->enabled_power_domains
= 0;
6098 * Sets the power management mode of the pipe and plane.
6100 void intel_crtc_update_dpms(struct drm_crtc
*crtc
)
6102 struct drm_device
*dev
= crtc
->dev
;
6103 struct intel_encoder
*intel_encoder
;
6104 bool enable
= false;
6106 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
6107 enable
|= intel_encoder
->connectors_active
;
6109 intel_crtc_control(crtc
, enable
);
6112 static void intel_crtc_disable(struct drm_crtc
*crtc
)
6114 struct drm_device
*dev
= crtc
->dev
;
6115 struct drm_connector
*connector
;
6116 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6118 /* crtc should still be enabled when we disable it. */
6119 WARN_ON(!crtc
->state
->enable
);
6121 intel_crtc_disable_planes(crtc
);
6122 dev_priv
->display
.crtc_disable(crtc
);
6123 dev_priv
->display
.off(crtc
);
6125 drm_plane_helper_disable(crtc
->primary
);
6127 /* Update computed state. */
6128 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
6129 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
6132 if (connector
->encoder
->crtc
!= crtc
)
6135 connector
->dpms
= DRM_MODE_DPMS_OFF
;
6136 to_intel_encoder(connector
->encoder
)->connectors_active
= false;
6140 void intel_encoder_destroy(struct drm_encoder
*encoder
)
6142 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
6144 drm_encoder_cleanup(encoder
);
6145 kfree(intel_encoder
);
6148 /* Simple dpms helper for encoders with just one connector, no cloning and only
6149 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
6150 * state of the entire output pipe. */
6151 static void intel_encoder_dpms(struct intel_encoder
*encoder
, int mode
)
6153 if (mode
== DRM_MODE_DPMS_ON
) {
6154 encoder
->connectors_active
= true;
6156 intel_crtc_update_dpms(encoder
->base
.crtc
);
6158 encoder
->connectors_active
= false;
6160 intel_crtc_update_dpms(encoder
->base
.crtc
);
6164 /* Cross check the actual hw state with our own modeset state tracking (and it's
6165 * internal consistency). */
6166 static void intel_connector_check_state(struct intel_connector
*connector
)
6168 if (connector
->get_hw_state(connector
)) {
6169 struct intel_encoder
*encoder
= connector
->encoder
;
6170 struct drm_crtc
*crtc
;
6171 bool encoder_enabled
;
6174 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6175 connector
->base
.base
.id
,
6176 connector
->base
.name
);
6178 /* there is no real hw state for MST connectors */
6179 if (connector
->mst_port
)
6182 I915_STATE_WARN(connector
->base
.dpms
== DRM_MODE_DPMS_OFF
,
6183 "wrong connector dpms state\n");
6184 I915_STATE_WARN(connector
->base
.encoder
!= &encoder
->base
,
6185 "active connector not linked to encoder\n");
6188 I915_STATE_WARN(!encoder
->connectors_active
,
6189 "encoder->connectors_active not set\n");
6191 encoder_enabled
= encoder
->get_hw_state(encoder
, &pipe
);
6192 I915_STATE_WARN(!encoder_enabled
, "encoder not enabled\n");
6193 if (I915_STATE_WARN_ON(!encoder
->base
.crtc
))
6196 crtc
= encoder
->base
.crtc
;
6198 I915_STATE_WARN(!crtc
->state
->enable
,
6199 "crtc not enabled\n");
6200 I915_STATE_WARN(!to_intel_crtc(crtc
)->active
, "crtc not active\n");
6201 I915_STATE_WARN(pipe
!= to_intel_crtc(crtc
)->pipe
,
6202 "encoder active on the wrong pipe\n");
6207 int intel_connector_init(struct intel_connector
*connector
)
6209 struct drm_connector_state
*connector_state
;
6211 connector_state
= kzalloc(sizeof *connector_state
, GFP_KERNEL
);
6212 if (!connector_state
)
6215 connector
->base
.state
= connector_state
;
6219 struct intel_connector
*intel_connector_alloc(void)
6221 struct intel_connector
*connector
;
6223 connector
= kzalloc(sizeof *connector
, GFP_KERNEL
);
6227 if (intel_connector_init(connector
) < 0) {
6235 /* Even simpler default implementation, if there's really no special case to
6237 void intel_connector_dpms(struct drm_connector
*connector
, int mode
)
6239 /* All the simple cases only support two dpms states. */
6240 if (mode
!= DRM_MODE_DPMS_ON
)
6241 mode
= DRM_MODE_DPMS_OFF
;
6243 if (mode
== connector
->dpms
)
6246 connector
->dpms
= mode
;
6248 /* Only need to change hw state when actually enabled */
6249 if (connector
->encoder
)
6250 intel_encoder_dpms(to_intel_encoder(connector
->encoder
), mode
);
6252 intel_modeset_check_state(connector
->dev
);
6255 /* Simple connector->get_hw_state implementation for encoders that support only
6256 * one connector and no cloning and hence the encoder state determines the state
6257 * of the connector. */
6258 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
6261 struct intel_encoder
*encoder
= connector
->encoder
;
6263 return encoder
->get_hw_state(encoder
, &pipe
);
6266 static int pipe_required_fdi_lanes(struct intel_crtc_state
*crtc_state
)
6268 if (crtc_state
->base
.enable
&& crtc_state
->has_pch_encoder
)
6269 return crtc_state
->fdi_lanes
;
6274 static int ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
6275 struct intel_crtc_state
*pipe_config
)
6277 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
6278 struct intel_crtc
*other_crtc
;
6279 struct intel_crtc_state
*other_crtc_state
;
6281 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6282 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6283 if (pipe_config
->fdi_lanes
> 4) {
6284 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6285 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6289 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
6290 if (pipe_config
->fdi_lanes
> 2) {
6291 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6292 pipe_config
->fdi_lanes
);
6299 if (INTEL_INFO(dev
)->num_pipes
== 2)
6302 /* Ivybridge 3 pipe is really complicated */
6307 if (pipe_config
->fdi_lanes
<= 2)
6310 other_crtc
= to_intel_crtc(intel_get_crtc_for_pipe(dev
, PIPE_C
));
6312 intel_atomic_get_crtc_state(state
, other_crtc
);
6313 if (IS_ERR(other_crtc_state
))
6314 return PTR_ERR(other_crtc_state
);
6316 if (pipe_required_fdi_lanes(other_crtc_state
) > 0) {
6317 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6318 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6323 if (pipe_config
->fdi_lanes
> 2) {
6324 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6325 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6329 other_crtc
= to_intel_crtc(intel_get_crtc_for_pipe(dev
, PIPE_B
));
6331 intel_atomic_get_crtc_state(state
, other_crtc
);
6332 if (IS_ERR(other_crtc_state
))
6333 return PTR_ERR(other_crtc_state
);
6335 if (pipe_required_fdi_lanes(other_crtc_state
) > 2) {
6336 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6346 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
6347 struct intel_crtc_state
*pipe_config
)
6349 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6350 struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6351 int lane
, link_bw
, fdi_dotclock
, ret
;
6352 bool needs_recompute
= false;
6355 /* FDI is a binary signal running at ~2.7GHz, encoding
6356 * each output octet as 10 bits. The actual frequency
6357 * is stored as a divider into a 100MHz clock, and the
6358 * mode pixel clock is stored in units of 1KHz.
6359 * Hence the bw of each lane in terms of the mode signal
6362 link_bw
= intel_fdi_link_freq(dev
) * MHz(100)/KHz(1)/10;
6364 fdi_dotclock
= adjusted_mode
->crtc_clock
;
6366 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
6367 pipe_config
->pipe_bpp
);
6369 pipe_config
->fdi_lanes
= lane
;
6371 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
6372 link_bw
, &pipe_config
->fdi_m_n
);
6374 ret
= ironlake_check_fdi_lanes(intel_crtc
->base
.dev
,
6375 intel_crtc
->pipe
, pipe_config
);
6376 if (ret
== -EINVAL
&& pipe_config
->pipe_bpp
> 6*3) {
6377 pipe_config
->pipe_bpp
-= 2*3;
6378 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6379 pipe_config
->pipe_bpp
);
6380 needs_recompute
= true;
6381 pipe_config
->bw_constrained
= true;
6386 if (needs_recompute
)
6392 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
6393 struct intel_crtc_state
*pipe_config
)
6395 pipe_config
->ips_enabled
= i915
.enable_ips
&&
6396 hsw_crtc_supports_ips(crtc
) &&
6397 pipe_config
->pipe_bpp
<= 24;
6400 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
6401 struct intel_crtc_state
*pipe_config
)
6403 struct drm_device
*dev
= crtc
->base
.dev
;
6404 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6405 struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6408 /* FIXME should check pixel clock limits on all platforms */
6409 if (INTEL_INFO(dev
)->gen
< 4) {
6411 dev_priv
->display
.get_display_clock_speed(dev
);
6414 * Enable pixel doubling when the dot clock
6415 * is > 90% of the (display) core speed.
6417 * GDG double wide on either pipe,
6418 * otherwise pipe A only.
6420 if ((crtc
->pipe
== PIPE_A
|| IS_I915G(dev
)) &&
6421 adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10) {
6423 pipe_config
->double_wide
= true;
6426 if (adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10)
6431 * Pipe horizontal size must be even in:
6433 * - LVDS dual channel mode
6434 * - Double wide pipe
6436 if ((intel_pipe_will_have_type(pipe_config
, INTEL_OUTPUT_LVDS
) &&
6437 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
6438 pipe_config
->pipe_src_w
&= ~1;
6440 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6441 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6443 if ((INTEL_INFO(dev
)->gen
> 4 || IS_G4X(dev
)) &&
6444 adjusted_mode
->hsync_start
== adjusted_mode
->hdisplay
)
6448 hsw_compute_ips_config(crtc
, pipe_config
);
6450 if (pipe_config
->has_pch_encoder
)
6451 return ironlake_fdi_compute_config(crtc
, pipe_config
);
6453 /* FIXME: remove below call once atomic mode set is place and all crtc
6454 * related checks called from atomic_crtc_check function */
6456 DRM_DEBUG_KMS("intel_crtc = %p drm_state (pipe_config->base.state) = %p\n",
6457 crtc
, pipe_config
->base
.state
);
6458 ret
= intel_atomic_setup_scalers(dev
, crtc
, pipe_config
);
6463 static int skylake_get_display_clock_speed(struct drm_device
*dev
)
6465 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6466 uint32_t lcpll1
= I915_READ(LCPLL1_CTL
);
6467 uint32_t cdctl
= I915_READ(CDCLK_CTL
);
6470 if (!(lcpll1
& LCPLL_PLL_ENABLE
)) {
6471 WARN(1, "LCPLL1 not enabled\n");
6472 return 24000; /* 24MHz is the cd freq with NSSC ref */
6475 if ((cdctl
& CDCLK_FREQ_SEL_MASK
) == CDCLK_FREQ_540
)
6478 linkrate
= (I915_READ(DPLL_CTRL1
) &
6479 DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
)) >> 1;
6481 if (linkrate
== DPLL_CTRL1_LINK_RATE_2160
||
6482 linkrate
== DPLL_CTRL1_LINK_RATE_1080
) {
6484 switch (cdctl
& CDCLK_FREQ_SEL_MASK
) {
6485 case CDCLK_FREQ_450_432
:
6487 case CDCLK_FREQ_337_308
:
6489 case CDCLK_FREQ_675_617
:
6492 WARN(1, "Unknown cd freq selection\n");
6496 switch (cdctl
& CDCLK_FREQ_SEL_MASK
) {
6497 case CDCLK_FREQ_450_432
:
6499 case CDCLK_FREQ_337_308
:
6501 case CDCLK_FREQ_675_617
:
6504 WARN(1, "Unknown cd freq selection\n");
6508 /* error case, do as if DPLL0 isn't enabled */
6512 static int broadwell_get_display_clock_speed(struct drm_device
*dev
)
6514 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6515 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
6516 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
6518 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
6520 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
6522 else if (freq
== LCPLL_CLK_FREQ_450
)
6524 else if (freq
== LCPLL_CLK_FREQ_54O_BDW
)
6526 else if (freq
== LCPLL_CLK_FREQ_337_5_BDW
)
6532 static int haswell_get_display_clock_speed(struct drm_device
*dev
)
6534 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6535 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
6536 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
6538 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
6540 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
6542 else if (freq
== LCPLL_CLK_FREQ_450
)
6544 else if (IS_HSW_ULT(dev
))
6550 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
6552 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6556 if (dev_priv
->hpll_freq
== 0)
6557 dev_priv
->hpll_freq
= valleyview_get_vco(dev_priv
);
6559 mutex_lock(&dev_priv
->dpio_lock
);
6560 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
6561 mutex_unlock(&dev_priv
->dpio_lock
);
6563 divider
= val
& DISPLAY_FREQUENCY_VALUES
;
6565 WARN((val
& DISPLAY_FREQUENCY_STATUS
) !=
6566 (divider
<< DISPLAY_FREQUENCY_STATUS_SHIFT
),
6567 "cdclk change in progress\n");
6569 return DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, divider
+ 1);
6572 static int ilk_get_display_clock_speed(struct drm_device
*dev
)
6577 static int i945_get_display_clock_speed(struct drm_device
*dev
)
6582 static int i915_get_display_clock_speed(struct drm_device
*dev
)
6587 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
6592 static int pnv_get_display_clock_speed(struct drm_device
*dev
)
6596 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
6598 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
6599 case GC_DISPLAY_CLOCK_267_MHZ_PNV
:
6601 case GC_DISPLAY_CLOCK_333_MHZ_PNV
:
6603 case GC_DISPLAY_CLOCK_444_MHZ_PNV
:
6605 case GC_DISPLAY_CLOCK_200_MHZ_PNV
:
6608 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc
);
6609 case GC_DISPLAY_CLOCK_133_MHZ_PNV
:
6611 case GC_DISPLAY_CLOCK_167_MHZ_PNV
:
6616 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
6620 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
6622 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
6625 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
6626 case GC_DISPLAY_CLOCK_333_MHZ
:
6629 case GC_DISPLAY_CLOCK_190_200_MHZ
:
6635 static int i865_get_display_clock_speed(struct drm_device
*dev
)
6640 static int i855_get_display_clock_speed(struct drm_device
*dev
)
6643 /* Assume that the hardware is in the high speed state. This
6644 * should be the default.
6646 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
6647 case GC_CLOCK_133_200
:
6648 case GC_CLOCK_100_200
:
6650 case GC_CLOCK_166_250
:
6652 case GC_CLOCK_100_133
:
6656 /* Shouldn't happen */
6660 static int i830_get_display_clock_speed(struct drm_device
*dev
)
6666 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
6668 while (*num
> DATA_LINK_M_N_MASK
||
6669 *den
> DATA_LINK_M_N_MASK
) {
6675 static void compute_m_n(unsigned int m
, unsigned int n
,
6676 uint32_t *ret_m
, uint32_t *ret_n
)
6678 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
6679 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
6680 intel_reduce_m_n_ratio(ret_m
, ret_n
);
6684 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
6685 int pixel_clock
, int link_clock
,
6686 struct intel_link_m_n
*m_n
)
6690 compute_m_n(bits_per_pixel
* pixel_clock
,
6691 link_clock
* nlanes
* 8,
6692 &m_n
->gmch_m
, &m_n
->gmch_n
);
6694 compute_m_n(pixel_clock
, link_clock
,
6695 &m_n
->link_m
, &m_n
->link_n
);
6698 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
6700 if (i915
.panel_use_ssc
>= 0)
6701 return i915
.panel_use_ssc
!= 0;
6702 return dev_priv
->vbt
.lvds_use_ssc
6703 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
6706 static int i9xx_get_refclk(const struct intel_crtc_state
*crtc_state
,
6709 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
6710 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6713 WARN_ON(!crtc_state
->base
.state
);
6715 if (IS_VALLEYVIEW(dev
) || IS_BROXTON(dev
)) {
6717 } else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6718 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
6719 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
6720 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
6721 } else if (!IS_GEN2(dev
)) {
6730 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
6732 return (1 << dpll
->n
) << 16 | dpll
->m2
;
6735 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
6737 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
6740 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
6741 struct intel_crtc_state
*crtc_state
,
6742 intel_clock_t
*reduced_clock
)
6744 struct drm_device
*dev
= crtc
->base
.dev
;
6747 if (IS_PINEVIEW(dev
)) {
6748 fp
= pnv_dpll_compute_fp(&crtc_state
->dpll
);
6750 fp2
= pnv_dpll_compute_fp(reduced_clock
);
6752 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
6754 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
6757 crtc_state
->dpll_hw_state
.fp0
= fp
;
6759 crtc
->lowfreq_avail
= false;
6760 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6762 crtc_state
->dpll_hw_state
.fp1
= fp2
;
6763 crtc
->lowfreq_avail
= true;
6765 crtc_state
->dpll_hw_state
.fp1
= fp
;
6769 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
6775 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6776 * and set it to a reasonable value instead.
6778 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6779 reg_val
&= 0xffffff00;
6780 reg_val
|= 0x00000030;
6781 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6783 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6784 reg_val
&= 0x8cffffff;
6785 reg_val
= 0x8c000000;
6786 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6788 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6789 reg_val
&= 0xffffff00;
6790 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6792 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6793 reg_val
&= 0x00ffffff;
6794 reg_val
|= 0xb0000000;
6795 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6798 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
6799 struct intel_link_m_n
*m_n
)
6801 struct drm_device
*dev
= crtc
->base
.dev
;
6802 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6803 int pipe
= crtc
->pipe
;
6805 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6806 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
6807 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
6808 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
6811 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
6812 struct intel_link_m_n
*m_n
,
6813 struct intel_link_m_n
*m2_n2
)
6815 struct drm_device
*dev
= crtc
->base
.dev
;
6816 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6817 int pipe
= crtc
->pipe
;
6818 enum transcoder transcoder
= crtc
->config
->cpu_transcoder
;
6820 if (INTEL_INFO(dev
)->gen
>= 5) {
6821 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6822 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
6823 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
6824 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
6825 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
6826 * for gen < 8) and if DRRS is supported (to make sure the
6827 * registers are not unnecessarily accessed).
6829 if (m2_n2
&& (IS_CHERRYVIEW(dev
) || INTEL_INFO(dev
)->gen
< 8) &&
6830 crtc
->config
->has_drrs
) {
6831 I915_WRITE(PIPE_DATA_M2(transcoder
),
6832 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
6833 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
6834 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
6835 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
6838 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6839 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
6840 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
6841 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
6845 void intel_dp_set_m_n(struct intel_crtc
*crtc
, enum link_m_n_set m_n
)
6847 struct intel_link_m_n
*dp_m_n
, *dp_m2_n2
= NULL
;
6850 dp_m_n
= &crtc
->config
->dp_m_n
;
6851 dp_m2_n2
= &crtc
->config
->dp_m2_n2
;
6852 } else if (m_n
== M2_N2
) {
6855 * M2_N2 registers are not supported. Hence m2_n2 divider value
6856 * needs to be programmed into M1_N1.
6858 dp_m_n
= &crtc
->config
->dp_m2_n2
;
6860 DRM_ERROR("Unsupported divider value\n");
6864 if (crtc
->config
->has_pch_encoder
)
6865 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
->dp_m_n
);
6867 intel_cpu_transcoder_set_m_n(crtc
, dp_m_n
, dp_m2_n2
);
6870 static void vlv_update_pll(struct intel_crtc
*crtc
,
6871 struct intel_crtc_state
*pipe_config
)
6876 * Enable DPIO clock input. We should never disable the reference
6877 * clock for pipe B, since VGA hotplug / manual detection depends
6880 dpll
= DPLL_EXT_BUFFER_ENABLE_VLV
| DPLL_REFA_CLK_ENABLE_VLV
|
6881 DPLL_VGA_MODE_DIS
| DPLL_INTEGRATED_CLOCK_VLV
;
6882 /* We should never disable this, set it here for state tracking */
6883 if (crtc
->pipe
== PIPE_B
)
6884 dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
6885 dpll
|= DPLL_VCO_ENABLE
;
6886 pipe_config
->dpll_hw_state
.dpll
= dpll
;
6888 dpll_md
= (pipe_config
->pixel_multiplier
- 1)
6889 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6890 pipe_config
->dpll_hw_state
.dpll_md
= dpll_md
;
6893 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
6894 const struct intel_crtc_state
*pipe_config
)
6896 struct drm_device
*dev
= crtc
->base
.dev
;
6897 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6898 int pipe
= crtc
->pipe
;
6900 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
6901 u32 coreclk
, reg_val
;
6903 mutex_lock(&dev_priv
->dpio_lock
);
6905 bestn
= pipe_config
->dpll
.n
;
6906 bestm1
= pipe_config
->dpll
.m1
;
6907 bestm2
= pipe_config
->dpll
.m2
;
6908 bestp1
= pipe_config
->dpll
.p1
;
6909 bestp2
= pipe_config
->dpll
.p2
;
6911 /* See eDP HDMI DPIO driver vbios notes doc */
6913 /* PLL B needs special handling */
6915 vlv_pllb_recal_opamp(dev_priv
, pipe
);
6917 /* Set up Tx target for periodic Rcomp update */
6918 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
6920 /* Disable target IRef on PLL */
6921 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
6922 reg_val
&= 0x00ffffff;
6923 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
6925 /* Disable fast lock */
6926 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
6928 /* Set idtafcrecal before PLL is enabled */
6929 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
6930 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
6931 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
6932 mdiv
|= (1 << DPIO_K_SHIFT
);
6935 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6936 * but we don't support that).
6937 * Note: don't use the DAC post divider as it seems unstable.
6939 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
6940 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
6942 mdiv
|= DPIO_ENABLE_CALIBRATION
;
6943 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
6945 /* Set HBR and RBR LPF coefficients */
6946 if (pipe_config
->port_clock
== 162000 ||
6947 intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
) ||
6948 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
))
6949 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
6952 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
6955 if (pipe_config
->has_dp_encoder
) {
6956 /* Use SSC source */
6958 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6961 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6963 } else { /* HDMI or VGA */
6964 /* Use bend source */
6966 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6969 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6973 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
6974 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
6975 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
6976 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))
6977 coreclk
|= 0x01000000;
6978 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
6980 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
6981 mutex_unlock(&dev_priv
->dpio_lock
);
6984 static void chv_update_pll(struct intel_crtc
*crtc
,
6985 struct intel_crtc_state
*pipe_config
)
6987 pipe_config
->dpll_hw_state
.dpll
= DPLL_SSC_REF_CLOCK_CHV
|
6988 DPLL_REFA_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
|
6990 if (crtc
->pipe
!= PIPE_A
)
6991 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
6993 pipe_config
->dpll_hw_state
.dpll_md
=
6994 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6997 static void chv_prepare_pll(struct intel_crtc
*crtc
,
6998 const struct intel_crtc_state
*pipe_config
)
7000 struct drm_device
*dev
= crtc
->base
.dev
;
7001 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7002 int pipe
= crtc
->pipe
;
7003 int dpll_reg
= DPLL(crtc
->pipe
);
7004 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
7005 u32 loopfilter
, tribuf_calcntr
;
7006 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
7010 bestn
= pipe_config
->dpll
.n
;
7011 bestm2_frac
= pipe_config
->dpll
.m2
& 0x3fffff;
7012 bestm1
= pipe_config
->dpll
.m1
;
7013 bestm2
= pipe_config
->dpll
.m2
>> 22;
7014 bestp1
= pipe_config
->dpll
.p1
;
7015 bestp2
= pipe_config
->dpll
.p2
;
7016 vco
= pipe_config
->dpll
.vco
;
7021 * Enable Refclk and SSC
7023 I915_WRITE(dpll_reg
,
7024 pipe_config
->dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
7026 mutex_lock(&dev_priv
->dpio_lock
);
7028 /* p1 and p2 divider */
7029 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
7030 5 << DPIO_CHV_S1_DIV_SHIFT
|
7031 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
7032 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
7033 1 << DPIO_CHV_K_DIV_SHIFT
);
7035 /* Feedback post-divider - m2 */
7036 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
7038 /* Feedback refclk divider - n and m1 */
7039 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
7040 DPIO_CHV_M1_DIV_BY_2
|
7041 1 << DPIO_CHV_N_DIV_SHIFT
);
7043 /* M2 fraction division */
7045 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
7047 /* M2 fraction division enable */
7048 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
7049 dpio_val
&= ~(DPIO_CHV_FEEDFWD_GAIN_MASK
| DPIO_CHV_FRAC_DIV_EN
);
7050 dpio_val
|= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
);
7052 dpio_val
|= DPIO_CHV_FRAC_DIV_EN
;
7053 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
), dpio_val
);
7055 /* Program digital lock detect threshold */
7056 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW9(port
));
7057 dpio_val
&= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK
|
7058 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
);
7059 dpio_val
|= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT
);
7061 dpio_val
|= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
;
7062 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW9(port
), dpio_val
);
7065 if (vco
== 5400000) {
7066 loopfilter
|= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT
);
7067 loopfilter
|= (0x8 << DPIO_CHV_INT_COEFF_SHIFT
);
7068 loopfilter
|= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7069 tribuf_calcntr
= 0x9;
7070 } else if (vco
<= 6200000) {
7071 loopfilter
|= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT
);
7072 loopfilter
|= (0xB << DPIO_CHV_INT_COEFF_SHIFT
);
7073 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7074 tribuf_calcntr
= 0x9;
7075 } else if (vco
<= 6480000) {
7076 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
7077 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
7078 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7079 tribuf_calcntr
= 0x8;
7081 /* Not supported. Apply the same limits as in the max case */
7082 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
7083 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
7084 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7087 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
7089 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW8(port
));
7090 dpio_val
&= ~DPIO_CHV_TDC_TARGET_CNT_MASK
;
7091 dpio_val
|= (tribuf_calcntr
<< DPIO_CHV_TDC_TARGET_CNT_SHIFT
);
7092 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW8(port
), dpio_val
);
7095 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
7096 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
7099 mutex_unlock(&dev_priv
->dpio_lock
);
7103 * vlv_force_pll_on - forcibly enable just the PLL
7104 * @dev_priv: i915 private structure
7105 * @pipe: pipe PLL to enable
7106 * @dpll: PLL configuration
7108 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7109 * in cases where we need the PLL enabled even when @pipe is not going to
7112 void vlv_force_pll_on(struct drm_device
*dev
, enum pipe pipe
,
7113 const struct dpll
*dpll
)
7115 struct intel_crtc
*crtc
=
7116 to_intel_crtc(intel_get_crtc_for_pipe(dev
, pipe
));
7117 struct intel_crtc_state pipe_config
= {
7118 .base
.crtc
= &crtc
->base
,
7119 .pixel_multiplier
= 1,
7123 if (IS_CHERRYVIEW(dev
)) {
7124 chv_update_pll(crtc
, &pipe_config
);
7125 chv_prepare_pll(crtc
, &pipe_config
);
7126 chv_enable_pll(crtc
, &pipe_config
);
7128 vlv_update_pll(crtc
, &pipe_config
);
7129 vlv_prepare_pll(crtc
, &pipe_config
);
7130 vlv_enable_pll(crtc
, &pipe_config
);
7135 * vlv_force_pll_off - forcibly disable just the PLL
7136 * @dev_priv: i915 private structure
7137 * @pipe: pipe PLL to disable
7139 * Disable the PLL for @pipe. To be used in cases where we need
7140 * the PLL enabled even when @pipe is not going to be enabled.
7142 void vlv_force_pll_off(struct drm_device
*dev
, enum pipe pipe
)
7144 if (IS_CHERRYVIEW(dev
))
7145 chv_disable_pll(to_i915(dev
), pipe
);
7147 vlv_disable_pll(to_i915(dev
), pipe
);
7150 static void i9xx_update_pll(struct intel_crtc
*crtc
,
7151 struct intel_crtc_state
*crtc_state
,
7152 intel_clock_t
*reduced_clock
,
7155 struct drm_device
*dev
= crtc
->base
.dev
;
7156 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7159 struct dpll
*clock
= &crtc_state
->dpll
;
7161 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
7163 is_sdvo
= intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
7164 intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_HDMI
);
7166 dpll
= DPLL_VGA_MODE_DIS
;
7168 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
))
7169 dpll
|= DPLLB_MODE_LVDS
;
7171 dpll
|= DPLLB_MODE_DAC_SERIAL
;
7173 if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
7174 dpll
|= (crtc_state
->pixel_multiplier
- 1)
7175 << SDVO_MULTIPLIER_SHIFT_HIRES
;
7179 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7181 if (crtc_state
->has_dp_encoder
)
7182 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7184 /* compute bitmask from p1 value */
7185 if (IS_PINEVIEW(dev
))
7186 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
7188 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7189 if (IS_G4X(dev
) && reduced_clock
)
7190 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
7192 switch (clock
->p2
) {
7194 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
7197 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
7200 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
7203 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
7206 if (INTEL_INFO(dev
)->gen
>= 4)
7207 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
7209 if (crtc_state
->sdvo_tv_clock
)
7210 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
7211 else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
7212 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
7213 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7215 dpll
|= PLL_REF_INPUT_DREFCLK
;
7217 dpll
|= DPLL_VCO_ENABLE
;
7218 crtc_state
->dpll_hw_state
.dpll
= dpll
;
7220 if (INTEL_INFO(dev
)->gen
>= 4) {
7221 u32 dpll_md
= (crtc_state
->pixel_multiplier
- 1)
7222 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
7223 crtc_state
->dpll_hw_state
.dpll_md
= dpll_md
;
7227 static void i8xx_update_pll(struct intel_crtc
*crtc
,
7228 struct intel_crtc_state
*crtc_state
,
7229 intel_clock_t
*reduced_clock
,
7232 struct drm_device
*dev
= crtc
->base
.dev
;
7233 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7235 struct dpll
*clock
= &crtc_state
->dpll
;
7237 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
7239 dpll
= DPLL_VGA_MODE_DIS
;
7241 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7242 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7245 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
7247 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7249 dpll
|= PLL_P2_DIVIDE_BY_4
;
7252 if (!IS_I830(dev
) && intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_DVO
))
7253 dpll
|= DPLL_DVO_2X_MODE
;
7255 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
7256 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
7257 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7259 dpll
|= PLL_REF_INPUT_DREFCLK
;
7261 dpll
|= DPLL_VCO_ENABLE
;
7262 crtc_state
->dpll_hw_state
.dpll
= dpll
;
7265 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
7267 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7268 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7269 enum pipe pipe
= intel_crtc
->pipe
;
7270 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
7271 struct drm_display_mode
*adjusted_mode
=
7272 &intel_crtc
->config
->base
.adjusted_mode
;
7273 uint32_t crtc_vtotal
, crtc_vblank_end
;
7276 /* We need to be careful not to changed the adjusted mode, for otherwise
7277 * the hw state checker will get angry at the mismatch. */
7278 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
7279 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
7281 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
7282 /* the chip adds 2 halflines automatically */
7284 crtc_vblank_end
-= 1;
7286 if (intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
7287 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
7289 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
7290 adjusted_mode
->crtc_htotal
/ 2;
7292 vsyncshift
+= adjusted_mode
->crtc_htotal
;
7295 if (INTEL_INFO(dev
)->gen
> 3)
7296 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
7298 I915_WRITE(HTOTAL(cpu_transcoder
),
7299 (adjusted_mode
->crtc_hdisplay
- 1) |
7300 ((adjusted_mode
->crtc_htotal
- 1) << 16));
7301 I915_WRITE(HBLANK(cpu_transcoder
),
7302 (adjusted_mode
->crtc_hblank_start
- 1) |
7303 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
7304 I915_WRITE(HSYNC(cpu_transcoder
),
7305 (adjusted_mode
->crtc_hsync_start
- 1) |
7306 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
7308 I915_WRITE(VTOTAL(cpu_transcoder
),
7309 (adjusted_mode
->crtc_vdisplay
- 1) |
7310 ((crtc_vtotal
- 1) << 16));
7311 I915_WRITE(VBLANK(cpu_transcoder
),
7312 (adjusted_mode
->crtc_vblank_start
- 1) |
7313 ((crtc_vblank_end
- 1) << 16));
7314 I915_WRITE(VSYNC(cpu_transcoder
),
7315 (adjusted_mode
->crtc_vsync_start
- 1) |
7316 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
7318 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7319 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7320 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7322 if (IS_HASWELL(dev
) && cpu_transcoder
== TRANSCODER_EDP
&&
7323 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
7324 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
7326 /* pipesrc controls the size that is scaled from, which should
7327 * always be the user's requested size.
7329 I915_WRITE(PIPESRC(pipe
),
7330 ((intel_crtc
->config
->pipe_src_w
- 1) << 16) |
7331 (intel_crtc
->config
->pipe_src_h
- 1));
7334 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
7335 struct intel_crtc_state
*pipe_config
)
7337 struct drm_device
*dev
= crtc
->base
.dev
;
7338 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7339 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
7342 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
7343 pipe_config
->base
.adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
7344 pipe_config
->base
.adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
7345 tmp
= I915_READ(HBLANK(cpu_transcoder
));
7346 pipe_config
->base
.adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
7347 pipe_config
->base
.adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
7348 tmp
= I915_READ(HSYNC(cpu_transcoder
));
7349 pipe_config
->base
.adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
7350 pipe_config
->base
.adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
7352 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
7353 pipe_config
->base
.adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
7354 pipe_config
->base
.adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
7355 tmp
= I915_READ(VBLANK(cpu_transcoder
));
7356 pipe_config
->base
.adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
7357 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
7358 tmp
= I915_READ(VSYNC(cpu_transcoder
));
7359 pipe_config
->base
.adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
7360 pipe_config
->base
.adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
7362 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
7363 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
7364 pipe_config
->base
.adjusted_mode
.crtc_vtotal
+= 1;
7365 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
+= 1;
7368 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
7369 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
7370 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
7372 pipe_config
->base
.mode
.vdisplay
= pipe_config
->pipe_src_h
;
7373 pipe_config
->base
.mode
.hdisplay
= pipe_config
->pipe_src_w
;
7376 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
7377 struct intel_crtc_state
*pipe_config
)
7379 mode
->hdisplay
= pipe_config
->base
.adjusted_mode
.crtc_hdisplay
;
7380 mode
->htotal
= pipe_config
->base
.adjusted_mode
.crtc_htotal
;
7381 mode
->hsync_start
= pipe_config
->base
.adjusted_mode
.crtc_hsync_start
;
7382 mode
->hsync_end
= pipe_config
->base
.adjusted_mode
.crtc_hsync_end
;
7384 mode
->vdisplay
= pipe_config
->base
.adjusted_mode
.crtc_vdisplay
;
7385 mode
->vtotal
= pipe_config
->base
.adjusted_mode
.crtc_vtotal
;
7386 mode
->vsync_start
= pipe_config
->base
.adjusted_mode
.crtc_vsync_start
;
7387 mode
->vsync_end
= pipe_config
->base
.adjusted_mode
.crtc_vsync_end
;
7389 mode
->flags
= pipe_config
->base
.adjusted_mode
.flags
;
7391 mode
->clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
7392 mode
->flags
|= pipe_config
->base
.adjusted_mode
.flags
;
7395 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
7397 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7398 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7403 if ((intel_crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
7404 (intel_crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
7405 pipeconf
|= I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
;
7407 if (intel_crtc
->config
->double_wide
)
7408 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
7410 /* only g4x and later have fancy bpc/dither controls */
7411 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
7412 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7413 if (intel_crtc
->config
->dither
&& intel_crtc
->config
->pipe_bpp
!= 30)
7414 pipeconf
|= PIPECONF_DITHER_EN
|
7415 PIPECONF_DITHER_TYPE_SP
;
7417 switch (intel_crtc
->config
->pipe_bpp
) {
7419 pipeconf
|= PIPECONF_6BPC
;
7422 pipeconf
|= PIPECONF_8BPC
;
7425 pipeconf
|= PIPECONF_10BPC
;
7428 /* Case prevented by intel_choose_pipe_bpp_dither. */
7433 if (HAS_PIPE_CXSR(dev
)) {
7434 if (intel_crtc
->lowfreq_avail
) {
7435 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
7436 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
7438 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
7442 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
7443 if (INTEL_INFO(dev
)->gen
< 4 ||
7444 intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
7445 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
7447 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
7449 pipeconf
|= PIPECONF_PROGRESSIVE
;
7451 if (IS_VALLEYVIEW(dev
) && intel_crtc
->config
->limited_color_range
)
7452 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
7454 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
7455 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
7458 static int i9xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7459 struct intel_crtc_state
*crtc_state
)
7461 struct drm_device
*dev
= crtc
->base
.dev
;
7462 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7463 int refclk
, num_connectors
= 0;
7464 intel_clock_t clock
, reduced_clock
;
7465 bool ok
, has_reduced_clock
= false;
7466 bool is_lvds
= false, is_dsi
= false;
7467 struct intel_encoder
*encoder
;
7468 const intel_limit_t
*limit
;
7469 struct drm_atomic_state
*state
= crtc_state
->base
.state
;
7470 struct drm_connector
*connector
;
7471 struct drm_connector_state
*connector_state
;
7474 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
7475 if (connector_state
->crtc
!= &crtc
->base
)
7478 encoder
= to_intel_encoder(connector_state
->best_encoder
);
7480 switch (encoder
->type
) {
7481 case INTEL_OUTPUT_LVDS
:
7484 case INTEL_OUTPUT_DSI
:
7497 if (!crtc_state
->clock_set
) {
7498 refclk
= i9xx_get_refclk(crtc_state
, num_connectors
);
7501 * Returns a set of divisors for the desired target clock with
7502 * the given refclk, or FALSE. The returned values represent
7503 * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
7506 limit
= intel_limit(crtc_state
, refclk
);
7507 ok
= dev_priv
->display
.find_dpll(limit
, crtc_state
,
7508 crtc_state
->port_clock
,
7509 refclk
, NULL
, &clock
);
7511 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7515 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
7517 * Ensure we match the reduced clock's P to the target
7518 * clock. If the clocks don't match, we can't switch
7519 * the display clock by using the FP0/FP1. In such case
7520 * we will disable the LVDS downclock feature.
7523 dev_priv
->display
.find_dpll(limit
, crtc_state
,
7524 dev_priv
->lvds_downclock
,
7528 /* Compat-code for transition, will disappear. */
7529 crtc_state
->dpll
.n
= clock
.n
;
7530 crtc_state
->dpll
.m1
= clock
.m1
;
7531 crtc_state
->dpll
.m2
= clock
.m2
;
7532 crtc_state
->dpll
.p1
= clock
.p1
;
7533 crtc_state
->dpll
.p2
= clock
.p2
;
7537 i8xx_update_pll(crtc
, crtc_state
,
7538 has_reduced_clock
? &reduced_clock
: NULL
,
7540 } else if (IS_CHERRYVIEW(dev
)) {
7541 chv_update_pll(crtc
, crtc_state
);
7542 } else if (IS_VALLEYVIEW(dev
)) {
7543 vlv_update_pll(crtc
, crtc_state
);
7545 i9xx_update_pll(crtc
, crtc_state
,
7546 has_reduced_clock
? &reduced_clock
: NULL
,
7553 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
7554 struct intel_crtc_state
*pipe_config
)
7556 struct drm_device
*dev
= crtc
->base
.dev
;
7557 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7560 if (INTEL_INFO(dev
)->gen
<= 3 && (IS_I830(dev
) || !IS_MOBILE(dev
)))
7563 tmp
= I915_READ(PFIT_CONTROL
);
7564 if (!(tmp
& PFIT_ENABLE
))
7567 /* Check whether the pfit is attached to our pipe. */
7568 if (INTEL_INFO(dev
)->gen
< 4) {
7569 if (crtc
->pipe
!= PIPE_B
)
7572 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
7576 pipe_config
->gmch_pfit
.control
= tmp
;
7577 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
7578 if (INTEL_INFO(dev
)->gen
< 5)
7579 pipe_config
->gmch_pfit
.lvds_border_bits
=
7580 I915_READ(LVDS
) & LVDS_BORDER_ENABLE
;
7583 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
7584 struct intel_crtc_state
*pipe_config
)
7586 struct drm_device
*dev
= crtc
->base
.dev
;
7587 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7588 int pipe
= pipe_config
->cpu_transcoder
;
7589 intel_clock_t clock
;
7591 int refclk
= 100000;
7593 /* In case of MIPI DPLL will not even be used */
7594 if (!(pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
))
7597 mutex_lock(&dev_priv
->dpio_lock
);
7598 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
7599 mutex_unlock(&dev_priv
->dpio_lock
);
7601 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
7602 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
7603 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
7604 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
7605 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
7607 vlv_clock(refclk
, &clock
);
7609 /* clock.dot is the fast clock */
7610 pipe_config
->port_clock
= clock
.dot
/ 5;
7614 i9xx_get_initial_plane_config(struct intel_crtc
*crtc
,
7615 struct intel_initial_plane_config
*plane_config
)
7617 struct drm_device
*dev
= crtc
->base
.dev
;
7618 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7619 u32 val
, base
, offset
;
7620 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
7621 int fourcc
, pixel_format
;
7622 unsigned int aligned_height
;
7623 struct drm_framebuffer
*fb
;
7624 struct intel_framebuffer
*intel_fb
;
7626 val
= I915_READ(DSPCNTR(plane
));
7627 if (!(val
& DISPLAY_PLANE_ENABLE
))
7630 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
7632 DRM_DEBUG_KMS("failed to alloc fb\n");
7636 fb
= &intel_fb
->base
;
7638 if (INTEL_INFO(dev
)->gen
>= 4) {
7639 if (val
& DISPPLANE_TILED
) {
7640 plane_config
->tiling
= I915_TILING_X
;
7641 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
7645 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
7646 fourcc
= i9xx_format_to_fourcc(pixel_format
);
7647 fb
->pixel_format
= fourcc
;
7648 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
7650 if (INTEL_INFO(dev
)->gen
>= 4) {
7651 if (plane_config
->tiling
)
7652 offset
= I915_READ(DSPTILEOFF(plane
));
7654 offset
= I915_READ(DSPLINOFF(plane
));
7655 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
7657 base
= I915_READ(DSPADDR(plane
));
7659 plane_config
->base
= base
;
7661 val
= I915_READ(PIPESRC(pipe
));
7662 fb
->width
= ((val
>> 16) & 0xfff) + 1;
7663 fb
->height
= ((val
>> 0) & 0xfff) + 1;
7665 val
= I915_READ(DSPSTRIDE(pipe
));
7666 fb
->pitches
[0] = val
& 0xffffffc0;
7668 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
7672 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
7674 DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7675 pipe_name(pipe
), plane
, fb
->width
, fb
->height
,
7676 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
7677 plane_config
->size
);
7679 plane_config
->fb
= intel_fb
;
7682 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
7683 struct intel_crtc_state
*pipe_config
)
7685 struct drm_device
*dev
= crtc
->base
.dev
;
7686 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7687 int pipe
= pipe_config
->cpu_transcoder
;
7688 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
7689 intel_clock_t clock
;
7690 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
;
7691 int refclk
= 100000;
7693 mutex_lock(&dev_priv
->dpio_lock
);
7694 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
7695 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
7696 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
7697 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
7698 mutex_unlock(&dev_priv
->dpio_lock
);
7700 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
7701 clock
.m2
= ((pll_dw0
& 0xff) << 22) | (pll_dw2
& 0x3fffff);
7702 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
7703 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
7704 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
7706 chv_clock(refclk
, &clock
);
7708 /* clock.dot is the fast clock */
7709 pipe_config
->port_clock
= clock
.dot
/ 5;
7712 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
7713 struct intel_crtc_state
*pipe_config
)
7715 struct drm_device
*dev
= crtc
->base
.dev
;
7716 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7719 if (!intel_display_power_is_enabled(dev_priv
,
7720 POWER_DOMAIN_PIPE(crtc
->pipe
)))
7723 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7724 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
7726 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
7727 if (!(tmp
& PIPECONF_ENABLE
))
7730 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
7731 switch (tmp
& PIPECONF_BPC_MASK
) {
7733 pipe_config
->pipe_bpp
= 18;
7736 pipe_config
->pipe_bpp
= 24;
7738 case PIPECONF_10BPC
:
7739 pipe_config
->pipe_bpp
= 30;
7746 if (IS_VALLEYVIEW(dev
) && (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
7747 pipe_config
->limited_color_range
= true;
7749 if (INTEL_INFO(dev
)->gen
< 4)
7750 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
7752 intel_get_pipe_timings(crtc
, pipe_config
);
7754 i9xx_get_pfit_config(crtc
, pipe_config
);
7756 if (INTEL_INFO(dev
)->gen
>= 4) {
7757 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
7758 pipe_config
->pixel_multiplier
=
7759 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
7760 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
7761 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
7762 } else if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
7763 tmp
= I915_READ(DPLL(crtc
->pipe
));
7764 pipe_config
->pixel_multiplier
=
7765 ((tmp
& SDVO_MULTIPLIER_MASK
)
7766 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
7768 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7769 * port and will be fixed up in the encoder->get_config
7771 pipe_config
->pixel_multiplier
= 1;
7773 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
7774 if (!IS_VALLEYVIEW(dev
)) {
7776 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
7777 * on 830. Filter it out here so that we don't
7778 * report errors due to that.
7781 pipe_config
->dpll_hw_state
.dpll
&= ~DPLL_DVO_2X_MODE
;
7783 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
7784 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
7786 /* Mask out read-only status bits. */
7787 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
7788 DPLL_PORTC_READY_MASK
|
7789 DPLL_PORTB_READY_MASK
);
7792 if (IS_CHERRYVIEW(dev
))
7793 chv_crtc_clock_get(crtc
, pipe_config
);
7794 else if (IS_VALLEYVIEW(dev
))
7795 vlv_crtc_clock_get(crtc
, pipe_config
);
7797 i9xx_crtc_clock_get(crtc
, pipe_config
);
7802 static void ironlake_init_pch_refclk(struct drm_device
*dev
)
7804 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7805 struct intel_encoder
*encoder
;
7807 bool has_lvds
= false;
7808 bool has_cpu_edp
= false;
7809 bool has_panel
= false;
7810 bool has_ck505
= false;
7811 bool can_ssc
= false;
7813 /* We need to take the global config into account */
7814 for_each_intel_encoder(dev
, encoder
) {
7815 switch (encoder
->type
) {
7816 case INTEL_OUTPUT_LVDS
:
7820 case INTEL_OUTPUT_EDP
:
7822 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
7830 if (HAS_PCH_IBX(dev
)) {
7831 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
7832 can_ssc
= has_ck505
;
7838 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
7839 has_panel
, has_lvds
, has_ck505
);
7841 /* Ironlake: try to setup display ref clock before DPLL
7842 * enabling. This is only under driver's control after
7843 * PCH B stepping, previous chipset stepping should be
7844 * ignoring this setting.
7846 val
= I915_READ(PCH_DREF_CONTROL
);
7848 /* As we must carefully and slowly disable/enable each source in turn,
7849 * compute the final state we want first and check if we need to
7850 * make any changes at all.
7853 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
7855 final
|= DREF_NONSPREAD_CK505_ENABLE
;
7857 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
7859 final
&= ~DREF_SSC_SOURCE_MASK
;
7860 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7861 final
&= ~DREF_SSC1_ENABLE
;
7864 final
|= DREF_SSC_SOURCE_ENABLE
;
7866 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
7867 final
|= DREF_SSC1_ENABLE
;
7870 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
7871 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
7873 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
7875 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7877 final
|= DREF_SSC_SOURCE_DISABLE
;
7878 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7884 /* Always enable nonspread source */
7885 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
7888 val
|= DREF_NONSPREAD_CK505_ENABLE
;
7890 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
7893 val
&= ~DREF_SSC_SOURCE_MASK
;
7894 val
|= DREF_SSC_SOURCE_ENABLE
;
7896 /* SSC must be turned on before enabling the CPU output */
7897 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
7898 DRM_DEBUG_KMS("Using SSC on panel\n");
7899 val
|= DREF_SSC1_ENABLE
;
7901 val
&= ~DREF_SSC1_ENABLE
;
7903 /* Get SSC going before enabling the outputs */
7904 I915_WRITE(PCH_DREF_CONTROL
, val
);
7905 POSTING_READ(PCH_DREF_CONTROL
);
7908 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7910 /* Enable CPU source on CPU attached eDP */
7912 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
7913 DRM_DEBUG_KMS("Using SSC on eDP\n");
7914 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
7916 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
7918 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7920 I915_WRITE(PCH_DREF_CONTROL
, val
);
7921 POSTING_READ(PCH_DREF_CONTROL
);
7924 DRM_DEBUG_KMS("Disabling SSC entirely\n");
7926 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7928 /* Turn off CPU output */
7929 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7931 I915_WRITE(PCH_DREF_CONTROL
, val
);
7932 POSTING_READ(PCH_DREF_CONTROL
);
7935 /* Turn off the SSC source */
7936 val
&= ~DREF_SSC_SOURCE_MASK
;
7937 val
|= DREF_SSC_SOURCE_DISABLE
;
7940 val
&= ~DREF_SSC1_ENABLE
;
7942 I915_WRITE(PCH_DREF_CONTROL
, val
);
7943 POSTING_READ(PCH_DREF_CONTROL
);
7947 BUG_ON(val
!= final
);
7950 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
7954 tmp
= I915_READ(SOUTH_CHICKEN2
);
7955 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
7956 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
7958 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2
) &
7959 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
7960 DRM_ERROR("FDI mPHY reset assert timeout\n");
7962 tmp
= I915_READ(SOUTH_CHICKEN2
);
7963 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
7964 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
7966 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2
) &
7967 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
7968 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
7971 /* WaMPhyProgramming:hsw */
7972 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
7976 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
7977 tmp
&= ~(0xFF << 24);
7978 tmp
|= (0x12 << 24);
7979 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
7981 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
7983 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
7985 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
7987 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
7989 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
7990 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
7991 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
7993 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
7994 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
7995 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
7997 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
8000 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
8002 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
8005 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
8007 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
8010 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
8012 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
8015 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
8017 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
8018 tmp
&= ~(0xFF << 16);
8019 tmp
|= (0x1C << 16);
8020 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
8022 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
8023 tmp
&= ~(0xFF << 16);
8024 tmp
|= (0x1C << 16);
8025 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
8027 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
8029 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
8031 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
8033 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
8035 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
8036 tmp
&= ~(0xF << 28);
8038 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
8040 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
8041 tmp
&= ~(0xF << 28);
8043 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
8046 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8047 * Programming" based on the parameters passed:
8048 * - Sequence to enable CLKOUT_DP
8049 * - Sequence to enable CLKOUT_DP without spread
8050 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8052 static void lpt_enable_clkout_dp(struct drm_device
*dev
, bool with_spread
,
8055 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8058 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
8060 if (WARN(dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
&&
8061 with_fdi
, "LP PCH doesn't have FDI\n"))
8064 mutex_lock(&dev_priv
->dpio_lock
);
8066 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8067 tmp
&= ~SBI_SSCCTL_DISABLE
;
8068 tmp
|= SBI_SSCCTL_PATHALT
;
8069 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8074 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8075 tmp
&= ~SBI_SSCCTL_PATHALT
;
8076 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8079 lpt_reset_fdi_mphy(dev_priv
);
8080 lpt_program_fdi_mphy(dev_priv
);
8084 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
8085 SBI_GEN0
: SBI_DBUFF0
;
8086 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
8087 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
8088 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
8090 mutex_unlock(&dev_priv
->dpio_lock
);
8093 /* Sequence to disable CLKOUT_DP */
8094 static void lpt_disable_clkout_dp(struct drm_device
*dev
)
8096 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8099 mutex_lock(&dev_priv
->dpio_lock
);
8101 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
8102 SBI_GEN0
: SBI_DBUFF0
;
8103 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
8104 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
8105 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
8107 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8108 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
8109 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
8110 tmp
|= SBI_SSCCTL_PATHALT
;
8111 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8114 tmp
|= SBI_SSCCTL_DISABLE
;
8115 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8118 mutex_unlock(&dev_priv
->dpio_lock
);
8121 static void lpt_init_pch_refclk(struct drm_device
*dev
)
8123 struct intel_encoder
*encoder
;
8124 bool has_vga
= false;
8126 for_each_intel_encoder(dev
, encoder
) {
8127 switch (encoder
->type
) {
8128 case INTEL_OUTPUT_ANALOG
:
8137 lpt_enable_clkout_dp(dev
, true, true);
8139 lpt_disable_clkout_dp(dev
);
8143 * Initialize reference clocks when the driver loads
8145 void intel_init_pch_refclk(struct drm_device
*dev
)
8147 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
8148 ironlake_init_pch_refclk(dev
);
8149 else if (HAS_PCH_LPT(dev
))
8150 lpt_init_pch_refclk(dev
);
8153 static int ironlake_get_refclk(struct intel_crtc_state
*crtc_state
)
8155 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
8156 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8157 struct drm_atomic_state
*state
= crtc_state
->base
.state
;
8158 struct drm_connector
*connector
;
8159 struct drm_connector_state
*connector_state
;
8160 struct intel_encoder
*encoder
;
8161 int num_connectors
= 0, i
;
8162 bool is_lvds
= false;
8164 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
8165 if (connector_state
->crtc
!= crtc_state
->base
.crtc
)
8168 encoder
= to_intel_encoder(connector_state
->best_encoder
);
8170 switch (encoder
->type
) {
8171 case INTEL_OUTPUT_LVDS
:
8180 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
8181 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8182 dev_priv
->vbt
.lvds_ssc_freq
);
8183 return dev_priv
->vbt
.lvds_ssc_freq
;
8189 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
8191 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
8192 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8193 int pipe
= intel_crtc
->pipe
;
8198 switch (intel_crtc
->config
->pipe_bpp
) {
8200 val
|= PIPECONF_6BPC
;
8203 val
|= PIPECONF_8BPC
;
8206 val
|= PIPECONF_10BPC
;
8209 val
|= PIPECONF_12BPC
;
8212 /* Case prevented by intel_choose_pipe_bpp_dither. */
8216 if (intel_crtc
->config
->dither
)
8217 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
8219 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8220 val
|= PIPECONF_INTERLACED_ILK
;
8222 val
|= PIPECONF_PROGRESSIVE
;
8224 if (intel_crtc
->config
->limited_color_range
)
8225 val
|= PIPECONF_COLOR_RANGE_SELECT
;
8227 I915_WRITE(PIPECONF(pipe
), val
);
8228 POSTING_READ(PIPECONF(pipe
));
8232 * Set up the pipe CSC unit.
8234 * Currently only full range RGB to limited range RGB conversion
8235 * is supported, but eventually this should handle various
8236 * RGB<->YCbCr scenarios as well.
8238 static void intel_set_pipe_csc(struct drm_crtc
*crtc
)
8240 struct drm_device
*dev
= crtc
->dev
;
8241 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8242 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8243 int pipe
= intel_crtc
->pipe
;
8244 uint16_t coeff
= 0x7800; /* 1.0 */
8247 * TODO: Check what kind of values actually come out of the pipe
8248 * with these coeff/postoff values and adjust to get the best
8249 * accuracy. Perhaps we even need to take the bpc value into
8253 if (intel_crtc
->config
->limited_color_range
)
8254 coeff
= ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
8257 * GY/GU and RY/RU should be the other way around according
8258 * to BSpec, but reality doesn't agree. Just set them up in
8259 * a way that results in the correct picture.
8261 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe
), coeff
<< 16);
8262 I915_WRITE(PIPE_CSC_COEFF_BY(pipe
), 0);
8264 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe
), coeff
);
8265 I915_WRITE(PIPE_CSC_COEFF_BU(pipe
), 0);
8267 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe
), 0);
8268 I915_WRITE(PIPE_CSC_COEFF_BV(pipe
), coeff
<< 16);
8270 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe
), 0);
8271 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe
), 0);
8272 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe
), 0);
8274 if (INTEL_INFO(dev
)->gen
> 6) {
8275 uint16_t postoff
= 0;
8277 if (intel_crtc
->config
->limited_color_range
)
8278 postoff
= (16 * (1 << 12) / 255) & 0x1fff;
8280 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe
), postoff
);
8281 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe
), postoff
);
8282 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe
), postoff
);
8284 I915_WRITE(PIPE_CSC_MODE(pipe
), 0);
8286 uint32_t mode
= CSC_MODE_YUV_TO_RGB
;
8288 if (intel_crtc
->config
->limited_color_range
)
8289 mode
|= CSC_BLACK_SCREEN_OFFSET
;
8291 I915_WRITE(PIPE_CSC_MODE(pipe
), mode
);
8295 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
8297 struct drm_device
*dev
= crtc
->dev
;
8298 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8299 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8300 enum pipe pipe
= intel_crtc
->pipe
;
8301 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
8306 if (IS_HASWELL(dev
) && intel_crtc
->config
->dither
)
8307 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
8309 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8310 val
|= PIPECONF_INTERLACED_ILK
;
8312 val
|= PIPECONF_PROGRESSIVE
;
8314 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
8315 POSTING_READ(PIPECONF(cpu_transcoder
));
8317 I915_WRITE(GAMMA_MODE(intel_crtc
->pipe
), GAMMA_MODE_MODE_8BIT
);
8318 POSTING_READ(GAMMA_MODE(intel_crtc
->pipe
));
8320 if (IS_BROADWELL(dev
) || INTEL_INFO(dev
)->gen
>= 9) {
8323 switch (intel_crtc
->config
->pipe_bpp
) {
8325 val
|= PIPEMISC_DITHER_6_BPC
;
8328 val
|= PIPEMISC_DITHER_8_BPC
;
8331 val
|= PIPEMISC_DITHER_10_BPC
;
8334 val
|= PIPEMISC_DITHER_12_BPC
;
8337 /* Case prevented by pipe_config_set_bpp. */
8341 if (intel_crtc
->config
->dither
)
8342 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
8344 I915_WRITE(PIPEMISC(pipe
), val
);
8348 static bool ironlake_compute_clocks(struct drm_crtc
*crtc
,
8349 struct intel_crtc_state
*crtc_state
,
8350 intel_clock_t
*clock
,
8351 bool *has_reduced_clock
,
8352 intel_clock_t
*reduced_clock
)
8354 struct drm_device
*dev
= crtc
->dev
;
8355 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8357 const intel_limit_t
*limit
;
8358 bool ret
, is_lvds
= false;
8360 is_lvds
= intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
);
8362 refclk
= ironlake_get_refclk(crtc_state
);
8365 * Returns a set of divisors for the desired target clock with the given
8366 * refclk, or FALSE. The returned values represent the clock equation:
8367 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
8369 limit
= intel_limit(crtc_state
, refclk
);
8370 ret
= dev_priv
->display
.find_dpll(limit
, crtc_state
,
8371 crtc_state
->port_clock
,
8372 refclk
, NULL
, clock
);
8376 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
8378 * Ensure we match the reduced clock's P to the target clock.
8379 * If the clocks don't match, we can't switch the display clock
8380 * by using the FP0/FP1. In such case we will disable the LVDS
8381 * downclock feature.
8383 *has_reduced_clock
=
8384 dev_priv
->display
.find_dpll(limit
, crtc_state
,
8385 dev_priv
->lvds_downclock
,
8393 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
8396 * Account for spread spectrum to avoid
8397 * oversubscribing the link. Max center spread
8398 * is 2.5%; use 5% for safety's sake.
8400 u32 bps
= target_clock
* bpp
* 21 / 20;
8401 return DIV_ROUND_UP(bps
, link_bw
* 8);
8404 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
8406 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
8409 static uint32_t ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
8410 struct intel_crtc_state
*crtc_state
,
8412 intel_clock_t
*reduced_clock
, u32
*fp2
)
8414 struct drm_crtc
*crtc
= &intel_crtc
->base
;
8415 struct drm_device
*dev
= crtc
->dev
;
8416 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8417 struct drm_atomic_state
*state
= crtc_state
->base
.state
;
8418 struct drm_connector
*connector
;
8419 struct drm_connector_state
*connector_state
;
8420 struct intel_encoder
*encoder
;
8422 int factor
, num_connectors
= 0, i
;
8423 bool is_lvds
= false, is_sdvo
= false;
8425 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
8426 if (connector_state
->crtc
!= crtc_state
->base
.crtc
)
8429 encoder
= to_intel_encoder(connector_state
->best_encoder
);
8431 switch (encoder
->type
) {
8432 case INTEL_OUTPUT_LVDS
:
8435 case INTEL_OUTPUT_SDVO
:
8436 case INTEL_OUTPUT_HDMI
:
8446 /* Enable autotuning of the PLL clock (if permissible) */
8449 if ((intel_panel_use_ssc(dev_priv
) &&
8450 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
8451 (HAS_PCH_IBX(dev
) && intel_is_dual_link_lvds(dev
)))
8453 } else if (crtc_state
->sdvo_tv_clock
)
8456 if (ironlake_needs_fb_cb_tune(&crtc_state
->dpll
, factor
))
8459 if (fp2
&& (reduced_clock
->m
< factor
* reduced_clock
->n
))
8465 dpll
|= DPLLB_MODE_LVDS
;
8467 dpll
|= DPLLB_MODE_DAC_SERIAL
;
8469 dpll
|= (crtc_state
->pixel_multiplier
- 1)
8470 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
8473 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8474 if (crtc_state
->has_dp_encoder
)
8475 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8477 /* compute bitmask from p1 value */
8478 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8480 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
8482 switch (crtc_state
->dpll
.p2
) {
8484 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
8487 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
8490 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
8493 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
8497 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
8498 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
8500 dpll
|= PLL_REF_INPUT_DREFCLK
;
8502 return dpll
| DPLL_VCO_ENABLE
;
8505 static int ironlake_crtc_compute_clock(struct intel_crtc
*crtc
,
8506 struct intel_crtc_state
*crtc_state
)
8508 struct drm_device
*dev
= crtc
->base
.dev
;
8509 intel_clock_t clock
, reduced_clock
;
8510 u32 dpll
= 0, fp
= 0, fp2
= 0;
8511 bool ok
, has_reduced_clock
= false;
8512 bool is_lvds
= false;
8513 struct intel_shared_dpll
*pll
;
8515 is_lvds
= intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
);
8517 WARN(!(HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)),
8518 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev
));
8520 ok
= ironlake_compute_clocks(&crtc
->base
, crtc_state
, &clock
,
8521 &has_reduced_clock
, &reduced_clock
);
8522 if (!ok
&& !crtc_state
->clock_set
) {
8523 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8526 /* Compat-code for transition, will disappear. */
8527 if (!crtc_state
->clock_set
) {
8528 crtc_state
->dpll
.n
= clock
.n
;
8529 crtc_state
->dpll
.m1
= clock
.m1
;
8530 crtc_state
->dpll
.m2
= clock
.m2
;
8531 crtc_state
->dpll
.p1
= clock
.p1
;
8532 crtc_state
->dpll
.p2
= clock
.p2
;
8535 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8536 if (crtc_state
->has_pch_encoder
) {
8537 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
8538 if (has_reduced_clock
)
8539 fp2
= i9xx_dpll_compute_fp(&reduced_clock
);
8541 dpll
= ironlake_compute_dpll(crtc
, crtc_state
,
8542 &fp
, &reduced_clock
,
8543 has_reduced_clock
? &fp2
: NULL
);
8545 crtc_state
->dpll_hw_state
.dpll
= dpll
;
8546 crtc_state
->dpll_hw_state
.fp0
= fp
;
8547 if (has_reduced_clock
)
8548 crtc_state
->dpll_hw_state
.fp1
= fp2
;
8550 crtc_state
->dpll_hw_state
.fp1
= fp
;
8552 pll
= intel_get_shared_dpll(crtc
, crtc_state
);
8554 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8555 pipe_name(crtc
->pipe
));
8560 if (is_lvds
&& has_reduced_clock
)
8561 crtc
->lowfreq_avail
= true;
8563 crtc
->lowfreq_avail
= false;
8568 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
8569 struct intel_link_m_n
*m_n
)
8571 struct drm_device
*dev
= crtc
->base
.dev
;
8572 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8573 enum pipe pipe
= crtc
->pipe
;
8575 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
8576 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
8577 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
8579 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
8580 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
8581 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8584 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
8585 enum transcoder transcoder
,
8586 struct intel_link_m_n
*m_n
,
8587 struct intel_link_m_n
*m2_n2
)
8589 struct drm_device
*dev
= crtc
->base
.dev
;
8590 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8591 enum pipe pipe
= crtc
->pipe
;
8593 if (INTEL_INFO(dev
)->gen
>= 5) {
8594 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
8595 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
8596 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
8598 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
8599 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
8600 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8601 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8602 * gen < 8) and if DRRS is supported (to make sure the
8603 * registers are not unnecessarily read).
8605 if (m2_n2
&& INTEL_INFO(dev
)->gen
< 8 &&
8606 crtc
->config
->has_drrs
) {
8607 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
8608 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
8609 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
8611 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
8612 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
8613 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8616 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
8617 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
8618 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
8620 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
8621 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
8622 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8626 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
8627 struct intel_crtc_state
*pipe_config
)
8629 if (pipe_config
->has_pch_encoder
)
8630 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
8632 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8633 &pipe_config
->dp_m_n
,
8634 &pipe_config
->dp_m2_n2
);
8637 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
8638 struct intel_crtc_state
*pipe_config
)
8640 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8641 &pipe_config
->fdi_m_n
, NULL
);
8644 static void skylake_get_pfit_config(struct intel_crtc
*crtc
,
8645 struct intel_crtc_state
*pipe_config
)
8647 struct drm_device
*dev
= crtc
->base
.dev
;
8648 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8649 struct intel_crtc_scaler_state
*scaler_state
= &pipe_config
->scaler_state
;
8650 uint32_t ps_ctrl
= 0;
8654 /* find scaler attached to this pipe */
8655 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
8656 ps_ctrl
= I915_READ(SKL_PS_CTRL(crtc
->pipe
, i
));
8657 if (ps_ctrl
& PS_SCALER_EN
&& !(ps_ctrl
& PS_PLANE_SEL_MASK
)) {
8659 pipe_config
->pch_pfit
.enabled
= true;
8660 pipe_config
->pch_pfit
.pos
= I915_READ(SKL_PS_WIN_POS(crtc
->pipe
, i
));
8661 pipe_config
->pch_pfit
.size
= I915_READ(SKL_PS_WIN_SZ(crtc
->pipe
, i
));
8666 scaler_state
->scaler_id
= id
;
8668 scaler_state
->scaler_users
|= (1 << SKL_CRTC_INDEX
);
8670 scaler_state
->scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
8675 skylake_get_initial_plane_config(struct intel_crtc
*crtc
,
8676 struct intel_initial_plane_config
*plane_config
)
8678 struct drm_device
*dev
= crtc
->base
.dev
;
8679 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8680 u32 val
, base
, offset
, stride_mult
, tiling
;
8681 int pipe
= crtc
->pipe
;
8682 int fourcc
, pixel_format
;
8683 unsigned int aligned_height
;
8684 struct drm_framebuffer
*fb
;
8685 struct intel_framebuffer
*intel_fb
;
8687 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8689 DRM_DEBUG_KMS("failed to alloc fb\n");
8693 fb
= &intel_fb
->base
;
8695 val
= I915_READ(PLANE_CTL(pipe
, 0));
8696 if (!(val
& PLANE_CTL_ENABLE
))
8699 pixel_format
= val
& PLANE_CTL_FORMAT_MASK
;
8700 fourcc
= skl_format_to_fourcc(pixel_format
,
8701 val
& PLANE_CTL_ORDER_RGBX
,
8702 val
& PLANE_CTL_ALPHA_MASK
);
8703 fb
->pixel_format
= fourcc
;
8704 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
8706 tiling
= val
& PLANE_CTL_TILED_MASK
;
8708 case PLANE_CTL_TILED_LINEAR
:
8709 fb
->modifier
[0] = DRM_FORMAT_MOD_NONE
;
8711 case PLANE_CTL_TILED_X
:
8712 plane_config
->tiling
= I915_TILING_X
;
8713 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
8715 case PLANE_CTL_TILED_Y
:
8716 fb
->modifier
[0] = I915_FORMAT_MOD_Y_TILED
;
8718 case PLANE_CTL_TILED_YF
:
8719 fb
->modifier
[0] = I915_FORMAT_MOD_Yf_TILED
;
8722 MISSING_CASE(tiling
);
8726 base
= I915_READ(PLANE_SURF(pipe
, 0)) & 0xfffff000;
8727 plane_config
->base
= base
;
8729 offset
= I915_READ(PLANE_OFFSET(pipe
, 0));
8731 val
= I915_READ(PLANE_SIZE(pipe
, 0));
8732 fb
->height
= ((val
>> 16) & 0xfff) + 1;
8733 fb
->width
= ((val
>> 0) & 0x1fff) + 1;
8735 val
= I915_READ(PLANE_STRIDE(pipe
, 0));
8736 stride_mult
= intel_fb_stride_alignment(dev
, fb
->modifier
[0],
8738 fb
->pitches
[0] = (val
& 0x3ff) * stride_mult
;
8740 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
8744 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8746 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8747 pipe_name(pipe
), fb
->width
, fb
->height
,
8748 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
8749 plane_config
->size
);
8751 plane_config
->fb
= intel_fb
;
8758 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
8759 struct intel_crtc_state
*pipe_config
)
8761 struct drm_device
*dev
= crtc
->base
.dev
;
8762 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8765 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
8767 if (tmp
& PF_ENABLE
) {
8768 pipe_config
->pch_pfit
.enabled
= true;
8769 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
8770 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
8772 /* We currently do not free assignements of panel fitters on
8773 * ivb/hsw (since we don't use the higher upscaling modes which
8774 * differentiates them) so just WARN about this case for now. */
8776 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
8777 PF_PIPE_SEL_IVB(crtc
->pipe
));
8783 ironlake_get_initial_plane_config(struct intel_crtc
*crtc
,
8784 struct intel_initial_plane_config
*plane_config
)
8786 struct drm_device
*dev
= crtc
->base
.dev
;
8787 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8788 u32 val
, base
, offset
;
8789 int pipe
= crtc
->pipe
;
8790 int fourcc
, pixel_format
;
8791 unsigned int aligned_height
;
8792 struct drm_framebuffer
*fb
;
8793 struct intel_framebuffer
*intel_fb
;
8795 val
= I915_READ(DSPCNTR(pipe
));
8796 if (!(val
& DISPLAY_PLANE_ENABLE
))
8799 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8801 DRM_DEBUG_KMS("failed to alloc fb\n");
8805 fb
= &intel_fb
->base
;
8807 if (INTEL_INFO(dev
)->gen
>= 4) {
8808 if (val
& DISPPLANE_TILED
) {
8809 plane_config
->tiling
= I915_TILING_X
;
8810 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
8814 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
8815 fourcc
= i9xx_format_to_fourcc(pixel_format
);
8816 fb
->pixel_format
= fourcc
;
8817 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
8819 base
= I915_READ(DSPSURF(pipe
)) & 0xfffff000;
8820 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
8821 offset
= I915_READ(DSPOFFSET(pipe
));
8823 if (plane_config
->tiling
)
8824 offset
= I915_READ(DSPTILEOFF(pipe
));
8826 offset
= I915_READ(DSPLINOFF(pipe
));
8828 plane_config
->base
= base
;
8830 val
= I915_READ(PIPESRC(pipe
));
8831 fb
->width
= ((val
>> 16) & 0xfff) + 1;
8832 fb
->height
= ((val
>> 0) & 0xfff) + 1;
8834 val
= I915_READ(DSPSTRIDE(pipe
));
8835 fb
->pitches
[0] = val
& 0xffffffc0;
8837 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
8841 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8843 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8844 pipe_name(pipe
), fb
->width
, fb
->height
,
8845 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
8846 plane_config
->size
);
8848 plane_config
->fb
= intel_fb
;
8851 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
8852 struct intel_crtc_state
*pipe_config
)
8854 struct drm_device
*dev
= crtc
->base
.dev
;
8855 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8858 if (!intel_display_power_is_enabled(dev_priv
,
8859 POWER_DOMAIN_PIPE(crtc
->pipe
)))
8862 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8863 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
8865 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
8866 if (!(tmp
& PIPECONF_ENABLE
))
8869 switch (tmp
& PIPECONF_BPC_MASK
) {
8871 pipe_config
->pipe_bpp
= 18;
8874 pipe_config
->pipe_bpp
= 24;
8876 case PIPECONF_10BPC
:
8877 pipe_config
->pipe_bpp
= 30;
8879 case PIPECONF_12BPC
:
8880 pipe_config
->pipe_bpp
= 36;
8886 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
8887 pipe_config
->limited_color_range
= true;
8889 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
8890 struct intel_shared_dpll
*pll
;
8892 pipe_config
->has_pch_encoder
= true;
8894 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
8895 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
8896 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
8898 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
8900 if (HAS_PCH_IBX(dev_priv
->dev
)) {
8901 pipe_config
->shared_dpll
=
8902 (enum intel_dpll_id
) crtc
->pipe
;
8904 tmp
= I915_READ(PCH_DPLL_SEL
);
8905 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
8906 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_B
;
8908 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_A
;
8911 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
8913 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
8914 &pipe_config
->dpll_hw_state
));
8916 tmp
= pipe_config
->dpll_hw_state
.dpll
;
8917 pipe_config
->pixel_multiplier
=
8918 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
8919 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
8921 ironlake_pch_clock_get(crtc
, pipe_config
);
8923 pipe_config
->pixel_multiplier
= 1;
8926 intel_get_pipe_timings(crtc
, pipe_config
);
8928 ironlake_get_pfit_config(crtc
, pipe_config
);
8933 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
8935 struct drm_device
*dev
= dev_priv
->dev
;
8936 struct intel_crtc
*crtc
;
8938 for_each_intel_crtc(dev
, crtc
)
8939 I915_STATE_WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
8940 pipe_name(crtc
->pipe
));
8942 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
8943 I915_STATE_WARN(I915_READ(SPLL_CTL
) & SPLL_PLL_ENABLE
, "SPLL enabled\n");
8944 I915_STATE_WARN(I915_READ(WRPLL_CTL1
) & WRPLL_PLL_ENABLE
, "WRPLL1 enabled\n");
8945 I915_STATE_WARN(I915_READ(WRPLL_CTL2
) & WRPLL_PLL_ENABLE
, "WRPLL2 enabled\n");
8946 I915_STATE_WARN(I915_READ(PCH_PP_STATUS
) & PP_ON
, "Panel power on\n");
8947 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
8948 "CPU PWM1 enabled\n");
8949 if (IS_HASWELL(dev
))
8950 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
8951 "CPU PWM2 enabled\n");
8952 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
8953 "PCH PWM1 enabled\n");
8954 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
8955 "Utility pin enabled\n");
8956 I915_STATE_WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
8959 * In theory we can still leave IRQs enabled, as long as only the HPD
8960 * interrupts remain enabled. We used to check for that, but since it's
8961 * gen-specific and since we only disable LCPLL after we fully disable
8962 * the interrupts, the check below should be enough.
8964 I915_STATE_WARN(intel_irqs_enabled(dev_priv
), "IRQs enabled\n");
8967 static uint32_t hsw_read_dcomp(struct drm_i915_private
*dev_priv
)
8969 struct drm_device
*dev
= dev_priv
->dev
;
8971 if (IS_HASWELL(dev
))
8972 return I915_READ(D_COMP_HSW
);
8974 return I915_READ(D_COMP_BDW
);
8977 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
8979 struct drm_device
*dev
= dev_priv
->dev
;
8981 if (IS_HASWELL(dev
)) {
8982 mutex_lock(&dev_priv
->rps
.hw_lock
);
8983 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
8985 DRM_ERROR("Failed to write to D_COMP\n");
8986 mutex_unlock(&dev_priv
->rps
.hw_lock
);
8988 I915_WRITE(D_COMP_BDW
, val
);
8989 POSTING_READ(D_COMP_BDW
);
8994 * This function implements pieces of two sequences from BSpec:
8995 * - Sequence for display software to disable LCPLL
8996 * - Sequence for display software to allow package C8+
8997 * The steps implemented here are just the steps that actually touch the LCPLL
8998 * register. Callers should take care of disabling all the display engine
8999 * functions, doing the mode unset, fixing interrupts, etc.
9001 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
9002 bool switch_to_fclk
, bool allow_power_down
)
9006 assert_can_disable_lcpll(dev_priv
);
9008 val
= I915_READ(LCPLL_CTL
);
9010 if (switch_to_fclk
) {
9011 val
|= LCPLL_CD_SOURCE_FCLK
;
9012 I915_WRITE(LCPLL_CTL
, val
);
9014 if (wait_for_atomic_us(I915_READ(LCPLL_CTL
) &
9015 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
9016 DRM_ERROR("Switching to FCLK failed\n");
9018 val
= I915_READ(LCPLL_CTL
);
9021 val
|= LCPLL_PLL_DISABLE
;
9022 I915_WRITE(LCPLL_CTL
, val
);
9023 POSTING_READ(LCPLL_CTL
);
9025 if (wait_for((I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
) == 0, 1))
9026 DRM_ERROR("LCPLL still locked\n");
9028 val
= hsw_read_dcomp(dev_priv
);
9029 val
|= D_COMP_COMP_DISABLE
;
9030 hsw_write_dcomp(dev_priv
, val
);
9033 if (wait_for((hsw_read_dcomp(dev_priv
) & D_COMP_RCOMP_IN_PROGRESS
) == 0,
9035 DRM_ERROR("D_COMP RCOMP still in progress\n");
9037 if (allow_power_down
) {
9038 val
= I915_READ(LCPLL_CTL
);
9039 val
|= LCPLL_POWER_DOWN_ALLOW
;
9040 I915_WRITE(LCPLL_CTL
, val
);
9041 POSTING_READ(LCPLL_CTL
);
9046 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9049 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
9053 val
= I915_READ(LCPLL_CTL
);
9055 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
9056 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
9060 * Make sure we're not on PC8 state before disabling PC8, otherwise
9061 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
9063 intel_uncore_forcewake_get(dev_priv
, FORCEWAKE_ALL
);
9065 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
9066 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
9067 I915_WRITE(LCPLL_CTL
, val
);
9068 POSTING_READ(LCPLL_CTL
);
9071 val
= hsw_read_dcomp(dev_priv
);
9072 val
|= D_COMP_COMP_FORCE
;
9073 val
&= ~D_COMP_COMP_DISABLE
;
9074 hsw_write_dcomp(dev_priv
, val
);
9076 val
= I915_READ(LCPLL_CTL
);
9077 val
&= ~LCPLL_PLL_DISABLE
;
9078 I915_WRITE(LCPLL_CTL
, val
);
9080 if (wait_for(I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
, 5))
9081 DRM_ERROR("LCPLL not locked yet\n");
9083 if (val
& LCPLL_CD_SOURCE_FCLK
) {
9084 val
= I915_READ(LCPLL_CTL
);
9085 val
&= ~LCPLL_CD_SOURCE_FCLK
;
9086 I915_WRITE(LCPLL_CTL
, val
);
9088 if (wait_for_atomic_us((I915_READ(LCPLL_CTL
) &
9089 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
9090 DRM_ERROR("Switching back to LCPLL failed\n");
9093 intel_uncore_forcewake_put(dev_priv
, FORCEWAKE_ALL
);
9097 * Package states C8 and deeper are really deep PC states that can only be
9098 * reached when all the devices on the system allow it, so even if the graphics
9099 * device allows PC8+, it doesn't mean the system will actually get to these
9100 * states. Our driver only allows PC8+ when going into runtime PM.
9102 * The requirements for PC8+ are that all the outputs are disabled, the power
9103 * well is disabled and most interrupts are disabled, and these are also
9104 * requirements for runtime PM. When these conditions are met, we manually do
9105 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9106 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9109 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9110 * the state of some registers, so when we come back from PC8+ we need to
9111 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9112 * need to take care of the registers kept by RC6. Notice that this happens even
9113 * if we don't put the device in PCI D3 state (which is what currently happens
9114 * because of the runtime PM support).
9116 * For more, read "Display Sequences for Package C8" on the hardware
9119 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
9121 struct drm_device
*dev
= dev_priv
->dev
;
9124 DRM_DEBUG_KMS("Enabling package C8+\n");
9126 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
9127 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
9128 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
9129 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
9132 lpt_disable_clkout_dp(dev
);
9133 hsw_disable_lcpll(dev_priv
, true, true);
9136 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
9138 struct drm_device
*dev
= dev_priv
->dev
;
9141 DRM_DEBUG_KMS("Disabling package C8+\n");
9143 hsw_restore_lcpll(dev_priv
);
9144 lpt_init_pch_refclk(dev
);
9146 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
9147 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
9148 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
9149 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
9152 intel_prepare_ddi(dev
);
9155 static void broxton_modeset_global_resources(struct drm_atomic_state
*state
)
9157 struct drm_device
*dev
= state
->dev
;
9158 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9159 int max_pixclk
= intel_mode_max_pixclk(state
);
9162 /* see the comment in valleyview_modeset_global_resources */
9163 if (WARN_ON(max_pixclk
< 0))
9166 req_cdclk
= broxton_calc_cdclk(dev_priv
, max_pixclk
);
9168 if (req_cdclk
!= dev_priv
->cdclk_freq
)
9169 broxton_set_cdclk(dev
, req_cdclk
);
9172 static int haswell_crtc_compute_clock(struct intel_crtc
*crtc
,
9173 struct intel_crtc_state
*crtc_state
)
9175 if (!intel_ddi_pll_select(crtc
, crtc_state
))
9178 crtc
->lowfreq_avail
= false;
9183 static void bxt_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9185 struct intel_crtc_state
*pipe_config
)
9189 pipe_config
->ddi_pll_sel
= SKL_DPLL0
;
9190 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL1
;
9193 pipe_config
->ddi_pll_sel
= SKL_DPLL1
;
9194 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL2
;
9197 pipe_config
->ddi_pll_sel
= SKL_DPLL2
;
9198 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL3
;
9201 DRM_ERROR("Incorrect port type\n");
9205 static void skylake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9207 struct intel_crtc_state
*pipe_config
)
9209 u32 temp
, dpll_ctl1
;
9211 temp
= I915_READ(DPLL_CTRL2
) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port
);
9212 pipe_config
->ddi_pll_sel
= temp
>> (port
* 3 + 1);
9214 switch (pipe_config
->ddi_pll_sel
) {
9217 * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part
9218 * of the shared DPLL framework and thus needs to be read out
9221 dpll_ctl1
= I915_READ(DPLL_CTRL1
);
9222 pipe_config
->dpll_hw_state
.ctrl1
= dpll_ctl1
& 0x3f;
9225 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL1
;
9228 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL2
;
9231 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL3
;
9236 static void haswell_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9238 struct intel_crtc_state
*pipe_config
)
9240 pipe_config
->ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
9242 switch (pipe_config
->ddi_pll_sel
) {
9243 case PORT_CLK_SEL_WRPLL1
:
9244 pipe_config
->shared_dpll
= DPLL_ID_WRPLL1
;
9246 case PORT_CLK_SEL_WRPLL2
:
9247 pipe_config
->shared_dpll
= DPLL_ID_WRPLL2
;
9252 static void haswell_get_ddi_port_state(struct intel_crtc
*crtc
,
9253 struct intel_crtc_state
*pipe_config
)
9255 struct drm_device
*dev
= crtc
->base
.dev
;
9256 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9257 struct intel_shared_dpll
*pll
;
9261 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
9263 port
= (tmp
& TRANS_DDI_PORT_MASK
) >> TRANS_DDI_PORT_SHIFT
;
9265 if (IS_SKYLAKE(dev
))
9266 skylake_get_ddi_pll(dev_priv
, port
, pipe_config
);
9267 else if (IS_BROXTON(dev
))
9268 bxt_get_ddi_pll(dev_priv
, port
, pipe_config
);
9270 haswell_get_ddi_pll(dev_priv
, port
, pipe_config
);
9272 if (pipe_config
->shared_dpll
>= 0) {
9273 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
9275 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
9276 &pipe_config
->dpll_hw_state
));
9280 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9281 * DDI E. So just check whether this pipe is wired to DDI E and whether
9282 * the PCH transcoder is on.
9284 if (INTEL_INFO(dev
)->gen
< 9 &&
9285 (port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
9286 pipe_config
->has_pch_encoder
= true;
9288 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
9289 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
9290 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
9292 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
9296 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
9297 struct intel_crtc_state
*pipe_config
)
9299 struct drm_device
*dev
= crtc
->base
.dev
;
9300 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9301 enum intel_display_power_domain pfit_domain
;
9304 if (!intel_display_power_is_enabled(dev_priv
,
9305 POWER_DOMAIN_PIPE(crtc
->pipe
)))
9308 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
9309 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
9311 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
9312 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
9313 enum pipe trans_edp_pipe
;
9314 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
9316 WARN(1, "unknown pipe linked to edp transcoder\n");
9317 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
9318 case TRANS_DDI_EDP_INPUT_A_ON
:
9319 trans_edp_pipe
= PIPE_A
;
9321 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
9322 trans_edp_pipe
= PIPE_B
;
9324 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
9325 trans_edp_pipe
= PIPE_C
;
9329 if (trans_edp_pipe
== crtc
->pipe
)
9330 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
9333 if (!intel_display_power_is_enabled(dev_priv
,
9334 POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
)))
9337 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
9338 if (!(tmp
& PIPECONF_ENABLE
))
9341 haswell_get_ddi_port_state(crtc
, pipe_config
);
9343 intel_get_pipe_timings(crtc
, pipe_config
);
9345 if (INTEL_INFO(dev
)->gen
>= 9) {
9346 skl_init_scalers(dev
, crtc
, pipe_config
);
9349 pfit_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
9350 if (intel_display_power_is_enabled(dev_priv
, pfit_domain
)) {
9351 if (INTEL_INFO(dev
)->gen
== 9)
9352 skylake_get_pfit_config(crtc
, pipe_config
);
9353 else if (INTEL_INFO(dev
)->gen
< 9)
9354 ironlake_get_pfit_config(crtc
, pipe_config
);
9356 MISSING_CASE(INTEL_INFO(dev
)->gen
);
9359 pipe_config
->scaler_state
.scaler_id
= -1;
9360 pipe_config
->scaler_state
.scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
9363 if (IS_HASWELL(dev
))
9364 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
9365 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
9367 if (pipe_config
->cpu_transcoder
!= TRANSCODER_EDP
) {
9368 pipe_config
->pixel_multiplier
=
9369 I915_READ(PIPE_MULT(pipe_config
->cpu_transcoder
)) + 1;
9371 pipe_config
->pixel_multiplier
= 1;
9377 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
)
9379 struct drm_device
*dev
= crtc
->dev
;
9380 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9381 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9382 uint32_t cntl
= 0, size
= 0;
9385 unsigned int width
= intel_crtc
->base
.cursor
->state
->crtc_w
;
9386 unsigned int height
= intel_crtc
->base
.cursor
->state
->crtc_h
;
9387 unsigned int stride
= roundup_pow_of_two(width
) * 4;
9391 WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
9402 cntl
|= CURSOR_ENABLE
|
9403 CURSOR_GAMMA_ENABLE
|
9404 CURSOR_FORMAT_ARGB
|
9405 CURSOR_STRIDE(stride
);
9407 size
= (height
<< 12) | width
;
9410 if (intel_crtc
->cursor_cntl
!= 0 &&
9411 (intel_crtc
->cursor_base
!= base
||
9412 intel_crtc
->cursor_size
!= size
||
9413 intel_crtc
->cursor_cntl
!= cntl
)) {
9414 /* On these chipsets we can only modify the base/size/stride
9415 * whilst the cursor is disabled.
9417 I915_WRITE(_CURACNTR
, 0);
9418 POSTING_READ(_CURACNTR
);
9419 intel_crtc
->cursor_cntl
= 0;
9422 if (intel_crtc
->cursor_base
!= base
) {
9423 I915_WRITE(_CURABASE
, base
);
9424 intel_crtc
->cursor_base
= base
;
9427 if (intel_crtc
->cursor_size
!= size
) {
9428 I915_WRITE(CURSIZE
, size
);
9429 intel_crtc
->cursor_size
= size
;
9432 if (intel_crtc
->cursor_cntl
!= cntl
) {
9433 I915_WRITE(_CURACNTR
, cntl
);
9434 POSTING_READ(_CURACNTR
);
9435 intel_crtc
->cursor_cntl
= cntl
;
9439 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
)
9441 struct drm_device
*dev
= crtc
->dev
;
9442 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9443 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9444 int pipe
= intel_crtc
->pipe
;
9449 cntl
= MCURSOR_GAMMA_ENABLE
;
9450 switch (intel_crtc
->base
.cursor
->state
->crtc_w
) {
9452 cntl
|= CURSOR_MODE_64_ARGB_AX
;
9455 cntl
|= CURSOR_MODE_128_ARGB_AX
;
9458 cntl
|= CURSOR_MODE_256_ARGB_AX
;
9461 MISSING_CASE(intel_crtc
->base
.cursor
->state
->crtc_w
);
9464 cntl
|= pipe
<< 28; /* Connect to correct pipe */
9466 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
9467 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
9470 if (crtc
->cursor
->state
->rotation
== BIT(DRM_ROTATE_180
))
9471 cntl
|= CURSOR_ROTATE_180
;
9473 if (intel_crtc
->cursor_cntl
!= cntl
) {
9474 I915_WRITE(CURCNTR(pipe
), cntl
);
9475 POSTING_READ(CURCNTR(pipe
));
9476 intel_crtc
->cursor_cntl
= cntl
;
9479 /* and commit changes on next vblank */
9480 I915_WRITE(CURBASE(pipe
), base
);
9481 POSTING_READ(CURBASE(pipe
));
9483 intel_crtc
->cursor_base
= base
;
9486 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
9487 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
9490 struct drm_device
*dev
= crtc
->dev
;
9491 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9492 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9493 int pipe
= intel_crtc
->pipe
;
9494 int x
= crtc
->cursor_x
;
9495 int y
= crtc
->cursor_y
;
9496 u32 base
= 0, pos
= 0;
9499 base
= intel_crtc
->cursor_addr
;
9501 if (x
>= intel_crtc
->config
->pipe_src_w
)
9504 if (y
>= intel_crtc
->config
->pipe_src_h
)
9508 if (x
+ intel_crtc
->base
.cursor
->state
->crtc_w
<= 0)
9511 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
9514 pos
|= x
<< CURSOR_X_SHIFT
;
9517 if (y
+ intel_crtc
->base
.cursor
->state
->crtc_h
<= 0)
9520 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
9523 pos
|= y
<< CURSOR_Y_SHIFT
;
9525 if (base
== 0 && intel_crtc
->cursor_base
== 0)
9528 I915_WRITE(CURPOS(pipe
), pos
);
9530 /* ILK+ do this automagically */
9531 if (HAS_GMCH_DISPLAY(dev
) &&
9532 crtc
->cursor
->state
->rotation
== BIT(DRM_ROTATE_180
)) {
9533 base
+= (intel_crtc
->base
.cursor
->state
->crtc_h
*
9534 intel_crtc
->base
.cursor
->state
->crtc_w
- 1) * 4;
9537 if (IS_845G(dev
) || IS_I865G(dev
))
9538 i845_update_cursor(crtc
, base
);
9540 i9xx_update_cursor(crtc
, base
);
9543 static bool cursor_size_ok(struct drm_device
*dev
,
9544 uint32_t width
, uint32_t height
)
9546 if (width
== 0 || height
== 0)
9550 * 845g/865g are special in that they are only limited by
9551 * the width of their cursors, the height is arbitrary up to
9552 * the precision of the register. Everything else requires
9553 * square cursors, limited to a few power-of-two sizes.
9555 if (IS_845G(dev
) || IS_I865G(dev
)) {
9556 if ((width
& 63) != 0)
9559 if (width
> (IS_845G(dev
) ? 64 : 512))
9565 switch (width
| height
) {
9580 static void intel_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
9581 u16
*blue
, uint32_t start
, uint32_t size
)
9583 int end
= (start
+ size
> 256) ? 256 : start
+ size
, i
;
9584 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9586 for (i
= start
; i
< end
; i
++) {
9587 intel_crtc
->lut_r
[i
] = red
[i
] >> 8;
9588 intel_crtc
->lut_g
[i
] = green
[i
] >> 8;
9589 intel_crtc
->lut_b
[i
] = blue
[i
] >> 8;
9592 intel_crtc_load_lut(crtc
);
9595 /* VESA 640x480x72Hz mode to set on the pipe */
9596 static struct drm_display_mode load_detect_mode
= {
9597 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
9598 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
9601 struct drm_framebuffer
*
9602 __intel_framebuffer_create(struct drm_device
*dev
,
9603 struct drm_mode_fb_cmd2
*mode_cmd
,
9604 struct drm_i915_gem_object
*obj
)
9606 struct intel_framebuffer
*intel_fb
;
9609 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9611 drm_gem_object_unreference(&obj
->base
);
9612 return ERR_PTR(-ENOMEM
);
9615 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
9619 return &intel_fb
->base
;
9621 drm_gem_object_unreference(&obj
->base
);
9624 return ERR_PTR(ret
);
9627 static struct drm_framebuffer
*
9628 intel_framebuffer_create(struct drm_device
*dev
,
9629 struct drm_mode_fb_cmd2
*mode_cmd
,
9630 struct drm_i915_gem_object
*obj
)
9632 struct drm_framebuffer
*fb
;
9635 ret
= i915_mutex_lock_interruptible(dev
);
9637 return ERR_PTR(ret
);
9638 fb
= __intel_framebuffer_create(dev
, mode_cmd
, obj
);
9639 mutex_unlock(&dev
->struct_mutex
);
9645 intel_framebuffer_pitch_for_width(int width
, int bpp
)
9647 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
9648 return ALIGN(pitch
, 64);
9652 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
9654 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
9655 return PAGE_ALIGN(pitch
* mode
->vdisplay
);
9658 static struct drm_framebuffer
*
9659 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
9660 struct drm_display_mode
*mode
,
9663 struct drm_i915_gem_object
*obj
;
9664 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
9666 obj
= i915_gem_alloc_object(dev
,
9667 intel_framebuffer_size_for_mode(mode
, bpp
));
9669 return ERR_PTR(-ENOMEM
);
9671 mode_cmd
.width
= mode
->hdisplay
;
9672 mode_cmd
.height
= mode
->vdisplay
;
9673 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
9675 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
9677 return intel_framebuffer_create(dev
, &mode_cmd
, obj
);
9680 static struct drm_framebuffer
*
9681 mode_fits_in_fbdev(struct drm_device
*dev
,
9682 struct drm_display_mode
*mode
)
9684 #ifdef CONFIG_DRM_I915_FBDEV
9685 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9686 struct drm_i915_gem_object
*obj
;
9687 struct drm_framebuffer
*fb
;
9689 if (!dev_priv
->fbdev
)
9692 if (!dev_priv
->fbdev
->fb
)
9695 obj
= dev_priv
->fbdev
->fb
->obj
;
9698 fb
= &dev_priv
->fbdev
->fb
->base
;
9699 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
9700 fb
->bits_per_pixel
))
9703 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
9712 static int intel_modeset_setup_plane_state(struct drm_atomic_state
*state
,
9713 struct drm_crtc
*crtc
,
9714 struct drm_display_mode
*mode
,
9715 struct drm_framebuffer
*fb
,
9718 struct drm_plane_state
*plane_state
;
9719 int hdisplay
, vdisplay
;
9722 plane_state
= drm_atomic_get_plane_state(state
, crtc
->primary
);
9723 if (IS_ERR(plane_state
))
9724 return PTR_ERR(plane_state
);
9727 drm_crtc_get_hv_timing(mode
, &hdisplay
, &vdisplay
);
9729 hdisplay
= vdisplay
= 0;
9731 ret
= drm_atomic_set_crtc_for_plane(plane_state
, fb
? crtc
: NULL
);
9734 drm_atomic_set_fb_for_plane(plane_state
, fb
);
9735 plane_state
->crtc_x
= 0;
9736 plane_state
->crtc_y
= 0;
9737 plane_state
->crtc_w
= hdisplay
;
9738 plane_state
->crtc_h
= vdisplay
;
9739 plane_state
->src_x
= x
<< 16;
9740 plane_state
->src_y
= y
<< 16;
9741 plane_state
->src_w
= hdisplay
<< 16;
9742 plane_state
->src_h
= vdisplay
<< 16;
9747 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
9748 struct drm_display_mode
*mode
,
9749 struct intel_load_detect_pipe
*old
,
9750 struct drm_modeset_acquire_ctx
*ctx
)
9752 struct intel_crtc
*intel_crtc
;
9753 struct intel_encoder
*intel_encoder
=
9754 intel_attached_encoder(connector
);
9755 struct drm_crtc
*possible_crtc
;
9756 struct drm_encoder
*encoder
= &intel_encoder
->base
;
9757 struct drm_crtc
*crtc
= NULL
;
9758 struct drm_device
*dev
= encoder
->dev
;
9759 struct drm_framebuffer
*fb
;
9760 struct drm_mode_config
*config
= &dev
->mode_config
;
9761 struct drm_atomic_state
*state
= NULL
;
9762 struct drm_connector_state
*connector_state
;
9763 struct intel_crtc_state
*crtc_state
;
9766 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9767 connector
->base
.id
, connector
->name
,
9768 encoder
->base
.id
, encoder
->name
);
9771 ret
= drm_modeset_lock(&config
->connection_mutex
, ctx
);
9776 * Algorithm gets a little messy:
9778 * - if the connector already has an assigned crtc, use it (but make
9779 * sure it's on first)
9781 * - try to find the first unused crtc that can drive this connector,
9782 * and use that if we find one
9785 /* See if we already have a CRTC for this connector */
9786 if (encoder
->crtc
) {
9787 crtc
= encoder
->crtc
;
9789 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
9792 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
9796 old
->dpms_mode
= connector
->dpms
;
9797 old
->load_detect_temp
= false;
9799 /* Make sure the crtc and connector are running */
9800 if (connector
->dpms
!= DRM_MODE_DPMS_ON
)
9801 connector
->funcs
->dpms(connector
, DRM_MODE_DPMS_ON
);
9806 /* Find an unused one (if possible) */
9807 for_each_crtc(dev
, possible_crtc
) {
9809 if (!(encoder
->possible_crtcs
& (1 << i
)))
9811 if (possible_crtc
->state
->enable
)
9813 /* This can occur when applying the pipe A quirk on resume. */
9814 if (to_intel_crtc(possible_crtc
)->new_enabled
)
9817 crtc
= possible_crtc
;
9822 * If we didn't find an unused CRTC, don't use any.
9825 DRM_DEBUG_KMS("no pipe available for load-detect\n");
9829 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
9832 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
9835 intel_encoder
->new_crtc
= to_intel_crtc(crtc
);
9836 to_intel_connector(connector
)->new_encoder
= intel_encoder
;
9838 intel_crtc
= to_intel_crtc(crtc
);
9839 intel_crtc
->new_enabled
= true;
9840 old
->dpms_mode
= connector
->dpms
;
9841 old
->load_detect_temp
= true;
9842 old
->release_fb
= NULL
;
9844 state
= drm_atomic_state_alloc(dev
);
9848 state
->acquire_ctx
= ctx
;
9850 connector_state
= drm_atomic_get_connector_state(state
, connector
);
9851 if (IS_ERR(connector_state
)) {
9852 ret
= PTR_ERR(connector_state
);
9856 connector_state
->crtc
= crtc
;
9857 connector_state
->best_encoder
= &intel_encoder
->base
;
9859 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
9860 if (IS_ERR(crtc_state
)) {
9861 ret
= PTR_ERR(crtc_state
);
9865 crtc_state
->base
.enable
= true;
9868 mode
= &load_detect_mode
;
9870 /* We need a framebuffer large enough to accommodate all accesses
9871 * that the plane may generate whilst we perform load detection.
9872 * We can not rely on the fbcon either being present (we get called
9873 * during its initialisation to detect all boot displays, or it may
9874 * not even exist) or that it is large enough to satisfy the
9877 fb
= mode_fits_in_fbdev(dev
, mode
);
9879 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
9880 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
9881 old
->release_fb
= fb
;
9883 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
9885 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
9889 ret
= intel_modeset_setup_plane_state(state
, crtc
, mode
, fb
, 0, 0);
9893 if (intel_set_mode(crtc
, mode
, state
)) {
9894 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
9895 if (old
->release_fb
)
9896 old
->release_fb
->funcs
->destroy(old
->release_fb
);
9899 crtc
->primary
->crtc
= crtc
;
9901 /* let the connector get through one full cycle before testing */
9902 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
9906 intel_crtc
->new_enabled
= crtc
->state
->enable
;
9908 drm_atomic_state_free(state
);
9911 if (ret
== -EDEADLK
) {
9912 drm_modeset_backoff(ctx
);
9919 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
9920 struct intel_load_detect_pipe
*old
,
9921 struct drm_modeset_acquire_ctx
*ctx
)
9923 struct drm_device
*dev
= connector
->dev
;
9924 struct intel_encoder
*intel_encoder
=
9925 intel_attached_encoder(connector
);
9926 struct drm_encoder
*encoder
= &intel_encoder
->base
;
9927 struct drm_crtc
*crtc
= encoder
->crtc
;
9928 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9929 struct drm_atomic_state
*state
;
9930 struct drm_connector_state
*connector_state
;
9931 struct intel_crtc_state
*crtc_state
;
9934 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9935 connector
->base
.id
, connector
->name
,
9936 encoder
->base
.id
, encoder
->name
);
9938 if (old
->load_detect_temp
) {
9939 state
= drm_atomic_state_alloc(dev
);
9943 state
->acquire_ctx
= ctx
;
9945 connector_state
= drm_atomic_get_connector_state(state
, connector
);
9946 if (IS_ERR(connector_state
))
9949 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
9950 if (IS_ERR(crtc_state
))
9953 to_intel_connector(connector
)->new_encoder
= NULL
;
9954 intel_encoder
->new_crtc
= NULL
;
9955 intel_crtc
->new_enabled
= false;
9957 connector_state
->best_encoder
= NULL
;
9958 connector_state
->crtc
= NULL
;
9960 crtc_state
->base
.enable
= false;
9962 ret
= intel_modeset_setup_plane_state(state
, crtc
, NULL
, NULL
,
9967 intel_set_mode(crtc
, NULL
, state
);
9969 drm_atomic_state_free(state
);
9971 if (old
->release_fb
) {
9972 drm_framebuffer_unregister_private(old
->release_fb
);
9973 drm_framebuffer_unreference(old
->release_fb
);
9979 /* Switch crtc and encoder back off if necessary */
9980 if (old
->dpms_mode
!= DRM_MODE_DPMS_ON
)
9981 connector
->funcs
->dpms(connector
, old
->dpms_mode
);
9985 DRM_DEBUG_KMS("Couldn't release load detect pipe.\n");
9986 drm_atomic_state_free(state
);
9989 static int i9xx_pll_refclk(struct drm_device
*dev
,
9990 const struct intel_crtc_state
*pipe_config
)
9992 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9993 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
9995 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
9996 return dev_priv
->vbt
.lvds_ssc_freq
;
9997 else if (HAS_PCH_SPLIT(dev
))
9999 else if (!IS_GEN2(dev
))
10005 /* Returns the clock of the currently programmed mode of the given pipe. */
10006 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
10007 struct intel_crtc_state
*pipe_config
)
10009 struct drm_device
*dev
= crtc
->base
.dev
;
10010 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10011 int pipe
= pipe_config
->cpu_transcoder
;
10012 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
10014 intel_clock_t clock
;
10015 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
10017 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
10018 fp
= pipe_config
->dpll_hw_state
.fp0
;
10020 fp
= pipe_config
->dpll_hw_state
.fp1
;
10022 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
10023 if (IS_PINEVIEW(dev
)) {
10024 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
10025 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
10027 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
10028 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
10031 if (!IS_GEN2(dev
)) {
10032 if (IS_PINEVIEW(dev
))
10033 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
10034 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
10036 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
10037 DPLL_FPA01_P1_POST_DIV_SHIFT
);
10039 switch (dpll
& DPLL_MODE_MASK
) {
10040 case DPLLB_MODE_DAC_SERIAL
:
10041 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
10044 case DPLLB_MODE_LVDS
:
10045 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
10049 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10050 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
10054 if (IS_PINEVIEW(dev
))
10055 pineview_clock(refclk
, &clock
);
10057 i9xx_clock(refclk
, &clock
);
10059 u32 lvds
= IS_I830(dev
) ? 0 : I915_READ(LVDS
);
10060 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
10063 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
10064 DPLL_FPA01_P1_POST_DIV_SHIFT
);
10066 if (lvds
& LVDS_CLKB_POWER_UP
)
10071 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
10074 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
10075 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
10077 if (dpll
& PLL_P2_DIVIDE_BY_4
)
10083 i9xx_clock(refclk
, &clock
);
10087 * This value includes pixel_multiplier. We will use
10088 * port_clock to compute adjusted_mode.crtc_clock in the
10089 * encoder's get_config() function.
10091 pipe_config
->port_clock
= clock
.dot
;
10094 int intel_dotclock_calculate(int link_freq
,
10095 const struct intel_link_m_n
*m_n
)
10098 * The calculation for the data clock is:
10099 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10100 * But we want to avoid losing precison if possible, so:
10101 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10103 * and the link clock is simpler:
10104 * link_clock = (m * link_clock) / n
10110 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
10113 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
10114 struct intel_crtc_state
*pipe_config
)
10116 struct drm_device
*dev
= crtc
->base
.dev
;
10118 /* read out port_clock from the DPLL */
10119 i9xx_crtc_clock_get(crtc
, pipe_config
);
10122 * This value does not include pixel_multiplier.
10123 * We will check that port_clock and adjusted_mode.crtc_clock
10124 * agree once we know their relationship in the encoder's
10125 * get_config() function.
10127 pipe_config
->base
.adjusted_mode
.crtc_clock
=
10128 intel_dotclock_calculate(intel_fdi_link_freq(dev
) * 10000,
10129 &pipe_config
->fdi_m_n
);
10132 /** Returns the currently programmed mode of the given pipe. */
10133 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
10134 struct drm_crtc
*crtc
)
10136 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10137 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10138 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
10139 struct drm_display_mode
*mode
;
10140 struct intel_crtc_state pipe_config
;
10141 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
10142 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
10143 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
10144 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
10145 enum pipe pipe
= intel_crtc
->pipe
;
10147 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
10152 * Construct a pipe_config sufficient for getting the clock info
10153 * back out of crtc_clock_get.
10155 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
10156 * to use a real value here instead.
10158 pipe_config
.cpu_transcoder
= (enum transcoder
) pipe
;
10159 pipe_config
.pixel_multiplier
= 1;
10160 pipe_config
.dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
10161 pipe_config
.dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
10162 pipe_config
.dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
10163 i9xx_crtc_clock_get(intel_crtc
, &pipe_config
);
10165 mode
->clock
= pipe_config
.port_clock
/ pipe_config
.pixel_multiplier
;
10166 mode
->hdisplay
= (htot
& 0xffff) + 1;
10167 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
10168 mode
->hsync_start
= (hsync
& 0xffff) + 1;
10169 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
10170 mode
->vdisplay
= (vtot
& 0xffff) + 1;
10171 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
10172 mode
->vsync_start
= (vsync
& 0xffff) + 1;
10173 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
10175 drm_mode_set_name(mode
);
10180 static void intel_decrease_pllclock(struct drm_crtc
*crtc
)
10182 struct drm_device
*dev
= crtc
->dev
;
10183 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10184 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10186 if (!HAS_GMCH_DISPLAY(dev
))
10189 if (!dev_priv
->lvds_downclock_avail
)
10193 * Since this is called by a timer, we should never get here in
10196 if (!HAS_PIPE_CXSR(dev
) && intel_crtc
->lowfreq_avail
) {
10197 int pipe
= intel_crtc
->pipe
;
10198 int dpll_reg
= DPLL(pipe
);
10201 DRM_DEBUG_DRIVER("downclocking LVDS\n");
10203 assert_panel_unlocked(dev_priv
, pipe
);
10205 dpll
= I915_READ(dpll_reg
);
10206 dpll
|= DISPLAY_RATE_SELECT_FPA1
;
10207 I915_WRITE(dpll_reg
, dpll
);
10208 intel_wait_for_vblank(dev
, pipe
);
10209 dpll
= I915_READ(dpll_reg
);
10210 if (!(dpll
& DISPLAY_RATE_SELECT_FPA1
))
10211 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
10216 void intel_mark_busy(struct drm_device
*dev
)
10218 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10220 if (dev_priv
->mm
.busy
)
10223 intel_runtime_pm_get(dev_priv
);
10224 i915_update_gfx_val(dev_priv
);
10225 if (INTEL_INFO(dev
)->gen
>= 6)
10226 gen6_rps_busy(dev_priv
);
10227 dev_priv
->mm
.busy
= true;
10230 void intel_mark_idle(struct drm_device
*dev
)
10232 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10233 struct drm_crtc
*crtc
;
10235 if (!dev_priv
->mm
.busy
)
10238 dev_priv
->mm
.busy
= false;
10240 for_each_crtc(dev
, crtc
) {
10241 if (!crtc
->primary
->fb
)
10244 intel_decrease_pllclock(crtc
);
10247 if (INTEL_INFO(dev
)->gen
>= 6)
10248 gen6_rps_idle(dev
->dev_private
);
10250 intel_runtime_pm_put(dev_priv
);
10253 static void intel_crtc_set_state(struct intel_crtc
*crtc
,
10254 struct intel_crtc_state
*crtc_state
)
10256 kfree(crtc
->config
);
10257 crtc
->config
= crtc_state
;
10258 crtc
->base
.state
= &crtc_state
->base
;
10261 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
10263 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10264 struct drm_device
*dev
= crtc
->dev
;
10265 struct intel_unpin_work
*work
;
10267 spin_lock_irq(&dev
->event_lock
);
10268 work
= intel_crtc
->unpin_work
;
10269 intel_crtc
->unpin_work
= NULL
;
10270 spin_unlock_irq(&dev
->event_lock
);
10273 cancel_work_sync(&work
->work
);
10277 intel_crtc_set_state(intel_crtc
, NULL
);
10278 drm_crtc_cleanup(crtc
);
10283 static void intel_unpin_work_fn(struct work_struct
*__work
)
10285 struct intel_unpin_work
*work
=
10286 container_of(__work
, struct intel_unpin_work
, work
);
10287 struct drm_device
*dev
= work
->crtc
->dev
;
10288 enum pipe pipe
= to_intel_crtc(work
->crtc
)->pipe
;
10290 mutex_lock(&dev
->struct_mutex
);
10291 intel_unpin_fb_obj(work
->old_fb
, work
->crtc
->primary
->state
);
10292 drm_gem_object_unreference(&work
->pending_flip_obj
->base
);
10294 intel_fbc_update(dev
);
10296 if (work
->flip_queued_req
)
10297 i915_gem_request_assign(&work
->flip_queued_req
, NULL
);
10298 mutex_unlock(&dev
->struct_mutex
);
10300 intel_frontbuffer_flip_complete(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
10301 drm_framebuffer_unreference(work
->old_fb
);
10303 BUG_ON(atomic_read(&to_intel_crtc(work
->crtc
)->unpin_work_count
) == 0);
10304 atomic_dec(&to_intel_crtc(work
->crtc
)->unpin_work_count
);
10309 static void do_intel_finish_page_flip(struct drm_device
*dev
,
10310 struct drm_crtc
*crtc
)
10312 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10313 struct intel_unpin_work
*work
;
10314 unsigned long flags
;
10316 /* Ignore early vblank irqs */
10317 if (intel_crtc
== NULL
)
10321 * This is called both by irq handlers and the reset code (to complete
10322 * lost pageflips) so needs the full irqsave spinlocks.
10324 spin_lock_irqsave(&dev
->event_lock
, flags
);
10325 work
= intel_crtc
->unpin_work
;
10327 /* Ensure we don't miss a work->pending update ... */
10330 if (work
== NULL
|| atomic_read(&work
->pending
) < INTEL_FLIP_COMPLETE
) {
10331 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
10335 page_flip_completed(intel_crtc
);
10337 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
10340 void intel_finish_page_flip(struct drm_device
*dev
, int pipe
)
10342 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10343 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
10345 do_intel_finish_page_flip(dev
, crtc
);
10348 void intel_finish_page_flip_plane(struct drm_device
*dev
, int plane
)
10350 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10351 struct drm_crtc
*crtc
= dev_priv
->plane_to_crtc_mapping
[plane
];
10353 do_intel_finish_page_flip(dev
, crtc
);
10356 /* Is 'a' after or equal to 'b'? */
10357 static bool g4x_flip_count_after_eq(u32 a
, u32 b
)
10359 return !((a
- b
) & 0x80000000);
10362 static bool page_flip_finished(struct intel_crtc
*crtc
)
10364 struct drm_device
*dev
= crtc
->base
.dev
;
10365 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10367 if (i915_reset_in_progress(&dev_priv
->gpu_error
) ||
10368 crtc
->reset_counter
!= atomic_read(&dev_priv
->gpu_error
.reset_counter
))
10372 * The relevant registers doen't exist on pre-ctg.
10373 * As the flip done interrupt doesn't trigger for mmio
10374 * flips on gmch platforms, a flip count check isn't
10375 * really needed there. But since ctg has the registers,
10376 * include it in the check anyway.
10378 if (INTEL_INFO(dev
)->gen
< 5 && !IS_G4X(dev
))
10382 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
10383 * used the same base address. In that case the mmio flip might
10384 * have completed, but the CS hasn't even executed the flip yet.
10386 * A flip count check isn't enough as the CS might have updated
10387 * the base address just after start of vblank, but before we
10388 * managed to process the interrupt. This means we'd complete the
10389 * CS flip too soon.
10391 * Combining both checks should get us a good enough result. It may
10392 * still happen that the CS flip has been executed, but has not
10393 * yet actually completed. But in case the base address is the same
10394 * anyway, we don't really care.
10396 return (I915_READ(DSPSURFLIVE(crtc
->plane
)) & ~0xfff) ==
10397 crtc
->unpin_work
->gtt_offset
&&
10398 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc
->pipe
)),
10399 crtc
->unpin_work
->flip_count
);
10402 void intel_prepare_page_flip(struct drm_device
*dev
, int plane
)
10404 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10405 struct intel_crtc
*intel_crtc
=
10406 to_intel_crtc(dev_priv
->plane_to_crtc_mapping
[plane
]);
10407 unsigned long flags
;
10411 * This is called both by irq handlers and the reset code (to complete
10412 * lost pageflips) so needs the full irqsave spinlocks.
10414 * NB: An MMIO update of the plane base pointer will also
10415 * generate a page-flip completion irq, i.e. every modeset
10416 * is also accompanied by a spurious intel_prepare_page_flip().
10418 spin_lock_irqsave(&dev
->event_lock
, flags
);
10419 if (intel_crtc
->unpin_work
&& page_flip_finished(intel_crtc
))
10420 atomic_inc_not_zero(&intel_crtc
->unpin_work
->pending
);
10421 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
10424 static inline void intel_mark_page_flip_active(struct intel_crtc
*intel_crtc
)
10426 /* Ensure that the work item is consistent when activating it ... */
10428 atomic_set(&intel_crtc
->unpin_work
->pending
, INTEL_FLIP_PENDING
);
10429 /* and that it is marked active as soon as the irq could fire. */
10433 static int intel_gen2_queue_flip(struct drm_device
*dev
,
10434 struct drm_crtc
*crtc
,
10435 struct drm_framebuffer
*fb
,
10436 struct drm_i915_gem_object
*obj
,
10437 struct intel_engine_cs
*ring
,
10440 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10444 ret
= intel_ring_begin(ring
, 6);
10448 /* Can't queue multiple flips, so wait for the previous
10449 * one to finish before executing the next.
10451 if (intel_crtc
->plane
)
10452 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
10454 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
10455 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
10456 intel_ring_emit(ring
, MI_NOOP
);
10457 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
10458 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
10459 intel_ring_emit(ring
, fb
->pitches
[0]);
10460 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
10461 intel_ring_emit(ring
, 0); /* aux display base address, unused */
10463 intel_mark_page_flip_active(intel_crtc
);
10464 __intel_ring_advance(ring
);
10468 static int intel_gen3_queue_flip(struct drm_device
*dev
,
10469 struct drm_crtc
*crtc
,
10470 struct drm_framebuffer
*fb
,
10471 struct drm_i915_gem_object
*obj
,
10472 struct intel_engine_cs
*ring
,
10475 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10479 ret
= intel_ring_begin(ring
, 6);
10483 if (intel_crtc
->plane
)
10484 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
10486 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
10487 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
10488 intel_ring_emit(ring
, MI_NOOP
);
10489 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
|
10490 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
10491 intel_ring_emit(ring
, fb
->pitches
[0]);
10492 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
10493 intel_ring_emit(ring
, MI_NOOP
);
10495 intel_mark_page_flip_active(intel_crtc
);
10496 __intel_ring_advance(ring
);
10500 static int intel_gen4_queue_flip(struct drm_device
*dev
,
10501 struct drm_crtc
*crtc
,
10502 struct drm_framebuffer
*fb
,
10503 struct drm_i915_gem_object
*obj
,
10504 struct intel_engine_cs
*ring
,
10507 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10508 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10509 uint32_t pf
, pipesrc
;
10512 ret
= intel_ring_begin(ring
, 4);
10516 /* i965+ uses the linear or tiled offsets from the
10517 * Display Registers (which do not change across a page-flip)
10518 * so we need only reprogram the base address.
10520 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
10521 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
10522 intel_ring_emit(ring
, fb
->pitches
[0]);
10523 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
|
10526 /* XXX Enabling the panel-fitter across page-flip is so far
10527 * untested on non-native modes, so ignore it for now.
10528 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
10531 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
10532 intel_ring_emit(ring
, pf
| pipesrc
);
10534 intel_mark_page_flip_active(intel_crtc
);
10535 __intel_ring_advance(ring
);
10539 static int intel_gen6_queue_flip(struct drm_device
*dev
,
10540 struct drm_crtc
*crtc
,
10541 struct drm_framebuffer
*fb
,
10542 struct drm_i915_gem_object
*obj
,
10543 struct intel_engine_cs
*ring
,
10546 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10547 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10548 uint32_t pf
, pipesrc
;
10551 ret
= intel_ring_begin(ring
, 4);
10555 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
10556 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
10557 intel_ring_emit(ring
, fb
->pitches
[0] | obj
->tiling_mode
);
10558 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
10560 /* Contrary to the suggestions in the documentation,
10561 * "Enable Panel Fitter" does not seem to be required when page
10562 * flipping with a non-native mode, and worse causes a normal
10564 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
10567 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
10568 intel_ring_emit(ring
, pf
| pipesrc
);
10570 intel_mark_page_flip_active(intel_crtc
);
10571 __intel_ring_advance(ring
);
10575 static int intel_gen7_queue_flip(struct drm_device
*dev
,
10576 struct drm_crtc
*crtc
,
10577 struct drm_framebuffer
*fb
,
10578 struct drm_i915_gem_object
*obj
,
10579 struct intel_engine_cs
*ring
,
10582 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10583 uint32_t plane_bit
= 0;
10586 switch (intel_crtc
->plane
) {
10588 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
10591 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
10594 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
10597 WARN_ONCE(1, "unknown plane in flip command\n");
10602 if (ring
->id
== RCS
) {
10605 * On Gen 8, SRM is now taking an extra dword to accommodate
10606 * 48bits addresses, and we need a NOOP for the batch size to
10614 * BSpec MI_DISPLAY_FLIP for IVB:
10615 * "The full packet must be contained within the same cache line."
10617 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
10618 * cacheline, if we ever start emitting more commands before
10619 * the MI_DISPLAY_FLIP we may need to first emit everything else,
10620 * then do the cacheline alignment, and finally emit the
10623 ret
= intel_ring_cacheline_align(ring
);
10627 ret
= intel_ring_begin(ring
, len
);
10631 /* Unmask the flip-done completion message. Note that the bspec says that
10632 * we should do this for both the BCS and RCS, and that we must not unmask
10633 * more than one flip event at any time (or ensure that one flip message
10634 * can be sent by waiting for flip-done prior to queueing new flips).
10635 * Experimentation says that BCS works despite DERRMR masking all
10636 * flip-done completion events and that unmasking all planes at once
10637 * for the RCS also doesn't appear to drop events. Setting the DERRMR
10638 * to zero does lead to lockups within MI_DISPLAY_FLIP.
10640 if (ring
->id
== RCS
) {
10641 intel_ring_emit(ring
, MI_LOAD_REGISTER_IMM(1));
10642 intel_ring_emit(ring
, DERRMR
);
10643 intel_ring_emit(ring
, ~(DERRMR_PIPEA_PRI_FLIP_DONE
|
10644 DERRMR_PIPEB_PRI_FLIP_DONE
|
10645 DERRMR_PIPEC_PRI_FLIP_DONE
));
10647 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM_GEN8(1) |
10648 MI_SRM_LRM_GLOBAL_GTT
);
10650 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM(1) |
10651 MI_SRM_LRM_GLOBAL_GTT
);
10652 intel_ring_emit(ring
, DERRMR
);
10653 intel_ring_emit(ring
, ring
->scratch
.gtt_offset
+ 256);
10654 if (IS_GEN8(dev
)) {
10655 intel_ring_emit(ring
, 0);
10656 intel_ring_emit(ring
, MI_NOOP
);
10660 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
| plane_bit
);
10661 intel_ring_emit(ring
, (fb
->pitches
[0] | obj
->tiling_mode
));
10662 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
10663 intel_ring_emit(ring
, (MI_NOOP
));
10665 intel_mark_page_flip_active(intel_crtc
);
10666 __intel_ring_advance(ring
);
10670 static bool use_mmio_flip(struct intel_engine_cs
*ring
,
10671 struct drm_i915_gem_object
*obj
)
10674 * This is not being used for older platforms, because
10675 * non-availability of flip done interrupt forces us to use
10676 * CS flips. Older platforms derive flip done using some clever
10677 * tricks involving the flip_pending status bits and vblank irqs.
10678 * So using MMIO flips there would disrupt this mechanism.
10684 if (INTEL_INFO(ring
->dev
)->gen
< 5)
10687 if (i915
.use_mmio_flip
< 0)
10689 else if (i915
.use_mmio_flip
> 0)
10691 else if (i915
.enable_execlists
)
10694 return ring
!= i915_gem_request_get_ring(obj
->last_read_req
);
10697 static void skl_do_mmio_flip(struct intel_crtc
*intel_crtc
)
10699 struct drm_device
*dev
= intel_crtc
->base
.dev
;
10700 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10701 struct drm_framebuffer
*fb
= intel_crtc
->base
.primary
->fb
;
10702 const enum pipe pipe
= intel_crtc
->pipe
;
10705 ctl
= I915_READ(PLANE_CTL(pipe
, 0));
10706 ctl
&= ~PLANE_CTL_TILED_MASK
;
10707 switch (fb
->modifier
[0]) {
10708 case DRM_FORMAT_MOD_NONE
:
10710 case I915_FORMAT_MOD_X_TILED
:
10711 ctl
|= PLANE_CTL_TILED_X
;
10713 case I915_FORMAT_MOD_Y_TILED
:
10714 ctl
|= PLANE_CTL_TILED_Y
;
10716 case I915_FORMAT_MOD_Yf_TILED
:
10717 ctl
|= PLANE_CTL_TILED_YF
;
10720 MISSING_CASE(fb
->modifier
[0]);
10724 * The stride is either expressed as a multiple of 64 bytes chunks for
10725 * linear buffers or in number of tiles for tiled buffers.
10727 stride
= fb
->pitches
[0] /
10728 intel_fb_stride_alignment(dev
, fb
->modifier
[0],
10732 * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on
10733 * PLANE_SURF updates, the update is then guaranteed to be atomic.
10735 I915_WRITE(PLANE_CTL(pipe
, 0), ctl
);
10736 I915_WRITE(PLANE_STRIDE(pipe
, 0), stride
);
10738 I915_WRITE(PLANE_SURF(pipe
, 0), intel_crtc
->unpin_work
->gtt_offset
);
10739 POSTING_READ(PLANE_SURF(pipe
, 0));
10742 static void ilk_do_mmio_flip(struct intel_crtc
*intel_crtc
)
10744 struct drm_device
*dev
= intel_crtc
->base
.dev
;
10745 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10746 struct intel_framebuffer
*intel_fb
=
10747 to_intel_framebuffer(intel_crtc
->base
.primary
->fb
);
10748 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
10752 reg
= DSPCNTR(intel_crtc
->plane
);
10753 dspcntr
= I915_READ(reg
);
10755 if (obj
->tiling_mode
!= I915_TILING_NONE
)
10756 dspcntr
|= DISPPLANE_TILED
;
10758 dspcntr
&= ~DISPPLANE_TILED
;
10760 I915_WRITE(reg
, dspcntr
);
10762 I915_WRITE(DSPSURF(intel_crtc
->plane
),
10763 intel_crtc
->unpin_work
->gtt_offset
);
10764 POSTING_READ(DSPSURF(intel_crtc
->plane
));
10769 * XXX: This is the temporary way to update the plane registers until we get
10770 * around to using the usual plane update functions for MMIO flips
10772 static void intel_do_mmio_flip(struct intel_crtc
*intel_crtc
)
10774 struct drm_device
*dev
= intel_crtc
->base
.dev
;
10775 bool atomic_update
;
10776 u32 start_vbl_count
;
10778 intel_mark_page_flip_active(intel_crtc
);
10780 atomic_update
= intel_pipe_update_start(intel_crtc
, &start_vbl_count
);
10782 if (INTEL_INFO(dev
)->gen
>= 9)
10783 skl_do_mmio_flip(intel_crtc
);
10785 /* use_mmio_flip() retricts MMIO flips to ilk+ */
10786 ilk_do_mmio_flip(intel_crtc
);
10789 intel_pipe_update_end(intel_crtc
, start_vbl_count
);
10792 static void intel_mmio_flip_work_func(struct work_struct
*work
)
10794 struct intel_crtc
*crtc
=
10795 container_of(work
, struct intel_crtc
, mmio_flip
.work
);
10796 struct intel_mmio_flip
*mmio_flip
;
10798 mmio_flip
= &crtc
->mmio_flip
;
10799 if (mmio_flip
->req
)
10800 WARN_ON(__i915_wait_request(mmio_flip
->req
,
10801 crtc
->reset_counter
,
10802 false, NULL
, NULL
) != 0);
10804 intel_do_mmio_flip(crtc
);
10805 if (mmio_flip
->req
) {
10806 mutex_lock(&crtc
->base
.dev
->struct_mutex
);
10807 i915_gem_request_assign(&mmio_flip
->req
, NULL
);
10808 mutex_unlock(&crtc
->base
.dev
->struct_mutex
);
10812 static int intel_queue_mmio_flip(struct drm_device
*dev
,
10813 struct drm_crtc
*crtc
,
10814 struct drm_framebuffer
*fb
,
10815 struct drm_i915_gem_object
*obj
,
10816 struct intel_engine_cs
*ring
,
10819 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10821 i915_gem_request_assign(&intel_crtc
->mmio_flip
.req
,
10822 obj
->last_write_req
);
10824 schedule_work(&intel_crtc
->mmio_flip
.work
);
10829 static int intel_default_queue_flip(struct drm_device
*dev
,
10830 struct drm_crtc
*crtc
,
10831 struct drm_framebuffer
*fb
,
10832 struct drm_i915_gem_object
*obj
,
10833 struct intel_engine_cs
*ring
,
10839 static bool __intel_pageflip_stall_check(struct drm_device
*dev
,
10840 struct drm_crtc
*crtc
)
10842 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10843 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10844 struct intel_unpin_work
*work
= intel_crtc
->unpin_work
;
10847 if (atomic_read(&work
->pending
) >= INTEL_FLIP_COMPLETE
)
10850 if (!work
->enable_stall_check
)
10853 if (work
->flip_ready_vblank
== 0) {
10854 if (work
->flip_queued_req
&&
10855 !i915_gem_request_completed(work
->flip_queued_req
, true))
10858 work
->flip_ready_vblank
= drm_crtc_vblank_count(crtc
);
10861 if (drm_crtc_vblank_count(crtc
) - work
->flip_ready_vblank
< 3)
10864 /* Potential stall - if we see that the flip has happened,
10865 * assume a missed interrupt. */
10866 if (INTEL_INFO(dev
)->gen
>= 4)
10867 addr
= I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc
->plane
)));
10869 addr
= I915_READ(DSPADDR(intel_crtc
->plane
));
10871 /* There is a potential issue here with a false positive after a flip
10872 * to the same address. We could address this by checking for a
10873 * non-incrementing frame counter.
10875 return addr
== work
->gtt_offset
;
10878 void intel_check_page_flip(struct drm_device
*dev
, int pipe
)
10880 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10881 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
10882 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10883 struct intel_unpin_work
*work
;
10885 WARN_ON(!in_interrupt());
10890 spin_lock(&dev
->event_lock
);
10891 work
= intel_crtc
->unpin_work
;
10892 if (work
!= NULL
&& __intel_pageflip_stall_check(dev
, crtc
)) {
10893 WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n",
10894 work
->flip_queued_vblank
, drm_vblank_count(dev
, pipe
));
10895 page_flip_completed(intel_crtc
);
10898 if (work
!= NULL
&&
10899 drm_vblank_count(dev
, pipe
) - work
->flip_queued_vblank
> 1)
10900 intel_queue_rps_boost_for_request(dev
, work
->flip_queued_req
);
10901 spin_unlock(&dev
->event_lock
);
10904 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
10905 struct drm_framebuffer
*fb
,
10906 struct drm_pending_vblank_event
*event
,
10907 uint32_t page_flip_flags
)
10909 struct drm_device
*dev
= crtc
->dev
;
10910 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10911 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
10912 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
10913 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10914 struct drm_plane
*primary
= crtc
->primary
;
10915 enum pipe pipe
= intel_crtc
->pipe
;
10916 struct intel_unpin_work
*work
;
10917 struct intel_engine_cs
*ring
;
10922 * drm_mode_page_flip_ioctl() should already catch this, but double
10923 * check to be safe. In the future we may enable pageflipping from
10924 * a disabled primary plane.
10926 if (WARN_ON(intel_fb_obj(old_fb
) == NULL
))
10929 /* Can't change pixel format via MI display flips. */
10930 if (fb
->pixel_format
!= crtc
->primary
->fb
->pixel_format
)
10934 * TILEOFF/LINOFF registers can't be changed via MI display flips.
10935 * Note that pitch changes could also affect these register.
10937 if (INTEL_INFO(dev
)->gen
> 3 &&
10938 (fb
->offsets
[0] != crtc
->primary
->fb
->offsets
[0] ||
10939 fb
->pitches
[0] != crtc
->primary
->fb
->pitches
[0]))
10942 if (i915_terminally_wedged(&dev_priv
->gpu_error
))
10945 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
10949 work
->event
= event
;
10951 work
->old_fb
= old_fb
;
10952 INIT_WORK(&work
->work
, intel_unpin_work_fn
);
10954 ret
= drm_crtc_vblank_get(crtc
);
10958 /* We borrow the event spin lock for protecting unpin_work */
10959 spin_lock_irq(&dev
->event_lock
);
10960 if (intel_crtc
->unpin_work
) {
10961 /* Before declaring the flip queue wedged, check if
10962 * the hardware completed the operation behind our backs.
10964 if (__intel_pageflip_stall_check(dev
, crtc
)) {
10965 DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
10966 page_flip_completed(intel_crtc
);
10968 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
10969 spin_unlock_irq(&dev
->event_lock
);
10971 drm_crtc_vblank_put(crtc
);
10976 intel_crtc
->unpin_work
= work
;
10977 spin_unlock_irq(&dev
->event_lock
);
10979 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
10980 flush_workqueue(dev_priv
->wq
);
10982 /* Reference the objects for the scheduled work. */
10983 drm_framebuffer_reference(work
->old_fb
);
10984 drm_gem_object_reference(&obj
->base
);
10986 crtc
->primary
->fb
= fb
;
10987 update_state_fb(crtc
->primary
);
10989 work
->pending_flip_obj
= obj
;
10991 ret
= i915_mutex_lock_interruptible(dev
);
10995 atomic_inc(&intel_crtc
->unpin_work_count
);
10996 intel_crtc
->reset_counter
= atomic_read(&dev_priv
->gpu_error
.reset_counter
);
10998 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
10999 work
->flip_count
= I915_READ(PIPE_FLIPCOUNT_GM45(pipe
)) + 1;
11001 if (IS_VALLEYVIEW(dev
)) {
11002 ring
= &dev_priv
->ring
[BCS
];
11003 if (obj
->tiling_mode
!= intel_fb_obj(work
->old_fb
)->tiling_mode
)
11004 /* vlv: DISPLAY_FLIP fails to change tiling */
11006 } else if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
)) {
11007 ring
= &dev_priv
->ring
[BCS
];
11008 } else if (INTEL_INFO(dev
)->gen
>= 7) {
11009 ring
= i915_gem_request_get_ring(obj
->last_read_req
);
11010 if (ring
== NULL
|| ring
->id
!= RCS
)
11011 ring
= &dev_priv
->ring
[BCS
];
11013 ring
= &dev_priv
->ring
[RCS
];
11016 mmio_flip
= use_mmio_flip(ring
, obj
);
11018 /* When using CS flips, we want to emit semaphores between rings.
11019 * However, when using mmio flips we will create a task to do the
11020 * synchronisation, so all we want here is to pin the framebuffer
11021 * into the display plane and skip any waits.
11023 ret
= intel_pin_and_fence_fb_obj(crtc
->primary
, fb
,
11024 crtc
->primary
->state
,
11025 mmio_flip
? i915_gem_request_get_ring(obj
->last_read_req
) : ring
);
11027 goto cleanup_pending
;
11029 work
->gtt_offset
= intel_plane_obj_offset(to_intel_plane(primary
), obj
)
11030 + intel_crtc
->dspaddr_offset
;
11033 ret
= intel_queue_mmio_flip(dev
, crtc
, fb
, obj
, ring
,
11036 goto cleanup_unpin
;
11038 i915_gem_request_assign(&work
->flip_queued_req
,
11039 obj
->last_write_req
);
11041 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
, ring
,
11044 goto cleanup_unpin
;
11046 i915_gem_request_assign(&work
->flip_queued_req
,
11047 intel_ring_get_request(ring
));
11050 work
->flip_queued_vblank
= drm_crtc_vblank_count(crtc
);
11051 work
->enable_stall_check
= true;
11053 i915_gem_track_fb(intel_fb_obj(work
->old_fb
), obj
,
11054 INTEL_FRONTBUFFER_PRIMARY(pipe
));
11056 intel_fbc_disable(dev
);
11057 intel_frontbuffer_flip_prepare(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
11058 mutex_unlock(&dev
->struct_mutex
);
11060 trace_i915_flip_request(intel_crtc
->plane
, obj
);
11065 intel_unpin_fb_obj(fb
, crtc
->primary
->state
);
11067 atomic_dec(&intel_crtc
->unpin_work_count
);
11068 mutex_unlock(&dev
->struct_mutex
);
11070 crtc
->primary
->fb
= old_fb
;
11071 update_state_fb(crtc
->primary
);
11073 drm_gem_object_unreference_unlocked(&obj
->base
);
11074 drm_framebuffer_unreference(work
->old_fb
);
11076 spin_lock_irq(&dev
->event_lock
);
11077 intel_crtc
->unpin_work
= NULL
;
11078 spin_unlock_irq(&dev
->event_lock
);
11080 drm_crtc_vblank_put(crtc
);
11086 ret
= intel_plane_restore(primary
);
11087 if (ret
== 0 && event
) {
11088 spin_lock_irq(&dev
->event_lock
);
11089 drm_send_vblank_event(dev
, pipe
, event
);
11090 spin_unlock_irq(&dev
->event_lock
);
11096 static const struct drm_crtc_helper_funcs intel_helper_funcs
= {
11097 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
11098 .load_lut
= intel_crtc_load_lut
,
11099 .atomic_begin
= intel_begin_crtc_commit
,
11100 .atomic_flush
= intel_finish_crtc_commit
,
11104 * intel_modeset_update_staged_output_state
11106 * Updates the staged output configuration state, e.g. after we've read out the
11107 * current hw state.
11109 static void intel_modeset_update_staged_output_state(struct drm_device
*dev
)
11111 struct intel_crtc
*crtc
;
11112 struct intel_encoder
*encoder
;
11113 struct intel_connector
*connector
;
11115 for_each_intel_connector(dev
, connector
) {
11116 connector
->new_encoder
=
11117 to_intel_encoder(connector
->base
.encoder
);
11120 for_each_intel_encoder(dev
, encoder
) {
11121 encoder
->new_crtc
=
11122 to_intel_crtc(encoder
->base
.crtc
);
11125 for_each_intel_crtc(dev
, crtc
) {
11126 crtc
->new_enabled
= crtc
->base
.state
->enable
;
11130 /* Transitional helper to copy current connector/encoder state to
11131 * connector->state. This is needed so that code that is partially
11132 * converted to atomic does the right thing.
11134 static void intel_modeset_update_connector_atomic_state(struct drm_device
*dev
)
11136 struct intel_connector
*connector
;
11138 for_each_intel_connector(dev
, connector
) {
11139 if (connector
->base
.encoder
) {
11140 connector
->base
.state
->best_encoder
=
11141 connector
->base
.encoder
;
11142 connector
->base
.state
->crtc
=
11143 connector
->base
.encoder
->crtc
;
11145 connector
->base
.state
->best_encoder
= NULL
;
11146 connector
->base
.state
->crtc
= NULL
;
11152 * intel_modeset_commit_output_state
11154 * This function copies the stage display pipe configuration to the real one.
11156 static void intel_modeset_commit_output_state(struct drm_device
*dev
)
11158 struct intel_crtc
*crtc
;
11159 struct intel_encoder
*encoder
;
11160 struct intel_connector
*connector
;
11162 for_each_intel_connector(dev
, connector
) {
11163 connector
->base
.encoder
= &connector
->new_encoder
->base
;
11166 for_each_intel_encoder(dev
, encoder
) {
11167 encoder
->base
.crtc
= &encoder
->new_crtc
->base
;
11170 for_each_intel_crtc(dev
, crtc
) {
11171 crtc
->base
.state
->enable
= crtc
->new_enabled
;
11172 crtc
->base
.enabled
= crtc
->new_enabled
;
11175 intel_modeset_update_connector_atomic_state(dev
);
11179 connected_sink_compute_bpp(struct intel_connector
*connector
,
11180 struct intel_crtc_state
*pipe_config
)
11182 int bpp
= pipe_config
->pipe_bpp
;
11184 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
11185 connector
->base
.base
.id
,
11186 connector
->base
.name
);
11188 /* Don't use an invalid EDID bpc value */
11189 if (connector
->base
.display_info
.bpc
&&
11190 connector
->base
.display_info
.bpc
* 3 < bpp
) {
11191 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
11192 bpp
, connector
->base
.display_info
.bpc
*3);
11193 pipe_config
->pipe_bpp
= connector
->base
.display_info
.bpc
*3;
11196 /* Clamp bpp to 8 on screens without EDID 1.4 */
11197 if (connector
->base
.display_info
.bpc
== 0 && bpp
> 24) {
11198 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
11200 pipe_config
->pipe_bpp
= 24;
11205 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
11206 struct intel_crtc_state
*pipe_config
)
11208 struct drm_device
*dev
= crtc
->base
.dev
;
11209 struct drm_atomic_state
*state
;
11210 struct drm_connector
*connector
;
11211 struct drm_connector_state
*connector_state
;
11214 if ((IS_G4X(dev
) || IS_VALLEYVIEW(dev
)))
11216 else if (INTEL_INFO(dev
)->gen
>= 5)
11222 pipe_config
->pipe_bpp
= bpp
;
11224 state
= pipe_config
->base
.state
;
11226 /* Clamp display bpp to EDID value */
11227 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11228 if (connector_state
->crtc
!= &crtc
->base
)
11231 connected_sink_compute_bpp(to_intel_connector(connector
),
11238 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
11240 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11241 "type: 0x%x flags: 0x%x\n",
11243 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
11244 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
11245 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
11246 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
11249 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
11250 struct intel_crtc_state
*pipe_config
,
11251 const char *context
)
11253 struct drm_device
*dev
= crtc
->base
.dev
;
11254 struct drm_plane
*plane
;
11255 struct intel_plane
*intel_plane
;
11256 struct intel_plane_state
*state
;
11257 struct drm_framebuffer
*fb
;
11259 DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc
->base
.base
.id
,
11260 context
, pipe_config
, pipe_name(crtc
->pipe
));
11262 DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config
->cpu_transcoder
));
11263 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
11264 pipe_config
->pipe_bpp
, pipe_config
->dither
);
11265 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11266 pipe_config
->has_pch_encoder
,
11267 pipe_config
->fdi_lanes
,
11268 pipe_config
->fdi_m_n
.gmch_m
, pipe_config
->fdi_m_n
.gmch_n
,
11269 pipe_config
->fdi_m_n
.link_m
, pipe_config
->fdi_m_n
.link_n
,
11270 pipe_config
->fdi_m_n
.tu
);
11271 DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11272 pipe_config
->has_dp_encoder
,
11273 pipe_config
->dp_m_n
.gmch_m
, pipe_config
->dp_m_n
.gmch_n
,
11274 pipe_config
->dp_m_n
.link_m
, pipe_config
->dp_m_n
.link_n
,
11275 pipe_config
->dp_m_n
.tu
);
11277 DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
11278 pipe_config
->has_dp_encoder
,
11279 pipe_config
->dp_m2_n2
.gmch_m
,
11280 pipe_config
->dp_m2_n2
.gmch_n
,
11281 pipe_config
->dp_m2_n2
.link_m
,
11282 pipe_config
->dp_m2_n2
.link_n
,
11283 pipe_config
->dp_m2_n2
.tu
);
11285 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
11286 pipe_config
->has_audio
,
11287 pipe_config
->has_infoframe
);
11289 DRM_DEBUG_KMS("requested mode:\n");
11290 drm_mode_debug_printmodeline(&pipe_config
->base
.mode
);
11291 DRM_DEBUG_KMS("adjusted mode:\n");
11292 drm_mode_debug_printmodeline(&pipe_config
->base
.adjusted_mode
);
11293 intel_dump_crtc_timings(&pipe_config
->base
.adjusted_mode
);
11294 DRM_DEBUG_KMS("port clock: %d\n", pipe_config
->port_clock
);
11295 DRM_DEBUG_KMS("pipe src size: %dx%d\n",
11296 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
11297 DRM_DEBUG_KMS("num_scalers: %d\n", crtc
->num_scalers
);
11298 DRM_DEBUG_KMS("scaler_users: 0x%x\n", pipe_config
->scaler_state
.scaler_users
);
11299 DRM_DEBUG_KMS("scaler id: %d\n", pipe_config
->scaler_state
.scaler_id
);
11300 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
11301 pipe_config
->gmch_pfit
.control
,
11302 pipe_config
->gmch_pfit
.pgm_ratios
,
11303 pipe_config
->gmch_pfit
.lvds_border_bits
);
11304 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
11305 pipe_config
->pch_pfit
.pos
,
11306 pipe_config
->pch_pfit
.size
,
11307 pipe_config
->pch_pfit
.enabled
? "enabled" : "disabled");
11308 DRM_DEBUG_KMS("ips: %i\n", pipe_config
->ips_enabled
);
11309 DRM_DEBUG_KMS("double wide: %i\n", pipe_config
->double_wide
);
11311 DRM_DEBUG_KMS("planes on this crtc\n");
11312 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
11313 intel_plane
= to_intel_plane(plane
);
11314 if (intel_plane
->pipe
!= crtc
->pipe
)
11317 state
= to_intel_plane_state(plane
->state
);
11318 fb
= state
->base
.fb
;
11320 DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d "
11321 "disabled, scaler_id = %d\n",
11322 plane
->type
== DRM_PLANE_TYPE_CURSOR
? "CURSOR" : "STANDARD",
11323 plane
->base
.id
, intel_plane
->pipe
,
11324 (crtc
->base
.primary
== plane
) ? 0 : intel_plane
->plane
+ 1,
11325 drm_plane_index(plane
), state
->scaler_id
);
11329 DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled",
11330 plane
->type
== DRM_PLANE_TYPE_CURSOR
? "CURSOR" : "STANDARD",
11331 plane
->base
.id
, intel_plane
->pipe
,
11332 crtc
->base
.primary
== plane
? 0 : intel_plane
->plane
+ 1,
11333 drm_plane_index(plane
));
11334 DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x",
11335 fb
->base
.id
, fb
->width
, fb
->height
, fb
->pixel_format
);
11336 DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n",
11338 state
->src
.x1
>> 16, state
->src
.y1
>> 16,
11339 drm_rect_width(&state
->src
) >> 16,
11340 drm_rect_height(&state
->src
) >> 16,
11341 state
->dst
.x1
, state
->dst
.y1
,
11342 drm_rect_width(&state
->dst
), drm_rect_height(&state
->dst
));
11346 static bool encoders_cloneable(const struct intel_encoder
*a
,
11347 const struct intel_encoder
*b
)
11349 /* masks could be asymmetric, so check both ways */
11350 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
11351 b
->cloneable
& (1 << a
->type
));
11354 static bool check_single_encoder_cloning(struct drm_atomic_state
*state
,
11355 struct intel_crtc
*crtc
,
11356 struct intel_encoder
*encoder
)
11358 struct intel_encoder
*source_encoder
;
11359 struct drm_connector
*connector
;
11360 struct drm_connector_state
*connector_state
;
11363 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11364 if (connector_state
->crtc
!= &crtc
->base
)
11368 to_intel_encoder(connector_state
->best_encoder
);
11369 if (!encoders_cloneable(encoder
, source_encoder
))
11376 static bool check_encoder_cloning(struct drm_atomic_state
*state
,
11377 struct intel_crtc
*crtc
)
11379 struct intel_encoder
*encoder
;
11380 struct drm_connector
*connector
;
11381 struct drm_connector_state
*connector_state
;
11384 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11385 if (connector_state
->crtc
!= &crtc
->base
)
11388 encoder
= to_intel_encoder(connector_state
->best_encoder
);
11389 if (!check_single_encoder_cloning(state
, crtc
, encoder
))
11396 static bool check_digital_port_conflicts(struct drm_atomic_state
*state
)
11398 struct drm_device
*dev
= state
->dev
;
11399 struct intel_encoder
*encoder
;
11400 struct drm_connector
*connector
;
11401 struct drm_connector_state
*connector_state
;
11402 unsigned int used_ports
= 0;
11406 * Walk the connector list instead of the encoder
11407 * list to detect the problem on ddi platforms
11408 * where there's just one encoder per digital port.
11410 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11411 if (!connector_state
->best_encoder
)
11414 encoder
= to_intel_encoder(connector_state
->best_encoder
);
11416 WARN_ON(!connector_state
->crtc
);
11418 switch (encoder
->type
) {
11419 unsigned int port_mask
;
11420 case INTEL_OUTPUT_UNKNOWN
:
11421 if (WARN_ON(!HAS_DDI(dev
)))
11423 case INTEL_OUTPUT_DISPLAYPORT
:
11424 case INTEL_OUTPUT_HDMI
:
11425 case INTEL_OUTPUT_EDP
:
11426 port_mask
= 1 << enc_to_dig_port(&encoder
->base
)->port
;
11428 /* the same port mustn't appear more than once */
11429 if (used_ports
& port_mask
)
11432 used_ports
|= port_mask
;
11442 clear_intel_crtc_state(struct intel_crtc_state
*crtc_state
)
11444 struct drm_crtc_state tmp_state
;
11445 struct intel_crtc_scaler_state scaler_state
;
11447 /* Clear only the intel specific part of the crtc state excluding scalers */
11448 tmp_state
= crtc_state
->base
;
11449 scaler_state
= crtc_state
->scaler_state
;
11450 memset(crtc_state
, 0, sizeof *crtc_state
);
11451 crtc_state
->base
= tmp_state
;
11452 crtc_state
->scaler_state
= scaler_state
;
11456 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
11457 struct drm_display_mode
*mode
,
11458 struct drm_atomic_state
*state
,
11459 struct intel_crtc_state
*pipe_config
)
11461 struct intel_encoder
*encoder
;
11462 struct drm_connector
*connector
;
11463 struct drm_connector_state
*connector_state
;
11464 int base_bpp
, ret
= -EINVAL
;
11468 if (!check_encoder_cloning(state
, to_intel_crtc(crtc
))) {
11469 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
11473 if (!check_digital_port_conflicts(state
)) {
11474 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
11478 clear_intel_crtc_state(pipe_config
);
11480 pipe_config
->base
.crtc
= crtc
;
11481 drm_mode_copy(&pipe_config
->base
.adjusted_mode
, mode
);
11482 drm_mode_copy(&pipe_config
->base
.mode
, mode
);
11484 pipe_config
->cpu_transcoder
=
11485 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
11486 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
11489 * Sanitize sync polarity flags based on requested ones. If neither
11490 * positive or negative polarity is requested, treat this as meaning
11491 * negative polarity.
11493 if (!(pipe_config
->base
.adjusted_mode
.flags
&
11494 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
11495 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
11497 if (!(pipe_config
->base
.adjusted_mode
.flags
&
11498 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
11499 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
11501 /* Compute a starting value for pipe_config->pipe_bpp taking the source
11502 * plane pixel format and any sink constraints into account. Returns the
11503 * source plane bpp so that dithering can be selected on mismatches
11504 * after encoders and crtc also have had their say. */
11505 base_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
11511 * Determine the real pipe dimensions. Note that stereo modes can
11512 * increase the actual pipe size due to the frame doubling and
11513 * insertion of additional space for blanks between the frame. This
11514 * is stored in the crtc timings. We use the requested mode to do this
11515 * computation to clearly distinguish it from the adjusted mode, which
11516 * can be changed by the connectors in the below retry loop.
11518 drm_crtc_get_hv_timing(&pipe_config
->base
.mode
,
11519 &pipe_config
->pipe_src_w
,
11520 &pipe_config
->pipe_src_h
);
11523 /* Ensure the port clock defaults are reset when retrying. */
11524 pipe_config
->port_clock
= 0;
11525 pipe_config
->pixel_multiplier
= 1;
11527 /* Fill in default crtc timings, allow encoders to overwrite them. */
11528 drm_mode_set_crtcinfo(&pipe_config
->base
.adjusted_mode
,
11529 CRTC_STEREO_DOUBLE
);
11531 /* Pass our mode to the connectors and the CRTC to give them a chance to
11532 * adjust it according to limitations or connector properties, and also
11533 * a chance to reject the mode entirely.
11535 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11536 if (connector_state
->crtc
!= crtc
)
11539 encoder
= to_intel_encoder(connector_state
->best_encoder
);
11541 if (!(encoder
->compute_config(encoder
, pipe_config
))) {
11542 DRM_DEBUG_KMS("Encoder config failure\n");
11547 /* Set default port clock if not overwritten by the encoder. Needs to be
11548 * done afterwards in case the encoder adjusts the mode. */
11549 if (!pipe_config
->port_clock
)
11550 pipe_config
->port_clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
11551 * pipe_config
->pixel_multiplier
;
11553 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
11555 DRM_DEBUG_KMS("CRTC fixup failed\n");
11559 if (ret
== RETRY
) {
11560 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
11565 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11567 goto encoder_retry
;
11570 pipe_config
->dither
= pipe_config
->pipe_bpp
!= base_bpp
;
11571 DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
11572 base_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
11579 static bool intel_crtc_in_use(struct drm_crtc
*crtc
)
11581 struct drm_encoder
*encoder
;
11582 struct drm_device
*dev
= crtc
->dev
;
11584 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
11585 if (encoder
->crtc
== crtc
)
11592 needs_modeset(struct drm_crtc_state
*state
)
11594 return state
->mode_changed
|| state
->active_changed
;
11598 intel_modeset_update_state(struct drm_atomic_state
*state
)
11600 struct drm_device
*dev
= state
->dev
;
11601 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11602 struct intel_encoder
*intel_encoder
;
11603 struct drm_crtc
*crtc
;
11604 struct drm_crtc_state
*crtc_state
;
11605 struct drm_connector
*connector
;
11608 intel_shared_dpll_commit(dev_priv
);
11610 for_each_intel_encoder(dev
, intel_encoder
) {
11611 if (!intel_encoder
->base
.crtc
)
11614 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
)
11615 if (crtc
== intel_encoder
->base
.crtc
)
11618 if (crtc
!= intel_encoder
->base
.crtc
)
11621 if (crtc_state
->enable
&& needs_modeset(crtc_state
))
11622 intel_encoder
->connectors_active
= false;
11625 intel_modeset_commit_output_state(dev
);
11627 /* Double check state. */
11628 for_each_crtc(dev
, crtc
) {
11629 WARN_ON(crtc
->state
->enable
!= intel_crtc_in_use(crtc
));
11632 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
11633 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
11636 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
)
11637 if (crtc
== connector
->encoder
->crtc
)
11640 if (crtc
!= connector
->encoder
->crtc
)
11643 if (crtc_state
->enable
&& needs_modeset(crtc_state
)) {
11644 struct drm_property
*dpms_property
=
11645 dev
->mode_config
.dpms_property
;
11647 connector
->dpms
= DRM_MODE_DPMS_ON
;
11648 drm_object_property_set_value(&connector
->base
,
11652 intel_encoder
= to_intel_encoder(connector
->encoder
);
11653 intel_encoder
->connectors_active
= true;
11659 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
11663 if (clock1
== clock2
)
11666 if (!clock1
|| !clock2
)
11669 diff
= abs(clock1
- clock2
);
11671 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
11677 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
11678 list_for_each_entry((intel_crtc), \
11679 &(dev)->mode_config.crtc_list, \
11681 if (mask & (1 <<(intel_crtc)->pipe))
11684 intel_pipe_config_compare(struct drm_device
*dev
,
11685 struct intel_crtc_state
*current_config
,
11686 struct intel_crtc_state
*pipe_config
)
11688 #define PIPE_CONF_CHECK_X(name) \
11689 if (current_config->name != pipe_config->name) { \
11690 DRM_ERROR("mismatch in " #name " " \
11691 "(expected 0x%08x, found 0x%08x)\n", \
11692 current_config->name, \
11693 pipe_config->name); \
11697 #define PIPE_CONF_CHECK_I(name) \
11698 if (current_config->name != pipe_config->name) { \
11699 DRM_ERROR("mismatch in " #name " " \
11700 "(expected %i, found %i)\n", \
11701 current_config->name, \
11702 pipe_config->name); \
11706 /* This is required for BDW+ where there is only one set of registers for
11707 * switching between high and low RR.
11708 * This macro can be used whenever a comparison has to be made between one
11709 * hw state and multiple sw state variables.
11711 #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \
11712 if ((current_config->name != pipe_config->name) && \
11713 (current_config->alt_name != pipe_config->name)) { \
11714 DRM_ERROR("mismatch in " #name " " \
11715 "(expected %i or %i, found %i)\n", \
11716 current_config->name, \
11717 current_config->alt_name, \
11718 pipe_config->name); \
11722 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
11723 if ((current_config->name ^ pipe_config->name) & (mask)) { \
11724 DRM_ERROR("mismatch in " #name "(" #mask ") " \
11725 "(expected %i, found %i)\n", \
11726 current_config->name & (mask), \
11727 pipe_config->name & (mask)); \
11731 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
11732 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
11733 DRM_ERROR("mismatch in " #name " " \
11734 "(expected %i, found %i)\n", \
11735 current_config->name, \
11736 pipe_config->name); \
11740 #define PIPE_CONF_QUIRK(quirk) \
11741 ((current_config->quirks | pipe_config->quirks) & (quirk))
11743 PIPE_CONF_CHECK_I(cpu_transcoder
);
11745 PIPE_CONF_CHECK_I(has_pch_encoder
);
11746 PIPE_CONF_CHECK_I(fdi_lanes
);
11747 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_m
);
11748 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_n
);
11749 PIPE_CONF_CHECK_I(fdi_m_n
.link_m
);
11750 PIPE_CONF_CHECK_I(fdi_m_n
.link_n
);
11751 PIPE_CONF_CHECK_I(fdi_m_n
.tu
);
11753 PIPE_CONF_CHECK_I(has_dp_encoder
);
11755 if (INTEL_INFO(dev
)->gen
< 8) {
11756 PIPE_CONF_CHECK_I(dp_m_n
.gmch_m
);
11757 PIPE_CONF_CHECK_I(dp_m_n
.gmch_n
);
11758 PIPE_CONF_CHECK_I(dp_m_n
.link_m
);
11759 PIPE_CONF_CHECK_I(dp_m_n
.link_n
);
11760 PIPE_CONF_CHECK_I(dp_m_n
.tu
);
11762 if (current_config
->has_drrs
) {
11763 PIPE_CONF_CHECK_I(dp_m2_n2
.gmch_m
);
11764 PIPE_CONF_CHECK_I(dp_m2_n2
.gmch_n
);
11765 PIPE_CONF_CHECK_I(dp_m2_n2
.link_m
);
11766 PIPE_CONF_CHECK_I(dp_m2_n2
.link_n
);
11767 PIPE_CONF_CHECK_I(dp_m2_n2
.tu
);
11770 PIPE_CONF_CHECK_I_ALT(dp_m_n
.gmch_m
, dp_m2_n2
.gmch_m
);
11771 PIPE_CONF_CHECK_I_ALT(dp_m_n
.gmch_n
, dp_m2_n2
.gmch_n
);
11772 PIPE_CONF_CHECK_I_ALT(dp_m_n
.link_m
, dp_m2_n2
.link_m
);
11773 PIPE_CONF_CHECK_I_ALT(dp_m_n
.link_n
, dp_m2_n2
.link_n
);
11774 PIPE_CONF_CHECK_I_ALT(dp_m_n
.tu
, dp_m2_n2
.tu
);
11777 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hdisplay
);
11778 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_htotal
);
11779 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_start
);
11780 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_end
);
11781 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_start
);
11782 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_end
);
11784 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vdisplay
);
11785 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vtotal
);
11786 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_start
);
11787 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_end
);
11788 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_start
);
11789 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_end
);
11791 PIPE_CONF_CHECK_I(pixel_multiplier
);
11792 PIPE_CONF_CHECK_I(has_hdmi_sink
);
11793 if ((INTEL_INFO(dev
)->gen
< 8 && !IS_HASWELL(dev
)) ||
11794 IS_VALLEYVIEW(dev
))
11795 PIPE_CONF_CHECK_I(limited_color_range
);
11796 PIPE_CONF_CHECK_I(has_infoframe
);
11798 PIPE_CONF_CHECK_I(has_audio
);
11800 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11801 DRM_MODE_FLAG_INTERLACE
);
11803 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
11804 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11805 DRM_MODE_FLAG_PHSYNC
);
11806 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11807 DRM_MODE_FLAG_NHSYNC
);
11808 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11809 DRM_MODE_FLAG_PVSYNC
);
11810 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11811 DRM_MODE_FLAG_NVSYNC
);
11814 PIPE_CONF_CHECK_I(pipe_src_w
);
11815 PIPE_CONF_CHECK_I(pipe_src_h
);
11818 * FIXME: BIOS likes to set up a cloned config with lvds+external
11819 * screen. Since we don't yet re-compute the pipe config when moving
11820 * just the lvds port away to another pipe the sw tracking won't match.
11822 * Proper atomic modesets with recomputed global state will fix this.
11823 * Until then just don't check gmch state for inherited modes.
11825 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE
)) {
11826 PIPE_CONF_CHECK_I(gmch_pfit
.control
);
11827 /* pfit ratios are autocomputed by the hw on gen4+ */
11828 if (INTEL_INFO(dev
)->gen
< 4)
11829 PIPE_CONF_CHECK_I(gmch_pfit
.pgm_ratios
);
11830 PIPE_CONF_CHECK_I(gmch_pfit
.lvds_border_bits
);
11833 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
11834 if (current_config
->pch_pfit
.enabled
) {
11835 PIPE_CONF_CHECK_I(pch_pfit
.pos
);
11836 PIPE_CONF_CHECK_I(pch_pfit
.size
);
11839 PIPE_CONF_CHECK_I(scaler_state
.scaler_id
);
11841 /* BDW+ don't expose a synchronous way to read the state */
11842 if (IS_HASWELL(dev
))
11843 PIPE_CONF_CHECK_I(ips_enabled
);
11845 PIPE_CONF_CHECK_I(double_wide
);
11847 PIPE_CONF_CHECK_X(ddi_pll_sel
);
11849 PIPE_CONF_CHECK_I(shared_dpll
);
11850 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
11851 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
11852 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
11853 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
11854 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
11855 PIPE_CONF_CHECK_X(dpll_hw_state
.ctrl1
);
11856 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr1
);
11857 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr2
);
11859 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5)
11860 PIPE_CONF_CHECK_I(pipe_bpp
);
11862 PIPE_CONF_CHECK_CLOCK_FUZZY(base
.adjusted_mode
.crtc_clock
);
11863 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
11865 #undef PIPE_CONF_CHECK_X
11866 #undef PIPE_CONF_CHECK_I
11867 #undef PIPE_CONF_CHECK_I_ALT
11868 #undef PIPE_CONF_CHECK_FLAGS
11869 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
11870 #undef PIPE_CONF_QUIRK
11875 static void check_wm_state(struct drm_device
*dev
)
11877 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11878 struct skl_ddb_allocation hw_ddb
, *sw_ddb
;
11879 struct intel_crtc
*intel_crtc
;
11882 if (INTEL_INFO(dev
)->gen
< 9)
11885 skl_ddb_get_hw_state(dev_priv
, &hw_ddb
);
11886 sw_ddb
= &dev_priv
->wm
.skl_hw
.ddb
;
11888 for_each_intel_crtc(dev
, intel_crtc
) {
11889 struct skl_ddb_entry
*hw_entry
, *sw_entry
;
11890 const enum pipe pipe
= intel_crtc
->pipe
;
11892 if (!intel_crtc
->active
)
11896 for_each_plane(dev_priv
, pipe
, plane
) {
11897 hw_entry
= &hw_ddb
.plane
[pipe
][plane
];
11898 sw_entry
= &sw_ddb
->plane
[pipe
][plane
];
11900 if (skl_ddb_entry_equal(hw_entry
, sw_entry
))
11903 DRM_ERROR("mismatch in DDB state pipe %c plane %d "
11904 "(expected (%u,%u), found (%u,%u))\n",
11905 pipe_name(pipe
), plane
+ 1,
11906 sw_entry
->start
, sw_entry
->end
,
11907 hw_entry
->start
, hw_entry
->end
);
11911 hw_entry
= &hw_ddb
.cursor
[pipe
];
11912 sw_entry
= &sw_ddb
->cursor
[pipe
];
11914 if (skl_ddb_entry_equal(hw_entry
, sw_entry
))
11917 DRM_ERROR("mismatch in DDB state pipe %c cursor "
11918 "(expected (%u,%u), found (%u,%u))\n",
11920 sw_entry
->start
, sw_entry
->end
,
11921 hw_entry
->start
, hw_entry
->end
);
11926 check_connector_state(struct drm_device
*dev
)
11928 struct intel_connector
*connector
;
11930 for_each_intel_connector(dev
, connector
) {
11931 /* This also checks the encoder/connector hw state with the
11932 * ->get_hw_state callbacks. */
11933 intel_connector_check_state(connector
);
11935 I915_STATE_WARN(&connector
->new_encoder
->base
!= connector
->base
.encoder
,
11936 "connector's staged encoder doesn't match current encoder\n");
11941 check_encoder_state(struct drm_device
*dev
)
11943 struct intel_encoder
*encoder
;
11944 struct intel_connector
*connector
;
11946 for_each_intel_encoder(dev
, encoder
) {
11947 bool enabled
= false;
11948 bool active
= false;
11949 enum pipe pipe
, tracked_pipe
;
11951 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
11952 encoder
->base
.base
.id
,
11953 encoder
->base
.name
);
11955 I915_STATE_WARN(&encoder
->new_crtc
->base
!= encoder
->base
.crtc
,
11956 "encoder's stage crtc doesn't match current crtc\n");
11957 I915_STATE_WARN(encoder
->connectors_active
&& !encoder
->base
.crtc
,
11958 "encoder's active_connectors set, but no crtc\n");
11960 for_each_intel_connector(dev
, connector
) {
11961 if (connector
->base
.encoder
!= &encoder
->base
)
11964 if (connector
->base
.dpms
!= DRM_MODE_DPMS_OFF
)
11968 * for MST connectors if we unplug the connector is gone
11969 * away but the encoder is still connected to a crtc
11970 * until a modeset happens in response to the hotplug.
11972 if (!enabled
&& encoder
->base
.encoder_type
== DRM_MODE_ENCODER_DPMST
)
11975 I915_STATE_WARN(!!encoder
->base
.crtc
!= enabled
,
11976 "encoder's enabled state mismatch "
11977 "(expected %i, found %i)\n",
11978 !!encoder
->base
.crtc
, enabled
);
11979 I915_STATE_WARN(active
&& !encoder
->base
.crtc
,
11980 "active encoder with no crtc\n");
11982 I915_STATE_WARN(encoder
->connectors_active
!= active
,
11983 "encoder's computed active state doesn't match tracked active state "
11984 "(expected %i, found %i)\n", active
, encoder
->connectors_active
);
11986 active
= encoder
->get_hw_state(encoder
, &pipe
);
11987 I915_STATE_WARN(active
!= encoder
->connectors_active
,
11988 "encoder's hw state doesn't match sw tracking "
11989 "(expected %i, found %i)\n",
11990 encoder
->connectors_active
, active
);
11992 if (!encoder
->base
.crtc
)
11995 tracked_pipe
= to_intel_crtc(encoder
->base
.crtc
)->pipe
;
11996 I915_STATE_WARN(active
&& pipe
!= tracked_pipe
,
11997 "active encoder's pipe doesn't match"
11998 "(expected %i, found %i)\n",
11999 tracked_pipe
, pipe
);
12005 check_crtc_state(struct drm_device
*dev
)
12007 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12008 struct intel_crtc
*crtc
;
12009 struct intel_encoder
*encoder
;
12010 struct intel_crtc_state pipe_config
;
12012 for_each_intel_crtc(dev
, crtc
) {
12013 bool enabled
= false;
12014 bool active
= false;
12016 memset(&pipe_config
, 0, sizeof(pipe_config
));
12018 DRM_DEBUG_KMS("[CRTC:%d]\n",
12019 crtc
->base
.base
.id
);
12021 I915_STATE_WARN(crtc
->active
&& !crtc
->base
.state
->enable
,
12022 "active crtc, but not enabled in sw tracking\n");
12024 for_each_intel_encoder(dev
, encoder
) {
12025 if (encoder
->base
.crtc
!= &crtc
->base
)
12028 if (encoder
->connectors_active
)
12032 I915_STATE_WARN(active
!= crtc
->active
,
12033 "crtc's computed active state doesn't match tracked active state "
12034 "(expected %i, found %i)\n", active
, crtc
->active
);
12035 I915_STATE_WARN(enabled
!= crtc
->base
.state
->enable
,
12036 "crtc's computed enabled state doesn't match tracked enabled state "
12037 "(expected %i, found %i)\n", enabled
,
12038 crtc
->base
.state
->enable
);
12040 active
= dev_priv
->display
.get_pipe_config(crtc
,
12043 /* hw state is inconsistent with the pipe quirk */
12044 if ((crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
12045 (crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
12046 active
= crtc
->active
;
12048 for_each_intel_encoder(dev
, encoder
) {
12050 if (encoder
->base
.crtc
!= &crtc
->base
)
12052 if (encoder
->get_hw_state(encoder
, &pipe
))
12053 encoder
->get_config(encoder
, &pipe_config
);
12056 I915_STATE_WARN(crtc
->active
!= active
,
12057 "crtc active state doesn't match with hw state "
12058 "(expected %i, found %i)\n", crtc
->active
, active
);
12061 !intel_pipe_config_compare(dev
, crtc
->config
, &pipe_config
)) {
12062 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12063 intel_dump_pipe_config(crtc
, &pipe_config
,
12065 intel_dump_pipe_config(crtc
, crtc
->config
,
12072 check_shared_dpll_state(struct drm_device
*dev
)
12074 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12075 struct intel_crtc
*crtc
;
12076 struct intel_dpll_hw_state dpll_hw_state
;
12079 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
12080 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
12081 int enabled_crtcs
= 0, active_crtcs
= 0;
12084 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
12086 DRM_DEBUG_KMS("%s\n", pll
->name
);
12088 active
= pll
->get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
12090 I915_STATE_WARN(pll
->active
> hweight32(pll
->config
.crtc_mask
),
12091 "more active pll users than references: %i vs %i\n",
12092 pll
->active
, hweight32(pll
->config
.crtc_mask
));
12093 I915_STATE_WARN(pll
->active
&& !pll
->on
,
12094 "pll in active use but not on in sw tracking\n");
12095 I915_STATE_WARN(pll
->on
&& !pll
->active
,
12096 "pll in on but not on in use in sw tracking\n");
12097 I915_STATE_WARN(pll
->on
!= active
,
12098 "pll on state mismatch (expected %i, found %i)\n",
12101 for_each_intel_crtc(dev
, crtc
) {
12102 if (crtc
->base
.state
->enable
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
12104 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
12107 I915_STATE_WARN(pll
->active
!= active_crtcs
,
12108 "pll active crtcs mismatch (expected %i, found %i)\n",
12109 pll
->active
, active_crtcs
);
12110 I915_STATE_WARN(hweight32(pll
->config
.crtc_mask
) != enabled_crtcs
,
12111 "pll enabled crtcs mismatch (expected %i, found %i)\n",
12112 hweight32(pll
->config
.crtc_mask
), enabled_crtcs
);
12114 I915_STATE_WARN(pll
->on
&& memcmp(&pll
->config
.hw_state
, &dpll_hw_state
,
12115 sizeof(dpll_hw_state
)),
12116 "pll hw state mismatch\n");
12121 intel_modeset_check_state(struct drm_device
*dev
)
12123 check_wm_state(dev
);
12124 check_connector_state(dev
);
12125 check_encoder_state(dev
);
12126 check_crtc_state(dev
);
12127 check_shared_dpll_state(dev
);
12130 void ironlake_check_encoder_dotclock(const struct intel_crtc_state
*pipe_config
,
12134 * FDI already provided one idea for the dotclock.
12135 * Yell if the encoder disagrees.
12137 WARN(!intel_fuzzy_clock_check(pipe_config
->base
.adjusted_mode
.crtc_clock
, dotclock
),
12138 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
12139 pipe_config
->base
.adjusted_mode
.crtc_clock
, dotclock
);
12142 static void update_scanline_offset(struct intel_crtc
*crtc
)
12144 struct drm_device
*dev
= crtc
->base
.dev
;
12147 * The scanline counter increments at the leading edge of hsync.
12149 * On most platforms it starts counting from vtotal-1 on the
12150 * first active line. That means the scanline counter value is
12151 * always one less than what we would expect. Ie. just after
12152 * start of vblank, which also occurs at start of hsync (on the
12153 * last active line), the scanline counter will read vblank_start-1.
12155 * On gen2 the scanline counter starts counting from 1 instead
12156 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12157 * to keep the value positive), instead of adding one.
12159 * On HSW+ the behaviour of the scanline counter depends on the output
12160 * type. For DP ports it behaves like most other platforms, but on HDMI
12161 * there's an extra 1 line difference. So we need to add two instead of
12162 * one to the value.
12164 if (IS_GEN2(dev
)) {
12165 const struct drm_display_mode
*mode
= &crtc
->config
->base
.adjusted_mode
;
12168 vtotal
= mode
->crtc_vtotal
;
12169 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
12172 crtc
->scanline_offset
= vtotal
- 1;
12173 } else if (HAS_DDI(dev
) &&
12174 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
)) {
12175 crtc
->scanline_offset
= 2;
12177 crtc
->scanline_offset
= 1;
12181 intel_atomic_modeset_compute_changed_flags(struct drm_atomic_state
*state
,
12182 struct drm_crtc
*modeset_crtc
)
12184 struct drm_crtc_state
*crtc_state
;
12185 struct drm_crtc
*crtc
;
12188 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12189 if (crtc_state
->enable
!= crtc
->state
->enable
)
12190 crtc_state
->mode_changed
= true;
12192 /* FIXME: Do we need to always set mode_changed for
12193 * modeset_crtc if it is enabled? modeset_affect_pipes()
12198 static struct intel_crtc_state
*
12199 intel_modeset_compute_config(struct drm_crtc
*crtc
,
12200 struct drm_display_mode
*mode
,
12201 struct drm_atomic_state
*state
)
12203 struct intel_crtc_state
*pipe_config
;
12206 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
12208 return ERR_PTR(ret
);
12210 intel_atomic_modeset_compute_changed_flags(state
, crtc
);
12213 * Note this needs changes when we start tracking multiple modes
12214 * and crtcs. At that point we'll need to compute the whole config
12215 * (i.e. one pipe_config for each crtc) rather than just the one
12218 pipe_config
= intel_atomic_get_crtc_state(state
, to_intel_crtc(crtc
));
12219 if (IS_ERR(pipe_config
))
12220 return pipe_config
;
12222 if (!pipe_config
->base
.enable
)
12223 return pipe_config
;
12225 ret
= intel_modeset_pipe_config(crtc
, mode
, state
, pipe_config
);
12227 return ERR_PTR(ret
);
12229 /* Check things that can only be changed through modeset */
12230 if (pipe_config
->has_audio
!=
12231 to_intel_crtc(crtc
)->config
->has_audio
)
12232 pipe_config
->base
.mode_changed
= true;
12235 * Note we have an issue here with infoframes: current code
12236 * only updates them on the full mode set path per hw
12237 * requirements. So here we should be checking for any
12238 * required changes and forcing a mode set.
12241 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,"[modeset]");
12243 return pipe_config
;
12246 static int __intel_set_mode_setup_plls(struct drm_atomic_state
*state
)
12248 struct drm_device
*dev
= state
->dev
;
12249 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12250 unsigned clear_pipes
= 0;
12251 struct intel_crtc
*intel_crtc
;
12252 struct intel_crtc_state
*intel_crtc_state
;
12253 struct drm_crtc
*crtc
;
12254 struct drm_crtc_state
*crtc_state
;
12258 if (!dev_priv
->display
.crtc_compute_clock
)
12261 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12262 intel_crtc
= to_intel_crtc(crtc
);
12264 if (needs_modeset(crtc_state
))
12265 clear_pipes
|= 1 << intel_crtc
->pipe
;
12268 ret
= intel_shared_dpll_start_config(dev_priv
, clear_pipes
);
12272 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12273 if (!needs_modeset(crtc_state
) || !crtc_state
->enable
)
12276 intel_crtc
= to_intel_crtc(crtc
);
12277 intel_crtc_state
= to_intel_crtc_state(crtc_state
);
12279 ret
= dev_priv
->display
.crtc_compute_clock(intel_crtc
,
12282 intel_shared_dpll_abort_config(dev_priv
);
12291 /* Code that should eventually be part of atomic_check() */
12292 static int __intel_set_mode_checks(struct drm_atomic_state
*state
)
12294 struct drm_device
*dev
= state
->dev
;
12298 * See if the config requires any additional preparation, e.g.
12299 * to adjust global state with pipes off. We need to do this
12300 * here so we can get the modeset_pipe updated config for the new
12301 * mode set on this crtc. For other crtcs we need to use the
12302 * adjusted_mode bits in the crtc directly.
12304 if (IS_VALLEYVIEW(dev
) || IS_BROXTON(dev
)) {
12305 ret
= valleyview_modeset_global_pipes(state
);
12310 ret
= __intel_set_mode_setup_plls(state
);
12317 static int __intel_set_mode(struct drm_crtc
*modeset_crtc
,
12318 struct drm_display_mode
*mode
,
12319 struct intel_crtc_state
*pipe_config
)
12321 struct drm_device
*dev
= modeset_crtc
->dev
;
12322 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12323 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
12324 struct intel_crtc_state
*crtc_state_copy
= NULL
;
12325 struct intel_crtc
*intel_crtc
;
12326 struct drm_crtc
*crtc
;
12327 struct drm_crtc_state
*crtc_state
;
12328 struct drm_plane
*plane
;
12329 struct drm_plane_state
*plane_state
;
12333 ret
= __intel_set_mode_checks(state
);
12337 crtc_state_copy
= kmalloc(sizeof(*crtc_state_copy
), GFP_KERNEL
);
12338 if (!crtc_state_copy
)
12341 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12342 if (!needs_modeset(crtc_state
))
12345 if (!crtc_state
->enable
) {
12346 intel_crtc_disable(crtc
);
12347 } else if (crtc
->state
->enable
) {
12348 intel_crtc_disable_planes(crtc
);
12349 dev_priv
->display
.crtc_disable(crtc
);
12353 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
12354 * to set it here already despite that we pass it down the callchain.
12356 * Note we'll need to fix this up when we start tracking multiple
12357 * pipes; here we assume a single modeset_pipe and only track the
12358 * single crtc and mode.
12360 if (pipe_config
->base
.enable
&& needs_modeset(&pipe_config
->base
)) {
12361 modeset_crtc
->mode
= *mode
;
12362 /* mode_set/enable/disable functions rely on a correct pipe
12364 intel_crtc_set_state(to_intel_crtc(modeset_crtc
), pipe_config
);
12367 * Calculate and store various constants which
12368 * are later needed by vblank and swap-completion
12369 * timestamping. They are derived from true hwmode.
12371 drm_calc_timestamping_constants(modeset_crtc
,
12372 &pipe_config
->base
.adjusted_mode
);
12375 /* Only after disabling all output pipelines that will be changed can we
12376 * update the the output configuration. */
12377 intel_modeset_update_state(state
);
12379 modeset_update_crtc_power_domains(state
);
12381 for_each_plane_in_state(state
, plane
, plane_state
, i
) {
12382 if (WARN_ON(plane
!= modeset_crtc
->primary
))
12385 /* Primary plane is disabled in intel_crtc_disable() */
12386 if (!pipe_config
->base
.enable
)
12389 ret
= drm_plane_helper_update(plane
, plane_state
->crtc
,
12391 plane_state
->crtc_x
,
12392 plane_state
->crtc_y
,
12393 plane_state
->crtc_w
,
12394 plane_state
->crtc_h
,
12395 plane_state
->src_x
,
12396 plane_state
->src_y
,
12397 plane_state
->src_w
,
12398 plane_state
->src_h
);
12402 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
12403 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12404 if (!needs_modeset(crtc_state
) || !crtc_state
->enable
)
12407 update_scanline_offset(to_intel_crtc(crtc
));
12409 dev_priv
->display
.crtc_enable(crtc
);
12410 intel_crtc_enable_planes(crtc
);
12413 /* FIXME: add subpixel order */
12415 intel_crtc
= to_intel_crtc(modeset_crtc
);
12417 /* The pipe_config will be freed with the atomic state, so
12419 memcpy(crtc_state_copy
, intel_crtc
->config
, sizeof *crtc_state_copy
);
12420 intel_crtc
->config
= crtc_state_copy
;
12421 intel_crtc
->base
.state
= &crtc_state_copy
->base
;
12426 static int intel_set_mode_with_config(struct drm_crtc
*crtc
,
12427 struct drm_display_mode
*mode
,
12428 struct intel_crtc_state
*pipe_config
)
12432 ret
= __intel_set_mode(crtc
, mode
, pipe_config
);
12435 intel_modeset_check_state(crtc
->dev
);
12440 static int intel_set_mode(struct drm_crtc
*crtc
,
12441 struct drm_display_mode
*mode
,
12442 struct drm_atomic_state
*state
)
12444 struct intel_crtc_state
*pipe_config
;
12447 pipe_config
= intel_modeset_compute_config(crtc
, mode
, state
);
12448 if (IS_ERR(pipe_config
)) {
12449 ret
= PTR_ERR(pipe_config
);
12453 ret
= intel_set_mode_with_config(crtc
, mode
, pipe_config
);
12461 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
12463 struct drm_device
*dev
= crtc
->dev
;
12464 struct drm_atomic_state
*state
;
12465 struct intel_crtc
*intel_crtc
;
12466 struct intel_encoder
*encoder
;
12467 struct intel_connector
*connector
;
12468 struct drm_connector_state
*connector_state
;
12469 struct intel_crtc_state
*crtc_state
;
12471 state
= drm_atomic_state_alloc(dev
);
12473 DRM_DEBUG_KMS("[CRTC:%d] mode restore failed, out of memory",
12478 state
->acquire_ctx
= dev
->mode_config
.acquire_ctx
;
12480 /* The force restore path in the HW readout code relies on the staged
12481 * config still keeping the user requested config while the actual
12482 * state has been overwritten by the configuration read from HW. We
12483 * need to copy the staged config to the atomic state, otherwise the
12484 * mode set will just reapply the state the HW is already in. */
12485 for_each_intel_encoder(dev
, encoder
) {
12486 if (&encoder
->new_crtc
->base
!= crtc
)
12489 for_each_intel_connector(dev
, connector
) {
12490 if (connector
->new_encoder
!= encoder
)
12493 connector_state
= drm_atomic_get_connector_state(state
, &connector
->base
);
12494 if (IS_ERR(connector_state
)) {
12495 DRM_DEBUG_KMS("Failed to add [CONNECTOR:%d:%s] to state: %ld\n",
12496 connector
->base
.base
.id
,
12497 connector
->base
.name
,
12498 PTR_ERR(connector_state
));
12502 connector_state
->crtc
= crtc
;
12503 connector_state
->best_encoder
= &encoder
->base
;
12507 for_each_intel_crtc(dev
, intel_crtc
) {
12508 if (intel_crtc
->new_enabled
== intel_crtc
->base
.enabled
)
12511 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
12512 if (IS_ERR(crtc_state
)) {
12513 DRM_DEBUG_KMS("Failed to add [CRTC:%d] to state: %ld\n",
12514 intel_crtc
->base
.base
.id
,
12515 PTR_ERR(crtc_state
));
12519 crtc_state
->base
.enable
= intel_crtc
->new_enabled
;
12522 intel_modeset_setup_plane_state(state
, crtc
, &crtc
->mode
,
12523 crtc
->primary
->fb
, crtc
->x
, crtc
->y
);
12525 intel_set_mode(crtc
, &crtc
->mode
, state
);
12527 drm_atomic_state_free(state
);
12530 #undef for_each_intel_crtc_masked
12532 static void intel_set_config_free(struct intel_set_config
*config
)
12537 kfree(config
->save_connector_encoders
);
12538 kfree(config
->save_encoder_crtcs
);
12539 kfree(config
->save_crtc_enabled
);
12543 static int intel_set_config_save_state(struct drm_device
*dev
,
12544 struct intel_set_config
*config
)
12546 struct drm_crtc
*crtc
;
12547 struct drm_encoder
*encoder
;
12548 struct drm_connector
*connector
;
12551 config
->save_crtc_enabled
=
12552 kcalloc(dev
->mode_config
.num_crtc
,
12553 sizeof(bool), GFP_KERNEL
);
12554 if (!config
->save_crtc_enabled
)
12557 config
->save_encoder_crtcs
=
12558 kcalloc(dev
->mode_config
.num_encoder
,
12559 sizeof(struct drm_crtc
*), GFP_KERNEL
);
12560 if (!config
->save_encoder_crtcs
)
12563 config
->save_connector_encoders
=
12564 kcalloc(dev
->mode_config
.num_connector
,
12565 sizeof(struct drm_encoder
*), GFP_KERNEL
);
12566 if (!config
->save_connector_encoders
)
12569 /* Copy data. Note that driver private data is not affected.
12570 * Should anything bad happen only the expected state is
12571 * restored, not the drivers personal bookkeeping.
12574 for_each_crtc(dev
, crtc
) {
12575 config
->save_crtc_enabled
[count
++] = crtc
->state
->enable
;
12579 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
12580 config
->save_encoder_crtcs
[count
++] = encoder
->crtc
;
12584 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
12585 config
->save_connector_encoders
[count
++] = connector
->encoder
;
12591 static void intel_set_config_restore_state(struct drm_device
*dev
,
12592 struct intel_set_config
*config
)
12594 struct intel_crtc
*crtc
;
12595 struct intel_encoder
*encoder
;
12596 struct intel_connector
*connector
;
12600 for_each_intel_crtc(dev
, crtc
) {
12601 crtc
->new_enabled
= config
->save_crtc_enabled
[count
++];
12605 for_each_intel_encoder(dev
, encoder
) {
12606 encoder
->new_crtc
=
12607 to_intel_crtc(config
->save_encoder_crtcs
[count
++]);
12611 for_each_intel_connector(dev
, connector
) {
12612 connector
->new_encoder
=
12613 to_intel_encoder(config
->save_connector_encoders
[count
++]);
12618 is_crtc_connector_off(struct drm_mode_set
*set
)
12622 if (set
->num_connectors
== 0)
12625 if (WARN_ON(set
->connectors
== NULL
))
12628 for (i
= 0; i
< set
->num_connectors
; i
++)
12629 if (set
->connectors
[i
]->encoder
&&
12630 set
->connectors
[i
]->encoder
->crtc
== set
->crtc
&&
12631 set
->connectors
[i
]->dpms
!= DRM_MODE_DPMS_ON
)
12638 intel_set_config_compute_mode_changes(struct drm_mode_set
*set
,
12639 struct intel_crtc_state
*pipe_config
)
12641 struct drm_atomic_state
*state
;
12642 struct drm_connector
*connector
;
12643 struct drm_connector_state
*connector_state
;
12644 struct drm_crtc
*crtc
;
12645 struct drm_crtc_state
*crtc_state
;
12648 /* We should be able to check here if the fb has the same properties
12649 * and then just flip_or_move it */
12650 if (is_crtc_connector_off(set
)) {
12651 pipe_config
->base
.mode_changed
= true;
12652 } else if (set
->crtc
->primary
->fb
!= set
->fb
) {
12654 * If we have no fb, we can only flip as long as the crtc is
12655 * active, otherwise we need a full mode set. The crtc may
12656 * be active if we've only disabled the primary plane, or
12657 * in fastboot situations.
12659 if (set
->crtc
->primary
->fb
== NULL
) {
12660 struct intel_crtc
*intel_crtc
=
12661 to_intel_crtc(set
->crtc
);
12663 if (intel_crtc
->active
) {
12664 DRM_DEBUG_KMS("crtc has no fb, will flip\n");
12665 pipe_config
->base
.planes_changed
= true;
12667 DRM_DEBUG_KMS("inactive crtc, full mode set\n");
12668 pipe_config
->base
.mode_changed
= true;
12670 } else if (set
->fb
== NULL
) {
12671 pipe_config
->base
.mode_changed
= true;
12672 } else if (set
->fb
->pixel_format
!=
12673 set
->crtc
->primary
->fb
->pixel_format
) {
12674 pipe_config
->base
.mode_changed
= true;
12676 pipe_config
->base
.planes_changed
= true;
12680 if (set
->fb
&& (set
->x
!= set
->crtc
->x
|| set
->y
!= set
->crtc
->y
))
12681 pipe_config
->base
.planes_changed
= true;
12683 if (set
->mode
&& !drm_mode_equal(set
->mode
, &set
->crtc
->mode
)) {
12684 DRM_DEBUG_KMS("modes are different, full mode set\n");
12685 drm_mode_debug_printmodeline(&set
->crtc
->mode
);
12686 drm_mode_debug_printmodeline(set
->mode
);
12687 pipe_config
->base
.mode_changed
= true;
12690 state
= pipe_config
->base
.state
;
12692 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
12693 if (connector_state
->best_encoder
!=
12694 connector
->state
->best_encoder
) {
12695 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] encoder changed, full mode switch\n",
12696 connector
->base
.id
,
12698 pipe_config
->base
.mode_changed
= true;
12701 if (connector_state
->crtc
!= connector
->state
->crtc
) {
12702 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] crtc changed, full mode switch\n",
12703 connector
->base
.id
,
12705 pipe_config
->base
.mode_changed
= true;
12709 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12710 if (crtc_state
->enable
== crtc
->state
->enable
)
12713 DRM_DEBUG_KMS("[CRTC:%d] %sabled, full mode switch\n",
12715 crtc_state
->enable
? "en" : "dis");
12716 pipe_config
->base
.mode_changed
= true;
12719 DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
12720 set
->crtc
->base
.id
, pipe_config
->base
.mode_changed
,
12721 pipe_config
->base
.planes_changed
);
12724 static bool intel_connector_in_mode_set(struct intel_connector
*connector
,
12725 struct drm_mode_set
*set
)
12729 for (ro
= 0; ro
< set
->num_connectors
; ro
++)
12730 if (set
->connectors
[ro
] == &connector
->base
)
12737 intel_modeset_stage_output_state(struct drm_device
*dev
,
12738 struct drm_mode_set
*set
,
12739 struct drm_atomic_state
*state
)
12741 struct intel_connector
*connector
;
12742 struct drm_connector_state
*connector_state
;
12743 struct intel_encoder
*encoder
;
12744 struct intel_crtc
*crtc
;
12745 struct intel_crtc_state
*crtc_state
;
12747 /* The upper layers ensure that we either disable a crtc or have a list
12748 * of connectors. For paranoia, double-check this. */
12749 WARN_ON(!set
->fb
&& (set
->num_connectors
!= 0));
12750 WARN_ON(set
->fb
&& (set
->num_connectors
== 0));
12752 for_each_intel_connector(dev
, connector
) {
12753 bool in_mode_set
= intel_connector_in_mode_set(connector
, set
);
12756 int pipe
= to_intel_crtc(set
->crtc
)->pipe
;
12757 connector
->new_encoder
=
12758 intel_find_encoder(connector
, pipe
);
12761 if (!connector
->base
.encoder
||
12762 connector
->base
.encoder
->crtc
!= set
->crtc
)
12765 /* If we disable the crtc, disable all its connectors. Also, if
12766 * the connector is on the changing crtc but not on the new
12767 * connector list, disable it. */
12768 if (!set
->fb
|| !in_mode_set
) {
12769 connector
->new_encoder
= NULL
;
12771 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
12772 connector
->base
.base
.id
,
12773 connector
->base
.name
);
12776 /* connector->new_encoder is now updated for all connectors. */
12778 /* Update crtc of enabled connectors. */
12779 for_each_intel_connector(dev
, connector
) {
12780 struct drm_crtc
*new_crtc
;
12782 if (!connector
->new_encoder
)
12785 if (intel_connector_in_mode_set(connector
, set
))
12786 new_crtc
= set
->crtc
;
12788 new_crtc
= connector
->new_encoder
->base
.crtc
;
12790 /* Make sure the new CRTC will work with the encoder */
12791 if (!drm_encoder_crtc_ok(&connector
->new_encoder
->base
,
12795 connector
->new_encoder
->new_crtc
= to_intel_crtc(new_crtc
);
12798 drm_atomic_get_connector_state(state
, &connector
->base
);
12799 if (IS_ERR(connector_state
))
12800 return PTR_ERR(connector_state
);
12802 connector_state
->crtc
= new_crtc
;
12803 connector_state
->best_encoder
= &connector
->new_encoder
->base
;
12805 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
12806 connector
->base
.base
.id
,
12807 connector
->base
.name
,
12808 new_crtc
->base
.id
);
12811 /* Check for any encoders that needs to be disabled. */
12812 for_each_intel_encoder(dev
, encoder
) {
12813 int num_connectors
= 0;
12814 for_each_intel_connector(dev
, connector
) {
12815 if (connector
->new_encoder
== encoder
) {
12816 WARN_ON(!connector
->new_encoder
->new_crtc
);
12821 if (num_connectors
== 0)
12822 encoder
->new_crtc
= NULL
;
12823 else if (num_connectors
> 1)
12826 /* Now we've also updated encoder->new_crtc for all encoders. */
12827 for_each_intel_connector(dev
, connector
) {
12829 drm_atomic_get_connector_state(state
, &connector
->base
);
12830 if (IS_ERR(connector_state
))
12831 return PTR_ERR(connector_state
);
12833 if (connector
->new_encoder
) {
12834 if (connector
->new_encoder
!= connector
->encoder
)
12835 connector
->encoder
= connector
->new_encoder
;
12837 connector_state
->crtc
= NULL
;
12838 connector_state
->best_encoder
= NULL
;
12841 for_each_intel_crtc(dev
, crtc
) {
12842 crtc
->new_enabled
= false;
12844 for_each_intel_encoder(dev
, encoder
) {
12845 if (encoder
->new_crtc
== crtc
) {
12846 crtc
->new_enabled
= true;
12851 if (crtc
->new_enabled
!= crtc
->base
.state
->enable
) {
12852 crtc_state
= intel_atomic_get_crtc_state(state
, crtc
);
12853 if (IS_ERR(crtc_state
))
12854 return PTR_ERR(crtc_state
);
12856 crtc_state
->base
.enable
= crtc
->new_enabled
;
12863 static bool primary_plane_visible(struct drm_crtc
*crtc
)
12865 struct intel_plane_state
*plane_state
=
12866 to_intel_plane_state(crtc
->primary
->state
);
12868 return plane_state
->visible
;
12871 static int intel_crtc_set_config(struct drm_mode_set
*set
)
12873 struct drm_device
*dev
;
12874 struct drm_atomic_state
*state
= NULL
;
12875 struct intel_set_config
*config
;
12876 struct intel_crtc_state
*pipe_config
;
12877 bool primary_plane_was_visible
;
12881 BUG_ON(!set
->crtc
);
12882 BUG_ON(!set
->crtc
->helper_private
);
12884 /* Enforce sane interface api - has been abused by the fb helper. */
12885 BUG_ON(!set
->mode
&& set
->fb
);
12886 BUG_ON(set
->fb
&& set
->num_connectors
== 0);
12889 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
12890 set
->crtc
->base
.id
, set
->fb
->base
.id
,
12891 (int)set
->num_connectors
, set
->x
, set
->y
);
12893 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set
->crtc
->base
.id
);
12896 dev
= set
->crtc
->dev
;
12899 config
= kzalloc(sizeof(*config
), GFP_KERNEL
);
12903 ret
= intel_set_config_save_state(dev
, config
);
12907 state
= drm_atomic_state_alloc(dev
);
12913 state
->acquire_ctx
= dev
->mode_config
.acquire_ctx
;
12915 ret
= intel_modeset_stage_output_state(dev
, set
, state
);
12919 ret
= intel_modeset_setup_plane_state(state
, set
->crtc
, set
->mode
,
12920 set
->fb
, set
->x
, set
->y
);
12924 pipe_config
= intel_modeset_compute_config(set
->crtc
, set
->mode
,
12926 if (IS_ERR(pipe_config
)) {
12927 ret
= PTR_ERR(pipe_config
);
12931 /* Compute whether we need a full modeset, only an fb base update or no
12932 * change at all. In the future we might also check whether only the
12933 * mode changed, e.g. for LVDS where we only change the panel fitter in
12935 intel_set_config_compute_mode_changes(set
, pipe_config
);
12937 intel_update_pipe_size(to_intel_crtc(set
->crtc
));
12939 primary_plane_was_visible
= primary_plane_visible(set
->crtc
);
12941 ret
= intel_set_mode_with_config(set
->crtc
, set
->mode
,
12945 pipe_config
->base
.enable
&&
12946 pipe_config
->base
.planes_changed
&&
12947 !needs_modeset(&pipe_config
->base
)) {
12948 struct intel_crtc
*intel_crtc
= to_intel_crtc(set
->crtc
);
12951 * We need to make sure the primary plane is re-enabled if it
12952 * has previously been turned off.
12954 if (ret
== 0 && !primary_plane_was_visible
&&
12955 primary_plane_visible(set
->crtc
)) {
12956 WARN_ON(!intel_crtc
->active
);
12957 intel_post_enable_primary(set
->crtc
);
12961 * In the fastboot case this may be our only check of the
12962 * state after boot. It would be better to only do it on
12963 * the first update, but we don't have a nice way of doing that
12964 * (and really, set_config isn't used much for high freq page
12965 * flipping, so increasing its cost here shouldn't be a big
12968 if (i915
.fastboot
&& ret
== 0)
12969 intel_modeset_check_state(set
->crtc
->dev
);
12973 DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
12974 set
->crtc
->base
.id
, ret
);
12976 intel_set_config_restore_state(dev
, config
);
12980 drm_atomic_state_free(state
);
12982 intel_set_config_free(config
);
12986 static const struct drm_crtc_funcs intel_crtc_funcs
= {
12987 .gamma_set
= intel_crtc_gamma_set
,
12988 .set_config
= intel_crtc_set_config
,
12989 .destroy
= intel_crtc_destroy
,
12990 .page_flip
= intel_crtc_page_flip
,
12991 .atomic_duplicate_state
= intel_crtc_duplicate_state
,
12992 .atomic_destroy_state
= intel_crtc_destroy_state
,
12995 static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private
*dev_priv
,
12996 struct intel_shared_dpll
*pll
,
12997 struct intel_dpll_hw_state
*hw_state
)
13001 if (!intel_display_power_is_enabled(dev_priv
, POWER_DOMAIN_PLLS
))
13004 val
= I915_READ(PCH_DPLL(pll
->id
));
13005 hw_state
->dpll
= val
;
13006 hw_state
->fp0
= I915_READ(PCH_FP0(pll
->id
));
13007 hw_state
->fp1
= I915_READ(PCH_FP1(pll
->id
));
13009 return val
& DPLL_VCO_ENABLE
;
13012 static void ibx_pch_dpll_mode_set(struct drm_i915_private
*dev_priv
,
13013 struct intel_shared_dpll
*pll
)
13015 I915_WRITE(PCH_FP0(pll
->id
), pll
->config
.hw_state
.fp0
);
13016 I915_WRITE(PCH_FP1(pll
->id
), pll
->config
.hw_state
.fp1
);
13019 static void ibx_pch_dpll_enable(struct drm_i915_private
*dev_priv
,
13020 struct intel_shared_dpll
*pll
)
13022 /* PCH refclock must be enabled first */
13023 ibx_assert_pch_refclk_enabled(dev_priv
);
13025 I915_WRITE(PCH_DPLL(pll
->id
), pll
->config
.hw_state
.dpll
);
13027 /* Wait for the clocks to stabilize. */
13028 POSTING_READ(PCH_DPLL(pll
->id
));
13031 /* The pixel multiplier can only be updated once the
13032 * DPLL is enabled and the clocks are stable.
13034 * So write it again.
13036 I915_WRITE(PCH_DPLL(pll
->id
), pll
->config
.hw_state
.dpll
);
13037 POSTING_READ(PCH_DPLL(pll
->id
));
13041 static void ibx_pch_dpll_disable(struct drm_i915_private
*dev_priv
,
13042 struct intel_shared_dpll
*pll
)
13044 struct drm_device
*dev
= dev_priv
->dev
;
13045 struct intel_crtc
*crtc
;
13047 /* Make sure no transcoder isn't still depending on us. */
13048 for_each_intel_crtc(dev
, crtc
) {
13049 if (intel_crtc_to_shared_dpll(crtc
) == pll
)
13050 assert_pch_transcoder_disabled(dev_priv
, crtc
->pipe
);
13053 I915_WRITE(PCH_DPLL(pll
->id
), 0);
13054 POSTING_READ(PCH_DPLL(pll
->id
));
13058 static char *ibx_pch_dpll_names
[] = {
13063 static void ibx_pch_dpll_init(struct drm_device
*dev
)
13065 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13068 dev_priv
->num_shared_dpll
= 2;
13070 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
13071 dev_priv
->shared_dplls
[i
].id
= i
;
13072 dev_priv
->shared_dplls
[i
].name
= ibx_pch_dpll_names
[i
];
13073 dev_priv
->shared_dplls
[i
].mode_set
= ibx_pch_dpll_mode_set
;
13074 dev_priv
->shared_dplls
[i
].enable
= ibx_pch_dpll_enable
;
13075 dev_priv
->shared_dplls
[i
].disable
= ibx_pch_dpll_disable
;
13076 dev_priv
->shared_dplls
[i
].get_hw_state
=
13077 ibx_pch_dpll_get_hw_state
;
13081 static void intel_shared_dpll_init(struct drm_device
*dev
)
13083 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13086 intel_ddi_pll_init(dev
);
13087 else if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
13088 ibx_pch_dpll_init(dev
);
13090 dev_priv
->num_shared_dpll
= 0;
13092 BUG_ON(dev_priv
->num_shared_dpll
> I915_NUM_PLLS
);
13096 * intel_wm_need_update - Check whether watermarks need updating
13097 * @plane: drm plane
13098 * @state: new plane state
13100 * Check current plane state versus the new one to determine whether
13101 * watermarks need to be recalculated.
13103 * Returns true or false.
13105 bool intel_wm_need_update(struct drm_plane
*plane
,
13106 struct drm_plane_state
*state
)
13108 /* Update watermarks on tiling changes. */
13109 if (!plane
->state
->fb
|| !state
->fb
||
13110 plane
->state
->fb
->modifier
[0] != state
->fb
->modifier
[0] ||
13111 plane
->state
->rotation
!= state
->rotation
)
13118 * intel_prepare_plane_fb - Prepare fb for usage on plane
13119 * @plane: drm plane to prepare for
13120 * @fb: framebuffer to prepare for presentation
13122 * Prepares a framebuffer for usage on a display plane. Generally this
13123 * involves pinning the underlying object and updating the frontbuffer tracking
13124 * bits. Some older platforms need special physical address handling for
13127 * Returns 0 on success, negative error code on failure.
13130 intel_prepare_plane_fb(struct drm_plane
*plane
,
13131 struct drm_framebuffer
*fb
,
13132 const struct drm_plane_state
*new_state
)
13134 struct drm_device
*dev
= plane
->dev
;
13135 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
13136 enum pipe pipe
= intel_plane
->pipe
;
13137 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13138 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->fb
);
13139 unsigned frontbuffer_bits
= 0;
13145 switch (plane
->type
) {
13146 case DRM_PLANE_TYPE_PRIMARY
:
13147 frontbuffer_bits
= INTEL_FRONTBUFFER_PRIMARY(pipe
);
13149 case DRM_PLANE_TYPE_CURSOR
:
13150 frontbuffer_bits
= INTEL_FRONTBUFFER_CURSOR(pipe
);
13152 case DRM_PLANE_TYPE_OVERLAY
:
13153 frontbuffer_bits
= INTEL_FRONTBUFFER_SPRITE(pipe
);
13157 mutex_lock(&dev
->struct_mutex
);
13159 if (plane
->type
== DRM_PLANE_TYPE_CURSOR
&&
13160 INTEL_INFO(dev
)->cursor_needs_physical
) {
13161 int align
= IS_I830(dev
) ? 16 * 1024 : 256;
13162 ret
= i915_gem_object_attach_phys(obj
, align
);
13164 DRM_DEBUG_KMS("failed to attach phys object\n");
13166 ret
= intel_pin_and_fence_fb_obj(plane
, fb
, new_state
, NULL
);
13170 i915_gem_track_fb(old_obj
, obj
, frontbuffer_bits
);
13172 mutex_unlock(&dev
->struct_mutex
);
13178 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13179 * @plane: drm plane to clean up for
13180 * @fb: old framebuffer that was on plane
13182 * Cleans up a framebuffer that has just been removed from a plane.
13185 intel_cleanup_plane_fb(struct drm_plane
*plane
,
13186 struct drm_framebuffer
*fb
,
13187 const struct drm_plane_state
*old_state
)
13189 struct drm_device
*dev
= plane
->dev
;
13190 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13195 if (plane
->type
!= DRM_PLANE_TYPE_CURSOR
||
13196 !INTEL_INFO(dev
)->cursor_needs_physical
) {
13197 mutex_lock(&dev
->struct_mutex
);
13198 intel_unpin_fb_obj(fb
, old_state
);
13199 mutex_unlock(&dev
->struct_mutex
);
13204 skl_max_scale(struct intel_crtc
*intel_crtc
, struct intel_crtc_state
*crtc_state
)
13207 struct drm_device
*dev
;
13208 struct drm_i915_private
*dev_priv
;
13209 int crtc_clock
, cdclk
;
13211 if (!intel_crtc
|| !crtc_state
)
13212 return DRM_PLANE_HELPER_NO_SCALING
;
13214 dev
= intel_crtc
->base
.dev
;
13215 dev_priv
= dev
->dev_private
;
13216 crtc_clock
= crtc_state
->base
.adjusted_mode
.crtc_clock
;
13217 cdclk
= dev_priv
->display
.get_display_clock_speed(dev
);
13219 if (!crtc_clock
|| !cdclk
)
13220 return DRM_PLANE_HELPER_NO_SCALING
;
13223 * skl max scale is lower of:
13224 * close to 3 but not 3, -1 is for that purpose
13228 max_scale
= min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk
<< 8) / crtc_clock
));
13234 intel_check_primary_plane(struct drm_plane
*plane
,
13235 struct intel_plane_state
*state
)
13237 struct drm_device
*dev
= plane
->dev
;
13238 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13239 struct drm_crtc
*crtc
= state
->base
.crtc
;
13240 struct intel_crtc
*intel_crtc
;
13241 struct intel_crtc_state
*crtc_state
;
13242 struct drm_framebuffer
*fb
= state
->base
.fb
;
13243 struct drm_rect
*dest
= &state
->dst
;
13244 struct drm_rect
*src
= &state
->src
;
13245 const struct drm_rect
*clip
= &state
->clip
;
13246 bool can_position
= false;
13247 int max_scale
= DRM_PLANE_HELPER_NO_SCALING
;
13248 int min_scale
= DRM_PLANE_HELPER_NO_SCALING
;
13251 crtc
= crtc
? crtc
: plane
->crtc
;
13252 intel_crtc
= to_intel_crtc(crtc
);
13253 crtc_state
= state
->base
.state
?
13254 intel_atomic_get_crtc_state(state
->base
.state
, intel_crtc
) : NULL
;
13256 if (INTEL_INFO(dev
)->gen
>= 9) {
13258 max_scale
= skl_max_scale(intel_crtc
, crtc_state
);
13259 can_position
= true;
13262 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
13266 can_position
, true,
13271 if (intel_crtc
->active
) {
13272 struct intel_plane_state
*old_state
=
13273 to_intel_plane_state(plane
->state
);
13275 intel_crtc
->atomic
.wait_for_flips
= true;
13278 * FBC does not work on some platforms for rotated
13279 * planes, so disable it when rotation is not 0 and
13280 * update it when rotation is set back to 0.
13282 * FIXME: This is redundant with the fbc update done in
13283 * the primary plane enable function except that that
13284 * one is done too late. We eventually need to unify
13287 if (state
->visible
&&
13288 INTEL_INFO(dev
)->gen
<= 4 && !IS_G4X(dev
) &&
13289 dev_priv
->fbc
.crtc
== intel_crtc
&&
13290 state
->base
.rotation
!= BIT(DRM_ROTATE_0
)) {
13291 intel_crtc
->atomic
.disable_fbc
= true;
13294 if (state
->visible
&& !old_state
->visible
) {
13296 * BDW signals flip done immediately if the plane
13297 * is disabled, even if the plane enable is already
13298 * armed to occur at the next vblank :(
13300 if (IS_BROADWELL(dev
))
13301 intel_crtc
->atomic
.wait_vblank
= true;
13304 intel_crtc
->atomic
.fb_bits
|=
13305 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
);
13307 intel_crtc
->atomic
.update_fbc
= true;
13309 if (intel_wm_need_update(plane
, &state
->base
))
13310 intel_crtc
->atomic
.update_wm
= true;
13313 if (INTEL_INFO(dev
)->gen
>= 9) {
13314 ret
= skl_update_scaler_users(intel_crtc
, crtc_state
,
13315 to_intel_plane(plane
), state
, 0);
13324 intel_commit_primary_plane(struct drm_plane
*plane
,
13325 struct intel_plane_state
*state
)
13327 struct drm_crtc
*crtc
= state
->base
.crtc
;
13328 struct drm_framebuffer
*fb
= state
->base
.fb
;
13329 struct drm_device
*dev
= plane
->dev
;
13330 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13331 struct intel_crtc
*intel_crtc
;
13332 struct drm_rect
*src
= &state
->src
;
13334 crtc
= crtc
? crtc
: plane
->crtc
;
13335 intel_crtc
= to_intel_crtc(crtc
);
13338 crtc
->x
= src
->x1
>> 16;
13339 crtc
->y
= src
->y1
>> 16;
13341 if (intel_crtc
->active
) {
13342 if (state
->visible
)
13343 /* FIXME: kill this fastboot hack */
13344 intel_update_pipe_size(intel_crtc
);
13346 dev_priv
->display
.update_primary_plane(crtc
, plane
->fb
,
13352 intel_disable_primary_plane(struct drm_plane
*plane
,
13353 struct drm_crtc
*crtc
,
13356 struct drm_device
*dev
= plane
->dev
;
13357 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13359 dev_priv
->display
.update_primary_plane(crtc
, NULL
, 0, 0);
13362 static void intel_begin_crtc_commit(struct drm_crtc
*crtc
)
13364 struct drm_device
*dev
= crtc
->dev
;
13365 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13366 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13367 struct intel_plane
*intel_plane
;
13368 struct drm_plane
*p
;
13369 unsigned fb_bits
= 0;
13371 /* Track fb's for any planes being disabled */
13372 list_for_each_entry(p
, &dev
->mode_config
.plane_list
, head
) {
13373 intel_plane
= to_intel_plane(p
);
13375 if (intel_crtc
->atomic
.disabled_planes
&
13376 (1 << drm_plane_index(p
))) {
13378 case DRM_PLANE_TYPE_PRIMARY
:
13379 fb_bits
= INTEL_FRONTBUFFER_PRIMARY(intel_plane
->pipe
);
13381 case DRM_PLANE_TYPE_CURSOR
:
13382 fb_bits
= INTEL_FRONTBUFFER_CURSOR(intel_plane
->pipe
);
13384 case DRM_PLANE_TYPE_OVERLAY
:
13385 fb_bits
= INTEL_FRONTBUFFER_SPRITE(intel_plane
->pipe
);
13389 mutex_lock(&dev
->struct_mutex
);
13390 i915_gem_track_fb(intel_fb_obj(p
->fb
), NULL
, fb_bits
);
13391 mutex_unlock(&dev
->struct_mutex
);
13395 if (intel_crtc
->atomic
.wait_for_flips
)
13396 intel_crtc_wait_for_pending_flips(crtc
);
13398 if (intel_crtc
->atomic
.disable_fbc
)
13399 intel_fbc_disable(dev
);
13401 if (intel_crtc
->atomic
.pre_disable_primary
)
13402 intel_pre_disable_primary(crtc
);
13404 if (intel_crtc
->atomic
.update_wm
)
13405 intel_update_watermarks(crtc
);
13407 intel_runtime_pm_get(dev_priv
);
13409 /* Perform vblank evasion around commit operation */
13410 if (intel_crtc
->active
)
13411 intel_crtc
->atomic
.evade
=
13412 intel_pipe_update_start(intel_crtc
,
13413 &intel_crtc
->atomic
.start_vbl_count
);
13416 static void intel_finish_crtc_commit(struct drm_crtc
*crtc
)
13418 struct drm_device
*dev
= crtc
->dev
;
13419 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13420 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13421 struct drm_plane
*p
;
13423 if (intel_crtc
->atomic
.evade
)
13424 intel_pipe_update_end(intel_crtc
,
13425 intel_crtc
->atomic
.start_vbl_count
);
13427 intel_runtime_pm_put(dev_priv
);
13429 if (intel_crtc
->atomic
.wait_vblank
)
13430 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
13432 intel_frontbuffer_flip(dev
, intel_crtc
->atomic
.fb_bits
);
13434 if (intel_crtc
->atomic
.update_fbc
) {
13435 mutex_lock(&dev
->struct_mutex
);
13436 intel_fbc_update(dev
);
13437 mutex_unlock(&dev
->struct_mutex
);
13440 if (intel_crtc
->atomic
.post_enable_primary
)
13441 intel_post_enable_primary(crtc
);
13443 drm_for_each_legacy_plane(p
, &dev
->mode_config
.plane_list
)
13444 if (intel_crtc
->atomic
.update_sprite_watermarks
& drm_plane_index(p
))
13445 intel_update_sprite_watermarks(p
, crtc
, 0, 0, 0,
13448 memset(&intel_crtc
->atomic
, 0, sizeof(intel_crtc
->atomic
));
13452 * intel_plane_destroy - destroy a plane
13453 * @plane: plane to destroy
13455 * Common destruction function for all types of planes (primary, cursor,
13458 void intel_plane_destroy(struct drm_plane
*plane
)
13460 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
13461 drm_plane_cleanup(plane
);
13462 kfree(intel_plane
);
13465 const struct drm_plane_funcs intel_plane_funcs
= {
13466 .update_plane
= drm_atomic_helper_update_plane
,
13467 .disable_plane
= drm_atomic_helper_disable_plane
,
13468 .destroy
= intel_plane_destroy
,
13469 .set_property
= drm_atomic_helper_plane_set_property
,
13470 .atomic_get_property
= intel_plane_atomic_get_property
,
13471 .atomic_set_property
= intel_plane_atomic_set_property
,
13472 .atomic_duplicate_state
= intel_plane_duplicate_state
,
13473 .atomic_destroy_state
= intel_plane_destroy_state
,
13477 static struct drm_plane
*intel_primary_plane_create(struct drm_device
*dev
,
13480 struct intel_plane
*primary
;
13481 struct intel_plane_state
*state
;
13482 const uint32_t *intel_primary_formats
;
13485 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
13486 if (primary
== NULL
)
13489 state
= intel_create_plane_state(&primary
->base
);
13494 primary
->base
.state
= &state
->base
;
13496 primary
->can_scale
= false;
13497 primary
->max_downscale
= 1;
13498 if (INTEL_INFO(dev
)->gen
>= 9) {
13499 primary
->can_scale
= true;
13501 state
->scaler_id
= -1;
13502 primary
->pipe
= pipe
;
13503 primary
->plane
= pipe
;
13504 primary
->check_plane
= intel_check_primary_plane
;
13505 primary
->commit_plane
= intel_commit_primary_plane
;
13506 primary
->disable_plane
= intel_disable_primary_plane
;
13507 primary
->ckey
.flags
= I915_SET_COLORKEY_NONE
;
13508 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4)
13509 primary
->plane
= !pipe
;
13511 if (INTEL_INFO(dev
)->gen
<= 3) {
13512 intel_primary_formats
= intel_primary_formats_gen2
;
13513 num_formats
= ARRAY_SIZE(intel_primary_formats_gen2
);
13515 intel_primary_formats
= intel_primary_formats_gen4
;
13516 num_formats
= ARRAY_SIZE(intel_primary_formats_gen4
);
13519 drm_universal_plane_init(dev
, &primary
->base
, 0,
13520 &intel_plane_funcs
,
13521 intel_primary_formats
, num_formats
,
13522 DRM_PLANE_TYPE_PRIMARY
);
13524 if (INTEL_INFO(dev
)->gen
>= 4)
13525 intel_create_rotation_property(dev
, primary
);
13527 drm_plane_helper_add(&primary
->base
, &intel_plane_helper_funcs
);
13529 return &primary
->base
;
13532 void intel_create_rotation_property(struct drm_device
*dev
, struct intel_plane
*plane
)
13534 if (!dev
->mode_config
.rotation_property
) {
13535 unsigned long flags
= BIT(DRM_ROTATE_0
) |
13536 BIT(DRM_ROTATE_180
);
13538 if (INTEL_INFO(dev
)->gen
>= 9)
13539 flags
|= BIT(DRM_ROTATE_90
) | BIT(DRM_ROTATE_270
);
13541 dev
->mode_config
.rotation_property
=
13542 drm_mode_create_rotation_property(dev
, flags
);
13544 if (dev
->mode_config
.rotation_property
)
13545 drm_object_attach_property(&plane
->base
.base
,
13546 dev
->mode_config
.rotation_property
,
13547 plane
->base
.state
->rotation
);
13551 intel_check_cursor_plane(struct drm_plane
*plane
,
13552 struct intel_plane_state
*state
)
13554 struct drm_crtc
*crtc
= state
->base
.crtc
;
13555 struct drm_device
*dev
= plane
->dev
;
13556 struct drm_framebuffer
*fb
= state
->base
.fb
;
13557 struct drm_rect
*dest
= &state
->dst
;
13558 struct drm_rect
*src
= &state
->src
;
13559 const struct drm_rect
*clip
= &state
->clip
;
13560 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13561 struct intel_crtc
*intel_crtc
;
13565 crtc
= crtc
? crtc
: plane
->crtc
;
13566 intel_crtc
= to_intel_crtc(crtc
);
13568 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
13570 DRM_PLANE_HELPER_NO_SCALING
,
13571 DRM_PLANE_HELPER_NO_SCALING
,
13572 true, true, &state
->visible
);
13577 /* if we want to turn off the cursor ignore width and height */
13581 /* Check for which cursor types we support */
13582 if (!cursor_size_ok(dev
, state
->base
.crtc_w
, state
->base
.crtc_h
)) {
13583 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
13584 state
->base
.crtc_w
, state
->base
.crtc_h
);
13588 stride
= roundup_pow_of_two(state
->base
.crtc_w
) * 4;
13589 if (obj
->base
.size
< stride
* state
->base
.crtc_h
) {
13590 DRM_DEBUG_KMS("buffer is too small\n");
13594 if (fb
->modifier
[0] != DRM_FORMAT_MOD_NONE
) {
13595 DRM_DEBUG_KMS("cursor cannot be tiled\n");
13600 if (intel_crtc
->active
) {
13601 if (plane
->state
->crtc_w
!= state
->base
.crtc_w
)
13602 intel_crtc
->atomic
.update_wm
= true;
13604 intel_crtc
->atomic
.fb_bits
|=
13605 INTEL_FRONTBUFFER_CURSOR(intel_crtc
->pipe
);
13612 intel_disable_cursor_plane(struct drm_plane
*plane
,
13613 struct drm_crtc
*crtc
,
13616 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13620 intel_crtc
->cursor_bo
= NULL
;
13621 intel_crtc
->cursor_addr
= 0;
13624 intel_crtc_update_cursor(crtc
, false);
13628 intel_commit_cursor_plane(struct drm_plane
*plane
,
13629 struct intel_plane_state
*state
)
13631 struct drm_crtc
*crtc
= state
->base
.crtc
;
13632 struct drm_device
*dev
= plane
->dev
;
13633 struct intel_crtc
*intel_crtc
;
13634 struct drm_i915_gem_object
*obj
= intel_fb_obj(state
->base
.fb
);
13637 crtc
= crtc
? crtc
: plane
->crtc
;
13638 intel_crtc
= to_intel_crtc(crtc
);
13640 plane
->fb
= state
->base
.fb
;
13641 crtc
->cursor_x
= state
->base
.crtc_x
;
13642 crtc
->cursor_y
= state
->base
.crtc_y
;
13644 if (intel_crtc
->cursor_bo
== obj
)
13649 else if (!INTEL_INFO(dev
)->cursor_needs_physical
)
13650 addr
= i915_gem_obj_ggtt_offset(obj
);
13652 addr
= obj
->phys_handle
->busaddr
;
13654 intel_crtc
->cursor_addr
= addr
;
13655 intel_crtc
->cursor_bo
= obj
;
13658 if (intel_crtc
->active
)
13659 intel_crtc_update_cursor(crtc
, state
->visible
);
13662 static struct drm_plane
*intel_cursor_plane_create(struct drm_device
*dev
,
13665 struct intel_plane
*cursor
;
13666 struct intel_plane_state
*state
;
13668 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
13669 if (cursor
== NULL
)
13672 state
= intel_create_plane_state(&cursor
->base
);
13677 cursor
->base
.state
= &state
->base
;
13679 cursor
->can_scale
= false;
13680 cursor
->max_downscale
= 1;
13681 cursor
->pipe
= pipe
;
13682 cursor
->plane
= pipe
;
13683 state
->scaler_id
= -1;
13684 cursor
->check_plane
= intel_check_cursor_plane
;
13685 cursor
->commit_plane
= intel_commit_cursor_plane
;
13686 cursor
->disable_plane
= intel_disable_cursor_plane
;
13688 drm_universal_plane_init(dev
, &cursor
->base
, 0,
13689 &intel_plane_funcs
,
13690 intel_cursor_formats
,
13691 ARRAY_SIZE(intel_cursor_formats
),
13692 DRM_PLANE_TYPE_CURSOR
);
13694 if (INTEL_INFO(dev
)->gen
>= 4) {
13695 if (!dev
->mode_config
.rotation_property
)
13696 dev
->mode_config
.rotation_property
=
13697 drm_mode_create_rotation_property(dev
,
13698 BIT(DRM_ROTATE_0
) |
13699 BIT(DRM_ROTATE_180
));
13700 if (dev
->mode_config
.rotation_property
)
13701 drm_object_attach_property(&cursor
->base
.base
,
13702 dev
->mode_config
.rotation_property
,
13703 state
->base
.rotation
);
13706 drm_plane_helper_add(&cursor
->base
, &intel_plane_helper_funcs
);
13708 return &cursor
->base
;
13711 static void skl_init_scalers(struct drm_device
*dev
, struct intel_crtc
*intel_crtc
,
13712 struct intel_crtc_state
*crtc_state
)
13715 struct intel_scaler
*intel_scaler
;
13716 struct intel_crtc_scaler_state
*scaler_state
= &crtc_state
->scaler_state
;
13718 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
13719 intel_scaler
= &scaler_state
->scalers
[i
];
13720 intel_scaler
->in_use
= 0;
13721 intel_scaler
->id
= i
;
13723 intel_scaler
->mode
= PS_SCALER_MODE_DYN
;
13726 scaler_state
->scaler_id
= -1;
13729 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
13731 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13732 struct intel_crtc
*intel_crtc
;
13733 struct intel_crtc_state
*crtc_state
= NULL
;
13734 struct drm_plane
*primary
= NULL
;
13735 struct drm_plane
*cursor
= NULL
;
13738 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
13739 if (intel_crtc
== NULL
)
13742 crtc_state
= kzalloc(sizeof(*crtc_state
), GFP_KERNEL
);
13745 intel_crtc_set_state(intel_crtc
, crtc_state
);
13746 crtc_state
->base
.crtc
= &intel_crtc
->base
;
13748 /* initialize shared scalers */
13749 if (INTEL_INFO(dev
)->gen
>= 9) {
13750 if (pipe
== PIPE_C
)
13751 intel_crtc
->num_scalers
= 1;
13753 intel_crtc
->num_scalers
= SKL_NUM_SCALERS
;
13755 skl_init_scalers(dev
, intel_crtc
, crtc_state
);
13758 primary
= intel_primary_plane_create(dev
, pipe
);
13762 cursor
= intel_cursor_plane_create(dev
, pipe
);
13766 ret
= drm_crtc_init_with_planes(dev
, &intel_crtc
->base
, primary
,
13767 cursor
, &intel_crtc_funcs
);
13771 drm_mode_crtc_set_gamma_size(&intel_crtc
->base
, 256);
13772 for (i
= 0; i
< 256; i
++) {
13773 intel_crtc
->lut_r
[i
] = i
;
13774 intel_crtc
->lut_g
[i
] = i
;
13775 intel_crtc
->lut_b
[i
] = i
;
13779 * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
13780 * is hooked to pipe B. Hence we want plane A feeding pipe B.
13782 intel_crtc
->pipe
= pipe
;
13783 intel_crtc
->plane
= pipe
;
13784 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4) {
13785 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
13786 intel_crtc
->plane
= !pipe
;
13789 intel_crtc
->cursor_base
= ~0;
13790 intel_crtc
->cursor_cntl
= ~0;
13791 intel_crtc
->cursor_size
= ~0;
13793 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
13794 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
13795 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
13796 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
13798 INIT_WORK(&intel_crtc
->mmio_flip
.work
, intel_mmio_flip_work_func
);
13800 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
13802 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
13807 drm_plane_cleanup(primary
);
13809 drm_plane_cleanup(cursor
);
13814 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
13816 struct drm_encoder
*encoder
= connector
->base
.encoder
;
13817 struct drm_device
*dev
= connector
->base
.dev
;
13819 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
13821 if (!encoder
|| WARN_ON(!encoder
->crtc
))
13822 return INVALID_PIPE
;
13824 return to_intel_crtc(encoder
->crtc
)->pipe
;
13827 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
13828 struct drm_file
*file
)
13830 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
13831 struct drm_crtc
*drmmode_crtc
;
13832 struct intel_crtc
*crtc
;
13834 drmmode_crtc
= drm_crtc_find(dev
, pipe_from_crtc_id
->crtc_id
);
13836 if (!drmmode_crtc
) {
13837 DRM_ERROR("no such CRTC id\n");
13841 crtc
= to_intel_crtc(drmmode_crtc
);
13842 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
13847 static int intel_encoder_clones(struct intel_encoder
*encoder
)
13849 struct drm_device
*dev
= encoder
->base
.dev
;
13850 struct intel_encoder
*source_encoder
;
13851 int index_mask
= 0;
13854 for_each_intel_encoder(dev
, source_encoder
) {
13855 if (encoders_cloneable(encoder
, source_encoder
))
13856 index_mask
|= (1 << entry
);
13864 static bool has_edp_a(struct drm_device
*dev
)
13866 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13868 if (!IS_MOBILE(dev
))
13871 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
13874 if (IS_GEN5(dev
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
13880 static bool intel_crt_present(struct drm_device
*dev
)
13882 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13884 if (INTEL_INFO(dev
)->gen
>= 9)
13887 if (IS_HSW_ULT(dev
) || IS_BDW_ULT(dev
))
13890 if (IS_CHERRYVIEW(dev
))
13893 if (IS_VALLEYVIEW(dev
) && !dev_priv
->vbt
.int_crt_support
)
13899 static void intel_setup_outputs(struct drm_device
*dev
)
13901 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13902 struct intel_encoder
*encoder
;
13903 bool dpd_is_edp
= false;
13905 intel_lvds_init(dev
);
13907 if (intel_crt_present(dev
))
13908 intel_crt_init(dev
);
13910 if (IS_BROXTON(dev
)) {
13912 * FIXME: Broxton doesn't support port detection via the
13913 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
13914 * detect the ports.
13916 intel_ddi_init(dev
, PORT_A
);
13917 intel_ddi_init(dev
, PORT_B
);
13918 intel_ddi_init(dev
, PORT_C
);
13919 } else if (HAS_DDI(dev
)) {
13923 * Haswell uses DDI functions to detect digital outputs.
13924 * On SKL pre-D0 the strap isn't connected, so we assume
13927 found
= I915_READ(DDI_BUF_CTL_A
) & DDI_INIT_DISPLAY_DETECTED
;
13928 /* WaIgnoreDDIAStrap: skl */
13930 (IS_SKYLAKE(dev
) && INTEL_REVID(dev
) < SKL_REVID_D0
))
13931 intel_ddi_init(dev
, PORT_A
);
13933 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
13935 found
= I915_READ(SFUSE_STRAP
);
13937 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
13938 intel_ddi_init(dev
, PORT_B
);
13939 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
13940 intel_ddi_init(dev
, PORT_C
);
13941 if (found
& SFUSE_STRAP_DDID_DETECTED
)
13942 intel_ddi_init(dev
, PORT_D
);
13943 } else if (HAS_PCH_SPLIT(dev
)) {
13945 dpd_is_edp
= intel_dp_is_edp(dev
, PORT_D
);
13947 if (has_edp_a(dev
))
13948 intel_dp_init(dev
, DP_A
, PORT_A
);
13950 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
13951 /* PCH SDVOB multiplex with HDMIB */
13952 found
= intel_sdvo_init(dev
, PCH_SDVOB
, true);
13954 intel_hdmi_init(dev
, PCH_HDMIB
, PORT_B
);
13955 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
13956 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
13959 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
13960 intel_hdmi_init(dev
, PCH_HDMIC
, PORT_C
);
13962 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
13963 intel_hdmi_init(dev
, PCH_HDMID
, PORT_D
);
13965 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
13966 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
13968 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
13969 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
13970 } else if (IS_VALLEYVIEW(dev
)) {
13972 * The DP_DETECTED bit is the latched state of the DDC
13973 * SDA pin at boot. However since eDP doesn't require DDC
13974 * (no way to plug in a DP->HDMI dongle) the DDC pins for
13975 * eDP ports may have been muxed to an alternate function.
13976 * Thus we can't rely on the DP_DETECTED bit alone to detect
13977 * eDP ports. Consult the VBT as well as DP_DETECTED to
13978 * detect eDP ports.
13980 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIB
) & SDVO_DETECTED
&&
13981 !intel_dp_is_edp(dev
, PORT_B
))
13982 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIB
,
13984 if (I915_READ(VLV_DISPLAY_BASE
+ DP_B
) & DP_DETECTED
||
13985 intel_dp_is_edp(dev
, PORT_B
))
13986 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_B
, PORT_B
);
13988 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIC
) & SDVO_DETECTED
&&
13989 !intel_dp_is_edp(dev
, PORT_C
))
13990 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIC
,
13992 if (I915_READ(VLV_DISPLAY_BASE
+ DP_C
) & DP_DETECTED
||
13993 intel_dp_is_edp(dev
, PORT_C
))
13994 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_C
, PORT_C
);
13996 if (IS_CHERRYVIEW(dev
)) {
13997 if (I915_READ(VLV_DISPLAY_BASE
+ CHV_HDMID
) & SDVO_DETECTED
)
13998 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ CHV_HDMID
,
14000 /* eDP not supported on port D, so don't check VBT */
14001 if (I915_READ(VLV_DISPLAY_BASE
+ DP_D
) & DP_DETECTED
)
14002 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_D
, PORT_D
);
14005 intel_dsi_init(dev
);
14006 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev
)) {
14007 bool found
= false;
14009 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
14010 DRM_DEBUG_KMS("probing SDVOB\n");
14011 found
= intel_sdvo_init(dev
, GEN3_SDVOB
, true);
14012 if (!found
&& SUPPORTS_INTEGRATED_HDMI(dev
)) {
14013 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
14014 intel_hdmi_init(dev
, GEN4_HDMIB
, PORT_B
);
14017 if (!found
&& SUPPORTS_INTEGRATED_DP(dev
))
14018 intel_dp_init(dev
, DP_B
, PORT_B
);
14021 /* Before G4X SDVOC doesn't have its own detect register */
14023 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
14024 DRM_DEBUG_KMS("probing SDVOC\n");
14025 found
= intel_sdvo_init(dev
, GEN3_SDVOC
, false);
14028 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
14030 if (SUPPORTS_INTEGRATED_HDMI(dev
)) {
14031 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
14032 intel_hdmi_init(dev
, GEN4_HDMIC
, PORT_C
);
14034 if (SUPPORTS_INTEGRATED_DP(dev
))
14035 intel_dp_init(dev
, DP_C
, PORT_C
);
14038 if (SUPPORTS_INTEGRATED_DP(dev
) &&
14039 (I915_READ(DP_D
) & DP_DETECTED
))
14040 intel_dp_init(dev
, DP_D
, PORT_D
);
14041 } else if (IS_GEN2(dev
))
14042 intel_dvo_init(dev
);
14044 if (SUPPORTS_TV(dev
))
14045 intel_tv_init(dev
);
14047 intel_psr_init(dev
);
14049 for_each_intel_encoder(dev
, encoder
) {
14050 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
14051 encoder
->base
.possible_clones
=
14052 intel_encoder_clones(encoder
);
14055 intel_init_pch_refclk(dev
);
14057 drm_helper_move_panel_connectors_to_head(dev
);
14060 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
14062 struct drm_device
*dev
= fb
->dev
;
14063 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
14065 drm_framebuffer_cleanup(fb
);
14066 mutex_lock(&dev
->struct_mutex
);
14067 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
14068 drm_gem_object_unreference(&intel_fb
->obj
->base
);
14069 mutex_unlock(&dev
->struct_mutex
);
14073 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
14074 struct drm_file
*file
,
14075 unsigned int *handle
)
14077 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
14078 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
14080 return drm_gem_handle_create(file
, &obj
->base
, handle
);
14083 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
14084 .destroy
= intel_user_framebuffer_destroy
,
14085 .create_handle
= intel_user_framebuffer_create_handle
,
14089 u32
intel_fb_pitch_limit(struct drm_device
*dev
, uint64_t fb_modifier
,
14090 uint32_t pixel_format
)
14092 u32 gen
= INTEL_INFO(dev
)->gen
;
14095 /* "The stride in bytes must not exceed the of the size of 8K
14096 * pixels and 32K bytes."
14098 return min(8192*drm_format_plane_cpp(pixel_format
, 0), 32768);
14099 } else if (gen
>= 5 && !IS_VALLEYVIEW(dev
)) {
14101 } else if (gen
>= 4) {
14102 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
14106 } else if (gen
>= 3) {
14107 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
14112 /* XXX DSPC is limited to 4k tiled */
14117 static int intel_framebuffer_init(struct drm_device
*dev
,
14118 struct intel_framebuffer
*intel_fb
,
14119 struct drm_mode_fb_cmd2
*mode_cmd
,
14120 struct drm_i915_gem_object
*obj
)
14122 unsigned int aligned_height
;
14124 u32 pitch_limit
, stride_alignment
;
14126 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
14128 if (mode_cmd
->flags
& DRM_MODE_FB_MODIFIERS
) {
14129 /* Enforce that fb modifier and tiling mode match, but only for
14130 * X-tiled. This is needed for FBC. */
14131 if (!!(obj
->tiling_mode
== I915_TILING_X
) !=
14132 !!(mode_cmd
->modifier
[0] == I915_FORMAT_MOD_X_TILED
)) {
14133 DRM_DEBUG("tiling_mode doesn't match fb modifier\n");
14137 if (obj
->tiling_mode
== I915_TILING_X
)
14138 mode_cmd
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
14139 else if (obj
->tiling_mode
== I915_TILING_Y
) {
14140 DRM_DEBUG("No Y tiling for legacy addfb\n");
14145 /* Passed in modifier sanity checking. */
14146 switch (mode_cmd
->modifier
[0]) {
14147 case I915_FORMAT_MOD_Y_TILED
:
14148 case I915_FORMAT_MOD_Yf_TILED
:
14149 if (INTEL_INFO(dev
)->gen
< 9) {
14150 DRM_DEBUG("Unsupported tiling 0x%llx!\n",
14151 mode_cmd
->modifier
[0]);
14154 case DRM_FORMAT_MOD_NONE
:
14155 case I915_FORMAT_MOD_X_TILED
:
14158 DRM_DEBUG("Unsupported fb modifier 0x%llx!\n",
14159 mode_cmd
->modifier
[0]);
14163 stride_alignment
= intel_fb_stride_alignment(dev
, mode_cmd
->modifier
[0],
14164 mode_cmd
->pixel_format
);
14165 if (mode_cmd
->pitches
[0] & (stride_alignment
- 1)) {
14166 DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n",
14167 mode_cmd
->pitches
[0], stride_alignment
);
14171 pitch_limit
= intel_fb_pitch_limit(dev
, mode_cmd
->modifier
[0],
14172 mode_cmd
->pixel_format
);
14173 if (mode_cmd
->pitches
[0] > pitch_limit
) {
14174 DRM_DEBUG("%s pitch (%u) must be at less than %d\n",
14175 mode_cmd
->modifier
[0] != DRM_FORMAT_MOD_NONE
?
14176 "tiled" : "linear",
14177 mode_cmd
->pitches
[0], pitch_limit
);
14181 if (mode_cmd
->modifier
[0] == I915_FORMAT_MOD_X_TILED
&&
14182 mode_cmd
->pitches
[0] != obj
->stride
) {
14183 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
14184 mode_cmd
->pitches
[0], obj
->stride
);
14188 /* Reject formats not supported by any plane early. */
14189 switch (mode_cmd
->pixel_format
) {
14190 case DRM_FORMAT_C8
:
14191 case DRM_FORMAT_RGB565
:
14192 case DRM_FORMAT_XRGB8888
:
14193 case DRM_FORMAT_ARGB8888
:
14195 case DRM_FORMAT_XRGB1555
:
14196 case DRM_FORMAT_ARGB1555
:
14197 if (INTEL_INFO(dev
)->gen
> 3) {
14198 DRM_DEBUG("unsupported pixel format: %s\n",
14199 drm_get_format_name(mode_cmd
->pixel_format
));
14203 case DRM_FORMAT_XBGR8888
:
14204 case DRM_FORMAT_ABGR8888
:
14205 case DRM_FORMAT_XRGB2101010
:
14206 case DRM_FORMAT_ARGB2101010
:
14207 case DRM_FORMAT_XBGR2101010
:
14208 case DRM_FORMAT_ABGR2101010
:
14209 if (INTEL_INFO(dev
)->gen
< 4) {
14210 DRM_DEBUG("unsupported pixel format: %s\n",
14211 drm_get_format_name(mode_cmd
->pixel_format
));
14215 case DRM_FORMAT_YUYV
:
14216 case DRM_FORMAT_UYVY
:
14217 case DRM_FORMAT_YVYU
:
14218 case DRM_FORMAT_VYUY
:
14219 if (INTEL_INFO(dev
)->gen
< 5) {
14220 DRM_DEBUG("unsupported pixel format: %s\n",
14221 drm_get_format_name(mode_cmd
->pixel_format
));
14226 DRM_DEBUG("unsupported pixel format: %s\n",
14227 drm_get_format_name(mode_cmd
->pixel_format
));
14231 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14232 if (mode_cmd
->offsets
[0] != 0)
14235 aligned_height
= intel_fb_align_height(dev
, mode_cmd
->height
,
14236 mode_cmd
->pixel_format
,
14237 mode_cmd
->modifier
[0]);
14238 /* FIXME drm helper for size checks (especially planar formats)? */
14239 if (obj
->base
.size
< aligned_height
* mode_cmd
->pitches
[0])
14242 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
14243 intel_fb
->obj
= obj
;
14244 intel_fb
->obj
->framebuffer_references
++;
14246 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
14248 DRM_ERROR("framebuffer init failed %d\n", ret
);
14255 static struct drm_framebuffer
*
14256 intel_user_framebuffer_create(struct drm_device
*dev
,
14257 struct drm_file
*filp
,
14258 struct drm_mode_fb_cmd2
*mode_cmd
)
14260 struct drm_i915_gem_object
*obj
;
14262 obj
= to_intel_bo(drm_gem_object_lookup(dev
, filp
,
14263 mode_cmd
->handles
[0]));
14264 if (&obj
->base
== NULL
)
14265 return ERR_PTR(-ENOENT
);
14267 return intel_framebuffer_create(dev
, mode_cmd
, obj
);
14270 #ifndef CONFIG_DRM_I915_FBDEV
14271 static inline void intel_fbdev_output_poll_changed(struct drm_device
*dev
)
14276 static const struct drm_mode_config_funcs intel_mode_funcs
= {
14277 .fb_create
= intel_user_framebuffer_create
,
14278 .output_poll_changed
= intel_fbdev_output_poll_changed
,
14279 .atomic_check
= intel_atomic_check
,
14280 .atomic_commit
= intel_atomic_commit
,
14283 /* Set up chip specific display functions */
14284 static void intel_init_display(struct drm_device
*dev
)
14286 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14288 if (HAS_PCH_SPLIT(dev
) || IS_G4X(dev
))
14289 dev_priv
->display
.find_dpll
= g4x_find_best_dpll
;
14290 else if (IS_CHERRYVIEW(dev
))
14291 dev_priv
->display
.find_dpll
= chv_find_best_dpll
;
14292 else if (IS_VALLEYVIEW(dev
))
14293 dev_priv
->display
.find_dpll
= vlv_find_best_dpll
;
14294 else if (IS_PINEVIEW(dev
))
14295 dev_priv
->display
.find_dpll
= pnv_find_best_dpll
;
14297 dev_priv
->display
.find_dpll
= i9xx_find_best_dpll
;
14299 if (INTEL_INFO(dev
)->gen
>= 9) {
14300 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
14301 dev_priv
->display
.get_initial_plane_config
=
14302 skylake_get_initial_plane_config
;
14303 dev_priv
->display
.crtc_compute_clock
=
14304 haswell_crtc_compute_clock
;
14305 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
14306 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
14307 dev_priv
->display
.off
= ironlake_crtc_off
;
14308 dev_priv
->display
.update_primary_plane
=
14309 skylake_update_primary_plane
;
14310 } else if (HAS_DDI(dev
)) {
14311 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
14312 dev_priv
->display
.get_initial_plane_config
=
14313 ironlake_get_initial_plane_config
;
14314 dev_priv
->display
.crtc_compute_clock
=
14315 haswell_crtc_compute_clock
;
14316 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
14317 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
14318 dev_priv
->display
.off
= ironlake_crtc_off
;
14319 dev_priv
->display
.update_primary_plane
=
14320 ironlake_update_primary_plane
;
14321 } else if (HAS_PCH_SPLIT(dev
)) {
14322 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
14323 dev_priv
->display
.get_initial_plane_config
=
14324 ironlake_get_initial_plane_config
;
14325 dev_priv
->display
.crtc_compute_clock
=
14326 ironlake_crtc_compute_clock
;
14327 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
14328 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
14329 dev_priv
->display
.off
= ironlake_crtc_off
;
14330 dev_priv
->display
.update_primary_plane
=
14331 ironlake_update_primary_plane
;
14332 } else if (IS_VALLEYVIEW(dev
)) {
14333 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14334 dev_priv
->display
.get_initial_plane_config
=
14335 i9xx_get_initial_plane_config
;
14336 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
14337 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
14338 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14339 dev_priv
->display
.off
= i9xx_crtc_off
;
14340 dev_priv
->display
.update_primary_plane
=
14341 i9xx_update_primary_plane
;
14343 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14344 dev_priv
->display
.get_initial_plane_config
=
14345 i9xx_get_initial_plane_config
;
14346 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
14347 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14348 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14349 dev_priv
->display
.off
= i9xx_crtc_off
;
14350 dev_priv
->display
.update_primary_plane
=
14351 i9xx_update_primary_plane
;
14354 /* Returns the core display clock speed */
14355 if (IS_SKYLAKE(dev
))
14356 dev_priv
->display
.get_display_clock_speed
=
14357 skylake_get_display_clock_speed
;
14358 else if (IS_BROADWELL(dev
))
14359 dev_priv
->display
.get_display_clock_speed
=
14360 broadwell_get_display_clock_speed
;
14361 else if (IS_HASWELL(dev
))
14362 dev_priv
->display
.get_display_clock_speed
=
14363 haswell_get_display_clock_speed
;
14364 else if (IS_VALLEYVIEW(dev
))
14365 dev_priv
->display
.get_display_clock_speed
=
14366 valleyview_get_display_clock_speed
;
14367 else if (IS_GEN5(dev
))
14368 dev_priv
->display
.get_display_clock_speed
=
14369 ilk_get_display_clock_speed
;
14370 else if (IS_I945G(dev
) || IS_BROADWATER(dev
) ||
14371 IS_GEN6(dev
) || IS_IVYBRIDGE(dev
) || (IS_G33(dev
) && !IS_PINEVIEW_M(dev
)))
14372 dev_priv
->display
.get_display_clock_speed
=
14373 i945_get_display_clock_speed
;
14374 else if (IS_I915G(dev
))
14375 dev_priv
->display
.get_display_clock_speed
=
14376 i915_get_display_clock_speed
;
14377 else if (IS_I945GM(dev
) || IS_845G(dev
))
14378 dev_priv
->display
.get_display_clock_speed
=
14379 i9xx_misc_get_display_clock_speed
;
14380 else if (IS_PINEVIEW(dev
))
14381 dev_priv
->display
.get_display_clock_speed
=
14382 pnv_get_display_clock_speed
;
14383 else if (IS_I915GM(dev
))
14384 dev_priv
->display
.get_display_clock_speed
=
14385 i915gm_get_display_clock_speed
;
14386 else if (IS_I865G(dev
))
14387 dev_priv
->display
.get_display_clock_speed
=
14388 i865_get_display_clock_speed
;
14389 else if (IS_I85X(dev
))
14390 dev_priv
->display
.get_display_clock_speed
=
14391 i855_get_display_clock_speed
;
14392 else /* 852, 830 */
14393 dev_priv
->display
.get_display_clock_speed
=
14394 i830_get_display_clock_speed
;
14396 if (IS_GEN5(dev
)) {
14397 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
14398 } else if (IS_GEN6(dev
)) {
14399 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
14400 } else if (IS_IVYBRIDGE(dev
)) {
14401 /* FIXME: detect B0+ stepping and use auto training */
14402 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
14403 } else if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
14404 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
14405 } else if (IS_VALLEYVIEW(dev
)) {
14406 dev_priv
->display
.modeset_global_resources
=
14407 valleyview_modeset_global_resources
;
14408 } else if (IS_BROXTON(dev
)) {
14409 dev_priv
->display
.modeset_global_resources
=
14410 broxton_modeset_global_resources
;
14413 switch (INTEL_INFO(dev
)->gen
) {
14415 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
14419 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
14424 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
14428 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
14431 case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
14432 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
14435 /* Drop through - unsupported since execlist only. */
14437 /* Default just returns -ENODEV to indicate unsupported */
14438 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
14441 intel_panel_init_backlight_funcs(dev
);
14443 mutex_init(&dev_priv
->pps_mutex
);
14447 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
14448 * resume, or other times. This quirk makes sure that's the case for
14449 * affected systems.
14451 static void quirk_pipea_force(struct drm_device
*dev
)
14453 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14455 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
14456 DRM_INFO("applying pipe a force quirk\n");
14459 static void quirk_pipeb_force(struct drm_device
*dev
)
14461 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14463 dev_priv
->quirks
|= QUIRK_PIPEB_FORCE
;
14464 DRM_INFO("applying pipe b force quirk\n");
14468 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
14470 static void quirk_ssc_force_disable(struct drm_device
*dev
)
14472 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14473 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
14474 DRM_INFO("applying lvds SSC disable quirk\n");
14478 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
14481 static void quirk_invert_brightness(struct drm_device
*dev
)
14483 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14484 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
14485 DRM_INFO("applying inverted panel brightness quirk\n");
14488 /* Some VBT's incorrectly indicate no backlight is present */
14489 static void quirk_backlight_present(struct drm_device
*dev
)
14491 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14492 dev_priv
->quirks
|= QUIRK_BACKLIGHT_PRESENT
;
14493 DRM_INFO("applying backlight present quirk\n");
14496 struct intel_quirk
{
14498 int subsystem_vendor
;
14499 int subsystem_device
;
14500 void (*hook
)(struct drm_device
*dev
);
14503 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
14504 struct intel_dmi_quirk
{
14505 void (*hook
)(struct drm_device
*dev
);
14506 const struct dmi_system_id (*dmi_id_list
)[];
14509 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
14511 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
14515 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
14517 .dmi_id_list
= &(const struct dmi_system_id
[]) {
14519 .callback
= intel_dmi_reverse_brightness
,
14520 .ident
= "NCR Corporation",
14521 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
14522 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
14525 { } /* terminating entry */
14527 .hook
= quirk_invert_brightness
,
14531 static struct intel_quirk intel_quirks
[] = {
14532 /* HP Mini needs pipe A force quirk (LP: #322104) */
14533 { 0x27ae, 0x103c, 0x361a, quirk_pipea_force
},
14535 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
14536 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
14538 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
14539 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
14541 /* 830 needs to leave pipe A & dpll A up */
14542 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
14544 /* 830 needs to leave pipe B & dpll B up */
14545 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipeb_force
},
14547 /* Lenovo U160 cannot use SSC on LVDS */
14548 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
14550 /* Sony Vaio Y cannot use SSC on LVDS */
14551 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
14553 /* Acer Aspire 5734Z must invert backlight brightness */
14554 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
14556 /* Acer/eMachines G725 */
14557 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
14559 /* Acer/eMachines e725 */
14560 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
14562 /* Acer/Packard Bell NCL20 */
14563 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
14565 /* Acer Aspire 4736Z */
14566 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
14568 /* Acer Aspire 5336 */
14569 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
14571 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
14572 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present
},
14574 /* Acer C720 Chromebook (Core i3 4005U) */
14575 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present
},
14577 /* Apple Macbook 2,1 (Core 2 T7400) */
14578 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present
},
14580 /* Toshiba CB35 Chromebook (Celeron 2955U) */
14581 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present
},
14583 /* HP Chromebook 14 (Celeron 2955U) */
14584 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present
},
14586 /* Dell Chromebook 11 */
14587 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present
},
14590 static void intel_init_quirks(struct drm_device
*dev
)
14592 struct pci_dev
*d
= dev
->pdev
;
14595 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
14596 struct intel_quirk
*q
= &intel_quirks
[i
];
14598 if (d
->device
== q
->device
&&
14599 (d
->subsystem_vendor
== q
->subsystem_vendor
||
14600 q
->subsystem_vendor
== PCI_ANY_ID
) &&
14601 (d
->subsystem_device
== q
->subsystem_device
||
14602 q
->subsystem_device
== PCI_ANY_ID
))
14605 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
14606 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
14607 intel_dmi_quirks
[i
].hook(dev
);
14611 /* Disable the VGA plane that we never use */
14612 static void i915_disable_vga(struct drm_device
*dev
)
14614 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14616 u32 vga_reg
= i915_vgacntrl_reg(dev
);
14618 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
14619 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
14620 outb(SR01
, VGA_SR_INDEX
);
14621 sr1
= inb(VGA_SR_DATA
);
14622 outb(sr1
| 1<<5, VGA_SR_DATA
);
14623 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
14626 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
14627 POSTING_READ(vga_reg
);
14630 void intel_modeset_init_hw(struct drm_device
*dev
)
14632 intel_prepare_ddi(dev
);
14634 if (IS_VALLEYVIEW(dev
))
14635 vlv_update_cdclk(dev
);
14637 intel_init_clock_gating(dev
);
14639 intel_enable_gt_powersave(dev
);
14642 void intel_modeset_init(struct drm_device
*dev
)
14644 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14647 struct intel_crtc
*crtc
;
14649 drm_mode_config_init(dev
);
14651 dev
->mode_config
.min_width
= 0;
14652 dev
->mode_config
.min_height
= 0;
14654 dev
->mode_config
.preferred_depth
= 24;
14655 dev
->mode_config
.prefer_shadow
= 1;
14657 dev
->mode_config
.allow_fb_modifiers
= true;
14659 dev
->mode_config
.funcs
= &intel_mode_funcs
;
14661 intel_init_quirks(dev
);
14663 intel_init_pm(dev
);
14665 if (INTEL_INFO(dev
)->num_pipes
== 0)
14668 intel_init_display(dev
);
14669 intel_init_audio(dev
);
14671 if (IS_GEN2(dev
)) {
14672 dev
->mode_config
.max_width
= 2048;
14673 dev
->mode_config
.max_height
= 2048;
14674 } else if (IS_GEN3(dev
)) {
14675 dev
->mode_config
.max_width
= 4096;
14676 dev
->mode_config
.max_height
= 4096;
14678 dev
->mode_config
.max_width
= 8192;
14679 dev
->mode_config
.max_height
= 8192;
14682 if (IS_845G(dev
) || IS_I865G(dev
)) {
14683 dev
->mode_config
.cursor_width
= IS_845G(dev
) ? 64 : 512;
14684 dev
->mode_config
.cursor_height
= 1023;
14685 } else if (IS_GEN2(dev
)) {
14686 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
14687 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
14689 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
14690 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
14693 dev
->mode_config
.fb_base
= dev_priv
->gtt
.mappable_base
;
14695 DRM_DEBUG_KMS("%d display pipe%s available.\n",
14696 INTEL_INFO(dev
)->num_pipes
,
14697 INTEL_INFO(dev
)->num_pipes
> 1 ? "s" : "");
14699 for_each_pipe(dev_priv
, pipe
) {
14700 intel_crtc_init(dev
, pipe
);
14701 for_each_sprite(dev_priv
, pipe
, sprite
) {
14702 ret
= intel_plane_init(dev
, pipe
, sprite
);
14704 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
14705 pipe_name(pipe
), sprite_name(pipe
, sprite
), ret
);
14709 intel_init_dpio(dev
);
14711 intel_shared_dpll_init(dev
);
14713 /* Just disable it once at startup */
14714 i915_disable_vga(dev
);
14715 intel_setup_outputs(dev
);
14717 /* Just in case the BIOS is doing something questionable. */
14718 intel_fbc_disable(dev
);
14720 drm_modeset_lock_all(dev
);
14721 intel_modeset_setup_hw_state(dev
, false);
14722 drm_modeset_unlock_all(dev
);
14724 for_each_intel_crtc(dev
, crtc
) {
14729 * Note that reserving the BIOS fb up front prevents us
14730 * from stuffing other stolen allocations like the ring
14731 * on top. This prevents some ugliness at boot time, and
14732 * can even allow for smooth boot transitions if the BIOS
14733 * fb is large enough for the active pipe configuration.
14735 if (dev_priv
->display
.get_initial_plane_config
) {
14736 dev_priv
->display
.get_initial_plane_config(crtc
,
14737 &crtc
->plane_config
);
14739 * If the fb is shared between multiple heads, we'll
14740 * just get the first one.
14742 intel_find_initial_plane_obj(crtc
, &crtc
->plane_config
);
14747 static void intel_enable_pipe_a(struct drm_device
*dev
)
14749 struct intel_connector
*connector
;
14750 struct drm_connector
*crt
= NULL
;
14751 struct intel_load_detect_pipe load_detect_temp
;
14752 struct drm_modeset_acquire_ctx
*ctx
= dev
->mode_config
.acquire_ctx
;
14754 /* We can't just switch on the pipe A, we need to set things up with a
14755 * proper mode and output configuration. As a gross hack, enable pipe A
14756 * by enabling the load detect pipe once. */
14757 for_each_intel_connector(dev
, connector
) {
14758 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
14759 crt
= &connector
->base
;
14767 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
, ctx
))
14768 intel_release_load_detect_pipe(crt
, &load_detect_temp
, ctx
);
14772 intel_check_plane_mapping(struct intel_crtc
*crtc
)
14774 struct drm_device
*dev
= crtc
->base
.dev
;
14775 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14778 if (INTEL_INFO(dev
)->num_pipes
== 1)
14781 reg
= DSPCNTR(!crtc
->plane
);
14782 val
= I915_READ(reg
);
14784 if ((val
& DISPLAY_PLANE_ENABLE
) &&
14785 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
14791 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
14793 struct drm_device
*dev
= crtc
->base
.dev
;
14794 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14797 /* Clear any frame start delays used for debugging left by the BIOS */
14798 reg
= PIPECONF(crtc
->config
->cpu_transcoder
);
14799 I915_WRITE(reg
, I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
14801 /* restore vblank interrupts to correct state */
14802 drm_crtc_vblank_reset(&crtc
->base
);
14803 if (crtc
->active
) {
14804 update_scanline_offset(crtc
);
14805 drm_crtc_vblank_on(&crtc
->base
);
14808 /* We need to sanitize the plane -> pipe mapping first because this will
14809 * disable the crtc (and hence change the state) if it is wrong. Note
14810 * that gen4+ has a fixed plane -> pipe mapping. */
14811 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
14812 struct intel_connector
*connector
;
14815 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
14816 crtc
->base
.base
.id
);
14818 /* Pipe has the wrong plane attached and the plane is active.
14819 * Temporarily change the plane mapping and disable everything
14821 plane
= crtc
->plane
;
14822 to_intel_plane_state(crtc
->base
.primary
->state
)->visible
= true;
14823 crtc
->plane
= !plane
;
14824 intel_crtc_disable_planes(&crtc
->base
);
14825 dev_priv
->display
.crtc_disable(&crtc
->base
);
14826 crtc
->plane
= plane
;
14828 /* ... and break all links. */
14829 for_each_intel_connector(dev
, connector
) {
14830 if (connector
->encoder
->base
.crtc
!= &crtc
->base
)
14833 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
14834 connector
->base
.encoder
= NULL
;
14836 /* multiple connectors may have the same encoder:
14837 * handle them and break crtc link separately */
14838 for_each_intel_connector(dev
, connector
)
14839 if (connector
->encoder
->base
.crtc
== &crtc
->base
) {
14840 connector
->encoder
->base
.crtc
= NULL
;
14841 connector
->encoder
->connectors_active
= false;
14844 WARN_ON(crtc
->active
);
14845 crtc
->base
.state
->enable
= false;
14846 crtc
->base
.enabled
= false;
14849 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
14850 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
14851 /* BIOS forgot to enable pipe A, this mostly happens after
14852 * resume. Force-enable the pipe to fix this, the update_dpms
14853 * call below we restore the pipe to the right state, but leave
14854 * the required bits on. */
14855 intel_enable_pipe_a(dev
);
14858 /* Adjust the state of the output pipe according to whether we
14859 * have active connectors/encoders. */
14860 intel_crtc_update_dpms(&crtc
->base
);
14862 if (crtc
->active
!= crtc
->base
.state
->enable
) {
14863 struct intel_encoder
*encoder
;
14865 /* This can happen either due to bugs in the get_hw_state
14866 * functions or because the pipe is force-enabled due to the
14868 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
14869 crtc
->base
.base
.id
,
14870 crtc
->base
.state
->enable
? "enabled" : "disabled",
14871 crtc
->active
? "enabled" : "disabled");
14873 crtc
->base
.state
->enable
= crtc
->active
;
14874 crtc
->base
.enabled
= crtc
->active
;
14876 /* Because we only establish the connector -> encoder ->
14877 * crtc links if something is active, this means the
14878 * crtc is now deactivated. Break the links. connector
14879 * -> encoder links are only establish when things are
14880 * actually up, hence no need to break them. */
14881 WARN_ON(crtc
->active
);
14883 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
14884 WARN_ON(encoder
->connectors_active
);
14885 encoder
->base
.crtc
= NULL
;
14889 if (crtc
->active
|| HAS_GMCH_DISPLAY(dev
)) {
14891 * We start out with underrun reporting disabled to avoid races.
14892 * For correct bookkeeping mark this on active crtcs.
14894 * Also on gmch platforms we dont have any hardware bits to
14895 * disable the underrun reporting. Which means we need to start
14896 * out with underrun reporting disabled also on inactive pipes,
14897 * since otherwise we'll complain about the garbage we read when
14898 * e.g. coming up after runtime pm.
14900 * No protection against concurrent access is required - at
14901 * worst a fifo underrun happens which also sets this to false.
14903 crtc
->cpu_fifo_underrun_disabled
= true;
14904 crtc
->pch_fifo_underrun_disabled
= true;
14908 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
14910 struct intel_connector
*connector
;
14911 struct drm_device
*dev
= encoder
->base
.dev
;
14913 /* We need to check both for a crtc link (meaning that the
14914 * encoder is active and trying to read from a pipe) and the
14915 * pipe itself being active. */
14916 bool has_active_crtc
= encoder
->base
.crtc
&&
14917 to_intel_crtc(encoder
->base
.crtc
)->active
;
14919 if (encoder
->connectors_active
&& !has_active_crtc
) {
14920 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
14921 encoder
->base
.base
.id
,
14922 encoder
->base
.name
);
14924 /* Connector is active, but has no active pipe. This is
14925 * fallout from our resume register restoring. Disable
14926 * the encoder manually again. */
14927 if (encoder
->base
.crtc
) {
14928 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
14929 encoder
->base
.base
.id
,
14930 encoder
->base
.name
);
14931 encoder
->disable(encoder
);
14932 if (encoder
->post_disable
)
14933 encoder
->post_disable(encoder
);
14935 encoder
->base
.crtc
= NULL
;
14936 encoder
->connectors_active
= false;
14938 /* Inconsistent output/port/pipe state happens presumably due to
14939 * a bug in one of the get_hw_state functions. Or someplace else
14940 * in our code, like the register restore mess on resume. Clamp
14941 * things to off as a safer default. */
14942 for_each_intel_connector(dev
, connector
) {
14943 if (connector
->encoder
!= encoder
)
14945 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
14946 connector
->base
.encoder
= NULL
;
14949 /* Enabled encoders without active connectors will be fixed in
14950 * the crtc fixup. */
14953 void i915_redisable_vga_power_on(struct drm_device
*dev
)
14955 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14956 u32 vga_reg
= i915_vgacntrl_reg(dev
);
14958 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
14959 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
14960 i915_disable_vga(dev
);
14964 void i915_redisable_vga(struct drm_device
*dev
)
14966 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14968 /* This function can be called both from intel_modeset_setup_hw_state or
14969 * at a very early point in our resume sequence, where the power well
14970 * structures are not yet restored. Since this function is at a very
14971 * paranoid "someone might have enabled VGA while we were not looking"
14972 * level, just check if the power well is enabled instead of trying to
14973 * follow the "don't touch the power well if we don't need it" policy
14974 * the rest of the driver uses. */
14975 if (!intel_display_power_is_enabled(dev_priv
, POWER_DOMAIN_VGA
))
14978 i915_redisable_vga_power_on(dev
);
14981 static bool primary_get_hw_state(struct intel_crtc
*crtc
)
14983 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
14988 return I915_READ(DSPCNTR(crtc
->plane
)) & DISPLAY_PLANE_ENABLE
;
14991 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
14993 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14995 struct intel_crtc
*crtc
;
14996 struct intel_encoder
*encoder
;
14997 struct intel_connector
*connector
;
15000 for_each_intel_crtc(dev
, crtc
) {
15001 struct drm_plane
*primary
= crtc
->base
.primary
;
15002 struct intel_plane_state
*plane_state
;
15004 memset(crtc
->config
, 0, sizeof(*crtc
->config
));
15006 crtc
->config
->quirks
|= PIPE_CONFIG_QUIRK_INHERITED_MODE
;
15008 crtc
->active
= dev_priv
->display
.get_pipe_config(crtc
,
15011 crtc
->base
.state
->enable
= crtc
->active
;
15012 crtc
->base
.enabled
= crtc
->active
;
15014 plane_state
= to_intel_plane_state(primary
->state
);
15015 plane_state
->visible
= primary_get_hw_state(crtc
);
15017 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
15018 crtc
->base
.base
.id
,
15019 crtc
->active
? "enabled" : "disabled");
15022 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
15023 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
15025 pll
->on
= pll
->get_hw_state(dev_priv
, pll
,
15026 &pll
->config
.hw_state
);
15028 pll
->config
.crtc_mask
= 0;
15029 for_each_intel_crtc(dev
, crtc
) {
15030 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
) {
15032 pll
->config
.crtc_mask
|= 1 << crtc
->pipe
;
15036 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15037 pll
->name
, pll
->config
.crtc_mask
, pll
->on
);
15039 if (pll
->config
.crtc_mask
)
15040 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
15043 for_each_intel_encoder(dev
, encoder
) {
15046 if (encoder
->get_hw_state(encoder
, &pipe
)) {
15047 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
15048 encoder
->base
.crtc
= &crtc
->base
;
15049 encoder
->get_config(encoder
, crtc
->config
);
15051 encoder
->base
.crtc
= NULL
;
15054 encoder
->connectors_active
= false;
15055 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15056 encoder
->base
.base
.id
,
15057 encoder
->base
.name
,
15058 encoder
->base
.crtc
? "enabled" : "disabled",
15062 for_each_intel_connector(dev
, connector
) {
15063 if (connector
->get_hw_state(connector
)) {
15064 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
15065 connector
->encoder
->connectors_active
= true;
15066 connector
->base
.encoder
= &connector
->encoder
->base
;
15068 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
15069 connector
->base
.encoder
= NULL
;
15071 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
15072 connector
->base
.base
.id
,
15073 connector
->base
.name
,
15074 connector
->base
.encoder
? "enabled" : "disabled");
15078 /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
15079 * and i915 state tracking structures. */
15080 void intel_modeset_setup_hw_state(struct drm_device
*dev
,
15081 bool force_restore
)
15083 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15085 struct intel_crtc
*crtc
;
15086 struct intel_encoder
*encoder
;
15089 intel_modeset_readout_hw_state(dev
);
15092 * Now that we have the config, copy it to each CRTC struct
15093 * Note that this could go away if we move to using crtc_config
15094 * checking everywhere.
15096 for_each_intel_crtc(dev
, crtc
) {
15097 if (crtc
->active
&& i915
.fastboot
) {
15098 intel_mode_from_pipe_config(&crtc
->base
.mode
,
15100 DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
15101 crtc
->base
.base
.id
);
15102 drm_mode_debug_printmodeline(&crtc
->base
.mode
);
15106 /* HW state is read out, now we need to sanitize this mess. */
15107 for_each_intel_encoder(dev
, encoder
) {
15108 intel_sanitize_encoder(encoder
);
15111 for_each_pipe(dev_priv
, pipe
) {
15112 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
15113 intel_sanitize_crtc(crtc
);
15114 intel_dump_pipe_config(crtc
, crtc
->config
,
15115 "[setup_hw_state]");
15118 intel_modeset_update_connector_atomic_state(dev
);
15120 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
15121 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
15123 if (!pll
->on
|| pll
->active
)
15126 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
15128 pll
->disable(dev_priv
, pll
);
15133 skl_wm_get_hw_state(dev
);
15134 else if (HAS_PCH_SPLIT(dev
))
15135 ilk_wm_get_hw_state(dev
);
15137 if (force_restore
) {
15138 i915_redisable_vga(dev
);
15141 * We need to use raw interfaces for restoring state to avoid
15142 * checking (bogus) intermediate states.
15144 for_each_pipe(dev_priv
, pipe
) {
15145 struct drm_crtc
*crtc
=
15146 dev_priv
->pipe_to_crtc_mapping
[pipe
];
15148 intel_crtc_restore_mode(crtc
);
15151 intel_modeset_update_staged_output_state(dev
);
15154 intel_modeset_check_state(dev
);
15157 void intel_modeset_gem_init(struct drm_device
*dev
)
15159 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15160 struct drm_crtc
*c
;
15161 struct drm_i915_gem_object
*obj
;
15164 mutex_lock(&dev
->struct_mutex
);
15165 intel_init_gt_powersave(dev
);
15166 mutex_unlock(&dev
->struct_mutex
);
15169 * There may be no VBT; and if the BIOS enabled SSC we can
15170 * just keep using it to avoid unnecessary flicker. Whereas if the
15171 * BIOS isn't using it, don't assume it will work even if the VBT
15172 * indicates as much.
15174 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
15175 dev_priv
->vbt
.lvds_use_ssc
= !!(I915_READ(PCH_DREF_CONTROL
) &
15178 intel_modeset_init_hw(dev
);
15180 intel_setup_overlay(dev
);
15183 * Make sure any fbs we allocated at startup are properly
15184 * pinned & fenced. When we do the allocation it's too early
15187 for_each_crtc(dev
, c
) {
15188 obj
= intel_fb_obj(c
->primary
->fb
);
15192 mutex_lock(&dev
->struct_mutex
);
15193 ret
= intel_pin_and_fence_fb_obj(c
->primary
,
15197 mutex_unlock(&dev
->struct_mutex
);
15199 DRM_ERROR("failed to pin boot fb on pipe %d\n",
15200 to_intel_crtc(c
)->pipe
);
15201 drm_framebuffer_unreference(c
->primary
->fb
);
15202 c
->primary
->fb
= NULL
;
15203 update_state_fb(c
->primary
);
15207 intel_backlight_register(dev
);
15210 void intel_connector_unregister(struct intel_connector
*intel_connector
)
15212 struct drm_connector
*connector
= &intel_connector
->base
;
15214 intel_panel_destroy_backlight(connector
);
15215 drm_connector_unregister(connector
);
15218 void intel_modeset_cleanup(struct drm_device
*dev
)
15220 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15221 struct drm_connector
*connector
;
15223 intel_disable_gt_powersave(dev
);
15225 intel_backlight_unregister(dev
);
15228 * Interrupts and polling as the first thing to avoid creating havoc.
15229 * Too much stuff here (turning of connectors, ...) would
15230 * experience fancy races otherwise.
15232 intel_irq_uninstall(dev_priv
);
15235 * Due to the hpd irq storm handling the hotplug work can re-arm the
15236 * poll handlers. Hence disable polling after hpd handling is shut down.
15238 drm_kms_helper_poll_fini(dev
);
15240 mutex_lock(&dev
->struct_mutex
);
15242 intel_unregister_dsm_handler();
15244 intel_fbc_disable(dev
);
15246 mutex_unlock(&dev
->struct_mutex
);
15248 /* flush any delayed tasks or pending work */
15249 flush_scheduled_work();
15251 /* destroy the backlight and sysfs files before encoders/connectors */
15252 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
15253 struct intel_connector
*intel_connector
;
15255 intel_connector
= to_intel_connector(connector
);
15256 intel_connector
->unregister(intel_connector
);
15259 drm_mode_config_cleanup(dev
);
15261 intel_cleanup_overlay(dev
);
15263 mutex_lock(&dev
->struct_mutex
);
15264 intel_cleanup_gt_powersave(dev
);
15265 mutex_unlock(&dev
->struct_mutex
);
15269 * Return which encoder is currently attached for connector.
15271 struct drm_encoder
*intel_best_encoder(struct drm_connector
*connector
)
15273 return &intel_attached_encoder(connector
)->base
;
15276 void intel_connector_attach_encoder(struct intel_connector
*connector
,
15277 struct intel_encoder
*encoder
)
15279 connector
->encoder
= encoder
;
15280 drm_mode_connector_attach_encoder(&connector
->base
,
15285 * set vga decode state - true == enable VGA decode
15287 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
15289 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15290 unsigned reg
= INTEL_INFO(dev
)->gen
>= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
15293 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
15294 DRM_ERROR("failed to read control word\n");
15298 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
15302 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
15304 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
15306 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
15307 DRM_ERROR("failed to write control word\n");
15314 struct intel_display_error_state
{
15316 u32 power_well_driver
;
15318 int num_transcoders
;
15320 struct intel_cursor_error_state
{
15325 } cursor
[I915_MAX_PIPES
];
15327 struct intel_pipe_error_state
{
15328 bool power_domain_on
;
15331 } pipe
[I915_MAX_PIPES
];
15333 struct intel_plane_error_state
{
15341 } plane
[I915_MAX_PIPES
];
15343 struct intel_transcoder_error_state
{
15344 bool power_domain_on
;
15345 enum transcoder cpu_transcoder
;
15358 struct intel_display_error_state
*
15359 intel_display_capture_error_state(struct drm_device
*dev
)
15361 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15362 struct intel_display_error_state
*error
;
15363 int transcoders
[] = {
15371 if (INTEL_INFO(dev
)->num_pipes
== 0)
15374 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
15378 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
15379 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
15381 for_each_pipe(dev_priv
, i
) {
15382 error
->pipe
[i
].power_domain_on
=
15383 __intel_display_power_is_enabled(dev_priv
,
15384 POWER_DOMAIN_PIPE(i
));
15385 if (!error
->pipe
[i
].power_domain_on
)
15388 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
15389 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
15390 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
15392 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
15393 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
15394 if (INTEL_INFO(dev
)->gen
<= 3) {
15395 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
15396 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
15398 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
15399 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
15400 if (INTEL_INFO(dev
)->gen
>= 4) {
15401 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
15402 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
15405 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
15407 if (HAS_GMCH_DISPLAY(dev
))
15408 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
15411 error
->num_transcoders
= INTEL_INFO(dev
)->num_pipes
;
15412 if (HAS_DDI(dev_priv
->dev
))
15413 error
->num_transcoders
++; /* Account for eDP. */
15415 for (i
= 0; i
< error
->num_transcoders
; i
++) {
15416 enum transcoder cpu_transcoder
= transcoders
[i
];
15418 error
->transcoder
[i
].power_domain_on
=
15419 __intel_display_power_is_enabled(dev_priv
,
15420 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
15421 if (!error
->transcoder
[i
].power_domain_on
)
15424 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
15426 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
15427 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
15428 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
15429 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
15430 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
15431 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
15432 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
15438 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
15441 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
15442 struct drm_device
*dev
,
15443 struct intel_display_error_state
*error
)
15445 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15451 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev
)->num_pipes
);
15452 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
15453 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
15454 error
->power_well_driver
);
15455 for_each_pipe(dev_priv
, i
) {
15456 err_printf(m
, "Pipe [%d]:\n", i
);
15457 err_printf(m
, " Power: %s\n",
15458 error
->pipe
[i
].power_domain_on
? "on" : "off");
15459 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
15460 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
15462 err_printf(m
, "Plane [%d]:\n", i
);
15463 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
15464 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
15465 if (INTEL_INFO(dev
)->gen
<= 3) {
15466 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
15467 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
15469 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
15470 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
15471 if (INTEL_INFO(dev
)->gen
>= 4) {
15472 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
15473 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
15476 err_printf(m
, "Cursor [%d]:\n", i
);
15477 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
15478 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
15479 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
15482 for (i
= 0; i
< error
->num_transcoders
; i
++) {
15483 err_printf(m
, "CPU transcoder: %c\n",
15484 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
15485 err_printf(m
, " Power: %s\n",
15486 error
->transcoder
[i
].power_domain_on
? "on" : "off");
15487 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
15488 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
15489 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
15490 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
15491 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
15492 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
15493 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);
15497 void intel_modeset_preclose(struct drm_device
*dev
, struct drm_file
*file
)
15499 struct intel_crtc
*crtc
;
15501 for_each_intel_crtc(dev
, crtc
) {
15502 struct intel_unpin_work
*work
;
15504 spin_lock_irq(&dev
->event_lock
);
15506 work
= crtc
->unpin_work
;
15508 if (work
&& work
->event
&&
15509 work
->event
->base
.file_priv
== file
) {
15510 kfree(work
->event
);
15511 work
->event
= NULL
;
15514 spin_unlock_irq(&dev
->event_lock
);