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 for gen <= 3 */
49 static const uint32_t i8xx_primary_formats
[] = {
56 /* Primary plane formats for gen >= 4 */
57 static const uint32_t i965_primary_formats
[] = {
62 DRM_FORMAT_XRGB2101010
,
63 DRM_FORMAT_XBGR2101010
,
66 static const uint32_t skl_primary_formats
[] = {
73 DRM_FORMAT_XRGB2101010
,
74 DRM_FORMAT_XBGR2101010
,
78 static const uint32_t intel_cursor_formats
[] = {
82 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
, bool on
);
84 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
85 struct intel_crtc_state
*pipe_config
);
86 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
87 struct intel_crtc_state
*pipe_config
);
89 static int intel_set_mode(struct drm_crtc
*crtc
,
90 struct drm_atomic_state
*state
);
91 static int intel_framebuffer_init(struct drm_device
*dev
,
92 struct intel_framebuffer
*ifb
,
93 struct drm_mode_fb_cmd2
*mode_cmd
,
94 struct drm_i915_gem_object
*obj
);
95 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
);
96 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
);
97 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
98 struct intel_link_m_n
*m_n
,
99 struct intel_link_m_n
*m2_n2
);
100 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
);
101 static void haswell_set_pipeconf(struct drm_crtc
*crtc
);
102 static void intel_set_pipe_csc(struct drm_crtc
*crtc
);
103 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
104 const struct intel_crtc_state
*pipe_config
);
105 static void chv_prepare_pll(struct intel_crtc
*crtc
,
106 const struct intel_crtc_state
*pipe_config
);
107 static void intel_begin_crtc_commit(struct drm_crtc
*crtc
);
108 static void intel_finish_crtc_commit(struct drm_crtc
*crtc
);
109 static void skl_init_scalers(struct drm_device
*dev
, struct intel_crtc
*intel_crtc
,
110 struct intel_crtc_state
*crtc_state
);
111 static int i9xx_get_refclk(const struct intel_crtc_state
*crtc_state
,
113 static void intel_crtc_enable_planes(struct drm_crtc
*crtc
);
114 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
);
116 static struct intel_encoder
*intel_find_encoder(struct intel_connector
*connector
, int pipe
)
118 if (!connector
->mst_port
)
119 return connector
->encoder
;
121 return &connector
->mst_port
->mst_encoders
[pipe
]->base
;
130 int p2_slow
, p2_fast
;
133 typedef struct intel_limit intel_limit_t
;
135 intel_range_t dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
140 intel_pch_rawclk(struct drm_device
*dev
)
142 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
144 WARN_ON(!HAS_PCH_SPLIT(dev
));
146 return I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
;
149 static inline u32
/* units of 100MHz */
150 intel_fdi_link_freq(struct drm_device
*dev
)
153 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
154 return (I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2;
159 static const intel_limit_t intel_limits_i8xx_dac
= {
160 .dot
= { .min
= 25000, .max
= 350000 },
161 .vco
= { .min
= 908000, .max
= 1512000 },
162 .n
= { .min
= 2, .max
= 16 },
163 .m
= { .min
= 96, .max
= 140 },
164 .m1
= { .min
= 18, .max
= 26 },
165 .m2
= { .min
= 6, .max
= 16 },
166 .p
= { .min
= 4, .max
= 128 },
167 .p1
= { .min
= 2, .max
= 33 },
168 .p2
= { .dot_limit
= 165000,
169 .p2_slow
= 4, .p2_fast
= 2 },
172 static const intel_limit_t intel_limits_i8xx_dvo
= {
173 .dot
= { .min
= 25000, .max
= 350000 },
174 .vco
= { .min
= 908000, .max
= 1512000 },
175 .n
= { .min
= 2, .max
= 16 },
176 .m
= { .min
= 96, .max
= 140 },
177 .m1
= { .min
= 18, .max
= 26 },
178 .m2
= { .min
= 6, .max
= 16 },
179 .p
= { .min
= 4, .max
= 128 },
180 .p1
= { .min
= 2, .max
= 33 },
181 .p2
= { .dot_limit
= 165000,
182 .p2_slow
= 4, .p2_fast
= 4 },
185 static const intel_limit_t intel_limits_i8xx_lvds
= {
186 .dot
= { .min
= 25000, .max
= 350000 },
187 .vco
= { .min
= 908000, .max
= 1512000 },
188 .n
= { .min
= 2, .max
= 16 },
189 .m
= { .min
= 96, .max
= 140 },
190 .m1
= { .min
= 18, .max
= 26 },
191 .m2
= { .min
= 6, .max
= 16 },
192 .p
= { .min
= 4, .max
= 128 },
193 .p1
= { .min
= 1, .max
= 6 },
194 .p2
= { .dot_limit
= 165000,
195 .p2_slow
= 14, .p2_fast
= 7 },
198 static const intel_limit_t intel_limits_i9xx_sdvo
= {
199 .dot
= { .min
= 20000, .max
= 400000 },
200 .vco
= { .min
= 1400000, .max
= 2800000 },
201 .n
= { .min
= 1, .max
= 6 },
202 .m
= { .min
= 70, .max
= 120 },
203 .m1
= { .min
= 8, .max
= 18 },
204 .m2
= { .min
= 3, .max
= 7 },
205 .p
= { .min
= 5, .max
= 80 },
206 .p1
= { .min
= 1, .max
= 8 },
207 .p2
= { .dot_limit
= 200000,
208 .p2_slow
= 10, .p2_fast
= 5 },
211 static const intel_limit_t intel_limits_i9xx_lvds
= {
212 .dot
= { .min
= 20000, .max
= 400000 },
213 .vco
= { .min
= 1400000, .max
= 2800000 },
214 .n
= { .min
= 1, .max
= 6 },
215 .m
= { .min
= 70, .max
= 120 },
216 .m1
= { .min
= 8, .max
= 18 },
217 .m2
= { .min
= 3, .max
= 7 },
218 .p
= { .min
= 7, .max
= 98 },
219 .p1
= { .min
= 1, .max
= 8 },
220 .p2
= { .dot_limit
= 112000,
221 .p2_slow
= 14, .p2_fast
= 7 },
225 static const intel_limit_t intel_limits_g4x_sdvo
= {
226 .dot
= { .min
= 25000, .max
= 270000 },
227 .vco
= { .min
= 1750000, .max
= 3500000},
228 .n
= { .min
= 1, .max
= 4 },
229 .m
= { .min
= 104, .max
= 138 },
230 .m1
= { .min
= 17, .max
= 23 },
231 .m2
= { .min
= 5, .max
= 11 },
232 .p
= { .min
= 10, .max
= 30 },
233 .p1
= { .min
= 1, .max
= 3},
234 .p2
= { .dot_limit
= 270000,
240 static const intel_limit_t intel_limits_g4x_hdmi
= {
241 .dot
= { .min
= 22000, .max
= 400000 },
242 .vco
= { .min
= 1750000, .max
= 3500000},
243 .n
= { .min
= 1, .max
= 4 },
244 .m
= { .min
= 104, .max
= 138 },
245 .m1
= { .min
= 16, .max
= 23 },
246 .m2
= { .min
= 5, .max
= 11 },
247 .p
= { .min
= 5, .max
= 80 },
248 .p1
= { .min
= 1, .max
= 8},
249 .p2
= { .dot_limit
= 165000,
250 .p2_slow
= 10, .p2_fast
= 5 },
253 static const intel_limit_t intel_limits_g4x_single_channel_lvds
= {
254 .dot
= { .min
= 20000, .max
= 115000 },
255 .vco
= { .min
= 1750000, .max
= 3500000 },
256 .n
= { .min
= 1, .max
= 3 },
257 .m
= { .min
= 104, .max
= 138 },
258 .m1
= { .min
= 17, .max
= 23 },
259 .m2
= { .min
= 5, .max
= 11 },
260 .p
= { .min
= 28, .max
= 112 },
261 .p1
= { .min
= 2, .max
= 8 },
262 .p2
= { .dot_limit
= 0,
263 .p2_slow
= 14, .p2_fast
= 14
267 static const intel_limit_t intel_limits_g4x_dual_channel_lvds
= {
268 .dot
= { .min
= 80000, .max
= 224000 },
269 .vco
= { .min
= 1750000, .max
= 3500000 },
270 .n
= { .min
= 1, .max
= 3 },
271 .m
= { .min
= 104, .max
= 138 },
272 .m1
= { .min
= 17, .max
= 23 },
273 .m2
= { .min
= 5, .max
= 11 },
274 .p
= { .min
= 14, .max
= 42 },
275 .p1
= { .min
= 2, .max
= 6 },
276 .p2
= { .dot_limit
= 0,
277 .p2_slow
= 7, .p2_fast
= 7
281 static const intel_limit_t intel_limits_pineview_sdvo
= {
282 .dot
= { .min
= 20000, .max
= 400000},
283 .vco
= { .min
= 1700000, .max
= 3500000 },
284 /* Pineview's Ncounter is a ring counter */
285 .n
= { .min
= 3, .max
= 6 },
286 .m
= { .min
= 2, .max
= 256 },
287 /* Pineview only has one combined m divider, which we treat as m2. */
288 .m1
= { .min
= 0, .max
= 0 },
289 .m2
= { .min
= 0, .max
= 254 },
290 .p
= { .min
= 5, .max
= 80 },
291 .p1
= { .min
= 1, .max
= 8 },
292 .p2
= { .dot_limit
= 200000,
293 .p2_slow
= 10, .p2_fast
= 5 },
296 static const intel_limit_t intel_limits_pineview_lvds
= {
297 .dot
= { .min
= 20000, .max
= 400000 },
298 .vco
= { .min
= 1700000, .max
= 3500000 },
299 .n
= { .min
= 3, .max
= 6 },
300 .m
= { .min
= 2, .max
= 256 },
301 .m1
= { .min
= 0, .max
= 0 },
302 .m2
= { .min
= 0, .max
= 254 },
303 .p
= { .min
= 7, .max
= 112 },
304 .p1
= { .min
= 1, .max
= 8 },
305 .p2
= { .dot_limit
= 112000,
306 .p2_slow
= 14, .p2_fast
= 14 },
309 /* Ironlake / Sandybridge
311 * We calculate clock using (register_value + 2) for N/M1/M2, so here
312 * the range value for them is (actual_value - 2).
314 static const intel_limit_t intel_limits_ironlake_dac
= {
315 .dot
= { .min
= 25000, .max
= 350000 },
316 .vco
= { .min
= 1760000, .max
= 3510000 },
317 .n
= { .min
= 1, .max
= 5 },
318 .m
= { .min
= 79, .max
= 127 },
319 .m1
= { .min
= 12, .max
= 22 },
320 .m2
= { .min
= 5, .max
= 9 },
321 .p
= { .min
= 5, .max
= 80 },
322 .p1
= { .min
= 1, .max
= 8 },
323 .p2
= { .dot_limit
= 225000,
324 .p2_slow
= 10, .p2_fast
= 5 },
327 static const intel_limit_t intel_limits_ironlake_single_lvds
= {
328 .dot
= { .min
= 25000, .max
= 350000 },
329 .vco
= { .min
= 1760000, .max
= 3510000 },
330 .n
= { .min
= 1, .max
= 3 },
331 .m
= { .min
= 79, .max
= 118 },
332 .m1
= { .min
= 12, .max
= 22 },
333 .m2
= { .min
= 5, .max
= 9 },
334 .p
= { .min
= 28, .max
= 112 },
335 .p1
= { .min
= 2, .max
= 8 },
336 .p2
= { .dot_limit
= 225000,
337 .p2_slow
= 14, .p2_fast
= 14 },
340 static const intel_limit_t intel_limits_ironlake_dual_lvds
= {
341 .dot
= { .min
= 25000, .max
= 350000 },
342 .vco
= { .min
= 1760000, .max
= 3510000 },
343 .n
= { .min
= 1, .max
= 3 },
344 .m
= { .min
= 79, .max
= 127 },
345 .m1
= { .min
= 12, .max
= 22 },
346 .m2
= { .min
= 5, .max
= 9 },
347 .p
= { .min
= 14, .max
= 56 },
348 .p1
= { .min
= 2, .max
= 8 },
349 .p2
= { .dot_limit
= 225000,
350 .p2_slow
= 7, .p2_fast
= 7 },
353 /* LVDS 100mhz refclk limits. */
354 static const intel_limit_t intel_limits_ironlake_single_lvds_100m
= {
355 .dot
= { .min
= 25000, .max
= 350000 },
356 .vco
= { .min
= 1760000, .max
= 3510000 },
357 .n
= { .min
= 1, .max
= 2 },
358 .m
= { .min
= 79, .max
= 126 },
359 .m1
= { .min
= 12, .max
= 22 },
360 .m2
= { .min
= 5, .max
= 9 },
361 .p
= { .min
= 28, .max
= 112 },
362 .p1
= { .min
= 2, .max
= 8 },
363 .p2
= { .dot_limit
= 225000,
364 .p2_slow
= 14, .p2_fast
= 14 },
367 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m
= {
368 .dot
= { .min
= 25000, .max
= 350000 },
369 .vco
= { .min
= 1760000, .max
= 3510000 },
370 .n
= { .min
= 1, .max
= 3 },
371 .m
= { .min
= 79, .max
= 126 },
372 .m1
= { .min
= 12, .max
= 22 },
373 .m2
= { .min
= 5, .max
= 9 },
374 .p
= { .min
= 14, .max
= 42 },
375 .p1
= { .min
= 2, .max
= 6 },
376 .p2
= { .dot_limit
= 225000,
377 .p2_slow
= 7, .p2_fast
= 7 },
380 static const intel_limit_t intel_limits_vlv
= {
382 * These are the data rate limits (measured in fast clocks)
383 * since those are the strictest limits we have. The fast
384 * clock and actual rate limits are more relaxed, so checking
385 * them would make no difference.
387 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
388 .vco
= { .min
= 4000000, .max
= 6000000 },
389 .n
= { .min
= 1, .max
= 7 },
390 .m1
= { .min
= 2, .max
= 3 },
391 .m2
= { .min
= 11, .max
= 156 },
392 .p1
= { .min
= 2, .max
= 3 },
393 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
396 static const intel_limit_t intel_limits_chv
= {
398 * These are the data rate limits (measured in fast clocks)
399 * since those are the strictest limits we have. The fast
400 * clock and actual rate limits are more relaxed, so checking
401 * them would make no difference.
403 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
404 .vco
= { .min
= 4800000, .max
= 6480000 },
405 .n
= { .min
= 1, .max
= 1 },
406 .m1
= { .min
= 2, .max
= 2 },
407 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
408 .p1
= { .min
= 2, .max
= 4 },
409 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
412 static const intel_limit_t intel_limits_bxt
= {
413 /* FIXME: find real dot limits */
414 .dot
= { .min
= 0, .max
= INT_MAX
},
415 .vco
= { .min
= 4800000, .max
= 6480000 },
416 .n
= { .min
= 1, .max
= 1 },
417 .m1
= { .min
= 2, .max
= 2 },
418 /* FIXME: find real m2 limits */
419 .m2
= { .min
= 2 << 22, .max
= 255 << 22 },
420 .p1
= { .min
= 2, .max
= 4 },
421 .p2
= { .p2_slow
= 1, .p2_fast
= 20 },
424 static void vlv_clock(int refclk
, intel_clock_t
*clock
)
426 clock
->m
= clock
->m1
* clock
->m2
;
427 clock
->p
= clock
->p1
* clock
->p2
;
428 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
430 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
431 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
435 * Returns whether any output on the specified pipe is of the specified type
437 bool intel_pipe_has_type(struct intel_crtc
*crtc
, enum intel_output_type type
)
439 struct drm_device
*dev
= crtc
->base
.dev
;
440 struct intel_encoder
*encoder
;
442 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
443 if (encoder
->type
== type
)
450 * Returns whether any output on the specified pipe will have the specified
451 * type after a staged modeset is complete, i.e., the same as
452 * intel_pipe_has_type() but looking at encoder->new_crtc instead of
455 static bool intel_pipe_will_have_type(const struct intel_crtc_state
*crtc_state
,
458 struct drm_atomic_state
*state
= crtc_state
->base
.state
;
459 struct drm_connector
*connector
;
460 struct drm_connector_state
*connector_state
;
461 struct intel_encoder
*encoder
;
462 int i
, num_connectors
= 0;
464 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
465 if (connector_state
->crtc
!= crtc_state
->base
.crtc
)
470 encoder
= to_intel_encoder(connector_state
->best_encoder
);
471 if (encoder
->type
== type
)
475 WARN_ON(num_connectors
== 0);
480 static const intel_limit_t
*
481 intel_ironlake_limit(struct intel_crtc_state
*crtc_state
, int refclk
)
483 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
484 const intel_limit_t
*limit
;
486 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
487 if (intel_is_dual_link_lvds(dev
)) {
488 if (refclk
== 100000)
489 limit
= &intel_limits_ironlake_dual_lvds_100m
;
491 limit
= &intel_limits_ironlake_dual_lvds
;
493 if (refclk
== 100000)
494 limit
= &intel_limits_ironlake_single_lvds_100m
;
496 limit
= &intel_limits_ironlake_single_lvds
;
499 limit
= &intel_limits_ironlake_dac
;
504 static const intel_limit_t
*
505 intel_g4x_limit(struct intel_crtc_state
*crtc_state
)
507 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
508 const intel_limit_t
*limit
;
510 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
511 if (intel_is_dual_link_lvds(dev
))
512 limit
= &intel_limits_g4x_dual_channel_lvds
;
514 limit
= &intel_limits_g4x_single_channel_lvds
;
515 } else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_HDMI
) ||
516 intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_ANALOG
)) {
517 limit
= &intel_limits_g4x_hdmi
;
518 } else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_SDVO
)) {
519 limit
= &intel_limits_g4x_sdvo
;
520 } else /* The option is for other outputs */
521 limit
= &intel_limits_i9xx_sdvo
;
526 static const intel_limit_t
*
527 intel_limit(struct intel_crtc_state
*crtc_state
, int refclk
)
529 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
530 const intel_limit_t
*limit
;
533 limit
= &intel_limits_bxt
;
534 else if (HAS_PCH_SPLIT(dev
))
535 limit
= intel_ironlake_limit(crtc_state
, refclk
);
536 else if (IS_G4X(dev
)) {
537 limit
= intel_g4x_limit(crtc_state
);
538 } else if (IS_PINEVIEW(dev
)) {
539 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
))
540 limit
= &intel_limits_pineview_lvds
;
542 limit
= &intel_limits_pineview_sdvo
;
543 } else if (IS_CHERRYVIEW(dev
)) {
544 limit
= &intel_limits_chv
;
545 } else if (IS_VALLEYVIEW(dev
)) {
546 limit
= &intel_limits_vlv
;
547 } else if (!IS_GEN2(dev
)) {
548 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
))
549 limit
= &intel_limits_i9xx_lvds
;
551 limit
= &intel_limits_i9xx_sdvo
;
553 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
))
554 limit
= &intel_limits_i8xx_lvds
;
555 else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_DVO
))
556 limit
= &intel_limits_i8xx_dvo
;
558 limit
= &intel_limits_i8xx_dac
;
563 /* m1 is reserved as 0 in Pineview, n is a ring counter */
564 static void pineview_clock(int refclk
, intel_clock_t
*clock
)
566 clock
->m
= clock
->m2
+ 2;
567 clock
->p
= clock
->p1
* clock
->p2
;
568 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
570 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
571 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
574 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
576 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
579 static void i9xx_clock(int refclk
, intel_clock_t
*clock
)
581 clock
->m
= i9xx_dpll_compute_m(clock
);
582 clock
->p
= clock
->p1
* clock
->p2
;
583 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
585 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
586 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
589 static void chv_clock(int refclk
, intel_clock_t
*clock
)
591 clock
->m
= clock
->m1
* clock
->m2
;
592 clock
->p
= clock
->p1
* clock
->p2
;
593 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
595 clock
->vco
= DIV_ROUND_CLOSEST_ULL((uint64_t)refclk
* clock
->m
,
597 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
600 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
602 * Returns whether the given set of divisors are valid for a given refclk with
603 * the given connectors.
606 static bool intel_PLL_is_valid(struct drm_device
*dev
,
607 const intel_limit_t
*limit
,
608 const intel_clock_t
*clock
)
610 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
611 INTELPllInvalid("n out of range\n");
612 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
613 INTELPllInvalid("p1 out of range\n");
614 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
615 INTELPllInvalid("m2 out of range\n");
616 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
617 INTELPllInvalid("m1 out of range\n");
619 if (!IS_PINEVIEW(dev
) && !IS_VALLEYVIEW(dev
) && !IS_BROXTON(dev
))
620 if (clock
->m1
<= clock
->m2
)
621 INTELPllInvalid("m1 <= m2\n");
623 if (!IS_VALLEYVIEW(dev
) && !IS_BROXTON(dev
)) {
624 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
625 INTELPllInvalid("p out of range\n");
626 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
627 INTELPllInvalid("m out of range\n");
630 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
631 INTELPllInvalid("vco out of range\n");
632 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
633 * connector, etc., rather than just a single range.
635 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
636 INTELPllInvalid("dot out of range\n");
642 i9xx_find_best_dpll(const intel_limit_t
*limit
,
643 struct intel_crtc_state
*crtc_state
,
644 int target
, int refclk
, intel_clock_t
*match_clock
,
645 intel_clock_t
*best_clock
)
647 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
648 struct drm_device
*dev
= crtc
->base
.dev
;
652 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
654 * For LVDS just rely on its current settings for dual-channel.
655 * We haven't figured out how to reliably set up different
656 * single/dual channel state, if we even can.
658 if (intel_is_dual_link_lvds(dev
))
659 clock
.p2
= limit
->p2
.p2_fast
;
661 clock
.p2
= limit
->p2
.p2_slow
;
663 if (target
< limit
->p2
.dot_limit
)
664 clock
.p2
= limit
->p2
.p2_slow
;
666 clock
.p2
= limit
->p2
.p2_fast
;
669 memset(best_clock
, 0, sizeof(*best_clock
));
671 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
673 for (clock
.m2
= limit
->m2
.min
;
674 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
675 if (clock
.m2
>= clock
.m1
)
677 for (clock
.n
= limit
->n
.min
;
678 clock
.n
<= limit
->n
.max
; clock
.n
++) {
679 for (clock
.p1
= limit
->p1
.min
;
680 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
683 i9xx_clock(refclk
, &clock
);
684 if (!intel_PLL_is_valid(dev
, limit
,
688 clock
.p
!= match_clock
->p
)
691 this_err
= abs(clock
.dot
- target
);
692 if (this_err
< err
) {
701 return (err
!= target
);
705 pnv_find_best_dpll(const intel_limit_t
*limit
,
706 struct intel_crtc_state
*crtc_state
,
707 int target
, int refclk
, intel_clock_t
*match_clock
,
708 intel_clock_t
*best_clock
)
710 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
711 struct drm_device
*dev
= crtc
->base
.dev
;
715 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
717 * For LVDS just rely on its current settings for dual-channel.
718 * We haven't figured out how to reliably set up different
719 * single/dual channel state, if we even can.
721 if (intel_is_dual_link_lvds(dev
))
722 clock
.p2
= limit
->p2
.p2_fast
;
724 clock
.p2
= limit
->p2
.p2_slow
;
726 if (target
< limit
->p2
.dot_limit
)
727 clock
.p2
= limit
->p2
.p2_slow
;
729 clock
.p2
= limit
->p2
.p2_fast
;
732 memset(best_clock
, 0, sizeof(*best_clock
));
734 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
736 for (clock
.m2
= limit
->m2
.min
;
737 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
738 for (clock
.n
= limit
->n
.min
;
739 clock
.n
<= limit
->n
.max
; clock
.n
++) {
740 for (clock
.p1
= limit
->p1
.min
;
741 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
744 pineview_clock(refclk
, &clock
);
745 if (!intel_PLL_is_valid(dev
, limit
,
749 clock
.p
!= match_clock
->p
)
752 this_err
= abs(clock
.dot
- target
);
753 if (this_err
< err
) {
762 return (err
!= target
);
766 g4x_find_best_dpll(const intel_limit_t
*limit
,
767 struct intel_crtc_state
*crtc_state
,
768 int target
, int refclk
, intel_clock_t
*match_clock
,
769 intel_clock_t
*best_clock
)
771 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
772 struct drm_device
*dev
= crtc
->base
.dev
;
776 /* approximately equals target * 0.00585 */
777 int err_most
= (target
>> 8) + (target
>> 9);
780 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
781 if (intel_is_dual_link_lvds(dev
))
782 clock
.p2
= limit
->p2
.p2_fast
;
784 clock
.p2
= limit
->p2
.p2_slow
;
786 if (target
< limit
->p2
.dot_limit
)
787 clock
.p2
= limit
->p2
.p2_slow
;
789 clock
.p2
= limit
->p2
.p2_fast
;
792 memset(best_clock
, 0, sizeof(*best_clock
));
793 max_n
= limit
->n
.max
;
794 /* based on hardware requirement, prefer smaller n to precision */
795 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
796 /* based on hardware requirement, prefere larger m1,m2 */
797 for (clock
.m1
= limit
->m1
.max
;
798 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
799 for (clock
.m2
= limit
->m2
.max
;
800 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
801 for (clock
.p1
= limit
->p1
.max
;
802 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
805 i9xx_clock(refclk
, &clock
);
806 if (!intel_PLL_is_valid(dev
, limit
,
810 this_err
= abs(clock
.dot
- target
);
811 if (this_err
< err_most
) {
825 * Check if the calculated PLL configuration is more optimal compared to the
826 * best configuration and error found so far. Return the calculated error.
828 static bool vlv_PLL_is_optimal(struct drm_device
*dev
, int target_freq
,
829 const intel_clock_t
*calculated_clock
,
830 const intel_clock_t
*best_clock
,
831 unsigned int best_error_ppm
,
832 unsigned int *error_ppm
)
835 * For CHV ignore the error and consider only the P value.
836 * Prefer a bigger P value based on HW requirements.
838 if (IS_CHERRYVIEW(dev
)) {
841 return calculated_clock
->p
> best_clock
->p
;
844 if (WARN_ON_ONCE(!target_freq
))
847 *error_ppm
= div_u64(1000000ULL *
848 abs(target_freq
- calculated_clock
->dot
),
851 * Prefer a better P value over a better (smaller) error if the error
852 * is small. Ensure this preference for future configurations too by
853 * setting the error to 0.
855 if (*error_ppm
< 100 && calculated_clock
->p
> best_clock
->p
) {
861 return *error_ppm
+ 10 < best_error_ppm
;
865 vlv_find_best_dpll(const intel_limit_t
*limit
,
866 struct intel_crtc_state
*crtc_state
,
867 int target
, int refclk
, intel_clock_t
*match_clock
,
868 intel_clock_t
*best_clock
)
870 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
871 struct drm_device
*dev
= crtc
->base
.dev
;
873 unsigned int bestppm
= 1000000;
874 /* min update 19.2 MHz */
875 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
878 target
*= 5; /* fast clock */
880 memset(best_clock
, 0, sizeof(*best_clock
));
882 /* based on hardware requirement, prefer smaller n to precision */
883 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
884 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
885 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
886 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
887 clock
.p
= clock
.p1
* clock
.p2
;
888 /* based on hardware requirement, prefer bigger m1,m2 values */
889 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
892 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
895 vlv_clock(refclk
, &clock
);
897 if (!intel_PLL_is_valid(dev
, limit
,
901 if (!vlv_PLL_is_optimal(dev
, target
,
919 chv_find_best_dpll(const intel_limit_t
*limit
,
920 struct intel_crtc_state
*crtc_state
,
921 int target
, int refclk
, intel_clock_t
*match_clock
,
922 intel_clock_t
*best_clock
)
924 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
925 struct drm_device
*dev
= crtc
->base
.dev
;
926 unsigned int best_error_ppm
;
931 memset(best_clock
, 0, sizeof(*best_clock
));
932 best_error_ppm
= 1000000;
935 * Based on hardware doc, the n always set to 1, and m1 always
936 * set to 2. If requires to support 200Mhz refclk, we need to
937 * revisit this because n may not 1 anymore.
939 clock
.n
= 1, clock
.m1
= 2;
940 target
*= 5; /* fast clock */
942 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
943 for (clock
.p2
= limit
->p2
.p2_fast
;
944 clock
.p2
>= limit
->p2
.p2_slow
;
945 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
946 unsigned int error_ppm
;
948 clock
.p
= clock
.p1
* clock
.p2
;
950 m2
= DIV_ROUND_CLOSEST_ULL(((uint64_t)target
* clock
.p
*
951 clock
.n
) << 22, refclk
* clock
.m1
);
953 if (m2
> INT_MAX
/clock
.m1
)
958 chv_clock(refclk
, &clock
);
960 if (!intel_PLL_is_valid(dev
, limit
, &clock
))
963 if (!vlv_PLL_is_optimal(dev
, target
, &clock
, best_clock
,
964 best_error_ppm
, &error_ppm
))
968 best_error_ppm
= error_ppm
;
976 bool bxt_find_best_dpll(struct intel_crtc_state
*crtc_state
, int target_clock
,
977 intel_clock_t
*best_clock
)
979 int refclk
= i9xx_get_refclk(crtc_state
, 0);
981 return chv_find_best_dpll(intel_limit(crtc_state
, refclk
), crtc_state
,
982 target_clock
, refclk
, NULL
, best_clock
);
985 bool intel_crtc_active(struct drm_crtc
*crtc
)
987 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
989 /* Be paranoid as we can arrive here with only partial
990 * state retrieved from the hardware during setup.
992 * We can ditch the adjusted_mode.crtc_clock check as soon
993 * as Haswell has gained clock readout/fastboot support.
995 * We can ditch the crtc->primary->fb check as soon as we can
996 * properly reconstruct framebuffers.
998 * FIXME: The intel_crtc->active here should be switched to
999 * crtc->state->active once we have proper CRTC states wired up
1002 return intel_crtc
->active
&& crtc
->primary
->state
->fb
&&
1003 intel_crtc
->config
->base
.adjusted_mode
.crtc_clock
;
1006 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
1009 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1010 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1012 return intel_crtc
->config
->cpu_transcoder
;
1015 static bool pipe_dsl_stopped(struct drm_device
*dev
, enum pipe pipe
)
1017 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1018 u32 reg
= PIPEDSL(pipe
);
1023 line_mask
= DSL_LINEMASK_GEN2
;
1025 line_mask
= DSL_LINEMASK_GEN3
;
1027 line1
= I915_READ(reg
) & line_mask
;
1029 line2
= I915_READ(reg
) & line_mask
;
1031 return line1
== line2
;
1035 * intel_wait_for_pipe_off - wait for pipe to turn off
1036 * @crtc: crtc whose pipe to wait for
1038 * After disabling a pipe, we can't wait for vblank in the usual way,
1039 * spinning on the vblank interrupt status bit, since we won't actually
1040 * see an interrupt when the pipe is disabled.
1042 * On Gen4 and above:
1043 * wait for the pipe register state bit to turn off
1046 * wait for the display line value to settle (it usually
1047 * ends up stopping at the start of the next frame).
1050 static void intel_wait_for_pipe_off(struct intel_crtc
*crtc
)
1052 struct drm_device
*dev
= crtc
->base
.dev
;
1053 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1054 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1055 enum pipe pipe
= crtc
->pipe
;
1057 if (INTEL_INFO(dev
)->gen
>= 4) {
1058 int reg
= PIPECONF(cpu_transcoder
);
1060 /* Wait for the Pipe State to go off */
1061 if (wait_for((I915_READ(reg
) & I965_PIPECONF_ACTIVE
) == 0,
1063 WARN(1, "pipe_off wait timed out\n");
1065 /* Wait for the display line to settle */
1066 if (wait_for(pipe_dsl_stopped(dev
, pipe
), 100))
1067 WARN(1, "pipe_off wait timed out\n");
1072 * ibx_digital_port_connected - is the specified port connected?
1073 * @dev_priv: i915 private structure
1074 * @port: the port to test
1076 * Returns true if @port is connected, false otherwise.
1078 bool ibx_digital_port_connected(struct drm_i915_private
*dev_priv
,
1079 struct intel_digital_port
*port
)
1083 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1084 switch (port
->port
) {
1086 bit
= SDE_PORTB_HOTPLUG
;
1089 bit
= SDE_PORTC_HOTPLUG
;
1092 bit
= SDE_PORTD_HOTPLUG
;
1098 switch (port
->port
) {
1100 bit
= SDE_PORTB_HOTPLUG_CPT
;
1103 bit
= SDE_PORTC_HOTPLUG_CPT
;
1106 bit
= SDE_PORTD_HOTPLUG_CPT
;
1113 return I915_READ(SDEISR
) & bit
;
1116 static const char *state_string(bool enabled
)
1118 return enabled
? "on" : "off";
1121 /* Only for pre-ILK configs */
1122 void assert_pll(struct drm_i915_private
*dev_priv
,
1123 enum pipe pipe
, bool state
)
1130 val
= I915_READ(reg
);
1131 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1132 I915_STATE_WARN(cur_state
!= state
,
1133 "PLL state assertion failure (expected %s, current %s)\n",
1134 state_string(state
), state_string(cur_state
));
1137 /* XXX: the dsi pll is shared between MIPI DSI ports */
1138 static void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1143 mutex_lock(&dev_priv
->dpio_lock
);
1144 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1145 mutex_unlock(&dev_priv
->dpio_lock
);
1147 cur_state
= val
& DSI_PLL_VCO_EN
;
1148 I915_STATE_WARN(cur_state
!= state
,
1149 "DSI PLL state assertion failure (expected %s, current %s)\n",
1150 state_string(state
), state_string(cur_state
));
1152 #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
1153 #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
1155 struct intel_shared_dpll
*
1156 intel_crtc_to_shared_dpll(struct intel_crtc
*crtc
)
1158 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
1160 if (crtc
->config
->shared_dpll
< 0)
1163 return &dev_priv
->shared_dplls
[crtc
->config
->shared_dpll
];
1167 void assert_shared_dpll(struct drm_i915_private
*dev_priv
,
1168 struct intel_shared_dpll
*pll
,
1172 struct intel_dpll_hw_state hw_state
;
1175 "asserting DPLL %s with no DPLL\n", state_string(state
)))
1178 cur_state
= pll
->get_hw_state(dev_priv
, pll
, &hw_state
);
1179 I915_STATE_WARN(cur_state
!= state
,
1180 "%s assertion failure (expected %s, current %s)\n",
1181 pll
->name
, state_string(state
), state_string(cur_state
));
1184 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1185 enum pipe pipe
, bool state
)
1190 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1193 if (HAS_DDI(dev_priv
->dev
)) {
1194 /* DDI does not have a specific FDI_TX register */
1195 reg
= TRANS_DDI_FUNC_CTL(cpu_transcoder
);
1196 val
= I915_READ(reg
);
1197 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1199 reg
= FDI_TX_CTL(pipe
);
1200 val
= I915_READ(reg
);
1201 cur_state
= !!(val
& FDI_TX_ENABLE
);
1203 I915_STATE_WARN(cur_state
!= state
,
1204 "FDI TX state assertion failure (expected %s, current %s)\n",
1205 state_string(state
), state_string(cur_state
));
1207 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1208 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1210 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1211 enum pipe pipe
, bool state
)
1217 reg
= FDI_RX_CTL(pipe
);
1218 val
= I915_READ(reg
);
1219 cur_state
= !!(val
& FDI_RX_ENABLE
);
1220 I915_STATE_WARN(cur_state
!= state
,
1221 "FDI RX state assertion failure (expected %s, current %s)\n",
1222 state_string(state
), state_string(cur_state
));
1224 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1225 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1227 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1233 /* ILK FDI PLL is always enabled */
1234 if (INTEL_INFO(dev_priv
->dev
)->gen
== 5)
1237 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1238 if (HAS_DDI(dev_priv
->dev
))
1241 reg
= FDI_TX_CTL(pipe
);
1242 val
= I915_READ(reg
);
1243 I915_STATE_WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1246 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1247 enum pipe pipe
, bool state
)
1253 reg
= FDI_RX_CTL(pipe
);
1254 val
= I915_READ(reg
);
1255 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1256 I915_STATE_WARN(cur_state
!= state
,
1257 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1258 state_string(state
), state_string(cur_state
));
1261 void assert_panel_unlocked(struct drm_i915_private
*dev_priv
,
1264 struct drm_device
*dev
= dev_priv
->dev
;
1267 enum pipe panel_pipe
= PIPE_A
;
1270 if (WARN_ON(HAS_DDI(dev
)))
1273 if (HAS_PCH_SPLIT(dev
)) {
1276 pp_reg
= PCH_PP_CONTROL
;
1277 port_sel
= I915_READ(PCH_PP_ON_DELAYS
) & PANEL_PORT_SELECT_MASK
;
1279 if (port_sel
== PANEL_PORT_SELECT_LVDS
&&
1280 I915_READ(PCH_LVDS
) & LVDS_PIPEB_SELECT
)
1281 panel_pipe
= PIPE_B
;
1282 /* XXX: else fix for eDP */
1283 } else if (IS_VALLEYVIEW(dev
)) {
1284 /* presumably write lock depends on pipe, not port select */
1285 pp_reg
= VLV_PIPE_PP_CONTROL(pipe
);
1288 pp_reg
= PP_CONTROL
;
1289 if (I915_READ(LVDS
) & LVDS_PIPEB_SELECT
)
1290 panel_pipe
= PIPE_B
;
1293 val
= I915_READ(pp_reg
);
1294 if (!(val
& PANEL_POWER_ON
) ||
1295 ((val
& PANEL_UNLOCK_MASK
) == PANEL_UNLOCK_REGS
))
1298 I915_STATE_WARN(panel_pipe
== pipe
&& locked
,
1299 "panel assertion failure, pipe %c regs locked\n",
1303 static void assert_cursor(struct drm_i915_private
*dev_priv
,
1304 enum pipe pipe
, bool state
)
1306 struct drm_device
*dev
= dev_priv
->dev
;
1309 if (IS_845G(dev
) || IS_I865G(dev
))
1310 cur_state
= I915_READ(_CURACNTR
) & CURSOR_ENABLE
;
1312 cur_state
= I915_READ(CURCNTR(pipe
)) & CURSOR_MODE
;
1314 I915_STATE_WARN(cur_state
!= state
,
1315 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1316 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1318 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1319 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1321 void assert_pipe(struct drm_i915_private
*dev_priv
,
1322 enum pipe pipe
, bool state
)
1327 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1330 /* if we need the pipe quirk it must be always on */
1331 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1332 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1335 if (!intel_display_power_is_enabled(dev_priv
,
1336 POWER_DOMAIN_TRANSCODER(cpu_transcoder
))) {
1339 reg
= PIPECONF(cpu_transcoder
);
1340 val
= I915_READ(reg
);
1341 cur_state
= !!(val
& PIPECONF_ENABLE
);
1344 I915_STATE_WARN(cur_state
!= state
,
1345 "pipe %c assertion failure (expected %s, current %s)\n",
1346 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1349 static void assert_plane(struct drm_i915_private
*dev_priv
,
1350 enum plane plane
, bool state
)
1356 reg
= DSPCNTR(plane
);
1357 val
= I915_READ(reg
);
1358 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1359 I915_STATE_WARN(cur_state
!= state
,
1360 "plane %c assertion failure (expected %s, current %s)\n",
1361 plane_name(plane
), state_string(state
), state_string(cur_state
));
1364 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1365 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1367 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1370 struct drm_device
*dev
= dev_priv
->dev
;
1375 /* Primary planes are fixed to pipes on gen4+ */
1376 if (INTEL_INFO(dev
)->gen
>= 4) {
1377 reg
= DSPCNTR(pipe
);
1378 val
= I915_READ(reg
);
1379 I915_STATE_WARN(val
& DISPLAY_PLANE_ENABLE
,
1380 "plane %c assertion failure, should be disabled but not\n",
1385 /* Need to check both planes against the pipe */
1386 for_each_pipe(dev_priv
, i
) {
1388 val
= I915_READ(reg
);
1389 cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1390 DISPPLANE_SEL_PIPE_SHIFT
;
1391 I915_STATE_WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1392 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1393 plane_name(i
), pipe_name(pipe
));
1397 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1400 struct drm_device
*dev
= dev_priv
->dev
;
1404 if (INTEL_INFO(dev
)->gen
>= 9) {
1405 for_each_sprite(dev_priv
, pipe
, sprite
) {
1406 val
= I915_READ(PLANE_CTL(pipe
, sprite
));
1407 I915_STATE_WARN(val
& PLANE_CTL_ENABLE
,
1408 "plane %d assertion failure, should be off on pipe %c but is still active\n",
1409 sprite
, pipe_name(pipe
));
1411 } else if (IS_VALLEYVIEW(dev
)) {
1412 for_each_sprite(dev_priv
, pipe
, sprite
) {
1413 reg
= SPCNTR(pipe
, sprite
);
1414 val
= I915_READ(reg
);
1415 I915_STATE_WARN(val
& SP_ENABLE
,
1416 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1417 sprite_name(pipe
, sprite
), pipe_name(pipe
));
1419 } else if (INTEL_INFO(dev
)->gen
>= 7) {
1421 val
= I915_READ(reg
);
1422 I915_STATE_WARN(val
& SPRITE_ENABLE
,
1423 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1424 plane_name(pipe
), pipe_name(pipe
));
1425 } else if (INTEL_INFO(dev
)->gen
>= 5) {
1426 reg
= DVSCNTR(pipe
);
1427 val
= I915_READ(reg
);
1428 I915_STATE_WARN(val
& DVS_ENABLE
,
1429 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1430 plane_name(pipe
), pipe_name(pipe
));
1434 static void assert_vblank_disabled(struct drm_crtc
*crtc
)
1436 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc
) == 0))
1437 drm_crtc_vblank_put(crtc
);
1440 static void ibx_assert_pch_refclk_enabled(struct drm_i915_private
*dev_priv
)
1445 I915_STATE_WARN_ON(!(HAS_PCH_IBX(dev_priv
->dev
) || HAS_PCH_CPT(dev_priv
->dev
)));
1447 val
= I915_READ(PCH_DREF_CONTROL
);
1448 enabled
= !!(val
& (DREF_SSC_SOURCE_MASK
| DREF_NONSPREAD_SOURCE_MASK
|
1449 DREF_SUPERSPREAD_SOURCE_MASK
));
1450 I915_STATE_WARN(!enabled
, "PCH refclk assertion failure, should be active but is disabled\n");
1453 static void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1460 reg
= PCH_TRANSCONF(pipe
);
1461 val
= I915_READ(reg
);
1462 enabled
= !!(val
& TRANS_ENABLE
);
1463 I915_STATE_WARN(enabled
,
1464 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1468 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1469 enum pipe pipe
, u32 port_sel
, u32 val
)
1471 if ((val
& DP_PORT_EN
) == 0)
1474 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1475 u32 trans_dp_ctl_reg
= TRANS_DP_CTL(pipe
);
1476 u32 trans_dp_ctl
= I915_READ(trans_dp_ctl_reg
);
1477 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1479 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1480 if ((val
& DP_PIPE_MASK_CHV
) != DP_PIPE_SELECT_CHV(pipe
))
1483 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1489 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1490 enum pipe pipe
, u32 val
)
1492 if ((val
& SDVO_ENABLE
) == 0)
1495 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1496 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1498 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1499 if ((val
& SDVO_PIPE_SEL_MASK_CHV
) != SDVO_PIPE_SEL_CHV(pipe
))
1502 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1508 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1509 enum pipe pipe
, u32 val
)
1511 if ((val
& LVDS_PORT_EN
) == 0)
1514 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1515 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1518 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1524 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1525 enum pipe pipe
, u32 val
)
1527 if ((val
& ADPA_DAC_ENABLE
) == 0)
1529 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1530 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1533 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1539 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1540 enum pipe pipe
, int reg
, u32 port_sel
)
1542 u32 val
= I915_READ(reg
);
1543 I915_STATE_WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1544 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1545 reg
, pipe_name(pipe
));
1547 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& DP_PORT_EN
) == 0
1548 && (val
& DP_PIPEB_SELECT
),
1549 "IBX PCH dp port still using transcoder B\n");
1552 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1553 enum pipe pipe
, int reg
)
1555 u32 val
= I915_READ(reg
);
1556 I915_STATE_WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1557 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1558 reg
, pipe_name(pipe
));
1560 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& SDVO_ENABLE
) == 0
1561 && (val
& SDVO_PIPE_B_SELECT
),
1562 "IBX PCH hdmi port still using transcoder B\n");
1565 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1571 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1572 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1573 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1576 val
= I915_READ(reg
);
1577 I915_STATE_WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1578 "PCH VGA enabled on transcoder %c, should be disabled\n",
1582 val
= I915_READ(reg
);
1583 I915_STATE_WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1584 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1587 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1588 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1589 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1592 static void intel_init_dpio(struct drm_device
*dev
)
1594 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1596 if (!IS_VALLEYVIEW(dev
))
1600 * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
1601 * CHV x1 PHY (DP/HDMI D)
1602 * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
1604 if (IS_CHERRYVIEW(dev
)) {
1605 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO_2
;
1606 DPIO_PHY_IOSF_PORT(DPIO_PHY1
) = IOSF_PORT_DPIO
;
1608 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO
;
1612 static void vlv_enable_pll(struct intel_crtc
*crtc
,
1613 const struct intel_crtc_state
*pipe_config
)
1615 struct drm_device
*dev
= crtc
->base
.dev
;
1616 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1617 int reg
= DPLL(crtc
->pipe
);
1618 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
1620 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1622 /* No really, not for ILK+ */
1623 BUG_ON(!IS_VALLEYVIEW(dev_priv
->dev
));
1625 /* PLL is protected by panel, make sure we can write it */
1626 if (IS_MOBILE(dev_priv
->dev
))
1627 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1629 I915_WRITE(reg
, dpll
);
1633 if (wait_for(((I915_READ(reg
) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1634 DRM_ERROR("DPLL %d failed to lock\n", crtc
->pipe
);
1636 I915_WRITE(DPLL_MD(crtc
->pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1637 POSTING_READ(DPLL_MD(crtc
->pipe
));
1639 /* We do this three times for luck */
1640 I915_WRITE(reg
, dpll
);
1642 udelay(150); /* wait for warmup */
1643 I915_WRITE(reg
, dpll
);
1645 udelay(150); /* wait for warmup */
1646 I915_WRITE(reg
, dpll
);
1648 udelay(150); /* wait for warmup */
1651 static void chv_enable_pll(struct intel_crtc
*crtc
,
1652 const struct intel_crtc_state
*pipe_config
)
1654 struct drm_device
*dev
= crtc
->base
.dev
;
1655 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1656 int pipe
= crtc
->pipe
;
1657 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1660 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1662 BUG_ON(!IS_CHERRYVIEW(dev_priv
->dev
));
1664 mutex_lock(&dev_priv
->dpio_lock
);
1666 /* Enable back the 10bit clock to display controller */
1667 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1668 tmp
|= DPIO_DCLKP_EN
;
1669 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), tmp
);
1672 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1677 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1679 /* Check PLL is locked */
1680 if (wait_for(((I915_READ(DPLL(pipe
)) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1681 DRM_ERROR("PLL %d failed to lock\n", pipe
);
1683 /* not sure when this should be written */
1684 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1685 POSTING_READ(DPLL_MD(pipe
));
1687 mutex_unlock(&dev_priv
->dpio_lock
);
1690 static int intel_num_dvo_pipes(struct drm_device
*dev
)
1692 struct intel_crtc
*crtc
;
1695 for_each_intel_crtc(dev
, crtc
)
1696 count
+= crtc
->active
&&
1697 intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
);
1702 static void i9xx_enable_pll(struct intel_crtc
*crtc
)
1704 struct drm_device
*dev
= crtc
->base
.dev
;
1705 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1706 int reg
= DPLL(crtc
->pipe
);
1707 u32 dpll
= crtc
->config
->dpll_hw_state
.dpll
;
1709 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1711 /* No really, not for ILK+ */
1712 BUG_ON(INTEL_INFO(dev
)->gen
>= 5);
1714 /* PLL is protected by panel, make sure we can write it */
1715 if (IS_MOBILE(dev
) && !IS_I830(dev
))
1716 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1718 /* Enable DVO 2x clock on both PLLs if necessary */
1719 if (IS_I830(dev
) && intel_num_dvo_pipes(dev
) > 0) {
1721 * It appears to be important that we don't enable this
1722 * for the current pipe before otherwise configuring the
1723 * PLL. No idea how this should be handled if multiple
1724 * DVO outputs are enabled simultaneosly.
1726 dpll
|= DPLL_DVO_2X_MODE
;
1727 I915_WRITE(DPLL(!crtc
->pipe
),
1728 I915_READ(DPLL(!crtc
->pipe
)) | DPLL_DVO_2X_MODE
);
1731 /* Wait for the clocks to stabilize. */
1735 if (INTEL_INFO(dev
)->gen
>= 4) {
1736 I915_WRITE(DPLL_MD(crtc
->pipe
),
1737 crtc
->config
->dpll_hw_state
.dpll_md
);
1739 /* The pixel multiplier can only be updated once the
1740 * DPLL is enabled and the clocks are stable.
1742 * So write it again.
1744 I915_WRITE(reg
, dpll
);
1747 /* We do this three times for luck */
1748 I915_WRITE(reg
, dpll
);
1750 udelay(150); /* wait for warmup */
1751 I915_WRITE(reg
, dpll
);
1753 udelay(150); /* wait for warmup */
1754 I915_WRITE(reg
, dpll
);
1756 udelay(150); /* wait for warmup */
1760 * i9xx_disable_pll - disable a PLL
1761 * @dev_priv: i915 private structure
1762 * @pipe: pipe PLL to disable
1764 * Disable the PLL for @pipe, making sure the pipe is off first.
1766 * Note! This is for pre-ILK only.
1768 static void i9xx_disable_pll(struct intel_crtc
*crtc
)
1770 struct drm_device
*dev
= crtc
->base
.dev
;
1771 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1772 enum pipe pipe
= crtc
->pipe
;
1774 /* Disable DVO 2x clock on both PLLs if necessary */
1776 intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
) &&
1777 intel_num_dvo_pipes(dev
) == 1) {
1778 I915_WRITE(DPLL(PIPE_B
),
1779 I915_READ(DPLL(PIPE_B
)) & ~DPLL_DVO_2X_MODE
);
1780 I915_WRITE(DPLL(PIPE_A
),
1781 I915_READ(DPLL(PIPE_A
)) & ~DPLL_DVO_2X_MODE
);
1784 /* Don't disable pipe or pipe PLLs if needed */
1785 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1786 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1789 /* Make sure the pipe isn't still relying on us */
1790 assert_pipe_disabled(dev_priv
, pipe
);
1792 I915_WRITE(DPLL(pipe
), 0);
1793 POSTING_READ(DPLL(pipe
));
1796 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1800 /* Make sure the pipe isn't still relying on us */
1801 assert_pipe_disabled(dev_priv
, pipe
);
1804 * Leave integrated clock source and reference clock enabled for pipe B.
1805 * The latter is needed for VGA hotplug / manual detection.
1808 val
= DPLL_INTEGRATED_CRI_CLK_VLV
| DPLL_REFA_CLK_ENABLE_VLV
;
1809 I915_WRITE(DPLL(pipe
), val
);
1810 POSTING_READ(DPLL(pipe
));
1814 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1816 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1819 /* Make sure the pipe isn't still relying on us */
1820 assert_pipe_disabled(dev_priv
, pipe
);
1822 /* Set PLL en = 0 */
1823 val
= DPLL_SSC_REF_CLOCK_CHV
| DPLL_REFA_CLK_ENABLE_VLV
;
1825 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1826 I915_WRITE(DPLL(pipe
), val
);
1827 POSTING_READ(DPLL(pipe
));
1829 mutex_lock(&dev_priv
->dpio_lock
);
1831 /* Disable 10bit clock to display controller */
1832 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1833 val
&= ~DPIO_DCLKP_EN
;
1834 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1836 /* disable left/right clock distribution */
1837 if (pipe
!= PIPE_B
) {
1838 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
);
1839 val
&= ~(CHV_BUFLEFTENA1_MASK
| CHV_BUFRIGHTENA1_MASK
);
1840 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
, val
);
1842 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
);
1843 val
&= ~(CHV_BUFLEFTENA2_MASK
| CHV_BUFRIGHTENA2_MASK
);
1844 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
, val
);
1847 mutex_unlock(&dev_priv
->dpio_lock
);
1850 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1851 struct intel_digital_port
*dport
,
1852 unsigned int expected_mask
)
1857 switch (dport
->port
) {
1859 port_mask
= DPLL_PORTB_READY_MASK
;
1863 port_mask
= DPLL_PORTC_READY_MASK
;
1865 expected_mask
<<= 4;
1868 port_mask
= DPLL_PORTD_READY_MASK
;
1869 dpll_reg
= DPIO_PHY_STATUS
;
1875 if (wait_for((I915_READ(dpll_reg
) & port_mask
) == expected_mask
, 1000))
1876 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1877 port_name(dport
->port
), I915_READ(dpll_reg
) & port_mask
, expected_mask
);
1880 static void intel_prepare_shared_dpll(struct intel_crtc
*crtc
)
1882 struct drm_device
*dev
= crtc
->base
.dev
;
1883 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1884 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1886 if (WARN_ON(pll
== NULL
))
1889 WARN_ON(!pll
->config
.crtc_mask
);
1890 if (pll
->active
== 0) {
1891 DRM_DEBUG_DRIVER("setting up %s\n", pll
->name
);
1893 assert_shared_dpll_disabled(dev_priv
, pll
);
1895 pll
->mode_set(dev_priv
, pll
);
1900 * intel_enable_shared_dpll - enable PCH PLL
1901 * @dev_priv: i915 private structure
1902 * @pipe: pipe PLL to enable
1904 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1905 * drives the transcoder clock.
1907 static void intel_enable_shared_dpll(struct intel_crtc
*crtc
)
1909 struct drm_device
*dev
= crtc
->base
.dev
;
1910 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1911 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1913 if (WARN_ON(pll
== NULL
))
1916 if (WARN_ON(pll
->config
.crtc_mask
== 0))
1919 DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n",
1920 pll
->name
, pll
->active
, pll
->on
,
1921 crtc
->base
.base
.id
);
1923 if (pll
->active
++) {
1925 assert_shared_dpll_enabled(dev_priv
, pll
);
1930 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
1932 DRM_DEBUG_KMS("enabling %s\n", pll
->name
);
1933 pll
->enable(dev_priv
, pll
);
1937 static void intel_disable_shared_dpll(struct intel_crtc
*crtc
)
1939 struct drm_device
*dev
= crtc
->base
.dev
;
1940 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1941 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1943 /* PCH only available on ILK+ */
1944 BUG_ON(INTEL_INFO(dev
)->gen
< 5);
1945 if (WARN_ON(pll
== NULL
))
1948 if (WARN_ON(pll
->config
.crtc_mask
== 0))
1951 DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
1952 pll
->name
, pll
->active
, pll
->on
,
1953 crtc
->base
.base
.id
);
1955 if (WARN_ON(pll
->active
== 0)) {
1956 assert_shared_dpll_disabled(dev_priv
, pll
);
1960 assert_shared_dpll_enabled(dev_priv
, pll
);
1965 DRM_DEBUG_KMS("disabling %s\n", pll
->name
);
1966 pll
->disable(dev_priv
, pll
);
1969 intel_display_power_put(dev_priv
, POWER_DOMAIN_PLLS
);
1972 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1975 struct drm_device
*dev
= dev_priv
->dev
;
1976 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1977 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1978 uint32_t reg
, val
, pipeconf_val
;
1980 /* PCH only available on ILK+ */
1981 BUG_ON(!HAS_PCH_SPLIT(dev
));
1983 /* Make sure PCH DPLL is enabled */
1984 assert_shared_dpll_enabled(dev_priv
,
1985 intel_crtc_to_shared_dpll(intel_crtc
));
1987 /* FDI must be feeding us bits for PCH ports */
1988 assert_fdi_tx_enabled(dev_priv
, pipe
);
1989 assert_fdi_rx_enabled(dev_priv
, pipe
);
1991 if (HAS_PCH_CPT(dev
)) {
1992 /* Workaround: Set the timing override bit before enabling the
1993 * pch transcoder. */
1994 reg
= TRANS_CHICKEN2(pipe
);
1995 val
= I915_READ(reg
);
1996 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1997 I915_WRITE(reg
, val
);
2000 reg
= PCH_TRANSCONF(pipe
);
2001 val
= I915_READ(reg
);
2002 pipeconf_val
= I915_READ(PIPECONF(pipe
));
2004 if (HAS_PCH_IBX(dev_priv
->dev
)) {
2006 * make the BPC in transcoder be consistent with
2007 * that in pipeconf reg.
2009 val
&= ~PIPECONF_BPC_MASK
;
2010 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
2013 val
&= ~TRANS_INTERLACE_MASK
;
2014 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
2015 if (HAS_PCH_IBX(dev_priv
->dev
) &&
2016 intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
2017 val
|= TRANS_LEGACY_INTERLACED_ILK
;
2019 val
|= TRANS_INTERLACED
;
2021 val
|= TRANS_PROGRESSIVE
;
2023 I915_WRITE(reg
, val
| TRANS_ENABLE
);
2024 if (wait_for(I915_READ(reg
) & TRANS_STATE_ENABLE
, 100))
2025 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
2028 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
2029 enum transcoder cpu_transcoder
)
2031 u32 val
, pipeconf_val
;
2033 /* PCH only available on ILK+ */
2034 BUG_ON(!HAS_PCH_SPLIT(dev_priv
->dev
));
2036 /* FDI must be feeding us bits for PCH ports */
2037 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
2038 assert_fdi_rx_enabled(dev_priv
, TRANSCODER_A
);
2040 /* Workaround: set timing override bit. */
2041 val
= I915_READ(_TRANSA_CHICKEN2
);
2042 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
2043 I915_WRITE(_TRANSA_CHICKEN2
, val
);
2046 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
2048 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
2049 PIPECONF_INTERLACED_ILK
)
2050 val
|= TRANS_INTERLACED
;
2052 val
|= TRANS_PROGRESSIVE
;
2054 I915_WRITE(LPT_TRANSCONF
, val
);
2055 if (wait_for(I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
, 100))
2056 DRM_ERROR("Failed to enable PCH transcoder\n");
2059 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
2062 struct drm_device
*dev
= dev_priv
->dev
;
2065 /* FDI relies on the transcoder */
2066 assert_fdi_tx_disabled(dev_priv
, pipe
);
2067 assert_fdi_rx_disabled(dev_priv
, pipe
);
2069 /* Ports must be off as well */
2070 assert_pch_ports_disabled(dev_priv
, pipe
);
2072 reg
= PCH_TRANSCONF(pipe
);
2073 val
= I915_READ(reg
);
2074 val
&= ~TRANS_ENABLE
;
2075 I915_WRITE(reg
, val
);
2076 /* wait for PCH transcoder off, transcoder state */
2077 if (wait_for((I915_READ(reg
) & TRANS_STATE_ENABLE
) == 0, 50))
2078 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
2080 if (!HAS_PCH_IBX(dev
)) {
2081 /* Workaround: Clear the timing override chicken bit again. */
2082 reg
= TRANS_CHICKEN2(pipe
);
2083 val
= I915_READ(reg
);
2084 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
2085 I915_WRITE(reg
, val
);
2089 static void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
2093 val
= I915_READ(LPT_TRANSCONF
);
2094 val
&= ~TRANS_ENABLE
;
2095 I915_WRITE(LPT_TRANSCONF
, val
);
2096 /* wait for PCH transcoder off, transcoder state */
2097 if (wait_for((I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
) == 0, 50))
2098 DRM_ERROR("Failed to disable PCH transcoder\n");
2100 /* Workaround: clear timing override bit. */
2101 val
= I915_READ(_TRANSA_CHICKEN2
);
2102 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
2103 I915_WRITE(_TRANSA_CHICKEN2
, val
);
2107 * intel_enable_pipe - enable a pipe, asserting requirements
2108 * @crtc: crtc responsible for the pipe
2110 * Enable @crtc's pipe, making sure that various hardware specific requirements
2111 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
2113 static void intel_enable_pipe(struct intel_crtc
*crtc
)
2115 struct drm_device
*dev
= crtc
->base
.dev
;
2116 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2117 enum pipe pipe
= crtc
->pipe
;
2118 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
2120 enum pipe pch_transcoder
;
2124 assert_planes_disabled(dev_priv
, pipe
);
2125 assert_cursor_disabled(dev_priv
, pipe
);
2126 assert_sprites_disabled(dev_priv
, pipe
);
2128 if (HAS_PCH_LPT(dev_priv
->dev
))
2129 pch_transcoder
= TRANSCODER_A
;
2131 pch_transcoder
= pipe
;
2134 * A pipe without a PLL won't actually be able to drive bits from
2135 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
2138 if (HAS_GMCH_DISPLAY(dev_priv
->dev
))
2139 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
))
2140 assert_dsi_pll_enabled(dev_priv
);
2142 assert_pll_enabled(dev_priv
, pipe
);
2144 if (crtc
->config
->has_pch_encoder
) {
2145 /* if driving the PCH, we need FDI enabled */
2146 assert_fdi_rx_pll_enabled(dev_priv
, pch_transcoder
);
2147 assert_fdi_tx_pll_enabled(dev_priv
,
2148 (enum pipe
) cpu_transcoder
);
2150 /* FIXME: assert CPU port conditions for SNB+ */
2153 reg
= PIPECONF(cpu_transcoder
);
2154 val
= I915_READ(reg
);
2155 if (val
& PIPECONF_ENABLE
) {
2156 WARN_ON(!((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
2157 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
)));
2161 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
2166 * intel_disable_pipe - disable a pipe, asserting requirements
2167 * @crtc: crtc whose pipes is to be disabled
2169 * Disable the pipe of @crtc, making sure that various hardware
2170 * specific requirements are met, if applicable, e.g. plane
2171 * disabled, panel fitter off, etc.
2173 * Will wait until the pipe has shut down before returning.
2175 static void intel_disable_pipe(struct intel_crtc
*crtc
)
2177 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
2178 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
2179 enum pipe pipe
= crtc
->pipe
;
2184 * Make sure planes won't keep trying to pump pixels to us,
2185 * or we might hang the display.
2187 assert_planes_disabled(dev_priv
, pipe
);
2188 assert_cursor_disabled(dev_priv
, pipe
);
2189 assert_sprites_disabled(dev_priv
, pipe
);
2191 reg
= PIPECONF(cpu_transcoder
);
2192 val
= I915_READ(reg
);
2193 if ((val
& PIPECONF_ENABLE
) == 0)
2197 * Double wide has implications for planes
2198 * so best keep it disabled when not needed.
2200 if (crtc
->config
->double_wide
)
2201 val
&= ~PIPECONF_DOUBLE_WIDE
;
2203 /* Don't disable pipe or pipe PLLs if needed */
2204 if (!(pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) &&
2205 !(pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
2206 val
&= ~PIPECONF_ENABLE
;
2208 I915_WRITE(reg
, val
);
2209 if ((val
& PIPECONF_ENABLE
) == 0)
2210 intel_wait_for_pipe_off(crtc
);
2214 * Plane regs are double buffered, going from enabled->disabled needs a
2215 * trigger in order to latch. The display address reg provides this.
2217 void intel_flush_primary_plane(struct drm_i915_private
*dev_priv
,
2220 struct drm_device
*dev
= dev_priv
->dev
;
2221 u32 reg
= INTEL_INFO(dev
)->gen
>= 4 ? DSPSURF(plane
) : DSPADDR(plane
);
2223 I915_WRITE(reg
, I915_READ(reg
));
2228 * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
2229 * @plane: plane to be enabled
2230 * @crtc: crtc for the plane
2232 * Enable @plane on @crtc, making sure that the pipe is running first.
2234 static void intel_enable_primary_hw_plane(struct drm_plane
*plane
,
2235 struct drm_crtc
*crtc
)
2237 struct drm_device
*dev
= plane
->dev
;
2238 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2239 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2241 /* If the pipe isn't enabled, we can't pump pixels and may hang */
2242 assert_pipe_enabled(dev_priv
, intel_crtc
->pipe
);
2243 to_intel_plane_state(plane
->state
)->visible
= true;
2245 dev_priv
->display
.update_primary_plane(crtc
, plane
->fb
,
2249 static bool need_vtd_wa(struct drm_device
*dev
)
2251 #ifdef CONFIG_INTEL_IOMMU
2252 if (INTEL_INFO(dev
)->gen
>= 6 && intel_iommu_gfx_mapped
)
2259 intel_tile_height(struct drm_device
*dev
, uint32_t pixel_format
,
2260 uint64_t fb_format_modifier
)
2262 unsigned int tile_height
;
2263 uint32_t pixel_bytes
;
2265 switch (fb_format_modifier
) {
2266 case DRM_FORMAT_MOD_NONE
:
2269 case I915_FORMAT_MOD_X_TILED
:
2270 tile_height
= IS_GEN2(dev
) ? 16 : 8;
2272 case I915_FORMAT_MOD_Y_TILED
:
2275 case I915_FORMAT_MOD_Yf_TILED
:
2276 pixel_bytes
= drm_format_plane_cpp(pixel_format
, 0);
2277 switch (pixel_bytes
) {
2291 "128-bit pixels are not supported for display!");
2297 MISSING_CASE(fb_format_modifier
);
2306 intel_fb_align_height(struct drm_device
*dev
, unsigned int height
,
2307 uint32_t pixel_format
, uint64_t fb_format_modifier
)
2309 return ALIGN(height
, intel_tile_height(dev
, pixel_format
,
2310 fb_format_modifier
));
2314 intel_fill_fb_ggtt_view(struct i915_ggtt_view
*view
, struct drm_framebuffer
*fb
,
2315 const struct drm_plane_state
*plane_state
)
2317 struct intel_rotation_info
*info
= &view
->rotation_info
;
2319 *view
= i915_ggtt_view_normal
;
2324 if (!intel_rotation_90_or_270(plane_state
->rotation
))
2327 *view
= i915_ggtt_view_rotated
;
2329 info
->height
= fb
->height
;
2330 info
->pixel_format
= fb
->pixel_format
;
2331 info
->pitch
= fb
->pitches
[0];
2332 info
->fb_modifier
= fb
->modifier
[0];
2338 intel_pin_and_fence_fb_obj(struct drm_plane
*plane
,
2339 struct drm_framebuffer
*fb
,
2340 const struct drm_plane_state
*plane_state
,
2341 struct intel_engine_cs
*pipelined
)
2343 struct drm_device
*dev
= fb
->dev
;
2344 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2345 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2346 struct i915_ggtt_view view
;
2350 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
2352 switch (fb
->modifier
[0]) {
2353 case DRM_FORMAT_MOD_NONE
:
2354 if (INTEL_INFO(dev
)->gen
>= 9)
2355 alignment
= 256 * 1024;
2356 else if (IS_BROADWATER(dev
) || IS_CRESTLINE(dev
))
2357 alignment
= 128 * 1024;
2358 else if (INTEL_INFO(dev
)->gen
>= 4)
2359 alignment
= 4 * 1024;
2361 alignment
= 64 * 1024;
2363 case I915_FORMAT_MOD_X_TILED
:
2364 if (INTEL_INFO(dev
)->gen
>= 9)
2365 alignment
= 256 * 1024;
2367 /* pin() will align the object as required by fence */
2371 case I915_FORMAT_MOD_Y_TILED
:
2372 case I915_FORMAT_MOD_Yf_TILED
:
2373 if (WARN_ONCE(INTEL_INFO(dev
)->gen
< 9,
2374 "Y tiling bo slipped through, driver bug!\n"))
2376 alignment
= 1 * 1024 * 1024;
2379 MISSING_CASE(fb
->modifier
[0]);
2383 ret
= intel_fill_fb_ggtt_view(&view
, fb
, plane_state
);
2387 /* Note that the w/a also requires 64 PTE of padding following the
2388 * bo. We currently fill all unused PTE with the shadow page and so
2389 * we should always have valid PTE following the scanout preventing
2392 if (need_vtd_wa(dev
) && alignment
< 256 * 1024)
2393 alignment
= 256 * 1024;
2396 * Global gtt pte registers are special registers which actually forward
2397 * writes to a chunk of system memory. Which means that there is no risk
2398 * that the register values disappear as soon as we call
2399 * intel_runtime_pm_put(), so it is correct to wrap only the
2400 * pin/unpin/fence and not more.
2402 intel_runtime_pm_get(dev_priv
);
2404 dev_priv
->mm
.interruptible
= false;
2405 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, pipelined
,
2408 goto err_interruptible
;
2410 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2411 * fence, whereas 965+ only requires a fence if using
2412 * framebuffer compression. For simplicity, we always install
2413 * a fence as the cost is not that onerous.
2415 ret
= i915_gem_object_get_fence(obj
);
2419 i915_gem_object_pin_fence(obj
);
2421 dev_priv
->mm
.interruptible
= true;
2422 intel_runtime_pm_put(dev_priv
);
2426 i915_gem_object_unpin_from_display_plane(obj
, &view
);
2428 dev_priv
->mm
.interruptible
= true;
2429 intel_runtime_pm_put(dev_priv
);
2433 static void intel_unpin_fb_obj(struct drm_framebuffer
*fb
,
2434 const struct drm_plane_state
*plane_state
)
2436 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2437 struct i915_ggtt_view view
;
2440 WARN_ON(!mutex_is_locked(&obj
->base
.dev
->struct_mutex
));
2442 ret
= intel_fill_fb_ggtt_view(&view
, fb
, plane_state
);
2443 WARN_ONCE(ret
, "Couldn't get view from plane state!");
2445 i915_gem_object_unpin_fence(obj
);
2446 i915_gem_object_unpin_from_display_plane(obj
, &view
);
2449 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
2450 * is assumed to be a power-of-two. */
2451 unsigned long intel_gen4_compute_page_offset(int *x
, int *y
,
2452 unsigned int tiling_mode
,
2456 if (tiling_mode
!= I915_TILING_NONE
) {
2457 unsigned int tile_rows
, tiles
;
2462 tiles
= *x
/ (512/cpp
);
2465 return tile_rows
* pitch
* 8 + tiles
* 4096;
2467 unsigned int offset
;
2469 offset
= *y
* pitch
+ *x
* cpp
;
2471 *x
= (offset
& 4095) / cpp
;
2472 return offset
& -4096;
2476 static int i9xx_format_to_fourcc(int format
)
2479 case DISPPLANE_8BPP
:
2480 return DRM_FORMAT_C8
;
2481 case DISPPLANE_BGRX555
:
2482 return DRM_FORMAT_XRGB1555
;
2483 case DISPPLANE_BGRX565
:
2484 return DRM_FORMAT_RGB565
;
2486 case DISPPLANE_BGRX888
:
2487 return DRM_FORMAT_XRGB8888
;
2488 case DISPPLANE_RGBX888
:
2489 return DRM_FORMAT_XBGR8888
;
2490 case DISPPLANE_BGRX101010
:
2491 return DRM_FORMAT_XRGB2101010
;
2492 case DISPPLANE_RGBX101010
:
2493 return DRM_FORMAT_XBGR2101010
;
2497 static int skl_format_to_fourcc(int format
, bool rgb_order
, bool alpha
)
2500 case PLANE_CTL_FORMAT_RGB_565
:
2501 return DRM_FORMAT_RGB565
;
2503 case PLANE_CTL_FORMAT_XRGB_8888
:
2506 return DRM_FORMAT_ABGR8888
;
2508 return DRM_FORMAT_XBGR8888
;
2511 return DRM_FORMAT_ARGB8888
;
2513 return DRM_FORMAT_XRGB8888
;
2515 case PLANE_CTL_FORMAT_XRGB_2101010
:
2517 return DRM_FORMAT_XBGR2101010
;
2519 return DRM_FORMAT_XRGB2101010
;
2524 intel_alloc_initial_plane_obj(struct intel_crtc
*crtc
,
2525 struct intel_initial_plane_config
*plane_config
)
2527 struct drm_device
*dev
= crtc
->base
.dev
;
2528 struct drm_i915_gem_object
*obj
= NULL
;
2529 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2530 struct drm_framebuffer
*fb
= &plane_config
->fb
->base
;
2531 u32 base_aligned
= round_down(plane_config
->base
, PAGE_SIZE
);
2532 u32 size_aligned
= round_up(plane_config
->base
+ plane_config
->size
,
2535 size_aligned
-= base_aligned
;
2537 if (plane_config
->size
== 0)
2540 obj
= i915_gem_object_create_stolen_for_preallocated(dev
,
2547 obj
->tiling_mode
= plane_config
->tiling
;
2548 if (obj
->tiling_mode
== I915_TILING_X
)
2549 obj
->stride
= fb
->pitches
[0];
2551 mode_cmd
.pixel_format
= fb
->pixel_format
;
2552 mode_cmd
.width
= fb
->width
;
2553 mode_cmd
.height
= fb
->height
;
2554 mode_cmd
.pitches
[0] = fb
->pitches
[0];
2555 mode_cmd
.modifier
[0] = fb
->modifier
[0];
2556 mode_cmd
.flags
= DRM_MODE_FB_MODIFIERS
;
2558 mutex_lock(&dev
->struct_mutex
);
2559 if (intel_framebuffer_init(dev
, to_intel_framebuffer(fb
),
2561 DRM_DEBUG_KMS("intel fb init failed\n");
2564 mutex_unlock(&dev
->struct_mutex
);
2566 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj
);
2570 drm_gem_object_unreference(&obj
->base
);
2571 mutex_unlock(&dev
->struct_mutex
);
2575 /* Update plane->state->fb to match plane->fb after driver-internal updates */
2577 update_state_fb(struct drm_plane
*plane
)
2579 if (plane
->fb
== plane
->state
->fb
)
2582 if (plane
->state
->fb
)
2583 drm_framebuffer_unreference(plane
->state
->fb
);
2584 plane
->state
->fb
= plane
->fb
;
2585 if (plane
->state
->fb
)
2586 drm_framebuffer_reference(plane
->state
->fb
);
2590 intel_find_initial_plane_obj(struct intel_crtc
*intel_crtc
,
2591 struct intel_initial_plane_config
*plane_config
)
2593 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2594 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2596 struct intel_crtc
*i
;
2597 struct drm_i915_gem_object
*obj
;
2598 struct drm_plane
*primary
= intel_crtc
->base
.primary
;
2599 struct drm_framebuffer
*fb
;
2601 if (!plane_config
->fb
)
2604 if (intel_alloc_initial_plane_obj(intel_crtc
, plane_config
)) {
2605 fb
= &plane_config
->fb
->base
;
2609 kfree(plane_config
->fb
);
2612 * Failed to alloc the obj, check to see if we should share
2613 * an fb with another CRTC instead
2615 for_each_crtc(dev
, c
) {
2616 i
= to_intel_crtc(c
);
2618 if (c
== &intel_crtc
->base
)
2624 fb
= c
->primary
->fb
;
2628 obj
= intel_fb_obj(fb
);
2629 if (i915_gem_obj_ggtt_offset(obj
) == plane_config
->base
) {
2630 drm_framebuffer_reference(fb
);
2638 obj
= intel_fb_obj(fb
);
2639 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2640 dev_priv
->preserve_bios_swizzle
= true;
2643 primary
->state
->crtc
= &intel_crtc
->base
;
2644 primary
->crtc
= &intel_crtc
->base
;
2645 update_state_fb(primary
);
2646 obj
->frontbuffer_bits
|= INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
);
2649 static void i9xx_update_primary_plane(struct drm_crtc
*crtc
,
2650 struct drm_framebuffer
*fb
,
2653 struct drm_device
*dev
= crtc
->dev
;
2654 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2655 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2656 struct drm_plane
*primary
= crtc
->primary
;
2657 bool visible
= to_intel_plane_state(primary
->state
)->visible
;
2658 struct drm_i915_gem_object
*obj
;
2659 int plane
= intel_crtc
->plane
;
2660 unsigned long linear_offset
;
2662 u32 reg
= DSPCNTR(plane
);
2665 if (!visible
|| !fb
) {
2667 if (INTEL_INFO(dev
)->gen
>= 4)
2668 I915_WRITE(DSPSURF(plane
), 0);
2670 I915_WRITE(DSPADDR(plane
), 0);
2675 obj
= intel_fb_obj(fb
);
2676 if (WARN_ON(obj
== NULL
))
2679 pixel_size
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2681 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2683 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2685 if (INTEL_INFO(dev
)->gen
< 4) {
2686 if (intel_crtc
->pipe
== PIPE_B
)
2687 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
2689 /* pipesrc and dspsize control the size that is scaled from,
2690 * which should always be the user's requested size.
2692 I915_WRITE(DSPSIZE(plane
),
2693 ((intel_crtc
->config
->pipe_src_h
- 1) << 16) |
2694 (intel_crtc
->config
->pipe_src_w
- 1));
2695 I915_WRITE(DSPPOS(plane
), 0);
2696 } else if (IS_CHERRYVIEW(dev
) && plane
== PLANE_B
) {
2697 I915_WRITE(PRIMSIZE(plane
),
2698 ((intel_crtc
->config
->pipe_src_h
- 1) << 16) |
2699 (intel_crtc
->config
->pipe_src_w
- 1));
2700 I915_WRITE(PRIMPOS(plane
), 0);
2701 I915_WRITE(PRIMCNSTALPHA(plane
), 0);
2704 switch (fb
->pixel_format
) {
2706 dspcntr
|= DISPPLANE_8BPP
;
2708 case DRM_FORMAT_XRGB1555
:
2709 dspcntr
|= DISPPLANE_BGRX555
;
2711 case DRM_FORMAT_RGB565
:
2712 dspcntr
|= DISPPLANE_BGRX565
;
2714 case DRM_FORMAT_XRGB8888
:
2715 dspcntr
|= DISPPLANE_BGRX888
;
2717 case DRM_FORMAT_XBGR8888
:
2718 dspcntr
|= DISPPLANE_RGBX888
;
2720 case DRM_FORMAT_XRGB2101010
:
2721 dspcntr
|= DISPPLANE_BGRX101010
;
2723 case DRM_FORMAT_XBGR2101010
:
2724 dspcntr
|= DISPPLANE_RGBX101010
;
2730 if (INTEL_INFO(dev
)->gen
>= 4 &&
2731 obj
->tiling_mode
!= I915_TILING_NONE
)
2732 dspcntr
|= DISPPLANE_TILED
;
2735 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2737 linear_offset
= y
* fb
->pitches
[0] + x
* pixel_size
;
2739 if (INTEL_INFO(dev
)->gen
>= 4) {
2740 intel_crtc
->dspaddr_offset
=
2741 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2744 linear_offset
-= intel_crtc
->dspaddr_offset
;
2746 intel_crtc
->dspaddr_offset
= linear_offset
;
2749 if (crtc
->primary
->state
->rotation
== BIT(DRM_ROTATE_180
)) {
2750 dspcntr
|= DISPPLANE_ROTATE_180
;
2752 x
+= (intel_crtc
->config
->pipe_src_w
- 1);
2753 y
+= (intel_crtc
->config
->pipe_src_h
- 1);
2755 /* Finding the last pixel of the last line of the display
2756 data and adding to linear_offset*/
2758 (intel_crtc
->config
->pipe_src_h
- 1) * fb
->pitches
[0] +
2759 (intel_crtc
->config
->pipe_src_w
- 1) * pixel_size
;
2762 I915_WRITE(reg
, dspcntr
);
2764 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2765 if (INTEL_INFO(dev
)->gen
>= 4) {
2766 I915_WRITE(DSPSURF(plane
),
2767 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2768 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2769 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2771 I915_WRITE(DSPADDR(plane
), i915_gem_obj_ggtt_offset(obj
) + linear_offset
);
2775 static void ironlake_update_primary_plane(struct drm_crtc
*crtc
,
2776 struct drm_framebuffer
*fb
,
2779 struct drm_device
*dev
= crtc
->dev
;
2780 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2781 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2782 struct drm_plane
*primary
= crtc
->primary
;
2783 bool visible
= to_intel_plane_state(primary
->state
)->visible
;
2784 struct drm_i915_gem_object
*obj
;
2785 int plane
= intel_crtc
->plane
;
2786 unsigned long linear_offset
;
2788 u32 reg
= DSPCNTR(plane
);
2791 if (!visible
|| !fb
) {
2793 I915_WRITE(DSPSURF(plane
), 0);
2798 obj
= intel_fb_obj(fb
);
2799 if (WARN_ON(obj
== NULL
))
2802 pixel_size
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2804 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2806 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2808 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2809 dspcntr
|= DISPPLANE_PIPE_CSC_ENABLE
;
2811 switch (fb
->pixel_format
) {
2813 dspcntr
|= DISPPLANE_8BPP
;
2815 case DRM_FORMAT_RGB565
:
2816 dspcntr
|= DISPPLANE_BGRX565
;
2818 case DRM_FORMAT_XRGB8888
:
2819 dspcntr
|= DISPPLANE_BGRX888
;
2821 case DRM_FORMAT_XBGR8888
:
2822 dspcntr
|= DISPPLANE_RGBX888
;
2824 case DRM_FORMAT_XRGB2101010
:
2825 dspcntr
|= DISPPLANE_BGRX101010
;
2827 case DRM_FORMAT_XBGR2101010
:
2828 dspcntr
|= DISPPLANE_RGBX101010
;
2834 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2835 dspcntr
|= DISPPLANE_TILED
;
2837 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
))
2838 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2840 linear_offset
= y
* fb
->pitches
[0] + x
* pixel_size
;
2841 intel_crtc
->dspaddr_offset
=
2842 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2845 linear_offset
-= intel_crtc
->dspaddr_offset
;
2846 if (crtc
->primary
->state
->rotation
== BIT(DRM_ROTATE_180
)) {
2847 dspcntr
|= DISPPLANE_ROTATE_180
;
2849 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
)) {
2850 x
+= (intel_crtc
->config
->pipe_src_w
- 1);
2851 y
+= (intel_crtc
->config
->pipe_src_h
- 1);
2853 /* Finding the last pixel of the last line of the display
2854 data and adding to linear_offset*/
2856 (intel_crtc
->config
->pipe_src_h
- 1) * fb
->pitches
[0] +
2857 (intel_crtc
->config
->pipe_src_w
- 1) * pixel_size
;
2861 I915_WRITE(reg
, dspcntr
);
2863 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2864 I915_WRITE(DSPSURF(plane
),
2865 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2866 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2867 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
2869 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2870 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2875 u32
intel_fb_stride_alignment(struct drm_device
*dev
, uint64_t fb_modifier
,
2876 uint32_t pixel_format
)
2878 u32 bits_per_pixel
= drm_format_plane_cpp(pixel_format
, 0) * 8;
2881 * The stride is either expressed as a multiple of 64 bytes
2882 * chunks for linear buffers or in number of tiles for tiled
2885 switch (fb_modifier
) {
2886 case DRM_FORMAT_MOD_NONE
:
2888 case I915_FORMAT_MOD_X_TILED
:
2889 if (INTEL_INFO(dev
)->gen
== 2)
2892 case I915_FORMAT_MOD_Y_TILED
:
2893 /* No need to check for old gens and Y tiling since this is
2894 * about the display engine and those will be blocked before
2898 case I915_FORMAT_MOD_Yf_TILED
:
2899 if (bits_per_pixel
== 8)
2904 MISSING_CASE(fb_modifier
);
2909 unsigned long intel_plane_obj_offset(struct intel_plane
*intel_plane
,
2910 struct drm_i915_gem_object
*obj
)
2912 const struct i915_ggtt_view
*view
= &i915_ggtt_view_normal
;
2914 if (intel_rotation_90_or_270(intel_plane
->base
.state
->rotation
))
2915 view
= &i915_ggtt_view_rotated
;
2917 return i915_gem_obj_ggtt_offset_view(obj
, view
);
2921 * This function detaches (aka. unbinds) unused scalers in hardware
2923 void skl_detach_scalers(struct intel_crtc
*intel_crtc
)
2925 struct drm_device
*dev
;
2926 struct drm_i915_private
*dev_priv
;
2927 struct intel_crtc_scaler_state
*scaler_state
;
2930 if (!intel_crtc
|| !intel_crtc
->config
)
2933 dev
= intel_crtc
->base
.dev
;
2934 dev_priv
= dev
->dev_private
;
2935 scaler_state
= &intel_crtc
->config
->scaler_state
;
2937 /* loop through and disable scalers that aren't in use */
2938 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
2939 if (!scaler_state
->scalers
[i
].in_use
) {
2940 I915_WRITE(SKL_PS_CTRL(intel_crtc
->pipe
, i
), 0);
2941 I915_WRITE(SKL_PS_WIN_POS(intel_crtc
->pipe
, i
), 0);
2942 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc
->pipe
, i
), 0);
2943 DRM_DEBUG_KMS("CRTC:%d Disabled scaler id %u.%u\n",
2944 intel_crtc
->base
.base
.id
, intel_crtc
->pipe
, i
);
2949 u32
skl_plane_ctl_format(uint32_t pixel_format
)
2951 switch (pixel_format
) {
2953 return PLANE_CTL_FORMAT_INDEXED
;
2954 case DRM_FORMAT_RGB565
:
2955 return PLANE_CTL_FORMAT_RGB_565
;
2956 case DRM_FORMAT_XBGR8888
:
2957 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
;
2958 case DRM_FORMAT_XRGB8888
:
2959 return PLANE_CTL_FORMAT_XRGB_8888
;
2961 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
2962 * to be already pre-multiplied. We need to add a knob (or a different
2963 * DRM_FORMAT) for user-space to configure that.
2965 case DRM_FORMAT_ABGR8888
:
2966 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
|
2967 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
2968 case DRM_FORMAT_ARGB8888
:
2969 return PLANE_CTL_FORMAT_XRGB_8888
|
2970 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
2971 case DRM_FORMAT_XRGB2101010
:
2972 return PLANE_CTL_FORMAT_XRGB_2101010
;
2973 case DRM_FORMAT_XBGR2101010
:
2974 return PLANE_CTL_ORDER_RGBX
| PLANE_CTL_FORMAT_XRGB_2101010
;
2975 case DRM_FORMAT_YUYV
:
2976 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YUYV
;
2977 case DRM_FORMAT_YVYU
:
2978 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YVYU
;
2979 case DRM_FORMAT_UYVY
:
2980 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_UYVY
;
2981 case DRM_FORMAT_VYUY
:
2982 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_VYUY
;
2984 MISSING_CASE(pixel_format
);
2990 u32
skl_plane_ctl_tiling(uint64_t fb_modifier
)
2992 switch (fb_modifier
) {
2993 case DRM_FORMAT_MOD_NONE
:
2995 case I915_FORMAT_MOD_X_TILED
:
2996 return PLANE_CTL_TILED_X
;
2997 case I915_FORMAT_MOD_Y_TILED
:
2998 return PLANE_CTL_TILED_Y
;
2999 case I915_FORMAT_MOD_Yf_TILED
:
3000 return PLANE_CTL_TILED_YF
;
3002 MISSING_CASE(fb_modifier
);
3008 u32
skl_plane_ctl_rotation(unsigned int rotation
)
3011 case BIT(DRM_ROTATE_0
):
3014 * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr
3015 * while i915 HW rotation is clockwise, thats why this swapping.
3017 case BIT(DRM_ROTATE_90
):
3018 return PLANE_CTL_ROTATE_270
;
3019 case BIT(DRM_ROTATE_180
):
3020 return PLANE_CTL_ROTATE_180
;
3021 case BIT(DRM_ROTATE_270
):
3022 return PLANE_CTL_ROTATE_90
;
3024 MISSING_CASE(rotation
);
3030 static void skylake_update_primary_plane(struct drm_crtc
*crtc
,
3031 struct drm_framebuffer
*fb
,
3034 struct drm_device
*dev
= crtc
->dev
;
3035 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3036 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3037 struct drm_plane
*plane
= crtc
->primary
;
3038 bool visible
= to_intel_plane_state(plane
->state
)->visible
;
3039 struct drm_i915_gem_object
*obj
;
3040 int pipe
= intel_crtc
->pipe
;
3041 u32 plane_ctl
, stride_div
, stride
;
3042 u32 tile_height
, plane_offset
, plane_size
;
3043 unsigned int rotation
;
3044 int x_offset
, y_offset
;
3045 unsigned long surf_addr
;
3046 struct intel_crtc_state
*crtc_state
= intel_crtc
->config
;
3047 struct intel_plane_state
*plane_state
;
3048 int src_x
= 0, src_y
= 0, src_w
= 0, src_h
= 0;
3049 int dst_x
= 0, dst_y
= 0, dst_w
= 0, dst_h
= 0;
3052 plane_state
= to_intel_plane_state(plane
->state
);
3054 if (!visible
|| !fb
) {
3055 I915_WRITE(PLANE_CTL(pipe
, 0), 0);
3056 I915_WRITE(PLANE_SURF(pipe
, 0), 0);
3057 POSTING_READ(PLANE_CTL(pipe
, 0));
3061 plane_ctl
= PLANE_CTL_ENABLE
|
3062 PLANE_CTL_PIPE_GAMMA_ENABLE
|
3063 PLANE_CTL_PIPE_CSC_ENABLE
;
3065 plane_ctl
|= skl_plane_ctl_format(fb
->pixel_format
);
3066 plane_ctl
|= skl_plane_ctl_tiling(fb
->modifier
[0]);
3067 plane_ctl
|= PLANE_CTL_PLANE_GAMMA_DISABLE
;
3069 rotation
= plane
->state
->rotation
;
3070 plane_ctl
|= skl_plane_ctl_rotation(rotation
);
3072 obj
= intel_fb_obj(fb
);
3073 stride_div
= intel_fb_stride_alignment(dev
, fb
->modifier
[0],
3075 surf_addr
= intel_plane_obj_offset(to_intel_plane(plane
), obj
);
3078 * FIXME: intel_plane_state->src, dst aren't set when transitional
3079 * update_plane helpers are called from legacy paths.
3080 * Once full atomic crtc is available, below check can be avoided.
3082 if (drm_rect_width(&plane_state
->src
)) {
3083 scaler_id
= plane_state
->scaler_id
;
3084 src_x
= plane_state
->src
.x1
>> 16;
3085 src_y
= plane_state
->src
.y1
>> 16;
3086 src_w
= drm_rect_width(&plane_state
->src
) >> 16;
3087 src_h
= drm_rect_height(&plane_state
->src
) >> 16;
3088 dst_x
= plane_state
->dst
.x1
;
3089 dst_y
= plane_state
->dst
.y1
;
3090 dst_w
= drm_rect_width(&plane_state
->dst
);
3091 dst_h
= drm_rect_height(&plane_state
->dst
);
3093 WARN_ON(x
!= src_x
|| y
!= src_y
);
3095 src_w
= intel_crtc
->config
->pipe_src_w
;
3096 src_h
= intel_crtc
->config
->pipe_src_h
;
3099 if (intel_rotation_90_or_270(rotation
)) {
3100 /* stride = Surface height in tiles */
3101 tile_height
= intel_tile_height(dev
, fb
->pixel_format
,
3103 stride
= DIV_ROUND_UP(fb
->height
, tile_height
);
3104 x_offset
= stride
* tile_height
- y
- src_h
;
3106 plane_size
= (src_w
- 1) << 16 | (src_h
- 1);
3108 stride
= fb
->pitches
[0] / stride_div
;
3111 plane_size
= (src_h
- 1) << 16 | (src_w
- 1);
3113 plane_offset
= y_offset
<< 16 | x_offset
;
3115 I915_WRITE(PLANE_CTL(pipe
, 0), plane_ctl
);
3116 I915_WRITE(PLANE_OFFSET(pipe
, 0), plane_offset
);
3117 I915_WRITE(PLANE_SIZE(pipe
, 0), plane_size
);
3118 I915_WRITE(PLANE_STRIDE(pipe
, 0), stride
);
3120 if (scaler_id
>= 0) {
3121 uint32_t ps_ctrl
= 0;
3123 WARN_ON(!dst_w
|| !dst_h
);
3124 ps_ctrl
= PS_SCALER_EN
| PS_PLANE_SEL(0) |
3125 crtc_state
->scaler_state
.scalers
[scaler_id
].mode
;
3126 I915_WRITE(SKL_PS_CTRL(pipe
, scaler_id
), ps_ctrl
);
3127 I915_WRITE(SKL_PS_PWR_GATE(pipe
, scaler_id
), 0);
3128 I915_WRITE(SKL_PS_WIN_POS(pipe
, scaler_id
), (dst_x
<< 16) | dst_y
);
3129 I915_WRITE(SKL_PS_WIN_SZ(pipe
, scaler_id
), (dst_w
<< 16) | dst_h
);
3130 I915_WRITE(PLANE_POS(pipe
, 0), 0);
3132 I915_WRITE(PLANE_POS(pipe
, 0), (dst_y
<< 16) | dst_x
);
3135 I915_WRITE(PLANE_SURF(pipe
, 0), surf_addr
);
3137 POSTING_READ(PLANE_SURF(pipe
, 0));
3140 /* Assume fb object is pinned & idle & fenced and just update base pointers */
3142 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
3143 int x
, int y
, enum mode_set_atomic state
)
3145 struct drm_device
*dev
= crtc
->dev
;
3146 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3148 if (dev_priv
->display
.disable_fbc
)
3149 dev_priv
->display
.disable_fbc(dev
);
3151 dev_priv
->display
.update_primary_plane(crtc
, fb
, x
, y
);
3156 static void intel_complete_page_flips(struct drm_device
*dev
)
3158 struct drm_crtc
*crtc
;
3160 for_each_crtc(dev
, crtc
) {
3161 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3162 enum plane plane
= intel_crtc
->plane
;
3164 intel_prepare_page_flip(dev
, plane
);
3165 intel_finish_page_flip_plane(dev
, plane
);
3169 static void intel_update_primary_planes(struct drm_device
*dev
)
3171 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3172 struct drm_crtc
*crtc
;
3174 for_each_crtc(dev
, crtc
) {
3175 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3177 drm_modeset_lock(&crtc
->mutex
, NULL
);
3179 * FIXME: Once we have proper support for primary planes (and
3180 * disabling them without disabling the entire crtc) allow again
3181 * a NULL crtc->primary->fb.
3183 if (intel_crtc
->active
&& crtc
->primary
->fb
)
3184 dev_priv
->display
.update_primary_plane(crtc
,
3188 drm_modeset_unlock(&crtc
->mutex
);
3192 void intel_crtc_reset(struct intel_crtc
*crtc
)
3194 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
3199 intel_crtc_disable_planes(&crtc
->base
);
3200 dev_priv
->display
.crtc_disable(&crtc
->base
);
3201 dev_priv
->display
.crtc_enable(&crtc
->base
);
3202 intel_crtc_enable_planes(&crtc
->base
);
3205 void intel_prepare_reset(struct drm_device
*dev
)
3207 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3208 struct intel_crtc
*crtc
;
3210 /* no reset support for gen2 */
3214 /* reset doesn't touch the display */
3215 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
3218 drm_modeset_lock_all(dev
);
3221 * Disabling the crtcs gracefully seems nicer. Also the
3222 * g33 docs say we should at least disable all the planes.
3224 for_each_intel_crtc(dev
, crtc
) {
3228 intel_crtc_disable_planes(&crtc
->base
);
3229 dev_priv
->display
.crtc_disable(&crtc
->base
);
3233 void intel_finish_reset(struct drm_device
*dev
)
3235 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3238 * Flips in the rings will be nuked by the reset,
3239 * so complete all pending flips so that user space
3240 * will get its events and not get stuck.
3242 intel_complete_page_flips(dev
);
3244 /* no reset support for gen2 */
3248 /* reset doesn't touch the display */
3249 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
)) {
3251 * Flips in the rings have been nuked by the reset,
3252 * so update the base address of all primary
3253 * planes to the the last fb to make sure we're
3254 * showing the correct fb after a reset.
3256 intel_update_primary_planes(dev
);
3261 * The display has been reset as well,
3262 * so need a full re-initialization.
3264 intel_runtime_pm_disable_interrupts(dev_priv
);
3265 intel_runtime_pm_enable_interrupts(dev_priv
);
3267 intel_modeset_init_hw(dev
);
3269 spin_lock_irq(&dev_priv
->irq_lock
);
3270 if (dev_priv
->display
.hpd_irq_setup
)
3271 dev_priv
->display
.hpd_irq_setup(dev
);
3272 spin_unlock_irq(&dev_priv
->irq_lock
);
3274 intel_modeset_setup_hw_state(dev
, true);
3276 intel_hpd_init(dev_priv
);
3278 drm_modeset_unlock_all(dev
);
3282 intel_finish_fb(struct drm_framebuffer
*old_fb
)
3284 struct drm_i915_gem_object
*obj
= intel_fb_obj(old_fb
);
3285 struct drm_i915_private
*dev_priv
= to_i915(obj
->base
.dev
);
3286 bool was_interruptible
= dev_priv
->mm
.interruptible
;
3289 /* Big Hammer, we also need to ensure that any pending
3290 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
3291 * current scanout is retired before unpinning the old
3292 * framebuffer. Note that we rely on userspace rendering
3293 * into the buffer attached to the pipe they are waiting
3294 * on. If not, userspace generates a GPU hang with IPEHR
3295 * point to the MI_WAIT_FOR_EVENT.
3297 * This should only fail upon a hung GPU, in which case we
3298 * can safely continue.
3300 dev_priv
->mm
.interruptible
= false;
3301 ret
= i915_gem_object_wait_rendering(obj
, true);
3302 dev_priv
->mm
.interruptible
= was_interruptible
;
3307 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
3309 struct drm_device
*dev
= crtc
->dev
;
3310 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3311 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3314 if (i915_reset_in_progress(&dev_priv
->gpu_error
) ||
3315 intel_crtc
->reset_counter
!= atomic_read(&dev_priv
->gpu_error
.reset_counter
))
3318 spin_lock_irq(&dev
->event_lock
);
3319 pending
= to_intel_crtc(crtc
)->unpin_work
!= NULL
;
3320 spin_unlock_irq(&dev
->event_lock
);
3325 static void intel_update_pipe_size(struct intel_crtc
*crtc
)
3327 struct drm_device
*dev
= crtc
->base
.dev
;
3328 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3329 const struct drm_display_mode
*adjusted_mode
;
3335 * Update pipe size and adjust fitter if needed: the reason for this is
3336 * that in compute_mode_changes we check the native mode (not the pfit
3337 * mode) to see if we can flip rather than do a full mode set. In the
3338 * fastboot case, we'll flip, but if we don't update the pipesrc and
3339 * pfit state, we'll end up with a big fb scanned out into the wrong
3342 * To fix this properly, we need to hoist the checks up into
3343 * compute_mode_changes (or above), check the actual pfit state and
3344 * whether the platform allows pfit disable with pipe active, and only
3345 * then update the pipesrc and pfit state, even on the flip path.
3348 adjusted_mode
= &crtc
->config
->base
.adjusted_mode
;
3350 I915_WRITE(PIPESRC(crtc
->pipe
),
3351 ((adjusted_mode
->crtc_hdisplay
- 1) << 16) |
3352 (adjusted_mode
->crtc_vdisplay
- 1));
3353 if (!crtc
->config
->pch_pfit
.enabled
&&
3354 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) ||
3355 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
3356 I915_WRITE(PF_CTL(crtc
->pipe
), 0);
3357 I915_WRITE(PF_WIN_POS(crtc
->pipe
), 0);
3358 I915_WRITE(PF_WIN_SZ(crtc
->pipe
), 0);
3360 crtc
->config
->pipe_src_w
= adjusted_mode
->crtc_hdisplay
;
3361 crtc
->config
->pipe_src_h
= adjusted_mode
->crtc_vdisplay
;
3364 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
3366 struct drm_device
*dev
= crtc
->dev
;
3367 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3368 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3369 int pipe
= intel_crtc
->pipe
;
3372 /* enable normal train */
3373 reg
= FDI_TX_CTL(pipe
);
3374 temp
= I915_READ(reg
);
3375 if (IS_IVYBRIDGE(dev
)) {
3376 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3377 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3379 temp
&= ~FDI_LINK_TRAIN_NONE
;
3380 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3382 I915_WRITE(reg
, temp
);
3384 reg
= FDI_RX_CTL(pipe
);
3385 temp
= I915_READ(reg
);
3386 if (HAS_PCH_CPT(dev
)) {
3387 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3388 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
3390 temp
&= ~FDI_LINK_TRAIN_NONE
;
3391 temp
|= FDI_LINK_TRAIN_NONE
;
3393 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
3395 /* wait one idle pattern time */
3399 /* IVB wants error correction enabled */
3400 if (IS_IVYBRIDGE(dev
))
3401 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
3402 FDI_FE_ERRC_ENABLE
);
3405 /* The FDI link training functions for ILK/Ibexpeak. */
3406 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
3408 struct drm_device
*dev
= crtc
->dev
;
3409 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3410 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3411 int pipe
= intel_crtc
->pipe
;
3412 u32 reg
, temp
, tries
;
3414 /* FDI needs bits from pipe first */
3415 assert_pipe_enabled(dev_priv
, pipe
);
3417 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3419 reg
= FDI_RX_IMR(pipe
);
3420 temp
= I915_READ(reg
);
3421 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3422 temp
&= ~FDI_RX_BIT_LOCK
;
3423 I915_WRITE(reg
, temp
);
3427 /* enable CPU FDI TX and PCH FDI RX */
3428 reg
= FDI_TX_CTL(pipe
);
3429 temp
= I915_READ(reg
);
3430 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3431 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3432 temp
&= ~FDI_LINK_TRAIN_NONE
;
3433 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3434 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3436 reg
= FDI_RX_CTL(pipe
);
3437 temp
= I915_READ(reg
);
3438 temp
&= ~FDI_LINK_TRAIN_NONE
;
3439 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3440 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3445 /* Ironlake workaround, enable clock pointer after FDI enable*/
3446 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3447 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
3448 FDI_RX_PHASE_SYNC_POINTER_EN
);
3450 reg
= FDI_RX_IIR(pipe
);
3451 for (tries
= 0; tries
< 5; tries
++) {
3452 temp
= I915_READ(reg
);
3453 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3455 if ((temp
& FDI_RX_BIT_LOCK
)) {
3456 DRM_DEBUG_KMS("FDI train 1 done.\n");
3457 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3462 DRM_ERROR("FDI train 1 fail!\n");
3465 reg
= FDI_TX_CTL(pipe
);
3466 temp
= I915_READ(reg
);
3467 temp
&= ~FDI_LINK_TRAIN_NONE
;
3468 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3469 I915_WRITE(reg
, temp
);
3471 reg
= FDI_RX_CTL(pipe
);
3472 temp
= I915_READ(reg
);
3473 temp
&= ~FDI_LINK_TRAIN_NONE
;
3474 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3475 I915_WRITE(reg
, temp
);
3480 reg
= FDI_RX_IIR(pipe
);
3481 for (tries
= 0; tries
< 5; tries
++) {
3482 temp
= I915_READ(reg
);
3483 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3485 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3486 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3487 DRM_DEBUG_KMS("FDI train 2 done.\n");
3492 DRM_ERROR("FDI train 2 fail!\n");
3494 DRM_DEBUG_KMS("FDI train done\n");
3498 static const int snb_b_fdi_train_param
[] = {
3499 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
3500 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
3501 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
3502 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
3505 /* The FDI link training functions for SNB/Cougarpoint. */
3506 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
3508 struct drm_device
*dev
= crtc
->dev
;
3509 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3510 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3511 int pipe
= intel_crtc
->pipe
;
3512 u32 reg
, temp
, i
, retry
;
3514 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3516 reg
= FDI_RX_IMR(pipe
);
3517 temp
= I915_READ(reg
);
3518 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3519 temp
&= ~FDI_RX_BIT_LOCK
;
3520 I915_WRITE(reg
, temp
);
3525 /* enable CPU FDI TX and PCH FDI RX */
3526 reg
= FDI_TX_CTL(pipe
);
3527 temp
= I915_READ(reg
);
3528 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3529 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3530 temp
&= ~FDI_LINK_TRAIN_NONE
;
3531 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3532 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3534 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3535 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3537 I915_WRITE(FDI_RX_MISC(pipe
),
3538 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3540 reg
= FDI_RX_CTL(pipe
);
3541 temp
= I915_READ(reg
);
3542 if (HAS_PCH_CPT(dev
)) {
3543 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3544 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3546 temp
&= ~FDI_LINK_TRAIN_NONE
;
3547 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3549 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3554 for (i
= 0; i
< 4; i
++) {
3555 reg
= FDI_TX_CTL(pipe
);
3556 temp
= I915_READ(reg
);
3557 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3558 temp
|= snb_b_fdi_train_param
[i
];
3559 I915_WRITE(reg
, temp
);
3564 for (retry
= 0; retry
< 5; retry
++) {
3565 reg
= FDI_RX_IIR(pipe
);
3566 temp
= I915_READ(reg
);
3567 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3568 if (temp
& FDI_RX_BIT_LOCK
) {
3569 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3570 DRM_DEBUG_KMS("FDI train 1 done.\n");
3579 DRM_ERROR("FDI train 1 fail!\n");
3582 reg
= FDI_TX_CTL(pipe
);
3583 temp
= I915_READ(reg
);
3584 temp
&= ~FDI_LINK_TRAIN_NONE
;
3585 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3587 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3589 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3591 I915_WRITE(reg
, temp
);
3593 reg
= FDI_RX_CTL(pipe
);
3594 temp
= I915_READ(reg
);
3595 if (HAS_PCH_CPT(dev
)) {
3596 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3597 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3599 temp
&= ~FDI_LINK_TRAIN_NONE
;
3600 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3602 I915_WRITE(reg
, temp
);
3607 for (i
= 0; i
< 4; i
++) {
3608 reg
= FDI_TX_CTL(pipe
);
3609 temp
= I915_READ(reg
);
3610 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3611 temp
|= snb_b_fdi_train_param
[i
];
3612 I915_WRITE(reg
, temp
);
3617 for (retry
= 0; retry
< 5; retry
++) {
3618 reg
= FDI_RX_IIR(pipe
);
3619 temp
= I915_READ(reg
);
3620 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3621 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3622 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3623 DRM_DEBUG_KMS("FDI train 2 done.\n");
3632 DRM_ERROR("FDI train 2 fail!\n");
3634 DRM_DEBUG_KMS("FDI train done.\n");
3637 /* Manual link training for Ivy Bridge A0 parts */
3638 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
3640 struct drm_device
*dev
= crtc
->dev
;
3641 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3642 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3643 int pipe
= intel_crtc
->pipe
;
3644 u32 reg
, temp
, i
, j
;
3646 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3648 reg
= FDI_RX_IMR(pipe
);
3649 temp
= I915_READ(reg
);
3650 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3651 temp
&= ~FDI_RX_BIT_LOCK
;
3652 I915_WRITE(reg
, temp
);
3657 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3658 I915_READ(FDI_RX_IIR(pipe
)));
3660 /* Try each vswing and preemphasis setting twice before moving on */
3661 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
3662 /* disable first in case we need to retry */
3663 reg
= FDI_TX_CTL(pipe
);
3664 temp
= I915_READ(reg
);
3665 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
3666 temp
&= ~FDI_TX_ENABLE
;
3667 I915_WRITE(reg
, temp
);
3669 reg
= FDI_RX_CTL(pipe
);
3670 temp
= I915_READ(reg
);
3671 temp
&= ~FDI_LINK_TRAIN_AUTO
;
3672 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3673 temp
&= ~FDI_RX_ENABLE
;
3674 I915_WRITE(reg
, temp
);
3676 /* enable CPU FDI TX and PCH FDI RX */
3677 reg
= FDI_TX_CTL(pipe
);
3678 temp
= I915_READ(reg
);
3679 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3680 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3681 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
3682 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3683 temp
|= snb_b_fdi_train_param
[j
/2];
3684 temp
|= FDI_COMPOSITE_SYNC
;
3685 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3687 I915_WRITE(FDI_RX_MISC(pipe
),
3688 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3690 reg
= FDI_RX_CTL(pipe
);
3691 temp
= I915_READ(reg
);
3692 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3693 temp
|= FDI_COMPOSITE_SYNC
;
3694 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3697 udelay(1); /* should be 0.5us */
3699 for (i
= 0; i
< 4; i
++) {
3700 reg
= FDI_RX_IIR(pipe
);
3701 temp
= I915_READ(reg
);
3702 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3704 if (temp
& FDI_RX_BIT_LOCK
||
3705 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
3706 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3707 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3711 udelay(1); /* should be 0.5us */
3714 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
3719 reg
= FDI_TX_CTL(pipe
);
3720 temp
= I915_READ(reg
);
3721 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3722 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
3723 I915_WRITE(reg
, temp
);
3725 reg
= FDI_RX_CTL(pipe
);
3726 temp
= I915_READ(reg
);
3727 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3728 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3729 I915_WRITE(reg
, temp
);
3732 udelay(2); /* should be 1.5us */
3734 for (i
= 0; i
< 4; i
++) {
3735 reg
= FDI_RX_IIR(pipe
);
3736 temp
= I915_READ(reg
);
3737 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3739 if (temp
& FDI_RX_SYMBOL_LOCK
||
3740 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
3741 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3742 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
3746 udelay(2); /* should be 1.5us */
3749 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
3753 DRM_DEBUG_KMS("FDI train done.\n");
3756 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
3758 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3759 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3760 int pipe
= intel_crtc
->pipe
;
3764 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
3765 reg
= FDI_RX_CTL(pipe
);
3766 temp
= I915_READ(reg
);
3767 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
3768 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3769 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3770 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
3775 /* Switch from Rawclk to PCDclk */
3776 temp
= I915_READ(reg
);
3777 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
3782 /* Enable CPU FDI TX PLL, always on for Ironlake */
3783 reg
= FDI_TX_CTL(pipe
);
3784 temp
= I915_READ(reg
);
3785 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
3786 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
3793 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
3795 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3796 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3797 int pipe
= intel_crtc
->pipe
;
3800 /* Switch from PCDclk to Rawclk */
3801 reg
= FDI_RX_CTL(pipe
);
3802 temp
= I915_READ(reg
);
3803 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
3805 /* Disable CPU FDI TX PLL */
3806 reg
= FDI_TX_CTL(pipe
);
3807 temp
= I915_READ(reg
);
3808 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
3813 reg
= FDI_RX_CTL(pipe
);
3814 temp
= I915_READ(reg
);
3815 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
3817 /* Wait for the clocks to turn off. */
3822 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
3824 struct drm_device
*dev
= crtc
->dev
;
3825 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3826 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3827 int pipe
= intel_crtc
->pipe
;
3830 /* disable CPU FDI tx and PCH FDI rx */
3831 reg
= FDI_TX_CTL(pipe
);
3832 temp
= I915_READ(reg
);
3833 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
3836 reg
= FDI_RX_CTL(pipe
);
3837 temp
= I915_READ(reg
);
3838 temp
&= ~(0x7 << 16);
3839 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3840 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
3845 /* Ironlake workaround, disable clock pointer after downing FDI */
3846 if (HAS_PCH_IBX(dev
))
3847 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3849 /* still set train pattern 1 */
3850 reg
= FDI_TX_CTL(pipe
);
3851 temp
= I915_READ(reg
);
3852 temp
&= ~FDI_LINK_TRAIN_NONE
;
3853 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3854 I915_WRITE(reg
, temp
);
3856 reg
= FDI_RX_CTL(pipe
);
3857 temp
= I915_READ(reg
);
3858 if (HAS_PCH_CPT(dev
)) {
3859 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3860 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3862 temp
&= ~FDI_LINK_TRAIN_NONE
;
3863 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3865 /* BPC in FDI rx is consistent with that in PIPECONF */
3866 temp
&= ~(0x07 << 16);
3867 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3868 I915_WRITE(reg
, temp
);
3874 bool intel_has_pending_fb_unpin(struct drm_device
*dev
)
3876 struct intel_crtc
*crtc
;
3878 /* Note that we don't need to be called with mode_config.lock here
3879 * as our list of CRTC objects is static for the lifetime of the
3880 * device and so cannot disappear as we iterate. Similarly, we can
3881 * happily treat the predicates as racy, atomic checks as userspace
3882 * cannot claim and pin a new fb without at least acquring the
3883 * struct_mutex and so serialising with us.
3885 for_each_intel_crtc(dev
, crtc
) {
3886 if (atomic_read(&crtc
->unpin_work_count
) == 0)
3889 if (crtc
->unpin_work
)
3890 intel_wait_for_vblank(dev
, crtc
->pipe
);
3898 static void page_flip_completed(struct intel_crtc
*intel_crtc
)
3900 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
3901 struct intel_unpin_work
*work
= intel_crtc
->unpin_work
;
3903 /* ensure that the unpin work is consistent wrt ->pending. */
3905 intel_crtc
->unpin_work
= NULL
;
3908 drm_send_vblank_event(intel_crtc
->base
.dev
,
3912 drm_crtc_vblank_put(&intel_crtc
->base
);
3914 wake_up_all(&dev_priv
->pending_flip_queue
);
3915 queue_work(dev_priv
->wq
, &work
->work
);
3917 trace_i915_flip_complete(intel_crtc
->plane
,
3918 work
->pending_flip_obj
);
3921 void intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
3923 struct drm_device
*dev
= crtc
->dev
;
3924 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3926 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
3927 if (WARN_ON(wait_event_timeout(dev_priv
->pending_flip_queue
,
3928 !intel_crtc_has_pending_flip(crtc
),
3930 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3932 spin_lock_irq(&dev
->event_lock
);
3933 if (intel_crtc
->unpin_work
) {
3934 WARN_ONCE(1, "Removing stuck page flip\n");
3935 page_flip_completed(intel_crtc
);
3937 spin_unlock_irq(&dev
->event_lock
);
3940 if (crtc
->primary
->fb
) {
3941 mutex_lock(&dev
->struct_mutex
);
3942 intel_finish_fb(crtc
->primary
->fb
);
3943 mutex_unlock(&dev
->struct_mutex
);
3947 /* Program iCLKIP clock to the desired frequency */
3948 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
3950 struct drm_device
*dev
= crtc
->dev
;
3951 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3952 int clock
= to_intel_crtc(crtc
)->config
->base
.adjusted_mode
.crtc_clock
;
3953 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
3956 mutex_lock(&dev_priv
->dpio_lock
);
3958 /* It is necessary to ungate the pixclk gate prior to programming
3959 * the divisors, and gate it back when it is done.
3961 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
3963 /* Disable SSCCTL */
3964 intel_sbi_write(dev_priv
, SBI_SSCCTL6
,
3965 intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
) |
3969 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
3970 if (clock
== 20000) {
3975 /* The iCLK virtual clock root frequency is in MHz,
3976 * but the adjusted_mode->crtc_clock in in KHz. To get the
3977 * divisors, it is necessary to divide one by another, so we
3978 * convert the virtual clock precision to KHz here for higher
3981 u32 iclk_virtual_root_freq
= 172800 * 1000;
3982 u32 iclk_pi_range
= 64;
3983 u32 desired_divisor
, msb_divisor_value
, pi_value
;
3985 desired_divisor
= (iclk_virtual_root_freq
/ clock
);
3986 msb_divisor_value
= desired_divisor
/ iclk_pi_range
;
3987 pi_value
= desired_divisor
% iclk_pi_range
;
3990 divsel
= msb_divisor_value
- 2;
3991 phaseinc
= pi_value
;
3994 /* This should not happen with any sane values */
3995 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
3996 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
3997 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
3998 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
4000 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4007 /* Program SSCDIVINTPHASE6 */
4008 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
4009 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
4010 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
4011 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
4012 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
4013 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
4014 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
4015 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
4017 /* Program SSCAUXDIV */
4018 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
4019 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4020 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
4021 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
4023 /* Enable modulator and associated divider */
4024 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4025 temp
&= ~SBI_SSCCTL_DISABLE
;
4026 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
4028 /* Wait for initialization time */
4031 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
4033 mutex_unlock(&dev_priv
->dpio_lock
);
4036 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
4037 enum pipe pch_transcoder
)
4039 struct drm_device
*dev
= crtc
->base
.dev
;
4040 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4041 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
4043 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
4044 I915_READ(HTOTAL(cpu_transcoder
)));
4045 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
4046 I915_READ(HBLANK(cpu_transcoder
)));
4047 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
4048 I915_READ(HSYNC(cpu_transcoder
)));
4050 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
4051 I915_READ(VTOTAL(cpu_transcoder
)));
4052 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
4053 I915_READ(VBLANK(cpu_transcoder
)));
4054 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
4055 I915_READ(VSYNC(cpu_transcoder
)));
4056 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
4057 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
4060 static void cpt_set_fdi_bc_bifurcation(struct drm_device
*dev
, bool enable
)
4062 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4065 temp
= I915_READ(SOUTH_CHICKEN1
);
4066 if (!!(temp
& FDI_BC_BIFURCATION_SELECT
) == enable
)
4069 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
4070 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
4072 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
4074 temp
|= FDI_BC_BIFURCATION_SELECT
;
4076 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable
? "en" : "dis");
4077 I915_WRITE(SOUTH_CHICKEN1
, temp
);
4078 POSTING_READ(SOUTH_CHICKEN1
);
4081 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
4083 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4085 switch (intel_crtc
->pipe
) {
4089 if (intel_crtc
->config
->fdi_lanes
> 2)
4090 cpt_set_fdi_bc_bifurcation(dev
, false);
4092 cpt_set_fdi_bc_bifurcation(dev
, true);
4096 cpt_set_fdi_bc_bifurcation(dev
, true);
4105 * Enable PCH resources required for PCH ports:
4107 * - FDI training & RX/TX
4108 * - update transcoder timings
4109 * - DP transcoding bits
4112 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
4114 struct drm_device
*dev
= crtc
->dev
;
4115 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4116 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4117 int pipe
= intel_crtc
->pipe
;
4120 assert_pch_transcoder_disabled(dev_priv
, pipe
);
4122 if (IS_IVYBRIDGE(dev
))
4123 ivybridge_update_fdi_bc_bifurcation(intel_crtc
);
4125 /* Write the TU size bits before fdi link training, so that error
4126 * detection works. */
4127 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
4128 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
4130 /* For PCH output, training FDI link */
4131 dev_priv
->display
.fdi_link_train(crtc
);
4133 /* We need to program the right clock selection before writing the pixel
4134 * mutliplier into the DPLL. */
4135 if (HAS_PCH_CPT(dev
)) {
4138 temp
= I915_READ(PCH_DPLL_SEL
);
4139 temp
|= TRANS_DPLL_ENABLE(pipe
);
4140 sel
= TRANS_DPLLB_SEL(pipe
);
4141 if (intel_crtc
->config
->shared_dpll
== DPLL_ID_PCH_PLL_B
)
4145 I915_WRITE(PCH_DPLL_SEL
, temp
);
4148 /* XXX: pch pll's can be enabled any time before we enable the PCH
4149 * transcoder, and we actually should do this to not upset any PCH
4150 * transcoder that already use the clock when we share it.
4152 * Note that enable_shared_dpll tries to do the right thing, but
4153 * get_shared_dpll unconditionally resets the pll - we need that to have
4154 * the right LVDS enable sequence. */
4155 intel_enable_shared_dpll(intel_crtc
);
4157 /* set transcoder timing, panel must allow it */
4158 assert_panel_unlocked(dev_priv
, pipe
);
4159 ironlake_pch_transcoder_set_timings(intel_crtc
, pipe
);
4161 intel_fdi_normal_train(crtc
);
4163 /* For PCH DP, enable TRANS_DP_CTL */
4164 if (HAS_PCH_CPT(dev
) && intel_crtc
->config
->has_dp_encoder
) {
4165 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
4166 reg
= TRANS_DP_CTL(pipe
);
4167 temp
= I915_READ(reg
);
4168 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
4169 TRANS_DP_SYNC_MASK
|
4171 temp
|= TRANS_DP_OUTPUT_ENABLE
;
4172 temp
|= bpc
<< 9; /* same format but at 11:9 */
4174 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PHSYNC
)
4175 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
4176 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PVSYNC
)
4177 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
4179 switch (intel_trans_dp_port_sel(crtc
)) {
4181 temp
|= TRANS_DP_PORT_SEL_B
;
4184 temp
|= TRANS_DP_PORT_SEL_C
;
4187 temp
|= TRANS_DP_PORT_SEL_D
;
4193 I915_WRITE(reg
, temp
);
4196 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
4199 static void lpt_pch_enable(struct drm_crtc
*crtc
)
4201 struct drm_device
*dev
= crtc
->dev
;
4202 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4203 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4204 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
4206 assert_pch_transcoder_disabled(dev_priv
, TRANSCODER_A
);
4208 lpt_program_iclkip(crtc
);
4210 /* Set transcoder timing. */
4211 ironlake_pch_transcoder_set_timings(intel_crtc
, PIPE_A
);
4213 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
4216 void intel_put_shared_dpll(struct intel_crtc
*crtc
)
4218 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
4223 if (!(pll
->config
.crtc_mask
& (1 << crtc
->pipe
))) {
4224 WARN(1, "bad %s crtc mask\n", pll
->name
);
4228 pll
->config
.crtc_mask
&= ~(1 << crtc
->pipe
);
4229 if (pll
->config
.crtc_mask
== 0) {
4231 WARN_ON(pll
->active
);
4234 crtc
->config
->shared_dpll
= DPLL_ID_PRIVATE
;
4237 struct intel_shared_dpll
*intel_get_shared_dpll(struct intel_crtc
*crtc
,
4238 struct intel_crtc_state
*crtc_state
)
4240 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
4241 struct intel_shared_dpll
*pll
;
4242 enum intel_dpll_id i
;
4244 if (HAS_PCH_IBX(dev_priv
->dev
)) {
4245 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
4246 i
= (enum intel_dpll_id
) crtc
->pipe
;
4247 pll
= &dev_priv
->shared_dplls
[i
];
4249 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
4250 crtc
->base
.base
.id
, pll
->name
);
4252 WARN_ON(pll
->new_config
->crtc_mask
);
4257 if (IS_BROXTON(dev_priv
->dev
)) {
4258 /* PLL is attached to port in bxt */
4259 struct intel_encoder
*encoder
;
4260 struct intel_digital_port
*intel_dig_port
;
4262 encoder
= intel_ddi_get_crtc_new_encoder(crtc_state
);
4263 if (WARN_ON(!encoder
))
4266 intel_dig_port
= enc_to_dig_port(&encoder
->base
);
4267 /* 1:1 mapping between ports and PLLs */
4268 i
= (enum intel_dpll_id
)intel_dig_port
->port
;
4269 pll
= &dev_priv
->shared_dplls
[i
];
4270 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
4271 crtc
->base
.base
.id
, pll
->name
);
4272 WARN_ON(pll
->new_config
->crtc_mask
);
4277 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4278 pll
= &dev_priv
->shared_dplls
[i
];
4280 /* Only want to check enabled timings first */
4281 if (pll
->new_config
->crtc_mask
== 0)
4284 if (memcmp(&crtc_state
->dpll_hw_state
,
4285 &pll
->new_config
->hw_state
,
4286 sizeof(pll
->new_config
->hw_state
)) == 0) {
4287 DRM_DEBUG_KMS("CRTC:%d sharing existing %s (crtc mask 0x%08x, ative %d)\n",
4288 crtc
->base
.base
.id
, pll
->name
,
4289 pll
->new_config
->crtc_mask
,
4295 /* Ok no matching timings, maybe there's a free one? */
4296 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4297 pll
= &dev_priv
->shared_dplls
[i
];
4298 if (pll
->new_config
->crtc_mask
== 0) {
4299 DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
4300 crtc
->base
.base
.id
, pll
->name
);
4308 if (pll
->new_config
->crtc_mask
== 0)
4309 pll
->new_config
->hw_state
= crtc_state
->dpll_hw_state
;
4311 crtc_state
->shared_dpll
= i
;
4312 DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll
->name
,
4313 pipe_name(crtc
->pipe
));
4315 pll
->new_config
->crtc_mask
|= 1 << crtc
->pipe
;
4321 * intel_shared_dpll_start_config - start a new PLL staged config
4322 * @dev_priv: DRM device
4323 * @clear_pipes: mask of pipes that will have their PLLs freed
4325 * Starts a new PLL staged config, copying the current config but
4326 * releasing the references of pipes specified in clear_pipes.
4328 static int intel_shared_dpll_start_config(struct drm_i915_private
*dev_priv
,
4329 unsigned clear_pipes
)
4331 struct intel_shared_dpll
*pll
;
4332 enum intel_dpll_id i
;
4334 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4335 pll
= &dev_priv
->shared_dplls
[i
];
4337 pll
->new_config
= kmemdup(&pll
->config
, sizeof pll
->config
,
4339 if (!pll
->new_config
)
4342 pll
->new_config
->crtc_mask
&= ~clear_pipes
;
4349 pll
= &dev_priv
->shared_dplls
[i
];
4350 kfree(pll
->new_config
);
4351 pll
->new_config
= NULL
;
4357 static void intel_shared_dpll_commit(struct drm_i915_private
*dev_priv
)
4359 struct intel_shared_dpll
*pll
;
4360 enum intel_dpll_id i
;
4362 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4363 pll
= &dev_priv
->shared_dplls
[i
];
4365 WARN_ON(pll
->new_config
== &pll
->config
);
4367 pll
->config
= *pll
->new_config
;
4368 kfree(pll
->new_config
);
4369 pll
->new_config
= NULL
;
4373 static void intel_shared_dpll_abort_config(struct drm_i915_private
*dev_priv
)
4375 struct intel_shared_dpll
*pll
;
4376 enum intel_dpll_id i
;
4378 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4379 pll
= &dev_priv
->shared_dplls
[i
];
4381 WARN_ON(pll
->new_config
== &pll
->config
);
4383 kfree(pll
->new_config
);
4384 pll
->new_config
= NULL
;
4388 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
4390 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4391 int dslreg
= PIPEDSL(pipe
);
4394 temp
= I915_READ(dslreg
);
4396 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
4397 if (wait_for(I915_READ(dslreg
) != temp
, 5))
4398 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
4403 * skl_update_scaler_users - Stages update to crtc's scaler state
4405 * @crtc_state: crtc_state
4406 * @plane: plane (NULL indicates crtc is requesting update)
4407 * @plane_state: plane's state
4408 * @force_detach: request unconditional detachment of scaler
4410 * This function updates scaler state for requested plane or crtc.
4411 * To request scaler usage update for a plane, caller shall pass plane pointer.
4412 * To request scaler usage update for crtc, caller shall pass plane pointer
4416 * 0 - scaler_usage updated successfully
4417 * error - requested scaling cannot be supported or other error condition
4420 skl_update_scaler_users(
4421 struct intel_crtc
*intel_crtc
, struct intel_crtc_state
*crtc_state
,
4422 struct intel_plane
*intel_plane
, struct intel_plane_state
*plane_state
,
4427 int src_w
, src_h
, dst_w
, dst_h
;
4429 struct drm_framebuffer
*fb
;
4430 struct intel_crtc_scaler_state
*scaler_state
;
4431 unsigned int rotation
;
4433 if (!intel_crtc
|| !crtc_state
)
4436 scaler_state
= &crtc_state
->scaler_state
;
4438 idx
= intel_plane
? drm_plane_index(&intel_plane
->base
) : SKL_CRTC_INDEX
;
4439 fb
= intel_plane
? plane_state
->base
.fb
: NULL
;
4442 src_w
= drm_rect_width(&plane_state
->src
) >> 16;
4443 src_h
= drm_rect_height(&plane_state
->src
) >> 16;
4444 dst_w
= drm_rect_width(&plane_state
->dst
);
4445 dst_h
= drm_rect_height(&plane_state
->dst
);
4446 scaler_id
= &plane_state
->scaler_id
;
4447 rotation
= plane_state
->base
.rotation
;
4449 struct drm_display_mode
*adjusted_mode
=
4450 &crtc_state
->base
.adjusted_mode
;
4451 src_w
= crtc_state
->pipe_src_w
;
4452 src_h
= crtc_state
->pipe_src_h
;
4453 dst_w
= adjusted_mode
->hdisplay
;
4454 dst_h
= adjusted_mode
->vdisplay
;
4455 scaler_id
= &scaler_state
->scaler_id
;
4456 rotation
= DRM_ROTATE_0
;
4459 need_scaling
= intel_rotation_90_or_270(rotation
) ?
4460 (src_h
!= dst_w
|| src_w
!= dst_h
):
4461 (src_w
!= dst_w
|| src_h
!= dst_h
);
4464 * if plane is being disabled or scaler is no more required or force detach
4465 * - free scaler binded to this plane/crtc
4466 * - in order to do this, update crtc->scaler_usage
4468 * Here scaler state in crtc_state is set free so that
4469 * scaler can be assigned to other user. Actual register
4470 * update to free the scaler is done in plane/panel-fit programming.
4471 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4473 if (force_detach
|| !need_scaling
|| (intel_plane
&&
4474 (!fb
|| !plane_state
->visible
))) {
4475 if (*scaler_id
>= 0) {
4476 scaler_state
->scaler_users
&= ~(1 << idx
);
4477 scaler_state
->scalers
[*scaler_id
].in_use
= 0;
4479 DRM_DEBUG_KMS("Staged freeing scaler id %d.%d from %s:%d "
4480 "crtc_state = %p scaler_users = 0x%x\n",
4481 intel_crtc
->pipe
, *scaler_id
, intel_plane
? "PLANE" : "CRTC",
4482 intel_plane
? intel_plane
->base
.base
.id
:
4483 intel_crtc
->base
.base
.id
, crtc_state
,
4484 scaler_state
->scaler_users
);
4491 if (src_w
< SKL_MIN_SRC_W
|| src_h
< SKL_MIN_SRC_H
||
4492 dst_w
< SKL_MIN_DST_W
|| dst_h
< SKL_MIN_DST_H
||
4494 src_w
> SKL_MAX_SRC_W
|| src_h
> SKL_MAX_SRC_H
||
4495 dst_w
> SKL_MAX_DST_W
|| dst_h
> SKL_MAX_DST_H
) {
4496 DRM_DEBUG_KMS("%s:%d scaler_user index %u.%u: src %ux%u dst %ux%u "
4497 "size is out of scaler range\n",
4498 intel_plane
? "PLANE" : "CRTC",
4499 intel_plane
? intel_plane
->base
.base
.id
: intel_crtc
->base
.base
.id
,
4500 intel_crtc
->pipe
, idx
, src_w
, src_h
, dst_w
, dst_h
);
4504 /* check colorkey */
4505 if (WARN_ON(intel_plane
&&
4506 intel_plane
->ckey
.flags
!= I915_SET_COLORKEY_NONE
)) {
4507 DRM_DEBUG_KMS("PLANE:%d scaling %ux%u->%ux%u not allowed with colorkey",
4508 intel_plane
->base
.base
.id
, src_w
, src_h
, dst_w
, dst_h
);
4512 /* Check src format */
4514 switch (fb
->pixel_format
) {
4515 case DRM_FORMAT_RGB565
:
4516 case DRM_FORMAT_XBGR8888
:
4517 case DRM_FORMAT_XRGB8888
:
4518 case DRM_FORMAT_ABGR8888
:
4519 case DRM_FORMAT_ARGB8888
:
4520 case DRM_FORMAT_XRGB2101010
:
4521 case DRM_FORMAT_XBGR2101010
:
4522 case DRM_FORMAT_YUYV
:
4523 case DRM_FORMAT_YVYU
:
4524 case DRM_FORMAT_UYVY
:
4525 case DRM_FORMAT_VYUY
:
4528 DRM_DEBUG_KMS("PLANE:%d FB:%d unsupported scaling format 0x%x\n",
4529 intel_plane
->base
.base
.id
, fb
->base
.id
, fb
->pixel_format
);
4534 /* mark this plane as a scaler user in crtc_state */
4535 scaler_state
->scaler_users
|= (1 << idx
);
4536 DRM_DEBUG_KMS("%s:%d staged scaling request for %ux%u->%ux%u "
4537 "crtc_state = %p scaler_users = 0x%x\n",
4538 intel_plane
? "PLANE" : "CRTC",
4539 intel_plane
? intel_plane
->base
.base
.id
: intel_crtc
->base
.base
.id
,
4540 src_w
, src_h
, dst_w
, dst_h
, crtc_state
, scaler_state
->scaler_users
);
4544 static void skylake_pfit_update(struct intel_crtc
*crtc
, int enable
)
4546 struct drm_device
*dev
= crtc
->base
.dev
;
4547 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4548 int pipe
= crtc
->pipe
;
4549 struct intel_crtc_scaler_state
*scaler_state
=
4550 &crtc
->config
->scaler_state
;
4552 DRM_DEBUG_KMS("for crtc_state = %p\n", crtc
->config
);
4554 /* To update pfit, first update scaler state */
4555 skl_update_scaler_users(crtc
, crtc
->config
, NULL
, NULL
, !enable
);
4556 intel_atomic_setup_scalers(crtc
->base
.dev
, crtc
, crtc
->config
);
4557 skl_detach_scalers(crtc
);
4561 if (crtc
->config
->pch_pfit
.enabled
) {
4564 if (WARN_ON(crtc
->config
->scaler_state
.scaler_id
< 0)) {
4565 DRM_ERROR("Requesting pfit without getting a scaler first\n");
4569 id
= scaler_state
->scaler_id
;
4570 I915_WRITE(SKL_PS_CTRL(pipe
, id
), PS_SCALER_EN
|
4571 PS_FILTER_MEDIUM
| scaler_state
->scalers
[id
].mode
);
4572 I915_WRITE(SKL_PS_WIN_POS(pipe
, id
), crtc
->config
->pch_pfit
.pos
);
4573 I915_WRITE(SKL_PS_WIN_SZ(pipe
, id
), crtc
->config
->pch_pfit
.size
);
4575 DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc
->config
, id
);
4579 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
4581 struct drm_device
*dev
= crtc
->base
.dev
;
4582 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4583 int pipe
= crtc
->pipe
;
4585 if (crtc
->config
->pch_pfit
.enabled
) {
4586 /* Force use of hard-coded filter coefficients
4587 * as some pre-programmed values are broken,
4590 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
))
4591 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
4592 PF_PIPE_SEL_IVB(pipe
));
4594 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
4595 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
->pch_pfit
.pos
);
4596 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
->pch_pfit
.size
);
4600 static void intel_enable_sprite_planes(struct drm_crtc
*crtc
)
4602 struct drm_device
*dev
= crtc
->dev
;
4603 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
4604 struct drm_plane
*plane
;
4605 struct intel_plane
*intel_plane
;
4607 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
4608 intel_plane
= to_intel_plane(plane
);
4609 if (intel_plane
->pipe
== pipe
)
4610 intel_plane_restore(&intel_plane
->base
);
4614 void hsw_enable_ips(struct intel_crtc
*crtc
)
4616 struct drm_device
*dev
= crtc
->base
.dev
;
4617 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4619 if (!crtc
->config
->ips_enabled
)
4622 /* We can only enable IPS after we enable a plane and wait for a vblank */
4623 intel_wait_for_vblank(dev
, crtc
->pipe
);
4625 assert_plane_enabled(dev_priv
, crtc
->plane
);
4626 if (IS_BROADWELL(dev
)) {
4627 mutex_lock(&dev_priv
->rps
.hw_lock
);
4628 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
4629 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4630 /* Quoting Art Runyan: "its not safe to expect any particular
4631 * value in IPS_CTL bit 31 after enabling IPS through the
4632 * mailbox." Moreover, the mailbox may return a bogus state,
4633 * so we need to just enable it and continue on.
4636 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
4637 /* The bit only becomes 1 in the next vblank, so this wait here
4638 * is essentially intel_wait_for_vblank. If we don't have this
4639 * and don't wait for vblanks until the end of crtc_enable, then
4640 * the HW state readout code will complain that the expected
4641 * IPS_CTL value is not the one we read. */
4642 if (wait_for(I915_READ_NOTRACE(IPS_CTL
) & IPS_ENABLE
, 50))
4643 DRM_ERROR("Timed out waiting for IPS enable\n");
4647 void hsw_disable_ips(struct intel_crtc
*crtc
)
4649 struct drm_device
*dev
= crtc
->base
.dev
;
4650 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4652 if (!crtc
->config
->ips_enabled
)
4655 assert_plane_enabled(dev_priv
, crtc
->plane
);
4656 if (IS_BROADWELL(dev
)) {
4657 mutex_lock(&dev_priv
->rps
.hw_lock
);
4658 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
4659 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4660 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4661 if (wait_for((I915_READ(IPS_CTL
) & IPS_ENABLE
) == 0, 42))
4662 DRM_ERROR("Timed out waiting for IPS disable\n");
4664 I915_WRITE(IPS_CTL
, 0);
4665 POSTING_READ(IPS_CTL
);
4668 /* We need to wait for a vblank before we can disable the plane. */
4669 intel_wait_for_vblank(dev
, crtc
->pipe
);
4672 /** Loads the palette/gamma unit for the CRTC with the prepared values */
4673 static void intel_crtc_load_lut(struct drm_crtc
*crtc
)
4675 struct drm_device
*dev
= crtc
->dev
;
4676 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4677 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4678 enum pipe pipe
= intel_crtc
->pipe
;
4679 int palreg
= PALETTE(pipe
);
4681 bool reenable_ips
= false;
4683 /* The clocks have to be on to load the palette. */
4684 if (!crtc
->state
->enable
|| !intel_crtc
->active
)
4687 if (HAS_GMCH_DISPLAY(dev_priv
->dev
)) {
4688 if (intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_DSI
))
4689 assert_dsi_pll_enabled(dev_priv
);
4691 assert_pll_enabled(dev_priv
, pipe
);
4694 /* use legacy palette for Ironlake */
4695 if (!HAS_GMCH_DISPLAY(dev
))
4696 palreg
= LGC_PALETTE(pipe
);
4698 /* Workaround : Do not read or write the pipe palette/gamma data while
4699 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
4701 if (IS_HASWELL(dev
) && intel_crtc
->config
->ips_enabled
&&
4702 ((I915_READ(GAMMA_MODE(pipe
)) & GAMMA_MODE_MODE_MASK
) ==
4703 GAMMA_MODE_MODE_SPLIT
)) {
4704 hsw_disable_ips(intel_crtc
);
4705 reenable_ips
= true;
4708 for (i
= 0; i
< 256; i
++) {
4709 I915_WRITE(palreg
+ 4 * i
,
4710 (intel_crtc
->lut_r
[i
] << 16) |
4711 (intel_crtc
->lut_g
[i
] << 8) |
4712 intel_crtc
->lut_b
[i
]);
4716 hsw_enable_ips(intel_crtc
);
4719 static void intel_crtc_dpms_overlay_disable(struct intel_crtc
*intel_crtc
)
4721 if (intel_crtc
->overlay
) {
4722 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4723 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4725 mutex_lock(&dev
->struct_mutex
);
4726 dev_priv
->mm
.interruptible
= false;
4727 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
4728 dev_priv
->mm
.interruptible
= true;
4729 mutex_unlock(&dev
->struct_mutex
);
4732 /* Let userspace switch the overlay on again. In most cases userspace
4733 * has to recompute where to put it anyway.
4738 * intel_post_enable_primary - Perform operations after enabling primary plane
4739 * @crtc: the CRTC whose primary plane was just enabled
4741 * Performs potentially sleeping operations that must be done after the primary
4742 * plane is enabled, such as updating FBC and IPS. Note that this may be
4743 * called due to an explicit primary plane update, or due to an implicit
4744 * re-enable that is caused when a sprite plane is updated to no longer
4745 * completely hide the primary plane.
4748 intel_post_enable_primary(struct drm_crtc
*crtc
)
4750 struct drm_device
*dev
= crtc
->dev
;
4751 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4752 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4753 int pipe
= intel_crtc
->pipe
;
4756 * BDW signals flip done immediately if the plane
4757 * is disabled, even if the plane enable is already
4758 * armed to occur at the next vblank :(
4760 if (IS_BROADWELL(dev
))
4761 intel_wait_for_vblank(dev
, pipe
);
4764 * FIXME IPS should be fine as long as one plane is
4765 * enabled, but in practice it seems to have problems
4766 * when going from primary only to sprite only and vice
4769 hsw_enable_ips(intel_crtc
);
4771 mutex_lock(&dev
->struct_mutex
);
4772 intel_fbc_update(dev
);
4773 mutex_unlock(&dev
->struct_mutex
);
4776 * Gen2 reports pipe underruns whenever all planes are disabled.
4777 * So don't enable underrun reporting before at least some planes
4779 * FIXME: Need to fix the logic to work when we turn off all planes
4780 * but leave the pipe running.
4783 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4785 /* Underruns don't raise interrupts, so check manually. */
4786 if (HAS_GMCH_DISPLAY(dev
))
4787 i9xx_check_fifo_underruns(dev_priv
);
4791 * intel_pre_disable_primary - Perform operations before disabling primary plane
4792 * @crtc: the CRTC whose primary plane is to be disabled
4794 * Performs potentially sleeping operations that must be done before the
4795 * primary plane is disabled, such as updating FBC and IPS. Note that this may
4796 * be called due to an explicit primary plane update, or due to an implicit
4797 * disable that is caused when a sprite plane completely hides the primary
4801 intel_pre_disable_primary(struct drm_crtc
*crtc
)
4803 struct drm_device
*dev
= crtc
->dev
;
4804 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4805 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4806 int pipe
= intel_crtc
->pipe
;
4809 * Gen2 reports pipe underruns whenever all planes are disabled.
4810 * So diasble underrun reporting before all the planes get disabled.
4811 * FIXME: Need to fix the logic to work when we turn off all planes
4812 * but leave the pipe running.
4815 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4818 * Vblank time updates from the shadow to live plane control register
4819 * are blocked if the memory self-refresh mode is active at that
4820 * moment. So to make sure the plane gets truly disabled, disable
4821 * first the self-refresh mode. The self-refresh enable bit in turn
4822 * will be checked/applied by the HW only at the next frame start
4823 * event which is after the vblank start event, so we need to have a
4824 * wait-for-vblank between disabling the plane and the pipe.
4826 if (HAS_GMCH_DISPLAY(dev
))
4827 intel_set_memory_cxsr(dev_priv
, false);
4829 mutex_lock(&dev
->struct_mutex
);
4830 if (dev_priv
->fbc
.crtc
== intel_crtc
)
4831 intel_fbc_disable(dev
);
4832 mutex_unlock(&dev
->struct_mutex
);
4835 * FIXME IPS should be fine as long as one plane is
4836 * enabled, but in practice it seems to have problems
4837 * when going from primary only to sprite only and vice
4840 hsw_disable_ips(intel_crtc
);
4843 static void intel_crtc_enable_planes(struct drm_crtc
*crtc
)
4845 intel_enable_primary_hw_plane(crtc
->primary
, crtc
);
4846 intel_enable_sprite_planes(crtc
);
4847 intel_crtc_update_cursor(crtc
, true);
4849 intel_post_enable_primary(crtc
);
4852 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
)
4854 struct drm_device
*dev
= crtc
->dev
;
4855 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4856 struct intel_plane
*intel_plane
;
4857 int pipe
= intel_crtc
->pipe
;
4859 intel_crtc_wait_for_pending_flips(crtc
);
4861 intel_pre_disable_primary(crtc
);
4863 intel_crtc_dpms_overlay_disable(intel_crtc
);
4864 for_each_intel_plane(dev
, intel_plane
) {
4865 if (intel_plane
->pipe
== pipe
) {
4866 struct drm_crtc
*from
= intel_plane
->base
.crtc
;
4868 intel_plane
->disable_plane(&intel_plane
->base
,
4869 from
?: crtc
, true);
4874 * FIXME: Once we grow proper nuclear flip support out of this we need
4875 * to compute the mask of flip planes precisely. For the time being
4876 * consider this a flip to a NULL plane.
4878 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_ALL_MASK(pipe
));
4881 static void ironlake_crtc_enable(struct drm_crtc
*crtc
)
4883 struct drm_device
*dev
= crtc
->dev
;
4884 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4885 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4886 struct intel_encoder
*encoder
;
4887 int pipe
= intel_crtc
->pipe
;
4889 WARN_ON(!crtc
->state
->enable
);
4891 if (intel_crtc
->active
)
4894 if (intel_crtc
->config
->has_pch_encoder
)
4895 intel_prepare_shared_dpll(intel_crtc
);
4897 if (intel_crtc
->config
->has_dp_encoder
)
4898 intel_dp_set_m_n(intel_crtc
, M1_N1
);
4900 intel_set_pipe_timings(intel_crtc
);
4902 if (intel_crtc
->config
->has_pch_encoder
) {
4903 intel_cpu_transcoder_set_m_n(intel_crtc
,
4904 &intel_crtc
->config
->fdi_m_n
, NULL
);
4907 ironlake_set_pipeconf(crtc
);
4909 intel_crtc
->active
= true;
4911 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4912 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
4914 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4915 if (encoder
->pre_enable
)
4916 encoder
->pre_enable(encoder
);
4918 if (intel_crtc
->config
->has_pch_encoder
) {
4919 /* Note: FDI PLL enabling _must_ be done before we enable the
4920 * cpu pipes, hence this is separate from all the other fdi/pch
4922 ironlake_fdi_pll_enable(intel_crtc
);
4924 assert_fdi_tx_disabled(dev_priv
, pipe
);
4925 assert_fdi_rx_disabled(dev_priv
, pipe
);
4928 ironlake_pfit_enable(intel_crtc
);
4931 * On ILK+ LUT must be loaded before the pipe is running but with
4934 intel_crtc_load_lut(crtc
);
4936 intel_update_watermarks(crtc
);
4937 intel_enable_pipe(intel_crtc
);
4939 if (intel_crtc
->config
->has_pch_encoder
)
4940 ironlake_pch_enable(crtc
);
4942 assert_vblank_disabled(crtc
);
4943 drm_crtc_vblank_on(crtc
);
4945 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4946 encoder
->enable(encoder
);
4948 if (HAS_PCH_CPT(dev
))
4949 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
4952 /* IPS only exists on ULT machines and is tied to pipe A. */
4953 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
4955 return HAS_IPS(crtc
->base
.dev
) && crtc
->pipe
== PIPE_A
;
4959 * This implements the workaround described in the "notes" section of the mode
4960 * set sequence documentation. When going from no pipes or single pipe to
4961 * multiple pipes, and planes are enabled after the pipe, we need to wait at
4962 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
4964 static void haswell_mode_set_planes_workaround(struct intel_crtc
*crtc
)
4966 struct drm_device
*dev
= crtc
->base
.dev
;
4967 struct intel_crtc
*crtc_it
, *other_active_crtc
= NULL
;
4969 /* We want to get the other_active_crtc only if there's only 1 other
4971 for_each_intel_crtc(dev
, crtc_it
) {
4972 if (!crtc_it
->active
|| crtc_it
== crtc
)
4975 if (other_active_crtc
)
4978 other_active_crtc
= crtc_it
;
4980 if (!other_active_crtc
)
4983 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4984 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4987 static void haswell_crtc_enable(struct drm_crtc
*crtc
)
4989 struct drm_device
*dev
= crtc
->dev
;
4990 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4991 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4992 struct intel_encoder
*encoder
;
4993 int pipe
= intel_crtc
->pipe
;
4995 WARN_ON(!crtc
->state
->enable
);
4997 if (intel_crtc
->active
)
5000 if (intel_crtc_to_shared_dpll(intel_crtc
))
5001 intel_enable_shared_dpll(intel_crtc
);
5003 if (intel_crtc
->config
->has_dp_encoder
)
5004 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5006 intel_set_pipe_timings(intel_crtc
);
5008 if (intel_crtc
->config
->cpu_transcoder
!= TRANSCODER_EDP
) {
5009 I915_WRITE(PIPE_MULT(intel_crtc
->config
->cpu_transcoder
),
5010 intel_crtc
->config
->pixel_multiplier
- 1);
5013 if (intel_crtc
->config
->has_pch_encoder
) {
5014 intel_cpu_transcoder_set_m_n(intel_crtc
,
5015 &intel_crtc
->config
->fdi_m_n
, NULL
);
5018 haswell_set_pipeconf(crtc
);
5020 intel_set_pipe_csc(crtc
);
5022 intel_crtc
->active
= true;
5024 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5025 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5026 if (encoder
->pre_enable
)
5027 encoder
->pre_enable(encoder
);
5029 if (intel_crtc
->config
->has_pch_encoder
) {
5030 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5032 dev_priv
->display
.fdi_link_train(crtc
);
5035 intel_ddi_enable_pipe_clock(intel_crtc
);
5037 if (INTEL_INFO(dev
)->gen
== 9)
5038 skylake_pfit_update(intel_crtc
, 1);
5039 else if (INTEL_INFO(dev
)->gen
< 9)
5040 ironlake_pfit_enable(intel_crtc
);
5042 MISSING_CASE(INTEL_INFO(dev
)->gen
);
5045 * On ILK+ LUT must be loaded before the pipe is running but with
5048 intel_crtc_load_lut(crtc
);
5050 intel_ddi_set_pipe_settings(crtc
);
5051 intel_ddi_enable_transcoder_func(crtc
);
5053 intel_update_watermarks(crtc
);
5054 intel_enable_pipe(intel_crtc
);
5056 if (intel_crtc
->config
->has_pch_encoder
)
5057 lpt_pch_enable(crtc
);
5059 if (intel_crtc
->config
->dp_encoder_is_mst
)
5060 intel_ddi_set_vc_payload_alloc(crtc
, true);
5062 assert_vblank_disabled(crtc
);
5063 drm_crtc_vblank_on(crtc
);
5065 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5066 encoder
->enable(encoder
);
5067 intel_opregion_notify_encoder(encoder
, true);
5070 /* If we change the relative order between pipe/planes enabling, we need
5071 * to change the workaround. */
5072 haswell_mode_set_planes_workaround(intel_crtc
);
5075 static void ironlake_pfit_disable(struct intel_crtc
*crtc
)
5077 struct drm_device
*dev
= crtc
->base
.dev
;
5078 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5079 int pipe
= crtc
->pipe
;
5081 /* To avoid upsetting the power well on haswell only disable the pfit if
5082 * it's in use. The hw state code will make sure we get this right. */
5083 if (crtc
->config
->pch_pfit
.enabled
) {
5084 I915_WRITE(PF_CTL(pipe
), 0);
5085 I915_WRITE(PF_WIN_POS(pipe
), 0);
5086 I915_WRITE(PF_WIN_SZ(pipe
), 0);
5090 static void ironlake_crtc_disable(struct drm_crtc
*crtc
)
5092 struct drm_device
*dev
= crtc
->dev
;
5093 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5094 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5095 struct intel_encoder
*encoder
;
5096 int pipe
= intel_crtc
->pipe
;
5099 if (!intel_crtc
->active
)
5102 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5103 encoder
->disable(encoder
);
5105 drm_crtc_vblank_off(crtc
);
5106 assert_vblank_disabled(crtc
);
5108 if (intel_crtc
->config
->has_pch_encoder
)
5109 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
5111 intel_disable_pipe(intel_crtc
);
5113 ironlake_pfit_disable(intel_crtc
);
5115 if (intel_crtc
->config
->has_pch_encoder
)
5116 ironlake_fdi_disable(crtc
);
5118 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5119 if (encoder
->post_disable
)
5120 encoder
->post_disable(encoder
);
5122 if (intel_crtc
->config
->has_pch_encoder
) {
5123 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
5125 if (HAS_PCH_CPT(dev
)) {
5126 /* disable TRANS_DP_CTL */
5127 reg
= TRANS_DP_CTL(pipe
);
5128 temp
= I915_READ(reg
);
5129 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
5130 TRANS_DP_PORT_SEL_MASK
);
5131 temp
|= TRANS_DP_PORT_SEL_NONE
;
5132 I915_WRITE(reg
, temp
);
5134 /* disable DPLL_SEL */
5135 temp
= I915_READ(PCH_DPLL_SEL
);
5136 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
5137 I915_WRITE(PCH_DPLL_SEL
, temp
);
5140 /* disable PCH DPLL */
5141 intel_disable_shared_dpll(intel_crtc
);
5143 ironlake_fdi_pll_disable(intel_crtc
);
5146 intel_crtc
->active
= false;
5147 intel_update_watermarks(crtc
);
5149 mutex_lock(&dev
->struct_mutex
);
5150 intel_fbc_update(dev
);
5151 mutex_unlock(&dev
->struct_mutex
);
5154 static void haswell_crtc_disable(struct drm_crtc
*crtc
)
5156 struct drm_device
*dev
= crtc
->dev
;
5157 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5158 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5159 struct intel_encoder
*encoder
;
5160 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5162 if (!intel_crtc
->active
)
5165 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5166 intel_opregion_notify_encoder(encoder
, false);
5167 encoder
->disable(encoder
);
5170 drm_crtc_vblank_off(crtc
);
5171 assert_vblank_disabled(crtc
);
5173 if (intel_crtc
->config
->has_pch_encoder
)
5174 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5176 intel_disable_pipe(intel_crtc
);
5178 if (intel_crtc
->config
->dp_encoder_is_mst
)
5179 intel_ddi_set_vc_payload_alloc(crtc
, false);
5181 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
5183 if (INTEL_INFO(dev
)->gen
== 9)
5184 skylake_pfit_update(intel_crtc
, 0);
5185 else if (INTEL_INFO(dev
)->gen
< 9)
5186 ironlake_pfit_disable(intel_crtc
);
5188 MISSING_CASE(INTEL_INFO(dev
)->gen
);
5190 intel_ddi_disable_pipe_clock(intel_crtc
);
5192 if (intel_crtc
->config
->has_pch_encoder
) {
5193 lpt_disable_pch_transcoder(dev_priv
);
5194 intel_ddi_fdi_disable(crtc
);
5197 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5198 if (encoder
->post_disable
)
5199 encoder
->post_disable(encoder
);
5201 intel_crtc
->active
= false;
5202 intel_update_watermarks(crtc
);
5204 mutex_lock(&dev
->struct_mutex
);
5205 intel_fbc_update(dev
);
5206 mutex_unlock(&dev
->struct_mutex
);
5208 if (intel_crtc_to_shared_dpll(intel_crtc
))
5209 intel_disable_shared_dpll(intel_crtc
);
5212 static void ironlake_crtc_off(struct drm_crtc
*crtc
)
5214 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5215 intel_put_shared_dpll(intel_crtc
);
5219 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
5221 struct drm_device
*dev
= crtc
->base
.dev
;
5222 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5223 struct intel_crtc_state
*pipe_config
= crtc
->config
;
5225 if (!pipe_config
->gmch_pfit
.control
)
5229 * The panel fitter should only be adjusted whilst the pipe is disabled,
5230 * according to register description and PRM.
5232 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
5233 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5235 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
5236 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
5238 /* Border color in case we don't scale up to the full screen. Black by
5239 * default, change to something else for debugging. */
5240 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
5243 static enum intel_display_power_domain
port_to_power_domain(enum port port
)
5247 return POWER_DOMAIN_PORT_DDI_A_4_LANES
;
5249 return POWER_DOMAIN_PORT_DDI_B_4_LANES
;
5251 return POWER_DOMAIN_PORT_DDI_C_4_LANES
;
5253 return POWER_DOMAIN_PORT_DDI_D_4_LANES
;
5256 return POWER_DOMAIN_PORT_OTHER
;
5260 #define for_each_power_domain(domain, mask) \
5261 for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
5262 if ((1 << (domain)) & (mask))
5264 enum intel_display_power_domain
5265 intel_display_port_power_domain(struct intel_encoder
*intel_encoder
)
5267 struct drm_device
*dev
= intel_encoder
->base
.dev
;
5268 struct intel_digital_port
*intel_dig_port
;
5270 switch (intel_encoder
->type
) {
5271 case INTEL_OUTPUT_UNKNOWN
:
5272 /* Only DDI platforms should ever use this output type */
5273 WARN_ON_ONCE(!HAS_DDI(dev
));
5274 case INTEL_OUTPUT_DISPLAYPORT
:
5275 case INTEL_OUTPUT_HDMI
:
5276 case INTEL_OUTPUT_EDP
:
5277 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
5278 return port_to_power_domain(intel_dig_port
->port
);
5279 case INTEL_OUTPUT_DP_MST
:
5280 intel_dig_port
= enc_to_mst(&intel_encoder
->base
)->primary
;
5281 return port_to_power_domain(intel_dig_port
->port
);
5282 case INTEL_OUTPUT_ANALOG
:
5283 return POWER_DOMAIN_PORT_CRT
;
5284 case INTEL_OUTPUT_DSI
:
5285 return POWER_DOMAIN_PORT_DSI
;
5287 return POWER_DOMAIN_PORT_OTHER
;
5291 static unsigned long get_crtc_power_domains(struct drm_crtc
*crtc
)
5293 struct drm_device
*dev
= crtc
->dev
;
5294 struct intel_encoder
*intel_encoder
;
5295 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5296 enum pipe pipe
= intel_crtc
->pipe
;
5298 enum transcoder transcoder
;
5300 transcoder
= intel_pipe_to_cpu_transcoder(dev
->dev_private
, pipe
);
5302 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
5303 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
5304 if (intel_crtc
->config
->pch_pfit
.enabled
||
5305 intel_crtc
->config
->pch_pfit
.force_thru
)
5306 mask
|= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
5308 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
5309 mask
|= BIT(intel_display_port_power_domain(intel_encoder
));
5314 static void modeset_update_crtc_power_domains(struct drm_atomic_state
*state
)
5316 struct drm_device
*dev
= state
->dev
;
5317 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5318 unsigned long pipe_domains
[I915_MAX_PIPES
] = { 0, };
5319 struct intel_crtc
*crtc
;
5322 * First get all needed power domains, then put all unneeded, to avoid
5323 * any unnecessary toggling of the power wells.
5325 for_each_intel_crtc(dev
, crtc
) {
5326 enum intel_display_power_domain domain
;
5328 if (!crtc
->base
.state
->enable
)
5331 pipe_domains
[crtc
->pipe
] = get_crtc_power_domains(&crtc
->base
);
5333 for_each_power_domain(domain
, pipe_domains
[crtc
->pipe
])
5334 intel_display_power_get(dev_priv
, domain
);
5337 if (dev_priv
->display
.modeset_global_resources
)
5338 dev_priv
->display
.modeset_global_resources(state
);
5340 for_each_intel_crtc(dev
, crtc
) {
5341 enum intel_display_power_domain domain
;
5343 for_each_power_domain(domain
, crtc
->enabled_power_domains
)
5344 intel_display_power_put(dev_priv
, domain
);
5346 crtc
->enabled_power_domains
= pipe_domains
[crtc
->pipe
];
5349 intel_display_set_init_power(dev_priv
, false);
5352 void broxton_set_cdclk(struct drm_device
*dev
, int frequency
)
5354 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5357 uint32_t current_freq
;
5360 /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */
5361 switch (frequency
) {
5363 divider
= BXT_CDCLK_CD2X_DIV_SEL_4
;
5364 ratio
= BXT_DE_PLL_RATIO(60);
5367 divider
= BXT_CDCLK_CD2X_DIV_SEL_2
;
5368 ratio
= BXT_DE_PLL_RATIO(60);
5371 divider
= BXT_CDCLK_CD2X_DIV_SEL_1_5
;
5372 ratio
= BXT_DE_PLL_RATIO(60);
5375 divider
= BXT_CDCLK_CD2X_DIV_SEL_1
;
5376 ratio
= BXT_DE_PLL_RATIO(60);
5379 divider
= BXT_CDCLK_CD2X_DIV_SEL_1
;
5380 ratio
= BXT_DE_PLL_RATIO(65);
5384 * Bypass frequency with DE PLL disabled. Init ratio, divider
5385 * to suppress GCC warning.
5391 DRM_ERROR("unsupported CDCLK freq %d", frequency
);
5396 mutex_lock(&dev_priv
->rps
.hw_lock
);
5397 /* Inform power controller of upcoming frequency change */
5398 ret
= sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
,
5400 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5403 DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n",
5408 current_freq
= I915_READ(CDCLK_CTL
) & CDCLK_FREQ_DECIMAL_MASK
;
5409 /* convert from .1 fixpoint MHz with -1MHz offset to kHz */
5410 current_freq
= current_freq
* 500 + 1000;
5413 * DE PLL has to be disabled when
5414 * - setting to 19.2MHz (bypass, PLL isn't used)
5415 * - before setting to 624MHz (PLL needs toggling)
5416 * - before setting to any frequency from 624MHz (PLL needs toggling)
5418 if (frequency
== 19200 || frequency
== 624000 ||
5419 current_freq
== 624000) {
5420 I915_WRITE(BXT_DE_PLL_ENABLE
, ~BXT_DE_PLL_PLL_ENABLE
);
5422 if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_LOCK
),
5424 DRM_ERROR("timout waiting for DE PLL unlock\n");
5427 if (frequency
!= 19200) {
5430 val
= I915_READ(BXT_DE_PLL_CTL
);
5431 val
&= ~BXT_DE_PLL_RATIO_MASK
;
5433 I915_WRITE(BXT_DE_PLL_CTL
, val
);
5435 I915_WRITE(BXT_DE_PLL_ENABLE
, BXT_DE_PLL_PLL_ENABLE
);
5437 if (wait_for(I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_LOCK
, 1))
5438 DRM_ERROR("timeout waiting for DE PLL lock\n");
5440 val
= I915_READ(CDCLK_CTL
);
5441 val
&= ~BXT_CDCLK_CD2X_DIV_SEL_MASK
;
5444 * Disable SSA Precharge when CD clock frequency < 500 MHz,
5447 val
&= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE
;
5448 if (frequency
>= 500000)
5449 val
|= BXT_CDCLK_SSA_PRECHARGE_ENABLE
;
5451 val
&= ~CDCLK_FREQ_DECIMAL_MASK
;
5452 /* convert from kHz to .1 fixpoint MHz with -1MHz offset */
5453 val
|= (frequency
- 1000) / 500;
5454 I915_WRITE(CDCLK_CTL
, val
);
5457 mutex_lock(&dev_priv
->rps
.hw_lock
);
5458 ret
= sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
,
5459 DIV_ROUND_UP(frequency
, 25000));
5460 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5463 DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n",
5468 dev_priv
->cdclk_freq
= frequency
;
5471 void broxton_init_cdclk(struct drm_device
*dev
)
5473 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5477 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
5478 * or else the reset will hang because there is no PCH to respond.
5479 * Move the handshake programming to initialization sequence.
5480 * Previously was left up to BIOS.
5482 val
= I915_READ(HSW_NDE_RSTWRN_OPT
);
5483 val
&= ~RESET_PCH_HANDSHAKE_ENABLE
;
5484 I915_WRITE(HSW_NDE_RSTWRN_OPT
, val
);
5486 /* Enable PG1 for cdclk */
5487 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
5489 /* check if cd clock is enabled */
5490 if (I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_PLL_ENABLE
) {
5491 DRM_DEBUG_KMS("Display already initialized\n");
5497 * - The initial CDCLK needs to be read from VBT.
5498 * Need to make this change after VBT has changes for BXT.
5499 * - check if setting the max (or any) cdclk freq is really necessary
5500 * here, it belongs to modeset time
5502 broxton_set_cdclk(dev
, 624000);
5504 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) | DBUF_POWER_REQUEST
);
5505 POSTING_READ(DBUF_CTL
);
5509 if (!(I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
))
5510 DRM_ERROR("DBuf power enable timeout!\n");
5513 void broxton_uninit_cdclk(struct drm_device
*dev
)
5515 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
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 disable timeout!\n");
5525 /* Set minimum (bypass) frequency, in effect turning off the DE PLL */
5526 broxton_set_cdclk(dev
, 19200);
5528 intel_display_power_put(dev_priv
, POWER_DOMAIN_PLLS
);
5531 static const struct skl_cdclk_entry
{
5534 } skl_cdclk_frequencies
[] = {
5535 { .freq
= 308570, .vco
= 8640 },
5536 { .freq
= 337500, .vco
= 8100 },
5537 { .freq
= 432000, .vco
= 8640 },
5538 { .freq
= 450000, .vco
= 8100 },
5539 { .freq
= 540000, .vco
= 8100 },
5540 { .freq
= 617140, .vco
= 8640 },
5541 { .freq
= 675000, .vco
= 8100 },
5544 static unsigned int skl_cdclk_decimal(unsigned int freq
)
5546 return (freq
- 1000) / 500;
5549 static unsigned int skl_cdclk_get_vco(unsigned int freq
)
5553 for (i
= 0; i
< ARRAY_SIZE(skl_cdclk_frequencies
); i
++) {
5554 const struct skl_cdclk_entry
*e
= &skl_cdclk_frequencies
[i
];
5556 if (e
->freq
== freq
)
5564 skl_dpll0_enable(struct drm_i915_private
*dev_priv
, unsigned int required_vco
)
5566 unsigned int min_freq
;
5569 /* select the minimum CDCLK before enabling DPLL 0 */
5570 val
= I915_READ(CDCLK_CTL
);
5571 val
&= ~CDCLK_FREQ_SEL_MASK
| ~CDCLK_FREQ_DECIMAL_MASK
;
5572 val
|= CDCLK_FREQ_337_308
;
5574 if (required_vco
== 8640)
5579 val
= CDCLK_FREQ_337_308
| skl_cdclk_decimal(min_freq
);
5581 I915_WRITE(CDCLK_CTL
, val
);
5582 POSTING_READ(CDCLK_CTL
);
5585 * We always enable DPLL0 with the lowest link rate possible, but still
5586 * taking into account the VCO required to operate the eDP panel at the
5587 * desired frequency. The usual DP link rates operate with a VCO of
5588 * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640.
5589 * The modeset code is responsible for the selection of the exact link
5590 * rate later on, with the constraint of choosing a frequency that
5591 * works with required_vco.
5593 val
= I915_READ(DPLL_CTRL1
);
5595 val
&= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0
) | DPLL_CTRL1_SSC(SKL_DPLL0
) |
5596 DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
));
5597 val
|= DPLL_CTRL1_OVERRIDE(SKL_DPLL0
);
5598 if (required_vco
== 8640)
5599 val
|= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080
,
5602 val
|= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810
,
5605 I915_WRITE(DPLL_CTRL1
, val
);
5606 POSTING_READ(DPLL_CTRL1
);
5608 I915_WRITE(LCPLL1_CTL
, I915_READ(LCPLL1_CTL
) | LCPLL_PLL_ENABLE
);
5610 if (wait_for(I915_READ(LCPLL1_CTL
) & LCPLL_PLL_LOCK
, 5))
5611 DRM_ERROR("DPLL0 not locked\n");
5614 static bool skl_cdclk_pcu_ready(struct drm_i915_private
*dev_priv
)
5619 /* inform PCU we want to change CDCLK */
5620 val
= SKL_CDCLK_PREPARE_FOR_CHANGE
;
5621 mutex_lock(&dev_priv
->rps
.hw_lock
);
5622 ret
= sandybridge_pcode_read(dev_priv
, SKL_PCODE_CDCLK_CONTROL
, &val
);
5623 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5625 return ret
== 0 && (val
& SKL_CDCLK_READY_FOR_CHANGE
);
5628 static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private
*dev_priv
)
5632 for (i
= 0; i
< 15; i
++) {
5633 if (skl_cdclk_pcu_ready(dev_priv
))
5641 static void skl_set_cdclk(struct drm_i915_private
*dev_priv
, unsigned int freq
)
5643 u32 freq_select
, pcu_ack
;
5645 DRM_DEBUG_DRIVER("Changing CDCLK to %dKHz\n", freq
);
5647 if (!skl_cdclk_wait_for_pcu_ready(dev_priv
)) {
5648 DRM_ERROR("failed to inform PCU about cdclk change\n");
5656 freq_select
= CDCLK_FREQ_450_432
;
5660 freq_select
= CDCLK_FREQ_540
;
5666 freq_select
= CDCLK_FREQ_337_308
;
5671 freq_select
= CDCLK_FREQ_675_617
;
5676 I915_WRITE(CDCLK_CTL
, freq_select
| skl_cdclk_decimal(freq
));
5677 POSTING_READ(CDCLK_CTL
);
5679 /* inform PCU of the change */
5680 mutex_lock(&dev_priv
->rps
.hw_lock
);
5681 sandybridge_pcode_write(dev_priv
, SKL_PCODE_CDCLK_CONTROL
, pcu_ack
);
5682 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5685 void skl_uninit_cdclk(struct drm_i915_private
*dev_priv
)
5687 /* disable DBUF power */
5688 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) & ~DBUF_POWER_REQUEST
);
5689 POSTING_READ(DBUF_CTL
);
5693 if (I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
)
5694 DRM_ERROR("DBuf power disable timeout\n");
5697 I915_WRITE(LCPLL1_CTL
, I915_READ(LCPLL1_CTL
) & ~LCPLL_PLL_ENABLE
);
5698 if (wait_for(!(I915_READ(LCPLL1_CTL
) & LCPLL_PLL_LOCK
), 1))
5699 DRM_ERROR("Couldn't disable DPLL0\n");
5701 intel_display_power_put(dev_priv
, POWER_DOMAIN_PLLS
);
5704 void skl_init_cdclk(struct drm_i915_private
*dev_priv
)
5707 unsigned int required_vco
;
5709 /* enable PCH reset handshake */
5710 val
= I915_READ(HSW_NDE_RSTWRN_OPT
);
5711 I915_WRITE(HSW_NDE_RSTWRN_OPT
, val
| RESET_PCH_HANDSHAKE_ENABLE
);
5713 /* enable PG1 and Misc I/O */
5714 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
5716 /* DPLL0 already enabed !? */
5717 if (I915_READ(LCPLL1_CTL
) & LCPLL_PLL_ENABLE
) {
5718 DRM_DEBUG_DRIVER("DPLL0 already running\n");
5723 required_vco
= skl_cdclk_get_vco(dev_priv
->skl_boot_cdclk
);
5724 skl_dpll0_enable(dev_priv
, required_vco
);
5726 /* set CDCLK to the frequency the BIOS chose */
5727 skl_set_cdclk(dev_priv
, dev_priv
->skl_boot_cdclk
);
5729 /* enable DBUF power */
5730 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) | DBUF_POWER_REQUEST
);
5731 POSTING_READ(DBUF_CTL
);
5735 if (!(I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
))
5736 DRM_ERROR("DBuf power enable timeout\n");
5739 /* returns HPLL frequency in kHz */
5740 static int valleyview_get_vco(struct drm_i915_private
*dev_priv
)
5742 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
5744 /* Obtain SKU information */
5745 mutex_lock(&dev_priv
->dpio_lock
);
5746 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
5747 CCK_FUSE_HPLL_FREQ_MASK
;
5748 mutex_unlock(&dev_priv
->dpio_lock
);
5750 return vco_freq
[hpll_freq
] * 1000;
5753 static void vlv_update_cdclk(struct drm_device
*dev
)
5755 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5757 dev_priv
->cdclk_freq
= dev_priv
->display
.get_display_clock_speed(dev
);
5758 DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n",
5759 dev_priv
->cdclk_freq
);
5762 * Program the gmbus_freq based on the cdclk frequency.
5763 * BSpec erroneously claims we should aim for 4MHz, but
5764 * in fact 1MHz is the correct frequency.
5766 I915_WRITE(GMBUSFREQ_VLV
, DIV_ROUND_UP(dev_priv
->cdclk_freq
, 1000));
5769 /* Adjust CDclk dividers to allow high res or save power if possible */
5770 static void valleyview_set_cdclk(struct drm_device
*dev
, int cdclk
)
5772 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5775 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
)
5776 != dev_priv
->cdclk_freq
);
5778 if (cdclk
>= 320000) /* jump to highest voltage for 400MHz too */
5780 else if (cdclk
== 266667)
5785 mutex_lock(&dev_priv
->rps
.hw_lock
);
5786 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
5787 val
&= ~DSPFREQGUAR_MASK
;
5788 val
|= (cmd
<< DSPFREQGUAR_SHIFT
);
5789 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
5790 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
5791 DSPFREQSTAT_MASK
) == (cmd
<< DSPFREQSTAT_SHIFT
),
5793 DRM_ERROR("timed out waiting for CDclk change\n");
5795 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5797 if (cdclk
== 400000) {
5800 divider
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
5802 mutex_lock(&dev_priv
->dpio_lock
);
5803 /* adjust cdclk divider */
5804 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
5805 val
&= ~DISPLAY_FREQUENCY_VALUES
;
5807 vlv_cck_write(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
, val
);
5809 if (wait_for((vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
) &
5810 DISPLAY_FREQUENCY_STATUS
) == (divider
<< DISPLAY_FREQUENCY_STATUS_SHIFT
),
5812 DRM_ERROR("timed out waiting for CDclk change\n");
5813 mutex_unlock(&dev_priv
->dpio_lock
);
5816 mutex_lock(&dev_priv
->dpio_lock
);
5817 /* adjust self-refresh exit latency value */
5818 val
= vlv_bunit_read(dev_priv
, BUNIT_REG_BISOC
);
5822 * For high bandwidth configs, we set a higher latency in the bunit
5823 * so that the core display fetch happens in time to avoid underruns.
5825 if (cdclk
== 400000)
5826 val
|= 4500 / 250; /* 4.5 usec */
5828 val
|= 3000 / 250; /* 3.0 usec */
5829 vlv_bunit_write(dev_priv
, BUNIT_REG_BISOC
, val
);
5830 mutex_unlock(&dev_priv
->dpio_lock
);
5832 vlv_update_cdclk(dev
);
5835 static void cherryview_set_cdclk(struct drm_device
*dev
, int cdclk
)
5837 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5840 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
)
5841 != dev_priv
->cdclk_freq
);
5850 MISSING_CASE(cdclk
);
5855 * Specs are full of misinformation, but testing on actual
5856 * hardware has shown that we just need to write the desired
5857 * CCK divider into the Punit register.
5859 cmd
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
5861 mutex_lock(&dev_priv
->rps
.hw_lock
);
5862 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
5863 val
&= ~DSPFREQGUAR_MASK_CHV
;
5864 val
|= (cmd
<< DSPFREQGUAR_SHIFT_CHV
);
5865 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
5866 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
5867 DSPFREQSTAT_MASK_CHV
) == (cmd
<< DSPFREQSTAT_SHIFT_CHV
),
5869 DRM_ERROR("timed out waiting for CDclk change\n");
5871 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5873 vlv_update_cdclk(dev
);
5876 static int valleyview_calc_cdclk(struct drm_i915_private
*dev_priv
,
5879 int freq_320
= (dev_priv
->hpll_freq
<< 1) % 320000 != 0 ? 333333 : 320000;
5880 int limit
= IS_CHERRYVIEW(dev_priv
) ? 95 : 90;
5883 * Really only a few cases to deal with, as only 4 CDclks are supported:
5886 * 320/333MHz (depends on HPLL freq)
5888 * So we check to see whether we're above 90% (VLV) or 95% (CHV)
5889 * of the lower bin and adjust if needed.
5891 * We seem to get an unstable or solid color picture at 200MHz.
5892 * Not sure what's wrong. For now use 200MHz only when all pipes
5895 if (!IS_CHERRYVIEW(dev_priv
) &&
5896 max_pixclk
> freq_320
*limit
/100)
5898 else if (max_pixclk
> 266667*limit
/100)
5900 else if (max_pixclk
> 0)
5906 static int broxton_calc_cdclk(struct drm_i915_private
*dev_priv
,
5911 * - remove the guardband, it's not needed on BXT
5912 * - set 19.2MHz bypass frequency if there are no active pipes
5914 if (max_pixclk
> 576000*9/10)
5916 else if (max_pixclk
> 384000*9/10)
5918 else if (max_pixclk
> 288000*9/10)
5920 else if (max_pixclk
> 144000*9/10)
5926 /* Compute the max pixel clock for new configuration. Uses atomic state if
5927 * that's non-NULL, look at current state otherwise. */
5928 static int intel_mode_max_pixclk(struct drm_device
*dev
,
5929 struct drm_atomic_state
*state
)
5931 struct intel_crtc
*intel_crtc
;
5932 struct intel_crtc_state
*crtc_state
;
5935 for_each_intel_crtc(dev
, intel_crtc
) {
5938 intel_atomic_get_crtc_state(state
, intel_crtc
);
5940 crtc_state
= intel_crtc
->config
;
5941 if (IS_ERR(crtc_state
))
5942 return PTR_ERR(crtc_state
);
5944 if (!crtc_state
->base
.enable
)
5947 max_pixclk
= max(max_pixclk
,
5948 crtc_state
->base
.adjusted_mode
.crtc_clock
);
5954 static int valleyview_modeset_global_pipes(struct drm_atomic_state
*state
)
5956 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
5957 struct drm_crtc
*crtc
;
5958 struct drm_crtc_state
*crtc_state
;
5959 int max_pixclk
= intel_mode_max_pixclk(state
->dev
, state
);
5965 if (IS_VALLEYVIEW(dev_priv
))
5966 cdclk
= valleyview_calc_cdclk(dev_priv
, max_pixclk
);
5968 cdclk
= broxton_calc_cdclk(dev_priv
, max_pixclk
);
5970 if (cdclk
== dev_priv
->cdclk_freq
)
5973 /* add all active pipes to the state */
5974 for_each_crtc(state
->dev
, crtc
) {
5975 if (!crtc
->state
->enable
)
5978 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
5979 if (IS_ERR(crtc_state
))
5980 return PTR_ERR(crtc_state
);
5983 /* disable/enable all currently active pipes while we change cdclk */
5984 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
)
5985 if (crtc_state
->enable
)
5986 crtc_state
->mode_changed
= true;
5991 static void vlv_program_pfi_credits(struct drm_i915_private
*dev_priv
)
5993 unsigned int credits
, default_credits
;
5995 if (IS_CHERRYVIEW(dev_priv
))
5996 default_credits
= PFI_CREDIT(12);
5998 default_credits
= PFI_CREDIT(8);
6000 if (DIV_ROUND_CLOSEST(dev_priv
->cdclk_freq
, 1000) >= dev_priv
->rps
.cz_freq
) {
6001 /* CHV suggested value is 31 or 63 */
6002 if (IS_CHERRYVIEW(dev_priv
))
6003 credits
= PFI_CREDIT_31
;
6005 credits
= PFI_CREDIT(15);
6007 credits
= default_credits
;
6011 * WA - write default credits before re-programming
6012 * FIXME: should we also set the resend bit here?
6014 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
6017 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
6018 credits
| PFI_CREDIT_RESEND
);
6021 * FIXME is this guaranteed to clear
6022 * immediately or should we poll for it?
6024 WARN_ON(I915_READ(GCI_CONTROL
) & PFI_CREDIT_RESEND
);
6027 static void valleyview_modeset_global_resources(struct drm_atomic_state
*old_state
)
6029 struct drm_device
*dev
= old_state
->dev
;
6030 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6031 int max_pixclk
= intel_mode_max_pixclk(dev
, NULL
);
6034 /* The path in intel_mode_max_pixclk() with a NULL atomic state should
6036 if (WARN_ON(max_pixclk
< 0))
6039 req_cdclk
= valleyview_calc_cdclk(dev_priv
, max_pixclk
);
6041 if (req_cdclk
!= dev_priv
->cdclk_freq
) {
6043 * FIXME: We can end up here with all power domains off, yet
6044 * with a CDCLK frequency other than the minimum. To account
6045 * for this take the PIPE-A power domain, which covers the HW
6046 * blocks needed for the following programming. This can be
6047 * removed once it's guaranteed that we get here either with
6048 * the minimum CDCLK set, or the required power domains
6051 intel_display_power_get(dev_priv
, POWER_DOMAIN_PIPE_A
);
6053 if (IS_CHERRYVIEW(dev
))
6054 cherryview_set_cdclk(dev
, req_cdclk
);
6056 valleyview_set_cdclk(dev
, req_cdclk
);
6058 vlv_program_pfi_credits(dev_priv
);
6060 intel_display_power_put(dev_priv
, POWER_DOMAIN_PIPE_A
);
6064 static void valleyview_crtc_enable(struct drm_crtc
*crtc
)
6066 struct drm_device
*dev
= crtc
->dev
;
6067 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6068 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6069 struct intel_encoder
*encoder
;
6070 int pipe
= intel_crtc
->pipe
;
6073 WARN_ON(!crtc
->state
->enable
);
6075 if (intel_crtc
->active
)
6078 is_dsi
= intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_DSI
);
6081 if (IS_CHERRYVIEW(dev
))
6082 chv_prepare_pll(intel_crtc
, intel_crtc
->config
);
6084 vlv_prepare_pll(intel_crtc
, intel_crtc
->config
);
6087 if (intel_crtc
->config
->has_dp_encoder
)
6088 intel_dp_set_m_n(intel_crtc
, M1_N1
);
6090 intel_set_pipe_timings(intel_crtc
);
6092 if (IS_CHERRYVIEW(dev
) && pipe
== PIPE_B
) {
6093 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6095 I915_WRITE(CHV_BLEND(pipe
), CHV_BLEND_LEGACY
);
6096 I915_WRITE(CHV_CANVAS(pipe
), 0);
6099 i9xx_set_pipeconf(intel_crtc
);
6101 intel_crtc
->active
= true;
6103 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
6105 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6106 if (encoder
->pre_pll_enable
)
6107 encoder
->pre_pll_enable(encoder
);
6110 if (IS_CHERRYVIEW(dev
))
6111 chv_enable_pll(intel_crtc
, intel_crtc
->config
);
6113 vlv_enable_pll(intel_crtc
, intel_crtc
->config
);
6116 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6117 if (encoder
->pre_enable
)
6118 encoder
->pre_enable(encoder
);
6120 i9xx_pfit_enable(intel_crtc
);
6122 intel_crtc_load_lut(crtc
);
6124 intel_update_watermarks(crtc
);
6125 intel_enable_pipe(intel_crtc
);
6127 assert_vblank_disabled(crtc
);
6128 drm_crtc_vblank_on(crtc
);
6130 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6131 encoder
->enable(encoder
);
6134 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
6136 struct drm_device
*dev
= crtc
->base
.dev
;
6137 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6139 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp0
);
6140 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp1
);
6143 static void i9xx_crtc_enable(struct drm_crtc
*crtc
)
6145 struct drm_device
*dev
= crtc
->dev
;
6146 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6147 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6148 struct intel_encoder
*encoder
;
6149 int pipe
= intel_crtc
->pipe
;
6151 WARN_ON(!crtc
->state
->enable
);
6153 if (intel_crtc
->active
)
6156 i9xx_set_pll_dividers(intel_crtc
);
6158 if (intel_crtc
->config
->has_dp_encoder
)
6159 intel_dp_set_m_n(intel_crtc
, M1_N1
);
6161 intel_set_pipe_timings(intel_crtc
);
6163 i9xx_set_pipeconf(intel_crtc
);
6165 intel_crtc
->active
= true;
6168 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
6170 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6171 if (encoder
->pre_enable
)
6172 encoder
->pre_enable(encoder
);
6174 i9xx_enable_pll(intel_crtc
);
6176 i9xx_pfit_enable(intel_crtc
);
6178 intel_crtc_load_lut(crtc
);
6180 intel_update_watermarks(crtc
);
6181 intel_enable_pipe(intel_crtc
);
6183 assert_vblank_disabled(crtc
);
6184 drm_crtc_vblank_on(crtc
);
6186 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6187 encoder
->enable(encoder
);
6190 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
6192 struct drm_device
*dev
= crtc
->base
.dev
;
6193 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6195 if (!crtc
->config
->gmch_pfit
.control
)
6198 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
6200 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
6201 I915_READ(PFIT_CONTROL
));
6202 I915_WRITE(PFIT_CONTROL
, 0);
6205 static void i9xx_crtc_disable(struct drm_crtc
*crtc
)
6207 struct drm_device
*dev
= crtc
->dev
;
6208 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6209 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6210 struct intel_encoder
*encoder
;
6211 int pipe
= intel_crtc
->pipe
;
6213 if (!intel_crtc
->active
)
6217 * On gen2 planes are double buffered but the pipe isn't, so we must
6218 * wait for planes to fully turn off before disabling the pipe.
6219 * We also need to wait on all gmch platforms because of the
6220 * self-refresh mode constraint explained above.
6222 intel_wait_for_vblank(dev
, pipe
);
6224 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6225 encoder
->disable(encoder
);
6227 drm_crtc_vblank_off(crtc
);
6228 assert_vblank_disabled(crtc
);
6230 intel_disable_pipe(intel_crtc
);
6232 i9xx_pfit_disable(intel_crtc
);
6234 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6235 if (encoder
->post_disable
)
6236 encoder
->post_disable(encoder
);
6238 if (!intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_DSI
)) {
6239 if (IS_CHERRYVIEW(dev
))
6240 chv_disable_pll(dev_priv
, pipe
);
6241 else if (IS_VALLEYVIEW(dev
))
6242 vlv_disable_pll(dev_priv
, pipe
);
6244 i9xx_disable_pll(intel_crtc
);
6248 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
6250 intel_crtc
->active
= false;
6251 intel_update_watermarks(crtc
);
6253 mutex_lock(&dev
->struct_mutex
);
6254 intel_fbc_update(dev
);
6255 mutex_unlock(&dev
->struct_mutex
);
6258 static void i9xx_crtc_off(struct drm_crtc
*crtc
)
6262 /* Master function to enable/disable CRTC and corresponding power wells */
6263 void intel_crtc_control(struct drm_crtc
*crtc
, bool enable
)
6265 struct drm_device
*dev
= crtc
->dev
;
6266 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6267 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6268 enum intel_display_power_domain domain
;
6269 unsigned long domains
;
6272 if (!intel_crtc
->active
) {
6273 domains
= get_crtc_power_domains(crtc
);
6274 for_each_power_domain(domain
, domains
)
6275 intel_display_power_get(dev_priv
, domain
);
6276 intel_crtc
->enabled_power_domains
= domains
;
6278 dev_priv
->display
.crtc_enable(crtc
);
6279 intel_crtc_enable_planes(crtc
);
6282 if (intel_crtc
->active
) {
6283 intel_crtc_disable_planes(crtc
);
6284 dev_priv
->display
.crtc_disable(crtc
);
6286 domains
= intel_crtc
->enabled_power_domains
;
6287 for_each_power_domain(domain
, domains
)
6288 intel_display_power_put(dev_priv
, domain
);
6289 intel_crtc
->enabled_power_domains
= 0;
6295 * Sets the power management mode of the pipe and plane.
6297 void intel_crtc_update_dpms(struct drm_crtc
*crtc
)
6299 struct drm_device
*dev
= crtc
->dev
;
6300 struct intel_encoder
*intel_encoder
;
6301 bool enable
= false;
6303 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
6304 enable
|= intel_encoder
->connectors_active
;
6306 intel_crtc_control(crtc
, enable
);
6308 crtc
->state
->active
= enable
;
6311 static void intel_crtc_disable(struct drm_crtc
*crtc
)
6313 struct drm_device
*dev
= crtc
->dev
;
6314 struct drm_connector
*connector
;
6315 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6317 /* crtc should still be enabled when we disable it. */
6318 WARN_ON(!crtc
->state
->enable
);
6320 intel_crtc_disable_planes(crtc
);
6321 dev_priv
->display
.crtc_disable(crtc
);
6322 dev_priv
->display
.off(crtc
);
6324 drm_plane_helper_disable(crtc
->primary
);
6326 /* Update computed state. */
6327 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
6328 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
6331 if (connector
->encoder
->crtc
!= crtc
)
6334 connector
->dpms
= DRM_MODE_DPMS_OFF
;
6335 to_intel_encoder(connector
->encoder
)->connectors_active
= false;
6339 void intel_encoder_destroy(struct drm_encoder
*encoder
)
6341 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
6343 drm_encoder_cleanup(encoder
);
6344 kfree(intel_encoder
);
6347 /* Simple dpms helper for encoders with just one connector, no cloning and only
6348 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
6349 * state of the entire output pipe. */
6350 static void intel_encoder_dpms(struct intel_encoder
*encoder
, int mode
)
6352 if (mode
== DRM_MODE_DPMS_ON
) {
6353 encoder
->connectors_active
= true;
6355 intel_crtc_update_dpms(encoder
->base
.crtc
);
6357 encoder
->connectors_active
= false;
6359 intel_crtc_update_dpms(encoder
->base
.crtc
);
6363 /* Cross check the actual hw state with our own modeset state tracking (and it's
6364 * internal consistency). */
6365 static void intel_connector_check_state(struct intel_connector
*connector
)
6367 if (connector
->get_hw_state(connector
)) {
6368 struct intel_encoder
*encoder
= connector
->encoder
;
6369 struct drm_crtc
*crtc
;
6370 bool encoder_enabled
;
6373 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6374 connector
->base
.base
.id
,
6375 connector
->base
.name
);
6377 /* there is no real hw state for MST connectors */
6378 if (connector
->mst_port
)
6381 I915_STATE_WARN(connector
->base
.dpms
== DRM_MODE_DPMS_OFF
,
6382 "wrong connector dpms state\n");
6383 I915_STATE_WARN(connector
->base
.encoder
!= &encoder
->base
,
6384 "active connector not linked to encoder\n");
6387 I915_STATE_WARN(!encoder
->connectors_active
,
6388 "encoder->connectors_active not set\n");
6390 encoder_enabled
= encoder
->get_hw_state(encoder
, &pipe
);
6391 I915_STATE_WARN(!encoder_enabled
, "encoder not enabled\n");
6392 if (I915_STATE_WARN_ON(!encoder
->base
.crtc
))
6395 crtc
= encoder
->base
.crtc
;
6397 I915_STATE_WARN(!crtc
->state
->enable
,
6398 "crtc not enabled\n");
6399 I915_STATE_WARN(!to_intel_crtc(crtc
)->active
, "crtc not active\n");
6400 I915_STATE_WARN(pipe
!= to_intel_crtc(crtc
)->pipe
,
6401 "encoder active on the wrong pipe\n");
6406 int intel_connector_init(struct intel_connector
*connector
)
6408 struct drm_connector_state
*connector_state
;
6410 connector_state
= kzalloc(sizeof *connector_state
, GFP_KERNEL
);
6411 if (!connector_state
)
6414 connector
->base
.state
= connector_state
;
6418 struct intel_connector
*intel_connector_alloc(void)
6420 struct intel_connector
*connector
;
6422 connector
= kzalloc(sizeof *connector
, GFP_KERNEL
);
6426 if (intel_connector_init(connector
) < 0) {
6434 /* Even simpler default implementation, if there's really no special case to
6436 void intel_connector_dpms(struct drm_connector
*connector
, int mode
)
6438 /* All the simple cases only support two dpms states. */
6439 if (mode
!= DRM_MODE_DPMS_ON
)
6440 mode
= DRM_MODE_DPMS_OFF
;
6442 if (mode
== connector
->dpms
)
6445 connector
->dpms
= mode
;
6447 /* Only need to change hw state when actually enabled */
6448 if (connector
->encoder
)
6449 intel_encoder_dpms(to_intel_encoder(connector
->encoder
), mode
);
6451 intel_modeset_check_state(connector
->dev
);
6454 /* Simple connector->get_hw_state implementation for encoders that support only
6455 * one connector and no cloning and hence the encoder state determines the state
6456 * of the connector. */
6457 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
6460 struct intel_encoder
*encoder
= connector
->encoder
;
6462 return encoder
->get_hw_state(encoder
, &pipe
);
6465 static int pipe_required_fdi_lanes(struct intel_crtc_state
*crtc_state
)
6467 if (crtc_state
->base
.enable
&& crtc_state
->has_pch_encoder
)
6468 return crtc_state
->fdi_lanes
;
6473 static int ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
6474 struct intel_crtc_state
*pipe_config
)
6476 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
6477 struct intel_crtc
*other_crtc
;
6478 struct intel_crtc_state
*other_crtc_state
;
6480 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6481 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6482 if (pipe_config
->fdi_lanes
> 4) {
6483 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6484 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6488 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
6489 if (pipe_config
->fdi_lanes
> 2) {
6490 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6491 pipe_config
->fdi_lanes
);
6498 if (INTEL_INFO(dev
)->num_pipes
== 2)
6501 /* Ivybridge 3 pipe is really complicated */
6506 if (pipe_config
->fdi_lanes
<= 2)
6509 other_crtc
= to_intel_crtc(intel_get_crtc_for_pipe(dev
, PIPE_C
));
6511 intel_atomic_get_crtc_state(state
, other_crtc
);
6512 if (IS_ERR(other_crtc_state
))
6513 return PTR_ERR(other_crtc_state
);
6515 if (pipe_required_fdi_lanes(other_crtc_state
) > 0) {
6516 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6517 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6522 if (pipe_config
->fdi_lanes
> 2) {
6523 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6524 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6528 other_crtc
= to_intel_crtc(intel_get_crtc_for_pipe(dev
, PIPE_B
));
6530 intel_atomic_get_crtc_state(state
, other_crtc
);
6531 if (IS_ERR(other_crtc_state
))
6532 return PTR_ERR(other_crtc_state
);
6534 if (pipe_required_fdi_lanes(other_crtc_state
) > 2) {
6535 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6545 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
6546 struct intel_crtc_state
*pipe_config
)
6548 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6549 struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6550 int lane
, link_bw
, fdi_dotclock
, ret
;
6551 bool needs_recompute
= false;
6554 /* FDI is a binary signal running at ~2.7GHz, encoding
6555 * each output octet as 10 bits. The actual frequency
6556 * is stored as a divider into a 100MHz clock, and the
6557 * mode pixel clock is stored in units of 1KHz.
6558 * Hence the bw of each lane in terms of the mode signal
6561 link_bw
= intel_fdi_link_freq(dev
) * MHz(100)/KHz(1)/10;
6563 fdi_dotclock
= adjusted_mode
->crtc_clock
;
6565 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
6566 pipe_config
->pipe_bpp
);
6568 pipe_config
->fdi_lanes
= lane
;
6570 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
6571 link_bw
, &pipe_config
->fdi_m_n
);
6573 ret
= ironlake_check_fdi_lanes(intel_crtc
->base
.dev
,
6574 intel_crtc
->pipe
, pipe_config
);
6575 if (ret
== -EINVAL
&& pipe_config
->pipe_bpp
> 6*3) {
6576 pipe_config
->pipe_bpp
-= 2*3;
6577 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6578 pipe_config
->pipe_bpp
);
6579 needs_recompute
= true;
6580 pipe_config
->bw_constrained
= true;
6585 if (needs_recompute
)
6591 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
6592 struct intel_crtc_state
*pipe_config
)
6594 pipe_config
->ips_enabled
= i915
.enable_ips
&&
6595 hsw_crtc_supports_ips(crtc
) &&
6596 pipe_config
->pipe_bpp
<= 24;
6599 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
6600 struct intel_crtc_state
*pipe_config
)
6602 struct drm_device
*dev
= crtc
->base
.dev
;
6603 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6604 struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6607 /* FIXME should check pixel clock limits on all platforms */
6608 if (INTEL_INFO(dev
)->gen
< 4) {
6610 dev_priv
->display
.get_display_clock_speed(dev
);
6613 * Enable pixel doubling when the dot clock
6614 * is > 90% of the (display) core speed.
6616 * GDG double wide on either pipe,
6617 * otherwise pipe A only.
6619 if ((crtc
->pipe
== PIPE_A
|| IS_I915G(dev
)) &&
6620 adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10) {
6622 pipe_config
->double_wide
= true;
6625 if (adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10)
6630 * Pipe horizontal size must be even in:
6632 * - LVDS dual channel mode
6633 * - Double wide pipe
6635 if ((intel_pipe_will_have_type(pipe_config
, INTEL_OUTPUT_LVDS
) &&
6636 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
6637 pipe_config
->pipe_src_w
&= ~1;
6639 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6640 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6642 if ((INTEL_INFO(dev
)->gen
> 4 || IS_G4X(dev
)) &&
6643 adjusted_mode
->hsync_start
== adjusted_mode
->hdisplay
)
6647 hsw_compute_ips_config(crtc
, pipe_config
);
6649 if (pipe_config
->has_pch_encoder
)
6650 return ironlake_fdi_compute_config(crtc
, pipe_config
);
6652 /* FIXME: remove below call once atomic mode set is place and all crtc
6653 * related checks called from atomic_crtc_check function */
6655 DRM_DEBUG_KMS("intel_crtc = %p drm_state (pipe_config->base.state) = %p\n",
6656 crtc
, pipe_config
->base
.state
);
6657 ret
= intel_atomic_setup_scalers(dev
, crtc
, pipe_config
);
6662 static int skylake_get_display_clock_speed(struct drm_device
*dev
)
6664 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6665 uint32_t lcpll1
= I915_READ(LCPLL1_CTL
);
6666 uint32_t cdctl
= I915_READ(CDCLK_CTL
);
6669 if (!(lcpll1
& LCPLL_PLL_ENABLE
)) {
6670 WARN(1, "LCPLL1 not enabled\n");
6671 return 24000; /* 24MHz is the cd freq with NSSC ref */
6674 if ((cdctl
& CDCLK_FREQ_SEL_MASK
) == CDCLK_FREQ_540
)
6677 linkrate
= (I915_READ(DPLL_CTRL1
) &
6678 DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
)) >> 1;
6680 if (linkrate
== DPLL_CTRL1_LINK_RATE_2160
||
6681 linkrate
== DPLL_CTRL1_LINK_RATE_1080
) {
6683 switch (cdctl
& CDCLK_FREQ_SEL_MASK
) {
6684 case CDCLK_FREQ_450_432
:
6686 case CDCLK_FREQ_337_308
:
6688 case CDCLK_FREQ_675_617
:
6691 WARN(1, "Unknown cd freq selection\n");
6695 switch (cdctl
& CDCLK_FREQ_SEL_MASK
) {
6696 case CDCLK_FREQ_450_432
:
6698 case CDCLK_FREQ_337_308
:
6700 case CDCLK_FREQ_675_617
:
6703 WARN(1, "Unknown cd freq selection\n");
6707 /* error case, do as if DPLL0 isn't enabled */
6711 static int broadwell_get_display_clock_speed(struct drm_device
*dev
)
6713 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6714 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
6715 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
6717 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
6719 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
6721 else if (freq
== LCPLL_CLK_FREQ_450
)
6723 else if (freq
== LCPLL_CLK_FREQ_54O_BDW
)
6725 else if (freq
== LCPLL_CLK_FREQ_337_5_BDW
)
6731 static int haswell_get_display_clock_speed(struct drm_device
*dev
)
6733 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6734 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
6735 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
6737 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
6739 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
6741 else if (freq
== LCPLL_CLK_FREQ_450
)
6743 else if (IS_HSW_ULT(dev
))
6749 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
6751 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6755 if (dev_priv
->hpll_freq
== 0)
6756 dev_priv
->hpll_freq
= valleyview_get_vco(dev_priv
);
6758 mutex_lock(&dev_priv
->dpio_lock
);
6759 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
6760 mutex_unlock(&dev_priv
->dpio_lock
);
6762 divider
= val
& DISPLAY_FREQUENCY_VALUES
;
6764 WARN((val
& DISPLAY_FREQUENCY_STATUS
) !=
6765 (divider
<< DISPLAY_FREQUENCY_STATUS_SHIFT
),
6766 "cdclk change in progress\n");
6768 return DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, divider
+ 1);
6771 static int ilk_get_display_clock_speed(struct drm_device
*dev
)
6776 static int i945_get_display_clock_speed(struct drm_device
*dev
)
6781 static int i915_get_display_clock_speed(struct drm_device
*dev
)
6786 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
6791 static int pnv_get_display_clock_speed(struct drm_device
*dev
)
6795 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
6797 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
6798 case GC_DISPLAY_CLOCK_267_MHZ_PNV
:
6800 case GC_DISPLAY_CLOCK_333_MHZ_PNV
:
6802 case GC_DISPLAY_CLOCK_444_MHZ_PNV
:
6804 case GC_DISPLAY_CLOCK_200_MHZ_PNV
:
6807 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc
);
6808 case GC_DISPLAY_CLOCK_133_MHZ_PNV
:
6810 case GC_DISPLAY_CLOCK_167_MHZ_PNV
:
6815 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
6819 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
6821 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
6824 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
6825 case GC_DISPLAY_CLOCK_333_MHZ
:
6828 case GC_DISPLAY_CLOCK_190_200_MHZ
:
6834 static int i865_get_display_clock_speed(struct drm_device
*dev
)
6839 static int i855_get_display_clock_speed(struct drm_device
*dev
)
6842 /* Assume that the hardware is in the high speed state. This
6843 * should be the default.
6845 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
6846 case GC_CLOCK_133_200
:
6847 case GC_CLOCK_100_200
:
6849 case GC_CLOCK_166_250
:
6851 case GC_CLOCK_100_133
:
6855 /* Shouldn't happen */
6859 static int i830_get_display_clock_speed(struct drm_device
*dev
)
6865 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
6867 while (*num
> DATA_LINK_M_N_MASK
||
6868 *den
> DATA_LINK_M_N_MASK
) {
6874 static void compute_m_n(unsigned int m
, unsigned int n
,
6875 uint32_t *ret_m
, uint32_t *ret_n
)
6877 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
6878 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
6879 intel_reduce_m_n_ratio(ret_m
, ret_n
);
6883 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
6884 int pixel_clock
, int link_clock
,
6885 struct intel_link_m_n
*m_n
)
6889 compute_m_n(bits_per_pixel
* pixel_clock
,
6890 link_clock
* nlanes
* 8,
6891 &m_n
->gmch_m
, &m_n
->gmch_n
);
6893 compute_m_n(pixel_clock
, link_clock
,
6894 &m_n
->link_m
, &m_n
->link_n
);
6897 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
6899 if (i915
.panel_use_ssc
>= 0)
6900 return i915
.panel_use_ssc
!= 0;
6901 return dev_priv
->vbt
.lvds_use_ssc
6902 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
6905 static int i9xx_get_refclk(const struct intel_crtc_state
*crtc_state
,
6908 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
6909 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6912 WARN_ON(!crtc_state
->base
.state
);
6914 if (IS_VALLEYVIEW(dev
) || IS_BROXTON(dev
)) {
6916 } else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6917 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
6918 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
6919 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
6920 } else if (!IS_GEN2(dev
)) {
6929 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
6931 return (1 << dpll
->n
) << 16 | dpll
->m2
;
6934 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
6936 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
6939 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
6940 struct intel_crtc_state
*crtc_state
,
6941 intel_clock_t
*reduced_clock
)
6943 struct drm_device
*dev
= crtc
->base
.dev
;
6946 if (IS_PINEVIEW(dev
)) {
6947 fp
= pnv_dpll_compute_fp(&crtc_state
->dpll
);
6949 fp2
= pnv_dpll_compute_fp(reduced_clock
);
6951 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
6953 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
6956 crtc_state
->dpll_hw_state
.fp0
= fp
;
6958 crtc
->lowfreq_avail
= false;
6959 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6961 crtc_state
->dpll_hw_state
.fp1
= fp2
;
6962 crtc
->lowfreq_avail
= true;
6964 crtc_state
->dpll_hw_state
.fp1
= fp
;
6968 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
6974 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6975 * and set it to a reasonable value instead.
6977 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6978 reg_val
&= 0xffffff00;
6979 reg_val
|= 0x00000030;
6980 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6982 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6983 reg_val
&= 0x8cffffff;
6984 reg_val
= 0x8c000000;
6985 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6987 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6988 reg_val
&= 0xffffff00;
6989 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6991 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6992 reg_val
&= 0x00ffffff;
6993 reg_val
|= 0xb0000000;
6994 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6997 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
6998 struct intel_link_m_n
*m_n
)
7000 struct drm_device
*dev
= crtc
->base
.dev
;
7001 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7002 int pipe
= crtc
->pipe
;
7004 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
7005 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
7006 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
7007 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
7010 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
7011 struct intel_link_m_n
*m_n
,
7012 struct intel_link_m_n
*m2_n2
)
7014 struct drm_device
*dev
= crtc
->base
.dev
;
7015 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7016 int pipe
= crtc
->pipe
;
7017 enum transcoder transcoder
= crtc
->config
->cpu_transcoder
;
7019 if (INTEL_INFO(dev
)->gen
>= 5) {
7020 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
7021 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
7022 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
7023 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
7024 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
7025 * for gen < 8) and if DRRS is supported (to make sure the
7026 * registers are not unnecessarily accessed).
7028 if (m2_n2
&& (IS_CHERRYVIEW(dev
) || INTEL_INFO(dev
)->gen
< 8) &&
7029 crtc
->config
->has_drrs
) {
7030 I915_WRITE(PIPE_DATA_M2(transcoder
),
7031 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
7032 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
7033 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
7034 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
7037 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
7038 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
7039 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
7040 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
7044 void intel_dp_set_m_n(struct intel_crtc
*crtc
, enum link_m_n_set m_n
)
7046 struct intel_link_m_n
*dp_m_n
, *dp_m2_n2
= NULL
;
7049 dp_m_n
= &crtc
->config
->dp_m_n
;
7050 dp_m2_n2
= &crtc
->config
->dp_m2_n2
;
7051 } else if (m_n
== M2_N2
) {
7054 * M2_N2 registers are not supported. Hence m2_n2 divider value
7055 * needs to be programmed into M1_N1.
7057 dp_m_n
= &crtc
->config
->dp_m2_n2
;
7059 DRM_ERROR("Unsupported divider value\n");
7063 if (crtc
->config
->has_pch_encoder
)
7064 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
->dp_m_n
);
7066 intel_cpu_transcoder_set_m_n(crtc
, dp_m_n
, dp_m2_n2
);
7069 static void vlv_update_pll(struct intel_crtc
*crtc
,
7070 struct intel_crtc_state
*pipe_config
)
7075 * Enable DPIO clock input. We should never disable the reference
7076 * clock for pipe B, since VGA hotplug / manual detection depends
7079 dpll
= DPLL_EXT_BUFFER_ENABLE_VLV
| DPLL_REFA_CLK_ENABLE_VLV
|
7080 DPLL_VGA_MODE_DIS
| DPLL_INTEGRATED_CLOCK_VLV
;
7081 /* We should never disable this, set it here for state tracking */
7082 if (crtc
->pipe
== PIPE_B
)
7083 dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
7084 dpll
|= DPLL_VCO_ENABLE
;
7085 pipe_config
->dpll_hw_state
.dpll
= dpll
;
7087 dpll_md
= (pipe_config
->pixel_multiplier
- 1)
7088 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
7089 pipe_config
->dpll_hw_state
.dpll_md
= dpll_md
;
7092 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
7093 const struct intel_crtc_state
*pipe_config
)
7095 struct drm_device
*dev
= crtc
->base
.dev
;
7096 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7097 int pipe
= crtc
->pipe
;
7099 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
7100 u32 coreclk
, reg_val
;
7102 mutex_lock(&dev_priv
->dpio_lock
);
7104 bestn
= pipe_config
->dpll
.n
;
7105 bestm1
= pipe_config
->dpll
.m1
;
7106 bestm2
= pipe_config
->dpll
.m2
;
7107 bestp1
= pipe_config
->dpll
.p1
;
7108 bestp2
= pipe_config
->dpll
.p2
;
7110 /* See eDP HDMI DPIO driver vbios notes doc */
7112 /* PLL B needs special handling */
7114 vlv_pllb_recal_opamp(dev_priv
, pipe
);
7116 /* Set up Tx target for periodic Rcomp update */
7117 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
7119 /* Disable target IRef on PLL */
7120 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
7121 reg_val
&= 0x00ffffff;
7122 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
7124 /* Disable fast lock */
7125 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
7127 /* Set idtafcrecal before PLL is enabled */
7128 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
7129 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
7130 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
7131 mdiv
|= (1 << DPIO_K_SHIFT
);
7134 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7135 * but we don't support that).
7136 * Note: don't use the DAC post divider as it seems unstable.
7138 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
7139 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
7141 mdiv
|= DPIO_ENABLE_CALIBRATION
;
7142 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
7144 /* Set HBR and RBR LPF coefficients */
7145 if (pipe_config
->port_clock
== 162000 ||
7146 intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
) ||
7147 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
))
7148 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
7151 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
7154 if (pipe_config
->has_dp_encoder
) {
7155 /* Use SSC source */
7157 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7160 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7162 } else { /* HDMI or VGA */
7163 /* Use bend source */
7165 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7168 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
7172 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
7173 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
7174 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
7175 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))
7176 coreclk
|= 0x01000000;
7177 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
7179 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
7180 mutex_unlock(&dev_priv
->dpio_lock
);
7183 static void chv_update_pll(struct intel_crtc
*crtc
,
7184 struct intel_crtc_state
*pipe_config
)
7186 pipe_config
->dpll_hw_state
.dpll
= DPLL_SSC_REF_CLOCK_CHV
|
7187 DPLL_REFA_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
|
7189 if (crtc
->pipe
!= PIPE_A
)
7190 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
7192 pipe_config
->dpll_hw_state
.dpll_md
=
7193 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
7196 static void chv_prepare_pll(struct intel_crtc
*crtc
,
7197 const struct intel_crtc_state
*pipe_config
)
7199 struct drm_device
*dev
= crtc
->base
.dev
;
7200 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7201 int pipe
= crtc
->pipe
;
7202 int dpll_reg
= DPLL(crtc
->pipe
);
7203 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
7204 u32 loopfilter
, tribuf_calcntr
;
7205 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
7209 bestn
= pipe_config
->dpll
.n
;
7210 bestm2_frac
= pipe_config
->dpll
.m2
& 0x3fffff;
7211 bestm1
= pipe_config
->dpll
.m1
;
7212 bestm2
= pipe_config
->dpll
.m2
>> 22;
7213 bestp1
= pipe_config
->dpll
.p1
;
7214 bestp2
= pipe_config
->dpll
.p2
;
7215 vco
= pipe_config
->dpll
.vco
;
7220 * Enable Refclk and SSC
7222 I915_WRITE(dpll_reg
,
7223 pipe_config
->dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
7225 mutex_lock(&dev_priv
->dpio_lock
);
7227 /* p1 and p2 divider */
7228 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
7229 5 << DPIO_CHV_S1_DIV_SHIFT
|
7230 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
7231 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
7232 1 << DPIO_CHV_K_DIV_SHIFT
);
7234 /* Feedback post-divider - m2 */
7235 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
7237 /* Feedback refclk divider - n and m1 */
7238 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
7239 DPIO_CHV_M1_DIV_BY_2
|
7240 1 << DPIO_CHV_N_DIV_SHIFT
);
7242 /* M2 fraction division */
7244 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
7246 /* M2 fraction division enable */
7247 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
7248 dpio_val
&= ~(DPIO_CHV_FEEDFWD_GAIN_MASK
| DPIO_CHV_FRAC_DIV_EN
);
7249 dpio_val
|= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
);
7251 dpio_val
|= DPIO_CHV_FRAC_DIV_EN
;
7252 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
), dpio_val
);
7254 /* Program digital lock detect threshold */
7255 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW9(port
));
7256 dpio_val
&= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK
|
7257 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
);
7258 dpio_val
|= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT
);
7260 dpio_val
|= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
;
7261 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW9(port
), dpio_val
);
7264 if (vco
== 5400000) {
7265 loopfilter
|= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT
);
7266 loopfilter
|= (0x8 << DPIO_CHV_INT_COEFF_SHIFT
);
7267 loopfilter
|= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7268 tribuf_calcntr
= 0x9;
7269 } else if (vco
<= 6200000) {
7270 loopfilter
|= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT
);
7271 loopfilter
|= (0xB << DPIO_CHV_INT_COEFF_SHIFT
);
7272 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7273 tribuf_calcntr
= 0x9;
7274 } else if (vco
<= 6480000) {
7275 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
7276 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
7277 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7278 tribuf_calcntr
= 0x8;
7280 /* Not supported. Apply the same limits as in the max case */
7281 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
7282 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
7283 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7286 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
7288 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW8(port
));
7289 dpio_val
&= ~DPIO_CHV_TDC_TARGET_CNT_MASK
;
7290 dpio_val
|= (tribuf_calcntr
<< DPIO_CHV_TDC_TARGET_CNT_SHIFT
);
7291 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW8(port
), dpio_val
);
7294 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
7295 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
7298 mutex_unlock(&dev_priv
->dpio_lock
);
7302 * vlv_force_pll_on - forcibly enable just the PLL
7303 * @dev_priv: i915 private structure
7304 * @pipe: pipe PLL to enable
7305 * @dpll: PLL configuration
7307 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7308 * in cases where we need the PLL enabled even when @pipe is not going to
7311 void vlv_force_pll_on(struct drm_device
*dev
, enum pipe pipe
,
7312 const struct dpll
*dpll
)
7314 struct intel_crtc
*crtc
=
7315 to_intel_crtc(intel_get_crtc_for_pipe(dev
, pipe
));
7316 struct intel_crtc_state pipe_config
= {
7317 .base
.crtc
= &crtc
->base
,
7318 .pixel_multiplier
= 1,
7322 if (IS_CHERRYVIEW(dev
)) {
7323 chv_update_pll(crtc
, &pipe_config
);
7324 chv_prepare_pll(crtc
, &pipe_config
);
7325 chv_enable_pll(crtc
, &pipe_config
);
7327 vlv_update_pll(crtc
, &pipe_config
);
7328 vlv_prepare_pll(crtc
, &pipe_config
);
7329 vlv_enable_pll(crtc
, &pipe_config
);
7334 * vlv_force_pll_off - forcibly disable just the PLL
7335 * @dev_priv: i915 private structure
7336 * @pipe: pipe PLL to disable
7338 * Disable the PLL for @pipe. To be used in cases where we need
7339 * the PLL enabled even when @pipe is not going to be enabled.
7341 void vlv_force_pll_off(struct drm_device
*dev
, enum pipe pipe
)
7343 if (IS_CHERRYVIEW(dev
))
7344 chv_disable_pll(to_i915(dev
), pipe
);
7346 vlv_disable_pll(to_i915(dev
), pipe
);
7349 static void i9xx_update_pll(struct intel_crtc
*crtc
,
7350 struct intel_crtc_state
*crtc_state
,
7351 intel_clock_t
*reduced_clock
,
7354 struct drm_device
*dev
= crtc
->base
.dev
;
7355 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7358 struct dpll
*clock
= &crtc_state
->dpll
;
7360 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
7362 is_sdvo
= intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
7363 intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_HDMI
);
7365 dpll
= DPLL_VGA_MODE_DIS
;
7367 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
))
7368 dpll
|= DPLLB_MODE_LVDS
;
7370 dpll
|= DPLLB_MODE_DAC_SERIAL
;
7372 if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
7373 dpll
|= (crtc_state
->pixel_multiplier
- 1)
7374 << SDVO_MULTIPLIER_SHIFT_HIRES
;
7378 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7380 if (crtc_state
->has_dp_encoder
)
7381 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7383 /* compute bitmask from p1 value */
7384 if (IS_PINEVIEW(dev
))
7385 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
7387 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7388 if (IS_G4X(dev
) && reduced_clock
)
7389 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
7391 switch (clock
->p2
) {
7393 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
7396 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
7399 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
7402 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
7405 if (INTEL_INFO(dev
)->gen
>= 4)
7406 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
7408 if (crtc_state
->sdvo_tv_clock
)
7409 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
7410 else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
7411 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
7412 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7414 dpll
|= PLL_REF_INPUT_DREFCLK
;
7416 dpll
|= DPLL_VCO_ENABLE
;
7417 crtc_state
->dpll_hw_state
.dpll
= dpll
;
7419 if (INTEL_INFO(dev
)->gen
>= 4) {
7420 u32 dpll_md
= (crtc_state
->pixel_multiplier
- 1)
7421 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
7422 crtc_state
->dpll_hw_state
.dpll_md
= dpll_md
;
7426 static void i8xx_update_pll(struct intel_crtc
*crtc
,
7427 struct intel_crtc_state
*crtc_state
,
7428 intel_clock_t
*reduced_clock
,
7431 struct drm_device
*dev
= crtc
->base
.dev
;
7432 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7434 struct dpll
*clock
= &crtc_state
->dpll
;
7436 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
7438 dpll
= DPLL_VGA_MODE_DIS
;
7440 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7441 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7444 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
7446 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7448 dpll
|= PLL_P2_DIVIDE_BY_4
;
7451 if (!IS_I830(dev
) && intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_DVO
))
7452 dpll
|= DPLL_DVO_2X_MODE
;
7454 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
7455 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
7456 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7458 dpll
|= PLL_REF_INPUT_DREFCLK
;
7460 dpll
|= DPLL_VCO_ENABLE
;
7461 crtc_state
->dpll_hw_state
.dpll
= dpll
;
7464 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
7466 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7467 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7468 enum pipe pipe
= intel_crtc
->pipe
;
7469 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
7470 struct drm_display_mode
*adjusted_mode
=
7471 &intel_crtc
->config
->base
.adjusted_mode
;
7472 uint32_t crtc_vtotal
, crtc_vblank_end
;
7475 /* We need to be careful not to changed the adjusted mode, for otherwise
7476 * the hw state checker will get angry at the mismatch. */
7477 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
7478 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
7480 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
7481 /* the chip adds 2 halflines automatically */
7483 crtc_vblank_end
-= 1;
7485 if (intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
7486 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
7488 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
7489 adjusted_mode
->crtc_htotal
/ 2;
7491 vsyncshift
+= adjusted_mode
->crtc_htotal
;
7494 if (INTEL_INFO(dev
)->gen
> 3)
7495 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
7497 I915_WRITE(HTOTAL(cpu_transcoder
),
7498 (adjusted_mode
->crtc_hdisplay
- 1) |
7499 ((adjusted_mode
->crtc_htotal
- 1) << 16));
7500 I915_WRITE(HBLANK(cpu_transcoder
),
7501 (adjusted_mode
->crtc_hblank_start
- 1) |
7502 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
7503 I915_WRITE(HSYNC(cpu_transcoder
),
7504 (adjusted_mode
->crtc_hsync_start
- 1) |
7505 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
7507 I915_WRITE(VTOTAL(cpu_transcoder
),
7508 (adjusted_mode
->crtc_vdisplay
- 1) |
7509 ((crtc_vtotal
- 1) << 16));
7510 I915_WRITE(VBLANK(cpu_transcoder
),
7511 (adjusted_mode
->crtc_vblank_start
- 1) |
7512 ((crtc_vblank_end
- 1) << 16));
7513 I915_WRITE(VSYNC(cpu_transcoder
),
7514 (adjusted_mode
->crtc_vsync_start
- 1) |
7515 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
7517 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7518 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7519 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7521 if (IS_HASWELL(dev
) && cpu_transcoder
== TRANSCODER_EDP
&&
7522 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
7523 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
7525 /* pipesrc controls the size that is scaled from, which should
7526 * always be the user's requested size.
7528 I915_WRITE(PIPESRC(pipe
),
7529 ((intel_crtc
->config
->pipe_src_w
- 1) << 16) |
7530 (intel_crtc
->config
->pipe_src_h
- 1));
7533 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
7534 struct intel_crtc_state
*pipe_config
)
7536 struct drm_device
*dev
= crtc
->base
.dev
;
7537 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7538 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
7541 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
7542 pipe_config
->base
.adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
7543 pipe_config
->base
.adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
7544 tmp
= I915_READ(HBLANK(cpu_transcoder
));
7545 pipe_config
->base
.adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
7546 pipe_config
->base
.adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
7547 tmp
= I915_READ(HSYNC(cpu_transcoder
));
7548 pipe_config
->base
.adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
7549 pipe_config
->base
.adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
7551 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
7552 pipe_config
->base
.adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
7553 pipe_config
->base
.adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
7554 tmp
= I915_READ(VBLANK(cpu_transcoder
));
7555 pipe_config
->base
.adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
7556 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
7557 tmp
= I915_READ(VSYNC(cpu_transcoder
));
7558 pipe_config
->base
.adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
7559 pipe_config
->base
.adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
7561 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
7562 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
7563 pipe_config
->base
.adjusted_mode
.crtc_vtotal
+= 1;
7564 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
+= 1;
7567 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
7568 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
7569 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
7571 pipe_config
->base
.mode
.vdisplay
= pipe_config
->pipe_src_h
;
7572 pipe_config
->base
.mode
.hdisplay
= pipe_config
->pipe_src_w
;
7575 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
7576 struct intel_crtc_state
*pipe_config
)
7578 mode
->hdisplay
= pipe_config
->base
.adjusted_mode
.crtc_hdisplay
;
7579 mode
->htotal
= pipe_config
->base
.adjusted_mode
.crtc_htotal
;
7580 mode
->hsync_start
= pipe_config
->base
.adjusted_mode
.crtc_hsync_start
;
7581 mode
->hsync_end
= pipe_config
->base
.adjusted_mode
.crtc_hsync_end
;
7583 mode
->vdisplay
= pipe_config
->base
.adjusted_mode
.crtc_vdisplay
;
7584 mode
->vtotal
= pipe_config
->base
.adjusted_mode
.crtc_vtotal
;
7585 mode
->vsync_start
= pipe_config
->base
.adjusted_mode
.crtc_vsync_start
;
7586 mode
->vsync_end
= pipe_config
->base
.adjusted_mode
.crtc_vsync_end
;
7588 mode
->flags
= pipe_config
->base
.adjusted_mode
.flags
;
7590 mode
->clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
7591 mode
->flags
|= pipe_config
->base
.adjusted_mode
.flags
;
7594 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
7596 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7597 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7602 if ((intel_crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
7603 (intel_crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
7604 pipeconf
|= I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
;
7606 if (intel_crtc
->config
->double_wide
)
7607 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
7609 /* only g4x and later have fancy bpc/dither controls */
7610 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
7611 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7612 if (intel_crtc
->config
->dither
&& intel_crtc
->config
->pipe_bpp
!= 30)
7613 pipeconf
|= PIPECONF_DITHER_EN
|
7614 PIPECONF_DITHER_TYPE_SP
;
7616 switch (intel_crtc
->config
->pipe_bpp
) {
7618 pipeconf
|= PIPECONF_6BPC
;
7621 pipeconf
|= PIPECONF_8BPC
;
7624 pipeconf
|= PIPECONF_10BPC
;
7627 /* Case prevented by intel_choose_pipe_bpp_dither. */
7632 if (HAS_PIPE_CXSR(dev
)) {
7633 if (intel_crtc
->lowfreq_avail
) {
7634 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
7635 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
7637 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
7641 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
7642 if (INTEL_INFO(dev
)->gen
< 4 ||
7643 intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
7644 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
7646 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
7648 pipeconf
|= PIPECONF_PROGRESSIVE
;
7650 if (IS_VALLEYVIEW(dev
) && intel_crtc
->config
->limited_color_range
)
7651 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
7653 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
7654 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
7657 static int i9xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7658 struct intel_crtc_state
*crtc_state
)
7660 struct drm_device
*dev
= crtc
->base
.dev
;
7661 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7662 int refclk
, num_connectors
= 0;
7663 intel_clock_t clock
, reduced_clock
;
7664 bool ok
, has_reduced_clock
= false;
7665 bool is_lvds
= false, is_dsi
= false;
7666 struct intel_encoder
*encoder
;
7667 const intel_limit_t
*limit
;
7668 struct drm_atomic_state
*state
= crtc_state
->base
.state
;
7669 struct drm_connector
*connector
;
7670 struct drm_connector_state
*connector_state
;
7673 memset(&crtc_state
->dpll_hw_state
, 0,
7674 sizeof(crtc_state
->dpll_hw_state
));
7676 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
7677 if (connector_state
->crtc
!= &crtc
->base
)
7680 encoder
= to_intel_encoder(connector_state
->best_encoder
);
7682 switch (encoder
->type
) {
7683 case INTEL_OUTPUT_LVDS
:
7686 case INTEL_OUTPUT_DSI
:
7699 if (!crtc_state
->clock_set
) {
7700 refclk
= i9xx_get_refclk(crtc_state
, num_connectors
);
7703 * Returns a set of divisors for the desired target clock with
7704 * the given refclk, or FALSE. The returned values represent
7705 * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
7708 limit
= intel_limit(crtc_state
, refclk
);
7709 ok
= dev_priv
->display
.find_dpll(limit
, crtc_state
,
7710 crtc_state
->port_clock
,
7711 refclk
, NULL
, &clock
);
7713 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7717 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
7719 * Ensure we match the reduced clock's P to the target
7720 * clock. If the clocks don't match, we can't switch
7721 * the display clock by using the FP0/FP1. In such case
7722 * we will disable the LVDS downclock feature.
7725 dev_priv
->display
.find_dpll(limit
, crtc_state
,
7726 dev_priv
->lvds_downclock
,
7730 /* Compat-code for transition, will disappear. */
7731 crtc_state
->dpll
.n
= clock
.n
;
7732 crtc_state
->dpll
.m1
= clock
.m1
;
7733 crtc_state
->dpll
.m2
= clock
.m2
;
7734 crtc_state
->dpll
.p1
= clock
.p1
;
7735 crtc_state
->dpll
.p2
= clock
.p2
;
7739 i8xx_update_pll(crtc
, crtc_state
,
7740 has_reduced_clock
? &reduced_clock
: NULL
,
7742 } else if (IS_CHERRYVIEW(dev
)) {
7743 chv_update_pll(crtc
, crtc_state
);
7744 } else if (IS_VALLEYVIEW(dev
)) {
7745 vlv_update_pll(crtc
, crtc_state
);
7747 i9xx_update_pll(crtc
, crtc_state
,
7748 has_reduced_clock
? &reduced_clock
: NULL
,
7755 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
7756 struct intel_crtc_state
*pipe_config
)
7758 struct drm_device
*dev
= crtc
->base
.dev
;
7759 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7762 if (INTEL_INFO(dev
)->gen
<= 3 && (IS_I830(dev
) || !IS_MOBILE(dev
)))
7765 tmp
= I915_READ(PFIT_CONTROL
);
7766 if (!(tmp
& PFIT_ENABLE
))
7769 /* Check whether the pfit is attached to our pipe. */
7770 if (INTEL_INFO(dev
)->gen
< 4) {
7771 if (crtc
->pipe
!= PIPE_B
)
7774 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
7778 pipe_config
->gmch_pfit
.control
= tmp
;
7779 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
7780 if (INTEL_INFO(dev
)->gen
< 5)
7781 pipe_config
->gmch_pfit
.lvds_border_bits
=
7782 I915_READ(LVDS
) & LVDS_BORDER_ENABLE
;
7785 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
7786 struct intel_crtc_state
*pipe_config
)
7788 struct drm_device
*dev
= crtc
->base
.dev
;
7789 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7790 int pipe
= pipe_config
->cpu_transcoder
;
7791 intel_clock_t clock
;
7793 int refclk
= 100000;
7795 /* In case of MIPI DPLL will not even be used */
7796 if (!(pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
))
7799 mutex_lock(&dev_priv
->dpio_lock
);
7800 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
7801 mutex_unlock(&dev_priv
->dpio_lock
);
7803 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
7804 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
7805 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
7806 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
7807 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
7809 vlv_clock(refclk
, &clock
);
7811 /* clock.dot is the fast clock */
7812 pipe_config
->port_clock
= clock
.dot
/ 5;
7816 i9xx_get_initial_plane_config(struct intel_crtc
*crtc
,
7817 struct intel_initial_plane_config
*plane_config
)
7819 struct drm_device
*dev
= crtc
->base
.dev
;
7820 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7821 u32 val
, base
, offset
;
7822 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
7823 int fourcc
, pixel_format
;
7824 unsigned int aligned_height
;
7825 struct drm_framebuffer
*fb
;
7826 struct intel_framebuffer
*intel_fb
;
7828 val
= I915_READ(DSPCNTR(plane
));
7829 if (!(val
& DISPLAY_PLANE_ENABLE
))
7832 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
7834 DRM_DEBUG_KMS("failed to alloc fb\n");
7838 fb
= &intel_fb
->base
;
7840 if (INTEL_INFO(dev
)->gen
>= 4) {
7841 if (val
& DISPPLANE_TILED
) {
7842 plane_config
->tiling
= I915_TILING_X
;
7843 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
7847 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
7848 fourcc
= i9xx_format_to_fourcc(pixel_format
);
7849 fb
->pixel_format
= fourcc
;
7850 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
7852 if (INTEL_INFO(dev
)->gen
>= 4) {
7853 if (plane_config
->tiling
)
7854 offset
= I915_READ(DSPTILEOFF(plane
));
7856 offset
= I915_READ(DSPLINOFF(plane
));
7857 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
7859 base
= I915_READ(DSPADDR(plane
));
7861 plane_config
->base
= base
;
7863 val
= I915_READ(PIPESRC(pipe
));
7864 fb
->width
= ((val
>> 16) & 0xfff) + 1;
7865 fb
->height
= ((val
>> 0) & 0xfff) + 1;
7867 val
= I915_READ(DSPSTRIDE(pipe
));
7868 fb
->pitches
[0] = val
& 0xffffffc0;
7870 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
7874 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
7876 DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7877 pipe_name(pipe
), plane
, fb
->width
, fb
->height
,
7878 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
7879 plane_config
->size
);
7881 plane_config
->fb
= intel_fb
;
7884 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
7885 struct intel_crtc_state
*pipe_config
)
7887 struct drm_device
*dev
= crtc
->base
.dev
;
7888 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7889 int pipe
= pipe_config
->cpu_transcoder
;
7890 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
7891 intel_clock_t clock
;
7892 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
;
7893 int refclk
= 100000;
7895 mutex_lock(&dev_priv
->dpio_lock
);
7896 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
7897 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
7898 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
7899 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
7900 mutex_unlock(&dev_priv
->dpio_lock
);
7902 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
7903 clock
.m2
= ((pll_dw0
& 0xff) << 22) | (pll_dw2
& 0x3fffff);
7904 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
7905 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
7906 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
7908 chv_clock(refclk
, &clock
);
7910 /* clock.dot is the fast clock */
7911 pipe_config
->port_clock
= clock
.dot
/ 5;
7914 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
7915 struct intel_crtc_state
*pipe_config
)
7917 struct drm_device
*dev
= crtc
->base
.dev
;
7918 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7921 if (!intel_display_power_is_enabled(dev_priv
,
7922 POWER_DOMAIN_PIPE(crtc
->pipe
)))
7925 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7926 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
7928 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
7929 if (!(tmp
& PIPECONF_ENABLE
))
7932 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
7933 switch (tmp
& PIPECONF_BPC_MASK
) {
7935 pipe_config
->pipe_bpp
= 18;
7938 pipe_config
->pipe_bpp
= 24;
7940 case PIPECONF_10BPC
:
7941 pipe_config
->pipe_bpp
= 30;
7948 if (IS_VALLEYVIEW(dev
) && (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
7949 pipe_config
->limited_color_range
= true;
7951 if (INTEL_INFO(dev
)->gen
< 4)
7952 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
7954 intel_get_pipe_timings(crtc
, pipe_config
);
7956 i9xx_get_pfit_config(crtc
, pipe_config
);
7958 if (INTEL_INFO(dev
)->gen
>= 4) {
7959 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
7960 pipe_config
->pixel_multiplier
=
7961 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
7962 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
7963 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
7964 } else if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
7965 tmp
= I915_READ(DPLL(crtc
->pipe
));
7966 pipe_config
->pixel_multiplier
=
7967 ((tmp
& SDVO_MULTIPLIER_MASK
)
7968 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
7970 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7971 * port and will be fixed up in the encoder->get_config
7973 pipe_config
->pixel_multiplier
= 1;
7975 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
7976 if (!IS_VALLEYVIEW(dev
)) {
7978 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
7979 * on 830. Filter it out here so that we don't
7980 * report errors due to that.
7983 pipe_config
->dpll_hw_state
.dpll
&= ~DPLL_DVO_2X_MODE
;
7985 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
7986 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
7988 /* Mask out read-only status bits. */
7989 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
7990 DPLL_PORTC_READY_MASK
|
7991 DPLL_PORTB_READY_MASK
);
7994 if (IS_CHERRYVIEW(dev
))
7995 chv_crtc_clock_get(crtc
, pipe_config
);
7996 else if (IS_VALLEYVIEW(dev
))
7997 vlv_crtc_clock_get(crtc
, pipe_config
);
7999 i9xx_crtc_clock_get(crtc
, pipe_config
);
8004 static void ironlake_init_pch_refclk(struct drm_device
*dev
)
8006 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8007 struct intel_encoder
*encoder
;
8009 bool has_lvds
= false;
8010 bool has_cpu_edp
= false;
8011 bool has_panel
= false;
8012 bool has_ck505
= false;
8013 bool can_ssc
= false;
8015 /* We need to take the global config into account */
8016 for_each_intel_encoder(dev
, encoder
) {
8017 switch (encoder
->type
) {
8018 case INTEL_OUTPUT_LVDS
:
8022 case INTEL_OUTPUT_EDP
:
8024 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
8032 if (HAS_PCH_IBX(dev
)) {
8033 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
8034 can_ssc
= has_ck505
;
8040 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
8041 has_panel
, has_lvds
, has_ck505
);
8043 /* Ironlake: try to setup display ref clock before DPLL
8044 * enabling. This is only under driver's control after
8045 * PCH B stepping, previous chipset stepping should be
8046 * ignoring this setting.
8048 val
= I915_READ(PCH_DREF_CONTROL
);
8050 /* As we must carefully and slowly disable/enable each source in turn,
8051 * compute the final state we want first and check if we need to
8052 * make any changes at all.
8055 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
8057 final
|= DREF_NONSPREAD_CK505_ENABLE
;
8059 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
8061 final
&= ~DREF_SSC_SOURCE_MASK
;
8062 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
8063 final
&= ~DREF_SSC1_ENABLE
;
8066 final
|= DREF_SSC_SOURCE_ENABLE
;
8068 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
8069 final
|= DREF_SSC1_ENABLE
;
8072 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
8073 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
8075 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
8077 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
8079 final
|= DREF_SSC_SOURCE_DISABLE
;
8080 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
8086 /* Always enable nonspread source */
8087 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
8090 val
|= DREF_NONSPREAD_CK505_ENABLE
;
8092 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
8095 val
&= ~DREF_SSC_SOURCE_MASK
;
8096 val
|= DREF_SSC_SOURCE_ENABLE
;
8098 /* SSC must be turned on before enabling the CPU output */
8099 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
8100 DRM_DEBUG_KMS("Using SSC on panel\n");
8101 val
|= DREF_SSC1_ENABLE
;
8103 val
&= ~DREF_SSC1_ENABLE
;
8105 /* Get SSC going before enabling the outputs */
8106 I915_WRITE(PCH_DREF_CONTROL
, val
);
8107 POSTING_READ(PCH_DREF_CONTROL
);
8110 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
8112 /* Enable CPU source on CPU attached eDP */
8114 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
8115 DRM_DEBUG_KMS("Using SSC on eDP\n");
8116 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
8118 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
8120 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
8122 I915_WRITE(PCH_DREF_CONTROL
, val
);
8123 POSTING_READ(PCH_DREF_CONTROL
);
8126 DRM_DEBUG_KMS("Disabling SSC entirely\n");
8128 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
8130 /* Turn off CPU output */
8131 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
8133 I915_WRITE(PCH_DREF_CONTROL
, val
);
8134 POSTING_READ(PCH_DREF_CONTROL
);
8137 /* Turn off the SSC source */
8138 val
&= ~DREF_SSC_SOURCE_MASK
;
8139 val
|= DREF_SSC_SOURCE_DISABLE
;
8142 val
&= ~DREF_SSC1_ENABLE
;
8144 I915_WRITE(PCH_DREF_CONTROL
, val
);
8145 POSTING_READ(PCH_DREF_CONTROL
);
8149 BUG_ON(val
!= final
);
8152 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
8156 tmp
= I915_READ(SOUTH_CHICKEN2
);
8157 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
8158 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
8160 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2
) &
8161 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
8162 DRM_ERROR("FDI mPHY reset assert timeout\n");
8164 tmp
= I915_READ(SOUTH_CHICKEN2
);
8165 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
8166 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
8168 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2
) &
8169 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
8170 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
8173 /* WaMPhyProgramming:hsw */
8174 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
8178 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
8179 tmp
&= ~(0xFF << 24);
8180 tmp
|= (0x12 << 24);
8181 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
8183 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
8185 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
8187 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
8189 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
8191 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
8192 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
8193 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
8195 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
8196 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
8197 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
8199 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
8202 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
8204 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
8207 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
8209 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
8212 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
8214 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
8217 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
8219 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
8220 tmp
&= ~(0xFF << 16);
8221 tmp
|= (0x1C << 16);
8222 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
8224 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
8225 tmp
&= ~(0xFF << 16);
8226 tmp
|= (0x1C << 16);
8227 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
8229 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
8231 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
8233 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
8235 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
8237 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
8238 tmp
&= ~(0xF << 28);
8240 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
8242 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
8243 tmp
&= ~(0xF << 28);
8245 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
8248 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8249 * Programming" based on the parameters passed:
8250 * - Sequence to enable CLKOUT_DP
8251 * - Sequence to enable CLKOUT_DP without spread
8252 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8254 static void lpt_enable_clkout_dp(struct drm_device
*dev
, bool with_spread
,
8257 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8260 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
8262 if (WARN(dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
&&
8263 with_fdi
, "LP PCH doesn't have FDI\n"))
8266 mutex_lock(&dev_priv
->dpio_lock
);
8268 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8269 tmp
&= ~SBI_SSCCTL_DISABLE
;
8270 tmp
|= SBI_SSCCTL_PATHALT
;
8271 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8276 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8277 tmp
&= ~SBI_SSCCTL_PATHALT
;
8278 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8281 lpt_reset_fdi_mphy(dev_priv
);
8282 lpt_program_fdi_mphy(dev_priv
);
8286 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
8287 SBI_GEN0
: SBI_DBUFF0
;
8288 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
8289 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
8290 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
8292 mutex_unlock(&dev_priv
->dpio_lock
);
8295 /* Sequence to disable CLKOUT_DP */
8296 static void lpt_disable_clkout_dp(struct drm_device
*dev
)
8298 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8301 mutex_lock(&dev_priv
->dpio_lock
);
8303 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
8304 SBI_GEN0
: SBI_DBUFF0
;
8305 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
8306 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
8307 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
8309 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8310 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
8311 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
8312 tmp
|= SBI_SSCCTL_PATHALT
;
8313 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8316 tmp
|= SBI_SSCCTL_DISABLE
;
8317 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8320 mutex_unlock(&dev_priv
->dpio_lock
);
8323 static void lpt_init_pch_refclk(struct drm_device
*dev
)
8325 struct intel_encoder
*encoder
;
8326 bool has_vga
= false;
8328 for_each_intel_encoder(dev
, encoder
) {
8329 switch (encoder
->type
) {
8330 case INTEL_OUTPUT_ANALOG
:
8339 lpt_enable_clkout_dp(dev
, true, true);
8341 lpt_disable_clkout_dp(dev
);
8345 * Initialize reference clocks when the driver loads
8347 void intel_init_pch_refclk(struct drm_device
*dev
)
8349 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
8350 ironlake_init_pch_refclk(dev
);
8351 else if (HAS_PCH_LPT(dev
))
8352 lpt_init_pch_refclk(dev
);
8355 static int ironlake_get_refclk(struct intel_crtc_state
*crtc_state
)
8357 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
8358 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8359 struct drm_atomic_state
*state
= crtc_state
->base
.state
;
8360 struct drm_connector
*connector
;
8361 struct drm_connector_state
*connector_state
;
8362 struct intel_encoder
*encoder
;
8363 int num_connectors
= 0, i
;
8364 bool is_lvds
= false;
8366 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
8367 if (connector_state
->crtc
!= crtc_state
->base
.crtc
)
8370 encoder
= to_intel_encoder(connector_state
->best_encoder
);
8372 switch (encoder
->type
) {
8373 case INTEL_OUTPUT_LVDS
:
8382 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
8383 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8384 dev_priv
->vbt
.lvds_ssc_freq
);
8385 return dev_priv
->vbt
.lvds_ssc_freq
;
8391 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
8393 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
8394 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8395 int pipe
= intel_crtc
->pipe
;
8400 switch (intel_crtc
->config
->pipe_bpp
) {
8402 val
|= PIPECONF_6BPC
;
8405 val
|= PIPECONF_8BPC
;
8408 val
|= PIPECONF_10BPC
;
8411 val
|= PIPECONF_12BPC
;
8414 /* Case prevented by intel_choose_pipe_bpp_dither. */
8418 if (intel_crtc
->config
->dither
)
8419 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
8421 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8422 val
|= PIPECONF_INTERLACED_ILK
;
8424 val
|= PIPECONF_PROGRESSIVE
;
8426 if (intel_crtc
->config
->limited_color_range
)
8427 val
|= PIPECONF_COLOR_RANGE_SELECT
;
8429 I915_WRITE(PIPECONF(pipe
), val
);
8430 POSTING_READ(PIPECONF(pipe
));
8434 * Set up the pipe CSC unit.
8436 * Currently only full range RGB to limited range RGB conversion
8437 * is supported, but eventually this should handle various
8438 * RGB<->YCbCr scenarios as well.
8440 static void intel_set_pipe_csc(struct drm_crtc
*crtc
)
8442 struct drm_device
*dev
= crtc
->dev
;
8443 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8444 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8445 int pipe
= intel_crtc
->pipe
;
8446 uint16_t coeff
= 0x7800; /* 1.0 */
8449 * TODO: Check what kind of values actually come out of the pipe
8450 * with these coeff/postoff values and adjust to get the best
8451 * accuracy. Perhaps we even need to take the bpc value into
8455 if (intel_crtc
->config
->limited_color_range
)
8456 coeff
= ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
8459 * GY/GU and RY/RU should be the other way around according
8460 * to BSpec, but reality doesn't agree. Just set them up in
8461 * a way that results in the correct picture.
8463 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe
), coeff
<< 16);
8464 I915_WRITE(PIPE_CSC_COEFF_BY(pipe
), 0);
8466 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe
), coeff
);
8467 I915_WRITE(PIPE_CSC_COEFF_BU(pipe
), 0);
8469 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe
), 0);
8470 I915_WRITE(PIPE_CSC_COEFF_BV(pipe
), coeff
<< 16);
8472 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe
), 0);
8473 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe
), 0);
8474 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe
), 0);
8476 if (INTEL_INFO(dev
)->gen
> 6) {
8477 uint16_t postoff
= 0;
8479 if (intel_crtc
->config
->limited_color_range
)
8480 postoff
= (16 * (1 << 12) / 255) & 0x1fff;
8482 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe
), postoff
);
8483 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe
), postoff
);
8484 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe
), postoff
);
8486 I915_WRITE(PIPE_CSC_MODE(pipe
), 0);
8488 uint32_t mode
= CSC_MODE_YUV_TO_RGB
;
8490 if (intel_crtc
->config
->limited_color_range
)
8491 mode
|= CSC_BLACK_SCREEN_OFFSET
;
8493 I915_WRITE(PIPE_CSC_MODE(pipe
), mode
);
8497 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
8499 struct drm_device
*dev
= crtc
->dev
;
8500 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8501 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8502 enum pipe pipe
= intel_crtc
->pipe
;
8503 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
8508 if (IS_HASWELL(dev
) && intel_crtc
->config
->dither
)
8509 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
8511 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8512 val
|= PIPECONF_INTERLACED_ILK
;
8514 val
|= PIPECONF_PROGRESSIVE
;
8516 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
8517 POSTING_READ(PIPECONF(cpu_transcoder
));
8519 I915_WRITE(GAMMA_MODE(intel_crtc
->pipe
), GAMMA_MODE_MODE_8BIT
);
8520 POSTING_READ(GAMMA_MODE(intel_crtc
->pipe
));
8522 if (IS_BROADWELL(dev
) || INTEL_INFO(dev
)->gen
>= 9) {
8525 switch (intel_crtc
->config
->pipe_bpp
) {
8527 val
|= PIPEMISC_DITHER_6_BPC
;
8530 val
|= PIPEMISC_DITHER_8_BPC
;
8533 val
|= PIPEMISC_DITHER_10_BPC
;
8536 val
|= PIPEMISC_DITHER_12_BPC
;
8539 /* Case prevented by pipe_config_set_bpp. */
8543 if (intel_crtc
->config
->dither
)
8544 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
8546 I915_WRITE(PIPEMISC(pipe
), val
);
8550 static bool ironlake_compute_clocks(struct drm_crtc
*crtc
,
8551 struct intel_crtc_state
*crtc_state
,
8552 intel_clock_t
*clock
,
8553 bool *has_reduced_clock
,
8554 intel_clock_t
*reduced_clock
)
8556 struct drm_device
*dev
= crtc
->dev
;
8557 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8559 const intel_limit_t
*limit
;
8560 bool ret
, is_lvds
= false;
8562 is_lvds
= intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
);
8564 refclk
= ironlake_get_refclk(crtc_state
);
8567 * Returns a set of divisors for the desired target clock with the given
8568 * refclk, or FALSE. The returned values represent the clock equation:
8569 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
8571 limit
= intel_limit(crtc_state
, refclk
);
8572 ret
= dev_priv
->display
.find_dpll(limit
, crtc_state
,
8573 crtc_state
->port_clock
,
8574 refclk
, NULL
, clock
);
8578 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
8580 * Ensure we match the reduced clock's P to the target clock.
8581 * If the clocks don't match, we can't switch the display clock
8582 * by using the FP0/FP1. In such case we will disable the LVDS
8583 * downclock feature.
8585 *has_reduced_clock
=
8586 dev_priv
->display
.find_dpll(limit
, crtc_state
,
8587 dev_priv
->lvds_downclock
,
8595 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
8598 * Account for spread spectrum to avoid
8599 * oversubscribing the link. Max center spread
8600 * is 2.5%; use 5% for safety's sake.
8602 u32 bps
= target_clock
* bpp
* 21 / 20;
8603 return DIV_ROUND_UP(bps
, link_bw
* 8);
8606 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
8608 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
8611 static uint32_t ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
8612 struct intel_crtc_state
*crtc_state
,
8614 intel_clock_t
*reduced_clock
, u32
*fp2
)
8616 struct drm_crtc
*crtc
= &intel_crtc
->base
;
8617 struct drm_device
*dev
= crtc
->dev
;
8618 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8619 struct drm_atomic_state
*state
= crtc_state
->base
.state
;
8620 struct drm_connector
*connector
;
8621 struct drm_connector_state
*connector_state
;
8622 struct intel_encoder
*encoder
;
8624 int factor
, num_connectors
= 0, i
;
8625 bool is_lvds
= false, is_sdvo
= false;
8627 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
8628 if (connector_state
->crtc
!= crtc_state
->base
.crtc
)
8631 encoder
= to_intel_encoder(connector_state
->best_encoder
);
8633 switch (encoder
->type
) {
8634 case INTEL_OUTPUT_LVDS
:
8637 case INTEL_OUTPUT_SDVO
:
8638 case INTEL_OUTPUT_HDMI
:
8648 /* Enable autotuning of the PLL clock (if permissible) */
8651 if ((intel_panel_use_ssc(dev_priv
) &&
8652 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
8653 (HAS_PCH_IBX(dev
) && intel_is_dual_link_lvds(dev
)))
8655 } else if (crtc_state
->sdvo_tv_clock
)
8658 if (ironlake_needs_fb_cb_tune(&crtc_state
->dpll
, factor
))
8661 if (fp2
&& (reduced_clock
->m
< factor
* reduced_clock
->n
))
8667 dpll
|= DPLLB_MODE_LVDS
;
8669 dpll
|= DPLLB_MODE_DAC_SERIAL
;
8671 dpll
|= (crtc_state
->pixel_multiplier
- 1)
8672 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
8675 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8676 if (crtc_state
->has_dp_encoder
)
8677 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8679 /* compute bitmask from p1 value */
8680 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8682 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
8684 switch (crtc_state
->dpll
.p2
) {
8686 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
8689 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
8692 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
8695 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
8699 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
8700 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
8702 dpll
|= PLL_REF_INPUT_DREFCLK
;
8704 return dpll
| DPLL_VCO_ENABLE
;
8707 static int ironlake_crtc_compute_clock(struct intel_crtc
*crtc
,
8708 struct intel_crtc_state
*crtc_state
)
8710 struct drm_device
*dev
= crtc
->base
.dev
;
8711 intel_clock_t clock
, reduced_clock
;
8712 u32 dpll
= 0, fp
= 0, fp2
= 0;
8713 bool ok
, has_reduced_clock
= false;
8714 bool is_lvds
= false;
8715 struct intel_shared_dpll
*pll
;
8717 memset(&crtc_state
->dpll_hw_state
, 0,
8718 sizeof(crtc_state
->dpll_hw_state
));
8720 is_lvds
= intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
);
8722 WARN(!(HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)),
8723 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev
));
8725 ok
= ironlake_compute_clocks(&crtc
->base
, crtc_state
, &clock
,
8726 &has_reduced_clock
, &reduced_clock
);
8727 if (!ok
&& !crtc_state
->clock_set
) {
8728 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8731 /* Compat-code for transition, will disappear. */
8732 if (!crtc_state
->clock_set
) {
8733 crtc_state
->dpll
.n
= clock
.n
;
8734 crtc_state
->dpll
.m1
= clock
.m1
;
8735 crtc_state
->dpll
.m2
= clock
.m2
;
8736 crtc_state
->dpll
.p1
= clock
.p1
;
8737 crtc_state
->dpll
.p2
= clock
.p2
;
8740 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8741 if (crtc_state
->has_pch_encoder
) {
8742 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
8743 if (has_reduced_clock
)
8744 fp2
= i9xx_dpll_compute_fp(&reduced_clock
);
8746 dpll
= ironlake_compute_dpll(crtc
, crtc_state
,
8747 &fp
, &reduced_clock
,
8748 has_reduced_clock
? &fp2
: NULL
);
8750 crtc_state
->dpll_hw_state
.dpll
= dpll
;
8751 crtc_state
->dpll_hw_state
.fp0
= fp
;
8752 if (has_reduced_clock
)
8753 crtc_state
->dpll_hw_state
.fp1
= fp2
;
8755 crtc_state
->dpll_hw_state
.fp1
= fp
;
8757 pll
= intel_get_shared_dpll(crtc
, crtc_state
);
8759 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8760 pipe_name(crtc
->pipe
));
8765 if (is_lvds
&& has_reduced_clock
)
8766 crtc
->lowfreq_avail
= true;
8768 crtc
->lowfreq_avail
= false;
8773 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
8774 struct intel_link_m_n
*m_n
)
8776 struct drm_device
*dev
= crtc
->base
.dev
;
8777 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8778 enum pipe pipe
= crtc
->pipe
;
8780 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
8781 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
8782 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
8784 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
8785 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
8786 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8789 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
8790 enum transcoder transcoder
,
8791 struct intel_link_m_n
*m_n
,
8792 struct intel_link_m_n
*m2_n2
)
8794 struct drm_device
*dev
= crtc
->base
.dev
;
8795 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8796 enum pipe pipe
= crtc
->pipe
;
8798 if (INTEL_INFO(dev
)->gen
>= 5) {
8799 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
8800 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
8801 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
8803 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
8804 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
8805 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8806 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8807 * gen < 8) and if DRRS is supported (to make sure the
8808 * registers are not unnecessarily read).
8810 if (m2_n2
&& INTEL_INFO(dev
)->gen
< 8 &&
8811 crtc
->config
->has_drrs
) {
8812 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
8813 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
8814 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
8816 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
8817 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
8818 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8821 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
8822 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
8823 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
8825 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
8826 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
8827 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8831 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
8832 struct intel_crtc_state
*pipe_config
)
8834 if (pipe_config
->has_pch_encoder
)
8835 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
8837 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8838 &pipe_config
->dp_m_n
,
8839 &pipe_config
->dp_m2_n2
);
8842 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
8843 struct intel_crtc_state
*pipe_config
)
8845 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8846 &pipe_config
->fdi_m_n
, NULL
);
8849 static void skylake_get_pfit_config(struct intel_crtc
*crtc
,
8850 struct intel_crtc_state
*pipe_config
)
8852 struct drm_device
*dev
= crtc
->base
.dev
;
8853 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8854 struct intel_crtc_scaler_state
*scaler_state
= &pipe_config
->scaler_state
;
8855 uint32_t ps_ctrl
= 0;
8859 /* find scaler attached to this pipe */
8860 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
8861 ps_ctrl
= I915_READ(SKL_PS_CTRL(crtc
->pipe
, i
));
8862 if (ps_ctrl
& PS_SCALER_EN
&& !(ps_ctrl
& PS_PLANE_SEL_MASK
)) {
8864 pipe_config
->pch_pfit
.enabled
= true;
8865 pipe_config
->pch_pfit
.pos
= I915_READ(SKL_PS_WIN_POS(crtc
->pipe
, i
));
8866 pipe_config
->pch_pfit
.size
= I915_READ(SKL_PS_WIN_SZ(crtc
->pipe
, i
));
8871 scaler_state
->scaler_id
= id
;
8873 scaler_state
->scaler_users
|= (1 << SKL_CRTC_INDEX
);
8875 scaler_state
->scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
8880 skylake_get_initial_plane_config(struct intel_crtc
*crtc
,
8881 struct intel_initial_plane_config
*plane_config
)
8883 struct drm_device
*dev
= crtc
->base
.dev
;
8884 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8885 u32 val
, base
, offset
, stride_mult
, tiling
;
8886 int pipe
= crtc
->pipe
;
8887 int fourcc
, pixel_format
;
8888 unsigned int aligned_height
;
8889 struct drm_framebuffer
*fb
;
8890 struct intel_framebuffer
*intel_fb
;
8892 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8894 DRM_DEBUG_KMS("failed to alloc fb\n");
8898 fb
= &intel_fb
->base
;
8900 val
= I915_READ(PLANE_CTL(pipe
, 0));
8901 if (!(val
& PLANE_CTL_ENABLE
))
8904 pixel_format
= val
& PLANE_CTL_FORMAT_MASK
;
8905 fourcc
= skl_format_to_fourcc(pixel_format
,
8906 val
& PLANE_CTL_ORDER_RGBX
,
8907 val
& PLANE_CTL_ALPHA_MASK
);
8908 fb
->pixel_format
= fourcc
;
8909 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
8911 tiling
= val
& PLANE_CTL_TILED_MASK
;
8913 case PLANE_CTL_TILED_LINEAR
:
8914 fb
->modifier
[0] = DRM_FORMAT_MOD_NONE
;
8916 case PLANE_CTL_TILED_X
:
8917 plane_config
->tiling
= I915_TILING_X
;
8918 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
8920 case PLANE_CTL_TILED_Y
:
8921 fb
->modifier
[0] = I915_FORMAT_MOD_Y_TILED
;
8923 case PLANE_CTL_TILED_YF
:
8924 fb
->modifier
[0] = I915_FORMAT_MOD_Yf_TILED
;
8927 MISSING_CASE(tiling
);
8931 base
= I915_READ(PLANE_SURF(pipe
, 0)) & 0xfffff000;
8932 plane_config
->base
= base
;
8934 offset
= I915_READ(PLANE_OFFSET(pipe
, 0));
8936 val
= I915_READ(PLANE_SIZE(pipe
, 0));
8937 fb
->height
= ((val
>> 16) & 0xfff) + 1;
8938 fb
->width
= ((val
>> 0) & 0x1fff) + 1;
8940 val
= I915_READ(PLANE_STRIDE(pipe
, 0));
8941 stride_mult
= intel_fb_stride_alignment(dev
, fb
->modifier
[0],
8943 fb
->pitches
[0] = (val
& 0x3ff) * stride_mult
;
8945 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
8949 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8951 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8952 pipe_name(pipe
), fb
->width
, fb
->height
,
8953 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
8954 plane_config
->size
);
8956 plane_config
->fb
= intel_fb
;
8963 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
8964 struct intel_crtc_state
*pipe_config
)
8966 struct drm_device
*dev
= crtc
->base
.dev
;
8967 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8970 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
8972 if (tmp
& PF_ENABLE
) {
8973 pipe_config
->pch_pfit
.enabled
= true;
8974 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
8975 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
8977 /* We currently do not free assignements of panel fitters on
8978 * ivb/hsw (since we don't use the higher upscaling modes which
8979 * differentiates them) so just WARN about this case for now. */
8981 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
8982 PF_PIPE_SEL_IVB(crtc
->pipe
));
8988 ironlake_get_initial_plane_config(struct intel_crtc
*crtc
,
8989 struct intel_initial_plane_config
*plane_config
)
8991 struct drm_device
*dev
= crtc
->base
.dev
;
8992 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8993 u32 val
, base
, offset
;
8994 int pipe
= crtc
->pipe
;
8995 int fourcc
, pixel_format
;
8996 unsigned int aligned_height
;
8997 struct drm_framebuffer
*fb
;
8998 struct intel_framebuffer
*intel_fb
;
9000 val
= I915_READ(DSPCNTR(pipe
));
9001 if (!(val
& DISPLAY_PLANE_ENABLE
))
9004 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9006 DRM_DEBUG_KMS("failed to alloc fb\n");
9010 fb
= &intel_fb
->base
;
9012 if (INTEL_INFO(dev
)->gen
>= 4) {
9013 if (val
& DISPPLANE_TILED
) {
9014 plane_config
->tiling
= I915_TILING_X
;
9015 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
9019 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
9020 fourcc
= i9xx_format_to_fourcc(pixel_format
);
9021 fb
->pixel_format
= fourcc
;
9022 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
9024 base
= I915_READ(DSPSURF(pipe
)) & 0xfffff000;
9025 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
9026 offset
= I915_READ(DSPOFFSET(pipe
));
9028 if (plane_config
->tiling
)
9029 offset
= I915_READ(DSPTILEOFF(pipe
));
9031 offset
= I915_READ(DSPLINOFF(pipe
));
9033 plane_config
->base
= base
;
9035 val
= I915_READ(PIPESRC(pipe
));
9036 fb
->width
= ((val
>> 16) & 0xfff) + 1;
9037 fb
->height
= ((val
>> 0) & 0xfff) + 1;
9039 val
= I915_READ(DSPSTRIDE(pipe
));
9040 fb
->pitches
[0] = val
& 0xffffffc0;
9042 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
9046 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
9048 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9049 pipe_name(pipe
), fb
->width
, fb
->height
,
9050 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
9051 plane_config
->size
);
9053 plane_config
->fb
= intel_fb
;
9056 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
9057 struct intel_crtc_state
*pipe_config
)
9059 struct drm_device
*dev
= crtc
->base
.dev
;
9060 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9063 if (!intel_display_power_is_enabled(dev_priv
,
9064 POWER_DOMAIN_PIPE(crtc
->pipe
)))
9067 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
9068 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
9070 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
9071 if (!(tmp
& PIPECONF_ENABLE
))
9074 switch (tmp
& PIPECONF_BPC_MASK
) {
9076 pipe_config
->pipe_bpp
= 18;
9079 pipe_config
->pipe_bpp
= 24;
9081 case PIPECONF_10BPC
:
9082 pipe_config
->pipe_bpp
= 30;
9084 case PIPECONF_12BPC
:
9085 pipe_config
->pipe_bpp
= 36;
9091 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
9092 pipe_config
->limited_color_range
= true;
9094 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
9095 struct intel_shared_dpll
*pll
;
9097 pipe_config
->has_pch_encoder
= true;
9099 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
9100 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
9101 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
9103 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
9105 if (HAS_PCH_IBX(dev_priv
->dev
)) {
9106 pipe_config
->shared_dpll
=
9107 (enum intel_dpll_id
) crtc
->pipe
;
9109 tmp
= I915_READ(PCH_DPLL_SEL
);
9110 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
9111 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_B
;
9113 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_A
;
9116 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
9118 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
9119 &pipe_config
->dpll_hw_state
));
9121 tmp
= pipe_config
->dpll_hw_state
.dpll
;
9122 pipe_config
->pixel_multiplier
=
9123 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
9124 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
9126 ironlake_pch_clock_get(crtc
, pipe_config
);
9128 pipe_config
->pixel_multiplier
= 1;
9131 intel_get_pipe_timings(crtc
, pipe_config
);
9133 ironlake_get_pfit_config(crtc
, pipe_config
);
9138 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
9140 struct drm_device
*dev
= dev_priv
->dev
;
9141 struct intel_crtc
*crtc
;
9143 for_each_intel_crtc(dev
, crtc
)
9144 I915_STATE_WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
9145 pipe_name(crtc
->pipe
));
9147 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
9148 I915_STATE_WARN(I915_READ(SPLL_CTL
) & SPLL_PLL_ENABLE
, "SPLL enabled\n");
9149 I915_STATE_WARN(I915_READ(WRPLL_CTL1
) & WRPLL_PLL_ENABLE
, "WRPLL1 enabled\n");
9150 I915_STATE_WARN(I915_READ(WRPLL_CTL2
) & WRPLL_PLL_ENABLE
, "WRPLL2 enabled\n");
9151 I915_STATE_WARN(I915_READ(PCH_PP_STATUS
) & PP_ON
, "Panel power on\n");
9152 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
9153 "CPU PWM1 enabled\n");
9154 if (IS_HASWELL(dev
))
9155 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
9156 "CPU PWM2 enabled\n");
9157 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
9158 "PCH PWM1 enabled\n");
9159 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
9160 "Utility pin enabled\n");
9161 I915_STATE_WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
9164 * In theory we can still leave IRQs enabled, as long as only the HPD
9165 * interrupts remain enabled. We used to check for that, but since it's
9166 * gen-specific and since we only disable LCPLL after we fully disable
9167 * the interrupts, the check below should be enough.
9169 I915_STATE_WARN(intel_irqs_enabled(dev_priv
), "IRQs enabled\n");
9172 static uint32_t hsw_read_dcomp(struct drm_i915_private
*dev_priv
)
9174 struct drm_device
*dev
= dev_priv
->dev
;
9176 if (IS_HASWELL(dev
))
9177 return I915_READ(D_COMP_HSW
);
9179 return I915_READ(D_COMP_BDW
);
9182 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
9184 struct drm_device
*dev
= dev_priv
->dev
;
9186 if (IS_HASWELL(dev
)) {
9187 mutex_lock(&dev_priv
->rps
.hw_lock
);
9188 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
9190 DRM_ERROR("Failed to write to D_COMP\n");
9191 mutex_unlock(&dev_priv
->rps
.hw_lock
);
9193 I915_WRITE(D_COMP_BDW
, val
);
9194 POSTING_READ(D_COMP_BDW
);
9199 * This function implements pieces of two sequences from BSpec:
9200 * - Sequence for display software to disable LCPLL
9201 * - Sequence for display software to allow package C8+
9202 * The steps implemented here are just the steps that actually touch the LCPLL
9203 * register. Callers should take care of disabling all the display engine
9204 * functions, doing the mode unset, fixing interrupts, etc.
9206 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
9207 bool switch_to_fclk
, bool allow_power_down
)
9211 assert_can_disable_lcpll(dev_priv
);
9213 val
= I915_READ(LCPLL_CTL
);
9215 if (switch_to_fclk
) {
9216 val
|= LCPLL_CD_SOURCE_FCLK
;
9217 I915_WRITE(LCPLL_CTL
, val
);
9219 if (wait_for_atomic_us(I915_READ(LCPLL_CTL
) &
9220 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
9221 DRM_ERROR("Switching to FCLK failed\n");
9223 val
= I915_READ(LCPLL_CTL
);
9226 val
|= LCPLL_PLL_DISABLE
;
9227 I915_WRITE(LCPLL_CTL
, val
);
9228 POSTING_READ(LCPLL_CTL
);
9230 if (wait_for((I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
) == 0, 1))
9231 DRM_ERROR("LCPLL still locked\n");
9233 val
= hsw_read_dcomp(dev_priv
);
9234 val
|= D_COMP_COMP_DISABLE
;
9235 hsw_write_dcomp(dev_priv
, val
);
9238 if (wait_for((hsw_read_dcomp(dev_priv
) & D_COMP_RCOMP_IN_PROGRESS
) == 0,
9240 DRM_ERROR("D_COMP RCOMP still in progress\n");
9242 if (allow_power_down
) {
9243 val
= I915_READ(LCPLL_CTL
);
9244 val
|= LCPLL_POWER_DOWN_ALLOW
;
9245 I915_WRITE(LCPLL_CTL
, val
);
9246 POSTING_READ(LCPLL_CTL
);
9251 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9254 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
9258 val
= I915_READ(LCPLL_CTL
);
9260 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
9261 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
9265 * Make sure we're not on PC8 state before disabling PC8, otherwise
9266 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
9268 intel_uncore_forcewake_get(dev_priv
, FORCEWAKE_ALL
);
9270 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
9271 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
9272 I915_WRITE(LCPLL_CTL
, val
);
9273 POSTING_READ(LCPLL_CTL
);
9276 val
= hsw_read_dcomp(dev_priv
);
9277 val
|= D_COMP_COMP_FORCE
;
9278 val
&= ~D_COMP_COMP_DISABLE
;
9279 hsw_write_dcomp(dev_priv
, val
);
9281 val
= I915_READ(LCPLL_CTL
);
9282 val
&= ~LCPLL_PLL_DISABLE
;
9283 I915_WRITE(LCPLL_CTL
, val
);
9285 if (wait_for(I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
, 5))
9286 DRM_ERROR("LCPLL not locked yet\n");
9288 if (val
& LCPLL_CD_SOURCE_FCLK
) {
9289 val
= I915_READ(LCPLL_CTL
);
9290 val
&= ~LCPLL_CD_SOURCE_FCLK
;
9291 I915_WRITE(LCPLL_CTL
, val
);
9293 if (wait_for_atomic_us((I915_READ(LCPLL_CTL
) &
9294 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
9295 DRM_ERROR("Switching back to LCPLL failed\n");
9298 intel_uncore_forcewake_put(dev_priv
, FORCEWAKE_ALL
);
9302 * Package states C8 and deeper are really deep PC states that can only be
9303 * reached when all the devices on the system allow it, so even if the graphics
9304 * device allows PC8+, it doesn't mean the system will actually get to these
9305 * states. Our driver only allows PC8+ when going into runtime PM.
9307 * The requirements for PC8+ are that all the outputs are disabled, the power
9308 * well is disabled and most interrupts are disabled, and these are also
9309 * requirements for runtime PM. When these conditions are met, we manually do
9310 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9311 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9314 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9315 * the state of some registers, so when we come back from PC8+ we need to
9316 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9317 * need to take care of the registers kept by RC6. Notice that this happens even
9318 * if we don't put the device in PCI D3 state (which is what currently happens
9319 * because of the runtime PM support).
9321 * For more, read "Display Sequences for Package C8" on the hardware
9324 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
9326 struct drm_device
*dev
= dev_priv
->dev
;
9329 DRM_DEBUG_KMS("Enabling package C8+\n");
9331 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
9332 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
9333 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
9334 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
9337 lpt_disable_clkout_dp(dev
);
9338 hsw_disable_lcpll(dev_priv
, true, true);
9341 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
9343 struct drm_device
*dev
= dev_priv
->dev
;
9346 DRM_DEBUG_KMS("Disabling package C8+\n");
9348 hsw_restore_lcpll(dev_priv
);
9349 lpt_init_pch_refclk(dev
);
9351 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
9352 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
9353 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
9354 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
9357 intel_prepare_ddi(dev
);
9360 static void broxton_modeset_global_resources(struct drm_atomic_state
*old_state
)
9362 struct drm_device
*dev
= old_state
->dev
;
9363 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9364 int max_pixclk
= intel_mode_max_pixclk(dev
, NULL
);
9367 /* see the comment in valleyview_modeset_global_resources */
9368 if (WARN_ON(max_pixclk
< 0))
9371 req_cdclk
= broxton_calc_cdclk(dev_priv
, max_pixclk
);
9373 if (req_cdclk
!= dev_priv
->cdclk_freq
)
9374 broxton_set_cdclk(dev
, req_cdclk
);
9377 static int haswell_crtc_compute_clock(struct intel_crtc
*crtc
,
9378 struct intel_crtc_state
*crtc_state
)
9380 if (!intel_ddi_pll_select(crtc
, crtc_state
))
9383 crtc
->lowfreq_avail
= false;
9388 static void bxt_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9390 struct intel_crtc_state
*pipe_config
)
9394 pipe_config
->ddi_pll_sel
= SKL_DPLL0
;
9395 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL1
;
9398 pipe_config
->ddi_pll_sel
= SKL_DPLL1
;
9399 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL2
;
9402 pipe_config
->ddi_pll_sel
= SKL_DPLL2
;
9403 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL3
;
9406 DRM_ERROR("Incorrect port type\n");
9410 static void skylake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9412 struct intel_crtc_state
*pipe_config
)
9414 u32 temp
, dpll_ctl1
;
9416 temp
= I915_READ(DPLL_CTRL2
) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port
);
9417 pipe_config
->ddi_pll_sel
= temp
>> (port
* 3 + 1);
9419 switch (pipe_config
->ddi_pll_sel
) {
9422 * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part
9423 * of the shared DPLL framework and thus needs to be read out
9426 dpll_ctl1
= I915_READ(DPLL_CTRL1
);
9427 pipe_config
->dpll_hw_state
.ctrl1
= dpll_ctl1
& 0x3f;
9430 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL1
;
9433 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL2
;
9436 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL3
;
9441 static void haswell_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9443 struct intel_crtc_state
*pipe_config
)
9445 pipe_config
->ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
9447 switch (pipe_config
->ddi_pll_sel
) {
9448 case PORT_CLK_SEL_WRPLL1
:
9449 pipe_config
->shared_dpll
= DPLL_ID_WRPLL1
;
9451 case PORT_CLK_SEL_WRPLL2
:
9452 pipe_config
->shared_dpll
= DPLL_ID_WRPLL2
;
9457 static void haswell_get_ddi_port_state(struct intel_crtc
*crtc
,
9458 struct intel_crtc_state
*pipe_config
)
9460 struct drm_device
*dev
= crtc
->base
.dev
;
9461 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9462 struct intel_shared_dpll
*pll
;
9466 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
9468 port
= (tmp
& TRANS_DDI_PORT_MASK
) >> TRANS_DDI_PORT_SHIFT
;
9470 if (IS_SKYLAKE(dev
))
9471 skylake_get_ddi_pll(dev_priv
, port
, pipe_config
);
9472 else if (IS_BROXTON(dev
))
9473 bxt_get_ddi_pll(dev_priv
, port
, pipe_config
);
9475 haswell_get_ddi_pll(dev_priv
, port
, pipe_config
);
9477 if (pipe_config
->shared_dpll
>= 0) {
9478 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
9480 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
9481 &pipe_config
->dpll_hw_state
));
9485 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9486 * DDI E. So just check whether this pipe is wired to DDI E and whether
9487 * the PCH transcoder is on.
9489 if (INTEL_INFO(dev
)->gen
< 9 &&
9490 (port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
9491 pipe_config
->has_pch_encoder
= true;
9493 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
9494 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
9495 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
9497 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
9501 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
9502 struct intel_crtc_state
*pipe_config
)
9504 struct drm_device
*dev
= crtc
->base
.dev
;
9505 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9506 enum intel_display_power_domain pfit_domain
;
9509 if (!intel_display_power_is_enabled(dev_priv
,
9510 POWER_DOMAIN_PIPE(crtc
->pipe
)))
9513 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
9514 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
9516 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
9517 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
9518 enum pipe trans_edp_pipe
;
9519 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
9521 WARN(1, "unknown pipe linked to edp transcoder\n");
9522 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
9523 case TRANS_DDI_EDP_INPUT_A_ON
:
9524 trans_edp_pipe
= PIPE_A
;
9526 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
9527 trans_edp_pipe
= PIPE_B
;
9529 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
9530 trans_edp_pipe
= PIPE_C
;
9534 if (trans_edp_pipe
== crtc
->pipe
)
9535 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
9538 if (!intel_display_power_is_enabled(dev_priv
,
9539 POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
)))
9542 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
9543 if (!(tmp
& PIPECONF_ENABLE
))
9546 haswell_get_ddi_port_state(crtc
, pipe_config
);
9548 intel_get_pipe_timings(crtc
, pipe_config
);
9550 if (INTEL_INFO(dev
)->gen
>= 9) {
9551 skl_init_scalers(dev
, crtc
, pipe_config
);
9554 pfit_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
9556 if (INTEL_INFO(dev
)->gen
>= 9) {
9557 pipe_config
->scaler_state
.scaler_id
= -1;
9558 pipe_config
->scaler_state
.scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
9561 if (intel_display_power_is_enabled(dev_priv
, pfit_domain
)) {
9562 if (INTEL_INFO(dev
)->gen
== 9)
9563 skylake_get_pfit_config(crtc
, pipe_config
);
9564 else if (INTEL_INFO(dev
)->gen
< 9)
9565 ironlake_get_pfit_config(crtc
, pipe_config
);
9567 MISSING_CASE(INTEL_INFO(dev
)->gen
);
9570 if (IS_HASWELL(dev
))
9571 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
9572 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
9574 if (pipe_config
->cpu_transcoder
!= TRANSCODER_EDP
) {
9575 pipe_config
->pixel_multiplier
=
9576 I915_READ(PIPE_MULT(pipe_config
->cpu_transcoder
)) + 1;
9578 pipe_config
->pixel_multiplier
= 1;
9584 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
)
9586 struct drm_device
*dev
= crtc
->dev
;
9587 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9588 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9589 uint32_t cntl
= 0, size
= 0;
9592 unsigned int width
= intel_crtc
->base
.cursor
->state
->crtc_w
;
9593 unsigned int height
= intel_crtc
->base
.cursor
->state
->crtc_h
;
9594 unsigned int stride
= roundup_pow_of_two(width
) * 4;
9598 WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
9609 cntl
|= CURSOR_ENABLE
|
9610 CURSOR_GAMMA_ENABLE
|
9611 CURSOR_FORMAT_ARGB
|
9612 CURSOR_STRIDE(stride
);
9614 size
= (height
<< 12) | width
;
9617 if (intel_crtc
->cursor_cntl
!= 0 &&
9618 (intel_crtc
->cursor_base
!= base
||
9619 intel_crtc
->cursor_size
!= size
||
9620 intel_crtc
->cursor_cntl
!= cntl
)) {
9621 /* On these chipsets we can only modify the base/size/stride
9622 * whilst the cursor is disabled.
9624 I915_WRITE(_CURACNTR
, 0);
9625 POSTING_READ(_CURACNTR
);
9626 intel_crtc
->cursor_cntl
= 0;
9629 if (intel_crtc
->cursor_base
!= base
) {
9630 I915_WRITE(_CURABASE
, base
);
9631 intel_crtc
->cursor_base
= base
;
9634 if (intel_crtc
->cursor_size
!= size
) {
9635 I915_WRITE(CURSIZE
, size
);
9636 intel_crtc
->cursor_size
= size
;
9639 if (intel_crtc
->cursor_cntl
!= cntl
) {
9640 I915_WRITE(_CURACNTR
, cntl
);
9641 POSTING_READ(_CURACNTR
);
9642 intel_crtc
->cursor_cntl
= cntl
;
9646 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
)
9648 struct drm_device
*dev
= crtc
->dev
;
9649 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9650 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9651 int pipe
= intel_crtc
->pipe
;
9656 cntl
= MCURSOR_GAMMA_ENABLE
;
9657 switch (intel_crtc
->base
.cursor
->state
->crtc_w
) {
9659 cntl
|= CURSOR_MODE_64_ARGB_AX
;
9662 cntl
|= CURSOR_MODE_128_ARGB_AX
;
9665 cntl
|= CURSOR_MODE_256_ARGB_AX
;
9668 MISSING_CASE(intel_crtc
->base
.cursor
->state
->crtc_w
);
9671 cntl
|= pipe
<< 28; /* Connect to correct pipe */
9673 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
9674 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
9677 if (crtc
->cursor
->state
->rotation
== BIT(DRM_ROTATE_180
))
9678 cntl
|= CURSOR_ROTATE_180
;
9680 if (intel_crtc
->cursor_cntl
!= cntl
) {
9681 I915_WRITE(CURCNTR(pipe
), cntl
);
9682 POSTING_READ(CURCNTR(pipe
));
9683 intel_crtc
->cursor_cntl
= cntl
;
9686 /* and commit changes on next vblank */
9687 I915_WRITE(CURBASE(pipe
), base
);
9688 POSTING_READ(CURBASE(pipe
));
9690 intel_crtc
->cursor_base
= base
;
9693 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
9694 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
9697 struct drm_device
*dev
= crtc
->dev
;
9698 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9699 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9700 int pipe
= intel_crtc
->pipe
;
9701 int x
= crtc
->cursor_x
;
9702 int y
= crtc
->cursor_y
;
9703 u32 base
= 0, pos
= 0;
9706 base
= intel_crtc
->cursor_addr
;
9708 if (x
>= intel_crtc
->config
->pipe_src_w
)
9711 if (y
>= intel_crtc
->config
->pipe_src_h
)
9715 if (x
+ intel_crtc
->base
.cursor
->state
->crtc_w
<= 0)
9718 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
9721 pos
|= x
<< CURSOR_X_SHIFT
;
9724 if (y
+ intel_crtc
->base
.cursor
->state
->crtc_h
<= 0)
9727 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
9730 pos
|= y
<< CURSOR_Y_SHIFT
;
9732 if (base
== 0 && intel_crtc
->cursor_base
== 0)
9735 I915_WRITE(CURPOS(pipe
), pos
);
9737 /* ILK+ do this automagically */
9738 if (HAS_GMCH_DISPLAY(dev
) &&
9739 crtc
->cursor
->state
->rotation
== BIT(DRM_ROTATE_180
)) {
9740 base
+= (intel_crtc
->base
.cursor
->state
->crtc_h
*
9741 intel_crtc
->base
.cursor
->state
->crtc_w
- 1) * 4;
9744 if (IS_845G(dev
) || IS_I865G(dev
))
9745 i845_update_cursor(crtc
, base
);
9747 i9xx_update_cursor(crtc
, base
);
9750 static bool cursor_size_ok(struct drm_device
*dev
,
9751 uint32_t width
, uint32_t height
)
9753 if (width
== 0 || height
== 0)
9757 * 845g/865g are special in that they are only limited by
9758 * the width of their cursors, the height is arbitrary up to
9759 * the precision of the register. Everything else requires
9760 * square cursors, limited to a few power-of-two sizes.
9762 if (IS_845G(dev
) || IS_I865G(dev
)) {
9763 if ((width
& 63) != 0)
9766 if (width
> (IS_845G(dev
) ? 64 : 512))
9772 switch (width
| height
) {
9787 static void intel_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
9788 u16
*blue
, uint32_t start
, uint32_t size
)
9790 int end
= (start
+ size
> 256) ? 256 : start
+ size
, i
;
9791 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9793 for (i
= start
; i
< end
; i
++) {
9794 intel_crtc
->lut_r
[i
] = red
[i
] >> 8;
9795 intel_crtc
->lut_g
[i
] = green
[i
] >> 8;
9796 intel_crtc
->lut_b
[i
] = blue
[i
] >> 8;
9799 intel_crtc_load_lut(crtc
);
9802 /* VESA 640x480x72Hz mode to set on the pipe */
9803 static struct drm_display_mode load_detect_mode
= {
9804 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
9805 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
9808 struct drm_framebuffer
*
9809 __intel_framebuffer_create(struct drm_device
*dev
,
9810 struct drm_mode_fb_cmd2
*mode_cmd
,
9811 struct drm_i915_gem_object
*obj
)
9813 struct intel_framebuffer
*intel_fb
;
9816 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9818 drm_gem_object_unreference(&obj
->base
);
9819 return ERR_PTR(-ENOMEM
);
9822 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
9826 return &intel_fb
->base
;
9828 drm_gem_object_unreference(&obj
->base
);
9831 return ERR_PTR(ret
);
9834 static struct drm_framebuffer
*
9835 intel_framebuffer_create(struct drm_device
*dev
,
9836 struct drm_mode_fb_cmd2
*mode_cmd
,
9837 struct drm_i915_gem_object
*obj
)
9839 struct drm_framebuffer
*fb
;
9842 ret
= i915_mutex_lock_interruptible(dev
);
9844 return ERR_PTR(ret
);
9845 fb
= __intel_framebuffer_create(dev
, mode_cmd
, obj
);
9846 mutex_unlock(&dev
->struct_mutex
);
9852 intel_framebuffer_pitch_for_width(int width
, int bpp
)
9854 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
9855 return ALIGN(pitch
, 64);
9859 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
9861 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
9862 return PAGE_ALIGN(pitch
* mode
->vdisplay
);
9865 static struct drm_framebuffer
*
9866 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
9867 struct drm_display_mode
*mode
,
9870 struct drm_i915_gem_object
*obj
;
9871 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
9873 obj
= i915_gem_alloc_object(dev
,
9874 intel_framebuffer_size_for_mode(mode
, bpp
));
9876 return ERR_PTR(-ENOMEM
);
9878 mode_cmd
.width
= mode
->hdisplay
;
9879 mode_cmd
.height
= mode
->vdisplay
;
9880 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
9882 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
9884 return intel_framebuffer_create(dev
, &mode_cmd
, obj
);
9887 static struct drm_framebuffer
*
9888 mode_fits_in_fbdev(struct drm_device
*dev
,
9889 struct drm_display_mode
*mode
)
9891 #ifdef CONFIG_DRM_I915_FBDEV
9892 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9893 struct drm_i915_gem_object
*obj
;
9894 struct drm_framebuffer
*fb
;
9896 if (!dev_priv
->fbdev
)
9899 if (!dev_priv
->fbdev
->fb
)
9902 obj
= dev_priv
->fbdev
->fb
->obj
;
9905 fb
= &dev_priv
->fbdev
->fb
->base
;
9906 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
9907 fb
->bits_per_pixel
))
9910 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
9919 static int intel_modeset_setup_plane_state(struct drm_atomic_state
*state
,
9920 struct drm_crtc
*crtc
,
9921 struct drm_display_mode
*mode
,
9922 struct drm_framebuffer
*fb
,
9925 struct drm_plane_state
*plane_state
;
9926 int hdisplay
, vdisplay
;
9929 plane_state
= drm_atomic_get_plane_state(state
, crtc
->primary
);
9930 if (IS_ERR(plane_state
))
9931 return PTR_ERR(plane_state
);
9934 drm_crtc_get_hv_timing(mode
, &hdisplay
, &vdisplay
);
9936 hdisplay
= vdisplay
= 0;
9938 ret
= drm_atomic_set_crtc_for_plane(plane_state
, fb
? crtc
: NULL
);
9941 drm_atomic_set_fb_for_plane(plane_state
, fb
);
9942 plane_state
->crtc_x
= 0;
9943 plane_state
->crtc_y
= 0;
9944 plane_state
->crtc_w
= hdisplay
;
9945 plane_state
->crtc_h
= vdisplay
;
9946 plane_state
->src_x
= x
<< 16;
9947 plane_state
->src_y
= y
<< 16;
9948 plane_state
->src_w
= hdisplay
<< 16;
9949 plane_state
->src_h
= vdisplay
<< 16;
9954 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
9955 struct drm_display_mode
*mode
,
9956 struct intel_load_detect_pipe
*old
,
9957 struct drm_modeset_acquire_ctx
*ctx
)
9959 struct intel_crtc
*intel_crtc
;
9960 struct intel_encoder
*intel_encoder
=
9961 intel_attached_encoder(connector
);
9962 struct drm_crtc
*possible_crtc
;
9963 struct drm_encoder
*encoder
= &intel_encoder
->base
;
9964 struct drm_crtc
*crtc
= NULL
;
9965 struct drm_device
*dev
= encoder
->dev
;
9966 struct drm_framebuffer
*fb
;
9967 struct drm_mode_config
*config
= &dev
->mode_config
;
9968 struct drm_atomic_state
*state
= NULL
;
9969 struct drm_connector_state
*connector_state
;
9970 struct intel_crtc_state
*crtc_state
;
9973 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9974 connector
->base
.id
, connector
->name
,
9975 encoder
->base
.id
, encoder
->name
);
9978 ret
= drm_modeset_lock(&config
->connection_mutex
, ctx
);
9983 * Algorithm gets a little messy:
9985 * - if the connector already has an assigned crtc, use it (but make
9986 * sure it's on first)
9988 * - try to find the first unused crtc that can drive this connector,
9989 * and use that if we find one
9992 /* See if we already have a CRTC for this connector */
9993 if (encoder
->crtc
) {
9994 crtc
= encoder
->crtc
;
9996 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
9999 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
10003 old
->dpms_mode
= connector
->dpms
;
10004 old
->load_detect_temp
= false;
10006 /* Make sure the crtc and connector are running */
10007 if (connector
->dpms
!= DRM_MODE_DPMS_ON
)
10008 connector
->funcs
->dpms(connector
, DRM_MODE_DPMS_ON
);
10013 /* Find an unused one (if possible) */
10014 for_each_crtc(dev
, possible_crtc
) {
10016 if (!(encoder
->possible_crtcs
& (1 << i
)))
10018 if (possible_crtc
->state
->enable
)
10020 /* This can occur when applying the pipe A quirk on resume. */
10021 if (to_intel_crtc(possible_crtc
)->new_enabled
)
10024 crtc
= possible_crtc
;
10029 * If we didn't find an unused CRTC, don't use any.
10032 DRM_DEBUG_KMS("no pipe available for load-detect\n");
10036 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
10039 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
10042 intel_encoder
->new_crtc
= to_intel_crtc(crtc
);
10043 to_intel_connector(connector
)->new_encoder
= intel_encoder
;
10045 intel_crtc
= to_intel_crtc(crtc
);
10046 intel_crtc
->new_enabled
= true;
10047 old
->dpms_mode
= connector
->dpms
;
10048 old
->load_detect_temp
= true;
10049 old
->release_fb
= NULL
;
10051 state
= drm_atomic_state_alloc(dev
);
10055 state
->acquire_ctx
= ctx
;
10057 connector_state
= drm_atomic_get_connector_state(state
, connector
);
10058 if (IS_ERR(connector_state
)) {
10059 ret
= PTR_ERR(connector_state
);
10063 connector_state
->crtc
= crtc
;
10064 connector_state
->best_encoder
= &intel_encoder
->base
;
10066 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
10067 if (IS_ERR(crtc_state
)) {
10068 ret
= PTR_ERR(crtc_state
);
10072 crtc_state
->base
.active
= crtc_state
->base
.enable
= true;
10075 mode
= &load_detect_mode
;
10077 /* We need a framebuffer large enough to accommodate all accesses
10078 * that the plane may generate whilst we perform load detection.
10079 * We can not rely on the fbcon either being present (we get called
10080 * during its initialisation to detect all boot displays, or it may
10081 * not even exist) or that it is large enough to satisfy the
10084 fb
= mode_fits_in_fbdev(dev
, mode
);
10086 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
10087 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
10088 old
->release_fb
= fb
;
10090 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
10092 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
10096 ret
= intel_modeset_setup_plane_state(state
, crtc
, mode
, fb
, 0, 0);
10100 drm_mode_copy(&crtc_state
->base
.mode
, mode
);
10102 if (intel_set_mode(crtc
, state
)) {
10103 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
10104 if (old
->release_fb
)
10105 old
->release_fb
->funcs
->destroy(old
->release_fb
);
10108 crtc
->primary
->crtc
= crtc
;
10110 /* let the connector get through one full cycle before testing */
10111 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
10115 intel_crtc
->new_enabled
= crtc
->state
->enable
;
10117 drm_atomic_state_free(state
);
10120 if (ret
== -EDEADLK
) {
10121 drm_modeset_backoff(ctx
);
10128 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
10129 struct intel_load_detect_pipe
*old
,
10130 struct drm_modeset_acquire_ctx
*ctx
)
10132 struct drm_device
*dev
= connector
->dev
;
10133 struct intel_encoder
*intel_encoder
=
10134 intel_attached_encoder(connector
);
10135 struct drm_encoder
*encoder
= &intel_encoder
->base
;
10136 struct drm_crtc
*crtc
= encoder
->crtc
;
10137 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10138 struct drm_atomic_state
*state
;
10139 struct drm_connector_state
*connector_state
;
10140 struct intel_crtc_state
*crtc_state
;
10143 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10144 connector
->base
.id
, connector
->name
,
10145 encoder
->base
.id
, encoder
->name
);
10147 if (old
->load_detect_temp
) {
10148 state
= drm_atomic_state_alloc(dev
);
10152 state
->acquire_ctx
= ctx
;
10154 connector_state
= drm_atomic_get_connector_state(state
, connector
);
10155 if (IS_ERR(connector_state
))
10158 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
10159 if (IS_ERR(crtc_state
))
10162 to_intel_connector(connector
)->new_encoder
= NULL
;
10163 intel_encoder
->new_crtc
= NULL
;
10164 intel_crtc
->new_enabled
= false;
10166 connector_state
->best_encoder
= NULL
;
10167 connector_state
->crtc
= NULL
;
10169 crtc_state
->base
.enable
= crtc_state
->base
.active
= false;
10171 ret
= intel_modeset_setup_plane_state(state
, crtc
, NULL
, NULL
,
10176 ret
= intel_set_mode(crtc
, state
);
10180 if (old
->release_fb
) {
10181 drm_framebuffer_unregister_private(old
->release_fb
);
10182 drm_framebuffer_unreference(old
->release_fb
);
10188 /* Switch crtc and encoder back off if necessary */
10189 if (old
->dpms_mode
!= DRM_MODE_DPMS_ON
)
10190 connector
->funcs
->dpms(connector
, old
->dpms_mode
);
10194 DRM_DEBUG_KMS("Couldn't release load detect pipe.\n");
10195 drm_atomic_state_free(state
);
10198 static int i9xx_pll_refclk(struct drm_device
*dev
,
10199 const struct intel_crtc_state
*pipe_config
)
10201 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10202 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
10204 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
10205 return dev_priv
->vbt
.lvds_ssc_freq
;
10206 else if (HAS_PCH_SPLIT(dev
))
10208 else if (!IS_GEN2(dev
))
10214 /* Returns the clock of the currently programmed mode of the given pipe. */
10215 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
10216 struct intel_crtc_state
*pipe_config
)
10218 struct drm_device
*dev
= crtc
->base
.dev
;
10219 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10220 int pipe
= pipe_config
->cpu_transcoder
;
10221 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
10223 intel_clock_t clock
;
10224 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
10226 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
10227 fp
= pipe_config
->dpll_hw_state
.fp0
;
10229 fp
= pipe_config
->dpll_hw_state
.fp1
;
10231 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
10232 if (IS_PINEVIEW(dev
)) {
10233 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
10234 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
10236 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
10237 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
10240 if (!IS_GEN2(dev
)) {
10241 if (IS_PINEVIEW(dev
))
10242 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
10243 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
10245 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
10246 DPLL_FPA01_P1_POST_DIV_SHIFT
);
10248 switch (dpll
& DPLL_MODE_MASK
) {
10249 case DPLLB_MODE_DAC_SERIAL
:
10250 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
10253 case DPLLB_MODE_LVDS
:
10254 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
10258 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10259 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
10263 if (IS_PINEVIEW(dev
))
10264 pineview_clock(refclk
, &clock
);
10266 i9xx_clock(refclk
, &clock
);
10268 u32 lvds
= IS_I830(dev
) ? 0 : I915_READ(LVDS
);
10269 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
10272 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
10273 DPLL_FPA01_P1_POST_DIV_SHIFT
);
10275 if (lvds
& LVDS_CLKB_POWER_UP
)
10280 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
10283 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
10284 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
10286 if (dpll
& PLL_P2_DIVIDE_BY_4
)
10292 i9xx_clock(refclk
, &clock
);
10296 * This value includes pixel_multiplier. We will use
10297 * port_clock to compute adjusted_mode.crtc_clock in the
10298 * encoder's get_config() function.
10300 pipe_config
->port_clock
= clock
.dot
;
10303 int intel_dotclock_calculate(int link_freq
,
10304 const struct intel_link_m_n
*m_n
)
10307 * The calculation for the data clock is:
10308 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10309 * But we want to avoid losing precison if possible, so:
10310 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10312 * and the link clock is simpler:
10313 * link_clock = (m * link_clock) / n
10319 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
10322 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
10323 struct intel_crtc_state
*pipe_config
)
10325 struct drm_device
*dev
= crtc
->base
.dev
;
10327 /* read out port_clock from the DPLL */
10328 i9xx_crtc_clock_get(crtc
, pipe_config
);
10331 * This value does not include pixel_multiplier.
10332 * We will check that port_clock and adjusted_mode.crtc_clock
10333 * agree once we know their relationship in the encoder's
10334 * get_config() function.
10336 pipe_config
->base
.adjusted_mode
.crtc_clock
=
10337 intel_dotclock_calculate(intel_fdi_link_freq(dev
) * 10000,
10338 &pipe_config
->fdi_m_n
);
10341 /** Returns the currently programmed mode of the given pipe. */
10342 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
10343 struct drm_crtc
*crtc
)
10345 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10346 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10347 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
10348 struct drm_display_mode
*mode
;
10349 struct intel_crtc_state pipe_config
;
10350 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
10351 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
10352 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
10353 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
10354 enum pipe pipe
= intel_crtc
->pipe
;
10356 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
10361 * Construct a pipe_config sufficient for getting the clock info
10362 * back out of crtc_clock_get.
10364 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
10365 * to use a real value here instead.
10367 pipe_config
.cpu_transcoder
= (enum transcoder
) pipe
;
10368 pipe_config
.pixel_multiplier
= 1;
10369 pipe_config
.dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
10370 pipe_config
.dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
10371 pipe_config
.dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
10372 i9xx_crtc_clock_get(intel_crtc
, &pipe_config
);
10374 mode
->clock
= pipe_config
.port_clock
/ pipe_config
.pixel_multiplier
;
10375 mode
->hdisplay
= (htot
& 0xffff) + 1;
10376 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
10377 mode
->hsync_start
= (hsync
& 0xffff) + 1;
10378 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
10379 mode
->vdisplay
= (vtot
& 0xffff) + 1;
10380 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
10381 mode
->vsync_start
= (vsync
& 0xffff) + 1;
10382 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
10384 drm_mode_set_name(mode
);
10389 static void intel_decrease_pllclock(struct drm_crtc
*crtc
)
10391 struct drm_device
*dev
= crtc
->dev
;
10392 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10393 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10395 if (!HAS_GMCH_DISPLAY(dev
))
10398 if (!dev_priv
->lvds_downclock_avail
)
10402 * Since this is called by a timer, we should never get here in
10405 if (!HAS_PIPE_CXSR(dev
) && intel_crtc
->lowfreq_avail
) {
10406 int pipe
= intel_crtc
->pipe
;
10407 int dpll_reg
= DPLL(pipe
);
10410 DRM_DEBUG_DRIVER("downclocking LVDS\n");
10412 assert_panel_unlocked(dev_priv
, pipe
);
10414 dpll
= I915_READ(dpll_reg
);
10415 dpll
|= DISPLAY_RATE_SELECT_FPA1
;
10416 I915_WRITE(dpll_reg
, dpll
);
10417 intel_wait_for_vblank(dev
, pipe
);
10418 dpll
= I915_READ(dpll_reg
);
10419 if (!(dpll
& DISPLAY_RATE_SELECT_FPA1
))
10420 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
10425 void intel_mark_busy(struct drm_device
*dev
)
10427 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10429 if (dev_priv
->mm
.busy
)
10432 intel_runtime_pm_get(dev_priv
);
10433 i915_update_gfx_val(dev_priv
);
10434 if (INTEL_INFO(dev
)->gen
>= 6)
10435 gen6_rps_busy(dev_priv
);
10436 dev_priv
->mm
.busy
= true;
10439 void intel_mark_idle(struct drm_device
*dev
)
10441 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10442 struct drm_crtc
*crtc
;
10444 if (!dev_priv
->mm
.busy
)
10447 dev_priv
->mm
.busy
= false;
10449 for_each_crtc(dev
, crtc
) {
10450 if (!crtc
->primary
->fb
)
10453 intel_decrease_pllclock(crtc
);
10456 if (INTEL_INFO(dev
)->gen
>= 6)
10457 gen6_rps_idle(dev
->dev_private
);
10459 intel_runtime_pm_put(dev_priv
);
10462 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
10464 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10465 struct drm_device
*dev
= crtc
->dev
;
10466 struct intel_unpin_work
*work
;
10468 spin_lock_irq(&dev
->event_lock
);
10469 work
= intel_crtc
->unpin_work
;
10470 intel_crtc
->unpin_work
= NULL
;
10471 spin_unlock_irq(&dev
->event_lock
);
10474 cancel_work_sync(&work
->work
);
10478 drm_crtc_cleanup(crtc
);
10483 static void intel_unpin_work_fn(struct work_struct
*__work
)
10485 struct intel_unpin_work
*work
=
10486 container_of(__work
, struct intel_unpin_work
, work
);
10487 struct drm_device
*dev
= work
->crtc
->dev
;
10488 enum pipe pipe
= to_intel_crtc(work
->crtc
)->pipe
;
10490 mutex_lock(&dev
->struct_mutex
);
10491 intel_unpin_fb_obj(work
->old_fb
, work
->crtc
->primary
->state
);
10492 drm_gem_object_unreference(&work
->pending_flip_obj
->base
);
10494 intel_fbc_update(dev
);
10496 if (work
->flip_queued_req
)
10497 i915_gem_request_assign(&work
->flip_queued_req
, NULL
);
10498 mutex_unlock(&dev
->struct_mutex
);
10500 intel_frontbuffer_flip_complete(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
10501 drm_framebuffer_unreference(work
->old_fb
);
10503 BUG_ON(atomic_read(&to_intel_crtc(work
->crtc
)->unpin_work_count
) == 0);
10504 atomic_dec(&to_intel_crtc(work
->crtc
)->unpin_work_count
);
10509 static void do_intel_finish_page_flip(struct drm_device
*dev
,
10510 struct drm_crtc
*crtc
)
10512 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10513 struct intel_unpin_work
*work
;
10514 unsigned long flags
;
10516 /* Ignore early vblank irqs */
10517 if (intel_crtc
== NULL
)
10521 * This is called both by irq handlers and the reset code (to complete
10522 * lost pageflips) so needs the full irqsave spinlocks.
10524 spin_lock_irqsave(&dev
->event_lock
, flags
);
10525 work
= intel_crtc
->unpin_work
;
10527 /* Ensure we don't miss a work->pending update ... */
10530 if (work
== NULL
|| atomic_read(&work
->pending
) < INTEL_FLIP_COMPLETE
) {
10531 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
10535 page_flip_completed(intel_crtc
);
10537 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
10540 void intel_finish_page_flip(struct drm_device
*dev
, int pipe
)
10542 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10543 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
10545 do_intel_finish_page_flip(dev
, crtc
);
10548 void intel_finish_page_flip_plane(struct drm_device
*dev
, int plane
)
10550 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10551 struct drm_crtc
*crtc
= dev_priv
->plane_to_crtc_mapping
[plane
];
10553 do_intel_finish_page_flip(dev
, crtc
);
10556 /* Is 'a' after or equal to 'b'? */
10557 static bool g4x_flip_count_after_eq(u32 a
, u32 b
)
10559 return !((a
- b
) & 0x80000000);
10562 static bool page_flip_finished(struct intel_crtc
*crtc
)
10564 struct drm_device
*dev
= crtc
->base
.dev
;
10565 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10567 if (i915_reset_in_progress(&dev_priv
->gpu_error
) ||
10568 crtc
->reset_counter
!= atomic_read(&dev_priv
->gpu_error
.reset_counter
))
10572 * The relevant registers doen't exist on pre-ctg.
10573 * As the flip done interrupt doesn't trigger for mmio
10574 * flips on gmch platforms, a flip count check isn't
10575 * really needed there. But since ctg has the registers,
10576 * include it in the check anyway.
10578 if (INTEL_INFO(dev
)->gen
< 5 && !IS_G4X(dev
))
10582 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
10583 * used the same base address. In that case the mmio flip might
10584 * have completed, but the CS hasn't even executed the flip yet.
10586 * A flip count check isn't enough as the CS might have updated
10587 * the base address just after start of vblank, but before we
10588 * managed to process the interrupt. This means we'd complete the
10589 * CS flip too soon.
10591 * Combining both checks should get us a good enough result. It may
10592 * still happen that the CS flip has been executed, but has not
10593 * yet actually completed. But in case the base address is the same
10594 * anyway, we don't really care.
10596 return (I915_READ(DSPSURFLIVE(crtc
->plane
)) & ~0xfff) ==
10597 crtc
->unpin_work
->gtt_offset
&&
10598 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc
->pipe
)),
10599 crtc
->unpin_work
->flip_count
);
10602 void intel_prepare_page_flip(struct drm_device
*dev
, int plane
)
10604 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10605 struct intel_crtc
*intel_crtc
=
10606 to_intel_crtc(dev_priv
->plane_to_crtc_mapping
[plane
]);
10607 unsigned long flags
;
10611 * This is called both by irq handlers and the reset code (to complete
10612 * lost pageflips) so needs the full irqsave spinlocks.
10614 * NB: An MMIO update of the plane base pointer will also
10615 * generate a page-flip completion irq, i.e. every modeset
10616 * is also accompanied by a spurious intel_prepare_page_flip().
10618 spin_lock_irqsave(&dev
->event_lock
, flags
);
10619 if (intel_crtc
->unpin_work
&& page_flip_finished(intel_crtc
))
10620 atomic_inc_not_zero(&intel_crtc
->unpin_work
->pending
);
10621 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
10624 static inline void intel_mark_page_flip_active(struct intel_crtc
*intel_crtc
)
10626 /* Ensure that the work item is consistent when activating it ... */
10628 atomic_set(&intel_crtc
->unpin_work
->pending
, INTEL_FLIP_PENDING
);
10629 /* and that it is marked active as soon as the irq could fire. */
10633 static int intel_gen2_queue_flip(struct drm_device
*dev
,
10634 struct drm_crtc
*crtc
,
10635 struct drm_framebuffer
*fb
,
10636 struct drm_i915_gem_object
*obj
,
10637 struct intel_engine_cs
*ring
,
10640 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10644 ret
= intel_ring_begin(ring
, 6);
10648 /* Can't queue multiple flips, so wait for the previous
10649 * one to finish before executing the next.
10651 if (intel_crtc
->plane
)
10652 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
10654 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
10655 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
10656 intel_ring_emit(ring
, MI_NOOP
);
10657 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
10658 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
10659 intel_ring_emit(ring
, fb
->pitches
[0]);
10660 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
10661 intel_ring_emit(ring
, 0); /* aux display base address, unused */
10663 intel_mark_page_flip_active(intel_crtc
);
10664 __intel_ring_advance(ring
);
10668 static int intel_gen3_queue_flip(struct drm_device
*dev
,
10669 struct drm_crtc
*crtc
,
10670 struct drm_framebuffer
*fb
,
10671 struct drm_i915_gem_object
*obj
,
10672 struct intel_engine_cs
*ring
,
10675 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10679 ret
= intel_ring_begin(ring
, 6);
10683 if (intel_crtc
->plane
)
10684 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
10686 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
10687 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
10688 intel_ring_emit(ring
, MI_NOOP
);
10689 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
|
10690 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
10691 intel_ring_emit(ring
, fb
->pitches
[0]);
10692 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
10693 intel_ring_emit(ring
, MI_NOOP
);
10695 intel_mark_page_flip_active(intel_crtc
);
10696 __intel_ring_advance(ring
);
10700 static int intel_gen4_queue_flip(struct drm_device
*dev
,
10701 struct drm_crtc
*crtc
,
10702 struct drm_framebuffer
*fb
,
10703 struct drm_i915_gem_object
*obj
,
10704 struct intel_engine_cs
*ring
,
10707 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10708 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10709 uint32_t pf
, pipesrc
;
10712 ret
= intel_ring_begin(ring
, 4);
10716 /* i965+ uses the linear or tiled offsets from the
10717 * Display Registers (which do not change across a page-flip)
10718 * so we need only reprogram the base address.
10720 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
10721 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
10722 intel_ring_emit(ring
, fb
->pitches
[0]);
10723 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
|
10726 /* XXX Enabling the panel-fitter across page-flip is so far
10727 * untested on non-native modes, so ignore it for now.
10728 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
10731 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
10732 intel_ring_emit(ring
, pf
| pipesrc
);
10734 intel_mark_page_flip_active(intel_crtc
);
10735 __intel_ring_advance(ring
);
10739 static int intel_gen6_queue_flip(struct drm_device
*dev
,
10740 struct drm_crtc
*crtc
,
10741 struct drm_framebuffer
*fb
,
10742 struct drm_i915_gem_object
*obj
,
10743 struct intel_engine_cs
*ring
,
10746 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10747 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10748 uint32_t pf
, pipesrc
;
10751 ret
= intel_ring_begin(ring
, 4);
10755 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
10756 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
10757 intel_ring_emit(ring
, fb
->pitches
[0] | obj
->tiling_mode
);
10758 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
10760 /* Contrary to the suggestions in the documentation,
10761 * "Enable Panel Fitter" does not seem to be required when page
10762 * flipping with a non-native mode, and worse causes a normal
10764 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
10767 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
10768 intel_ring_emit(ring
, pf
| pipesrc
);
10770 intel_mark_page_flip_active(intel_crtc
);
10771 __intel_ring_advance(ring
);
10775 static int intel_gen7_queue_flip(struct drm_device
*dev
,
10776 struct drm_crtc
*crtc
,
10777 struct drm_framebuffer
*fb
,
10778 struct drm_i915_gem_object
*obj
,
10779 struct intel_engine_cs
*ring
,
10782 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10783 uint32_t plane_bit
= 0;
10786 switch (intel_crtc
->plane
) {
10788 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
10791 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
10794 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
10797 WARN_ONCE(1, "unknown plane in flip command\n");
10802 if (ring
->id
== RCS
) {
10805 * On Gen 8, SRM is now taking an extra dword to accommodate
10806 * 48bits addresses, and we need a NOOP for the batch size to
10814 * BSpec MI_DISPLAY_FLIP for IVB:
10815 * "The full packet must be contained within the same cache line."
10817 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
10818 * cacheline, if we ever start emitting more commands before
10819 * the MI_DISPLAY_FLIP we may need to first emit everything else,
10820 * then do the cacheline alignment, and finally emit the
10823 ret
= intel_ring_cacheline_align(ring
);
10827 ret
= intel_ring_begin(ring
, len
);
10831 /* Unmask the flip-done completion message. Note that the bspec says that
10832 * we should do this for both the BCS and RCS, and that we must not unmask
10833 * more than one flip event at any time (or ensure that one flip message
10834 * can be sent by waiting for flip-done prior to queueing new flips).
10835 * Experimentation says that BCS works despite DERRMR masking all
10836 * flip-done completion events and that unmasking all planes at once
10837 * for the RCS also doesn't appear to drop events. Setting the DERRMR
10838 * to zero does lead to lockups within MI_DISPLAY_FLIP.
10840 if (ring
->id
== RCS
) {
10841 intel_ring_emit(ring
, MI_LOAD_REGISTER_IMM(1));
10842 intel_ring_emit(ring
, DERRMR
);
10843 intel_ring_emit(ring
, ~(DERRMR_PIPEA_PRI_FLIP_DONE
|
10844 DERRMR_PIPEB_PRI_FLIP_DONE
|
10845 DERRMR_PIPEC_PRI_FLIP_DONE
));
10847 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM_GEN8(1) |
10848 MI_SRM_LRM_GLOBAL_GTT
);
10850 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM(1) |
10851 MI_SRM_LRM_GLOBAL_GTT
);
10852 intel_ring_emit(ring
, DERRMR
);
10853 intel_ring_emit(ring
, ring
->scratch
.gtt_offset
+ 256);
10854 if (IS_GEN8(dev
)) {
10855 intel_ring_emit(ring
, 0);
10856 intel_ring_emit(ring
, MI_NOOP
);
10860 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
| plane_bit
);
10861 intel_ring_emit(ring
, (fb
->pitches
[0] | obj
->tiling_mode
));
10862 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
10863 intel_ring_emit(ring
, (MI_NOOP
));
10865 intel_mark_page_flip_active(intel_crtc
);
10866 __intel_ring_advance(ring
);
10870 static bool use_mmio_flip(struct intel_engine_cs
*ring
,
10871 struct drm_i915_gem_object
*obj
)
10874 * This is not being used for older platforms, because
10875 * non-availability of flip done interrupt forces us to use
10876 * CS flips. Older platforms derive flip done using some clever
10877 * tricks involving the flip_pending status bits and vblank irqs.
10878 * So using MMIO flips there would disrupt this mechanism.
10884 if (INTEL_INFO(ring
->dev
)->gen
< 5)
10887 if (i915
.use_mmio_flip
< 0)
10889 else if (i915
.use_mmio_flip
> 0)
10891 else if (i915
.enable_execlists
)
10894 return ring
!= i915_gem_request_get_ring(obj
->last_write_req
);
10897 static void skl_do_mmio_flip(struct intel_crtc
*intel_crtc
)
10899 struct drm_device
*dev
= intel_crtc
->base
.dev
;
10900 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10901 struct drm_framebuffer
*fb
= intel_crtc
->base
.primary
->fb
;
10902 const enum pipe pipe
= intel_crtc
->pipe
;
10905 ctl
= I915_READ(PLANE_CTL(pipe
, 0));
10906 ctl
&= ~PLANE_CTL_TILED_MASK
;
10907 switch (fb
->modifier
[0]) {
10908 case DRM_FORMAT_MOD_NONE
:
10910 case I915_FORMAT_MOD_X_TILED
:
10911 ctl
|= PLANE_CTL_TILED_X
;
10913 case I915_FORMAT_MOD_Y_TILED
:
10914 ctl
|= PLANE_CTL_TILED_Y
;
10916 case I915_FORMAT_MOD_Yf_TILED
:
10917 ctl
|= PLANE_CTL_TILED_YF
;
10920 MISSING_CASE(fb
->modifier
[0]);
10924 * The stride is either expressed as a multiple of 64 bytes chunks for
10925 * linear buffers or in number of tiles for tiled buffers.
10927 stride
= fb
->pitches
[0] /
10928 intel_fb_stride_alignment(dev
, fb
->modifier
[0],
10932 * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on
10933 * PLANE_SURF updates, the update is then guaranteed to be atomic.
10935 I915_WRITE(PLANE_CTL(pipe
, 0), ctl
);
10936 I915_WRITE(PLANE_STRIDE(pipe
, 0), stride
);
10938 I915_WRITE(PLANE_SURF(pipe
, 0), intel_crtc
->unpin_work
->gtt_offset
);
10939 POSTING_READ(PLANE_SURF(pipe
, 0));
10942 static void ilk_do_mmio_flip(struct intel_crtc
*intel_crtc
)
10944 struct drm_device
*dev
= intel_crtc
->base
.dev
;
10945 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10946 struct intel_framebuffer
*intel_fb
=
10947 to_intel_framebuffer(intel_crtc
->base
.primary
->fb
);
10948 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
10952 reg
= DSPCNTR(intel_crtc
->plane
);
10953 dspcntr
= I915_READ(reg
);
10955 if (obj
->tiling_mode
!= I915_TILING_NONE
)
10956 dspcntr
|= DISPPLANE_TILED
;
10958 dspcntr
&= ~DISPPLANE_TILED
;
10960 I915_WRITE(reg
, dspcntr
);
10962 I915_WRITE(DSPSURF(intel_crtc
->plane
),
10963 intel_crtc
->unpin_work
->gtt_offset
);
10964 POSTING_READ(DSPSURF(intel_crtc
->plane
));
10969 * XXX: This is the temporary way to update the plane registers until we get
10970 * around to using the usual plane update functions for MMIO flips
10972 static void intel_do_mmio_flip(struct intel_crtc
*intel_crtc
)
10974 struct drm_device
*dev
= intel_crtc
->base
.dev
;
10975 bool atomic_update
;
10976 u32 start_vbl_count
;
10978 intel_mark_page_flip_active(intel_crtc
);
10980 atomic_update
= intel_pipe_update_start(intel_crtc
, &start_vbl_count
);
10982 if (INTEL_INFO(dev
)->gen
>= 9)
10983 skl_do_mmio_flip(intel_crtc
);
10985 /* use_mmio_flip() retricts MMIO flips to ilk+ */
10986 ilk_do_mmio_flip(intel_crtc
);
10989 intel_pipe_update_end(intel_crtc
, start_vbl_count
);
10992 static void intel_mmio_flip_work_func(struct work_struct
*work
)
10994 struct intel_mmio_flip
*mmio_flip
=
10995 container_of(work
, struct intel_mmio_flip
, work
);
10997 if (mmio_flip
->req
)
10998 WARN_ON(__i915_wait_request(mmio_flip
->req
,
10999 mmio_flip
->crtc
->reset_counter
,
11001 &mmio_flip
->i915
->rps
.mmioflips
));
11003 intel_do_mmio_flip(mmio_flip
->crtc
);
11005 i915_gem_request_unreference__unlocked(mmio_flip
->req
);
11009 static int intel_queue_mmio_flip(struct drm_device
*dev
,
11010 struct drm_crtc
*crtc
,
11011 struct drm_framebuffer
*fb
,
11012 struct drm_i915_gem_object
*obj
,
11013 struct intel_engine_cs
*ring
,
11016 struct intel_mmio_flip
*mmio_flip
;
11018 mmio_flip
= kmalloc(sizeof(*mmio_flip
), GFP_KERNEL
);
11019 if (mmio_flip
== NULL
)
11022 mmio_flip
->i915
= to_i915(dev
);
11023 mmio_flip
->req
= i915_gem_request_reference(obj
->last_write_req
);
11024 mmio_flip
->crtc
= to_intel_crtc(crtc
);
11026 INIT_WORK(&mmio_flip
->work
, intel_mmio_flip_work_func
);
11027 schedule_work(&mmio_flip
->work
);
11032 static int intel_default_queue_flip(struct drm_device
*dev
,
11033 struct drm_crtc
*crtc
,
11034 struct drm_framebuffer
*fb
,
11035 struct drm_i915_gem_object
*obj
,
11036 struct intel_engine_cs
*ring
,
11042 static bool __intel_pageflip_stall_check(struct drm_device
*dev
,
11043 struct drm_crtc
*crtc
)
11045 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11046 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11047 struct intel_unpin_work
*work
= intel_crtc
->unpin_work
;
11050 if (atomic_read(&work
->pending
) >= INTEL_FLIP_COMPLETE
)
11053 if (!work
->enable_stall_check
)
11056 if (work
->flip_ready_vblank
== 0) {
11057 if (work
->flip_queued_req
&&
11058 !i915_gem_request_completed(work
->flip_queued_req
, true))
11061 work
->flip_ready_vblank
= drm_crtc_vblank_count(crtc
);
11064 if (drm_crtc_vblank_count(crtc
) - work
->flip_ready_vblank
< 3)
11067 /* Potential stall - if we see that the flip has happened,
11068 * assume a missed interrupt. */
11069 if (INTEL_INFO(dev
)->gen
>= 4)
11070 addr
= I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc
->plane
)));
11072 addr
= I915_READ(DSPADDR(intel_crtc
->plane
));
11074 /* There is a potential issue here with a false positive after a flip
11075 * to the same address. We could address this by checking for a
11076 * non-incrementing frame counter.
11078 return addr
== work
->gtt_offset
;
11081 void intel_check_page_flip(struct drm_device
*dev
, int pipe
)
11083 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11084 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
11085 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11086 struct intel_unpin_work
*work
;
11088 WARN_ON(!in_interrupt());
11093 spin_lock(&dev
->event_lock
);
11094 work
= intel_crtc
->unpin_work
;
11095 if (work
!= NULL
&& __intel_pageflip_stall_check(dev
, crtc
)) {
11096 WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n",
11097 work
->flip_queued_vblank
, drm_vblank_count(dev
, pipe
));
11098 page_flip_completed(intel_crtc
);
11101 if (work
!= NULL
&&
11102 drm_vblank_count(dev
, pipe
) - work
->flip_queued_vblank
> 1)
11103 intel_queue_rps_boost_for_request(dev
, work
->flip_queued_req
);
11104 spin_unlock(&dev
->event_lock
);
11107 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
11108 struct drm_framebuffer
*fb
,
11109 struct drm_pending_vblank_event
*event
,
11110 uint32_t page_flip_flags
)
11112 struct drm_device
*dev
= crtc
->dev
;
11113 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11114 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
11115 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
11116 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11117 struct drm_plane
*primary
= crtc
->primary
;
11118 enum pipe pipe
= intel_crtc
->pipe
;
11119 struct intel_unpin_work
*work
;
11120 struct intel_engine_cs
*ring
;
11125 * drm_mode_page_flip_ioctl() should already catch this, but double
11126 * check to be safe. In the future we may enable pageflipping from
11127 * a disabled primary plane.
11129 if (WARN_ON(intel_fb_obj(old_fb
) == NULL
))
11132 /* Can't change pixel format via MI display flips. */
11133 if (fb
->pixel_format
!= crtc
->primary
->fb
->pixel_format
)
11137 * TILEOFF/LINOFF registers can't be changed via MI display flips.
11138 * Note that pitch changes could also affect these register.
11140 if (INTEL_INFO(dev
)->gen
> 3 &&
11141 (fb
->offsets
[0] != crtc
->primary
->fb
->offsets
[0] ||
11142 fb
->pitches
[0] != crtc
->primary
->fb
->pitches
[0]))
11145 if (i915_terminally_wedged(&dev_priv
->gpu_error
))
11148 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
11152 work
->event
= event
;
11154 work
->old_fb
= old_fb
;
11155 INIT_WORK(&work
->work
, intel_unpin_work_fn
);
11157 ret
= drm_crtc_vblank_get(crtc
);
11161 /* We borrow the event spin lock for protecting unpin_work */
11162 spin_lock_irq(&dev
->event_lock
);
11163 if (intel_crtc
->unpin_work
) {
11164 /* Before declaring the flip queue wedged, check if
11165 * the hardware completed the operation behind our backs.
11167 if (__intel_pageflip_stall_check(dev
, crtc
)) {
11168 DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
11169 page_flip_completed(intel_crtc
);
11171 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
11172 spin_unlock_irq(&dev
->event_lock
);
11174 drm_crtc_vblank_put(crtc
);
11179 intel_crtc
->unpin_work
= work
;
11180 spin_unlock_irq(&dev
->event_lock
);
11182 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
11183 flush_workqueue(dev_priv
->wq
);
11185 /* Reference the objects for the scheduled work. */
11186 drm_framebuffer_reference(work
->old_fb
);
11187 drm_gem_object_reference(&obj
->base
);
11189 crtc
->primary
->fb
= fb
;
11190 update_state_fb(crtc
->primary
);
11192 work
->pending_flip_obj
= obj
;
11194 ret
= i915_mutex_lock_interruptible(dev
);
11198 atomic_inc(&intel_crtc
->unpin_work_count
);
11199 intel_crtc
->reset_counter
= atomic_read(&dev_priv
->gpu_error
.reset_counter
);
11201 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
11202 work
->flip_count
= I915_READ(PIPE_FLIPCOUNT_GM45(pipe
)) + 1;
11204 if (IS_VALLEYVIEW(dev
)) {
11205 ring
= &dev_priv
->ring
[BCS
];
11206 if (obj
->tiling_mode
!= intel_fb_obj(work
->old_fb
)->tiling_mode
)
11207 /* vlv: DISPLAY_FLIP fails to change tiling */
11209 } else if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
)) {
11210 ring
= &dev_priv
->ring
[BCS
];
11211 } else if (INTEL_INFO(dev
)->gen
>= 7) {
11212 ring
= i915_gem_request_get_ring(obj
->last_write_req
);
11213 if (ring
== NULL
|| ring
->id
!= RCS
)
11214 ring
= &dev_priv
->ring
[BCS
];
11216 ring
= &dev_priv
->ring
[RCS
];
11219 mmio_flip
= use_mmio_flip(ring
, obj
);
11221 /* When using CS flips, we want to emit semaphores between rings.
11222 * However, when using mmio flips we will create a task to do the
11223 * synchronisation, so all we want here is to pin the framebuffer
11224 * into the display plane and skip any waits.
11226 ret
= intel_pin_and_fence_fb_obj(crtc
->primary
, fb
,
11227 crtc
->primary
->state
,
11228 mmio_flip
? i915_gem_request_get_ring(obj
->last_write_req
) : ring
);
11230 goto cleanup_pending
;
11232 work
->gtt_offset
= intel_plane_obj_offset(to_intel_plane(primary
), obj
)
11233 + intel_crtc
->dspaddr_offset
;
11236 ret
= intel_queue_mmio_flip(dev
, crtc
, fb
, obj
, ring
,
11239 goto cleanup_unpin
;
11241 i915_gem_request_assign(&work
->flip_queued_req
,
11242 obj
->last_write_req
);
11244 if (obj
->last_write_req
) {
11245 ret
= i915_gem_check_olr(obj
->last_write_req
);
11247 goto cleanup_unpin
;
11250 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
, ring
,
11253 goto cleanup_unpin
;
11255 i915_gem_request_assign(&work
->flip_queued_req
,
11256 intel_ring_get_request(ring
));
11259 work
->flip_queued_vblank
= drm_crtc_vblank_count(crtc
);
11260 work
->enable_stall_check
= true;
11262 i915_gem_track_fb(intel_fb_obj(work
->old_fb
), obj
,
11263 INTEL_FRONTBUFFER_PRIMARY(pipe
));
11265 intel_fbc_disable(dev
);
11266 intel_frontbuffer_flip_prepare(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
11267 mutex_unlock(&dev
->struct_mutex
);
11269 trace_i915_flip_request(intel_crtc
->plane
, obj
);
11274 intel_unpin_fb_obj(fb
, crtc
->primary
->state
);
11276 atomic_dec(&intel_crtc
->unpin_work_count
);
11277 mutex_unlock(&dev
->struct_mutex
);
11279 crtc
->primary
->fb
= old_fb
;
11280 update_state_fb(crtc
->primary
);
11282 drm_gem_object_unreference_unlocked(&obj
->base
);
11283 drm_framebuffer_unreference(work
->old_fb
);
11285 spin_lock_irq(&dev
->event_lock
);
11286 intel_crtc
->unpin_work
= NULL
;
11287 spin_unlock_irq(&dev
->event_lock
);
11289 drm_crtc_vblank_put(crtc
);
11295 ret
= intel_plane_restore(primary
);
11296 if (ret
== 0 && event
) {
11297 spin_lock_irq(&dev
->event_lock
);
11298 drm_send_vblank_event(dev
, pipe
, event
);
11299 spin_unlock_irq(&dev
->event_lock
);
11305 static const struct drm_crtc_helper_funcs intel_helper_funcs
= {
11306 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
11307 .load_lut
= intel_crtc_load_lut
,
11308 .atomic_begin
= intel_begin_crtc_commit
,
11309 .atomic_flush
= intel_finish_crtc_commit
,
11313 * intel_modeset_update_staged_output_state
11315 * Updates the staged output configuration state, e.g. after we've read out the
11316 * current hw state.
11318 static void intel_modeset_update_staged_output_state(struct drm_device
*dev
)
11320 struct intel_crtc
*crtc
;
11321 struct intel_encoder
*encoder
;
11322 struct intel_connector
*connector
;
11324 for_each_intel_connector(dev
, connector
) {
11325 connector
->new_encoder
=
11326 to_intel_encoder(connector
->base
.encoder
);
11329 for_each_intel_encoder(dev
, encoder
) {
11330 encoder
->new_crtc
=
11331 to_intel_crtc(encoder
->base
.crtc
);
11334 for_each_intel_crtc(dev
, crtc
) {
11335 crtc
->new_enabled
= crtc
->base
.state
->enable
;
11339 /* Transitional helper to copy current connector/encoder state to
11340 * connector->state. This is needed so that code that is partially
11341 * converted to atomic does the right thing.
11343 static void intel_modeset_update_connector_atomic_state(struct drm_device
*dev
)
11345 struct intel_connector
*connector
;
11347 for_each_intel_connector(dev
, connector
) {
11348 if (connector
->base
.encoder
) {
11349 connector
->base
.state
->best_encoder
=
11350 connector
->base
.encoder
;
11351 connector
->base
.state
->crtc
=
11352 connector
->base
.encoder
->crtc
;
11354 connector
->base
.state
->best_encoder
= NULL
;
11355 connector
->base
.state
->crtc
= NULL
;
11360 /* Fixup legacy state after an atomic state swap.
11362 static void intel_modeset_fixup_state(struct drm_atomic_state
*state
)
11364 struct intel_crtc
*crtc
;
11365 struct intel_encoder
*encoder
;
11366 struct intel_connector
*connector
;
11368 for_each_intel_connector(state
->dev
, connector
) {
11369 connector
->base
.encoder
= connector
->base
.state
->best_encoder
;
11370 if (connector
->base
.encoder
)
11371 connector
->base
.encoder
->crtc
=
11372 connector
->base
.state
->crtc
;
11375 /* Update crtc of disabled encoders */
11376 for_each_intel_encoder(state
->dev
, encoder
) {
11377 int num_connectors
= 0;
11379 for_each_intel_connector(state
->dev
, connector
)
11380 if (connector
->base
.encoder
== &encoder
->base
)
11383 if (num_connectors
== 0)
11384 encoder
->base
.crtc
= NULL
;
11387 for_each_intel_crtc(state
->dev
, crtc
) {
11388 crtc
->base
.enabled
= crtc
->base
.state
->enable
;
11389 crtc
->config
= to_intel_crtc_state(crtc
->base
.state
);
11392 /* Copy the new configuration to the staged state, to keep the few
11393 * pieces of code that haven't been converted yet happy */
11394 intel_modeset_update_staged_output_state(state
->dev
);
11398 connected_sink_compute_bpp(struct intel_connector
*connector
,
11399 struct intel_crtc_state
*pipe_config
)
11401 int bpp
= pipe_config
->pipe_bpp
;
11403 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
11404 connector
->base
.base
.id
,
11405 connector
->base
.name
);
11407 /* Don't use an invalid EDID bpc value */
11408 if (connector
->base
.display_info
.bpc
&&
11409 connector
->base
.display_info
.bpc
* 3 < bpp
) {
11410 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
11411 bpp
, connector
->base
.display_info
.bpc
*3);
11412 pipe_config
->pipe_bpp
= connector
->base
.display_info
.bpc
*3;
11415 /* Clamp bpp to 8 on screens without EDID 1.4 */
11416 if (connector
->base
.display_info
.bpc
== 0 && bpp
> 24) {
11417 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
11419 pipe_config
->pipe_bpp
= 24;
11424 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
11425 struct intel_crtc_state
*pipe_config
)
11427 struct drm_device
*dev
= crtc
->base
.dev
;
11428 struct drm_atomic_state
*state
;
11429 struct drm_connector
*connector
;
11430 struct drm_connector_state
*connector_state
;
11433 if ((IS_G4X(dev
) || IS_VALLEYVIEW(dev
)))
11435 else if (INTEL_INFO(dev
)->gen
>= 5)
11441 pipe_config
->pipe_bpp
= bpp
;
11443 state
= pipe_config
->base
.state
;
11445 /* Clamp display bpp to EDID value */
11446 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11447 if (connector_state
->crtc
!= &crtc
->base
)
11450 connected_sink_compute_bpp(to_intel_connector(connector
),
11457 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
11459 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11460 "type: 0x%x flags: 0x%x\n",
11462 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
11463 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
11464 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
11465 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
11468 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
11469 struct intel_crtc_state
*pipe_config
,
11470 const char *context
)
11472 struct drm_device
*dev
= crtc
->base
.dev
;
11473 struct drm_plane
*plane
;
11474 struct intel_plane
*intel_plane
;
11475 struct intel_plane_state
*state
;
11476 struct drm_framebuffer
*fb
;
11478 DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc
->base
.base
.id
,
11479 context
, pipe_config
, pipe_name(crtc
->pipe
));
11481 DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config
->cpu_transcoder
));
11482 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
11483 pipe_config
->pipe_bpp
, pipe_config
->dither
);
11484 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11485 pipe_config
->has_pch_encoder
,
11486 pipe_config
->fdi_lanes
,
11487 pipe_config
->fdi_m_n
.gmch_m
, pipe_config
->fdi_m_n
.gmch_n
,
11488 pipe_config
->fdi_m_n
.link_m
, pipe_config
->fdi_m_n
.link_n
,
11489 pipe_config
->fdi_m_n
.tu
);
11490 DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11491 pipe_config
->has_dp_encoder
,
11492 pipe_config
->dp_m_n
.gmch_m
, pipe_config
->dp_m_n
.gmch_n
,
11493 pipe_config
->dp_m_n
.link_m
, pipe_config
->dp_m_n
.link_n
,
11494 pipe_config
->dp_m_n
.tu
);
11496 DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
11497 pipe_config
->has_dp_encoder
,
11498 pipe_config
->dp_m2_n2
.gmch_m
,
11499 pipe_config
->dp_m2_n2
.gmch_n
,
11500 pipe_config
->dp_m2_n2
.link_m
,
11501 pipe_config
->dp_m2_n2
.link_n
,
11502 pipe_config
->dp_m2_n2
.tu
);
11504 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
11505 pipe_config
->has_audio
,
11506 pipe_config
->has_infoframe
);
11508 DRM_DEBUG_KMS("requested mode:\n");
11509 drm_mode_debug_printmodeline(&pipe_config
->base
.mode
);
11510 DRM_DEBUG_KMS("adjusted mode:\n");
11511 drm_mode_debug_printmodeline(&pipe_config
->base
.adjusted_mode
);
11512 intel_dump_crtc_timings(&pipe_config
->base
.adjusted_mode
);
11513 DRM_DEBUG_KMS("port clock: %d\n", pipe_config
->port_clock
);
11514 DRM_DEBUG_KMS("pipe src size: %dx%d\n",
11515 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
11516 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
11518 pipe_config
->scaler_state
.scaler_users
,
11519 pipe_config
->scaler_state
.scaler_id
);
11520 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
11521 pipe_config
->gmch_pfit
.control
,
11522 pipe_config
->gmch_pfit
.pgm_ratios
,
11523 pipe_config
->gmch_pfit
.lvds_border_bits
);
11524 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
11525 pipe_config
->pch_pfit
.pos
,
11526 pipe_config
->pch_pfit
.size
,
11527 pipe_config
->pch_pfit
.enabled
? "enabled" : "disabled");
11528 DRM_DEBUG_KMS("ips: %i\n", pipe_config
->ips_enabled
);
11529 DRM_DEBUG_KMS("double wide: %i\n", pipe_config
->double_wide
);
11531 if (IS_BROXTON(dev
)) {
11532 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, "
11533 "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, "
11534 "pll6: 0x%x, pll8: 0x%x, pcsdw12: 0x%x\n",
11535 pipe_config
->ddi_pll_sel
,
11536 pipe_config
->dpll_hw_state
.ebb0
,
11537 pipe_config
->dpll_hw_state
.pll0
,
11538 pipe_config
->dpll_hw_state
.pll1
,
11539 pipe_config
->dpll_hw_state
.pll2
,
11540 pipe_config
->dpll_hw_state
.pll3
,
11541 pipe_config
->dpll_hw_state
.pll6
,
11542 pipe_config
->dpll_hw_state
.pll8
,
11543 pipe_config
->dpll_hw_state
.pcsdw12
);
11544 } else if (IS_SKYLAKE(dev
)) {
11545 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: "
11546 "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n",
11547 pipe_config
->ddi_pll_sel
,
11548 pipe_config
->dpll_hw_state
.ctrl1
,
11549 pipe_config
->dpll_hw_state
.cfgcr1
,
11550 pipe_config
->dpll_hw_state
.cfgcr2
);
11551 } else if (HAS_DDI(dev
)) {
11552 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: wrpll: 0x%x\n",
11553 pipe_config
->ddi_pll_sel
,
11554 pipe_config
->dpll_hw_state
.wrpll
);
11556 DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, "
11557 "fp0: 0x%x, fp1: 0x%x\n",
11558 pipe_config
->dpll_hw_state
.dpll
,
11559 pipe_config
->dpll_hw_state
.dpll_md
,
11560 pipe_config
->dpll_hw_state
.fp0
,
11561 pipe_config
->dpll_hw_state
.fp1
);
11564 DRM_DEBUG_KMS("planes on this crtc\n");
11565 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
11566 intel_plane
= to_intel_plane(plane
);
11567 if (intel_plane
->pipe
!= crtc
->pipe
)
11570 state
= to_intel_plane_state(plane
->state
);
11571 fb
= state
->base
.fb
;
11573 DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d "
11574 "disabled, scaler_id = %d\n",
11575 plane
->type
== DRM_PLANE_TYPE_CURSOR
? "CURSOR" : "STANDARD",
11576 plane
->base
.id
, intel_plane
->pipe
,
11577 (crtc
->base
.primary
== plane
) ? 0 : intel_plane
->plane
+ 1,
11578 drm_plane_index(plane
), state
->scaler_id
);
11582 DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled",
11583 plane
->type
== DRM_PLANE_TYPE_CURSOR
? "CURSOR" : "STANDARD",
11584 plane
->base
.id
, intel_plane
->pipe
,
11585 crtc
->base
.primary
== plane
? 0 : intel_plane
->plane
+ 1,
11586 drm_plane_index(plane
));
11587 DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x",
11588 fb
->base
.id
, fb
->width
, fb
->height
, fb
->pixel_format
);
11589 DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n",
11591 state
->src
.x1
>> 16, state
->src
.y1
>> 16,
11592 drm_rect_width(&state
->src
) >> 16,
11593 drm_rect_height(&state
->src
) >> 16,
11594 state
->dst
.x1
, state
->dst
.y1
,
11595 drm_rect_width(&state
->dst
), drm_rect_height(&state
->dst
));
11599 static bool encoders_cloneable(const struct intel_encoder
*a
,
11600 const struct intel_encoder
*b
)
11602 /* masks could be asymmetric, so check both ways */
11603 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
11604 b
->cloneable
& (1 << a
->type
));
11607 static bool check_single_encoder_cloning(struct drm_atomic_state
*state
,
11608 struct intel_crtc
*crtc
,
11609 struct intel_encoder
*encoder
)
11611 struct intel_encoder
*source_encoder
;
11612 struct drm_connector
*connector
;
11613 struct drm_connector_state
*connector_state
;
11616 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11617 if (connector_state
->crtc
!= &crtc
->base
)
11621 to_intel_encoder(connector_state
->best_encoder
);
11622 if (!encoders_cloneable(encoder
, source_encoder
))
11629 static bool check_encoder_cloning(struct drm_atomic_state
*state
,
11630 struct intel_crtc
*crtc
)
11632 struct intel_encoder
*encoder
;
11633 struct drm_connector
*connector
;
11634 struct drm_connector_state
*connector_state
;
11637 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11638 if (connector_state
->crtc
!= &crtc
->base
)
11641 encoder
= to_intel_encoder(connector_state
->best_encoder
);
11642 if (!check_single_encoder_cloning(state
, crtc
, encoder
))
11649 static bool check_digital_port_conflicts(struct drm_atomic_state
*state
)
11651 struct drm_device
*dev
= state
->dev
;
11652 struct intel_encoder
*encoder
;
11653 struct drm_connector
*connector
;
11654 struct drm_connector_state
*connector_state
;
11655 unsigned int used_ports
= 0;
11659 * Walk the connector list instead of the encoder
11660 * list to detect the problem on ddi platforms
11661 * where there's just one encoder per digital port.
11663 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11664 if (!connector_state
->best_encoder
)
11667 encoder
= to_intel_encoder(connector_state
->best_encoder
);
11669 WARN_ON(!connector_state
->crtc
);
11671 switch (encoder
->type
) {
11672 unsigned int port_mask
;
11673 case INTEL_OUTPUT_UNKNOWN
:
11674 if (WARN_ON(!HAS_DDI(dev
)))
11676 case INTEL_OUTPUT_DISPLAYPORT
:
11677 case INTEL_OUTPUT_HDMI
:
11678 case INTEL_OUTPUT_EDP
:
11679 port_mask
= 1 << enc_to_dig_port(&encoder
->base
)->port
;
11681 /* the same port mustn't appear more than once */
11682 if (used_ports
& port_mask
)
11685 used_ports
|= port_mask
;
11695 clear_intel_crtc_state(struct intel_crtc_state
*crtc_state
)
11697 struct drm_crtc_state tmp_state
;
11698 struct intel_crtc_scaler_state scaler_state
;
11699 struct intel_dpll_hw_state dpll_hw_state
;
11700 enum intel_dpll_id shared_dpll
;
11701 uint32_t ddi_pll_sel
;
11703 /* FIXME: before the switch to atomic started, a new pipe_config was
11704 * kzalloc'd. Code that depends on any field being zero should be
11705 * fixed, so that the crtc_state can be safely duplicated. For now,
11706 * only fields that are know to not cause problems are preserved. */
11708 tmp_state
= crtc_state
->base
;
11709 scaler_state
= crtc_state
->scaler_state
;
11710 shared_dpll
= crtc_state
->shared_dpll
;
11711 dpll_hw_state
= crtc_state
->dpll_hw_state
;
11712 ddi_pll_sel
= crtc_state
->ddi_pll_sel
;
11714 memset(crtc_state
, 0, sizeof *crtc_state
);
11716 crtc_state
->base
= tmp_state
;
11717 crtc_state
->scaler_state
= scaler_state
;
11718 crtc_state
->shared_dpll
= shared_dpll
;
11719 crtc_state
->dpll_hw_state
= dpll_hw_state
;
11720 crtc_state
->ddi_pll_sel
= ddi_pll_sel
;
11724 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
11725 struct drm_atomic_state
*state
,
11726 struct intel_crtc_state
*pipe_config
)
11728 struct intel_encoder
*encoder
;
11729 struct drm_connector
*connector
;
11730 struct drm_connector_state
*connector_state
;
11731 int base_bpp
, ret
= -EINVAL
;
11735 if (!check_encoder_cloning(state
, to_intel_crtc(crtc
))) {
11736 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
11740 if (!check_digital_port_conflicts(state
)) {
11741 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
11745 clear_intel_crtc_state(pipe_config
);
11747 pipe_config
->cpu_transcoder
=
11748 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
11751 * Sanitize sync polarity flags based on requested ones. If neither
11752 * positive or negative polarity is requested, treat this as meaning
11753 * negative polarity.
11755 if (!(pipe_config
->base
.adjusted_mode
.flags
&
11756 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
11757 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
11759 if (!(pipe_config
->base
.adjusted_mode
.flags
&
11760 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
11761 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
11763 /* Compute a starting value for pipe_config->pipe_bpp taking the source
11764 * plane pixel format and any sink constraints into account. Returns the
11765 * source plane bpp so that dithering can be selected on mismatches
11766 * after encoders and crtc also have had their say. */
11767 base_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
11773 * Determine the real pipe dimensions. Note that stereo modes can
11774 * increase the actual pipe size due to the frame doubling and
11775 * insertion of additional space for blanks between the frame. This
11776 * is stored in the crtc timings. We use the requested mode to do this
11777 * computation to clearly distinguish it from the adjusted mode, which
11778 * can be changed by the connectors in the below retry loop.
11780 drm_crtc_get_hv_timing(&pipe_config
->base
.mode
,
11781 &pipe_config
->pipe_src_w
,
11782 &pipe_config
->pipe_src_h
);
11785 /* Ensure the port clock defaults are reset when retrying. */
11786 pipe_config
->port_clock
= 0;
11787 pipe_config
->pixel_multiplier
= 1;
11789 /* Fill in default crtc timings, allow encoders to overwrite them. */
11790 drm_mode_set_crtcinfo(&pipe_config
->base
.adjusted_mode
,
11791 CRTC_STEREO_DOUBLE
);
11793 /* Pass our mode to the connectors and the CRTC to give them a chance to
11794 * adjust it according to limitations or connector properties, and also
11795 * a chance to reject the mode entirely.
11797 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11798 if (connector_state
->crtc
!= crtc
)
11801 encoder
= to_intel_encoder(connector_state
->best_encoder
);
11803 if (!(encoder
->compute_config(encoder
, pipe_config
))) {
11804 DRM_DEBUG_KMS("Encoder config failure\n");
11809 /* Set default port clock if not overwritten by the encoder. Needs to be
11810 * done afterwards in case the encoder adjusts the mode. */
11811 if (!pipe_config
->port_clock
)
11812 pipe_config
->port_clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
11813 * pipe_config
->pixel_multiplier
;
11815 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
11817 DRM_DEBUG_KMS("CRTC fixup failed\n");
11821 if (ret
== RETRY
) {
11822 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
11827 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11829 goto encoder_retry
;
11832 pipe_config
->dither
= pipe_config
->pipe_bpp
!= base_bpp
;
11833 DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
11834 base_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
11841 static bool intel_crtc_in_use(struct drm_crtc
*crtc
)
11843 struct drm_encoder
*encoder
;
11844 struct drm_device
*dev
= crtc
->dev
;
11846 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
11847 if (encoder
->crtc
== crtc
)
11854 needs_modeset(struct drm_crtc_state
*state
)
11856 return state
->mode_changed
|| state
->active_changed
;
11860 intel_modeset_update_state(struct drm_atomic_state
*state
)
11862 struct drm_device
*dev
= state
->dev
;
11863 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11864 struct intel_encoder
*intel_encoder
;
11865 struct drm_crtc
*crtc
;
11866 struct drm_crtc_state
*crtc_state
;
11867 struct drm_connector
*connector
;
11870 intel_shared_dpll_commit(dev_priv
);
11872 for_each_intel_encoder(dev
, intel_encoder
) {
11873 if (!intel_encoder
->base
.crtc
)
11876 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
)
11877 if (crtc
== intel_encoder
->base
.crtc
)
11880 if (crtc
!= intel_encoder
->base
.crtc
)
11883 if (crtc_state
->enable
&& needs_modeset(crtc_state
))
11884 intel_encoder
->connectors_active
= false;
11887 drm_atomic_helper_swap_state(state
->dev
, state
);
11888 intel_modeset_fixup_state(state
);
11890 /* Double check state. */
11891 for_each_crtc(dev
, crtc
) {
11892 WARN_ON(crtc
->state
->enable
!= intel_crtc_in_use(crtc
));
11895 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
11896 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
11899 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
)
11900 if (crtc
== connector
->encoder
->crtc
)
11903 if (crtc
!= connector
->encoder
->crtc
)
11906 if (crtc
->state
->enable
&& needs_modeset(crtc
->state
)) {
11907 struct drm_property
*dpms_property
=
11908 dev
->mode_config
.dpms_property
;
11910 connector
->dpms
= DRM_MODE_DPMS_ON
;
11911 drm_object_property_set_value(&connector
->base
,
11915 intel_encoder
= to_intel_encoder(connector
->encoder
);
11916 intel_encoder
->connectors_active
= true;
11922 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
11926 if (clock1
== clock2
)
11929 if (!clock1
|| !clock2
)
11932 diff
= abs(clock1
- clock2
);
11934 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
11940 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
11941 list_for_each_entry((intel_crtc), \
11942 &(dev)->mode_config.crtc_list, \
11944 if (mask & (1 <<(intel_crtc)->pipe))
11947 intel_pipe_config_compare(struct drm_device
*dev
,
11948 struct intel_crtc_state
*current_config
,
11949 struct intel_crtc_state
*pipe_config
)
11951 #define PIPE_CONF_CHECK_X(name) \
11952 if (current_config->name != pipe_config->name) { \
11953 DRM_ERROR("mismatch in " #name " " \
11954 "(expected 0x%08x, found 0x%08x)\n", \
11955 current_config->name, \
11956 pipe_config->name); \
11960 #define PIPE_CONF_CHECK_I(name) \
11961 if (current_config->name != pipe_config->name) { \
11962 DRM_ERROR("mismatch in " #name " " \
11963 "(expected %i, found %i)\n", \
11964 current_config->name, \
11965 pipe_config->name); \
11969 /* This is required for BDW+ where there is only one set of registers for
11970 * switching between high and low RR.
11971 * This macro can be used whenever a comparison has to be made between one
11972 * hw state and multiple sw state variables.
11974 #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \
11975 if ((current_config->name != pipe_config->name) && \
11976 (current_config->alt_name != pipe_config->name)) { \
11977 DRM_ERROR("mismatch in " #name " " \
11978 "(expected %i or %i, found %i)\n", \
11979 current_config->name, \
11980 current_config->alt_name, \
11981 pipe_config->name); \
11985 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
11986 if ((current_config->name ^ pipe_config->name) & (mask)) { \
11987 DRM_ERROR("mismatch in " #name "(" #mask ") " \
11988 "(expected %i, found %i)\n", \
11989 current_config->name & (mask), \
11990 pipe_config->name & (mask)); \
11994 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
11995 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
11996 DRM_ERROR("mismatch in " #name " " \
11997 "(expected %i, found %i)\n", \
11998 current_config->name, \
11999 pipe_config->name); \
12003 #define PIPE_CONF_QUIRK(quirk) \
12004 ((current_config->quirks | pipe_config->quirks) & (quirk))
12006 PIPE_CONF_CHECK_I(cpu_transcoder
);
12008 PIPE_CONF_CHECK_I(has_pch_encoder
);
12009 PIPE_CONF_CHECK_I(fdi_lanes
);
12010 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_m
);
12011 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_n
);
12012 PIPE_CONF_CHECK_I(fdi_m_n
.link_m
);
12013 PIPE_CONF_CHECK_I(fdi_m_n
.link_n
);
12014 PIPE_CONF_CHECK_I(fdi_m_n
.tu
);
12016 PIPE_CONF_CHECK_I(has_dp_encoder
);
12018 if (INTEL_INFO(dev
)->gen
< 8) {
12019 PIPE_CONF_CHECK_I(dp_m_n
.gmch_m
);
12020 PIPE_CONF_CHECK_I(dp_m_n
.gmch_n
);
12021 PIPE_CONF_CHECK_I(dp_m_n
.link_m
);
12022 PIPE_CONF_CHECK_I(dp_m_n
.link_n
);
12023 PIPE_CONF_CHECK_I(dp_m_n
.tu
);
12025 if (current_config
->has_drrs
) {
12026 PIPE_CONF_CHECK_I(dp_m2_n2
.gmch_m
);
12027 PIPE_CONF_CHECK_I(dp_m2_n2
.gmch_n
);
12028 PIPE_CONF_CHECK_I(dp_m2_n2
.link_m
);
12029 PIPE_CONF_CHECK_I(dp_m2_n2
.link_n
);
12030 PIPE_CONF_CHECK_I(dp_m2_n2
.tu
);
12033 PIPE_CONF_CHECK_I_ALT(dp_m_n
.gmch_m
, dp_m2_n2
.gmch_m
);
12034 PIPE_CONF_CHECK_I_ALT(dp_m_n
.gmch_n
, dp_m2_n2
.gmch_n
);
12035 PIPE_CONF_CHECK_I_ALT(dp_m_n
.link_m
, dp_m2_n2
.link_m
);
12036 PIPE_CONF_CHECK_I_ALT(dp_m_n
.link_n
, dp_m2_n2
.link_n
);
12037 PIPE_CONF_CHECK_I_ALT(dp_m_n
.tu
, dp_m2_n2
.tu
);
12040 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hdisplay
);
12041 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_htotal
);
12042 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_start
);
12043 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_end
);
12044 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_start
);
12045 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_end
);
12047 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vdisplay
);
12048 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vtotal
);
12049 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_start
);
12050 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_end
);
12051 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_start
);
12052 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_end
);
12054 PIPE_CONF_CHECK_I(pixel_multiplier
);
12055 PIPE_CONF_CHECK_I(has_hdmi_sink
);
12056 if ((INTEL_INFO(dev
)->gen
< 8 && !IS_HASWELL(dev
)) ||
12057 IS_VALLEYVIEW(dev
))
12058 PIPE_CONF_CHECK_I(limited_color_range
);
12059 PIPE_CONF_CHECK_I(has_infoframe
);
12061 PIPE_CONF_CHECK_I(has_audio
);
12063 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12064 DRM_MODE_FLAG_INTERLACE
);
12066 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
12067 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12068 DRM_MODE_FLAG_PHSYNC
);
12069 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12070 DRM_MODE_FLAG_NHSYNC
);
12071 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12072 DRM_MODE_FLAG_PVSYNC
);
12073 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
12074 DRM_MODE_FLAG_NVSYNC
);
12077 PIPE_CONF_CHECK_I(pipe_src_w
);
12078 PIPE_CONF_CHECK_I(pipe_src_h
);
12081 * FIXME: BIOS likes to set up a cloned config with lvds+external
12082 * screen. Since we don't yet re-compute the pipe config when moving
12083 * just the lvds port away to another pipe the sw tracking won't match.
12085 * Proper atomic modesets with recomputed global state will fix this.
12086 * Until then just don't check gmch state for inherited modes.
12088 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE
)) {
12089 PIPE_CONF_CHECK_I(gmch_pfit
.control
);
12090 /* pfit ratios are autocomputed by the hw on gen4+ */
12091 if (INTEL_INFO(dev
)->gen
< 4)
12092 PIPE_CONF_CHECK_I(gmch_pfit
.pgm_ratios
);
12093 PIPE_CONF_CHECK_I(gmch_pfit
.lvds_border_bits
);
12096 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
12097 if (current_config
->pch_pfit
.enabled
) {
12098 PIPE_CONF_CHECK_I(pch_pfit
.pos
);
12099 PIPE_CONF_CHECK_I(pch_pfit
.size
);
12102 PIPE_CONF_CHECK_I(scaler_state
.scaler_id
);
12104 /* BDW+ don't expose a synchronous way to read the state */
12105 if (IS_HASWELL(dev
))
12106 PIPE_CONF_CHECK_I(ips_enabled
);
12108 PIPE_CONF_CHECK_I(double_wide
);
12110 PIPE_CONF_CHECK_X(ddi_pll_sel
);
12112 PIPE_CONF_CHECK_I(shared_dpll
);
12113 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
12114 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
12115 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
12116 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
12117 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
12118 PIPE_CONF_CHECK_X(dpll_hw_state
.ctrl1
);
12119 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr1
);
12120 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr2
);
12122 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5)
12123 PIPE_CONF_CHECK_I(pipe_bpp
);
12125 PIPE_CONF_CHECK_CLOCK_FUZZY(base
.adjusted_mode
.crtc_clock
);
12126 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
12128 #undef PIPE_CONF_CHECK_X
12129 #undef PIPE_CONF_CHECK_I
12130 #undef PIPE_CONF_CHECK_I_ALT
12131 #undef PIPE_CONF_CHECK_FLAGS
12132 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
12133 #undef PIPE_CONF_QUIRK
12138 static void check_wm_state(struct drm_device
*dev
)
12140 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12141 struct skl_ddb_allocation hw_ddb
, *sw_ddb
;
12142 struct intel_crtc
*intel_crtc
;
12145 if (INTEL_INFO(dev
)->gen
< 9)
12148 skl_ddb_get_hw_state(dev_priv
, &hw_ddb
);
12149 sw_ddb
= &dev_priv
->wm
.skl_hw
.ddb
;
12151 for_each_intel_crtc(dev
, intel_crtc
) {
12152 struct skl_ddb_entry
*hw_entry
, *sw_entry
;
12153 const enum pipe pipe
= intel_crtc
->pipe
;
12155 if (!intel_crtc
->active
)
12159 for_each_plane(dev_priv
, pipe
, plane
) {
12160 hw_entry
= &hw_ddb
.plane
[pipe
][plane
];
12161 sw_entry
= &sw_ddb
->plane
[pipe
][plane
];
12163 if (skl_ddb_entry_equal(hw_entry
, sw_entry
))
12166 DRM_ERROR("mismatch in DDB state pipe %c plane %d "
12167 "(expected (%u,%u), found (%u,%u))\n",
12168 pipe_name(pipe
), plane
+ 1,
12169 sw_entry
->start
, sw_entry
->end
,
12170 hw_entry
->start
, hw_entry
->end
);
12174 hw_entry
= &hw_ddb
.cursor
[pipe
];
12175 sw_entry
= &sw_ddb
->cursor
[pipe
];
12177 if (skl_ddb_entry_equal(hw_entry
, sw_entry
))
12180 DRM_ERROR("mismatch in DDB state pipe %c cursor "
12181 "(expected (%u,%u), found (%u,%u))\n",
12183 sw_entry
->start
, sw_entry
->end
,
12184 hw_entry
->start
, hw_entry
->end
);
12189 check_connector_state(struct drm_device
*dev
)
12191 struct intel_connector
*connector
;
12193 for_each_intel_connector(dev
, connector
) {
12194 /* This also checks the encoder/connector hw state with the
12195 * ->get_hw_state callbacks. */
12196 intel_connector_check_state(connector
);
12198 I915_STATE_WARN(&connector
->new_encoder
->base
!= connector
->base
.encoder
,
12199 "connector's staged encoder doesn't match current encoder\n");
12204 check_encoder_state(struct drm_device
*dev
)
12206 struct intel_encoder
*encoder
;
12207 struct intel_connector
*connector
;
12209 for_each_intel_encoder(dev
, encoder
) {
12210 bool enabled
= false;
12211 bool active
= false;
12212 enum pipe pipe
, tracked_pipe
;
12214 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
12215 encoder
->base
.base
.id
,
12216 encoder
->base
.name
);
12218 I915_STATE_WARN(&encoder
->new_crtc
->base
!= encoder
->base
.crtc
,
12219 "encoder's stage crtc doesn't match current crtc\n");
12220 I915_STATE_WARN(encoder
->connectors_active
&& !encoder
->base
.crtc
,
12221 "encoder's active_connectors set, but no crtc\n");
12223 for_each_intel_connector(dev
, connector
) {
12224 if (connector
->base
.encoder
!= &encoder
->base
)
12227 if (connector
->base
.dpms
!= DRM_MODE_DPMS_OFF
)
12231 * for MST connectors if we unplug the connector is gone
12232 * away but the encoder is still connected to a crtc
12233 * until a modeset happens in response to the hotplug.
12235 if (!enabled
&& encoder
->base
.encoder_type
== DRM_MODE_ENCODER_DPMST
)
12238 I915_STATE_WARN(!!encoder
->base
.crtc
!= enabled
,
12239 "encoder's enabled state mismatch "
12240 "(expected %i, found %i)\n",
12241 !!encoder
->base
.crtc
, enabled
);
12242 I915_STATE_WARN(active
&& !encoder
->base
.crtc
,
12243 "active encoder with no crtc\n");
12245 I915_STATE_WARN(encoder
->connectors_active
!= active
,
12246 "encoder's computed active state doesn't match tracked active state "
12247 "(expected %i, found %i)\n", active
, encoder
->connectors_active
);
12249 active
= encoder
->get_hw_state(encoder
, &pipe
);
12250 I915_STATE_WARN(active
!= encoder
->connectors_active
,
12251 "encoder's hw state doesn't match sw tracking "
12252 "(expected %i, found %i)\n",
12253 encoder
->connectors_active
, active
);
12255 if (!encoder
->base
.crtc
)
12258 tracked_pipe
= to_intel_crtc(encoder
->base
.crtc
)->pipe
;
12259 I915_STATE_WARN(active
&& pipe
!= tracked_pipe
,
12260 "active encoder's pipe doesn't match"
12261 "(expected %i, found %i)\n",
12262 tracked_pipe
, pipe
);
12268 check_crtc_state(struct drm_device
*dev
)
12270 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12271 struct intel_crtc
*crtc
;
12272 struct intel_encoder
*encoder
;
12273 struct intel_crtc_state pipe_config
;
12275 for_each_intel_crtc(dev
, crtc
) {
12276 bool enabled
= false;
12277 bool active
= false;
12279 memset(&pipe_config
, 0, sizeof(pipe_config
));
12281 DRM_DEBUG_KMS("[CRTC:%d]\n",
12282 crtc
->base
.base
.id
);
12284 I915_STATE_WARN(crtc
->active
&& !crtc
->base
.state
->enable
,
12285 "active crtc, but not enabled in sw tracking\n");
12287 for_each_intel_encoder(dev
, encoder
) {
12288 if (encoder
->base
.crtc
!= &crtc
->base
)
12291 if (encoder
->connectors_active
)
12295 I915_STATE_WARN(active
!= crtc
->active
,
12296 "crtc's computed active state doesn't match tracked active state "
12297 "(expected %i, found %i)\n", active
, crtc
->active
);
12298 I915_STATE_WARN(enabled
!= crtc
->base
.state
->enable
,
12299 "crtc's computed enabled state doesn't match tracked enabled state "
12300 "(expected %i, found %i)\n", enabled
,
12301 crtc
->base
.state
->enable
);
12303 active
= dev_priv
->display
.get_pipe_config(crtc
,
12306 /* hw state is inconsistent with the pipe quirk */
12307 if ((crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
12308 (crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
12309 active
= crtc
->active
;
12311 for_each_intel_encoder(dev
, encoder
) {
12313 if (encoder
->base
.crtc
!= &crtc
->base
)
12315 if (encoder
->get_hw_state(encoder
, &pipe
))
12316 encoder
->get_config(encoder
, &pipe_config
);
12319 I915_STATE_WARN(crtc
->active
!= active
,
12320 "crtc active state doesn't match with hw state "
12321 "(expected %i, found %i)\n", crtc
->active
, active
);
12324 !intel_pipe_config_compare(dev
, crtc
->config
, &pipe_config
)) {
12325 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12326 intel_dump_pipe_config(crtc
, &pipe_config
,
12328 intel_dump_pipe_config(crtc
, crtc
->config
,
12335 check_shared_dpll_state(struct drm_device
*dev
)
12337 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12338 struct intel_crtc
*crtc
;
12339 struct intel_dpll_hw_state dpll_hw_state
;
12342 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
12343 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
12344 int enabled_crtcs
= 0, active_crtcs
= 0;
12347 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
12349 DRM_DEBUG_KMS("%s\n", pll
->name
);
12351 active
= pll
->get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
12353 I915_STATE_WARN(pll
->active
> hweight32(pll
->config
.crtc_mask
),
12354 "more active pll users than references: %i vs %i\n",
12355 pll
->active
, hweight32(pll
->config
.crtc_mask
));
12356 I915_STATE_WARN(pll
->active
&& !pll
->on
,
12357 "pll in active use but not on in sw tracking\n");
12358 I915_STATE_WARN(pll
->on
&& !pll
->active
,
12359 "pll in on but not on in use in sw tracking\n");
12360 I915_STATE_WARN(pll
->on
!= active
,
12361 "pll on state mismatch (expected %i, found %i)\n",
12364 for_each_intel_crtc(dev
, crtc
) {
12365 if (crtc
->base
.state
->enable
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
12367 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
12370 I915_STATE_WARN(pll
->active
!= active_crtcs
,
12371 "pll active crtcs mismatch (expected %i, found %i)\n",
12372 pll
->active
, active_crtcs
);
12373 I915_STATE_WARN(hweight32(pll
->config
.crtc_mask
) != enabled_crtcs
,
12374 "pll enabled crtcs mismatch (expected %i, found %i)\n",
12375 hweight32(pll
->config
.crtc_mask
), enabled_crtcs
);
12377 I915_STATE_WARN(pll
->on
&& memcmp(&pll
->config
.hw_state
, &dpll_hw_state
,
12378 sizeof(dpll_hw_state
)),
12379 "pll hw state mismatch\n");
12384 intel_modeset_check_state(struct drm_device
*dev
)
12386 check_wm_state(dev
);
12387 check_connector_state(dev
);
12388 check_encoder_state(dev
);
12389 check_crtc_state(dev
);
12390 check_shared_dpll_state(dev
);
12393 void ironlake_check_encoder_dotclock(const struct intel_crtc_state
*pipe_config
,
12397 * FDI already provided one idea for the dotclock.
12398 * Yell if the encoder disagrees.
12400 WARN(!intel_fuzzy_clock_check(pipe_config
->base
.adjusted_mode
.crtc_clock
, dotclock
),
12401 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
12402 pipe_config
->base
.adjusted_mode
.crtc_clock
, dotclock
);
12405 static void update_scanline_offset(struct intel_crtc
*crtc
)
12407 struct drm_device
*dev
= crtc
->base
.dev
;
12410 * The scanline counter increments at the leading edge of hsync.
12412 * On most platforms it starts counting from vtotal-1 on the
12413 * first active line. That means the scanline counter value is
12414 * always one less than what we would expect. Ie. just after
12415 * start of vblank, which also occurs at start of hsync (on the
12416 * last active line), the scanline counter will read vblank_start-1.
12418 * On gen2 the scanline counter starts counting from 1 instead
12419 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12420 * to keep the value positive), instead of adding one.
12422 * On HSW+ the behaviour of the scanline counter depends on the output
12423 * type. For DP ports it behaves like most other platforms, but on HDMI
12424 * there's an extra 1 line difference. So we need to add two instead of
12425 * one to the value.
12427 if (IS_GEN2(dev
)) {
12428 const struct drm_display_mode
*mode
= &crtc
->config
->base
.adjusted_mode
;
12431 vtotal
= mode
->crtc_vtotal
;
12432 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
12435 crtc
->scanline_offset
= vtotal
- 1;
12436 } else if (HAS_DDI(dev
) &&
12437 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
)) {
12438 crtc
->scanline_offset
= 2;
12440 crtc
->scanline_offset
= 1;
12443 static struct intel_crtc_state
*
12444 intel_modeset_compute_config(struct drm_crtc
*crtc
,
12445 struct drm_atomic_state
*state
)
12447 struct intel_crtc_state
*pipe_config
;
12450 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
12452 return ERR_PTR(ret
);
12454 ret
= drm_atomic_helper_check_modeset(state
->dev
, state
);
12456 return ERR_PTR(ret
);
12459 * Note this needs changes when we start tracking multiple modes
12460 * and crtcs. At that point we'll need to compute the whole config
12461 * (i.e. one pipe_config for each crtc) rather than just the one
12464 pipe_config
= intel_atomic_get_crtc_state(state
, to_intel_crtc(crtc
));
12465 if (IS_ERR(pipe_config
))
12466 return pipe_config
;
12468 if (!pipe_config
->base
.enable
)
12469 return pipe_config
;
12471 ret
= intel_modeset_pipe_config(crtc
, state
, pipe_config
);
12473 return ERR_PTR(ret
);
12475 /* Check things that can only be changed through modeset */
12476 if (pipe_config
->has_audio
!=
12477 to_intel_crtc(crtc
)->config
->has_audio
)
12478 pipe_config
->base
.mode_changed
= true;
12481 * Note we have an issue here with infoframes: current code
12482 * only updates them on the full mode set path per hw
12483 * requirements. So here we should be checking for any
12484 * required changes and forcing a mode set.
12487 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,"[modeset]");
12489 ret
= drm_atomic_helper_check_planes(state
->dev
, state
);
12491 return ERR_PTR(ret
);
12493 return pipe_config
;
12496 static int __intel_set_mode_setup_plls(struct drm_atomic_state
*state
)
12498 struct drm_device
*dev
= state
->dev
;
12499 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12500 unsigned clear_pipes
= 0;
12501 struct intel_crtc
*intel_crtc
;
12502 struct intel_crtc_state
*intel_crtc_state
;
12503 struct drm_crtc
*crtc
;
12504 struct drm_crtc_state
*crtc_state
;
12508 if (!dev_priv
->display
.crtc_compute_clock
)
12511 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12512 intel_crtc
= to_intel_crtc(crtc
);
12513 intel_crtc_state
= to_intel_crtc_state(crtc_state
);
12515 if (needs_modeset(crtc_state
)) {
12516 clear_pipes
|= 1 << intel_crtc
->pipe
;
12517 intel_crtc_state
->shared_dpll
= DPLL_ID_PRIVATE
;
12521 ret
= intel_shared_dpll_start_config(dev_priv
, clear_pipes
);
12525 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12526 if (!needs_modeset(crtc_state
) || !crtc_state
->enable
)
12529 intel_crtc
= to_intel_crtc(crtc
);
12530 intel_crtc_state
= to_intel_crtc_state(crtc_state
);
12532 ret
= dev_priv
->display
.crtc_compute_clock(intel_crtc
,
12535 intel_shared_dpll_abort_config(dev_priv
);
12544 /* Code that should eventually be part of atomic_check() */
12545 static int __intel_set_mode_checks(struct drm_atomic_state
*state
)
12547 struct drm_device
*dev
= state
->dev
;
12551 * See if the config requires any additional preparation, e.g.
12552 * to adjust global state with pipes off. We need to do this
12553 * here so we can get the modeset_pipe updated config for the new
12554 * mode set on this crtc. For other crtcs we need to use the
12555 * adjusted_mode bits in the crtc directly.
12557 if (IS_VALLEYVIEW(dev
) || IS_BROXTON(dev
)) {
12558 ret
= valleyview_modeset_global_pipes(state
);
12563 ret
= __intel_set_mode_setup_plls(state
);
12570 static int __intel_set_mode(struct drm_crtc
*modeset_crtc
,
12571 struct intel_crtc_state
*pipe_config
)
12573 struct drm_device
*dev
= modeset_crtc
->dev
;
12574 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12575 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
12576 struct drm_crtc
*crtc
;
12577 struct drm_crtc_state
*crtc_state
;
12581 ret
= __intel_set_mode_checks(state
);
12585 ret
= drm_atomic_helper_prepare_planes(dev
, state
);
12589 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12590 if (!needs_modeset(crtc_state
))
12593 if (!crtc_state
->enable
) {
12594 intel_crtc_disable(crtc
);
12595 } else if (crtc
->state
->enable
) {
12596 intel_crtc_disable_planes(crtc
);
12597 dev_priv
->display
.crtc_disable(crtc
);
12601 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
12602 * to set it here already despite that we pass it down the callchain.
12604 * Note we'll need to fix this up when we start tracking multiple
12605 * pipes; here we assume a single modeset_pipe and only track the
12606 * single crtc and mode.
12608 if (pipe_config
->base
.enable
&& needs_modeset(&pipe_config
->base
)) {
12609 modeset_crtc
->mode
= pipe_config
->base
.mode
;
12612 * Calculate and store various constants which
12613 * are later needed by vblank and swap-completion
12614 * timestamping. They are derived from true hwmode.
12616 drm_calc_timestamping_constants(modeset_crtc
,
12617 &pipe_config
->base
.adjusted_mode
);
12620 /* Only after disabling all output pipelines that will be changed can we
12621 * update the the output configuration. */
12622 intel_modeset_update_state(state
);
12624 /* The state has been swaped above, so state actually contains the
12625 * old state now. */
12627 modeset_update_crtc_power_domains(state
);
12629 drm_atomic_helper_commit_planes(dev
, state
);
12631 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
12632 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12633 if (!needs_modeset(crtc
->state
) || !crtc
->state
->enable
)
12636 update_scanline_offset(to_intel_crtc(crtc
));
12638 dev_priv
->display
.crtc_enable(crtc
);
12639 intel_crtc_enable_planes(crtc
);
12642 /* FIXME: add subpixel order */
12644 drm_atomic_helper_cleanup_planes(dev
, state
);
12646 drm_atomic_state_free(state
);
12651 static int intel_set_mode_with_config(struct drm_crtc
*crtc
,
12652 struct intel_crtc_state
*pipe_config
)
12656 ret
= __intel_set_mode(crtc
, pipe_config
);
12659 intel_modeset_check_state(crtc
->dev
);
12664 static int intel_set_mode(struct drm_crtc
*crtc
,
12665 struct drm_atomic_state
*state
)
12667 struct intel_crtc_state
*pipe_config
;
12670 pipe_config
= intel_modeset_compute_config(crtc
, state
);
12671 if (IS_ERR(pipe_config
)) {
12672 ret
= PTR_ERR(pipe_config
);
12676 ret
= intel_set_mode_with_config(crtc
, pipe_config
);
12684 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
12686 struct drm_device
*dev
= crtc
->dev
;
12687 struct drm_atomic_state
*state
;
12688 struct intel_crtc
*intel_crtc
;
12689 struct intel_encoder
*encoder
;
12690 struct intel_connector
*connector
;
12691 struct drm_connector_state
*connector_state
;
12692 struct intel_crtc_state
*crtc_state
;
12695 state
= drm_atomic_state_alloc(dev
);
12697 DRM_DEBUG_KMS("[CRTC:%d] mode restore failed, out of memory",
12702 state
->acquire_ctx
= dev
->mode_config
.acquire_ctx
;
12704 /* The force restore path in the HW readout code relies on the staged
12705 * config still keeping the user requested config while the actual
12706 * state has been overwritten by the configuration read from HW. We
12707 * need to copy the staged config to the atomic state, otherwise the
12708 * mode set will just reapply the state the HW is already in. */
12709 for_each_intel_encoder(dev
, encoder
) {
12710 if (&encoder
->new_crtc
->base
!= crtc
)
12713 for_each_intel_connector(dev
, connector
) {
12714 if (connector
->new_encoder
!= encoder
)
12717 connector_state
= drm_atomic_get_connector_state(state
, &connector
->base
);
12718 if (IS_ERR(connector_state
)) {
12719 DRM_DEBUG_KMS("Failed to add [CONNECTOR:%d:%s] to state: %ld\n",
12720 connector
->base
.base
.id
,
12721 connector
->base
.name
,
12722 PTR_ERR(connector_state
));
12726 connector_state
->crtc
= crtc
;
12727 connector_state
->best_encoder
= &encoder
->base
;
12731 for_each_intel_crtc(dev
, intel_crtc
) {
12732 if (intel_crtc
->new_enabled
== intel_crtc
->base
.enabled
)
12735 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
12736 if (IS_ERR(crtc_state
)) {
12737 DRM_DEBUG_KMS("Failed to add [CRTC:%d] to state: %ld\n",
12738 intel_crtc
->base
.base
.id
,
12739 PTR_ERR(crtc_state
));
12743 crtc_state
->base
.active
= crtc_state
->base
.enable
=
12744 intel_crtc
->new_enabled
;
12746 if (&intel_crtc
->base
== crtc
)
12747 drm_mode_copy(&crtc_state
->base
.mode
, &crtc
->mode
);
12750 intel_modeset_setup_plane_state(state
, crtc
, &crtc
->mode
,
12751 crtc
->primary
->fb
, crtc
->x
, crtc
->y
);
12753 ret
= intel_set_mode(crtc
, state
);
12755 drm_atomic_state_free(state
);
12758 #undef for_each_intel_crtc_masked
12760 static bool intel_connector_in_mode_set(struct intel_connector
*connector
,
12761 struct drm_mode_set
*set
)
12765 for (ro
= 0; ro
< set
->num_connectors
; ro
++)
12766 if (set
->connectors
[ro
] == &connector
->base
)
12773 intel_modeset_stage_output_state(struct drm_device
*dev
,
12774 struct drm_mode_set
*set
,
12775 struct drm_atomic_state
*state
)
12777 struct intel_connector
*connector
;
12778 struct drm_connector
*drm_connector
;
12779 struct drm_connector_state
*connector_state
;
12780 struct drm_crtc
*crtc
;
12781 struct drm_crtc_state
*crtc_state
;
12784 /* The upper layers ensure that we either disable a crtc or have a list
12785 * of connectors. For paranoia, double-check this. */
12786 WARN_ON(!set
->fb
&& (set
->num_connectors
!= 0));
12787 WARN_ON(set
->fb
&& (set
->num_connectors
== 0));
12789 for_each_intel_connector(dev
, connector
) {
12790 bool in_mode_set
= intel_connector_in_mode_set(connector
, set
);
12792 if (!in_mode_set
&& connector
->base
.state
->crtc
!= set
->crtc
)
12796 drm_atomic_get_connector_state(state
, &connector
->base
);
12797 if (IS_ERR(connector_state
))
12798 return PTR_ERR(connector_state
);
12801 int pipe
= to_intel_crtc(set
->crtc
)->pipe
;
12802 connector_state
->best_encoder
=
12803 &intel_find_encoder(connector
, pipe
)->base
;
12806 if (connector
->base
.state
->crtc
!= set
->crtc
)
12809 /* If we disable the crtc, disable all its connectors. Also, if
12810 * the connector is on the changing crtc but not on the new
12811 * connector list, disable it. */
12812 if (!set
->fb
|| !in_mode_set
) {
12813 connector_state
->best_encoder
= NULL
;
12815 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
12816 connector
->base
.base
.id
,
12817 connector
->base
.name
);
12820 /* connector->new_encoder is now updated for all connectors. */
12822 for_each_connector_in_state(state
, drm_connector
, connector_state
, i
) {
12823 connector
= to_intel_connector(drm_connector
);
12825 if (!connector_state
->best_encoder
) {
12826 ret
= drm_atomic_set_crtc_for_connector(connector_state
,
12834 if (intel_connector_in_mode_set(connector
, set
)) {
12835 struct drm_crtc
*crtc
= connector
->base
.state
->crtc
;
12837 /* If this connector was in a previous crtc, add it
12838 * to the state. We might need to disable it. */
12841 drm_atomic_get_crtc_state(state
, crtc
);
12842 if (IS_ERR(crtc_state
))
12843 return PTR_ERR(crtc_state
);
12846 ret
= drm_atomic_set_crtc_for_connector(connector_state
,
12852 /* Make sure the new CRTC will work with the encoder */
12853 if (!drm_encoder_crtc_ok(connector_state
->best_encoder
,
12854 connector_state
->crtc
)) {
12858 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
12859 connector
->base
.base
.id
,
12860 connector
->base
.name
,
12861 connector_state
->crtc
->base
.id
);
12863 if (connector_state
->best_encoder
!= &connector
->encoder
->base
)
12864 connector
->encoder
=
12865 to_intel_encoder(connector_state
->best_encoder
);
12868 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12869 bool has_connectors
;
12871 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
12875 has_connectors
= !!drm_atomic_connectors_for_crtc(state
, crtc
);
12876 if (has_connectors
!= crtc_state
->enable
)
12877 crtc_state
->enable
=
12878 crtc_state
->active
= has_connectors
;
12881 ret
= intel_modeset_setup_plane_state(state
, set
->crtc
, set
->mode
,
12882 set
->fb
, set
->x
, set
->y
);
12886 crtc_state
= drm_atomic_get_crtc_state(state
, set
->crtc
);
12887 if (IS_ERR(crtc_state
))
12888 return PTR_ERR(crtc_state
);
12891 drm_mode_copy(&crtc_state
->mode
, set
->mode
);
12893 if (set
->num_connectors
)
12894 crtc_state
->active
= true;
12899 static bool primary_plane_visible(struct drm_crtc
*crtc
)
12901 struct intel_plane_state
*plane_state
=
12902 to_intel_plane_state(crtc
->primary
->state
);
12904 return plane_state
->visible
;
12907 static int intel_crtc_set_config(struct drm_mode_set
*set
)
12909 struct drm_device
*dev
;
12910 struct drm_atomic_state
*state
= NULL
;
12911 struct intel_crtc_state
*pipe_config
;
12912 bool primary_plane_was_visible
;
12916 BUG_ON(!set
->crtc
);
12917 BUG_ON(!set
->crtc
->helper_private
);
12919 /* Enforce sane interface api - has been abused by the fb helper. */
12920 BUG_ON(!set
->mode
&& set
->fb
);
12921 BUG_ON(set
->fb
&& set
->num_connectors
== 0);
12924 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
12925 set
->crtc
->base
.id
, set
->fb
->base
.id
,
12926 (int)set
->num_connectors
, set
->x
, set
->y
);
12928 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set
->crtc
->base
.id
);
12931 dev
= set
->crtc
->dev
;
12933 state
= drm_atomic_state_alloc(dev
);
12937 state
->acquire_ctx
= dev
->mode_config
.acquire_ctx
;
12939 ret
= intel_modeset_stage_output_state(dev
, set
, state
);
12943 pipe_config
= intel_modeset_compute_config(set
->crtc
, state
);
12944 if (IS_ERR(pipe_config
)) {
12945 ret
= PTR_ERR(pipe_config
);
12949 intel_update_pipe_size(to_intel_crtc(set
->crtc
));
12951 primary_plane_was_visible
= primary_plane_visible(set
->crtc
);
12953 ret
= intel_set_mode_with_config(set
->crtc
, pipe_config
);
12956 pipe_config
->base
.enable
&&
12957 pipe_config
->base
.planes_changed
&&
12958 !needs_modeset(&pipe_config
->base
)) {
12959 struct intel_crtc
*intel_crtc
= to_intel_crtc(set
->crtc
);
12962 * We need to make sure the primary plane is re-enabled if it
12963 * has previously been turned off.
12965 if (ret
== 0 && !primary_plane_was_visible
&&
12966 primary_plane_visible(set
->crtc
)) {
12967 WARN_ON(!intel_crtc
->active
);
12968 intel_post_enable_primary(set
->crtc
);
12972 * In the fastboot case this may be our only check of the
12973 * state after boot. It would be better to only do it on
12974 * the first update, but we don't have a nice way of doing that
12975 * (and really, set_config isn't used much for high freq page
12976 * flipping, so increasing its cost here shouldn't be a big
12979 if (i915
.fastboot
&& ret
== 0)
12980 intel_modeset_check_state(set
->crtc
->dev
);
12984 DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
12985 set
->crtc
->base
.id
, ret
);
12990 drm_atomic_state_free(state
);
12994 static const struct drm_crtc_funcs intel_crtc_funcs
= {
12995 .gamma_set
= intel_crtc_gamma_set
,
12996 .set_config
= intel_crtc_set_config
,
12997 .destroy
= intel_crtc_destroy
,
12998 .page_flip
= intel_crtc_page_flip
,
12999 .atomic_duplicate_state
= intel_crtc_duplicate_state
,
13000 .atomic_destroy_state
= intel_crtc_destroy_state
,
13003 static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private
*dev_priv
,
13004 struct intel_shared_dpll
*pll
,
13005 struct intel_dpll_hw_state
*hw_state
)
13009 if (!intel_display_power_is_enabled(dev_priv
, POWER_DOMAIN_PLLS
))
13012 val
= I915_READ(PCH_DPLL(pll
->id
));
13013 hw_state
->dpll
= val
;
13014 hw_state
->fp0
= I915_READ(PCH_FP0(pll
->id
));
13015 hw_state
->fp1
= I915_READ(PCH_FP1(pll
->id
));
13017 return val
& DPLL_VCO_ENABLE
;
13020 static void ibx_pch_dpll_mode_set(struct drm_i915_private
*dev_priv
,
13021 struct intel_shared_dpll
*pll
)
13023 I915_WRITE(PCH_FP0(pll
->id
), pll
->config
.hw_state
.fp0
);
13024 I915_WRITE(PCH_FP1(pll
->id
), pll
->config
.hw_state
.fp1
);
13027 static void ibx_pch_dpll_enable(struct drm_i915_private
*dev_priv
,
13028 struct intel_shared_dpll
*pll
)
13030 /* PCH refclock must be enabled first */
13031 ibx_assert_pch_refclk_enabled(dev_priv
);
13033 I915_WRITE(PCH_DPLL(pll
->id
), pll
->config
.hw_state
.dpll
);
13035 /* Wait for the clocks to stabilize. */
13036 POSTING_READ(PCH_DPLL(pll
->id
));
13039 /* The pixel multiplier can only be updated once the
13040 * DPLL is enabled and the clocks are stable.
13042 * So write it again.
13044 I915_WRITE(PCH_DPLL(pll
->id
), pll
->config
.hw_state
.dpll
);
13045 POSTING_READ(PCH_DPLL(pll
->id
));
13049 static void ibx_pch_dpll_disable(struct drm_i915_private
*dev_priv
,
13050 struct intel_shared_dpll
*pll
)
13052 struct drm_device
*dev
= dev_priv
->dev
;
13053 struct intel_crtc
*crtc
;
13055 /* Make sure no transcoder isn't still depending on us. */
13056 for_each_intel_crtc(dev
, crtc
) {
13057 if (intel_crtc_to_shared_dpll(crtc
) == pll
)
13058 assert_pch_transcoder_disabled(dev_priv
, crtc
->pipe
);
13061 I915_WRITE(PCH_DPLL(pll
->id
), 0);
13062 POSTING_READ(PCH_DPLL(pll
->id
));
13066 static char *ibx_pch_dpll_names
[] = {
13071 static void ibx_pch_dpll_init(struct drm_device
*dev
)
13073 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13076 dev_priv
->num_shared_dpll
= 2;
13078 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
13079 dev_priv
->shared_dplls
[i
].id
= i
;
13080 dev_priv
->shared_dplls
[i
].name
= ibx_pch_dpll_names
[i
];
13081 dev_priv
->shared_dplls
[i
].mode_set
= ibx_pch_dpll_mode_set
;
13082 dev_priv
->shared_dplls
[i
].enable
= ibx_pch_dpll_enable
;
13083 dev_priv
->shared_dplls
[i
].disable
= ibx_pch_dpll_disable
;
13084 dev_priv
->shared_dplls
[i
].get_hw_state
=
13085 ibx_pch_dpll_get_hw_state
;
13089 static void intel_shared_dpll_init(struct drm_device
*dev
)
13091 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13094 intel_ddi_pll_init(dev
);
13095 else if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
13096 ibx_pch_dpll_init(dev
);
13098 dev_priv
->num_shared_dpll
= 0;
13100 BUG_ON(dev_priv
->num_shared_dpll
> I915_NUM_PLLS
);
13104 * intel_wm_need_update - Check whether watermarks need updating
13105 * @plane: drm plane
13106 * @state: new plane state
13108 * Check current plane state versus the new one to determine whether
13109 * watermarks need to be recalculated.
13111 * Returns true or false.
13113 bool intel_wm_need_update(struct drm_plane
*plane
,
13114 struct drm_plane_state
*state
)
13116 /* Update watermarks on tiling changes. */
13117 if (!plane
->state
->fb
|| !state
->fb
||
13118 plane
->state
->fb
->modifier
[0] != state
->fb
->modifier
[0] ||
13119 plane
->state
->rotation
!= state
->rotation
)
13126 * intel_prepare_plane_fb - Prepare fb for usage on plane
13127 * @plane: drm plane to prepare for
13128 * @fb: framebuffer to prepare for presentation
13130 * Prepares a framebuffer for usage on a display plane. Generally this
13131 * involves pinning the underlying object and updating the frontbuffer tracking
13132 * bits. Some older platforms need special physical address handling for
13135 * Returns 0 on success, negative error code on failure.
13138 intel_prepare_plane_fb(struct drm_plane
*plane
,
13139 struct drm_framebuffer
*fb
,
13140 const struct drm_plane_state
*new_state
)
13142 struct drm_device
*dev
= plane
->dev
;
13143 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
13144 enum pipe pipe
= intel_plane
->pipe
;
13145 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13146 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->fb
);
13147 unsigned frontbuffer_bits
= 0;
13153 switch (plane
->type
) {
13154 case DRM_PLANE_TYPE_PRIMARY
:
13155 frontbuffer_bits
= INTEL_FRONTBUFFER_PRIMARY(pipe
);
13157 case DRM_PLANE_TYPE_CURSOR
:
13158 frontbuffer_bits
= INTEL_FRONTBUFFER_CURSOR(pipe
);
13160 case DRM_PLANE_TYPE_OVERLAY
:
13161 frontbuffer_bits
= INTEL_FRONTBUFFER_SPRITE(pipe
);
13165 mutex_lock(&dev
->struct_mutex
);
13167 if (plane
->type
== DRM_PLANE_TYPE_CURSOR
&&
13168 INTEL_INFO(dev
)->cursor_needs_physical
) {
13169 int align
= IS_I830(dev
) ? 16 * 1024 : 256;
13170 ret
= i915_gem_object_attach_phys(obj
, align
);
13172 DRM_DEBUG_KMS("failed to attach phys object\n");
13174 ret
= intel_pin_and_fence_fb_obj(plane
, fb
, new_state
, NULL
);
13178 i915_gem_track_fb(old_obj
, obj
, frontbuffer_bits
);
13180 mutex_unlock(&dev
->struct_mutex
);
13186 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13187 * @plane: drm plane to clean up for
13188 * @fb: old framebuffer that was on plane
13190 * Cleans up a framebuffer that has just been removed from a plane.
13193 intel_cleanup_plane_fb(struct drm_plane
*plane
,
13194 struct drm_framebuffer
*fb
,
13195 const struct drm_plane_state
*old_state
)
13197 struct drm_device
*dev
= plane
->dev
;
13198 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13203 if (plane
->type
!= DRM_PLANE_TYPE_CURSOR
||
13204 !INTEL_INFO(dev
)->cursor_needs_physical
) {
13205 mutex_lock(&dev
->struct_mutex
);
13206 intel_unpin_fb_obj(fb
, old_state
);
13207 mutex_unlock(&dev
->struct_mutex
);
13212 skl_max_scale(struct intel_crtc
*intel_crtc
, struct intel_crtc_state
*crtc_state
)
13215 struct drm_device
*dev
;
13216 struct drm_i915_private
*dev_priv
;
13217 int crtc_clock
, cdclk
;
13219 if (!intel_crtc
|| !crtc_state
)
13220 return DRM_PLANE_HELPER_NO_SCALING
;
13222 dev
= intel_crtc
->base
.dev
;
13223 dev_priv
= dev
->dev_private
;
13224 crtc_clock
= crtc_state
->base
.adjusted_mode
.crtc_clock
;
13225 cdclk
= dev_priv
->display
.get_display_clock_speed(dev
);
13227 if (!crtc_clock
|| !cdclk
)
13228 return DRM_PLANE_HELPER_NO_SCALING
;
13231 * skl max scale is lower of:
13232 * close to 3 but not 3, -1 is for that purpose
13236 max_scale
= min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk
<< 8) / crtc_clock
));
13242 intel_check_primary_plane(struct drm_plane
*plane
,
13243 struct intel_plane_state
*state
)
13245 struct drm_device
*dev
= plane
->dev
;
13246 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13247 struct drm_crtc
*crtc
= state
->base
.crtc
;
13248 struct intel_crtc
*intel_crtc
;
13249 struct intel_crtc_state
*crtc_state
;
13250 struct drm_framebuffer
*fb
= state
->base
.fb
;
13251 struct drm_rect
*dest
= &state
->dst
;
13252 struct drm_rect
*src
= &state
->src
;
13253 const struct drm_rect
*clip
= &state
->clip
;
13254 bool can_position
= false;
13255 int max_scale
= DRM_PLANE_HELPER_NO_SCALING
;
13256 int min_scale
= DRM_PLANE_HELPER_NO_SCALING
;
13259 crtc
= crtc
? crtc
: plane
->crtc
;
13260 intel_crtc
= to_intel_crtc(crtc
);
13261 crtc_state
= state
->base
.state
?
13262 intel_atomic_get_crtc_state(state
->base
.state
, intel_crtc
) : NULL
;
13264 if (INTEL_INFO(dev
)->gen
>= 9) {
13265 /* use scaler when colorkey is not required */
13266 if (to_intel_plane(plane
)->ckey
.flags
== I915_SET_COLORKEY_NONE
) {
13268 max_scale
= skl_max_scale(intel_crtc
, crtc_state
);
13270 can_position
= true;
13273 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
13277 can_position
, true,
13282 if (intel_crtc
->active
) {
13283 struct intel_plane_state
*old_state
=
13284 to_intel_plane_state(plane
->state
);
13286 intel_crtc
->atomic
.wait_for_flips
= true;
13289 * FBC does not work on some platforms for rotated
13290 * planes, so disable it when rotation is not 0 and
13291 * update it when rotation is set back to 0.
13293 * FIXME: This is redundant with the fbc update done in
13294 * the primary plane enable function except that that
13295 * one is done too late. We eventually need to unify
13298 if (state
->visible
&&
13299 INTEL_INFO(dev
)->gen
<= 4 && !IS_G4X(dev
) &&
13300 dev_priv
->fbc
.crtc
== intel_crtc
&&
13301 state
->base
.rotation
!= BIT(DRM_ROTATE_0
)) {
13302 intel_crtc
->atomic
.disable_fbc
= true;
13305 if (state
->visible
&& !old_state
->visible
) {
13307 * BDW signals flip done immediately if the plane
13308 * is disabled, even if the plane enable is already
13309 * armed to occur at the next vblank :(
13311 if (IS_BROADWELL(dev
))
13312 intel_crtc
->atomic
.wait_vblank
= true;
13315 intel_crtc
->atomic
.fb_bits
|=
13316 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
);
13318 intel_crtc
->atomic
.update_fbc
= true;
13320 if (intel_wm_need_update(plane
, &state
->base
))
13321 intel_crtc
->atomic
.update_wm
= true;
13324 if (INTEL_INFO(dev
)->gen
>= 9) {
13325 ret
= skl_update_scaler_users(intel_crtc
, crtc_state
,
13326 to_intel_plane(plane
), state
, 0);
13335 intel_commit_primary_plane(struct drm_plane
*plane
,
13336 struct intel_plane_state
*state
)
13338 struct drm_crtc
*crtc
= state
->base
.crtc
;
13339 struct drm_framebuffer
*fb
= state
->base
.fb
;
13340 struct drm_device
*dev
= plane
->dev
;
13341 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13342 struct intel_crtc
*intel_crtc
;
13343 struct drm_rect
*src
= &state
->src
;
13345 crtc
= crtc
? crtc
: plane
->crtc
;
13346 intel_crtc
= to_intel_crtc(crtc
);
13349 crtc
->x
= src
->x1
>> 16;
13350 crtc
->y
= src
->y1
>> 16;
13352 if (intel_crtc
->active
) {
13353 if (state
->visible
)
13354 /* FIXME: kill this fastboot hack */
13355 intel_update_pipe_size(intel_crtc
);
13357 dev_priv
->display
.update_primary_plane(crtc
, plane
->fb
,
13363 intel_disable_primary_plane(struct drm_plane
*plane
,
13364 struct drm_crtc
*crtc
,
13367 struct drm_device
*dev
= plane
->dev
;
13368 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13370 dev_priv
->display
.update_primary_plane(crtc
, NULL
, 0, 0);
13373 static void intel_begin_crtc_commit(struct drm_crtc
*crtc
)
13375 struct drm_device
*dev
= crtc
->dev
;
13376 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13377 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13378 struct intel_plane
*intel_plane
;
13379 struct drm_plane
*p
;
13380 unsigned fb_bits
= 0;
13382 /* Track fb's for any planes being disabled */
13383 list_for_each_entry(p
, &dev
->mode_config
.plane_list
, head
) {
13384 intel_plane
= to_intel_plane(p
);
13386 if (intel_crtc
->atomic
.disabled_planes
&
13387 (1 << drm_plane_index(p
))) {
13389 case DRM_PLANE_TYPE_PRIMARY
:
13390 fb_bits
= INTEL_FRONTBUFFER_PRIMARY(intel_plane
->pipe
);
13392 case DRM_PLANE_TYPE_CURSOR
:
13393 fb_bits
= INTEL_FRONTBUFFER_CURSOR(intel_plane
->pipe
);
13395 case DRM_PLANE_TYPE_OVERLAY
:
13396 fb_bits
= INTEL_FRONTBUFFER_SPRITE(intel_plane
->pipe
);
13400 mutex_lock(&dev
->struct_mutex
);
13401 i915_gem_track_fb(intel_fb_obj(p
->fb
), NULL
, fb_bits
);
13402 mutex_unlock(&dev
->struct_mutex
);
13406 if (intel_crtc
->atomic
.wait_for_flips
)
13407 intel_crtc_wait_for_pending_flips(crtc
);
13409 if (intel_crtc
->atomic
.disable_fbc
)
13410 intel_fbc_disable(dev
);
13412 if (intel_crtc
->atomic
.pre_disable_primary
)
13413 intel_pre_disable_primary(crtc
);
13415 if (intel_crtc
->atomic
.update_wm
)
13416 intel_update_watermarks(crtc
);
13418 intel_runtime_pm_get(dev_priv
);
13420 /* Perform vblank evasion around commit operation */
13421 if (intel_crtc
->active
)
13422 intel_crtc
->atomic
.evade
=
13423 intel_pipe_update_start(intel_crtc
,
13424 &intel_crtc
->atomic
.start_vbl_count
);
13427 static void intel_finish_crtc_commit(struct drm_crtc
*crtc
)
13429 struct drm_device
*dev
= crtc
->dev
;
13430 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13431 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13432 struct drm_plane
*p
;
13434 if (intel_crtc
->atomic
.evade
)
13435 intel_pipe_update_end(intel_crtc
,
13436 intel_crtc
->atomic
.start_vbl_count
);
13438 intel_runtime_pm_put(dev_priv
);
13440 if (intel_crtc
->atomic
.wait_vblank
)
13441 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
13443 intel_frontbuffer_flip(dev
, intel_crtc
->atomic
.fb_bits
);
13445 if (intel_crtc
->atomic
.update_fbc
) {
13446 mutex_lock(&dev
->struct_mutex
);
13447 intel_fbc_update(dev
);
13448 mutex_unlock(&dev
->struct_mutex
);
13451 if (intel_crtc
->atomic
.post_enable_primary
)
13452 intel_post_enable_primary(crtc
);
13454 drm_for_each_legacy_plane(p
, &dev
->mode_config
.plane_list
)
13455 if (intel_crtc
->atomic
.update_sprite_watermarks
& drm_plane_index(p
))
13456 intel_update_sprite_watermarks(p
, crtc
, 0, 0, 0,
13459 memset(&intel_crtc
->atomic
, 0, sizeof(intel_crtc
->atomic
));
13463 * intel_plane_destroy - destroy a plane
13464 * @plane: plane to destroy
13466 * Common destruction function for all types of planes (primary, cursor,
13469 void intel_plane_destroy(struct drm_plane
*plane
)
13471 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
13472 drm_plane_cleanup(plane
);
13473 kfree(intel_plane
);
13476 const struct drm_plane_funcs intel_plane_funcs
= {
13477 .update_plane
= drm_atomic_helper_update_plane
,
13478 .disable_plane
= drm_atomic_helper_disable_plane
,
13479 .destroy
= intel_plane_destroy
,
13480 .set_property
= drm_atomic_helper_plane_set_property
,
13481 .atomic_get_property
= intel_plane_atomic_get_property
,
13482 .atomic_set_property
= intel_plane_atomic_set_property
,
13483 .atomic_duplicate_state
= intel_plane_duplicate_state
,
13484 .atomic_destroy_state
= intel_plane_destroy_state
,
13488 static struct drm_plane
*intel_primary_plane_create(struct drm_device
*dev
,
13491 struct intel_plane
*primary
;
13492 struct intel_plane_state
*state
;
13493 const uint32_t *intel_primary_formats
;
13496 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
13497 if (primary
== NULL
)
13500 state
= intel_create_plane_state(&primary
->base
);
13505 primary
->base
.state
= &state
->base
;
13507 primary
->can_scale
= false;
13508 primary
->max_downscale
= 1;
13509 if (INTEL_INFO(dev
)->gen
>= 9) {
13510 primary
->can_scale
= true;
13511 state
->scaler_id
= -1;
13513 primary
->pipe
= pipe
;
13514 primary
->plane
= pipe
;
13515 primary
->check_plane
= intel_check_primary_plane
;
13516 primary
->commit_plane
= intel_commit_primary_plane
;
13517 primary
->disable_plane
= intel_disable_primary_plane
;
13518 primary
->ckey
.flags
= I915_SET_COLORKEY_NONE
;
13519 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4)
13520 primary
->plane
= !pipe
;
13522 if (INTEL_INFO(dev
)->gen
>= 9) {
13523 intel_primary_formats
= skl_primary_formats
;
13524 num_formats
= ARRAY_SIZE(skl_primary_formats
);
13525 } else if (INTEL_INFO(dev
)->gen
>= 4) {
13526 intel_primary_formats
= i965_primary_formats
;
13527 num_formats
= ARRAY_SIZE(i965_primary_formats
);
13529 intel_primary_formats
= i8xx_primary_formats
;
13530 num_formats
= ARRAY_SIZE(i8xx_primary_formats
);
13533 drm_universal_plane_init(dev
, &primary
->base
, 0,
13534 &intel_plane_funcs
,
13535 intel_primary_formats
, num_formats
,
13536 DRM_PLANE_TYPE_PRIMARY
);
13538 if (INTEL_INFO(dev
)->gen
>= 4)
13539 intel_create_rotation_property(dev
, primary
);
13541 drm_plane_helper_add(&primary
->base
, &intel_plane_helper_funcs
);
13543 return &primary
->base
;
13546 void intel_create_rotation_property(struct drm_device
*dev
, struct intel_plane
*plane
)
13548 if (!dev
->mode_config
.rotation_property
) {
13549 unsigned long flags
= BIT(DRM_ROTATE_0
) |
13550 BIT(DRM_ROTATE_180
);
13552 if (INTEL_INFO(dev
)->gen
>= 9)
13553 flags
|= BIT(DRM_ROTATE_90
) | BIT(DRM_ROTATE_270
);
13555 dev
->mode_config
.rotation_property
=
13556 drm_mode_create_rotation_property(dev
, flags
);
13558 if (dev
->mode_config
.rotation_property
)
13559 drm_object_attach_property(&plane
->base
.base
,
13560 dev
->mode_config
.rotation_property
,
13561 plane
->base
.state
->rotation
);
13565 intel_check_cursor_plane(struct drm_plane
*plane
,
13566 struct intel_plane_state
*state
)
13568 struct drm_crtc
*crtc
= state
->base
.crtc
;
13569 struct drm_device
*dev
= plane
->dev
;
13570 struct drm_framebuffer
*fb
= state
->base
.fb
;
13571 struct drm_rect
*dest
= &state
->dst
;
13572 struct drm_rect
*src
= &state
->src
;
13573 const struct drm_rect
*clip
= &state
->clip
;
13574 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13575 struct intel_crtc
*intel_crtc
;
13579 crtc
= crtc
? crtc
: plane
->crtc
;
13580 intel_crtc
= to_intel_crtc(crtc
);
13582 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
13584 DRM_PLANE_HELPER_NO_SCALING
,
13585 DRM_PLANE_HELPER_NO_SCALING
,
13586 true, true, &state
->visible
);
13591 /* if we want to turn off the cursor ignore width and height */
13595 /* Check for which cursor types we support */
13596 if (!cursor_size_ok(dev
, state
->base
.crtc_w
, state
->base
.crtc_h
)) {
13597 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
13598 state
->base
.crtc_w
, state
->base
.crtc_h
);
13602 stride
= roundup_pow_of_two(state
->base
.crtc_w
) * 4;
13603 if (obj
->base
.size
< stride
* state
->base
.crtc_h
) {
13604 DRM_DEBUG_KMS("buffer is too small\n");
13608 if (fb
->modifier
[0] != DRM_FORMAT_MOD_NONE
) {
13609 DRM_DEBUG_KMS("cursor cannot be tiled\n");
13614 if (intel_crtc
->active
) {
13615 if (plane
->state
->crtc_w
!= state
->base
.crtc_w
)
13616 intel_crtc
->atomic
.update_wm
= true;
13618 intel_crtc
->atomic
.fb_bits
|=
13619 INTEL_FRONTBUFFER_CURSOR(intel_crtc
->pipe
);
13626 intel_disable_cursor_plane(struct drm_plane
*plane
,
13627 struct drm_crtc
*crtc
,
13630 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13634 intel_crtc
->cursor_bo
= NULL
;
13635 intel_crtc
->cursor_addr
= 0;
13638 intel_crtc_update_cursor(crtc
, false);
13642 intel_commit_cursor_plane(struct drm_plane
*plane
,
13643 struct intel_plane_state
*state
)
13645 struct drm_crtc
*crtc
= state
->base
.crtc
;
13646 struct drm_device
*dev
= plane
->dev
;
13647 struct intel_crtc
*intel_crtc
;
13648 struct drm_i915_gem_object
*obj
= intel_fb_obj(state
->base
.fb
);
13651 crtc
= crtc
? crtc
: plane
->crtc
;
13652 intel_crtc
= to_intel_crtc(crtc
);
13654 plane
->fb
= state
->base
.fb
;
13655 crtc
->cursor_x
= state
->base
.crtc_x
;
13656 crtc
->cursor_y
= state
->base
.crtc_y
;
13658 if (intel_crtc
->cursor_bo
== obj
)
13663 else if (!INTEL_INFO(dev
)->cursor_needs_physical
)
13664 addr
= i915_gem_obj_ggtt_offset(obj
);
13666 addr
= obj
->phys_handle
->busaddr
;
13668 intel_crtc
->cursor_addr
= addr
;
13669 intel_crtc
->cursor_bo
= obj
;
13672 if (intel_crtc
->active
)
13673 intel_crtc_update_cursor(crtc
, state
->visible
);
13676 static struct drm_plane
*intel_cursor_plane_create(struct drm_device
*dev
,
13679 struct intel_plane
*cursor
;
13680 struct intel_plane_state
*state
;
13682 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
13683 if (cursor
== NULL
)
13686 state
= intel_create_plane_state(&cursor
->base
);
13691 cursor
->base
.state
= &state
->base
;
13693 cursor
->can_scale
= false;
13694 cursor
->max_downscale
= 1;
13695 cursor
->pipe
= pipe
;
13696 cursor
->plane
= pipe
;
13697 cursor
->check_plane
= intel_check_cursor_plane
;
13698 cursor
->commit_plane
= intel_commit_cursor_plane
;
13699 cursor
->disable_plane
= intel_disable_cursor_plane
;
13701 drm_universal_plane_init(dev
, &cursor
->base
, 0,
13702 &intel_plane_funcs
,
13703 intel_cursor_formats
,
13704 ARRAY_SIZE(intel_cursor_formats
),
13705 DRM_PLANE_TYPE_CURSOR
);
13707 if (INTEL_INFO(dev
)->gen
>= 4) {
13708 if (!dev
->mode_config
.rotation_property
)
13709 dev
->mode_config
.rotation_property
=
13710 drm_mode_create_rotation_property(dev
,
13711 BIT(DRM_ROTATE_0
) |
13712 BIT(DRM_ROTATE_180
));
13713 if (dev
->mode_config
.rotation_property
)
13714 drm_object_attach_property(&cursor
->base
.base
,
13715 dev
->mode_config
.rotation_property
,
13716 state
->base
.rotation
);
13719 if (INTEL_INFO(dev
)->gen
>=9)
13720 state
->scaler_id
= -1;
13722 drm_plane_helper_add(&cursor
->base
, &intel_plane_helper_funcs
);
13724 return &cursor
->base
;
13727 static void skl_init_scalers(struct drm_device
*dev
, struct intel_crtc
*intel_crtc
,
13728 struct intel_crtc_state
*crtc_state
)
13731 struct intel_scaler
*intel_scaler
;
13732 struct intel_crtc_scaler_state
*scaler_state
= &crtc_state
->scaler_state
;
13734 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
13735 intel_scaler
= &scaler_state
->scalers
[i
];
13736 intel_scaler
->in_use
= 0;
13737 intel_scaler
->id
= i
;
13739 intel_scaler
->mode
= PS_SCALER_MODE_DYN
;
13742 scaler_state
->scaler_id
= -1;
13745 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
13747 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13748 struct intel_crtc
*intel_crtc
;
13749 struct intel_crtc_state
*crtc_state
= NULL
;
13750 struct drm_plane
*primary
= NULL
;
13751 struct drm_plane
*cursor
= NULL
;
13754 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
13755 if (intel_crtc
== NULL
)
13758 crtc_state
= kzalloc(sizeof(*crtc_state
), GFP_KERNEL
);
13761 intel_crtc
->config
= crtc_state
;
13762 intel_crtc
->base
.state
= &crtc_state
->base
;
13763 crtc_state
->base
.crtc
= &intel_crtc
->base
;
13765 /* initialize shared scalers */
13766 if (INTEL_INFO(dev
)->gen
>= 9) {
13767 if (pipe
== PIPE_C
)
13768 intel_crtc
->num_scalers
= 1;
13770 intel_crtc
->num_scalers
= SKL_NUM_SCALERS
;
13772 skl_init_scalers(dev
, intel_crtc
, crtc_state
);
13775 primary
= intel_primary_plane_create(dev
, pipe
);
13779 cursor
= intel_cursor_plane_create(dev
, pipe
);
13783 ret
= drm_crtc_init_with_planes(dev
, &intel_crtc
->base
, primary
,
13784 cursor
, &intel_crtc_funcs
);
13788 drm_mode_crtc_set_gamma_size(&intel_crtc
->base
, 256);
13789 for (i
= 0; i
< 256; i
++) {
13790 intel_crtc
->lut_r
[i
] = i
;
13791 intel_crtc
->lut_g
[i
] = i
;
13792 intel_crtc
->lut_b
[i
] = i
;
13796 * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
13797 * is hooked to pipe B. Hence we want plane A feeding pipe B.
13799 intel_crtc
->pipe
= pipe
;
13800 intel_crtc
->plane
= pipe
;
13801 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4) {
13802 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
13803 intel_crtc
->plane
= !pipe
;
13806 intel_crtc
->cursor_base
= ~0;
13807 intel_crtc
->cursor_cntl
= ~0;
13808 intel_crtc
->cursor_size
= ~0;
13810 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
13811 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
13812 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
13813 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
13815 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
13817 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
13822 drm_plane_cleanup(primary
);
13824 drm_plane_cleanup(cursor
);
13829 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
13831 struct drm_encoder
*encoder
= connector
->base
.encoder
;
13832 struct drm_device
*dev
= connector
->base
.dev
;
13834 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
13836 if (!encoder
|| WARN_ON(!encoder
->crtc
))
13837 return INVALID_PIPE
;
13839 return to_intel_crtc(encoder
->crtc
)->pipe
;
13842 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
13843 struct drm_file
*file
)
13845 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
13846 struct drm_crtc
*drmmode_crtc
;
13847 struct intel_crtc
*crtc
;
13849 drmmode_crtc
= drm_crtc_find(dev
, pipe_from_crtc_id
->crtc_id
);
13851 if (!drmmode_crtc
) {
13852 DRM_ERROR("no such CRTC id\n");
13856 crtc
= to_intel_crtc(drmmode_crtc
);
13857 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
13862 static int intel_encoder_clones(struct intel_encoder
*encoder
)
13864 struct drm_device
*dev
= encoder
->base
.dev
;
13865 struct intel_encoder
*source_encoder
;
13866 int index_mask
= 0;
13869 for_each_intel_encoder(dev
, source_encoder
) {
13870 if (encoders_cloneable(encoder
, source_encoder
))
13871 index_mask
|= (1 << entry
);
13879 static bool has_edp_a(struct drm_device
*dev
)
13881 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13883 if (!IS_MOBILE(dev
))
13886 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
13889 if (IS_GEN5(dev
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
13895 static bool intel_crt_present(struct drm_device
*dev
)
13897 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13899 if (INTEL_INFO(dev
)->gen
>= 9)
13902 if (IS_HSW_ULT(dev
) || IS_BDW_ULT(dev
))
13905 if (IS_CHERRYVIEW(dev
))
13908 if (IS_VALLEYVIEW(dev
) && !dev_priv
->vbt
.int_crt_support
)
13914 static void intel_setup_outputs(struct drm_device
*dev
)
13916 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13917 struct intel_encoder
*encoder
;
13918 bool dpd_is_edp
= false;
13920 intel_lvds_init(dev
);
13922 if (intel_crt_present(dev
))
13923 intel_crt_init(dev
);
13925 if (IS_BROXTON(dev
)) {
13927 * FIXME: Broxton doesn't support port detection via the
13928 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
13929 * detect the ports.
13931 intel_ddi_init(dev
, PORT_A
);
13932 intel_ddi_init(dev
, PORT_B
);
13933 intel_ddi_init(dev
, PORT_C
);
13934 } else if (HAS_DDI(dev
)) {
13938 * Haswell uses DDI functions to detect digital outputs.
13939 * On SKL pre-D0 the strap isn't connected, so we assume
13942 found
= I915_READ(DDI_BUF_CTL_A
) & DDI_INIT_DISPLAY_DETECTED
;
13943 /* WaIgnoreDDIAStrap: skl */
13945 (IS_SKYLAKE(dev
) && INTEL_REVID(dev
) < SKL_REVID_D0
))
13946 intel_ddi_init(dev
, PORT_A
);
13948 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
13950 found
= I915_READ(SFUSE_STRAP
);
13952 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
13953 intel_ddi_init(dev
, PORT_B
);
13954 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
13955 intel_ddi_init(dev
, PORT_C
);
13956 if (found
& SFUSE_STRAP_DDID_DETECTED
)
13957 intel_ddi_init(dev
, PORT_D
);
13958 } else if (HAS_PCH_SPLIT(dev
)) {
13960 dpd_is_edp
= intel_dp_is_edp(dev
, PORT_D
);
13962 if (has_edp_a(dev
))
13963 intel_dp_init(dev
, DP_A
, PORT_A
);
13965 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
13966 /* PCH SDVOB multiplex with HDMIB */
13967 found
= intel_sdvo_init(dev
, PCH_SDVOB
, true);
13969 intel_hdmi_init(dev
, PCH_HDMIB
, PORT_B
);
13970 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
13971 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
13974 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
13975 intel_hdmi_init(dev
, PCH_HDMIC
, PORT_C
);
13977 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
13978 intel_hdmi_init(dev
, PCH_HDMID
, PORT_D
);
13980 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
13981 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
13983 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
13984 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
13985 } else if (IS_VALLEYVIEW(dev
)) {
13987 * The DP_DETECTED bit is the latched state of the DDC
13988 * SDA pin at boot. However since eDP doesn't require DDC
13989 * (no way to plug in a DP->HDMI dongle) the DDC pins for
13990 * eDP ports may have been muxed to an alternate function.
13991 * Thus we can't rely on the DP_DETECTED bit alone to detect
13992 * eDP ports. Consult the VBT as well as DP_DETECTED to
13993 * detect eDP ports.
13995 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIB
) & SDVO_DETECTED
&&
13996 !intel_dp_is_edp(dev
, PORT_B
))
13997 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIB
,
13999 if (I915_READ(VLV_DISPLAY_BASE
+ DP_B
) & DP_DETECTED
||
14000 intel_dp_is_edp(dev
, PORT_B
))
14001 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_B
, PORT_B
);
14003 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIC
) & SDVO_DETECTED
&&
14004 !intel_dp_is_edp(dev
, PORT_C
))
14005 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIC
,
14007 if (I915_READ(VLV_DISPLAY_BASE
+ DP_C
) & DP_DETECTED
||
14008 intel_dp_is_edp(dev
, PORT_C
))
14009 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_C
, PORT_C
);
14011 if (IS_CHERRYVIEW(dev
)) {
14012 if (I915_READ(VLV_DISPLAY_BASE
+ CHV_HDMID
) & SDVO_DETECTED
)
14013 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ CHV_HDMID
,
14015 /* eDP not supported on port D, so don't check VBT */
14016 if (I915_READ(VLV_DISPLAY_BASE
+ DP_D
) & DP_DETECTED
)
14017 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_D
, PORT_D
);
14020 intel_dsi_init(dev
);
14021 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev
)) {
14022 bool found
= false;
14024 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
14025 DRM_DEBUG_KMS("probing SDVOB\n");
14026 found
= intel_sdvo_init(dev
, GEN3_SDVOB
, true);
14027 if (!found
&& SUPPORTS_INTEGRATED_HDMI(dev
)) {
14028 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
14029 intel_hdmi_init(dev
, GEN4_HDMIB
, PORT_B
);
14032 if (!found
&& SUPPORTS_INTEGRATED_DP(dev
))
14033 intel_dp_init(dev
, DP_B
, PORT_B
);
14036 /* Before G4X SDVOC doesn't have its own detect register */
14038 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
14039 DRM_DEBUG_KMS("probing SDVOC\n");
14040 found
= intel_sdvo_init(dev
, GEN3_SDVOC
, false);
14043 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
14045 if (SUPPORTS_INTEGRATED_HDMI(dev
)) {
14046 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
14047 intel_hdmi_init(dev
, GEN4_HDMIC
, PORT_C
);
14049 if (SUPPORTS_INTEGRATED_DP(dev
))
14050 intel_dp_init(dev
, DP_C
, PORT_C
);
14053 if (SUPPORTS_INTEGRATED_DP(dev
) &&
14054 (I915_READ(DP_D
) & DP_DETECTED
))
14055 intel_dp_init(dev
, DP_D
, PORT_D
);
14056 } else if (IS_GEN2(dev
))
14057 intel_dvo_init(dev
);
14059 if (SUPPORTS_TV(dev
))
14060 intel_tv_init(dev
);
14062 intel_psr_init(dev
);
14064 for_each_intel_encoder(dev
, encoder
) {
14065 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
14066 encoder
->base
.possible_clones
=
14067 intel_encoder_clones(encoder
);
14070 intel_init_pch_refclk(dev
);
14072 drm_helper_move_panel_connectors_to_head(dev
);
14075 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
14077 struct drm_device
*dev
= fb
->dev
;
14078 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
14080 drm_framebuffer_cleanup(fb
);
14081 mutex_lock(&dev
->struct_mutex
);
14082 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
14083 drm_gem_object_unreference(&intel_fb
->obj
->base
);
14084 mutex_unlock(&dev
->struct_mutex
);
14088 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
14089 struct drm_file
*file
,
14090 unsigned int *handle
)
14092 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
14093 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
14095 return drm_gem_handle_create(file
, &obj
->base
, handle
);
14098 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
14099 .destroy
= intel_user_framebuffer_destroy
,
14100 .create_handle
= intel_user_framebuffer_create_handle
,
14104 u32
intel_fb_pitch_limit(struct drm_device
*dev
, uint64_t fb_modifier
,
14105 uint32_t pixel_format
)
14107 u32 gen
= INTEL_INFO(dev
)->gen
;
14110 /* "The stride in bytes must not exceed the of the size of 8K
14111 * pixels and 32K bytes."
14113 return min(8192*drm_format_plane_cpp(pixel_format
, 0), 32768);
14114 } else if (gen
>= 5 && !IS_VALLEYVIEW(dev
)) {
14116 } else if (gen
>= 4) {
14117 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
14121 } else if (gen
>= 3) {
14122 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
14127 /* XXX DSPC is limited to 4k tiled */
14132 static int intel_framebuffer_init(struct drm_device
*dev
,
14133 struct intel_framebuffer
*intel_fb
,
14134 struct drm_mode_fb_cmd2
*mode_cmd
,
14135 struct drm_i915_gem_object
*obj
)
14137 unsigned int aligned_height
;
14139 u32 pitch_limit
, stride_alignment
;
14141 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
14143 if (mode_cmd
->flags
& DRM_MODE_FB_MODIFIERS
) {
14144 /* Enforce that fb modifier and tiling mode match, but only for
14145 * X-tiled. This is needed for FBC. */
14146 if (!!(obj
->tiling_mode
== I915_TILING_X
) !=
14147 !!(mode_cmd
->modifier
[0] == I915_FORMAT_MOD_X_TILED
)) {
14148 DRM_DEBUG("tiling_mode doesn't match fb modifier\n");
14152 if (obj
->tiling_mode
== I915_TILING_X
)
14153 mode_cmd
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
14154 else if (obj
->tiling_mode
== I915_TILING_Y
) {
14155 DRM_DEBUG("No Y tiling for legacy addfb\n");
14160 /* Passed in modifier sanity checking. */
14161 switch (mode_cmd
->modifier
[0]) {
14162 case I915_FORMAT_MOD_Y_TILED
:
14163 case I915_FORMAT_MOD_Yf_TILED
:
14164 if (INTEL_INFO(dev
)->gen
< 9) {
14165 DRM_DEBUG("Unsupported tiling 0x%llx!\n",
14166 mode_cmd
->modifier
[0]);
14169 case DRM_FORMAT_MOD_NONE
:
14170 case I915_FORMAT_MOD_X_TILED
:
14173 DRM_DEBUG("Unsupported fb modifier 0x%llx!\n",
14174 mode_cmd
->modifier
[0]);
14178 stride_alignment
= intel_fb_stride_alignment(dev
, mode_cmd
->modifier
[0],
14179 mode_cmd
->pixel_format
);
14180 if (mode_cmd
->pitches
[0] & (stride_alignment
- 1)) {
14181 DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n",
14182 mode_cmd
->pitches
[0], stride_alignment
);
14186 pitch_limit
= intel_fb_pitch_limit(dev
, mode_cmd
->modifier
[0],
14187 mode_cmd
->pixel_format
);
14188 if (mode_cmd
->pitches
[0] > pitch_limit
) {
14189 DRM_DEBUG("%s pitch (%u) must be at less than %d\n",
14190 mode_cmd
->modifier
[0] != DRM_FORMAT_MOD_NONE
?
14191 "tiled" : "linear",
14192 mode_cmd
->pitches
[0], pitch_limit
);
14196 if (mode_cmd
->modifier
[0] == I915_FORMAT_MOD_X_TILED
&&
14197 mode_cmd
->pitches
[0] != obj
->stride
) {
14198 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
14199 mode_cmd
->pitches
[0], obj
->stride
);
14203 /* Reject formats not supported by any plane early. */
14204 switch (mode_cmd
->pixel_format
) {
14205 case DRM_FORMAT_C8
:
14206 case DRM_FORMAT_RGB565
:
14207 case DRM_FORMAT_XRGB8888
:
14208 case DRM_FORMAT_ARGB8888
:
14210 case DRM_FORMAT_XRGB1555
:
14211 if (INTEL_INFO(dev
)->gen
> 3) {
14212 DRM_DEBUG("unsupported pixel format: %s\n",
14213 drm_get_format_name(mode_cmd
->pixel_format
));
14217 case DRM_FORMAT_ABGR8888
:
14218 if (!IS_VALLEYVIEW(dev
) && INTEL_INFO(dev
)->gen
< 9) {
14219 DRM_DEBUG("unsupported pixel format: %s\n",
14220 drm_get_format_name(mode_cmd
->pixel_format
));
14224 case DRM_FORMAT_XBGR8888
:
14225 case DRM_FORMAT_XRGB2101010
:
14226 case DRM_FORMAT_XBGR2101010
:
14227 if (INTEL_INFO(dev
)->gen
< 4) {
14228 DRM_DEBUG("unsupported pixel format: %s\n",
14229 drm_get_format_name(mode_cmd
->pixel_format
));
14233 case DRM_FORMAT_ABGR2101010
:
14234 if (!IS_VALLEYVIEW(dev
)) {
14235 DRM_DEBUG("unsupported pixel format: %s\n",
14236 drm_get_format_name(mode_cmd
->pixel_format
));
14240 case DRM_FORMAT_YUYV
:
14241 case DRM_FORMAT_UYVY
:
14242 case DRM_FORMAT_YVYU
:
14243 case DRM_FORMAT_VYUY
:
14244 if (INTEL_INFO(dev
)->gen
< 5) {
14245 DRM_DEBUG("unsupported pixel format: %s\n",
14246 drm_get_format_name(mode_cmd
->pixel_format
));
14251 DRM_DEBUG("unsupported pixel format: %s\n",
14252 drm_get_format_name(mode_cmd
->pixel_format
));
14256 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14257 if (mode_cmd
->offsets
[0] != 0)
14260 aligned_height
= intel_fb_align_height(dev
, mode_cmd
->height
,
14261 mode_cmd
->pixel_format
,
14262 mode_cmd
->modifier
[0]);
14263 /* FIXME drm helper for size checks (especially planar formats)? */
14264 if (obj
->base
.size
< aligned_height
* mode_cmd
->pitches
[0])
14267 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
14268 intel_fb
->obj
= obj
;
14269 intel_fb
->obj
->framebuffer_references
++;
14271 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
14273 DRM_ERROR("framebuffer init failed %d\n", ret
);
14280 static struct drm_framebuffer
*
14281 intel_user_framebuffer_create(struct drm_device
*dev
,
14282 struct drm_file
*filp
,
14283 struct drm_mode_fb_cmd2
*mode_cmd
)
14285 struct drm_i915_gem_object
*obj
;
14287 obj
= to_intel_bo(drm_gem_object_lookup(dev
, filp
,
14288 mode_cmd
->handles
[0]));
14289 if (&obj
->base
== NULL
)
14290 return ERR_PTR(-ENOENT
);
14292 return intel_framebuffer_create(dev
, mode_cmd
, obj
);
14295 #ifndef CONFIG_DRM_I915_FBDEV
14296 static inline void intel_fbdev_output_poll_changed(struct drm_device
*dev
)
14301 static const struct drm_mode_config_funcs intel_mode_funcs
= {
14302 .fb_create
= intel_user_framebuffer_create
,
14303 .output_poll_changed
= intel_fbdev_output_poll_changed
,
14304 .atomic_check
= intel_atomic_check
,
14305 .atomic_commit
= intel_atomic_commit
,
14308 /* Set up chip specific display functions */
14309 static void intel_init_display(struct drm_device
*dev
)
14311 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14313 if (HAS_PCH_SPLIT(dev
) || IS_G4X(dev
))
14314 dev_priv
->display
.find_dpll
= g4x_find_best_dpll
;
14315 else if (IS_CHERRYVIEW(dev
))
14316 dev_priv
->display
.find_dpll
= chv_find_best_dpll
;
14317 else if (IS_VALLEYVIEW(dev
))
14318 dev_priv
->display
.find_dpll
= vlv_find_best_dpll
;
14319 else if (IS_PINEVIEW(dev
))
14320 dev_priv
->display
.find_dpll
= pnv_find_best_dpll
;
14322 dev_priv
->display
.find_dpll
= i9xx_find_best_dpll
;
14324 if (INTEL_INFO(dev
)->gen
>= 9) {
14325 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
14326 dev_priv
->display
.get_initial_plane_config
=
14327 skylake_get_initial_plane_config
;
14328 dev_priv
->display
.crtc_compute_clock
=
14329 haswell_crtc_compute_clock
;
14330 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
14331 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
14332 dev_priv
->display
.off
= ironlake_crtc_off
;
14333 dev_priv
->display
.update_primary_plane
=
14334 skylake_update_primary_plane
;
14335 } else if (HAS_DDI(dev
)) {
14336 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
14337 dev_priv
->display
.get_initial_plane_config
=
14338 ironlake_get_initial_plane_config
;
14339 dev_priv
->display
.crtc_compute_clock
=
14340 haswell_crtc_compute_clock
;
14341 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
14342 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
14343 dev_priv
->display
.off
= ironlake_crtc_off
;
14344 dev_priv
->display
.update_primary_plane
=
14345 ironlake_update_primary_plane
;
14346 } else if (HAS_PCH_SPLIT(dev
)) {
14347 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
14348 dev_priv
->display
.get_initial_plane_config
=
14349 ironlake_get_initial_plane_config
;
14350 dev_priv
->display
.crtc_compute_clock
=
14351 ironlake_crtc_compute_clock
;
14352 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
14353 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
14354 dev_priv
->display
.off
= ironlake_crtc_off
;
14355 dev_priv
->display
.update_primary_plane
=
14356 ironlake_update_primary_plane
;
14357 } else if (IS_VALLEYVIEW(dev
)) {
14358 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14359 dev_priv
->display
.get_initial_plane_config
=
14360 i9xx_get_initial_plane_config
;
14361 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
14362 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
14363 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14364 dev_priv
->display
.off
= i9xx_crtc_off
;
14365 dev_priv
->display
.update_primary_plane
=
14366 i9xx_update_primary_plane
;
14368 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14369 dev_priv
->display
.get_initial_plane_config
=
14370 i9xx_get_initial_plane_config
;
14371 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
14372 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14373 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14374 dev_priv
->display
.off
= i9xx_crtc_off
;
14375 dev_priv
->display
.update_primary_plane
=
14376 i9xx_update_primary_plane
;
14379 /* Returns the core display clock speed */
14380 if (IS_SKYLAKE(dev
))
14381 dev_priv
->display
.get_display_clock_speed
=
14382 skylake_get_display_clock_speed
;
14383 else if (IS_BROADWELL(dev
))
14384 dev_priv
->display
.get_display_clock_speed
=
14385 broadwell_get_display_clock_speed
;
14386 else if (IS_HASWELL(dev
))
14387 dev_priv
->display
.get_display_clock_speed
=
14388 haswell_get_display_clock_speed
;
14389 else if (IS_VALLEYVIEW(dev
))
14390 dev_priv
->display
.get_display_clock_speed
=
14391 valleyview_get_display_clock_speed
;
14392 else if (IS_GEN5(dev
))
14393 dev_priv
->display
.get_display_clock_speed
=
14394 ilk_get_display_clock_speed
;
14395 else if (IS_I945G(dev
) || IS_BROADWATER(dev
) ||
14396 IS_GEN6(dev
) || IS_IVYBRIDGE(dev
) || (IS_G33(dev
) && !IS_PINEVIEW_M(dev
)))
14397 dev_priv
->display
.get_display_clock_speed
=
14398 i945_get_display_clock_speed
;
14399 else if (IS_I915G(dev
))
14400 dev_priv
->display
.get_display_clock_speed
=
14401 i915_get_display_clock_speed
;
14402 else if (IS_I945GM(dev
) || IS_845G(dev
))
14403 dev_priv
->display
.get_display_clock_speed
=
14404 i9xx_misc_get_display_clock_speed
;
14405 else if (IS_PINEVIEW(dev
))
14406 dev_priv
->display
.get_display_clock_speed
=
14407 pnv_get_display_clock_speed
;
14408 else if (IS_I915GM(dev
))
14409 dev_priv
->display
.get_display_clock_speed
=
14410 i915gm_get_display_clock_speed
;
14411 else if (IS_I865G(dev
))
14412 dev_priv
->display
.get_display_clock_speed
=
14413 i865_get_display_clock_speed
;
14414 else if (IS_I85X(dev
))
14415 dev_priv
->display
.get_display_clock_speed
=
14416 i855_get_display_clock_speed
;
14417 else /* 852, 830 */
14418 dev_priv
->display
.get_display_clock_speed
=
14419 i830_get_display_clock_speed
;
14421 if (IS_GEN5(dev
)) {
14422 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
14423 } else if (IS_GEN6(dev
)) {
14424 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
14425 } else if (IS_IVYBRIDGE(dev
)) {
14426 /* FIXME: detect B0+ stepping and use auto training */
14427 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
14428 } else if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
14429 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
14430 } else if (IS_VALLEYVIEW(dev
)) {
14431 dev_priv
->display
.modeset_global_resources
=
14432 valleyview_modeset_global_resources
;
14433 } else if (IS_BROXTON(dev
)) {
14434 dev_priv
->display
.modeset_global_resources
=
14435 broxton_modeset_global_resources
;
14438 switch (INTEL_INFO(dev
)->gen
) {
14440 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
14444 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
14449 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
14453 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
14456 case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
14457 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
14460 /* Drop through - unsupported since execlist only. */
14462 /* Default just returns -ENODEV to indicate unsupported */
14463 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
14466 intel_panel_init_backlight_funcs(dev
);
14468 mutex_init(&dev_priv
->pps_mutex
);
14472 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
14473 * resume, or other times. This quirk makes sure that's the case for
14474 * affected systems.
14476 static void quirk_pipea_force(struct drm_device
*dev
)
14478 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14480 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
14481 DRM_INFO("applying pipe a force quirk\n");
14484 static void quirk_pipeb_force(struct drm_device
*dev
)
14486 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14488 dev_priv
->quirks
|= QUIRK_PIPEB_FORCE
;
14489 DRM_INFO("applying pipe b force quirk\n");
14493 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
14495 static void quirk_ssc_force_disable(struct drm_device
*dev
)
14497 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14498 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
14499 DRM_INFO("applying lvds SSC disable quirk\n");
14503 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
14506 static void quirk_invert_brightness(struct drm_device
*dev
)
14508 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14509 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
14510 DRM_INFO("applying inverted panel brightness quirk\n");
14513 /* Some VBT's incorrectly indicate no backlight is present */
14514 static void quirk_backlight_present(struct drm_device
*dev
)
14516 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14517 dev_priv
->quirks
|= QUIRK_BACKLIGHT_PRESENT
;
14518 DRM_INFO("applying backlight present quirk\n");
14521 struct intel_quirk
{
14523 int subsystem_vendor
;
14524 int subsystem_device
;
14525 void (*hook
)(struct drm_device
*dev
);
14528 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
14529 struct intel_dmi_quirk
{
14530 void (*hook
)(struct drm_device
*dev
);
14531 const struct dmi_system_id (*dmi_id_list
)[];
14534 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
14536 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
14540 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
14542 .dmi_id_list
= &(const struct dmi_system_id
[]) {
14544 .callback
= intel_dmi_reverse_brightness
,
14545 .ident
= "NCR Corporation",
14546 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
14547 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
14550 { } /* terminating entry */
14552 .hook
= quirk_invert_brightness
,
14556 static struct intel_quirk intel_quirks
[] = {
14557 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
14558 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
14560 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
14561 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
14563 /* 830 needs to leave pipe A & dpll A up */
14564 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
14566 /* 830 needs to leave pipe B & dpll B up */
14567 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipeb_force
},
14569 /* Lenovo U160 cannot use SSC on LVDS */
14570 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
14572 /* Sony Vaio Y cannot use SSC on LVDS */
14573 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
14575 /* Acer Aspire 5734Z must invert backlight brightness */
14576 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
14578 /* Acer/eMachines G725 */
14579 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
14581 /* Acer/eMachines e725 */
14582 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
14584 /* Acer/Packard Bell NCL20 */
14585 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
14587 /* Acer Aspire 4736Z */
14588 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
14590 /* Acer Aspire 5336 */
14591 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
14593 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
14594 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present
},
14596 /* Acer C720 Chromebook (Core i3 4005U) */
14597 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present
},
14599 /* Apple Macbook 2,1 (Core 2 T7400) */
14600 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present
},
14602 /* Toshiba CB35 Chromebook (Celeron 2955U) */
14603 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present
},
14605 /* HP Chromebook 14 (Celeron 2955U) */
14606 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present
},
14608 /* Dell Chromebook 11 */
14609 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present
},
14612 static void intel_init_quirks(struct drm_device
*dev
)
14614 struct pci_dev
*d
= dev
->pdev
;
14617 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
14618 struct intel_quirk
*q
= &intel_quirks
[i
];
14620 if (d
->device
== q
->device
&&
14621 (d
->subsystem_vendor
== q
->subsystem_vendor
||
14622 q
->subsystem_vendor
== PCI_ANY_ID
) &&
14623 (d
->subsystem_device
== q
->subsystem_device
||
14624 q
->subsystem_device
== PCI_ANY_ID
))
14627 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
14628 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
14629 intel_dmi_quirks
[i
].hook(dev
);
14633 /* Disable the VGA plane that we never use */
14634 static void i915_disable_vga(struct drm_device
*dev
)
14636 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14638 u32 vga_reg
= i915_vgacntrl_reg(dev
);
14640 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
14641 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
14642 outb(SR01
, VGA_SR_INDEX
);
14643 sr1
= inb(VGA_SR_DATA
);
14644 outb(sr1
| 1<<5, VGA_SR_DATA
);
14645 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
14648 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
14649 POSTING_READ(vga_reg
);
14652 void intel_modeset_init_hw(struct drm_device
*dev
)
14654 intel_prepare_ddi(dev
);
14656 if (IS_VALLEYVIEW(dev
))
14657 vlv_update_cdclk(dev
);
14659 intel_init_clock_gating(dev
);
14661 intel_enable_gt_powersave(dev
);
14664 void intel_modeset_init(struct drm_device
*dev
)
14666 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14669 struct intel_crtc
*crtc
;
14671 drm_mode_config_init(dev
);
14673 dev
->mode_config
.min_width
= 0;
14674 dev
->mode_config
.min_height
= 0;
14676 dev
->mode_config
.preferred_depth
= 24;
14677 dev
->mode_config
.prefer_shadow
= 1;
14679 dev
->mode_config
.allow_fb_modifiers
= true;
14681 dev
->mode_config
.funcs
= &intel_mode_funcs
;
14683 intel_init_quirks(dev
);
14685 intel_init_pm(dev
);
14687 if (INTEL_INFO(dev
)->num_pipes
== 0)
14690 intel_init_display(dev
);
14691 intel_init_audio(dev
);
14693 if (IS_GEN2(dev
)) {
14694 dev
->mode_config
.max_width
= 2048;
14695 dev
->mode_config
.max_height
= 2048;
14696 } else if (IS_GEN3(dev
)) {
14697 dev
->mode_config
.max_width
= 4096;
14698 dev
->mode_config
.max_height
= 4096;
14700 dev
->mode_config
.max_width
= 8192;
14701 dev
->mode_config
.max_height
= 8192;
14704 if (IS_845G(dev
) || IS_I865G(dev
)) {
14705 dev
->mode_config
.cursor_width
= IS_845G(dev
) ? 64 : 512;
14706 dev
->mode_config
.cursor_height
= 1023;
14707 } else if (IS_GEN2(dev
)) {
14708 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
14709 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
14711 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
14712 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
14715 dev
->mode_config
.fb_base
= dev_priv
->gtt
.mappable_base
;
14717 DRM_DEBUG_KMS("%d display pipe%s available.\n",
14718 INTEL_INFO(dev
)->num_pipes
,
14719 INTEL_INFO(dev
)->num_pipes
> 1 ? "s" : "");
14721 for_each_pipe(dev_priv
, pipe
) {
14722 intel_crtc_init(dev
, pipe
);
14723 for_each_sprite(dev_priv
, pipe
, sprite
) {
14724 ret
= intel_plane_init(dev
, pipe
, sprite
);
14726 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
14727 pipe_name(pipe
), sprite_name(pipe
, sprite
), ret
);
14731 intel_init_dpio(dev
);
14733 intel_shared_dpll_init(dev
);
14735 /* Just disable it once at startup */
14736 i915_disable_vga(dev
);
14737 intel_setup_outputs(dev
);
14739 /* Just in case the BIOS is doing something questionable. */
14740 intel_fbc_disable(dev
);
14742 drm_modeset_lock_all(dev
);
14743 intel_modeset_setup_hw_state(dev
, false);
14744 drm_modeset_unlock_all(dev
);
14746 for_each_intel_crtc(dev
, crtc
) {
14751 * Note that reserving the BIOS fb up front prevents us
14752 * from stuffing other stolen allocations like the ring
14753 * on top. This prevents some ugliness at boot time, and
14754 * can even allow for smooth boot transitions if the BIOS
14755 * fb is large enough for the active pipe configuration.
14757 if (dev_priv
->display
.get_initial_plane_config
) {
14758 dev_priv
->display
.get_initial_plane_config(crtc
,
14759 &crtc
->plane_config
);
14761 * If the fb is shared between multiple heads, we'll
14762 * just get the first one.
14764 intel_find_initial_plane_obj(crtc
, &crtc
->plane_config
);
14769 static void intel_enable_pipe_a(struct drm_device
*dev
)
14771 struct intel_connector
*connector
;
14772 struct drm_connector
*crt
= NULL
;
14773 struct intel_load_detect_pipe load_detect_temp
;
14774 struct drm_modeset_acquire_ctx
*ctx
= dev
->mode_config
.acquire_ctx
;
14776 /* We can't just switch on the pipe A, we need to set things up with a
14777 * proper mode and output configuration. As a gross hack, enable pipe A
14778 * by enabling the load detect pipe once. */
14779 for_each_intel_connector(dev
, connector
) {
14780 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
14781 crt
= &connector
->base
;
14789 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
, ctx
))
14790 intel_release_load_detect_pipe(crt
, &load_detect_temp
, ctx
);
14794 intel_check_plane_mapping(struct intel_crtc
*crtc
)
14796 struct drm_device
*dev
= crtc
->base
.dev
;
14797 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14800 if (INTEL_INFO(dev
)->num_pipes
== 1)
14803 reg
= DSPCNTR(!crtc
->plane
);
14804 val
= I915_READ(reg
);
14806 if ((val
& DISPLAY_PLANE_ENABLE
) &&
14807 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
14813 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
14815 struct drm_device
*dev
= crtc
->base
.dev
;
14816 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14819 /* Clear any frame start delays used for debugging left by the BIOS */
14820 reg
= PIPECONF(crtc
->config
->cpu_transcoder
);
14821 I915_WRITE(reg
, I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
14823 /* restore vblank interrupts to correct state */
14824 drm_crtc_vblank_reset(&crtc
->base
);
14825 if (crtc
->active
) {
14826 update_scanline_offset(crtc
);
14827 drm_crtc_vblank_on(&crtc
->base
);
14830 /* We need to sanitize the plane -> pipe mapping first because this will
14831 * disable the crtc (and hence change the state) if it is wrong. Note
14832 * that gen4+ has a fixed plane -> pipe mapping. */
14833 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
14834 struct intel_connector
*connector
;
14837 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
14838 crtc
->base
.base
.id
);
14840 /* Pipe has the wrong plane attached and the plane is active.
14841 * Temporarily change the plane mapping and disable everything
14843 plane
= crtc
->plane
;
14844 to_intel_plane_state(crtc
->base
.primary
->state
)->visible
= true;
14845 crtc
->plane
= !plane
;
14846 intel_crtc_disable_planes(&crtc
->base
);
14847 dev_priv
->display
.crtc_disable(&crtc
->base
);
14848 crtc
->plane
= plane
;
14850 /* ... and break all links. */
14851 for_each_intel_connector(dev
, connector
) {
14852 if (connector
->encoder
->base
.crtc
!= &crtc
->base
)
14855 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
14856 connector
->base
.encoder
= NULL
;
14858 /* multiple connectors may have the same encoder:
14859 * handle them and break crtc link separately */
14860 for_each_intel_connector(dev
, connector
)
14861 if (connector
->encoder
->base
.crtc
== &crtc
->base
) {
14862 connector
->encoder
->base
.crtc
= NULL
;
14863 connector
->encoder
->connectors_active
= false;
14866 WARN_ON(crtc
->active
);
14867 crtc
->base
.state
->enable
= false;
14868 crtc
->base
.state
->active
= false;
14869 crtc
->base
.enabled
= false;
14872 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
14873 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
14874 /* BIOS forgot to enable pipe A, this mostly happens after
14875 * resume. Force-enable the pipe to fix this, the update_dpms
14876 * call below we restore the pipe to the right state, but leave
14877 * the required bits on. */
14878 intel_enable_pipe_a(dev
);
14881 /* Adjust the state of the output pipe according to whether we
14882 * have active connectors/encoders. */
14883 intel_crtc_update_dpms(&crtc
->base
);
14885 if (crtc
->active
!= crtc
->base
.state
->enable
) {
14886 struct intel_encoder
*encoder
;
14888 /* This can happen either due to bugs in the get_hw_state
14889 * functions or because the pipe is force-enabled due to the
14891 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
14892 crtc
->base
.base
.id
,
14893 crtc
->base
.state
->enable
? "enabled" : "disabled",
14894 crtc
->active
? "enabled" : "disabled");
14896 crtc
->base
.state
->enable
= crtc
->active
;
14897 crtc
->base
.state
->active
= crtc
->active
;
14898 crtc
->base
.enabled
= crtc
->active
;
14900 /* Because we only establish the connector -> encoder ->
14901 * crtc links if something is active, this means the
14902 * crtc is now deactivated. Break the links. connector
14903 * -> encoder links are only establish when things are
14904 * actually up, hence no need to break them. */
14905 WARN_ON(crtc
->active
);
14907 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
14908 WARN_ON(encoder
->connectors_active
);
14909 encoder
->base
.crtc
= NULL
;
14913 if (crtc
->active
|| HAS_GMCH_DISPLAY(dev
)) {
14915 * We start out with underrun reporting disabled to avoid races.
14916 * For correct bookkeeping mark this on active crtcs.
14918 * Also on gmch platforms we dont have any hardware bits to
14919 * disable the underrun reporting. Which means we need to start
14920 * out with underrun reporting disabled also on inactive pipes,
14921 * since otherwise we'll complain about the garbage we read when
14922 * e.g. coming up after runtime pm.
14924 * No protection against concurrent access is required - at
14925 * worst a fifo underrun happens which also sets this to false.
14927 crtc
->cpu_fifo_underrun_disabled
= true;
14928 crtc
->pch_fifo_underrun_disabled
= true;
14932 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
14934 struct intel_connector
*connector
;
14935 struct drm_device
*dev
= encoder
->base
.dev
;
14937 /* We need to check both for a crtc link (meaning that the
14938 * encoder is active and trying to read from a pipe) and the
14939 * pipe itself being active. */
14940 bool has_active_crtc
= encoder
->base
.crtc
&&
14941 to_intel_crtc(encoder
->base
.crtc
)->active
;
14943 if (encoder
->connectors_active
&& !has_active_crtc
) {
14944 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
14945 encoder
->base
.base
.id
,
14946 encoder
->base
.name
);
14948 /* Connector is active, but has no active pipe. This is
14949 * fallout from our resume register restoring. Disable
14950 * the encoder manually again. */
14951 if (encoder
->base
.crtc
) {
14952 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
14953 encoder
->base
.base
.id
,
14954 encoder
->base
.name
);
14955 encoder
->disable(encoder
);
14956 if (encoder
->post_disable
)
14957 encoder
->post_disable(encoder
);
14959 encoder
->base
.crtc
= NULL
;
14960 encoder
->connectors_active
= false;
14962 /* Inconsistent output/port/pipe state happens presumably due to
14963 * a bug in one of the get_hw_state functions. Or someplace else
14964 * in our code, like the register restore mess on resume. Clamp
14965 * things to off as a safer default. */
14966 for_each_intel_connector(dev
, connector
) {
14967 if (connector
->encoder
!= encoder
)
14969 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
14970 connector
->base
.encoder
= NULL
;
14973 /* Enabled encoders without active connectors will be fixed in
14974 * the crtc fixup. */
14977 void i915_redisable_vga_power_on(struct drm_device
*dev
)
14979 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14980 u32 vga_reg
= i915_vgacntrl_reg(dev
);
14982 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
14983 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
14984 i915_disable_vga(dev
);
14988 void i915_redisable_vga(struct drm_device
*dev
)
14990 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14992 /* This function can be called both from intel_modeset_setup_hw_state or
14993 * at a very early point in our resume sequence, where the power well
14994 * structures are not yet restored. Since this function is at a very
14995 * paranoid "someone might have enabled VGA while we were not looking"
14996 * level, just check if the power well is enabled instead of trying to
14997 * follow the "don't touch the power well if we don't need it" policy
14998 * the rest of the driver uses. */
14999 if (!intel_display_power_is_enabled(dev_priv
, POWER_DOMAIN_VGA
))
15002 i915_redisable_vga_power_on(dev
);
15005 static bool primary_get_hw_state(struct intel_crtc
*crtc
)
15007 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
15012 return I915_READ(DSPCNTR(crtc
->plane
)) & DISPLAY_PLANE_ENABLE
;
15015 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
15017 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15019 struct intel_crtc
*crtc
;
15020 struct intel_encoder
*encoder
;
15021 struct intel_connector
*connector
;
15024 for_each_intel_crtc(dev
, crtc
) {
15025 struct drm_plane
*primary
= crtc
->base
.primary
;
15026 struct intel_plane_state
*plane_state
;
15028 memset(crtc
->config
, 0, sizeof(*crtc
->config
));
15030 crtc
->config
->quirks
|= PIPE_CONFIG_QUIRK_INHERITED_MODE
;
15032 crtc
->active
= dev_priv
->display
.get_pipe_config(crtc
,
15035 crtc
->base
.state
->enable
= crtc
->active
;
15036 crtc
->base
.state
->active
= crtc
->active
;
15037 crtc
->base
.enabled
= crtc
->active
;
15039 plane_state
= to_intel_plane_state(primary
->state
);
15040 plane_state
->visible
= primary_get_hw_state(crtc
);
15042 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
15043 crtc
->base
.base
.id
,
15044 crtc
->active
? "enabled" : "disabled");
15047 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
15048 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
15050 pll
->on
= pll
->get_hw_state(dev_priv
, pll
,
15051 &pll
->config
.hw_state
);
15053 pll
->config
.crtc_mask
= 0;
15054 for_each_intel_crtc(dev
, crtc
) {
15055 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
) {
15057 pll
->config
.crtc_mask
|= 1 << crtc
->pipe
;
15061 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15062 pll
->name
, pll
->config
.crtc_mask
, pll
->on
);
15064 if (pll
->config
.crtc_mask
)
15065 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
15068 for_each_intel_encoder(dev
, encoder
) {
15071 if (encoder
->get_hw_state(encoder
, &pipe
)) {
15072 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
15073 encoder
->base
.crtc
= &crtc
->base
;
15074 encoder
->get_config(encoder
, crtc
->config
);
15076 encoder
->base
.crtc
= NULL
;
15079 encoder
->connectors_active
= false;
15080 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15081 encoder
->base
.base
.id
,
15082 encoder
->base
.name
,
15083 encoder
->base
.crtc
? "enabled" : "disabled",
15087 for_each_intel_connector(dev
, connector
) {
15088 if (connector
->get_hw_state(connector
)) {
15089 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
15090 connector
->encoder
->connectors_active
= true;
15091 connector
->base
.encoder
= &connector
->encoder
->base
;
15093 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
15094 connector
->base
.encoder
= NULL
;
15096 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
15097 connector
->base
.base
.id
,
15098 connector
->base
.name
,
15099 connector
->base
.encoder
? "enabled" : "disabled");
15103 /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
15104 * and i915 state tracking structures. */
15105 void intel_modeset_setup_hw_state(struct drm_device
*dev
,
15106 bool force_restore
)
15108 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15110 struct intel_crtc
*crtc
;
15111 struct intel_encoder
*encoder
;
15114 intel_modeset_readout_hw_state(dev
);
15117 * Now that we have the config, copy it to each CRTC struct
15118 * Note that this could go away if we move to using crtc_config
15119 * checking everywhere.
15121 for_each_intel_crtc(dev
, crtc
) {
15122 if (crtc
->active
&& i915
.fastboot
) {
15123 intel_mode_from_pipe_config(&crtc
->base
.mode
,
15125 DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
15126 crtc
->base
.base
.id
);
15127 drm_mode_debug_printmodeline(&crtc
->base
.mode
);
15131 /* HW state is read out, now we need to sanitize this mess. */
15132 for_each_intel_encoder(dev
, encoder
) {
15133 intel_sanitize_encoder(encoder
);
15136 for_each_pipe(dev_priv
, pipe
) {
15137 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
15138 intel_sanitize_crtc(crtc
);
15139 intel_dump_pipe_config(crtc
, crtc
->config
,
15140 "[setup_hw_state]");
15143 intel_modeset_update_connector_atomic_state(dev
);
15145 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
15146 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
15148 if (!pll
->on
|| pll
->active
)
15151 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
15153 pll
->disable(dev_priv
, pll
);
15158 skl_wm_get_hw_state(dev
);
15159 else if (HAS_PCH_SPLIT(dev
))
15160 ilk_wm_get_hw_state(dev
);
15162 if (force_restore
) {
15163 i915_redisable_vga(dev
);
15166 * We need to use raw interfaces for restoring state to avoid
15167 * checking (bogus) intermediate states.
15169 for_each_pipe(dev_priv
, pipe
) {
15170 struct drm_crtc
*crtc
=
15171 dev_priv
->pipe_to_crtc_mapping
[pipe
];
15173 intel_crtc_restore_mode(crtc
);
15176 intel_modeset_update_staged_output_state(dev
);
15179 intel_modeset_check_state(dev
);
15182 void intel_modeset_gem_init(struct drm_device
*dev
)
15184 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15185 struct drm_crtc
*c
;
15186 struct drm_i915_gem_object
*obj
;
15189 mutex_lock(&dev
->struct_mutex
);
15190 intel_init_gt_powersave(dev
);
15191 mutex_unlock(&dev
->struct_mutex
);
15194 * There may be no VBT; and if the BIOS enabled SSC we can
15195 * just keep using it to avoid unnecessary flicker. Whereas if the
15196 * BIOS isn't using it, don't assume it will work even if the VBT
15197 * indicates as much.
15199 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
15200 dev_priv
->vbt
.lvds_use_ssc
= !!(I915_READ(PCH_DREF_CONTROL
) &
15203 intel_modeset_init_hw(dev
);
15205 intel_setup_overlay(dev
);
15208 * Make sure any fbs we allocated at startup are properly
15209 * pinned & fenced. When we do the allocation it's too early
15212 for_each_crtc(dev
, c
) {
15213 obj
= intel_fb_obj(c
->primary
->fb
);
15217 mutex_lock(&dev
->struct_mutex
);
15218 ret
= intel_pin_and_fence_fb_obj(c
->primary
,
15222 mutex_unlock(&dev
->struct_mutex
);
15224 DRM_ERROR("failed to pin boot fb on pipe %d\n",
15225 to_intel_crtc(c
)->pipe
);
15226 drm_framebuffer_unreference(c
->primary
->fb
);
15227 c
->primary
->fb
= NULL
;
15228 update_state_fb(c
->primary
);
15232 intel_backlight_register(dev
);
15235 void intel_connector_unregister(struct intel_connector
*intel_connector
)
15237 struct drm_connector
*connector
= &intel_connector
->base
;
15239 intel_panel_destroy_backlight(connector
);
15240 drm_connector_unregister(connector
);
15243 void intel_modeset_cleanup(struct drm_device
*dev
)
15245 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15246 struct drm_connector
*connector
;
15248 intel_disable_gt_powersave(dev
);
15250 intel_backlight_unregister(dev
);
15253 * Interrupts and polling as the first thing to avoid creating havoc.
15254 * Too much stuff here (turning of connectors, ...) would
15255 * experience fancy races otherwise.
15257 intel_irq_uninstall(dev_priv
);
15260 * Due to the hpd irq storm handling the hotplug work can re-arm the
15261 * poll handlers. Hence disable polling after hpd handling is shut down.
15263 drm_kms_helper_poll_fini(dev
);
15265 mutex_lock(&dev
->struct_mutex
);
15267 intel_unregister_dsm_handler();
15269 intel_fbc_disable(dev
);
15271 mutex_unlock(&dev
->struct_mutex
);
15273 /* flush any delayed tasks or pending work */
15274 flush_scheduled_work();
15276 /* destroy the backlight and sysfs files before encoders/connectors */
15277 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
15278 struct intel_connector
*intel_connector
;
15280 intel_connector
= to_intel_connector(connector
);
15281 intel_connector
->unregister(intel_connector
);
15284 drm_mode_config_cleanup(dev
);
15286 intel_cleanup_overlay(dev
);
15288 mutex_lock(&dev
->struct_mutex
);
15289 intel_cleanup_gt_powersave(dev
);
15290 mutex_unlock(&dev
->struct_mutex
);
15294 * Return which encoder is currently attached for connector.
15296 struct drm_encoder
*intel_best_encoder(struct drm_connector
*connector
)
15298 return &intel_attached_encoder(connector
)->base
;
15301 void intel_connector_attach_encoder(struct intel_connector
*connector
,
15302 struct intel_encoder
*encoder
)
15304 connector
->encoder
= encoder
;
15305 drm_mode_connector_attach_encoder(&connector
->base
,
15310 * set vga decode state - true == enable VGA decode
15312 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
15314 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15315 unsigned reg
= INTEL_INFO(dev
)->gen
>= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
15318 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
15319 DRM_ERROR("failed to read control word\n");
15323 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
15327 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
15329 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
15331 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
15332 DRM_ERROR("failed to write control word\n");
15339 struct intel_display_error_state
{
15341 u32 power_well_driver
;
15343 int num_transcoders
;
15345 struct intel_cursor_error_state
{
15350 } cursor
[I915_MAX_PIPES
];
15352 struct intel_pipe_error_state
{
15353 bool power_domain_on
;
15356 } pipe
[I915_MAX_PIPES
];
15358 struct intel_plane_error_state
{
15366 } plane
[I915_MAX_PIPES
];
15368 struct intel_transcoder_error_state
{
15369 bool power_domain_on
;
15370 enum transcoder cpu_transcoder
;
15383 struct intel_display_error_state
*
15384 intel_display_capture_error_state(struct drm_device
*dev
)
15386 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15387 struct intel_display_error_state
*error
;
15388 int transcoders
[] = {
15396 if (INTEL_INFO(dev
)->num_pipes
== 0)
15399 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
15403 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
15404 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
15406 for_each_pipe(dev_priv
, i
) {
15407 error
->pipe
[i
].power_domain_on
=
15408 __intel_display_power_is_enabled(dev_priv
,
15409 POWER_DOMAIN_PIPE(i
));
15410 if (!error
->pipe
[i
].power_domain_on
)
15413 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
15414 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
15415 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
15417 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
15418 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
15419 if (INTEL_INFO(dev
)->gen
<= 3) {
15420 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
15421 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
15423 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
15424 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
15425 if (INTEL_INFO(dev
)->gen
>= 4) {
15426 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
15427 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
15430 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
15432 if (HAS_GMCH_DISPLAY(dev
))
15433 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
15436 error
->num_transcoders
= INTEL_INFO(dev
)->num_pipes
;
15437 if (HAS_DDI(dev_priv
->dev
))
15438 error
->num_transcoders
++; /* Account for eDP. */
15440 for (i
= 0; i
< error
->num_transcoders
; i
++) {
15441 enum transcoder cpu_transcoder
= transcoders
[i
];
15443 error
->transcoder
[i
].power_domain_on
=
15444 __intel_display_power_is_enabled(dev_priv
,
15445 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
15446 if (!error
->transcoder
[i
].power_domain_on
)
15449 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
15451 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
15452 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
15453 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
15454 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
15455 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
15456 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
15457 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
15463 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
15466 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
15467 struct drm_device
*dev
,
15468 struct intel_display_error_state
*error
)
15470 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15476 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev
)->num_pipes
);
15477 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
15478 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
15479 error
->power_well_driver
);
15480 for_each_pipe(dev_priv
, i
) {
15481 err_printf(m
, "Pipe [%d]:\n", i
);
15482 err_printf(m
, " Power: %s\n",
15483 error
->pipe
[i
].power_domain_on
? "on" : "off");
15484 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
15485 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
15487 err_printf(m
, "Plane [%d]:\n", i
);
15488 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
15489 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
15490 if (INTEL_INFO(dev
)->gen
<= 3) {
15491 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
15492 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
15494 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
15495 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
15496 if (INTEL_INFO(dev
)->gen
>= 4) {
15497 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
15498 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
15501 err_printf(m
, "Cursor [%d]:\n", i
);
15502 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
15503 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
15504 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
15507 for (i
= 0; i
< error
->num_transcoders
; i
++) {
15508 err_printf(m
, "CPU transcoder: %c\n",
15509 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
15510 err_printf(m
, " Power: %s\n",
15511 error
->transcoder
[i
].power_domain_on
? "on" : "off");
15512 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
15513 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
15514 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
15515 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
15516 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
15517 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
15518 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);
15522 void intel_modeset_preclose(struct drm_device
*dev
, struct drm_file
*file
)
15524 struct intel_crtc
*crtc
;
15526 for_each_intel_crtc(dev
, crtc
) {
15527 struct intel_unpin_work
*work
;
15529 spin_lock_irq(&dev
->event_lock
);
15531 work
= crtc
->unpin_work
;
15533 if (work
&& work
->event
&&
15534 work
->event
->base
.file_priv
== file
) {
15535 kfree(work
->event
);
15536 work
->event
= NULL
;
15539 spin_unlock_irq(&dev
->event_lock
);