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
[] = {
57 /* Primary plane formats for gen >= 4 */
58 static const uint32_t i965_primary_formats
[] = {
65 DRM_FORMAT_XRGB2101010
,
66 DRM_FORMAT_XBGR2101010
,
70 static const uint32_t intel_cursor_formats
[] = {
74 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
, bool on
);
76 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
77 struct intel_crtc_state
*pipe_config
);
78 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
79 struct intel_crtc_state
*pipe_config
);
81 static int intel_set_mode(struct drm_crtc
*crtc
,
82 struct drm_atomic_state
*state
);
83 static int intel_framebuffer_init(struct drm_device
*dev
,
84 struct intel_framebuffer
*ifb
,
85 struct drm_mode_fb_cmd2
*mode_cmd
,
86 struct drm_i915_gem_object
*obj
);
87 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
);
88 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
);
89 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
90 struct intel_link_m_n
*m_n
,
91 struct intel_link_m_n
*m2_n2
);
92 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
);
93 static void haswell_set_pipeconf(struct drm_crtc
*crtc
);
94 static void intel_set_pipe_csc(struct drm_crtc
*crtc
);
95 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
96 const struct intel_crtc_state
*pipe_config
);
97 static void chv_prepare_pll(struct intel_crtc
*crtc
,
98 const struct intel_crtc_state
*pipe_config
);
99 static void intel_begin_crtc_commit(struct drm_crtc
*crtc
);
100 static void intel_finish_crtc_commit(struct drm_crtc
*crtc
);
101 static void skl_init_scalers(struct drm_device
*dev
, struct intel_crtc
*intel_crtc
,
102 struct intel_crtc_state
*crtc_state
);
103 static int i9xx_get_refclk(const struct intel_crtc_state
*crtc_state
,
105 static void intel_crtc_enable_planes(struct drm_crtc
*crtc
);
106 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
);
108 static struct intel_encoder
*intel_find_encoder(struct intel_connector
*connector
, int pipe
)
110 if (!connector
->mst_port
)
111 return connector
->encoder
;
113 return &connector
->mst_port
->mst_encoders
[pipe
]->base
;
122 int p2_slow
, p2_fast
;
125 typedef struct intel_limit intel_limit_t
;
127 intel_range_t dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
132 intel_pch_rawclk(struct drm_device
*dev
)
134 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
136 WARN_ON(!HAS_PCH_SPLIT(dev
));
138 return I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
;
141 static inline u32
/* units of 100MHz */
142 intel_fdi_link_freq(struct drm_device
*dev
)
145 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
146 return (I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2;
151 static const intel_limit_t intel_limits_i8xx_dac
= {
152 .dot
= { .min
= 25000, .max
= 350000 },
153 .vco
= { .min
= 908000, .max
= 1512000 },
154 .n
= { .min
= 2, .max
= 16 },
155 .m
= { .min
= 96, .max
= 140 },
156 .m1
= { .min
= 18, .max
= 26 },
157 .m2
= { .min
= 6, .max
= 16 },
158 .p
= { .min
= 4, .max
= 128 },
159 .p1
= { .min
= 2, .max
= 33 },
160 .p2
= { .dot_limit
= 165000,
161 .p2_slow
= 4, .p2_fast
= 2 },
164 static const intel_limit_t intel_limits_i8xx_dvo
= {
165 .dot
= { .min
= 25000, .max
= 350000 },
166 .vco
= { .min
= 908000, .max
= 1512000 },
167 .n
= { .min
= 2, .max
= 16 },
168 .m
= { .min
= 96, .max
= 140 },
169 .m1
= { .min
= 18, .max
= 26 },
170 .m2
= { .min
= 6, .max
= 16 },
171 .p
= { .min
= 4, .max
= 128 },
172 .p1
= { .min
= 2, .max
= 33 },
173 .p2
= { .dot_limit
= 165000,
174 .p2_slow
= 4, .p2_fast
= 4 },
177 static const intel_limit_t intel_limits_i8xx_lvds
= {
178 .dot
= { .min
= 25000, .max
= 350000 },
179 .vco
= { .min
= 908000, .max
= 1512000 },
180 .n
= { .min
= 2, .max
= 16 },
181 .m
= { .min
= 96, .max
= 140 },
182 .m1
= { .min
= 18, .max
= 26 },
183 .m2
= { .min
= 6, .max
= 16 },
184 .p
= { .min
= 4, .max
= 128 },
185 .p1
= { .min
= 1, .max
= 6 },
186 .p2
= { .dot_limit
= 165000,
187 .p2_slow
= 14, .p2_fast
= 7 },
190 static const intel_limit_t intel_limits_i9xx_sdvo
= {
191 .dot
= { .min
= 20000, .max
= 400000 },
192 .vco
= { .min
= 1400000, .max
= 2800000 },
193 .n
= { .min
= 1, .max
= 6 },
194 .m
= { .min
= 70, .max
= 120 },
195 .m1
= { .min
= 8, .max
= 18 },
196 .m2
= { .min
= 3, .max
= 7 },
197 .p
= { .min
= 5, .max
= 80 },
198 .p1
= { .min
= 1, .max
= 8 },
199 .p2
= { .dot_limit
= 200000,
200 .p2_slow
= 10, .p2_fast
= 5 },
203 static const intel_limit_t intel_limits_i9xx_lvds
= {
204 .dot
= { .min
= 20000, .max
= 400000 },
205 .vco
= { .min
= 1400000, .max
= 2800000 },
206 .n
= { .min
= 1, .max
= 6 },
207 .m
= { .min
= 70, .max
= 120 },
208 .m1
= { .min
= 8, .max
= 18 },
209 .m2
= { .min
= 3, .max
= 7 },
210 .p
= { .min
= 7, .max
= 98 },
211 .p1
= { .min
= 1, .max
= 8 },
212 .p2
= { .dot_limit
= 112000,
213 .p2_slow
= 14, .p2_fast
= 7 },
217 static const intel_limit_t intel_limits_g4x_sdvo
= {
218 .dot
= { .min
= 25000, .max
= 270000 },
219 .vco
= { .min
= 1750000, .max
= 3500000},
220 .n
= { .min
= 1, .max
= 4 },
221 .m
= { .min
= 104, .max
= 138 },
222 .m1
= { .min
= 17, .max
= 23 },
223 .m2
= { .min
= 5, .max
= 11 },
224 .p
= { .min
= 10, .max
= 30 },
225 .p1
= { .min
= 1, .max
= 3},
226 .p2
= { .dot_limit
= 270000,
232 static const intel_limit_t intel_limits_g4x_hdmi
= {
233 .dot
= { .min
= 22000, .max
= 400000 },
234 .vco
= { .min
= 1750000, .max
= 3500000},
235 .n
= { .min
= 1, .max
= 4 },
236 .m
= { .min
= 104, .max
= 138 },
237 .m1
= { .min
= 16, .max
= 23 },
238 .m2
= { .min
= 5, .max
= 11 },
239 .p
= { .min
= 5, .max
= 80 },
240 .p1
= { .min
= 1, .max
= 8},
241 .p2
= { .dot_limit
= 165000,
242 .p2_slow
= 10, .p2_fast
= 5 },
245 static const intel_limit_t intel_limits_g4x_single_channel_lvds
= {
246 .dot
= { .min
= 20000, .max
= 115000 },
247 .vco
= { .min
= 1750000, .max
= 3500000 },
248 .n
= { .min
= 1, .max
= 3 },
249 .m
= { .min
= 104, .max
= 138 },
250 .m1
= { .min
= 17, .max
= 23 },
251 .m2
= { .min
= 5, .max
= 11 },
252 .p
= { .min
= 28, .max
= 112 },
253 .p1
= { .min
= 2, .max
= 8 },
254 .p2
= { .dot_limit
= 0,
255 .p2_slow
= 14, .p2_fast
= 14
259 static const intel_limit_t intel_limits_g4x_dual_channel_lvds
= {
260 .dot
= { .min
= 80000, .max
= 224000 },
261 .vco
= { .min
= 1750000, .max
= 3500000 },
262 .n
= { .min
= 1, .max
= 3 },
263 .m
= { .min
= 104, .max
= 138 },
264 .m1
= { .min
= 17, .max
= 23 },
265 .m2
= { .min
= 5, .max
= 11 },
266 .p
= { .min
= 14, .max
= 42 },
267 .p1
= { .min
= 2, .max
= 6 },
268 .p2
= { .dot_limit
= 0,
269 .p2_slow
= 7, .p2_fast
= 7
273 static const intel_limit_t intel_limits_pineview_sdvo
= {
274 .dot
= { .min
= 20000, .max
= 400000},
275 .vco
= { .min
= 1700000, .max
= 3500000 },
276 /* Pineview's Ncounter is a ring counter */
277 .n
= { .min
= 3, .max
= 6 },
278 .m
= { .min
= 2, .max
= 256 },
279 /* Pineview only has one combined m divider, which we treat as m2. */
280 .m1
= { .min
= 0, .max
= 0 },
281 .m2
= { .min
= 0, .max
= 254 },
282 .p
= { .min
= 5, .max
= 80 },
283 .p1
= { .min
= 1, .max
= 8 },
284 .p2
= { .dot_limit
= 200000,
285 .p2_slow
= 10, .p2_fast
= 5 },
288 static const intel_limit_t intel_limits_pineview_lvds
= {
289 .dot
= { .min
= 20000, .max
= 400000 },
290 .vco
= { .min
= 1700000, .max
= 3500000 },
291 .n
= { .min
= 3, .max
= 6 },
292 .m
= { .min
= 2, .max
= 256 },
293 .m1
= { .min
= 0, .max
= 0 },
294 .m2
= { .min
= 0, .max
= 254 },
295 .p
= { .min
= 7, .max
= 112 },
296 .p1
= { .min
= 1, .max
= 8 },
297 .p2
= { .dot_limit
= 112000,
298 .p2_slow
= 14, .p2_fast
= 14 },
301 /* Ironlake / Sandybridge
303 * We calculate clock using (register_value + 2) for N/M1/M2, so here
304 * the range value for them is (actual_value - 2).
306 static const intel_limit_t intel_limits_ironlake_dac
= {
307 .dot
= { .min
= 25000, .max
= 350000 },
308 .vco
= { .min
= 1760000, .max
= 3510000 },
309 .n
= { .min
= 1, .max
= 5 },
310 .m
= { .min
= 79, .max
= 127 },
311 .m1
= { .min
= 12, .max
= 22 },
312 .m2
= { .min
= 5, .max
= 9 },
313 .p
= { .min
= 5, .max
= 80 },
314 .p1
= { .min
= 1, .max
= 8 },
315 .p2
= { .dot_limit
= 225000,
316 .p2_slow
= 10, .p2_fast
= 5 },
319 static const intel_limit_t intel_limits_ironlake_single_lvds
= {
320 .dot
= { .min
= 25000, .max
= 350000 },
321 .vco
= { .min
= 1760000, .max
= 3510000 },
322 .n
= { .min
= 1, .max
= 3 },
323 .m
= { .min
= 79, .max
= 118 },
324 .m1
= { .min
= 12, .max
= 22 },
325 .m2
= { .min
= 5, .max
= 9 },
326 .p
= { .min
= 28, .max
= 112 },
327 .p1
= { .min
= 2, .max
= 8 },
328 .p2
= { .dot_limit
= 225000,
329 .p2_slow
= 14, .p2_fast
= 14 },
332 static const intel_limit_t intel_limits_ironlake_dual_lvds
= {
333 .dot
= { .min
= 25000, .max
= 350000 },
334 .vco
= { .min
= 1760000, .max
= 3510000 },
335 .n
= { .min
= 1, .max
= 3 },
336 .m
= { .min
= 79, .max
= 127 },
337 .m1
= { .min
= 12, .max
= 22 },
338 .m2
= { .min
= 5, .max
= 9 },
339 .p
= { .min
= 14, .max
= 56 },
340 .p1
= { .min
= 2, .max
= 8 },
341 .p2
= { .dot_limit
= 225000,
342 .p2_slow
= 7, .p2_fast
= 7 },
345 /* LVDS 100mhz refclk limits. */
346 static const intel_limit_t intel_limits_ironlake_single_lvds_100m
= {
347 .dot
= { .min
= 25000, .max
= 350000 },
348 .vco
= { .min
= 1760000, .max
= 3510000 },
349 .n
= { .min
= 1, .max
= 2 },
350 .m
= { .min
= 79, .max
= 126 },
351 .m1
= { .min
= 12, .max
= 22 },
352 .m2
= { .min
= 5, .max
= 9 },
353 .p
= { .min
= 28, .max
= 112 },
354 .p1
= { .min
= 2, .max
= 8 },
355 .p2
= { .dot_limit
= 225000,
356 .p2_slow
= 14, .p2_fast
= 14 },
359 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m
= {
360 .dot
= { .min
= 25000, .max
= 350000 },
361 .vco
= { .min
= 1760000, .max
= 3510000 },
362 .n
= { .min
= 1, .max
= 3 },
363 .m
= { .min
= 79, .max
= 126 },
364 .m1
= { .min
= 12, .max
= 22 },
365 .m2
= { .min
= 5, .max
= 9 },
366 .p
= { .min
= 14, .max
= 42 },
367 .p1
= { .min
= 2, .max
= 6 },
368 .p2
= { .dot_limit
= 225000,
369 .p2_slow
= 7, .p2_fast
= 7 },
372 static const intel_limit_t intel_limits_vlv
= {
374 * These are the data rate limits (measured in fast clocks)
375 * since those are the strictest limits we have. The fast
376 * clock and actual rate limits are more relaxed, so checking
377 * them would make no difference.
379 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
380 .vco
= { .min
= 4000000, .max
= 6000000 },
381 .n
= { .min
= 1, .max
= 7 },
382 .m1
= { .min
= 2, .max
= 3 },
383 .m2
= { .min
= 11, .max
= 156 },
384 .p1
= { .min
= 2, .max
= 3 },
385 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
388 static const intel_limit_t intel_limits_chv
= {
390 * These are the data rate limits (measured in fast clocks)
391 * since those are the strictest limits we have. The fast
392 * clock and actual rate limits are more relaxed, so checking
393 * them would make no difference.
395 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
396 .vco
= { .min
= 4800000, .max
= 6480000 },
397 .n
= { .min
= 1, .max
= 1 },
398 .m1
= { .min
= 2, .max
= 2 },
399 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
400 .p1
= { .min
= 2, .max
= 4 },
401 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
404 static const intel_limit_t intel_limits_bxt
= {
405 /* FIXME: find real dot limits */
406 .dot
= { .min
= 0, .max
= INT_MAX
},
407 .vco
= { .min
= 4800000, .max
= 6480000 },
408 .n
= { .min
= 1, .max
= 1 },
409 .m1
= { .min
= 2, .max
= 2 },
410 /* FIXME: find real m2 limits */
411 .m2
= { .min
= 2 << 22, .max
= 255 << 22 },
412 .p1
= { .min
= 2, .max
= 4 },
413 .p2
= { .p2_slow
= 1, .p2_fast
= 20 },
416 static void vlv_clock(int refclk
, intel_clock_t
*clock
)
418 clock
->m
= clock
->m1
* clock
->m2
;
419 clock
->p
= clock
->p1
* clock
->p2
;
420 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
422 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
423 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
427 * Returns whether any output on the specified pipe is of the specified type
429 bool intel_pipe_has_type(struct intel_crtc
*crtc
, enum intel_output_type type
)
431 struct drm_device
*dev
= crtc
->base
.dev
;
432 struct intel_encoder
*encoder
;
434 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
435 if (encoder
->type
== type
)
442 * Returns whether any output on the specified pipe will have the specified
443 * type after a staged modeset is complete, i.e., the same as
444 * intel_pipe_has_type() but looking at encoder->new_crtc instead of
447 static bool intel_pipe_will_have_type(const struct intel_crtc_state
*crtc_state
,
450 struct drm_atomic_state
*state
= crtc_state
->base
.state
;
451 struct drm_connector
*connector
;
452 struct drm_connector_state
*connector_state
;
453 struct intel_encoder
*encoder
;
454 int i
, num_connectors
= 0;
456 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
457 if (connector_state
->crtc
!= crtc_state
->base
.crtc
)
462 encoder
= to_intel_encoder(connector_state
->best_encoder
);
463 if (encoder
->type
== type
)
467 WARN_ON(num_connectors
== 0);
472 static const intel_limit_t
*
473 intel_ironlake_limit(struct intel_crtc_state
*crtc_state
, int refclk
)
475 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
476 const intel_limit_t
*limit
;
478 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
479 if (intel_is_dual_link_lvds(dev
)) {
480 if (refclk
== 100000)
481 limit
= &intel_limits_ironlake_dual_lvds_100m
;
483 limit
= &intel_limits_ironlake_dual_lvds
;
485 if (refclk
== 100000)
486 limit
= &intel_limits_ironlake_single_lvds_100m
;
488 limit
= &intel_limits_ironlake_single_lvds
;
491 limit
= &intel_limits_ironlake_dac
;
496 static const intel_limit_t
*
497 intel_g4x_limit(struct intel_crtc_state
*crtc_state
)
499 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
500 const intel_limit_t
*limit
;
502 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
503 if (intel_is_dual_link_lvds(dev
))
504 limit
= &intel_limits_g4x_dual_channel_lvds
;
506 limit
= &intel_limits_g4x_single_channel_lvds
;
507 } else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_HDMI
) ||
508 intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_ANALOG
)) {
509 limit
= &intel_limits_g4x_hdmi
;
510 } else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_SDVO
)) {
511 limit
= &intel_limits_g4x_sdvo
;
512 } else /* The option is for other outputs */
513 limit
= &intel_limits_i9xx_sdvo
;
518 static const intel_limit_t
*
519 intel_limit(struct intel_crtc_state
*crtc_state
, int refclk
)
521 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
522 const intel_limit_t
*limit
;
525 limit
= &intel_limits_bxt
;
526 else if (HAS_PCH_SPLIT(dev
))
527 limit
= intel_ironlake_limit(crtc_state
, refclk
);
528 else if (IS_G4X(dev
)) {
529 limit
= intel_g4x_limit(crtc_state
);
530 } else if (IS_PINEVIEW(dev
)) {
531 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
))
532 limit
= &intel_limits_pineview_lvds
;
534 limit
= &intel_limits_pineview_sdvo
;
535 } else if (IS_CHERRYVIEW(dev
)) {
536 limit
= &intel_limits_chv
;
537 } else if (IS_VALLEYVIEW(dev
)) {
538 limit
= &intel_limits_vlv
;
539 } else if (!IS_GEN2(dev
)) {
540 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
))
541 limit
= &intel_limits_i9xx_lvds
;
543 limit
= &intel_limits_i9xx_sdvo
;
545 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
))
546 limit
= &intel_limits_i8xx_lvds
;
547 else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_DVO
))
548 limit
= &intel_limits_i8xx_dvo
;
550 limit
= &intel_limits_i8xx_dac
;
555 /* m1 is reserved as 0 in Pineview, n is a ring counter */
556 static void pineview_clock(int refclk
, intel_clock_t
*clock
)
558 clock
->m
= clock
->m2
+ 2;
559 clock
->p
= clock
->p1
* clock
->p2
;
560 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
562 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
563 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
566 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
568 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
571 static void i9xx_clock(int refclk
, intel_clock_t
*clock
)
573 clock
->m
= i9xx_dpll_compute_m(clock
);
574 clock
->p
= clock
->p1
* clock
->p2
;
575 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
577 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
578 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
581 static void chv_clock(int refclk
, intel_clock_t
*clock
)
583 clock
->m
= clock
->m1
* clock
->m2
;
584 clock
->p
= clock
->p1
* clock
->p2
;
585 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
587 clock
->vco
= DIV_ROUND_CLOSEST_ULL((uint64_t)refclk
* clock
->m
,
589 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
592 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
594 * Returns whether the given set of divisors are valid for a given refclk with
595 * the given connectors.
598 static bool intel_PLL_is_valid(struct drm_device
*dev
,
599 const intel_limit_t
*limit
,
600 const intel_clock_t
*clock
)
602 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
603 INTELPllInvalid("n out of range\n");
604 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
605 INTELPllInvalid("p1 out of range\n");
606 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
607 INTELPllInvalid("m2 out of range\n");
608 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
609 INTELPllInvalid("m1 out of range\n");
611 if (!IS_PINEVIEW(dev
) && !IS_VALLEYVIEW(dev
) && !IS_BROXTON(dev
))
612 if (clock
->m1
<= clock
->m2
)
613 INTELPllInvalid("m1 <= m2\n");
615 if (!IS_VALLEYVIEW(dev
) && !IS_BROXTON(dev
)) {
616 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
617 INTELPllInvalid("p out of range\n");
618 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
619 INTELPllInvalid("m out of range\n");
622 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
623 INTELPllInvalid("vco out of range\n");
624 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
625 * connector, etc., rather than just a single range.
627 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
628 INTELPllInvalid("dot out of range\n");
634 i9xx_find_best_dpll(const intel_limit_t
*limit
,
635 struct intel_crtc_state
*crtc_state
,
636 int target
, int refclk
, intel_clock_t
*match_clock
,
637 intel_clock_t
*best_clock
)
639 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
640 struct drm_device
*dev
= crtc
->base
.dev
;
644 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
646 * For LVDS just rely on its current settings for dual-channel.
647 * We haven't figured out how to reliably set up different
648 * single/dual channel state, if we even can.
650 if (intel_is_dual_link_lvds(dev
))
651 clock
.p2
= limit
->p2
.p2_fast
;
653 clock
.p2
= limit
->p2
.p2_slow
;
655 if (target
< limit
->p2
.dot_limit
)
656 clock
.p2
= limit
->p2
.p2_slow
;
658 clock
.p2
= limit
->p2
.p2_fast
;
661 memset(best_clock
, 0, sizeof(*best_clock
));
663 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
665 for (clock
.m2
= limit
->m2
.min
;
666 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
667 if (clock
.m2
>= clock
.m1
)
669 for (clock
.n
= limit
->n
.min
;
670 clock
.n
<= limit
->n
.max
; clock
.n
++) {
671 for (clock
.p1
= limit
->p1
.min
;
672 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
675 i9xx_clock(refclk
, &clock
);
676 if (!intel_PLL_is_valid(dev
, limit
,
680 clock
.p
!= match_clock
->p
)
683 this_err
= abs(clock
.dot
- target
);
684 if (this_err
< err
) {
693 return (err
!= target
);
697 pnv_find_best_dpll(const intel_limit_t
*limit
,
698 struct intel_crtc_state
*crtc_state
,
699 int target
, int refclk
, intel_clock_t
*match_clock
,
700 intel_clock_t
*best_clock
)
702 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
703 struct drm_device
*dev
= crtc
->base
.dev
;
707 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
709 * For LVDS just rely on its current settings for dual-channel.
710 * We haven't figured out how to reliably set up different
711 * single/dual channel state, if we even can.
713 if (intel_is_dual_link_lvds(dev
))
714 clock
.p2
= limit
->p2
.p2_fast
;
716 clock
.p2
= limit
->p2
.p2_slow
;
718 if (target
< limit
->p2
.dot_limit
)
719 clock
.p2
= limit
->p2
.p2_slow
;
721 clock
.p2
= limit
->p2
.p2_fast
;
724 memset(best_clock
, 0, sizeof(*best_clock
));
726 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
728 for (clock
.m2
= limit
->m2
.min
;
729 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
730 for (clock
.n
= limit
->n
.min
;
731 clock
.n
<= limit
->n
.max
; clock
.n
++) {
732 for (clock
.p1
= limit
->p1
.min
;
733 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
736 pineview_clock(refclk
, &clock
);
737 if (!intel_PLL_is_valid(dev
, limit
,
741 clock
.p
!= match_clock
->p
)
744 this_err
= abs(clock
.dot
- target
);
745 if (this_err
< err
) {
754 return (err
!= target
);
758 g4x_find_best_dpll(const intel_limit_t
*limit
,
759 struct intel_crtc_state
*crtc_state
,
760 int target
, int refclk
, intel_clock_t
*match_clock
,
761 intel_clock_t
*best_clock
)
763 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
764 struct drm_device
*dev
= crtc
->base
.dev
;
768 /* approximately equals target * 0.00585 */
769 int err_most
= (target
>> 8) + (target
>> 9);
772 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
773 if (intel_is_dual_link_lvds(dev
))
774 clock
.p2
= limit
->p2
.p2_fast
;
776 clock
.p2
= limit
->p2
.p2_slow
;
778 if (target
< limit
->p2
.dot_limit
)
779 clock
.p2
= limit
->p2
.p2_slow
;
781 clock
.p2
= limit
->p2
.p2_fast
;
784 memset(best_clock
, 0, sizeof(*best_clock
));
785 max_n
= limit
->n
.max
;
786 /* based on hardware requirement, prefer smaller n to precision */
787 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
788 /* based on hardware requirement, prefere larger m1,m2 */
789 for (clock
.m1
= limit
->m1
.max
;
790 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
791 for (clock
.m2
= limit
->m2
.max
;
792 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
793 for (clock
.p1
= limit
->p1
.max
;
794 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
797 i9xx_clock(refclk
, &clock
);
798 if (!intel_PLL_is_valid(dev
, limit
,
802 this_err
= abs(clock
.dot
- target
);
803 if (this_err
< err_most
) {
817 * Check if the calculated PLL configuration is more optimal compared to the
818 * best configuration and error found so far. Return the calculated error.
820 static bool vlv_PLL_is_optimal(struct drm_device
*dev
, int target_freq
,
821 const intel_clock_t
*calculated_clock
,
822 const intel_clock_t
*best_clock
,
823 unsigned int best_error_ppm
,
824 unsigned int *error_ppm
)
827 * For CHV ignore the error and consider only the P value.
828 * Prefer a bigger P value based on HW requirements.
830 if (IS_CHERRYVIEW(dev
)) {
833 return calculated_clock
->p
> best_clock
->p
;
836 if (WARN_ON_ONCE(!target_freq
))
839 *error_ppm
= div_u64(1000000ULL *
840 abs(target_freq
- calculated_clock
->dot
),
843 * Prefer a better P value over a better (smaller) error if the error
844 * is small. Ensure this preference for future configurations too by
845 * setting the error to 0.
847 if (*error_ppm
< 100 && calculated_clock
->p
> best_clock
->p
) {
853 return *error_ppm
+ 10 < best_error_ppm
;
857 vlv_find_best_dpll(const intel_limit_t
*limit
,
858 struct intel_crtc_state
*crtc_state
,
859 int target
, int refclk
, intel_clock_t
*match_clock
,
860 intel_clock_t
*best_clock
)
862 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
863 struct drm_device
*dev
= crtc
->base
.dev
;
865 unsigned int bestppm
= 1000000;
866 /* min update 19.2 MHz */
867 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
870 target
*= 5; /* fast clock */
872 memset(best_clock
, 0, sizeof(*best_clock
));
874 /* based on hardware requirement, prefer smaller n to precision */
875 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
876 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
877 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
878 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
879 clock
.p
= clock
.p1
* clock
.p2
;
880 /* based on hardware requirement, prefer bigger m1,m2 values */
881 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
884 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
887 vlv_clock(refclk
, &clock
);
889 if (!intel_PLL_is_valid(dev
, limit
,
893 if (!vlv_PLL_is_optimal(dev
, target
,
911 chv_find_best_dpll(const intel_limit_t
*limit
,
912 struct intel_crtc_state
*crtc_state
,
913 int target
, int refclk
, intel_clock_t
*match_clock
,
914 intel_clock_t
*best_clock
)
916 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->base
.crtc
);
917 struct drm_device
*dev
= crtc
->base
.dev
;
918 unsigned int best_error_ppm
;
923 memset(best_clock
, 0, sizeof(*best_clock
));
924 best_error_ppm
= 1000000;
927 * Based on hardware doc, the n always set to 1, and m1 always
928 * set to 2. If requires to support 200Mhz refclk, we need to
929 * revisit this because n may not 1 anymore.
931 clock
.n
= 1, clock
.m1
= 2;
932 target
*= 5; /* fast clock */
934 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
935 for (clock
.p2
= limit
->p2
.p2_fast
;
936 clock
.p2
>= limit
->p2
.p2_slow
;
937 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
938 unsigned int error_ppm
;
940 clock
.p
= clock
.p1
* clock
.p2
;
942 m2
= DIV_ROUND_CLOSEST_ULL(((uint64_t)target
* clock
.p
*
943 clock
.n
) << 22, refclk
* clock
.m1
);
945 if (m2
> INT_MAX
/clock
.m1
)
950 chv_clock(refclk
, &clock
);
952 if (!intel_PLL_is_valid(dev
, limit
, &clock
))
955 if (!vlv_PLL_is_optimal(dev
, target
, &clock
, best_clock
,
956 best_error_ppm
, &error_ppm
))
960 best_error_ppm
= error_ppm
;
968 bool bxt_find_best_dpll(struct intel_crtc_state
*crtc_state
, int target_clock
,
969 intel_clock_t
*best_clock
)
971 int refclk
= i9xx_get_refclk(crtc_state
, 0);
973 return chv_find_best_dpll(intel_limit(crtc_state
, refclk
), crtc_state
,
974 target_clock
, refclk
, NULL
, best_clock
);
977 bool intel_crtc_active(struct drm_crtc
*crtc
)
979 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
981 /* Be paranoid as we can arrive here with only partial
982 * state retrieved from the hardware during setup.
984 * We can ditch the adjusted_mode.crtc_clock check as soon
985 * as Haswell has gained clock readout/fastboot support.
987 * We can ditch the crtc->primary->fb check as soon as we can
988 * properly reconstruct framebuffers.
990 * FIXME: The intel_crtc->active here should be switched to
991 * crtc->state->active once we have proper CRTC states wired up
994 return intel_crtc
->active
&& crtc
->primary
->state
->fb
&&
995 intel_crtc
->config
->base
.adjusted_mode
.crtc_clock
;
998 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
1001 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1002 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1004 return intel_crtc
->config
->cpu_transcoder
;
1007 static bool pipe_dsl_stopped(struct drm_device
*dev
, enum pipe pipe
)
1009 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1010 u32 reg
= PIPEDSL(pipe
);
1015 line_mask
= DSL_LINEMASK_GEN2
;
1017 line_mask
= DSL_LINEMASK_GEN3
;
1019 line1
= I915_READ(reg
) & line_mask
;
1021 line2
= I915_READ(reg
) & line_mask
;
1023 return line1
== line2
;
1027 * intel_wait_for_pipe_off - wait for pipe to turn off
1028 * @crtc: crtc whose pipe to wait for
1030 * After disabling a pipe, we can't wait for vblank in the usual way,
1031 * spinning on the vblank interrupt status bit, since we won't actually
1032 * see an interrupt when the pipe is disabled.
1034 * On Gen4 and above:
1035 * wait for the pipe register state bit to turn off
1038 * wait for the display line value to settle (it usually
1039 * ends up stopping at the start of the next frame).
1042 static void intel_wait_for_pipe_off(struct intel_crtc
*crtc
)
1044 struct drm_device
*dev
= crtc
->base
.dev
;
1045 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1046 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
1047 enum pipe pipe
= crtc
->pipe
;
1049 if (INTEL_INFO(dev
)->gen
>= 4) {
1050 int reg
= PIPECONF(cpu_transcoder
);
1052 /* Wait for the Pipe State to go off */
1053 if (wait_for((I915_READ(reg
) & I965_PIPECONF_ACTIVE
) == 0,
1055 WARN(1, "pipe_off wait timed out\n");
1057 /* Wait for the display line to settle */
1058 if (wait_for(pipe_dsl_stopped(dev
, pipe
), 100))
1059 WARN(1, "pipe_off wait timed out\n");
1064 * ibx_digital_port_connected - is the specified port connected?
1065 * @dev_priv: i915 private structure
1066 * @port: the port to test
1068 * Returns true if @port is connected, false otherwise.
1070 bool ibx_digital_port_connected(struct drm_i915_private
*dev_priv
,
1071 struct intel_digital_port
*port
)
1075 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1076 switch (port
->port
) {
1078 bit
= SDE_PORTB_HOTPLUG
;
1081 bit
= SDE_PORTC_HOTPLUG
;
1084 bit
= SDE_PORTD_HOTPLUG
;
1090 switch (port
->port
) {
1092 bit
= SDE_PORTB_HOTPLUG_CPT
;
1095 bit
= SDE_PORTC_HOTPLUG_CPT
;
1098 bit
= SDE_PORTD_HOTPLUG_CPT
;
1105 return I915_READ(SDEISR
) & bit
;
1108 static const char *state_string(bool enabled
)
1110 return enabled
? "on" : "off";
1113 /* Only for pre-ILK configs */
1114 void assert_pll(struct drm_i915_private
*dev_priv
,
1115 enum pipe pipe
, bool state
)
1122 val
= I915_READ(reg
);
1123 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1124 I915_STATE_WARN(cur_state
!= state
,
1125 "PLL state assertion failure (expected %s, current %s)\n",
1126 state_string(state
), state_string(cur_state
));
1129 /* XXX: the dsi pll is shared between MIPI DSI ports */
1130 static void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1135 mutex_lock(&dev_priv
->dpio_lock
);
1136 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1137 mutex_unlock(&dev_priv
->dpio_lock
);
1139 cur_state
= val
& DSI_PLL_VCO_EN
;
1140 I915_STATE_WARN(cur_state
!= state
,
1141 "DSI PLL state assertion failure (expected %s, current %s)\n",
1142 state_string(state
), state_string(cur_state
));
1144 #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
1145 #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
1147 struct intel_shared_dpll
*
1148 intel_crtc_to_shared_dpll(struct intel_crtc
*crtc
)
1150 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
1152 if (crtc
->config
->shared_dpll
< 0)
1155 return &dev_priv
->shared_dplls
[crtc
->config
->shared_dpll
];
1159 void assert_shared_dpll(struct drm_i915_private
*dev_priv
,
1160 struct intel_shared_dpll
*pll
,
1164 struct intel_dpll_hw_state hw_state
;
1167 "asserting DPLL %s with no DPLL\n", state_string(state
)))
1170 cur_state
= pll
->get_hw_state(dev_priv
, pll
, &hw_state
);
1171 I915_STATE_WARN(cur_state
!= state
,
1172 "%s assertion failure (expected %s, current %s)\n",
1173 pll
->name
, state_string(state
), state_string(cur_state
));
1176 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1177 enum pipe pipe
, bool state
)
1182 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1185 if (HAS_DDI(dev_priv
->dev
)) {
1186 /* DDI does not have a specific FDI_TX register */
1187 reg
= TRANS_DDI_FUNC_CTL(cpu_transcoder
);
1188 val
= I915_READ(reg
);
1189 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1191 reg
= FDI_TX_CTL(pipe
);
1192 val
= I915_READ(reg
);
1193 cur_state
= !!(val
& FDI_TX_ENABLE
);
1195 I915_STATE_WARN(cur_state
!= state
,
1196 "FDI TX state assertion failure (expected %s, current %s)\n",
1197 state_string(state
), state_string(cur_state
));
1199 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1200 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1202 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1203 enum pipe pipe
, bool state
)
1209 reg
= FDI_RX_CTL(pipe
);
1210 val
= I915_READ(reg
);
1211 cur_state
= !!(val
& FDI_RX_ENABLE
);
1212 I915_STATE_WARN(cur_state
!= state
,
1213 "FDI RX state assertion failure (expected %s, current %s)\n",
1214 state_string(state
), state_string(cur_state
));
1216 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1217 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1219 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1225 /* ILK FDI PLL is always enabled */
1226 if (INTEL_INFO(dev_priv
->dev
)->gen
== 5)
1229 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1230 if (HAS_DDI(dev_priv
->dev
))
1233 reg
= FDI_TX_CTL(pipe
);
1234 val
= I915_READ(reg
);
1235 I915_STATE_WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1238 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1239 enum pipe pipe
, bool state
)
1245 reg
= FDI_RX_CTL(pipe
);
1246 val
= I915_READ(reg
);
1247 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1248 I915_STATE_WARN(cur_state
!= state
,
1249 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1250 state_string(state
), state_string(cur_state
));
1253 void assert_panel_unlocked(struct drm_i915_private
*dev_priv
,
1256 struct drm_device
*dev
= dev_priv
->dev
;
1259 enum pipe panel_pipe
= PIPE_A
;
1262 if (WARN_ON(HAS_DDI(dev
)))
1265 if (HAS_PCH_SPLIT(dev
)) {
1268 pp_reg
= PCH_PP_CONTROL
;
1269 port_sel
= I915_READ(PCH_PP_ON_DELAYS
) & PANEL_PORT_SELECT_MASK
;
1271 if (port_sel
== PANEL_PORT_SELECT_LVDS
&&
1272 I915_READ(PCH_LVDS
) & LVDS_PIPEB_SELECT
)
1273 panel_pipe
= PIPE_B
;
1274 /* XXX: else fix for eDP */
1275 } else if (IS_VALLEYVIEW(dev
)) {
1276 /* presumably write lock depends on pipe, not port select */
1277 pp_reg
= VLV_PIPE_PP_CONTROL(pipe
);
1280 pp_reg
= PP_CONTROL
;
1281 if (I915_READ(LVDS
) & LVDS_PIPEB_SELECT
)
1282 panel_pipe
= PIPE_B
;
1285 val
= I915_READ(pp_reg
);
1286 if (!(val
& PANEL_POWER_ON
) ||
1287 ((val
& PANEL_UNLOCK_MASK
) == PANEL_UNLOCK_REGS
))
1290 I915_STATE_WARN(panel_pipe
== pipe
&& locked
,
1291 "panel assertion failure, pipe %c regs locked\n",
1295 static void assert_cursor(struct drm_i915_private
*dev_priv
,
1296 enum pipe pipe
, bool state
)
1298 struct drm_device
*dev
= dev_priv
->dev
;
1301 if (IS_845G(dev
) || IS_I865G(dev
))
1302 cur_state
= I915_READ(_CURACNTR
) & CURSOR_ENABLE
;
1304 cur_state
= I915_READ(CURCNTR(pipe
)) & CURSOR_MODE
;
1306 I915_STATE_WARN(cur_state
!= state
,
1307 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1308 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1310 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1311 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1313 void assert_pipe(struct drm_i915_private
*dev_priv
,
1314 enum pipe pipe
, bool state
)
1319 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1322 /* if we need the pipe quirk it must be always on */
1323 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1324 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1327 if (!intel_display_power_is_enabled(dev_priv
,
1328 POWER_DOMAIN_TRANSCODER(cpu_transcoder
))) {
1331 reg
= PIPECONF(cpu_transcoder
);
1332 val
= I915_READ(reg
);
1333 cur_state
= !!(val
& PIPECONF_ENABLE
);
1336 I915_STATE_WARN(cur_state
!= state
,
1337 "pipe %c assertion failure (expected %s, current %s)\n",
1338 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1341 static void assert_plane(struct drm_i915_private
*dev_priv
,
1342 enum plane plane
, bool state
)
1348 reg
= DSPCNTR(plane
);
1349 val
= I915_READ(reg
);
1350 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1351 I915_STATE_WARN(cur_state
!= state
,
1352 "plane %c assertion failure (expected %s, current %s)\n",
1353 plane_name(plane
), state_string(state
), state_string(cur_state
));
1356 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1357 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1359 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1362 struct drm_device
*dev
= dev_priv
->dev
;
1367 /* Primary planes are fixed to pipes on gen4+ */
1368 if (INTEL_INFO(dev
)->gen
>= 4) {
1369 reg
= DSPCNTR(pipe
);
1370 val
= I915_READ(reg
);
1371 I915_STATE_WARN(val
& DISPLAY_PLANE_ENABLE
,
1372 "plane %c assertion failure, should be disabled but not\n",
1377 /* Need to check both planes against the pipe */
1378 for_each_pipe(dev_priv
, i
) {
1380 val
= I915_READ(reg
);
1381 cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1382 DISPPLANE_SEL_PIPE_SHIFT
;
1383 I915_STATE_WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1384 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1385 plane_name(i
), pipe_name(pipe
));
1389 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1392 struct drm_device
*dev
= dev_priv
->dev
;
1396 if (INTEL_INFO(dev
)->gen
>= 9) {
1397 for_each_sprite(dev_priv
, pipe
, sprite
) {
1398 val
= I915_READ(PLANE_CTL(pipe
, sprite
));
1399 I915_STATE_WARN(val
& PLANE_CTL_ENABLE
,
1400 "plane %d assertion failure, should be off on pipe %c but is still active\n",
1401 sprite
, pipe_name(pipe
));
1403 } else if (IS_VALLEYVIEW(dev
)) {
1404 for_each_sprite(dev_priv
, pipe
, sprite
) {
1405 reg
= SPCNTR(pipe
, sprite
);
1406 val
= I915_READ(reg
);
1407 I915_STATE_WARN(val
& SP_ENABLE
,
1408 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1409 sprite_name(pipe
, sprite
), pipe_name(pipe
));
1411 } else if (INTEL_INFO(dev
)->gen
>= 7) {
1413 val
= I915_READ(reg
);
1414 I915_STATE_WARN(val
& SPRITE_ENABLE
,
1415 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1416 plane_name(pipe
), pipe_name(pipe
));
1417 } else if (INTEL_INFO(dev
)->gen
>= 5) {
1418 reg
= DVSCNTR(pipe
);
1419 val
= I915_READ(reg
);
1420 I915_STATE_WARN(val
& DVS_ENABLE
,
1421 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1422 plane_name(pipe
), pipe_name(pipe
));
1426 static void assert_vblank_disabled(struct drm_crtc
*crtc
)
1428 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc
) == 0))
1429 drm_crtc_vblank_put(crtc
);
1432 static void ibx_assert_pch_refclk_enabled(struct drm_i915_private
*dev_priv
)
1437 I915_STATE_WARN_ON(!(HAS_PCH_IBX(dev_priv
->dev
) || HAS_PCH_CPT(dev_priv
->dev
)));
1439 val
= I915_READ(PCH_DREF_CONTROL
);
1440 enabled
= !!(val
& (DREF_SSC_SOURCE_MASK
| DREF_NONSPREAD_SOURCE_MASK
|
1441 DREF_SUPERSPREAD_SOURCE_MASK
));
1442 I915_STATE_WARN(!enabled
, "PCH refclk assertion failure, should be active but is disabled\n");
1445 static void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1452 reg
= PCH_TRANSCONF(pipe
);
1453 val
= I915_READ(reg
);
1454 enabled
= !!(val
& TRANS_ENABLE
);
1455 I915_STATE_WARN(enabled
,
1456 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1460 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1461 enum pipe pipe
, u32 port_sel
, u32 val
)
1463 if ((val
& DP_PORT_EN
) == 0)
1466 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1467 u32 trans_dp_ctl_reg
= TRANS_DP_CTL(pipe
);
1468 u32 trans_dp_ctl
= I915_READ(trans_dp_ctl_reg
);
1469 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1471 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1472 if ((val
& DP_PIPE_MASK_CHV
) != DP_PIPE_SELECT_CHV(pipe
))
1475 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1481 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1482 enum pipe pipe
, u32 val
)
1484 if ((val
& SDVO_ENABLE
) == 0)
1487 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1488 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1490 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1491 if ((val
& SDVO_PIPE_SEL_MASK_CHV
) != SDVO_PIPE_SEL_CHV(pipe
))
1494 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1500 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1501 enum pipe pipe
, u32 val
)
1503 if ((val
& LVDS_PORT_EN
) == 0)
1506 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1507 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1510 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1516 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1517 enum pipe pipe
, u32 val
)
1519 if ((val
& ADPA_DAC_ENABLE
) == 0)
1521 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1522 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1525 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1531 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1532 enum pipe pipe
, int reg
, u32 port_sel
)
1534 u32 val
= I915_READ(reg
);
1535 I915_STATE_WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1536 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1537 reg
, pipe_name(pipe
));
1539 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& DP_PORT_EN
) == 0
1540 && (val
& DP_PIPEB_SELECT
),
1541 "IBX PCH dp port still using transcoder B\n");
1544 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1545 enum pipe pipe
, int reg
)
1547 u32 val
= I915_READ(reg
);
1548 I915_STATE_WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1549 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1550 reg
, pipe_name(pipe
));
1552 I915_STATE_WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& SDVO_ENABLE
) == 0
1553 && (val
& SDVO_PIPE_B_SELECT
),
1554 "IBX PCH hdmi port still using transcoder B\n");
1557 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1563 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1564 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1565 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1568 val
= I915_READ(reg
);
1569 I915_STATE_WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1570 "PCH VGA enabled on transcoder %c, should be disabled\n",
1574 val
= I915_READ(reg
);
1575 I915_STATE_WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1576 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1579 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1580 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1581 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1584 static void intel_init_dpio(struct drm_device
*dev
)
1586 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1588 if (!IS_VALLEYVIEW(dev
))
1592 * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
1593 * CHV x1 PHY (DP/HDMI D)
1594 * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
1596 if (IS_CHERRYVIEW(dev
)) {
1597 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO_2
;
1598 DPIO_PHY_IOSF_PORT(DPIO_PHY1
) = IOSF_PORT_DPIO
;
1600 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO
;
1604 static void vlv_enable_pll(struct intel_crtc
*crtc
,
1605 const struct intel_crtc_state
*pipe_config
)
1607 struct drm_device
*dev
= crtc
->base
.dev
;
1608 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1609 int reg
= DPLL(crtc
->pipe
);
1610 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
1612 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1614 /* No really, not for ILK+ */
1615 BUG_ON(!IS_VALLEYVIEW(dev_priv
->dev
));
1617 /* PLL is protected by panel, make sure we can write it */
1618 if (IS_MOBILE(dev_priv
->dev
))
1619 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1621 I915_WRITE(reg
, dpll
);
1625 if (wait_for(((I915_READ(reg
) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1626 DRM_ERROR("DPLL %d failed to lock\n", crtc
->pipe
);
1628 I915_WRITE(DPLL_MD(crtc
->pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1629 POSTING_READ(DPLL_MD(crtc
->pipe
));
1631 /* We do this three times for luck */
1632 I915_WRITE(reg
, dpll
);
1634 udelay(150); /* wait for warmup */
1635 I915_WRITE(reg
, dpll
);
1637 udelay(150); /* wait for warmup */
1638 I915_WRITE(reg
, dpll
);
1640 udelay(150); /* wait for warmup */
1643 static void chv_enable_pll(struct intel_crtc
*crtc
,
1644 const struct intel_crtc_state
*pipe_config
)
1646 struct drm_device
*dev
= crtc
->base
.dev
;
1647 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1648 int pipe
= crtc
->pipe
;
1649 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1652 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1654 BUG_ON(!IS_CHERRYVIEW(dev_priv
->dev
));
1656 mutex_lock(&dev_priv
->dpio_lock
);
1658 /* Enable back the 10bit clock to display controller */
1659 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1660 tmp
|= DPIO_DCLKP_EN
;
1661 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), tmp
);
1664 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1669 I915_WRITE(DPLL(pipe
), pipe_config
->dpll_hw_state
.dpll
);
1671 /* Check PLL is locked */
1672 if (wait_for(((I915_READ(DPLL(pipe
)) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1673 DRM_ERROR("PLL %d failed to lock\n", pipe
);
1675 /* not sure when this should be written */
1676 I915_WRITE(DPLL_MD(pipe
), pipe_config
->dpll_hw_state
.dpll_md
);
1677 POSTING_READ(DPLL_MD(pipe
));
1679 mutex_unlock(&dev_priv
->dpio_lock
);
1682 static int intel_num_dvo_pipes(struct drm_device
*dev
)
1684 struct intel_crtc
*crtc
;
1687 for_each_intel_crtc(dev
, crtc
)
1688 count
+= crtc
->active
&&
1689 intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
);
1694 static void i9xx_enable_pll(struct intel_crtc
*crtc
)
1696 struct drm_device
*dev
= crtc
->base
.dev
;
1697 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1698 int reg
= DPLL(crtc
->pipe
);
1699 u32 dpll
= crtc
->config
->dpll_hw_state
.dpll
;
1701 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1703 /* No really, not for ILK+ */
1704 BUG_ON(INTEL_INFO(dev
)->gen
>= 5);
1706 /* PLL is protected by panel, make sure we can write it */
1707 if (IS_MOBILE(dev
) && !IS_I830(dev
))
1708 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1710 /* Enable DVO 2x clock on both PLLs if necessary */
1711 if (IS_I830(dev
) && intel_num_dvo_pipes(dev
) > 0) {
1713 * It appears to be important that we don't enable this
1714 * for the current pipe before otherwise configuring the
1715 * PLL. No idea how this should be handled if multiple
1716 * DVO outputs are enabled simultaneosly.
1718 dpll
|= DPLL_DVO_2X_MODE
;
1719 I915_WRITE(DPLL(!crtc
->pipe
),
1720 I915_READ(DPLL(!crtc
->pipe
)) | DPLL_DVO_2X_MODE
);
1723 /* Wait for the clocks to stabilize. */
1727 if (INTEL_INFO(dev
)->gen
>= 4) {
1728 I915_WRITE(DPLL_MD(crtc
->pipe
),
1729 crtc
->config
->dpll_hw_state
.dpll_md
);
1731 /* The pixel multiplier can only be updated once the
1732 * DPLL is enabled and the clocks are stable.
1734 * So write it again.
1736 I915_WRITE(reg
, dpll
);
1739 /* We do this three times for luck */
1740 I915_WRITE(reg
, dpll
);
1742 udelay(150); /* wait for warmup */
1743 I915_WRITE(reg
, dpll
);
1745 udelay(150); /* wait for warmup */
1746 I915_WRITE(reg
, dpll
);
1748 udelay(150); /* wait for warmup */
1752 * i9xx_disable_pll - disable a PLL
1753 * @dev_priv: i915 private structure
1754 * @pipe: pipe PLL to disable
1756 * Disable the PLL for @pipe, making sure the pipe is off first.
1758 * Note! This is for pre-ILK only.
1760 static void i9xx_disable_pll(struct intel_crtc
*crtc
)
1762 struct drm_device
*dev
= crtc
->base
.dev
;
1763 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1764 enum pipe pipe
= crtc
->pipe
;
1766 /* Disable DVO 2x clock on both PLLs if necessary */
1768 intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
) &&
1769 intel_num_dvo_pipes(dev
) == 1) {
1770 I915_WRITE(DPLL(PIPE_B
),
1771 I915_READ(DPLL(PIPE_B
)) & ~DPLL_DVO_2X_MODE
);
1772 I915_WRITE(DPLL(PIPE_A
),
1773 I915_READ(DPLL(PIPE_A
)) & ~DPLL_DVO_2X_MODE
);
1776 /* Don't disable pipe or pipe PLLs if needed */
1777 if ((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
1778 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
1781 /* Make sure the pipe isn't still relying on us */
1782 assert_pipe_disabled(dev_priv
, pipe
);
1784 I915_WRITE(DPLL(pipe
), 0);
1785 POSTING_READ(DPLL(pipe
));
1788 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1792 /* Make sure the pipe isn't still relying on us */
1793 assert_pipe_disabled(dev_priv
, pipe
);
1796 * Leave integrated clock source and reference clock enabled for pipe B.
1797 * The latter is needed for VGA hotplug / manual detection.
1800 val
= DPLL_INTEGRATED_CRI_CLK_VLV
| DPLL_REFA_CLK_ENABLE_VLV
;
1801 I915_WRITE(DPLL(pipe
), val
);
1802 POSTING_READ(DPLL(pipe
));
1806 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1808 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1811 /* Make sure the pipe isn't still relying on us */
1812 assert_pipe_disabled(dev_priv
, pipe
);
1814 /* Set PLL en = 0 */
1815 val
= DPLL_SSC_REF_CLOCK_CHV
| DPLL_REFA_CLK_ENABLE_VLV
;
1817 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1818 I915_WRITE(DPLL(pipe
), val
);
1819 POSTING_READ(DPLL(pipe
));
1821 mutex_lock(&dev_priv
->dpio_lock
);
1823 /* Disable 10bit clock to display controller */
1824 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1825 val
&= ~DPIO_DCLKP_EN
;
1826 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1828 /* disable left/right clock distribution */
1829 if (pipe
!= PIPE_B
) {
1830 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
);
1831 val
&= ~(CHV_BUFLEFTENA1_MASK
| CHV_BUFRIGHTENA1_MASK
);
1832 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
, val
);
1834 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
);
1835 val
&= ~(CHV_BUFLEFTENA2_MASK
| CHV_BUFRIGHTENA2_MASK
);
1836 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
, val
);
1839 mutex_unlock(&dev_priv
->dpio_lock
);
1842 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1843 struct intel_digital_port
*dport
,
1844 unsigned int expected_mask
)
1849 switch (dport
->port
) {
1851 port_mask
= DPLL_PORTB_READY_MASK
;
1855 port_mask
= DPLL_PORTC_READY_MASK
;
1857 expected_mask
<<= 4;
1860 port_mask
= DPLL_PORTD_READY_MASK
;
1861 dpll_reg
= DPIO_PHY_STATUS
;
1867 if (wait_for((I915_READ(dpll_reg
) & port_mask
) == expected_mask
, 1000))
1868 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1869 port_name(dport
->port
), I915_READ(dpll_reg
) & port_mask
, expected_mask
);
1872 static void intel_prepare_shared_dpll(struct intel_crtc
*crtc
)
1874 struct drm_device
*dev
= crtc
->base
.dev
;
1875 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1876 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1878 if (WARN_ON(pll
== NULL
))
1881 WARN_ON(!pll
->config
.crtc_mask
);
1882 if (pll
->active
== 0) {
1883 DRM_DEBUG_DRIVER("setting up %s\n", pll
->name
);
1885 assert_shared_dpll_disabled(dev_priv
, pll
);
1887 pll
->mode_set(dev_priv
, pll
);
1892 * intel_enable_shared_dpll - enable PCH PLL
1893 * @dev_priv: i915 private structure
1894 * @pipe: pipe PLL to enable
1896 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1897 * drives the transcoder clock.
1899 static void intel_enable_shared_dpll(struct intel_crtc
*crtc
)
1901 struct drm_device
*dev
= crtc
->base
.dev
;
1902 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1903 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1905 if (WARN_ON(pll
== NULL
))
1908 if (WARN_ON(pll
->config
.crtc_mask
== 0))
1911 DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n",
1912 pll
->name
, pll
->active
, pll
->on
,
1913 crtc
->base
.base
.id
);
1915 if (pll
->active
++) {
1917 assert_shared_dpll_enabled(dev_priv
, pll
);
1922 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
1924 DRM_DEBUG_KMS("enabling %s\n", pll
->name
);
1925 pll
->enable(dev_priv
, pll
);
1929 static void intel_disable_shared_dpll(struct intel_crtc
*crtc
)
1931 struct drm_device
*dev
= crtc
->base
.dev
;
1932 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1933 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1935 /* PCH only available on ILK+ */
1936 BUG_ON(INTEL_INFO(dev
)->gen
< 5);
1937 if (WARN_ON(pll
== NULL
))
1940 if (WARN_ON(pll
->config
.crtc_mask
== 0))
1943 DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
1944 pll
->name
, pll
->active
, pll
->on
,
1945 crtc
->base
.base
.id
);
1947 if (WARN_ON(pll
->active
== 0)) {
1948 assert_shared_dpll_disabled(dev_priv
, pll
);
1952 assert_shared_dpll_enabled(dev_priv
, pll
);
1957 DRM_DEBUG_KMS("disabling %s\n", pll
->name
);
1958 pll
->disable(dev_priv
, pll
);
1961 intel_display_power_put(dev_priv
, POWER_DOMAIN_PLLS
);
1964 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1967 struct drm_device
*dev
= dev_priv
->dev
;
1968 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1969 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1970 uint32_t reg
, val
, pipeconf_val
;
1972 /* PCH only available on ILK+ */
1973 BUG_ON(!HAS_PCH_SPLIT(dev
));
1975 /* Make sure PCH DPLL is enabled */
1976 assert_shared_dpll_enabled(dev_priv
,
1977 intel_crtc_to_shared_dpll(intel_crtc
));
1979 /* FDI must be feeding us bits for PCH ports */
1980 assert_fdi_tx_enabled(dev_priv
, pipe
);
1981 assert_fdi_rx_enabled(dev_priv
, pipe
);
1983 if (HAS_PCH_CPT(dev
)) {
1984 /* Workaround: Set the timing override bit before enabling the
1985 * pch transcoder. */
1986 reg
= TRANS_CHICKEN2(pipe
);
1987 val
= I915_READ(reg
);
1988 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1989 I915_WRITE(reg
, val
);
1992 reg
= PCH_TRANSCONF(pipe
);
1993 val
= I915_READ(reg
);
1994 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1996 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1998 * make the BPC in transcoder be consistent with
1999 * that in pipeconf reg.
2001 val
&= ~PIPECONF_BPC_MASK
;
2002 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
2005 val
&= ~TRANS_INTERLACE_MASK
;
2006 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
2007 if (HAS_PCH_IBX(dev_priv
->dev
) &&
2008 intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
2009 val
|= TRANS_LEGACY_INTERLACED_ILK
;
2011 val
|= TRANS_INTERLACED
;
2013 val
|= TRANS_PROGRESSIVE
;
2015 I915_WRITE(reg
, val
| TRANS_ENABLE
);
2016 if (wait_for(I915_READ(reg
) & TRANS_STATE_ENABLE
, 100))
2017 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
2020 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
2021 enum transcoder cpu_transcoder
)
2023 u32 val
, pipeconf_val
;
2025 /* PCH only available on ILK+ */
2026 BUG_ON(!HAS_PCH_SPLIT(dev_priv
->dev
));
2028 /* FDI must be feeding us bits for PCH ports */
2029 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
2030 assert_fdi_rx_enabled(dev_priv
, TRANSCODER_A
);
2032 /* Workaround: set timing override bit. */
2033 val
= I915_READ(_TRANSA_CHICKEN2
);
2034 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
2035 I915_WRITE(_TRANSA_CHICKEN2
, val
);
2038 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
2040 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
2041 PIPECONF_INTERLACED_ILK
)
2042 val
|= TRANS_INTERLACED
;
2044 val
|= TRANS_PROGRESSIVE
;
2046 I915_WRITE(LPT_TRANSCONF
, val
);
2047 if (wait_for(I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
, 100))
2048 DRM_ERROR("Failed to enable PCH transcoder\n");
2051 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
2054 struct drm_device
*dev
= dev_priv
->dev
;
2057 /* FDI relies on the transcoder */
2058 assert_fdi_tx_disabled(dev_priv
, pipe
);
2059 assert_fdi_rx_disabled(dev_priv
, pipe
);
2061 /* Ports must be off as well */
2062 assert_pch_ports_disabled(dev_priv
, pipe
);
2064 reg
= PCH_TRANSCONF(pipe
);
2065 val
= I915_READ(reg
);
2066 val
&= ~TRANS_ENABLE
;
2067 I915_WRITE(reg
, val
);
2068 /* wait for PCH transcoder off, transcoder state */
2069 if (wait_for((I915_READ(reg
) & TRANS_STATE_ENABLE
) == 0, 50))
2070 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
2072 if (!HAS_PCH_IBX(dev
)) {
2073 /* Workaround: Clear the timing override chicken bit again. */
2074 reg
= TRANS_CHICKEN2(pipe
);
2075 val
= I915_READ(reg
);
2076 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
2077 I915_WRITE(reg
, val
);
2081 static void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
2085 val
= I915_READ(LPT_TRANSCONF
);
2086 val
&= ~TRANS_ENABLE
;
2087 I915_WRITE(LPT_TRANSCONF
, val
);
2088 /* wait for PCH transcoder off, transcoder state */
2089 if (wait_for((I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
) == 0, 50))
2090 DRM_ERROR("Failed to disable PCH transcoder\n");
2092 /* Workaround: clear timing override bit. */
2093 val
= I915_READ(_TRANSA_CHICKEN2
);
2094 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
2095 I915_WRITE(_TRANSA_CHICKEN2
, val
);
2099 * intel_enable_pipe - enable a pipe, asserting requirements
2100 * @crtc: crtc responsible for the pipe
2102 * Enable @crtc's pipe, making sure that various hardware specific requirements
2103 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
2105 static void intel_enable_pipe(struct intel_crtc
*crtc
)
2107 struct drm_device
*dev
= crtc
->base
.dev
;
2108 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2109 enum pipe pipe
= crtc
->pipe
;
2110 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
2112 enum pipe pch_transcoder
;
2116 assert_planes_disabled(dev_priv
, pipe
);
2117 assert_cursor_disabled(dev_priv
, pipe
);
2118 assert_sprites_disabled(dev_priv
, pipe
);
2120 if (HAS_PCH_LPT(dev_priv
->dev
))
2121 pch_transcoder
= TRANSCODER_A
;
2123 pch_transcoder
= pipe
;
2126 * A pipe without a PLL won't actually be able to drive bits from
2127 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
2130 if (HAS_GMCH_DISPLAY(dev_priv
->dev
))
2131 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
))
2132 assert_dsi_pll_enabled(dev_priv
);
2134 assert_pll_enabled(dev_priv
, pipe
);
2136 if (crtc
->config
->has_pch_encoder
) {
2137 /* if driving the PCH, we need FDI enabled */
2138 assert_fdi_rx_pll_enabled(dev_priv
, pch_transcoder
);
2139 assert_fdi_tx_pll_enabled(dev_priv
,
2140 (enum pipe
) cpu_transcoder
);
2142 /* FIXME: assert CPU port conditions for SNB+ */
2145 reg
= PIPECONF(cpu_transcoder
);
2146 val
= I915_READ(reg
);
2147 if (val
& PIPECONF_ENABLE
) {
2148 WARN_ON(!((pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
2149 (pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
)));
2153 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
2158 * intel_disable_pipe - disable a pipe, asserting requirements
2159 * @crtc: crtc whose pipes is to be disabled
2161 * Disable the pipe of @crtc, making sure that various hardware
2162 * specific requirements are met, if applicable, e.g. plane
2163 * disabled, panel fitter off, etc.
2165 * Will wait until the pipe has shut down before returning.
2167 static void intel_disable_pipe(struct intel_crtc
*crtc
)
2169 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
2170 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
2171 enum pipe pipe
= crtc
->pipe
;
2176 * Make sure planes won't keep trying to pump pixels to us,
2177 * or we might hang the display.
2179 assert_planes_disabled(dev_priv
, pipe
);
2180 assert_cursor_disabled(dev_priv
, pipe
);
2181 assert_sprites_disabled(dev_priv
, pipe
);
2183 reg
= PIPECONF(cpu_transcoder
);
2184 val
= I915_READ(reg
);
2185 if ((val
& PIPECONF_ENABLE
) == 0)
2189 * Double wide has implications for planes
2190 * so best keep it disabled when not needed.
2192 if (crtc
->config
->double_wide
)
2193 val
&= ~PIPECONF_DOUBLE_WIDE
;
2195 /* Don't disable pipe or pipe PLLs if needed */
2196 if (!(pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) &&
2197 !(pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
2198 val
&= ~PIPECONF_ENABLE
;
2200 I915_WRITE(reg
, val
);
2201 if ((val
& PIPECONF_ENABLE
) == 0)
2202 intel_wait_for_pipe_off(crtc
);
2206 * Plane regs are double buffered, going from enabled->disabled needs a
2207 * trigger in order to latch. The display address reg provides this.
2209 void intel_flush_primary_plane(struct drm_i915_private
*dev_priv
,
2212 struct drm_device
*dev
= dev_priv
->dev
;
2213 u32 reg
= INTEL_INFO(dev
)->gen
>= 4 ? DSPSURF(plane
) : DSPADDR(plane
);
2215 I915_WRITE(reg
, I915_READ(reg
));
2220 * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
2221 * @plane: plane to be enabled
2222 * @crtc: crtc for the plane
2224 * Enable @plane on @crtc, making sure that the pipe is running first.
2226 static void intel_enable_primary_hw_plane(struct drm_plane
*plane
,
2227 struct drm_crtc
*crtc
)
2229 struct drm_device
*dev
= plane
->dev
;
2230 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2231 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2233 /* If the pipe isn't enabled, we can't pump pixels and may hang */
2234 assert_pipe_enabled(dev_priv
, intel_crtc
->pipe
);
2235 to_intel_plane_state(plane
->state
)->visible
= true;
2237 dev_priv
->display
.update_primary_plane(crtc
, plane
->fb
,
2241 static bool need_vtd_wa(struct drm_device
*dev
)
2243 #ifdef CONFIG_INTEL_IOMMU
2244 if (INTEL_INFO(dev
)->gen
>= 6 && intel_iommu_gfx_mapped
)
2251 intel_tile_height(struct drm_device
*dev
, uint32_t pixel_format
,
2252 uint64_t fb_format_modifier
)
2254 unsigned int tile_height
;
2255 uint32_t pixel_bytes
;
2257 switch (fb_format_modifier
) {
2258 case DRM_FORMAT_MOD_NONE
:
2261 case I915_FORMAT_MOD_X_TILED
:
2262 tile_height
= IS_GEN2(dev
) ? 16 : 8;
2264 case I915_FORMAT_MOD_Y_TILED
:
2267 case I915_FORMAT_MOD_Yf_TILED
:
2268 pixel_bytes
= drm_format_plane_cpp(pixel_format
, 0);
2269 switch (pixel_bytes
) {
2283 "128-bit pixels are not supported for display!");
2289 MISSING_CASE(fb_format_modifier
);
2298 intel_fb_align_height(struct drm_device
*dev
, unsigned int height
,
2299 uint32_t pixel_format
, uint64_t fb_format_modifier
)
2301 return ALIGN(height
, intel_tile_height(dev
, pixel_format
,
2302 fb_format_modifier
));
2306 intel_fill_fb_ggtt_view(struct i915_ggtt_view
*view
, struct drm_framebuffer
*fb
,
2307 const struct drm_plane_state
*plane_state
)
2309 struct intel_rotation_info
*info
= &view
->rotation_info
;
2311 *view
= i915_ggtt_view_normal
;
2316 if (!intel_rotation_90_or_270(plane_state
->rotation
))
2319 *view
= i915_ggtt_view_rotated
;
2321 info
->height
= fb
->height
;
2322 info
->pixel_format
= fb
->pixel_format
;
2323 info
->pitch
= fb
->pitches
[0];
2324 info
->fb_modifier
= fb
->modifier
[0];
2330 intel_pin_and_fence_fb_obj(struct drm_plane
*plane
,
2331 struct drm_framebuffer
*fb
,
2332 const struct drm_plane_state
*plane_state
,
2333 struct intel_engine_cs
*pipelined
)
2335 struct drm_device
*dev
= fb
->dev
;
2336 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2337 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2338 struct i915_ggtt_view view
;
2342 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
2344 switch (fb
->modifier
[0]) {
2345 case DRM_FORMAT_MOD_NONE
:
2346 if (INTEL_INFO(dev
)->gen
>= 9)
2347 alignment
= 256 * 1024;
2348 else if (IS_BROADWATER(dev
) || IS_CRESTLINE(dev
))
2349 alignment
= 128 * 1024;
2350 else if (INTEL_INFO(dev
)->gen
>= 4)
2351 alignment
= 4 * 1024;
2353 alignment
= 64 * 1024;
2355 case I915_FORMAT_MOD_X_TILED
:
2356 if (INTEL_INFO(dev
)->gen
>= 9)
2357 alignment
= 256 * 1024;
2359 /* pin() will align the object as required by fence */
2363 case I915_FORMAT_MOD_Y_TILED
:
2364 case I915_FORMAT_MOD_Yf_TILED
:
2365 if (WARN_ONCE(INTEL_INFO(dev
)->gen
< 9,
2366 "Y tiling bo slipped through, driver bug!\n"))
2368 alignment
= 1 * 1024 * 1024;
2371 MISSING_CASE(fb
->modifier
[0]);
2375 ret
= intel_fill_fb_ggtt_view(&view
, fb
, plane_state
);
2379 /* Note that the w/a also requires 64 PTE of padding following the
2380 * bo. We currently fill all unused PTE with the shadow page and so
2381 * we should always have valid PTE following the scanout preventing
2384 if (need_vtd_wa(dev
) && alignment
< 256 * 1024)
2385 alignment
= 256 * 1024;
2388 * Global gtt pte registers are special registers which actually forward
2389 * writes to a chunk of system memory. Which means that there is no risk
2390 * that the register values disappear as soon as we call
2391 * intel_runtime_pm_put(), so it is correct to wrap only the
2392 * pin/unpin/fence and not more.
2394 intel_runtime_pm_get(dev_priv
);
2396 dev_priv
->mm
.interruptible
= false;
2397 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, pipelined
,
2400 goto err_interruptible
;
2402 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2403 * fence, whereas 965+ only requires a fence if using
2404 * framebuffer compression. For simplicity, we always install
2405 * a fence as the cost is not that onerous.
2407 ret
= i915_gem_object_get_fence(obj
);
2411 i915_gem_object_pin_fence(obj
);
2413 dev_priv
->mm
.interruptible
= true;
2414 intel_runtime_pm_put(dev_priv
);
2418 i915_gem_object_unpin_from_display_plane(obj
, &view
);
2420 dev_priv
->mm
.interruptible
= true;
2421 intel_runtime_pm_put(dev_priv
);
2425 static void intel_unpin_fb_obj(struct drm_framebuffer
*fb
,
2426 const struct drm_plane_state
*plane_state
)
2428 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2429 struct i915_ggtt_view view
;
2432 WARN_ON(!mutex_is_locked(&obj
->base
.dev
->struct_mutex
));
2434 ret
= intel_fill_fb_ggtt_view(&view
, fb
, plane_state
);
2435 WARN_ONCE(ret
, "Couldn't get view from plane state!");
2437 i915_gem_object_unpin_fence(obj
);
2438 i915_gem_object_unpin_from_display_plane(obj
, &view
);
2441 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
2442 * is assumed to be a power-of-two. */
2443 unsigned long intel_gen4_compute_page_offset(int *x
, int *y
,
2444 unsigned int tiling_mode
,
2448 if (tiling_mode
!= I915_TILING_NONE
) {
2449 unsigned int tile_rows
, tiles
;
2454 tiles
= *x
/ (512/cpp
);
2457 return tile_rows
* pitch
* 8 + tiles
* 4096;
2459 unsigned int offset
;
2461 offset
= *y
* pitch
+ *x
* cpp
;
2463 *x
= (offset
& 4095) / cpp
;
2464 return offset
& -4096;
2468 static int i9xx_format_to_fourcc(int format
)
2471 case DISPPLANE_8BPP
:
2472 return DRM_FORMAT_C8
;
2473 case DISPPLANE_BGRX555
:
2474 return DRM_FORMAT_XRGB1555
;
2475 case DISPPLANE_BGRX565
:
2476 return DRM_FORMAT_RGB565
;
2478 case DISPPLANE_BGRX888
:
2479 return DRM_FORMAT_XRGB8888
;
2480 case DISPPLANE_RGBX888
:
2481 return DRM_FORMAT_XBGR8888
;
2482 case DISPPLANE_BGRX101010
:
2483 return DRM_FORMAT_XRGB2101010
;
2484 case DISPPLANE_RGBX101010
:
2485 return DRM_FORMAT_XBGR2101010
;
2489 static int skl_format_to_fourcc(int format
, bool rgb_order
, bool alpha
)
2492 case PLANE_CTL_FORMAT_RGB_565
:
2493 return DRM_FORMAT_RGB565
;
2495 case PLANE_CTL_FORMAT_XRGB_8888
:
2498 return DRM_FORMAT_ABGR8888
;
2500 return DRM_FORMAT_XBGR8888
;
2503 return DRM_FORMAT_ARGB8888
;
2505 return DRM_FORMAT_XRGB8888
;
2507 case PLANE_CTL_FORMAT_XRGB_2101010
:
2509 return DRM_FORMAT_XBGR2101010
;
2511 return DRM_FORMAT_XRGB2101010
;
2516 intel_alloc_initial_plane_obj(struct intel_crtc
*crtc
,
2517 struct intel_initial_plane_config
*plane_config
)
2519 struct drm_device
*dev
= crtc
->base
.dev
;
2520 struct drm_i915_gem_object
*obj
= NULL
;
2521 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2522 struct drm_framebuffer
*fb
= &plane_config
->fb
->base
;
2523 u32 base_aligned
= round_down(plane_config
->base
, PAGE_SIZE
);
2524 u32 size_aligned
= round_up(plane_config
->base
+ plane_config
->size
,
2527 size_aligned
-= base_aligned
;
2529 if (plane_config
->size
== 0)
2532 obj
= i915_gem_object_create_stolen_for_preallocated(dev
,
2539 obj
->tiling_mode
= plane_config
->tiling
;
2540 if (obj
->tiling_mode
== I915_TILING_X
)
2541 obj
->stride
= fb
->pitches
[0];
2543 mode_cmd
.pixel_format
= fb
->pixel_format
;
2544 mode_cmd
.width
= fb
->width
;
2545 mode_cmd
.height
= fb
->height
;
2546 mode_cmd
.pitches
[0] = fb
->pitches
[0];
2547 mode_cmd
.modifier
[0] = fb
->modifier
[0];
2548 mode_cmd
.flags
= DRM_MODE_FB_MODIFIERS
;
2550 mutex_lock(&dev
->struct_mutex
);
2551 if (intel_framebuffer_init(dev
, to_intel_framebuffer(fb
),
2553 DRM_DEBUG_KMS("intel fb init failed\n");
2556 mutex_unlock(&dev
->struct_mutex
);
2558 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj
);
2562 drm_gem_object_unreference(&obj
->base
);
2563 mutex_unlock(&dev
->struct_mutex
);
2567 /* Update plane->state->fb to match plane->fb after driver-internal updates */
2569 update_state_fb(struct drm_plane
*plane
)
2571 if (plane
->fb
== plane
->state
->fb
)
2574 if (plane
->state
->fb
)
2575 drm_framebuffer_unreference(plane
->state
->fb
);
2576 plane
->state
->fb
= plane
->fb
;
2577 if (plane
->state
->fb
)
2578 drm_framebuffer_reference(plane
->state
->fb
);
2582 intel_find_initial_plane_obj(struct intel_crtc
*intel_crtc
,
2583 struct intel_initial_plane_config
*plane_config
)
2585 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2586 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2588 struct intel_crtc
*i
;
2589 struct drm_i915_gem_object
*obj
;
2590 struct drm_plane
*primary
= intel_crtc
->base
.primary
;
2591 struct drm_framebuffer
*fb
;
2593 if (!plane_config
->fb
)
2596 if (intel_alloc_initial_plane_obj(intel_crtc
, plane_config
)) {
2597 fb
= &plane_config
->fb
->base
;
2601 kfree(plane_config
->fb
);
2604 * Failed to alloc the obj, check to see if we should share
2605 * an fb with another CRTC instead
2607 for_each_crtc(dev
, c
) {
2608 i
= to_intel_crtc(c
);
2610 if (c
== &intel_crtc
->base
)
2616 fb
= c
->primary
->fb
;
2620 obj
= intel_fb_obj(fb
);
2621 if (i915_gem_obj_ggtt_offset(obj
) == plane_config
->base
) {
2622 drm_framebuffer_reference(fb
);
2630 obj
= intel_fb_obj(fb
);
2631 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2632 dev_priv
->preserve_bios_swizzle
= true;
2635 primary
->state
->crtc
= &intel_crtc
->base
;
2636 primary
->crtc
= &intel_crtc
->base
;
2637 update_state_fb(primary
);
2638 obj
->frontbuffer_bits
|= INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
);
2641 static void i9xx_update_primary_plane(struct drm_crtc
*crtc
,
2642 struct drm_framebuffer
*fb
,
2645 struct drm_device
*dev
= crtc
->dev
;
2646 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2647 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2648 struct drm_plane
*primary
= crtc
->primary
;
2649 bool visible
= to_intel_plane_state(primary
->state
)->visible
;
2650 struct drm_i915_gem_object
*obj
;
2651 int plane
= intel_crtc
->plane
;
2652 unsigned long linear_offset
;
2654 u32 reg
= DSPCNTR(plane
);
2657 if (!visible
|| !fb
) {
2659 if (INTEL_INFO(dev
)->gen
>= 4)
2660 I915_WRITE(DSPSURF(plane
), 0);
2662 I915_WRITE(DSPADDR(plane
), 0);
2667 obj
= intel_fb_obj(fb
);
2668 if (WARN_ON(obj
== NULL
))
2671 pixel_size
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2673 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2675 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2677 if (INTEL_INFO(dev
)->gen
< 4) {
2678 if (intel_crtc
->pipe
== PIPE_B
)
2679 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
2681 /* pipesrc and dspsize control the size that is scaled from,
2682 * which should always be the user's requested size.
2684 I915_WRITE(DSPSIZE(plane
),
2685 ((intel_crtc
->config
->pipe_src_h
- 1) << 16) |
2686 (intel_crtc
->config
->pipe_src_w
- 1));
2687 I915_WRITE(DSPPOS(plane
), 0);
2688 } else if (IS_CHERRYVIEW(dev
) && plane
== PLANE_B
) {
2689 I915_WRITE(PRIMSIZE(plane
),
2690 ((intel_crtc
->config
->pipe_src_h
- 1) << 16) |
2691 (intel_crtc
->config
->pipe_src_w
- 1));
2692 I915_WRITE(PRIMPOS(plane
), 0);
2693 I915_WRITE(PRIMCNSTALPHA(plane
), 0);
2696 switch (fb
->pixel_format
) {
2698 dspcntr
|= DISPPLANE_8BPP
;
2700 case DRM_FORMAT_XRGB1555
:
2701 dspcntr
|= DISPPLANE_BGRX555
;
2703 case DRM_FORMAT_RGB565
:
2704 dspcntr
|= DISPPLANE_BGRX565
;
2706 case DRM_FORMAT_XRGB8888
:
2707 case DRM_FORMAT_ARGB8888
:
2708 dspcntr
|= DISPPLANE_BGRX888
;
2710 case DRM_FORMAT_XBGR8888
:
2711 case DRM_FORMAT_ABGR8888
:
2712 dspcntr
|= DISPPLANE_RGBX888
;
2714 case DRM_FORMAT_XRGB2101010
:
2715 dspcntr
|= DISPPLANE_BGRX101010
;
2717 case DRM_FORMAT_XBGR2101010
:
2718 dspcntr
|= DISPPLANE_RGBX101010
;
2724 if (INTEL_INFO(dev
)->gen
>= 4 &&
2725 obj
->tiling_mode
!= I915_TILING_NONE
)
2726 dspcntr
|= DISPPLANE_TILED
;
2729 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2731 linear_offset
= y
* fb
->pitches
[0] + x
* pixel_size
;
2733 if (INTEL_INFO(dev
)->gen
>= 4) {
2734 intel_crtc
->dspaddr_offset
=
2735 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2738 linear_offset
-= intel_crtc
->dspaddr_offset
;
2740 intel_crtc
->dspaddr_offset
= linear_offset
;
2743 if (crtc
->primary
->state
->rotation
== BIT(DRM_ROTATE_180
)) {
2744 dspcntr
|= DISPPLANE_ROTATE_180
;
2746 x
+= (intel_crtc
->config
->pipe_src_w
- 1);
2747 y
+= (intel_crtc
->config
->pipe_src_h
- 1);
2749 /* Finding the last pixel of the last line of the display
2750 data and adding to linear_offset*/
2752 (intel_crtc
->config
->pipe_src_h
- 1) * fb
->pitches
[0] +
2753 (intel_crtc
->config
->pipe_src_w
- 1) * pixel_size
;
2756 I915_WRITE(reg
, dspcntr
);
2758 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2759 if (INTEL_INFO(dev
)->gen
>= 4) {
2760 I915_WRITE(DSPSURF(plane
),
2761 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2762 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2763 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2765 I915_WRITE(DSPADDR(plane
), i915_gem_obj_ggtt_offset(obj
) + linear_offset
);
2769 static void ironlake_update_primary_plane(struct drm_crtc
*crtc
,
2770 struct drm_framebuffer
*fb
,
2773 struct drm_device
*dev
= crtc
->dev
;
2774 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2775 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2776 struct drm_plane
*primary
= crtc
->primary
;
2777 bool visible
= to_intel_plane_state(primary
->state
)->visible
;
2778 struct drm_i915_gem_object
*obj
;
2779 int plane
= intel_crtc
->plane
;
2780 unsigned long linear_offset
;
2782 u32 reg
= DSPCNTR(plane
);
2785 if (!visible
|| !fb
) {
2787 I915_WRITE(DSPSURF(plane
), 0);
2792 obj
= intel_fb_obj(fb
);
2793 if (WARN_ON(obj
== NULL
))
2796 pixel_size
= drm_format_plane_cpp(fb
->pixel_format
, 0);
2798 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2800 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2802 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2803 dspcntr
|= DISPPLANE_PIPE_CSC_ENABLE
;
2805 switch (fb
->pixel_format
) {
2807 dspcntr
|= DISPPLANE_8BPP
;
2809 case DRM_FORMAT_RGB565
:
2810 dspcntr
|= DISPPLANE_BGRX565
;
2812 case DRM_FORMAT_XRGB8888
:
2813 case DRM_FORMAT_ARGB8888
:
2814 dspcntr
|= DISPPLANE_BGRX888
;
2816 case DRM_FORMAT_XBGR8888
:
2817 case DRM_FORMAT_ABGR8888
:
2818 dspcntr
|= DISPPLANE_RGBX888
;
2820 case DRM_FORMAT_XRGB2101010
:
2821 dspcntr
|= DISPPLANE_BGRX101010
;
2823 case DRM_FORMAT_XBGR2101010
:
2824 dspcntr
|= DISPPLANE_RGBX101010
;
2830 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2831 dspcntr
|= DISPPLANE_TILED
;
2833 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
))
2834 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2836 linear_offset
= y
* fb
->pitches
[0] + x
* pixel_size
;
2837 intel_crtc
->dspaddr_offset
=
2838 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2841 linear_offset
-= intel_crtc
->dspaddr_offset
;
2842 if (crtc
->primary
->state
->rotation
== BIT(DRM_ROTATE_180
)) {
2843 dspcntr
|= DISPPLANE_ROTATE_180
;
2845 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
)) {
2846 x
+= (intel_crtc
->config
->pipe_src_w
- 1);
2847 y
+= (intel_crtc
->config
->pipe_src_h
- 1);
2849 /* Finding the last pixel of the last line of the display
2850 data and adding to linear_offset*/
2852 (intel_crtc
->config
->pipe_src_h
- 1) * fb
->pitches
[0] +
2853 (intel_crtc
->config
->pipe_src_w
- 1) * pixel_size
;
2857 I915_WRITE(reg
, dspcntr
);
2859 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2860 I915_WRITE(DSPSURF(plane
),
2861 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2862 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2863 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
2865 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2866 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2871 u32
intel_fb_stride_alignment(struct drm_device
*dev
, uint64_t fb_modifier
,
2872 uint32_t pixel_format
)
2874 u32 bits_per_pixel
= drm_format_plane_cpp(pixel_format
, 0) * 8;
2877 * The stride is either expressed as a multiple of 64 bytes
2878 * chunks for linear buffers or in number of tiles for tiled
2881 switch (fb_modifier
) {
2882 case DRM_FORMAT_MOD_NONE
:
2884 case I915_FORMAT_MOD_X_TILED
:
2885 if (INTEL_INFO(dev
)->gen
== 2)
2888 case I915_FORMAT_MOD_Y_TILED
:
2889 /* No need to check for old gens and Y tiling since this is
2890 * about the display engine and those will be blocked before
2894 case I915_FORMAT_MOD_Yf_TILED
:
2895 if (bits_per_pixel
== 8)
2900 MISSING_CASE(fb_modifier
);
2905 unsigned long intel_plane_obj_offset(struct intel_plane
*intel_plane
,
2906 struct drm_i915_gem_object
*obj
)
2908 const struct i915_ggtt_view
*view
= &i915_ggtt_view_normal
;
2910 if (intel_rotation_90_or_270(intel_plane
->base
.state
->rotation
))
2911 view
= &i915_ggtt_view_rotated
;
2913 return i915_gem_obj_ggtt_offset_view(obj
, view
);
2917 * This function detaches (aka. unbinds) unused scalers in hardware
2919 void skl_detach_scalers(struct intel_crtc
*intel_crtc
)
2921 struct drm_device
*dev
;
2922 struct drm_i915_private
*dev_priv
;
2923 struct intel_crtc_scaler_state
*scaler_state
;
2926 if (!intel_crtc
|| !intel_crtc
->config
)
2929 dev
= intel_crtc
->base
.dev
;
2930 dev_priv
= dev
->dev_private
;
2931 scaler_state
= &intel_crtc
->config
->scaler_state
;
2933 /* loop through and disable scalers that aren't in use */
2934 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
2935 if (!scaler_state
->scalers
[i
].in_use
) {
2936 I915_WRITE(SKL_PS_CTRL(intel_crtc
->pipe
, i
), 0);
2937 I915_WRITE(SKL_PS_WIN_POS(intel_crtc
->pipe
, i
), 0);
2938 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc
->pipe
, i
), 0);
2939 DRM_DEBUG_KMS("CRTC:%d Disabled scaler id %u.%u\n",
2940 intel_crtc
->base
.base
.id
, intel_crtc
->pipe
, i
);
2945 u32
skl_plane_ctl_format(uint32_t pixel_format
)
2947 switch (pixel_format
) {
2949 return PLANE_CTL_FORMAT_INDEXED
;
2950 case DRM_FORMAT_RGB565
:
2951 return PLANE_CTL_FORMAT_RGB_565
;
2952 case DRM_FORMAT_XBGR8888
:
2953 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
;
2954 case DRM_FORMAT_XRGB8888
:
2955 return PLANE_CTL_FORMAT_XRGB_8888
;
2957 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
2958 * to be already pre-multiplied. We need to add a knob (or a different
2959 * DRM_FORMAT) for user-space to configure that.
2961 case DRM_FORMAT_ABGR8888
:
2962 return PLANE_CTL_FORMAT_XRGB_8888
| PLANE_CTL_ORDER_RGBX
|
2963 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
2964 case DRM_FORMAT_ARGB8888
:
2965 return PLANE_CTL_FORMAT_XRGB_8888
|
2966 PLANE_CTL_ALPHA_SW_PREMULTIPLY
;
2967 case DRM_FORMAT_XRGB2101010
:
2968 return PLANE_CTL_FORMAT_XRGB_2101010
;
2969 case DRM_FORMAT_XBGR2101010
:
2970 return PLANE_CTL_ORDER_RGBX
| PLANE_CTL_FORMAT_XRGB_2101010
;
2971 case DRM_FORMAT_YUYV
:
2972 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YUYV
;
2973 case DRM_FORMAT_YVYU
:
2974 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_YVYU
;
2975 case DRM_FORMAT_UYVY
:
2976 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_UYVY
;
2977 case DRM_FORMAT_VYUY
:
2978 return PLANE_CTL_FORMAT_YUV422
| PLANE_CTL_YUV422_VYUY
;
2980 MISSING_CASE(pixel_format
);
2986 u32
skl_plane_ctl_tiling(uint64_t fb_modifier
)
2988 switch (fb_modifier
) {
2989 case DRM_FORMAT_MOD_NONE
:
2991 case I915_FORMAT_MOD_X_TILED
:
2992 return PLANE_CTL_TILED_X
;
2993 case I915_FORMAT_MOD_Y_TILED
:
2994 return PLANE_CTL_TILED_Y
;
2995 case I915_FORMAT_MOD_Yf_TILED
:
2996 return PLANE_CTL_TILED_YF
;
2998 MISSING_CASE(fb_modifier
);
3004 u32
skl_plane_ctl_rotation(unsigned int rotation
)
3007 case BIT(DRM_ROTATE_0
):
3009 case BIT(DRM_ROTATE_90
):
3010 return PLANE_CTL_ROTATE_90
;
3011 case BIT(DRM_ROTATE_180
):
3012 return PLANE_CTL_ROTATE_180
;
3013 case BIT(DRM_ROTATE_270
):
3014 return PLANE_CTL_ROTATE_270
;
3016 MISSING_CASE(rotation
);
3022 static void skylake_update_primary_plane(struct drm_crtc
*crtc
,
3023 struct drm_framebuffer
*fb
,
3026 struct drm_device
*dev
= crtc
->dev
;
3027 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3028 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3029 struct drm_plane
*plane
= crtc
->primary
;
3030 bool visible
= to_intel_plane_state(plane
->state
)->visible
;
3031 struct drm_i915_gem_object
*obj
;
3032 int pipe
= intel_crtc
->pipe
;
3033 u32 plane_ctl
, stride_div
, stride
;
3034 u32 tile_height
, plane_offset
, plane_size
;
3035 unsigned int rotation
;
3036 int x_offset
, y_offset
;
3037 unsigned long surf_addr
;
3038 struct intel_crtc_state
*crtc_state
= intel_crtc
->config
;
3039 struct intel_plane_state
*plane_state
;
3040 int src_x
= 0, src_y
= 0, src_w
= 0, src_h
= 0;
3041 int dst_x
= 0, dst_y
= 0, dst_w
= 0, dst_h
= 0;
3044 plane_state
= to_intel_plane_state(plane
->state
);
3046 if (!visible
|| !fb
) {
3047 I915_WRITE(PLANE_CTL(pipe
, 0), 0);
3048 I915_WRITE(PLANE_SURF(pipe
, 0), 0);
3049 POSTING_READ(PLANE_CTL(pipe
, 0));
3053 plane_ctl
= PLANE_CTL_ENABLE
|
3054 PLANE_CTL_PIPE_GAMMA_ENABLE
|
3055 PLANE_CTL_PIPE_CSC_ENABLE
;
3057 plane_ctl
|= skl_plane_ctl_format(fb
->pixel_format
);
3058 plane_ctl
|= skl_plane_ctl_tiling(fb
->modifier
[0]);
3059 plane_ctl
|= PLANE_CTL_PLANE_GAMMA_DISABLE
;
3061 rotation
= plane
->state
->rotation
;
3062 plane_ctl
|= skl_plane_ctl_rotation(rotation
);
3064 obj
= intel_fb_obj(fb
);
3065 stride_div
= intel_fb_stride_alignment(dev
, fb
->modifier
[0],
3067 surf_addr
= intel_plane_obj_offset(to_intel_plane(plane
), obj
);
3070 * FIXME: intel_plane_state->src, dst aren't set when transitional
3071 * update_plane helpers are called from legacy paths.
3072 * Once full atomic crtc is available, below check can be avoided.
3074 if (drm_rect_width(&plane_state
->src
)) {
3075 scaler_id
= plane_state
->scaler_id
;
3076 src_x
= plane_state
->src
.x1
>> 16;
3077 src_y
= plane_state
->src
.y1
>> 16;
3078 src_w
= drm_rect_width(&plane_state
->src
) >> 16;
3079 src_h
= drm_rect_height(&plane_state
->src
) >> 16;
3080 dst_x
= plane_state
->dst
.x1
;
3081 dst_y
= plane_state
->dst
.y1
;
3082 dst_w
= drm_rect_width(&plane_state
->dst
);
3083 dst_h
= drm_rect_height(&plane_state
->dst
);
3085 WARN_ON(x
!= src_x
|| y
!= src_y
);
3087 src_w
= intel_crtc
->config
->pipe_src_w
;
3088 src_h
= intel_crtc
->config
->pipe_src_h
;
3091 if (intel_rotation_90_or_270(rotation
)) {
3092 /* stride = Surface height in tiles */
3093 tile_height
= intel_tile_height(dev
, fb
->pixel_format
,
3095 stride
= DIV_ROUND_UP(fb
->height
, tile_height
);
3096 x_offset
= stride
* tile_height
- y
- src_h
;
3098 plane_size
= (src_w
- 1) << 16 | (src_h
- 1);
3100 stride
= fb
->pitches
[0] / stride_div
;
3103 plane_size
= (src_h
- 1) << 16 | (src_w
- 1);
3105 plane_offset
= y_offset
<< 16 | x_offset
;
3107 I915_WRITE(PLANE_CTL(pipe
, 0), plane_ctl
);
3108 I915_WRITE(PLANE_OFFSET(pipe
, 0), plane_offset
);
3109 I915_WRITE(PLANE_SIZE(pipe
, 0), plane_size
);
3110 I915_WRITE(PLANE_STRIDE(pipe
, 0), stride
);
3112 if (scaler_id
>= 0) {
3113 uint32_t ps_ctrl
= 0;
3115 WARN_ON(!dst_w
|| !dst_h
);
3116 ps_ctrl
= PS_SCALER_EN
| PS_PLANE_SEL(0) |
3117 crtc_state
->scaler_state
.scalers
[scaler_id
].mode
;
3118 I915_WRITE(SKL_PS_CTRL(pipe
, scaler_id
), ps_ctrl
);
3119 I915_WRITE(SKL_PS_PWR_GATE(pipe
, scaler_id
), 0);
3120 I915_WRITE(SKL_PS_WIN_POS(pipe
, scaler_id
), (dst_x
<< 16) | dst_y
);
3121 I915_WRITE(SKL_PS_WIN_SZ(pipe
, scaler_id
), (dst_w
<< 16) | dst_h
);
3122 I915_WRITE(PLANE_POS(pipe
, 0), 0);
3124 I915_WRITE(PLANE_POS(pipe
, 0), (dst_y
<< 16) | dst_x
);
3127 I915_WRITE(PLANE_SURF(pipe
, 0), surf_addr
);
3129 POSTING_READ(PLANE_SURF(pipe
, 0));
3132 /* Assume fb object is pinned & idle & fenced and just update base pointers */
3134 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
3135 int x
, int y
, enum mode_set_atomic state
)
3137 struct drm_device
*dev
= crtc
->dev
;
3138 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3140 if (dev_priv
->display
.disable_fbc
)
3141 dev_priv
->display
.disable_fbc(dev
);
3143 dev_priv
->display
.update_primary_plane(crtc
, fb
, x
, y
);
3148 static void intel_complete_page_flips(struct drm_device
*dev
)
3150 struct drm_crtc
*crtc
;
3152 for_each_crtc(dev
, crtc
) {
3153 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3154 enum plane plane
= intel_crtc
->plane
;
3156 intel_prepare_page_flip(dev
, plane
);
3157 intel_finish_page_flip_plane(dev
, plane
);
3161 static void intel_update_primary_planes(struct drm_device
*dev
)
3163 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3164 struct drm_crtc
*crtc
;
3166 for_each_crtc(dev
, crtc
) {
3167 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3169 drm_modeset_lock(&crtc
->mutex
, NULL
);
3171 * FIXME: Once we have proper support for primary planes (and
3172 * disabling them without disabling the entire crtc) allow again
3173 * a NULL crtc->primary->fb.
3175 if (intel_crtc
->active
&& crtc
->primary
->fb
)
3176 dev_priv
->display
.update_primary_plane(crtc
,
3180 drm_modeset_unlock(&crtc
->mutex
);
3184 void intel_crtc_reset(struct intel_crtc
*crtc
)
3186 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
3191 intel_crtc_disable_planes(&crtc
->base
);
3192 dev_priv
->display
.crtc_disable(&crtc
->base
);
3193 dev_priv
->display
.crtc_enable(&crtc
->base
);
3194 intel_crtc_enable_planes(&crtc
->base
);
3197 void intel_prepare_reset(struct drm_device
*dev
)
3199 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3200 struct intel_crtc
*crtc
;
3202 /* no reset support for gen2 */
3206 /* reset doesn't touch the display */
3207 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
3210 drm_modeset_lock_all(dev
);
3213 * Disabling the crtcs gracefully seems nicer. Also the
3214 * g33 docs say we should at least disable all the planes.
3216 for_each_intel_crtc(dev
, crtc
) {
3220 intel_crtc_disable_planes(&crtc
->base
);
3221 dev_priv
->display
.crtc_disable(&crtc
->base
);
3225 void intel_finish_reset(struct drm_device
*dev
)
3227 struct drm_i915_private
*dev_priv
= to_i915(dev
);
3230 * Flips in the rings will be nuked by the reset,
3231 * so complete all pending flips so that user space
3232 * will get its events and not get stuck.
3234 intel_complete_page_flips(dev
);
3236 /* no reset support for gen2 */
3240 /* reset doesn't touch the display */
3241 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
)) {
3243 * Flips in the rings have been nuked by the reset,
3244 * so update the base address of all primary
3245 * planes to the the last fb to make sure we're
3246 * showing the correct fb after a reset.
3248 intel_update_primary_planes(dev
);
3253 * The display has been reset as well,
3254 * so need a full re-initialization.
3256 intel_runtime_pm_disable_interrupts(dev_priv
);
3257 intel_runtime_pm_enable_interrupts(dev_priv
);
3259 intel_modeset_init_hw(dev
);
3261 spin_lock_irq(&dev_priv
->irq_lock
);
3262 if (dev_priv
->display
.hpd_irq_setup
)
3263 dev_priv
->display
.hpd_irq_setup(dev
);
3264 spin_unlock_irq(&dev_priv
->irq_lock
);
3266 intel_modeset_setup_hw_state(dev
, true);
3268 intel_hpd_init(dev_priv
);
3270 drm_modeset_unlock_all(dev
);
3274 intel_finish_fb(struct drm_framebuffer
*old_fb
)
3276 struct drm_i915_gem_object
*obj
= intel_fb_obj(old_fb
);
3277 struct drm_i915_private
*dev_priv
= to_i915(obj
->base
.dev
);
3278 bool was_interruptible
= dev_priv
->mm
.interruptible
;
3281 /* Big Hammer, we also need to ensure that any pending
3282 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
3283 * current scanout is retired before unpinning the old
3284 * framebuffer. Note that we rely on userspace rendering
3285 * into the buffer attached to the pipe they are waiting
3286 * on. If not, userspace generates a GPU hang with IPEHR
3287 * point to the MI_WAIT_FOR_EVENT.
3289 * This should only fail upon a hung GPU, in which case we
3290 * can safely continue.
3292 dev_priv
->mm
.interruptible
= false;
3293 ret
= i915_gem_object_wait_rendering(obj
, true);
3294 dev_priv
->mm
.interruptible
= was_interruptible
;
3299 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
3301 struct drm_device
*dev
= crtc
->dev
;
3302 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3303 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3306 if (i915_reset_in_progress(&dev_priv
->gpu_error
) ||
3307 intel_crtc
->reset_counter
!= atomic_read(&dev_priv
->gpu_error
.reset_counter
))
3310 spin_lock_irq(&dev
->event_lock
);
3311 pending
= to_intel_crtc(crtc
)->unpin_work
!= NULL
;
3312 spin_unlock_irq(&dev
->event_lock
);
3317 static void intel_update_pipe_size(struct intel_crtc
*crtc
)
3319 struct drm_device
*dev
= crtc
->base
.dev
;
3320 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3321 const struct drm_display_mode
*adjusted_mode
;
3327 * Update pipe size and adjust fitter if needed: the reason for this is
3328 * that in compute_mode_changes we check the native mode (not the pfit
3329 * mode) to see if we can flip rather than do a full mode set. In the
3330 * fastboot case, we'll flip, but if we don't update the pipesrc and
3331 * pfit state, we'll end up with a big fb scanned out into the wrong
3334 * To fix this properly, we need to hoist the checks up into
3335 * compute_mode_changes (or above), check the actual pfit state and
3336 * whether the platform allows pfit disable with pipe active, and only
3337 * then update the pipesrc and pfit state, even on the flip path.
3340 adjusted_mode
= &crtc
->config
->base
.adjusted_mode
;
3342 I915_WRITE(PIPESRC(crtc
->pipe
),
3343 ((adjusted_mode
->crtc_hdisplay
- 1) << 16) |
3344 (adjusted_mode
->crtc_vdisplay
- 1));
3345 if (!crtc
->config
->pch_pfit
.enabled
&&
3346 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) ||
3347 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
3348 I915_WRITE(PF_CTL(crtc
->pipe
), 0);
3349 I915_WRITE(PF_WIN_POS(crtc
->pipe
), 0);
3350 I915_WRITE(PF_WIN_SZ(crtc
->pipe
), 0);
3352 crtc
->config
->pipe_src_w
= adjusted_mode
->crtc_hdisplay
;
3353 crtc
->config
->pipe_src_h
= adjusted_mode
->crtc_vdisplay
;
3356 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
3358 struct drm_device
*dev
= crtc
->dev
;
3359 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3360 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3361 int pipe
= intel_crtc
->pipe
;
3364 /* enable normal train */
3365 reg
= FDI_TX_CTL(pipe
);
3366 temp
= I915_READ(reg
);
3367 if (IS_IVYBRIDGE(dev
)) {
3368 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3369 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3371 temp
&= ~FDI_LINK_TRAIN_NONE
;
3372 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
3374 I915_WRITE(reg
, temp
);
3376 reg
= FDI_RX_CTL(pipe
);
3377 temp
= I915_READ(reg
);
3378 if (HAS_PCH_CPT(dev
)) {
3379 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3380 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
3382 temp
&= ~FDI_LINK_TRAIN_NONE
;
3383 temp
|= FDI_LINK_TRAIN_NONE
;
3385 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
3387 /* wait one idle pattern time */
3391 /* IVB wants error correction enabled */
3392 if (IS_IVYBRIDGE(dev
))
3393 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
3394 FDI_FE_ERRC_ENABLE
);
3397 /* The FDI link training functions for ILK/Ibexpeak. */
3398 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
3400 struct drm_device
*dev
= crtc
->dev
;
3401 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3402 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3403 int pipe
= intel_crtc
->pipe
;
3404 u32 reg
, temp
, tries
;
3406 /* FDI needs bits from pipe first */
3407 assert_pipe_enabled(dev_priv
, pipe
);
3409 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3411 reg
= FDI_RX_IMR(pipe
);
3412 temp
= I915_READ(reg
);
3413 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3414 temp
&= ~FDI_RX_BIT_LOCK
;
3415 I915_WRITE(reg
, temp
);
3419 /* enable CPU FDI TX and PCH FDI RX */
3420 reg
= FDI_TX_CTL(pipe
);
3421 temp
= I915_READ(reg
);
3422 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3423 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3424 temp
&= ~FDI_LINK_TRAIN_NONE
;
3425 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3426 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3428 reg
= FDI_RX_CTL(pipe
);
3429 temp
= I915_READ(reg
);
3430 temp
&= ~FDI_LINK_TRAIN_NONE
;
3431 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3432 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3437 /* Ironlake workaround, enable clock pointer after FDI enable*/
3438 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3439 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
3440 FDI_RX_PHASE_SYNC_POINTER_EN
);
3442 reg
= FDI_RX_IIR(pipe
);
3443 for (tries
= 0; tries
< 5; tries
++) {
3444 temp
= I915_READ(reg
);
3445 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3447 if ((temp
& FDI_RX_BIT_LOCK
)) {
3448 DRM_DEBUG_KMS("FDI train 1 done.\n");
3449 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3454 DRM_ERROR("FDI train 1 fail!\n");
3457 reg
= FDI_TX_CTL(pipe
);
3458 temp
= I915_READ(reg
);
3459 temp
&= ~FDI_LINK_TRAIN_NONE
;
3460 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3461 I915_WRITE(reg
, temp
);
3463 reg
= FDI_RX_CTL(pipe
);
3464 temp
= I915_READ(reg
);
3465 temp
&= ~FDI_LINK_TRAIN_NONE
;
3466 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3467 I915_WRITE(reg
, temp
);
3472 reg
= FDI_RX_IIR(pipe
);
3473 for (tries
= 0; tries
< 5; tries
++) {
3474 temp
= I915_READ(reg
);
3475 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3477 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3478 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3479 DRM_DEBUG_KMS("FDI train 2 done.\n");
3484 DRM_ERROR("FDI train 2 fail!\n");
3486 DRM_DEBUG_KMS("FDI train done\n");
3490 static const int snb_b_fdi_train_param
[] = {
3491 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
3492 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
3493 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
3494 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
3497 /* The FDI link training functions for SNB/Cougarpoint. */
3498 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
3500 struct drm_device
*dev
= crtc
->dev
;
3501 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3502 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3503 int pipe
= intel_crtc
->pipe
;
3504 u32 reg
, temp
, i
, retry
;
3506 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3508 reg
= FDI_RX_IMR(pipe
);
3509 temp
= I915_READ(reg
);
3510 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3511 temp
&= ~FDI_RX_BIT_LOCK
;
3512 I915_WRITE(reg
, temp
);
3517 /* enable CPU FDI TX and PCH FDI RX */
3518 reg
= FDI_TX_CTL(pipe
);
3519 temp
= I915_READ(reg
);
3520 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3521 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3522 temp
&= ~FDI_LINK_TRAIN_NONE
;
3523 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3524 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3526 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3527 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3529 I915_WRITE(FDI_RX_MISC(pipe
),
3530 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3532 reg
= FDI_RX_CTL(pipe
);
3533 temp
= I915_READ(reg
);
3534 if (HAS_PCH_CPT(dev
)) {
3535 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3536 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3538 temp
&= ~FDI_LINK_TRAIN_NONE
;
3539 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3541 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3546 for (i
= 0; i
< 4; i
++) {
3547 reg
= FDI_TX_CTL(pipe
);
3548 temp
= I915_READ(reg
);
3549 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3550 temp
|= snb_b_fdi_train_param
[i
];
3551 I915_WRITE(reg
, temp
);
3556 for (retry
= 0; retry
< 5; retry
++) {
3557 reg
= FDI_RX_IIR(pipe
);
3558 temp
= I915_READ(reg
);
3559 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3560 if (temp
& FDI_RX_BIT_LOCK
) {
3561 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3562 DRM_DEBUG_KMS("FDI train 1 done.\n");
3571 DRM_ERROR("FDI train 1 fail!\n");
3574 reg
= FDI_TX_CTL(pipe
);
3575 temp
= I915_READ(reg
);
3576 temp
&= ~FDI_LINK_TRAIN_NONE
;
3577 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3579 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3581 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3583 I915_WRITE(reg
, temp
);
3585 reg
= FDI_RX_CTL(pipe
);
3586 temp
= I915_READ(reg
);
3587 if (HAS_PCH_CPT(dev
)) {
3588 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3589 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3591 temp
&= ~FDI_LINK_TRAIN_NONE
;
3592 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3594 I915_WRITE(reg
, temp
);
3599 for (i
= 0; i
< 4; i
++) {
3600 reg
= FDI_TX_CTL(pipe
);
3601 temp
= I915_READ(reg
);
3602 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3603 temp
|= snb_b_fdi_train_param
[i
];
3604 I915_WRITE(reg
, temp
);
3609 for (retry
= 0; retry
< 5; retry
++) {
3610 reg
= FDI_RX_IIR(pipe
);
3611 temp
= I915_READ(reg
);
3612 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3613 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3614 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3615 DRM_DEBUG_KMS("FDI train 2 done.\n");
3624 DRM_ERROR("FDI train 2 fail!\n");
3626 DRM_DEBUG_KMS("FDI train done.\n");
3629 /* Manual link training for Ivy Bridge A0 parts */
3630 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
3632 struct drm_device
*dev
= crtc
->dev
;
3633 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3634 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3635 int pipe
= intel_crtc
->pipe
;
3636 u32 reg
, temp
, i
, j
;
3638 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3640 reg
= FDI_RX_IMR(pipe
);
3641 temp
= I915_READ(reg
);
3642 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3643 temp
&= ~FDI_RX_BIT_LOCK
;
3644 I915_WRITE(reg
, temp
);
3649 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3650 I915_READ(FDI_RX_IIR(pipe
)));
3652 /* Try each vswing and preemphasis setting twice before moving on */
3653 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
3654 /* disable first in case we need to retry */
3655 reg
= FDI_TX_CTL(pipe
);
3656 temp
= I915_READ(reg
);
3657 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
3658 temp
&= ~FDI_TX_ENABLE
;
3659 I915_WRITE(reg
, temp
);
3661 reg
= FDI_RX_CTL(pipe
);
3662 temp
= I915_READ(reg
);
3663 temp
&= ~FDI_LINK_TRAIN_AUTO
;
3664 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3665 temp
&= ~FDI_RX_ENABLE
;
3666 I915_WRITE(reg
, temp
);
3668 /* enable CPU FDI TX and PCH FDI RX */
3669 reg
= FDI_TX_CTL(pipe
);
3670 temp
= I915_READ(reg
);
3671 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3672 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3673 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
3674 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3675 temp
|= snb_b_fdi_train_param
[j
/2];
3676 temp
|= FDI_COMPOSITE_SYNC
;
3677 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3679 I915_WRITE(FDI_RX_MISC(pipe
),
3680 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3682 reg
= FDI_RX_CTL(pipe
);
3683 temp
= I915_READ(reg
);
3684 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3685 temp
|= FDI_COMPOSITE_SYNC
;
3686 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3689 udelay(1); /* should be 0.5us */
3691 for (i
= 0; i
< 4; i
++) {
3692 reg
= FDI_RX_IIR(pipe
);
3693 temp
= I915_READ(reg
);
3694 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3696 if (temp
& FDI_RX_BIT_LOCK
||
3697 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
3698 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3699 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3703 udelay(1); /* should be 0.5us */
3706 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
3711 reg
= FDI_TX_CTL(pipe
);
3712 temp
= I915_READ(reg
);
3713 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3714 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
3715 I915_WRITE(reg
, temp
);
3717 reg
= FDI_RX_CTL(pipe
);
3718 temp
= I915_READ(reg
);
3719 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3720 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3721 I915_WRITE(reg
, temp
);
3724 udelay(2); /* should be 1.5us */
3726 for (i
= 0; i
< 4; i
++) {
3727 reg
= FDI_RX_IIR(pipe
);
3728 temp
= I915_READ(reg
);
3729 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3731 if (temp
& FDI_RX_SYMBOL_LOCK
||
3732 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
3733 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3734 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
3738 udelay(2); /* should be 1.5us */
3741 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
3745 DRM_DEBUG_KMS("FDI train done.\n");
3748 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
3750 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3751 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3752 int pipe
= intel_crtc
->pipe
;
3756 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
3757 reg
= FDI_RX_CTL(pipe
);
3758 temp
= I915_READ(reg
);
3759 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
3760 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
->fdi_lanes
);
3761 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3762 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
3767 /* Switch from Rawclk to PCDclk */
3768 temp
= I915_READ(reg
);
3769 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
3774 /* Enable CPU FDI TX PLL, always on for Ironlake */
3775 reg
= FDI_TX_CTL(pipe
);
3776 temp
= I915_READ(reg
);
3777 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
3778 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
3785 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
3787 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3788 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3789 int pipe
= intel_crtc
->pipe
;
3792 /* Switch from PCDclk to Rawclk */
3793 reg
= FDI_RX_CTL(pipe
);
3794 temp
= I915_READ(reg
);
3795 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
3797 /* Disable CPU FDI TX PLL */
3798 reg
= FDI_TX_CTL(pipe
);
3799 temp
= I915_READ(reg
);
3800 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
3805 reg
= FDI_RX_CTL(pipe
);
3806 temp
= I915_READ(reg
);
3807 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
3809 /* Wait for the clocks to turn off. */
3814 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
3816 struct drm_device
*dev
= crtc
->dev
;
3817 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3818 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3819 int pipe
= intel_crtc
->pipe
;
3822 /* disable CPU FDI tx and PCH FDI rx */
3823 reg
= FDI_TX_CTL(pipe
);
3824 temp
= I915_READ(reg
);
3825 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
3828 reg
= FDI_RX_CTL(pipe
);
3829 temp
= I915_READ(reg
);
3830 temp
&= ~(0x7 << 16);
3831 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3832 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
3837 /* Ironlake workaround, disable clock pointer after downing FDI */
3838 if (HAS_PCH_IBX(dev
))
3839 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3841 /* still set train pattern 1 */
3842 reg
= FDI_TX_CTL(pipe
);
3843 temp
= I915_READ(reg
);
3844 temp
&= ~FDI_LINK_TRAIN_NONE
;
3845 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3846 I915_WRITE(reg
, temp
);
3848 reg
= FDI_RX_CTL(pipe
);
3849 temp
= I915_READ(reg
);
3850 if (HAS_PCH_CPT(dev
)) {
3851 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3852 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3854 temp
&= ~FDI_LINK_TRAIN_NONE
;
3855 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3857 /* BPC in FDI rx is consistent with that in PIPECONF */
3858 temp
&= ~(0x07 << 16);
3859 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3860 I915_WRITE(reg
, temp
);
3866 bool intel_has_pending_fb_unpin(struct drm_device
*dev
)
3868 struct intel_crtc
*crtc
;
3870 /* Note that we don't need to be called with mode_config.lock here
3871 * as our list of CRTC objects is static for the lifetime of the
3872 * device and so cannot disappear as we iterate. Similarly, we can
3873 * happily treat the predicates as racy, atomic checks as userspace
3874 * cannot claim and pin a new fb without at least acquring the
3875 * struct_mutex and so serialising with us.
3877 for_each_intel_crtc(dev
, crtc
) {
3878 if (atomic_read(&crtc
->unpin_work_count
) == 0)
3881 if (crtc
->unpin_work
)
3882 intel_wait_for_vblank(dev
, crtc
->pipe
);
3890 static void page_flip_completed(struct intel_crtc
*intel_crtc
)
3892 struct drm_i915_private
*dev_priv
= to_i915(intel_crtc
->base
.dev
);
3893 struct intel_unpin_work
*work
= intel_crtc
->unpin_work
;
3895 /* ensure that the unpin work is consistent wrt ->pending. */
3897 intel_crtc
->unpin_work
= NULL
;
3900 drm_send_vblank_event(intel_crtc
->base
.dev
,
3904 drm_crtc_vblank_put(&intel_crtc
->base
);
3906 wake_up_all(&dev_priv
->pending_flip_queue
);
3907 queue_work(dev_priv
->wq
, &work
->work
);
3909 trace_i915_flip_complete(intel_crtc
->plane
,
3910 work
->pending_flip_obj
);
3913 void intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
3915 struct drm_device
*dev
= crtc
->dev
;
3916 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3918 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
3919 if (WARN_ON(wait_event_timeout(dev_priv
->pending_flip_queue
,
3920 !intel_crtc_has_pending_flip(crtc
),
3922 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3924 spin_lock_irq(&dev
->event_lock
);
3925 if (intel_crtc
->unpin_work
) {
3926 WARN_ONCE(1, "Removing stuck page flip\n");
3927 page_flip_completed(intel_crtc
);
3929 spin_unlock_irq(&dev
->event_lock
);
3932 if (crtc
->primary
->fb
) {
3933 mutex_lock(&dev
->struct_mutex
);
3934 intel_finish_fb(crtc
->primary
->fb
);
3935 mutex_unlock(&dev
->struct_mutex
);
3939 /* Program iCLKIP clock to the desired frequency */
3940 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
3942 struct drm_device
*dev
= crtc
->dev
;
3943 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3944 int clock
= to_intel_crtc(crtc
)->config
->base
.adjusted_mode
.crtc_clock
;
3945 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
3948 mutex_lock(&dev_priv
->dpio_lock
);
3950 /* It is necessary to ungate the pixclk gate prior to programming
3951 * the divisors, and gate it back when it is done.
3953 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
3955 /* Disable SSCCTL */
3956 intel_sbi_write(dev_priv
, SBI_SSCCTL6
,
3957 intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
) |
3961 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
3962 if (clock
== 20000) {
3967 /* The iCLK virtual clock root frequency is in MHz,
3968 * but the adjusted_mode->crtc_clock in in KHz. To get the
3969 * divisors, it is necessary to divide one by another, so we
3970 * convert the virtual clock precision to KHz here for higher
3973 u32 iclk_virtual_root_freq
= 172800 * 1000;
3974 u32 iclk_pi_range
= 64;
3975 u32 desired_divisor
, msb_divisor_value
, pi_value
;
3977 desired_divisor
= (iclk_virtual_root_freq
/ clock
);
3978 msb_divisor_value
= desired_divisor
/ iclk_pi_range
;
3979 pi_value
= desired_divisor
% iclk_pi_range
;
3982 divsel
= msb_divisor_value
- 2;
3983 phaseinc
= pi_value
;
3986 /* This should not happen with any sane values */
3987 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
3988 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
3989 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
3990 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
3992 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3999 /* Program SSCDIVINTPHASE6 */
4000 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
4001 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
4002 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
4003 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
4004 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
4005 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
4006 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
4007 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
4009 /* Program SSCAUXDIV */
4010 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
4011 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4012 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
4013 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
4015 /* Enable modulator and associated divider */
4016 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
4017 temp
&= ~SBI_SSCCTL_DISABLE
;
4018 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
4020 /* Wait for initialization time */
4023 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
4025 mutex_unlock(&dev_priv
->dpio_lock
);
4028 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
4029 enum pipe pch_transcoder
)
4031 struct drm_device
*dev
= crtc
->base
.dev
;
4032 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4033 enum transcoder cpu_transcoder
= crtc
->config
->cpu_transcoder
;
4035 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
4036 I915_READ(HTOTAL(cpu_transcoder
)));
4037 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
4038 I915_READ(HBLANK(cpu_transcoder
)));
4039 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
4040 I915_READ(HSYNC(cpu_transcoder
)));
4042 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
4043 I915_READ(VTOTAL(cpu_transcoder
)));
4044 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
4045 I915_READ(VBLANK(cpu_transcoder
)));
4046 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
4047 I915_READ(VSYNC(cpu_transcoder
)));
4048 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
4049 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
4052 static void cpt_set_fdi_bc_bifurcation(struct drm_device
*dev
, bool enable
)
4054 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4057 temp
= I915_READ(SOUTH_CHICKEN1
);
4058 if (!!(temp
& FDI_BC_BIFURCATION_SELECT
) == enable
)
4061 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
4062 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
4064 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
4066 temp
|= FDI_BC_BIFURCATION_SELECT
;
4068 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable
? "en" : "dis");
4069 I915_WRITE(SOUTH_CHICKEN1
, temp
);
4070 POSTING_READ(SOUTH_CHICKEN1
);
4073 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
4075 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4077 switch (intel_crtc
->pipe
) {
4081 if (intel_crtc
->config
->fdi_lanes
> 2)
4082 cpt_set_fdi_bc_bifurcation(dev
, false);
4084 cpt_set_fdi_bc_bifurcation(dev
, true);
4088 cpt_set_fdi_bc_bifurcation(dev
, true);
4097 * Enable PCH resources required for PCH ports:
4099 * - FDI training & RX/TX
4100 * - update transcoder timings
4101 * - DP transcoding bits
4104 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
4106 struct drm_device
*dev
= crtc
->dev
;
4107 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4108 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4109 int pipe
= intel_crtc
->pipe
;
4112 assert_pch_transcoder_disabled(dev_priv
, pipe
);
4114 if (IS_IVYBRIDGE(dev
))
4115 ivybridge_update_fdi_bc_bifurcation(intel_crtc
);
4117 /* Write the TU size bits before fdi link training, so that error
4118 * detection works. */
4119 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
4120 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
4122 /* For PCH output, training FDI link */
4123 dev_priv
->display
.fdi_link_train(crtc
);
4125 /* We need to program the right clock selection before writing the pixel
4126 * mutliplier into the DPLL. */
4127 if (HAS_PCH_CPT(dev
)) {
4130 temp
= I915_READ(PCH_DPLL_SEL
);
4131 temp
|= TRANS_DPLL_ENABLE(pipe
);
4132 sel
= TRANS_DPLLB_SEL(pipe
);
4133 if (intel_crtc
->config
->shared_dpll
== DPLL_ID_PCH_PLL_B
)
4137 I915_WRITE(PCH_DPLL_SEL
, temp
);
4140 /* XXX: pch pll's can be enabled any time before we enable the PCH
4141 * transcoder, and we actually should do this to not upset any PCH
4142 * transcoder that already use the clock when we share it.
4144 * Note that enable_shared_dpll tries to do the right thing, but
4145 * get_shared_dpll unconditionally resets the pll - we need that to have
4146 * the right LVDS enable sequence. */
4147 intel_enable_shared_dpll(intel_crtc
);
4149 /* set transcoder timing, panel must allow it */
4150 assert_panel_unlocked(dev_priv
, pipe
);
4151 ironlake_pch_transcoder_set_timings(intel_crtc
, pipe
);
4153 intel_fdi_normal_train(crtc
);
4155 /* For PCH DP, enable TRANS_DP_CTL */
4156 if (HAS_PCH_CPT(dev
) && intel_crtc
->config
->has_dp_encoder
) {
4157 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
4158 reg
= TRANS_DP_CTL(pipe
);
4159 temp
= I915_READ(reg
);
4160 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
4161 TRANS_DP_SYNC_MASK
|
4163 temp
|= (TRANS_DP_OUTPUT_ENABLE
|
4164 TRANS_DP_ENH_FRAMING
);
4165 temp
|= bpc
<< 9; /* same format but at 11:9 */
4167 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PHSYNC
)
4168 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
4169 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PVSYNC
)
4170 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
4172 switch (intel_trans_dp_port_sel(crtc
)) {
4174 temp
|= TRANS_DP_PORT_SEL_B
;
4177 temp
|= TRANS_DP_PORT_SEL_C
;
4180 temp
|= TRANS_DP_PORT_SEL_D
;
4186 I915_WRITE(reg
, temp
);
4189 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
4192 static void lpt_pch_enable(struct drm_crtc
*crtc
)
4194 struct drm_device
*dev
= crtc
->dev
;
4195 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4196 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4197 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
4199 assert_pch_transcoder_disabled(dev_priv
, TRANSCODER_A
);
4201 lpt_program_iclkip(crtc
);
4203 /* Set transcoder timing. */
4204 ironlake_pch_transcoder_set_timings(intel_crtc
, PIPE_A
);
4206 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
4209 void intel_put_shared_dpll(struct intel_crtc
*crtc
)
4211 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
4216 if (!(pll
->config
.crtc_mask
& (1 << crtc
->pipe
))) {
4217 WARN(1, "bad %s crtc mask\n", pll
->name
);
4221 pll
->config
.crtc_mask
&= ~(1 << crtc
->pipe
);
4222 if (pll
->config
.crtc_mask
== 0) {
4224 WARN_ON(pll
->active
);
4227 crtc
->config
->shared_dpll
= DPLL_ID_PRIVATE
;
4230 struct intel_shared_dpll
*intel_get_shared_dpll(struct intel_crtc
*crtc
,
4231 struct intel_crtc_state
*crtc_state
)
4233 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
4234 struct intel_shared_dpll
*pll
;
4235 enum intel_dpll_id i
;
4237 if (HAS_PCH_IBX(dev_priv
->dev
)) {
4238 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
4239 i
= (enum intel_dpll_id
) crtc
->pipe
;
4240 pll
= &dev_priv
->shared_dplls
[i
];
4242 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
4243 crtc
->base
.base
.id
, pll
->name
);
4245 WARN_ON(pll
->new_config
->crtc_mask
);
4250 if (IS_BROXTON(dev_priv
->dev
)) {
4251 /* PLL is attached to port in bxt */
4252 struct intel_encoder
*encoder
;
4253 struct intel_digital_port
*intel_dig_port
;
4255 encoder
= intel_ddi_get_crtc_new_encoder(crtc_state
);
4256 if (WARN_ON(!encoder
))
4259 intel_dig_port
= enc_to_dig_port(&encoder
->base
);
4260 /* 1:1 mapping between ports and PLLs */
4261 i
= (enum intel_dpll_id
)intel_dig_port
->port
;
4262 pll
= &dev_priv
->shared_dplls
[i
];
4263 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
4264 crtc
->base
.base
.id
, pll
->name
);
4265 WARN_ON(pll
->new_config
->crtc_mask
);
4270 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4271 pll
= &dev_priv
->shared_dplls
[i
];
4273 /* Only want to check enabled timings first */
4274 if (pll
->new_config
->crtc_mask
== 0)
4277 if (memcmp(&crtc_state
->dpll_hw_state
,
4278 &pll
->new_config
->hw_state
,
4279 sizeof(pll
->new_config
->hw_state
)) == 0) {
4280 DRM_DEBUG_KMS("CRTC:%d sharing existing %s (crtc mask 0x%08x, ative %d)\n",
4281 crtc
->base
.base
.id
, pll
->name
,
4282 pll
->new_config
->crtc_mask
,
4288 /* Ok no matching timings, maybe there's a free one? */
4289 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4290 pll
= &dev_priv
->shared_dplls
[i
];
4291 if (pll
->new_config
->crtc_mask
== 0) {
4292 DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
4293 crtc
->base
.base
.id
, pll
->name
);
4301 if (pll
->new_config
->crtc_mask
== 0)
4302 pll
->new_config
->hw_state
= crtc_state
->dpll_hw_state
;
4304 crtc_state
->shared_dpll
= i
;
4305 DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll
->name
,
4306 pipe_name(crtc
->pipe
));
4308 pll
->new_config
->crtc_mask
|= 1 << crtc
->pipe
;
4314 * intel_shared_dpll_start_config - start a new PLL staged config
4315 * @dev_priv: DRM device
4316 * @clear_pipes: mask of pipes that will have their PLLs freed
4318 * Starts a new PLL staged config, copying the current config but
4319 * releasing the references of pipes specified in clear_pipes.
4321 static int intel_shared_dpll_start_config(struct drm_i915_private
*dev_priv
,
4322 unsigned clear_pipes
)
4324 struct intel_shared_dpll
*pll
;
4325 enum intel_dpll_id i
;
4327 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4328 pll
= &dev_priv
->shared_dplls
[i
];
4330 pll
->new_config
= kmemdup(&pll
->config
, sizeof pll
->config
,
4332 if (!pll
->new_config
)
4335 pll
->new_config
->crtc_mask
&= ~clear_pipes
;
4342 pll
= &dev_priv
->shared_dplls
[i
];
4343 kfree(pll
->new_config
);
4344 pll
->new_config
= NULL
;
4350 static void intel_shared_dpll_commit(struct drm_i915_private
*dev_priv
)
4352 struct intel_shared_dpll
*pll
;
4353 enum intel_dpll_id i
;
4355 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4356 pll
= &dev_priv
->shared_dplls
[i
];
4358 WARN_ON(pll
->new_config
== &pll
->config
);
4360 pll
->config
= *pll
->new_config
;
4361 kfree(pll
->new_config
);
4362 pll
->new_config
= NULL
;
4366 static void intel_shared_dpll_abort_config(struct drm_i915_private
*dev_priv
)
4368 struct intel_shared_dpll
*pll
;
4369 enum intel_dpll_id i
;
4371 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
4372 pll
= &dev_priv
->shared_dplls
[i
];
4374 WARN_ON(pll
->new_config
== &pll
->config
);
4376 kfree(pll
->new_config
);
4377 pll
->new_config
= NULL
;
4381 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
4383 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4384 int dslreg
= PIPEDSL(pipe
);
4387 temp
= I915_READ(dslreg
);
4389 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
4390 if (wait_for(I915_READ(dslreg
) != temp
, 5))
4391 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
4396 * skl_update_scaler_users - Stages update to crtc's scaler state
4398 * @crtc_state: crtc_state
4399 * @plane: plane (NULL indicates crtc is requesting update)
4400 * @plane_state: plane's state
4401 * @force_detach: request unconditional detachment of scaler
4403 * This function updates scaler state for requested plane or crtc.
4404 * To request scaler usage update for a plane, caller shall pass plane pointer.
4405 * To request scaler usage update for crtc, caller shall pass plane pointer
4409 * 0 - scaler_usage updated successfully
4410 * error - requested scaling cannot be supported or other error condition
4413 skl_update_scaler_users(
4414 struct intel_crtc
*intel_crtc
, struct intel_crtc_state
*crtc_state
,
4415 struct intel_plane
*intel_plane
, struct intel_plane_state
*plane_state
,
4420 int src_w
, src_h
, dst_w
, dst_h
;
4422 struct drm_framebuffer
*fb
;
4423 struct intel_crtc_scaler_state
*scaler_state
;
4424 unsigned int rotation
;
4426 if (!intel_crtc
|| !crtc_state
)
4429 scaler_state
= &crtc_state
->scaler_state
;
4431 idx
= intel_plane
? drm_plane_index(&intel_plane
->base
) : SKL_CRTC_INDEX
;
4432 fb
= intel_plane
? plane_state
->base
.fb
: NULL
;
4435 src_w
= drm_rect_width(&plane_state
->src
) >> 16;
4436 src_h
= drm_rect_height(&plane_state
->src
) >> 16;
4437 dst_w
= drm_rect_width(&plane_state
->dst
);
4438 dst_h
= drm_rect_height(&plane_state
->dst
);
4439 scaler_id
= &plane_state
->scaler_id
;
4440 rotation
= plane_state
->base
.rotation
;
4442 struct drm_display_mode
*adjusted_mode
=
4443 &crtc_state
->base
.adjusted_mode
;
4444 src_w
= crtc_state
->pipe_src_w
;
4445 src_h
= crtc_state
->pipe_src_h
;
4446 dst_w
= adjusted_mode
->hdisplay
;
4447 dst_h
= adjusted_mode
->vdisplay
;
4448 scaler_id
= &scaler_state
->scaler_id
;
4449 rotation
= DRM_ROTATE_0
;
4452 need_scaling
= intel_rotation_90_or_270(rotation
) ?
4453 (src_h
!= dst_w
|| src_w
!= dst_h
):
4454 (src_w
!= dst_w
|| src_h
!= dst_h
);
4457 * if plane is being disabled or scaler is no more required or force detach
4458 * - free scaler binded to this plane/crtc
4459 * - in order to do this, update crtc->scaler_usage
4461 * Here scaler state in crtc_state is set free so that
4462 * scaler can be assigned to other user. Actual register
4463 * update to free the scaler is done in plane/panel-fit programming.
4464 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4466 if (force_detach
|| !need_scaling
|| (intel_plane
&&
4467 (!fb
|| !plane_state
->visible
))) {
4468 if (*scaler_id
>= 0) {
4469 scaler_state
->scaler_users
&= ~(1 << idx
);
4470 scaler_state
->scalers
[*scaler_id
].in_use
= 0;
4472 DRM_DEBUG_KMS("Staged freeing scaler id %d.%d from %s:%d "
4473 "crtc_state = %p scaler_users = 0x%x\n",
4474 intel_crtc
->pipe
, *scaler_id
, intel_plane
? "PLANE" : "CRTC",
4475 intel_plane
? intel_plane
->base
.base
.id
:
4476 intel_crtc
->base
.base
.id
, crtc_state
,
4477 scaler_state
->scaler_users
);
4484 if (src_w
< SKL_MIN_SRC_W
|| src_h
< SKL_MIN_SRC_H
||
4485 dst_w
< SKL_MIN_DST_W
|| dst_h
< SKL_MIN_DST_H
||
4487 src_w
> SKL_MAX_SRC_W
|| src_h
> SKL_MAX_SRC_H
||
4488 dst_w
> SKL_MAX_DST_W
|| dst_h
> SKL_MAX_DST_H
) {
4489 DRM_DEBUG_KMS("%s:%d scaler_user index %u.%u: src %ux%u dst %ux%u "
4490 "size is out of scaler range\n",
4491 intel_plane
? "PLANE" : "CRTC",
4492 intel_plane
? intel_plane
->base
.base
.id
: intel_crtc
->base
.base
.id
,
4493 intel_crtc
->pipe
, idx
, src_w
, src_h
, dst_w
, dst_h
);
4497 /* check colorkey */
4498 if (intel_plane
&& intel_plane
->ckey
.flags
!= I915_SET_COLORKEY_NONE
) {
4499 DRM_DEBUG_KMS("PLANE:%d scaling with color key not allowed",
4500 intel_plane
->base
.base
.id
);
4504 /* Check src format */
4506 switch (fb
->pixel_format
) {
4507 case DRM_FORMAT_RGB565
:
4508 case DRM_FORMAT_XBGR8888
:
4509 case DRM_FORMAT_XRGB8888
:
4510 case DRM_FORMAT_ABGR8888
:
4511 case DRM_FORMAT_ARGB8888
:
4512 case DRM_FORMAT_XRGB2101010
:
4513 case DRM_FORMAT_XBGR2101010
:
4514 case DRM_FORMAT_YUYV
:
4515 case DRM_FORMAT_YVYU
:
4516 case DRM_FORMAT_UYVY
:
4517 case DRM_FORMAT_VYUY
:
4520 DRM_DEBUG_KMS("PLANE:%d FB:%d unsupported scaling format 0x%x\n",
4521 intel_plane
->base
.base
.id
, fb
->base
.id
, fb
->pixel_format
);
4526 /* mark this plane as a scaler user in crtc_state */
4527 scaler_state
->scaler_users
|= (1 << idx
);
4528 DRM_DEBUG_KMS("%s:%d staged scaling request for %ux%u->%ux%u "
4529 "crtc_state = %p scaler_users = 0x%x\n",
4530 intel_plane
? "PLANE" : "CRTC",
4531 intel_plane
? intel_plane
->base
.base
.id
: intel_crtc
->base
.base
.id
,
4532 src_w
, src_h
, dst_w
, dst_h
, crtc_state
, scaler_state
->scaler_users
);
4536 static void skylake_pfit_update(struct intel_crtc
*crtc
, int enable
)
4538 struct drm_device
*dev
= crtc
->base
.dev
;
4539 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4540 int pipe
= crtc
->pipe
;
4541 struct intel_crtc_scaler_state
*scaler_state
=
4542 &crtc
->config
->scaler_state
;
4544 DRM_DEBUG_KMS("for crtc_state = %p\n", crtc
->config
);
4546 /* To update pfit, first update scaler state */
4547 skl_update_scaler_users(crtc
, crtc
->config
, NULL
, NULL
, !enable
);
4548 intel_atomic_setup_scalers(crtc
->base
.dev
, crtc
, crtc
->config
);
4549 skl_detach_scalers(crtc
);
4553 if (crtc
->config
->pch_pfit
.enabled
) {
4556 if (WARN_ON(crtc
->config
->scaler_state
.scaler_id
< 0)) {
4557 DRM_ERROR("Requesting pfit without getting a scaler first\n");
4561 id
= scaler_state
->scaler_id
;
4562 I915_WRITE(SKL_PS_CTRL(pipe
, id
), PS_SCALER_EN
|
4563 PS_FILTER_MEDIUM
| scaler_state
->scalers
[id
].mode
);
4564 I915_WRITE(SKL_PS_WIN_POS(pipe
, id
), crtc
->config
->pch_pfit
.pos
);
4565 I915_WRITE(SKL_PS_WIN_SZ(pipe
, id
), crtc
->config
->pch_pfit
.size
);
4567 DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc
->config
, id
);
4571 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
4573 struct drm_device
*dev
= crtc
->base
.dev
;
4574 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4575 int pipe
= crtc
->pipe
;
4577 if (crtc
->config
->pch_pfit
.enabled
) {
4578 /* Force use of hard-coded filter coefficients
4579 * as some pre-programmed values are broken,
4582 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
))
4583 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
4584 PF_PIPE_SEL_IVB(pipe
));
4586 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
4587 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
->pch_pfit
.pos
);
4588 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
->pch_pfit
.size
);
4592 static void intel_enable_sprite_planes(struct drm_crtc
*crtc
)
4594 struct drm_device
*dev
= crtc
->dev
;
4595 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
4596 struct drm_plane
*plane
;
4597 struct intel_plane
*intel_plane
;
4599 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
4600 intel_plane
= to_intel_plane(plane
);
4601 if (intel_plane
->pipe
== pipe
)
4602 intel_plane_restore(&intel_plane
->base
);
4606 void hsw_enable_ips(struct intel_crtc
*crtc
)
4608 struct drm_device
*dev
= crtc
->base
.dev
;
4609 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4611 if (!crtc
->config
->ips_enabled
)
4614 /* We can only enable IPS after we enable a plane and wait for a vblank */
4615 intel_wait_for_vblank(dev
, crtc
->pipe
);
4617 assert_plane_enabled(dev_priv
, crtc
->plane
);
4618 if (IS_BROADWELL(dev
)) {
4619 mutex_lock(&dev_priv
->rps
.hw_lock
);
4620 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
4621 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4622 /* Quoting Art Runyan: "its not safe to expect any particular
4623 * value in IPS_CTL bit 31 after enabling IPS through the
4624 * mailbox." Moreover, the mailbox may return a bogus state,
4625 * so we need to just enable it and continue on.
4628 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
4629 /* The bit only becomes 1 in the next vblank, so this wait here
4630 * is essentially intel_wait_for_vblank. If we don't have this
4631 * and don't wait for vblanks until the end of crtc_enable, then
4632 * the HW state readout code will complain that the expected
4633 * IPS_CTL value is not the one we read. */
4634 if (wait_for(I915_READ_NOTRACE(IPS_CTL
) & IPS_ENABLE
, 50))
4635 DRM_ERROR("Timed out waiting for IPS enable\n");
4639 void hsw_disable_ips(struct intel_crtc
*crtc
)
4641 struct drm_device
*dev
= crtc
->base
.dev
;
4642 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4644 if (!crtc
->config
->ips_enabled
)
4647 assert_plane_enabled(dev_priv
, crtc
->plane
);
4648 if (IS_BROADWELL(dev
)) {
4649 mutex_lock(&dev_priv
->rps
.hw_lock
);
4650 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
4651 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4652 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4653 if (wait_for((I915_READ(IPS_CTL
) & IPS_ENABLE
) == 0, 42))
4654 DRM_ERROR("Timed out waiting for IPS disable\n");
4656 I915_WRITE(IPS_CTL
, 0);
4657 POSTING_READ(IPS_CTL
);
4660 /* We need to wait for a vblank before we can disable the plane. */
4661 intel_wait_for_vblank(dev
, crtc
->pipe
);
4664 /** Loads the palette/gamma unit for the CRTC with the prepared values */
4665 static void intel_crtc_load_lut(struct drm_crtc
*crtc
)
4667 struct drm_device
*dev
= crtc
->dev
;
4668 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4669 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4670 enum pipe pipe
= intel_crtc
->pipe
;
4671 int palreg
= PALETTE(pipe
);
4673 bool reenable_ips
= false;
4675 /* The clocks have to be on to load the palette. */
4676 if (!crtc
->state
->enable
|| !intel_crtc
->active
)
4679 if (HAS_GMCH_DISPLAY(dev_priv
->dev
)) {
4680 if (intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_DSI
))
4681 assert_dsi_pll_enabled(dev_priv
);
4683 assert_pll_enabled(dev_priv
, pipe
);
4686 /* use legacy palette for Ironlake */
4687 if (!HAS_GMCH_DISPLAY(dev
))
4688 palreg
= LGC_PALETTE(pipe
);
4690 /* Workaround : Do not read or write the pipe palette/gamma data while
4691 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
4693 if (IS_HASWELL(dev
) && intel_crtc
->config
->ips_enabled
&&
4694 ((I915_READ(GAMMA_MODE(pipe
)) & GAMMA_MODE_MODE_MASK
) ==
4695 GAMMA_MODE_MODE_SPLIT
)) {
4696 hsw_disable_ips(intel_crtc
);
4697 reenable_ips
= true;
4700 for (i
= 0; i
< 256; i
++) {
4701 I915_WRITE(palreg
+ 4 * i
,
4702 (intel_crtc
->lut_r
[i
] << 16) |
4703 (intel_crtc
->lut_g
[i
] << 8) |
4704 intel_crtc
->lut_b
[i
]);
4708 hsw_enable_ips(intel_crtc
);
4711 static void intel_crtc_dpms_overlay_disable(struct intel_crtc
*intel_crtc
)
4713 if (intel_crtc
->overlay
) {
4714 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4715 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4717 mutex_lock(&dev
->struct_mutex
);
4718 dev_priv
->mm
.interruptible
= false;
4719 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
4720 dev_priv
->mm
.interruptible
= true;
4721 mutex_unlock(&dev
->struct_mutex
);
4724 /* Let userspace switch the overlay on again. In most cases userspace
4725 * has to recompute where to put it anyway.
4730 * intel_post_enable_primary - Perform operations after enabling primary plane
4731 * @crtc: the CRTC whose primary plane was just enabled
4733 * Performs potentially sleeping operations that must be done after the primary
4734 * plane is enabled, such as updating FBC and IPS. Note that this may be
4735 * called due to an explicit primary plane update, or due to an implicit
4736 * re-enable that is caused when a sprite plane is updated to no longer
4737 * completely hide the primary plane.
4740 intel_post_enable_primary(struct drm_crtc
*crtc
)
4742 struct drm_device
*dev
= crtc
->dev
;
4743 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4744 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4745 int pipe
= intel_crtc
->pipe
;
4748 * BDW signals flip done immediately if the plane
4749 * is disabled, even if the plane enable is already
4750 * armed to occur at the next vblank :(
4752 if (IS_BROADWELL(dev
))
4753 intel_wait_for_vblank(dev
, pipe
);
4756 * FIXME IPS should be fine as long as one plane is
4757 * enabled, but in practice it seems to have problems
4758 * when going from primary only to sprite only and vice
4761 hsw_enable_ips(intel_crtc
);
4763 mutex_lock(&dev
->struct_mutex
);
4764 intel_fbc_update(dev
);
4765 mutex_unlock(&dev
->struct_mutex
);
4768 * Gen2 reports pipe underruns whenever all planes are disabled.
4769 * So don't enable underrun reporting before at least some planes
4771 * FIXME: Need to fix the logic to work when we turn off all planes
4772 * but leave the pipe running.
4775 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4777 /* Underruns don't raise interrupts, so check manually. */
4778 if (HAS_GMCH_DISPLAY(dev
))
4779 i9xx_check_fifo_underruns(dev_priv
);
4783 * intel_pre_disable_primary - Perform operations before disabling primary plane
4784 * @crtc: the CRTC whose primary plane is to be disabled
4786 * Performs potentially sleeping operations that must be done before the
4787 * primary plane is disabled, such as updating FBC and IPS. Note that this may
4788 * be called due to an explicit primary plane update, or due to an implicit
4789 * disable that is caused when a sprite plane completely hides the primary
4793 intel_pre_disable_primary(struct drm_crtc
*crtc
)
4795 struct drm_device
*dev
= crtc
->dev
;
4796 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4797 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4798 int pipe
= intel_crtc
->pipe
;
4801 * Gen2 reports pipe underruns whenever all planes are disabled.
4802 * So diasble underrun reporting before all the planes get disabled.
4803 * FIXME: Need to fix the logic to work when we turn off all planes
4804 * but leave the pipe running.
4807 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
4810 * Vblank time updates from the shadow to live plane control register
4811 * are blocked if the memory self-refresh mode is active at that
4812 * moment. So to make sure the plane gets truly disabled, disable
4813 * first the self-refresh mode. The self-refresh enable bit in turn
4814 * will be checked/applied by the HW only at the next frame start
4815 * event which is after the vblank start event, so we need to have a
4816 * wait-for-vblank between disabling the plane and the pipe.
4818 if (HAS_GMCH_DISPLAY(dev
))
4819 intel_set_memory_cxsr(dev_priv
, false);
4821 mutex_lock(&dev
->struct_mutex
);
4822 if (dev_priv
->fbc
.crtc
== intel_crtc
)
4823 intel_fbc_disable(dev
);
4824 mutex_unlock(&dev
->struct_mutex
);
4827 * FIXME IPS should be fine as long as one plane is
4828 * enabled, but in practice it seems to have problems
4829 * when going from primary only to sprite only and vice
4832 hsw_disable_ips(intel_crtc
);
4835 static void intel_crtc_enable_planes(struct drm_crtc
*crtc
)
4837 intel_enable_primary_hw_plane(crtc
->primary
, crtc
);
4838 intel_enable_sprite_planes(crtc
);
4839 intel_crtc_update_cursor(crtc
, true);
4841 intel_post_enable_primary(crtc
);
4844 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
)
4846 struct drm_device
*dev
= crtc
->dev
;
4847 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4848 struct intel_plane
*intel_plane
;
4849 int pipe
= intel_crtc
->pipe
;
4851 intel_crtc_wait_for_pending_flips(crtc
);
4853 intel_pre_disable_primary(crtc
);
4855 intel_crtc_dpms_overlay_disable(intel_crtc
);
4856 for_each_intel_plane(dev
, intel_plane
) {
4857 if (intel_plane
->pipe
== pipe
) {
4858 struct drm_crtc
*from
= intel_plane
->base
.crtc
;
4860 intel_plane
->disable_plane(&intel_plane
->base
,
4861 from
?: crtc
, true);
4866 * FIXME: Once we grow proper nuclear flip support out of this we need
4867 * to compute the mask of flip planes precisely. For the time being
4868 * consider this a flip to a NULL plane.
4870 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_ALL_MASK(pipe
));
4873 static void ironlake_crtc_enable(struct drm_crtc
*crtc
)
4875 struct drm_device
*dev
= crtc
->dev
;
4876 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4877 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4878 struct intel_encoder
*encoder
;
4879 int pipe
= intel_crtc
->pipe
;
4881 WARN_ON(!crtc
->state
->enable
);
4883 if (intel_crtc
->active
)
4886 if (intel_crtc
->config
->has_pch_encoder
)
4887 intel_prepare_shared_dpll(intel_crtc
);
4889 if (intel_crtc
->config
->has_dp_encoder
)
4890 intel_dp_set_m_n(intel_crtc
, M1_N1
);
4892 intel_set_pipe_timings(intel_crtc
);
4894 if (intel_crtc
->config
->has_pch_encoder
) {
4895 intel_cpu_transcoder_set_m_n(intel_crtc
,
4896 &intel_crtc
->config
->fdi_m_n
, NULL
);
4899 ironlake_set_pipeconf(crtc
);
4901 intel_crtc
->active
= true;
4903 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
4904 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, true);
4906 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4907 if (encoder
->pre_enable
)
4908 encoder
->pre_enable(encoder
);
4910 if (intel_crtc
->config
->has_pch_encoder
) {
4911 /* Note: FDI PLL enabling _must_ be done before we enable the
4912 * cpu pipes, hence this is separate from all the other fdi/pch
4914 ironlake_fdi_pll_enable(intel_crtc
);
4916 assert_fdi_tx_disabled(dev_priv
, pipe
);
4917 assert_fdi_rx_disabled(dev_priv
, pipe
);
4920 ironlake_pfit_enable(intel_crtc
);
4923 * On ILK+ LUT must be loaded before the pipe is running but with
4926 intel_crtc_load_lut(crtc
);
4928 intel_update_watermarks(crtc
);
4929 intel_enable_pipe(intel_crtc
);
4931 if (intel_crtc
->config
->has_pch_encoder
)
4932 ironlake_pch_enable(crtc
);
4934 assert_vblank_disabled(crtc
);
4935 drm_crtc_vblank_on(crtc
);
4937 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4938 encoder
->enable(encoder
);
4940 if (HAS_PCH_CPT(dev
))
4941 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
4944 /* IPS only exists on ULT machines and is tied to pipe A. */
4945 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
4947 return HAS_IPS(crtc
->base
.dev
) && crtc
->pipe
== PIPE_A
;
4951 * This implements the workaround described in the "notes" section of the mode
4952 * set sequence documentation. When going from no pipes or single pipe to
4953 * multiple pipes, and planes are enabled after the pipe, we need to wait at
4954 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
4956 static void haswell_mode_set_planes_workaround(struct intel_crtc
*crtc
)
4958 struct drm_device
*dev
= crtc
->base
.dev
;
4959 struct intel_crtc
*crtc_it
, *other_active_crtc
= NULL
;
4961 /* We want to get the other_active_crtc only if there's only 1 other
4963 for_each_intel_crtc(dev
, crtc_it
) {
4964 if (!crtc_it
->active
|| crtc_it
== crtc
)
4967 if (other_active_crtc
)
4970 other_active_crtc
= crtc_it
;
4972 if (!other_active_crtc
)
4975 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4976 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4979 static void haswell_crtc_enable(struct drm_crtc
*crtc
)
4981 struct drm_device
*dev
= crtc
->dev
;
4982 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4983 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4984 struct intel_encoder
*encoder
;
4985 int pipe
= intel_crtc
->pipe
;
4987 WARN_ON(!crtc
->state
->enable
);
4989 if (intel_crtc
->active
)
4992 if (intel_crtc_to_shared_dpll(intel_crtc
))
4993 intel_enable_shared_dpll(intel_crtc
);
4995 if (intel_crtc
->config
->has_dp_encoder
)
4996 intel_dp_set_m_n(intel_crtc
, M1_N1
);
4998 intel_set_pipe_timings(intel_crtc
);
5000 if (intel_crtc
->config
->cpu_transcoder
!= TRANSCODER_EDP
) {
5001 I915_WRITE(PIPE_MULT(intel_crtc
->config
->cpu_transcoder
),
5002 intel_crtc
->config
->pixel_multiplier
- 1);
5005 if (intel_crtc
->config
->has_pch_encoder
) {
5006 intel_cpu_transcoder_set_m_n(intel_crtc
,
5007 &intel_crtc
->config
->fdi_m_n
, NULL
);
5010 haswell_set_pipeconf(crtc
);
5012 intel_set_pipe_csc(crtc
);
5014 intel_crtc
->active
= true;
5016 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5017 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5018 if (encoder
->pre_enable
)
5019 encoder
->pre_enable(encoder
);
5021 if (intel_crtc
->config
->has_pch_encoder
) {
5022 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5024 dev_priv
->display
.fdi_link_train(crtc
);
5027 intel_ddi_enable_pipe_clock(intel_crtc
);
5029 if (INTEL_INFO(dev
)->gen
== 9)
5030 skylake_pfit_update(intel_crtc
, 1);
5031 else if (INTEL_INFO(dev
)->gen
< 9)
5032 ironlake_pfit_enable(intel_crtc
);
5034 MISSING_CASE(INTEL_INFO(dev
)->gen
);
5037 * On ILK+ LUT must be loaded before the pipe is running but with
5040 intel_crtc_load_lut(crtc
);
5042 intel_ddi_set_pipe_settings(crtc
);
5043 intel_ddi_enable_transcoder_func(crtc
);
5045 intel_update_watermarks(crtc
);
5046 intel_enable_pipe(intel_crtc
);
5048 if (intel_crtc
->config
->has_pch_encoder
)
5049 lpt_pch_enable(crtc
);
5051 if (intel_crtc
->config
->dp_encoder_is_mst
)
5052 intel_ddi_set_vc_payload_alloc(crtc
, true);
5054 assert_vblank_disabled(crtc
);
5055 drm_crtc_vblank_on(crtc
);
5057 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5058 encoder
->enable(encoder
);
5059 intel_opregion_notify_encoder(encoder
, true);
5062 /* If we change the relative order between pipe/planes enabling, we need
5063 * to change the workaround. */
5064 haswell_mode_set_planes_workaround(intel_crtc
);
5067 static void ironlake_pfit_disable(struct intel_crtc
*crtc
)
5069 struct drm_device
*dev
= crtc
->base
.dev
;
5070 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5071 int pipe
= crtc
->pipe
;
5073 /* To avoid upsetting the power well on haswell only disable the pfit if
5074 * it's in use. The hw state code will make sure we get this right. */
5075 if (crtc
->config
->pch_pfit
.enabled
) {
5076 I915_WRITE(PF_CTL(pipe
), 0);
5077 I915_WRITE(PF_WIN_POS(pipe
), 0);
5078 I915_WRITE(PF_WIN_SZ(pipe
), 0);
5082 static void ironlake_crtc_disable(struct drm_crtc
*crtc
)
5084 struct drm_device
*dev
= crtc
->dev
;
5085 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5086 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5087 struct intel_encoder
*encoder
;
5088 int pipe
= intel_crtc
->pipe
;
5091 if (!intel_crtc
->active
)
5094 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5095 encoder
->disable(encoder
);
5097 drm_crtc_vblank_off(crtc
);
5098 assert_vblank_disabled(crtc
);
5100 if (intel_crtc
->config
->has_pch_encoder
)
5101 intel_set_pch_fifo_underrun_reporting(dev_priv
, pipe
, false);
5103 intel_disable_pipe(intel_crtc
);
5105 ironlake_pfit_disable(intel_crtc
);
5107 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5108 if (encoder
->post_disable
)
5109 encoder
->post_disable(encoder
);
5111 if (intel_crtc
->config
->has_pch_encoder
) {
5112 ironlake_fdi_disable(crtc
);
5114 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
5116 if (HAS_PCH_CPT(dev
)) {
5117 /* disable TRANS_DP_CTL */
5118 reg
= TRANS_DP_CTL(pipe
);
5119 temp
= I915_READ(reg
);
5120 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
5121 TRANS_DP_PORT_SEL_MASK
);
5122 temp
|= TRANS_DP_PORT_SEL_NONE
;
5123 I915_WRITE(reg
, temp
);
5125 /* disable DPLL_SEL */
5126 temp
= I915_READ(PCH_DPLL_SEL
);
5127 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
5128 I915_WRITE(PCH_DPLL_SEL
, temp
);
5131 /* disable PCH DPLL */
5132 intel_disable_shared_dpll(intel_crtc
);
5134 ironlake_fdi_pll_disable(intel_crtc
);
5137 intel_crtc
->active
= false;
5138 intel_update_watermarks(crtc
);
5140 mutex_lock(&dev
->struct_mutex
);
5141 intel_fbc_update(dev
);
5142 mutex_unlock(&dev
->struct_mutex
);
5145 static void haswell_crtc_disable(struct drm_crtc
*crtc
)
5147 struct drm_device
*dev
= crtc
->dev
;
5148 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5149 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5150 struct intel_encoder
*encoder
;
5151 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
5153 if (!intel_crtc
->active
)
5156 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5157 intel_opregion_notify_encoder(encoder
, false);
5158 encoder
->disable(encoder
);
5161 drm_crtc_vblank_off(crtc
);
5162 assert_vblank_disabled(crtc
);
5164 if (intel_crtc
->config
->has_pch_encoder
)
5165 intel_set_pch_fifo_underrun_reporting(dev_priv
, TRANSCODER_A
,
5167 intel_disable_pipe(intel_crtc
);
5169 if (intel_crtc
->config
->dp_encoder_is_mst
)
5170 intel_ddi_set_vc_payload_alloc(crtc
, false);
5172 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
5174 if (INTEL_INFO(dev
)->gen
== 9)
5175 skylake_pfit_update(intel_crtc
, 0);
5176 else if (INTEL_INFO(dev
)->gen
< 9)
5177 ironlake_pfit_disable(intel_crtc
);
5179 MISSING_CASE(INTEL_INFO(dev
)->gen
);
5181 intel_ddi_disable_pipe_clock(intel_crtc
);
5183 if (intel_crtc
->config
->has_pch_encoder
) {
5184 lpt_disable_pch_transcoder(dev_priv
);
5185 intel_ddi_fdi_disable(crtc
);
5188 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5189 if (encoder
->post_disable
)
5190 encoder
->post_disable(encoder
);
5192 intel_crtc
->active
= false;
5193 intel_update_watermarks(crtc
);
5195 mutex_lock(&dev
->struct_mutex
);
5196 intel_fbc_update(dev
);
5197 mutex_unlock(&dev
->struct_mutex
);
5199 if (intel_crtc_to_shared_dpll(intel_crtc
))
5200 intel_disable_shared_dpll(intel_crtc
);
5203 static void ironlake_crtc_off(struct drm_crtc
*crtc
)
5205 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5206 intel_put_shared_dpll(intel_crtc
);
5210 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
5212 struct drm_device
*dev
= crtc
->base
.dev
;
5213 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5214 struct intel_crtc_state
*pipe_config
= crtc
->config
;
5216 if (!pipe_config
->gmch_pfit
.control
)
5220 * The panel fitter should only be adjusted whilst the pipe is disabled,
5221 * according to register description and PRM.
5223 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
5224 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5226 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
5227 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
5229 /* Border color in case we don't scale up to the full screen. Black by
5230 * default, change to something else for debugging. */
5231 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
5234 static enum intel_display_power_domain
port_to_power_domain(enum port port
)
5238 return POWER_DOMAIN_PORT_DDI_A_4_LANES
;
5240 return POWER_DOMAIN_PORT_DDI_B_4_LANES
;
5242 return POWER_DOMAIN_PORT_DDI_C_4_LANES
;
5244 return POWER_DOMAIN_PORT_DDI_D_4_LANES
;
5247 return POWER_DOMAIN_PORT_OTHER
;
5251 #define for_each_power_domain(domain, mask) \
5252 for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
5253 if ((1 << (domain)) & (mask))
5255 enum intel_display_power_domain
5256 intel_display_port_power_domain(struct intel_encoder
*intel_encoder
)
5258 struct drm_device
*dev
= intel_encoder
->base
.dev
;
5259 struct intel_digital_port
*intel_dig_port
;
5261 switch (intel_encoder
->type
) {
5262 case INTEL_OUTPUT_UNKNOWN
:
5263 /* Only DDI platforms should ever use this output type */
5264 WARN_ON_ONCE(!HAS_DDI(dev
));
5265 case INTEL_OUTPUT_DISPLAYPORT
:
5266 case INTEL_OUTPUT_HDMI
:
5267 case INTEL_OUTPUT_EDP
:
5268 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
5269 return port_to_power_domain(intel_dig_port
->port
);
5270 case INTEL_OUTPUT_DP_MST
:
5271 intel_dig_port
= enc_to_mst(&intel_encoder
->base
)->primary
;
5272 return port_to_power_domain(intel_dig_port
->port
);
5273 case INTEL_OUTPUT_ANALOG
:
5274 return POWER_DOMAIN_PORT_CRT
;
5275 case INTEL_OUTPUT_DSI
:
5276 return POWER_DOMAIN_PORT_DSI
;
5278 return POWER_DOMAIN_PORT_OTHER
;
5282 static unsigned long get_crtc_power_domains(struct drm_crtc
*crtc
)
5284 struct drm_device
*dev
= crtc
->dev
;
5285 struct intel_encoder
*intel_encoder
;
5286 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5287 enum pipe pipe
= intel_crtc
->pipe
;
5289 enum transcoder transcoder
;
5291 transcoder
= intel_pipe_to_cpu_transcoder(dev
->dev_private
, pipe
);
5293 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
5294 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
5295 if (intel_crtc
->config
->pch_pfit
.enabled
||
5296 intel_crtc
->config
->pch_pfit
.force_thru
)
5297 mask
|= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
5299 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
5300 mask
|= BIT(intel_display_port_power_domain(intel_encoder
));
5305 static void modeset_update_crtc_power_domains(struct drm_atomic_state
*state
)
5307 struct drm_device
*dev
= state
->dev
;
5308 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5309 unsigned long pipe_domains
[I915_MAX_PIPES
] = { 0, };
5310 struct intel_crtc
*crtc
;
5313 * First get all needed power domains, then put all unneeded, to avoid
5314 * any unnecessary toggling of the power wells.
5316 for_each_intel_crtc(dev
, crtc
) {
5317 enum intel_display_power_domain domain
;
5319 if (!crtc
->base
.state
->enable
)
5322 pipe_domains
[crtc
->pipe
] = get_crtc_power_domains(&crtc
->base
);
5324 for_each_power_domain(domain
, pipe_domains
[crtc
->pipe
])
5325 intel_display_power_get(dev_priv
, domain
);
5328 if (dev_priv
->display
.modeset_global_resources
)
5329 dev_priv
->display
.modeset_global_resources(state
);
5331 for_each_intel_crtc(dev
, crtc
) {
5332 enum intel_display_power_domain domain
;
5334 for_each_power_domain(domain
, crtc
->enabled_power_domains
)
5335 intel_display_power_put(dev_priv
, domain
);
5337 crtc
->enabled_power_domains
= pipe_domains
[crtc
->pipe
];
5340 intel_display_set_init_power(dev_priv
, false);
5343 void broxton_set_cdclk(struct drm_device
*dev
, int frequency
)
5345 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5348 uint32_t current_freq
;
5351 /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */
5352 switch (frequency
) {
5354 divider
= BXT_CDCLK_CD2X_DIV_SEL_4
;
5355 ratio
= BXT_DE_PLL_RATIO(60);
5358 divider
= BXT_CDCLK_CD2X_DIV_SEL_2
;
5359 ratio
= BXT_DE_PLL_RATIO(60);
5362 divider
= BXT_CDCLK_CD2X_DIV_SEL_1_5
;
5363 ratio
= BXT_DE_PLL_RATIO(60);
5366 divider
= BXT_CDCLK_CD2X_DIV_SEL_1
;
5367 ratio
= BXT_DE_PLL_RATIO(60);
5370 divider
= BXT_CDCLK_CD2X_DIV_SEL_1
;
5371 ratio
= BXT_DE_PLL_RATIO(65);
5375 * Bypass frequency with DE PLL disabled. Init ratio, divider
5376 * to suppress GCC warning.
5382 DRM_ERROR("unsupported CDCLK freq %d", frequency
);
5387 mutex_lock(&dev_priv
->rps
.hw_lock
);
5388 /* Inform power controller of upcoming frequency change */
5389 ret
= sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
,
5391 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5394 DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n",
5399 current_freq
= I915_READ(CDCLK_CTL
) & CDCLK_FREQ_DECIMAL_MASK
;
5400 /* convert from .1 fixpoint MHz with -1MHz offset to kHz */
5401 current_freq
= current_freq
* 500 + 1000;
5404 * DE PLL has to be disabled when
5405 * - setting to 19.2MHz (bypass, PLL isn't used)
5406 * - before setting to 624MHz (PLL needs toggling)
5407 * - before setting to any frequency from 624MHz (PLL needs toggling)
5409 if (frequency
== 19200 || frequency
== 624000 ||
5410 current_freq
== 624000) {
5411 I915_WRITE(BXT_DE_PLL_ENABLE
, ~BXT_DE_PLL_PLL_ENABLE
);
5413 if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_LOCK
),
5415 DRM_ERROR("timout waiting for DE PLL unlock\n");
5418 if (frequency
!= 19200) {
5421 val
= I915_READ(BXT_DE_PLL_CTL
);
5422 val
&= ~BXT_DE_PLL_RATIO_MASK
;
5424 I915_WRITE(BXT_DE_PLL_CTL
, val
);
5426 I915_WRITE(BXT_DE_PLL_ENABLE
, BXT_DE_PLL_PLL_ENABLE
);
5428 if (wait_for(I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_LOCK
, 1))
5429 DRM_ERROR("timeout waiting for DE PLL lock\n");
5431 val
= I915_READ(CDCLK_CTL
);
5432 val
&= ~BXT_CDCLK_CD2X_DIV_SEL_MASK
;
5435 * Disable SSA Precharge when CD clock frequency < 500 MHz,
5438 val
&= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE
;
5439 if (frequency
>= 500000)
5440 val
|= BXT_CDCLK_SSA_PRECHARGE_ENABLE
;
5442 val
&= ~CDCLK_FREQ_DECIMAL_MASK
;
5443 /* convert from kHz to .1 fixpoint MHz with -1MHz offset */
5444 val
|= (frequency
- 1000) / 500;
5445 I915_WRITE(CDCLK_CTL
, val
);
5448 mutex_lock(&dev_priv
->rps
.hw_lock
);
5449 ret
= sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
,
5450 DIV_ROUND_UP(frequency
, 25000));
5451 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5454 DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n",
5459 dev_priv
->cdclk_freq
= frequency
;
5462 void broxton_init_cdclk(struct drm_device
*dev
)
5464 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5468 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
5469 * or else the reset will hang because there is no PCH to respond.
5470 * Move the handshake programming to initialization sequence.
5471 * Previously was left up to BIOS.
5473 val
= I915_READ(HSW_NDE_RSTWRN_OPT
);
5474 val
&= ~RESET_PCH_HANDSHAKE_ENABLE
;
5475 I915_WRITE(HSW_NDE_RSTWRN_OPT
, val
);
5477 /* Enable PG1 for cdclk */
5478 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
5480 /* check if cd clock is enabled */
5481 if (I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_PLL_ENABLE
) {
5482 DRM_DEBUG_KMS("Display already initialized\n");
5488 * - The initial CDCLK needs to be read from VBT.
5489 * Need to make this change after VBT has changes for BXT.
5490 * - check if setting the max (or any) cdclk freq is really necessary
5491 * here, it belongs to modeset time
5493 broxton_set_cdclk(dev
, 624000);
5495 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) | DBUF_POWER_REQUEST
);
5496 POSTING_READ(DBUF_CTL
);
5500 if (!(I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
))
5501 DRM_ERROR("DBuf power enable timeout!\n");
5504 void broxton_uninit_cdclk(struct drm_device
*dev
)
5506 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5508 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) & ~DBUF_POWER_REQUEST
);
5509 POSTING_READ(DBUF_CTL
);
5513 if (I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
)
5514 DRM_ERROR("DBuf power disable timeout!\n");
5516 /* Set minimum (bypass) frequency, in effect turning off the DE PLL */
5517 broxton_set_cdclk(dev
, 19200);
5519 intel_display_power_put(dev_priv
, POWER_DOMAIN_PLLS
);
5522 /* returns HPLL frequency in kHz */
5523 static int valleyview_get_vco(struct drm_i915_private
*dev_priv
)
5525 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
5527 /* Obtain SKU information */
5528 mutex_lock(&dev_priv
->dpio_lock
);
5529 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
5530 CCK_FUSE_HPLL_FREQ_MASK
;
5531 mutex_unlock(&dev_priv
->dpio_lock
);
5533 return vco_freq
[hpll_freq
] * 1000;
5536 static void vlv_update_cdclk(struct drm_device
*dev
)
5538 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5540 dev_priv
->cdclk_freq
= dev_priv
->display
.get_display_clock_speed(dev
);
5541 DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n",
5542 dev_priv
->cdclk_freq
);
5545 * Program the gmbus_freq based on the cdclk frequency.
5546 * BSpec erroneously claims we should aim for 4MHz, but
5547 * in fact 1MHz is the correct frequency.
5549 I915_WRITE(GMBUSFREQ_VLV
, DIV_ROUND_UP(dev_priv
->cdclk_freq
, 1000));
5552 /* Adjust CDclk dividers to allow high res or save power if possible */
5553 static void valleyview_set_cdclk(struct drm_device
*dev
, int cdclk
)
5555 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5558 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
)
5559 != dev_priv
->cdclk_freq
);
5561 if (cdclk
>= 320000) /* jump to highest voltage for 400MHz too */
5563 else if (cdclk
== 266667)
5568 mutex_lock(&dev_priv
->rps
.hw_lock
);
5569 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
5570 val
&= ~DSPFREQGUAR_MASK
;
5571 val
|= (cmd
<< DSPFREQGUAR_SHIFT
);
5572 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
5573 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
5574 DSPFREQSTAT_MASK
) == (cmd
<< DSPFREQSTAT_SHIFT
),
5576 DRM_ERROR("timed out waiting for CDclk change\n");
5578 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5580 if (cdclk
== 400000) {
5583 divider
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
5585 mutex_lock(&dev_priv
->dpio_lock
);
5586 /* adjust cdclk divider */
5587 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
5588 val
&= ~DISPLAY_FREQUENCY_VALUES
;
5590 vlv_cck_write(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
, val
);
5592 if (wait_for((vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
) &
5593 DISPLAY_FREQUENCY_STATUS
) == (divider
<< DISPLAY_FREQUENCY_STATUS_SHIFT
),
5595 DRM_ERROR("timed out waiting for CDclk change\n");
5596 mutex_unlock(&dev_priv
->dpio_lock
);
5599 mutex_lock(&dev_priv
->dpio_lock
);
5600 /* adjust self-refresh exit latency value */
5601 val
= vlv_bunit_read(dev_priv
, BUNIT_REG_BISOC
);
5605 * For high bandwidth configs, we set a higher latency in the bunit
5606 * so that the core display fetch happens in time to avoid underruns.
5608 if (cdclk
== 400000)
5609 val
|= 4500 / 250; /* 4.5 usec */
5611 val
|= 3000 / 250; /* 3.0 usec */
5612 vlv_bunit_write(dev_priv
, BUNIT_REG_BISOC
, val
);
5613 mutex_unlock(&dev_priv
->dpio_lock
);
5615 vlv_update_cdclk(dev
);
5618 static void cherryview_set_cdclk(struct drm_device
*dev
, int cdclk
)
5620 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5623 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
)
5624 != dev_priv
->cdclk_freq
);
5633 MISSING_CASE(cdclk
);
5638 * Specs are full of misinformation, but testing on actual
5639 * hardware has shown that we just need to write the desired
5640 * CCK divider into the Punit register.
5642 cmd
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
5644 mutex_lock(&dev_priv
->rps
.hw_lock
);
5645 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
5646 val
&= ~DSPFREQGUAR_MASK_CHV
;
5647 val
|= (cmd
<< DSPFREQGUAR_SHIFT_CHV
);
5648 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
5649 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
5650 DSPFREQSTAT_MASK_CHV
) == (cmd
<< DSPFREQSTAT_SHIFT_CHV
),
5652 DRM_ERROR("timed out waiting for CDclk change\n");
5654 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5656 vlv_update_cdclk(dev
);
5659 static int valleyview_calc_cdclk(struct drm_i915_private
*dev_priv
,
5662 int freq_320
= (dev_priv
->hpll_freq
<< 1) % 320000 != 0 ? 333333 : 320000;
5663 int limit
= IS_CHERRYVIEW(dev_priv
) ? 95 : 90;
5666 * Really only a few cases to deal with, as only 4 CDclks are supported:
5669 * 320/333MHz (depends on HPLL freq)
5671 * So we check to see whether we're above 90% (VLV) or 95% (CHV)
5672 * of the lower bin and adjust if needed.
5674 * We seem to get an unstable or solid color picture at 200MHz.
5675 * Not sure what's wrong. For now use 200MHz only when all pipes
5678 if (!IS_CHERRYVIEW(dev_priv
) &&
5679 max_pixclk
> freq_320
*limit
/100)
5681 else if (max_pixclk
> 266667*limit
/100)
5683 else if (max_pixclk
> 0)
5689 static int broxton_calc_cdclk(struct drm_i915_private
*dev_priv
,
5694 * - remove the guardband, it's not needed on BXT
5695 * - set 19.2MHz bypass frequency if there are no active pipes
5697 if (max_pixclk
> 576000*9/10)
5699 else if (max_pixclk
> 384000*9/10)
5701 else if (max_pixclk
> 288000*9/10)
5703 else if (max_pixclk
> 144000*9/10)
5709 /* Compute the max pixel clock for new configuration. Uses atomic state if
5710 * that's non-NULL, look at current state otherwise. */
5711 static int intel_mode_max_pixclk(struct drm_device
*dev
,
5712 struct drm_atomic_state
*state
)
5714 struct intel_crtc
*intel_crtc
;
5715 struct intel_crtc_state
*crtc_state
;
5718 for_each_intel_crtc(dev
, intel_crtc
) {
5721 intel_atomic_get_crtc_state(state
, intel_crtc
);
5723 crtc_state
= intel_crtc
->config
;
5724 if (IS_ERR(crtc_state
))
5725 return PTR_ERR(crtc_state
);
5727 if (!crtc_state
->base
.enable
)
5730 max_pixclk
= max(max_pixclk
,
5731 crtc_state
->base
.adjusted_mode
.crtc_clock
);
5737 static int valleyview_modeset_global_pipes(struct drm_atomic_state
*state
)
5739 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
5740 struct drm_crtc
*crtc
;
5741 struct drm_crtc_state
*crtc_state
;
5742 int max_pixclk
= intel_mode_max_pixclk(state
->dev
, state
);
5748 if (IS_VALLEYVIEW(dev_priv
))
5749 cdclk
= valleyview_calc_cdclk(dev_priv
, max_pixclk
);
5751 cdclk
= broxton_calc_cdclk(dev_priv
, max_pixclk
);
5753 if (cdclk
== dev_priv
->cdclk_freq
)
5756 /* add all active pipes to the state */
5757 for_each_crtc(state
->dev
, crtc
) {
5758 if (!crtc
->state
->enable
)
5761 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
5762 if (IS_ERR(crtc_state
))
5763 return PTR_ERR(crtc_state
);
5766 /* disable/enable all currently active pipes while we change cdclk */
5767 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
)
5768 if (crtc_state
->enable
)
5769 crtc_state
->mode_changed
= true;
5774 static void vlv_program_pfi_credits(struct drm_i915_private
*dev_priv
)
5776 unsigned int credits
, default_credits
;
5778 if (IS_CHERRYVIEW(dev_priv
))
5779 default_credits
= PFI_CREDIT(12);
5781 default_credits
= PFI_CREDIT(8);
5783 if (DIV_ROUND_CLOSEST(dev_priv
->cdclk_freq
, 1000) >= dev_priv
->rps
.cz_freq
) {
5784 /* CHV suggested value is 31 or 63 */
5785 if (IS_CHERRYVIEW(dev_priv
))
5786 credits
= PFI_CREDIT_31
;
5788 credits
= PFI_CREDIT(15);
5790 credits
= default_credits
;
5794 * WA - write default credits before re-programming
5795 * FIXME: should we also set the resend bit here?
5797 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
5800 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
5801 credits
| PFI_CREDIT_RESEND
);
5804 * FIXME is this guaranteed to clear
5805 * immediately or should we poll for it?
5807 WARN_ON(I915_READ(GCI_CONTROL
) & PFI_CREDIT_RESEND
);
5810 static void valleyview_modeset_global_resources(struct drm_atomic_state
*old_state
)
5812 struct drm_device
*dev
= old_state
->dev
;
5813 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5814 int max_pixclk
= intel_mode_max_pixclk(dev
, NULL
);
5817 /* The path in intel_mode_max_pixclk() with a NULL atomic state should
5819 if (WARN_ON(max_pixclk
< 0))
5822 req_cdclk
= valleyview_calc_cdclk(dev_priv
, max_pixclk
);
5824 if (req_cdclk
!= dev_priv
->cdclk_freq
) {
5826 * FIXME: We can end up here with all power domains off, yet
5827 * with a CDCLK frequency other than the minimum. To account
5828 * for this take the PIPE-A power domain, which covers the HW
5829 * blocks needed for the following programming. This can be
5830 * removed once it's guaranteed that we get here either with
5831 * the minimum CDCLK set, or the required power domains
5834 intel_display_power_get(dev_priv
, POWER_DOMAIN_PIPE_A
);
5836 if (IS_CHERRYVIEW(dev
))
5837 cherryview_set_cdclk(dev
, req_cdclk
);
5839 valleyview_set_cdclk(dev
, req_cdclk
);
5841 vlv_program_pfi_credits(dev_priv
);
5843 intel_display_power_put(dev_priv
, POWER_DOMAIN_PIPE_A
);
5847 static void valleyview_crtc_enable(struct drm_crtc
*crtc
)
5849 struct drm_device
*dev
= crtc
->dev
;
5850 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5851 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5852 struct intel_encoder
*encoder
;
5853 int pipe
= intel_crtc
->pipe
;
5856 WARN_ON(!crtc
->state
->enable
);
5858 if (intel_crtc
->active
)
5861 is_dsi
= intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_DSI
);
5864 if (IS_CHERRYVIEW(dev
))
5865 chv_prepare_pll(intel_crtc
, intel_crtc
->config
);
5867 vlv_prepare_pll(intel_crtc
, intel_crtc
->config
);
5870 if (intel_crtc
->config
->has_dp_encoder
)
5871 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5873 intel_set_pipe_timings(intel_crtc
);
5875 if (IS_CHERRYVIEW(dev
) && pipe
== PIPE_B
) {
5876 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5878 I915_WRITE(CHV_BLEND(pipe
), CHV_BLEND_LEGACY
);
5879 I915_WRITE(CHV_CANVAS(pipe
), 0);
5882 i9xx_set_pipeconf(intel_crtc
);
5884 intel_crtc
->active
= true;
5886 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5888 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5889 if (encoder
->pre_pll_enable
)
5890 encoder
->pre_pll_enable(encoder
);
5893 if (IS_CHERRYVIEW(dev
))
5894 chv_enable_pll(intel_crtc
, intel_crtc
->config
);
5896 vlv_enable_pll(intel_crtc
, intel_crtc
->config
);
5899 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5900 if (encoder
->pre_enable
)
5901 encoder
->pre_enable(encoder
);
5903 i9xx_pfit_enable(intel_crtc
);
5905 intel_crtc_load_lut(crtc
);
5907 intel_update_watermarks(crtc
);
5908 intel_enable_pipe(intel_crtc
);
5910 assert_vblank_disabled(crtc
);
5911 drm_crtc_vblank_on(crtc
);
5913 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5914 encoder
->enable(encoder
);
5917 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
5919 struct drm_device
*dev
= crtc
->base
.dev
;
5920 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5922 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp0
);
5923 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
->dpll_hw_state
.fp1
);
5926 static void i9xx_crtc_enable(struct drm_crtc
*crtc
)
5928 struct drm_device
*dev
= crtc
->dev
;
5929 struct drm_i915_private
*dev_priv
= to_i915(dev
);
5930 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5931 struct intel_encoder
*encoder
;
5932 int pipe
= intel_crtc
->pipe
;
5934 WARN_ON(!crtc
->state
->enable
);
5936 if (intel_crtc
->active
)
5939 i9xx_set_pll_dividers(intel_crtc
);
5941 if (intel_crtc
->config
->has_dp_encoder
)
5942 intel_dp_set_m_n(intel_crtc
, M1_N1
);
5944 intel_set_pipe_timings(intel_crtc
);
5946 i9xx_set_pipeconf(intel_crtc
);
5948 intel_crtc
->active
= true;
5951 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
5953 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5954 if (encoder
->pre_enable
)
5955 encoder
->pre_enable(encoder
);
5957 i9xx_enable_pll(intel_crtc
);
5959 i9xx_pfit_enable(intel_crtc
);
5961 intel_crtc_load_lut(crtc
);
5963 intel_update_watermarks(crtc
);
5964 intel_enable_pipe(intel_crtc
);
5966 assert_vblank_disabled(crtc
);
5967 drm_crtc_vblank_on(crtc
);
5969 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5970 encoder
->enable(encoder
);
5973 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
5975 struct drm_device
*dev
= crtc
->base
.dev
;
5976 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5978 if (!crtc
->config
->gmch_pfit
.control
)
5981 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
5983 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
5984 I915_READ(PFIT_CONTROL
));
5985 I915_WRITE(PFIT_CONTROL
, 0);
5988 static void i9xx_crtc_disable(struct drm_crtc
*crtc
)
5990 struct drm_device
*dev
= crtc
->dev
;
5991 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5992 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5993 struct intel_encoder
*encoder
;
5994 int pipe
= intel_crtc
->pipe
;
5996 if (!intel_crtc
->active
)
6000 * On gen2 planes are double buffered but the pipe isn't, so we must
6001 * wait for planes to fully turn off before disabling the pipe.
6002 * We also need to wait on all gmch platforms because of the
6003 * self-refresh mode constraint explained above.
6005 intel_wait_for_vblank(dev
, pipe
);
6007 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6008 encoder
->disable(encoder
);
6010 drm_crtc_vblank_off(crtc
);
6011 assert_vblank_disabled(crtc
);
6013 intel_disable_pipe(intel_crtc
);
6015 i9xx_pfit_disable(intel_crtc
);
6017 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
6018 if (encoder
->post_disable
)
6019 encoder
->post_disable(encoder
);
6021 if (!intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_DSI
)) {
6022 if (IS_CHERRYVIEW(dev
))
6023 chv_disable_pll(dev_priv
, pipe
);
6024 else if (IS_VALLEYVIEW(dev
))
6025 vlv_disable_pll(dev_priv
, pipe
);
6027 i9xx_disable_pll(intel_crtc
);
6031 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false);
6033 intel_crtc
->active
= false;
6034 intel_update_watermarks(crtc
);
6036 mutex_lock(&dev
->struct_mutex
);
6037 intel_fbc_update(dev
);
6038 mutex_unlock(&dev
->struct_mutex
);
6041 static void i9xx_crtc_off(struct drm_crtc
*crtc
)
6045 /* Master function to enable/disable CRTC and corresponding power wells */
6046 void intel_crtc_control(struct drm_crtc
*crtc
, bool enable
)
6048 struct drm_device
*dev
= crtc
->dev
;
6049 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6050 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6051 enum intel_display_power_domain domain
;
6052 unsigned long domains
;
6055 if (!intel_crtc
->active
) {
6056 domains
= get_crtc_power_domains(crtc
);
6057 for_each_power_domain(domain
, domains
)
6058 intel_display_power_get(dev_priv
, domain
);
6059 intel_crtc
->enabled_power_domains
= domains
;
6061 dev_priv
->display
.crtc_enable(crtc
);
6062 intel_crtc_enable_planes(crtc
);
6065 if (intel_crtc
->active
) {
6066 intel_crtc_disable_planes(crtc
);
6067 dev_priv
->display
.crtc_disable(crtc
);
6069 domains
= intel_crtc
->enabled_power_domains
;
6070 for_each_power_domain(domain
, domains
)
6071 intel_display_power_put(dev_priv
, domain
);
6072 intel_crtc
->enabled_power_domains
= 0;
6078 * Sets the power management mode of the pipe and plane.
6080 void intel_crtc_update_dpms(struct drm_crtc
*crtc
)
6082 struct drm_device
*dev
= crtc
->dev
;
6083 struct intel_encoder
*intel_encoder
;
6084 bool enable
= false;
6086 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
6087 enable
|= intel_encoder
->connectors_active
;
6089 intel_crtc_control(crtc
, enable
);
6091 crtc
->state
->active
= enable
;
6094 static void intel_crtc_disable(struct drm_crtc
*crtc
)
6096 struct drm_device
*dev
= crtc
->dev
;
6097 struct drm_connector
*connector
;
6098 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6100 /* crtc should still be enabled when we disable it. */
6101 WARN_ON(!crtc
->state
->enable
);
6103 intel_crtc_disable_planes(crtc
);
6104 dev_priv
->display
.crtc_disable(crtc
);
6105 dev_priv
->display
.off(crtc
);
6107 drm_plane_helper_disable(crtc
->primary
);
6109 /* Update computed state. */
6110 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
6111 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
6114 if (connector
->encoder
->crtc
!= crtc
)
6117 connector
->dpms
= DRM_MODE_DPMS_OFF
;
6118 to_intel_encoder(connector
->encoder
)->connectors_active
= false;
6122 void intel_encoder_destroy(struct drm_encoder
*encoder
)
6124 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
6126 drm_encoder_cleanup(encoder
);
6127 kfree(intel_encoder
);
6130 /* Simple dpms helper for encoders with just one connector, no cloning and only
6131 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
6132 * state of the entire output pipe. */
6133 static void intel_encoder_dpms(struct intel_encoder
*encoder
, int mode
)
6135 if (mode
== DRM_MODE_DPMS_ON
) {
6136 encoder
->connectors_active
= true;
6138 intel_crtc_update_dpms(encoder
->base
.crtc
);
6140 encoder
->connectors_active
= false;
6142 intel_crtc_update_dpms(encoder
->base
.crtc
);
6146 /* Cross check the actual hw state with our own modeset state tracking (and it's
6147 * internal consistency). */
6148 static void intel_connector_check_state(struct intel_connector
*connector
)
6150 if (connector
->get_hw_state(connector
)) {
6151 struct intel_encoder
*encoder
= connector
->encoder
;
6152 struct drm_crtc
*crtc
;
6153 bool encoder_enabled
;
6156 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6157 connector
->base
.base
.id
,
6158 connector
->base
.name
);
6160 /* there is no real hw state for MST connectors */
6161 if (connector
->mst_port
)
6164 I915_STATE_WARN(connector
->base
.dpms
== DRM_MODE_DPMS_OFF
,
6165 "wrong connector dpms state\n");
6166 I915_STATE_WARN(connector
->base
.encoder
!= &encoder
->base
,
6167 "active connector not linked to encoder\n");
6170 I915_STATE_WARN(!encoder
->connectors_active
,
6171 "encoder->connectors_active not set\n");
6173 encoder_enabled
= encoder
->get_hw_state(encoder
, &pipe
);
6174 I915_STATE_WARN(!encoder_enabled
, "encoder not enabled\n");
6175 if (I915_STATE_WARN_ON(!encoder
->base
.crtc
))
6178 crtc
= encoder
->base
.crtc
;
6180 I915_STATE_WARN(!crtc
->state
->enable
,
6181 "crtc not enabled\n");
6182 I915_STATE_WARN(!to_intel_crtc(crtc
)->active
, "crtc not active\n");
6183 I915_STATE_WARN(pipe
!= to_intel_crtc(crtc
)->pipe
,
6184 "encoder active on the wrong pipe\n");
6189 int intel_connector_init(struct intel_connector
*connector
)
6191 struct drm_connector_state
*connector_state
;
6193 connector_state
= kzalloc(sizeof *connector_state
, GFP_KERNEL
);
6194 if (!connector_state
)
6197 connector
->base
.state
= connector_state
;
6201 struct intel_connector
*intel_connector_alloc(void)
6203 struct intel_connector
*connector
;
6205 connector
= kzalloc(sizeof *connector
, GFP_KERNEL
);
6209 if (intel_connector_init(connector
) < 0) {
6217 /* Even simpler default implementation, if there's really no special case to
6219 void intel_connector_dpms(struct drm_connector
*connector
, int mode
)
6221 /* All the simple cases only support two dpms states. */
6222 if (mode
!= DRM_MODE_DPMS_ON
)
6223 mode
= DRM_MODE_DPMS_OFF
;
6225 if (mode
== connector
->dpms
)
6228 connector
->dpms
= mode
;
6230 /* Only need to change hw state when actually enabled */
6231 if (connector
->encoder
)
6232 intel_encoder_dpms(to_intel_encoder(connector
->encoder
), mode
);
6234 intel_modeset_check_state(connector
->dev
);
6237 /* Simple connector->get_hw_state implementation for encoders that support only
6238 * one connector and no cloning and hence the encoder state determines the state
6239 * of the connector. */
6240 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
6243 struct intel_encoder
*encoder
= connector
->encoder
;
6245 return encoder
->get_hw_state(encoder
, &pipe
);
6248 static int pipe_required_fdi_lanes(struct intel_crtc_state
*crtc_state
)
6250 if (crtc_state
->base
.enable
&& crtc_state
->has_pch_encoder
)
6251 return crtc_state
->fdi_lanes
;
6256 static int ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
6257 struct intel_crtc_state
*pipe_config
)
6259 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
6260 struct intel_crtc
*other_crtc
;
6261 struct intel_crtc_state
*other_crtc_state
;
6263 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6264 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6265 if (pipe_config
->fdi_lanes
> 4) {
6266 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6267 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6271 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
6272 if (pipe_config
->fdi_lanes
> 2) {
6273 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6274 pipe_config
->fdi_lanes
);
6281 if (INTEL_INFO(dev
)->num_pipes
== 2)
6284 /* Ivybridge 3 pipe is really complicated */
6289 if (pipe_config
->fdi_lanes
<= 2)
6292 other_crtc
= to_intel_crtc(intel_get_crtc_for_pipe(dev
, PIPE_C
));
6294 intel_atomic_get_crtc_state(state
, other_crtc
);
6295 if (IS_ERR(other_crtc_state
))
6296 return PTR_ERR(other_crtc_state
);
6298 if (pipe_required_fdi_lanes(other_crtc_state
) > 0) {
6299 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6300 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6305 if (pipe_config
->fdi_lanes
> 2) {
6306 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6307 pipe_name(pipe
), pipe_config
->fdi_lanes
);
6311 other_crtc
= to_intel_crtc(intel_get_crtc_for_pipe(dev
, PIPE_B
));
6313 intel_atomic_get_crtc_state(state
, other_crtc
);
6314 if (IS_ERR(other_crtc_state
))
6315 return PTR_ERR(other_crtc_state
);
6317 if (pipe_required_fdi_lanes(other_crtc_state
) > 2) {
6318 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6328 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
6329 struct intel_crtc_state
*pipe_config
)
6331 struct drm_device
*dev
= intel_crtc
->base
.dev
;
6332 struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6333 int lane
, link_bw
, fdi_dotclock
, ret
;
6334 bool needs_recompute
= false;
6337 /* FDI is a binary signal running at ~2.7GHz, encoding
6338 * each output octet as 10 bits. The actual frequency
6339 * is stored as a divider into a 100MHz clock, and the
6340 * mode pixel clock is stored in units of 1KHz.
6341 * Hence the bw of each lane in terms of the mode signal
6344 link_bw
= intel_fdi_link_freq(dev
) * MHz(100)/KHz(1)/10;
6346 fdi_dotclock
= adjusted_mode
->crtc_clock
;
6348 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
6349 pipe_config
->pipe_bpp
);
6351 pipe_config
->fdi_lanes
= lane
;
6353 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
6354 link_bw
, &pipe_config
->fdi_m_n
);
6356 ret
= ironlake_check_fdi_lanes(intel_crtc
->base
.dev
,
6357 intel_crtc
->pipe
, pipe_config
);
6358 if (ret
== -EINVAL
&& pipe_config
->pipe_bpp
> 6*3) {
6359 pipe_config
->pipe_bpp
-= 2*3;
6360 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6361 pipe_config
->pipe_bpp
);
6362 needs_recompute
= true;
6363 pipe_config
->bw_constrained
= true;
6368 if (needs_recompute
)
6374 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
6375 struct intel_crtc_state
*pipe_config
)
6377 pipe_config
->ips_enabled
= i915
.enable_ips
&&
6378 hsw_crtc_supports_ips(crtc
) &&
6379 pipe_config
->pipe_bpp
<= 24;
6382 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
6383 struct intel_crtc_state
*pipe_config
)
6385 struct drm_device
*dev
= crtc
->base
.dev
;
6386 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6387 struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
6390 /* FIXME should check pixel clock limits on all platforms */
6391 if (INTEL_INFO(dev
)->gen
< 4) {
6393 dev_priv
->display
.get_display_clock_speed(dev
);
6396 * Enable pixel doubling when the dot clock
6397 * is > 90% of the (display) core speed.
6399 * GDG double wide on either pipe,
6400 * otherwise pipe A only.
6402 if ((crtc
->pipe
== PIPE_A
|| IS_I915G(dev
)) &&
6403 adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10) {
6405 pipe_config
->double_wide
= true;
6408 if (adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10)
6413 * Pipe horizontal size must be even in:
6415 * - LVDS dual channel mode
6416 * - Double wide pipe
6418 if ((intel_pipe_will_have_type(pipe_config
, INTEL_OUTPUT_LVDS
) &&
6419 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
6420 pipe_config
->pipe_src_w
&= ~1;
6422 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6423 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6425 if ((INTEL_INFO(dev
)->gen
> 4 || IS_G4X(dev
)) &&
6426 adjusted_mode
->hsync_start
== adjusted_mode
->hdisplay
)
6430 hsw_compute_ips_config(crtc
, pipe_config
);
6432 if (pipe_config
->has_pch_encoder
)
6433 return ironlake_fdi_compute_config(crtc
, pipe_config
);
6435 /* FIXME: remove below call once atomic mode set is place and all crtc
6436 * related checks called from atomic_crtc_check function */
6438 DRM_DEBUG_KMS("intel_crtc = %p drm_state (pipe_config->base.state) = %p\n",
6439 crtc
, pipe_config
->base
.state
);
6440 ret
= intel_atomic_setup_scalers(dev
, crtc
, pipe_config
);
6445 static int skylake_get_display_clock_speed(struct drm_device
*dev
)
6447 struct drm_i915_private
*dev_priv
= to_i915(dev
);
6448 uint32_t lcpll1
= I915_READ(LCPLL1_CTL
);
6449 uint32_t cdctl
= I915_READ(CDCLK_CTL
);
6452 if (!(lcpll1
& LCPLL_PLL_ENABLE
)) {
6453 WARN(1, "LCPLL1 not enabled\n");
6454 return 24000; /* 24MHz is the cd freq with NSSC ref */
6457 if ((cdctl
& CDCLK_FREQ_SEL_MASK
) == CDCLK_FREQ_540
)
6460 linkrate
= (I915_READ(DPLL_CTRL1
) &
6461 DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
)) >> 1;
6463 if (linkrate
== DPLL_CTRL1_LINK_RATE_2160
||
6464 linkrate
== DPLL_CTRL1_LINK_RATE_1080
) {
6466 switch (cdctl
& CDCLK_FREQ_SEL_MASK
) {
6467 case CDCLK_FREQ_450_432
:
6469 case CDCLK_FREQ_337_308
:
6471 case CDCLK_FREQ_675_617
:
6474 WARN(1, "Unknown cd freq selection\n");
6478 switch (cdctl
& CDCLK_FREQ_SEL_MASK
) {
6479 case CDCLK_FREQ_450_432
:
6481 case CDCLK_FREQ_337_308
:
6483 case CDCLK_FREQ_675_617
:
6486 WARN(1, "Unknown cd freq selection\n");
6490 /* error case, do as if DPLL0 isn't enabled */
6494 static int broadwell_get_display_clock_speed(struct drm_device
*dev
)
6496 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6497 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
6498 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
6500 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
6502 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
6504 else if (freq
== LCPLL_CLK_FREQ_450
)
6506 else if (freq
== LCPLL_CLK_FREQ_54O_BDW
)
6508 else if (freq
== LCPLL_CLK_FREQ_337_5_BDW
)
6514 static int haswell_get_display_clock_speed(struct drm_device
*dev
)
6516 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6517 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
6518 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
6520 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
6522 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
6524 else if (freq
== LCPLL_CLK_FREQ_450
)
6526 else if (IS_HSW_ULT(dev
))
6532 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
6534 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6538 if (dev_priv
->hpll_freq
== 0)
6539 dev_priv
->hpll_freq
= valleyview_get_vco(dev_priv
);
6541 mutex_lock(&dev_priv
->dpio_lock
);
6542 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
6543 mutex_unlock(&dev_priv
->dpio_lock
);
6545 divider
= val
& DISPLAY_FREQUENCY_VALUES
;
6547 WARN((val
& DISPLAY_FREQUENCY_STATUS
) !=
6548 (divider
<< DISPLAY_FREQUENCY_STATUS_SHIFT
),
6549 "cdclk change in progress\n");
6551 return DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, divider
+ 1);
6554 static int ilk_get_display_clock_speed(struct drm_device
*dev
)
6559 static int i945_get_display_clock_speed(struct drm_device
*dev
)
6564 static int i915_get_display_clock_speed(struct drm_device
*dev
)
6569 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
6574 static int pnv_get_display_clock_speed(struct drm_device
*dev
)
6578 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
6580 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
6581 case GC_DISPLAY_CLOCK_267_MHZ_PNV
:
6583 case GC_DISPLAY_CLOCK_333_MHZ_PNV
:
6585 case GC_DISPLAY_CLOCK_444_MHZ_PNV
:
6587 case GC_DISPLAY_CLOCK_200_MHZ_PNV
:
6590 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc
);
6591 case GC_DISPLAY_CLOCK_133_MHZ_PNV
:
6593 case GC_DISPLAY_CLOCK_167_MHZ_PNV
:
6598 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
6602 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
6604 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
6607 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
6608 case GC_DISPLAY_CLOCK_333_MHZ
:
6611 case GC_DISPLAY_CLOCK_190_200_MHZ
:
6617 static int i865_get_display_clock_speed(struct drm_device
*dev
)
6622 static int i855_get_display_clock_speed(struct drm_device
*dev
)
6625 /* Assume that the hardware is in the high speed state. This
6626 * should be the default.
6628 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
6629 case GC_CLOCK_133_200
:
6630 case GC_CLOCK_100_200
:
6632 case GC_CLOCK_166_250
:
6634 case GC_CLOCK_100_133
:
6638 /* Shouldn't happen */
6642 static int i830_get_display_clock_speed(struct drm_device
*dev
)
6648 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
6650 while (*num
> DATA_LINK_M_N_MASK
||
6651 *den
> DATA_LINK_M_N_MASK
) {
6657 static void compute_m_n(unsigned int m
, unsigned int n
,
6658 uint32_t *ret_m
, uint32_t *ret_n
)
6660 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
6661 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
6662 intel_reduce_m_n_ratio(ret_m
, ret_n
);
6666 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
6667 int pixel_clock
, int link_clock
,
6668 struct intel_link_m_n
*m_n
)
6672 compute_m_n(bits_per_pixel
* pixel_clock
,
6673 link_clock
* nlanes
* 8,
6674 &m_n
->gmch_m
, &m_n
->gmch_n
);
6676 compute_m_n(pixel_clock
, link_clock
,
6677 &m_n
->link_m
, &m_n
->link_n
);
6680 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
6682 if (i915
.panel_use_ssc
>= 0)
6683 return i915
.panel_use_ssc
!= 0;
6684 return dev_priv
->vbt
.lvds_use_ssc
6685 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
6688 static int i9xx_get_refclk(const struct intel_crtc_state
*crtc_state
,
6691 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
6692 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6695 WARN_ON(!crtc_state
->base
.state
);
6697 if (IS_VALLEYVIEW(dev
) || IS_BROXTON(dev
)) {
6699 } else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6700 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
6701 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
6702 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
6703 } else if (!IS_GEN2(dev
)) {
6712 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
6714 return (1 << dpll
->n
) << 16 | dpll
->m2
;
6717 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
6719 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
6722 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
6723 struct intel_crtc_state
*crtc_state
,
6724 intel_clock_t
*reduced_clock
)
6726 struct drm_device
*dev
= crtc
->base
.dev
;
6729 if (IS_PINEVIEW(dev
)) {
6730 fp
= pnv_dpll_compute_fp(&crtc_state
->dpll
);
6732 fp2
= pnv_dpll_compute_fp(reduced_clock
);
6734 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
6736 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
6739 crtc_state
->dpll_hw_state
.fp0
= fp
;
6741 crtc
->lowfreq_avail
= false;
6742 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
6744 crtc_state
->dpll_hw_state
.fp1
= fp2
;
6745 crtc
->lowfreq_avail
= true;
6747 crtc_state
->dpll_hw_state
.fp1
= fp
;
6751 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
6757 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6758 * and set it to a reasonable value instead.
6760 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6761 reg_val
&= 0xffffff00;
6762 reg_val
|= 0x00000030;
6763 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6765 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6766 reg_val
&= 0x8cffffff;
6767 reg_val
= 0x8c000000;
6768 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6770 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
6771 reg_val
&= 0xffffff00;
6772 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
6774 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
6775 reg_val
&= 0x00ffffff;
6776 reg_val
|= 0xb0000000;
6777 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
6780 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
6781 struct intel_link_m_n
*m_n
)
6783 struct drm_device
*dev
= crtc
->base
.dev
;
6784 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6785 int pipe
= crtc
->pipe
;
6787 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6788 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
6789 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
6790 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
6793 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
6794 struct intel_link_m_n
*m_n
,
6795 struct intel_link_m_n
*m2_n2
)
6797 struct drm_device
*dev
= crtc
->base
.dev
;
6798 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6799 int pipe
= crtc
->pipe
;
6800 enum transcoder transcoder
= crtc
->config
->cpu_transcoder
;
6802 if (INTEL_INFO(dev
)->gen
>= 5) {
6803 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6804 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
6805 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
6806 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
6807 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
6808 * for gen < 8) and if DRRS is supported (to make sure the
6809 * registers are not unnecessarily accessed).
6811 if (m2_n2
&& (IS_CHERRYVIEW(dev
) || INTEL_INFO(dev
)->gen
< 8) &&
6812 crtc
->config
->has_drrs
) {
6813 I915_WRITE(PIPE_DATA_M2(transcoder
),
6814 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
6815 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
6816 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
6817 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
6820 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
6821 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
6822 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
6823 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
6827 void intel_dp_set_m_n(struct intel_crtc
*crtc
, enum link_m_n_set m_n
)
6829 struct intel_link_m_n
*dp_m_n
, *dp_m2_n2
= NULL
;
6832 dp_m_n
= &crtc
->config
->dp_m_n
;
6833 dp_m2_n2
= &crtc
->config
->dp_m2_n2
;
6834 } else if (m_n
== M2_N2
) {
6837 * M2_N2 registers are not supported. Hence m2_n2 divider value
6838 * needs to be programmed into M1_N1.
6840 dp_m_n
= &crtc
->config
->dp_m2_n2
;
6842 DRM_ERROR("Unsupported divider value\n");
6846 if (crtc
->config
->has_pch_encoder
)
6847 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
->dp_m_n
);
6849 intel_cpu_transcoder_set_m_n(crtc
, dp_m_n
, dp_m2_n2
);
6852 static void vlv_update_pll(struct intel_crtc
*crtc
,
6853 struct intel_crtc_state
*pipe_config
)
6858 * Enable DPIO clock input. We should never disable the reference
6859 * clock for pipe B, since VGA hotplug / manual detection depends
6862 dpll
= DPLL_EXT_BUFFER_ENABLE_VLV
| DPLL_REFA_CLK_ENABLE_VLV
|
6863 DPLL_VGA_MODE_DIS
| DPLL_INTEGRATED_CLOCK_VLV
;
6864 /* We should never disable this, set it here for state tracking */
6865 if (crtc
->pipe
== PIPE_B
)
6866 dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
6867 dpll
|= DPLL_VCO_ENABLE
;
6868 pipe_config
->dpll_hw_state
.dpll
= dpll
;
6870 dpll_md
= (pipe_config
->pixel_multiplier
- 1)
6871 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6872 pipe_config
->dpll_hw_state
.dpll_md
= dpll_md
;
6875 static void vlv_prepare_pll(struct intel_crtc
*crtc
,
6876 const struct intel_crtc_state
*pipe_config
)
6878 struct drm_device
*dev
= crtc
->base
.dev
;
6879 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6880 int pipe
= crtc
->pipe
;
6882 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
6883 u32 coreclk
, reg_val
;
6885 mutex_lock(&dev_priv
->dpio_lock
);
6887 bestn
= pipe_config
->dpll
.n
;
6888 bestm1
= pipe_config
->dpll
.m1
;
6889 bestm2
= pipe_config
->dpll
.m2
;
6890 bestp1
= pipe_config
->dpll
.p1
;
6891 bestp2
= pipe_config
->dpll
.p2
;
6893 /* See eDP HDMI DPIO driver vbios notes doc */
6895 /* PLL B needs special handling */
6897 vlv_pllb_recal_opamp(dev_priv
, pipe
);
6899 /* Set up Tx target for periodic Rcomp update */
6900 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
6902 /* Disable target IRef on PLL */
6903 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
6904 reg_val
&= 0x00ffffff;
6905 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
6907 /* Disable fast lock */
6908 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
6910 /* Set idtafcrecal before PLL is enabled */
6911 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
6912 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
6913 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
6914 mdiv
|= (1 << DPIO_K_SHIFT
);
6917 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6918 * but we don't support that).
6919 * Note: don't use the DAC post divider as it seems unstable.
6921 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
6922 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
6924 mdiv
|= DPIO_ENABLE_CALIBRATION
;
6925 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
6927 /* Set HBR and RBR LPF coefficients */
6928 if (pipe_config
->port_clock
== 162000 ||
6929 intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
) ||
6930 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
))
6931 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
6934 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
6937 if (pipe_config
->has_dp_encoder
) {
6938 /* Use SSC source */
6940 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6943 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6945 } else { /* HDMI or VGA */
6946 /* Use bend source */
6948 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6951 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
6955 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
6956 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
6957 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
6958 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))
6959 coreclk
|= 0x01000000;
6960 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
6962 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
6963 mutex_unlock(&dev_priv
->dpio_lock
);
6966 static void chv_update_pll(struct intel_crtc
*crtc
,
6967 struct intel_crtc_state
*pipe_config
)
6969 pipe_config
->dpll_hw_state
.dpll
= DPLL_SSC_REF_CLOCK_CHV
|
6970 DPLL_REFA_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
|
6972 if (crtc
->pipe
!= PIPE_A
)
6973 pipe_config
->dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
6975 pipe_config
->dpll_hw_state
.dpll_md
=
6976 (pipe_config
->pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
6979 static void chv_prepare_pll(struct intel_crtc
*crtc
,
6980 const struct intel_crtc_state
*pipe_config
)
6982 struct drm_device
*dev
= crtc
->base
.dev
;
6983 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6984 int pipe
= crtc
->pipe
;
6985 int dpll_reg
= DPLL(crtc
->pipe
);
6986 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
6987 u32 loopfilter
, tribuf_calcntr
;
6988 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
6992 bestn
= pipe_config
->dpll
.n
;
6993 bestm2_frac
= pipe_config
->dpll
.m2
& 0x3fffff;
6994 bestm1
= pipe_config
->dpll
.m1
;
6995 bestm2
= pipe_config
->dpll
.m2
>> 22;
6996 bestp1
= pipe_config
->dpll
.p1
;
6997 bestp2
= pipe_config
->dpll
.p2
;
6998 vco
= pipe_config
->dpll
.vco
;
7003 * Enable Refclk and SSC
7005 I915_WRITE(dpll_reg
,
7006 pipe_config
->dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
7008 mutex_lock(&dev_priv
->dpio_lock
);
7010 /* p1 and p2 divider */
7011 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
7012 5 << DPIO_CHV_S1_DIV_SHIFT
|
7013 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
7014 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
7015 1 << DPIO_CHV_K_DIV_SHIFT
);
7017 /* Feedback post-divider - m2 */
7018 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
7020 /* Feedback refclk divider - n and m1 */
7021 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
7022 DPIO_CHV_M1_DIV_BY_2
|
7023 1 << DPIO_CHV_N_DIV_SHIFT
);
7025 /* M2 fraction division */
7027 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
7029 /* M2 fraction division enable */
7030 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW3(port
));
7031 dpio_val
&= ~(DPIO_CHV_FEEDFWD_GAIN_MASK
| DPIO_CHV_FRAC_DIV_EN
);
7032 dpio_val
|= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
);
7034 dpio_val
|= DPIO_CHV_FRAC_DIV_EN
;
7035 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
), dpio_val
);
7037 /* Program digital lock detect threshold */
7038 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW9(port
));
7039 dpio_val
&= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK
|
7040 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
);
7041 dpio_val
|= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT
);
7043 dpio_val
|= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE
;
7044 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW9(port
), dpio_val
);
7047 if (vco
== 5400000) {
7048 loopfilter
|= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT
);
7049 loopfilter
|= (0x8 << DPIO_CHV_INT_COEFF_SHIFT
);
7050 loopfilter
|= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7051 tribuf_calcntr
= 0x9;
7052 } else if (vco
<= 6200000) {
7053 loopfilter
|= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT
);
7054 loopfilter
|= (0xB << DPIO_CHV_INT_COEFF_SHIFT
);
7055 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7056 tribuf_calcntr
= 0x9;
7057 } else if (vco
<= 6480000) {
7058 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
7059 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
7060 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7061 tribuf_calcntr
= 0x8;
7063 /* Not supported. Apply the same limits as in the max case */
7064 loopfilter
|= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT
);
7065 loopfilter
|= (0x9 << DPIO_CHV_INT_COEFF_SHIFT
);
7066 loopfilter
|= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT
);
7069 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
7071 dpio_val
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW8(port
));
7072 dpio_val
&= ~DPIO_CHV_TDC_TARGET_CNT_MASK
;
7073 dpio_val
|= (tribuf_calcntr
<< DPIO_CHV_TDC_TARGET_CNT_SHIFT
);
7074 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW8(port
), dpio_val
);
7077 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
7078 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
7081 mutex_unlock(&dev_priv
->dpio_lock
);
7085 * vlv_force_pll_on - forcibly enable just the PLL
7086 * @dev_priv: i915 private structure
7087 * @pipe: pipe PLL to enable
7088 * @dpll: PLL configuration
7090 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7091 * in cases where we need the PLL enabled even when @pipe is not going to
7094 void vlv_force_pll_on(struct drm_device
*dev
, enum pipe pipe
,
7095 const struct dpll
*dpll
)
7097 struct intel_crtc
*crtc
=
7098 to_intel_crtc(intel_get_crtc_for_pipe(dev
, pipe
));
7099 struct intel_crtc_state pipe_config
= {
7100 .base
.crtc
= &crtc
->base
,
7101 .pixel_multiplier
= 1,
7105 if (IS_CHERRYVIEW(dev
)) {
7106 chv_update_pll(crtc
, &pipe_config
);
7107 chv_prepare_pll(crtc
, &pipe_config
);
7108 chv_enable_pll(crtc
, &pipe_config
);
7110 vlv_update_pll(crtc
, &pipe_config
);
7111 vlv_prepare_pll(crtc
, &pipe_config
);
7112 vlv_enable_pll(crtc
, &pipe_config
);
7117 * vlv_force_pll_off - forcibly disable just the PLL
7118 * @dev_priv: i915 private structure
7119 * @pipe: pipe PLL to disable
7121 * Disable the PLL for @pipe. To be used in cases where we need
7122 * the PLL enabled even when @pipe is not going to be enabled.
7124 void vlv_force_pll_off(struct drm_device
*dev
, enum pipe pipe
)
7126 if (IS_CHERRYVIEW(dev
))
7127 chv_disable_pll(to_i915(dev
), pipe
);
7129 vlv_disable_pll(to_i915(dev
), pipe
);
7132 static void i9xx_update_pll(struct intel_crtc
*crtc
,
7133 struct intel_crtc_state
*crtc_state
,
7134 intel_clock_t
*reduced_clock
,
7137 struct drm_device
*dev
= crtc
->base
.dev
;
7138 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7141 struct dpll
*clock
= &crtc_state
->dpll
;
7143 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
7145 is_sdvo
= intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_SDVO
) ||
7146 intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_HDMI
);
7148 dpll
= DPLL_VGA_MODE_DIS
;
7150 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
))
7151 dpll
|= DPLLB_MODE_LVDS
;
7153 dpll
|= DPLLB_MODE_DAC_SERIAL
;
7155 if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
7156 dpll
|= (crtc_state
->pixel_multiplier
- 1)
7157 << SDVO_MULTIPLIER_SHIFT_HIRES
;
7161 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7163 if (crtc_state
->has_dp_encoder
)
7164 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7166 /* compute bitmask from p1 value */
7167 if (IS_PINEVIEW(dev
))
7168 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
7170 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7171 if (IS_G4X(dev
) && reduced_clock
)
7172 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
7174 switch (clock
->p2
) {
7176 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
7179 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
7182 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
7185 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
7188 if (INTEL_INFO(dev
)->gen
>= 4)
7189 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
7191 if (crtc_state
->sdvo_tv_clock
)
7192 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
7193 else if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
7194 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
7195 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7197 dpll
|= PLL_REF_INPUT_DREFCLK
;
7199 dpll
|= DPLL_VCO_ENABLE
;
7200 crtc_state
->dpll_hw_state
.dpll
= dpll
;
7202 if (INTEL_INFO(dev
)->gen
>= 4) {
7203 u32 dpll_md
= (crtc_state
->pixel_multiplier
- 1)
7204 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
7205 crtc_state
->dpll_hw_state
.dpll_md
= dpll_md
;
7209 static void i8xx_update_pll(struct intel_crtc
*crtc
,
7210 struct intel_crtc_state
*crtc_state
,
7211 intel_clock_t
*reduced_clock
,
7214 struct drm_device
*dev
= crtc
->base
.dev
;
7215 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7217 struct dpll
*clock
= &crtc_state
->dpll
;
7219 i9xx_update_pll_dividers(crtc
, crtc_state
, reduced_clock
);
7221 dpll
= DPLL_VGA_MODE_DIS
;
7223 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
)) {
7224 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7227 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
7229 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7231 dpll
|= PLL_P2_DIVIDE_BY_4
;
7234 if (!IS_I830(dev
) && intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_DVO
))
7235 dpll
|= DPLL_DVO_2X_MODE
;
7237 if (intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
) &&
7238 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
7239 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7241 dpll
|= PLL_REF_INPUT_DREFCLK
;
7243 dpll
|= DPLL_VCO_ENABLE
;
7244 crtc_state
->dpll_hw_state
.dpll
= dpll
;
7247 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
7249 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7250 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7251 enum pipe pipe
= intel_crtc
->pipe
;
7252 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
7253 struct drm_display_mode
*adjusted_mode
=
7254 &intel_crtc
->config
->base
.adjusted_mode
;
7255 uint32_t crtc_vtotal
, crtc_vblank_end
;
7258 /* We need to be careful not to changed the adjusted mode, for otherwise
7259 * the hw state checker will get angry at the mismatch. */
7260 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
7261 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
7263 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
7264 /* the chip adds 2 halflines automatically */
7266 crtc_vblank_end
-= 1;
7268 if (intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
7269 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
7271 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
7272 adjusted_mode
->crtc_htotal
/ 2;
7274 vsyncshift
+= adjusted_mode
->crtc_htotal
;
7277 if (INTEL_INFO(dev
)->gen
> 3)
7278 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
7280 I915_WRITE(HTOTAL(cpu_transcoder
),
7281 (adjusted_mode
->crtc_hdisplay
- 1) |
7282 ((adjusted_mode
->crtc_htotal
- 1) << 16));
7283 I915_WRITE(HBLANK(cpu_transcoder
),
7284 (adjusted_mode
->crtc_hblank_start
- 1) |
7285 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
7286 I915_WRITE(HSYNC(cpu_transcoder
),
7287 (adjusted_mode
->crtc_hsync_start
- 1) |
7288 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
7290 I915_WRITE(VTOTAL(cpu_transcoder
),
7291 (adjusted_mode
->crtc_vdisplay
- 1) |
7292 ((crtc_vtotal
- 1) << 16));
7293 I915_WRITE(VBLANK(cpu_transcoder
),
7294 (adjusted_mode
->crtc_vblank_start
- 1) |
7295 ((crtc_vblank_end
- 1) << 16));
7296 I915_WRITE(VSYNC(cpu_transcoder
),
7297 (adjusted_mode
->crtc_vsync_start
- 1) |
7298 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
7300 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7301 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7302 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7304 if (IS_HASWELL(dev
) && cpu_transcoder
== TRANSCODER_EDP
&&
7305 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
7306 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
7308 /* pipesrc controls the size that is scaled from, which should
7309 * always be the user's requested size.
7311 I915_WRITE(PIPESRC(pipe
),
7312 ((intel_crtc
->config
->pipe_src_w
- 1) << 16) |
7313 (intel_crtc
->config
->pipe_src_h
- 1));
7316 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
7317 struct intel_crtc_state
*pipe_config
)
7319 struct drm_device
*dev
= crtc
->base
.dev
;
7320 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7321 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
7324 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
7325 pipe_config
->base
.adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
7326 pipe_config
->base
.adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
7327 tmp
= I915_READ(HBLANK(cpu_transcoder
));
7328 pipe_config
->base
.adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
7329 pipe_config
->base
.adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
7330 tmp
= I915_READ(HSYNC(cpu_transcoder
));
7331 pipe_config
->base
.adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
7332 pipe_config
->base
.adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
7334 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
7335 pipe_config
->base
.adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
7336 pipe_config
->base
.adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
7337 tmp
= I915_READ(VBLANK(cpu_transcoder
));
7338 pipe_config
->base
.adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
7339 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
7340 tmp
= I915_READ(VSYNC(cpu_transcoder
));
7341 pipe_config
->base
.adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
7342 pipe_config
->base
.adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
7344 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
7345 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
7346 pipe_config
->base
.adjusted_mode
.crtc_vtotal
+= 1;
7347 pipe_config
->base
.adjusted_mode
.crtc_vblank_end
+= 1;
7350 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
7351 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
7352 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
7354 pipe_config
->base
.mode
.vdisplay
= pipe_config
->pipe_src_h
;
7355 pipe_config
->base
.mode
.hdisplay
= pipe_config
->pipe_src_w
;
7358 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
7359 struct intel_crtc_state
*pipe_config
)
7361 mode
->hdisplay
= pipe_config
->base
.adjusted_mode
.crtc_hdisplay
;
7362 mode
->htotal
= pipe_config
->base
.adjusted_mode
.crtc_htotal
;
7363 mode
->hsync_start
= pipe_config
->base
.adjusted_mode
.crtc_hsync_start
;
7364 mode
->hsync_end
= pipe_config
->base
.adjusted_mode
.crtc_hsync_end
;
7366 mode
->vdisplay
= pipe_config
->base
.adjusted_mode
.crtc_vdisplay
;
7367 mode
->vtotal
= pipe_config
->base
.adjusted_mode
.crtc_vtotal
;
7368 mode
->vsync_start
= pipe_config
->base
.adjusted_mode
.crtc_vsync_start
;
7369 mode
->vsync_end
= pipe_config
->base
.adjusted_mode
.crtc_vsync_end
;
7371 mode
->flags
= pipe_config
->base
.adjusted_mode
.flags
;
7373 mode
->clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
;
7374 mode
->flags
|= pipe_config
->base
.adjusted_mode
.flags
;
7377 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
7379 struct drm_device
*dev
= intel_crtc
->base
.dev
;
7380 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7385 if ((intel_crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
7386 (intel_crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
7387 pipeconf
|= I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
;
7389 if (intel_crtc
->config
->double_wide
)
7390 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
7392 /* only g4x and later have fancy bpc/dither controls */
7393 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
7394 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7395 if (intel_crtc
->config
->dither
&& intel_crtc
->config
->pipe_bpp
!= 30)
7396 pipeconf
|= PIPECONF_DITHER_EN
|
7397 PIPECONF_DITHER_TYPE_SP
;
7399 switch (intel_crtc
->config
->pipe_bpp
) {
7401 pipeconf
|= PIPECONF_6BPC
;
7404 pipeconf
|= PIPECONF_8BPC
;
7407 pipeconf
|= PIPECONF_10BPC
;
7410 /* Case prevented by intel_choose_pipe_bpp_dither. */
7415 if (HAS_PIPE_CXSR(dev
)) {
7416 if (intel_crtc
->lowfreq_avail
) {
7417 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
7418 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
7420 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
7424 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
7425 if (INTEL_INFO(dev
)->gen
< 4 ||
7426 intel_pipe_has_type(intel_crtc
, INTEL_OUTPUT_SDVO
))
7427 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
7429 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
7431 pipeconf
|= PIPECONF_PROGRESSIVE
;
7433 if (IS_VALLEYVIEW(dev
) && intel_crtc
->config
->limited_color_range
)
7434 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
7436 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
7437 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
7440 static int i9xx_crtc_compute_clock(struct intel_crtc
*crtc
,
7441 struct intel_crtc_state
*crtc_state
)
7443 struct drm_device
*dev
= crtc
->base
.dev
;
7444 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7445 int refclk
, num_connectors
= 0;
7446 intel_clock_t clock
, reduced_clock
;
7447 bool ok
, has_reduced_clock
= false;
7448 bool is_lvds
= false, is_dsi
= false;
7449 struct intel_encoder
*encoder
;
7450 const intel_limit_t
*limit
;
7451 struct drm_atomic_state
*state
= crtc_state
->base
.state
;
7452 struct drm_connector
*connector
;
7453 struct drm_connector_state
*connector_state
;
7456 memset(&crtc_state
->dpll_hw_state
, 0,
7457 sizeof(crtc_state
->dpll_hw_state
));
7459 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
7460 if (connector_state
->crtc
!= &crtc
->base
)
7463 encoder
= to_intel_encoder(connector_state
->best_encoder
);
7465 switch (encoder
->type
) {
7466 case INTEL_OUTPUT_LVDS
:
7469 case INTEL_OUTPUT_DSI
:
7482 if (!crtc_state
->clock_set
) {
7483 refclk
= i9xx_get_refclk(crtc_state
, num_connectors
);
7486 * Returns a set of divisors for the desired target clock with
7487 * the given refclk, or FALSE. The returned values represent
7488 * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
7491 limit
= intel_limit(crtc_state
, refclk
);
7492 ok
= dev_priv
->display
.find_dpll(limit
, crtc_state
,
7493 crtc_state
->port_clock
,
7494 refclk
, NULL
, &clock
);
7496 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7500 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
7502 * Ensure we match the reduced clock's P to the target
7503 * clock. If the clocks don't match, we can't switch
7504 * the display clock by using the FP0/FP1. In such case
7505 * we will disable the LVDS downclock feature.
7508 dev_priv
->display
.find_dpll(limit
, crtc_state
,
7509 dev_priv
->lvds_downclock
,
7513 /* Compat-code for transition, will disappear. */
7514 crtc_state
->dpll
.n
= clock
.n
;
7515 crtc_state
->dpll
.m1
= clock
.m1
;
7516 crtc_state
->dpll
.m2
= clock
.m2
;
7517 crtc_state
->dpll
.p1
= clock
.p1
;
7518 crtc_state
->dpll
.p2
= clock
.p2
;
7522 i8xx_update_pll(crtc
, crtc_state
,
7523 has_reduced_clock
? &reduced_clock
: NULL
,
7525 } else if (IS_CHERRYVIEW(dev
)) {
7526 chv_update_pll(crtc
, crtc_state
);
7527 } else if (IS_VALLEYVIEW(dev
)) {
7528 vlv_update_pll(crtc
, crtc_state
);
7530 i9xx_update_pll(crtc
, crtc_state
,
7531 has_reduced_clock
? &reduced_clock
: NULL
,
7538 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
7539 struct intel_crtc_state
*pipe_config
)
7541 struct drm_device
*dev
= crtc
->base
.dev
;
7542 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7545 if (INTEL_INFO(dev
)->gen
<= 3 && (IS_I830(dev
) || !IS_MOBILE(dev
)))
7548 tmp
= I915_READ(PFIT_CONTROL
);
7549 if (!(tmp
& PFIT_ENABLE
))
7552 /* Check whether the pfit is attached to our pipe. */
7553 if (INTEL_INFO(dev
)->gen
< 4) {
7554 if (crtc
->pipe
!= PIPE_B
)
7557 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
7561 pipe_config
->gmch_pfit
.control
= tmp
;
7562 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
7563 if (INTEL_INFO(dev
)->gen
< 5)
7564 pipe_config
->gmch_pfit
.lvds_border_bits
=
7565 I915_READ(LVDS
) & LVDS_BORDER_ENABLE
;
7568 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
7569 struct intel_crtc_state
*pipe_config
)
7571 struct drm_device
*dev
= crtc
->base
.dev
;
7572 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7573 int pipe
= pipe_config
->cpu_transcoder
;
7574 intel_clock_t clock
;
7576 int refclk
= 100000;
7578 /* In case of MIPI DPLL will not even be used */
7579 if (!(pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
))
7582 mutex_lock(&dev_priv
->dpio_lock
);
7583 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
7584 mutex_unlock(&dev_priv
->dpio_lock
);
7586 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
7587 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
7588 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
7589 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
7590 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
7592 vlv_clock(refclk
, &clock
);
7594 /* clock.dot is the fast clock */
7595 pipe_config
->port_clock
= clock
.dot
/ 5;
7599 i9xx_get_initial_plane_config(struct intel_crtc
*crtc
,
7600 struct intel_initial_plane_config
*plane_config
)
7602 struct drm_device
*dev
= crtc
->base
.dev
;
7603 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7604 u32 val
, base
, offset
;
7605 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
7606 int fourcc
, pixel_format
;
7607 unsigned int aligned_height
;
7608 struct drm_framebuffer
*fb
;
7609 struct intel_framebuffer
*intel_fb
;
7611 val
= I915_READ(DSPCNTR(plane
));
7612 if (!(val
& DISPLAY_PLANE_ENABLE
))
7615 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
7617 DRM_DEBUG_KMS("failed to alloc fb\n");
7621 fb
= &intel_fb
->base
;
7623 if (INTEL_INFO(dev
)->gen
>= 4) {
7624 if (val
& DISPPLANE_TILED
) {
7625 plane_config
->tiling
= I915_TILING_X
;
7626 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
7630 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
7631 fourcc
= i9xx_format_to_fourcc(pixel_format
);
7632 fb
->pixel_format
= fourcc
;
7633 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
7635 if (INTEL_INFO(dev
)->gen
>= 4) {
7636 if (plane_config
->tiling
)
7637 offset
= I915_READ(DSPTILEOFF(plane
));
7639 offset
= I915_READ(DSPLINOFF(plane
));
7640 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
7642 base
= I915_READ(DSPADDR(plane
));
7644 plane_config
->base
= base
;
7646 val
= I915_READ(PIPESRC(pipe
));
7647 fb
->width
= ((val
>> 16) & 0xfff) + 1;
7648 fb
->height
= ((val
>> 0) & 0xfff) + 1;
7650 val
= I915_READ(DSPSTRIDE(pipe
));
7651 fb
->pitches
[0] = val
& 0xffffffc0;
7653 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
7657 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
7659 DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7660 pipe_name(pipe
), plane
, fb
->width
, fb
->height
,
7661 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
7662 plane_config
->size
);
7664 plane_config
->fb
= intel_fb
;
7667 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
7668 struct intel_crtc_state
*pipe_config
)
7670 struct drm_device
*dev
= crtc
->base
.dev
;
7671 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7672 int pipe
= pipe_config
->cpu_transcoder
;
7673 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
7674 intel_clock_t clock
;
7675 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
;
7676 int refclk
= 100000;
7678 mutex_lock(&dev_priv
->dpio_lock
);
7679 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
7680 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
7681 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
7682 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
7683 mutex_unlock(&dev_priv
->dpio_lock
);
7685 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
7686 clock
.m2
= ((pll_dw0
& 0xff) << 22) | (pll_dw2
& 0x3fffff);
7687 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
7688 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
7689 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
7691 chv_clock(refclk
, &clock
);
7693 /* clock.dot is the fast clock */
7694 pipe_config
->port_clock
= clock
.dot
/ 5;
7697 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
7698 struct intel_crtc_state
*pipe_config
)
7700 struct drm_device
*dev
= crtc
->base
.dev
;
7701 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7704 if (!intel_display_power_is_enabled(dev_priv
,
7705 POWER_DOMAIN_PIPE(crtc
->pipe
)))
7708 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7709 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
7711 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
7712 if (!(tmp
& PIPECONF_ENABLE
))
7715 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
7716 switch (tmp
& PIPECONF_BPC_MASK
) {
7718 pipe_config
->pipe_bpp
= 18;
7721 pipe_config
->pipe_bpp
= 24;
7723 case PIPECONF_10BPC
:
7724 pipe_config
->pipe_bpp
= 30;
7731 if (IS_VALLEYVIEW(dev
) && (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
7732 pipe_config
->limited_color_range
= true;
7734 if (INTEL_INFO(dev
)->gen
< 4)
7735 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
7737 intel_get_pipe_timings(crtc
, pipe_config
);
7739 i9xx_get_pfit_config(crtc
, pipe_config
);
7741 if (INTEL_INFO(dev
)->gen
>= 4) {
7742 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
7743 pipe_config
->pixel_multiplier
=
7744 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
7745 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
7746 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
7747 } else if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
7748 tmp
= I915_READ(DPLL(crtc
->pipe
));
7749 pipe_config
->pixel_multiplier
=
7750 ((tmp
& SDVO_MULTIPLIER_MASK
)
7751 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
7753 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7754 * port and will be fixed up in the encoder->get_config
7756 pipe_config
->pixel_multiplier
= 1;
7758 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
7759 if (!IS_VALLEYVIEW(dev
)) {
7761 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
7762 * on 830. Filter it out here so that we don't
7763 * report errors due to that.
7766 pipe_config
->dpll_hw_state
.dpll
&= ~DPLL_DVO_2X_MODE
;
7768 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
7769 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
7771 /* Mask out read-only status bits. */
7772 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
7773 DPLL_PORTC_READY_MASK
|
7774 DPLL_PORTB_READY_MASK
);
7777 if (IS_CHERRYVIEW(dev
))
7778 chv_crtc_clock_get(crtc
, pipe_config
);
7779 else if (IS_VALLEYVIEW(dev
))
7780 vlv_crtc_clock_get(crtc
, pipe_config
);
7782 i9xx_crtc_clock_get(crtc
, pipe_config
);
7787 static void ironlake_init_pch_refclk(struct drm_device
*dev
)
7789 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7790 struct intel_encoder
*encoder
;
7792 bool has_lvds
= false;
7793 bool has_cpu_edp
= false;
7794 bool has_panel
= false;
7795 bool has_ck505
= false;
7796 bool can_ssc
= false;
7798 /* We need to take the global config into account */
7799 for_each_intel_encoder(dev
, encoder
) {
7800 switch (encoder
->type
) {
7801 case INTEL_OUTPUT_LVDS
:
7805 case INTEL_OUTPUT_EDP
:
7807 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
7815 if (HAS_PCH_IBX(dev
)) {
7816 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
7817 can_ssc
= has_ck505
;
7823 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
7824 has_panel
, has_lvds
, has_ck505
);
7826 /* Ironlake: try to setup display ref clock before DPLL
7827 * enabling. This is only under driver's control after
7828 * PCH B stepping, previous chipset stepping should be
7829 * ignoring this setting.
7831 val
= I915_READ(PCH_DREF_CONTROL
);
7833 /* As we must carefully and slowly disable/enable each source in turn,
7834 * compute the final state we want first and check if we need to
7835 * make any changes at all.
7838 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
7840 final
|= DREF_NONSPREAD_CK505_ENABLE
;
7842 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
7844 final
&= ~DREF_SSC_SOURCE_MASK
;
7845 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7846 final
&= ~DREF_SSC1_ENABLE
;
7849 final
|= DREF_SSC_SOURCE_ENABLE
;
7851 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
7852 final
|= DREF_SSC1_ENABLE
;
7855 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
7856 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
7858 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
7860 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7862 final
|= DREF_SSC_SOURCE_DISABLE
;
7863 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7869 /* Always enable nonspread source */
7870 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
7873 val
|= DREF_NONSPREAD_CK505_ENABLE
;
7875 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
7878 val
&= ~DREF_SSC_SOURCE_MASK
;
7879 val
|= DREF_SSC_SOURCE_ENABLE
;
7881 /* SSC must be turned on before enabling the CPU output */
7882 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
7883 DRM_DEBUG_KMS("Using SSC on panel\n");
7884 val
|= DREF_SSC1_ENABLE
;
7886 val
&= ~DREF_SSC1_ENABLE
;
7888 /* Get SSC going before enabling the outputs */
7889 I915_WRITE(PCH_DREF_CONTROL
, val
);
7890 POSTING_READ(PCH_DREF_CONTROL
);
7893 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7895 /* Enable CPU source on CPU attached eDP */
7897 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
7898 DRM_DEBUG_KMS("Using SSC on eDP\n");
7899 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
7901 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
7903 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7905 I915_WRITE(PCH_DREF_CONTROL
, val
);
7906 POSTING_READ(PCH_DREF_CONTROL
);
7909 DRM_DEBUG_KMS("Disabling SSC entirely\n");
7911 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
7913 /* Turn off CPU output */
7914 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
7916 I915_WRITE(PCH_DREF_CONTROL
, val
);
7917 POSTING_READ(PCH_DREF_CONTROL
);
7920 /* Turn off the SSC source */
7921 val
&= ~DREF_SSC_SOURCE_MASK
;
7922 val
|= DREF_SSC_SOURCE_DISABLE
;
7925 val
&= ~DREF_SSC1_ENABLE
;
7927 I915_WRITE(PCH_DREF_CONTROL
, val
);
7928 POSTING_READ(PCH_DREF_CONTROL
);
7932 BUG_ON(val
!= final
);
7935 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
7939 tmp
= I915_READ(SOUTH_CHICKEN2
);
7940 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
7941 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
7943 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2
) &
7944 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
7945 DRM_ERROR("FDI mPHY reset assert timeout\n");
7947 tmp
= I915_READ(SOUTH_CHICKEN2
);
7948 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
7949 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
7951 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2
) &
7952 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
7953 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
7956 /* WaMPhyProgramming:hsw */
7957 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
7961 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
7962 tmp
&= ~(0xFF << 24);
7963 tmp
|= (0x12 << 24);
7964 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
7966 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
7968 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
7970 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
7972 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
7974 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
7975 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
7976 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
7978 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
7979 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
7980 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
7982 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
7985 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
7987 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
7990 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
7992 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
7995 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
7997 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
8000 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
8002 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
8003 tmp
&= ~(0xFF << 16);
8004 tmp
|= (0x1C << 16);
8005 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
8007 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
8008 tmp
&= ~(0xFF << 16);
8009 tmp
|= (0x1C << 16);
8010 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
8012 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
8014 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
8016 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
8018 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
8020 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
8021 tmp
&= ~(0xF << 28);
8023 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
8025 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
8026 tmp
&= ~(0xF << 28);
8028 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
8031 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8032 * Programming" based on the parameters passed:
8033 * - Sequence to enable CLKOUT_DP
8034 * - Sequence to enable CLKOUT_DP without spread
8035 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8037 static void lpt_enable_clkout_dp(struct drm_device
*dev
, bool with_spread
,
8040 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8043 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
8045 if (WARN(dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
&&
8046 with_fdi
, "LP PCH doesn't have FDI\n"))
8049 mutex_lock(&dev_priv
->dpio_lock
);
8051 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8052 tmp
&= ~SBI_SSCCTL_DISABLE
;
8053 tmp
|= SBI_SSCCTL_PATHALT
;
8054 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8059 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8060 tmp
&= ~SBI_SSCCTL_PATHALT
;
8061 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8064 lpt_reset_fdi_mphy(dev_priv
);
8065 lpt_program_fdi_mphy(dev_priv
);
8069 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
8070 SBI_GEN0
: SBI_DBUFF0
;
8071 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
8072 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
8073 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
8075 mutex_unlock(&dev_priv
->dpio_lock
);
8078 /* Sequence to disable CLKOUT_DP */
8079 static void lpt_disable_clkout_dp(struct drm_device
*dev
)
8081 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8084 mutex_lock(&dev_priv
->dpio_lock
);
8086 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
8087 SBI_GEN0
: SBI_DBUFF0
;
8088 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
8089 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
8090 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
8092 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
8093 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
8094 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
8095 tmp
|= SBI_SSCCTL_PATHALT
;
8096 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8099 tmp
|= SBI_SSCCTL_DISABLE
;
8100 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
8103 mutex_unlock(&dev_priv
->dpio_lock
);
8106 static void lpt_init_pch_refclk(struct drm_device
*dev
)
8108 struct intel_encoder
*encoder
;
8109 bool has_vga
= false;
8111 for_each_intel_encoder(dev
, encoder
) {
8112 switch (encoder
->type
) {
8113 case INTEL_OUTPUT_ANALOG
:
8122 lpt_enable_clkout_dp(dev
, true, true);
8124 lpt_disable_clkout_dp(dev
);
8128 * Initialize reference clocks when the driver loads
8130 void intel_init_pch_refclk(struct drm_device
*dev
)
8132 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
8133 ironlake_init_pch_refclk(dev
);
8134 else if (HAS_PCH_LPT(dev
))
8135 lpt_init_pch_refclk(dev
);
8138 static int ironlake_get_refclk(struct intel_crtc_state
*crtc_state
)
8140 struct drm_device
*dev
= crtc_state
->base
.crtc
->dev
;
8141 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8142 struct drm_atomic_state
*state
= crtc_state
->base
.state
;
8143 struct drm_connector
*connector
;
8144 struct drm_connector_state
*connector_state
;
8145 struct intel_encoder
*encoder
;
8146 int num_connectors
= 0, i
;
8147 bool is_lvds
= false;
8149 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
8150 if (connector_state
->crtc
!= crtc_state
->base
.crtc
)
8153 encoder
= to_intel_encoder(connector_state
->best_encoder
);
8155 switch (encoder
->type
) {
8156 case INTEL_OUTPUT_LVDS
:
8165 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
8166 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8167 dev_priv
->vbt
.lvds_ssc_freq
);
8168 return dev_priv
->vbt
.lvds_ssc_freq
;
8174 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
8176 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
8177 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8178 int pipe
= intel_crtc
->pipe
;
8183 switch (intel_crtc
->config
->pipe_bpp
) {
8185 val
|= PIPECONF_6BPC
;
8188 val
|= PIPECONF_8BPC
;
8191 val
|= PIPECONF_10BPC
;
8194 val
|= PIPECONF_12BPC
;
8197 /* Case prevented by intel_choose_pipe_bpp_dither. */
8201 if (intel_crtc
->config
->dither
)
8202 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
8204 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8205 val
|= PIPECONF_INTERLACED_ILK
;
8207 val
|= PIPECONF_PROGRESSIVE
;
8209 if (intel_crtc
->config
->limited_color_range
)
8210 val
|= PIPECONF_COLOR_RANGE_SELECT
;
8212 I915_WRITE(PIPECONF(pipe
), val
);
8213 POSTING_READ(PIPECONF(pipe
));
8217 * Set up the pipe CSC unit.
8219 * Currently only full range RGB to limited range RGB conversion
8220 * is supported, but eventually this should handle various
8221 * RGB<->YCbCr scenarios as well.
8223 static void intel_set_pipe_csc(struct drm_crtc
*crtc
)
8225 struct drm_device
*dev
= crtc
->dev
;
8226 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8227 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8228 int pipe
= intel_crtc
->pipe
;
8229 uint16_t coeff
= 0x7800; /* 1.0 */
8232 * TODO: Check what kind of values actually come out of the pipe
8233 * with these coeff/postoff values and adjust to get the best
8234 * accuracy. Perhaps we even need to take the bpc value into
8238 if (intel_crtc
->config
->limited_color_range
)
8239 coeff
= ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
8242 * GY/GU and RY/RU should be the other way around according
8243 * to BSpec, but reality doesn't agree. Just set them up in
8244 * a way that results in the correct picture.
8246 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe
), coeff
<< 16);
8247 I915_WRITE(PIPE_CSC_COEFF_BY(pipe
), 0);
8249 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe
), coeff
);
8250 I915_WRITE(PIPE_CSC_COEFF_BU(pipe
), 0);
8252 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe
), 0);
8253 I915_WRITE(PIPE_CSC_COEFF_BV(pipe
), coeff
<< 16);
8255 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe
), 0);
8256 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe
), 0);
8257 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe
), 0);
8259 if (INTEL_INFO(dev
)->gen
> 6) {
8260 uint16_t postoff
= 0;
8262 if (intel_crtc
->config
->limited_color_range
)
8263 postoff
= (16 * (1 << 12) / 255) & 0x1fff;
8265 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe
), postoff
);
8266 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe
), postoff
);
8267 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe
), postoff
);
8269 I915_WRITE(PIPE_CSC_MODE(pipe
), 0);
8271 uint32_t mode
= CSC_MODE_YUV_TO_RGB
;
8273 if (intel_crtc
->config
->limited_color_range
)
8274 mode
|= CSC_BLACK_SCREEN_OFFSET
;
8276 I915_WRITE(PIPE_CSC_MODE(pipe
), mode
);
8280 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
8282 struct drm_device
*dev
= crtc
->dev
;
8283 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8284 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8285 enum pipe pipe
= intel_crtc
->pipe
;
8286 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
8291 if (IS_HASWELL(dev
) && intel_crtc
->config
->dither
)
8292 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
8294 if (intel_crtc
->config
->base
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
8295 val
|= PIPECONF_INTERLACED_ILK
;
8297 val
|= PIPECONF_PROGRESSIVE
;
8299 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
8300 POSTING_READ(PIPECONF(cpu_transcoder
));
8302 I915_WRITE(GAMMA_MODE(intel_crtc
->pipe
), GAMMA_MODE_MODE_8BIT
);
8303 POSTING_READ(GAMMA_MODE(intel_crtc
->pipe
));
8305 if (IS_BROADWELL(dev
) || INTEL_INFO(dev
)->gen
>= 9) {
8308 switch (intel_crtc
->config
->pipe_bpp
) {
8310 val
|= PIPEMISC_DITHER_6_BPC
;
8313 val
|= PIPEMISC_DITHER_8_BPC
;
8316 val
|= PIPEMISC_DITHER_10_BPC
;
8319 val
|= PIPEMISC_DITHER_12_BPC
;
8322 /* Case prevented by pipe_config_set_bpp. */
8326 if (intel_crtc
->config
->dither
)
8327 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
8329 I915_WRITE(PIPEMISC(pipe
), val
);
8333 static bool ironlake_compute_clocks(struct drm_crtc
*crtc
,
8334 struct intel_crtc_state
*crtc_state
,
8335 intel_clock_t
*clock
,
8336 bool *has_reduced_clock
,
8337 intel_clock_t
*reduced_clock
)
8339 struct drm_device
*dev
= crtc
->dev
;
8340 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8342 const intel_limit_t
*limit
;
8343 bool ret
, is_lvds
= false;
8345 is_lvds
= intel_pipe_will_have_type(crtc_state
, INTEL_OUTPUT_LVDS
);
8347 refclk
= ironlake_get_refclk(crtc_state
);
8350 * Returns a set of divisors for the desired target clock with the given
8351 * refclk, or FALSE. The returned values represent the clock equation:
8352 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
8354 limit
= intel_limit(crtc_state
, refclk
);
8355 ret
= dev_priv
->display
.find_dpll(limit
, crtc_state
,
8356 crtc_state
->port_clock
,
8357 refclk
, NULL
, clock
);
8361 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
8363 * Ensure we match the reduced clock's P to the target clock.
8364 * If the clocks don't match, we can't switch the display clock
8365 * by using the FP0/FP1. In such case we will disable the LVDS
8366 * downclock feature.
8368 *has_reduced_clock
=
8369 dev_priv
->display
.find_dpll(limit
, crtc_state
,
8370 dev_priv
->lvds_downclock
,
8378 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
8381 * Account for spread spectrum to avoid
8382 * oversubscribing the link. Max center spread
8383 * is 2.5%; use 5% for safety's sake.
8385 u32 bps
= target_clock
* bpp
* 21 / 20;
8386 return DIV_ROUND_UP(bps
, link_bw
* 8);
8389 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
8391 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
8394 static uint32_t ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
8395 struct intel_crtc_state
*crtc_state
,
8397 intel_clock_t
*reduced_clock
, u32
*fp2
)
8399 struct drm_crtc
*crtc
= &intel_crtc
->base
;
8400 struct drm_device
*dev
= crtc
->dev
;
8401 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8402 struct drm_atomic_state
*state
= crtc_state
->base
.state
;
8403 struct drm_connector
*connector
;
8404 struct drm_connector_state
*connector_state
;
8405 struct intel_encoder
*encoder
;
8407 int factor
, num_connectors
= 0, i
;
8408 bool is_lvds
= false, is_sdvo
= false;
8410 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
8411 if (connector_state
->crtc
!= crtc_state
->base
.crtc
)
8414 encoder
= to_intel_encoder(connector_state
->best_encoder
);
8416 switch (encoder
->type
) {
8417 case INTEL_OUTPUT_LVDS
:
8420 case INTEL_OUTPUT_SDVO
:
8421 case INTEL_OUTPUT_HDMI
:
8431 /* Enable autotuning of the PLL clock (if permissible) */
8434 if ((intel_panel_use_ssc(dev_priv
) &&
8435 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
8436 (HAS_PCH_IBX(dev
) && intel_is_dual_link_lvds(dev
)))
8438 } else if (crtc_state
->sdvo_tv_clock
)
8441 if (ironlake_needs_fb_cb_tune(&crtc_state
->dpll
, factor
))
8444 if (fp2
&& (reduced_clock
->m
< factor
* reduced_clock
->n
))
8450 dpll
|= DPLLB_MODE_LVDS
;
8452 dpll
|= DPLLB_MODE_DAC_SERIAL
;
8454 dpll
|= (crtc_state
->pixel_multiplier
- 1)
8455 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
8458 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8459 if (crtc_state
->has_dp_encoder
)
8460 dpll
|= DPLL_SDVO_HIGH_SPEED
;
8462 /* compute bitmask from p1 value */
8463 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
8465 dpll
|= (1 << (crtc_state
->dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
8467 switch (crtc_state
->dpll
.p2
) {
8469 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
8472 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
8475 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
8478 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
8482 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
8483 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
8485 dpll
|= PLL_REF_INPUT_DREFCLK
;
8487 return dpll
| DPLL_VCO_ENABLE
;
8490 static int ironlake_crtc_compute_clock(struct intel_crtc
*crtc
,
8491 struct intel_crtc_state
*crtc_state
)
8493 struct drm_device
*dev
= crtc
->base
.dev
;
8494 intel_clock_t clock
, reduced_clock
;
8495 u32 dpll
= 0, fp
= 0, fp2
= 0;
8496 bool ok
, has_reduced_clock
= false;
8497 bool is_lvds
= false;
8498 struct intel_shared_dpll
*pll
;
8500 memset(&crtc_state
->dpll_hw_state
, 0,
8501 sizeof(crtc_state
->dpll_hw_state
));
8503 is_lvds
= intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
);
8505 WARN(!(HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)),
8506 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev
));
8508 ok
= ironlake_compute_clocks(&crtc
->base
, crtc_state
, &clock
,
8509 &has_reduced_clock
, &reduced_clock
);
8510 if (!ok
&& !crtc_state
->clock_set
) {
8511 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8514 /* Compat-code for transition, will disappear. */
8515 if (!crtc_state
->clock_set
) {
8516 crtc_state
->dpll
.n
= clock
.n
;
8517 crtc_state
->dpll
.m1
= clock
.m1
;
8518 crtc_state
->dpll
.m2
= clock
.m2
;
8519 crtc_state
->dpll
.p1
= clock
.p1
;
8520 crtc_state
->dpll
.p2
= clock
.p2
;
8523 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8524 if (crtc_state
->has_pch_encoder
) {
8525 fp
= i9xx_dpll_compute_fp(&crtc_state
->dpll
);
8526 if (has_reduced_clock
)
8527 fp2
= i9xx_dpll_compute_fp(&reduced_clock
);
8529 dpll
= ironlake_compute_dpll(crtc
, crtc_state
,
8530 &fp
, &reduced_clock
,
8531 has_reduced_clock
? &fp2
: NULL
);
8533 crtc_state
->dpll_hw_state
.dpll
= dpll
;
8534 crtc_state
->dpll_hw_state
.fp0
= fp
;
8535 if (has_reduced_clock
)
8536 crtc_state
->dpll_hw_state
.fp1
= fp2
;
8538 crtc_state
->dpll_hw_state
.fp1
= fp
;
8540 pll
= intel_get_shared_dpll(crtc
, crtc_state
);
8542 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8543 pipe_name(crtc
->pipe
));
8548 if (is_lvds
&& has_reduced_clock
)
8549 crtc
->lowfreq_avail
= true;
8551 crtc
->lowfreq_avail
= false;
8556 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
8557 struct intel_link_m_n
*m_n
)
8559 struct drm_device
*dev
= crtc
->base
.dev
;
8560 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8561 enum pipe pipe
= crtc
->pipe
;
8563 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
8564 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
8565 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
8567 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
8568 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
8569 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8572 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
8573 enum transcoder transcoder
,
8574 struct intel_link_m_n
*m_n
,
8575 struct intel_link_m_n
*m2_n2
)
8577 struct drm_device
*dev
= crtc
->base
.dev
;
8578 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8579 enum pipe pipe
= crtc
->pipe
;
8581 if (INTEL_INFO(dev
)->gen
>= 5) {
8582 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
8583 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
8584 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
8586 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
8587 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
8588 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8589 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8590 * gen < 8) and if DRRS is supported (to make sure the
8591 * registers are not unnecessarily read).
8593 if (m2_n2
&& INTEL_INFO(dev
)->gen
< 8 &&
8594 crtc
->config
->has_drrs
) {
8595 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
8596 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
8597 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
8599 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
8600 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
8601 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8604 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
8605 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
8606 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
8608 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
8609 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
8610 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
8614 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
8615 struct intel_crtc_state
*pipe_config
)
8617 if (pipe_config
->has_pch_encoder
)
8618 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
8620 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8621 &pipe_config
->dp_m_n
,
8622 &pipe_config
->dp_m2_n2
);
8625 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
8626 struct intel_crtc_state
*pipe_config
)
8628 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
8629 &pipe_config
->fdi_m_n
, NULL
);
8632 static void skylake_get_pfit_config(struct intel_crtc
*crtc
,
8633 struct intel_crtc_state
*pipe_config
)
8635 struct drm_device
*dev
= crtc
->base
.dev
;
8636 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8637 struct intel_crtc_scaler_state
*scaler_state
= &pipe_config
->scaler_state
;
8638 uint32_t ps_ctrl
= 0;
8642 /* find scaler attached to this pipe */
8643 for (i
= 0; i
< crtc
->num_scalers
; i
++) {
8644 ps_ctrl
= I915_READ(SKL_PS_CTRL(crtc
->pipe
, i
));
8645 if (ps_ctrl
& PS_SCALER_EN
&& !(ps_ctrl
& PS_PLANE_SEL_MASK
)) {
8647 pipe_config
->pch_pfit
.enabled
= true;
8648 pipe_config
->pch_pfit
.pos
= I915_READ(SKL_PS_WIN_POS(crtc
->pipe
, i
));
8649 pipe_config
->pch_pfit
.size
= I915_READ(SKL_PS_WIN_SZ(crtc
->pipe
, i
));
8654 scaler_state
->scaler_id
= id
;
8656 scaler_state
->scaler_users
|= (1 << SKL_CRTC_INDEX
);
8658 scaler_state
->scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
8663 skylake_get_initial_plane_config(struct intel_crtc
*crtc
,
8664 struct intel_initial_plane_config
*plane_config
)
8666 struct drm_device
*dev
= crtc
->base
.dev
;
8667 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8668 u32 val
, base
, offset
, stride_mult
, tiling
;
8669 int pipe
= crtc
->pipe
;
8670 int fourcc
, pixel_format
;
8671 unsigned int aligned_height
;
8672 struct drm_framebuffer
*fb
;
8673 struct intel_framebuffer
*intel_fb
;
8675 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8677 DRM_DEBUG_KMS("failed to alloc fb\n");
8681 fb
= &intel_fb
->base
;
8683 val
= I915_READ(PLANE_CTL(pipe
, 0));
8684 if (!(val
& PLANE_CTL_ENABLE
))
8687 pixel_format
= val
& PLANE_CTL_FORMAT_MASK
;
8688 fourcc
= skl_format_to_fourcc(pixel_format
,
8689 val
& PLANE_CTL_ORDER_RGBX
,
8690 val
& PLANE_CTL_ALPHA_MASK
);
8691 fb
->pixel_format
= fourcc
;
8692 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
8694 tiling
= val
& PLANE_CTL_TILED_MASK
;
8696 case PLANE_CTL_TILED_LINEAR
:
8697 fb
->modifier
[0] = DRM_FORMAT_MOD_NONE
;
8699 case PLANE_CTL_TILED_X
:
8700 plane_config
->tiling
= I915_TILING_X
;
8701 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
8703 case PLANE_CTL_TILED_Y
:
8704 fb
->modifier
[0] = I915_FORMAT_MOD_Y_TILED
;
8706 case PLANE_CTL_TILED_YF
:
8707 fb
->modifier
[0] = I915_FORMAT_MOD_Yf_TILED
;
8710 MISSING_CASE(tiling
);
8714 base
= I915_READ(PLANE_SURF(pipe
, 0)) & 0xfffff000;
8715 plane_config
->base
= base
;
8717 offset
= I915_READ(PLANE_OFFSET(pipe
, 0));
8719 val
= I915_READ(PLANE_SIZE(pipe
, 0));
8720 fb
->height
= ((val
>> 16) & 0xfff) + 1;
8721 fb
->width
= ((val
>> 0) & 0x1fff) + 1;
8723 val
= I915_READ(PLANE_STRIDE(pipe
, 0));
8724 stride_mult
= intel_fb_stride_alignment(dev
, fb
->modifier
[0],
8726 fb
->pitches
[0] = (val
& 0x3ff) * stride_mult
;
8728 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
8732 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8734 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8735 pipe_name(pipe
), fb
->width
, fb
->height
,
8736 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
8737 plane_config
->size
);
8739 plane_config
->fb
= intel_fb
;
8746 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
8747 struct intel_crtc_state
*pipe_config
)
8749 struct drm_device
*dev
= crtc
->base
.dev
;
8750 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8753 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
8755 if (tmp
& PF_ENABLE
) {
8756 pipe_config
->pch_pfit
.enabled
= true;
8757 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
8758 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
8760 /* We currently do not free assignements of panel fitters on
8761 * ivb/hsw (since we don't use the higher upscaling modes which
8762 * differentiates them) so just WARN about this case for now. */
8764 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
8765 PF_PIPE_SEL_IVB(crtc
->pipe
));
8771 ironlake_get_initial_plane_config(struct intel_crtc
*crtc
,
8772 struct intel_initial_plane_config
*plane_config
)
8774 struct drm_device
*dev
= crtc
->base
.dev
;
8775 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8776 u32 val
, base
, offset
;
8777 int pipe
= crtc
->pipe
;
8778 int fourcc
, pixel_format
;
8779 unsigned int aligned_height
;
8780 struct drm_framebuffer
*fb
;
8781 struct intel_framebuffer
*intel_fb
;
8783 val
= I915_READ(DSPCNTR(pipe
));
8784 if (!(val
& DISPLAY_PLANE_ENABLE
))
8787 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8789 DRM_DEBUG_KMS("failed to alloc fb\n");
8793 fb
= &intel_fb
->base
;
8795 if (INTEL_INFO(dev
)->gen
>= 4) {
8796 if (val
& DISPPLANE_TILED
) {
8797 plane_config
->tiling
= I915_TILING_X
;
8798 fb
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
8802 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
8803 fourcc
= i9xx_format_to_fourcc(pixel_format
);
8804 fb
->pixel_format
= fourcc
;
8805 fb
->bits_per_pixel
= drm_format_plane_cpp(fourcc
, 0) * 8;
8807 base
= I915_READ(DSPSURF(pipe
)) & 0xfffff000;
8808 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
8809 offset
= I915_READ(DSPOFFSET(pipe
));
8811 if (plane_config
->tiling
)
8812 offset
= I915_READ(DSPTILEOFF(pipe
));
8814 offset
= I915_READ(DSPLINOFF(pipe
));
8816 plane_config
->base
= base
;
8818 val
= I915_READ(PIPESRC(pipe
));
8819 fb
->width
= ((val
>> 16) & 0xfff) + 1;
8820 fb
->height
= ((val
>> 0) & 0xfff) + 1;
8822 val
= I915_READ(DSPSTRIDE(pipe
));
8823 fb
->pitches
[0] = val
& 0xffffffc0;
8825 aligned_height
= intel_fb_align_height(dev
, fb
->height
,
8829 plane_config
->size
= fb
->pitches
[0] * aligned_height
;
8831 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8832 pipe_name(pipe
), fb
->width
, fb
->height
,
8833 fb
->bits_per_pixel
, base
, fb
->pitches
[0],
8834 plane_config
->size
);
8836 plane_config
->fb
= intel_fb
;
8839 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
8840 struct intel_crtc_state
*pipe_config
)
8842 struct drm_device
*dev
= crtc
->base
.dev
;
8843 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8846 if (!intel_display_power_is_enabled(dev_priv
,
8847 POWER_DOMAIN_PIPE(crtc
->pipe
)))
8850 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
8851 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
8853 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
8854 if (!(tmp
& PIPECONF_ENABLE
))
8857 switch (tmp
& PIPECONF_BPC_MASK
) {
8859 pipe_config
->pipe_bpp
= 18;
8862 pipe_config
->pipe_bpp
= 24;
8864 case PIPECONF_10BPC
:
8865 pipe_config
->pipe_bpp
= 30;
8867 case PIPECONF_12BPC
:
8868 pipe_config
->pipe_bpp
= 36;
8874 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
8875 pipe_config
->limited_color_range
= true;
8877 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
8878 struct intel_shared_dpll
*pll
;
8880 pipe_config
->has_pch_encoder
= true;
8882 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
8883 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
8884 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
8886 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
8888 if (HAS_PCH_IBX(dev_priv
->dev
)) {
8889 pipe_config
->shared_dpll
=
8890 (enum intel_dpll_id
) crtc
->pipe
;
8892 tmp
= I915_READ(PCH_DPLL_SEL
);
8893 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
8894 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_B
;
8896 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_A
;
8899 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
8901 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
8902 &pipe_config
->dpll_hw_state
));
8904 tmp
= pipe_config
->dpll_hw_state
.dpll
;
8905 pipe_config
->pixel_multiplier
=
8906 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
8907 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
8909 ironlake_pch_clock_get(crtc
, pipe_config
);
8911 pipe_config
->pixel_multiplier
= 1;
8914 intel_get_pipe_timings(crtc
, pipe_config
);
8916 ironlake_get_pfit_config(crtc
, pipe_config
);
8921 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
8923 struct drm_device
*dev
= dev_priv
->dev
;
8924 struct intel_crtc
*crtc
;
8926 for_each_intel_crtc(dev
, crtc
)
8927 I915_STATE_WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
8928 pipe_name(crtc
->pipe
));
8930 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
8931 I915_STATE_WARN(I915_READ(SPLL_CTL
) & SPLL_PLL_ENABLE
, "SPLL enabled\n");
8932 I915_STATE_WARN(I915_READ(WRPLL_CTL1
) & WRPLL_PLL_ENABLE
, "WRPLL1 enabled\n");
8933 I915_STATE_WARN(I915_READ(WRPLL_CTL2
) & WRPLL_PLL_ENABLE
, "WRPLL2 enabled\n");
8934 I915_STATE_WARN(I915_READ(PCH_PP_STATUS
) & PP_ON
, "Panel power on\n");
8935 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
8936 "CPU PWM1 enabled\n");
8937 if (IS_HASWELL(dev
))
8938 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
8939 "CPU PWM2 enabled\n");
8940 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
8941 "PCH PWM1 enabled\n");
8942 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
8943 "Utility pin enabled\n");
8944 I915_STATE_WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
8947 * In theory we can still leave IRQs enabled, as long as only the HPD
8948 * interrupts remain enabled. We used to check for that, but since it's
8949 * gen-specific and since we only disable LCPLL after we fully disable
8950 * the interrupts, the check below should be enough.
8952 I915_STATE_WARN(intel_irqs_enabled(dev_priv
), "IRQs enabled\n");
8955 static uint32_t hsw_read_dcomp(struct drm_i915_private
*dev_priv
)
8957 struct drm_device
*dev
= dev_priv
->dev
;
8959 if (IS_HASWELL(dev
))
8960 return I915_READ(D_COMP_HSW
);
8962 return I915_READ(D_COMP_BDW
);
8965 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
8967 struct drm_device
*dev
= dev_priv
->dev
;
8969 if (IS_HASWELL(dev
)) {
8970 mutex_lock(&dev_priv
->rps
.hw_lock
);
8971 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
8973 DRM_ERROR("Failed to write to D_COMP\n");
8974 mutex_unlock(&dev_priv
->rps
.hw_lock
);
8976 I915_WRITE(D_COMP_BDW
, val
);
8977 POSTING_READ(D_COMP_BDW
);
8982 * This function implements pieces of two sequences from BSpec:
8983 * - Sequence for display software to disable LCPLL
8984 * - Sequence for display software to allow package C8+
8985 * The steps implemented here are just the steps that actually touch the LCPLL
8986 * register. Callers should take care of disabling all the display engine
8987 * functions, doing the mode unset, fixing interrupts, etc.
8989 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
8990 bool switch_to_fclk
, bool allow_power_down
)
8994 assert_can_disable_lcpll(dev_priv
);
8996 val
= I915_READ(LCPLL_CTL
);
8998 if (switch_to_fclk
) {
8999 val
|= LCPLL_CD_SOURCE_FCLK
;
9000 I915_WRITE(LCPLL_CTL
, val
);
9002 if (wait_for_atomic_us(I915_READ(LCPLL_CTL
) &
9003 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
9004 DRM_ERROR("Switching to FCLK failed\n");
9006 val
= I915_READ(LCPLL_CTL
);
9009 val
|= LCPLL_PLL_DISABLE
;
9010 I915_WRITE(LCPLL_CTL
, val
);
9011 POSTING_READ(LCPLL_CTL
);
9013 if (wait_for((I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
) == 0, 1))
9014 DRM_ERROR("LCPLL still locked\n");
9016 val
= hsw_read_dcomp(dev_priv
);
9017 val
|= D_COMP_COMP_DISABLE
;
9018 hsw_write_dcomp(dev_priv
, val
);
9021 if (wait_for((hsw_read_dcomp(dev_priv
) & D_COMP_RCOMP_IN_PROGRESS
) == 0,
9023 DRM_ERROR("D_COMP RCOMP still in progress\n");
9025 if (allow_power_down
) {
9026 val
= I915_READ(LCPLL_CTL
);
9027 val
|= LCPLL_POWER_DOWN_ALLOW
;
9028 I915_WRITE(LCPLL_CTL
, val
);
9029 POSTING_READ(LCPLL_CTL
);
9034 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9037 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
9041 val
= I915_READ(LCPLL_CTL
);
9043 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
9044 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
9048 * Make sure we're not on PC8 state before disabling PC8, otherwise
9049 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
9051 intel_uncore_forcewake_get(dev_priv
, FORCEWAKE_ALL
);
9053 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
9054 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
9055 I915_WRITE(LCPLL_CTL
, val
);
9056 POSTING_READ(LCPLL_CTL
);
9059 val
= hsw_read_dcomp(dev_priv
);
9060 val
|= D_COMP_COMP_FORCE
;
9061 val
&= ~D_COMP_COMP_DISABLE
;
9062 hsw_write_dcomp(dev_priv
, val
);
9064 val
= I915_READ(LCPLL_CTL
);
9065 val
&= ~LCPLL_PLL_DISABLE
;
9066 I915_WRITE(LCPLL_CTL
, val
);
9068 if (wait_for(I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
, 5))
9069 DRM_ERROR("LCPLL not locked yet\n");
9071 if (val
& LCPLL_CD_SOURCE_FCLK
) {
9072 val
= I915_READ(LCPLL_CTL
);
9073 val
&= ~LCPLL_CD_SOURCE_FCLK
;
9074 I915_WRITE(LCPLL_CTL
, val
);
9076 if (wait_for_atomic_us((I915_READ(LCPLL_CTL
) &
9077 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
9078 DRM_ERROR("Switching back to LCPLL failed\n");
9081 intel_uncore_forcewake_put(dev_priv
, FORCEWAKE_ALL
);
9085 * Package states C8 and deeper are really deep PC states that can only be
9086 * reached when all the devices on the system allow it, so even if the graphics
9087 * device allows PC8+, it doesn't mean the system will actually get to these
9088 * states. Our driver only allows PC8+ when going into runtime PM.
9090 * The requirements for PC8+ are that all the outputs are disabled, the power
9091 * well is disabled and most interrupts are disabled, and these are also
9092 * requirements for runtime PM. When these conditions are met, we manually do
9093 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9094 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9097 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9098 * the state of some registers, so when we come back from PC8+ we need to
9099 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9100 * need to take care of the registers kept by RC6. Notice that this happens even
9101 * if we don't put the device in PCI D3 state (which is what currently happens
9102 * because of the runtime PM support).
9104 * For more, read "Display Sequences for Package C8" on the hardware
9107 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
9109 struct drm_device
*dev
= dev_priv
->dev
;
9112 DRM_DEBUG_KMS("Enabling package C8+\n");
9114 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
9115 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
9116 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
9117 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
9120 lpt_disable_clkout_dp(dev
);
9121 hsw_disable_lcpll(dev_priv
, true, true);
9124 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
9126 struct drm_device
*dev
= dev_priv
->dev
;
9129 DRM_DEBUG_KMS("Disabling package C8+\n");
9131 hsw_restore_lcpll(dev_priv
);
9132 lpt_init_pch_refclk(dev
);
9134 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
9135 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
9136 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
9137 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
9140 intel_prepare_ddi(dev
);
9143 static void broxton_modeset_global_resources(struct drm_atomic_state
*old_state
)
9145 struct drm_device
*dev
= old_state
->dev
;
9146 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9147 int max_pixclk
= intel_mode_max_pixclk(dev
, NULL
);
9150 /* see the comment in valleyview_modeset_global_resources */
9151 if (WARN_ON(max_pixclk
< 0))
9154 req_cdclk
= broxton_calc_cdclk(dev_priv
, max_pixclk
);
9156 if (req_cdclk
!= dev_priv
->cdclk_freq
)
9157 broxton_set_cdclk(dev
, req_cdclk
);
9160 static int haswell_crtc_compute_clock(struct intel_crtc
*crtc
,
9161 struct intel_crtc_state
*crtc_state
)
9163 if (!intel_ddi_pll_select(crtc
, crtc_state
))
9166 crtc
->lowfreq_avail
= false;
9171 static void bxt_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9173 struct intel_crtc_state
*pipe_config
)
9177 pipe_config
->ddi_pll_sel
= SKL_DPLL0
;
9178 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL1
;
9181 pipe_config
->ddi_pll_sel
= SKL_DPLL1
;
9182 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL2
;
9185 pipe_config
->ddi_pll_sel
= SKL_DPLL2
;
9186 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL3
;
9189 DRM_ERROR("Incorrect port type\n");
9193 static void skylake_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9195 struct intel_crtc_state
*pipe_config
)
9197 u32 temp
, dpll_ctl1
;
9199 temp
= I915_READ(DPLL_CTRL2
) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port
);
9200 pipe_config
->ddi_pll_sel
= temp
>> (port
* 3 + 1);
9202 switch (pipe_config
->ddi_pll_sel
) {
9205 * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part
9206 * of the shared DPLL framework and thus needs to be read out
9209 dpll_ctl1
= I915_READ(DPLL_CTRL1
);
9210 pipe_config
->dpll_hw_state
.ctrl1
= dpll_ctl1
& 0x3f;
9213 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL1
;
9216 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL2
;
9219 pipe_config
->shared_dpll
= DPLL_ID_SKL_DPLL3
;
9224 static void haswell_get_ddi_pll(struct drm_i915_private
*dev_priv
,
9226 struct intel_crtc_state
*pipe_config
)
9228 pipe_config
->ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
9230 switch (pipe_config
->ddi_pll_sel
) {
9231 case PORT_CLK_SEL_WRPLL1
:
9232 pipe_config
->shared_dpll
= DPLL_ID_WRPLL1
;
9234 case PORT_CLK_SEL_WRPLL2
:
9235 pipe_config
->shared_dpll
= DPLL_ID_WRPLL2
;
9240 static void haswell_get_ddi_port_state(struct intel_crtc
*crtc
,
9241 struct intel_crtc_state
*pipe_config
)
9243 struct drm_device
*dev
= crtc
->base
.dev
;
9244 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9245 struct intel_shared_dpll
*pll
;
9249 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
9251 port
= (tmp
& TRANS_DDI_PORT_MASK
) >> TRANS_DDI_PORT_SHIFT
;
9253 if (IS_SKYLAKE(dev
))
9254 skylake_get_ddi_pll(dev_priv
, port
, pipe_config
);
9255 else if (IS_BROXTON(dev
))
9256 bxt_get_ddi_pll(dev_priv
, port
, pipe_config
);
9258 haswell_get_ddi_pll(dev_priv
, port
, pipe_config
);
9260 if (pipe_config
->shared_dpll
>= 0) {
9261 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
9263 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
9264 &pipe_config
->dpll_hw_state
));
9268 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9269 * DDI E. So just check whether this pipe is wired to DDI E and whether
9270 * the PCH transcoder is on.
9272 if (INTEL_INFO(dev
)->gen
< 9 &&
9273 (port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
9274 pipe_config
->has_pch_encoder
= true;
9276 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
9277 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
9278 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
9280 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
9284 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
9285 struct intel_crtc_state
*pipe_config
)
9287 struct drm_device
*dev
= crtc
->base
.dev
;
9288 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9289 enum intel_display_power_domain pfit_domain
;
9292 if (!intel_display_power_is_enabled(dev_priv
,
9293 POWER_DOMAIN_PIPE(crtc
->pipe
)))
9296 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
9297 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
9299 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
9300 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
9301 enum pipe trans_edp_pipe
;
9302 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
9304 WARN(1, "unknown pipe linked to edp transcoder\n");
9305 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
9306 case TRANS_DDI_EDP_INPUT_A_ON
:
9307 trans_edp_pipe
= PIPE_A
;
9309 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
9310 trans_edp_pipe
= PIPE_B
;
9312 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
9313 trans_edp_pipe
= PIPE_C
;
9317 if (trans_edp_pipe
== crtc
->pipe
)
9318 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
9321 if (!intel_display_power_is_enabled(dev_priv
,
9322 POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
)))
9325 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
9326 if (!(tmp
& PIPECONF_ENABLE
))
9329 haswell_get_ddi_port_state(crtc
, pipe_config
);
9331 intel_get_pipe_timings(crtc
, pipe_config
);
9333 if (INTEL_INFO(dev
)->gen
>= 9) {
9334 skl_init_scalers(dev
, crtc
, pipe_config
);
9337 pfit_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
9339 if (INTEL_INFO(dev
)->gen
>= 9) {
9340 pipe_config
->scaler_state
.scaler_id
= -1;
9341 pipe_config
->scaler_state
.scaler_users
&= ~(1 << SKL_CRTC_INDEX
);
9344 if (intel_display_power_is_enabled(dev_priv
, pfit_domain
)) {
9345 if (INTEL_INFO(dev
)->gen
== 9)
9346 skylake_get_pfit_config(crtc
, pipe_config
);
9347 else if (INTEL_INFO(dev
)->gen
< 9)
9348 ironlake_get_pfit_config(crtc
, pipe_config
);
9350 MISSING_CASE(INTEL_INFO(dev
)->gen
);
9353 if (IS_HASWELL(dev
))
9354 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
9355 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
9357 if (pipe_config
->cpu_transcoder
!= TRANSCODER_EDP
) {
9358 pipe_config
->pixel_multiplier
=
9359 I915_READ(PIPE_MULT(pipe_config
->cpu_transcoder
)) + 1;
9361 pipe_config
->pixel_multiplier
= 1;
9367 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
)
9369 struct drm_device
*dev
= crtc
->dev
;
9370 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9371 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9372 uint32_t cntl
= 0, size
= 0;
9375 unsigned int width
= intel_crtc
->base
.cursor
->state
->crtc_w
;
9376 unsigned int height
= intel_crtc
->base
.cursor
->state
->crtc_h
;
9377 unsigned int stride
= roundup_pow_of_two(width
) * 4;
9381 WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
9392 cntl
|= CURSOR_ENABLE
|
9393 CURSOR_GAMMA_ENABLE
|
9394 CURSOR_FORMAT_ARGB
|
9395 CURSOR_STRIDE(stride
);
9397 size
= (height
<< 12) | width
;
9400 if (intel_crtc
->cursor_cntl
!= 0 &&
9401 (intel_crtc
->cursor_base
!= base
||
9402 intel_crtc
->cursor_size
!= size
||
9403 intel_crtc
->cursor_cntl
!= cntl
)) {
9404 /* On these chipsets we can only modify the base/size/stride
9405 * whilst the cursor is disabled.
9407 I915_WRITE(_CURACNTR
, 0);
9408 POSTING_READ(_CURACNTR
);
9409 intel_crtc
->cursor_cntl
= 0;
9412 if (intel_crtc
->cursor_base
!= base
) {
9413 I915_WRITE(_CURABASE
, base
);
9414 intel_crtc
->cursor_base
= base
;
9417 if (intel_crtc
->cursor_size
!= size
) {
9418 I915_WRITE(CURSIZE
, size
);
9419 intel_crtc
->cursor_size
= size
;
9422 if (intel_crtc
->cursor_cntl
!= cntl
) {
9423 I915_WRITE(_CURACNTR
, cntl
);
9424 POSTING_READ(_CURACNTR
);
9425 intel_crtc
->cursor_cntl
= cntl
;
9429 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
)
9431 struct drm_device
*dev
= crtc
->dev
;
9432 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9433 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9434 int pipe
= intel_crtc
->pipe
;
9439 cntl
= MCURSOR_GAMMA_ENABLE
;
9440 switch (intel_crtc
->base
.cursor
->state
->crtc_w
) {
9442 cntl
|= CURSOR_MODE_64_ARGB_AX
;
9445 cntl
|= CURSOR_MODE_128_ARGB_AX
;
9448 cntl
|= CURSOR_MODE_256_ARGB_AX
;
9451 MISSING_CASE(intel_crtc
->base
.cursor
->state
->crtc_w
);
9454 cntl
|= pipe
<< 28; /* Connect to correct pipe */
9456 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
9457 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
9460 if (crtc
->cursor
->state
->rotation
== BIT(DRM_ROTATE_180
))
9461 cntl
|= CURSOR_ROTATE_180
;
9463 if (intel_crtc
->cursor_cntl
!= cntl
) {
9464 I915_WRITE(CURCNTR(pipe
), cntl
);
9465 POSTING_READ(CURCNTR(pipe
));
9466 intel_crtc
->cursor_cntl
= cntl
;
9469 /* and commit changes on next vblank */
9470 I915_WRITE(CURBASE(pipe
), base
);
9471 POSTING_READ(CURBASE(pipe
));
9473 intel_crtc
->cursor_base
= base
;
9476 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
9477 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
9480 struct drm_device
*dev
= crtc
->dev
;
9481 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9482 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9483 int pipe
= intel_crtc
->pipe
;
9484 int x
= crtc
->cursor_x
;
9485 int y
= crtc
->cursor_y
;
9486 u32 base
= 0, pos
= 0;
9489 base
= intel_crtc
->cursor_addr
;
9491 if (x
>= intel_crtc
->config
->pipe_src_w
)
9494 if (y
>= intel_crtc
->config
->pipe_src_h
)
9498 if (x
+ intel_crtc
->base
.cursor
->state
->crtc_w
<= 0)
9501 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
9504 pos
|= x
<< CURSOR_X_SHIFT
;
9507 if (y
+ intel_crtc
->base
.cursor
->state
->crtc_h
<= 0)
9510 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
9513 pos
|= y
<< CURSOR_Y_SHIFT
;
9515 if (base
== 0 && intel_crtc
->cursor_base
== 0)
9518 I915_WRITE(CURPOS(pipe
), pos
);
9520 /* ILK+ do this automagically */
9521 if (HAS_GMCH_DISPLAY(dev
) &&
9522 crtc
->cursor
->state
->rotation
== BIT(DRM_ROTATE_180
)) {
9523 base
+= (intel_crtc
->base
.cursor
->state
->crtc_h
*
9524 intel_crtc
->base
.cursor
->state
->crtc_w
- 1) * 4;
9527 if (IS_845G(dev
) || IS_I865G(dev
))
9528 i845_update_cursor(crtc
, base
);
9530 i9xx_update_cursor(crtc
, base
);
9533 static bool cursor_size_ok(struct drm_device
*dev
,
9534 uint32_t width
, uint32_t height
)
9536 if (width
== 0 || height
== 0)
9540 * 845g/865g are special in that they are only limited by
9541 * the width of their cursors, the height is arbitrary up to
9542 * the precision of the register. Everything else requires
9543 * square cursors, limited to a few power-of-two sizes.
9545 if (IS_845G(dev
) || IS_I865G(dev
)) {
9546 if ((width
& 63) != 0)
9549 if (width
> (IS_845G(dev
) ? 64 : 512))
9555 switch (width
| height
) {
9570 static void intel_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
9571 u16
*blue
, uint32_t start
, uint32_t size
)
9573 int end
= (start
+ size
> 256) ? 256 : start
+ size
, i
;
9574 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9576 for (i
= start
; i
< end
; i
++) {
9577 intel_crtc
->lut_r
[i
] = red
[i
] >> 8;
9578 intel_crtc
->lut_g
[i
] = green
[i
] >> 8;
9579 intel_crtc
->lut_b
[i
] = blue
[i
] >> 8;
9582 intel_crtc_load_lut(crtc
);
9585 /* VESA 640x480x72Hz mode to set on the pipe */
9586 static struct drm_display_mode load_detect_mode
= {
9587 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
9588 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
9591 struct drm_framebuffer
*
9592 __intel_framebuffer_create(struct drm_device
*dev
,
9593 struct drm_mode_fb_cmd2
*mode_cmd
,
9594 struct drm_i915_gem_object
*obj
)
9596 struct intel_framebuffer
*intel_fb
;
9599 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
9601 drm_gem_object_unreference(&obj
->base
);
9602 return ERR_PTR(-ENOMEM
);
9605 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
9609 return &intel_fb
->base
;
9611 drm_gem_object_unreference(&obj
->base
);
9614 return ERR_PTR(ret
);
9617 static struct drm_framebuffer
*
9618 intel_framebuffer_create(struct drm_device
*dev
,
9619 struct drm_mode_fb_cmd2
*mode_cmd
,
9620 struct drm_i915_gem_object
*obj
)
9622 struct drm_framebuffer
*fb
;
9625 ret
= i915_mutex_lock_interruptible(dev
);
9627 return ERR_PTR(ret
);
9628 fb
= __intel_framebuffer_create(dev
, mode_cmd
, obj
);
9629 mutex_unlock(&dev
->struct_mutex
);
9635 intel_framebuffer_pitch_for_width(int width
, int bpp
)
9637 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
9638 return ALIGN(pitch
, 64);
9642 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
9644 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
9645 return PAGE_ALIGN(pitch
* mode
->vdisplay
);
9648 static struct drm_framebuffer
*
9649 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
9650 struct drm_display_mode
*mode
,
9653 struct drm_i915_gem_object
*obj
;
9654 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
9656 obj
= i915_gem_alloc_object(dev
,
9657 intel_framebuffer_size_for_mode(mode
, bpp
));
9659 return ERR_PTR(-ENOMEM
);
9661 mode_cmd
.width
= mode
->hdisplay
;
9662 mode_cmd
.height
= mode
->vdisplay
;
9663 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
9665 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
9667 return intel_framebuffer_create(dev
, &mode_cmd
, obj
);
9670 static struct drm_framebuffer
*
9671 mode_fits_in_fbdev(struct drm_device
*dev
,
9672 struct drm_display_mode
*mode
)
9674 #ifdef CONFIG_DRM_I915_FBDEV
9675 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9676 struct drm_i915_gem_object
*obj
;
9677 struct drm_framebuffer
*fb
;
9679 if (!dev_priv
->fbdev
)
9682 if (!dev_priv
->fbdev
->fb
)
9685 obj
= dev_priv
->fbdev
->fb
->obj
;
9688 fb
= &dev_priv
->fbdev
->fb
->base
;
9689 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
9690 fb
->bits_per_pixel
))
9693 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
9702 static int intel_modeset_setup_plane_state(struct drm_atomic_state
*state
,
9703 struct drm_crtc
*crtc
,
9704 struct drm_display_mode
*mode
,
9705 struct drm_framebuffer
*fb
,
9708 struct drm_plane_state
*plane_state
;
9709 int hdisplay
, vdisplay
;
9712 plane_state
= drm_atomic_get_plane_state(state
, crtc
->primary
);
9713 if (IS_ERR(plane_state
))
9714 return PTR_ERR(plane_state
);
9717 drm_crtc_get_hv_timing(mode
, &hdisplay
, &vdisplay
);
9719 hdisplay
= vdisplay
= 0;
9721 ret
= drm_atomic_set_crtc_for_plane(plane_state
, fb
? crtc
: NULL
);
9724 drm_atomic_set_fb_for_plane(plane_state
, fb
);
9725 plane_state
->crtc_x
= 0;
9726 plane_state
->crtc_y
= 0;
9727 plane_state
->crtc_w
= hdisplay
;
9728 plane_state
->crtc_h
= vdisplay
;
9729 plane_state
->src_x
= x
<< 16;
9730 plane_state
->src_y
= y
<< 16;
9731 plane_state
->src_w
= hdisplay
<< 16;
9732 plane_state
->src_h
= vdisplay
<< 16;
9737 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
9738 struct drm_display_mode
*mode
,
9739 struct intel_load_detect_pipe
*old
,
9740 struct drm_modeset_acquire_ctx
*ctx
)
9742 struct intel_crtc
*intel_crtc
;
9743 struct intel_encoder
*intel_encoder
=
9744 intel_attached_encoder(connector
);
9745 struct drm_crtc
*possible_crtc
;
9746 struct drm_encoder
*encoder
= &intel_encoder
->base
;
9747 struct drm_crtc
*crtc
= NULL
;
9748 struct drm_device
*dev
= encoder
->dev
;
9749 struct drm_framebuffer
*fb
;
9750 struct drm_mode_config
*config
= &dev
->mode_config
;
9751 struct drm_atomic_state
*state
= NULL
;
9752 struct drm_connector_state
*connector_state
;
9753 struct intel_crtc_state
*crtc_state
;
9756 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9757 connector
->base
.id
, connector
->name
,
9758 encoder
->base
.id
, encoder
->name
);
9761 ret
= drm_modeset_lock(&config
->connection_mutex
, ctx
);
9766 * Algorithm gets a little messy:
9768 * - if the connector already has an assigned crtc, use it (but make
9769 * sure it's on first)
9771 * - try to find the first unused crtc that can drive this connector,
9772 * and use that if we find one
9775 /* See if we already have a CRTC for this connector */
9776 if (encoder
->crtc
) {
9777 crtc
= encoder
->crtc
;
9779 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
9782 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
9786 old
->dpms_mode
= connector
->dpms
;
9787 old
->load_detect_temp
= false;
9789 /* Make sure the crtc and connector are running */
9790 if (connector
->dpms
!= DRM_MODE_DPMS_ON
)
9791 connector
->funcs
->dpms(connector
, DRM_MODE_DPMS_ON
);
9796 /* Find an unused one (if possible) */
9797 for_each_crtc(dev
, possible_crtc
) {
9799 if (!(encoder
->possible_crtcs
& (1 << i
)))
9801 if (possible_crtc
->state
->enable
)
9803 /* This can occur when applying the pipe A quirk on resume. */
9804 if (to_intel_crtc(possible_crtc
)->new_enabled
)
9807 crtc
= possible_crtc
;
9812 * If we didn't find an unused CRTC, don't use any.
9815 DRM_DEBUG_KMS("no pipe available for load-detect\n");
9819 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
9822 ret
= drm_modeset_lock(&crtc
->primary
->mutex
, ctx
);
9825 intel_encoder
->new_crtc
= to_intel_crtc(crtc
);
9826 to_intel_connector(connector
)->new_encoder
= intel_encoder
;
9828 intel_crtc
= to_intel_crtc(crtc
);
9829 intel_crtc
->new_enabled
= true;
9830 old
->dpms_mode
= connector
->dpms
;
9831 old
->load_detect_temp
= true;
9832 old
->release_fb
= NULL
;
9834 state
= drm_atomic_state_alloc(dev
);
9838 state
->acquire_ctx
= ctx
;
9840 connector_state
= drm_atomic_get_connector_state(state
, connector
);
9841 if (IS_ERR(connector_state
)) {
9842 ret
= PTR_ERR(connector_state
);
9846 connector_state
->crtc
= crtc
;
9847 connector_state
->best_encoder
= &intel_encoder
->base
;
9849 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
9850 if (IS_ERR(crtc_state
)) {
9851 ret
= PTR_ERR(crtc_state
);
9855 crtc_state
->base
.active
= crtc_state
->base
.enable
= true;
9858 mode
= &load_detect_mode
;
9860 /* We need a framebuffer large enough to accommodate all accesses
9861 * that the plane may generate whilst we perform load detection.
9862 * We can not rely on the fbcon either being present (we get called
9863 * during its initialisation to detect all boot displays, or it may
9864 * not even exist) or that it is large enough to satisfy the
9867 fb
= mode_fits_in_fbdev(dev
, mode
);
9869 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
9870 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
9871 old
->release_fb
= fb
;
9873 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
9875 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
9879 ret
= intel_modeset_setup_plane_state(state
, crtc
, mode
, fb
, 0, 0);
9883 drm_mode_copy(&crtc_state
->base
.mode
, mode
);
9885 if (intel_set_mode(crtc
, state
)) {
9886 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
9887 if (old
->release_fb
)
9888 old
->release_fb
->funcs
->destroy(old
->release_fb
);
9891 crtc
->primary
->crtc
= crtc
;
9893 /* let the connector get through one full cycle before testing */
9894 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
9898 intel_crtc
->new_enabled
= crtc
->state
->enable
;
9900 drm_atomic_state_free(state
);
9903 if (ret
== -EDEADLK
) {
9904 drm_modeset_backoff(ctx
);
9911 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
9912 struct intel_load_detect_pipe
*old
,
9913 struct drm_modeset_acquire_ctx
*ctx
)
9915 struct drm_device
*dev
= connector
->dev
;
9916 struct intel_encoder
*intel_encoder
=
9917 intel_attached_encoder(connector
);
9918 struct drm_encoder
*encoder
= &intel_encoder
->base
;
9919 struct drm_crtc
*crtc
= encoder
->crtc
;
9920 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9921 struct drm_atomic_state
*state
;
9922 struct drm_connector_state
*connector_state
;
9923 struct intel_crtc_state
*crtc_state
;
9926 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9927 connector
->base
.id
, connector
->name
,
9928 encoder
->base
.id
, encoder
->name
);
9930 if (old
->load_detect_temp
) {
9931 state
= drm_atomic_state_alloc(dev
);
9935 state
->acquire_ctx
= ctx
;
9937 connector_state
= drm_atomic_get_connector_state(state
, connector
);
9938 if (IS_ERR(connector_state
))
9941 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
9942 if (IS_ERR(crtc_state
))
9945 to_intel_connector(connector
)->new_encoder
= NULL
;
9946 intel_encoder
->new_crtc
= NULL
;
9947 intel_crtc
->new_enabled
= false;
9949 connector_state
->best_encoder
= NULL
;
9950 connector_state
->crtc
= NULL
;
9952 crtc_state
->base
.enable
= crtc_state
->base
.active
= false;
9954 ret
= intel_modeset_setup_plane_state(state
, crtc
, NULL
, NULL
,
9959 ret
= intel_set_mode(crtc
, state
);
9963 if (old
->release_fb
) {
9964 drm_framebuffer_unregister_private(old
->release_fb
);
9965 drm_framebuffer_unreference(old
->release_fb
);
9971 /* Switch crtc and encoder back off if necessary */
9972 if (old
->dpms_mode
!= DRM_MODE_DPMS_ON
)
9973 connector
->funcs
->dpms(connector
, old
->dpms_mode
);
9977 DRM_DEBUG_KMS("Couldn't release load detect pipe.\n");
9978 drm_atomic_state_free(state
);
9981 static int i9xx_pll_refclk(struct drm_device
*dev
,
9982 const struct intel_crtc_state
*pipe_config
)
9984 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9985 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
9987 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
9988 return dev_priv
->vbt
.lvds_ssc_freq
;
9989 else if (HAS_PCH_SPLIT(dev
))
9991 else if (!IS_GEN2(dev
))
9997 /* Returns the clock of the currently programmed mode of the given pipe. */
9998 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
9999 struct intel_crtc_state
*pipe_config
)
10001 struct drm_device
*dev
= crtc
->base
.dev
;
10002 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10003 int pipe
= pipe_config
->cpu_transcoder
;
10004 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
10006 intel_clock_t clock
;
10007 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
10009 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
10010 fp
= pipe_config
->dpll_hw_state
.fp0
;
10012 fp
= pipe_config
->dpll_hw_state
.fp1
;
10014 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
10015 if (IS_PINEVIEW(dev
)) {
10016 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
10017 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
10019 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
10020 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
10023 if (!IS_GEN2(dev
)) {
10024 if (IS_PINEVIEW(dev
))
10025 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
10026 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
10028 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
10029 DPLL_FPA01_P1_POST_DIV_SHIFT
);
10031 switch (dpll
& DPLL_MODE_MASK
) {
10032 case DPLLB_MODE_DAC_SERIAL
:
10033 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
10036 case DPLLB_MODE_LVDS
:
10037 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
10041 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10042 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
10046 if (IS_PINEVIEW(dev
))
10047 pineview_clock(refclk
, &clock
);
10049 i9xx_clock(refclk
, &clock
);
10051 u32 lvds
= IS_I830(dev
) ? 0 : I915_READ(LVDS
);
10052 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
10055 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
10056 DPLL_FPA01_P1_POST_DIV_SHIFT
);
10058 if (lvds
& LVDS_CLKB_POWER_UP
)
10063 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
10066 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
10067 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
10069 if (dpll
& PLL_P2_DIVIDE_BY_4
)
10075 i9xx_clock(refclk
, &clock
);
10079 * This value includes pixel_multiplier. We will use
10080 * port_clock to compute adjusted_mode.crtc_clock in the
10081 * encoder's get_config() function.
10083 pipe_config
->port_clock
= clock
.dot
;
10086 int intel_dotclock_calculate(int link_freq
,
10087 const struct intel_link_m_n
*m_n
)
10090 * The calculation for the data clock is:
10091 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10092 * But we want to avoid losing precison if possible, so:
10093 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10095 * and the link clock is simpler:
10096 * link_clock = (m * link_clock) / n
10102 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
10105 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
10106 struct intel_crtc_state
*pipe_config
)
10108 struct drm_device
*dev
= crtc
->base
.dev
;
10110 /* read out port_clock from the DPLL */
10111 i9xx_crtc_clock_get(crtc
, pipe_config
);
10114 * This value does not include pixel_multiplier.
10115 * We will check that port_clock and adjusted_mode.crtc_clock
10116 * agree once we know their relationship in the encoder's
10117 * get_config() function.
10119 pipe_config
->base
.adjusted_mode
.crtc_clock
=
10120 intel_dotclock_calculate(intel_fdi_link_freq(dev
) * 10000,
10121 &pipe_config
->fdi_m_n
);
10124 /** Returns the currently programmed mode of the given pipe. */
10125 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
10126 struct drm_crtc
*crtc
)
10128 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10129 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10130 enum transcoder cpu_transcoder
= intel_crtc
->config
->cpu_transcoder
;
10131 struct drm_display_mode
*mode
;
10132 struct intel_crtc_state pipe_config
;
10133 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
10134 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
10135 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
10136 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
10137 enum pipe pipe
= intel_crtc
->pipe
;
10139 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
10144 * Construct a pipe_config sufficient for getting the clock info
10145 * back out of crtc_clock_get.
10147 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
10148 * to use a real value here instead.
10150 pipe_config
.cpu_transcoder
= (enum transcoder
) pipe
;
10151 pipe_config
.pixel_multiplier
= 1;
10152 pipe_config
.dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
10153 pipe_config
.dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
10154 pipe_config
.dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
10155 i9xx_crtc_clock_get(intel_crtc
, &pipe_config
);
10157 mode
->clock
= pipe_config
.port_clock
/ pipe_config
.pixel_multiplier
;
10158 mode
->hdisplay
= (htot
& 0xffff) + 1;
10159 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
10160 mode
->hsync_start
= (hsync
& 0xffff) + 1;
10161 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
10162 mode
->vdisplay
= (vtot
& 0xffff) + 1;
10163 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
10164 mode
->vsync_start
= (vsync
& 0xffff) + 1;
10165 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
10167 drm_mode_set_name(mode
);
10172 static void intel_decrease_pllclock(struct drm_crtc
*crtc
)
10174 struct drm_device
*dev
= crtc
->dev
;
10175 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10176 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10178 if (!HAS_GMCH_DISPLAY(dev
))
10181 if (!dev_priv
->lvds_downclock_avail
)
10185 * Since this is called by a timer, we should never get here in
10188 if (!HAS_PIPE_CXSR(dev
) && intel_crtc
->lowfreq_avail
) {
10189 int pipe
= intel_crtc
->pipe
;
10190 int dpll_reg
= DPLL(pipe
);
10193 DRM_DEBUG_DRIVER("downclocking LVDS\n");
10195 assert_panel_unlocked(dev_priv
, pipe
);
10197 dpll
= I915_READ(dpll_reg
);
10198 dpll
|= DISPLAY_RATE_SELECT_FPA1
;
10199 I915_WRITE(dpll_reg
, dpll
);
10200 intel_wait_for_vblank(dev
, pipe
);
10201 dpll
= I915_READ(dpll_reg
);
10202 if (!(dpll
& DISPLAY_RATE_SELECT_FPA1
))
10203 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
10208 void intel_mark_busy(struct drm_device
*dev
)
10210 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10212 if (dev_priv
->mm
.busy
)
10215 intel_runtime_pm_get(dev_priv
);
10216 i915_update_gfx_val(dev_priv
);
10217 if (INTEL_INFO(dev
)->gen
>= 6)
10218 gen6_rps_busy(dev_priv
);
10219 dev_priv
->mm
.busy
= true;
10222 void intel_mark_idle(struct drm_device
*dev
)
10224 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10225 struct drm_crtc
*crtc
;
10227 if (!dev_priv
->mm
.busy
)
10230 dev_priv
->mm
.busy
= false;
10232 for_each_crtc(dev
, crtc
) {
10233 if (!crtc
->primary
->fb
)
10236 intel_decrease_pllclock(crtc
);
10239 if (INTEL_INFO(dev
)->gen
>= 6)
10240 gen6_rps_idle(dev
->dev_private
);
10242 intel_runtime_pm_put(dev_priv
);
10245 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
10247 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10248 struct drm_device
*dev
= crtc
->dev
;
10249 struct intel_unpin_work
*work
;
10251 spin_lock_irq(&dev
->event_lock
);
10252 work
= intel_crtc
->unpin_work
;
10253 intel_crtc
->unpin_work
= NULL
;
10254 spin_unlock_irq(&dev
->event_lock
);
10257 cancel_work_sync(&work
->work
);
10261 drm_crtc_cleanup(crtc
);
10266 static void intel_unpin_work_fn(struct work_struct
*__work
)
10268 struct intel_unpin_work
*work
=
10269 container_of(__work
, struct intel_unpin_work
, work
);
10270 struct drm_device
*dev
= work
->crtc
->dev
;
10271 enum pipe pipe
= to_intel_crtc(work
->crtc
)->pipe
;
10273 mutex_lock(&dev
->struct_mutex
);
10274 intel_unpin_fb_obj(work
->old_fb
, work
->crtc
->primary
->state
);
10275 drm_gem_object_unreference(&work
->pending_flip_obj
->base
);
10277 intel_fbc_update(dev
);
10279 if (work
->flip_queued_req
)
10280 i915_gem_request_assign(&work
->flip_queued_req
, NULL
);
10281 mutex_unlock(&dev
->struct_mutex
);
10283 intel_frontbuffer_flip_complete(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
10284 drm_framebuffer_unreference(work
->old_fb
);
10286 BUG_ON(atomic_read(&to_intel_crtc(work
->crtc
)->unpin_work_count
) == 0);
10287 atomic_dec(&to_intel_crtc(work
->crtc
)->unpin_work_count
);
10292 static void do_intel_finish_page_flip(struct drm_device
*dev
,
10293 struct drm_crtc
*crtc
)
10295 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10296 struct intel_unpin_work
*work
;
10297 unsigned long flags
;
10299 /* Ignore early vblank irqs */
10300 if (intel_crtc
== NULL
)
10304 * This is called both by irq handlers and the reset code (to complete
10305 * lost pageflips) so needs the full irqsave spinlocks.
10307 spin_lock_irqsave(&dev
->event_lock
, flags
);
10308 work
= intel_crtc
->unpin_work
;
10310 /* Ensure we don't miss a work->pending update ... */
10313 if (work
== NULL
|| atomic_read(&work
->pending
) < INTEL_FLIP_COMPLETE
) {
10314 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
10318 page_flip_completed(intel_crtc
);
10320 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
10323 void intel_finish_page_flip(struct drm_device
*dev
, int pipe
)
10325 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10326 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
10328 do_intel_finish_page_flip(dev
, crtc
);
10331 void intel_finish_page_flip_plane(struct drm_device
*dev
, int plane
)
10333 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10334 struct drm_crtc
*crtc
= dev_priv
->plane_to_crtc_mapping
[plane
];
10336 do_intel_finish_page_flip(dev
, crtc
);
10339 /* Is 'a' after or equal to 'b'? */
10340 static bool g4x_flip_count_after_eq(u32 a
, u32 b
)
10342 return !((a
- b
) & 0x80000000);
10345 static bool page_flip_finished(struct intel_crtc
*crtc
)
10347 struct drm_device
*dev
= crtc
->base
.dev
;
10348 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10350 if (i915_reset_in_progress(&dev_priv
->gpu_error
) ||
10351 crtc
->reset_counter
!= atomic_read(&dev_priv
->gpu_error
.reset_counter
))
10355 * The relevant registers doen't exist on pre-ctg.
10356 * As the flip done interrupt doesn't trigger for mmio
10357 * flips on gmch platforms, a flip count check isn't
10358 * really needed there. But since ctg has the registers,
10359 * include it in the check anyway.
10361 if (INTEL_INFO(dev
)->gen
< 5 && !IS_G4X(dev
))
10365 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
10366 * used the same base address. In that case the mmio flip might
10367 * have completed, but the CS hasn't even executed the flip yet.
10369 * A flip count check isn't enough as the CS might have updated
10370 * the base address just after start of vblank, but before we
10371 * managed to process the interrupt. This means we'd complete the
10372 * CS flip too soon.
10374 * Combining both checks should get us a good enough result. It may
10375 * still happen that the CS flip has been executed, but has not
10376 * yet actually completed. But in case the base address is the same
10377 * anyway, we don't really care.
10379 return (I915_READ(DSPSURFLIVE(crtc
->plane
)) & ~0xfff) ==
10380 crtc
->unpin_work
->gtt_offset
&&
10381 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc
->pipe
)),
10382 crtc
->unpin_work
->flip_count
);
10385 void intel_prepare_page_flip(struct drm_device
*dev
, int plane
)
10387 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10388 struct intel_crtc
*intel_crtc
=
10389 to_intel_crtc(dev_priv
->plane_to_crtc_mapping
[plane
]);
10390 unsigned long flags
;
10394 * This is called both by irq handlers and the reset code (to complete
10395 * lost pageflips) so needs the full irqsave spinlocks.
10397 * NB: An MMIO update of the plane base pointer will also
10398 * generate a page-flip completion irq, i.e. every modeset
10399 * is also accompanied by a spurious intel_prepare_page_flip().
10401 spin_lock_irqsave(&dev
->event_lock
, flags
);
10402 if (intel_crtc
->unpin_work
&& page_flip_finished(intel_crtc
))
10403 atomic_inc_not_zero(&intel_crtc
->unpin_work
->pending
);
10404 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
10407 static inline void intel_mark_page_flip_active(struct intel_crtc
*intel_crtc
)
10409 /* Ensure that the work item is consistent when activating it ... */
10411 atomic_set(&intel_crtc
->unpin_work
->pending
, INTEL_FLIP_PENDING
);
10412 /* and that it is marked active as soon as the irq could fire. */
10416 static int intel_gen2_queue_flip(struct drm_device
*dev
,
10417 struct drm_crtc
*crtc
,
10418 struct drm_framebuffer
*fb
,
10419 struct drm_i915_gem_object
*obj
,
10420 struct intel_engine_cs
*ring
,
10423 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10427 ret
= intel_ring_begin(ring
, 6);
10431 /* Can't queue multiple flips, so wait for the previous
10432 * one to finish before executing the next.
10434 if (intel_crtc
->plane
)
10435 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
10437 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
10438 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
10439 intel_ring_emit(ring
, MI_NOOP
);
10440 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
10441 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
10442 intel_ring_emit(ring
, fb
->pitches
[0]);
10443 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
10444 intel_ring_emit(ring
, 0); /* aux display base address, unused */
10446 intel_mark_page_flip_active(intel_crtc
);
10447 __intel_ring_advance(ring
);
10451 static int intel_gen3_queue_flip(struct drm_device
*dev
,
10452 struct drm_crtc
*crtc
,
10453 struct drm_framebuffer
*fb
,
10454 struct drm_i915_gem_object
*obj
,
10455 struct intel_engine_cs
*ring
,
10458 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10462 ret
= intel_ring_begin(ring
, 6);
10466 if (intel_crtc
->plane
)
10467 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
10469 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
10470 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
10471 intel_ring_emit(ring
, MI_NOOP
);
10472 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
|
10473 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
10474 intel_ring_emit(ring
, fb
->pitches
[0]);
10475 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
10476 intel_ring_emit(ring
, MI_NOOP
);
10478 intel_mark_page_flip_active(intel_crtc
);
10479 __intel_ring_advance(ring
);
10483 static int intel_gen4_queue_flip(struct drm_device
*dev
,
10484 struct drm_crtc
*crtc
,
10485 struct drm_framebuffer
*fb
,
10486 struct drm_i915_gem_object
*obj
,
10487 struct intel_engine_cs
*ring
,
10490 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10491 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10492 uint32_t pf
, pipesrc
;
10495 ret
= intel_ring_begin(ring
, 4);
10499 /* i965+ uses the linear or tiled offsets from the
10500 * Display Registers (which do not change across a page-flip)
10501 * so we need only reprogram the base address.
10503 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
10504 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
10505 intel_ring_emit(ring
, fb
->pitches
[0]);
10506 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
|
10509 /* XXX Enabling the panel-fitter across page-flip is so far
10510 * untested on non-native modes, so ignore it for now.
10511 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
10514 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
10515 intel_ring_emit(ring
, pf
| pipesrc
);
10517 intel_mark_page_flip_active(intel_crtc
);
10518 __intel_ring_advance(ring
);
10522 static int intel_gen6_queue_flip(struct drm_device
*dev
,
10523 struct drm_crtc
*crtc
,
10524 struct drm_framebuffer
*fb
,
10525 struct drm_i915_gem_object
*obj
,
10526 struct intel_engine_cs
*ring
,
10529 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10530 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10531 uint32_t pf
, pipesrc
;
10534 ret
= intel_ring_begin(ring
, 4);
10538 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
10539 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
10540 intel_ring_emit(ring
, fb
->pitches
[0] | obj
->tiling_mode
);
10541 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
10543 /* Contrary to the suggestions in the documentation,
10544 * "Enable Panel Fitter" does not seem to be required when page
10545 * flipping with a non-native mode, and worse causes a normal
10547 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
10550 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
10551 intel_ring_emit(ring
, pf
| pipesrc
);
10553 intel_mark_page_flip_active(intel_crtc
);
10554 __intel_ring_advance(ring
);
10558 static int intel_gen7_queue_flip(struct drm_device
*dev
,
10559 struct drm_crtc
*crtc
,
10560 struct drm_framebuffer
*fb
,
10561 struct drm_i915_gem_object
*obj
,
10562 struct intel_engine_cs
*ring
,
10565 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10566 uint32_t plane_bit
= 0;
10569 switch (intel_crtc
->plane
) {
10571 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
10574 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
10577 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
10580 WARN_ONCE(1, "unknown plane in flip command\n");
10585 if (ring
->id
== RCS
) {
10588 * On Gen 8, SRM is now taking an extra dword to accommodate
10589 * 48bits addresses, and we need a NOOP for the batch size to
10597 * BSpec MI_DISPLAY_FLIP for IVB:
10598 * "The full packet must be contained within the same cache line."
10600 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
10601 * cacheline, if we ever start emitting more commands before
10602 * the MI_DISPLAY_FLIP we may need to first emit everything else,
10603 * then do the cacheline alignment, and finally emit the
10606 ret
= intel_ring_cacheline_align(ring
);
10610 ret
= intel_ring_begin(ring
, len
);
10614 /* Unmask the flip-done completion message. Note that the bspec says that
10615 * we should do this for both the BCS and RCS, and that we must not unmask
10616 * more than one flip event at any time (or ensure that one flip message
10617 * can be sent by waiting for flip-done prior to queueing new flips).
10618 * Experimentation says that BCS works despite DERRMR masking all
10619 * flip-done completion events and that unmasking all planes at once
10620 * for the RCS also doesn't appear to drop events. Setting the DERRMR
10621 * to zero does lead to lockups within MI_DISPLAY_FLIP.
10623 if (ring
->id
== RCS
) {
10624 intel_ring_emit(ring
, MI_LOAD_REGISTER_IMM(1));
10625 intel_ring_emit(ring
, DERRMR
);
10626 intel_ring_emit(ring
, ~(DERRMR_PIPEA_PRI_FLIP_DONE
|
10627 DERRMR_PIPEB_PRI_FLIP_DONE
|
10628 DERRMR_PIPEC_PRI_FLIP_DONE
));
10630 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM_GEN8(1) |
10631 MI_SRM_LRM_GLOBAL_GTT
);
10633 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM(1) |
10634 MI_SRM_LRM_GLOBAL_GTT
);
10635 intel_ring_emit(ring
, DERRMR
);
10636 intel_ring_emit(ring
, ring
->scratch
.gtt_offset
+ 256);
10637 if (IS_GEN8(dev
)) {
10638 intel_ring_emit(ring
, 0);
10639 intel_ring_emit(ring
, MI_NOOP
);
10643 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
| plane_bit
);
10644 intel_ring_emit(ring
, (fb
->pitches
[0] | obj
->tiling_mode
));
10645 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
10646 intel_ring_emit(ring
, (MI_NOOP
));
10648 intel_mark_page_flip_active(intel_crtc
);
10649 __intel_ring_advance(ring
);
10653 static bool use_mmio_flip(struct intel_engine_cs
*ring
,
10654 struct drm_i915_gem_object
*obj
)
10657 * This is not being used for older platforms, because
10658 * non-availability of flip done interrupt forces us to use
10659 * CS flips. Older platforms derive flip done using some clever
10660 * tricks involving the flip_pending status bits and vblank irqs.
10661 * So using MMIO flips there would disrupt this mechanism.
10667 if (INTEL_INFO(ring
->dev
)->gen
< 5)
10670 if (i915
.use_mmio_flip
< 0)
10672 else if (i915
.use_mmio_flip
> 0)
10674 else if (i915
.enable_execlists
)
10677 return ring
!= i915_gem_request_get_ring(obj
->last_read_req
);
10680 static void skl_do_mmio_flip(struct intel_crtc
*intel_crtc
)
10682 struct drm_device
*dev
= intel_crtc
->base
.dev
;
10683 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10684 struct drm_framebuffer
*fb
= intel_crtc
->base
.primary
->fb
;
10685 const enum pipe pipe
= intel_crtc
->pipe
;
10688 ctl
= I915_READ(PLANE_CTL(pipe
, 0));
10689 ctl
&= ~PLANE_CTL_TILED_MASK
;
10690 switch (fb
->modifier
[0]) {
10691 case DRM_FORMAT_MOD_NONE
:
10693 case I915_FORMAT_MOD_X_TILED
:
10694 ctl
|= PLANE_CTL_TILED_X
;
10696 case I915_FORMAT_MOD_Y_TILED
:
10697 ctl
|= PLANE_CTL_TILED_Y
;
10699 case I915_FORMAT_MOD_Yf_TILED
:
10700 ctl
|= PLANE_CTL_TILED_YF
;
10703 MISSING_CASE(fb
->modifier
[0]);
10707 * The stride is either expressed as a multiple of 64 bytes chunks for
10708 * linear buffers or in number of tiles for tiled buffers.
10710 stride
= fb
->pitches
[0] /
10711 intel_fb_stride_alignment(dev
, fb
->modifier
[0],
10715 * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on
10716 * PLANE_SURF updates, the update is then guaranteed to be atomic.
10718 I915_WRITE(PLANE_CTL(pipe
, 0), ctl
);
10719 I915_WRITE(PLANE_STRIDE(pipe
, 0), stride
);
10721 I915_WRITE(PLANE_SURF(pipe
, 0), intel_crtc
->unpin_work
->gtt_offset
);
10722 POSTING_READ(PLANE_SURF(pipe
, 0));
10725 static void ilk_do_mmio_flip(struct intel_crtc
*intel_crtc
)
10727 struct drm_device
*dev
= intel_crtc
->base
.dev
;
10728 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10729 struct intel_framebuffer
*intel_fb
=
10730 to_intel_framebuffer(intel_crtc
->base
.primary
->fb
);
10731 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
10735 reg
= DSPCNTR(intel_crtc
->plane
);
10736 dspcntr
= I915_READ(reg
);
10738 if (obj
->tiling_mode
!= I915_TILING_NONE
)
10739 dspcntr
|= DISPPLANE_TILED
;
10741 dspcntr
&= ~DISPPLANE_TILED
;
10743 I915_WRITE(reg
, dspcntr
);
10745 I915_WRITE(DSPSURF(intel_crtc
->plane
),
10746 intel_crtc
->unpin_work
->gtt_offset
);
10747 POSTING_READ(DSPSURF(intel_crtc
->plane
));
10752 * XXX: This is the temporary way to update the plane registers until we get
10753 * around to using the usual plane update functions for MMIO flips
10755 static void intel_do_mmio_flip(struct intel_crtc
*intel_crtc
)
10757 struct drm_device
*dev
= intel_crtc
->base
.dev
;
10758 bool atomic_update
;
10759 u32 start_vbl_count
;
10761 intel_mark_page_flip_active(intel_crtc
);
10763 atomic_update
= intel_pipe_update_start(intel_crtc
, &start_vbl_count
);
10765 if (INTEL_INFO(dev
)->gen
>= 9)
10766 skl_do_mmio_flip(intel_crtc
);
10768 /* use_mmio_flip() retricts MMIO flips to ilk+ */
10769 ilk_do_mmio_flip(intel_crtc
);
10772 intel_pipe_update_end(intel_crtc
, start_vbl_count
);
10775 static void intel_mmio_flip_work_func(struct work_struct
*work
)
10777 struct intel_mmio_flip
*mmio_flip
=
10778 container_of(work
, struct intel_mmio_flip
, work
);
10781 WARN_ON(__i915_wait_request(mmio_flip
->rq
,
10782 mmio_flip
->crtc
->reset_counter
,
10783 false, NULL
, NULL
));
10785 intel_do_mmio_flip(mmio_flip
->crtc
);
10787 i915_gem_request_unreference__unlocked(mmio_flip
->rq
);
10791 static int intel_queue_mmio_flip(struct drm_device
*dev
,
10792 struct drm_crtc
*crtc
,
10793 struct drm_framebuffer
*fb
,
10794 struct drm_i915_gem_object
*obj
,
10795 struct intel_engine_cs
*ring
,
10798 struct intel_mmio_flip
*mmio_flip
;
10800 mmio_flip
= kmalloc(sizeof(*mmio_flip
), GFP_KERNEL
);
10801 if (mmio_flip
== NULL
)
10804 mmio_flip
->rq
= i915_gem_request_reference(obj
->last_write_req
);
10805 mmio_flip
->crtc
= to_intel_crtc(crtc
);
10807 INIT_WORK(&mmio_flip
->work
, intel_mmio_flip_work_func
);
10808 schedule_work(&mmio_flip
->work
);
10813 static int intel_default_queue_flip(struct drm_device
*dev
,
10814 struct drm_crtc
*crtc
,
10815 struct drm_framebuffer
*fb
,
10816 struct drm_i915_gem_object
*obj
,
10817 struct intel_engine_cs
*ring
,
10823 static bool __intel_pageflip_stall_check(struct drm_device
*dev
,
10824 struct drm_crtc
*crtc
)
10826 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10827 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10828 struct intel_unpin_work
*work
= intel_crtc
->unpin_work
;
10831 if (atomic_read(&work
->pending
) >= INTEL_FLIP_COMPLETE
)
10834 if (!work
->enable_stall_check
)
10837 if (work
->flip_ready_vblank
== 0) {
10838 if (work
->flip_queued_req
&&
10839 !i915_gem_request_completed(work
->flip_queued_req
, true))
10842 work
->flip_ready_vblank
= drm_crtc_vblank_count(crtc
);
10845 if (drm_crtc_vblank_count(crtc
) - work
->flip_ready_vblank
< 3)
10848 /* Potential stall - if we see that the flip has happened,
10849 * assume a missed interrupt. */
10850 if (INTEL_INFO(dev
)->gen
>= 4)
10851 addr
= I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc
->plane
)));
10853 addr
= I915_READ(DSPADDR(intel_crtc
->plane
));
10855 /* There is a potential issue here with a false positive after a flip
10856 * to the same address. We could address this by checking for a
10857 * non-incrementing frame counter.
10859 return addr
== work
->gtt_offset
;
10862 void intel_check_page_flip(struct drm_device
*dev
, int pipe
)
10864 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10865 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
10866 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10867 struct intel_unpin_work
*work
;
10869 WARN_ON(!in_interrupt());
10874 spin_lock(&dev
->event_lock
);
10875 work
= intel_crtc
->unpin_work
;
10876 if (work
!= NULL
&& __intel_pageflip_stall_check(dev
, crtc
)) {
10877 WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n",
10878 work
->flip_queued_vblank
, drm_vblank_count(dev
, pipe
));
10879 page_flip_completed(intel_crtc
);
10882 if (work
!= NULL
&&
10883 drm_vblank_count(dev
, pipe
) - work
->flip_queued_vblank
> 1)
10884 intel_queue_rps_boost_for_request(dev
, work
->flip_queued_req
);
10885 spin_unlock(&dev
->event_lock
);
10888 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
10889 struct drm_framebuffer
*fb
,
10890 struct drm_pending_vblank_event
*event
,
10891 uint32_t page_flip_flags
)
10893 struct drm_device
*dev
= crtc
->dev
;
10894 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10895 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
10896 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
10897 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
10898 struct drm_plane
*primary
= crtc
->primary
;
10899 enum pipe pipe
= intel_crtc
->pipe
;
10900 struct intel_unpin_work
*work
;
10901 struct intel_engine_cs
*ring
;
10906 * drm_mode_page_flip_ioctl() should already catch this, but double
10907 * check to be safe. In the future we may enable pageflipping from
10908 * a disabled primary plane.
10910 if (WARN_ON(intel_fb_obj(old_fb
) == NULL
))
10913 /* Can't change pixel format via MI display flips. */
10914 if (fb
->pixel_format
!= crtc
->primary
->fb
->pixel_format
)
10918 * TILEOFF/LINOFF registers can't be changed via MI display flips.
10919 * Note that pitch changes could also affect these register.
10921 if (INTEL_INFO(dev
)->gen
> 3 &&
10922 (fb
->offsets
[0] != crtc
->primary
->fb
->offsets
[0] ||
10923 fb
->pitches
[0] != crtc
->primary
->fb
->pitches
[0]))
10926 if (i915_terminally_wedged(&dev_priv
->gpu_error
))
10929 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
10933 work
->event
= event
;
10935 work
->old_fb
= old_fb
;
10936 INIT_WORK(&work
->work
, intel_unpin_work_fn
);
10938 ret
= drm_crtc_vblank_get(crtc
);
10942 /* We borrow the event spin lock for protecting unpin_work */
10943 spin_lock_irq(&dev
->event_lock
);
10944 if (intel_crtc
->unpin_work
) {
10945 /* Before declaring the flip queue wedged, check if
10946 * the hardware completed the operation behind our backs.
10948 if (__intel_pageflip_stall_check(dev
, crtc
)) {
10949 DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
10950 page_flip_completed(intel_crtc
);
10952 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
10953 spin_unlock_irq(&dev
->event_lock
);
10955 drm_crtc_vblank_put(crtc
);
10960 intel_crtc
->unpin_work
= work
;
10961 spin_unlock_irq(&dev
->event_lock
);
10963 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
10964 flush_workqueue(dev_priv
->wq
);
10966 /* Reference the objects for the scheduled work. */
10967 drm_framebuffer_reference(work
->old_fb
);
10968 drm_gem_object_reference(&obj
->base
);
10970 crtc
->primary
->fb
= fb
;
10971 update_state_fb(crtc
->primary
);
10973 work
->pending_flip_obj
= obj
;
10975 ret
= i915_mutex_lock_interruptible(dev
);
10979 atomic_inc(&intel_crtc
->unpin_work_count
);
10980 intel_crtc
->reset_counter
= atomic_read(&dev_priv
->gpu_error
.reset_counter
);
10982 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
10983 work
->flip_count
= I915_READ(PIPE_FLIPCOUNT_GM45(pipe
)) + 1;
10985 if (IS_VALLEYVIEW(dev
)) {
10986 ring
= &dev_priv
->ring
[BCS
];
10987 if (obj
->tiling_mode
!= intel_fb_obj(work
->old_fb
)->tiling_mode
)
10988 /* vlv: DISPLAY_FLIP fails to change tiling */
10990 } else if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
)) {
10991 ring
= &dev_priv
->ring
[BCS
];
10992 } else if (INTEL_INFO(dev
)->gen
>= 7) {
10993 ring
= i915_gem_request_get_ring(obj
->last_read_req
);
10994 if (ring
== NULL
|| ring
->id
!= RCS
)
10995 ring
= &dev_priv
->ring
[BCS
];
10997 ring
= &dev_priv
->ring
[RCS
];
11000 mmio_flip
= use_mmio_flip(ring
, obj
);
11002 /* When using CS flips, we want to emit semaphores between rings.
11003 * However, when using mmio flips we will create a task to do the
11004 * synchronisation, so all we want here is to pin the framebuffer
11005 * into the display plane and skip any waits.
11007 ret
= intel_pin_and_fence_fb_obj(crtc
->primary
, fb
,
11008 crtc
->primary
->state
,
11009 mmio_flip
? i915_gem_request_get_ring(obj
->last_read_req
) : ring
);
11011 goto cleanup_pending
;
11013 work
->gtt_offset
= intel_plane_obj_offset(to_intel_plane(primary
), obj
)
11014 + intel_crtc
->dspaddr_offset
;
11017 ret
= intel_queue_mmio_flip(dev
, crtc
, fb
, obj
, ring
,
11020 goto cleanup_unpin
;
11022 i915_gem_request_assign(&work
->flip_queued_req
,
11023 obj
->last_write_req
);
11025 if (obj
->last_write_req
) {
11026 ret
= i915_gem_check_olr(obj
->last_write_req
);
11028 goto cleanup_unpin
;
11031 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
, ring
,
11034 goto cleanup_unpin
;
11036 i915_gem_request_assign(&work
->flip_queued_req
,
11037 intel_ring_get_request(ring
));
11040 work
->flip_queued_vblank
= drm_crtc_vblank_count(crtc
);
11041 work
->enable_stall_check
= true;
11043 i915_gem_track_fb(intel_fb_obj(work
->old_fb
), obj
,
11044 INTEL_FRONTBUFFER_PRIMARY(pipe
));
11046 intel_fbc_disable(dev
);
11047 intel_frontbuffer_flip_prepare(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
11048 mutex_unlock(&dev
->struct_mutex
);
11050 trace_i915_flip_request(intel_crtc
->plane
, obj
);
11055 intel_unpin_fb_obj(fb
, crtc
->primary
->state
);
11057 atomic_dec(&intel_crtc
->unpin_work_count
);
11058 mutex_unlock(&dev
->struct_mutex
);
11060 crtc
->primary
->fb
= old_fb
;
11061 update_state_fb(crtc
->primary
);
11063 drm_gem_object_unreference_unlocked(&obj
->base
);
11064 drm_framebuffer_unreference(work
->old_fb
);
11066 spin_lock_irq(&dev
->event_lock
);
11067 intel_crtc
->unpin_work
= NULL
;
11068 spin_unlock_irq(&dev
->event_lock
);
11070 drm_crtc_vblank_put(crtc
);
11076 ret
= intel_plane_restore(primary
);
11077 if (ret
== 0 && event
) {
11078 spin_lock_irq(&dev
->event_lock
);
11079 drm_send_vblank_event(dev
, pipe
, event
);
11080 spin_unlock_irq(&dev
->event_lock
);
11086 static const struct drm_crtc_helper_funcs intel_helper_funcs
= {
11087 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
11088 .load_lut
= intel_crtc_load_lut
,
11089 .atomic_begin
= intel_begin_crtc_commit
,
11090 .atomic_flush
= intel_finish_crtc_commit
,
11094 * intel_modeset_update_staged_output_state
11096 * Updates the staged output configuration state, e.g. after we've read out the
11097 * current hw state.
11099 static void intel_modeset_update_staged_output_state(struct drm_device
*dev
)
11101 struct intel_crtc
*crtc
;
11102 struct intel_encoder
*encoder
;
11103 struct intel_connector
*connector
;
11105 for_each_intel_connector(dev
, connector
) {
11106 connector
->new_encoder
=
11107 to_intel_encoder(connector
->base
.encoder
);
11110 for_each_intel_encoder(dev
, encoder
) {
11111 encoder
->new_crtc
=
11112 to_intel_crtc(encoder
->base
.crtc
);
11115 for_each_intel_crtc(dev
, crtc
) {
11116 crtc
->new_enabled
= crtc
->base
.state
->enable
;
11120 /* Transitional helper to copy current connector/encoder state to
11121 * connector->state. This is needed so that code that is partially
11122 * converted to atomic does the right thing.
11124 static void intel_modeset_update_connector_atomic_state(struct drm_device
*dev
)
11126 struct intel_connector
*connector
;
11128 for_each_intel_connector(dev
, connector
) {
11129 if (connector
->base
.encoder
) {
11130 connector
->base
.state
->best_encoder
=
11131 connector
->base
.encoder
;
11132 connector
->base
.state
->crtc
=
11133 connector
->base
.encoder
->crtc
;
11135 connector
->base
.state
->best_encoder
= NULL
;
11136 connector
->base
.state
->crtc
= NULL
;
11141 /* Fixup legacy state after an atomic state swap.
11143 static void intel_modeset_fixup_state(struct drm_atomic_state
*state
)
11145 struct intel_crtc
*crtc
;
11146 struct intel_encoder
*encoder
;
11147 struct intel_connector
*connector
;
11149 for_each_intel_connector(state
->dev
, connector
) {
11150 connector
->base
.encoder
= connector
->base
.state
->best_encoder
;
11151 if (connector
->base
.encoder
)
11152 connector
->base
.encoder
->crtc
=
11153 connector
->base
.state
->crtc
;
11156 /* Update crtc of disabled encoders */
11157 for_each_intel_encoder(state
->dev
, encoder
) {
11158 int num_connectors
= 0;
11160 for_each_intel_connector(state
->dev
, connector
)
11161 if (connector
->base
.encoder
== &encoder
->base
)
11164 if (num_connectors
== 0)
11165 encoder
->base
.crtc
= NULL
;
11168 for_each_intel_crtc(state
->dev
, crtc
) {
11169 crtc
->base
.enabled
= crtc
->base
.state
->enable
;
11170 crtc
->config
= to_intel_crtc_state(crtc
->base
.state
);
11173 /* Copy the new configuration to the staged state, to keep the few
11174 * pieces of code that haven't been converted yet happy */
11175 intel_modeset_update_staged_output_state(state
->dev
);
11179 connected_sink_compute_bpp(struct intel_connector
*connector
,
11180 struct intel_crtc_state
*pipe_config
)
11182 int bpp
= pipe_config
->pipe_bpp
;
11184 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
11185 connector
->base
.base
.id
,
11186 connector
->base
.name
);
11188 /* Don't use an invalid EDID bpc value */
11189 if (connector
->base
.display_info
.bpc
&&
11190 connector
->base
.display_info
.bpc
* 3 < bpp
) {
11191 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
11192 bpp
, connector
->base
.display_info
.bpc
*3);
11193 pipe_config
->pipe_bpp
= connector
->base
.display_info
.bpc
*3;
11196 /* Clamp bpp to 8 on screens without EDID 1.4 */
11197 if (connector
->base
.display_info
.bpc
== 0 && bpp
> 24) {
11198 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
11200 pipe_config
->pipe_bpp
= 24;
11205 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
11206 struct intel_crtc_state
*pipe_config
)
11208 struct drm_device
*dev
= crtc
->base
.dev
;
11209 struct drm_atomic_state
*state
;
11210 struct drm_connector
*connector
;
11211 struct drm_connector_state
*connector_state
;
11214 if ((IS_G4X(dev
) || IS_VALLEYVIEW(dev
)))
11216 else if (INTEL_INFO(dev
)->gen
>= 5)
11222 pipe_config
->pipe_bpp
= bpp
;
11224 state
= pipe_config
->base
.state
;
11226 /* Clamp display bpp to EDID value */
11227 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11228 if (connector_state
->crtc
!= &crtc
->base
)
11231 connected_sink_compute_bpp(to_intel_connector(connector
),
11238 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
11240 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11241 "type: 0x%x flags: 0x%x\n",
11243 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
11244 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
11245 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
11246 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
11249 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
11250 struct intel_crtc_state
*pipe_config
,
11251 const char *context
)
11253 struct drm_device
*dev
= crtc
->base
.dev
;
11254 struct drm_plane
*plane
;
11255 struct intel_plane
*intel_plane
;
11256 struct intel_plane_state
*state
;
11257 struct drm_framebuffer
*fb
;
11259 DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc
->base
.base
.id
,
11260 context
, pipe_config
, pipe_name(crtc
->pipe
));
11262 DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config
->cpu_transcoder
));
11263 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
11264 pipe_config
->pipe_bpp
, pipe_config
->dither
);
11265 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11266 pipe_config
->has_pch_encoder
,
11267 pipe_config
->fdi_lanes
,
11268 pipe_config
->fdi_m_n
.gmch_m
, pipe_config
->fdi_m_n
.gmch_n
,
11269 pipe_config
->fdi_m_n
.link_m
, pipe_config
->fdi_m_n
.link_n
,
11270 pipe_config
->fdi_m_n
.tu
);
11271 DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11272 pipe_config
->has_dp_encoder
,
11273 pipe_config
->dp_m_n
.gmch_m
, pipe_config
->dp_m_n
.gmch_n
,
11274 pipe_config
->dp_m_n
.link_m
, pipe_config
->dp_m_n
.link_n
,
11275 pipe_config
->dp_m_n
.tu
);
11277 DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
11278 pipe_config
->has_dp_encoder
,
11279 pipe_config
->dp_m2_n2
.gmch_m
,
11280 pipe_config
->dp_m2_n2
.gmch_n
,
11281 pipe_config
->dp_m2_n2
.link_m
,
11282 pipe_config
->dp_m2_n2
.link_n
,
11283 pipe_config
->dp_m2_n2
.tu
);
11285 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
11286 pipe_config
->has_audio
,
11287 pipe_config
->has_infoframe
);
11289 DRM_DEBUG_KMS("requested mode:\n");
11290 drm_mode_debug_printmodeline(&pipe_config
->base
.mode
);
11291 DRM_DEBUG_KMS("adjusted mode:\n");
11292 drm_mode_debug_printmodeline(&pipe_config
->base
.adjusted_mode
);
11293 intel_dump_crtc_timings(&pipe_config
->base
.adjusted_mode
);
11294 DRM_DEBUG_KMS("port clock: %d\n", pipe_config
->port_clock
);
11295 DRM_DEBUG_KMS("pipe src size: %dx%d\n",
11296 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
11297 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
11299 pipe_config
->scaler_state
.scaler_users
,
11300 pipe_config
->scaler_state
.scaler_id
);
11301 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
11302 pipe_config
->gmch_pfit
.control
,
11303 pipe_config
->gmch_pfit
.pgm_ratios
,
11304 pipe_config
->gmch_pfit
.lvds_border_bits
);
11305 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
11306 pipe_config
->pch_pfit
.pos
,
11307 pipe_config
->pch_pfit
.size
,
11308 pipe_config
->pch_pfit
.enabled
? "enabled" : "disabled");
11309 DRM_DEBUG_KMS("ips: %i\n", pipe_config
->ips_enabled
);
11310 DRM_DEBUG_KMS("double wide: %i\n", pipe_config
->double_wide
);
11312 if (IS_BROXTON(dev
)) {
11313 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, "
11314 "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, "
11315 "pll6: 0x%x, pll8: 0x%x, pcsdw12: 0x%x\n",
11316 pipe_config
->ddi_pll_sel
,
11317 pipe_config
->dpll_hw_state
.ebb0
,
11318 pipe_config
->dpll_hw_state
.pll0
,
11319 pipe_config
->dpll_hw_state
.pll1
,
11320 pipe_config
->dpll_hw_state
.pll2
,
11321 pipe_config
->dpll_hw_state
.pll3
,
11322 pipe_config
->dpll_hw_state
.pll6
,
11323 pipe_config
->dpll_hw_state
.pll8
,
11324 pipe_config
->dpll_hw_state
.pcsdw12
);
11325 } else if (IS_SKYLAKE(dev
)) {
11326 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: "
11327 "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n",
11328 pipe_config
->ddi_pll_sel
,
11329 pipe_config
->dpll_hw_state
.ctrl1
,
11330 pipe_config
->dpll_hw_state
.cfgcr1
,
11331 pipe_config
->dpll_hw_state
.cfgcr2
);
11332 } else if (HAS_DDI(dev
)) {
11333 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: wrpll: 0x%x\n",
11334 pipe_config
->ddi_pll_sel
,
11335 pipe_config
->dpll_hw_state
.wrpll
);
11337 DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, "
11338 "fp0: 0x%x, fp1: 0x%x\n",
11339 pipe_config
->dpll_hw_state
.dpll
,
11340 pipe_config
->dpll_hw_state
.dpll_md
,
11341 pipe_config
->dpll_hw_state
.fp0
,
11342 pipe_config
->dpll_hw_state
.fp1
);
11345 DRM_DEBUG_KMS("planes on this crtc\n");
11346 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
11347 intel_plane
= to_intel_plane(plane
);
11348 if (intel_plane
->pipe
!= crtc
->pipe
)
11351 state
= to_intel_plane_state(plane
->state
);
11352 fb
= state
->base
.fb
;
11354 DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d "
11355 "disabled, scaler_id = %d\n",
11356 plane
->type
== DRM_PLANE_TYPE_CURSOR
? "CURSOR" : "STANDARD",
11357 plane
->base
.id
, intel_plane
->pipe
,
11358 (crtc
->base
.primary
== plane
) ? 0 : intel_plane
->plane
+ 1,
11359 drm_plane_index(plane
), state
->scaler_id
);
11363 DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled",
11364 plane
->type
== DRM_PLANE_TYPE_CURSOR
? "CURSOR" : "STANDARD",
11365 plane
->base
.id
, intel_plane
->pipe
,
11366 crtc
->base
.primary
== plane
? 0 : intel_plane
->plane
+ 1,
11367 drm_plane_index(plane
));
11368 DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x",
11369 fb
->base
.id
, fb
->width
, fb
->height
, fb
->pixel_format
);
11370 DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n",
11372 state
->src
.x1
>> 16, state
->src
.y1
>> 16,
11373 drm_rect_width(&state
->src
) >> 16,
11374 drm_rect_height(&state
->src
) >> 16,
11375 state
->dst
.x1
, state
->dst
.y1
,
11376 drm_rect_width(&state
->dst
), drm_rect_height(&state
->dst
));
11380 static bool encoders_cloneable(const struct intel_encoder
*a
,
11381 const struct intel_encoder
*b
)
11383 /* masks could be asymmetric, so check both ways */
11384 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
11385 b
->cloneable
& (1 << a
->type
));
11388 static bool check_single_encoder_cloning(struct drm_atomic_state
*state
,
11389 struct intel_crtc
*crtc
,
11390 struct intel_encoder
*encoder
)
11392 struct intel_encoder
*source_encoder
;
11393 struct drm_connector
*connector
;
11394 struct drm_connector_state
*connector_state
;
11397 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11398 if (connector_state
->crtc
!= &crtc
->base
)
11402 to_intel_encoder(connector_state
->best_encoder
);
11403 if (!encoders_cloneable(encoder
, source_encoder
))
11410 static bool check_encoder_cloning(struct drm_atomic_state
*state
,
11411 struct intel_crtc
*crtc
)
11413 struct intel_encoder
*encoder
;
11414 struct drm_connector
*connector
;
11415 struct drm_connector_state
*connector_state
;
11418 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11419 if (connector_state
->crtc
!= &crtc
->base
)
11422 encoder
= to_intel_encoder(connector_state
->best_encoder
);
11423 if (!check_single_encoder_cloning(state
, crtc
, encoder
))
11430 static bool check_digital_port_conflicts(struct drm_atomic_state
*state
)
11432 struct drm_device
*dev
= state
->dev
;
11433 struct intel_encoder
*encoder
;
11434 struct drm_connector
*connector
;
11435 struct drm_connector_state
*connector_state
;
11436 unsigned int used_ports
= 0;
11440 * Walk the connector list instead of the encoder
11441 * list to detect the problem on ddi platforms
11442 * where there's just one encoder per digital port.
11444 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11445 if (!connector_state
->best_encoder
)
11448 encoder
= to_intel_encoder(connector_state
->best_encoder
);
11450 WARN_ON(!connector_state
->crtc
);
11452 switch (encoder
->type
) {
11453 unsigned int port_mask
;
11454 case INTEL_OUTPUT_UNKNOWN
:
11455 if (WARN_ON(!HAS_DDI(dev
)))
11457 case INTEL_OUTPUT_DISPLAYPORT
:
11458 case INTEL_OUTPUT_HDMI
:
11459 case INTEL_OUTPUT_EDP
:
11460 port_mask
= 1 << enc_to_dig_port(&encoder
->base
)->port
;
11462 /* the same port mustn't appear more than once */
11463 if (used_ports
& port_mask
)
11466 used_ports
|= port_mask
;
11476 clear_intel_crtc_state(struct intel_crtc_state
*crtc_state
)
11478 struct drm_crtc_state tmp_state
;
11479 struct intel_crtc_scaler_state scaler_state
;
11480 struct intel_dpll_hw_state dpll_hw_state
;
11481 enum intel_dpll_id shared_dpll
;
11482 uint32_t ddi_pll_sel
;
11484 /* Clear only the intel specific part of the crtc state excluding scalers */
11485 tmp_state
= crtc_state
->base
;
11486 scaler_state
= crtc_state
->scaler_state
;
11487 shared_dpll
= crtc_state
->shared_dpll
;
11488 dpll_hw_state
= crtc_state
->dpll_hw_state
;
11489 ddi_pll_sel
= crtc_state
->ddi_pll_sel
;
11491 memset(crtc_state
, 0, sizeof *crtc_state
);
11493 crtc_state
->base
= tmp_state
;
11494 crtc_state
->scaler_state
= scaler_state
;
11495 crtc_state
->shared_dpll
= shared_dpll
;
11496 crtc_state
->dpll_hw_state
= dpll_hw_state
;
11497 crtc_state
->ddi_pll_sel
= ddi_pll_sel
;
11501 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
11502 struct drm_atomic_state
*state
,
11503 struct intel_crtc_state
*pipe_config
)
11505 struct intel_encoder
*encoder
;
11506 struct drm_connector
*connector
;
11507 struct drm_connector_state
*connector_state
;
11508 int base_bpp
, ret
= -EINVAL
;
11512 if (!check_encoder_cloning(state
, to_intel_crtc(crtc
))) {
11513 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
11517 if (!check_digital_port_conflicts(state
)) {
11518 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
11522 clear_intel_crtc_state(pipe_config
);
11524 pipe_config
->cpu_transcoder
=
11525 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
11528 * Sanitize sync polarity flags based on requested ones. If neither
11529 * positive or negative polarity is requested, treat this as meaning
11530 * negative polarity.
11532 if (!(pipe_config
->base
.adjusted_mode
.flags
&
11533 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
11534 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
11536 if (!(pipe_config
->base
.adjusted_mode
.flags
&
11537 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
11538 pipe_config
->base
.adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
11540 /* Compute a starting value for pipe_config->pipe_bpp taking the source
11541 * plane pixel format and any sink constraints into account. Returns the
11542 * source plane bpp so that dithering can be selected on mismatches
11543 * after encoders and crtc also have had their say. */
11544 base_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
11550 * Determine the real pipe dimensions. Note that stereo modes can
11551 * increase the actual pipe size due to the frame doubling and
11552 * insertion of additional space for blanks between the frame. This
11553 * is stored in the crtc timings. We use the requested mode to do this
11554 * computation to clearly distinguish it from the adjusted mode, which
11555 * can be changed by the connectors in the below retry loop.
11557 drm_crtc_get_hv_timing(&pipe_config
->base
.mode
,
11558 &pipe_config
->pipe_src_w
,
11559 &pipe_config
->pipe_src_h
);
11562 /* Ensure the port clock defaults are reset when retrying. */
11563 pipe_config
->port_clock
= 0;
11564 pipe_config
->pixel_multiplier
= 1;
11566 /* Fill in default crtc timings, allow encoders to overwrite them. */
11567 drm_mode_set_crtcinfo(&pipe_config
->base
.adjusted_mode
,
11568 CRTC_STEREO_DOUBLE
);
11570 /* Pass our mode to the connectors and the CRTC to give them a chance to
11571 * adjust it according to limitations or connector properties, and also
11572 * a chance to reject the mode entirely.
11574 for_each_connector_in_state(state
, connector
, connector_state
, i
) {
11575 if (connector_state
->crtc
!= crtc
)
11578 encoder
= to_intel_encoder(connector_state
->best_encoder
);
11580 if (!(encoder
->compute_config(encoder
, pipe_config
))) {
11581 DRM_DEBUG_KMS("Encoder config failure\n");
11586 /* Set default port clock if not overwritten by the encoder. Needs to be
11587 * done afterwards in case the encoder adjusts the mode. */
11588 if (!pipe_config
->port_clock
)
11589 pipe_config
->port_clock
= pipe_config
->base
.adjusted_mode
.crtc_clock
11590 * pipe_config
->pixel_multiplier
;
11592 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
11594 DRM_DEBUG_KMS("CRTC fixup failed\n");
11598 if (ret
== RETRY
) {
11599 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
11604 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11606 goto encoder_retry
;
11609 pipe_config
->dither
= pipe_config
->pipe_bpp
!= base_bpp
;
11610 DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
11611 base_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
11618 static bool intel_crtc_in_use(struct drm_crtc
*crtc
)
11620 struct drm_encoder
*encoder
;
11621 struct drm_device
*dev
= crtc
->dev
;
11623 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
11624 if (encoder
->crtc
== crtc
)
11631 needs_modeset(struct drm_crtc_state
*state
)
11633 return state
->mode_changed
|| state
->active_changed
;
11637 intel_modeset_update_state(struct drm_atomic_state
*state
)
11639 struct drm_device
*dev
= state
->dev
;
11640 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11641 struct intel_encoder
*intel_encoder
;
11642 struct drm_crtc
*crtc
;
11643 struct drm_crtc_state
*crtc_state
;
11644 struct drm_connector
*connector
;
11647 intel_shared_dpll_commit(dev_priv
);
11649 for_each_intel_encoder(dev
, intel_encoder
) {
11650 if (!intel_encoder
->base
.crtc
)
11653 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
)
11654 if (crtc
== intel_encoder
->base
.crtc
)
11657 if (crtc
!= intel_encoder
->base
.crtc
)
11660 if (crtc_state
->enable
&& needs_modeset(crtc_state
))
11661 intel_encoder
->connectors_active
= false;
11664 drm_atomic_helper_swap_state(state
->dev
, state
);
11665 intel_modeset_fixup_state(state
);
11667 /* Double check state. */
11668 for_each_crtc(dev
, crtc
) {
11669 WARN_ON(crtc
->state
->enable
!= intel_crtc_in_use(crtc
));
11672 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
11673 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
11676 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
)
11677 if (crtc
== connector
->encoder
->crtc
)
11680 if (crtc
!= connector
->encoder
->crtc
)
11683 if (crtc
->state
->enable
&& needs_modeset(crtc
->state
)) {
11684 struct drm_property
*dpms_property
=
11685 dev
->mode_config
.dpms_property
;
11687 connector
->dpms
= DRM_MODE_DPMS_ON
;
11688 drm_object_property_set_value(&connector
->base
,
11692 intel_encoder
= to_intel_encoder(connector
->encoder
);
11693 intel_encoder
->connectors_active
= true;
11699 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
11703 if (clock1
== clock2
)
11706 if (!clock1
|| !clock2
)
11709 diff
= abs(clock1
- clock2
);
11711 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
11717 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
11718 list_for_each_entry((intel_crtc), \
11719 &(dev)->mode_config.crtc_list, \
11721 if (mask & (1 <<(intel_crtc)->pipe))
11724 intel_pipe_config_compare(struct drm_device
*dev
,
11725 struct intel_crtc_state
*current_config
,
11726 struct intel_crtc_state
*pipe_config
)
11728 #define PIPE_CONF_CHECK_X(name) \
11729 if (current_config->name != pipe_config->name) { \
11730 DRM_ERROR("mismatch in " #name " " \
11731 "(expected 0x%08x, found 0x%08x)\n", \
11732 current_config->name, \
11733 pipe_config->name); \
11737 #define PIPE_CONF_CHECK_I(name) \
11738 if (current_config->name != pipe_config->name) { \
11739 DRM_ERROR("mismatch in " #name " " \
11740 "(expected %i, found %i)\n", \
11741 current_config->name, \
11742 pipe_config->name); \
11746 /* This is required for BDW+ where there is only one set of registers for
11747 * switching between high and low RR.
11748 * This macro can be used whenever a comparison has to be made between one
11749 * hw state and multiple sw state variables.
11751 #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \
11752 if ((current_config->name != pipe_config->name) && \
11753 (current_config->alt_name != pipe_config->name)) { \
11754 DRM_ERROR("mismatch in " #name " " \
11755 "(expected %i or %i, found %i)\n", \
11756 current_config->name, \
11757 current_config->alt_name, \
11758 pipe_config->name); \
11762 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
11763 if ((current_config->name ^ pipe_config->name) & (mask)) { \
11764 DRM_ERROR("mismatch in " #name "(" #mask ") " \
11765 "(expected %i, found %i)\n", \
11766 current_config->name & (mask), \
11767 pipe_config->name & (mask)); \
11771 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
11772 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
11773 DRM_ERROR("mismatch in " #name " " \
11774 "(expected %i, found %i)\n", \
11775 current_config->name, \
11776 pipe_config->name); \
11780 #define PIPE_CONF_QUIRK(quirk) \
11781 ((current_config->quirks | pipe_config->quirks) & (quirk))
11783 PIPE_CONF_CHECK_I(cpu_transcoder
);
11785 PIPE_CONF_CHECK_I(has_pch_encoder
);
11786 PIPE_CONF_CHECK_I(fdi_lanes
);
11787 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_m
);
11788 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_n
);
11789 PIPE_CONF_CHECK_I(fdi_m_n
.link_m
);
11790 PIPE_CONF_CHECK_I(fdi_m_n
.link_n
);
11791 PIPE_CONF_CHECK_I(fdi_m_n
.tu
);
11793 PIPE_CONF_CHECK_I(has_dp_encoder
);
11795 if (INTEL_INFO(dev
)->gen
< 8) {
11796 PIPE_CONF_CHECK_I(dp_m_n
.gmch_m
);
11797 PIPE_CONF_CHECK_I(dp_m_n
.gmch_n
);
11798 PIPE_CONF_CHECK_I(dp_m_n
.link_m
);
11799 PIPE_CONF_CHECK_I(dp_m_n
.link_n
);
11800 PIPE_CONF_CHECK_I(dp_m_n
.tu
);
11802 if (current_config
->has_drrs
) {
11803 PIPE_CONF_CHECK_I(dp_m2_n2
.gmch_m
);
11804 PIPE_CONF_CHECK_I(dp_m2_n2
.gmch_n
);
11805 PIPE_CONF_CHECK_I(dp_m2_n2
.link_m
);
11806 PIPE_CONF_CHECK_I(dp_m2_n2
.link_n
);
11807 PIPE_CONF_CHECK_I(dp_m2_n2
.tu
);
11810 PIPE_CONF_CHECK_I_ALT(dp_m_n
.gmch_m
, dp_m2_n2
.gmch_m
);
11811 PIPE_CONF_CHECK_I_ALT(dp_m_n
.gmch_n
, dp_m2_n2
.gmch_n
);
11812 PIPE_CONF_CHECK_I_ALT(dp_m_n
.link_m
, dp_m2_n2
.link_m
);
11813 PIPE_CONF_CHECK_I_ALT(dp_m_n
.link_n
, dp_m2_n2
.link_n
);
11814 PIPE_CONF_CHECK_I_ALT(dp_m_n
.tu
, dp_m2_n2
.tu
);
11817 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hdisplay
);
11818 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_htotal
);
11819 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_start
);
11820 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hblank_end
);
11821 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_start
);
11822 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_hsync_end
);
11824 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vdisplay
);
11825 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vtotal
);
11826 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_start
);
11827 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vblank_end
);
11828 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_start
);
11829 PIPE_CONF_CHECK_I(base
.adjusted_mode
.crtc_vsync_end
);
11831 PIPE_CONF_CHECK_I(pixel_multiplier
);
11832 PIPE_CONF_CHECK_I(has_hdmi_sink
);
11833 if ((INTEL_INFO(dev
)->gen
< 8 && !IS_HASWELL(dev
)) ||
11834 IS_VALLEYVIEW(dev
))
11835 PIPE_CONF_CHECK_I(limited_color_range
);
11836 PIPE_CONF_CHECK_I(has_infoframe
);
11838 PIPE_CONF_CHECK_I(has_audio
);
11840 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11841 DRM_MODE_FLAG_INTERLACE
);
11843 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
11844 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11845 DRM_MODE_FLAG_PHSYNC
);
11846 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11847 DRM_MODE_FLAG_NHSYNC
);
11848 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11849 DRM_MODE_FLAG_PVSYNC
);
11850 PIPE_CONF_CHECK_FLAGS(base
.adjusted_mode
.flags
,
11851 DRM_MODE_FLAG_NVSYNC
);
11854 PIPE_CONF_CHECK_I(pipe_src_w
);
11855 PIPE_CONF_CHECK_I(pipe_src_h
);
11858 * FIXME: BIOS likes to set up a cloned config with lvds+external
11859 * screen. Since we don't yet re-compute the pipe config when moving
11860 * just the lvds port away to another pipe the sw tracking won't match.
11862 * Proper atomic modesets with recomputed global state will fix this.
11863 * Until then just don't check gmch state for inherited modes.
11865 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE
)) {
11866 PIPE_CONF_CHECK_I(gmch_pfit
.control
);
11867 /* pfit ratios are autocomputed by the hw on gen4+ */
11868 if (INTEL_INFO(dev
)->gen
< 4)
11869 PIPE_CONF_CHECK_I(gmch_pfit
.pgm_ratios
);
11870 PIPE_CONF_CHECK_I(gmch_pfit
.lvds_border_bits
);
11873 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
11874 if (current_config
->pch_pfit
.enabled
) {
11875 PIPE_CONF_CHECK_I(pch_pfit
.pos
);
11876 PIPE_CONF_CHECK_I(pch_pfit
.size
);
11879 PIPE_CONF_CHECK_I(scaler_state
.scaler_id
);
11881 /* BDW+ don't expose a synchronous way to read the state */
11882 if (IS_HASWELL(dev
))
11883 PIPE_CONF_CHECK_I(ips_enabled
);
11885 PIPE_CONF_CHECK_I(double_wide
);
11887 PIPE_CONF_CHECK_X(ddi_pll_sel
);
11889 PIPE_CONF_CHECK_I(shared_dpll
);
11890 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
11891 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
11892 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
11893 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
11894 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
11895 PIPE_CONF_CHECK_X(dpll_hw_state
.ctrl1
);
11896 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr1
);
11897 PIPE_CONF_CHECK_X(dpll_hw_state
.cfgcr2
);
11899 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5)
11900 PIPE_CONF_CHECK_I(pipe_bpp
);
11902 PIPE_CONF_CHECK_CLOCK_FUZZY(base
.adjusted_mode
.crtc_clock
);
11903 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
11905 #undef PIPE_CONF_CHECK_X
11906 #undef PIPE_CONF_CHECK_I
11907 #undef PIPE_CONF_CHECK_I_ALT
11908 #undef PIPE_CONF_CHECK_FLAGS
11909 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
11910 #undef PIPE_CONF_QUIRK
11915 static void check_wm_state(struct drm_device
*dev
)
11917 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11918 struct skl_ddb_allocation hw_ddb
, *sw_ddb
;
11919 struct intel_crtc
*intel_crtc
;
11922 if (INTEL_INFO(dev
)->gen
< 9)
11925 skl_ddb_get_hw_state(dev_priv
, &hw_ddb
);
11926 sw_ddb
= &dev_priv
->wm
.skl_hw
.ddb
;
11928 for_each_intel_crtc(dev
, intel_crtc
) {
11929 struct skl_ddb_entry
*hw_entry
, *sw_entry
;
11930 const enum pipe pipe
= intel_crtc
->pipe
;
11932 if (!intel_crtc
->active
)
11936 for_each_plane(dev_priv
, pipe
, plane
) {
11937 hw_entry
= &hw_ddb
.plane
[pipe
][plane
];
11938 sw_entry
= &sw_ddb
->plane
[pipe
][plane
];
11940 if (skl_ddb_entry_equal(hw_entry
, sw_entry
))
11943 DRM_ERROR("mismatch in DDB state pipe %c plane %d "
11944 "(expected (%u,%u), found (%u,%u))\n",
11945 pipe_name(pipe
), plane
+ 1,
11946 sw_entry
->start
, sw_entry
->end
,
11947 hw_entry
->start
, hw_entry
->end
);
11951 hw_entry
= &hw_ddb
.cursor
[pipe
];
11952 sw_entry
= &sw_ddb
->cursor
[pipe
];
11954 if (skl_ddb_entry_equal(hw_entry
, sw_entry
))
11957 DRM_ERROR("mismatch in DDB state pipe %c cursor "
11958 "(expected (%u,%u), found (%u,%u))\n",
11960 sw_entry
->start
, sw_entry
->end
,
11961 hw_entry
->start
, hw_entry
->end
);
11966 check_connector_state(struct drm_device
*dev
)
11968 struct intel_connector
*connector
;
11970 for_each_intel_connector(dev
, connector
) {
11971 /* This also checks the encoder/connector hw state with the
11972 * ->get_hw_state callbacks. */
11973 intel_connector_check_state(connector
);
11975 I915_STATE_WARN(&connector
->new_encoder
->base
!= connector
->base
.encoder
,
11976 "connector's staged encoder doesn't match current encoder\n");
11981 check_encoder_state(struct drm_device
*dev
)
11983 struct intel_encoder
*encoder
;
11984 struct intel_connector
*connector
;
11986 for_each_intel_encoder(dev
, encoder
) {
11987 bool enabled
= false;
11988 bool active
= false;
11989 enum pipe pipe
, tracked_pipe
;
11991 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
11992 encoder
->base
.base
.id
,
11993 encoder
->base
.name
);
11995 I915_STATE_WARN(&encoder
->new_crtc
->base
!= encoder
->base
.crtc
,
11996 "encoder's stage crtc doesn't match current crtc\n");
11997 I915_STATE_WARN(encoder
->connectors_active
&& !encoder
->base
.crtc
,
11998 "encoder's active_connectors set, but no crtc\n");
12000 for_each_intel_connector(dev
, connector
) {
12001 if (connector
->base
.encoder
!= &encoder
->base
)
12004 if (connector
->base
.dpms
!= DRM_MODE_DPMS_OFF
)
12008 * for MST connectors if we unplug the connector is gone
12009 * away but the encoder is still connected to a crtc
12010 * until a modeset happens in response to the hotplug.
12012 if (!enabled
&& encoder
->base
.encoder_type
== DRM_MODE_ENCODER_DPMST
)
12015 I915_STATE_WARN(!!encoder
->base
.crtc
!= enabled
,
12016 "encoder's enabled state mismatch "
12017 "(expected %i, found %i)\n",
12018 !!encoder
->base
.crtc
, enabled
);
12019 I915_STATE_WARN(active
&& !encoder
->base
.crtc
,
12020 "active encoder with no crtc\n");
12022 I915_STATE_WARN(encoder
->connectors_active
!= active
,
12023 "encoder's computed active state doesn't match tracked active state "
12024 "(expected %i, found %i)\n", active
, encoder
->connectors_active
);
12026 active
= encoder
->get_hw_state(encoder
, &pipe
);
12027 I915_STATE_WARN(active
!= encoder
->connectors_active
,
12028 "encoder's hw state doesn't match sw tracking "
12029 "(expected %i, found %i)\n",
12030 encoder
->connectors_active
, active
);
12032 if (!encoder
->base
.crtc
)
12035 tracked_pipe
= to_intel_crtc(encoder
->base
.crtc
)->pipe
;
12036 I915_STATE_WARN(active
&& pipe
!= tracked_pipe
,
12037 "active encoder's pipe doesn't match"
12038 "(expected %i, found %i)\n",
12039 tracked_pipe
, pipe
);
12045 check_crtc_state(struct drm_device
*dev
)
12047 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12048 struct intel_crtc
*crtc
;
12049 struct intel_encoder
*encoder
;
12050 struct intel_crtc_state pipe_config
;
12052 for_each_intel_crtc(dev
, crtc
) {
12053 bool enabled
= false;
12054 bool active
= false;
12056 memset(&pipe_config
, 0, sizeof(pipe_config
));
12058 DRM_DEBUG_KMS("[CRTC:%d]\n",
12059 crtc
->base
.base
.id
);
12061 I915_STATE_WARN(crtc
->active
&& !crtc
->base
.state
->enable
,
12062 "active crtc, but not enabled in sw tracking\n");
12064 for_each_intel_encoder(dev
, encoder
) {
12065 if (encoder
->base
.crtc
!= &crtc
->base
)
12068 if (encoder
->connectors_active
)
12072 I915_STATE_WARN(active
!= crtc
->active
,
12073 "crtc's computed active state doesn't match tracked active state "
12074 "(expected %i, found %i)\n", active
, crtc
->active
);
12075 I915_STATE_WARN(enabled
!= crtc
->base
.state
->enable
,
12076 "crtc's computed enabled state doesn't match tracked enabled state "
12077 "(expected %i, found %i)\n", enabled
,
12078 crtc
->base
.state
->enable
);
12080 active
= dev_priv
->display
.get_pipe_config(crtc
,
12083 /* hw state is inconsistent with the pipe quirk */
12084 if ((crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
) ||
12085 (crtc
->pipe
== PIPE_B
&& dev_priv
->quirks
& QUIRK_PIPEB_FORCE
))
12086 active
= crtc
->active
;
12088 for_each_intel_encoder(dev
, encoder
) {
12090 if (encoder
->base
.crtc
!= &crtc
->base
)
12092 if (encoder
->get_hw_state(encoder
, &pipe
))
12093 encoder
->get_config(encoder
, &pipe_config
);
12096 I915_STATE_WARN(crtc
->active
!= active
,
12097 "crtc active state doesn't match with hw state "
12098 "(expected %i, found %i)\n", crtc
->active
, active
);
12101 !intel_pipe_config_compare(dev
, crtc
->config
, &pipe_config
)) {
12102 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12103 intel_dump_pipe_config(crtc
, &pipe_config
,
12105 intel_dump_pipe_config(crtc
, crtc
->config
,
12112 check_shared_dpll_state(struct drm_device
*dev
)
12114 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12115 struct intel_crtc
*crtc
;
12116 struct intel_dpll_hw_state dpll_hw_state
;
12119 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
12120 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
12121 int enabled_crtcs
= 0, active_crtcs
= 0;
12124 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
12126 DRM_DEBUG_KMS("%s\n", pll
->name
);
12128 active
= pll
->get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
12130 I915_STATE_WARN(pll
->active
> hweight32(pll
->config
.crtc_mask
),
12131 "more active pll users than references: %i vs %i\n",
12132 pll
->active
, hweight32(pll
->config
.crtc_mask
));
12133 I915_STATE_WARN(pll
->active
&& !pll
->on
,
12134 "pll in active use but not on in sw tracking\n");
12135 I915_STATE_WARN(pll
->on
&& !pll
->active
,
12136 "pll in on but not on in use in sw tracking\n");
12137 I915_STATE_WARN(pll
->on
!= active
,
12138 "pll on state mismatch (expected %i, found %i)\n",
12141 for_each_intel_crtc(dev
, crtc
) {
12142 if (crtc
->base
.state
->enable
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
12144 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
12147 I915_STATE_WARN(pll
->active
!= active_crtcs
,
12148 "pll active crtcs mismatch (expected %i, found %i)\n",
12149 pll
->active
, active_crtcs
);
12150 I915_STATE_WARN(hweight32(pll
->config
.crtc_mask
) != enabled_crtcs
,
12151 "pll enabled crtcs mismatch (expected %i, found %i)\n",
12152 hweight32(pll
->config
.crtc_mask
), enabled_crtcs
);
12154 I915_STATE_WARN(pll
->on
&& memcmp(&pll
->config
.hw_state
, &dpll_hw_state
,
12155 sizeof(dpll_hw_state
)),
12156 "pll hw state mismatch\n");
12161 intel_modeset_check_state(struct drm_device
*dev
)
12163 check_wm_state(dev
);
12164 check_connector_state(dev
);
12165 check_encoder_state(dev
);
12166 check_crtc_state(dev
);
12167 check_shared_dpll_state(dev
);
12170 void ironlake_check_encoder_dotclock(const struct intel_crtc_state
*pipe_config
,
12174 * FDI already provided one idea for the dotclock.
12175 * Yell if the encoder disagrees.
12177 WARN(!intel_fuzzy_clock_check(pipe_config
->base
.adjusted_mode
.crtc_clock
, dotclock
),
12178 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
12179 pipe_config
->base
.adjusted_mode
.crtc_clock
, dotclock
);
12182 static void update_scanline_offset(struct intel_crtc
*crtc
)
12184 struct drm_device
*dev
= crtc
->base
.dev
;
12187 * The scanline counter increments at the leading edge of hsync.
12189 * On most platforms it starts counting from vtotal-1 on the
12190 * first active line. That means the scanline counter value is
12191 * always one less than what we would expect. Ie. just after
12192 * start of vblank, which also occurs at start of hsync (on the
12193 * last active line), the scanline counter will read vblank_start-1.
12195 * On gen2 the scanline counter starts counting from 1 instead
12196 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12197 * to keep the value positive), instead of adding one.
12199 * On HSW+ the behaviour of the scanline counter depends on the output
12200 * type. For DP ports it behaves like most other platforms, but on HDMI
12201 * there's an extra 1 line difference. So we need to add two instead of
12202 * one to the value.
12204 if (IS_GEN2(dev
)) {
12205 const struct drm_display_mode
*mode
= &crtc
->config
->base
.adjusted_mode
;
12208 vtotal
= mode
->crtc_vtotal
;
12209 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
12212 crtc
->scanline_offset
= vtotal
- 1;
12213 } else if (HAS_DDI(dev
) &&
12214 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
)) {
12215 crtc
->scanline_offset
= 2;
12217 crtc
->scanline_offset
= 1;
12220 static struct intel_crtc_state
*
12221 intel_modeset_compute_config(struct drm_crtc
*crtc
,
12222 struct drm_atomic_state
*state
)
12224 struct intel_crtc_state
*pipe_config
;
12227 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
12229 return ERR_PTR(ret
);
12231 ret
= drm_atomic_helper_check_modeset(state
->dev
, state
);
12233 return ERR_PTR(ret
);
12236 * Note this needs changes when we start tracking multiple modes
12237 * and crtcs. At that point we'll need to compute the whole config
12238 * (i.e. one pipe_config for each crtc) rather than just the one
12241 pipe_config
= intel_atomic_get_crtc_state(state
, to_intel_crtc(crtc
));
12242 if (IS_ERR(pipe_config
))
12243 return pipe_config
;
12245 if (!pipe_config
->base
.enable
)
12246 return pipe_config
;
12248 ret
= intel_modeset_pipe_config(crtc
, state
, pipe_config
);
12250 return ERR_PTR(ret
);
12252 /* Check things that can only be changed through modeset */
12253 if (pipe_config
->has_audio
!=
12254 to_intel_crtc(crtc
)->config
->has_audio
)
12255 pipe_config
->base
.mode_changed
= true;
12258 * Note we have an issue here with infoframes: current code
12259 * only updates them on the full mode set path per hw
12260 * requirements. So here we should be checking for any
12261 * required changes and forcing a mode set.
12264 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,"[modeset]");
12266 ret
= drm_atomic_helper_check_planes(state
->dev
, state
);
12268 return ERR_PTR(ret
);
12270 return pipe_config
;
12273 static int __intel_set_mode_setup_plls(struct drm_atomic_state
*state
)
12275 struct drm_device
*dev
= state
->dev
;
12276 struct drm_i915_private
*dev_priv
= to_i915(dev
);
12277 unsigned clear_pipes
= 0;
12278 struct intel_crtc
*intel_crtc
;
12279 struct intel_crtc_state
*intel_crtc_state
;
12280 struct drm_crtc
*crtc
;
12281 struct drm_crtc_state
*crtc_state
;
12285 if (!dev_priv
->display
.crtc_compute_clock
)
12288 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12289 intel_crtc
= to_intel_crtc(crtc
);
12290 intel_crtc_state
= to_intel_crtc_state(crtc_state
);
12292 if (needs_modeset(crtc_state
)) {
12293 clear_pipes
|= 1 << intel_crtc
->pipe
;
12294 intel_crtc_state
->shared_dpll
= DPLL_ID_PRIVATE
;
12298 ret
= intel_shared_dpll_start_config(dev_priv
, clear_pipes
);
12302 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12303 if (!needs_modeset(crtc_state
) || !crtc_state
->enable
)
12306 intel_crtc
= to_intel_crtc(crtc
);
12307 intel_crtc_state
= to_intel_crtc_state(crtc_state
);
12309 ret
= dev_priv
->display
.crtc_compute_clock(intel_crtc
,
12312 intel_shared_dpll_abort_config(dev_priv
);
12321 /* Code that should eventually be part of atomic_check() */
12322 static int __intel_set_mode_checks(struct drm_atomic_state
*state
)
12324 struct drm_device
*dev
= state
->dev
;
12328 * See if the config requires any additional preparation, e.g.
12329 * to adjust global state with pipes off. We need to do this
12330 * here so we can get the modeset_pipe updated config for the new
12331 * mode set on this crtc. For other crtcs we need to use the
12332 * adjusted_mode bits in the crtc directly.
12334 if (IS_VALLEYVIEW(dev
) || IS_BROXTON(dev
)) {
12335 ret
= valleyview_modeset_global_pipes(state
);
12340 ret
= __intel_set_mode_setup_plls(state
);
12347 static int __intel_set_mode(struct drm_crtc
*modeset_crtc
,
12348 struct intel_crtc_state
*pipe_config
)
12350 struct drm_device
*dev
= modeset_crtc
->dev
;
12351 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12352 struct drm_atomic_state
*state
= pipe_config
->base
.state
;
12353 struct drm_crtc
*crtc
;
12354 struct drm_crtc_state
*crtc_state
;
12358 ret
= __intel_set_mode_checks(state
);
12362 ret
= drm_atomic_helper_prepare_planes(dev
, state
);
12366 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12367 if (!needs_modeset(crtc_state
))
12370 if (!crtc_state
->enable
) {
12371 intel_crtc_disable(crtc
);
12372 } else if (crtc
->state
->enable
) {
12373 intel_crtc_disable_planes(crtc
);
12374 dev_priv
->display
.crtc_disable(crtc
);
12378 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
12379 * to set it here already despite that we pass it down the callchain.
12381 * Note we'll need to fix this up when we start tracking multiple
12382 * pipes; here we assume a single modeset_pipe and only track the
12383 * single crtc and mode.
12385 if (pipe_config
->base
.enable
&& needs_modeset(&pipe_config
->base
)) {
12386 modeset_crtc
->mode
= pipe_config
->base
.mode
;
12389 * Calculate and store various constants which
12390 * are later needed by vblank and swap-completion
12391 * timestamping. They are derived from true hwmode.
12393 drm_calc_timestamping_constants(modeset_crtc
,
12394 &pipe_config
->base
.adjusted_mode
);
12397 /* Only after disabling all output pipelines that will be changed can we
12398 * update the the output configuration. */
12399 intel_modeset_update_state(state
);
12401 /* The state has been swaped above, so state actually contains the
12402 * old state now. */
12404 modeset_update_crtc_power_domains(state
);
12406 drm_atomic_helper_commit_planes(dev
, state
);
12408 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
12409 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12410 if (!needs_modeset(crtc
->state
) || !crtc
->state
->enable
)
12413 update_scanline_offset(to_intel_crtc(crtc
));
12415 dev_priv
->display
.crtc_enable(crtc
);
12416 intel_crtc_enable_planes(crtc
);
12419 /* FIXME: add subpixel order */
12421 drm_atomic_helper_cleanup_planes(dev
, state
);
12423 drm_atomic_state_free(state
);
12428 static int intel_set_mode_with_config(struct drm_crtc
*crtc
,
12429 struct intel_crtc_state
*pipe_config
)
12433 ret
= __intel_set_mode(crtc
, pipe_config
);
12436 intel_modeset_check_state(crtc
->dev
);
12441 static int intel_set_mode(struct drm_crtc
*crtc
,
12442 struct drm_atomic_state
*state
)
12444 struct intel_crtc_state
*pipe_config
;
12447 pipe_config
= intel_modeset_compute_config(crtc
, state
);
12448 if (IS_ERR(pipe_config
)) {
12449 ret
= PTR_ERR(pipe_config
);
12453 ret
= intel_set_mode_with_config(crtc
, pipe_config
);
12461 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
12463 struct drm_device
*dev
= crtc
->dev
;
12464 struct drm_atomic_state
*state
;
12465 struct intel_crtc
*intel_crtc
;
12466 struct intel_encoder
*encoder
;
12467 struct intel_connector
*connector
;
12468 struct drm_connector_state
*connector_state
;
12469 struct intel_crtc_state
*crtc_state
;
12472 state
= drm_atomic_state_alloc(dev
);
12474 DRM_DEBUG_KMS("[CRTC:%d] mode restore failed, out of memory",
12479 state
->acquire_ctx
= dev
->mode_config
.acquire_ctx
;
12481 /* The force restore path in the HW readout code relies on the staged
12482 * config still keeping the user requested config while the actual
12483 * state has been overwritten by the configuration read from HW. We
12484 * need to copy the staged config to the atomic state, otherwise the
12485 * mode set will just reapply the state the HW is already in. */
12486 for_each_intel_encoder(dev
, encoder
) {
12487 if (&encoder
->new_crtc
->base
!= crtc
)
12490 for_each_intel_connector(dev
, connector
) {
12491 if (connector
->new_encoder
!= encoder
)
12494 connector_state
= drm_atomic_get_connector_state(state
, &connector
->base
);
12495 if (IS_ERR(connector_state
)) {
12496 DRM_DEBUG_KMS("Failed to add [CONNECTOR:%d:%s] to state: %ld\n",
12497 connector
->base
.base
.id
,
12498 connector
->base
.name
,
12499 PTR_ERR(connector_state
));
12503 connector_state
->crtc
= crtc
;
12504 connector_state
->best_encoder
= &encoder
->base
;
12508 for_each_intel_crtc(dev
, intel_crtc
) {
12509 if (intel_crtc
->new_enabled
== intel_crtc
->base
.enabled
)
12512 crtc_state
= intel_atomic_get_crtc_state(state
, intel_crtc
);
12513 if (IS_ERR(crtc_state
)) {
12514 DRM_DEBUG_KMS("Failed to add [CRTC:%d] to state: %ld\n",
12515 intel_crtc
->base
.base
.id
,
12516 PTR_ERR(crtc_state
));
12520 crtc_state
->base
.active
= crtc_state
->base
.enable
=
12521 intel_crtc
->new_enabled
;
12523 if (&intel_crtc
->base
== crtc
)
12524 drm_mode_copy(&crtc_state
->base
.mode
, &crtc
->mode
);
12527 intel_modeset_setup_plane_state(state
, crtc
, &crtc
->mode
,
12528 crtc
->primary
->fb
, crtc
->x
, crtc
->y
);
12530 ret
= intel_set_mode(crtc
, state
);
12532 drm_atomic_state_free(state
);
12535 #undef for_each_intel_crtc_masked
12537 static bool intel_connector_in_mode_set(struct intel_connector
*connector
,
12538 struct drm_mode_set
*set
)
12542 for (ro
= 0; ro
< set
->num_connectors
; ro
++)
12543 if (set
->connectors
[ro
] == &connector
->base
)
12550 intel_modeset_stage_output_state(struct drm_device
*dev
,
12551 struct drm_mode_set
*set
,
12552 struct drm_atomic_state
*state
)
12554 struct intel_connector
*connector
;
12555 struct drm_connector
*drm_connector
;
12556 struct drm_connector_state
*connector_state
;
12557 struct drm_crtc
*crtc
;
12558 struct drm_crtc_state
*crtc_state
;
12561 /* The upper layers ensure that we either disable a crtc or have a list
12562 * of connectors. For paranoia, double-check this. */
12563 WARN_ON(!set
->fb
&& (set
->num_connectors
!= 0));
12564 WARN_ON(set
->fb
&& (set
->num_connectors
== 0));
12566 for_each_intel_connector(dev
, connector
) {
12567 bool in_mode_set
= intel_connector_in_mode_set(connector
, set
);
12569 if (!in_mode_set
&& connector
->base
.state
->crtc
!= set
->crtc
)
12573 drm_atomic_get_connector_state(state
, &connector
->base
);
12574 if (IS_ERR(connector_state
))
12575 return PTR_ERR(connector_state
);
12578 int pipe
= to_intel_crtc(set
->crtc
)->pipe
;
12579 connector_state
->best_encoder
=
12580 &intel_find_encoder(connector
, pipe
)->base
;
12583 if (connector
->base
.state
->crtc
!= set
->crtc
)
12586 /* If we disable the crtc, disable all its connectors. Also, if
12587 * the connector is on the changing crtc but not on the new
12588 * connector list, disable it. */
12589 if (!set
->fb
|| !in_mode_set
) {
12590 connector_state
->best_encoder
= NULL
;
12592 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
12593 connector
->base
.base
.id
,
12594 connector
->base
.name
);
12597 /* connector->new_encoder is now updated for all connectors. */
12599 for_each_connector_in_state(state
, drm_connector
, connector_state
, i
) {
12600 connector
= to_intel_connector(drm_connector
);
12602 if (!connector_state
->best_encoder
) {
12603 ret
= drm_atomic_set_crtc_for_connector(connector_state
,
12611 if (intel_connector_in_mode_set(connector
, set
)) {
12612 struct drm_crtc
*crtc
= connector
->base
.state
->crtc
;
12614 /* If this connector was in a previous crtc, add it
12615 * to the state. We might need to disable it. */
12618 drm_atomic_get_crtc_state(state
, crtc
);
12619 if (IS_ERR(crtc_state
))
12620 return PTR_ERR(crtc_state
);
12623 ret
= drm_atomic_set_crtc_for_connector(connector_state
,
12629 /* Make sure the new CRTC will work with the encoder */
12630 if (!drm_encoder_crtc_ok(connector_state
->best_encoder
,
12631 connector_state
->crtc
)) {
12635 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
12636 connector
->base
.base
.id
,
12637 connector
->base
.name
,
12638 connector_state
->crtc
->base
.id
);
12640 if (connector_state
->best_encoder
!= &connector
->encoder
->base
)
12641 connector
->encoder
=
12642 to_intel_encoder(connector_state
->best_encoder
);
12645 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
12646 bool has_connectors
;
12648 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
12652 has_connectors
= !!drm_atomic_connectors_for_crtc(state
, crtc
);
12653 if (has_connectors
!= crtc_state
->enable
)
12654 crtc_state
->enable
=
12655 crtc_state
->active
= has_connectors
;
12658 ret
= intel_modeset_setup_plane_state(state
, set
->crtc
, set
->mode
,
12659 set
->fb
, set
->x
, set
->y
);
12663 crtc_state
= drm_atomic_get_crtc_state(state
, set
->crtc
);
12664 if (IS_ERR(crtc_state
))
12665 return PTR_ERR(crtc_state
);
12668 drm_mode_copy(&crtc_state
->mode
, set
->mode
);
12670 if (set
->num_connectors
)
12671 crtc_state
->active
= true;
12676 static bool primary_plane_visible(struct drm_crtc
*crtc
)
12678 struct intel_plane_state
*plane_state
=
12679 to_intel_plane_state(crtc
->primary
->state
);
12681 return plane_state
->visible
;
12684 static int intel_crtc_set_config(struct drm_mode_set
*set
)
12686 struct drm_device
*dev
;
12687 struct drm_atomic_state
*state
= NULL
;
12688 struct intel_crtc_state
*pipe_config
;
12689 bool primary_plane_was_visible
;
12693 BUG_ON(!set
->crtc
);
12694 BUG_ON(!set
->crtc
->helper_private
);
12696 /* Enforce sane interface api - has been abused by the fb helper. */
12697 BUG_ON(!set
->mode
&& set
->fb
);
12698 BUG_ON(set
->fb
&& set
->num_connectors
== 0);
12701 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
12702 set
->crtc
->base
.id
, set
->fb
->base
.id
,
12703 (int)set
->num_connectors
, set
->x
, set
->y
);
12705 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set
->crtc
->base
.id
);
12708 dev
= set
->crtc
->dev
;
12710 state
= drm_atomic_state_alloc(dev
);
12714 state
->acquire_ctx
= dev
->mode_config
.acquire_ctx
;
12716 ret
= intel_modeset_stage_output_state(dev
, set
, state
);
12720 pipe_config
= intel_modeset_compute_config(set
->crtc
, state
);
12721 if (IS_ERR(pipe_config
)) {
12722 ret
= PTR_ERR(pipe_config
);
12726 intel_update_pipe_size(to_intel_crtc(set
->crtc
));
12728 primary_plane_was_visible
= primary_plane_visible(set
->crtc
);
12730 ret
= intel_set_mode_with_config(set
->crtc
, pipe_config
);
12733 pipe_config
->base
.enable
&&
12734 pipe_config
->base
.planes_changed
&&
12735 !needs_modeset(&pipe_config
->base
)) {
12736 struct intel_crtc
*intel_crtc
= to_intel_crtc(set
->crtc
);
12739 * We need to make sure the primary plane is re-enabled if it
12740 * has previously been turned off.
12742 if (ret
== 0 && !primary_plane_was_visible
&&
12743 primary_plane_visible(set
->crtc
)) {
12744 WARN_ON(!intel_crtc
->active
);
12745 intel_post_enable_primary(set
->crtc
);
12749 * In the fastboot case this may be our only check of the
12750 * state after boot. It would be better to only do it on
12751 * the first update, but we don't have a nice way of doing that
12752 * (and really, set_config isn't used much for high freq page
12753 * flipping, so increasing its cost here shouldn't be a big
12756 if (i915
.fastboot
&& ret
== 0)
12757 intel_modeset_check_state(set
->crtc
->dev
);
12761 DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
12762 set
->crtc
->base
.id
, ret
);
12767 drm_atomic_state_free(state
);
12771 static const struct drm_crtc_funcs intel_crtc_funcs
= {
12772 .gamma_set
= intel_crtc_gamma_set
,
12773 .set_config
= intel_crtc_set_config
,
12774 .destroy
= intel_crtc_destroy
,
12775 .page_flip
= intel_crtc_page_flip
,
12776 .atomic_duplicate_state
= intel_crtc_duplicate_state
,
12777 .atomic_destroy_state
= intel_crtc_destroy_state
,
12780 static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private
*dev_priv
,
12781 struct intel_shared_dpll
*pll
,
12782 struct intel_dpll_hw_state
*hw_state
)
12786 if (!intel_display_power_is_enabled(dev_priv
, POWER_DOMAIN_PLLS
))
12789 val
= I915_READ(PCH_DPLL(pll
->id
));
12790 hw_state
->dpll
= val
;
12791 hw_state
->fp0
= I915_READ(PCH_FP0(pll
->id
));
12792 hw_state
->fp1
= I915_READ(PCH_FP1(pll
->id
));
12794 return val
& DPLL_VCO_ENABLE
;
12797 static void ibx_pch_dpll_mode_set(struct drm_i915_private
*dev_priv
,
12798 struct intel_shared_dpll
*pll
)
12800 I915_WRITE(PCH_FP0(pll
->id
), pll
->config
.hw_state
.fp0
);
12801 I915_WRITE(PCH_FP1(pll
->id
), pll
->config
.hw_state
.fp1
);
12804 static void ibx_pch_dpll_enable(struct drm_i915_private
*dev_priv
,
12805 struct intel_shared_dpll
*pll
)
12807 /* PCH refclock must be enabled first */
12808 ibx_assert_pch_refclk_enabled(dev_priv
);
12810 I915_WRITE(PCH_DPLL(pll
->id
), pll
->config
.hw_state
.dpll
);
12812 /* Wait for the clocks to stabilize. */
12813 POSTING_READ(PCH_DPLL(pll
->id
));
12816 /* The pixel multiplier can only be updated once the
12817 * DPLL is enabled and the clocks are stable.
12819 * So write it again.
12821 I915_WRITE(PCH_DPLL(pll
->id
), pll
->config
.hw_state
.dpll
);
12822 POSTING_READ(PCH_DPLL(pll
->id
));
12826 static void ibx_pch_dpll_disable(struct drm_i915_private
*dev_priv
,
12827 struct intel_shared_dpll
*pll
)
12829 struct drm_device
*dev
= dev_priv
->dev
;
12830 struct intel_crtc
*crtc
;
12832 /* Make sure no transcoder isn't still depending on us. */
12833 for_each_intel_crtc(dev
, crtc
) {
12834 if (intel_crtc_to_shared_dpll(crtc
) == pll
)
12835 assert_pch_transcoder_disabled(dev_priv
, crtc
->pipe
);
12838 I915_WRITE(PCH_DPLL(pll
->id
), 0);
12839 POSTING_READ(PCH_DPLL(pll
->id
));
12843 static char *ibx_pch_dpll_names
[] = {
12848 static void ibx_pch_dpll_init(struct drm_device
*dev
)
12850 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12853 dev_priv
->num_shared_dpll
= 2;
12855 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
12856 dev_priv
->shared_dplls
[i
].id
= i
;
12857 dev_priv
->shared_dplls
[i
].name
= ibx_pch_dpll_names
[i
];
12858 dev_priv
->shared_dplls
[i
].mode_set
= ibx_pch_dpll_mode_set
;
12859 dev_priv
->shared_dplls
[i
].enable
= ibx_pch_dpll_enable
;
12860 dev_priv
->shared_dplls
[i
].disable
= ibx_pch_dpll_disable
;
12861 dev_priv
->shared_dplls
[i
].get_hw_state
=
12862 ibx_pch_dpll_get_hw_state
;
12866 static void intel_shared_dpll_init(struct drm_device
*dev
)
12868 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12871 intel_ddi_pll_init(dev
);
12872 else if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
12873 ibx_pch_dpll_init(dev
);
12875 dev_priv
->num_shared_dpll
= 0;
12877 BUG_ON(dev_priv
->num_shared_dpll
> I915_NUM_PLLS
);
12881 * intel_wm_need_update - Check whether watermarks need updating
12882 * @plane: drm plane
12883 * @state: new plane state
12885 * Check current plane state versus the new one to determine whether
12886 * watermarks need to be recalculated.
12888 * Returns true or false.
12890 bool intel_wm_need_update(struct drm_plane
*plane
,
12891 struct drm_plane_state
*state
)
12893 /* Update watermarks on tiling changes. */
12894 if (!plane
->state
->fb
|| !state
->fb
||
12895 plane
->state
->fb
->modifier
[0] != state
->fb
->modifier
[0] ||
12896 plane
->state
->rotation
!= state
->rotation
)
12903 * intel_prepare_plane_fb - Prepare fb for usage on plane
12904 * @plane: drm plane to prepare for
12905 * @fb: framebuffer to prepare for presentation
12907 * Prepares a framebuffer for usage on a display plane. Generally this
12908 * involves pinning the underlying object and updating the frontbuffer tracking
12909 * bits. Some older platforms need special physical address handling for
12912 * Returns 0 on success, negative error code on failure.
12915 intel_prepare_plane_fb(struct drm_plane
*plane
,
12916 struct drm_framebuffer
*fb
,
12917 const struct drm_plane_state
*new_state
)
12919 struct drm_device
*dev
= plane
->dev
;
12920 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
12921 enum pipe pipe
= intel_plane
->pipe
;
12922 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
12923 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->fb
);
12924 unsigned frontbuffer_bits
= 0;
12930 switch (plane
->type
) {
12931 case DRM_PLANE_TYPE_PRIMARY
:
12932 frontbuffer_bits
= INTEL_FRONTBUFFER_PRIMARY(pipe
);
12934 case DRM_PLANE_TYPE_CURSOR
:
12935 frontbuffer_bits
= INTEL_FRONTBUFFER_CURSOR(pipe
);
12937 case DRM_PLANE_TYPE_OVERLAY
:
12938 frontbuffer_bits
= INTEL_FRONTBUFFER_SPRITE(pipe
);
12942 mutex_lock(&dev
->struct_mutex
);
12944 if (plane
->type
== DRM_PLANE_TYPE_CURSOR
&&
12945 INTEL_INFO(dev
)->cursor_needs_physical
) {
12946 int align
= IS_I830(dev
) ? 16 * 1024 : 256;
12947 ret
= i915_gem_object_attach_phys(obj
, align
);
12949 DRM_DEBUG_KMS("failed to attach phys object\n");
12951 ret
= intel_pin_and_fence_fb_obj(plane
, fb
, new_state
, NULL
);
12955 i915_gem_track_fb(old_obj
, obj
, frontbuffer_bits
);
12957 mutex_unlock(&dev
->struct_mutex
);
12963 * intel_cleanup_plane_fb - Cleans up an fb after plane use
12964 * @plane: drm plane to clean up for
12965 * @fb: old framebuffer that was on plane
12967 * Cleans up a framebuffer that has just been removed from a plane.
12970 intel_cleanup_plane_fb(struct drm_plane
*plane
,
12971 struct drm_framebuffer
*fb
,
12972 const struct drm_plane_state
*old_state
)
12974 struct drm_device
*dev
= plane
->dev
;
12975 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
12980 if (plane
->type
!= DRM_PLANE_TYPE_CURSOR
||
12981 !INTEL_INFO(dev
)->cursor_needs_physical
) {
12982 mutex_lock(&dev
->struct_mutex
);
12983 intel_unpin_fb_obj(fb
, old_state
);
12984 mutex_unlock(&dev
->struct_mutex
);
12989 skl_max_scale(struct intel_crtc
*intel_crtc
, struct intel_crtc_state
*crtc_state
)
12992 struct drm_device
*dev
;
12993 struct drm_i915_private
*dev_priv
;
12994 int crtc_clock
, cdclk
;
12996 if (!intel_crtc
|| !crtc_state
)
12997 return DRM_PLANE_HELPER_NO_SCALING
;
12999 dev
= intel_crtc
->base
.dev
;
13000 dev_priv
= dev
->dev_private
;
13001 crtc_clock
= crtc_state
->base
.adjusted_mode
.crtc_clock
;
13002 cdclk
= dev_priv
->display
.get_display_clock_speed(dev
);
13004 if (!crtc_clock
|| !cdclk
)
13005 return DRM_PLANE_HELPER_NO_SCALING
;
13008 * skl max scale is lower of:
13009 * close to 3 but not 3, -1 is for that purpose
13013 max_scale
= min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk
<< 8) / crtc_clock
));
13019 intel_check_primary_plane(struct drm_plane
*plane
,
13020 struct intel_plane_state
*state
)
13022 struct drm_device
*dev
= plane
->dev
;
13023 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13024 struct drm_crtc
*crtc
= state
->base
.crtc
;
13025 struct intel_crtc
*intel_crtc
;
13026 struct intel_crtc_state
*crtc_state
;
13027 struct drm_framebuffer
*fb
= state
->base
.fb
;
13028 struct drm_rect
*dest
= &state
->dst
;
13029 struct drm_rect
*src
= &state
->src
;
13030 const struct drm_rect
*clip
= &state
->clip
;
13031 bool can_position
= false;
13032 int max_scale
= DRM_PLANE_HELPER_NO_SCALING
;
13033 int min_scale
= DRM_PLANE_HELPER_NO_SCALING
;
13036 crtc
= crtc
? crtc
: plane
->crtc
;
13037 intel_crtc
= to_intel_crtc(crtc
);
13038 crtc_state
= state
->base
.state
?
13039 intel_atomic_get_crtc_state(state
->base
.state
, intel_crtc
) : NULL
;
13041 if (INTEL_INFO(dev
)->gen
>= 9) {
13043 max_scale
= skl_max_scale(intel_crtc
, crtc_state
);
13044 can_position
= true;
13047 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
13051 can_position
, true,
13056 if (intel_crtc
->active
) {
13057 struct intel_plane_state
*old_state
=
13058 to_intel_plane_state(plane
->state
);
13060 intel_crtc
->atomic
.wait_for_flips
= true;
13063 * FBC does not work on some platforms for rotated
13064 * planes, so disable it when rotation is not 0 and
13065 * update it when rotation is set back to 0.
13067 * FIXME: This is redundant with the fbc update done in
13068 * the primary plane enable function except that that
13069 * one is done too late. We eventually need to unify
13072 if (state
->visible
&&
13073 INTEL_INFO(dev
)->gen
<= 4 && !IS_G4X(dev
) &&
13074 dev_priv
->fbc
.crtc
== intel_crtc
&&
13075 state
->base
.rotation
!= BIT(DRM_ROTATE_0
)) {
13076 intel_crtc
->atomic
.disable_fbc
= true;
13079 if (state
->visible
&& !old_state
->visible
) {
13081 * BDW signals flip done immediately if the plane
13082 * is disabled, even if the plane enable is already
13083 * armed to occur at the next vblank :(
13085 if (IS_BROADWELL(dev
))
13086 intel_crtc
->atomic
.wait_vblank
= true;
13089 intel_crtc
->atomic
.fb_bits
|=
13090 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
);
13092 intel_crtc
->atomic
.update_fbc
= true;
13094 if (intel_wm_need_update(plane
, &state
->base
))
13095 intel_crtc
->atomic
.update_wm
= true;
13098 if (INTEL_INFO(dev
)->gen
>= 9) {
13099 ret
= skl_update_scaler_users(intel_crtc
, crtc_state
,
13100 to_intel_plane(plane
), state
, 0);
13109 intel_commit_primary_plane(struct drm_plane
*plane
,
13110 struct intel_plane_state
*state
)
13112 struct drm_crtc
*crtc
= state
->base
.crtc
;
13113 struct drm_framebuffer
*fb
= state
->base
.fb
;
13114 struct drm_device
*dev
= plane
->dev
;
13115 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13116 struct intel_crtc
*intel_crtc
;
13117 struct drm_rect
*src
= &state
->src
;
13119 crtc
= crtc
? crtc
: plane
->crtc
;
13120 intel_crtc
= to_intel_crtc(crtc
);
13123 crtc
->x
= src
->x1
>> 16;
13124 crtc
->y
= src
->y1
>> 16;
13126 if (intel_crtc
->active
) {
13127 if (state
->visible
)
13128 /* FIXME: kill this fastboot hack */
13129 intel_update_pipe_size(intel_crtc
);
13131 dev_priv
->display
.update_primary_plane(crtc
, plane
->fb
,
13137 intel_disable_primary_plane(struct drm_plane
*plane
,
13138 struct drm_crtc
*crtc
,
13141 struct drm_device
*dev
= plane
->dev
;
13142 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13144 dev_priv
->display
.update_primary_plane(crtc
, NULL
, 0, 0);
13147 static void intel_begin_crtc_commit(struct drm_crtc
*crtc
)
13149 struct drm_device
*dev
= crtc
->dev
;
13150 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13151 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13152 struct intel_plane
*intel_plane
;
13153 struct drm_plane
*p
;
13154 unsigned fb_bits
= 0;
13156 /* Track fb's for any planes being disabled */
13157 list_for_each_entry(p
, &dev
->mode_config
.plane_list
, head
) {
13158 intel_plane
= to_intel_plane(p
);
13160 if (intel_crtc
->atomic
.disabled_planes
&
13161 (1 << drm_plane_index(p
))) {
13163 case DRM_PLANE_TYPE_PRIMARY
:
13164 fb_bits
= INTEL_FRONTBUFFER_PRIMARY(intel_plane
->pipe
);
13166 case DRM_PLANE_TYPE_CURSOR
:
13167 fb_bits
= INTEL_FRONTBUFFER_CURSOR(intel_plane
->pipe
);
13169 case DRM_PLANE_TYPE_OVERLAY
:
13170 fb_bits
= INTEL_FRONTBUFFER_SPRITE(intel_plane
->pipe
);
13174 mutex_lock(&dev
->struct_mutex
);
13175 i915_gem_track_fb(intel_fb_obj(p
->fb
), NULL
, fb_bits
);
13176 mutex_unlock(&dev
->struct_mutex
);
13180 if (intel_crtc
->atomic
.wait_for_flips
)
13181 intel_crtc_wait_for_pending_flips(crtc
);
13183 if (intel_crtc
->atomic
.disable_fbc
)
13184 intel_fbc_disable(dev
);
13186 if (intel_crtc
->atomic
.pre_disable_primary
)
13187 intel_pre_disable_primary(crtc
);
13189 if (intel_crtc
->atomic
.update_wm
)
13190 intel_update_watermarks(crtc
);
13192 intel_runtime_pm_get(dev_priv
);
13194 /* Perform vblank evasion around commit operation */
13195 if (intel_crtc
->active
)
13196 intel_crtc
->atomic
.evade
=
13197 intel_pipe_update_start(intel_crtc
,
13198 &intel_crtc
->atomic
.start_vbl_count
);
13201 static void intel_finish_crtc_commit(struct drm_crtc
*crtc
)
13203 struct drm_device
*dev
= crtc
->dev
;
13204 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13205 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13206 struct drm_plane
*p
;
13208 if (intel_crtc
->atomic
.evade
)
13209 intel_pipe_update_end(intel_crtc
,
13210 intel_crtc
->atomic
.start_vbl_count
);
13212 intel_runtime_pm_put(dev_priv
);
13214 if (intel_crtc
->atomic
.wait_vblank
)
13215 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
13217 intel_frontbuffer_flip(dev
, intel_crtc
->atomic
.fb_bits
);
13219 if (intel_crtc
->atomic
.update_fbc
) {
13220 mutex_lock(&dev
->struct_mutex
);
13221 intel_fbc_update(dev
);
13222 mutex_unlock(&dev
->struct_mutex
);
13225 if (intel_crtc
->atomic
.post_enable_primary
)
13226 intel_post_enable_primary(crtc
);
13228 drm_for_each_legacy_plane(p
, &dev
->mode_config
.plane_list
)
13229 if (intel_crtc
->atomic
.update_sprite_watermarks
& drm_plane_index(p
))
13230 intel_update_sprite_watermarks(p
, crtc
, 0, 0, 0,
13233 memset(&intel_crtc
->atomic
, 0, sizeof(intel_crtc
->atomic
));
13237 * intel_plane_destroy - destroy a plane
13238 * @plane: plane to destroy
13240 * Common destruction function for all types of planes (primary, cursor,
13243 void intel_plane_destroy(struct drm_plane
*plane
)
13245 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
13246 drm_plane_cleanup(plane
);
13247 kfree(intel_plane
);
13250 const struct drm_plane_funcs intel_plane_funcs
= {
13251 .update_plane
= drm_atomic_helper_update_plane
,
13252 .disable_plane
= drm_atomic_helper_disable_plane
,
13253 .destroy
= intel_plane_destroy
,
13254 .set_property
= drm_atomic_helper_plane_set_property
,
13255 .atomic_get_property
= intel_plane_atomic_get_property
,
13256 .atomic_set_property
= intel_plane_atomic_set_property
,
13257 .atomic_duplicate_state
= intel_plane_duplicate_state
,
13258 .atomic_destroy_state
= intel_plane_destroy_state
,
13262 static struct drm_plane
*intel_primary_plane_create(struct drm_device
*dev
,
13265 struct intel_plane
*primary
;
13266 struct intel_plane_state
*state
;
13267 const uint32_t *intel_primary_formats
;
13270 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
13271 if (primary
== NULL
)
13274 state
= intel_create_plane_state(&primary
->base
);
13279 primary
->base
.state
= &state
->base
;
13281 primary
->can_scale
= false;
13282 primary
->max_downscale
= 1;
13283 if (INTEL_INFO(dev
)->gen
>= 9) {
13284 primary
->can_scale
= true;
13285 state
->scaler_id
= -1;
13287 primary
->pipe
= pipe
;
13288 primary
->plane
= pipe
;
13289 primary
->check_plane
= intel_check_primary_plane
;
13290 primary
->commit_plane
= intel_commit_primary_plane
;
13291 primary
->disable_plane
= intel_disable_primary_plane
;
13292 primary
->ckey
.flags
= I915_SET_COLORKEY_NONE
;
13293 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4)
13294 primary
->plane
= !pipe
;
13296 if (INTEL_INFO(dev
)->gen
<= 3) {
13297 intel_primary_formats
= i8xx_primary_formats
;
13298 num_formats
= ARRAY_SIZE(i8xx_primary_formats
);
13300 intel_primary_formats
= i965_primary_formats
;
13301 num_formats
= ARRAY_SIZE(i965_primary_formats
);
13304 drm_universal_plane_init(dev
, &primary
->base
, 0,
13305 &intel_plane_funcs
,
13306 intel_primary_formats
, num_formats
,
13307 DRM_PLANE_TYPE_PRIMARY
);
13309 if (INTEL_INFO(dev
)->gen
>= 4)
13310 intel_create_rotation_property(dev
, primary
);
13312 drm_plane_helper_add(&primary
->base
, &intel_plane_helper_funcs
);
13314 return &primary
->base
;
13317 void intel_create_rotation_property(struct drm_device
*dev
, struct intel_plane
*plane
)
13319 if (!dev
->mode_config
.rotation_property
) {
13320 unsigned long flags
= BIT(DRM_ROTATE_0
) |
13321 BIT(DRM_ROTATE_180
);
13323 if (INTEL_INFO(dev
)->gen
>= 9)
13324 flags
|= BIT(DRM_ROTATE_90
) | BIT(DRM_ROTATE_270
);
13326 dev
->mode_config
.rotation_property
=
13327 drm_mode_create_rotation_property(dev
, flags
);
13329 if (dev
->mode_config
.rotation_property
)
13330 drm_object_attach_property(&plane
->base
.base
,
13331 dev
->mode_config
.rotation_property
,
13332 plane
->base
.state
->rotation
);
13336 intel_check_cursor_plane(struct drm_plane
*plane
,
13337 struct intel_plane_state
*state
)
13339 struct drm_crtc
*crtc
= state
->base
.crtc
;
13340 struct drm_device
*dev
= plane
->dev
;
13341 struct drm_framebuffer
*fb
= state
->base
.fb
;
13342 struct drm_rect
*dest
= &state
->dst
;
13343 struct drm_rect
*src
= &state
->src
;
13344 const struct drm_rect
*clip
= &state
->clip
;
13345 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
13346 struct intel_crtc
*intel_crtc
;
13350 crtc
= crtc
? crtc
: plane
->crtc
;
13351 intel_crtc
= to_intel_crtc(crtc
);
13353 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
13355 DRM_PLANE_HELPER_NO_SCALING
,
13356 DRM_PLANE_HELPER_NO_SCALING
,
13357 true, true, &state
->visible
);
13362 /* if we want to turn off the cursor ignore width and height */
13366 /* Check for which cursor types we support */
13367 if (!cursor_size_ok(dev
, state
->base
.crtc_w
, state
->base
.crtc_h
)) {
13368 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
13369 state
->base
.crtc_w
, state
->base
.crtc_h
);
13373 stride
= roundup_pow_of_two(state
->base
.crtc_w
) * 4;
13374 if (obj
->base
.size
< stride
* state
->base
.crtc_h
) {
13375 DRM_DEBUG_KMS("buffer is too small\n");
13379 if (fb
->modifier
[0] != DRM_FORMAT_MOD_NONE
) {
13380 DRM_DEBUG_KMS("cursor cannot be tiled\n");
13385 if (intel_crtc
->active
) {
13386 if (plane
->state
->crtc_w
!= state
->base
.crtc_w
)
13387 intel_crtc
->atomic
.update_wm
= true;
13389 intel_crtc
->atomic
.fb_bits
|=
13390 INTEL_FRONTBUFFER_CURSOR(intel_crtc
->pipe
);
13397 intel_disable_cursor_plane(struct drm_plane
*plane
,
13398 struct drm_crtc
*crtc
,
13401 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
13405 intel_crtc
->cursor_bo
= NULL
;
13406 intel_crtc
->cursor_addr
= 0;
13409 intel_crtc_update_cursor(crtc
, false);
13413 intel_commit_cursor_plane(struct drm_plane
*plane
,
13414 struct intel_plane_state
*state
)
13416 struct drm_crtc
*crtc
= state
->base
.crtc
;
13417 struct drm_device
*dev
= plane
->dev
;
13418 struct intel_crtc
*intel_crtc
;
13419 struct drm_i915_gem_object
*obj
= intel_fb_obj(state
->base
.fb
);
13422 crtc
= crtc
? crtc
: plane
->crtc
;
13423 intel_crtc
= to_intel_crtc(crtc
);
13425 plane
->fb
= state
->base
.fb
;
13426 crtc
->cursor_x
= state
->base
.crtc_x
;
13427 crtc
->cursor_y
= state
->base
.crtc_y
;
13429 if (intel_crtc
->cursor_bo
== obj
)
13434 else if (!INTEL_INFO(dev
)->cursor_needs_physical
)
13435 addr
= i915_gem_obj_ggtt_offset(obj
);
13437 addr
= obj
->phys_handle
->busaddr
;
13439 intel_crtc
->cursor_addr
= addr
;
13440 intel_crtc
->cursor_bo
= obj
;
13443 if (intel_crtc
->active
)
13444 intel_crtc_update_cursor(crtc
, state
->visible
);
13447 static struct drm_plane
*intel_cursor_plane_create(struct drm_device
*dev
,
13450 struct intel_plane
*cursor
;
13451 struct intel_plane_state
*state
;
13453 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
13454 if (cursor
== NULL
)
13457 state
= intel_create_plane_state(&cursor
->base
);
13462 cursor
->base
.state
= &state
->base
;
13464 cursor
->can_scale
= false;
13465 cursor
->max_downscale
= 1;
13466 cursor
->pipe
= pipe
;
13467 cursor
->plane
= pipe
;
13468 cursor
->check_plane
= intel_check_cursor_plane
;
13469 cursor
->commit_plane
= intel_commit_cursor_plane
;
13470 cursor
->disable_plane
= intel_disable_cursor_plane
;
13472 drm_universal_plane_init(dev
, &cursor
->base
, 0,
13473 &intel_plane_funcs
,
13474 intel_cursor_formats
,
13475 ARRAY_SIZE(intel_cursor_formats
),
13476 DRM_PLANE_TYPE_CURSOR
);
13478 if (INTEL_INFO(dev
)->gen
>= 4) {
13479 if (!dev
->mode_config
.rotation_property
)
13480 dev
->mode_config
.rotation_property
=
13481 drm_mode_create_rotation_property(dev
,
13482 BIT(DRM_ROTATE_0
) |
13483 BIT(DRM_ROTATE_180
));
13484 if (dev
->mode_config
.rotation_property
)
13485 drm_object_attach_property(&cursor
->base
.base
,
13486 dev
->mode_config
.rotation_property
,
13487 state
->base
.rotation
);
13490 if (INTEL_INFO(dev
)->gen
>=9)
13491 state
->scaler_id
= -1;
13493 drm_plane_helper_add(&cursor
->base
, &intel_plane_helper_funcs
);
13495 return &cursor
->base
;
13498 static void skl_init_scalers(struct drm_device
*dev
, struct intel_crtc
*intel_crtc
,
13499 struct intel_crtc_state
*crtc_state
)
13502 struct intel_scaler
*intel_scaler
;
13503 struct intel_crtc_scaler_state
*scaler_state
= &crtc_state
->scaler_state
;
13505 for (i
= 0; i
< intel_crtc
->num_scalers
; i
++) {
13506 intel_scaler
= &scaler_state
->scalers
[i
];
13507 intel_scaler
->in_use
= 0;
13508 intel_scaler
->id
= i
;
13510 intel_scaler
->mode
= PS_SCALER_MODE_DYN
;
13513 scaler_state
->scaler_id
= -1;
13516 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
13518 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13519 struct intel_crtc
*intel_crtc
;
13520 struct intel_crtc_state
*crtc_state
= NULL
;
13521 struct drm_plane
*primary
= NULL
;
13522 struct drm_plane
*cursor
= NULL
;
13525 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
13526 if (intel_crtc
== NULL
)
13529 crtc_state
= kzalloc(sizeof(*crtc_state
), GFP_KERNEL
);
13532 intel_crtc
->config
= crtc_state
;
13533 intel_crtc
->base
.state
= &crtc_state
->base
;
13534 crtc_state
->base
.crtc
= &intel_crtc
->base
;
13536 /* initialize shared scalers */
13537 if (INTEL_INFO(dev
)->gen
>= 9) {
13538 if (pipe
== PIPE_C
)
13539 intel_crtc
->num_scalers
= 1;
13541 intel_crtc
->num_scalers
= SKL_NUM_SCALERS
;
13543 skl_init_scalers(dev
, intel_crtc
, crtc_state
);
13546 primary
= intel_primary_plane_create(dev
, pipe
);
13550 cursor
= intel_cursor_plane_create(dev
, pipe
);
13554 ret
= drm_crtc_init_with_planes(dev
, &intel_crtc
->base
, primary
,
13555 cursor
, &intel_crtc_funcs
);
13559 drm_mode_crtc_set_gamma_size(&intel_crtc
->base
, 256);
13560 for (i
= 0; i
< 256; i
++) {
13561 intel_crtc
->lut_r
[i
] = i
;
13562 intel_crtc
->lut_g
[i
] = i
;
13563 intel_crtc
->lut_b
[i
] = i
;
13567 * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
13568 * is hooked to pipe B. Hence we want plane A feeding pipe B.
13570 intel_crtc
->pipe
= pipe
;
13571 intel_crtc
->plane
= pipe
;
13572 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4) {
13573 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
13574 intel_crtc
->plane
= !pipe
;
13577 intel_crtc
->cursor_base
= ~0;
13578 intel_crtc
->cursor_cntl
= ~0;
13579 intel_crtc
->cursor_size
= ~0;
13581 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
13582 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
13583 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
13584 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
13586 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
13588 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
13593 drm_plane_cleanup(primary
);
13595 drm_plane_cleanup(cursor
);
13600 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
13602 struct drm_encoder
*encoder
= connector
->base
.encoder
;
13603 struct drm_device
*dev
= connector
->base
.dev
;
13605 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
13607 if (!encoder
|| WARN_ON(!encoder
->crtc
))
13608 return INVALID_PIPE
;
13610 return to_intel_crtc(encoder
->crtc
)->pipe
;
13613 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
13614 struct drm_file
*file
)
13616 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
13617 struct drm_crtc
*drmmode_crtc
;
13618 struct intel_crtc
*crtc
;
13620 drmmode_crtc
= drm_crtc_find(dev
, pipe_from_crtc_id
->crtc_id
);
13622 if (!drmmode_crtc
) {
13623 DRM_ERROR("no such CRTC id\n");
13627 crtc
= to_intel_crtc(drmmode_crtc
);
13628 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
13633 static int intel_encoder_clones(struct intel_encoder
*encoder
)
13635 struct drm_device
*dev
= encoder
->base
.dev
;
13636 struct intel_encoder
*source_encoder
;
13637 int index_mask
= 0;
13640 for_each_intel_encoder(dev
, source_encoder
) {
13641 if (encoders_cloneable(encoder
, source_encoder
))
13642 index_mask
|= (1 << entry
);
13650 static bool has_edp_a(struct drm_device
*dev
)
13652 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13654 if (!IS_MOBILE(dev
))
13657 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
13660 if (IS_GEN5(dev
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
13666 static bool intel_crt_present(struct drm_device
*dev
)
13668 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13670 if (INTEL_INFO(dev
)->gen
>= 9)
13673 if (IS_HSW_ULT(dev
) || IS_BDW_ULT(dev
))
13676 if (IS_CHERRYVIEW(dev
))
13679 if (IS_VALLEYVIEW(dev
) && !dev_priv
->vbt
.int_crt_support
)
13685 static void intel_setup_outputs(struct drm_device
*dev
)
13687 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13688 struct intel_encoder
*encoder
;
13689 bool dpd_is_edp
= false;
13691 intel_lvds_init(dev
);
13693 if (intel_crt_present(dev
))
13694 intel_crt_init(dev
);
13696 if (IS_BROXTON(dev
)) {
13698 * FIXME: Broxton doesn't support port detection via the
13699 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
13700 * detect the ports.
13702 intel_ddi_init(dev
, PORT_A
);
13703 intel_ddi_init(dev
, PORT_B
);
13704 intel_ddi_init(dev
, PORT_C
);
13705 } else if (HAS_DDI(dev
)) {
13709 * Haswell uses DDI functions to detect digital outputs.
13710 * On SKL pre-D0 the strap isn't connected, so we assume
13713 found
= I915_READ(DDI_BUF_CTL_A
) & DDI_INIT_DISPLAY_DETECTED
;
13714 /* WaIgnoreDDIAStrap: skl */
13716 (IS_SKYLAKE(dev
) && INTEL_REVID(dev
) < SKL_REVID_D0
))
13717 intel_ddi_init(dev
, PORT_A
);
13719 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
13721 found
= I915_READ(SFUSE_STRAP
);
13723 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
13724 intel_ddi_init(dev
, PORT_B
);
13725 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
13726 intel_ddi_init(dev
, PORT_C
);
13727 if (found
& SFUSE_STRAP_DDID_DETECTED
)
13728 intel_ddi_init(dev
, PORT_D
);
13729 } else if (HAS_PCH_SPLIT(dev
)) {
13731 dpd_is_edp
= intel_dp_is_edp(dev
, PORT_D
);
13733 if (has_edp_a(dev
))
13734 intel_dp_init(dev
, DP_A
, PORT_A
);
13736 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
13737 /* PCH SDVOB multiplex with HDMIB */
13738 found
= intel_sdvo_init(dev
, PCH_SDVOB
, true);
13740 intel_hdmi_init(dev
, PCH_HDMIB
, PORT_B
);
13741 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
13742 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
13745 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
13746 intel_hdmi_init(dev
, PCH_HDMIC
, PORT_C
);
13748 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
13749 intel_hdmi_init(dev
, PCH_HDMID
, PORT_D
);
13751 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
13752 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
13754 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
13755 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
13756 } else if (IS_VALLEYVIEW(dev
)) {
13758 * The DP_DETECTED bit is the latched state of the DDC
13759 * SDA pin at boot. However since eDP doesn't require DDC
13760 * (no way to plug in a DP->HDMI dongle) the DDC pins for
13761 * eDP ports may have been muxed to an alternate function.
13762 * Thus we can't rely on the DP_DETECTED bit alone to detect
13763 * eDP ports. Consult the VBT as well as DP_DETECTED to
13764 * detect eDP ports.
13766 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIB
) & SDVO_DETECTED
&&
13767 !intel_dp_is_edp(dev
, PORT_B
))
13768 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIB
,
13770 if (I915_READ(VLV_DISPLAY_BASE
+ DP_B
) & DP_DETECTED
||
13771 intel_dp_is_edp(dev
, PORT_B
))
13772 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_B
, PORT_B
);
13774 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIC
) & SDVO_DETECTED
&&
13775 !intel_dp_is_edp(dev
, PORT_C
))
13776 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIC
,
13778 if (I915_READ(VLV_DISPLAY_BASE
+ DP_C
) & DP_DETECTED
||
13779 intel_dp_is_edp(dev
, PORT_C
))
13780 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_C
, PORT_C
);
13782 if (IS_CHERRYVIEW(dev
)) {
13783 if (I915_READ(VLV_DISPLAY_BASE
+ CHV_HDMID
) & SDVO_DETECTED
)
13784 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ CHV_HDMID
,
13786 /* eDP not supported on port D, so don't check VBT */
13787 if (I915_READ(VLV_DISPLAY_BASE
+ DP_D
) & DP_DETECTED
)
13788 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_D
, PORT_D
);
13791 intel_dsi_init(dev
);
13792 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev
)) {
13793 bool found
= false;
13795 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
13796 DRM_DEBUG_KMS("probing SDVOB\n");
13797 found
= intel_sdvo_init(dev
, GEN3_SDVOB
, true);
13798 if (!found
&& SUPPORTS_INTEGRATED_HDMI(dev
)) {
13799 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
13800 intel_hdmi_init(dev
, GEN4_HDMIB
, PORT_B
);
13803 if (!found
&& SUPPORTS_INTEGRATED_DP(dev
))
13804 intel_dp_init(dev
, DP_B
, PORT_B
);
13807 /* Before G4X SDVOC doesn't have its own detect register */
13809 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
13810 DRM_DEBUG_KMS("probing SDVOC\n");
13811 found
= intel_sdvo_init(dev
, GEN3_SDVOC
, false);
13814 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
13816 if (SUPPORTS_INTEGRATED_HDMI(dev
)) {
13817 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
13818 intel_hdmi_init(dev
, GEN4_HDMIC
, PORT_C
);
13820 if (SUPPORTS_INTEGRATED_DP(dev
))
13821 intel_dp_init(dev
, DP_C
, PORT_C
);
13824 if (SUPPORTS_INTEGRATED_DP(dev
) &&
13825 (I915_READ(DP_D
) & DP_DETECTED
))
13826 intel_dp_init(dev
, DP_D
, PORT_D
);
13827 } else if (IS_GEN2(dev
))
13828 intel_dvo_init(dev
);
13830 if (SUPPORTS_TV(dev
))
13831 intel_tv_init(dev
);
13833 intel_psr_init(dev
);
13835 for_each_intel_encoder(dev
, encoder
) {
13836 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
13837 encoder
->base
.possible_clones
=
13838 intel_encoder_clones(encoder
);
13841 intel_init_pch_refclk(dev
);
13843 drm_helper_move_panel_connectors_to_head(dev
);
13846 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
13848 struct drm_device
*dev
= fb
->dev
;
13849 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
13851 drm_framebuffer_cleanup(fb
);
13852 mutex_lock(&dev
->struct_mutex
);
13853 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
13854 drm_gem_object_unreference(&intel_fb
->obj
->base
);
13855 mutex_unlock(&dev
->struct_mutex
);
13859 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
13860 struct drm_file
*file
,
13861 unsigned int *handle
)
13863 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
13864 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
13866 return drm_gem_handle_create(file
, &obj
->base
, handle
);
13869 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
13870 .destroy
= intel_user_framebuffer_destroy
,
13871 .create_handle
= intel_user_framebuffer_create_handle
,
13875 u32
intel_fb_pitch_limit(struct drm_device
*dev
, uint64_t fb_modifier
,
13876 uint32_t pixel_format
)
13878 u32 gen
= INTEL_INFO(dev
)->gen
;
13881 /* "The stride in bytes must not exceed the of the size of 8K
13882 * pixels and 32K bytes."
13884 return min(8192*drm_format_plane_cpp(pixel_format
, 0), 32768);
13885 } else if (gen
>= 5 && !IS_VALLEYVIEW(dev
)) {
13887 } else if (gen
>= 4) {
13888 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
13892 } else if (gen
>= 3) {
13893 if (fb_modifier
== I915_FORMAT_MOD_X_TILED
)
13898 /* XXX DSPC is limited to 4k tiled */
13903 static int intel_framebuffer_init(struct drm_device
*dev
,
13904 struct intel_framebuffer
*intel_fb
,
13905 struct drm_mode_fb_cmd2
*mode_cmd
,
13906 struct drm_i915_gem_object
*obj
)
13908 unsigned int aligned_height
;
13910 u32 pitch_limit
, stride_alignment
;
13912 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
13914 if (mode_cmd
->flags
& DRM_MODE_FB_MODIFIERS
) {
13915 /* Enforce that fb modifier and tiling mode match, but only for
13916 * X-tiled. This is needed for FBC. */
13917 if (!!(obj
->tiling_mode
== I915_TILING_X
) !=
13918 !!(mode_cmd
->modifier
[0] == I915_FORMAT_MOD_X_TILED
)) {
13919 DRM_DEBUG("tiling_mode doesn't match fb modifier\n");
13923 if (obj
->tiling_mode
== I915_TILING_X
)
13924 mode_cmd
->modifier
[0] = I915_FORMAT_MOD_X_TILED
;
13925 else if (obj
->tiling_mode
== I915_TILING_Y
) {
13926 DRM_DEBUG("No Y tiling for legacy addfb\n");
13931 /* Passed in modifier sanity checking. */
13932 switch (mode_cmd
->modifier
[0]) {
13933 case I915_FORMAT_MOD_Y_TILED
:
13934 case I915_FORMAT_MOD_Yf_TILED
:
13935 if (INTEL_INFO(dev
)->gen
< 9) {
13936 DRM_DEBUG("Unsupported tiling 0x%llx!\n",
13937 mode_cmd
->modifier
[0]);
13940 case DRM_FORMAT_MOD_NONE
:
13941 case I915_FORMAT_MOD_X_TILED
:
13944 DRM_DEBUG("Unsupported fb modifier 0x%llx!\n",
13945 mode_cmd
->modifier
[0]);
13949 stride_alignment
= intel_fb_stride_alignment(dev
, mode_cmd
->modifier
[0],
13950 mode_cmd
->pixel_format
);
13951 if (mode_cmd
->pitches
[0] & (stride_alignment
- 1)) {
13952 DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n",
13953 mode_cmd
->pitches
[0], stride_alignment
);
13957 pitch_limit
= intel_fb_pitch_limit(dev
, mode_cmd
->modifier
[0],
13958 mode_cmd
->pixel_format
);
13959 if (mode_cmd
->pitches
[0] > pitch_limit
) {
13960 DRM_DEBUG("%s pitch (%u) must be at less than %d\n",
13961 mode_cmd
->modifier
[0] != DRM_FORMAT_MOD_NONE
?
13962 "tiled" : "linear",
13963 mode_cmd
->pitches
[0], pitch_limit
);
13967 if (mode_cmd
->modifier
[0] == I915_FORMAT_MOD_X_TILED
&&
13968 mode_cmd
->pitches
[0] != obj
->stride
) {
13969 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
13970 mode_cmd
->pitches
[0], obj
->stride
);
13974 /* Reject formats not supported by any plane early. */
13975 switch (mode_cmd
->pixel_format
) {
13976 case DRM_FORMAT_C8
:
13977 case DRM_FORMAT_RGB565
:
13978 case DRM_FORMAT_XRGB8888
:
13979 case DRM_FORMAT_ARGB8888
:
13981 case DRM_FORMAT_XRGB1555
:
13982 if (INTEL_INFO(dev
)->gen
> 3) {
13983 DRM_DEBUG("unsupported pixel format: %s\n",
13984 drm_get_format_name(mode_cmd
->pixel_format
));
13988 case DRM_FORMAT_XBGR8888
:
13989 case DRM_FORMAT_ABGR8888
:
13990 case DRM_FORMAT_XRGB2101010
:
13991 case DRM_FORMAT_XBGR2101010
:
13992 if (INTEL_INFO(dev
)->gen
< 4) {
13993 DRM_DEBUG("unsupported pixel format: %s\n",
13994 drm_get_format_name(mode_cmd
->pixel_format
));
13998 case DRM_FORMAT_ABGR2101010
:
13999 if (!IS_VALLEYVIEW(dev
)) {
14000 DRM_DEBUG("unsupported pixel format: %s\n",
14001 drm_get_format_name(mode_cmd
->pixel_format
));
14005 case DRM_FORMAT_YUYV
:
14006 case DRM_FORMAT_UYVY
:
14007 case DRM_FORMAT_YVYU
:
14008 case DRM_FORMAT_VYUY
:
14009 if (INTEL_INFO(dev
)->gen
< 5) {
14010 DRM_DEBUG("unsupported pixel format: %s\n",
14011 drm_get_format_name(mode_cmd
->pixel_format
));
14016 DRM_DEBUG("unsupported pixel format: %s\n",
14017 drm_get_format_name(mode_cmd
->pixel_format
));
14021 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14022 if (mode_cmd
->offsets
[0] != 0)
14025 aligned_height
= intel_fb_align_height(dev
, mode_cmd
->height
,
14026 mode_cmd
->pixel_format
,
14027 mode_cmd
->modifier
[0]);
14028 /* FIXME drm helper for size checks (especially planar formats)? */
14029 if (obj
->base
.size
< aligned_height
* mode_cmd
->pitches
[0])
14032 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
14033 intel_fb
->obj
= obj
;
14034 intel_fb
->obj
->framebuffer_references
++;
14036 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
14038 DRM_ERROR("framebuffer init failed %d\n", ret
);
14045 static struct drm_framebuffer
*
14046 intel_user_framebuffer_create(struct drm_device
*dev
,
14047 struct drm_file
*filp
,
14048 struct drm_mode_fb_cmd2
*mode_cmd
)
14050 struct drm_i915_gem_object
*obj
;
14052 obj
= to_intel_bo(drm_gem_object_lookup(dev
, filp
,
14053 mode_cmd
->handles
[0]));
14054 if (&obj
->base
== NULL
)
14055 return ERR_PTR(-ENOENT
);
14057 return intel_framebuffer_create(dev
, mode_cmd
, obj
);
14060 #ifndef CONFIG_DRM_I915_FBDEV
14061 static inline void intel_fbdev_output_poll_changed(struct drm_device
*dev
)
14066 static const struct drm_mode_config_funcs intel_mode_funcs
= {
14067 .fb_create
= intel_user_framebuffer_create
,
14068 .output_poll_changed
= intel_fbdev_output_poll_changed
,
14069 .atomic_check
= intel_atomic_check
,
14070 .atomic_commit
= intel_atomic_commit
,
14073 /* Set up chip specific display functions */
14074 static void intel_init_display(struct drm_device
*dev
)
14076 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14078 if (HAS_PCH_SPLIT(dev
) || IS_G4X(dev
))
14079 dev_priv
->display
.find_dpll
= g4x_find_best_dpll
;
14080 else if (IS_CHERRYVIEW(dev
))
14081 dev_priv
->display
.find_dpll
= chv_find_best_dpll
;
14082 else if (IS_VALLEYVIEW(dev
))
14083 dev_priv
->display
.find_dpll
= vlv_find_best_dpll
;
14084 else if (IS_PINEVIEW(dev
))
14085 dev_priv
->display
.find_dpll
= pnv_find_best_dpll
;
14087 dev_priv
->display
.find_dpll
= i9xx_find_best_dpll
;
14089 if (INTEL_INFO(dev
)->gen
>= 9) {
14090 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
14091 dev_priv
->display
.get_initial_plane_config
=
14092 skylake_get_initial_plane_config
;
14093 dev_priv
->display
.crtc_compute_clock
=
14094 haswell_crtc_compute_clock
;
14095 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
14096 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
14097 dev_priv
->display
.off
= ironlake_crtc_off
;
14098 dev_priv
->display
.update_primary_plane
=
14099 skylake_update_primary_plane
;
14100 } else if (HAS_DDI(dev
)) {
14101 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
14102 dev_priv
->display
.get_initial_plane_config
=
14103 ironlake_get_initial_plane_config
;
14104 dev_priv
->display
.crtc_compute_clock
=
14105 haswell_crtc_compute_clock
;
14106 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
14107 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
14108 dev_priv
->display
.off
= ironlake_crtc_off
;
14109 dev_priv
->display
.update_primary_plane
=
14110 ironlake_update_primary_plane
;
14111 } else if (HAS_PCH_SPLIT(dev
)) {
14112 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
14113 dev_priv
->display
.get_initial_plane_config
=
14114 ironlake_get_initial_plane_config
;
14115 dev_priv
->display
.crtc_compute_clock
=
14116 ironlake_crtc_compute_clock
;
14117 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
14118 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
14119 dev_priv
->display
.off
= ironlake_crtc_off
;
14120 dev_priv
->display
.update_primary_plane
=
14121 ironlake_update_primary_plane
;
14122 } else if (IS_VALLEYVIEW(dev
)) {
14123 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14124 dev_priv
->display
.get_initial_plane_config
=
14125 i9xx_get_initial_plane_config
;
14126 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
14127 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
14128 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14129 dev_priv
->display
.off
= i9xx_crtc_off
;
14130 dev_priv
->display
.update_primary_plane
=
14131 i9xx_update_primary_plane
;
14133 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
14134 dev_priv
->display
.get_initial_plane_config
=
14135 i9xx_get_initial_plane_config
;
14136 dev_priv
->display
.crtc_compute_clock
= i9xx_crtc_compute_clock
;
14137 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
14138 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
14139 dev_priv
->display
.off
= i9xx_crtc_off
;
14140 dev_priv
->display
.update_primary_plane
=
14141 i9xx_update_primary_plane
;
14144 /* Returns the core display clock speed */
14145 if (IS_SKYLAKE(dev
))
14146 dev_priv
->display
.get_display_clock_speed
=
14147 skylake_get_display_clock_speed
;
14148 else if (IS_BROADWELL(dev
))
14149 dev_priv
->display
.get_display_clock_speed
=
14150 broadwell_get_display_clock_speed
;
14151 else if (IS_HASWELL(dev
))
14152 dev_priv
->display
.get_display_clock_speed
=
14153 haswell_get_display_clock_speed
;
14154 else if (IS_VALLEYVIEW(dev
))
14155 dev_priv
->display
.get_display_clock_speed
=
14156 valleyview_get_display_clock_speed
;
14157 else if (IS_GEN5(dev
))
14158 dev_priv
->display
.get_display_clock_speed
=
14159 ilk_get_display_clock_speed
;
14160 else if (IS_I945G(dev
) || IS_BROADWATER(dev
) ||
14161 IS_GEN6(dev
) || IS_IVYBRIDGE(dev
) || (IS_G33(dev
) && !IS_PINEVIEW_M(dev
)))
14162 dev_priv
->display
.get_display_clock_speed
=
14163 i945_get_display_clock_speed
;
14164 else if (IS_I915G(dev
))
14165 dev_priv
->display
.get_display_clock_speed
=
14166 i915_get_display_clock_speed
;
14167 else if (IS_I945GM(dev
) || IS_845G(dev
))
14168 dev_priv
->display
.get_display_clock_speed
=
14169 i9xx_misc_get_display_clock_speed
;
14170 else if (IS_PINEVIEW(dev
))
14171 dev_priv
->display
.get_display_clock_speed
=
14172 pnv_get_display_clock_speed
;
14173 else if (IS_I915GM(dev
))
14174 dev_priv
->display
.get_display_clock_speed
=
14175 i915gm_get_display_clock_speed
;
14176 else if (IS_I865G(dev
))
14177 dev_priv
->display
.get_display_clock_speed
=
14178 i865_get_display_clock_speed
;
14179 else if (IS_I85X(dev
))
14180 dev_priv
->display
.get_display_clock_speed
=
14181 i855_get_display_clock_speed
;
14182 else /* 852, 830 */
14183 dev_priv
->display
.get_display_clock_speed
=
14184 i830_get_display_clock_speed
;
14186 if (IS_GEN5(dev
)) {
14187 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
14188 } else if (IS_GEN6(dev
)) {
14189 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
14190 } else if (IS_IVYBRIDGE(dev
)) {
14191 /* FIXME: detect B0+ stepping and use auto training */
14192 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
14193 } else if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
14194 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
14195 } else if (IS_VALLEYVIEW(dev
)) {
14196 dev_priv
->display
.modeset_global_resources
=
14197 valleyview_modeset_global_resources
;
14198 } else if (IS_BROXTON(dev
)) {
14199 dev_priv
->display
.modeset_global_resources
=
14200 broxton_modeset_global_resources
;
14203 switch (INTEL_INFO(dev
)->gen
) {
14205 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
14209 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
14214 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
14218 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
14221 case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
14222 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
14225 /* Drop through - unsupported since execlist only. */
14227 /* Default just returns -ENODEV to indicate unsupported */
14228 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
14231 intel_panel_init_backlight_funcs(dev
);
14233 mutex_init(&dev_priv
->pps_mutex
);
14237 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
14238 * resume, or other times. This quirk makes sure that's the case for
14239 * affected systems.
14241 static void quirk_pipea_force(struct drm_device
*dev
)
14243 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14245 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
14246 DRM_INFO("applying pipe a force quirk\n");
14249 static void quirk_pipeb_force(struct drm_device
*dev
)
14251 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14253 dev_priv
->quirks
|= QUIRK_PIPEB_FORCE
;
14254 DRM_INFO("applying pipe b force quirk\n");
14258 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
14260 static void quirk_ssc_force_disable(struct drm_device
*dev
)
14262 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14263 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
14264 DRM_INFO("applying lvds SSC disable quirk\n");
14268 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
14271 static void quirk_invert_brightness(struct drm_device
*dev
)
14273 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14274 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
14275 DRM_INFO("applying inverted panel brightness quirk\n");
14278 /* Some VBT's incorrectly indicate no backlight is present */
14279 static void quirk_backlight_present(struct drm_device
*dev
)
14281 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14282 dev_priv
->quirks
|= QUIRK_BACKLIGHT_PRESENT
;
14283 DRM_INFO("applying backlight present quirk\n");
14286 struct intel_quirk
{
14288 int subsystem_vendor
;
14289 int subsystem_device
;
14290 void (*hook
)(struct drm_device
*dev
);
14293 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
14294 struct intel_dmi_quirk
{
14295 void (*hook
)(struct drm_device
*dev
);
14296 const struct dmi_system_id (*dmi_id_list
)[];
14299 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
14301 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
14305 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
14307 .dmi_id_list
= &(const struct dmi_system_id
[]) {
14309 .callback
= intel_dmi_reverse_brightness
,
14310 .ident
= "NCR Corporation",
14311 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
14312 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
14315 { } /* terminating entry */
14317 .hook
= quirk_invert_brightness
,
14321 static struct intel_quirk intel_quirks
[] = {
14322 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
14323 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
14325 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
14326 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
14328 /* 830 needs to leave pipe A & dpll A up */
14329 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
14331 /* 830 needs to leave pipe B & dpll B up */
14332 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipeb_force
},
14334 /* Lenovo U160 cannot use SSC on LVDS */
14335 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
14337 /* Sony Vaio Y cannot use SSC on LVDS */
14338 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
14340 /* Acer Aspire 5734Z must invert backlight brightness */
14341 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
14343 /* Acer/eMachines G725 */
14344 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
14346 /* Acer/eMachines e725 */
14347 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
14349 /* Acer/Packard Bell NCL20 */
14350 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
14352 /* Acer Aspire 4736Z */
14353 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
14355 /* Acer Aspire 5336 */
14356 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
14358 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
14359 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present
},
14361 /* Acer C720 Chromebook (Core i3 4005U) */
14362 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present
},
14364 /* Apple Macbook 2,1 (Core 2 T7400) */
14365 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present
},
14367 /* Toshiba CB35 Chromebook (Celeron 2955U) */
14368 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present
},
14370 /* HP Chromebook 14 (Celeron 2955U) */
14371 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present
},
14373 /* Dell Chromebook 11 */
14374 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present
},
14377 static void intel_init_quirks(struct drm_device
*dev
)
14379 struct pci_dev
*d
= dev
->pdev
;
14382 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
14383 struct intel_quirk
*q
= &intel_quirks
[i
];
14385 if (d
->device
== q
->device
&&
14386 (d
->subsystem_vendor
== q
->subsystem_vendor
||
14387 q
->subsystem_vendor
== PCI_ANY_ID
) &&
14388 (d
->subsystem_device
== q
->subsystem_device
||
14389 q
->subsystem_device
== PCI_ANY_ID
))
14392 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
14393 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
14394 intel_dmi_quirks
[i
].hook(dev
);
14398 /* Disable the VGA plane that we never use */
14399 static void i915_disable_vga(struct drm_device
*dev
)
14401 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14403 u32 vga_reg
= i915_vgacntrl_reg(dev
);
14405 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
14406 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
14407 outb(SR01
, VGA_SR_INDEX
);
14408 sr1
= inb(VGA_SR_DATA
);
14409 outb(sr1
| 1<<5, VGA_SR_DATA
);
14410 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
14413 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
14414 POSTING_READ(vga_reg
);
14417 void intel_modeset_init_hw(struct drm_device
*dev
)
14419 intel_prepare_ddi(dev
);
14421 if (IS_VALLEYVIEW(dev
))
14422 vlv_update_cdclk(dev
);
14424 intel_init_clock_gating(dev
);
14426 intel_enable_gt_powersave(dev
);
14429 void intel_modeset_init(struct drm_device
*dev
)
14431 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14434 struct intel_crtc
*crtc
;
14436 drm_mode_config_init(dev
);
14438 dev
->mode_config
.min_width
= 0;
14439 dev
->mode_config
.min_height
= 0;
14441 dev
->mode_config
.preferred_depth
= 24;
14442 dev
->mode_config
.prefer_shadow
= 1;
14444 dev
->mode_config
.allow_fb_modifiers
= true;
14446 dev
->mode_config
.funcs
= &intel_mode_funcs
;
14448 intel_init_quirks(dev
);
14450 intel_init_pm(dev
);
14452 if (INTEL_INFO(dev
)->num_pipes
== 0)
14455 intel_init_display(dev
);
14456 intel_init_audio(dev
);
14458 if (IS_GEN2(dev
)) {
14459 dev
->mode_config
.max_width
= 2048;
14460 dev
->mode_config
.max_height
= 2048;
14461 } else if (IS_GEN3(dev
)) {
14462 dev
->mode_config
.max_width
= 4096;
14463 dev
->mode_config
.max_height
= 4096;
14465 dev
->mode_config
.max_width
= 8192;
14466 dev
->mode_config
.max_height
= 8192;
14469 if (IS_845G(dev
) || IS_I865G(dev
)) {
14470 dev
->mode_config
.cursor_width
= IS_845G(dev
) ? 64 : 512;
14471 dev
->mode_config
.cursor_height
= 1023;
14472 } else if (IS_GEN2(dev
)) {
14473 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
14474 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
14476 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
14477 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
14480 dev
->mode_config
.fb_base
= dev_priv
->gtt
.mappable_base
;
14482 DRM_DEBUG_KMS("%d display pipe%s available.\n",
14483 INTEL_INFO(dev
)->num_pipes
,
14484 INTEL_INFO(dev
)->num_pipes
> 1 ? "s" : "");
14486 for_each_pipe(dev_priv
, pipe
) {
14487 intel_crtc_init(dev
, pipe
);
14488 for_each_sprite(dev_priv
, pipe
, sprite
) {
14489 ret
= intel_plane_init(dev
, pipe
, sprite
);
14491 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
14492 pipe_name(pipe
), sprite_name(pipe
, sprite
), ret
);
14496 intel_init_dpio(dev
);
14498 intel_shared_dpll_init(dev
);
14500 /* Just disable it once at startup */
14501 i915_disable_vga(dev
);
14502 intel_setup_outputs(dev
);
14504 /* Just in case the BIOS is doing something questionable. */
14505 intel_fbc_disable(dev
);
14507 drm_modeset_lock_all(dev
);
14508 intel_modeset_setup_hw_state(dev
, false);
14509 drm_modeset_unlock_all(dev
);
14511 for_each_intel_crtc(dev
, crtc
) {
14516 * Note that reserving the BIOS fb up front prevents us
14517 * from stuffing other stolen allocations like the ring
14518 * on top. This prevents some ugliness at boot time, and
14519 * can even allow for smooth boot transitions if the BIOS
14520 * fb is large enough for the active pipe configuration.
14522 if (dev_priv
->display
.get_initial_plane_config
) {
14523 dev_priv
->display
.get_initial_plane_config(crtc
,
14524 &crtc
->plane_config
);
14526 * If the fb is shared between multiple heads, we'll
14527 * just get the first one.
14529 intel_find_initial_plane_obj(crtc
, &crtc
->plane_config
);
14534 static void intel_enable_pipe_a(struct drm_device
*dev
)
14536 struct intel_connector
*connector
;
14537 struct drm_connector
*crt
= NULL
;
14538 struct intel_load_detect_pipe load_detect_temp
;
14539 struct drm_modeset_acquire_ctx
*ctx
= dev
->mode_config
.acquire_ctx
;
14541 /* We can't just switch on the pipe A, we need to set things up with a
14542 * proper mode and output configuration. As a gross hack, enable pipe A
14543 * by enabling the load detect pipe once. */
14544 for_each_intel_connector(dev
, connector
) {
14545 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
14546 crt
= &connector
->base
;
14554 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
, ctx
))
14555 intel_release_load_detect_pipe(crt
, &load_detect_temp
, ctx
);
14559 intel_check_plane_mapping(struct intel_crtc
*crtc
)
14561 struct drm_device
*dev
= crtc
->base
.dev
;
14562 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14565 if (INTEL_INFO(dev
)->num_pipes
== 1)
14568 reg
= DSPCNTR(!crtc
->plane
);
14569 val
= I915_READ(reg
);
14571 if ((val
& DISPLAY_PLANE_ENABLE
) &&
14572 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
14578 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
14580 struct drm_device
*dev
= crtc
->base
.dev
;
14581 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14584 /* Clear any frame start delays used for debugging left by the BIOS */
14585 reg
= PIPECONF(crtc
->config
->cpu_transcoder
);
14586 I915_WRITE(reg
, I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
14588 /* restore vblank interrupts to correct state */
14589 drm_crtc_vblank_reset(&crtc
->base
);
14590 if (crtc
->active
) {
14591 update_scanline_offset(crtc
);
14592 drm_crtc_vblank_on(&crtc
->base
);
14595 /* We need to sanitize the plane -> pipe mapping first because this will
14596 * disable the crtc (and hence change the state) if it is wrong. Note
14597 * that gen4+ has a fixed plane -> pipe mapping. */
14598 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
14599 struct intel_connector
*connector
;
14602 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
14603 crtc
->base
.base
.id
);
14605 /* Pipe has the wrong plane attached and the plane is active.
14606 * Temporarily change the plane mapping and disable everything
14608 plane
= crtc
->plane
;
14609 to_intel_plane_state(crtc
->base
.primary
->state
)->visible
= true;
14610 crtc
->plane
= !plane
;
14611 intel_crtc_disable_planes(&crtc
->base
);
14612 dev_priv
->display
.crtc_disable(&crtc
->base
);
14613 crtc
->plane
= plane
;
14615 /* ... and break all links. */
14616 for_each_intel_connector(dev
, connector
) {
14617 if (connector
->encoder
->base
.crtc
!= &crtc
->base
)
14620 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
14621 connector
->base
.encoder
= NULL
;
14623 /* multiple connectors may have the same encoder:
14624 * handle them and break crtc link separately */
14625 for_each_intel_connector(dev
, connector
)
14626 if (connector
->encoder
->base
.crtc
== &crtc
->base
) {
14627 connector
->encoder
->base
.crtc
= NULL
;
14628 connector
->encoder
->connectors_active
= false;
14631 WARN_ON(crtc
->active
);
14632 crtc
->base
.state
->enable
= false;
14633 crtc
->base
.state
->active
= false;
14634 crtc
->base
.enabled
= false;
14637 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
14638 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
14639 /* BIOS forgot to enable pipe A, this mostly happens after
14640 * resume. Force-enable the pipe to fix this, the update_dpms
14641 * call below we restore the pipe to the right state, but leave
14642 * the required bits on. */
14643 intel_enable_pipe_a(dev
);
14646 /* Adjust the state of the output pipe according to whether we
14647 * have active connectors/encoders. */
14648 intel_crtc_update_dpms(&crtc
->base
);
14650 if (crtc
->active
!= crtc
->base
.state
->enable
) {
14651 struct intel_encoder
*encoder
;
14653 /* This can happen either due to bugs in the get_hw_state
14654 * functions or because the pipe is force-enabled due to the
14656 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
14657 crtc
->base
.base
.id
,
14658 crtc
->base
.state
->enable
? "enabled" : "disabled",
14659 crtc
->active
? "enabled" : "disabled");
14661 crtc
->base
.state
->enable
= crtc
->active
;
14662 crtc
->base
.state
->active
= crtc
->active
;
14663 crtc
->base
.enabled
= crtc
->active
;
14665 /* Because we only establish the connector -> encoder ->
14666 * crtc links if something is active, this means the
14667 * crtc is now deactivated. Break the links. connector
14668 * -> encoder links are only establish when things are
14669 * actually up, hence no need to break them. */
14670 WARN_ON(crtc
->active
);
14672 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
14673 WARN_ON(encoder
->connectors_active
);
14674 encoder
->base
.crtc
= NULL
;
14678 if (crtc
->active
|| HAS_GMCH_DISPLAY(dev
)) {
14680 * We start out with underrun reporting disabled to avoid races.
14681 * For correct bookkeeping mark this on active crtcs.
14683 * Also on gmch platforms we dont have any hardware bits to
14684 * disable the underrun reporting. Which means we need to start
14685 * out with underrun reporting disabled also on inactive pipes,
14686 * since otherwise we'll complain about the garbage we read when
14687 * e.g. coming up after runtime pm.
14689 * No protection against concurrent access is required - at
14690 * worst a fifo underrun happens which also sets this to false.
14692 crtc
->cpu_fifo_underrun_disabled
= true;
14693 crtc
->pch_fifo_underrun_disabled
= true;
14697 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
14699 struct intel_connector
*connector
;
14700 struct drm_device
*dev
= encoder
->base
.dev
;
14702 /* We need to check both for a crtc link (meaning that the
14703 * encoder is active and trying to read from a pipe) and the
14704 * pipe itself being active. */
14705 bool has_active_crtc
= encoder
->base
.crtc
&&
14706 to_intel_crtc(encoder
->base
.crtc
)->active
;
14708 if (encoder
->connectors_active
&& !has_active_crtc
) {
14709 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
14710 encoder
->base
.base
.id
,
14711 encoder
->base
.name
);
14713 /* Connector is active, but has no active pipe. This is
14714 * fallout from our resume register restoring. Disable
14715 * the encoder manually again. */
14716 if (encoder
->base
.crtc
) {
14717 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
14718 encoder
->base
.base
.id
,
14719 encoder
->base
.name
);
14720 encoder
->disable(encoder
);
14721 if (encoder
->post_disable
)
14722 encoder
->post_disable(encoder
);
14724 encoder
->base
.crtc
= NULL
;
14725 encoder
->connectors_active
= false;
14727 /* Inconsistent output/port/pipe state happens presumably due to
14728 * a bug in one of the get_hw_state functions. Or someplace else
14729 * in our code, like the register restore mess on resume. Clamp
14730 * things to off as a safer default. */
14731 for_each_intel_connector(dev
, connector
) {
14732 if (connector
->encoder
!= encoder
)
14734 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
14735 connector
->base
.encoder
= NULL
;
14738 /* Enabled encoders without active connectors will be fixed in
14739 * the crtc fixup. */
14742 void i915_redisable_vga_power_on(struct drm_device
*dev
)
14744 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14745 u32 vga_reg
= i915_vgacntrl_reg(dev
);
14747 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
14748 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
14749 i915_disable_vga(dev
);
14753 void i915_redisable_vga(struct drm_device
*dev
)
14755 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14757 /* This function can be called both from intel_modeset_setup_hw_state or
14758 * at a very early point in our resume sequence, where the power well
14759 * structures are not yet restored. Since this function is at a very
14760 * paranoid "someone might have enabled VGA while we were not looking"
14761 * level, just check if the power well is enabled instead of trying to
14762 * follow the "don't touch the power well if we don't need it" policy
14763 * the rest of the driver uses. */
14764 if (!intel_display_power_is_enabled(dev_priv
, POWER_DOMAIN_VGA
))
14767 i915_redisable_vga_power_on(dev
);
14770 static bool primary_get_hw_state(struct intel_crtc
*crtc
)
14772 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
14777 return I915_READ(DSPCNTR(crtc
->plane
)) & DISPLAY_PLANE_ENABLE
;
14780 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
14782 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14784 struct intel_crtc
*crtc
;
14785 struct intel_encoder
*encoder
;
14786 struct intel_connector
*connector
;
14789 for_each_intel_crtc(dev
, crtc
) {
14790 struct drm_plane
*primary
= crtc
->base
.primary
;
14791 struct intel_plane_state
*plane_state
;
14793 memset(crtc
->config
, 0, sizeof(*crtc
->config
));
14795 crtc
->config
->quirks
|= PIPE_CONFIG_QUIRK_INHERITED_MODE
;
14797 crtc
->active
= dev_priv
->display
.get_pipe_config(crtc
,
14800 crtc
->base
.state
->enable
= crtc
->active
;
14801 crtc
->base
.state
->active
= crtc
->active
;
14802 crtc
->base
.enabled
= crtc
->active
;
14804 plane_state
= to_intel_plane_state(primary
->state
);
14805 plane_state
->visible
= primary_get_hw_state(crtc
);
14807 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
14808 crtc
->base
.base
.id
,
14809 crtc
->active
? "enabled" : "disabled");
14812 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
14813 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
14815 pll
->on
= pll
->get_hw_state(dev_priv
, pll
,
14816 &pll
->config
.hw_state
);
14818 pll
->config
.crtc_mask
= 0;
14819 for_each_intel_crtc(dev
, crtc
) {
14820 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
) {
14822 pll
->config
.crtc_mask
|= 1 << crtc
->pipe
;
14826 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
14827 pll
->name
, pll
->config
.crtc_mask
, pll
->on
);
14829 if (pll
->config
.crtc_mask
)
14830 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
14833 for_each_intel_encoder(dev
, encoder
) {
14836 if (encoder
->get_hw_state(encoder
, &pipe
)) {
14837 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
14838 encoder
->base
.crtc
= &crtc
->base
;
14839 encoder
->get_config(encoder
, crtc
->config
);
14841 encoder
->base
.crtc
= NULL
;
14844 encoder
->connectors_active
= false;
14845 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
14846 encoder
->base
.base
.id
,
14847 encoder
->base
.name
,
14848 encoder
->base
.crtc
? "enabled" : "disabled",
14852 for_each_intel_connector(dev
, connector
) {
14853 if (connector
->get_hw_state(connector
)) {
14854 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
14855 connector
->encoder
->connectors_active
= true;
14856 connector
->base
.encoder
= &connector
->encoder
->base
;
14858 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
14859 connector
->base
.encoder
= NULL
;
14861 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
14862 connector
->base
.base
.id
,
14863 connector
->base
.name
,
14864 connector
->base
.encoder
? "enabled" : "disabled");
14868 /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
14869 * and i915 state tracking structures. */
14870 void intel_modeset_setup_hw_state(struct drm_device
*dev
,
14871 bool force_restore
)
14873 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14875 struct intel_crtc
*crtc
;
14876 struct intel_encoder
*encoder
;
14879 intel_modeset_readout_hw_state(dev
);
14882 * Now that we have the config, copy it to each CRTC struct
14883 * Note that this could go away if we move to using crtc_config
14884 * checking everywhere.
14886 for_each_intel_crtc(dev
, crtc
) {
14887 if (crtc
->active
&& i915
.fastboot
) {
14888 intel_mode_from_pipe_config(&crtc
->base
.mode
,
14890 DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
14891 crtc
->base
.base
.id
);
14892 drm_mode_debug_printmodeline(&crtc
->base
.mode
);
14896 /* HW state is read out, now we need to sanitize this mess. */
14897 for_each_intel_encoder(dev
, encoder
) {
14898 intel_sanitize_encoder(encoder
);
14901 for_each_pipe(dev_priv
, pipe
) {
14902 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
14903 intel_sanitize_crtc(crtc
);
14904 intel_dump_pipe_config(crtc
, crtc
->config
,
14905 "[setup_hw_state]");
14908 intel_modeset_update_connector_atomic_state(dev
);
14910 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
14911 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
14913 if (!pll
->on
|| pll
->active
)
14916 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
14918 pll
->disable(dev_priv
, pll
);
14923 skl_wm_get_hw_state(dev
);
14924 else if (HAS_PCH_SPLIT(dev
))
14925 ilk_wm_get_hw_state(dev
);
14927 if (force_restore
) {
14928 i915_redisable_vga(dev
);
14931 * We need to use raw interfaces for restoring state to avoid
14932 * checking (bogus) intermediate states.
14934 for_each_pipe(dev_priv
, pipe
) {
14935 struct drm_crtc
*crtc
=
14936 dev_priv
->pipe_to_crtc_mapping
[pipe
];
14938 intel_crtc_restore_mode(crtc
);
14941 intel_modeset_update_staged_output_state(dev
);
14944 intel_modeset_check_state(dev
);
14947 void intel_modeset_gem_init(struct drm_device
*dev
)
14949 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
14950 struct drm_crtc
*c
;
14951 struct drm_i915_gem_object
*obj
;
14954 mutex_lock(&dev
->struct_mutex
);
14955 intel_init_gt_powersave(dev
);
14956 mutex_unlock(&dev
->struct_mutex
);
14959 * There may be no VBT; and if the BIOS enabled SSC we can
14960 * just keep using it to avoid unnecessary flicker. Whereas if the
14961 * BIOS isn't using it, don't assume it will work even if the VBT
14962 * indicates as much.
14964 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
14965 dev_priv
->vbt
.lvds_use_ssc
= !!(I915_READ(PCH_DREF_CONTROL
) &
14968 intel_modeset_init_hw(dev
);
14970 intel_setup_overlay(dev
);
14973 * Make sure any fbs we allocated at startup are properly
14974 * pinned & fenced. When we do the allocation it's too early
14977 for_each_crtc(dev
, c
) {
14978 obj
= intel_fb_obj(c
->primary
->fb
);
14982 mutex_lock(&dev
->struct_mutex
);
14983 ret
= intel_pin_and_fence_fb_obj(c
->primary
,
14987 mutex_unlock(&dev
->struct_mutex
);
14989 DRM_ERROR("failed to pin boot fb on pipe %d\n",
14990 to_intel_crtc(c
)->pipe
);
14991 drm_framebuffer_unreference(c
->primary
->fb
);
14992 c
->primary
->fb
= NULL
;
14993 update_state_fb(c
->primary
);
14997 intel_backlight_register(dev
);
15000 void intel_connector_unregister(struct intel_connector
*intel_connector
)
15002 struct drm_connector
*connector
= &intel_connector
->base
;
15004 intel_panel_destroy_backlight(connector
);
15005 drm_connector_unregister(connector
);
15008 void intel_modeset_cleanup(struct drm_device
*dev
)
15010 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15011 struct drm_connector
*connector
;
15013 intel_disable_gt_powersave(dev
);
15015 intel_backlight_unregister(dev
);
15018 * Interrupts and polling as the first thing to avoid creating havoc.
15019 * Too much stuff here (turning of connectors, ...) would
15020 * experience fancy races otherwise.
15022 intel_irq_uninstall(dev_priv
);
15025 * Due to the hpd irq storm handling the hotplug work can re-arm the
15026 * poll handlers. Hence disable polling after hpd handling is shut down.
15028 drm_kms_helper_poll_fini(dev
);
15030 mutex_lock(&dev
->struct_mutex
);
15032 intel_unregister_dsm_handler();
15034 intel_fbc_disable(dev
);
15036 mutex_unlock(&dev
->struct_mutex
);
15038 /* flush any delayed tasks or pending work */
15039 flush_scheduled_work();
15041 /* destroy the backlight and sysfs files before encoders/connectors */
15042 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
15043 struct intel_connector
*intel_connector
;
15045 intel_connector
= to_intel_connector(connector
);
15046 intel_connector
->unregister(intel_connector
);
15049 drm_mode_config_cleanup(dev
);
15051 intel_cleanup_overlay(dev
);
15053 mutex_lock(&dev
->struct_mutex
);
15054 intel_cleanup_gt_powersave(dev
);
15055 mutex_unlock(&dev
->struct_mutex
);
15059 * Return which encoder is currently attached for connector.
15061 struct drm_encoder
*intel_best_encoder(struct drm_connector
*connector
)
15063 return &intel_attached_encoder(connector
)->base
;
15066 void intel_connector_attach_encoder(struct intel_connector
*connector
,
15067 struct intel_encoder
*encoder
)
15069 connector
->encoder
= encoder
;
15070 drm_mode_connector_attach_encoder(&connector
->base
,
15075 * set vga decode state - true == enable VGA decode
15077 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
15079 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15080 unsigned reg
= INTEL_INFO(dev
)->gen
>= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
15083 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
15084 DRM_ERROR("failed to read control word\n");
15088 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
15092 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
15094 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
15096 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
15097 DRM_ERROR("failed to write control word\n");
15104 struct intel_display_error_state
{
15106 u32 power_well_driver
;
15108 int num_transcoders
;
15110 struct intel_cursor_error_state
{
15115 } cursor
[I915_MAX_PIPES
];
15117 struct intel_pipe_error_state
{
15118 bool power_domain_on
;
15121 } pipe
[I915_MAX_PIPES
];
15123 struct intel_plane_error_state
{
15131 } plane
[I915_MAX_PIPES
];
15133 struct intel_transcoder_error_state
{
15134 bool power_domain_on
;
15135 enum transcoder cpu_transcoder
;
15148 struct intel_display_error_state
*
15149 intel_display_capture_error_state(struct drm_device
*dev
)
15151 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15152 struct intel_display_error_state
*error
;
15153 int transcoders
[] = {
15161 if (INTEL_INFO(dev
)->num_pipes
== 0)
15164 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
15168 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
15169 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
15171 for_each_pipe(dev_priv
, i
) {
15172 error
->pipe
[i
].power_domain_on
=
15173 __intel_display_power_is_enabled(dev_priv
,
15174 POWER_DOMAIN_PIPE(i
));
15175 if (!error
->pipe
[i
].power_domain_on
)
15178 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
15179 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
15180 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
15182 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
15183 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
15184 if (INTEL_INFO(dev
)->gen
<= 3) {
15185 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
15186 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
15188 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
15189 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
15190 if (INTEL_INFO(dev
)->gen
>= 4) {
15191 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
15192 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
15195 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
15197 if (HAS_GMCH_DISPLAY(dev
))
15198 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
15201 error
->num_transcoders
= INTEL_INFO(dev
)->num_pipes
;
15202 if (HAS_DDI(dev_priv
->dev
))
15203 error
->num_transcoders
++; /* Account for eDP. */
15205 for (i
= 0; i
< error
->num_transcoders
; i
++) {
15206 enum transcoder cpu_transcoder
= transcoders
[i
];
15208 error
->transcoder
[i
].power_domain_on
=
15209 __intel_display_power_is_enabled(dev_priv
,
15210 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
15211 if (!error
->transcoder
[i
].power_domain_on
)
15214 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
15216 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
15217 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
15218 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
15219 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
15220 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
15221 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
15222 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
15228 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
15231 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
15232 struct drm_device
*dev
,
15233 struct intel_display_error_state
*error
)
15235 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
15241 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev
)->num_pipes
);
15242 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
15243 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
15244 error
->power_well_driver
);
15245 for_each_pipe(dev_priv
, i
) {
15246 err_printf(m
, "Pipe [%d]:\n", i
);
15247 err_printf(m
, " Power: %s\n",
15248 error
->pipe
[i
].power_domain_on
? "on" : "off");
15249 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
15250 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
15252 err_printf(m
, "Plane [%d]:\n", i
);
15253 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
15254 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
15255 if (INTEL_INFO(dev
)->gen
<= 3) {
15256 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
15257 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
15259 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
15260 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
15261 if (INTEL_INFO(dev
)->gen
>= 4) {
15262 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
15263 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
15266 err_printf(m
, "Cursor [%d]:\n", i
);
15267 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
15268 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
15269 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
15272 for (i
= 0; i
< error
->num_transcoders
; i
++) {
15273 err_printf(m
, "CPU transcoder: %c\n",
15274 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
15275 err_printf(m
, " Power: %s\n",
15276 error
->transcoder
[i
].power_domain_on
? "on" : "off");
15277 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
15278 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
15279 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
15280 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
15281 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
15282 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
15283 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);
15287 void intel_modeset_preclose(struct drm_device
*dev
, struct drm_file
*file
)
15289 struct intel_crtc
*crtc
;
15291 for_each_intel_crtc(dev
, crtc
) {
15292 struct intel_unpin_work
*work
;
15294 spin_lock_irq(&dev
->event_lock
);
15296 work
= crtc
->unpin_work
;
15298 if (work
&& work
->event
&&
15299 work
->event
->base
.file_priv
== file
) {
15300 kfree(work
->event
);
15301 work
->event
= NULL
;
15304 spin_unlock_irq(&dev
->event_lock
);