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.
27 #include <linux/module.h>
28 #include <linux/input.h>
29 #include <linux/i2c.h>
30 #include <linux/kernel.h>
31 #include <linux/slab.h>
32 #include <linux/vgaarb.h>
33 #include <drm/drm_edid.h>
35 #include "intel_drv.h"
36 #include "intel_frontbuffer.h"
37 #include <drm/i915_drm.h>
39 #include "i915_gem_clflush.h"
40 #include "intel_dsi.h"
41 #include "i915_trace.h"
42 #include <drm/drm_atomic.h>
43 #include <drm/drm_atomic_helper.h>
44 #include <drm/drm_dp_helper.h>
45 #include <drm/drm_crtc_helper.h>
46 #include <drm/drm_plane_helper.h>
47 #include <drm/drm_rect.h>
48 #include <drm/drm_atomic_uapi.h>
49 #include <linux/dma_remapping.h>
50 #include <linux/reservation.h>
52 /* Primary plane formats for gen <= 3 */
53 static const uint32_t i8xx_primary_formats[] = {
60 /* Primary plane formats for gen >= 4 */
61 static const uint32_t i965_primary_formats[] = {
66 DRM_FORMAT_XRGB2101010,
67 DRM_FORMAT_XBGR2101010,
70 static const uint64_t i9xx_format_modifiers[] = {
71 I915_FORMAT_MOD_X_TILED,
72 DRM_FORMAT_MOD_LINEAR,
73 DRM_FORMAT_MOD_INVALID
77 static const uint32_t intel_cursor_formats[] = {
81 static const uint64_t cursor_format_modifiers[] = {
82 DRM_FORMAT_MOD_LINEAR,
83 DRM_FORMAT_MOD_INVALID
86 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
87 struct intel_crtc_state *pipe_config);
88 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
89 struct intel_crtc_state *pipe_config);
91 static int intel_framebuffer_init(struct intel_framebuffer *ifb,
92 struct drm_i915_gem_object *obj,
93 struct drm_mode_fb_cmd2 *mode_cmd);
94 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state);
95 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
96 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
97 const struct intel_link_m_n *m_n,
98 const struct intel_link_m_n *m2_n2);
99 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
100 static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state);
101 static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state);
102 static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state);
103 static void vlv_prepare_pll(struct intel_crtc *crtc,
104 const struct intel_crtc_state *pipe_config);
105 static void chv_prepare_pll(struct intel_crtc *crtc,
106 const struct intel_crtc_state *pipe_config);
107 static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
108 static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
109 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
110 struct intel_crtc_state *crtc_state);
111 static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state);
112 static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state);
113 static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state);
114 static void intel_modeset_setup_hw_state(struct drm_device *dev,
115 struct drm_modeset_acquire_ctx *ctx);
116 static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc);
121 } dot, vco, n, m, m1, m2, p, p1;
125 int p2_slow, p2_fast;
129 /* returns HPLL frequency in kHz */
130 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
132 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
134 /* Obtain SKU information */
135 mutex_lock(&dev_priv->sb_lock);
136 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
137 CCK_FUSE_HPLL_FREQ_MASK;
138 mutex_unlock(&dev_priv->sb_lock);
140 return vco_freq[hpll_freq] * 1000;
143 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
144 const char *name, u32 reg, int ref_freq)
149 mutex_lock(&dev_priv->sb_lock);
150 val = vlv_cck_read(dev_priv, reg);
151 mutex_unlock(&dev_priv->sb_lock);
153 divider = val & CCK_FREQUENCY_VALUES;
155 WARN((val & CCK_FREQUENCY_STATUS) !=
156 (divider << CCK_FREQUENCY_STATUS_SHIFT),
157 "%s change in progress\n", name);
159 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
162 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
163 const char *name, u32 reg)
165 if (dev_priv->hpll_freq == 0)
166 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
168 return vlv_get_cck_clock(dev_priv, name, reg,
169 dev_priv->hpll_freq);
172 static void intel_update_czclk(struct drm_i915_private *dev_priv)
174 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
177 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
178 CCK_CZ_CLOCK_CONTROL);
180 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
183 static inline u32 /* units of 100MHz */
184 intel_fdi_link_freq(struct drm_i915_private *dev_priv,
185 const struct intel_crtc_state *pipe_config)
187 if (HAS_DDI(dev_priv))
188 return pipe_config->port_clock; /* SPLL */
190 return dev_priv->fdi_pll_freq;
193 static const struct intel_limit intel_limits_i8xx_dac = {
194 .dot = { .min = 25000, .max = 350000 },
195 .vco = { .min = 908000, .max = 1512000 },
196 .n = { .min = 2, .max = 16 },
197 .m = { .min = 96, .max = 140 },
198 .m1 = { .min = 18, .max = 26 },
199 .m2 = { .min = 6, .max = 16 },
200 .p = { .min = 4, .max = 128 },
201 .p1 = { .min = 2, .max = 33 },
202 .p2 = { .dot_limit = 165000,
203 .p2_slow = 4, .p2_fast = 2 },
206 static const struct intel_limit intel_limits_i8xx_dvo = {
207 .dot = { .min = 25000, .max = 350000 },
208 .vco = { .min = 908000, .max = 1512000 },
209 .n = { .min = 2, .max = 16 },
210 .m = { .min = 96, .max = 140 },
211 .m1 = { .min = 18, .max = 26 },
212 .m2 = { .min = 6, .max = 16 },
213 .p = { .min = 4, .max = 128 },
214 .p1 = { .min = 2, .max = 33 },
215 .p2 = { .dot_limit = 165000,
216 .p2_slow = 4, .p2_fast = 4 },
219 static const struct intel_limit intel_limits_i8xx_lvds = {
220 .dot = { .min = 25000, .max = 350000 },
221 .vco = { .min = 908000, .max = 1512000 },
222 .n = { .min = 2, .max = 16 },
223 .m = { .min = 96, .max = 140 },
224 .m1 = { .min = 18, .max = 26 },
225 .m2 = { .min = 6, .max = 16 },
226 .p = { .min = 4, .max = 128 },
227 .p1 = { .min = 1, .max = 6 },
228 .p2 = { .dot_limit = 165000,
229 .p2_slow = 14, .p2_fast = 7 },
232 static const struct intel_limit intel_limits_i9xx_sdvo = {
233 .dot = { .min = 20000, .max = 400000 },
234 .vco = { .min = 1400000, .max = 2800000 },
235 .n = { .min = 1, .max = 6 },
236 .m = { .min = 70, .max = 120 },
237 .m1 = { .min = 8, .max = 18 },
238 .m2 = { .min = 3, .max = 7 },
239 .p = { .min = 5, .max = 80 },
240 .p1 = { .min = 1, .max = 8 },
241 .p2 = { .dot_limit = 200000,
242 .p2_slow = 10, .p2_fast = 5 },
245 static const struct intel_limit intel_limits_i9xx_lvds = {
246 .dot = { .min = 20000, .max = 400000 },
247 .vco = { .min = 1400000, .max = 2800000 },
248 .n = { .min = 1, .max = 6 },
249 .m = { .min = 70, .max = 120 },
250 .m1 = { .min = 8, .max = 18 },
251 .m2 = { .min = 3, .max = 7 },
252 .p = { .min = 7, .max = 98 },
253 .p1 = { .min = 1, .max = 8 },
254 .p2 = { .dot_limit = 112000,
255 .p2_slow = 14, .p2_fast = 7 },
259 static const struct intel_limit intel_limits_g4x_sdvo = {
260 .dot = { .min = 25000, .max = 270000 },
261 .vco = { .min = 1750000, .max = 3500000},
262 .n = { .min = 1, .max = 4 },
263 .m = { .min = 104, .max = 138 },
264 .m1 = { .min = 17, .max = 23 },
265 .m2 = { .min = 5, .max = 11 },
266 .p = { .min = 10, .max = 30 },
267 .p1 = { .min = 1, .max = 3},
268 .p2 = { .dot_limit = 270000,
274 static const struct intel_limit intel_limits_g4x_hdmi = {
275 .dot = { .min = 22000, .max = 400000 },
276 .vco = { .min = 1750000, .max = 3500000},
277 .n = { .min = 1, .max = 4 },
278 .m = { .min = 104, .max = 138 },
279 .m1 = { .min = 16, .max = 23 },
280 .m2 = { .min = 5, .max = 11 },
281 .p = { .min = 5, .max = 80 },
282 .p1 = { .min = 1, .max = 8},
283 .p2 = { .dot_limit = 165000,
284 .p2_slow = 10, .p2_fast = 5 },
287 static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
288 .dot = { .min = 20000, .max = 115000 },
289 .vco = { .min = 1750000, .max = 3500000 },
290 .n = { .min = 1, .max = 3 },
291 .m = { .min = 104, .max = 138 },
292 .m1 = { .min = 17, .max = 23 },
293 .m2 = { .min = 5, .max = 11 },
294 .p = { .min = 28, .max = 112 },
295 .p1 = { .min = 2, .max = 8 },
296 .p2 = { .dot_limit = 0,
297 .p2_slow = 14, .p2_fast = 14
301 static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
302 .dot = { .min = 80000, .max = 224000 },
303 .vco = { .min = 1750000, .max = 3500000 },
304 .n = { .min = 1, .max = 3 },
305 .m = { .min = 104, .max = 138 },
306 .m1 = { .min = 17, .max = 23 },
307 .m2 = { .min = 5, .max = 11 },
308 .p = { .min = 14, .max = 42 },
309 .p1 = { .min = 2, .max = 6 },
310 .p2 = { .dot_limit = 0,
311 .p2_slow = 7, .p2_fast = 7
315 static const struct intel_limit intel_limits_pineview_sdvo = {
316 .dot = { .min = 20000, .max = 400000},
317 .vco = { .min = 1700000, .max = 3500000 },
318 /* Pineview's Ncounter is a ring counter */
319 .n = { .min = 3, .max = 6 },
320 .m = { .min = 2, .max = 256 },
321 /* Pineview only has one combined m divider, which we treat as m2. */
322 .m1 = { .min = 0, .max = 0 },
323 .m2 = { .min = 0, .max = 254 },
324 .p = { .min = 5, .max = 80 },
325 .p1 = { .min = 1, .max = 8 },
326 .p2 = { .dot_limit = 200000,
327 .p2_slow = 10, .p2_fast = 5 },
330 static const struct intel_limit intel_limits_pineview_lvds = {
331 .dot = { .min = 20000, .max = 400000 },
332 .vco = { .min = 1700000, .max = 3500000 },
333 .n = { .min = 3, .max = 6 },
334 .m = { .min = 2, .max = 256 },
335 .m1 = { .min = 0, .max = 0 },
336 .m2 = { .min = 0, .max = 254 },
337 .p = { .min = 7, .max = 112 },
338 .p1 = { .min = 1, .max = 8 },
339 .p2 = { .dot_limit = 112000,
340 .p2_slow = 14, .p2_fast = 14 },
343 /* Ironlake / Sandybridge
345 * We calculate clock using (register_value + 2) for N/M1/M2, so here
346 * the range value for them is (actual_value - 2).
348 static const struct intel_limit intel_limits_ironlake_dac = {
349 .dot = { .min = 25000, .max = 350000 },
350 .vco = { .min = 1760000, .max = 3510000 },
351 .n = { .min = 1, .max = 5 },
352 .m = { .min = 79, .max = 127 },
353 .m1 = { .min = 12, .max = 22 },
354 .m2 = { .min = 5, .max = 9 },
355 .p = { .min = 5, .max = 80 },
356 .p1 = { .min = 1, .max = 8 },
357 .p2 = { .dot_limit = 225000,
358 .p2_slow = 10, .p2_fast = 5 },
361 static const struct intel_limit intel_limits_ironlake_single_lvds = {
362 .dot = { .min = 25000, .max = 350000 },
363 .vco = { .min = 1760000, .max = 3510000 },
364 .n = { .min = 1, .max = 3 },
365 .m = { .min = 79, .max = 118 },
366 .m1 = { .min = 12, .max = 22 },
367 .m2 = { .min = 5, .max = 9 },
368 .p = { .min = 28, .max = 112 },
369 .p1 = { .min = 2, .max = 8 },
370 .p2 = { .dot_limit = 225000,
371 .p2_slow = 14, .p2_fast = 14 },
374 static const struct intel_limit intel_limits_ironlake_dual_lvds = {
375 .dot = { .min = 25000, .max = 350000 },
376 .vco = { .min = 1760000, .max = 3510000 },
377 .n = { .min = 1, .max = 3 },
378 .m = { .min = 79, .max = 127 },
379 .m1 = { .min = 12, .max = 22 },
380 .m2 = { .min = 5, .max = 9 },
381 .p = { .min = 14, .max = 56 },
382 .p1 = { .min = 2, .max = 8 },
383 .p2 = { .dot_limit = 225000,
384 .p2_slow = 7, .p2_fast = 7 },
387 /* LVDS 100mhz refclk limits. */
388 static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
389 .dot = { .min = 25000, .max = 350000 },
390 .vco = { .min = 1760000, .max = 3510000 },
391 .n = { .min = 1, .max = 2 },
392 .m = { .min = 79, .max = 126 },
393 .m1 = { .min = 12, .max = 22 },
394 .m2 = { .min = 5, .max = 9 },
395 .p = { .min = 28, .max = 112 },
396 .p1 = { .min = 2, .max = 8 },
397 .p2 = { .dot_limit = 225000,
398 .p2_slow = 14, .p2_fast = 14 },
401 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
402 .dot = { .min = 25000, .max = 350000 },
403 .vco = { .min = 1760000, .max = 3510000 },
404 .n = { .min = 1, .max = 3 },
405 .m = { .min = 79, .max = 126 },
406 .m1 = { .min = 12, .max = 22 },
407 .m2 = { .min = 5, .max = 9 },
408 .p = { .min = 14, .max = 42 },
409 .p1 = { .min = 2, .max = 6 },
410 .p2 = { .dot_limit = 225000,
411 .p2_slow = 7, .p2_fast = 7 },
414 static const struct intel_limit intel_limits_vlv = {
416 * These are the data rate limits (measured in fast clocks)
417 * since those are the strictest limits we have. The fast
418 * clock and actual rate limits are more relaxed, so checking
419 * them would make no difference.
421 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
422 .vco = { .min = 4000000, .max = 6000000 },
423 .n = { .min = 1, .max = 7 },
424 .m1 = { .min = 2, .max = 3 },
425 .m2 = { .min = 11, .max = 156 },
426 .p1 = { .min = 2, .max = 3 },
427 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
430 static const struct intel_limit intel_limits_chv = {
432 * These are the data rate limits (measured in fast clocks)
433 * since those are the strictest limits we have. The fast
434 * clock and actual rate limits are more relaxed, so checking
435 * them would make no difference.
437 .dot = { .min = 25000 * 5, .max = 540000 * 5},
438 .vco = { .min = 4800000, .max = 6480000 },
439 .n = { .min = 1, .max = 1 },
440 .m1 = { .min = 2, .max = 2 },
441 .m2 = { .min = 24 << 22, .max = 175 << 22 },
442 .p1 = { .min = 2, .max = 4 },
443 .p2 = { .p2_slow = 1, .p2_fast = 14 },
446 static const struct intel_limit intel_limits_bxt = {
447 /* FIXME: find real dot limits */
448 .dot = { .min = 0, .max = INT_MAX },
449 .vco = { .min = 4800000, .max = 6700000 },
450 .n = { .min = 1, .max = 1 },
451 .m1 = { .min = 2, .max = 2 },
452 /* FIXME: find real m2 limits */
453 .m2 = { .min = 2 << 22, .max = 255 << 22 },
454 .p1 = { .min = 2, .max = 4 },
455 .p2 = { .p2_slow = 1, .p2_fast = 20 },
459 skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable)
462 I915_WRITE(CLKGATE_DIS_PSL(pipe),
463 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
465 I915_WRITE(CLKGATE_DIS_PSL(pipe),
466 I915_READ(CLKGATE_DIS_PSL(pipe)) &
467 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
471 needs_modeset(const struct drm_crtc_state *state)
473 return drm_atomic_crtc_needs_modeset(state);
477 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
478 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
479 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
480 * The helpers' return value is the rate of the clock that is fed to the
481 * display engine's pipe which can be the above fast dot clock rate or a
482 * divided-down version of it.
484 /* m1 is reserved as 0 in Pineview, n is a ring counter */
485 static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
487 clock->m = clock->m2 + 2;
488 clock->p = clock->p1 * clock->p2;
489 if (WARN_ON(clock->n == 0 || clock->p == 0))
491 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
492 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
497 static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
499 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
502 static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
504 clock->m = i9xx_dpll_compute_m(clock);
505 clock->p = clock->p1 * clock->p2;
506 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
508 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
509 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
514 static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
516 clock->m = clock->m1 * clock->m2;
517 clock->p = clock->p1 * clock->p2;
518 if (WARN_ON(clock->n == 0 || clock->p == 0))
520 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
521 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
523 return clock->dot / 5;
526 int chv_calc_dpll_params(int refclk, struct dpll *clock)
528 clock->m = clock->m1 * clock->m2;
529 clock->p = clock->p1 * clock->p2;
530 if (WARN_ON(clock->n == 0 || clock->p == 0))
532 clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
534 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
536 return clock->dot / 5;
539 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
542 * Returns whether the given set of divisors are valid for a given refclk with
543 * the given connectors.
545 static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
546 const struct intel_limit *limit,
547 const struct dpll *clock)
549 if (clock->n < limit->n.min || limit->n.max < clock->n)
550 INTELPllInvalid("n out of range\n");
551 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
552 INTELPllInvalid("p1 out of range\n");
553 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
554 INTELPllInvalid("m2 out of range\n");
555 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
556 INTELPllInvalid("m1 out of range\n");
558 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
559 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
560 if (clock->m1 <= clock->m2)
561 INTELPllInvalid("m1 <= m2\n");
563 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
564 !IS_GEN9_LP(dev_priv)) {
565 if (clock->p < limit->p.min || limit->p.max < clock->p)
566 INTELPllInvalid("p out of range\n");
567 if (clock->m < limit->m.min || limit->m.max < clock->m)
568 INTELPllInvalid("m out of range\n");
571 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
572 INTELPllInvalid("vco out of range\n");
573 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
574 * connector, etc., rather than just a single range.
576 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
577 INTELPllInvalid("dot out of range\n");
583 i9xx_select_p2_div(const struct intel_limit *limit,
584 const struct intel_crtc_state *crtc_state,
587 struct drm_device *dev = crtc_state->base.crtc->dev;
589 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
591 * For LVDS just rely on its current settings for dual-channel.
592 * We haven't figured out how to reliably set up different
593 * single/dual channel state, if we even can.
595 if (intel_is_dual_link_lvds(dev))
596 return limit->p2.p2_fast;
598 return limit->p2.p2_slow;
600 if (target < limit->p2.dot_limit)
601 return limit->p2.p2_slow;
603 return limit->p2.p2_fast;
608 * Returns a set of divisors for the desired target clock with the given
609 * refclk, or FALSE. The returned values represent the clock equation:
610 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
612 * Target and reference clocks are specified in kHz.
614 * If match_clock is provided, then best_clock P divider must match the P
615 * divider from @match_clock used for LVDS downclocking.
618 i9xx_find_best_dpll(const struct intel_limit *limit,
619 struct intel_crtc_state *crtc_state,
620 int target, int refclk, struct dpll *match_clock,
621 struct dpll *best_clock)
623 struct drm_device *dev = crtc_state->base.crtc->dev;
627 memset(best_clock, 0, sizeof(*best_clock));
629 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
631 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
633 for (clock.m2 = limit->m2.min;
634 clock.m2 <= limit->m2.max; clock.m2++) {
635 if (clock.m2 >= clock.m1)
637 for (clock.n = limit->n.min;
638 clock.n <= limit->n.max; clock.n++) {
639 for (clock.p1 = limit->p1.min;
640 clock.p1 <= limit->p1.max; clock.p1++) {
643 i9xx_calc_dpll_params(refclk, &clock);
644 if (!intel_PLL_is_valid(to_i915(dev),
649 clock.p != match_clock->p)
652 this_err = abs(clock.dot - target);
653 if (this_err < err) {
662 return (err != target);
666 * Returns a set of divisors for the desired target clock with the given
667 * refclk, or FALSE. The returned values represent the clock equation:
668 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
670 * Target and reference clocks are specified in kHz.
672 * If match_clock is provided, then best_clock P divider must match the P
673 * divider from @match_clock used for LVDS downclocking.
676 pnv_find_best_dpll(const struct intel_limit *limit,
677 struct intel_crtc_state *crtc_state,
678 int target, int refclk, struct dpll *match_clock,
679 struct dpll *best_clock)
681 struct drm_device *dev = crtc_state->base.crtc->dev;
685 memset(best_clock, 0, sizeof(*best_clock));
687 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
689 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
691 for (clock.m2 = limit->m2.min;
692 clock.m2 <= limit->m2.max; clock.m2++) {
693 for (clock.n = limit->n.min;
694 clock.n <= limit->n.max; clock.n++) {
695 for (clock.p1 = limit->p1.min;
696 clock.p1 <= limit->p1.max; clock.p1++) {
699 pnv_calc_dpll_params(refclk, &clock);
700 if (!intel_PLL_is_valid(to_i915(dev),
705 clock.p != match_clock->p)
708 this_err = abs(clock.dot - target);
709 if (this_err < err) {
718 return (err != target);
722 * Returns a set of divisors for the desired target clock with the given
723 * refclk, or FALSE. The returned values represent the clock equation:
724 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
726 * Target and reference clocks are specified in kHz.
728 * If match_clock is provided, then best_clock P divider must match the P
729 * divider from @match_clock used for LVDS downclocking.
732 g4x_find_best_dpll(const struct intel_limit *limit,
733 struct intel_crtc_state *crtc_state,
734 int target, int refclk, struct dpll *match_clock,
735 struct dpll *best_clock)
737 struct drm_device *dev = crtc_state->base.crtc->dev;
741 /* approximately equals target * 0.00585 */
742 int err_most = (target >> 8) + (target >> 9);
744 memset(best_clock, 0, sizeof(*best_clock));
746 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
748 max_n = limit->n.max;
749 /* based on hardware requirement, prefer smaller n to precision */
750 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
751 /* based on hardware requirement, prefere larger m1,m2 */
752 for (clock.m1 = limit->m1.max;
753 clock.m1 >= limit->m1.min; clock.m1--) {
754 for (clock.m2 = limit->m2.max;
755 clock.m2 >= limit->m2.min; clock.m2--) {
756 for (clock.p1 = limit->p1.max;
757 clock.p1 >= limit->p1.min; clock.p1--) {
760 i9xx_calc_dpll_params(refclk, &clock);
761 if (!intel_PLL_is_valid(to_i915(dev),
766 this_err = abs(clock.dot - target);
767 if (this_err < err_most) {
781 * Check if the calculated PLL configuration is more optimal compared to the
782 * best configuration and error found so far. Return the calculated error.
784 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
785 const struct dpll *calculated_clock,
786 const struct dpll *best_clock,
787 unsigned int best_error_ppm,
788 unsigned int *error_ppm)
791 * For CHV ignore the error and consider only the P value.
792 * Prefer a bigger P value based on HW requirements.
794 if (IS_CHERRYVIEW(to_i915(dev))) {
797 return calculated_clock->p > best_clock->p;
800 if (WARN_ON_ONCE(!target_freq))
803 *error_ppm = div_u64(1000000ULL *
804 abs(target_freq - calculated_clock->dot),
807 * Prefer a better P value over a better (smaller) error if the error
808 * is small. Ensure this preference for future configurations too by
809 * setting the error to 0.
811 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
817 return *error_ppm + 10 < best_error_ppm;
821 * Returns a set of divisors for the desired target clock with the given
822 * refclk, or FALSE. The returned values represent the clock equation:
823 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
826 vlv_find_best_dpll(const struct intel_limit *limit,
827 struct intel_crtc_state *crtc_state,
828 int target, int refclk, struct dpll *match_clock,
829 struct dpll *best_clock)
831 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
832 struct drm_device *dev = crtc->base.dev;
834 unsigned int bestppm = 1000000;
835 /* min update 19.2 MHz */
836 int max_n = min(limit->n.max, refclk / 19200);
839 target *= 5; /* fast clock */
841 memset(best_clock, 0, sizeof(*best_clock));
843 /* based on hardware requirement, prefer smaller n to precision */
844 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
845 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
846 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
847 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
848 clock.p = clock.p1 * clock.p2;
849 /* based on hardware requirement, prefer bigger m1,m2 values */
850 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
853 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
856 vlv_calc_dpll_params(refclk, &clock);
858 if (!intel_PLL_is_valid(to_i915(dev),
863 if (!vlv_PLL_is_optimal(dev, target,
881 * Returns a set of divisors for the desired target clock with the given
882 * refclk, or FALSE. The returned values represent the clock equation:
883 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
886 chv_find_best_dpll(const struct intel_limit *limit,
887 struct intel_crtc_state *crtc_state,
888 int target, int refclk, struct dpll *match_clock,
889 struct dpll *best_clock)
891 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
892 struct drm_device *dev = crtc->base.dev;
893 unsigned int best_error_ppm;
898 memset(best_clock, 0, sizeof(*best_clock));
899 best_error_ppm = 1000000;
902 * Based on hardware doc, the n always set to 1, and m1 always
903 * set to 2. If requires to support 200Mhz refclk, we need to
904 * revisit this because n may not 1 anymore.
906 clock.n = 1, clock.m1 = 2;
907 target *= 5; /* fast clock */
909 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
910 for (clock.p2 = limit->p2.p2_fast;
911 clock.p2 >= limit->p2.p2_slow;
912 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
913 unsigned int error_ppm;
915 clock.p = clock.p1 * clock.p2;
917 m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
918 clock.n) << 22, refclk * clock.m1);
920 if (m2 > INT_MAX/clock.m1)
925 chv_calc_dpll_params(refclk, &clock);
927 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
930 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
931 best_error_ppm, &error_ppm))
935 best_error_ppm = error_ppm;
943 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock,
944 struct dpll *best_clock)
947 const struct intel_limit *limit = &intel_limits_bxt;
949 return chv_find_best_dpll(limit, crtc_state,
950 target_clock, refclk, NULL, best_clock);
953 bool intel_crtc_active(struct intel_crtc *crtc)
955 /* Be paranoid as we can arrive here with only partial
956 * state retrieved from the hardware during setup.
958 * We can ditch the adjusted_mode.crtc_clock check as soon
959 * as Haswell has gained clock readout/fastboot support.
961 * We can ditch the crtc->primary->state->fb check as soon as we can
962 * properly reconstruct framebuffers.
964 * FIXME: The intel_crtc->active here should be switched to
965 * crtc->state->active once we have proper CRTC states wired up
968 return crtc->active && crtc->base.primary->state->fb &&
969 crtc->config->base.adjusted_mode.crtc_clock;
972 enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
975 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
977 return crtc->config->cpu_transcoder;
980 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
983 i915_reg_t reg = PIPEDSL(pipe);
987 if (IS_GEN2(dev_priv))
988 line_mask = DSL_LINEMASK_GEN2;
990 line_mask = DSL_LINEMASK_GEN3;
992 line1 = I915_READ(reg) & line_mask;
994 line2 = I915_READ(reg) & line_mask;
996 return line1 != line2;
999 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1001 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1002 enum pipe pipe = crtc->pipe;
1004 /* Wait for the display line to settle/start moving */
1005 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1006 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1007 pipe_name(pipe), onoff(state));
1010 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1012 wait_for_pipe_scanline_moving(crtc, false);
1015 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1017 wait_for_pipe_scanline_moving(crtc, true);
1021 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
1023 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1024 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1026 if (INTEL_GEN(dev_priv) >= 4) {
1027 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1028 i915_reg_t reg = PIPECONF(cpu_transcoder);
1030 /* Wait for the Pipe State to go off */
1031 if (intel_wait_for_register(dev_priv,
1032 reg, I965_PIPECONF_ACTIVE, 0,
1034 WARN(1, "pipe_off wait timed out\n");
1036 intel_wait_for_pipe_scanline_stopped(crtc);
1040 /* Only for pre-ILK configs */
1041 void assert_pll(struct drm_i915_private *dev_priv,
1042 enum pipe pipe, bool state)
1047 val = I915_READ(DPLL(pipe));
1048 cur_state = !!(val & DPLL_VCO_ENABLE);
1049 I915_STATE_WARN(cur_state != state,
1050 "PLL state assertion failure (expected %s, current %s)\n",
1051 onoff(state), onoff(cur_state));
1054 /* XXX: the dsi pll is shared between MIPI DSI ports */
1055 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1060 mutex_lock(&dev_priv->sb_lock);
1061 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1062 mutex_unlock(&dev_priv->sb_lock);
1064 cur_state = val & DSI_PLL_VCO_EN;
1065 I915_STATE_WARN(cur_state != state,
1066 "DSI PLL state assertion failure (expected %s, current %s)\n",
1067 onoff(state), onoff(cur_state));
1070 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1071 enum pipe pipe, bool state)
1074 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1077 if (HAS_DDI(dev_priv)) {
1078 /* DDI does not have a specific FDI_TX register */
1079 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1080 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1082 u32 val = I915_READ(FDI_TX_CTL(pipe));
1083 cur_state = !!(val & FDI_TX_ENABLE);
1085 I915_STATE_WARN(cur_state != state,
1086 "FDI TX state assertion failure (expected %s, current %s)\n",
1087 onoff(state), onoff(cur_state));
1089 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1090 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1092 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1093 enum pipe pipe, bool state)
1098 val = I915_READ(FDI_RX_CTL(pipe));
1099 cur_state = !!(val & FDI_RX_ENABLE);
1100 I915_STATE_WARN(cur_state != state,
1101 "FDI RX state assertion failure (expected %s, current %s)\n",
1102 onoff(state), onoff(cur_state));
1104 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1105 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1107 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1112 /* ILK FDI PLL is always enabled */
1113 if (IS_GEN5(dev_priv))
1116 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1117 if (HAS_DDI(dev_priv))
1120 val = I915_READ(FDI_TX_CTL(pipe));
1121 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1124 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1125 enum pipe pipe, bool state)
1130 val = I915_READ(FDI_RX_CTL(pipe));
1131 cur_state = !!(val & FDI_RX_PLL_ENABLE);
1132 I915_STATE_WARN(cur_state != state,
1133 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1134 onoff(state), onoff(cur_state));
1137 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
1141 enum pipe panel_pipe = INVALID_PIPE;
1144 if (WARN_ON(HAS_DDI(dev_priv)))
1147 if (HAS_PCH_SPLIT(dev_priv)) {
1150 pp_reg = PP_CONTROL(0);
1151 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1154 case PANEL_PORT_SELECT_LVDS:
1155 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
1157 case PANEL_PORT_SELECT_DPA:
1158 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1160 case PANEL_PORT_SELECT_DPC:
1161 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1163 case PANEL_PORT_SELECT_DPD:
1164 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1167 MISSING_CASE(port_sel);
1170 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1171 /* presumably write lock depends on pipe, not port select */
1172 pp_reg = PP_CONTROL(pipe);
1177 pp_reg = PP_CONTROL(0);
1178 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1180 WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS);
1181 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
1184 val = I915_READ(pp_reg);
1185 if (!(val & PANEL_POWER_ON) ||
1186 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1189 I915_STATE_WARN(panel_pipe == pipe && locked,
1190 "panel assertion failure, pipe %c regs locked\n",
1194 void assert_pipe(struct drm_i915_private *dev_priv,
1195 enum pipe pipe, bool state)
1198 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1200 enum intel_display_power_domain power_domain;
1202 /* we keep both pipes enabled on 830 */
1203 if (IS_I830(dev_priv))
1206 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1207 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
1208 u32 val = I915_READ(PIPECONF(cpu_transcoder));
1209 cur_state = !!(val & PIPECONF_ENABLE);
1211 intel_display_power_put(dev_priv, power_domain);
1216 I915_STATE_WARN(cur_state != state,
1217 "pipe %c assertion failure (expected %s, current %s)\n",
1218 pipe_name(pipe), onoff(state), onoff(cur_state));
1221 static void assert_plane(struct intel_plane *plane, bool state)
1226 cur_state = plane->get_hw_state(plane, &pipe);
1228 I915_STATE_WARN(cur_state != state,
1229 "%s assertion failure (expected %s, current %s)\n",
1230 plane->base.name, onoff(state), onoff(cur_state));
1233 #define assert_plane_enabled(p) assert_plane(p, true)
1234 #define assert_plane_disabled(p) assert_plane(p, false)
1236 static void assert_planes_disabled(struct intel_crtc *crtc)
1238 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1239 struct intel_plane *plane;
1241 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1242 assert_plane_disabled(plane);
1245 static void assert_vblank_disabled(struct drm_crtc *crtc)
1247 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1248 drm_crtc_vblank_put(crtc);
1251 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1257 val = I915_READ(PCH_TRANSCONF(pipe));
1258 enabled = !!(val & TRANS_ENABLE);
1259 I915_STATE_WARN(enabled,
1260 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1264 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1265 enum pipe pipe, enum port port,
1268 enum pipe port_pipe;
1271 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1273 I915_STATE_WARN(state && port_pipe == pipe,
1274 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1275 port_name(port), pipe_name(pipe));
1277 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1278 "IBX PCH DP %c still using transcoder B\n",
1282 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1283 enum pipe pipe, enum port port,
1284 i915_reg_t hdmi_reg)
1286 enum pipe port_pipe;
1289 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1291 I915_STATE_WARN(state && port_pipe == pipe,
1292 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1293 port_name(port), pipe_name(pipe));
1295 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1296 "IBX PCH HDMI %c still using transcoder B\n",
1300 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1303 enum pipe port_pipe;
1305 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1306 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1307 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
1309 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1311 "PCH VGA enabled on transcoder %c, should be disabled\n",
1314 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1316 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1319 /* PCH SDVOB multiplex with HDMIB */
1320 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1321 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1322 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
1325 static void _vlv_enable_pll(struct intel_crtc *crtc,
1326 const struct intel_crtc_state *pipe_config)
1328 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1329 enum pipe pipe = crtc->pipe;
1331 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1332 POSTING_READ(DPLL(pipe));
1335 if (intel_wait_for_register(dev_priv,
1340 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1343 static void vlv_enable_pll(struct intel_crtc *crtc,
1344 const struct intel_crtc_state *pipe_config)
1346 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1347 enum pipe pipe = crtc->pipe;
1349 assert_pipe_disabled(dev_priv, pipe);
1351 /* PLL is protected by panel, make sure we can write it */
1352 assert_panel_unlocked(dev_priv, pipe);
1354 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1355 _vlv_enable_pll(crtc, pipe_config);
1357 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1358 POSTING_READ(DPLL_MD(pipe));
1362 static void _chv_enable_pll(struct intel_crtc *crtc,
1363 const struct intel_crtc_state *pipe_config)
1365 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1366 enum pipe pipe = crtc->pipe;
1367 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1370 mutex_lock(&dev_priv->sb_lock);
1372 /* Enable back the 10bit clock to display controller */
1373 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1374 tmp |= DPIO_DCLKP_EN;
1375 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1377 mutex_unlock(&dev_priv->sb_lock);
1380 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1385 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1387 /* Check PLL is locked */
1388 if (intel_wait_for_register(dev_priv,
1389 DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV,
1391 DRM_ERROR("PLL %d failed to lock\n", pipe);
1394 static void chv_enable_pll(struct intel_crtc *crtc,
1395 const struct intel_crtc_state *pipe_config)
1397 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1398 enum pipe pipe = crtc->pipe;
1400 assert_pipe_disabled(dev_priv, pipe);
1402 /* PLL is protected by panel, make sure we can write it */
1403 assert_panel_unlocked(dev_priv, pipe);
1405 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1406 _chv_enable_pll(crtc, pipe_config);
1408 if (pipe != PIPE_A) {
1410 * WaPixelRepeatModeFixForC0:chv
1412 * DPLLCMD is AWOL. Use chicken bits to propagate
1413 * the value from DPLLBMD to either pipe B or C.
1415 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1416 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1417 I915_WRITE(CBR4_VLV, 0);
1418 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1421 * DPLLB VGA mode also seems to cause problems.
1422 * We should always have it disabled.
1424 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1426 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1427 POSTING_READ(DPLL_MD(pipe));
1431 static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv)
1433 struct intel_crtc *crtc;
1436 for_each_intel_crtc(&dev_priv->drm, crtc) {
1437 count += crtc->base.state->active &&
1438 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO);
1444 static void i9xx_enable_pll(struct intel_crtc *crtc,
1445 const struct intel_crtc_state *crtc_state)
1447 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1448 i915_reg_t reg = DPLL(crtc->pipe);
1449 u32 dpll = crtc_state->dpll_hw_state.dpll;
1452 assert_pipe_disabled(dev_priv, crtc->pipe);
1454 /* PLL is protected by panel, make sure we can write it */
1455 if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv))
1456 assert_panel_unlocked(dev_priv, crtc->pipe);
1458 /* Enable DVO 2x clock on both PLLs if necessary */
1459 if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) {
1461 * It appears to be important that we don't enable this
1462 * for the current pipe before otherwise configuring the
1463 * PLL. No idea how this should be handled if multiple
1464 * DVO outputs are enabled simultaneosly.
1466 dpll |= DPLL_DVO_2X_MODE;
1467 I915_WRITE(DPLL(!crtc->pipe),
1468 I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
1472 * Apparently we need to have VGA mode enabled prior to changing
1473 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1474 * dividers, even though the register value does change.
1478 I915_WRITE(reg, dpll);
1480 /* Wait for the clocks to stabilize. */
1484 if (INTEL_GEN(dev_priv) >= 4) {
1485 I915_WRITE(DPLL_MD(crtc->pipe),
1486 crtc_state->dpll_hw_state.dpll_md);
1488 /* The pixel multiplier can only be updated once the
1489 * DPLL is enabled and the clocks are stable.
1491 * So write it again.
1493 I915_WRITE(reg, dpll);
1496 /* We do this three times for luck */
1497 for (i = 0; i < 3; i++) {
1498 I915_WRITE(reg, dpll);
1500 udelay(150); /* wait for warmup */
1504 static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
1506 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1507 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1508 enum pipe pipe = crtc->pipe;
1510 /* Disable DVO 2x clock on both PLLs if necessary */
1511 if (IS_I830(dev_priv) &&
1512 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO) &&
1513 !intel_num_dvo_pipes(dev_priv)) {
1514 I915_WRITE(DPLL(PIPE_B),
1515 I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
1516 I915_WRITE(DPLL(PIPE_A),
1517 I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
1520 /* Don't disable pipe or pipe PLLs if needed */
1521 if (IS_I830(dev_priv))
1524 /* Make sure the pipe isn't still relying on us */
1525 assert_pipe_disabled(dev_priv, pipe);
1527 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
1528 POSTING_READ(DPLL(pipe));
1531 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1535 /* Make sure the pipe isn't still relying on us */
1536 assert_pipe_disabled(dev_priv, pipe);
1538 val = DPLL_INTEGRATED_REF_CLK_VLV |
1539 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1541 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1543 I915_WRITE(DPLL(pipe), val);
1544 POSTING_READ(DPLL(pipe));
1547 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1549 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1552 /* Make sure the pipe isn't still relying on us */
1553 assert_pipe_disabled(dev_priv, pipe);
1555 val = DPLL_SSC_REF_CLK_CHV |
1556 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1558 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1560 I915_WRITE(DPLL(pipe), val);
1561 POSTING_READ(DPLL(pipe));
1563 mutex_lock(&dev_priv->sb_lock);
1565 /* Disable 10bit clock to display controller */
1566 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1567 val &= ~DPIO_DCLKP_EN;
1568 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1570 mutex_unlock(&dev_priv->sb_lock);
1573 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1574 struct intel_digital_port *dport,
1575 unsigned int expected_mask)
1578 i915_reg_t dpll_reg;
1580 switch (dport->base.port) {
1582 port_mask = DPLL_PORTB_READY_MASK;
1586 port_mask = DPLL_PORTC_READY_MASK;
1588 expected_mask <<= 4;
1591 port_mask = DPLL_PORTD_READY_MASK;
1592 dpll_reg = DPIO_PHY_STATUS;
1598 if (intel_wait_for_register(dev_priv,
1599 dpll_reg, port_mask, expected_mask,
1601 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1602 port_name(dport->base.port),
1603 I915_READ(dpll_reg) & port_mask, expected_mask);
1606 static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
1608 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1609 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1610 enum pipe pipe = crtc->pipe;
1612 uint32_t val, pipeconf_val;
1614 /* Make sure PCH DPLL is enabled */
1615 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
1617 /* FDI must be feeding us bits for PCH ports */
1618 assert_fdi_tx_enabled(dev_priv, pipe);
1619 assert_fdi_rx_enabled(dev_priv, pipe);
1621 if (HAS_PCH_CPT(dev_priv)) {
1622 /* Workaround: Set the timing override bit before enabling the
1623 * pch transcoder. */
1624 reg = TRANS_CHICKEN2(pipe);
1625 val = I915_READ(reg);
1626 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1627 I915_WRITE(reg, val);
1630 reg = PCH_TRANSCONF(pipe);
1631 val = I915_READ(reg);
1632 pipeconf_val = I915_READ(PIPECONF(pipe));
1634 if (HAS_PCH_IBX(dev_priv)) {
1636 * Make the BPC in transcoder be consistent with
1637 * that in pipeconf reg. For HDMI we must use 8bpc
1638 * here for both 8bpc and 12bpc.
1640 val &= ~PIPECONF_BPC_MASK;
1641 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1642 val |= PIPECONF_8BPC;
1644 val |= pipeconf_val & PIPECONF_BPC_MASK;
1647 val &= ~TRANS_INTERLACE_MASK;
1648 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
1649 if (HAS_PCH_IBX(dev_priv) &&
1650 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
1651 val |= TRANS_LEGACY_INTERLACED_ILK;
1653 val |= TRANS_INTERLACED;
1655 val |= TRANS_PROGRESSIVE;
1657 I915_WRITE(reg, val | TRANS_ENABLE);
1658 if (intel_wait_for_register(dev_priv,
1659 reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE,
1661 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
1664 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1665 enum transcoder cpu_transcoder)
1667 u32 val, pipeconf_val;
1669 /* FDI must be feeding us bits for PCH ports */
1670 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1671 assert_fdi_rx_enabled(dev_priv, PIPE_A);
1673 /* Workaround: set timing override bit. */
1674 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1675 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1676 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1679 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
1681 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1682 PIPECONF_INTERLACED_ILK)
1683 val |= TRANS_INTERLACED;
1685 val |= TRANS_PROGRESSIVE;
1687 I915_WRITE(LPT_TRANSCONF, val);
1688 if (intel_wait_for_register(dev_priv,
1693 DRM_ERROR("Failed to enable PCH transcoder\n");
1696 static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1702 /* FDI relies on the transcoder */
1703 assert_fdi_tx_disabled(dev_priv, pipe);
1704 assert_fdi_rx_disabled(dev_priv, pipe);
1706 /* Ports must be off as well */
1707 assert_pch_ports_disabled(dev_priv, pipe);
1709 reg = PCH_TRANSCONF(pipe);
1710 val = I915_READ(reg);
1711 val &= ~TRANS_ENABLE;
1712 I915_WRITE(reg, val);
1713 /* wait for PCH transcoder off, transcoder state */
1714 if (intel_wait_for_register(dev_priv,
1715 reg, TRANS_STATE_ENABLE, 0,
1717 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
1719 if (HAS_PCH_CPT(dev_priv)) {
1720 /* Workaround: Clear the timing override chicken bit again. */
1721 reg = TRANS_CHICKEN2(pipe);
1722 val = I915_READ(reg);
1723 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1724 I915_WRITE(reg, val);
1728 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1732 val = I915_READ(LPT_TRANSCONF);
1733 val &= ~TRANS_ENABLE;
1734 I915_WRITE(LPT_TRANSCONF, val);
1735 /* wait for PCH transcoder off, transcoder state */
1736 if (intel_wait_for_register(dev_priv,
1737 LPT_TRANSCONF, TRANS_STATE_ENABLE, 0,
1739 DRM_ERROR("Failed to disable PCH transcoder\n");
1741 /* Workaround: clear timing override bit. */
1742 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1743 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1744 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1747 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
1749 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1751 if (HAS_PCH_LPT(dev_priv))
1757 static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
1759 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1760 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1761 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1762 enum pipe pipe = crtc->pipe;
1766 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1768 assert_planes_disabled(crtc);
1771 * A pipe without a PLL won't actually be able to drive bits from
1772 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1775 if (HAS_GMCH_DISPLAY(dev_priv)) {
1776 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1777 assert_dsi_pll_enabled(dev_priv);
1779 assert_pll_enabled(dev_priv, pipe);
1781 if (new_crtc_state->has_pch_encoder) {
1782 /* if driving the PCH, we need FDI enabled */
1783 assert_fdi_rx_pll_enabled(dev_priv,
1784 intel_crtc_pch_transcoder(crtc));
1785 assert_fdi_tx_pll_enabled(dev_priv,
1786 (enum pipe) cpu_transcoder);
1788 /* FIXME: assert CPU port conditions for SNB+ */
1791 reg = PIPECONF(cpu_transcoder);
1792 val = I915_READ(reg);
1793 if (val & PIPECONF_ENABLE) {
1794 /* we keep both pipes enabled on 830 */
1795 WARN_ON(!IS_I830(dev_priv));
1799 I915_WRITE(reg, val | PIPECONF_ENABLE);
1803 * Until the pipe starts PIPEDSL reads will return a stale value,
1804 * which causes an apparent vblank timestamp jump when PIPEDSL
1805 * resets to its proper value. That also messes up the frame count
1806 * when it's derived from the timestamps. So let's wait for the
1807 * pipe to start properly before we call drm_crtc_vblank_on()
1809 if (dev_priv->drm.max_vblank_count == 0)
1810 intel_wait_for_pipe_scanline_moving(crtc);
1813 static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1815 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1816 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1817 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1818 enum pipe pipe = crtc->pipe;
1822 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1825 * Make sure planes won't keep trying to pump pixels to us,
1826 * or we might hang the display.
1828 assert_planes_disabled(crtc);
1830 reg = PIPECONF(cpu_transcoder);
1831 val = I915_READ(reg);
1832 if ((val & PIPECONF_ENABLE) == 0)
1836 * Double wide has implications for planes
1837 * so best keep it disabled when not needed.
1839 if (old_crtc_state->double_wide)
1840 val &= ~PIPECONF_DOUBLE_WIDE;
1842 /* Don't disable pipe or pipe PLLs if needed */
1843 if (!IS_I830(dev_priv))
1844 val &= ~PIPECONF_ENABLE;
1846 I915_WRITE(reg, val);
1847 if ((val & PIPECONF_ENABLE) == 0)
1848 intel_wait_for_pipe_off(old_crtc_state);
1851 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1853 return IS_GEN2(dev_priv) ? 2048 : 4096;
1857 intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
1859 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1860 unsigned int cpp = fb->format->cpp[color_plane];
1862 switch (fb->modifier) {
1863 case DRM_FORMAT_MOD_LINEAR:
1865 case I915_FORMAT_MOD_X_TILED:
1866 if (IS_GEN2(dev_priv))
1870 case I915_FORMAT_MOD_Y_TILED_CCS:
1871 if (color_plane == 1)
1874 case I915_FORMAT_MOD_Y_TILED:
1875 if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv))
1879 case I915_FORMAT_MOD_Yf_TILED_CCS:
1880 if (color_plane == 1)
1883 case I915_FORMAT_MOD_Yf_TILED:
1899 MISSING_CASE(fb->modifier);
1905 intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
1907 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
1910 return intel_tile_size(to_i915(fb->dev)) /
1911 intel_tile_width_bytes(fb, color_plane);
1914 /* Return the tile dimensions in pixel units */
1915 static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
1916 unsigned int *tile_width,
1917 unsigned int *tile_height)
1919 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
1920 unsigned int cpp = fb->format->cpp[color_plane];
1922 *tile_width = tile_width_bytes / cpp;
1923 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
1927 intel_fb_align_height(const struct drm_framebuffer *fb,
1928 int color_plane, unsigned int height)
1930 unsigned int tile_height = intel_tile_height(fb, color_plane);
1932 return ALIGN(height, tile_height);
1935 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
1937 unsigned int size = 0;
1940 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
1941 size += rot_info->plane[i].width * rot_info->plane[i].height;
1947 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
1948 const struct drm_framebuffer *fb,
1949 unsigned int rotation)
1951 view->type = I915_GGTT_VIEW_NORMAL;
1952 if (drm_rotation_90_or_270(rotation)) {
1953 view->type = I915_GGTT_VIEW_ROTATED;
1954 view->rotated = to_intel_framebuffer(fb)->rot_info;
1958 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
1960 if (IS_I830(dev_priv))
1962 else if (IS_I85X(dev_priv))
1964 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
1970 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
1972 if (INTEL_GEN(dev_priv) >= 9)
1974 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
1975 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
1977 else if (INTEL_GEN(dev_priv) >= 4)
1983 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
1986 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1988 /* AUX_DIST needs only 4K alignment */
1989 if (color_plane == 1)
1992 switch (fb->modifier) {
1993 case DRM_FORMAT_MOD_LINEAR:
1994 return intel_linear_alignment(dev_priv);
1995 case I915_FORMAT_MOD_X_TILED:
1996 if (INTEL_GEN(dev_priv) >= 9)
1999 case I915_FORMAT_MOD_Y_TILED_CCS:
2000 case I915_FORMAT_MOD_Yf_TILED_CCS:
2001 case I915_FORMAT_MOD_Y_TILED:
2002 case I915_FORMAT_MOD_Yf_TILED:
2003 return 1 * 1024 * 1024;
2005 MISSING_CASE(fb->modifier);
2010 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2012 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2013 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2015 return INTEL_GEN(dev_priv) < 4 || plane->has_fbc;
2019 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
2020 const struct i915_ggtt_view *view,
2022 unsigned long *out_flags)
2024 struct drm_device *dev = fb->dev;
2025 struct drm_i915_private *dev_priv = to_i915(dev);
2026 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2027 struct i915_vma *vma;
2028 unsigned int pinctl;
2031 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2033 alignment = intel_surf_alignment(fb, 0);
2035 /* Note that the w/a also requires 64 PTE of padding following the
2036 * bo. We currently fill all unused PTE with the shadow page and so
2037 * we should always have valid PTE following the scanout preventing
2040 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2041 alignment = 256 * 1024;
2044 * Global gtt pte registers are special registers which actually forward
2045 * writes to a chunk of system memory. Which means that there is no risk
2046 * that the register values disappear as soon as we call
2047 * intel_runtime_pm_put(), so it is correct to wrap only the
2048 * pin/unpin/fence and not more.
2050 intel_runtime_pm_get(dev_priv);
2052 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2056 /* Valleyview is definitely limited to scanning out the first
2057 * 512MiB. Lets presume this behaviour was inherited from the
2058 * g4x display engine and that all earlier gen are similarly
2059 * limited. Testing suggests that it is a little more
2060 * complicated than this. For example, Cherryview appears quite
2061 * happy to scanout from anywhere within its global aperture.
2063 if (HAS_GMCH_DISPLAY(dev_priv))
2064 pinctl |= PIN_MAPPABLE;
2066 vma = i915_gem_object_pin_to_display_plane(obj,
2067 alignment, view, pinctl);
2071 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
2074 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2075 * fence, whereas 965+ only requires a fence if using
2076 * framebuffer compression. For simplicity, we always, when
2077 * possible, install a fence as the cost is not that onerous.
2079 * If we fail to fence the tiled scanout, then either the
2080 * modeset will reject the change (which is highly unlikely as
2081 * the affected systems, all but one, do not have unmappable
2082 * space) or we will not be able to enable full powersaving
2083 * techniques (also likely not to apply due to various limits
2084 * FBC and the like impose on the size of the buffer, which
2085 * presumably we violated anyway with this unmappable buffer).
2086 * Anyway, it is presumably better to stumble onwards with
2087 * something and try to run the system in a "less than optimal"
2088 * mode that matches the user configuration.
2090 ret = i915_vma_pin_fence(vma);
2091 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
2092 i915_gem_object_unpin_from_display_plane(vma);
2097 if (ret == 0 && vma->fence)
2098 *out_flags |= PLANE_HAS_FENCE;
2103 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2105 intel_runtime_pm_put(dev_priv);
2109 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
2111 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
2113 if (flags & PLANE_HAS_FENCE)
2114 i915_vma_unpin_fence(vma);
2115 i915_gem_object_unpin_from_display_plane(vma);
2119 static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
2120 unsigned int rotation)
2122 if (drm_rotation_90_or_270(rotation))
2123 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
2125 return fb->pitches[color_plane];
2129 * Convert the x/y offsets into a linear offset.
2130 * Only valid with 0/180 degree rotation, which is fine since linear
2131 * offset is only used with linear buffers on pre-hsw and tiled buffers
2132 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2134 u32 intel_fb_xy_to_linear(int x, int y,
2135 const struct intel_plane_state *state,
2138 const struct drm_framebuffer *fb = state->base.fb;
2139 unsigned int cpp = fb->format->cpp[color_plane];
2140 unsigned int pitch = state->color_plane[color_plane].stride;
2142 return y * pitch + x * cpp;
2146 * Add the x/y offsets derived from fb->offsets[] to the user
2147 * specified plane src x/y offsets. The resulting x/y offsets
2148 * specify the start of scanout from the beginning of the gtt mapping.
2150 void intel_add_fb_offsets(int *x, int *y,
2151 const struct intel_plane_state *state,
2155 const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
2156 unsigned int rotation = state->base.rotation;
2158 if (drm_rotation_90_or_270(rotation)) {
2159 *x += intel_fb->rotated[color_plane].x;
2160 *y += intel_fb->rotated[color_plane].y;
2162 *x += intel_fb->normal[color_plane].x;
2163 *y += intel_fb->normal[color_plane].y;
2167 static u32 intel_adjust_tile_offset(int *x, int *y,
2168 unsigned int tile_width,
2169 unsigned int tile_height,
2170 unsigned int tile_size,
2171 unsigned int pitch_tiles,
2175 unsigned int pitch_pixels = pitch_tiles * tile_width;
2178 WARN_ON(old_offset & (tile_size - 1));
2179 WARN_ON(new_offset & (tile_size - 1));
2180 WARN_ON(new_offset > old_offset);
2182 tiles = (old_offset - new_offset) / tile_size;
2184 *y += tiles / pitch_tiles * tile_height;
2185 *x += tiles % pitch_tiles * tile_width;
2187 /* minimize x in case it got needlessly big */
2188 *y += *x / pitch_pixels * tile_height;
2194 static bool is_surface_linear(u64 modifier, int color_plane)
2196 return modifier == DRM_FORMAT_MOD_LINEAR;
2199 static u32 intel_adjust_aligned_offset(int *x, int *y,
2200 const struct drm_framebuffer *fb,
2202 unsigned int rotation,
2204 u32 old_offset, u32 new_offset)
2206 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2207 unsigned int cpp = fb->format->cpp[color_plane];
2209 WARN_ON(new_offset > old_offset);
2211 if (!is_surface_linear(fb->modifier, color_plane)) {
2212 unsigned int tile_size, tile_width, tile_height;
2213 unsigned int pitch_tiles;
2215 tile_size = intel_tile_size(dev_priv);
2216 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2218 if (drm_rotation_90_or_270(rotation)) {
2219 pitch_tiles = pitch / tile_height;
2220 swap(tile_width, tile_height);
2222 pitch_tiles = pitch / (tile_width * cpp);
2225 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2226 tile_size, pitch_tiles,
2227 old_offset, new_offset);
2229 old_offset += *y * pitch + *x * cpp;
2231 *y = (old_offset - new_offset) / pitch;
2232 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2239 * Adjust the tile offset by moving the difference into
2242 static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2243 const struct intel_plane_state *state,
2245 u32 old_offset, u32 new_offset)
2247 return intel_adjust_aligned_offset(x, y, state->base.fb, color_plane,
2248 state->base.rotation,
2249 state->color_plane[color_plane].stride,
2250 old_offset, new_offset);
2254 * Computes the aligned offset to the base tile and adjusts
2255 * x, y. bytes per pixel is assumed to be a power-of-two.
2257 * In the 90/270 rotated case, x and y are assumed
2258 * to be already rotated to match the rotated GTT view, and
2259 * pitch is the tile_height aligned framebuffer height.
2261 * This function is used when computing the derived information
2262 * under intel_framebuffer, so using any of that information
2263 * here is not allowed. Anything under drm_framebuffer can be
2264 * used. This is why the user has to pass in the pitch since it
2265 * is specified in the rotated orientation.
2267 static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2269 const struct drm_framebuffer *fb,
2272 unsigned int rotation,
2275 unsigned int cpp = fb->format->cpp[color_plane];
2276 u32 offset, offset_aligned;
2281 if (!is_surface_linear(fb->modifier, color_plane)) {
2282 unsigned int tile_size, tile_width, tile_height;
2283 unsigned int tile_rows, tiles, pitch_tiles;
2285 tile_size = intel_tile_size(dev_priv);
2286 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2288 if (drm_rotation_90_or_270(rotation)) {
2289 pitch_tiles = pitch / tile_height;
2290 swap(tile_width, tile_height);
2292 pitch_tiles = pitch / (tile_width * cpp);
2295 tile_rows = *y / tile_height;
2298 tiles = *x / tile_width;
2301 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2302 offset_aligned = offset & ~alignment;
2304 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2305 tile_size, pitch_tiles,
2306 offset, offset_aligned);
2308 offset = *y * pitch + *x * cpp;
2309 offset_aligned = offset & ~alignment;
2311 *y = (offset & alignment) / pitch;
2312 *x = ((offset & alignment) - *y * pitch) / cpp;
2315 return offset_aligned;
2318 static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2319 const struct intel_plane_state *state,
2322 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2323 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2324 const struct drm_framebuffer *fb = state->base.fb;
2325 unsigned int rotation = state->base.rotation;
2326 int pitch = state->color_plane[color_plane].stride;
2329 if (intel_plane->id == PLANE_CURSOR)
2330 alignment = intel_cursor_alignment(dev_priv);
2332 alignment = intel_surf_alignment(fb, color_plane);
2334 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
2335 pitch, rotation, alignment);
2338 /* Convert the fb->offset[] into x/y offsets */
2339 static int intel_fb_offset_to_xy(int *x, int *y,
2340 const struct drm_framebuffer *fb,
2343 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2344 unsigned int height;
2346 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
2347 fb->offsets[color_plane] % intel_tile_size(dev_priv)) {
2348 DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n",
2349 fb->offsets[color_plane], color_plane);
2353 height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
2354 height = ALIGN(height, intel_tile_height(fb, color_plane));
2356 /* Catch potential overflows early */
2357 if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
2358 fb->offsets[color_plane])) {
2359 DRM_DEBUG_KMS("Bad offset 0x%08x or pitch %d for color plane %d\n",
2360 fb->offsets[color_plane], fb->pitches[color_plane],
2368 intel_adjust_aligned_offset(x, y,
2369 fb, color_plane, DRM_MODE_ROTATE_0,
2370 fb->pitches[color_plane],
2371 fb->offsets[color_plane], 0);
2376 static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier)
2378 switch (fb_modifier) {
2379 case I915_FORMAT_MOD_X_TILED:
2380 return I915_TILING_X;
2381 case I915_FORMAT_MOD_Y_TILED:
2382 case I915_FORMAT_MOD_Y_TILED_CCS:
2383 return I915_TILING_Y;
2385 return I915_TILING_NONE;
2390 * From the Sky Lake PRM:
2391 * "The Color Control Surface (CCS) contains the compression status of
2392 * the cache-line pairs. The compression state of the cache-line pair
2393 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2394 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2395 * cache-line-pairs. CCS is always Y tiled."
2397 * Since cache line pairs refers to horizontally adjacent cache lines,
2398 * each cache line in the CCS corresponds to an area of 32x16 cache
2399 * lines on the main surface. Since each pixel is 4 bytes, this gives
2400 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2403 static const struct drm_format_info ccs_formats[] = {
2404 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2405 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2406 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2407 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2410 static const struct drm_format_info *
2411 lookup_format_info(const struct drm_format_info formats[],
2412 int num_formats, u32 format)
2416 for (i = 0; i < num_formats; i++) {
2417 if (formats[i].format == format)
2424 static const struct drm_format_info *
2425 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2427 switch (cmd->modifier[0]) {
2428 case I915_FORMAT_MOD_Y_TILED_CCS:
2429 case I915_FORMAT_MOD_Yf_TILED_CCS:
2430 return lookup_format_info(ccs_formats,
2431 ARRAY_SIZE(ccs_formats),
2438 bool is_ccs_modifier(u64 modifier)
2440 return modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2441 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2445 intel_fill_fb_info(struct drm_i915_private *dev_priv,
2446 struct drm_framebuffer *fb)
2448 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2449 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2450 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2451 u32 gtt_offset_rotated = 0;
2452 unsigned int max_size = 0;
2453 int i, num_planes = fb->format->num_planes;
2454 unsigned int tile_size = intel_tile_size(dev_priv);
2456 for (i = 0; i < num_planes; i++) {
2457 unsigned int width, height;
2458 unsigned int cpp, size;
2463 cpp = fb->format->cpp[i];
2464 width = drm_framebuffer_plane_width(fb->width, fb, i);
2465 height = drm_framebuffer_plane_height(fb->height, fb, i);
2467 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2469 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2474 if (is_ccs_modifier(fb->modifier) && i == 1) {
2475 int hsub = fb->format->hsub;
2476 int vsub = fb->format->vsub;
2477 int tile_width, tile_height;
2481 intel_tile_dims(fb, i, &tile_width, &tile_height);
2483 tile_height *= vsub;
2485 ccs_x = (x * hsub) % tile_width;
2486 ccs_y = (y * vsub) % tile_height;
2487 main_x = intel_fb->normal[0].x % tile_width;
2488 main_y = intel_fb->normal[0].y % tile_height;
2491 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2492 * x/y offsets must match between CCS and the main surface.
2494 if (main_x != ccs_x || main_y != ccs_y) {
2495 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2498 intel_fb->normal[0].x,
2499 intel_fb->normal[0].y,
2506 * The fence (if used) is aligned to the start of the object
2507 * so having the framebuffer wrap around across the edge of the
2508 * fenced region doesn't really work. We have no API to configure
2509 * the fence start offset within the object (nor could we probably
2510 * on gen2/3). So it's just easier if we just require that the
2511 * fb layout agrees with the fence layout. We already check that the
2512 * fb stride matches the fence stride elsewhere.
2514 if (i == 0 && i915_gem_object_is_tiled(obj) &&
2515 (x + width) * cpp > fb->pitches[i]) {
2516 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2522 * First pixel of the framebuffer from
2523 * the start of the normal gtt mapping.
2525 intel_fb->normal[i].x = x;
2526 intel_fb->normal[i].y = y;
2528 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
2532 offset /= tile_size;
2534 if (!is_surface_linear(fb->modifier, i)) {
2535 unsigned int tile_width, tile_height;
2536 unsigned int pitch_tiles;
2539 intel_tile_dims(fb, i, &tile_width, &tile_height);
2541 rot_info->plane[i].offset = offset;
2542 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2543 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2544 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2546 intel_fb->rotated[i].pitch =
2547 rot_info->plane[i].height * tile_height;
2549 /* how many tiles does this plane need */
2550 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2552 * If the plane isn't horizontally tile aligned,
2553 * we need one more tile.
2558 /* rotate the x/y offsets to match the GTT view */
2564 rot_info->plane[i].width * tile_width,
2565 rot_info->plane[i].height * tile_height,
2566 DRM_MODE_ROTATE_270);
2570 /* rotate the tile dimensions to match the GTT view */
2571 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2572 swap(tile_width, tile_height);
2575 * We only keep the x/y offsets, so push all of the
2576 * gtt offset into the x/y offsets.
2578 intel_adjust_tile_offset(&x, &y,
2579 tile_width, tile_height,
2580 tile_size, pitch_tiles,
2581 gtt_offset_rotated * tile_size, 0);
2583 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2586 * First pixel of the framebuffer from
2587 * the start of the rotated gtt mapping.
2589 intel_fb->rotated[i].x = x;
2590 intel_fb->rotated[i].y = y;
2592 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2593 x * cpp, tile_size);
2596 /* how many tiles in total needed in the bo */
2597 max_size = max(max_size, offset + size);
2600 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
2601 DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n",
2602 mul_u32_u32(max_size, tile_size), obj->base.size);
2609 static int i9xx_format_to_fourcc(int format)
2612 case DISPPLANE_8BPP:
2613 return DRM_FORMAT_C8;
2614 case DISPPLANE_BGRX555:
2615 return DRM_FORMAT_XRGB1555;
2616 case DISPPLANE_BGRX565:
2617 return DRM_FORMAT_RGB565;
2619 case DISPPLANE_BGRX888:
2620 return DRM_FORMAT_XRGB8888;
2621 case DISPPLANE_RGBX888:
2622 return DRM_FORMAT_XBGR8888;
2623 case DISPPLANE_BGRX101010:
2624 return DRM_FORMAT_XRGB2101010;
2625 case DISPPLANE_RGBX101010:
2626 return DRM_FORMAT_XBGR2101010;
2630 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
2633 case PLANE_CTL_FORMAT_RGB_565:
2634 return DRM_FORMAT_RGB565;
2635 case PLANE_CTL_FORMAT_NV12:
2636 return DRM_FORMAT_NV12;
2638 case PLANE_CTL_FORMAT_XRGB_8888:
2641 return DRM_FORMAT_ABGR8888;
2643 return DRM_FORMAT_XBGR8888;
2646 return DRM_FORMAT_ARGB8888;
2648 return DRM_FORMAT_XRGB8888;
2650 case PLANE_CTL_FORMAT_XRGB_2101010:
2652 return DRM_FORMAT_XBGR2101010;
2654 return DRM_FORMAT_XRGB2101010;
2659 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2660 struct intel_initial_plane_config *plane_config)
2662 struct drm_device *dev = crtc->base.dev;
2663 struct drm_i915_private *dev_priv = to_i915(dev);
2664 struct drm_i915_gem_object *obj = NULL;
2665 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
2666 struct drm_framebuffer *fb = &plane_config->fb->base;
2667 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2668 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2671 size_aligned -= base_aligned;
2673 if (plane_config->size == 0)
2676 /* If the FB is too big, just don't use it since fbdev is not very
2677 * important and we should probably use that space with FBC or other
2679 if (size_aligned * 2 > dev_priv->stolen_usable_size)
2682 switch (fb->modifier) {
2683 case DRM_FORMAT_MOD_LINEAR:
2684 case I915_FORMAT_MOD_X_TILED:
2685 case I915_FORMAT_MOD_Y_TILED:
2688 DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n",
2693 mutex_lock(&dev->struct_mutex);
2694 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
2698 mutex_unlock(&dev->struct_mutex);
2702 switch (plane_config->tiling) {
2703 case I915_TILING_NONE:
2707 obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling;
2710 MISSING_CASE(plane_config->tiling);
2714 mode_cmd.pixel_format = fb->format->format;
2715 mode_cmd.width = fb->width;
2716 mode_cmd.height = fb->height;
2717 mode_cmd.pitches[0] = fb->pitches[0];
2718 mode_cmd.modifier[0] = fb->modifier;
2719 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
2721 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
2722 DRM_DEBUG_KMS("intel fb init failed\n");
2727 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
2731 i915_gem_object_put(obj);
2736 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2737 struct intel_plane_state *plane_state,
2740 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2742 plane_state->base.visible = visible;
2745 crtc_state->base.plane_mask |= drm_plane_mask(&plane->base);
2747 crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base);
2750 static void fixup_active_planes(struct intel_crtc_state *crtc_state)
2752 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
2753 struct drm_plane *plane;
2756 * Active_planes aliases if multiple "primary" or cursor planes
2757 * have been used on the same (or wrong) pipe. plane_mask uses
2758 * unique ids, hence we can use that to reconstruct active_planes.
2760 crtc_state->active_planes = 0;
2762 drm_for_each_plane_mask(plane, &dev_priv->drm,
2763 crtc_state->base.plane_mask)
2764 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
2767 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2768 struct intel_plane *plane)
2770 struct intel_crtc_state *crtc_state =
2771 to_intel_crtc_state(crtc->base.state);
2772 struct intel_plane_state *plane_state =
2773 to_intel_plane_state(plane->base.state);
2775 DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
2776 plane->base.base.id, plane->base.name,
2777 crtc->base.base.id, crtc->base.name);
2779 intel_set_plane_visible(crtc_state, plane_state, false);
2780 fixup_active_planes(crtc_state);
2782 if (plane->id == PLANE_PRIMARY)
2783 intel_pre_disable_primary_noatomic(&crtc->base);
2785 trace_intel_disable_plane(&plane->base, crtc);
2786 plane->disable_plane(plane, crtc_state);
2790 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2791 struct intel_initial_plane_config *plane_config)
2793 struct drm_device *dev = intel_crtc->base.dev;
2794 struct drm_i915_private *dev_priv = to_i915(dev);
2796 struct drm_i915_gem_object *obj;
2797 struct drm_plane *primary = intel_crtc->base.primary;
2798 struct drm_plane_state *plane_state = primary->state;
2799 struct intel_plane *intel_plane = to_intel_plane(primary);
2800 struct intel_plane_state *intel_state =
2801 to_intel_plane_state(plane_state);
2802 struct drm_framebuffer *fb;
2804 if (!plane_config->fb)
2807 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
2808 fb = &plane_config->fb->base;
2812 kfree(plane_config->fb);
2815 * Failed to alloc the obj, check to see if we should share
2816 * an fb with another CRTC instead
2818 for_each_crtc(dev, c) {
2819 struct intel_plane_state *state;
2821 if (c == &intel_crtc->base)
2824 if (!to_intel_crtc(c)->active)
2827 state = to_intel_plane_state(c->primary->state);
2831 if (intel_plane_ggtt_offset(state) == plane_config->base) {
2832 fb = state->base.fb;
2833 drm_framebuffer_get(fb);
2839 * We've failed to reconstruct the BIOS FB. Current display state
2840 * indicates that the primary plane is visible, but has a NULL FB,
2841 * which will lead to problems later if we don't fix it up. The
2842 * simplest solution is to just disable the primary plane now and
2843 * pretend the BIOS never had it enabled.
2845 intel_plane_disable_noatomic(intel_crtc, intel_plane);
2850 intel_state->base.rotation = plane_config->rotation;
2851 intel_fill_fb_ggtt_view(&intel_state->view, fb,
2852 intel_state->base.rotation);
2853 intel_state->color_plane[0].stride =
2854 intel_fb_pitch(fb, 0, intel_state->base.rotation);
2856 mutex_lock(&dev->struct_mutex);
2858 intel_pin_and_fence_fb_obj(fb,
2860 intel_plane_uses_fence(intel_state),
2861 &intel_state->flags);
2862 mutex_unlock(&dev->struct_mutex);
2863 if (IS_ERR(intel_state->vma)) {
2864 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2865 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2867 intel_state->vma = NULL;
2868 drm_framebuffer_put(fb);
2872 obj = intel_fb_obj(fb);
2873 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
2875 plane_state->src_x = 0;
2876 plane_state->src_y = 0;
2877 plane_state->src_w = fb->width << 16;
2878 plane_state->src_h = fb->height << 16;
2880 plane_state->crtc_x = 0;
2881 plane_state->crtc_y = 0;
2882 plane_state->crtc_w = fb->width;
2883 plane_state->crtc_h = fb->height;
2885 intel_state->base.src = drm_plane_state_src(plane_state);
2886 intel_state->base.dst = drm_plane_state_dest(plane_state);
2888 if (i915_gem_object_is_tiled(obj))
2889 dev_priv->preserve_bios_swizzle = true;
2891 plane_state->fb = fb;
2892 plane_state->crtc = &intel_crtc->base;
2894 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2895 &obj->frontbuffer_bits);
2898 static int skl_max_plane_width(const struct drm_framebuffer *fb,
2900 unsigned int rotation)
2902 int cpp = fb->format->cpp[color_plane];
2904 switch (fb->modifier) {
2905 case DRM_FORMAT_MOD_LINEAR:
2906 case I915_FORMAT_MOD_X_TILED:
2919 case I915_FORMAT_MOD_Y_TILED_CCS:
2920 case I915_FORMAT_MOD_Yf_TILED_CCS:
2921 /* FIXME AUX plane? */
2922 case I915_FORMAT_MOD_Y_TILED:
2923 case I915_FORMAT_MOD_Yf_TILED:
2938 MISSING_CASE(fb->modifier);
2944 static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
2945 int main_x, int main_y, u32 main_offset)
2947 const struct drm_framebuffer *fb = plane_state->base.fb;
2948 int hsub = fb->format->hsub;
2949 int vsub = fb->format->vsub;
2950 int aux_x = plane_state->color_plane[1].x;
2951 int aux_y = plane_state->color_plane[1].y;
2952 u32 aux_offset = plane_state->color_plane[1].offset;
2953 u32 alignment = intel_surf_alignment(fb, 1);
2955 while (aux_offset >= main_offset && aux_y <= main_y) {
2958 if (aux_x == main_x && aux_y == main_y)
2961 if (aux_offset == 0)
2966 aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1,
2967 aux_offset, aux_offset - alignment);
2968 aux_x = x * hsub + aux_x % hsub;
2969 aux_y = y * vsub + aux_y % vsub;
2972 if (aux_x != main_x || aux_y != main_y)
2975 plane_state->color_plane[1].offset = aux_offset;
2976 plane_state->color_plane[1].x = aux_x;
2977 plane_state->color_plane[1].y = aux_y;
2982 static int skl_check_main_surface(struct intel_plane_state *plane_state)
2984 const struct drm_framebuffer *fb = plane_state->base.fb;
2985 unsigned int rotation = plane_state->base.rotation;
2986 int x = plane_state->base.src.x1 >> 16;
2987 int y = plane_state->base.src.y1 >> 16;
2988 int w = drm_rect_width(&plane_state->base.src) >> 16;
2989 int h = drm_rect_height(&plane_state->base.src) >> 16;
2990 int max_width = skl_max_plane_width(fb, 0, rotation);
2991 int max_height = 4096;
2992 u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset;
2994 if (w > max_width || h > max_height) {
2995 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
2996 w, h, max_width, max_height);
3000 intel_add_fb_offsets(&x, &y, plane_state, 0);
3001 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
3002 alignment = intel_surf_alignment(fb, 0);
3005 * AUX surface offset is specified as the distance from the
3006 * main surface offset, and it must be non-negative. Make
3007 * sure that is what we will get.
3009 if (offset > aux_offset)
3010 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3011 offset, aux_offset & ~(alignment - 1));
3014 * When using an X-tiled surface, the plane blows up
3015 * if the x offset + width exceed the stride.
3017 * TODO: linear and Y-tiled seem fine, Yf untested,
3019 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3020 int cpp = fb->format->cpp[0];
3022 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
3024 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
3028 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3029 offset, offset - alignment);
3034 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3035 * they match with the main surface x/y offsets.
3037 if (is_ccs_modifier(fb->modifier)) {
3038 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3042 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3043 offset, offset - alignment);
3046 if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) {
3047 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3052 plane_state->color_plane[0].offset = offset;
3053 plane_state->color_plane[0].x = x;
3054 plane_state->color_plane[0].y = y;
3059 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3061 const struct drm_framebuffer *fb = plane_state->base.fb;
3062 unsigned int rotation = plane_state->base.rotation;
3063 int max_width = skl_max_plane_width(fb, 1, rotation);
3064 int max_height = 4096;
3065 int x = plane_state->base.src.x1 >> 17;
3066 int y = plane_state->base.src.y1 >> 17;
3067 int w = drm_rect_width(&plane_state->base.src) >> 17;
3068 int h = drm_rect_height(&plane_state->base.src) >> 17;
3071 intel_add_fb_offsets(&x, &y, plane_state, 1);
3072 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3074 /* FIXME not quite sure how/if these apply to the chroma plane */
3075 if (w > max_width || h > max_height) {
3076 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3077 w, h, max_width, max_height);
3081 plane_state->color_plane[1].offset = offset;
3082 plane_state->color_plane[1].x = x;
3083 plane_state->color_plane[1].y = y;
3088 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3090 const struct drm_framebuffer *fb = plane_state->base.fb;
3091 int src_x = plane_state->base.src.x1 >> 16;
3092 int src_y = plane_state->base.src.y1 >> 16;
3093 int hsub = fb->format->hsub;
3094 int vsub = fb->format->vsub;
3095 int x = src_x / hsub;
3096 int y = src_y / vsub;
3099 intel_add_fb_offsets(&x, &y, plane_state, 1);
3100 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3102 plane_state->color_plane[1].offset = offset;
3103 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3104 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
3109 int skl_check_plane_surface(struct intel_plane_state *plane_state)
3111 const struct drm_framebuffer *fb = plane_state->base.fb;
3112 unsigned int rotation = plane_state->base.rotation;
3115 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
3116 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3117 plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation);
3119 ret = intel_plane_check_stride(plane_state);
3123 if (!plane_state->base.visible)
3126 /* Rotate src coordinates to match rotated GTT view */
3127 if (drm_rotation_90_or_270(rotation))
3128 drm_rect_rotate(&plane_state->base.src,
3129 fb->width << 16, fb->height << 16,
3130 DRM_MODE_ROTATE_270);
3133 * Handle the AUX surface first since
3134 * the main surface setup depends on it.
3136 if (fb->format->format == DRM_FORMAT_NV12) {
3137 ret = skl_check_nv12_aux_surface(plane_state);
3140 } else if (is_ccs_modifier(fb->modifier)) {
3141 ret = skl_check_ccs_aux_surface(plane_state);
3145 plane_state->color_plane[1].offset = ~0xfff;
3146 plane_state->color_plane[1].x = 0;
3147 plane_state->color_plane[1].y = 0;
3150 ret = skl_check_main_surface(plane_state);
3158 i9xx_plane_max_stride(struct intel_plane *plane,
3159 u32 pixel_format, u64 modifier,
3160 unsigned int rotation)
3162 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3164 if (!HAS_GMCH_DISPLAY(dev_priv)) {
3166 } else if (INTEL_GEN(dev_priv) >= 4) {
3167 if (modifier == I915_FORMAT_MOD_X_TILED)
3171 } else if (INTEL_GEN(dev_priv) >= 3) {
3172 if (modifier == I915_FORMAT_MOD_X_TILED)
3177 if (plane->i9xx_plane == PLANE_C)
3184 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3185 const struct intel_plane_state *plane_state)
3187 struct drm_i915_private *dev_priv =
3188 to_i915(plane_state->base.plane->dev);
3189 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3190 const struct drm_framebuffer *fb = plane_state->base.fb;
3191 unsigned int rotation = plane_state->base.rotation;
3194 dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE;
3196 if (IS_G4X(dev_priv) || IS_GEN5(dev_priv) ||
3197 IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
3198 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
3200 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3201 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
3203 if (INTEL_GEN(dev_priv) < 5)
3204 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
3206 switch (fb->format->format) {
3208 dspcntr |= DISPPLANE_8BPP;
3210 case DRM_FORMAT_XRGB1555:
3211 dspcntr |= DISPPLANE_BGRX555;
3213 case DRM_FORMAT_RGB565:
3214 dspcntr |= DISPPLANE_BGRX565;
3216 case DRM_FORMAT_XRGB8888:
3217 dspcntr |= DISPPLANE_BGRX888;
3219 case DRM_FORMAT_XBGR8888:
3220 dspcntr |= DISPPLANE_RGBX888;
3222 case DRM_FORMAT_XRGB2101010:
3223 dspcntr |= DISPPLANE_BGRX101010;
3225 case DRM_FORMAT_XBGR2101010:
3226 dspcntr |= DISPPLANE_RGBX101010;
3229 MISSING_CASE(fb->format->format);
3233 if (INTEL_GEN(dev_priv) >= 4 &&
3234 fb->modifier == I915_FORMAT_MOD_X_TILED)
3235 dspcntr |= DISPPLANE_TILED;
3237 if (rotation & DRM_MODE_ROTATE_180)
3238 dspcntr |= DISPPLANE_ROTATE_180;
3240 if (rotation & DRM_MODE_REFLECT_X)
3241 dspcntr |= DISPPLANE_MIRROR;
3246 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
3248 struct drm_i915_private *dev_priv =
3249 to_i915(plane_state->base.plane->dev);
3250 const struct drm_framebuffer *fb = plane_state->base.fb;
3251 unsigned int rotation = plane_state->base.rotation;
3252 int src_x = plane_state->base.src.x1 >> 16;
3253 int src_y = plane_state->base.src.y1 >> 16;
3257 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
3258 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3260 ret = intel_plane_check_stride(plane_state);
3264 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
3266 if (INTEL_GEN(dev_priv) >= 4)
3267 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
3272 /* HSW/BDW do this automagically in hardware */
3273 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
3274 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3275 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3277 if (rotation & DRM_MODE_ROTATE_180) {
3280 } else if (rotation & DRM_MODE_REFLECT_X) {
3285 plane_state->color_plane[0].offset = offset;
3286 plane_state->color_plane[0].x = src_x;
3287 plane_state->color_plane[0].y = src_y;
3293 i9xx_plane_check(struct intel_crtc_state *crtc_state,
3294 struct intel_plane_state *plane_state)
3298 ret = chv_plane_check_rotation(plane_state);
3302 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
3304 DRM_PLANE_HELPER_NO_SCALING,
3305 DRM_PLANE_HELPER_NO_SCALING,
3310 if (!plane_state->base.visible)
3313 ret = intel_plane_check_src_coordinates(plane_state);
3317 ret = i9xx_check_plane_surface(plane_state);
3321 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
3326 static void i9xx_update_plane(struct intel_plane *plane,
3327 const struct intel_crtc_state *crtc_state,
3328 const struct intel_plane_state *plane_state)
3330 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3331 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3333 u32 dspcntr = plane_state->ctl;
3334 int x = plane_state->color_plane[0].x;
3335 int y = plane_state->color_plane[0].y;
3336 unsigned long irqflags;
3339 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
3341 if (INTEL_GEN(dev_priv) >= 4)
3342 dspaddr_offset = plane_state->color_plane[0].offset;
3344 dspaddr_offset = linear_offset;
3346 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3348 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
3350 if (INTEL_GEN(dev_priv) < 4) {
3351 /* pipesrc and dspsize control the size that is scaled from,
3352 * which should always be the user's requested size.
3354 I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
3355 I915_WRITE_FW(DSPSIZE(i9xx_plane),
3356 ((crtc_state->pipe_src_h - 1) << 16) |
3357 (crtc_state->pipe_src_w - 1));
3358 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
3359 I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
3360 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
3361 ((crtc_state->pipe_src_h - 1) << 16) |
3362 (crtc_state->pipe_src_w - 1));
3363 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
3366 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3367 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
3368 } else if (INTEL_GEN(dev_priv) >= 4) {
3369 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3370 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3374 * The control register self-arms if the plane was previously
3375 * disabled. Try to make the plane enable atomic by writing
3376 * the control register just before the surface register.
3378 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3379 if (INTEL_GEN(dev_priv) >= 4)
3380 I915_WRITE_FW(DSPSURF(i9xx_plane),
3381 intel_plane_ggtt_offset(plane_state) +
3384 I915_WRITE_FW(DSPADDR(i9xx_plane),
3385 intel_plane_ggtt_offset(plane_state) +
3388 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3391 static void i9xx_disable_plane(struct intel_plane *plane,
3392 const struct intel_crtc_state *crtc_state)
3394 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3395 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3396 unsigned long irqflags;
3398 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3400 I915_WRITE_FW(DSPCNTR(i9xx_plane), 0);
3401 if (INTEL_GEN(dev_priv) >= 4)
3402 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
3404 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
3406 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3409 static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
3412 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3413 enum intel_display_power_domain power_domain;
3414 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3419 * Not 100% correct for planes that can move between pipes,
3420 * but that's only the case for gen2-4 which don't have any
3421 * display power wells.
3423 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
3424 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
3427 val = I915_READ(DSPCNTR(i9xx_plane));
3429 ret = val & DISPLAY_PLANE_ENABLE;
3431 if (INTEL_GEN(dev_priv) >= 5)
3432 *pipe = plane->pipe;
3434 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
3435 DISPPLANE_SEL_PIPE_SHIFT;
3437 intel_display_power_put(dev_priv, power_domain);
3443 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
3445 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3448 return intel_tile_width_bytes(fb, color_plane);
3451 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3453 struct drm_device *dev = intel_crtc->base.dev;
3454 struct drm_i915_private *dev_priv = to_i915(dev);
3456 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3457 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3458 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
3462 * This function detaches (aka. unbinds) unused scalers in hardware
3464 static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
3466 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3467 const struct intel_crtc_scaler_state *scaler_state =
3468 &crtc_state->scaler_state;
3471 /* loop through and disable scalers that aren't in use */
3472 for (i = 0; i < intel_crtc->num_scalers; i++) {
3473 if (!scaler_state->scalers[i].in_use)
3474 skl_detach_scaler(intel_crtc, i);
3478 static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
3479 int color_plane, unsigned int rotation)
3482 * The stride is either expressed as a multiple of 64 bytes chunks for
3483 * linear buffers or in number of tiles for tiled buffers.
3485 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3487 else if (drm_rotation_90_or_270(rotation))
3488 return intel_tile_height(fb, color_plane);
3490 return intel_tile_width_bytes(fb, color_plane);
3493 u32 skl_plane_stride(const struct intel_plane_state *plane_state,
3496 const struct drm_framebuffer *fb = plane_state->base.fb;
3497 unsigned int rotation = plane_state->base.rotation;
3498 u32 stride = plane_state->color_plane[color_plane].stride;
3500 if (color_plane >= fb->format->num_planes)
3503 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
3506 static u32 skl_plane_ctl_format(uint32_t pixel_format)
3508 switch (pixel_format) {
3510 return PLANE_CTL_FORMAT_INDEXED;
3511 case DRM_FORMAT_RGB565:
3512 return PLANE_CTL_FORMAT_RGB_565;
3513 case DRM_FORMAT_XBGR8888:
3514 case DRM_FORMAT_ABGR8888:
3515 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
3516 case DRM_FORMAT_XRGB8888:
3517 case DRM_FORMAT_ARGB8888:
3518 return PLANE_CTL_FORMAT_XRGB_8888;
3519 case DRM_FORMAT_XRGB2101010:
3520 return PLANE_CTL_FORMAT_XRGB_2101010;
3521 case DRM_FORMAT_XBGR2101010:
3522 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
3523 case DRM_FORMAT_YUYV:
3524 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
3525 case DRM_FORMAT_YVYU:
3526 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
3527 case DRM_FORMAT_UYVY:
3528 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
3529 case DRM_FORMAT_VYUY:
3530 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
3531 case DRM_FORMAT_NV12:
3532 return PLANE_CTL_FORMAT_NV12;
3534 MISSING_CASE(pixel_format);
3540 static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
3542 if (!plane_state->base.fb->format->has_alpha)
3543 return PLANE_CTL_ALPHA_DISABLE;
3545 switch (plane_state->base.pixel_blend_mode) {
3546 case DRM_MODE_BLEND_PIXEL_NONE:
3547 return PLANE_CTL_ALPHA_DISABLE;
3548 case DRM_MODE_BLEND_PREMULTI:
3549 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
3550 case DRM_MODE_BLEND_COVERAGE:
3551 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
3553 MISSING_CASE(plane_state->base.pixel_blend_mode);
3554 return PLANE_CTL_ALPHA_DISABLE;
3558 static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
3560 if (!plane_state->base.fb->format->has_alpha)
3561 return PLANE_COLOR_ALPHA_DISABLE;
3563 switch (plane_state->base.pixel_blend_mode) {
3564 case DRM_MODE_BLEND_PIXEL_NONE:
3565 return PLANE_COLOR_ALPHA_DISABLE;
3566 case DRM_MODE_BLEND_PREMULTI:
3567 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
3568 case DRM_MODE_BLEND_COVERAGE:
3569 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
3571 MISSING_CASE(plane_state->base.pixel_blend_mode);
3572 return PLANE_COLOR_ALPHA_DISABLE;
3576 static u32 skl_plane_ctl_tiling(uint64_t fb_modifier)
3578 switch (fb_modifier) {
3579 case DRM_FORMAT_MOD_LINEAR:
3581 case I915_FORMAT_MOD_X_TILED:
3582 return PLANE_CTL_TILED_X;
3583 case I915_FORMAT_MOD_Y_TILED:
3584 return PLANE_CTL_TILED_Y;
3585 case I915_FORMAT_MOD_Y_TILED_CCS:
3586 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
3587 case I915_FORMAT_MOD_Yf_TILED:
3588 return PLANE_CTL_TILED_YF;
3589 case I915_FORMAT_MOD_Yf_TILED_CCS:
3590 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
3592 MISSING_CASE(fb_modifier);
3598 static u32 skl_plane_ctl_rotate(unsigned int rotate)
3601 case DRM_MODE_ROTATE_0:
3604 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
3605 * while i915 HW rotation is clockwise, thats why this swapping.
3607 case DRM_MODE_ROTATE_90:
3608 return PLANE_CTL_ROTATE_270;
3609 case DRM_MODE_ROTATE_180:
3610 return PLANE_CTL_ROTATE_180;
3611 case DRM_MODE_ROTATE_270:
3612 return PLANE_CTL_ROTATE_90;
3614 MISSING_CASE(rotate);
3620 static u32 cnl_plane_ctl_flip(unsigned int reflect)
3625 case DRM_MODE_REFLECT_X:
3626 return PLANE_CTL_FLIP_HORIZONTAL;
3627 case DRM_MODE_REFLECT_Y:
3629 MISSING_CASE(reflect);
3635 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3636 const struct intel_plane_state *plane_state)
3638 struct drm_i915_private *dev_priv =
3639 to_i915(plane_state->base.plane->dev);
3640 const struct drm_framebuffer *fb = plane_state->base.fb;
3641 unsigned int rotation = plane_state->base.rotation;
3642 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
3645 plane_ctl = PLANE_CTL_ENABLE;
3647 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
3648 plane_ctl |= skl_plane_ctl_alpha(plane_state);
3650 PLANE_CTL_PIPE_GAMMA_ENABLE |
3651 PLANE_CTL_PIPE_CSC_ENABLE |
3652 PLANE_CTL_PLANE_GAMMA_DISABLE;
3654 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3655 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
3657 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3658 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
3661 plane_ctl |= skl_plane_ctl_format(fb->format->format);
3662 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
3663 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
3665 if (INTEL_GEN(dev_priv) >= 10)
3666 plane_ctl |= cnl_plane_ctl_flip(rotation &
3667 DRM_MODE_REFLECT_MASK);
3669 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3670 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3671 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3672 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3677 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3678 const struct intel_plane_state *plane_state)
3680 struct drm_i915_private *dev_priv =
3681 to_i915(plane_state->base.plane->dev);
3682 const struct drm_framebuffer *fb = plane_state->base.fb;
3683 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
3684 u32 plane_color_ctl = 0;
3686 if (INTEL_GEN(dev_priv) < 11) {
3687 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3688 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3690 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
3691 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
3693 if (fb->format->is_yuv && !icl_is_hdr_plane(plane)) {
3694 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3695 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3697 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
3699 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3700 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
3701 } else if (fb->format->is_yuv) {
3702 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
3705 return plane_color_ctl;
3709 __intel_display_resume(struct drm_device *dev,
3710 struct drm_atomic_state *state,
3711 struct drm_modeset_acquire_ctx *ctx)
3713 struct drm_crtc_state *crtc_state;
3714 struct drm_crtc *crtc;
3717 intel_modeset_setup_hw_state(dev, ctx);
3718 i915_redisable_vga(to_i915(dev));
3724 * We've duplicated the state, pointers to the old state are invalid.
3726 * Don't attempt to use the old state until we commit the duplicated state.
3728 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
3730 * Force recalculation even if we restore
3731 * current state. With fast modeset this may not result
3732 * in a modeset when the state is compatible.
3734 crtc_state->mode_changed = true;
3737 /* ignore any reset values/BIOS leftovers in the WM registers */
3738 if (!HAS_GMCH_DISPLAY(to_i915(dev)))
3739 to_intel_atomic_state(state)->skip_intermediate_wm = true;
3741 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
3743 WARN_ON(ret == -EDEADLK);
3747 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3749 return intel_has_gpu_reset(dev_priv) &&
3750 INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv);
3753 void intel_prepare_reset(struct drm_i915_private *dev_priv)
3755 struct drm_device *dev = &dev_priv->drm;
3756 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3757 struct drm_atomic_state *state;
3760 /* reset doesn't touch the display */
3761 if (!i915_modparams.force_reset_modeset_test &&
3762 !gpu_reset_clobbers_display(dev_priv))
3765 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3766 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3767 wake_up_all(&dev_priv->gpu_error.wait_queue);
3769 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3770 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
3771 i915_gem_set_wedged(dev_priv);
3775 * Need mode_config.mutex so that we don't
3776 * trample ongoing ->detect() and whatnot.
3778 mutex_lock(&dev->mode_config.mutex);
3779 drm_modeset_acquire_init(ctx, 0);
3781 ret = drm_modeset_lock_all_ctx(dev, ctx);
3782 if (ret != -EDEADLK)
3785 drm_modeset_backoff(ctx);
3788 * Disabling the crtcs gracefully seems nicer. Also the
3789 * g33 docs say we should at least disable all the planes.
3791 state = drm_atomic_helper_duplicate_state(dev, ctx);
3792 if (IS_ERR(state)) {
3793 ret = PTR_ERR(state);
3794 DRM_ERROR("Duplicating state failed with %i\n", ret);
3798 ret = drm_atomic_helper_disable_all(dev, ctx);
3800 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
3801 drm_atomic_state_put(state);
3805 dev_priv->modeset_restore_state = state;
3806 state->acquire_ctx = ctx;
3809 void intel_finish_reset(struct drm_i915_private *dev_priv)
3811 struct drm_device *dev = &dev_priv->drm;
3812 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3813 struct drm_atomic_state *state;
3816 /* reset doesn't touch the display */
3817 if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
3820 state = fetch_and_zero(&dev_priv->modeset_restore_state);
3824 /* reset doesn't touch the display */
3825 if (!gpu_reset_clobbers_display(dev_priv)) {
3826 /* for testing only restore the display */
3827 ret = __intel_display_resume(dev, state, ctx);
3829 DRM_ERROR("Restoring old state failed with %i\n", ret);
3832 * The display has been reset as well,
3833 * so need a full re-initialization.
3835 intel_runtime_pm_disable_interrupts(dev_priv);
3836 intel_runtime_pm_enable_interrupts(dev_priv);
3838 intel_pps_unlock_regs_wa(dev_priv);
3839 intel_modeset_init_hw(dev);
3840 intel_init_clock_gating(dev_priv);
3842 spin_lock_irq(&dev_priv->irq_lock);
3843 if (dev_priv->display.hpd_irq_setup)
3844 dev_priv->display.hpd_irq_setup(dev_priv);
3845 spin_unlock_irq(&dev_priv->irq_lock);
3847 ret = __intel_display_resume(dev, state, ctx);
3849 DRM_ERROR("Restoring old state failed with %i\n", ret);
3851 intel_hpd_init(dev_priv);
3854 drm_atomic_state_put(state);
3856 drm_modeset_drop_locks(ctx);
3857 drm_modeset_acquire_fini(ctx);
3858 mutex_unlock(&dev->mode_config.mutex);
3860 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3863 static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
3864 const struct intel_crtc_state *new_crtc_state)
3866 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
3867 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3869 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
3870 crtc->base.mode = new_crtc_state->base.mode;
3873 * Update pipe size and adjust fitter if needed: the reason for this is
3874 * that in compute_mode_changes we check the native mode (not the pfit
3875 * mode) to see if we can flip rather than do a full mode set. In the
3876 * fastboot case, we'll flip, but if we don't update the pipesrc and
3877 * pfit state, we'll end up with a big fb scanned out into the wrong
3881 I915_WRITE(PIPESRC(crtc->pipe),
3882 ((new_crtc_state->pipe_src_w - 1) << 16) |
3883 (new_crtc_state->pipe_src_h - 1));
3885 /* on skylake this is done by detaching scalers */
3886 if (INTEL_GEN(dev_priv) >= 9) {
3887 skl_detach_scalers(new_crtc_state);
3889 if (new_crtc_state->pch_pfit.enabled)
3890 skylake_pfit_enable(new_crtc_state);
3891 } else if (HAS_PCH_SPLIT(dev_priv)) {
3892 if (new_crtc_state->pch_pfit.enabled)
3893 ironlake_pfit_enable(new_crtc_state);
3894 else if (old_crtc_state->pch_pfit.enabled)
3895 ironlake_pfit_disable(old_crtc_state);
3899 static void intel_fdi_normal_train(struct intel_crtc *crtc)
3901 struct drm_device *dev = crtc->base.dev;
3902 struct drm_i915_private *dev_priv = to_i915(dev);
3903 int pipe = crtc->pipe;
3907 /* enable normal train */
3908 reg = FDI_TX_CTL(pipe);
3909 temp = I915_READ(reg);
3910 if (IS_IVYBRIDGE(dev_priv)) {
3911 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
3912 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
3914 temp &= ~FDI_LINK_TRAIN_NONE;
3915 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
3917 I915_WRITE(reg, temp);
3919 reg = FDI_RX_CTL(pipe);
3920 temp = I915_READ(reg);
3921 if (HAS_PCH_CPT(dev_priv)) {
3922 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3923 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
3925 temp &= ~FDI_LINK_TRAIN_NONE;
3926 temp |= FDI_LINK_TRAIN_NONE;
3928 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
3930 /* wait one idle pattern time */
3934 /* IVB wants error correction enabled */
3935 if (IS_IVYBRIDGE(dev_priv))
3936 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
3937 FDI_FE_ERRC_ENABLE);
3940 /* The FDI link training functions for ILK/Ibexpeak. */
3941 static void ironlake_fdi_link_train(struct intel_crtc *crtc,
3942 const struct intel_crtc_state *crtc_state)
3944 struct drm_device *dev = crtc->base.dev;
3945 struct drm_i915_private *dev_priv = to_i915(dev);
3946 int pipe = crtc->pipe;
3950 /* FDI needs bits from pipe first */
3951 assert_pipe_enabled(dev_priv, pipe);
3953 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3955 reg = FDI_RX_IMR(pipe);
3956 temp = I915_READ(reg);
3957 temp &= ~FDI_RX_SYMBOL_LOCK;
3958 temp &= ~FDI_RX_BIT_LOCK;
3959 I915_WRITE(reg, temp);
3963 /* enable CPU FDI TX and PCH FDI RX */
3964 reg = FDI_TX_CTL(pipe);
3965 temp = I915_READ(reg);
3966 temp &= ~FDI_DP_PORT_WIDTH_MASK;
3967 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
3968 temp &= ~FDI_LINK_TRAIN_NONE;
3969 temp |= FDI_LINK_TRAIN_PATTERN_1;
3970 I915_WRITE(reg, temp | FDI_TX_ENABLE);
3972 reg = FDI_RX_CTL(pipe);
3973 temp = I915_READ(reg);
3974 temp &= ~FDI_LINK_TRAIN_NONE;
3975 temp |= FDI_LINK_TRAIN_PATTERN_1;
3976 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3981 /* Ironlake workaround, enable clock pointer after FDI enable*/
3982 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
3983 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
3984 FDI_RX_PHASE_SYNC_POINTER_EN);
3986 reg = FDI_RX_IIR(pipe);
3987 for (tries = 0; tries < 5; tries++) {
3988 temp = I915_READ(reg);
3989 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3991 if ((temp & FDI_RX_BIT_LOCK)) {
3992 DRM_DEBUG_KMS("FDI train 1 done.\n");
3993 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
3998 DRM_ERROR("FDI train 1 fail!\n");
4001 reg = FDI_TX_CTL(pipe);
4002 temp = I915_READ(reg);
4003 temp &= ~FDI_LINK_TRAIN_NONE;
4004 temp |= FDI_LINK_TRAIN_PATTERN_2;
4005 I915_WRITE(reg, temp);
4007 reg = FDI_RX_CTL(pipe);
4008 temp = I915_READ(reg);
4009 temp &= ~FDI_LINK_TRAIN_NONE;
4010 temp |= FDI_LINK_TRAIN_PATTERN_2;
4011 I915_WRITE(reg, temp);
4016 reg = FDI_RX_IIR(pipe);
4017 for (tries = 0; tries < 5; tries++) {
4018 temp = I915_READ(reg);
4019 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4021 if (temp & FDI_RX_SYMBOL_LOCK) {
4022 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4023 DRM_DEBUG_KMS("FDI train 2 done.\n");
4028 DRM_ERROR("FDI train 2 fail!\n");
4030 DRM_DEBUG_KMS("FDI train done\n");
4034 static const int snb_b_fdi_train_param[] = {
4035 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4036 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4037 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4038 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4041 /* The FDI link training functions for SNB/Cougarpoint. */
4042 static void gen6_fdi_link_train(struct intel_crtc *crtc,
4043 const struct intel_crtc_state *crtc_state)
4045 struct drm_device *dev = crtc->base.dev;
4046 struct drm_i915_private *dev_priv = to_i915(dev);
4047 int pipe = crtc->pipe;
4051 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4053 reg = FDI_RX_IMR(pipe);
4054 temp = I915_READ(reg);
4055 temp &= ~FDI_RX_SYMBOL_LOCK;
4056 temp &= ~FDI_RX_BIT_LOCK;
4057 I915_WRITE(reg, temp);
4062 /* enable CPU FDI TX and PCH FDI RX */
4063 reg = FDI_TX_CTL(pipe);
4064 temp = I915_READ(reg);
4065 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4066 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4067 temp &= ~FDI_LINK_TRAIN_NONE;
4068 temp |= FDI_LINK_TRAIN_PATTERN_1;
4069 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4071 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4072 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4074 I915_WRITE(FDI_RX_MISC(pipe),
4075 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4077 reg = FDI_RX_CTL(pipe);
4078 temp = I915_READ(reg);
4079 if (HAS_PCH_CPT(dev_priv)) {
4080 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4081 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4083 temp &= ~FDI_LINK_TRAIN_NONE;
4084 temp |= FDI_LINK_TRAIN_PATTERN_1;
4086 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4091 for (i = 0; i < 4; i++) {
4092 reg = FDI_TX_CTL(pipe);
4093 temp = I915_READ(reg);
4094 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4095 temp |= snb_b_fdi_train_param[i];
4096 I915_WRITE(reg, temp);
4101 for (retry = 0; retry < 5; retry++) {
4102 reg = FDI_RX_IIR(pipe);
4103 temp = I915_READ(reg);
4104 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4105 if (temp & FDI_RX_BIT_LOCK) {
4106 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4107 DRM_DEBUG_KMS("FDI train 1 done.\n");
4116 DRM_ERROR("FDI train 1 fail!\n");
4119 reg = FDI_TX_CTL(pipe);
4120 temp = I915_READ(reg);
4121 temp &= ~FDI_LINK_TRAIN_NONE;
4122 temp |= FDI_LINK_TRAIN_PATTERN_2;
4123 if (IS_GEN6(dev_priv)) {
4124 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4126 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4128 I915_WRITE(reg, temp);
4130 reg = FDI_RX_CTL(pipe);
4131 temp = I915_READ(reg);
4132 if (HAS_PCH_CPT(dev_priv)) {
4133 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4134 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4136 temp &= ~FDI_LINK_TRAIN_NONE;
4137 temp |= FDI_LINK_TRAIN_PATTERN_2;
4139 I915_WRITE(reg, temp);
4144 for (i = 0; i < 4; i++) {
4145 reg = FDI_TX_CTL(pipe);
4146 temp = I915_READ(reg);
4147 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4148 temp |= snb_b_fdi_train_param[i];
4149 I915_WRITE(reg, temp);
4154 for (retry = 0; retry < 5; retry++) {
4155 reg = FDI_RX_IIR(pipe);
4156 temp = I915_READ(reg);
4157 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4158 if (temp & FDI_RX_SYMBOL_LOCK) {
4159 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4160 DRM_DEBUG_KMS("FDI train 2 done.\n");
4169 DRM_ERROR("FDI train 2 fail!\n");
4171 DRM_DEBUG_KMS("FDI train done.\n");
4174 /* Manual link training for Ivy Bridge A0 parts */
4175 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4176 const struct intel_crtc_state *crtc_state)
4178 struct drm_device *dev = crtc->base.dev;
4179 struct drm_i915_private *dev_priv = to_i915(dev);
4180 int pipe = crtc->pipe;
4184 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4186 reg = FDI_RX_IMR(pipe);
4187 temp = I915_READ(reg);
4188 temp &= ~FDI_RX_SYMBOL_LOCK;
4189 temp &= ~FDI_RX_BIT_LOCK;
4190 I915_WRITE(reg, temp);
4195 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4196 I915_READ(FDI_RX_IIR(pipe)));
4198 /* Try each vswing and preemphasis setting twice before moving on */
4199 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4200 /* disable first in case we need to retry */
4201 reg = FDI_TX_CTL(pipe);
4202 temp = I915_READ(reg);
4203 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4204 temp &= ~FDI_TX_ENABLE;
4205 I915_WRITE(reg, temp);
4207 reg = FDI_RX_CTL(pipe);
4208 temp = I915_READ(reg);
4209 temp &= ~FDI_LINK_TRAIN_AUTO;
4210 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4211 temp &= ~FDI_RX_ENABLE;
4212 I915_WRITE(reg, temp);
4214 /* enable CPU FDI TX and PCH FDI RX */
4215 reg = FDI_TX_CTL(pipe);
4216 temp = I915_READ(reg);
4217 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4218 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4219 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
4220 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4221 temp |= snb_b_fdi_train_param[j/2];
4222 temp |= FDI_COMPOSITE_SYNC;
4223 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4225 I915_WRITE(FDI_RX_MISC(pipe),
4226 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4228 reg = FDI_RX_CTL(pipe);
4229 temp = I915_READ(reg);
4230 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4231 temp |= FDI_COMPOSITE_SYNC;
4232 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4235 udelay(1); /* should be 0.5us */
4237 for (i = 0; i < 4; i++) {
4238 reg = FDI_RX_IIR(pipe);
4239 temp = I915_READ(reg);
4240 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4242 if (temp & FDI_RX_BIT_LOCK ||
4243 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4244 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4245 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4249 udelay(1); /* should be 0.5us */
4252 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4257 reg = FDI_TX_CTL(pipe);
4258 temp = I915_READ(reg);
4259 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4260 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4261 I915_WRITE(reg, temp);
4263 reg = FDI_RX_CTL(pipe);
4264 temp = I915_READ(reg);
4265 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4266 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4267 I915_WRITE(reg, temp);
4270 udelay(2); /* should be 1.5us */
4272 for (i = 0; i < 4; i++) {
4273 reg = FDI_RX_IIR(pipe);
4274 temp = I915_READ(reg);
4275 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4277 if (temp & FDI_RX_SYMBOL_LOCK ||
4278 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4279 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4280 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4284 udelay(2); /* should be 1.5us */
4287 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
4291 DRM_DEBUG_KMS("FDI train done.\n");
4294 static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
4296 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4297 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4298 int pipe = intel_crtc->pipe;
4302 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4303 reg = FDI_RX_CTL(pipe);
4304 temp = I915_READ(reg);
4305 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
4306 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4307 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4308 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4313 /* Switch from Rawclk to PCDclk */
4314 temp = I915_READ(reg);
4315 I915_WRITE(reg, temp | FDI_PCDCLK);
4320 /* Enable CPU FDI TX PLL, always on for Ironlake */
4321 reg = FDI_TX_CTL(pipe);
4322 temp = I915_READ(reg);
4323 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4324 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
4331 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4333 struct drm_device *dev = intel_crtc->base.dev;
4334 struct drm_i915_private *dev_priv = to_i915(dev);
4335 int pipe = intel_crtc->pipe;
4339 /* Switch from PCDclk to Rawclk */
4340 reg = FDI_RX_CTL(pipe);
4341 temp = I915_READ(reg);
4342 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4344 /* Disable CPU FDI TX PLL */
4345 reg = FDI_TX_CTL(pipe);
4346 temp = I915_READ(reg);
4347 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4352 reg = FDI_RX_CTL(pipe);
4353 temp = I915_READ(reg);
4354 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4356 /* Wait for the clocks to turn off. */
4361 static void ironlake_fdi_disable(struct drm_crtc *crtc)
4363 struct drm_device *dev = crtc->dev;
4364 struct drm_i915_private *dev_priv = to_i915(dev);
4365 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4366 int pipe = intel_crtc->pipe;
4370 /* disable CPU FDI tx and PCH FDI rx */
4371 reg = FDI_TX_CTL(pipe);
4372 temp = I915_READ(reg);
4373 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4376 reg = FDI_RX_CTL(pipe);
4377 temp = I915_READ(reg);
4378 temp &= ~(0x7 << 16);
4379 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4380 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4385 /* Ironlake workaround, disable clock pointer after downing FDI */
4386 if (HAS_PCH_IBX(dev_priv))
4387 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4389 /* still set train pattern 1 */
4390 reg = FDI_TX_CTL(pipe);
4391 temp = I915_READ(reg);
4392 temp &= ~FDI_LINK_TRAIN_NONE;
4393 temp |= FDI_LINK_TRAIN_PATTERN_1;
4394 I915_WRITE(reg, temp);
4396 reg = FDI_RX_CTL(pipe);
4397 temp = I915_READ(reg);
4398 if (HAS_PCH_CPT(dev_priv)) {
4399 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4400 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4402 temp &= ~FDI_LINK_TRAIN_NONE;
4403 temp |= FDI_LINK_TRAIN_PATTERN_1;
4405 /* BPC in FDI rx is consistent with that in PIPECONF */
4406 temp &= ~(0x07 << 16);
4407 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4408 I915_WRITE(reg, temp);
4414 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
4416 struct drm_crtc *crtc;
4419 drm_for_each_crtc(crtc, &dev_priv->drm) {
4420 struct drm_crtc_commit *commit;
4421 spin_lock(&crtc->commit_lock);
4422 commit = list_first_entry_or_null(&crtc->commit_list,
4423 struct drm_crtc_commit, commit_entry);
4424 cleanup_done = commit ?
4425 try_wait_for_completion(&commit->cleanup_done) : true;
4426 spin_unlock(&crtc->commit_lock);
4431 drm_crtc_wait_one_vblank(crtc);
4439 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
4443 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4445 mutex_lock(&dev_priv->sb_lock);
4447 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4448 temp |= SBI_SSCCTL_DISABLE;
4449 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4451 mutex_unlock(&dev_priv->sb_lock);
4454 /* Program iCLKIP clock to the desired frequency */
4455 static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
4457 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4458 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4459 int clock = crtc_state->base.adjusted_mode.crtc_clock;
4460 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4463 lpt_disable_iclkip(dev_priv);
4465 /* The iCLK virtual clock root frequency is in MHz,
4466 * but the adjusted_mode->crtc_clock in in KHz. To get the
4467 * divisors, it is necessary to divide one by another, so we
4468 * convert the virtual clock precision to KHz here for higher
4471 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
4472 u32 iclk_virtual_root_freq = 172800 * 1000;
4473 u32 iclk_pi_range = 64;
4474 u32 desired_divisor;
4476 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4478 divsel = (desired_divisor / iclk_pi_range) - 2;
4479 phaseinc = desired_divisor % iclk_pi_range;
4482 * Near 20MHz is a corner case which is
4483 * out of range for the 7-bit divisor
4489 /* This should not happen with any sane values */
4490 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
4491 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
4492 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
4493 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
4495 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4502 mutex_lock(&dev_priv->sb_lock);
4504 /* Program SSCDIVINTPHASE6 */
4505 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4506 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
4507 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
4508 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
4509 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
4510 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
4511 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
4512 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
4514 /* Program SSCAUXDIV */
4515 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4516 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4517 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
4518 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
4520 /* Enable modulator and associated divider */
4521 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4522 temp &= ~SBI_SSCCTL_DISABLE;
4523 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4525 mutex_unlock(&dev_priv->sb_lock);
4527 /* Wait for initialization time */
4530 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4533 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
4535 u32 divsel, phaseinc, auxdiv;
4536 u32 iclk_virtual_root_freq = 172800 * 1000;
4537 u32 iclk_pi_range = 64;
4538 u32 desired_divisor;
4541 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
4544 mutex_lock(&dev_priv->sb_lock);
4546 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4547 if (temp & SBI_SSCCTL_DISABLE) {
4548 mutex_unlock(&dev_priv->sb_lock);
4552 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4553 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
4554 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
4555 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
4556 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
4558 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4559 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
4560 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
4562 mutex_unlock(&dev_priv->sb_lock);
4564 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
4566 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4567 desired_divisor << auxdiv);
4570 static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
4571 enum pipe pch_transcoder)
4573 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4574 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4575 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4577 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4578 I915_READ(HTOTAL(cpu_transcoder)));
4579 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4580 I915_READ(HBLANK(cpu_transcoder)));
4581 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4582 I915_READ(HSYNC(cpu_transcoder)));
4584 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4585 I915_READ(VTOTAL(cpu_transcoder)));
4586 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4587 I915_READ(VBLANK(cpu_transcoder)));
4588 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4589 I915_READ(VSYNC(cpu_transcoder)));
4590 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4591 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4594 static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
4598 temp = I915_READ(SOUTH_CHICKEN1);
4599 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
4602 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4603 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4605 temp &= ~FDI_BC_BIFURCATION_SELECT;
4607 temp |= FDI_BC_BIFURCATION_SELECT;
4609 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
4610 I915_WRITE(SOUTH_CHICKEN1, temp);
4611 POSTING_READ(SOUTH_CHICKEN1);
4614 static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
4616 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4617 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4619 switch (crtc->pipe) {
4623 if (crtc_state->fdi_lanes > 2)
4624 cpt_set_fdi_bc_bifurcation(dev_priv, false);
4626 cpt_set_fdi_bc_bifurcation(dev_priv, true);
4630 cpt_set_fdi_bc_bifurcation(dev_priv, true);
4639 * Finds the encoder associated with the given CRTC. This can only be
4640 * used when we know that the CRTC isn't feeding multiple encoders!
4642 static struct intel_encoder *
4643 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
4644 const struct intel_crtc_state *crtc_state)
4646 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4647 const struct drm_connector_state *connector_state;
4648 const struct drm_connector *connector;
4649 struct intel_encoder *encoder = NULL;
4650 int num_encoders = 0;
4653 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4654 if (connector_state->crtc != &crtc->base)
4657 encoder = to_intel_encoder(connector_state->best_encoder);
4661 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
4662 num_encoders, pipe_name(crtc->pipe));
4668 * Enable PCH resources required for PCH ports:
4670 * - FDI training & RX/TX
4671 * - update transcoder timings
4672 * - DP transcoding bits
4675 static void ironlake_pch_enable(const struct intel_atomic_state *state,
4676 const struct intel_crtc_state *crtc_state)
4678 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4679 struct drm_device *dev = crtc->base.dev;
4680 struct drm_i915_private *dev_priv = to_i915(dev);
4681 int pipe = crtc->pipe;
4684 assert_pch_transcoder_disabled(dev_priv, pipe);
4686 if (IS_IVYBRIDGE(dev_priv))
4687 ivybridge_update_fdi_bc_bifurcation(crtc_state);
4689 /* Write the TU size bits before fdi link training, so that error
4690 * detection works. */
4691 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4692 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4694 /* For PCH output, training FDI link */
4695 dev_priv->display.fdi_link_train(crtc, crtc_state);
4697 /* We need to program the right clock selection before writing the pixel
4698 * mutliplier into the DPLL. */
4699 if (HAS_PCH_CPT(dev_priv)) {
4702 temp = I915_READ(PCH_DPLL_SEL);
4703 temp |= TRANS_DPLL_ENABLE(pipe);
4704 sel = TRANS_DPLLB_SEL(pipe);
4705 if (crtc_state->shared_dpll ==
4706 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
4710 I915_WRITE(PCH_DPLL_SEL, temp);
4713 /* XXX: pch pll's can be enabled any time before we enable the PCH
4714 * transcoder, and we actually should do this to not upset any PCH
4715 * transcoder that already use the clock when we share it.
4717 * Note that enable_shared_dpll tries to do the right thing, but
4718 * get_shared_dpll unconditionally resets the pll - we need that to have
4719 * the right LVDS enable sequence. */
4720 intel_enable_shared_dpll(crtc_state);
4722 /* set transcoder timing, panel must allow it */
4723 assert_panel_unlocked(dev_priv, pipe);
4724 ironlake_pch_transcoder_set_timings(crtc_state, pipe);
4726 intel_fdi_normal_train(crtc);
4728 /* For PCH DP, enable TRANS_DP_CTL */
4729 if (HAS_PCH_CPT(dev_priv) &&
4730 intel_crtc_has_dp_encoder(crtc_state)) {
4731 const struct drm_display_mode *adjusted_mode =
4732 &crtc_state->base.adjusted_mode;
4733 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
4734 i915_reg_t reg = TRANS_DP_CTL(pipe);
4737 temp = I915_READ(reg);
4738 temp &= ~(TRANS_DP_PORT_SEL_MASK |
4739 TRANS_DP_SYNC_MASK |
4741 temp |= TRANS_DP_OUTPUT_ENABLE;
4742 temp |= bpc << 9; /* same format but at 11:9 */
4744 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
4745 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
4746 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
4747 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
4749 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
4750 WARN_ON(port < PORT_B || port > PORT_D);
4751 temp |= TRANS_DP_PORT_SEL(port);
4753 I915_WRITE(reg, temp);
4756 ironlake_enable_pch_transcoder(crtc_state);
4759 static void lpt_pch_enable(const struct intel_atomic_state *state,
4760 const struct intel_crtc_state *crtc_state)
4762 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4763 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4764 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4766 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
4768 lpt_program_iclkip(crtc_state);
4770 /* Set transcoder timing. */
4771 ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A);
4773 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
4776 static void cpt_verify_modeset(struct drm_device *dev, int pipe)
4778 struct drm_i915_private *dev_priv = to_i915(dev);
4779 i915_reg_t dslreg = PIPEDSL(pipe);
4782 temp = I915_READ(dslreg);
4784 if (wait_for(I915_READ(dslreg) != temp, 5)) {
4785 if (wait_for(I915_READ(dslreg) != temp, 5))
4786 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
4791 * The hardware phase 0.0 refers to the center of the pixel.
4792 * We want to start from the top/left edge which is phase
4793 * -0.5. That matches how the hardware calculates the scaling
4794 * factors (from top-left of the first pixel to bottom-right
4795 * of the last pixel, as opposed to the pixel centers).
4797 * For 4:2:0 subsampled chroma planes we obviously have to
4798 * adjust that so that the chroma sample position lands in
4801 * Note that for packed YCbCr 4:2:2 formats there is no way to
4802 * control chroma siting. The hardware simply replicates the
4803 * chroma samples for both of the luma samples, and thus we don't
4804 * actually get the expected MPEG2 chroma siting convention :(
4805 * The same behaviour is observed on pre-SKL platforms as well.
4807 * Theory behind the formula (note that we ignore sub-pixel
4808 * source coordinates):
4809 * s = source sample position
4810 * d = destination sample position
4815 * | | 1.5 (initial phase)
4823 * | -0.375 (initial phase)
4830 u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
4832 int phase = -0x8000;
4836 phase += (sub - 1) * 0x8000 / sub;
4838 phase += scale / (2 * sub);
4841 * Hardware initial phase limited to [-0.5:1.5].
4842 * Since the max hardware scale factor is 3.0, we
4843 * should never actually excdeed 1.0 here.
4845 WARN_ON(phase < -0x8000 || phase > 0x18000);
4848 phase = 0x10000 + phase;
4850 trip = PS_PHASE_TRIP;
4852 return ((phase >> 2) & PS_PHASE_MASK) | trip;
4856 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
4857 unsigned int scaler_user, int *scaler_id,
4858 int src_w, int src_h, int dst_w, int dst_h,
4859 const struct drm_format_info *format, bool need_scaler)
4861 struct intel_crtc_scaler_state *scaler_state =
4862 &crtc_state->scaler_state;
4863 struct intel_crtc *intel_crtc =
4864 to_intel_crtc(crtc_state->base.crtc);
4865 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4866 const struct drm_display_mode *adjusted_mode =
4867 &crtc_state->base.adjusted_mode;
4870 * Src coordinates are already rotated by 270 degrees for
4871 * the 90/270 degree plane rotation cases (to match the
4872 * GTT mapping), hence no need to account for rotation here.
4874 if (src_w != dst_w || src_h != dst_h)
4878 * Scaling/fitting not supported in IF-ID mode in GEN9+
4879 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4880 * Once NV12 is enabled, handle it here while allocating scaler
4883 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
4884 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4885 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
4890 * if plane is being disabled or scaler is no more required or force detach
4891 * - free scaler binded to this plane/crtc
4892 * - in order to do this, update crtc->scaler_usage
4894 * Here scaler state in crtc_state is set free so that
4895 * scaler can be assigned to other user. Actual register
4896 * update to free the scaler is done in plane/panel-fit programming.
4897 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4899 if (force_detach || !need_scaler) {
4900 if (*scaler_id >= 0) {
4901 scaler_state->scaler_users &= ~(1 << scaler_user);
4902 scaler_state->scalers[*scaler_id].in_use = 0;
4904 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4905 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4906 intel_crtc->pipe, scaler_user, *scaler_id,
4907 scaler_state->scaler_users);
4913 if (format && format->format == DRM_FORMAT_NV12 &&
4914 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
4915 DRM_DEBUG_KMS("NV12: src dimensions not met\n");
4920 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
4921 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
4922 (IS_GEN11(dev_priv) &&
4923 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
4924 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
4925 (!IS_GEN11(dev_priv) &&
4926 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
4927 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
4928 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4929 "size is out of scaler range\n",
4930 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
4934 /* mark this plane as a scaler user in crtc_state */
4935 scaler_state->scaler_users |= (1 << scaler_user);
4936 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4937 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4938 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
4939 scaler_state->scaler_users);
4945 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4947 * @state: crtc's scaler state
4950 * 0 - scaler_usage updated successfully
4951 * error - requested scaling cannot be supported or other error condition
4953 int skl_update_scaler_crtc(struct intel_crtc_state *state)
4955 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
4956 bool need_scaler = false;
4958 if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
4961 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
4962 &state->scaler_state.scaler_id,
4963 state->pipe_src_w, state->pipe_src_h,
4964 adjusted_mode->crtc_hdisplay,
4965 adjusted_mode->crtc_vdisplay, NULL, need_scaler);
4969 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4970 * @crtc_state: crtc's scaler state
4971 * @plane_state: atomic plane state to update
4974 * 0 - scaler_usage updated successfully
4975 * error - requested scaling cannot be supported or other error condition
4977 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
4978 struct intel_plane_state *plane_state)
4980 struct intel_plane *intel_plane =
4981 to_intel_plane(plane_state->base.plane);
4982 struct drm_framebuffer *fb = plane_state->base.fb;
4984 bool force_detach = !fb || !plane_state->base.visible;
4985 bool need_scaler = false;
4987 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
4988 if (!icl_is_hdr_plane(intel_plane) &&
4989 fb && fb->format->format == DRM_FORMAT_NV12)
4992 ret = skl_update_scaler(crtc_state, force_detach,
4993 drm_plane_index(&intel_plane->base),
4994 &plane_state->scaler_id,
4995 drm_rect_width(&plane_state->base.src) >> 16,
4996 drm_rect_height(&plane_state->base.src) >> 16,
4997 drm_rect_width(&plane_state->base.dst),
4998 drm_rect_height(&plane_state->base.dst),
4999 fb ? fb->format : NULL, need_scaler);
5001 if (ret || plane_state->scaler_id < 0)
5004 /* check colorkey */
5005 if (plane_state->ckey.flags) {
5006 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
5007 intel_plane->base.base.id,
5008 intel_plane->base.name);
5012 /* Check src format */
5013 switch (fb->format->format) {
5014 case DRM_FORMAT_RGB565:
5015 case DRM_FORMAT_XBGR8888:
5016 case DRM_FORMAT_XRGB8888:
5017 case DRM_FORMAT_ABGR8888:
5018 case DRM_FORMAT_ARGB8888:
5019 case DRM_FORMAT_XRGB2101010:
5020 case DRM_FORMAT_XBGR2101010:
5021 case DRM_FORMAT_YUYV:
5022 case DRM_FORMAT_YVYU:
5023 case DRM_FORMAT_UYVY:
5024 case DRM_FORMAT_VYUY:
5025 case DRM_FORMAT_NV12:
5028 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
5029 intel_plane->base.base.id, intel_plane->base.name,
5030 fb->base.id, fb->format->format);
5037 static void skylake_scaler_disable(struct intel_crtc *crtc)
5041 for (i = 0; i < crtc->num_scalers; i++)
5042 skl_detach_scaler(crtc, i);
5045 static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
5047 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5048 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5049 enum pipe pipe = crtc->pipe;
5050 const struct intel_crtc_scaler_state *scaler_state =
5051 &crtc_state->scaler_state;
5053 if (crtc_state->pch_pfit.enabled) {
5054 u16 uv_rgb_hphase, uv_rgb_vphase;
5055 int pfit_w, pfit_h, hscale, vscale;
5058 if (WARN_ON(crtc_state->scaler_state.scaler_id < 0))
5061 pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF;
5062 pfit_h = crtc_state->pch_pfit.size & 0xFFFF;
5064 hscale = (crtc_state->pipe_src_w << 16) / pfit_w;
5065 vscale = (crtc_state->pipe_src_h << 16) / pfit_h;
5067 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
5068 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
5070 id = scaler_state->scaler_id;
5071 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
5072 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
5073 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
5074 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5075 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
5076 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
5077 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos);
5078 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size);
5082 static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state)
5084 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5085 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5086 int pipe = crtc->pipe;
5088 if (crtc_state->pch_pfit.enabled) {
5089 /* Force use of hard-coded filter coefficients
5090 * as some pre-programmed values are broken,
5093 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
5094 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5095 PF_PIPE_SEL_IVB(pipe));
5097 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
5098 I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos);
5099 I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size);
5103 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
5105 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5106 struct drm_device *dev = crtc->base.dev;
5107 struct drm_i915_private *dev_priv = to_i915(dev);
5109 if (!crtc_state->ips_enabled)
5113 * We can only enable IPS after we enable a plane and wait for a vblank
5114 * This function is called from post_plane_update, which is run after
5117 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
5119 if (IS_BROADWELL(dev_priv)) {
5120 mutex_lock(&dev_priv->pcu_lock);
5121 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5122 IPS_ENABLE | IPS_PCODE_CONTROL));
5123 mutex_unlock(&dev_priv->pcu_lock);
5124 /* Quoting Art Runyan: "its not safe to expect any particular
5125 * value in IPS_CTL bit 31 after enabling IPS through the
5126 * mailbox." Moreover, the mailbox may return a bogus state,
5127 * so we need to just enable it and continue on.
5130 I915_WRITE(IPS_CTL, IPS_ENABLE);
5131 /* The bit only becomes 1 in the next vblank, so this wait here
5132 * is essentially intel_wait_for_vblank. If we don't have this
5133 * and don't wait for vblanks until the end of crtc_enable, then
5134 * the HW state readout code will complain that the expected
5135 * IPS_CTL value is not the one we read. */
5136 if (intel_wait_for_register(dev_priv,
5137 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
5139 DRM_ERROR("Timed out waiting for IPS enable\n");
5143 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
5145 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5146 struct drm_device *dev = crtc->base.dev;
5147 struct drm_i915_private *dev_priv = to_i915(dev);
5149 if (!crtc_state->ips_enabled)
5152 if (IS_BROADWELL(dev_priv)) {
5153 mutex_lock(&dev_priv->pcu_lock);
5154 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
5155 mutex_unlock(&dev_priv->pcu_lock);
5157 * Wait for PCODE to finish disabling IPS. The BSpec specified
5158 * 42ms timeout value leads to occasional timeouts so use 100ms
5161 if (intel_wait_for_register(dev_priv,
5162 IPS_CTL, IPS_ENABLE, 0,
5164 DRM_ERROR("Timed out waiting for IPS disable\n");
5166 I915_WRITE(IPS_CTL, 0);
5167 POSTING_READ(IPS_CTL);
5170 /* We need to wait for a vblank before we can disable the plane. */
5171 intel_wait_for_vblank(dev_priv, crtc->pipe);
5174 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
5176 if (intel_crtc->overlay) {
5177 struct drm_device *dev = intel_crtc->base.dev;
5179 mutex_lock(&dev->struct_mutex);
5180 (void) intel_overlay_switch_off(intel_crtc->overlay);
5181 mutex_unlock(&dev->struct_mutex);
5184 /* Let userspace switch the overlay on again. In most cases userspace
5185 * has to recompute where to put it anyway.
5190 * intel_post_enable_primary - Perform operations after enabling primary plane
5191 * @crtc: the CRTC whose primary plane was just enabled
5192 * @new_crtc_state: the enabling state
5194 * Performs potentially sleeping operations that must be done after the primary
5195 * plane is enabled, such as updating FBC and IPS. Note that this may be
5196 * called due to an explicit primary plane update, or due to an implicit
5197 * re-enable that is caused when a sprite plane is updated to no longer
5198 * completely hide the primary plane.
5201 intel_post_enable_primary(struct drm_crtc *crtc,
5202 const struct intel_crtc_state *new_crtc_state)
5204 struct drm_device *dev = crtc->dev;
5205 struct drm_i915_private *dev_priv = to_i915(dev);
5206 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5207 int pipe = intel_crtc->pipe;
5210 * Gen2 reports pipe underruns whenever all planes are disabled.
5211 * So don't enable underrun reporting before at least some planes
5213 * FIXME: Need to fix the logic to work when we turn off all planes
5214 * but leave the pipe running.
5216 if (IS_GEN2(dev_priv))
5217 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5219 /* Underruns don't always raise interrupts, so check manually. */
5220 intel_check_cpu_fifo_underruns(dev_priv);
5221 intel_check_pch_fifo_underruns(dev_priv);
5224 /* FIXME get rid of this and use pre_plane_update */
5226 intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5228 struct drm_device *dev = crtc->dev;
5229 struct drm_i915_private *dev_priv = to_i915(dev);
5230 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5231 int pipe = intel_crtc->pipe;
5234 * Gen2 reports pipe underruns whenever all planes are disabled.
5235 * So disable underrun reporting before all the planes get disabled.
5237 if (IS_GEN2(dev_priv))
5238 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5240 hsw_disable_ips(to_intel_crtc_state(crtc->state));
5243 * Vblank time updates from the shadow to live plane control register
5244 * are blocked if the memory self-refresh mode is active at that
5245 * moment. So to make sure the plane gets truly disabled, disable
5246 * first the self-refresh mode. The self-refresh enable bit in turn
5247 * will be checked/applied by the HW only at the next frame start
5248 * event which is after the vblank start event, so we need to have a
5249 * wait-for-vblank between disabling the plane and the pipe.
5251 if (HAS_GMCH_DISPLAY(dev_priv) &&
5252 intel_set_memory_cxsr(dev_priv, false))
5253 intel_wait_for_vblank(dev_priv, pipe);
5256 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5257 const struct intel_crtc_state *new_crtc_state)
5259 if (!old_crtc_state->ips_enabled)
5262 if (needs_modeset(&new_crtc_state->base))
5265 return !new_crtc_state->ips_enabled;
5268 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5269 const struct intel_crtc_state *new_crtc_state)
5271 if (!new_crtc_state->ips_enabled)
5274 if (needs_modeset(&new_crtc_state->base))
5278 * We can't read out IPS on broadwell, assume the worst and
5279 * forcibly enable IPS on the first fastset.
5281 if (new_crtc_state->update_pipe &&
5282 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5285 return !old_crtc_state->ips_enabled;
5288 static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5289 const struct intel_crtc_state *crtc_state)
5291 if (!crtc_state->nv12_planes)
5294 /* WA Display #0827: Gen9:all */
5295 if (IS_GEN9(dev_priv) && !IS_GEMINILAKE(dev_priv))
5301 static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5303 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5304 struct drm_device *dev = crtc->base.dev;
5305 struct drm_i915_private *dev_priv = to_i915(dev);
5306 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5307 struct intel_crtc_state *pipe_config =
5308 intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
5310 struct drm_plane *primary = crtc->base.primary;
5311 struct drm_plane_state *old_primary_state =
5312 drm_atomic_get_old_plane_state(old_state, primary);
5314 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
5316 if (pipe_config->update_wm_post && pipe_config->base.active)
5317 intel_update_watermarks(crtc);
5319 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5320 hsw_enable_ips(pipe_config);
5322 if (old_primary_state) {
5323 struct drm_plane_state *new_primary_state =
5324 drm_atomic_get_new_plane_state(old_state, primary);
5326 intel_fbc_post_update(crtc);
5328 if (new_primary_state->visible &&
5329 (needs_modeset(&pipe_config->base) ||
5330 !old_primary_state->visible))
5331 intel_post_enable_primary(&crtc->base, pipe_config);
5334 /* Display WA 827 */
5335 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
5336 !needs_nv12_wa(dev_priv, pipe_config)) {
5337 skl_wa_clkgate(dev_priv, crtc->pipe, false);
5341 static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5342 struct intel_crtc_state *pipe_config)
5344 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5345 struct drm_device *dev = crtc->base.dev;
5346 struct drm_i915_private *dev_priv = to_i915(dev);
5347 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5348 struct drm_plane *primary = crtc->base.primary;
5349 struct drm_plane_state *old_primary_state =
5350 drm_atomic_get_old_plane_state(old_state, primary);
5351 bool modeset = needs_modeset(&pipe_config->base);
5352 struct intel_atomic_state *old_intel_state =
5353 to_intel_atomic_state(old_state);
5355 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5356 hsw_disable_ips(old_crtc_state);
5358 if (old_primary_state) {
5359 struct intel_plane_state *new_primary_state =
5360 intel_atomic_get_new_plane_state(old_intel_state,
5361 to_intel_plane(primary));
5363 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
5365 * Gen2 reports pipe underruns whenever all planes are disabled.
5366 * So disable underrun reporting before all the planes get disabled.
5368 if (IS_GEN2(dev_priv) && old_primary_state->visible &&
5369 (modeset || !new_primary_state->base.visible))
5370 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
5373 /* Display WA 827 */
5374 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
5375 needs_nv12_wa(dev_priv, pipe_config)) {
5376 skl_wa_clkgate(dev_priv, crtc->pipe, true);
5380 * Vblank time updates from the shadow to live plane control register
5381 * are blocked if the memory self-refresh mode is active at that
5382 * moment. So to make sure the plane gets truly disabled, disable
5383 * first the self-refresh mode. The self-refresh enable bit in turn
5384 * will be checked/applied by the HW only at the next frame start
5385 * event which is after the vblank start event, so we need to have a
5386 * wait-for-vblank between disabling the plane and the pipe.
5388 if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active &&
5389 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5390 intel_wait_for_vblank(dev_priv, crtc->pipe);
5393 * IVB workaround: must disable low power watermarks for at least
5394 * one frame before enabling scaling. LP watermarks can be re-enabled
5395 * when scaling is disabled.
5397 * WaCxSRDisabledForSpriteScaling:ivb
5399 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) &&
5400 old_crtc_state->base.active)
5401 intel_wait_for_vblank(dev_priv, crtc->pipe);
5404 * If we're doing a modeset, we're done. No need to do any pre-vblank
5405 * watermark programming here.
5407 if (needs_modeset(&pipe_config->base))
5411 * For platforms that support atomic watermarks, program the
5412 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5413 * will be the intermediate values that are safe for both pre- and
5414 * post- vblank; when vblank happens, the 'active' values will be set
5415 * to the final 'target' values and we'll do this again to get the
5416 * optimal watermarks. For gen9+ platforms, the values we program here
5417 * will be the final target values which will get automatically latched
5418 * at vblank time; no further programming will be necessary.
5420 * If a platform hasn't been transitioned to atomic watermarks yet,
5421 * we'll continue to update watermarks the old way, if flags tell
5424 if (dev_priv->display.initial_watermarks != NULL)
5425 dev_priv->display.initial_watermarks(old_intel_state,
5427 else if (pipe_config->update_wm_pre)
5428 intel_update_watermarks(crtc);
5431 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
5432 struct intel_crtc *crtc)
5434 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5435 const struct intel_crtc_state *new_crtc_state =
5436 intel_atomic_get_new_crtc_state(state, crtc);
5437 unsigned int update_mask = new_crtc_state->update_planes;
5438 const struct intel_plane_state *old_plane_state;
5439 struct intel_plane *plane;
5440 unsigned fb_bits = 0;
5443 intel_crtc_dpms_overlay_disable(crtc);
5445 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
5446 if (crtc->pipe != plane->pipe ||
5447 !(update_mask & BIT(plane->id)))
5450 plane->disable_plane(plane, new_crtc_state);
5452 if (old_plane_state->base.visible)
5453 fb_bits |= plane->frontbuffer_bit;
5456 intel_frontbuffer_flip(dev_priv, fb_bits);
5459 static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
5460 struct intel_crtc_state *crtc_state,
5461 struct drm_atomic_state *old_state)
5463 struct drm_connector_state *conn_state;
5464 struct drm_connector *conn;
5467 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5468 struct intel_encoder *encoder =
5469 to_intel_encoder(conn_state->best_encoder);
5471 if (conn_state->crtc != crtc)
5474 if (encoder->pre_pll_enable)
5475 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
5479 static void intel_encoders_pre_enable(struct drm_crtc *crtc,
5480 struct intel_crtc_state *crtc_state,
5481 struct drm_atomic_state *old_state)
5483 struct drm_connector_state *conn_state;
5484 struct drm_connector *conn;
5487 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5488 struct intel_encoder *encoder =
5489 to_intel_encoder(conn_state->best_encoder);
5491 if (conn_state->crtc != crtc)
5494 if (encoder->pre_enable)
5495 encoder->pre_enable(encoder, crtc_state, conn_state);
5499 static void intel_encoders_enable(struct drm_crtc *crtc,
5500 struct intel_crtc_state *crtc_state,
5501 struct drm_atomic_state *old_state)
5503 struct drm_connector_state *conn_state;
5504 struct drm_connector *conn;
5507 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5508 struct intel_encoder *encoder =
5509 to_intel_encoder(conn_state->best_encoder);
5511 if (conn_state->crtc != crtc)
5514 if (encoder->enable)
5515 encoder->enable(encoder, crtc_state, conn_state);
5516 intel_opregion_notify_encoder(encoder, true);
5520 static void intel_encoders_disable(struct drm_crtc *crtc,
5521 struct intel_crtc_state *old_crtc_state,
5522 struct drm_atomic_state *old_state)
5524 struct drm_connector_state *old_conn_state;
5525 struct drm_connector *conn;
5528 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5529 struct intel_encoder *encoder =
5530 to_intel_encoder(old_conn_state->best_encoder);
5532 if (old_conn_state->crtc != crtc)
5535 intel_opregion_notify_encoder(encoder, false);
5536 if (encoder->disable)
5537 encoder->disable(encoder, old_crtc_state, old_conn_state);
5541 static void intel_encoders_post_disable(struct drm_crtc *crtc,
5542 struct intel_crtc_state *old_crtc_state,
5543 struct drm_atomic_state *old_state)
5545 struct drm_connector_state *old_conn_state;
5546 struct drm_connector *conn;
5549 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5550 struct intel_encoder *encoder =
5551 to_intel_encoder(old_conn_state->best_encoder);
5553 if (old_conn_state->crtc != crtc)
5556 if (encoder->post_disable)
5557 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
5561 static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
5562 struct intel_crtc_state *old_crtc_state,
5563 struct drm_atomic_state *old_state)
5565 struct drm_connector_state *old_conn_state;
5566 struct drm_connector *conn;
5569 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5570 struct intel_encoder *encoder =
5571 to_intel_encoder(old_conn_state->best_encoder);
5573 if (old_conn_state->crtc != crtc)
5576 if (encoder->post_pll_disable)
5577 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
5581 static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
5582 struct drm_atomic_state *old_state)
5584 struct drm_crtc *crtc = pipe_config->base.crtc;
5585 struct drm_device *dev = crtc->dev;
5586 struct drm_i915_private *dev_priv = to_i915(dev);
5587 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5588 int pipe = intel_crtc->pipe;
5589 struct intel_atomic_state *old_intel_state =
5590 to_intel_atomic_state(old_state);
5592 if (WARN_ON(intel_crtc->active))
5596 * Sometimes spurious CPU pipe underruns happen during FDI
5597 * training, at least with VGA+HDMI cloning. Suppress them.
5599 * On ILK we get an occasional spurious CPU pipe underruns
5600 * between eDP port A enable and vdd enable. Also PCH port
5601 * enable seems to result in the occasional CPU pipe underrun.
5603 * Spurious PCH underruns also occur during PCH enabling.
5605 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5606 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5608 if (pipe_config->has_pch_encoder)
5609 intel_prepare_shared_dpll(pipe_config);
5611 if (intel_crtc_has_dp_encoder(pipe_config))
5612 intel_dp_set_m_n(pipe_config, M1_N1);
5614 intel_set_pipe_timings(pipe_config);
5615 intel_set_pipe_src_size(pipe_config);
5617 if (pipe_config->has_pch_encoder) {
5618 intel_cpu_transcoder_set_m_n(pipe_config,
5619 &pipe_config->fdi_m_n, NULL);
5622 ironlake_set_pipeconf(pipe_config);
5624 intel_crtc->active = true;
5626 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5628 if (pipe_config->has_pch_encoder) {
5629 /* Note: FDI PLL enabling _must_ be done before we enable the
5630 * cpu pipes, hence this is separate from all the other fdi/pch
5632 ironlake_fdi_pll_enable(pipe_config);
5634 assert_fdi_tx_disabled(dev_priv, pipe);
5635 assert_fdi_rx_disabled(dev_priv, pipe);
5638 ironlake_pfit_enable(pipe_config);
5641 * On ILK+ LUT must be loaded before the pipe is running but with
5644 intel_color_load_luts(&pipe_config->base);
5646 if (dev_priv->display.initial_watermarks != NULL)
5647 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
5648 intel_enable_pipe(pipe_config);
5650 if (pipe_config->has_pch_encoder)
5651 ironlake_pch_enable(old_intel_state, pipe_config);
5653 assert_vblank_disabled(crtc);
5654 drm_crtc_vblank_on(crtc);
5656 intel_encoders_enable(crtc, pipe_config, old_state);
5658 if (HAS_PCH_CPT(dev_priv))
5659 cpt_verify_modeset(dev, intel_crtc->pipe);
5662 * Must wait for vblank to avoid spurious PCH FIFO underruns.
5663 * And a second vblank wait is needed at least on ILK with
5664 * some interlaced HDMI modes. Let's do the double wait always
5665 * in case there are more corner cases we don't know about.
5667 if (pipe_config->has_pch_encoder) {
5668 intel_wait_for_vblank(dev_priv, pipe);
5669 intel_wait_for_vblank(dev_priv, pipe);
5671 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5672 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5675 /* IPS only exists on ULT machines and is tied to pipe A. */
5676 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5678 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
5681 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5682 enum pipe pipe, bool apply)
5684 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
5685 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5692 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
5695 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
5697 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5698 enum pipe pipe = crtc->pipe;
5701 val = MBUS_DBOX_A_CREDIT(2);
5702 val |= MBUS_DBOX_BW_CREDIT(1);
5703 val |= MBUS_DBOX_B_CREDIT(8);
5705 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
5708 static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
5709 struct drm_atomic_state *old_state)
5711 struct drm_crtc *crtc = pipe_config->base.crtc;
5712 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5713 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5714 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
5715 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
5716 struct intel_atomic_state *old_intel_state =
5717 to_intel_atomic_state(old_state);
5718 bool psl_clkgate_wa;
5721 if (WARN_ON(intel_crtc->active))
5724 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
5726 if (pipe_config->shared_dpll)
5727 intel_enable_shared_dpll(pipe_config);
5729 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5731 if (intel_crtc_has_dp_encoder(pipe_config))
5732 intel_dp_set_m_n(pipe_config, M1_N1);
5734 if (!transcoder_is_dsi(cpu_transcoder))
5735 intel_set_pipe_timings(pipe_config);
5737 intel_set_pipe_src_size(pipe_config);
5739 if (cpu_transcoder != TRANSCODER_EDP &&
5740 !transcoder_is_dsi(cpu_transcoder)) {
5741 I915_WRITE(PIPE_MULT(cpu_transcoder),
5742 pipe_config->pixel_multiplier - 1);
5745 if (pipe_config->has_pch_encoder) {
5746 intel_cpu_transcoder_set_m_n(pipe_config,
5747 &pipe_config->fdi_m_n, NULL);
5750 if (!transcoder_is_dsi(cpu_transcoder))
5751 haswell_set_pipeconf(pipe_config);
5753 haswell_set_pipemisc(pipe_config);
5755 intel_color_set_csc(&pipe_config->base);
5757 intel_crtc->active = true;
5759 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
5760 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
5761 pipe_config->pch_pfit.enabled;
5763 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
5765 if (INTEL_GEN(dev_priv) >= 9)
5766 skylake_pfit_enable(pipe_config);
5768 ironlake_pfit_enable(pipe_config);
5771 * On ILK+ LUT must be loaded before the pipe is running but with
5774 intel_color_load_luts(&pipe_config->base);
5777 * Display WA #1153: enable hardware to bypass the alpha math
5778 * and rounding for per-pixel values 00 and 0xff
5780 if (INTEL_GEN(dev_priv) >= 11) {
5781 pipe_chicken = I915_READ(PIPE_CHICKEN(pipe));
5782 if (!(pipe_chicken & PER_PIXEL_ALPHA_BYPASS_EN))
5783 I915_WRITE_FW(PIPE_CHICKEN(pipe),
5784 pipe_chicken | PER_PIXEL_ALPHA_BYPASS_EN);
5787 intel_ddi_set_pipe_settings(pipe_config);
5788 if (!transcoder_is_dsi(cpu_transcoder))
5789 intel_ddi_enable_transcoder_func(pipe_config);
5791 if (dev_priv->display.initial_watermarks != NULL)
5792 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
5794 if (INTEL_GEN(dev_priv) >= 11)
5795 icl_pipe_mbus_enable(intel_crtc);
5797 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5798 if (!transcoder_is_dsi(cpu_transcoder))
5799 intel_enable_pipe(pipe_config);
5801 if (pipe_config->has_pch_encoder)
5802 lpt_pch_enable(old_intel_state, pipe_config);
5804 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST))
5805 intel_ddi_set_vc_payload_alloc(pipe_config, true);
5807 assert_vblank_disabled(crtc);
5808 drm_crtc_vblank_on(crtc);
5810 intel_encoders_enable(crtc, pipe_config, old_state);
5812 if (psl_clkgate_wa) {
5813 intel_wait_for_vblank(dev_priv, pipe);
5814 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
5817 /* If we change the relative order between pipe/planes enabling, we need
5818 * to change the workaround. */
5819 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
5820 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
5821 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5822 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5826 static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
5828 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5829 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5830 enum pipe pipe = crtc->pipe;
5832 /* To avoid upsetting the power well on haswell only disable the pfit if
5833 * it's in use. The hw state code will make sure we get this right. */
5834 if (old_crtc_state->pch_pfit.enabled) {
5835 I915_WRITE(PF_CTL(pipe), 0);
5836 I915_WRITE(PF_WIN_POS(pipe), 0);
5837 I915_WRITE(PF_WIN_SZ(pipe), 0);
5841 static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
5842 struct drm_atomic_state *old_state)
5844 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5845 struct drm_device *dev = crtc->dev;
5846 struct drm_i915_private *dev_priv = to_i915(dev);
5847 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5848 int pipe = intel_crtc->pipe;
5851 * Sometimes spurious CPU pipe underruns happen when the
5852 * pipe is already disabled, but FDI RX/TX is still enabled.
5853 * Happens at least with VGA+HDMI cloning. Suppress them.
5855 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5856 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5858 intel_encoders_disable(crtc, old_crtc_state, old_state);
5860 drm_crtc_vblank_off(crtc);
5861 assert_vblank_disabled(crtc);
5863 intel_disable_pipe(old_crtc_state);
5865 ironlake_pfit_disable(old_crtc_state);
5867 if (old_crtc_state->has_pch_encoder)
5868 ironlake_fdi_disable(crtc);
5870 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5872 if (old_crtc_state->has_pch_encoder) {
5873 ironlake_disable_pch_transcoder(dev_priv, pipe);
5875 if (HAS_PCH_CPT(dev_priv)) {
5879 /* disable TRANS_DP_CTL */
5880 reg = TRANS_DP_CTL(pipe);
5881 temp = I915_READ(reg);
5882 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
5883 TRANS_DP_PORT_SEL_MASK);
5884 temp |= TRANS_DP_PORT_SEL_NONE;
5885 I915_WRITE(reg, temp);
5887 /* disable DPLL_SEL */
5888 temp = I915_READ(PCH_DPLL_SEL);
5889 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
5890 I915_WRITE(PCH_DPLL_SEL, temp);
5893 ironlake_fdi_pll_disable(intel_crtc);
5896 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5897 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5900 static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
5901 struct drm_atomic_state *old_state)
5903 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5904 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5905 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5906 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
5908 intel_encoders_disable(crtc, old_crtc_state, old_state);
5910 drm_crtc_vblank_off(crtc);
5911 assert_vblank_disabled(crtc);
5913 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5914 if (!transcoder_is_dsi(cpu_transcoder))
5915 intel_disable_pipe(old_crtc_state);
5917 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
5918 intel_ddi_set_vc_payload_alloc(old_crtc_state, false);
5920 if (!transcoder_is_dsi(cpu_transcoder))
5921 intel_ddi_disable_transcoder_func(old_crtc_state);
5923 intel_dsc_disable(old_crtc_state);
5925 if (INTEL_GEN(dev_priv) >= 9)
5926 skylake_scaler_disable(intel_crtc);
5928 ironlake_pfit_disable(old_crtc_state);
5930 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5932 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
5935 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
5937 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5938 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5940 if (!crtc_state->gmch_pfit.control)
5944 * The panel fitter should only be adjusted whilst the pipe is disabled,
5945 * according to register description and PRM.
5947 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
5948 assert_pipe_disabled(dev_priv, crtc->pipe);
5950 I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
5951 I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
5953 /* Border color in case we don't scale up to the full screen. Black by
5954 * default, change to something else for debugging. */
5955 I915_WRITE(BCLRPAT(crtc->pipe), 0);
5958 bool intel_port_is_combophy(struct drm_i915_private *dev_priv, enum port port)
5960 if (port == PORT_NONE)
5963 if (IS_ICELAKE(dev_priv))
5964 return port <= PORT_B;
5969 bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port)
5971 if (IS_ICELAKE(dev_priv))
5972 return port >= PORT_C && port <= PORT_F;
5977 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
5979 if (!intel_port_is_tc(dev_priv, port))
5980 return PORT_TC_NONE;
5982 return port - PORT_C;
5985 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
5989 return POWER_DOMAIN_PORT_DDI_A_LANES;
5991 return POWER_DOMAIN_PORT_DDI_B_LANES;
5993 return POWER_DOMAIN_PORT_DDI_C_LANES;
5995 return POWER_DOMAIN_PORT_DDI_D_LANES;
5997 return POWER_DOMAIN_PORT_DDI_E_LANES;
5999 return POWER_DOMAIN_PORT_DDI_F_LANES;
6002 return POWER_DOMAIN_PORT_OTHER;
6006 enum intel_display_power_domain
6007 intel_aux_power_domain(struct intel_digital_port *dig_port)
6009 switch (dig_port->aux_ch) {
6011 return POWER_DOMAIN_AUX_A;
6013 return POWER_DOMAIN_AUX_B;
6015 return POWER_DOMAIN_AUX_C;
6017 return POWER_DOMAIN_AUX_D;
6019 return POWER_DOMAIN_AUX_E;
6021 return POWER_DOMAIN_AUX_F;
6023 MISSING_CASE(dig_port->aux_ch);
6024 return POWER_DOMAIN_AUX_A;
6028 static u64 get_crtc_power_domains(struct drm_crtc *crtc,
6029 struct intel_crtc_state *crtc_state)
6031 struct drm_device *dev = crtc->dev;
6032 struct drm_i915_private *dev_priv = to_i915(dev);
6033 struct drm_encoder *encoder;
6034 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6035 enum pipe pipe = intel_crtc->pipe;
6037 enum transcoder transcoder = crtc_state->cpu_transcoder;
6039 if (!crtc_state->base.active)
6042 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
6043 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
6044 if (crtc_state->pch_pfit.enabled ||
6045 crtc_state->pch_pfit.force_thru)
6046 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
6048 drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
6049 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6051 mask |= BIT_ULL(intel_encoder->power_domain);
6054 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
6055 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
6057 if (crtc_state->shared_dpll)
6058 mask |= BIT_ULL(POWER_DOMAIN_PLLS);
6064 modeset_get_crtc_power_domains(struct drm_crtc *crtc,
6065 struct intel_crtc_state *crtc_state)
6067 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6068 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6069 enum intel_display_power_domain domain;
6070 u64 domains, new_domains, old_domains;
6072 old_domains = intel_crtc->enabled_power_domains;
6073 intel_crtc->enabled_power_domains = new_domains =
6074 get_crtc_power_domains(crtc, crtc_state);
6076 domains = new_domains & ~old_domains;
6078 for_each_power_domain(domain, domains)
6079 intel_display_power_get(dev_priv, domain);
6081 return old_domains & ~new_domains;
6084 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
6087 enum intel_display_power_domain domain;
6089 for_each_power_domain(domain, domains)
6090 intel_display_power_put(dev_priv, domain);
6093 static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
6094 struct drm_atomic_state *old_state)
6096 struct intel_atomic_state *old_intel_state =
6097 to_intel_atomic_state(old_state);
6098 struct drm_crtc *crtc = pipe_config->base.crtc;
6099 struct drm_device *dev = crtc->dev;
6100 struct drm_i915_private *dev_priv = to_i915(dev);
6101 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6102 int pipe = intel_crtc->pipe;
6104 if (WARN_ON(intel_crtc->active))
6107 if (intel_crtc_has_dp_encoder(pipe_config))
6108 intel_dp_set_m_n(pipe_config, M1_N1);
6110 intel_set_pipe_timings(pipe_config);
6111 intel_set_pipe_src_size(pipe_config);
6113 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
6114 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6115 I915_WRITE(CHV_CANVAS(pipe), 0);
6118 i9xx_set_pipeconf(pipe_config);
6120 intel_color_set_csc(&pipe_config->base);
6122 intel_crtc->active = true;
6124 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6126 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
6128 if (IS_CHERRYVIEW(dev_priv)) {
6129 chv_prepare_pll(intel_crtc, pipe_config);
6130 chv_enable_pll(intel_crtc, pipe_config);
6132 vlv_prepare_pll(intel_crtc, pipe_config);
6133 vlv_enable_pll(intel_crtc, pipe_config);
6136 intel_encoders_pre_enable(crtc, pipe_config, old_state);
6138 i9xx_pfit_enable(pipe_config);
6140 intel_color_load_luts(&pipe_config->base);
6142 dev_priv->display.initial_watermarks(old_intel_state,
6144 intel_enable_pipe(pipe_config);
6146 assert_vblank_disabled(crtc);
6147 drm_crtc_vblank_on(crtc);
6149 intel_encoders_enable(crtc, pipe_config, old_state);
6152 static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
6154 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6155 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6157 I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0);
6158 I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1);
6161 static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
6162 struct drm_atomic_state *old_state)
6164 struct intel_atomic_state *old_intel_state =
6165 to_intel_atomic_state(old_state);
6166 struct drm_crtc *crtc = pipe_config->base.crtc;
6167 struct drm_device *dev = crtc->dev;
6168 struct drm_i915_private *dev_priv = to_i915(dev);
6169 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6170 enum pipe pipe = intel_crtc->pipe;
6172 if (WARN_ON(intel_crtc->active))
6175 i9xx_set_pll_dividers(pipe_config);
6177 if (intel_crtc_has_dp_encoder(pipe_config))
6178 intel_dp_set_m_n(pipe_config, M1_N1);
6180 intel_set_pipe_timings(pipe_config);
6181 intel_set_pipe_src_size(pipe_config);
6183 i9xx_set_pipeconf(pipe_config);
6185 intel_crtc->active = true;
6187 if (!IS_GEN2(dev_priv))
6188 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6190 intel_encoders_pre_enable(crtc, pipe_config, old_state);
6192 i9xx_enable_pll(intel_crtc, pipe_config);
6194 i9xx_pfit_enable(pipe_config);
6196 intel_color_load_luts(&pipe_config->base);
6198 if (dev_priv->display.initial_watermarks != NULL)
6199 dev_priv->display.initial_watermarks(old_intel_state,
6202 intel_update_watermarks(intel_crtc);
6203 intel_enable_pipe(pipe_config);
6205 assert_vblank_disabled(crtc);
6206 drm_crtc_vblank_on(crtc);
6208 intel_encoders_enable(crtc, pipe_config, old_state);
6211 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6213 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6214 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6216 if (!old_crtc_state->gmch_pfit.control)
6219 assert_pipe_disabled(dev_priv, crtc->pipe);
6221 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
6222 I915_READ(PFIT_CONTROL));
6223 I915_WRITE(PFIT_CONTROL, 0);
6226 static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6227 struct drm_atomic_state *old_state)
6229 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6230 struct drm_device *dev = crtc->dev;
6231 struct drm_i915_private *dev_priv = to_i915(dev);
6232 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6233 int pipe = intel_crtc->pipe;
6236 * On gen2 planes are double buffered but the pipe isn't, so we must
6237 * wait for planes to fully turn off before disabling the pipe.
6239 if (IS_GEN2(dev_priv))
6240 intel_wait_for_vblank(dev_priv, pipe);
6242 intel_encoders_disable(crtc, old_crtc_state, old_state);
6244 drm_crtc_vblank_off(crtc);
6245 assert_vblank_disabled(crtc);
6247 intel_disable_pipe(old_crtc_state);
6249 i9xx_pfit_disable(old_crtc_state);
6251 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
6253 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
6254 if (IS_CHERRYVIEW(dev_priv))
6255 chv_disable_pll(dev_priv, pipe);
6256 else if (IS_VALLEYVIEW(dev_priv))
6257 vlv_disable_pll(dev_priv, pipe);
6259 i9xx_disable_pll(old_crtc_state);
6262 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
6264 if (!IS_GEN2(dev_priv))
6265 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6267 if (!dev_priv->display.initial_watermarks)
6268 intel_update_watermarks(intel_crtc);
6270 /* clock the pipe down to 640x480@60 to potentially save power */
6271 if (IS_I830(dev_priv))
6272 i830_enable_pipe(dev_priv, pipe);
6275 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
6276 struct drm_modeset_acquire_ctx *ctx)
6278 struct intel_encoder *encoder;
6279 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6280 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6281 enum intel_display_power_domain domain;
6282 struct intel_plane *plane;
6284 struct drm_atomic_state *state;
6285 struct intel_crtc_state *crtc_state;
6288 if (!intel_crtc->active)
6291 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
6292 const struct intel_plane_state *plane_state =
6293 to_intel_plane_state(plane->base.state);
6295 if (plane_state->base.visible)
6296 intel_plane_disable_noatomic(intel_crtc, plane);
6299 state = drm_atomic_state_alloc(crtc->dev);
6301 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
6302 crtc->base.id, crtc->name);
6306 state->acquire_ctx = ctx;
6308 /* Everything's already locked, -EDEADLK can't happen. */
6309 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
6310 ret = drm_atomic_add_affected_connectors(state, crtc);
6312 WARN_ON(IS_ERR(crtc_state) || ret);
6314 dev_priv->display.crtc_disable(crtc_state, state);
6316 drm_atomic_state_put(state);
6318 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6319 crtc->base.id, crtc->name);
6321 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
6322 crtc->state->active = false;
6323 intel_crtc->active = false;
6324 crtc->enabled = false;
6325 crtc->state->connector_mask = 0;
6326 crtc->state->encoder_mask = 0;
6328 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
6329 encoder->base.crtc = NULL;
6331 intel_fbc_disable(intel_crtc);
6332 intel_update_watermarks(intel_crtc);
6333 intel_disable_shared_dpll(to_intel_crtc_state(crtc->state));
6335 domains = intel_crtc->enabled_power_domains;
6336 for_each_power_domain(domain, domains)
6337 intel_display_power_put(dev_priv, domain);
6338 intel_crtc->enabled_power_domains = 0;
6340 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
6341 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
6342 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
6346 * turn all crtc's off, but do not adjust state
6347 * This has to be paired with a call to intel_modeset_setup_hw_state.
6349 int intel_display_suspend(struct drm_device *dev)
6351 struct drm_i915_private *dev_priv = to_i915(dev);
6352 struct drm_atomic_state *state;
6355 state = drm_atomic_helper_suspend(dev);
6356 ret = PTR_ERR_OR_ZERO(state);
6358 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
6360 dev_priv->modeset_restore_state = state;
6364 void intel_encoder_destroy(struct drm_encoder *encoder)
6366 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6368 drm_encoder_cleanup(encoder);
6369 kfree(intel_encoder);
6372 /* Cross check the actual hw state with our own modeset state tracking (and it's
6373 * internal consistency). */
6374 static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
6375 struct drm_connector_state *conn_state)
6377 struct intel_connector *connector = to_intel_connector(conn_state->connector);
6379 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6380 connector->base.base.id,
6381 connector->base.name);
6383 if (connector->get_hw_state(connector)) {
6384 struct intel_encoder *encoder = connector->encoder;
6386 I915_STATE_WARN(!crtc_state,
6387 "connector enabled without attached crtc\n");
6392 I915_STATE_WARN(!crtc_state->active,
6393 "connector is active, but attached crtc isn't\n");
6395 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
6398 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
6399 "atomic encoder doesn't match attached encoder\n");
6401 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
6402 "attached encoder crtc differs from connector crtc\n");
6404 I915_STATE_WARN(crtc_state && crtc_state->active,
6405 "attached crtc is active, but connector isn't\n");
6406 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
6407 "best encoder set without crtc!\n");
6411 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
6413 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6414 return crtc_state->fdi_lanes;
6419 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
6420 struct intel_crtc_state *pipe_config)
6422 struct drm_i915_private *dev_priv = to_i915(dev);
6423 struct drm_atomic_state *state = pipe_config->base.state;
6424 struct intel_crtc *other_crtc;
6425 struct intel_crtc_state *other_crtc_state;
6427 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6428 pipe_name(pipe), pipe_config->fdi_lanes);
6429 if (pipe_config->fdi_lanes > 4) {
6430 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6431 pipe_name(pipe), pipe_config->fdi_lanes);
6435 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
6436 if (pipe_config->fdi_lanes > 2) {
6437 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6438 pipe_config->fdi_lanes);
6445 if (INTEL_INFO(dev_priv)->num_pipes == 2)
6448 /* Ivybridge 3 pipe is really complicated */
6453 if (pipe_config->fdi_lanes <= 2)
6456 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
6458 intel_atomic_get_crtc_state(state, other_crtc);
6459 if (IS_ERR(other_crtc_state))
6460 return PTR_ERR(other_crtc_state);
6462 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
6463 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6464 pipe_name(pipe), pipe_config->fdi_lanes);
6469 if (pipe_config->fdi_lanes > 2) {
6470 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6471 pipe_name(pipe), pipe_config->fdi_lanes);
6475 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
6477 intel_atomic_get_crtc_state(state, other_crtc);
6478 if (IS_ERR(other_crtc_state))
6479 return PTR_ERR(other_crtc_state);
6481 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
6482 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6492 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
6493 struct intel_crtc_state *pipe_config)
6495 struct drm_device *dev = intel_crtc->base.dev;
6496 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6497 int lane, link_bw, fdi_dotclock, ret;
6498 bool needs_recompute = false;
6501 /* FDI is a binary signal running at ~2.7GHz, encoding
6502 * each output octet as 10 bits. The actual frequency
6503 * is stored as a divider into a 100MHz clock, and the
6504 * mode pixel clock is stored in units of 1KHz.
6505 * Hence the bw of each lane in terms of the mode signal
6508 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
6510 fdi_dotclock = adjusted_mode->crtc_clock;
6512 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
6513 pipe_config->pipe_bpp);
6515 pipe_config->fdi_lanes = lane;
6517 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
6518 link_bw, &pipe_config->fdi_m_n, false);
6520 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
6521 if (ret == -EDEADLK)
6524 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
6525 pipe_config->pipe_bpp -= 2*3;
6526 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6527 pipe_config->pipe_bpp);
6528 needs_recompute = true;
6529 pipe_config->bw_constrained = true;
6534 if (needs_recompute)
6540 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
6542 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6543 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6545 /* IPS only exists on ULT machines and is tied to pipe A. */
6546 if (!hsw_crtc_supports_ips(crtc))
6549 if (!i915_modparams.enable_ips)
6552 if (crtc_state->pipe_bpp > 24)
6556 * We compare against max which means we must take
6557 * the increased cdclk requirement into account when
6558 * calculating the new cdclk.
6560 * Should measure whether using a lower cdclk w/o IPS
6562 if (IS_BROADWELL(dev_priv) &&
6563 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6569 static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
6571 struct drm_i915_private *dev_priv =
6572 to_i915(crtc_state->base.crtc->dev);
6573 struct intel_atomic_state *intel_state =
6574 to_intel_atomic_state(crtc_state->base.state);
6576 if (!hsw_crtc_state_ips_capable(crtc_state))
6579 if (crtc_state->ips_force_disable)
6582 /* IPS should be fine as long as at least one plane is enabled. */
6583 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
6586 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6587 if (IS_BROADWELL(dev_priv) &&
6588 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
6594 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6596 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6598 /* GDG double wide on either pipe, otherwise pipe A only */
6599 return INTEL_GEN(dev_priv) < 4 &&
6600 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6603 static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
6605 uint32_t pixel_rate;
6607 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
6610 * We only use IF-ID interlacing. If we ever use
6611 * PF-ID we'll need to adjust the pixel_rate here.
6614 if (pipe_config->pch_pfit.enabled) {
6615 uint64_t pipe_w, pipe_h, pfit_w, pfit_h;
6616 uint32_t pfit_size = pipe_config->pch_pfit.size;
6618 pipe_w = pipe_config->pipe_src_w;
6619 pipe_h = pipe_config->pipe_src_h;
6621 pfit_w = (pfit_size >> 16) & 0xFFFF;
6622 pfit_h = pfit_size & 0xFFFF;
6623 if (pipe_w < pfit_w)
6625 if (pipe_h < pfit_h)
6628 if (WARN_ON(!pfit_w || !pfit_h))
6631 pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h,
6638 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6640 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
6642 if (HAS_GMCH_DISPLAY(dev_priv))
6643 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6644 crtc_state->pixel_rate =
6645 crtc_state->base.adjusted_mode.crtc_clock;
6647 crtc_state->pixel_rate =
6648 ilk_pipe_pixel_rate(crtc_state);
6651 static int intel_crtc_compute_config(struct intel_crtc *crtc,
6652 struct intel_crtc_state *pipe_config)
6654 struct drm_device *dev = crtc->base.dev;
6655 struct drm_i915_private *dev_priv = to_i915(dev);
6656 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6657 int clock_limit = dev_priv->max_dotclk_freq;
6659 if (INTEL_GEN(dev_priv) < 4) {
6660 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
6663 * Enable double wide mode when the dot clock
6664 * is > 90% of the (display) core speed.
6666 if (intel_crtc_supports_double_wide(crtc) &&
6667 adjusted_mode->crtc_clock > clock_limit) {
6668 clock_limit = dev_priv->max_dotclk_freq;
6669 pipe_config->double_wide = true;
6673 if (adjusted_mode->crtc_clock > clock_limit) {
6674 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6675 adjusted_mode->crtc_clock, clock_limit,
6676 yesno(pipe_config->double_wide));
6680 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
6681 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
6682 pipe_config->base.ctm) {
6684 * There is only one pipe CSC unit per pipe, and we need that
6685 * for output conversion from RGB->YCBCR. So if CTM is already
6686 * applied we can't support YCBCR420 output.
6688 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6693 * Pipe horizontal size must be even in:
6695 * - LVDS dual channel mode
6696 * - Double wide pipe
6698 if (pipe_config->pipe_src_w & 1) {
6699 if (pipe_config->double_wide) {
6700 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
6704 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6705 intel_is_dual_link_lvds(dev)) {
6706 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
6711 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6712 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6714 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
6715 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
6718 intel_crtc_compute_pixel_rate(pipe_config);
6720 if (pipe_config->has_pch_encoder)
6721 return ironlake_fdi_compute_config(crtc, pipe_config);
6727 intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
6729 while (*num > DATA_LINK_M_N_MASK ||
6730 *den > DATA_LINK_M_N_MASK) {
6736 static void compute_m_n(unsigned int m, unsigned int n,
6737 uint32_t *ret_m, uint32_t *ret_n,
6741 * Several DP dongles in particular seem to be fussy about
6742 * too large link M/N values. Give N value as 0x8000 that
6743 * should be acceptable by specific devices. 0x8000 is the
6744 * specified fixed N value for asynchronous clock mode,
6745 * which the devices expect also in synchronous clock mode.
6750 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
6752 *ret_m = div_u64((uint64_t) m * *ret_n, n);
6753 intel_reduce_m_n_ratio(ret_m, ret_n);
6757 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
6758 int pixel_clock, int link_clock,
6759 struct intel_link_m_n *m_n,
6764 compute_m_n(bits_per_pixel * pixel_clock,
6765 link_clock * nlanes * 8,
6766 &m_n->gmch_m, &m_n->gmch_n,
6769 compute_m_n(pixel_clock, link_clock,
6770 &m_n->link_m, &m_n->link_n,
6774 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
6776 if (i915_modparams.panel_use_ssc >= 0)
6777 return i915_modparams.panel_use_ssc != 0;
6778 return dev_priv->vbt.lvds_use_ssc
6779 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
6782 static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
6784 return (1 << dpll->n) << 16 | dpll->m2;
6787 static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
6789 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
6792 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
6793 struct intel_crtc_state *crtc_state,
6794 struct dpll *reduced_clock)
6796 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6799 if (IS_PINEVIEW(dev_priv)) {
6800 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
6802 fp2 = pnv_dpll_compute_fp(reduced_clock);
6804 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
6806 fp2 = i9xx_dpll_compute_fp(reduced_clock);
6809 crtc_state->dpll_hw_state.fp0 = fp;
6811 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
6813 crtc_state->dpll_hw_state.fp1 = fp2;
6815 crtc_state->dpll_hw_state.fp1 = fp;
6819 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
6825 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6826 * and set it to a reasonable value instead.
6828 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6829 reg_val &= 0xffffff00;
6830 reg_val |= 0x00000030;
6831 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6833 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6834 reg_val &= 0x00ffffff;
6835 reg_val |= 0x8c000000;
6836 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6838 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6839 reg_val &= 0xffffff00;
6840 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6842 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6843 reg_val &= 0x00ffffff;
6844 reg_val |= 0xb0000000;
6845 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6848 static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
6849 const struct intel_link_m_n *m_n)
6851 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6852 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6853 enum pipe pipe = crtc->pipe;
6855 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6856 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
6857 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
6858 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
6861 static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
6862 enum transcoder transcoder)
6864 if (IS_HASWELL(dev_priv))
6865 return transcoder == TRANSCODER_EDP;
6868 * Strictly speaking some registers are available before
6869 * gen7, but we only support DRRS on gen7+
6871 return IS_GEN7(dev_priv) || IS_CHERRYVIEW(dev_priv);
6874 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
6875 const struct intel_link_m_n *m_n,
6876 const struct intel_link_m_n *m2_n2)
6878 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6879 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6880 enum pipe pipe = crtc->pipe;
6881 enum transcoder transcoder = crtc_state->cpu_transcoder;
6883 if (INTEL_GEN(dev_priv) >= 5) {
6884 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
6885 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
6886 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
6887 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
6889 * M2_N2 registers are set only if DRRS is supported
6890 * (to make sure the registers are not unnecessarily accessed).
6892 if (m2_n2 && crtc_state->has_drrs &&
6893 transcoder_has_m2_n2(dev_priv, transcoder)) {
6894 I915_WRITE(PIPE_DATA_M2(transcoder),
6895 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
6896 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
6897 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
6898 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
6901 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6902 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
6903 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
6904 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
6908 void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n)
6910 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
6913 dp_m_n = &crtc_state->dp_m_n;
6914 dp_m2_n2 = &crtc_state->dp_m2_n2;
6915 } else if (m_n == M2_N2) {
6918 * M2_N2 registers are not supported. Hence m2_n2 divider value
6919 * needs to be programmed into M1_N1.
6921 dp_m_n = &crtc_state->dp_m2_n2;
6923 DRM_ERROR("Unsupported divider value\n");
6927 if (crtc_state->has_pch_encoder)
6928 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
6930 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
6933 static void vlv_compute_dpll(struct intel_crtc *crtc,
6934 struct intel_crtc_state *pipe_config)
6936 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
6937 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
6938 if (crtc->pipe != PIPE_A)
6939 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6941 /* DPLL not used with DSI, but still need the rest set up */
6942 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
6943 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
6944 DPLL_EXT_BUFFER_ENABLE_VLV;
6946 pipe_config->dpll_hw_state.dpll_md =
6947 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6950 static void chv_compute_dpll(struct intel_crtc *crtc,
6951 struct intel_crtc_state *pipe_config)
6953 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
6954 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
6955 if (crtc->pipe != PIPE_A)
6956 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6958 /* DPLL not used with DSI, but still need the rest set up */
6959 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
6960 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
6962 pipe_config->dpll_hw_state.dpll_md =
6963 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6966 static void vlv_prepare_pll(struct intel_crtc *crtc,
6967 const struct intel_crtc_state *pipe_config)
6969 struct drm_device *dev = crtc->base.dev;
6970 struct drm_i915_private *dev_priv = to_i915(dev);
6971 enum pipe pipe = crtc->pipe;
6973 u32 bestn, bestm1, bestm2, bestp1, bestp2;
6974 u32 coreclk, reg_val;
6977 I915_WRITE(DPLL(pipe),
6978 pipe_config->dpll_hw_state.dpll &
6979 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
6981 /* No need to actually set up the DPLL with DSI */
6982 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6985 mutex_lock(&dev_priv->sb_lock);
6987 bestn = pipe_config->dpll.n;
6988 bestm1 = pipe_config->dpll.m1;
6989 bestm2 = pipe_config->dpll.m2;
6990 bestp1 = pipe_config->dpll.p1;
6991 bestp2 = pipe_config->dpll.p2;
6993 /* See eDP HDMI DPIO driver vbios notes doc */
6995 /* PLL B needs special handling */
6997 vlv_pllb_recal_opamp(dev_priv, pipe);
6999 /* Set up Tx target for periodic Rcomp update */
7000 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
7002 /* Disable target IRef on PLL */
7003 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
7004 reg_val &= 0x00ffffff;
7005 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
7007 /* Disable fast lock */
7008 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
7010 /* Set idtafcrecal before PLL is enabled */
7011 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
7012 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
7013 mdiv |= ((bestn << DPIO_N_SHIFT));
7014 mdiv |= (1 << DPIO_K_SHIFT);
7017 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7018 * but we don't support that).
7019 * Note: don't use the DAC post divider as it seems unstable.
7021 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
7022 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7024 mdiv |= DPIO_ENABLE_CALIBRATION;
7025 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7027 /* Set HBR and RBR LPF coefficients */
7028 if (pipe_config->port_clock == 162000 ||
7029 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
7030 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
7031 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7034 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7037 if (intel_crtc_has_dp_encoder(pipe_config)) {
7038 /* Use SSC source */
7040 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7043 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7045 } else { /* HDMI or VGA */
7046 /* Use bend source */
7048 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7051 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7055 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
7056 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
7057 if (intel_crtc_has_dp_encoder(pipe_config))
7058 coreclk |= 0x01000000;
7059 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
7061 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
7062 mutex_unlock(&dev_priv->sb_lock);
7065 static void chv_prepare_pll(struct intel_crtc *crtc,
7066 const struct intel_crtc_state *pipe_config)
7068 struct drm_device *dev = crtc->base.dev;
7069 struct drm_i915_private *dev_priv = to_i915(dev);
7070 enum pipe pipe = crtc->pipe;
7071 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7072 u32 loopfilter, tribuf_calcntr;
7073 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
7077 /* Enable Refclk and SSC */
7078 I915_WRITE(DPLL(pipe),
7079 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
7081 /* No need to actually set up the DPLL with DSI */
7082 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7085 bestn = pipe_config->dpll.n;
7086 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7087 bestm1 = pipe_config->dpll.m1;
7088 bestm2 = pipe_config->dpll.m2 >> 22;
7089 bestp1 = pipe_config->dpll.p1;
7090 bestp2 = pipe_config->dpll.p2;
7091 vco = pipe_config->dpll.vco;
7095 mutex_lock(&dev_priv->sb_lock);
7097 /* p1 and p2 divider */
7098 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7099 5 << DPIO_CHV_S1_DIV_SHIFT |
7100 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
7101 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
7102 1 << DPIO_CHV_K_DIV_SHIFT);
7104 /* Feedback post-divider - m2 */
7105 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7107 /* Feedback refclk divider - n and m1 */
7108 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7109 DPIO_CHV_M1_DIV_BY_2 |
7110 1 << DPIO_CHV_N_DIV_SHIFT);
7112 /* M2 fraction division */
7113 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
7115 /* M2 fraction division enable */
7116 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7117 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7118 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7120 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7121 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
7123 /* Program digital lock detect threshold */
7124 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7125 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7126 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7127 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7129 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7130 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7133 if (vco == 5400000) {
7134 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7135 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7136 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7137 tribuf_calcntr = 0x9;
7138 } else if (vco <= 6200000) {
7139 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7140 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7141 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7142 tribuf_calcntr = 0x9;
7143 } else if (vco <= 6480000) {
7144 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7145 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7146 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7147 tribuf_calcntr = 0x8;
7149 /* Not supported. Apply the same limits as in the max case */
7150 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7151 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7152 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7155 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7157 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
7158 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7159 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7160 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7163 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7164 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7167 mutex_unlock(&dev_priv->sb_lock);
7171 * vlv_force_pll_on - forcibly enable just the PLL
7172 * @dev_priv: i915 private structure
7173 * @pipe: pipe PLL to enable
7174 * @dpll: PLL configuration
7176 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7177 * in cases where we need the PLL enabled even when @pipe is not going to
7180 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
7181 const struct dpll *dpll)
7183 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
7184 struct intel_crtc_state *pipe_config;
7186 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7190 pipe_config->base.crtc = &crtc->base;
7191 pipe_config->pixel_multiplier = 1;
7192 pipe_config->dpll = *dpll;
7194 if (IS_CHERRYVIEW(dev_priv)) {
7195 chv_compute_dpll(crtc, pipe_config);
7196 chv_prepare_pll(crtc, pipe_config);
7197 chv_enable_pll(crtc, pipe_config);
7199 vlv_compute_dpll(crtc, pipe_config);
7200 vlv_prepare_pll(crtc, pipe_config);
7201 vlv_enable_pll(crtc, pipe_config);
7210 * vlv_force_pll_off - forcibly disable just the PLL
7211 * @dev_priv: i915 private structure
7212 * @pipe: pipe PLL to disable
7214 * Disable the PLL for @pipe. To be used in cases where we need
7215 * the PLL enabled even when @pipe is not going to be enabled.
7217 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
7219 if (IS_CHERRYVIEW(dev_priv))
7220 chv_disable_pll(dev_priv, pipe);
7222 vlv_disable_pll(dev_priv, pipe);
7225 static void i9xx_compute_dpll(struct intel_crtc *crtc,
7226 struct intel_crtc_state *crtc_state,
7227 struct dpll *reduced_clock)
7229 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7231 struct dpll *clock = &crtc_state->dpll;
7233 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7235 dpll = DPLL_VGA_MODE_DIS;
7237 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
7238 dpll |= DPLLB_MODE_LVDS;
7240 dpll |= DPLLB_MODE_DAC_SERIAL;
7242 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7243 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7244 dpll |= (crtc_state->pixel_multiplier - 1)
7245 << SDVO_MULTIPLIER_SHIFT_HIRES;
7248 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7249 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
7250 dpll |= DPLL_SDVO_HIGH_SPEED;
7252 if (intel_crtc_has_dp_encoder(crtc_state))
7253 dpll |= DPLL_SDVO_HIGH_SPEED;
7255 /* compute bitmask from p1 value */
7256 if (IS_PINEVIEW(dev_priv))
7257 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7259 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7260 if (IS_G4X(dev_priv) && reduced_clock)
7261 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7263 switch (clock->p2) {
7265 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7268 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7271 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7274 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7277 if (INTEL_GEN(dev_priv) >= 4)
7278 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7280 if (crtc_state->sdvo_tv_clock)
7281 dpll |= PLL_REF_INPUT_TVCLKINBC;
7282 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7283 intel_panel_use_ssc(dev_priv))
7284 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7286 dpll |= PLL_REF_INPUT_DREFCLK;
7288 dpll |= DPLL_VCO_ENABLE;
7289 crtc_state->dpll_hw_state.dpll = dpll;
7291 if (INTEL_GEN(dev_priv) >= 4) {
7292 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
7293 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7294 crtc_state->dpll_hw_state.dpll_md = dpll_md;
7298 static void i8xx_compute_dpll(struct intel_crtc *crtc,
7299 struct intel_crtc_state *crtc_state,
7300 struct dpll *reduced_clock)
7302 struct drm_device *dev = crtc->base.dev;
7303 struct drm_i915_private *dev_priv = to_i915(dev);
7305 struct dpll *clock = &crtc_state->dpll;
7307 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7309 dpll = DPLL_VGA_MODE_DIS;
7311 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7312 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7315 dpll |= PLL_P1_DIVIDE_BY_TWO;
7317 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7319 dpll |= PLL_P2_DIVIDE_BY_4;
7322 if (!IS_I830(dev_priv) &&
7323 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
7324 dpll |= DPLL_DVO_2X_MODE;
7326 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7327 intel_panel_use_ssc(dev_priv))
7328 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7330 dpll |= PLL_REF_INPUT_DREFCLK;
7332 dpll |= DPLL_VCO_ENABLE;
7333 crtc_state->dpll_hw_state.dpll = dpll;
7336 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
7338 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7339 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7340 enum pipe pipe = crtc->pipe;
7341 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
7342 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
7343 uint32_t crtc_vtotal, crtc_vblank_end;
7346 /* We need to be careful not to changed the adjusted mode, for otherwise
7347 * the hw state checker will get angry at the mismatch. */
7348 crtc_vtotal = adjusted_mode->crtc_vtotal;
7349 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
7351 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
7352 /* the chip adds 2 halflines automatically */
7354 crtc_vblank_end -= 1;
7356 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
7357 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7359 vsyncshift = adjusted_mode->crtc_hsync_start -
7360 adjusted_mode->crtc_htotal / 2;
7362 vsyncshift += adjusted_mode->crtc_htotal;
7365 if (INTEL_GEN(dev_priv) > 3)
7366 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
7368 I915_WRITE(HTOTAL(cpu_transcoder),
7369 (adjusted_mode->crtc_hdisplay - 1) |
7370 ((adjusted_mode->crtc_htotal - 1) << 16));
7371 I915_WRITE(HBLANK(cpu_transcoder),
7372 (adjusted_mode->crtc_hblank_start - 1) |
7373 ((adjusted_mode->crtc_hblank_end - 1) << 16));
7374 I915_WRITE(HSYNC(cpu_transcoder),
7375 (adjusted_mode->crtc_hsync_start - 1) |
7376 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7378 I915_WRITE(VTOTAL(cpu_transcoder),
7379 (adjusted_mode->crtc_vdisplay - 1) |
7380 ((crtc_vtotal - 1) << 16));
7381 I915_WRITE(VBLANK(cpu_transcoder),
7382 (adjusted_mode->crtc_vblank_start - 1) |
7383 ((crtc_vblank_end - 1) << 16));
7384 I915_WRITE(VSYNC(cpu_transcoder),
7385 (adjusted_mode->crtc_vsync_start - 1) |
7386 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7388 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7389 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7390 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7392 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
7393 (pipe == PIPE_B || pipe == PIPE_C))
7394 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7398 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
7400 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7401 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7402 enum pipe pipe = crtc->pipe;
7404 /* pipesrc controls the size that is scaled from, which should
7405 * always be the user's requested size.
7407 I915_WRITE(PIPESRC(pipe),
7408 ((crtc_state->pipe_src_w - 1) << 16) |
7409 (crtc_state->pipe_src_h - 1));
7412 static void intel_get_pipe_timings(struct intel_crtc *crtc,
7413 struct intel_crtc_state *pipe_config)
7415 struct drm_device *dev = crtc->base.dev;
7416 struct drm_i915_private *dev_priv = to_i915(dev);
7417 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7420 tmp = I915_READ(HTOTAL(cpu_transcoder));
7421 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7422 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
7423 tmp = I915_READ(HBLANK(cpu_transcoder));
7424 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7425 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
7426 tmp = I915_READ(HSYNC(cpu_transcoder));
7427 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7428 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
7430 tmp = I915_READ(VTOTAL(cpu_transcoder));
7431 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7432 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
7433 tmp = I915_READ(VBLANK(cpu_transcoder));
7434 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7435 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
7436 tmp = I915_READ(VSYNC(cpu_transcoder));
7437 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7438 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
7440 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
7441 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7442 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7443 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
7447 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7448 struct intel_crtc_state *pipe_config)
7450 struct drm_device *dev = crtc->base.dev;
7451 struct drm_i915_private *dev_priv = to_i915(dev);
7454 tmp = I915_READ(PIPESRC(crtc->pipe));
7455 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7456 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7458 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7459 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
7462 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
7463 struct intel_crtc_state *pipe_config)
7465 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7466 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7467 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7468 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
7470 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7471 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7472 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7473 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
7475 mode->flags = pipe_config->base.adjusted_mode.flags;
7476 mode->type = DRM_MODE_TYPE_DRIVER;
7478 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
7480 mode->hsync = drm_mode_hsync(mode);
7481 mode->vrefresh = drm_mode_vrefresh(mode);
7482 drm_mode_set_name(mode);
7485 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
7487 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7488 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7493 /* we keep both pipes enabled on 830 */
7494 if (IS_I830(dev_priv))
7495 pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
7497 if (crtc_state->double_wide)
7498 pipeconf |= PIPECONF_DOUBLE_WIDE;
7500 /* only g4x and later have fancy bpc/dither controls */
7501 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7502 IS_CHERRYVIEW(dev_priv)) {
7503 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7504 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
7505 pipeconf |= PIPECONF_DITHER_EN |
7506 PIPECONF_DITHER_TYPE_SP;
7508 switch (crtc_state->pipe_bpp) {
7510 pipeconf |= PIPECONF_6BPC;
7513 pipeconf |= PIPECONF_8BPC;
7516 pipeconf |= PIPECONF_10BPC;
7519 /* Case prevented by intel_choose_pipe_bpp_dither. */
7524 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
7525 if (INTEL_GEN(dev_priv) < 4 ||
7526 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
7527 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7529 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7531 pipeconf |= PIPECONF_PROGRESSIVE;
7533 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7534 crtc_state->limited_color_range)
7535 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
7537 I915_WRITE(PIPECONF(crtc->pipe), pipeconf);
7538 POSTING_READ(PIPECONF(crtc->pipe));
7541 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
7542 struct intel_crtc_state *crtc_state)
7544 struct drm_device *dev = crtc->base.dev;
7545 struct drm_i915_private *dev_priv = to_i915(dev);
7546 const struct intel_limit *limit;
7549 memset(&crtc_state->dpll_hw_state, 0,
7550 sizeof(crtc_state->dpll_hw_state));
7552 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7553 if (intel_panel_use_ssc(dev_priv)) {
7554 refclk = dev_priv->vbt.lvds_ssc_freq;
7555 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7558 limit = &intel_limits_i8xx_lvds;
7559 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
7560 limit = &intel_limits_i8xx_dvo;
7562 limit = &intel_limits_i8xx_dac;
7565 if (!crtc_state->clock_set &&
7566 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7567 refclk, NULL, &crtc_state->dpll)) {
7568 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7572 i8xx_compute_dpll(crtc, crtc_state, NULL);
7577 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
7578 struct intel_crtc_state *crtc_state)
7580 struct drm_device *dev = crtc->base.dev;
7581 struct drm_i915_private *dev_priv = to_i915(dev);
7582 const struct intel_limit *limit;
7585 memset(&crtc_state->dpll_hw_state, 0,
7586 sizeof(crtc_state->dpll_hw_state));
7588 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7589 if (intel_panel_use_ssc(dev_priv)) {
7590 refclk = dev_priv->vbt.lvds_ssc_freq;
7591 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7594 if (intel_is_dual_link_lvds(dev))
7595 limit = &intel_limits_g4x_dual_channel_lvds;
7597 limit = &intel_limits_g4x_single_channel_lvds;
7598 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
7599 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
7600 limit = &intel_limits_g4x_hdmi;
7601 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
7602 limit = &intel_limits_g4x_sdvo;
7604 /* The option is for other outputs */
7605 limit = &intel_limits_i9xx_sdvo;
7608 if (!crtc_state->clock_set &&
7609 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7610 refclk, NULL, &crtc_state->dpll)) {
7611 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7615 i9xx_compute_dpll(crtc, crtc_state, NULL);
7620 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
7621 struct intel_crtc_state *crtc_state)
7623 struct drm_device *dev = crtc->base.dev;
7624 struct drm_i915_private *dev_priv = to_i915(dev);
7625 const struct intel_limit *limit;
7628 memset(&crtc_state->dpll_hw_state, 0,
7629 sizeof(crtc_state->dpll_hw_state));
7631 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7632 if (intel_panel_use_ssc(dev_priv)) {
7633 refclk = dev_priv->vbt.lvds_ssc_freq;
7634 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7637 limit = &intel_limits_pineview_lvds;
7639 limit = &intel_limits_pineview_sdvo;
7642 if (!crtc_state->clock_set &&
7643 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7644 refclk, NULL, &crtc_state->dpll)) {
7645 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7649 i9xx_compute_dpll(crtc, crtc_state, NULL);
7654 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7655 struct intel_crtc_state *crtc_state)
7657 struct drm_device *dev = crtc->base.dev;
7658 struct drm_i915_private *dev_priv = to_i915(dev);
7659 const struct intel_limit *limit;
7662 memset(&crtc_state->dpll_hw_state, 0,
7663 sizeof(crtc_state->dpll_hw_state));
7665 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7666 if (intel_panel_use_ssc(dev_priv)) {
7667 refclk = dev_priv->vbt.lvds_ssc_freq;
7668 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7671 limit = &intel_limits_i9xx_lvds;
7673 limit = &intel_limits_i9xx_sdvo;
7676 if (!crtc_state->clock_set &&
7677 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7678 refclk, NULL, &crtc_state->dpll)) {
7679 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7683 i9xx_compute_dpll(crtc, crtc_state, NULL);
7688 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
7689 struct intel_crtc_state *crtc_state)
7691 int refclk = 100000;
7692 const struct intel_limit *limit = &intel_limits_chv;
7694 memset(&crtc_state->dpll_hw_state, 0,
7695 sizeof(crtc_state->dpll_hw_state));
7697 if (!crtc_state->clock_set &&
7698 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7699 refclk, NULL, &crtc_state->dpll)) {
7700 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7704 chv_compute_dpll(crtc, crtc_state);
7709 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
7710 struct intel_crtc_state *crtc_state)
7712 int refclk = 100000;
7713 const struct intel_limit *limit = &intel_limits_vlv;
7715 memset(&crtc_state->dpll_hw_state, 0,
7716 sizeof(crtc_state->dpll_hw_state));
7718 if (!crtc_state->clock_set &&
7719 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7720 refclk, NULL, &crtc_state->dpll)) {
7721 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7725 vlv_compute_dpll(crtc, crtc_state);
7730 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
7731 struct intel_crtc_state *pipe_config)
7733 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7736 if (INTEL_GEN(dev_priv) <= 3 &&
7737 (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
7740 tmp = I915_READ(PFIT_CONTROL);
7741 if (!(tmp & PFIT_ENABLE))
7744 /* Check whether the pfit is attached to our pipe. */
7745 if (INTEL_GEN(dev_priv) < 4) {
7746 if (crtc->pipe != PIPE_B)
7749 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7753 pipe_config->gmch_pfit.control = tmp;
7754 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
7757 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
7758 struct intel_crtc_state *pipe_config)
7760 struct drm_device *dev = crtc->base.dev;
7761 struct drm_i915_private *dev_priv = to_i915(dev);
7762 int pipe = pipe_config->cpu_transcoder;
7765 int refclk = 100000;
7767 /* In case of DSI, DPLL will not be used */
7768 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7771 mutex_lock(&dev_priv->sb_lock);
7772 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
7773 mutex_unlock(&dev_priv->sb_lock);
7775 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7776 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7777 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7778 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7779 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7781 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
7785 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
7786 struct intel_initial_plane_config *plane_config)
7788 struct drm_device *dev = crtc->base.dev;
7789 struct drm_i915_private *dev_priv = to_i915(dev);
7790 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
7791 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
7793 u32 val, base, offset;
7794 int fourcc, pixel_format;
7795 unsigned int aligned_height;
7796 struct drm_framebuffer *fb;
7797 struct intel_framebuffer *intel_fb;
7799 if (!plane->get_hw_state(plane, &pipe))
7802 WARN_ON(pipe != crtc->pipe);
7804 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
7806 DRM_DEBUG_KMS("failed to alloc fb\n");
7810 fb = &intel_fb->base;
7814 val = I915_READ(DSPCNTR(i9xx_plane));
7816 if (INTEL_GEN(dev_priv) >= 4) {
7817 if (val & DISPPLANE_TILED) {
7818 plane_config->tiling = I915_TILING_X;
7819 fb->modifier = I915_FORMAT_MOD_X_TILED;
7822 if (val & DISPPLANE_ROTATE_180)
7823 plane_config->rotation = DRM_MODE_ROTATE_180;
7826 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
7827 val & DISPPLANE_MIRROR)
7828 plane_config->rotation |= DRM_MODE_REFLECT_X;
7830 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
7831 fourcc = i9xx_format_to_fourcc(pixel_format);
7832 fb->format = drm_format_info(fourcc);
7834 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7835 offset = I915_READ(DSPOFFSET(i9xx_plane));
7836 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7837 } else if (INTEL_GEN(dev_priv) >= 4) {
7838 if (plane_config->tiling)
7839 offset = I915_READ(DSPTILEOFF(i9xx_plane));
7841 offset = I915_READ(DSPLINOFF(i9xx_plane));
7842 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7844 base = I915_READ(DSPADDR(i9xx_plane));
7846 plane_config->base = base;
7848 val = I915_READ(PIPESRC(pipe));
7849 fb->width = ((val >> 16) & 0xfff) + 1;
7850 fb->height = ((val >> 0) & 0xfff) + 1;
7852 val = I915_READ(DSPSTRIDE(i9xx_plane));
7853 fb->pitches[0] = val & 0xffffffc0;
7855 aligned_height = intel_fb_align_height(fb, 0, fb->height);
7857 plane_config->size = fb->pitches[0] * aligned_height;
7859 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7860 crtc->base.name, plane->base.name, fb->width, fb->height,
7861 fb->format->cpp[0] * 8, base, fb->pitches[0],
7862 plane_config->size);
7864 plane_config->fb = intel_fb;
7867 static void chv_crtc_clock_get(struct intel_crtc *crtc,
7868 struct intel_crtc_state *pipe_config)
7870 struct drm_device *dev = crtc->base.dev;
7871 struct drm_i915_private *dev_priv = to_i915(dev);
7872 int pipe = pipe_config->cpu_transcoder;
7873 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7875 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
7876 int refclk = 100000;
7878 /* In case of DSI, DPLL will not be used */
7879 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7882 mutex_lock(&dev_priv->sb_lock);
7883 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
7884 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
7885 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
7886 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
7887 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7888 mutex_unlock(&dev_priv->sb_lock);
7890 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
7891 clock.m2 = (pll_dw0 & 0xff) << 22;
7892 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
7893 clock.m2 |= pll_dw2 & 0x3fffff;
7894 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
7895 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
7896 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
7898 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
7901 static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc,
7902 struct intel_crtc_state *pipe_config)
7904 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7905 enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB;
7907 pipe_config->lspcon_downsampling = false;
7909 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
7910 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
7912 if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
7913 bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE;
7914 bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND;
7916 if (ycbcr420_enabled) {
7917 /* We support 4:2:0 in full blend mode only */
7919 output = INTEL_OUTPUT_FORMAT_INVALID;
7920 else if (!(IS_GEMINILAKE(dev_priv) ||
7921 INTEL_GEN(dev_priv) >= 10))
7922 output = INTEL_OUTPUT_FORMAT_INVALID;
7924 output = INTEL_OUTPUT_FORMAT_YCBCR420;
7927 * Currently there is no interface defined to
7928 * check user preference between RGB/YCBCR444
7929 * or YCBCR420. So the only possible case for
7930 * YCBCR444 usage is driving YCBCR420 output
7931 * with LSPCON, when pipe is configured for
7932 * YCBCR444 output and LSPCON takes care of
7935 pipe_config->lspcon_downsampling = true;
7936 output = INTEL_OUTPUT_FORMAT_YCBCR444;
7941 pipe_config->output_format = output;
7944 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
7945 struct intel_crtc_state *pipe_config)
7947 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7948 enum intel_display_power_domain power_domain;
7952 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
7953 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
7956 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
7957 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
7958 pipe_config->shared_dpll = NULL;
7962 tmp = I915_READ(PIPECONF(crtc->pipe));
7963 if (!(tmp & PIPECONF_ENABLE))
7966 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7967 IS_CHERRYVIEW(dev_priv)) {
7968 switch (tmp & PIPECONF_BPC_MASK) {
7970 pipe_config->pipe_bpp = 18;
7973 pipe_config->pipe_bpp = 24;
7975 case PIPECONF_10BPC:
7976 pipe_config->pipe_bpp = 30;
7983 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7984 (tmp & PIPECONF_COLOR_RANGE_SELECT))
7985 pipe_config->limited_color_range = true;
7987 if (INTEL_GEN(dev_priv) < 4)
7988 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
7990 intel_get_pipe_timings(crtc, pipe_config);
7991 intel_get_pipe_src_size(crtc, pipe_config);
7993 i9xx_get_pfit_config(crtc, pipe_config);
7995 if (INTEL_GEN(dev_priv) >= 4) {
7996 /* No way to read it out on pipes B and C */
7997 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
7998 tmp = dev_priv->chv_dpll_md[crtc->pipe];
8000 tmp = I915_READ(DPLL_MD(crtc->pipe));
8001 pipe_config->pixel_multiplier =
8002 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
8003 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
8004 pipe_config->dpll_hw_state.dpll_md = tmp;
8005 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
8006 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
8007 tmp = I915_READ(DPLL(crtc->pipe));
8008 pipe_config->pixel_multiplier =
8009 ((tmp & SDVO_MULTIPLIER_MASK)
8010 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
8012 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8013 * port and will be fixed up in the encoder->get_config
8015 pipe_config->pixel_multiplier = 1;
8017 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
8018 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
8020 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
8021 * on 830. Filter it out here so that we don't
8022 * report errors due to that.
8024 if (IS_I830(dev_priv))
8025 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
8027 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
8028 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
8030 /* Mask out read-only status bits. */
8031 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
8032 DPLL_PORTC_READY_MASK |
8033 DPLL_PORTB_READY_MASK);
8036 if (IS_CHERRYVIEW(dev_priv))
8037 chv_crtc_clock_get(crtc, pipe_config);
8038 else if (IS_VALLEYVIEW(dev_priv))
8039 vlv_crtc_clock_get(crtc, pipe_config);
8041 i9xx_crtc_clock_get(crtc, pipe_config);
8044 * Normally the dotclock is filled in by the encoder .get_config()
8045 * but in case the pipe is enabled w/o any ports we need a sane
8048 pipe_config->base.adjusted_mode.crtc_clock =
8049 pipe_config->port_clock / pipe_config->pixel_multiplier;
8054 intel_display_power_put(dev_priv, power_domain);
8059 static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
8061 struct intel_encoder *encoder;
8064 bool has_lvds = false;
8065 bool has_cpu_edp = false;
8066 bool has_panel = false;
8067 bool has_ck505 = false;
8068 bool can_ssc = false;
8069 bool using_ssc_source = false;
8071 /* We need to take the global config into account */
8072 for_each_intel_encoder(&dev_priv->drm, encoder) {
8073 switch (encoder->type) {
8074 case INTEL_OUTPUT_LVDS:
8078 case INTEL_OUTPUT_EDP:
8080 if (encoder->port == PORT_A)
8088 if (HAS_PCH_IBX(dev_priv)) {
8089 has_ck505 = dev_priv->vbt.display_clock_mode;
8090 can_ssc = has_ck505;
8096 /* Check if any DPLLs are using the SSC source */
8097 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
8098 u32 temp = I915_READ(PCH_DPLL(i));
8100 if (!(temp & DPLL_VCO_ENABLE))
8103 if ((temp & PLL_REF_INPUT_MASK) ==
8104 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
8105 using_ssc_source = true;
8110 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
8111 has_panel, has_lvds, has_ck505, using_ssc_source);
8113 /* Ironlake: try to setup display ref clock before DPLL
8114 * enabling. This is only under driver's control after
8115 * PCH B stepping, previous chipset stepping should be
8116 * ignoring this setting.
8118 val = I915_READ(PCH_DREF_CONTROL);
8120 /* As we must carefully and slowly disable/enable each source in turn,
8121 * compute the final state we want first and check if we need to
8122 * make any changes at all.
8125 final &= ~DREF_NONSPREAD_SOURCE_MASK;
8127 final |= DREF_NONSPREAD_CK505_ENABLE;
8129 final |= DREF_NONSPREAD_SOURCE_ENABLE;
8131 final &= ~DREF_SSC_SOURCE_MASK;
8132 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8133 final &= ~DREF_SSC1_ENABLE;
8136 final |= DREF_SSC_SOURCE_ENABLE;
8138 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8139 final |= DREF_SSC1_ENABLE;
8142 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8143 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8145 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8147 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8148 } else if (using_ssc_source) {
8149 final |= DREF_SSC_SOURCE_ENABLE;
8150 final |= DREF_SSC1_ENABLE;
8156 /* Always enable nonspread source */
8157 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8160 val |= DREF_NONSPREAD_CK505_ENABLE;
8162 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8165 val &= ~DREF_SSC_SOURCE_MASK;
8166 val |= DREF_SSC_SOURCE_ENABLE;
8168 /* SSC must be turned on before enabling the CPU output */
8169 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8170 DRM_DEBUG_KMS("Using SSC on panel\n");
8171 val |= DREF_SSC1_ENABLE;
8173 val &= ~DREF_SSC1_ENABLE;
8175 /* Get SSC going before enabling the outputs */
8176 I915_WRITE(PCH_DREF_CONTROL, val);
8177 POSTING_READ(PCH_DREF_CONTROL);
8180 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8182 /* Enable CPU source on CPU attached eDP */
8184 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8185 DRM_DEBUG_KMS("Using SSC on eDP\n");
8186 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8188 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8190 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8192 I915_WRITE(PCH_DREF_CONTROL, val);
8193 POSTING_READ(PCH_DREF_CONTROL);
8196 DRM_DEBUG_KMS("Disabling CPU source output\n");
8198 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8200 /* Turn off CPU output */
8201 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8203 I915_WRITE(PCH_DREF_CONTROL, val);
8204 POSTING_READ(PCH_DREF_CONTROL);
8207 if (!using_ssc_source) {
8208 DRM_DEBUG_KMS("Disabling SSC source\n");
8210 /* Turn off the SSC source */
8211 val &= ~DREF_SSC_SOURCE_MASK;
8212 val |= DREF_SSC_SOURCE_DISABLE;
8215 val &= ~DREF_SSC1_ENABLE;
8217 I915_WRITE(PCH_DREF_CONTROL, val);
8218 POSTING_READ(PCH_DREF_CONTROL);
8223 BUG_ON(val != final);
8226 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
8230 tmp = I915_READ(SOUTH_CHICKEN2);
8231 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
8232 I915_WRITE(SOUTH_CHICKEN2, tmp);
8234 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
8235 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
8236 DRM_ERROR("FDI mPHY reset assert timeout\n");
8238 tmp = I915_READ(SOUTH_CHICKEN2);
8239 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
8240 I915_WRITE(SOUTH_CHICKEN2, tmp);
8242 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
8243 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
8244 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
8247 /* WaMPhyProgramming:hsw */
8248 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
8252 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
8253 tmp &= ~(0xFF << 24);
8254 tmp |= (0x12 << 24);
8255 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
8257 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
8259 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
8261 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
8263 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
8265 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
8266 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8267 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
8269 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
8270 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8271 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
8273 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
8276 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
8278 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
8281 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
8283 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
8286 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
8288 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
8291 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
8293 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
8294 tmp &= ~(0xFF << 16);
8295 tmp |= (0x1C << 16);
8296 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
8298 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
8299 tmp &= ~(0xFF << 16);
8300 tmp |= (0x1C << 16);
8301 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8303 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8305 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
8307 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8309 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
8311 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8312 tmp &= ~(0xF << 28);
8314 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
8316 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8317 tmp &= ~(0xF << 28);
8319 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
8322 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8323 * Programming" based on the parameters passed:
8324 * - Sequence to enable CLKOUT_DP
8325 * - Sequence to enable CLKOUT_DP without spread
8326 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8328 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
8329 bool with_spread, bool with_fdi)
8333 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8335 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
8336 with_fdi, "LP PCH doesn't have FDI\n"))
8339 mutex_lock(&dev_priv->sb_lock);
8341 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8342 tmp &= ~SBI_SSCCTL_DISABLE;
8343 tmp |= SBI_SSCCTL_PATHALT;
8344 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8349 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8350 tmp &= ~SBI_SSCCTL_PATHALT;
8351 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8354 lpt_reset_fdi_mphy(dev_priv);
8355 lpt_program_fdi_mphy(dev_priv);
8359 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8360 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8361 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8362 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8364 mutex_unlock(&dev_priv->sb_lock);
8367 /* Sequence to disable CLKOUT_DP */
8368 static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
8372 mutex_lock(&dev_priv->sb_lock);
8374 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8375 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8376 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8377 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8379 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8380 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8381 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8382 tmp |= SBI_SSCCTL_PATHALT;
8383 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8386 tmp |= SBI_SSCCTL_DISABLE;
8387 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8390 mutex_unlock(&dev_priv->sb_lock);
8393 #define BEND_IDX(steps) ((50 + (steps)) / 5)
8395 static const uint16_t sscdivintphase[] = {
8396 [BEND_IDX( 50)] = 0x3B23,
8397 [BEND_IDX( 45)] = 0x3B23,
8398 [BEND_IDX( 40)] = 0x3C23,
8399 [BEND_IDX( 35)] = 0x3C23,
8400 [BEND_IDX( 30)] = 0x3D23,
8401 [BEND_IDX( 25)] = 0x3D23,
8402 [BEND_IDX( 20)] = 0x3E23,
8403 [BEND_IDX( 15)] = 0x3E23,
8404 [BEND_IDX( 10)] = 0x3F23,
8405 [BEND_IDX( 5)] = 0x3F23,
8406 [BEND_IDX( 0)] = 0x0025,
8407 [BEND_IDX( -5)] = 0x0025,
8408 [BEND_IDX(-10)] = 0x0125,
8409 [BEND_IDX(-15)] = 0x0125,
8410 [BEND_IDX(-20)] = 0x0225,
8411 [BEND_IDX(-25)] = 0x0225,
8412 [BEND_IDX(-30)] = 0x0325,
8413 [BEND_IDX(-35)] = 0x0325,
8414 [BEND_IDX(-40)] = 0x0425,
8415 [BEND_IDX(-45)] = 0x0425,
8416 [BEND_IDX(-50)] = 0x0525,
8421 * steps -50 to 50 inclusive, in steps of 5
8422 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8423 * change in clock period = -(steps / 10) * 5.787 ps
8425 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
8428 int idx = BEND_IDX(steps);
8430 if (WARN_ON(steps % 5 != 0))
8433 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
8436 mutex_lock(&dev_priv->sb_lock);
8438 if (steps % 10 != 0)
8442 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
8444 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
8446 tmp |= sscdivintphase[idx];
8447 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
8449 mutex_unlock(&dev_priv->sb_lock);
8454 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
8456 struct intel_encoder *encoder;
8457 bool has_vga = false;
8459 for_each_intel_encoder(&dev_priv->drm, encoder) {
8460 switch (encoder->type) {
8461 case INTEL_OUTPUT_ANALOG:
8470 lpt_bend_clkout_dp(dev_priv, 0);
8471 lpt_enable_clkout_dp(dev_priv, true, true);
8473 lpt_disable_clkout_dp(dev_priv);
8478 * Initialize reference clocks when the driver loads
8480 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
8482 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
8483 ironlake_init_pch_refclk(dev_priv);
8484 else if (HAS_PCH_LPT(dev_priv))
8485 lpt_init_pch_refclk(dev_priv);
8488 static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
8490 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8491 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8492 enum pipe pipe = crtc->pipe;
8497 switch (crtc_state->pipe_bpp) {
8499 val |= PIPECONF_6BPC;
8502 val |= PIPECONF_8BPC;
8505 val |= PIPECONF_10BPC;
8508 val |= PIPECONF_12BPC;
8511 /* Case prevented by intel_choose_pipe_bpp_dither. */
8515 if (crtc_state->dither)
8516 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8518 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8519 val |= PIPECONF_INTERLACED_ILK;
8521 val |= PIPECONF_PROGRESSIVE;
8523 if (crtc_state->limited_color_range)
8524 val |= PIPECONF_COLOR_RANGE_SELECT;
8526 I915_WRITE(PIPECONF(pipe), val);
8527 POSTING_READ(PIPECONF(pipe));
8530 static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state)
8532 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8533 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8534 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8537 if (IS_HASWELL(dev_priv) && crtc_state->dither)
8538 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8540 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8541 val |= PIPECONF_INTERLACED_ILK;
8543 val |= PIPECONF_PROGRESSIVE;
8545 I915_WRITE(PIPECONF(cpu_transcoder), val);
8546 POSTING_READ(PIPECONF(cpu_transcoder));
8549 static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state)
8551 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
8552 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
8554 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
8557 switch (crtc_state->pipe_bpp) {
8559 val |= PIPEMISC_DITHER_6_BPC;
8562 val |= PIPEMISC_DITHER_8_BPC;
8565 val |= PIPEMISC_DITHER_10_BPC;
8568 val |= PIPEMISC_DITHER_12_BPC;
8571 /* Case prevented by pipe_config_set_bpp. */
8575 if (crtc_state->dither)
8576 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8578 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
8579 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
8580 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
8582 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
8583 val |= PIPEMISC_YUV420_ENABLE |
8584 PIPEMISC_YUV420_MODE_FULL_BLEND;
8586 I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
8590 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8593 * Account for spread spectrum to avoid
8594 * oversubscribing the link. Max center spread
8595 * is 2.5%; use 5% for safety's sake.
8597 u32 bps = target_clock * bpp * 21 / 20;
8598 return DIV_ROUND_UP(bps, link_bw * 8);
8601 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
8603 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
8606 static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8607 struct intel_crtc_state *crtc_state,
8608 struct dpll *reduced_clock)
8610 struct drm_crtc *crtc = &intel_crtc->base;
8611 struct drm_device *dev = crtc->dev;
8612 struct drm_i915_private *dev_priv = to_i915(dev);
8616 /* Enable autotuning of the PLL clock (if permissible) */
8618 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8619 if ((intel_panel_use_ssc(dev_priv) &&
8620 dev_priv->vbt.lvds_ssc_freq == 100000) ||
8621 (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
8623 } else if (crtc_state->sdvo_tv_clock)
8626 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
8628 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8631 if (reduced_clock) {
8632 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8634 if (reduced_clock->m < factor * reduced_clock->n)
8642 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8643 dpll |= DPLLB_MODE_LVDS;
8645 dpll |= DPLLB_MODE_DAC_SERIAL;
8647 dpll |= (crtc_state->pixel_multiplier - 1)
8648 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
8650 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8651 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8652 dpll |= DPLL_SDVO_HIGH_SPEED;
8654 if (intel_crtc_has_dp_encoder(crtc_state))
8655 dpll |= DPLL_SDVO_HIGH_SPEED;
8658 * The high speed IO clock is only really required for
8659 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8660 * possible to share the DPLL between CRT and HDMI. Enabling
8661 * the clock needlessly does no real harm, except use up a
8662 * bit of power potentially.
8664 * We'll limit this to IVB with 3 pipes, since it has only two
8665 * DPLLs and so DPLL sharing is the only way to get three pipes
8666 * driving PCH ports at the same time. On SNB we could do this,
8667 * and potentially avoid enabling the second DPLL, but it's not
8668 * clear if it''s a win or loss power wise. No point in doing
8669 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8671 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
8672 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
8673 dpll |= DPLL_SDVO_HIGH_SPEED;
8675 /* compute bitmask from p1 value */
8676 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8678 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8680 switch (crtc_state->dpll.p2) {
8682 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8685 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8688 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8691 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8695 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8696 intel_panel_use_ssc(dev_priv))
8697 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8699 dpll |= PLL_REF_INPUT_DREFCLK;
8701 dpll |= DPLL_VCO_ENABLE;
8703 crtc_state->dpll_hw_state.dpll = dpll;
8704 crtc_state->dpll_hw_state.fp0 = fp;
8705 crtc_state->dpll_hw_state.fp1 = fp2;
8708 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8709 struct intel_crtc_state *crtc_state)
8711 struct drm_device *dev = crtc->base.dev;
8712 struct drm_i915_private *dev_priv = to_i915(dev);
8713 const struct intel_limit *limit;
8714 int refclk = 120000;
8716 memset(&crtc_state->dpll_hw_state, 0,
8717 sizeof(crtc_state->dpll_hw_state));
8719 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8720 if (!crtc_state->has_pch_encoder)
8723 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8724 if (intel_panel_use_ssc(dev_priv)) {
8725 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8726 dev_priv->vbt.lvds_ssc_freq);
8727 refclk = dev_priv->vbt.lvds_ssc_freq;
8730 if (intel_is_dual_link_lvds(dev)) {
8731 if (refclk == 100000)
8732 limit = &intel_limits_ironlake_dual_lvds_100m;
8734 limit = &intel_limits_ironlake_dual_lvds;
8736 if (refclk == 100000)
8737 limit = &intel_limits_ironlake_single_lvds_100m;
8739 limit = &intel_limits_ironlake_single_lvds;
8742 limit = &intel_limits_ironlake_dac;
8745 if (!crtc_state->clock_set &&
8746 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8747 refclk, NULL, &crtc_state->dpll)) {
8748 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8752 ironlake_compute_dpll(crtc, crtc_state, NULL);
8754 if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
8755 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
8756 pipe_name(crtc->pipe));
8763 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8764 struct intel_link_m_n *m_n)
8766 struct drm_device *dev = crtc->base.dev;
8767 struct drm_i915_private *dev_priv = to_i915(dev);
8768 enum pipe pipe = crtc->pipe;
8770 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8771 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8772 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8774 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8775 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8776 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8779 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8780 enum transcoder transcoder,
8781 struct intel_link_m_n *m_n,
8782 struct intel_link_m_n *m2_n2)
8784 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8785 enum pipe pipe = crtc->pipe;
8787 if (INTEL_GEN(dev_priv) >= 5) {
8788 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
8789 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
8790 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
8792 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
8793 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
8794 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8796 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
8797 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
8798 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
8799 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
8801 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
8802 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
8803 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8806 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
8807 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
8808 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
8810 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
8811 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
8812 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8816 void intel_dp_get_m_n(struct intel_crtc *crtc,
8817 struct intel_crtc_state *pipe_config)
8819 if (pipe_config->has_pch_encoder)
8820 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
8822 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8823 &pipe_config->dp_m_n,
8824 &pipe_config->dp_m2_n2);
8827 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
8828 struct intel_crtc_state *pipe_config)
8830 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8831 &pipe_config->fdi_m_n, NULL);
8834 static void skylake_get_pfit_config(struct intel_crtc *crtc,
8835 struct intel_crtc_state *pipe_config)
8837 struct drm_device *dev = crtc->base.dev;
8838 struct drm_i915_private *dev_priv = to_i915(dev);
8839 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
8840 uint32_t ps_ctrl = 0;
8844 /* find scaler attached to this pipe */
8845 for (i = 0; i < crtc->num_scalers; i++) {
8846 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
8847 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
8849 pipe_config->pch_pfit.enabled = true;
8850 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
8851 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
8856 scaler_state->scaler_id = id;
8858 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
8860 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
8865 skylake_get_initial_plane_config(struct intel_crtc *crtc,
8866 struct intel_initial_plane_config *plane_config)
8868 struct drm_device *dev = crtc->base.dev;
8869 struct drm_i915_private *dev_priv = to_i915(dev);
8870 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8871 enum plane_id plane_id = plane->id;
8873 u32 val, base, offset, stride_mult, tiling, alpha;
8874 int fourcc, pixel_format;
8875 unsigned int aligned_height;
8876 struct drm_framebuffer *fb;
8877 struct intel_framebuffer *intel_fb;
8879 if (!plane->get_hw_state(plane, &pipe))
8882 WARN_ON(pipe != crtc->pipe);
8884 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8886 DRM_DEBUG_KMS("failed to alloc fb\n");
8890 fb = &intel_fb->base;
8894 val = I915_READ(PLANE_CTL(pipe, plane_id));
8896 if (INTEL_GEN(dev_priv) >= 11)
8897 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
8899 pixel_format = val & PLANE_CTL_FORMAT_MASK;
8901 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
8902 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
8903 alpha &= PLANE_COLOR_ALPHA_MASK;
8905 alpha = val & PLANE_CTL_ALPHA_MASK;
8908 fourcc = skl_format_to_fourcc(pixel_format,
8909 val & PLANE_CTL_ORDER_RGBX, alpha);
8910 fb->format = drm_format_info(fourcc);
8912 tiling = val & PLANE_CTL_TILED_MASK;
8914 case PLANE_CTL_TILED_LINEAR:
8915 fb->modifier = DRM_FORMAT_MOD_LINEAR;
8917 case PLANE_CTL_TILED_X:
8918 plane_config->tiling = I915_TILING_X;
8919 fb->modifier = I915_FORMAT_MOD_X_TILED;
8921 case PLANE_CTL_TILED_Y:
8922 plane_config->tiling = I915_TILING_Y;
8923 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
8924 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
8926 fb->modifier = I915_FORMAT_MOD_Y_TILED;
8928 case PLANE_CTL_TILED_YF:
8929 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
8930 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
8932 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
8935 MISSING_CASE(tiling);
8940 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
8941 * while i915 HW rotation is clockwise, thats why this swapping.
8943 switch (val & PLANE_CTL_ROTATE_MASK) {
8944 case PLANE_CTL_ROTATE_0:
8945 plane_config->rotation = DRM_MODE_ROTATE_0;
8947 case PLANE_CTL_ROTATE_90:
8948 plane_config->rotation = DRM_MODE_ROTATE_270;
8950 case PLANE_CTL_ROTATE_180:
8951 plane_config->rotation = DRM_MODE_ROTATE_180;
8953 case PLANE_CTL_ROTATE_270:
8954 plane_config->rotation = DRM_MODE_ROTATE_90;
8958 if (INTEL_GEN(dev_priv) >= 10 &&
8959 val & PLANE_CTL_FLIP_HORIZONTAL)
8960 plane_config->rotation |= DRM_MODE_REFLECT_X;
8962 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
8963 plane_config->base = base;
8965 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
8967 val = I915_READ(PLANE_SIZE(pipe, plane_id));
8968 fb->height = ((val >> 16) & 0xfff) + 1;
8969 fb->width = ((val >> 0) & 0x1fff) + 1;
8971 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
8972 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
8973 fb->pitches[0] = (val & 0x3ff) * stride_mult;
8975 aligned_height = intel_fb_align_height(fb, 0, fb->height);
8977 plane_config->size = fb->pitches[0] * aligned_height;
8979 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8980 crtc->base.name, plane->base.name, fb->width, fb->height,
8981 fb->format->cpp[0] * 8, base, fb->pitches[0],
8982 plane_config->size);
8984 plane_config->fb = intel_fb;
8991 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
8992 struct intel_crtc_state *pipe_config)
8994 struct drm_device *dev = crtc->base.dev;
8995 struct drm_i915_private *dev_priv = to_i915(dev);
8998 tmp = I915_READ(PF_CTL(crtc->pipe));
9000 if (tmp & PF_ENABLE) {
9001 pipe_config->pch_pfit.enabled = true;
9002 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
9003 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
9005 /* We currently do not free assignements of panel fitters on
9006 * ivb/hsw (since we don't use the higher upscaling modes which
9007 * differentiates them) so just WARN about this case for now. */
9008 if (IS_GEN7(dev_priv)) {
9009 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
9010 PF_PIPE_SEL_IVB(crtc->pipe));
9015 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
9016 struct intel_crtc_state *pipe_config)
9018 struct drm_device *dev = crtc->base.dev;
9019 struct drm_i915_private *dev_priv = to_i915(dev);
9020 enum intel_display_power_domain power_domain;
9024 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9025 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9028 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
9029 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9030 pipe_config->shared_dpll = NULL;
9033 tmp = I915_READ(PIPECONF(crtc->pipe));
9034 if (!(tmp & PIPECONF_ENABLE))
9037 switch (tmp & PIPECONF_BPC_MASK) {
9039 pipe_config->pipe_bpp = 18;
9042 pipe_config->pipe_bpp = 24;
9044 case PIPECONF_10BPC:
9045 pipe_config->pipe_bpp = 30;
9047 case PIPECONF_12BPC:
9048 pipe_config->pipe_bpp = 36;
9054 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
9055 pipe_config->limited_color_range = true;
9057 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
9058 struct intel_shared_dpll *pll;
9059 enum intel_dpll_id pll_id;
9061 pipe_config->has_pch_encoder = true;
9063 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
9064 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9065 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9067 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9069 if (HAS_PCH_IBX(dev_priv)) {
9071 * The pipe->pch transcoder and pch transcoder->pll
9074 pll_id = (enum intel_dpll_id) crtc->pipe;
9076 tmp = I915_READ(PCH_DPLL_SEL);
9077 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
9078 pll_id = DPLL_ID_PCH_PLL_B;
9080 pll_id= DPLL_ID_PCH_PLL_A;
9083 pipe_config->shared_dpll =
9084 intel_get_shared_dpll_by_id(dev_priv, pll_id);
9085 pll = pipe_config->shared_dpll;
9087 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9088 &pipe_config->dpll_hw_state));
9090 tmp = pipe_config->dpll_hw_state.dpll;
9091 pipe_config->pixel_multiplier =
9092 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
9093 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
9095 ironlake_pch_clock_get(crtc, pipe_config);
9097 pipe_config->pixel_multiplier = 1;
9100 intel_get_pipe_timings(crtc, pipe_config);
9101 intel_get_pipe_src_size(crtc, pipe_config);
9103 ironlake_get_pfit_config(crtc, pipe_config);
9108 intel_display_power_put(dev_priv, power_domain);
9113 static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
9115 struct drm_device *dev = &dev_priv->drm;
9116 struct intel_crtc *crtc;
9118 for_each_intel_crtc(dev, crtc)
9119 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
9120 pipe_name(crtc->pipe));
9122 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2),
9123 "Display power well on\n");
9124 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
9125 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
9126 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
9127 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
9128 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
9129 "CPU PWM1 enabled\n");
9130 if (IS_HASWELL(dev_priv))
9131 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
9132 "CPU PWM2 enabled\n");
9133 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
9134 "PCH PWM1 enabled\n");
9135 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
9136 "Utility pin enabled\n");
9137 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
9140 * In theory we can still leave IRQs enabled, as long as only the HPD
9141 * interrupts remain enabled. We used to check for that, but since it's
9142 * gen-specific and since we only disable LCPLL after we fully disable
9143 * the interrupts, the check below should be enough.
9145 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
9148 static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
9150 if (IS_HASWELL(dev_priv))
9151 return I915_READ(D_COMP_HSW);
9153 return I915_READ(D_COMP_BDW);
9156 static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
9158 if (IS_HASWELL(dev_priv)) {
9159 mutex_lock(&dev_priv->pcu_lock);
9160 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
9162 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
9163 mutex_unlock(&dev_priv->pcu_lock);
9165 I915_WRITE(D_COMP_BDW, val);
9166 POSTING_READ(D_COMP_BDW);
9171 * This function implements pieces of two sequences from BSpec:
9172 * - Sequence for display software to disable LCPLL
9173 * - Sequence for display software to allow package C8+
9174 * The steps implemented here are just the steps that actually touch the LCPLL
9175 * register. Callers should take care of disabling all the display engine
9176 * functions, doing the mode unset, fixing interrupts, etc.
9178 static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
9179 bool switch_to_fclk, bool allow_power_down)
9183 assert_can_disable_lcpll(dev_priv);
9185 val = I915_READ(LCPLL_CTL);
9187 if (switch_to_fclk) {
9188 val |= LCPLL_CD_SOURCE_FCLK;
9189 I915_WRITE(LCPLL_CTL, val);
9191 if (wait_for_us(I915_READ(LCPLL_CTL) &
9192 LCPLL_CD_SOURCE_FCLK_DONE, 1))
9193 DRM_ERROR("Switching to FCLK failed\n");
9195 val = I915_READ(LCPLL_CTL);
9198 val |= LCPLL_PLL_DISABLE;
9199 I915_WRITE(LCPLL_CTL, val);
9200 POSTING_READ(LCPLL_CTL);
9202 if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
9203 DRM_ERROR("LCPLL still locked\n");
9205 val = hsw_read_dcomp(dev_priv);
9206 val |= D_COMP_COMP_DISABLE;
9207 hsw_write_dcomp(dev_priv, val);
9210 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
9212 DRM_ERROR("D_COMP RCOMP still in progress\n");
9214 if (allow_power_down) {
9215 val = I915_READ(LCPLL_CTL);
9216 val |= LCPLL_POWER_DOWN_ALLOW;
9217 I915_WRITE(LCPLL_CTL, val);
9218 POSTING_READ(LCPLL_CTL);
9223 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9226 static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
9230 val = I915_READ(LCPLL_CTL);
9232 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
9233 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
9237 * Make sure we're not on PC8 state before disabling PC8, otherwise
9238 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
9240 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
9242 if (val & LCPLL_POWER_DOWN_ALLOW) {
9243 val &= ~LCPLL_POWER_DOWN_ALLOW;
9244 I915_WRITE(LCPLL_CTL, val);
9245 POSTING_READ(LCPLL_CTL);
9248 val = hsw_read_dcomp(dev_priv);
9249 val |= D_COMP_COMP_FORCE;
9250 val &= ~D_COMP_COMP_DISABLE;
9251 hsw_write_dcomp(dev_priv, val);
9253 val = I915_READ(LCPLL_CTL);
9254 val &= ~LCPLL_PLL_DISABLE;
9255 I915_WRITE(LCPLL_CTL, val);
9257 if (intel_wait_for_register(dev_priv,
9258 LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
9260 DRM_ERROR("LCPLL not locked yet\n");
9262 if (val & LCPLL_CD_SOURCE_FCLK) {
9263 val = I915_READ(LCPLL_CTL);
9264 val &= ~LCPLL_CD_SOURCE_FCLK;
9265 I915_WRITE(LCPLL_CTL, val);
9267 if (wait_for_us((I915_READ(LCPLL_CTL) &
9268 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
9269 DRM_ERROR("Switching back to LCPLL failed\n");
9272 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
9274 intel_update_cdclk(dev_priv);
9275 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
9279 * Package states C8 and deeper are really deep PC states that can only be
9280 * reached when all the devices on the system allow it, so even if the graphics
9281 * device allows PC8+, it doesn't mean the system will actually get to these
9282 * states. Our driver only allows PC8+ when going into runtime PM.
9284 * The requirements for PC8+ are that all the outputs are disabled, the power
9285 * well is disabled and most interrupts are disabled, and these are also
9286 * requirements for runtime PM. When these conditions are met, we manually do
9287 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9288 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9291 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9292 * the state of some registers, so when we come back from PC8+ we need to
9293 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9294 * need to take care of the registers kept by RC6. Notice that this happens even
9295 * if we don't put the device in PCI D3 state (which is what currently happens
9296 * because of the runtime PM support).
9298 * For more, read "Display Sequences for Package C8" on the hardware
9301 void hsw_enable_pc8(struct drm_i915_private *dev_priv)
9305 DRM_DEBUG_KMS("Enabling package C8+\n");
9307 if (HAS_PCH_LPT_LP(dev_priv)) {
9308 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9309 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
9310 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9313 lpt_disable_clkout_dp(dev_priv);
9314 hsw_disable_lcpll(dev_priv, true, true);
9317 void hsw_disable_pc8(struct drm_i915_private *dev_priv)
9321 DRM_DEBUG_KMS("Disabling package C8+\n");
9323 hsw_restore_lcpll(dev_priv);
9324 lpt_init_pch_refclk(dev_priv);
9326 if (HAS_PCH_LPT_LP(dev_priv)) {
9327 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9328 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9329 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9333 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9334 struct intel_crtc_state *crtc_state)
9336 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9337 struct intel_atomic_state *state =
9338 to_intel_atomic_state(crtc_state->base.state);
9340 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) ||
9341 IS_ICELAKE(dev_priv)) {
9342 struct intel_encoder *encoder =
9343 intel_get_crtc_new_encoder(state, crtc_state);
9345 if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
9346 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
9347 pipe_name(crtc->pipe));
9355 static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
9357 struct intel_crtc_state *pipe_config)
9359 enum intel_dpll_id id;
9362 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9363 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9365 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
9368 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9371 static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
9373 struct intel_crtc_state *pipe_config)
9375 enum intel_dpll_id id;
9378 /* TODO: TBT pll not implemented. */
9379 if (intel_port_is_combophy(dev_priv, port)) {
9380 temp = I915_READ(DPCLKA_CFGCR0_ICL) &
9381 DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9382 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9384 if (WARN_ON(!intel_dpll_is_combophy(id)))
9386 } else if (intel_port_is_tc(dev_priv, port)) {
9387 id = icl_port_to_mg_pll_id(port);
9389 WARN(1, "Invalid port %x\n", port);
9393 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9396 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9398 struct intel_crtc_state *pipe_config)
9400 enum intel_dpll_id id;
9404 id = DPLL_ID_SKL_DPLL0;
9407 id = DPLL_ID_SKL_DPLL1;
9410 id = DPLL_ID_SKL_DPLL2;
9413 DRM_ERROR("Incorrect port type\n");
9417 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9420 static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9422 struct intel_crtc_state *pipe_config)
9424 enum intel_dpll_id id;
9427 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
9428 id = temp >> (port * 3 + 1);
9430 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
9433 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9436 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9438 struct intel_crtc_state *pipe_config)
9440 enum intel_dpll_id id;
9441 uint32_t ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
9443 switch (ddi_pll_sel) {
9444 case PORT_CLK_SEL_WRPLL1:
9445 id = DPLL_ID_WRPLL1;
9447 case PORT_CLK_SEL_WRPLL2:
9448 id = DPLL_ID_WRPLL2;
9450 case PORT_CLK_SEL_SPLL:
9453 case PORT_CLK_SEL_LCPLL_810:
9454 id = DPLL_ID_LCPLL_810;
9456 case PORT_CLK_SEL_LCPLL_1350:
9457 id = DPLL_ID_LCPLL_1350;
9459 case PORT_CLK_SEL_LCPLL_2700:
9460 id = DPLL_ID_LCPLL_2700;
9463 MISSING_CASE(ddi_pll_sel);
9465 case PORT_CLK_SEL_NONE:
9469 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9472 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
9473 struct intel_crtc_state *pipe_config,
9474 u64 *power_domain_mask)
9476 struct drm_device *dev = crtc->base.dev;
9477 struct drm_i915_private *dev_priv = to_i915(dev);
9478 enum intel_display_power_domain power_domain;
9479 unsigned long panel_transcoder_mask = BIT(TRANSCODER_EDP);
9480 unsigned long enabled_panel_transcoders = 0;
9481 enum transcoder panel_transcoder;
9484 if (IS_ICELAKE(dev_priv))
9485 panel_transcoder_mask |=
9486 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
9489 * The pipe->transcoder mapping is fixed with the exception of the eDP
9490 * and DSI transcoders handled below.
9492 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9495 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9496 * consistency and less surprising code; it's in always on power).
9498 for_each_set_bit(panel_transcoder, &panel_transcoder_mask, 32) {
9499 enum pipe trans_pipe;
9501 tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder));
9502 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
9506 * Log all enabled ones, only use the first one.
9508 * FIXME: This won't work for two separate DSI displays.
9510 enabled_panel_transcoders |= BIT(panel_transcoder);
9511 if (enabled_panel_transcoders != BIT(panel_transcoder))
9514 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9516 WARN(1, "unknown pipe linked to transcoder %s\n",
9517 transcoder_name(panel_transcoder));
9519 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9520 case TRANS_DDI_EDP_INPUT_A_ON:
9521 trans_pipe = PIPE_A;
9523 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9524 trans_pipe = PIPE_B;
9526 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9527 trans_pipe = PIPE_C;
9531 if (trans_pipe == crtc->pipe)
9532 pipe_config->cpu_transcoder = panel_transcoder;
9536 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
9538 WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
9539 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
9541 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
9542 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9544 *power_domain_mask |= BIT_ULL(power_domain);
9546 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9548 return tmp & PIPECONF_ENABLE;
9551 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
9552 struct intel_crtc_state *pipe_config,
9553 u64 *power_domain_mask)
9555 struct drm_device *dev = crtc->base.dev;
9556 struct drm_i915_private *dev_priv = to_i915(dev);
9557 enum intel_display_power_domain power_domain;
9559 enum transcoder cpu_transcoder;
9562 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
9564 cpu_transcoder = TRANSCODER_DSI_A;
9566 cpu_transcoder = TRANSCODER_DSI_C;
9568 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
9569 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9571 *power_domain_mask |= BIT_ULL(power_domain);
9574 * The PLL needs to be enabled with a valid divider
9575 * configuration, otherwise accessing DSI registers will hang
9576 * the machine. See BSpec North Display Engine
9577 * registers/MIPI[BXT]. We can break out here early, since we
9578 * need the same DSI PLL to be enabled for both DSI ports.
9580 if (!bxt_dsi_pll_is_enabled(dev_priv))
9583 /* XXX: this works for video mode only */
9584 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
9585 if (!(tmp & DPI_ENABLE))
9588 tmp = I915_READ(MIPI_CTRL(port));
9589 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
9592 pipe_config->cpu_transcoder = cpu_transcoder;
9596 return transcoder_is_dsi(pipe_config->cpu_transcoder);
9599 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
9600 struct intel_crtc_state *pipe_config)
9602 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9603 struct intel_shared_dpll *pll;
9607 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9609 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9611 if (IS_ICELAKE(dev_priv))
9612 icelake_get_ddi_pll(dev_priv, port, pipe_config);
9613 else if (IS_CANNONLAKE(dev_priv))
9614 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
9615 else if (IS_GEN9_BC(dev_priv))
9616 skylake_get_ddi_pll(dev_priv, port, pipe_config);
9617 else if (IS_GEN9_LP(dev_priv))
9618 bxt_get_ddi_pll(dev_priv, port, pipe_config);
9620 haswell_get_ddi_pll(dev_priv, port, pipe_config);
9622 pll = pipe_config->shared_dpll;
9624 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9625 &pipe_config->dpll_hw_state));
9629 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9630 * DDI E. So just check whether this pipe is wired to DDI E and whether
9631 * the PCH transcoder is on.
9633 if (INTEL_GEN(dev_priv) < 9 &&
9634 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
9635 pipe_config->has_pch_encoder = true;
9637 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9638 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9639 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9641 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9645 static bool haswell_get_pipe_config(struct intel_crtc *crtc,
9646 struct intel_crtc_state *pipe_config)
9648 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9649 enum intel_display_power_domain power_domain;
9650 u64 power_domain_mask;
9653 intel_crtc_init_scalers(crtc, pipe_config);
9655 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9656 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9658 power_domain_mask = BIT_ULL(power_domain);
9660 pipe_config->shared_dpll = NULL;
9662 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
9664 if (IS_GEN9_LP(dev_priv) &&
9665 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
9673 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
9674 IS_ICELAKE(dev_priv)) {
9675 haswell_get_ddi_port_state(crtc, pipe_config);
9676 intel_get_pipe_timings(crtc, pipe_config);
9679 intel_get_pipe_src_size(crtc, pipe_config);
9680 intel_get_crtc_ycbcr_config(crtc, pipe_config);
9682 pipe_config->gamma_mode =
9683 I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
9685 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9686 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
9687 power_domain_mask |= BIT_ULL(power_domain);
9688 if (INTEL_GEN(dev_priv) >= 9)
9689 skylake_get_pfit_config(crtc, pipe_config);
9691 ironlake_get_pfit_config(crtc, pipe_config);
9694 if (hsw_crtc_supports_ips(crtc)) {
9695 if (IS_HASWELL(dev_priv))
9696 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
9699 * We cannot readout IPS state on broadwell, set to
9700 * true so we can set it to a defined state on first
9703 pipe_config->ips_enabled = true;
9707 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9708 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9709 pipe_config->pixel_multiplier =
9710 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9712 pipe_config->pixel_multiplier = 1;
9716 for_each_power_domain(power_domain, power_domain_mask)
9717 intel_display_power_put(dev_priv, power_domain);
9722 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
9724 struct drm_i915_private *dev_priv =
9725 to_i915(plane_state->base.plane->dev);
9726 const struct drm_framebuffer *fb = plane_state->base.fb;
9727 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9730 if (INTEL_INFO(dev_priv)->display.cursor_needs_physical)
9731 base = obj->phys_handle->busaddr;
9733 base = intel_plane_ggtt_offset(plane_state);
9735 base += plane_state->color_plane[0].offset;
9737 /* ILK+ do this automagically */
9738 if (HAS_GMCH_DISPLAY(dev_priv) &&
9739 plane_state->base.rotation & DRM_MODE_ROTATE_180)
9740 base += (plane_state->base.crtc_h *
9741 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
9746 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
9748 int x = plane_state->base.crtc_x;
9749 int y = plane_state->base.crtc_y;
9753 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
9756 pos |= x << CURSOR_X_SHIFT;
9759 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
9762 pos |= y << CURSOR_Y_SHIFT;
9767 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
9769 const struct drm_mode_config *config =
9770 &plane_state->base.plane->dev->mode_config;
9771 int width = plane_state->base.crtc_w;
9772 int height = plane_state->base.crtc_h;
9774 return width > 0 && width <= config->cursor_width &&
9775 height > 0 && height <= config->cursor_height;
9778 static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
9780 const struct drm_framebuffer *fb = plane_state->base.fb;
9781 unsigned int rotation = plane_state->base.rotation;
9786 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
9787 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
9789 ret = intel_plane_check_stride(plane_state);
9793 src_x = plane_state->base.src_x >> 16;
9794 src_y = plane_state->base.src_y >> 16;
9796 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
9797 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
9800 if (src_x != 0 || src_y != 0) {
9801 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9805 plane_state->color_plane[0].offset = offset;
9810 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
9811 struct intel_plane_state *plane_state)
9813 const struct drm_framebuffer *fb = plane_state->base.fb;
9816 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
9817 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9821 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
9823 DRM_PLANE_HELPER_NO_SCALING,
9824 DRM_PLANE_HELPER_NO_SCALING,
9829 if (!plane_state->base.visible)
9832 ret = intel_plane_check_src_coordinates(plane_state);
9836 ret = intel_cursor_check_surface(plane_state);
9844 i845_cursor_max_stride(struct intel_plane *plane,
9845 u32 pixel_format, u64 modifier,
9846 unsigned int rotation)
9851 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
9852 const struct intel_plane_state *plane_state)
9854 return CURSOR_ENABLE |
9855 CURSOR_GAMMA_ENABLE |
9856 CURSOR_FORMAT_ARGB |
9857 CURSOR_STRIDE(plane_state->color_plane[0].stride);
9860 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
9862 int width = plane_state->base.crtc_w;
9865 * 845g/865g are only limited by the width of their cursors,
9866 * the height is arbitrary up to the precision of the register.
9868 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
9871 static int i845_check_cursor(struct intel_crtc_state *crtc_state,
9872 struct intel_plane_state *plane_state)
9874 const struct drm_framebuffer *fb = plane_state->base.fb;
9877 ret = intel_check_cursor(crtc_state, plane_state);
9881 /* if we want to turn off the cursor ignore width and height */
9885 /* Check for which cursor types we support */
9886 if (!i845_cursor_size_ok(plane_state)) {
9887 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9888 plane_state->base.crtc_w,
9889 plane_state->base.crtc_h);
9893 WARN_ON(plane_state->base.visible &&
9894 plane_state->color_plane[0].stride != fb->pitches[0]);
9896 switch (fb->pitches[0]) {
9903 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
9908 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
9913 static void i845_update_cursor(struct intel_plane *plane,
9914 const struct intel_crtc_state *crtc_state,
9915 const struct intel_plane_state *plane_state)
9917 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9918 u32 cntl = 0, base = 0, pos = 0, size = 0;
9919 unsigned long irqflags;
9921 if (plane_state && plane_state->base.visible) {
9922 unsigned int width = plane_state->base.crtc_w;
9923 unsigned int height = plane_state->base.crtc_h;
9925 cntl = plane_state->ctl;
9926 size = (height << 12) | width;
9928 base = intel_cursor_base(plane_state);
9929 pos = intel_cursor_position(plane_state);
9932 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9934 /* On these chipsets we can only modify the base/size/stride
9935 * whilst the cursor is disabled.
9937 if (plane->cursor.base != base ||
9938 plane->cursor.size != size ||
9939 plane->cursor.cntl != cntl) {
9940 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
9941 I915_WRITE_FW(CURBASE(PIPE_A), base);
9942 I915_WRITE_FW(CURSIZE, size);
9943 I915_WRITE_FW(CURPOS(PIPE_A), pos);
9944 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
9946 plane->cursor.base = base;
9947 plane->cursor.size = size;
9948 plane->cursor.cntl = cntl;
9950 I915_WRITE_FW(CURPOS(PIPE_A), pos);
9953 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
9956 static void i845_disable_cursor(struct intel_plane *plane,
9957 const struct intel_crtc_state *crtc_state)
9959 i845_update_cursor(plane, crtc_state, NULL);
9962 static bool i845_cursor_get_hw_state(struct intel_plane *plane,
9965 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9966 enum intel_display_power_domain power_domain;
9969 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
9970 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9973 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
9977 intel_display_power_put(dev_priv, power_domain);
9983 i9xx_cursor_max_stride(struct intel_plane *plane,
9984 u32 pixel_format, u64 modifier,
9985 unsigned int rotation)
9987 return plane->base.dev->mode_config.cursor_width * 4;
9990 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
9991 const struct intel_plane_state *plane_state)
9993 struct drm_i915_private *dev_priv =
9994 to_i915(plane_state->base.plane->dev);
9995 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9998 if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
9999 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
10001 if (INTEL_GEN(dev_priv) <= 10) {
10002 cntl |= MCURSOR_GAMMA_ENABLE;
10004 if (HAS_DDI(dev_priv))
10005 cntl |= MCURSOR_PIPE_CSC_ENABLE;
10008 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10009 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
10011 switch (plane_state->base.crtc_w) {
10013 cntl |= MCURSOR_MODE_64_ARGB_AX;
10016 cntl |= MCURSOR_MODE_128_ARGB_AX;
10019 cntl |= MCURSOR_MODE_256_ARGB_AX;
10022 MISSING_CASE(plane_state->base.crtc_w);
10026 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
10027 cntl |= MCURSOR_ROTATE_180;
10032 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
10034 struct drm_i915_private *dev_priv =
10035 to_i915(plane_state->base.plane->dev);
10036 int width = plane_state->base.crtc_w;
10037 int height = plane_state->base.crtc_h;
10039 if (!intel_cursor_size_ok(plane_state))
10042 /* Cursor width is limited to a few power-of-two sizes */
10053 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
10054 * height from 8 lines up to the cursor width, when the
10055 * cursor is not rotated. Everything else requires square
10058 if (HAS_CUR_FBC(dev_priv) &&
10059 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
10060 if (height < 8 || height > width)
10063 if (height != width)
10070 static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
10071 struct intel_plane_state *plane_state)
10073 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
10074 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10075 const struct drm_framebuffer *fb = plane_state->base.fb;
10076 enum pipe pipe = plane->pipe;
10079 ret = intel_check_cursor(crtc_state, plane_state);
10083 /* if we want to turn off the cursor ignore width and height */
10087 /* Check for which cursor types we support */
10088 if (!i9xx_cursor_size_ok(plane_state)) {
10089 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10090 plane_state->base.crtc_w,
10091 plane_state->base.crtc_h);
10095 WARN_ON(plane_state->base.visible &&
10096 plane_state->color_plane[0].stride != fb->pitches[0]);
10098 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
10099 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
10100 fb->pitches[0], plane_state->base.crtc_w);
10105 * There's something wrong with the cursor on CHV pipe C.
10106 * If it straddles the left edge of the screen then
10107 * moving it away from the edge or disabling it often
10108 * results in a pipe underrun, and often that can lead to
10109 * dead pipe (constant underrun reported, and it scans
10110 * out just a solid color). To recover from that, the
10111 * display power well must be turned off and on again.
10112 * Refuse the put the cursor into that compromised position.
10114 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
10115 plane_state->base.visible && plane_state->base.crtc_x < 0) {
10116 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
10120 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
10125 static void i9xx_update_cursor(struct intel_plane *plane,
10126 const struct intel_crtc_state *crtc_state,
10127 const struct intel_plane_state *plane_state)
10129 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10130 enum pipe pipe = plane->pipe;
10131 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
10132 unsigned long irqflags;
10134 if (plane_state && plane_state->base.visible) {
10135 cntl = plane_state->ctl;
10137 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
10138 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
10140 base = intel_cursor_base(plane_state);
10141 pos = intel_cursor_position(plane_state);
10144 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10147 * On some platforms writing CURCNTR first will also
10148 * cause CURPOS to be armed by the CURBASE write.
10149 * Without the CURCNTR write the CURPOS write would
10150 * arm itself. Thus we always update CURCNTR before
10153 * On other platforms CURPOS always requires the
10154 * CURBASE write to arm the update. Additonally
10155 * a write to any of the cursor register will cancel
10156 * an already armed cursor update. Thus leaving out
10157 * the CURBASE write after CURPOS could lead to a
10158 * cursor that doesn't appear to move, or even change
10159 * shape. Thus we always write CURBASE.
10161 * The other registers are armed by by the CURBASE write
10162 * except when the plane is getting enabled at which time
10163 * the CURCNTR write arms the update.
10166 if (INTEL_GEN(dev_priv) >= 9)
10167 skl_write_cursor_wm(plane, crtc_state);
10169 if (plane->cursor.base != base ||
10170 plane->cursor.size != fbc_ctl ||
10171 plane->cursor.cntl != cntl) {
10172 if (HAS_CUR_FBC(dev_priv))
10173 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
10174 I915_WRITE_FW(CURCNTR(pipe), cntl);
10175 I915_WRITE_FW(CURPOS(pipe), pos);
10176 I915_WRITE_FW(CURBASE(pipe), base);
10178 plane->cursor.base = base;
10179 plane->cursor.size = fbc_ctl;
10180 plane->cursor.cntl = cntl;
10182 I915_WRITE_FW(CURPOS(pipe), pos);
10183 I915_WRITE_FW(CURBASE(pipe), base);
10186 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
10189 static void i9xx_disable_cursor(struct intel_plane *plane,
10190 const struct intel_crtc_state *crtc_state)
10192 i9xx_update_cursor(plane, crtc_state, NULL);
10195 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
10198 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10199 enum intel_display_power_domain power_domain;
10204 * Not 100% correct for planes that can move between pipes,
10205 * but that's only the case for gen2-3 which don't have any
10206 * display power wells.
10208 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
10209 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
10212 val = I915_READ(CURCNTR(plane->pipe));
10214 ret = val & MCURSOR_MODE;
10216 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
10217 *pipe = plane->pipe;
10219 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
10220 MCURSOR_PIPE_SELECT_SHIFT;
10222 intel_display_power_put(dev_priv, power_domain);
10227 /* VESA 640x480x72Hz mode to set on the pipe */
10228 static const struct drm_display_mode load_detect_mode = {
10229 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
10230 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
10233 struct drm_framebuffer *
10234 intel_framebuffer_create(struct drm_i915_gem_object *obj,
10235 struct drm_mode_fb_cmd2 *mode_cmd)
10237 struct intel_framebuffer *intel_fb;
10240 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
10242 return ERR_PTR(-ENOMEM);
10244 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
10248 return &intel_fb->base;
10252 return ERR_PTR(ret);
10255 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
10256 struct drm_crtc *crtc)
10258 struct drm_plane *plane;
10259 struct drm_plane_state *plane_state;
10262 ret = drm_atomic_add_affected_planes(state, crtc);
10266 for_each_new_plane_in_state(state, plane, plane_state, i) {
10267 if (plane_state->crtc != crtc)
10270 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
10274 drm_atomic_set_fb_for_plane(plane_state, NULL);
10280 int intel_get_load_detect_pipe(struct drm_connector *connector,
10281 const struct drm_display_mode *mode,
10282 struct intel_load_detect_pipe *old,
10283 struct drm_modeset_acquire_ctx *ctx)
10285 struct intel_crtc *intel_crtc;
10286 struct intel_encoder *intel_encoder =
10287 intel_attached_encoder(connector);
10288 struct drm_crtc *possible_crtc;
10289 struct drm_encoder *encoder = &intel_encoder->base;
10290 struct drm_crtc *crtc = NULL;
10291 struct drm_device *dev = encoder->dev;
10292 struct drm_i915_private *dev_priv = to_i915(dev);
10293 struct drm_mode_config *config = &dev->mode_config;
10294 struct drm_atomic_state *state = NULL, *restore_state = NULL;
10295 struct drm_connector_state *connector_state;
10296 struct intel_crtc_state *crtc_state;
10299 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10300 connector->base.id, connector->name,
10301 encoder->base.id, encoder->name);
10303 old->restore_state = NULL;
10305 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
10308 * Algorithm gets a little messy:
10310 * - if the connector already has an assigned crtc, use it (but make
10311 * sure it's on first)
10313 * - try to find the first unused crtc that can drive this connector,
10314 * and use that if we find one
10317 /* See if we already have a CRTC for this connector */
10318 if (connector->state->crtc) {
10319 crtc = connector->state->crtc;
10321 ret = drm_modeset_lock(&crtc->mutex, ctx);
10325 /* Make sure the crtc and connector are running */
10329 /* Find an unused one (if possible) */
10330 for_each_crtc(dev, possible_crtc) {
10332 if (!(encoder->possible_crtcs & (1 << i)))
10335 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
10339 if (possible_crtc->state->enable) {
10340 drm_modeset_unlock(&possible_crtc->mutex);
10344 crtc = possible_crtc;
10349 * If we didn't find an unused CRTC, don't use any.
10352 DRM_DEBUG_KMS("no pipe available for load-detect\n");
10358 intel_crtc = to_intel_crtc(crtc);
10360 state = drm_atomic_state_alloc(dev);
10361 restore_state = drm_atomic_state_alloc(dev);
10362 if (!state || !restore_state) {
10367 state->acquire_ctx = ctx;
10368 restore_state->acquire_ctx = ctx;
10370 connector_state = drm_atomic_get_connector_state(state, connector);
10371 if (IS_ERR(connector_state)) {
10372 ret = PTR_ERR(connector_state);
10376 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
10380 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10381 if (IS_ERR(crtc_state)) {
10382 ret = PTR_ERR(crtc_state);
10386 crtc_state->base.active = crtc_state->base.enable = true;
10389 mode = &load_detect_mode;
10391 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
10395 ret = intel_modeset_disable_planes(state, crtc);
10399 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
10401 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
10403 ret = drm_atomic_add_affected_planes(restore_state, crtc);
10405 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
10409 ret = drm_atomic_commit(state);
10411 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
10415 old->restore_state = restore_state;
10416 drm_atomic_state_put(state);
10418 /* let the connector get through one full cycle before testing */
10419 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
10424 drm_atomic_state_put(state);
10427 if (restore_state) {
10428 drm_atomic_state_put(restore_state);
10429 restore_state = NULL;
10432 if (ret == -EDEADLK)
10438 void intel_release_load_detect_pipe(struct drm_connector *connector,
10439 struct intel_load_detect_pipe *old,
10440 struct drm_modeset_acquire_ctx *ctx)
10442 struct intel_encoder *intel_encoder =
10443 intel_attached_encoder(connector);
10444 struct drm_encoder *encoder = &intel_encoder->base;
10445 struct drm_atomic_state *state = old->restore_state;
10448 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10449 connector->base.id, connector->name,
10450 encoder->base.id, encoder->name);
10455 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
10457 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
10458 drm_atomic_state_put(state);
10461 static int i9xx_pll_refclk(struct drm_device *dev,
10462 const struct intel_crtc_state *pipe_config)
10464 struct drm_i915_private *dev_priv = to_i915(dev);
10465 u32 dpll = pipe_config->dpll_hw_state.dpll;
10467 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
10468 return dev_priv->vbt.lvds_ssc_freq;
10469 else if (HAS_PCH_SPLIT(dev_priv))
10471 else if (!IS_GEN2(dev_priv))
10477 /* Returns the clock of the currently programmed mode of the given pipe. */
10478 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
10479 struct intel_crtc_state *pipe_config)
10481 struct drm_device *dev = crtc->base.dev;
10482 struct drm_i915_private *dev_priv = to_i915(dev);
10483 int pipe = pipe_config->cpu_transcoder;
10484 u32 dpll = pipe_config->dpll_hw_state.dpll;
10488 int refclk = i9xx_pll_refclk(dev, pipe_config);
10490 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
10491 fp = pipe_config->dpll_hw_state.fp0;
10493 fp = pipe_config->dpll_hw_state.fp1;
10495 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
10496 if (IS_PINEVIEW(dev_priv)) {
10497 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10498 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
10500 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10501 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10504 if (!IS_GEN2(dev_priv)) {
10505 if (IS_PINEVIEW(dev_priv))
10506 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10507 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
10509 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
10510 DPLL_FPA01_P1_POST_DIV_SHIFT);
10512 switch (dpll & DPLL_MODE_MASK) {
10513 case DPLLB_MODE_DAC_SERIAL:
10514 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10517 case DPLLB_MODE_LVDS:
10518 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10522 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10523 "mode\n", (int)(dpll & DPLL_MODE_MASK));
10527 if (IS_PINEVIEW(dev_priv))
10528 port_clock = pnv_calc_dpll_params(refclk, &clock);
10530 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10532 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
10533 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
10536 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10537 DPLL_FPA01_P1_POST_DIV_SHIFT);
10539 if (lvds & LVDS_CLKB_POWER_UP)
10544 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10547 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10548 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10550 if (dpll & PLL_P2_DIVIDE_BY_4)
10556 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10560 * This value includes pixel_multiplier. We will use
10561 * port_clock to compute adjusted_mode.crtc_clock in the
10562 * encoder's get_config() function.
10564 pipe_config->port_clock = port_clock;
10567 int intel_dotclock_calculate(int link_freq,
10568 const struct intel_link_m_n *m_n)
10571 * The calculation for the data clock is:
10572 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10573 * But we want to avoid losing precison if possible, so:
10574 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10576 * and the link clock is simpler:
10577 * link_clock = (m * link_clock) / n
10583 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
10586 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
10587 struct intel_crtc_state *pipe_config)
10589 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10591 /* read out port_clock from the DPLL */
10592 i9xx_crtc_clock_get(crtc, pipe_config);
10595 * In case there is an active pipe without active ports,
10596 * we may need some idea for the dotclock anyway.
10597 * Calculate one based on the FDI configuration.
10599 pipe_config->base.adjusted_mode.crtc_clock =
10600 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
10601 &pipe_config->fdi_m_n);
10604 /* Returns the currently programmed mode of the given encoder. */
10605 struct drm_display_mode *
10606 intel_encoder_current_mode(struct intel_encoder *encoder)
10608 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
10609 struct intel_crtc_state *crtc_state;
10610 struct drm_display_mode *mode;
10611 struct intel_crtc *crtc;
10614 if (!encoder->get_hw_state(encoder, &pipe))
10617 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
10619 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10623 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
10629 crtc_state->base.crtc = &crtc->base;
10631 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
10637 encoder->get_config(encoder, crtc_state);
10639 intel_mode_from_pipe_config(mode, crtc_state);
10646 static void intel_crtc_destroy(struct drm_crtc *crtc)
10648 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10650 drm_crtc_cleanup(crtc);
10655 * intel_wm_need_update - Check whether watermarks need updating
10656 * @plane: drm plane
10657 * @state: new plane state
10659 * Check current plane state versus the new one to determine whether
10660 * watermarks need to be recalculated.
10662 * Returns true or false.
10664 static bool intel_wm_need_update(struct drm_plane *plane,
10665 struct drm_plane_state *state)
10667 struct intel_plane_state *new = to_intel_plane_state(state);
10668 struct intel_plane_state *cur = to_intel_plane_state(plane->state);
10670 /* Update watermarks on tiling or size changes. */
10671 if (new->base.visible != cur->base.visible)
10674 if (!cur->base.fb || !new->base.fb)
10677 if (cur->base.fb->modifier != new->base.fb->modifier ||
10678 cur->base.rotation != new->base.rotation ||
10679 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
10680 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
10681 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
10682 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
10688 static bool needs_scaling(const struct intel_plane_state *state)
10690 int src_w = drm_rect_width(&state->base.src) >> 16;
10691 int src_h = drm_rect_height(&state->base.src) >> 16;
10692 int dst_w = drm_rect_width(&state->base.dst);
10693 int dst_h = drm_rect_height(&state->base.dst);
10695 return (src_w != dst_w || src_h != dst_h);
10698 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
10699 struct drm_crtc_state *crtc_state,
10700 const struct intel_plane_state *old_plane_state,
10701 struct drm_plane_state *plane_state)
10703 struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
10704 struct drm_crtc *crtc = crtc_state->crtc;
10705 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10706 struct intel_plane *plane = to_intel_plane(plane_state->plane);
10707 struct drm_device *dev = crtc->dev;
10708 struct drm_i915_private *dev_priv = to_i915(dev);
10709 bool mode_changed = needs_modeset(crtc_state);
10710 bool was_crtc_enabled = old_crtc_state->base.active;
10711 bool is_crtc_enabled = crtc_state->active;
10712 bool turn_off, turn_on, visible, was_visible;
10713 struct drm_framebuffer *fb = plane_state->fb;
10716 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
10717 ret = skl_update_scaler_plane(
10718 to_intel_crtc_state(crtc_state),
10719 to_intel_plane_state(plane_state));
10724 was_visible = old_plane_state->base.visible;
10725 visible = plane_state->visible;
10727 if (!was_crtc_enabled && WARN_ON(was_visible))
10728 was_visible = false;
10731 * Visibility is calculated as if the crtc was on, but
10732 * after scaler setup everything depends on it being off
10733 * when the crtc isn't active.
10735 * FIXME this is wrong for watermarks. Watermarks should also
10736 * be computed as if the pipe would be active. Perhaps move
10737 * per-plane wm computation to the .check_plane() hook, and
10738 * only combine the results from all planes in the current place?
10740 if (!is_crtc_enabled) {
10741 plane_state->visible = visible = false;
10742 to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
10745 if (!was_visible && !visible)
10748 if (fb != old_plane_state->base.fb)
10749 pipe_config->fb_changed = true;
10751 turn_off = was_visible && (!visible || mode_changed);
10752 turn_on = visible && (!was_visible || mode_changed);
10754 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
10755 intel_crtc->base.base.id, intel_crtc->base.name,
10756 plane->base.base.id, plane->base.name,
10757 fb ? fb->base.id : -1);
10759 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
10760 plane->base.base.id, plane->base.name,
10761 was_visible, visible,
10762 turn_off, turn_on, mode_changed);
10765 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10766 pipe_config->update_wm_pre = true;
10768 /* must disable cxsr around plane enable/disable */
10769 if (plane->id != PLANE_CURSOR)
10770 pipe_config->disable_cxsr = true;
10771 } else if (turn_off) {
10772 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10773 pipe_config->update_wm_post = true;
10775 /* must disable cxsr around plane enable/disable */
10776 if (plane->id != PLANE_CURSOR)
10777 pipe_config->disable_cxsr = true;
10778 } else if (intel_wm_need_update(&plane->base, plane_state)) {
10779 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
10780 /* FIXME bollocks */
10781 pipe_config->update_wm_pre = true;
10782 pipe_config->update_wm_post = true;
10786 if (visible || was_visible)
10787 pipe_config->fb_bits |= plane->frontbuffer_bit;
10790 * ILK/SNB DVSACNTR/Sprite Enable
10791 * IVB SPR_CTL/Sprite Enable
10792 * "When in Self Refresh Big FIFO mode, a write to enable the
10793 * plane will be internally buffered and delayed while Big FIFO
10794 * mode is exiting."
10796 * Which means that enabling the sprite can take an extra frame
10797 * when we start in big FIFO mode (LP1+). Thus we need to drop
10798 * down to LP0 and wait for vblank in order to make sure the
10799 * sprite gets enabled on the next vblank after the register write.
10800 * Doing otherwise would risk enabling the sprite one frame after
10801 * we've already signalled flip completion. We can resume LP1+
10802 * once the sprite has been enabled.
10805 * WaCxSRDisabledForSpriteScaling:ivb
10806 * IVB SPR_SCALE/Scaling Enable
10807 * "Low Power watermarks must be disabled for at least one
10808 * frame before enabling sprite scaling, and kept disabled
10809 * until sprite scaling is disabled."
10811 * ILK/SNB DVSASCALE/Scaling Enable
10812 * "When in Self Refresh Big FIFO mode, scaling enable will be
10813 * masked off while Big FIFO mode is exiting."
10815 * Despite the w/a only being listed for IVB we assume that
10816 * the ILK/SNB note has similar ramifications, hence we apply
10817 * the w/a on all three platforms.
10819 if (plane->id == PLANE_SPRITE0 &&
10820 (IS_GEN5(dev_priv) || IS_GEN6(dev_priv) ||
10821 IS_IVYBRIDGE(dev_priv)) &&
10822 (turn_on || (!needs_scaling(old_plane_state) &&
10823 needs_scaling(to_intel_plane_state(plane_state)))))
10824 pipe_config->disable_lp_wm = true;
10829 static bool encoders_cloneable(const struct intel_encoder *a,
10830 const struct intel_encoder *b)
10832 /* masks could be asymmetric, so check both ways */
10833 return a == b || (a->cloneable & (1 << b->type) &&
10834 b->cloneable & (1 << a->type));
10837 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
10838 struct intel_crtc *crtc,
10839 struct intel_encoder *encoder)
10841 struct intel_encoder *source_encoder;
10842 struct drm_connector *connector;
10843 struct drm_connector_state *connector_state;
10846 for_each_new_connector_in_state(state, connector, connector_state, i) {
10847 if (connector_state->crtc != &crtc->base)
10851 to_intel_encoder(connector_state->best_encoder);
10852 if (!encoders_cloneable(encoder, source_encoder))
10859 static int icl_add_linked_planes(struct intel_atomic_state *state)
10861 struct intel_plane *plane, *linked;
10862 struct intel_plane_state *plane_state, *linked_plane_state;
10865 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10866 linked = plane_state->linked_plane;
10871 linked_plane_state = intel_atomic_get_plane_state(state, linked);
10872 if (IS_ERR(linked_plane_state))
10873 return PTR_ERR(linked_plane_state);
10875 WARN_ON(linked_plane_state->linked_plane != plane);
10876 WARN_ON(linked_plane_state->slave == plane_state->slave);
10882 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
10884 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
10885 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10886 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state);
10887 struct intel_plane *plane, *linked;
10888 struct intel_plane_state *plane_state;
10891 if (INTEL_GEN(dev_priv) < 11)
10895 * Destroy all old plane links and make the slave plane invisible
10896 * in the crtc_state->active_planes mask.
10898 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10899 if (plane->pipe != crtc->pipe || !plane_state->linked_plane)
10902 plane_state->linked_plane = NULL;
10903 if (plane_state->slave && !plane_state->base.visible) {
10904 crtc_state->active_planes &= ~BIT(plane->id);
10905 crtc_state->update_planes |= BIT(plane->id);
10908 plane_state->slave = false;
10911 if (!crtc_state->nv12_planes)
10914 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10915 struct intel_plane_state *linked_state = NULL;
10917 if (plane->pipe != crtc->pipe ||
10918 !(crtc_state->nv12_planes & BIT(plane->id)))
10921 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
10922 if (!icl_is_nv12_y_plane(linked->id))
10925 if (crtc_state->active_planes & BIT(linked->id))
10928 linked_state = intel_atomic_get_plane_state(state, linked);
10929 if (IS_ERR(linked_state))
10930 return PTR_ERR(linked_state);
10935 if (!linked_state) {
10936 DRM_DEBUG_KMS("Need %d free Y planes for NV12\n",
10937 hweight8(crtc_state->nv12_planes));
10942 plane_state->linked_plane = linked;
10944 linked_state->slave = true;
10945 linked_state->linked_plane = plane;
10946 crtc_state->active_planes |= BIT(linked->id);
10947 crtc_state->update_planes |= BIT(linked->id);
10948 DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name);
10954 static int intel_crtc_atomic_check(struct drm_crtc *crtc,
10955 struct drm_crtc_state *crtc_state)
10957 struct drm_device *dev = crtc->dev;
10958 struct drm_i915_private *dev_priv = to_i915(dev);
10959 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10960 struct intel_crtc_state *pipe_config =
10961 to_intel_crtc_state(crtc_state);
10963 bool mode_changed = needs_modeset(crtc_state);
10965 if (mode_changed && !crtc_state->active)
10966 pipe_config->update_wm_post = true;
10968 if (mode_changed && crtc_state->enable &&
10969 dev_priv->display.crtc_compute_clock &&
10970 !WARN_ON(pipe_config->shared_dpll)) {
10971 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
10977 if (crtc_state->color_mgmt_changed) {
10978 ret = intel_color_check(crtc, crtc_state);
10983 * Changing color management on Intel hardware is
10984 * handled as part of planes update.
10986 crtc_state->planes_changed = true;
10990 if (dev_priv->display.compute_pipe_wm) {
10991 ret = dev_priv->display.compute_pipe_wm(pipe_config);
10993 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
10998 if (dev_priv->display.compute_intermediate_wm) {
10999 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
11003 * Calculate 'intermediate' watermarks that satisfy both the
11004 * old state and the new state. We can program these
11007 ret = dev_priv->display.compute_intermediate_wm(dev,
11011 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
11016 if (INTEL_GEN(dev_priv) >= 9) {
11018 ret = skl_update_scaler_crtc(pipe_config);
11021 ret = icl_check_nv12_planes(pipe_config);
11023 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
11026 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
11030 if (HAS_IPS(dev_priv))
11031 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
11036 static const struct drm_crtc_helper_funcs intel_helper_funcs = {
11037 .atomic_check = intel_crtc_atomic_check,
11040 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
11042 struct intel_connector *connector;
11043 struct drm_connector_list_iter conn_iter;
11045 drm_connector_list_iter_begin(dev, &conn_iter);
11046 for_each_intel_connector_iter(connector, &conn_iter) {
11047 if (connector->base.state->crtc)
11048 drm_connector_put(&connector->base);
11050 if (connector->base.encoder) {
11051 connector->base.state->best_encoder =
11052 connector->base.encoder;
11053 connector->base.state->crtc =
11054 connector->base.encoder->crtc;
11056 drm_connector_get(&connector->base);
11058 connector->base.state->best_encoder = NULL;
11059 connector->base.state->crtc = NULL;
11062 drm_connector_list_iter_end(&conn_iter);
11066 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
11067 struct intel_crtc_state *pipe_config)
11069 struct drm_connector *connector = conn_state->connector;
11070 const struct drm_display_info *info = &connector->display_info;
11073 switch (conn_state->max_bpc) {
11090 if (bpp < pipe_config->pipe_bpp) {
11091 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
11092 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
11093 connector->base.id, connector->name,
11094 bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc,
11095 pipe_config->pipe_bpp);
11097 pipe_config->pipe_bpp = bpp;
11104 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
11105 struct intel_crtc_state *pipe_config)
11107 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11108 struct drm_atomic_state *state = pipe_config->base.state;
11109 struct drm_connector *connector;
11110 struct drm_connector_state *connector_state;
11113 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
11114 IS_CHERRYVIEW(dev_priv)))
11116 else if (INTEL_GEN(dev_priv) >= 5)
11121 pipe_config->pipe_bpp = bpp;
11123 /* Clamp display bpp to connector max bpp */
11124 for_each_new_connector_in_state(state, connector, connector_state, i) {
11127 if (connector_state->crtc != &crtc->base)
11130 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
11138 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
11140 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11141 "type: 0x%x flags: 0x%x\n",
11143 mode->crtc_hdisplay, mode->crtc_hsync_start,
11144 mode->crtc_hsync_end, mode->crtc_htotal,
11145 mode->crtc_vdisplay, mode->crtc_vsync_start,
11146 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
11150 intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
11151 unsigned int lane_count, struct intel_link_m_n *m_n)
11153 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11155 m_n->gmch_m, m_n->gmch_n,
11156 m_n->link_m, m_n->link_n, m_n->tu);
11159 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
11161 static const char * const output_type_str[] = {
11162 OUTPUT_TYPE(UNUSED),
11163 OUTPUT_TYPE(ANALOG),
11167 OUTPUT_TYPE(TVOUT),
11173 OUTPUT_TYPE(DP_MST),
11178 static void snprintf_output_types(char *buf, size_t len,
11179 unsigned int output_types)
11186 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
11189 if ((output_types & BIT(i)) == 0)
11192 r = snprintf(str, len, "%s%s",
11193 str != buf ? "," : "", output_type_str[i]);
11199 output_types &= ~BIT(i);
11202 WARN_ON_ONCE(output_types != 0);
11205 static const char * const output_format_str[] = {
11206 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
11207 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
11208 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
11209 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
11212 static const char *output_formats(enum intel_output_format format)
11214 if (format >= ARRAY_SIZE(output_format_str))
11215 format = INTEL_OUTPUT_FORMAT_INVALID;
11216 return output_format_str[format];
11219 static void intel_dump_pipe_config(struct intel_crtc *crtc,
11220 struct intel_crtc_state *pipe_config,
11221 const char *context)
11223 struct drm_device *dev = crtc->base.dev;
11224 struct drm_i915_private *dev_priv = to_i915(dev);
11225 struct drm_plane *plane;
11226 struct intel_plane *intel_plane;
11227 struct intel_plane_state *state;
11228 struct drm_framebuffer *fb;
11231 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
11232 crtc->base.base.id, crtc->base.name, context);
11234 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
11235 DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
11236 buf, pipe_config->output_types);
11238 DRM_DEBUG_KMS("output format: %s\n",
11239 output_formats(pipe_config->output_format));
11241 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
11242 transcoder_name(pipe_config->cpu_transcoder),
11243 pipe_config->pipe_bpp, pipe_config->dither);
11245 if (pipe_config->has_pch_encoder)
11246 intel_dump_m_n_config(pipe_config, "fdi",
11247 pipe_config->fdi_lanes,
11248 &pipe_config->fdi_m_n);
11250 if (intel_crtc_has_dp_encoder(pipe_config)) {
11251 intel_dump_m_n_config(pipe_config, "dp m_n",
11252 pipe_config->lane_count, &pipe_config->dp_m_n);
11253 if (pipe_config->has_drrs)
11254 intel_dump_m_n_config(pipe_config, "dp m2_n2",
11255 pipe_config->lane_count,
11256 &pipe_config->dp_m2_n2);
11259 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
11260 pipe_config->has_audio, pipe_config->has_infoframe);
11262 DRM_DEBUG_KMS("requested mode:\n");
11263 drm_mode_debug_printmodeline(&pipe_config->base.mode);
11264 DRM_DEBUG_KMS("adjusted mode:\n");
11265 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
11266 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
11267 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
11268 pipe_config->port_clock,
11269 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
11270 pipe_config->pixel_rate);
11272 if (INTEL_GEN(dev_priv) >= 9)
11273 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
11275 pipe_config->scaler_state.scaler_users,
11276 pipe_config->scaler_state.scaler_id);
11278 if (HAS_GMCH_DISPLAY(dev_priv))
11279 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
11280 pipe_config->gmch_pfit.control,
11281 pipe_config->gmch_pfit.pgm_ratios,
11282 pipe_config->gmch_pfit.lvds_border_bits);
11284 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
11285 pipe_config->pch_pfit.pos,
11286 pipe_config->pch_pfit.size,
11287 enableddisabled(pipe_config->pch_pfit.enabled));
11289 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
11290 pipe_config->ips_enabled, pipe_config->double_wide);
11292 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
11294 DRM_DEBUG_KMS("planes on this crtc\n");
11295 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
11296 struct drm_format_name_buf format_name;
11297 intel_plane = to_intel_plane(plane);
11298 if (intel_plane->pipe != crtc->pipe)
11301 state = to_intel_plane_state(plane->state);
11302 fb = state->base.fb;
11304 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
11305 plane->base.id, plane->name, state->scaler_id);
11309 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
11310 plane->base.id, plane->name,
11311 fb->base.id, fb->width, fb->height,
11312 drm_get_format_name(fb->format->format, &format_name));
11313 if (INTEL_GEN(dev_priv) >= 9)
11314 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
11316 state->base.src.x1 >> 16,
11317 state->base.src.y1 >> 16,
11318 drm_rect_width(&state->base.src) >> 16,
11319 drm_rect_height(&state->base.src) >> 16,
11320 state->base.dst.x1, state->base.dst.y1,
11321 drm_rect_width(&state->base.dst),
11322 drm_rect_height(&state->base.dst));
11326 static bool check_digital_port_conflicts(struct drm_atomic_state *state)
11328 struct drm_device *dev = state->dev;
11329 struct drm_connector *connector;
11330 struct drm_connector_list_iter conn_iter;
11331 unsigned int used_ports = 0;
11332 unsigned int used_mst_ports = 0;
11336 * Walk the connector list instead of the encoder
11337 * list to detect the problem on ddi platforms
11338 * where there's just one encoder per digital port.
11340 drm_connector_list_iter_begin(dev, &conn_iter);
11341 drm_for_each_connector_iter(connector, &conn_iter) {
11342 struct drm_connector_state *connector_state;
11343 struct intel_encoder *encoder;
11345 connector_state = drm_atomic_get_new_connector_state(state, connector);
11346 if (!connector_state)
11347 connector_state = connector->state;
11349 if (!connector_state->best_encoder)
11352 encoder = to_intel_encoder(connector_state->best_encoder);
11354 WARN_ON(!connector_state->crtc);
11356 switch (encoder->type) {
11357 unsigned int port_mask;
11358 case INTEL_OUTPUT_DDI:
11359 if (WARN_ON(!HAS_DDI(to_i915(dev))))
11361 /* else: fall through */
11362 case INTEL_OUTPUT_DP:
11363 case INTEL_OUTPUT_HDMI:
11364 case INTEL_OUTPUT_EDP:
11365 port_mask = 1 << encoder->port;
11367 /* the same port mustn't appear more than once */
11368 if (used_ports & port_mask)
11371 used_ports |= port_mask;
11373 case INTEL_OUTPUT_DP_MST:
11375 1 << encoder->port;
11381 drm_connector_list_iter_end(&conn_iter);
11383 /* can't mix MST and SST/HDMI on the same port */
11384 if (used_ports & used_mst_ports)
11391 clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
11393 struct drm_i915_private *dev_priv =
11394 to_i915(crtc_state->base.crtc->dev);
11395 struct intel_crtc_scaler_state scaler_state;
11396 struct intel_dpll_hw_state dpll_hw_state;
11397 struct intel_shared_dpll *shared_dpll;
11398 struct intel_crtc_wm_state wm_state;
11399 bool force_thru, ips_force_disable;
11401 /* FIXME: before the switch to atomic started, a new pipe_config was
11402 * kzalloc'd. Code that depends on any field being zero should be
11403 * fixed, so that the crtc_state can be safely duplicated. For now,
11404 * only fields that are know to not cause problems are preserved. */
11406 scaler_state = crtc_state->scaler_state;
11407 shared_dpll = crtc_state->shared_dpll;
11408 dpll_hw_state = crtc_state->dpll_hw_state;
11409 force_thru = crtc_state->pch_pfit.force_thru;
11410 ips_force_disable = crtc_state->ips_force_disable;
11411 if (IS_G4X(dev_priv) ||
11412 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11413 wm_state = crtc_state->wm;
11415 /* Keep base drm_crtc_state intact, only clear our extended struct */
11416 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
11417 memset(&crtc_state->base + 1, 0,
11418 sizeof(*crtc_state) - sizeof(crtc_state->base));
11420 crtc_state->scaler_state = scaler_state;
11421 crtc_state->shared_dpll = shared_dpll;
11422 crtc_state->dpll_hw_state = dpll_hw_state;
11423 crtc_state->pch_pfit.force_thru = force_thru;
11424 crtc_state->ips_force_disable = ips_force_disable;
11425 if (IS_G4X(dev_priv) ||
11426 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11427 crtc_state->wm = wm_state;
11431 intel_modeset_pipe_config(struct drm_crtc *crtc,
11432 struct intel_crtc_state *pipe_config)
11434 struct drm_atomic_state *state = pipe_config->base.state;
11435 struct intel_encoder *encoder;
11436 struct drm_connector *connector;
11437 struct drm_connector_state *connector_state;
11442 clear_intel_crtc_state(pipe_config);
11444 pipe_config->cpu_transcoder =
11445 (enum transcoder) to_intel_crtc(crtc)->pipe;
11448 * Sanitize sync polarity flags based on requested ones. If neither
11449 * positive or negative polarity is requested, treat this as meaning
11450 * negative polarity.
11452 if (!(pipe_config->base.adjusted_mode.flags &
11453 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
11454 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
11456 if (!(pipe_config->base.adjusted_mode.flags &
11457 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
11458 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
11460 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
11465 base_bpp = pipe_config->pipe_bpp;
11468 * Determine the real pipe dimensions. Note that stereo modes can
11469 * increase the actual pipe size due to the frame doubling and
11470 * insertion of additional space for blanks between the frame. This
11471 * is stored in the crtc timings. We use the requested mode to do this
11472 * computation to clearly distinguish it from the adjusted mode, which
11473 * can be changed by the connectors in the below retry loop.
11475 drm_mode_get_hv_timing(&pipe_config->base.mode,
11476 &pipe_config->pipe_src_w,
11477 &pipe_config->pipe_src_h);
11479 for_each_new_connector_in_state(state, connector, connector_state, i) {
11480 if (connector_state->crtc != crtc)
11483 encoder = to_intel_encoder(connector_state->best_encoder);
11485 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
11486 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
11491 * Determine output_types before calling the .compute_config()
11492 * hooks so that the hooks can use this information safely.
11494 if (encoder->compute_output_type)
11495 pipe_config->output_types |=
11496 BIT(encoder->compute_output_type(encoder, pipe_config,
11499 pipe_config->output_types |= BIT(encoder->type);
11503 /* Ensure the port clock defaults are reset when retrying. */
11504 pipe_config->port_clock = 0;
11505 pipe_config->pixel_multiplier = 1;
11507 /* Fill in default crtc timings, allow encoders to overwrite them. */
11508 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
11509 CRTC_STEREO_DOUBLE);
11511 /* Pass our mode to the connectors and the CRTC to give them a chance to
11512 * adjust it according to limitations or connector properties, and also
11513 * a chance to reject the mode entirely.
11515 for_each_new_connector_in_state(state, connector, connector_state, i) {
11516 if (connector_state->crtc != crtc)
11519 encoder = to_intel_encoder(connector_state->best_encoder);
11521 if (!(encoder->compute_config(encoder, pipe_config, connector_state))) {
11522 DRM_DEBUG_KMS("Encoder config failure\n");
11527 /* Set default port clock if not overwritten by the encoder. Needs to be
11528 * done afterwards in case the encoder adjusts the mode. */
11529 if (!pipe_config->port_clock)
11530 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
11531 * pipe_config->pixel_multiplier;
11533 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
11534 if (ret == -EDEADLK)
11537 DRM_DEBUG_KMS("CRTC fixup failed\n");
11541 if (ret == RETRY) {
11542 if (WARN(!retry, "loop in pipe configuration computation\n"))
11545 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11547 goto encoder_retry;
11550 /* Dithering seems to not pass-through bits correctly when it should, so
11551 * only enable it on 6bpc panels and when its not a compliance
11552 * test requesting 6bpc video pattern.
11554 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
11555 !pipe_config->dither_force_disable;
11556 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
11557 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
11562 static bool intel_fuzzy_clock_check(int clock1, int clock2)
11566 if (clock1 == clock2)
11569 if (!clock1 || !clock2)
11572 diff = abs(clock1 - clock2);
11574 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
11581 intel_compare_m_n(unsigned int m, unsigned int n,
11582 unsigned int m2, unsigned int n2,
11585 if (m == m2 && n == n2)
11588 if (exact || !m || !n || !m2 || !n2)
11591 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
11598 } else if (n < n2) {
11608 return intel_fuzzy_clock_check(m, m2);
11612 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
11613 struct intel_link_m_n *m2_n2,
11616 if (m_n->tu == m2_n2->tu &&
11617 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
11618 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
11619 intel_compare_m_n(m_n->link_m, m_n->link_n,
11620 m2_n2->link_m, m2_n2->link_n, !adjust)) {
11630 static void __printf(3, 4)
11631 pipe_config_err(bool adjust, const char *name, const char *format, ...)
11633 struct va_format vaf;
11636 va_start(args, format);
11641 drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf);
11643 drm_err("mismatch in %s %pV", name, &vaf);
11649 intel_pipe_config_compare(struct drm_i915_private *dev_priv,
11650 struct intel_crtc_state *current_config,
11651 struct intel_crtc_state *pipe_config,
11655 bool fixup_inherited = adjust &&
11656 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
11657 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
11659 #define PIPE_CONF_CHECK_X(name) do { \
11660 if (current_config->name != pipe_config->name) { \
11661 pipe_config_err(adjust, __stringify(name), \
11662 "(expected 0x%08x, found 0x%08x)\n", \
11663 current_config->name, \
11664 pipe_config->name); \
11669 #define PIPE_CONF_CHECK_I(name) do { \
11670 if (current_config->name != pipe_config->name) { \
11671 pipe_config_err(adjust, __stringify(name), \
11672 "(expected %i, found %i)\n", \
11673 current_config->name, \
11674 pipe_config->name); \
11679 #define PIPE_CONF_CHECK_BOOL(name) do { \
11680 if (current_config->name != pipe_config->name) { \
11681 pipe_config_err(adjust, __stringify(name), \
11682 "(expected %s, found %s)\n", \
11683 yesno(current_config->name), \
11684 yesno(pipe_config->name)); \
11690 * Checks state where we only read out the enabling, but not the entire
11691 * state itself (like full infoframes or ELD for audio). These states
11692 * require a full modeset on bootup to fix up.
11694 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
11695 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11696 PIPE_CONF_CHECK_BOOL(name); \
11698 pipe_config_err(adjust, __stringify(name), \
11699 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
11700 yesno(current_config->name), \
11701 yesno(pipe_config->name)); \
11706 #define PIPE_CONF_CHECK_P(name) do { \
11707 if (current_config->name != pipe_config->name) { \
11708 pipe_config_err(adjust, __stringify(name), \
11709 "(expected %p, found %p)\n", \
11710 current_config->name, \
11711 pipe_config->name); \
11716 #define PIPE_CONF_CHECK_M_N(name) do { \
11717 if (!intel_compare_link_m_n(¤t_config->name, \
11718 &pipe_config->name,\
11720 pipe_config_err(adjust, __stringify(name), \
11721 "(expected tu %i gmch %i/%i link %i/%i, " \
11722 "found tu %i, gmch %i/%i link %i/%i)\n", \
11723 current_config->name.tu, \
11724 current_config->name.gmch_m, \
11725 current_config->name.gmch_n, \
11726 current_config->name.link_m, \
11727 current_config->name.link_n, \
11728 pipe_config->name.tu, \
11729 pipe_config->name.gmch_m, \
11730 pipe_config->name.gmch_n, \
11731 pipe_config->name.link_m, \
11732 pipe_config->name.link_n); \
11737 /* This is required for BDW+ where there is only one set of registers for
11738 * switching between high and low RR.
11739 * This macro can be used whenever a comparison has to be made between one
11740 * hw state and multiple sw state variables.
11742 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
11743 if (!intel_compare_link_m_n(¤t_config->name, \
11744 &pipe_config->name, adjust) && \
11745 !intel_compare_link_m_n(¤t_config->alt_name, \
11746 &pipe_config->name, adjust)) { \
11747 pipe_config_err(adjust, __stringify(name), \
11748 "(expected tu %i gmch %i/%i link %i/%i, " \
11749 "or tu %i gmch %i/%i link %i/%i, " \
11750 "found tu %i, gmch %i/%i link %i/%i)\n", \
11751 current_config->name.tu, \
11752 current_config->name.gmch_m, \
11753 current_config->name.gmch_n, \
11754 current_config->name.link_m, \
11755 current_config->name.link_n, \
11756 current_config->alt_name.tu, \
11757 current_config->alt_name.gmch_m, \
11758 current_config->alt_name.gmch_n, \
11759 current_config->alt_name.link_m, \
11760 current_config->alt_name.link_n, \
11761 pipe_config->name.tu, \
11762 pipe_config->name.gmch_m, \
11763 pipe_config->name.gmch_n, \
11764 pipe_config->name.link_m, \
11765 pipe_config->name.link_n); \
11770 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
11771 if ((current_config->name ^ pipe_config->name) & (mask)) { \
11772 pipe_config_err(adjust, __stringify(name), \
11773 "(%x) (expected %i, found %i)\n", \
11775 current_config->name & (mask), \
11776 pipe_config->name & (mask)); \
11781 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
11782 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
11783 pipe_config_err(adjust, __stringify(name), \
11784 "(expected %i, found %i)\n", \
11785 current_config->name, \
11786 pipe_config->name); \
11791 #define PIPE_CONF_QUIRK(quirk) \
11792 ((current_config->quirks | pipe_config->quirks) & (quirk))
11794 PIPE_CONF_CHECK_I(cpu_transcoder);
11796 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
11797 PIPE_CONF_CHECK_I(fdi_lanes);
11798 PIPE_CONF_CHECK_M_N(fdi_m_n);
11800 PIPE_CONF_CHECK_I(lane_count);
11801 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
11803 if (INTEL_GEN(dev_priv) < 8) {
11804 PIPE_CONF_CHECK_M_N(dp_m_n);
11806 if (current_config->has_drrs)
11807 PIPE_CONF_CHECK_M_N(dp_m2_n2);
11809 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
11811 PIPE_CONF_CHECK_X(output_types);
11813 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
11814 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
11815 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
11816 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
11817 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
11818 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
11820 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
11821 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
11822 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
11823 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
11824 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
11825 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
11827 PIPE_CONF_CHECK_I(pixel_multiplier);
11828 PIPE_CONF_CHECK_I(output_format);
11829 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
11830 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
11831 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11832 PIPE_CONF_CHECK_BOOL(limited_color_range);
11834 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
11835 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
11836 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
11838 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
11840 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11841 DRM_MODE_FLAG_INTERLACE);
11843 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
11844 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11845 DRM_MODE_FLAG_PHSYNC);
11846 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11847 DRM_MODE_FLAG_NHSYNC);
11848 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11849 DRM_MODE_FLAG_PVSYNC);
11850 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11851 DRM_MODE_FLAG_NVSYNC);
11854 PIPE_CONF_CHECK_X(gmch_pfit.control);
11855 /* pfit ratios are autocomputed by the hw on gen4+ */
11856 if (INTEL_GEN(dev_priv) < 4)
11857 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
11858 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
11861 PIPE_CONF_CHECK_I(pipe_src_w);
11862 PIPE_CONF_CHECK_I(pipe_src_h);
11864 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
11865 if (current_config->pch_pfit.enabled) {
11866 PIPE_CONF_CHECK_X(pch_pfit.pos);
11867 PIPE_CONF_CHECK_X(pch_pfit.size);
11870 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
11871 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
11874 PIPE_CONF_CHECK_BOOL(double_wide);
11876 PIPE_CONF_CHECK_P(shared_dpll);
11877 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
11878 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
11879 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
11880 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
11881 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
11882 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
11883 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
11884 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
11885 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
11886 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
11887 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
11888 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
11889 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
11890 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
11891 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
11892 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
11893 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
11894 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
11895 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
11896 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
11897 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
11898 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
11899 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
11900 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
11901 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
11902 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
11903 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
11904 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
11905 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
11906 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
11907 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
11909 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
11910 PIPE_CONF_CHECK_X(dsi_pll.div);
11912 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
11913 PIPE_CONF_CHECK_I(pipe_bpp);
11915 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
11916 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
11918 PIPE_CONF_CHECK_I(min_voltage_level);
11920 #undef PIPE_CONF_CHECK_X
11921 #undef PIPE_CONF_CHECK_I
11922 #undef PIPE_CONF_CHECK_BOOL
11923 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
11924 #undef PIPE_CONF_CHECK_P
11925 #undef PIPE_CONF_CHECK_FLAGS
11926 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
11927 #undef PIPE_CONF_QUIRK
11932 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
11933 const struct intel_crtc_state *pipe_config)
11935 if (pipe_config->has_pch_encoder) {
11936 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
11937 &pipe_config->fdi_m_n);
11938 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
11941 * FDI already provided one idea for the dotclock.
11942 * Yell if the encoder disagrees.
11944 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
11945 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11946 fdi_dotclock, dotclock);
11950 static void verify_wm_state(struct drm_crtc *crtc,
11951 struct drm_crtc_state *new_state)
11953 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
11954 struct skl_ddb_allocation hw_ddb, *sw_ddb;
11955 struct skl_pipe_wm hw_wm, *sw_wm;
11956 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
11957 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
11958 struct skl_ddb_entry hw_ddb_y[I915_MAX_PLANES];
11959 struct skl_ddb_entry hw_ddb_uv[I915_MAX_PLANES];
11960 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11961 const enum pipe pipe = intel_crtc->pipe;
11962 int plane, level, max_level = ilk_wm_max_level(dev_priv);
11964 if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
11967 skl_pipe_wm_get_hw_state(crtc, &hw_wm);
11968 sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
11970 skl_pipe_ddb_get_hw_state(intel_crtc, hw_ddb_y, hw_ddb_uv);
11972 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
11973 sw_ddb = &dev_priv->wm.skl_hw.ddb;
11975 if (INTEL_GEN(dev_priv) >= 11)
11976 if (hw_ddb.enabled_slices != sw_ddb->enabled_slices)
11977 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
11978 sw_ddb->enabled_slices,
11979 hw_ddb.enabled_slices);
11981 for_each_universal_plane(dev_priv, pipe, plane) {
11982 hw_plane_wm = &hw_wm.planes[plane];
11983 sw_plane_wm = &sw_wm->planes[plane];
11986 for (level = 0; level <= max_level; level++) {
11987 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11988 &sw_plane_wm->wm[level]))
11991 DRM_ERROR("mismatch in WM pipe %c plane %d level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11992 pipe_name(pipe), plane + 1, level,
11993 sw_plane_wm->wm[level].plane_en,
11994 sw_plane_wm->wm[level].plane_res_b,
11995 sw_plane_wm->wm[level].plane_res_l,
11996 hw_plane_wm->wm[level].plane_en,
11997 hw_plane_wm->wm[level].plane_res_b,
11998 hw_plane_wm->wm[level].plane_res_l);
12001 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12002 &sw_plane_wm->trans_wm)) {
12003 DRM_ERROR("mismatch in trans WM pipe %c plane %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
12004 pipe_name(pipe), plane + 1,
12005 sw_plane_wm->trans_wm.plane_en,
12006 sw_plane_wm->trans_wm.plane_res_b,
12007 sw_plane_wm->trans_wm.plane_res_l,
12008 hw_plane_wm->trans_wm.plane_en,
12009 hw_plane_wm->trans_wm.plane_res_b,
12010 hw_plane_wm->trans_wm.plane_res_l);
12014 hw_ddb_entry = &hw_ddb_y[plane];
12015 sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[plane];
12017 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
12018 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
12019 pipe_name(pipe), plane + 1,
12020 sw_ddb_entry->start, sw_ddb_entry->end,
12021 hw_ddb_entry->start, hw_ddb_entry->end);
12027 * If the cursor plane isn't active, we may not have updated it's ddb
12028 * allocation. In that case since the ddb allocation will be updated
12029 * once the plane becomes visible, we can skip this check
12032 hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
12033 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
12036 for (level = 0; level <= max_level; level++) {
12037 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
12038 &sw_plane_wm->wm[level]))
12041 DRM_ERROR("mismatch in WM pipe %c cursor level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
12042 pipe_name(pipe), level,
12043 sw_plane_wm->wm[level].plane_en,
12044 sw_plane_wm->wm[level].plane_res_b,
12045 sw_plane_wm->wm[level].plane_res_l,
12046 hw_plane_wm->wm[level].plane_en,
12047 hw_plane_wm->wm[level].plane_res_b,
12048 hw_plane_wm->wm[level].plane_res_l);
12051 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12052 &sw_plane_wm->trans_wm)) {
12053 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
12055 sw_plane_wm->trans_wm.plane_en,
12056 sw_plane_wm->trans_wm.plane_res_b,
12057 sw_plane_wm->trans_wm.plane_res_l,
12058 hw_plane_wm->trans_wm.plane_en,
12059 hw_plane_wm->trans_wm.plane_res_b,
12060 hw_plane_wm->trans_wm.plane_res_l);
12064 hw_ddb_entry = &hw_ddb_y[PLANE_CURSOR];
12065 sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[PLANE_CURSOR];
12067 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
12068 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
12070 sw_ddb_entry->start, sw_ddb_entry->end,
12071 hw_ddb_entry->start, hw_ddb_entry->end);
12077 verify_connector_state(struct drm_device *dev,
12078 struct drm_atomic_state *state,
12079 struct drm_crtc *crtc)
12081 struct drm_connector *connector;
12082 struct drm_connector_state *new_conn_state;
12085 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
12086 struct drm_encoder *encoder = connector->encoder;
12087 struct drm_crtc_state *crtc_state = NULL;
12089 if (new_conn_state->crtc != crtc)
12093 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
12095 intel_connector_verify_state(crtc_state, new_conn_state);
12097 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
12098 "connector's atomic encoder doesn't match legacy encoder\n");
12103 verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
12105 struct intel_encoder *encoder;
12106 struct drm_connector *connector;
12107 struct drm_connector_state *old_conn_state, *new_conn_state;
12110 for_each_intel_encoder(dev, encoder) {
12111 bool enabled = false, found = false;
12114 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
12115 encoder->base.base.id,
12116 encoder->base.name);
12118 for_each_oldnew_connector_in_state(state, connector, old_conn_state,
12119 new_conn_state, i) {
12120 if (old_conn_state->best_encoder == &encoder->base)
12123 if (new_conn_state->best_encoder != &encoder->base)
12125 found = enabled = true;
12127 I915_STATE_WARN(new_conn_state->crtc !=
12128 encoder->base.crtc,
12129 "connector's crtc doesn't match encoder crtc\n");
12135 I915_STATE_WARN(!!encoder->base.crtc != enabled,
12136 "encoder's enabled state mismatch "
12137 "(expected %i, found %i)\n",
12138 !!encoder->base.crtc, enabled);
12140 if (!encoder->base.crtc) {
12143 active = encoder->get_hw_state(encoder, &pipe);
12144 I915_STATE_WARN(active,
12145 "encoder detached but still enabled on pipe %c.\n",
12152 verify_crtc_state(struct drm_crtc *crtc,
12153 struct drm_crtc_state *old_crtc_state,
12154 struct drm_crtc_state *new_crtc_state)
12156 struct drm_device *dev = crtc->dev;
12157 struct drm_i915_private *dev_priv = to_i915(dev);
12158 struct intel_encoder *encoder;
12159 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12160 struct intel_crtc_state *pipe_config, *sw_config;
12161 struct drm_atomic_state *old_state;
12164 old_state = old_crtc_state->state;
12165 __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
12166 pipe_config = to_intel_crtc_state(old_crtc_state);
12167 memset(pipe_config, 0, sizeof(*pipe_config));
12168 pipe_config->base.crtc = crtc;
12169 pipe_config->base.state = old_state;
12171 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
12173 active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
12175 /* we keep both pipes enabled on 830 */
12176 if (IS_I830(dev_priv))
12177 active = new_crtc_state->active;
12179 I915_STATE_WARN(new_crtc_state->active != active,
12180 "crtc active state doesn't match with hw state "
12181 "(expected %i, found %i)\n", new_crtc_state->active, active);
12183 I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
12184 "transitional active state does not match atomic hw state "
12185 "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
12187 for_each_encoder_on_crtc(dev, crtc, encoder) {
12190 active = encoder->get_hw_state(encoder, &pipe);
12191 I915_STATE_WARN(active != new_crtc_state->active,
12192 "[ENCODER:%i] active %i with crtc active %i\n",
12193 encoder->base.base.id, active, new_crtc_state->active);
12195 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
12196 "Encoder connected to wrong pipe %c\n",
12200 encoder->get_config(encoder, pipe_config);
12203 intel_crtc_compute_pixel_rate(pipe_config);
12205 if (!new_crtc_state->active)
12208 intel_pipe_config_sanity_check(dev_priv, pipe_config);
12210 sw_config = to_intel_crtc_state(new_crtc_state);
12211 if (!intel_pipe_config_compare(dev_priv, sw_config,
12212 pipe_config, false)) {
12213 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12214 intel_dump_pipe_config(intel_crtc, pipe_config,
12216 intel_dump_pipe_config(intel_crtc, sw_config,
12222 intel_verify_planes(struct intel_atomic_state *state)
12224 struct intel_plane *plane;
12225 const struct intel_plane_state *plane_state;
12228 for_each_new_intel_plane_in_state(state, plane,
12230 assert_plane(plane, plane_state->base.visible);
12234 verify_single_dpll_state(struct drm_i915_private *dev_priv,
12235 struct intel_shared_dpll *pll,
12236 struct drm_crtc *crtc,
12237 struct drm_crtc_state *new_state)
12239 struct intel_dpll_hw_state dpll_hw_state;
12240 unsigned int crtc_mask;
12243 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
12245 DRM_DEBUG_KMS("%s\n", pll->info->name);
12247 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
12249 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
12250 I915_STATE_WARN(!pll->on && pll->active_mask,
12251 "pll in active use but not on in sw tracking\n");
12252 I915_STATE_WARN(pll->on && !pll->active_mask,
12253 "pll is on but not used by any active crtc\n");
12254 I915_STATE_WARN(pll->on != active,
12255 "pll on state mismatch (expected %i, found %i)\n",
12260 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
12261 "more active pll users than references: %x vs %x\n",
12262 pll->active_mask, pll->state.crtc_mask);
12267 crtc_mask = drm_crtc_mask(crtc);
12269 if (new_state->active)
12270 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
12271 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
12272 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12274 I915_STATE_WARN(pll->active_mask & crtc_mask,
12275 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
12276 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12278 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
12279 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
12280 crtc_mask, pll->state.crtc_mask);
12282 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
12284 sizeof(dpll_hw_state)),
12285 "pll hw state mismatch\n");
12289 verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
12290 struct drm_crtc_state *old_crtc_state,
12291 struct drm_crtc_state *new_crtc_state)
12293 struct drm_i915_private *dev_priv = to_i915(dev);
12294 struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
12295 struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
12297 if (new_state->shared_dpll)
12298 verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
12300 if (old_state->shared_dpll &&
12301 old_state->shared_dpll != new_state->shared_dpll) {
12302 unsigned int crtc_mask = drm_crtc_mask(crtc);
12303 struct intel_shared_dpll *pll = old_state->shared_dpll;
12305 I915_STATE_WARN(pll->active_mask & crtc_mask,
12306 "pll active mismatch (didn't expect pipe %c in active mask)\n",
12307 pipe_name(drm_crtc_index(crtc)));
12308 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
12309 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
12310 pipe_name(drm_crtc_index(crtc)));
12315 intel_modeset_verify_crtc(struct drm_crtc *crtc,
12316 struct drm_atomic_state *state,
12317 struct drm_crtc_state *old_state,
12318 struct drm_crtc_state *new_state)
12320 if (!needs_modeset(new_state) &&
12321 !to_intel_crtc_state(new_state)->update_pipe)
12324 verify_wm_state(crtc, new_state);
12325 verify_connector_state(crtc->dev, state, crtc);
12326 verify_crtc_state(crtc, old_state, new_state);
12327 verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
12331 verify_disabled_dpll_state(struct drm_device *dev)
12333 struct drm_i915_private *dev_priv = to_i915(dev);
12336 for (i = 0; i < dev_priv->num_shared_dpll; i++)
12337 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
12341 intel_modeset_verify_disabled(struct drm_device *dev,
12342 struct drm_atomic_state *state)
12344 verify_encoder_state(dev, state);
12345 verify_connector_state(dev, state, NULL);
12346 verify_disabled_dpll_state(dev);
12349 static void update_scanline_offset(const struct intel_crtc_state *crtc_state)
12351 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
12352 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12355 * The scanline counter increments at the leading edge of hsync.
12357 * On most platforms it starts counting from vtotal-1 on the
12358 * first active line. That means the scanline counter value is
12359 * always one less than what we would expect. Ie. just after
12360 * start of vblank, which also occurs at start of hsync (on the
12361 * last active line), the scanline counter will read vblank_start-1.
12363 * On gen2 the scanline counter starts counting from 1 instead
12364 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12365 * to keep the value positive), instead of adding one.
12367 * On HSW+ the behaviour of the scanline counter depends on the output
12368 * type. For DP ports it behaves like most other platforms, but on HDMI
12369 * there's an extra 1 line difference. So we need to add two instead of
12370 * one to the value.
12372 * On VLV/CHV DSI the scanline counter would appear to increment
12373 * approx. 1/3 of a scanline before start of vblank. Unfortunately
12374 * that means we can't tell whether we're in vblank or not while
12375 * we're on that particular line. We must still set scanline_offset
12376 * to 1 so that the vblank timestamps come out correct when we query
12377 * the scanline counter from within the vblank interrupt handler.
12378 * However if queried just before the start of vblank we'll get an
12379 * answer that's slightly in the future.
12381 if (IS_GEN2(dev_priv)) {
12382 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
12385 vtotal = adjusted_mode->crtc_vtotal;
12386 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
12389 crtc->scanline_offset = vtotal - 1;
12390 } else if (HAS_DDI(dev_priv) &&
12391 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
12392 crtc->scanline_offset = 2;
12394 crtc->scanline_offset = 1;
12397 static void intel_modeset_clear_plls(struct drm_atomic_state *state)
12399 struct drm_device *dev = state->dev;
12400 struct drm_i915_private *dev_priv = to_i915(dev);
12401 struct drm_crtc *crtc;
12402 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12405 if (!dev_priv->display.crtc_compute_clock)
12408 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12409 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12410 struct intel_shared_dpll *old_dpll =
12411 to_intel_crtc_state(old_crtc_state)->shared_dpll;
12413 if (!needs_modeset(new_crtc_state))
12416 to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
12421 intel_release_shared_dpll(old_dpll, intel_crtc, state);
12426 * This implements the workaround described in the "notes" section of the mode
12427 * set sequence documentation. When going from no pipes or single pipe to
12428 * multiple pipes, and planes are enabled after the pipe, we need to wait at
12429 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
12431 static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
12433 struct drm_crtc_state *crtc_state;
12434 struct intel_crtc *intel_crtc;
12435 struct drm_crtc *crtc;
12436 struct intel_crtc_state *first_crtc_state = NULL;
12437 struct intel_crtc_state *other_crtc_state = NULL;
12438 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
12441 /* look at all crtc's that are going to be enabled in during modeset */
12442 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
12443 intel_crtc = to_intel_crtc(crtc);
12445 if (!crtc_state->active || !needs_modeset(crtc_state))
12448 if (first_crtc_state) {
12449 other_crtc_state = to_intel_crtc_state(crtc_state);
12452 first_crtc_state = to_intel_crtc_state(crtc_state);
12453 first_pipe = intel_crtc->pipe;
12457 /* No workaround needed? */
12458 if (!first_crtc_state)
12461 /* w/a possibly needed, check how many crtc's are already enabled. */
12462 for_each_intel_crtc(state->dev, intel_crtc) {
12463 struct intel_crtc_state *pipe_config;
12465 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
12466 if (IS_ERR(pipe_config))
12467 return PTR_ERR(pipe_config);
12469 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
12471 if (!pipe_config->base.active ||
12472 needs_modeset(&pipe_config->base))
12475 /* 2 or more enabled crtcs means no need for w/a */
12476 if (enabled_pipe != INVALID_PIPE)
12479 enabled_pipe = intel_crtc->pipe;
12482 if (enabled_pipe != INVALID_PIPE)
12483 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
12484 else if (other_crtc_state)
12485 other_crtc_state->hsw_workaround_pipe = first_pipe;
12490 static int intel_lock_all_pipes(struct drm_atomic_state *state)
12492 struct drm_crtc *crtc;
12494 /* Add all pipes to the state */
12495 for_each_crtc(state->dev, crtc) {
12496 struct drm_crtc_state *crtc_state;
12498 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12499 if (IS_ERR(crtc_state))
12500 return PTR_ERR(crtc_state);
12506 static int intel_modeset_all_pipes(struct drm_atomic_state *state)
12508 struct drm_crtc *crtc;
12511 * Add all pipes to the state, and force
12512 * a modeset on all the active ones.
12514 for_each_crtc(state->dev, crtc) {
12515 struct drm_crtc_state *crtc_state;
12518 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12519 if (IS_ERR(crtc_state))
12520 return PTR_ERR(crtc_state);
12522 if (!crtc_state->active || needs_modeset(crtc_state))
12525 crtc_state->mode_changed = true;
12527 ret = drm_atomic_add_affected_connectors(state, crtc);
12531 ret = drm_atomic_add_affected_planes(state, crtc);
12539 static int intel_modeset_checks(struct drm_atomic_state *state)
12541 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12542 struct drm_i915_private *dev_priv = to_i915(state->dev);
12543 struct drm_crtc *crtc;
12544 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12547 if (!check_digital_port_conflicts(state)) {
12548 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12552 intel_state->modeset = true;
12553 intel_state->active_crtcs = dev_priv->active_crtcs;
12554 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12555 intel_state->cdclk.actual = dev_priv->cdclk.actual;
12557 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12558 if (new_crtc_state->active)
12559 intel_state->active_crtcs |= 1 << i;
12561 intel_state->active_crtcs &= ~(1 << i);
12563 if (old_crtc_state->active != new_crtc_state->active)
12564 intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
12568 * See if the config requires any additional preparation, e.g.
12569 * to adjust global state with pipes off. We need to do this
12570 * here so we can get the modeset_pipe updated config for the new
12571 * mode set on this crtc. For other crtcs we need to use the
12572 * adjusted_mode bits in the crtc directly.
12574 if (dev_priv->display.modeset_calc_cdclk) {
12575 ret = dev_priv->display.modeset_calc_cdclk(state);
12580 * Writes to dev_priv->cdclk.logical must protected by
12581 * holding all the crtc locks, even if we don't end up
12582 * touching the hardware
12584 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
12585 &intel_state->cdclk.logical)) {
12586 ret = intel_lock_all_pipes(state);
12591 /* All pipes must be switched off while we change the cdclk. */
12592 if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
12593 &intel_state->cdclk.actual)) {
12594 ret = intel_modeset_all_pipes(state);
12599 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12600 intel_state->cdclk.logical.cdclk,
12601 intel_state->cdclk.actual.cdclk);
12602 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
12603 intel_state->cdclk.logical.voltage_level,
12604 intel_state->cdclk.actual.voltage_level);
12606 to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
12609 intel_modeset_clear_plls(state);
12611 if (IS_HASWELL(dev_priv))
12612 return haswell_mode_set_planes_workaround(state);
12618 * Handle calculation of various watermark data at the end of the atomic check
12619 * phase. The code here should be run after the per-crtc and per-plane 'check'
12620 * handlers to ensure that all derived state has been updated.
12622 static int calc_watermark_data(struct drm_atomic_state *state)
12624 struct drm_device *dev = state->dev;
12625 struct drm_i915_private *dev_priv = to_i915(dev);
12627 /* Is there platform-specific watermark information to calculate? */
12628 if (dev_priv->display.compute_global_watermarks)
12629 return dev_priv->display.compute_global_watermarks(state);
12635 * intel_atomic_check - validate state object
12637 * @state: state to validate
12639 static int intel_atomic_check(struct drm_device *dev,
12640 struct drm_atomic_state *state)
12642 struct drm_i915_private *dev_priv = to_i915(dev);
12643 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12644 struct drm_crtc *crtc;
12645 struct drm_crtc_state *old_crtc_state, *crtc_state;
12647 bool any_ms = false;
12649 /* Catch I915_MODE_FLAG_INHERITED */
12650 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
12652 if (crtc_state->mode.private_flags !=
12653 old_crtc_state->mode.private_flags)
12654 crtc_state->mode_changed = true;
12657 ret = drm_atomic_helper_check_modeset(dev, state);
12661 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
12662 struct intel_crtc_state *pipe_config =
12663 to_intel_crtc_state(crtc_state);
12665 if (!needs_modeset(crtc_state))
12668 if (!crtc_state->enable) {
12673 ret = intel_modeset_pipe_config(crtc, pipe_config);
12674 if (ret == -EDEADLK)
12677 intel_dump_pipe_config(to_intel_crtc(crtc),
12678 pipe_config, "[failed]");
12682 if (i915_modparams.fastboot &&
12683 intel_pipe_config_compare(dev_priv,
12684 to_intel_crtc_state(old_crtc_state),
12685 pipe_config, true)) {
12686 crtc_state->mode_changed = false;
12687 pipe_config->update_pipe = true;
12690 if (needs_modeset(crtc_state))
12693 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
12694 needs_modeset(crtc_state) ?
12695 "[modeset]" : "[fastset]");
12699 ret = intel_modeset_checks(state);
12704 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12707 ret = icl_add_linked_planes(intel_state);
12711 ret = drm_atomic_helper_check_planes(dev, state);
12715 intel_fbc_choose_crtc(dev_priv, intel_state);
12716 return calc_watermark_data(state);
12719 static int intel_atomic_prepare_commit(struct drm_device *dev,
12720 struct drm_atomic_state *state)
12722 return drm_atomic_helper_prepare_planes(dev, state);
12725 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
12727 struct drm_device *dev = crtc->base.dev;
12729 if (!dev->max_vblank_count)
12730 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
12732 return dev->driver->get_vblank_counter(dev, crtc->pipe);
12735 static void intel_update_crtc(struct drm_crtc *crtc,
12736 struct drm_atomic_state *state,
12737 struct drm_crtc_state *old_crtc_state,
12738 struct drm_crtc_state *new_crtc_state)
12740 struct drm_device *dev = crtc->dev;
12741 struct drm_i915_private *dev_priv = to_i915(dev);
12742 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12743 struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
12744 bool modeset = needs_modeset(new_crtc_state);
12745 struct intel_plane_state *new_plane_state =
12746 intel_atomic_get_new_plane_state(to_intel_atomic_state(state),
12747 to_intel_plane(crtc->primary));
12750 update_scanline_offset(pipe_config);
12751 dev_priv->display.crtc_enable(pipe_config, state);
12753 /* vblanks work again, re-enable pipe CRC. */
12754 intel_crtc_enable_pipe_crc(intel_crtc);
12756 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12760 if (new_plane_state)
12761 intel_fbc_enable(intel_crtc, pipe_config, new_plane_state);
12763 intel_begin_crtc_commit(crtc, old_crtc_state);
12765 if (INTEL_GEN(dev_priv) >= 9)
12766 skl_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc);
12768 i9xx_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc);
12770 intel_finish_crtc_commit(crtc, old_crtc_state);
12773 static void intel_update_crtcs(struct drm_atomic_state *state)
12775 struct drm_crtc *crtc;
12776 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12779 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12780 if (!new_crtc_state->active)
12783 intel_update_crtc(crtc, state, old_crtc_state,
12788 static void skl_update_crtcs(struct drm_atomic_state *state)
12790 struct drm_i915_private *dev_priv = to_i915(state->dev);
12791 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12792 struct drm_crtc *crtc;
12793 struct intel_crtc *intel_crtc;
12794 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12795 struct intel_crtc_state *cstate;
12796 unsigned int updated = 0;
12800 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
12801 u8 required_slices = intel_state->wm_results.ddb.enabled_slices;
12802 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
12804 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
12805 /* ignore allocations for crtc's that have been turned off. */
12806 if (new_crtc_state->active)
12807 entries[i] = to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
12809 /* If 2nd DBuf slice required, enable it here */
12810 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
12811 icl_dbuf_slices_update(dev_priv, required_slices);
12814 * Whenever the number of active pipes changes, we need to make sure we
12815 * update the pipes in the right order so that their ddb allocations
12816 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
12817 * cause pipe underruns and other bad stuff.
12822 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12823 bool vbl_wait = false;
12824 unsigned int cmask = drm_crtc_mask(crtc);
12826 intel_crtc = to_intel_crtc(crtc);
12827 cstate = to_intel_crtc_state(new_crtc_state);
12828 pipe = intel_crtc->pipe;
12830 if (updated & cmask || !cstate->base.active)
12833 if (skl_ddb_allocation_overlaps(&cstate->wm.skl.ddb,
12835 INTEL_INFO(dev_priv)->num_pipes, i))
12839 entries[i] = cstate->wm.skl.ddb;
12842 * If this is an already active pipe, it's DDB changed,
12843 * and this isn't the last pipe that needs updating
12844 * then we need to wait for a vblank to pass for the
12845 * new ddb allocation to take effect.
12847 if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
12848 &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
12849 !new_crtc_state->active_changed &&
12850 intel_state->wm_results.dirty_pipes != updated)
12853 intel_update_crtc(crtc, state, old_crtc_state,
12857 intel_wait_for_vblank(dev_priv, pipe);
12861 } while (progress);
12863 /* If 2nd DBuf slice is no more required disable it */
12864 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
12865 icl_dbuf_slices_update(dev_priv, required_slices);
12868 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
12870 struct intel_atomic_state *state, *next;
12871 struct llist_node *freed;
12873 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
12874 llist_for_each_entry_safe(state, next, freed, freed)
12875 drm_atomic_state_put(&state->base);
12878 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
12880 struct drm_i915_private *dev_priv =
12881 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
12883 intel_atomic_helper_free_state(dev_priv);
12886 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
12888 struct wait_queue_entry wait_fence, wait_reset;
12889 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
12891 init_wait_entry(&wait_fence, 0);
12892 init_wait_entry(&wait_reset, 0);
12894 prepare_to_wait(&intel_state->commit_ready.wait,
12895 &wait_fence, TASK_UNINTERRUPTIBLE);
12896 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
12897 &wait_reset, TASK_UNINTERRUPTIBLE);
12900 if (i915_sw_fence_done(&intel_state->commit_ready)
12901 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
12906 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
12907 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
12910 static void intel_atomic_cleanup_work(struct work_struct *work)
12912 struct drm_atomic_state *state =
12913 container_of(work, struct drm_atomic_state, commit_work);
12914 struct drm_i915_private *i915 = to_i915(state->dev);
12916 drm_atomic_helper_cleanup_planes(&i915->drm, state);
12917 drm_atomic_helper_commit_cleanup_done(state);
12918 drm_atomic_state_put(state);
12920 intel_atomic_helper_free_state(i915);
12923 static void intel_atomic_commit_tail(struct drm_atomic_state *state)
12925 struct drm_device *dev = state->dev;
12926 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12927 struct drm_i915_private *dev_priv = to_i915(dev);
12928 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12929 struct intel_crtc_state *new_intel_crtc_state, *old_intel_crtc_state;
12930 struct drm_crtc *crtc;
12931 struct intel_crtc *intel_crtc;
12932 u64 put_domains[I915_MAX_PIPES] = {};
12935 intel_atomic_commit_fence_wait(intel_state);
12937 drm_atomic_helper_wait_for_dependencies(state);
12939 if (intel_state->modeset)
12940 intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
12942 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12943 old_intel_crtc_state = to_intel_crtc_state(old_crtc_state);
12944 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
12945 intel_crtc = to_intel_crtc(crtc);
12947 if (needs_modeset(new_crtc_state) ||
12948 to_intel_crtc_state(new_crtc_state)->update_pipe) {
12950 put_domains[intel_crtc->pipe] =
12951 modeset_get_crtc_power_domains(crtc,
12952 new_intel_crtc_state);
12955 if (!needs_modeset(new_crtc_state))
12958 intel_pre_plane_update(old_intel_crtc_state, new_intel_crtc_state);
12960 if (old_crtc_state->active) {
12961 intel_crtc_disable_planes(intel_state, intel_crtc);
12964 * We need to disable pipe CRC before disabling the pipe,
12965 * or we race against vblank off.
12967 intel_crtc_disable_pipe_crc(intel_crtc);
12969 dev_priv->display.crtc_disable(old_intel_crtc_state, state);
12970 intel_crtc->active = false;
12971 intel_fbc_disable(intel_crtc);
12972 intel_disable_shared_dpll(old_intel_crtc_state);
12975 * Underruns don't always raise
12976 * interrupts, so check manually.
12978 intel_check_cpu_fifo_underruns(dev_priv);
12979 intel_check_pch_fifo_underruns(dev_priv);
12981 /* FIXME unify this for all platforms */
12982 if (!new_crtc_state->active &&
12983 !HAS_GMCH_DISPLAY(dev_priv) &&
12984 dev_priv->display.initial_watermarks)
12985 dev_priv->display.initial_watermarks(intel_state,
12986 new_intel_crtc_state);
12990 /* FIXME: Eventually get rid of our intel_crtc->config pointer */
12991 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
12992 to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
12994 if (intel_state->modeset) {
12995 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
12997 intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
13000 * SKL workaround: bspec recommends we disable the SAGV when we
13001 * have more then one pipe enabled
13003 if (!intel_can_enable_sagv(state))
13004 intel_disable_sagv(dev_priv);
13006 intel_modeset_verify_disabled(dev, state);
13009 /* Complete the events for pipes that have now been disabled */
13010 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
13011 bool modeset = needs_modeset(new_crtc_state);
13013 /* Complete events for now disable pipes here. */
13014 if (modeset && !new_crtc_state->active && new_crtc_state->event) {
13015 spin_lock_irq(&dev->event_lock);
13016 drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
13017 spin_unlock_irq(&dev->event_lock);
13019 new_crtc_state->event = NULL;
13023 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
13024 dev_priv->display.update_crtcs(state);
13026 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
13027 * already, but still need the state for the delayed optimization. To
13029 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
13030 * - schedule that vblank worker _before_ calling hw_done
13031 * - at the start of commit_tail, cancel it _synchrously
13032 * - switch over to the vblank wait helper in the core after that since
13033 * we don't need out special handling any more.
13035 drm_atomic_helper_wait_for_flip_done(dev, state);
13038 * Now that the vblank has passed, we can go ahead and program the
13039 * optimal watermarks on platforms that need two-step watermark
13042 * TODO: Move this (and other cleanup) to an async worker eventually.
13044 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
13045 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
13047 if (dev_priv->display.optimize_watermarks)
13048 dev_priv->display.optimize_watermarks(intel_state,
13049 new_intel_crtc_state);
13052 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13053 intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
13055 if (put_domains[i])
13056 modeset_put_power_domains(dev_priv, put_domains[i]);
13058 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
13061 if (intel_state->modeset)
13062 intel_verify_planes(intel_state);
13064 if (intel_state->modeset && intel_can_enable_sagv(state))
13065 intel_enable_sagv(dev_priv);
13067 drm_atomic_helper_commit_hw_done(state);
13069 if (intel_state->modeset) {
13070 /* As one of the primary mmio accessors, KMS has a high
13071 * likelihood of triggering bugs in unclaimed access. After we
13072 * finish modesetting, see if an error has been flagged, and if
13073 * so enable debugging for the next modeset - and hope we catch
13076 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
13077 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET);
13081 * Defer the cleanup of the old state to a separate worker to not
13082 * impede the current task (userspace for blocking modesets) that
13083 * are executed inline. For out-of-line asynchronous modesets/flips,
13084 * deferring to a new worker seems overkill, but we would place a
13085 * schedule point (cond_resched()) here anyway to keep latencies
13088 INIT_WORK(&state->commit_work, intel_atomic_cleanup_work);
13089 queue_work(system_highpri_wq, &state->commit_work);
13092 static void intel_atomic_commit_work(struct work_struct *work)
13094 struct drm_atomic_state *state =
13095 container_of(work, struct drm_atomic_state, commit_work);
13097 intel_atomic_commit_tail(state);
13100 static int __i915_sw_fence_call
13101 intel_atomic_commit_ready(struct i915_sw_fence *fence,
13102 enum i915_sw_fence_notify notify)
13104 struct intel_atomic_state *state =
13105 container_of(fence, struct intel_atomic_state, commit_ready);
13108 case FENCE_COMPLETE:
13109 /* we do blocking waits in the worker, nothing to do here */
13113 struct intel_atomic_helper *helper =
13114 &to_i915(state->base.dev)->atomic_helper;
13116 if (llist_add(&state->freed, &helper->free_list))
13117 schedule_work(&helper->free_work);
13122 return NOTIFY_DONE;
13125 static void intel_atomic_track_fbs(struct drm_atomic_state *state)
13127 struct drm_plane_state *old_plane_state, *new_plane_state;
13128 struct drm_plane *plane;
13131 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
13132 i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
13133 intel_fb_obj(new_plane_state->fb),
13134 to_intel_plane(plane)->frontbuffer_bit);
13138 * intel_atomic_commit - commit validated state object
13140 * @state: the top-level driver state object
13141 * @nonblock: nonblocking commit
13143 * This function commits a top-level state object that has been validated
13144 * with drm_atomic_helper_check().
13147 * Zero for success or -errno.
13149 static int intel_atomic_commit(struct drm_device *dev,
13150 struct drm_atomic_state *state,
13153 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
13154 struct drm_i915_private *dev_priv = to_i915(dev);
13157 drm_atomic_state_get(state);
13158 i915_sw_fence_init(&intel_state->commit_ready,
13159 intel_atomic_commit_ready);
13162 * The intel_legacy_cursor_update() fast path takes care
13163 * of avoiding the vblank waits for simple cursor
13164 * movement and flips. For cursor on/off and size changes,
13165 * we want to perform the vblank waits so that watermark
13166 * updates happen during the correct frames. Gen9+ have
13167 * double buffered watermarks and so shouldn't need this.
13169 * Unset state->legacy_cursor_update before the call to
13170 * drm_atomic_helper_setup_commit() because otherwise
13171 * drm_atomic_helper_wait_for_flip_done() is a noop and
13172 * we get FIFO underruns because we didn't wait
13175 * FIXME doing watermarks and fb cleanup from a vblank worker
13176 * (assuming we had any) would solve these problems.
13178 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
13179 struct intel_crtc_state *new_crtc_state;
13180 struct intel_crtc *crtc;
13183 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
13184 if (new_crtc_state->wm.need_postvbl_update ||
13185 new_crtc_state->update_wm_post)
13186 state->legacy_cursor_update = false;
13189 ret = intel_atomic_prepare_commit(dev, state);
13191 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
13192 i915_sw_fence_commit(&intel_state->commit_ready);
13196 ret = drm_atomic_helper_setup_commit(state, nonblock);
13198 ret = drm_atomic_helper_swap_state(state, true);
13201 i915_sw_fence_commit(&intel_state->commit_ready);
13203 drm_atomic_helper_cleanup_planes(dev, state);
13206 dev_priv->wm.distrust_bios_wm = false;
13207 intel_shared_dpll_swap_state(state);
13208 intel_atomic_track_fbs(state);
13210 if (intel_state->modeset) {
13211 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
13212 sizeof(intel_state->min_cdclk));
13213 memcpy(dev_priv->min_voltage_level,
13214 intel_state->min_voltage_level,
13215 sizeof(intel_state->min_voltage_level));
13216 dev_priv->active_crtcs = intel_state->active_crtcs;
13217 dev_priv->cdclk.logical = intel_state->cdclk.logical;
13218 dev_priv->cdclk.actual = intel_state->cdclk.actual;
13221 drm_atomic_state_get(state);
13222 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
13224 i915_sw_fence_commit(&intel_state->commit_ready);
13225 if (nonblock && intel_state->modeset) {
13226 queue_work(dev_priv->modeset_wq, &state->commit_work);
13227 } else if (nonblock) {
13228 queue_work(system_unbound_wq, &state->commit_work);
13230 if (intel_state->modeset)
13231 flush_workqueue(dev_priv->modeset_wq);
13232 intel_atomic_commit_tail(state);
13238 static const struct drm_crtc_funcs intel_crtc_funcs = {
13239 .gamma_set = drm_atomic_helper_legacy_gamma_set,
13240 .set_config = drm_atomic_helper_set_config,
13241 .destroy = intel_crtc_destroy,
13242 .page_flip = drm_atomic_helper_page_flip,
13243 .atomic_duplicate_state = intel_crtc_duplicate_state,
13244 .atomic_destroy_state = intel_crtc_destroy_state,
13245 .set_crc_source = intel_crtc_set_crc_source,
13246 .verify_crc_source = intel_crtc_verify_crc_source,
13247 .get_crc_sources = intel_crtc_get_crc_sources,
13250 struct wait_rps_boost {
13251 struct wait_queue_entry wait;
13253 struct drm_crtc *crtc;
13254 struct i915_request *request;
13257 static int do_rps_boost(struct wait_queue_entry *_wait,
13258 unsigned mode, int sync, void *key)
13260 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
13261 struct i915_request *rq = wait->request;
13264 * If we missed the vblank, but the request is already running it
13265 * is reasonable to assume that it will complete before the next
13266 * vblank without our intervention, so leave RPS alone.
13268 if (!i915_request_started(rq))
13269 gen6_rps_boost(rq, NULL);
13270 i915_request_put(rq);
13272 drm_crtc_vblank_put(wait->crtc);
13274 list_del(&wait->wait.entry);
13279 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
13280 struct dma_fence *fence)
13282 struct wait_rps_boost *wait;
13284 if (!dma_fence_is_i915(fence))
13287 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
13290 if (drm_crtc_vblank_get(crtc))
13293 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
13295 drm_crtc_vblank_put(crtc);
13299 wait->request = to_request(dma_fence_get(fence));
13302 wait->wait.func = do_rps_boost;
13303 wait->wait.flags = 0;
13305 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
13308 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
13310 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
13311 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
13312 struct drm_framebuffer *fb = plane_state->base.fb;
13313 struct i915_vma *vma;
13315 if (plane->id == PLANE_CURSOR &&
13316 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
13317 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13318 const int align = intel_cursor_alignment(dev_priv);
13321 err = i915_gem_object_attach_phys(obj, align);
13326 vma = intel_pin_and_fence_fb_obj(fb,
13327 &plane_state->view,
13328 intel_plane_uses_fence(plane_state),
13329 &plane_state->flags);
13331 return PTR_ERR(vma);
13333 plane_state->vma = vma;
13338 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
13340 struct i915_vma *vma;
13342 vma = fetch_and_zero(&old_plane_state->vma);
13344 intel_unpin_fb_vma(vma, old_plane_state->flags);
13347 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
13349 struct i915_sched_attr attr = {
13350 .priority = I915_PRIORITY_DISPLAY,
13353 i915_gem_object_wait_priority(obj, 0, &attr);
13357 * intel_prepare_plane_fb - Prepare fb for usage on plane
13358 * @plane: drm plane to prepare for
13359 * @new_state: the plane state being prepared
13361 * Prepares a framebuffer for usage on a display plane. Generally this
13362 * involves pinning the underlying object and updating the frontbuffer tracking
13363 * bits. Some older platforms need special physical address handling for
13366 * Must be called with struct_mutex held.
13368 * Returns 0 on success, negative error code on failure.
13371 intel_prepare_plane_fb(struct drm_plane *plane,
13372 struct drm_plane_state *new_state)
13374 struct intel_atomic_state *intel_state =
13375 to_intel_atomic_state(new_state->state);
13376 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13377 struct drm_framebuffer *fb = new_state->fb;
13378 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13379 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
13383 struct drm_crtc_state *crtc_state =
13384 drm_atomic_get_new_crtc_state(new_state->state,
13385 plane->state->crtc);
13387 /* Big Hammer, we also need to ensure that any pending
13388 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
13389 * current scanout is retired before unpinning the old
13390 * framebuffer. Note that we rely on userspace rendering
13391 * into the buffer attached to the pipe they are waiting
13392 * on. If not, userspace generates a GPU hang with IPEHR
13393 * point to the MI_WAIT_FOR_EVENT.
13395 * This should only fail upon a hung GPU, in which case we
13396 * can safely continue.
13398 if (needs_modeset(crtc_state)) {
13399 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13400 old_obj->resv, NULL,
13408 if (new_state->fence) { /* explicit fencing */
13409 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
13411 I915_FENCE_TIMEOUT,
13420 ret = i915_gem_object_pin_pages(obj);
13424 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13426 i915_gem_object_unpin_pages(obj);
13430 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
13432 mutex_unlock(&dev_priv->drm.struct_mutex);
13433 i915_gem_object_unpin_pages(obj);
13437 fb_obj_bump_render_priority(obj);
13438 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
13440 if (!new_state->fence) { /* implicit fencing */
13441 struct dma_fence *fence;
13443 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13445 false, I915_FENCE_TIMEOUT,
13450 fence = reservation_object_get_excl_rcu(obj->resv);
13452 add_rps_boost_after_vblank(new_state->crtc, fence);
13453 dma_fence_put(fence);
13456 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
13460 * We declare pageflips to be interactive and so merit a small bias
13461 * towards upclocking to deliver the frame on time. By only changing
13462 * the RPS thresholds to sample more regularly and aim for higher
13463 * clocks we can hopefully deliver low power workloads (like kodi)
13464 * that are not quite steady state without resorting to forcing
13465 * maximum clocks following a vblank miss (see do_rps_boost()).
13467 if (!intel_state->rps_interactive) {
13468 intel_rps_mark_interactive(dev_priv, true);
13469 intel_state->rps_interactive = true;
13476 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13477 * @plane: drm plane to clean up for
13478 * @old_state: the state from the previous modeset
13480 * Cleans up a framebuffer that has just been removed from a plane.
13482 * Must be called with struct_mutex held.
13485 intel_cleanup_plane_fb(struct drm_plane *plane,
13486 struct drm_plane_state *old_state)
13488 struct intel_atomic_state *intel_state =
13489 to_intel_atomic_state(old_state->state);
13490 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13492 if (intel_state->rps_interactive) {
13493 intel_rps_mark_interactive(dev_priv, false);
13494 intel_state->rps_interactive = false;
13497 /* Should only be called after a successful intel_prepare_plane_fb()! */
13498 mutex_lock(&dev_priv->drm.struct_mutex);
13499 intel_plane_unpin_fb(to_intel_plane_state(old_state));
13500 mutex_unlock(&dev_priv->drm.struct_mutex);
13504 skl_max_scale(const struct intel_crtc_state *crtc_state,
13507 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
13508 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13509 int max_scale, mult;
13510 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
13512 if (!crtc_state->base.enable)
13513 return DRM_PLANE_HELPER_NO_SCALING;
13515 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
13516 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
13518 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
13521 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
13522 return DRM_PLANE_HELPER_NO_SCALING;
13525 * skl max scale is lower of:
13526 * close to 3 but not 3, -1 is for that purpose
13530 mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3;
13531 tmpclk1 = (1 << 16) * mult - 1;
13532 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
13533 max_scale = min(tmpclk1, tmpclk2);
13538 static void intel_begin_crtc_commit(struct drm_crtc *crtc,
13539 struct drm_crtc_state *old_crtc_state)
13541 struct drm_device *dev = crtc->dev;
13542 struct drm_i915_private *dev_priv = to_i915(dev);
13543 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13544 struct intel_crtc_state *old_intel_cstate =
13545 to_intel_crtc_state(old_crtc_state);
13546 struct intel_atomic_state *old_intel_state =
13547 to_intel_atomic_state(old_crtc_state->state);
13548 struct intel_crtc_state *intel_cstate =
13549 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13550 bool modeset = needs_modeset(&intel_cstate->base);
13553 (intel_cstate->base.color_mgmt_changed ||
13554 intel_cstate->update_pipe)) {
13555 intel_color_set_csc(&intel_cstate->base);
13556 intel_color_load_luts(&intel_cstate->base);
13559 /* Perform vblank evasion around commit operation */
13560 intel_pipe_update_start(intel_cstate);
13565 if (intel_cstate->update_pipe)
13566 intel_update_pipe_config(old_intel_cstate, intel_cstate);
13567 else if (INTEL_GEN(dev_priv) >= 9)
13568 skl_detach_scalers(intel_cstate);
13571 if (dev_priv->display.atomic_update_watermarks)
13572 dev_priv->display.atomic_update_watermarks(old_intel_state,
13576 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
13577 struct intel_crtc_state *crtc_state)
13579 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13581 if (!IS_GEN2(dev_priv))
13582 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
13584 if (crtc_state->has_pch_encoder) {
13585 enum pipe pch_transcoder =
13586 intel_crtc_pch_transcoder(crtc);
13588 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
13592 static void intel_finish_crtc_commit(struct drm_crtc *crtc,
13593 struct drm_crtc_state *old_crtc_state)
13595 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13596 struct intel_atomic_state *old_intel_state =
13597 to_intel_atomic_state(old_crtc_state->state);
13598 struct intel_crtc_state *new_crtc_state =
13599 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13601 intel_pipe_update_end(new_crtc_state);
13603 if (new_crtc_state->update_pipe &&
13604 !needs_modeset(&new_crtc_state->base) &&
13605 old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED)
13606 intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state);
13610 * intel_plane_destroy - destroy a plane
13611 * @plane: plane to destroy
13613 * Common destruction function for all types of planes (primary, cursor,
13616 void intel_plane_destroy(struct drm_plane *plane)
13618 drm_plane_cleanup(plane);
13619 kfree(to_intel_plane(plane));
13622 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
13623 u32 format, u64 modifier)
13625 switch (modifier) {
13626 case DRM_FORMAT_MOD_LINEAR:
13627 case I915_FORMAT_MOD_X_TILED:
13634 case DRM_FORMAT_C8:
13635 case DRM_FORMAT_RGB565:
13636 case DRM_FORMAT_XRGB1555:
13637 case DRM_FORMAT_XRGB8888:
13638 return modifier == DRM_FORMAT_MOD_LINEAR ||
13639 modifier == I915_FORMAT_MOD_X_TILED;
13645 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
13646 u32 format, u64 modifier)
13648 switch (modifier) {
13649 case DRM_FORMAT_MOD_LINEAR:
13650 case I915_FORMAT_MOD_X_TILED:
13657 case DRM_FORMAT_C8:
13658 case DRM_FORMAT_RGB565:
13659 case DRM_FORMAT_XRGB8888:
13660 case DRM_FORMAT_XBGR8888:
13661 case DRM_FORMAT_XRGB2101010:
13662 case DRM_FORMAT_XBGR2101010:
13663 return modifier == DRM_FORMAT_MOD_LINEAR ||
13664 modifier == I915_FORMAT_MOD_X_TILED;
13670 static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
13671 u32 format, u64 modifier)
13673 return modifier == DRM_FORMAT_MOD_LINEAR &&
13674 format == DRM_FORMAT_ARGB8888;
13677 static const struct drm_plane_funcs i965_plane_funcs = {
13678 .update_plane = drm_atomic_helper_update_plane,
13679 .disable_plane = drm_atomic_helper_disable_plane,
13680 .destroy = intel_plane_destroy,
13681 .atomic_get_property = intel_plane_atomic_get_property,
13682 .atomic_set_property = intel_plane_atomic_set_property,
13683 .atomic_duplicate_state = intel_plane_duplicate_state,
13684 .atomic_destroy_state = intel_plane_destroy_state,
13685 .format_mod_supported = i965_plane_format_mod_supported,
13688 static const struct drm_plane_funcs i8xx_plane_funcs = {
13689 .update_plane = drm_atomic_helper_update_plane,
13690 .disable_plane = drm_atomic_helper_disable_plane,
13691 .destroy = intel_plane_destroy,
13692 .atomic_get_property = intel_plane_atomic_get_property,
13693 .atomic_set_property = intel_plane_atomic_set_property,
13694 .atomic_duplicate_state = intel_plane_duplicate_state,
13695 .atomic_destroy_state = intel_plane_destroy_state,
13696 .format_mod_supported = i8xx_plane_format_mod_supported,
13700 intel_legacy_cursor_update(struct drm_plane *plane,
13701 struct drm_crtc *crtc,
13702 struct drm_framebuffer *fb,
13703 int crtc_x, int crtc_y,
13704 unsigned int crtc_w, unsigned int crtc_h,
13705 uint32_t src_x, uint32_t src_y,
13706 uint32_t src_w, uint32_t src_h,
13707 struct drm_modeset_acquire_ctx *ctx)
13709 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
13711 struct drm_plane_state *old_plane_state, *new_plane_state;
13712 struct intel_plane *intel_plane = to_intel_plane(plane);
13713 struct drm_framebuffer *old_fb;
13714 struct intel_crtc_state *crtc_state =
13715 to_intel_crtc_state(crtc->state);
13716 struct intel_crtc_state *new_crtc_state;
13719 * When crtc is inactive or there is a modeset pending,
13720 * wait for it to complete in the slowpath
13722 if (!crtc_state->base.active || needs_modeset(&crtc_state->base) ||
13723 crtc_state->update_pipe)
13726 old_plane_state = plane->state;
13728 * Don't do an async update if there is an outstanding commit modifying
13729 * the plane. This prevents our async update's changes from getting
13730 * overridden by a previous synchronous update's state.
13732 if (old_plane_state->commit &&
13733 !try_wait_for_completion(&old_plane_state->commit->hw_done))
13737 * If any parameters change that may affect watermarks,
13738 * take the slowpath. Only changing fb or position should be
13741 if (old_plane_state->crtc != crtc ||
13742 old_plane_state->src_w != src_w ||
13743 old_plane_state->src_h != src_h ||
13744 old_plane_state->crtc_w != crtc_w ||
13745 old_plane_state->crtc_h != crtc_h ||
13746 !old_plane_state->fb != !fb)
13749 new_plane_state = intel_plane_duplicate_state(plane);
13750 if (!new_plane_state)
13753 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc));
13754 if (!new_crtc_state) {
13759 drm_atomic_set_fb_for_plane(new_plane_state, fb);
13761 new_plane_state->src_x = src_x;
13762 new_plane_state->src_y = src_y;
13763 new_plane_state->src_w = src_w;
13764 new_plane_state->src_h = src_h;
13765 new_plane_state->crtc_x = crtc_x;
13766 new_plane_state->crtc_y = crtc_y;
13767 new_plane_state->crtc_w = crtc_w;
13768 new_plane_state->crtc_h = crtc_h;
13770 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
13771 to_intel_plane_state(old_plane_state),
13772 to_intel_plane_state(new_plane_state));
13776 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13780 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
13784 intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
13786 old_fb = old_plane_state->fb;
13787 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
13788 intel_plane->frontbuffer_bit);
13790 /* Swap plane state */
13791 plane->state = new_plane_state;
13794 * We cannot swap crtc_state as it may be in use by an atomic commit or
13795 * page flip that's running simultaneously. If we swap crtc_state and
13796 * destroy the old state, we will cause a use-after-free there.
13798 * Only update active_planes, which is needed for our internal
13799 * bookkeeping. Either value will do the right thing when updating
13800 * planes atomically. If the cursor was part of the atomic update then
13801 * we would have taken the slowpath.
13803 crtc_state->active_planes = new_crtc_state->active_planes;
13805 if (plane->state->visible) {
13806 trace_intel_update_plane(plane, to_intel_crtc(crtc));
13807 intel_plane->update_plane(intel_plane, crtc_state,
13808 to_intel_plane_state(plane->state));
13810 trace_intel_disable_plane(plane, to_intel_crtc(crtc));
13811 intel_plane->disable_plane(intel_plane, crtc_state);
13814 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
13817 mutex_unlock(&dev_priv->drm.struct_mutex);
13819 if (new_crtc_state)
13820 intel_crtc_destroy_state(crtc, &new_crtc_state->base);
13822 intel_plane_destroy_state(plane, new_plane_state);
13824 intel_plane_destroy_state(plane, old_plane_state);
13828 return drm_atomic_helper_update_plane(plane, crtc, fb,
13829 crtc_x, crtc_y, crtc_w, crtc_h,
13830 src_x, src_y, src_w, src_h, ctx);
13833 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
13834 .update_plane = intel_legacy_cursor_update,
13835 .disable_plane = drm_atomic_helper_disable_plane,
13836 .destroy = intel_plane_destroy,
13837 .atomic_get_property = intel_plane_atomic_get_property,
13838 .atomic_set_property = intel_plane_atomic_set_property,
13839 .atomic_duplicate_state = intel_plane_duplicate_state,
13840 .atomic_destroy_state = intel_plane_destroy_state,
13841 .format_mod_supported = intel_cursor_format_mod_supported,
13844 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
13845 enum i9xx_plane_id i9xx_plane)
13847 if (!HAS_FBC(dev_priv))
13850 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
13851 return i9xx_plane == PLANE_A; /* tied to pipe A */
13852 else if (IS_IVYBRIDGE(dev_priv))
13853 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
13854 i9xx_plane == PLANE_C;
13855 else if (INTEL_GEN(dev_priv) >= 4)
13856 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
13858 return i9xx_plane == PLANE_A;
13861 static struct intel_plane *
13862 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
13864 struct intel_plane *plane;
13865 const struct drm_plane_funcs *plane_funcs;
13866 unsigned int supported_rotations;
13867 unsigned int possible_crtcs;
13868 const u64 *modifiers;
13869 const u32 *formats;
13873 if (INTEL_GEN(dev_priv) >= 9)
13874 return skl_universal_plane_create(dev_priv, pipe,
13877 plane = intel_plane_alloc();
13881 plane->pipe = pipe;
13883 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
13884 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
13886 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
13887 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
13889 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
13890 plane->id = PLANE_PRIMARY;
13891 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
13893 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
13894 if (plane->has_fbc) {
13895 struct intel_fbc *fbc = &dev_priv->fbc;
13897 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
13900 if (INTEL_GEN(dev_priv) >= 4) {
13901 formats = i965_primary_formats;
13902 num_formats = ARRAY_SIZE(i965_primary_formats);
13903 modifiers = i9xx_format_modifiers;
13905 plane->max_stride = i9xx_plane_max_stride;
13906 plane->update_plane = i9xx_update_plane;
13907 plane->disable_plane = i9xx_disable_plane;
13908 plane->get_hw_state = i9xx_plane_get_hw_state;
13909 plane->check_plane = i9xx_plane_check;
13911 plane_funcs = &i965_plane_funcs;
13913 formats = i8xx_primary_formats;
13914 num_formats = ARRAY_SIZE(i8xx_primary_formats);
13915 modifiers = i9xx_format_modifiers;
13917 plane->max_stride = i9xx_plane_max_stride;
13918 plane->update_plane = i9xx_update_plane;
13919 plane->disable_plane = i9xx_disable_plane;
13920 plane->get_hw_state = i9xx_plane_get_hw_state;
13921 plane->check_plane = i9xx_plane_check;
13923 plane_funcs = &i8xx_plane_funcs;
13926 possible_crtcs = BIT(pipe);
13928 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
13929 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
13930 possible_crtcs, plane_funcs,
13931 formats, num_formats, modifiers,
13932 DRM_PLANE_TYPE_PRIMARY,
13933 "primary %c", pipe_name(pipe));
13935 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
13936 possible_crtcs, plane_funcs,
13937 formats, num_formats, modifiers,
13938 DRM_PLANE_TYPE_PRIMARY,
13940 plane_name(plane->i9xx_plane));
13944 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
13945 supported_rotations =
13946 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
13947 DRM_MODE_REFLECT_X;
13948 } else if (INTEL_GEN(dev_priv) >= 4) {
13949 supported_rotations =
13950 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
13952 supported_rotations = DRM_MODE_ROTATE_0;
13955 if (INTEL_GEN(dev_priv) >= 4)
13956 drm_plane_create_rotation_property(&plane->base,
13958 supported_rotations);
13960 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
13965 intel_plane_free(plane);
13967 return ERR_PTR(ret);
13970 static struct intel_plane *
13971 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
13974 unsigned int possible_crtcs;
13975 struct intel_plane *cursor;
13978 cursor = intel_plane_alloc();
13979 if (IS_ERR(cursor))
13982 cursor->pipe = pipe;
13983 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
13984 cursor->id = PLANE_CURSOR;
13985 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
13987 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
13988 cursor->max_stride = i845_cursor_max_stride;
13989 cursor->update_plane = i845_update_cursor;
13990 cursor->disable_plane = i845_disable_cursor;
13991 cursor->get_hw_state = i845_cursor_get_hw_state;
13992 cursor->check_plane = i845_check_cursor;
13994 cursor->max_stride = i9xx_cursor_max_stride;
13995 cursor->update_plane = i9xx_update_cursor;
13996 cursor->disable_plane = i9xx_disable_cursor;
13997 cursor->get_hw_state = i9xx_cursor_get_hw_state;
13998 cursor->check_plane = i9xx_check_cursor;
14001 cursor->cursor.base = ~0;
14002 cursor->cursor.cntl = ~0;
14004 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
14005 cursor->cursor.size = ~0;
14007 possible_crtcs = BIT(pipe);
14009 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
14010 possible_crtcs, &intel_cursor_plane_funcs,
14011 intel_cursor_formats,
14012 ARRAY_SIZE(intel_cursor_formats),
14013 cursor_format_modifiers,
14014 DRM_PLANE_TYPE_CURSOR,
14015 "cursor %c", pipe_name(pipe));
14019 if (INTEL_GEN(dev_priv) >= 4)
14020 drm_plane_create_rotation_property(&cursor->base,
14022 DRM_MODE_ROTATE_0 |
14023 DRM_MODE_ROTATE_180);
14025 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
14030 intel_plane_free(cursor);
14032 return ERR_PTR(ret);
14035 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
14036 struct intel_crtc_state *crtc_state)
14038 struct intel_crtc_scaler_state *scaler_state =
14039 &crtc_state->scaler_state;
14040 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14043 crtc->num_scalers = dev_priv->info.num_scalers[crtc->pipe];
14044 if (!crtc->num_scalers)
14047 for (i = 0; i < crtc->num_scalers; i++) {
14048 struct intel_scaler *scaler = &scaler_state->scalers[i];
14050 scaler->in_use = 0;
14054 scaler_state->scaler_id = -1;
14057 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
14059 struct intel_crtc *intel_crtc;
14060 struct intel_crtc_state *crtc_state = NULL;
14061 struct intel_plane *primary = NULL;
14062 struct intel_plane *cursor = NULL;
14065 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
14069 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
14074 intel_crtc->config = crtc_state;
14075 intel_crtc->base.state = &crtc_state->base;
14076 crtc_state->base.crtc = &intel_crtc->base;
14078 primary = intel_primary_plane_create(dev_priv, pipe);
14079 if (IS_ERR(primary)) {
14080 ret = PTR_ERR(primary);
14083 intel_crtc->plane_ids_mask |= BIT(primary->id);
14085 for_each_sprite(dev_priv, pipe, sprite) {
14086 struct intel_plane *plane;
14088 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
14089 if (IS_ERR(plane)) {
14090 ret = PTR_ERR(plane);
14093 intel_crtc->plane_ids_mask |= BIT(plane->id);
14096 cursor = intel_cursor_plane_create(dev_priv, pipe);
14097 if (IS_ERR(cursor)) {
14098 ret = PTR_ERR(cursor);
14101 intel_crtc->plane_ids_mask |= BIT(cursor->id);
14103 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
14104 &primary->base, &cursor->base,
14106 "pipe %c", pipe_name(pipe));
14110 intel_crtc->pipe = pipe;
14112 /* initialize shared scalers */
14113 intel_crtc_init_scalers(intel_crtc, crtc_state);
14115 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
14116 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
14117 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
14119 if (INTEL_GEN(dev_priv) < 9) {
14120 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
14122 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
14123 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
14124 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
14127 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
14129 intel_color_init(&intel_crtc->base);
14131 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
14137 * drm_mode_config_cleanup() will free up any
14138 * crtcs/planes already initialized.
14146 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
14147 struct drm_file *file)
14149 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
14150 struct drm_crtc *drmmode_crtc;
14151 struct intel_crtc *crtc;
14153 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
14157 crtc = to_intel_crtc(drmmode_crtc);
14158 pipe_from_crtc_id->pipe = crtc->pipe;
14163 static int intel_encoder_clones(struct intel_encoder *encoder)
14165 struct drm_device *dev = encoder->base.dev;
14166 struct intel_encoder *source_encoder;
14167 int index_mask = 0;
14170 for_each_intel_encoder(dev, source_encoder) {
14171 if (encoders_cloneable(encoder, source_encoder))
14172 index_mask |= (1 << entry);
14180 static bool has_edp_a(struct drm_i915_private *dev_priv)
14182 if (!IS_MOBILE(dev_priv))
14185 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
14188 if (IS_GEN5(dev_priv) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
14194 static bool intel_crt_present(struct drm_i915_private *dev_priv)
14196 if (INTEL_GEN(dev_priv) >= 9)
14199 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
14202 if (IS_CHERRYVIEW(dev_priv))
14205 if (HAS_PCH_LPT_H(dev_priv) &&
14206 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
14209 /* DDI E can't be used if DDI A requires 4 lanes */
14210 if (HAS_DDI(dev_priv) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
14213 if (!dev_priv->vbt.int_crt_support)
14219 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
14224 if (HAS_DDI(dev_priv))
14227 * This w/a is needed at least on CPT/PPT, but to be sure apply it
14228 * everywhere where registers can be write protected.
14230 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14235 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
14236 u32 val = I915_READ(PP_CONTROL(pps_idx));
14238 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
14239 I915_WRITE(PP_CONTROL(pps_idx), val);
14243 static void intel_pps_init(struct drm_i915_private *dev_priv)
14245 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
14246 dev_priv->pps_mmio_base = PCH_PPS_BASE;
14247 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14248 dev_priv->pps_mmio_base = VLV_PPS_BASE;
14250 dev_priv->pps_mmio_base = PPS_BASE;
14252 intel_pps_unlock_regs_wa(dev_priv);
14255 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
14257 struct intel_encoder *encoder;
14258 bool dpd_is_edp = false;
14260 intel_pps_init(dev_priv);
14262 if (!HAS_DISPLAY(dev_priv))
14266 * intel_edp_init_connector() depends on this completing first, to
14267 * prevent the registeration of both eDP and LVDS and the incorrect
14268 * sharing of the PPS.
14270 intel_lvds_init(dev_priv);
14272 if (intel_crt_present(dev_priv))
14273 intel_crt_init(dev_priv);
14275 if (IS_ICELAKE(dev_priv)) {
14276 intel_ddi_init(dev_priv, PORT_A);
14277 intel_ddi_init(dev_priv, PORT_B);
14278 intel_ddi_init(dev_priv, PORT_C);
14279 intel_ddi_init(dev_priv, PORT_D);
14280 intel_ddi_init(dev_priv, PORT_E);
14281 intel_ddi_init(dev_priv, PORT_F);
14282 icl_dsi_init(dev_priv);
14283 } else if (IS_GEN9_LP(dev_priv)) {
14285 * FIXME: Broxton doesn't support port detection via the
14286 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
14287 * detect the ports.
14289 intel_ddi_init(dev_priv, PORT_A);
14290 intel_ddi_init(dev_priv, PORT_B);
14291 intel_ddi_init(dev_priv, PORT_C);
14293 vlv_dsi_init(dev_priv);
14294 } else if (HAS_DDI(dev_priv)) {
14298 * Haswell uses DDI functions to detect digital outputs.
14299 * On SKL pre-D0 the strap isn't connected, so we assume
14302 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
14303 /* WaIgnoreDDIAStrap: skl */
14304 if (found || IS_GEN9_BC(dev_priv))
14305 intel_ddi_init(dev_priv, PORT_A);
14307 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
14309 found = I915_READ(SFUSE_STRAP);
14311 if (found & SFUSE_STRAP_DDIB_DETECTED)
14312 intel_ddi_init(dev_priv, PORT_B);
14313 if (found & SFUSE_STRAP_DDIC_DETECTED)
14314 intel_ddi_init(dev_priv, PORT_C);
14315 if (found & SFUSE_STRAP_DDID_DETECTED)
14316 intel_ddi_init(dev_priv, PORT_D);
14317 if (found & SFUSE_STRAP_DDIF_DETECTED)
14318 intel_ddi_init(dev_priv, PORT_F);
14320 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14322 if (IS_GEN9_BC(dev_priv) &&
14323 (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp ||
14324 dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi ||
14325 dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi))
14326 intel_ddi_init(dev_priv, PORT_E);
14328 } else if (HAS_PCH_SPLIT(dev_priv)) {
14330 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
14332 if (has_edp_a(dev_priv))
14333 intel_dp_init(dev_priv, DP_A, PORT_A);
14335 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
14336 /* PCH SDVOB multiplex with HDMIB */
14337 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
14339 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
14340 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
14341 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
14344 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
14345 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
14347 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
14348 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
14350 if (I915_READ(PCH_DP_C) & DP_DETECTED)
14351 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
14353 if (I915_READ(PCH_DP_D) & DP_DETECTED)
14354 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
14355 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
14356 bool has_edp, has_port;
14359 * The DP_DETECTED bit is the latched state of the DDC
14360 * SDA pin at boot. However since eDP doesn't require DDC
14361 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14362 * eDP ports may have been muxed to an alternate function.
14363 * Thus we can't rely on the DP_DETECTED bit alone to detect
14364 * eDP ports. Consult the VBT as well as DP_DETECTED to
14365 * detect eDP ports.
14367 * Sadly the straps seem to be missing sometimes even for HDMI
14368 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
14369 * and VBT for the presence of the port. Additionally we can't
14370 * trust the port type the VBT declares as we've seen at least
14371 * HDMI ports that the VBT claim are DP or eDP.
14373 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
14374 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
14375 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
14376 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
14377 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
14378 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
14380 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
14381 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
14382 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
14383 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
14384 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
14385 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
14387 if (IS_CHERRYVIEW(dev_priv)) {
14389 * eDP not supported on port D,
14390 * so no need to worry about it
14392 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
14393 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
14394 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
14395 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
14396 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
14399 vlv_dsi_init(dev_priv);
14400 } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) {
14401 bool found = false;
14403 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14404 DRM_DEBUG_KMS("probing SDVOB\n");
14405 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
14406 if (!found && IS_G4X(dev_priv)) {
14407 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
14408 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
14411 if (!found && IS_G4X(dev_priv))
14412 intel_dp_init(dev_priv, DP_B, PORT_B);
14415 /* Before G4X SDVOC doesn't have its own detect register */
14417 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14418 DRM_DEBUG_KMS("probing SDVOC\n");
14419 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
14422 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
14424 if (IS_G4X(dev_priv)) {
14425 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
14426 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
14428 if (IS_G4X(dev_priv))
14429 intel_dp_init(dev_priv, DP_C, PORT_C);
14432 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
14433 intel_dp_init(dev_priv, DP_D, PORT_D);
14434 } else if (IS_GEN2(dev_priv))
14435 intel_dvo_init(dev_priv);
14437 if (SUPPORTS_TV(dev_priv))
14438 intel_tv_init(dev_priv);
14440 intel_psr_init(dev_priv);
14442 for_each_intel_encoder(&dev_priv->drm, encoder) {
14443 encoder->base.possible_crtcs = encoder->crtc_mask;
14444 encoder->base.possible_clones =
14445 intel_encoder_clones(encoder);
14448 intel_init_pch_refclk(dev_priv);
14450 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
14453 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14455 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14456 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14458 drm_framebuffer_cleanup(fb);
14460 i915_gem_object_lock(obj);
14461 WARN_ON(!obj->framebuffer_references--);
14462 i915_gem_object_unlock(obj);
14464 i915_gem_object_put(obj);
14469 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
14470 struct drm_file *file,
14471 unsigned int *handle)
14473 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14475 if (obj->userptr.mm) {
14476 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14480 return drm_gem_handle_create(file, &obj->base, handle);
14483 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14484 struct drm_file *file,
14485 unsigned flags, unsigned color,
14486 struct drm_clip_rect *clips,
14487 unsigned num_clips)
14489 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14491 i915_gem_object_flush_if_display(obj);
14492 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
14497 static const struct drm_framebuffer_funcs intel_fb_funcs = {
14498 .destroy = intel_user_framebuffer_destroy,
14499 .create_handle = intel_user_framebuffer_create_handle,
14500 .dirty = intel_user_framebuffer_dirty,
14504 u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
14505 u32 pixel_format, u64 fb_modifier)
14507 struct intel_crtc *crtc;
14508 struct intel_plane *plane;
14511 * We assume the primary plane for pipe A has
14512 * the highest stride limits of them all.
14514 crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
14515 plane = to_intel_plane(crtc->base.primary);
14517 return plane->max_stride(plane, pixel_format, fb_modifier,
14518 DRM_MODE_ROTATE_0);
14521 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
14522 struct drm_i915_gem_object *obj,
14523 struct drm_mode_fb_cmd2 *mode_cmd)
14525 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
14526 struct drm_framebuffer *fb = &intel_fb->base;
14528 unsigned int tiling, stride;
14532 i915_gem_object_lock(obj);
14533 obj->framebuffer_references++;
14534 tiling = i915_gem_object_get_tiling(obj);
14535 stride = i915_gem_object_get_stride(obj);
14536 i915_gem_object_unlock(obj);
14538 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
14540 * If there's a fence, enforce that
14541 * the fb modifier and tiling mode match.
14543 if (tiling != I915_TILING_NONE &&
14544 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14545 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
14549 if (tiling == I915_TILING_X) {
14550 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
14551 } else if (tiling == I915_TILING_Y) {
14552 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
14557 if (!drm_any_plane_has_format(&dev_priv->drm,
14558 mode_cmd->pixel_format,
14559 mode_cmd->modifier[0])) {
14560 struct drm_format_name_buf format_name;
14562 DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n",
14563 drm_get_format_name(mode_cmd->pixel_format,
14565 mode_cmd->modifier[0]);
14570 * gen2/3 display engine uses the fence if present,
14571 * so the tiling mode must match the fb modifier exactly.
14573 if (INTEL_GEN(dev_priv) < 4 &&
14574 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14575 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
14579 pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->pixel_format,
14580 mode_cmd->modifier[0]);
14581 if (mode_cmd->pitches[0] > pitch_limit) {
14582 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
14583 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
14584 "tiled" : "linear",
14585 mode_cmd->pitches[0], pitch_limit);
14590 * If there's a fence, enforce that
14591 * the fb pitch and fence stride match.
14593 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
14594 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
14595 mode_cmd->pitches[0], stride);
14599 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14600 if (mode_cmd->offsets[0] != 0)
14603 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
14605 if (fb->format->format == DRM_FORMAT_NV12 &&
14606 (fb->width < SKL_MIN_YUV_420_SRC_W ||
14607 fb->height < SKL_MIN_YUV_420_SRC_H ||
14608 (fb->width % 4) != 0 || (fb->height % 4) != 0)) {
14609 DRM_DEBUG_KMS("src dimensions not correct for NV12\n");
14613 for (i = 0; i < fb->format->num_planes; i++) {
14614 u32 stride_alignment;
14616 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14617 DRM_DEBUG_KMS("bad plane %d handle\n", i);
14621 stride_alignment = intel_fb_stride_alignment(fb, i);
14624 * Display WA #0531: skl,bxt,kbl,glk
14626 * Render decompression and plane width > 3840
14627 * combined with horizontal panning requires the
14628 * plane stride to be a multiple of 4. We'll just
14629 * require the entire fb to accommodate that to avoid
14630 * potential runtime errors at plane configuration time.
14632 if (IS_GEN9(dev_priv) && i == 0 && fb->width > 3840 &&
14633 is_ccs_modifier(fb->modifier))
14634 stride_alignment *= 4;
14636 if (fb->pitches[i] & (stride_alignment - 1)) {
14637 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
14638 i, fb->pitches[i], stride_alignment);
14642 fb->obj[i] = &obj->base;
14645 ret = intel_fill_fb_info(dev_priv, fb);
14649 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
14651 DRM_ERROR("framebuffer init failed %d\n", ret);
14658 i915_gem_object_lock(obj);
14659 obj->framebuffer_references--;
14660 i915_gem_object_unlock(obj);
14664 static struct drm_framebuffer *
14665 intel_user_framebuffer_create(struct drm_device *dev,
14666 struct drm_file *filp,
14667 const struct drm_mode_fb_cmd2 *user_mode_cmd)
14669 struct drm_framebuffer *fb;
14670 struct drm_i915_gem_object *obj;
14671 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
14673 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14675 return ERR_PTR(-ENOENT);
14677 fb = intel_framebuffer_create(obj, &mode_cmd);
14679 i915_gem_object_put(obj);
14684 static void intel_atomic_state_free(struct drm_atomic_state *state)
14686 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
14688 drm_atomic_state_default_release(state);
14690 i915_sw_fence_fini(&intel_state->commit_ready);
14695 static enum drm_mode_status
14696 intel_mode_valid(struct drm_device *dev,
14697 const struct drm_display_mode *mode)
14699 struct drm_i915_private *dev_priv = to_i915(dev);
14700 int hdisplay_max, htotal_max;
14701 int vdisplay_max, vtotal_max;
14704 * Can't reject DBLSCAN here because Xorg ddxen can add piles
14705 * of DBLSCAN modes to the output's mode list when they detect
14706 * the scaling mode property on the connector. And they don't
14707 * ask the kernel to validate those modes in any way until
14708 * modeset time at which point the client gets a protocol error.
14709 * So in order to not upset those clients we silently ignore the
14710 * DBLSCAN flag on such connectors. For other connectors we will
14711 * reject modes with the DBLSCAN flag in encoder->compute_config().
14712 * And we always reject DBLSCAN modes in connector->mode_valid()
14713 * as we never want such modes on the connector's mode list.
14716 if (mode->vscan > 1)
14717 return MODE_NO_VSCAN;
14719 if (mode->flags & DRM_MODE_FLAG_HSKEW)
14720 return MODE_H_ILLEGAL;
14722 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
14723 DRM_MODE_FLAG_NCSYNC |
14724 DRM_MODE_FLAG_PCSYNC))
14727 if (mode->flags & (DRM_MODE_FLAG_BCAST |
14728 DRM_MODE_FLAG_PIXMUX |
14729 DRM_MODE_FLAG_CLKDIV2))
14732 if (INTEL_GEN(dev_priv) >= 9 ||
14733 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
14734 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
14735 vdisplay_max = 4096;
14738 } else if (INTEL_GEN(dev_priv) >= 3) {
14739 hdisplay_max = 4096;
14740 vdisplay_max = 4096;
14744 hdisplay_max = 2048;
14745 vdisplay_max = 2048;
14750 if (mode->hdisplay > hdisplay_max ||
14751 mode->hsync_start > htotal_max ||
14752 mode->hsync_end > htotal_max ||
14753 mode->htotal > htotal_max)
14754 return MODE_H_ILLEGAL;
14756 if (mode->vdisplay > vdisplay_max ||
14757 mode->vsync_start > vtotal_max ||
14758 mode->vsync_end > vtotal_max ||
14759 mode->vtotal > vtotal_max)
14760 return MODE_V_ILLEGAL;
14765 static const struct drm_mode_config_funcs intel_mode_funcs = {
14766 .fb_create = intel_user_framebuffer_create,
14767 .get_format_info = intel_get_format_info,
14768 .output_poll_changed = intel_fbdev_output_poll_changed,
14769 .mode_valid = intel_mode_valid,
14770 .atomic_check = intel_atomic_check,
14771 .atomic_commit = intel_atomic_commit,
14772 .atomic_state_alloc = intel_atomic_state_alloc,
14773 .atomic_state_clear = intel_atomic_state_clear,
14774 .atomic_state_free = intel_atomic_state_free,
14778 * intel_init_display_hooks - initialize the display modesetting hooks
14779 * @dev_priv: device private
14781 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
14783 intel_init_cdclk_hooks(dev_priv);
14785 if (INTEL_GEN(dev_priv) >= 9) {
14786 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14787 dev_priv->display.get_initial_plane_config =
14788 skylake_get_initial_plane_config;
14789 dev_priv->display.crtc_compute_clock =
14790 haswell_crtc_compute_clock;
14791 dev_priv->display.crtc_enable = haswell_crtc_enable;
14792 dev_priv->display.crtc_disable = haswell_crtc_disable;
14793 } else if (HAS_DDI(dev_priv)) {
14794 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14795 dev_priv->display.get_initial_plane_config =
14796 i9xx_get_initial_plane_config;
14797 dev_priv->display.crtc_compute_clock =
14798 haswell_crtc_compute_clock;
14799 dev_priv->display.crtc_enable = haswell_crtc_enable;
14800 dev_priv->display.crtc_disable = haswell_crtc_disable;
14801 } else if (HAS_PCH_SPLIT(dev_priv)) {
14802 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
14803 dev_priv->display.get_initial_plane_config =
14804 i9xx_get_initial_plane_config;
14805 dev_priv->display.crtc_compute_clock =
14806 ironlake_crtc_compute_clock;
14807 dev_priv->display.crtc_enable = ironlake_crtc_enable;
14808 dev_priv->display.crtc_disable = ironlake_crtc_disable;
14809 } else if (IS_CHERRYVIEW(dev_priv)) {
14810 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14811 dev_priv->display.get_initial_plane_config =
14812 i9xx_get_initial_plane_config;
14813 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
14814 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14815 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14816 } else if (IS_VALLEYVIEW(dev_priv)) {
14817 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14818 dev_priv->display.get_initial_plane_config =
14819 i9xx_get_initial_plane_config;
14820 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
14821 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14822 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14823 } else if (IS_G4X(dev_priv)) {
14824 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14825 dev_priv->display.get_initial_plane_config =
14826 i9xx_get_initial_plane_config;
14827 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
14828 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14829 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14830 } else if (IS_PINEVIEW(dev_priv)) {
14831 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14832 dev_priv->display.get_initial_plane_config =
14833 i9xx_get_initial_plane_config;
14834 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
14835 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14836 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14837 } else if (!IS_GEN2(dev_priv)) {
14838 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14839 dev_priv->display.get_initial_plane_config =
14840 i9xx_get_initial_plane_config;
14841 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
14842 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14843 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14845 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14846 dev_priv->display.get_initial_plane_config =
14847 i9xx_get_initial_plane_config;
14848 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
14849 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14850 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14853 if (IS_GEN5(dev_priv)) {
14854 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
14855 } else if (IS_GEN6(dev_priv)) {
14856 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
14857 } else if (IS_IVYBRIDGE(dev_priv)) {
14858 /* FIXME: detect B0+ stepping and use auto training */
14859 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
14860 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
14861 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
14864 if (INTEL_GEN(dev_priv) >= 9)
14865 dev_priv->display.update_crtcs = skl_update_crtcs;
14867 dev_priv->display.update_crtcs = intel_update_crtcs;
14870 /* Disable the VGA plane that we never use */
14871 static void i915_disable_vga(struct drm_i915_private *dev_priv)
14873 struct pci_dev *pdev = dev_priv->drm.pdev;
14875 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
14877 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
14878 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
14879 outb(SR01, VGA_SR_INDEX);
14880 sr1 = inb(VGA_SR_DATA);
14881 outb(sr1 | 1<<5, VGA_SR_DATA);
14882 vga_put(pdev, VGA_RSRC_LEGACY_IO);
14885 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
14886 POSTING_READ(vga_reg);
14889 void intel_modeset_init_hw(struct drm_device *dev)
14891 struct drm_i915_private *dev_priv = to_i915(dev);
14893 intel_update_cdclk(dev_priv);
14894 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
14895 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
14899 * Calculate what we think the watermarks should be for the state we've read
14900 * out of the hardware and then immediately program those watermarks so that
14901 * we ensure the hardware settings match our internal state.
14903 * We can calculate what we think WM's should be by creating a duplicate of the
14904 * current state (which was constructed during hardware readout) and running it
14905 * through the atomic check code to calculate new watermark values in the
14908 static void sanitize_watermarks(struct drm_device *dev)
14910 struct drm_i915_private *dev_priv = to_i915(dev);
14911 struct drm_atomic_state *state;
14912 struct intel_atomic_state *intel_state;
14913 struct drm_crtc *crtc;
14914 struct drm_crtc_state *cstate;
14915 struct drm_modeset_acquire_ctx ctx;
14919 /* Only supported on platforms that use atomic watermark design */
14920 if (!dev_priv->display.optimize_watermarks)
14924 * We need to hold connection_mutex before calling duplicate_state so
14925 * that the connector loop is protected.
14927 drm_modeset_acquire_init(&ctx, 0);
14929 ret = drm_modeset_lock_all_ctx(dev, &ctx);
14930 if (ret == -EDEADLK) {
14931 drm_modeset_backoff(&ctx);
14933 } else if (WARN_ON(ret)) {
14937 state = drm_atomic_helper_duplicate_state(dev, &ctx);
14938 if (WARN_ON(IS_ERR(state)))
14941 intel_state = to_intel_atomic_state(state);
14944 * Hardware readout is the only time we don't want to calculate
14945 * intermediate watermarks (since we don't trust the current
14948 if (!HAS_GMCH_DISPLAY(dev_priv))
14949 intel_state->skip_intermediate_wm = true;
14951 ret = intel_atomic_check(dev, state);
14954 * If we fail here, it means that the hardware appears to be
14955 * programmed in a way that shouldn't be possible, given our
14956 * understanding of watermark requirements. This might mean a
14957 * mistake in the hardware readout code or a mistake in the
14958 * watermark calculations for a given platform. Raise a WARN
14959 * so that this is noticeable.
14961 * If this actually happens, we'll have to just leave the
14962 * BIOS-programmed watermarks untouched and hope for the best.
14964 WARN(true, "Could not determine valid watermarks for inherited state\n");
14968 /* Write calculated watermark values back */
14969 for_each_new_crtc_in_state(state, crtc, cstate, i) {
14970 struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
14972 cs->wm.need_postvbl_update = true;
14973 dev_priv->display.optimize_watermarks(intel_state, cs);
14975 to_intel_crtc_state(crtc->state)->wm = cs->wm;
14979 drm_atomic_state_put(state);
14981 drm_modeset_drop_locks(&ctx);
14982 drm_modeset_acquire_fini(&ctx);
14985 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
14987 if (IS_GEN5(dev_priv)) {
14989 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
14991 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
14992 } else if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) {
14993 dev_priv->fdi_pll_freq = 270000;
14998 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
15001 static int intel_initial_commit(struct drm_device *dev)
15003 struct drm_atomic_state *state = NULL;
15004 struct drm_modeset_acquire_ctx ctx;
15005 struct drm_crtc *crtc;
15006 struct drm_crtc_state *crtc_state;
15009 state = drm_atomic_state_alloc(dev);
15013 drm_modeset_acquire_init(&ctx, 0);
15016 state->acquire_ctx = &ctx;
15018 drm_for_each_crtc(crtc, dev) {
15019 crtc_state = drm_atomic_get_crtc_state(state, crtc);
15020 if (IS_ERR(crtc_state)) {
15021 ret = PTR_ERR(crtc_state);
15025 if (crtc_state->active) {
15026 ret = drm_atomic_add_affected_planes(state, crtc);
15031 * FIXME hack to force a LUT update to avoid the
15032 * plane update forcing the pipe gamma on without
15033 * having a proper LUT loaded. Remove once we
15034 * have readout for pipe gamma enable.
15036 crtc_state->color_mgmt_changed = true;
15040 ret = drm_atomic_commit(state);
15043 if (ret == -EDEADLK) {
15044 drm_atomic_state_clear(state);
15045 drm_modeset_backoff(&ctx);
15049 drm_atomic_state_put(state);
15051 drm_modeset_drop_locks(&ctx);
15052 drm_modeset_acquire_fini(&ctx);
15057 int intel_modeset_init(struct drm_device *dev)
15059 struct drm_i915_private *dev_priv = to_i915(dev);
15060 struct i915_ggtt *ggtt = &dev_priv->ggtt;
15062 struct intel_crtc *crtc;
15065 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
15067 drm_mode_config_init(dev);
15069 dev->mode_config.min_width = 0;
15070 dev->mode_config.min_height = 0;
15072 dev->mode_config.preferred_depth = 24;
15073 dev->mode_config.prefer_shadow = 1;
15075 dev->mode_config.allow_fb_modifiers = true;
15077 dev->mode_config.funcs = &intel_mode_funcs;
15079 init_llist_head(&dev_priv->atomic_helper.free_list);
15080 INIT_WORK(&dev_priv->atomic_helper.free_work,
15081 intel_atomic_helper_free_state_worker);
15083 intel_init_quirks(dev_priv);
15085 intel_fbc_init(dev_priv);
15087 intel_init_pm(dev_priv);
15090 * There may be no VBT; and if the BIOS enabled SSC we can
15091 * just keep using it to avoid unnecessary flicker. Whereas if the
15092 * BIOS isn't using it, don't assume it will work even if the VBT
15093 * indicates as much.
15095 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
15096 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
15099 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
15100 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
15101 bios_lvds_use_ssc ? "en" : "dis",
15102 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
15103 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
15107 /* maximum framebuffer dimensions */
15108 if (IS_GEN2(dev_priv)) {
15109 dev->mode_config.max_width = 2048;
15110 dev->mode_config.max_height = 2048;
15111 } else if (IS_GEN3(dev_priv)) {
15112 dev->mode_config.max_width = 4096;
15113 dev->mode_config.max_height = 4096;
15115 dev->mode_config.max_width = 8192;
15116 dev->mode_config.max_height = 8192;
15119 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
15120 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
15121 dev->mode_config.cursor_height = 1023;
15122 } else if (IS_GEN2(dev_priv)) {
15123 dev->mode_config.cursor_width = 64;
15124 dev->mode_config.cursor_height = 64;
15126 dev->mode_config.cursor_width = 256;
15127 dev->mode_config.cursor_height = 256;
15130 dev->mode_config.fb_base = ggtt->gmadr.start;
15132 DRM_DEBUG_KMS("%d display pipe%s available.\n",
15133 INTEL_INFO(dev_priv)->num_pipes,
15134 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
15136 for_each_pipe(dev_priv, pipe) {
15137 ret = intel_crtc_init(dev_priv, pipe);
15139 drm_mode_config_cleanup(dev);
15144 intel_shared_dpll_init(dev);
15145 intel_update_fdi_pll_freq(dev_priv);
15147 intel_update_czclk(dev_priv);
15148 intel_modeset_init_hw(dev);
15150 if (dev_priv->max_cdclk_freq == 0)
15151 intel_update_max_cdclk(dev_priv);
15153 /* Just disable it once at startup */
15154 i915_disable_vga(dev_priv);
15155 intel_setup_outputs(dev_priv);
15157 drm_modeset_lock_all(dev);
15158 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
15159 drm_modeset_unlock_all(dev);
15161 for_each_intel_crtc(dev, crtc) {
15162 struct intel_initial_plane_config plane_config = {};
15168 * Note that reserving the BIOS fb up front prevents us
15169 * from stuffing other stolen allocations like the ring
15170 * on top. This prevents some ugliness at boot time, and
15171 * can even allow for smooth boot transitions if the BIOS
15172 * fb is large enough for the active pipe configuration.
15174 dev_priv->display.get_initial_plane_config(crtc,
15178 * If the fb is shared between multiple heads, we'll
15179 * just get the first one.
15181 intel_find_initial_plane_obj(crtc, &plane_config);
15185 * Make sure hardware watermarks really match the state we read out.
15186 * Note that we need to do this after reconstructing the BIOS fb's
15187 * since the watermark calculation done here will use pstate->fb.
15189 if (!HAS_GMCH_DISPLAY(dev_priv))
15190 sanitize_watermarks(dev);
15193 * Force all active planes to recompute their states. So that on
15194 * mode_setcrtc after probe, all the intel_plane_state variables
15195 * are already calculated and there is no assert_plane warnings
15198 ret = intel_initial_commit(dev);
15200 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
15205 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15207 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15208 /* 640x480@60Hz, ~25175 kHz */
15209 struct dpll clock = {
15219 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
15221 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
15222 pipe_name(pipe), clock.vco, clock.dot);
15224 fp = i9xx_dpll_compute_fp(&clock);
15225 dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
15226 DPLL_VGA_MODE_DIS |
15227 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
15228 PLL_P2_DIVIDE_BY_4 |
15229 PLL_REF_INPUT_DREFCLK |
15232 I915_WRITE(FP0(pipe), fp);
15233 I915_WRITE(FP1(pipe), fp);
15235 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
15236 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
15237 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
15238 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
15239 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
15240 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
15241 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
15244 * Apparently we need to have VGA mode enabled prior to changing
15245 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
15246 * dividers, even though the register value does change.
15248 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
15249 I915_WRITE(DPLL(pipe), dpll);
15251 /* Wait for the clocks to stabilize. */
15252 POSTING_READ(DPLL(pipe));
15255 /* The pixel multiplier can only be updated once the
15256 * DPLL is enabled and the clocks are stable.
15258 * So write it again.
15260 I915_WRITE(DPLL(pipe), dpll);
15262 /* We do this three times for luck */
15263 for (i = 0; i < 3 ; i++) {
15264 I915_WRITE(DPLL(pipe), dpll);
15265 POSTING_READ(DPLL(pipe));
15266 udelay(150); /* wait for warmup */
15269 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
15270 POSTING_READ(PIPECONF(pipe));
15272 intel_wait_for_pipe_scanline_moving(crtc);
15275 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15277 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15279 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
15282 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
15283 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
15284 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
15285 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
15286 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
15288 I915_WRITE(PIPECONF(pipe), 0);
15289 POSTING_READ(PIPECONF(pipe));
15291 intel_wait_for_pipe_scanline_stopped(crtc);
15293 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
15294 POSTING_READ(DPLL(pipe));
15298 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
15300 struct intel_crtc *crtc;
15302 if (INTEL_GEN(dev_priv) >= 4)
15305 for_each_intel_crtc(&dev_priv->drm, crtc) {
15306 struct intel_plane *plane =
15307 to_intel_plane(crtc->base.primary);
15308 struct intel_crtc *plane_crtc;
15311 if (!plane->get_hw_state(plane, &pipe))
15314 if (pipe == crtc->pipe)
15317 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
15318 plane->base.base.id, plane->base.name);
15320 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15321 intel_plane_disable_noatomic(plane_crtc, plane);
15325 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
15327 struct drm_device *dev = crtc->base.dev;
15328 struct intel_encoder *encoder;
15330 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
15336 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
15338 struct drm_device *dev = encoder->base.dev;
15339 struct intel_connector *connector;
15341 for_each_connector_on_encoder(dev, &encoder->base, connector)
15347 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
15348 enum pipe pch_transcoder)
15350 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
15351 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
15354 static void intel_sanitize_crtc(struct intel_crtc *crtc,
15355 struct drm_modeset_acquire_ctx *ctx)
15357 struct drm_device *dev = crtc->base.dev;
15358 struct drm_i915_private *dev_priv = to_i915(dev);
15359 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
15360 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
15362 /* Clear any frame start delays used for debugging left by the BIOS */
15363 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
15364 i915_reg_t reg = PIPECONF(cpu_transcoder);
15367 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
15370 if (crtc_state->base.active) {
15371 struct intel_plane *plane;
15373 /* Disable everything but the primary plane */
15374 for_each_intel_plane_on_crtc(dev, crtc, plane) {
15375 const struct intel_plane_state *plane_state =
15376 to_intel_plane_state(plane->base.state);
15378 if (plane_state->base.visible &&
15379 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
15380 intel_plane_disable_noatomic(crtc, plane);
15384 /* Adjust the state of the output pipe according to whether we
15385 * have active connectors/encoders. */
15386 if (crtc_state->base.active && !intel_crtc_has_encoders(crtc))
15387 intel_crtc_disable_noatomic(&crtc->base, ctx);
15389 if (crtc_state->base.active || HAS_GMCH_DISPLAY(dev_priv)) {
15391 * We start out with underrun reporting disabled to avoid races.
15392 * For correct bookkeeping mark this on active crtcs.
15394 * Also on gmch platforms we dont have any hardware bits to
15395 * disable the underrun reporting. Which means we need to start
15396 * out with underrun reporting disabled also on inactive pipes,
15397 * since otherwise we'll complain about the garbage we read when
15398 * e.g. coming up after runtime pm.
15400 * No protection against concurrent access is required - at
15401 * worst a fifo underrun happens which also sets this to false.
15403 crtc->cpu_fifo_underrun_disabled = true;
15405 * We track the PCH trancoder underrun reporting state
15406 * within the crtc. With crtc for pipe A housing the underrun
15407 * reporting state for PCH transcoder A, crtc for pipe B housing
15408 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
15409 * and marking underrun reporting as disabled for the non-existing
15410 * PCH transcoders B and C would prevent enabling the south
15411 * error interrupt (see cpt_can_enable_serr_int()).
15413 if (has_pch_trancoder(dev_priv, crtc->pipe))
15414 crtc->pch_fifo_underrun_disabled = true;
15418 static void intel_sanitize_encoder(struct intel_encoder *encoder)
15420 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
15421 struct intel_connector *connector;
15423 /* We need to check both for a crtc link (meaning that the
15424 * encoder is active and trying to read from a pipe) and the
15425 * pipe itself being active. */
15426 bool has_active_crtc = encoder->base.crtc &&
15427 to_intel_crtc(encoder->base.crtc)->active;
15429 connector = intel_encoder_find_connector(encoder);
15430 if (connector && !has_active_crtc) {
15431 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15432 encoder->base.base.id,
15433 encoder->base.name);
15435 /* Connector is active, but has no active pipe. This is
15436 * fallout from our resume register restoring. Disable
15437 * the encoder manually again. */
15438 if (encoder->base.crtc) {
15439 struct drm_crtc_state *crtc_state = encoder->base.crtc->state;
15441 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15442 encoder->base.base.id,
15443 encoder->base.name);
15444 if (encoder->disable)
15445 encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
15446 if (encoder->post_disable)
15447 encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
15449 encoder->base.crtc = NULL;
15451 /* Inconsistent output/port/pipe state happens presumably due to
15452 * a bug in one of the get_hw_state functions. Or someplace else
15453 * in our code, like the register restore mess on resume. Clamp
15454 * things to off as a safer default. */
15456 connector->base.dpms = DRM_MODE_DPMS_OFF;
15457 connector->base.encoder = NULL;
15460 /* notify opregion of the sanitized encoder state */
15461 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
15463 if (INTEL_GEN(dev_priv) >= 11)
15464 icl_sanitize_encoder_pll_mapping(encoder);
15467 void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
15469 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
15471 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15472 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
15473 i915_disable_vga(dev_priv);
15477 void i915_redisable_vga(struct drm_i915_private *dev_priv)
15479 /* This function can be called both from intel_modeset_setup_hw_state or
15480 * at a very early point in our resume sequence, where the power well
15481 * structures are not yet restored. Since this function is at a very
15482 * paranoid "someone might have enabled VGA while we were not looking"
15483 * level, just check if the power well is enabled instead of trying to
15484 * follow the "don't touch the power well if we don't need it" policy
15485 * the rest of the driver uses. */
15486 if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA))
15489 i915_redisable_vga_power_on(dev_priv);
15491 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA);
15494 /* FIXME read out full plane state for all planes */
15495 static void readout_plane_state(struct drm_i915_private *dev_priv)
15497 struct intel_plane *plane;
15498 struct intel_crtc *crtc;
15500 for_each_intel_plane(&dev_priv->drm, plane) {
15501 struct intel_plane_state *plane_state =
15502 to_intel_plane_state(plane->base.state);
15503 struct intel_crtc_state *crtc_state;
15504 enum pipe pipe = PIPE_A;
15507 visible = plane->get_hw_state(plane, &pipe);
15509 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15510 crtc_state = to_intel_crtc_state(crtc->base.state);
15512 intel_set_plane_visible(crtc_state, plane_state, visible);
15514 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
15515 plane->base.base.id, plane->base.name,
15516 enableddisabled(visible), pipe_name(pipe));
15519 for_each_intel_crtc(&dev_priv->drm, crtc) {
15520 struct intel_crtc_state *crtc_state =
15521 to_intel_crtc_state(crtc->base.state);
15523 fixup_active_planes(crtc_state);
15527 static void intel_modeset_readout_hw_state(struct drm_device *dev)
15529 struct drm_i915_private *dev_priv = to_i915(dev);
15531 struct intel_crtc *crtc;
15532 struct intel_encoder *encoder;
15533 struct intel_connector *connector;
15534 struct drm_connector_list_iter conn_iter;
15537 dev_priv->active_crtcs = 0;
15539 for_each_intel_crtc(dev, crtc) {
15540 struct intel_crtc_state *crtc_state =
15541 to_intel_crtc_state(crtc->base.state);
15543 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
15544 memset(crtc_state, 0, sizeof(*crtc_state));
15545 crtc_state->base.crtc = &crtc->base;
15547 crtc_state->base.active = crtc_state->base.enable =
15548 dev_priv->display.get_pipe_config(crtc, crtc_state);
15550 crtc->base.enabled = crtc_state->base.enable;
15551 crtc->active = crtc_state->base.active;
15553 if (crtc_state->base.active)
15554 dev_priv->active_crtcs |= 1 << crtc->pipe;
15556 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15557 crtc->base.base.id, crtc->base.name,
15558 enableddisabled(crtc_state->base.active));
15561 readout_plane_state(dev_priv);
15563 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15564 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15566 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
15567 &pll->state.hw_state);
15568 pll->state.crtc_mask = 0;
15569 for_each_intel_crtc(dev, crtc) {
15570 struct intel_crtc_state *crtc_state =
15571 to_intel_crtc_state(crtc->base.state);
15573 if (crtc_state->base.active &&
15574 crtc_state->shared_dpll == pll)
15575 pll->state.crtc_mask |= 1 << crtc->pipe;
15577 pll->active_mask = pll->state.crtc_mask;
15579 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15580 pll->info->name, pll->state.crtc_mask, pll->on);
15583 for_each_intel_encoder(dev, encoder) {
15586 if (encoder->get_hw_state(encoder, &pipe)) {
15587 struct intel_crtc_state *crtc_state;
15589 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15590 crtc_state = to_intel_crtc_state(crtc->base.state);
15592 encoder->base.crtc = &crtc->base;
15593 encoder->get_config(encoder, crtc_state);
15595 encoder->base.crtc = NULL;
15598 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15599 encoder->base.base.id, encoder->base.name,
15600 enableddisabled(encoder->base.crtc),
15604 drm_connector_list_iter_begin(dev, &conn_iter);
15605 for_each_intel_connector_iter(connector, &conn_iter) {
15606 if (connector->get_hw_state(connector)) {
15607 connector->base.dpms = DRM_MODE_DPMS_ON;
15609 encoder = connector->encoder;
15610 connector->base.encoder = &encoder->base;
15612 if (encoder->base.crtc &&
15613 encoder->base.crtc->state->active) {
15615 * This has to be done during hardware readout
15616 * because anything calling .crtc_disable may
15617 * rely on the connector_mask being accurate.
15619 encoder->base.crtc->state->connector_mask |=
15620 drm_connector_mask(&connector->base);
15621 encoder->base.crtc->state->encoder_mask |=
15622 drm_encoder_mask(&encoder->base);
15626 connector->base.dpms = DRM_MODE_DPMS_OFF;
15627 connector->base.encoder = NULL;
15629 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
15630 connector->base.base.id, connector->base.name,
15631 enableddisabled(connector->base.encoder));
15633 drm_connector_list_iter_end(&conn_iter);
15635 for_each_intel_crtc(dev, crtc) {
15636 struct intel_crtc_state *crtc_state =
15637 to_intel_crtc_state(crtc->base.state);
15640 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
15641 if (crtc_state->base.active) {
15642 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
15643 crtc->base.mode.hdisplay = crtc_state->pipe_src_w;
15644 crtc->base.mode.vdisplay = crtc_state->pipe_src_h;
15645 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
15646 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
15649 * The initial mode needs to be set in order to keep
15650 * the atomic core happy. It wants a valid mode if the
15651 * crtc's enabled, so we do the above call.
15653 * But we don't set all the derived state fully, hence
15654 * set a flag to indicate that a full recalculation is
15655 * needed on the next commit.
15657 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
15659 intel_crtc_compute_pixel_rate(crtc_state);
15661 if (dev_priv->display.modeset_calc_cdclk) {
15662 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
15663 if (WARN_ON(min_cdclk < 0))
15667 drm_calc_timestamping_constants(&crtc->base,
15668 &crtc_state->base.adjusted_mode);
15669 update_scanline_offset(crtc_state);
15672 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
15673 dev_priv->min_voltage_level[crtc->pipe] =
15674 crtc_state->min_voltage_level;
15676 intel_pipe_config_sanity_check(dev_priv, crtc_state);
15681 get_encoder_power_domains(struct drm_i915_private *dev_priv)
15683 struct intel_encoder *encoder;
15685 for_each_intel_encoder(&dev_priv->drm, encoder) {
15687 enum intel_display_power_domain domain;
15688 struct intel_crtc_state *crtc_state;
15690 if (!encoder->get_power_domains)
15694 * MST-primary and inactive encoders don't have a crtc state
15695 * and neither of these require any power domain references.
15697 if (!encoder->base.crtc)
15700 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
15701 get_domains = encoder->get_power_domains(encoder, crtc_state);
15702 for_each_power_domain(domain, get_domains)
15703 intel_display_power_get(dev_priv, domain);
15707 static void intel_early_display_was(struct drm_i915_private *dev_priv)
15709 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
15710 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
15711 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
15714 if (IS_HASWELL(dev_priv)) {
15716 * WaRsPkgCStateDisplayPMReq:hsw
15717 * System hang if this isn't done before disabling all planes!
15719 I915_WRITE(CHICKEN_PAR1_1,
15720 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
15724 static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
15725 enum port port, i915_reg_t hdmi_reg)
15727 u32 val = I915_READ(hdmi_reg);
15729 if (val & SDVO_ENABLE ||
15730 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
15733 DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n",
15736 val &= ~SDVO_PIPE_SEL_MASK;
15737 val |= SDVO_PIPE_SEL(PIPE_A);
15739 I915_WRITE(hdmi_reg, val);
15742 static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
15743 enum port port, i915_reg_t dp_reg)
15745 u32 val = I915_READ(dp_reg);
15747 if (val & DP_PORT_EN ||
15748 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
15751 DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n",
15754 val &= ~DP_PIPE_SEL_MASK;
15755 val |= DP_PIPE_SEL(PIPE_A);
15757 I915_WRITE(dp_reg, val);
15760 static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
15763 * The BIOS may select transcoder B on some of the PCH
15764 * ports even it doesn't enable the port. This would trip
15765 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
15766 * Sanitize the transcoder select bits to prevent that. We
15767 * assume that the BIOS never actually enabled the port,
15768 * because if it did we'd actually have to toggle the port
15769 * on and back off to make the transcoder A select stick
15770 * (see. intel_dp_link_down(), intel_disable_hdmi(),
15771 * intel_disable_sdvo()).
15773 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
15774 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
15775 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
15777 /* PCH SDVOB multiplex with HDMIB */
15778 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
15779 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
15780 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
15783 /* Scan out the current hw modeset state,
15784 * and sanitizes it to the current state
15787 intel_modeset_setup_hw_state(struct drm_device *dev,
15788 struct drm_modeset_acquire_ctx *ctx)
15790 struct drm_i915_private *dev_priv = to_i915(dev);
15791 struct intel_crtc *crtc;
15792 struct intel_crtc_state *crtc_state;
15793 struct intel_encoder *encoder;
15796 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
15798 intel_early_display_was(dev_priv);
15799 intel_modeset_readout_hw_state(dev);
15801 /* HW state is read out, now we need to sanitize this mess. */
15802 get_encoder_power_domains(dev_priv);
15804 if (HAS_PCH_IBX(dev_priv))
15805 ibx_sanitize_pch_ports(dev_priv);
15808 * intel_sanitize_plane_mapping() may need to do vblank
15809 * waits, so we need vblank interrupts restored beforehand.
15811 for_each_intel_crtc(&dev_priv->drm, crtc) {
15812 drm_crtc_vblank_reset(&crtc->base);
15814 if (crtc->base.state->active)
15815 drm_crtc_vblank_on(&crtc->base);
15818 intel_sanitize_plane_mapping(dev_priv);
15820 for_each_intel_encoder(dev, encoder)
15821 intel_sanitize_encoder(encoder);
15823 for_each_intel_crtc(&dev_priv->drm, crtc) {
15824 crtc_state = to_intel_crtc_state(crtc->base.state);
15825 intel_sanitize_crtc(crtc, ctx);
15826 intel_dump_pipe_config(crtc, crtc_state,
15827 "[setup_hw_state]");
15830 intel_modeset_update_connector_atomic_state(dev);
15832 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15833 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15835 if (!pll->on || pll->active_mask)
15838 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
15841 pll->info->funcs->disable(dev_priv, pll);
15845 if (IS_G4X(dev_priv)) {
15846 g4x_wm_get_hw_state(dev);
15847 g4x_wm_sanitize(dev_priv);
15848 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
15849 vlv_wm_get_hw_state(dev);
15850 vlv_wm_sanitize(dev_priv);
15851 } else if (INTEL_GEN(dev_priv) >= 9) {
15852 skl_wm_get_hw_state(dev);
15853 } else if (HAS_PCH_SPLIT(dev_priv)) {
15854 ilk_wm_get_hw_state(dev);
15857 for_each_intel_crtc(dev, crtc) {
15860 crtc_state = to_intel_crtc_state(crtc->base.state);
15861 put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc_state);
15862 if (WARN_ON(put_domains))
15863 modeset_put_power_domains(dev_priv, put_domains);
15866 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
15868 intel_fbc_init_pipe_state(dev_priv);
15871 void intel_display_resume(struct drm_device *dev)
15873 struct drm_i915_private *dev_priv = to_i915(dev);
15874 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
15875 struct drm_modeset_acquire_ctx ctx;
15878 dev_priv->modeset_restore_state = NULL;
15880 state->acquire_ctx = &ctx;
15882 drm_modeset_acquire_init(&ctx, 0);
15885 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15886 if (ret != -EDEADLK)
15889 drm_modeset_backoff(&ctx);
15893 ret = __intel_display_resume(dev, state, &ctx);
15895 intel_enable_ipc(dev_priv);
15896 drm_modeset_drop_locks(&ctx);
15897 drm_modeset_acquire_fini(&ctx);
15900 DRM_ERROR("Restoring old state failed with %i\n", ret);
15902 drm_atomic_state_put(state);
15905 static void intel_hpd_poll_fini(struct drm_device *dev)
15907 struct intel_connector *connector;
15908 struct drm_connector_list_iter conn_iter;
15910 /* Kill all the work that may have been queued by hpd. */
15911 drm_connector_list_iter_begin(dev, &conn_iter);
15912 for_each_intel_connector_iter(connector, &conn_iter) {
15913 if (connector->modeset_retry_work.func)
15914 cancel_work_sync(&connector->modeset_retry_work);
15915 if (connector->hdcp.shim) {
15916 cancel_delayed_work_sync(&connector->hdcp.check_work);
15917 cancel_work_sync(&connector->hdcp.prop_work);
15920 drm_connector_list_iter_end(&conn_iter);
15923 void intel_modeset_cleanup(struct drm_device *dev)
15925 struct drm_i915_private *dev_priv = to_i915(dev);
15927 flush_workqueue(dev_priv->modeset_wq);
15929 flush_work(&dev_priv->atomic_helper.free_work);
15930 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
15933 * Interrupts and polling as the first thing to avoid creating havoc.
15934 * Too much stuff here (turning of connectors, ...) would
15935 * experience fancy races otherwise.
15937 intel_irq_uninstall(dev_priv);
15940 * Due to the hpd irq storm handling the hotplug work can re-arm the
15941 * poll handlers. Hence disable polling after hpd handling is shut down.
15943 intel_hpd_poll_fini(dev);
15945 /* poll work can call into fbdev, hence clean that up afterwards */
15946 intel_fbdev_fini(dev_priv);
15948 intel_unregister_dsm_handler();
15950 intel_fbc_global_disable(dev_priv);
15952 /* flush any delayed tasks or pending work */
15953 flush_scheduled_work();
15955 drm_mode_config_cleanup(dev);
15957 intel_overlay_cleanup(dev_priv);
15959 intel_teardown_gmbus(dev_priv);
15961 destroy_workqueue(dev_priv->modeset_wq);
15963 intel_fbc_cleanup_cfb(dev_priv);
15967 * set vga decode state - true == enable VGA decode
15969 int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
15971 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
15974 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
15975 DRM_ERROR("failed to read control word\n");
15979 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
15983 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
15985 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
15987 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
15988 DRM_ERROR("failed to write control word\n");
15995 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
15997 struct intel_display_error_state {
15999 u32 power_well_driver;
16001 int num_transcoders;
16003 struct intel_cursor_error_state {
16008 } cursor[I915_MAX_PIPES];
16010 struct intel_pipe_error_state {
16011 bool power_domain_on;
16014 } pipe[I915_MAX_PIPES];
16016 struct intel_plane_error_state {
16024 } plane[I915_MAX_PIPES];
16026 struct intel_transcoder_error_state {
16027 bool power_domain_on;
16028 enum transcoder cpu_transcoder;
16041 struct intel_display_error_state *
16042 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
16044 struct intel_display_error_state *error;
16045 int transcoders[] = {
16053 if (!HAS_DISPLAY(dev_priv))
16056 error = kzalloc(sizeof(*error), GFP_ATOMIC);
16060 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
16061 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
16063 for_each_pipe(dev_priv, i) {
16064 error->pipe[i].power_domain_on =
16065 __intel_display_power_is_enabled(dev_priv,
16066 POWER_DOMAIN_PIPE(i));
16067 if (!error->pipe[i].power_domain_on)
16070 error->cursor[i].control = I915_READ(CURCNTR(i));
16071 error->cursor[i].position = I915_READ(CURPOS(i));
16072 error->cursor[i].base = I915_READ(CURBASE(i));
16074 error->plane[i].control = I915_READ(DSPCNTR(i));
16075 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
16076 if (INTEL_GEN(dev_priv) <= 3) {
16077 error->plane[i].size = I915_READ(DSPSIZE(i));
16078 error->plane[i].pos = I915_READ(DSPPOS(i));
16080 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
16081 error->plane[i].addr = I915_READ(DSPADDR(i));
16082 if (INTEL_GEN(dev_priv) >= 4) {
16083 error->plane[i].surface = I915_READ(DSPSURF(i));
16084 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
16087 error->pipe[i].source = I915_READ(PIPESRC(i));
16089 if (HAS_GMCH_DISPLAY(dev_priv))
16090 error->pipe[i].stat = I915_READ(PIPESTAT(i));
16093 /* Note: this does not include DSI transcoders. */
16094 error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
16095 if (HAS_DDI(dev_priv))
16096 error->num_transcoders++; /* Account for eDP. */
16098 for (i = 0; i < error->num_transcoders; i++) {
16099 enum transcoder cpu_transcoder = transcoders[i];
16101 error->transcoder[i].power_domain_on =
16102 __intel_display_power_is_enabled(dev_priv,
16103 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
16104 if (!error->transcoder[i].power_domain_on)
16107 error->transcoder[i].cpu_transcoder = cpu_transcoder;
16109 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
16110 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
16111 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
16112 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
16113 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
16114 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
16115 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
16121 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
16124 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
16125 struct intel_display_error_state *error)
16127 struct drm_i915_private *dev_priv = m->i915;
16133 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
16134 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
16135 err_printf(m, "PWR_WELL_CTL2: %08x\n",
16136 error->power_well_driver);
16137 for_each_pipe(dev_priv, i) {
16138 err_printf(m, "Pipe [%d]:\n", i);
16139 err_printf(m, " Power: %s\n",
16140 onoff(error->pipe[i].power_domain_on));
16141 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
16142 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
16144 err_printf(m, "Plane [%d]:\n", i);
16145 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
16146 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
16147 if (INTEL_GEN(dev_priv) <= 3) {
16148 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
16149 err_printf(m, " POS: %08x\n", error->plane[i].pos);
16151 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
16152 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
16153 if (INTEL_GEN(dev_priv) >= 4) {
16154 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
16155 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
16158 err_printf(m, "Cursor [%d]:\n", i);
16159 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
16160 err_printf(m, " POS: %08x\n", error->cursor[i].position);
16161 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
16164 for (i = 0; i < error->num_transcoders; i++) {
16165 err_printf(m, "CPU transcoder: %s\n",
16166 transcoder_name(error->transcoder[i].cpu_transcoder));
16167 err_printf(m, " Power: %s\n",
16168 onoff(error->transcoder[i].power_domain_on));
16169 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
16170 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
16171 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
16172 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
16173 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
16174 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
16175 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);