2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
27 #include <linux/dmi.h>
28 #include <linux/module.h>
29 #include <linux/input.h>
30 #include <linux/i2c.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/vgaarb.h>
34 #include <drm/drm_edid.h>
36 #include "intel_drv.h"
37 #include <drm/i915_drm.h>
39 #include "i915_trace.h"
40 #include <drm/drm_atomic.h>
41 #include <drm/drm_atomic_helper.h>
42 #include <drm/drm_dp_helper.h>
43 #include <drm/drm_crtc_helper.h>
44 #include <drm/drm_plane_helper.h>
45 #include <drm/drm_rect.h>
46 #include <linux/dma_remapping.h>
48 /* Primary plane formats for gen <= 3 */
49 static const uint32_t i8xx_primary_formats[] = {
56 /* Primary plane formats for gen >= 4 */
57 static const uint32_t i965_primary_formats[] = {
62 DRM_FORMAT_XRGB2101010,
63 DRM_FORMAT_XBGR2101010,
66 static const uint32_t skl_primary_formats[] = {
73 DRM_FORMAT_XRGB2101010,
74 DRM_FORMAT_XBGR2101010,
78 static const uint32_t intel_cursor_formats[] = {
82 static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
84 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
85 struct intel_crtc_state *pipe_config);
86 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
87 struct intel_crtc_state *pipe_config);
89 static int intel_framebuffer_init(struct drm_device *dev,
90 struct intel_framebuffer *ifb,
91 struct drm_mode_fb_cmd2 *mode_cmd,
92 struct drm_i915_gem_object *obj);
93 static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc);
94 static void intel_set_pipe_timings(struct intel_crtc *intel_crtc);
95 static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
96 struct intel_link_m_n *m_n,
97 struct intel_link_m_n *m2_n2);
98 static void ironlake_set_pipeconf(struct drm_crtc *crtc);
99 static void haswell_set_pipeconf(struct drm_crtc *crtc);
100 static void intel_set_pipe_csc(struct drm_crtc *crtc);
101 static void vlv_prepare_pll(struct intel_crtc *crtc,
102 const struct intel_crtc_state *pipe_config);
103 static void chv_prepare_pll(struct intel_crtc *crtc,
104 const struct intel_crtc_state *pipe_config);
105 static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
106 static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
107 static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc,
108 struct intel_crtc_state *crtc_state);
109 static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state,
111 static void intel_modeset_setup_hw_state(struct drm_device *dev);
119 int p2_slow, p2_fast;
122 typedef struct intel_limit intel_limit_t;
124 intel_range_t dot, vco, n, m, m1, m2, p, p1;
129 intel_pch_rawclk(struct drm_device *dev)
131 struct drm_i915_private *dev_priv = dev->dev_private;
133 WARN_ON(!HAS_PCH_SPLIT(dev));
135 return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
138 /* hrawclock is 1/4 the FSB frequency */
139 int intel_hrawclk(struct drm_device *dev)
141 struct drm_i915_private *dev_priv = dev->dev_private;
144 /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */
145 if (IS_VALLEYVIEW(dev))
148 clkcfg = I915_READ(CLKCFG);
149 switch (clkcfg & CLKCFG_FSB_MASK) {
158 case CLKCFG_FSB_1067:
160 case CLKCFG_FSB_1333:
162 /* these two are just a guess; one of them might be right */
163 case CLKCFG_FSB_1600:
164 case CLKCFG_FSB_1600_ALT:
171 static inline u32 /* units of 100MHz */
172 intel_fdi_link_freq(struct drm_device *dev)
175 struct drm_i915_private *dev_priv = dev->dev_private;
176 return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
181 static const intel_limit_t intel_limits_i8xx_dac = {
182 .dot = { .min = 25000, .max = 350000 },
183 .vco = { .min = 908000, .max = 1512000 },
184 .n = { .min = 2, .max = 16 },
185 .m = { .min = 96, .max = 140 },
186 .m1 = { .min = 18, .max = 26 },
187 .m2 = { .min = 6, .max = 16 },
188 .p = { .min = 4, .max = 128 },
189 .p1 = { .min = 2, .max = 33 },
190 .p2 = { .dot_limit = 165000,
191 .p2_slow = 4, .p2_fast = 2 },
194 static const intel_limit_t intel_limits_i8xx_dvo = {
195 .dot = { .min = 25000, .max = 350000 },
196 .vco = { .min = 908000, .max = 1512000 },
197 .n = { .min = 2, .max = 16 },
198 .m = { .min = 96, .max = 140 },
199 .m1 = { .min = 18, .max = 26 },
200 .m2 = { .min = 6, .max = 16 },
201 .p = { .min = 4, .max = 128 },
202 .p1 = { .min = 2, .max = 33 },
203 .p2 = { .dot_limit = 165000,
204 .p2_slow = 4, .p2_fast = 4 },
207 static const intel_limit_t intel_limits_i8xx_lvds = {
208 .dot = { .min = 25000, .max = 350000 },
209 .vco = { .min = 908000, .max = 1512000 },
210 .n = { .min = 2, .max = 16 },
211 .m = { .min = 96, .max = 140 },
212 .m1 = { .min = 18, .max = 26 },
213 .m2 = { .min = 6, .max = 16 },
214 .p = { .min = 4, .max = 128 },
215 .p1 = { .min = 1, .max = 6 },
216 .p2 = { .dot_limit = 165000,
217 .p2_slow = 14, .p2_fast = 7 },
220 static const intel_limit_t intel_limits_i9xx_sdvo = {
221 .dot = { .min = 20000, .max = 400000 },
222 .vco = { .min = 1400000, .max = 2800000 },
223 .n = { .min = 1, .max = 6 },
224 .m = { .min = 70, .max = 120 },
225 .m1 = { .min = 8, .max = 18 },
226 .m2 = { .min = 3, .max = 7 },
227 .p = { .min = 5, .max = 80 },
228 .p1 = { .min = 1, .max = 8 },
229 .p2 = { .dot_limit = 200000,
230 .p2_slow = 10, .p2_fast = 5 },
233 static const intel_limit_t intel_limits_i9xx_lvds = {
234 .dot = { .min = 20000, .max = 400000 },
235 .vco = { .min = 1400000, .max = 2800000 },
236 .n = { .min = 1, .max = 6 },
237 .m = { .min = 70, .max = 120 },
238 .m1 = { .min = 8, .max = 18 },
239 .m2 = { .min = 3, .max = 7 },
240 .p = { .min = 7, .max = 98 },
241 .p1 = { .min = 1, .max = 8 },
242 .p2 = { .dot_limit = 112000,
243 .p2_slow = 14, .p2_fast = 7 },
247 static const intel_limit_t intel_limits_g4x_sdvo = {
248 .dot = { .min = 25000, .max = 270000 },
249 .vco = { .min = 1750000, .max = 3500000},
250 .n = { .min = 1, .max = 4 },
251 .m = { .min = 104, .max = 138 },
252 .m1 = { .min = 17, .max = 23 },
253 .m2 = { .min = 5, .max = 11 },
254 .p = { .min = 10, .max = 30 },
255 .p1 = { .min = 1, .max = 3},
256 .p2 = { .dot_limit = 270000,
262 static const intel_limit_t intel_limits_g4x_hdmi = {
263 .dot = { .min = 22000, .max = 400000 },
264 .vco = { .min = 1750000, .max = 3500000},
265 .n = { .min = 1, .max = 4 },
266 .m = { .min = 104, .max = 138 },
267 .m1 = { .min = 16, .max = 23 },
268 .m2 = { .min = 5, .max = 11 },
269 .p = { .min = 5, .max = 80 },
270 .p1 = { .min = 1, .max = 8},
271 .p2 = { .dot_limit = 165000,
272 .p2_slow = 10, .p2_fast = 5 },
275 static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
276 .dot = { .min = 20000, .max = 115000 },
277 .vco = { .min = 1750000, .max = 3500000 },
278 .n = { .min = 1, .max = 3 },
279 .m = { .min = 104, .max = 138 },
280 .m1 = { .min = 17, .max = 23 },
281 .m2 = { .min = 5, .max = 11 },
282 .p = { .min = 28, .max = 112 },
283 .p1 = { .min = 2, .max = 8 },
284 .p2 = { .dot_limit = 0,
285 .p2_slow = 14, .p2_fast = 14
289 static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
290 .dot = { .min = 80000, .max = 224000 },
291 .vco = { .min = 1750000, .max = 3500000 },
292 .n = { .min = 1, .max = 3 },
293 .m = { .min = 104, .max = 138 },
294 .m1 = { .min = 17, .max = 23 },
295 .m2 = { .min = 5, .max = 11 },
296 .p = { .min = 14, .max = 42 },
297 .p1 = { .min = 2, .max = 6 },
298 .p2 = { .dot_limit = 0,
299 .p2_slow = 7, .p2_fast = 7
303 static const intel_limit_t intel_limits_pineview_sdvo = {
304 .dot = { .min = 20000, .max = 400000},
305 .vco = { .min = 1700000, .max = 3500000 },
306 /* Pineview's Ncounter is a ring counter */
307 .n = { .min = 3, .max = 6 },
308 .m = { .min = 2, .max = 256 },
309 /* Pineview only has one combined m divider, which we treat as m2. */
310 .m1 = { .min = 0, .max = 0 },
311 .m2 = { .min = 0, .max = 254 },
312 .p = { .min = 5, .max = 80 },
313 .p1 = { .min = 1, .max = 8 },
314 .p2 = { .dot_limit = 200000,
315 .p2_slow = 10, .p2_fast = 5 },
318 static const intel_limit_t intel_limits_pineview_lvds = {
319 .dot = { .min = 20000, .max = 400000 },
320 .vco = { .min = 1700000, .max = 3500000 },
321 .n = { .min = 3, .max = 6 },
322 .m = { .min = 2, .max = 256 },
323 .m1 = { .min = 0, .max = 0 },
324 .m2 = { .min = 0, .max = 254 },
325 .p = { .min = 7, .max = 112 },
326 .p1 = { .min = 1, .max = 8 },
327 .p2 = { .dot_limit = 112000,
328 .p2_slow = 14, .p2_fast = 14 },
331 /* Ironlake / Sandybridge
333 * We calculate clock using (register_value + 2) for N/M1/M2, so here
334 * the range value for them is (actual_value - 2).
336 static const intel_limit_t intel_limits_ironlake_dac = {
337 .dot = { .min = 25000, .max = 350000 },
338 .vco = { .min = 1760000, .max = 3510000 },
339 .n = { .min = 1, .max = 5 },
340 .m = { .min = 79, .max = 127 },
341 .m1 = { .min = 12, .max = 22 },
342 .m2 = { .min = 5, .max = 9 },
343 .p = { .min = 5, .max = 80 },
344 .p1 = { .min = 1, .max = 8 },
345 .p2 = { .dot_limit = 225000,
346 .p2_slow = 10, .p2_fast = 5 },
349 static const intel_limit_t intel_limits_ironlake_single_lvds = {
350 .dot = { .min = 25000, .max = 350000 },
351 .vco = { .min = 1760000, .max = 3510000 },
352 .n = { .min = 1, .max = 3 },
353 .m = { .min = 79, .max = 118 },
354 .m1 = { .min = 12, .max = 22 },
355 .m2 = { .min = 5, .max = 9 },
356 .p = { .min = 28, .max = 112 },
357 .p1 = { .min = 2, .max = 8 },
358 .p2 = { .dot_limit = 225000,
359 .p2_slow = 14, .p2_fast = 14 },
362 static const intel_limit_t intel_limits_ironlake_dual_lvds = {
363 .dot = { .min = 25000, .max = 350000 },
364 .vco = { .min = 1760000, .max = 3510000 },
365 .n = { .min = 1, .max = 3 },
366 .m = { .min = 79, .max = 127 },
367 .m1 = { .min = 12, .max = 22 },
368 .m2 = { .min = 5, .max = 9 },
369 .p = { .min = 14, .max = 56 },
370 .p1 = { .min = 2, .max = 8 },
371 .p2 = { .dot_limit = 225000,
372 .p2_slow = 7, .p2_fast = 7 },
375 /* LVDS 100mhz refclk limits. */
376 static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
377 .dot = { .min = 25000, .max = 350000 },
378 .vco = { .min = 1760000, .max = 3510000 },
379 .n = { .min = 1, .max = 2 },
380 .m = { .min = 79, .max = 126 },
381 .m1 = { .min = 12, .max = 22 },
382 .m2 = { .min = 5, .max = 9 },
383 .p = { .min = 28, .max = 112 },
384 .p1 = { .min = 2, .max = 8 },
385 .p2 = { .dot_limit = 225000,
386 .p2_slow = 14, .p2_fast = 14 },
389 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
390 .dot = { .min = 25000, .max = 350000 },
391 .vco = { .min = 1760000, .max = 3510000 },
392 .n = { .min = 1, .max = 3 },
393 .m = { .min = 79, .max = 126 },
394 .m1 = { .min = 12, .max = 22 },
395 .m2 = { .min = 5, .max = 9 },
396 .p = { .min = 14, .max = 42 },
397 .p1 = { .min = 2, .max = 6 },
398 .p2 = { .dot_limit = 225000,
399 .p2_slow = 7, .p2_fast = 7 },
402 static const intel_limit_t intel_limits_vlv = {
404 * These are the data rate limits (measured in fast clocks)
405 * since those are the strictest limits we have. The fast
406 * clock and actual rate limits are more relaxed, so checking
407 * them would make no difference.
409 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
410 .vco = { .min = 4000000, .max = 6000000 },
411 .n = { .min = 1, .max = 7 },
412 .m1 = { .min = 2, .max = 3 },
413 .m2 = { .min = 11, .max = 156 },
414 .p1 = { .min = 2, .max = 3 },
415 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
418 static const intel_limit_t intel_limits_chv = {
420 * These are the data rate limits (measured in fast clocks)
421 * since those are the strictest limits we have. The fast
422 * clock and actual rate limits are more relaxed, so checking
423 * them would make no difference.
425 .dot = { .min = 25000 * 5, .max = 540000 * 5},
426 .vco = { .min = 4800000, .max = 6480000 },
427 .n = { .min = 1, .max = 1 },
428 .m1 = { .min = 2, .max = 2 },
429 .m2 = { .min = 24 << 22, .max = 175 << 22 },
430 .p1 = { .min = 2, .max = 4 },
431 .p2 = { .p2_slow = 1, .p2_fast = 14 },
434 static const intel_limit_t intel_limits_bxt = {
435 /* FIXME: find real dot limits */
436 .dot = { .min = 0, .max = INT_MAX },
437 .vco = { .min = 4800000, .max = 6700000 },
438 .n = { .min = 1, .max = 1 },
439 .m1 = { .min = 2, .max = 2 },
440 /* FIXME: find real m2 limits */
441 .m2 = { .min = 2 << 22, .max = 255 << 22 },
442 .p1 = { .min = 2, .max = 4 },
443 .p2 = { .p2_slow = 1, .p2_fast = 20 },
447 needs_modeset(struct drm_crtc_state *state)
449 return drm_atomic_crtc_needs_modeset(state);
453 * Returns whether any output on the specified pipe is of the specified type
455 bool intel_pipe_has_type(struct intel_crtc *crtc, enum intel_output_type type)
457 struct drm_device *dev = crtc->base.dev;
458 struct intel_encoder *encoder;
460 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
461 if (encoder->type == type)
468 * Returns whether any output on the specified pipe will have the specified
469 * type after a staged modeset is complete, i.e., the same as
470 * intel_pipe_has_type() but looking at encoder->new_crtc instead of
473 static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state,
476 struct drm_atomic_state *state = crtc_state->base.state;
477 struct drm_connector *connector;
478 struct drm_connector_state *connector_state;
479 struct intel_encoder *encoder;
480 int i, num_connectors = 0;
482 for_each_connector_in_state(state, connector, connector_state, i) {
483 if (connector_state->crtc != crtc_state->base.crtc)
488 encoder = to_intel_encoder(connector_state->best_encoder);
489 if (encoder->type == type)
493 WARN_ON(num_connectors == 0);
498 static const intel_limit_t *
499 intel_ironlake_limit(struct intel_crtc_state *crtc_state, int refclk)
501 struct drm_device *dev = crtc_state->base.crtc->dev;
502 const intel_limit_t *limit;
504 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) {
505 if (intel_is_dual_link_lvds(dev)) {
506 if (refclk == 100000)
507 limit = &intel_limits_ironlake_dual_lvds_100m;
509 limit = &intel_limits_ironlake_dual_lvds;
511 if (refclk == 100000)
512 limit = &intel_limits_ironlake_single_lvds_100m;
514 limit = &intel_limits_ironlake_single_lvds;
517 limit = &intel_limits_ironlake_dac;
522 static const intel_limit_t *
523 intel_g4x_limit(struct intel_crtc_state *crtc_state)
525 struct drm_device *dev = crtc_state->base.crtc->dev;
526 const intel_limit_t *limit;
528 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) {
529 if (intel_is_dual_link_lvds(dev))
530 limit = &intel_limits_g4x_dual_channel_lvds;
532 limit = &intel_limits_g4x_single_channel_lvds;
533 } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) ||
534 intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
535 limit = &intel_limits_g4x_hdmi;
536 } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) {
537 limit = &intel_limits_g4x_sdvo;
538 } else /* The option is for other outputs */
539 limit = &intel_limits_i9xx_sdvo;
544 static const intel_limit_t *
545 intel_limit(struct intel_crtc_state *crtc_state, int refclk)
547 struct drm_device *dev = crtc_state->base.crtc->dev;
548 const intel_limit_t *limit;
551 limit = &intel_limits_bxt;
552 else if (HAS_PCH_SPLIT(dev))
553 limit = intel_ironlake_limit(crtc_state, refclk);
554 else if (IS_G4X(dev)) {
555 limit = intel_g4x_limit(crtc_state);
556 } else if (IS_PINEVIEW(dev)) {
557 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS))
558 limit = &intel_limits_pineview_lvds;
560 limit = &intel_limits_pineview_sdvo;
561 } else if (IS_CHERRYVIEW(dev)) {
562 limit = &intel_limits_chv;
563 } else if (IS_VALLEYVIEW(dev)) {
564 limit = &intel_limits_vlv;
565 } else if (!IS_GEN2(dev)) {
566 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS))
567 limit = &intel_limits_i9xx_lvds;
569 limit = &intel_limits_i9xx_sdvo;
571 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS))
572 limit = &intel_limits_i8xx_lvds;
573 else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO))
574 limit = &intel_limits_i8xx_dvo;
576 limit = &intel_limits_i8xx_dac;
582 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
583 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
584 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
585 * The helpers' return value is the rate of the clock that is fed to the
586 * display engine's pipe which can be the above fast dot clock rate or a
587 * divided-down version of it.
589 /* m1 is reserved as 0 in Pineview, n is a ring counter */
590 static int pnv_calc_dpll_params(int refclk, intel_clock_t *clock)
592 clock->m = clock->m2 + 2;
593 clock->p = clock->p1 * clock->p2;
594 if (WARN_ON(clock->n == 0 || clock->p == 0))
596 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
597 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
602 static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
604 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
607 static int i9xx_calc_dpll_params(int refclk, intel_clock_t *clock)
609 clock->m = i9xx_dpll_compute_m(clock);
610 clock->p = clock->p1 * clock->p2;
611 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
613 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
614 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
619 static int vlv_calc_dpll_params(int refclk, intel_clock_t *clock)
621 clock->m = clock->m1 * clock->m2;
622 clock->p = clock->p1 * clock->p2;
623 if (WARN_ON(clock->n == 0 || clock->p == 0))
625 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
626 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
628 return clock->dot / 5;
631 int chv_calc_dpll_params(int refclk, intel_clock_t *clock)
633 clock->m = clock->m1 * clock->m2;
634 clock->p = clock->p1 * clock->p2;
635 if (WARN_ON(clock->n == 0 || clock->p == 0))
637 clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
639 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
641 return clock->dot / 5;
644 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
646 * Returns whether the given set of divisors are valid for a given refclk with
647 * the given connectors.
650 static bool intel_PLL_is_valid(struct drm_device *dev,
651 const intel_limit_t *limit,
652 const intel_clock_t *clock)
654 if (clock->n < limit->n.min || limit->n.max < clock->n)
655 INTELPllInvalid("n out of range\n");
656 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
657 INTELPllInvalid("p1 out of range\n");
658 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
659 INTELPllInvalid("m2 out of range\n");
660 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
661 INTELPllInvalid("m1 out of range\n");
663 if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev) && !IS_BROXTON(dev))
664 if (clock->m1 <= clock->m2)
665 INTELPllInvalid("m1 <= m2\n");
667 if (!IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) {
668 if (clock->p < limit->p.min || limit->p.max < clock->p)
669 INTELPllInvalid("p out of range\n");
670 if (clock->m < limit->m.min || limit->m.max < clock->m)
671 INTELPllInvalid("m out of range\n");
674 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
675 INTELPllInvalid("vco out of range\n");
676 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
677 * connector, etc., rather than just a single range.
679 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
680 INTELPllInvalid("dot out of range\n");
686 i9xx_select_p2_div(const intel_limit_t *limit,
687 const struct intel_crtc_state *crtc_state,
690 struct drm_device *dev = crtc_state->base.crtc->dev;
692 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) {
694 * For LVDS just rely on its current settings for dual-channel.
695 * We haven't figured out how to reliably set up different
696 * single/dual channel state, if we even can.
698 if (intel_is_dual_link_lvds(dev))
699 return limit->p2.p2_fast;
701 return limit->p2.p2_slow;
703 if (target < limit->p2.dot_limit)
704 return limit->p2.p2_slow;
706 return limit->p2.p2_fast;
711 i9xx_find_best_dpll(const intel_limit_t *limit,
712 struct intel_crtc_state *crtc_state,
713 int target, int refclk, intel_clock_t *match_clock,
714 intel_clock_t *best_clock)
716 struct drm_device *dev = crtc_state->base.crtc->dev;
720 memset(best_clock, 0, sizeof(*best_clock));
722 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
724 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
726 for (clock.m2 = limit->m2.min;
727 clock.m2 <= limit->m2.max; clock.m2++) {
728 if (clock.m2 >= clock.m1)
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 i9xx_calc_dpll_params(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 pnv_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 drm_device *dev = crtc_state->base.crtc->dev;
767 memset(best_clock, 0, sizeof(*best_clock));
769 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
771 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
773 for (clock.m2 = limit->m2.min;
774 clock.m2 <= limit->m2.max; clock.m2++) {
775 for (clock.n = limit->n.min;
776 clock.n <= limit->n.max; clock.n++) {
777 for (clock.p1 = limit->p1.min;
778 clock.p1 <= limit->p1.max; clock.p1++) {
781 pnv_calc_dpll_params(refclk, &clock);
782 if (!intel_PLL_is_valid(dev, limit,
786 clock.p != match_clock->p)
789 this_err = abs(clock.dot - target);
790 if (this_err < err) {
799 return (err != target);
803 g4x_find_best_dpll(const intel_limit_t *limit,
804 struct intel_crtc_state *crtc_state,
805 int target, int refclk, intel_clock_t *match_clock,
806 intel_clock_t *best_clock)
808 struct drm_device *dev = crtc_state->base.crtc->dev;
812 /* approximately equals target * 0.00585 */
813 int err_most = (target >> 8) + (target >> 9);
815 memset(best_clock, 0, sizeof(*best_clock));
817 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
819 max_n = limit->n.max;
820 /* based on hardware requirement, prefer smaller n to precision */
821 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
822 /* based on hardware requirement, prefere larger m1,m2 */
823 for (clock.m1 = limit->m1.max;
824 clock.m1 >= limit->m1.min; clock.m1--) {
825 for (clock.m2 = limit->m2.max;
826 clock.m2 >= limit->m2.min; clock.m2--) {
827 for (clock.p1 = limit->p1.max;
828 clock.p1 >= limit->p1.min; clock.p1--) {
831 i9xx_calc_dpll_params(refclk, &clock);
832 if (!intel_PLL_is_valid(dev, limit,
836 this_err = abs(clock.dot - target);
837 if (this_err < err_most) {
851 * Check if the calculated PLL configuration is more optimal compared to the
852 * best configuration and error found so far. Return the calculated error.
854 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
855 const intel_clock_t *calculated_clock,
856 const intel_clock_t *best_clock,
857 unsigned int best_error_ppm,
858 unsigned int *error_ppm)
861 * For CHV ignore the error and consider only the P value.
862 * Prefer a bigger P value based on HW requirements.
864 if (IS_CHERRYVIEW(dev)) {
867 return calculated_clock->p > best_clock->p;
870 if (WARN_ON_ONCE(!target_freq))
873 *error_ppm = div_u64(1000000ULL *
874 abs(target_freq - calculated_clock->dot),
877 * Prefer a better P value over a better (smaller) error if the error
878 * is small. Ensure this preference for future configurations too by
879 * setting the error to 0.
881 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
887 return *error_ppm + 10 < best_error_ppm;
891 vlv_find_best_dpll(const intel_limit_t *limit,
892 struct intel_crtc_state *crtc_state,
893 int target, int refclk, intel_clock_t *match_clock,
894 intel_clock_t *best_clock)
896 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
897 struct drm_device *dev = crtc->base.dev;
899 unsigned int bestppm = 1000000;
900 /* min update 19.2 MHz */
901 int max_n = min(limit->n.max, refclk / 19200);
904 target *= 5; /* fast clock */
906 memset(best_clock, 0, sizeof(*best_clock));
908 /* based on hardware requirement, prefer smaller n to precision */
909 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
910 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
911 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
912 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
913 clock.p = clock.p1 * clock.p2;
914 /* based on hardware requirement, prefer bigger m1,m2 values */
915 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
918 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
921 vlv_calc_dpll_params(refclk, &clock);
923 if (!intel_PLL_is_valid(dev, limit,
927 if (!vlv_PLL_is_optimal(dev, target,
945 chv_find_best_dpll(const intel_limit_t *limit,
946 struct intel_crtc_state *crtc_state,
947 int target, int refclk, intel_clock_t *match_clock,
948 intel_clock_t *best_clock)
950 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
951 struct drm_device *dev = crtc->base.dev;
952 unsigned int best_error_ppm;
957 memset(best_clock, 0, sizeof(*best_clock));
958 best_error_ppm = 1000000;
961 * Based on hardware doc, the n always set to 1, and m1 always
962 * set to 2. If requires to support 200Mhz refclk, we need to
963 * revisit this because n may not 1 anymore.
965 clock.n = 1, clock.m1 = 2;
966 target *= 5; /* fast clock */
968 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
969 for (clock.p2 = limit->p2.p2_fast;
970 clock.p2 >= limit->p2.p2_slow;
971 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
972 unsigned int error_ppm;
974 clock.p = clock.p1 * clock.p2;
976 m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
977 clock.n) << 22, refclk * clock.m1);
979 if (m2 > INT_MAX/clock.m1)
984 chv_calc_dpll_params(refclk, &clock);
986 if (!intel_PLL_is_valid(dev, limit, &clock))
989 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
990 best_error_ppm, &error_ppm))
994 best_error_ppm = error_ppm;
1002 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock,
1003 intel_clock_t *best_clock)
1005 int refclk = i9xx_get_refclk(crtc_state, 0);
1007 return chv_find_best_dpll(intel_limit(crtc_state, refclk), crtc_state,
1008 target_clock, refclk, NULL, best_clock);
1011 bool intel_crtc_active(struct drm_crtc *crtc)
1013 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1015 /* Be paranoid as we can arrive here with only partial
1016 * state retrieved from the hardware during setup.
1018 * We can ditch the adjusted_mode.crtc_clock check as soon
1019 * as Haswell has gained clock readout/fastboot support.
1021 * We can ditch the crtc->primary->fb check as soon as we can
1022 * properly reconstruct framebuffers.
1024 * FIXME: The intel_crtc->active here should be switched to
1025 * crtc->state->active once we have proper CRTC states wired up
1028 return intel_crtc->active && crtc->primary->state->fb &&
1029 intel_crtc->config->base.adjusted_mode.crtc_clock;
1032 enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
1035 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1036 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1038 return intel_crtc->config->cpu_transcoder;
1041 static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe)
1043 struct drm_i915_private *dev_priv = dev->dev_private;
1044 u32 reg = PIPEDSL(pipe);
1049 line_mask = DSL_LINEMASK_GEN2;
1051 line_mask = DSL_LINEMASK_GEN3;
1053 line1 = I915_READ(reg) & line_mask;
1055 line2 = I915_READ(reg) & line_mask;
1057 return line1 == line2;
1061 * intel_wait_for_pipe_off - wait for pipe to turn off
1062 * @crtc: crtc whose pipe to wait for
1064 * After disabling a pipe, we can't wait for vblank in the usual way,
1065 * spinning on the vblank interrupt status bit, since we won't actually
1066 * see an interrupt when the pipe is disabled.
1068 * On Gen4 and above:
1069 * wait for the pipe register state bit to turn off
1072 * wait for the display line value to settle (it usually
1073 * ends up stopping at the start of the next frame).
1076 static void intel_wait_for_pipe_off(struct intel_crtc *crtc)
1078 struct drm_device *dev = crtc->base.dev;
1079 struct drm_i915_private *dev_priv = dev->dev_private;
1080 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
1081 enum pipe pipe = crtc->pipe;
1083 if (INTEL_INFO(dev)->gen >= 4) {
1084 int reg = PIPECONF(cpu_transcoder);
1086 /* Wait for the Pipe State to go off */
1087 if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
1089 WARN(1, "pipe_off wait timed out\n");
1091 /* Wait for the display line to settle */
1092 if (wait_for(pipe_dsl_stopped(dev, pipe), 100))
1093 WARN(1, "pipe_off wait timed out\n");
1097 static const char *state_string(bool enabled)
1099 return enabled ? "on" : "off";
1102 /* Only for pre-ILK configs */
1103 void assert_pll(struct drm_i915_private *dev_priv,
1104 enum pipe pipe, bool state)
1111 val = I915_READ(reg);
1112 cur_state = !!(val & DPLL_VCO_ENABLE);
1113 I915_STATE_WARN(cur_state != state,
1114 "PLL state assertion failure (expected %s, current %s)\n",
1115 state_string(state), state_string(cur_state));
1118 /* XXX: the dsi pll is shared between MIPI DSI ports */
1119 static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1124 mutex_lock(&dev_priv->sb_lock);
1125 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1126 mutex_unlock(&dev_priv->sb_lock);
1128 cur_state = val & DSI_PLL_VCO_EN;
1129 I915_STATE_WARN(cur_state != state,
1130 "DSI PLL state assertion failure (expected %s, current %s)\n",
1131 state_string(state), state_string(cur_state));
1133 #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
1134 #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
1136 struct intel_shared_dpll *
1137 intel_crtc_to_shared_dpll(struct intel_crtc *crtc)
1139 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
1141 if (crtc->config->shared_dpll < 0)
1144 return &dev_priv->shared_dplls[crtc->config->shared_dpll];
1148 void assert_shared_dpll(struct drm_i915_private *dev_priv,
1149 struct intel_shared_dpll *pll,
1153 struct intel_dpll_hw_state hw_state;
1156 "asserting DPLL %s with no DPLL\n", state_string(state)))
1159 cur_state = pll->get_hw_state(dev_priv, pll, &hw_state);
1160 I915_STATE_WARN(cur_state != state,
1161 "%s assertion failure (expected %s, current %s)\n",
1162 pll->name, state_string(state), state_string(cur_state));
1165 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1166 enum pipe pipe, bool state)
1171 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1174 if (HAS_DDI(dev_priv->dev)) {
1175 /* DDI does not have a specific FDI_TX register */
1176 reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
1177 val = I915_READ(reg);
1178 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1180 reg = FDI_TX_CTL(pipe);
1181 val = I915_READ(reg);
1182 cur_state = !!(val & FDI_TX_ENABLE);
1184 I915_STATE_WARN(cur_state != state,
1185 "FDI TX state assertion failure (expected %s, current %s)\n",
1186 state_string(state), state_string(cur_state));
1188 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1189 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1191 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1192 enum pipe pipe, bool state)
1198 reg = FDI_RX_CTL(pipe);
1199 val = I915_READ(reg);
1200 cur_state = !!(val & FDI_RX_ENABLE);
1201 I915_STATE_WARN(cur_state != state,
1202 "FDI RX state assertion failure (expected %s, current %s)\n",
1203 state_string(state), state_string(cur_state));
1205 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1206 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1208 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1214 /* ILK FDI PLL is always enabled */
1215 if (INTEL_INFO(dev_priv->dev)->gen == 5)
1218 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1219 if (HAS_DDI(dev_priv->dev))
1222 reg = FDI_TX_CTL(pipe);
1223 val = I915_READ(reg);
1224 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1227 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1228 enum pipe pipe, bool state)
1234 reg = FDI_RX_CTL(pipe);
1235 val = I915_READ(reg);
1236 cur_state = !!(val & FDI_RX_PLL_ENABLE);
1237 I915_STATE_WARN(cur_state != state,
1238 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1239 state_string(state), state_string(cur_state));
1242 void assert_panel_unlocked(struct drm_i915_private *dev_priv,
1245 struct drm_device *dev = dev_priv->dev;
1248 enum pipe panel_pipe = PIPE_A;
1251 if (WARN_ON(HAS_DDI(dev)))
1254 if (HAS_PCH_SPLIT(dev)) {
1257 pp_reg = PCH_PP_CONTROL;
1258 port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK;
1260 if (port_sel == PANEL_PORT_SELECT_LVDS &&
1261 I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT)
1262 panel_pipe = PIPE_B;
1263 /* XXX: else fix for eDP */
1264 } else if (IS_VALLEYVIEW(dev)) {
1265 /* presumably write lock depends on pipe, not port select */
1266 pp_reg = VLV_PIPE_PP_CONTROL(pipe);
1269 pp_reg = PP_CONTROL;
1270 if (I915_READ(LVDS) & LVDS_PIPEB_SELECT)
1271 panel_pipe = PIPE_B;
1274 val = I915_READ(pp_reg);
1275 if (!(val & PANEL_POWER_ON) ||
1276 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1279 I915_STATE_WARN(panel_pipe == pipe && locked,
1280 "panel assertion failure, pipe %c regs locked\n",
1284 static void assert_cursor(struct drm_i915_private *dev_priv,
1285 enum pipe pipe, bool state)
1287 struct drm_device *dev = dev_priv->dev;
1290 if (IS_845G(dev) || IS_I865G(dev))
1291 cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
1293 cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
1295 I915_STATE_WARN(cur_state != state,
1296 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1297 pipe_name(pipe), state_string(state), state_string(cur_state));
1299 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1300 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1302 void assert_pipe(struct drm_i915_private *dev_priv,
1303 enum pipe pipe, bool state)
1308 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1311 /* if we need the pipe quirk it must be always on */
1312 if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
1313 (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
1316 if (!intel_display_power_is_enabled(dev_priv,
1317 POWER_DOMAIN_TRANSCODER(cpu_transcoder))) {
1320 reg = PIPECONF(cpu_transcoder);
1321 val = I915_READ(reg);
1322 cur_state = !!(val & PIPECONF_ENABLE);
1325 I915_STATE_WARN(cur_state != state,
1326 "pipe %c assertion failure (expected %s, current %s)\n",
1327 pipe_name(pipe), state_string(state), state_string(cur_state));
1330 static void assert_plane(struct drm_i915_private *dev_priv,
1331 enum plane plane, bool state)
1337 reg = DSPCNTR(plane);
1338 val = I915_READ(reg);
1339 cur_state = !!(val & DISPLAY_PLANE_ENABLE);
1340 I915_STATE_WARN(cur_state != state,
1341 "plane %c assertion failure (expected %s, current %s)\n",
1342 plane_name(plane), state_string(state), state_string(cur_state));
1345 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1346 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1348 static void assert_planes_disabled(struct drm_i915_private *dev_priv,
1351 struct drm_device *dev = dev_priv->dev;
1356 /* Primary planes are fixed to pipes on gen4+ */
1357 if (INTEL_INFO(dev)->gen >= 4) {
1358 reg = DSPCNTR(pipe);
1359 val = I915_READ(reg);
1360 I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE,
1361 "plane %c assertion failure, should be disabled but not\n",
1366 /* Need to check both planes against the pipe */
1367 for_each_pipe(dev_priv, i) {
1369 val = I915_READ(reg);
1370 cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
1371 DISPPLANE_SEL_PIPE_SHIFT;
1372 I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
1373 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1374 plane_name(i), pipe_name(pipe));
1378 static void assert_sprites_disabled(struct drm_i915_private *dev_priv,
1381 struct drm_device *dev = dev_priv->dev;
1385 if (INTEL_INFO(dev)->gen >= 9) {
1386 for_each_sprite(dev_priv, pipe, sprite) {
1387 val = I915_READ(PLANE_CTL(pipe, sprite));
1388 I915_STATE_WARN(val & PLANE_CTL_ENABLE,
1389 "plane %d assertion failure, should be off on pipe %c but is still active\n",
1390 sprite, pipe_name(pipe));
1392 } else if (IS_VALLEYVIEW(dev)) {
1393 for_each_sprite(dev_priv, pipe, sprite) {
1394 reg = SPCNTR(pipe, sprite);
1395 val = I915_READ(reg);
1396 I915_STATE_WARN(val & SP_ENABLE,
1397 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1398 sprite_name(pipe, sprite), pipe_name(pipe));
1400 } else if (INTEL_INFO(dev)->gen >= 7) {
1402 val = I915_READ(reg);
1403 I915_STATE_WARN(val & SPRITE_ENABLE,
1404 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1405 plane_name(pipe), pipe_name(pipe));
1406 } else if (INTEL_INFO(dev)->gen >= 5) {
1407 reg = DVSCNTR(pipe);
1408 val = I915_READ(reg);
1409 I915_STATE_WARN(val & DVS_ENABLE,
1410 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1411 plane_name(pipe), pipe_name(pipe));
1415 static void assert_vblank_disabled(struct drm_crtc *crtc)
1417 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1418 drm_crtc_vblank_put(crtc);
1421 static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
1426 I915_STATE_WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev)));
1428 val = I915_READ(PCH_DREF_CONTROL);
1429 enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
1430 DREF_SUPERSPREAD_SOURCE_MASK));
1431 I915_STATE_WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
1434 static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1441 reg = PCH_TRANSCONF(pipe);
1442 val = I915_READ(reg);
1443 enabled = !!(val & TRANS_ENABLE);
1444 I915_STATE_WARN(enabled,
1445 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1449 static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
1450 enum pipe pipe, u32 port_sel, u32 val)
1452 if ((val & DP_PORT_EN) == 0)
1455 if (HAS_PCH_CPT(dev_priv->dev)) {
1456 u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
1457 u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
1458 if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
1460 } else if (IS_CHERRYVIEW(dev_priv->dev)) {
1461 if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe))
1464 if ((val & DP_PIPE_MASK) != (pipe << 30))
1470 static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
1471 enum pipe pipe, u32 val)
1473 if ((val & SDVO_ENABLE) == 0)
1476 if (HAS_PCH_CPT(dev_priv->dev)) {
1477 if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
1479 } else if (IS_CHERRYVIEW(dev_priv->dev)) {
1480 if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe))
1483 if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
1489 static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
1490 enum pipe pipe, u32 val)
1492 if ((val & LVDS_PORT_EN) == 0)
1495 if (HAS_PCH_CPT(dev_priv->dev)) {
1496 if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1499 if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
1505 static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
1506 enum pipe pipe, u32 val)
1508 if ((val & ADPA_DAC_ENABLE) == 0)
1510 if (HAS_PCH_CPT(dev_priv->dev)) {
1511 if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1514 if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
1520 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1521 enum pipe pipe, int reg, u32 port_sel)
1523 u32 val = I915_READ(reg);
1524 I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
1525 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1526 reg, pipe_name(pipe));
1528 I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
1529 && (val & DP_PIPEB_SELECT),
1530 "IBX PCH dp port still using transcoder B\n");
1533 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1534 enum pipe pipe, int reg)
1536 u32 val = I915_READ(reg);
1537 I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
1538 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1539 reg, pipe_name(pipe));
1541 I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0
1542 && (val & SDVO_PIPE_B_SELECT),
1543 "IBX PCH hdmi port still using transcoder B\n");
1546 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1552 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
1553 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
1554 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
1557 val = I915_READ(reg);
1558 I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val),
1559 "PCH VGA enabled on transcoder %c, should be disabled\n",
1563 val = I915_READ(reg);
1564 I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val),
1565 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1568 assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
1569 assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
1570 assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
1573 static void vlv_enable_pll(struct intel_crtc *crtc,
1574 const struct intel_crtc_state *pipe_config)
1576 struct drm_device *dev = crtc->base.dev;
1577 struct drm_i915_private *dev_priv = dev->dev_private;
1578 int reg = DPLL(crtc->pipe);
1579 u32 dpll = pipe_config->dpll_hw_state.dpll;
1581 assert_pipe_disabled(dev_priv, crtc->pipe);
1583 /* No really, not for ILK+ */
1584 BUG_ON(!IS_VALLEYVIEW(dev_priv->dev));
1586 /* PLL is protected by panel, make sure we can write it */
1587 if (IS_MOBILE(dev_priv->dev))
1588 assert_panel_unlocked(dev_priv, crtc->pipe);
1590 I915_WRITE(reg, dpll);
1594 if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
1595 DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe);
1597 I915_WRITE(DPLL_MD(crtc->pipe), pipe_config->dpll_hw_state.dpll_md);
1598 POSTING_READ(DPLL_MD(crtc->pipe));
1600 /* We do this three times for luck */
1601 I915_WRITE(reg, dpll);
1603 udelay(150); /* wait for warmup */
1604 I915_WRITE(reg, dpll);
1606 udelay(150); /* wait for warmup */
1607 I915_WRITE(reg, dpll);
1609 udelay(150); /* wait for warmup */
1612 static void chv_enable_pll(struct intel_crtc *crtc,
1613 const struct intel_crtc_state *pipe_config)
1615 struct drm_device *dev = crtc->base.dev;
1616 struct drm_i915_private *dev_priv = dev->dev_private;
1617 int pipe = crtc->pipe;
1618 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1621 assert_pipe_disabled(dev_priv, crtc->pipe);
1623 BUG_ON(!IS_CHERRYVIEW(dev_priv->dev));
1625 mutex_lock(&dev_priv->sb_lock);
1627 /* Enable back the 10bit clock to display controller */
1628 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1629 tmp |= DPIO_DCLKP_EN;
1630 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1632 mutex_unlock(&dev_priv->sb_lock);
1635 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1640 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1642 /* Check PLL is locked */
1643 if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
1644 DRM_ERROR("PLL %d failed to lock\n", pipe);
1646 /* not sure when this should be written */
1647 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1648 POSTING_READ(DPLL_MD(pipe));
1651 static int intel_num_dvo_pipes(struct drm_device *dev)
1653 struct intel_crtc *crtc;
1656 for_each_intel_crtc(dev, crtc)
1657 count += crtc->base.state->active &&
1658 intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO);
1663 static void i9xx_enable_pll(struct intel_crtc *crtc)
1665 struct drm_device *dev = crtc->base.dev;
1666 struct drm_i915_private *dev_priv = dev->dev_private;
1667 int reg = DPLL(crtc->pipe);
1668 u32 dpll = crtc->config->dpll_hw_state.dpll;
1670 assert_pipe_disabled(dev_priv, crtc->pipe);
1672 /* No really, not for ILK+ */
1673 BUG_ON(INTEL_INFO(dev)->gen >= 5);
1675 /* PLL is protected by panel, make sure we can write it */
1676 if (IS_MOBILE(dev) && !IS_I830(dev))
1677 assert_panel_unlocked(dev_priv, crtc->pipe);
1679 /* Enable DVO 2x clock on both PLLs if necessary */
1680 if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) {
1682 * It appears to be important that we don't enable this
1683 * for the current pipe before otherwise configuring the
1684 * PLL. No idea how this should be handled if multiple
1685 * DVO outputs are enabled simultaneosly.
1687 dpll |= DPLL_DVO_2X_MODE;
1688 I915_WRITE(DPLL(!crtc->pipe),
1689 I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
1692 /* Wait for the clocks to stabilize. */
1696 if (INTEL_INFO(dev)->gen >= 4) {
1697 I915_WRITE(DPLL_MD(crtc->pipe),
1698 crtc->config->dpll_hw_state.dpll_md);
1700 /* The pixel multiplier can only be updated once the
1701 * DPLL is enabled and the clocks are stable.
1703 * So write it again.
1705 I915_WRITE(reg, dpll);
1708 /* We do this three times for luck */
1709 I915_WRITE(reg, dpll);
1711 udelay(150); /* wait for warmup */
1712 I915_WRITE(reg, dpll);
1714 udelay(150); /* wait for warmup */
1715 I915_WRITE(reg, dpll);
1717 udelay(150); /* wait for warmup */
1721 * i9xx_disable_pll - disable a PLL
1722 * @dev_priv: i915 private structure
1723 * @pipe: pipe PLL to disable
1725 * Disable the PLL for @pipe, making sure the pipe is off first.
1727 * Note! This is for pre-ILK only.
1729 static void i9xx_disable_pll(struct intel_crtc *crtc)
1731 struct drm_device *dev = crtc->base.dev;
1732 struct drm_i915_private *dev_priv = dev->dev_private;
1733 enum pipe pipe = crtc->pipe;
1735 /* Disable DVO 2x clock on both PLLs if necessary */
1737 intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) &&
1738 !intel_num_dvo_pipes(dev)) {
1739 I915_WRITE(DPLL(PIPE_B),
1740 I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
1741 I915_WRITE(DPLL(PIPE_A),
1742 I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
1745 /* Don't disable pipe or pipe PLLs if needed */
1746 if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
1747 (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
1750 /* Make sure the pipe isn't still relying on us */
1751 assert_pipe_disabled(dev_priv, pipe);
1753 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
1754 POSTING_READ(DPLL(pipe));
1757 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1761 /* Make sure the pipe isn't still relying on us */
1762 assert_pipe_disabled(dev_priv, pipe);
1765 * Leave integrated clock source and reference clock enabled for pipe B.
1766 * The latter is needed for VGA hotplug / manual detection.
1768 val = DPLL_VGA_MODE_DIS;
1770 val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REF_CLK_ENABLE_VLV;
1771 I915_WRITE(DPLL(pipe), val);
1772 POSTING_READ(DPLL(pipe));
1776 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1778 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1781 /* Make sure the pipe isn't still relying on us */
1782 assert_pipe_disabled(dev_priv, pipe);
1784 /* Set PLL en = 0 */
1785 val = DPLL_SSC_REF_CLK_CHV |
1786 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1788 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1789 I915_WRITE(DPLL(pipe), val);
1790 POSTING_READ(DPLL(pipe));
1792 mutex_lock(&dev_priv->sb_lock);
1794 /* Disable 10bit clock to display controller */
1795 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1796 val &= ~DPIO_DCLKP_EN;
1797 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1799 mutex_unlock(&dev_priv->sb_lock);
1802 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1803 struct intel_digital_port *dport,
1804 unsigned int expected_mask)
1809 switch (dport->port) {
1811 port_mask = DPLL_PORTB_READY_MASK;
1815 port_mask = DPLL_PORTC_READY_MASK;
1817 expected_mask <<= 4;
1820 port_mask = DPLL_PORTD_READY_MASK;
1821 dpll_reg = DPIO_PHY_STATUS;
1827 if (wait_for((I915_READ(dpll_reg) & port_mask) == expected_mask, 1000))
1828 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1829 port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask);
1832 static void intel_prepare_shared_dpll(struct intel_crtc *crtc)
1834 struct drm_device *dev = crtc->base.dev;
1835 struct drm_i915_private *dev_priv = dev->dev_private;
1836 struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
1838 if (WARN_ON(pll == NULL))
1841 WARN_ON(!pll->config.crtc_mask);
1842 if (pll->active == 0) {
1843 DRM_DEBUG_DRIVER("setting up %s\n", pll->name);
1845 assert_shared_dpll_disabled(dev_priv, pll);
1847 pll->mode_set(dev_priv, pll);
1852 * intel_enable_shared_dpll - enable PCH PLL
1853 * @dev_priv: i915 private structure
1854 * @pipe: pipe PLL to enable
1856 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1857 * drives the transcoder clock.
1859 static void intel_enable_shared_dpll(struct intel_crtc *crtc)
1861 struct drm_device *dev = crtc->base.dev;
1862 struct drm_i915_private *dev_priv = dev->dev_private;
1863 struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
1865 if (WARN_ON(pll == NULL))
1868 if (WARN_ON(pll->config.crtc_mask == 0))
1871 DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n",
1872 pll->name, pll->active, pll->on,
1873 crtc->base.base.id);
1875 if (pll->active++) {
1877 assert_shared_dpll_enabled(dev_priv, pll);
1882 intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
1884 DRM_DEBUG_KMS("enabling %s\n", pll->name);
1885 pll->enable(dev_priv, pll);
1889 static void intel_disable_shared_dpll(struct intel_crtc *crtc)
1891 struct drm_device *dev = crtc->base.dev;
1892 struct drm_i915_private *dev_priv = dev->dev_private;
1893 struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
1895 /* PCH only available on ILK+ */
1896 if (INTEL_INFO(dev)->gen < 5)
1902 if (WARN_ON(!(pll->config.crtc_mask & (1 << drm_crtc_index(&crtc->base)))))
1905 DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
1906 pll->name, pll->active, pll->on,
1907 crtc->base.base.id);
1909 if (WARN_ON(pll->active == 0)) {
1910 assert_shared_dpll_disabled(dev_priv, pll);
1914 assert_shared_dpll_enabled(dev_priv, pll);
1919 DRM_DEBUG_KMS("disabling %s\n", pll->name);
1920 pll->disable(dev_priv, pll);
1923 intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS);
1926 static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1929 struct drm_device *dev = dev_priv->dev;
1930 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1931 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1932 uint32_t reg, val, pipeconf_val;
1934 /* PCH only available on ILK+ */
1935 BUG_ON(!HAS_PCH_SPLIT(dev));
1937 /* Make sure PCH DPLL is enabled */
1938 assert_shared_dpll_enabled(dev_priv,
1939 intel_crtc_to_shared_dpll(intel_crtc));
1941 /* FDI must be feeding us bits for PCH ports */
1942 assert_fdi_tx_enabled(dev_priv, pipe);
1943 assert_fdi_rx_enabled(dev_priv, pipe);
1945 if (HAS_PCH_CPT(dev)) {
1946 /* Workaround: Set the timing override bit before enabling the
1947 * pch transcoder. */
1948 reg = TRANS_CHICKEN2(pipe);
1949 val = I915_READ(reg);
1950 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1951 I915_WRITE(reg, val);
1954 reg = PCH_TRANSCONF(pipe);
1955 val = I915_READ(reg);
1956 pipeconf_val = I915_READ(PIPECONF(pipe));
1958 if (HAS_PCH_IBX(dev_priv->dev)) {
1960 * Make the BPC in transcoder be consistent with
1961 * that in pipeconf reg. For HDMI we must use 8bpc
1962 * here for both 8bpc and 12bpc.
1964 val &= ~PIPECONF_BPC_MASK;
1965 if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_HDMI))
1966 val |= PIPECONF_8BPC;
1968 val |= pipeconf_val & PIPECONF_BPC_MASK;
1971 val &= ~TRANS_INTERLACE_MASK;
1972 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
1973 if (HAS_PCH_IBX(dev_priv->dev) &&
1974 intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO))
1975 val |= TRANS_LEGACY_INTERLACED_ILK;
1977 val |= TRANS_INTERLACED;
1979 val |= TRANS_PROGRESSIVE;
1981 I915_WRITE(reg, val | TRANS_ENABLE);
1982 if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
1983 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
1986 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1987 enum transcoder cpu_transcoder)
1989 u32 val, pipeconf_val;
1991 /* PCH only available on ILK+ */
1992 BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev));
1994 /* FDI must be feeding us bits for PCH ports */
1995 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1996 assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
1998 /* Workaround: set timing override bit. */
1999 val = I915_READ(_TRANSA_CHICKEN2);
2000 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
2001 I915_WRITE(_TRANSA_CHICKEN2, val);
2004 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
2006 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
2007 PIPECONF_INTERLACED_ILK)
2008 val |= TRANS_INTERLACED;
2010 val |= TRANS_PROGRESSIVE;
2012 I915_WRITE(LPT_TRANSCONF, val);
2013 if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100))
2014 DRM_ERROR("Failed to enable PCH transcoder\n");
2017 static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
2020 struct drm_device *dev = dev_priv->dev;
2023 /* FDI relies on the transcoder */
2024 assert_fdi_tx_disabled(dev_priv, pipe);
2025 assert_fdi_rx_disabled(dev_priv, pipe);
2027 /* Ports must be off as well */
2028 assert_pch_ports_disabled(dev_priv, pipe);
2030 reg = PCH_TRANSCONF(pipe);
2031 val = I915_READ(reg);
2032 val &= ~TRANS_ENABLE;
2033 I915_WRITE(reg, val);
2034 /* wait for PCH transcoder off, transcoder state */
2035 if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
2036 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
2038 if (!HAS_PCH_IBX(dev)) {
2039 /* Workaround: Clear the timing override chicken bit again. */
2040 reg = TRANS_CHICKEN2(pipe);
2041 val = I915_READ(reg);
2042 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
2043 I915_WRITE(reg, val);
2047 static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
2051 val = I915_READ(LPT_TRANSCONF);
2052 val &= ~TRANS_ENABLE;
2053 I915_WRITE(LPT_TRANSCONF, val);
2054 /* wait for PCH transcoder off, transcoder state */
2055 if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50))
2056 DRM_ERROR("Failed to disable PCH transcoder\n");
2058 /* Workaround: clear timing override bit. */
2059 val = I915_READ(_TRANSA_CHICKEN2);
2060 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
2061 I915_WRITE(_TRANSA_CHICKEN2, val);
2065 * intel_enable_pipe - enable a pipe, asserting requirements
2066 * @crtc: crtc responsible for the pipe
2068 * Enable @crtc's pipe, making sure that various hardware specific requirements
2069 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
2071 static void intel_enable_pipe(struct intel_crtc *crtc)
2073 struct drm_device *dev = crtc->base.dev;
2074 struct drm_i915_private *dev_priv = dev->dev_private;
2075 enum pipe pipe = crtc->pipe;
2076 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
2078 enum pipe pch_transcoder;
2082 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
2084 assert_planes_disabled(dev_priv, pipe);
2085 assert_cursor_disabled(dev_priv, pipe);
2086 assert_sprites_disabled(dev_priv, pipe);
2088 if (HAS_PCH_LPT(dev_priv->dev))
2089 pch_transcoder = TRANSCODER_A;
2091 pch_transcoder = pipe;
2094 * A pipe without a PLL won't actually be able to drive bits from
2095 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
2098 if (HAS_GMCH_DISPLAY(dev_priv->dev))
2099 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI))
2100 assert_dsi_pll_enabled(dev_priv);
2102 assert_pll_enabled(dev_priv, pipe);
2104 if (crtc->config->has_pch_encoder) {
2105 /* if driving the PCH, we need FDI enabled */
2106 assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
2107 assert_fdi_tx_pll_enabled(dev_priv,
2108 (enum pipe) cpu_transcoder);
2110 /* FIXME: assert CPU port conditions for SNB+ */
2113 reg = PIPECONF(cpu_transcoder);
2114 val = I915_READ(reg);
2115 if (val & PIPECONF_ENABLE) {
2116 WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
2117 (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)));
2121 I915_WRITE(reg, val | PIPECONF_ENABLE);
2126 * intel_disable_pipe - disable a pipe, asserting requirements
2127 * @crtc: crtc whose pipes is to be disabled
2129 * Disable the pipe of @crtc, making sure that various hardware
2130 * specific requirements are met, if applicable, e.g. plane
2131 * disabled, panel fitter off, etc.
2133 * Will wait until the pipe has shut down before returning.
2135 static void intel_disable_pipe(struct intel_crtc *crtc)
2137 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
2138 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
2139 enum pipe pipe = crtc->pipe;
2143 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
2146 * Make sure planes won't keep trying to pump pixels to us,
2147 * or we might hang the display.
2149 assert_planes_disabled(dev_priv, pipe);
2150 assert_cursor_disabled(dev_priv, pipe);
2151 assert_sprites_disabled(dev_priv, pipe);
2153 reg = PIPECONF(cpu_transcoder);
2154 val = I915_READ(reg);
2155 if ((val & PIPECONF_ENABLE) == 0)
2159 * Double wide has implications for planes
2160 * so best keep it disabled when not needed.
2162 if (crtc->config->double_wide)
2163 val &= ~PIPECONF_DOUBLE_WIDE;
2165 /* Don't disable pipe or pipe PLLs if needed */
2166 if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) &&
2167 !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
2168 val &= ~PIPECONF_ENABLE;
2170 I915_WRITE(reg, val);
2171 if ((val & PIPECONF_ENABLE) == 0)
2172 intel_wait_for_pipe_off(crtc);
2175 static bool need_vtd_wa(struct drm_device *dev)
2177 #ifdef CONFIG_INTEL_IOMMU
2178 if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped)
2185 intel_tile_height(struct drm_device *dev, uint32_t pixel_format,
2186 uint64_t fb_format_modifier)
2188 unsigned int tile_height;
2189 uint32_t pixel_bytes;
2191 switch (fb_format_modifier) {
2192 case DRM_FORMAT_MOD_NONE:
2195 case I915_FORMAT_MOD_X_TILED:
2196 tile_height = IS_GEN2(dev) ? 16 : 8;
2198 case I915_FORMAT_MOD_Y_TILED:
2201 case I915_FORMAT_MOD_Yf_TILED:
2202 pixel_bytes = drm_format_plane_cpp(pixel_format, 0);
2203 switch (pixel_bytes) {
2217 "128-bit pixels are not supported for display!");
2223 MISSING_CASE(fb_format_modifier);
2232 intel_fb_align_height(struct drm_device *dev, unsigned int height,
2233 uint32_t pixel_format, uint64_t fb_format_modifier)
2235 return ALIGN(height, intel_tile_height(dev, pixel_format,
2236 fb_format_modifier));
2240 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb,
2241 const struct drm_plane_state *plane_state)
2243 struct intel_rotation_info *info = &view->rotation_info;
2244 unsigned int tile_height, tile_pitch;
2246 *view = i915_ggtt_view_normal;
2251 if (!intel_rotation_90_or_270(plane_state->rotation))
2254 *view = i915_ggtt_view_rotated;
2256 info->height = fb->height;
2257 info->pixel_format = fb->pixel_format;
2258 info->pitch = fb->pitches[0];
2259 info->fb_modifier = fb->modifier[0];
2261 tile_height = intel_tile_height(fb->dev, fb->pixel_format,
2263 tile_pitch = PAGE_SIZE / tile_height;
2264 info->width_pages = DIV_ROUND_UP(fb->pitches[0], tile_pitch);
2265 info->height_pages = DIV_ROUND_UP(fb->height, tile_height);
2266 info->size = info->width_pages * info->height_pages * PAGE_SIZE;
2271 static unsigned int intel_linear_alignment(struct drm_i915_private *dev_priv)
2273 if (INTEL_INFO(dev_priv)->gen >= 9)
2275 else if (IS_BROADWATER(dev_priv) || IS_CRESTLINE(dev_priv) ||
2276 IS_VALLEYVIEW(dev_priv))
2278 else if (INTEL_INFO(dev_priv)->gen >= 4)
2285 intel_pin_and_fence_fb_obj(struct drm_plane *plane,
2286 struct drm_framebuffer *fb,
2287 const struct drm_plane_state *plane_state,
2288 struct intel_engine_cs *pipelined,
2289 struct drm_i915_gem_request **pipelined_request)
2291 struct drm_device *dev = fb->dev;
2292 struct drm_i915_private *dev_priv = dev->dev_private;
2293 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2294 struct i915_ggtt_view view;
2298 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2300 switch (fb->modifier[0]) {
2301 case DRM_FORMAT_MOD_NONE:
2302 alignment = intel_linear_alignment(dev_priv);
2304 case I915_FORMAT_MOD_X_TILED:
2305 if (INTEL_INFO(dev)->gen >= 9)
2306 alignment = 256 * 1024;
2308 /* pin() will align the object as required by fence */
2312 case I915_FORMAT_MOD_Y_TILED:
2313 case I915_FORMAT_MOD_Yf_TILED:
2314 if (WARN_ONCE(INTEL_INFO(dev)->gen < 9,
2315 "Y tiling bo slipped through, driver bug!\n"))
2317 alignment = 1 * 1024 * 1024;
2320 MISSING_CASE(fb->modifier[0]);
2324 ret = intel_fill_fb_ggtt_view(&view, fb, plane_state);
2328 /* Note that the w/a also requires 64 PTE of padding following the
2329 * bo. We currently fill all unused PTE with the shadow page and so
2330 * we should always have valid PTE following the scanout preventing
2333 if (need_vtd_wa(dev) && alignment < 256 * 1024)
2334 alignment = 256 * 1024;
2337 * Global gtt pte registers are special registers which actually forward
2338 * writes to a chunk of system memory. Which means that there is no risk
2339 * that the register values disappear as soon as we call
2340 * intel_runtime_pm_put(), so it is correct to wrap only the
2341 * pin/unpin/fence and not more.
2343 intel_runtime_pm_get(dev_priv);
2345 dev_priv->mm.interruptible = false;
2346 ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined,
2347 pipelined_request, &view);
2349 goto err_interruptible;
2351 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2352 * fence, whereas 965+ only requires a fence if using
2353 * framebuffer compression. For simplicity, we always install
2354 * a fence as the cost is not that onerous.
2356 ret = i915_gem_object_get_fence(obj);
2357 if (ret == -EDEADLK) {
2359 * -EDEADLK means there are no free fences
2362 * This is propagated to atomic, but it uses
2363 * -EDEADLK to force a locking recovery, so
2364 * change the returned error to -EBUSY.
2371 i915_gem_object_pin_fence(obj);
2373 dev_priv->mm.interruptible = true;
2374 intel_runtime_pm_put(dev_priv);
2378 i915_gem_object_unpin_from_display_plane(obj, &view);
2380 dev_priv->mm.interruptible = true;
2381 intel_runtime_pm_put(dev_priv);
2385 static void intel_unpin_fb_obj(struct drm_framebuffer *fb,
2386 const struct drm_plane_state *plane_state)
2388 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2389 struct i915_ggtt_view view;
2392 WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex));
2394 ret = intel_fill_fb_ggtt_view(&view, fb, plane_state);
2395 WARN_ONCE(ret, "Couldn't get view from plane state!");
2397 i915_gem_object_unpin_fence(obj);
2398 i915_gem_object_unpin_from_display_plane(obj, &view);
2401 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
2402 * is assumed to be a power-of-two. */
2403 unsigned long intel_gen4_compute_page_offset(struct drm_i915_private *dev_priv,
2405 unsigned int tiling_mode,
2409 if (tiling_mode != I915_TILING_NONE) {
2410 unsigned int tile_rows, tiles;
2415 tiles = *x / (512/cpp);
2418 return tile_rows * pitch * 8 + tiles * 4096;
2420 unsigned int alignment = intel_linear_alignment(dev_priv) - 1;
2421 unsigned int offset;
2423 offset = *y * pitch + *x * cpp;
2424 *y = (offset & alignment) / pitch;
2425 *x = ((offset & alignment) - *y * pitch) / cpp;
2426 return offset & ~alignment;
2430 static int i9xx_format_to_fourcc(int format)
2433 case DISPPLANE_8BPP:
2434 return DRM_FORMAT_C8;
2435 case DISPPLANE_BGRX555:
2436 return DRM_FORMAT_XRGB1555;
2437 case DISPPLANE_BGRX565:
2438 return DRM_FORMAT_RGB565;
2440 case DISPPLANE_BGRX888:
2441 return DRM_FORMAT_XRGB8888;
2442 case DISPPLANE_RGBX888:
2443 return DRM_FORMAT_XBGR8888;
2444 case DISPPLANE_BGRX101010:
2445 return DRM_FORMAT_XRGB2101010;
2446 case DISPPLANE_RGBX101010:
2447 return DRM_FORMAT_XBGR2101010;
2451 static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
2454 case PLANE_CTL_FORMAT_RGB_565:
2455 return DRM_FORMAT_RGB565;
2457 case PLANE_CTL_FORMAT_XRGB_8888:
2460 return DRM_FORMAT_ABGR8888;
2462 return DRM_FORMAT_XBGR8888;
2465 return DRM_FORMAT_ARGB8888;
2467 return DRM_FORMAT_XRGB8888;
2469 case PLANE_CTL_FORMAT_XRGB_2101010:
2471 return DRM_FORMAT_XBGR2101010;
2473 return DRM_FORMAT_XRGB2101010;
2478 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2479 struct intel_initial_plane_config *plane_config)
2481 struct drm_device *dev = crtc->base.dev;
2482 struct drm_i915_gem_object *obj = NULL;
2483 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
2484 struct drm_framebuffer *fb = &plane_config->fb->base;
2485 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2486 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2489 size_aligned -= base_aligned;
2491 if (plane_config->size == 0)
2494 obj = i915_gem_object_create_stolen_for_preallocated(dev,
2501 obj->tiling_mode = plane_config->tiling;
2502 if (obj->tiling_mode == I915_TILING_X)
2503 obj->stride = fb->pitches[0];
2505 mode_cmd.pixel_format = fb->pixel_format;
2506 mode_cmd.width = fb->width;
2507 mode_cmd.height = fb->height;
2508 mode_cmd.pitches[0] = fb->pitches[0];
2509 mode_cmd.modifier[0] = fb->modifier[0];
2510 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
2512 mutex_lock(&dev->struct_mutex);
2513 if (intel_framebuffer_init(dev, to_intel_framebuffer(fb),
2515 DRM_DEBUG_KMS("intel fb init failed\n");
2518 mutex_unlock(&dev->struct_mutex);
2520 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
2524 drm_gem_object_unreference(&obj->base);
2525 mutex_unlock(&dev->struct_mutex);
2529 /* Update plane->state->fb to match plane->fb after driver-internal updates */
2531 update_state_fb(struct drm_plane *plane)
2533 if (plane->fb == plane->state->fb)
2536 if (plane->state->fb)
2537 drm_framebuffer_unreference(plane->state->fb);
2538 plane->state->fb = plane->fb;
2539 if (plane->state->fb)
2540 drm_framebuffer_reference(plane->state->fb);
2544 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2545 struct intel_initial_plane_config *plane_config)
2547 struct drm_device *dev = intel_crtc->base.dev;
2548 struct drm_i915_private *dev_priv = dev->dev_private;
2550 struct intel_crtc *i;
2551 struct drm_i915_gem_object *obj;
2552 struct drm_plane *primary = intel_crtc->base.primary;
2553 struct drm_plane_state *plane_state = primary->state;
2554 struct drm_framebuffer *fb;
2556 if (!plane_config->fb)
2559 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
2560 fb = &plane_config->fb->base;
2564 kfree(plane_config->fb);
2567 * Failed to alloc the obj, check to see if we should share
2568 * an fb with another CRTC instead
2570 for_each_crtc(dev, c) {
2571 i = to_intel_crtc(c);
2573 if (c == &intel_crtc->base)
2579 fb = c->primary->fb;
2583 obj = intel_fb_obj(fb);
2584 if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) {
2585 drm_framebuffer_reference(fb);
2593 plane_state->src_x = plane_state->src_y = 0;
2594 plane_state->src_w = fb->width << 16;
2595 plane_state->src_h = fb->height << 16;
2597 plane_state->crtc_x = plane_state->src_y = 0;
2598 plane_state->crtc_w = fb->width;
2599 plane_state->crtc_h = fb->height;
2601 obj = intel_fb_obj(fb);
2602 if (obj->tiling_mode != I915_TILING_NONE)
2603 dev_priv->preserve_bios_swizzle = true;
2605 drm_framebuffer_reference(fb);
2606 primary->fb = primary->state->fb = fb;
2607 primary->crtc = primary->state->crtc = &intel_crtc->base;
2608 intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary));
2609 obj->frontbuffer_bits |= to_intel_plane(primary)->frontbuffer_bit;
2612 static void i9xx_update_primary_plane(struct drm_crtc *crtc,
2613 struct drm_framebuffer *fb,
2616 struct drm_device *dev = crtc->dev;
2617 struct drm_i915_private *dev_priv = dev->dev_private;
2618 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2619 struct drm_plane *primary = crtc->primary;
2620 bool visible = to_intel_plane_state(primary->state)->visible;
2621 struct drm_i915_gem_object *obj;
2622 int plane = intel_crtc->plane;
2623 unsigned long linear_offset;
2625 u32 reg = DSPCNTR(plane);
2628 if (!visible || !fb) {
2630 if (INTEL_INFO(dev)->gen >= 4)
2631 I915_WRITE(DSPSURF(plane), 0);
2633 I915_WRITE(DSPADDR(plane), 0);
2638 obj = intel_fb_obj(fb);
2639 if (WARN_ON(obj == NULL))
2642 pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
2644 dspcntr = DISPPLANE_GAMMA_ENABLE;
2646 dspcntr |= DISPLAY_PLANE_ENABLE;
2648 if (INTEL_INFO(dev)->gen < 4) {
2649 if (intel_crtc->pipe == PIPE_B)
2650 dspcntr |= DISPPLANE_SEL_PIPE_B;
2652 /* pipesrc and dspsize control the size that is scaled from,
2653 * which should always be the user's requested size.
2655 I915_WRITE(DSPSIZE(plane),
2656 ((intel_crtc->config->pipe_src_h - 1) << 16) |
2657 (intel_crtc->config->pipe_src_w - 1));
2658 I915_WRITE(DSPPOS(plane), 0);
2659 } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) {
2660 I915_WRITE(PRIMSIZE(plane),
2661 ((intel_crtc->config->pipe_src_h - 1) << 16) |
2662 (intel_crtc->config->pipe_src_w - 1));
2663 I915_WRITE(PRIMPOS(plane), 0);
2664 I915_WRITE(PRIMCNSTALPHA(plane), 0);
2667 switch (fb->pixel_format) {
2669 dspcntr |= DISPPLANE_8BPP;
2671 case DRM_FORMAT_XRGB1555:
2672 dspcntr |= DISPPLANE_BGRX555;
2674 case DRM_FORMAT_RGB565:
2675 dspcntr |= DISPPLANE_BGRX565;
2677 case DRM_FORMAT_XRGB8888:
2678 dspcntr |= DISPPLANE_BGRX888;
2680 case DRM_FORMAT_XBGR8888:
2681 dspcntr |= DISPPLANE_RGBX888;
2683 case DRM_FORMAT_XRGB2101010:
2684 dspcntr |= DISPPLANE_BGRX101010;
2686 case DRM_FORMAT_XBGR2101010:
2687 dspcntr |= DISPPLANE_RGBX101010;
2693 if (INTEL_INFO(dev)->gen >= 4 &&
2694 obj->tiling_mode != I915_TILING_NONE)
2695 dspcntr |= DISPPLANE_TILED;
2698 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
2700 linear_offset = y * fb->pitches[0] + x * pixel_size;
2702 if (INTEL_INFO(dev)->gen >= 4) {
2703 intel_crtc->dspaddr_offset =
2704 intel_gen4_compute_page_offset(dev_priv,
2705 &x, &y, obj->tiling_mode,
2708 linear_offset -= intel_crtc->dspaddr_offset;
2710 intel_crtc->dspaddr_offset = linear_offset;
2713 if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) {
2714 dspcntr |= DISPPLANE_ROTATE_180;
2716 x += (intel_crtc->config->pipe_src_w - 1);
2717 y += (intel_crtc->config->pipe_src_h - 1);
2719 /* Finding the last pixel of the last line of the display
2720 data and adding to linear_offset*/
2722 (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] +
2723 (intel_crtc->config->pipe_src_w - 1) * pixel_size;
2726 I915_WRITE(reg, dspcntr);
2728 I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
2729 if (INTEL_INFO(dev)->gen >= 4) {
2730 I915_WRITE(DSPSURF(plane),
2731 i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
2732 I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
2733 I915_WRITE(DSPLINOFF(plane), linear_offset);
2735 I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset);
2739 static void ironlake_update_primary_plane(struct drm_crtc *crtc,
2740 struct drm_framebuffer *fb,
2743 struct drm_device *dev = crtc->dev;
2744 struct drm_i915_private *dev_priv = dev->dev_private;
2745 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2746 struct drm_plane *primary = crtc->primary;
2747 bool visible = to_intel_plane_state(primary->state)->visible;
2748 struct drm_i915_gem_object *obj;
2749 int plane = intel_crtc->plane;
2750 unsigned long linear_offset;
2752 u32 reg = DSPCNTR(plane);
2755 if (!visible || !fb) {
2757 I915_WRITE(DSPSURF(plane), 0);
2762 obj = intel_fb_obj(fb);
2763 if (WARN_ON(obj == NULL))
2766 pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
2768 dspcntr = DISPPLANE_GAMMA_ENABLE;
2770 dspcntr |= DISPLAY_PLANE_ENABLE;
2772 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
2773 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
2775 switch (fb->pixel_format) {
2777 dspcntr |= DISPPLANE_8BPP;
2779 case DRM_FORMAT_RGB565:
2780 dspcntr |= DISPPLANE_BGRX565;
2782 case DRM_FORMAT_XRGB8888:
2783 dspcntr |= DISPPLANE_BGRX888;
2785 case DRM_FORMAT_XBGR8888:
2786 dspcntr |= DISPPLANE_RGBX888;
2788 case DRM_FORMAT_XRGB2101010:
2789 dspcntr |= DISPPLANE_BGRX101010;
2791 case DRM_FORMAT_XBGR2101010:
2792 dspcntr |= DISPPLANE_RGBX101010;
2798 if (obj->tiling_mode != I915_TILING_NONE)
2799 dspcntr |= DISPPLANE_TILED;
2801 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev))
2802 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
2804 linear_offset = y * fb->pitches[0] + x * pixel_size;
2805 intel_crtc->dspaddr_offset =
2806 intel_gen4_compute_page_offset(dev_priv,
2807 &x, &y, obj->tiling_mode,
2810 linear_offset -= intel_crtc->dspaddr_offset;
2811 if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) {
2812 dspcntr |= DISPPLANE_ROTATE_180;
2814 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
2815 x += (intel_crtc->config->pipe_src_w - 1);
2816 y += (intel_crtc->config->pipe_src_h - 1);
2818 /* Finding the last pixel of the last line of the display
2819 data and adding to linear_offset*/
2821 (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] +
2822 (intel_crtc->config->pipe_src_w - 1) * pixel_size;
2826 I915_WRITE(reg, dspcntr);
2828 I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
2829 I915_WRITE(DSPSURF(plane),
2830 i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
2831 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
2832 I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
2834 I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
2835 I915_WRITE(DSPLINOFF(plane), linear_offset);
2840 u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier,
2841 uint32_t pixel_format)
2843 u32 bits_per_pixel = drm_format_plane_cpp(pixel_format, 0) * 8;
2846 * The stride is either expressed as a multiple of 64 bytes
2847 * chunks for linear buffers or in number of tiles for tiled
2850 switch (fb_modifier) {
2851 case DRM_FORMAT_MOD_NONE:
2853 case I915_FORMAT_MOD_X_TILED:
2854 if (INTEL_INFO(dev)->gen == 2)
2857 case I915_FORMAT_MOD_Y_TILED:
2858 /* No need to check for old gens and Y tiling since this is
2859 * about the display engine and those will be blocked before
2863 case I915_FORMAT_MOD_Yf_TILED:
2864 if (bits_per_pixel == 8)
2869 MISSING_CASE(fb_modifier);
2874 unsigned long intel_plane_obj_offset(struct intel_plane *intel_plane,
2875 struct drm_i915_gem_object *obj)
2877 const struct i915_ggtt_view *view = &i915_ggtt_view_normal;
2879 if (intel_rotation_90_or_270(intel_plane->base.state->rotation))
2880 view = &i915_ggtt_view_rotated;
2882 return i915_gem_obj_ggtt_offset_view(obj, view);
2885 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
2887 struct drm_device *dev = intel_crtc->base.dev;
2888 struct drm_i915_private *dev_priv = dev->dev_private;
2890 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
2891 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
2892 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
2896 * This function detaches (aka. unbinds) unused scalers in hardware
2898 static void skl_detach_scalers(struct intel_crtc *intel_crtc)
2900 struct intel_crtc_scaler_state *scaler_state;
2903 scaler_state = &intel_crtc->config->scaler_state;
2905 /* loop through and disable scalers that aren't in use */
2906 for (i = 0; i < intel_crtc->num_scalers; i++) {
2907 if (!scaler_state->scalers[i].in_use)
2908 skl_detach_scaler(intel_crtc, i);
2912 u32 skl_plane_ctl_format(uint32_t pixel_format)
2914 switch (pixel_format) {
2916 return PLANE_CTL_FORMAT_INDEXED;
2917 case DRM_FORMAT_RGB565:
2918 return PLANE_CTL_FORMAT_RGB_565;
2919 case DRM_FORMAT_XBGR8888:
2920 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
2921 case DRM_FORMAT_XRGB8888:
2922 return PLANE_CTL_FORMAT_XRGB_8888;
2924 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
2925 * to be already pre-multiplied. We need to add a knob (or a different
2926 * DRM_FORMAT) for user-space to configure that.
2928 case DRM_FORMAT_ABGR8888:
2929 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX |
2930 PLANE_CTL_ALPHA_SW_PREMULTIPLY;
2931 case DRM_FORMAT_ARGB8888:
2932 return PLANE_CTL_FORMAT_XRGB_8888 |
2933 PLANE_CTL_ALPHA_SW_PREMULTIPLY;
2934 case DRM_FORMAT_XRGB2101010:
2935 return PLANE_CTL_FORMAT_XRGB_2101010;
2936 case DRM_FORMAT_XBGR2101010:
2937 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
2938 case DRM_FORMAT_YUYV:
2939 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
2940 case DRM_FORMAT_YVYU:
2941 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
2942 case DRM_FORMAT_UYVY:
2943 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
2944 case DRM_FORMAT_VYUY:
2945 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
2947 MISSING_CASE(pixel_format);
2953 u32 skl_plane_ctl_tiling(uint64_t fb_modifier)
2955 switch (fb_modifier) {
2956 case DRM_FORMAT_MOD_NONE:
2958 case I915_FORMAT_MOD_X_TILED:
2959 return PLANE_CTL_TILED_X;
2960 case I915_FORMAT_MOD_Y_TILED:
2961 return PLANE_CTL_TILED_Y;
2962 case I915_FORMAT_MOD_Yf_TILED:
2963 return PLANE_CTL_TILED_YF;
2965 MISSING_CASE(fb_modifier);
2971 u32 skl_plane_ctl_rotation(unsigned int rotation)
2974 case BIT(DRM_ROTATE_0):
2977 * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr
2978 * while i915 HW rotation is clockwise, thats why this swapping.
2980 case BIT(DRM_ROTATE_90):
2981 return PLANE_CTL_ROTATE_270;
2982 case BIT(DRM_ROTATE_180):
2983 return PLANE_CTL_ROTATE_180;
2984 case BIT(DRM_ROTATE_270):
2985 return PLANE_CTL_ROTATE_90;
2987 MISSING_CASE(rotation);
2993 static void skylake_update_primary_plane(struct drm_crtc *crtc,
2994 struct drm_framebuffer *fb,
2997 struct drm_device *dev = crtc->dev;
2998 struct drm_i915_private *dev_priv = dev->dev_private;
2999 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3000 struct drm_plane *plane = crtc->primary;
3001 bool visible = to_intel_plane_state(plane->state)->visible;
3002 struct drm_i915_gem_object *obj;
3003 int pipe = intel_crtc->pipe;
3004 u32 plane_ctl, stride_div, stride;
3005 u32 tile_height, plane_offset, plane_size;
3006 unsigned int rotation;
3007 int x_offset, y_offset;
3008 unsigned long surf_addr;
3009 struct intel_crtc_state *crtc_state = intel_crtc->config;
3010 struct intel_plane_state *plane_state;
3011 int src_x = 0, src_y = 0, src_w = 0, src_h = 0;
3012 int dst_x = 0, dst_y = 0, dst_w = 0, dst_h = 0;
3015 plane_state = to_intel_plane_state(plane->state);
3017 if (!visible || !fb) {
3018 I915_WRITE(PLANE_CTL(pipe, 0), 0);
3019 I915_WRITE(PLANE_SURF(pipe, 0), 0);
3020 POSTING_READ(PLANE_CTL(pipe, 0));
3024 plane_ctl = PLANE_CTL_ENABLE |
3025 PLANE_CTL_PIPE_GAMMA_ENABLE |
3026 PLANE_CTL_PIPE_CSC_ENABLE;
3028 plane_ctl |= skl_plane_ctl_format(fb->pixel_format);
3029 plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]);
3030 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
3032 rotation = plane->state->rotation;
3033 plane_ctl |= skl_plane_ctl_rotation(rotation);
3035 obj = intel_fb_obj(fb);
3036 stride_div = intel_fb_stride_alignment(dev, fb->modifier[0],
3038 surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj);
3041 * FIXME: intel_plane_state->src, dst aren't set when transitional
3042 * update_plane helpers are called from legacy paths.
3043 * Once full atomic crtc is available, below check can be avoided.
3045 if (drm_rect_width(&plane_state->src)) {
3046 scaler_id = plane_state->scaler_id;
3047 src_x = plane_state->src.x1 >> 16;
3048 src_y = plane_state->src.y1 >> 16;
3049 src_w = drm_rect_width(&plane_state->src) >> 16;
3050 src_h = drm_rect_height(&plane_state->src) >> 16;
3051 dst_x = plane_state->dst.x1;
3052 dst_y = plane_state->dst.y1;
3053 dst_w = drm_rect_width(&plane_state->dst);
3054 dst_h = drm_rect_height(&plane_state->dst);
3056 WARN_ON(x != src_x || y != src_y);
3058 src_w = intel_crtc->config->pipe_src_w;
3059 src_h = intel_crtc->config->pipe_src_h;
3062 if (intel_rotation_90_or_270(rotation)) {
3063 /* stride = Surface height in tiles */
3064 tile_height = intel_tile_height(dev, fb->pixel_format,
3066 stride = DIV_ROUND_UP(fb->height, tile_height);
3067 x_offset = stride * tile_height - y - src_h;
3069 plane_size = (src_w - 1) << 16 | (src_h - 1);
3071 stride = fb->pitches[0] / stride_div;
3074 plane_size = (src_h - 1) << 16 | (src_w - 1);
3076 plane_offset = y_offset << 16 | x_offset;
3078 I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl);
3079 I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset);
3080 I915_WRITE(PLANE_SIZE(pipe, 0), plane_size);
3081 I915_WRITE(PLANE_STRIDE(pipe, 0), stride);
3083 if (scaler_id >= 0) {
3084 uint32_t ps_ctrl = 0;
3086 WARN_ON(!dst_w || !dst_h);
3087 ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) |
3088 crtc_state->scaler_state.scalers[scaler_id].mode;
3089 I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl);
3090 I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0);
3091 I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y);
3092 I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h);
3093 I915_WRITE(PLANE_POS(pipe, 0), 0);
3095 I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x);
3098 I915_WRITE(PLANE_SURF(pipe, 0), surf_addr);
3100 POSTING_READ(PLANE_SURF(pipe, 0));
3103 /* Assume fb object is pinned & idle & fenced and just update base pointers */
3105 intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
3106 int x, int y, enum mode_set_atomic state)
3108 struct drm_device *dev = crtc->dev;
3109 struct drm_i915_private *dev_priv = dev->dev_private;
3111 if (dev_priv->fbc.disable_fbc)
3112 dev_priv->fbc.disable_fbc(dev_priv);
3114 dev_priv->display.update_primary_plane(crtc, fb, x, y);
3119 static void intel_complete_page_flips(struct drm_device *dev)
3121 struct drm_crtc *crtc;
3123 for_each_crtc(dev, crtc) {
3124 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3125 enum plane plane = intel_crtc->plane;
3127 intel_prepare_page_flip(dev, plane);
3128 intel_finish_page_flip_plane(dev, plane);
3132 static void intel_update_primary_planes(struct drm_device *dev)
3134 struct drm_i915_private *dev_priv = dev->dev_private;
3135 struct drm_crtc *crtc;
3137 for_each_crtc(dev, crtc) {
3138 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3140 drm_modeset_lock(&crtc->mutex, NULL);
3142 * FIXME: Once we have proper support for primary planes (and
3143 * disabling them without disabling the entire crtc) allow again
3144 * a NULL crtc->primary->fb.
3146 if (intel_crtc->active && crtc->primary->fb)
3147 dev_priv->display.update_primary_plane(crtc,
3151 drm_modeset_unlock(&crtc->mutex);
3155 void intel_prepare_reset(struct drm_device *dev)
3157 /* no reset support for gen2 */
3161 /* reset doesn't touch the display */
3162 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
3165 drm_modeset_lock_all(dev);
3167 * Disabling the crtcs gracefully seems nicer. Also the
3168 * g33 docs say we should at least disable all the planes.
3170 intel_display_suspend(dev);
3173 void intel_finish_reset(struct drm_device *dev)
3175 struct drm_i915_private *dev_priv = to_i915(dev);
3178 * Flips in the rings will be nuked by the reset,
3179 * so complete all pending flips so that user space
3180 * will get its events and not get stuck.
3182 intel_complete_page_flips(dev);
3184 /* no reset support for gen2 */
3188 /* reset doesn't touch the display */
3189 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) {
3191 * Flips in the rings have been nuked by the reset,
3192 * so update the base address of all primary
3193 * planes to the the last fb to make sure we're
3194 * showing the correct fb after a reset.
3196 intel_update_primary_planes(dev);
3201 * The display has been reset as well,
3202 * so need a full re-initialization.
3204 intel_runtime_pm_disable_interrupts(dev_priv);
3205 intel_runtime_pm_enable_interrupts(dev_priv);
3207 intel_modeset_init_hw(dev);
3209 spin_lock_irq(&dev_priv->irq_lock);
3210 if (dev_priv->display.hpd_irq_setup)
3211 dev_priv->display.hpd_irq_setup(dev);
3212 spin_unlock_irq(&dev_priv->irq_lock);
3214 intel_display_resume(dev);
3216 intel_hpd_init(dev_priv);
3218 drm_modeset_unlock_all(dev);
3222 intel_finish_fb(struct drm_framebuffer *old_fb)
3224 struct drm_i915_gem_object *obj = intel_fb_obj(old_fb);
3225 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
3226 bool was_interruptible = dev_priv->mm.interruptible;
3229 /* Big Hammer, we also need to ensure that any pending
3230 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
3231 * current scanout is retired before unpinning the old
3232 * framebuffer. Note that we rely on userspace rendering
3233 * into the buffer attached to the pipe they are waiting
3234 * on. If not, userspace generates a GPU hang with IPEHR
3235 * point to the MI_WAIT_FOR_EVENT.
3237 * This should only fail upon a hung GPU, in which case we
3238 * can safely continue.
3240 dev_priv->mm.interruptible = false;
3241 ret = i915_gem_object_wait_rendering(obj, true);
3242 dev_priv->mm.interruptible = was_interruptible;
3247 static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
3249 struct drm_device *dev = crtc->dev;
3250 struct drm_i915_private *dev_priv = dev->dev_private;
3251 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3254 if (i915_reset_in_progress(&dev_priv->gpu_error) ||
3255 intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
3258 spin_lock_irq(&dev->event_lock);
3259 pending = to_intel_crtc(crtc)->unpin_work != NULL;
3260 spin_unlock_irq(&dev->event_lock);
3265 static void intel_update_pipe_size(struct intel_crtc *crtc)
3267 struct drm_device *dev = crtc->base.dev;
3268 struct drm_i915_private *dev_priv = dev->dev_private;
3269 const struct drm_display_mode *adjusted_mode;
3275 * Update pipe size and adjust fitter if needed: the reason for this is
3276 * that in compute_mode_changes we check the native mode (not the pfit
3277 * mode) to see if we can flip rather than do a full mode set. In the
3278 * fastboot case, we'll flip, but if we don't update the pipesrc and
3279 * pfit state, we'll end up with a big fb scanned out into the wrong
3282 * To fix this properly, we need to hoist the checks up into
3283 * compute_mode_changes (or above), check the actual pfit state and
3284 * whether the platform allows pfit disable with pipe active, and only
3285 * then update the pipesrc and pfit state, even on the flip path.
3288 adjusted_mode = &crtc->config->base.adjusted_mode;
3290 I915_WRITE(PIPESRC(crtc->pipe),
3291 ((adjusted_mode->crtc_hdisplay - 1) << 16) |
3292 (adjusted_mode->crtc_vdisplay - 1));
3293 if (!crtc->config->pch_pfit.enabled &&
3294 (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
3295 intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
3296 I915_WRITE(PF_CTL(crtc->pipe), 0);
3297 I915_WRITE(PF_WIN_POS(crtc->pipe), 0);
3298 I915_WRITE(PF_WIN_SZ(crtc->pipe), 0);
3300 crtc->config->pipe_src_w = adjusted_mode->crtc_hdisplay;
3301 crtc->config->pipe_src_h = adjusted_mode->crtc_vdisplay;
3304 static void intel_fdi_normal_train(struct drm_crtc *crtc)
3306 struct drm_device *dev = crtc->dev;
3307 struct drm_i915_private *dev_priv = dev->dev_private;
3308 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3309 int pipe = intel_crtc->pipe;
3312 /* enable normal train */
3313 reg = FDI_TX_CTL(pipe);
3314 temp = I915_READ(reg);
3315 if (IS_IVYBRIDGE(dev)) {
3316 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
3317 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
3319 temp &= ~FDI_LINK_TRAIN_NONE;
3320 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
3322 I915_WRITE(reg, temp);
3324 reg = FDI_RX_CTL(pipe);
3325 temp = I915_READ(reg);
3326 if (HAS_PCH_CPT(dev)) {
3327 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3328 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
3330 temp &= ~FDI_LINK_TRAIN_NONE;
3331 temp |= FDI_LINK_TRAIN_NONE;
3333 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
3335 /* wait one idle pattern time */
3339 /* IVB wants error correction enabled */
3340 if (IS_IVYBRIDGE(dev))
3341 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
3342 FDI_FE_ERRC_ENABLE);
3345 /* The FDI link training functions for ILK/Ibexpeak. */
3346 static void ironlake_fdi_link_train(struct drm_crtc *crtc)
3348 struct drm_device *dev = crtc->dev;
3349 struct drm_i915_private *dev_priv = dev->dev_private;
3350 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3351 int pipe = intel_crtc->pipe;
3352 u32 reg, temp, tries;
3354 /* FDI needs bits from pipe first */
3355 assert_pipe_enabled(dev_priv, pipe);
3357 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3359 reg = FDI_RX_IMR(pipe);
3360 temp = I915_READ(reg);
3361 temp &= ~FDI_RX_SYMBOL_LOCK;
3362 temp &= ~FDI_RX_BIT_LOCK;
3363 I915_WRITE(reg, temp);
3367 /* enable CPU FDI TX and PCH FDI RX */
3368 reg = FDI_TX_CTL(pipe);
3369 temp = I915_READ(reg);
3370 temp &= ~FDI_DP_PORT_WIDTH_MASK;
3371 temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
3372 temp &= ~FDI_LINK_TRAIN_NONE;
3373 temp |= FDI_LINK_TRAIN_PATTERN_1;
3374 I915_WRITE(reg, temp | FDI_TX_ENABLE);
3376 reg = FDI_RX_CTL(pipe);
3377 temp = I915_READ(reg);
3378 temp &= ~FDI_LINK_TRAIN_NONE;
3379 temp |= FDI_LINK_TRAIN_PATTERN_1;
3380 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3385 /* Ironlake workaround, enable clock pointer after FDI enable*/
3386 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
3387 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
3388 FDI_RX_PHASE_SYNC_POINTER_EN);
3390 reg = FDI_RX_IIR(pipe);
3391 for (tries = 0; tries < 5; tries++) {
3392 temp = I915_READ(reg);
3393 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3395 if ((temp & FDI_RX_BIT_LOCK)) {
3396 DRM_DEBUG_KMS("FDI train 1 done.\n");
3397 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
3402 DRM_ERROR("FDI train 1 fail!\n");
3405 reg = FDI_TX_CTL(pipe);
3406 temp = I915_READ(reg);
3407 temp &= ~FDI_LINK_TRAIN_NONE;
3408 temp |= FDI_LINK_TRAIN_PATTERN_2;
3409 I915_WRITE(reg, temp);
3411 reg = FDI_RX_CTL(pipe);
3412 temp = I915_READ(reg);
3413 temp &= ~FDI_LINK_TRAIN_NONE;
3414 temp |= FDI_LINK_TRAIN_PATTERN_2;
3415 I915_WRITE(reg, temp);
3420 reg = FDI_RX_IIR(pipe);
3421 for (tries = 0; tries < 5; tries++) {
3422 temp = I915_READ(reg);
3423 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3425 if (temp & FDI_RX_SYMBOL_LOCK) {
3426 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
3427 DRM_DEBUG_KMS("FDI train 2 done.\n");
3432 DRM_ERROR("FDI train 2 fail!\n");
3434 DRM_DEBUG_KMS("FDI train done\n");
3438 static const int snb_b_fdi_train_param[] = {
3439 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
3440 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
3441 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
3442 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
3445 /* The FDI link training functions for SNB/Cougarpoint. */
3446 static void gen6_fdi_link_train(struct drm_crtc *crtc)
3448 struct drm_device *dev = crtc->dev;
3449 struct drm_i915_private *dev_priv = dev->dev_private;
3450 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3451 int pipe = intel_crtc->pipe;
3452 u32 reg, temp, i, retry;
3454 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3456 reg = FDI_RX_IMR(pipe);
3457 temp = I915_READ(reg);
3458 temp &= ~FDI_RX_SYMBOL_LOCK;
3459 temp &= ~FDI_RX_BIT_LOCK;
3460 I915_WRITE(reg, temp);
3465 /* enable CPU FDI TX and PCH FDI RX */
3466 reg = FDI_TX_CTL(pipe);
3467 temp = I915_READ(reg);
3468 temp &= ~FDI_DP_PORT_WIDTH_MASK;
3469 temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
3470 temp &= ~FDI_LINK_TRAIN_NONE;
3471 temp |= FDI_LINK_TRAIN_PATTERN_1;
3472 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
3474 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
3475 I915_WRITE(reg, temp | FDI_TX_ENABLE);
3477 I915_WRITE(FDI_RX_MISC(pipe),
3478 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
3480 reg = FDI_RX_CTL(pipe);
3481 temp = I915_READ(reg);
3482 if (HAS_PCH_CPT(dev)) {
3483 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3484 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
3486 temp &= ~FDI_LINK_TRAIN_NONE;
3487 temp |= FDI_LINK_TRAIN_PATTERN_1;
3489 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3494 for (i = 0; i < 4; i++) {
3495 reg = FDI_TX_CTL(pipe);
3496 temp = I915_READ(reg);
3497 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
3498 temp |= snb_b_fdi_train_param[i];
3499 I915_WRITE(reg, temp);
3504 for (retry = 0; retry < 5; retry++) {
3505 reg = FDI_RX_IIR(pipe);
3506 temp = I915_READ(reg);
3507 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3508 if (temp & FDI_RX_BIT_LOCK) {
3509 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
3510 DRM_DEBUG_KMS("FDI train 1 done.\n");
3519 DRM_ERROR("FDI train 1 fail!\n");
3522 reg = FDI_TX_CTL(pipe);
3523 temp = I915_READ(reg);
3524 temp &= ~FDI_LINK_TRAIN_NONE;
3525 temp |= FDI_LINK_TRAIN_PATTERN_2;
3527 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
3529 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
3531 I915_WRITE(reg, temp);
3533 reg = FDI_RX_CTL(pipe);
3534 temp = I915_READ(reg);
3535 if (HAS_PCH_CPT(dev)) {
3536 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3537 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
3539 temp &= ~FDI_LINK_TRAIN_NONE;
3540 temp |= FDI_LINK_TRAIN_PATTERN_2;
3542 I915_WRITE(reg, temp);
3547 for (i = 0; i < 4; i++) {
3548 reg = FDI_TX_CTL(pipe);
3549 temp = I915_READ(reg);
3550 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
3551 temp |= snb_b_fdi_train_param[i];
3552 I915_WRITE(reg, temp);
3557 for (retry = 0; retry < 5; retry++) {
3558 reg = FDI_RX_IIR(pipe);
3559 temp = I915_READ(reg);
3560 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3561 if (temp & FDI_RX_SYMBOL_LOCK) {
3562 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
3563 DRM_DEBUG_KMS("FDI train 2 done.\n");
3572 DRM_ERROR("FDI train 2 fail!\n");
3574 DRM_DEBUG_KMS("FDI train done.\n");
3577 /* Manual link training for Ivy Bridge A0 parts */
3578 static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
3580 struct drm_device *dev = crtc->dev;
3581 struct drm_i915_private *dev_priv = dev->dev_private;
3582 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3583 int pipe = intel_crtc->pipe;
3584 u32 reg, temp, i, j;
3586 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3588 reg = FDI_RX_IMR(pipe);
3589 temp = I915_READ(reg);
3590 temp &= ~FDI_RX_SYMBOL_LOCK;
3591 temp &= ~FDI_RX_BIT_LOCK;
3592 I915_WRITE(reg, temp);
3597 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3598 I915_READ(FDI_RX_IIR(pipe)));
3600 /* Try each vswing and preemphasis setting twice before moving on */
3601 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
3602 /* disable first in case we need to retry */
3603 reg = FDI_TX_CTL(pipe);
3604 temp = I915_READ(reg);
3605 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
3606 temp &= ~FDI_TX_ENABLE;
3607 I915_WRITE(reg, temp);
3609 reg = FDI_RX_CTL(pipe);
3610 temp = I915_READ(reg);
3611 temp &= ~FDI_LINK_TRAIN_AUTO;
3612 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3613 temp &= ~FDI_RX_ENABLE;
3614 I915_WRITE(reg, temp);
3616 /* enable CPU FDI TX and PCH FDI RX */
3617 reg = FDI_TX_CTL(pipe);
3618 temp = I915_READ(reg);
3619 temp &= ~FDI_DP_PORT_WIDTH_MASK;
3620 temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
3621 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
3622 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
3623 temp |= snb_b_fdi_train_param[j/2];
3624 temp |= FDI_COMPOSITE_SYNC;
3625 I915_WRITE(reg, temp | FDI_TX_ENABLE);
3627 I915_WRITE(FDI_RX_MISC(pipe),
3628 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
3630 reg = FDI_RX_CTL(pipe);
3631 temp = I915_READ(reg);
3632 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
3633 temp |= FDI_COMPOSITE_SYNC;
3634 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3637 udelay(1); /* should be 0.5us */
3639 for (i = 0; i < 4; i++) {
3640 reg = FDI_RX_IIR(pipe);
3641 temp = I915_READ(reg);
3642 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3644 if (temp & FDI_RX_BIT_LOCK ||
3645 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
3646 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
3647 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3651 udelay(1); /* should be 0.5us */
3654 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
3659 reg = FDI_TX_CTL(pipe);
3660 temp = I915_READ(reg);
3661 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
3662 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
3663 I915_WRITE(reg, temp);
3665 reg = FDI_RX_CTL(pipe);
3666 temp = I915_READ(reg);
3667 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3668 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
3669 I915_WRITE(reg, temp);
3672 udelay(2); /* should be 1.5us */
3674 for (i = 0; i < 4; i++) {
3675 reg = FDI_RX_IIR(pipe);
3676 temp = I915_READ(reg);
3677 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3679 if (temp & FDI_RX_SYMBOL_LOCK ||
3680 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
3681 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
3682 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
3686 udelay(2); /* should be 1.5us */
3689 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
3693 DRM_DEBUG_KMS("FDI train done.\n");
3696 static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
3698 struct drm_device *dev = intel_crtc->base.dev;
3699 struct drm_i915_private *dev_priv = dev->dev_private;
3700 int pipe = intel_crtc->pipe;
3704 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
3705 reg = FDI_RX_CTL(pipe);
3706 temp = I915_READ(reg);
3707 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
3708 temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
3709 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
3710 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
3715 /* Switch from Rawclk to PCDclk */
3716 temp = I915_READ(reg);
3717 I915_WRITE(reg, temp | FDI_PCDCLK);
3722 /* Enable CPU FDI TX PLL, always on for Ironlake */
3723 reg = FDI_TX_CTL(pipe);
3724 temp = I915_READ(reg);
3725 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
3726 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
3733 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
3735 struct drm_device *dev = intel_crtc->base.dev;
3736 struct drm_i915_private *dev_priv = dev->dev_private;
3737 int pipe = intel_crtc->pipe;
3740 /* Switch from PCDclk to Rawclk */
3741 reg = FDI_RX_CTL(pipe);
3742 temp = I915_READ(reg);
3743 I915_WRITE(reg, temp & ~FDI_PCDCLK);
3745 /* Disable CPU FDI TX PLL */
3746 reg = FDI_TX_CTL(pipe);
3747 temp = I915_READ(reg);
3748 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
3753 reg = FDI_RX_CTL(pipe);
3754 temp = I915_READ(reg);
3755 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
3757 /* Wait for the clocks to turn off. */
3762 static void ironlake_fdi_disable(struct drm_crtc *crtc)
3764 struct drm_device *dev = crtc->dev;
3765 struct drm_i915_private *dev_priv = dev->dev_private;
3766 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3767 int pipe = intel_crtc->pipe;
3770 /* disable CPU FDI tx and PCH FDI rx */
3771 reg = FDI_TX_CTL(pipe);
3772 temp = I915_READ(reg);
3773 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
3776 reg = FDI_RX_CTL(pipe);
3777 temp = I915_READ(reg);
3778 temp &= ~(0x7 << 16);
3779 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
3780 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
3785 /* Ironlake workaround, disable clock pointer after downing FDI */
3786 if (HAS_PCH_IBX(dev))
3787 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
3789 /* still set train pattern 1 */
3790 reg = FDI_TX_CTL(pipe);
3791 temp = I915_READ(reg);
3792 temp &= ~FDI_LINK_TRAIN_NONE;
3793 temp |= FDI_LINK_TRAIN_PATTERN_1;
3794 I915_WRITE(reg, temp);
3796 reg = FDI_RX_CTL(pipe);
3797 temp = I915_READ(reg);
3798 if (HAS_PCH_CPT(dev)) {
3799 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3800 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
3802 temp &= ~FDI_LINK_TRAIN_NONE;
3803 temp |= FDI_LINK_TRAIN_PATTERN_1;
3805 /* BPC in FDI rx is consistent with that in PIPECONF */
3806 temp &= ~(0x07 << 16);
3807 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
3808 I915_WRITE(reg, temp);
3814 bool intel_has_pending_fb_unpin(struct drm_device *dev)
3816 struct intel_crtc *crtc;
3818 /* Note that we don't need to be called with mode_config.lock here
3819 * as our list of CRTC objects is static for the lifetime of the
3820 * device and so cannot disappear as we iterate. Similarly, we can
3821 * happily treat the predicates as racy, atomic checks as userspace
3822 * cannot claim and pin a new fb without at least acquring the
3823 * struct_mutex and so serialising with us.
3825 for_each_intel_crtc(dev, crtc) {
3826 if (atomic_read(&crtc->unpin_work_count) == 0)
3829 if (crtc->unpin_work)
3830 intel_wait_for_vblank(dev, crtc->pipe);
3838 static void page_flip_completed(struct intel_crtc *intel_crtc)
3840 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
3841 struct intel_unpin_work *work = intel_crtc->unpin_work;
3843 /* ensure that the unpin work is consistent wrt ->pending. */
3845 intel_crtc->unpin_work = NULL;
3848 drm_send_vblank_event(intel_crtc->base.dev,
3852 drm_crtc_vblank_put(&intel_crtc->base);
3854 wake_up_all(&dev_priv->pending_flip_queue);
3855 queue_work(dev_priv->wq, &work->work);
3857 trace_i915_flip_complete(intel_crtc->plane,
3858 work->pending_flip_obj);
3861 void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
3863 struct drm_device *dev = crtc->dev;
3864 struct drm_i915_private *dev_priv = dev->dev_private;
3866 WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
3867 if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue,
3868 !intel_crtc_has_pending_flip(crtc),
3870 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3872 spin_lock_irq(&dev->event_lock);
3873 if (intel_crtc->unpin_work) {
3874 WARN_ONCE(1, "Removing stuck page flip\n");
3875 page_flip_completed(intel_crtc);
3877 spin_unlock_irq(&dev->event_lock);
3880 if (crtc->primary->fb) {
3881 mutex_lock(&dev->struct_mutex);
3882 intel_finish_fb(crtc->primary->fb);
3883 mutex_unlock(&dev->struct_mutex);
3887 /* Program iCLKIP clock to the desired frequency */
3888 static void lpt_program_iclkip(struct drm_crtc *crtc)
3890 struct drm_device *dev = crtc->dev;
3891 struct drm_i915_private *dev_priv = dev->dev_private;
3892 int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock;
3893 u32 divsel, phaseinc, auxdiv, phasedir = 0;
3896 mutex_lock(&dev_priv->sb_lock);
3898 /* It is necessary to ungate the pixclk gate prior to programming
3899 * the divisors, and gate it back when it is done.
3901 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
3903 /* Disable SSCCTL */
3904 intel_sbi_write(dev_priv, SBI_SSCCTL6,
3905 intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
3909 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
3910 if (clock == 20000) {
3915 /* The iCLK virtual clock root frequency is in MHz,
3916 * but the adjusted_mode->crtc_clock in in KHz. To get the
3917 * divisors, it is necessary to divide one by another, so we
3918 * convert the virtual clock precision to KHz here for higher
3921 u32 iclk_virtual_root_freq = 172800 * 1000;
3922 u32 iclk_pi_range = 64;
3923 u32 desired_divisor, msb_divisor_value, pi_value;
3925 desired_divisor = (iclk_virtual_root_freq / clock);
3926 msb_divisor_value = desired_divisor / iclk_pi_range;
3927 pi_value = desired_divisor % iclk_pi_range;
3930 divsel = msb_divisor_value - 2;
3931 phaseinc = pi_value;
3934 /* This should not happen with any sane values */
3935 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
3936 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
3937 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
3938 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
3940 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3947 /* Program SSCDIVINTPHASE6 */
3948 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
3949 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
3950 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
3951 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
3952 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
3953 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
3954 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
3955 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
3957 /* Program SSCAUXDIV */
3958 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
3959 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3960 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
3961 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
3963 /* Enable modulator and associated divider */
3964 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
3965 temp &= ~SBI_SSCCTL_DISABLE;
3966 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
3968 /* Wait for initialization time */
3971 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
3973 mutex_unlock(&dev_priv->sb_lock);
3976 static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
3977 enum pipe pch_transcoder)
3979 struct drm_device *dev = crtc->base.dev;
3980 struct drm_i915_private *dev_priv = dev->dev_private;
3981 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
3983 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
3984 I915_READ(HTOTAL(cpu_transcoder)));
3985 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
3986 I915_READ(HBLANK(cpu_transcoder)));
3987 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
3988 I915_READ(HSYNC(cpu_transcoder)));
3990 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
3991 I915_READ(VTOTAL(cpu_transcoder)));
3992 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
3993 I915_READ(VBLANK(cpu_transcoder)));
3994 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
3995 I915_READ(VSYNC(cpu_transcoder)));
3996 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
3997 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4000 static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable)
4002 struct drm_i915_private *dev_priv = dev->dev_private;
4005 temp = I915_READ(SOUTH_CHICKEN1);
4006 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
4009 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4010 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4012 temp &= ~FDI_BC_BIFURCATION_SELECT;
4014 temp |= FDI_BC_BIFURCATION_SELECT;
4016 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
4017 I915_WRITE(SOUTH_CHICKEN1, temp);
4018 POSTING_READ(SOUTH_CHICKEN1);
4021 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
4023 struct drm_device *dev = intel_crtc->base.dev;
4025 switch (intel_crtc->pipe) {
4029 if (intel_crtc->config->fdi_lanes > 2)
4030 cpt_set_fdi_bc_bifurcation(dev, false);
4032 cpt_set_fdi_bc_bifurcation(dev, true);
4036 cpt_set_fdi_bc_bifurcation(dev, true);
4045 * Enable PCH resources required for PCH ports:
4047 * - FDI training & RX/TX
4048 * - update transcoder timings
4049 * - DP transcoding bits
4052 static void ironlake_pch_enable(struct drm_crtc *crtc)
4054 struct drm_device *dev = crtc->dev;
4055 struct drm_i915_private *dev_priv = dev->dev_private;
4056 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4057 int pipe = intel_crtc->pipe;
4060 assert_pch_transcoder_disabled(dev_priv, pipe);
4062 if (IS_IVYBRIDGE(dev))
4063 ivybridge_update_fdi_bc_bifurcation(intel_crtc);
4065 /* Write the TU size bits before fdi link training, so that error
4066 * detection works. */
4067 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4068 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4070 /* For PCH output, training FDI link */
4071 dev_priv->display.fdi_link_train(crtc);
4073 /* We need to program the right clock selection before writing the pixel
4074 * mutliplier into the DPLL. */
4075 if (HAS_PCH_CPT(dev)) {
4078 temp = I915_READ(PCH_DPLL_SEL);
4079 temp |= TRANS_DPLL_ENABLE(pipe);
4080 sel = TRANS_DPLLB_SEL(pipe);
4081 if (intel_crtc->config->shared_dpll == DPLL_ID_PCH_PLL_B)
4085 I915_WRITE(PCH_DPLL_SEL, temp);
4088 /* XXX: pch pll's can be enabled any time before we enable the PCH
4089 * transcoder, and we actually should do this to not upset any PCH
4090 * transcoder that already use the clock when we share it.
4092 * Note that enable_shared_dpll tries to do the right thing, but
4093 * get_shared_dpll unconditionally resets the pll - we need that to have
4094 * the right LVDS enable sequence. */
4095 intel_enable_shared_dpll(intel_crtc);
4097 /* set transcoder timing, panel must allow it */
4098 assert_panel_unlocked(dev_priv, pipe);
4099 ironlake_pch_transcoder_set_timings(intel_crtc, pipe);
4101 intel_fdi_normal_train(crtc);
4103 /* For PCH DP, enable TRANS_DP_CTL */
4104 if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) {
4105 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
4106 reg = TRANS_DP_CTL(pipe);
4107 temp = I915_READ(reg);
4108 temp &= ~(TRANS_DP_PORT_SEL_MASK |
4109 TRANS_DP_SYNC_MASK |
4111 temp |= TRANS_DP_OUTPUT_ENABLE;
4112 temp |= bpc << 9; /* same format but at 11:9 */
4114 if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
4115 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
4116 if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
4117 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
4119 switch (intel_trans_dp_port_sel(crtc)) {
4121 temp |= TRANS_DP_PORT_SEL_B;
4124 temp |= TRANS_DP_PORT_SEL_C;
4127 temp |= TRANS_DP_PORT_SEL_D;
4133 I915_WRITE(reg, temp);
4136 ironlake_enable_pch_transcoder(dev_priv, pipe);
4139 static void lpt_pch_enable(struct drm_crtc *crtc)
4141 struct drm_device *dev = crtc->dev;
4142 struct drm_i915_private *dev_priv = dev->dev_private;
4143 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4144 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
4146 assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A);
4148 lpt_program_iclkip(crtc);
4150 /* Set transcoder timing. */
4151 ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A);
4153 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
4156 struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc,
4157 struct intel_crtc_state *crtc_state)
4159 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
4160 struct intel_shared_dpll *pll;
4161 struct intel_shared_dpll_config *shared_dpll;
4162 enum intel_dpll_id i;
4164 shared_dpll = intel_atomic_get_shared_dpll_state(crtc_state->base.state);
4166 if (HAS_PCH_IBX(dev_priv->dev)) {
4167 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
4168 i = (enum intel_dpll_id) crtc->pipe;
4169 pll = &dev_priv->shared_dplls[i];
4171 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
4172 crtc->base.base.id, pll->name);
4174 WARN_ON(shared_dpll[i].crtc_mask);
4179 if (IS_BROXTON(dev_priv->dev)) {
4180 /* PLL is attached to port in bxt */
4181 struct intel_encoder *encoder;
4182 struct intel_digital_port *intel_dig_port;
4184 encoder = intel_ddi_get_crtc_new_encoder(crtc_state);
4185 if (WARN_ON(!encoder))
4188 intel_dig_port = enc_to_dig_port(&encoder->base);
4189 /* 1:1 mapping between ports and PLLs */
4190 i = (enum intel_dpll_id)intel_dig_port->port;
4191 pll = &dev_priv->shared_dplls[i];
4192 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
4193 crtc->base.base.id, pll->name);
4194 WARN_ON(shared_dpll[i].crtc_mask);
4199 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
4200 pll = &dev_priv->shared_dplls[i];
4202 /* Only want to check enabled timings first */
4203 if (shared_dpll[i].crtc_mask == 0)
4206 if (memcmp(&crtc_state->dpll_hw_state,
4207 &shared_dpll[i].hw_state,
4208 sizeof(crtc_state->dpll_hw_state)) == 0) {
4209 DRM_DEBUG_KMS("CRTC:%d sharing existing %s (crtc mask 0x%08x, ative %d)\n",
4210 crtc->base.base.id, pll->name,
4211 shared_dpll[i].crtc_mask,
4217 /* Ok no matching timings, maybe there's a free one? */
4218 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
4219 pll = &dev_priv->shared_dplls[i];
4220 if (shared_dpll[i].crtc_mask == 0) {
4221 DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
4222 crtc->base.base.id, pll->name);
4230 if (shared_dpll[i].crtc_mask == 0)
4231 shared_dpll[i].hw_state =
4232 crtc_state->dpll_hw_state;
4234 crtc_state->shared_dpll = i;
4235 DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name,
4236 pipe_name(crtc->pipe));
4238 shared_dpll[i].crtc_mask |= 1 << crtc->pipe;
4243 static void intel_shared_dpll_commit(struct drm_atomic_state *state)
4245 struct drm_i915_private *dev_priv = to_i915(state->dev);
4246 struct intel_shared_dpll_config *shared_dpll;
4247 struct intel_shared_dpll *pll;
4248 enum intel_dpll_id i;
4250 if (!to_intel_atomic_state(state)->dpll_set)
4253 shared_dpll = to_intel_atomic_state(state)->shared_dpll;
4254 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
4255 pll = &dev_priv->shared_dplls[i];
4256 pll->config = shared_dpll[i];
4260 static void cpt_verify_modeset(struct drm_device *dev, int pipe)
4262 struct drm_i915_private *dev_priv = dev->dev_private;
4263 int dslreg = PIPEDSL(pipe);
4266 temp = I915_READ(dslreg);
4268 if (wait_for(I915_READ(dslreg) != temp, 5)) {
4269 if (wait_for(I915_READ(dslreg) != temp, 5))
4270 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
4275 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
4276 unsigned scaler_user, int *scaler_id, unsigned int rotation,
4277 int src_w, int src_h, int dst_w, int dst_h)
4279 struct intel_crtc_scaler_state *scaler_state =
4280 &crtc_state->scaler_state;
4281 struct intel_crtc *intel_crtc =
4282 to_intel_crtc(crtc_state->base.crtc);
4285 need_scaling = intel_rotation_90_or_270(rotation) ?
4286 (src_h != dst_w || src_w != dst_h):
4287 (src_w != dst_w || src_h != dst_h);
4290 * if plane is being disabled or scaler is no more required or force detach
4291 * - free scaler binded to this plane/crtc
4292 * - in order to do this, update crtc->scaler_usage
4294 * Here scaler state in crtc_state is set free so that
4295 * scaler can be assigned to other user. Actual register
4296 * update to free the scaler is done in plane/panel-fit programming.
4297 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4299 if (force_detach || !need_scaling) {
4300 if (*scaler_id >= 0) {
4301 scaler_state->scaler_users &= ~(1 << scaler_user);
4302 scaler_state->scalers[*scaler_id].in_use = 0;
4304 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4305 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4306 intel_crtc->pipe, scaler_user, *scaler_id,
4307 scaler_state->scaler_users);
4314 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
4315 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
4317 src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
4318 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) {
4319 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4320 "size is out of scaler range\n",
4321 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
4325 /* mark this plane as a scaler user in crtc_state */
4326 scaler_state->scaler_users |= (1 << scaler_user);
4327 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4328 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4329 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
4330 scaler_state->scaler_users);
4336 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4338 * @state: crtc's scaler state
4341 * 0 - scaler_usage updated successfully
4342 * error - requested scaling cannot be supported or other error condition
4344 int skl_update_scaler_crtc(struct intel_crtc_state *state)
4346 struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc);
4347 struct drm_display_mode *adjusted_mode =
4348 &state->base.adjusted_mode;
4350 DRM_DEBUG_KMS("Updating scaler for [CRTC:%i] scaler_user index %u.%u\n",
4351 intel_crtc->base.base.id, intel_crtc->pipe, SKL_CRTC_INDEX);
4353 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
4354 &state->scaler_state.scaler_id, DRM_ROTATE_0,
4355 state->pipe_src_w, state->pipe_src_h,
4356 adjusted_mode->hdisplay, adjusted_mode->vdisplay);
4360 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4362 * @state: crtc's scaler state
4363 * @plane_state: atomic plane state to update
4366 * 0 - scaler_usage updated successfully
4367 * error - requested scaling cannot be supported or other error condition
4369 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
4370 struct intel_plane_state *plane_state)
4373 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4374 struct intel_plane *intel_plane =
4375 to_intel_plane(plane_state->base.plane);
4376 struct drm_framebuffer *fb = plane_state->base.fb;
4379 bool force_detach = !fb || !plane_state->visible;
4381 DRM_DEBUG_KMS("Updating scaler for [PLANE:%d] scaler_user index %u.%u\n",
4382 intel_plane->base.base.id, intel_crtc->pipe,
4383 drm_plane_index(&intel_plane->base));
4385 ret = skl_update_scaler(crtc_state, force_detach,
4386 drm_plane_index(&intel_plane->base),
4387 &plane_state->scaler_id,
4388 plane_state->base.rotation,
4389 drm_rect_width(&plane_state->src) >> 16,
4390 drm_rect_height(&plane_state->src) >> 16,
4391 drm_rect_width(&plane_state->dst),
4392 drm_rect_height(&plane_state->dst));
4394 if (ret || plane_state->scaler_id < 0)
4397 /* check colorkey */
4398 if (plane_state->ckey.flags != I915_SET_COLORKEY_NONE) {
4399 DRM_DEBUG_KMS("[PLANE:%d] scaling with color key not allowed",
4400 intel_plane->base.base.id);
4404 /* Check src format */
4405 switch (fb->pixel_format) {
4406 case DRM_FORMAT_RGB565:
4407 case DRM_FORMAT_XBGR8888:
4408 case DRM_FORMAT_XRGB8888:
4409 case DRM_FORMAT_ABGR8888:
4410 case DRM_FORMAT_ARGB8888:
4411 case DRM_FORMAT_XRGB2101010:
4412 case DRM_FORMAT_XBGR2101010:
4413 case DRM_FORMAT_YUYV:
4414 case DRM_FORMAT_YVYU:
4415 case DRM_FORMAT_UYVY:
4416 case DRM_FORMAT_VYUY:
4419 DRM_DEBUG_KMS("[PLANE:%d] FB:%d unsupported scaling format 0x%x\n",
4420 intel_plane->base.base.id, fb->base.id, fb->pixel_format);
4427 static void skylake_scaler_disable(struct intel_crtc *crtc)
4431 for (i = 0; i < crtc->num_scalers; i++)
4432 skl_detach_scaler(crtc, i);
4435 static void skylake_pfit_enable(struct intel_crtc *crtc)
4437 struct drm_device *dev = crtc->base.dev;
4438 struct drm_i915_private *dev_priv = dev->dev_private;
4439 int pipe = crtc->pipe;
4440 struct intel_crtc_scaler_state *scaler_state =
4441 &crtc->config->scaler_state;
4443 DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config);
4445 if (crtc->config->pch_pfit.enabled) {
4448 if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) {
4449 DRM_ERROR("Requesting pfit without getting a scaler first\n");
4453 id = scaler_state->scaler_id;
4454 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
4455 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
4456 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos);
4457 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size);
4459 DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc->config, id);
4463 static void ironlake_pfit_enable(struct intel_crtc *crtc)
4465 struct drm_device *dev = crtc->base.dev;
4466 struct drm_i915_private *dev_priv = dev->dev_private;
4467 int pipe = crtc->pipe;
4469 if (crtc->config->pch_pfit.enabled) {
4470 /* Force use of hard-coded filter coefficients
4471 * as some pre-programmed values are broken,
4474 if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
4475 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
4476 PF_PIPE_SEL_IVB(pipe));
4478 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
4479 I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos);
4480 I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size);
4484 void hsw_enable_ips(struct intel_crtc *crtc)
4486 struct drm_device *dev = crtc->base.dev;
4487 struct drm_i915_private *dev_priv = dev->dev_private;
4489 if (!crtc->config->ips_enabled)
4492 /* We can only enable IPS after we enable a plane and wait for a vblank */
4493 intel_wait_for_vblank(dev, crtc->pipe);
4495 assert_plane_enabled(dev_priv, crtc->plane);
4496 if (IS_BROADWELL(dev)) {
4497 mutex_lock(&dev_priv->rps.hw_lock);
4498 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000));
4499 mutex_unlock(&dev_priv->rps.hw_lock);
4500 /* Quoting Art Runyan: "its not safe to expect any particular
4501 * value in IPS_CTL bit 31 after enabling IPS through the
4502 * mailbox." Moreover, the mailbox may return a bogus state,
4503 * so we need to just enable it and continue on.
4506 I915_WRITE(IPS_CTL, IPS_ENABLE);
4507 /* The bit only becomes 1 in the next vblank, so this wait here
4508 * is essentially intel_wait_for_vblank. If we don't have this
4509 * and don't wait for vblanks until the end of crtc_enable, then
4510 * the HW state readout code will complain that the expected
4511 * IPS_CTL value is not the one we read. */
4512 if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50))
4513 DRM_ERROR("Timed out waiting for IPS enable\n");
4517 void hsw_disable_ips(struct intel_crtc *crtc)
4519 struct drm_device *dev = crtc->base.dev;
4520 struct drm_i915_private *dev_priv = dev->dev_private;
4522 if (!crtc->config->ips_enabled)
4525 assert_plane_enabled(dev_priv, crtc->plane);
4526 if (IS_BROADWELL(dev)) {
4527 mutex_lock(&dev_priv->rps.hw_lock);
4528 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
4529 mutex_unlock(&dev_priv->rps.hw_lock);
4530 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4531 if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42))
4532 DRM_ERROR("Timed out waiting for IPS disable\n");
4534 I915_WRITE(IPS_CTL, 0);
4535 POSTING_READ(IPS_CTL);
4538 /* We need to wait for a vblank before we can disable the plane. */
4539 intel_wait_for_vblank(dev, crtc->pipe);
4542 /** Loads the palette/gamma unit for the CRTC with the prepared values */
4543 static void intel_crtc_load_lut(struct drm_crtc *crtc)
4545 struct drm_device *dev = crtc->dev;
4546 struct drm_i915_private *dev_priv = dev->dev_private;
4547 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4548 enum pipe pipe = intel_crtc->pipe;
4549 int palreg = PALETTE(pipe);
4551 bool reenable_ips = false;
4553 /* The clocks have to be on to load the palette. */
4554 if (!crtc->state->active)
4557 if (HAS_GMCH_DISPLAY(dev_priv->dev)) {
4558 if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI))
4559 assert_dsi_pll_enabled(dev_priv);
4561 assert_pll_enabled(dev_priv, pipe);
4564 /* use legacy palette for Ironlake */
4565 if (!HAS_GMCH_DISPLAY(dev))
4566 palreg = LGC_PALETTE(pipe);
4568 /* Workaround : Do not read or write the pipe palette/gamma data while
4569 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
4571 if (IS_HASWELL(dev) && intel_crtc->config->ips_enabled &&
4572 ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) ==
4573 GAMMA_MODE_MODE_SPLIT)) {
4574 hsw_disable_ips(intel_crtc);
4575 reenable_ips = true;
4578 for (i = 0; i < 256; i++) {
4579 I915_WRITE(palreg + 4 * i,
4580 (intel_crtc->lut_r[i] << 16) |
4581 (intel_crtc->lut_g[i] << 8) |
4582 intel_crtc->lut_b[i]);
4586 hsw_enable_ips(intel_crtc);
4589 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
4591 if (intel_crtc->overlay) {
4592 struct drm_device *dev = intel_crtc->base.dev;
4593 struct drm_i915_private *dev_priv = dev->dev_private;
4595 mutex_lock(&dev->struct_mutex);
4596 dev_priv->mm.interruptible = false;
4597 (void) intel_overlay_switch_off(intel_crtc->overlay);
4598 dev_priv->mm.interruptible = true;
4599 mutex_unlock(&dev->struct_mutex);
4602 /* Let userspace switch the overlay on again. In most cases userspace
4603 * has to recompute where to put it anyway.
4608 * intel_post_enable_primary - Perform operations after enabling primary plane
4609 * @crtc: the CRTC whose primary plane was just enabled
4611 * Performs potentially sleeping operations that must be done after the primary
4612 * plane is enabled, such as updating FBC and IPS. Note that this may be
4613 * called due to an explicit primary plane update, or due to an implicit
4614 * re-enable that is caused when a sprite plane is updated to no longer
4615 * completely hide the primary plane.
4618 intel_post_enable_primary(struct drm_crtc *crtc)
4620 struct drm_device *dev = crtc->dev;
4621 struct drm_i915_private *dev_priv = dev->dev_private;
4622 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4623 int pipe = intel_crtc->pipe;
4626 * BDW signals flip done immediately if the plane
4627 * is disabled, even if the plane enable is already
4628 * armed to occur at the next vblank :(
4630 if (IS_BROADWELL(dev))
4631 intel_wait_for_vblank(dev, pipe);
4634 * FIXME IPS should be fine as long as one plane is
4635 * enabled, but in practice it seems to have problems
4636 * when going from primary only to sprite only and vice
4639 hsw_enable_ips(intel_crtc);
4642 * Gen2 reports pipe underruns whenever all planes are disabled.
4643 * So don't enable underrun reporting before at least some planes
4645 * FIXME: Need to fix the logic to work when we turn off all planes
4646 * but leave the pipe running.
4649 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
4651 /* Underruns don't raise interrupts, so check manually. */
4652 if (HAS_GMCH_DISPLAY(dev))
4653 i9xx_check_fifo_underruns(dev_priv);
4657 * intel_pre_disable_primary - Perform operations before disabling primary plane
4658 * @crtc: the CRTC whose primary plane is to be disabled
4660 * Performs potentially sleeping operations that must be done before the
4661 * primary plane is disabled, such as updating FBC and IPS. Note that this may
4662 * be called due to an explicit primary plane update, or due to an implicit
4663 * disable that is caused when a sprite plane completely hides the primary
4667 intel_pre_disable_primary(struct drm_crtc *crtc)
4669 struct drm_device *dev = crtc->dev;
4670 struct drm_i915_private *dev_priv = dev->dev_private;
4671 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4672 int pipe = intel_crtc->pipe;
4675 * Gen2 reports pipe underruns whenever all planes are disabled.
4676 * So diasble underrun reporting before all the planes get disabled.
4677 * FIXME: Need to fix the logic to work when we turn off all planes
4678 * but leave the pipe running.
4681 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
4684 * Vblank time updates from the shadow to live plane control register
4685 * are blocked if the memory self-refresh mode is active at that
4686 * moment. So to make sure the plane gets truly disabled, disable
4687 * first the self-refresh mode. The self-refresh enable bit in turn
4688 * will be checked/applied by the HW only at the next frame start
4689 * event which is after the vblank start event, so we need to have a
4690 * wait-for-vblank between disabling the plane and the pipe.
4692 if (HAS_GMCH_DISPLAY(dev)) {
4693 intel_set_memory_cxsr(dev_priv, false);
4694 dev_priv->wm.vlv.cxsr = false;
4695 intel_wait_for_vblank(dev, pipe);
4699 * FIXME IPS should be fine as long as one plane is
4700 * enabled, but in practice it seems to have problems
4701 * when going from primary only to sprite only and vice
4704 hsw_disable_ips(intel_crtc);
4707 static void intel_post_plane_update(struct intel_crtc *crtc)
4709 struct intel_crtc_atomic_commit *atomic = &crtc->atomic;
4710 struct drm_device *dev = crtc->base.dev;
4711 struct drm_i915_private *dev_priv = dev->dev_private;
4712 struct drm_plane *plane;
4714 if (atomic->wait_vblank)
4715 intel_wait_for_vblank(dev, crtc->pipe);
4717 intel_frontbuffer_flip(dev, atomic->fb_bits);
4719 if (atomic->disable_cxsr)
4720 crtc->wm.cxsr_allowed = true;
4722 if (crtc->atomic.update_wm_post)
4723 intel_update_watermarks(&crtc->base);
4725 if (atomic->update_fbc)
4726 intel_fbc_update(dev_priv);
4728 if (atomic->post_enable_primary)
4729 intel_post_enable_primary(&crtc->base);
4731 drm_for_each_plane_mask(plane, dev, atomic->update_sprite_watermarks)
4732 intel_update_sprite_watermarks(plane, &crtc->base,
4733 0, 0, 0, false, false);
4735 memset(atomic, 0, sizeof(*atomic));
4738 static void intel_pre_plane_update(struct intel_crtc *crtc)
4740 struct drm_device *dev = crtc->base.dev;
4741 struct drm_i915_private *dev_priv = dev->dev_private;
4742 struct intel_crtc_atomic_commit *atomic = &crtc->atomic;
4743 struct drm_plane *p;
4745 /* Track fb's for any planes being disabled */
4746 drm_for_each_plane_mask(p, dev, atomic->disabled_planes) {
4747 struct intel_plane *plane = to_intel_plane(p);
4749 mutex_lock(&dev->struct_mutex);
4750 i915_gem_track_fb(intel_fb_obj(plane->base.fb), NULL,
4751 plane->frontbuffer_bit);
4752 mutex_unlock(&dev->struct_mutex);
4755 if (atomic->wait_for_flips)
4756 intel_crtc_wait_for_pending_flips(&crtc->base);
4758 if (atomic->disable_fbc)
4759 intel_fbc_disable_crtc(crtc);
4761 if (crtc->atomic.disable_ips)
4762 hsw_disable_ips(crtc);
4764 if (atomic->pre_disable_primary)
4765 intel_pre_disable_primary(&crtc->base);
4767 if (atomic->disable_cxsr) {
4768 crtc->wm.cxsr_allowed = false;
4769 intel_set_memory_cxsr(dev_priv, false);
4773 static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask)
4775 struct drm_device *dev = crtc->dev;
4776 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4777 struct drm_plane *p;
4778 int pipe = intel_crtc->pipe;
4780 intel_crtc_dpms_overlay_disable(intel_crtc);
4782 drm_for_each_plane_mask(p, dev, plane_mask)
4783 to_intel_plane(p)->disable_plane(p, crtc);
4786 * FIXME: Once we grow proper nuclear flip support out of this we need
4787 * to compute the mask of flip planes precisely. For the time being
4788 * consider this a flip to a NULL plane.
4790 intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
4793 static void ironlake_crtc_enable(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 struct intel_encoder *encoder;
4799 int pipe = intel_crtc->pipe;
4801 if (WARN_ON(intel_crtc->active))
4804 if (intel_crtc->config->has_pch_encoder)
4805 intel_prepare_shared_dpll(intel_crtc);
4807 if (intel_crtc->config->has_dp_encoder)
4808 intel_dp_set_m_n(intel_crtc, M1_N1);
4810 intel_set_pipe_timings(intel_crtc);
4812 if (intel_crtc->config->has_pch_encoder) {
4813 intel_cpu_transcoder_set_m_n(intel_crtc,
4814 &intel_crtc->config->fdi_m_n, NULL);
4817 ironlake_set_pipeconf(crtc);
4819 intel_crtc->active = true;
4821 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
4822 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
4824 for_each_encoder_on_crtc(dev, crtc, encoder)
4825 if (encoder->pre_enable)
4826 encoder->pre_enable(encoder);
4828 if (intel_crtc->config->has_pch_encoder) {
4829 /* Note: FDI PLL enabling _must_ be done before we enable the
4830 * cpu pipes, hence this is separate from all the other fdi/pch
4832 ironlake_fdi_pll_enable(intel_crtc);
4834 assert_fdi_tx_disabled(dev_priv, pipe);
4835 assert_fdi_rx_disabled(dev_priv, pipe);
4838 ironlake_pfit_enable(intel_crtc);
4841 * On ILK+ LUT must be loaded before the pipe is running but with
4844 intel_crtc_load_lut(crtc);
4846 intel_update_watermarks(crtc);
4847 intel_enable_pipe(intel_crtc);
4849 if (intel_crtc->config->has_pch_encoder)
4850 ironlake_pch_enable(crtc);
4852 assert_vblank_disabled(crtc);
4853 drm_crtc_vblank_on(crtc);
4855 for_each_encoder_on_crtc(dev, crtc, encoder)
4856 encoder->enable(encoder);
4858 if (HAS_PCH_CPT(dev))
4859 cpt_verify_modeset(dev, intel_crtc->pipe);
4862 /* IPS only exists on ULT machines and is tied to pipe A. */
4863 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
4865 return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A;
4868 static void haswell_crtc_enable(struct drm_crtc *crtc)
4870 struct drm_device *dev = crtc->dev;
4871 struct drm_i915_private *dev_priv = dev->dev_private;
4872 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4873 struct intel_encoder *encoder;
4874 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
4875 struct intel_crtc_state *pipe_config =
4876 to_intel_crtc_state(crtc->state);
4878 if (WARN_ON(intel_crtc->active))
4881 if (intel_crtc_to_shared_dpll(intel_crtc))
4882 intel_enable_shared_dpll(intel_crtc);
4884 if (intel_crtc->config->has_dp_encoder)
4885 intel_dp_set_m_n(intel_crtc, M1_N1);
4887 intel_set_pipe_timings(intel_crtc);
4889 if (intel_crtc->config->cpu_transcoder != TRANSCODER_EDP) {
4890 I915_WRITE(PIPE_MULT(intel_crtc->config->cpu_transcoder),
4891 intel_crtc->config->pixel_multiplier - 1);
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 haswell_set_pipeconf(crtc);
4901 intel_set_pipe_csc(crtc);
4903 intel_crtc->active = true;
4905 intel_set_cpu_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 intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A,
4913 dev_priv->display.fdi_link_train(crtc);
4916 intel_ddi_enable_pipe_clock(intel_crtc);
4918 if (INTEL_INFO(dev)->gen == 9)
4919 skylake_pfit_enable(intel_crtc);
4920 else if (INTEL_INFO(dev)->gen < 9)
4921 ironlake_pfit_enable(intel_crtc);
4923 MISSING_CASE(INTEL_INFO(dev)->gen);
4926 * On ILK+ LUT must be loaded before the pipe is running but with
4929 intel_crtc_load_lut(crtc);
4931 intel_ddi_set_pipe_settings(crtc);
4932 intel_ddi_enable_transcoder_func(crtc);
4934 intel_update_watermarks(crtc);
4935 intel_enable_pipe(intel_crtc);
4937 if (intel_crtc->config->has_pch_encoder)
4938 lpt_pch_enable(crtc);
4940 if (intel_crtc->config->dp_encoder_is_mst)
4941 intel_ddi_set_vc_payload_alloc(crtc, true);
4943 assert_vblank_disabled(crtc);
4944 drm_crtc_vblank_on(crtc);
4946 for_each_encoder_on_crtc(dev, crtc, encoder) {
4947 encoder->enable(encoder);
4948 intel_opregion_notify_encoder(encoder, true);
4951 /* If we change the relative order between pipe/planes enabling, we need
4952 * to change the workaround. */
4953 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
4954 if (IS_HASWELL(dev) && hsw_workaround_pipe != INVALID_PIPE) {
4955 intel_wait_for_vblank(dev, hsw_workaround_pipe);
4956 intel_wait_for_vblank(dev, hsw_workaround_pipe);
4960 static void ironlake_pfit_disable(struct intel_crtc *crtc)
4962 struct drm_device *dev = crtc->base.dev;
4963 struct drm_i915_private *dev_priv = dev->dev_private;
4964 int pipe = crtc->pipe;
4966 /* To avoid upsetting the power well on haswell only disable the pfit if
4967 * it's in use. The hw state code will make sure we get this right. */
4968 if (crtc->config->pch_pfit.enabled) {
4969 I915_WRITE(PF_CTL(pipe), 0);
4970 I915_WRITE(PF_WIN_POS(pipe), 0);
4971 I915_WRITE(PF_WIN_SZ(pipe), 0);
4975 static void ironlake_crtc_disable(struct drm_crtc *crtc)
4977 struct drm_device *dev = crtc->dev;
4978 struct drm_i915_private *dev_priv = dev->dev_private;
4979 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4980 struct intel_encoder *encoder;
4981 int pipe = intel_crtc->pipe;
4984 for_each_encoder_on_crtc(dev, crtc, encoder)
4985 encoder->disable(encoder);
4987 drm_crtc_vblank_off(crtc);
4988 assert_vblank_disabled(crtc);
4990 if (intel_crtc->config->has_pch_encoder)
4991 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
4993 intel_disable_pipe(intel_crtc);
4995 ironlake_pfit_disable(intel_crtc);
4997 if (intel_crtc->config->has_pch_encoder)
4998 ironlake_fdi_disable(crtc);
5000 for_each_encoder_on_crtc(dev, crtc, encoder)
5001 if (encoder->post_disable)
5002 encoder->post_disable(encoder);
5004 if (intel_crtc->config->has_pch_encoder) {
5005 ironlake_disable_pch_transcoder(dev_priv, pipe);
5007 if (HAS_PCH_CPT(dev)) {
5008 /* disable TRANS_DP_CTL */
5009 reg = TRANS_DP_CTL(pipe);
5010 temp = I915_READ(reg);
5011 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
5012 TRANS_DP_PORT_SEL_MASK);
5013 temp |= TRANS_DP_PORT_SEL_NONE;
5014 I915_WRITE(reg, temp);
5016 /* disable DPLL_SEL */
5017 temp = I915_READ(PCH_DPLL_SEL);
5018 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
5019 I915_WRITE(PCH_DPLL_SEL, temp);
5022 ironlake_fdi_pll_disable(intel_crtc);
5025 intel_crtc->active = false;
5026 intel_update_watermarks(crtc);
5029 static void haswell_crtc_disable(struct drm_crtc *crtc)
5031 struct drm_device *dev = crtc->dev;
5032 struct drm_i915_private *dev_priv = dev->dev_private;
5033 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5034 struct intel_encoder *encoder;
5035 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
5037 for_each_encoder_on_crtc(dev, crtc, encoder) {
5038 intel_opregion_notify_encoder(encoder, false);
5039 encoder->disable(encoder);
5042 drm_crtc_vblank_off(crtc);
5043 assert_vblank_disabled(crtc);
5045 if (intel_crtc->config->has_pch_encoder)
5046 intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A,
5048 intel_disable_pipe(intel_crtc);
5050 if (intel_crtc->config->dp_encoder_is_mst)
5051 intel_ddi_set_vc_payload_alloc(crtc, false);
5053 intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
5055 if (INTEL_INFO(dev)->gen == 9)
5056 skylake_scaler_disable(intel_crtc);
5057 else if (INTEL_INFO(dev)->gen < 9)
5058 ironlake_pfit_disable(intel_crtc);
5060 MISSING_CASE(INTEL_INFO(dev)->gen);
5062 intel_ddi_disable_pipe_clock(intel_crtc);
5064 if (intel_crtc->config->has_pch_encoder) {
5065 lpt_disable_pch_transcoder(dev_priv);
5066 intel_ddi_fdi_disable(crtc);
5069 for_each_encoder_on_crtc(dev, crtc, encoder)
5070 if (encoder->post_disable)
5071 encoder->post_disable(encoder);
5073 intel_crtc->active = false;
5074 intel_update_watermarks(crtc);
5077 static void i9xx_pfit_enable(struct intel_crtc *crtc)
5079 struct drm_device *dev = crtc->base.dev;
5080 struct drm_i915_private *dev_priv = dev->dev_private;
5081 struct intel_crtc_state *pipe_config = crtc->config;
5083 if (!pipe_config->gmch_pfit.control)
5087 * The panel fitter should only be adjusted whilst the pipe is disabled,
5088 * according to register description and PRM.
5090 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
5091 assert_pipe_disabled(dev_priv, crtc->pipe);
5093 I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
5094 I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
5096 /* Border color in case we don't scale up to the full screen. Black by
5097 * default, change to something else for debugging. */
5098 I915_WRITE(BCLRPAT(crtc->pipe), 0);
5101 static enum intel_display_power_domain port_to_power_domain(enum port port)
5105 return POWER_DOMAIN_PORT_DDI_A_4_LANES;
5107 return POWER_DOMAIN_PORT_DDI_B_4_LANES;
5109 return POWER_DOMAIN_PORT_DDI_C_4_LANES;
5111 return POWER_DOMAIN_PORT_DDI_D_4_LANES;
5113 return POWER_DOMAIN_PORT_DDI_E_2_LANES;
5116 return POWER_DOMAIN_PORT_OTHER;
5120 #define for_each_power_domain(domain, mask) \
5121 for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
5122 if ((1 << (domain)) & (mask))
5124 enum intel_display_power_domain
5125 intel_display_port_power_domain(struct intel_encoder *intel_encoder)
5127 struct drm_device *dev = intel_encoder->base.dev;
5128 struct intel_digital_port *intel_dig_port;
5130 switch (intel_encoder->type) {
5131 case INTEL_OUTPUT_UNKNOWN:
5132 /* Only DDI platforms should ever use this output type */
5133 WARN_ON_ONCE(!HAS_DDI(dev));
5134 case INTEL_OUTPUT_DISPLAYPORT:
5135 case INTEL_OUTPUT_HDMI:
5136 case INTEL_OUTPUT_EDP:
5137 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
5138 return port_to_power_domain(intel_dig_port->port);
5139 case INTEL_OUTPUT_DP_MST:
5140 intel_dig_port = enc_to_mst(&intel_encoder->base)->primary;
5141 return port_to_power_domain(intel_dig_port->port);
5142 case INTEL_OUTPUT_ANALOG:
5143 return POWER_DOMAIN_PORT_CRT;
5144 case INTEL_OUTPUT_DSI:
5145 return POWER_DOMAIN_PORT_DSI;
5147 return POWER_DOMAIN_PORT_OTHER;
5151 static unsigned long get_crtc_power_domains(struct drm_crtc *crtc)
5153 struct drm_device *dev = crtc->dev;
5154 struct intel_encoder *intel_encoder;
5155 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5156 enum pipe pipe = intel_crtc->pipe;
5158 enum transcoder transcoder;
5160 if (!crtc->state->active)
5163 transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe);
5165 mask = BIT(POWER_DOMAIN_PIPE(pipe));
5166 mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder));
5167 if (intel_crtc->config->pch_pfit.enabled ||
5168 intel_crtc->config->pch_pfit.force_thru)
5169 mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
5171 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
5172 mask |= BIT(intel_display_port_power_domain(intel_encoder));
5177 static unsigned long modeset_get_crtc_power_domains(struct drm_crtc *crtc)
5179 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
5180 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5181 enum intel_display_power_domain domain;
5182 unsigned long domains, new_domains, old_domains;
5184 old_domains = intel_crtc->enabled_power_domains;
5185 intel_crtc->enabled_power_domains = new_domains = get_crtc_power_domains(crtc);
5187 domains = new_domains & ~old_domains;
5189 for_each_power_domain(domain, domains)
5190 intel_display_power_get(dev_priv, domain);
5192 return old_domains & ~new_domains;
5195 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
5196 unsigned long domains)
5198 enum intel_display_power_domain domain;
5200 for_each_power_domain(domain, domains)
5201 intel_display_power_put(dev_priv, domain);
5204 static void modeset_update_crtc_power_domains(struct drm_atomic_state *state)
5206 struct drm_device *dev = state->dev;
5207 struct drm_i915_private *dev_priv = dev->dev_private;
5208 unsigned long put_domains[I915_MAX_PIPES] = {};
5209 struct drm_crtc_state *crtc_state;
5210 struct drm_crtc *crtc;
5213 for_each_crtc_in_state(state, crtc, crtc_state, i) {
5214 if (needs_modeset(crtc->state))
5215 put_domains[to_intel_crtc(crtc)->pipe] =
5216 modeset_get_crtc_power_domains(crtc);
5219 if (dev_priv->display.modeset_commit_cdclk) {
5220 unsigned int cdclk = to_intel_atomic_state(state)->cdclk;
5222 if (cdclk != dev_priv->cdclk_freq &&
5223 !WARN_ON(!state->allow_modeset))
5224 dev_priv->display.modeset_commit_cdclk(state);
5227 for (i = 0; i < I915_MAX_PIPES; i++)
5229 modeset_put_power_domains(dev_priv, put_domains[i]);
5232 static int intel_compute_max_dotclk(struct drm_i915_private *dev_priv)
5234 int max_cdclk_freq = dev_priv->max_cdclk_freq;
5236 if (INTEL_INFO(dev_priv)->gen >= 9 ||
5237 IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
5238 return max_cdclk_freq;
5239 else if (IS_CHERRYVIEW(dev_priv))
5240 return max_cdclk_freq*95/100;
5241 else if (INTEL_INFO(dev_priv)->gen < 4)
5242 return 2*max_cdclk_freq*90/100;
5244 return max_cdclk_freq*90/100;
5247 static void intel_update_max_cdclk(struct drm_device *dev)
5249 struct drm_i915_private *dev_priv = dev->dev_private;
5251 if (IS_SKYLAKE(dev)) {
5252 u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK;
5254 if (limit == SKL_DFSM_CDCLK_LIMIT_675)
5255 dev_priv->max_cdclk_freq = 675000;
5256 else if (limit == SKL_DFSM_CDCLK_LIMIT_540)
5257 dev_priv->max_cdclk_freq = 540000;
5258 else if (limit == SKL_DFSM_CDCLK_LIMIT_450)
5259 dev_priv->max_cdclk_freq = 450000;
5261 dev_priv->max_cdclk_freq = 337500;
5262 } else if (IS_BROADWELL(dev)) {
5264 * FIXME with extra cooling we can allow
5265 * 540 MHz for ULX and 675 Mhz for ULT.
5266 * How can we know if extra cooling is
5267 * available? PCI ID, VTB, something else?
5269 if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT)
5270 dev_priv->max_cdclk_freq = 450000;
5271 else if (IS_BDW_ULX(dev))
5272 dev_priv->max_cdclk_freq = 450000;
5273 else if (IS_BDW_ULT(dev))
5274 dev_priv->max_cdclk_freq = 540000;
5276 dev_priv->max_cdclk_freq = 675000;
5277 } else if (IS_CHERRYVIEW(dev)) {
5278 dev_priv->max_cdclk_freq = 320000;
5279 } else if (IS_VALLEYVIEW(dev)) {
5280 dev_priv->max_cdclk_freq = 400000;
5282 /* otherwise assume cdclk is fixed */
5283 dev_priv->max_cdclk_freq = dev_priv->cdclk_freq;
5286 dev_priv->max_dotclk_freq = intel_compute_max_dotclk(dev_priv);
5288 DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n",
5289 dev_priv->max_cdclk_freq);
5291 DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n",
5292 dev_priv->max_dotclk_freq);
5295 static void intel_update_cdclk(struct drm_device *dev)
5297 struct drm_i915_private *dev_priv = dev->dev_private;
5299 dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev);
5300 DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n",
5301 dev_priv->cdclk_freq);
5304 * Program the gmbus_freq based on the cdclk frequency.
5305 * BSpec erroneously claims we should aim for 4MHz, but
5306 * in fact 1MHz is the correct frequency.
5308 if (IS_VALLEYVIEW(dev)) {
5310 * Program the gmbus_freq based on the cdclk frequency.
5311 * BSpec erroneously claims we should aim for 4MHz, but
5312 * in fact 1MHz is the correct frequency.
5314 I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000));
5317 if (dev_priv->max_cdclk_freq == 0)
5318 intel_update_max_cdclk(dev);
5321 static void broxton_set_cdclk(struct drm_device *dev, int frequency)
5323 struct drm_i915_private *dev_priv = dev->dev_private;
5326 uint32_t current_freq;
5329 /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */
5330 switch (frequency) {
5332 divider = BXT_CDCLK_CD2X_DIV_SEL_4;
5333 ratio = BXT_DE_PLL_RATIO(60);
5336 divider = BXT_CDCLK_CD2X_DIV_SEL_2;
5337 ratio = BXT_DE_PLL_RATIO(60);
5340 divider = BXT_CDCLK_CD2X_DIV_SEL_1_5;
5341 ratio = BXT_DE_PLL_RATIO(60);
5344 divider = BXT_CDCLK_CD2X_DIV_SEL_1;
5345 ratio = BXT_DE_PLL_RATIO(60);
5348 divider = BXT_CDCLK_CD2X_DIV_SEL_1;
5349 ratio = BXT_DE_PLL_RATIO(65);
5353 * Bypass frequency with DE PLL disabled. Init ratio, divider
5354 * to suppress GCC warning.
5360 DRM_ERROR("unsupported CDCLK freq %d", frequency);
5365 mutex_lock(&dev_priv->rps.hw_lock);
5366 /* Inform power controller of upcoming frequency change */
5367 ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ,
5369 mutex_unlock(&dev_priv->rps.hw_lock);
5372 DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n",
5377 current_freq = I915_READ(CDCLK_CTL) & CDCLK_FREQ_DECIMAL_MASK;
5378 /* convert from .1 fixpoint MHz with -1MHz offset to kHz */
5379 current_freq = current_freq * 500 + 1000;
5382 * DE PLL has to be disabled when
5383 * - setting to 19.2MHz (bypass, PLL isn't used)
5384 * - before setting to 624MHz (PLL needs toggling)
5385 * - before setting to any frequency from 624MHz (PLL needs toggling)
5387 if (frequency == 19200 || frequency == 624000 ||
5388 current_freq == 624000) {
5389 I915_WRITE(BXT_DE_PLL_ENABLE, ~BXT_DE_PLL_PLL_ENABLE);
5391 if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK),
5393 DRM_ERROR("timout waiting for DE PLL unlock\n");
5396 if (frequency != 19200) {
5399 val = I915_READ(BXT_DE_PLL_CTL);
5400 val &= ~BXT_DE_PLL_RATIO_MASK;
5402 I915_WRITE(BXT_DE_PLL_CTL, val);
5404 I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE);
5406 if (wait_for(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK, 1))
5407 DRM_ERROR("timeout waiting for DE PLL lock\n");
5409 val = I915_READ(CDCLK_CTL);
5410 val &= ~BXT_CDCLK_CD2X_DIV_SEL_MASK;
5413 * Disable SSA Precharge when CD clock frequency < 500 MHz,
5416 val &= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE;
5417 if (frequency >= 500000)
5418 val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE;
5420 val &= ~CDCLK_FREQ_DECIMAL_MASK;
5421 /* convert from kHz to .1 fixpoint MHz with -1MHz offset */
5422 val |= (frequency - 1000) / 500;
5423 I915_WRITE(CDCLK_CTL, val);
5426 mutex_lock(&dev_priv->rps.hw_lock);
5427 ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ,
5428 DIV_ROUND_UP(frequency, 25000));
5429 mutex_unlock(&dev_priv->rps.hw_lock);
5432 DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n",
5437 intel_update_cdclk(dev);
5440 void broxton_init_cdclk(struct drm_device *dev)
5442 struct drm_i915_private *dev_priv = dev->dev_private;
5446 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
5447 * or else the reset will hang because there is no PCH to respond.
5448 * Move the handshake programming to initialization sequence.
5449 * Previously was left up to BIOS.
5451 val = I915_READ(HSW_NDE_RSTWRN_OPT);
5452 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
5453 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
5455 /* Enable PG1 for cdclk */
5456 intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
5458 /* check if cd clock is enabled */
5459 if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) {
5460 DRM_DEBUG_KMS("Display already initialized\n");
5466 * - The initial CDCLK needs to be read from VBT.
5467 * Need to make this change after VBT has changes for BXT.
5468 * - check if setting the max (or any) cdclk freq is really necessary
5469 * here, it belongs to modeset time
5471 broxton_set_cdclk(dev, 624000);
5473 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
5474 POSTING_READ(DBUF_CTL);
5478 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
5479 DRM_ERROR("DBuf power enable timeout!\n");
5482 void broxton_uninit_cdclk(struct drm_device *dev)
5484 struct drm_i915_private *dev_priv = dev->dev_private;
5486 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
5487 POSTING_READ(DBUF_CTL);
5491 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
5492 DRM_ERROR("DBuf power disable timeout!\n");
5494 /* Set minimum (bypass) frequency, in effect turning off the DE PLL */
5495 broxton_set_cdclk(dev, 19200);
5497 intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS);
5500 static const struct skl_cdclk_entry {
5503 } skl_cdclk_frequencies[] = {
5504 { .freq = 308570, .vco = 8640 },
5505 { .freq = 337500, .vco = 8100 },
5506 { .freq = 432000, .vco = 8640 },
5507 { .freq = 450000, .vco = 8100 },
5508 { .freq = 540000, .vco = 8100 },
5509 { .freq = 617140, .vco = 8640 },
5510 { .freq = 675000, .vco = 8100 },
5513 static unsigned int skl_cdclk_decimal(unsigned int freq)
5515 return (freq - 1000) / 500;
5518 static unsigned int skl_cdclk_get_vco(unsigned int freq)
5522 for (i = 0; i < ARRAY_SIZE(skl_cdclk_frequencies); i++) {
5523 const struct skl_cdclk_entry *e = &skl_cdclk_frequencies[i];
5525 if (e->freq == freq)
5533 skl_dpll0_enable(struct drm_i915_private *dev_priv, unsigned int required_vco)
5535 unsigned int min_freq;
5538 /* select the minimum CDCLK before enabling DPLL 0 */
5539 val = I915_READ(CDCLK_CTL);
5540 val &= ~CDCLK_FREQ_SEL_MASK | ~CDCLK_FREQ_DECIMAL_MASK;
5541 val |= CDCLK_FREQ_337_308;
5543 if (required_vco == 8640)
5548 val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_freq);
5550 I915_WRITE(CDCLK_CTL, val);
5551 POSTING_READ(CDCLK_CTL);
5554 * We always enable DPLL0 with the lowest link rate possible, but still
5555 * taking into account the VCO required to operate the eDP panel at the
5556 * desired frequency. The usual DP link rates operate with a VCO of
5557 * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640.
5558 * The modeset code is responsible for the selection of the exact link
5559 * rate later on, with the constraint of choosing a frequency that
5560 * works with required_vco.
5562 val = I915_READ(DPLL_CTRL1);
5564 val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) |
5565 DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0));
5566 val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0);
5567 if (required_vco == 8640)
5568 val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080,
5571 val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810,
5574 I915_WRITE(DPLL_CTRL1, val);
5575 POSTING_READ(DPLL_CTRL1);
5577 I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE);
5579 if (wait_for(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK, 5))
5580 DRM_ERROR("DPLL0 not locked\n");
5583 static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv)
5588 /* inform PCU we want to change CDCLK */
5589 val = SKL_CDCLK_PREPARE_FOR_CHANGE;
5590 mutex_lock(&dev_priv->rps.hw_lock);
5591 ret = sandybridge_pcode_read(dev_priv, SKL_PCODE_CDCLK_CONTROL, &val);
5592 mutex_unlock(&dev_priv->rps.hw_lock);
5594 return ret == 0 && (val & SKL_CDCLK_READY_FOR_CHANGE);
5597 static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv)
5601 for (i = 0; i < 15; i++) {
5602 if (skl_cdclk_pcu_ready(dev_priv))
5610 static void skl_set_cdclk(struct drm_i915_private *dev_priv, unsigned int freq)
5612 struct drm_device *dev = dev_priv->dev;
5613 u32 freq_select, pcu_ack;
5615 DRM_DEBUG_DRIVER("Changing CDCLK to %dKHz\n", freq);
5617 if (!skl_cdclk_wait_for_pcu_ready(dev_priv)) {
5618 DRM_ERROR("failed to inform PCU about cdclk change\n");
5626 freq_select = CDCLK_FREQ_450_432;
5630 freq_select = CDCLK_FREQ_540;
5636 freq_select = CDCLK_FREQ_337_308;
5641 freq_select = CDCLK_FREQ_675_617;
5646 I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(freq));
5647 POSTING_READ(CDCLK_CTL);
5649 /* inform PCU of the change */
5650 mutex_lock(&dev_priv->rps.hw_lock);
5651 sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack);
5652 mutex_unlock(&dev_priv->rps.hw_lock);
5654 intel_update_cdclk(dev);
5657 void skl_uninit_cdclk(struct drm_i915_private *dev_priv)
5659 /* disable DBUF power */
5660 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
5661 POSTING_READ(DBUF_CTL);
5665 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
5666 DRM_ERROR("DBuf power disable timeout\n");
5669 I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & ~LCPLL_PLL_ENABLE);
5670 if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1))
5671 DRM_ERROR("Couldn't disable DPLL0\n");
5673 intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS);
5676 void skl_init_cdclk(struct drm_i915_private *dev_priv)
5679 unsigned int required_vco;
5681 /* enable PCH reset handshake */
5682 val = I915_READ(HSW_NDE_RSTWRN_OPT);
5683 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
5685 /* enable PG1 and Misc I/O */
5686 intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
5688 /* DPLL0 not enabled (happens on early BIOS versions) */
5689 if (!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE)) {
5691 required_vco = skl_cdclk_get_vco(dev_priv->skl_boot_cdclk);
5692 skl_dpll0_enable(dev_priv, required_vco);
5695 /* set CDCLK to the frequency the BIOS chose */
5696 skl_set_cdclk(dev_priv, dev_priv->skl_boot_cdclk);
5698 /* enable DBUF power */
5699 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
5700 POSTING_READ(DBUF_CTL);
5704 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
5705 DRM_ERROR("DBuf power enable timeout\n");
5708 /* returns HPLL frequency in kHz */
5709 static int valleyview_get_vco(struct drm_i915_private *dev_priv)
5711 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
5713 /* Obtain SKU information */
5714 mutex_lock(&dev_priv->sb_lock);
5715 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
5716 CCK_FUSE_HPLL_FREQ_MASK;
5717 mutex_unlock(&dev_priv->sb_lock);
5719 return vco_freq[hpll_freq] * 1000;
5722 /* Adjust CDclk dividers to allow high res or save power if possible */
5723 static void valleyview_set_cdclk(struct drm_device *dev, int cdclk)
5725 struct drm_i915_private *dev_priv = dev->dev_private;
5728 WARN_ON(dev_priv->display.get_display_clock_speed(dev)
5729 != dev_priv->cdclk_freq);
5731 if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */
5733 else if (cdclk == 266667)
5738 mutex_lock(&dev_priv->rps.hw_lock);
5739 val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
5740 val &= ~DSPFREQGUAR_MASK;
5741 val |= (cmd << DSPFREQGUAR_SHIFT);
5742 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
5743 if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
5744 DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT),
5746 DRM_ERROR("timed out waiting for CDclk change\n");
5748 mutex_unlock(&dev_priv->rps.hw_lock);
5750 mutex_lock(&dev_priv->sb_lock);
5752 if (cdclk == 400000) {
5755 divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1;
5757 /* adjust cdclk divider */
5758 val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
5759 val &= ~DISPLAY_FREQUENCY_VALUES;
5761 vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val);
5763 if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) &
5764 DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
5766 DRM_ERROR("timed out waiting for CDclk change\n");
5769 /* adjust self-refresh exit latency value */
5770 val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC);
5774 * For high bandwidth configs, we set a higher latency in the bunit
5775 * so that the core display fetch happens in time to avoid underruns.
5777 if (cdclk == 400000)
5778 val |= 4500 / 250; /* 4.5 usec */
5780 val |= 3000 / 250; /* 3.0 usec */
5781 vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val);
5783 mutex_unlock(&dev_priv->sb_lock);
5785 intel_update_cdclk(dev);
5788 static void cherryview_set_cdclk(struct drm_device *dev, int cdclk)
5790 struct drm_i915_private *dev_priv = dev->dev_private;
5793 WARN_ON(dev_priv->display.get_display_clock_speed(dev)
5794 != dev_priv->cdclk_freq);
5803 MISSING_CASE(cdclk);
5808 * Specs are full of misinformation, but testing on actual
5809 * hardware has shown that we just need to write the desired
5810 * CCK divider into the Punit register.
5812 cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1;
5814 mutex_lock(&dev_priv->rps.hw_lock);
5815 val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
5816 val &= ~DSPFREQGUAR_MASK_CHV;
5817 val |= (cmd << DSPFREQGUAR_SHIFT_CHV);
5818 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
5819 if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
5820 DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV),
5822 DRM_ERROR("timed out waiting for CDclk change\n");
5824 mutex_unlock(&dev_priv->rps.hw_lock);
5826 intel_update_cdclk(dev);
5829 static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv,
5832 int freq_320 = (dev_priv->hpll_freq << 1) % 320000 != 0 ? 333333 : 320000;
5833 int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90;
5836 * Really only a few cases to deal with, as only 4 CDclks are supported:
5839 * 320/333MHz (depends on HPLL freq)
5841 * So we check to see whether we're above 90% (VLV) or 95% (CHV)
5842 * of the lower bin and adjust if needed.
5844 * We seem to get an unstable or solid color picture at 200MHz.
5845 * Not sure what's wrong. For now use 200MHz only when all pipes
5848 if (!IS_CHERRYVIEW(dev_priv) &&
5849 max_pixclk > freq_320*limit/100)
5851 else if (max_pixclk > 266667*limit/100)
5853 else if (max_pixclk > 0)
5859 static int broxton_calc_cdclk(struct drm_i915_private *dev_priv,
5864 * - remove the guardband, it's not needed on BXT
5865 * - set 19.2MHz bypass frequency if there are no active pipes
5867 if (max_pixclk > 576000*9/10)
5869 else if (max_pixclk > 384000*9/10)
5871 else if (max_pixclk > 288000*9/10)
5873 else if (max_pixclk > 144000*9/10)
5879 /* Compute the max pixel clock for new configuration. Uses atomic state if
5880 * that's non-NULL, look at current state otherwise. */
5881 static int intel_mode_max_pixclk(struct drm_device *dev,
5882 struct drm_atomic_state *state)
5884 struct intel_crtc *intel_crtc;
5885 struct intel_crtc_state *crtc_state;
5888 for_each_intel_crtc(dev, intel_crtc) {
5889 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
5890 if (IS_ERR(crtc_state))
5891 return PTR_ERR(crtc_state);
5893 if (!crtc_state->base.enable)
5896 max_pixclk = max(max_pixclk,
5897 crtc_state->base.adjusted_mode.crtc_clock);
5903 static int valleyview_modeset_calc_cdclk(struct drm_atomic_state *state)
5905 struct drm_device *dev = state->dev;
5906 struct drm_i915_private *dev_priv = dev->dev_private;
5907 int max_pixclk = intel_mode_max_pixclk(dev, state);
5912 to_intel_atomic_state(state)->cdclk =
5913 valleyview_calc_cdclk(dev_priv, max_pixclk);
5918 static int broxton_modeset_calc_cdclk(struct drm_atomic_state *state)
5920 struct drm_device *dev = state->dev;
5921 struct drm_i915_private *dev_priv = dev->dev_private;
5922 int max_pixclk = intel_mode_max_pixclk(dev, state);
5927 to_intel_atomic_state(state)->cdclk =
5928 broxton_calc_cdclk(dev_priv, max_pixclk);
5933 static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv)
5935 unsigned int credits, default_credits;
5937 if (IS_CHERRYVIEW(dev_priv))
5938 default_credits = PFI_CREDIT(12);
5940 default_credits = PFI_CREDIT(8);
5942 if (DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 1000) >= dev_priv->rps.cz_freq) {
5943 /* CHV suggested value is 31 or 63 */
5944 if (IS_CHERRYVIEW(dev_priv))
5945 credits = PFI_CREDIT_63;
5947 credits = PFI_CREDIT(15);
5949 credits = default_credits;
5953 * WA - write default credits before re-programming
5954 * FIXME: should we also set the resend bit here?
5956 I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE |
5959 I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE |
5960 credits | PFI_CREDIT_RESEND);
5963 * FIXME is this guaranteed to clear
5964 * immediately or should we poll for it?
5966 WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND);
5969 static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state)
5971 struct drm_device *dev = old_state->dev;
5972 unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk;
5973 struct drm_i915_private *dev_priv = dev->dev_private;
5976 * FIXME: We can end up here with all power domains off, yet
5977 * with a CDCLK frequency other than the minimum. To account
5978 * for this take the PIPE-A power domain, which covers the HW
5979 * blocks needed for the following programming. This can be
5980 * removed once it's guaranteed that we get here either with
5981 * the minimum CDCLK set, or the required power domains
5984 intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A);
5986 if (IS_CHERRYVIEW(dev))
5987 cherryview_set_cdclk(dev, req_cdclk);
5989 valleyview_set_cdclk(dev, req_cdclk);
5991 vlv_program_pfi_credits(dev_priv);
5993 intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A);
5996 static void valleyview_crtc_enable(struct drm_crtc *crtc)
5998 struct drm_device *dev = crtc->dev;
5999 struct drm_i915_private *dev_priv = to_i915(dev);
6000 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6001 struct intel_encoder *encoder;
6002 int pipe = intel_crtc->pipe;
6005 if (WARN_ON(intel_crtc->active))
6008 is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI);
6010 if (intel_crtc->config->has_dp_encoder)
6011 intel_dp_set_m_n(intel_crtc, M1_N1);
6013 intel_set_pipe_timings(intel_crtc);
6015 if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) {
6016 struct drm_i915_private *dev_priv = dev->dev_private;
6018 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6019 I915_WRITE(CHV_CANVAS(pipe), 0);
6022 i9xx_set_pipeconf(intel_crtc);
6024 intel_crtc->active = true;
6026 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6028 for_each_encoder_on_crtc(dev, crtc, encoder)
6029 if (encoder->pre_pll_enable)
6030 encoder->pre_pll_enable(encoder);
6033 if (IS_CHERRYVIEW(dev)) {
6034 chv_prepare_pll(intel_crtc, intel_crtc->config);
6035 chv_enable_pll(intel_crtc, intel_crtc->config);
6037 vlv_prepare_pll(intel_crtc, intel_crtc->config);
6038 vlv_enable_pll(intel_crtc, intel_crtc->config);
6042 for_each_encoder_on_crtc(dev, crtc, encoder)
6043 if (encoder->pre_enable)
6044 encoder->pre_enable(encoder);
6046 i9xx_pfit_enable(intel_crtc);
6048 intel_crtc_load_lut(crtc);
6050 intel_enable_pipe(intel_crtc);
6052 assert_vblank_disabled(crtc);
6053 drm_crtc_vblank_on(crtc);
6055 for_each_encoder_on_crtc(dev, crtc, encoder)
6056 encoder->enable(encoder);
6059 static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
6061 struct drm_device *dev = crtc->base.dev;
6062 struct drm_i915_private *dev_priv = dev->dev_private;
6064 I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0);
6065 I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1);
6068 static void i9xx_crtc_enable(struct drm_crtc *crtc)
6070 struct drm_device *dev = crtc->dev;
6071 struct drm_i915_private *dev_priv = to_i915(dev);
6072 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6073 struct intel_encoder *encoder;
6074 int pipe = intel_crtc->pipe;
6076 if (WARN_ON(intel_crtc->active))
6079 i9xx_set_pll_dividers(intel_crtc);
6081 if (intel_crtc->config->has_dp_encoder)
6082 intel_dp_set_m_n(intel_crtc, M1_N1);
6084 intel_set_pipe_timings(intel_crtc);
6086 i9xx_set_pipeconf(intel_crtc);
6088 intel_crtc->active = true;
6091 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6093 for_each_encoder_on_crtc(dev, crtc, encoder)
6094 if (encoder->pre_enable)
6095 encoder->pre_enable(encoder);
6097 i9xx_enable_pll(intel_crtc);
6099 i9xx_pfit_enable(intel_crtc);
6101 intel_crtc_load_lut(crtc);
6103 intel_update_watermarks(crtc);
6104 intel_enable_pipe(intel_crtc);
6106 assert_vblank_disabled(crtc);
6107 drm_crtc_vblank_on(crtc);
6109 for_each_encoder_on_crtc(dev, crtc, encoder)
6110 encoder->enable(encoder);
6113 static void i9xx_pfit_disable(struct intel_crtc *crtc)
6115 struct drm_device *dev = crtc->base.dev;
6116 struct drm_i915_private *dev_priv = dev->dev_private;
6118 if (!crtc->config->gmch_pfit.control)
6121 assert_pipe_disabled(dev_priv, crtc->pipe);
6123 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
6124 I915_READ(PFIT_CONTROL));
6125 I915_WRITE(PFIT_CONTROL, 0);
6128 static void i9xx_crtc_disable(struct drm_crtc *crtc)
6130 struct drm_device *dev = crtc->dev;
6131 struct drm_i915_private *dev_priv = dev->dev_private;
6132 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6133 struct intel_encoder *encoder;
6134 int pipe = intel_crtc->pipe;
6137 * On gen2 planes are double buffered but the pipe isn't, so we must
6138 * wait for planes to fully turn off before disabling the pipe.
6139 * We also need to wait on all gmch platforms because of the
6140 * self-refresh mode constraint explained above.
6142 intel_wait_for_vblank(dev, pipe);
6144 for_each_encoder_on_crtc(dev, crtc, encoder)
6145 encoder->disable(encoder);
6147 drm_crtc_vblank_off(crtc);
6148 assert_vblank_disabled(crtc);
6150 intel_disable_pipe(intel_crtc);
6152 i9xx_pfit_disable(intel_crtc);
6154 for_each_encoder_on_crtc(dev, crtc, encoder)
6155 if (encoder->post_disable)
6156 encoder->post_disable(encoder);
6158 if (!intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) {
6159 if (IS_CHERRYVIEW(dev))
6160 chv_disable_pll(dev_priv, pipe);
6161 else if (IS_VALLEYVIEW(dev))
6162 vlv_disable_pll(dev_priv, pipe);
6164 i9xx_disable_pll(intel_crtc);
6167 for_each_encoder_on_crtc(dev, crtc, encoder)
6168 if (encoder->post_pll_disable)
6169 encoder->post_pll_disable(encoder);
6172 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6174 intel_crtc->active = false;
6175 intel_update_watermarks(crtc);
6178 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc)
6180 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6181 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6182 enum intel_display_power_domain domain;
6183 unsigned long domains;
6185 if (!intel_crtc->active)
6188 if (to_intel_plane_state(crtc->primary->state)->visible) {
6189 intel_crtc_wait_for_pending_flips(crtc);
6190 intel_pre_disable_primary(crtc);
6193 intel_crtc_disable_planes(crtc, crtc->state->plane_mask);
6194 dev_priv->display.crtc_disable(crtc);
6195 intel_disable_shared_dpll(intel_crtc);
6197 domains = intel_crtc->enabled_power_domains;
6198 for_each_power_domain(domain, domains)
6199 intel_display_power_put(dev_priv, domain);
6200 intel_crtc->enabled_power_domains = 0;
6204 * turn all crtc's off, but do not adjust state
6205 * This has to be paired with a call to intel_modeset_setup_hw_state.
6207 int intel_display_suspend(struct drm_device *dev)
6209 struct drm_mode_config *config = &dev->mode_config;
6210 struct drm_modeset_acquire_ctx *ctx = config->acquire_ctx;
6211 struct drm_atomic_state *state;
6212 struct drm_crtc *crtc;
6213 unsigned crtc_mask = 0;
6219 lockdep_assert_held(&ctx->ww_ctx);
6220 state = drm_atomic_state_alloc(dev);
6221 if (WARN_ON(!state))
6224 state->acquire_ctx = ctx;
6225 state->allow_modeset = true;
6227 for_each_crtc(dev, crtc) {
6228 struct drm_crtc_state *crtc_state =
6229 drm_atomic_get_crtc_state(state, crtc);
6231 ret = PTR_ERR_OR_ZERO(crtc_state);
6235 if (!crtc_state->active)
6238 crtc_state->active = false;
6239 crtc_mask |= 1 << drm_crtc_index(crtc);
6243 ret = drm_atomic_commit(state);
6246 for_each_crtc(dev, crtc)
6247 if (crtc_mask & (1 << drm_crtc_index(crtc)))
6248 crtc->state->active = true;
6256 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
6257 drm_atomic_state_free(state);
6261 void intel_encoder_destroy(struct drm_encoder *encoder)
6263 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6265 drm_encoder_cleanup(encoder);
6266 kfree(intel_encoder);
6269 /* Cross check the actual hw state with our own modeset state tracking (and it's
6270 * internal consistency). */
6271 static void intel_connector_check_state(struct intel_connector *connector)
6273 struct drm_crtc *crtc = connector->base.state->crtc;
6275 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6276 connector->base.base.id,
6277 connector->base.name);
6279 if (connector->get_hw_state(connector)) {
6280 struct drm_encoder *encoder = &connector->encoder->base;
6281 struct drm_connector_state *conn_state = connector->base.state;
6283 I915_STATE_WARN(!crtc,
6284 "connector enabled without attached crtc\n");
6289 I915_STATE_WARN(!crtc->state->active,
6290 "connector is active, but attached crtc isn't\n");
6295 I915_STATE_WARN(conn_state->best_encoder != encoder,
6296 "atomic encoder doesn't match attached encoder\n");
6298 I915_STATE_WARN(conn_state->crtc != encoder->crtc,
6299 "attached encoder crtc differs from connector crtc\n");
6301 I915_STATE_WARN(crtc && crtc->state->active,
6302 "attached crtc is active, but connector isn't\n");
6303 I915_STATE_WARN(!crtc && connector->base.state->best_encoder,
6304 "best encoder set without crtc!\n");
6308 int intel_connector_init(struct intel_connector *connector)
6310 struct drm_connector_state *connector_state;
6312 connector_state = kzalloc(sizeof *connector_state, GFP_KERNEL);
6313 if (!connector_state)
6316 connector->base.state = connector_state;
6320 struct intel_connector *intel_connector_alloc(void)
6322 struct intel_connector *connector;
6324 connector = kzalloc(sizeof *connector, GFP_KERNEL);
6328 if (intel_connector_init(connector) < 0) {
6336 /* Simple connector->get_hw_state implementation for encoders that support only
6337 * one connector and no cloning and hence the encoder state determines the state
6338 * of the connector. */
6339 bool intel_connector_get_hw_state(struct intel_connector *connector)
6342 struct intel_encoder *encoder = connector->encoder;
6344 return encoder->get_hw_state(encoder, &pipe);
6347 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
6349 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6350 return crtc_state->fdi_lanes;
6355 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
6356 struct intel_crtc_state *pipe_config)
6358 struct drm_atomic_state *state = pipe_config->base.state;
6359 struct intel_crtc *other_crtc;
6360 struct intel_crtc_state *other_crtc_state;
6362 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6363 pipe_name(pipe), pipe_config->fdi_lanes);
6364 if (pipe_config->fdi_lanes > 4) {
6365 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6366 pipe_name(pipe), pipe_config->fdi_lanes);
6370 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
6371 if (pipe_config->fdi_lanes > 2) {
6372 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6373 pipe_config->fdi_lanes);
6380 if (INTEL_INFO(dev)->num_pipes == 2)
6383 /* Ivybridge 3 pipe is really complicated */
6388 if (pipe_config->fdi_lanes <= 2)
6391 other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C));
6393 intel_atomic_get_crtc_state(state, other_crtc);
6394 if (IS_ERR(other_crtc_state))
6395 return PTR_ERR(other_crtc_state);
6397 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
6398 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6399 pipe_name(pipe), pipe_config->fdi_lanes);
6404 if (pipe_config->fdi_lanes > 2) {
6405 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6406 pipe_name(pipe), pipe_config->fdi_lanes);
6410 other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B));
6412 intel_atomic_get_crtc_state(state, other_crtc);
6413 if (IS_ERR(other_crtc_state))
6414 return PTR_ERR(other_crtc_state);
6416 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
6417 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6427 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
6428 struct intel_crtc_state *pipe_config)
6430 struct drm_device *dev = intel_crtc->base.dev;
6431 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6432 int lane, link_bw, fdi_dotclock, ret;
6433 bool needs_recompute = false;
6436 /* FDI is a binary signal running at ~2.7GHz, encoding
6437 * each output octet as 10 bits. The actual frequency
6438 * is stored as a divider into a 100MHz clock, and the
6439 * mode pixel clock is stored in units of 1KHz.
6440 * Hence the bw of each lane in terms of the mode signal
6443 link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
6445 fdi_dotclock = adjusted_mode->crtc_clock;
6447 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
6448 pipe_config->pipe_bpp);
6450 pipe_config->fdi_lanes = lane;
6452 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
6453 link_bw, &pipe_config->fdi_m_n);
6455 ret = ironlake_check_fdi_lanes(intel_crtc->base.dev,
6456 intel_crtc->pipe, pipe_config);
6457 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
6458 pipe_config->pipe_bpp -= 2*3;
6459 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6460 pipe_config->pipe_bpp);
6461 needs_recompute = true;
6462 pipe_config->bw_constrained = true;
6467 if (needs_recompute)
6473 static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv,
6474 struct intel_crtc_state *pipe_config)
6476 if (pipe_config->pipe_bpp > 24)
6479 /* HSW can handle pixel rate up to cdclk? */
6480 if (IS_HASWELL(dev_priv->dev))
6484 * We compare against max which means we must take
6485 * the increased cdclk requirement into account when
6486 * calculating the new cdclk.
6488 * Should measure whether using a lower cdclk w/o IPS
6490 return ilk_pipe_pixel_rate(pipe_config) <=
6491 dev_priv->max_cdclk_freq * 95 / 100;
6494 static void hsw_compute_ips_config(struct intel_crtc *crtc,
6495 struct intel_crtc_state *pipe_config)
6497 struct drm_device *dev = crtc->base.dev;
6498 struct drm_i915_private *dev_priv = dev->dev_private;
6500 pipe_config->ips_enabled = i915.enable_ips &&
6501 hsw_crtc_supports_ips(crtc) &&
6502 pipe_config_supports_ips(dev_priv, pipe_config);
6505 static int intel_crtc_compute_config(struct intel_crtc *crtc,
6506 struct intel_crtc_state *pipe_config)
6508 struct drm_device *dev = crtc->base.dev;
6509 struct drm_i915_private *dev_priv = dev->dev_private;
6510 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6512 /* FIXME should check pixel clock limits on all platforms */
6513 if (INTEL_INFO(dev)->gen < 4) {
6514 int clock_limit = dev_priv->max_cdclk_freq;
6517 * Enable pixel doubling when the dot clock
6518 * is > 90% of the (display) core speed.
6520 * GDG double wide on either pipe,
6521 * otherwise pipe A only.
6523 if ((crtc->pipe == PIPE_A || IS_I915G(dev)) &&
6524 adjusted_mode->crtc_clock > clock_limit * 9 / 10) {
6526 pipe_config->double_wide = true;
6529 if (adjusted_mode->crtc_clock > clock_limit * 9 / 10)
6534 * Pipe horizontal size must be even in:
6536 * - LVDS dual channel mode
6537 * - Double wide pipe
6539 if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6540 intel_is_dual_link_lvds(dev)) || pipe_config->double_wide)
6541 pipe_config->pipe_src_w &= ~1;
6543 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6544 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6546 if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
6547 adjusted_mode->hsync_start == adjusted_mode->hdisplay)
6551 hsw_compute_ips_config(crtc, pipe_config);
6553 if (pipe_config->has_pch_encoder)
6554 return ironlake_fdi_compute_config(crtc, pipe_config);
6559 static int skylake_get_display_clock_speed(struct drm_device *dev)
6561 struct drm_i915_private *dev_priv = to_i915(dev);
6562 uint32_t lcpll1 = I915_READ(LCPLL1_CTL);
6563 uint32_t cdctl = I915_READ(CDCLK_CTL);
6566 if (!(lcpll1 & LCPLL_PLL_ENABLE))
6567 return 24000; /* 24MHz is the cd freq with NSSC ref */
6569 if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540)
6572 linkrate = (I915_READ(DPLL_CTRL1) &
6573 DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1;
6575 if (linkrate == DPLL_CTRL1_LINK_RATE_2160 ||
6576 linkrate == DPLL_CTRL1_LINK_RATE_1080) {
6578 switch (cdctl & CDCLK_FREQ_SEL_MASK) {
6579 case CDCLK_FREQ_450_432:
6581 case CDCLK_FREQ_337_308:
6583 case CDCLK_FREQ_675_617:
6586 WARN(1, "Unknown cd freq selection\n");
6590 switch (cdctl & CDCLK_FREQ_SEL_MASK) {
6591 case CDCLK_FREQ_450_432:
6593 case CDCLK_FREQ_337_308:
6595 case CDCLK_FREQ_675_617:
6598 WARN(1, "Unknown cd freq selection\n");
6602 /* error case, do as if DPLL0 isn't enabled */
6606 static int broxton_get_display_clock_speed(struct drm_device *dev)
6608 struct drm_i915_private *dev_priv = to_i915(dev);
6609 uint32_t cdctl = I915_READ(CDCLK_CTL);
6610 uint32_t pll_ratio = I915_READ(BXT_DE_PLL_CTL) & BXT_DE_PLL_RATIO_MASK;
6611 uint32_t pll_enab = I915_READ(BXT_DE_PLL_ENABLE);
6614 if (!(pll_enab & BXT_DE_PLL_PLL_ENABLE))
6617 cdclk = 19200 * pll_ratio / 2;
6619 switch (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) {
6620 case BXT_CDCLK_CD2X_DIV_SEL_1:
6621 return cdclk; /* 576MHz or 624MHz */
6622 case BXT_CDCLK_CD2X_DIV_SEL_1_5:
6623 return cdclk * 2 / 3; /* 384MHz */
6624 case BXT_CDCLK_CD2X_DIV_SEL_2:
6625 return cdclk / 2; /* 288MHz */
6626 case BXT_CDCLK_CD2X_DIV_SEL_4:
6627 return cdclk / 4; /* 144MHz */
6630 /* error case, do as if DE PLL isn't enabled */
6634 static int broadwell_get_display_clock_speed(struct drm_device *dev)
6636 struct drm_i915_private *dev_priv = dev->dev_private;
6637 uint32_t lcpll = I915_READ(LCPLL_CTL);
6638 uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
6640 if (lcpll & LCPLL_CD_SOURCE_FCLK)
6642 else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT)
6644 else if (freq == LCPLL_CLK_FREQ_450)
6646 else if (freq == LCPLL_CLK_FREQ_54O_BDW)
6648 else if (freq == LCPLL_CLK_FREQ_337_5_BDW)
6654 static int haswell_get_display_clock_speed(struct drm_device *dev)
6656 struct drm_i915_private *dev_priv = dev->dev_private;
6657 uint32_t lcpll = I915_READ(LCPLL_CTL);
6658 uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
6660 if (lcpll & LCPLL_CD_SOURCE_FCLK)
6662 else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT)
6664 else if (freq == LCPLL_CLK_FREQ_450)
6666 else if (IS_HSW_ULT(dev))
6672 static int valleyview_get_display_clock_speed(struct drm_device *dev)
6674 struct drm_i915_private *dev_priv = dev->dev_private;
6678 if (dev_priv->hpll_freq == 0)
6679 dev_priv->hpll_freq = valleyview_get_vco(dev_priv);
6681 mutex_lock(&dev_priv->sb_lock);
6682 val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
6683 mutex_unlock(&dev_priv->sb_lock);
6685 divider = val & DISPLAY_FREQUENCY_VALUES;
6687 WARN((val & DISPLAY_FREQUENCY_STATUS) !=
6688 (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
6689 "cdclk change in progress\n");
6691 return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1);
6694 static int ilk_get_display_clock_speed(struct drm_device *dev)
6699 static int i945_get_display_clock_speed(struct drm_device *dev)
6704 static int i915_get_display_clock_speed(struct drm_device *dev)
6709 static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
6714 static int pnv_get_display_clock_speed(struct drm_device *dev)
6718 pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
6720 switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
6721 case GC_DISPLAY_CLOCK_267_MHZ_PNV:
6723 case GC_DISPLAY_CLOCK_333_MHZ_PNV:
6725 case GC_DISPLAY_CLOCK_444_MHZ_PNV:
6727 case GC_DISPLAY_CLOCK_200_MHZ_PNV:
6730 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc);
6731 case GC_DISPLAY_CLOCK_133_MHZ_PNV:
6733 case GC_DISPLAY_CLOCK_167_MHZ_PNV:
6738 static int i915gm_get_display_clock_speed(struct drm_device *dev)
6742 pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
6744 if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
6747 switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
6748 case GC_DISPLAY_CLOCK_333_MHZ:
6751 case GC_DISPLAY_CLOCK_190_200_MHZ:
6757 static int i865_get_display_clock_speed(struct drm_device *dev)
6762 static int i85x_get_display_clock_speed(struct drm_device *dev)
6767 * 852GM/852GMV only supports 133 MHz and the HPLLCC
6768 * encoding is different :(
6769 * FIXME is this the right way to detect 852GM/852GMV?
6771 if (dev->pdev->revision == 0x1)
6774 pci_bus_read_config_word(dev->pdev->bus,
6775 PCI_DEVFN(0, 3), HPLLCC, &hpllcc);
6777 /* Assume that the hardware is in the high speed state. This
6778 * should be the default.
6780 switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
6781 case GC_CLOCK_133_200:
6782 case GC_CLOCK_133_200_2:
6783 case GC_CLOCK_100_200:
6785 case GC_CLOCK_166_250:
6787 case GC_CLOCK_100_133:
6789 case GC_CLOCK_133_266:
6790 case GC_CLOCK_133_266_2:
6791 case GC_CLOCK_166_266:
6795 /* Shouldn't happen */
6799 static int i830_get_display_clock_speed(struct drm_device *dev)
6804 static unsigned int intel_hpll_vco(struct drm_device *dev)
6806 struct drm_i915_private *dev_priv = dev->dev_private;
6807 static const unsigned int blb_vco[8] = {
6814 static const unsigned int pnv_vco[8] = {
6821 static const unsigned int cl_vco[8] = {
6830 static const unsigned int elk_vco[8] = {
6836 static const unsigned int ctg_vco[8] = {
6844 const unsigned int *vco_table;
6848 /* FIXME other chipsets? */
6850 vco_table = ctg_vco;
6851 else if (IS_G4X(dev))
6852 vco_table = elk_vco;
6853 else if (IS_CRESTLINE(dev))
6855 else if (IS_PINEVIEW(dev))
6856 vco_table = pnv_vco;
6857 else if (IS_G33(dev))
6858 vco_table = blb_vco;
6862 tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO);
6864 vco = vco_table[tmp & 0x7];
6866 DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp);
6868 DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco);
6873 static int gm45_get_display_clock_speed(struct drm_device *dev)
6875 unsigned int cdclk_sel, vco = intel_hpll_vco(dev);
6878 pci_read_config_word(dev->pdev, GCFGC, &tmp);
6880 cdclk_sel = (tmp >> 12) & 0x1;
6886 return cdclk_sel ? 333333 : 222222;
6888 return cdclk_sel ? 320000 : 228571;
6890 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp);
6895 static int i965gm_get_display_clock_speed(struct drm_device *dev)
6897 static const uint8_t div_3200[] = { 16, 10, 8 };
6898 static const uint8_t div_4000[] = { 20, 12, 10 };
6899 static const uint8_t div_5333[] = { 24, 16, 14 };
6900 const uint8_t *div_table;
6901 unsigned int cdclk_sel, vco = intel_hpll_vco(dev);
6904 pci_read_config_word(dev->pdev, GCFGC, &tmp);
6906 cdclk_sel = ((tmp >> 8) & 0x1f) - 1;
6908 if (cdclk_sel >= ARRAY_SIZE(div_3200))
6913 div_table = div_3200;
6916 div_table = div_4000;
6919 div_table = div_5333;
6925 return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]);
6928 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp);
6932 static int g33_get_display_clock_speed(struct drm_device *dev)
6934 static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 };
6935 static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 };
6936 static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 };
6937 static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 };
6938 const uint8_t *div_table;
6939 unsigned int cdclk_sel, vco = intel_hpll_vco(dev);
6942 pci_read_config_word(dev->pdev, GCFGC, &tmp);
6944 cdclk_sel = (tmp >> 4) & 0x7;
6946 if (cdclk_sel >= ARRAY_SIZE(div_3200))
6951 div_table = div_3200;
6954 div_table = div_4000;
6957 div_table = div_4800;
6960 div_table = div_5333;
6966 return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]);
6969 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp);
6974 intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
6976 while (*num > DATA_LINK_M_N_MASK ||
6977 *den > DATA_LINK_M_N_MASK) {
6983 static void compute_m_n(unsigned int m, unsigned int n,
6984 uint32_t *ret_m, uint32_t *ret_n)
6986 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
6987 *ret_m = div_u64((uint64_t) m * *ret_n, n);
6988 intel_reduce_m_n_ratio(ret_m, ret_n);
6992 intel_link_compute_m_n(int bits_per_pixel, int nlanes,
6993 int pixel_clock, int link_clock,
6994 struct intel_link_m_n *m_n)
6998 compute_m_n(bits_per_pixel * pixel_clock,
6999 link_clock * nlanes * 8,
7000 &m_n->gmch_m, &m_n->gmch_n);
7002 compute_m_n(pixel_clock, link_clock,
7003 &m_n->link_m, &m_n->link_n);
7006 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
7008 if (i915.panel_use_ssc >= 0)
7009 return i915.panel_use_ssc != 0;
7010 return dev_priv->vbt.lvds_use_ssc
7011 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
7014 static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state,
7017 struct drm_device *dev = crtc_state->base.crtc->dev;
7018 struct drm_i915_private *dev_priv = dev->dev_private;
7021 WARN_ON(!crtc_state->base.state);
7023 if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) {
7025 } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7026 intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
7027 refclk = dev_priv->vbt.lvds_ssc_freq;
7028 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7029 } else if (!IS_GEN2(dev)) {
7038 static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
7040 return (1 << dpll->n) << 16 | dpll->m2;
7043 static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
7045 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
7048 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
7049 struct intel_crtc_state *crtc_state,
7050 intel_clock_t *reduced_clock)
7052 struct drm_device *dev = crtc->base.dev;
7055 if (IS_PINEVIEW(dev)) {
7056 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
7058 fp2 = pnv_dpll_compute_fp(reduced_clock);
7060 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
7062 fp2 = i9xx_dpll_compute_fp(reduced_clock);
7065 crtc_state->dpll_hw_state.fp0 = fp;
7067 crtc->lowfreq_avail = false;
7068 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7070 crtc_state->dpll_hw_state.fp1 = fp2;
7071 crtc->lowfreq_avail = true;
7073 crtc_state->dpll_hw_state.fp1 = fp;
7077 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
7083 * PLLB opamp always calibrates to max value of 0x3f, force enable it
7084 * and set it to a reasonable value instead.
7086 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7087 reg_val &= 0xffffff00;
7088 reg_val |= 0x00000030;
7089 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7091 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7092 reg_val &= 0x8cffffff;
7093 reg_val = 0x8c000000;
7094 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7096 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7097 reg_val &= 0xffffff00;
7098 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7100 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7101 reg_val &= 0x00ffffff;
7102 reg_val |= 0xb0000000;
7103 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7106 static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
7107 struct intel_link_m_n *m_n)
7109 struct drm_device *dev = crtc->base.dev;
7110 struct drm_i915_private *dev_priv = dev->dev_private;
7111 int pipe = crtc->pipe;
7113 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7114 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
7115 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
7116 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
7119 static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
7120 struct intel_link_m_n *m_n,
7121 struct intel_link_m_n *m2_n2)
7123 struct drm_device *dev = crtc->base.dev;
7124 struct drm_i915_private *dev_priv = dev->dev_private;
7125 int pipe = crtc->pipe;
7126 enum transcoder transcoder = crtc->config->cpu_transcoder;
7128 if (INTEL_INFO(dev)->gen >= 5) {
7129 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
7130 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
7131 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
7132 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
7133 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
7134 * for gen < 8) and if DRRS is supported (to make sure the
7135 * registers are not unnecessarily accessed).
7137 if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) &&
7138 crtc->config->has_drrs) {
7139 I915_WRITE(PIPE_DATA_M2(transcoder),
7140 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
7141 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
7142 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
7143 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
7146 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7147 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
7148 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
7149 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
7153 void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n)
7155 struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
7158 dp_m_n = &crtc->config->dp_m_n;
7159 dp_m2_n2 = &crtc->config->dp_m2_n2;
7160 } else if (m_n == M2_N2) {
7163 * M2_N2 registers are not supported. Hence m2_n2 divider value
7164 * needs to be programmed into M1_N1.
7166 dp_m_n = &crtc->config->dp_m2_n2;
7168 DRM_ERROR("Unsupported divider value\n");
7172 if (crtc->config->has_pch_encoder)
7173 intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n);
7175 intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2);
7178 static void vlv_compute_dpll(struct intel_crtc *crtc,
7179 struct intel_crtc_state *pipe_config)
7184 * Enable DPIO clock input. We should never disable the reference
7185 * clock for pipe B, since VGA hotplug / manual detection depends
7188 dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REF_CLK_ENABLE_VLV |
7189 DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_REF_CLK_VLV;
7190 /* We should never disable this, set it here for state tracking */
7191 if (crtc->pipe == PIPE_B)
7192 dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7193 dpll |= DPLL_VCO_ENABLE;
7194 pipe_config->dpll_hw_state.dpll = dpll;
7196 dpll_md = (pipe_config->pixel_multiplier - 1)
7197 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7198 pipe_config->dpll_hw_state.dpll_md = dpll_md;
7201 static void vlv_prepare_pll(struct intel_crtc *crtc,
7202 const struct intel_crtc_state *pipe_config)
7204 struct drm_device *dev = crtc->base.dev;
7205 struct drm_i915_private *dev_priv = dev->dev_private;
7206 int pipe = crtc->pipe;
7208 u32 bestn, bestm1, bestm2, bestp1, bestp2;
7209 u32 coreclk, reg_val;
7211 mutex_lock(&dev_priv->sb_lock);
7213 bestn = pipe_config->dpll.n;
7214 bestm1 = pipe_config->dpll.m1;
7215 bestm2 = pipe_config->dpll.m2;
7216 bestp1 = pipe_config->dpll.p1;
7217 bestp2 = pipe_config->dpll.p2;
7219 /* See eDP HDMI DPIO driver vbios notes doc */
7221 /* PLL B needs special handling */
7223 vlv_pllb_recal_opamp(dev_priv, pipe);
7225 /* Set up Tx target for periodic Rcomp update */
7226 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
7228 /* Disable target IRef on PLL */
7229 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
7230 reg_val &= 0x00ffffff;
7231 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
7233 /* Disable fast lock */
7234 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
7236 /* Set idtafcrecal before PLL is enabled */
7237 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
7238 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
7239 mdiv |= ((bestn << DPIO_N_SHIFT));
7240 mdiv |= (1 << DPIO_K_SHIFT);
7243 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7244 * but we don't support that).
7245 * Note: don't use the DAC post divider as it seems unstable.
7247 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
7248 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7250 mdiv |= DPIO_ENABLE_CALIBRATION;
7251 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7253 /* Set HBR and RBR LPF coefficients */
7254 if (pipe_config->port_clock == 162000 ||
7255 intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) ||
7256 intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
7257 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7260 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7263 if (pipe_config->has_dp_encoder) {
7264 /* Use SSC source */
7266 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7269 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7271 } else { /* HDMI or VGA */
7272 /* Use bend source */
7274 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7277 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7281 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
7282 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
7283 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
7284 intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
7285 coreclk |= 0x01000000;
7286 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
7288 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
7289 mutex_unlock(&dev_priv->sb_lock);
7292 static void chv_compute_dpll(struct intel_crtc *crtc,
7293 struct intel_crtc_state *pipe_config)
7295 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
7296 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS |
7298 if (crtc->pipe != PIPE_A)
7299 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7301 pipe_config->dpll_hw_state.dpll_md =
7302 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7305 static void chv_prepare_pll(struct intel_crtc *crtc,
7306 const struct intel_crtc_state *pipe_config)
7308 struct drm_device *dev = crtc->base.dev;
7309 struct drm_i915_private *dev_priv = dev->dev_private;
7310 int pipe = crtc->pipe;
7311 int dpll_reg = DPLL(crtc->pipe);
7312 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7313 u32 loopfilter, tribuf_calcntr;
7314 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
7318 bestn = pipe_config->dpll.n;
7319 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7320 bestm1 = pipe_config->dpll.m1;
7321 bestm2 = pipe_config->dpll.m2 >> 22;
7322 bestp1 = pipe_config->dpll.p1;
7323 bestp2 = pipe_config->dpll.p2;
7324 vco = pipe_config->dpll.vco;
7329 * Enable Refclk and SSC
7331 I915_WRITE(dpll_reg,
7332 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
7334 mutex_lock(&dev_priv->sb_lock);
7336 /* p1 and p2 divider */
7337 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7338 5 << DPIO_CHV_S1_DIV_SHIFT |
7339 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
7340 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
7341 1 << DPIO_CHV_K_DIV_SHIFT);
7343 /* Feedback post-divider - m2 */
7344 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7346 /* Feedback refclk divider - n and m1 */
7347 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7348 DPIO_CHV_M1_DIV_BY_2 |
7349 1 << DPIO_CHV_N_DIV_SHIFT);
7351 /* M2 fraction division */
7352 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
7354 /* M2 fraction division enable */
7355 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7356 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7357 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7359 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7360 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
7362 /* Program digital lock detect threshold */
7363 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7364 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7365 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7366 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7368 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7369 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7372 if (vco == 5400000) {
7373 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7374 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7375 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7376 tribuf_calcntr = 0x9;
7377 } else if (vco <= 6200000) {
7378 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7379 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7380 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7381 tribuf_calcntr = 0x9;
7382 } else if (vco <= 6480000) {
7383 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7384 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7385 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7386 tribuf_calcntr = 0x8;
7388 /* Not supported. Apply the same limits as in the max case */
7389 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7390 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7391 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7394 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7396 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
7397 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7398 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7399 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7402 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7403 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7406 mutex_unlock(&dev_priv->sb_lock);
7410 * vlv_force_pll_on - forcibly enable just the PLL
7411 * @dev_priv: i915 private structure
7412 * @pipe: pipe PLL to enable
7413 * @dpll: PLL configuration
7415 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7416 * in cases where we need the PLL enabled even when @pipe is not going to
7419 void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe,
7420 const struct dpll *dpll)
7422 struct intel_crtc *crtc =
7423 to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe));
7424 struct intel_crtc_state pipe_config = {
7425 .base.crtc = &crtc->base,
7426 .pixel_multiplier = 1,
7430 if (IS_CHERRYVIEW(dev)) {
7431 chv_compute_dpll(crtc, &pipe_config);
7432 chv_prepare_pll(crtc, &pipe_config);
7433 chv_enable_pll(crtc, &pipe_config);
7435 vlv_compute_dpll(crtc, &pipe_config);
7436 vlv_prepare_pll(crtc, &pipe_config);
7437 vlv_enable_pll(crtc, &pipe_config);
7442 * vlv_force_pll_off - forcibly disable just the PLL
7443 * @dev_priv: i915 private structure
7444 * @pipe: pipe PLL to disable
7446 * Disable the PLL for @pipe. To be used in cases where we need
7447 * the PLL enabled even when @pipe is not going to be enabled.
7449 void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe)
7451 if (IS_CHERRYVIEW(dev))
7452 chv_disable_pll(to_i915(dev), pipe);
7454 vlv_disable_pll(to_i915(dev), pipe);
7457 static void i9xx_compute_dpll(struct intel_crtc *crtc,
7458 struct intel_crtc_state *crtc_state,
7459 intel_clock_t *reduced_clock,
7462 struct drm_device *dev = crtc->base.dev;
7463 struct drm_i915_private *dev_priv = dev->dev_private;
7466 struct dpll *clock = &crtc_state->dpll;
7468 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7470 is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7471 intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI);
7473 dpll = DPLL_VGA_MODE_DIS;
7475 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS))
7476 dpll |= DPLLB_MODE_LVDS;
7478 dpll |= DPLLB_MODE_DAC_SERIAL;
7480 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
7481 dpll |= (crtc_state->pixel_multiplier - 1)
7482 << SDVO_MULTIPLIER_SHIFT_HIRES;
7486 dpll |= DPLL_SDVO_HIGH_SPEED;
7488 if (crtc_state->has_dp_encoder)
7489 dpll |= DPLL_SDVO_HIGH_SPEED;
7491 /* compute bitmask from p1 value */
7492 if (IS_PINEVIEW(dev))
7493 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7495 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7496 if (IS_G4X(dev) && reduced_clock)
7497 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7499 switch (clock->p2) {
7501 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7504 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7507 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7510 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7513 if (INTEL_INFO(dev)->gen >= 4)
7514 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7516 if (crtc_state->sdvo_tv_clock)
7517 dpll |= PLL_REF_INPUT_TVCLKINBC;
7518 else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7519 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
7520 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7522 dpll |= PLL_REF_INPUT_DREFCLK;
7524 dpll |= DPLL_VCO_ENABLE;
7525 crtc_state->dpll_hw_state.dpll = dpll;
7527 if (INTEL_INFO(dev)->gen >= 4) {
7528 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
7529 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7530 crtc_state->dpll_hw_state.dpll_md = dpll_md;
7534 static void i8xx_compute_dpll(struct intel_crtc *crtc,
7535 struct intel_crtc_state *crtc_state,
7536 intel_clock_t *reduced_clock,
7539 struct drm_device *dev = crtc->base.dev;
7540 struct drm_i915_private *dev_priv = dev->dev_private;
7542 struct dpll *clock = &crtc_state->dpll;
7544 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7546 dpll = DPLL_VGA_MODE_DIS;
7548 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7549 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7552 dpll |= PLL_P1_DIVIDE_BY_TWO;
7554 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7556 dpll |= PLL_P2_DIVIDE_BY_4;
7559 if (!IS_I830(dev) && intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO))
7560 dpll |= DPLL_DVO_2X_MODE;
7562 if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7563 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
7564 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7566 dpll |= PLL_REF_INPUT_DREFCLK;
7568 dpll |= DPLL_VCO_ENABLE;
7569 crtc_state->dpll_hw_state.dpll = dpll;
7572 static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
7574 struct drm_device *dev = intel_crtc->base.dev;
7575 struct drm_i915_private *dev_priv = dev->dev_private;
7576 enum pipe pipe = intel_crtc->pipe;
7577 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
7578 struct drm_display_mode *adjusted_mode =
7579 &intel_crtc->config->base.adjusted_mode;
7580 uint32_t crtc_vtotal, crtc_vblank_end;
7583 /* We need to be careful not to changed the adjusted mode, for otherwise
7584 * the hw state checker will get angry at the mismatch. */
7585 crtc_vtotal = adjusted_mode->crtc_vtotal;
7586 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
7588 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
7589 /* the chip adds 2 halflines automatically */
7591 crtc_vblank_end -= 1;
7593 if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO))
7594 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7596 vsyncshift = adjusted_mode->crtc_hsync_start -
7597 adjusted_mode->crtc_htotal / 2;
7599 vsyncshift += adjusted_mode->crtc_htotal;
7602 if (INTEL_INFO(dev)->gen > 3)
7603 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
7605 I915_WRITE(HTOTAL(cpu_transcoder),
7606 (adjusted_mode->crtc_hdisplay - 1) |
7607 ((adjusted_mode->crtc_htotal - 1) << 16));
7608 I915_WRITE(HBLANK(cpu_transcoder),
7609 (adjusted_mode->crtc_hblank_start - 1) |
7610 ((adjusted_mode->crtc_hblank_end - 1) << 16));
7611 I915_WRITE(HSYNC(cpu_transcoder),
7612 (adjusted_mode->crtc_hsync_start - 1) |
7613 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7615 I915_WRITE(VTOTAL(cpu_transcoder),
7616 (adjusted_mode->crtc_vdisplay - 1) |
7617 ((crtc_vtotal - 1) << 16));
7618 I915_WRITE(VBLANK(cpu_transcoder),
7619 (adjusted_mode->crtc_vblank_start - 1) |
7620 ((crtc_vblank_end - 1) << 16));
7621 I915_WRITE(VSYNC(cpu_transcoder),
7622 (adjusted_mode->crtc_vsync_start - 1) |
7623 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7625 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7626 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7627 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7629 if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
7630 (pipe == PIPE_B || pipe == PIPE_C))
7631 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7633 /* pipesrc controls the size that is scaled from, which should
7634 * always be the user's requested size.
7636 I915_WRITE(PIPESRC(pipe),
7637 ((intel_crtc->config->pipe_src_w - 1) << 16) |
7638 (intel_crtc->config->pipe_src_h - 1));
7641 static void intel_get_pipe_timings(struct intel_crtc *crtc,
7642 struct intel_crtc_state *pipe_config)
7644 struct drm_device *dev = crtc->base.dev;
7645 struct drm_i915_private *dev_priv = dev->dev_private;
7646 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7649 tmp = I915_READ(HTOTAL(cpu_transcoder));
7650 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7651 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
7652 tmp = I915_READ(HBLANK(cpu_transcoder));
7653 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7654 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
7655 tmp = I915_READ(HSYNC(cpu_transcoder));
7656 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7657 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
7659 tmp = I915_READ(VTOTAL(cpu_transcoder));
7660 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7661 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
7662 tmp = I915_READ(VBLANK(cpu_transcoder));
7663 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7664 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
7665 tmp = I915_READ(VSYNC(cpu_transcoder));
7666 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7667 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
7669 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
7670 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7671 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7672 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
7675 tmp = I915_READ(PIPESRC(crtc->pipe));
7676 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7677 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7679 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7680 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
7683 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
7684 struct intel_crtc_state *pipe_config)
7686 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7687 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7688 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7689 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
7691 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7692 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7693 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7694 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
7696 mode->flags = pipe_config->base.adjusted_mode.flags;
7697 mode->type = DRM_MODE_TYPE_DRIVER;
7699 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
7700 mode->flags |= pipe_config->base.adjusted_mode.flags;
7702 mode->hsync = drm_mode_hsync(mode);
7703 mode->vrefresh = drm_mode_vrefresh(mode);
7704 drm_mode_set_name(mode);
7707 static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
7709 struct drm_device *dev = intel_crtc->base.dev;
7710 struct drm_i915_private *dev_priv = dev->dev_private;
7715 if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
7716 (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
7717 pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE;
7719 if (intel_crtc->config->double_wide)
7720 pipeconf |= PIPECONF_DOUBLE_WIDE;
7722 /* only g4x and later have fancy bpc/dither controls */
7723 if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
7724 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7725 if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30)
7726 pipeconf |= PIPECONF_DITHER_EN |
7727 PIPECONF_DITHER_TYPE_SP;
7729 switch (intel_crtc->config->pipe_bpp) {
7731 pipeconf |= PIPECONF_6BPC;
7734 pipeconf |= PIPECONF_8BPC;
7737 pipeconf |= PIPECONF_10BPC;
7740 /* Case prevented by intel_choose_pipe_bpp_dither. */
7745 if (HAS_PIPE_CXSR(dev)) {
7746 if (intel_crtc->lowfreq_avail) {
7747 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
7748 pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
7750 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
7754 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
7755 if (INTEL_INFO(dev)->gen < 4 ||
7756 intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO))
7757 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7759 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7761 pipeconf |= PIPECONF_PROGRESSIVE;
7763 if (IS_VALLEYVIEW(dev) && intel_crtc->config->limited_color_range)
7764 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
7766 I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
7767 POSTING_READ(PIPECONF(intel_crtc->pipe));
7770 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7771 struct intel_crtc_state *crtc_state)
7773 struct drm_device *dev = crtc->base.dev;
7774 struct drm_i915_private *dev_priv = dev->dev_private;
7775 int refclk, num_connectors = 0;
7776 intel_clock_t clock;
7778 bool is_dsi = false;
7779 struct intel_encoder *encoder;
7780 const intel_limit_t *limit;
7781 struct drm_atomic_state *state = crtc_state->base.state;
7782 struct drm_connector *connector;
7783 struct drm_connector_state *connector_state;
7786 memset(&crtc_state->dpll_hw_state, 0,
7787 sizeof(crtc_state->dpll_hw_state));
7789 for_each_connector_in_state(state, connector, connector_state, i) {
7790 if (connector_state->crtc != &crtc->base)
7793 encoder = to_intel_encoder(connector_state->best_encoder);
7795 switch (encoder->type) {
7796 case INTEL_OUTPUT_DSI:
7809 if (!crtc_state->clock_set) {
7810 refclk = i9xx_get_refclk(crtc_state, num_connectors);
7813 * Returns a set of divisors for the desired target clock with
7814 * the given refclk, or FALSE. The returned values represent
7815 * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
7818 limit = intel_limit(crtc_state, refclk);
7819 ok = dev_priv->display.find_dpll(limit, crtc_state,
7820 crtc_state->port_clock,
7821 refclk, NULL, &clock);
7823 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7827 /* Compat-code for transition, will disappear. */
7828 crtc_state->dpll.n = clock.n;
7829 crtc_state->dpll.m1 = clock.m1;
7830 crtc_state->dpll.m2 = clock.m2;
7831 crtc_state->dpll.p1 = clock.p1;
7832 crtc_state->dpll.p2 = clock.p2;
7836 i8xx_compute_dpll(crtc, crtc_state, NULL,
7838 } else if (IS_CHERRYVIEW(dev)) {
7839 chv_compute_dpll(crtc, crtc_state);
7840 } else if (IS_VALLEYVIEW(dev)) {
7841 vlv_compute_dpll(crtc, crtc_state);
7843 i9xx_compute_dpll(crtc, crtc_state, NULL,
7850 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
7851 struct intel_crtc_state *pipe_config)
7853 struct drm_device *dev = crtc->base.dev;
7854 struct drm_i915_private *dev_priv = dev->dev_private;
7857 if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev)))
7860 tmp = I915_READ(PFIT_CONTROL);
7861 if (!(tmp & PFIT_ENABLE))
7864 /* Check whether the pfit is attached to our pipe. */
7865 if (INTEL_INFO(dev)->gen < 4) {
7866 if (crtc->pipe != PIPE_B)
7869 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7873 pipe_config->gmch_pfit.control = tmp;
7874 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
7875 if (INTEL_INFO(dev)->gen < 5)
7876 pipe_config->gmch_pfit.lvds_border_bits =
7877 I915_READ(LVDS) & LVDS_BORDER_ENABLE;
7880 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
7881 struct intel_crtc_state *pipe_config)
7883 struct drm_device *dev = crtc->base.dev;
7884 struct drm_i915_private *dev_priv = dev->dev_private;
7885 int pipe = pipe_config->cpu_transcoder;
7886 intel_clock_t clock;
7888 int refclk = 100000;
7890 /* In case of MIPI DPLL will not even be used */
7891 if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE))
7894 mutex_lock(&dev_priv->sb_lock);
7895 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
7896 mutex_unlock(&dev_priv->sb_lock);
7898 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7899 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7900 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7901 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7902 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7904 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
7908 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
7909 struct intel_initial_plane_config *plane_config)
7911 struct drm_device *dev = crtc->base.dev;
7912 struct drm_i915_private *dev_priv = dev->dev_private;
7913 u32 val, base, offset;
7914 int pipe = crtc->pipe, plane = crtc->plane;
7915 int fourcc, pixel_format;
7916 unsigned int aligned_height;
7917 struct drm_framebuffer *fb;
7918 struct intel_framebuffer *intel_fb;
7920 val = I915_READ(DSPCNTR(plane));
7921 if (!(val & DISPLAY_PLANE_ENABLE))
7924 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
7926 DRM_DEBUG_KMS("failed to alloc fb\n");
7930 fb = &intel_fb->base;
7932 if (INTEL_INFO(dev)->gen >= 4) {
7933 if (val & DISPPLANE_TILED) {
7934 plane_config->tiling = I915_TILING_X;
7935 fb->modifier[0] = I915_FORMAT_MOD_X_TILED;
7939 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
7940 fourcc = i9xx_format_to_fourcc(pixel_format);
7941 fb->pixel_format = fourcc;
7942 fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8;
7944 if (INTEL_INFO(dev)->gen >= 4) {
7945 if (plane_config->tiling)
7946 offset = I915_READ(DSPTILEOFF(plane));
7948 offset = I915_READ(DSPLINOFF(plane));
7949 base = I915_READ(DSPSURF(plane)) & 0xfffff000;
7951 base = I915_READ(DSPADDR(plane));
7953 plane_config->base = base;
7955 val = I915_READ(PIPESRC(pipe));
7956 fb->width = ((val >> 16) & 0xfff) + 1;
7957 fb->height = ((val >> 0) & 0xfff) + 1;
7959 val = I915_READ(DSPSTRIDE(pipe));
7960 fb->pitches[0] = val & 0xffffffc0;
7962 aligned_height = intel_fb_align_height(dev, fb->height,
7966 plane_config->size = fb->pitches[0] * aligned_height;
7968 DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7969 pipe_name(pipe), plane, fb->width, fb->height,
7970 fb->bits_per_pixel, base, fb->pitches[0],
7971 plane_config->size);
7973 plane_config->fb = intel_fb;
7976 static void chv_crtc_clock_get(struct intel_crtc *crtc,
7977 struct intel_crtc_state *pipe_config)
7979 struct drm_device *dev = crtc->base.dev;
7980 struct drm_i915_private *dev_priv = dev->dev_private;
7981 int pipe = pipe_config->cpu_transcoder;
7982 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7983 intel_clock_t clock;
7984 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
7985 int refclk = 100000;
7987 mutex_lock(&dev_priv->sb_lock);
7988 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
7989 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
7990 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
7991 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
7992 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7993 mutex_unlock(&dev_priv->sb_lock);
7995 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
7996 clock.m2 = (pll_dw0 & 0xff) << 22;
7997 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
7998 clock.m2 |= pll_dw2 & 0x3fffff;
7999 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
8000 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
8001 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
8003 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
8006 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
8007 struct intel_crtc_state *pipe_config)
8009 struct drm_device *dev = crtc->base.dev;
8010 struct drm_i915_private *dev_priv = dev->dev_private;
8013 if (!intel_display_power_is_enabled(dev_priv,
8014 POWER_DOMAIN_PIPE(crtc->pipe)))
8017 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
8018 pipe_config->shared_dpll = DPLL_ID_PRIVATE;
8020 tmp = I915_READ(PIPECONF(crtc->pipe));
8021 if (!(tmp & PIPECONF_ENABLE))
8024 if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
8025 switch (tmp & PIPECONF_BPC_MASK) {
8027 pipe_config->pipe_bpp = 18;
8030 pipe_config->pipe_bpp = 24;
8032 case PIPECONF_10BPC:
8033 pipe_config->pipe_bpp = 30;
8040 if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT))
8041 pipe_config->limited_color_range = true;
8043 if (INTEL_INFO(dev)->gen < 4)
8044 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
8046 intel_get_pipe_timings(crtc, pipe_config);
8048 i9xx_get_pfit_config(crtc, pipe_config);
8050 if (INTEL_INFO(dev)->gen >= 4) {
8051 tmp = I915_READ(DPLL_MD(crtc->pipe));
8052 pipe_config->pixel_multiplier =
8053 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
8054 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
8055 pipe_config->dpll_hw_state.dpll_md = tmp;
8056 } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
8057 tmp = I915_READ(DPLL(crtc->pipe));
8058 pipe_config->pixel_multiplier =
8059 ((tmp & SDVO_MULTIPLIER_MASK)
8060 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
8062 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8063 * port and will be fixed up in the encoder->get_config
8065 pipe_config->pixel_multiplier = 1;
8067 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
8068 if (!IS_VALLEYVIEW(dev)) {
8070 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
8071 * on 830. Filter it out here so that we don't
8072 * report errors due to that.
8075 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
8077 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
8078 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
8080 /* Mask out read-only status bits. */
8081 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
8082 DPLL_PORTC_READY_MASK |
8083 DPLL_PORTB_READY_MASK);
8086 if (IS_CHERRYVIEW(dev))
8087 chv_crtc_clock_get(crtc, pipe_config);
8088 else if (IS_VALLEYVIEW(dev))
8089 vlv_crtc_clock_get(crtc, pipe_config);
8091 i9xx_crtc_clock_get(crtc, pipe_config);
8094 * Normally the dotclock is filled in by the encoder .get_config()
8095 * but in case the pipe is enabled w/o any ports we need a sane
8098 pipe_config->base.adjusted_mode.crtc_clock =
8099 pipe_config->port_clock / pipe_config->pixel_multiplier;
8104 static void ironlake_init_pch_refclk(struct drm_device *dev)
8106 struct drm_i915_private *dev_priv = dev->dev_private;
8107 struct intel_encoder *encoder;
8109 bool has_lvds = false;
8110 bool has_cpu_edp = false;
8111 bool has_panel = false;
8112 bool has_ck505 = false;
8113 bool can_ssc = false;
8115 /* We need to take the global config into account */
8116 for_each_intel_encoder(dev, encoder) {
8117 switch (encoder->type) {
8118 case INTEL_OUTPUT_LVDS:
8122 case INTEL_OUTPUT_EDP:
8124 if (enc_to_dig_port(&encoder->base)->port == PORT_A)
8132 if (HAS_PCH_IBX(dev)) {
8133 has_ck505 = dev_priv->vbt.display_clock_mode;
8134 can_ssc = has_ck505;
8140 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
8141 has_panel, has_lvds, has_ck505);
8143 /* Ironlake: try to setup display ref clock before DPLL
8144 * enabling. This is only under driver's control after
8145 * PCH B stepping, previous chipset stepping should be
8146 * ignoring this setting.
8148 val = I915_READ(PCH_DREF_CONTROL);
8150 /* As we must carefully and slowly disable/enable each source in turn,
8151 * compute the final state we want first and check if we need to
8152 * make any changes at all.
8155 final &= ~DREF_NONSPREAD_SOURCE_MASK;
8157 final |= DREF_NONSPREAD_CK505_ENABLE;
8159 final |= DREF_NONSPREAD_SOURCE_ENABLE;
8161 final &= ~DREF_SSC_SOURCE_MASK;
8162 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8163 final &= ~DREF_SSC1_ENABLE;
8166 final |= DREF_SSC_SOURCE_ENABLE;
8168 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8169 final |= DREF_SSC1_ENABLE;
8172 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8173 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8175 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8177 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8179 final |= DREF_SSC_SOURCE_DISABLE;
8180 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8186 /* Always enable nonspread source */
8187 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8190 val |= DREF_NONSPREAD_CK505_ENABLE;
8192 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8195 val &= ~DREF_SSC_SOURCE_MASK;
8196 val |= DREF_SSC_SOURCE_ENABLE;
8198 /* SSC must be turned on before enabling the CPU output */
8199 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8200 DRM_DEBUG_KMS("Using SSC on panel\n");
8201 val |= DREF_SSC1_ENABLE;
8203 val &= ~DREF_SSC1_ENABLE;
8205 /* Get SSC going before enabling the outputs */
8206 I915_WRITE(PCH_DREF_CONTROL, val);
8207 POSTING_READ(PCH_DREF_CONTROL);
8210 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8212 /* Enable CPU source on CPU attached eDP */
8214 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8215 DRM_DEBUG_KMS("Using SSC on eDP\n");
8216 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8218 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8220 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8222 I915_WRITE(PCH_DREF_CONTROL, val);
8223 POSTING_READ(PCH_DREF_CONTROL);
8226 DRM_DEBUG_KMS("Disabling SSC entirely\n");
8228 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8230 /* Turn off CPU output */
8231 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8233 I915_WRITE(PCH_DREF_CONTROL, val);
8234 POSTING_READ(PCH_DREF_CONTROL);
8237 /* Turn off the SSC source */
8238 val &= ~DREF_SSC_SOURCE_MASK;
8239 val |= DREF_SSC_SOURCE_DISABLE;
8242 val &= ~DREF_SSC1_ENABLE;
8244 I915_WRITE(PCH_DREF_CONTROL, val);
8245 POSTING_READ(PCH_DREF_CONTROL);
8249 BUG_ON(val != final);
8252 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
8256 tmp = I915_READ(SOUTH_CHICKEN2);
8257 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
8258 I915_WRITE(SOUTH_CHICKEN2, tmp);
8260 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
8261 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
8262 DRM_ERROR("FDI mPHY reset assert timeout\n");
8264 tmp = I915_READ(SOUTH_CHICKEN2);
8265 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
8266 I915_WRITE(SOUTH_CHICKEN2, tmp);
8268 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
8269 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
8270 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
8273 /* WaMPhyProgramming:hsw */
8274 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
8278 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
8279 tmp &= ~(0xFF << 24);
8280 tmp |= (0x12 << 24);
8281 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
8283 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
8285 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
8287 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
8289 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
8291 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
8292 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8293 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
8295 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
8296 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8297 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
8299 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
8302 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
8304 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
8307 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
8309 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
8312 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
8314 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
8317 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
8319 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
8320 tmp &= ~(0xFF << 16);
8321 tmp |= (0x1C << 16);
8322 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
8324 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
8325 tmp &= ~(0xFF << 16);
8326 tmp |= (0x1C << 16);
8327 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8329 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8331 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
8333 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8335 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
8337 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8338 tmp &= ~(0xF << 28);
8340 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
8342 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8343 tmp &= ~(0xF << 28);
8345 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
8348 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8349 * Programming" based on the parameters passed:
8350 * - Sequence to enable CLKOUT_DP
8351 * - Sequence to enable CLKOUT_DP without spread
8352 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8354 static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread,
8357 struct drm_i915_private *dev_priv = dev->dev_private;
8360 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8362 if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE &&
8363 with_fdi, "LP PCH doesn't have FDI\n"))
8366 mutex_lock(&dev_priv->sb_lock);
8368 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8369 tmp &= ~SBI_SSCCTL_DISABLE;
8370 tmp |= SBI_SSCCTL_PATHALT;
8371 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8376 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8377 tmp &= ~SBI_SSCCTL_PATHALT;
8378 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8381 lpt_reset_fdi_mphy(dev_priv);
8382 lpt_program_fdi_mphy(dev_priv);
8386 reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
8387 SBI_GEN0 : SBI_DBUFF0;
8388 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8389 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8390 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8392 mutex_unlock(&dev_priv->sb_lock);
8395 /* Sequence to disable CLKOUT_DP */
8396 static void lpt_disable_clkout_dp(struct drm_device *dev)
8398 struct drm_i915_private *dev_priv = dev->dev_private;
8401 mutex_lock(&dev_priv->sb_lock);
8403 reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
8404 SBI_GEN0 : SBI_DBUFF0;
8405 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8406 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8407 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8409 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8410 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8411 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8412 tmp |= SBI_SSCCTL_PATHALT;
8413 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8416 tmp |= SBI_SSCCTL_DISABLE;
8417 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8420 mutex_unlock(&dev_priv->sb_lock);
8423 static void lpt_init_pch_refclk(struct drm_device *dev)
8425 struct intel_encoder *encoder;
8426 bool has_vga = false;
8428 for_each_intel_encoder(dev, encoder) {
8429 switch (encoder->type) {
8430 case INTEL_OUTPUT_ANALOG:
8439 lpt_enable_clkout_dp(dev, true, true);
8441 lpt_disable_clkout_dp(dev);
8445 * Initialize reference clocks when the driver loads
8447 void intel_init_pch_refclk(struct drm_device *dev)
8449 if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
8450 ironlake_init_pch_refclk(dev);
8451 else if (HAS_PCH_LPT(dev))
8452 lpt_init_pch_refclk(dev);
8455 static int ironlake_get_refclk(struct intel_crtc_state *crtc_state)
8457 struct drm_device *dev = crtc_state->base.crtc->dev;
8458 struct drm_i915_private *dev_priv = dev->dev_private;
8459 struct drm_atomic_state *state = crtc_state->base.state;
8460 struct drm_connector *connector;
8461 struct drm_connector_state *connector_state;
8462 struct intel_encoder *encoder;
8463 int num_connectors = 0, i;
8464 bool is_lvds = false;
8466 for_each_connector_in_state(state, connector, connector_state, i) {
8467 if (connector_state->crtc != crtc_state->base.crtc)
8470 encoder = to_intel_encoder(connector_state->best_encoder);
8472 switch (encoder->type) {
8473 case INTEL_OUTPUT_LVDS:
8482 if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
8483 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8484 dev_priv->vbt.lvds_ssc_freq);
8485 return dev_priv->vbt.lvds_ssc_freq;
8491 static void ironlake_set_pipeconf(struct drm_crtc *crtc)
8493 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
8494 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8495 int pipe = intel_crtc->pipe;
8500 switch (intel_crtc->config->pipe_bpp) {
8502 val |= PIPECONF_6BPC;
8505 val |= PIPECONF_8BPC;
8508 val |= PIPECONF_10BPC;
8511 val |= PIPECONF_12BPC;
8514 /* Case prevented by intel_choose_pipe_bpp_dither. */
8518 if (intel_crtc->config->dither)
8519 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8521 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8522 val |= PIPECONF_INTERLACED_ILK;
8524 val |= PIPECONF_PROGRESSIVE;
8526 if (intel_crtc->config->limited_color_range)
8527 val |= PIPECONF_COLOR_RANGE_SELECT;
8529 I915_WRITE(PIPECONF(pipe), val);
8530 POSTING_READ(PIPECONF(pipe));
8534 * Set up the pipe CSC unit.
8536 * Currently only full range RGB to limited range RGB conversion
8537 * is supported, but eventually this should handle various
8538 * RGB<->YCbCr scenarios as well.
8540 static void intel_set_pipe_csc(struct drm_crtc *crtc)
8542 struct drm_device *dev = crtc->dev;
8543 struct drm_i915_private *dev_priv = dev->dev_private;
8544 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8545 int pipe = intel_crtc->pipe;
8546 uint16_t coeff = 0x7800; /* 1.0 */
8549 * TODO: Check what kind of values actually come out of the pipe
8550 * with these coeff/postoff values and adjust to get the best
8551 * accuracy. Perhaps we even need to take the bpc value into
8555 if (intel_crtc->config->limited_color_range)
8556 coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
8559 * GY/GU and RY/RU should be the other way around according
8560 * to BSpec, but reality doesn't agree. Just set them up in
8561 * a way that results in the correct picture.
8563 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
8564 I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
8566 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
8567 I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
8569 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
8570 I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
8572 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
8573 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
8574 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
8576 if (INTEL_INFO(dev)->gen > 6) {
8577 uint16_t postoff = 0;
8579 if (intel_crtc->config->limited_color_range)
8580 postoff = (16 * (1 << 12) / 255) & 0x1fff;
8582 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
8583 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
8584 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
8586 I915_WRITE(PIPE_CSC_MODE(pipe), 0);
8588 uint32_t mode = CSC_MODE_YUV_TO_RGB;
8590 if (intel_crtc->config->limited_color_range)
8591 mode |= CSC_BLACK_SCREEN_OFFSET;
8593 I915_WRITE(PIPE_CSC_MODE(pipe), mode);
8597 static void haswell_set_pipeconf(struct drm_crtc *crtc)
8599 struct drm_device *dev = crtc->dev;
8600 struct drm_i915_private *dev_priv = dev->dev_private;
8601 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8602 enum pipe pipe = intel_crtc->pipe;
8603 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
8608 if (IS_HASWELL(dev) && intel_crtc->config->dither)
8609 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8611 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8612 val |= PIPECONF_INTERLACED_ILK;
8614 val |= PIPECONF_PROGRESSIVE;
8616 I915_WRITE(PIPECONF(cpu_transcoder), val);
8617 POSTING_READ(PIPECONF(cpu_transcoder));
8619 I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT);
8620 POSTING_READ(GAMMA_MODE(intel_crtc->pipe));
8622 if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) {
8625 switch (intel_crtc->config->pipe_bpp) {
8627 val |= PIPEMISC_DITHER_6_BPC;
8630 val |= PIPEMISC_DITHER_8_BPC;
8633 val |= PIPEMISC_DITHER_10_BPC;
8636 val |= PIPEMISC_DITHER_12_BPC;
8639 /* Case prevented by pipe_config_set_bpp. */
8643 if (intel_crtc->config->dither)
8644 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8646 I915_WRITE(PIPEMISC(pipe), val);
8650 static bool ironlake_compute_clocks(struct drm_crtc *crtc,
8651 struct intel_crtc_state *crtc_state,
8652 intel_clock_t *clock,
8653 bool *has_reduced_clock,
8654 intel_clock_t *reduced_clock)
8656 struct drm_device *dev = crtc->dev;
8657 struct drm_i915_private *dev_priv = dev->dev_private;
8659 const intel_limit_t *limit;
8662 refclk = ironlake_get_refclk(crtc_state);
8665 * Returns a set of divisors for the desired target clock with the given
8666 * refclk, or FALSE. The returned values represent the clock equation:
8667 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
8669 limit = intel_limit(crtc_state, refclk);
8670 ret = dev_priv->display.find_dpll(limit, crtc_state,
8671 crtc_state->port_clock,
8672 refclk, NULL, clock);
8679 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8682 * Account for spread spectrum to avoid
8683 * oversubscribing the link. Max center spread
8684 * is 2.5%; use 5% for safety's sake.
8686 u32 bps = target_clock * bpp * 21 / 20;
8687 return DIV_ROUND_UP(bps, link_bw * 8);
8690 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
8692 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
8695 static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8696 struct intel_crtc_state *crtc_state,
8698 intel_clock_t *reduced_clock, u32 *fp2)
8700 struct drm_crtc *crtc = &intel_crtc->base;
8701 struct drm_device *dev = crtc->dev;
8702 struct drm_i915_private *dev_priv = dev->dev_private;
8703 struct drm_atomic_state *state = crtc_state->base.state;
8704 struct drm_connector *connector;
8705 struct drm_connector_state *connector_state;
8706 struct intel_encoder *encoder;
8708 int factor, num_connectors = 0, i;
8709 bool is_lvds = false, is_sdvo = false;
8711 for_each_connector_in_state(state, connector, connector_state, i) {
8712 if (connector_state->crtc != crtc_state->base.crtc)
8715 encoder = to_intel_encoder(connector_state->best_encoder);
8717 switch (encoder->type) {
8718 case INTEL_OUTPUT_LVDS:
8721 case INTEL_OUTPUT_SDVO:
8722 case INTEL_OUTPUT_HDMI:
8732 /* Enable autotuning of the PLL clock (if permissible) */
8735 if ((intel_panel_use_ssc(dev_priv) &&
8736 dev_priv->vbt.lvds_ssc_freq == 100000) ||
8737 (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev)))
8739 } else if (crtc_state->sdvo_tv_clock)
8742 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8745 if (fp2 && (reduced_clock->m < factor * reduced_clock->n))
8751 dpll |= DPLLB_MODE_LVDS;
8753 dpll |= DPLLB_MODE_DAC_SERIAL;
8755 dpll |= (crtc_state->pixel_multiplier - 1)
8756 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
8759 dpll |= DPLL_SDVO_HIGH_SPEED;
8760 if (crtc_state->has_dp_encoder)
8761 dpll |= DPLL_SDVO_HIGH_SPEED;
8763 /* compute bitmask from p1 value */
8764 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8766 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8768 switch (crtc_state->dpll.p2) {
8770 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8773 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8776 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8779 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8783 if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
8784 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8786 dpll |= PLL_REF_INPUT_DREFCLK;
8788 return dpll | DPLL_VCO_ENABLE;
8791 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8792 struct intel_crtc_state *crtc_state)
8794 struct drm_device *dev = crtc->base.dev;
8795 intel_clock_t clock, reduced_clock;
8796 u32 dpll = 0, fp = 0, fp2 = 0;
8797 bool ok, has_reduced_clock = false;
8798 bool is_lvds = false;
8799 struct intel_shared_dpll *pll;
8801 memset(&crtc_state->dpll_hw_state, 0,
8802 sizeof(crtc_state->dpll_hw_state));
8804 is_lvds = intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS);
8806 WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
8807 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
8809 ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock,
8810 &has_reduced_clock, &reduced_clock);
8811 if (!ok && !crtc_state->clock_set) {
8812 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8815 /* Compat-code for transition, will disappear. */
8816 if (!crtc_state->clock_set) {
8817 crtc_state->dpll.n = clock.n;
8818 crtc_state->dpll.m1 = clock.m1;
8819 crtc_state->dpll.m2 = clock.m2;
8820 crtc_state->dpll.p1 = clock.p1;
8821 crtc_state->dpll.p2 = clock.p2;
8824 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8825 if (crtc_state->has_pch_encoder) {
8826 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
8827 if (has_reduced_clock)
8828 fp2 = i9xx_dpll_compute_fp(&reduced_clock);
8830 dpll = ironlake_compute_dpll(crtc, crtc_state,
8831 &fp, &reduced_clock,
8832 has_reduced_clock ? &fp2 : NULL);
8834 crtc_state->dpll_hw_state.dpll = dpll;
8835 crtc_state->dpll_hw_state.fp0 = fp;
8836 if (has_reduced_clock)
8837 crtc_state->dpll_hw_state.fp1 = fp2;
8839 crtc_state->dpll_hw_state.fp1 = fp;
8841 pll = intel_get_shared_dpll(crtc, crtc_state);
8843 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8844 pipe_name(crtc->pipe));
8849 if (is_lvds && has_reduced_clock)
8850 crtc->lowfreq_avail = true;
8852 crtc->lowfreq_avail = false;
8857 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8858 struct intel_link_m_n *m_n)
8860 struct drm_device *dev = crtc->base.dev;
8861 struct drm_i915_private *dev_priv = dev->dev_private;
8862 enum pipe pipe = crtc->pipe;
8864 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8865 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8866 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8868 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8869 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8870 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8873 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8874 enum transcoder transcoder,
8875 struct intel_link_m_n *m_n,
8876 struct intel_link_m_n *m2_n2)
8878 struct drm_device *dev = crtc->base.dev;
8879 struct drm_i915_private *dev_priv = dev->dev_private;
8880 enum pipe pipe = crtc->pipe;
8882 if (INTEL_INFO(dev)->gen >= 5) {
8883 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
8884 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
8885 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
8887 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
8888 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
8889 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8890 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8891 * gen < 8) and if DRRS is supported (to make sure the
8892 * registers are not unnecessarily read).
8894 if (m2_n2 && INTEL_INFO(dev)->gen < 8 &&
8895 crtc->config->has_drrs) {
8896 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
8897 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
8898 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
8900 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
8901 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
8902 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8905 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
8906 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
8907 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
8909 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
8910 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
8911 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8915 void intel_dp_get_m_n(struct intel_crtc *crtc,
8916 struct intel_crtc_state *pipe_config)
8918 if (pipe_config->has_pch_encoder)
8919 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
8921 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8922 &pipe_config->dp_m_n,
8923 &pipe_config->dp_m2_n2);
8926 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
8927 struct intel_crtc_state *pipe_config)
8929 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8930 &pipe_config->fdi_m_n, NULL);
8933 static void skylake_get_pfit_config(struct intel_crtc *crtc,
8934 struct intel_crtc_state *pipe_config)
8936 struct drm_device *dev = crtc->base.dev;
8937 struct drm_i915_private *dev_priv = dev->dev_private;
8938 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
8939 uint32_t ps_ctrl = 0;
8943 /* find scaler attached to this pipe */
8944 for (i = 0; i < crtc->num_scalers; i++) {
8945 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
8946 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
8948 pipe_config->pch_pfit.enabled = true;
8949 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
8950 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
8955 scaler_state->scaler_id = id;
8957 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
8959 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
8964 skylake_get_initial_plane_config(struct intel_crtc *crtc,
8965 struct intel_initial_plane_config *plane_config)
8967 struct drm_device *dev = crtc->base.dev;
8968 struct drm_i915_private *dev_priv = dev->dev_private;
8969 u32 val, base, offset, stride_mult, tiling;
8970 int pipe = crtc->pipe;
8971 int fourcc, pixel_format;
8972 unsigned int aligned_height;
8973 struct drm_framebuffer *fb;
8974 struct intel_framebuffer *intel_fb;
8976 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8978 DRM_DEBUG_KMS("failed to alloc fb\n");
8982 fb = &intel_fb->base;
8984 val = I915_READ(PLANE_CTL(pipe, 0));
8985 if (!(val & PLANE_CTL_ENABLE))
8988 pixel_format = val & PLANE_CTL_FORMAT_MASK;
8989 fourcc = skl_format_to_fourcc(pixel_format,
8990 val & PLANE_CTL_ORDER_RGBX,
8991 val & PLANE_CTL_ALPHA_MASK);
8992 fb->pixel_format = fourcc;
8993 fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8;
8995 tiling = val & PLANE_CTL_TILED_MASK;
8997 case PLANE_CTL_TILED_LINEAR:
8998 fb->modifier[0] = DRM_FORMAT_MOD_NONE;
9000 case PLANE_CTL_TILED_X:
9001 plane_config->tiling = I915_TILING_X;
9002 fb->modifier[0] = I915_FORMAT_MOD_X_TILED;
9004 case PLANE_CTL_TILED_Y:
9005 fb->modifier[0] = I915_FORMAT_MOD_Y_TILED;
9007 case PLANE_CTL_TILED_YF:
9008 fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED;
9011 MISSING_CASE(tiling);
9015 base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000;
9016 plane_config->base = base;
9018 offset = I915_READ(PLANE_OFFSET(pipe, 0));
9020 val = I915_READ(PLANE_SIZE(pipe, 0));
9021 fb->height = ((val >> 16) & 0xfff) + 1;
9022 fb->width = ((val >> 0) & 0x1fff) + 1;
9024 val = I915_READ(PLANE_STRIDE(pipe, 0));
9025 stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0],
9027 fb->pitches[0] = (val & 0x3ff) * stride_mult;
9029 aligned_height = intel_fb_align_height(dev, fb->height,
9033 plane_config->size = fb->pitches[0] * aligned_height;
9035 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9036 pipe_name(pipe), fb->width, fb->height,
9037 fb->bits_per_pixel, base, fb->pitches[0],
9038 plane_config->size);
9040 plane_config->fb = intel_fb;
9047 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
9048 struct intel_crtc_state *pipe_config)
9050 struct drm_device *dev = crtc->base.dev;
9051 struct drm_i915_private *dev_priv = dev->dev_private;
9054 tmp = I915_READ(PF_CTL(crtc->pipe));
9056 if (tmp & PF_ENABLE) {
9057 pipe_config->pch_pfit.enabled = true;
9058 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
9059 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
9061 /* We currently do not free assignements of panel fitters on
9062 * ivb/hsw (since we don't use the higher upscaling modes which
9063 * differentiates them) so just WARN about this case for now. */
9065 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
9066 PF_PIPE_SEL_IVB(crtc->pipe));
9072 ironlake_get_initial_plane_config(struct intel_crtc *crtc,
9073 struct intel_initial_plane_config *plane_config)
9075 struct drm_device *dev = crtc->base.dev;
9076 struct drm_i915_private *dev_priv = dev->dev_private;
9077 u32 val, base, offset;
9078 int pipe = crtc->pipe;
9079 int fourcc, pixel_format;
9080 unsigned int aligned_height;
9081 struct drm_framebuffer *fb;
9082 struct intel_framebuffer *intel_fb;
9084 val = I915_READ(DSPCNTR(pipe));
9085 if (!(val & DISPLAY_PLANE_ENABLE))
9088 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9090 DRM_DEBUG_KMS("failed to alloc fb\n");
9094 fb = &intel_fb->base;
9096 if (INTEL_INFO(dev)->gen >= 4) {
9097 if (val & DISPPLANE_TILED) {
9098 plane_config->tiling = I915_TILING_X;
9099 fb->modifier[0] = I915_FORMAT_MOD_X_TILED;
9103 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
9104 fourcc = i9xx_format_to_fourcc(pixel_format);
9105 fb->pixel_format = fourcc;
9106 fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8;
9108 base = I915_READ(DSPSURF(pipe)) & 0xfffff000;
9109 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
9110 offset = I915_READ(DSPOFFSET(pipe));
9112 if (plane_config->tiling)
9113 offset = I915_READ(DSPTILEOFF(pipe));
9115 offset = I915_READ(DSPLINOFF(pipe));
9117 plane_config->base = base;
9119 val = I915_READ(PIPESRC(pipe));
9120 fb->width = ((val >> 16) & 0xfff) + 1;
9121 fb->height = ((val >> 0) & 0xfff) + 1;
9123 val = I915_READ(DSPSTRIDE(pipe));
9124 fb->pitches[0] = val & 0xffffffc0;
9126 aligned_height = intel_fb_align_height(dev, fb->height,
9130 plane_config->size = fb->pitches[0] * aligned_height;
9132 DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9133 pipe_name(pipe), fb->width, fb->height,
9134 fb->bits_per_pixel, base, fb->pitches[0],
9135 plane_config->size);
9137 plane_config->fb = intel_fb;
9140 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
9141 struct intel_crtc_state *pipe_config)
9143 struct drm_device *dev = crtc->base.dev;
9144 struct drm_i915_private *dev_priv = dev->dev_private;
9147 if (!intel_display_power_is_enabled(dev_priv,
9148 POWER_DOMAIN_PIPE(crtc->pipe)))
9151 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9152 pipe_config->shared_dpll = DPLL_ID_PRIVATE;
9154 tmp = I915_READ(PIPECONF(crtc->pipe));
9155 if (!(tmp & PIPECONF_ENABLE))
9158 switch (tmp & PIPECONF_BPC_MASK) {
9160 pipe_config->pipe_bpp = 18;
9163 pipe_config->pipe_bpp = 24;
9165 case PIPECONF_10BPC:
9166 pipe_config->pipe_bpp = 30;
9168 case PIPECONF_12BPC:
9169 pipe_config->pipe_bpp = 36;
9175 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
9176 pipe_config->limited_color_range = true;
9178 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
9179 struct intel_shared_dpll *pll;
9181 pipe_config->has_pch_encoder = true;
9183 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
9184 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9185 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9187 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9189 if (HAS_PCH_IBX(dev_priv->dev)) {
9190 pipe_config->shared_dpll =
9191 (enum intel_dpll_id) crtc->pipe;
9193 tmp = I915_READ(PCH_DPLL_SEL);
9194 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
9195 pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B;
9197 pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A;
9200 pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
9202 WARN_ON(!pll->get_hw_state(dev_priv, pll,
9203 &pipe_config->dpll_hw_state));
9205 tmp = pipe_config->dpll_hw_state.dpll;
9206 pipe_config->pixel_multiplier =
9207 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
9208 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
9210 ironlake_pch_clock_get(crtc, pipe_config);
9212 pipe_config->pixel_multiplier = 1;
9215 intel_get_pipe_timings(crtc, pipe_config);
9217 ironlake_get_pfit_config(crtc, pipe_config);
9222 static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
9224 struct drm_device *dev = dev_priv->dev;
9225 struct intel_crtc *crtc;
9227 for_each_intel_crtc(dev, crtc)
9228 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
9229 pipe_name(crtc->pipe));
9231 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n");
9232 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
9233 I915_STATE_WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
9234 I915_STATE_WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
9235 I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n");
9236 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
9237 "CPU PWM1 enabled\n");
9238 if (IS_HASWELL(dev))
9239 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
9240 "CPU PWM2 enabled\n");
9241 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
9242 "PCH PWM1 enabled\n");
9243 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
9244 "Utility pin enabled\n");
9245 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
9248 * In theory we can still leave IRQs enabled, as long as only the HPD
9249 * interrupts remain enabled. We used to check for that, but since it's
9250 * gen-specific and since we only disable LCPLL after we fully disable
9251 * the interrupts, the check below should be enough.
9253 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
9256 static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
9258 struct drm_device *dev = dev_priv->dev;
9260 if (IS_HASWELL(dev))
9261 return I915_READ(D_COMP_HSW);
9263 return I915_READ(D_COMP_BDW);
9266 static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
9268 struct drm_device *dev = dev_priv->dev;
9270 if (IS_HASWELL(dev)) {
9271 mutex_lock(&dev_priv->rps.hw_lock);
9272 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
9274 DRM_ERROR("Failed to write to D_COMP\n");
9275 mutex_unlock(&dev_priv->rps.hw_lock);
9277 I915_WRITE(D_COMP_BDW, val);
9278 POSTING_READ(D_COMP_BDW);
9283 * This function implements pieces of two sequences from BSpec:
9284 * - Sequence for display software to disable LCPLL
9285 * - Sequence for display software to allow package C8+
9286 * The steps implemented here are just the steps that actually touch the LCPLL
9287 * register. Callers should take care of disabling all the display engine
9288 * functions, doing the mode unset, fixing interrupts, etc.
9290 static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
9291 bool switch_to_fclk, bool allow_power_down)
9295 assert_can_disable_lcpll(dev_priv);
9297 val = I915_READ(LCPLL_CTL);
9299 if (switch_to_fclk) {
9300 val |= LCPLL_CD_SOURCE_FCLK;
9301 I915_WRITE(LCPLL_CTL, val);
9303 if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
9304 LCPLL_CD_SOURCE_FCLK_DONE, 1))
9305 DRM_ERROR("Switching to FCLK failed\n");
9307 val = I915_READ(LCPLL_CTL);
9310 val |= LCPLL_PLL_DISABLE;
9311 I915_WRITE(LCPLL_CTL, val);
9312 POSTING_READ(LCPLL_CTL);
9314 if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1))
9315 DRM_ERROR("LCPLL still locked\n");
9317 val = hsw_read_dcomp(dev_priv);
9318 val |= D_COMP_COMP_DISABLE;
9319 hsw_write_dcomp(dev_priv, val);
9322 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
9324 DRM_ERROR("D_COMP RCOMP still in progress\n");
9326 if (allow_power_down) {
9327 val = I915_READ(LCPLL_CTL);
9328 val |= LCPLL_POWER_DOWN_ALLOW;
9329 I915_WRITE(LCPLL_CTL, val);
9330 POSTING_READ(LCPLL_CTL);
9335 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9338 static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
9342 val = I915_READ(LCPLL_CTL);
9344 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
9345 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
9349 * Make sure we're not on PC8 state before disabling PC8, otherwise
9350 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
9352 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
9354 if (val & LCPLL_POWER_DOWN_ALLOW) {
9355 val &= ~LCPLL_POWER_DOWN_ALLOW;
9356 I915_WRITE(LCPLL_CTL, val);
9357 POSTING_READ(LCPLL_CTL);
9360 val = hsw_read_dcomp(dev_priv);
9361 val |= D_COMP_COMP_FORCE;
9362 val &= ~D_COMP_COMP_DISABLE;
9363 hsw_write_dcomp(dev_priv, val);
9365 val = I915_READ(LCPLL_CTL);
9366 val &= ~LCPLL_PLL_DISABLE;
9367 I915_WRITE(LCPLL_CTL, val);
9369 if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5))
9370 DRM_ERROR("LCPLL not locked yet\n");
9372 if (val & LCPLL_CD_SOURCE_FCLK) {
9373 val = I915_READ(LCPLL_CTL);
9374 val &= ~LCPLL_CD_SOURCE_FCLK;
9375 I915_WRITE(LCPLL_CTL, val);
9377 if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
9378 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
9379 DRM_ERROR("Switching back to LCPLL failed\n");
9382 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
9383 intel_update_cdclk(dev_priv->dev);
9387 * Package states C8 and deeper are really deep PC states that can only be
9388 * reached when all the devices on the system allow it, so even if the graphics
9389 * device allows PC8+, it doesn't mean the system will actually get to these
9390 * states. Our driver only allows PC8+ when going into runtime PM.
9392 * The requirements for PC8+ are that all the outputs are disabled, the power
9393 * well is disabled and most interrupts are disabled, and these are also
9394 * requirements for runtime PM. When these conditions are met, we manually do
9395 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9396 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9399 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9400 * the state of some registers, so when we come back from PC8+ we need to
9401 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9402 * need to take care of the registers kept by RC6. Notice that this happens even
9403 * if we don't put the device in PCI D3 state (which is what currently happens
9404 * because of the runtime PM support).
9406 * For more, read "Display Sequences for Package C8" on the hardware
9409 void hsw_enable_pc8(struct drm_i915_private *dev_priv)
9411 struct drm_device *dev = dev_priv->dev;
9414 DRM_DEBUG_KMS("Enabling package C8+\n");
9416 if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
9417 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9418 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
9419 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9422 lpt_disable_clkout_dp(dev);
9423 hsw_disable_lcpll(dev_priv, true, true);
9426 void hsw_disable_pc8(struct drm_i915_private *dev_priv)
9428 struct drm_device *dev = dev_priv->dev;
9431 DRM_DEBUG_KMS("Disabling package C8+\n");
9433 hsw_restore_lcpll(dev_priv);
9434 lpt_init_pch_refclk(dev);
9436 if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
9437 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9438 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9439 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9442 intel_prepare_ddi(dev);
9445 static void broxton_modeset_commit_cdclk(struct drm_atomic_state *old_state)
9447 struct drm_device *dev = old_state->dev;
9448 unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk;
9450 broxton_set_cdclk(dev, req_cdclk);
9453 /* compute the max rate for new configuration */
9454 static int ilk_max_pixel_rate(struct drm_atomic_state *state)
9456 struct intel_crtc *intel_crtc;
9457 struct intel_crtc_state *crtc_state;
9458 int max_pixel_rate = 0;
9460 for_each_intel_crtc(state->dev, intel_crtc) {
9463 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
9464 if (IS_ERR(crtc_state))
9465 return PTR_ERR(crtc_state);
9467 if (!crtc_state->base.enable)
9470 pixel_rate = ilk_pipe_pixel_rate(crtc_state);
9472 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
9473 if (IS_BROADWELL(state->dev) && crtc_state->ips_enabled)
9474 pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95);
9476 max_pixel_rate = max(max_pixel_rate, pixel_rate);
9479 return max_pixel_rate;
9482 static void broadwell_set_cdclk(struct drm_device *dev, int cdclk)
9484 struct drm_i915_private *dev_priv = dev->dev_private;
9488 if (WARN((I915_READ(LCPLL_CTL) &
9489 (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK |
9490 LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE |
9491 LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW |
9492 LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK,
9493 "trying to change cdclk frequency with cdclk not enabled\n"))
9496 mutex_lock(&dev_priv->rps.hw_lock);
9497 ret = sandybridge_pcode_write(dev_priv,
9498 BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0);
9499 mutex_unlock(&dev_priv->rps.hw_lock);
9501 DRM_ERROR("failed to inform pcode about cdclk change\n");
9505 val = I915_READ(LCPLL_CTL);
9506 val |= LCPLL_CD_SOURCE_FCLK;
9507 I915_WRITE(LCPLL_CTL, val);
9509 if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
9510 LCPLL_CD_SOURCE_FCLK_DONE, 1))
9511 DRM_ERROR("Switching to FCLK failed\n");
9513 val = I915_READ(LCPLL_CTL);
9514 val &= ~LCPLL_CLK_FREQ_MASK;
9518 val |= LCPLL_CLK_FREQ_450;
9522 val |= LCPLL_CLK_FREQ_54O_BDW;
9526 val |= LCPLL_CLK_FREQ_337_5_BDW;
9530 val |= LCPLL_CLK_FREQ_675_BDW;
9534 WARN(1, "invalid cdclk frequency\n");
9538 I915_WRITE(LCPLL_CTL, val);
9540 val = I915_READ(LCPLL_CTL);
9541 val &= ~LCPLL_CD_SOURCE_FCLK;
9542 I915_WRITE(LCPLL_CTL, val);
9544 if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
9545 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
9546 DRM_ERROR("Switching back to LCPLL failed\n");
9548 mutex_lock(&dev_priv->rps.hw_lock);
9549 sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data);
9550 mutex_unlock(&dev_priv->rps.hw_lock);
9552 intel_update_cdclk(dev);
9554 WARN(cdclk != dev_priv->cdclk_freq,
9555 "cdclk requested %d kHz but got %d kHz\n",
9556 cdclk, dev_priv->cdclk_freq);
9559 static int broadwell_modeset_calc_cdclk(struct drm_atomic_state *state)
9561 struct drm_i915_private *dev_priv = to_i915(state->dev);
9562 int max_pixclk = ilk_max_pixel_rate(state);
9566 * FIXME should also account for plane ratio
9567 * once 64bpp pixel formats are supported.
9569 if (max_pixclk > 540000)
9571 else if (max_pixclk > 450000)
9573 else if (max_pixclk > 337500)
9579 * FIXME move the cdclk caclulation to
9580 * compute_config() so we can fail gracegully.
9582 if (cdclk > dev_priv->max_cdclk_freq) {
9583 DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n",
9584 cdclk, dev_priv->max_cdclk_freq);
9585 cdclk = dev_priv->max_cdclk_freq;
9588 to_intel_atomic_state(state)->cdclk = cdclk;
9593 static void broadwell_modeset_commit_cdclk(struct drm_atomic_state *old_state)
9595 struct drm_device *dev = old_state->dev;
9596 unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk;
9598 broadwell_set_cdclk(dev, req_cdclk);
9601 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9602 struct intel_crtc_state *crtc_state)
9604 if (!intel_ddi_pll_select(crtc, crtc_state))
9607 crtc->lowfreq_avail = false;
9612 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9614 struct intel_crtc_state *pipe_config)
9618 pipe_config->ddi_pll_sel = SKL_DPLL0;
9619 pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1;
9622 pipe_config->ddi_pll_sel = SKL_DPLL1;
9623 pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2;
9626 pipe_config->ddi_pll_sel = SKL_DPLL2;
9627 pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3;
9630 DRM_ERROR("Incorrect port type\n");
9634 static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9636 struct intel_crtc_state *pipe_config)
9638 u32 temp, dpll_ctl1;
9640 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
9641 pipe_config->ddi_pll_sel = temp >> (port * 3 + 1);
9643 switch (pipe_config->ddi_pll_sel) {
9646 * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part
9647 * of the shared DPLL framework and thus needs to be read out
9650 dpll_ctl1 = I915_READ(DPLL_CTRL1);
9651 pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f;
9654 pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1;
9657 pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2;
9660 pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3;
9665 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9667 struct intel_crtc_state *pipe_config)
9669 pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
9671 switch (pipe_config->ddi_pll_sel) {
9672 case PORT_CLK_SEL_WRPLL1:
9673 pipe_config->shared_dpll = DPLL_ID_WRPLL1;
9675 case PORT_CLK_SEL_WRPLL2:
9676 pipe_config->shared_dpll = DPLL_ID_WRPLL2;
9681 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
9682 struct intel_crtc_state *pipe_config)
9684 struct drm_device *dev = crtc->base.dev;
9685 struct drm_i915_private *dev_priv = dev->dev_private;
9686 struct intel_shared_dpll *pll;
9690 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9692 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9694 if (IS_SKYLAKE(dev))
9695 skylake_get_ddi_pll(dev_priv, port, pipe_config);
9696 else if (IS_BROXTON(dev))
9697 bxt_get_ddi_pll(dev_priv, port, pipe_config);
9699 haswell_get_ddi_pll(dev_priv, port, pipe_config);
9701 if (pipe_config->shared_dpll >= 0) {
9702 pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
9704 WARN_ON(!pll->get_hw_state(dev_priv, pll,
9705 &pipe_config->dpll_hw_state));
9709 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9710 * DDI E. So just check whether this pipe is wired to DDI E and whether
9711 * the PCH transcoder is on.
9713 if (INTEL_INFO(dev)->gen < 9 &&
9714 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
9715 pipe_config->has_pch_encoder = true;
9717 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9718 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9719 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9721 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9725 static bool haswell_get_pipe_config(struct intel_crtc *crtc,
9726 struct intel_crtc_state *pipe_config)
9728 struct drm_device *dev = crtc->base.dev;
9729 struct drm_i915_private *dev_priv = dev->dev_private;
9730 enum intel_display_power_domain pfit_domain;
9733 if (!intel_display_power_is_enabled(dev_priv,
9734 POWER_DOMAIN_PIPE(crtc->pipe)))
9737 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9738 pipe_config->shared_dpll = DPLL_ID_PRIVATE;
9740 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
9741 if (tmp & TRANS_DDI_FUNC_ENABLE) {
9742 enum pipe trans_edp_pipe;
9743 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9745 WARN(1, "unknown pipe linked to edp transcoder\n");
9746 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9747 case TRANS_DDI_EDP_INPUT_A_ON:
9748 trans_edp_pipe = PIPE_A;
9750 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9751 trans_edp_pipe = PIPE_B;
9753 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9754 trans_edp_pipe = PIPE_C;
9758 if (trans_edp_pipe == crtc->pipe)
9759 pipe_config->cpu_transcoder = TRANSCODER_EDP;
9762 if (!intel_display_power_is_enabled(dev_priv,
9763 POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
9766 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9767 if (!(tmp & PIPECONF_ENABLE))
9770 haswell_get_ddi_port_state(crtc, pipe_config);
9772 intel_get_pipe_timings(crtc, pipe_config);
9774 if (INTEL_INFO(dev)->gen >= 9) {
9775 skl_init_scalers(dev, crtc, pipe_config);
9778 pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9780 if (INTEL_INFO(dev)->gen >= 9) {
9781 pipe_config->scaler_state.scaler_id = -1;
9782 pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX);
9785 if (intel_display_power_is_enabled(dev_priv, pfit_domain)) {
9786 if (INTEL_INFO(dev)->gen == 9)
9787 skylake_get_pfit_config(crtc, pipe_config);
9788 else if (INTEL_INFO(dev)->gen < 9)
9789 ironlake_get_pfit_config(crtc, pipe_config);
9791 MISSING_CASE(INTEL_INFO(dev)->gen);
9794 if (IS_HASWELL(dev))
9795 pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) &&
9796 (I915_READ(IPS_CTL) & IPS_ENABLE);
9798 if (pipe_config->cpu_transcoder != TRANSCODER_EDP) {
9799 pipe_config->pixel_multiplier =
9800 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9802 pipe_config->pixel_multiplier = 1;
9808 static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
9810 struct drm_device *dev = crtc->dev;
9811 struct drm_i915_private *dev_priv = dev->dev_private;
9812 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
9813 uint32_t cntl = 0, size = 0;
9816 unsigned int width = intel_crtc->base.cursor->state->crtc_w;
9817 unsigned int height = intel_crtc->base.cursor->state->crtc_h;
9818 unsigned int stride = roundup_pow_of_two(width) * 4;
9822 WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
9833 cntl |= CURSOR_ENABLE |
9834 CURSOR_GAMMA_ENABLE |
9835 CURSOR_FORMAT_ARGB |
9836 CURSOR_STRIDE(stride);
9838 size = (height << 12) | width;
9841 if (intel_crtc->cursor_cntl != 0 &&
9842 (intel_crtc->cursor_base != base ||
9843 intel_crtc->cursor_size != size ||
9844 intel_crtc->cursor_cntl != cntl)) {
9845 /* On these chipsets we can only modify the base/size/stride
9846 * whilst the cursor is disabled.
9848 I915_WRITE(_CURACNTR, 0);
9849 POSTING_READ(_CURACNTR);
9850 intel_crtc->cursor_cntl = 0;
9853 if (intel_crtc->cursor_base != base) {
9854 I915_WRITE(_CURABASE, base);
9855 intel_crtc->cursor_base = base;
9858 if (intel_crtc->cursor_size != size) {
9859 I915_WRITE(CURSIZE, size);
9860 intel_crtc->cursor_size = size;
9863 if (intel_crtc->cursor_cntl != cntl) {
9864 I915_WRITE(_CURACNTR, cntl);
9865 POSTING_READ(_CURACNTR);
9866 intel_crtc->cursor_cntl = cntl;
9870 static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
9872 struct drm_device *dev = crtc->dev;
9873 struct drm_i915_private *dev_priv = dev->dev_private;
9874 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
9875 int pipe = intel_crtc->pipe;
9880 cntl = MCURSOR_GAMMA_ENABLE;
9881 switch (intel_crtc->base.cursor->state->crtc_w) {
9883 cntl |= CURSOR_MODE_64_ARGB_AX;
9886 cntl |= CURSOR_MODE_128_ARGB_AX;
9889 cntl |= CURSOR_MODE_256_ARGB_AX;
9892 MISSING_CASE(intel_crtc->base.cursor->state->crtc_w);
9895 cntl |= pipe << 28; /* Connect to correct pipe */
9897 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
9898 cntl |= CURSOR_PIPE_CSC_ENABLE;
9901 if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180))
9902 cntl |= CURSOR_ROTATE_180;
9904 if (intel_crtc->cursor_cntl != cntl) {
9905 I915_WRITE(CURCNTR(pipe), cntl);
9906 POSTING_READ(CURCNTR(pipe));
9907 intel_crtc->cursor_cntl = cntl;
9910 /* and commit changes on next vblank */
9911 I915_WRITE(CURBASE(pipe), base);
9912 POSTING_READ(CURBASE(pipe));
9914 intel_crtc->cursor_base = base;
9917 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
9918 static void intel_crtc_update_cursor(struct drm_crtc *crtc,
9921 struct drm_device *dev = crtc->dev;
9922 struct drm_i915_private *dev_priv = dev->dev_private;
9923 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
9924 int pipe = intel_crtc->pipe;
9925 int x = crtc->cursor_x;
9926 int y = crtc->cursor_y;
9927 u32 base = 0, pos = 0;
9930 base = intel_crtc->cursor_addr;
9932 if (x >= intel_crtc->config->pipe_src_w)
9935 if (y >= intel_crtc->config->pipe_src_h)
9939 if (x + intel_crtc->base.cursor->state->crtc_w <= 0)
9942 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
9945 pos |= x << CURSOR_X_SHIFT;
9948 if (y + intel_crtc->base.cursor->state->crtc_h <= 0)
9951 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
9954 pos |= y << CURSOR_Y_SHIFT;
9956 if (base == 0 && intel_crtc->cursor_base == 0)
9959 I915_WRITE(CURPOS(pipe), pos);
9961 /* ILK+ do this automagically */
9962 if (HAS_GMCH_DISPLAY(dev) &&
9963 crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) {
9964 base += (intel_crtc->base.cursor->state->crtc_h *
9965 intel_crtc->base.cursor->state->crtc_w - 1) * 4;
9968 if (IS_845G(dev) || IS_I865G(dev))
9969 i845_update_cursor(crtc, base);
9971 i9xx_update_cursor(crtc, base);
9974 static bool cursor_size_ok(struct drm_device *dev,
9975 uint32_t width, uint32_t height)
9977 if (width == 0 || height == 0)
9981 * 845g/865g are special in that they are only limited by
9982 * the width of their cursors, the height is arbitrary up to
9983 * the precision of the register. Everything else requires
9984 * square cursors, limited to a few power-of-two sizes.
9986 if (IS_845G(dev) || IS_I865G(dev)) {
9987 if ((width & 63) != 0)
9990 if (width > (IS_845G(dev) ? 64 : 512))
9996 switch (width | height) {
10011 static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
10012 u16 *blue, uint32_t start, uint32_t size)
10014 int end = (start + size > 256) ? 256 : start + size, i;
10015 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10017 for (i = start; i < end; i++) {
10018 intel_crtc->lut_r[i] = red[i] >> 8;
10019 intel_crtc->lut_g[i] = green[i] >> 8;
10020 intel_crtc->lut_b[i] = blue[i] >> 8;
10023 intel_crtc_load_lut(crtc);
10026 /* VESA 640x480x72Hz mode to set on the pipe */
10027 static struct drm_display_mode load_detect_mode = {
10028 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
10029 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
10032 struct drm_framebuffer *
10033 __intel_framebuffer_create(struct drm_device *dev,
10034 struct drm_mode_fb_cmd2 *mode_cmd,
10035 struct drm_i915_gem_object *obj)
10037 struct intel_framebuffer *intel_fb;
10040 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
10042 drm_gem_object_unreference(&obj->base);
10043 return ERR_PTR(-ENOMEM);
10046 ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
10050 return &intel_fb->base;
10052 drm_gem_object_unreference(&obj->base);
10055 return ERR_PTR(ret);
10058 static struct drm_framebuffer *
10059 intel_framebuffer_create(struct drm_device *dev,
10060 struct drm_mode_fb_cmd2 *mode_cmd,
10061 struct drm_i915_gem_object *obj)
10063 struct drm_framebuffer *fb;
10066 ret = i915_mutex_lock_interruptible(dev);
10068 return ERR_PTR(ret);
10069 fb = __intel_framebuffer_create(dev, mode_cmd, obj);
10070 mutex_unlock(&dev->struct_mutex);
10076 intel_framebuffer_pitch_for_width(int width, int bpp)
10078 u32 pitch = DIV_ROUND_UP(width * bpp, 8);
10079 return ALIGN(pitch, 64);
10083 intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
10085 u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
10086 return PAGE_ALIGN(pitch * mode->vdisplay);
10089 static struct drm_framebuffer *
10090 intel_framebuffer_create_for_mode(struct drm_device *dev,
10091 struct drm_display_mode *mode,
10092 int depth, int bpp)
10094 struct drm_i915_gem_object *obj;
10095 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
10097 obj = i915_gem_alloc_object(dev,
10098 intel_framebuffer_size_for_mode(mode, bpp));
10100 return ERR_PTR(-ENOMEM);
10102 mode_cmd.width = mode->hdisplay;
10103 mode_cmd.height = mode->vdisplay;
10104 mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
10106 mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
10108 return intel_framebuffer_create(dev, &mode_cmd, obj);
10111 static struct drm_framebuffer *
10112 mode_fits_in_fbdev(struct drm_device *dev,
10113 struct drm_display_mode *mode)
10115 #ifdef CONFIG_DRM_FBDEV_EMULATION
10116 struct drm_i915_private *dev_priv = dev->dev_private;
10117 struct drm_i915_gem_object *obj;
10118 struct drm_framebuffer *fb;
10120 if (!dev_priv->fbdev)
10123 if (!dev_priv->fbdev->fb)
10126 obj = dev_priv->fbdev->fb->obj;
10129 fb = &dev_priv->fbdev->fb->base;
10130 if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
10131 fb->bits_per_pixel))
10134 if (obj->base.size < mode->vdisplay * fb->pitches[0])
10143 static int intel_modeset_setup_plane_state(struct drm_atomic_state *state,
10144 struct drm_crtc *crtc,
10145 struct drm_display_mode *mode,
10146 struct drm_framebuffer *fb,
10149 struct drm_plane_state *plane_state;
10150 int hdisplay, vdisplay;
10153 plane_state = drm_atomic_get_plane_state(state, crtc->primary);
10154 if (IS_ERR(plane_state))
10155 return PTR_ERR(plane_state);
10158 drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay);
10160 hdisplay = vdisplay = 0;
10162 ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL);
10165 drm_atomic_set_fb_for_plane(plane_state, fb);
10166 plane_state->crtc_x = 0;
10167 plane_state->crtc_y = 0;
10168 plane_state->crtc_w = hdisplay;
10169 plane_state->crtc_h = vdisplay;
10170 plane_state->src_x = x << 16;
10171 plane_state->src_y = y << 16;
10172 plane_state->src_w = hdisplay << 16;
10173 plane_state->src_h = vdisplay << 16;
10178 bool intel_get_load_detect_pipe(struct drm_connector *connector,
10179 struct drm_display_mode *mode,
10180 struct intel_load_detect_pipe *old,
10181 struct drm_modeset_acquire_ctx *ctx)
10183 struct intel_crtc *intel_crtc;
10184 struct intel_encoder *intel_encoder =
10185 intel_attached_encoder(connector);
10186 struct drm_crtc *possible_crtc;
10187 struct drm_encoder *encoder = &intel_encoder->base;
10188 struct drm_crtc *crtc = NULL;
10189 struct drm_device *dev = encoder->dev;
10190 struct drm_framebuffer *fb;
10191 struct drm_mode_config *config = &dev->mode_config;
10192 struct drm_atomic_state *state = NULL;
10193 struct drm_connector_state *connector_state;
10194 struct intel_crtc_state *crtc_state;
10197 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10198 connector->base.id, connector->name,
10199 encoder->base.id, encoder->name);
10202 ret = drm_modeset_lock(&config->connection_mutex, ctx);
10207 * Algorithm gets a little messy:
10209 * - if the connector already has an assigned crtc, use it (but make
10210 * sure it's on first)
10212 * - try to find the first unused crtc that can drive this connector,
10213 * and use that if we find one
10216 /* See if we already have a CRTC for this connector */
10217 if (encoder->crtc) {
10218 crtc = encoder->crtc;
10220 ret = drm_modeset_lock(&crtc->mutex, ctx);
10223 ret = drm_modeset_lock(&crtc->primary->mutex, ctx);
10227 old->dpms_mode = connector->dpms;
10228 old->load_detect_temp = false;
10230 /* Make sure the crtc and connector are running */
10231 if (connector->dpms != DRM_MODE_DPMS_ON)
10232 connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
10237 /* Find an unused one (if possible) */
10238 for_each_crtc(dev, possible_crtc) {
10240 if (!(encoder->possible_crtcs & (1 << i)))
10242 if (possible_crtc->state->enable)
10245 crtc = possible_crtc;
10250 * If we didn't find an unused CRTC, don't use any.
10253 DRM_DEBUG_KMS("no pipe available for load-detect\n");
10257 ret = drm_modeset_lock(&crtc->mutex, ctx);
10260 ret = drm_modeset_lock(&crtc->primary->mutex, ctx);
10264 intel_crtc = to_intel_crtc(crtc);
10265 old->dpms_mode = connector->dpms;
10266 old->load_detect_temp = true;
10267 old->release_fb = NULL;
10269 state = drm_atomic_state_alloc(dev);
10273 state->acquire_ctx = ctx;
10275 connector_state = drm_atomic_get_connector_state(state, connector);
10276 if (IS_ERR(connector_state)) {
10277 ret = PTR_ERR(connector_state);
10281 connector_state->crtc = crtc;
10282 connector_state->best_encoder = &intel_encoder->base;
10284 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10285 if (IS_ERR(crtc_state)) {
10286 ret = PTR_ERR(crtc_state);
10290 crtc_state->base.active = crtc_state->base.enable = true;
10293 mode = &load_detect_mode;
10295 /* We need a framebuffer large enough to accommodate all accesses
10296 * that the plane may generate whilst we perform load detection.
10297 * We can not rely on the fbcon either being present (we get called
10298 * during its initialisation to detect all boot displays, or it may
10299 * not even exist) or that it is large enough to satisfy the
10302 fb = mode_fits_in_fbdev(dev, mode);
10304 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
10305 fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
10306 old->release_fb = fb;
10308 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
10310 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
10314 ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0);
10318 drm_mode_copy(&crtc_state->base.mode, mode);
10320 if (drm_atomic_commit(state)) {
10321 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
10322 if (old->release_fb)
10323 old->release_fb->funcs->destroy(old->release_fb);
10326 crtc->primary->crtc = crtc;
10328 /* let the connector get through one full cycle before testing */
10329 intel_wait_for_vblank(dev, intel_crtc->pipe);
10333 drm_atomic_state_free(state);
10336 if (ret == -EDEADLK) {
10337 drm_modeset_backoff(ctx);
10344 void intel_release_load_detect_pipe(struct drm_connector *connector,
10345 struct intel_load_detect_pipe *old,
10346 struct drm_modeset_acquire_ctx *ctx)
10348 struct drm_device *dev = connector->dev;
10349 struct intel_encoder *intel_encoder =
10350 intel_attached_encoder(connector);
10351 struct drm_encoder *encoder = &intel_encoder->base;
10352 struct drm_crtc *crtc = encoder->crtc;
10353 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10354 struct drm_atomic_state *state;
10355 struct drm_connector_state *connector_state;
10356 struct intel_crtc_state *crtc_state;
10359 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10360 connector->base.id, connector->name,
10361 encoder->base.id, encoder->name);
10363 if (old->load_detect_temp) {
10364 state = drm_atomic_state_alloc(dev);
10368 state->acquire_ctx = ctx;
10370 connector_state = drm_atomic_get_connector_state(state, connector);
10371 if (IS_ERR(connector_state))
10374 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10375 if (IS_ERR(crtc_state))
10378 connector_state->best_encoder = NULL;
10379 connector_state->crtc = NULL;
10381 crtc_state->base.enable = crtc_state->base.active = false;
10383 ret = intel_modeset_setup_plane_state(state, crtc, NULL, NULL,
10388 ret = drm_atomic_commit(state);
10392 if (old->release_fb) {
10393 drm_framebuffer_unregister_private(old->release_fb);
10394 drm_framebuffer_unreference(old->release_fb);
10400 /* Switch crtc and encoder back off if necessary */
10401 if (old->dpms_mode != DRM_MODE_DPMS_ON)
10402 connector->funcs->dpms(connector, old->dpms_mode);
10406 DRM_DEBUG_KMS("Couldn't release load detect pipe.\n");
10407 drm_atomic_state_free(state);
10410 static int i9xx_pll_refclk(struct drm_device *dev,
10411 const struct intel_crtc_state *pipe_config)
10413 struct drm_i915_private *dev_priv = dev->dev_private;
10414 u32 dpll = pipe_config->dpll_hw_state.dpll;
10416 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
10417 return dev_priv->vbt.lvds_ssc_freq;
10418 else if (HAS_PCH_SPLIT(dev))
10420 else if (!IS_GEN2(dev))
10426 /* Returns the clock of the currently programmed mode of the given pipe. */
10427 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
10428 struct intel_crtc_state *pipe_config)
10430 struct drm_device *dev = crtc->base.dev;
10431 struct drm_i915_private *dev_priv = dev->dev_private;
10432 int pipe = pipe_config->cpu_transcoder;
10433 u32 dpll = pipe_config->dpll_hw_state.dpll;
10435 intel_clock_t clock;
10437 int refclk = i9xx_pll_refclk(dev, pipe_config);
10439 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
10440 fp = pipe_config->dpll_hw_state.fp0;
10442 fp = pipe_config->dpll_hw_state.fp1;
10444 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
10445 if (IS_PINEVIEW(dev)) {
10446 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10447 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
10449 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10450 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10453 if (!IS_GEN2(dev)) {
10454 if (IS_PINEVIEW(dev))
10455 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10456 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
10458 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
10459 DPLL_FPA01_P1_POST_DIV_SHIFT);
10461 switch (dpll & DPLL_MODE_MASK) {
10462 case DPLLB_MODE_DAC_SERIAL:
10463 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10466 case DPLLB_MODE_LVDS:
10467 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10471 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10472 "mode\n", (int)(dpll & DPLL_MODE_MASK));
10476 if (IS_PINEVIEW(dev))
10477 port_clock = pnv_calc_dpll_params(refclk, &clock);
10479 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10481 u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS);
10482 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
10485 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10486 DPLL_FPA01_P1_POST_DIV_SHIFT);
10488 if (lvds & LVDS_CLKB_POWER_UP)
10493 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10496 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10497 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10499 if (dpll & PLL_P2_DIVIDE_BY_4)
10505 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10509 * This value includes pixel_multiplier. We will use
10510 * port_clock to compute adjusted_mode.crtc_clock in the
10511 * encoder's get_config() function.
10513 pipe_config->port_clock = port_clock;
10516 int intel_dotclock_calculate(int link_freq,
10517 const struct intel_link_m_n *m_n)
10520 * The calculation for the data clock is:
10521 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10522 * But we want to avoid losing precison if possible, so:
10523 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10525 * and the link clock is simpler:
10526 * link_clock = (m * link_clock) / n
10532 return div_u64((u64)m_n->link_m * link_freq, m_n->link_n);
10535 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
10536 struct intel_crtc_state *pipe_config)
10538 struct drm_device *dev = crtc->base.dev;
10540 /* read out port_clock from the DPLL */
10541 i9xx_crtc_clock_get(crtc, pipe_config);
10544 * This value does not include pixel_multiplier.
10545 * We will check that port_clock and adjusted_mode.crtc_clock
10546 * agree once we know their relationship in the encoder's
10547 * get_config() function.
10549 pipe_config->base.adjusted_mode.crtc_clock =
10550 intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000,
10551 &pipe_config->fdi_m_n);
10554 /** Returns the currently programmed mode of the given pipe. */
10555 struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
10556 struct drm_crtc *crtc)
10558 struct drm_i915_private *dev_priv = dev->dev_private;
10559 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10560 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
10561 struct drm_display_mode *mode;
10562 struct intel_crtc_state pipe_config;
10563 int htot = I915_READ(HTOTAL(cpu_transcoder));
10564 int hsync = I915_READ(HSYNC(cpu_transcoder));
10565 int vtot = I915_READ(VTOTAL(cpu_transcoder));
10566 int vsync = I915_READ(VSYNC(cpu_transcoder));
10567 enum pipe pipe = intel_crtc->pipe;
10569 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10574 * Construct a pipe_config sufficient for getting the clock info
10575 * back out of crtc_clock_get.
10577 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
10578 * to use a real value here instead.
10580 pipe_config.cpu_transcoder = (enum transcoder) pipe;
10581 pipe_config.pixel_multiplier = 1;
10582 pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe));
10583 pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe));
10584 pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe));
10585 i9xx_crtc_clock_get(intel_crtc, &pipe_config);
10587 mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier;
10588 mode->hdisplay = (htot & 0xffff) + 1;
10589 mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
10590 mode->hsync_start = (hsync & 0xffff) + 1;
10591 mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
10592 mode->vdisplay = (vtot & 0xffff) + 1;
10593 mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
10594 mode->vsync_start = (vsync & 0xffff) + 1;
10595 mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
10597 drm_mode_set_name(mode);
10602 void intel_mark_busy(struct drm_device *dev)
10604 struct drm_i915_private *dev_priv = dev->dev_private;
10606 if (dev_priv->mm.busy)
10609 intel_runtime_pm_get(dev_priv);
10610 i915_update_gfx_val(dev_priv);
10611 if (INTEL_INFO(dev)->gen >= 6)
10612 gen6_rps_busy(dev_priv);
10613 dev_priv->mm.busy = true;
10616 void intel_mark_idle(struct drm_device *dev)
10618 struct drm_i915_private *dev_priv = dev->dev_private;
10620 if (!dev_priv->mm.busy)
10623 dev_priv->mm.busy = false;
10625 if (INTEL_INFO(dev)->gen >= 6)
10626 gen6_rps_idle(dev->dev_private);
10628 intel_runtime_pm_put(dev_priv);
10631 static void intel_crtc_destroy(struct drm_crtc *crtc)
10633 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10634 struct drm_device *dev = crtc->dev;
10635 struct intel_unpin_work *work;
10637 spin_lock_irq(&dev->event_lock);
10638 work = intel_crtc->unpin_work;
10639 intel_crtc->unpin_work = NULL;
10640 spin_unlock_irq(&dev->event_lock);
10643 cancel_work_sync(&work->work);
10647 drm_crtc_cleanup(crtc);
10652 static void intel_unpin_work_fn(struct work_struct *__work)
10654 struct intel_unpin_work *work =
10655 container_of(__work, struct intel_unpin_work, work);
10656 struct intel_crtc *crtc = to_intel_crtc(work->crtc);
10657 struct drm_device *dev = crtc->base.dev;
10658 struct drm_plane *primary = crtc->base.primary;
10660 mutex_lock(&dev->struct_mutex);
10661 intel_unpin_fb_obj(work->old_fb, primary->state);
10662 drm_gem_object_unreference(&work->pending_flip_obj->base);
10664 if (work->flip_queued_req)
10665 i915_gem_request_assign(&work->flip_queued_req, NULL);
10666 mutex_unlock(&dev->struct_mutex);
10668 intel_frontbuffer_flip_complete(dev, to_intel_plane(primary)->frontbuffer_bit);
10669 drm_framebuffer_unreference(work->old_fb);
10671 BUG_ON(atomic_read(&crtc->unpin_work_count) == 0);
10672 atomic_dec(&crtc->unpin_work_count);
10677 static void do_intel_finish_page_flip(struct drm_device *dev,
10678 struct drm_crtc *crtc)
10680 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10681 struct intel_unpin_work *work;
10682 unsigned long flags;
10684 /* Ignore early vblank irqs */
10685 if (intel_crtc == NULL)
10689 * This is called both by irq handlers and the reset code (to complete
10690 * lost pageflips) so needs the full irqsave spinlocks.
10692 spin_lock_irqsave(&dev->event_lock, flags);
10693 work = intel_crtc->unpin_work;
10695 /* Ensure we don't miss a work->pending update ... */
10698 if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
10699 spin_unlock_irqrestore(&dev->event_lock, flags);
10703 page_flip_completed(intel_crtc);
10705 spin_unlock_irqrestore(&dev->event_lock, flags);
10708 void intel_finish_page_flip(struct drm_device *dev, int pipe)
10710 struct drm_i915_private *dev_priv = dev->dev_private;
10711 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
10713 do_intel_finish_page_flip(dev, crtc);
10716 void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
10718 struct drm_i915_private *dev_priv = dev->dev_private;
10719 struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
10721 do_intel_finish_page_flip(dev, crtc);
10724 /* Is 'a' after or equal to 'b'? */
10725 static bool g4x_flip_count_after_eq(u32 a, u32 b)
10727 return !((a - b) & 0x80000000);
10730 static bool page_flip_finished(struct intel_crtc *crtc)
10732 struct drm_device *dev = crtc->base.dev;
10733 struct drm_i915_private *dev_priv = dev->dev_private;
10735 if (i915_reset_in_progress(&dev_priv->gpu_error) ||
10736 crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
10740 * The relevant registers doen't exist on pre-ctg.
10741 * As the flip done interrupt doesn't trigger for mmio
10742 * flips on gmch platforms, a flip count check isn't
10743 * really needed there. But since ctg has the registers,
10744 * include it in the check anyway.
10746 if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev))
10750 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
10751 * used the same base address. In that case the mmio flip might
10752 * have completed, but the CS hasn't even executed the flip yet.
10754 * A flip count check isn't enough as the CS might have updated
10755 * the base address just after start of vblank, but before we
10756 * managed to process the interrupt. This means we'd complete the
10757 * CS flip too soon.
10759 * Combining both checks should get us a good enough result. It may
10760 * still happen that the CS flip has been executed, but has not
10761 * yet actually completed. But in case the base address is the same
10762 * anyway, we don't really care.
10764 return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) ==
10765 crtc->unpin_work->gtt_offset &&
10766 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)),
10767 crtc->unpin_work->flip_count);
10770 void intel_prepare_page_flip(struct drm_device *dev, int plane)
10772 struct drm_i915_private *dev_priv = dev->dev_private;
10773 struct intel_crtc *intel_crtc =
10774 to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
10775 unsigned long flags;
10779 * This is called both by irq handlers and the reset code (to complete
10780 * lost pageflips) so needs the full irqsave spinlocks.
10782 * NB: An MMIO update of the plane base pointer will also
10783 * generate a page-flip completion irq, i.e. every modeset
10784 * is also accompanied by a spurious intel_prepare_page_flip().
10786 spin_lock_irqsave(&dev->event_lock, flags);
10787 if (intel_crtc->unpin_work && page_flip_finished(intel_crtc))
10788 atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
10789 spin_unlock_irqrestore(&dev->event_lock, flags);
10792 static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
10794 /* Ensure that the work item is consistent when activating it ... */
10796 atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
10797 /* and that it is marked active as soon as the irq could fire. */
10801 static int intel_gen2_queue_flip(struct drm_device *dev,
10802 struct drm_crtc *crtc,
10803 struct drm_framebuffer *fb,
10804 struct drm_i915_gem_object *obj,
10805 struct drm_i915_gem_request *req,
10808 struct intel_engine_cs *ring = req->ring;
10809 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10813 ret = intel_ring_begin(req, 6);
10817 /* Can't queue multiple flips, so wait for the previous
10818 * one to finish before executing the next.
10820 if (intel_crtc->plane)
10821 flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
10823 flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
10824 intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
10825 intel_ring_emit(ring, MI_NOOP);
10826 intel_ring_emit(ring, MI_DISPLAY_FLIP |
10827 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
10828 intel_ring_emit(ring, fb->pitches[0]);
10829 intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
10830 intel_ring_emit(ring, 0); /* aux display base address, unused */
10832 intel_mark_page_flip_active(intel_crtc);
10836 static int intel_gen3_queue_flip(struct drm_device *dev,
10837 struct drm_crtc *crtc,
10838 struct drm_framebuffer *fb,
10839 struct drm_i915_gem_object *obj,
10840 struct drm_i915_gem_request *req,
10843 struct intel_engine_cs *ring = req->ring;
10844 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10848 ret = intel_ring_begin(req, 6);
10852 if (intel_crtc->plane)
10853 flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
10855 flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
10856 intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
10857 intel_ring_emit(ring, MI_NOOP);
10858 intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
10859 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
10860 intel_ring_emit(ring, fb->pitches[0]);
10861 intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
10862 intel_ring_emit(ring, MI_NOOP);
10864 intel_mark_page_flip_active(intel_crtc);
10868 static int intel_gen4_queue_flip(struct drm_device *dev,
10869 struct drm_crtc *crtc,
10870 struct drm_framebuffer *fb,
10871 struct drm_i915_gem_object *obj,
10872 struct drm_i915_gem_request *req,
10875 struct intel_engine_cs *ring = req->ring;
10876 struct drm_i915_private *dev_priv = dev->dev_private;
10877 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10878 uint32_t pf, pipesrc;
10881 ret = intel_ring_begin(req, 4);
10885 /* i965+ uses the linear or tiled offsets from the
10886 * Display Registers (which do not change across a page-flip)
10887 * so we need only reprogram the base address.
10889 intel_ring_emit(ring, MI_DISPLAY_FLIP |
10890 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
10891 intel_ring_emit(ring, fb->pitches[0]);
10892 intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset |
10895 /* XXX Enabling the panel-fitter across page-flip is so far
10896 * untested on non-native modes, so ignore it for now.
10897 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
10900 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
10901 intel_ring_emit(ring, pf | pipesrc);
10903 intel_mark_page_flip_active(intel_crtc);
10907 static int intel_gen6_queue_flip(struct drm_device *dev,
10908 struct drm_crtc *crtc,
10909 struct drm_framebuffer *fb,
10910 struct drm_i915_gem_object *obj,
10911 struct drm_i915_gem_request *req,
10914 struct intel_engine_cs *ring = req->ring;
10915 struct drm_i915_private *dev_priv = dev->dev_private;
10916 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10917 uint32_t pf, pipesrc;
10920 ret = intel_ring_begin(req, 4);
10924 intel_ring_emit(ring, MI_DISPLAY_FLIP |
10925 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
10926 intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
10927 intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
10929 /* Contrary to the suggestions in the documentation,
10930 * "Enable Panel Fitter" does not seem to be required when page
10931 * flipping with a non-native mode, and worse causes a normal
10933 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
10936 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
10937 intel_ring_emit(ring, pf | pipesrc);
10939 intel_mark_page_flip_active(intel_crtc);
10943 static int intel_gen7_queue_flip(struct drm_device *dev,
10944 struct drm_crtc *crtc,
10945 struct drm_framebuffer *fb,
10946 struct drm_i915_gem_object *obj,
10947 struct drm_i915_gem_request *req,
10950 struct intel_engine_cs *ring = req->ring;
10951 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10952 uint32_t plane_bit = 0;
10955 switch (intel_crtc->plane) {
10957 plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
10960 plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
10963 plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
10966 WARN_ONCE(1, "unknown plane in flip command\n");
10971 if (ring->id == RCS) {
10974 * On Gen 8, SRM is now taking an extra dword to accommodate
10975 * 48bits addresses, and we need a NOOP for the batch size to
10983 * BSpec MI_DISPLAY_FLIP for IVB:
10984 * "The full packet must be contained within the same cache line."
10986 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
10987 * cacheline, if we ever start emitting more commands before
10988 * the MI_DISPLAY_FLIP we may need to first emit everything else,
10989 * then do the cacheline alignment, and finally emit the
10992 ret = intel_ring_cacheline_align(req);
10996 ret = intel_ring_begin(req, len);
11000 /* Unmask the flip-done completion message. Note that the bspec says that
11001 * we should do this for both the BCS and RCS, and that we must not unmask
11002 * more than one flip event at any time (or ensure that one flip message
11003 * can be sent by waiting for flip-done prior to queueing new flips).
11004 * Experimentation says that BCS works despite DERRMR masking all
11005 * flip-done completion events and that unmasking all planes at once
11006 * for the RCS also doesn't appear to drop events. Setting the DERRMR
11007 * to zero does lead to lockups within MI_DISPLAY_FLIP.
11009 if (ring->id == RCS) {
11010 intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
11011 intel_ring_emit(ring, DERRMR);
11012 intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE |
11013 DERRMR_PIPEB_PRI_FLIP_DONE |
11014 DERRMR_PIPEC_PRI_FLIP_DONE));
11016 intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8 |
11017 MI_SRM_LRM_GLOBAL_GTT);
11019 intel_ring_emit(ring, MI_STORE_REGISTER_MEM |
11020 MI_SRM_LRM_GLOBAL_GTT);
11021 intel_ring_emit(ring, DERRMR);
11022 intel_ring_emit(ring, ring->scratch.gtt_offset + 256);
11023 if (IS_GEN8(dev)) {
11024 intel_ring_emit(ring, 0);
11025 intel_ring_emit(ring, MI_NOOP);
11029 intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
11030 intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
11031 intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
11032 intel_ring_emit(ring, (MI_NOOP));
11034 intel_mark_page_flip_active(intel_crtc);
11038 static bool use_mmio_flip(struct intel_engine_cs *ring,
11039 struct drm_i915_gem_object *obj)
11042 * This is not being used for older platforms, because
11043 * non-availability of flip done interrupt forces us to use
11044 * CS flips. Older platforms derive flip done using some clever
11045 * tricks involving the flip_pending status bits and vblank irqs.
11046 * So using MMIO flips there would disrupt this mechanism.
11052 if (INTEL_INFO(ring->dev)->gen < 5)
11055 if (i915.use_mmio_flip < 0)
11057 else if (i915.use_mmio_flip > 0)
11059 else if (i915.enable_execlists)
11062 return ring != i915_gem_request_get_ring(obj->last_write_req);
11065 static void skl_do_mmio_flip(struct intel_crtc *intel_crtc)
11067 struct drm_device *dev = intel_crtc->base.dev;
11068 struct drm_i915_private *dev_priv = dev->dev_private;
11069 struct drm_framebuffer *fb = intel_crtc->base.primary->fb;
11070 const enum pipe pipe = intel_crtc->pipe;
11073 ctl = I915_READ(PLANE_CTL(pipe, 0));
11074 ctl &= ~PLANE_CTL_TILED_MASK;
11075 switch (fb->modifier[0]) {
11076 case DRM_FORMAT_MOD_NONE:
11078 case I915_FORMAT_MOD_X_TILED:
11079 ctl |= PLANE_CTL_TILED_X;
11081 case I915_FORMAT_MOD_Y_TILED:
11082 ctl |= PLANE_CTL_TILED_Y;
11084 case I915_FORMAT_MOD_Yf_TILED:
11085 ctl |= PLANE_CTL_TILED_YF;
11088 MISSING_CASE(fb->modifier[0]);
11092 * The stride is either expressed as a multiple of 64 bytes chunks for
11093 * linear buffers or in number of tiles for tiled buffers.
11095 stride = fb->pitches[0] /
11096 intel_fb_stride_alignment(dev, fb->modifier[0],
11100 * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on
11101 * PLANE_SURF updates, the update is then guaranteed to be atomic.
11103 I915_WRITE(PLANE_CTL(pipe, 0), ctl);
11104 I915_WRITE(PLANE_STRIDE(pipe, 0), stride);
11106 I915_WRITE(PLANE_SURF(pipe, 0), intel_crtc->unpin_work->gtt_offset);
11107 POSTING_READ(PLANE_SURF(pipe, 0));
11110 static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc)
11112 struct drm_device *dev = intel_crtc->base.dev;
11113 struct drm_i915_private *dev_priv = dev->dev_private;
11114 struct intel_framebuffer *intel_fb =
11115 to_intel_framebuffer(intel_crtc->base.primary->fb);
11116 struct drm_i915_gem_object *obj = intel_fb->obj;
11120 reg = DSPCNTR(intel_crtc->plane);
11121 dspcntr = I915_READ(reg);
11123 if (obj->tiling_mode != I915_TILING_NONE)
11124 dspcntr |= DISPPLANE_TILED;
11126 dspcntr &= ~DISPPLANE_TILED;
11128 I915_WRITE(reg, dspcntr);
11130 I915_WRITE(DSPSURF(intel_crtc->plane),
11131 intel_crtc->unpin_work->gtt_offset);
11132 POSTING_READ(DSPSURF(intel_crtc->plane));
11137 * XXX: This is the temporary way to update the plane registers until we get
11138 * around to using the usual plane update functions for MMIO flips
11140 static void intel_do_mmio_flip(struct intel_crtc *intel_crtc)
11142 struct drm_device *dev = intel_crtc->base.dev;
11144 intel_mark_page_flip_active(intel_crtc);
11146 intel_pipe_update_start(intel_crtc);
11148 if (INTEL_INFO(dev)->gen >= 9)
11149 skl_do_mmio_flip(intel_crtc);
11151 /* use_mmio_flip() retricts MMIO flips to ilk+ */
11152 ilk_do_mmio_flip(intel_crtc);
11154 intel_pipe_update_end(intel_crtc);
11157 static void intel_mmio_flip_work_func(struct work_struct *work)
11159 struct intel_mmio_flip *mmio_flip =
11160 container_of(work, struct intel_mmio_flip, work);
11162 if (mmio_flip->req)
11163 WARN_ON(__i915_wait_request(mmio_flip->req,
11164 mmio_flip->crtc->reset_counter,
11166 &mmio_flip->i915->rps.mmioflips));
11168 intel_do_mmio_flip(mmio_flip->crtc);
11170 i915_gem_request_unreference__unlocked(mmio_flip->req);
11174 static int intel_queue_mmio_flip(struct drm_device *dev,
11175 struct drm_crtc *crtc,
11176 struct drm_framebuffer *fb,
11177 struct drm_i915_gem_object *obj,
11178 struct intel_engine_cs *ring,
11181 struct intel_mmio_flip *mmio_flip;
11183 mmio_flip = kmalloc(sizeof(*mmio_flip), GFP_KERNEL);
11184 if (mmio_flip == NULL)
11187 mmio_flip->i915 = to_i915(dev);
11188 mmio_flip->req = i915_gem_request_reference(obj->last_write_req);
11189 mmio_flip->crtc = to_intel_crtc(crtc);
11191 INIT_WORK(&mmio_flip->work, intel_mmio_flip_work_func);
11192 schedule_work(&mmio_flip->work);
11197 static int intel_default_queue_flip(struct drm_device *dev,
11198 struct drm_crtc *crtc,
11199 struct drm_framebuffer *fb,
11200 struct drm_i915_gem_object *obj,
11201 struct drm_i915_gem_request *req,
11207 static bool __intel_pageflip_stall_check(struct drm_device *dev,
11208 struct drm_crtc *crtc)
11210 struct drm_i915_private *dev_priv = dev->dev_private;
11211 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11212 struct intel_unpin_work *work = intel_crtc->unpin_work;
11215 if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE)
11218 if (atomic_read(&work->pending) < INTEL_FLIP_PENDING)
11221 if (!work->enable_stall_check)
11224 if (work->flip_ready_vblank == 0) {
11225 if (work->flip_queued_req &&
11226 !i915_gem_request_completed(work->flip_queued_req, true))
11229 work->flip_ready_vblank = drm_crtc_vblank_count(crtc);
11232 if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3)
11235 /* Potential stall - if we see that the flip has happened,
11236 * assume a missed interrupt. */
11237 if (INTEL_INFO(dev)->gen >= 4)
11238 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane)));
11240 addr = I915_READ(DSPADDR(intel_crtc->plane));
11242 /* There is a potential issue here with a false positive after a flip
11243 * to the same address. We could address this by checking for a
11244 * non-incrementing frame counter.
11246 return addr == work->gtt_offset;
11249 void intel_check_page_flip(struct drm_device *dev, int pipe)
11251 struct drm_i915_private *dev_priv = dev->dev_private;
11252 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
11253 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11254 struct intel_unpin_work *work;
11256 WARN_ON(!in_interrupt());
11261 spin_lock(&dev->event_lock);
11262 work = intel_crtc->unpin_work;
11263 if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) {
11264 WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n",
11265 work->flip_queued_vblank, drm_vblank_count(dev, pipe));
11266 page_flip_completed(intel_crtc);
11269 if (work != NULL &&
11270 drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1)
11271 intel_queue_rps_boost_for_request(dev, work->flip_queued_req);
11272 spin_unlock(&dev->event_lock);
11275 static int intel_crtc_page_flip(struct drm_crtc *crtc,
11276 struct drm_framebuffer *fb,
11277 struct drm_pending_vblank_event *event,
11278 uint32_t page_flip_flags)
11280 struct drm_device *dev = crtc->dev;
11281 struct drm_i915_private *dev_priv = dev->dev_private;
11282 struct drm_framebuffer *old_fb = crtc->primary->fb;
11283 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
11284 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11285 struct drm_plane *primary = crtc->primary;
11286 enum pipe pipe = intel_crtc->pipe;
11287 struct intel_unpin_work *work;
11288 struct intel_engine_cs *ring;
11290 struct drm_i915_gem_request *request = NULL;
11294 * drm_mode_page_flip_ioctl() should already catch this, but double
11295 * check to be safe. In the future we may enable pageflipping from
11296 * a disabled primary plane.
11298 if (WARN_ON(intel_fb_obj(old_fb) == NULL))
11301 /* Can't change pixel format via MI display flips. */
11302 if (fb->pixel_format != crtc->primary->fb->pixel_format)
11306 * TILEOFF/LINOFF registers can't be changed via MI display flips.
11307 * Note that pitch changes could also affect these register.
11309 if (INTEL_INFO(dev)->gen > 3 &&
11310 (fb->offsets[0] != crtc->primary->fb->offsets[0] ||
11311 fb->pitches[0] != crtc->primary->fb->pitches[0]))
11314 if (i915_terminally_wedged(&dev_priv->gpu_error))
11317 work = kzalloc(sizeof(*work), GFP_KERNEL);
11321 work->event = event;
11323 work->old_fb = old_fb;
11324 INIT_WORK(&work->work, intel_unpin_work_fn);
11326 ret = drm_crtc_vblank_get(crtc);
11330 /* We borrow the event spin lock for protecting unpin_work */
11331 spin_lock_irq(&dev->event_lock);
11332 if (intel_crtc->unpin_work) {
11333 /* Before declaring the flip queue wedged, check if
11334 * the hardware completed the operation behind our backs.
11336 if (__intel_pageflip_stall_check(dev, crtc)) {
11337 DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
11338 page_flip_completed(intel_crtc);
11340 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
11341 spin_unlock_irq(&dev->event_lock);
11343 drm_crtc_vblank_put(crtc);
11348 intel_crtc->unpin_work = work;
11349 spin_unlock_irq(&dev->event_lock);
11351 if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
11352 flush_workqueue(dev_priv->wq);
11354 /* Reference the objects for the scheduled work. */
11355 drm_framebuffer_reference(work->old_fb);
11356 drm_gem_object_reference(&obj->base);
11358 crtc->primary->fb = fb;
11359 update_state_fb(crtc->primary);
11361 work->pending_flip_obj = obj;
11363 ret = i915_mutex_lock_interruptible(dev);
11367 atomic_inc(&intel_crtc->unpin_work_count);
11368 intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
11370 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
11371 work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1;
11373 if (IS_VALLEYVIEW(dev)) {
11374 ring = &dev_priv->ring[BCS];
11375 if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode)
11376 /* vlv: DISPLAY_FLIP fails to change tiling */
11378 } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) {
11379 ring = &dev_priv->ring[BCS];
11380 } else if (INTEL_INFO(dev)->gen >= 7) {
11381 ring = i915_gem_request_get_ring(obj->last_write_req);
11382 if (ring == NULL || ring->id != RCS)
11383 ring = &dev_priv->ring[BCS];
11385 ring = &dev_priv->ring[RCS];
11388 mmio_flip = use_mmio_flip(ring, obj);
11390 /* When using CS flips, we want to emit semaphores between rings.
11391 * However, when using mmio flips we will create a task to do the
11392 * synchronisation, so all we want here is to pin the framebuffer
11393 * into the display plane and skip any waits.
11395 ret = intel_pin_and_fence_fb_obj(crtc->primary, fb,
11396 crtc->primary->state,
11397 mmio_flip ? i915_gem_request_get_ring(obj->last_write_req) : ring, &request);
11399 goto cleanup_pending;
11401 work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), obj)
11402 + intel_crtc->dspaddr_offset;
11405 ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring,
11408 goto cleanup_unpin;
11410 i915_gem_request_assign(&work->flip_queued_req,
11411 obj->last_write_req);
11414 ret = i915_gem_request_alloc(ring, ring->default_context, &request);
11416 goto cleanup_unpin;
11419 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request,
11422 goto cleanup_unpin;
11424 i915_gem_request_assign(&work->flip_queued_req, request);
11428 i915_add_request_no_flush(request);
11430 work->flip_queued_vblank = drm_crtc_vblank_count(crtc);
11431 work->enable_stall_check = true;
11433 i915_gem_track_fb(intel_fb_obj(work->old_fb), obj,
11434 to_intel_plane(primary)->frontbuffer_bit);
11435 mutex_unlock(&dev->struct_mutex);
11437 intel_fbc_disable_crtc(intel_crtc);
11438 intel_frontbuffer_flip_prepare(dev,
11439 to_intel_plane(primary)->frontbuffer_bit);
11441 trace_i915_flip_request(intel_crtc->plane, obj);
11446 intel_unpin_fb_obj(fb, crtc->primary->state);
11449 i915_gem_request_cancel(request);
11450 atomic_dec(&intel_crtc->unpin_work_count);
11451 mutex_unlock(&dev->struct_mutex);
11453 crtc->primary->fb = old_fb;
11454 update_state_fb(crtc->primary);
11456 drm_gem_object_unreference_unlocked(&obj->base);
11457 drm_framebuffer_unreference(work->old_fb);
11459 spin_lock_irq(&dev->event_lock);
11460 intel_crtc->unpin_work = NULL;
11461 spin_unlock_irq(&dev->event_lock);
11463 drm_crtc_vblank_put(crtc);
11468 struct drm_atomic_state *state;
11469 struct drm_plane_state *plane_state;
11472 state = drm_atomic_state_alloc(dev);
11475 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
11478 plane_state = drm_atomic_get_plane_state(state, primary);
11479 ret = PTR_ERR_OR_ZERO(plane_state);
11481 drm_atomic_set_fb_for_plane(plane_state, fb);
11483 ret = drm_atomic_set_crtc_for_plane(plane_state, crtc);
11485 ret = drm_atomic_commit(state);
11488 if (ret == -EDEADLK) {
11489 drm_modeset_backoff(state->acquire_ctx);
11490 drm_atomic_state_clear(state);
11495 drm_atomic_state_free(state);
11497 if (ret == 0 && event) {
11498 spin_lock_irq(&dev->event_lock);
11499 drm_send_vblank_event(dev, pipe, event);
11500 spin_unlock_irq(&dev->event_lock);
11508 * intel_wm_need_update - Check whether watermarks need updating
11509 * @plane: drm plane
11510 * @state: new plane state
11512 * Check current plane state versus the new one to determine whether
11513 * watermarks need to be recalculated.
11515 * Returns true or false.
11517 static bool intel_wm_need_update(struct drm_plane *plane,
11518 struct drm_plane_state *state)
11520 /* Update watermarks on tiling changes. */
11521 if (!plane->state->fb || !state->fb ||
11522 plane->state->fb->modifier[0] != state->fb->modifier[0] ||
11523 plane->state->rotation != state->rotation)
11526 if (plane->state->crtc_w != state->crtc_w)
11532 int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state,
11533 struct drm_plane_state *plane_state)
11535 struct drm_crtc *crtc = crtc_state->crtc;
11536 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11537 struct drm_plane *plane = plane_state->plane;
11538 struct drm_device *dev = crtc->dev;
11539 struct drm_i915_private *dev_priv = dev->dev_private;
11540 struct intel_plane_state *old_plane_state =
11541 to_intel_plane_state(plane->state);
11542 int idx = intel_crtc->base.base.id, ret;
11543 int i = drm_plane_index(plane);
11544 bool mode_changed = needs_modeset(crtc_state);
11545 bool was_crtc_enabled = crtc->state->active;
11546 bool is_crtc_enabled = crtc_state->active;
11548 bool turn_off, turn_on, visible, was_visible;
11549 struct drm_framebuffer *fb = plane_state->fb;
11551 if (crtc_state && INTEL_INFO(dev)->gen >= 9 &&
11552 plane->type != DRM_PLANE_TYPE_CURSOR) {
11553 ret = skl_update_scaler_plane(
11554 to_intel_crtc_state(crtc_state),
11555 to_intel_plane_state(plane_state));
11561 * Disabling a plane is always okay; we just need to update
11562 * fb tracking in a special way since cleanup_fb() won't
11563 * get called by the plane helpers.
11565 if (old_plane_state->base.fb && !fb)
11566 intel_crtc->atomic.disabled_planes |= 1 << i;
11568 was_visible = old_plane_state->visible;
11569 visible = to_intel_plane_state(plane_state)->visible;
11571 if (!was_crtc_enabled && WARN_ON(was_visible))
11572 was_visible = false;
11574 if (!is_crtc_enabled && WARN_ON(visible))
11577 if (!was_visible && !visible)
11580 turn_off = was_visible && (!visible || mode_changed);
11581 turn_on = visible && (!was_visible || mode_changed);
11583 DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx,
11584 plane->base.id, fb ? fb->base.id : -1);
11586 DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n",
11587 plane->base.id, was_visible, visible,
11588 turn_off, turn_on, mode_changed);
11591 intel_crtc->atomic.update_wm_pre = true;
11592 /* must disable cxsr around plane enable/disable */
11593 if (plane->type != DRM_PLANE_TYPE_CURSOR) {
11594 intel_crtc->atomic.disable_cxsr = true;
11595 /* to potentially re-enable cxsr */
11596 intel_crtc->atomic.wait_vblank = true;
11597 intel_crtc->atomic.update_wm_post = true;
11599 } else if (turn_off) {
11600 intel_crtc->atomic.update_wm_post = true;
11601 /* must disable cxsr around plane enable/disable */
11602 if (plane->type != DRM_PLANE_TYPE_CURSOR) {
11603 if (is_crtc_enabled)
11604 intel_crtc->atomic.wait_vblank = true;
11605 intel_crtc->atomic.disable_cxsr = true;
11607 } else if (intel_wm_need_update(plane, plane_state)) {
11608 intel_crtc->atomic.update_wm_pre = true;
11611 if (visible || was_visible)
11612 intel_crtc->atomic.fb_bits |=
11613 to_intel_plane(plane)->frontbuffer_bit;
11615 switch (plane->type) {
11616 case DRM_PLANE_TYPE_PRIMARY:
11617 intel_crtc->atomic.wait_for_flips = true;
11618 intel_crtc->atomic.pre_disable_primary = turn_off;
11619 intel_crtc->atomic.post_enable_primary = turn_on;
11623 * FIXME: Actually if we will still have any other
11624 * plane enabled on the pipe we could let IPS enabled
11625 * still, but for now lets consider that when we make
11626 * primary invisible by setting DSPCNTR to 0 on
11627 * update_primary_plane function IPS needs to be
11630 intel_crtc->atomic.disable_ips = true;
11632 intel_crtc->atomic.disable_fbc = true;
11636 * FBC does not work on some platforms for rotated
11637 * planes, so disable it when rotation is not 0 and
11638 * update it when rotation is set back to 0.
11640 * FIXME: This is redundant with the fbc update done in
11641 * the primary plane enable function except that that
11642 * one is done too late. We eventually need to unify
11647 INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) &&
11648 dev_priv->fbc.crtc == intel_crtc &&
11649 plane_state->rotation != BIT(DRM_ROTATE_0))
11650 intel_crtc->atomic.disable_fbc = true;
11653 * BDW signals flip done immediately if the plane
11654 * is disabled, even if the plane enable is already
11655 * armed to occur at the next vblank :(
11657 if (turn_on && IS_BROADWELL(dev))
11658 intel_crtc->atomic.wait_vblank = true;
11660 intel_crtc->atomic.update_fbc |= visible || mode_changed;
11662 case DRM_PLANE_TYPE_CURSOR:
11664 case DRM_PLANE_TYPE_OVERLAY:
11665 if (turn_off && !mode_changed) {
11666 intel_crtc->atomic.wait_vblank = true;
11667 intel_crtc->atomic.update_sprite_watermarks |=
11674 static bool encoders_cloneable(const struct intel_encoder *a,
11675 const struct intel_encoder *b)
11677 /* masks could be asymmetric, so check both ways */
11678 return a == b || (a->cloneable & (1 << b->type) &&
11679 b->cloneable & (1 << a->type));
11682 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
11683 struct intel_crtc *crtc,
11684 struct intel_encoder *encoder)
11686 struct intel_encoder *source_encoder;
11687 struct drm_connector *connector;
11688 struct drm_connector_state *connector_state;
11691 for_each_connector_in_state(state, connector, connector_state, i) {
11692 if (connector_state->crtc != &crtc->base)
11696 to_intel_encoder(connector_state->best_encoder);
11697 if (!encoders_cloneable(encoder, source_encoder))
11704 static bool check_encoder_cloning(struct drm_atomic_state *state,
11705 struct intel_crtc *crtc)
11707 struct intel_encoder *encoder;
11708 struct drm_connector *connector;
11709 struct drm_connector_state *connector_state;
11712 for_each_connector_in_state(state, connector, connector_state, i) {
11713 if (connector_state->crtc != &crtc->base)
11716 encoder = to_intel_encoder(connector_state->best_encoder);
11717 if (!check_single_encoder_cloning(state, crtc, encoder))
11724 static int intel_crtc_atomic_check(struct drm_crtc *crtc,
11725 struct drm_crtc_state *crtc_state)
11727 struct drm_device *dev = crtc->dev;
11728 struct drm_i915_private *dev_priv = dev->dev_private;
11729 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11730 struct intel_crtc_state *pipe_config =
11731 to_intel_crtc_state(crtc_state);
11732 struct drm_atomic_state *state = crtc_state->state;
11734 bool mode_changed = needs_modeset(crtc_state);
11736 if (mode_changed && !check_encoder_cloning(state, intel_crtc)) {
11737 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
11741 if (mode_changed && !crtc_state->active)
11742 intel_crtc->atomic.update_wm_post = true;
11744 if (mode_changed && crtc_state->enable &&
11745 dev_priv->display.crtc_compute_clock &&
11746 !WARN_ON(pipe_config->shared_dpll != DPLL_ID_PRIVATE)) {
11747 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
11754 if (INTEL_INFO(dev)->gen >= 9) {
11756 ret = skl_update_scaler_crtc(pipe_config);
11759 ret = intel_atomic_setup_scalers(dev, intel_crtc,
11766 static const struct drm_crtc_helper_funcs intel_helper_funcs = {
11767 .mode_set_base_atomic = intel_pipe_set_base_atomic,
11768 .load_lut = intel_crtc_load_lut,
11769 .atomic_begin = intel_begin_crtc_commit,
11770 .atomic_flush = intel_finish_crtc_commit,
11771 .atomic_check = intel_crtc_atomic_check,
11774 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
11776 struct intel_connector *connector;
11778 for_each_intel_connector(dev, connector) {
11779 if (connector->base.encoder) {
11780 connector->base.state->best_encoder =
11781 connector->base.encoder;
11782 connector->base.state->crtc =
11783 connector->base.encoder->crtc;
11785 connector->base.state->best_encoder = NULL;
11786 connector->base.state->crtc = NULL;
11792 connected_sink_compute_bpp(struct intel_connector *connector,
11793 struct intel_crtc_state *pipe_config)
11795 int bpp = pipe_config->pipe_bpp;
11797 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
11798 connector->base.base.id,
11799 connector->base.name);
11801 /* Don't use an invalid EDID bpc value */
11802 if (connector->base.display_info.bpc &&
11803 connector->base.display_info.bpc * 3 < bpp) {
11804 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
11805 bpp, connector->base.display_info.bpc*3);
11806 pipe_config->pipe_bpp = connector->base.display_info.bpc*3;
11809 /* Clamp bpp to 8 on screens without EDID 1.4 */
11810 if (connector->base.display_info.bpc == 0 && bpp > 24) {
11811 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
11813 pipe_config->pipe_bpp = 24;
11818 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
11819 struct intel_crtc_state *pipe_config)
11821 struct drm_device *dev = crtc->base.dev;
11822 struct drm_atomic_state *state;
11823 struct drm_connector *connector;
11824 struct drm_connector_state *connector_state;
11827 if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)))
11829 else if (INTEL_INFO(dev)->gen >= 5)
11835 pipe_config->pipe_bpp = bpp;
11837 state = pipe_config->base.state;
11839 /* Clamp display bpp to EDID value */
11840 for_each_connector_in_state(state, connector, connector_state, i) {
11841 if (connector_state->crtc != &crtc->base)
11844 connected_sink_compute_bpp(to_intel_connector(connector),
11851 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
11853 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11854 "type: 0x%x flags: 0x%x\n",
11856 mode->crtc_hdisplay, mode->crtc_hsync_start,
11857 mode->crtc_hsync_end, mode->crtc_htotal,
11858 mode->crtc_vdisplay, mode->crtc_vsync_start,
11859 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
11862 static void intel_dump_pipe_config(struct intel_crtc *crtc,
11863 struct intel_crtc_state *pipe_config,
11864 const char *context)
11866 struct drm_device *dev = crtc->base.dev;
11867 struct drm_plane *plane;
11868 struct intel_plane *intel_plane;
11869 struct intel_plane_state *state;
11870 struct drm_framebuffer *fb;
11872 DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id,
11873 context, pipe_config, pipe_name(crtc->pipe));
11875 DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder));
11876 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
11877 pipe_config->pipe_bpp, pipe_config->dither);
11878 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11879 pipe_config->has_pch_encoder,
11880 pipe_config->fdi_lanes,
11881 pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n,
11882 pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n,
11883 pipe_config->fdi_m_n.tu);
11884 DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11885 pipe_config->has_dp_encoder,
11886 pipe_config->lane_count,
11887 pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n,
11888 pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n,
11889 pipe_config->dp_m_n.tu);
11891 DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
11892 pipe_config->has_dp_encoder,
11893 pipe_config->lane_count,
11894 pipe_config->dp_m2_n2.gmch_m,
11895 pipe_config->dp_m2_n2.gmch_n,
11896 pipe_config->dp_m2_n2.link_m,
11897 pipe_config->dp_m2_n2.link_n,
11898 pipe_config->dp_m2_n2.tu);
11900 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
11901 pipe_config->has_audio,
11902 pipe_config->has_infoframe);
11904 DRM_DEBUG_KMS("requested mode:\n");
11905 drm_mode_debug_printmodeline(&pipe_config->base.mode);
11906 DRM_DEBUG_KMS("adjusted mode:\n");
11907 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
11908 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
11909 DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock);
11910 DRM_DEBUG_KMS("pipe src size: %dx%d\n",
11911 pipe_config->pipe_src_w, pipe_config->pipe_src_h);
11912 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
11914 pipe_config->scaler_state.scaler_users,
11915 pipe_config->scaler_state.scaler_id);
11916 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
11917 pipe_config->gmch_pfit.control,
11918 pipe_config->gmch_pfit.pgm_ratios,
11919 pipe_config->gmch_pfit.lvds_border_bits);
11920 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
11921 pipe_config->pch_pfit.pos,
11922 pipe_config->pch_pfit.size,
11923 pipe_config->pch_pfit.enabled ? "enabled" : "disabled");
11924 DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled);
11925 DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide);
11927 if (IS_BROXTON(dev)) {
11928 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x,"
11929 "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, "
11930 "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n",
11931 pipe_config->ddi_pll_sel,
11932 pipe_config->dpll_hw_state.ebb0,
11933 pipe_config->dpll_hw_state.ebb4,
11934 pipe_config->dpll_hw_state.pll0,
11935 pipe_config->dpll_hw_state.pll1,
11936 pipe_config->dpll_hw_state.pll2,
11937 pipe_config->dpll_hw_state.pll3,
11938 pipe_config->dpll_hw_state.pll6,
11939 pipe_config->dpll_hw_state.pll8,
11940 pipe_config->dpll_hw_state.pll9,
11941 pipe_config->dpll_hw_state.pll10,
11942 pipe_config->dpll_hw_state.pcsdw12);
11943 } else if (IS_SKYLAKE(dev)) {
11944 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: "
11945 "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n",
11946 pipe_config->ddi_pll_sel,
11947 pipe_config->dpll_hw_state.ctrl1,
11948 pipe_config->dpll_hw_state.cfgcr1,
11949 pipe_config->dpll_hw_state.cfgcr2);
11950 } else if (HAS_DDI(dev)) {
11951 DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: wrpll: 0x%x\n",
11952 pipe_config->ddi_pll_sel,
11953 pipe_config->dpll_hw_state.wrpll);
11955 DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, "
11956 "fp0: 0x%x, fp1: 0x%x\n",
11957 pipe_config->dpll_hw_state.dpll,
11958 pipe_config->dpll_hw_state.dpll_md,
11959 pipe_config->dpll_hw_state.fp0,
11960 pipe_config->dpll_hw_state.fp1);
11963 DRM_DEBUG_KMS("planes on this crtc\n");
11964 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
11965 intel_plane = to_intel_plane(plane);
11966 if (intel_plane->pipe != crtc->pipe)
11969 state = to_intel_plane_state(plane->state);
11970 fb = state->base.fb;
11972 DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d "
11973 "disabled, scaler_id = %d\n",
11974 plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD",
11975 plane->base.id, intel_plane->pipe,
11976 (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1,
11977 drm_plane_index(plane), state->scaler_id);
11981 DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled",
11982 plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD",
11983 plane->base.id, intel_plane->pipe,
11984 crtc->base.primary == plane ? 0 : intel_plane->plane + 1,
11985 drm_plane_index(plane));
11986 DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x",
11987 fb->base.id, fb->width, fb->height, fb->pixel_format);
11988 DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n",
11990 state->src.x1 >> 16, state->src.y1 >> 16,
11991 drm_rect_width(&state->src) >> 16,
11992 drm_rect_height(&state->src) >> 16,
11993 state->dst.x1, state->dst.y1,
11994 drm_rect_width(&state->dst), drm_rect_height(&state->dst));
11998 static bool check_digital_port_conflicts(struct drm_atomic_state *state)
12000 struct drm_device *dev = state->dev;
12001 struct intel_encoder *encoder;
12002 struct drm_connector *connector;
12003 struct drm_connector_state *connector_state;
12004 unsigned int used_ports = 0;
12008 * Walk the connector list instead of the encoder
12009 * list to detect the problem on ddi platforms
12010 * where there's just one encoder per digital port.
12012 for_each_connector_in_state(state, connector, connector_state, i) {
12013 if (!connector_state->best_encoder)
12016 encoder = to_intel_encoder(connector_state->best_encoder);
12018 WARN_ON(!connector_state->crtc);
12020 switch (encoder->type) {
12021 unsigned int port_mask;
12022 case INTEL_OUTPUT_UNKNOWN:
12023 if (WARN_ON(!HAS_DDI(dev)))
12025 case INTEL_OUTPUT_DISPLAYPORT:
12026 case INTEL_OUTPUT_HDMI:
12027 case INTEL_OUTPUT_EDP:
12028 port_mask = 1 << enc_to_dig_port(&encoder->base)->port;
12030 /* the same port mustn't appear more than once */
12031 if (used_ports & port_mask)
12034 used_ports |= port_mask;
12044 clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
12046 struct drm_crtc_state tmp_state;
12047 struct intel_crtc_scaler_state scaler_state;
12048 struct intel_dpll_hw_state dpll_hw_state;
12049 enum intel_dpll_id shared_dpll;
12050 uint32_t ddi_pll_sel;
12053 /* FIXME: before the switch to atomic started, a new pipe_config was
12054 * kzalloc'd. Code that depends on any field being zero should be
12055 * fixed, so that the crtc_state can be safely duplicated. For now,
12056 * only fields that are know to not cause problems are preserved. */
12058 tmp_state = crtc_state->base;
12059 scaler_state = crtc_state->scaler_state;
12060 shared_dpll = crtc_state->shared_dpll;
12061 dpll_hw_state = crtc_state->dpll_hw_state;
12062 ddi_pll_sel = crtc_state->ddi_pll_sel;
12063 force_thru = crtc_state->pch_pfit.force_thru;
12065 memset(crtc_state, 0, sizeof *crtc_state);
12067 crtc_state->base = tmp_state;
12068 crtc_state->scaler_state = scaler_state;
12069 crtc_state->shared_dpll = shared_dpll;
12070 crtc_state->dpll_hw_state = dpll_hw_state;
12071 crtc_state->ddi_pll_sel = ddi_pll_sel;
12072 crtc_state->pch_pfit.force_thru = force_thru;
12076 intel_modeset_pipe_config(struct drm_crtc *crtc,
12077 struct intel_crtc_state *pipe_config)
12079 struct drm_atomic_state *state = pipe_config->base.state;
12080 struct intel_encoder *encoder;
12081 struct drm_connector *connector;
12082 struct drm_connector_state *connector_state;
12083 int base_bpp, ret = -EINVAL;
12087 clear_intel_crtc_state(pipe_config);
12089 pipe_config->cpu_transcoder =
12090 (enum transcoder) to_intel_crtc(crtc)->pipe;
12093 * Sanitize sync polarity flags based on requested ones. If neither
12094 * positive or negative polarity is requested, treat this as meaning
12095 * negative polarity.
12097 if (!(pipe_config->base.adjusted_mode.flags &
12098 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
12099 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
12101 if (!(pipe_config->base.adjusted_mode.flags &
12102 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
12103 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
12105 /* Compute a starting value for pipe_config->pipe_bpp taking the source
12106 * plane pixel format and any sink constraints into account. Returns the
12107 * source plane bpp so that dithering can be selected on mismatches
12108 * after encoders and crtc also have had their say. */
12109 base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
12115 * Determine the real pipe dimensions. Note that stereo modes can
12116 * increase the actual pipe size due to the frame doubling and
12117 * insertion of additional space for blanks between the frame. This
12118 * is stored in the crtc timings. We use the requested mode to do this
12119 * computation to clearly distinguish it from the adjusted mode, which
12120 * can be changed by the connectors in the below retry loop.
12122 drm_crtc_get_hv_timing(&pipe_config->base.mode,
12123 &pipe_config->pipe_src_w,
12124 &pipe_config->pipe_src_h);
12127 /* Ensure the port clock defaults are reset when retrying. */
12128 pipe_config->port_clock = 0;
12129 pipe_config->pixel_multiplier = 1;
12131 /* Fill in default crtc timings, allow encoders to overwrite them. */
12132 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
12133 CRTC_STEREO_DOUBLE);
12135 /* Pass our mode to the connectors and the CRTC to give them a chance to
12136 * adjust it according to limitations or connector properties, and also
12137 * a chance to reject the mode entirely.
12139 for_each_connector_in_state(state, connector, connector_state, i) {
12140 if (connector_state->crtc != crtc)
12143 encoder = to_intel_encoder(connector_state->best_encoder);
12145 if (!(encoder->compute_config(encoder, pipe_config))) {
12146 DRM_DEBUG_KMS("Encoder config failure\n");
12151 /* Set default port clock if not overwritten by the encoder. Needs to be
12152 * done afterwards in case the encoder adjusts the mode. */
12153 if (!pipe_config->port_clock)
12154 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
12155 * pipe_config->pixel_multiplier;
12157 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
12159 DRM_DEBUG_KMS("CRTC fixup failed\n");
12163 if (ret == RETRY) {
12164 if (WARN(!retry, "loop in pipe configuration computation\n")) {
12169 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
12171 goto encoder_retry;
12174 /* Dithering seems to not pass-through bits correctly when it should, so
12175 * only enable it on 6bpc panels. */
12176 pipe_config->dither = pipe_config->pipe_bpp == 6*3;
12177 DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
12178 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
12185 intel_modeset_update_crtc_state(struct drm_atomic_state *state)
12187 struct drm_crtc *crtc;
12188 struct drm_crtc_state *crtc_state;
12191 /* Double check state. */
12192 for_each_crtc_in_state(state, crtc, crtc_state, i) {
12193 to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state);
12195 /* Update hwmode for vblank functions */
12196 if (crtc->state->active)
12197 crtc->hwmode = crtc->state->adjusted_mode;
12199 crtc->hwmode.crtc_clock = 0;
12203 static bool intel_fuzzy_clock_check(int clock1, int clock2)
12207 if (clock1 == clock2)
12210 if (!clock1 || !clock2)
12213 diff = abs(clock1 - clock2);
12215 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
12221 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
12222 list_for_each_entry((intel_crtc), \
12223 &(dev)->mode_config.crtc_list, \
12225 if (mask & (1 <<(intel_crtc)->pipe))
12229 intel_compare_m_n(unsigned int m, unsigned int n,
12230 unsigned int m2, unsigned int n2,
12233 if (m == m2 && n == n2)
12236 if (exact || !m || !n || !m2 || !n2)
12239 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
12246 } else if (m < m2) {
12253 return m == m2 && n == n2;
12257 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
12258 struct intel_link_m_n *m2_n2,
12261 if (m_n->tu == m2_n2->tu &&
12262 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
12263 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
12264 intel_compare_m_n(m_n->link_m, m_n->link_n,
12265 m2_n2->link_m, m2_n2->link_n, !adjust)) {
12276 intel_pipe_config_compare(struct drm_device *dev,
12277 struct intel_crtc_state *current_config,
12278 struct intel_crtc_state *pipe_config,
12283 #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \
12286 DRM_ERROR(fmt, ##__VA_ARGS__); \
12288 DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \
12291 #define PIPE_CONF_CHECK_X(name) \
12292 if (current_config->name != pipe_config->name) { \
12293 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12294 "(expected 0x%08x, found 0x%08x)\n", \
12295 current_config->name, \
12296 pipe_config->name); \
12300 #define PIPE_CONF_CHECK_I(name) \
12301 if (current_config->name != pipe_config->name) { \
12302 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12303 "(expected %i, found %i)\n", \
12304 current_config->name, \
12305 pipe_config->name); \
12309 #define PIPE_CONF_CHECK_M_N(name) \
12310 if (!intel_compare_link_m_n(¤t_config->name, \
12311 &pipe_config->name,\
12313 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12314 "(expected tu %i gmch %i/%i link %i/%i, " \
12315 "found tu %i, gmch %i/%i link %i/%i)\n", \
12316 current_config->name.tu, \
12317 current_config->name.gmch_m, \
12318 current_config->name.gmch_n, \
12319 current_config->name.link_m, \
12320 current_config->name.link_n, \
12321 pipe_config->name.tu, \
12322 pipe_config->name.gmch_m, \
12323 pipe_config->name.gmch_n, \
12324 pipe_config->name.link_m, \
12325 pipe_config->name.link_n); \
12329 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \
12330 if (!intel_compare_link_m_n(¤t_config->name, \
12331 &pipe_config->name, adjust) && \
12332 !intel_compare_link_m_n(¤t_config->alt_name, \
12333 &pipe_config->name, adjust)) { \
12334 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12335 "(expected tu %i gmch %i/%i link %i/%i, " \
12336 "or tu %i gmch %i/%i link %i/%i, " \
12337 "found tu %i, gmch %i/%i link %i/%i)\n", \
12338 current_config->name.tu, \
12339 current_config->name.gmch_m, \
12340 current_config->name.gmch_n, \
12341 current_config->name.link_m, \
12342 current_config->name.link_n, \
12343 current_config->alt_name.tu, \
12344 current_config->alt_name.gmch_m, \
12345 current_config->alt_name.gmch_n, \
12346 current_config->alt_name.link_m, \
12347 current_config->alt_name.link_n, \
12348 pipe_config->name.tu, \
12349 pipe_config->name.gmch_m, \
12350 pipe_config->name.gmch_n, \
12351 pipe_config->name.link_m, \
12352 pipe_config->name.link_n); \
12356 /* This is required for BDW+ where there is only one set of registers for
12357 * switching between high and low RR.
12358 * This macro can be used whenever a comparison has to be made between one
12359 * hw state and multiple sw state variables.
12361 #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \
12362 if ((current_config->name != pipe_config->name) && \
12363 (current_config->alt_name != pipe_config->name)) { \
12364 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12365 "(expected %i or %i, found %i)\n", \
12366 current_config->name, \
12367 current_config->alt_name, \
12368 pipe_config->name); \
12372 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
12373 if ((current_config->name ^ pipe_config->name) & (mask)) { \
12374 INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \
12375 "(expected %i, found %i)\n", \
12376 current_config->name & (mask), \
12377 pipe_config->name & (mask)); \
12381 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
12382 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
12383 INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \
12384 "(expected %i, found %i)\n", \
12385 current_config->name, \
12386 pipe_config->name); \
12390 #define PIPE_CONF_QUIRK(quirk) \
12391 ((current_config->quirks | pipe_config->quirks) & (quirk))
12393 PIPE_CONF_CHECK_I(cpu_transcoder);
12395 PIPE_CONF_CHECK_I(has_pch_encoder);
12396 PIPE_CONF_CHECK_I(fdi_lanes);
12397 PIPE_CONF_CHECK_M_N(fdi_m_n);
12399 PIPE_CONF_CHECK_I(has_dp_encoder);
12400 PIPE_CONF_CHECK_I(lane_count);
12402 if (INTEL_INFO(dev)->gen < 8) {
12403 PIPE_CONF_CHECK_M_N(dp_m_n);
12405 PIPE_CONF_CHECK_I(has_drrs);
12406 if (current_config->has_drrs)
12407 PIPE_CONF_CHECK_M_N(dp_m2_n2);
12409 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
12411 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
12412 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
12413 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
12414 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
12415 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
12416 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
12418 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
12419 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
12420 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
12421 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
12422 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
12423 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
12425 PIPE_CONF_CHECK_I(pixel_multiplier);
12426 PIPE_CONF_CHECK_I(has_hdmi_sink);
12427 if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) ||
12428 IS_VALLEYVIEW(dev))
12429 PIPE_CONF_CHECK_I(limited_color_range);
12430 PIPE_CONF_CHECK_I(has_infoframe);
12432 PIPE_CONF_CHECK_I(has_audio);
12434 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12435 DRM_MODE_FLAG_INTERLACE);
12437 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
12438 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12439 DRM_MODE_FLAG_PHSYNC);
12440 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12441 DRM_MODE_FLAG_NHSYNC);
12442 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12443 DRM_MODE_FLAG_PVSYNC);
12444 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12445 DRM_MODE_FLAG_NVSYNC);
12448 PIPE_CONF_CHECK_I(pipe_src_w);
12449 PIPE_CONF_CHECK_I(pipe_src_h);
12451 PIPE_CONF_CHECK_I(gmch_pfit.control);
12452 /* pfit ratios are autocomputed by the hw on gen4+ */
12453 if (INTEL_INFO(dev)->gen < 4)
12454 PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios);
12455 PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits);
12457 PIPE_CONF_CHECK_I(pch_pfit.enabled);
12458 if (current_config->pch_pfit.enabled) {
12459 PIPE_CONF_CHECK_I(pch_pfit.pos);
12460 PIPE_CONF_CHECK_I(pch_pfit.size);
12463 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
12465 /* BDW+ don't expose a synchronous way to read the state */
12466 if (IS_HASWELL(dev))
12467 PIPE_CONF_CHECK_I(ips_enabled);
12469 PIPE_CONF_CHECK_I(double_wide);
12471 PIPE_CONF_CHECK_X(ddi_pll_sel);
12473 PIPE_CONF_CHECK_I(shared_dpll);
12474 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
12475 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
12476 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
12477 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
12478 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
12479 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
12480 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
12481 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
12483 if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5)
12484 PIPE_CONF_CHECK_I(pipe_bpp);
12486 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
12487 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
12489 #undef PIPE_CONF_CHECK_X
12490 #undef PIPE_CONF_CHECK_I
12491 #undef PIPE_CONF_CHECK_I_ALT
12492 #undef PIPE_CONF_CHECK_FLAGS
12493 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
12494 #undef PIPE_CONF_QUIRK
12495 #undef INTEL_ERR_OR_DBG_KMS
12500 static void check_wm_state(struct drm_device *dev)
12502 struct drm_i915_private *dev_priv = dev->dev_private;
12503 struct skl_ddb_allocation hw_ddb, *sw_ddb;
12504 struct intel_crtc *intel_crtc;
12507 if (INTEL_INFO(dev)->gen < 9)
12510 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
12511 sw_ddb = &dev_priv->wm.skl_hw.ddb;
12513 for_each_intel_crtc(dev, intel_crtc) {
12514 struct skl_ddb_entry *hw_entry, *sw_entry;
12515 const enum pipe pipe = intel_crtc->pipe;
12517 if (!intel_crtc->active)
12521 for_each_plane(dev_priv, pipe, plane) {
12522 hw_entry = &hw_ddb.plane[pipe][plane];
12523 sw_entry = &sw_ddb->plane[pipe][plane];
12525 if (skl_ddb_entry_equal(hw_entry, sw_entry))
12528 DRM_ERROR("mismatch in DDB state pipe %c plane %d "
12529 "(expected (%u,%u), found (%u,%u))\n",
12530 pipe_name(pipe), plane + 1,
12531 sw_entry->start, sw_entry->end,
12532 hw_entry->start, hw_entry->end);
12536 hw_entry = &hw_ddb.cursor[pipe];
12537 sw_entry = &sw_ddb->cursor[pipe];
12539 if (skl_ddb_entry_equal(hw_entry, sw_entry))
12542 DRM_ERROR("mismatch in DDB state pipe %c cursor "
12543 "(expected (%u,%u), found (%u,%u))\n",
12545 sw_entry->start, sw_entry->end,
12546 hw_entry->start, hw_entry->end);
12551 check_connector_state(struct drm_device *dev,
12552 struct drm_atomic_state *old_state)
12554 struct drm_connector_state *old_conn_state;
12555 struct drm_connector *connector;
12558 for_each_connector_in_state(old_state, connector, old_conn_state, i) {
12559 struct drm_encoder *encoder = connector->encoder;
12560 struct drm_connector_state *state = connector->state;
12562 /* This also checks the encoder/connector hw state with the
12563 * ->get_hw_state callbacks. */
12564 intel_connector_check_state(to_intel_connector(connector));
12566 I915_STATE_WARN(state->best_encoder != encoder,
12567 "connector's atomic encoder doesn't match legacy encoder\n");
12572 check_encoder_state(struct drm_device *dev)
12574 struct intel_encoder *encoder;
12575 struct intel_connector *connector;
12577 for_each_intel_encoder(dev, encoder) {
12578 bool enabled = false;
12581 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
12582 encoder->base.base.id,
12583 encoder->base.name);
12585 for_each_intel_connector(dev, connector) {
12586 if (connector->base.state->best_encoder != &encoder->base)
12590 I915_STATE_WARN(connector->base.state->crtc !=
12591 encoder->base.crtc,
12592 "connector's crtc doesn't match encoder crtc\n");
12595 I915_STATE_WARN(!!encoder->base.crtc != enabled,
12596 "encoder's enabled state mismatch "
12597 "(expected %i, found %i)\n",
12598 !!encoder->base.crtc, enabled);
12600 if (!encoder->base.crtc) {
12603 active = encoder->get_hw_state(encoder, &pipe);
12604 I915_STATE_WARN(active,
12605 "encoder detached but still enabled on pipe %c.\n",
12612 check_crtc_state(struct drm_device *dev, struct drm_atomic_state *old_state)
12614 struct drm_i915_private *dev_priv = dev->dev_private;
12615 struct intel_encoder *encoder;
12616 struct drm_crtc_state *old_crtc_state;
12617 struct drm_crtc *crtc;
12620 for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
12621 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12622 struct intel_crtc_state *pipe_config, *sw_config;
12625 if (!needs_modeset(crtc->state))
12628 __drm_atomic_helper_crtc_destroy_state(crtc, old_crtc_state);
12629 pipe_config = to_intel_crtc_state(old_crtc_state);
12630 memset(pipe_config, 0, sizeof(*pipe_config));
12631 pipe_config->base.crtc = crtc;
12632 pipe_config->base.state = old_state;
12634 DRM_DEBUG_KMS("[CRTC:%d]\n",
12637 active = dev_priv->display.get_pipe_config(intel_crtc,
12640 /* hw state is inconsistent with the pipe quirk */
12641 if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
12642 (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
12643 active = crtc->state->active;
12645 I915_STATE_WARN(crtc->state->active != active,
12646 "crtc active state doesn't match with hw state "
12647 "(expected %i, found %i)\n", crtc->state->active, active);
12649 I915_STATE_WARN(intel_crtc->active != crtc->state->active,
12650 "transitional active state does not match atomic hw state "
12651 "(expected %i, found %i)\n", crtc->state->active, intel_crtc->active);
12653 for_each_encoder_on_crtc(dev, crtc, encoder) {
12656 active = encoder->get_hw_state(encoder, &pipe);
12657 I915_STATE_WARN(active != crtc->state->active,
12658 "[ENCODER:%i] active %i with crtc active %i\n",
12659 encoder->base.base.id, active, crtc->state->active);
12661 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
12662 "Encoder connected to wrong pipe %c\n",
12666 encoder->get_config(encoder, pipe_config);
12669 if (!crtc->state->active)
12672 sw_config = to_intel_crtc_state(crtc->state);
12673 if (!intel_pipe_config_compare(dev, sw_config,
12674 pipe_config, false)) {
12675 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12676 intel_dump_pipe_config(intel_crtc, pipe_config,
12678 intel_dump_pipe_config(intel_crtc, sw_config,
12685 check_shared_dpll_state(struct drm_device *dev)
12687 struct drm_i915_private *dev_priv = dev->dev_private;
12688 struct intel_crtc *crtc;
12689 struct intel_dpll_hw_state dpll_hw_state;
12692 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
12693 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
12694 int enabled_crtcs = 0, active_crtcs = 0;
12697 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
12699 DRM_DEBUG_KMS("%s\n", pll->name);
12701 active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state);
12703 I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask),
12704 "more active pll users than references: %i vs %i\n",
12705 pll->active, hweight32(pll->config.crtc_mask));
12706 I915_STATE_WARN(pll->active && !pll->on,
12707 "pll in active use but not on in sw tracking\n");
12708 I915_STATE_WARN(pll->on && !pll->active,
12709 "pll in on but not on in use in sw tracking\n");
12710 I915_STATE_WARN(pll->on != active,
12711 "pll on state mismatch (expected %i, found %i)\n",
12714 for_each_intel_crtc(dev, crtc) {
12715 if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll)
12717 if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
12720 I915_STATE_WARN(pll->active != active_crtcs,
12721 "pll active crtcs mismatch (expected %i, found %i)\n",
12722 pll->active, active_crtcs);
12723 I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs,
12724 "pll enabled crtcs mismatch (expected %i, found %i)\n",
12725 hweight32(pll->config.crtc_mask), enabled_crtcs);
12727 I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, &dpll_hw_state,
12728 sizeof(dpll_hw_state)),
12729 "pll hw state mismatch\n");
12734 intel_modeset_check_state(struct drm_device *dev,
12735 struct drm_atomic_state *old_state)
12737 check_wm_state(dev);
12738 check_connector_state(dev, old_state);
12739 check_encoder_state(dev);
12740 check_crtc_state(dev, old_state);
12741 check_shared_dpll_state(dev);
12744 void ironlake_check_encoder_dotclock(const struct intel_crtc_state *pipe_config,
12748 * FDI already provided one idea for the dotclock.
12749 * Yell if the encoder disagrees.
12751 WARN(!intel_fuzzy_clock_check(pipe_config->base.adjusted_mode.crtc_clock, dotclock),
12752 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
12753 pipe_config->base.adjusted_mode.crtc_clock, dotclock);
12756 static void update_scanline_offset(struct intel_crtc *crtc)
12758 struct drm_device *dev = crtc->base.dev;
12761 * The scanline counter increments at the leading edge of hsync.
12763 * On most platforms it starts counting from vtotal-1 on the
12764 * first active line. That means the scanline counter value is
12765 * always one less than what we would expect. Ie. just after
12766 * start of vblank, which also occurs at start of hsync (on the
12767 * last active line), the scanline counter will read vblank_start-1.
12769 * On gen2 the scanline counter starts counting from 1 instead
12770 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12771 * to keep the value positive), instead of adding one.
12773 * On HSW+ the behaviour of the scanline counter depends on the output
12774 * type. For DP ports it behaves like most other platforms, but on HDMI
12775 * there's an extra 1 line difference. So we need to add two instead of
12776 * one to the value.
12778 if (IS_GEN2(dev)) {
12779 const struct drm_display_mode *mode = &crtc->config->base.adjusted_mode;
12782 vtotal = mode->crtc_vtotal;
12783 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
12786 crtc->scanline_offset = vtotal - 1;
12787 } else if (HAS_DDI(dev) &&
12788 intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) {
12789 crtc->scanline_offset = 2;
12791 crtc->scanline_offset = 1;
12794 static void intel_modeset_clear_plls(struct drm_atomic_state *state)
12796 struct drm_device *dev = state->dev;
12797 struct drm_i915_private *dev_priv = to_i915(dev);
12798 struct intel_shared_dpll_config *shared_dpll = NULL;
12799 struct intel_crtc *intel_crtc;
12800 struct intel_crtc_state *intel_crtc_state;
12801 struct drm_crtc *crtc;
12802 struct drm_crtc_state *crtc_state;
12805 if (!dev_priv->display.crtc_compute_clock)
12808 for_each_crtc_in_state(state, crtc, crtc_state, i) {
12811 intel_crtc = to_intel_crtc(crtc);
12812 intel_crtc_state = to_intel_crtc_state(crtc_state);
12813 dpll = intel_crtc_state->shared_dpll;
12815 if (!needs_modeset(crtc_state) || dpll == DPLL_ID_PRIVATE)
12818 intel_crtc_state->shared_dpll = DPLL_ID_PRIVATE;
12821 shared_dpll = intel_atomic_get_shared_dpll_state(state);
12823 shared_dpll[dpll].crtc_mask &= ~(1 << intel_crtc->pipe);
12828 * This implements the workaround described in the "notes" section of the mode
12829 * set sequence documentation. When going from no pipes or single pipe to
12830 * multiple pipes, and planes are enabled after the pipe, we need to wait at
12831 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
12833 static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
12835 struct drm_crtc_state *crtc_state;
12836 struct intel_crtc *intel_crtc;
12837 struct drm_crtc *crtc;
12838 struct intel_crtc_state *first_crtc_state = NULL;
12839 struct intel_crtc_state *other_crtc_state = NULL;
12840 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
12843 /* look at all crtc's that are going to be enabled in during modeset */
12844 for_each_crtc_in_state(state, crtc, crtc_state, i) {
12845 intel_crtc = to_intel_crtc(crtc);
12847 if (!crtc_state->active || !needs_modeset(crtc_state))
12850 if (first_crtc_state) {
12851 other_crtc_state = to_intel_crtc_state(crtc_state);
12854 first_crtc_state = to_intel_crtc_state(crtc_state);
12855 first_pipe = intel_crtc->pipe;
12859 /* No workaround needed? */
12860 if (!first_crtc_state)
12863 /* w/a possibly needed, check how many crtc's are already enabled. */
12864 for_each_intel_crtc(state->dev, intel_crtc) {
12865 struct intel_crtc_state *pipe_config;
12867 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
12868 if (IS_ERR(pipe_config))
12869 return PTR_ERR(pipe_config);
12871 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
12873 if (!pipe_config->base.active ||
12874 needs_modeset(&pipe_config->base))
12877 /* 2 or more enabled crtcs means no need for w/a */
12878 if (enabled_pipe != INVALID_PIPE)
12881 enabled_pipe = intel_crtc->pipe;
12884 if (enabled_pipe != INVALID_PIPE)
12885 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
12886 else if (other_crtc_state)
12887 other_crtc_state->hsw_workaround_pipe = first_pipe;
12892 static int intel_modeset_all_pipes(struct drm_atomic_state *state)
12894 struct drm_crtc *crtc;
12895 struct drm_crtc_state *crtc_state;
12898 /* add all active pipes to the state */
12899 for_each_crtc(state->dev, crtc) {
12900 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12901 if (IS_ERR(crtc_state))
12902 return PTR_ERR(crtc_state);
12904 if (!crtc_state->active || needs_modeset(crtc_state))
12907 crtc_state->mode_changed = true;
12909 ret = drm_atomic_add_affected_connectors(state, crtc);
12913 ret = drm_atomic_add_affected_planes(state, crtc);
12922 static int intel_modeset_checks(struct drm_atomic_state *state)
12924 struct drm_device *dev = state->dev;
12925 struct drm_i915_private *dev_priv = dev->dev_private;
12928 if (!check_digital_port_conflicts(state)) {
12929 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12934 * See if the config requires any additional preparation, e.g.
12935 * to adjust global state with pipes off. We need to do this
12936 * here so we can get the modeset_pipe updated config for the new
12937 * mode set on this crtc. For other crtcs we need to use the
12938 * adjusted_mode bits in the crtc directly.
12940 if (dev_priv->display.modeset_calc_cdclk) {
12941 unsigned int cdclk;
12943 ret = dev_priv->display.modeset_calc_cdclk(state);
12945 cdclk = to_intel_atomic_state(state)->cdclk;
12946 if (!ret && cdclk != dev_priv->cdclk_freq)
12947 ret = intel_modeset_all_pipes(state);
12952 to_intel_atomic_state(state)->cdclk = dev_priv->cdclk_freq;
12954 intel_modeset_clear_plls(state);
12956 if (IS_HASWELL(dev))
12957 return haswell_mode_set_planes_workaround(state);
12963 * intel_atomic_check - validate state object
12965 * @state: state to validate
12967 static int intel_atomic_check(struct drm_device *dev,
12968 struct drm_atomic_state *state)
12970 struct drm_crtc *crtc;
12971 struct drm_crtc_state *crtc_state;
12973 bool any_ms = false;
12975 ret = drm_atomic_helper_check_modeset(dev, state);
12979 for_each_crtc_in_state(state, crtc, crtc_state, i) {
12980 struct intel_crtc_state *pipe_config =
12981 to_intel_crtc_state(crtc_state);
12983 /* Catch I915_MODE_FLAG_INHERITED */
12984 if (crtc_state->mode.private_flags != crtc->state->mode.private_flags)
12985 crtc_state->mode_changed = true;
12987 if (!crtc_state->enable) {
12988 if (needs_modeset(crtc_state))
12993 if (!needs_modeset(crtc_state))
12996 /* FIXME: For only active_changed we shouldn't need to do any
12997 * state recomputation at all. */
12999 ret = drm_atomic_add_affected_connectors(state, crtc);
13003 ret = intel_modeset_pipe_config(crtc, pipe_config);
13007 if (i915.fastboot &&
13008 intel_pipe_config_compare(state->dev,
13009 to_intel_crtc_state(crtc->state),
13010 pipe_config, true)) {
13011 crtc_state->mode_changed = false;
13014 if (needs_modeset(crtc_state)) {
13017 ret = drm_atomic_add_affected_planes(state, crtc);
13022 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
13023 needs_modeset(crtc_state) ?
13024 "[modeset]" : "[fastset]");
13028 ret = intel_modeset_checks(state);
13033 to_intel_atomic_state(state)->cdclk =
13034 to_i915(state->dev)->cdclk_freq;
13036 return drm_atomic_helper_check_planes(state->dev, state);
13040 * intel_atomic_commit - commit validated state object
13042 * @state: the top-level driver state object
13043 * @async: asynchronous commit
13045 * This function commits a top-level state object that has been validated
13046 * with drm_atomic_helper_check().
13048 * FIXME: Atomic modeset support for i915 is not yet complete. At the moment
13049 * we can only handle plane-related operations and do not yet support
13050 * asynchronous commit.
13053 * Zero for success or -errno.
13055 static int intel_atomic_commit(struct drm_device *dev,
13056 struct drm_atomic_state *state,
13059 struct drm_i915_private *dev_priv = dev->dev_private;
13060 struct drm_crtc *crtc;
13061 struct drm_crtc_state *crtc_state;
13064 bool any_ms = false;
13067 DRM_DEBUG_KMS("i915 does not yet support async commit\n");
13071 ret = drm_atomic_helper_prepare_planes(dev, state);
13075 drm_atomic_helper_swap_state(dev, state);
13077 for_each_crtc_in_state(state, crtc, crtc_state, i) {
13078 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13080 if (!needs_modeset(crtc->state))
13084 intel_pre_plane_update(intel_crtc);
13086 if (crtc_state->active) {
13087 intel_crtc_disable_planes(crtc, crtc_state->plane_mask);
13088 dev_priv->display.crtc_disable(crtc);
13089 intel_crtc->active = false;
13090 intel_disable_shared_dpll(intel_crtc);
13094 /* Only after disabling all output pipelines that will be changed can we
13095 * update the the output configuration. */
13096 intel_modeset_update_crtc_state(state);
13099 intel_shared_dpll_commit(state);
13101 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
13102 modeset_update_crtc_power_domains(state);
13105 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
13106 for_each_crtc_in_state(state, crtc, crtc_state, i) {
13107 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13108 bool modeset = needs_modeset(crtc->state);
13110 if (modeset && crtc->state->active) {
13111 update_scanline_offset(to_intel_crtc(crtc));
13112 dev_priv->display.crtc_enable(crtc);
13116 intel_pre_plane_update(intel_crtc);
13118 drm_atomic_helper_commit_planes_on_crtc(crtc_state);
13119 intel_post_plane_update(intel_crtc);
13122 /* FIXME: add subpixel order */
13124 drm_atomic_helper_wait_for_vblanks(dev, state);
13125 drm_atomic_helper_cleanup_planes(dev, state);
13128 intel_modeset_check_state(dev, state);
13130 drm_atomic_state_free(state);
13135 void intel_crtc_restore_mode(struct drm_crtc *crtc)
13137 struct drm_device *dev = crtc->dev;
13138 struct drm_atomic_state *state;
13139 struct drm_crtc_state *crtc_state;
13142 state = drm_atomic_state_alloc(dev);
13144 DRM_DEBUG_KMS("[CRTC:%d] crtc restore failed, out of memory",
13149 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
13152 crtc_state = drm_atomic_get_crtc_state(state, crtc);
13153 ret = PTR_ERR_OR_ZERO(crtc_state);
13155 if (!crtc_state->active)
13158 crtc_state->mode_changed = true;
13159 ret = drm_atomic_commit(state);
13162 if (ret == -EDEADLK) {
13163 drm_atomic_state_clear(state);
13164 drm_modeset_backoff(state->acquire_ctx);
13170 drm_atomic_state_free(state);
13173 #undef for_each_intel_crtc_masked
13175 static const struct drm_crtc_funcs intel_crtc_funcs = {
13176 .gamma_set = intel_crtc_gamma_set,
13177 .set_config = drm_atomic_helper_set_config,
13178 .destroy = intel_crtc_destroy,
13179 .page_flip = intel_crtc_page_flip,
13180 .atomic_duplicate_state = intel_crtc_duplicate_state,
13181 .atomic_destroy_state = intel_crtc_destroy_state,
13184 static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv,
13185 struct intel_shared_dpll *pll,
13186 struct intel_dpll_hw_state *hw_state)
13190 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS))
13193 val = I915_READ(PCH_DPLL(pll->id));
13194 hw_state->dpll = val;
13195 hw_state->fp0 = I915_READ(PCH_FP0(pll->id));
13196 hw_state->fp1 = I915_READ(PCH_FP1(pll->id));
13198 return val & DPLL_VCO_ENABLE;
13201 static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv,
13202 struct intel_shared_dpll *pll)
13204 I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0);
13205 I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1);
13208 static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv,
13209 struct intel_shared_dpll *pll)
13211 /* PCH refclock must be enabled first */
13212 ibx_assert_pch_refclk_enabled(dev_priv);
13214 I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll);
13216 /* Wait for the clocks to stabilize. */
13217 POSTING_READ(PCH_DPLL(pll->id));
13220 /* The pixel multiplier can only be updated once the
13221 * DPLL is enabled and the clocks are stable.
13223 * So write it again.
13225 I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll);
13226 POSTING_READ(PCH_DPLL(pll->id));
13230 static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv,
13231 struct intel_shared_dpll *pll)
13233 struct drm_device *dev = dev_priv->dev;
13234 struct intel_crtc *crtc;
13236 /* Make sure no transcoder isn't still depending on us. */
13237 for_each_intel_crtc(dev, crtc) {
13238 if (intel_crtc_to_shared_dpll(crtc) == pll)
13239 assert_pch_transcoder_disabled(dev_priv, crtc->pipe);
13242 I915_WRITE(PCH_DPLL(pll->id), 0);
13243 POSTING_READ(PCH_DPLL(pll->id));
13247 static char *ibx_pch_dpll_names[] = {
13252 static void ibx_pch_dpll_init(struct drm_device *dev)
13254 struct drm_i915_private *dev_priv = dev->dev_private;
13257 dev_priv->num_shared_dpll = 2;
13259 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
13260 dev_priv->shared_dplls[i].id = i;
13261 dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i];
13262 dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set;
13263 dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable;
13264 dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable;
13265 dev_priv->shared_dplls[i].get_hw_state =
13266 ibx_pch_dpll_get_hw_state;
13270 static void intel_shared_dpll_init(struct drm_device *dev)
13272 struct drm_i915_private *dev_priv = dev->dev_private;
13274 intel_update_cdclk(dev);
13277 intel_ddi_pll_init(dev);
13278 else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
13279 ibx_pch_dpll_init(dev);
13281 dev_priv->num_shared_dpll = 0;
13283 BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS);
13287 * intel_prepare_plane_fb - Prepare fb for usage on plane
13288 * @plane: drm plane to prepare for
13289 * @fb: framebuffer to prepare for presentation
13291 * Prepares a framebuffer for usage on a display plane. Generally this
13292 * involves pinning the underlying object and updating the frontbuffer tracking
13293 * bits. Some older platforms need special physical address handling for
13296 * Returns 0 on success, negative error code on failure.
13299 intel_prepare_plane_fb(struct drm_plane *plane,
13300 struct drm_framebuffer *fb,
13301 const struct drm_plane_state *new_state)
13303 struct drm_device *dev = plane->dev;
13304 struct intel_plane *intel_plane = to_intel_plane(plane);
13305 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13306 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
13312 mutex_lock(&dev->struct_mutex);
13314 if (plane->type == DRM_PLANE_TYPE_CURSOR &&
13315 INTEL_INFO(dev)->cursor_needs_physical) {
13316 int align = IS_I830(dev) ? 16 * 1024 : 256;
13317 ret = i915_gem_object_attach_phys(obj, align);
13319 DRM_DEBUG_KMS("failed to attach phys object\n");
13321 ret = intel_pin_and_fence_fb_obj(plane, fb, new_state, NULL, NULL);
13325 i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit);
13327 mutex_unlock(&dev->struct_mutex);
13333 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13334 * @plane: drm plane to clean up for
13335 * @fb: old framebuffer that was on plane
13337 * Cleans up a framebuffer that has just been removed from a plane.
13340 intel_cleanup_plane_fb(struct drm_plane *plane,
13341 struct drm_framebuffer *fb,
13342 const struct drm_plane_state *old_state)
13344 struct drm_device *dev = plane->dev;
13345 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13350 if (plane->type != DRM_PLANE_TYPE_CURSOR ||
13351 !INTEL_INFO(dev)->cursor_needs_physical) {
13352 mutex_lock(&dev->struct_mutex);
13353 intel_unpin_fb_obj(fb, old_state);
13354 mutex_unlock(&dev->struct_mutex);
13359 skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state)
13362 struct drm_device *dev;
13363 struct drm_i915_private *dev_priv;
13364 int crtc_clock, cdclk;
13366 if (!intel_crtc || !crtc_state)
13367 return DRM_PLANE_HELPER_NO_SCALING;
13369 dev = intel_crtc->base.dev;
13370 dev_priv = dev->dev_private;
13371 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
13372 cdclk = to_intel_atomic_state(crtc_state->base.state)->cdclk;
13374 if (!crtc_clock || !cdclk)
13375 return DRM_PLANE_HELPER_NO_SCALING;
13378 * skl max scale is lower of:
13379 * close to 3 but not 3, -1 is for that purpose
13383 max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock));
13389 intel_check_primary_plane(struct drm_plane *plane,
13390 struct intel_crtc_state *crtc_state,
13391 struct intel_plane_state *state)
13393 struct drm_crtc *crtc = state->base.crtc;
13394 struct drm_framebuffer *fb = state->base.fb;
13395 int min_scale = DRM_PLANE_HELPER_NO_SCALING;
13396 int max_scale = DRM_PLANE_HELPER_NO_SCALING;
13397 bool can_position = false;
13399 /* use scaler when colorkey is not required */
13400 if (INTEL_INFO(plane->dev)->gen >= 9 &&
13401 state->ckey.flags == I915_SET_COLORKEY_NONE) {
13403 max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state);
13404 can_position = true;
13407 return drm_plane_helper_check_update(plane, crtc, fb, &state->src,
13408 &state->dst, &state->clip,
13409 min_scale, max_scale,
13410 can_position, true,
13415 intel_commit_primary_plane(struct drm_plane *plane,
13416 struct intel_plane_state *state)
13418 struct drm_crtc *crtc = state->base.crtc;
13419 struct drm_framebuffer *fb = state->base.fb;
13420 struct drm_device *dev = plane->dev;
13421 struct drm_i915_private *dev_priv = dev->dev_private;
13422 struct intel_crtc *intel_crtc;
13423 struct drm_rect *src = &state->src;
13425 crtc = crtc ? crtc : plane->crtc;
13426 intel_crtc = to_intel_crtc(crtc);
13429 crtc->x = src->x1 >> 16;
13430 crtc->y = src->y1 >> 16;
13432 if (!crtc->state->active)
13435 if (state->visible)
13436 /* FIXME: kill this fastboot hack */
13437 intel_update_pipe_size(intel_crtc);
13439 dev_priv->display.update_primary_plane(crtc, fb, crtc->x, crtc->y);
13443 intel_disable_primary_plane(struct drm_plane *plane,
13444 struct drm_crtc *crtc)
13446 struct drm_device *dev = plane->dev;
13447 struct drm_i915_private *dev_priv = dev->dev_private;
13449 dev_priv->display.update_primary_plane(crtc, NULL, 0, 0);
13452 static void intel_begin_crtc_commit(struct drm_crtc *crtc,
13453 struct drm_crtc_state *old_crtc_state)
13455 struct drm_device *dev = crtc->dev;
13456 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13458 if (intel_crtc->atomic.update_wm_pre)
13459 intel_update_watermarks(crtc);
13461 /* Perform vblank evasion around commit operation */
13462 if (crtc->state->active)
13463 intel_pipe_update_start(intel_crtc);
13465 if (!needs_modeset(crtc->state) && INTEL_INFO(dev)->gen >= 9)
13466 skl_detach_scalers(intel_crtc);
13469 static void intel_finish_crtc_commit(struct drm_crtc *crtc,
13470 struct drm_crtc_state *old_crtc_state)
13472 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13474 if (crtc->state->active)
13475 intel_pipe_update_end(intel_crtc);
13479 * intel_plane_destroy - destroy a plane
13480 * @plane: plane to destroy
13482 * Common destruction function for all types of planes (primary, cursor,
13485 void intel_plane_destroy(struct drm_plane *plane)
13487 struct intel_plane *intel_plane = to_intel_plane(plane);
13488 drm_plane_cleanup(plane);
13489 kfree(intel_plane);
13492 const struct drm_plane_funcs intel_plane_funcs = {
13493 .update_plane = drm_atomic_helper_update_plane,
13494 .disable_plane = drm_atomic_helper_disable_plane,
13495 .destroy = intel_plane_destroy,
13496 .set_property = drm_atomic_helper_plane_set_property,
13497 .atomic_get_property = intel_plane_atomic_get_property,
13498 .atomic_set_property = intel_plane_atomic_set_property,
13499 .atomic_duplicate_state = intel_plane_duplicate_state,
13500 .atomic_destroy_state = intel_plane_destroy_state,
13504 static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
13507 struct intel_plane *primary;
13508 struct intel_plane_state *state;
13509 const uint32_t *intel_primary_formats;
13510 unsigned int num_formats;
13512 primary = kzalloc(sizeof(*primary), GFP_KERNEL);
13513 if (primary == NULL)
13516 state = intel_create_plane_state(&primary->base);
13521 primary->base.state = &state->base;
13523 primary->can_scale = false;
13524 primary->max_downscale = 1;
13525 if (INTEL_INFO(dev)->gen >= 9) {
13526 primary->can_scale = true;
13527 state->scaler_id = -1;
13529 primary->pipe = pipe;
13530 primary->plane = pipe;
13531 primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe);
13532 primary->check_plane = intel_check_primary_plane;
13533 primary->commit_plane = intel_commit_primary_plane;
13534 primary->disable_plane = intel_disable_primary_plane;
13535 if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4)
13536 primary->plane = !pipe;
13538 if (INTEL_INFO(dev)->gen >= 9) {
13539 intel_primary_formats = skl_primary_formats;
13540 num_formats = ARRAY_SIZE(skl_primary_formats);
13541 } else if (INTEL_INFO(dev)->gen >= 4) {
13542 intel_primary_formats = i965_primary_formats;
13543 num_formats = ARRAY_SIZE(i965_primary_formats);
13545 intel_primary_formats = i8xx_primary_formats;
13546 num_formats = ARRAY_SIZE(i8xx_primary_formats);
13549 drm_universal_plane_init(dev, &primary->base, 0,
13550 &intel_plane_funcs,
13551 intel_primary_formats, num_formats,
13552 DRM_PLANE_TYPE_PRIMARY);
13554 if (INTEL_INFO(dev)->gen >= 4)
13555 intel_create_rotation_property(dev, primary);
13557 drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs);
13559 return &primary->base;
13562 void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane)
13564 if (!dev->mode_config.rotation_property) {
13565 unsigned long flags = BIT(DRM_ROTATE_0) |
13566 BIT(DRM_ROTATE_180);
13568 if (INTEL_INFO(dev)->gen >= 9)
13569 flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270);
13571 dev->mode_config.rotation_property =
13572 drm_mode_create_rotation_property(dev, flags);
13574 if (dev->mode_config.rotation_property)
13575 drm_object_attach_property(&plane->base.base,
13576 dev->mode_config.rotation_property,
13577 plane->base.state->rotation);
13581 intel_check_cursor_plane(struct drm_plane *plane,
13582 struct intel_crtc_state *crtc_state,
13583 struct intel_plane_state *state)
13585 struct drm_crtc *crtc = crtc_state->base.crtc;
13586 struct drm_framebuffer *fb = state->base.fb;
13587 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13591 ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src,
13592 &state->dst, &state->clip,
13593 DRM_PLANE_HELPER_NO_SCALING,
13594 DRM_PLANE_HELPER_NO_SCALING,
13595 true, true, &state->visible);
13599 /* if we want to turn off the cursor ignore width and height */
13603 /* Check for which cursor types we support */
13604 if (!cursor_size_ok(plane->dev, state->base.crtc_w, state->base.crtc_h)) {
13605 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
13606 state->base.crtc_w, state->base.crtc_h);
13610 stride = roundup_pow_of_two(state->base.crtc_w) * 4;
13611 if (obj->base.size < stride * state->base.crtc_h) {
13612 DRM_DEBUG_KMS("buffer is too small\n");
13616 if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) {
13617 DRM_DEBUG_KMS("cursor cannot be tiled\n");
13625 intel_disable_cursor_plane(struct drm_plane *plane,
13626 struct drm_crtc *crtc)
13628 intel_crtc_update_cursor(crtc, false);
13632 intel_commit_cursor_plane(struct drm_plane *plane,
13633 struct intel_plane_state *state)
13635 struct drm_crtc *crtc = state->base.crtc;
13636 struct drm_device *dev = plane->dev;
13637 struct intel_crtc *intel_crtc;
13638 struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb);
13641 crtc = crtc ? crtc : plane->crtc;
13642 intel_crtc = to_intel_crtc(crtc);
13644 plane->fb = state->base.fb;
13645 crtc->cursor_x = state->base.crtc_x;
13646 crtc->cursor_y = state->base.crtc_y;
13648 if (intel_crtc->cursor_bo == obj)
13653 else if (!INTEL_INFO(dev)->cursor_needs_physical)
13654 addr = i915_gem_obj_ggtt_offset(obj);
13656 addr = obj->phys_handle->busaddr;
13658 intel_crtc->cursor_addr = addr;
13659 intel_crtc->cursor_bo = obj;
13662 if (crtc->state->active)
13663 intel_crtc_update_cursor(crtc, state->visible);
13666 static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
13669 struct intel_plane *cursor;
13670 struct intel_plane_state *state;
13672 cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
13673 if (cursor == NULL)
13676 state = intel_create_plane_state(&cursor->base);
13681 cursor->base.state = &state->base;
13683 cursor->can_scale = false;
13684 cursor->max_downscale = 1;
13685 cursor->pipe = pipe;
13686 cursor->plane = pipe;
13687 cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe);
13688 cursor->check_plane = intel_check_cursor_plane;
13689 cursor->commit_plane = intel_commit_cursor_plane;
13690 cursor->disable_plane = intel_disable_cursor_plane;
13692 drm_universal_plane_init(dev, &cursor->base, 0,
13693 &intel_plane_funcs,
13694 intel_cursor_formats,
13695 ARRAY_SIZE(intel_cursor_formats),
13696 DRM_PLANE_TYPE_CURSOR);
13698 if (INTEL_INFO(dev)->gen >= 4) {
13699 if (!dev->mode_config.rotation_property)
13700 dev->mode_config.rotation_property =
13701 drm_mode_create_rotation_property(dev,
13702 BIT(DRM_ROTATE_0) |
13703 BIT(DRM_ROTATE_180));
13704 if (dev->mode_config.rotation_property)
13705 drm_object_attach_property(&cursor->base.base,
13706 dev->mode_config.rotation_property,
13707 state->base.rotation);
13710 if (INTEL_INFO(dev)->gen >=9)
13711 state->scaler_id = -1;
13713 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
13715 return &cursor->base;
13718 static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc,
13719 struct intel_crtc_state *crtc_state)
13722 struct intel_scaler *intel_scaler;
13723 struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state;
13725 for (i = 0; i < intel_crtc->num_scalers; i++) {
13726 intel_scaler = &scaler_state->scalers[i];
13727 intel_scaler->in_use = 0;
13728 intel_scaler->mode = PS_SCALER_MODE_DYN;
13731 scaler_state->scaler_id = -1;
13734 static void intel_crtc_init(struct drm_device *dev, int pipe)
13736 struct drm_i915_private *dev_priv = dev->dev_private;
13737 struct intel_crtc *intel_crtc;
13738 struct intel_crtc_state *crtc_state = NULL;
13739 struct drm_plane *primary = NULL;
13740 struct drm_plane *cursor = NULL;
13743 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
13744 if (intel_crtc == NULL)
13747 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
13750 intel_crtc->config = crtc_state;
13751 intel_crtc->base.state = &crtc_state->base;
13752 crtc_state->base.crtc = &intel_crtc->base;
13754 /* initialize shared scalers */
13755 if (INTEL_INFO(dev)->gen >= 9) {
13756 if (pipe == PIPE_C)
13757 intel_crtc->num_scalers = 1;
13759 intel_crtc->num_scalers = SKL_NUM_SCALERS;
13761 skl_init_scalers(dev, intel_crtc, crtc_state);
13764 primary = intel_primary_plane_create(dev, pipe);
13768 cursor = intel_cursor_plane_create(dev, pipe);
13772 ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary,
13773 cursor, &intel_crtc_funcs);
13777 drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
13778 for (i = 0; i < 256; i++) {
13779 intel_crtc->lut_r[i] = i;
13780 intel_crtc->lut_g[i] = i;
13781 intel_crtc->lut_b[i] = i;
13785 * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
13786 * is hooked to pipe B. Hence we want plane A feeding pipe B.
13788 intel_crtc->pipe = pipe;
13789 intel_crtc->plane = pipe;
13790 if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) {
13791 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
13792 intel_crtc->plane = !pipe;
13795 intel_crtc->cursor_base = ~0;
13796 intel_crtc->cursor_cntl = ~0;
13797 intel_crtc->cursor_size = ~0;
13799 intel_crtc->wm.cxsr_allowed = true;
13801 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
13802 dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
13803 dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
13804 dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
13806 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
13808 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
13813 drm_plane_cleanup(primary);
13815 drm_plane_cleanup(cursor);
13820 enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
13822 struct drm_encoder *encoder = connector->base.encoder;
13823 struct drm_device *dev = connector->base.dev;
13825 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
13827 if (!encoder || WARN_ON(!encoder->crtc))
13828 return INVALID_PIPE;
13830 return to_intel_crtc(encoder->crtc)->pipe;
13833 int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
13834 struct drm_file *file)
13836 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
13837 struct drm_crtc *drmmode_crtc;
13838 struct intel_crtc *crtc;
13840 drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id);
13842 if (!drmmode_crtc) {
13843 DRM_ERROR("no such CRTC id\n");
13847 crtc = to_intel_crtc(drmmode_crtc);
13848 pipe_from_crtc_id->pipe = crtc->pipe;
13853 static int intel_encoder_clones(struct intel_encoder *encoder)
13855 struct drm_device *dev = encoder->base.dev;
13856 struct intel_encoder *source_encoder;
13857 int index_mask = 0;
13860 for_each_intel_encoder(dev, source_encoder) {
13861 if (encoders_cloneable(encoder, source_encoder))
13862 index_mask |= (1 << entry);
13870 static bool has_edp_a(struct drm_device *dev)
13872 struct drm_i915_private *dev_priv = dev->dev_private;
13874 if (!IS_MOBILE(dev))
13877 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
13880 if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
13886 static bool intel_crt_present(struct drm_device *dev)
13888 struct drm_i915_private *dev_priv = dev->dev_private;
13890 if (INTEL_INFO(dev)->gen >= 9)
13893 if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev))
13896 if (IS_CHERRYVIEW(dev))
13899 if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support)
13905 static void intel_setup_outputs(struct drm_device *dev)
13907 struct drm_i915_private *dev_priv = dev->dev_private;
13908 struct intel_encoder *encoder;
13909 bool dpd_is_edp = false;
13911 intel_lvds_init(dev);
13913 if (intel_crt_present(dev))
13914 intel_crt_init(dev);
13916 if (IS_BROXTON(dev)) {
13918 * FIXME: Broxton doesn't support port detection via the
13919 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
13920 * detect the ports.
13922 intel_ddi_init(dev, PORT_A);
13923 intel_ddi_init(dev, PORT_B);
13924 intel_ddi_init(dev, PORT_C);
13925 } else if (HAS_DDI(dev)) {
13929 * Haswell uses DDI functions to detect digital outputs.
13930 * On SKL pre-D0 the strap isn't connected, so we assume
13933 found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
13934 /* WaIgnoreDDIAStrap: skl */
13935 if (found || IS_SKYLAKE(dev))
13936 intel_ddi_init(dev, PORT_A);
13938 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
13940 found = I915_READ(SFUSE_STRAP);
13942 if (found & SFUSE_STRAP_DDIB_DETECTED)
13943 intel_ddi_init(dev, PORT_B);
13944 if (found & SFUSE_STRAP_DDIC_DETECTED)
13945 intel_ddi_init(dev, PORT_C);
13946 if (found & SFUSE_STRAP_DDID_DETECTED)
13947 intel_ddi_init(dev, PORT_D);
13949 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
13951 if (IS_SKYLAKE(dev) &&
13952 (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp ||
13953 dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi ||
13954 dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi))
13955 intel_ddi_init(dev, PORT_E);
13957 } else if (HAS_PCH_SPLIT(dev)) {
13959 dpd_is_edp = intel_dp_is_edp(dev, PORT_D);
13961 if (has_edp_a(dev))
13962 intel_dp_init(dev, DP_A, PORT_A);
13964 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
13965 /* PCH SDVOB multiplex with HDMIB */
13966 found = intel_sdvo_init(dev, PCH_SDVOB, true);
13968 intel_hdmi_init(dev, PCH_HDMIB, PORT_B);
13969 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
13970 intel_dp_init(dev, PCH_DP_B, PORT_B);
13973 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
13974 intel_hdmi_init(dev, PCH_HDMIC, PORT_C);
13976 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
13977 intel_hdmi_init(dev, PCH_HDMID, PORT_D);
13979 if (I915_READ(PCH_DP_C) & DP_DETECTED)
13980 intel_dp_init(dev, PCH_DP_C, PORT_C);
13982 if (I915_READ(PCH_DP_D) & DP_DETECTED)
13983 intel_dp_init(dev, PCH_DP_D, PORT_D);
13984 } else if (IS_VALLEYVIEW(dev)) {
13986 * The DP_DETECTED bit is the latched state of the DDC
13987 * SDA pin at boot. However since eDP doesn't require DDC
13988 * (no way to plug in a DP->HDMI dongle) the DDC pins for
13989 * eDP ports may have been muxed to an alternate function.
13990 * Thus we can't rely on the DP_DETECTED bit alone to detect
13991 * eDP ports. Consult the VBT as well as DP_DETECTED to
13992 * detect eDP ports.
13994 if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED &&
13995 !intel_dp_is_edp(dev, PORT_B))
13996 intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB,
13998 if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED ||
13999 intel_dp_is_edp(dev, PORT_B))
14000 intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
14002 if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED &&
14003 !intel_dp_is_edp(dev, PORT_C))
14004 intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC,
14006 if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED ||
14007 intel_dp_is_edp(dev, PORT_C))
14008 intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
14010 if (IS_CHERRYVIEW(dev)) {
14011 if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED)
14012 intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID,
14014 /* eDP not supported on port D, so don't check VBT */
14015 if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED)
14016 intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D);
14019 intel_dsi_init(dev);
14020 } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) {
14021 bool found = false;
14023 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14024 DRM_DEBUG_KMS("probing SDVOB\n");
14025 found = intel_sdvo_init(dev, GEN3_SDVOB, true);
14026 if (!found && IS_G4X(dev)) {
14027 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
14028 intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
14031 if (!found && IS_G4X(dev))
14032 intel_dp_init(dev, DP_B, PORT_B);
14035 /* Before G4X SDVOC doesn't have its own detect register */
14037 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14038 DRM_DEBUG_KMS("probing SDVOC\n");
14039 found = intel_sdvo_init(dev, GEN3_SDVOC, false);
14042 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
14045 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
14046 intel_hdmi_init(dev, GEN4_HDMIC, PORT_C);
14049 intel_dp_init(dev, DP_C, PORT_C);
14053 (I915_READ(DP_D) & DP_DETECTED))
14054 intel_dp_init(dev, DP_D, PORT_D);
14055 } else if (IS_GEN2(dev))
14056 intel_dvo_init(dev);
14058 if (SUPPORTS_TV(dev))
14059 intel_tv_init(dev);
14061 intel_psr_init(dev);
14063 for_each_intel_encoder(dev, encoder) {
14064 encoder->base.possible_crtcs = encoder->crtc_mask;
14065 encoder->base.possible_clones =
14066 intel_encoder_clones(encoder);
14069 intel_init_pch_refclk(dev);
14071 drm_helper_move_panel_connectors_to_head(dev);
14074 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14076 struct drm_device *dev = fb->dev;
14077 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14079 drm_framebuffer_cleanup(fb);
14080 mutex_lock(&dev->struct_mutex);
14081 WARN_ON(!intel_fb->obj->framebuffer_references--);
14082 drm_gem_object_unreference(&intel_fb->obj->base);
14083 mutex_unlock(&dev->struct_mutex);
14087 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
14088 struct drm_file *file,
14089 unsigned int *handle)
14091 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14092 struct drm_i915_gem_object *obj = intel_fb->obj;
14094 return drm_gem_handle_create(file, &obj->base, handle);
14097 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14098 struct drm_file *file,
14099 unsigned flags, unsigned color,
14100 struct drm_clip_rect *clips,
14101 unsigned num_clips)
14103 struct drm_device *dev = fb->dev;
14104 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14105 struct drm_i915_gem_object *obj = intel_fb->obj;
14107 mutex_lock(&dev->struct_mutex);
14108 intel_fb_obj_flush(obj, false, ORIGIN_DIRTYFB);
14109 mutex_unlock(&dev->struct_mutex);
14114 static const struct drm_framebuffer_funcs intel_fb_funcs = {
14115 .destroy = intel_user_framebuffer_destroy,
14116 .create_handle = intel_user_framebuffer_create_handle,
14117 .dirty = intel_user_framebuffer_dirty,
14121 u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier,
14122 uint32_t pixel_format)
14124 u32 gen = INTEL_INFO(dev)->gen;
14127 /* "The stride in bytes must not exceed the of the size of 8K
14128 * pixels and 32K bytes."
14130 return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768);
14131 } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) {
14133 } else if (gen >= 4) {
14134 if (fb_modifier == I915_FORMAT_MOD_X_TILED)
14138 } else if (gen >= 3) {
14139 if (fb_modifier == I915_FORMAT_MOD_X_TILED)
14144 /* XXX DSPC is limited to 4k tiled */
14149 static int intel_framebuffer_init(struct drm_device *dev,
14150 struct intel_framebuffer *intel_fb,
14151 struct drm_mode_fb_cmd2 *mode_cmd,
14152 struct drm_i915_gem_object *obj)
14154 unsigned int aligned_height;
14156 u32 pitch_limit, stride_alignment;
14158 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
14160 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
14161 /* Enforce that fb modifier and tiling mode match, but only for
14162 * X-tiled. This is needed for FBC. */
14163 if (!!(obj->tiling_mode == I915_TILING_X) !=
14164 !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) {
14165 DRM_DEBUG("tiling_mode doesn't match fb modifier\n");
14169 if (obj->tiling_mode == I915_TILING_X)
14170 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
14171 else if (obj->tiling_mode == I915_TILING_Y) {
14172 DRM_DEBUG("No Y tiling for legacy addfb\n");
14177 /* Passed in modifier sanity checking. */
14178 switch (mode_cmd->modifier[0]) {
14179 case I915_FORMAT_MOD_Y_TILED:
14180 case I915_FORMAT_MOD_Yf_TILED:
14181 if (INTEL_INFO(dev)->gen < 9) {
14182 DRM_DEBUG("Unsupported tiling 0x%llx!\n",
14183 mode_cmd->modifier[0]);
14186 case DRM_FORMAT_MOD_NONE:
14187 case I915_FORMAT_MOD_X_TILED:
14190 DRM_DEBUG("Unsupported fb modifier 0x%llx!\n",
14191 mode_cmd->modifier[0]);
14195 stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0],
14196 mode_cmd->pixel_format);
14197 if (mode_cmd->pitches[0] & (stride_alignment - 1)) {
14198 DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n",
14199 mode_cmd->pitches[0], stride_alignment);
14203 pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0],
14204 mode_cmd->pixel_format);
14205 if (mode_cmd->pitches[0] > pitch_limit) {
14206 DRM_DEBUG("%s pitch (%u) must be at less than %d\n",
14207 mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ?
14208 "tiled" : "linear",
14209 mode_cmd->pitches[0], pitch_limit);
14213 if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED &&
14214 mode_cmd->pitches[0] != obj->stride) {
14215 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
14216 mode_cmd->pitches[0], obj->stride);
14220 /* Reject formats not supported by any plane early. */
14221 switch (mode_cmd->pixel_format) {
14222 case DRM_FORMAT_C8:
14223 case DRM_FORMAT_RGB565:
14224 case DRM_FORMAT_XRGB8888:
14225 case DRM_FORMAT_ARGB8888:
14227 case DRM_FORMAT_XRGB1555:
14228 if (INTEL_INFO(dev)->gen > 3) {
14229 DRM_DEBUG("unsupported pixel format: %s\n",
14230 drm_get_format_name(mode_cmd->pixel_format));
14234 case DRM_FORMAT_ABGR8888:
14235 if (!IS_VALLEYVIEW(dev) && INTEL_INFO(dev)->gen < 9) {
14236 DRM_DEBUG("unsupported pixel format: %s\n",
14237 drm_get_format_name(mode_cmd->pixel_format));
14241 case DRM_FORMAT_XBGR8888:
14242 case DRM_FORMAT_XRGB2101010:
14243 case DRM_FORMAT_XBGR2101010:
14244 if (INTEL_INFO(dev)->gen < 4) {
14245 DRM_DEBUG("unsupported pixel format: %s\n",
14246 drm_get_format_name(mode_cmd->pixel_format));
14250 case DRM_FORMAT_ABGR2101010:
14251 if (!IS_VALLEYVIEW(dev)) {
14252 DRM_DEBUG("unsupported pixel format: %s\n",
14253 drm_get_format_name(mode_cmd->pixel_format));
14257 case DRM_FORMAT_YUYV:
14258 case DRM_FORMAT_UYVY:
14259 case DRM_FORMAT_YVYU:
14260 case DRM_FORMAT_VYUY:
14261 if (INTEL_INFO(dev)->gen < 5) {
14262 DRM_DEBUG("unsupported pixel format: %s\n",
14263 drm_get_format_name(mode_cmd->pixel_format));
14268 DRM_DEBUG("unsupported pixel format: %s\n",
14269 drm_get_format_name(mode_cmd->pixel_format));
14273 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14274 if (mode_cmd->offsets[0] != 0)
14277 aligned_height = intel_fb_align_height(dev, mode_cmd->height,
14278 mode_cmd->pixel_format,
14279 mode_cmd->modifier[0]);
14280 /* FIXME drm helper for size checks (especially planar formats)? */
14281 if (obj->base.size < aligned_height * mode_cmd->pitches[0])
14284 drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
14285 intel_fb->obj = obj;
14286 intel_fb->obj->framebuffer_references++;
14288 ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
14290 DRM_ERROR("framebuffer init failed %d\n", ret);
14297 static struct drm_framebuffer *
14298 intel_user_framebuffer_create(struct drm_device *dev,
14299 struct drm_file *filp,
14300 struct drm_mode_fb_cmd2 *mode_cmd)
14302 struct drm_i915_gem_object *obj;
14304 obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
14305 mode_cmd->handles[0]));
14306 if (&obj->base == NULL)
14307 return ERR_PTR(-ENOENT);
14309 return intel_framebuffer_create(dev, mode_cmd, obj);
14312 #ifndef CONFIG_DRM_FBDEV_EMULATION
14313 static inline void intel_fbdev_output_poll_changed(struct drm_device *dev)
14318 static const struct drm_mode_config_funcs intel_mode_funcs = {
14319 .fb_create = intel_user_framebuffer_create,
14320 .output_poll_changed = intel_fbdev_output_poll_changed,
14321 .atomic_check = intel_atomic_check,
14322 .atomic_commit = intel_atomic_commit,
14323 .atomic_state_alloc = intel_atomic_state_alloc,
14324 .atomic_state_clear = intel_atomic_state_clear,
14327 /* Set up chip specific display functions */
14328 static void intel_init_display(struct drm_device *dev)
14330 struct drm_i915_private *dev_priv = dev->dev_private;
14332 if (HAS_PCH_SPLIT(dev) || IS_G4X(dev))
14333 dev_priv->display.find_dpll = g4x_find_best_dpll;
14334 else if (IS_CHERRYVIEW(dev))
14335 dev_priv->display.find_dpll = chv_find_best_dpll;
14336 else if (IS_VALLEYVIEW(dev))
14337 dev_priv->display.find_dpll = vlv_find_best_dpll;
14338 else if (IS_PINEVIEW(dev))
14339 dev_priv->display.find_dpll = pnv_find_best_dpll;
14341 dev_priv->display.find_dpll = i9xx_find_best_dpll;
14343 if (INTEL_INFO(dev)->gen >= 9) {
14344 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14345 dev_priv->display.get_initial_plane_config =
14346 skylake_get_initial_plane_config;
14347 dev_priv->display.crtc_compute_clock =
14348 haswell_crtc_compute_clock;
14349 dev_priv->display.crtc_enable = haswell_crtc_enable;
14350 dev_priv->display.crtc_disable = haswell_crtc_disable;
14351 dev_priv->display.update_primary_plane =
14352 skylake_update_primary_plane;
14353 } else if (HAS_DDI(dev)) {
14354 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14355 dev_priv->display.get_initial_plane_config =
14356 ironlake_get_initial_plane_config;
14357 dev_priv->display.crtc_compute_clock =
14358 haswell_crtc_compute_clock;
14359 dev_priv->display.crtc_enable = haswell_crtc_enable;
14360 dev_priv->display.crtc_disable = haswell_crtc_disable;
14361 dev_priv->display.update_primary_plane =
14362 ironlake_update_primary_plane;
14363 } else if (HAS_PCH_SPLIT(dev)) {
14364 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
14365 dev_priv->display.get_initial_plane_config =
14366 ironlake_get_initial_plane_config;
14367 dev_priv->display.crtc_compute_clock =
14368 ironlake_crtc_compute_clock;
14369 dev_priv->display.crtc_enable = ironlake_crtc_enable;
14370 dev_priv->display.crtc_disable = ironlake_crtc_disable;
14371 dev_priv->display.update_primary_plane =
14372 ironlake_update_primary_plane;
14373 } else if (IS_VALLEYVIEW(dev)) {
14374 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14375 dev_priv->display.get_initial_plane_config =
14376 i9xx_get_initial_plane_config;
14377 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
14378 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14379 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14380 dev_priv->display.update_primary_plane =
14381 i9xx_update_primary_plane;
14383 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14384 dev_priv->display.get_initial_plane_config =
14385 i9xx_get_initial_plane_config;
14386 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
14387 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14388 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14389 dev_priv->display.update_primary_plane =
14390 i9xx_update_primary_plane;
14393 /* Returns the core display clock speed */
14394 if (IS_SKYLAKE(dev))
14395 dev_priv->display.get_display_clock_speed =
14396 skylake_get_display_clock_speed;
14397 else if (IS_BROXTON(dev))
14398 dev_priv->display.get_display_clock_speed =
14399 broxton_get_display_clock_speed;
14400 else if (IS_BROADWELL(dev))
14401 dev_priv->display.get_display_clock_speed =
14402 broadwell_get_display_clock_speed;
14403 else if (IS_HASWELL(dev))
14404 dev_priv->display.get_display_clock_speed =
14405 haswell_get_display_clock_speed;
14406 else if (IS_VALLEYVIEW(dev))
14407 dev_priv->display.get_display_clock_speed =
14408 valleyview_get_display_clock_speed;
14409 else if (IS_GEN5(dev))
14410 dev_priv->display.get_display_clock_speed =
14411 ilk_get_display_clock_speed;
14412 else if (IS_I945G(dev) || IS_BROADWATER(dev) ||
14413 IS_GEN6(dev) || IS_IVYBRIDGE(dev))
14414 dev_priv->display.get_display_clock_speed =
14415 i945_get_display_clock_speed;
14416 else if (IS_GM45(dev))
14417 dev_priv->display.get_display_clock_speed =
14418 gm45_get_display_clock_speed;
14419 else if (IS_CRESTLINE(dev))
14420 dev_priv->display.get_display_clock_speed =
14421 i965gm_get_display_clock_speed;
14422 else if (IS_PINEVIEW(dev))
14423 dev_priv->display.get_display_clock_speed =
14424 pnv_get_display_clock_speed;
14425 else if (IS_G33(dev) || IS_G4X(dev))
14426 dev_priv->display.get_display_clock_speed =
14427 g33_get_display_clock_speed;
14428 else if (IS_I915G(dev))
14429 dev_priv->display.get_display_clock_speed =
14430 i915_get_display_clock_speed;
14431 else if (IS_I945GM(dev) || IS_845G(dev))
14432 dev_priv->display.get_display_clock_speed =
14433 i9xx_misc_get_display_clock_speed;
14434 else if (IS_PINEVIEW(dev))
14435 dev_priv->display.get_display_clock_speed =
14436 pnv_get_display_clock_speed;
14437 else if (IS_I915GM(dev))
14438 dev_priv->display.get_display_clock_speed =
14439 i915gm_get_display_clock_speed;
14440 else if (IS_I865G(dev))
14441 dev_priv->display.get_display_clock_speed =
14442 i865_get_display_clock_speed;
14443 else if (IS_I85X(dev))
14444 dev_priv->display.get_display_clock_speed =
14445 i85x_get_display_clock_speed;
14447 WARN(!IS_I830(dev), "Unknown platform. Assuming 133 MHz CDCLK\n");
14448 dev_priv->display.get_display_clock_speed =
14449 i830_get_display_clock_speed;
14452 if (IS_GEN5(dev)) {
14453 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
14454 } else if (IS_GEN6(dev)) {
14455 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
14456 } else if (IS_IVYBRIDGE(dev)) {
14457 /* FIXME: detect B0+ stepping and use auto training */
14458 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
14459 } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
14460 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
14461 if (IS_BROADWELL(dev)) {
14462 dev_priv->display.modeset_commit_cdclk =
14463 broadwell_modeset_commit_cdclk;
14464 dev_priv->display.modeset_calc_cdclk =
14465 broadwell_modeset_calc_cdclk;
14467 } else if (IS_VALLEYVIEW(dev)) {
14468 dev_priv->display.modeset_commit_cdclk =
14469 valleyview_modeset_commit_cdclk;
14470 dev_priv->display.modeset_calc_cdclk =
14471 valleyview_modeset_calc_cdclk;
14472 } else if (IS_BROXTON(dev)) {
14473 dev_priv->display.modeset_commit_cdclk =
14474 broxton_modeset_commit_cdclk;
14475 dev_priv->display.modeset_calc_cdclk =
14476 broxton_modeset_calc_cdclk;
14479 switch (INTEL_INFO(dev)->gen) {
14481 dev_priv->display.queue_flip = intel_gen2_queue_flip;
14485 dev_priv->display.queue_flip = intel_gen3_queue_flip;
14490 dev_priv->display.queue_flip = intel_gen4_queue_flip;
14494 dev_priv->display.queue_flip = intel_gen6_queue_flip;
14497 case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
14498 dev_priv->display.queue_flip = intel_gen7_queue_flip;
14501 /* Drop through - unsupported since execlist only. */
14503 /* Default just returns -ENODEV to indicate unsupported */
14504 dev_priv->display.queue_flip = intel_default_queue_flip;
14507 intel_panel_init_backlight_funcs(dev);
14509 mutex_init(&dev_priv->pps_mutex);
14513 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
14514 * resume, or other times. This quirk makes sure that's the case for
14515 * affected systems.
14517 static void quirk_pipea_force(struct drm_device *dev)
14519 struct drm_i915_private *dev_priv = dev->dev_private;
14521 dev_priv->quirks |= QUIRK_PIPEA_FORCE;
14522 DRM_INFO("applying pipe a force quirk\n");
14525 static void quirk_pipeb_force(struct drm_device *dev)
14527 struct drm_i915_private *dev_priv = dev->dev_private;
14529 dev_priv->quirks |= QUIRK_PIPEB_FORCE;
14530 DRM_INFO("applying pipe b force quirk\n");
14534 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
14536 static void quirk_ssc_force_disable(struct drm_device *dev)
14538 struct drm_i915_private *dev_priv = dev->dev_private;
14539 dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
14540 DRM_INFO("applying lvds SSC disable quirk\n");
14544 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
14547 static void quirk_invert_brightness(struct drm_device *dev)
14549 struct drm_i915_private *dev_priv = dev->dev_private;
14550 dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
14551 DRM_INFO("applying inverted panel brightness quirk\n");
14554 /* Some VBT's incorrectly indicate no backlight is present */
14555 static void quirk_backlight_present(struct drm_device *dev)
14557 struct drm_i915_private *dev_priv = dev->dev_private;
14558 dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT;
14559 DRM_INFO("applying backlight present quirk\n");
14562 struct intel_quirk {
14564 int subsystem_vendor;
14565 int subsystem_device;
14566 void (*hook)(struct drm_device *dev);
14569 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
14570 struct intel_dmi_quirk {
14571 void (*hook)(struct drm_device *dev);
14572 const struct dmi_system_id (*dmi_id_list)[];
14575 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
14577 DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
14581 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
14583 .dmi_id_list = &(const struct dmi_system_id[]) {
14585 .callback = intel_dmi_reverse_brightness,
14586 .ident = "NCR Corporation",
14587 .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
14588 DMI_MATCH(DMI_PRODUCT_NAME, ""),
14591 { } /* terminating entry */
14593 .hook = quirk_invert_brightness,
14597 static struct intel_quirk intel_quirks[] = {
14598 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
14599 { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
14601 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
14602 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
14604 /* 830 needs to leave pipe A & dpll A up */
14605 { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
14607 /* 830 needs to leave pipe B & dpll B up */
14608 { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force },
14610 /* Lenovo U160 cannot use SSC on LVDS */
14611 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
14613 /* Sony Vaio Y cannot use SSC on LVDS */
14614 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
14616 /* Acer Aspire 5734Z must invert backlight brightness */
14617 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
14619 /* Acer/eMachines G725 */
14620 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
14622 /* Acer/eMachines e725 */
14623 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
14625 /* Acer/Packard Bell NCL20 */
14626 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
14628 /* Acer Aspire 4736Z */
14629 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
14631 /* Acer Aspire 5336 */
14632 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
14634 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
14635 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
14637 /* Acer C720 Chromebook (Core i3 4005U) */
14638 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
14640 /* Apple Macbook 2,1 (Core 2 T7400) */
14641 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present },
14643 /* Toshiba CB35 Chromebook (Celeron 2955U) */
14644 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
14646 /* HP Chromebook 14 (Celeron 2955U) */
14647 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
14649 /* Dell Chromebook 11 */
14650 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present },
14653 static void intel_init_quirks(struct drm_device *dev)
14655 struct pci_dev *d = dev->pdev;
14658 for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
14659 struct intel_quirk *q = &intel_quirks[i];
14661 if (d->device == q->device &&
14662 (d->subsystem_vendor == q->subsystem_vendor ||
14663 q->subsystem_vendor == PCI_ANY_ID) &&
14664 (d->subsystem_device == q->subsystem_device ||
14665 q->subsystem_device == PCI_ANY_ID))
14668 for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
14669 if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
14670 intel_dmi_quirks[i].hook(dev);
14674 /* Disable the VGA plane that we never use */
14675 static void i915_disable_vga(struct drm_device *dev)
14677 struct drm_i915_private *dev_priv = dev->dev_private;
14679 u32 vga_reg = i915_vgacntrl_reg(dev);
14681 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
14682 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
14683 outb(SR01, VGA_SR_INDEX);
14684 sr1 = inb(VGA_SR_DATA);
14685 outb(sr1 | 1<<5, VGA_SR_DATA);
14686 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
14689 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
14690 POSTING_READ(vga_reg);
14693 void intel_modeset_init_hw(struct drm_device *dev)
14695 intel_update_cdclk(dev);
14696 intel_prepare_ddi(dev);
14697 intel_init_clock_gating(dev);
14698 intel_enable_gt_powersave(dev);
14701 void intel_modeset_init(struct drm_device *dev)
14703 struct drm_i915_private *dev_priv = dev->dev_private;
14706 struct intel_crtc *crtc;
14708 drm_mode_config_init(dev);
14710 dev->mode_config.min_width = 0;
14711 dev->mode_config.min_height = 0;
14713 dev->mode_config.preferred_depth = 24;
14714 dev->mode_config.prefer_shadow = 1;
14716 dev->mode_config.allow_fb_modifiers = true;
14718 dev->mode_config.funcs = &intel_mode_funcs;
14720 intel_init_quirks(dev);
14722 intel_init_pm(dev);
14724 if (INTEL_INFO(dev)->num_pipes == 0)
14728 * There may be no VBT; and if the BIOS enabled SSC we can
14729 * just keep using it to avoid unnecessary flicker. Whereas if the
14730 * BIOS isn't using it, don't assume it will work even if the VBT
14731 * indicates as much.
14733 if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
14734 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
14737 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
14738 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
14739 bios_lvds_use_ssc ? "en" : "dis",
14740 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
14741 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
14745 intel_init_display(dev);
14746 intel_init_audio(dev);
14748 if (IS_GEN2(dev)) {
14749 dev->mode_config.max_width = 2048;
14750 dev->mode_config.max_height = 2048;
14751 } else if (IS_GEN3(dev)) {
14752 dev->mode_config.max_width = 4096;
14753 dev->mode_config.max_height = 4096;
14755 dev->mode_config.max_width = 8192;
14756 dev->mode_config.max_height = 8192;
14759 if (IS_845G(dev) || IS_I865G(dev)) {
14760 dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512;
14761 dev->mode_config.cursor_height = 1023;
14762 } else if (IS_GEN2(dev)) {
14763 dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
14764 dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
14766 dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
14767 dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
14770 dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
14772 DRM_DEBUG_KMS("%d display pipe%s available.\n",
14773 INTEL_INFO(dev)->num_pipes,
14774 INTEL_INFO(dev)->num_pipes > 1 ? "s" : "");
14776 for_each_pipe(dev_priv, pipe) {
14777 intel_crtc_init(dev, pipe);
14778 for_each_sprite(dev_priv, pipe, sprite) {
14779 ret = intel_plane_init(dev, pipe, sprite);
14781 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
14782 pipe_name(pipe), sprite_name(pipe, sprite), ret);
14786 intel_shared_dpll_init(dev);
14788 /* Just disable it once at startup */
14789 i915_disable_vga(dev);
14790 intel_setup_outputs(dev);
14792 /* Just in case the BIOS is doing something questionable. */
14793 intel_fbc_disable(dev_priv);
14795 drm_modeset_lock_all(dev);
14796 intel_modeset_setup_hw_state(dev);
14797 drm_modeset_unlock_all(dev);
14799 for_each_intel_crtc(dev, crtc) {
14800 struct intel_initial_plane_config plane_config = {};
14806 * Note that reserving the BIOS fb up front prevents us
14807 * from stuffing other stolen allocations like the ring
14808 * on top. This prevents some ugliness at boot time, and
14809 * can even allow for smooth boot transitions if the BIOS
14810 * fb is large enough for the active pipe configuration.
14812 dev_priv->display.get_initial_plane_config(crtc,
14816 * If the fb is shared between multiple heads, we'll
14817 * just get the first one.
14819 intel_find_initial_plane_obj(crtc, &plane_config);
14823 static void intel_enable_pipe_a(struct drm_device *dev)
14825 struct intel_connector *connector;
14826 struct drm_connector *crt = NULL;
14827 struct intel_load_detect_pipe load_detect_temp;
14828 struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx;
14830 /* We can't just switch on the pipe A, we need to set things up with a
14831 * proper mode and output configuration. As a gross hack, enable pipe A
14832 * by enabling the load detect pipe once. */
14833 for_each_intel_connector(dev, connector) {
14834 if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
14835 crt = &connector->base;
14843 if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx))
14844 intel_release_load_detect_pipe(crt, &load_detect_temp, ctx);
14848 intel_check_plane_mapping(struct intel_crtc *crtc)
14850 struct drm_device *dev = crtc->base.dev;
14851 struct drm_i915_private *dev_priv = dev->dev_private;
14854 if (INTEL_INFO(dev)->num_pipes == 1)
14857 reg = DSPCNTR(!crtc->plane);
14858 val = I915_READ(reg);
14860 if ((val & DISPLAY_PLANE_ENABLE) &&
14861 (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
14867 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
14869 struct drm_device *dev = crtc->base.dev;
14870 struct intel_encoder *encoder;
14872 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
14878 static void intel_sanitize_crtc(struct intel_crtc *crtc)
14880 struct drm_device *dev = crtc->base.dev;
14881 struct drm_i915_private *dev_priv = dev->dev_private;
14884 /* Clear any frame start delays used for debugging left by the BIOS */
14885 reg = PIPECONF(crtc->config->cpu_transcoder);
14886 I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
14888 /* restore vblank interrupts to correct state */
14889 drm_crtc_vblank_reset(&crtc->base);
14890 if (crtc->active) {
14891 drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode);
14892 update_scanline_offset(crtc);
14893 drm_crtc_vblank_on(&crtc->base);
14896 /* We need to sanitize the plane -> pipe mapping first because this will
14897 * disable the crtc (and hence change the state) if it is wrong. Note
14898 * that gen4+ has a fixed plane -> pipe mapping. */
14899 if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
14902 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
14903 crtc->base.base.id);
14905 /* Pipe has the wrong plane attached and the plane is active.
14906 * Temporarily change the plane mapping and disable everything
14908 plane = crtc->plane;
14909 to_intel_plane_state(crtc->base.primary->state)->visible = true;
14910 crtc->plane = !plane;
14911 intel_crtc_disable_noatomic(&crtc->base);
14912 crtc->plane = plane;
14915 if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
14916 crtc->pipe == PIPE_A && !crtc->active) {
14917 /* BIOS forgot to enable pipe A, this mostly happens after
14918 * resume. Force-enable the pipe to fix this, the update_dpms
14919 * call below we restore the pipe to the right state, but leave
14920 * the required bits on. */
14921 intel_enable_pipe_a(dev);
14924 /* Adjust the state of the output pipe according to whether we
14925 * have active connectors/encoders. */
14926 if (!intel_crtc_has_encoders(crtc))
14927 intel_crtc_disable_noatomic(&crtc->base);
14929 if (crtc->active != crtc->base.state->active) {
14930 struct intel_encoder *encoder;
14932 /* This can happen either due to bugs in the get_hw_state
14933 * functions or because of calls to intel_crtc_disable_noatomic,
14934 * or because the pipe is force-enabled due to the
14936 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
14937 crtc->base.base.id,
14938 crtc->base.state->enable ? "enabled" : "disabled",
14939 crtc->active ? "enabled" : "disabled");
14941 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, NULL) < 0);
14942 crtc->base.state->active = crtc->active;
14943 crtc->base.enabled = crtc->active;
14945 /* Because we only establish the connector -> encoder ->
14946 * crtc links if something is active, this means the
14947 * crtc is now deactivated. Break the links. connector
14948 * -> encoder links are only establish when things are
14949 * actually up, hence no need to break them. */
14950 WARN_ON(crtc->active);
14952 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
14953 encoder->base.crtc = NULL;
14956 if (crtc->active || HAS_GMCH_DISPLAY(dev)) {
14958 * We start out with underrun reporting disabled to avoid races.
14959 * For correct bookkeeping mark this on active crtcs.
14961 * Also on gmch platforms we dont have any hardware bits to
14962 * disable the underrun reporting. Which means we need to start
14963 * out with underrun reporting disabled also on inactive pipes,
14964 * since otherwise we'll complain about the garbage we read when
14965 * e.g. coming up after runtime pm.
14967 * No protection against concurrent access is required - at
14968 * worst a fifo underrun happens which also sets this to false.
14970 crtc->cpu_fifo_underrun_disabled = true;
14971 crtc->pch_fifo_underrun_disabled = true;
14975 static void intel_sanitize_encoder(struct intel_encoder *encoder)
14977 struct intel_connector *connector;
14978 struct drm_device *dev = encoder->base.dev;
14979 bool active = false;
14981 /* We need to check both for a crtc link (meaning that the
14982 * encoder is active and trying to read from a pipe) and the
14983 * pipe itself being active. */
14984 bool has_active_crtc = encoder->base.crtc &&
14985 to_intel_crtc(encoder->base.crtc)->active;
14987 for_each_intel_connector(dev, connector) {
14988 if (connector->base.encoder != &encoder->base)
14995 if (active && !has_active_crtc) {
14996 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
14997 encoder->base.base.id,
14998 encoder->base.name);
15000 /* Connector is active, but has no active pipe. This is
15001 * fallout from our resume register restoring. Disable
15002 * the encoder manually again. */
15003 if (encoder->base.crtc) {
15004 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15005 encoder->base.base.id,
15006 encoder->base.name);
15007 encoder->disable(encoder);
15008 if (encoder->post_disable)
15009 encoder->post_disable(encoder);
15011 encoder->base.crtc = NULL;
15013 /* Inconsistent output/port/pipe state happens presumably due to
15014 * a bug in one of the get_hw_state functions. Or someplace else
15015 * in our code, like the register restore mess on resume. Clamp
15016 * things to off as a safer default. */
15017 for_each_intel_connector(dev, connector) {
15018 if (connector->encoder != encoder)
15020 connector->base.dpms = DRM_MODE_DPMS_OFF;
15021 connector->base.encoder = NULL;
15024 /* Enabled encoders without active connectors will be fixed in
15025 * the crtc fixup. */
15028 void i915_redisable_vga_power_on(struct drm_device *dev)
15030 struct drm_i915_private *dev_priv = dev->dev_private;
15031 u32 vga_reg = i915_vgacntrl_reg(dev);
15033 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15034 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
15035 i915_disable_vga(dev);
15039 void i915_redisable_vga(struct drm_device *dev)
15041 struct drm_i915_private *dev_priv = dev->dev_private;
15043 /* This function can be called both from intel_modeset_setup_hw_state or
15044 * at a very early point in our resume sequence, where the power well
15045 * structures are not yet restored. Since this function is at a very
15046 * paranoid "someone might have enabled VGA while we were not looking"
15047 * level, just check if the power well is enabled instead of trying to
15048 * follow the "don't touch the power well if we don't need it" policy
15049 * the rest of the driver uses. */
15050 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA))
15053 i915_redisable_vga_power_on(dev);
15056 static bool primary_get_hw_state(struct intel_crtc *crtc)
15058 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
15060 return !!(I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE);
15063 static void readout_plane_state(struct intel_crtc *crtc,
15064 struct intel_crtc_state *crtc_state)
15066 struct intel_plane *p;
15067 struct intel_plane_state *plane_state;
15068 bool active = crtc_state->base.active;
15070 for_each_intel_plane(crtc->base.dev, p) {
15071 if (crtc->pipe != p->pipe)
15074 plane_state = to_intel_plane_state(p->base.state);
15076 if (p->base.type == DRM_PLANE_TYPE_PRIMARY)
15077 plane_state->visible = primary_get_hw_state(crtc);
15080 p->disable_plane(&p->base, &crtc->base);
15082 plane_state->visible = false;
15087 static void intel_modeset_readout_hw_state(struct drm_device *dev)
15089 struct drm_i915_private *dev_priv = dev->dev_private;
15091 struct intel_crtc *crtc;
15092 struct intel_encoder *encoder;
15093 struct intel_connector *connector;
15096 for_each_intel_crtc(dev, crtc) {
15097 __drm_atomic_helper_crtc_destroy_state(&crtc->base, crtc->base.state);
15098 memset(crtc->config, 0, sizeof(*crtc->config));
15099 crtc->config->base.crtc = &crtc->base;
15101 crtc->active = dev_priv->display.get_pipe_config(crtc,
15104 crtc->base.state->active = crtc->active;
15105 crtc->base.enabled = crtc->active;
15107 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
15108 if (crtc->base.state->active) {
15109 intel_mode_from_pipe_config(&crtc->base.mode, crtc->config);
15110 intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config);
15111 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
15114 * The initial mode needs to be set in order to keep
15115 * the atomic core happy. It wants a valid mode if the
15116 * crtc's enabled, so we do the above call.
15118 * At this point some state updated by the connectors
15119 * in their ->detect() callback has not run yet, so
15120 * no recalculation can be done yet.
15122 * Even if we could do a recalculation and modeset
15123 * right now it would cause a double modeset if
15124 * fbdev or userspace chooses a different initial mode.
15126 * If that happens, someone indicated they wanted a
15127 * mode change, which means it's safe to do a full
15130 crtc->base.state->mode.private_flags = I915_MODE_FLAG_INHERITED;
15133 crtc->base.hwmode = crtc->config->base.adjusted_mode;
15134 readout_plane_state(crtc, to_intel_crtc_state(crtc->base.state));
15136 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
15137 crtc->base.base.id,
15138 crtc->active ? "enabled" : "disabled");
15141 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15142 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15144 pll->on = pll->get_hw_state(dev_priv, pll,
15145 &pll->config.hw_state);
15147 pll->config.crtc_mask = 0;
15148 for_each_intel_crtc(dev, crtc) {
15149 if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) {
15151 pll->config.crtc_mask |= 1 << crtc->pipe;
15155 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15156 pll->name, pll->config.crtc_mask, pll->on);
15158 if (pll->config.crtc_mask)
15159 intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
15162 for_each_intel_encoder(dev, encoder) {
15165 if (encoder->get_hw_state(encoder, &pipe)) {
15166 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
15167 encoder->base.crtc = &crtc->base;
15168 encoder->get_config(encoder, crtc->config);
15170 encoder->base.crtc = NULL;
15173 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15174 encoder->base.base.id,
15175 encoder->base.name,
15176 encoder->base.crtc ? "enabled" : "disabled",
15180 for_each_intel_connector(dev, connector) {
15181 if (connector->get_hw_state(connector)) {
15182 connector->base.dpms = DRM_MODE_DPMS_ON;
15183 connector->base.encoder = &connector->encoder->base;
15185 connector->base.dpms = DRM_MODE_DPMS_OFF;
15186 connector->base.encoder = NULL;
15188 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
15189 connector->base.base.id,
15190 connector->base.name,
15191 connector->base.encoder ? "enabled" : "disabled");
15195 /* Scan out the current hw modeset state,
15196 * and sanitizes it to the current state
15199 intel_modeset_setup_hw_state(struct drm_device *dev)
15201 struct drm_i915_private *dev_priv = dev->dev_private;
15203 struct intel_crtc *crtc;
15204 struct intel_encoder *encoder;
15207 intel_modeset_readout_hw_state(dev);
15209 /* HW state is read out, now we need to sanitize this mess. */
15210 for_each_intel_encoder(dev, encoder) {
15211 intel_sanitize_encoder(encoder);
15214 for_each_pipe(dev_priv, pipe) {
15215 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
15216 intel_sanitize_crtc(crtc);
15217 intel_dump_pipe_config(crtc, crtc->config,
15218 "[setup_hw_state]");
15221 intel_modeset_update_connector_atomic_state(dev);
15223 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15224 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15226 if (!pll->on || pll->active)
15229 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name);
15231 pll->disable(dev_priv, pll);
15235 if (IS_VALLEYVIEW(dev))
15236 vlv_wm_get_hw_state(dev);
15237 else if (IS_GEN9(dev))
15238 skl_wm_get_hw_state(dev);
15239 else if (HAS_PCH_SPLIT(dev))
15240 ilk_wm_get_hw_state(dev);
15242 for_each_intel_crtc(dev, crtc) {
15243 unsigned long put_domains;
15245 put_domains = modeset_get_crtc_power_domains(&crtc->base);
15246 if (WARN_ON(put_domains))
15247 modeset_put_power_domains(dev_priv, put_domains);
15249 intel_display_set_init_power(dev_priv, false);
15252 void intel_display_resume(struct drm_device *dev)
15254 struct drm_atomic_state *state = drm_atomic_state_alloc(dev);
15255 struct intel_connector *conn;
15256 struct intel_plane *plane;
15257 struct drm_crtc *crtc;
15263 state->acquire_ctx = dev->mode_config.acquire_ctx;
15265 /* preserve complete old state, including dpll */
15266 intel_atomic_get_shared_dpll_state(state);
15268 for_each_crtc(dev, crtc) {
15269 struct drm_crtc_state *crtc_state =
15270 drm_atomic_get_crtc_state(state, crtc);
15272 ret = PTR_ERR_OR_ZERO(crtc_state);
15276 /* force a restore */
15277 crtc_state->mode_changed = true;
15280 for_each_intel_plane(dev, plane) {
15281 ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(state, &plane->base));
15286 for_each_intel_connector(dev, conn) {
15287 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(state, &conn->base));
15292 intel_modeset_setup_hw_state(dev);
15294 i915_redisable_vga(dev);
15295 ret = drm_atomic_commit(state);
15300 DRM_ERROR("Restoring old state failed with %i\n", ret);
15301 drm_atomic_state_free(state);
15304 void intel_modeset_gem_init(struct drm_device *dev)
15306 struct drm_crtc *c;
15307 struct drm_i915_gem_object *obj;
15310 mutex_lock(&dev->struct_mutex);
15311 intel_init_gt_powersave(dev);
15312 mutex_unlock(&dev->struct_mutex);
15314 intel_modeset_init_hw(dev);
15316 intel_setup_overlay(dev);
15319 * Make sure any fbs we allocated at startup are properly
15320 * pinned & fenced. When we do the allocation it's too early
15323 for_each_crtc(dev, c) {
15324 obj = intel_fb_obj(c->primary->fb);
15328 mutex_lock(&dev->struct_mutex);
15329 ret = intel_pin_and_fence_fb_obj(c->primary,
15333 mutex_unlock(&dev->struct_mutex);
15335 DRM_ERROR("failed to pin boot fb on pipe %d\n",
15336 to_intel_crtc(c)->pipe);
15337 drm_framebuffer_unreference(c->primary->fb);
15338 c->primary->fb = NULL;
15339 c->primary->crtc = c->primary->state->crtc = NULL;
15340 update_state_fb(c->primary);
15341 c->state->plane_mask &= ~(1 << drm_plane_index(c->primary));
15345 intel_backlight_register(dev);
15348 void intel_connector_unregister(struct intel_connector *intel_connector)
15350 struct drm_connector *connector = &intel_connector->base;
15352 intel_panel_destroy_backlight(connector);
15353 drm_connector_unregister(connector);
15356 void intel_modeset_cleanup(struct drm_device *dev)
15358 struct drm_i915_private *dev_priv = dev->dev_private;
15359 struct drm_connector *connector;
15361 intel_disable_gt_powersave(dev);
15363 intel_backlight_unregister(dev);
15366 * Interrupts and polling as the first thing to avoid creating havoc.
15367 * Too much stuff here (turning of connectors, ...) would
15368 * experience fancy races otherwise.
15370 intel_irq_uninstall(dev_priv);
15373 * Due to the hpd irq storm handling the hotplug work can re-arm the
15374 * poll handlers. Hence disable polling after hpd handling is shut down.
15376 drm_kms_helper_poll_fini(dev);
15378 intel_unregister_dsm_handler();
15380 intel_fbc_disable(dev_priv);
15382 /* flush any delayed tasks or pending work */
15383 flush_scheduled_work();
15385 /* destroy the backlight and sysfs files before encoders/connectors */
15386 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
15387 struct intel_connector *intel_connector;
15389 intel_connector = to_intel_connector(connector);
15390 intel_connector->unregister(intel_connector);
15393 drm_mode_config_cleanup(dev);
15395 intel_cleanup_overlay(dev);
15397 mutex_lock(&dev->struct_mutex);
15398 intel_cleanup_gt_powersave(dev);
15399 mutex_unlock(&dev->struct_mutex);
15403 * Return which encoder is currently attached for connector.
15405 struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
15407 return &intel_attached_encoder(connector)->base;
15410 void intel_connector_attach_encoder(struct intel_connector *connector,
15411 struct intel_encoder *encoder)
15413 connector->encoder = encoder;
15414 drm_mode_connector_attach_encoder(&connector->base,
15419 * set vga decode state - true == enable VGA decode
15421 int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
15423 struct drm_i915_private *dev_priv = dev->dev_private;
15424 unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
15427 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
15428 DRM_ERROR("failed to read control word\n");
15432 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
15436 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
15438 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
15440 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
15441 DRM_ERROR("failed to write control word\n");
15448 struct intel_display_error_state {
15450 u32 power_well_driver;
15452 int num_transcoders;
15454 struct intel_cursor_error_state {
15459 } cursor[I915_MAX_PIPES];
15461 struct intel_pipe_error_state {
15462 bool power_domain_on;
15465 } pipe[I915_MAX_PIPES];
15467 struct intel_plane_error_state {
15475 } plane[I915_MAX_PIPES];
15477 struct intel_transcoder_error_state {
15478 bool power_domain_on;
15479 enum transcoder cpu_transcoder;
15492 struct intel_display_error_state *
15493 intel_display_capture_error_state(struct drm_device *dev)
15495 struct drm_i915_private *dev_priv = dev->dev_private;
15496 struct intel_display_error_state *error;
15497 int transcoders[] = {
15505 if (INTEL_INFO(dev)->num_pipes == 0)
15508 error = kzalloc(sizeof(*error), GFP_ATOMIC);
15512 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
15513 error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER);
15515 for_each_pipe(dev_priv, i) {
15516 error->pipe[i].power_domain_on =
15517 __intel_display_power_is_enabled(dev_priv,
15518 POWER_DOMAIN_PIPE(i));
15519 if (!error->pipe[i].power_domain_on)
15522 error->cursor[i].control = I915_READ(CURCNTR(i));
15523 error->cursor[i].position = I915_READ(CURPOS(i));
15524 error->cursor[i].base = I915_READ(CURBASE(i));
15526 error->plane[i].control = I915_READ(DSPCNTR(i));
15527 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
15528 if (INTEL_INFO(dev)->gen <= 3) {
15529 error->plane[i].size = I915_READ(DSPSIZE(i));
15530 error->plane[i].pos = I915_READ(DSPPOS(i));
15532 if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
15533 error->plane[i].addr = I915_READ(DSPADDR(i));
15534 if (INTEL_INFO(dev)->gen >= 4) {
15535 error->plane[i].surface = I915_READ(DSPSURF(i));
15536 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
15539 error->pipe[i].source = I915_READ(PIPESRC(i));
15541 if (HAS_GMCH_DISPLAY(dev))
15542 error->pipe[i].stat = I915_READ(PIPESTAT(i));
15545 error->num_transcoders = INTEL_INFO(dev)->num_pipes;
15546 if (HAS_DDI(dev_priv->dev))
15547 error->num_transcoders++; /* Account for eDP. */
15549 for (i = 0; i < error->num_transcoders; i++) {
15550 enum transcoder cpu_transcoder = transcoders[i];
15552 error->transcoder[i].power_domain_on =
15553 __intel_display_power_is_enabled(dev_priv,
15554 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
15555 if (!error->transcoder[i].power_domain_on)
15558 error->transcoder[i].cpu_transcoder = cpu_transcoder;
15560 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
15561 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
15562 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
15563 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
15564 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
15565 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
15566 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
15572 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
15575 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
15576 struct drm_device *dev,
15577 struct intel_display_error_state *error)
15579 struct drm_i915_private *dev_priv = dev->dev_private;
15585 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes);
15586 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
15587 err_printf(m, "PWR_WELL_CTL2: %08x\n",
15588 error->power_well_driver);
15589 for_each_pipe(dev_priv, i) {
15590 err_printf(m, "Pipe [%d]:\n", i);
15591 err_printf(m, " Power: %s\n",
15592 error->pipe[i].power_domain_on ? "on" : "off");
15593 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
15594 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
15596 err_printf(m, "Plane [%d]:\n", i);
15597 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
15598 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
15599 if (INTEL_INFO(dev)->gen <= 3) {
15600 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
15601 err_printf(m, " POS: %08x\n", error->plane[i].pos);
15603 if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
15604 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
15605 if (INTEL_INFO(dev)->gen >= 4) {
15606 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
15607 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
15610 err_printf(m, "Cursor [%d]:\n", i);
15611 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
15612 err_printf(m, " POS: %08x\n", error->cursor[i].position);
15613 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
15616 for (i = 0; i < error->num_transcoders; i++) {
15617 err_printf(m, "CPU transcoder: %c\n",
15618 transcoder_name(error->transcoder[i].cpu_transcoder));
15619 err_printf(m, " Power: %s\n",
15620 error->transcoder[i].power_domain_on ? "on" : "off");
15621 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
15622 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
15623 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
15624 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
15625 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
15626 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
15627 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
15631 void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file)
15633 struct intel_crtc *crtc;
15635 for_each_intel_crtc(dev, crtc) {
15636 struct intel_unpin_work *work;
15638 spin_lock_irq(&dev->event_lock);
15640 work = crtc->unpin_work;
15642 if (work && work->event &&
15643 work->event->base.file_priv == file) {
15644 kfree(work->event);
15645 work->event = NULL;
15648 spin_unlock_irq(&dev->event_lock);